I just found out about Python today and it sounds very interesting,
but I'm having trouble finding solid information about my main
question. Is Python a compiled language, or merely a sequence of
commands fed into a seperate program?
The impression I get from www.python.org is that it is a compiled
very high level language, which is extendable via C++. I'm a C++
programmer and the tools and utilities referred to existing in Python
would increase the development time of my projects. However, what I'm
creating are programs, not just scripts.
Is Python a language which can be compiled into an executable program?
Well, Python isn't a compiled language in the sense of native code compilation
(that is, making an EXE on Win32, or a normal binary executable on Unix, etc.),
though there is a tool called py2exe that you may want to look into in order to
bundle your program into an executable on Win32.
(http://starship.python.net/crew/theller/py2exe/)
However, despite being an "interpreted" language, it's certainly a usable - I
daresay great - language for large applications (or even things such as video
games!) as well as scripts. If you ever need a performance boost, you can use
psyco (http://psyco.sourceforge.net/), and if that doesn't do the trick, you
can profile your code to find out what needs to be rewritten in C or C++.
Note that it's much easier to write your main code in Python and extend it with
C++, rather than embedding Python in C++ (the same goes for C, of course).
The best advice I can give is just give it a shot. Write something small but
nontrivial and see how it works for you. Any more questions?
- Kef
I'm not sure how this distinction names corelatives, or even why it's
important.
Python is a bytecode compiled language (as opposed to machine-code compiled,
but see Psycho http://psyco.sourceforge.net/introduction.html (et al.?),
which compile Python to native machine code like a JIT compiler).
Python is also an interpreted language. It interprets the bytecode. (This
is, presumably, your "sequence of commands fed into a seperate program"?)
Python is also interactive:
Read:eval:print :: code:bytecode:interpreting bytecode.
...
> Is Python a language which can be compiled into an executable program?
Um, what do you mean by "executable"? You can execute Python code, sure,
given a Python interpreter. Python will simply compile it before running
the generated bytecode (compilation is transparent and fast enough that we
ignore it, for all practical purposes). You can also only give Python the
bytecode, and it'll use that (these are *.pyc files).
Or, you can use Psycho. (I think there's something out there that converts
Python to C code, too?)
Or, you can bind up the Python code with a Python interpreter, using py2exe
or workalikes.
Or, you can write C that uses the CPython libraries, but doesn't use the
Python interpreter. It's arguable whether this is still Python, but hey.
But what computer language is there that doesn't produce--at least
theoretically--an executable program?
I simply don't understand your categories. Python is a real-life bona-fide
computer programming language. You write code, give it to the Python thingy
(whatever you want to call it), and it makes the computer do stuff. Like
any language.
Python isn't a "scripting" language any more than lisp is. It's not a very
good shell-script replacement (see perl for that); it's a general-purpose
language. Does "scripting" mean "does not compile to machine code"? Or
maybe it means "no pointers"? "Scripting" names a problem domain, not a
language species (except insofar as that problem domain is a given
language's strength. Even then, Python isn't a scripting language!)
I think you're probably going about this the wrong way. Pythonistas
generally extend Python with C(++) for one of two reasons:
1) Because native Python simply isn't fast enough (rare)
2) To wrap libraries that aren't in Python (very common, so common that
there is boilerplate code in the distribution to speed you along.)
Otherwise, they program everything in Python! So when I read this:
> the tools and utilities referred to existing in Python
> would increase the development time of my projects.
I think, "Well, just using Python would increase it even *more*!"
Then I read this:
> However, what I'm
> creating are programs, not just scripts.
I think, "What the?! Only C++ programs are 'real' programs?!"
Look, I know you said you just heard about Python, so I'm being far gruffer
than I should be. I'm sorry. I can't say anything specific because you
weren't very specific about how you think Python can serve your needs. I
may be entirely off base. However, there are only three ways *I* can think
of as to how Python could possibly help you:
1) Prototype your code in Python, then write it in C++.
2) Embed Python into an existing C++ application, as a "scripting language"
for that application.
3) Just write the whole darned thing in Python!
Try this: download Python, follow the included Python tutorial, and code up
some small non-trivial application that duplicates part of the functionality
of something you already have some C++ code doing in the application domain
for which you want to use Python's "tools and utilities". I guarantee you,
that even if you code in a very un-Pythonic fashion, the Python code will be
simpler, shorter, clearer, more robust and powerful, have fewer bugs, be
more fun to write, and 9 times out of 10, fast *enough*. Repeat this a few
times, and you'll probably want to stop using C++ altogether.
But that's just me. Explore the www.python.org site a bit more, and you'll
find many faqs, commercial success stories, tutorials, HOWTOs, links to
Python-related sites, the entire documentation for present, past, and future
language and library versions, tutorials, Package Index, etc, etc, where you
can learn more.
--
Francis Avila
Why is that your main question? If it's not just curiosity, can
you explain why this issue concerns you?
If you think the world is divided into "compiled" and "not compiled"
languages, you are missing some useful and interesting experience.
You might also be missing some great opportunities if you let that
impact your decision-making in a big way.
> The impression I get from www.python.org is that it is a compiled
> very high level language, which is extendable via C++. I'm a C++
> programmer and the tools and utilities referred to existing in Python
> would increase the development time of my projects. However, what I'm
> creating are programs, not just scripts.
My company (Kaval Wireless) uses Python to create "programs" which
would have been created in C (if, say, we were insane) but which we
chose to create in Python. We did this because it is a very high-level
language which allows us to get more work done in less time, with
higher quality results. It's also easier to do with Python, and much
more fun! The products range from embedded industrial controllers
through automated testing systems right up to Intranet servers. Oh
yeah, we also write "scripts" using Python, when necessary (to use
the meaning I suspect you assign to that term).
> Is Python a language which can be compiled into an executable program?
Definitely. We do it frequently. The fact that it is not done in the
traditional (and rapidly becoming obsolete) way that, say, C++ is
handled is not important to us.
As a C++ programmer, I suspect you consider Java a "real" language,
and not a scripting language. You've surely seen the market for
programmers using Java grow and in some cases impact on the market
for C++ programmers. Just so you know, Python is a compiled language
in much the way Java is -- specifically the code compiles to byte code
(like "machine code") for a "virtual machine". Other than the fact that
CPUs that natively execute Python byte code don't actually exist
(though they now do for Java, of course), there's not much difference
in that respect.
In the end, it's easiest to download it (since it's free after all)
and whip through the tutorial, which you can probably manage in an
hour or so. Afterwards, if you aren't inspired to try more, at least
you gave it a shot. On the other hand, you might start to see some
potential, and if you do I predict you'll rapidly find fewer and fewer
places where using C++ seems reasonable.
-Peter
I think that would be very useful, thank you. :)
When I say compiled language, I do mean a language like C++ which is
transformed into machine code by a compiler.
I was under the impression that Python had no such compiler, and that
the end user of my programs would be required to install the Python
Interpreter. Is that true in most cases?
> The best advice I can give is just give it a shot. Write something
small but
> nontrivial and see how it works for you. Any more questions?
I'm a video game programmer and the applications I'm hoping to use
Python for are the games themselves as well as the utilities used in
making the games, such as level editors.
There are several programming concepts which I haven't studied in
depth which I read Python can handle easily, such as handling the
Windows GUI, using and even creating internet transfer protocols, and
compressing and decompressing files.
Also, can Python support Linked Lists? I believe someone said in one
of the other emails that Python doesn't support pointers.
Thanks for your assistance!
> I think that would be very useful, thank you. :)
>
> When I say compiled language, I do mean a language like C++ which is
> transformed into machine code by a compiler.
>
> I was under the impression that Python had no such compiler, and that
> the end user of my programs would be required to install the Python
> Interpreter. Is that true in most cases?
Um, did you look at the link above? :-)
Python compiles to bytecode, not to machine code. But that doesn't mean the
end user needs to install a Python interpreter.
> Also, can Python support Linked Lists? I believe someone said in one
> of the other emails that Python doesn't support pointers.
Lists are a native Python type. They're one of the things it does best--you
don't need to implement linked lists yourself with pointers.
-Mike
But Python's lists aren't linked lists. They're resizing arrays (like
std::vector in c++), confusingly called lists. The speed differences
are in inserting and deleting from the middle of the list, and
random access.
Anyway, one could say that Python's variables are pointers but they
just don't support pointer arithmetic (like adding 1 to the pointer
so that it'll refer to the next memory location). So many variables
can point to the same object, and implementing a linked list is possible.
Actually it does; py2exe and similar programs ship the interpreter
bundled with the code, so you don't install the interpreter directly,
but indirectly you do. The disadvantage is that a ten line script
requires megabites of space in order to be made executable. This
may be an issue if you plan to distribute your program via the net
and your customers have slow connection. Also, it may be an issue
for embedded systems. Finally, it is somewhat disturbing that a ten
line script cannot fit in good old 3.5' floppy :-(
Michele
Linked lists are one implementation of the abstract concept List.
Extensible arrays, as in Python, are another. The latter is more
complicated but more efficient for many (maybe most) purposes. If you
actually need the former, you can make them with Python tuples or
lists. Here is the basic idea:
Ltail = ('tail', None)
Lhead = ('middle', Ltail)
Lhead = ('new head', Lhead)
# use [] to be able to mutate data or link field
Now write function to walk list. Or make LinkedList class with
__iter__ method. Making doubly linked list is trivial modification.
For game programming, see posts in archives and PyGame site.
Terry J. Reedy
Hannu Kankaanp??:
> But Python's lists aren't linked lists. They're resizing arrays
> (like std::vector in c++), confusingly called lists. The speed
> differences are in inserting and deleting from the middle of
> the list, and random access.
Oh man do I feel stupid. I should know better! Yes, there's a big difference
between a linked list and a Python "list". I did get tripped up by the
name--thanks for the correction.
> Anyway, one could say that Python's variables are pointers
> but they just don't support pointer arithmetic (like adding
> 1 to the pointer so that it'll refer to the next memory location).
> So many variables can point to the same object, and
> implementing a linked list is possible.
Yeah, that's the ticket--references let you do most of the things that you
would otherwise do with pointers.
-Mike
Well, actually this isn't really true. It's perfectly possible to write
nontrivial programs (more than ten lines of code) and pack them with
py2exe that completely fit onto a floppy - even if nothing is
compressed. You just don't use wxPython, instead ctypes and venster,
for example.
Thomas
Michele Simionato:
> Actually it does; py2exe and similar programs ship the interpreter
> bundled with the code, so you don't install the interpreter directly,
> but indirectly you do. The disadvantage is that a ten line script
> requires megabites of space in order to be made executable. This
> may be an issue if you plan to distribute your program via the net
> and your customers have slow connection. Also, it may be an issue
> for embedded systems. Finally, it is somewhat disturbing that a ten
> line script cannot fit in good old 3.5' floppy :-(
That's true, of course. What I meant was merely that you could hide all of
this so that the end user doesn't have to go through a separate step of
downloading and installing the Python interpreter. So it becomes a size
issue, not a "why do I have to go through all these steps?" issue.
-Mike
"Michael Geary" <Mi...@DeleteThis.Geary.com> wrote in message
news:vqif0v9...@corp.supernews.com...