473,320 Members | 1,947 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 1754
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Amir Dekel | last post by:
Hello everyone, First, I have to say that Python is one of the coolest programing languages I have seen. And now for the problem (must be a silly one): When I import a module I have wrote, and...
5
by: Steve Holden | last post by:
This is even stranger: it makes it if I import the module a second time: import dbimp as dbimp import sys if __name__ == "__main__": dbimp.install() #k = sys.modules.keys() #k.sort() #for...
11
by: Svens | last post by:
Hey everyone! I'm a math student working on a short script involving logs. I have a function on my scientific calculator, and was wondering if there was a similar funtion in python. For example:...
12
by: Joshua Rulz | last post by:
Hi, i want to learn to program im quite skilled with computers and want to learn c++. is there anyone who can teach me or tell me a good website to learn it? all replies will be appreciated.
15
by: Notre Poubelle | last post by:
Hello, I have a large legacy MFC application. As is typical, there is an executable along with several MFC DLLs. One of these DLLs is created by staticly linking in many libraries resulting in...
11
by: Brian Blazer | last post by:
OK, I have a very simple class here: class Student: """Defines the student class""" def __init__(self, lName, fName, mi): self.lName = lName self.fName = fName self.mi = mi
2
by: Jon | last post by:
It appears that (windows) python searches in the current working directory before looking in the local site-packages directory, or that '.' comes first in sys.path? The problem arises when I made...
6
by: RJ | last post by:
I'm trying to teach myself Python (probably running into the old dog new tricks issue) and I'm trying to start with the very basics to get a handle on them. I'm trying to write code to get the...
6
by: bvdp | last post by:
I'm going quite nutty here with an import problem. I've got a fairly complicated program (about 12,000 lines in 34 modules). I just made some "improvements" and get the following error: bob$ mma...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.