The pprint
method of the PrettyPrinter
class does not accept a stream
keyword argument. Either give the stream when you create the object in this line:
pp = pprint.PrettyPrinter(indent=4)
or use the function pprint.pprint
, which accepts a stream
keyword argument.
That's the reason for the error. A more fundamental question is: why you are using the pprint
module, when title of the question is "write and read xml Python 3"? The pprint
module does not generate XML. See https://wiki.python.org/moin/PythonXml for some ideas on handling XML with python.
Also note that pywapi.get_weather_from_weather_com
returns a python dictionary. The function has already converted the XML data into a dictionary, so you don't have to read any XML. See this example (if you haven't already).
You could save the dictionary as a JSON file.
import json
with open('weather.txt', 'wt') as out:
json.dump(steyregg, out, indent=4)