上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 38 下一页
摘要: commands 模块包含一些用于执行外部命令的函数. Example 3-7展示了这个模块.3.5.0.1. Example 3-7. 使用 commands 模块import commandsstat, output = commands.getstatusoutput("ls -lR")pri... 阅读全文
posted @ 2014-01-13 14:27 前行者2011 阅读(106) 评论(0) 推荐(0) 编辑
摘要: 转载地址:http://hi.baidu.com/liheng_2009/item/28525511e5061a07b88a1a5e1.用os.system(cmd)不过取不了返回值2.用os.popen(cmd)要得到命令的输出内容,只需再调用下read()或readlines()等如a=os.p... 阅读全文
posted @ 2014-01-13 14:13 前行者2011 阅读(103) 评论(0) 推荐(0) 编辑
摘要: 使用生成器:#coding:utf-8--使用生成器,返回小于n的元素值,myield函数返回一个生成器对象def myyiled(n): a,b=0,1 while a<n: yield a a,b=a+b,a--使用生成器,返回前n项的元素值,my函数返回... 阅读全文
posted @ 2014-01-13 10:28 前行者2011 阅读(159) 评论(0) 推荐(0) 编辑
摘要: 定义的类与基类可以可以放在不同的模块,例如:定义类 DerivedClassName,继承modname模块中的BaseClassName类class DerivedClassName(modname.BaseClassName):派生类定义的执行过程和基类是一样的。构造派生类对象时,就记住了基类。... 阅读全文
posted @ 2014-01-10 17:54 前行者2011 阅读(133) 评论(0) 推荐(0) 编辑
摘要: #coding:utf-8'''用途:接收用户输出的参数,如果参数长度小于3,则抛出异常;如果参数中包含英文中的句号,则抛出相应的异常否则,输出参数中各个字符对应的ascii码值'''import sysclass lengthlimit: def __init__(self,length,a... 阅读全文
posted @ 2014-01-09 14:21 前行者2011 阅读(124) 评论(0) 推荐(0) 编辑
摘要: 导入模块方法一(建议用此种方法):package下要有 __init__.py文件from package import moduleimport modulefrom package.module import func导入模块方法二:import语句按如下条件进行转换:执行from packae... 阅读全文
posted @ 2014-01-06 14:20 前行者2011 阅读(93) 评论(0) 推荐(0) 编辑
摘要: Ubuntu下的安装方法:sudo apt-get install shuttershutter 不能编辑的解决办法:shutter是一个非常好的抓图工具,最近在ubuntu下使用它来截图发现不能直接编辑图片了,在网上搜索了一翻,真解很少,后来还是在ubuntu中文论坛中找到答案,原来是需要新的包在... 阅读全文
posted @ 2014-01-05 09:16 前行者2011 阅读(116) 评论(0) 推荐(0) 编辑
摘要: >>> import pprint >>> pprint.pprint(data) ('this is a string', [1, 2, 3, 4], ('more tuples', 1.0, 2.3, 4.5), 'this is yet another string') >>... 阅读全文
posted @ 2014-01-03 16:40 前行者2011 阅读(115) 评论(0) 推荐(0) 编辑
摘要: 总结:内部函数,不修改全局变量可以访问全局变量内部函数,修改同名全局变量,则python会认为它是一个局部变量在内部函数修改同名全局变量之前调用变量名称(如print sum),则引发Unbound-LocalError在程序中设置的sum属于全局变量,而在函数中没有sum的定义,根据python访... 阅读全文
posted @ 2014-01-01 16:35 前行者2011 阅读(164) 评论(0) 推荐(0) 编辑
摘要: dive into python P350移除连续重复的字符串元素b='abccdefekjllj'def remove(): a2=b[0] for i in b[1:]: if a2[-1]!=i: a2+=i print a2 #abcdefekjlj 阅读全文
posted @ 2014-01-01 15:53 前行者2011 阅读(183) 评论(0) 推荐(0) 编辑
上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 38 下一页