module not callable - why not?

Josiah Carlson jcarlson at uci.edu
Sun Apr 18 04:28:59 EDT 2004


>>- Don't name the module and a class in it the same thing
>>  import Queue # Queue is a module
>>  from Queue import Queue # Queue is a class
>>  ...  
> 
> To be frank, this problem is just one of the symptoms of a sickened
> programming language. Python runs into this problem (like
> SimpleXMLRPCServer.SimpleXMLRPCServer) because:
> 
> (a) By historical accident, Python modules differ significantly from
> regular classes. (Modules are like singleton without constructor for
> multiple instantiation, and without property getters/setters.)
> 
> (b) Python uses class-based OOP, instead of prototype-based OOP.
> 
> Class-based OOP is a historical mistake. If time could be turned back,
> I think people would rather start with prototype-based OOP, instead.
> 
> Because of this mistake of using class-based OOP, you have incomplete
> objects like modules and classes: you usually can't use them directly,
> at least not as comfortably/powerfully. Therefore, you find yourself
> dealing with names like SimpleXMLPRCServer.SimpleXMLRPCServer, without
> being able to collapse instance/class/module into one single object
> and one single name.

I think of modules as a namespace.  Why?  Because that is what they are. 
  They contain a space of names, some of which may be useful to you, 
otherwise you wouldn't have imported the module.  One really nifty thing 
about modules is that you can rename them if you want to, or even rebind 
names within them.  The user is allowed to do anything they want, even 
foolish things like "from module_blah import *".

In my opinion, modules are an explicit (and correct) solution to the 
namespace problem.  You don't like them?  Fine, write your own custom 
import command and stick it in site.py.  If you're good, you can enable 
it per-module (so that you can still use the standard library), and only 
have to deal with the "mistake" every once and a while.

  - Josiah



More information about the Python-list mailing list