__init__.py and proper initialization










0














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?



  1. 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?

  2. 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?

  3. Should I put the definition of constants in a Config.ini file and get it through configparser.ConfigParser()? or just define it directly in the initialization module (__init__.py or another) ?

Thanks in advance for your insights.



Pierre.










share|improve this question























  • 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















0














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?



  1. 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?

  2. 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?

  3. Should I put the definition of constants in a Config.ini file and get it through configparser.ConfigParser()? or just define it directly in the initialization module (__init__.py or another) ?

Thanks in advance for your insights.



Pierre.










share|improve this question























  • 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













0












0








0







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?



  1. 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?

  2. 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?

  3. Should I put the definition of constants in a Config.ini file and get it through configparser.ConfigParser()? or just define it directly in the initialization module (__init__.py or another) ?

Thanks in advance for your insights.



Pierre.










share|improve this question















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?



  1. 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?

  2. 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?

  3. Should I put the definition of constants in a Config.ini file and get it through configparser.ConfigParser()? or just define it directly in the initialization module (__init__.py or another) ?

Thanks in advance for your insights.



Pierre.







python initialization






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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
















  • 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

















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
);



);













draft saved

draft discarded


















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















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo