Is there a way to delete created variables, functions, etc from the memory of the interpreter?

前端 未结 6 1945
春和景丽
春和景丽 2020-11-27 10:07

I\'ve been searching for the accurate answer to this question for a couple of days now but haven\'t got anything good. I\'m not a complete beginner in programming, but not y

6条回答
  •  抹茶落季
    2020-11-27 10:41

    This worked for me.

    You need to run it twice once for globals followed by locals

    for name in dir():
        if not name.startswith('_'):
            del globals()[name]
    
    for name in dir():
        if not name.startswith('_'):
            del locals()[name]
    

提交回复
热议问题