Running external module and accessing the created objects

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sat Mar 9 03:03:31 EST 2013


On Fri, 08 Mar 2013 22:06:28 -0500, Kene Meniru wrote:

> Program summary:
> 
> I have a module called user.py that imports another module called
> app.py. Functions in app.py are used in user.py to describe 3D objects.
> These objects are saved in another object described in doc.py.

What do you mean, "objects are saved in another object"?


> app.py contains a function called view(). When called in user.py, it
> signals the end of object descriptions. Presently all objects contained
> in doc.py are exported to either POV-Ray or OpenSCAD file format
> depending on the argument given to view().
> 
> My Issues:
> 
> I have decided I want to provide a preview of the objects using opengl
> (pyglet). So I am trying to create another module called appwin.py which
> the user can launch with user.py as an argument.

What happens if the user launches appwin with a different argument?

If appwin can only take one, compulsory, argument, then it's silly to 
require it as an argument. Just have appwin automatically import user.py, 
and do whatever it needs.


> When each object is
> described in user.py, I want the user to be able to switch to appwin.py,
> provide a signal that makes appwin.py redraw the screen to show any
> modifications (perhaps with the enter key).

This makes no sense to me. Are you saying that appwin opens a text editor 
that allows the user to edit the user.py source code?


> I do not want to invest much time with appwin.py now as I am still
> coding app.py. Right now, appwin.py just subclasses
> pyglet.window.Window().
> 
> I do not want to merge app.py and appwin.py. I want them to be two
> separate applications because I want to retain the option of either
> console or many different window interfaces.

Making them a single module still retains the option of console or many 
different window interfaces.


> The problem then is:
> 
> How can I run appwin.py which will then execute user.py to create the
> objects to be saved in doc.py. 

I don't know. How does user.py create the objects? Suppose it users a 
function called "create". Then you would do this in appwin:


import user
user.create()


> Then when view() is encountered to be
> able to access the objects stored in doc.py in appwin.py?

What do you mean by "view() is encounted"? 

How would you access the objects stored in doc.py? Suppose you access 
them using a list called "list_of_objects". Then in appwin.py:

import doc
for obj in doc.list_of_objects:
    do_something_with(obj)

where you have to write the function "do_something_with", to do whatever 
it is you want to do.


By the way, calling a module "doc" which is not for *documentation* is a 
bad idea.



-- 
Steven



More information about the Python-list mailing list