Is it possible to call a C Function by reference from python??
Question: I am a beginner in python and I need to test a C function which is being
called by reference.

Here is my C File : myfile.c

    
    
    #include<stdio.h>
    
    int my_function(int *x)
    {
    int A;
    printf("enter value of A");
    scanf("%d",&A);
    *x = 10 * A; // this sets the value to the address x is referencing to
     return 0; 
    }
    

now, my python script should call my_function() and pass the argument so that
I can check and verify the result.

something like :

`result = self.loaded_class.my_function(addressOf(some_variable))`

`self.assertEqual(some_variable,10)`

Is this possible ?? how can i achieve this. And I am writing scripts in python
for auto tests , not using interactive python.


Answer: If you compile your file as a shared library or dll (I don't know how to do
that), you can use [ctypes](http://docs.python.org/2/library/ctypes.html) like
this (assuming it's a dll for this example):

    
    
    import ctypes as ct
    
    mylib = ct.cdll.myfile
    c_int = ct.c_int(0)
    mylib.my_function(ct.byref(c_int))
    print c_int.value
    

