Python ¶þ½øÖÆÎļþ¶ÁÈ¡ÏÔʾ
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'),
index=index+1
if index == 16:
index=0
print
f.close()
ÕâÀïÏÔʾµÄÊÇ£¬¶Áȡһ¸öBMPͼÏñºóµÄЧ¹û
´ÓÕâÀ¿ÉÒÔ¿´³ö£¬printÓï¾äºÍCµÄprintf¶Ô¸ñʽҪÇóÊÇÒ»Öµģ¬»òÕß˵£¬Python²ÉÓÃÁËCµÄ¸ñʽ¹æ·¶¡£
print "%-3s" % "#" ,
¶ººÅ·ÀÖ¹×Ô¶¯Éú³É»»Ðзû£¬-3±íʾÏÔʾռ3¸ö×Ö·û²¢ÇÒ´Ó×óÏÔʾ£¨Ä¬ÈÏ´ÓÓÒ£©¡£
f.read(1)
ÿ´Î¶ÁÒ»¸ö×Ö½Ú¡£Èç¹û¶Á³öÀ´µÄ³¤¶ÈΪ0£¬Ôòµ½ÁËÎļþĩβ¡£
PythonÓï·¨ÓкܶàÌØÊâµÄµØ·½£¬ÒÔºó»¹ÒªÂýÂýѧϰ
Ïà¹ØÎĵµ£º
Ô´´úÂëÏÂÔØ£ºÏÂÔØµØÖ·ÔÚÕâÀï
# 034
class Person:
def __init__(self, name):
self.name = name # ÕâÒ»¾äÖеÚÒ»¸önameÊÇÀàÖаüº¬µÄÓò£¬µÚ¶þ¸önameÊÇ´«½øÀ´µÄ²ÎÊý
# end of def
def sayHello(self):
print 'Hello!'
# end of def
# end of class
p = Person('Ning')
print p.nam ......
# 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,ËùÒÔÒª×öÈçÏ ......