title: Is there a way to pass a F# method to a Python function?
body: <p>I am trying to call a python function from F#. So far, I managed to call a simple Python function (e.g: to print a string). The problem is that I can't manage to pass a F# method to my Python function and call it from here.</p>
  <p>Program.fs</p>
  <pre><code>let printMsg () = Console.WriteLine &quot;Print from F#&quot;
  
  [&lt;EntryPoint&gt;]
  let main argv =
      Environment.SetEnvironmentVariable (&quot;PATH&quot;, pythonPath + Environment.GetEnvironmentVariable &quot;PATH&quot;)
      PythonEngine.Initialize ()
  
      let import = PythonEngine.ImportModule &quot;HelloWorld&quot;
      let helloWorld = import?HelloWorld()
  
      helloWorld?exec(printMsg)
  
      PythonEngine.Shutdown ()
  
      0
  </code></pre>
  <p>Helloworld.py</p>
  <pre><code>class HelloWorld:
      def __init__(self):
          print(&quot;__init__&quot;)
  
      def exec(self, printMsg):
          printMsg()
  </code></pre>
  <p>But I get <code>Python.Runtime.PythonException: 'TypeError : object is not callable'</code> on the <code>helloWorld?exec(printMsg)</code> line of <code>Program.fs</code>, caused by the call to <code>printMsg()</code> from Python.</p>