title: Open a TemporaryFile using open()
body: <p>I'm trying to interface with an existing library that uses the built in <a href="https://docs.python.org/3/library/functions.html#open" rel="nofollow noreferrer"><code>open()</code></a> function to read a <code>.json</code> file using <a href="https://docs.python.org/3/glossary.html#term-path-like-object" rel="nofollow noreferrer">either a str or bytes object representing a path, or an object implementing the os.PathLike protocol</a>. </p>
  
  <p>My function generate a dictionary which is converted to <code>json</code> using <code>json.dump()</code>, but I'm not sure how to pass that to the existing function which expects a file path.</p>
  
  <p>I was thinking something like this might work, but I'm not sure how to get a <code>os.PathLike</code> object of a TemporaryFile.</p>
  
  <pre><code>import tempfile
  temp_file = tempfile.TemporaryFile('w')
  json.dump('{"test": 1}', fp=temp_file)
  file = open(temp_file.path(), 'r')
  </code></pre>