Download presentation source - Python

coordinatedcapableΛογισμικό & κατασκευή λογ/κού

4 Νοε 2013 (πριν από 4 χρόνια και 6 μήνες)

104 εμφανίσεις


What’s in a name?

Snake logos and mascot
notwithstanding, it’s named after
Monty Python’s Flying Circus

impaired can safely ignore
the spam references :


expects the Spanish

What is Python?

O rapid prototyping language

Not just a scripting language

Not just another Perl

Extensible (add new modules)


Java (through JPython)

Embeddable in applications



Free (open source)

copyrighted but use not restricted

Mature (9 years old)

Supportive user community

& more books in the pipeline!

Elegant design, easy to learn

reads like “pseudo

Suitable as first language

level properties

Extremely portable

Unix, Windows, Mac, BeOS, Win/CE,
DOS, OS/2, Amiga, VMS, Cray, …

Compiles to interpreted byte code

compilation is implicit and automatic

Memory mgt through ref counting

easier for C/C++ extensions

“Safe”: no core dumps

Interfaces to...


Commercial databases

Java (JPython)

Many GUI libraries


Tk, wxWindows, GTK


MFC, MacOS, X11

Language properties

Everything is an object

Modules, classes, functions

Exception handling

Dynamic typing, polymorphism

Static scoping

Operator overloading

Indentation for block structure

Otherwise conventional syntax

level data types

Numbers: int, long, float, complex

Strings: immutable

Lists and dictionaries: containers

Other types for e.g. binary data,
regular expressions, introspection

Extension modules can define new
in” data types

What is it used for?

rapid prototyping

web scripting

away, ad hoc programming

steering scientific applications

extension language

XML processing

database applications

GUI applications

Who is using it?

LLNL, Fermilab (steering)

Alice project at CMU (3D graphics)

ObjectDomain (extend UML tool)

Infoseek (ext. language, scripting)

Industrial Light & Magic (everything)

Yahoo! (CGI in Yahoo!mail)

Digital Creations (Zope website mgt)

RedHat (Linux installation tools)

Compared to Perl

Easier to learn

especially for infrequent users

More readable code

improved code maintenance

Fewer “magical” side effects

More “safety” guarantees

Better Java integration

Some things slower

Compared to Java

Code 5
10 times more concise

Dynamic typing

Much quicker development

no compilation phase

less typing

Yes, it runs slower

but development is much faster!

Ditto (but more so) for C/C++

Compared to Tcl

Real datatypes, object

More differentiated syntax

Much faster (even than Tcl 8.0)

Can use threads

Less need for C extensions

hence fewer extension conflicts

Better Java integration

Python uses Tk as de
facto GUI std


Seamless integration with Java

Separate implementation

“classic Python” called CPython here

Implements the same language

Different set of standard modules

differences in “gray areas”

e.g. some different introspection calls

different command line options, etc.

Java integration


Compiles direct to Java bytecode

Import Java classes directly

Subclass Java classes

pass instances back to Java

Java beans integration

Can compile into Java class files

run as applet in browsers

Example function

def gcd(a, b):

“greatest common divisor”

while a != 0:

a, b = b%a, a # parallel assignment

return b

Example class

class Stack:

“A well
known data structure…” # doc string

def __init__(self): # constructor

self.items = []

def push(self, x):

self.items.append(x) # the sky is the limit

def pop(self):

x = self.items[
1] # what happens if it’s empty?

del self.items[

return x

def empty(self):

return len(self.items) == 0