By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,767 Members | 1,303 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,767 IT Pros & Developers. It's quick & easy.

beginner import confusion

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.