• Welcome to Computer Association of SIUE - Forums.
 

LOTM: Python Thurs April 23rd

Started by Travis W, 2009-03-25T10:19:13-05:00 (Wednesday)

Previous topic - Next topic

Tangent Orchard

Well done, Michael. =) I forgot to ask during the presentation, but you mentioned you normally write Python code in a normal text editor like Notepad or something.  How do you take it from there to an executable?

Jarod Luebbert

Quote from: Tangent Orchard on 2009-04-24T21:26:15-05:00 (Friday)
Well done, Michael. =) I forgot to ask during the presentation, but you mentioned you normally write Python code in a normal text editor like Notepad or something.  How do you take it from there to an executable?

Usually python programs are distributed as just .py or .pyc files, but there are bundling tools out there that create an executable. This is good if you want to be able to distribute your programs without having to worry about if the user has Python installed or not.

To create a .pyc file just:

import py_compile

py_compile.compile("mymodule.py")


And that should generate the bytecode.

You can use http://www.py2exe.org/ for windows or http://undefined.org/python/ (py2app) for mac to make an .exe or .app file.
Jarod Luebbert
Computer Science Major

Mark Sands

Quote from: Tangent Orchard on 2009-04-24T21:26:15-05:00 (Friday)
Well done, Michael. =) I forgot to ask during the presentation, but you mentioned you normally write Python code in a normal text editor like Notepad or something.  How do you take it from there to an executable?

or if you're on a *nix box and you just want to run a simple script, from command line: python filename.py
Mark Sands
Computer Science Major

and459d2

another way on a unix system is to specify the directory where the python binary is located at the top of your file..

Example:   #!/usr/bin/python 

                then on the command line type sudo chmod +x "python-file.py", and then you have an executable python script.

William Grim

The recommended magic file type is actually

#!/usr/bin/env python

This is so your PATH gets checked.
William Grim
IT Associate, Morgan Stanley

raptor

President of CAOS
Software Engineer NASA Nspires/Roses Grant

Robert Kennedy

There's not nearly enough ways to run a .py file it seems. 


rbalfan

I found this in another forum.

Code (python) Select

python -c 'print "\n".join([" ".join(["*"*n for n in t]).center(9) for
t in [(3, 3), (9,)] + map(lambda n: (n,), range(9, 0, -2))])'

raptor

 *** ***
*********
*********
*******
  ***** 
   ***   
    * 
President of CAOS
Software Engineer NASA Nspires/Roses Grant

Mark Sands

Scott's 500th post was a heart, via a python script. win.
Mark Sands
Computer Science Major