SCRIPTS FILES basicΒΆ

# -*-Python-*-
# Created by grierson at 04 Apr 2016  13:11

printi('Files will appear in {}'.format(root['SETTINGS']['SETUP']['workDir']))
printi("And can be easily viewed in OMFIT Terminal tab with `ls runs/TUTORIAL/p0/`")

# Open file for writing, using `with` that also automatically closes it
with open('file.txt', 'w') as f:
    # write a line
    f.write('hello\n')

# Create text for a file
txt = []
txt.append('First line\n')
txt.append('Second line\n')
# Write multiple lines of text to file
with open('file2.txt', 'w') as f:
    for i in range(len(txt)):
        f.write(txt[i])

# Yet another way for multple lines.
# This is the preferred way.
txt = []
txt.append('Line 1')
txt.append('Line 2')
with open('file3.txt', 'w') as f:
    f.write('\n'.join(txt))