
笨办法学python
周杰伦今天喝奶茶了吗
喜欢周杰伦,也喜欢优快云博客,这使我快乐!
展开
-
习题0:准备工作。python的安装
实不相瞒,为了在cmd或者PowerShell上跑出如下效果,我前后弄了差不多一个小时。(唉,还真是笨办法学啊)一直在纠结环境变量配置的问题,按照查的资料上配置了,但在cmd或PowerShell上一输入python,就报错,接着显示“python停止工作”。一度非常崩溃。后来决定归零重来,于是又重新安装。安装中无意发现,原来可以在安装时就选择自动配置环境变量。于是,我就决定再试最后一把,要是还不...原创 2018-03-17 22:32:57 · 183 阅读 · 0 评论 -
《笨办法学python》习题15:读取文件
from sys import argv#使用 argv 来获取文件名script,filename =argvtxt=open(filename)print "here is your file %r:"%filenameprint txt.read()print "type the filename again:"file_again =raw_input(">")...原创 2018-03-20 20:45:30 · 979 阅读 · 0 评论 -
《笨办法学python》习题16:读写文件
from sys import argvscript, filename = argvprint "We're going to erase %r." % filenameprint "If you don't want that, hit CTRL-C (^C)."print "If you do want that, hit RETURN."raw_input("?")pr...原创 2018-03-20 21:16:01 · 413 阅读 · 0 评论 -
《笨办法学Python》习题21:函数可以返回东西
def add(a, b): print "ADDING %d + %d" % (a, b) return a + bdef subtract(a, b): print "SUBTRACTING %d - %d" % (a, b) return a - bdef multiply(a, b): print "MULTIPLYING %d * %d" ...原创 2018-03-25 16:25:54 · 357 阅读 · 0 评论 -
《笨办法学Python》习题24:更多练习
print "Let's practice everything."print 'You\'d need to know \'bout escape with \\ that do \n newline and \t tabs.'poem="""\tThe lovely worldwith logic so firmly plantedcannot discern \n the ne...原创 2018-03-25 16:50:59 · 351 阅读 · 0 评论 -
《笨办法学python》习题17:更多文件操作
from sys import argvfrom os.path import exists #我们 import 了又一个很好用的命令 exists。这个命令将文件名字符串作为参数,如果文件存在的话,它将返回 True,否则将返回 False。script, from_file, to_file = argvprint "Copying from %s to %s" % (from_...原创 2018-03-21 22:32:51 · 1199 阅读 · 0 评论 -
《笨办法学Python》习题18:命名,变量,代码,函数
错误代码:(编译时一直报错)IndentationError:expected an indented block:说明此处需要缩进# this one is like your scripts with argvdef print_two(*args):arg1, arg2 = argsprint "arg1: %r, arg2: %r" % (arg1, arg2)# ok, tha...原创 2018-03-21 22:48:45 · 318 阅读 · 0 评论 -
《笨办法学python》习题19:函数和变量
def cheese_and_crackers(chess_count,boxes_of_crackers): print "you have %d cheeses" %cheese_count print "you have %d boxes of crackers!" %boxes_of_crackers print "Man that's enough for a party!"...原创 2018-03-22 10:14:39 · 299 阅读 · 0 评论 -
《笨办法学python》习题20:函数和文件
from sys import argvscript, input_file = argvdef print_all(f):print f.read()#readline() 方法用于从文件读取整行,包括 "\n" 字符。如果指定了一个非负数的参数,则返回指定大小的字节数,包括 "\n" 字符。def rewind(f):f.seek(0)def print_a_line(li...原创 2018-03-22 11:42:17 · 366 阅读 · 0 评论 -
Python3脚本抢票
一直很想尝试一下电脑跑脚本,抢票就是一个很好的例子。于是在网上找呀找,终于找到了一个可以运行的12306抢票脚本。虽然因为12306的图片验证而有些阻碍。但我觉得代码跑起来的整体体验非常好。感谢一位博主提供的代码:https://www.cnblogs.com/lizm166/p/8191305.html1.Chromedriver 驱动的下载地址如下: http://chromedriv...原创 2018-09-09 16:22:27 · 29923 阅读 · 9 评论 -
学python遇到的问题:SyntaxError: Non-UTF-8 code starting with '\xb7' in file SyntaxError: (unicode error) '
1.SyntaxError: Non-UTF-8 code starting with '\xb7' in file 解决方式:在程序最上面加上: # coding=gbk 2.此外还遇到了问题,python2和python3 中print用法不同。因为我用的是python3,所以print(),其后的括号一定不能忘。 3.SyntaxError: (unicode ...原创 2018-09-19 21:24:40 · 7181 阅读 · 3 评论 -
cmd命令行里python、pip的具体操作及问题
1.怎么打开及退出python环境?2.怎么查看pip的安装情况?(是 Python 包管理工具,该工具提供了对Python 包的查找、下载、安装、卸载的功能。目前如果你在 python.org 下载最新版本的安装包,则是已经自带了该工具。Python 2.7.9 + 或 Python 3.4+ 以上版本都自带 pip 工具。)两种命令行语句都可以: 3...原创 2018-09-29 11:11:47 · 27979 阅读 · 2 评论 -
pycharm:ModuleNotFoundError: No module named 'scrapy'
最初遇到这个问题的时候,是因为我没有安装scrapy由于scrapy爬虫框架依赖许多第三方库,所以在安装scrapy之前,需确保以下第三方库均已安装:1.lxml库 可通过命令行查看是否安装 pip3 list2.通过 pip安装 zope.interface库pip3 install zope.interface3.twisted库twisted库不能...原创 2018-09-29 15:29:51 · 18316 阅读 · 4 评论 -
《笨办法学python》习题14:提示和传递
from sys import argvscript, user_name = argvprompt = '> ' #将用户提示符设置为变量 prompt,print "Hi %s, I'm the %s script." % (user_name, script)print "I'd like to ask you a few questions."print "Do you...原创 2018-03-20 00:17:22 · 725 阅读 · 0 评论 -
习题13:
代码:from sys import argvscript, first, second, third = argvprint "The script is called:", scriptprint "Your first variable is:", firstprint "Your second variable is:", secondprint "Your third va...原创 2018-03-19 13:35:41 · 266 阅读 · 1 评论 -
习题1:第一个程序
首先在notepad++里写如下语句,并保存为 .py格式然后在powershell里运行刚才保存的程序。可以发现,我因为语句不熟悉,中间还报错了一次。运行前要先加 python,然后才是.py文件。如此,第一个任务便完成了。在书里,作者提到,有可能需要在第一行加# -- coding: utf-8 才可以正确编译,而我没有加也可以行得通。感觉这应该是Notepad++的功劳。...原创 2018-03-17 22:52:26 · 234 阅读 · 0 评论 -
习题2:注释和#号
源码:运行情况:从上述运行情况的报错可以看出,文件运行时,路径的正确性太重要了。原创 2018-03-17 23:07:07 · 222 阅读 · 0 评论 -
习题3:数字和数字计算
+ plus- minus/ slash * asterisk% percent< less-than > greater-than<= less-than-equal>= greater-than-equal (顺带学点英语~hhh)print "I will now count my chickens:"print "Hens",25+30/6print "Roo...原创 2018-03-17 23:28:02 · 320 阅读 · 0 评论 -
习题4:变量(Variable)和命名
在这个简单任务中,我却频频报错,原因何在?“unexpected indent”经改正后发现python的空格、缩进啥的,格式要求是很严格的!把那些多余的空格去掉之后,运行就正常啦!...原创 2018-03-17 23:43:55 · 344 阅读 · 0 评论 -
习题5:更多的变量和打印
my_name = 'Zed A. Shaw'my_age = 35 # not a liemy_height = 74 # inchesmy_weight = 180 # lbsmy_eyes = 'Blue'my_teeth = 'White'my_hair = 'Brown'print "Let's talk about %s." % my_nameprint "He's ...原创 2018-03-18 00:05:01 · 256 阅读 · 0 评论 -
习题6:字符串string和文本
x = "There are %d types of people." % 10binary = "binary"do_not = "don't"y = "Those who know %s and those who %s." % (binary, do_not)print xprint yprint "I said: %r." % xprint "I also said: '.原创 2018-03-18 12:12:58 · 242 阅读 · 0 评论 -
习题7:更多打印
print "Mary had a little lamb."print "Its fleece was white as %s."%'snow'print "And everywhere that Mary went."print "."*10 # what'd that do?end1="C"end2="h"end3="e"end4 = "原创 2018-03-18 12:25:39 · 247 阅读 · 0 评论 -
习题8:打印打印
formatter = "%r %r %r %r"print formatter % (1, 2, 3, 4)print formatter % ("one", "two", "three", "four")print formatter % (True, False, False, True)print formatter % (formatter, formatter, formatt...原创 2018-03-18 12:38:15 · 321 阅读 · 2 评论 -
习题9:打印打印打印
# Here's some new strange stuff, remember type it exactly.days = "Mon Tue Wed Thu Fri Sat Sun"months = "Jan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug"print "Here are the days: ", daysprint "Here are the ...原创 2018-03-18 12:49:35 · 307 阅读 · 0 评论 -
习题10:那是什么?
原文:在习题 9 中我你接触了一些新东西。我让你看到两种让字符串扩展到多行的方法。第一种方法是在月份之间用 \n (back-slash n ) 隔开。这两个字符的作用是在该位置上放入一个“新行 (new line)”字符。使用反斜杠 \ (back-slash) 可以将难打印出来的字符放到字符串。针对不同的符号有很多这样的所谓“转义序列 (escape sequences)”,但有一个特殊的转义...原创 2018-03-18 13:01:01 · 278 阅读 · 0 评论 -
习题11:提问
print "How old are you?",age = raw_input()print "How tall are you?",height = raw_input()print "How much do you weigh?",weight = raw_input()print "So, you're %r old, %r tall and %r heavy." % (age, heig...原创 2018-03-18 13:19:01 · 355 阅读 · 0 评论 -
习题11:提示别人
age = raw_input("How old are you? ")height = raw_input("How tall are you? ")weight = raw_input("How much do you weigh? ")print "So, you're %r old, %r tall and %r heavy." % (age, height, weight)其实目...原创 2018-03-19 13:23:52 · 256 阅读 · 0 评论 -
pycharm 如何导入库?
以前记得,好久不用,又……又忘了在哪里配置了。(*/ω\*)File →Settings→ project interpreter→+原创 2019-04-22 17:09:05 · 1532 阅读 · 0 评论