Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #42276

dir() vs print(dir()) in the embedded mode

Date 2013-03-29 16:04 -0500
From Nick Gnedin <ngnedin@gmail.com>
Subject dir() vs print(dir()) in the embedded mode
Newsgroups comp.lang.python
Message-ID <mailman.3964.1364591074.2939.python-list@python.org> (permalink)

Show all headers | View raw


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 <Python.h>

int main()
{
   Py_Initialize();
   PyRun_SimpleString("dir()");
   printf("-----\n");
   PyRun_SimpleString("print(dir())");
   Py_Finalize();

   return 0;
}

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

dir() vs print(dir()) in the embedded mode Nick Gnedin <ngnedin@gmail.com> - 2013-03-29 16:04 -0500
  Re: dir() vs print(dir()) in the embedded mode Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-29 22:16 +0000
  Re: dir() vs print(dir()) in the embedded mode rusi <rustompmody@gmail.com> - 2013-03-29 22:52 -0700

csiph-web