The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
How do I run a script in IDLe
Discuss How do I run a script in IDLe in the Python Programming forum on Dev Shed. How do I run a script in IDLe Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

February 12th, 2013, 09:35 AM
|
|
Registered User
|
|
Join Date: Feb 2013
Posts: 4
Time spent in forums: 36 m 5 sec
Reputation 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
|

February 12th, 2013, 11:21 AM
|
 |
Contributing User
|
|
|
|
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!
|

February 12th, 2013, 12:08 PM
|
|
Registered User
|
|
Join Date: Feb 2013
Posts: 4
Time spent in forums: 36 m 5 sec
Reputation Power: 0
|
|
|
How do I run a script in IDLe
Quote: | 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
|

February 12th, 2013, 12:24 PM
|
 |
Contributing User
|
|
Join Date: Nov 2012
Location: Iran / France
|
|
|
@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
|

February 12th, 2013, 12:26 PM
|
 |
Contributing User
|
|
|
|
|
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.
|

February 12th, 2013, 04:02 PM
|
|
Registered User
|
|
Join Date: Feb 2013
Posts: 4
Time spent in forums: 36 m 5 sec
Reputation Power: 0
|
|
Quote: | 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
|

February 12th, 2013, 04:21 PM
|
|
Registered User
|
|
Join Date: Feb 2013
Posts: 4
Time spent in forums: 36 m 5 sec
Reputation Power: 0
|
|
Quote: | 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
|

February 13th, 2013, 12:38 PM
|
 |
Contributing User
|
|
|
|
|
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
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|