Creating a local variable scope.

markolopa marko.loparic at
Sun Nov 29 22:12:13 CET 2009


On 18 Sep, 10:36, "markol... at" <markol... at> wrote:
> On Sep 11, 7:36 pm, Johan Grönqvist <johan.gronqv... at> wrote:
> > I find several places in my code where I would like tohavea variable
> > scope that is smaller than the enclosing function/class/module definition.
> This is one of the single major frustrations I have with Python and an
> important source of bugs for me. Here is a typical situation

Here is another bug that I just got. Twenty minutes lost to find it...

class ValueColumn(AbstractColumn):
    def __init__(self, name, header, domain_names):
        if type(domain_names) != tuple:
            raise ValueError('a tuple of domain names must be given')
        for name in domain_names:
            if type(name) != str:
                raise ValueError('a tuple of domain names must be
        self.domain_names = domain_names
        super(ValueColumn, self).__init__(name, header)

The upper class was initialized with the wrong name, because the for
loop to check
domain_names used "name" which is also the argument to be passed.

If is an old thread but I am reopening to present real situation where
this Python
"feature" bothers me...


More information about the Python-list mailing list