[Tutor] modules == class instances?
Sean 'Shaleh' Perry
shalehperry@attbi.com
Tue, 02 Apr 2002 18:41:05 -0800 (PST)
On 03-Apr-2002 Erik Price wrote:
> I have noticed something in the past day or so -- that the syntax for
> referring to a module's namespace is identical to the syntax used for
> referring to a class instance's methods -- you specify the name of the
> module or the class instance, then a dot, and then you specify the name
> of the function or property or method you wish to access.
>
> When I import a module into a script, does the import process in fact
> create an object instance to represent the module, or is this just a
> coincidence?
>
modules certainly ACT like objects:
>>> import re
>>> type(re)
<type 'module'>
>>> print re
<module 're' from '/usr/lib/python2.1/re.pyc'>
>>> dir(re)
['DOTALL', 'I', 'IGNORECASE', 'L', 'LOCALE', 'M', 'MULTILINE', 'S', 'U',
'UNICODE', 'VERBOSE', 'X', '__all__', '__builtins__', '__doc__', '__file__',
'__name__', 'compile', 'engine', 'error', 'escape', 'findall', 'match',
'purge', 'search', 'split', 'sub', 'subn', 'template']
but I am unsure how python treats them internally.
If nothing else it makes sense to use modules as objects too, so it makes sense
to simplify the language a bit.