IOformat Tutorial¶
IOformat helps us keep consistant formatting throughout AutoMech. We can practice working with strings:
>>> import ioformat
>>> mystring = 'I love AutoMech'
>>> ioformat.indent(mystring, 4)
' I love AutoMech'
>>> ioformat.addchar(mystring, ':) ', side='pre')
':) I love AutoMech'
>>> ioformat.addchar(mystring, '!', side='post')
'I love AutoMech !'
ioformat can also be used to remove unwanted characters from strings:
>>> uglystring = 'AutoMech '
>>> ioformat.remove_whitespace_from_string(uglystring)
'AutoMech'
Paths must be formatted very particularly and ioformat gives us that control:
>>> path = ioformat.pathtools.current_path()
>>> tutorial_path = 'automech-tutorial'
>>> new_path = ioformat.pathtools.prepare_path((path, tutorial_path), make=True)
>>> new_path
'/gpfs/fs1/home/elliott/automech-tutorial'
ioformat optionally can create this path and allows us to go to it
>>> ioformat.pathtools.go_to(new_path)
>>> ioformat.pathtools.write_file(mystring, new_path, 'myfile.txt')
>>> ioformat.pathtools.read_file(new_path, 'myfile.txt')
'I love AutoMech'
Note
Move on to the next tutorial Autoparse Tutorial to …
Or return to the tutorial hub Tutorial Hub to check out more tutorials