#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    4
    Rep Power
    0

    How do I run a script in IDLe


    *First post from newbie*
    ```````````````````````````
    I have never used Python before.
    I thought this would be obvious, but to me it is not.

    I was sent a script by someone.
    Here are their instructions:

    "With 5 lines of code you can split the string of coordinates into a list, reverse the list, and join it back together into a long string. The printed result can be copied and pasted into the KML and the elevation profile will be reversed. The code below will do the trick."

    Here is the script:

    # Python script to reverse KML coordinates, just paste coordinates into KMLcoords variable and run script
    KMLcoords = ''' PASTE COORDINATES HERE, BETWEEN TRIPLE QUOTES '''
    coordsSplit = KMLcoords.split(' ')
    coordsReversed = coordsSplit[::-1]
    coordsJoined = ' '.join(coordsReversed)
    print coordsJoined
    # end python script

    Here is what I pasted into the IDLE prompt as a test:

    # Python script to reverse KML coordinates, just paste coordinates into KMLcoords variable and run script
    KMLcoords = '''-79.7962560949221,39.5034318624616,0
    -79.7963859014283,39.5034814389697,0
    -79.7970197879323,39.5037059595619,0
    -79.7979009449095,39.5040388009614,0
    -79.7984644303751,39.5042449905803,0
    -79.7989934019142,39.5044450976328,0
    -79.7997323475272,39.5047217540965,0
    -79.800625474953,39.5050555724905,0
    '''
    coordsSplit = KMLcoords.split(' ')
    coordsReversed = coordsSplit[::-1]
    coordsJoined = ' '.join(coordsReversed)
    print coordsJoined
    # end python script

    I thought I would find a "Run Script" in the menu, but I don't see one. So, after pasting in the above I hit "Enter".
    The results at the prompt:
    SyntaxError: multiple statements found while compiling a single statement.

    Obviously, I am cluesless.
    What do I need to do to run the script?
    Thanks,
    WV-Mike
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,837
    Rep Power
    480
    I try to avoid idle, but anyway
    click File
    select new window
    paste the code into new window
    click run
    or maybe save then run


    The program won't work as you expect because it's set up to use a space character as a record delimiter. You'll need to change the data all on one line as
    Code:
    '-79.7962560949221,39.5034318624616,0 -79.7963859014283,39.5034814389697,0
    or change both occurrences of ' ' to '\n' .
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    4
    Rep Power
    0

    How do I run a script in IDLe


    Originally Posted by b49P23TIvg
    I try to avoid idle, but anyway
    click File
    select new window
    paste the code into new window
    click run
    or maybe save then run


    The program won't work as you expect because it's set up to use a space character as a record delimiter. You'll need to change the data all on one line as
    Code:
    '-79.7962560949221,39.5034318624616,0 -79.7963859014283,39.5034814389697,0
    or change both occurrences of ' ' to '\n' .
    Greetings,
    I think I followed your instructions correctly.
    But, I get and error.
    Here is a screen shot: http://epicroadtrips.us/py/
    Thanks,
    WV-Mike
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    Iran
    Posts
    149
    Rep Power
    139
    @WV-Mike
    Why not simply put the code in a file edited by a good text editor (for example notepad++ or any editor of your favorite) and run the script directly from a terminal? Is there any particular reason that you have to use IDLE?

    Regards,
    Dariyoosh
  8. #5
  9. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,837
    Rep Power
    480
    Yes, beautiful scenery. If you're using python 3 you'd need
    print(coordsJoined)
    because print is a function in python 3 whereas it was a statement in earlier python versions.
    [code]Code tags[/code] are essential for python code and Makefiles!
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    4
    Rep Power
    0
    Originally Posted by dariyoosh
    @WV-Mike
    Why not simply put the code in a file edited by a good text editor (for example notepad++ or any editor of your favorite) and run the script directly from a terminal? Is there any particular reason that you have to use IDLE? Regards,Dariyoosh
    Yes.
    I am more used to a GUI.
    And, I would not know how to run the script from the command line either.

    I tried to accomplish this in Excel but it exceeds what it will work with.

    Thanks,
    WV-Mike
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    4
    Rep Power
    0
    Originally Posted by b49P23TIvg
    Yes, beautiful scenery. If you're using python 3 you'd need
    print(coordsJoined)
    because print is a function in python 3 whereas it was a statement in earlier python versions.
    Using print(coordsJoined) did the trick.
    Script ran fine and output was what I wanted.
    Thanks!
    -Mike
  14. #8
  15. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2005
    Posts
    606
    Rep Power
    65
    Are we getting into Python best editor wars?

    If you are a beginner with Python coding, IDLE can be very helpful once you understand that the code written in the editor has to be saved (Ctrl s or File/Save) before it can be run (F5 or Run/Run Module). You have to configure IDLE (Options) to come up in the editor and not the interactive shell ('>>>' prompts).
    Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25

IMN logo majestic logo threadwatch logo seochat tools logo