Page 71 -
P. 71

sharing your code


          Turn your function into a module


          A module is simply a text file that contains Python code. The main
           requirement is that the name of the file needs to end in .py: the Python
           extension. To turn your function into a module, save your code into an
           appropriately named file:

            Your code
             from
             Chapter 1   def print_lol(the_list):
                               for each_item in the_list:
                                      if isinstance(each_item, list):
                                              print_lol(each_item)
                                      else:
                                              print(each_item)








                                                                    Let’s call
                                                                   this file
                                                                   “nester.py”.






           Q:   What’s the best Python editor?



           A: The answer to that question really depends on who you ask. However, you
           can, of course, use any text editor to create and save your function’s code in a
           text file. Something as simple as NotePad on Windows works fine for this, as does
           a full-featured editor such as TextMate on Mac OS X. And there’s also full-fledged   Do this!
           IDEs such as Eclipse on Linux, as well as the classic vi and emacs editors. And,
           as you already know, Python comes with IDLE, which also includes a built-in
           code editor. It might not be as capable as those other “real” editors, but IDLE is
           installed with Python and is essentially guaranteed to be available. For lots of
           jobs, IDLE’s edit window is all the editor you’ll ever need when working with your
           Python code. Of course, there are other IDEs for Python, too. Check out WingIDE   Go ahead and create a text
           for one that specifically targets Python developers.                  file called nester.py that
                                                                                 contains your function code
                                                                                 from the end of Chapter 1.



                                                                                       you are here 4    35
   66   67   68   69   70   71   72   73   74   75   76