__init__.py and proper initialization
I created a "project" with Spyder and wrote a few classes that I stored into separate files (I would call the files "module" but I am not sure it is the proper way to call it).
I read that the __init__.py
file is meant to avoid unwanted overwriting of names.
Is it a proper way to program in Python if I use __init__.py
to initialize things for all my "modules": define constants (eg. debug level), "calculated" values (eg. system encoding), imports, start a global debugging function (tuned for my needs), etc. ?
In other words: What is the best way to do the initialization?
- Leave
__init__.py
empty and initialize my values in another "module" which will be called a/ at the beginning of each "module" or b/ by each one of the__init__()
of the classes? - If I use
__init__.py
and import it in every "module" for initialization, Spyder warns because I don't use it explicitly: I am actually doing something wrong or should I ignore the warning? - Should I put the definition of constants in a
Config.ini
file and get it throughconfigparser.ConfigParser()
? or just define it directly in the initialization module (__init__.py
or another) ?
Thanks in advance for your insights.
Pierre.
python initialization
add a comment |
I created a "project" with Spyder and wrote a few classes that I stored into separate files (I would call the files "module" but I am not sure it is the proper way to call it).
I read that the __init__.py
file is meant to avoid unwanted overwriting of names.
Is it a proper way to program in Python if I use __init__.py
to initialize things for all my "modules": define constants (eg. debug level), "calculated" values (eg. system encoding), imports, start a global debugging function (tuned for my needs), etc. ?
In other words: What is the best way to do the initialization?
- Leave
__init__.py
empty and initialize my values in another "module" which will be called a/ at the beginning of each "module" or b/ by each one of the__init__()
of the classes? - If I use
__init__.py
and import it in every "module" for initialization, Spyder warns because I don't use it explicitly: I am actually doing something wrong or should I ignore the warning? - Should I put the definition of constants in a
Config.ini
file and get it throughconfigparser.ConfigParser()
? or just define it directly in the initialization module (__init__.py
or another) ?
Thanks in advance for your insights.
Pierre.
python initialization
Hi Pierre. I think that this question will be difficult to answer here because "the best" way to do initialization will depend on your project's needs. You may get better feedback posting the code for one of your approaches at a time at Code Review. Good luck!
– Carlos Mermingas
Nov 11 at 15:51
I have never heard of init.py being meant "to avoid unwanted overwriting of names". Where did you read that? What exactly do you mean by it?
– Daniel Roseman
Nov 11 at 15:55
Thanks, I did not know it is possible. I am a bit reluctant to post 60 pages though !
– NewbieOneCannotBe
Nov 11 at 16:11
Daniel, I read it here : stackoverflow.com/questions/448271/what-is-init-py-for
– NewbieOneCannotBe
Nov 11 at 16:14
add a comment |
I created a "project" with Spyder and wrote a few classes that I stored into separate files (I would call the files "module" but I am not sure it is the proper way to call it).
I read that the __init__.py
file is meant to avoid unwanted overwriting of names.
Is it a proper way to program in Python if I use __init__.py
to initialize things for all my "modules": define constants (eg. debug level), "calculated" values (eg. system encoding), imports, start a global debugging function (tuned for my needs), etc. ?
In other words: What is the best way to do the initialization?
- Leave
__init__.py
empty and initialize my values in another "module" which will be called a/ at the beginning of each "module" or b/ by each one of the__init__()
of the classes? - If I use
__init__.py
and import it in every "module" for initialization, Spyder warns because I don't use it explicitly: I am actually doing something wrong or should I ignore the warning? - Should I put the definition of constants in a
Config.ini
file and get it throughconfigparser.ConfigParser()
? or just define it directly in the initialization module (__init__.py
or another) ?
Thanks in advance for your insights.
Pierre.
python initialization
I created a "project" with Spyder and wrote a few classes that I stored into separate files (I would call the files "module" but I am not sure it is the proper way to call it).
I read that the __init__.py
file is meant to avoid unwanted overwriting of names.
Is it a proper way to program in Python if I use __init__.py
to initialize things for all my "modules": define constants (eg. debug level), "calculated" values (eg. system encoding), imports, start a global debugging function (tuned for my needs), etc. ?
In other words: What is the best way to do the initialization?
- Leave
__init__.py
empty and initialize my values in another "module" which will be called a/ at the beginning of each "module" or b/ by each one of the__init__()
of the classes? - If I use
__init__.py
and import it in every "module" for initialization, Spyder warns because I don't use it explicitly: I am actually doing something wrong or should I ignore the warning? - Should I put the definition of constants in a
Config.ini
file and get it throughconfigparser.ConfigParser()
? or just define it directly in the initialization module (__init__.py
or another) ?
Thanks in advance for your insights.
Pierre.
python initialization
python initialization
edited Nov 11 at 15:42
Carlos Mermingas
2,25221129
2,25221129
asked Nov 11 at 15:37
NewbieOneCannotBe
61
61
Hi Pierre. I think that this question will be difficult to answer here because "the best" way to do initialization will depend on your project's needs. You may get better feedback posting the code for one of your approaches at a time at Code Review. Good luck!
– Carlos Mermingas
Nov 11 at 15:51
I have never heard of init.py being meant "to avoid unwanted overwriting of names". Where did you read that? What exactly do you mean by it?
– Daniel Roseman
Nov 11 at 15:55
Thanks, I did not know it is possible. I am a bit reluctant to post 60 pages though !
– NewbieOneCannotBe
Nov 11 at 16:11
Daniel, I read it here : stackoverflow.com/questions/448271/what-is-init-py-for
– NewbieOneCannotBe
Nov 11 at 16:14
add a comment |
Hi Pierre. I think that this question will be difficult to answer here because "the best" way to do initialization will depend on your project's needs. You may get better feedback posting the code for one of your approaches at a time at Code Review. Good luck!
– Carlos Mermingas
Nov 11 at 15:51
I have never heard of init.py being meant "to avoid unwanted overwriting of names". Where did you read that? What exactly do you mean by it?
– Daniel Roseman
Nov 11 at 15:55
Thanks, I did not know it is possible. I am a bit reluctant to post 60 pages though !
– NewbieOneCannotBe
Nov 11 at 16:11
Daniel, I read it here : stackoverflow.com/questions/448271/what-is-init-py-for
– NewbieOneCannotBe
Nov 11 at 16:14
Hi Pierre. I think that this question will be difficult to answer here because "the best" way to do initialization will depend on your project's needs. You may get better feedback posting the code for one of your approaches at a time at Code Review. Good luck!
– Carlos Mermingas
Nov 11 at 15:51
Hi Pierre. I think that this question will be difficult to answer here because "the best" way to do initialization will depend on your project's needs. You may get better feedback posting the code for one of your approaches at a time at Code Review. Good luck!
– Carlos Mermingas
Nov 11 at 15:51
I have never heard of init.py being meant "to avoid unwanted overwriting of names". Where did you read that? What exactly do you mean by it?
– Daniel Roseman
Nov 11 at 15:55
I have never heard of init.py being meant "to avoid unwanted overwriting of names". Where did you read that? What exactly do you mean by it?
– Daniel Roseman
Nov 11 at 15:55
Thanks, I did not know it is possible. I am a bit reluctant to post 60 pages though !
– NewbieOneCannotBe
Nov 11 at 16:11
Thanks, I did not know it is possible. I am a bit reluctant to post 60 pages though !
– NewbieOneCannotBe
Nov 11 at 16:11
Daniel, I read it here : stackoverflow.com/questions/448271/what-is-init-py-for
– NewbieOneCannotBe
Nov 11 at 16:14
Daniel, I read it here : stackoverflow.com/questions/448271/what-is-init-py-for
– NewbieOneCannotBe
Nov 11 at 16:14
add a comment |
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53250302%2finit-py-and-proper-initialization%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53250302%2finit-py-and-proper-initialization%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Hi Pierre. I think that this question will be difficult to answer here because "the best" way to do initialization will depend on your project's needs. You may get better feedback posting the code for one of your approaches at a time at Code Review. Good luck!
– Carlos Mermingas
Nov 11 at 15:51
I have never heard of init.py being meant "to avoid unwanted overwriting of names". Where did you read that? What exactly do you mean by it?
– Daniel Roseman
Nov 11 at 15:55
Thanks, I did not know it is possible. I am a bit reluctant to post 60 pages though !
– NewbieOneCannotBe
Nov 11 at 16:11
Daniel, I read it here : stackoverflow.com/questions/448271/what-is-init-py-for
– NewbieOneCannotBe
Nov 11 at 16:14