title: How to write PID to file in Python?
body: <p>I get the current running script PID by <code>os.getpid()</code>, and try to store it in a file but I get an error that <code>write()</code> only accepts 'string' and not 'int'. So how to pass PID as a string to <code>write()</code>?</p>
  <p>My code:</p>
  <pre><code>import os
  
  outputFile = open('test.txt', &quot;w&quot;)
  pid = os.getpid()
  outputFile.write(pid)
  outputFile.close()
  </code></pre>