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/2002-June/024985.html below:

[Python-Dev] Draft Guide for code migration and modernation

[Python-Dev] Draft Guide for code migration and modernationWalter Dörwald walter@livinglogic.de
Tue, 04 Jun 2002 13:58:53 +0200
Neal Norwitz wrote:

> [...]
> Pattern:  import string ; string.method(s, ...)  -->  s.method(...)

join and zfill should probably be mentioned separately:
"""
Be careful with string.join(): The order of the arguments is reversed
here.

string.zfill has a "decadent feature": It also works for
non-string objects by calling repr before formatting.
"""

             string.atoi(s, ...)  -->  int(s, ...)
             string.atol(s, ...)  -->  long(s, ...)
             string.atof(s, ...)  -->  float(s, ...)

>           c in string.whitespace --> c.isspace()

This changes the meaning slightly for unicode characters, because
chr(i).isspace() != unichr(i).isspace()
for i in { 0x1c, 0x1d, 0x1e, 0x1f, 0x85, 0xa0 }

New ones:

Pattern:  "foobar"[:3] == "foo" -> "foobar".startswith("foo")
           "foobar"[-3:] == "bar" -> "foobar".endswith("bar")
Version:  ??? (It was added on the string_methods branch)
Benefits: Faster because no slice has to be created.
           No danger of miscounting.
Locating: grep "\[\w*-[0-9]*\w*:\w*\]" | grep "=="
           grep "\[\w*:\w*[0-9]*\w*\]" | grep "=="

Pattern:  import types;
           if hasattr(types, "UnicodeType"):
               foo
           else:
               bar
           -->
           try:
               unicode
           except NameError:
               bar
           else:
               foo
Idea:     The types module will likely to be deprecated in the future.
Version:  2.2
Benefits: Avoid a deprecated feature.
Locating: grep "hasattr.*UnicodeType"

Bye,
    Walter Dörwald





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