A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2009-October/092460.html below:

[Python-Dev] transitioning from % to {} formatting

[Python-Dev] transitioning from % to {} formatting [Python-Dev] transitioning from % to {} formattingNick Coghlan ncoghlan at gmail.com
Thu Oct 1 23:11:57 CEST 2009
Vinay Sajip wrote:
> You're right to be nervous: it's not hard to mangle subtypes.
> 
>>>> class mystr(str): pass
> ...
>>>> s = mystr("Abc")
>>>> s
> 'Abc'
>>>> type(s)
> <class '__main__.mystr'>
>>>> s2 = s.replace("A", "a")
>>>> s2
> 'abc'
>>>> type(s2)
> <type 'str'>

It's also difficult for the subclass to prevent this without creating an
infinite loop... (I only spent about 10 minutes looking into it the
other day, but that's what happened in all of my naive attempts at doing
it in pure Python code).

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4