gpt4 book ai didi

python - 构建一个字符串并在终端 python 中运行它

转载 作者:太空宇宙 更新时间:2023-11-03 18:15:34 25 4
gpt4 key购买 nike

嘿伙计们,我正在创建一个 python 脚本来下载 youtube 视频。我知道我可以使用 native 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")

我认为简单的(“'”)是问题所在。我怎样才能写它来工作?

谢谢!!

最佳答案

你的问题是你有

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)

关于python - 构建一个字符串并在终端 python 中运行它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25070153/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com