如何将命令输入python脚本

如何将命令输入python脚本,python,Python,我目前的脚本是这样设计的,在我打开某个网站之前,我必须输入3行代码 我的代码名为genius.py 我想知道如何在一行中完成它 e、 g 我目前的代码是: #!/usr/bin/python import webbrowser artist = raw_input("Enter artist name: ") song = raw_input("Enter song name: ") artist = artist.replace(" ", "-") song = song.replace

我目前的脚本是这样设计的,在我打开某个网站之前,我必须输入3行代码

我的代码名为genius.py

我想知道如何在一行中完成它 e、 g

我目前的代码是:

#!/usr/bin/python

import webbrowser

artist = raw_input("Enter artist name: ")
song = raw_input("Enter song name: ")

artist = artist.replace(" ", "-")
song = song.replace(" ", "-")

webbrowser.open("http://genius.com/"+artist+"-"+song+"-lyrics")

可以使用sys模块

import sys
print sys.argv

或者您可以使用更专业的模块,如
sys.argv
数组中的命令行参数

import sys
artist = sys.argv[1]
song = sys.argv[2]
您需要引用包含空格的名称:

genius.py "the beatles" "a day in the life"

否则,无法判断艺术家在哪里结束,歌曲在哪里开始。

您在寻找命令行参数吗?他希望能够在一行中输入所有输入值,而不是在一行Python代码中输入。
import sys
artist = sys.argv[1]
song = sys.argv[2]
genius.py "the beatles" "a day in the life"