0%
读取文件
1 2 3 4 5 6 7 8 9
| file = open ("./pvuv.txt", 'r', encoding='utf-8') for line in file.readlines (): print (line) file.close ()
file = open ("./pvuv.txt", encoding='utf-8') for line in file: print (line) file.close ()
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| with open ("./pvuv.txt", encoding='utf-8') as fin: print (type (fin))
with open ("./pvuv.txt", encoding='utf-8') as fin: print (fin)
with open ("./pvuv.txt") as fin: print (fin)
with open ("./pvuv.txt", encoding='utf-8') as fin: for line in fin: print (type (line))
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| datas = [] with open ("./pvuv.txt") as fin: is_first_line = True for line in fin: if is_first_line: is_first_line = False continue datas.append (line [:-1].split ("\t"))
datas = [] with open ("./pvuv.txt", encoding='utf-8') as fin: for line in fin: print (line [:].replace ('\n', ''))
|
1 2 3 4 5
| txt = "Google#Runoob#Taobao#Facebook"
x = txt.split ("#", 1) print x
|