ITeye博客

python

共 4 篇文章

分解质因数小脚本

awk语言的版本,如下: { x = $0; } function foo(a) { for (i = 2; i <= a; i++) if (a%i == 0) {printf("%d ",i);return i;} } END { c = foo(x); while (c < x) { x = x / c; c = foo(x); } } # usage(): $echo 2520 | awk -f script.awk 下边这个是一样思路的Bash版本,不过运行的非常慢。 #!/usr/bin/bash #usage(): $sh script.sh 2520 function foo…

2013-02-12 20:24 · Shell · python

django教程写的好

http://djangobook.py3k.cn/2.0/ 超赞,拜读。 python的web框架不要太多... django、flask、bottle、tornado...

2013-02-12 18:35 · python

python读入文件和time/sys模块的简单使用

python读入文件和time/sys模块的简单使用 一些标准库函数的用法也待学习,如:os/re/sets/string/queue/socket #!/usr/bin/python print ord('a') print chr(97) #字符和整型互相转换 fp = open("file.tmp") for line in fp.readlines(): print line, #文件操作readlines()函数一次读入多行,循环输出 for line in fp: print line, #!/usr/bin/python import time #time模块使用 print …

2013-02-12 17:11 · python

python写json示例

#!/usr/bin/python import json source = '{"name":"polyahu", "type":"title"}' f = open('./json.data') j = json.loads(source) r = json.load(f) s = json.dumps(j) print "j's type", print type(j) print "s's type", print type(s) json.loads()和json.dumps()是将str类型和dict类型互相转换。

2013-02-08 22:06 · python