Linked Questions

22 questions linked to/from How to avoid explicit 'self' in Python?
4 votes
5 answers
5k views

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 ...
Bin Chen's user avatar
  • 63.6k
8 votes
3 answers
3k views

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
1 vote
2 answers
839 views

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

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

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

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 ...
Nisha's user avatar
  • 1
263 votes
7 answers
359k views

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

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

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 ...
readonly's user avatar
  • 359k
88 votes
5 answers
59k views

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

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/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

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 ...
MASL's user avatar
  • 939
9 votes
3 answers
11k views

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 ...
user avatar
1 vote
4 answers
6k views

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 ...

15 30 50 per page
1
2