r/pythonhelp • • 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?

  1. split off the timestamp code into its own module, and import it in the logging module and main app code?

  2. 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)

  3. embed the timestamp code separately inside the module and main app code?

2 Upvotes

3 comments sorted by

1

u/sleepyleperchaun Feb 23 '21

RemindMe!

1

u/RemindMeBot Feb 23 '21

Defaulted to one day.

I will be messaging you on 2021-02-24 10:07:17 UTC to remind you of this link

CLICK THIS LINK to send a PM to also be reminded and to reduce spam.

Parent commenter can delete this message to hide from others.


InfoCustomYour RemindersFeedback

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.