Reputation: 3913
Is it possible to format strings while saving in a file, similar when printing to a console?
f = open('test.txt', 'w')
f.write('{0:10} {1:10}').format('one', 'two')
f.close()
Upvotes: 0
Views: 795
Reputation: 11545
Yes it is. I think that one of your closing parenthesis was not where you meant it to be:
with open('test.txt', 'w') as f:
f.write('{0:10} {1:10}'.format('one', 'two'))
Upvotes: 1