I'm new to Python and I'm writing my first script. I'm adopting a procedural approach (for now) so the script is just a big collection of functions. Since it's getting quite big I want to split it into smaller source files.
I've adopted this tecnique where prj is the name of the project:
1) I've split the main file into smaller ones. Each file imports the needed modules for itself. Each file looks like this
# -*- coding: utf-8 -*-
import os
import sys
import json
import timelib
# code follows...
2) I've put all the files in a subdirectory called prj_submodules
3) I've named each file with this pattern:
prj_globals.py
prj_database_and_logic.py
prj_configuration.py
...
4) One level up of prj_submodules I've the main script prj.py that include all:
# -*- coding: utf-8 -*-
import sys
sys.path.append('prj_submodules')
from prj_configuration import *
from prj_globals import *
from prj_database_and_logic import *
from prj_repository_and_rendering import *
from prj_filesystem import *
from prj_tools import *
from prj_packing_and_resolution import *
from prj_paths import *
from prj_errors import *
from prj_test import *
I've prepended prj_ to each filename and to the splitted-files directory to avoid naming conflicts with existing modules.
UPDATE:
It works but I'd like to know if it's the proper way to do it, if there are better way to accomplish the same...
No, it doesn't work (or either there is an error somewhere). It seem functions in one module doesn't see as defined functions in other modules and thus cannot call each other.