CHAPTER FOUR LIBRARY AND EXTENSION FAQ 4.1 General Library Questions 4.1.1 How do I find a module or application to perform task X? 4.1.2 Where is the math.py (socket.py, regex.py, etc.) source file? 4.1.3 How do I make a Python script executable on Unix? 49 Check the Library Reference to see if there’s a relevant standard library module. (Eventually you’ll learn what’s in the standard library and will be able to skip this step.) For third-party packages, search the Python Package Index or try Google or another Web search engine. Searching for “Python” plus a keyword or two for your topic of interest will usually find something helpful. If you can’t find a source file for a module it may be a built-in or dynamically loaded module implemented in C, C++ or other compiled language. In this case you may not have the source file or it may be something like$_{mathmodule.c}$ , somewhere in a C source directory (not on the Python Path). There are (at least) three kinds of modules in Python: import sys print(sys.builtin_module_names) You need to do two things: the script file’s mode must be executable and the first line must begin with$_{#!}$ followed by the path of the Python interpreter. The first is done by executing$_{chmod +x scriptfile}$ or perhaps$_{chmod 755 scriptfile}$ . The second can be done in a number of ways. The most straightforward way is to write #!/usr/local/bin/python as the very first line of your file, using the pathname for where the Python interpreter is installed on your platform. If you would like the script to be independent of where the Python interpreter lives, you can use the$_{env}$program. Almost all Unix variants support the following, assuming the Python interpreter is in a directory on the user’s$_{PATH}$ : #!/usr/bin/env python 3) modules written in C and linked with the interpreter; to get a list of these, type: 2) modules written in C and dynamically loaded (.dll, .pyd, .so, .sl, etc); 1) modules written in Python (.py);