Linked Questions
22 questions linked to/from How to avoid explicit 'self' in Python?
4
votes
5
answers
5k
views
is it possible not to use "self" in a class? [duplicate]
Possible Duplicate:
Python: How to avoid explicit 'self'?
In python class if I need to reference the class member variable, I need to have a self. before it. This is anonying, can I not ...
8
votes
3
answers
3k
views
How to avoid using 'self' so much [duplicate]
I am writing a program to simulate a small physical system and have become more and more annoyed as I write things like this:
K = 0.5 * self.m * self.v**2
In the case above, the equation is short ...
user avatar
user1641774
1
vote
2
answers
839
views
How do I create a class-wide, manipulable variable in Python? [duplicate]
Relatively new Python programmer here. So I am trying to create a variable that is accessible and changeable by any method within a class that is initialized within the constructor. So far, I cannot ...
-1
votes
1
answer
638
views
TypeError: hola() takes 0 positional arguments but 1 was given [duplicate]
This a simply code that I trying to access to a method in a class from another method in the same class but it is given me that error any help?
class menu:
def __init__(self,a,b):
self.a=...
-2
votes
1
answer
79
views
Python Classes and the self [duplicate]
I got a little beginner question about Classes and the self.
My Function checkAbonnement looks like that right now:
def checkAbonnement(self):
# Create Labels and Buttons
self.text = ...
-2
votes
2
answers
68
views
Do we have to always use self.variable while using them in some expression? [duplicate]
class learn:
def __init__(self,radius=1):
self.radius = radius
def reset_area(self,new_radius):
self.radius= new_radius
self.area = new_radius*new_radius*3.14
...
263
votes
7
answers
359k
views
Iterate over object attributes in python [duplicate]
I have a python object with several attributes and methods. I want to iterate over object attributes.
class my_python_obj(object):
attr1='a'
attr2='b'
attr3='c'
def method1(self, ...
124
votes
17
answers
58k
views
Automatically initialize instance variables?
I have a python class that looks like this:
class Process:
def __init__(self, PID, PPID, cmd, FDs, reachable, user):
followed by:
self.PID=PID
self.PPID=PPID
self.cmd=cmd
...
225
votes
10
answers
115k
views
Why do you need explicitly have the "self" argument in a Python method? [duplicate]
When defining a method on a class in Python, it looks something like this:
class MyClass(object):
def __init__(self, x, y):
self.x = x
self.y = y
But in some other languages, such ...
88
votes
5
answers
59k
views
What difference does it make to use "self" to define a member in a Python class?
How do these 2 classes differ?
class A():
x = 3
class B():
def __init__(self):
self.x = 3
Is there any significant difference?
ryeguy's user avatar
- 67.3k
22
votes
5
answers
21k
views
Any way to modify locals dictionary?
locals is a built in function that returns a dictionary of local values. The documentation says:
Warning
The contents of this dictionary should
not be modified; changes may not
affect the ...
23
votes
5
answers
6k
views
What is the advantage of having this/self pointer mandatory explicit?
What is the advantage of having this/self/me pointer mandatory explicit?
According to OOP theory a method is supposed to operate mainly (only?) on member variables and method's arguments. Following ...
17
votes
4
answers
47k
views
Python class methods: when is self not needed
I'm trying to rewrite some code using classes. At some point what I want is assign a member function a particular definition using a parameter value for each instance of an object.
Coming from other ...
9
votes
3
answers
11k
views
What does self do? [duplicate]
Possible Duplicate:
Python 'self' keyword
Forgive me if this is an incredibly noobish question, but I never did understand self in Python. What does it do? And when I see things like
def ...
1
vote
4
answers
6k
views
Why do functions/methods in python need self as parameter? [duplicate]
I can understand why it is needed for local variables, (self.x), but why is is nessecary as parameter in a function? Is there something else you could put there instead of self?
Please explain in as ...