22.10 Classes Versus Modules

Finally, let's wrap up this chapter by comparing the topics of this book's last two parts modules and classes. Since they're both about namespaces, the distinction can sometimes be confusing. In short:


Modules

  • Are data/logic packages

  • Are created by writing Python files or C extensions

  • Are used by being imported


Classes

  • Implement new objects

  • Are created by class statements

  • Are used by being called

  • Always live within a module

Classes also support extra features modules don't, such as operator overloading, multiple instance generation, and inheritance. Although both are namespaces, we hope you can tell by now that they are very different things.



Learning Python
Learning Python: Powerful Object-Oriented Programming
ISBN: 0596158068
EAN: 2147483647
Year: 2003
Pages: 253
Authors: Mark Lutz

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net