Object type check

Calvin Spealman ironfroggy at gmail.com
Wed Feb 7 12:07:54 EST 2007


On 7 Feb 2007 08:59:12 -0800, king kikapu <aboudouvas at panafonet.gr> wrote:
> > Dont restrict them to particular types. You would
> > not restrict them to a particular class in C#. Instead, you define the
> > interfaces simply by how you use the objects.
>
> Of cource i restrict them to particular types! In C# you cannot pass
> something bad
> this way because the compiler will just catch it!

No, you restrict the interfaces, in your example, not the classes. It
is the same in python, but the interfaces are implicitly defined by
how you use the objects.

> I see what you mean by "duck typing". So you suggest the "do nothing
> at all" direction,
> better document my code so other can see what is expected, right ?

Yes. Also, remember that this means if you write code to expect a
dictionary, any mapping type that supports the operations and methods
you use will work transparently, allowing your code to be much more
flexible.

-- 
Read my blog! I depend on your acceptance of my opinion! I am interesting!
http://ironfroggy-code.blogspot.com/



More information about the Python-list mailing list