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Óï·¨ÓкܶàÌØÊâµÄµØ·½£¬ÒÔºó»¹ÒªÂýÂýѧϰ
Ïà¹ØÎĵµ£º
# 027
toolName = 'Google'
if toolName.startswith('Go'):
print 'The tool\'s name starts with \"Go\".'
if 'oo' in toolName:
print 'The tool\'s name contains the stirng "oo".'
print toolName.find('gl') # ·µ»ØÊ״γöÏÖ“gl”×Ö·û´®µÄË÷Òý
if toolName.find('Baidu ......
Ô´´úÂëÏÂÔØ£ºÏÂÔØµØÖ·ÔÚÕâÀï
# 028
consoleInput = raw_input('ÇëÊäÈëµãʲô°É£º')
aFile = file(r'C:\out.txt', 'w')
aFile.write(consoleInput + '\n')
aFile.write('ÕâÀïÊǵڶþÐÐ')
aFile.close()
output£º
>>>
ÇëÊäÈëµãʲô°É£ºhaha
>>>
......
Ô´´úÂëÏÂÔØ£ºÏÂÔØµØÖ·ÔÚÕâÀï
e.g.1
# 030
aFile = file(r'C:\temp.txt', 'a')
aFile.write('ÓÖÌí¼ÓÁËÒ»ÐС£')
aFile.close()
output:
e.g.2
# 030
aFile = file(r'C:\temp.txt', 'a')
aFile.write('ÓÖÌí¼ÓÁËÒ»ÐС£')
aFile.close()
output:
e.g.3
ʵÏÖ¸ù¾ÝÔʼÎļþÓÐûÓÐ×îºóÒ»ÐпÕÐеÄÇé¿öÀ´½øÐÐ&ldqu ......
µÚ¾Å¹Ø Image
´ÓÒ³ÃæÉϵÄͼƬ¿ÉÒÔ¿´µ½ÓÐÒ»´®µã£¬ÄÇôÊDz»ÊÇ´ú±í¸Ã¹ØÓëͼÏñµãÓйأ¿ ÎÒÃÇ´ÓÒ³ÃæÔ´Âë¿ÉÒÔ¿´µ½£¬ÓÐÁ½¶ÎÊý×ÖÐòÁÐfirstºÍsecond£¬¶øÓÐÒ»¸öÌáʾfirst+second=? ʲôÒâË¼ÄØ£¿ÄѵÀÊÇ˵(first, second)´ú±íÁËͼÏñµãµÄ×ø±ê£¿²»Ïñ£¬Á½¶ÎÐòÁеij¤¶ÈÓкܴó²îÒì¡£ÄÇôËã·û+»¹ÓÐʲôº¬ÒåÄØ£¬Óп ......