3. Program Execution
In interactive shell:
print ‘hello world’ # hello world
print 2 ** 100 # 1267650600228229491496703205376
In command line:
python hello.py
4. Python Virtual Machine
.py VS. .pyc
1. .py is the source code of Python
2. .pyc is the byte-compiled code of .py
3. .pyc can be executed in PVM
5. Python Virtual Machine
.py .pyc PVM
source byte code execution
PVM is a huge loop that executes our code one by one.
6. .pyc
A file contains byte-code interpreted from .py
Boost the execution time.
Rebuild automatically if .py changed.
The text in .pyc file is not binary code.
7. Python Implementation
CPython - ported from ANSI C, standard
implementation.
Jython - compiled Python code to Java byte-
code and executed on JVM
IronPython - similar as Jython implemented
9. Input
standard input
a = “hello world”
print a
a = raw_input()
print a
sys.argv[1]
import sys
print sys.argv[1]
> python script1.py
script1.py
10. Module import and reload
script4.py
print ‘hello world’
print 2 ** 100
title = ‘The Meaning
of life’
IDLE
>>>import script4
>>>reload(script4)
>>>print script4.title
11. Module import and reload
threenames.py
a = ‘dead’
b = ‘parrot’
c = ‘sketch’
print a, b ,c
IDLE
>>>import three names
>>>threenames.b,
threenames.c
>>>from threenames
import a, b, c