![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Jul 2004
Posts: 4
Rep Power: 0
![]() |
HELp. Im following beginners tutorials for python
' Everything was doing fine. I was able to open the PY files by double clicking them. The cmd prompt would open and run the stuff. Now all the sudden I run the program it as me for my inputs but after the last input the cmd window closes. Ive tried restarting windows and completely shutting down. Still when it gets to the point of returning a answer it closes. All these programs worked 10 minutes before it stopped working so im not sure what is happening. The programs run fine in the python window. |
|
|
|
|
|
#2 |
|
Programming Guru
![]() ![]() ![]() |
is your command prompt processing the script, then closing? or is it "not working"... need more clarification.
if it is you run the cmd prompt and want the window to remain open try this... cmd /K yourCommand this call to cmd carries out the command specified in your Command and the cmd window remains... by default i believe a call to cmd is /C which closes it before you see output. as far as why it worked before and now it doesn't... sounds like a fluke.
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Jul 2004
Posts: 4
Rep Power: 0
![]() |
Yes it appears to be processing it and then closing.
Im not running it from the command prompt. Im double clicking the pythong script and it opends the command prompt. I enter the info it ask for and it runs and closes so fast I cant see the reslts..... Although the first couple times it worked fine and stayed open. Her is a sample script that im talking about. Althou it the same with all of them that worked before. Pleas eodont laugh im just learning. #This program calculates the perimeter and area of a rectangle print "Calculate information about a rectangle" length = input("Length:") width = input("Width:") print "Area",length*width print "Perimeter",2*length+2*width |
|
|
|
|
|
#4 |
|
Newbie
Join Date: Jul 2004
Posts: 4
Rep Power: 0
![]() |
Sorry for the spelling I must have been typing too fast and its late
![]() |
|
|
|
|
|
#5 |
|
Expert Programmer
|
This is a very very common problem, windows will only keep the command prompt window open as long as it needs to, so once your script is done executing the window is closed, even if you have not had a chance to read the output.
Open up an actual command prompt manually (run -> type |cmd| -> [ENTER]) and then run your scripts by giving commands at the prompt to execute the python scripts, force your python script to pause just before the program terminates, you can pass the system command "PAUSE" to do this for you if you want.
__________________
Clifford Matthew Roche <geek@cliffordroche.com> Web Hosting: http://www.crd-hosting.com Consulting: http://www.crdev-consulting.com |
|
|
|
|
|
#6 |
|
Programming Guru
![]() ![]() ![]() |
Ahhh. I failed to mention what I use the most... PAUSE via system shell. There are other compiler, etc options and preferences that can be set to do this for you as well.
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#7 |
|
Newbie
Join Date: Jul 2004
Posts: 4
Rep Power: 0
![]() |
Wow finally a python forum that delivers. This is the only one that answered me....lol
Obviously im the ultimate newb. I map for UT alot and im fairly comfortable with my meager modeling skills and I want to learn some programming. So you have to realize things as simple as running a script at the cmd promt is foriegn to me. I have done it before but where I falter is finding the program and running it. I type run Hello15.py (the name of the script) at the cmd promt and it says run is not a command. Also what is the right syntax for using pause in my script and would I make it the last command????? Also another question that came up today. I thought that once I wrote the code and saved and ran it. That it was compiling the code. But I noticed that it wasnt as I opened it in notepad. Shouldnt I be compiling it??? Although in the tutorial it said nothing of it. I appreciate the time you guys take answering what is probably trivial questions to you. Oh and one more thing that has crossed my mind. Am I learning the right programing language. Or should I be dabling in something like VB instead. I was told that if you want your program to have a GUI interface you should be using VB and that python was more for text type of programs. |
|
|
|
|
|
#8 |
|
Expert Programmer
|
Very trivial, true... but hey, all of us were there at some point. You'll find coding, hopefully, to be very rewarding, as I have.
__________________
Clifford Matthew Roche <geek@cliffordroche.com> Web Hosting: http://www.crd-hosting.com Consulting: http://www.crdev-consulting.com |
|
|
|
|
|
#9 | |
|
Programmer
|
Quote:
You could just have it wait for input that does nothing at the end of the script. A loan raw_input at the end. "Also another question that came up today. I thought that once I wrote the code and saved and ran it. That it was compiling the code. But I noticed that it wasnt as I opened it in notepad. Shouldnt I be compiling it??? Although in the tutorial it said nothing of it." Python is an interpreted language. When you interpret the program, it compiles it in the PWD as "file.pyc". The c obviously stands for compiled. You can run that independantly, and distributed it. "Oh and one more thing that has crossed my mind. Am I learning the right programing language. Or should I be dabling in something like VB instead. I was told that if you want your program to have a GUI interface you should be using VB and that python was more for text type of programs." This is true, in a sense. Python is a great language to learn how to program with. You aren't going to be jumping straight into any GUI any time soon, so why rush to a language that quickly facilitates it? Python is a wonderful tool, and it is worth learning for anybody. I am sure there is some kind of GTK/QT extensions you can use with Python, it isn't really practical though. I would suggest you learn C/C++ for GUI apps, but ride python out. It's going to be much more beneficial than you can imagine at this point.
__________________
ALLOW IMAGES IN SIGNATURES NOW |
|
|
|
|
|
|
#10 |
|
Expert Programmer
|
The easiest way to keep the command prompt open for me when I just double click is this. It just calls the pause command for msdos.
import os
'''
All of your python code here.
'''
print "\n"
os.system('pause')Then it will ask you to press any key to continue so that you have time to read what you need to read. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|