Path: csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'output': 0.04; 'python': 0.09; 'namespace': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:module': 0.09; 'def': 0.10; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:accessing': 0.16; 'subject:created': 0.16; 'test()': 0.16; 'test():': 0.16; 'string': 0.17; 'module': 0.19; 'math': 0.20; 'question.': 0.20; 'skip:- 40': 0.21; 'import': 0.21; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.28; 'run': 0.28; 'question:': 0.29; 'summary': 0.29; 'skip:_ 10': 0.29; 'class': 0.29; 'print': 0.32; 'received:comcast.net': 0.33; 'to:addr:python-list': 0.33; 'another': 0.33; 'skip:d 20': 0.34; 'skip:: 10': 0.35; 'received:org': 0.36; 'execute': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'email addr:gmail.com': 0.63; 'header :Reply-To:1': 0.68; 'reply-to:no real name:2**0': 0.72; 'dic': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Kene Meniru Subject: Re: Running external module and accessing the created objects Followup-To: gmane.comp.python.general Date: Mon, 11 Mar 2013 19:57:28 -0400 Organization: illom.org References: <513aecd3$0$6512$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: c-68-49-243-100.hsd1.md.comcast.net User-Agent: KNode/4.4.7 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Kene.Meniru@illom.org 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: 42 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1363046277 news.xs4all.nl 6940 [2001:888:2000:d::a6]:42522 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:41098 Here's the answer to this question. The summary of the question: how to run a module (called myapp.py) from another module (called myappwin.py) and be able to access the namespace of myapp.py from myappwin.py. ------------------------------------------ # contents of myapp.py import math class MyApp(object): def __init__(self): super(MyApp, self).__init__() self.name = "MyAppName" def testFunction(): boke = "Smilling" print math.sin(1), boke ----------------------------------------- # contents of myappwin def test(): dic = {} execfile("myapp.py", dic) testObj = dic["MyApp"]() # access MyApp class dic["testFunction"]() # execute testFunction print testObj.name # print string test() ----------------------------------------- # OUTPUT $ python myappwin.py 0.841470984808 Smilling MyAppName -- Kene :::::::::::::::::: KeMeniru@gmail.com