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

Python¡¢UnicodeºÍÖÐÎÄ[ת]


¹Ø¼ü×Ö: python
Python¡¢UnicodeºÍÖÐÎÄ[ת] 
pythonµÄÖÐÎÄÎÊÌâÒ»Ö±ÊÇÀ§ÈÅÐÂÊÖµÄÍ·ÌÛÎÊÌ⣬ÕâÆªÎÄÕ½«¸øÄãÏêϸµØ½²½âÒ»ÏÂÕâ·½ÃæµÄ֪ʶ¡£µ±È»£¬¼¸ºõ¿ÉÒÔÈ·¶¨µÄÊÇ£¬ÔÚ½«À´µÄ°æ±¾ÖУ¬python»á³¹µ×½â¾ö´ËÎÊÌ⣬²»ÓÃÎÒÃÇÕâôÂé·³ÁË¡£ 
ÏÈÀ´¿´¿´pythonµÄ°æ±¾£º 
>>> import sys 
>>> sys.version 
'2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)]' 
£¨Ò»£© 
ÓüÇʱ¾´´½¨Ò»¸öÎļþChineseTest.py£¬Ä¬ÈÏANSI£º 
s = "ÖÐÎÄ" 
print s 
²âÊÔÒ»ÏÂÇÆÇÆ£º 
E:\Project\Python\Test>python ChineseTest.py 
  File "ChineseTest.py", line 1 
SyntaxError: Non-ASCII character '\xd6' in file ChineseTest.py on line 1, but no encoding declared; see http://www.pytho 
n.org/peps/pep-0263.html for details 
͵͵µØ°ÑÎļþ±àÂë¸Ä³ÉUTF-8£º 
E:\Project\Python\Test>python ChineseTest.py 
  File "ChineseTest.py", line 1 
SyntaxError: Non-ASCII character '\xe4' in file ChineseTest.py on line 1, but no encoding declared; see http://www.pytho 
n.org/peps/pep-0263.html for details 
ÎÞ¼ÃÓÚÊ¡£¡£¡£ 
¼ÈÈ»ËüÌṩÁËÍøÖ·£¬ÄǾͿ´¿´°É¡£¼òµ¥µØä¯ÀÀһϣ¬ÖÕÓÚÖªµÀÈç¹ûÎļþÀïÓзÇASCII×Ö·û£¬ÐèÒªÔÚµÚÒ»ÐлòµÚ¶þÐÐÖ¸¶¨±àÂëÉùÃ÷¡£°ÑChineseTest.pyÎļþµÄ±àÂëÖØÐ¸ÄΪANSI£¬²¢¼ÓÉϱàÂëÉùÃ÷£º 
# coding=gbk 
s = "ÖÐÎÄ" 
print s 
ÔÙÊÔһϣº 
E:\Project\Python\Test>python ChineseTest.py 
ÖÐÎÄ 
Õý³£¿©£º£© 
£¨¶þ£© 
¿´Ò»¿´ËüµÄ³¤¶È£º 
# coding=gbk 
s = "ÖÐÎÄ" 
print len(s) 
½á¹û£º4¡£ 
sÕâÀïÊÇstrÀàÐÍ£¬ËùÒÔ¼ÆËãµÄʱºòÒ»¸öÖÐÎÄÏ൱ÓÚÁ½¸öÓ¢ÎÄ×Ö·û£¬Òò´Ë³¤¶ÈΪ4¡£ 
ÎÒÃÇÕâÑùд: 
# coding=gbk 
s = "ÖÐÎÄ" 
s1 = u"ÖÐÎÄ" 
s2 = unicode(s, "gbk") #Ê¡ÂÔ²ÎÊý½«ÓÃpythonĬÈϵÄASCIIÀ´½âÂë 
s3 = s.decode("gbk") #°Ñstrת»»³ÉunicodeÊÇdecode£¬unicodeº¯Êý×÷ÓÃÓëÖ®Ïàͬ 
print len(s1) 
print len(s2) 
print len(s3) 
½á¹û£º 


Ïà¹ØÎĵµ£º

Install Python + Eric IDE


Install Python Eric IDE
1 Download following things
 
1) Python3.1
 
2) PyQt for python 3.1
(http://www.riverbankcomputing.co.uk/software/pyqt/download) I am using
PyQt-Py3.1-gpl-4.7.3-2.exe
 
3) Eric5 IDE
(http://eric-ide.python-projects.org/eric-download.html)
 
2 ......

»ù±¾Êý¾Ý½á¹¹µÄpythonʵÏÖ ¶ÓÁÐ

¶ÓÁУº
Óë¶ÑÕ»ÀàËÆ£¬Í¨¹ýpythonµÄÁбíÀàÐÍÀ´ÊµÏÖ£¬²Î¿¼ help(list)
shoplist=['apple','mango','carrot','banana']
print 'I have',len(shoplist),'items to purchase'
print 'these items are:'
for item in shoplist:
print item,
shoplist.append('rice')
print 'my shopping list is now', shoplist
shoplist. ......

Python TKinter Gui: Toplevel window

#from pp3e Chapter 9.3
#############################################################################
# popup three new window, with style
# destroy() kills one window, quit() kills all windows and app; top-level
# windows have title, icon, iconify/deiconify and protocol for wm events;
# there ......

¡¶Dive Into Python¡··ÇËÀ²»¿É

ÒëÕßÑÔ£º
ÔçÔÚ 2008 Äê 8 Ô£¬ÎÒ¾ÍÔøÔÚ×Ô¼ºµÄ²©¿Í·¢±íÁËһƪ¡¶ÎªÊ²Ã´<Dive into Python>²»ÖµµÃÍÆ¼ö¡·£¨http://blog.csdn.net/lanphaday/archive/2008/08/28/2845258.aspx
£©£¬µ±Ê±ÒýÆðµÄÌÖÂ۾Ͳ»¶à˵ÁË£¬²»¹ýÊÂʵÉϵ½½ñÌìÈÔÈ»ÓÐÐí¶àÅóÓÑÁôÑÔÓëÎÒÌÖÂÛ£¬ÈÃÎÒ¼¸´ÎÔôÐIJ»ËÀ£¬ÏëдÔÙÉîÈëÅúÅС£ºÃÔ˵ÄʱºòÔÚÎÒÕæÕýÔÜ×㶯Á ......

ʹÓÃPython¶ÁSEGYµÀÍ·

×Ô¼ºÓöµ½µÄÒ»¸öÎÊÌâ, WestGecoµÄ3DµØÕðÊý¾Ý, ÌáÈ¡µ¼º½Êý¾Ý:
#!/bin/env python
import sys
import struct
try:
        f=open(sys.argv[1],'rb')
except (IOError,Exception):
    print '''usage:
        scriptname segyfilename
'''
&nbs ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ