Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.009 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'sys': 0.05; 'mentioned,': 0.07; 'imported': 0.09; 'imports': 0.09; 'objects.': 0.09; 'subject:module': 0.09; 'stored': 0.10; "hasn't": 0.15; 'dictionary.': 0.16; 'framework,': 0.16; 'globals.': 0.16; 'subject:accessing': 0.16; 'subject:created': 0.16; 'wrote:': 0.17; 'script.': 0.17; 'module': 0.19; 'import': 0.21; 'doc': 0.22; 'defined': 0.22; 'seems': 0.23; 'tried': 0.25; 'header:In- Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'library.': 0.27; 'module.': 0.27; 'run': 0.28; 'dictionary': 0.29; 'objects': 0.29; 'class': 0.29; 'problem': 0.33; 'to:addr:python-list': 0.33; 'another': 0.33; 'pm,': 0.35; 'modules': 0.36; 'execute': 0.37; 'two': 0.37; 'uses': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'called': 0.39; 'received:192.168': 0.40; 'your': 0.60; 'most': 0.61; 'save': 0.61; 'strange': 0.62; 'dangerous': 0.66; 'received:74.208': 0.71; 'special': 0.73; 'received:74.208.4.194': 0.84; 'dozens': 0.91; 'angel': 0.93 Date: Mon, 11 Mar 2013 22:16:17 -0400 From: Dave Angel User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130221 Thunderbird/17.0.3 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Running external module and accessing the created objects References: <513aecd3$0$6512$c3e8da3$5496439d@news.astraweb.com> <513E7B6B.5070608@davea.name> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:ym/QW5LH0HhScj+cZe9/ZcZwsXkLkOL6JglB0CylEKR 4H6A/JJ/s81Kpa07w414Ow+B0ldBF7ceLGQN/MICxP5cAIfS3+ GeneTf9Ve+TodeBci0w6SdpEvaQpVaEMXcihzzRkdJXxDsgokF mgWn9oFrKkxftWyKohCCQ+MBLwDKwkRAXbkBH+sbwk0ujoP2ei fqpHvi5UPyumT2PDBIQ5wIrGGvpEwiilVtL5ycWJNaw6A5hvSR kpRekKDW/4Q0/wouCktIXKlDiR4wpzXPmFoiC8uWEyvwU5gNL+ 6o2Wav5lvxzMoEy2VM7kFJm7D5C4g8KmFM819Ky1ewvkJs0Eg= = X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 40 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1363054599 news.xs4all.nl 6840 [2001:888:2000:d::a6]:47435 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:41105 On 03/11/2013 09:58 PM, Kene Meniru wrote: > Dave Angel wrote: > >> On 03/11/2013 07:57 PM, Kene Meniru wrote: > >> >> I hope you're just kidding. execfile() and exec() are two of the most >> dangerous mechanisms around. import or __import__() would be much >> better, as long as your user hasn't already run myapp.py as his script. >> > > Tried __import__ and it seems to execute the myapp.py just like execfile > however it only provides access to objects defined in the module myapp.py > only. Like I mentioned, my program has multiple packages and the objects > myappwin needs access to are stored in an object in another module called > doc.py. > > - myapp.py provides the functions used to describe 3D objects > - app.py is imported into myapp.py and is called by the functions after they > create the 3D objects. > - app.py uses another module called doc.py which app.py imports to save the > objects in a class with a dictionary. > - myappwin needs to access the dictionary in the class inside the doc > module. > If you need access to modules in your own framework, then import them yourself. You don't need any strange indirection through the myapp.py module. It's because you said that name was arbitrary and would change from run to run that we had to special case it. Same as you do with sys module in the standard library. It may get imported from dozens of places, and as long as they all import it by simple import sys there's no special problem accessing its globals. -- DaveA