0
Python: the Project, the Language and the Style

                                     Juan Manuel Gimeno Illa
            ...
Outline

 1   Introduction

 2   Python, the project

 3   Python, the language
       References
       Functions
       ...
Introduction


What this session pretends


        A very light introduction to the making of Python (the project)
      ...
Introduction


What this session pretends


        A very light introduction to the making of Python (the project)
      ...
Introduction


What this session pretends


        A very light introduction to the making of Python (the project)
      ...
Introduction


What this session pretends


        A very light introduction to the making of Python (the project)
      ...
Introduction


What this session pretends


        A very light introduction to the making of Python (the project)
      ...
Introduction


What this session pretends


        A very light introduction to the making of Python (the project)
      ...
Python, the project


Organization

        Initiated by Guido van Rossum (BDFL: Benevolent Dictator For Life)
        in ...
Python, the project


Organization

        Initiated by Guido van Rossum (BDFL: Benevolent Dictator For Life)
        in ...
Python, the project


Organization

        Initiated by Guido van Rossum (BDFL: Benevolent Dictator For Life)
        in ...
Python, the project


Organization

        Initiated by Guido van Rossum (BDFL: Benevolent Dictator For Life)
        in ...
Python, the project


Organization

        Initiated by Guido van Rossum (BDFL: Benevolent Dictator For Life)
        in ...
Python, the project


Organization

        Initiated by Guido van Rossum (BDFL: Benevolent Dictator For Life)
        in ...
Python, the project


Organization

        Initiated by Guido van Rossum (BDFL: Benevolent Dictator For Life)
        in ...
Python, the project


Organization

        Initiated by Guido van Rossum (BDFL: Benevolent Dictator For Life)
        in ...
Python, the project


Organization

        Initiated by Guido van Rossum (BDFL: Benevolent Dictator For Life)
        in ...
Python, the project


Organization

        Initiated by Guido van Rossum (BDFL: Benevolent Dictator For Life)
        in ...
Python, the project


Implementations
 The language Python has different implementations
     CPython: Standard implementat...
Python, the project


Implementations
 The language Python has different implementations
     CPython: Standard implementat...
Python, the project


Implementations
 The language Python has different implementations
     CPython: Standard implementat...
Python, the project


Implementations
 The language Python has different implementations
     CPython: Standard implementat...
Python, the project


Implementations
 The language Python has different implementations
     CPython: Standard implementat...
Python, the project


Implementations
 The language Python has different implementations
     CPython: Standard implementat...
Python, the project


Implementations
 The language Python has different implementations
     CPython: Standard implementat...
Python, the project


Implementations
 The language Python has different implementations
     CPython: Standard implementat...
Python, the project


Implementations
 The language Python has different implementations
     CPython: Standard implementat...
Python, the language    References


Variables and References
        A Python program access data values through referenc...
Python, the language    References


Variables and References
        A Python program access data values through referenc...
Python, the language    References


Variables and References
        A Python program access data values through referenc...
Python, the language    References


Variables and References
        A Python program access data values through referenc...
Python, the language    References


Variables and References
        A Python program access data values through referenc...
Python, the language    References


Variables and References
        A Python program access data values through referenc...
Python, the language    References


Variables and References
        A Python program access data values through referenc...
Python, the language    References


Variables and References
        A Python program access data values through referenc...
Python, the language    References


Variables and References
        A Python program access data values through referenc...
Python, the language    References


Variables and References
        A Python program access data values through referenc...
Python, the language    References


Binding, Rebinding and Unbinding
                                                    ...
Python, the language    References


Binding, Rebinding and Unbinding
                                                    ...
Python, the language    References


Binding, Rebinding and Unbinding
                                                    ...
Python, the language    References


Binding, Rebinding and Unbinding
                                                    ...
Python, the language    References


Binding, Rebinding and Unbinding
                                                    ...
Python, the language    Functions


The def statement


         def function-name(mandatory, optional=expression):
      ...
Python, the language    Functions


The def statement


         def function-name(mandatory, optional=expression):
      ...
Python, the language    Functions


The def statement


         def function-name(mandatory, optional=expression):
      ...
Python, the language    Functions


The def statement


         def function-name(mandatory, optional=expression):
      ...
Python, the language    Functions


The def statement


         def function-name(mandatory, optional=expression):
      ...
Python, the language    Functions


Evaluation of the defaults
 The default expression is not evaluated when the function ...
Python, the language    Functions


Evaluation of the defaults
 The default expression is not evaluated when the function ...
Python, the language    Functions


Evaluation of the defaults
 The default expression is not evaluated when the function ...
Python, the language    Functions


Evaluation of the defaults
 The default expression is not evaluated when the function ...
Python, the language    Functions


Evaluation of the defaults
 The default expression is not evaluated when the function ...
Python, the language    Functions


Evaluation of the defaults
 The default expression is not evaluated when the function ...
Python, the language    Functions


Extra Positional Arguments

        At the end of the arguments list you may optionall...
Python, the language    Functions


Extra Positional Arguments

        At the end of the arguments list you may optionall...
Python, the language    Functions


Extra Positional Arguments

        At the end of the arguments list you may optionall...
Python, the language    Functions


Extra Positional Arguments

        At the end of the arguments list you may optionall...
Python, the language    Functions


Extra Positional Arguments

        At the end of the arguments list you may optionall...
Python, the language    Functions


Extra Positional Arguments

        At the end of the arguments list you may optionall...
Python, the language    Functions


Extra Positional Arguments

        At the end of the arguments list you may optionall...
Python, the language    Functions


Extra Positional Arguments

        At the end of the arguments list you may optionall...
Python, the language    Functions


Extra Positional Arguments

        At the end of the arguments list you may optionall...
Python, the language    Functions


Extra Positional Arguments

        At the end of the arguments list you may optionall...
Python, the language    Functions


Extra Positional Arguments

        At the end of the arguments list you may optionall...
Python, the language    Functions


Extra Positional Arguments

        At the end of the arguments list you may optionall...
Python, the language    Functions


Extra Positional Arguments

        At the end of the arguments list you may optionall...
Python, the language    Functions


Extra Positional Arguments

        At the end of the arguments list you may optionall...
Python, the language    Functions


Extra Positional Arguments

        At the end of the arguments list you may optionall...
Python, the language    Functions


Extra Named Arguments
        At the end of the arguments list you may optionally add ...
Python, the language    Functions


Extra Named Arguments
        At the end of the arguments list you may optionally add ...
Python, the language    Functions


Extra Named Arguments
        At the end of the arguments list you may optionally add ...
Python, the language    Functions


Extra Named Arguments
        At the end of the arguments list you may optionally add ...
Python, the language    Functions


Extra Named Arguments
        At the end of the arguments list you may optionally add ...
Python, the language    Functions


Extra Named Arguments
        At the end of the arguments list you may optionally add ...
Python, the language    Functions


Extra Named Arguments
        At the end of the arguments list you may optionally add ...
Python, the language    Functions


Extra Named Arguments
        At the end of the arguments list you may optionally add ...
Python, the language    Functions


Extra Named Arguments
        At the end of the arguments list you may optionally add ...
Python, the language    Functions


Extra Named Arguments
        At the end of the arguments list you may optionally add ...
Python, the language    Functions


Extra Named Arguments
        At the end of the arguments list you may optionally add ...
Python, the language    Functions


Extra Named Arguments
        At the end of the arguments list you may optionally add ...
Python, the language    Functions


Extra Named Arguments
        At the end of the arguments list you may optionally add ...
Python, the language    Functions


Extra Named Arguments
        At the end of the arguments list you may optionally add ...
Python, the language    Functions


Extra Named Arguments
        At the end of the arguments list you may optionally add ...
Python, the language    Functions


Extra Named Arguments
        At the end of the arguments list you may optionally add ...
Python, the language    Modules and Packages


Modules
        A typical Python program is made up of several source files
...
Python, the language    Modules and Packages


Modules
        A typical Python program is made up of several source files
...
Python, the language    Modules and Packages


Modules
        A typical Python program is made up of several source files
...
Python, the language    Modules and Packages


Modules
        A typical Python program is made up of several source files
...
Python, the language    Modules and Packages


Modules
        A typical Python program is made up of several source files
...
Python, the language    Modules and Packages


Modules
        A typical Python program is made up of several source files
...
Python, the language    Modules and Packages


Modules
        A typical Python program is made up of several source files
...
Python, the language    Modules and Packages


Modules
        A typical Python program is made up of several source files
...
Python, the language    Modules and Packages


Modules
        A typical Python program is made up of several source files
...
Python, the language    Modules and Packages


Modules
        A typical Python program is made up of several source files
...
Python, the language    Modules and Packages


import modulename

  spam.py
  #!/usr/bin/env python
  # -*- coding: latin-...
Python, the language    Modules and Packages


import modulename
                                                    >>> i...
Python, the language    Modules and Packages


import modulename
                                                    >>> i...
Python, the language    Modules and Packages


import modulename
                                                    >>> i...
Python, the language    Modules and Packages


import modulename
                                                    >>> i...
Python, the language    Modules and Packages


import modulename
                                                    >>> i...
Python, the language    Modules and Packages


import modulename
                                                    >>> i...
Python, the language    Modules and Packages


import modulename
                                                    >>> i...
Python, the language    Modules and Packages


import modulename
                                                    >>> i...
Python, the language    Modules and Packages


import modulename
                                                    >>> i...
Python, the language    Modules and Packages


import modulename
                                                    >>> i...
Python, the language    Modules and Packages


import modulename
                                                    >>> i...
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Upcoming SlideShare
Loading in...5
×

Python: the Project, the Language and the Style

2,525

Published on

An introduction to the python language and its organization as an open-source project.

Published in: Education
1 Comment
12 Likes
Statistics
Notes
No Downloads
Views
Total Views
2,525
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
175
Comments
1
Likes
12
Embeds 0
No embeds

No notes for slide

Transcript of "Python: the Project, the Language and the Style"

  1. 1. Python: the Project, the Language and the Style Juan Manuel Gimeno Illa jmgimeno@diei.udl.cat October 2008 J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 1 / 28
  2. 2. Outline 1 Introduction 2 Python, the project 3 Python, the language References Functions Modules and Packages Namespaces and Scopes 4 Python, the style 5 Hands on Work J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 2 / 28
  3. 3. Introduction What this session pretends A very light introduction to the making of Python (the project) A presentation of some aspects of Python (the language) We will focus on those elements and concepts that are most shocking for people coming from C, C++, Java, . . . A basic knowledge of the language is assumed (a casual reading the Python Tutorial is enough) We will begin to get into what me might call the python style of doing things (the style) (In the live session we will also present the interpreter (python), an enhanced interpreter (ipython) and the default integrated development environment (idle) among other things) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 3 / 28
  4. 4. Introduction What this session pretends A very light introduction to the making of Python (the project) A presentation of some aspects of Python (the language) We will focus on those elements and concepts that are most shocking for people coming from C, C++, Java, . . . A basic knowledge of the language is assumed (a casual reading the Python Tutorial is enough) We will begin to get into what me might call the python style of doing things (the style) (In the live session we will also present the interpreter (python), an enhanced interpreter (ipython) and the default integrated development environment (idle) among other things) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 3 / 28
  5. 5. Introduction What this session pretends A very light introduction to the making of Python (the project) A presentation of some aspects of Python (the language) We will focus on those elements and concepts that are most shocking for people coming from C, C++, Java, . . . A basic knowledge of the language is assumed (a casual reading the Python Tutorial is enough) We will begin to get into what me might call the python style of doing things (the style) (In the live session we will also present the interpreter (python), an enhanced interpreter (ipython) and the default integrated development environment (idle) among other things) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 3 / 28
  6. 6. Introduction What this session pretends A very light introduction to the making of Python (the project) A presentation of some aspects of Python (the language) We will focus on those elements and concepts that are most shocking for people coming from C, C++, Java, . . . A basic knowledge of the language is assumed (a casual reading the Python Tutorial is enough) We will begin to get into what me might call the python style of doing things (the style) (In the live session we will also present the interpreter (python), an enhanced interpreter (ipython) and the default integrated development environment (idle) among other things) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 3 / 28
  7. 7. Introduction What this session pretends A very light introduction to the making of Python (the project) A presentation of some aspects of Python (the language) We will focus on those elements and concepts that are most shocking for people coming from C, C++, Java, . . . A basic knowledge of the language is assumed (a casual reading the Python Tutorial is enough) We will begin to get into what me might call the python style of doing things (the style) (In the live session we will also present the interpreter (python), an enhanced interpreter (ipython) and the default integrated development environment (idle) among other things) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 3 / 28
  8. 8. Introduction What this session pretends A very light introduction to the making of Python (the project) A presentation of some aspects of Python (the language) We will focus on those elements and concepts that are most shocking for people coming from C, C++, Java, . . . A basic knowledge of the language is assumed (a casual reading the Python Tutorial is enough) We will begin to get into what me might call the python style of doing things (the style) (In the live session we will also present the interpreter (python), an enhanced interpreter (ipython) and the default integrated development environment (idle) among other things) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 3 / 28
  9. 9. Python, the project Organization Initiated by Guido van Rossum (BDFL: Benevolent Dictator For Life) in 1990 and made public in 1991 By the years, a process and an infrastructure for the development of Python have emerged: SourceForge: patches, bugs, etc. Mailing lists: python-dev, python-list Newsgroup: comp.lang.python PEPs: Python Enhancement Proposals SIGs: Special Interest Groups PSF: Python Software Foundation holds the copyright of Python since version 2.1 All of this is accessible from http://python.org Its a very open project provided you follow some rules!! J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 4 / 28
  10. 10. Python, the project Organization Initiated by Guido van Rossum (BDFL: Benevolent Dictator For Life) in 1990 and made public in 1991 By the years, a process and an infrastructure for the development of Python have emerged: SourceForge: patches, bugs, etc. Mailing lists: python-dev, python-list Newsgroup: comp.lang.python PEPs: Python Enhancement Proposals SIGs: Special Interest Groups PSF: Python Software Foundation holds the copyright of Python since version 2.1 All of this is accessible from http://python.org Its a very open project provided you follow some rules!! J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 4 / 28
  11. 11. Python, the project Organization Initiated by Guido van Rossum (BDFL: Benevolent Dictator For Life) in 1990 and made public in 1991 By the years, a process and an infrastructure for the development of Python have emerged: SourceForge: patches, bugs, etc. Mailing lists: python-dev, python-list Newsgroup: comp.lang.python PEPs: Python Enhancement Proposals SIGs: Special Interest Groups PSF: Python Software Foundation holds the copyright of Python since version 2.1 All of this is accessible from http://python.org Its a very open project provided you follow some rules!! J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 4 / 28
  12. 12. Python, the project Organization Initiated by Guido van Rossum (BDFL: Benevolent Dictator For Life) in 1990 and made public in 1991 By the years, a process and an infrastructure for the development of Python have emerged: SourceForge: patches, bugs, etc. Mailing lists: python-dev, python-list Newsgroup: comp.lang.python PEPs: Python Enhancement Proposals SIGs: Special Interest Groups PSF: Python Software Foundation holds the copyright of Python since version 2.1 All of this is accessible from http://python.org Its a very open project provided you follow some rules!! J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 4 / 28
  13. 13. Python, the project Organization Initiated by Guido van Rossum (BDFL: Benevolent Dictator For Life) in 1990 and made public in 1991 By the years, a process and an infrastructure for the development of Python have emerged: SourceForge: patches, bugs, etc. Mailing lists: python-dev, python-list Newsgroup: comp.lang.python PEPs: Python Enhancement Proposals SIGs: Special Interest Groups PSF: Python Software Foundation holds the copyright of Python since version 2.1 All of this is accessible from http://python.org Its a very open project provided you follow some rules!! J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 4 / 28
  14. 14. Python, the project Organization Initiated by Guido van Rossum (BDFL: Benevolent Dictator For Life) in 1990 and made public in 1991 By the years, a process and an infrastructure for the development of Python have emerged: SourceForge: patches, bugs, etc. Mailing lists: python-dev, python-list Newsgroup: comp.lang.python PEPs: Python Enhancement Proposals SIGs: Special Interest Groups PSF: Python Software Foundation holds the copyright of Python since version 2.1 All of this is accessible from http://python.org Its a very open project provided you follow some rules!! J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 4 / 28
  15. 15. Python, the project Organization Initiated by Guido van Rossum (BDFL: Benevolent Dictator For Life) in 1990 and made public in 1991 By the years, a process and an infrastructure for the development of Python have emerged: SourceForge: patches, bugs, etc. Mailing lists: python-dev, python-list Newsgroup: comp.lang.python PEPs: Python Enhancement Proposals SIGs: Special Interest Groups PSF: Python Software Foundation holds the copyright of Python since version 2.1 All of this is accessible from http://python.org Its a very open project provided you follow some rules!! J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 4 / 28
  16. 16. Python, the project Organization Initiated by Guido van Rossum (BDFL: Benevolent Dictator For Life) in 1990 and made public in 1991 By the years, a process and an infrastructure for the development of Python have emerged: SourceForge: patches, bugs, etc. Mailing lists: python-dev, python-list Newsgroup: comp.lang.python PEPs: Python Enhancement Proposals SIGs: Special Interest Groups PSF: Python Software Foundation holds the copyright of Python since version 2.1 All of this is accessible from http://python.org Its a very open project provided you follow some rules!! J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 4 / 28
  17. 17. Python, the project Organization Initiated by Guido van Rossum (BDFL: Benevolent Dictator For Life) in 1990 and made public in 1991 By the years, a process and an infrastructure for the development of Python have emerged: SourceForge: patches, bugs, etc. Mailing lists: python-dev, python-list Newsgroup: comp.lang.python PEPs: Python Enhancement Proposals SIGs: Special Interest Groups PSF: Python Software Foundation holds the copyright of Python since version 2.1 All of this is accessible from http://python.org Its a very open project provided you follow some rules!! J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 4 / 28
  18. 18. Python, the project Organization Initiated by Guido van Rossum (BDFL: Benevolent Dictator For Life) in 1990 and made public in 1991 By the years, a process and an infrastructure for the development of Python have emerged: SourceForge: patches, bugs, etc. Mailing lists: python-dev, python-list Newsgroup: comp.lang.python PEPs: Python Enhancement Proposals SIGs: Special Interest Groups PSF: Python Software Foundation holds the copyright of Python since version 2.1 All of this is accessible from http://python.org Its a very open project provided you follow some rules!! J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 4 / 28
  19. 19. Python, the project Implementations The language Python has different implementations CPython: Standard implementation of the python language in C. Currently at version 2.6 of the language Jython: Java implementation that compiles python code to JVM byte-code Currently at version 2.2.1 of the language (alpha version 2.5a3) IronPython: .NET implementation that compiles python code to CLR Currently at version 2.4 of the language (with minor differences) Stackless: enhanced version using micro-threads, implemented in C Currently at version 2.6 of the language PyPy: Rather experimental version of python written in python Python 3000: (or py3k) non-backwards compatible evolution of CPython We will use CPython versions 2.4 (very little differences) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 5 / 28
  20. 20. Python, the project Implementations The language Python has different implementations CPython: Standard implementation of the python language in C. Currently at version 2.6 of the language Jython: Java implementation that compiles python code to JVM byte-code Currently at version 2.2.1 of the language (alpha version 2.5a3) IronPython: .NET implementation that compiles python code to CLR Currently at version 2.4 of the language (with minor differences) Stackless: enhanced version using micro-threads, implemented in C Currently at version 2.6 of the language PyPy: Rather experimental version of python written in python Python 3000: (or py3k) non-backwards compatible evolution of CPython We will use CPython versions 2.4 (very little differences) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 5 / 28
  21. 21. Python, the project Implementations The language Python has different implementations CPython: Standard implementation of the python language in C. Currently at version 2.6 of the language Jython: Java implementation that compiles python code to JVM byte-code Currently at version 2.2.1 of the language (alpha version 2.5a3) IronPython: .NET implementation that compiles python code to CLR Currently at version 2.4 of the language (with minor differences) Stackless: enhanced version using micro-threads, implemented in C Currently at version 2.6 of the language PyPy: Rather experimental version of python written in python Python 3000: (or py3k) non-backwards compatible evolution of CPython We will use CPython versions 2.4 (very little differences) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 5 / 28
  22. 22. Python, the project Implementations The language Python has different implementations CPython: Standard implementation of the python language in C. Currently at version 2.6 of the language Jython: Java implementation that compiles python code to JVM byte-code Currently at version 2.2.1 of the language (alpha version 2.5a3) IronPython: .NET implementation that compiles python code to CLR Currently at version 2.4 of the language (with minor differences) Stackless: enhanced version using micro-threads, implemented in C Currently at version 2.6 of the language PyPy: Rather experimental version of python written in python Python 3000: (or py3k) non-backwards compatible evolution of CPython We will use CPython versions 2.4 (very little differences) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 5 / 28
  23. 23. Python, the project Implementations The language Python has different implementations CPython: Standard implementation of the python language in C. Currently at version 2.6 of the language Jython: Java implementation that compiles python code to JVM byte-code Currently at version 2.2.1 of the language (alpha version 2.5a3) IronPython: .NET implementation that compiles python code to CLR Currently at version 2.4 of the language (with minor differences) Stackless: enhanced version using micro-threads, implemented in C Currently at version 2.6 of the language PyPy: Rather experimental version of python written in python Python 3000: (or py3k) non-backwards compatible evolution of CPython We will use CPython versions 2.4 (very little differences) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 5 / 28
  24. 24. Python, the project Implementations The language Python has different implementations CPython: Standard implementation of the python language in C. Currently at version 2.6 of the language Jython: Java implementation that compiles python code to JVM byte-code Currently at version 2.2.1 of the language (alpha version 2.5a3) IronPython: .NET implementation that compiles python code to CLR Currently at version 2.4 of the language (with minor differences) Stackless: enhanced version using micro-threads, implemented in C Currently at version 2.6 of the language PyPy: Rather experimental version of python written in python Python 3000: (or py3k) non-backwards compatible evolution of CPython We will use CPython versions 2.4 (very little differences) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 5 / 28
  25. 25. Python, the project Implementations The language Python has different implementations CPython: Standard implementation of the python language in C. Currently at version 2.6 of the language Jython: Java implementation that compiles python code to JVM byte-code Currently at version 2.2.1 of the language (alpha version 2.5a3) IronPython: .NET implementation that compiles python code to CLR Currently at version 2.4 of the language (with minor differences) Stackless: enhanced version using micro-threads, implemented in C Currently at version 2.6 of the language PyPy: Rather experimental version of python written in python Python 3000: (or py3k) non-backwards compatible evolution of CPython We will use CPython versions 2.4 (very little differences) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 5 / 28
  26. 26. Python, the project Implementations The language Python has different implementations CPython: Standard implementation of the python language in C. Currently at version 2.6 of the language Jython: Java implementation that compiles python code to JVM byte-code Currently at version 2.2.1 of the language (alpha version 2.5a3) IronPython: .NET implementation that compiles python code to CLR Currently at version 2.4 of the language (with minor differences) Stackless: enhanced version using micro-threads, implemented in C Currently at version 2.6 of the language PyPy: Rather experimental version of python written in python Python 3000: (or py3k) non-backwards compatible evolution of CPython We will use CPython versions 2.4 (very little differences) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 5 / 28
  27. 27. Python, the project Implementations The language Python has different implementations CPython: Standard implementation of the python language in C. Currently at version 2.6 of the language Jython: Java implementation that compiles python code to JVM byte-code Currently at version 2.2.1 of the language (alpha version 2.5a3) IronPython: .NET implementation that compiles python code to CLR Currently at version 2.4 of the language (with minor differences) Stackless: enhanced version using micro-threads, implemented in C Currently at version 2.6 of the language PyPy: Rather experimental version of python written in python Python 3000: (or py3k) non-backwards compatible evolution of CPython We will use CPython versions 2.4 (very little differences) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 5 / 28
  28. 28. Python, the language References Variables and References A Python program access data values through references A reference is a name that refers to the location in memory of a value (object) (Python classes, functions and methods are also objects) References takes the form of variables (x), attributes (x.y) and items (x[y]) A reference has no intrinsic type but gets the type of the referenced object (duck typing) The process of linking a reference to a value is called binding References can be rebound to another object Statements that create/modify bindings are assignment, def, class and import The del statement unbinds the reference (does not deletes the object) Bindings live in name-spaces (more on this later) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 6 / 28
  29. 29. Python, the language References Variables and References A Python program access data values through references A reference is a name that refers to the location in memory of a value (object) (Python classes, functions and methods are also objects) References takes the form of variables (x), attributes (x.y) and items (x[y]) A reference has no intrinsic type but gets the type of the referenced object (duck typing) The process of linking a reference to a value is called binding References can be rebound to another object Statements that create/modify bindings are assignment, def, class and import The del statement unbinds the reference (does not deletes the object) Bindings live in name-spaces (more on this later) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 6 / 28
  30. 30. Python, the language References Variables and References A Python program access data values through references A reference is a name that refers to the location in memory of a value (object) (Python classes, functions and methods are also objects) References takes the form of variables (x), attributes (x.y) and items (x[y]) A reference has no intrinsic type but gets the type of the referenced object (duck typing) The process of linking a reference to a value is called binding References can be rebound to another object Statements that create/modify bindings are assignment, def, class and import The del statement unbinds the reference (does not deletes the object) Bindings live in name-spaces (more on this later) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 6 / 28
  31. 31. Python, the language References Variables and References A Python program access data values through references A reference is a name that refers to the location in memory of a value (object) (Python classes, functions and methods are also objects) References takes the form of variables (x), attributes (x.y) and items (x[y]) A reference has no intrinsic type but gets the type of the referenced object (duck typing) The process of linking a reference to a value is called binding References can be rebound to another object Statements that create/modify bindings are assignment, def, class and import The del statement unbinds the reference (does not deletes the object) Bindings live in name-spaces (more on this later) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 6 / 28
  32. 32. Python, the language References Variables and References A Python program access data values through references A reference is a name that refers to the location in memory of a value (object) (Python classes, functions and methods are also objects) References takes the form of variables (x), attributes (x.y) and items (x[y]) A reference has no intrinsic type but gets the type of the referenced object (duck typing) The process of linking a reference to a value is called binding References can be rebound to another object Statements that create/modify bindings are assignment, def, class and import The del statement unbinds the reference (does not deletes the object) Bindings live in name-spaces (more on this later) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 6 / 28
  33. 33. Python, the language References Variables and References A Python program access data values through references A reference is a name that refers to the location in memory of a value (object) (Python classes, functions and methods are also objects) References takes the form of variables (x), attributes (x.y) and items (x[y]) A reference has no intrinsic type but gets the type of the referenced object (duck typing) The process of linking a reference to a value is called binding References can be rebound to another object Statements that create/modify bindings are assignment, def, class and import The del statement unbinds the reference (does not deletes the object) Bindings live in name-spaces (more on this later) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 6 / 28
  34. 34. Python, the language References Variables and References A Python program access data values through references A reference is a name that refers to the location in memory of a value (object) (Python classes, functions and methods are also objects) References takes the form of variables (x), attributes (x.y) and items (x[y]) A reference has no intrinsic type but gets the type of the referenced object (duck typing) The process of linking a reference to a value is called binding References can be rebound to another object Statements that create/modify bindings are assignment, def, class and import The del statement unbinds the reference (does not deletes the object) Bindings live in name-spaces (more on this later) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 6 / 28
  35. 35. Python, the language References Variables and References A Python program access data values through references A reference is a name that refers to the location in memory of a value (object) (Python classes, functions and methods are also objects) References takes the form of variables (x), attributes (x.y) and items (x[y]) A reference has no intrinsic type but gets the type of the referenced object (duck typing) The process of linking a reference to a value is called binding References can be rebound to another object Statements that create/modify bindings are assignment, def, class and import The del statement unbinds the reference (does not deletes the object) Bindings live in name-spaces (more on this later) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 6 / 28
  36. 36. Python, the language References Variables and References A Python program access data values through references A reference is a name that refers to the location in memory of a value (object) (Python classes, functions and methods are also objects) References takes the form of variables (x), attributes (x.y) and items (x[y]) A reference has no intrinsic type but gets the type of the referenced object (duck typing) The process of linking a reference to a value is called binding References can be rebound to another object Statements that create/modify bindings are assignment, def, class and import The del statement unbinds the reference (does not deletes the object) Bindings live in name-spaces (more on this later) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 6 / 28
  37. 37. Python, the language References Variables and References A Python program access data values through references A reference is a name that refers to the location in memory of a value (object) (Python classes, functions and methods are also objects) References takes the form of variables (x), attributes (x.y) and items (x[y]) A reference has no intrinsic type but gets the type of the referenced object (duck typing) The process of linking a reference to a value is called binding References can be rebound to another object Statements that create/modify bindings are assignment, def, class and import The del statement unbinds the reference (does not deletes the object) Bindings live in name-spaces (more on this later) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 6 / 28
  38. 38. Python, the language References Binding, Rebinding and Unbinding >>> l = [] >>> id(l) -1210453844 l gets bound though assignment to a list (id returns the identity of an object) l maintains its identity through method application But gets rebound with assignment In this case, augmented assignment does not rebind del statement unbinds the reference (it does not delete objects!!) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 7 / 28
  39. 39. Python, the language References Binding, Rebinding and Unbinding >>> l = [] >>> id(l) -1210453844 >>> l.append(1) l gets bound though assignment to a list >>> id(l) (id returns the identity of an object) -1210453844 l maintains its identity through method application But gets rebound with assignment In this case, augmented assignment does not rebind del statement unbinds the reference (it does not delete objects!!) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 7 / 28
  40. 40. Python, the language References Binding, Rebinding and Unbinding >>> l = [] >>> id(l) -1210453844 >>> l.append(1) l gets bound though assignment to a list >>> id(l) (id returns the identity of an object) -1210453844 l maintains its identity through method >>> l = l + [2] application >>> id(l) But gets rebound with assignment -1210467412 In this case, augmented assignment does not rebind del statement unbinds the reference (it does not delete objects!!) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 7 / 28
  41. 41. Python, the language References Binding, Rebinding and Unbinding >>> l = [] >>> id(l) -1210453844 >>> l.append(1) l gets bound though assignment to a list >>> id(l) (id returns the identity of an object) -1210453844 l maintains its identity through method >>> l = l + [2] application >>> id(l) But gets rebound with assignment -1210467412 In this case, augmented assignment does >>> l += [3] not rebind >>> id(l) del statement unbinds the reference (it -1210467412 does not delete objects!!) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 7 / 28
  42. 42. Python, the language References Binding, Rebinding and Unbinding >>> l = [] >>> id(l) -1210453844 >>> l.append(1) l gets bound though assignment to a list >>> id(l) (id returns the identity of an object) -1210453844 l maintains its identity through method >>> l = l + [2] application >>> id(l) But gets rebound with assignment -1210467412 In this case, augmented assignment does >>> l += [3] not rebind >>> id(l) del statement unbinds the reference (it -1210467412 does not delete objects!!) >>> del l >>> id(l) Traceback (most recent call last): File ’<stdin>’, line 1, in ? NameError: name ’l’ is not defined J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 7 / 28
  43. 43. Python, the language Functions The def statement def function-name(mandatory, optional=expression): statement(s) Formal parameters can be Mandatory Each call must supply a value for the parameter Optional If the call does not supply a value, the default is used The def statement evaluates the expression and saves a reference to the expression value (the default value of the parameter) among the attributes of the function object J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 8 / 28
  44. 44. Python, the language Functions The def statement def function-name(mandatory, optional=expression): statement(s) Formal parameters can be Mandatory Each call must supply a value for the parameter Optional If the call does not supply a value, the default is used The def statement evaluates the expression and saves a reference to the expression value (the default value of the parameter) among the attributes of the function object J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 8 / 28
  45. 45. Python, the language Functions The def statement def function-name(mandatory, optional=expression): statement(s) Formal parameters can be Mandatory Each call must supply a value for the parameter Optional If the call does not supply a value, the default is used The def statement evaluates the expression and saves a reference to the expression value (the default value of the parameter) among the attributes of the function object J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 8 / 28
  46. 46. Python, the language Functions The def statement def function-name(mandatory, optional=expression): statement(s) Formal parameters can be Mandatory Each call must supply a value for the parameter Optional If the call does not supply a value, the default is used The def statement evaluates the expression and saves a reference to the expression value (the default value of the parameter) among the attributes of the function object J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 8 / 28
  47. 47. Python, the language Functions The def statement def function-name(mandatory, optional=expression): statement(s) Formal parameters can be Mandatory Each call must supply a value for the parameter Optional If the call does not supply a value, the default is used The def statement evaluates the expression and saves a reference to the expression value (the default value of the parameter) among the attributes of the function object J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 8 / 28
  48. 48. Python, the language Functions Evaluation of the defaults The default expression is not evaluated when the function gets called. >>> def f(x, y=None): >>> def f(x, y=[]): ... if y is None: y = [] ... y.append(x) ... y.append(x) ... return y ... return y ... ... >>> print f(23) >>> print f(23) [23] [23] >>> print f(42) >>> print f(42) [23, 42] [42] The y=None idiom is the standard way to deal with mutable defaults. Problem: Do you find another solution in this case? J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 9 / 28
  49. 49. Python, the language Functions Evaluation of the defaults The default expression is not evaluated when the function gets called. >>> def f(x, y=None): >>> def f(x, y=[]): ... if y is None: y = [] ... y.append(x) ... y.append(x) ... return y ... return y ... ... >>> print f(23) >>> print f(23) [23] [23] >>> print f(42) >>> print f(42) [23, 42] [42] The y=None idiom is the standard way to deal with mutable defaults. Problem: Do you find another solution in this case? J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 9 / 28
  50. 50. Python, the language Functions Evaluation of the defaults The default expression is not evaluated when the function gets called. >>> def f(x, y=None): >>> def f(x, y=[]): ... if y is None: y = [] ... y.append(x) ... y.append(x) ... return y ... return y ... ... >>> print f(23) >>> print f(23) [23] [23] >>> print f(42) >>> print f(42) [23, 42] [42] The y=None idiom is the standard way to deal with mutable defaults. Problem: Do you find another solution in this case? J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 9 / 28
  51. 51. Python, the language Functions Evaluation of the defaults The default expression is not evaluated when the function gets called. >>> def f(x, y=None): >>> def f(x, y=[]): ... if y is None: y = [] ... y.append(x) ... y.append(x) ... return y ... return y ... ... >>> print f(23) >>> print f(23) [23] [23] >>> print f(42) >>> print f(42) [23, 42] [42] The y=None idiom is the standard way to deal with mutable defaults. Problem: Do you find another solution in this case? J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 9 / 28
  52. 52. Python, the language Functions Evaluation of the defaults The default expression is not evaluated when the function gets called. >>> def f(x, y=None): >>> def f(x, y=[]): ... if y is None: y = [] ... y.append(x) ... y.append(x) ... return y ... return y ... ... >>> print f(23) >>> print f(23) [23] [23] >>> print f(42) >>> print f(42) [23, 42] [42] The y=None idiom is the standard way to deal with mutable defaults. Problem: Do you find another solution in this case? J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 9 / 28
  53. 53. Python, the language Functions Evaluation of the defaults The default expression is not evaluated when the function gets called. >>> def f(x, y=None): >>> def f(x, y=[]): ... if y is None: y = [] ... y.append(x) ... y.append(x) ... return y ... return y ... ... >>> print f(23) >>> print f(23) [23] [23] >>> print f(42) >>> print f(42) [23, 42] [42] The y=None idiom is the standard way to deal with mutable defaults. Problem: Do you find another solution in this case? J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 9 / 28
  54. 54. Python, the language Functions Extra Positional Arguments At the end of the arguments list you may optionally add the special form *args This binds args to a tuple containing the extra values passed in the function call J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 10 / 28
  55. 55. Python, the language Functions Extra Positional Arguments At the end of the arguments list you may optionally add the special form *args This binds args to a tuple containing the extra values passed in the function call J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 10 / 28
  56. 56. Python, the language Functions Extra Positional Arguments At the end of the arguments list you may optionally add the special form *args This binds args to a tuple containing the extra values passed in the function call >>> def spam(a, b, *args): ... print a, b, args J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 10 / 28
  57. 57. Python, the language Functions Extra Positional Arguments At the end of the arguments list you may optionally add the special form *args This binds args to a tuple containing the extra values passed in the function call >>> def spam(a, b, *args): ... print a, b, args >>> spam(1, 2) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 10 / 28
  58. 58. Python, the language Functions Extra Positional Arguments At the end of the arguments list you may optionally add the special form *args This binds args to a tuple containing the extra values passed in the function call >>> def spam(a, b, *args): ... print a, b, args >>> spam(1, 2) 1 2 () J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 10 / 28
  59. 59. Python, the language Functions Extra Positional Arguments At the end of the arguments list you may optionally add the special form *args This binds args to a tuple containing the extra values passed in the function call >>> def spam(a, b, *args): ... print a, b, args >>> spam(1, 2) 1 2 () >>> spam(b=1, a=2) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 10 / 28
  60. 60. Python, the language Functions Extra Positional Arguments At the end of the arguments list you may optionally add the special form *args This binds args to a tuple containing the extra values passed in the function call >>> def spam(a, b, *args): ... print a, b, args >>> spam(1, 2) 1 2 () >>> spam(b=1, a=2) 2 1 () J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 10 / 28
  61. 61. Python, the language Functions Extra Positional Arguments At the end of the arguments list you may optionally add the special form *args This binds args to a tuple containing the extra values passed in the function call >>> def spam(a, b, *args): ... print a, b, args >>> spam(1, 2) 1 2 () >>> spam(b=1, a=2) 2 1 () >>> spam(1, 2, 3, 4, 5) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 10 / 28
  62. 62. Python, the language Functions Extra Positional Arguments At the end of the arguments list you may optionally add the special form *args This binds args to a tuple containing the extra values passed in the function call >>> def spam(a, b, *args): ... print a, b, args >>> spam(1, 2) 1 2 () >>> spam(b=1, a=2) 2 1 () >>> spam(1, 2, 3, 4, 5) 1 2 (3, 4, 5) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 10 / 28
  63. 63. Python, the language Functions Extra Positional Arguments At the end of the arguments list you may optionally add the special form *args This binds args to a tuple containing the extra values passed in the function call >>> def spam(a, b, *args): >>> def eggs(a, *args): ... print a, b, args ... spam(a, args) >>> spam(1, 2) 1 2 () >>> spam(b=1, a=2) 2 1 () >>> spam(1, 2, 3, 4, 5) 1 2 (3, 4, 5) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 10 / 28
  64. 64. Python, the language Functions Extra Positional Arguments At the end of the arguments list you may optionally add the special form *args This binds args to a tuple containing the extra values passed in the function call >>> def spam(a, b, *args): >>> def eggs(a, *args): ... print a, b, args ... spam(a, args) >>> spam(1, 2) >>> eggs(1, 2, 3, 4, 5) 1 2 () >>> spam(b=1, a=2) 2 1 () >>> spam(1, 2, 3, 4, 5) 1 2 (3, 4, 5) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 10 / 28
  65. 65. Python, the language Functions Extra Positional Arguments At the end of the arguments list you may optionally add the special form *args This binds args to a tuple containing the extra values passed in the function call >>> def spam(a, b, *args): >>> def eggs(a, *args): ... print a, b, args ... spam(a, args) >>> spam(1, 2) >>> eggs(1, 2, 3, 4, 5) 1 2 () 1 (2, 3, 4, 5) () >>> spam(b=1, a=2) 2 1 () >>> spam(1, 2, 3, 4, 5) 1 2 (3, 4, 5) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 10 / 28
  66. 66. Python, the language Functions Extra Positional Arguments At the end of the arguments list you may optionally add the special form *args This binds args to a tuple containing the extra values passed in the function call >>> def spam(a, b, *args): >>> def eggs(a, *args): ... print a, b, args ... spam(a, args) >>> spam(1, 2) >>> eggs(1, 2, 3, 4, 5) 1 2 () 1 (2, 3, 4, 5) () >>> spam(b=1, a=2) >>> def ham(a, *args): 2 1 () ... spam(a, *args) >>> spam(1, 2, 3, 4, 5) 1 2 (3, 4, 5) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 10 / 28
  67. 67. Python, the language Functions Extra Positional Arguments At the end of the arguments list you may optionally add the special form *args This binds args to a tuple containing the extra values passed in the function call >>> def spam(a, b, *args): >>> def eggs(a, *args): ... print a, b, args ... spam(a, args) >>> spam(1, 2) >>> eggs(1, 2, 3, 4, 5) 1 2 () 1 (2, 3, 4, 5) () >>> spam(b=1, a=2) >>> def ham(a, *args): 2 1 () ... spam(a, *args) >>> spam(1, 2, 3, 4, 5) >>> ham(1, 2, 3, 4, 5) 1 2 (3, 4, 5) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 10 / 28
  68. 68. Python, the language Functions Extra Positional Arguments At the end of the arguments list you may optionally add the special form *args This binds args to a tuple containing the extra values passed in the function call >>> def spam(a, b, *args): >>> def eggs(a, *args): ... print a, b, args ... spam(a, args) >>> spam(1, 2) >>> eggs(1, 2, 3, 4, 5) 1 2 () 1 (2, 3, 4, 5) () >>> spam(b=1, a=2) >>> def ham(a, *args): 2 1 () ... spam(a, *args) >>> spam(1, 2, 3, 4, 5) >>> ham(1, 2, 3, 4, 5) 1 2 (3, 4, 5) 1 2 (3, 4, 5) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 10 / 28
  69. 69. Python, the language Functions Extra Named Arguments At the end of the arguments list you may optionally add the special from **kwargs This binds kwargs to a dictionary containing the extra values passed in the function call and their names J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 11 / 28
  70. 70. Python, the language Functions Extra Named Arguments At the end of the arguments list you may optionally add the special from **kwargs This binds kwargs to a dictionary containing the extra values passed in the function call and their names J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 11 / 28
  71. 71. Python, the language Functions Extra Named Arguments At the end of the arguments list you may optionally add the special from **kwargs This binds kwargs to a dictionary containing the extra values passed in the function call and their names >>> def spam(a, b, **kw): ... print a, b, kw J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 11 / 28
  72. 72. Python, the language Functions Extra Named Arguments At the end of the arguments list you may optionally add the special from **kwargs This binds kwargs to a dictionary containing the extra values passed in the function call and their names >>> def spam(a, b, **kw): ... print a, b, kw >>> spam(1, 2) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 11 / 28
  73. 73. Python, the language Functions Extra Named Arguments At the end of the arguments list you may optionally add the special from **kwargs This binds kwargs to a dictionary containing the extra values passed in the function call and their names >>> def spam(a, b, **kw): ... print a, b, kw >>> spam(1, 2) 1 2 {} J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 11 / 28
  74. 74. Python, the language Functions Extra Named Arguments At the end of the arguments list you may optionally add the special from **kwargs This binds kwargs to a dictionary containing the extra values passed in the function call and their names >>> def spam(a, b, **kw): ... print a, b, kw >>> spam(1, 2) 1 2 {} >>> spam(b=1, a=2, c=3, d=4) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 11 / 28
  75. 75. Python, the language Functions Extra Named Arguments At the end of the arguments list you may optionally add the special from **kwargs This binds kwargs to a dictionary containing the extra values passed in the function call and their names >>> def spam(a, b, **kw): ... print a, b, kw >>> spam(1, 2) 1 2 {} >>> spam(b=1, a=2, c=3, d=4) 2 1 {’c’: 3, ’d’: 4} J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 11 / 28
  76. 76. Python, the language Functions Extra Named Arguments At the end of the arguments list you may optionally add the special from **kwargs This binds kwargs to a dictionary containing the extra values passed in the function call and their names >>> def spam(a, b, **kw): ... print a, b, kw >>> spam(1, 2) 1 2 {} >>> spam(b=1, a=2, c=3, d=4) 2 1 {’c’: 3, ’d’: 4} >>> def eggs(a, *args, **kw): ... print a, args, kw J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 11 / 28
  77. 77. Python, the language Functions Extra Named Arguments At the end of the arguments list you may optionally add the special from **kwargs This binds kwargs to a dictionary containing the extra values passed in the function call and their names >>> def spam(a, b, **kw): ... print a, b, kw >>> spam(1, 2) 1 2 {} >>> spam(b=1, a=2, c=3, d=4) 2 1 {’c’: 3, ’d’: 4} >>> def eggs(a, *args, **kw): ... print a, args, kw >>> eggs(1,2,3,4) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 11 / 28
  78. 78. Python, the language Functions Extra Named Arguments At the end of the arguments list you may optionally add the special from **kwargs This binds kwargs to a dictionary containing the extra values passed in the function call and their names >>> def spam(a, b, **kw): ... print a, b, kw >>> spam(1, 2) 1 2 {} >>> spam(b=1, a=2, c=3, d=4) 2 1 {’c’: 3, ’d’: 4} >>> def eggs(a, *args, **kw): ... print a, args, kw >>> eggs(1,2,3,4) 1 (2, 3, 4) {} J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 11 / 28
  79. 79. Python, the language Functions Extra Named Arguments At the end of the arguments list you may optionally add the special from **kwargs This binds kwargs to a dictionary containing the extra values passed in the function call and their names >>> def spam(a, b, **kw): >>> def ham(a,**kw): ... print a, b, kw ... spam(a, kw) >>> spam(1, 2) 1 2 {} >>> spam(b=1, a=2, c=3, d=4) 2 1 {’c’: 3, ’d’: 4} >>> def eggs(a, *args, **kw): ... print a, args, kw >>> eggs(1,2,3,4) 1 (2, 3, 4) {} J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 11 / 28
  80. 80. Python, the language Functions Extra Named Arguments At the end of the arguments list you may optionally add the special from **kwargs This binds kwargs to a dictionary containing the extra values passed in the function call and their names >>> def spam(a, b, **kw): >>> def ham(a,**kw): ... print a, b, kw ... spam(a, kw) >>> spam(1, 2) >>> ham(1, b=2, c=3) 1 2 {} >>> spam(b=1, a=2, c=3, d=4) 2 1 {’c’: 3, ’d’: 4} >>> def eggs(a, *args, **kw): ... print a, args, kw >>> eggs(1,2,3,4) 1 (2, 3, 4) {} J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 11 / 28
  81. 81. Python, the language Functions Extra Named Arguments At the end of the arguments list you may optionally add the special from **kwargs This binds kwargs to a dictionary containing the extra values passed in the function call and their names >>> def spam(a, b, **kw): >>> def ham(a,**kw): ... print a, b, kw ... spam(a, kw) >>> spam(1, 2) >>> ham(1, b=2, c=3) 1 2 {} 1 {’c’: 3, ’b’: 2} {} >>> spam(b=1, a=2, c=3, d=4) 2 1 {’c’: 3, ’d’: 4} >>> def eggs(a, *args, **kw): ... print a, args, kw >>> eggs(1,2,3,4) 1 (2, 3, 4) {} J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 11 / 28
  82. 82. Python, the language Functions Extra Named Arguments At the end of the arguments list you may optionally add the special from **kwargs This binds kwargs to a dictionary containing the extra values passed in the function call and their names >>> def spam(a, b, **kw): >>> def ham(a,**kw): ... print a, b, kw ... spam(a, kw) >>> spam(1, 2) >>> ham(1, b=2, c=3) 1 2 {} 1 {’c’: 3, ’b’: 2} {} >>> spam(b=1, a=2, c=3, d=4) >>> def pram(a,**kw): 2 1 {’c’: 3, ’d’: 4} ... spam(a, **kw) >>> def eggs(a, *args, **kw): ... print a, args, kw >>> eggs(1,2,3,4) 1 (2, 3, 4) {} J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 11 / 28
  83. 83. Python, the language Functions Extra Named Arguments At the end of the arguments list you may optionally add the special from **kwargs This binds kwargs to a dictionary containing the extra values passed in the function call and their names >>> def spam(a, b, **kw): >>> def ham(a,**kw): ... print a, b, kw ... spam(a, kw) >>> spam(1, 2) >>> ham(1, b=2, c=3) 1 2 {} 1 {’c’: 3, ’b’: 2} {} >>> spam(b=1, a=2, c=3, d=4) >>> def pram(a,**kw): 2 1 {’c’: 3, ’d’: 4} ... spam(a, **kw) >>> def eggs(a, *args, **kw): >>> pram(1, b=2, c=3) ... print a, args, kw >>> eggs(1,2,3,4) 1 (2, 3, 4) {} J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 11 / 28
  84. 84. Python, the language Functions Extra Named Arguments At the end of the arguments list you may optionally add the special from **kwargs This binds kwargs to a dictionary containing the extra values passed in the function call and their names >>> def spam(a, b, **kw): >>> def ham(a,**kw): ... print a, b, kw ... spam(a, kw) >>> spam(1, 2) >>> ham(1, b=2, c=3) 1 2 {} 1 {’c’: 3, ’b’: 2} {} >>> spam(b=1, a=2, c=3, d=4) >>> def pram(a,**kw): 2 1 {’c’: 3, ’d’: 4} ... spam(a, **kw) >>> def eggs(a, *args, **kw): >>> pram(1, b=2, c=3) ... print a, args, kw 1 2 {’c’: 3} >>> eggs(1,2,3,4) 1 (2, 3, 4) {} J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 11 / 28
  85. 85. Python, the language Modules and Packages Modules A typical Python program is made up of several source files Each source file corresponds to a module that groups variables, functions, classes, etc. for reuse A module explicitly establishes its dependencies using the import and from statements In some languages global variables provide a hidden mechanism for coupling between modules In Python global variables are not global to all modules: they are attributes of a module object (module.variable) Extensions, components coded in other languages such as C, C++, Java, C#, are treated as modules by the python code In Python everything is defined in a module: main program or interactive sessions in module main built-ins in preloaded module builtin accessible via import builtin at loading, modules get an extra attribute named builtins which refers to either to module builtin or to its dictionary J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 12 / 28
  86. 86. Python, the language Modules and Packages Modules A typical Python program is made up of several source files Each source file corresponds to a module that groups variables, functions, classes, etc. for reuse A module explicitly establishes its dependencies using the import and from statements In some languages global variables provide a hidden mechanism for coupling between modules In Python global variables are not global to all modules: they are attributes of a module object (module.variable) Extensions, components coded in other languages such as C, C++, Java, C#, are treated as modules by the python code In Python everything is defined in a module: main program or interactive sessions in module main built-ins in preloaded module builtin accessible via import builtin at loading, modules get an extra attribute named builtins which refers to either to module builtin or to its dictionary J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 12 / 28
  87. 87. Python, the language Modules and Packages Modules A typical Python program is made up of several source files Each source file corresponds to a module that groups variables, functions, classes, etc. for reuse A module explicitly establishes its dependencies using the import and from statements In some languages global variables provide a hidden mechanism for coupling between modules In Python global variables are not global to all modules: they are attributes of a module object (module.variable) Extensions, components coded in other languages such as C, C++, Java, C#, are treated as modules by the python code In Python everything is defined in a module: main program or interactive sessions in module main built-ins in preloaded module builtin accessible via import builtin at loading, modules get an extra attribute named builtins which refers to either to module builtin or to its dictionary J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 12 / 28
  88. 88. Python, the language Modules and Packages Modules A typical Python program is made up of several source files Each source file corresponds to a module that groups variables, functions, classes, etc. for reuse A module explicitly establishes its dependencies using the import and from statements In some languages global variables provide a hidden mechanism for coupling between modules In Python global variables are not global to all modules: they are attributes of a module object (module.variable) Extensions, components coded in other languages such as C, C++, Java, C#, are treated as modules by the python code In Python everything is defined in a module: main program or interactive sessions in module main built-ins in preloaded module builtin accessible via import builtin at loading, modules get an extra attribute named builtins which refers to either to module builtin or to its dictionary J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 12 / 28
  89. 89. Python, the language Modules and Packages Modules A typical Python program is made up of several source files Each source file corresponds to a module that groups variables, functions, classes, etc. for reuse A module explicitly establishes its dependencies using the import and from statements In some languages global variables provide a hidden mechanism for coupling between modules In Python global variables are not global to all modules: they are attributes of a module object (module.variable) Extensions, components coded in other languages such as C, C++, Java, C#, are treated as modules by the python code In Python everything is defined in a module: main program or interactive sessions in module main built-ins in preloaded module builtin accessible via import builtin at loading, modules get an extra attribute named builtins which refers to either to module builtin or to its dictionary J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 12 / 28
  90. 90. Python, the language Modules and Packages Modules A typical Python program is made up of several source files Each source file corresponds to a module that groups variables, functions, classes, etc. for reuse A module explicitly establishes its dependencies using the import and from statements In some languages global variables provide a hidden mechanism for coupling between modules In Python global variables are not global to all modules: they are attributes of a module object (module.variable) Extensions, components coded in other languages such as C, C++, Java, C#, are treated as modules by the python code In Python everything is defined in a module: main program or interactive sessions in module main built-ins in preloaded module builtin accessible via import builtin at loading, modules get an extra attribute named builtins which refers to either to module builtin or to its dictionary J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 12 / 28
  91. 91. Python, the language Modules and Packages Modules A typical Python program is made up of several source files Each source file corresponds to a module that groups variables, functions, classes, etc. for reuse A module explicitly establishes its dependencies using the import and from statements In some languages global variables provide a hidden mechanism for coupling between modules In Python global variables are not global to all modules: they are attributes of a module object (module.variable) Extensions, components coded in other languages such as C, C++, Java, C#, are treated as modules by the python code In Python everything is defined in a module: main program or interactive sessions in module main built-ins in preloaded module builtin accessible via import builtin at loading, modules get an extra attribute named builtins which refers to either to module builtin or to its dictionary J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 12 / 28
  92. 92. Python, the language Modules and Packages Modules A typical Python program is made up of several source files Each source file corresponds to a module that groups variables, functions, classes, etc. for reuse A module explicitly establishes its dependencies using the import and from statements In some languages global variables provide a hidden mechanism for coupling between modules In Python global variables are not global to all modules: they are attributes of a module object (module.variable) Extensions, components coded in other languages such as C, C++, Java, C#, are treated as modules by the python code In Python everything is defined in a module: main program or interactive sessions in module main built-ins in preloaded module builtin accessible via import builtin at loading, modules get an extra attribute named builtins which refers to either to module builtin or to its dictionary J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 12 / 28
  93. 93. Python, the language Modules and Packages Modules A typical Python program is made up of several source files Each source file corresponds to a module that groups variables, functions, classes, etc. for reuse A module explicitly establishes its dependencies using the import and from statements In some languages global variables provide a hidden mechanism for coupling between modules In Python global variables are not global to all modules: they are attributes of a module object (module.variable) Extensions, components coded in other languages such as C, C++, Java, C#, are treated as modules by the python code In Python everything is defined in a module: main program or interactive sessions in module main built-ins in preloaded module builtin accessible via import builtin at loading, modules get an extra attribute named builtins which refers to either to module builtin or to its dictionary J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 12 / 28
  94. 94. Python, the language Modules and Packages Modules A typical Python program is made up of several source files Each source file corresponds to a module that groups variables, functions, classes, etc. for reuse A module explicitly establishes its dependencies using the import and from statements In some languages global variables provide a hidden mechanism for coupling between modules In Python global variables are not global to all modules: they are attributes of a module object (module.variable) Extensions, components coded in other languages such as C, C++, Java, C#, are treated as modules by the python code In Python everything is defined in a module: main program or interactive sessions in module main built-ins in preloaded module builtin accessible via import builtin at loading, modules get an extra attribute named builtins which refers to either to module builtin or to its dictionary J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 12 / 28
  95. 95. Python, the language Modules and Packages import modulename spam.py #!/usr/bin/env python # -*- coding: latin-1 -*- quot;quot;quot;Documentation of the spam module.quot;quot;quot; def eggs(): quot;quot;quot;eggs documentationquot;quot;quot; print quot;eggs !!!quot; def spam(s): quot;quot;quot;spam documentationquot;quot;quot; print quot;spam !!!quot; if __name__ == quot;__main__quot;: eggs() J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 13 / 28
  96. 96. Python, the language Modules and Packages import modulename >>> import spam spam.py #!/usr/bin/env python # -*- coding: latin-1 -*- quot;quot;quot;Documentation of the spam module.quot;quot;quot; def eggs(): quot;quot;quot;eggs documentationquot;quot;quot; print quot;eggs !!!quot; def spam(s): quot;quot;quot;spam documentationquot;quot;quot; print quot;spam !!!quot; if __name__ == quot;__main__quot;: eggs() J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 13 / 28
  97. 97. Python, the language Modules and Packages import modulename >>> import spam spam.py >>> spam #!/usr/bin/env python # -*- coding: latin-1 -*- quot;quot;quot;Documentation of the spam module.quot;quot;quot; def eggs(): quot;quot;quot;eggs documentationquot;quot;quot; print quot;eggs !!!quot; def spam(s): quot;quot;quot;spam documentationquot;quot;quot; print quot;spam !!!quot; if __name__ == quot;__main__quot;: eggs() J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 13 / 28
  98. 98. Python, the language Modules and Packages import modulename >>> import spam spam.py >>> spam #!/usr/bin/env python <module ’spam’ from ’spam.pyc’> # -*- coding: latin-1 -*- quot;quot;quot;Documentation of the spam module.quot;quot;quot; def eggs(): quot;quot;quot;eggs documentationquot;quot;quot; print quot;eggs !!!quot; def spam(s): quot;quot;quot;spam documentationquot;quot;quot; print quot;spam !!!quot; if __name__ == quot;__main__quot;: eggs() J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 13 / 28
  99. 99. Python, the language Modules and Packages import modulename >>> import spam spam.py >>> spam #!/usr/bin/env python <module ’spam’ from ’spam.pyc’> # -*- coding: latin-1 -*- >>> eggs() quot;quot;quot;Documentation of the spam module.quot;quot;quot; def eggs(): quot;quot;quot;eggs documentationquot;quot;quot; print quot;eggs !!!quot; def spam(s): quot;quot;quot;spam documentationquot;quot;quot; print quot;spam !!!quot; if __name__ == quot;__main__quot;: eggs() J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 13 / 28
  100. 100. Python, the language Modules and Packages import modulename >>> import spam spam.py >>> spam #!/usr/bin/env python <module ’spam’ from ’spam.pyc’> # -*- coding: latin-1 -*- >>> eggs() quot;quot;quot;Documentation of the Traceback (most recent call last): spam module.quot;quot;quot; File ’<stdin>’, line 1, in ? NameError: name ’eggs’ is not defined def eggs(): quot;quot;quot;eggs documentationquot;quot;quot; print quot;eggs !!!quot; def spam(s): quot;quot;quot;spam documentationquot;quot;quot; print quot;spam !!!quot; if __name__ == quot;__main__quot;: eggs() J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 13 / 28
  101. 101. Python, the language Modules and Packages import modulename >>> import spam spam.py >>> spam #!/usr/bin/env python <module ’spam’ from ’spam.pyc’> # -*- coding: latin-1 -*- >>> eggs() quot;quot;quot;Documentation of the Traceback (most recent call last): spam module.quot;quot;quot; File ’<stdin>’, line 1, in ? NameError: name ’eggs’ is not defined def eggs(): >>> spam.eggs() quot;quot;quot;eggs documentationquot;quot;quot; print quot;eggs !!!quot; def spam(s): quot;quot;quot;spam documentationquot;quot;quot; print quot;spam !!!quot; if __name__ == quot;__main__quot;: eggs() J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 13 / 28
  102. 102. Python, the language Modules and Packages import modulename >>> import spam spam.py >>> spam #!/usr/bin/env python <module ’spam’ from ’spam.pyc’> # -*- coding: latin-1 -*- >>> eggs() quot;quot;quot;Documentation of the Traceback (most recent call last): spam module.quot;quot;quot; File ’<stdin>’, line 1, in ? NameError: name ’eggs’ is not defined def eggs(): >>> spam.eggs() quot;quot;quot;eggs documentationquot;quot;quot; eggs !!! print quot;eggs !!!quot; def spam(s): quot;quot;quot;spam documentationquot;quot;quot; print quot;spam !!!quot; if __name__ == quot;__main__quot;: eggs() J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 13 / 28
  103. 103. Python, the language Modules and Packages import modulename >>> import spam spam.py >>> spam #!/usr/bin/env python <module ’spam’ from ’spam.pyc’> # -*- coding: latin-1 -*- >>> eggs() quot;quot;quot;Documentation of the Traceback (most recent call last): spam module.quot;quot;quot; File ’<stdin>’, line 1, in ? NameError: name ’eggs’ is not defined def eggs(): >>> spam.eggs() quot;quot;quot;eggs documentationquot;quot;quot; eggs !!! print quot;eggs !!!quot; >>> ham=spam def spam(s): quot;quot;quot;spam documentationquot;quot;quot; print quot;spam !!!quot; if __name__ == quot;__main__quot;: eggs() J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 13 / 28
  104. 104. Python, the language Modules and Packages import modulename >>> import spam spam.py >>> spam #!/usr/bin/env python <module ’spam’ from ’spam.pyc’> # -*- coding: latin-1 -*- >>> eggs() quot;quot;quot;Documentation of the Traceback (most recent call last): spam module.quot;quot;quot; File ’<stdin>’, line 1, in ? NameError: name ’eggs’ is not defined def eggs(): >>> spam.eggs() quot;quot;quot;eggs documentationquot;quot;quot; eggs !!! print quot;eggs !!!quot; >>> ham=spam >>> ham.spam() def spam(s): quot;quot;quot;spam documentationquot;quot;quot; print quot;spam !!!quot; if __name__ == quot;__main__quot;: eggs() J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 13 / 28
  105. 105. Python, the language Modules and Packages import modulename >>> import spam spam.py >>> spam #!/usr/bin/env python <module ’spam’ from ’spam.pyc’> # -*- coding: latin-1 -*- >>> eggs() quot;quot;quot;Documentation of the Traceback (most recent call last): spam module.quot;quot;quot; File ’<stdin>’, line 1, in ? NameError: name ’eggs’ is not defined def eggs(): >>> spam.eggs() quot;quot;quot;eggs documentationquot;quot;quot; eggs !!! print quot;eggs !!!quot; >>> ham=spam >>> ham.spam() def spam(s): spam !!! quot;quot;quot;spam documentationquot;quot;quot; print quot;spam !!!quot; if __name__ == quot;__main__quot;: eggs() J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 13 / 28
  106. 106. Python, the language Modules and Packages import modulename >>> import spam spam.py >>> spam #!/usr/bin/env python <module ’spam’ from ’spam.pyc’> # -*- coding: latin-1 -*- >>> eggs() quot;quot;quot;Documentation of the Traceback (most recent call last): spam module.quot;quot;quot; File ’<stdin>’, line 1, in ? NameError: name ’eggs’ is not defined def eggs(): >>> spam.eggs() quot;quot;quot;eggs documentationquot;quot;quot; eggs !!! print quot;eggs !!!quot; >>> ham=spam >>> ham.spam() def spam(s): spam !!! quot;quot;quot;spam documentationquot;quot;quot; >>> dir() print quot;spam !!!quot; if __name__ == quot;__main__quot;: eggs() J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 13 / 28
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×