Dec-30-2023, 03:27 PM
Hello everybody!
Im learning python by myself, so there are unknown "gaps" in my skill set..
Instead of trying to explain my overly complex and confusing project (that i use to teach myself python), i will use a hypothetical project.
I would like to use modular code, each "function/feature" in its own separate python-file(.py).
I have more than one feature that requires network (wlan).
I kind of prefer to have a separate python file for my network management, connecting/disconnecting the wifi from defined functions instead of having all of that code in my "main program.py".
so lets imagine we have "main.py", "wifi.py", "clock.py" and "foo.py".
The main.py program includes the clock and foo features and executes them using function calls.
We have included wifi.py in the clock.py program to implement network time synk.
Now, the foo.py also needs network stuff and would benefit from including the wifi.py projekt.
But im somewhat baffled and confused, how should i go about this, should i include wifi.py from two project.py-files, or should i write a new implementation in the new foo.py project?
Or could i pass the "wifi" object to the function as parameter, implementing wifi only once but in the main program instead?
Whats the "correct" / "pythonic" way of solving such programmatical "issues"?
Thank you for your time,
/liggisten
Im learning python by myself, so there are unknown "gaps" in my skill set..
Instead of trying to explain my overly complex and confusing project (that i use to teach myself python), i will use a hypothetical project.
I would like to use modular code, each "function/feature" in its own separate python-file(.py).
I have more than one feature that requires network (wlan).
I kind of prefer to have a separate python file for my network management, connecting/disconnecting the wifi from defined functions instead of having all of that code in my "main program.py".
so lets imagine we have "main.py", "wifi.py", "clock.py" and "foo.py".
The main.py program includes the clock and foo features and executes them using function calls.
We have included wifi.py in the clock.py program to implement network time synk.
Now, the foo.py also needs network stuff and would benefit from including the wifi.py projekt.
But im somewhat baffled and confused, how should i go about this, should i include wifi.py from two project.py-files, or should i write a new implementation in the new foo.py project?
Or could i pass the "wifi" object to the function as parameter, implementing wifi only once but in the main program instead?
Whats the "correct" / "pythonic" way of solving such programmatical "issues"?
Thank you for your time,
/liggisten