Python脚本正在打开Python 2.7解释器

时间:2012-04-27 22:21:58

标签: python ubuntu

我最近在Kubuntu 12.04上安装了几个Python包(iPythonmatplotlibnumpyipython-notebookipython-qtconsolepython-scipy )。现在,当我尝试从命令行(./script.py)运行python脚本时,我会被抛入python解释器。

示例:

user@machine:~/$ ./script.py 

Welcome to Python 2.7!  This is the online help utility.

If this is your first time using Python, you should definitely check out
the tutorial on the Internet at http://docs.python.org/tutorial/.

Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules.  To quit this help utility and
return to the interpreter, just type "quit".

To get a list of available modules, keywords, or topics, type "modules",
"keywords", or "topics".  Each module also comes with a one-line summary
of what it does; to list the modules whose summaries contain a given word
such as "spam", type "modules spam".

help> 

为什么会这样?

我该怎样做才能停止?

除了删除iPython之外还有其他选择吗?

编辑: 我应该提一下脚本是一个python模块。我不知道这与它有什么关系。我能够运行一个简单的hello world脚本。

@Adam Mihalcin: #!/usr/bin/python

编辑2: 看起来这与iPython无关。我删除了iPython,我仍然遇到了这个问题。这是文件的内容。 (我的大多数Python文件都会发生这种情况)

#!/usr/bin/python

# Import libraries
import sys
import subprocess

def createCommand(project):
    # Create the basic command
    command = "git clone " + project

    subprocess.call(command, shell = True)

    return 0

def helpMenu():

    return 0;

def validateInput(user_input):
    # validity key
    valid = 0

    if (len(user_input) < 3):
        help()
        return 1

    if (user_input[1] == '-cl'):
        if (len(user_input) == 3):
            valid = 1
            return 0

    if (valid == 0):
        help()
        return 1

def main(user_input):
    # Validate inputs
    failure = validateInput(user_input)

    # Return if there was a failure    
    if (failure == 1):
        return 1;

    # Create the git commands        
    failure = createCommand(user_input[2])

    # Return if there was a failure    
    if (failure == 1):
        return 1;

    return 0;

if (__name__ == '__main__'):
    main(sys.argv)

编辑3: 误报!

这令人尴尬。事实证明,我知道我将使用help()函数遇到命名空间问题。我将其更改为helpMenu()但忘记更改它所在的位置。

对于浪费的帖子我很抱歉。 :(

1 个答案:

答案 0 :(得分:0)

这令人尴尬。事实证明我知道我将使用help()函数遇到命名空间问题。我将其更改为helpMenu()但忘记更改它所在的位置。

对于浪费的帖子我很抱歉。 :(