Questions tagged [init]

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. Or abbreviation of initialization - giving variables a "starting" value.

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.
1654 questions
772
votes
20 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
  • 10,673
  • 5
  • 39
  • 57
401
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
  • 13,522
  • 35
  • 118
  • 206
165
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
  • 57,071
  • 27
  • 154
  • 186
144
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
  • 3,924
  • 5
  • 34
  • 36
128
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
  • 8,247
  • 11
  • 43
  • 71
115
votes
11 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
  • 37,814
  • 34
  • 84
  • 122
105
votes
4 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
  • 1,969
  • 4
  • 16
  • 13
82
votes
3 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.
  • 843
  • 1
  • 7
  • 6
76
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
  • 28,317
  • 26
  • 75
  • 116
72
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
  • 107,447
  • 124
  • 346
  • 512
71
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,474
  • 7
  • 39
  • 65
66
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.
mgamer
  • 12,296
  • 23
  • 84
  • 142
66
votes
12 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
  • 843
  • 1
  • 6
  • 8
51
votes
5 answers

Is there any reason to choose __new__ over __init__ when defining a metaclass?

I've always set up metaclasses something like this: class SomeMetaClass(type): def __new__(cls, name, bases, dict): #do stuff here But I just came across a metaclass that was defined like this: class SomeMetaClass(type): def…
Jason Baker
  • 171,942
  • 122
  • 354
  • 501
49
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
  • 112,924
  • 78
  • 260
  • 376
1
2 3
99 100