logo       

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

programming.swig

Subject: Re: Re: using stdout/stderr with python

On 2004.05.26 11:45, Martin F Krafft wrote:
also sprach Luigi Ballabio <luigi.ballabio@xxxxxxxxxxxxx>
[2004.05.26.1118 +0200]:
> do you mean that you received my typemap and it's not
working,
> or that you didn't receive it at all?

It means that I have tried this solution before, it's quoted in the
docs. However, it's not working.

I actually tried this time---it works for me. Here's my foo.i file:
------------------------------------------------------
%module Foo

%include exception.i

%{
#include <stdlib.h>
%}

%typemap(in) FILE* {
if (PyFile_Check($input)) {
$1 = PyFile_AsFile($input);
} else {
SWIG_exception(SWIG_TypeError, "file expected");
}
}

%inline %{
void test(FILE* out) {
fprintf(out, "Hello World!\n");
}
%}
------------------------------------------------------

and here's a transcript from my console:

ballabl:~$ swig -python foo.i
ballabl:~$ gcc -shared -I/usr/include/python2.3/ -o _Foo.so foo_wrap.c
ballabl:~$ python
Python 2.3.4c1 (#2, May 13 2004, 21:46:36)
[GCC 3.3.3 (Debian 20040429)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
import Foo
import sys
Foo.test(sys.stdout)
Hello World!
f = open('foo.txt','w')
Foo.test(f)
f.close()

ballabl:~$ cat foo.txt
Hello World!
ballabl:~$

you might want to start working from here to get the desired behavior for your functions.

Hope this helps,
Luigi

_______________________________________________
Swig maillist - Swig@xxxxxxxxxxxxxxx
http://mailman.cs.uchicago.edu/mailman/listinfo/swig



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

News | FAQ | advertise