I am trying to use the next function on an iterator, however, I have a local variable in the same scope that is also named next.  The obvious solution is to rename the local variable, however, I'm fairly new to Python so I'm curious to learn how to prefix the next function so I achieve the desired behavior.
The code I'm using looks something like this:
for prev, curr, next in neighborhood(list):
    if (prev == desired_value):
        print(prev+" "+next)
        desired_value = next(value_iterator)
Note that I'm using Python 3.2.
You can use __builtins__.next to refer to the next built-in function.
for prev, curr, next in neighborhood(list):
    if (prev == desired_value):
        print(prev+" "+next)
        desired_value = __builtins__.next(value_iterator)
However, as you point out, the obvious solution is to use a different name for your variable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With