May-20-2018, 08:50 PM
import pprint cats = [{'name': 'Zophie', 'desc': 'chubby'}, {'name': 'Pooka', 'desc': 'fluffy'}] print(pprint.pformat(cats)) fileObj = open('C:\\Python36\\kodovi\\myCats.py', 'w') with open('myCats.py') as f: f.write('cats = ' + pprint.pformat(cats) + '\n') with open('myCats.py') as f: print(f.read())
Error:Traceback (most recent call last):
File "C:\Python36\kodovi\pretty.py", line 6, in <module>
f.write('cats = ' + pprint.pformat(cats) + '\n')
io.UnsupportedOperation: not writable
example is from the same book ( Automate...), not sure why isn't it writible.