SlideShare une entreprise Scribd logo
1  sur  48
Nom du fichier – à compléter Management Presentation
Python
Opensource Object Oriented scripting language
Python
Opensource Object Oriented scripting language
1
Nom du fichier – à compléter Management Presentation
Agenda of workshop.
 Introduction to Python
 Features of Python
 Python in Enterprise
 Who use Python (They speak about Python)
 Rapid application Development using Python with OpenERP and
Django.
 Installation of Python on Windows and Linux
 Setup Development Enviroments using Eclipse
 Step to Python
 String
 Number
 Statements & Control Flow
Nom du fichier – à compléter Management Presentation
Agenda.
 Data Structure
• List, Tuple, Dict
 Sorting
 Object Oriented
• Class, Object, Inheritence, Polymorphism
 Modules
 Errors and Exceptions Handling
 Input / Output
 Python Quiz
Nom du fichier – à compléter Management Presentation
Introduction to Python
 Python is developed by Guido van Rossum, named the language
after the BBC show "Monty Python's Flying Circus".
Nom du fichier – à compléter Management Presentation
Introduction to Python.
 Python is an easy to learn, powerful programming language. It has
efficient high-level data structures and a simple but effective
approach to object-oriented
programming.
 Python's elegant syntax and dynamic typing, together with its
interpreted nature, make it an ideal language for scripting and
rapid application development in many areas on most platforms.
Nom du fichier – à compléter Management Presentation
Features of Python.
 Simple
 Flexible.
 Easy to Learn
 Free and Open Source
 High-level Language
 Platform Independent.
 Dynamic Type.
 Extensive Libraries.
 Object Oriented.
 Interpreted.
 Scalable.
Nom du fichier – à compléter Management Presentation
Python in Enterprise
 Frameworks, Web Development and MNCs.
Nom du fichier – à compléter Management Presentation
Python in Enterprise.
 Server, Social Network, shopping sites.
 Games & Graphics.
Nom du fichier – à compléter Management Presentation
What User Says ?
 YouTube.com
• "Python is fast enough for our site and allows us to produce maintainable
features in record times, with a minimum of developers," said Cuong Do,
Software Architect, YouTube.com.
 Google
• "Python has been an important part of Google since the beginning, and remains
so as the system grows and evolves. Today dozens of Google engineers use
Python, and we're looking for more people with skills in this language." said Peter
Norvig, director of search quality at Google, Inc.
 Industrial Light & Magic
• "Python plays a key role in our production pipeline. Without it a project the size
of Star Wars: Episode II would have been very difficult to pull off. From crowd
rendering to batch processing to compositing, Python binds all things together,"
said Tommy Burnette, Senior Technical Director, Industrial Light & Magic.
Nom du fichier – à compléter Management Presentation
What User Says ?
 University of Maryland
• "I have the students learn Python in our undergraduate and graduate
Semantic Web courses. Why? Because basically there's nothing else with the
flexibility and as many web libraries," said Prof. James A. Hendler.
Nom du fichier – à compléter Management Presentation
Rapid application Development using Python
• OpenERP Module
• Web Application using DJango
Nom du fichier – à compléter Management Presentation
Starting with Python.
 Instalation on Linux
• If you are using a Linux distribution such as Ubuntu, Fedora, OpenSUSE it is
most likely you already have Python installed on your system.
• To test if you have Python already installed on your Linux box, open a shell
program (like console or gnome-terminal) and enter the command python -V
as shown below.
 Instalation on Windows
• download the latest python version from the website and install it on your
system.
• Set the environment variable path.
 Setup Development Enviroments using Eclipse.
• http://www.easyeclipse.org/site/distributions/python.html
Nom du fichier – à compléter Management Presentation
First step to Python.
 Using The Interpreter Prompt
• Start the interpreter on the command line by entering python at the shell
prompt.
• For Windows users, you can run the interpreter in the command line if you
have set the PATH variable appropriately.
• Ex.
print('Hello World')
 Using Source file.
 Indentation
Nom du fichier – à compléter Management Presentation
Python Literals & Numbers.
 Literal Constants
• An example of a literal constant is a number like 5, 1.23, 9.25e-3 or a string
like 'This is a string' or "It's a string!". It is called a literal because it is literal -
you use its value literally.
 Numbers
• Numbers in Python are of three types - integers, floating point and complex
numbers.
• Ex. 3.23 and 52.3E-4
Nom du fichier – à compléter Management Presentation
Python Strings.
 Strings
• Single Quotes
• Double Quotes
• Triple Quotes
• Escape Sequences
 Raw Strings
 Strings Are Immutable
 String Literal Concatenation
Nom du fichier – à compléter Management Presentation
Control Flow statements
 The if statement.
• The if statement is used to check a condition and if the condition is true, we
run a block of statements (called the if-block), else we process another block
of statements (called the else-block). The else clause is optional.
• Example
Nom du fichier – à compléter Management Presentation
Control Flows Cont...
 The while Statement
• The while statement allows you to repeatedly execute a block of statements as long as a condition is
true. A while statement is an example of what is called a looping statement. A while statement can
have an optional else clause.
• Example
number = 23
running = True
while running:
guess = int(input('Enter an integer : '))
if guess == number:
print('Congratulations, you guessed it.')
running = False # this causes the while loop to stop
elif guess < number:
print('No, it is a little higher than that.')
else:
print('No, it is a little lower than that.')
else:
print('The while loop is over.')
# Do anything else you want to do here
Nom du fichier – à compléter Management Presentation
Python Control Flow...
 The for loop
• The for..in statement is another looping statement which iterates over a
sequence of objects i.e. go through each item in a sequence, sequence is just
an ordered collection of items.
• The for loop also have optional else statement.
• Example
Nom du fichier – à compléter Management Presentation
Python Control Flow...
 The break Statement
• The break statement is used to break out of a loop statement i.e. stop the
execution of a looping statement, even if the loop condition has not become
False or the sequence of items has been completely iterated over.
• Example
 The continue Statement
• The continue statement is used to tell Python to skip the rest of the
statements in the current loop block and to continue to the next iteration of
the loop.
• Example
Nom du fichier – à compléter Management Presentation
Python Functions
 Functions are reusable pieces of programs. They allow you to give a
name to a block of statements and you can run that block using
that name anywhere in your program and any number of times.
 Functions are defined using the def keyword.
 This is followed by an identifier name for the function followed by a
pair of parentheses which may enclose some names of variables
and the line ends with a colon.
 Example
Nom du fichier – à compléter Management Presentation
Python Function Cont...
 Local Variables
 Using The global Statement
 Default Argument Values
 Keyword Arguments
 The return Statement
 DocStrings
• Python has a nifty feature called documentation strings, usually referred to
by its shorter name docstrings. DocStrings are an important tool that you
should make use of since it helps to document the program better and
makes it easier to understand.
Nom du fichier – à compléter Management Presentation
Modules
 You have seen how you can reuse code in your program by defining
functions once. What if you wanted to reuse a number of functions
in other programs that you write?
 The answer is modules.
 There are various methods of writing modules, but the simplest
way is to create a file with a .py extension that contains functions
and variables.
 A module can be imported by another program to make use of its
functionality.
Nom du fichier – à compléter Management Presentation
Making Your Own Modules
 Creating your own modules is easy, you've been doing it all along!
This is because every Python program is also a module. You just
have to make sure it has a .py extension.
 Example of Module
Nom du fichier – à compléter Management Presentation
Packages
 Packages are just folders of modules with a special __init__.py file
that indicates to Python that this folder is special because it
contains Python modules.
Nom du fichier – à compléter Management Presentation
Python Data Structures
 Data structures are basically just that - they are structures which
can hold some data together. In other words, they are used to
store a collection of related data.
 List
• A list is a data structure that holds an ordered collection of items i.e. you can
store a sequence of items in a list.
• The list of items should be enclosed in square brackets so that Python
understands that you are specifying a list. Once you have created a list, you
can add, remove or search for items in the list. Since we can add and remove
items, we say that a list is a mutable data type i.e. this type can be altered.
• Example
o [1,2,3, 'a']
Nom du fichier – à compléter Management Presentation
Data Structure cont...
 Tuple
• Tuples are used to hold together multiple objects. Think of them as similar to
lists, but without the extensive functionality that the list class gives you. One
major feature of tuples is that they are immutable like strings i.e. you cannot
modify tuples.
• Tuples are defined by specifying items separated by commas within an
optional pair of parentheses.
• Tuples are usually used in cases where a statement or a user-defined
function can safely assume that the collection of values i.e. the tuple of
values used will not change.
• Example
o (1,2,3)
Nom du fichier – à compléter Management Presentation
Python Data Structure cont...
 Dictionary
• A dictionary is like an address-book where you can find the address or
contact details of a person by knowing only his/her name i.e. we associate
keys (name) with values (details).
• Note that the key must be unique just like you cannot find out the correct
information if you have two persons with the exact same name.
• Example
o {'a': 1, 'b':2}
Nom du fichier – à compléter Management Presentation
Python Data Structure
 Set
• Sets are unordered collections of simple objects. These are used when the
existence of an object in a collection is more important than the order or
how many times it occurs.
• Example
o bri = set(['brazil', 'russia', 'india'])
o
Nom du fichier – à compléter Management Presentation
Sorting
 There are lots of way to sort the data in python.
 Each data structure have its own sorting mechanism.
 List Sort
numlist=[1, 2.1, 2, 1.1, 1.3, 1.8, 1.9, 2.4, 2.8, 2.5, 2.8, 2.4, 2.1, 2.3, 1.1, 1.3,
1.3, 1.2, 1.2, 3, 3.1, 2.5, 3.5]
numlist.sort()
print (numlist)
• Custom Sorting With key=
strs = ['ccc', 'aaaa', 'd', 'bb']
print sorted(strs, key=len)
print sorted(strs, key=str.lower)
Nom du fichier – à compléter Management Presentation
Sorting cont...
 sort() method
mylist = ["b", "C", "A"]
mylist.sort()
 Dictonary sorting
import operator
x = {1: 2, 3: 4, 4:3, 2:1, 0:0}
sorted_x = sorted(x.iteritems(), key=operator.itemgetter(1))
Nom du fichier – à compléter Management Presentation
Object Oriented Programming with Python
 Organizing your program which is to combine data and
functionality and wrap it inside something called an object. This is
called the object oriented programming paradigm.
 Classes and objects are the two main aspects of object oriented
programming.
 Class contains data and methods.
 The self
• Class methods have only one specific difference from ordinary functions -
they must have an extra first name that has to be added to the beginning of
the parameter list, but you do not give a value for this parameter when you
call the method, Python will provide it. This particular variable refers to the
object itself, and by convention, it is given the name self.
Nom du fichier – à compléter Management Presentation
Classes
 The simplest class possible is shown in the following example.
Nom du fichier – à compléter Management Presentation
Object Methods
 We have already discussed that classes/objects can have methods
just like functions except that we have an extra self variable.
 Example
Nom du fichier – à compléter Management Presentation
The __init__method
 There are many method names which have special significance in
Python classes. We will see the significance of the __init__ method
now.
 The __init__ method is run as soon as an object of a class is
instantiated. The method is useful to do any initialization you want
to do with your object.
 Example
Nom du fichier – à compléter Management Presentation
Class And Object Variables
 There are two types of fields - class variables and object variables
which are classified depending on whether the class or the object
owns the variables respectively.
 Class variables are shared - they can be accessed by all instances of
that class. There is only one copy of the class variable and when
any one object makes a change to a class variable, that change will
be seen by all the other instances.
 Object variables are owned by each individual object/instance of
the class. In this case, each object has its own copy of the field i.e.
they are not shared and are not related in anyway to the field by
the same name in a different instance.
 Example
Nom du fichier – à compléter Management Presentation
Inheritance
 One of the major benefits of object oriented programming is reuse
of code and one of the ways this is achieved is through the
inheritance mechanism.
 Inheritance can be best imagined as implementing a type and
subtype relationship between classes.
 Simple inheritance.
 Multiple inheritance.
 Multi level Inheritance.
Nom du fichier – à compléter Management Presentation
Object oriented concepts...
 Method overloading.
 Method overwriting.
 Polymorphism

Nom du fichier – à compléter Management Presentation
Errors and Exceptions Handling
 Exception
• Exceptions occur when certain exceptional situations occur in your program.
For example, what if you are going to read a file and the file does not exist?
Or what if you accidentally deleted it when the program was running? Such
situations are handled using exceptions.
• We will try to read input from the user. Press ctrl-d and see what happens.
Nom du fichier – à compléter Management Presentation
Exception cont...
 Errors
• Consider a simple print function call. What if we misspelt print as Print?
Nom du fichier – à compléter Management Presentation
Handling Exceptions
 We can handle exceptions using the try..except statement.
 We put all the statements that might raise exceptions/errors inside
the try block and then put handlers for the appropriate
errors/exceptions in the except clause/block.
 The except clause can handle a single specified error or exception,
or a parenthesized list of errors/exceptions. If no names of errors
or exceptions are supplied, it will handle all errors and exceptions.
 If any error or wxception is not handeled then default python
handler will called.
 You can also have an else clause associated with a try..except
block. The else clause is executed if no exception occurs.
Nom du fichier – à compléter Management Presentation
Raising Exceptions
 You can raise exceptions using the raise statement by providing the
name of the error/exception and the exception object that is to be
thrown.
 The error or exception that you can arise should be class which
directly or indirectly must be a derived class of the Exception class.
 Example
Nom du fichier – à compléter Management Presentation
Try ..Finally
 Suppose you are reading a file in your program. How do you ensure
that the file object is closed properly whether or not an exception
was raised? This can be done using the finally block.
 Example
Nom du fichier – à compléter Management Presentation
Input / Output
 Up to now we have seen how to take input from user and display it
using input, raw_input and print statements.
 Another common type of input/output is dealing with files. The
ability to create, read and write files is essential to many programs.
 Files
• You can open and use files for reading or writing by creating an object of the
file class and using its read, readline or write methods appropriately to read
from or write to the file.
• The ability to read or write to the file depends on the mode you have
specified for the file opening.
• Then finally, when you are finished with the file, you call the close method to
tell Python that we are done using the file.
Nom du fichier – à compléter Management Presentation
Input/Output.
 Methods of File object.
• read()
• read_line()
• readlines()
• write(stringToWrite)
• seek(seekingByte)
• close()
Nom du fichier – à compléter Management Presentation
Input/Output
 Pickle
• when you want to save more complex data types like lists, dictionaries, or
class instances, things get a lot more complicated.
• Python provides a standard module called pickle.
• This is an amazing module that can take almost any Python object and
convert it to a string representation; this process is called pickling.
• Reconstructing the object from the string representation is called unpickling.
Nom du fichier – à compléter Management Presentation
Input/Output
 If you have an object x, and a file object f that’s been opened for
writing, the simplest way to pickle the object takes only one line of
code:
• pickle.dump(x, f)
 To unpickle the object again, if f is a file object which has been
opened for reading:
• x = pickle.load(f)
Nom du fichier – à compléter Management Presentation
Questions ?
Nom du fichier – à compléter Management Presentation
Contact Us
Write email at education@openerp.co.in
call us on 91 79 400 500 48

Contenu connexe

Tendances

Python quick guide1
Python quick guide1Python quick guide1
Python quick guide1
Kanchilug
 
Pythonanditsapplications 161121160425
Pythonanditsapplications 161121160425Pythonanditsapplications 161121160425
Pythonanditsapplications 161121160425
Sapna Tyagi
 

Tendances (20)

Python quick guide1
Python quick guide1Python quick guide1
Python quick guide1
 
Python
PythonPython
Python
 
PYTHON CURRENT TREND APPLICATIONS- AN OVERVIEW
PYTHON CURRENT TREND APPLICATIONS- AN OVERVIEWPYTHON CURRENT TREND APPLICATIONS- AN OVERVIEW
PYTHON CURRENT TREND APPLICATIONS- AN OVERVIEW
 
Introduction to python
 Introduction to python Introduction to python
Introduction to python
 
Python course syllabus
Python course syllabusPython course syllabus
Python course syllabus
 
Seminar report On Python
Seminar report On PythonSeminar report On Python
Seminar report On Python
 
Python programming
Python programmingPython programming
Python programming
 
Python Tutorial Part 2
Python Tutorial Part 2Python Tutorial Part 2
Python Tutorial Part 2
 
Python and its Applications
Python and its ApplicationsPython and its Applications
Python and its Applications
 
Presentation on java
Presentation on javaPresentation on java
Presentation on java
 
Research paper on python by Rj
Research paper on python by RjResearch paper on python by Rj
Research paper on python by Rj
 
summer training report on python
summer training report on pythonsummer training report on python
summer training report on python
 
Python Introduction
Python IntroductionPython Introduction
Python Introduction
 
Pythonanditsapplications 161121160425
Pythonanditsapplications 161121160425Pythonanditsapplications 161121160425
Pythonanditsapplications 161121160425
 
Python Programming ppt
Python Programming pptPython Programming ppt
Python Programming ppt
 
Top python interview question and answer
Top python interview question and answerTop python interview question and answer
Top python interview question and answer
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Python for All
Python for All Python for All
Python for All
 
Introduction To Python
Introduction To PythonIntroduction To Python
Introduction To Python
 
Python: the Project, the Language and the Style
Python: the Project, the Language and the StylePython: the Project, the Language and the Style
Python: the Project, the Language and the Style
 

En vedette (6)

FDP Event Report
FDP Event Report FDP Event Report
FDP Event Report
 
Python Workshop
Python WorkshopPython Workshop
Python Workshop
 
Python day2
Python day2Python day2
Python day2
 
Python Workshop
Python WorkshopPython Workshop
Python Workshop
 
Point of Sale - OpenERP 6.1
Point of Sale - OpenERP 6.1Point of Sale - OpenERP 6.1
Point of Sale - OpenERP 6.1
 
Python Day1
Python Day1Python Day1
Python Day1
 

Similaire à 20120314 changa-python-workshop

Python Programming-1.pptx of python by computer
Python Programming-1.pptx of python by computerPython Programming-1.pptx of python by computer
Python Programming-1.pptx of python by computer
sharanyarashmir5
 
Python and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthroughPython and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthrough
gabriellekuruvilla
 

Similaire à 20120314 changa-python-workshop (20)

First Steps in Python Programming
First Steps in Python ProgrammingFirst Steps in Python Programming
First Steps in Python Programming
 
Python Foundation – A programmer's introduction to Python concepts & style
Python Foundation – A programmer's introduction to Python concepts & stylePython Foundation – A programmer's introduction to Python concepts & style
Python Foundation – A programmer's introduction to Python concepts & style
 
Interview-level-QA-on-Python-Programming.pdf
Interview-level-QA-on-Python-Programming.pdfInterview-level-QA-on-Python-Programming.pdf
Interview-level-QA-on-Python-Programming.pdf
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Summer Training Project On Python Programming
Summer Training Project On Python ProgrammingSummer Training Project On Python Programming
Summer Training Project On Python Programming
 
Python
Python Python
Python
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Python Course.docx
Python Course.docxPython Course.docx
Python Course.docx
 
Python programming language introduction unit
Python programming language introduction unitPython programming language introduction unit
Python programming language introduction unit
 
pythontraining-201jn026043638.pptx
pythontraining-201jn026043638.pptxpythontraining-201jn026043638.pptx
pythontraining-201jn026043638.pptx
 
Python Programming-1.pptx of python by computer
Python Programming-1.pptx of python by computerPython Programming-1.pptx of python by computer
Python Programming-1.pptx of python by computer
 
Python Course In Chandigarh
Python Course In ChandigarhPython Course In Chandigarh
Python Course In Chandigarh
 
web programming UNIT VIII python by Bhavsingh Maloth
web programming UNIT VIII python by Bhavsingh Malothweb programming UNIT VIII python by Bhavsingh Maloth
web programming UNIT VIII python by Bhavsingh Maloth
 
Python training
Python trainingPython training
Python training
 
Python Programming1.ppt
Python Programming1.pptPython Programming1.ppt
Python Programming1.ppt
 
Python and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthroughPython and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthrough
 
Python programming
Python programmingPython programming
Python programming
 
PYTHON PPT.pptx
PYTHON PPT.pptxPYTHON PPT.pptx
PYTHON PPT.pptx
 
python-ppt.ppt
python-ppt.pptpython-ppt.ppt
python-ppt.ppt
 
python-ppt.ppt
python-ppt.pptpython-ppt.ppt
python-ppt.ppt
 

Dernier

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Dernier (20)

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

20120314 changa-python-workshop

  • 1. Nom du fichier – à compléter Management Presentation Python Opensource Object Oriented scripting language Python Opensource Object Oriented scripting language 1
  • 2. Nom du fichier – à compléter Management Presentation Agenda of workshop.  Introduction to Python  Features of Python  Python in Enterprise  Who use Python (They speak about Python)  Rapid application Development using Python with OpenERP and Django.  Installation of Python on Windows and Linux  Setup Development Enviroments using Eclipse  Step to Python  String  Number  Statements & Control Flow
  • 3. Nom du fichier – à compléter Management Presentation Agenda.  Data Structure • List, Tuple, Dict  Sorting  Object Oriented • Class, Object, Inheritence, Polymorphism  Modules  Errors and Exceptions Handling  Input / Output  Python Quiz
  • 4. Nom du fichier – à compléter Management Presentation Introduction to Python  Python is developed by Guido van Rossum, named the language after the BBC show "Monty Python's Flying Circus".
  • 5. Nom du fichier – à compléter Management Presentation Introduction to Python.  Python is an easy to learn, powerful programming language. It has efficient high-level data structures and a simple but effective approach to object-oriented programming.  Python's elegant syntax and dynamic typing, together with its interpreted nature, make it an ideal language for scripting and rapid application development in many areas on most platforms.
  • 6. Nom du fichier – à compléter Management Presentation Features of Python.  Simple  Flexible.  Easy to Learn  Free and Open Source  High-level Language  Platform Independent.  Dynamic Type.  Extensive Libraries.  Object Oriented.  Interpreted.  Scalable.
  • 7. Nom du fichier – à compléter Management Presentation Python in Enterprise  Frameworks, Web Development and MNCs.
  • 8. Nom du fichier – à compléter Management Presentation Python in Enterprise.  Server, Social Network, shopping sites.  Games & Graphics.
  • 9. Nom du fichier – à compléter Management Presentation What User Says ?  YouTube.com • "Python is fast enough for our site and allows us to produce maintainable features in record times, with a minimum of developers," said Cuong Do, Software Architect, YouTube.com.  Google • "Python has been an important part of Google since the beginning, and remains so as the system grows and evolves. Today dozens of Google engineers use Python, and we're looking for more people with skills in this language." said Peter Norvig, director of search quality at Google, Inc.  Industrial Light & Magic • "Python plays a key role in our production pipeline. Without it a project the size of Star Wars: Episode II would have been very difficult to pull off. From crowd rendering to batch processing to compositing, Python binds all things together," said Tommy Burnette, Senior Technical Director, Industrial Light & Magic.
  • 10. Nom du fichier – à compléter Management Presentation What User Says ?  University of Maryland • "I have the students learn Python in our undergraduate and graduate Semantic Web courses. Why? Because basically there's nothing else with the flexibility and as many web libraries," said Prof. James A. Hendler.
  • 11. Nom du fichier – à compléter Management Presentation Rapid application Development using Python • OpenERP Module • Web Application using DJango
  • 12. Nom du fichier – à compléter Management Presentation Starting with Python.  Instalation on Linux • If you are using a Linux distribution such as Ubuntu, Fedora, OpenSUSE it is most likely you already have Python installed on your system. • To test if you have Python already installed on your Linux box, open a shell program (like console or gnome-terminal) and enter the command python -V as shown below.  Instalation on Windows • download the latest python version from the website and install it on your system. • Set the environment variable path.  Setup Development Enviroments using Eclipse. • http://www.easyeclipse.org/site/distributions/python.html
  • 13. Nom du fichier – à compléter Management Presentation First step to Python.  Using The Interpreter Prompt • Start the interpreter on the command line by entering python at the shell prompt. • For Windows users, you can run the interpreter in the command line if you have set the PATH variable appropriately. • Ex. print('Hello World')  Using Source file.  Indentation
  • 14. Nom du fichier – à compléter Management Presentation Python Literals & Numbers.  Literal Constants • An example of a literal constant is a number like 5, 1.23, 9.25e-3 or a string like 'This is a string' or "It's a string!". It is called a literal because it is literal - you use its value literally.  Numbers • Numbers in Python are of three types - integers, floating point and complex numbers. • Ex. 3.23 and 52.3E-4
  • 15. Nom du fichier – à compléter Management Presentation Python Strings.  Strings • Single Quotes • Double Quotes • Triple Quotes • Escape Sequences  Raw Strings  Strings Are Immutable  String Literal Concatenation
  • 16. Nom du fichier – à compléter Management Presentation Control Flow statements  The if statement. • The if statement is used to check a condition and if the condition is true, we run a block of statements (called the if-block), else we process another block of statements (called the else-block). The else clause is optional. • Example
  • 17. Nom du fichier – à compléter Management Presentation Control Flows Cont...  The while Statement • The while statement allows you to repeatedly execute a block of statements as long as a condition is true. A while statement is an example of what is called a looping statement. A while statement can have an optional else clause. • Example number = 23 running = True while running: guess = int(input('Enter an integer : ')) if guess == number: print('Congratulations, you guessed it.') running = False # this causes the while loop to stop elif guess < number: print('No, it is a little higher than that.') else: print('No, it is a little lower than that.') else: print('The while loop is over.') # Do anything else you want to do here
  • 18. Nom du fichier – à compléter Management Presentation Python Control Flow...  The for loop • The for..in statement is another looping statement which iterates over a sequence of objects i.e. go through each item in a sequence, sequence is just an ordered collection of items. • The for loop also have optional else statement. • Example
  • 19. Nom du fichier – à compléter Management Presentation Python Control Flow...  The break Statement • The break statement is used to break out of a loop statement i.e. stop the execution of a looping statement, even if the loop condition has not become False or the sequence of items has been completely iterated over. • Example  The continue Statement • The continue statement is used to tell Python to skip the rest of the statements in the current loop block and to continue to the next iteration of the loop. • Example
  • 20. Nom du fichier – à compléter Management Presentation Python Functions  Functions are reusable pieces of programs. They allow you to give a name to a block of statements and you can run that block using that name anywhere in your program and any number of times.  Functions are defined using the def keyword.  This is followed by an identifier name for the function followed by a pair of parentheses which may enclose some names of variables and the line ends with a colon.  Example
  • 21. Nom du fichier – à compléter Management Presentation Python Function Cont...  Local Variables  Using The global Statement  Default Argument Values  Keyword Arguments  The return Statement  DocStrings • Python has a nifty feature called documentation strings, usually referred to by its shorter name docstrings. DocStrings are an important tool that you should make use of since it helps to document the program better and makes it easier to understand.
  • 22. Nom du fichier – à compléter Management Presentation Modules  You have seen how you can reuse code in your program by defining functions once. What if you wanted to reuse a number of functions in other programs that you write?  The answer is modules.  There are various methods of writing modules, but the simplest way is to create a file with a .py extension that contains functions and variables.  A module can be imported by another program to make use of its functionality.
  • 23. Nom du fichier – à compléter Management Presentation Making Your Own Modules  Creating your own modules is easy, you've been doing it all along! This is because every Python program is also a module. You just have to make sure it has a .py extension.  Example of Module
  • 24. Nom du fichier – à compléter Management Presentation Packages  Packages are just folders of modules with a special __init__.py file that indicates to Python that this folder is special because it contains Python modules.
  • 25. Nom du fichier – à compléter Management Presentation Python Data Structures  Data structures are basically just that - they are structures which can hold some data together. In other words, they are used to store a collection of related data.  List • A list is a data structure that holds an ordered collection of items i.e. you can store a sequence of items in a list. • The list of items should be enclosed in square brackets so that Python understands that you are specifying a list. Once you have created a list, you can add, remove or search for items in the list. Since we can add and remove items, we say that a list is a mutable data type i.e. this type can be altered. • Example o [1,2,3, 'a']
  • 26. Nom du fichier – à compléter Management Presentation Data Structure cont...  Tuple • Tuples are used to hold together multiple objects. Think of them as similar to lists, but without the extensive functionality that the list class gives you. One major feature of tuples is that they are immutable like strings i.e. you cannot modify tuples. • Tuples are defined by specifying items separated by commas within an optional pair of parentheses. • Tuples are usually used in cases where a statement or a user-defined function can safely assume that the collection of values i.e. the tuple of values used will not change. • Example o (1,2,3)
  • 27. Nom du fichier – à compléter Management Presentation Python Data Structure cont...  Dictionary • A dictionary is like an address-book where you can find the address or contact details of a person by knowing only his/her name i.e. we associate keys (name) with values (details). • Note that the key must be unique just like you cannot find out the correct information if you have two persons with the exact same name. • Example o {'a': 1, 'b':2}
  • 28. Nom du fichier – à compléter Management Presentation Python Data Structure  Set • Sets are unordered collections of simple objects. These are used when the existence of an object in a collection is more important than the order or how many times it occurs. • Example o bri = set(['brazil', 'russia', 'india']) o
  • 29. Nom du fichier – à compléter Management Presentation Sorting  There are lots of way to sort the data in python.  Each data structure have its own sorting mechanism.  List Sort numlist=[1, 2.1, 2, 1.1, 1.3, 1.8, 1.9, 2.4, 2.8, 2.5, 2.8, 2.4, 2.1, 2.3, 1.1, 1.3, 1.3, 1.2, 1.2, 3, 3.1, 2.5, 3.5] numlist.sort() print (numlist) • Custom Sorting With key= strs = ['ccc', 'aaaa', 'd', 'bb'] print sorted(strs, key=len) print sorted(strs, key=str.lower)
  • 30. Nom du fichier – à compléter Management Presentation Sorting cont...  sort() method mylist = ["b", "C", "A"] mylist.sort()  Dictonary sorting import operator x = {1: 2, 3: 4, 4:3, 2:1, 0:0} sorted_x = sorted(x.iteritems(), key=operator.itemgetter(1))
  • 31. Nom du fichier – à compléter Management Presentation Object Oriented Programming with Python  Organizing your program which is to combine data and functionality and wrap it inside something called an object. This is called the object oriented programming paradigm.  Classes and objects are the two main aspects of object oriented programming.  Class contains data and methods.  The self • Class methods have only one specific difference from ordinary functions - they must have an extra first name that has to be added to the beginning of the parameter list, but you do not give a value for this parameter when you call the method, Python will provide it. This particular variable refers to the object itself, and by convention, it is given the name self.
  • 32. Nom du fichier – à compléter Management Presentation Classes  The simplest class possible is shown in the following example.
  • 33. Nom du fichier – à compléter Management Presentation Object Methods  We have already discussed that classes/objects can have methods just like functions except that we have an extra self variable.  Example
  • 34. Nom du fichier – à compléter Management Presentation The __init__method  There are many method names which have special significance in Python classes. We will see the significance of the __init__ method now.  The __init__ method is run as soon as an object of a class is instantiated. The method is useful to do any initialization you want to do with your object.  Example
  • 35. Nom du fichier – à compléter Management Presentation Class And Object Variables  There are two types of fields - class variables and object variables which are classified depending on whether the class or the object owns the variables respectively.  Class variables are shared - they can be accessed by all instances of that class. There is only one copy of the class variable and when any one object makes a change to a class variable, that change will be seen by all the other instances.  Object variables are owned by each individual object/instance of the class. In this case, each object has its own copy of the field i.e. they are not shared and are not related in anyway to the field by the same name in a different instance.  Example
  • 36. Nom du fichier – à compléter Management Presentation Inheritance  One of the major benefits of object oriented programming is reuse of code and one of the ways this is achieved is through the inheritance mechanism.  Inheritance can be best imagined as implementing a type and subtype relationship between classes.  Simple inheritance.  Multiple inheritance.  Multi level Inheritance.
  • 37. Nom du fichier – à compléter Management Presentation Object oriented concepts...  Method overloading.  Method overwriting.  Polymorphism 
  • 38. Nom du fichier – à compléter Management Presentation Errors and Exceptions Handling  Exception • Exceptions occur when certain exceptional situations occur in your program. For example, what if you are going to read a file and the file does not exist? Or what if you accidentally deleted it when the program was running? Such situations are handled using exceptions. • We will try to read input from the user. Press ctrl-d and see what happens.
  • 39. Nom du fichier – à compléter Management Presentation Exception cont...  Errors • Consider a simple print function call. What if we misspelt print as Print?
  • 40. Nom du fichier – à compléter Management Presentation Handling Exceptions  We can handle exceptions using the try..except statement.  We put all the statements that might raise exceptions/errors inside the try block and then put handlers for the appropriate errors/exceptions in the except clause/block.  The except clause can handle a single specified error or exception, or a parenthesized list of errors/exceptions. If no names of errors or exceptions are supplied, it will handle all errors and exceptions.  If any error or wxception is not handeled then default python handler will called.  You can also have an else clause associated with a try..except block. The else clause is executed if no exception occurs.
  • 41. Nom du fichier – à compléter Management Presentation Raising Exceptions  You can raise exceptions using the raise statement by providing the name of the error/exception and the exception object that is to be thrown.  The error or exception that you can arise should be class which directly or indirectly must be a derived class of the Exception class.  Example
  • 42. Nom du fichier – à compléter Management Presentation Try ..Finally  Suppose you are reading a file in your program. How do you ensure that the file object is closed properly whether or not an exception was raised? This can be done using the finally block.  Example
  • 43. Nom du fichier – à compléter Management Presentation Input / Output  Up to now we have seen how to take input from user and display it using input, raw_input and print statements.  Another common type of input/output is dealing with files. The ability to create, read and write files is essential to many programs.  Files • You can open and use files for reading or writing by creating an object of the file class and using its read, readline or write methods appropriately to read from or write to the file. • The ability to read or write to the file depends on the mode you have specified for the file opening. • Then finally, when you are finished with the file, you call the close method to tell Python that we are done using the file.
  • 44. Nom du fichier – à compléter Management Presentation Input/Output.  Methods of File object. • read() • read_line() • readlines() • write(stringToWrite) • seek(seekingByte) • close()
  • 45. Nom du fichier – à compléter Management Presentation Input/Output  Pickle • when you want to save more complex data types like lists, dictionaries, or class instances, things get a lot more complicated. • Python provides a standard module called pickle. • This is an amazing module that can take almost any Python object and convert it to a string representation; this process is called pickling. • Reconstructing the object from the string representation is called unpickling.
  • 46. Nom du fichier – à compléter Management Presentation Input/Output  If you have an object x, and a file object f that’s been opened for writing, the simplest way to pickle the object takes only one line of code: • pickle.dump(x, f)  To unpickle the object again, if f is a file object which has been opened for reading: • x = pickle.load(f)
  • 47. Nom du fichier – à compléter Management Presentation Questions ?
  • 48. Nom du fichier – à compléter Management Presentation Contact Us Write email at education@openerp.co.in call us on 91 79 400 500 48