Inheritance confusion

Mark Shroyer usenet-mail at markshroyer.com
Sat Apr 19 03:03:54 EDT 2008


In article <4809932c$0$12307$c3e8da3 at news.astraweb.com>,
 Hook <Hook at somewhere.nowhere.co.au.it> wrote:

> 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/



More information about the Python-list mailing list