Changing interpreter's deafult output/error streams

I

Ira

Hi,

Using an embedded interpreter, how do I change it's default output streams
(specifically the one used by PyErr_Print() which I'm guessing is the
default error stream)?

Cheers,
Ira
 
M

Michael Hudson

Ira said:
Using an embedded interpreter, how do I change it's default output
streams (specifically the one used by PyErr_Print() which I'm
guessing is the default error stream)?

It looks as though it writes to stderr unconditionally. But most of
the reasons for ended up in PyErr_Print can be intercepted at a higher
level (I think -- I mean sys.excepthook & co here).

Cheers,
mwh
 
I

Ira

OK let me rephrase,

the standard error stream (and if I'm not mistaken also the one that
PyErr_Print() writes to) is the python object sys.stderr. Now say I'd go
ahead and write the following in python...

SomeNewStreamOrFileOrWhateverItIs = new stream
sys.stderr = SomeNewStreamOrFileOrWhateverItIs

I can go ahead and do the exact same thing from the C source code. All I
need to do is to figure out how to wrap a c-style FILE* with a PyObject, And
PySys_SetObjet("stderr", newstream);

I'm very new to python so that might be nonsense but it appeals to my
programmer's common sense. Can anyone tell me how to do this?
 
I

Ira

OK let me rephrase,

the standard error stream (and if I'm not mistaken also the one that
PyErr_Print() writes to) is the python object sys.stderr. Now say I'd go
ahead and write the following in python...

SomeNewStreamOrFileOrWhateverItIs = new stream
sys.stderr = SomeNewStreamOrFileOrWhateverItIs

I can go ahead and do the exact same thing from the C source code. All I
need to do is to figure out how to wrap a c-style FILE* with a PyObject, And
PySys_SetObjet("stderr", newstream);

I'm very new to python so that might be nonsense but it appeals to my
programmer's common sense. Can anyone tell me how to do this?
 
R

Robert Kern

Ira said:
OK let me rephrase,

the standard error stream (and if I'm not mistaken also the one that
PyErr_Print() writes to) is the python object sys.stderr. Now say I'd go
ahead and write the following in python...

SomeNewStreamOrFileOrWhateverItIs = new stream
sys.stderr = SomeNewStreamOrFileOrWhateverItIs

I can go ahead and do the exact same thing from the C source code. All I
need to do is to figure out how to wrap a c-style FILE* with a PyObject, And
PySys_SetObjet("stderr", newstream);

I'm very new to python so that might be nonsense but it appeals to my
programmer's common sense. Can anyone tell me how to do this?

http://docs.python.org/api/fileObjects.html

--
Robert Kern
(e-mail address removed)

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
 
M

Michael Hudson

Ira said:
OK let me rephrase,

the standard error stream (and if I'm not mistaken also the one that
PyErr_Print() writes to) is the python object sys.stderr. Now say I'd go
ahead and write the following in python...

Ah, OK, I think you're mistaken, and PyErr_Print prints to the C level
FILE* stderr (I agree my first post was confusing on this point, sorry
about that...).

Cheers,
mwh
 
R

Robert Kern

Michael said:
Ah, OK, I think you're mistaken, and PyErr_Print prints to the C level
FILE* stderr (I agree my first post was confusing on this point, sorry
about that...).

No, it doesn't. It grabs the appropriate object from sys.stderr.

--
Robert Kern
(e-mail address removed)

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
 
M

Michael Hudson

Robert Kern said:
No, it doesn't. It grabs the appropriate object from sys.stderr.

Ah, you're right, I somehow ended up reading PySys_WriteStderr...

Cheers,
mwh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top