Passing objects to a function
bruno modulix
onurb at xiludom.org
Mon May 10 09:39:58 EDT 2004
Holger Türk a écrit :
(snip)
>
> This could be supported by an assert statement:
>
> def BlackJackValue(hand):
> """BlackJackValue(Hand_instance) -> int\n\nReturn an integer, which
> is the value of the Hand according to the rules of BlackJack."""
>
> assert isinstance (hand, Hand)
>
> [...]
>
> The method will throw an AssertionError if hand is not
> an instance of Hand. Assertions can be turned off later for
> performance reasons; with -O I guess.
Note that this is also highly unpythonic since you won't be able to pass
objects that implements the Hand interface but do not subclass Hand.
This may not be a problem in this specific case, but this probably
should not be recommanded in the general case unless there is a very
compelling reason to do so...
--
bruno - modulix
onurb ta xiludom tod gro
--
More information about the Python-list
mailing list