How to assign a default constant value in a function declaration
Vineet Jain
vineet at eswap.com
Mon Apr 5 20:44:52 EDT 2004
Thanks for all the repsonses. It turns out that the following actually
works:
def someFunction(option=Constants.DEFAULT_VALUE):
I did want the evaluate "Constants.DEFAULT_VALUE" function definition time.
If that changes at function call time then it should not be in Constants.
So all in all it works as expected and I have changed all hard coded default
arguments in my functions to Constant.* values.
Thanks for all your help.
VJ
-----Original Message-----
From: python-list-bounces+vineet=eswap.com at python.org
[mailto:python-list-bounces+vineet=eswap.com at python.org]On Behalf Of
rzed
Sent: Monday, April 05, 2004 3:52 PM
To: python-list at python.org
Subject: Re: How to assign a default constant value in a function
declaration
Scott David Daniels <Scott.Daniels at Acm.Org> wrote in
news:4071a362 at nntp0.pdx.net:
> Marco Bartel wrote:
>
>> rzed wrote:
>>
[...]
>>> Do you mean in a context like this?
>>> class Const:
>>> someVal=255
>>> otherVal=0
>>>
>>> def blip(Const.someVal):
> Should be:
> def blip(test=Const.someVal):
>>
>> i checked this out, and i think its the name you were using:
>> Const
> Nope, it is the missing arg name.
>
Well, not so much that as an incorrectly formed parameter name. I
can legally do this:
def blip( someVal ):
...
but not this:
def blip( x.someVal ):
=> SyntaxError aimed at the dot.
Since there is no argname to assign a value to, "Const.someVal" is
taken as an identifier for a passed-in parameter. But it seems
(sensibly enough) that an identifier can't contain a '.' character,
which evidently is reserved for a qualifier separator (or some such
term) in that context.
--
rzed
--
http://mail.python.org/mailman/listinfo/python-list
More information about the Python-list
mailing list