how to erase a variable

Discussion in 'Python' started by greenflame, Jun 3, 2006.

  1. greenflame

    greenflame Guest

    Is there a way to get rid of a variable as though it never existed? I
    know this sounds very basic but I have not come across any such
    methods. Also is the fact that I will have a bunch of extra variables
    just haning around because my use for them is over a bad thing? I will
    likely have on the order of 10 to 50 or so of these for the particular
    program I an working on at the moment.
     
    greenflame, Jun 3, 2006
    #1
    1. Advertising

  2. greenflame

    John Machin Guest

    greenflame wrote:
    > Is there a way to get rid of a variable as though it never existed? I
    > know this sounds very basic but I have not come across any such
    > methods. Also is the fact that I will have a bunch of extra variables
    > just haning around because my use for them is over a bad thing? I will
    > likely have on the order of 10 to 50 or so of these for the particular
    > program I an working on at the moment.


    del rubbish, garbage, junk, unwanted_stuff
     
    John Machin, Jun 3, 2006
    #2
    1. Advertising

  3. greenflame

    Ben Finney Guest

    "greenflame" <> writes:

    > Is there a way to get rid of a variable as though it never existed? I
    > know this sounds very basic but I have not come across any such
    > methods.


    You can use the 'del' statement to delete a name.

    > Also is the fact that I will have a bunch of extra variables just
    > haning around because my use for them is over a bad thing? I will
    > likely have on the order of 10 to 50 or so of these for the
    > particular program I an working on at the moment.


    It doesn't cause the computer any grief to have extra objects; they'll
    eventually be cleaned up by garbage collection anyway.

    That said, it sounds like your program is not modular enough, which is
    a burden on the *programmer* to need to keep so many items in their
    head at once. It's far better to divide your program into discrete
    functional units, and write each conceptual step as a function.

    By dividing your program into functional modules (whether they be
    functions, classes with methods, or separate program modules) each
    unit of functionality has a limited scope, and the variables are local
    and get cleaned up after the function ends. This greatly aids the
    person reading the program: they have fewer things to concentrate on
    at any point in your program.

    --
    \ "For every complex problem, there is a solution that is simple, |
    `\ neat, and wrong." -- Henry L. Mencken |
    _o__) |
    Ben Finney
     
    Ben Finney, Jun 3, 2006
    #3
  4. greenflame

    greenflame Guest

    Ok thanks all!
     
    greenflame, Jun 3, 2006
    #4
    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. tom_usenet
    Replies:
    1
    Views:
    358
    Corno
    Jul 5, 2003
  2. Robert Sturzenegger

    How to erase node from deque?

    Robert Sturzenegger, Jul 28, 2003, in forum: C++
    Replies:
    0
    Views:
    314
    Robert Sturzenegger
    Jul 28, 2003
  3. John Harrison

    Re: STL insert/erase behaviour

    John Harrison, Aug 13, 2003, in forum: C++
    Replies:
    0
    Views:
    639
    John Harrison
    Aug 13, 2003
  4. erase vs. erase

    , Mar 25, 2006, in forum: C++
    Replies:
    7
    Views:
    369
    Pete Becker
    Mar 30, 2006
  5. Mike Copeland
    Replies:
    4
    Views:
    294
    Bo Persson
    Dec 15, 2012
Loading...

Share This Page