Two questions

Peter Hansen peter at engcorp.com
Thu Jun 2 09:58:34 EDT 2005


qscomputing at gmail.com wrote:
> 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;

for i in xrange(0, 3):
     # code

Please read the tutorial.  I'm fairly sure this and many more things 
you'll want to know are covered adequately.

> 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?

They are compiled versions of the .py files, so definitely not the same. 
  They are created automatically and transparently when you import .py 
modules, so normally you don't pay any attention to them.  They can 
easily be reverse-engineered, if by that you mean turned back into 
source code.  See "decompyle" for example.  Using the "compileall" 
module you can manually compile .py to .pyc but, again, that's generally 
not needed.  Use of tools like py2exe is generally advised for packaging 
and distibution if you don't want to distribute source, though few of 
the existing tools do much more than package up .pyc files inside 
archives, bundle the runtime library, and add wrapper code to make the 
execution transparent.

Philosophy not entirely aside, you should note that object code in any 
language can "easily" be reverse-engineered in the same way, with the 
only difference being the degree of ease involved.  If the code is worth 
enough to someone that they are willing to risk violating your license 
terms, they *will* be able to recover enough source code (whether it was 
Python, C, or assembly) to do what they need.  The only certain 
protection is to keep the valuable code on a server and use some kind of 
web service (or whatever) to control access to its execution.  (There 
have been *many* past discussions of all this in the forum -- it's a 
very tired topic by now -- so please feel free to peruse the archives 
via Google Groups before asking lots of the same questions over again. 
You'll be doing yourself a favour.)

-Peter



More information about the Python-list mailing list