易截截图软件、单文件、免安装、纯绿色、仅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个例子 之 19

源代码下载:下载地址在这里
# 023
# Tuple(元素组)是不可变的列表
tuple1 = (1, 2, 3)
print tuple1
tuple2 = (tuple1, 4, 5, 6) # 一个元素组可以作为另外一个元素组的元素
print tuple2 # 并且能够在存储的时候保持原始的逻辑关系
for ele in tuple2:
print ele
print '\n'
for ele in tuple2[0]:
pr ......

Python入门的36个例子 之 23

源代码下载:下载地址在这里
# 026
aList = ['1','2','3','4']
aListCopy = aList # 其实,这里仅仅复制了一个引用
del aList[0]
print aList
print aListCopy # 两个引用指向了了同一个对象,所以打印结果一样
aListCopy = aList[:] # 这是复制整个对象的有效方法
del aList[0]
print aList
print aListCopy
......

Python入门的36个例子 之 26

源代码下载:下载地址在这里
# 029
aFile = file(r'C:\in.txt', 'r')
while True:
line = aFile.readline()
if len(line) == 0:
break
# end of if
print line,
# end of while
aFile.close()

output:
>>>
This is the first line.
This is the second line.
This is ......

Python入门的36个例子 之 31

源代码下载:下载地址在这里
# 035
class Person:
population = 0 #这个变量是属于整个类的
def __init__(self, name):
self.name = name
print '初始化 %s' % self.name
Person.population += 1
# end of def
def __del__(self):
print '%s says bye.' % self. ......

Python入门的36个例子 之 35

源代码下载:下载地址在这里
# 039
while True:
try:
x = int(raw_input('Input a number:'))
y = int(raw_input('Input a number:'))
z = x / y
except ValueError, ev:
print 'That is not a valid number.', ev
except ZeroDivisionError, ez:
print 'Di ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号