Symbols as parameters?
Stefan Behnel
stefan_ml at behnel.de
Thu Jan 21 06:41:04 EST 2010
Alf P. Steinbach, 21.01.2010 09:30:
> * Martin Drautzburg:
>> - to be able to call move(up)
>> - having the "up" symbol only in the context of the function call
>>
>> So it should look something like this
>>
>> ... magic, magic ...
>> move(up)
>> ... unmagic, unmagic ...
>> print up
Looks like a terribly bad design to me.
>> This should complain that "up" is not defined during the "print" call,
>> but not when move() is called. And of course there should be as little
>> magic as possible.
>>
>> Any way to achieve this?
>
> >>> def move( direction ):
> ... print( "move " + str( direction ) )
> ...
> >>> move( "up" )
> move up
> >>>
> >>> class using_directions:
> ... up = 42
> ... move( up )
> ...
> move 42
> >>> up
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> NameError: name 'up' is not defined
> >>> _
>
> Of course it's an abuse of the language. :-)
And, of course, it's totally useless as the move() function doesn't know
about the 'up' thing in the first place.
Stefan
More information about the Python-list
mailing list