To avoid
How python imports modules
Initializing expensive objects on module level
If def calculate
is needed in another file and imported there, load data is run when
the function is imported. Best avoided by putting all logic into functions.
# calculate.py
from time import sleep
def load_data(count: int = 3):
sleep(count)
return []
data = load_data(2)
def transform():
return (entry["id"] for entry in data)
Import *
This is a pattern should be avoided because:
- It imports everything when most of the time just certain objects are needed
- It is not transparent what objects were imported
Letztes Update:
June 27, 2022
Erstellt: June 27, 2022
Erstellt: June 27, 2022