logo       

Re: using stdout/stderr with python: msg#00134

programming.swig

Subject: Re: using stdout/stderr with python

also sprach Martin F Krafft <krafft@xxxxxxxx> [2004.05.25.0140 +0200]:
> Some of my functions take a FILE*. I understand how one can
> provide wrappers or a typemap to deal with that, but what if
> I want to pass stdout and stderr into these functions as the FILE*
> arguments? I could not find a way to do this.

I found sys.stdout and sys.stderr, but I can't seem to use them.
Neither can I use file objects.

I am using the following typemap in the .i file:

%typemap(python,in) FILE* {
if (!PyFile_Check($input)) {
PyErr_SetString(PyExc_TypeError, "need a file!");
return NULL;
}
$1 = PyFile_AsFile($input);
}

(basically copied from the docs)

but when I ttry to use sys.stdout as a FILE* argument, Python
complains:

Traceback (most recent call last):
File "./test", line 11, in ?
phidget_set_debug_stream(f)
TypeError: Type error. Expected _p_FILE

The same happens if I pass f = open('file', 'w')

I would appreciate any tips and pointers!

--
Martin F. Krafft Artificial Intelligence Laboratory
Ph.D. Student Department of Information Technology
Email: krafft@xxxxxxxx University of Zurich
Tel: +41.(0)1.63-54323 Andreasstrasse 15, Office 2.18
http://ailab.ch/people/krafft CH-8050 Zurich, Switzerland

Invalid/expired PGP subkeys? Use subkeys.pgp.net as keyserver!
Spamtraps: krafft.bogus@xxxxxxxx madduck.bogus@xxxxxxxxxxx

"when a woman marries again it is because she detested her first husband.
when a man marries again it is because he adored his first wife.
women try their luck; men risk theirs."
-- oscar wilde

Attachment: signature.asc
Description: Digital signature

<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise