module __call__
Thomas Wouters
thomas at xs4all.net
Wed Apr 19 04:27:00 EDT 2000
On Tue, Apr 18, 2000 at 04:23:43PM -0700, Dirck Blaskey wrote:
> Fredrik Lundh <effbot at telia.com> wrote in message
> news:7N4L4.497$wYl.191816704 at newsb.telia.net...
> > Dirck Blaskey <dirck at pacbell.net> wrote:
> > > ...Gee-Wouldn't-It-Be-Nice-If...
> > >
> > > modules could def __call__():
> > >
> > > so you could call a module, i.e.
> > >
> > > import StringIO
> > > f = StringIO()
> >
> > and
> >
> > class myStringIO(StringIO):
> > ...
> >
> > would explode in your face. lousy idea.
>
> Hmm...
>
> class myStringIO(StringIO):
>
> already doesn't work;
> you have to
>
> class myStringIO(StringIO.StringIO):
>
> as currently implemented.
Yes, but 'f = StringIO()' doesn't work either, in that case. Fredrik's
point, though a bit blunt, is that it would be confusing and thus unwise to
functionally separate
f = StringIO()
and
class myStringIO(StringIO)
If you really dislike typing StringIO twice, do what (nearly) everyone else
does:
from StringIO import StringIO
And if you dont subclass StringIO (haven't seen that happen a lot) you can
even go nifty and do:
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
giving you the power of cStringIO when it's available.
--
Thomas Wouters <thomas at xs4all.net>
Hi! I'm a .signature virus! copy me into your .signature file to help me spread!
More information about the Python-list
mailing list