473,326 Members | 2,110 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Python Interpreter question.


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello all

I am a beginner teaching myself python, and I am enjoying it immensely :)
As a language it is great, I real treat to study, I actually find it fun to
study the language heh

Anyways to the point of my post.....

The other day I was talking with a few others about the age old Interpreted
v compiled language issue.
Were one person was saying,

"You cannot beat a compiled language."
"Interpreted scripting languages like python are just to slow" he said.

Well I agreed with him that compared to say C or any other compiled
language, languages like python and
[dare I mention the word here] 'perl', are slower in some cases;

"But!!", I said, "they are also more advantageous in many other ways as
well."

Well, after a few minutes, another Python champion came into the debate, and
turned everything on it's head by saying this,

"Python is also a compiled language, and it doesn't use an interpreter, it
uses the Python VM"

Well I was shocked at first lol, and indignant, telling him that Python does
indeed have an interpreter and python was an interpreted language, while
also reminding him that I also prefer python to to other languages as well.

I asked him, "Well what is sitting on my hard drive if not the Python
Interpreter?"

He replied that it wasn't an interpreter and was the Python compiler and VM
that did what I was refering to.
He went on to explain that the so called, "Interpreter" I was referring to
didn't exist, and that what python does when it gets python source, or
[shudders at the word] "script", is to compile the python source into
python byte code and then pass that compiled data to the python VM for
running.

So my question is this really,

Is all of that true? is it right to say in fact that python doesn't have an
interpreter, but rather it has a compiler and VM for running the python
code?

Please forgive me if all this sounds so simple to you experienced types,
Python is my 1st language, and while I am loving it and learning at a good
steady rate, python is still my, "first computer language".

Thanks in advance..
Anon


- --
*************
The Imagination may be compared to Adam's dream-
he awoke and found it truth.
John Keats.
*************
-----BEGIN PGP SIGNATURE-----
Version: PGP 8.0

iQA/AwUBQT3kwi/z2sM4qf2WEQLKsQCcDwg03n7KYM7OmGRVjCCoCUk8PpkAn2Pa
EEwtRUMnMLHi+iYtIqR1mAgT
=o/5V
-----END PGP SIGNATURE-----
Jul 18 '05 #1
12 2360
"Anon" <gu***@My.email.address.scum.com> wrote:
Is all of that true? is it right to say in fact that python doesn't have an
interpreter, but rather it has a compiler and VM for running the python
code?


Python source code is indeed converted into an intermediate form (byte
code) which is then executed on a virtual machine. Very much like Java
is. Whether you want to call this "interpreted" or "compiled" is, I
suppose, a matter of personal opinion.
Jul 18 '05 #2
Anon <gu***@My.email.address.scum.com> wrote:
...
Is all of that true? is it right to say in fact that python doesn't have an
interpreter, but rather it has a compiler and VM for running the python
code?


Python is indeed based on a compiler to bytecode plus a VM, like Java.

However, Python goes the extra step to make an interpreter out of the
combination of the two -- after all, compiling source to bytecode and
then handing the bytecode over to the VM _is_ easy. So, any time you're
using exec, eval, or execfile on source strings or files, in practice,
to all intents and purposes, you ARE using an interpreter, even if it's
put together with smoke and mirrors, oops, I mean compilers and VM's.

Similarly for anything you type at the interactive >>> prompt -- the
fact that whatever source you type gets compiled into bytecode first,
and then that bytecode is handed over to the VM for execution, is no
problem to you... in practice you DO have an interpreter, even though
"deep down" it's just a compiler + a VM!-)
Alex
Jul 18 '05 #3
On Tue, 07 Sep 2004 12:56:40 -0400, Roy Smith wrote:
Whether you want to call this "interpreted" or "compiled" is, I
suppose, a matter of personal opinion.


It is, for some suitable (but widely-agreed upon) definitions of those
words, both.

It is compiled into a form that is then interpreted.

Suitable definitions, for instance:

* Compile: To take some semantic meaning in one format (.py Python source
files) and convert it to some other format (.pyc compiled source) with
equivalent semantics. (This is a very general definition.)
* Interpret: To run a program not encoded in the native binary format of
the processor executing the program by providing it with a virtual machine
to run on that executes the program.

Java, .NET, and a lot of other things work this way now. The day is
rapidly approaching, if not already here, where rejecting "interpreted"
languages is to reject the majority of running code as "not real code".

Jul 18 '05 #4
In article <1g****************************@yahoo.com>,
al*****@yahoo.com (Alex Martelli) wrote:
Similarly for anything you type at the interactive >>> prompt -- the
fact that whatever source you type gets compiled into bytecode first,
and then that bytecode is handed over to the VM for execution, is no
problem to you... in practice you DO have an interpreter, even though
"deep down" it's just a compiler + a VM!-)


And this is one of the coolest features of python. Being able to just
type stuff at an interactive prompt instead of having to create a file,
compile it, and run it, makes it so easy to explore bits of the system
you're not sure of. For example, if I want to find out what methods
lists have, I can just type

dir ([])

which is a lot faster than looking it up in the docs.
Jul 18 '05 #5

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

[edit:snip]

OK, thanks peoplethe clarification helps me :)
I had often wondered if other language devlopers would go the same as what
the.NET JIT style and Java had gone, with the VM side of things I mean.

Anyways -what-ever- it's all facinating to me, it's like a whole new world
with it's own set of social orders-languages and politics hehe :)
I am really enjoying myself :)

Thanks:
Anon
-----BEGIN PGP SIGNATURE-----
Version: PGP 8.0

iQA/AwUBQT4lVy/z2sM4qf2WEQJh8gCg23lWdkAQKM7bnjA8v1fF49IGJFUAn2PY
tAklqLVa0Uywa1e1io9+4AB3
=SMSY
-----END PGP SIGNATURE-----
Jul 18 '05 #6
> "Python is also a compiled language, and it doesn't use an interpreter,
it
uses the Python VM"

Well I was shocked at first lol, and indignant, telling him that Python
does
indeed have an interpreter and python was an interpreted language, while
also reminding him that I also prefer python to to other languages as
well.


Would you be shocked to also learn that humanly programmed languages are
generally not compiled to actual machine code, but, as I understand it, to
multibyte code which invokes subroutines written in actual machine code,
which is usually called microcode. One can, I believe, think of Pentiums
and Athlons, for instance, as hardware interpreters or emulators of what is
now mostly the virtual 386 machine (plus extensions). Intel and AMD can
change the real machine code as they please as long as they properly
emulate the 386, as seen from the programmer view. Whether the 386 machine
was ever a real machine or whether it was also microcoded, I do not know.

Terry J. Reedy

Jul 18 '05 #7
Roy Smith wrote:
And this is one of the coolest features of python. Being able to just
type stuff at an interactive prompt instead of having to create a file,
compile it, and run it, makes it so easy to explore bits of the system
you're not sure of.


Incidentally, that feature does not require that the language be
interpreted. There are interactive programming language systems
that attempt to compile text as you type in at the prompt. If
syntactically incorrect they report the error, otherwise they
execute the native jump or call instruction to the generated
machine code.
--
--Bryan
Jul 18 '05 #8
Am Mittwoch, 8. September 2004 06:46 schrieb Terry Reedy:
Whether the 386 machine
was ever a real machine or whether it was also microcoded, I do not know.


All CPUs made by Intel up to and including the Pentium (586) were "real"
machines, which ran the bytecode as it came from RAM, without an intermediate
layer of microcoding. Only with the wake of the Pentium II (IIRC), the
concept of microcode with a (somewhat) RISC core became seasonable in the PC
CPU-producing community.

Also, IIRC, the AMD K6-* were real CPUs in the sense that they didn't have a
microcode layer between the execution and the runtime environment.

The first AMD CPU to feature microcode (although it wasn't software
changeable, as it was with all Intel CPUs from the PII on; using a little
software tool you can change the behaviour of your Pentium to resemble that
of a Motorola 68000, except for the endianness issue, now isn't that cool?)
was the Athlon, which used microcode not only for the core instruction set,
but also to drive its FPU, which is completely different to the standard FPUs
found in the Intel CPUs (it is a RISC processor in the true sense of the
word). This is also what made the Athlon so easily extensible, as
implementing a new set of FPU-instructions (like SSE/MMX/SSE2, etc.) only
needed some additional microcode on the chip (which is cheap to write),
something that Intel has much more trouble with, as the FPU is decoupled from
the CPUs microcode layer, and isn't microcoded at all AFAIK.

Anybody correct me if I'm wrong; this is all that I remember from my first
semester classes on CPU-design. ;)

Heiko.
Jul 18 '05 #9
"Terry Reedy" <tj*****@udel.edu> wrote:

Would you be shocked to also learn that humanly programmed languages are
generally not compiled to actual machine code, but, as I understand it, to
multibyte code which invokes subroutines written in actual machine code,
which is usually called microcode. One can, I believe, think of Pentiums
and Athlons, for instance, as hardware interpreters or emulators of what is
now mostly the virtual 386 machine (plus extensions). Intel and AMD can
change the real machine code as they please as long as they properly
emulate the 386, as seen from the programmer view. Whether the 386 machine
was ever a real machine or whether it was also microcoded, I do not know.


This has changed over time. The 386, 486, and Pentium are partly
microcoded. The complicated instructions are in microcode, but the most
common instructions are hardwired. This results in many non-intuitive
situations in which a single, complicated instruction would take longer
than a sequence of two or three simpler instructions.

Starting with the PentiumPro, all instructions are chopped into
"micro-operations", the pieces of which can be executed out of order. This
renders instruction timing practically impossible...
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jul 18 '05 #10

[newbie still]

I have a dictionary with around 500 keys, 50 to 100 of those keys will be
in the format *text or text* (eg "*williams" or "tim*" ) for use as
wildcards.

I need to be able to match some input text to these wildcards (eg timothy
will match tim*), * on its own is invalid, there must be text before or
after the *.

I've never used Regular Expressions, and so can't judge whether they are
suitable (ie the best way) for searching MyDict.keys() to match the input
text and get the key's value, or whether iterating the keys and using
startwith() or endswith() would be better. Or (probably) there is a
different and much better way of doing it.

Any advice would be gratefully received.

TIA

Tim

Jul 18 '05 #11
Am Donnerstag, 9. September 2004 13:28 schrieb Tim Williams:
I need to be able to match some input text to these wildcards (eg timothy
will match tim*), * on its own is invalid, there must be text before or
after the *.


Check out the fnmatch module (if you use simple wildcards, unix shell style,
which aren't regular expressions):
import fnmatch
fnmatch.fnmatch("mylittletext","my*") True fnmatch.fnmatch("mylittletext","little*") False fnmatch.fnmatch("mylittletext","*little*")

True

For documentation on the wildcards accepted by fnmatch.fnmatch, use

help(fnmatch)

in an interactive console window after you have imported the module.

HTH!

Heiko.
Jul 18 '05 #12

----- Original Message -----
From: "Heiko Wundram" <he*****@ceosg.de>

Am Donnerstag, 9. September 2004 13:28 schrieb Tim Williams:
I need to be able to match some input text to these wildcards (eg timothy
will match tim*), * on its own is invalid, there must be text before or after the *.
Check out the fnmatch module (if you use simple wildcards, unix shell

style, which aren't regular expressions):
import fnmatch
fnmatch.fnmatch("mylittletext","my*") True fnmatch.fnmatch("mylittletext","little*") False fnmatch.fnmatch("mylittletext","*little*")

True


Yes, this does the trick, many thanks.

I used something like

import fnmatch as f
t = 'tim.williams'

# in place of L = MyDict.keys()
L = ['tim*' , 'dav* ', 'david' , 'peter' , '*m' , '*y' , ' not-a-name ',
'timoth?' , '*.*' , '*iams' , '*']

L.sort() # to give a consistent search order

for name in L:
.... if f.fnmatch(t, name):
.... print t, 'matches', name

tim.williams matches *
tim.williams matches *.*
tim.williams matches *iams
tim.williams matches tim*

:-)

Jul 18 '05 #13

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

Similar topics

12
by: Rex Eastbourne | last post by:
Hi, I'm interested in running a Python interpreter in Emacs. I have Python extensions for Emacs, and my python menu lists "C-c !" as the command to run the interpreter. Yet when I run it I get...
8
by: Paul Cochrane | last post by:
Hi all, I've got an application that I'm writing that autogenerates python code which I then execute with exec(). I know that this is not the best way to run things, and I'm not 100% sure as to...
118
by: 63q2o4i02 | last post by:
Hi, I've been thinking about Python vs. Lisp. I've been learning Python the past few months and like it very much. A few years ago I had an AI class where we had to use Lisp, and I absolutely...
0
by: has | last post by:
Hi all, need a little bit of advice on dynamically binding an embedded Python interpreter. First, the code for anyone that wants a look: ...
5
by: Adam Atlas | last post by:
Does anyone know if it would be possible to create a CPython extension -- or use the ctypes module -- to access Python's own embedding API (http://docs.python.org/api/initialization.html &c.)?...
3
by: Marcin Kalicinski | last post by:
How do I use multiple Python interpreters within the same process? I know there's a function Py_NewInterpreter. However, how do I use functions like Py_RunString etc. with it? They don't take any...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.