Linked Questions
17 questions linked to/from python class attribute
2
votes
1
answer
2k
views
Set class variable using @classmethod [duplicate]
I have a class Employee with a class variable raise_amount. I created two instances, emp_1 & emp_2, for this class.
This question is not asking, what is a class variable, or how class variables ...
2
votes
3
answers
589
views
Why a classmethod can change the value of a class variable for one instance but not for another instance? [duplicate]
I have changed the value of class variable raise_amount for one instance. Later I have changed the value of the class variable with the classmethod set_raise_amt but it could not change the value for ...
0
votes
0
answers
274
views
python append object to a list [duplicate]
I have the following code:
receps =[1,1,1,2,2,2,2,3,3,3,3,3,3]
listRecep = []
listNumRecep = []
class Line:
def __init__(self,recep) :
self.recep = recep
class Recep:
recep=&...
0
votes
0
answers
85
views
How to use class attribute as instance attribute in Python? [duplicate]
I am new to Python programming and I was coding the following script to increase my understanding of Pyhton OOP.
# Python OOP
class Employee:
num_of_emps = 0
raise_amt = 1.04
def ...
2630
votes
27
answers
1.8m
views
Class (static) variables and methods
How do I create class (i.e. static) variables or methods in Python?
20
votes
5
answers
2k
views
Shared python generator
I am trying to reproduce the reactive extensions "shared" observable concept with Python generators.
Say I have an API that gives me an infinite stream that I can use like this:
def my_generator():
...
6
votes
7
answers
3k
views
Class attribute for two instances of the same class
There is this code:
class Sample:
variable = 2
object1 = Sample()
object2 = Sample()
print object1.variable # 2
print object2.variable # 2
object1.variable = 1
print object1.variable # 1
print ...
scdmb's user avatar
- 15.7k
3
votes
2
answers
3k
views
Difference between class attribute and instance variable with default value
Are there any differences between a class variable and an instance variable with a default value?
(especially in terms of their behavior under "normal use", internally I suppose they most likely are ...
3
votes
1
answer
2k
views
How to Create Shared Class Attributes between Classes in Python
I asked about this yesterday, but I botched writing up my question so much that by the time I realized what I typed, all the replies were solutions to a different miss-worded problem I didn't have. ...
-1
votes
2
answers
2k
views
What is the difference between class and data attributes?
To quote diveintopython,
"You already know about data attributes, which are variables owned by
a specific instance of a class. Python also supports class attributes,
which are variables owned by ...
Mark's user avatar
- 1,224
1
vote
2
answers
725
views
Doing something to one object does the same to all objects of the same class?
I'm only just starting to actually dabble seriously in Python, so it's possible this has a very easy answer, but at the moment I'm just dumbfounded. Here's the gist of what my code is:
class deck:
...
1
vote
4
answers
160
views
Class does not seem to be Global in python
I setup a class and it accepts and prints out the variables fine in one if statement.
class npc: #class for creating mooks
def __init__(self, name):
self.name = name
def npc_iq (self,...
1
vote
2
answers
128
views
Class Attributes/Variables in Python
Two examples;
class Foo1:
something = 0
def __init__(self, n):
self.something = n
and
class Foo2:
def __init__(self, n):
self.something = n
Both classes seem to have the ...
ap0's user avatar
- 1,173
1
vote
1
answer
84
views
Why the Python scope seems to behave differently for list variable and string variable?
Say that I have the following Python code:
import sys
class DogStr:
tricks = ''
def add_trick(self, trick):
self.tricks = trick
class DogList:
tricks = []
def add_trick(...
0
votes
0
answers
142
views
Thread stopped during while loop execution
I have a thread class (TransmitThread) written in python which takes few parameters and then starts transmitting to a device(NI USRP).
I have a rest flask based webservice,which on rest request by ...