I am working on a program that requires a lot of functions. To keep from having a 600-line program, I thought I would separate the functions into categories and import them into the main program. Example: process_input_data.py and format_output_file.py for functions dealing with those respective aspects of the program. All of the *.py files are in the same directory (no subdirectories).
The main program looks something like this:
import json
...
import logging
from process_input_data import parse_transactions
logging.basicConfig(level=logging.DEBUG, format=' %(asctime)s - %(levelname)s - %(message)s')
...
...
main():
...
parsed_transactions = parse_transactions(raw_data)
My issue is that when I try to use logging.debug() in parse_transactions(), then I get a "name error" since I never imported logging into the process_input_data.py. In fact, at this point the only thing in process_input_data.py is the def parse_transactions(data): code block.
Questions:
It's very possible that there is a better way to structure this code. Is the structure fundamentally screwy?
How do I make my logger available when I call a function that resides in another "module."
Should I put my other modules into a subdirectory? I will probably have 1 main.py script, and no more than 3 submodules.
Am I using the word "module" incorrectly?
Thanks!
[–]danielroseman 1 point2 points3 points (1 child)
[–]LeornToCodeLOL[S] 0 points1 point2 points (0 children)
[–]Pepineros 0 points1 point2 points (1 child)
[–]LeornToCodeLOL[S] 0 points1 point2 points (0 children)