On Thu, 02 Jun 2005 06:45:18 -0700, qscomputing 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;
Use Delphi. If you insist on using Python (and why wouldn't you?), then I'm afraid you will have to create for loops in the Python style: for i in range(3): do_something Notice the small gotcha: if you want to loop over the values 0, 1, and 2, you have to use range(3), NOT range(2). This may seem strange now, but it is actually very useful and prevents a lot of off-by-one errors. > 2. Philospohy(sp?) aside, Philosophy. > 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 In PythonCard? I have no idea. Sorry. In ordinary Python? When you run or import a Python module, the Python interpreter first looks for a .pyc file of the same name that is more recent than the .py file. If it doesn't find one, it compiles the .py file into byte-code, stores the byte-code in the .pyc file, and runs that. In other words, to create your .pyc file, just run your .py file and Python will do it automatically. > and, aside from > being basically read-only, are they used just like ordinary .py source > files? And can they be easily reverse-engineered? Yes, they can be easily reverse-engineered. The short answer is, Python has not been designed to hide your code. If that's what you are trying to do, perhaps you need to think about _why_ you want to go to all that extra effort to keep your software secret, rather than just _how_ to keep it secret. I can think of a number of reasons why somebody might want to hide their code. In no particular order: (1) You are ashamed of the quality of your buggy code, and don't want people to see how bad it is. If so, learn to write better code, and the best way of doing that is to let people see your code and give you advice. (2) You have stolen somebody else's code, and are trying to keep that fact secret. If so, pay the licence fee, or legally reverse-engineer the code, or use OpenSource software that allows copying. If the code you have stolen is valuable enough, the legal owners will find out, even without the source code. (3) You have create an incredibly valuable piece of code that will be worth millions, but only if nobody can see the source code. Yeah right. (4) "It's MY CODE, nobody is allowed to use it unless I SAY SO!!!" Fine, whatever you say, there are tens or hundreds of thousands of OpenSource software packages competing with your software without those restrictions. Good luck. (5) Your code has security holes and you hope that the bad guys won't find them without access to the source code. Be prepared for serious embarrassment, because the crackers WILL crack your code, source code or no source code. Obscurity is no substitute for security. (6) You are worried about people copying the code for their friends without paying you for it. How does keeping the source code secret stop them from copying the .pyc files and giving them to their friends? (7) You are using secret programs licenced from another programmer or company, and the conditions of use are that the source code isn't made available. Good luck, I hope it works out for you. (8) You are programming a game or puzzle, and you don't want players to cheat by reading the source code. Consider pulling out the information they need to cheat and putting it in an encrypted data file instead. There may be other reasons for wanting to keep the code secret. Some of them might even be good reasons, for some value of "good". The reality is, the more valuable your code is, the more effort people will put into reverse-engineering it. People will find out how it works, if they care enough, and the more valuable your program, the more they will care. On the other hand, there are incredible advantages to making your code available to the users of your software. I'm sure you already know those advantages: you are learning Python, which is based on those principles of openness. If you want to discuss these issues further, please feel free. If you really what to hide your code, you might like to think about using C-extensions instead. -- Steven -- http://mail.python.org/mailman/listinfo/python-list