Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #55714

Re: Running python scripts from the command line.

Path csiph.com!eeepc.pasdenom.info!news.pasdenom.info!news.dougwise.org!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <bsk16@case.edu>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'script,': 0.07; 'python': 0.08; 'nameerror:': 0.09; 'scripts': 0.09; 'syntax': 0.10; '>>>': 0.11; 'pm,': 0.12; 'wrote:': 0.14; 'defined': 0.14; 'invalid': 0.15; 'received:74.125.82.44': 0.15; 'received:mail- ww0-f44.google.com': 0.15; 'traceback': 0.15; 'command': 0.15; 'subject:python': 0.15; '"copyright",': 0.16; '"credits"': 0.16; '"license"': 0.16; '(here': 0.16; '[gcc': 0.16; 'anderson': 0.16; 'exit()': 0.16; 'interpreter.': 0.16; 'subject:command': 0.16; 'subject:scripts': 0.16; '\xa0print': 0.16; '(most': 0.17; 'language,': 0.17; 'seems': 0.17; 'trying': 0.22; 'installed': 0.22; 'jan': 0.22; 'last):': 0.23; 'header:In-Reply-To:1': 0.23; 'script': 0.25; 'greatly': 0.25; 'thanks,': 0.26; 'windows': 0.28; "i'm": 0.28; 'correct': 0.28; 'message-id:@mail.gmail.com': 0.29; 'problem.': 0.29; 'exists,': 0.30; 'to:addr:python-list': 0.31; "i've": 0.31; 'url:mailman': 0.31; 'message:': 0.32; 'error': 0.32; 'file': 0.34; '"",': 0.34; 'appreciated.': 0.35; 'using': 0.35; 'but': 0.36; 'help': 0.38; 'received:google.com': 0.38; 'should': 0.38; 'url:org': 0.38; 'subject:: ': 0.39; 'url:python': 0.39; 'to:addr:python.org': 0.40; 'that.': 0.40; 'your': 0.61; 'name': 0.61; 'easy,': 0.67
MIME-Version 1.0
In-Reply-To <2e8ce9be-fa71-42ff-a9bf-446bb9ec86dc@l22g2000pre.googlegroups.com>
References <2e8ce9be-fa71-42ff-a9bf-446bb9ec86dc@l22g2000pre.googlegroups.com>
Date Mon, 31 Jan 2011 21:54:28 -0500
Subject Re: Running python scripts from the command line.
From Benjamin Kaplan <benjamin.kaplan@case.edu>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1527.1296528879.6505.python-list@python.org> (permalink)
Lines 50
NNTP-Posting-Host 82.94.164.166
X-Trace 1296528879 news.xs4all.nl 41103 [::ffff:82.94.164.166]:56787
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:55714

Show key headers only | View raw


On Mon, Jan 31, 2011 at 9:43 PM, Nanderson
<mandersonrandersonanderson@gmail.com> 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
>

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Running python scripts from the command line. Nanderson <mandersonrandersonanderson@gmail.com> - 2011-01-31 18:43 -0800
  Re: Running python scripts from the command line. Benjamin Kaplan <benjamin.kaplan@case.edu> - 2011-01-31 21:54 -0500
    Re: Running python scripts from the command line. Nanderson <mandersonrandersonanderson@gmail.com> - 2011-01-31 19:08 -0800

csiph-web