tags:

views:

227

answers:

7

Though there can be many but as i am very new to python so which modules or classes within standard libraries i should know when programming in python, especially when i am practicing programming challenges from a C++ book? Libraries which can make my life easier? Since there can be no single correct answer, i am making this question a wiki.

+1  A: 

The standard library, especially the built-in functions. They seem trivial but can yield impressive results!

It really pays to know the basics of a default python installation. If you doubt that just follow the Stack Overflow python questions. Some answers are just amazing :)

extraneon
+8  A: 

The standard libraries, i.e. the ones considered more or less part of Python. Start with those, there is plenty to learn before starting on 3rd party stuff.

Things like:

unwind
+4  A: 

The re module is a must. itertools also often comes handy.

Generally speaking: Take a deep look at Standard library. Then you might think about wxPython for GUI, numPy for computations, Django for web and Amara for XML, and... there's plenty of Python libs and modules out there. Just suit your needs.

Abgan
+1 for itertools, came here to answer that
Jed Smith
`itertools` is the probably the most versatile and powerful
Otto Allmendinger
+8  A: 

Check out the excellent Python Module of the Week blog series.

Jonathan Feinberg
Those blog are actually just descriptions of modules in python's standard library. Yep, there's plenty of functionality in there. Lots of fun things to do and learn.
Reinout van Rees
+2  A: 

Since you ask about libraries, not specific modules in them, the standard library that comes with Python is the first and most fundamental answer; the programming challenges from a C++ book are unlikely to require anything beyond that (such as GUI toolkits) -- perhaps numpy/scipy if the book is heavily slanted to scientific programming.

Alex Martelli
sorry i have correct my question, i mean modules or classes within standard libraries.
itsaboutcode
+3  A: 

Actually, to work problems from a C++ book using Python, you mainly just need to master Python's built-in types, especially the data structures tuple, list, set, and dict; and the built-in functions, like max, min, sorted, and reversed.

These builtins have a lot of features that aren't obvious at first, such as the in keyword, the optional key= argument to list.sort, list slicing, sequence multiplication, the dict(list_of_pairs) constructor, del, tuple unpacking, and so on. It's fun to learn these, and they make Python a real joy to use.

Also see collections.defaultdict. If you need file I/O, read about open and file objects.

Jason Orendorff
+4  A: 

math

Seems too fundamental, but when getting started with python (lets face it, I'm still learning it) I missed some functions in the math module that would have been helpful. I ended up writing my own versions which worked but I could have saved time...

Frank V
advice to you frank: there is `cmath` too! (I don't want to you rewrite that using math) :-)
kaizer.se
Thanks! I didn't know about cmath.
Frank V