473,698 Members | 2,034 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Dat eTime(2004)

I get AttributeError: 'module' object has no attribute 'DateTime'

but if you type:
import mx.DateTime
mx.DateTime.Dat eTime(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 1779
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.Dat eTime(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.Dat eTime(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.Dat eTime 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***********@A cm.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.Dat eTime(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.Dat eTime(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.Dat eTime 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***********@A cm.Org

Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
1375
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 then I find bugs, it seems that I can't import it again after a fix it. It always shows the same problem. I try del module but it doesn't work. (I use Python 2.4 with the ActivePython pack (PythonWin IDE)
5
2472
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 kk in k:
11
2556
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: (log65536)/(log4)= 8 I've searched around a bit and haven't been able to find anything.
12
2111
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
2309
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 one very large DLL that has the bulk of the code. I've downloaded the MFCWinFormsSample.EXE and have noticed that the main app could stay as a native executable (i.e. no CLR support) whereas the various ..DLLs can be marked as having CLR...
11
1499
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
2568
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 the mistake of running a test program from the same directory where I built and installed my package. Python uses the package from the current directory, which misses the pyd files, instead of the site-packages package which has them installed. ...
6
1660
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 computer to flip a coin 100 times and give me the output of how many times heads and tails. After solving a few syntax errors I seem to be stuck in an endless loop and have to kill python. A few times I would get it to print 'heads 0 (or 1) times...
6
4573
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 Traceback (most recent call last): File "/usr/local/bin/mma", line 55, in <module> import MMA.main File "/usr/local/share/mma/MMA/main.py", line 33, in <module> import MMA.docs
0
8600
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9155
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9018
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8858
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7711
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5859
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4360
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3038
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2322
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.