I've a method that I want to be able to accept either a single string (a path, but not necessarily one that exists on the machine running the code) or a list/tuple of strings.
Given that strings act as lists of characters, how can I tell which kind the method has received?
I'd like to be able to accept either standard or unicode strings for a single entry, and either lists or tuples for multiple, so isinstance doesn't seem to be the answer unless I'm missing a clever trick with it (like taking advantage of common ancestor classes?).
Python version is 2.5
Best Answer
You can check if a variable is a string or unicode string with
This will return
True
for both strings and unicode stringsAs you are using python 2.5, you could do something like this:
Stringness is probably not a word, but I hope you get the idea