【发布时间】:2014-03-27 00:41:41
【问题描述】:
我正在尝试创建一个从输出中获取数字的代码并创建一个生成文本文件 用那个数字,然后在那个文件中用那个数字写一些行..
我尝试使用代码:
for i in Nums:
sh1 = '%d.txt' %i
target = open (sh1, 'w') ## a will append, w will over-write
text = '%d * 0\n %d *1'
target.write(text %(i))
target.close()
但我遇到了这个错误 TypeError: not enough arguments for format string 。 我不明白这个错误为什么会显示给我。我进行了搜索,但解决方案不适用于我的代码。
我需要从代码中创建文本文件,就像我输入数字 1 一样。创建 txt 文件名 1.txt 并将这些行写入其中。
1 * 0
1 * 1
1 * 2
1 * 3
有什么帮助吗? 提前致谢
【问题讨论】:
-
提示:first 搜索结果实际上很有帮助。