[Patches] [ python-Patches-536241 ] string.zfill and unicode

noreply@sourceforge.net noreply@sourceforge.net
Mon, 15 Apr 2002 06:41:47 -0700


Patches item #536241, was opened at 2002-03-28 14:26
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=536241&group_id=5470

Category: Library (Lib)
Group: None
>Status: Closed
Resolution: Accepted
Priority: 5
Submitted By: Walter Dörwald (doerwalter)
Assigned to: Walter Dörwald (doerwalter)
Summary: string.zfill and unicode

Initial Comment:
This patch makes the function string.zfill work with 
unicode instances (and instances of str and unicode 
subclasses). Currently string.zfill(u"123", 10) 
results in "0000u'123'". With this patch the result is 
u'0000000123'.

Should zfill be made a real str und unicode method? I 
noticed that a zfill implementation is available in 
unicodeobject.c, but commented out.

----------------------------------------------------------------------

>Comment By: Walter Dörwald (doerwalter)
Date: 2002-04-15 15:41

Message:
Logged In: YES 
user_id=89016

Checked in as:
Doc/lib/libstdtypes.tex 1.88
Lib/UserString.py 1.12
Lib/string.py 1.63
test/string_tests.py 1.13
test/test_unicode.py 1.54
Misc/NEWS 1.388
Objects/stringobject.c 2.157
Objects/unicodeobject.c 2.138


----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2002-04-13 03:00

Message:
Logged In: YES 
user_id=6380

I'm for making them methods. Walter, just check it in!

----------------------------------------------------------------------

Comment By: Walter Dörwald (doerwalter)
Date: 2002-04-12 20:37

Message:
Logged In: YES 
user_id=89016

Now that test_userstring.py works and fails (rev 1.6) 
should we add zfill as str and unicode methods or change 
UserString.zfill to use string.zfill?

I've made a patch (attached) that implements zfill as 
methods (i.e. activates the version in unicodeobject.c that 
was commented out and implements the same in stringobject.c)

(And it adds the test for unicode support back in.)

----------------------------------------------------------------------

Comment By: Martin v. Löwis (loewis)
Date: 2002-04-12 16:51

Message:
Logged In: YES 
user_id=21627

Re: optional Unicode: Walter is correct; configuring with
--disable-unicode currently breaks the string module. One
might consider using types.StringTypes; OTOH, pulling in
types might not be desirable.

As for str vs. repr: Python was always using repr in zfill,
so changing it may break things.

So I recommend that Walter reverts Andrew's check-in and
applies his change.

----------------------------------------------------------------------

Comment By: Michael Hudson (mwh)
Date: 2002-03-30 12:25

Message:
Logged In: YES 
user_id=6656

Hah, I was going to say that but was distracted by IE 
wiping out the machine I'm sitting at.

Re-opening.

----------------------------------------------------------------------

Comment By: Walter Dörwald (doerwalter)
Date: 2002-03-30 12:16

Message:
Logged In: YES 
user_id=89016

But Python could be compiled without unicode support (by
undefining PY_USING_UNICODE), and string.zfill should work
even in this case.

What about making zfill a real str and unicode method?

----------------------------------------------------------------------

Comment By: A.M. Kuchling (akuchling)
Date: 2002-03-29 17:24

Message:
Logged In: YES 
user_id=11375

Thanks for your patch!  I've checked it into CVS, with two 
modifications.  First, I removed the code to handle the case 
where Python doesn't have a unicode() built-in; there's no 
expection that 
you can take the standard library for Python version N and use 
it with version N-1, so this code isn't needed.

Second, I changed string.zfill() to take the str() and not the repr()
when it gets a non-string object because that seems to make 
more sense.




----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=536241&group_id=5470