Linked Questions
34 questions linked to/from Why do we use __init__ in Python classes?
982
votes
18
answers
1.6m
views
What do __init__ and self do in Python? [duplicate]
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 ...
24
votes
3
answers
28k
views
What does object's __init__() method do in python? [duplicate]
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
Is __init__ always required? [duplicate]
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 ...
-3
votes
2
answers
6k
views
What is the purpose of _init_()? [duplicate]
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 ...
-1
votes
1
answer
2k
views
What does __init__(self) mean in Python? [duplicate]
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.
1
vote
1
answer
752
views
What does the __init__ method serve for? [duplicate]
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
What do parenthesis do in Python? [duplicate]
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
what is ` __init__()` in a python class [duplicate]
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
How do I determine what to put inside the __init__ function in a python class?
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 ...
1
vote
1
answer
8k
views
Calling a variable from another method in the same class [duplicate]
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 ...
4
votes
1
answer
5k
views
Class attribute overriding: keep parent class changes
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
What happens when your class does not explicitly define an __init__ method?
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
Python class parameters, where to define
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
How to dynamic loading the field of ChoiceField in form using the database in Django?
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
Class initialization without __init__ method
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 ...