[Chicago] When to load?

Leon Shernoff leon at mushroomthejournal.com
Mon Feb 1 11:13:51 EST 2016


Hello,

I have a modularity design question. I am writing a program that, as it 
goes along, calls a text-parsing routine. In fact, the main program is a 
scraping program (or pseudo-scraping -- it will also run on a collection 
of text files) that runs this parsing routine in a loop over many 
pages/files.

The parsing routine calls various other subroutines, so I'd like to put 
the whole set of them in a separate file that gets imported by the main 
program. The parsing program uses several dictionaries of terms, and as 
it processes more and more texts it adds more terms to those 
dictionaries and they get stored in a database that is read at launch to 
construct the dictionaries. So the dictionaries are a bit expensive to 
generate and I'd like to have to construct them only once.

So, I'm unclear on the persistence here (experienced developer, pretty 
new to Python):

1) If I put the database-read dictionary-construction code in the 
parser's file, will those get run (and the dictionaries reconstructed) 
each time the main program uses the parser?

2) If so, do I need to construct the dictionaries in the main program 
and pass them to the parser each time I invoke it? That would make for 
several parameters, all of which would be the same each time except for 
the text to be parsed. This may be one of those things that's more 
annoying to humans than it is to machines; but if the whole point of 
sequestering the parse routines in a separate file is to make my main 
program look cleaner and understand, it is kind of backwards to do that 
and then issue ugly, cluttered calls to those routines. :-)

3) Is there a better way? (or is #1 just not a problem and they only get 
constructed once) (Please, please...)  :-)

-- 
Best regards,
     Leon

"Creative work defines itself; therefore, confront the work."
      -- John Cage


Leon Shernoff
1511 E 54th St, Bsmt
Chicago, IL  60615

(312) 320-2190



More information about the Chicago mailing list