Newbie Question HELP!

Bengt Richter bokr at oz.net
Fri Dec 19 19:28:31 EST 2003


On Fri, 19 Dec 2003 08:39:58 GMT, "TyBriD" <TyBriD at si.rr.com> wrote:

>hello guys i am new top programming and was told python is the best place to
>start i so far understand variables ex:
>print ("Fill In Below")
>name = raw_input("Enter Your Name Please: ")
>age = input("Enter Your Age Please: ")
>print "Your Name Is", name
>print "Your Age Is", age
>
>but i was wondering if there was a way to compile a EXE file to display the
>print because this only seems to run in python shell, or is there a way to
>create my own interface for my program in python thanks in advanced
>
Others have mentioned ways to get an EXE, but I am wondering if you are really
just messing around interactively so far (a good way to get familiar with things,
but not very good for repating and extending what you were doing yesterday).

I.e., I'm not sure you realize that you can take the lines you typed in
and type them into (or better, if they're still on your screen, copy and paste them into)
your favorite text editor (or even notepad) and do a save-as to some file name with a .py
extension (watch out for notepad, it likes to add .txt if you have text type as the file type
selected on the save-as dialog. Select "all files" instead before saving e.g., myprog.py).

After you have done that, go back to the "DOS"/console window (or start one and cd to the
directory where the file is) and then type python myprog.py, and the lines you saved should
be executed.

BTW, don't use input just to get some entered data converted, unless you know that the
input will never come from an unpredictable source, because interpreting arbitary text
could do real damage if it came from a malicious source.

Use raw_input instead, and then do limited conversion from string to whatever -- integer
for your example, presumably. You could write age = int(raw_input("Enter Your Age Please: "))
to get that. Expecting the user to get everything right the first time is probably optimistic,
so later you may want to re-prompt and/or have a bailout option in case of errors.

If you want to run your myprog.py from the start menu or a dektop icon, start by proceeding
as if it were an ordinary .exe to run.
I.e., right-click the task bar > properties > start menu programs> add > and browse for
your myprog.py and select it. Then when that gets into the command line slot of the create-shortcut
dialog you were just in, prefix "cmd /k python" so it reads "cmd /k python myprog.py" (w/o quotes).
Then proceed normally to put the shortcut in the menu or desktop and give it a name.

One more step: find the shortcut and right click it and select properties. Then go to the short
cut and change the "start in" directory to the full path to where myprog.py is. That way when
your script exits, the "DOS"/console window will be looking at the same default directory,
and you'll be able to re-run your script by just typing python myprog.py (or even just myprog.py
if the extension association is set up). BTW, explicitly running python is a safer bet if you
want to redirect printed output or pipe stuff to stdin of your script. Some windows versions
won't redirect right when running scripts by extension-association.

Some details of the above may vary with windows version too, but the equivalent should exist.
All of which you may know, but in case your question wasn't really about making an EXE, but
rather how to run your scripts on your machine as if they were EXE's, then HTH.

BTW, if you want the window to disappear on exit from your script, use /c in place of /k.
You may need to specify command in place of cmd also, depending on version.

Regards,
Bengt Richter




More information about the Python-list mailing list