I have a piece of code in a function definition which is:
try:
with open(requests,'rt') as f:
tree = ElementTree.parse(f)
The string, requests, contains a file path and apparently that file is opened. At the beginning of the .py file, I have
from xml.etree.ElementTree import ElementTree
When I try these lines in test.py and call "python3 test.py" I do NOT get an error message, however when I run the program with python3 I get the following error message:
tree = ElementTree.parse(f)
TypeError: parse() missing 1 required positional argument: 'source'
However as you can see the positional argument of parse() is f. I did put a print command to examine the value of requests, and it showed the proper file name.
You should invoke the
parse
method on anElementTree
instance:e.g.
Code fix: