- 寫檔
f = file( 'filename.txt' , 'w')
f.write('gy5566')
f.close()
- 讀檔
f = file( 'filename.txt' ) # 預設是 r
data = ''
while True :
line = f.readline()
if( len( line ) == 0 ) :
break
data += line
f.close()
- 取得日期
import time
time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()) )
- regular expression
import re
pattern = 'your regular expression'
process = re.compile( pattern , re.DOTALL ) # like '{}s'
# preg_match_all( $pattern , $page_content , $match_data );
match_data = process.findall( page_content )
# preg_replace
new_data = process.sub( 'new' , 'src_data' )
- file_get_contents
import urllib
def file_get_contents( URL ) :
fh = urllib.urlopen( URL )
page_contents = ''
for tmp in fh :
page_contents += tmp
return page_contents
- mail
import smtplib
http://www.eskimo.com/~jet/python/examples/mail/smtp1.html
沒有留言:
張貼留言