python 3 定位修改文件中二维数的组某一个元素

fo = open("test.txt","w")
print("fileName:",fo.name)

MapList = [[0 for i in range(40)]for i in range(40)]  # 创建二维数组

for row in range(40):
    for col in range(40):
       if( row==0 or col==0 or row==39 or col==39):
               MapList[row][col]=1

for row in MapList:
    fo.write(str(row)+"\n")

fo.flush()
fo.close()



fo = open("test.txt","r")
print("文件名:",fo.name)

# 怎样定位修改某个元素
line = fo.readline()

print("读取的数据为:%s" % (line))

fo.flush()
fo.close()
查看回复