SlideShare a Scribd company logo
1 of 10
Download to read offline
CLTL Python Course 
Object Oriented Programming in Python 
2nd session 
May 1st 2013
Reminder session 1 
● What is Object Oriented Programming 
● Classes, objects, methods, properties... 
● How to define classes, with methods and attributes 
● How to create objects 
● The __init__ method 
● Basic inheritance
Session 2 
● How organize and reuse our code 
– Scripts 
– Classes 
– Modules 
– Packages 
● How to use eclipse with python 
– Creating projects, modules 
– Example
Python modules 
● A module is a file containing python definition and 
statements 
● The name of the module is the name of the file without .py 
– File: fibo.py Name module: fibo 
● The module name is important --> to reuse the module 
– Import statement 
● Inside the module the name is stored in the variable 
__name__ 
● A script is a module which defines a MAIN function: 
– When you run a module (python fibo.py) --> the mod. 
Name is set to __main__ 
if __name__ == '__main__':
Importing modules 
● Module “ruben” (file ruben.py) 
– 3 functions: say_hello(), add(a,b), say_bye() 
● We want to reuse this module in other modules 
– import ruben 
● Imports everything in the module 
● Access: ruben.say_hello() ruben.add(2,3) 
– from ruben import * 
● Imports everything in the module 
● Access: say_hello() say_bye() 
– from ruben import add 
● Imports only what you specify (add) 
● Access: add(4,5)
More on modules 
● Function dir(module) --> gives you all the content of the mod 
– Import ruben 
– dir(ruben) --> [...,'say_hello', 'add', 'say_bye'] 
● Module search path: (where python looks when “import”) 
1. Current directory 
2. PYTHONPATH environment variable 
3. Default location in your installation 
● You can modify inside your script the variable sys.path (list) 
to modify the PYTHONPATH 
● Import sys 
● Sys.path.append('C:/ruben/example/my_code)
Python Packages 
● A way of structure and reuse modules 
● Access through “dotted module names” 
– modA.modB.modC --> submodule modC inside 
submodule modB inside module modA 
● At low level a python package is a folder with some 
python modules and one file called __init__.py 
– This __init__ is called when we import the 
package to initialization
Example Python Package 
● Package to handle different sound files and data
Example Python Package 
● Package to handle different sound files and data 
DIFFERENT WAYS OF IMPORTING / USING 
Import sounds.effects.echo 
--> sunfs.effects.echo.echofilter(....) 
From sound.effects import echo 
--> echo.echofilter(....) 
From sound.effects.echo import echofilter 
--> echofilter(...) 
From sound.effects import * 
--> depends on the __all__ defined in 
sound.effects.__init__ 
__all__ = ['echo','surround']
Eclipse + PyDev

More Related Content

What's hot

Core Java Programming Language (JSE) : Chapter II - Object Oriented Programming.
Core Java Programming Language (JSE) : Chapter II - Object Oriented Programming.Core Java Programming Language (JSE) : Chapter II - Object Oriented Programming.
Core Java Programming Language (JSE) : Chapter II - Object Oriented Programming.WebStackAcademy
 
oop lecture 3
oop lecture 3oop lecture 3
oop lecture 3Atif Khan
 
09 Object Oriented Programming in PHP #burningkeyboards
09 Object Oriented Programming in PHP #burningkeyboards09 Object Oriented Programming in PHP #burningkeyboards
09 Object Oriented Programming in PHP #burningkeyboardsDenis Ristic
 
Object and class presentation
Object and class presentationObject and class presentation
Object and class presentationnafisa rahman
 

What's hot (8)

Core Java Programming Language (JSE) : Chapter II - Object Oriented Programming.
Core Java Programming Language (JSE) : Chapter II - Object Oriented Programming.Core Java Programming Language (JSE) : Chapter II - Object Oriented Programming.
Core Java Programming Language (JSE) : Chapter II - Object Oriented Programming.
 
Php oop (1)
Php oop (1)Php oop (1)
Php oop (1)
 
oop lecture 3
oop lecture 3oop lecture 3
oop lecture 3
 
Beginning OOP in PHP
Beginning OOP in PHPBeginning OOP in PHP
Beginning OOP in PHP
 
Class and objects
Class and objectsClass and objects
Class and objects
 
09 Object Oriented Programming in PHP #burningkeyboards
09 Object Oriented Programming in PHP #burningkeyboards09 Object Oriented Programming in PHP #burningkeyboards
09 Object Oriented Programming in PHP #burningkeyboards
 
Chapter 05 classes and objects
Chapter 05 classes and objectsChapter 05 classes and objects
Chapter 05 classes and objects
 
Object and class presentation
Object and class presentationObject and class presentation
Object and class presentation
 

Viewers also liked

Building an open source python application the right way
Building an open source python application the right wayBuilding an open source python application the right way
Building an open source python application the right wayKiran Gangadharan
 
RANLP2013: DutchSemCor, in Quest of the Ideal Sense Tagged Corpus
RANLP2013: DutchSemCor, in Quest of the Ideal Sense Tagged CorpusRANLP2013: DutchSemCor, in Quest of the Ideal Sense Tagged Corpus
RANLP2013: DutchSemCor, in Quest of the Ideal Sense Tagged CorpusRubén Izquierdo Beviá
 
MVC and Other Design Patterns
MVC and Other Design PatternsMVC and Other Design Patterns
MVC and Other Design PatternsJonathan Simon
 
Factory and Abstract Factory
Factory and Abstract FactoryFactory and Abstract Factory
Factory and Abstract FactoryJonathan Simon
 
Desing pattern prototype-Factory Method, Prototype and Builder
Desing pattern prototype-Factory Method, Prototype and Builder Desing pattern prototype-Factory Method, Prototype and Builder
Desing pattern prototype-Factory Method, Prototype and Builder paramisoft
 
Design Patterns For 70% Of Programmers In The World
Design Patterns For 70% Of Programmers In The WorldDesign Patterns For 70% Of Programmers In The World
Design Patterns For 70% Of Programmers In The WorldSaurabh Moody
 
Python Advanced – Building on the foundation
Python Advanced – Building on the foundationPython Advanced – Building on the foundation
Python Advanced – Building on the foundationKevlin Henney
 
Software Design Patterns in Laravel by Phill Sparks
Software Design Patterns in Laravel by Phill SparksSoftware Design Patterns in Laravel by Phill Sparks
Software Design Patterns in Laravel by Phill SparksPhill Sparks
 
Automating with NX-OS: Let's Get Started!
Automating with NX-OS: Let's Get Started!Automating with NX-OS: Let's Get Started!
Automating with NX-OS: Let's Get Started!Cisco DevNet
 
Operating system.ppt (1)
Operating system.ppt (1)Operating system.ppt (1)
Operating system.ppt (1)Vaibhav Bajaj
 
Operating system overview concepts ppt
Operating system overview concepts pptOperating system overview concepts ppt
Operating system overview concepts pptRajendraPrasad Alladi
 
Mac OS(Operating System)
Mac OS(Operating System)Mac OS(Operating System)
Mac OS(Operating System)Faizan Shaikh
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesMatt Harrison
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to PythonNowell Strite
 

Viewers also liked (15)

Building an open source python application the right way
Building an open source python application the right wayBuilding an open source python application the right way
Building an open source python application the right way
 
RANLP2013: DutchSemCor, in Quest of the Ideal Sense Tagged Corpus
RANLP2013: DutchSemCor, in Quest of the Ideal Sense Tagged CorpusRANLP2013: DutchSemCor, in Quest of the Ideal Sense Tagged Corpus
RANLP2013: DutchSemCor, in Quest of the Ideal Sense Tagged Corpus
 
MVC and Other Design Patterns
MVC and Other Design PatternsMVC and Other Design Patterns
MVC and Other Design Patterns
 
Factory and Abstract Factory
Factory and Abstract FactoryFactory and Abstract Factory
Factory and Abstract Factory
 
Desing pattern prototype-Factory Method, Prototype and Builder
Desing pattern prototype-Factory Method, Prototype and Builder Desing pattern prototype-Factory Method, Prototype and Builder
Desing pattern prototype-Factory Method, Prototype and Builder
 
Design Patterns For 70% Of Programmers In The World
Design Patterns For 70% Of Programmers In The WorldDesign Patterns For 70% Of Programmers In The World
Design Patterns For 70% Of Programmers In The World
 
Python Advanced – Building on the foundation
Python Advanced – Building on the foundationPython Advanced – Building on the foundation
Python Advanced – Building on the foundation
 
Software Design Patterns in Laravel by Phill Sparks
Software Design Patterns in Laravel by Phill SparksSoftware Design Patterns in Laravel by Phill Sparks
Software Design Patterns in Laravel by Phill Sparks
 
Automating with NX-OS: Let's Get Started!
Automating with NX-OS: Let's Get Started!Automating with NX-OS: Let's Get Started!
Automating with NX-OS: Let's Get Started!
 
Operating system.ppt (1)
Operating system.ppt (1)Operating system.ppt (1)
Operating system.ppt (1)
 
Design Patterns (Examples in .NET)
Design Patterns (Examples in .NET)Design Patterns (Examples in .NET)
Design Patterns (Examples in .NET)
 
Operating system overview concepts ppt
Operating system overview concepts pptOperating system overview concepts ppt
Operating system overview concepts ppt
 
Mac OS(Operating System)
Mac OS(Operating System)Mac OS(Operating System)
Mac OS(Operating System)
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 Minutes
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
 

Similar to CLTL python course: Object Oriented Programming (2/3)

Similar to CLTL python course: Object Oriented Programming (2/3) (20)

Python import mechanism
Python import mechanismPython import mechanism
Python import mechanism
 
Python Modules
Python ModulesPython Modules
Python Modules
 
Modules 101
Modules 101Modules 101
Modules 101
 
Python libraries
Python librariesPython libraries
Python libraries
 
Using Python Libraries.pdf
Using Python Libraries.pdfUsing Python Libraries.pdf
Using Python Libraries.pdf
 
Python: Modules and Packages
Python: Modules and PackagesPython: Modules and Packages
Python: Modules and Packages
 
Chapter 03 python libraries
Chapter 03 python librariesChapter 03 python libraries
Chapter 03 python libraries
 
Python Modules, executing modules as script.pptx
Python Modules, executing modules as script.pptxPython Modules, executing modules as script.pptx
Python Modules, executing modules as script.pptx
 
jb_Modules_in_Python.ppt
jb_Modules_in_Python.pptjb_Modules_in_Python.ppt
jb_Modules_in_Python.ppt
 
Structuring and packaging your python project
Structuring and packaging your python projectStructuring and packaging your python project
Structuring and packaging your python project
 
CBSE-Class 12-Ch4 -Using Python Libraries - SasikalaJayaprakash
CBSE-Class 12-Ch4 -Using Python Libraries - SasikalaJayaprakashCBSE-Class 12-Ch4 -Using Python Libraries - SasikalaJayaprakash
CBSE-Class 12-Ch4 -Using Python Libraries - SasikalaJayaprakash
 
Python modules
Python modulesPython modules
Python modules
 
Pythonpresent
PythonpresentPythonpresent
Pythonpresent
 
ITPROceed 2016 - The Art of PowerShell Toolmaking
ITPROceed 2016 - The Art of PowerShell ToolmakingITPROceed 2016 - The Art of PowerShell Toolmaking
ITPROceed 2016 - The Art of PowerShell Toolmaking
 
package module in the python environement.pptx
package module in the python environement.pptxpackage module in the python environement.pptx
package module in the python environement.pptx
 
D8 training
D8 trainingD8 training
D8 training
 
Functions_in_Python.pptx
Functions_in_Python.pptxFunctions_in_Python.pptx
Functions_in_Python.pptx
 
Python_Unit_2 OOPS.pptx
Python_Unit_2  OOPS.pptxPython_Unit_2  OOPS.pptx
Python_Unit_2 OOPS.pptx
 
packages.pptx
packages.pptxpackages.pptx
packages.pptx
 
Python modules
Python modulesPython modules
Python modules
 

More from Rubén Izquierdo Beviá

ULM-1 Understanding Languages by Machines: The borders of Ambiguity
ULM-1 Understanding Languages by Machines: The borders of AmbiguityULM-1 Understanding Languages by Machines: The borders of Ambiguity
ULM-1 Understanding Languages by Machines: The borders of AmbiguityRubén Izquierdo Beviá
 
DutchSemCor workshop: Domain classification and WSD systems
DutchSemCor workshop: Domain classification and WSD systemsDutchSemCor workshop: Domain classification and WSD systems
DutchSemCor workshop: Domain classification and WSD systemsRubén Izquierdo Beviá
 
Topic modeling and WSD on the Ancora corpus
Topic modeling and WSD on the Ancora corpusTopic modeling and WSD on the Ancora corpus
Topic modeling and WSD on the Ancora corpusRubén Izquierdo Beviá
 
Error analysis of Word Sense Disambiguation
Error analysis of Word Sense DisambiguationError analysis of Word Sense Disambiguation
Error analysis of Word Sense DisambiguationRubén Izquierdo Beviá
 
KafNafParserPy: a python library for parsing/creating KAF and NAF files
KafNafParserPy: a python library for parsing/creating KAF and NAF filesKafNafParserPy: a python library for parsing/creating KAF and NAF files
KafNafParserPy: a python library for parsing/creating KAF and NAF filesRubén Izquierdo Beviá
 
Thesis presentation (WSD and Semantic Classes)
Thesis presentation (WSD and Semantic Classes)Thesis presentation (WSD and Semantic Classes)
Thesis presentation (WSD and Semantic Classes)Rubén Izquierdo Beviá
 
CLTL: Description of web services and sofware. Nijmegen 2013
CLTL: Description of web services and sofware. Nijmegen 2013CLTL: Description of web services and sofware. Nijmegen 2013
CLTL: Description of web services and sofware. Nijmegen 2013Rubén Izquierdo Beviá
 
CLTL presentation: training an opinion mining system from KAF files using CRF
CLTL presentation: training an opinion mining system from KAF files using CRFCLTL presentation: training an opinion mining system from KAF files using CRF
CLTL presentation: training an opinion mining system from KAF files using CRFRubén Izquierdo Beviá
 
CLIN 2012: DutchSemCor Building a semantically annotated corpus for Dutch
CLIN 2012: DutchSemCor  Building a semantically annotated corpus for DutchCLIN 2012: DutchSemCor  Building a semantically annotated corpus for Dutch
CLIN 2012: DutchSemCor Building a semantically annotated corpus for DutchRubén Izquierdo Beviá
 
RANLP 2013: DutchSemcor in quest of the ideal corpus
RANLP 2013: DutchSemcor in quest of the ideal corpusRANLP 2013: DutchSemcor in quest of the ideal corpus
RANLP 2013: DutchSemcor in quest of the ideal corpusRubén Izquierdo Beviá
 

More from Rubén Izquierdo Beviá (14)

ULM-1 Understanding Languages by Machines: The borders of Ambiguity
ULM-1 Understanding Languages by Machines: The borders of AmbiguityULM-1 Understanding Languages by Machines: The borders of Ambiguity
ULM-1 Understanding Languages by Machines: The borders of Ambiguity
 
DutchSemCor workshop: Domain classification and WSD systems
DutchSemCor workshop: Domain classification and WSD systemsDutchSemCor workshop: Domain classification and WSD systems
DutchSemCor workshop: Domain classification and WSD systems
 
Topic modeling and WSD on the Ancora corpus
Topic modeling and WSD on the Ancora corpusTopic modeling and WSD on the Ancora corpus
Topic modeling and WSD on the Ancora corpus
 
Information Extraction
Information ExtractionInformation Extraction
Information Extraction
 
Error analysis of Word Sense Disambiguation
Error analysis of Word Sense DisambiguationError analysis of Word Sense Disambiguation
Error analysis of Word Sense Disambiguation
 
Juan Calvino y el Calvinismo
Juan Calvino y el CalvinismoJuan Calvino y el Calvinismo
Juan Calvino y el Calvinismo
 
KafNafParserPy: a python library for parsing/creating KAF and NAF files
KafNafParserPy: a python library for parsing/creating KAF and NAF filesKafNafParserPy: a python library for parsing/creating KAF and NAF files
KafNafParserPy: a python library for parsing/creating KAF and NAF files
 
CLTL Software and Web Services
CLTL Software and Web Services CLTL Software and Web Services
CLTL Software and Web Services
 
Thesis presentation (WSD and Semantic Classes)
Thesis presentation (WSD and Semantic Classes)Thesis presentation (WSD and Semantic Classes)
Thesis presentation (WSD and Semantic Classes)
 
ULM1 - The borders of Ambiguity
ULM1 - The borders of AmbiguityULM1 - The borders of Ambiguity
ULM1 - The borders of Ambiguity
 
CLTL: Description of web services and sofware. Nijmegen 2013
CLTL: Description of web services and sofware. Nijmegen 2013CLTL: Description of web services and sofware. Nijmegen 2013
CLTL: Description of web services and sofware. Nijmegen 2013
 
CLTL presentation: training an opinion mining system from KAF files using CRF
CLTL presentation: training an opinion mining system from KAF files using CRFCLTL presentation: training an opinion mining system from KAF files using CRF
CLTL presentation: training an opinion mining system from KAF files using CRF
 
CLIN 2012: DutchSemCor Building a semantically annotated corpus for Dutch
CLIN 2012: DutchSemCor  Building a semantically annotated corpus for DutchCLIN 2012: DutchSemCor  Building a semantically annotated corpus for Dutch
CLIN 2012: DutchSemCor Building a semantically annotated corpus for Dutch
 
RANLP 2013: DutchSemcor in quest of the ideal corpus
RANLP 2013: DutchSemcor in quest of the ideal corpusRANLP 2013: DutchSemcor in quest of the ideal corpus
RANLP 2013: DutchSemcor in quest of the ideal corpus
 

CLTL python course: Object Oriented Programming (2/3)

  • 1. CLTL Python Course Object Oriented Programming in Python 2nd session May 1st 2013
  • 2. Reminder session 1 ● What is Object Oriented Programming ● Classes, objects, methods, properties... ● How to define classes, with methods and attributes ● How to create objects ● The __init__ method ● Basic inheritance
  • 3. Session 2 ● How organize and reuse our code – Scripts – Classes – Modules – Packages ● How to use eclipse with python – Creating projects, modules – Example
  • 4. Python modules ● A module is a file containing python definition and statements ● The name of the module is the name of the file without .py – File: fibo.py Name module: fibo ● The module name is important --> to reuse the module – Import statement ● Inside the module the name is stored in the variable __name__ ● A script is a module which defines a MAIN function: – When you run a module (python fibo.py) --> the mod. Name is set to __main__ if __name__ == '__main__':
  • 5. Importing modules ● Module “ruben” (file ruben.py) – 3 functions: say_hello(), add(a,b), say_bye() ● We want to reuse this module in other modules – import ruben ● Imports everything in the module ● Access: ruben.say_hello() ruben.add(2,3) – from ruben import * ● Imports everything in the module ● Access: say_hello() say_bye() – from ruben import add ● Imports only what you specify (add) ● Access: add(4,5)
  • 6. More on modules ● Function dir(module) --> gives you all the content of the mod – Import ruben – dir(ruben) --> [...,'say_hello', 'add', 'say_bye'] ● Module search path: (where python looks when “import”) 1. Current directory 2. PYTHONPATH environment variable 3. Default location in your installation ● You can modify inside your script the variable sys.path (list) to modify the PYTHONPATH ● Import sys ● Sys.path.append('C:/ruben/example/my_code)
  • 7. Python Packages ● A way of structure and reuse modules ● Access through “dotted module names” – modA.modB.modC --> submodule modC inside submodule modB inside module modA ● At low level a python package is a folder with some python modules and one file called __init__.py – This __init__ is called when we import the package to initialization
  • 8. Example Python Package ● Package to handle different sound files and data
  • 9. Example Python Package ● Package to handle different sound files and data DIFFERENT WAYS OF IMPORTING / USING Import sounds.effects.echo --> sunfs.effects.echo.echofilter(....) From sound.effects import echo --> echo.echofilter(....) From sound.effects.echo import echofilter --> echofilter(...) From sound.effects import * --> depends on the __all__ defined in sound.effects.__init__ __all__ = ['echo','surround']