71
Python Programming Language

Python Programming Language

Embed Size (px)

DESCRIPTION

Python Programming Language. Python Programming Language. Created in 1991 by Guido Van Rossum. Python Programming Language. General Purpose Language Clean Syntax. Python Programming Language. General Purpose Language Clean Syntax Easy to Learn. Python Programming Language. - PowerPoint PPT Presentation

Citation preview

  • Python Programming Language

  • Python Programming LanguageCreated in 1991 by Guido Van Rossum

  • Python Programming LanguageGeneral Purpose LanguageClean Syntax

  • Python Programming LanguageGeneral Purpose LanguageClean SyntaxEasy to Learn

  • Python Programming LanguageGeneral Purpose LanguageClean SyntaxEasy to LearnEasy to Debug

  • Python Programming LanguageGeneral Purpose LanguageClean SyntaxEasy to LearnEasy to DebugNatural Feeling

  • Python Programming LanguageGeneral Purpose LanguageInterpreted

  • Python Programming LanguageGeneral Purpose LanguageInterpretedNo Compilation Phase

  • Python Programming LanguageGeneral Purpose LanguageInterpretedNo Compilation PhaseMultiplatform Integration

  • Python Programming LanguageGeneral Purpose LanguageInterpretedNo Compilation PhaseMultiplatform IntegrationNative Debugger

  • Python Programming LanguageGeneral Purpose LanguageInterpretedDuck Typing

  • Python Programming LanguageGeneral Purpose LanguageInterpretedDuck TypingOverride behaviours by creating methods

  • Python Programming LanguageGeneral Purpose LanguageInterpretedDuck TypingOverride behaviours by creating methodsImplement operations by creating methodst

  • Python Programming LanguageGeneral Purpose LanguageInterpretedDuck TypingOverride behaviours by creating methodsImplement operations by creating methodsAll data is an object

  • Python Programming LanguageObjects 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.

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

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

  • Python Programming LanguageGeneral Purpose LanguageInterpretedDuck TypingStrongly Typed

  • Python Programming LanguageA Python programmer can write in any style they like, using design patterns borrowed from:Imperative DeclarativeObject Orientedfunctional programming The author is free let the problem guide the development of the solution.

  • Python Programming Languageprint('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)

  • Functional ExampleJava: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))) Pythonaddn = lambda n: lambda x: x + nOrdef addN(n): def add_n(x): return x + n return add_n

  • Modular DesignThe standard Python interpreter (CPython) is written in C89It is designed with two-way interfacing in mind:Embedding C programs in PythonEmbedding Python programs in C

  • Modular Design

    An Example C Module#include

    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( **** 'find . -name "*.py" **** -exec grep -Hn "Flying Circus" {} \;') ***********************************************************/

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

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

  • Python Is Good ForProtyping

  • Python Is Good ForProtypingWeb Applications/SAS

  • Python Is Good ForProtypingWeb Applications/SASIntegration

  • Python Is Good ForProtypingWeb Applications/SASIntegrationTransport Limited Applications

  • Python Is Good ForProtypingWeb Applications/SASIntegrationTransport Limited ApplicationsIndeterminate Requirements

  • Python Is Good ForProtypingWeb Applications/SASIntegrationTransport Limited ApplicationsIndeterminate requirements Short Relevence Lifetime

  • Python Is Good ForProtypingWeb Applications/SASIntegrationTransport Limited ApplicationsIndeterminate requirements Short Relevence LifetimePorting Legacy Applications

  • Python Is Good ForProtypingWeb Applications/SASIntegrationTransport Limited ApplicationsIndeterminate requirements Short Relevence LifetimePorting Legacy ApplicationsGlue

  • Python is Not Good ForNative Cryptography

  • Python is Not Good ForNative CryptographyMILOR

  • Python is Not Good ForNative CryptographyMILORHighly Parallel Design

  • __Types__None

  • __Types__NoneNotImplemented

  • __Types__NoneNotImplementedBoolean

  • __Types__NoneNotImplementedBooleanInt/LongInt

  • __Types__NoneNotImplementedBooleanInt/LongIntFloat (which is really a double)

  • __Types__NoneNotImplementedBooleanInt/LongIntFloat (which is really a double)Complex (double +doubleJ)

  • __Types__NoneNotImplementedBooleanInt/LongIntFloat (which is really a double)Complex (double +doubleJ)Sequences...

  • __Types__Sequencesstringunicodebytestuplelistsetfrozenset

  • __Types__NoneNotImplementedBooleanInt/LongIntFloat (which is really a double)Complex (double +doubleJ)Sequences...Mapping Types (dict)

  • __Types__NoneNotImplementedBooleanInt/LongIntFloat (which is really a double)Complex (double +doubleJ)Sequences...Mapping Types (dict)Functions and Methods

  • __Types__NoneNotImplementedBooleanInt/LongIntFloat (which is really a double)Complex (double +doubleJ)Sequences...Mapping Types (dict)Functions and MethodsGenerators

  • __Types__NoneNotImplementedBooleanInt/LongIntFloat (which is really a double)Complex (double +doubleJ)Sequences...Mapping Types (dict)Functions and MethodsGeneratorsModules

  • __Types__NoneNotImplementedBooleanInt/LongIntFloat (which is really a double)Complex (double +doubleJ)Sequences...Mapping Types (dict)Functions and MethodsGeneratorsModulesFile/Buffer

  • __Types__NoneNotImplementedBooleanInt/LongIntFloat (which is really a double)Complex (double +doubleJ)Sequences...Mapping Types (dict)Functions and MethodsGeneratorsModulesFile/BufferType (metaclasses)

  • Special Duck Methods__abs__ __add____and____iter____getitem____iter____del____cmp__!__hash____lt__For Example

  • Example Codeclass Foo: baz = 'monkey' def bar(self): self.printFunc(self.text)

    foo = Foo()foo.text = 'Hello World'

    def print_console_factory( filter_func=lambda a: a ): def print_console(text): print(filter_func(text)) return print_console

    foo.printFunc = print_console_factory()

    print_hello_world = foo.barprint_hello_world()

    >>> Hello World

    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_vowels)print_hello_world()

    >>>Hll Wrld

  • Python Resources

    Python.org Documentation http://www.python.orgPython.org PEPs http://www.python.org/dev/peps/Ye Olde Cheese Shoppe http://pypi.python.org/pypi

  • Alternate ImplementationC APIhttp://docs.python.org/extendingCreate C ModulesExecute Python within a C applicationInterface via a C API

  • Alternate ImplementationJythonhttp://www.jython.org/ProjectNative JVM Python interpreterFull support for standard libraryOther C Extensions may not be portedPython extensions may rely on C extensions

  • Alternate ImplementationPyPyhttp://codespeak.net/pypy/dist/pypy/doc/Python interpreter written in pythonFramework interprets multiple languagesHighly extendableSlow

  • Alternate ImplementationPsycohttp://psyco.sourceforge.netActually a C moduleProduces highly optimized C code from python bytecodeExcellent performance characteristicsConfigurable

  • Alternate ImplementationIronPythonhttp://codesplex.com/Wiki/View.aspx?ProjectName=IronPythonNative python interpreter (C#) for .NETFull support for standard libraryMany external modules have been portedPorting modules is quite simpleCan integrate with .NET languages

  • Alternate ImplementationPyJamashttp://code.google.com/p/pyjamas/Python interpreter for JavaScriptCross browser fully supportedAs lightweight as you'd thinkJSON/JQuery may be a better option

  • Alternate ImplementationShedSkinhttp://code.google.com/p/shedskin/Produces C++ code from Python codeExcellent for prototypingSome language features not supportedImplicit static typed code only

  • Alternate ImplementationCythonhttp://www.cython.orgEmbed C code in a python applicationExcellent for use in profilingCompiled at first runtimeShared build env with python interpreter

  • Hosting Pythonmod_pythonBy far most common hosting mechanismhttp://modpython.orgApache2 specificInterpreter embedded in webserver workerMemory intensiveFast

  • Hosting PythonWSGIUp and coming for a good reasonhttp://code.google.com/p/modwsgi/http://code.google.com/p/isapi-wsgi/Can embedded interpreterCan run threaded standalong app serverVery fast and inexpensiveSandboxing supported

  • Hosting PythonFastCGIMature and stableRequires no 3rd party modules for most webserversFast and inexpensiveSandboxing supported

  • Hosting PythonCGIMature and stableSupported on nearly all platformsVery flexible in terms of hosting requirementsSlow

  • Web FrameworksDjangohttp://www.djangoproject.com/Active user communityWell documentedCurrently under active developmentExtensive meta and mock classesClean layer separation

  • Web FrameworksDjangoData LayerBusiness LogicControl LayerPresentation Layer

    Not just for the web

  • Web FrameworksTurbogears CherryPyhttp://www.turbogears.orgPersistent app serverJavascript integration via mochikitFlexible DB backend via SQLObject

  • Web FrameworksPylons - Pastehttp://www.pylonshq.org/Multiple DB Backends supportedMultiple templating languages pluggableMultiple request dispatchingHTTP orientedForward compatibleMVC Type layer separation

  • Web FrameworksZopehttp://www.zope.orgWeb Application FrameworkHighly Web OrientedNot lightweightHighly FeaturefulZDB Data store backend

  • Web FrameworksZopehttp://www.zope.orgWeb Application FrameworkHighly Web OrientedNot lightweightHighly FeaturefulZDB Data store backend