how to erase a variable

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • greenflame

    #1

    how to erase a variable

    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.

  • John Machin

    #2
    Re: how to erase a variable


    greenflame wrote:[color=blue]
    > 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.[/color]

    del rubbish, garbage, junk, unwanted_stuff

    Comment

    • Ben Finney

      #3
      Re: how to erase a variable

      "greenflame " <alikakakhel@ya hoo.com> writes:
      [color=blue]
      > 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.[/color]

      You can use the 'del' statement to delete a name.
      [color=blue]
      > 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.[/color]

      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

      Comment

      • greenflame

        #4
        Re: how to erase a variable

        Ok thanks all!

        Comment

        Working...