Linked Questions

34 questions linked to/from Why do we use __init__ in Python classes?
982 votes
18 answers
1.6m views

I'm learning the Python programming language and I've came across something I don't fully understand. In a method like: def method(self, blah): def __init__(?): .... .... What does ...
user avatar
24 votes
3 answers
28k views

While reading the code of OpenStack and I encountered this. A class named 'Service' inherits the base class 'object', and then in Service's __init__() method, object's __init__ is called. The related ...
can.'s user avatar
  • 2,289
5 votes
2 answers
8k views

Okay. So I saw someone using this code, and I understand it, I so I'm going to use it. Is it necessary to have __init__? class A(object): def __init__(self): self.x = 'Hello' def ...
jped's user avatar
  • 101
-3 votes
2 answers
6k views

Hey guys so I have done a lot of research into _init_() but still don't get it. From what I currently understand it must be used for all instances of a class to pass object args? I understand the use ...
Aeryes's user avatar
  • 701
-1 votes
1 answer
2k views

I am currently studying Python and I have seen in many source codes that uses init(self) but I do not know about it. I'm a newbie so please explain it easily.
K-C-J's user avatar
  • 1
1 vote
1 answer
752 views

I started learning python (with no prior knowledge of it, not programming) few weeks ago and am stuck at Classes. Currently the "init" class method confuses me. What does it do, in fact? Here is an ...
0 votes
0 answers
445 views

So, as a newbie in Python, I am trying to understand it with the use of some examples. I'd like to understand it better, so I have made this: class MyClass(object): i = 123 def hot(self): ...
Siyah's user avatar
  • 2,907
-3 votes
2 answers
132 views

I'm a novice in python programming. I've been jumping from one resource to another to really grasp a low-level understanding of what __init__() is which normally appears at the beginning of a python ...
11 votes
2 answers
6k views

So I understand how to use init when defining a class in Python. However, I am confused as to what to put inside the init function, or if I should use it at all. For example: Here I make the user ...
Talysin's user avatar
  • 363
1 vote
1 answer
8k views

My scenario I only have one class with two methods. In the first method I store values in a variable. In the second method I try to call these variables class UpdateTallysheet(Page): def ...
Rafael C.'s user avatar
  • 2,373
4 votes
1 answer
5k views

I want two class. Class A with a default class attribute and class B (child class) who override this class attribute. But if A class attribute definition is changed by developper, i don't want to ...
bux's user avatar
  • 7,711
3 votes
2 answers
2k views

How does the quality of my code gets affected if I don't use __init__ method in python? A simple example would be appreciated.
0 votes
2 answers
2k views

class Camera(object): def __init__(self, win, x=0.0, y=0.0, rot=0.0, zoom=1.0): self.win = win self.x = x self.y = y self.rot = rot self.zoom = zoom cam = ...
1 vote
2 answers
1k views

Just like the answer,I want to dynamic Load the database in the choicefield, and i had do this queue = forms.ChoiceField(label=u'queue',choices=((x.que,x.disr) for x in Queue.objects.all())) but it ...
1 vote
1 answer
1k views

While going through scapy source code (https://github.com/jwiegley/scapy), I came across the fact none of the Ether, IP, TCP, UDP or any other protocol classes contain any __init__ method, nor they ...
Soumen's user avatar
  • 1,088

15 30 50 per page
1
2 3