Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > The Python standard library and PEP8

Reply
Thread Tools

The Python standard library and PEP8

 
 
Emmanuel Surleau
Guest
Posts: n/a
 
      04-19-2009
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
 
Reply With Quote
 
 
 
 
bearophileHUGS@lycos.com
Guest
Posts: n/a
 
      04-20-2009
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
 
Reply With Quote
 
 
 
 
Colin J. Williams
Guest
Posts: n/a
 
      04-20-2009
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: The Python standard library and PEP8 Lawrence D'Oliveiro Python 3 04-21-2009 10:23 AM
Re: The Python standard library and PEP8 Tim Wintle Python 3 04-21-2009 04:51 AM
Re: The Python standard library and PEP8 Emmanuel Surleau Python 15 04-20-2009 04:55 PM
Re: The Python standard library and PEP8 Gabriel Genellina Python 2 04-19-2009 06:20 PM



Advertisments