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
Ïà¹ØÎĵµ£º
Àý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
_ ......
Ô´´úÂëÏÂÔØ£ºÏÂÔصØÖ·ÔÚÕâÀï
# 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! ......
Ô´´úÂëÏÂÔØ£ºÏÂÔصØÖ·ÔÚÕâÀï
# 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
......
µÚ¾Å¹Ø Image
´ÓÒ³ÃæÉϵÄͼƬ¿ÉÒÔ¿´µ½ÓÐÒ»´®µã£¬ÄÇôÊDz»ÊÇ´ú±í¸Ã¹ØÓëͼÏñµãÓйأ¿ ÎÒÃÇ´ÓÒ³ÃæÔ´Âë¿ÉÒÔ¿´µ½£¬ÓÐÁ½¶ÎÊý×ÖÐòÁÐfirstºÍsecond£¬¶øÓÐÒ»¸öÌáʾfirst+second=? ʲôÒâ˼ÄØ£¿ÄѵÀÊÇ˵(first, second)´ú±íÁËͼÏñµãµÄ×ø±ê£¿²»Ïñ£¬Á½¶ÎÐòÁеij¤¶ÈÓкܴó²îÒì¡£ÄÇôËã·û+»¹ÓÐʲôº¬ÒåÄØ£¬Óп ......
Ê×ÏÈÊÇÏÂÔØpython3£¬ÏÖÔÚµÄ×î¸ß°æ±¾ÊÇ3.1.1
for linux¡£
ÎҵķÅÖ÷¾¶ÊÇ/home/pythonÏ·ÅÖÃPython-3.1.1.tgz,Ö´ÐÐÒÔÏÂϵÁвÙ×÷£º
1.½âѹ£ºtar zxvf Python-3.1.1.tgz----Éú³É½âѹ°üPython-3.1.1
2.ת»»µ½Python-3.1.1·¾¶Ï£¬Ö´ÐÐ./configure
3.make
4.make install
ÔÚrehl5ÖÐÒѾĬÈÏ°²×°ÁËpython2.4,ËùÒÔÒª×öÈçÏ ......