Implicit lists

Martin Maney maney at
Mon Feb 3 05:38:37 CET 2003

Christian Tismer <tismer at> wrote:
> The summary is this:
> How can I express that I want to pass a string or some other
> object as a single parameter to a function that both accepts
> singletons and sequences?

I know it isn't the answer you want, but I have had occasion to try on
teeshirts from this drawer, and I don't think there is a better answer
than something like this in Python:

    foo(['my string here'])

or it might look like this, although it's IMO a bit less clear for
this simple example:

    foo(('this string available'))

> How can I prevend that Joe User ignores my interface and passes a
> string, and I misinterpret it as a bunch of characters?

You can't, not with certainty.  This is generally true, as the old saw
about how they're making better fools all the time (hence the futility
of trying to make your widget completely foolproof) points out.  If
this proves to be a common error, then perhaps having an interface that
tries to accomodate different types that require different handling yet
are so easily confused is not an optimum solution.

> All the attempts to figure out what the user wants
> have side effects, put implications or restrictions
> on objects which aren't intuitive or are application
> specific.

Yes.  When you are reduced to guessing, you have to expect to be right
less than 100% of the time, no?  If accuracy is all-important, then
perhaps you need a solution that removes the need to guess what is

> Is the consequence to always try to avoid polymorphic interfaces,

Why do you think it has to be all or nothing?  Polymorphism is neither
a magic bullet nor a child of Satan.  It's a tool, and like all tools
it is sometimes applicable and other times not.  At least that's been
my experience.

More information about the Python-list mailing list