Symbols as parameters?
Alf P. Steinbach
alfps at start.no
Thu Jan 21 12:57:41 CET 2010
* Stefan Behnel:
> 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 ...
>>> ... unmagic, unmagic ...
>>> print up
> Looks like a terribly bad design to me.
That it is, in Python.
>>> 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
>> 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.
Hm, it seems as if you thought that the example was *literally* what the OP
It was not: it just demonstrated the possibility.
Consider replacing the assignment with whatever, or alternatively, consider that
perhaps 42 is indeed the value of "up" that the move() function knows about.
Cheers & hth.,
More information about the Python-list