python上课笔记10:文件和异常

#10-1
with open ("data.txt") as data:
    print(data)
    print("~~~")
    b = []
    for a in data :
        print(a)
        b.append(a)
    print("~~~")

for c in b :
    print(c)

异常处理板块没啥好说的,这里跳过直接做json格式的数据

#10-11
import json
filename = 'ans.json'
num = input("input the number you want")
with open(filename,"w") as obj:
    json.dump(num , obj)
    print("we remember the number " + num)

阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页