Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed3.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'interpreter': 0.05; 'dan': 0.09; 'exec': 0.09; 'friday,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:script': 0.09; 'subject:How': 0.10; 'python': 0.11; 'jan': 0.12; 'assume': 0.14; 'latter,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'statement.': 0.16; 'subject:run': 0.16; 'thanks,': 0.17; 'wrote:': 0.18; 'module': 0.19; '2001': 0.19; 'command': 0.22; 'import': 0.22; 'separate': 0.22; 'header:User- Agent:1': 0.23; 'script': 0.25; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'usually': 0.31; '3.x': 0.31; 'use?': 0.31; 'run': 0.32; 'subject:from': 0.34; 'subject:?': 0.36; 'should': 0.36; 'january': 0.37; 'to:addr :python-list': 0.38; 'received:71': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'received:org': 0.40; 'email addr:gmail.com': 0.63; 'within': 0.65; 'containing': 0.69; 'received:fios.verizon.net': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: How to run script from interpreter? Date: Wed, 28 May 2014 11:32:13 -0400 References: <6e96c4c4-17db-464b-b291-816c534b70c4@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-71-175-90-87.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 In-Reply-To: <6e96c4c4-17db-464b-b291-816c534b70c4@googlegroups.com> 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: 21 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1401291154 news.xs4all.nl 2868 [2001:888:2000:d::a6]:44294 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:72168 On 5/28/2014 3:44 AM, onlyvinish@gmail.com wrote: > On Friday, January 19, 2001 1:22:23 AM UTC+5:30, Rolander, Dan wrote: >> What is the best way to run a python script from within the interpreter? >> What command should I use? >> >> Thanks, >> Dan > > try using execfile(filename) or in 3.x with open(filename) as f: exec f These both assume that you want to run the script in the same process as the interpreter and within the module containing the statement. This is rare. People usually either want to import into a separate module or run in a separate process. For the latter, use the subprocess module and the same command line that you would use in a console. -- Terry Jan Reedy