Is python module for global parameters good practice?

I am a mechanical student and I am building physical modeling with PyODE.

instead of running everything from a single file, I wanted to organize the material in modules, so I had:

  • main.py
  • callback.py
  • helper.py

I ran into problems when I realized that helper.py is needed to reference variables from main, but main was the only import helper!

so my solution was to create a 4th file that contains variables and only imports external modules (such as time and random).

so now i have:

  • main.py
  • callback.py
  • helper.py
  • parameters.py

and all scripts have: import parametersand use: parameters.fooor parameters.bar.

Is this an acceptable practice or is it a reliable way to make python programmers intimidating? :)

, , , !

, -Leav

+3
6

, . , , .

+1

"" , , , . , . . .

. , , , .:)

+3

, , , : ", helper.py main", " ", , .

+2

, , , . - ?

script , , -, - script.

if __name__ == '__main__':
    # Code that you want to run when the script is executed.
    # This block will not be executed if the script is imported.

Python .

0

You should probably read Dependency Inversion .

0
source

It looks like you want to organize various dependencies between the components. You will be better off expressing these dependencies in an object-oriented manner. Instead of doing this by importing modules and global states, encode these states in objects and pass them.

Reading objects and classes and writing them in Python; I would probably start there.

0
source

Source: https://habr.com/ru/post/1757905/


All Articles