Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

python stringºÍPyQtµÄQStringµÄÇø±ð

python stringºÍPyQtµÄQStringµÄÇø±ð ÒÔÏÂÔÚPython2.6ºÍPyQt4.4.4 for
Python2,6»·¾³ÏÂÌÖÂÛ£º PythonÖÐÓÐÁ½ÖÖÓйØ×Ö·ûµÄÀàÐÍ£ºPython string objectºÍPython Unicode
object¡£Ö÷ҪʹÓÃPython string object½øÐÐÊý¾ÝÊäÈëÊä³ö¡£ PyQtÖÐÓëÖ®Ïà¶ÔÓ¦µÄ×Ö·ûÓйØÀà
python stringºÍPyQtµÄQStringµÄÇø±ð
ÒÔÏÂÔÚPython2.6ºÍPyQt4.4.4 for Python2,6»·¾³ÏÂÌÖÂÛ£º
PythonÖÐÓÐÁ½ÖÖÓйØ×Ö·ûµÄÀàÐÍ£ºPython string objectºÍPython Unicode object¡£Ö÷ҪʹÓÃPython string object½øÐÐÊý¾ÝÊäÈëÊä³ö¡£
PyQtÖÐÓëÖ®Ïà¶ÔÓ¦µÄ×Ö·ûÓйØÀàÐÍÊÇ£ºQByteArrayºÍQString¡£Ö÷ҪʹÓÃQString²Ù×÷Êý¾Ý¡£
1. PythonºÍPyQtÖеÄÀàÐͶÔÓ¦
×¢ÒâÊÇÀàÐÍÏàËÆ£¬²»ÊÇÏàµÈ¡£
ÐèÒªÏÈÁ˽â±àÂ룺ascii¡¢gb2312¡¢big5£¬ÕâЩÊǸ÷¹ú×Ô¼ºÎÄ×Ö²»Í¬µÄ±àÂ룻unicode£¬¹ú¼ÊͨÓñàÂ룬¾ÍÊÇÇÕâ¸öÊÀ½çÉÏËùÓеÄÎÄ×Ö£¬¸ø
ÿ¸öÎÄ×Ö±àÒ»¸ö£¬ÓÖ·Öutf-8·½°¸--×ʹÓõÄ128¸öÓ¢ÎÄ×ÖĸÓÃÒ»¸ö×Ö½ÚÀ´±íʾ£¬¶øÖÐÎÄʹÓÃÈý¸ö×Ö½ÚÀ´±íʾ£¬utf-16·½°¸--ÆäÖÐÓ¢ÎĺÍÖÐÎͼ
ʹÓÃÁ½¸ö×Ö½ÚÀ´±íʾ£¬¶øÆäËü×Ö·û²ÉÓÃËĸö×Ö½Ú£¬utf-32·½°¸--ËùÓеÄÎÄ×Ö¶¼ÓÃËĸö×Ö½ÚÀ´±íʾ¡£
unicode¾Í¿ÉÓÃÀ´×÷Ϊ¸÷ÖÖ¶ÀÁ¢±àÂëÈçascii¡¢gb2312¡¢big5µÄת»»Öн顣
PythonÖÐgkb == gb2312¡£
1£©Python string object¿ÉÒÔÀí½âΪһ¸ö½ÓÒ»¸ö×Ö½Ú£¨byte£¬8룩µÄ×Ö½Ú×飬ÖÁÓÚ±íʾʲô±àÂ룬Óë±íʾÎÄ×ÖÓйأ¬È磺"python string"£¬"ÖÐÎÄ"¡£×¢ÒâËüÊÇÓв»Í¬±àÂëÇø·ÖµÄ£¡
PyQtÖÐÓëÖ®Ï൱µÄÊÇQByteArray£¬×¢Òâ²»ÊÇQString£¡
A built-in string object (plain or Unicode) is a sequence of characters
used to store and represent text-based information (plain strings are
also sometimes used to store and represent arbitrary sequences of
binary bytes). £¨Õª×Ô¡¶Python in a NutShell¡·£©
QByteArray can be used to store both raw bytes (including '"0's) and traditional 8-bit '"0'-terminated.£¨Õª×Ô¡¶PyQtÊֲᡷ£©
2£©Python Unicode object¿ÉÒÔÀí½âΪ¹Ì¶¨Ê¹ÓÃutf-16±àÂëµÄ×Ö½Ú×飬ÆäÖÐÓ¢ÎĺÍÖÐÎĶ¼Ê¹ÓÃÁ½¸ö×Ö½Ú£¨16룩À´±íʾ£¬È磺u"Python Unicode object"¡¢u"ÖÐÎÄ"¡£
PyQtÖÐÓëÖ®¶ÔÓ¦µÄ¾ÍÊÇQStringÁË¡£
Unicode string literals have the same syntax as other string literals,
with a u or U immediately before the leading quote. £¨Õª×Ô¡¶Python in a
NutSh


Ïà¹ØÎĵµ£º

PythonÄ£¿éѧϰ

¡¡¡¡ÓÐʱºò£¬Òª°ÑÄÚ´æÖеÄÒ»¸ö¶ÔÏó³Ö¾Ã»¯±£´æµ½´ÅÅÌÉÏ£¬»òÕßÐòÁл¯³É¶þ½øÖÆÁ÷ͨ¹ýÍøÂç·¢Ë͵½Ô¶³ÌÖ÷»úÉÏ¡£PythonÖÐÓкܶàÄ£¿éÌṩÁËÐòÁл¯Óë·´ÐòÁл¯µÄ¹¦ÄÜ£¬È磺marshal, pickle, cPickleµÈµÈ¡£½ñÌì¾Í½²½²marshalÄ£¿é¡£
¡¡¡¡×¢Ò⣺
marshal²¢²»ÊÇÒ»¸öͨÓõÄÄ£¿é£¬ÔÚijЩʱºòËüÊÇÒ»¸ö²»±»ÍƼöʹÓõÄÄ£¿é£¬ÒòΪʹÓÃmarshalÐ ......

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! ......

PythonÈëÃŵÄ36¸öÀý×Ó Ö® 32

Ô´´úÂëÏÂÔØ£ºÏÂÔØµØÖ·ÔÚÕâÀï
A Byte Of Python
ÖйØÓڼ̳ÐÓÐÕâÑùµÄÎÄ×Ö£º
Suppose you want to write a program which has to keep track of the
teachers and students in a college. They have some common
characteristics such as name, age and address. They also have specific
characteristics such as sala ......

PythonÈëÃŵÄ36¸öÀý×Ó Ö® 34

Ô´´úÂëÏÂÔØ£ºÏÂÔØµØÖ·ÔÚÕâÀï
raiseÓÐÁ½¸ö²ÎÊý£¬µÚÒ»¸öÊÇÓÉÎÒÃÇ×Ô¼º¶¨ÒåµÄÒì³£ÀàÐÍ£¬µÚ¶þ¸öÊǹØÓÚ´ËÒì³£µÄÉÙÁ¿ËµÃ÷ÐÅÏ¢¡£
# 038
def getAge():
age = input('Input your age:')
if (age < 0 or age > 160):
raise 'BadAgeError', 'It is impossible!!!!!'
# end of if
return age
# ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ