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

Python入门的36个例子 之 33

源代码下载:下载地址在这里
# 037
fileName = ''
while 1:
fileName = raw_input("Input a file name:")
if fileName == 'q':
break
try:
f = file(fileName, 'r')
print 'Opened a file.'
except:
print 'There is no file named', fileName
# end of try and except
f.close()
# end of while

output:
Input a file name:haha
There is no file named haha
Input a file name:txt
There is no file named txt
Input a file name:1
There is no file named 1
Input a file name:037_Exception.py
Opened a file.
Input a file name:q


相关文档:

python运算符 供重载参考

二元运算符及其对应的特殊方法
二元运算符
特殊方法
+
__add__,__radd__
-
__sub__,__rsub__
*
__mul__,__rmul__
/
__div__,__rdiv__,__truediv__,__rtruediv__
//
__floordiv__,__rfloordiv__
%
__mod__,__rmod__
**
__pow__,__rpow__
<<
__lshift__,__rlshift__
>>
_ ......

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个例子 之 25

源代码下载:下载地址在这里
# 028
consoleInput = raw_input('请输入点什么吧:')
aFile = file(r'C:\out.txt', 'w')
aFile.write(consoleInput + '\n')
aFile.write('这里是第二行')
aFile.close()

output:
>>>
请输入点什么吧:haha
>>>
......

Python入门的36个例子 之 29

源代码下载:下载地址在这里
# 033
class Person:
age = 22
def sayHello(self): # 方法与函数的区别在于需要一个self参数
print 'Hello!'
# end of def
# end of class # 这是我良好的编程风格
p = Person()
print p.age
p.sayHello()

output:
22
Hello! ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号