Coding Nested Loops

Dan Sommers me at privacy.net
Sat Sep 16 13:50:49 EDT 2006


On Sat, 16 Sep 2006 10:06:25 -0700 (PDT),
Rich Shepard <rshepard at appl-ecosys.com> wrote:

> On Sat, 16 Sep 2006, Dan Sommers wrote:

>> When you import random, all you're doing is importing the module; you
>> have to specify any given attribute thereof:

>   I thought that was implied. For example, I use 'import wx' and can
> then instantiate wx.frame, wx.dialogbox, etc. without explicitly
> importing each one. Apparently different modules work differently.

No, they all work the same way (thank goodness!).  The "." between "wx"
and "frame" is the same dot as is between "random" and "choice" (i.e.,
random.choice is the same construct as wx.frame).

Don't be confused by from:  if you use "from wx import frame," then you
can access frame *without* the "wx." bit.  I don't have wx installed,
but that works with random, too:

    >>> choice
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    NameError: name 'choice' is not defined
    >>> import random
    >>> random.choice
    <bound method Random.choice of <random.Random object at 0x1841a10>>
    >>> from random import choice
    >>> choice
    <bound method Random.choice of <random.Random object at 0x1841a10>>

HTH,
Dan

-- 
Dan Sommers
<http://www.tombstonezero.net/dan/>
"I wish people would die in alphabetical order." -- My wife, the genealogist



More information about the Python-list mailing list