1

Through SO/P.SE browsing, I've been picking up useful pieces of Python code (e.g. a Mutable memoizer, an efficient prime generator) that I'd like to stick into one spot to have available should I need it in future projects.

What are some best practices for how a "personal" code library of reusable classes/functions/modules should be set up?

For example, do I just drop it all into one module? Or should I model it after the standard library, even though some modules may have 1 class/function in them?

  • I need some ideas on this, too. I tend to organize things by subject, and put my code projects in subject-specific folders, and many of them are git repositories for gist.github.com, but it's not easy to call one script from another unless I dump them all in the same folder. – endolith May 25 '13 at 13:19
3

Partition it like you would a normal library. There is no reason to include a monster god module if you only need it for one method. The other advantage of organizing pieces into pieces is that it will be easier to find something you need, but haven't used in a while. You don't have to remember that your prime generator comes just before the memoizer in the file. You can just jump straight into the prime module and see the other related methods that you could use but forgot were in your library.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.