r/pythonhelp • u/leo-g • Feb 23 '21
How do I structure my internal modules with multiple references?
I have a commonly used datetime chunk of code that just handles the current ISO datestamp in the country which I live in.
timestamp_now_iso_sgt = datetime.datetime.now(datetime.timezone(datetime.timedelta(hours=8))).isoformat()
Inside my custom logging module, I am referencing the current time stamp in a function. Inside my main application code, it is also referencing the current time stamp.
What should I do?
split off the timestamp code into its own module, and import it in the logging module and main app code?
split off the timestamp code and handle it in the the main app code when the custom logging functions are called? Eg. CustomLogging(loginput, mod_timestamp.now)
embed the timestamp code separately inside the module and main app code?
1
u/MT1961 Feb 23 '21
Things like this usually end up in a utils module and get imported and reused all over the place. It isn't a generic function, you are specifying the hours for the timedelta in there. So, I'd just make it a function.
1
u/sleepyleperchaun Feb 23 '21
RemindMe!