Closed kounelios13 closed 6 years ago
I confess that I've always followed Martin's example, but I have just tried it the way you describe, with the same result as you. Martin may have more insights on this. But I therefore recommend that you do it with the "with Client() as cli" way.
I think I have a bit better understanding of this now.
Using the with-as construct, calls not only the constructor for the Client class, but also the __enter__
method to set up the connection and the __exit__
method to clean up afterwards. This doesn't happen if you don't use this construct, therefore the connection fails.
This explanation may be helpful to read in conjunction with the client.py file in pyvas (the __enter__
and __exit__
methods are right at the end of the file.
http://effbot.org/zone/python-with-statement.htm
@jal58 Thank you very much for the last link.It is especially interesting since I am still learning python and it helped me understand some things better
You're most welcome, and I'm glad you asked the question because I learned from it too!
Best wishes,
Anna
I noticed that in your examples I have to do
with Client() as cli
.However I tried to do the following:This however throws an error telling me
TypeError: File or filename expected, got 'NoneType'
.Any ideas why this is happening?