473,785 Members | 3,137 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

type() for new style classes - buggy?

hello,

does the type() command work correctly for new style classes? i guess
it does not, unfortunately. for example, for a new style class'
instance it returns <class '__main__.Class Name'>, but for old style
class' instance it returns <type 'instance'>.
import types
class A(object): pass class B: pass type(A()) <class '__main__.A'> type(B()) <type 'instance'> type(A()) == types.InstanceT ype 0 type(B()) == types.InstanceT ype

1

how can one then determine what he's working with when he uses new
style classes (either instance or class)?

thank you,
--
fuf (fu*@mageo.cz)

Jul 18 '05 #1
1 1337


In the case of new style classes type actually doubles up as a class
constructor, so all classes including type itself are instances type.
class A(object): .... pass
.... a = A()
type(a) <class '__main__.A'> type(A) <type 'type'> isinstance(A, type) True isinstance(a, type) False isinstance(type , type) True


hope this helps
there is some documentation on new style classes you might want to read.
http://www.python.org/doc/newstyle.html
particularly the first essay by Guido.


Jul 18 '05 #2

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

Similar topics

16
1679
by: Chris | last post by:
Is there any way to make the class Z behave the same way as class Y? Chris class Y: value = 42 def __hasattr__(self, name): if name == '__int__': return True def __getattr__(self, name):
13
2541
by: TheKeith | last post by:
Is it just me or does opera and ie not render the float style properly? IE does a sucky job at it, but opera makes a total mess; Mozilla/Firefox renders it correctly however. I'm just trying to be a good boy following the html 4.01 strict spec, and taking it a step further by not using tables for layout, but it's becoming a real pain. You would figure putting a strict doctype declaration at the top of the page would create a uniformity in...
5
4738
by: Alun | last post by:
I am trying to use the import method of attaching stlyesheets but I'm getting strange results. this is the code I'm using... <head> <title>CSS Example</title> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
7
6267
by: | last post by:
Source Error: Line 173: sData(rownumber - 1, lcnt) = WhatCol.Value Line 174: End IF Line 175: If (sData(rownumber, lcnt) = sData(rownumber - 1, lcnt)) AND (WhatCol.Type <> 5 AND WhatCol.Type <> 6) Then Line 176: If rownumber = 3 Then Line 177: thisfield = WhatCol.Value
104
5533
by: Colin McGuire | last post by:
Hi, is there a way to show a form without a titlebar (and therefore no control box/minimize box/title etc) but still have it appear looking like 3D? The property FormBorderStyle to None - this gives no titlebar etc but the form borders don't look 3D. In case I haven't explained what I want well, I want a form that looks like a button with no text (ie a form with the lovely 3D borders but no titlebar etc).
9
1344
by: Ryan | last post by:
Hi all, I'm playing with Lutz Roeders Reflector and have found several areas where I think there are issues in the framework libraries. I can't see how the following should work as expected and the compiler gives me an error on the 'text1 = text1...' line. Is it really this buggy (this particular bug is in several places) or am I missing something? You can see that that code has a possibility of crashing if the property has a .. in it....
5
3175
by: JH | last post by:
Hi I found that a type/class are both a subclass and a instance of base type "object". It conflicts to my understanding that: 1.) a type/class object is created from class statement 2.) a instance is created by "calling" a class object.
21
5202
by: Nikolaus Rath | last post by:
Hello, Can someone explain to me the difference between a type and a class? After reading http://www.cafepy.com/article/python_types_and_objects/ it seems to me that classes and types are actually the same thing: - both are instances of a metaclass, and the same metaclass ('type') can instantiate both classes and types. - both can be instantiated and yield an "ordinary" object - I can even inherit from a type and get a class
1
1126
by: Chris Rebert | last post by:
Subclassing 'object' makes the class new-style as opposed to old-style. object is the ultimate superclass of all new-style classes. Old-style classes are deprecated and will be removed in Python 3.0, but they're currently the default for backward-compatibility reasons. See http://docs.python.org/ref/node33.html for more info. - Chris On Mon, Sep 8, 2008 at 2:35 PM, AON LAZIO <aonlazio@gmail.comwrote:
0
9643
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10315
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10085
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2877
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.