4.5.5 How do I avoid blocking in the connect() method of a socket? . . . . . . . . . . . . . . . 57 4.6 Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 4.6.1 Are there any interfaces to database packages in Python? . . . . . . . . . . . . . . . . . . 58 4.6.2 How do you implement persistent objects in Python? . . . . . . . . . . . . . . . . . . . . 58 4.7 Mathematics and Numerics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 4.7.1 How do I generate random numbers in Python? . . . . . . . . . . . . . . . . . . . . . . . 58 5 Extending/Embedding FAQ 59 5.1 Can I create my own functions in C? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 5.2 Can I create my own functions in C++? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 5.3 Writing C is hard; are there any alternatives? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 5.4 How can I execute arbitrary Python statements from C? . . . . . . . . . . . . . . . . . . . . . . . 59 5.5 How can I evaluate an arbitrary Python expression from C? . . . . . . . . . . . . . . . . . . . . . 60 5.6 How do I extract C values from a Python object? . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 5.7 How do I use Py_BuildValue() to create a tuple of arbitrary length? . . . . . . . . . . . . . . . . . 60 5.8 How do I call an object’s method from C? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 5.9 How do I catch the output from PyErr_Print() (or anything that prints to stdout/stderr)? . . . . . . 61 5.10 How do I access a module written in Python from C? . . . . . . . . . . . . . . . . . . . . . . . . 61 5.11 How do I interface to C++ objects from Python? . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 5.12 I added a module using the Setup file and the make fails; why? . . . . . . . . . . . . . . . . . . . 62 5.13 How do I debug an extension? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 5.14 I want to compile a Python module on my Linux system, but some files are missing. Why? . . . . . 62 5.15 How do I tell “incomplete input” from “invalid input”? . . . . . . . . . . . . . . . . . . . . . . . . 62 5.16 How do I find undefined g++ symbols __builtin_new or __pure_virtual? . . . . . . . . . . . . . . 65 5.17 Can I create an object class with some methods implemented in C and others in Python (e.g. through inheritance)? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 6 Python on Windows FAQ 67 6.1 How do I run a Python program under Windows? . . . . . . . . . . . . . . . . . . . . . . . . . . 67 6.2 How do I make Python scripts executable? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 6.3 Why does Python sometimes take so long to start? . . . . . . . . . . . . . . . . . . . . . . . . . . 68 6.4 How do I make an executable from a Python script? . . . . . . . . . . . . . . . . . . . . . . . . . 68 6.5 Is a$_{*.pyd}$ file the same as a DLL? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 6.6 How can I embed Python into a Windows application? . . . . . . . . . . . . . . . . . . . . . . . . 69 6.7 How do I keep editors from inserting tabs into my Python source? . . . . . . . . . . . . . . . . . . 70 6.8 How do I check for a keypress without blocking? . . . . . . . . . . . . . . . . . . . . . . . . . . 70 7 Graphic User Interface FAQ 71 7.1 General GUI Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 7.2 What platform-independent GUI toolkits exist for Python? . . . . . . . . . . . . . . . . . . . . . 71 7.2.1 Tkinter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 7.2.2 wxWidgets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 7.2.3 Qt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 7.2.4 Gtk+ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 7.2.5 Kivy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 7.2.6 FLTK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 7.2.7 OpenGL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 7.3 What platform-specific GUI toolkits exist for Python? . . . . . . . . . . . . . . . . . . . . . . . . 72 7.4 Tkinter questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 7.4.1 How do I freeze Tkinter applications? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 7.4.2 Can I have Tk events handled while waiting for I/O? . . . . . . . . . . . . . . . . . . . . 73 7.4.3 I can’t get key bindings to work in Tkinter: why? . . . . . . . . . . . . . . . . . . . . . . 73 8 “Why is Python Installed on my Computer?” FAQ 75 8.1 What is Python? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 8.2 Why is Python installed on my machine? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 8.3 Can I delete Python? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 A Glossary 77 iv