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

PythonÖеÄ×Ö·û´®Óë×Ö·û¼¯

PythonÖ§³Öascii×Ö·û´®£¬unicode×Ö·û´®£¬ÒÔ¼°¸÷ÖÖ×Ö·û¼¯£¬ÄÇôËüÃǵ½µ×¸÷ÊÇʲô¸ÅÄÏ໥֮¼ä´æÔÚºÎÖÖ¹ØϵÄØ£¿
ÔÚPythonÖУ¬ascii×Ö·û´®£¬¼´strÀàÐ͵ÄÖµ£¬¿ÉÄÜÓÃÀ´±íʾÈÎÒâµÄÒ»¿é´æ´¢¿Õ¼ä£¬ÄÇôҲ¾ÍÊÇ˵£¬Õâ¸ö×Ö·û´®ÄÚ²¿¿ÉÒÔÊÇÈκÎÖµ£¬ÀýÈ磺¿É¼û×Ö·û×é³ÉµÄ×Ö·û´®£¬»òÕßÒ»¶Î¶þ½øÖÆÊý¾ÝµÈ¡£unicode×Ö·û´®£¬¼´unicodeÀàÐ͵ÄÖµ¡£
strÓëunicode¶¼ÊÇ×Ö·û´®µÄÒ»ÖÖ£¬¼Ì³ÐÓÚbasestring£¬¶¼Êdz£Á¿£¬¶¼²»¿ÉÐ޸ġ£Èç¹ûÐÞ¸Ä×Ö·û´®£¬ÄÇôʵ¼ÊÉÏÊDzúÉúÁËÒ»¸öеÄ×Ö·û´®¡£
×Ö·û¼¯ÊÇÎÒÃÇËùʹÓõÄ×Ö·û±àÂëµÄ¼¯ºÏ¡£×Ö·û¼¯¶Ôascii×Ö·û´®²ÅÓÐÒâÒ壬ÒòΪÔÚpythonÖи÷ÖÖ²»Í¬×Ö·û¼¯µÄ×Ö·û´®¶¼ÊÇÓÃstr±íʾ(±¾ÖÊÉϾÍÊÇÒ»¶Î´æ´¢¿Õ¼ä)¡£×îС×Ö·û¼¯×ÔÈ»ÊÇascii×Ö·û¼¯¡£È»ºó£¬¶ÔÓÚÖÐÎÄÓû§£¬³£ÓÃ×Ö·û¼¯ÊÇgbk£¬gb2312£¬»òÕßgb18030¡£ÆäÖУ¬gb18030ÊÇÇ°ÃæÁ½Õߵij¬¼¯£¬Ò²¾ÍÊÇ˵¼æÈÝgbkÓëgb2312µÄ¡£ÍƼöʹÓõÄÊÇgb18030£¬ÒòΪÕâÊÇеĹú¼Ò±ê×¼¡£cp936×Ö·û¼¯ÊÇÓëgbkÏà¶ÔÓ¦µÄ¡£ÆäËû³£ÓõÄ×Ö·û¼¯»¹ÓÐutf-8£¬Õâ¸öÊÇXMLÖо­³£Ê¹Óõġ£
ÓÐЩ×Ö·û¼¯Äܱíʾ¼¸ºõËùÓеÄÈËÀàÓïÑÔ×Ö·û£¬ÀýÈ磬utf-8£¬ÕâÒ²ÊÇxmlÑ¡ÔñÆä×öĬÈÏÊä³ö×Ö·û¼¯µÄÖØÒªÔ­Òò¡£ÓÚÊǾʹæÔÚÕâÑùÒ»ÖÖת»»ÎÊÌ⣺һ¶ÎÖÐÎÄ×Ö·û´®£¬Æä×Ö·û¼¯ÊÇgb18030µÄ£¬ÈçºÎת»¯Îªutf-8µÄ×Ö·û¼¯±íʾµÄ×Ö·û´®ÄØ£¿
ÔÚpythonÖУ¬ÕâÊÇͨ¹ýdecodeÓëencodeÁ½¸öº¯Êý½øÐеġ£
decode£¬¸ºÔð£ºstr---->unicode£»
encode£¬¸ºÔð£ºuncidoe---->str£»
ÓÚÊÇÎÒÃÇ¿ÉÒÔÕâÑùʵÏÖת»»£º
example_gb18030 = "ÄãºÃ£¬ÊÀ½ç£¡"
example_utf8 = example_gb18030.decode("gb18030").encode("utf-8")
¶ÔÓÚpython½âÊÍÆ÷×Ö·û¼¯¸ÅÄîµÄÀí½âÖ÷Òª¼¯ÖÐÔÚÁ½¸öµØ·½£º1¡¢½Å±¾µÄ×Ö·û¼¯£»2¡¢½âÊÍÆ÷×Ö·û¼¯¡£
Ç¿µ÷£ºÉÏÃæËù˵µÄ1¡¢2Á½µã¾ø¶Ô²»ÊÇͬһ¸ö¸ÅÄî¡£
½Å±¾×Ö·û¼¯ÊÇÔÚÖ¸½Å±¾±¾ÉíʹÓúÎÖÖ×Ö·û±àÂëµÄ¡£Ä¬ÈÏ£¬python½âÊÍÆ÷ÈÏΪÊÇascii×Ö·û¼¯¡£Èç¹ûÓöµ½·Çascii×Ö·û¾Í»á±¨´í´¦Àí¡£Èç¹ûÐèҪʹÓ÷Çascii×Ö·û£¬ÄÇô±ØÐëÔڽű¾µÄ¿ªÊ¼Î»ÖÃÉùÃ÷½Å±¾µÄ×Ö·û¼¯£¬ÀýÈç:
# coding=gb18030
ÕâÀï±¾ÖÊÉÏÊǸæËß½âÊÍÆ÷£¬Ê¹ÓúÎÖÖ×Ö·û¼¯²ÅÄÜÕýÈ·µØ½âÊͽű¾¡£
½âÊÍÆ÷×Ö·û¼¯ÊÇÖ¸½âÊÍÆ÷ÄÚ²¿ÈÏΪµÄascii×Ö·û´®µÄ×Ö·û¼¯¡£»»¾ä»°Ëµ£¬ÊǽâÊÍÆ÷½«ascii×Ö·û´®µ±×÷ºÎÖÖ×Ö·û¼¯À´´¦Àí¡£Ä¬ÈÏ£¬python½âÊÍÆ÷ÊÇascii×Ö·û¼¯µÄ¡£½âÊÍÆ÷×Ö·û¼¯»áÓ°ÏìһЩÒþʽ²Ù×÷¡£ÎÒÃÇÖªµÀ£¬str(X)Óëunicode(X)¿ÉÒÔ·Ö±ð½«Xת»»³ÉÒ»¸öascii×Ö·û´®»òÕßunicode×Ö·û´®¡£ÔÚXÊÇunicodeʱ£¬str(X)Ôò»á½øÐÐÀàËÆX.encode(xxxx)µÄ²Ù×


Ïà¹ØÎĵµ£º

Python ÓÎÏ·³õѧ

import sys, pygame, time
size = width, height = 700,700
fontColor = (0,0,255)
class walk:
'''This is a game about war.
Just like war 3.'''
def __init__(self):
'''Init the screen.
Get param and init the screen'''

#print ('this is init funnction') ......

python Ö® pilÉú³ÉÑéÖ¤ÂëͼƬ

#!/usr/bin/python
#coding=utf-8
import Image,ImageDraw,ImageFont,os,string,random,ImageFilter
def initChars():
"""
ÔÊÐíµÄ×Ö·û¼¯ºÏ£¬³õʼ¼¯ºÏΪÊý×Ö¡¢´óСд×Öĸ
usage: initChars()
param: None
return: list
·µ»ØÔÊÐíµÄ×Ö·û¼¯ºÍ
for: picCheckerÀà³õʼ×Ö·û¼¯ºÏ
todo: ......

Python³õѧ±Ê¼Ç£¨×ªÔØ£©


while µÄÓ÷¨£º
while ºóÃæ¸úÌõ¼þ±í´ïʽ£¬(:)ºóÃæ¸úÓï¾ä¿é£¬Äã¿ÉÒÔÔÚÕâ¶ÎÓï¾ä¿éÀïÐÞ¸ÄÌõ¼þ±í´ïʽµÄijЩ±äÁ¿£¬µ±Ìõ¼þ±í´ïʽ Ϊ¼ÙµÄʱºòÍ˳öÑ­»·¡£ÀýÈ磺
flag = 5
while flag > 0:
#ÕâÀïÊÇÄãµÄ´úÂë
flag -= 1
#if flag == 3: break
#if flag == 3: continue
print flag
µ±È»ÄãÒ²¿ÉÒÔÔÚÊʵ ......

python »ù´¡

   Python¿ìËÙÈëÃÅ
                        Ŀ¼
1. µÚÒ»Õ Python¿ìËÙÈëÃÅ
                &nbs ......

PythonÖÐÖ´ÐÐshellÃüÁîµÄʵÀý

1¡£
myCoolVariable="some_string"
os.system("echo myCoolVariable")
2.
>>> os.system('echo "asdg"')
asdg
0
>>> os.system("echo 'asdgwere'")
asdgwere
0
3.
$ python
>>>hamburger="potato"
>>>import os
>>>os.system("echo 'hamburger'")
potato
0
......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ