Page 13 -
P. 13

table of contents


                                     sharing your code
                           2         Modules of functions



                                     Reusable code is great, but a shareable module is better.
                                     By sharing your code as a Python module, you open up your code to the entire Python
                                     community…and it’s always good to share, isn’t it? In this chapter, you’ll learn how to
                                     create, install, and distribute your own shareable modules. You’ll then load your module
                                     onto Python’s software sharing site on the Web, so that everyone can benefit from your
                                     work. Along the way, you’ll pick up a few new tricks relating to Python’s functions, too.


                                                  It’s too good not to share                         34
                                                  Turn your function into a module                   35
                                                  Modules are everywhere                             36
                                                  Comment your code                                  37
                                                  Prepare your distribution                          40
                                                  Build your distribution                            41
                                                  A quick review of your distribution                42
                                                  Import a module to use it                          43
                                                  Python’s modules implement namespaces              45
                                                  Register with the PyPI website                     47
                                                  Upload your code to PyPI                           48
                                                  Welcome to the PyPI community                      49
                                                  Control behavior with an extra argument            52
                                                  Before your write new code, think BIF              53
                                                  Python tries its best to run your code             57
                                                  Trace your code                                    58
                                                  Work out what’s wrong                              59
                                                  Update PyPI with your new code                     60
                                                  You’ve changed your API                            62
                     nester                       Use optional arguments                             63
                                                  Your module supports both APIs                     65
                                                  Your API is still not right                        66
                                                  Your module’s reputation is restored               70
                         nester.py
                                                  Your Python Toolbox                                71
                         setup.py




                                                                                                         xi
   8   9   10   11   12   13   14   15   16   17   18