Steven D'Aprano steve+comp.lang.python at
Mon Sep 15 16:02:05 CEST 2014

Dave Angel wrote:

> Michael Torrie <torriem at> Wrote in message:

>> You can do it two ways:
>> Refer to it as random.shuffle()
>> or
>> from random import shuffle
>> I tend to use the first method (random.shuffle).  That way it prevents
>> my local namespace from getting polluted with random symbols imported
>> from modules.
> Or a third way:
> import random
> shuffle = random.shuffle

Our three weapons are:

(1) fully qualified names: 

    import random

(2) unqualified local imports: 

    from random import shuffle

(3) local name binding: 

    import random
    shuffle = random.shuffle

(4) messing about under the hood:

    shuffle = __import__('random', fromlist=['shuffle']).shuffle

(5) and a fanatical devotion to the Pope.

A serious question -- what is the point of the fromlist argument to
__import__? It doesn't appear to actually do anything.


More information about the Python-list mailing list