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
Ïà¹ØÎĵµ£º
¼¯ºÏÀàÐͲÙ×÷·û£¨ËùÓеļ¯ºÏÀàÐÍ£©
ÁªºÏ( | )
ÁªºÏ(union)²Ù×÷ºÍ¼¯ºÏµÄOR(ÓֳƿɼæÎöÈ¡(inclusive
disjunction))ÆäʵÊǵȼ۵ģ¬Á½¸ö¼¯
ºÏµÄÁªºÏÊÇÒ»¸öм¯ºÏ£¬¸Ã¼¯ºÏÖеÄÿ¸öÔªËض¼ÖÁÉÙÊÇÆäÖÐÒ»¸ö¼¯ºÏµÄ³ÉÔ±£¬¼´£¬ÊôÓÚÁ½¸ö¼¯ºÏÆä
ÖÐ
Ö®Ò»µÄ³ÉÔ±¡£ÁªºÏ·ûºÅÓÐÒ»¸öµÈ¼ÛµÄ·½·¨£¬union().
Edit By Vheavens
Edit By Vhe ......
×î½üÔÚ´ÓÍ·¿ªÊ¼Ñ§Ï°Python, Ï£ÍûÓÃblog˳±ã¼Ç¼ÏÂÀ´Ò»Ð©Ð¡µÄ¼¼ÇÉ¡£
½ñÌì¼Ç¼µÚÒ»¸ö£º variable _
ÔÚpythonµÄ½»»¥sessionÖУ¬Ò²¾ÍÊDz»´øÎļþÃûÖ±½ÓÊäÈë"Python”Ö®ºópythonËù´´½¨µÄsession£¬
±äÁ¿"_"»á±£´æÉÏÒ»´Î¼ÆËãµÄ½á¹û¡£ÀýÈ磺
Õâ¸ö±äÁ¿¶Ô¾³£°Ñpythonµ±¼ÆËãÆ÷ÓõÄͬѧ¿ÉÄÜÓÐÓá£
²Î¿¼£ºsys.displayhook( ......
ÏÂÃæÁгöPythonÕýÔò±í´ïʽµÄ¼¸ÖÖÆ¥ÅäÓ÷¨£º
1.²âÊÔÕýÔò±í´ïʽÊÇ·ñÆ¥Åä×Ö·û´®µÄÈ«²¿»ò²¿·Ö
regex=ur"" #ÕýÔò±í´ïʽ
if re.search(regex, subject):
do_something()
else:
do_anotherthing()
2.²âÊÔÕýÔò±í´ïʽÊÇ·ñÆ¥ÅäÕû¸ö×Ö·û´®
regex=ur"\Z" #ÕýÔò±í´ïʽĩβÒÔ\ ......
Ò»¡¢Ê¹ÓÃPythonÐèÒªÖªµÀµÄ
ÔÚ Windows ÉÏ£¬°²×° Python ÓÐÁ½ÖÖÑ¡Ôñ¡£
1¡¢ActiveState ÖÆ×÷µÄ ActivePython ÊÇרÃÅÕë¶Ô Windows µÄ Python Ì×¼þ£¬Ëü°üº¬ÁËÒ»¸öÍêÕûµÄ Python ·¢²¼¡¢Ò»¸öÊÊÓÃÓÚPython ±à³ÌµÄ IDE ÒÔ¼°Ò»Ð© PythonµÄ Windows À©Õ¹£¬ÌṩÁËÈ«²¿µÄ·ÃÎÊ Windows APIs µÄ·þÎñ£¬ÒÔ¼° Windows×¢²á±íµÄ×¢²áÐÅÏ¢¡£ËäÈ ......
ÈçºÎдһ¸ö·µ»Ø¶à¸öÖµµÄº¯Êý
º¯ÊýµÄreturn Óï¾äÖ»ÄÜ·µ»ØÒ»¸öÖµ£¬¿ÉÒÔÊÇÈκÎÀàÐÍ¡£
Òò´Ë£¬ÎÒÃÇ¿ÉÒÔ“·µ»ØÒ»¸ö tupleÀàÐÍ£¬À´¼ä½Ó´ïµ½·µ»Ø¶à¸öÖµ
”¡£
Àý: x ³ýÒÔ y µÄÓàÊýÓëÉ̵ĺ¯Êý
def F1 ( x, y ):
a = x % y
  ......