Questions tagged [class-attribute]
18 questions
22
votes
3 answers
Kotlin: Initialize class attribute in constructor
I create a Kotlin-class with a class attribute, which I want to initialize in the constructor:
public class TestClass {
private var context : Context? = null // Nullable attribute
public constructor(context : Context) {
this.context…

Christopher
- 9,682
- 7
- 47
- 76
7
votes
4 answers
Is it bad practice to use the html class attribute as a javascript handle
I often need to select multiple elements at once with jquery... to do this I usually just add a class to all the elements I'd like to select and then use jquery to select by class.
Is this a bad practice or should I use something like the html 5…

RayLoveless
- 19,880
- 21
- 76
- 94
6
votes
2 answers
The pythonic way to access a class attribute within the class
I was wondering how do you think is the way to access a class attribute from a function within the class. I haven't found a reference in PEP8 or a popular question about it. e.g.
class MyClass(object):
BAR = 1
def foo(self):
# Way…

Ofek .T.
- 741
- 3
- 10
- 29
6
votes
2 answers
When are python classes and class attributes garbage collected?
class Member(object):
def __init__(self, identifier):
self.identifier = identifier
print "Member __init__", self.identifier
def __del__(self):
print "Member __del__", self.identifier
with open("/home/might/"…

Might
- 305
- 3
- 12
2
votes
0 answers
Android SimpleXML ClassNotFoundException
I have XML response and trying to parse it:
…

Yvgen
- 2,036
- 2
- 23
- 27
1
vote
2 answers
Why an attribute of a class be set a value, but print a None type?
Here is the code:
class Animal:
def __init__(self, animal_type):
self.animal_type = animal_type
class Cat(Animal):
def __init__(self, animal_type, favorite_food):
super().__init__(animal_type)
self.favorite_food =…

xin chen
- 33
- 3
1
vote
1 answer
pyCharm refactoring python class attribute name, does not rename all attribute usages
Considering the following:
class test:
att = 7
def print_class(class_instance):
print(class_instance.att)
if (__name__ == '__main__'):
t = test()
print_class (t)
print_class expects a class test instance as a parameter, but this…

OJNSim
- 736
- 1
- 6
- 22
1
vote
1 answer
Using class attribute in method definition as argument?
I have the following code :
class Blah:
ABC, DEF = range(2)
def meth(self, arg=Blah.ABC):
.....
Blah.ABC works inside the method or any place outside , the only place it does not work is in the method definition !!!
Any way to resolve…

sten
- 7,028
- 9
- 41
- 63
1
vote
3 answers
jQuery dialog selector not responding to the class name of elements loaded with Ajax
Update: problem solved:
Since 'problematic' elements were being created after the moment the page loadad, event delegation made sure all of them were bound to the jQuery event.
Original post:
I got this piece of code:
while…

absay
- 187
- 2
- 15
1
vote
2 answers
How to declare class when loading data set from database in Weka
I'm trying to understand how the following .arff file can be expressed in Weka when loading data from database instead of the file.
An .arff file has the following form:
@relation sample
@attribute expression string
@attribute tone…

user1669675
- 23
- 4
0
votes
0 answers
Python - updating class attribute (monkey patching?)?
So there is a class called Field and it has class attribute _slots, this attribute is dictionary.
So it looks like this (that class also use custom __metaclass__):
class Field(object):
_slots = {
'key1': False,
'key2': None,
…

Andrius
- 19,658
- 37
- 143
- 243
0
votes
2 answers
How can I apply one or more attributes to all classes in a project?
How can I apply an attribute to all classes in a particular project?!
And is it enough to apply CLSCompliant attribute to just one class or do I have to apply to all classes?
Thanks for your answers...

Dr TJ
- 3,241
- 2
- 35
- 51
0
votes
1 answer
inheritance of set class attribute in python
I'm trying to create basic abstract class with mechanism for saving of set of all created instances.
class Basic(object):
__metaclass__ = ABCMeta
allInstances = set()
def __init__(self, name):
self.allInstances.add(self)
…

Azazell00
- 93
- 8
0
votes
3 answers
Why can't I access the instance.__class__ attribute in Python?
I'm new to Python, and I know I must be missing something pretty simple, but why doesn't this very, very simple code work?
class myClass:
pass
testObject = myClass
print testObject.__class__
I get the following error:
AttributeError: class…

froadie
- 79,995
- 75
- 166
- 235
0
votes
3 answers
Class attributes in Python
Is there any difference in the following two pieces of code? If not, is one preferred over the other? Why would we be allowed to create class attributes dynamically?
Snippet 1
class Test(object):
def setClassAttribute(self):
…

Joel Christophel
- 2,604
- 4
- 30
- 49