1. Trang chủ
  2. » Công Nghệ Thông Tin

OReilly python programming on win32 jan 2000 ISBN 1565926218

786 48 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 786
Dung lượng 6,78 MB

Nội dung

A— Key Python Modules and Functions The Python library is huge (231 files in the latest Windows distribution), but a full library reference in HTML format is included with every Python installation You may also download printable versions in PostScript or PDF formats from www.python.org and circulate copies without restriction: the document is a similar size to this book As a convenience to the armchair reader we have included the key functions and modules that are likely to be used by most nontrivial programs These are nearly direct reproductions from the Python Library The Python Library is also Open Source, but we are required to include this copyright notice: The Python Library Reference is Copyright © 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, The Netherlands All Rights Reserved Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the names of Stichting Mathematisch Centrum or CWI or Corporation for National Research Initiatives or CNRI not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission This appendix covers: • Methods of built-in types such as lists, dictionaries, and files • Built-in functions • The sys module • The os and os.path modules • The string module Built-in Types The following sections describe the standard types that are built into the interpreter These are the numeric types, sequence types, and several others, including types themselves There is no explicit boolean type; use integers instead Some operations are supported by several object types; in particular, all objects can be compared, tested for truth value, and converted to a string (with the notation ' …') The latter conversion is implicitly used when an object is written by the print statement Truth Value Testing Any object can be tested for truth value, to use in an if or while condition or as operand of the boolean operations below The following values are considered false: • None • Zero of any numeric type, e.g., 0, 0L, 0.0 • Any empty sequence, e.g., '', (), [] • Any empty mapping, e.g., {} • Instances of user-defined classes, if the class defines a nonzero () or len ()- method, when that method returns zero All other values are considered true, so objects of many types are always true Operations and built-in functions that have a boolean result always return 0 for false and 1 for true, unless otherwise stated Important exceptions are the boolean operations or and and, which always return one of their operands Boolean Operations The following table depicts the boolean operations, ordered by ascending priority Operation Result Notes x or y x and y not x If x is false, then y, else x If x is false, then x, else y If x is false, then 1, else 0 1 Notes These evaluate their second argument only if needed for their outcome ''Not" has a lower priority than non-boolean operators, e.g., not a == b is interpreted as not(a == b), and a == not b is a syntax error Comparisons Comparison operations are supported by all objects They have the same priority (which is higher than that of the boolean operations) Comparisons can be chained arbitrarily e.g., x < y > count = 2 >>> language = 'Python' >>> print'%(language)s has %(count)03d quote types.' % vars() Python has 002 quote types >>> In this case no * specifiers may occur in a format (since they require a sequential parameter list) Additional string operations are defined in standard module string and in builtin module re * A tuple object in this case should be a singleton ** These numbers are fairly arbitrary They are intended to avoid printing endless strings of meaningless digits without hampering correct use and without having to know the exact precision of floating-point values on a particular machine Mutable Sequence Types List objects support additional operations that allow in-place modification of the object These operations would be supported by other mutable sequence types (when added to the language) as well Strings and tuples are immutable sequence types, and such objects can't be modified once created The operations in the following table are defined on mutable sequence types (where x is an arbitrary object) Operation s[i] = x s[i:j] = t Result Item i of s is replaced by x Slice of s from i to j is replaced by t Notes del s[i:j] Same as s[i:j] = [] s.append(x) Same as s[len(s) :len(s)] = [x] s.extend(x) s.count(x) Same as s[len(s) :len(s)] = x Return number of i's for which s[i] == x s.index(x) s.insert(i, x) Return smallest i such that s[i] == x Same as s[i:i] = [x] if i >= 0 s.pop([i]) Same as x = s[i]; del s [i]; return x s.remove(x) Same as del s[s.index(x)] s.reverse() Reverses the items of s in place s.sort ([cmpfunc]) Sort the items of s in place 2,3 Notes This raises an exception when x is not found in s The sort() method takes an optional argument specifying a comparison function of two arguments (list items) that should return -1, 0, or 1 depending How to Contact Us Please address comments and questions concerning this book to the publisher: O'Reilly & Associates 101 Morris Street Sebastopol, CA 95472 1-800-998-9938 (in United States or Canada) 1-707-829-0515 (international or local) 1-707-829-0104 (fax) You can also send us messages electronically To be put on the mailing list or request a catalog, send email to info@oreilly.com To ask technical questions or comment on the book, send email to bookquestions@oreilly.com We have a web site for the book, where we list errata and any plans for future editions You can find it at http://www.oreilly.com/catalog/pythonwin32/ For more information about this book and others, see the O'Reilly web site http://www.oreilly.com Acknowledgments Although we were warned about what it takes to write a book like this, we were still not prepared! Many people contributed to this book and assisted with the enormous workload it involved The support of Guido van Rossum, the author of the Python language, for the Windows version of Python has enabled it to develop into a serious contender for most Windows development work Guido somehow manages to balance the opposing forces of maintaining platform independence and allowing Python to take advantage of the platform's unique features The wonderful Python community also has itself to thank for allowing this book to come to fruition The Python newsgroup seems to be one of the final bastions of Usenet where spams are ignored, newbies are treated kindly, and trolls are either ignored or quickly turned into a serious and on-topic discussion Many smart and friendly people hang out on the newsgroup, and it's one of the more esoteric reasons many people find using the language enjoyable The following people have provided invaluable help, whether with full reviews, in-depth knowledge of particular areas, or informal feedback: Guido van Rossum, Gordon McMillan, Greg Stein, Marc-André Lemburg, Christian Tismer, Gary Herron, Robin Dunn, Mike Da Silva, Richard Kennedy, and Damien Watkins Many others too numerous to mention, have played a part in shaping the book, whether in direct correspondence with us or in developing and working with the packages in this book At O'Reilly, we'd like to thank Robert Denn, Steven Abrams, and probably a whole bunch of other people we have never heard of Most important of all, Mark and Andy both wish to thank their families for their support and incredible patience, and they promise not to do this again any time soon Back TABLE OF CONTENTS Preface I Introduction to Python What Is Python? Language Features Python as an Integration Tool Case Studies of Python Deployment The Python Community Installation and Setup Conclusion Python Language Review A Crash Course Conclusion References Python on Windows The Python Core on Windows The Python for Windows Extensions The Python Imaging Library (PIL) PyOpenGL Web Publishing Tools The mx Extensions Scientific Tools XML Conclusion Integrated Development Environments for Python The PythonWin IDE IDLE Conclusion Introduction to COM What It Is Using COM Objects from Python Implementing COM Objects with Python Globally Unique Identifiers Conclusion II Building an Advanced Python Application A Financial Modeling Toolkit in Python Doubletalk A Crash Course in Accounting The Doubletalk Toolkit at Work Conclusion Building a GUI with COM Designing COM Servers A VB Client Writing a Delphi User Interface Conclusion Adding a Macro Language Dynamic Code Evaluation Making an Application Extensible Conclusion Integration with Excel Client-Side COM and the Excel Object Model Excel Concluded Putting It All Together: Importing Financial Data Server-Side COM Again: Excel as a GUI Conclusion References 10 Printed Output Business Requirements Automating Word Direct Output to the Printer with Windows PIDDLE: A Python Graphics API PostScript Portable Document Format Putting It Together: A High-Volume Invoicing System Conclusion References 11 Distributing Our Application DCOM Conclusion III Python on Windows Cookbook 12 Advanced Python and COM Advanced COM Python and COM Using Automation Objects from Python Using Other COM Interfaces Error Handling Implementing COM Objects in Python Python and DCOM Conclusion 13 Databases DAO, ADO, ODBC, OLEDB, and Other GBFLAs Python's Database API Getting at Your Data A Note on Speed Gadfly, the Pure Python Relational Database Data Laundering with Python A Three-Tier Architecture with Business Objects Conclusion References 14 Working with Email SMTP and POP3 Microsoft Exchange/Outlook Conclusion 15 Using the Basic Internet Protocols HTTP and HTML FTP NNTP Conclusion 16 Windows NT Administration Working with Users and Groups Server and Share Information Rebooting a Machine Conclusion References 17 Processes and Files Portable File Manipulation Native File Manipulation: The win32file Module Pipes Processes Conclusion 18 Windows NT Services Services in Brief Controlling Services with Python Reading the Event Log Windows NT Performance Monitor Data Writing Services in Python Sample Service Written in Python Writing to the Event Log Providing Performance Monitor Information A Final Service Conclusion 19 Communications Serial Communications Remote Access Services Sockets Other Communications Tools Conclusion References 20 GUI Development Tkinter PythonWin wxPython 21 Active Scripting Registering the Python Active Script Support Python and Popular Microsoft Applications Active Debugging How Active Scripting Works Active Script Hosting in Python Conclusion 22 Extending and Embedding with Visual C++ and Delphi Python and Visual C++ Simplified Wrapper and Interface Generator Python and Delphi Dynamic DLL Access References Conclusion IV Appendixes A Key Python Modules and Functions B Win32 Extensions Reference C The Python Database API Version 2.0 D Threads Index Back ... ‘/usr/local/lib /python1 .5/os.pyc’> Classes and Class Instances See Chapters 3 and 7 of the Python reference manual Functions Function objects are created by function definitions The only operation on a... Key Python Modules and Functions The Python library is huge (231 files in the latest Windows distribution), but a full library reference in HTML format is included with every Python installation... author or maintainer of your Python interpreter Be sure to report the version string of the Python interpreter (sys.version, also printed at the start of an interactive Python session), the exact error message (the exception's associated

Ngày đăng: 26/03/2019, 16:30

TỪ KHÓA LIÊN QUAN