简体   繁体   中英

TypeError: close() missing 1 required positional argument: 'self'

So I tried using the function InteractiveSession.close() If I do it says:

TypeError: close() missing 1 required positional argument: 'self'

But when I do InteractiveSession.close(self) It gives me the Error

NameError: name 'self' is not defined

I don't know what to do can anyone help? Thanks in Advance!!!!

You are expected to call .close() on an instance of the InteractiveSession class, not the class itself.

For example, if you have an instance of InteractiveSession in the variable session , you would write session.close() .

Also note that TF developers helpfully provided a usage example here: https://www.tensorflow.org/api_docs/python/tf/compat/v1/InteractiveSession

This question reflects a basic but common misunderstanding about how classes work in Python. There are many documents and guides that can help you on this topic, for example here is one I just found with a DDG search: https://medium.com/quick-code/understanding-self-in-python-a3704319e5f0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM