Re: Newbie Question HELP!

From: Bengt Richter (bokr_at_oz.net)
Date: 12/20/03


Date: 20 Dec 2003 00:28:31 GMT

On Fri, 19 Dec 2003 08:39:58 GMT, "TyBriD" <TyBriD@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



Relevant Pages

  • Re: wscript.echo and MsgBox stop execution of my script. Solution?
    ... You can use AutoIT for this. ... script which I then compiled into an exe. ... script or command line with the parameters specified. ... it is too long for the window."" " & sTEST ...
    (microsoft.public.scripting.vbscript)
  • Re: better Python IDE? Mimics Mayas script editor?
    ... In Maya's mel script editor window, ... It seems completely missing in Python's IDE. ... Does anyone know of a scripting enviroment for Python that mimics what ...
    (comp.lang.python)
  • Re: better Python IDE? Mimics Mayas script editor?
    ... In Maya's mel script editor window, ... It seems completely missing in Python's IDE. ... Does anyone know of a scripting enviroment for Python that mimics what ...
    (comp.lang.python)
  • Re: askstring Window to the top under Windows
    ... "Why do I get a DOS window when I run my python script?" ... (A word of warning but don't tell anyone: I've never used Tkinter, ... I found an example in Python 2.4 and modified as shown: ...
    (comp.lang.python)
  • several interpreters and suspend script
    ... I'm working with mixing Python scripting and C++. ... The first, when I'm in the program, I call a script, which call a function ... And when the window is opened the script should stop / wait, ... If I create more python objects, the dictionaries are different but not the ...
    (comp.lang.python)