On Sep 12, 11:08 am, Bojan Mihelac <[EMAIL PROTECTED]> wrote:
> Hi all - when trying to set some dynamic attributes in class, for
> example:
>
> class A:
> for lang in ['1', '2']:
> exec('title_%s = lang' % lang) #this work but is ugly
> # setattr(A, "title_%s" % lang, lang) # t
On Sep 12, 4:30 pm, Bojan Mihelac <[EMAIL PROTECTED]> wrote:
> On Sep 12, 5:21 pm, Christian Heimes <[EMAIL PROTECTED]> wrote:
>
> > Bojan Mihelac wrote:
> > > I guess A class not yet exists in line 4. Is it possible to achive
> > > adding dynamic attributes without using exec?
>
> > Correct, the c
On Sep 12, 5:35 pm, Wojtek Walczak <[EMAIL PROTECTED]> wrote:
> On Fri, 12 Sep 2008 08:08:18 -0700 (PDT), Bojan Mihelac wrote:
> > Hi all - when trying to set some dynamic attributes in class, for
> > example:
>
> > class A:
> > for lang in ['1', '2']:
> > exec('title_%s = lang' % lang)
On Fri, 12 Sep 2008 08:08:18 -0700 (PDT), Bojan Mihelac wrote:
> Hi all - when trying to set some dynamic attributes in class, for
> example:
>
> class A:
> for lang in ['1', '2']:
> exec('title_%s = lang' % lang) #this work but is ugly
> # setattr(A, "title_%s" % lang, lang) #
On Sep 12, 5:21 pm, Christian Heimes <[EMAIL PROTECTED]> wrote:
> Bojan Mihelac wrote:
> > I guess A class not yet exists in line 4. Is it possible to achive
> > adding dynamic attributes without using exec?
>
> Correct, the class doesn't exist until the end of the class body. You
> can either do i
Bojan Mihelac wrote:
I guess A class not yet exists in line 4. Is it possible to achive
adding dynamic attributes without using exec?
Correct, the class doesn't exist until the end of the class body. You
can either do it outside the class definition or you can use a metaclass.
Christian
--
Bojan Mihelac wrote:
Hi all - when trying to set some dynamic attributes in class, for
example:
class A:
for lang in ['1', '2']:
exec('title_%s = lang' % lang) #this work but is ugly
# setattr(A, "title_%s" % lang, lang) # this wont work
setattr(A, "title_1", "x") # this wo
Hi all - when trying to set some dynamic attributes in class, for
example:
class A:
for lang in ['1', '2']:
exec('title_%s = lang' % lang) #this work but is ugly
# setattr(A, "title_%s" % lang, lang) # this wont work
setattr(A, "title_1", "x") # this work when outside class
p