[Python-ideas] making a module callable

Haoyi Li haoyi.sg at gmail.com
Tue Nov 19 22:39:19 CET 2013


> there are some modules who just have one single main use (pprint) and
could profit from that.

A milion times this!

pprint.pprint()
time.time()
random.random()
copy.copy()
md5.md5()
timeit.timeit()
glob.glob()
cStringIO.cStringIO()
StringIO.StringIO()



On Tue, Nov 19, 2013 at 1:01 PM, Philipp A. <flying-sheep at web.de> wrote:

> 2013/11/19 Michael Foord <fuzzyman at gmail.com>
>
> On 19 November 2013 18:09, Philipp A. <flying-sheep at web.de> wrote:
>>
>>> imho it would simplify the situation. currently, everything is callable
>>> that has a __call__ property which is itself callable:
>>>
>> This is why module objects are not callable even if they have a __call__.
>> They are *instances* of ModuleType and the __call__ method is looked up on
>> their type, not the instance itself. So modules not being callable even
>> when they a __call__ is not an anomaly, even if it is not convenient
>> sometimes.
>>
> you’re right, apologies. so the hack consists of switching a module’s
> class during runtime…
>
> there’s also another hack, calldules<https://pypi.python.org/pypi/calldules>,
> making that automatic (funnily via implicits effects when doing import
> calldules). note that it isn’t serious! just a programming exercise.
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20131119/028403aa/attachment-0001.html>


More information about the Python-ideas mailing list