OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Delete object instance from class function in python

  • Thread starter Thread starter Izaya
  • Start date Start date
I

Izaya

Guest
I would like to delete an instance of my object after executing a function so that no python script can access this instance anymore.

Here is my code:

Code:
class MyClass():
    def myFunc(self):
       ...
       del self

myClass = MyClass()
myClass.myFunc()
print(myClass) # Supposed to raise an error because myClass is supposed to be deleted but that's not the case

What's going wrong?
<p>I would like to delete an instance of my object after executing a function so that no python script can access this instance anymore.</p>
<p>Here is my code:</p>
<pre><code>class MyClass():
def myFunc(self):
...
del self

myClass = MyClass()
myClass.myFunc()
print(myClass) # Supposed to raise an error because myClass is supposed to be deleted but that's not the case
</code></pre>
<p>What's going wrong?</p>
 
Top