The Python standard library and PEP8

E

Emmanuel Surleau

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
 
B

bearophileHUGS

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
 
C

Colin J. Williams

Emmanuel said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top