Movatterモバイル変換


[0]ホーム

URL:


[Python-Dev] Revised PEP 349: Allow str() to return unicodestrings

Neil Schemenauernas at arctrix.com
Thu Aug 25 19:03:32 CEST 2005


On Wed, Aug 24, 2005 at 09:11:18PM +0200, Dieter Maurer wrote:> Neil Schemenauer <nas at arctrix.com> writes on Mon, 22 Aug 2005 15:31:42 -0600:> >     The code was fixed by changing> >     the line "header = str(header)" to:> >> >         if isinstance(header, unicode):> >             header = header.encode('ascii')>> Note, that this is not equivalent to the old "str(header)":>>   "str(header)" used Python's "default encoding" while the>   new code uses 'ascii'.It also doesn't call __str__ if the object is not a basestringinstance.  I have a hard time understanding the exact purpose ofcalling str() here.  Maybe Barry can comment.> Can we get a new builtin with the exact same behaviour as> the current "str" which can be used when we do require an "str"> (and cannot use a "unicode").That fact that no code in the standard library requires such afunction (AFAIK), leads me to believe that it would not be usefulenough to be made a built-in.  You would just write it yourself:    def mystr(s):        s = str(s)        if isinstance(s, unicode):            s = s.encode(sys.getdefaultencoding())        return sCheers,  Neil


More information about the Python-Devmailing list

[8]ページ先頭

©2009-2025 Movatter.jp