From 068325ef926538a30d7feb13f9b14a6163e24b6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Walter=20D=C3=B6rwald?= Date: Mon, 15 Apr 2002 13:36:47 +0000 Subject: Apply the second version of SF patch http://www.python.org/sf/536241 Add a method zfill to str, unicode and UserString and change Lib/string.py accordingly. This activates the zfill version in unicodeobject.c that was commented out and implements the same in stringobject.c. It also adds the test for unicode support in Lib/string.py back in and uses repr() instead() of str() (as it was before Lib/string.py 1.62) --- Lib/string.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'Lib/string.py') diff --git a/Lib/string.py b/Lib/string.py index d68b0bf349..cd9909e266 100644 --- a/Lib/string.py +++ b/Lib/string.py @@ -190,7 +190,10 @@ def rfind(s, *args): _float = float _int = int _long = long -_StringTypes = (str, unicode) +try: + _StringTypes = (str, unicode) +except NameError: + _StringTypes = (str,) # Convert string to float def atof(s): @@ -277,13 +280,8 @@ def zfill(x, width): """ if not isinstance(x, _StringTypes): - x = str(x) - n = len(x) - if n >= width: return x - sign = '' - if x[0] in '-+': - sign, x = x[0], x[1:] - return sign + '0'*(width-n) + x + x = repr(x) + return x.zfill(width) # Expand tabs in a string. # Doesn't take non-printing chars into account, but does understand \n. -- cgit v1.2.1