Python Programming Language - PowerPoint PPT Presentation

1 / 71
About This Presentation
Title:

Python Programming Language

Description:

Objects are Python's abstraction for data. ... be built on most platforms with a standard C library including glibc and uclibc. ... – PowerPoint PPT presentation

Number of Views:453
Avg rating:3.0/5.0
Slides: 72
Provided by: ryanmc7
Category:

less

Transcript and Presenter's Notes

Title: Python Programming Language


1
Python Programming Language
2
Python Programming Language
  • Created in 1991 by Guido Van Rossum

3
Python Programming Language
  • General Purpose Language
  • Clean Syntax

4
Python Programming Language
  • General Purpose Language
  • Clean Syntax
  • Easy to Learn

5
Python Programming Language
  • General Purpose Language
  • Clean Syntax
  • Easy to Learn
  • Easy to Debug

6
Python Programming Language
  • General Purpose Language
  • Clean Syntax
  • Easy to Learn
  • Easy to Debug
  • Natural Feeling

7
Python Programming Language
  • General Purpose Language
  • Interpreted

8
Python Programming Language
  • General Purpose Language
  • Interpreted
  • No Compilation Phase

9
Python Programming Language
  • General Purpose Language
  • Interpreted
  • No Compilation Phase
  • Multiplatform Integration

10
Python Programming Language
  • General Purpose Language
  • Interpreted
  • No Compilation Phase
  • Multiplatform Integration
  • Native Debugger

11
Python Programming Language
  • General Purpose Language
  • Interpreted
  • Duck Typing

12
Python Programming Language
  • General Purpose Language
  • Interpreted
  • Duck Typing
  • Override behaviours by creating methods

13
Python Programming Language
  • General Purpose Language
  • Interpreted
  • Duck Typing
  • Override behaviours by creating methods
  • Implement operations by creating methodst

14
Python Programming Language
  • General Purpose Language
  • Interpreted
  • Duck Typing
  • Override behaviours by creating methods
  • Implement operations by creating methods
  • All data is an object

15
Python Programming Language
  • Objects are Pythons abstraction for data. All
    data in a Python program is represented by
    objects or by relations between objects.
  • Every object has an identity, a type and a value.

16
Python Programming Language
  • An objects identity never changes once it has
    been created
  • The is operator compares the identity of two
    objects
  • The id() function returns an integer representing
    its identity

17
Python Programming Language
  • An objects identity never changes once it has
    been created
  • The is operator compares the identity of two
    objects
  • The id() function returns an integer representing
    its identity
  • An objects type is also unchangeable.
  • The type() function returns an objects type
    (which is an object itself).

18
Python Programming Language
  • General Purpose Language
  • Interpreted
  • Duck Typing
  • Strongly Typed

19
Python Programming Language
  • A Python programmer can write in any style they
    like, using design patterns borrowed from
  • Imperative
  • Declarative
  • Object Oriented
  • functional programming
  • The author is free let the problem guide the
    development of the solution.

20
Python Programming Language
  • print('hello world')
  • class Hello(object)
  • def __init__(self, my_string)
  • self.my_string my_string
  • def __call__(self, render_func)
  • out_str 'Hello s' self.my_string
  • render_func(out_str)
  • def print_string(string_to_print)
  • print(string_to_print)
  • myHelloWorldClass Hello('world')
  • myHelloWorldClass(print_string)

21
Functional Example
  • Java
  • public class OuterClass
  • // Inner class
  • class AddN
  • AddN(int n) _n n
  • int add(int v) return _n v
  • private int _n
  • public AddN createAddN(int var)
  • return new AddN(var)
  • LISP
  • (define (addn n) (lambda (k) ( n k)))

Python addn lambda n lambda x x n Or def
addN(n) def add_n(x) return x n
return add_n
22
Modular Design
  • The standard Python interpreter (CPython) is
    written in C89
  • It is designed with two-way interfacing in mind
  • Embedding C programs in Python
  • Embedding Python programs in C

23
Modular Design
  • An Example C Module
  • include ltPython.hgt
  • static PyObject
  • spam_system(PyObject self, PyObject args)
  • const char command
  • int sts
  • if (!PyArg_ParseTuple(args, "s", command))
  • return NULL
  • sts system(command)
  • return Py_BuildValue("i", sts)
  • /
  • import spam
  • spam.system(

24
Cross Platform Execution
  • The CPython interpreter can be built on most
    platforms with a standard C library including
    glibc and uclibc.

25
Cross Platform Execution
  • Interpreters such as Jython and IronPython can be
    used to run a python interpreter on any Java or
    .NET VM respectively.

26
Python Is Good For
  • Protyping

27
Python Is Good For
  • Protyping
  • Web Applications/SAS

28
Python Is Good For
  • Protyping
  • Web Applications/SAS
  • Integration

29
Python Is Good For
  • Protyping
  • Web Applications/SAS
  • Integration
  • Transport Limited Applications

30
Python Is Good For
  • Protyping
  • Web Applications/SAS
  • Integration
  • Transport Limited Applications
  • Indeterminate Requirements

31
Python Is Good For
  • Protyping
  • Web Applications/SAS
  • Integration
  • Transport Limited Applications
  • Indeterminate requirements
  • Short Relevence Lifetime

32
Python Is Good For
  • Protyping
  • Web Applications/SAS
  • Integration
  • Transport Limited Applications
  • Indeterminate requirements
  • Short Relevence Lifetime
  • Porting Legacy Applications

33
Python Is Good For
  • Protyping
  • Web Applications/SAS
  • Integration
  • Transport Limited Applications
  • Indeterminate requirements
  • Short Relevence Lifetime
  • Porting Legacy Applications
  • Glue

34
Python is Not Good For
  • Native Cryptography

35
Python is Not Good For
  • Native Cryptography
  • MILOR

36
Python is Not Good For
  • Native Cryptography
  • MILOR
  • Highly Parallel Design

37
__Types__
  • None

38
__Types__
  • None
  • NotImplemented

39
__Types__
  • None
  • NotImplemented
  • Boolean

40
__Types__
  • None
  • NotImplemented
  • Boolean
  • Int/LongInt

41
__Types__
  • None
  • NotImplemented
  • Boolean
  • Int/LongInt
  • Float (which is really a double)

42
__Types__
  • None
  • NotImplemented
  • Boolean
  • Int/LongInt
  • Float (which is really a double)
  • Complex (double doubleJ)

43
__Types__
  • None
  • NotImplemented
  • Boolean
  • Int/LongInt
  • Float (which is really a double)
  • Complex (double doubleJ)
  • Sequences...

44
__Types__
  • Sequences
  • string
  • unicode
  • bytes
  • tuple
  • list
  • set
  • frozenset

45
__Types__
  • None
  • NotImplemented
  • Boolean
  • Int/LongInt
  • Float (which is really a double)
  • Complex (double doubleJ)
  • Sequences...
  • Mapping Types (dict)

46
__Types__
  • None
  • NotImplemented
  • Boolean
  • Int/LongInt
  • Float (which is really a double)
  • Complex (double doubleJ)
  • Sequences...
  • Mapping Types (dict)
  • Functions and Methods

47
__Types__
  • None
  • NotImplemented
  • Boolean
  • Int/LongInt
  • Float (which is really a double)
  • Complex (double doubleJ)
  • Sequences...
  • Mapping Types (dict)
  • Functions and Methods
  • Generators

48
__Types__
  • None
  • NotImplemented
  • Boolean
  • Int/LongInt
  • Float (which is really a double)
  • Complex (double doubleJ)
  • Sequences...
  • Mapping Types (dict)
  • Functions and Methods
  • Generators
  • Modules

49
__Types__
  • None
  • NotImplemented
  • Boolean
  • Int/LongInt
  • Float (which is really a double)
  • Complex (double doubleJ)
  • Sequences...
  • Mapping Types (dict)
  • Functions and Methods
  • Generators
  • Modules
  • File/Buffer

50
__Types__
  • None
  • NotImplemented
  • Boolean
  • Int/LongInt
  • Float (which is really a double)
  • Complex (double doubleJ)
  • Sequences...
  • Mapping Types (dict)
  • Functions and Methods
  • Generators
  • Modules
  • File/Buffer
  • Type (metaclasses)

51
Special Duck Methods
  • __abs__
  • __add__
  • __and__
  • __iter__
  • __getitem__
  • __iter__
  • __del__
  • __cmp__!
  • __hash__
  • __lt__
  • For Example

52
Example Code
  • class Foo
  • baz 'monkey'
  • def bar(self)
  • self.printFunc(self.text)
  • foo Foo()
  • foo.text 'Hello World'
  • def print_console_factory(
  • filter_funclambda a a
  • )
  • def print_console(text)
  • print(filter_func(text))
  • return print_console
  • foo.printFunc
  • print_console_factory()
  • print_hello_world foo.bar
  • vowels 'a', 'e', 'i', 'o', 'u'
  • filter_vowels lambda a
  • ''.join( let
  • for let in a
  • if not
  • let.lower() in vowels
  • )
  • foo.printFunc print_console_factory(filter_vowel
    s)
  • print_hello_world()
  • gtgtgtHll Wrld

53
Python Resources
  • Python.org Documentation
  • http//www.python.org
  • Python.org PEPs
  • http//www.python.org/dev/peps/
  • Ye Olde Cheese Shoppe
  • http//pypi.python.org/pypi

54
Alternate Implementation
  • C API
  • http//docs.python.org/extending
  • Create C Modules
  • Execute Python within a C application
  • Interface via a C API

55
Alternate Implementation
  • Jython
  • http//www.jython.org/Project
  • Native JVM Python interpreter
  • Full support for standard library
  • Other C Extensions may not be ported
  • Python extensions may rely on C extensions

56
Alternate Implementation
  • PyPy
  • http//codespeak.net/pypy/dist/pypy/doc/
  • Python interpreter written in python
  • Framework interprets multiple languages
  • Highly extendable
  • Slow

57
Alternate Implementation
  • Psyco
  • http//psyco.sourceforge.net
  • Actually a C module
  • Produces highly optimized C code from python
    bytecode
  • Excellent performance characteristics
  • Configurable

58
Alternate Implementation
  • IronPython
  • http//codesplex.com/Wiki/View.aspx?ProjectNameIr
    onPython
  • Native python interpreter (C) for .NET
  • Full support for standard library
  • Many external modules have been ported
  • Porting modules is quite simple
  • Can integrate with .NET languages

59
Alternate Implementation
  • PyJamas
  • http//code.google.com/p/pyjamas/
  • Python interpreter for JavaScript
  • Cross browser fully supported
  • As lightweight as you'd think
  • JSON/JQuery may be a better option

60
Alternate Implementation
  • ShedSkin
  • http//code.google.com/p/shedskin/
  • Produces C code from Python code
  • Excellent for prototyping
  • Some language features not supported
  • Implicit static typed code only

61
Alternate Implementation
  • Cython
  • http//www.cython.org
  • Embed C code in a python application
  • Excellent for use in profiling
  • Compiled at first runtime
  • Shared build env with python interpreter

62
Hosting Python
  • mod_python
  • By far most common hosting mechanism
  • http//modpython.org
  • Apache2 specific
  • Interpreter embedded in webserver worker
  • Memory intensive
  • Fast

63
Hosting Python
  • WSGI
  • Up and coming for a good reason
  • http//code.google.com/p/modwsgi/
  • http//code.google.com/p/isapi-wsgi/
  • Can embedded interpreter
  • Can run threaded standalong app server
  • Very fast and inexpensive
  • Sandboxing supported

64
Hosting Python
  • FastCGI
  • Mature and stable
  • Requires no 3rd party modules for most webservers
  • Fast and inexpensive
  • Sandboxing supported

65
Hosting Python
  • CGI
  • Mature and stable
  • Supported on nearly all platforms
  • Very flexible in terms of hosting requirements
  • Slow

66
Web Frameworks
  • Django
  • http//www.djangoproject.com/
  • Active user community
  • Well documented
  • Currently under active development
  • Extensive meta and mock classes
  • Clean layer separation

67
Web Frameworks
  • Django
  • Data Layer
  • Business Logic
  • Control Layer
  • Presentation Layer
  • Not just for the web

68
Web Frameworks
  • Turbogears CherryPy
  • http//www.turbogears.org
  • Persistent app server
  • Javascript integration via mochikit
  • Flexible DB backend via SQLObject

69
Web Frameworks
  • Pylons - Paste
  • http//www.pylonshq.org/
  • Multiple DB Backends supported
  • Multiple templating languages pluggable
  • Multiple request dispatching
  • HTTP oriented
  • Forward compatible
  • MVC Type layer separation

70
Web Frameworks
  • Zope
  • http//www.zope.org
  • Web Application Framework
  • Highly Web Oriented
  • Not lightweight
  • Highly Featureful
  • ZDB Data store backend

71
Web Frameworks
  • Zope
  • http//www.zope.org
  • Web Application Framework
  • Highly Web Oriented
  • Not lightweight
  • Highly Featureful
  • ZDB Data store backend
Write a Comment
User Comments (0)
About PowerShow.com