]> granicus.if.org Git - python/commitdiff
Replace sequential split/join calls on strings with a single replace call.
authorBrett Cannon <bcannon@gmail.com>
Tue, 23 Mar 2004 23:50:17 +0000 (23:50 +0000)
committerBrett Cannon <bcannon@gmail.com>
Tue, 23 Mar 2004 23:50:17 +0000 (23:50 +0000)
Thanks Andrew Gaul.

Lib/locale.py
Lib/urllib.py

index 2028948e9beefd52862ad8d1b1ec40f973ae8b03..192c91f1de296d19b60719977fb087fec3e7b301 100644 (file)
@@ -159,18 +159,16 @@ def str(val):
     """Convert float to integer, taking the locale into account."""
     return format("%.12g",val)
 
-def atof(str,func=float):
+def atof(string,func=float):
     "Parses a string as a float according to the locale settings."
     #First, get rid of the grouping
     ts = localeconv()['thousands_sep']
     if ts:
-        s=str.split(ts)
-        str="".join(s)
+        str = str.replace(ts, '')
     #next, replace the decimal point with a dot
     dd = localeconv()['decimal_point']
     if dd:
-        s=str.split(dd)
-        str='.'.join(s)
+        str = str.replace(dd, '.')
     #finally, parse the string
     return func(str)
 
index 1e633d8fd25f39f9f5e580e3326846c2b40dfaa7..823429690823ee7104d11325fe4aa2498ecef86d 100644 (file)
@@ -169,9 +169,7 @@ class URLopener:
             proxy = None
         name = 'open_' + urltype
         self.type = urltype
-        if '-' in name:
-            # replace - with _
-            name = '_'.join(name.split('-'))
+        name = name.replace('-', '_')
         if not hasattr(self, name):
             if proxy:
                 return self.open_unknown_proxy(proxy, fullurl, data)
@@ -1045,9 +1043,7 @@ def unquote(s):
 
 def unquote_plus(s):
     """unquote('%7e/abc+def') -> '~/abc def'"""
-    if '+' in s:
-        # replace '+' with ' '
-        s = ' '.join(s.split('+'))
+    s = s.replace('+', ' ')
     return unquote(s)
 
 always_safe = ('ABCDEFGHIJKLMNOPQRSTUVWXYZ'