[Tutor] learning classes (kinda long)

luke rabidpoobear at gmail.com
Sun Jul 31 07:36:50 CEST 2005


hello.

I didn't read or understand your code that well.
but you asked:

> for section in config.sections():
>     section = bsserver.Server() 
> 
> first I would like for this instance to be named the name of the host in
> the section
> but i keep getting instances named section I think doing it may require
> something more complex than my current understanding. How do I get them
> to become individuallly named
> Instances?

did you think about using a dictionary?
example that might apply:
#start of code


class aclass:
    def __init__(self,astring):
        self.avar = astring+"!!!"

listofstrings = ["hello","hi","what's up"]
classesdict = {}
for item in listofstrings:
    classesdict[item] = aclass(item)

print classesdict["hello"].avar
#should print "hello!!!"


print classesdict["hi"].avar
#should print "hi!!!"


print classesdict["what's up"].avar
#should print "what's up!!!"


#end of code
I hope that helps ya.
-Luke



More information about the Tutor mailing list