with open("name.txt", "w") as f1:
for line in f:
f1.write(line)
我需要open("name.txt", "w")
才能成为open(variable + ".txt", "w")
之类的东西;我是python新手,不胜感激!
感谢所有提供帮助的人,这是我的最终代码:
with open(f'aWord{name}.txt', "w") as f1:
for line in f:
f1.write(line)
答案 0 :(得分:3)
您可以在python中以多种方式实现
'{}.txt'.format(variable)
'{one}.txt'.format(one=variable)
'%s.txt' % variable
f'{variable}'
那么您将拥有
with open('{}.txt'.format(variable), "w") as f1:
...