[Tutor] Python Characteristics.

Alan Gauld alan.gauld at btinternet.com
Wed Jul 9 20:34:15 CEST 2008


"Jeremiah Stack" <nnolie at gmail.com> wrote

> I was pondering something. when you are in the live environment 
> receiving
> immediate feedback is it basically a compiler (or program), 
> responding to
> what the user inputs,

Yes, technically its an interpreter rather than a compiler, although 
there
is an intermediate compilation step involved in the interpretation!
But it is the same python program used to interpret scripts, it just
reads its input from stdin rather than from a text file.

> or is it like the bash shell where I could tell it to
> search the file system for a certain file?

You can interact with the operating system and file system using
modules such as os etc. But you can't do it directly as you can
in bash. But that is because bash has built in capability to execute
external commands, otherwise bash is an interpreter too, albeit
with a much more limited syntax and general capability. Bash's
power is in calling external commands. Python's power is in
creating commands!

> Or how does python interact with the environment it is in?

As above, it reads input from a file (foo.py) or from stdin.
It compiles the instructions too byte code.
If the file is being imported as a module it saves the bytecode
as a compiled file (foo.pyc) and uses that the next time it
imports the same module, provided the module has not been
changed - ie. it checks the datestamps!.
It then interprets the byte code much as does Java's JVM.
If the file is not being imported then it just executes the
internal byte code block by block.

There are various actions at startup time that influence the
operation of the interpreter, ie. its environment, but you can
read about all of these issues on the Python web site. There
is copious documentation on such things.

You can also use pythons introspection capabilities to explorte
much of it - for example you can decompile the .pyc byte code
into Python's pseudo assembler. You can find out which file
a particular module is from. etc.

> If those are too broad of questions just pass.

They are ok.

Alan G. 




More information about the Tutor mailing list