我試圖制作一個下載檔案的簡單程式。我的命令部分有問題。這是代碼:
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)
uj5u.com熱心網友回復:
str("curl ", url," --output ", filename)你在問如何連接字串?您可以使用運算子執行此操作,但通常在這里格式化字串會更容易,所以只需f"curl {url} --output {filename}". 此外,您可能應該使用subprocess而不是os.system
由@juanpa.arrivillaga 回答
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/512915.html
標籤:Python卷曲操作系统
