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

ÓÃPythonÖ±½ÓдUTF 8Îı¾Îļþ

µ±ÎÒÃÇÕâÑù½¨Á¢Îļþʱ
f =
file('x1.txt', 'w')
f.write(u'ÖÐÎÄ')
f.colse()
Ö±
½Ó½á¹ûÓ¦¸ÃÊÇÀàËÆ
    f.write(u'ÖÐÎÄ')
UnicodeEncodeError: 'ascii'
codec can't encode characters in position 0-16: ordinal not in
range(128)
ÒªÖ±½Óд utf-8 ÎļþÔõô°ìÄØ?
import codecs
f = codecs.open("pru_uni.txt", "w", "utf-8")
txt = unicode("campeón\n", "utf-8")
f.write(txt)
f.write(u'ÖÐÎÄ\n')
f.close()


Ïà¹ØÎĵµ£º

»ù±¾Êý¾Ý½á¹¹µÄ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¶ÁдÎļþ


1.open
ʹÓÃopen´ò¿ªÎļþºóÒ»¶¨Òª¼ÇµÃµ÷ÓÃÎļþ¶ÔÏóµÄclose()·½·¨¡£±ÈÈç¿ÉÒÔÓÃtry/finallyÓï¾äÀ´È·±£×îºóÄܹرÕÎļþ¡£
file_object = open('thefile.txt')
try:
     all_the_text = file_object.read( )
finally:
     file_object.close( )
×¢£º²»Ä ......

ÓÃEclipse±àÒëÏòsqliteÊý¾Ý¿â²åÈëÊý¾ÝµÄpython³ÌÐò

½ñÌìÓöµ½ÁËÂé·³£º
      ÓÃEclipse±àÒëpythonÏòsqliteÊý¾Ý¿â²åÈëÊý¾Ý×ÜÊÇÌáʾ±àÂëµÄÎÊÌ⣬ÎÒÉèÖÃÁËEclipseµÄworkspaceÓÃutf-8±àÂ뻹ÊDz»ÐÐ
µ«ÊÇÓÃEclipseдµÄ³ÌÐò±£´æÔÙÓÃIDLE´ò¿ªÈ´ÄܱàÒ룬Ææ¹ÖÁË
ÎÒ¿¼Âǵ½¿ÉÄÜÊÇÅäÖõÄÔ­Òò£¬ÕÒÕÒ±éÁËËùÓеÄÅäÖ㬶¼Ã»ÓÐÎÊÌ⣬°üÀ¨¹¤³ÌÎļþ
×îºóÎÒÓÃxvi32´ò¿ ......

»°ËµPython£¨Î壩¿ªÊ¼Æð·É°É

    С°×¶ÔÉϽڿÎÀïµÄ“СÂéȸ”ÐËȤ°»È»£¬ÕûÌì¾ÍÔÚËÞÉáµ·¹Ä¡£Õâ²»£¬¼¸ÌìÏÂÀ´ËûÒѾ­¹¥ÏÂÊ®¼¸¸öÍøÕ¾ÁË¡£
С²Ëȴϲ»¶Ò»¸öÈË×øÔÚµçÄÔÅԱߣ¬Öå×Åüͷ£¬ÐÀÉÍ×ÅÕâÒ»ÐÐÐÐ×Ô¼º¿´²»¶®µÄ´úÂë¡£“ÕâЩ×Ö·ûºÃ¹ÖÒìѽ£¡”С²ËÍá×ÅÍ·£¬“ËüΪɶ½ÐÕýÔò±í´ïʽÄØ£¿”
°Ù¶Èһϣ¬ÖÕÓÚÖªµÀ¡£Ð¡² ......

PythonÕýÔò±í´ïʽ

ÕýÔò±í´ïʽÊǸöħ¹í£¬Ò²ÊǸöÌìʹ¡£ÔÚÄãûÓÐÕÆÎÕËü֮ǰ£¬ËüÊÇħ¹í£¬ÔÚÄãÕÆÎÕËüºó£¬ËüÊÇÌìʹ£¬µ«ÊÇ£¬Ê±
²»Ê±»¹ÊÇÒªÌø³öÀ´£¬¸øÄãµ÷Ƥµ·µ°Ò»·¬¡£


Ò»¸öÕýÔò±í´ïʽ¾ÍÊÇÓÉÆÕͨ×Ö·ûÒÔ¼°ÌØÊâ×Ö·û×é³ÉµÄÎÄ×Öģʽ£¬¸ÃģʽÃèÊöÔÚ²éÕÒÎÄ×ÖÖ÷Ìåʱ´ý
Æ¥ÅäµÄÒ»¸ö»ò¶à¸ö×Ö·û´®¡£ÕýÔò±í´ïʽ×÷Ϊһ¸öÄ£°å£¬½«Ä³¸ö×Ö·ûģʽÓëËùËÑË÷µÄ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ