Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '2.7': 0.04; 'assign': 0.04; 'francis': 0.07; 'interpreter': 0.07; 'transform': 0.07; 'python': 0.08; 'file-like': 0.09; 'interpreter,': 0.09; 'python/c': 0.09; 'api': 0.09; 'output': 0.10; 'subject:python': 0.11; '3.2.': 0.16; 'received:192.168.1.40': 0.16; 'stderr.': 0.16; 'stdout': 0.16; 'wrote:': 0.16; '(most': 0.21; 'trying': 0.21; 'assume': 0.22; 'header:In-Reply-To:1': 0.22; 'division': 0.23; 'changed': 0.24; 'command': 0.24; "python's": 0.24; 'removed.': 0.24; 'traceback': 0.24; 'code': 0.25; 'statement': 0.25; "i'm": 0.27; 'function': 0.27; 'problem': 0.28; 'everyone,': 0.29; 'module': 0.30; 'objects': 0.32; 'does': 0.32; 'anyone': 0.32; 'there': 0.33; 'to:addr:python-list': 0.33; 'header:User- Agent:1': 0.34; 'normally': 0.34; 'elegant': 0.34; 'last):': 0.34; 'statement,': 0.34; 'thank': 0.35; 'file': 0.36; 'another': 0.37; 'executing': 0.37; 'communicate': 0.37; 'could': 0.38; 'allows': 0.38; 'some': 0.38; 'should': 0.38; 'subject:: ': 0.39; 'received:192': 0.39; 'i.e.': 0.39; 'either': 0.39; 'basic': 0.39; 'skip:z 10': 0.39; 'to:addr:python.org': 0.39; 'might': 0.40; 'entered': 0.40; 'more': 0.60; 'easily': 0.61; 'your': 0.61; 'custom': 0.61; 'our': 0.63; 'received:62': 0.70; 'from:addr:t': 0.84; 'replicate': 0.84 Date: Mon, 08 Aug 2011 17:31:38 +0200 From: Thomas Jollans User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:5.0) Gecko/20110628 Thunderbird/5.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Embedded python console and FILE* in python 3.2 References: In-Reply-To: X-Enigmail-Version: 1.2 OpenPGP: id=5C8691ED Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 55 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1312817513 news.xs4all.nl 23876 [2001:888:2000:d::a6]:36492 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:11035 On 08/08/11 17:17, Francis Labarre wrote: > Hello everyone, > > I'm currently trying to port some embedded code from python 2.7 to > python 3.2. > > The current code replicate the basic behavior of the python interpreter > in an > MFC application. When a command is entered in our embedded interpreter, > we write it to a FILE* then transform this FILE* into a Python file with > the api > function PyFile_FromFile and assign it to python's stdin. We also assign > another > FILE* as python's stdout and stderr. We then call PyRun_InteractiveOne > to execute > the statement as the python interpreter normally would. Finally, we > can easily retrieve > the result of the execution from the output FILE*. > > This is currently the only approach we have found that allows us to > retrieve the > result of executing a statement exactly as the interpreter would. > > The problem is that the implementation of files has changed in python 3 > and the function > PyFile_FromFile has been removed. > > Does anyone knows a way to achieve the same thing as this function > either trough the io module > or the python/C api? Or could there be a better approach to what we are > trying to achieve? > > Keep in mind that we need to obtain the result of any statement, i.e. : > > If the command is "2+2" the result should be "4", if the command is > "1/0" the result should be > > Traceback (most recent call last): > File "", line 1, in > ZeroDivisionError: division by zero > > > Thank you, > > F.L. > > I assume you could simply use PyFile_FromFd? The more elegant solution might be to create custom Python file-like objects for std{in,out,err} that communicate directly with your application. Thomas