Hallo everyone,
I'm trying to convert a main function from C to Python,by using Swig and call it with a .txt argument.The code is the following :
[CODE=c]
/*test.c*/
#include <stdio.h>
int main(int argc, char ** argv)
{
float f1,f2,f3;
FILE *fp;
fp=fopen(argv[1],"r");
if(fp!=NULL)
{
printf("Succesf ull opening\n");
fscanf(fp,"%f\n %f\n%f",&f1,&f2 ,&f3);
printf("the values are \n%f\n%f\n%f\n" ,f1,f2,f3);
fclose(fp);
}
return 0;
}
/*test_interface .i*/
%module example
%{
int main(int argc,char **argv);
%}
int main(int argc,char **argv);
/*text.txt*/[/CODE]
0.2313
2.3123
12.123
from Linux command prompt I execute the following commands:
$ swig -python test_interface. i
$ gcc -c test.c test_interface_ wrap.c -I/usr/include/python2.5
$ ld -shared test.o test_interface_ wrap.o -o _example.so
$ python
>>>from _example import *
>>>main(1,'text 1.txt') // ERROR !!!!
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: in method 'main', argument 2 of type 'char **'
All i want to do is the same thing like the following C procces:
$ gcc test.c -o test
$ ./test text.txt
the values are
0.231300
2.312300
12.123000
What is the solution?
I'm trying to convert a main function from C to Python,by using Swig and call it with a .txt argument.The code is the following :
[CODE=c]
/*test.c*/
#include <stdio.h>
int main(int argc, char ** argv)
{
float f1,f2,f3;
FILE *fp;
fp=fopen(argv[1],"r");
if(fp!=NULL)
{
printf("Succesf ull opening\n");
fscanf(fp,"%f\n %f\n%f",&f1,&f2 ,&f3);
printf("the values are \n%f\n%f\n%f\n" ,f1,f2,f3);
fclose(fp);
}
return 0;
}
/*test_interface .i*/
%module example
%{
int main(int argc,char **argv);
%}
int main(int argc,char **argv);
/*text.txt*/[/CODE]
0.2313
2.3123
12.123
from Linux command prompt I execute the following commands:
$ swig -python test_interface. i
$ gcc -c test.c test_interface_ wrap.c -I/usr/include/python2.5
$ ld -shared test.o test_interface_ wrap.o -o _example.so
$ python
>>>from _example import *
>>>main(1,'text 1.txt') // ERROR !!!!
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: in method 'main', argument 2 of type 'char **'
All i want to do is the same thing like the following C procces:
$ gcc test.c -o test
$ ./test text.txt
the values are
0.231300
2.312300
12.123000
What is the solution?
Comment