I am writing a flask application, and I have found I have have ton of generic utility functions.
Here are the examples of the type of functions that I consider generic utility functions:
def make_hash():
return defaultdict(make_hash)
def file_read(filename):
with open(file_name_, 'r') as f:
return f.read()
def file_write(filename, data):
with open(filename, 'w') as f:
f.write(data)
I was thinking of tossing these functions into a separate module all together. However, I am curious if I have the following concerns:
- There are two few unique functions to warrant a separate module all together. i.e. the file_read, and file_write functions above could go into a file.py module, however since its two functions, I feel like this might be overkill.
- In my application I use these functions 2-3 times per function so I am moving under the guise they creating these utility functions should help me save some lines of code, and hopefully is making me more efficient.
Question: - What would be the pythonic way of grouping generic utility functions? Should I create a separate module? Curious what others are doing for organizing this type of code.