See All Titles |
![]() ![]() Python on Win32 SystemsAs you might know at this point, Python has an official distribution for Win32 systems (Windows 95, Windows 98, Windows 2000, and Windows NT), called Pythonwin. In order to extend this distribution to its full power, you must get an installation package that contains Python Win32 Extensions. This set of extensions for Python exposes a good part of the Win32 API, along with other Win32 extensions. These extensions are part of the win32all installation package, which is available for download (including the source code) at http://www.python.org/windows/win32/ You can obtain more detailed and up-to-date information at Mark Hammond starship's page. He is the creator and maintainer of these extensions. http://starship.python.net/crew/mhammond/ After you download the latest win32all package, you will have access to the Microsoft Foundation Classes, the ODBC interface, the Microsoft Common Object Model (COM), and to several Windows NT services. For details about the COM interface, see Chapters 7, "Objects Interfacing and Distribution," and 8, "Working with Databases" , of this book. More information about using COM in a Python environment can be obtained at a COM Tutorial presented by Greg Stein and Mark Hammond, on a presentation given at IPC-6. http://www.python.org/windows/win32com/COMTutorial/ppframe.htm The following list shows the most important modules that are provided as part of the win32all package.
The next couple of paragraphs expose you to third-party programs created to handle specific Windows tasks. Note that many of these tasks can be replicated by writing programs that access the Win32 API. The first thing I will discuss is about how to load and use DLL files from Python running under MS Windows. My suggestion for you is to use Sam Rushing's calldll extension, which allows you to call functions in any DLL. This extension is part of the dynawin package, a completely developed Win32 GUI development environment. Also provided, there is a callback generator that lets external functions call back into Python as if it were C, and an ODBC module implemented using calldll (additional code for managing data sources, installing ODBC itself, and creating and maintaining Jet (Microsoft Access) databases is supplied, as well). For more information, check out http://www.nightmare.com/~rushing/dynwin/ By looking at http://www.nightmare.com/software.html, you can download a good number of Win32-specific software that was also created by Rushing. At Ken Seehof's Python Page, you can find several programs for the Windows platform, such as the Neural Integrator—a visual programming environment for prototyping neural networks and other directed graph-based programming models that can bring AI capabilities to your program. Once there, you can also obtain Wizard applications for the Pythonwin IDE, which can simplify many of your tasks, including the creation of extension modules. Be sure to have Visual C++ and Pythonwin, before trying to use the Wizards. Check out the following site: http://starship.python.net/crew/seehof/ Windows programmers sometimes have the requirement to make changes on the Windows Registry. The win32all package contains a very interesting script, which is installed at the subdirectory win32/scripts/regsetup.py that enables you to edit the Windows Registry. Another thing that we are always in need of is printing. It is your choice whether you use the Win32 API to handle that, or use a third-party module. The one that I mention here is a class developed by Bill Mailloux to print text to Windows printers. You can download the class at the following address: http://musingattheruins.homepage.com/printer.html The next example gives you a quick demonstration of how simple it is to use this module. import printer driver = printer.Printer() driver.open() driver.write("This sentence is going to be printed.") driver.close() del driver If you want to install Python 2.0 on a Windows NT or Windows 2000 machine, you don't necessarily need to have administrator priviledges. If you have them, great! Python will write its registry info under the key HKEY_LOCAL_MACHINE. However, if you don't have admin rights, Python will write its registry info under the key HKEY_CURRENT_USER. The only difference between both kinds of installations is that the latter option blocks some specific functionalities, such as running Python scripts as NT services. Note that all the core functionality remains available for you in both installations.
|
Index terms contained in this sectionadmin rightsinstallations administrator privileges installations callback generator calldll extension extensions calldll generators callback Hammond, Mark installations administrator privileges Ken Mailloux, Bill modules win32all package packages win32all 2nd printing text, Windows printers privileges administrator installations registries writing rights admin installations running Python Win32 2nd 3rd Rushing, Sam text printing, Windows printers Win32 running Python 2nd 3rd win32all package 2nd writing registries |
© 2002, O'Reilly & Associates, Inc. |