- 博客(11)
- 问答 (1)
- 收藏
- 关注
原创 python核心编程二十章例题asvcgi.py中的错误与修改
在python核心编程例题20.8中,按照作者代码是无法正常运行的,需要修改一下代码。主要是15行修改一下,48-51行添加四段代码。修改后代码如下:#!/usr/bin/env python# -*- coding:utf-8from cgi import FieldStoragefrom os import environfrom cStringIO import StringIO
2016-07-27 12:21:25 567
原创 python核心编程十五章练习
15-1import repattern = re.compile('([bh][aui]t )+')match = re.match(pattern, 'bat bit but hat hit hut ')print match.group()15-2import repattern = re.compile('\w+\s\w+')match = re.match(p
2016-07-24 23:00:45 527
原创 python核心编程十四章练习
14-3fn = raw_input('$py:')execfile(fn)14-4import osfrom subprocess import callos.system('dir')call('dir', shell=True)14-5from commands import getoutput output = getoutput('ls'
2016-07-24 22:57:11 282
原创 python核心编程十三章练习
13-2#!/user/bin/env python# -*- coding:utf-8 class MoneyFmt(object): '''把函数dollarize转换为一个类,并且包含以下的五个方法''' def __init__(self, value=0.0, default='-'): self.value = float(value)
2016-07-24 22:46:22 1002
原创 python核心编程第十一章练习
11-4def time_in_minues(minues): print '%d minues' % minues def minues2h_and_m(): minue = minues % 60 hours = minues // 60 return '%d : %d' % (hours, minue) return
2016-07-24 22:33:59 555
原创 python核心编程第十章练习
10-6def safe_open(filename, mode): try: f = open(filename, mode) except IOError: f = None return fsafe_open('10-6test.txt', 'w')safe_open('10-6test', 'w')10-8ef safe
2016-07-24 21:23:16 400
原创 python核心编程第九章练习
9-2#!/user/bin/env python# -*- coding:utf-8 -*-F = raw_input('Enter a filename ')N = int(raw_input('Enter lines to display '))filename = file(F, 'r')for eachLine in filename: if N != 0:
2016-07-24 21:04:42 427
原创 python核心编程第八章练习
8-2f = int(raw_input('from: '))t = int(raw_input('to: ')) i = int(raw_input('increment: '))for n8-4def isprime(num): for i in range(2, num): if num % i == 0: return False return True
2016-07-24 19:41:14 456
原创 python核心编程第七章练习
7-3(a)dic = {'Jack': 'man', 'Amy': 'woman', 'Lorry': 'woman', 'Json': 'man'}print sorted(dic)7-3(b)dic = {'Jack': 'man', 'Amy': 'woman', 'Lorry': 'woman', 'Json': 'man'}for key in sorted(dic):
2016-07-24 19:30:57 393
原创 python核心编程第六章练习
#!/user/bin/env python# -*- coding:utf-8 -*-def findchr(string, char): '''(a)创建一个叫findchar()的函数,查找字符char是否在string中,找到就返回该值的索引,否则返回-1。''' if char in string: y = 0 char_lens = len(char) stri
2016-07-23 23:22:38 405
原创 python核心编程第五章练习
5-3.Standard Type Operators。def get_letter_grade(score): if score >0 and score <100: if score >=90: return 'A' elif score >=80: return 'B' elif score >=70: return 'C' elif score >=
2016-07-23 22:58:44 466
空空如也
python 爬虫 出现IOError错误
2016-04-29
TA创建的收藏夹 TA关注的收藏夹
TA关注的人