Results 1 to 6 of 6

Thread: Problems running first Python program

  1. #1
    Join Date
    Sep 2006
    Location
    Washington, USA
    Beans
    767

    Problems running first Python program

    I did not think it was possible to mess up the first program following instructions, but I managed to.

    Here are instructions I followed:
    Start your editor, type the following program and save it as helloworld.py.

    print 'Hello World'

    Run this program by opening a shell prompt and run the command python helloworld.py. If you are using PythonWin, use the menu File → Run.

    The output is as shown below:

    $ python helloworld.py
    Hello World

    I get an error when I run the command in terminal...

    NOTE- Edited error message, pasted wrong

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

    EDIT- The carrot appears in terminal pointing to the d, but in the thread it does not seem to get spacing right

    I have the file saved as helloworld.py on the desktop, and have no idea why this will not work....

    Just entering "print 'hello world'" works fine in terminal
    Last edited by FleetAdmiral74; November 17th, 2006 at 05:22 AM.

  2. #2
    Join Date
    Dec 2005
    Location
    Cherry Hill, NJ
    Beans
    311
    Distro
    Ubuntu

    Re: Problems running first Python program

    Code:
    joe@necromancer:~$ cat helloworld.py
    print 'Hello World'
    joe@necromancer:~$ python helloworld.py 
    Hello World
    No such issue here....

  3. #3
    Join Date
    Sep 2006
    Location
    Washington, USA
    Beans
    767

    Re: Problems running first Python program

    I get

    fleetadmiral@Central-Plexus:~$ python helloworld.py
    python: can't open file 'helloworld.py': [Errno 2] No such file or directory
    fleetadmiral@Central-Plexus:~$


    Thats when I did not already type in python ( the stuff you pasted shows you did not). Am I supposed to save the files to some default dir its not telling me about?

  4. #4
    Join Date
    Mar 2006
    Beans
    2,423

    Re: Problems running first Python program

    cause you typed "python helloworld.py" while already in python. you were already running python inside a terminal, as denoted by the >>>

    so make sure it looks like $ python helloworld.py and not >>> python helloworld.py

    where did you save your .py file? if it is not in your home folder, you have to cd to the correct folder.

  5. #5
    Join Date
    Sep 2006
    Location
    Washington, USA
    Beans
    767

    Re: Problems running first Python program

    I saved it to me desktop

    Trying home folder now...

    It worked. Thank you for your time.

  6. #6
    Join Date
    Mar 2006
    Beans
    2,423

    Re: Problems running first Python program

    Quote Originally Posted by FleetAdmiral74 View Post
    I saved it to me desktop

    Trying home folder now...

    It worked. Thank you for your time.
    no prob.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •