Re: Two questions



qscomputing@xxxxxxxxx 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
.



Relevant Pages

  • Re: Python bytecode compatibility between interpreter versions
    ... Note that I specifically mentioned .pyc files vs. java class files, ... not Java the language/environment/platform vs. Python. ... > your platform. ... Perhaps one day .pyc files can work in such a manner. ...
    (comp.lang.python)
  • Re: Any way to not create .pyc files?
    ... As long as you zipped up the package will all .pyc and .pyo files removed, Python will have no choice but to compile the files every time they are imported - unless I'm grossly mistaken Python won't put the pyc files into the zip archive, or modify any that were there already. ... Instead of the users starting the application directly, they could start a starter application that checks with the server to determine if local files need to be updated, and if so grab them and then start the main app. ...
    (comp.lang.python)
  • Re: Race condition when generating .pyc files
    ... Part of the code lives in one place, ... hosts when the module's .pyc file is generated. ... python source first. ... Inhibiting the generation of .pyc files altogether if that's even ...
    (comp.lang.python)
  • Re: bytecode non-backcompatibility
    ... > So there are currently 7 implementations or variations of the Python ... >The same can't be said for .pyc files ... One of the principles of OOP is separation of interface from ... Python language is interface. ...
    (comp.lang.python)
  • Re: Python bytecode compatibility between interpreter versions
    ... > application as .pyc files? ... > .pyc's for each version of Python you support. ... Some installers like ZeroG will install them for you. ... up the interpretter, your code and extension libraries and dump ...
    (comp.lang.python)