python ---- read txt file

1. read txt file

path = os.getcwd () + '\\ dig shellfish times crawling online time record .txt' // ( two \\ a \ the turn and, os.getcwd get the current directory )
f = Open (path, ' RB ') // ( RB read-only )
pasttime reached, f.read = ()

2. write txt file

path = os.getcwd () + '\\ shellfishing internet times crawling time record .txt'

f=open(path,'wb')     //(wb 为只写)
now =datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')#datetime.datetime 转str
f.write((now).encode('utf-8'))
f.close()

 

Guess you like

Origin www.cnblogs.com/11wangxin7/p/11612795.html