need help with python

Paul McGuire ptmcg at austin.rr.com
Fri May 11 23:16:13 EDT 2007


On May 11, 9:41 pm, adamur... at hotmail.com wrote:
> On May 11, 9:34 pm, Paul McGuire <p... at austin.rr.com> wrote:
>
>
>
>
>
> > On May 11, 8:47 pm, adamur... at hotmail.com wrote:
>
> > > ya so im pretty much a newb to this whole python thing... its pretty
> > > cool but i just started today and im already having trouble.  i
> > > started to use a tutorial that i found somewhere and i followed the
> > > instructions and couldnt get the correct results.  heres the code
> > > stuff...
>
> > > temperature=input("what is the temperature of the spam?")
> > > if temperature>50:
> > >         print "the salad is properly cooked."
> > > else:
> > >         print "cook the salad some more."
>
> > > ya i was trying to do that but when i told it what the spams
> > > temperature was, it just turned off... well it wasnt working at all at
> > > first until i realized that i hadnt been following the instructions
> > > completely correctly and that i was supposed to type that code up in a
> > > notepad then save and open with python... so ya thats when it asked me
> > > what temperature the spam was and i typed a number then it just closed
> > > itself... im not really sure what went wrong... itd be real nice if
> > > someone would be like a mentor or something...
>
> > Well, this list has a varying level of mentoring and newbie-tolerance,
> > with more latitude for people who have made some effort to start with
> > before posting things like "here's my homework problem, please send me
> > the working code so I can hand it in."
>
> > I just ran your code interactively at the Python prompt, and it runs
> > just fine.  See?
>
> > >>> temperature=input("what is the temperature of the spam?")
>
> > what is the temperature of the spam?55>>> if temperature>50:
>
> > ...         print "the salad is properly cooked."
> > ... else:
> > ...         print "the salad is properly cooked."
> > ...
> > the salad is properly cooked.
>
> > I think the problem you are having is that, when you run your program
> > by double-clicking on the xyz.py file in a file browser, the OS
> > (Windows, I assume?) opens a separate console window, and runs the
> > program, and then at the end of the program, CLOSES the window.  I
> > think your code is running just fine, I think your "the salad is
> > whatever" messages get printed out, but afterward, your program ends,
> > so the window closes before you can see how your salad turned out.
>
> > A simple workaround you can do is to add to the end of your program
> > this statement:
>
> > input("<press return to end program>")
>
> > This will cause the process to stop and wait for you to press the
> > RETURN key, giving you time to stop and admire your salad results
> > before closing the window.
>
> > One final note: many people post in a "write like I talk" style.  This
> > is okay while telling your story ("well it wasn't working at all at
> > first..."), and the ee cummings all-lower-case is passable, but please
> > drop the "ya"s.  They are a verbal tic that may be okay in person, but
> > do not translate at all to written posts.  At least you don't say
> > "like" every other word, and I thank you for that! :)
>
> > You can get a sense of other writing styles by reading through the
> > comp.lang.python archives.  I would also recommend that you might find
> > more folks in the "just getting started" phase posting to the python-
> > tutor mailing list (go tohttp://mail.python.org/mailman/listinfo/tutor),
> > and you can skim through posts there for many introductory topics.
>
> > Good luck to you, and welcome to Python!
>
> > -- Paul
>
> well... i just discovered another of my mistakes.  i was writing it in
> notepad and not saving it as .py  silly me... hoho ya that input thing
> to get it to make u press enter worked tho... but only with that
> one... ive got another one that i cant get to work even with the input
> message to press enter.  Sorry about the bad grammar.  I'm used to
> Myspace where no one gives a particular hoot about how you type.  I
> hope this is better.  I will follow that link though.  Thanks for the
> help.- Hide quoted text -
>
> - Show quoted text -

It's possible that your next program has a runtime error, which will
raise an exception that, if not handled using try-except, will cause
the program to exit with a message (a message that will flash by and
then disappear, as the window closes immediately).

One thing you should try is to run your python programs using a
terminal window (sometimes called a "console window", or "the command
line").  There are several ways to open one of these, the simplest on
Windows is to click the "Start" button in the lower left corner,
select "Run...", and enter the command "cmd".  This will open up one
of these white-letters-on-black-background windows for typing system
commands.  From this command line, you can run your Python programs by
typing "python blah.py" where blah.py is the name of your Python
script (which you created in Notepad and saved as blah.py.  By running
scripts this way, you will get to see *all* of your program output,
without having the window close on you. (and please don't name all
your scripts "blah.py", you should pick different names...)

Another thing you might try is downloading and installing SciTE for
Windows - a free super-Notepad, with built-in support for editing *and
running* Python scripts.  Enter your Python code, save it as
"whatever.py", then press F5 - the editor will split down the middle,
keeping your program in the left half, and show the output messages
and exceptions on the right.  I find this much easier than going back
and forth between Notepad and a terminal window.  Other developer
editors (often called "IDE"s for Interactive Development Environment)
work similarly, such as pythonwin or IDLE - there are many others to
choose from, but coming from Notepad, SciTE will not be a big step,
but will move you forward.

-- Paul




More information about the Python-list mailing list