我试图在txt文件中导入一些文本,但它不起作用



这是我的代码:

file = open('C:/Users/SNEHIL RAJ/OneDrive/Desktop/shanu/coding/VS code workspace/python/gorcontent.txt', "w")
user_input = input("Type somethingn")
file.write(user_input)

当我检查我的gorcontent文件夹时,它被完全屏蔽了。

因为你不关闭文件,所以使用这样的with语句更有效(with语句会自动关闭文件(:


with open('C:/Users/SNEHIL RAJ/OneDrive/.../python/gorcontent.txt', "w") as file:
user_input = input("Type somethingn")
file.write(user_input)

最新更新