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

PythonÎļþµÄ¶Áд

Ïà±Èjava¶øÑÔ£¬PythonÓü¸ÐдúÂë¾Í¿ÉÒÔ´úÌæjavaÊ®À´ÐеĴúÂë£¬ÕæµÄ·Ç³£²»´í
'''
Created on 2009-9-2
@author: jiangqh
'''
# file create and write
context = '''hello world
hello china '''
f = file("hello.txt",'w')
f.write(context)
f.close()
Îļþ´´½¨
#use readline() read file
f = open("hello.txt")
while True:
line = f.readline()
if line:
print line
else :
break
f.close()
Ò»ÐÐÒ»ÐеĶÁÈ¡
# read more lines
f = file("hello.txt")
lines = f.readlines()
for line in lines:
print line
¶àÐжÁÈ¡
Ò»´ÎÐÔÈ«¶Á³öÎļþÀïµÄÄÚÈÝ
'''
Created on 2009-9-2
@author: jiangqh
'''
f = open("hello.txt")
context = f.read()
print context
f = open("hello.txt")
context = f.read(5) #¶ÁȡǰÎå×Ö½Ú
print context
print f.tell() #»ñµÃµ±Ç°Ö¸ÕëµÄλÖÃ
context = f.read(5) #¼ÌÐøµ±Ç°¶ÁÈ¡Îåλ
print context
print f.tell() #»ñµÃµ±Ç°Ö¸ÕëµÄλÖÃ
f.close()


Ïà¹ØÎĵµ£º

Python for win

Python²Ù×÷Excel·½·¨£º
£¨1£©ÔÚsourceforge.netÉÏÓÐÒ»¸öÀ©Õ¹Ä£¿é½ÐpyXLWriter£¬¿ÉÒÔ·½±ãµÄдExcelÎļþ¡£
£¨2£©ÏÂÔØwin32com°ü×°ÉÏ,Õâ¸ö°ü¿ÉÒÔµ÷ÓÃwindowsµÄcom¼°APIº¯ÊýµÈÕâÀàµÄ¹¦ÄÜ¡£PythonÀûÓÃwin32com²Ù×÷Excel¡£
Àý×Ó£º
#!/usr/bin/env python  
# -*- coding: utf-8 -*-  
from win32com. ......

UltraEdit»·¾³pythonÓï·¨¸ßÁÁÉèÖÃ

ÎÒÒ»Ö±ÔÚÓÃultraedit¿´zope3µÄÔ´´úÂë.Óï·¨¸ßÁÁÉèÖÿɲο¼www.ultraedit.com
UltraEditÊÇÒ»¸öºÜºÃµÄ¹¤¾ß£¬µ«ÊÇĬÈϲ»Ö§³ÖPythonµÄÓï·¨¸ßÁÁ£¬ÏÂÃæÊÇÒ»¸öÏֳɵÄWordFileƬ¶Ï£¬°ÑÕâ¶ÎÎÄ×ÖCopyµ½UltraEditÏÂÃæµÄWORDFIL E.TXTÎļþÖУ¬±£´æºó¾Í¿ÉÒÔ¿´µ½UltraEdit¶ÔPythonÎļþºÍÓï·¨µÄÖ§³ÖÁË^_^£¨×¢Ò⣬°Ñ/L11¸ÄΪÄãµÄWordfileµÄ ......

¶¯Ì¬ÓïÑÔÖ®Î壺PythonÓïÑÔÓëÉè¼ÆÄ£Ê½

 Éè¼ÆÄ£Ê½ÊÇÒ»¸ö³éÏó²ã´Î£¬ÃèÊöÁËÔÚÒ»¸öÌØ¶¨µÄ»·¾³ÖÐÓÃÀ´½â¾öÒ»°ãÉè¼ÆÎÊÌâµÄ¶ÔÏóºÍÀàÖ®¼äµÄ½»»¥¹ØÏµ£¬ÆäÖ÷ҪĿµÄÊdzä·ÖÀûÓÃÓïÑÔµÄÌØÐÔ£¬Éè¼Æ¿É¸´Óõġ¢Äܹ»ÊÊÓ¦ÐèÇó±ä¸üµÄÈí¼þ[9]¡£Éè¼ÆÄ£Ê½ÊÇÒ»ÖÖÉè¼ÆË¼Ï룬ÓïÑÔÊÇʵÏÖ˼ÏëµÄ¹¤¾ß¡£Òò´Ë£¬²»Í¬ÓïÑÔµÄÌØÐÔÓ°ÏìÁËÉè¼ÆÄ£Ê½µÄʵÏÖ£¬ÓÐЩÓïÑÔ¸üÈÝÒ×ʵÏÖÉè¼ÆÄ£Ê½£¬¶øÓÐЩÓïÑÔÔ ......

Pythonѧϰ±Ê¼Ç Îļþ¶Áд

PythonÖÐÎļþ²Ù×÷¿ÉÒÔͨ¹ýopenº¯Êý£¬ÕâµÄÈ·ºÜÏñCÓïÑÔÖеÄfopen¡£Í¨¹ýopenº¯Êý»ñȡһ¸öfile object£¬È»ºóµ÷ÓÃread()£¬write()µÈ·½·¨¶ÔÎļþ½øÐжÁд²Ù×÷¡£
1.open
ʹÓÃopen´ò¿ªÎļþºóÒ»¶¨Òª¼ÇµÃµ÷ÓÃÎļþ¶ÔÏóµÄclose()·½·¨¡£±ÈÈç¿ÉÒÔÓÃtry/finallyÓï¾äÀ´È·±£×îºóÄܹرÕÎļþ¡£
file_object = open('thefile.txt') ......

Python²éÕÒÌæ»»

>>> import string
>>> s='adbecf'
>>>
tt=string.maketrans("abc","ABC")
>>> s.translate(tt,"")
'AdBeCf'
>>>
s.translate(tt,"")
ºóÃæµÄÄǸö¿Õ×Ö·û´´¾ÍÊÇÄãҪɾ³ýµÄ×Ö·û£¬±ÈÈçҪɾ³ý»»ÐоÍÊÇs.translate(tt,"\n&q ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ