Shortcut to initialize variables

Andrew aetodd at gmail.com
Fri Jun 17 20:24:11 CEST 2005


Newb here... For one of my programs I want to initialize a variable for
each letter of the alphabet. For example, a,b,c = 0,0,0. I don't think
this works, but I'm wondering if I can do something similar to this:

from string import ascii_lowercase

class Blah:
    def __init__(self):
        for letter in ascii_lowercase:
            setattr(self,letter,0)

Is there a way I can do something like this without using classes?

Thanks




More information about the Python-list mailing list