Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > How to give a custom object instance a type name ?

Reply
Thread Tools

How to give a custom object instance a type name ?

 
 
Graeme Matthew
Guest
Posts: n/a
 
      07-14-2003
Hi all, quick one,

I hope I am explaining this properly, I am wanting to do some introspection
on custom object instances, for example:

import md5
>>> m = md5.new()
>>> type(m)

<type 'md5.md5'>

I can at least test here by doing something like if type(m) == 'md5.md5':


Here is a custom Dispatcher class that I have written

>>> from BI.System.Controller.Dispatcher import Dispatcher
>>> x = Dispatcher()
>>> type(x)

<type 'instance'>

How do I get the same as with instance 'm' above where the type displays the
actual object instance name, however my
custom dispatcher instance is just a generic 'instance', is there some
builtin where this is set ?

many thanks

Graeme






 
Reply With Quote
 
 
 
 
Ulrich Petri
Guest
Posts: n/a
 
      07-14-2003
"Graeme Matthew" <(E-Mail Removed)> schrieb im Newsbeitrag
newsAwQa.168$(E-Mail Removed)...
>
> Here is a custom Dispatcher class that I have written
>
> >>> from BI.System.Controller.Dispatcher import Dispatcher
> >>> x = Dispatcher()
> >>> type(x)

> <type 'instance'>


You did Java before ?

> How do I get the same as with instance 'm' above where the type displays

the
> actual object instance name, however my
> custom dispatcher instance is just a generic 'instance', is there some
> builtin where this is set ?
>


how about
>>> x.__class__.__name__


HTH
Ciao Ulrich


 
Reply With Quote
 
 
 
 
Graeme Matthew
Guest
Posts: n/a
 
      07-14-2003
works fine, ta

x.__class__.__name__
'Dispatcher'
>>>

"Ulrich Petri" <(E-Mail Removed)> wrote in message
news:beu76g$8t8vu$(E-Mail Removed)-berlin.de...
> "Graeme Matthew" <(E-Mail Removed)> schrieb im Newsbeitrag
> newsAwQa.168$(E-Mail Removed)...
> >
> > Here is a custom Dispatcher class that I have written
> >
> > >>> from BI.System.Controller.Dispatcher import Dispatcher
> > >>> x = Dispatcher()
> > >>> type(x)

> > <type 'instance'>

>
> You did Java before ?
>
> > How do I get the same as with instance 'm' above where the type displays

> the
> > actual object instance name, however my
> > custom dispatcher instance is just a generic 'instance', is there some
> > builtin where this is set ?
> >

>
> how about
> >>> x.__class__.__name__

>
> HTH
> Ciao Ulrich
>
>



 
Reply With Quote
 
Kim Petersen
Guest
Posts: n/a
 
      07-14-2003
Graeme Matthew wrote:
> Hi all, quick one,
>
> I hope I am explaining this properly, I am wanting to do some introspection
> on custom object instances, for example:
>
> import md5
>
>>>>m = md5.new()
>>>>type(m)

>
> <type 'md5.md5'>
>
> I can at least test here by doing something like if type(m) == 'md5.md5':


how about doing this instead:

isinstance(m,md5.md5)

>
>
> Here is a custom Dispatcher class that I have written
>
>
>>>>from BI.System.Controller.Dispatcher import Dispatcher
>>>>x = Dispatcher()
>>>>type(x)

>
> <type 'instance'>
>
> How do I get the same as with instance 'm' above where the type displays the
> actual object instance name, however my
> custom dispatcher instance is just a generic 'instance', is there some
> builtin where this is set ?


isinstance(x,Dispatcher)

otherwise if you _really_ need the name - just do as some others indicated.


--
Med Venlig Hilsen / Regards

Kim Petersen - Kyborg A/S (Udvikling)
IT - Innovationshuset
Havneparken 2
7100 Vejle
Tlf. +4576408183 || Fax. +4576408188

 
Reply With Quote
 
Michael Hudson
Guest
Posts: n/a
 
      07-15-2003
"Graeme Matthew" <(E-Mail Removed)> writes:

> works fine, ta
>
> x.__class__.__name__
> 'Dispatcher'
> >>>


You could also use new-style classes, btw.

Cheers,
M.

--
Windows installation day one. Getting rid of the old windows
was easy - they fell apart quite happily, and certainly wont
be re-installable anywhere else. -- http://www.linux.org.uk/diary/
(not *that* sort of windows...)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Custom Taglib problems - instead of a single instance per page, I have a single instance per application. chris brat Java 1 05-10-2006 11:16 AM
Custom Control Problem :: Object reference not set to an instance of an object David Bowey ASP .Net Building Controls 1 03-16-2005 10:33 PM
Custom Control Problem :: Object reference not set to an instance of an object David Bowey ASP .Net Web Controls 1 03-16-2005 10:33 PM
Getting name of object instance from within object method Martin Javascript 6 08-20-2004 12:24 PM



Advertisments