FAQ
I am going to try posting here again with more detail to see if I can
finally get my first program to work.

I am working on a MacBook Pro with OS X 10.4.11. I opened a new window
in IDLE to create a file. The file had only one line of code and was
saved as module1.py. I saved it to Macintosh HD. The one line of code
in the file is copied below:

print 'Hello module world!'

I closed the file and tried to run it in IDLE and Terminal, but I have
had no success. I'll paste my commands and the error messages below
(for IDLE, then Terminal). Any help would be very much appreciated. I
feel like the marathon just started and I've fallen flat on my face.
Thanks.

IDLE 2.6.2
python module1.py
SyntaxError: invalid syntax


sean-m-computer:~ seanm$ python
Python 2.6.2 (r262:71600, Apr 16 2009, 09:17:39)
[GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
python module1.py
File "<stdin>", line 1
python module1.py
^
SyntaxError: invalid syntax

Search Discussions

  • Stephen Hansen at May 2, 2009 at 9:44 pm

    IDLE 2.6.2
    python module1.py
    SyntaxError: invalid syntax
    The ">>>" prompt is Python's interactive interpreter. Once you are here, you
    already are in python-- so typing "python" again is redundant and invalid.
    From this prompt you type in python code.
    I have never used IDLE so can't comment on how to get it to run modules and
    collect output-- but I suspect when your file is open in IDLE there's a menu
    option that says something about Run.

    But....

    sean-m-computer:~ seanm$ python
    Python 2.6.2 (r262:71600, Apr 16 2009, 09:17:39)
    [GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    python module1.py
    File "<stdin>", line 1
    python module1.py
    ^
    SyntaxError: invalid syntax
    Same thing. You're starting python: then doing 'python module1.py' within
    Python, which doesn't make sense. If you want Python to run the module, just
    do "python module1.py" instead of "python" from your command prompt.

    --S
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: <http://mail.python.org/pipermail/python-list/attachments/20090502/1b41e5b5/attachment.htm>
  • Dave Angel at May 2, 2009 at 9:46 pm

    seanm.py at gmail.com wrote:
    I am going to try posting here again with more detail to see if I can
    finally get my first program to work.

    I am working on a MacBook Pro with OS X 10.4.11. I opened a new window
    in IDLE to create a file. The file had only one line of code and was
    saved as module1.py. I saved it to Macintosh HD. The one line of code
    in the file is copied below:

    print 'Hello module world!'

    I closed the file and tried to run it in IDLE and Terminal, but I have
    had no success. I'll paste my commands and the error messages below
    (for IDLE, then Terminal). Any help would be very much appreciated. I
    feel like the marathon just started and I've fallen flat on my face.
    Thanks.

    IDLE 2.6.2
    python module1.py
    SyntaxError: invalid syntax


    sean-m-computer:~ seanm$ python
    Python 2.6.2 (r262:71600, Apr 16 2009, 09:17:39)
    [GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    python module1.py
    File "<stdin>", line 1
    python module1.py
    ^
    SyntaxError: invalid syntax

    In both cases, you're already running python. Why would you expect to
    have to run python inside python?

    Once you're at a python prompt (in either of your cases), you use the
    command "import" to load a module. And you do not put the ".py"
    extension on the parameter. Specifically, it should look like this, and
    very similar for IDLE.

    M:\Programming\Python\sources\temp>c:\ProgFiles\Python26\python.exe
    Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit
    (Intel)] on
    win32
    Type "help", "copyright", "credits" or "license" for more information.
    import module1
    Hello module world!
    >>>
  • John Machin at May 2, 2009 at 10:25 pm

    On May 3, 7:46?am, Dave Angel wrote:
    seanm... at gmail.com wrote:
    I am going to try posting here again with more detail to see if I can
    finally get my first program to work.
    I am working on a MacBook Pro with OS X 10.4.11. I opened a new window
    in IDLE to create a file. The file had only one line of code and was
    saved as module1.py. I saved it to Macintosh HD. The one line of code
    in the file is copied below:
    print 'Hello module world!'
    I closed the file and tried to run it in IDLE and Terminal, but I have
    had no success. I'll paste my commands and the error messages below
    (for IDLE, then Terminal). Any help would be very much appreciated. I
    feel like the marathon just started and I've fallen flat on my face.
    Thanks.
    IDLE 2.6.2
    python module1.py
    SyntaxError: invalid syntax
    sean-m-computer:~ seanm$ python
    Python 2.6.2 (r262:71600, Apr 16 2009, 09:17:39)
    [GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    python module1.py
    ? File "<stdin>", line 1
    ? ? python module1.py
    ? ? ? ? ? ? ? ? ?^
    SyntaxError: invalid syntax
    In both cases, you're already running python. ?Why would you expect to
    have to run python inside python?

    Once you're at a python prompt (in either of your cases), you use the
    command "import" to load a module. ?And you do not put the ".py"
    extension on the parameter. ?Specifically, it should look like this, and
    very similar for IDLE.

    M:\Programming\Python\sources\temp>c:\ProgFiles\Python26\python.exe
    Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit
    (Intel)] on
    win32
    Type "help", "copyright", "credits" or "license" for more information.
    ?>>> import module1
    Hello module world!
    ?>>>
    Dave, importing modules which have side effects like printing is NOT a
    good habit to which a beginner should be introduced. He needs to know
    how to run a script.

    Sean, in Terminal, instead of typing
    python
    type
    python module1.py

    and I suggest that you give your script (not module) a more meaningful
    name.

    HTH,
    John
  • Seanm Py at May 3, 2009 at 12:10 am

    On May 2, 6:25?pm, John Machin wrote:
    On May 3, 7:46?am, Dave Angel wrote:


    seanm... at gmail.com wrote:
    I am going to try posting here again with more detail to see if I can
    finally get my first program to work.
    I am working on a MacBook Pro with OS X 10.4.11. I opened a new window
    in IDLE to create a file. The file had only one line of code and was
    saved as module1.py. I saved it to Macintosh HD. The one line of code
    in the file is copied below:
    print 'Hello module world!'
    I closed the file and tried to run it in IDLE and Terminal, but I have
    had no success. I'll paste my commands and the error messages below
    (for IDLE, then Terminal). Any help would be very much appreciated. I
    feel like the marathon just started and I've fallen flat on my face.
    Thanks.
    IDLE 2.6.2
    python module1.py
    SyntaxError: invalid syntax
    sean-m-computer:~ seanm$ python
    Python 2.6.2 (r262:71600, Apr 16 2009, 09:17:39)
    [GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    python module1.py
    ? File "<stdin>", line 1
    ? ? python module1.py
    ? ? ? ? ? ? ? ? ?^
    SyntaxError: invalid syntax
    In both cases, you're already running python. ?Why would you expect to
    have to run python inside python?
    Once you're at a python prompt (in either of your cases), you use the
    command "import" to load a module. ?And you do not put the ".py"
    extension on the parameter. ?Specifically, it should look like this, and
    very similar for IDLE.
    M:\Programming\Python\sources\temp>c:\ProgFiles\Python26\python.exe
    Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit
    (Intel)] on
    win32
    Type "help", "copyright", "credits" or "license" for more information.
    ?>>> import module1
    Hello module world!
    ?>>>
    Dave, importing modules which have side effects like printing is NOT a
    good habit to which a beginner should be introduced. He needs to know
    how to run a script.

    Sean, in Terminal, instead of typing
    ? ? python
    type
    ? ? python module1.py

    and I suggest that you give your script (not module) a more meaningful
    name.

    HTH,
    John
    Great. Thank you both very much. I appreciate the help.
  • CM at May 3, 2009 at 4:22 am

    On May 2, 4:36?pm, seanm... at gmail.com wrote:
    I am going to try posting here again with more detail to see if I can
    finally get my first program to work.

    I am working on a MacBook Pro with OS X 10.4.11. I opened a new window
    in IDLE to create a file. The file had only one line of code and was
    saved as module1.py. I saved it to Macintosh HD. The one line of code
    in the file is copied below:

    print 'Hello module world!'

    I closed the file and tried to run it in IDLE and Terminal, but I have
    had no success. I'll paste my commands and the error messages below
    (for IDLE, then Terminal). Any help would be very much appreciated. I
    feel like the marathon just started and I've fallen flat on my face.
    Thanks.

    IDLE 2.6.2>>> python module1.py

    SyntaxError: invalid syntax

    sean-m-computer:~ seanm$ python
    Python 2.6.2 (r262:71600, Apr 16 2009, 09:17:39)
    [GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.>>> python module1.py

    ? File "<stdin>", line 1
    ? ? python module1.py
    ? ? ? ? ? ? ? ? ?^
    SyntaxError: invalid syntax
    Sean, also, keep in mind you can use IDLE to run
    your scripts. After you have saved a script/program,
    there is an option for Run in the menu, and then under
    that, Run Module. The output of the script will be
    sent to IDLE window indicated as the Python shell.
    You can also just test code directly from within
    that shell, though for multi-line programs, it is
    easier within the composing window.

    I suggest you sign up for the Python tutor list:
    http://mail.python.org/mailman/listinfo/tutor

    And you can search through their big archive of
    questions and answers here:
    http://www.nabble.com/Python---tutor-f2981.html

    The tutors there are great and super-helpful, and
    will field any level of question but are particularly
    good for absolute beginners.

    Here is a tutorial on using IDLE:
    http://hkn.eecs.berkeley.edu/~dyoo/python/idle_intro/index.html

    And here is a very good general programming tutorial online
    book, focusing on Python:
    http://www.freenetpages.co.uk/hp/alan.gauld/

    Good luck!
    Che
  • Seanm Py at May 4, 2009 at 10:22 pm

    On May 3, 12:22?am, CM wrote:
    On May 2, 4:36?pm, seanm... at gmail.com wrote:


    I am going to try posting here again with more detail to see if I can
    finally get my first program to work.
    I am working on a MacBook Pro with OS X 10.4.11. I opened a new window
    in IDLE to create a file. The file had only one line of code and was
    saved as module1.py. I saved it to Macintosh HD. The one line of code
    in the file is copied below:
    print 'Hello module world!'
    I closed the file and tried to run it in IDLE and Terminal, but I have
    had no success. I'll paste my commands and the error messages below
    (for IDLE, then Terminal). Any help would be very much appreciated. I
    feel like the marathon just started and I've fallen flat on my face.
    Thanks.
    IDLE 2.6.2>>> python module1.py
    SyntaxError: invalid syntax
    sean-m-computer:~ seanm$ python
    Python 2.6.2 (r262:71600, Apr 16 2009, 09:17:39)
    [GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.>>> python module1.py
    ? File "<stdin>", line 1
    ? ? python module1.py
    ? ? ? ? ? ? ? ? ?^
    SyntaxError: invalid syntax
    Sean, also, keep in mind you can use IDLE to run
    your scripts. ?After you have saved a script/program,
    there is an option for Run in the menu, and then under
    that, Run Module. ?The output of the script will be
    sent to IDLE window indicated as the Python shell.
    You can also just test code directly from within
    that shell, though for multi-line programs, it is
    easier within the composing window.

    I suggest you sign up for the Python tutor list:http://mail.python.org/mailman/listinfo/tutor

    And you can search through their big archive of
    questions and answers here:http://www.nabble.com/Python---tutor-f2981.html

    The tutors there are great and super-helpful, and
    will field any level of question but are particularly
    good for absolute beginners.

    Here is a tutorial on using IDLE:http://hkn.eecs.berkeley.edu/~dyoo/python/idle_intro/index.html

    And here is a very good general programming tutorial online
    book, focusing on Python:http://www.freenetpages.co.uk/hp/alan.gauld/

    Good luck!
    Che
    Thanks Che! The explaination and links are much appreciated. -Sean

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedMay 2, '09 at 8:36p
activeMay 4, '09 at 10:22p
posts7
users5
websitepython.org

People

Translate

site design / logo © 2022 Grokbase