473,385 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Changing interpreter's deafult output/error streams

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

Jul 31 '05 #1
7 1989
"Ira" <sh******@gmail.com> writes:
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

--
ARTHUR: Yes. It was on display in the bottom of a locked filing
cabinet stuck in a disused lavatory with a sign on the door
saying "Beware of the Leopard".
-- The Hitch-Hikers Guide to the Galaxy, Episode 1
Jul 31 '05 #2
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?
"Michael Hudson" <mw*@python.net> wrote in message
news:m2************@82-33-185-193.cable.ubr01.azte.blueyonder.co.uk...
"Ira" <sh******@gmail.com> writes:
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

--
ARTHUR: Yes. It was on display in the bottom of a locked filing
cabinet stuck in a disused lavatory with a sign on the door
saying "Beware of the Leopard".
-- The Hitch-Hikers Guide to the Galaxy, Episode 1
--
http://mail.python.org/mailman/listinfo/python-list


Aug 1 '05 #3
Ira wrote:
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
rk***@ucsd.edu

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

Aug 1 '05 #4
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?
"Michael Hudson" <mw*@python.net> wrote in message
news:m2************@82-33-185-193.cable.ubr01.azte.blueyonder.co.uk...
"Ira" <sh******@gmail.com> writes:
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

--
ARTHUR: Yes. It was on display in the bottom of a locked filing
cabinet stuck in a disused lavatory with a sign on the door
saying "Beware of the Leopard".
-- The Hitch-Hikers Guide to the Galaxy, Episode 1
--
http://mail.python.org/mailman/listinfo/python-list



Aug 1 '05 #5
"Ira" <sh******@gmail.com> writes:
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

--
<Acapnotic> jemfinch: What's to parse? A numeric code, perhaps a
chicken, and some arguments
-- from Twisted.Quotes
Aug 1 '05 #6
Michael Hudson wrote:
"Ira" <sh******@gmail.com> writes:
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...).


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

--
Robert Kern
rk***@ucsd.edu

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

Aug 1 '05 #7
Robert Kern <rk***@ucsd.edu> writes:
Michael Hudson wrote:
"Ira" <sh******@gmail.com> writes:
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...).


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

--
The only problem with Microsoft is they just have no taste.
-- Steve Jobs, (From _Triumph of the Nerds_ PBS special)
and quoted by Aahz on comp.lang.python
Aug 1 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: radnoraj | last post by:
Hi, I am sucessfull in redirecting console output to a file. but in this case nothing is displayed on the console, cout output is written to file without display. how do write the output to...
2
by: Gopal | last post by:
Hi, I've a module report.py having a set of funtions to open/close/write data to a log file. I invoke these functions from another module script.py. Whenever I'm changing something in...
37
by: nobody | last post by:
I am writing a framework that other developers will write plug-ins for. I would like for one of the features of the framework to be to intercept all text written to stdout/stderr and prepend...
5
by: Russ | last post by:
I wrote a simple little function for exiting with an error message: def error ( message ): print_stack(); exit ("\nERROR: " + message + "\n") It works fine for executing as a script, but when...
18
by: v4vijayakumar | last post by:
is there any standard way to extract output from system(3) function? TIA.
3
by: morris.slutsky | last post by:
So every now and then I like to mess around with hobby projects - I often end up trying to write an OpenGL video game. My last attempt aborted due to the difficulty of automating game elements and...
0
by: nadeemabdulhamid | last post by:
Hello, I'm trying to write some Java code that will launch a python interpreter shell and pipe input/output back and forth from the interpreter's i/o streams and the Java program. The code posted...
40
by: castironpi | last post by:
I'm curious about some of the details of the internals of the Python interpreter: I understand C from a hardware perspective. x= y+ 1; Move value from place y into a register Add 1 to the...
5
by: Erik Hahn | last post by:
I'm looking for a standalone Javascript interpreter like the ones of Perl and Python. Does such a thing exist for Linux? Thanks in advance. -Erik --...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.