Duck Typing

Discussion in 'Python' started by srijit@yahoo.com, Sep 16, 2003.

Guest

Hello All,
I have been seeing this term "duck typing" for quite sometime now. It
will be nice if one of us can give an example in Python demonstrating
duck typing and/or link to some Python references.

Advertisements

<> wrote in message
news:...
> Hello All,
> I have been seeing this term "duck typing" for quite sometime now. It
> will be nice if one of us can give an example in Python demonstrating
> duck typing and/or link to some Python references.

Why in the world would anyone want to do such a thing? I hadn't
heard the term until you just brought it up, so a quick Google defined
it. AFAICT, it's simply a cute name that's applied to a very common
technique in languages that don't use static typing.

In other words, if you need a file-like object, and someone passes
you an object, your options are either to just use it (and handle the
exceptions if it doesn't really support the proper interface) or use
reflection to see if it has methods with the proper name and number
of parameters, and then be prepared to handle the exceptions when
they don't do what you expect.

Advertisements

wrote:
> I have been seeing this term "duck typing" for quite sometime now. It
> will be nice if one of us can give an example in Python demonstrating
> duck typing and/or link to some Python references.

On Tue, Sep 16, 2003 at 02:01:18AM -0700, wrote:
> Hello All,
> I have been seeing this term "duck typing" for quite sometime now. It
> will be nice if one of us can give an example in Python demonstrating
> duck typing and/or link to some Python references.

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!