473,246 Members | 1,588 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,246 software developers and data experts.

listing the type of an object

How can I list a type of an object instance ?

I tried:

class tLED (tDevice):
def some_proc(self):
print 'type(self)', type(self)

But i gives me:
type(self) <type 'instance'>

Moreover, I want even the type to be listed by it's ancestor, like this

class tDevice:
def some_other_proc:
print 'type(self)', type(self)

thanks,
Stef Mientki

Jun 27 '07 #1
5 1100
Stef Mientki a écrit :
How can I list a type of an object instance ?

I tried:

class tLED (tDevice):
<ot>
Do yourself (and the world) a favour and give up hungarian notation...
This should be:

class Led(Device):
#...

</ot>
def some_proc(self):
print 'type(self)', type(self)

But i gives me:
type(self) <type 'instance'>
looks like Device is an old style class.
Moreover, I want even the type to be listed by it's ancestor, like this

class tDevice:
def some_other_proc:
print 'type(self)', type(self)
Try this:

class Device(object):
def some_other_proc(self):
print self, type(self)

class Led(Device):
pass

led = Led()
led.some_other_proc()
Jun 28 '07 #2
Bruno Desthuilliers wrote:
Stef Mientki a écrit :
>How can I list a type of an object instance ?

I tried:

class tLED (tDevice):

<ot>
Do yourself (and the world) a favour and give up hungarian notation...
This should be:

class Led(Device):
#...

</ot>
Didn't know that this was called "Hungarian notation",
and although it's not my personal favorite, it is thé standard in Delphi,
but I admit that it's not a very good choice in a object oriented
language like Python.

The program I'm writing now is might be an exception,
I'm writing a program that should be extended by non-Python-programmers,
even maybe non-programmers !
So I'm trying to use a simplest approach from the viewpoint of the end
users.
>
> def some_proc(self):
print 'type(self)', type(self)

But i gives me:
type(self) <type 'instance'>

looks like Device is an old style class.
>Moreover, I want even the type to be listed by it's ancestor, like this

class tDevice:
def some_other_proc:
print 'type(self)', type(self)

Try this:

class Device(object):
def some_other_proc(self):
print self, type(self)

class Led(Device):
pass

led = Led()
led.some_other_proc()
thanks Bruno,
that does the job.

cheer,
Stef Mientki
Jun 28 '07 #3
stef a écrit :
Bruno Desthuilliers wrote:
>Stef Mientki a écrit :
>>How can I list a type of an object instance ?

I tried:

class tLED (tDevice):

<ot>
Do yourself (and the world) a favour and give up hungarian notation...
This should be:

class Led(Device):
#...

</ot>
Didn't know that this was called "Hungarian notation",
and although it's not my personal favorite, it is thé standard in Delphi,
Yeps. I know. But Python is not Delphi.
but I admit that it's not a very good choice in a object oriented
language like Python.
MHO is that it's not a very good choice, period. But that's another
troll !-)
The program I'm writing now is might be an exception,
I'm writing a program that should be extended by non-Python-programmers,
even maybe non-programmers !
AFAICT, lots of "non-programmers" are using Python.
So I'm trying to use a simplest approach from the viewpoint of the end
users.
I think the simplest approach is to use the simplest possible naming
scheme. Which is to stick to the idiomatic naming conventions, most of
them described in pep08.

My 2 cents...
Jun 28 '07 #4
On 2007-06-28, Bruno Desthuilliers <br********************@wtf.websiteburo.oops.comwr ote:
Stef Mientki a écrit :
>How can I list a type of an object instance ?

I tried:

class tLED (tDevice):

<ot>
Do yourself (and the world) a favour and give up hungarian notation...
This should be:

class Led(Device):
#...
Using a naming convention for class objects, e.g., camel-case, is
a practice very similar to hungarian notation.

I would've said something like: start learning the Python
community's naming conventions, and use those instead of
inventing your own.

--
Neil Cerutti
It will work out, somehow. That's a hell of a duo right there, Marbury,
Crawford and Houston. --Carmelo Anthony
Jun 28 '07 #5
Neil Cerutti a écrit :
On 2007-06-28, Bruno Desthuilliers <br********************@wtf.websiteburo.oops.comwr ote:
>Stef Mientki a écrit :
>>How can I list a type of an object instance ?

I tried:

class tLED (tDevice):
<ot>
Do yourself (and the world) a favour and give up hungarian notation...
This should be:

class Led(Device):
#...

Using a naming convention for class objects, e.g., camel-case, is
a practice very similar to hungarian notation.
And it's not even totally consistant since builtin types are usually
lowercase. But it's still the convention.
I would've said something like: start learning the Python
community's naming conventions, and use those instead of
inventing your own.
The TMyType convention comes from Delphi. So let's make this:

"""
start learning the Python
community's naming conventions, and use those instead of the ones of
your usual language
"""

!-)

Jun 28 '07 #6

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

Similar topics

5
by: benyang22 | last post by:
I have been a long time Matlab user. I Python, I miss Matlab's whos command. So I have written a little utility whos.py, which can be downloaded here:...
10
by: Chris | last post by:
Hi, Not sure if this is the right forum, but hopefully someone can help me. I am creating something for our intranet and i want to list the files and folders of a directory, i found some code...
3
by: Jason | last post by:
I need to get a listing of users from Active Directory. Getting the list is no problem using the DirectorySearcher class. My problem is getting the full legacy-style domain name of the user (in the...
3
by: Rohit Sharma | last post by:
Hi all.. ..NET + MSXML platform....VB Need to build a list of all the entities and attributes to allow the user to do search...how can i do that from the schema ?? Cheers Rohit
4
by: jbesr1230 | last post by:
Hello, How would I print out a listing of the queries that are in a database? I would like to have a spreadsheet style listing with the columns of: Query Name, Description, Modified Date, Created...
3
by: David Jacques | last post by:
I am trying to get a list of all files of a certain extension type on disk to do some processing in a loop. The code needs to be portable to UNIX, so I need to use plain c functionality. Does...
1
by: MLH | last post by:
Am having trouble with the filter property setting below. Would like to filter the listing to car makes beginning with "D". I'm blowing it on the filter spec somehow??? Sub OpenRecordsetX() ...
3
by: sandyw | last post by:
Hello Everyone. Well I working on a program that uses Map class and I have some errors. They are listed as. on line 110 Type safety: The method put(Object, Object) belongs to the raw type...
5
by: jain236 | last post by:
HI every body, i am always getting the following error while parsing a directory . i am reading a directory by doing ls and trying to find out the name,type,size, mtime and mode of files from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.