is it possible to give an instance a value?
Steven D'Aprano
steve at REMOVEME.cybersource.com.au
Wed Mar 7 21:22:25 EST 2007
On Wed, 07 Mar 2007 16:02:05 +0100, egbert wrote:
> On Tue, 06 Mar 2007 14:45:45 -0800, manstey wrote:
>>
>> class Test(object):
>> def __init__(self, val):
>> self.val = val
>>
>> a = Test('hello')
>
>> Is there a way to make a have the value a.val when it is used as
>> above, or as an argument (eg function(a, 10, 'sdf') etc)?
>>
> My impression is that you can do everything you want to
> by making your instance callable, and not using a but a().
You can't do this:
>>> a() = "some value"
SyntaxError: can't assign to function call
If you do this:
>>> a = "some value"
then we're back to the Original Poster's original problem.
--
Steven D'Aprano
More information about the Python-list
mailing list