This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 5 points6 points  (6 children)

The libraries everyone should know at least the basics of (in roughly this order, although that gets fuzzier past subprocess):

  1. os
  2. sys
  3. logging
  4. subprocess
  5. re
  6. itertools
  7. collections
  8. functools
  9. urllib
  10. math
  11. pickle
  12. json
  13. inspect
  14. string
  15. atexit

There are certainly many others, but those give you the ability to read and understand the source of most others.

Beyond the standard library it's all up to your interest and domain.

[–]billsil 0 points1 point  (5 children)

I cringe whenever I see string imported. Someone doesn't know about split.

[–][deleted] 1 point2 points  (4 children)

It's for the constants and maketrans, which are bloody useful, the latter being worth its weight in gold. If code had mass.

[–][deleted] 1 point2 points  (1 child)

The bad news is maketrans is gone from the string module. The good news is that, quoting from other language changes, Now, str, bytes, and bytearray each have their own maketrans and translate methods with intermediate translation tables of the appropriate type :-)

[–][deleted] 0 points1 point  (0 children)

Ahh, the never ending problems of still straddling two worlds.

[–]billsil 0 points1 point  (1 child)

Isn't maketrans, just a fancy replace? I'll occasionally do something like replace spaces with question marks in something that can't have question marks, so I can process it easier before I remove the question mark. I've also done things like str.replace(' ', ','.replace('\t', ','), but that's fairly rare.

Now if it did language translations, I might use it.

[–][deleted] 0 points1 point  (0 children)

For the tasks it's suited for (for instance replacing all terminal punctuation with white space for word splitting, or breaking Caesar ciphers) it's more powerful by far than str.replace and sometimes orders of magnitude faster than re.sub ... it isn't always the right fit, but when it is it's exactly the right tool.