简体   繁体   English

如何利用字符串参数中的变量进行函数调用

[英]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.

相关问题 如何使用字符串形式的类对象作为参数调用函数 - How to call a function with a class object as a parameter in string form 如何利用熊猫字符串格式 - How to utilize pandas string formatting 如何将字符串转换为列表的现有变量名作为函数的参数 - How to convert a string into an existing variable name of a list as a parameter of a function 如何在Python中将字符串用作函数参数并使用可变数量的参数 - How to use a string as a function parameter in Python and have variable number of parameters 如何使 function 的参数像变量字符串方法一样 - How to make parameter of function act like variable string methods 如何利用 function 之间的返回 - How to utilize return between function 如何在Python中调用带有存储为字符串的变量的函数 - How in Python can I call a function with a variable which is store as a string 利用 AWS SSM 参数存储进行 API 调用的安全方法 - Secure way to utilize AWS SSM parameter store to make API call 如何在Spark,缓存或BlockManager中利用全局变量? - How to utilize a global variable in spark, caching or BlockManager? 如何在新函数中的外部调用函数,并将参数的值添加到新变量中? - How do I call a function outside a in a new function and add the value of a parameter to a new variable?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM