May-20-2018, 09:32 PM
You don't use
The modern way,as mention before so do not @Al Sweigart care about new stuff in Python,
like string formatting he use
fileObj
,it's not needed either.import pprint cats = [{'name': 'Zophie', 'desc': 'chubby'}, {'name': 'Pooka', 'desc': 'fluffy'}] with open('cats.txt', 'w') as f: f.write('cats = ' + pprint.pformat(cats) + '\n') with open('cats.txt') as f: print(f.read())If you to use a path
with open(r'C:\Python36\kodovi\'cats.txt', 'w') as f:
The modern way,as mention before so do not @Al Sweigart care about new stuff in Python,
like string formatting he use
+
everywhere and stuff like pprint.pformat()
to build a string. cats = [{'name': 'Zophie', 'desc': 'chubby'}, {'name': 'Pooka', 'desc': 'fluffy'}] with open('cats.txt', 'w') as f: f.write(f'cats = {cats}\n') with open('cats.txt') as f: print(f.read())