Don't use 'strorunicodeobj' as the generic object name. Use just

'obj' -- after all, you don't know that it's a string or unicode
object just yet, that's what the test in these examples is for!
This commit is contained in:
Guido van Rossum 2002-06-04 17:02:07 +00:00
parent 22cf1a49f9
commit 6655f152be
1 changed files with 4 additions and 4 deletions

View File

@ -543,19 +543,19 @@ Programming Recommendations
might be a unicode string too! In Python 2.3, str and unicode might be a unicode string too! In Python 2.3, str and unicode
have a common base class, basestring, so you can do: have a common base class, basestring, so you can do:
if isinstance(strorunicodeobj, basestring): if isinstance(obj, basestring):
In Python 2.2, the types module has the StringTypes type defined In Python 2.2, the types module has the StringTypes type defined
for that purpose, e.g.: for that purpose, e.g.:
from string import StringTypes from string import StringTypes
if isinstance(strorunicodeobj, StringTypes): if isinstance(obj, StringTypes):
In Python 2.0 and 2.1, you should do: In Python 2.0 and 2.1, you should do:
from string import StringType, UnicodeType from string import StringType, UnicodeType
if isinstance(strorunicodeobj, StringType) or \ if isinstance(obj, StringType) or \
isinstance(strorunicodeobj, UnicodeType) : isinstance(obj, UnicodeType) :
- For sequences, (strings, lists, tuples), use the fact that empty - For sequences, (strings, lists, tuples), use the fact that empty
sequences are false, so "if not seq" or "if seq" is preferable sequences are false, so "if not seq" or "if seq" is preferable