By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,995 Members | 1,217 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,995 IT Pros & Developers. It's quick & easy.

Input and output files using Swig

P: 3
Hi Varun,

I have somewhat similar task where i am required to read a text file and after processing write the output to another file.Now checking the changes you have made to interface file i also tried to tinker with my file but it didnt work.

I want to learn how to write interface files to get the correct wrapping.I have checked many sites and all start with a simple example but not helping me to extend it to more meaningful programs.
I have begineers c skills but more than avg python skills.Can you help me what is the best way to start learning SWIG...and does it require to have expert C skills

**Moderator Note**
This post was moved from existing thread: link
Apr 9 '09 #1
Share this Question
Share on Google+
4 Replies

Expert Mod 2.5K+
P: 2,851

Varuns has not visited this site since February 2008. You should be able to handle your task entirely in Python. If you just want to learn SWIG, the latest documentation is here. Can you give us more details of your task?

Apr 9 '09 #2

P: 3
Thanks bvdet....Well my question was somewhat general as i wanted to know when you have write methods to call or send i/o in interface files and when it is okay to include all the header files and SWIG will do all the work.

I did checked Swig documentations,but as it all started with a simple sample program where i wanted my C code to read the file and print all the lines with certain formatting to another output file..

I have included all the header files and the functions in interface file but i was not able to pass the file line.... scriptname file_in file_out like i was able to do in C.

Now in such situations do we have to use %typemap and input checks like varuns did..or it is not required.

I will check the Swig documentation and see whether i am able to solve my problem...but if you have any suggestions then do reply..

Thanks man
Apr 13 '09 #3

P: 3
Just to make the task little bit clear,the C file i have takes two arguments.One is input file name and the other is Output file name.C code reads the input file name and writes after processing to Output filename.I am trying this to learn wrapping using Swig.So although i can complete the task using python very neatly ,i wanted to call the running C code from python.

Now the C file's main function checks whether the necessary two arguments input filename and output file name is provided or not by checking argc and then reads argv[1] that is the input file name and writes it to the argv[2] (i.e provided output filename).

so if the module name is _test then _test.main(input,output) doesnt work in my case.Please send me your thoughts till that time i will keep reading SWIG docs :(
Apr 15 '09 #4

Expert Mod 2.5K+
P: 2,851
I do not understand what the problem is (it may be because I do not know Swig). I would suggest reading the arguments (input and output file names) with your python code and pass them to the C function.
Expand|Select|Wrap|Line Numbers
  1. import a_C_module
  2. import sys
  4. a_C_module.some_function(sys.argv[1], sys.argv[2])
Apr 15 '09 #5

Post your reply

Sign in to post your reply or Sign up for a free account.