title: Python: Improvement (Code reduction): Compact write json to FTP
body: <p>This is my current code:</p>
  
  <pre><code>def ftp_upload(local_ftpfile_path, ftp_ftpfile_path):
      json_data = {...}
      with open(local_ftpfile_path, 'w') as f:
          json.dump(json_data, f)
      f.close()
      file = open(local_ftpfile_path, 'rb')  # file to send
      try:
          session.storbinary('STOR ' + ftp_ftpfile_path, file)  # send the file
      except ... :
          ...
      else:
          ...
  </code></pre>
  
  <p>Everything works, but I think it's a little stupid to open two files.</p>
  
  <p>How can I convert it to just one file, so either just to <code>f</code> or to <code>file</code>, but not both.</p>
  
  <p>How would you have to change the <code>w</code> and the <code>rb</code>? </p>
  
  <p>Thanks for the help!</p>
  
  <p>best regards,</p>
  
  <p>Lukas</p>