Python 请在参数、解包、变量方面提供帮助
我正在使用notepad++并在python shell中运行python程序。 我正在解包变量,但是当我调用程序时,例如在PythonShellPython 请在参数、解包、变量方面提供帮助,python,python-2.7,Python,Python 2.7,我正在使用notepad++并在python shell中运行python程序。 我正在解包变量,但是当我调用程序时,例如在PythonShellimport ex7.py中,它要求我使用大于1的值来解包 使用import ex7.py first sec third时,会引发无效语法异常 这是一个程序,我不只是想知道该怎么做: from sys import argv script, first, second, third = argv print "The script is call
import ex7.py
中,它要求我使用大于1的值来解包
使用import ex7.py first sec third
时,会引发无效语法异常
这是一个程序,我不只是想知道该怎么做:
from sys import argv
script, first, second, third = argv
print "The script is called:", script
print "Your first variable is:", first
print "Your second variable is:", second
print "Your third variable is:", third
要执行python代码,应使用“python file name.py” 但是您使用了“导入ex7.py”这是错误的 请使用:python ex7.py第一秒第三秒 那么输出是: ubuntu01:~$python ex7.py第一秒第三秒 脚本名为:ab.py 您的第一个变量是:first 第二个变量是:sec
您的第三个变量是:要在python shell中执行的第三个变量将代码放在ex7.py文件中的模块中,如下所示:
import os
def abc(*arg):
script, first, second, third = arg
print "The script is called:", script
print "Your first variable is:", first
print "Your second variable is:", second
print "Your third variable is:", third
在pythonshell中
>>> from ex7 import abc
>>> abc(parm1,parm2,parm3)
argv
是从命令行(python ex7.py first sec third
)设置的,而不是使用import语句。尝试解包另一个序列。。来自:传递给Python脚本的命令行参数列表。