讀取寫入檔案

2021-09-24 17:31:57 字數 985 閱讀 6380

file1=open('c:\\users\\administrator\\desktop\\text\\成績.txt','w+',encoding='gbk')

file1.write('''羅恩 23 35 44

哈利 60 77 68 88 90

馬赫 97 99 89 91 95 99

媽富爾 100 85 90''')

file1.close()

file1=open('c:\\users\\administrator\\desktop\\text\\成績.txt','r',encoding='gbk')

new=file1.readline()#readline函式,讀取首行

new1=file1.readlines()#readlines讀取多行

print(new)

print(new1)

file1.close()

last=

for i in new1:

data=i.split()#j將字串拆分成更小的字串,形成新的列表

sum=0

for score in data[1:]:

sum=sum+int(score)

re=data[0]+str(sum)+'\n'

print(re)

print(data)

print(last)

#寫入記事本

win=open('c:\\users\\administrator\\desktop\\text\\統計.txt','w',encoding='gbk')

win.writelines(last)#多行寫入

win.close()

a=['g','j','c']

b=''

a=b.join(a)#join函式,合併字串

print(a)

c='_'

a=c.join(a)

print(a)

寫入 讀取檔案

file類下面的方法 string str file.readalltext aa.txt system.text.encoding.getencoding utf 8 讀取檔案 console.writeline str console.read filestream類下面的方法 在當前目錄建立乙...

檔案讀取 寫入

這是我為了記錄知識隨寫,不喜勿噴 步驟 1.建立檔案流 filestream fs new filestream 路徑名稱 filemethod.提交方式,fileaccess.獲取方式 2.建立讀寫器 文文檔案讀 streamreader sr new streamreader fs 二進位制檔案...

讀取寫入ini檔案

1.所用的winapi函式原型為 其中各引數的意義 lpctstr lpstring 是鍵值,也就是變數的值,不過必須為lpctstr型或cstring型的.lpctstr lpfilename 是完整的ini檔名.2.具體使用方法 設現有一名學生,需把他的姓名和年齡寫入 c stud studen...