FAQ

On Thu, Sep 10, 2015 at 11:50 AM, Andrew Barnert via Python-ideas wrote:
Of course it adds the cost of making the module slower, and also more complex. Maybe a better solution would be to add a random.set_default_instance function that replaced all of the top-level functions with bound methods of the instance (just like what's already done at startup in random.py)? That's simple, and doesn't slow down anything, and it seems like it makes it more clear what you're doing than setting random.inst.

+1. A single function call that replaces all the methods adds a
minuscule constant to code size, run time, etc, and it's no less
readable than assignment to a module attribute. (If anything, it makes
it more clearly a supported operation - I've seen novices not realize
that "module.xyz = foo" is valid, but nobody would misunderstand the
validity of a function call.)


ChrisA

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

People

Translate

site design / logo © 2017 Grokbase