在 python 中写入文件后文件处理程序未打印
file handler is not printing after writing in to file in python
我正在尝试写入一个文件并在写入后读取。下面是我的代码。
with open('1.txt','w') as fr:
x = '3'
fr.write(x)
with open('1.txt','r') as fr_r:
fr_w = fr_r.read()
print (fr_w)
预期输出低于
3
你的代码应该是这样的(第二个没有缩进)
with open('1.txt','w') as fr:
x = '3'
fr.write(x)
with open('1.txt','r') as fr_r:
fr_w = fr_r.read()
print (fr_w)
一旦您使用 'with' 语句打开文件。你不需要关闭那个频道。出于这个原因 python 开发人员设置了一个限制,不能在此块中写入或使用另一个权限通道。
once read /write permission in opened we cannot add another permission channel in that block or indentation. it should be in seperate indentation like this below as follows``
我正在尝试写入一个文件并在写入后读取。下面是我的代码。
with open('1.txt','w') as fr:
x = '3'
fr.write(x)
with open('1.txt','r') as fr_r:
fr_w = fr_r.read()
print (fr_w)
预期输出低于
3
你的代码应该是这样的(第二个没有缩进)
with open('1.txt','w') as fr:
x = '3'
fr.write(x)
with open('1.txt','r') as fr_r:
fr_w = fr_r.read()
print (fr_w)
一旦您使用 'with' 语句打开文件。你不需要关闭那个频道。出于这个原因 python 开发人员设置了一个限制,不能在此块中写入或使用另一个权限通道。
once read /write permission in opened we cannot add another permission channel in that block or indentation. it should be in seperate indentation like this below as follows``