Home Download Buy Blog Forum Support

Newbie question - executing python scripts

Newbie question - executing python scripts

Postby mystelious on Tue Jul 28, 2009 9:05 pm

Hi everybody,

Firstly - wow - what an amazing editor. I have just started learning to code with python and was hunting around for the perfect editor and am now convinced that I have found it with sublime.
As an absolute beginner I have an absolutely newbie question. I am going through the Non-Programmers guide to python over at:
http://en.wikibooks.org/wiki/Non-Progra ... Python_3.0

I have gone through all of it up until now using the pre installed python editor IDLE and have just tried something from section "defining functions" using sublime. I have written everything correctly (the script that I have written runs fine in IDLE) but would love to be able to run it straight from sublime.

I actually have no idea how to do this. I presumed that it would be by going to tools -> build system and selecting python and then building the script. This works fine in showing me some outputs, but does not allow me to interact with the script at all. The script that I am trying to run is below:
Code: Select all
#   Converts temperature between Fahrenheit or Celcius
def print_options():
   print("options: ")
   print(" 'p' print options")
   print(" 'c' convert from celcius")
   print(" 'f' convert form Fahrenheit")
   print(" 'q' quit the program")

def celcius_to_fahrenheit(c_temp):
   return 9.0 / 5.0 * c_temp  + 32

def fahrenheit_to_celcius(f_temp):
   return (f_temp - 32 ) * 5.0 / 9.0

choice = "p"
while choice != "q":
   if choice == "c":
      temp = float(input("Celcius Temperature: "))
      print("Fahrenheit:", celcius_to_fahrenheit(temp))
   elif choice == "f":
      temp = float(input("Fahrenheit Temperature: "))
      print("Celcius:", fahrenheit_to_celcius(temp))
   elif choice == "p": #alternatively choice !=q: so that print when anything unexpected inputed
      print_options()
   choice = input("option: ")

and when I hit F7 to build (with settings build system -> python) I only get
Code: Select all
^Coptions:
'p' print options
'c' convert from celcius
'f' convert form Fahrenheit
'q' quit the program
option

without being able to interact with this at all.

I have also tried changing the build system to "run" but encounter this error:
Code: Select all
Traceback (most recent call last):
  File "C:\Documents and Settings\username\Desktop\Python\05 Functions\05 temperature2.py", line 25, in <module>
    choice = input("option: ")
RuntimeError: input(): lost sys.stdin


Could somebody be so kind to explain to me how to be able to execute scripts straight out of sublime? As a newbie I have quite a need to be able to do this easily due to toying around with commands and don't want to always have to go to start -> run -> pasting filepath.

Thanks in advance!
-M
mystelious
 
Posts: 2
Joined: Tue Jul 28, 2009 8:48 pm

Re: Newbie question - executing python scripts

Postby mystelious on Wed Jul 29, 2009 4:16 pm

Thanks for the feedback so far. I have played around with this some more and seems that launching an external app (IDLE in my case) would be the best option.
I will study those links and hopefully report back with a success story.

Again, thanks!
mystelious
 
Posts: 2
Joined: Tue Jul 28, 2009 8:48 pm


Return to Technical Support

Who is online

Users browsing this forum: Exabot [Bot], Yahoo [Bot] and 23 guests