易截截图软件、单文件、免安装、纯绿色、仅160KB

Python入门的36个例子 之 36

# 040
import time
try:
f = file('040_Finally.py')
while True:
line = f.readline()
if len(line) == 0:
break
time.sleep(0.33)
print line,
# end of while
finally:
f.close()
print 'Closed the file.'
# end of try
output:
>>>
# 040
import time
try:
    f = file('040_Finally.py')
    while True:
        line = f.readline()
        if len(line) == 0:
            break
        time.sleep(0.33)
        print line,
    # end of while
finally:
    f.close()
    print 'Closed the file.'
# end of try
   
Closed the file.
>>>
源代码下载:下载地址在这里


相关文档:

Python入门的36个例子——05 聪明的变量

# 005
# 在Python中给变量赋值时不需要声明数据类型
i = 33
print i
# 可以这样做的原因是Python把程序中遇到的任何东西都看成是对象(连int也不例外)
# 这样,在使用对象时,编译器会根据上下文的环境来调用对象自身的方法完成隐式的转换
# 你甚至可以把程序写成这样
print 3 * 'haha '
# 但若写成这样编译器就会报错 ......

Python:FriendFeed的Tornado Web Server

代码很简单,不到5k行。但是思路挺好的,改成non-blocking了之后效率就是能提高不少,特别是考虑到现代的web app都需要和其他的
HTTP服务器通信,blocking的代价太大了。 Tornado is an open source version of the scalable, non-blocking web server and tools that power FriendFeed. The FriendFeed application ......

Python入门的36个例子 之 18

例1:
# _018
# This is a module (if write Chinese in a module, there will be a error)
def func1():
print 'This is function 1.'
def func2():
print 'This is function 2.'
def func3():
print 'This is function 3.'
# 019
# 使用“import”语句调用模块:
import _018_Module
_ ......

Python入门的36个例子 之 27

源代码下载:下载地址在这里
e.g.1
# 030
aFile = file(r'C:\temp.txt', 'a')
aFile.write('又添加了一行。')
aFile.close()

output:
e.g.2
# 030
aFile = file(r'C:\temp.txt', 'a')
aFile.write('又添加了一行。')
aFile.close()

output:
e.g.3
实现根据原始文件有没有最后一行空行的情况来进行&ldqu ......

Python入门的36个例子 之 28

源代码下载:下载地址在这里
# 032
# 其实cPickle这个模块起到的作用可以用“完美地协调了文件中的内容(对象)和代码中的引用”来形容
import cPickle as p # 这条语句给cPickle起了个小名p
objectFileName = r'C:\Data.txt'
aList = [1, 2, 3]
f = file(objectFileName, 'w')
p.dump(aList, f)
f.close ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号