Single string vs list of strings
Joe Strout
joe at strout.net
Thu Oct 30 11:10:18 EDT 2008
On Oct 30, 2008, at 8:55 AM, Grant Edwards wrote:
> The question you might want to asked is whether the parameter
> is a single string or a sequence of strings. That way your
> code will also work with an iterator that returns strings.
>
>>>> type('asdf') is str
> True
I agree with the general approach, but this test will fail for Unicode
strings, and so is probably bad mojo moving forward. Instead I suggest:
isinstance(x, basestring)
which will work whether x='asdf' or x=u'asdf'.
Best,
- Joe
More information about the Python-list
mailing list