Two questions

Joal Heagney jhe13586 at bigpond.net.au
Thu Jun 2 10:06:58 EDT 2005


qscomputing at gmail.com wrote:
> Hi,
> 
> I've developed in several other languages and have recently found
> Python and I'm trying to use it in the shape of the PythonCard
> application development tool.
> 
> My two questions:
> 
> 1. What is the easiest way to create a for loop in the style I'm used
> to from Delphi ie:
> for I:=0 to 2 do begin
>   //code
> end;

Um, assuming that this loops through the numbers 0 to 2 and assigns them 
to the variable I, and then does something in code with I after it's 
been assigned, the python equivalent is:

for I in range(0,3):
	//code

(Note the whitespace after opening the for loop?)
And then break the indenting to finish the for loop. So you're next 
piece of code (Whatever you had after end;) would go here:

//morecode.

> 2. Philospohy(sp?) aside, I could potentially want to create a
> binary-only distribution of my finished apps. I noticed the
> documentation on .pyc files: how do I create these and, aside from
> being basically read-only, are they used just like ordinary .py source
> files? And can they be easily reverse-engineered?

As long as you have write access to the directory that you're .py files 
are in, when you run python, it will generate the .pyc files for you as 
they are loaded.
There is also a utility script in the main distribution called 
py_compile.py.
E.g. compiling a whole directory of .py files:

python /path/to/main/install/py_compile.py *.py

And to compile them as optimised binary files (.pyo):
python -O /path/to/main/install/py_compile.py *.py

They are used like ordinary .py source files. (Python actually executes 
from the .pyc files it builds from your .py files.)
They can be reverse-engineered, but then so can Java/C++/Assembler. Have 
a look through the group for something about being able to distribute 
your modules.pyc as a zipfile - I remember something about being able to 
do a -tiny- bit of extra protection by having them as a passworded zip file.

> Thanks,
>   - QS Computing.
> 

Welcome.

Joal



More information about the Python-list mailing list