title: Set execute bit for a file using python
body: <p>Using python on Mac OS, I would like to open a file for writing and put some shell commands into it. Later to be run in terminal.</p>
  
  <pre><code>with open("my_script.sh", "w") as fd:
      fd.write("#!/bin/sh\n")
      fd.write("echo $PATH\n")
  </code></pre>
  
  <p>This will create the file, but I could not figure how to set the execute bit so when I run it in the Terminal I will not get:</p>
  
  <pre><code>sh: my_script.sh: Permission denied
  </code></pre>