Input and output files using Swig

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pradpill
    New Member
    • Apr 2009
    • 3

    Input and output files using Swig

    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
    Last edited by bvdet; Apr 15 '09, 01:50 PM. Reason: Added moderator note
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    pradpill,

    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?

    -BV

    Comment

    • pradpill
      New Member
      • Apr 2009
      • 3

      #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

      Comment

      • pradpill
        New Member
        • Apr 2009
        • 3

        #4
        More info on task

        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(inpu t,output) doesnt work in my case.Please send me your thoughts till that time i will keep reading SWIG docs :(

        Comment

        • bvdet
          Recognized Expert Specialist
          • Oct 2006
          • 2851

          #5
          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.
          Code:
          import a_C_module
          import sys
          
          a_C_module.some_function(sys.argv[1], sys.argv[2])

          Comment

          Working...