Questions tagged [init]

May refer to Linux init, an abbreviation of initialization - giving variables a "starting" value, or Python's __init__ class initiation method.

May refer to :

  • Linux Init - the parent of all processes, which primary role is to create processes from a script stored in the file /etc/inittab.
  • variable init (abbreviation of initialization) - giving variables a "starting" value.
  • python magic __init__ - magic function that initializes an object.
1905 questions
832
votes
21 answers

How to fix "Attempted relative import in non-package" even with __init__.py

I'm trying to follow PEP 328, with the following directory structure: pkg/ __init__.py components/ core.py __init__.py tests/ core_test.py __init__.py In core_test.py I have the following import statement from…
skytreader
  • 11,467
  • 7
  • 43
  • 61
525
votes
11 answers

When is the init() function run?

I've tried to find a precise explanation of what the init() function does in Go. I read what Effective Go says but I was unsure if I understood fully what it said. The exact sentence I am unsure is the following: And finally means finally: init is…
Charlie Parker
  • 5,884
  • 57
  • 198
  • 323
183
votes
4 answers

Can I use __init__.py to define global variables?

I want to define a constant that should be available in all of the submodules of a package. I've thought that the best place would be in in the __init__.py file of the root package. But I don't know how to do this. Suppose I have a few subpackages…
Andrei Vajna II
  • 4,642
  • 5
  • 35
  • 38
166
votes
9 answers

In Objective-C why should I check if self = [super init] is not nil?

I have a general question about writing init methods in Objective-C. I see it everywhere (Apple's code, books, open source code, etc.) that an init method should check if self = [super init] is not nil before continuing with initialisation. The…
Jasarien
  • 58,279
  • 31
  • 157
  • 188
161
votes
13 answers

How to return a value from __init__ in Python?

I have a class with an __init__ function. How can I return an integer value from this function when an object is created? I wrote a program, where __init__ does command line parsing and I need to have some value set. Is it OK set it in global…
webminal.org
  • 44,948
  • 37
  • 94
  • 125
154
votes
5 answers

git add all except ignoring files in .gitignore file

I am adding source control to a project that had none. The problem is that there are a lot of files to initially add to git with a .gitignore file, but I can't figure out how to add all files without including the files matching something in the…
E-rich
  • 9,243
  • 11
  • 48
  • 79
129
votes
5 answers

Inheritance and init method in Python

I'm begginer of python. I can't understand inheritance and __init__(). class Num: def __init__(self,num): self.n1 = num class Num2(Num): def show(self): print self.n1 mynumber = Num2(8) mynumber.show() RESULT: 8 This is…
Yugo Kamo
  • 2,349
  • 4
  • 18
  • 13
91
votes
4 answers

What is the use of the init() usage in JavaScript?

What is the meaning and usage of the init() function in JavaScript?
David S.
  • 933
  • 1
  • 7
  • 6
81
votes
7 answers

Python: Inherit the superclass __init__

I have a base class with a lot of __init__ arguments: class BaseClass(object): def __init__(self, a, b, c, d, e, f, ...): self._a=a+b self._b=b if b else a ... All the inheriting classes should run __init__ method of the…
Adam Matan
  • 128,757
  • 147
  • 397
  • 562
78
votes
16 answers

git add . -> still "nothing to commit" with new files

I am struggling with Git, I can't seem to add my files. I ran ls to show that the files are in the current directory, then ran git add . then git status which showed "nothing to commit". JJ-Computer:first_app JJ$ git init Reinitialized existing…
RandyMy
  • 1,013
  • 1
  • 8
  • 9
77
votes
2 answers

Objective-C: init vs initialize

In Objective-C, what is the difference between the init method (i.e. the designated initializer for a class) and the initialize method? What initialization code should be put in each?
jrdioko
  • 32,230
  • 28
  • 81
  • 120
72
votes
3 answers

What is the difference between [Class new] and [[Class alloc] init] in iOS?

Possible Duplicate: alloc, init, and new in Objective-C I am a little confused about [Class new] and [[Class alloc] init]. I have defined an object content using [Class new] and [[Class alloc] init]. (1). NSMutableArray *content =…
Prasad G
  • 6,702
  • 7
  • 42
  • 65
71
votes
1 answer

How critical is dumb-init for Docker?

I hope that this question will not be marked as primarily opinion-based, but that there is an objective answer to it. I have read Introducing dumb-init, an init system for Docker containers, which extensively describes why and how to use dumb-init.…
Golo Roden
  • 140,679
  • 96
  • 298
  • 425
71
votes
8 answers

Guice call init method after instantinating an object

Is it possible to tell Guice to call some method (i.e. init()) after instantinating an object of given type? I look for functionality similar to @PostConstruct annotation in EJB 3 (and Spring).
mgamer
  • 13,580
  • 25
  • 87
  • 145
67
votes
3 answers

Property initializers run before 'self' is available

Seems like I'm having a problem with something that shouldn't be the case... But I would like to ask for some help. There are some explanations here on the Stack I don't get. Having two simple classes where one refers to another, as per below: class…
RafalK
  • 749
  • 2
  • 7
  • 13
1
2 3
99 100