Built-in Variables
- # Vehicle.py
- """ Vehicle Module defines Vehicle class
- """
-
- class Vehicle(object):
- """Document String: Define a Vehicle class"""
-
- def __init__(self, brand, year):
- self.brand = brand;
- self.year = year;
-
- # test.py
- """ Test Vehicle class defined in Vehicle module
- """
-
- from Vehicle import Vehicle
-
- def main():
- print Vehicle.__bases__ # base classes from which the calss directly inherits
- print Vehicle.__dict__ # a dictionary that corresponds to the class's namespace
- print Vehicle.__doc__ # a class's docstring
- print Vehicle.__module__ # module name in which the class is defined
- print Vehicle.__name__ # class name
-
- v = Vehicle("Buick", 1999)
- print v.__class__ # class name from which the object was instantiated
- print v.__dict__ # {'brand': 'Buick', 'year': 1999}
-
- if __name__ == '__main__':
- main()
-
__builtins__
provides direct access to all ‘built-in’ identifiers of Python; for example, __builtin__.open is the full name for the built-in function open()
__name__, the name of the module
__file__, the “path” to the file
- # Vehicle.py
- class Vehicle(object):
- """Document String: Define a Vehicle class"""
-
- def __init__(self, brand, year):
- #print "Create Vehicle Object ...";
- self._brand = brand;
- self._year = year;
-
- def main():
- v = Vehicle("Lincoln", 1998);
- print(__name__) # __main__
- print(__file__) # Vehicle.py
-
- if __name__ == "__main__":
- main()
-
__all__
Defined in __init__.py file, the list of modules that should be imported by from myPackage import *
Reference