Python

cornawakeSoftware and s/w Development

Nov 4, 2013 (3 years and 9 months ago)

101 views

Jonathan Huelman

CSC 415


Programming Languages

Python

Introduction to Python

Named for
Monty Python’s
Flying Circus
, the British
sketch comedy TV show

Defined as a very high
-
level scripting
language, there isn’t a lot Python
can’t
do with it’s extensive standard library

Python is interpreted,
meaning each line is
indirectly executed.
There is
no

byte code

“Batteries included”

History of Python


Guido Van Rossum,
BDFL

(Benevolent Dictator For Life)



Python based on ABC, first
created in the late 1980s



The Python Software foundation
launched in March 2006 with Van
Rossum as President. It is a non
-
profit organization dedicated to the
Python programming language





Release dates for the
major versions:

Python 1.0
-

January
1994

Python 2.0
-

October 16, 2000

Python
3.0
-

December 3,
2008

Who Uses Python


Graphics


Industrial Light and Magic


Walt

Disney Feature Animation


Games


Battlefield 2


Civilization

4


Web Development


Yahoo Maps


Google


Linux Weekly News



Mathematical libraries


Matplotlib
, which is like
MATLAB


NumPy
, a language extension that adds
support for large and fast, multi
-
dimensional
arrays and matrices


PyIMSL

Studio is a Python distribution which
includes the
IMSL

Numerical Libraries.

The Zen of Python

>>> import this

The Zen of Python, by Tim Peters


Beautiful is better than ugly.

Explicit is better than implicit.

Simple is better than complex.

Complex is better than complicated.

Flat is better than nested.

Sparse is better than dense.

Readability counts.

Special cases aren't special enough to break the rules.

Although practicality beats purity.

Errors should never pass silently.

Unless explicitly silenced.

In the face of ambiguity, refuse the temptation to guess.

There should be one
--

and preferably only one
--
obvious way to do it.

Although that way may not be obvious at first unless you're Dutch.

Now is better than never.

Although never is often better than *right* now.

If the implementation is hard to explain, it's a bad idea.

If the implementation is easy to explain, it may be a good idea.

Namespaces are one honking great idea
--

let's do more of those!

>>>


Pythonic
’ Code

1.
for (
i
=0;
i

<
mylist_length
;
i
++)


{
do_something
(
mylist
[
i
]); }

2.
i

= 0

while
i

<
mylist_length
:


do_something
(
mylist
[
i
])


i

+= 1

3.
for
i

in range(
mylist_length
):


do_something
(
mylist
[
i
])


4.
for element in
mylist
:


do_something
(element)

The Size of Python


http://docs.python.org/library/

Example


Regular Expressions

More Examples


http://wiki.python.org/moin/SimpleProgra
ms


http://code.activestate.com/recipes/5779
05
-
password
-
generator/?in=lang
-
python



Primes program




beers on the wall and a more

pythonic
’ version




Guessing game

Pros on Python

Why
Reddit

uses Python

“The
biggest thing that has kept us on Python …
...


One
are the libraries.
There’s a library for everything.
We’ve
been learning a lot of these technologies and a lot of these
architectures as we go
.


The
other thing that keeps us on Python, and this is the major
thing, is
how readable and writable it is
. When we hire new
employees
... it’s
awesome because I can see from across
the room, looking at their screen, whether their code is good
or bad.
Because good Python code has a very obvious
structure
.”


-

Steve Huffman, Web Developer, Co
-
Founder of
Reddit.com


Evaluation


very clear, readable syntax, once you get used to the
fact that indentation is key to syntax


intuitive object orientation


natural expression of procedural code


full modularity, supporting hierarchical packages


exception
-
based error handling


very high level dynamic data types


extensive standard libraries and third party modules for
virtually every task


embeddable within applications as a scripting interface


free, with relatively cheap
IDEs

available on the Internet



Sources

http://faassen.n
--
tree.net/blog/view/weblog/2005/08/06/0


http://brainsik.theory.org/.:./2009/why
-
reddit
-
uses
-
python


http://www.yak.net/fqa/171.html


http://www.python.org/


http://en.wikipedia.org/wiki/Python_(programming_language)