Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
493 views
in Technique[技术] by (71.8m points)

python - 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!!!!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...