title: Writing code to a file, and then executing it
body: <p>I have a Python script that imports an existing file in the same directory as a module. How does writing to the file, then using the import to execute it differ from <code>exec()</code>? Is it safer?<br>
  Here's an example to illustrate what I'm talking about:  </p>
  
  <pre><code>import example
  examplefile = open("example.py", "w")
  exampletext = "def examplefunction():\n\tprint('This is an example!')\n\treturn"
  examplefile.write(exampletext)
  examplefile.close()
  example.examplefunction()
  </code></pre>