New to Python - Compiled Language?

R

Relee Squirrel

Please reply both here and directly to my email address
(e-mail address removed)

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

KefX

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
 
F

Francis Avila

Relee Squirrel said:
Please reply both here and directly to my email address
(e-mail address removed)

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?

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.
 
P

Peter Hansen

Relee said:
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?

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,169
Messages
2,570,919
Members
47,460
Latest member
eibafima

Latest Threads

Top