ÓÃÕ»½âÎöËãÊõ±í´ïʽ[Python°æ]
´úÂëÖвÉÓÃÁËÈý²½ÊµÏÖËãÊõ±í´ïʽµÄ½âÎö:
1. ½«ËãÊõ±í´ïʽ(×Ö·û´®)ת»»³ÉÒ»¸öÁбíparseElement·½·¨
2. ½«Áбí±íʾµÄËãÊõ±í´ïʽת»»³Éºó׺±í´ïʽchangeToSuffix
3. ¼ÆËãºó׺±í´ïʽµÄ½á¹û
ÕâÀïÎÒÊÇΪÁË·½±ã, ¾ÍдÁ˸öparseElement, ²»ÏëÄÇ·½·¨Ð´µ½ºóÃæÈ´°Ñ×Ô¼ºÈÆסÁË, ¿ÉÒÔÏëÏóÒ»¸ö´ø×ÔÔö, λ, Âß¼, ËãÊõµÄ±í´ïʽµÄÊýÖµÌáÈ¡ÊǶàôµÄ¸´ÔÓ...
parseElement×Ô¼º¸Ð¾õÊÇÒ»¸ö±È½Ïʧ°ÜµÄ·½·¨, ËùÒÔ´ÓÒ»¸öÆÕ±éµÄ½Ç¶ÈÀ´·ÖÎöÒÔÏÂËãÊõ±í´ïʽµÄ½âÎö:
ÒÔ(A + B) * C / D ** E + F * GΪÀý
µÚÒ»²¿·Ö: ½«ÖÐ׺±í´ïʽ(ÉÏÃæ¾ÍÊÇ, ¾ßÌåÈ¥²éÓйØǰ׺, ÖÐ׺, ºó׺±í´ïʽ)
ÕâÒ»²½ÐèÒªÒ»¸öÕ»ÓÃÀ´±£´æÔËËã·û, Ò»¸ö×Ö·û´®ÓÃÀ´±£´æÊä³öµÄºó׺±í´ïʽ
·ûºÅÕ»: signStack
ºó׺±í´ïʽ: result
¹ý³Ì: ¶ÁÈ¡±í´ïʽÖÐÿ¸öÔªËØ(Êý×Ö»òÔËËã·û, ÎÒµÄparseElementÒâÔÚ½â¾öÕâ¸öÎÊÌâ, È´×öµÄ²»³É¹¦)
ÔÔò:
1. ²Ù×÷ÊýÖ±½ÓÊä³öµ½result
2. (Ö±½Ó½øÕ»
3. )³öÕ»Ö±µ½Óöµ½Ò»¸ö"("(×¢Òâ: ÕâÀï"("±ØÐë³öÕ»), Öмä³öÕ»µÄÔªËØ°´³öջ˳ÐòÊä³öµ½result
4. ÆäËûÔËËã·û, ¼ì²éÕ»¶¥ÔªËØ, Èç¹ûÕ»¶¥±Èµ±Ç°ÔËËã·ûÓÅÏȼ¶¸ß»òÏàͬ(ÓÅÏȼ¶Ïàͬ, °´Ë³ÐòÖ´ÐÐ)ÔòÏȽ«Õ»¶¥³öÕ», ÔÙÈëÕ». Èç¹ûµ±Ç°ÔªËØÓÅÏȼ¶¸ß, ÔòÖ±½ÓÈëÕ».
²Ù×÷¹ý³ÌµÄ״̬±ä»¯
signStack |result | current char
------------------------------------------------------
( | |(
( |A |A
(, + | |+
(  
Ïà¹ØÎĵµ£º
Ô´´úÂëÏÂÔØ£ºÏÂÔصØÖ·ÔÚÕâÀï
# 032
# ÆäʵcPickleÕâ¸öÄ£¿éÆðµ½µÄ×÷ÓÿÉÒÔÓÓÍêÃÀµØе÷ÁËÎļþÖеÄÄÚÈÝ£¨¶ÔÏ󣩺ʹúÂëÖеÄÒýÓÔÀ´ÐÎÈÝ
import cPickle as p # ÕâÌõÓï¾ä¸øcPickleÆðÁ˸öСÃûp
objectFileName = r'C:\Data.txt'
aList = [1, 2, 3]
f = file(objectFileName, 'w')
p.dump(aList, f)
f.close ......
# 040
import time
try:
f = file('040_Finally.py')
while True:
line = f.readline()
if len(line) == 0:
break
time.sleep(0.33)
print line,
# end of while
finally:
f.close()
print 'Closed the file.'
# end of try
output£º
> ......
µÚ¾Å¹Ø 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,ËùÒÔÒª×öÈçÏ ......
filename=raw_input('enter file name:')
f=open(filename,'rb')
f.seek(0,0)
index=0
for i in range(0,16):
print "%3s" % hex(i) ,
print
for i in range(0,16):
print "%-3s" % "#" ,
print
while True:
temp=f.read(1)
if len(temp) == 0:
break
else:
print "%3s" % temp.encode('hex'),
......