python day2
TRANSCRIPT
Day 2
Function, Object Oriented, Packaging
Function
Introduction
Function Parameters
Scope of Variables
Global statement
Default Argument Values
Keyword Arguments
The return statement
DocStrings in Functions
Function : Introduction
Functions are reusable pieces of programs
Functions are defined using the def keyword
A function can take parameters
You can declare variables inside a function definition
Functions can have optionals parameters too
Functions can have named arguments
Function : Global statement
You can use the values of such variables defined outside the function
Try to avoid the use of this global statement
Function : Parameters
Parameters are specified within the pair of parentheses in the function definition, separated by commas.
Function : Scope of Variables
the parameter passed in is actually a reference to a variable (but the reference is passed by value)
some data types are mutable, but others aren't
Function : Default Argument Values
Used when you want to declare as an optional argument
default argument value should be a constant (immutable)
Function : Keyword Arguments
You can give values for such parameters by naming them - this is called keyword arguments
we use the name (keyword) instead of the position, to specify the arguments to the function.
Benefits of this featureno need to remembers the order
we can give values to only those parameters which we want
Function : Keyword Arguments
Function : Keyword Arguments
Function : return
The return statement is used to return from a function i.e. break out of the function.
We can optionally return a value from the function as well.
In python can return one or move values
Function : best way to return
Function : DcdocStrings
documentation strings which is usually referred by docstring
important tool, you should make use of it
we can even get back the docstringfrom, say a function, when the program is actually running!
Function : working with DcdocStrings
Object Oriented
Introduction
Classes and Constructors
Object Methods
Class, Object Variables & Properties
Inheritance
Iterators and Generator
OO : Introduction
Declare a class with class keyword followed by class name
class NewStyle(object): """ NewStyle class decleration in Python 3.0 """ pass class OldStyle: """ OldStyle class decleration up to Python 2.7 """ pass
OO : class and constructor
Creating constructors in Python is really easy;
Simple create a method __init__
OO : arguments to constructor
Constructor is an like an methods
We can pass arguments to constructors
OO : Object Methods
OO : Class, Object Variables & Properties
Class variable are static variable
Variable declared with self are Object variable
OO : Class, Object Variables & Properties
OO : static method & object method
OO : Inheritance
OO : Magic method
OO : Iterator and generator
Iterator objects in python conform to the iterator protocol
which basically means they provide two methods: __iter__() and next()
The __iter__ returns the iterator object and is implicitly called at the start of loops.
The next() method returns the next value and is implicitly called at each loop increment.
next() raises a StopIteration exception when there are no more value to return
OO : Iterator
OO : generator
Packaging
Modules : Introduction
Byte-compiled .pyc files
A module's __name__
Creating your own Modules
from..import
The dir() function
Next Session ?
Installation of OpenERP
Working with LP
Understanding structure - Architecture
Customization Without Developments
Exercise: Room Reservation
Module - Minimal Structure
Module structure
Hello World First module to OpenERP
Contact me...
Mantavya Gajjar
Phone : 94263 40093Email : [email protected] : www.opentechnologies.inFollow on Twitter : @mantavyagajjar
Day 2