title: Whats the best way to write python code into a python file?
body: <p>I want to write a script (generate_script.py) generating another python script (filegenerated.py)</p>
  
  <p>So far i have created generate_script.py:</p>
  
  <pre><code>import os
  filepath = os.getcwd()
  def MakeFile(file_name):
      temp_path = filepath + file_name
      file = open(file_name, 'w')
      file.write('def print_success():')
      file.write('    print "sucesss"')
      file.close()
      print 'Execution completed.'
  </code></pre>
  
  <p>The file (filegenerated.py) looks now like this:</p>
  
  <blockquote>
    <p>def print_success():    print "sucesss"</p>
  </blockquote>
  
  <p>Now i don't want to manually insert all linebreaks (also due to operating system difficulties)...is there a template system i can use writing python code into a python file? Does someone have an example?</p>
  
  <p>Thanks a lot!</p>