A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2002-June/024850.html below:

[Python-Dev] subclass a module?

[Python-Dev] subclass a module? [Python-Dev] subclass a module?Guido van Rossum guido@python.org
Sat, 01 Jun 2002 09:36:51 -0400
> > > Can I now subclass from modules?
> > 
> > It's a bug IMO.  
> > 
> > > And if so, what good does that do me?
> > 
> > None whatsoever.  The resulting class cannot be instantiated.
> 
> Really?
> 
> >>> import re
> >>> class X(type(re)):
> ...     def hello(): print 'hi'
> ...
> >>> newmod = X()
> >>> newmod.hello
> <bound method X.hello of <module '?' (built-in)>>

You subclass the module metaclass.  The example we were discussing was
different: it subclassed the module itself, like this:

    >>> import re
    >>> class X(re):
	 pass
    ...
    >>> X()
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    TypeError: 'module' object is not callable
    >>> 

--Guido van Rossum (home page: http://www.python.org/~guido/)




RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4