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.

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 887
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Matthew Bell | last post: by
2 posts views Thread by Flavian Musyoka Mwasi | last post: by
1 post views Thread by Flavian Mwasi | last post: by
45 posts views Thread by Ben Blank | last post: by
5 posts views Thread by Invalidlastname | last post: by
1 post views Thread by CARIGAR | 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.