SlideShare a Scribd company logo
CLTL Python Course 
Object Oriented Programming in Python 
3rd session 
May 15th 2013
Reminders 
● Session I 
– What is Object Oriented Programming 
– Classes, objects, methods, properties... 
– How to define classes, with methods and attributes 
– How to create objects 
● Session II 
– Create modules 
– Create packages 
– Reuse and import
Session 3 
● Eclipse and PyDev 
– Use python within eclipse 
– Create projects 
– Create packages 
– Create modules 
– ...
Eclipse and PyDev 
1)Create a PyDev project 
Will contain all the structure, folders and information of the project 
2)Create a source folder in the project 
Required for creating modules and packages 
3)Create packages 
You already know python packages 
4)Create modules 
You also know python modules
Creating a PyDev project 
● File > new > project > PyDev > PyDev Project 
● Project name: the name of the project 
● Project contents: the folder to locate the project 
● Project type: usually Python 
● Grammar version: the python grammar version (not 
important) 
● Interpreter: which python you want use to run the project 
● Create default 'src' folder 
● Referenced projects: their source folders are added to the 
PYTHONPATH for the new project
Creating a source folder 
● Required in PyDev for creating packages and modules 
– For every new package/module, an existing source folder 
must be selected 
● Two ways of creating (if you didn't create it with the PyDev 
project) 
– File -> new -> source folder Browse and select the 
project (the name will be always 'src') 
– Right click on the project -> new -> Source folder (you 
can select the name of the folder)
Creating a Python package 
● Python package: 
– A special folder where group python modules 
– There is a special module __init__.py 
– It will be seen as a whole package 
● How to create packages: 
– File -> new -> python package. Select source folder and 
name 
– Right click on the project / source folder -> new python 
package 
● How to nest packages: 
– Drag/drop on the pydev package explorer 
– By the “dotted” name --> root.nested
Creating a Python module 
● Python module: a python file that can contain functions, classes... 
● In PyDev a python module can be associated to: 
– A source folder 
– A python package 
● How to create modules: 
– File -> new -> python module. Select source folder (leave 
package empty) or package, module name and template 
– Right click on source folder/package on explorer -> new python 
module 
● Pydev modules templates: 
– Empty: just an empty file 
– Class: contains the basic definition for a class 
– Main: contains the basic definition of a main python script (you 
can run it)
How to run a module in PyDev 
● Option 1 
– Select the module and make it active 
– Run --> Run As --> Python run 
● Option 2 
– Right click on the module on the explorer 
– Run --> Run as --> python run 
● Advanced: 
– Breakpoints, debugging...
Assignment 
We want to develop some python packages for different 
projects of the CLTL group, so we should create a nice 
structure of packages and modules. 
● We have only a main group (CLTL) 
● There are several projects going on: newsreader, opener, 
semantics_of_history, each one could be a package 
● In each project we will developed different tools... 
● Each tool will process different data, different files... 
● ....
Assignment 
● Define a project called my_cltl_project with a source folder 
● This package structure 
● Cltl (pkg) 
– Newsreader (pkg) 
– Opener (pkg) 
– semantics_of_history (pkg) 
● coreference_tool (pkg) 
– metrics: B3.py, MUC.py (mods) 
– data: coref_set.py (mods) 
– io: coref_set_reader.py, coref_set_writer.py, 
csv_reader.py (mods) 
– Common (pkg) 
● time_functions (mod)
Assignment 
● In time_functions.py implement a function called get_time() 
that returns a string with the current time (check python 
module time) 
● In csv_reader.py implement a function read_csv(path) that 
takes as input the path of a file, which is CSV comma 
separated, and prints each line reversed 
a,b,c,d,e --> e,d,c,b,a 
1,ruben,2,canito --> canito,2,ruben,1 
(check split and list slicing and indexing) 
● Created another project 
– with a main python module at least 
– Import the required stuff from the project cltl and call 
to the functions get_time() and read_csv(path)
Ad

More Related Content

What's hot (6)

Php oop (1)
Php oop (1)Php oop (1)
Php oop (1)
Sudip Simkhada
 
Beginning OOP in PHP
Beginning OOP in PHPBeginning OOP in PHP
Beginning OOP in PHP
David Stockton
 
oop lecture 3
oop lecture 3oop lecture 3
oop lecture 3
Atif Khan
 
Class and objects
Class and objectsClass and objects
Class and objects
nafisa rahman
 
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
Denis Ristic
 
Chapter 05 classes and objects
Chapter 05 classes and objectsChapter 05 classes and objects
Chapter 05 classes and objects
Praveen M Jigajinni
 
oop lecture 3
oop lecture 3oop lecture 3
oop lecture 3
Atif 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 #burningkeyboards
Denis Ristic
 

Viewers also liked (6)

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
Kiran 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 Corpus
Rubén Izquierdo Beviá
 
Python Advanced – Building on the foundation
Python Advanced – Building on the foundationPython Advanced – Building on the foundation
Python Advanced – Building on the foundation
Kevlin Henney
 
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
 
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
Matt Harrison
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
Nowell Strite
 
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
Kiran 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 Corpus
Rubén Izquierdo Beviá
 
Python Advanced – Building on the foundation
Python Advanced – Building on the foundationPython Advanced – Building on the foundation
Python Advanced – Building on the foundation
Kevlin Henney
 
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
 
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
Matt Harrison
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
Nowell Strite
 
Ad

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

Modules 101
Modules 101Modules 101
Modules 101
gjcross
 
Python import mechanism
Python import mechanismPython import mechanism
Python import mechanism
Yuki Nishiwaki
 
Structuring and packaging your python project
Structuring and packaging your python projectStructuring and packaging your python project
Structuring and packaging your python project
Eyal Trabelsi
 
Python Modules
Python ModulesPython Modules
Python Modules
Nitin Reddy Katkam
 
Python libraries
Python librariesPython libraries
Python libraries
Prof. Dr. K. Adisesha
 
Modules and Packages in Python_Basics.pdf
Modules and Packages in Python_Basics.pdfModules and Packages in Python_Basics.pdf
Modules and Packages in Python_Basics.pdf
RavindraTambe3
 
ExtBase workshop
ExtBase workshop ExtBase workshop
ExtBase workshop
schmutt
 
Python: Modules and Packages
Python: Modules and PackagesPython: Modules and Packages
Python: Modules and Packages
Damian T. Gordon
 
Chapter 03 python libraries
Chapter 03 python librariesChapter 03 python libraries
Chapter 03 python libraries
Praveen M Jigajinni
 
Using Python Libraries.pdf
Using Python Libraries.pdfUsing Python Libraries.pdf
Using Python Libraries.pdf
SoumyadityaDey
 
PyCourse - Self driving python course
PyCourse - Self driving python coursePyCourse - Self driving python course
PyCourse - Self driving python course
Eran Shlomo
 
Open source projects with python
Open source projects with pythonOpen source projects with python
Open source projects with python
roskakori
 
Interesting Presentation on Python Modules and packages
Interesting Presentation on Python Modules and packagesInteresting Presentation on Python Modules and packages
Interesting Presentation on Python Modules and packages
arunavamukherjee9999
 
Modules and Packages in Python Programming Language.pptx
Modules and Packages in Python Programming Language.pptxModules and Packages in Python Programming Language.pptx
Modules and Packages in Python Programming Language.pptx
arunavamukherjee9999
 
PyCon Taiwan 2013 Tutorial
PyCon Taiwan 2013 TutorialPyCon Taiwan 2013 Tutorial
PyCon Taiwan 2013 Tutorial
Justin Lin
 
Using python libraries.pptx , easy ppt to study class 12
Using python libraries.pptx , easy ppt to study class 12Using python libraries.pptx , easy ppt to study class 12
Using python libraries.pptx , easy ppt to study class 12
anikedheikhamsingh
 
Pythonpresent
PythonpresentPythonpresent
Pythonpresent
Chui-Wen Chiu
 
Programming with Python - Basic
Programming with Python - BasicProgramming with Python - Basic
Programming with Python - Basic
Mosky Liu
 
D7 as D8
D7 as D8D7 as D8
D7 as D8
Pablo López Escobés
 
Object oriented programming design and implementation
Object oriented programming design and implementationObject oriented programming design and implementation
Object oriented programming design and implementation
afsheenfaiq2
 
Modules 101
Modules 101Modules 101
Modules 101
gjcross
 
Python import mechanism
Python import mechanismPython import mechanism
Python import mechanism
Yuki Nishiwaki
 
Structuring and packaging your python project
Structuring and packaging your python projectStructuring and packaging your python project
Structuring and packaging your python project
Eyal Trabelsi
 
Modules and Packages in Python_Basics.pdf
Modules and Packages in Python_Basics.pdfModules and Packages in Python_Basics.pdf
Modules and Packages in Python_Basics.pdf
RavindraTambe3
 
ExtBase workshop
ExtBase workshop ExtBase workshop
ExtBase workshop
schmutt
 
Python: Modules and Packages
Python: Modules and PackagesPython: Modules and Packages
Python: Modules and Packages
Damian T. Gordon
 
Using Python Libraries.pdf
Using Python Libraries.pdfUsing Python Libraries.pdf
Using Python Libraries.pdf
SoumyadityaDey
 
PyCourse - Self driving python course
PyCourse - Self driving python coursePyCourse - Self driving python course
PyCourse - Self driving python course
Eran Shlomo
 
Open source projects with python
Open source projects with pythonOpen source projects with python
Open source projects with python
roskakori
 
Interesting Presentation on Python Modules and packages
Interesting Presentation on Python Modules and packagesInteresting Presentation on Python Modules and packages
Interesting Presentation on Python Modules and packages
arunavamukherjee9999
 
Modules and Packages in Python Programming Language.pptx
Modules and Packages in Python Programming Language.pptxModules and Packages in Python Programming Language.pptx
Modules and Packages in Python Programming Language.pptx
arunavamukherjee9999
 
PyCon Taiwan 2013 Tutorial
PyCon Taiwan 2013 TutorialPyCon Taiwan 2013 Tutorial
PyCon Taiwan 2013 Tutorial
Justin Lin
 
Using python libraries.pptx , easy ppt to study class 12
Using python libraries.pptx , easy ppt to study class 12Using python libraries.pptx , easy ppt to study class 12
Using python libraries.pptx , easy ppt to study class 12
anikedheikhamsingh
 
Programming with Python - Basic
Programming with Python - BasicProgramming with Python - Basic
Programming with Python - Basic
Mosky Liu
 
Object oriented programming design and implementation
Object oriented programming design and implementationObject oriented programming design and implementation
Object oriented programming design and implementation
afsheenfaiq2
 
Ad

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
Rubé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 systems
Rubé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 corpus
Rubén Izquierdo Beviá
 
Information Extraction
Information ExtractionInformation Extraction
Information Extraction
Rubé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 Disambiguation
Rubén Izquierdo Beviá
 
Juan Calvino y el Calvinismo
Juan Calvino y el CalvinismoJuan Calvino y el Calvinismo
Juan Calvino y el Calvinismo
Rubé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 files
Rubén Izquierdo Beviá
 
CLTL Software and Web Services
CLTL Software and Web Services CLTL Software and Web Services
CLTL Software and Web Services
Rubé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á
 
ULM1 - The borders of Ambiguity
ULM1 - The borders of AmbiguityULM1 - The borders of Ambiguity
ULM1 - The borders of Ambiguity
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 2013
Rubé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 CRF
Rubé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 Dutch
Rubé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 corpus
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 Ambiguity
Rubé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 systems
Rubé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 corpus
Rubé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 Disambiguation
Rubé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 files
Rubé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 2013
Rubé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 CRF
Rubé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 Dutch
Rubé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 corpus
Rubén Izquierdo Beviá
 

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

  • 1. CLTL Python Course Object Oriented Programming in Python 3rd session May 15th 2013
  • 2. Reminders ● Session I – What is Object Oriented Programming – Classes, objects, methods, properties... – How to define classes, with methods and attributes – How to create objects ● Session II – Create modules – Create packages – Reuse and import
  • 3. Session 3 ● Eclipse and PyDev – Use python within eclipse – Create projects – Create packages – Create modules – ...
  • 4. Eclipse and PyDev 1)Create a PyDev project Will contain all the structure, folders and information of the project 2)Create a source folder in the project Required for creating modules and packages 3)Create packages You already know python packages 4)Create modules You also know python modules
  • 5. Creating a PyDev project ● File > new > project > PyDev > PyDev Project ● Project name: the name of the project ● Project contents: the folder to locate the project ● Project type: usually Python ● Grammar version: the python grammar version (not important) ● Interpreter: which python you want use to run the project ● Create default 'src' folder ● Referenced projects: their source folders are added to the PYTHONPATH for the new project
  • 6. Creating a source folder ● Required in PyDev for creating packages and modules – For every new package/module, an existing source folder must be selected ● Two ways of creating (if you didn't create it with the PyDev project) – File -> new -> source folder Browse and select the project (the name will be always 'src') – Right click on the project -> new -> Source folder (you can select the name of the folder)
  • 7. Creating a Python package ● Python package: – A special folder where group python modules – There is a special module __init__.py – It will be seen as a whole package ● How to create packages: – File -> new -> python package. Select source folder and name – Right click on the project / source folder -> new python package ● How to nest packages: – Drag/drop on the pydev package explorer – By the “dotted” name --> root.nested
  • 8. Creating a Python module ● Python module: a python file that can contain functions, classes... ● In PyDev a python module can be associated to: – A source folder – A python package ● How to create modules: – File -> new -> python module. Select source folder (leave package empty) or package, module name and template – Right click on source folder/package on explorer -> new python module ● Pydev modules templates: – Empty: just an empty file – Class: contains the basic definition for a class – Main: contains the basic definition of a main python script (you can run it)
  • 9. How to run a module in PyDev ● Option 1 – Select the module and make it active – Run --> Run As --> Python run ● Option 2 – Right click on the module on the explorer – Run --> Run as --> python run ● Advanced: – Breakpoints, debugging...
  • 10. Assignment We want to develop some python packages for different projects of the CLTL group, so we should create a nice structure of packages and modules. ● We have only a main group (CLTL) ● There are several projects going on: newsreader, opener, semantics_of_history, each one could be a package ● In each project we will developed different tools... ● Each tool will process different data, different files... ● ....
  • 11. Assignment ● Define a project called my_cltl_project with a source folder ● This package structure ● Cltl (pkg) – Newsreader (pkg) – Opener (pkg) – semantics_of_history (pkg) ● coreference_tool (pkg) – metrics: B3.py, MUC.py (mods) – data: coref_set.py (mods) – io: coref_set_reader.py, coref_set_writer.py, csv_reader.py (mods) – Common (pkg) ● time_functions (mod)
  • 12. Assignment ● In time_functions.py implement a function called get_time() that returns a string with the current time (check python module time) ● In csv_reader.py implement a function read_csv(path) that takes as input the path of a file, which is CSV comma separated, and prints each line reversed a,b,c,d,e --> e,d,c,b,a 1,ruben,2,canito --> canito,2,ruben,1 (check split and list slicing and indexing) ● Created another project – with a main python module at least – Import the required stuff from the project cltl and call to the functions get_time() and read_csv(path)
  翻译: