new-style-class Questions

6

Solved

What is the difference between type(obj) and obj.__class__? Is there ever a possibility of type(obj) is not obj.__class__? I want to write a function that works generically on the supplied objects...
Abuse asked 29/6, 2009 at 20:55

2

Solved

A collection of classes defined as: class A(): @staticmethod def call(): print('a') class C(type): def __repr__(self): return 'somename' class B(A): __metaclass__ = C @staticmethod def ...
Commodore asked 13/3, 2012 at 1:27

3

Solved

I am converting code from python2 to python3 for newstyle classes using future. My project is in Django 1.11 I have a class in forms.py as: class Address: ...rest of code... class AddressForm(A...
Jasik asked 29/8, 2018 at 13:33

4

Solved

I have the following Python 2.7 code: class Frame: def __init__(self, image): self.image = image class Eye(Frame): def __init__(self, image): super(Eye, self).__init__() self.some_other_defi...
Repast asked 16/4, 2014 at 18:45

2

The python documentation states that __getattribute__ may be bypassed when looking up special methods. This is the result of implicit invocation via language syntax or built-in functions. For exam...
Stride asked 24/2, 2018 at 18:23

1

Solved

This is an old-style class: class OldStyle: pass This is a new-style class: class NewStyle(object): pass This is also a new-style class: class NewStyle2: __metaclass__ = type Is there a...
Mcdougald asked 15/9, 2016 at 1:3

4

Solved

So, I'm playing with decorators in Python 2.6, and I'm having some trouble getting them to work. Here is my class file: class testDec: @property def x(self): print 'called getter' return sel...
Frazil asked 28/2, 2009 at 14:33

8

Solved

What is the difference between old style and new style classes in Python? When should I use one or the other?
Sugihara asked 10/9, 2008 at 18:1

4

Solved

Code: import types class C(object): pass c = C() print(isinstance(c, types.InstanceType)) Output: False What correct way to check if object is instance of user-defined class for new-styl...
Papiamento asked 30/1, 2013 at 20:16

1

Solved

Why does this happen? class IsInstanceScrewer(object): def __init__(self, value): self.value = value def __getattribute__(self, name): if name in ('value',): return object.__getattribute__(s...
Dormitory asked 25/1, 2013 at 19:40

2

Solved

Possible Duplicate: Old style and new style classes in Python What is the current state of affairs with new-style and old-style classes in Python 2.7? I don't work with Python often,...
Ridglee asked 11/12, 2012 at 9:4

1

Solved

The Changelog for Python 2.2 (where new-style classes were introduced) says the following about the __new__ function: __new__ is a static method, not a class method. I initially thought it would...
Demagogy asked 1/2, 2012 at 7:4

2

Solved

I have recently stated trying to use the newer style of classes in Python (those derived from object). As an excersise to familiarise myself with them I am trying to define a class which has a numb...
Cortese asked 11/8, 2011 at 11:18

3

Solved

Possible Duplicate: Can Super deal with multiple inheritance? Python inheritance? I have a class structure (below), and want the child class to call the __init__ of both parents. Is t...
Inchoate asked 4/11, 2011 at 17:1

2

Solved

Can I force a parent class to call a derived class's version of a function? class Base(object): attr1 = '' attr2 = '' def virtual(self): pass # doesn't do anything in the parent class def f...
Molecular asked 19/2, 2010 at 16:25

3

Solved

I understand how both __init__ and __new__ work. I'm wondering if there is anything __init__ can do that __new__ cannot? i.e. can use of __init__ be replaced by the following pattern: class MySub...
Wightman asked 28/6, 2010 at 10:5

6

Solved

All the Python built-ins are subclasses of object and I come across many user-defined classes which are too. Why? What is the purpose of the class object? It's just an empty class, right?
Ganister asked 6/4, 2010 at 21:54

1

Solved

I have the following chunk of python code: import hashlib class User: def _set_password(self, value): self._password = hashlib.sha1(value).hexdigest() def _get_password(self): return self._p...
Kramatorsk asked 3/12, 2009 at 15:27

2

Solved

I'm trying to create a point class which defines a property called "coordinate". However, it's not behaving like I'd expect and I can't figure out why. class Point: def __init__(self, coord=None...
Schnabel asked 26/8, 2009 at 22:39
1

© 2022 - 2024 — McMap. All rights reserved.