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.

Carlos Mermingas
  • 3,822
  • 2
  • 21
  • 40
  • 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](https://codereview.stackexchange.com/). Good luck! – Carlos Mermingas Nov 11 '18 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 '18 at 15:55
  • Thanks, I did not know it is possible. I am a bit reluctant to post 60 pages though ! – NewbieOneCannotBe Nov 11 '18 at 16:11
  • Daniel, I read it here : https://stackoverflow.com/questions/448271/what-is-init-py-for – NewbieOneCannotBe Nov 11 '18 at 16:14

0 Answers0