[英]How to utilize variable in string parameter for a function call
I want to create text files each different in respect to the ending. 我想创建每个结尾都不同的文本文件。 For example
例如
for x in range(2)
np.savetxt('filex', a1, delimiter=',')
Through this I should have 3 files: file0, file1, file2 通过这个,我应该有3个文件:file0,file1,file2
UPDATE 更新
This works but this only generated one file. 此方法有效,但是仅生成一个文件。
for x in range(2)
np.savetxt('file'+str(x), a1, delimiter=',')
you could use string formatting 您可以使用字符串格式
for x in range(2)
np.savetxt('file%s' % x, a1, delimiter=',')
for x in range(2)
np.savetxt('file' + str(x), a1, delimiter=',')
should work 应该管用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.