我正在学习Automate那些无聊的东西,我注意到他教开放模块是这样的:
baconFile = open('bacon.txt', 'w')
baconFile.write('Bacon is not a vegetable.')
baconFile.close()为什么我们需要baconFile变量呢?我理解易于阅读/调试,但是,当我尝试以下代码时,文本不会输入到.txt文件中:
open('bacon.txt', 'w').write('Bacon is not a vegetable.')
open('bacon.txt', 'w').close()为什么?这两者之间的区别是什么?
编辑:人们说我在底部的代码中再次打开它。这不是我在顶层代码中所做的吗?我以为变量只是我不想再输入的代码的替代品。
发布于 2020-02-03 04:15:04
step 1. open the file to write.
step 2. write something in the file.
step 3. close the file.您正在尝试打开一个打开的文件。
https://stackoverflow.com/questions/60030086
复制相似问题