Running python scripts from the command line.

Discussion in 'Python' started by Nanderson, Feb 1, 2011.

  1. Nanderson

    Nanderson Guest

    I've recently started to program. Python is my first language, so I'm
    a complete beginner. I've been trying to call python scripts from the
    command line by entering this command into it:

    >>>python test.py


    But it gives me this error message:

    >>>python test.py

    File "<stdin>", line 1
    python test.py
    ^
    SyntaxError: invalid syntax

    I know that test.py exists, and the script is correct (here is is
    anyways):

    a = 1
    if a:
    print 'Value of a is', a

    I am using python 2.7.1 installed on Windows 7. This seems like
    something that should be easy, so I'm sure I'm just missing a very
    small problem. Any help is greatly appreciated.

    Thanks,
    Anderson
    Nanderson, Feb 1, 2011
    #1
    1. Advertising

  2. On Mon, Jan 31, 2011 at 9:43 PM, Nanderson
    <> wrote:
    > I've recently started to program. Python is my first language, so I'm
    > a complete beginner. I've been trying to call python scripts from the
    > command line by entering this command into it:
    >
    >>>>python test.py

    >
    > But it gives me this error message:
    >
    >>>>python test.py

    >  File "<stdin>", line 1
    >    python test.py
    >                   ^
    > SyntaxError: invalid syntax
    >
    > I know that test.py exists, and the script is correct (here is is
    > anyways):
    >
    > a = 1
    > if a:
    >    print 'Value of a is', a
    >
    > I am using python 2.7.1 installed on Windows 7. This seems like
    > something that should be easy, so I'm sure I'm just missing a very
    > small problem. Any help is greatly appreciated.
    >
    > Thanks,
    > Anderson


    You're already in Python when you type that. If you want to run a
    script, you need to call Python from your normal shell, not from
    inside the Python interpreter.

    $ python
    Python 2.6.6 (r266:84292, Jan 10 2011, 20:14:15)
    [GCC 4.2.1 (Apple Inc. build 5659)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> python

    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    NameError: name 'python' is not defined
    >>> exit()

    $ python test.py
    Value of a is 1


    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >
    Benjamin Kaplan, Feb 1, 2011
    #2
    1. Advertising

  3. Nanderson

    Nanderson Guest

    On Jan 31, 6:54 pm, Benjamin Kaplan <> wrote:
    > On Mon, Jan 31, 2011 at 9:43 PM, Nanderson
    >
    >
    >
    >
    >
    >
    >
    >
    >
    > <> wrote:
    > > I've recently started to program. Python is my first language, so I'm
    > > a complete beginner. I've been trying to call python scripts from the
    > > command line by entering this command into it:

    >
    > >>>>python test.py

    >
    > > But it gives me this error message:

    >
    > >>>>python test.py

    > >  File "<stdin>", line 1
    > >    python test.py
    > >                   ^
    > > SyntaxError: invalid syntax

    >
    > > I know that test.py exists, and the script is correct (here is is
    > > anyways):

    >
    > > a = 1
    > > if a:
    > >    print 'Value of a is', a

    >
    > > I am using python 2.7.1 installed on Windows 7. This seems like
    > > something that should be easy, so I'm sure I'm just missing a very
    > > small problem. Any help is greatly appreciated.

    >
    > > Thanks,
    > > Anderson

    >
    > You're already in Python when you type that. If you want to run a
    > script, you need to call Python from your normal shell, not from
    > inside the Python interpreter.
    >
    > $ python
    > Python 2.6.6 (r266:84292, Jan 10 2011, 20:14:15)
    > [GCC 4.2.1 (Apple Inc. build 5659)] on darwin
    > Type "help", "copyright", "credits" or "license" for more information.>>> python
    >
    > Traceback (most recent call last):
    >   File "<stdin>", line 1, in <module>
    > NameError: name 'python' is not defined>>> exit()
    >
    > $  python test.py
    > Value of a is 1
    >
    >
    >
    >
    >
    >
    >
    > > --
    > >http://mail.python.org/mailman/listinfo/python-list


    Wow, thank you very much for your help. This worked absolutely great.
    I feel like a huge n00b after that though; it was just so obvious!
    Anyways, like I said before, thank you very much for your help.

    Anderson
    Nanderson, Feb 1, 2011
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jan Danielsson
    Replies:
    8
    Views:
    619
    Mike Meyer
    Jul 22, 2005
  2. Jp Calderone
    Replies:
    0
    Views:
    449
    Jp Calderone
    Jul 21, 2005
  3. davidj411
    Replies:
    0
    Views:
    488
    davidj411
    Jun 27, 2008
  4. Peter
    Replies:
    0
    Views:
    377
    Peter
    Dec 3, 2009
  5. yusuf
    Replies:
    22
    Views:
    248
    Mumia W.
    Aug 11, 2006
Loading...

Share This Page