473,407 Members | 2,598 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,407 software developers and data experts.

Inheritance confusion

Hi,

I'm having a problem with multiple inheritance - it's clearly something
I've missed, but the web pages and books that I've consulted aren't
helping, so I'll throw myself on the mercy and collective wisdom of
Usenet!

I've got 4 files (what I'll show has the active content removed for
brevity):

Errors_m.py
~~~~~~~~~~~
class Errors (object) :
def __init__ (self, params) :
pass

def Error (self, string) :
return 100

DT_m.py
~~~~~~~
class DT (object) :
def __init__ (self, params) :
pass

def Date (self, epoch, pattern = 'd mmm yyyy') :
dt = datetime.datetime.fromtimestamp (epoch)

Hook_m.py
~~~~~~~~~
from DT_m import DT
from Error_m import Errors

class Hook (Errors, DT) :
def __init__ (self, params) :
DT.__init__ (self, params)
Errors.__init__ (self, params)

DB_m.py
~~~~~~~
from Hook_m import Hook

class DB (Hook) :
def __init__ (self, params) :
Hook.__init__ (self, params)
And a test script:

#!/usr/bin/python

import os
import re
import string
import sys

from DB_m import DB

Dict = dict ()
Dict ['logdir'] = '/tmp/log'
Dict ['diag'] = 1

Obj = DB (Dict)
print dir (Obj)
Obj.Connect ('Database')
When I run the script I get this:

Traceback (most recent call last):
File "./3.py", line 20, in <module>
Obj.Connect ('Database')
File "/mnt/isis/Projects/Python/Learning/DB_m.py", line 102, in Connect
self.TRACE ("DB::Connect (" + database + "," + mode)
File "/mnt/isis/Projects/Python/Learning/Hook_m.py", line 314, in TRACE
self.DailyLog (msg)
File "/mnt/isis/Projects/Python/Learning/Hook_m.py", line 98, in
DailyLog
dt = self.Date (time ())
TypeError: 'module' object is not callable
Googling the "TypeError" message suggests that I've got a module and
class with the same name, but I can't see that I have.

Can someone point me in the right direction please?

If you need to see all the source, can do, but it's certainly too much
for an intro message!

Thanks,

Hook
Jun 27 '08 #1
6 960
On 19 Apr., 08:37, Hook <H...@somewhere.nowhere.co.au.itwrote:
Traceback (most recent call last):
File "./3.py", line 20, in <module>
Obj.Connect ('Database')
File "/mnt/isis/Projects/Python/Learning/DB_m.py", line 102, in Connect
self.TRACE ("DB::Connect (" + database + "," + mode)
File "/mnt/isis/Projects/Python/Learning/Hook_m.py", line 314, in TRACE
self.DailyLog (msg)
File "/mnt/isis/Projects/Python/Learning/Hook_m.py", line 98, in
DailyLog
dt = self.Date (time ())
TypeError: 'module' object is not callable

Googling the "TypeError" message suggests that I've got a module and
class with the same name, but I can't see that I have.
The error message just says that you have called a module which is
time in this case.

Just replace the call to time by time.time() and it shall work.

Jun 27 '08 #2
Hook wrote:
When I run the script I get this:

Traceback (most recent call last):
File "./3.py", line 20, in <module>
Obj.Connect ('Database')
File "/mnt/isis/Projects/Python/Learning/DB_m.py", line 102, in Connect
self.TRACE ("DB::Connect (" + database + "," + mode)
File "/mnt/isis/Projects/Python/Learning/Hook_m.py", line 314, in TRACE
self.DailyLog (msg)
File "/mnt/isis/Projects/Python/Learning/Hook_m.py", line 98, in
DailyLog
dt = self.Date (time ())
TypeError: 'module' object is not callable
Googling the "TypeError" message suggests that I've got a module and
class with the same name, but I can't see that I have.

Can someone point me in the right direction please?
Read the traceback ;) Here's a hint:
>>import time
time()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'module' object is not callable
>>time.time()
1208588011.7017989

Peter
Jun 27 '08 #3
On Apr 19, 12:37*am, Hook <H...@somewhere.nowhere.co.au.itwrote:
Hi,

I'm having a problem with multiple inheritance - it's clearly something
I've missed, but the web pages and books that I've consulted aren't
helping, so I'll throw myself on the mercy and collective wisdom of
Usenet!

I've got 4 files (what I'll show has the active content removed for
brevity):

Errors_m.py
~~~~~~~~~~~
class Errors (object) :
* * def __init__ (self, params) :
* * * * pass

* * def Error (self, string) :
* * * * return 100

DT_m.py
~~~~~~~
class DT (object) :
* * def __init__ (self, params) :
* * * * * * * * pass

* * def Date (self, epoch, pattern = 'd mmm yyyy') :
* * * * dt = datetime.datetime.fromtimestamp (epoch)

Hook_m.py
~~~~~~~~~
from DT_m import DT
from Error_m import Errors

class Hook (Errors, DT) :
* * def __init__ (self, params) :
* * * * DT.__init__ (self, params)
* * * * Errors.__init__ (self, params)

DB_m.py
~~~~~~~
from Hook_m import Hook

class DB (Hook) :
* * def __init__ (self, params) :
* * * * Hook.__init__ (self, params)

And a test script:

#!/usr/bin/python

import os
import re
import string
import sys

from DB_m import DB

Dict = dict ()
Dict ['logdir'] = '/tmp/log'
Dict ['diag'] * = 1

Obj = DB (Dict)
print dir (Obj)
Obj.Connect ('Database')

When I run the script I get this:

Traceback (most recent call last):
* File "./3.py", line 20, in <module>
* * Obj.Connect ('Database')
* File "/mnt/isis/Projects/Python/Learning/DB_m.py", line 102, in Connect
* * self.TRACE ("DB::Connect (" + database + "," + mode)
* File "/mnt/isis/Projects/Python/Learning/Hook_m.py", line 314, in TRACE
* * self.DailyLog (msg)
* File "/mnt/isis/Projects/Python/Learning/Hook_m.py", line 98, in
DailyLog
* * dt * * * * *= self.Date (time ())
TypeError: 'module' object is not callable

Googling the "TypeError" message suggests that I've got a module and
class with the same name, but I can't see that I have.

Can someone point me in the right direction please?

If you need to see all the source, can do, but it's certainly too much
for an intro message!

Thanks,

Hook

import time

time()

--output:--
Traceback (most recent call last):
File "test1.py", line 3, in ?
time()
TypeError: 'module' object is not callable
Did you do that somewhere?
Jun 27 '08 #4
In article <48**********************@news.astraweb.com>,
Hook <Ho**@somewhere.nowhere.co.au.itwrote:
Hi,

I'm having a problem with multiple inheritance - it's clearly something
I've missed, but the web pages and books that I've consulted aren't
helping, so I'll throw myself on the mercy and collective wisdom of
Usenet!

I've got 4 files (what I'll show has the active content removed for
brevity):

Errors_m.py
~~~~~~~~~~~
class Errors (object) :
def __init__ (self, params) :
pass

def Error (self, string) :
return 100

DT_m.py
~~~~~~~
class DT (object) :
def __init__ (self, params) :
pass

def Date (self, epoch, pattern = 'd mmm yyyy') :
dt = datetime.datetime.fromtimestamp (epoch)

Hook_m.py
~~~~~~~~~
from DT_m import DT
from Error_m import Errors

class Hook (Errors, DT) :
def __init__ (self, params) :
DT.__init__ (self, params)
Errors.__init__ (self, params)

DB_m.py
~~~~~~~
from Hook_m import Hook

class DB (Hook) :
def __init__ (self, params) :
Hook.__init__ (self, params)
And a test script:

#!/usr/bin/python

import os
import re
import string
import sys

from DB_m import DB

Dict = dict ()
Dict ['logdir'] = '/tmp/log'
Dict ['diag'] = 1

Obj = DB (Dict)
print dir (Obj)
Obj.Connect ('Database')
When I run the script I get this:

Traceback (most recent call last):
File "./3.py", line 20, in <module>
Obj.Connect ('Database')
File "/mnt/isis/Projects/Python/Learning/DB_m.py", line 102, in Connect
self.TRACE ("DB::Connect (" + database + "," + mode)
File "/mnt/isis/Projects/Python/Learning/Hook_m.py", line 314, in TRACE
self.DailyLog (msg)
File "/mnt/isis/Projects/Python/Learning/Hook_m.py", line 98, in
DailyLog
dt = self.Date (time ())
TypeError: 'module' object is not callable
Googling the "TypeError" message suggests that I've got a module and
class with the same name, but I can't see that I have.
For what it's worth, modules actually *are* allowed to contain a class
of the same name: for example, datetime.datetime.

Anyway, what this error message is actually trying to tell you is that
you are attempting to call a module as a function somewhere -- and in
this particular case, I think it's referring to the time module. Are
you sure that line 98 in Hook_m.py should not instead be:

dt = self.Date(time.time())

The time module contains a function, time(), which returns the current
Unix time (another example of a module containing an object of the same
name, incidentally); but you'll need to call this function as
"time.time()" unless you have prefaced your code with

from time import time

or

from time import *

Otherwise, the token "time" refers to the time module, which is not
callable, and not the desired function therein.

--
Mark Shroyer, http://markshroyer.com/contact/

Due to extreme spam, I block all articles originating from Google
Groups. If you want your postings to be seen by more readers you will
need to find a different means of posting on Usenet.
http://improve-usenet.org/
Jun 27 '08 #5
Hook <Ho**@somewhere.nowhere.co.au.itwrites:
I'm having a problem with multiple inheritance
You aren't alone. Multiple inheritance (MI) is difficult to implement,
and once implemented, usually difficult to understand and sometimes
counterintuitive.

I recommend you read and absorb the article "The Truth about super"
<URL:http://www.phyast.pitt.edu/~micheles/python/super.htmlto
understand more about MI in Python.
However, there are more fundamental issues:
I've got 4 files
That should be irrelevant to MI problems. Please refine your example
so that it's in one module, and still exhibits the problem.
When I run the script I get this:

Traceback (most recent call last):
File "./3.py", line 20, in <module>
Obj.Connect ('Database')
File "/mnt/isis/Projects/Python/Learning/DB_m.py", line 102, in Connect
self.TRACE ("DB::Connect (" + database + "," + mode)
File "/mnt/isis/Projects/Python/Learning/Hook_m.py", line 314, in TRACE
self.DailyLog (msg)
File "/mnt/isis/Projects/Python/Learning/Hook_m.py", line 98, in
DailyLog
dt = self.Date (time ())
TypeError: 'module' object is not callable
No, you don't. That might be what you get from *your* code, but it's
not produced by the code you *posted*. (I know this if only because
none of your modules have a line 98 on which to raise an exception.)

So, since we don't have the code that generates that traceback, that
traceback isn't useful to us for diagnosing the problem.
If you need to see all the source, can do, but it's certainly too
much for an intro message!
Indeed. Instead, re-work your code (based on a copy) until it's as
simple as it can be, and *still* shows the problems when you execute
it. Then, if you still don't know why the traceback occurs, feel free
to post that minimal example with the corresponding traceback.

--
\ "Jury: A group of 12 people, who, having lied to the judge |
`\ about their health, hearing, and business engagements, have |
_o__) failed to fool him." -- Henry L. Mencken |
Ben Finney
Jun 27 '08 #6
Thanks to everyone who replied. Kay and Mark put me on the right track
immediately. Ben is quite right - the fragment that I posted couldn't
have given that error, but I didn't want to post the whole thing -
perhaps wrongly, I thought it wouldn't help clarify what I thought the
problem was. And that was the real issue - I had managed to convince
myself that I had a naming problem in one of my own modules somewhere.

If anyone is interested in the background, I'm a long time Perl
programmer trying to learn Python by converting a small set of standard,
locally developed Perl libraries. It's an edifying experience, and I can
understand why some colleagues like Python so much.

Again, thanks for the help, it's appreciated.

Hook
Jun 27 '08 #7

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

Similar topics

4
by: Matthew Bell | last post by:
I've got a conceptual problem to do with inheritance. I'd be grateful if someone could help to clear up my confusion. An example. Say I need a class that's basically a list, with all the...
2
by: Flavian Musyoka Mwasi | last post by:
I'm a novice programmer just beginning to learn the new C# language. I'm a bit confused about the way Inheritance and Interfaces are constructed in C#. The following examples may help clarify...
1
by: Flavian Mwasi | last post by:
I'm a novice programmer just beginning to learn the new C# language. I'm a bit confused about the way Inheritance and Interfaces are constructed in C#. The following examples may help clarify...
45
by: Ben Blank | last post by:
I'm writing a family of classes which all inherit most of their methods and code (including constructors) from a single base class. When attempting to instance one of the derived classes using...
5
by: Invalidlastname | last post by:
Hi, I just read the pattern "Design and Implementation Guidelines for Web Clients" from MSDN. Here is my question. In chapter 3,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.