Python version independent string and unicode handling.
This commit is contained in:
@@ -33,6 +33,7 @@ other than PathLog, then it probably doesn't belong here.
|
||||
'''
|
||||
|
||||
import PathScripts.PathLog as PathLog
|
||||
import sys
|
||||
|
||||
PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule())
|
||||
|
||||
@@ -96,3 +97,18 @@ Use this function to remove all expressions before deletion.'''
|
||||
if hasattr(obj, 'ExpressionEngine'):
|
||||
for attr,expr in obj.ExpressionEngine:
|
||||
obj.setExpression(attr, None)
|
||||
|
||||
def toUnicode(string):
|
||||
'''toUnicode(string) ... returns a unicode version of string regardless of the python version.'''
|
||||
if sys.version_info[0] < 3:
|
||||
return unicode(string)
|
||||
return string
|
||||
|
||||
def isString(string):
|
||||
'''isString(string) ... return True if string is a string, regardless of string type and python version.'''
|
||||
if type(string) == str:
|
||||
return True
|
||||
if sys.version_info[0] < 3 and type(string) == unicode:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
Reference in New Issue
Block a user