| Line 352: |
Line 352: |
| | | | |
| | == Class == | | == Class == |
| | + | <source lang="python"> |
| | + | class MyClass: |
| | + | __init__(self, arg1, arg2): |
| | + | #This functionn will be executed every time you instantiate an element of this class |
| | + | self.var1 = arg1 |
| | + | self.var2 = arg2 |
| | + | |
| | + | def myFunction(self, param1): |
| | + | self.var1 = self.var1 +param1 |
| | + | </source> |
| | + | |
| | + | Built in attributes:<br /> |
| | + | __dict__ → Dictionary containing the class's namespace<br /> |
| | + | __doc__ → Class documentation string or None if undefined<br /> |
| | + | __name__ → Class name<br /> |
| | + | __module__ → Module name in which the class is defined. This attribute is "__main__" in interactive mode.<br /> |
| | + | __bases__ → A possibly empty tuple containing the base classes in the order of their occurrence<br /> |
| | + | |
| | + | '''Inheritance''' |
| | + | <source lang="python"> |
| | + | class SubClassName(ParentClass1[, ParentClass2, ...]): |
| | + | 'Optional class documentation string' |
| | + | # Class code |
| | + | </source> |
| | + | |
| | + | * issubclass(sub, sup) |
| | + | * isinstance(obj, Class) |
| | + | |
| | + | '''Generic functionality that can be overriden in own classes'''<br /> |
| | + | __init__(self[, args...]) → Constructor<br /> |
| | + | __del__(self) → Executed when Python's garbage collector destroys an object<br /> |
| | + | __repr__(self) → Evaluable string representation<br /> |
| | + | __str__(self) → Printable string representation<br /> |
| | + | __cmp__(self, x) → Object comparison<br /> |
| | + | __add__(self, other) → To define the + operator behave<br /> |
| | + | |
| | + | '''Hiding attributes''' |
| | + | attributes that start with a __ wont be visible to others<br /> |
| | + | |
| | == MySQLdb == | | == MySQLdb == |
| | == os.system() == | | == os.system() == |