Commit 7a529be9 by BellCodeEditor

auto save

parent 6babeaa4
import csv
subject = ["姓名", "语文", "数学", "英语"]
score1 = ["小贝", 98, 99, 92]
score2 = ["聪聪", 95, 91, 95]
# 创建csv并写入
with open("scores.csv", "w", encoding="utf-8") as csvfile:
writer = csv.writer(csvfile)
writer.writerow(subject)
writer.writerow(score1)
writer.writerow(score2)
\ No newline at end of file
import csv
subject = ["姓名", "语文", "数学", "英语"]
score1 = ["小贝", 98, 99, 92]
score2 = ["聪聪", 95, 91, 95]
# 创建csv并写入
with open("scores.csv", "w", encoding="utf-8") as csvfile:
writer = csv.writer(csvfile)
writer.writerow(subject)
writer.writerow(score1)
writer.writerow(score2)
\ No newline at end of file
import csv
data = [["姓名", "语文", "数学", "英语"],
["小贝", 98, 99, 92],
["聪聪", 95, 91, 95]]
# 创建csv并写入
with open("scores.csv", "w", encoding="utf-8",newline='') as csvfile:
writer = csv.writer(csvfile)
writer.writerows(data)
import csv
with open("report.csv","r",encoding='utf-8') as f:
f_csv = csv.reader(f)
f_csv = list(f_csv)
print(f_csv)
for i in range(len(f_csv[0])):
print(f_csv[7][i],end='/')
print()
for j in range(len(f_csv)):
print(f_csv[j][3],end='/')
\ No newline at end of file
姓名,语文,数学,英语
小贝,98,99,92
聪聪,95,91,95
95,92,94
......
import csv
data = [95,92,94]
#创建csV并写入
with open("scores.csv","w") as csvfile:
writer = csv.writer(csvfile)
writer.writerow(data)
\ No newline at end of file
import csv
data = [["姓名", "语文", "数学", "英语"],
["小贝", 98, 99, 92],
["聪聪", 95, 91, 95]]
#创建csV并写入
with open("scores.csv","w",encoding='utf-8',newline='') as csvfile:
writer = csv.writer(csvfile)
for i in data:
writer.writerow(i)
\ No newline at end of file
import csv
with open("scores.csv","r",encoding='utf-8') as f:
f_csv = csv.reader(f)
print(f_csv)
f_csv = list(f_csv)
print(f_csv)
# 输出:‘小贝’的‘数学’成绩是‘99’
print(f_csv[1][0]+'的'+f_csv[0][2]+'成绩是'+f_csv[1][2])
a=f_csv[1]
print(a[0])
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment