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>')
Yes, but you'll have to open the file for writing if you want to write in it.