20061216 python intro

36
Python, A Charming Language Python, A Charming Language hzmangel@bupt Multimedia Technology Teaching and Researching Center BUPT December 13, 2006

Upload: linuxfb

Post on 27-Jan-2015

132 views

Category:

Technology


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: 20061216 python intro

Python, A Charming Language

Python, A Charming Language

hzmangel@bupt

Multimedia Technology Teaching and Researching CenterBUPT

December 13, 2006

Page 2: 20061216 python intro

Python, A Charming Language

Contents

1 A Brief Intro to Python

2 Application Domains

3 Playing with Others

4 To be Pythonic

5 Some Demos

6 Networks Resources

Page 3: 20061216 python intro

Python, A Charming Language

A Brief Intro to Python

The Definitions

Two Definitions

Python is one of those rare languages which can claim to beboth simple and powerful. You will find it easy to concentrateon the solution to your problem rather than having toconcentrate on the programming language.

Python is an easy to learn, powerful programming language.It has efficient high-level data structures and a simple buteffective approach to object-oriented programming. Python’selegant syntax and dynamic typing, together with itsinterpreted nature, make it an ideal language for scripting andrapid application development in many areas on mostplatforms.

Page 4: 20061216 python intro

Python, A Charming Language

A Brief Intro to Python

The History

The History for Python

Guido van Rossum, the creator of the Python language.

Xmas day in 1989.

BBC show “Monty Python’s Flying Circus”

Page 5: 20061216 python intro

Python, A Charming Language

A Brief Intro to Python

Features

Features of Python I

Simple:Python is a simple and minimalistic language. Reading a goodPython program feels almost like reading English, althoughvery strict English. This pseudo-code nature of Python is oneof its greatest strengths.

Easy to Learn:Python is extremely easy to get started with, it has anextraordinarily simple syntax.

Free and Open Source:Python is an example of a FOSS(Free and Open SourceSoftware).

Page 6: 20061216 python intro

Python, A Charming Language

A Brief Intro to Python

Features

Features of Python II

High-level Language:When you write programs in Python, you do not have toworry about low-level details such as managing the memoryused by your program, etc.

Protable:Python has been ported to many platforms, All your Pythonprograms can work on most of these platforms withoutrequiring any changes at all, if you are careful enough to avoidany system-specific features.

Interpreted:Python does not need compilation to a binary. It converts thesource code to a bytecodes file.

Page 7: 20061216 python intro

Python, A Charming Language

A Brief Intro to Python

Features

Features of Python III

Object-oriented:Python supports procedure-oriented programming as well asobject-oriented programming.

Extensible:Python can use the code written in C/C++.

Embeddable:You can embed Python within your C/C++ programs to give’scripting’ capabilities for your program’s users.

Extensive Libraries:The Python Standard Library is huge, and there are a hugenumber of high-quality libraries available for Python.

Page 8: 20061216 python intro

Python, A Charming Language

Application Domains

Many Application Domains

GUI, network

Graphic and image process

Document process

Game development

Website

Scientific computing

...

Page 9: 20061216 python intro

Python, A Charming Language

Application Domains

GUI Libraries

GUI Libraries

Tcl/tk

wxPython

PyGTK

PyQT

PySWT

Page 10: 20061216 python intro

Python, A Charming Language

Application Domains

Network Development

Network Development

socket module

High-level network module

SocketServer, BaseHTTPServer, CGIHTTPServer, ...email, ftplib, telnetlib, ...

twisted

jabber library

Python-QQ

Page 11: 20061216 python intro

Python, A Charming Language

Application Domains

Graphics and Images

Graphics and Images

PIL: Python Imaging Library

PyOpenGL

Blender

matplotlib

yapgvb

Page 12: 20061216 python intro

Python, A Charming Language

Application Domains

Document Process

Document Process

epydoc

ReportLab

Page 13: 20061216 python intro

Python, A Charming Language

Application Domains

Game Development

Game Development

pygame

Page 14: 20061216 python intro

Python, A Charming Language

Application Domains

Web Development

Web Development

mod python + Apache

zope/plone

karrigell

cherrypy

django

Page 15: 20061216 python intro

Python, A Charming Language

Application Domains

Scientific Computing

Scientific Computing

numarray

numeric

Page 16: 20061216 python intro

Python, A Charming Language

Playing with Others

Playing with Others

COM

Python for Windows extensions

.NET

IronPython, Python for .NET

Java

Jython

Page 17: 20061216 python intro

Python, A Charming Language

To be Pythonic

Zen of Python

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!

-- by Tim Peters

Page 18: 20061216 python intro

Python, A Charming Language

Some Demos

Some Demos

The slides followed will show some demos.

Almost all of them are copy from the turtiol

Page 19: 20061216 python intro

Python, A Charming Language

Some Demos

GUI Development

wxPython: Python + wxWidgets

import wx

class MyFrame(wx.Frame):

def __init__(self, parent, id, title):

wx.Frame.__init__(self, parent, id, title)

class MyApp(wx.App):

def OnInit(self):

frame = MyFrame(None, -1, "This is a test")

frame.Show(True)

self.SetTopWindow(frame)

return True

def main():

app = MyApp(0)

app.MainLoop()

if __name__ == "__main__":

main()

Page 20: 20061216 python intro

Python, A Charming Language

Some Demos

GUI Development

Screenshot

Figure: A simplewxPython app

Page 21: 20061216 python intro

Python, A Charming Language

Some Demos

GUI Development

BOA Constructor

Wiritten in Python

A Python IDE and wxPython GUI Builder

http://boa-constructor.sourceforge.net

Page 22: 20061216 python intro

Python, A Charming Language

Some Demos

GUI Development

Some Screenshots of BOA I

Figure: Frame Design

Page 23: 20061216 python intro

Python, A Charming Language

Some Demos

GUI Development

Some Screenshots of BOA II

Figure: Source Edit

Page 24: 20061216 python intro

Python, A Charming Language

Some Demos

GUI Development

Some Screenshots of BOA III

Figure: Debugger

Page 25: 20061216 python intro

Python, A Charming Language

Some Demos

GUI Development

Some Screenshots of BOA IV

Figure: UML View

Page 26: 20061216 python intro

Python, A Charming Language

Some Demos

Image Process

PIL: Python Image Library

Support many file format.

Provide powerful image processing and graphics capabilities.

Include filter, enchancement, ...

Export PostScript file.

Page 27: 20061216 python intro

Python, A Charming Language

Some Demos

Image Process

Demo Code

import Image

import ImageFilter

import ImageEnchance

im = Image.open("lenna.jpg")

im_rotate = im.rotate(45)

im_resize = im.resize(128, 128)

im_crop = im.crop((0, 0, 256, 256))

im_trans = im.transpose(Image.FLIP_LEFT_RIGHT)

r,g,b = im.split()

im_edge = im.filter(ImageFilter.FIND_EDGES)

im_enh = ImageEnhance.Contrast(im)

enh.enhance(1.3).show().

Page 28: 20061216 python intro

Python, A Charming Language

Some Demos

Image Process

Some Results

Page 29: 20061216 python intro

Python, A Charming Language

Some Demos

Scientific Computing

SciPy: Scientific Tools for Python

Pronounced Sigh Pie

Core library is NumPy

Provides many user-friendly and efficient numerical routines

http://www.scipy.org

Page 30: 20061216 python intro

Python, A Charming Language

Some Demos

Scientific Computing

A Simple Program

from enthought.chaco.wx import plt

from scipy import arange, optimize, special

plt.figure()

plt.hold()

w = []

z = []

x = arange(0,10,.01)

for k in arange(1,5,.5):

y = special.jv(k,x)

plt.plot(x,y)

f = lambda x: -special.jv(k,x)

x_max = optimize.fminbound(f,0,6)

w.append(x_max)

z.append(special.jv(k,x_max))

plt.plot(w,z, ’ro’)

from scipy import interpolate

t = interpolate.splrep(w, z, k=3)

s_fit3 = interpolate.splev(x,t)

plt.plot(x,s_fit3, ’g-’)

t5 = interpolate.splrep(w, z, k=5)

s_fit5 = interpolate.splev(x,t5)

plt.plot(x,s_fit5, ’y-’)

Page 31: 20061216 python intro

Python, A Charming Language

Some Demos

Scientific Computing

The Result

Figure: Result of SciPy Demo

Page 32: 20061216 python intro

Python, A Charming Language

Some Demos

Game Demo

PyGame

A set of Python modules

Designed for writing games

Written on top of SDL library

Page 33: 20061216 python intro

Python, A Charming Language

Networks Resources

Forums and Groups

Forums and Groups

http://www.python.org

http://python.cn

http://www.woodpecker.org.cn

http://groups.google.com/group/python-cn

Page 34: 20061216 python intro

Python, A Charming Language

Networks Resources

Python Powered Websites

Websites Powered by Python

http://moinmoin.wikiwikiweb.de

http://www.douban.com

Page 35: 20061216 python intro

Python, A Charming Language

Networks Resources

Python Powered Websites

Q&A

Q & A

Page 36: 20061216 python intro

Python, A Charming Language

Networks Resources

Python Powered Websites

Thanks

Thanks