opening a program?

Reply

Join Date: Dec 2007
Posts: 14
Reputation: magneto is an unknown quantity at this point 
Solved Threads: 0
magneto's Avatar
magneto magneto is offline Offline
Newbie Poster

opening a program?

 
0
  #1
Dec 23rd, 2007
OK, I am very new in programming, and I installed python2.5.1 and pygame, and I wrote the hello world programme etc. and I ran it in the python shell. But the problem is, I can't run any python document outside the shell. I tried an example in pygame, and the examples in python, but the same happens. A brief shell opens for a few milliseconds, the closes. Why does this happen and can I correct it?
click here
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 14
Reputation: magneto is an unknown quantity at this point 
Solved Threads: 0
magneto's Avatar
magneto magneto is offline Offline
Newbie Poster

Re: opening a program?

 
0
  #2
Dec 23rd, 2007
I figured it out!
Last edited by magneto; Dec 23rd, 2007 at 9:32 am. Reason: hm
click here
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 1,617
Reputation: scru has a spectacular aura about scru has a spectacular aura about 
Solved Threads: 136
Featured Poster
scru's Avatar
scru scru is offline Offline
Posting Virtuoso

Re: opening a program?

 
0
  #3
Dec 23rd, 2007
For others who might run into this problem, a simple solution would be to append the line
  1. raw_input("Press ENTER to exit")
at the end of your code.
Last edited by scru; Dec 23rd, 2007 at 9:58 am.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 1,593
Reputation: Ene Uran has a spectacular aura about Ene Uran has a spectacular aura about 
Solved Threads: 187
Ene Uran's Avatar
Ene Uran Ene Uran is offline Offline
Posting Virtuoso

Re: opening a program?

 
0
  #4
Dec 23rd, 2007
Another way is to use an IDE based editor like DrPython or IDLE that has its own output window.

See:
http://www.daniweb.com/forums/post104865-4.html
Last edited by Ene Uran; Dec 23rd, 2007 at 11:49 am.
drink her pretty in burbank
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 1,617
Reputation: scru has a spectacular aura about scru has a spectacular aura about 
Solved Threads: 136
Featured Poster
scru's Avatar
scru scru is offline Offline
Posting Virtuoso

Re: opening a program?

 
0
  #5
Dec 24th, 2007
Agreed, because then if an exception occurs you can view it in the IDE, as opposed to my method where the window just closes...
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 8
Reputation: laseredd is an unknown quantity at this point 
Solved Threads: 0
laseredd laseredd is offline Offline
Newbie Poster

Re: opening a program?

 
0
  #6
Dec 26th, 2007
To correct this problem you can add this to the end of your program:
  1. _pause = raw_input("Press <enter> to continue...")

If you're like me and don't want to add this to all your programs, I have created a small python program that will automate the process and then ask you if you want to remove the code.

To use it put it in the same directory as your program and run it. Type in the filename of your program (exclude the .py extension, this will be automatically added) and the program will add the code, launch the program and then ask you if you want to remove the code.

This probably won't work with all programs and I'm not to sure if it'll run on Linux or Mac, though I have tried my best to make it as portable as possible.

PythonPauser.py
  1. from os import system
  2. from os import remove
  3. from shutil import copyfile
  4.  
  5. program = raw_input("Which program do you want to open? ") + ".py"
  6. progtmp = program + ".tmp"
  7.  
  8. copyfile(program, progtmp) ##Backup original file
  9.  
  10. pause = open(program, "a")
  11. pause.write("_pause = raw_input('Press <enter> to continue...')")
  12. pause.close()
  13.  
  14. system(program) ##Launch the program
  15.  
  16. restore = raw_input("Do you want to remove the pausing code from the program?(y\n) ")
  17. if restore == "y":
  18. copyfile(progtmp, program)
  19. remove(progtmp)
  20. else:
  21. pass
Last edited by laseredd; Dec 26th, 2007 at 8:20 pm.
404: Signature not Found.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Python Forum


Views: 2191 | Replies: 5
Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC