On Sep 6, 8:43 am, Gary Robinson <[EMAIL PROTECTED]> wrote:
>
> I welcome feedback of any type.
>

This all seems a bit too complicated. Are you sure you want to do
this? Maybe you need to step back and rethink your problem.

Your example can be rewritten a number of different ways that are
easier to think about.

The simple approach:

  _x_counter = 0
  def x():
      _x_counter += 1
      return _x_counter

The generator approach:

  def counter_gen():
      x = 0
      while True:
          x += 1
          yield x

  counter = counter_gen()
  counter.next()
  counter.next() # etc...

A class-based approach:

  class Counter(object):
      def __init__(self):
          self._x = 0

      def count(self):
          self._x += 1
          return self._x

In general, there really isn't a need to mess with stack frames unless
you are really interested in looking at the stack frame.

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to