【发布时间】:2015-09-12 14:29:54
【问题描述】:
我有两个文件要打开:
file = open('textures.txt', 'w')
file = open('to_decode.txt', 'w')
那我想分别写给他们两个:
file.write("Username: " + username + " Textures: " + textures)
file.write(textures)
第一次写东西是为了第一次打开,第二次是为了第二次。 我该怎么做?
【问题讨论】:
-
你有什么尝试吗?
-
使用两个不同的变量名。
file也是一个糟糕的选择。它是 Python 2 中内置函数的名称。 -
file1 和 file2 或者您可以编写一个函数并在函数中进行打开和写入,这样您就不必重复自己...