I want to write a script (generate_script.py) generating another python script (filegenerated.py)
So far i have created generate_script.py:
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.'
The file (filegenerated.py) looks now like this:
def print_success(): print “sucesss”
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?
Thanks a lot!
You could just use a multiline string:
If you like your template code to be indented along with the rest of your code, but dedented when written to a separate file, you could use
textwrap.dedent: