How to assign a default constant value in a function declaration

Marco Bartel mab at iee
Mon Apr 5 10:06:34 EDT 2004


rzed wrote:
> "Vineet Jain" <vineet at eswap.com> wrote in
> news:mailman.341.1081121191.20120.python-list at python.org: 
> 
> 
>>The following does not work although it seems like something you
>>should be able to do.
>>
>>def someFunction(option=Constants.DEFAULT_VALUE):
>>
> 
> Do you mean in a context like this?
> 
> 
>>>>class Const:
> 
> ...    someVal=255
> ...    otherVal=0
> ...
> 
>>>>Const.someVal
> 
> 255
> 
>>>>someVal=255
>>>>someVal
> 
> 255
> 
>>>>def blip(Const.someVal):
> 
>   File "<stdin>", line 1
>     def blip(Const.someVal):
>                   ^
> SyntaxError: invalid syntax
> 
>>>>def blip(someVal):
> 
> ...    (no syntax error)
> 
> 
> I've wondered about that, too. 
> 
> 

i checked this out, and i think its the name you were using:

Const

i tried this, and it works fine

 >class mconst:
 >	testval = 255

 >def testme(test = mconst.testval)
 >	print test

 >print testme()

255


if this is what you wanted dont use the word const for the class

CU
Marco




More information about the Python-list mailing list