[EMAIL PROTECTED] wrote:
> 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

I can't think of any reason to do this for in-process communication. You 
still have to marshall and unmarshall the values, you might as well just 
pass around lists or some other structure.

> (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?

This is the best way. Well designed objects can help a lot with avoiding 
long argument lists. The key is to make objects that have functionality, 
they are more than just data containers but include the operations on 
the data.

For repeating data use lists.

> (3) via globals: AFAIK this is not recommended so we will move swiftly on

Only if there is no alternative.

> (4) indirectly: thinking here of something along the FORTRAN COMMON blocks 
> which (I think) Python doesn't have

You can use a module as a shared namespace. This sometimes makes sense 
for configuration data that is shared and doesn't change much. I 
wouldn't use it as a general argument passing mechanism, it has all the 
disadvantages of globals.
> 
> 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

(2)

Kent

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to