I'm on Ubuntu 10.04, and I everytime I run my program, it appears for a split second, then disappears (Problem Set 0) is anyone willing to check my code? It follows: # Problem Set 0 # Name: Cody Dostal # Collaborators: None # Time: 0:02 #! /usr/bin/env python # print "What is your first name? " FirstName = raw_input() print "What is your last name? " LastName = raw_input() print "Hello, " + FirstName + " " + LastName -------------END---------- What is my Problem with it?
it runs fine in IDLE, just not when I save it as ps0.py
I don't use Linux, but I can say that I always use IDLE for running and writing programs, never any sort of OS terminal. When I open a module (double clicking on one in the file management system of my mac or windows machines) it opens as a window in IDLE, and doesn't run until I specifically tell it to. From the line #! /usr/bin/env python and the "END" thing, it looks like you're using some flavor of terminal/command-line to run the code. There's probably a way to make that work, but if what you're looking for is just understanding Python, you won't miss anything by using IDLE.
that happens with me to, because it runs the code and after it is done it closes. To prevent this, type the following on the last line: raw_input("Press any key to exit")
@somnamnic: The -----------END------------ was just so I could show that that was the end of my code :) But I am starting to learn more about IDLE and am falling in love with it! @not4sale93: I did that, but it still does it :( New code: # Assignment: Problem Set 0 # Name: Cody Dostal # Collaborators: None # Time: 0:05 # firstname = raw_input('What is your first name? ') lastname = raw_input('What is your last name? ') print 'Hello, ' + firstname + ' ' + lastname raw_input("Press any key to exit")
I noticed that if I open terminal and type in: Python ps0.py it runs fine it's only when I double click it and say "Run in Terminal" :\
CodyWD, I think what you're running into is a normal behavior in Ubuntu. When you double-click to "Run in Terminal", the terminal window opens, runs the selected app, then closes. Nothing is telling the terminal window to stay open. You can "cheat" and add the following to the very end of your app (but don't brag about it to anyone :) ): raw_input("Press Enter to exit...") That line will keep the terminal window open long enough for you to see the output. But it's a kluge.
CodyWD, a good alternative too see your code execution is to open a terminal and then execute the code. For example, press Ctrl+Alt+T to open a terminal, go to the folder where you have your .py file, and then execute like this : "python ps0.py". The terminal will remain open so you will see the results. Don't forget to enclose the Print arguments in ("brackets..") I hope this is useful...
@Radly: That doesn't seem to work at all :\ @Emil: Already done, but I think I'm going to start sticking to IDLE for line-by-line testing, and PyScripter+Windows 7 for full programs haha
I use ubuntu also and I don't have a problem when I use raw_input() to make it block. If your code looks like: #!/usr/bin/python # whereis python to make sure it's that path firstname = raw_input('What is your first name? ') lastname = raw_input('What is your last name? ') print 'Hello, ' + firstname + ' ' + lastname raw_input("Press any key to exit") EOF Then you should have no problems
Join our real-time social learning platform and learn together with your friends!