我正在尝试制作一个下载文件的简单程序。我的命令部分有问题。这是代码:
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)
您是在问如何连接字符串吗?您可以使用str("curl ", url," --output ", filename)
运算符来完成此操作,但通常,在这里格式化字符串会更容易,因此只需使用+
即可。另外,您可能应该使用f"curl {url} --output {filename}"
而不是subprocess
os.system