我尝试做一个简单的程序下载一个文件。我有一个问题的命令部分。这里是代码:
import os
#gather user input
print("hello! welcome to the website dowloader! paste in the url(including the http
part) and type in the file name!)")
url = input("website url: ")
filename = input("the filename:")
#the command i want run. for example, if the url was "https://example.com" and the
#filename was "example.html"
#then i would want the command run to be: 'curl https://example.com --output
#example.html'
cmd = str("curl ", url," --output ", filename)
os.system(cmd)
1条答案
按热度按时间nkhmeac61#
str("curl ", url," --output ", filename)
你是在问如何连接字符串吗?你可以用+
操作符来完成,但是通常情况下,格式化字符串会更容易,所以只需要f"curl {url} --output {filename}"
。另外,你可能应该用subprocess
而不是os.system
回答者:@juanpa.arrivillaga