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

How to give a custom object instance a type name ?

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


Jul 18 '05 #1
4 4800
"Graeme Matthew" <gs*******@ozemail.com.au> schrieb im Newsbeitrag
news:DA****************@nnrp1.ozemail.com.au...

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
Jul 18 '05 #2
works fine, ta

x.__class__.__name__
'Dispatcher'
"Ulrich Petri" <ul***@gmx.de> wrote in message
news:be************@ID-67890.news.uni-berlin.de...
"Graeme Matthew" <gs*******@ozemail.com.au> schrieb im Newsbeitrag
news:DA****************@nnrp1.ozemail.com.au...

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

Jul 18 '05 #3
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

Jul 18 '05 #4
"Graeme Matthew" <gs*******@ozemail.com.au> 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...)
Jul 18 '05 #5

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

Similar topics

3
by: Michael Iantosca | last post by:
I have a custom attribute that I attach to certain pages in my application and I want to inspect each page request as it is made to see if the custom attribute is attached to the underlying page...
3
by: Minh Khoa | last post by:
Please give me more information about delegate and its usage? Why do i use it and when?
2
by: AMDRIT | last post by:
Hello everyone, I have created a custom component and one of its properties is a class object with it's own properties. During runtime, I can assign values to the class object properties just...
7
by: John Grandy | last post by:
My ASP.NET Web Service project has a Web Method that returns an array filled with instances of a custom class. The custom class is defined in a Class Library that is included in the web-service...
3
by: | last post by:
Hi all, I have a question on reflection Lets say I have a custom object called Address. Now, lets say I have a string variable that holds the name of a variable in the object such as...
3
by: Mark R. Dawson | last post by:
Hi all, I am trying to get custom attributes from a property. I can do this if I pass in the name of the property i.e. "Name" to the reflection methods, but if I pass in set_Name which is what...
0
by: a | last post by:
I need to create an instance of a custom object 'School.Teacher' and use it in a Profile object. I'm developing a bad case of "Pretzel Logic" thinking about this. Filling the custom object ...
15
by: Jeff Mason | last post by:
Hi, I'm having a reflection brain fog here, perhaps someone can set me on the right track. I'd like to define a custom attribute to be used in a class hierarchy. What I want to do is to...
1
by: asharda | last post by:
I have a custom property grid. I am using custom property grid as I do not want the error messages that the propertygrid shows when abphabets are entered in interger fields. The custom property...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.