Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: IDLE and Python 2.7

  1. #1
    Join Date
    May 2012
    Beans
    8

    IDLE and Python 2.7

    Hey everyone

    I'm new to Ubuntu/Linux and programming in Python as well. I installed Ubuntu on my parents old dell yesterday. The last two weeks or so I've been learning Python. I installed idle on my windows computers and haven't had any issues using it so far. Now I'm trying to use IDLE for Ubuntu and am having quite a few problems. I'm new to this so if these seem like dumb questions please bear with me. Any help would be appreciated.

    -When I write a file in IDLE and save it to a file on my desktop with the .py extension and then proceed to click on it, instead of executing the file like it does in windows it just comes up as a text file with the code. In windows a command prompt comes up and executes the file as written.

    -I wrote the following code

    name = input("Hi. What's your name? ")
    print(name)
    print("Hi,", name)
    input("\n\nPress the enter key to exit.")

    When I run this in the shell it will prompt me to enter my name like it should. Then after entering it I get this big error message in red print.

    Maybe I'm missing something simple here-any help would be appreciated.

  2. #2
    Join Date
    Mar 2008
    Beans
    26

    Re: IDLE and Python 2.7

    I'm not sure what you are after, but I assume you want to execute a .py script without typing

    Code:
    python myscript.py
    in a terminal.

    So the first thing you should do is , give the path to the interpreter. As such, include this line on the top of your file

    Code:
    #!/usr/bin/env python
    Then make your .py file an executable..

    Code:
    $ chmod +x myscript.py
    And to run it, type

    Code:
    ./myscript.py
    Samitha Ransara

  3. #3
    Join Date
    May 2012
    Beans
    8

    Re: IDLE and Python 2.7

    Ok so when I write this code
    Code:
    name = "Steveo"
    print(name)
    print("Hi,", name)
    
    input("\n\nPress the enter key to exit.")
    This is the output I get from IDLE

    Steveo
    ('Hi,', 'Steveo')


    Press the enter key to exit.
    I push enter and get this

    Traceback (most recent call last):
    File "/home/steve/Desktop/PythonFiles/steveo.py", line 5, in <module>
    input("\n\nPress the enter key to exit.")
    File "<string>", line 0

    ^
    SyntaxError: unexpected EOF while parsing
    and its in red. When I do this on my windows machine it works as it should.

  4. #4
    Join Date
    Nov 2005
    Location
    Sendai, Japan
    Beans
    11,296
    Distro
    Kubuntu

    Re: IDLE and Python 2.7

    Never ever use input() in Python 2.x. Always use raw_input(). the reason you are getting this error is that Python is trying to parse the string you get it (and fails, because there is nothing for it to parse).
    「明後日の夕方には帰ってるからね。」


  5. #5
    Join Date
    May 2012
    Beans
    8

    Re: IDLE and Python 2.7

    Thank you so much. One more question. Why does the

    Hi,Steveo
    come out like this

    ('Hi,','Steveo')

  6. #6
    Join Date
    Nov 2005
    Location
    Sendai, Japan
    Beans
    11,296
    Distro
    Kubuntu

    Re: IDLE and Python 2.7

    Because in Python 2, print is a statement, not a function. You should do

    Code:
    print "Hi,", name
    If you wrap parentheses around it, you create a tuple.
    「明後日の夕方には帰ってるからね。」


  7. #7
    Join Date
    May 2012
    Beans
    8

    Re: IDLE and Python 2.7

    Thanks again. I'm currently reading this book

    http://www.amazon.com/Python-Program...8137549&sr=8-1

    to learn python. And while its a great book thus far I had no idea the syntax only worked on windows computers-I had no idea there were so many differences.

  8. #8
    Join Date
    Nov 2005
    Location
    Sendai, Japan
    Beans
    11,296
    Distro
    Kubuntu

    Re: IDLE and Python 2.7

    Python is the same on all platforms, if you have the same version of Python. From the looks of it, your book seems to be using Python 3, so you should use that.
    「明後日の夕方には帰ってるからね。」


  9. #9
    Join Date
    May 2012
    Beans
    8

    Re: IDLE and Python 2.7

    That's what did it, Thank You!

  10. #10
    Join Date
    Oct 2011
    Location
    West Bengal, India
    Beans
    92
    Distro
    Kubuntu 12.04 Precise Pangolin

    Question Re: IDLE and Python 2.7

    So the first thing you should do is , give the path to the interpreter. As such, include this line on the top of your file

    Code:
    #!/usr/bin/env python
    This is not working for me! I am using IDLE 2.7 on ubuntu 12.04..
    Intel Core2Duo 2.20 GHz || 4 GB DDR3 RAM
    nVidia GT 240M 1 GB || 320 GB SATA Hard Disk

Page 1 of 2 12 LastLast

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
  •