beginner import confusion

DilbertFan steveb428pleaseremovethis at hotmail.com
Sat Apr 3 17:06:47 EST 2004


packages, okay... , yes, thank you..  got it, back to one of my O'Reilly
books
"Scott David Daniels" <Scott.Daniels at Acm.Org> wrote in message
news:406f2fe7$1 at nntp0.pdx.net...
> DilbertFan wrote:
>
> > Hi,
> >  I really thought that I had this importing business down.
> > I recently downloaded and installed mx module for the DateTime class.
> >
> > In IDLE, I go:
> >    import mx
> >    mx.DateTime.DateTime(2004)
>  >    I get AttributeError: 'module' object has no attribute 'DateTime'
>
> mx is a package, mx.DateTime is a module; you need to import a module
> to get to its contents.
>
> >  but if you type:
> >     import mx.DateTime
> >     mx.DateTime.DateTime(2004)
> >    <DateTime object for '2004-01-01 00:00:00.00' at a979e0>
>  > If you "import mx", ... doesn't that get everything?
> If mx were a module, you would be right.  However, it is a "package,"
> a collection of modules and packages.  Packages are a way of keeping
> the names one provider of many python modules from conflicting with
> the module names of both you and python itself.
>
> > If you know, from the docs, that it contains a DateTime class
> > and then a DateTime object,
> mx.DateTime.DateTime is a class, not an object.
> You could do:
>      from mx.DateTime import DateTime
> to simply get the DateTime class and then use DateTime(2004).
>
> -- 
> -Scott David Daniels
> Scott.Daniels at Acm.Org





More information about the Python-list mailing list