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 the third line.
>>>
相关文档:
在网上搜不到关于 Ascii 和 bcd互相转化的文章,于是自己写了一个,和大家分享下。
没有考虑到效率,能够优化的地方望大家提出
"""
AscII字符转换为BCD字符
"""
def asc2bcd(inAsc, pad_L0_R1 = 0):
#全部转换为大写,为后面的转换提供方便
inAsc = inAsc.upper()
&nb ......
1. Basic
参考《Python正则表达式操作指南》
模块re,perl风格的正则表达式
regex并不能解决所有的问题,有时候还是需要代码
regex基于确定性和非确定性有限自动机
2. 字符匹配(循序渐进)
元字符
. ^ $ * + ? { [ ] \ | ( )
1) "[" 和 "]"常用来指定一个字符类别,所谓字符类别就是你想匹配的一个字符集。如[ ......
关于C++和Python之间互相调用的问题,可以查找到很多资料。本文将主要从解决实际问题的角度看如何构建一个Python和C++混合系统。
&nbs ......
# 017
def lifeIsAMirror():
string = raw_input()
if string == 'I love you!':
return 'I love you, too!'
elif string == 'Fuck you!':
return ''
else:
return
# end of def
string = lifeIsAMirror()
if len(string) == 0:
print 'You have nothing.'
else: ......