[Python-bugs-list] [ python-Feature Requests-481962 ] Make modules callable
SourceForge.net
noreply@sourceforge.net
Sat, 28 Jun 2003 00:15:14 -0700
Feature Requests item #481962, was opened at 2001-11-14 23:11
Message generated for change (Comment added) made by rhettinger
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=481962&group_id=5470
Category: None
Group: None
>Status: Closed
>Resolution: Rejected
Priority: 5
Submitted By: Thomas Justin Shaw (justinshaw)
Assigned to: Nobody/Anonymous (nobody)
Summary: Make modules callable
Initial Comment:
Many modules are have the same name as the main class
they contain. I.E.
gnu = Gnuplot.Gnuplot()
Why not make modules callable. That is if a module
contains a function called "__init__()" then that
fucntion gets called whenever the code
x = module(args)
is encountered.
Just an idea.
----------------------------------------------------------------------
>Comment By: Raymond Hettinger (rhettinger)
Date: 2003-06-28 02:15
Message:
Logged In: YES
user_id=80475
On python-dev, Guido vetoed any efforts to make modules
look more like classes.
----------------------------------------------------------------------
Comment By: Cherniavsky Beni (cben)
Date: 2003-03-10 11:36
Message:
Logged In: YES
user_id=36166
It'd be better to do that on `__call__`. One would expect
`__init__` to be called when the module object is
initialized (which is not really needed because you can
write it in a the top level).
This only makes sense as a complete upgrade of modules to
object capabilities, i.e. `__add__`, `__getitem__`,
`__setattr__` should be implemented then too. I'm not sure
that's a good idea.
To be precise, the above ideas lose the distinction between
the type and it's instances - these special functions should
only be called for instances of the module but moduels don't
have instances...
An alternative proposal: implement just one magic function,
`__new__`, that if present is called at the end of the
import and the object returned by it is used instead of the
module. This allows any objects (e.g. class instances with
all their magic) to be exposed as modules. You can already
do this by installing any object in sys.modules; this would
provide a clean way to do it from inside the module.
----------------------------------------------------------------------
Comment By: Thomas Justin Shaw (justinshaw)
Date: 2003-01-23 19:19
Message:
Logged In: YES
user_id=135558
The problem with:
from Gnuplot import Gnuplot
is that now you cannot do:
d = Gnuplot.Data()
Yes, I agree "__call__" is more explicit.
----------------------------------------------------------------------
Comment By: Raymond Hettinger (rhettinger)
Date: 2003-01-22 23:48
Message:
Logged In: YES
user_id=80475
I don't think this shortcut gives an advantage over:
from Gnuplot import Gnuplot
. . .
x = Gnuplot(args)
----------------------------------------------------------------------
Comment By: Andrew Bennetts (spiv)
Date: 2002-06-27 02:51
Message:
Logged In: YES
user_id=50945
Wouldn't calling a function named "__call__" make more sense
than "__init__"?
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=481962&group_id=5470