Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 12th, 2013, 09:35 AM
WV-Mike WV-Mike is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 4 WV-Mike User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #2  
Old February 12th, 2013, 11:21 AM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,360 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 9 h 55 m 30 sec
Reputation Power: 383
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!

Reply With Quote
  #3  
Old February 12th, 2013, 12:08 PM
WV-Mike WV-Mike is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 4 WV-Mike User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #4  
Old February 12th, 2013, 12:24 PM
dariyoosh's Avatar
dariyoosh dariyoosh is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Location: Iran / France
Posts: 132 dariyoosh User rank is First Lieutenant (10000 - 20000 Reputation Level)dariyoosh User rank is First Lieutenant (10000 - 20000 Reputation Level)dariyoosh User rank is First Lieutenant (10000 - 20000 Reputation Level)dariyoosh User rank is First Lieutenant (10000 - 20000 Reputation Level)dariyoosh User rank is First Lieutenant (10000 - 20000 Reputation Level)dariyoosh User rank is First Lieutenant (10000 - 20000 Reputation Level)dariyoosh User rank is First Lieutenant (10000 - 20000 Reputation Level)dariyoosh User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Days 6 h 24 m 10 sec
Reputation Power: 133
@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

Reply With Quote
  #5  
Old February 12th, 2013, 12:26 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,360 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 9 h 55 m 30 sec
Reputation Power: 383
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.

Reply With Quote
  #6  
Old February 12th, 2013, 04:02 PM
WV-Mike WV-Mike is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 4 WV-Mike User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #7  
Old February 12th, 2013, 04:21 PM
WV-Mike WV-Mike is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 4 WV-Mike User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #8  
Old February 13th, 2013, 12:38 PM
Dietrich's Avatar
Dietrich Dietrich is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 482 Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Days 22 h 23 m 21 sec
Reputation Power: 63
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > How do I run a script in IDLe

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap