title: How to pass a variable to python script from c++
body: <p>There are similar questions &amp; answers to this kind of problem but I still can't find a satisfying answer to my specific problem:</p>
  <p>I need to pass a variable (should be a global variable to this python script) to a python script from c++ code. I run this python script using following line in c++:</p>
  <pre class="lang-cpp prettyprint-override"><code>PyRun_SimpleString ( &quot;exec(f.read())&quot; );
  </code></pre>
  <p>and I want to pass this variable <code>var=&quot;From c++&quot;</code> to the python environment so code in <code>f</code> script is able to access <code>var</code> variable.</p>
  <p>I'm looking at <code>PyDict_SetItem</code> and <code>PyDict_SetItemString</code>, etc... but couldn't get it right. How can I do that?</p>