The Python standard library and PEP8

Discussion in 'Python' started by Emmanuel Surleau, Apr 19, 2009.

  1. Hi there,

    Exploring the Python standard library, I was surprised to see that several
    packages (ConfigParser, logging...) use mixed case for methods all over the
    place. I assume that they were written back when the Python styling
    guidelines were not well-defined.

    Given that it's rather irritating (not to mention violating the principle of
    least surprise) to have this inconsistency, wouldn't it make sense to clean
    up the API by marking old-style, mixed-case methods as deprecated (but
    keep them around anyway) and add equivalent methods following the
    lowercase_with_underscores convention?

    On an unrelated note, it would be *really* nice to have a length property on
    strings. Even Java has that!

    Cheers,

    Emm
    Emmanuel Surleau, Apr 19, 2009
    #1
    1. Advertising

  2. Emmanuel Surleau

    Guest

    Emmanuel Surleau:
    > On an unrelated note, it would be *really* nice to have a length property on
    > strings. Even Java has that!


    Once you have written a good amount of Python code you can understand
    that a len() function, that calls the __len__ method of objects, is
    better. It allows you to write:
    sorted(seq, key=len)

    Instead, if you have a len attribute you need:
    sorted(seq, key=attrgetter("len"))
    Or even:
    sorted(seq, key=lambda x: x.len)

    Bye,
    bearophile
    , Apr 20, 2009
    #2
    1. Advertising

  3. Emmanuel Surleau wrote:
    > Hi there,
    >
    > Exploring the Python standard library, I was surprised to see that several
    > packages (ConfigParser, logging...) use mixed case for methods all over the
    > place. I assume that they were written back when the Python styling
    > guidelines were not well-defined.
    >
    > Given that it's rather irritating (not to mention violating the principle of
    > least surprise) to have this inconsistency, wouldn't it make sense to clean
    > up the API by marking old-style, mixed-case methods as deprecated (but
    > keep them around anyway) and add equivalent methods following the
    > lowercase_with_underscores convention?
    >
    > On an unrelated note, it would be *really* nice to have a length property on
    > strings. Even Java has that!

    Why not anySequence.len()?

    Colin W.

    PS Yes, I know this has been flogged before.
    >
    > Cheers,
    >
    > Emm
    Colin J. Williams, Apr 20, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gabriel Genellina

    Re: The Python standard library and PEP8

    Gabriel Genellina, Apr 19, 2009, in forum: Python
    Replies:
    2
    Views:
    277
    Gabriel Genellina
    Apr 19, 2009
  2. Emmanuel Surleau

    Re: The Python standard library and PEP8

    Emmanuel Surleau, Apr 19, 2009, in forum: Python
    Replies:
    15
    Views:
    415
    Emmanuel Surleau
    Apr 20, 2009
  3. Lawrence D'Oliveiro

    Re: The Python standard library and PEP8

    Lawrence D'Oliveiro, Apr 20, 2009, in forum: Python
    Replies:
    3
    Views:
    221
    Lawrence D'Oliveiro
    Apr 21, 2009
  4. Tim Wintle
    Replies:
    3
    Views:
    370
    Steven D'Aprano
    Apr 21, 2009
  5. Victor Hooi
    Replies:
    19
    Views:
    235
    Nick Mellor
    Dec 5, 2013
Loading...

Share This Page