Here's a useful function along these lines, which ideally would be string.remove():<div><br></div><div><div><font class="Apple-style-span" face="'courier new', monospace">def remove(s, sub, maxremove=None, sep=None):</font></div>

<div><font class="Apple-style-span" face="'courier new', monospace">  """Removes instances of sub from the string.</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br>

</font></div><div><font class="Apple-style-span" face="'courier new', monospace">  Args:</font></div><div><font class="Apple-style-span" face="'courier new', monospace">    s: The string to be modified.</font></div>

<div><font class="Apple-style-span" face="'courier new', monospace">    sub: The substring to be removed.</font></div><div><font class="Apple-style-span" face="'courier new', monospace">    maxremove: If specified, the maximum number of instances to be</font></div>

<div><font class="Apple-style-span" face="'courier new', monospace">        removed (starting from the left). If omitted, removes all instances.</font></div><div><font class="Apple-style-span" face="'courier new', monospace">    sep: Optionally, the separators to be removed. If the separator appears</font></div>

<div><font class="Apple-style-span" face="'courier new', monospace">        on both sides of a removed substring, one of the separators is removed.</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br>

</font></div><div><font class="Apple-style-span" face="'courier new', monospace">  >>> remove('test,blah,blah,blah,this', 'blah')</font></div><div><font class="Apple-style-span" face="'courier new', monospace">  'test,,,,this'</font></div>

<div><font class="Apple-style-span" face="'courier new', monospace">  >>> remove('test,blah,blah,blah,this', 'blah', maxremove=2)</font></div><div><font class="Apple-style-span" face="'courier new', monospace">  'test,,,blah,this'</font></div>

<div><font class="Apple-style-span" face="'courier new', monospace">  >>> remove('test,blah,blah,blah,this', 'blah', sep=',')</font></div><div><font class="Apple-style-span" face="'courier new', monospace">  'test,this'</font></div>

<div><font class="Apple-style-span" face="'courier new', monospace">  >>> remove('test,blah,blah,blah,this', 'blah', maxremove=2, sep=',')</font></div><div><font class="Apple-style-span" face="'courier new', monospace">  'test,blah,this'</font></div>

<div><font class="Apple-style-span" face="'courier new', monospace">  >>> remove('foo(1)blah(2)blah(3)bar', 'blah', 1)</font></div><div><font class="Apple-style-span" face="'courier new', monospace">  'foo(1)(2)blah(3)bar'</font></div>

<div><font class="Apple-style-span" face="'courier new', monospace">  """</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace">  processed = ''</font></div>

<div><font class="Apple-style-span" face="'courier new', monospace">  remaining = s</font></div><div><font class="Apple-style-span" face="'courier new', monospace">  while maxremove is None or maxremove > 0:</font></div>

<div><font class="Apple-style-span" face="'courier new', monospace">    parts = remaining.split(sub, 1)</font></div><div><font class="Apple-style-span" face="'courier new', monospace">    if len(parts) == 1:</font></div>

<div><font class="Apple-style-span" face="'courier new', monospace">      return processed + remaining</font></div><div><font class="Apple-style-span" face="'courier new', monospace">    processed += parts[0]</font></div>

<div><font class="Apple-style-span" face="'courier new', monospace">    remaining = parts[1]</font></div><div><font class="Apple-style-span" face="'courier new', monospace">    if sep and processed.endswith(sep) and remaining.startswith(sep):</font></div>

<div><font class="Apple-style-span" face="'courier new', monospace">      remaining = remaining[len(sep):]</font></div><div><font class="Apple-style-span" face="'courier new', monospace">    if maxremove is not None:</font></div>

<div><font class="Apple-style-span" face="'courier new', monospace">      maxremove -= 1</font></div><div><font class="Apple-style-span" face="'courier new', monospace">  return processed + remaining</font></div>

<div><br></div>--- Bruce<br>Latest blog post: <a href="http://www.vroospeak.com" target="_blank">http://www.vroospeak.com/2010/10/today-we-are-all-chileans.html</a><br>Learn how hackers think: <a href="http://j.mp/gruyere-security" target="_blank">http://j.mp/gruyere-security</a><br>

<br>
<br><br><div class="gmail_quote">On Thu, Oct 14, 2010 at 3:16 PM, spir <span dir="ltr"><<a href="mailto:denis.spir@gmail.com">denis.spir@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<div class="im">On Thu, 14 Oct 2010 17:23:11 -0400<br>
Mike Meyer <<a href="mailto:mwm-keyword-python.b4bdba@mired.org">mwm-keyword-python.b4bdba@mired.org</a>> wrote:<br>
<br>
> The problem isn't that it's non-intuitive (there's only one intuitive<br>
> interface, and it's got nothing to do with computers), it's that there<br>
> are a wealth of "intuitive" meanings.<br>
<br>
</div>Maybe have string.erase(sub,n) be a "more intuitive" shortcut for string.replace(sub,'',n)?<br>
<br>
Denis<br>
-- -- -- -- -- -- --<br>
vit esse estrany ☣<br>
<font color="#888888"><br>
<a href="http://spir.wikidot.com" target="_blank">spir.wikidot.com</a><br>
</font><div><div></div><div class="h5"><br>
_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/python-ideas" target="_blank">http://mail.python.org/mailman/listinfo/python-ideas</a><br>
</div></div></blockquote></div><br></div>