pass objects to exec

Jp Calderone exarkun at
Fri Mar 21 19:21:05 CET 2003

On Fri, Mar 21, 2003 at 05:15:40AM -0800, zunbeltz wrote:
> Hi
> I'm new programming in Python (and other languages :) )
> I've created a 
> class Group(Menmbers)
> Members is a list tahat I use to initialize a group
> i.e. GroupA = Group(Members)
> The class Group have a method superclass that return a list MemberList
> I want to create new instances of Class Group each initialized with
> each element of MembersList and I want that each new instance have a
> name I can use i.e. GroupA-A, GroupA-B, ... GroupA-n where n depends
> on len(MenmberList).

  Unfortunately, "-" is not allowed in identifiers in Python, so what you
want is impossible.

  What you can do, however, is create a dict.

      d = {}
      for i in range(len(MemberList)):
          d['GroupA-%c' % (i + ord('A'))] = Group(MemberList[i])

  And you never even need to use exec ;)


Examinations are formidable even to the best prepared, for
even the greatest fool may ask more the the wisest man can answer.
                -- C.C. Colton
 up 1 day, 13:58, 2 users, load average: 0.18, 0.34, 0.36

More information about the Python-list mailing list