> Yes, but you shouldn't unless you really need to. You're better off
> rethinking your algorithm.
I need it but inside a class. The idea is to pass an instance of a class
(think of something like a record but with some methods inside) with
"fields", whose names are not known in advance, to ano
Steven Bethard wrote:
> Steve Holden wrote:
>> You don't need setattr/getattr if you know in advance the name of the
>> attribute you need to access and you can get a reference to the object
>> whose attribute it is. So:
>>
>> >>> x = "Hello, Paulo"
>> >>> import sys
>> >>> sys.modules['__main
Steve Holden wrote:
> You don't need setattr/getattr if you know in advance the name of the
> attribute you need to access and you can get a reference to the object
> whose attribute it is. So:
>
> >>> x = "Hello, Paulo"
> >>> import sys
> >>> sys.modules['__main__'].x
> 'Hello, Paulo'
a.k.a
Paulo da Silva wrote:
> Steven Bethard escreveu:
>> Paulo da Silva wrote:
> ...
>
>> If you're at the module level, you can do::
>>
>> globals()['x'] = 10
>>
>> If you're inside a function, you probably want to look for another way
>> of doing what you're doing.
>>
>> What's the actual task yo
Steven Bethard escreveu:
> Paulo da Silva wrote:
...
> If you're at the module level, you can do::
>
> globals()['x'] = 10
>
> If you're inside a function, you probably want to look for another way
> of doing what you're doing.
>
> What's the actual task you're trying to accomplish here?
7stud escreveu:
> On Apr 2, 10:08 pm, Paulo da Silva <[EMAIL PROTECTED]> wrote:
>> Is it possible to use getattr/setattr for variables not inside
>> classes...?
>
> What does the python documentation say about the definition of
> setattr()?
>
I didn't read the full python documentation, yet! I ho
On Tue, 03 Apr 2007 05:08:42 +0100, Paulo da Silva wrote:
> Hi!
>
> In a class C, I may do setattr(C,'x',10).
>
> Is it possible to use getattr/setattr for variables not inside
> classes or something equivalent? I mean with the same result as
> exec("x=10").
Yes, but you shouldn't unless you re
On Apr 2, 10:08 pm, Paulo da Silva <[EMAIL PROTECTED]> wrote:
> Is it possible to use getattr/setattr for variables not inside
> classes...?
What does the python documentation say about the definition of
setattr()?
--
http://mail.python.org/mailman/listinfo/python-list
Paulo da Silva <[EMAIL PROTECTED]> writes:
> In a class C, I may do setattr(C,'x',10).
That would set an attribute on the class C, shared by all instances of
that class.
If you want to set an attribute on an instance, you need to do so on
the instance object::
>>> class Foo(object):
...
Paulo da Silva wrote:
> In a class C, I may do setattr(C,'x',10).
>
> Is it possible to use getattr/setattr for variables not inside
> classes or something equivalent? I mean with the same result as
> exec("x=10").
If you're at the module level, you can do::
globals()['x'] = 10
If you're i
Hi!
In a class C, I may do setattr(C,'x',10).
Is it possible to use getattr/setattr for variables not inside
classes or something equivalent? I mean with the same result as
exec("x=10").
Thanks.
--
http://mail.python.org/mailman/listinfo/python-list
11 matches
Mail list logo