近几日花了挺多时间在这上面,效果也较为显著,PMangar基本被实现了。期间有一些心得在这儿写下来做记录,顺便也分享:
I’ve been working on Python these days and here are some notes for it:
-
Python中不支持在string.find(str)中使用正则表达式,即str只能是string。
str in string.find(str) can not be a regular expression, it should be a string.
Code:
[python]
a=’abcd0123.py’
a.find(“[w]*.py”)
a.find(“0123.py”)#Result:
#-1
#4
[/python] -
使用for i in range(a,b)时,i的值可以等于a到不b-1而不会等于b。同理对于i[a:b]会截取i的第a至b-1个元素。
In Python, any operation involving a range of a to b means the value can be from a to b-1.
Code:
[python]
for i in range(0,2)
print i
a=”0123456789″
print a[3:7]#Result:
#0
#1
#3456
[/python] -
当已知一个字符的Unicode编码时,例如a=”u4eba”,可以通过unichr()和int()将其转换为相应字符的Unicode形式即b=”u4eba”
When you know the unicode number of a charactor, you can get the corresponding character by using unichr() and int().
Code:
[python]
a=r’u4eba’ #a is a string with 6 characters, the last 4 characters represents the unicode number of a chinese character “人”.
b=int(a[2:7],16) #Converting string to an decimal integer using base 16
c=unichr(int) #Find the corresponding unicode charactor of the number
print a
print b
print c#Result:
#u4eba
#20154 #<--This is the decimal number for hex num '4eba' #人 [/python]