2

I want to delete all user defined objects from a python session. Suppose I do the following things.

1) Start Rodeo ( a python GUI )

2) write u = 5

3) So u is an object now.

4) import some packages say

    import os
    import pandas as pd
    import datetime

5) Now I want to clear only these objects :- u, os module, pd module and datetime module.

By 'clear' I mean to say that after clearing if I type u in console, python should not be able to find the object u.

Similarly all commands in pd ( i.e. pandas ) module should be inaccessible.

How to do this ?

Please note that I don't want to delete any builtins ( as described in this question : How do I clear all variables in the middle of a Python script? ).

The duplicate question that you are pointing does not answer the question completely. I want to know how to remove only the user defined objects without removing the builtins etc.

The duplicate question gives answer about how to remove the builtins too - which I don't want.

Community
  • 1
  • 1
boral
  • 131
  • 9
  • [What's your X?](http://xyproblem.info/) – Stefan Pochmann Jul 30 '16 at 19:19
  • 1
    `locals()` and `globals()` are of data type `dict` for `dictionary` in python. So please check how to `remove objects from dictionary in python by providing index values` may be for those objects as you don't want to remove the bulletins. – Sowmya S. Manian Jul 30 '16 at 19:23
  • 1
    @SowmyaS.Manian Note that while modifying `globals` has the effect you'd expect, modifying `locals` is **not** reliable. It sometimes works, *most* of the time it doesn't. – Bakuriu Jul 30 '16 at 20:00
  • @Bakuriu Thank you for this information, I have started learning python. I am a beginner. – Sowmya S. Manian Jul 30 '16 at 20:10
  • 1
    In Ipython I found that the command is %reset -f – boral Jul 31 '16 at 03:59

0 Answers0