构建字符串并在终端运行Python
大家好,我正在写一个Python脚本来下载YouTube视频。我知道我可以用Linux的原生脚本语言来做这件事,但我想学会用Python写脚本,因为我在工作中使用的是Windows。
到目前为止,我已经写了:
import os
print("starting script....\n")
link = raw_input('add link\n')
name = name = raw_input('add the name with flv extension\n')
command = 'wget -O ' + name + ' $(youtube-dl -g ' + link + ' )'
os.system("command")
我觉得简单的引号(" ' ")可能是问题所在。我该怎么写才能让它正常工作呢?
谢谢大家!!
1 个回答
1
你的问题是你有
os.system("command")
这个代码正在尝试运行“command”这个命令,而不是wget命令。
试试这个:
import os
print("starting script....\n")
link = raw_input('add link\n')
name = name = raw_input('add the name with flv extension\n')
command = 'wget -O ' + name + ' $(youtube-dl -g ' + link + ' )'
os.system(command)