how do I know to what module an object belongs?

Michael Hudson mwh21 at
Fri Apr 14 10:27:03 CEST 2000

"Michal Wallace (sabren)" <sabren at> writes:

> On Thu, 13 Apr 2000, Michal Wallace (sabren) wrote:
> >    I know I can just as easily have them pass a reference to the
> > module along with it, but I'd be happier if I could just look at the
> > connection object and know which module it came from. Can I do this?
> Um.. Okay....
> for just about every module I've tried, I can do:
> module = eval(dbc.__class__.__module__)
> ... EXCEPT for ODBC.Windows..
> >>> dbc
> <MS ODBC Manager Connection object at 76c3b0>
> >>> dbc.__class__
> Traceback (innermost last):
>   File "<stdin>", line 1, in ?
> AttributeError: __class__
> >>>
> what gives?

Presumably dbc is not a Python class, but an extension type.

See what type(dbc).__name__ says; maybe you can special case for that?

Otherwise, I think you're hosed.  I'm not sure it's a good idea;
it sounds rather fragile to me.


  ... but I guess there are some things that are so gross you just have
  to forget,  or it'll destroy something within you.  perl is the first
  such thing I have known.                 -- Erik Naggum, comp.lang.lisp

More information about the Python-list mailing list