Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder1.xlned.com!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.009 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'interpreter': 0.05; 'newbie': 0.05; 'output': 0.05; '#include': 0.09; 'main()': 0.09; 'python': 0.11; 'differs': 0.16; 'folks,': 0.16; 'illustrates': 0.16; 'nick': 0.16; 'user?': 0.16; 'trying': 0.19; '(the': 0.22; 'example': 0.22; 'header:User-Agent:1': 0.23; 'skip:p 30': 0.29; 'mode': 0.30; 'code': 0.31; 'embed': 0.31; 'question:': 0.31; 'noticed': 0.34; 'subject:the': 0.34; 'display': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'thanks': 0.36; 'list': 0.37; 'message-id:@gmail.com': 0.38; 'to:addr:python- list': 0.38; 'that,': 0.38; 'does': 0.39; 'embedded': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'future': 0.60; 'first': 0.61; 'here': 0.66; 'behavior': 0.77; 'around,': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:message-id:date:from:user-agent:mime-version:to:subject :content-type:content-transfer-encoding; bh=rTpIa8AZ9WTbvsL72NWGI+Fvy2/fvtu3nfxNjqkmZP8=; b=SHNd4Nv7Zw0t+KUSaGZdH6xConFL8xVPfAlkMU/Df3eemejrqhDR0MhkagGO+dvKTk XXHQH/biovHTWMBo0x5VfyPFZMo3/MB1WXSNrFFswaiBaEtVuFzpx8NiSZZD2Z0XLtoS matSwNkgS9ah969ExivAEwQqTCNXRhoVB2cFGi0S+lXNVNibLTczOCQw0FPPe9Hyy/zY sLRzcqjZOvtbvRxoGNVEOenjyMsG7tjgIiTqgmZOoNnfJ5iR9l1fM2DQINeJdLuUh4VP YpSk5F/+G9lNDGCJ4mmzQVfuLg3nvXyHmDecBAibjR2ZDDlJ+Udf0PtV89wF4NEb5wFE cPnQ== X-Received: by 10.50.12.133 with SMTP id y5mr25542igb.108.1364591066061; Fri, 29 Mar 2013 14:04:26 -0700 (PDT) Date: Fri, 29 Mar 2013 16:04:24 -0500 From: Nick Gnedin User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130311 Thunderbird/17.0.3 MIME-Version: 1.0 To: python-list@python.org Subject: dir() vs print(dir()) in the embedded mode Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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: 34 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1364591074 news.xs4all.nl 6858 [2001:888:2000:d::a6]:48011 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:42276 Folks, I have a newbie question: I am trying to embed Python into my application. While playing around, I noticed that the behavior of the interpreter in the embedded mode differs from the standalone one. Namely, in the standalone mode if I type dir(), I get a list of build-in symbols. In the embedded mode only print(dir()) does that, while just dir() returns silently. Is there a way to intercept the output of dir() (and all other commands) and display them to the user? Here is an example code that illustrates the behavior (the first call to PyRun_SimpleString() returns silently). Many thanks for your future hints, Nick #include int main() { Py_Initialize(); PyRun_SimpleString("dir()"); printf("-----\n"); PyRun_SimpleString("print(dir())"); Py_Finalize(); return 0; }