摘要: 软件开发的过程 现在,我们已经走过了编写一个软件的各个环节。这些环节可以概括如下: 重要我们创建这个备份脚本的过程是编写程序的推荐方法——进行分析与设计。开始时实施一个简单的版本。对它进行测试与调试。使用它以确信它如预期那样地工作。再增加任何你想要的特性,根据需要一次次重复这个编写-测试-使用的周期 阅读全文
posted @ 2017-10-20 10:50 真勇士王小山 阅读(2187) 评论(0) 推荐(0) 编辑
摘要: exec语句用来执行储存在字符串或文件中的Python语句。例如,我们可以在运行时生成一个包含Python代码的字符串,然后使用exec语句执行这些语句。下面是一个简单的例子。 >>> exec 'print "Hello World"'Hello World eval语句用来计算存储在字符串中的有 阅读全文
posted @ 2017-10-20 10:13 真勇士王小山 阅读(127) 评论(0) 推荐(0) 编辑
摘要: #!/usr/bin/python# Filename: lambda.pydef make_repeater(n): return lambda s: s*ntwice = make_repeater(2)print twice('word')print twice(5) make_repeate 阅读全文
posted @ 2017-10-20 10:06 真勇士王小山 阅读(86) 评论(0) 推荐(0) 编辑
摘要: >>> def powersum(power, *args):... '''Return the sum of each argument raised to specified power.'''... total = 0... for i in args:... total += pow(i, 阅读全文
posted @ 2017-10-20 09:48 真勇士王小山 阅读(122) 评论(0) 推荐(0) 编辑
摘要: #!/usr/bin/python# Filename: list_comprehension.pylistone = [2, 3, 4]listtwo = [2*i for i in listone if i > 2]print listtwo 这里我们为满足条件(if i > 2)的数指定了一个 阅读全文
posted @ 2017-10-20 09:45 真勇士王小山 阅读(98) 评论(0) 推荐(0) 编辑
摘要: os模块 这个模块包含普遍的操作系统功能。如果你希望你的程序能够与平台无关的话,这个模块是尤为重要的。即它允许一个程序在编写后不需要任何改动,也不会发生任何问题,就可以在Linux和Windows下运行。一个例子就是使用os.sep可以取代操作系统特定的路径分割符。 下面列出了一些在os模块中比较有 阅读全文
posted @ 2017-10-20 00:52 真勇士王小山 阅读(99) 评论(0) 推荐(0) 编辑
摘要: #!/usr/bin/python# Filename: cat.pyimport sysdef readfile(filename): '''Print a file to the standard output.''' f = file(filename) while True: line = 阅读全文
posted @ 2017-10-20 00:49 真勇士王小山 阅读(268) 评论(0) 推荐(0) 编辑
摘要: #!/usr/bin/python# Filename: finally.pyimport timetry: f = file('poem.txt') while True: # our usual file-reading idiom line = f.readline() if len(line 阅读全文
posted @ 2017-10-20 00:41 真勇士王小山 阅读(139) 评论(0) 推荐(0) 编辑
摘要: #!/usr/bin/python# Filename: raising.pyclass ShortInputException(Exception): '''A user-defined exception class.''' def __init__(self, length, atleast) 阅读全文
posted @ 2017-10-20 00:35 真勇士王小山 阅读(157) 评论(0) 推荐(0) 编辑
摘要: #!/usr/bin/python# Filename: try_except.pyimport systry: s = raw_input('Enter something --> ')except EOFError: print '\nWhy did you do an EOF on me?' 阅读全文
posted @ 2017-10-20 00:30 真勇士王小山 阅读(110) 评论(0) 推荐(0) 编辑