Reputation: 2165
Is it possible to write a one-liner with
context manager in python?
Something like:
with open('xml_file.xml') as file: file.write('<fave_food>filled dhal puri roti</fave_food>')
Upvotes: 1
Views: 830
Reputation: 15887
Yes, but you'll have to open the file for writing if you want to write in it.
Upvotes: 2