一、一维数据
1.一维数据在python中的表示形式
2.一维数据在文件中的存储方式
3.一维数据的处理
python
ls = ["北京","上海","深圳","广州"]
f = open("city.csv","w")
s = ",".join(ls)
f.write(s)
f.close()
python
f = open("city.csv","r")#另外建一个文件
info = f.read()
f.close()
ls = info.split(",")
print(ls)
二、二维数据
·二维数据在python中的表示形式
·二维数据在文件中的存储方式
·二维数据的处理
python
students = [
["学号","姓名","性别","年龄"],
["1002","李四","男","16"],
["1003","王五","女","19"],
]
f = open("students.csv","w")
for row in students:
s = ",".join(row) + "\n"
f.write(s)
f.close()
python
f = open("students.csv","r")#另外创建一个文件写
students = []
for line in f:
line = line.strip("\n")#去除换行符
temp = line.split(",")
students.append(temp)
f.close()
print(students)