PythonWin: any way to delete all objects without exiting and without doing it with "del"?

Discussion in 'Python' started by dananrg@yahoo.com, Mar 1, 2006.

  1. Guest

    In PythonWin, is there any way to bulk-delete all objects without using
    "del object" for each, and without having to exit out of PythonWin?
    , Mar 1, 2006
    #1
    1. Advertising

  2. writes:

    > In PythonWin, is there any way to bulk-delete all objects without using
    > "del object" for each, and without having to exit out of PythonWin?


    PythonWin is just an IDE. For what reason you have to delete all objects by
    yourself? Garbage collector is there for that :)

    --
    Lawrence - http://www.oluyede.org/blog
    "Anyone can freely use whatever he wants but the light at the end
    of the tunnel for most of his problems is Python"
    Lawrence Oluyede, Mar 1, 2006
    #2
    1. Advertising

  3. Re: PythonWin: any way to delete all objects without exiting andwithout doing it with "del"?

    wrote:
    > In PythonWin, is there any way to bulk-delete all objects without using
    > "del object" for each, and without having to exit out of PythonWin?


    I think you just want to modify the globals() dict:

    >>> list(globals())

    ['__builtins__', 'text', 'glob', 'pywin', 're', 'match', 'basename',
    '__name__', 'line', 'foo', 'os', '__doc__', 'fn']
    >>> for name in list(globals()):

    .... if name != 'pywin' and name[:2] != '__':
    .... del globals()[name]
    ....
    >>> del name
    >>> list(globals())

    ['__builtins__', 'pywin', '__name__', '__doc__']

    Be careful though, I think there's a few things in there you might not
    want to ``del`` (e.g. ``pywin``).

    STeVe
    Steven Bethard, Mar 1, 2006
    #3
  4. Guest

    > PythonWin is just an IDE. For what reason you have to delete all objects by
    > yourself? Garbage collector is there for that :)


    I think the garbage collector is on strike. :)

    Example:

    # 1st execution
    a = [1,2,3]
    print a

    >>> [1,2.3]


    program ends.

    Then I comment out a = [1,2,3] and run the program:

    # 2nd execution
    # a = [1,2,3]
    print a

    >>> [1,2,3]


    Same result. Why? I know that's not a great example, but it was giving
    me grief in the debugging process while using the ODBC module. I'd
    really rather not have to exit out of PythonWin each time I want to
    clear out all the objects I created during a script, and then
    subsequently comment out for future executions of a script for
    debugging, if that makes any sense.
    , Mar 2, 2006
    #4
  5. Guest

    Steven, does your technique fix my problem? Would that delete the
    objects I've created within a program if I suffix my code with it?
    , Mar 3, 2006
    #5
  6. Re: PythonWin: any way to delete all objects without exiting andwithout doing it with "del"?

    wrote:
    > Steven, does your technique fix my problem? Would that delete the
    > objects I've created within a program if I suffix my code with it?


    I'm not certain I understand your problem, but I think so. Give it a try.

    STeVe
    Steven Bethard, Mar 3, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. stephan
    Replies:
    0
    Views:
    426
    stephan
    Jul 30, 2003
  2. python
    Replies:
    7
    Views:
    296
    Bruno Desthuilliers
    Jun 3, 2006
  3. Replies:
    2
    Views:
    268
  4. tom
    Replies:
    5
    Views:
    398
  5. Daniel Pitts
    Replies:
    16
    Views:
    902
    Kai-Uwe Bux
    Jun 6, 2008
Loading...

Share This Page