[Tutor] Sharing data between modules

etrade.griffiths at dsl.pipex.com etrade.griffiths at dsl.pipex.com
Thu Oct 19 11:41:27 CEST 2006


Hi

just starting to get to grips with writing GUIs in Python using wxPython and 
not being a computer scientist, have a philosophical question about the "best" 
way to pass data between various modules.  For example, I anticipate having 
one module to look after the GUI stuff where users can input data (either from 
the keyboard or file), another to process the data and (probably) a third to 
display the calculation results.  Just not sure what the most efficient way of 
passing data between the various modules.  I can think of 4 ways to do this, 
of which 1 is not possible in Python (I think).

(1) via temp files: modules read to and write from temporary files
(2) via function arguments: data passed from one module to another via 
argument lists.  This seems the most logical but I have an irrational dislike 
of long argument lists.  Could pass data objects (eg. C type structs) or 
dictionaries via the argument list but I don't think this gets around 
the "problem" of long argument lists and we now need pack/unpack type 
functions.  Maybe this isn't a problem anyway?
(3) via globals: AFAIK this is not recommended so we will move swiftly on
(4) indirectly: thinking here of something along the FORTRAN COMMON blocks 
which (I think) Python doesn't have

So, looks like it's a choice between (1) and (2) - or have I missed something 
obvious?  What is the most "pythonic" way of doing this?  Thanks in advance 
for any suggestions


More information about the Tutor mailing list