Skip to content

Instantly share code, notes, and snippets.

@nfarring
Created January 28, 2011 01:43
Show Gist options
  • Save nfarring/799665 to your computer and use it in GitHub Desktop.
Save nfarring/799665 to your computer and use it in GitHub Desktop.
A template for a Python module that implements a single Python class.
# Copyright (c) 2011, Nathan Farrington
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""This is the module documentation."""
# import foo
# from foo import bar
#############
## GLOBALS ##
#############
__all__ = ["TemplateClass"]
###############
## FUNCTIONS ##
###############
#############
## CLASSES ##
#############
class TemplateClass(object):
"""This is the class documentation."""
pass
# Ref: http://docs.python.org/reference/datamodel.html
#
# 3.4.1: Basic customization
# __new__
# __init__
# __del__
# __repr__
# __str__
# __lt__
# __le__
# __eq__
# __ne__
# __gt__
# __ge__
# __hash__
# __nonzero__
# __unicode__
#
# 3.4.2: Customizing attribute access
# __getattr__
# __setattr__
# __delattr__
#
# 3.4.2.1. More attribute access for new-style classes
# __getattribute__
#
# 3.4.2.2. Implementing Descriptors
# 3.4.2.3. Invoking Descriptors
# __get__
# __set__
# __delete__
#
# 3.4.2.4. __slots__
# __slots__
#
# 3.4.3. Customizing class creation
# __metaclass__
#
# 3.4.4. Customizing instance and subclass checks
# __instancecheck__
# __subclasscheck__
# See also: PEP 3119 - Introducing Abstract Base Classes
#
# 3.4.5. Emulating callable objects
# __call__
#
# 3.4.6. Emulating container types
# __len__
# __getitem__
# __setitem__
# __delitem__
# __iter__
# __reversed__
# __contains__
#
# 3.4.7. Additional methods for emulation of sequence types
# __getslice__
# __setslice__
# __delslice__
#
# 3.4.8. Emulating numeric types
# __add__
# __sub__
# __mul__
# __floordiv__
# __mod__
# __divmod__
# __pow__
# __lshift__
# __rshift__
# __and__
# __xor__
# __or__
# __div__
# __truediv__
# __radd__
# __rsub__
# __rmul__
# __rdiv__
# __rtruediv__
# __rfloordiv__
# __rmod__
# __rdivmod__
# __rpow__
# __rlshift__
# __rrshift__
# __rand__
# __rxor__
# __ror__
# __iadd__
# __isub__
# __imul__
# __idiv__
# __itruediv__
# __ifloordiv__
# __imod__
# __ipow__
# __ilshift__
# __irshift__
# __iand__
# __ixor__
# __ior__
# __neg__
# __pos__
# __abs__
# __invert__
# __complex__
# __int__
# __long__
# __float__
# __oct__
# __hex__
# __index__
# __coerce__
#
# 3.4.10. With Statement Context Managers
# __enter__
# __exit__
# See also: PEP 0343 - The "with" statement
# vim: set ts=4 sw=4 expandtab:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment