[英]How to copy a file and then save it with a dynamic filename using python
Example: I am taking a name from user, lets say: 例子:我从用户那里取一个名字,可以这样说:
domainName = input("Enter domain name:") domainName = input(“输入域名:”)
os.system(cp etc/default etc/domainName) os.system(cp等/默认等/域名)
Here the file will be copied with the name domainName but I want to save it with a name that is stored in variable domainName ? 在这里,文件将被复制为名称domainName,但是我想使用存储在变量domainName中的名称来保存它? How do I do this ? 我该怎么做呢 ?
Disclaimer: I don't recommend using os.system
to copy files. 免责声明:我不建议使用os.system
复制文件。 That said... 那个...
How about string concatenation? 字符串串联怎么样?
os.system("cp etc/default etc/" + domainName)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.