title: Getting a class' function using the Python C API
body: <p>I'm trying to import the ftp module of Python to a C++ application using the Python C API, but I'm having trouble getting a reference to the <code>FTP.nlst</code> function. (Or any function of the <code>FTP</code> class for that matter.)</p>
  <p>My current code snippet looks like this:</p>
  <pre><code>Py_Initialize();
  
  PyObject* module = PyImport_ImportModule(&quot;ftplib&quot;);
  PyObject* dict = PyModule_GetDict(module);
  PyObject* function = PyDict_GetItemString(dict, &quot;FTP.nlst&quot;);
  
  </code></pre>
  <p>The lines coming after this don't really matter as <code>function</code> is a <code>NULL</code> pointer no matter what I try, so this will always be UB.</p>
  <p>Trying something arbitrary, like importing the math module and assigning <code>function</code> to be the <code>fabs</code> function works on the other hand.</p>
  <p>Any help is appreciated!</p>