DjangoUrl
DjangoUrl

Reputation: 57

Why avoid string module and use str in Python?

What are the reasons why one should avoid the string module and use str instead in Python? Anybody knows? Thanks a lot for the help.

Upvotes: 0

Views: 253

Answers (1)

VPfB
VPfB

Reputation: 17267

There is a bunch of deprecated functions in the string module clearly tagged as such in Python2 (https://docs.python.org/2.7/library/string.html#deprecated-string-functions). These function are unavailable in Python3. Obviously, these functions should not be used. Let's now talk about the rest.

The existence of deprecated functions does not mean that the whole string library module is to be avoided in any way.

Further, you don't have a real choice between str class and string module. Take for example the functionality of Template and Formatter. The former provides "$name" substitution and the latter allows to parse format strings and to customize string formatting. These are uncommon tasks, but if you need to do just that, the str class alone does not provide the right tools.

Upvotes: 2

Related Questions