469,352 Members | 2,140 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,352 developers. It's quick & easy.

beginner import confusion

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'

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", like the first example, doesn't that get everything?

If you know, from the docs, that it contains a DateTime class and then a
DateTime object, and you specify the whole thing, why shouldn't that work?
thanks for your patience
Steve

Jul 18 '05 #1
2 1627
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
Sc***********@Acm.Org
Jul 18 '05 #2
packages, okay... , yes, thank you.. got it, back to one of my O'Reilly
books
"Scott David Daniels" <Sc***********@Acm.Org> wrote in message
news:40********@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
Sc***********@Acm.Org

Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Amir Dekel | last post: by
5 posts views Thread by Steve Holden | last post: by
11 posts views Thread by Svens | last post: by
12 posts views Thread by Joshua Rulz | last post: by
15 posts views Thread by Notre Poubelle | last post: by
11 posts views Thread by Brian Blazer | last post: by
6 posts views Thread by RJ | last post: by
6 posts views Thread by bvdp | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.