473,698 Members | 2,471 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Two questions

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;

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?

Thanks,
- QS Computing.

Jul 19 '05 #1
20 1878

On 2 Jun 2005 06:45:18 -0700, qs*********@gma il.com said:
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;
for i in range(0, 2):
do stuff

The range([start], stop, [step]) function generates a sequence of
numbers which the the for loop iterates over.

(You can also use xrange() for a more memory efficient solution for very
large ranges).
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?

To create binary only distributions for Windows you can use py2exe. Its
distributions files can be fairly easily reverse engineered.

Cheers,
Richard
Jul 19 '05 #2
qs*********@gma il.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
Jul 19 '05 #3
qs*********@gma il.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
Jul 19 '05 #4
rbt
Peter Hansen wrote:
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.


Don't intend to hijack this thread, but this bit interests me. I know
several accomplished C/assembly programmers who have told me that
reverse engineering object code from either of these two languages is
anything but trivial. Yet, I *hear* and *read* the opposite all of the
time. Can anyone actually demonstrate a decompile that mirrors the
original source?

Also, I'd venture to say that the number of people in the world who can
consistently reverse engineer object code is almost statistically
insignificant.. . sure, they are out there, but you'll win the lottery
before you meet one of them and most of them work for big, bad
government agencies ;)

Jul 19 '05 #5
rbt wrote:
Peter Hansen wrote:
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.

Don't intend to hijack this thread, but this bit interests me. I know
several accomplished C/assembly programmers who have told me that
reverse engineering object code from either of these two languages is
anything but trivial. Yet, I *hear* and *read* the opposite all of the
time. Can anyone actually demonstrate a decompile that mirrors the
original source?


I give you one example: Online/Multiplayer GTA 3 or 4
(http://gta3mta.tk/)

A C-App never intended to work that way - but skillfully patched so that
it works! And that even only as OSS - no commercial interest (and thus
funding). So I day Peter's statement has full validity - it's a question
of interest.

Diez
Jul 19 '05 #6
Richard Lewis wrote:
On 2 Jun 2005 06:45:18 -0700, qs*********@gma il.com said:
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;
for i in range(0, 2):
do stuff


Eh, no. range(0, 3) would be correct, since the Python range function
generates a list from start to stop-1.
The range([start], stop, [step]) function generates a sequence of
numbers which the the for loop iterates over.

(You can also use xrange() for a more memory efficient solution for very
large ranges).
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 a binary representation of bytecode, just like in Java. They can be
reverse-engineered more easily than machine code, but it still is no no-brainer.
Btw, they are created automatically.. .

Reinhold
Jul 19 '05 #7
Thanks to you all for the quick response.

I've noticed that when I do
$ python myprog.py
the file myprog.pyc file is not created, but the .pyc files for files I
import *are* created. Is this intentional and, if so, how do I get the
myprog.pyc file?

Thanks,
- QS Computing.

Jul 19 '05 #8
qs*********@gma il.com wrote:
Thanks to you all for the quick response.

I've noticed that when I do
$ python myprog.py
the file myprog.pyc file is not created, but the .pyc files for files I
import *are* created. Is this intentional and, if so, how do I get the
myprog.pyc file?


I thought the docs covered this, so I left it out. The
"main" .py file is not converted to a .pyc file for reasons I can't
remember (and don't care... after it, that's just the way it is). If
you really need a .pyc for it, the simplest thing to do is "import
myprog" from the interactive prompt. The compileall module I mentioned
would also be able to do this.

-Peter
Jul 19 '05 #9
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

Jul 19 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
4096
by: softwareengineer2006 | last post by:
All Interview Questions And Answers 10000 Interview Questions And Answers(C,C++,JAVA,DOTNET,Oracle,SAP) I have listed over 10000 interview questions asked in interview/placement test papers for all companies between year 2000-2005 in my website http://www.geocities.com/allinterviewquestion/ So please have a look and make use of it.
0
4591
by: connectrajesh | last post by:
INTERVIEWINFO.NET http://www.interviewinfo.net FREE WEB SITE AND SERVICE FOR JOB SEEKERS /FRESH GRADUATES NO ADVERTISEMENT
2
7219
by: freepdfforjobs | last post by:
Full eBook with 4000 C#, JAVA,.NET and SQL Server Interview questions http://www.questpond.com/SampleInterviewQuestionBook.zip Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of attending interviews. If you own a company best way to judge if the candidate is worth of it. http://www.questpond.com/InterviewRatingSheet.zip
4
2510
by: Drew | last post by:
I posted this to the asp.db group, but it doesn't look like there is much activity on there, also I noticed that there are a bunch of posts on here pertaining to database and asp. Sorry for cross-posting. I am trying to build a "checklist", where a user can navigate to an ASP page on the intranet which shows a list of "questions" that the user can check off. I am trying to figure out how to do this so that it is scalable, but I am...
8
7977
by: Krypto | last post by:
Hi, I have used Python for a couple of projects last year and I found it extremely useful. I could write two middle size projects in 2-3 months (part time). Right now I am a bit rusty and trying to catch up again with Python. I am now appearing for Job Interviews these days and I am wondering if anybody of you appeared for a Python Interview. Can you please share the questions you were asked. That will be great help to me.
0
1495
by: ramu | last post by:
C# Interview Questions and Answers8 http://allinterviewsbooks.blogspot.com/2008/07/c-interview-questions-and-answers8.html C# Interview Questions and Answers7 http://allinterviewsbooks.blogspot.com/2008/07/c-interview-questions-and-answers7.html C# Interview Questions and Answers 6 http://allinterviewsbooks.blogspot.com/2008/07/c-interview-questions-and-answers-6.html C# Interview Questions and Answers 5...
1
1621
by: ramu | last post by:
C# Interview Questions and Answers8 http://allinterviewsbooks.blogspot.com/2008/07/c-interview-questions-and-answers8.html C# Interview Questions and Answers7 http://allinterviewsbooks.blogspot.com/2008/07/c-interview-questions-and-answers7.html C# Interview Questions and Answers 6 http://allinterviewsbooks.blogspot.com/2008/07/c-interview-questions-and-answers-6.html C# Interview Questions and Answers 5...
0
4499
by: ramu | last post by:
C# Interview Questions and Answers8 http://allinterviewsbooks.blogspot.com/2008/07/c-interview-questions-and-answers8.html C# Interview Questions and Answers7 http://allinterviewsbooks.blogspot.com/2008/07/c-interview-questions-and-answers7.html C# Interview Questions and Answers 6 http://allinterviewsbooks.blogspot.com/2008/07/c-interview-questions-and-answers-6.html C# Interview Questions and Answers 5...
0
3428
by: reema | last post by:
EJB Interview Questions http://interviewdoor.com/technical/EJB-Interview-Questions.htm CSS Interview Questions http://interviewdoor.com/technical/CSS-Interview-Questions.htm C Interview Questions http://interviewdoor.com/technical/C-Interview-Questions.htm C# Interview Questions http://interviewdoor.com/technical/C-sharp-Interview-Questions.htm C++ Interview Questions http://interviewdoor.com/technical/C++-Interview-Questions.htm
0
2941
by: reema | last post by:
EJB Interview Questions http://interviewdoor.com/technical/EJB-Interview-Questions.htm CSS Interview Questions http://interviewdoor.com/technical/CSS-Interview-Questions.htm C Interview Questions http://interviewdoor.com/technical/C-Interview-Questions.htm C# Interview Questions http://interviewdoor.com/technical/C-sharp-Interview-Questions.htm C++ Interview Questions http://interviewdoor.com/technical/C++-Interview-Questions.htm
0
8683
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9170
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9031
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8901
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7739
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6528
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.