From pythonguy@Hotpop.com Fri Aug 1 00:16:06 2003 From: pythonguy@Hotpop.com (Anand Pillai) Date: 31 Jul 2003 16:16:06 -0700 Subject: HarvestMan 1.1 Message-ID: HarvestMan, is a mulyithreaded, highly customizable command line offline browser written completely in python. It allows one to download websites or specific files from websites to the hard disk for offline browsing. The project page is situated at http://members.lycos.co.uk/anandpillai. Version 1.1 with many changes, fixes and updates is available for download and review. Freshmeat: http://www.freshmeat.net/projects/harvestman Thanks to everyone who used the program, reviewed it and sent in their suggestions. ~Anand Pillai From falted@openlc.org Fri Aug 1 00:20:56 2003 From: falted@openlc.org (Francesc Alted) Date: Fri, 1 Aug 2003 01:20:56 +0200 Subject: ANN: PyTables 0.7 released Message-ID: Announcing PyTables 0.7 ----------------------- PyTables is a hierarchical database package designed to efficently manage very large amounts of data. PyTables is built on top of the HDF5 library and the numarray package and features an object-oriented interface that, combined with C-code generated from Pyrex sources, makes it a fast, yet extremely easy to use tool for interactively save and retrieve large amounts of data. Release 0.7 is the third public beta release. The version 0.6 was internal and will never be released. On this release you will find: - new AttributeSet class - 25% I/O speed improvement - fully multidimensional table cells support - new column descriptors - row deletion in tables is finally here - much more! More in detail: What's new ----------- - A new AttributeSet class has been added. This will allow the addition and deletion of generic attributes (any scalar type plus any Python object supported by Pickle) as easy as this: table.attrs.date = "2003/07/28 10:32" # Attach a string to table group._v_attrs.tempShift = 1.2 # Attach a float to group array.attrs.detectorList = [1,2,3,4] # Attach a list to array del array.attrs.detectorList # Detach detectorList attr from array - PyTables now has support for fully multidimensional table cells. This has been made possible in part by implementation of multidimensional cells in numarray.records.RecArray object. Thanks to numarray crew, and especially to Jin-chung Hsu, for willingly accepting to do that, and also for including some cache improvements in RecArray. - New column descriptors added: IntCol, Int8Col, UInt8Col, Int16Col, UInt16Col, Int32Col, UInt32Col, Int64Col, UInt64Col, FloatCol, Float32Col, Float64Col and StringCol. I think they are more explicit and easy-to-use than the now deprecated (but still supported) Col() descriptor. All the examples and user's manual has been accordingly updated. - The new Table.removeRows(start, stop) function allows you to remove rows from tables. This feature was requested a long time ago. There are still limitations, however: you cannot delete rows in extremely large Tables (as the remaining rows after the stop parameter are stored in memory). Nor is the performance optimized. These issues will hopefully be addressed in future releases. - Added iterators to File, Group and Table (they now support the special __iter__() method). They make the object much more user-friendly, especially in interactive mode. See documentation for usage examples. - Added a __getitem__() method to Table that works more or less like read(), but with extended slices support. - As a consequence of rewriting table iterators in C (with the help of Pyrex, of course) the table read performance has been improved between 20% and 30%. Data selections in PyTables are now starting to beat powerful relational databases like SQLite, even compared to in-core selects (!). I think there is still room for another 20% or 30% speed improvement, so stay tuned. - A checksum is now added automatically when using LZO (not with UCL where I'm having some difficulties implementing that capability). The Adler32 algorithm has been chosen because of its speed. With that, the compressing/decompressing speed has dropped 1% or 2%, which is hardly noticeable. I think this addition will allow the cautious user to be a bit more confident about this excellent compressor. Code has been added to be able to read files created without this checksum (so you can be confident that you will be able to read your existing files compressed with LZO and UCL). - Recursion has been removed from PyTables. Before, this made the maximum depth tree to be less than the Python recursion limit (which depends on implementation, but is around 900, at least in Linux). Now, the limit has been set (somewhat arbitrarily) at 2048. Thanks to John Nielsen for implementing the new iterative method!. - A new rootUEP parameter to openFile() has been added. You can now define the root from which you want to start to build the object tree. Thanks to John Nielsen for the suggestion and a first implementation. - A small bug fixed when dealing with non-native PyTables files that prevented the use of the "classname" filter during a listNodes() call. Thanks to Jeff Robbins for reporting that. - Some (non-serious) bugs were discovered and fixed. - Updated documentation to explain all these new bells and whistles. It is also available on the web: http://pytables.sourceforge.net/html-doc/usersguide-html.html - Added more unit tests (more than 350 now!) - PyTables 0.7 *needs* numarray 0.6 or higher and HDF-1.6.0 or higher to compile and work. It has been tested with Python 2.2 and 2.3 and should work fine on both versions. What is a table? ---------------- A table is defined as a collection of records whose values are stored in fixed-length fields. All records have the same structure and all values in each field have the same data type. The terms "fixed-length" and "strict data types" seems to be quite a strange requirement for an language like Python, that supports dynamic data types, but they serve a useful function if the goal is to save very large quantities of data (such as is generated by many scientific applications, for example) in an efficient manner that reduces demand on CPU time and I/O resources. What is HDF5? ------------- For those people who know nothing about HDF5, it is is a general purpose library and file format for storing scientific data made at NCSA. HDF5 can store two primary objects: datasets and groups. A dataset is essentially a multidimensional array of data elements, and a group is a structure for organizing objects in an HDF5 file. Using these two basic constructs, one can create and store almost any kind of scientific data structure, such as images, arrays of vectors, and structured and unstructured grids. You can also mix and match them in HDF5 files according to your needs. Platforms --------- I'm using Linux as the main development platform, but PyTables should be easy to compile/install on other UNIX machines. This package has also passed all the tests on a UltraSparc platform with Solaris 7 and Solaris 8. It also compiles and passes all the tests on a SGI Origin2000 with MIPS R12000 processors and running IRIX 6.5. Regarding Windows platforms, PyTables has been tested with Windows 2000 and Windows XP, but it should also work with other flavors. An example? ----------- For online code examples, have a look at http://pytables.sourceforge.net/tut/tutorial1-1.html and http://pytables.sourceforge.net/tut/tutorial1-2.html Web site -------- Go to the PyTables web site for more details: http://pytables.sourceforge.net/ Share your experience --------------------- Let me know of any bugs, suggestions, gripes, kudos, etc. you may have. Have fun! -- Francesc Alted falted@openlc.org From abulka@netspace.net.au Fri Aug 1 04:55:31 2003 From: abulka@netspace.net.au (Andy Bulka) Date: 31 Jul 2003 20:55:31 -0700 Subject: Bookmarking Plug-in for IDLE Message-ID: IDLE, the default python editor does not have a bookmarking facility. Nor does there seem to be a page dedicated to python IDLE plug-ins. So... Bookmarking Plug-in for IDLE - a simple book-marking plug-in for IDLE. Lets you hit F2 and add a bookmark. See http://www.atug.com/andypatterns/idle_bookmarker.htm I am also hosting a couple of other IDLE plug-ins which do not seem to have a home, namely: Smart Templates - lets you type a few letters, hit ALT-J and template code is squirted into your idle editor. You can then press ALT-H to jump between parts of the new template text. Recently Used Files list - remembers the last n files you have opened in IDLE. http://www.atug.com/andypatterns/idle_plugins.htm -Andy Bulka http://www.atug.com/andypatterns From h.goebel@goebel-consult.de Fri Aug 1 07:26:46 2003 From: h.goebel@goebel-consult.de (Hartmut Goebel) Date: Fri, 01 Aug 2003 08:26:46 +0200 Subject: ANN: managesieve 0.3 Message-ID: Announcing: managesieve =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Version 0.3 A MANGAGESIEVE client library for remotely managing Sieve scripts, including an interactive 'sieveshell'. This module allows accessing a Sieve-Server for managing Sieve scripts there. For more information about the MANAGESIEVE protocol see draft http://www.ietf.org/internet-drafts/draft-martin-managesieve-04.txt . Changes since 0.2 ----------------- * managesieve: - MANAGESIEVE.authenticate() now only returns a OK/NO/BYE result like any command not asking data from the server * sieveshell: - added 'edit', which may create scripts, too. (posix only) - now prints out the server capabilities, thus the user knows what ther server is capable of (and which Sieve-Commands may be used). - fixed some minor bugs - sieveshell was missing in archive What is MANAGESIEVE? -------------------- Sieve scripts allow users to filter incoming email. Message stores are commonly sealed servers so users cannot log into them, yet users must be able to update their scripts on them. This module implements a protocol "managesieve" for securely managing Sieve scripts on a remote server. This protocol allows a user to have multiple scripts, and also alerts a user to syntactically flawed scripts. This an interim measure as it is hoped that eventually Sieve scripts will be stored on ACAP. Availablity ----------- 'managesieve' is available for download at http://www.crazy-compilers.com/py-lib/managesieve.html Requirements ------------ Requires Python >=3D 2.0 Not yet implemented ------------------- - Only athentication method LOGIN is currently supported. - STARTTLS is not yet implemented. - sieve-names are only quoted dump (put into quotes, but no escapes yet). Copyright/License ----------------- (C) Copyright 2003 by Hartmut Goebel License: Python Software Foundation License http://www.opensource.org/licenses/PythonSoftFoundation.html License for 'sieveshell' and test suite: GPL http://www.opensource.org/licenses/gpl-license.php Credits ------- Based on Sieve.py from Ulrich Eck which is part of of 'ImapClient' (see http://www.zope.org/Members/jack-e/ImapClient), a Zope product. Some ideas taken from imaplib written by Piers Lauder et al. --=20 Regards Sch=F6nen Gru=DF Hartmut Goebel --=20 | Hartmut Goebel | IT-Security -- effizient | | h.goebel@goebel-consult.de | www.goebel-consult.de | From gtalvola@nameconnector.com Fri Aug 1 17:06:20 2003 From: gtalvola@nameconnector.com (Geoffrey Talvola) Date: Fri, 1 Aug 2003 12:06:20 -0400 Subject: Webware for Python 0.8.1 released Message-ID: Webware 0.8.1 has been released. It includes an important security fix. All users are encouraged to upgrade. Webware provides a suite of Python components for developing Web applications. It includes an App Server, Servlets, Python Server Pages, Object-Relational mapping, Task Scheduling, Session management, and many other features. Webware is very modular, and easily extended. Check out the Webware for Python home for documentation, and download instructions at http://webware.sourceforge.net/ From jason@tishler.net Sat Aug 2 01:55:06 2003 From: jason@tishler.net (Jason Tishler) Date: Fri, 1 Aug 2003 20:55:06 -0400 Subject: Updated Cygwin Package: python-2.3-1 Message-ID: New News: === ==== I have updated the version of Python to 2.3-1. The tarballs should be available on a Cygwin mirror near you shortly. Note this package was built against Cygwin 1.3.22-1. Hence, it is *not* a 64-bit, Cygwin 1.5.x test package. Old News: === ==== Python is an interpreted, interactive, object-oriented programming language. If interested, see the Python web site for more details: http://www.python.org/ Please read the README file: /usr/doc/Cygwin/python-2.3.README since it covers requirements, installation, known issues, etc. To update your installation, click on the "Install Cygwin now" link on the http://cygwin.com/ web page. This downloads setup.exe to your system. Then, run setup and answer all of the questions. Note that we have recently stopped downloads from sources.redhat.com (aka cygwin.com) due to bandwidth limitations. This means that you will need to find a mirror which has this update. In the US, ftp://mirrors.rcn.net/mirrors/sources.redhat.com/cygwin/ is a reliable high bandwidth connection. In Germany, ftp://ftp.uni-erlangen.de/pub/pc/gnuwin32/cygwin/mirrors/cygnus/ is usually pretty good. In the UK, http://programming.ccp14.ac.uk/ftp-mirror/programming/cygwin/pub/cygwin/ is usually up-to-date within 48 hours. If one of the above doesn't have the latest version of this package then you can either wait for the site to be updated or find another mirror. The setup.exe program will figure out what needs to be updated on your system and will install newer packages automatically. If you have questions or comments, please send them to the Cygwin mailing list at: cygwin@cygwin.com . I would appreciate if you would use this mailing list rather than emailing me directly. This includes ideas and comments about the setup utility or Cygwin in general. If you want to make a point or ask a question, the Cygwin mailing list is the appropriate place. *** CYGWIN-ANNOUNCE UNSUBSCRIBE INFO *** If you want to unsubscribe from the cygwin-announce mailing list, look at the "List-Unsubscribe: " tag in the email header of this message. Send email to the address specified there. It will be in the format: cygwin-announce-unsubscribe-you=yourdomain.com@cygwin.com Jason -- PGP/GPG Key: http://www.tishler.net/jason/pubkey.asc or key servers Fingerprint: 7A73 1405 7F2B E669 C19D 8784 1AFD E4CC ECF4 8EF6 From uche.ogbuji@fourthought.com Sat Aug 2 05:41:58 2003 From: uche.ogbuji@fourthought.com (Uche Ogbuji) Date: 01 Aug 2003 22:41:58 -0600 Subject: ANN: Anobind 0.5.0 Message-ID: http://uche.ogbuji.net/tech/4Suite/anobind Anobind is a Python/XML data binding, which is just a fancy way of saying it's a very Pythonic XML API. You feed Anobind an XML document and it returns a data structure of corresponding Python objects. For example, the document What do you mean "bleh" But I was looking for argument Would become a set of objects so that you could write binding.monty.python.spam In order to get the value "eggs" or binding.monty.python[1].text_content() In order to get the value "But I was looking for argument". There are other such tools for Python, and what makes Anobind unique is that it's driven by a very declarative rules-based system for binding XML to the Python data. One can register rules that are triggered by XPatterns or plain Python code in order to register specialized binding behavior. It also offers XPath support and some support for round-tripping documents. Anobind is open source, provided under the 4Suite variant of the Apache license. It requires Python 2.2.2 and 4Suite 1.0a3. -- Uche Ogbuji Fourthought, Inc. http://uche.ogbuji.net http://4Suite.org http://fourthought.com XML Data Bindings in Python, Part 2 - http://www.xml.com/pub/a/2003/07/02/py-xml.html Introducing Examplotron - http://www-106.ibm.com/developerworks/xml/library/x-xmptron/ Charming Jython - http://www-106.ibm.com/developerworks/java/library/j-jython.html Python, Web services, and XSLT - http://www-106.ibm.com/developerworks/xml/library/ws-pyth13/ A custom-fit career in app development - http://www.adtmag.com/article.asp?id=7744 From raghuprasad@yahoo.com Sat Aug 2 15:06:33 2003 From: raghuprasad@yahoo.com (K Raghu Prasad) Date: 2 Aug 2003 07:06:33 -0700 Subject: PyBackend: A simple RDBMS backed object persistence framework Message-ID: Hi! I am glad to announce the availability of an RDBMS backed object persistence framework in Python. It is in beta version, which means some hidden bugs may be there. It is available under GNU LGPL. So you can try it in your commercial applications too. Following are some of its features, straight ripped out from the project page: * It can store (as well as retrieve) attributes of objects in (from) a relational database supporting atomic transactions. * It allows you to map individual classes to corresponding databases. Hence an application can use multiple databases to populate its objects; all transparent to the application programmer. * It stores all information pertaining to the classes, attributes, databases, database authentication and number of connections per database etc. in a single text based configuration file. * It frees the application programmer from the task of creating and managing database connections. It creates such connections on demand. Maximum number of database connections for each database can be specified as a configuration option. * If your class interact with the database in more complex ways, you can execute your queries directly too. In this case you need not manage any database connections at all. You will get a handle to the correct database to which your class is mapped. * It can ensure atomic transactions even over multiple discrete operations; like over multiple HTTP/XMLRPC requests. Though not used in normal object management, this feature can be quite handy when you want to reserve a database connection exclusively for a particular use, even in a multi threaded application. Details are available at its project page: http://pybackend.sourceforge.net Hope it helps someone:-) cheers Raghu From barry@python.org Sun Aug 3 05:30:47 2003 From: barry@python.org (Barry Warsaw) Date: 03 Aug 2003 00:30:47 -0400 Subject: New python-mode project at SourceForge Message-ID: I no longer have time to properly maintain python-mode.el, so in the fine open source tradition, I've started a SourceForge project and a mailing list for python-mode. Skip and Ken are co-admins of the project, so this way we can give people access to python-mode without going through the rigamarole of making them committers on the Python project. python-mode@python.org is the mailing list (it used to be just an alias). http://sf.net/projects/python-mode is the project. Both are only minimally set up at the moment (I couldn't access cvs tonight so I haven't installed python-mode.el yet). We still need to decide what to do about Misc/python-mode.el. I propose we do imports from the python-mode project at appropriate times. Anyone hacking on python-mode.el should stop doing that in the Python project. Feel free to subscribe to the mailingl ist if you want to help. -Barry From jylevy@pacbell.net Sun Aug 3 06:46:08 2003 From: jylevy@pacbell.net (Jacob Levy) Date: Sun, 03 Aug 2003 05:46:08 GMT Subject: [ANNOUNCE] e4Graph 1.0a8 released Message-ID: I am pleased to announce the 1.0a8 release of e4Graph, the seventh Alpha release. WHAT IS IT: e4Graph is a C++ library that allows programs to store graph-like data persistently and to access and manipulate that data efficiently. With e4Graph, you can arrange your data in the most natural form that reflects the relationships between its parts, rather than having to force it into a table-like format. The e4Graph library also allows you to concentrate on the relationships you want to represent, and not on how to store them in a database. You can modify data items, and add and remove connections and relationships between pieces of data on the fly. e4Graph allows you to represent an unlimited number of different connections between pieces of data, and your program can selectively manipulate the data according to the relationships it cares about, not having to know about other connections represented in the data set. The e4Graph package also provides bindings in several other languages, currently Tcl, Python and Java, and allows input/output of object graphs via an XML representation. The e4Graph package is built on top of Metakit 2.4.9.2, and optionally uses Tcl 8.4.4, Python 2.2.3, Java 1.1 or later, and Expat 1.95.5. WHERE TO GET: Downloads: http://sourceforge.net/projects/e4graph/ Homepage: http://www.e4graph.com/e4graph/ Changelog: http://www.e4graph.com/e4graph/changes.txt Installation: http://www.e4graph.com/e4graph/e4install.html WHAT IS NEW: Support for MacOS X 10.2 and several other platforms was added. Support for Python 2.2 and later releases was added. The Java binding was updated. The event mechanism was completely overhauled and support for user defined events was added. The vertex caching mechanism was moved from the Tcl binding to the core e4Graph library to enable other language bindings to benefit from the increased performance afforded by the cache. The interface between e4Graph and data base drivers was formalized in preparation for supporting new data base drivers in addition to Metakit. Additional work was done to support 64-bit systems and very large storages; more work is needed. Support for SWIG was added so new language bindings can be created with SWIG, in preparation for incorporating Perl, PHP and Ruby bindings in the next release. Many bugs were fixed. ACKNOWLEDGMENTS: Michael Krimerman contributed the Python binding. J.P. Fletcher helped me get started with SWIG support. Daniel Steffen and Nicholas Brawn were instrumental helping with MacOS X support. I wish to acknowledge support from the HP test-drive facility and from the SourceForge compile farm. Many people (too many to mention) contributed bug reports and bug fixes. Geoff Shapiro and David Van Maren suggested many useful API changes. From jyl@e4graph.com Sun Aug 3 20:35:47 2003 From: jyl@e4graph.com (Jacob Levy) Date: 3 Aug 2003 12:35:47 -0700 Subject: [ANNOUNCE] e4Graph 1.0a8 released Message-ID: I am pleased to announce the 1.0a8 release of e4Graph, the eight Alpha release. WHAT IS IT: e4Graph is a C++ library that allows programs to store graph-like data persistently and to access and manipulate that data efficiently. With e4Graph, you can arrange your data in the most natural form that reflects the relationships between its parts, rather than having to force it into a table-like format. The e4Graph library also allows you to concentrate on the relationships you want to represent, and not on how to store them in a database. You can modify data items, and add and remove connections and relationships between pieces of data on the fly. e4Graph allows you to represent an unlimited number of different connections between pieces of data, and your program can selectively manipulate the data according to the relationships it cares about, not having to know about other connections represented in the data set. The e4Graph package also provides bindings in several other languages, currently Tcl, Python and Java, and allows input/output of object graphs via an XML representation. The e4Graph package is built on top of Metakit 2.4.9.2, and optionally uses Tcl 8.4.4, Python 2.2.3, Java 1.1 or later, and Expat 1.95.5. WHERE TO GET: Downloads: http://sourceforge.net/projects/e4graph/ Homepage: http://www.e4graph.com/e4graph/ Changelog: http://www.e4graph.com/e4graph/changes.txt Installation: http://www.e4graph.com/e4graph/e4install.html WHAT IS NEW: Support for MacOS X 10.2 and several other platforms was added. Support for Python 2.2 and later releases was added. The Java binding was updated. The event mechanism was completely overhauled and support for user defined events was added. The vertex caching mechanism was moved from the Tcl binding to the core e4Graph library to enable other language bindings to benefit from the increased performance afforded by the cache. The interface between e4Graph and data base drivers was formalized in preparation for supporting new data base drivers in addition to Metakit. Additional work was done to support 64-bit systems and very large storages; more work is needed. Support for SWIG was added so new language bindings can be created with SWIG, in preparation for incorporating Perl, PHP and Ruby bindings in the next release. Many bugs were fixed. ACKNOWLEDGMENTS: Michael Krimerman contributed the Python binding. J.P. Fletcher helped me get started with SWIG support. Joe Mistachkin provided access to a FreeBSD host for testing. Daniel Steffen and Nicholas Brawn were instrumental helping with MacOS X support. I wish to acknowledge support from the HP test-drive facility and from the SourceForge compile farm. Many people (too many to mention) contributed bug reports and bug fixes. Geoff Shapiro and David Van Maren suggested many useful API changes. From alexander.dejanovski@laposte.net Mon Aug 4 14:16:51 2003 From: alexander.dejanovski@laposte.net (Alexander DEJANOVSKI) Date: Mon, 04 Aug 2003 15:16:51 +0200 Subject: Developping an EAI server in Python : looking for developpers In-Reply-To: Message-ID: --=====================_30913100==_.ALT Content-Type: text/plain; charset="us-ascii"; format=flowed Hi all, I'm starting a new project to develop an Open-Source EAI server in Python and I'm looking for motivated developpers and testers. It is inspired by Open Adaptor (www.openadaptor.org), but aims to be easier to use and more powerful. I've developped yet a first alpha that contains several components: File Source FTP Source HTTP Source FlatToXML Pipe XSLT Pipe File Sink FTP Sink SMTP Sink Upcoming components are : SOAP Source/Sink MQSeries Source/Sink JMS (?) Source/Sink Database Source/Sink and a GUI to create config files. Config files are XML files looking like this : Loggers tags permit to add logging handlers (new logging module of Python 2.3) I've created the project on SourceForge (approval in progress). --=====================_30913100==_.ALT Content-Type: text/html; charset="us-ascii" Hi all,

I'm starting a new project to develop an Open-Source EAI server in Python
and I'm looking for motivated developpers and testers.
It is inspired by Open Adaptor (www.openadaptor.org), but aims to be easier
to use and more powerful.

I've developped yet a first alpha that contains several components:

File Source
FTP Source
HTTP Source

FlatToXML Pipe
XSLT Pipe

File Sink
FTP Sink
SMTP Sink


Upcoming components are :

SOAP Source/Sink
MQSeries Source/Sink
JMS (?) Source/Sink
Database Source/Sink


and a GUI to create config files.
Config files are XML files looking like this :

<?xml version="1.0" encoding="UTF-8"?>
<retic_adaptor>
        <logger name="Log1" handler="FileHandler" fileName="c:\\logTest.out" format="%(asctime)s %(levelname)s %(message)s" level="WARNING" mode="w"/>
        <logger name="Log2" handler="FileHandler" fileName="c:\\logTest2.out" format="%(asctime)s %(levelname)s %(message)s" level="INFO" mode="w"/>

<source name="source1" type="fileSource" polls="1" pollPeriod="10" filePath="c:" fileFilter="ext_err.csv" newExtension="" newDir="">
        <pipe name="transform_to_XML1" type="ToXML" msgKind="delimited" delimiter=";" rootTag="racine" recTag="rec" encoding="UTF-8">
                <field name="message"/>
                <field name="date_traitement"/>
                <field name="ident"/>
                <field name="no_contrat"/>
                <field name="no_lt"/>
                <field name="date_lt"/>
                <field name="etat"/>
                <field name="date_heure_saisie"/>

                <sink name="outputToFile1" type="fileSink" filePath="c:\" fileName="test_sink.xml" addTimestamp="n"/>
                <pipe name="xslt1" type="XSLT" stylesheet="E:\\Xml\\XSL\\test.xsl">
                        <sink name="outputToFile2" type="fileSink" filePath="c:\" fileName="test_sink.html" addTimestamp="n"/>
                        <sink name="outputToFtpFile1" type="ftpSink" ftpHost="194.214.207.44" ftpPort="" ftpUser="guest" ftpPass="guest" filePath="/E:/ADI" fileName="test_sink.html" addTimestamp="n"/>
                </pipe>
        </pipe>
</source>
</retic_adaptor>

Loggers tags permit to add logging handlers (new logging module of Python
2.3)

I've created the project on SourceForge (approval in progress).



--=====================_30913100==_.ALT-- From pycon@python.org Mon Aug 4 21:35:22 2003 From: pycon@python.org (PyCon Committee) Date: Mon, 4 Aug 2003 16:35:22 -0400 Subject: PyCon DC 2004 Kickoff! Message-ID: [Posted to comp.lang.python/python-list, comp.lang.python.announce, zope-announce, pycon-announce, and python-dev.] [Please repost to local Python mailing lists.] Planning for PyCon DC 2004, the Python community conference, is now underway. DC 2004 will be held March 24-26, 2004 in Washington, D.C. It will contain many of the features of this year's successful conference, including a development sprint and a similar cost structure. Registration will be open by October 1. A Call For Proposals will be issued in the next two weeks. Presentations will be required in electronic form for publication on the web. PyCon DC 2003 had a broad range of presentations, from reports on academic and commercial projects to tutorials and case studies, and these will all be included in the Call For Proposals. As long as the presentation is interesting and potentially useful to the Python community, it will be considered for inclusion in the program. There will again be a significant amount of Open Space to allow for informal and spur-of-the-moment presentations for which no formal submission is required. There will also be several Lightning Talk sessions. These informal sessions are opportunities for those who don't want to make a formal presentation. We're looking for volunteers to help run PyCon. If you're interested, subscribe to http://mail.python.org/mailman/listinfo/pycon-organizers Don't miss any PyCon announcements! Subscribe to http://mail.python.org/mailman/listinfo/pycon-announce You can discuss PyCon with other interested people by subscribing to http://mail.python.org/mailman/listinfo/pycon-interest The central resource for PyCon DC 2004 is http://www.python.org/pycon/dc2004/ -- Aahz (aahz@pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From fredrik@pythonware.com Tue Aug 5 10:35:49 2003 From: fredrik@pythonware.com (Fredrik Lundh) Date: Tue, 5 Aug 2003 11:35:49 +0200 Subject: ANN: ElementTree 1.2 alpha 2, ElementTidy 1.0 alpha 1 Message-ID: The Element type is a simple but flexible container object, designed to store hierarchical data structures, such as simplified XML infosets, in memory. The ElementTree package provides a Python implementation of this type, plus code to serialize element trees to and from XML = files. The 1.2 alpha 2 release fixes some minor issues (most notably, nicer serialization of the "xml" default namespace). You can get the ElementTree toolkit from: http://effbot.org/downloads Brief documentation and some code samples (including an XML-RPC unmarshaller in 16 lines) are available from: http://effbot.org/zone/element-index.htm If you want more sample code, my blog currently features a number of short articles on parsing stuff with element trees (the first four all = deal with RSS and RSS-like formats): http://online.effbot.org/2003_07_01_archive.htm#element-tricks In a related release, the ElementTidy library provides an alternative tree builder that can read (almost) arbitrary HTML, and turn it into well-formed XHTML element trees. The ElementTidy library uses a library versions of Dave Raggett's HTML Tidy utility to do the clean- up (source code is included), and does not rely on external utilities. http://effbot.org/downloads http://effbot.org/zone/element-tidylib.htm enjoy /F From frank@pc-nett.no Mon Aug 4 10:41:53 2003 From: frank@pc-nett.no (frank) Date: Mon, 4 Aug 2003 11:41:53 +0200 Subject: ANN: soprano 0.002 Message-ID: Soprano is a GUI app that scans a selected range of ip addresses and try to get info about the hosts such as users, localgroups, shares, operating system. This program only runs under windows enviorment(tested under win2000, should work under xp to, unsure about win98) changes 0.001 > 0.002: added toolbar and menubar. auto features are now in menubar under options. added log window. users can now set "ping timeout". works with python 2.3. eliminated some bugs. Source code and windows binary at http://sourceforge.net/projects/soprano/ From martin.vonloewis@hpi.uni-potsdam.de Thu Aug 7 10:29:20 2003 From: martin.vonloewis@hpi.uni-potsdam.de (Martin v. Löwis) Date: Thu, 7 Aug 2003 11:29:20 +0200 Subject: Preview of Python 2.3 Installer for Win64 Itanium available Message-ID: I made an initial attempt at packaging Python 2.3 for Itanium, using Microsoft Installer. The result is available at http://www.dcl.hpi.uni-potsdam.de/home/loewis/python23.msi I have tested this installer on W2k3-IA64; it will not do anything useful on x86 hardware. There are a number of known problems: - A few tests fail. Most of these are apparently errors in the test suite and no need to worry. - Neither _tkinter nor _bsddb appear to work. Any insight on the cause of the problems, and possible solutions are appreciated. - De-installation will leave behind the .pyc files. Please let me know what you think. Martin v. Löwis From tom1@launchbird.com Thu Aug 7 21:00:28 2003 From: tom1@launchbird.com (Tom Hawkins) Date: 7 Aug 2003 13:00:28 -0700 Subject: ANN: Confluence 0.6 Message-ID: Confluence is a functional programming language for digital logic design (FPGA/ASIC) and real-time embedded software development. Confluence source code compiles into Verilog, VHDL, C, and Python for synthesis, implementation, and verification. The release of Confluence 0.6 includes many language and compiler improvements including simplified syntax, static connection analysis, and increased debugging visibility. Also in the release is a new unit testing framework for assertion based verification of Confluence programs and output code (HDL/C/Python). Test suites, packaged in the distribution, use the framework to verify the Confluence standard libraries and output code generators. Release Notes, Documentation, and Download: http://www.launchbird.com/download.html Online Compiler: http://www.launchbird.com/cgi-bin/compiler.py Confluence Mailing Lists: http://www.launchbird.com/mailinglists.html -- Tom Hawkins Launchbird Design Systems, Inc. 952-200-3790 tom1@launchbird.com http://www.launchbird.com/ From adalke@mindspring.com Thu Aug 7 21:13:05 2003 From: adalke@mindspring.com (Andrew Dalke) Date: Thu, 7 Aug 2003 14:13:05 -0600 Subject: sre_dump.py Message-ID: sre_dump.py -- http://www.dalkescientific.com/Python/ Converts an sre_parse parse tree back into a regular expression, and includes information about where subexpressions can be found in that string. I have a certain fondness for writing regular expression based parsers. /F's sre_parse module (an internal part of the standard library) has been very fun to use in these projects. It turns a regular expression into a simple parse tree, which I use to generate my own parsers. When debugging, I want to know which part of the regular expression contributed to the part of the parser with the bug. The sre_dump module helps by using the parse tree to recreate the original pattern and tracking where the branches are in the string. The result is that I can do >>> s, offsets = sre_dump.dump_and_offsets("AB|CD") >>> def show_offsets(s, offsets): ... print s ... for expr, i, j, text in offsets: ... print " "*i + "-"*(j-i) + " " *(len(s)-j+1), s[i:j] ... >>> show_offsets(s, offsets) AB|CD - A - B - C - D ----- AB|CD >>> Andrew dalke@dalkescientific.com From blackhawke@legacygames.net Fri Aug 8 02:14:57 2003 From: blackhawke@legacygames.net (BlackHawke) Date: Thu, 7 Aug 2003 18:14:57 -0700 Subject: Game Company looking for Employiees Message-ID: Hello! My name is Nick Soutter, I am the owner of a small game company in San Diego, CA called Aepox Games (www.aepoxgames.net). Our first product, Andromeda Online (www.andromedaonline.net), goes commercial in a few months. We are in pre-production of our second project, codenamed "Avalon". It is a MMORPG. We have started a working relationship with a hosting company which can host our game, to our specifications, with up to 1 millions simultaneous players online with no lag (butterfly.net, partnered with IBM, using an ingenious method of data management to offer stability, reliability, and ultra fast reaction time with no lag). Because we are a small company, cost is an extremely limiting factor. We don 't have a lot of funds to throw at this, though we hope the success of Andromeda Online will help. Our arrangement with butterfly.net will allow us to pay on demand- as we gain more subscribers, we pay them proportionately, drastically reducing our upfront costs. There are two areas we are now lacking: 1: We need python scripters. Much of the programming used for the servers must necessarily be in python. The bulk of our code will be in Python, and we have no access to Python programmers at the moment. 2: We need people capable of programming vast worlds in the CrystalSpace 3d engine. While we do have excellent graphic artists on hand, we have no-one capable of developing the lands and cities in this game. We have chosen CrystalSpace because of our financial concerns. We are looking for Python programmers, and CrystalSpace developers. We are hopefully going to be able to pay a decent wage, but probably not a fully commensurate salary. Our company is strapped for cash. In addition to pay, however, we have a lot to offer. We are offering the potential for a long term job (if Avalon does well, we'll need continued support for years to come). We are offering the chance to get in on the ground floor of a budding game company. We also believe fully in giving credit to those who work for us. For you budding programmers, this is the chance for a big project, where you are needed, appreciated, and your work will be public and commercial. We are in pre-development. We have not begun production. Production is not slated to begin for another 6 months. We would like people in the San Diego area, it makes things mildly easier. HOWEVER, it is not a requirement. Andromeda was done with most of us never physically meeting the programmer. We have strong internet management and development resources. At present, we are simply trying to get some names, get a feel for who might be interested, the kind of experience they may have, and what our resources may be before we begin. Anybody interested, please send me an email, with your resume, at nsoutter@aepoxgames.com. Please only send us your resume if you are interested. Sending us your resume is not a promise you will take the project, nor is accepting your resume a promise of getting a job. We are simply trying to see who is interested, and what they can do. Thank you for your time, and I hope you consider us. Nick Soutter Aepox Games From max@alcyone.com Fri Aug 8 04:53:38 2003 From: max@alcyone.com (Erik Max Francis) Date: Thu, 07 Aug 2003 20:53:38 -0700 Subject: ANN: EmPy 3.0.4 -- A powerful and robust templating system for Python Message-ID: Summary A powerful and robust templating system for Python. Overview EmPy is a system for embedding Python expressions and statements in template text; it takes an EmPy source file, processes it, and produces output. This is accomplished via expansions, which are special signals to the EmPy system and are set off by a special prefix (by default the at sign, '@'). EmPy can expand arbitrary Python expressions and statements in this way, as well as a variety of special forms. Textual data not explicitly delimited in this way is sent unaffected to the output, allowing Python to be used in effect as a markup language. Also supported are callbacks via hooks, recording and playback via diversions, and dynamic, chainable filters. The system is highly configurable via command line options and embedded commands. Expressions are embedded in text with the '@(...)' notation; variations include conditional expressions with '@(...?...!...)' and the ability to handle thrown exceptions with '@(...$...)'. As a shortcut, simple variables and expressions can be abbreviated as '@variable', '@object.attribute', '@function(arguments)', '@sequence[index]', and combinations. Full-fledged statements are embedded with '@{...}'. Control flow in terms of conditional or repeated expansion is available with '@[...]'. A '@' followed by a whitespace character (including a newline) expands to nothing, allowing string concatenations and line continuations. Comments are indicated with '@#' and consume the rest of the line, up to and including the trailing newline. '@%' indicate "significators," which are special forms of variable assignment intended to specify per-file identification information in a format which is easy to parse externally. Context name and line number changes can be done with '@?' and '@!' respectively. Escape sequences analogous to those in C can be specified with '@\...', and finally a '@@' sequence expands to a single literal at sign. Getting the software The current version of empy is 3.0.4. The latest version of the software is available in a tarball here: http://www.alcyone.com/pyos/empy/empy-latest.tar.gz. The official URL for this Web site is http://www.alcyone.com/pyos/empy/. Requirements EmPy should work with any version of Python from 1.5.2 onward. It has been tested with all major versions of CPython from 1.5 up, and Jython from 2.0 up (using Java runtimes 1.3 and 1.4). The included test script is intended to run on Unix-like systems with a Bourne shell. License This code is released under the GPL. .... Release history [since 3.0.3] - 3.0.4; 2003 Aug 7. Somewhat more robust lvalue parsing for '@[for]' construct (thanks to Beni Cherniavsky for inspiration). From aleax@aleax.it Fri Aug 8 12:48:37 2003 From: aleax@aleax.it (Alex Martelli) Date: Fri, 08 Aug 2003 11:48:37 GMT Subject: [ANNOUNCE] gmpy 1.0 alpha released Message-ID: See http://gmpy.sourceforge.net/ for details. What is it: a wrapper for the GMP library, to provide multi-precision arithmetic for Python. Multi-precision floats, and unbounded-precision rationals, are not present in stock Python; multi-precision integers ('long') are, but gmpy's version of multi-precision integers is faster for some operations (NOT all -- used to be, but Python 2.3 did serious enhancements to some operations on longs) and provides lots of nifty pre-packaged additional functions. Minor changes and bug-fixes since the latest 0.9 pre-alpha; support for Python 2.3. The Windows binary release is now for Python 2.3 _only_ (if you're stuck with Python 2.2 on Windows, you can keep using gmpy 0.9 pre-alpha and not really suffer from that). Known bug on Windows: the scan0 and scan1 functions appear broken (perhaps related to the lack of a GMP 4.0 library for Windows -- haven't found one around yet). Alex From duncan-news@grisby.org Fri Aug 8 14:43:05 2003 From: duncan-news@grisby.org (Duncan Grisby) Date: Fri, 08 Aug 2003 13:43:05 GMT Subject: omniORB 4.0.2 and omniORBpy 2.2 released Message-ID: omniORB version 4.0.2 and omniORBpy 2.2 are now available. omniORB is a robust, high performance CORBA ORB for C++. omniORBpy is a version for Python. They are freely available under the terms of the GNU LGPL. These are mainly bug fix releases. Highlights of the new releases include: - Bug fixes. - Use of standard iostreams in omniNames etc., if available. - Rudimentary Python interceptor support. - Performance improvements. The releases can be downloaded from SourceForge from this page: http://sourceforge.net/project/showfiles.php?group_id=51138 For general omniORB details, see this page: http://omniorb.sourceforge.net/ Enjoy! Duncan. -- -- Duncan Grisby -- -- duncan@grisby.org -- -- http://www.grisby.org -- From pyguy30@yahoo.com Fri Aug 8 22:22:06 2003 From: pyguy30@yahoo.com (john) Date: 8 Aug 2003 14:22:06 -0700 Subject: pytunnel 0.21 and urllib3.py Message-ID: pytunnel has been further updated with .netrc support and a automatic shutdown of the standalone process after it's been idle. As an example, I've also just started a wrapper for urllib2.py, for lack of a better name, I've called it urllib3.py. It ultimately calls urllib2.py to do the heavy lifting but first sets up up a tunnel (via by pytunnel). You would use it like: import urllib3 print urllib3.urlopen('https://login.yahoo.com/',ssl='proxy_server').read() The ssl option tells urllib3 to setup a tunnel with proxy_server. Both programs are at: http://savannah.nongnu.org/download/pytunnel/urllib3.py http://savannah.nongnu.org/download/pytunnel/pytunnel.py What is pytunnel? Pytunnel is a program that tunnels TCP/IP through another server like a proxy. A typical use would be to tunnel through an http proxy. Pytunnel supports basic http proxy authentication. Pytunnel allows your software to connect to the local tunnel rather than connecting to the remote server directly. For example, if doing SSL, instead connecting to the webhost on port 443 you connect to localhost using the locally determined port. Pytunnel makes use of several technologies asyncore, threads, and non-blocking sockets w\a custom recv_all to take advantage of that. The tunnel has no knowledge of the protocol being tunneled through it, instead, it keeps the tunnel alive as long as any bit of data, now matter how tiny, comes across it. Once the data stops after a user defined timeout, tunnel shuts down. This program can be either used as a library or standalone tunnel. john From brian@zope.com Sat Aug 9 04:46:58 2003 From: brian@zope.com (Brian Lloyd) Date: Fri, 08 Aug 2003 23:46:58 -0400 Subject: Python for .NET preview 2 release Message-ID: For those interested, I've made a preview-2 release of Python for .NET. Python for .NET is a near-seamless integration of the CPython runtime with the .NET Common Language Runtime (CLR). It lets you script and build applications in Python, using CLR services and components written in any language that targets the CLR (C#, Managed C++, VB.NET, etc.). Highlights of this release include array and indexer support, better thread handling, the ability to subclass managed classes in Python and many bug fixes. For more info or to download the release: http://zope.org/Members/Brian/PythonNet/ - Brian From and@doxdesk.com Sun Aug 10 13:12:15 2003 From: and@doxdesk.com (Andrew Clover) Date: Sun, 10 Aug 2003 12:12:15 +0000 Subject: Ann: PXTL, the Python XML Templating Language Message-ID: PXTL is the Python XML Templating Language, a templating solution for producing XML, HTML and other text-based document types. Yes, sorry - it's another templating language. However, PXTL has some useful characteristics shared by no other Python templating language (that I have met, at least): - templates are pure XML-with-Namespaces documents, allowing authors to take advantage of generic XML authoring, testing and manipulation tools; - code structure is represented by nodes in the document tree: making the document hierarchy and the program hierarchy the same results in templates that are easy to read, write and debug; - powerful Python-style structural tools such as subtemplates and imports allow modular templates to be written. The PXTL language spec has reached revision 1.0, release candidate. Documentation is here: http://doxdesk.com/pxtl/ See the tutorial for syntax examples. The reference implementation of PXTL (version 0.9) is also now available. It is a full DOM-based implementation of PXTL with following features: - on program error, can write a useful in-depth debugging page for testing, aiding rapid development; - can read and return DOM Document trees, not just serialised text; - works anywhere: pure-Python package compatible with Python 1.5.2 and later (tested up to 2.3), with no non-standard dependencies or reliance on any application framework. The reference implementation is intended for testing, development, batch jobs and interactive use on low-traffic web sites only. An 'optimised' implementation will be included in the package as a drop-in upgrade later in the year, for high-traffic web sites which require only text output. Documentation and download (licence: new-BSD-style) here: http://doxdesk.com/software/py/pxtl.html -- Andrew Clover mailto:and@doxdesk.com http://www.doxdesk.com/ From and@doxdesk.com Sun Aug 10 13:12:58 2003 From: and@doxdesk.com (Andrew Clover) Date: Sun, 10 Aug 2003 12:12:58 +0000 Subject: Ann: pxdom, a DOM implementation Message-ID: pxdom is a stand-alone pure-Python DOM implementation and non-validating parser, supporting Level 3 Core, XML, Load and Save specifications. pxdom was written to support the needs of PXTL, but is a general-purpose implementation suitable for any DOM-based application. It can be included as a module inside packages that must rely on a fully-working DOM regardless of what version of Python or PyXML is installed. The emphasis of pxdom is on standards compliance. It supports the W3C specifications fully, with only very minor deviations (namely: not all possible invalid Unicode characters are checked for, and it is lenient about what nodes a Document may contain, for whitespace-handling purposes in particular). pxdom passes the DOM L1/2 Core Test Suite. The emphasis of pxdom is *not* on efficiency. General speed and memory usage can be expected to be somewhere between minidom and 4DOM levels, nowhere near cDomlette. Exactly how slow pxdom is remains to be seen; currently it has only been tested with the DOM Test Suite (where it was much slower than minidom) and PXTL (where it was - inexplicably - considerably faster). YMMV. Because of the relatively small number of applications it has been tested with, and above all because the DOM Level 3 spec is still subject to change (though it is now at Last Call), pxdom 0.6 is considered beta software. pxdom is compatible with Python 1.5.2 and later (tested up to 2.3); for correct Unicode support Python 1.6 or later is required. It is available under a new-BSD-style licence from: http://www.doxdesk.com/software/py/pxdom.html -- Andrew Clover mailto:and@doxdesk.com http://www.doxdesk.com/ From cben@techunix.technion.ac.il Sun Aug 10 19:45:41 2003 From: cben@techunix.technion.ac.il (Beni Cherniavsky) Date: Sun, 10 Aug 2003 21:45:41 +0300 (IDT) Subject: series (was: streams (was: reiter))) In-Reply-To: References: Message-ID: Beni Cherniavsky wrote on 2003-08-10: > Thus I'm releasing the module under yet another name: > > http://www.technion.ac.il/~cben/python/series.py > > I'd like to stop the renamings at this stage, so if you don't like it, > speak now :-). > [Sorry, hit Send too soon...] Here is the summary of what this is: This module exposes the duality between linked lists and iterators: - Simple linked lists have the drawback that their tail must be known and finite. This can be fixed by overloading head/tail access and making it lazy; the result is popular in functional programming languages [1]_. This is implemented by the `Series` and `UncomputedSeries` classes. - Iterators have the drawback that advancing them is destructive but there is no way to capture the ''remaining future'' of an iterator at some moment. This can be fixed by making an iterator explicitly point to a series and allow separate iterators to be forked from it. This is implemented by the `SeriesIter` class. Another useful thing about linked lists is that you can non-destructively cons items in front of them. This is implemented by the `Series` class (which is also used to represent the part of series that has already been computed) and is also accessible through the `SeriesIter.unyield()` method. A convenince subscripting interface is provided for series. -- Beni Cherniavsky From cben@techunix.technion.ac.il Sun Aug 10 19:41:28 2003 From: cben@techunix.technion.ac.il (Beni Cherniavsky) Date: Sun, 10 Aug 2003 21:41:28 +0300 (IDT) Subject: series (was: streams (was: reiter))) Message-ID: I was reminded by Paul Foley that CL has an unambiguos name for the concept: "series". Well, actually what the series package in CL does is quite different from what I want but the name is very good so I'll borrow it anyway ;-). At a high enough level of abstraction, it's very related. Thus I'm releasing the module under yet another name: http://www.technion.ac.il/~cben/python/series.py I'd like to stop the renamings at this stage, so if you don't like it, speak now :-). Renaming details: - Module name: `streams` -> `series` - `Cons` -> `Series` - `Stream` -> `UncomputedSeries` (you don't have to ever type this name as `Series()` is now a factory creating an `UncomputedSeries` object when called with one argument). - `StreamIter` -> `SeriesIter` - `StreamIter.fork` -> `SeriesIter.copy` Also I squashed a bug in `__repr__` - it referenced an undefined variable. What -- Beni Cherniavsky From brett@python.org Sun Aug 10 22:23:57 2003 From: brett@python.org (Brett C.) Date: Sun, 10 Aug 2003 14:23:57 -0700 Subject: python-dev Summary for 2003-07-01 through 2003-07-31 Message-ID: python-dev Summary for 2003-07-01 through 2003-07-31 ++++++++++++++++++++++++++++++++++++++++++++++++++++ This is a summary of traffic on the `python-dev mailing list`_ from July=20 1, 2003 through July 31, 2003. It is intended to inform the wider=20 Python community of on-going developments on the list. To comment on=20 anything mentioned here, just post to python-list@python.org or=20 `comp.lang.python`_ with a subject line mentioning what you are=20 discussing. All python-dev members are interested in seeing ideas=20 discussed by the community, so don't hesitate to take a stance on=20 something. And if all of this really interests you then get involved=20 and join `python-dev`_! This is the twenty-first/twenty-second summary written by Brett Cannon=20 (who is still learning how to count; gave the wrong summary count last=20 month). All summaries are archived at http://www.python.org/dev/summary/ . Please note that this summary is written using reStructuredText_ which=20 can be found at http://docutils.sf.net/rst.html . Any unfamiliar=20 punctuation is probably markup for reST_ (otherwise it is probably=20 regular expression syntax or a typo =3D); you can safely ignore it,=20 although I suggest learning reST; its simple and is accepted for `PEP=20 markup`_ and gives some perks for the HTML output. Also, because of the=20 wonders of programs that like to reformat text, I cannot guarantee you=20 will be able to run the text version of this summary through Docutils_=20 as-is unless it is from the original text file. .. _PEP Markup: http://www.python.org/peps/pep-0012.html The in-development version of the documentation for Python can be found=20 at http://www.python.org/dev/doc/devel/ and should be used when looking=20 up any documentation on something mentioned here. Python PEPs (Python=20 Enhancement Proposals) are located at http://www.python.org/peps/ . To=20 view files in the Python CVS online, go to=20 http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/python/ . .. _python-dev: http://www.python.org/dev/ .. _python-dev mailing list:=20 http://mail.python.org/mailman/listinfo/python-dev .. _comp.lang.python: http://groups.google.com/groups?q=3Dcomp.lang.pytho= n .. _Docutils: http://docutils.sf.net/ .. _reST: .. _reStructuredText: http://docutils.sf.net/rst.html .. contents:: .. _last summary:=20 http://www.python.org/dev/summary/2003-06-01_2003-06-30.html =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Summary Announcements =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D It's experimentation time again! In preparation for having to cut down=20 on the breadth of the summary thanks to my return to school I am=20 starting this summary off as the inaugural release of the new format.=20 Pretty much everything is going to change somewhat. First, though, I think I should explain my new viewpoint towards the=20 summaries that I am taking. In order to continue to provide a certain=20 level of quality and coverage while retaining my personal sanity and to=20 not feel like the Summaries are a job instead of something I do for fun=20 and to help others, I am going to start viewing the Summaries more from=20 a journalistic perspective than a historical one. Before I felt more=20 like a historian that was summarizing *everything* that happened on=20 python-dev. Now, though, I am be more like a journalist, covering only=20 the pertinent ideas. This also allows me to inject more of my=20 personality into my writing. But what ramifications does this new perspective cause? Well, it will=20 dictate what I do and do not summarize. I plan on several types of=20 discussions to be covered in the Summaries. One is new features of the=20 language. This is so people can know about them ASAP and thus comment=20 on them. Since practically any feature mentioned here is experimental=20 there is a chance to remove it if a community movement mounts. I will=20 also cover any major thinking on the future of Python. I have always=20 wished there was an easy way to see what pie-in-the-sky ideas python-dev=20 was thinking of in the back of our collective mind; the summaries might=20 as well fill this desire. And of course any random discussion that is=20 large, important, and/or complex will continue to be covered. In terms of formatting and layout, that will also change along with the=20 new viewpoint. I am planning to follow something more along the lines=20 of the Perl's `This Week...=20 `__; yes, I am taking a cue=20 from Perl but AM Kuchling and Michael Hudson originally used this format=20 as well. This means titles of summary sections will more reflect the=20 topic being summarized rather than the specific thread(s). I will=20 continue to list all of the threads that contributed to the summary,=20 though, for reference purposes. I feel this will be beneficial since I=20 know I have personally looked back into the Summary archives and had a=20 hard time finding something specific since the subject of a thread does=20 not always match the topic of discussion; if I can't find something and=20 I know about what month it happened I can only imagine what everyone=20 else has had to go through to find something! I am removing the Quickies section from the Summaries. This section was=20 nice to have, but it just ate away at my time. This also goes along=20 with the new viewpoint. I am sure not everyone will be happy with this change, that's fine. But=20 if someone out there *truly* hates the direction I am going then they=20 can step forward and take the reigns from me. But as I have stated=20 before, the fine print on me giving up this post is that the person who=20 takes over must be as thorough as I *used* to be; I can do the summaries=20 in a half-assed fashion as well as anyone else. Enough of that topic. One thing I would like to mention is that the=20 `Python Software Foundation`_ can now accept donations through PayPal.=20 Specifics can be found at http://www.python.org/psf/donations.html . It=20 would be great if people could donate since the PSF is more than just a=20 non-profit to hold the Python intellectual property. One of the goals=20 of the group is to get enough money to do something like the Perl=20 Foundation does and sponsor someone to hack on Python for a living for a=20 set amount of time. Right now we are a ways off from having that kind=20 of revenue, but there is no reason why we can't. Heck, if we can just=20 get enough to sponsor one person to do full-time Python hacking for a=20 week it would be beneficial. Or better yet, the PSF could sponsor one=20 of their own members to write a summary of the python-dev mailing list=20 for the betterment of the community. =3D) .. _PSF: .. _Python Software Foundation: http://www.python.org/psf/ .. _PayPal: http://www.paypal.com/ =3D=3D=3D=3D=3D=3D=3D=3D=3D Summaries =3D=3D=3D=3D=3D=3D=3D=3D=3D -------------------------- Python 2.3 final released! -------------------------- In case for some odd reason you didn't know, Python 2.3 final has gone=20 out the door. The team managed to meet the goal of getting it out by=20 the end of the month so that Apple_ can use a final release instead of a=20 release candidate in OS X 10.3 (a.k.a. Panther). The goal of this release was to continue to improve Python without=20 adding any new keywords. This was met while speeding things up, fixing=20 bugs, adding to the standard library, and adding some new built-ins. To=20 find out what is new or has changed look at the changelog at=20 http://www.python.org/2.3/highlights.html or `What's New in Python 2.3`_. As with all software, there are bound to be bugs. What bugs that are=20 known are listed at http://www.python.org/2.3/bugs.html . If you find=20 bugs not listed there, please report them on the SourceForge bug tracker=20 at http://sourceforge.net/tracker/?group_id=3D5470&atid=3D105470 . Runni= ng=20 the regression test suite (details on how to do this is covered in the=20 documentation for the 'test' package as found at=20 http://www.python.org/doc/current/lib/module-test.html) is always=20 appreciated. Contributing threads: - `Problem with 2.3b2 tarfile?`__ - `MacPython 2.3b2 binary installer for MacOSX`__ - `Running tests on freebsd5`__ - `Python 2.3 release schedule update`__ - `Vacation and possibly a new bug`__ - `Doc/ tree closes at noon, US/Eastern`__ - `I've tagged the tree`__ - `cygwin errors`__ - `test_strptime; test_logging; test_time failure`__ - `2.3rc1 delayed`__ - `Python 2.3 release candidate 1`__ - `post-release festivities`__ - `New branch for r23c2 work`__ - `Serious CallTip Bug in IDLE`__ - `MacPython-OS9 test failures`__ - `Doc/ tree on trunk closed`__ - `Cutting the 2.3c2 tonight 8pm EDT`__ - `Re: [Python-checkins] python/dist/src/Misc NEWS,1.826,1.827`__ - `RELEASED Python 2.3c2`__ - `2.3rc2 IDLE problems on a Win2000sp3 box`__ - `Draft: 2.3 download page`__ - `Last priority >=3D 7 bug for Python 2.3`__ - `CVS Freeze`__ - `RELEASED Python 2.3 (final)`__ __ http://mail.python.org/pipermail/python-dev/2003-July/036669.html __ http://mail.python.org/pipermail/python-dev/2003-July/036732.html __ http://mail.python.org/pipermail/python-dev/2003-July/036762.html __ http://mail.python.org/pipermail/python-dev/2003-July/036783.html __ http://mail.python.org/pipermail/python-dev/2003-July/036845.html __ http://mail.python.org/pipermail/python-dev/2003-July/036892.html __ http://mail.python.org/pipermail/python-dev/2003-July/036899.html __ http://mail.python.org/pipermail/python-dev/2003-July/036900.html __ http://mail.python.org/pipermail/python-dev/2003-July/037117.html __ http://mail.python.org/pipermail/python-dev/2003-July/036921.html __ http://mail.python.org/pipermail/python-dev/2003-July/036940.html __ http://mail.python.org/pipermail/python-dev/2003-July/036941.html __ http://mail.python.org/pipermail/python-dev/2003-July/037024.html __ http://mail.python.org/pipermail/python-dev/2003-July/037134.html __ http://mail.python.org/pipermail/python-dev/2003-July/037144.html __ http://mail.python.org/pipermail/python-dev/2003-July/037193.html __ http://mail.python.org/pipermail/python-dev/2003-July/037200.html __ http://mail.python.org/pipermail/python-dev/2003-July/037207.html __ http://mail.python.org/pipermail/python-dev/2003-July/037208.html __ http://mail.python.org/pipermail/python-dev/2003-July/037237.html __ http://mail.python.org/pipermail/python-dev/2003-July/037284.html __ http://mail.python.org/pipermail/python-dev/2003-July/037311.html __ http://mail.python.org/pipermail/python-dev/2003-July/037315.html __ http://mail.python.org/pipermail/python-dev/2003-July/037319.html .. _Apple: http://www.apple.com/ .. _What's New in Python 2.3: http://www.python.org/doc/2.3/whatsnew/ ------------------------------------------- String Exceptions Going Extinct, Eventually ------------------------------------------- It has been brought up several times before, but things are now moving=20 along to eventually deprecate string exceptions (e.g., ``raise "this=20 string exception"``). they have now been removed from the tutorial to=20 prevent people new to the language from picking up habits that will=20 eventually be impossible to perform. As for when the impending deprecation will occur only Guido knows. The=20 chances of it coming before Python 3, though, is most likely small. Contributing threads: - `String exceptions in the Tutorial`__ __ http://mail.python.org/pipermail/python-dev/2003-July/036665.html -------------------------------------------------------- Someday, My CVS updates Will Succeed on the First Try... -------------------------------------------------------- We all know that SourceForge_ does not have the snappiest or most=20 reliable CVS_ servers in the world; Python 2.3 final's release was=20 targeted a few days earlier than needed for Apple_ in case SF's CVS went=20 down. Solutions to how to deal with this problem have come up. One specific problem that people are trying to solve is the poor=20 anonymous pserver access. SF has their CVS servers set up so that=20 authorized CVS commands take priority over anonymous ones and thus when=20 there is heavy traffic anonymous CVS basically shuts down. Martin v.=20 L=F6wis put up a link to a nightly tarball at=20 http://www.dcl.hpi.uni-potsdam.de/home/loewis/python.tgz of the CVS=20 HEAD. perl.org has provided a nightly tarball as well at=20 http://cvs.perl.org/snapshots/python/ for quite some time now. The=20 suggestion of having a read-only version of the CVS tree on python.org=20 was came up, but how to properly do it and who would set it up was not=20 settled. And of course there is always the option of moving CVS off of SF=20 entirely. There is one offer on the table with the caveat that we need=20 to know what kind of bandwidth demands we would have. Another offer=20 sprung up this month from Michal Wallace to host our CVS at=20 http://www.versionhost.com/ with the hitch that it requires an external=20 Python script for secure connections (as specified at=20 http://www.sabren.net/code/cvssh/ ). Contributing threads: - `alternate pserver access for python CVS?`__ - `[fwd] SourceForge status`__ - `Volunteering to help with pserver cvs on python.org`__ __ http://mail.python.org/pipermail/python-dev/2003-July/036699.html __ http://mail.python.org/pipermail/python-dev/2003-July/036708.html __ http://mail.python.org/pipermail/python-dev/2003-July/036860.html .. _SourceForge: http://www.sf.net/ .. _CVS: http://www.cvshome.org/ --------------------- Which License to Use? --------------------- Domenico Andreoli wanted to donate `python-crack`_ to the PSF_ and=20 wondered what steps would be necessary to do so. He was first told that=20 the module would not be included in Python since it is too specific.=20 Secondly, it was suggested he not choose the PSF license. Instead, he=20 was told that he should use the BSD or MIT license (both of which can be=20 found at http://www.opensource.org/licenses/index.php); clean, simple=20 licenses that are not viral like the GPL but are GPL-compatible. This=20 is so that it can be included in any software that uses Python. Contributing threads: - `donating python-crack module`__ __ http://mail.python.org/pipermail/python-dev/2003-July/036712.html .. _python-crack: http://savannah.nongnu.org/projects/python-crack ---------------- Not Quite ANSI C ---------------- Every so often someone runs Python against a C code checker and notices=20 failures that get reported to us. Often, though, we have to tell the=20 person that we already know of the failures and that there is nothing to=20 worry about. This time it was failures under Purify. We have also=20 received reports of failures under Valgrind_ which are spurious. The=20 language isn't even fully ANSI C compliant, but as Tim Peters said,=20 "it's not possible to write a useful and portable memory allocator in=20 100% standard ANSI C" among other reasons why strict ANSI C conformity=20 is broken. The only major violations in the code are casting a pointer=20 to a unsigned integer type and assuming "that whatever memory protection=20 gimmicks an OS implements are at page granularity" which is a minor sin=20 at best. There is also some cases of accessing memory without proper=20 casting. Contributing threads: - `Invalid memory read in PyObject_Free`__ - `strict aliasing and Python`__ __ http://mail.python.org/pipermail/python-dev/2003-July/036717.html __ http://mail.python.org/pipermail/python-dev/2003-July/036898.html .. _Valgrind: http://developer.kde.org/~sewardj/ --------------------------------------- Shadowing Built-ins is Becoming a No-No --------------------------------------- Before the code was removed, Python 2.3 raised a DeprectionWarning when=20 you overshadowed a built-in in a module from outside the module's actual=20 code. What this means is that doing something like:: import mod mod.reload =3D 42 would raise the warning. Now doing ``reload =3D 42`` in the module itsel= f=20 would still be allowed. The idea was (and still is) that the compiler=20 can know when a built-in is shadowed in a module when it compiles the=20 module's code. But allowing someone to overwrite a built-in externally=20 means that the compiler cannot make any assumptions that built-ins will=20 forever reference the actual built-in code. This is unfortunate since=20 if shadowing externally was made illegal the compiler can reference the=20 built-in code directly and skip some steps for a nice speed-up. This is why there was code to warn against this initially. But it=20 didn't work well enough to be left in Python 2.3 so it has been removed.=20 But this restriction will most likely be enforced at some point so it=20 is something to keep in mind. Contributing threads: - `Deprecation warning 'assignment shadows builtin'`__... - `DeprecationWarning: assignment shadows builtin`__ __ http://mail.python.org/pipermail/python-dev/2003-July/036767.html __ http://mail.python.org/pipermail/python-dev/2003-July/036879.html ------------------------ Must...Start...Faster... ------------------------ While Python 2.3 sees up to a 30% speed increase over 2.2, it still=20 starts up slower. Originally it was believed that it was because of the=20 importation of the re module. Marc-Andr=E9 Lemburg applied a patch that=20 tried to minimize its possible importation at startup but it was still sl= ow. Jeremy Hylton pointed out that 2.2.3 imported re so that probably was=20 not the problem. One thing that is different, though, is the automatic=20 inclusion of warnings, codecs, and the ability to do zip imports. These=20 three things pull more modules and all of this leads to a longer startup=20 time. There is also the importation of distutils thanks to the site.py=20 module, but that only occurs if you execute in a build directory. Including zip imports also got attacked for the number of failed checks=20 for files it can incur. But it is believed this is not as bad as all of=20 the extra imports being done now and Just van Rossum said he would try=20 to cut down the unneeded checks in the future. Contributing threads: - `2.3 startup speed?`__ __ http://mail.python.org/pipermail/python-dev/2003-July/036815.html --------------------- The World and Numbers --------------------- People might not be aware of it, but locale.setlocale never changes the=20 LC_NUMERIC locale value. This is so that 'str' and 'float' can return=20 and receive numbers in a consistent way in source code. This causes a=20 problem, though, for people in locales that do not use a period for a=20 decimal point. If you had your locale set to Brazilian and tried to=20 pass the string "3,14" to 'float' it would fail even though that is a=20 legitimate number representation for your locale. The suggestion became to have a locale-agnostic version of 'str' and=20 'float' in the locale module for people to use when they needed such=20 functionality. It has now reached the stage of a rough draft PEP as=20 found at http://mail.python.org/pipermail/python-dev/2003-July/036996.htm= l . Contributing threads: - `LC_NUMERIC and C libraries`__ - `Be Honest about LC_NUMERIC`__ - `RE: [Spambayes] Question (or possibly a bug report)`__ __ http://mail.python.org/pipermail/python-dev/2003-July/036869.html __ http://mail.python.org/pipermail/python-dev/2003-July/036996.html __ http://mail.python.org/pipermail/python-dev/2003-July/037178.html --------------- Zippin' Nothin' --------------- The built-in 'zip' function in Python 2.3 raises TypeError when given no=20 arguments. This causes problem when you do ``zip(*args)`` and args is=20 empty. So for Python 2.4 'zip' with no arguments will return an empty li= st. Contributing threads: - `zip() in Py2.4`__ __ http://mail.python.org/pipermail/python-dev/2003-July/037332.html -------------------------------- A Syntax For Function Attributes -------------------------------- An old debate (or at least old in terms of it having popped up multiple=20 times during the tenure of your author) has been ways of enhancing=20 function definitions. Previously it has been over ways to make defining=20 classmethod and its ilk in a cleaner fashion along with properties (past=20 summaries on this can be found at=20 http://www.python.org/dev/summary/2003-01-16_2003-01-31.html#extended-fun= ction-syntax=20 and=20 http://www.python.org/dev/summary/2003-02-01_2003-02-15.html#extended-fun= ction-syntax=20 ). What made the discussion slightly different this time, though, was the=20 focus was on function attributes specifically. One idea was to tweak=20 Michael Hudson's bracket syntax for method annnotations to allow for=20 function attributes; ``def foo() [bar=3D42]: pass``. Another suggestion=20 was to take the dictionary-like connection even farther; ``def foo()=20 {bar=3D42}: pass``. There was no clear winner in either case partially=20 because this discussion flared up towards the end of the month. It was also pointed out that using Michael Hudson's method descriptors=20 you could come up with a wrapping function that handled the situation:: def attrs(**kw): def _(func): for k in kw: setattr(func, k, kw[k]) return func return _ def foo() [attrs(bar=3D42)]: pass Perk of this is it does not lead to any special syntax just for function=20 attributes. One drawback, though, as pointed out by Paul Moore is that=20 this makes the method annotation idea a little to liberal and open to=20 hackish solutions like this that will lead to abuse. This was not a=20 huge worry, though, since almost anything can be abused and this is all=20 already doable now, just without a nice, clean syntax. Contributing threads: - `A syntax for function attributes?`__ __ http://mail.python.org/pipermail/python-dev/2003-July/037338.html From halley@dnspython.org Mon Aug 11 06:00:22 2003 From: halley@dnspython.org (Bob Halley) Date: 10 Aug 2003 22:00:22 -0700 Subject: ANN: dnspython 1.1.0 Message-ID: dnspython 1.1.0 has been released. Here's the README: dnspython INTRODUCTION dnspython is a DNS toolkit for Python. It supports almost all record types. It can be used for queries, zone transfers, and dynamic updates. It supports TSIG authenticated messages and EDNS0. dnspython provides both high and low level access to DNS. The high level classes perform queries for data of a given name, type, and class, and return an answer set. The low level classes allow direct manipulation of DNS zones, messages, names, and records. To see a few of the ways dnspython can be used, look in the examples/ directory. dnspython originated at Nominum where it was developed to facilitate the testing of DNS software. Nominum has generously allowed it to be open sourced under a BSD-style license, and helps support its future development by continuing to employ the author :). ABOUT THIS RELEASE This is dnspython 1.1.0. New since 1.0.0: Message sections are now lists of RRsets, not lists of nodes. Nodes no longer have names; owner names are associated with nodes in the Zone object's nodes dictionary. Many tests have been added to the test suite; dnspython 1.0.0 has 47 tests, 1.1.0 has 275. The improved testing uncovered a number of bugs, all of which have been fixed. The NameDict class provides a dictionary whose keys are DNS names. In addition to behaving like a normal Python dictionary, it also provides the get_deepest_match() method. If, for example, you had a dictionary containing the keys foo.com and com, then get_deepest_match() of the name a.b.foo.com would match the foo.com key. A new Renderer class for those applications which want finer control over the DNS wire format message generation process. Support for a "TooBig" exception if the size of wire format output exceeds a specified limit. Zones now have find_rrset() and find_rdataset() convenience methods. They let you retrieve rdata with the specified name and type in one call, e.g.: rrset = zone.find_rrset('foo', 'mx') Other new zone convenience methods include: find_node(), delete_node(), delete_rdataset(), replace_rdataset(), iterate_rdatasets(), and iterate_rdatas(). get_ variants of find_ methods are provided; the difference is that get_ methods return None if the desired object doesn't exist, whereas the find_ methods raise an exception. Zones now have a to_file() method. The message and zone from_file() methods allow Unicode filenames on platforms (and versions of python) which support them. Universal newline support is also used if available. The Zone class now implements more of the standard mapping interface. E.g. you can say zone.keys(), zone.get('name'), zone.iteritems(), etc. __iter__() has been changed to iterate the keys rather than values to match the standard mapping interface's behavior. Rdatasets support more set operations Zone and Node factories may be specified, allowing applications to subclass Zone or Node and yet still use the algorithms which build zones from master files or AXFR data. dns.ipv6.inet_ntoa() now minimizes the text representation of IPv6 addresses in the usual way, e.g. "0000:0000:0000:0000:0000:0000:0000:0001" is minimized to "::1". dns.query functions now take an optional address family parameter. This release fixes all known bugs. See the ChangeLog file for more detailed information on changes since the prior release. REQUIREMENTS Python 2.2 or later. INSTALLATION To build and install dnspython, type python setup.py install HOME PAGE For the latest in releases, documentation, and information, visit the dnspython home page at http://www.dnspython.org/ DOCUMENTATION Documentation is sparse at the moment. Use pydoc, or read the HTML documentation at the dnspython home page, or download the HTML documentation. BUG REPORTS Bug reports may be sent to bugs@dnspython.org MAILING LISTS A number of mailing lists are available. Visit the dnspython home page to subscribe or unsubscribe. From alexander.dejanovski@laposte.net Mon Aug 11 07:55:31 2003 From: alexander.dejanovski@laposte.net (Alexander DEJANOVSKI) Date: Mon, 11 Aug 2003 08:55:31 +0200 Subject: Retic EAI Server 0.1 released Message-ID: Retic is a free EAI Server written in Python. It permits to build adaptors (data flows) with three types of components : sources, pipes and sinks. It was widely inspired by OpenAdaptor. The 0.1 release has the following components available : Sources : File, FTP, HTTP, SQL Pipes : toXML (flat to XML) , XSLT Sinks : File, FTP, SQL, SMTP Retic can be downloaded from its sourceforge home page : https://sourceforge.net/projects/retic/ More info and documentation can be found on : http://retic.sourceforge.net From rich@worldsinfinite.com Mon Aug 11 21:56:33 2003 From: rich@worldsinfinite.com (Rich Harkins) Date: 11 Aug 2003 16:56:33 -0400 Subject: ANN: pychains-0.1.0 Message-ID: pychains is a C-based python module providing a couple of useful Python types that delegate certain requests (__getitem__ and __getattr__) to other objects. Using pychains one can create dictionaries that are aggregates of other dictionaries, objects whose attributes come from numerous other objects, etc. Documentation, as it stands, is available on the home page as is the download link: http://pychains.sourceforge.net STANDARD DISCLAIMER: This code is *very* alpha. I'm using it in some of my projects and it hasn't crashed in a while so I'm allowing it into the source-compiling public for further testing, etc. I'm suspicious it may be leaking memory and I cannot guarantee it won't do something horrible. PLEASE don't use it where it doesn't belong (mission critical stuff). Regards, Rich -- Rich Harkins From mal@lemburg.com Tue Aug 12 13:18:34 2003 From: mal@lemburg.com (M.-A. Lemburg) Date: Tue, 12 Aug 2003 14:18:34 +0200 Subject: ANN: eGenix.com mx Base Extension Package 2.0.5 Message-ID: ________________________________________________________________________ ANNOUNCING: eGenix.com mx BASE Extension Package for Python 1.5.2 - 2.3 Version 2.0.5 Open Source Python extensions providing important and useful services for Python programmers. ________________________________________________________________________ WHAT IS IT ?: The eGenix.com mx Base Extensions for Python are a collection of professional quality software tools which enhance Python's usability in many important areas such as fast text searching, date/time processing and high speed datatypes. Python is an object-oriented Open Source programming language which runs on all modern platforms (http://www.python.org/). By integrating ease-of-use, clarity in coding, enterprise application connectivity and rapid application design, Python establishes an ideal programming platform for todays IT challenges. The tools have a proven record of being portable across many Unix and Windows platforms. You can write applications which use the tools on Windows and then run them on Unix platforms without change due to the consistent platform independent interfaces. All available packages have proven their stability and usefulness in many mission critical applications and various commercial settings all around the world. ________________________________________________________________________ WHAT'S NEW ? The new version includes patches needed to compile the packages under Python 2.3. As always we are providing precompiled versions of the package for Windows and Linux as well as sources which allow you to install the package on all other supported platforms. ________________________________________________________________________ EGENIX.COM MX BASE PACKAGE OVERVIEW: mxDateTime - Generic Date/Time Types mxDateTime is an extension package that provides three new object types, DateTime, DateTimeDelta and RelativeDateTime, which let you store and handle date/time values in a much more natural way than by using ticks (seconds since 1.1.70 0:00 UTC; the encoding used by the time module). You can add, subtract and even multiply instances, pickle and copy them and convert the results to strings, COM dates, ticks and some other more esoteric values. In addition, there are several convenient constructors and formatters at hand to greatly simplify dealing with dates and times in real-world applications. In addition to providing an easy-to-use Python interface the package also exports a comfortable C API interface for other extensions to build upon. This is especially interesting for database applications which often have to deal with date/time values (the mxODBC package is one example of an extension using this interface). mxTextTools - Fast Text Processing Tools mxTextTools is an extension package for Python that provides several useful functions and types that implement high-performance text manipulation and searching algorithms in addition to a very flexible and extendable state machine, the Tagging Engine, that allows scanning and processing text based on low-level byte-code "programs" written using Python tuples. It gives you access to the speed of C without the need to do any compile and link steps every time you change the parsing description. Applications include parsing structured text, finding and extracting text (either exact or using translation tables) and recombining strings to form new text. mxStack - Fast and Memory-Efficient Stack Type mxStack is an extension package that provides a new object type called Stack. It works much like what you would expect from such a type, having .push() and .pop() methods and focusses on obtaining maximum speed at low memory costs. mxTools - Collection of Additional Builtins mxTools is an extension package that includes a collection of handy functions and objects giving additional functionality in form of new builtins to the Python programmer. The package auto-installs the new functions and objects as builtins upon first import. This means that they become instantely available to all other modules without any further action on your part. Add the line import NewBuiltins to your site.py script and they will be available to all users at your site as if they were installed in the Python interpreter itself. mxProxy - Generic Proxy Wrapper Type mxProxy is an extension package that provides a new type that is suitable to implement Bastion like features without the need to use restricted execution environments. The type's main features are secure data encapsulation (the hidden objects are not accessible from Python since they are stored in internal C structures), customizable attribute lookup methods and a cleanup protocol that helps in breaking circular references prior to object deletion. The latest version adds a very interesting new feature: weak references which help you work with circular references in a way that doesn't cause memory leakage in a Python system. Note that even though Python 2.1+ has its own weak reference implemetation, this package can be used to write applications which also work on Python 1.5.2 and 2.0. mxBeeBase - On-disk B+Tree Based Database Kit mxBeeBase is a high performance construction kit for disk based indexed databases. It offers components which you can plug together to easily build your own custom mid-sized databases (the current size limit is sizeof(long) which gives you an address range of around 2GB on 32-bit platforms). The two basic building blocks in mxBeeBase are storage and index. Storage is implemented as variable record length data storage with integrated data protection features, automatic data recovery and locking for multi process access. Indexes use a high performance optimized B+Tree implementation built on top of Thomas Niemann's Cookbook B+Tree implementation (http://epaperpress.com/). ________________________________________________________________________ WHERE CAN I GET IT ? The download archives and instructions for installing the packages can be found at: http://www.egenix.com/ ________________________________________________________________________ WHAT DOES IT COST ? The Base package comes with a Python 2.0 style license, which means that you can use it in both commercial and non-commercial settings without fee or charge. Full source code is included. ________________________________________________________________________ WHERE CAN I GET SUPPORT ? Commercial quality support for these packages is available from eGenix.com Software GmbH. Please see http://www.egenix.com/files/python/eGenix-mx-Extensions.html#Support for details about the eGenix support offerings. ________________________________________________________________________ Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 12 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal@egenix.com Tue Aug 12 13:19:28 2003 From: mal@egenix.com (M.-A. Lemburg) Date: Tue, 12 Aug 2003 14:19:28 +0200 Subject: ANN: eGenix.com mx Experimental Package 0.8.0 Message-ID: ________________________________________________________________________ ANNOUNCING: eGenix.com mx Experimental Extension Package for Python 1.5.2 - 2.3 Version 0.8.0 Experimental Python extensions providing important and useful services for Python programmers. ________________________________________________________________________ WHAT IS IT ?: The eGenix.com mx Experimental Extensions for Python are a collection of alpha and beta quality software tools for Python which will be integrated into the other mx Extension Packages after they have matured to professional quality tools. Python is an object-oriented Open Source programming language which runs on all modern platforms (http://www.python.org/). By integrating ease-of-use, clarity in coding, enterprise application connectivity and rapid application design, Python establishes an ideal programming platform for todays IT challenges. ________________________________________________________________________ WHAT'S NEW ? The new version includes patches needed to compile the packages under Python 2.3. As always we are providing precompiled versions of the package for Windows and Linux as well as sources which allow you to install the package on all other supported platforms. ________________________________________________________________________ EGENIX.COM MX EXPERIMENTAL PACKAGE OVERVIEW: mxNumber - Python Interface to GNU MP Number Types mxNumber provides direct access to the high performance numeric types available in the GNU Multi-Precision Lib (GMP). This library is licensed under the LGPL and runs on practically all Unix platforms. eGenix.com has ported the GMP lib to Windows, to also provide our Windows users with the added benefit of being able to do arbitrary precision calculations. The package currently provide these numerical types: 1. Integer(value) -- arbitrary precision integers much like Python longs only faster 2. Rational(nom,denom) -- rational numbers with Integers as numerator and denominator 3. Float(value[,prec]) -- floating point number with at least prec bits precision 4. FareyRational(value, maxden) -- calculate the best rational represenation n/d of value such that d < maxden mxTidy - Interface to HTML Tidy (HTML/XML cleanup tool) mxTidy provides a Python interface to a thread-safe, library version of the HTML Tidy. command line tool. HTML Tidy helps you to cleanup coding errors in HTML and XML files and produce well-formed HTML, XHTML or XML as output. This allows you to preprocess web-page for inclusion in XML repositories, prepare broken XML files for validation and also makes it possible to write converters from well-known word processing applications such as MS Word to other structured data representations by using XML as intermediate format. mxURL - A URL Datatype mxURL provides a new datatype for storing and manipulating URL values as well as a few helpers related to URL building, encoding and decoding. The main intention of the package is to provide an easy to use, fast and lightwheight datatype for Universal Resource Locators (note the W3C now calls these URIs). mxUID - A UID Datatype mxUID provides a fast mechanism for generating universal identification strings (UIDs). The intent is to make these UIDs unique with high probability in order to serve as object or data set identifiers. A typical use lies in generating session IDs. Other areas where unique IDs play an important role are RPC-implementations, ORBs, etc. ________________________________________________________________________ WHERE CAN I DOWNLOAD IT ? The download archives and instructions for installing the packages can be found at: http://www.egenix.com/ Note that in order to use the eGenix.com mx EXPERIMENTAL package you will first need to install the eGenix.com mx BASE package which can be downloaded from the same location. ________________________________________________________________________ WHAT DOES IT COST ? The EXPERIMENTAL packages uses different licenses in its subpackages. Please refer to the subpackage documentation for details. Some of them may be integrated into the BASE package, others will be integrated into the COMMERCIAL package. The package comes with full source code ________________________________________________________________________ WHERE CAN I GET SUPPORT ? Commercial quality support for these packages is available from eGenix.com. Please see http://www.egenix.com/files/python/eGenix-mx-Extensions.html#Support for details about our support offerings. ________________________________________________________________________ Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 12 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mal@lemburg.com Tue Aug 12 13:21:29 2003 From: mal@lemburg.com (M.-A. Lemburg) Date: Tue, 12 Aug 2003 14:21:29 +0200 Subject: ANN: eGenix.com mxODBC Python Database Interface Version 2.0.6 Message-ID: ________________________________________________________________________ ANNOUNCING: eGenix.com mxODBC Database Interface for Python 1.5.2 - 2.3 Version 2.0.6 Full Source Python extension providing ODBC connectivity to Python applications on Windows, Unix abd Linux ________________________________________________________________________ WHAT IS IT ?: The mxODBC Database Interface allows users to connect from Python to just about any database on the market today, on Windows, Unix and Linux -- using just one interface to program against for all supported databases and platforms. This makes mxODBC the ideal basis for writing cross-platform database programs and utilities. mxODBC is included in the eGenix.com mx Commercial Extension Package for Python, the commercial part of the eGenix.com mx Extension Series, a collection of professional quality software tools which enhance Python's usability in many important areas such as ODBC database connectivity, fast text processing, date/time processing and web site programming. See http://www.egenix.com/ for details. ________________________________________________________________________ WHAT'S NEW ? The 2.0.6 version includes patches needed to compile the package for Python 2.3. Binaries are available for Python 1.5.2, 2.0, 2.1, 2.2 and 2.3 for Windows and Linux. ________________________________________________________________________ EGENIX.COM MX COMMERCIAL PACKAGE OVERVIEW: mxODBC - Generic ODBC 2.0-3.5 interface for Python mxODBC is an extension package that provides a Python Database API compliant interface to ODBC capable database drivers and managers. In addition to the capabilities provided through the standard DB API it also gives access to a rich set of catalog methods which allow you to scan the database for tables, procedures, etc. Furthermore, it uses the mxDateTime package for date/time value interfacing eliminating most of the problems these types normally introduce (other in/output formats are available too). mxODBC allows you to interface to more than one database from one process, making inter-database interfacing very flexible and reliable. The source version includes a varity of preconfigured setups for many commonly used databases such as MySQL, Oracle, Informix, Solid, SAP DB, Sybase ASA and ASE, DBMaker and many more. The precompiled versions for Windows and Linux include the interfaces to the standard ODBC manager on these platforms to allow for a more easily configurable setup. More details are available at: http://www.egenix.com/files/python/mxODBC.html ________________________________________________________________________ WHERE CAN I DOWNLOAD IT ? The download archives and instructions for installing the package can be found at: http://www.egenix.com/files/python/eGenix-mx-Extensions.html#Packages IMPORTANT: In order to use the eGenix.com mx Commercial package you will first need to install the eGenix.com mx Base package which can be downloaded from the same location. ________________________________________________________________________ WHERE CAN I BUY LICENSES ? mxODBC is free for non-commercial use. Commercial users have to buy licenses for continued use after a 30-day evaluation period. Special licensing setups are available for commercial product developers. Please see http://www.egenix.com/files/python/eGenix-mx-Extensions.html#BuyLicenses for details or go directly to our secure online shop: http://shop.egenix.com/ ________________________________________________________________________ WHERE CAN I GET SUPPORT ? Commercial quality support for these packages is available from eGenix.com. Please see http://www.egenix.com/files/python/eGenix-mx-Extensions.html#Support for details about our support offerings. ________________________________________________________________________ Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 12 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From stani_@hotmail.com Tue Aug 12 14:35:16 2003 From: stani_@hotmail.com (SM) Date: 12 Aug 2003 06:35:16 -0700 Subject: SPE 0.15: new Python IDE with optional Blender integration. Message-ID: SPE (Stani's Python Editor) is a Python IDE with optional Blender integration. (c)2003 http://www.stani.be spe 0.15 is now available at: http://projects.blender.org/projects/spe/ This version of Spe contains important changes since 0.14, especially support for Blender2.28 and an improved blenpy. Links: ------ Screenshot Spe: http://stani.host.sk/python/spe.png (Refresh your browser if the screenshot doesn't load.) Screenshots blenpy: http://stani.host.sk/python/blenpy.html Forum for help and discussion: http://projects.blender.org/forum/?group_id=30 Blender (3d): http://www.blender.org * What's new?: ------------ New features: Blender browser updated for Blender2.28 - Armature - Curve - Effect - IpoCurve - Metaball Help windows improved with logo and html window. Bugfixes: - blenpy has undergone numerous fixes and should run fine Requirements: - full python2.2 - wxpython 2.4.1.2.u (updated!) - optional Blender2.28 (updated!) Known issues: - Exploring Texts in Blender browser crashes due to internal Blender error. * Features: --------- Sidebar per file *class/method browser (jump to source) *automatic todo list, highlighting the most important ones (jump to source) *automatic alphabetic index of classes and methods (jump to source) *notes Tools: *interactive shell *locals browser (left click to open, right click to run) *seperate session recording *quick access to python files in folder and its subfolders (click to open) *unlimited recent file list (left click to open, right click to run) *automatic todo list of all open files, highlighting the most important ones (jump to source) *automatic alphabetic index of all open files (jump to source) Python related: *sytax-checking *syntax-coloring *auto-indentation *auto-completion *calltips Drag & Drop: drop any amount of files or folders... *on main frame to open them *on shell to run them *on recent files to add them *on browser to add folders General *context help defined everywhere *add your own menus and toolbar buttons *exit & remember:all open files will next time automatically be loaded (handy for Blender sessions) *wxPython gui, so should be cross-platform (Windows,Linux,Mac) *scripts can be executed in different ways:run,run verbose & import *after error jump to line in source code *remember toggle:remembers open files between sessions. Blender related: *redraw the Blender screen on idle (no blackout) *Blender object tree browser (cameras,objects,lamps,...) *add your favorite scripts to the menu *100% Blender compatible:can run within Blender, so all these features are available within Blender * Contribute: ----------- Beta-testers wanted: Spe is still under development. If Spe runs without any problems, I'm also interested to get a notice. I developped spe under windows xp and have no access to Linux, Mac, FreeBsd or any other platform. So any help for these platforms is highly appreciated. Join the forum: If you use Spe and find a bug or problem, please post a message on the appropiate forum on http://projects.blender.org/forum/?group_id=30 describing the platform, the problems that occur and possible solutions if you know. If you would like to contribute to spe in any way, send me an email with your skills (programming,graphics,icons,3d,html,...) and I'm sure you can help me out. From info@nyc-search.com Tue Aug 12 21:42:19 2003 From: info@nyc-search.com (NYC-SEARCH) Date: 12 Aug 2003 13:42:19 -0700 Subject: JOB: Python Technical Lead & Head of Data Quality Assurance, NYC Message-ID: If you are interested in a position, please review the requirements and reply with your salary requirement. My clients main concern with these positions is Python. Elaborating on your knowledge of Python when replying to me will greatly increase your chances of landing an interview. JOB #1: Python Technical Lead, New York, NY DETAILS: http://www.nyc-search.com/jobs/python.html JOB #2: Head of Data Quality Assurance, New York, NY DETAILS: http://www.nyc-search.com/jobs/headQA.html Thank you, Beau J. Gould Kaandidates.com Python Jobs Yahoo Group >> http://groups.yahoo.com/group/pythonjobs From jjl@pobox.com Wed Aug 13 01:12:57 2003 From: jjl@pobox.com (John J. Lee) Date: 13 Aug 2003 01:12:57 +0100 Subject: ANN: ClientCookie 0.4.3a released Message-ID: http://wwwsearch.sourceforge.net/ClientCookie/ A new development release. This is an alpha release: interfaces may change (probably not much, though). 0.4.3a is probably less broken than 0.3.5b. 0.3.x is no longer being maintained. 0.4.x includes interface changes, but it isn't hard to switch -- see: http://wwwsearch.sourceforge.net/ClientCookie/porting.txt Changes since 0.3.2a: * Changed license to BSD, so I can use a Python Cookbook recipe. The only difference is the addition of a non-endorsement clause. * Much of AbstractHTTPHandler has been rewritten in terms of processors (a bit like handlers). I've submitted this as a patch to SF, and am crossing my fingers that it'll get accepted roughly as-is. If it doesn't, there will likely be more interface changes here. * Renamed Cookies class to CookieJar (and analogously for MozillaCookies and MSIECookies). This was inevitable given the existence of the Cookie class -- too confusing otherwise. * Response objects are no longer seekable by default. Pass SeekableProcessor to build_opener if you want that. * Drastically reduced the requirements on response objects. * Applied some bugfixes for AbstractHTTPHandler from Python CVS. This fixes proxy support. * Assorted other bug fixes. * HTTPRefreshProcessor now has some constructor arguments to allow non-zero time Refreshes, and to control whether or not the requested pause is actually honoured, or just skipped. * Added support for automatically adding Referer HTTP header (only for simple chains of requests). * Added some minor new debugging support. Requires Python >= 1.5.2. ClientCookie is a Python module for handling HTTP cookies on the client client side, useful for accessing web sites that require cookies to be set and then returned later. It also provides some other (optional) useful stuff: HTTP-EQUIV and Refresh handling, automatic adding of the Referer [sic] header and lazily-seek()able responses. These extras are implemented using an extension that makes it easier to add new functionality to urllib2. It has developed from a port of Gisle Aas' Perl module HTTP::Cookies, from the libwww-perl library. Simple usage: import ClientCookie response = ClientCookie.urlopen("http://foo.bar.com/") This function behaves identically to urllib2.urlopen, except that it deals with cookies automatically. That's probably all you need to know. John From jjl@pobox.com Wed Aug 13 01:14:11 2003 From: jjl@pobox.com (John J. Lee) Date: 13 Aug 2003 01:14:11 +0100 Subject: ANN: ClientForm 0.1.7b released Message-ID: http://wwwsearch.sourceforge.net/ClientForm/ First (and last, I hope) beta release of 0.1.x. Changes from 0.1.5a to 0.1.7b: * After some thought about Law of Demeter, realised that there was no justification for deprecating most use of find_control, nor for adding many of the new methods on HTMLForm. Use of find_control is now officially OK again. set_/get_readonly, set_/get_disabled, set_/get_item_disabled, set_all_items_disabled have been removed from HTMLForm. * Added HTMLForm.set_all_readonly method. This one is actually useful! * possible_label_items is gone, replaced by by_label argument to possible_items. by_label is now as consistent as possible. The exceptions are set_value_by_label and get_value_by_label, since there is no method to add an argument to in those cases. The lack of implementation of by_label for CHECKBOX and RADIO is considered a bug, so NotImplementedError is raised. LabelNotSupportedError has gone. * Added indication to ListControl.__str__ of disabled items -- they have parentheses around them: item 1, (item 2), item 3 means "item 2" is disabled. * Bug fixes. Requires Python >= 1.5.2. ClientForm is a Python module for handling HTML forms on the client side, useful for parsing HTML forms, filling them in and returning the completed forms to the server. It has developed from a port of Gisle Aas' Perl module HTML::Form, from the libwww-perl library, but the interface is not the same. Simple example: from urllib2 import urlopen from ClientForm import ParseResponse forms = ParseResponse(urlopen("http://www.acme.com/form.html")) form = forms[0] print form form["author"] = "Gisle Aas" # form.click returns a urllib2.Request object # (see HTMLForm.click_request_data.__doc__ if you're not using urllib2) response = urlopen(form.click("Thanks")) John From info@nyc-search.com Wed Aug 13 21:55:04 2003 From: info@nyc-search.com (NYC-SEARCH) Date: 13 Aug 2003 13:55:04 -0700 Subject: Python Jobs Yahoo Group Message-ID: Python Jobs Yahoo Group >> http://groups.yahoo.com/group/pythonjobs From amk@nyman.amk.ca Thu Aug 14 01:32:26 2003 From: amk@nyman.amk.ca (amk@nyman.amk.ca) Date: Wed, 13 Aug 2003 20:32:26 -0400 Subject: General Python FAQ Message-ID: I've been working on translating the Python FAQ into Restructured Text and updating it to match the current 2.2/2.3 world. Here is the first completed section, which covers general questions about Python. Please offer suggestions for improving the answers: different techniques, relevant links, typos, code errors, etc. Are there other questions that come up repeatedly that should be answered in the FAQ? People with commit privileges for python.org can go ahead and edit the document; I've finished revising it for the time being. Note: permalinks to questions in the FAQ have not been set up yet, so please don't try linking to questions; any such link might well break in a future revision or rearrangement. I'll try to figure out a way to assign permanent links for each question. --amk ==================================== General Python FAQ ==================================== :Date: $Date: 2003/08/13 12:03:56 $ :Version: $Revision: 1.6 $ :Web site: http://www.python.org/ .. contents:: .. sectnum:: General Information ===================== What is Python? ---------------------- Python is an interpreted, interactive, object-oriented programming language. It incorporates modules, exceptions, dynamic typing, very high level dynamic data types, and classes. Python combines remarkable power with very clear syntax. It has interfaces to many system calls and libraries, as well as to various window systems, and is extensible in C or C++. It is also usable as an extension language for applications that need a programmable interface. Finally, Python is portable: it runs on many brands of UNIX, on the Mac, and on PCs under MS-DOS, Windows, Windows NT, and OS/2. To find out more, start with the `Beginner's Guide to Python `_. Why was Python created in the first place? -------------------------------------------------- Here's a *very* brief summary of what started it all, written by Guido van Rossum: I had extensive experience with implementing an interpreted language in the ABC group at CWI, and from working with this group I had learned a lot about language design. This is the origin of many Python features, including the use of indentation for statement grouping and the inclusion of very-high-level data types (although the details are all different in Python). I had a number of gripes about the ABC language, but also liked many of its features. It was impossible to extend the ABC language (or its implementation) to remedy my complaints -- in fact its lack of extensibility was one of its biggest problems. I had some experience with using Modula-2+ and talked with the designers of Modula-3 and read the Modula-3 report. Modula-3 is the origin of the syntax and semantics used for exceptions, and some other Python features. I was working in the Amoeba distributed operating system group at CWI. We needed a better way to do system administration than by writing either C programs or Bourne shell scripts, since Amoeba had its own system call interface which wasn't easily accessible from the Bourne shell. My experience with error handling in Amoeba made me acutely aware of the importance of exceptions as a programming language feature. It occurred to me that a scripting language with a syntax like ABC but with access to the Amoeba system calls would fill the need. I realized that it would be foolish to write an Amoeba-specific language, so I decided that I needed a language that was generally extensible. During the 1989 Christmas holidays, I had a lot of time on my hand, so I decided to give it a try. During the next year, while still mostly working on it in my own time, Python was used in the Amoeba project with increasing success, and the feedback from colleagues made me add many early improvements. In February 1991, after just over a year of development, I decided to post to USENET. The rest is in the Misc/HISTORY file. What is Python good for? -------------------------------- Python is used in many situations where a great deal of dynamism, ease of use, power, and flexibility are required. For tasks such as manipulating the operating system or processing text, Python is easier to use and is roughly as fast as any language. This makes Python good for many system administration tasks, for CGI programming and other application areas that manipulate text and strings. When augmented with standard extensions or special-purpose extensions that you write yourself, Python becomes a very convenient "glue" or "steering" language that helps make heterogeneous collections of unrelated software packages work together. For example, by combining Numeric Python with an Oracle interface, you can take data from a SQL database and perform statistical analysis or Fourier transforms on it. One of the features that makes Python excel in the "glue language" role is Python's simple, usable, and powerful C programming interface. In such cases the bulk of the work is being performed by an extension written in C, meaning that even though Python is slower than C the total reduction in performance is negligible. For example, several commercial computer games have used Python to implement artificial intelligence or game logic, running Python code that controls speed-critical components written in C/C++. Python's support for several different graphical user interfaces (Windows MFC, Tk, Qt, wxWindows, GTk+, Apple's Cocoa) means that you can write a prototype interface in Python. If you find the Python version is fast enough, you can move it into production use; if not, you can translate the prototype into C/C++/Java/Objective-C. Because Python code is easy to read and language features such as garbage collection and high-level data types make it easy to write Python programs, it's also a great language for learning programming concepts. How does the Python version numbering scheme work? ---------------------------------------------------------- Python versions are numbered A.B.C or A.B. A is the major version number -- it is only incremented for really major changes in the language. B is the minor version number, incremented for less earth-shattering changes. C is the micro-level -- it is incremented for each bugfix release. See `PEP 6 `_ for more information about bugfix releases. Not all releases are bugfix releases. In the run-up to a new major release, a series of development releases are made, denoted as alpha, beta, or release candidate. Alphas are early releases in which interfaces aren't yet finalized; it's not unexpected to see an interface change between two alpha releases. Betas are more stable, preserving existing interfaces but possibly adding new modules, and release candidates are frozen, making no changes except as needed to fix critical bugs. Alpha, beta and release candidate versions have an additional suffixes. The suffix for an alpha version is "aN" for some small number N, the suffix for a beta version is "bN" for some small number N, and the suffix for a release candidate version is "cN" for some small number N. In other words, all versions labeled 2.0aN precede the versions labeled 2.0bN, which precede versions labeled 2.0cN, and *those* precede 2.0. You may also find version numbers with a "+" suffix, e.g. "2.2+". These are unreleased versions, built directly from the CVS trunk. See also the documentation for ``sys.version``, ``sys.hexversion``, and ``sys.version_info``. Are there copyright restrictions on the use of Python? -------------------------------------------------------------- Not really. You can do anything you want with the source, as long as you leave the copyrights in, and display those copyrights in any documentation about Python that you produce. Also, don't use the author's institute's name in publicity without prior written permission, and don't hold them responsible for anything (read `the actual copyright `_ for a precise legal wording). If you honor the copyright rules, it's OK to use Python for commercial use, to sell copies of Python in source or binary form (modified or unmodified), or to sell products that enhance Python or incorporate Python (or part of it) in some form. We would still like to know about all commercial use of Python, of course. How do I obtain a copy of the Python source? --------------------------------------------------- The latest Python source distribution is always available from python.org, at http://www.python.org/download/. The latest development sources can be obtained via anonymous CVS from SourceForge, at http://www.sourceforge.net/projects/python. The source distribution is a gzipped tar file containing the complete C source, LaTeX documentation, Python library modules, example programs, and several useful pieces of freely distributable software. This will compile and run out of the box on most UNIX platforms. Older versions of Python are also available from python.org. How do I get documentation on Python? -------------------------------------------- All documentation is available on-line, starting at http://www.python.org/doc. The LaTeX source for the documentation is part of the source distribution. If you don't have LaTeX, the latest Python documentation set is available by anonymous FTP in various formats such as PostScript and HTML. Visit the above URL for links to the current versions. I've never programmed before. Is there a Python tutorial? ----------------------------------------------------------------- There are numerous tutorials and books available. Consult `the Beginner's Guide `_ to find information for beginning Python programmers, including lists of tutorials. Are there other FTP sites that mirror the Python distribution? --------------------------------------------------------------------- Consult the list of python.org mirrors at http://www.python.org/doc/Mirrors.html. Is there a newsgroup or mailing list devoted to Python? -------------------------------------------------------------- There is a newsgroup, comp.lang.python, and a mailing list, `python-list `_. The newsgroup and mailing list are gatewayed into each other -- if you can read news it's unnecessary to subscribe to the mailing list. comp.lang.python is high-traffic, receiving hundreds of postings every day, and Usenet readers are often more able to cope with this volume. Announcements of new software releases and events can be found in comp.lang.python.announce, a low-traffic moderated list that receives about five postings per day. It's available as `the python-announce mailing list `_. More info about other mailing lists and newsgroups can be found at http://www.python.org/community/lists.html. How do I get a beta test version of Python? --------------------------------------------------- All releases, including alphas, betas and release candidates, are announced on the comp.lang.python and comp.lang.python.announce newsgroups. All announcements also appear on the Python home page, at http://www.python.org; an RSS feed of news is available. You can also access the development version of Python through CVS. See http://sourceforge.net/cvs/?group_id=5470 for details. If you're not familiar with CVS, documents such as http://linux.oreillynet.com/pub/a/linux/2002/01/03/cvs_intro.html provide an introduction. How do I submit bug reports and patches for Python? ---------------------------------------------------------- To report a bug or submit a patch, please use the relevant service from the Python project at SourceForge. Bugs: http://sourceforge.net/tracker/?group_id=5470&atid=105470 Patches: http://sourceforge.net/tracker/?group_id=5470&atid=305470 You must have a SourceForge account to report bugs; this makes it possible for us to contact you if we have follow-up questions. It will also enable SourceForge to send you updates as we act on your bug. For more information on how Python is developed, consult `the Python Developer's Guide `_. Are there any published articles about Python that I can reference? --------------------------------------------------------------------------- It's probably best to reference your favorite book about Python. The very first article about Python is this very old article that's now quite outdated. Guido van Rossum and Jelke de Boer, "Interactively Testing Remote Servers Using the Python Programming Language", CWI Quarterly, Volume 4, Issue 4 (December 1991), Amsterdam, pp 283-303. Are there any books on Python? ------------------------------------- Yes, there are many, and more are being published. See the python.org Wiki at http://www.python.org/cgi-bin/moinmoin/PythonBooks for a list. You can also search online bookstores for "Python" and filter out the Monty Python references; or perhaps search for "Python" and "language". Where in the world is www.python.org located? ----------------------------------------------------- It's currently in Amsterdam, graciously hosted by `XS4ALL `_. Thanks to Thomas Wouters for his work in arranging python.org's hosting. Why is it called Python? ------------------------------- At the same time he began implementing Python, Guido van Rossum was also reading the published scripts from "Monty Python's Flying Circus" (a BBC comedy series from the seventies, in the unlikely case you didn't know). It occurred to him that he needed a name that was short, unique, and slightly mysterious, so he decided to call the language Python. Do I have to like "Monty Python's Flying Circus"? ------------------------------------------------------------------- No, but it helps. :) Python in the real world ============================ How stable is Python? ---------------------------- Very stable. New, stable releases have been coming out roughly every 6 to 18 months since 1991, and this seems likely to continue. Currently there are usually around 18 months between major releases. With the introduction of retrospective "bugfix" releases the stability of existing releases is being improved. Bugfix releases, indicated by a third component of the version number (e.g. 2.1.3, 2.2.2), are managed for stability; only fixes for known problems are included in abugfix release, and it's guaranteed that interfaces will remain the same throughout a series of bugfix releases. The `2.3 release `_ is the most stable version at this point in time. How many people are using Python? ---------------------------------------- Probably tens of thousands of users, though it's difficult to obtain an exact count. The comp.lang.python newsgroup is very active, but overall there is no accurate estimate of the number of subscribers or Python users. Have any significant projects been done in Python? --------------------------------------------------------- See http://www.pythonology.org/success for a list of projects that use Python. Consulting the proceedings for `past Python conferences `_ will reveal contributions from many different companies and organizations. High-profile Python projects include `the Mailman mailing list manager `_ and `the Zope application server `_. Several Linux distributions, most notably `Red Hat `_, have written part or all of their installer and system administration software in Python. Companies that use Python internally include Google, Yahoo, and Industrial Light & Magic. What new developments are expected for Python in the future? ------------------------------------------------------------------- See http://www.python.org/peps for the Python Enhancement Proposals (PEPs). PEPs are design documents describing a suggested new feature for Python, providing a concise technical specification and a rationale. `PEP 1 `_ explains the PEP process and PEP format; read it first if you want to submit a PEP. New developments are discussed on `the python-dev mailing list `_. Is it reasonable to propose incompatible changes to Python? ------------------------------------------------------------------ In general, no. There are already millions of lines of Python code around the world, so any change in the language that invalidates more than a very small fraction of existing programs has to be frowned upon. Even if you can provide a conversion program, there still is the problem of updating all documentation; many books have been written about Python, and we don't want to invalidate them all at a single stroke. Providing a gradual upgrade path is necessary if a feature has to be changed. `PEP 5 `_ describes the procedure followed for introducing backward-incompatible changes while minimizing disruption for users. What is the Python Software Foundation? ----------------------------------------- The Python Software Foundation is an independent non-profit organization that holds the copyright on Python versions 2.1 and newer. The PSF's mission is to advance open source technology related to the Python programming language and to publicize the use of Python. The PSF's home page is at http://www.python.org/psf/. Donations to the PSF are tax-exempt in the US. If you use Python and find it helpful, please contribute via `the PSF donation page `_. Is Python Y2K (Year 2000) Compliant? -------------------------------------------- As of August, 2003 no major problems have been reported and Y2K compliance seems to be a non-issue. Python does very few date calculations and for those it does perform relies on the C library functions. Python generally represents times either as seconds since 1970 or as a ``(year, month, day, ...)`` tuple where the year is expressed with four digits, which makes Y2K bugs unlikely. So as long as your C library is okay, Python should be okay. Of course, it's possible that a particular application written in Python makes assumptions about 2-digit years. Because Python is available free of charge, there are no absolute guarantees. If there *are* unforseen problems, liability is the user's problem rather than the developers', and there is nobody you can sue for damages. The Python copyright notice contains the following disclaimer: 4. PSF is making Python 2.3 available to Licensee on an "AS IS" basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON 2.3 WILL NOT INFRINGE ANY THIRD PARTY RIGHTS. 5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON 2.3 FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON 2.3, OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF. The good news is that *if* you encounter a problem, you have full source available to track it down and fix it. This is one advantage of an open source programming environment. Is Python a good language for beginning programmers? ----------------------------------------------------------------------- Yes. If you want to discuss Python's use in education, then you may be interested in joining `the edu-sig mailing list `_. It is still common to start students with a procedural (subset of a) statically typed language such as Pascal, C, or a subset of C++ or Java. Students may be better served by learning Python as their first language. Python has a very simple and consistent syntax and a large standard library and, most importantly, using Python in a beginning programming course permits students to concentrate on important programming skills such as problem decomposition and data type design. With Python, students can be quickly introduced to basic concepts such as loops and procedures. They can even probably work with user-defined objects in their very first course. For a student who has never programmed before, using a statically typed language seems unnatural. It presents additional complexity that the student must master and slows the pace of the course. The students are trying to learn to think like a computer, decompose problems, design consistent interfaces, and encapsulate data. While learning to use a statically typed language is important in the long term, it is not necessarily the best topic to address in the students' first programming course. Many other aspects of Python make it a good first language. Like Java, Python has a large standard library so that students can be assigned programming projects very early in the course that *do* something. Assignments aren't restricted to the standard four-function calculator and check balancing programs. By using the standard library, students can gain the satisfaction of working on realistic applications as they learn the fundamentals of programming. Using the standard library also teaches students about code reuse. Third-party modules such as PyGame are also helpful in extending the students' reach. Python's interactive interpreter enables students to test language features while they're programming. They can keep a window with the interpreter running while they enter their program's source in another window. If they can't remember the methods for a list, they can do something like this:: >>> L = [] >>> dir(L) ['append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort'] >>> help(L.append) Help on built-in function append: append(...) L.append(object) -- append object to end >>> L.append(1) >>> L [1] With the interpreter, documentation is never far from the student as he's programming. There are also good IDEs for Python. IDLE is a cross-platform IDE for Python that is written in Python using Tkinter. PythonWin is a Windows-specific IDE. Emacs users will be happy to know that there is a very good Python mode for Emacs. All of these programming environments provide syntax highlighting, auto-indenting, and access to the interactive interpreter while coding. Python's Design ===================== Why does Python use indentation for grouping of statements? ----------------------------------------------------------- Guido van Rossum believes that using indentation for grouping is extremely elegant and contributes a lot to the clarity of the average Python program. Most people learn to love this feature after awhile. Since there are no begin/end brackets there cannot be a disagreement between grouping perceived by the parser and the human reader. Occasionally C programmers will encounter a fragment of code like this:: if (x <= y) x++; y--; z++; Only the ``x++`` statement is executed if the condition is true, but the indentation leads you to believe otherwise. Even experienced C programmers will sometimes stare a long time at it wondering why y is being decremented even for ``x > y``. Because there are no begin/end brackets, Python is much less prone to coding-style conflicts. In C there are many different ways to place the braces. If you're used to reading and writing code that uses one style, you will feel at least slightly uneasy when reading (or being required to write) another style. Many coding styles place begin/end brackets on a line by themself. This makes programs considerably longer and wastes valuable screen space, making it harder to get a good overview of a program. Ideally, a function should fit on onescreen (say, 20-30 lines). 20 lines of Python can do a lot more work than 20 lines of C. This is not solely due to the lack of begin/end brackets -- the lack of declarations and the high-level data types are also responsible -- but the indentation-based syntax certainly helps. Why are floating point calculations so inaccurate? -------------------------------------------------- People are often very surprised by results like this:: >>> 1.2-1.0 0.199999999999999996 and think it is a bug in Python. It's not. It's a problem caused by the internal representation of floating point numbers, which uses a fixed number of binary digits to represent a decimal number. Some decimal numbers can't be represented exactly in binary, resulting in small roundoff errors. In decimal math, there are many numbers that can't be represented with a fixed number of decimal digits, e.g. 1/3 = 0.3333333333....... In base 2, 1/2 = 0.1, 1/4 = 0.01, 1/8 = 0.001, etc. .2 equals 2/10 equals 1/5, resulting in the binary fractional number 0.001100110011001... Floating point numbers only have 32 or 64 bits of precision, so the digits are cut off at some point, and the resulting number is 0.199999999999999996 in decimal, not 0.2. A floating point's ``repr()`` function prints as many digits are necessary to make ``eval(repr(f)) == f`` true for any float f. The ``str()`` function prints fewer digits and this often results in the more sensible number that was probably intended:: >>> 0.2 0.20000000000000001 >>> print 0.2 0.2 Again, this has nothing to do with Python, but with the way the underlying C platform handles floating point numbers, and ultimately with the inaccuracy you'll always have when writing down numbers as a string of a fixed number of digits. One of the consequences of this is that it is dangerous to compare the result of some computation to a float with == ! Tiny inaccuracies may mean that == fails. Instead, you have to check that the difference between the two numbers is less than a certain threshold:: epsilon = 0.0000000000001 # Tiny allowed error expected_result = 0.4 if expected_result-epsilon <= computation() <= expected_result+epsilon: ... Please see the chapter on `floating point arithmetic `_ in the Python tutorial for more information. Why are Python strings immutable? --------------------------------- There are several advantages. One is performance: knowing that a string is immutable makes it easy to lay it out at construction time -- fixed and unchanging storage requirements. This is also one of the reasons for the distinction between tuples and lists. The other is that strings in Python are considered as "elemental" as numbers. No amount of activity will change the value 8 to anything else, and in Python, no amount of activity will change the string "eight" to anything else. Why must 'self' be used explicitly in method definitions and calls? ------------------------------------------------------------------- The idea was borrowed from Modula-3. It turns out to be very useful, for a variety of reasons. First, it's more obvious that you are using a method or instance attribute instead of a local variable. Reading ``self.x`` or ``self.meth()`` makes it absolutely clear that an instance variable or method is used even if you don't know the class definition by heart. In C++, you can sort of tell by the lack of a local variable declaration (assuming globals are rare or easily recognizable) -- but in Python, there are no local variable declarations, so you'd have to look up the class definition to be sure. Some C++ and Java coding standards call for instance attributes to have an ``m_`` prefix, so this explicitness is still useful in those languages, too. Second, it means that no special syntax is necessary if you want to explicitly reference or call the method from a particular class. In C++, if you want to use a method from a base class which is overridden in a derived class, you have to use the :: operator -- in Python you can write baseclass.methodname(self, ). This is particularly useful for __init__() methods, and in general in cases where a derived class method wants to extend the base class method of the same name and thus has to call the base class method somehow. Finally, for instance variables it solves a syntactic problem with assignment: since local variables in Python are (by definition!) those variables to which a value assigned in a function body (and that aren't explicitly declared global), there has to be some way to tell the interpreter that an assignment was meant to assign to an instance variable instead of to a local variable, and it should preferably be syntactic (for efficiency reasons). C++ does this through declarations, but Python doesn't have declarations and it would be a pity having to introduce them just for this purpose. Using the explicit "self.var" solves this nicely. Similarly, for using instance variables, having to write "self.var" means that references to unqualified names inside a method don't have to search the instance's directories. Why can't I use an assignment in an expression? ------------------------------------------------------- Many people used to C or Perl complain that they want to use this C idiom:: while (line = readline(f)) { ...do something with line... } where in Python you're forced to write this:: while True: line = f.readline() if not line: break ...do something with line... The reason for not allowing assignment in Python expressions is a common, hard-to-find bug in those other languages, caused by this construct:: if (x = 0) { ...error handling... } else { ...code that only works for nonzero x... } The error is a simple typo: ``x = 0``, which assigns 0 to the variable ``x``, was written while the comparison ``x == 0`` is certainly what was intended. Many alternatives have been proposed. Most are hacks that save some typing but use arbitrary or cryptic syntax or keywords, and fail the simple criterion for language change proposals: it should intuitively suggest the proper meaning to a human reader who has not yet been introduced to the construct. An interesting phenomenon is that most experienced Python programmers recognize the "while True" idiom and don't seem to be missing the assignment in expression construct much; it's only newcomers who express a strong desire to add this to the language. There's an alternative way of spelling this that seems attractive but is generally less robust than the "while True" solution:: line = f.readline() while line: ...do something with line... line = f.readline() The problem with this is that if you change your mind about exactly how you get the next line (e.g. you want to change it into ``sys.stdin.readline()``) you have to remember to change two places in your program -- the second occurrence is hidden at the bottom of the loop. Why does Python use methods for some functionality (e.g. list.index()) but functions for other (e.g. len(list))? ---------------------------------------------------------------------------------------------------------------- The major reason is history. Functions were used for those operations that were generic for a group of types and which were intended to work even for objects that didn't have methods at all (e.g. tuples). It is also convenient to have a function that can readily be applied to an amorphous collection of objects when you use the functional features of Python (``map()``, ``apply()`` et al). In fact, implementing ``len()``, ``max()``, ``min()`` as a built-in function is actually less code than implementing them as methods for each type. One can quibble about individual cases but it's a part of Python, and it's too late to make such fundamental changes now. The functions have to remain to avoid massive code breakage. Note that for string operations Python has moved from external functions (the ``string`` module) to methods. However, ``len()`` is still a function. Why is join() a string method instead of a list or tuple method? ---------------------------------------------------------------- Strings became much more like other standard types starting in Python 1.6, when methods were added which give the same functionality that has always been available using the functions of the string module. Most of these new methods have been widely accepted, but the one which appears to make some programmers feel uncomfortable is:: ", ".join(['1', '2', '4', '8', '16']) which gives the result:: "1, 2, 4, 8, 16" There are two usual arguments against this usage. The first runs along the lines of: "It looks really ugly using a method of a string literal (string constant)", to which the answer is that it might, but a string literal is just a fixed value. If the methods are to be allowed on names bound to strings there is no logical reason to make them unavailable on literals. The second objection is typically cast as: "I am really telling a sequence to join its members together with a string constant". Sadly, you aren't. For some reason there seems to be much less difficulty with having split() as a string method, since in that case it is easy to see that :: "1, 2, 4, 8, 16".split(", ") is an instruction to a string literal to return the substrings delimited by the given separator (or, by default, arbitrary runs of white space). In this case a Unicode string returns a list of Unicode strings, an ASCII string returns a list of ASCII strings, and everyone is happy. join() is a string method because in using it you are telling the separator string to iterate over an arbitrary sequence, forming string representations of each of the elements, and inserting itself between the elements' representations. This method can be used with any argument which obeys the rules for sequence objects, inluding any new classes you might define yourself. Because this is a string method it can work for Unicode strings as well as plain ASCII strings. If join() were a method of the sequence types then the sequence types would have to decide which type of string to return depending on the type of the separator. If none of these arguments persuade you, then for the moment you can continue to use the join() function from the string module, which allows you to write :: string.join(['1', '2', '4', '8', '16'], ", ") How fast are exceptions? ------------------------ A try/except block is extremely efficient. Actually executing an exception is expensive. In versions of Python prior to 2.0 it was common to use this idiom:: try: value = dict[key] except KeyError: dict[key] = getvalue(key) value = dict[key] This only made sense when you expected the dict to have the key almost all the time. If that wasn't the case, you coded it like this:: if dict.has_key(key): value = dict[key] else: dict[key] = getvalue(key) value = dict[key] (In Python 2.0 and higher, you can code this as ``value = dict.setdefault(key, getvalue(key))``.) Why isn't there a switch or case statement in Python? ----------------------------------------------------- You can do this easily enough with a sequence of if... elif... elif... else. There have been some proposals for switch statement syntax, but there is no consensus (yet) on whether and how to do range tests. See `PEP 275 `_ for complete details and the current status. Can't you emulate threads in the interpreter instead of relying on an OS-specific thread implementation? -------------------------------------------------------------------------------------------------------- Answer 1: Unfortunately, the interpreter pushes at least one C stack frame for each Python stack frame. Also, extensions can call back into Python at almost random moments. Therefore, a complete threads implementation requires thread support for C. Answer 2: Fortunately, there is `Stackless Python `_, which has a completely redesigned interpreter loop that avoids the C stack. It's still experimental but looks very promising. Although it is binary compatible with standard Python, it's still unclear whether Stackless will make it into the core -- maybe it's just too revolutionary. Why can't lambda forms contain statements? ------------------------------------------ Python lambda forms cannot contain statements because Python's syntactic framework can't handle statements nested inside expressions. However, in Python, this is not a serious problem. Unlike lambda forms in other languages, where they add functionality, Python lambdas are only a shorthand notation if you're too lazy to define a function. Functions are already first class objects in Python, and can be declared in a local scope. Therefore the only advantage of using a lambda form instead of a locally-defined function is that you don't need to invent a name for the function -- but that's just a local variable to which the function object (which is exactly the same type of object that a lambda form yields) is assigned! Can Python be compiled to machine code, C or some other language? ----------------------------------------------------------------- Not easily. Python's high level data types, dynamic typing of objects and run-time invocation of the interpreter (using ``eval()`` or ``exec``) together mean that a "compiled" Python program would probably consist mostly of calls into the Python run-time system, even for seemingly simple operations like ``x+1``. Several projects described in the Python newsgroup or at past `Python conferences `_ have shown that this approach is feasible, although the speedups reached so far are only modest (e.g. 2x). Jython uses the same strategy for compiling to Java bytecode. (Jim Hugunin has demonstrated that in combination with whole-program analysis, speedups of 1000x are feasible for small demo programs. See the proceedings from the `1997 Python conference `_ for more information.) Internally, Python source code is always translated into a bytecode representation, and this bytecode is then executed by the Python virtual machine. In order to avoid the overhead of repeatedly parsing and translating modules that rarely change, this byte code is written into a file whose name ends in ".pyc" whenever a module is parsed. When the corresponding .py file is changed, it is parsed and translated again and the .pyc file is rewritten. There is no performance difference once the .pyc file has been loaded, as the bytecode read from the .pyc file is exactly the same as the bytecode created by direct translation. The only difference is that loading code from a .pyc file is faster than parsing and translating a .py file, so the presence of precompiled .pyc files improves the start-up time of Python scripts. If desired, the Lib/compileall.py module can be used to create valid .pyc files for a given set of modules. Note that the main script executed by Python, even if its filename ends in .py, is not compiled to a .pyc file. It is compiled to bytecode, but the bytecode is not saved to a file. Usually main scripts are quite short, so this doesn't cost much speed. If you are looking for a way to package up a Python program in order to distribute it in binary form without the need to distribute the interpreter and library as well, there are a few solutions available, `Gordon McMillan's Installer `_ and `Thomas Heller's py2exe `_. There are also several programs which make it easier to intermingle Python and C code in various ways to increase performance. See, for example, `Psyco `_, `Pyrex `_, `PyInline `_, `Py2Cmod `_, and `Weave `_. How does Python manage memory? ------------------------------ The details of Python memory management depend on the implementation. The standard C implementation of Python uses reference counting to detect inaccessible objects, and another mechanism to collect reference cycles, periodically executing a cycle detection algorithm which looks for inaccessible cycles and deletes the objects involved. The ``gc`` module provides functions to perform a garbage collection, obtain debugging statistics, and tune the collector's parameters. Jython relies on the Java runtime so the JVM's garbage collector is used. This difference can cause some subtle porting problems if your Python code depends on the behavior of the reference counting implementation. Sometimes objects get stuck in tracebacks temporarily and hence are not deallocated when you might expect. Clear the tracebacks with:: import sys sys.exc_clear() sys.exc_traceback = sys.last_traceback = None Tracebacks are used for reporting errors, implementing debuggers and related things. They contain a portion of the program state extracted during the handling of an exception (usually the most recent exception). In the absence of circularities and tracebacks, Python programs need not explicitly manage memory. Why doesn't Python use a more traditional garbage collection scheme? For one thing, this is not a C standard feature and hence it's not portable. (Yes, we know about the Boehm GC library. It has bits of assembler code for *most* common platforms, not for all of them, and although it is mostly transparent, it isn't completely transparent; patches are required to get Python to work with it.) Traditional GC also becomes a problem when Python is embedded into other applications. While in a standalone Python it's fine to replace the standard malloc() and free() with versions provided by the GC library, an application embedding Python may want to have its *own* substitute for malloc() and free(), and may not want Python's. Right now, Python works with anything that implements malloc() and free() properly. In Jython, the following code (which is fine in CPython) will probably run out of file descriptors long before it runs out of memory:: for file in : f = open(file) c = f.read(1) Using the current reference counting and destructor scheme, each new assignment to f closes the previous file. Using GC, this is not guaranteed. If you want to write code that will work with any Python implementation, you should explicitly close the file; this will work regardless of GC:: for file in : f = open(file) c = f.read(1) f.close() Why isn't all memory freed when Python exits? ----------------------------------------------------- Objects referenced from the global namespaces of Python modules are not always deallocated when Python exits. This may happen if there are circular references. There are also certain bits of memory that are allocated by the C library that are impossible to free (e.g. a tool like Purify will complain about these). Python is, however, aggressive about cleaning up memory on exit and does try to destroy every single object. If you want to force Python to delete certain things on deallocation use the ``sys.exitfunc()`` hook to run a function that will force those deletions. Why are there separate tuple and list data types? ------------------------------------------------- Lists and tuples, while similar in many respects, are generally used in fundamentally different ways. Tuples can be thought of as being similar to Pascal records or C structs; they're small collections of related data which may be of different types which are operated on as a group. For example, a Cartesian coordinate is appropriately represented as a tuple of two or three numbers. Lists, on the other hand, are more like arrays in other languages. They tend to hold a varying number of objects all of which have the same type and which are operated on one-by-one. For example, ``os.listdir('.')`` returns a list of strings representing the files in the current directory. Functions which operate on this output would generally not break if you added another file or two to the directory. How are lists implemented? -------------------------- Python's lists are really variable-length arrays, not Lisp-style linked lists. The implementation uses a contiguous array of references to other objects, and keeps a pointer to this array and the array's length in a list head structure. This makes indexing a list ``a[i]`` an operation whose cost is independent of the size of the list or the value of the index. When items are appended or inserted, the array of references is resized. Some cleverness is applied to improve the performance of appending items repeatedly; when the array must be grown, some extra space is allocated so the next few times don't require an actual resize. How are dictionaries implemented? ----------------------------------------- Python's dictionaries are implemented as resizable hash tables. Compared to B-trees, this gives better performance for lookup (the most common operation by far) under most circumstances, and the implementation is simpler. Dictionaries work by computing a hash code for each key stored in the dictionary using the ``hash()`` built-in function. The hash code varies widely depending on the key; for example, "Python" hashes to -539294296 while "python", a string that differs by a single bit, hashes to 1142331976. The hash code is then used to calculate a location in an internal array where the value will be stored. Assuming that you're storing keys that all have different hash values, this means that dictionaries take constant time -- O(1), in computer science notation -- to retrieve a key. It also means that no sorted order of the keys is maintained, and traversing the array as the ``.keys()`` and ``.items()`` do will output the dictionary's content in some arbitrary jumbled order. Why must dictionary keys be immutable? ---------------------------------------------- The hash table implementation of dictionaries uses a hash value calculated from the key value to find the key. If the key were a mutable object, its value could change, and thus its hash could also change. But since whoever changes the key object can't tell that it was being used as a dictionary key, it can't move the entry around in the dictionary. Then, when you try to look up the same object in the dictionary it won't be found because its hash value is different. If you tried to look up the old value it wouldn't be found either, because the value of the object found in that hash bin would be different. If you want a dictionary indexed with a list, simply convert the list to a tuple first; the function ``tuple(L)`` creates a tuple with the same entries as the list ``L``. Tuples are immutable and can therefore be used as dictionary keys. Some unacceptable solutions that have been proposed: - Hash lists by their address (object ID). This doesn't work because if you construct a new list with the same value it won't be found; e.g.:: d = {[1,2]: '12'} print d[[1,2]] would raise a KeyError exception because the id of the ``[1,2]`` used in the second line differs from that in the first line. In other words, dictionary keys should be compared using ``==``, not using 'is'. - Make a copy when using a list as a key. This doesn't work because the list, being a mutable object, could contain a reference to itself, and then the copying code would run into an infinite loop. - Allow lists as keys but tell the user not to modify them. This would allow a class of hard-to-track bugs in programs when you forgot or modified a list by accident. It also invalidates an important invariant of dictionaries: every value in ``d.keys()`` is usable as a key of the dictionary. - Mark lists as read-only once they are used as a dictionary key. The problem is that it's not just the top-level object that could change its value; you could use a tuple containing a list as a key. Entering anything as a key into a dictionary would require marking all objects reachable from there as read-only -- and again, self-referential objects could cause an infinite loop. There is a trick to get around this if you need to, but use it at your own risk: You can wrap a mutable structure inside a class instance which has both a __cmp__ and a __hash__ method. You must then make sure that the hash value for all such wrapper objects that reside in a dictionary (or other hash based structure), remain fixed while the object is in the dictionary (or other structure).:: class ListWrapper: def __init__(self, the_list): self.the_list = the_list def __cmp__(self, other): return self.the_list == other.the_list def __hash__(self): l = self.the_list result = 98767 - len(l)*555 for i in range(len(l)): try: result = result + (hash(l[i]) % 9999999) * 1001 + i except: result = (result % 7777777) + i * 333 return result Note that the hash computation is complicated by the possibility that some members of the list may be unhashable and also by the possibility of arithmetic overflow. Furthermore it must always be the case that if ``o1 == o2`` (ie ``o1.__cmp__(o2)==0``) then ``hash(o1)==hash(o2)`` (ie, ``o1.__hash__() == o2.__hash__()``), regardless of whether the object is in a dictionary or not. If you fail to meet these restrictions dictionaries and other hash based structures will misbehave. In the case of ListWrapper, whenever the wrapper object is in a dictionary the wrapped list must not change to avoid anomalies. Don't do this unless you are prepared to think hard about the requirements and the consequences of not meeting them correctly. Consider yourself warned. Why doesn't list.sort() return the sorted list? ------------------------------------------------------- In situations where performance matters, making a copy of the list just to sort it would be wasteful. Therefore, ``list.sort()`` sorts the list in place. In order to remind you of that fact, it does not return the sorted list. This way, you won't be fooled into accidentally overwriting a list when you need a sorted copy but also need to keep the unsorted version around. As a result, here's the idiom to iterate over the keys of a dictionary in sorted order:: keys = dict.keys() keys.sort() for key in keys: ...do whatever with dict[key]... How do you specify and enforce an interface spec in Python? ------------------------------------------------------------------- An interface specification for a module as provided by languages such as C++ and Java describes the prototypes for the methods and functions of the module. Many feel that compile-time enforcement of interface specifications help in the construction of large programs. Python does not support interface specifications directly, but many of their advantages can be obtained by an appropriate test discipline for components, which can often be very easily accomplished in Python. There is also a tool, PyChecker, which can be used to find problems due to subclassing. A good test suite for a module can at once provide a regression test and serve as both a module interface specification and a set of examples. Many Python modules can be run as a script to provide a simple "self test." Even modules which use complex external interfaces can often be tested in isolation using trivial "stub" emulations of the external interface. The ``doctest`` and ``unittest`` modules or third-party test frameworks can be used to construct exhaustive test suites that exercise every line of code in a module. An appropriate testing discipline can help build large complex applications in Python as well as having interface specifications would. In fact, it can be better because an interface specification cannot test certain properties of a program. For example, the ``append()`` method is expected to add new elements to the end of some internal list; an interface specification cannot test that your ``append()`` implementation will actually do this correctly, but it's trivial to check this property in a test suite. Writing test suites is very helpful, and you might want to design your code with an eye to making it easily tested. One increasingly popular technique, test-directed development, calls for writing parts of the test suite first, before you write any of the actual code. Of course Python allows you to be sloppy and not write test cases at all. Why are default values shared between objects? ---------------------------------------------------------------- This type of bug commonly bites neophyte programmers. Consider this function:: def foo(D={}): # Danger: shared reference to one dict for all calls ... compute something ... D[key] = value return D The first time you call this function, ``D`` contains a single item. The second time, ``D`` contains two items because when ``foo()`` begins executing, ``D`` starts out with an item already in it. It is often expected that a function call creates new objects for default values. This is not what happens. Default values are created exactly once, when the function is defined. If that object is changed, like the dictionary in this example, subsequent calls to the function will refer to this changed object. By definition, immutable objects such as numbers, strings, tuples, and ``None``, are safe from change. Changes to mutable objects such as dictionaries, lists, and class instances can lead to confusion. Because of this feature, it is good programming practice to not use mutable objects as default values. Instead, use ``None`` as the default value and inside the function, check if the parameter is ``None`` and create a new list/dictionary/whatever if it is. For example, don't write:: def foo(dict={}): ... but:: def foo(dict=None): if dict is None: dict = {} # create a new dict for local namespace This feature can be useful. When you have a function that's time-consuming to compute, a common technique is to cache the parameters and the resulting value of each call to the function, and return the cached value if the same value is requested again. This is called "memoizing", and can be implemented like this:: # Callers will never provide a third parameter for this function. def expensive (arg1, arg2, _cache={}): if _cache.has_key((arg1, arg2)): return _cache[(arg1, arg2)] # Calculate the value result = ... expensive computation ... _cache[(arg1, arg2)] = result # Store result in the cache return result You could use a global variable containing a dictionary instead of the default value; it's a matter of taste. Why is there no goto? ------------------------ You can use exceptions to provide a "structured goto" that even works across function calls. Many feel that exceptions can conveniently emulate all reasonable uses of the "go" or "goto" constructs of C, Fortran, and other languages. For example:: class label: pass # declare a label try: ... if (condition): raise label() # goto label ... except label: # where to goto pass ... This doesn't allow you to jump into the middle of a loop, but that's usually considered an abuse of goto anyway. Use sparingly. Why do I get a SyntaxError for a 'continue' inside a 'try'? ------------------------------------------------------------------- This is an implementation limitation, caused by the extremely simple-minded way Python generates bytecode. The ``try`` block pushes something on the "block stack" which the ``continue`` would have to pop off again. The current code generator doesn't have the data structures around so that ``continue`` can generate the right code. Note that Jython doesn't have this restriction! Why can't raw strings (r-strings) end with a backslash? --------------------------------------------------------------- More precisely, they can't end with an odd number of backslashes: the unpaired backslash at the end escapes the closing quote character, leaving an unterminated string. Raw strings were designed to ease creating input for processors (chiefly regular expression engines) that want to do their own backslash escape processing. Such processors consider an unmatched trailing backslash to be an error anyway, so raw strings disallow that. In return, they allow you to pass on the string quote character by escaping it with a backslash. These rules work well when r-strings are used for their intended purpose. If you're trying to build Windows pathnames, note that all Windows system calls accept forward slashes too:: f = open("/mydir/file.txt") # works fine! If you're trying to build a pathname for a DOS command, try e.g. one of :: dir = r"\this\is\my\dos\dir" "\\" dir = r"\this\is\my\dos\dir\ "[:-1] dir = "\\this\\is\\my\\dos\\dir\\" Why doesn't Python have a "with" statement like some other languages? --------------------------------------------------------------------------------------- Because such a construct would be ambiguous. Some languages, such as Object Pascal, Delphi, and C++, use static types. So it is possible to know, in an unambiguous way, what member is being assigned in a "with" clause. This is the main point - the compiler *always* knows the scope of every variable at compile time. Python uses dynamic types. It is impossible to know in advance which attribute will be referenced at runtime. Member attributes may be added or removed from objects on the fly. This would make it impossible to know, from a simple reading, what attribute is being referenced - a local one, a global one, or a member attribute. For instance, take the following incomplete snippet:: def foo(a): with a: print x The snippet assumes that "a" must have a member attribute called "x". However, there is nothing in Python that guarantees that. What should happen if "a" is, let us say, an integer? And if I have a global variable named "x", will it end up being used inside the with block? As you see, the dynamic nature of Python makes such choices much harder. The primary benefit of "with" and similar language features (reduction of code volume) can, however, easily be achieved in Python by assignment. Instead of:: function(args).dict[index][index].a = 21 function(args).dict[index][index].b = 42 function(args).dict[index][index].c = 63 write this:: ref = function(args).dict[index][index] ref.a = 21 ref.b = 42 ref.c = 63 This also has the side-effect of increasing execution speed because name bindings are resolved at run-time in Python, and the second version only needs to perform the resolution once. If the referenced object does not have a, b and c attributes, of course, the end result is still a run-time exception. Why are colons required for the if/while/def/class statements? -------------------------------------------------------------------- The colon is required primarily to enhance readability (one of the results of the experimental ABC language). Consider this:: if a==b print a versus :: if a==b: print a Notice how the second one is slightly easier to read. Notice further how a colon sets off the example in the second line of this FAQ answer; it's a standard usage in English. Another minor reason is that the colon makes it easier for editors with syntax highlighting; they can look for colons to decide when indentation needs to be increased instead of having to do a more elaborate parsing of the program text. From falted@openlc.org Thu Aug 14 11:38:36 2003 From: falted@openlc.org (Francesc Alted) Date: Thu, 14 Aug 2003 12:38:36 +0200 Subject: PyTables 0.7.1 Message-ID: PyTables 0.7.1 is out! ---------------------- This is a mainly a bug-fixing release, where the next problems has been addressed: - Fixed several memory leaks. After that, the memory consumption when using large object trees has dropped sensibly. However, there remains some small leaks, but hopefully they are not very important unless you use *huge* object trees. - Fixed a bug that make the __getitem__ special method in table to fail when the stop parameter in a extended slice was not specified. That is, table[10:] now correctly returns table[10:table.nrows+1], and not table[10:11]. - The removeRows() method in Table did not update the NROWS attribute in Table objects, giving place to errors after doing further updating operations (removing or adding more rows) in the same table. This has been fixed now. - The documentation has been updated, specially a more detailed instructions on the compression (zlib) libraries installation. Apart of these fixes, a new lazy reading algorithm for attributes has been activated by default. With that, the opening of objects with large hierarchies has been improved by 60% (you can obtain another additional 10% if using python 2.3 instead of python 2.2). Also, a stress test has been conducted in order to see if PyTables can *really* work not only with large data tables, but also with large object trees. In it, it has been generated and checked a file with more than 1 TB of size and more than 100 thousand tables on it!. See http://pytables.sourceforge.net/doc/stress-test.html for details. As always, let me know of any bugs, suggestions, etc. you may have. -- Francesc Alted From knight@baldmt.com Thu Aug 14 21:49:50 2003 From: knight@baldmt.com (Steven Knight) Date: Thu, 14 Aug 2003 15:49:50 -0500 (CDT) Subject: ANNOUNCE: SCons beta 0.91 adds Qt and SWIG support Message-ID: SCons is a software construction tool (build tool, or make tool) written in Python. It is based on the design which won the Software Carpentry build tool competition in August 2000. Beta version 0.91 of SCons has been released and is available for download from the SCons web site: http://www.scons.org/ Or through the download link at the SCons project page at SourceForge: http://sourceforge.net/projects/scons/ RPM and Debian packages and a Win32 installer are all available, in addition to the traditional .tar.gz and .zip files. WHAT'S NEW IN THIS RELEASE? IMPORTANT: Release 0.91 contains the following interface changes: - The spelling of the "validater" Builder option has been corrected to "validator". The old spelling still works, but generates a warning. - The SConscript() function no longer automatically splits its argument on white space into a list of SConscript file names. You must now explicitly enclose the argument in the Split() function (or do something similar) if you want that behavior. See the release notes for more information about these changes. This release adds the following features: - SWIG support has been added. - Qt support for processing .ui files into .c files has been added. - You may now specify a list of tools when calling Environment.Copy(). - A new "sconsign" script can be used to dump the contents of .sconsign files. - A new $MAXLINELENGTH construction variables allows control of when a temporary file is used for long link lines on Win32. - A Builder emitter can now be a dictionary that maps different source file types (suffixes) to separate emitter functions. - Builder "prefix" and "suffix" arguments can now be callables that return generated strings, or dictionaries that map different source file types (suffixes) to separate prefix or suffix values. - When executing a Win32 long link line in a temporary file, SCons now also prints the long line being executed through the file. - A new $CPPDEFINES variables supports defining platform-independent C preprocessor command-line arguments. - SCons now uses the C++ compiler only if there are any object files from C++ sources being linked, and otherwise invokes the C compiler. The following fixes have been added: - Python Value Nodes now work when using timestamps for signatures. - SCons now creates a .hpp file when the yacc file ends in .yy and the -d YACC flag is used. - SCons now correctly deduces target prefixes from source files in subdirectories in all tested cases. - When CVS checkout errors occur, SCons no longer creates zero-length files by mistake. - All Actions now print correctly when using the --cache-show option. - The Command() Builder can now take a directory as a source. - SConscript file or path names with white space now work. - The Microsoft Visual C++ /TP argument has been added to the default $CXXFLAGS value, so it can compile all the different C++ suffixes. - A problem with checking whether certain Node types are up-to-date has been fixed. - The LIB construction variable is now initialized for the Intel compiler (icl). - The g++ and gcc Tool specifications now actually use g++ and gcc in preference to c++ and cc. - SCons configuration tests no longer hang if a piped command generates more output than can be read in single buffer. Error handling has been improved as follows: - Handling Python errors in SConscript files is now more informative. - SCons now reports the target being built in various error conditions that prevent the build Action from being executed. - Incorrect arguments to the Install() function generates a better error message. - A stack trace is now generated if the internal task controller catches an exception. Performance has been improved as follows: - A default environment is created when needed, not every invocation. - Internal maintenance of various lists of dependencies has been sped up by using a dictionary to search for duplication. - The list of dependent children is now calculated once and cached. - The -debug=pdb option now invokes the Python debugger directly, not by recursively invoking Python+SCons. The following changes have been made to the SCons packaging: - An incorrect distutils warning message when using --prefix= option has been removed. - Building the SCons .rpm package should no longer depend on the installation location of the local distutils. The documentation has been improved: - The help output generated by "scons -H" has been tightened. - An explanation about SCons not propagating the external environment has been added to the introduction. - The AlwaysBuild() function is now better explained. - The SConscript function's "dirs" and "name" keywords are now documented. - Typos have been fixed. ABOUT SCONS Distinctive features of SCons include: - a global view of all dependencies; no multiple passes to get everything built properly - configuration files are Python scripts, allowing the full use of a real scripting language to solve difficult build problems - a modular architecture allows the SCons Build Engine to be embedded in other Python software - the ability to scan files for implicit dependencies (#include files); - improved parallel build (-j) support that provides consistent build speedup regardless of source tree layout - use of MD5 signatures to decide if a file has really changed; no need to "touch" files to fool make that something is up-to-date - easily extensible through user-defined Builder and Scanner objects - build actions can be Python code, as well as external commands An scons-users mailing list is available for those interested in getting started using SCons. You can subscribe at: http://lists.sourceforge.net/lists/listinfo/scons-users Alternatively, we invite you to subscribe to the low-volume scons-announce mailing list to receive notification when new versions of SCons become available: http://lists.sourceforge.net/lists/listinfo/scons-announce ACKNOWLEDGEMENTS Special thanks to Chad Austin, Bram Moolenaar, Gary Oberbrunner, Laurent Pelecq, Ben Scott and Christoph Wiedemann for their contributions to this release. On behalf of the SCons team, --SK From zanesdad@bellsouth.net Fri Aug 15 05:51:25 2003 From: zanesdad@bellsouth.net (Jeremy Jones) Date: Fri, 15 Aug 2003 00:51:25 -0400 Subject: ANN: munkwar Message-ID: I am happy to announce the creation of Munkware, a brand new project on Sourceforge. Munkware is a transactional and persistent queueing system inspired by Queue.Queue() in the Python standard library. The project can be found at: http://sourceforge.net/projects/munkware/ Currently, the SourceForge project homepage doesn't seem to be updating with the index page that I uploaded earlier. Sorry for that. Anyhow, feedback is ecstatically welcome. Jeremy Jones From zanesdad@bellsouth.net Fri Aug 15 13:31:14 2003 From: zanesdad@bellsouth.net (Jeremy Jones) Date: Fri, 15 Aug 2003 08:31:14 -0400 Subject: ANN: Munkware Message-ID: Sorry if this is re-posted. I am having some email problems right now. I posted last night and haven't seen my email show up just yet on the list - either on google or in my own emails from c.l.p (and I just checked and made sure that I am supposed to receive emails from myself). I am happy to announce the creation of Munkware, a brand new project on Sourceforge. Munkware is a transactional and persistent queueing system inspired by Queue.Queue() in the Python standard library. The project can be found at: http://sourceforge.net/projects/munkware/ Project home page is located at: http://munkware.sourceforge.net/ Anyhow, feedback is ecstatically welcome. Jeremy Jones From jcribbs@twmi.rr.com Sat Aug 16 02:56:13 2003 From: jcribbs@twmi.rr.com (Jamey Cribbs) Date: Sat, 16 Aug 2003 01:56:13 GMT Subject: ANNOUNCE: KirbyBase 1.3 Message-ID: KirbyBase 1.3 is now available at: http://www.netpromi.com/files/KirbyBase-1.3.zip What is KirbyBase? KirbyBase is a simple, pure-Python, plain-text, flat-file database management system that can be used either embedded in your application or in a client/server, multi-user mode. To find out more about KirbyBase, go to: http://www.netpromi.com/kirbybase.html Changes: Added ability to pass field values to update and insert using a dictionary. Added ability to specify field to sort on and sort direction for the results of a select. Added len method. Fixed bug in validateMatchCriteria where script was not restricting other match criteria if already attempting to match by recno. Fixed bug in validateMatchCriteria where script was not checking to see if pattern argument was an integer when attempting to match by recno. Changed the way field types are handled internally. This should not change any of the api or interfaces, EXCEPT for the getFieldTypes method, which now returns a list of types, instead of a list of strings. I hope this doesn't screw anyone's programs up. Corrected version number to conform to guidelines in distutils documentation. From amk@nyman.amk.ca Sat Aug 16 20:48:21 2003 From: amk@nyman.amk.ca (amk@nyman.amk.ca) Date: Sat, 16 Aug 2003 15:48:21 -0400 Subject: Extending/Embedding FAQ Message-ID: The FAQ parade continues with the Extending/Embedding FAQ, covering Python's C API. Comments are welcome. (Volunteers to maintain any of these FAQs would be even more welcome.) --amk Title: Python Extending/Embedding FAQ Content-type: text/x-rst ==================================== Extending/Embedding FAQ ==================================== :Date: $Date: 2003/08/14 20:47:18 $ :Version: $Revision: 1.2 $ :Web site: http://www.python.org/ .. contents:: .. sectnum:: Can I create my own functions in C? ------------------------------------------ Yes, you can create built-in modules containing functions, variables, exceptions and even new types in C. This is explained in the document "Extending and Embedding the Python Interpreter" (http://www.python.org/doc/current/ext/ext.html). Most intermediate or advanced Python books will also cover this topic. Can I create my own functions in C++? -------------------------------------------- Yes, using the C compatibility features found in C++. Place ``extern "C" { ... }`` around the Python include files and put ``extern "C"`` before each function that is going to be called by the Python interpreter. Global or static C++ objects with constructors are probably not a good idea. Writing C is hard; are there any alternatives? --------------------------------------------------- There are a number of alternatives to writing your own C extensions, depending on what you're trying to do. If you need more speed, `Psyco `_ generates x86 assembly code from Python bytecode. You can use Psyco to compile the most time-critical functions in your code, and gain a significant improvement with very little effort, as long as you're running on a machine with an x86-compatible processor. `Pyrex `_ is a compiler that accepts a slightly modified form of Python and generates the corresponding C code. Pyrex makes it possible to write an extension without having to learn Python's C API. If you need to interface to some C library for which no Python extension currently exists, you can try wrapping the library's data types and functions with a tool such as `SWIG `_. For C++ libraries, you can look at `SIP `_, `CXX `_, `Boost `_, or `Weave `_. How can I execute arbitrary Python statements from C? ------------------------------------------------------------ The highest-level function to do this is ``PyRun_SimpleString()`` which takes a single string argument to be executed in the context of the module ``__main__`` and returns 0 for success and -1 when an exception occurred (including ``SyntaxError``). If you want more control, use ``PyRun_String()``; see the source for ``PyRun_SimpleString()`` in Python/pythonrun.c. How can I evaluate an arbitrary Python expression from C? ---------------------------------------------------------------- Call the function ``PyRun_String()`` from the previous question with the start symbol ``Py_eval_input``; it parses an expression, evaluates it and returns its value. How do I extract C values from a Python object? ------------------------------------------------------ That depends on the object's type. If it's a tuple, ``PyTupleSize(o)`` returns its length and ``PyTuple_GetItem(o, i)`` returns its i'th item. Lists have similar functions, ``PyListSize(o)`` and ``PyList_GetItem(o, i)``. For strings, ``PyString_Size(o)`` returns its length and ``PyString_AsString(o)`` a pointer to its value. Note that Python strings may contain null bytes so C's ``strlen()`` should not be used. To test the type of an object, first make sure it isn't NULL, and then use ``PyString_Check(o)``, ``PyTuple_Check(o)``, ``PyList_Check(o)``, etc. There is also a high-level API to Python objects which is provided by the so-called 'abstract' interface -- read ``Include/abstract.h`` for further details. It allows interfacing with any kind of Python sequence using calls like ``PySequence_Length()``, ``PySequence_GetItem()``, etc.) as well as many other useful protocols. How do I use Py_BuildValue() to create a tuple of arbitrary length? -------------------------------------------------------------------------- You can't. Use ``t = PyTuple_New(n)`` instead, and fill it with objects using ``PyTuple_SetItem(t, i, o)`` -- note that this "eats" a reference count of ``o``, so you have to ``Py_INCREF`` it. Lists have similar functions ``PyList_New(n)`` and ``PyList_SetItem(l, i, o)``. Note that you *must* set all the tuple items to some value before you pass the tuple to Python code -- ``PyTuple_New(n)`` initializes them to NULL, which isn't a valid Python value. How do I call an object's method from C? ----------------------------------------------- The ``PyObject_CallMethod()`` function can be used to call an arbitrary method of an object. The parameters are the object, the name of the method to call, a format string like that used with ``Py_BuildValue()``, and the argument values:: PyObject * PyObject_CallMethod(PyObject *object, char *method_name, char *arg_format, ...); This works for any object that has methods -- whether built-in or user-defined. You are responsible for eventually ``Py_DECREF``'ing the return value. To call, e.g., a file object's "seek" method with arguments 10, 0 (assuming the file object pointer is "f"):: res = PyObject_CallMethod(f, "seek", "(ii)", 10, 0); if (res == NULL) { ... an exception occurred ... } else { Py_DECREF(res); } Note that since ``PyObject_CallObject()`` *always* wants a tuple for the argument list, to call a function without arguments, pass "()" for the format, and to call a function with one argument, surround the argument in parentheses, e.g. "(i)". How do I catch the output from PyErr_Print() (or anything that prints to stdout/stderr)? ----------------------------------------------------------------------------------------------- In Python code, define an object that supports the ``write()`` method. Assign this object to ``sys.stdout`` and ``sys.stderr``. Call print_error, or just allow the standard traceback mechanism to work. Then, the output will go wherever your ``write()`` method sends it. The easiest way to do this is to use the StringIO class in the standard library. Sample code and use for catching stdout:: >>> class StdoutCatcher: ... def __init__(self): ... self.data = '' ... def write(self, stuff): ... self.data = self.data + stuff ... >>> import sys >>> sys.stdout = StdoutCatcher() >>> print 'foo' >>> print 'hello world!' >>> sys.stderr.write(sys.stdout.data) foo hello world! How do I access a module written in Python from C? --------------------------------------------------------- You can get a pointer to the module object as follows:: module = PyImport_ImportModule(""); If the module hasn't been imported yet (i.e. it is not yet present in ``sys.modules``), this initializes the module; otherwise it simply returns the value of ``sys.modules[""]``. Note that it doesn't enter the module into any namespace -- it only ensures it has been initialized and is stored in ``sys.modules``. You can then access the module's attributes (i.e. any name defined in the module) as follows:: attr = PyObject_GetAttrString(module, ""); Calling ``PyObject_SetAttrString()`` to assign to variables in the module also works. How do I interface to C++ objects from Python? ------------------------------------------------------ Depending on your requirements, there are many approaches. To do this manually, begin by reading `the "Extending and Embedding" document `_. Realize that for the Python run-time system, there isn't a whole lot of difference between C and C++ -- so the strategy of building a new Python type around a C structure (pointer) type will also work for C++ objects. For C++ libraries, you can look at `SIP `_, `CXX `_, `Boost `_, or `Weave `_. `SWIG `_ is a similar automated tool that only supports C libraries. I added a module using the Setup file and the make fails; why? ---------------------------------------------------------------------- Setup must end in a newline, if there is no newline there, the build process fails. (Fixing this requires some ugly shell script hackery, and this bug is so minor that it doesn't seem worth the effort.) How do I debug an extension? ------------------------------------ When using GDB with dynamically loaded extensions, you can't set a breakpoint in your extension until your extension is loaded. In your ``.gdbinit`` file (or interactively), add the command:: br _PyImport_LoadDynamicModule Then, when you run GDB:: $ gdb /local/bin/python gdb) run myscript.py gdb) continue # repeat until your extension is loaded gdb) finish # so that your extension is loaded gdb) br myfunction.c:50 gdb) continue I want to compile a Python module on my Linux system, but some files are missing. Why? ------------------------------------------------------------------------------------------------- Most packaged versions of Python don't include the /usr/lib/python2.x/config/ directory, which contains various files required for compiling Python extensions. For Red Hat, install the python-devel RPM to get the necessary files. For Debian, run ``apt-get install python-devel``. What does "SystemError: _PyImport_FixupExtension: module yourmodule not loaded" mean? ------------------------------------------------------------------------------------------------------- This means that you have created an extension module named "yourmodule", but your module init function does not initialize with that name. Every module init function will have a line similar to:: module = Py_InitModule("yourmodule", yourmodule_functions); If the string passed to this function is not the same name as your extenion module, the ``SystemError`` exception will be raised. How do I tell "incomplete input" from "invalid input"? -------------------------------------------------------------------------------- Sometimes you want to emulate the Python interactive interpreter's behavior, where it gives you a continuation prompt when the input is incomplete (e.g. you typed the start of an "if" statement or you didn't close your parentheses or triple string quotes), but it gives you a syntax error message immediately when the input is invalid. In Python you can use the ``codeop`` module, which approximates the parser's behavior sufficiently. IDLE uses this, for example. The easiest way to do it in C is to call ``PyRun_InteractiveLoop()`` (perhaps in a separate thread) and let the Python interpreter handle the input for you. You can also set the ``PyOS_ReadlineFunctionPointer`` to point at your custom input function. See ``Modules/readline.c`` and ``Parser/myreadline.c`` for more hints. However sometimes you have to run the embedded Python interpreter in the same thread as your rest application and you can't allow the ``PyRun_InteractiveLoop()`` to stop while waiting for user input. The one solution then is to call ``PyParser_ParseString()`` and test for ``e.error`` equal to ``E_EOF``, which means the input is incomplete). Here's a sample code fragment, untested, inspired by code from Alex Farber:: #include #include #include #include #include #include int testcomplete(char *code) /* code should end in \n */ /* return -1 for error, 0 for incomplete, 1 for complete */ { node *n; perrdetail e; n = PyParser_ParseString(code, &_PyParser_Grammar, Py_file_input, &e); if (n == NULL) { if (e.error == E_EOF) return 0; return -1; } PyNode_Free(n); return 1; } Another solution is trying to compile the received string with ``Py_CompileString()``. If it compiles without errors, try to execute the returned code object by calling ``PyEval_EvalCode()``. Otherwise save the input for later. If the compilation fails, find out if it's an error or just more input is required - by extracting the message string from the exception tuple and comparing it to the string "unexpected EOF while parsing". Here is a complete example using the GNU readline library (you may want to ignore SIGINT while calling readline()):: #include #include #include #include #include #include int main (int argc, char* argv[]) { int i, j, done = 0; /* lengths of line, code */ char ps1[] = ">>> "; char ps2[] = "... "; char *prompt = ps1; char *msg, *line, *code = NULL; PyObject *src, *glb, *loc; PyObject *exc, *val, *trb, *obj, *dum; Py_Initialize (); loc = PyDict_New (); glb = PyDict_New (); PyDict_SetItemString (glb, "__builtins__", PyEval_GetBuiltins ()); while (!done) { line = readline (prompt); if (NULL == line) /* CTRL-D pressed */ { done = 1; } else { i = strlen (line); if (i > 0) add_history (line); /* save non-empty lines */ if (NULL == code) /* nothing in code yet */ j = 0; else j = strlen (code); code = realloc (code, i + j + 2); if (NULL == code) /* out of memory */ exit (1); if (0 == j) /* code was empty, so */ code[0] = '\0'; /* keep strncat happy */ strncat (code, line, i); /* append line to code */ code[i + j] = '\n'; /* append '\n' to code */ code[i + j + 1] = '\0'; src = Py_CompileString (code, "", Py_single_input); if (NULL != src) /* compiled just fine - */ { if (ps1 == prompt || /* ">>> " or */ '\n' == code[i + j - 1]) /* "... " and double '\n' */ { /* so execute it */ dum = PyEval_EvalCode ((PyCodeObject *)src, glb, loc); Py_XDECREF (dum); Py_XDECREF (src); free (code); code = NULL; if (PyErr_Occurred ()) PyErr_Print (); prompt = ps1; } } /* syntax error or E_EOF? */ else if (PyErr_ExceptionMatches (PyExc_SyntaxError)) { PyErr_Fetch (&exc, &val, &trb); /* clears exception! */ if (PyArg_ParseTuple (val, "sO", &msg, &obj) && !strcmp (msg, "unexpected EOF while parsing")) /* E_EOF */ { Py_XDECREF (exc); Py_XDECREF (val); Py_XDECREF (trb); prompt = ps2; } else /* some other syntax error */ { PyErr_Restore (exc, val, trb); PyErr_Print (); free (code); code = NULL; prompt = ps1; } } else /* some non-syntax error */ { PyErr_Print (); free (code); code = NULL; prompt = ps1; } free (line); } } Py_XDECREF(glb); Py_XDECREF(loc); Py_Finalize(); exit(0); } How do I find undefined g++ symbols __builtin_new or __pure_virtual? ----------------------------------------------------------------------------------- To dynamically load g++ extension modules, you must recompile Python, relink it using g++ (change LINKCC in the python Modules Makefile), and link your extension module using g++ (e.g., "g++ -shared -o mymodule.so mymodule.o"). Can I create an object class with some methods implemented in C and others in Python (e.g. through inheritance)? ----------------------------------------------------------------------------------------------------------------------------------------------------- In Python 2.2, you can inherit from builtin classes such as int, list, dict, etc. The Boost Python Library (BPL, http://www.boost.org/libs/python/doc/index.html) provides a way of doing this from C++ (i.e. you can inherit from an extension class written in C++ using the BPL). When importing module X, why do I get "undefined symbol: PyUnicodeUCS2*"? -------------------------------------------------------------------------------------------------- You are using a version of Python that uses a 4-byte representation for Unicode characters, but some C extension module you are importing was compiled using a Python that uses a 2-byte representation for Unicode characters (the default). If instead the name of the undefined symbol starts with ``PyUnicodeUCS4``, the problem is the reverse: Python was built using 2-byte Unicode characters, and the extension module was compiled using a Python with 4-byte Unicode characters. This can easily occur when using pre-built extension packages. RedHat Linux 7.x, in particular, provided a "python2" binary that is compiled with 4-byte Unicode. This only causes the link failure if the extension uses any of the ``PyUnicode_*()`` functions. It is also a problem if an extension uses any of the Unicode-related format specifiers for ``Py_BuildValue`` (or similar) or parameter specifications for ``PyArg_ParseTuple()``. You can check the size of the Unicode character a Python interpreter is using by checking the value of sys.maxunicode:: >>> import sys >>> if sys.maxunicode > 65535: ... print 'UCS4 build' ... else: ... print 'UCS2 build' The only way to solve this problem is to use extension modules compiled with a Python binary built using the same size for Unicode characters. From amk@nyman.amk.ca Sat Aug 16 20:50:19 2003 From: amk@nyman.amk.ca (amk@nyman.amk.ca) Date: Sat, 16 Aug 2003 15:50:19 -0400 Subject: GUI FAQ Message-ID: The GUI FAQ is really minimal; there weren't many questions in the old FAQ about GUIs, so this FAQ consists of two general questions about what GUI toolkit are available from Python, and two very specific Tkinter questions. --amk Title: Graphic User Interface FAQ Content-type: text/x-rst ==================================== Graphic User Interface FAQ ==================================== :Date: $Date: 2003/08/15 21:14:43 $ :Version: $Revision: 1.2 $ :Web site: http://www.python.org/ .. contents:: .. sectnum:: General GUI Questions ============================ What platform-independent GUI toolkits exist for Python? ---------------------------------------------------------------- Depending on what platform(s) you are aiming at, there are several. Tkinter '''''''''''' Standard builds of Python include an object-oriented interface to the Tcl/Tk widget set, called Tkinter. This is probably the easiest to install and use. For more info about Tk, including pointers to the source, see the Tcl/Tk home page at http://www.tcl.tk. Tcl/Tk is fully portable to the MacOS, Windows, and Unix platforms. wxWindows ''''''''''''' wxWindows is a portable GUI class library written in C++ that's a portable interface to various platform-specific libraries; wxPython is a Python interface to wxWindows. wxWindows supports Windows and MacOS; on Unix variants, it supports both GTk+ and Motif toolkits. wxWindows preserves the look and feel of the underlying graphics toolkit, and there is quite a rich widget set and collection of GDI classes. See `the wxWindows page `_ for more details. `wxPython `_ is an extension module that wraps many of the wxWindows C++ classes, and is quickly gaining popularity amongst Python developers. You can get wxPython as part of the source or CVS distribution of wxWindows, or directly from its home page. GTk+ ''''''''''' PyGTk bindings for the GTk+ Toolkit by James Henstridge are available; see ftp://ftp.daa.com.au/pub/james/python. Qt '''''' There are bindings available for the Qt toolkit (PyQt). and for KDE (PyKDE); see http://www.thekompany.com/projects/pykde. If you're writing open source software, you don't need to pay for PyQt, but if you want to write proprietary applications, you must buy a license from XXX. For OpenGL bindings, see `PyOpenGL `_. What platform-specific GUI toolkits exist for Python? ---------------------------------------------------------------- `The Mac port `_ by Jack Jansen has a rich and ever-growing set of modules that support the native Mac toolbox calls. The port includes support for MacOS9 and MacOS X's Carbon libraries. By installing the `PyObjc Objective-C bridge `_, Python programs can use MacOS X's Cocoa libraries. See the documentation that comes with the Mac port. `Pythonwin `_ by Mark Hammond includes an interface to the Microsoft Foundation Classes and a Python programming environment using it that's written mostly in Python. Tkinter ===================== How do I freeze Tkinter applications? --------------------------------------------- Freeze is a tool to create stand-alone applications. When freezing Tkinter applications, the applications will not be truly stand-alone, as the application will still need the Tcl and Tk libraries. One solution is to ship the application with the tcl and tk libraries, and point to them at run-time using the TCL_LIBRARY and TK_LIBRARY environment variables. To get truly stand-alone applications, the Tcl scripts that form the library have to be integrated into the application as well. One tool supporting that is SAM (stand-alone modules), which is part of the Tix distribution (http://tix.mne.com). Build Tix with SAM enabled, perform the appropriate call to Tclsam_init etc inside Python's Modules/tkappinit.c, and link with libtclsam and libtksam (you might include the Tix libraries as well). Can I have Tk events handled while waiting for I/O? ----------------------------------------------------------- Yes, and you don't even need threads! But you'll have to restructure your I/O code a bit. Tk has the equivalent of Xt's XtAddInput() call, which allows you to register a callback function which will be called from the Tk mainloop when I/O is possible on a file descriptor. Here's what you need:: from Tkinter import tkinter tkinter.createfilehandler(file, mask, callback) The file may be a Python file or socket object (actually, anything with a fileno() method), or an integer file descriptor. The mask is one of the constants tkinter.READABLE or tkinter.WRITABLE. The callback is called as follows:: callback(file, mask) You must unregister the callback when you're done, using :: tkinter.deletefilehandler(file) Note: since you don't know *how many bytes* are available for reading, you can't use the Python file object's read or readline methods, since these will insist on reading a predefined number of bytes. For sockets, the recv() or recvfrom() methods will work fine; for other files, use os.read(file.fileno(), maxbytecount). I can't get key bindings to work in Tkinter: why? --------------------------------------------------- An often-heard complaint is that event handlers bound to events with the bind() method don't get handled even when the appropriate key is pressed. The most common cause is that the widget to which the binding applies doesn't have "keyboard focus". Check out the Tk documentation for the focus command. Usually a widget is given the keyboard focus by clicking in it (but not for labels; see the takefocus option). From amk@nyman.amk.ca Sat Aug 16 20:53:43 2003 From: amk@nyman.amk.ca (amk@nyman.amk.ca) Date: Sat, 16 Aug 2003 15:53:43 -0400 Subject: Python on Windows FAQ Message-ID: This FAQ collects questions about using Python on Windows. Many of the more specific questions deal with one Windows bug or another; it's not clear how many of these bugs are still relevant for users of Windows XP or 2000. Please *don't* send me comments about the questions, because I can't tell which comments are correct and which aren't, so I'm not planning to make any changes to the file. A Windows-using maintainer is desperately needed. If you want to be the maintainer, just grab a copy of the reStructured Text source from http://www.python.org/doc/faq/windows.ht, edit away, and send your updated draft to the python.org webmaster address. --amk Title: Python Windows FAQ Content-type: text/x-rst ==================================== Python Windows FAQ ==================================== :Date: $Date: 2003/08/14 20:41:20 $ :Version: $Revision: 1.2 $ :Web site: http://www.python.org/ .. contents:: .. sectnum:: How do I run a Python program under Windows? ---------------------------------------------------- This is not necessarily a straightforward question. If you are already familiar with running programs from the Windows command line then everything will seem obvious; otherwise, you might need a little more guidance. There are also differences between Windows 95, 98, NT, ME, 2000 and XP which can add to the confusion. Unless you use some sort of integrated development environment, you will end up *typing* Windows commands into what is variously referred to as a "DOS window" or "Command prompt window". Usually you can create such a window from your Start menu; under Windows 2000 the menu selection is "Start | Programs | Accessories | Command Prompt". You should be able to recognize when you have started such a window because you will see a Windows "command prompt", which usually looks like this:: C:\> The letter may be different, and there might be other things after it, so you might just as easily see something like:: D:\Steve\Projects\Python> depending on how your computer has been set up and what else you have recently done with it. Once you have started such a window, you are well on the way to running Python programs. You need to realize that your Python scripts have to be processed by another program called the Python interpreter. The interpreter reads your script, compiles it into bytecodes, and then executes the bytecodes to run your program. So, how do you arrange for the interpreter to handle your Python? First, you need to make sure that your command window recognises the word "python" as an instruction to start the interpreter. If you have opened a command window, you should try entering the command ``python`` and hitting return. You should then see something like:: Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> You have started the interpreter in "interactive mode". That means you can enter Python statements or expressions interactively and have them executed or evaluated while you wait. This is one of Python's strongest features. Check it by entering a few expressions of your choice and seeing the results:: >>> print "Hello" Hello >>> "Hello" * 3 HelloHelloHello Many people use the interactive mode as a convenient yet highly programmable calculator. When you want to end your interactive Python session, hold the Ctrl key down while you enter a Z, then hit the "Enter" key to get back to your Windows command prompt. You may also find that you have a Start-menu entry such as "Start | Programs | Python 2.2 | Python (command line)" that results in you seeing the ">>>" prompt in a new window. If so, the window will disappear after you enter the Ctrl-Z character; Windows is running a single "python" command in the window, and closes it when you terminate the interpreter. If the ``python`` command, instead of displaying the interpreter prompt ">>>", gives you a message like:: 'python' is not recognized as an internal or external command, operable program or batch file. or:: Bad command or filename then you need to make sure that your computer knows where to find the Python interpreter. To do this you will have to modify a setting called PATH, which is a list of directories where Windows will look for programs. You should arrange for Python's installation directory to be added to the PATH of every command window as it starts. If you installed Python fairly recently then the command :: dir C:\py* will probably tell you where it is installed; the usual location is something like C:\Python23. Otherwise you will be reduced to a search of your whole disk ... use "Tools | Find" or hit the "Search" button and look for "python.exe". Supposing you discover that Python is installed in the C:\Python23 directory (the default at the time of writing), you should make sure that entering the command :: c:\Python23\python starts up the interpreter as above (and don't forget you'll need a "CTRL-Z" and an "Enter" to get out of it). Once you have verified the directory, you need to add it to the start-up routines your computer goes through. For older versions of Windows the easiest way to do this is to edit the C:\AUTOEXEC.BAT file. You would want to add a line like the following to AUTOEXEC.BAT:: PATH C:\Python23;%PATH% For Windows NT, 2000 and (I assume) XP, you will need to add a string such as :: ;C:\Python23 to the current setting for the PATH environment variable, which you will find in the properties window of "My Computer" under the "Advanced" tab. Note that if you have sufficient privilege you might get a choice of installing the settings either for the Current User or for System. The latter is preferred if you want everybody to be able to run Python on the machine. If you aren't confident doing any of these manipulations yourself, ask for help! At this stage you may want to reboot your system to make absolutely sure the new setting has taken effect. You probably won't need to reboot for Windows NT, XP or 2000. You can also avoid it in earlier versions by editing the file C:\WINDOWS\COMMAND\CMDINIT.BAT instead of AUTOEXEC.BAT. You should now be able to start a new command window, enter ``python`` at the "C:>" (or whatever) prompt, and see the ">>>" prompt that indicates the Python interpreter is reading interactive commands. Let's suppose you have a program called "pytest.py" in directory "C:\Steve\Projects\Python". A session to run that program might look like this:: C:\> cd \Steve\Projects\Python C:\Steve\Projects\Python> python pytest.py Because you added a file name to the command to start the interpreter, when it starts up it reads the Python script in the named file, compiles it, executes it, and terminates, so you see another "C:\>" prompt. You might also have entered :: C:\> python \Steve\Projects\Python\pytest.py if you hadn't wanted to change your current directory. Under NT, 2000 and XP you may well find that the installation process has also arranged that the command ``pytest.py`` (or, if the file isn't in the current directory, ``C:\Steve\Projects\Python\pytest.py``) will automatically recognize the ".py" extension and run the Python interpreter on the named file. Using this feature is fine, but *some* versions of Windows have bugs which mean that this form isn't exactly equivalent to using the interpreter explicitly, so be careful. The important things to remember are: 1. Start Python from the Start Menu, or make sure the PATH is set correctly so Windows can find the Python interpreter. :: python should give you a '>>>" prompt from the Python interpreter. Don't forget the CTRL-Z and ENTER to terminate the interpreter (and, if you started the window from the Start Menu, make the window disappear). 2. Once this works, you run programs with commands:: python {program-file} 3. When you know the commands to use you can build Windows shortcuts to run the Python interpreter on any of your scripts, naming particular working directories, and adding them to your menus. Take a look at :: python --help if your needs are complex. 4. Interactive mode (where you see the ">>>" prompt) is best used for checking that individual statements and expressions do what you think they will, and for developing code by experiment. How do I make python scripts executable? ---------------------------------------------- On Windows 2000, the standard Python installer already associates the .py extension with a file type (Python.File) and gives that file type an open command that runs the interpreter (D:\Program Files\Python\python.exe "%1" %*). This is enough to make scripts executable from the command prompt as 'foo.py'. If you'd rather be able to execute the script by simple typing 'foo' with no extension you need to add .py to the PATHEXT environment variable. On Windows NT, the steps taken by the installer as described above allow you to run a script with 'foo.py', but a longtime bug in the NT command processor prevents you from redirecting the input or output of any script executed in this way. This is often important. The incantation for making a Python script executable under WinNT is to give the file an extension of .cmd and add the following as the first line:: @setlocal enableextensions & python -x %~f0 %* & goto :EOF Where is Freeze for Windows? ------------------------------------ "Freeze" is a program that allows you to ship a Python program as a single stand-alone executable file. It is *not* a compiler; your programs don't run any faster, but they are more easily distributable, at least to platforms with the same OS and CPU. Read the README file of the freeze program for more disclaimers. You can use freeze on Windows, but you must download the source tree (see http://www.python.org/download/download_source.html). The freeze program is in the ``Tools\freeze`` subdirectory of the source tree. You need the Microsoft VC++ compiler, and you probably need to build Python. The required project files are in the PCbuild directory. Is a ``*.pyd`` file the same as a DLL? ------------------------------------------ Yes, .pyd files are dll's, but there are a few differences. If you have a DLL named foo.pyd, then it must have a function initfoo(). You can then write Python "import foo", and Python will search for foo.pyd (as well as foo.py, foo.pyc) and if it finds it, will attempt to call initfoo() to initialize it. You do not link your .exe with foo.lib, as that would cause Windows to require the DLL to be present. Note that the search path for foo.pyd is PYTHONPATH, not the same as the path that Windows uses to search for foo.dll. Also, foo.pyd need not be present to run your program, whereas if you linked your program with a dll, the dll is required. Of course, foo.pyd is required if you want to say "import foo". In a DLL, linkage is declared in the source code with __declspec(dllexport). In a .pyd, linkage is defined in a list of available functions. How can I embed Python into a Windows application? ---------------------------------------------------------- Embedding the Python interpreter in a Windows app can be summarized as follows: 1. Do _not_ build Python into your .exe file directly. On Windows, Python must be a DLL to handle importing modules that are themselves DLL's. (This is the first key undocumented fact.) Instead, link to pythonNN.dll; it is typically installed in c:\Windows\System. NN is the Python version, a number such as "23" for Python 2.3. You can link to Python statically or dynamically. Linking statically means linking against pythonNN.lib, while dynamically linking means linking against pythonNN.dll. The drawback to dynamic linking is that your app won't run if pythonNN.dll does not exist on your system. (General note: pythonNN.lib is the so-called "import lib" corresponding to python.dll. It merely defines symbols for the linker.) Linking dynamically greatly simplifies link options; everything happens at run time. Your code must load pythonNN.dll using the Windows LoadLibraryEx() routine. The code must also use access routines and data in pythonNN.dll (that is, Python's C API's) using pointers obtained by the Windows GetProcAddress() routine. Macros can make using these pointers transparent to any C code that calls routines in Python's C API. Borland note: convert pythonNN.lib to OMF format using Coff2Omf.exe first. 2. If you use SWIG, it is easy to create a Python "extension module" that will make the app's data and methods available to Python. SWIG will handle just about all the grungy details for you. The result is C code that you link *into* your .exe file (!) You do _not_ have to create a DLL file, and this also simplifies linking. 3. SWIG will create an init function (a C function) whose name depends on the name of the extension module. For example, if the name of the module is leo, the init function will be called initleo(). If you use SWIG shadow classes, as you should, the init function will be called initleoc(). This initializes a mostly hidden helper class used by the shadow class. The reason you can link the C code in step 2 into your .exe file is that calling the initialization function is equivalent to importing the module into Python! (This is the second key undocumented fact.) 4. In short, you can use the following code to initialize the Python interpreter with your extension module. :: #include "python.h" ... Py_Initialize(); // Initialize Python. initmyAppc(); // Initialize (import) the helper class. PyRun_SimpleString("import myApp") ; // Import the shadow class. 5. There are two problems with Python's C API which will become apparent if you use a compiler other than MSVC, the compiler used to build pythonNN.dll. Problem 1: The so-called "Very High Level" functions that take FILE * arguments will not work in a multi-compiler environment because each compiler's notion of a struct FILE will be different. From an implementation standpoint these are very _low_ level functions. Problem 2: SWIG generates the following code when generating wrappers to void functions:: Py_INCREF(Py_None); _resultobj = Py_None; return _resultobj; Alas, Py_None is a macro that expands to a reference to a complex data structure called _Py_NoneStruct inside pythonNN.dll. Again, this code will fail in a mult-compiler environment. Replace such code by:: return Py_BuildValue(""); It may be possible to use SWIG's %typemap command to make the change automatically, though I have not been able to get this to work (I'm a complete SWIG newbie). 6. Using a Python shell script to put up a Python interpreter window from inside your Windows app is not a good idea; the resulting window will be independent of your app's windowing system. Rather, you (or the wxPythonWindow class) should create a "native" interpreter window. It is easy to connect that window to the Python interpreter. You can redirect Python's i/o to _any_ object that supports read and write, so all you need is a Python object (defined in your extension module) that contains read() and write() methods. How do I use Python for CGI? ------------------------------------------------------- On the Microsoft IIS server or on the Win95 MS Personal Web Server you set up Python in the same way that you would set up any other scripting engine. Run regedt32 and go to:: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W3SVC\Parameters\ScriptMap and enter the following line (making any specific changes that your system may need):: .py :REG_SZ: c:\\python.exe -u %s %s This line will allow you to call your script with a simple reference like: http://yourserver/scripts/yourscript.py provided "scripts" is an "executable" directory for your server (which it usually is by default). The "-u" flag specifies unbuffered and binary mode for stdin - needed when working with binary data. In addition, it is recommended that using ".py" may not be a good idea for the file extensions when used in this context (you might want to reserve ``*.py`` for support modules and use ``*.cgi`` or ``*.cgp`` for "main program" scripts). In order to set up Internet Information Services 5 to use Python for CGI processing, please see the following links: http://www.e-coli.net/pyiis_server.html (for Win2k Server) http://www.e-coli.net/pyiis.html (for Win2k pro) Configuring Apache is much simpler. In the Apache configuration file ``httpd.conf``, add the following line at the end of the file:: ScriptInterpreterSource Registry Then, give your Python CGI-scripts the extension .py and put them in the cgi-bin directory. How do I keep editors from inserting tabs into my Python source? ------------------------------------------------------------------ The FAQ does not recommend using tabs, and `the Python style guide `_ recommends 4 spaces for distributed Python code; this is also the Emacs python-mode default. Under any editor, mixing tabs and spaces is a bad idea. MSVC is no different in this respect, and is easily configured to use spaces: Take Tools -> Options -> Tabs, and for file type "Default" set "Tab size" and "Indent size" to 4, and select the "Insert spaces" radio button. If you suspect mixed tabs and spaces are causing problems in leading whitespace, run Python with the -t switch or run ``Tools/Scripts/tabnanny.py`` to check a directory tree in batch mode. How do I check for a keypress without blocking? ---------------------------------------------------- Use the msvcrt module. This is a standard Windows-specific extension module. It defines a function kbhit() which checks whether a keyboard hit is present, and getch() which gets one character without echoing it. How do I emulate os.kill() in Windows? --------------------------------------------- Use win32api:: def kill(pid): """kill function for Win32""" import win32api handle = win32api.OpenProcess(1, 0, pid) return (0 != win32api.TerminateProcess(handle, 0)) Why does os.path.isdir() fail on NT shared directories? -------------------------------------------------------------- The solution appears to be always append the "\\" on the end of shared drives. :: >>> import os >>> os.path.isdir( '\\\\rorschach\\public') 0 >>> os.path.isdir( '\\\\rorschach\\public\\') 1 It helps to think of share points as being like drive letters. Example:: k: is not a directory k:\ is a directory k:\media is a directory k:\media\ is not a directory The same rules apply if you substitute "k:" with "\\conky\foo":: \\conky\foo is not a directory \\conky\foo\ is a directory \\conky\foo\media is a directory \\conky\foo\media\ is not a directory cgi.py (or other CGI programming) doesn't work sometimes on NT or win95! ----------------------------------------------------------------------------- Be sure you have the latest python.exe, that you are using python.exe rather than a GUI version of Python and that you have configured the server to execute :: "...\python.exe -u ..." for the CGI execution. The -u (unbuffered) option on NT and Win95 prevents the interpreter from altering newlines in the standard input and output. Without it post/multipart requests will seem to have the wrong length and binary (e.g. GIF) responses may get garbled (resulting in broken images, PDF files, and other binary downloads failing). Why doesn't os.popen() work in PythonWin on NT? ------------------------------------------------------- The reason that os.popen() doesn't work from within PythonWin is due to a bug in Microsoft's C Runtime Library (CRT). The CRT assumes you have a Win32 console attached to the process. You should use the win32pipe module's popen() instead which doesn't depend on having an attached Win32 console. Example:: import win32pipe f = win32pipe.popen('dir /c c:\\') print f.readlines() f.close() Why doesn't os.popen()/win32pipe.popen() work on Win9x? --------------------------------------------------------------- There is a bug in Win9x that prevents os.popen/win32pipe.popen* from working. The good news is there is a way to work around this problem. The Microsoft Knowledge Base article that you need to lookup is: Q150956. You will find links to the knowledge base at: http://www.microsoft.com/kb. PyRun_SimpleFile() crashes on Windows but not on Unix; why? ------------------------------------------------------------ This is very sensitive to the compiler vendor, version and (perhaps) even options. If the FILE* structure in your embedding program isn't the same as is assumed by the Python interpreter it won't work. The Python 1.5.* DLLs (python15.dll) are all compiled with MS VC++ 5.0 and with multithreading-DLL options (``/MD``). If you can't change compilers or flags, try using Py_RunSimpleString(). A trick to get it to run an arbitrary file is to construct a call to execfile() with the name of your file as argument. Also note that you can not mix-and-match Debug and Release versions. If you wish to use the Debug Multithreaded DLL, then your module _must_ have an "_d" appended to the base name. Importing _tkinter fails on Windows 95/98: why? ------------------------------------------------ Sometimes, the import of _tkinter fails on Windows 95 or 98, complaining with a message like the following:: ImportError: DLL load failed: One of the library files needed to run this application cannot be found. It could be that you haven't installed Tcl/Tk, but if you did install Tcl/Tk, and the Wish application works correctly, the problem may be that its installer didn't manage to edit the autoexec.bat file correctly. It tries to add a statement that changes the PATH environment variable to include the Tcl/Tk 'bin' subdirectory, but sometimes this edit doesn't quite work. Opening it with notepad usually reveals what the problem is. (One additional hint, noted by David Szafranski: you can't use long filenames here; e.g. use C:\PROGRA~1\Tcl\bin instead of C:\Program Files\Tcl\bin.) How do I extract the downloaded documentation on Windows? ------------------------------------------------------------ Sometimes, when you download the documentation package to a Windows machine using a web browser, the file extension of the saved file ends up being .EXE. This is a mistake; the extension should be .TGZ. Simply rename the downloaded file to have the .TGZ extension, and WinZip will be able to handle it. (If your copy of WinZip doesn't, get a newer one from http://www.winzip.com.) Missing cw3215mt.dll (or missing cw3215.dll) ---------------------------------------------------- Sometimes, when using Tkinter on Windows, you get an error that cw3215mt.dll or cw3215.dll is missing. Cause: you have an old Tcl/Tk DLL built with cygwin in your path (probably C:\Windows). You must use the Tcl/Tk DLLs from the standard Tcl/Tk installation (Python 1.5.2 comes with one). Warning about CTL3D32 version from installer ---------------------------------------------------- The Python installer issues a warning like this:: This version uses CTL3D32.DLL whitch is not the correct version. This version is used for windows NT applications only. [Tim Peters] This is a Microsoft DLL, and a notorious source of problems. The message means what it says: you have the wrong version of this DLL for your operating system. The Python installation did not cause this -- something else you installed previous to this overwrote the DLL that came with your OS (probably older shareware of some sort, but there's no way to tell now). If you search for "CTL3D32" using any search engine (AltaVista, for example), you'll find hundreds and hundreds of web pages complaining about the same problem with all sorts of installation programs. They'll point you to ways to get the correct version reinstalled on your system (since Python doesn't cause this, we can't fix it). David A Burton has written a little program to fix this. Go to http://www.burtonsys.com/download.html and click on "ctl3dfix.zip" From phil@riverbankcomputing.co.uk Sun Aug 17 20:05:02 2003 From: phil@riverbankcomputing.co.uk (Phil Thompson) Date: Sun, 17 Aug 2003 20:05:02 +0100 Subject: ANN: PyQt v3.8 Released Message-ID: PyQt v3.8 has been released and can be downloaded from http://www.riverbankcomputing.co.uk/pyqt/ Highlights of this release include the addition of many operators to existing classes and full support for Qt v3.2.0. PyQt is a comprehensive set of Python bindings for Trolltech's Qt GUI toolkit. It includes approximately 300 classes and 5,750 methods including OpenGL, SQL and XML support as well as a rich set of GUI widgets. It also includes a utility to generate Python code from Qt Designer, Qt's GUI builder. PyQt runs on UNIX/Linux, Windows and the Sharp Zaurus. PyQt is licensed under the GPL, commercial, educational and non-commercial licenses. Phil From richardjones@optushome.com.au Mon Aug 18 01:40:25 2003 From: richardjones@optushome.com.au (Richard Jones) Date: Mon, 18 Aug 2003 10:40:25 +1000 Subject: SC-Track Roundup 0.6.0 - an issue tracking system Message-ID: ================================================= SC-Track Roundup 0.6.0 - an issue tracking system ================================================= I'm pleased to announce the latest feature-packed release of Roundup. See below for a list of some of the goodies included in this release. If you're upgrading from an older version of Roundup you *must* follow the "Software Upgrade" guidelines given in the maintenance documentation. Unfortunately, the Zope frontend for Roundup is currently broken. I hope to revive it in a future 0.6 bugfix release. The gadfly backend has now been removed, having served its purpose as a template for other RDBMS implementations. It is replaced by the sqlite and mysql backends. Roundup requires python 2.1.3 or later for correct operation. The 0.6 release has lots of new goodies including: - new instant-gratification Demo Mode ("python demo.py" :) - added mysql backend (see doc/mysql.txt for details) - web interface cleanups including nicer history display, nicer index navigation and nicer popup list windows - searching of date ranges - better international support, including utf-8 email handling and ability to display localized dates in web interface. - more documentation including revamped design document, unix manual pages and some FAQ entries - significantly more powerful form handling allowing editing of multiple items and creation of multiple items - tracker templates can contain subdirectories and static files (e.g. images) and we may now distribute templates separately from Roundup. Template HTML files now have a .html extension too. - user registration is now a two-step process, with confirmation from the email address supplied in the registration form, and we also have a password reset feature for forgotten password / login - Windows Service mode for roundup-server when daemonification is attempted on Windows - lots of speed enhancements, making the web interface much more responsive - fixed issues with dumb email or web clients - email system handles more SMTP and POP features (TLS, APOP, ...) - lots more little tweaks and back-end work... Source and documentation is available at the website: http://roundup.sourceforge.net/ Release Info (via download page): http://sourceforge.net/projects/roundup Mailing lists - the place to ask questions: http://sourceforge.net/mail/?group_id=31577 About Roundup ============= Roundup is a simple-to-use and -install issue-tracking system with command-line, web and e-mail interfaces. It is based on the winning design from Ka-Ping Yee in the Software Carpentry "Track" design competition. Note: Ping is not responsible for this project. The contact for this project is richard@users.sourceforge.net. Roundup manages a number of issues (with flexible properties such as "description", "priority", and so on) and provides the ability to: (a) submit new issues, (b) find and edit existing issues, and (c) discuss issues with other participants. The system will facilitate communication among the participants by managing discussions and notifying interested parties when issues are edited. One of the major design goals for Roundup that it be simple to get going. Roundup is therefore usable "out of the box" with any python 2.1+ installation. It doesn't even need to be "installed" to be operational, though a disutils-based install script is provided. It comes with two issue tracker templates (a classic bug/feature tracker and a minimal skeleton) and six database back-ends (anydbm, bsddb, bsddb3, sqlite, metakit and mysql). From richardjones@optushome.com.au Mon Aug 18 05:24:45 2003 From: richardjones@optushome.com.au (Richard Jones) Date: Mon, 18 Aug 2003 14:24:45 +1000 Subject: SC-Track Roundup 0.6.0 - an issue tracking system In-Reply-To: References: Message-ID: On Mon, 18 Aug 2003 10:40 am, Richard Jones wrote: > Roundup requires python 2.1.3 or later for correct operation. Note that due to an incompatibility between the APIs of the Object-Craft CSV module and the one shipped with Python 2.3, Roundup is NOT to be considered compatible with Python 2.3! Richard ps. most of Roundup will work - just the few parts that use csv won't :( From amk@nyman.amk.ca Sat Aug 16 20:46:33 2003 From: amk@nyman.amk.ca (amk@nyman.amk.ca) Date: Sat, 16 Aug 2003 15:46:33 -0400 Subject: Python Programming FAQ Message-ID: Here's another one of the new FAQ documents, about basic Python programming and data types. --amk ==================================== Programming FAQ ==================================== :Date: $Date: 2003/08/14 20:49:08 $ :Version: $Revision: 1.8 $ :Web site: http://www.python.org/ .. contents:: .. sectnum:: General Questions =========================== Is there a source code level debugger with breakpoints, single-stepping, etc.? ------------------------------------------------------------------------------- Yes. The pdb module is a simple but adequate console-mode debugger for Python. It is part of the standard Python library, and is `documented in the Library Reference Manual `_. You can also write your own debugger by using the code for pdb as an example. The IDLE interactive development environment, which is part of the standard Python distribution (normally available as Tools/scripts/idle), includes a graphical debugger. There is documentation for the IDLE debugger at http://www.python.org/idle/doc/idle2.html#Debugger PythonWin is a Python IDE that includes a GUI debugger based on pdb. The Pythonwin debugger colors breakpoints and has quite a few cool features such as debugging non-Pythonwin programs. A reference can be found at http://www.python.org/ftp/python/pythonwin/pwindex.html More recent versions of PythonWin are available as a part of the ActivePython distribution (see http://www.activestate.com/Products/ActivePython/index.html). Pydb is a version of the standard Python debugger pdb, modified for use with DDD (Data Display Debugger), a popular graphical debugger front end. Pydb can be found at http://packages.debian.org/unstable/devel/pydb.html> and DDD can be found at http://www.gnu.org/software/ddd. There are a number of commmercial Python IDEs that include graphical debuggers. They include: * Wing IDE (http://wingide.com) * Komodo IDE (http://www.activestate.com/Products/Komodo) Is there a tool to help find bugs or perform static analysis? ---------------------------------------------------------------------- Yes. PyChecker is a static analysis tool that finds bugs in Python source code and warns about code complexity and style. You can get PyChecker from http://pychecker.sf.net. How can I create a stand-alone binary from a Python script? ------------------------------------------------------------------- You don't need the ability to compile Python to C code, if all you want is a stand-alone program that users can download and run without having to install the Python distribution first. There are a number of tools that determine the set of modules required by a program and bind these modules together with a Python binary to produce a single executable. One is to use the freeze tool, which is included in the Python source tree as ``Tools/freeze``. It converts Python byte code to C arrays; a C compiler you can embed all your modules into a new program, which is then linked with the standard Python modules. It works by scanning your source recursively for import statements (in both forms) and looking for the modules in the standard Python path as well as in the source directory (for built-in modules). It then turns the bytecode for modules written in Python into C code (array initializers that can be turned into code objects using the marshal module) and creates a custom-made config file that only contains those built-in modules which are actually used in the program. It then compiles the generated C code and links it with the rest of the Python interpreter to form a self-contained binary which acts exactly like your script. Obviously, freeze requires a C compiler. There are several other utilities which don't. The first is Gordon McMillan's installer at http://www.mcmillan-inc.com/install1.html which works on Windows, Linux and at least some forms of Unix. Another is Thomas Heller's py2exe (Windows only) at http://starship.python.net/crew/theller/py2exe A third is Christian Tismer's `SQFREEZE `_ which appends the byte code to a specially-prepared Python interpreter that can find the byte code in the executable. A fourth is Fredrik Lundh's `Squeeze `_. Are there coding standards or a style guide for Python programs? ------------------------------------------------------------------------ Yes. The coding style required for standard library modules is documented as `PEP 8 `_. My program is too slow. How do I speed it up? ---------------------------------------------------- That's a tough one, in general. There are many tricks to speed up Python code; consider rewriting parts in C as a last resort. One thing to notice is that function and (especially) method calls are rather expensive; if you have designed a purely OO interface with lots of tiny functions that don't do much more than get or set an instance variable or call another method, you might consider using a more direct way such as directly accessing instance variables. Also see the standard module "profile" (`described in the Library Reference manual `_) which makes it possible to find out where your program is spending most of its time (if you have some patience -- the profiling itself can slow your program down by an order of magnitude). Remember that many standard optimization heuristics you may know from other programming experience may well apply to Python. For example it may be faster to send output to output devices using larger writes rather than smaller ones in order to reduce the overhead of kernel system calls. Thus CGI scripts that write all output in "one shot" may be faster than those that write lots of small pieces of output. Also, be sure to use Python's core features where appropriate. For example, slicing allows programs to chop up lists and other sequence objects in a single tick of the interpreter's mainloop using highly optimized C implementations. Thus to get the same effect as:: L2 = [] for i in range[3]: L2.append(L1[i]) it is much shorter and far faster to use :: L2 = list(L1[:3]) # "list" is redundant if L1 is a list. Note that the functionally-oriented builtins such as ``map()``, ``zip()``, and friends can be a convenient accelerator for loops that perform a single task. For example to pair the elements of two lists together:: >>> zip([1,2,3], [4,5,6]) [(1, 4), (2, 5), (3, 6)] or to compute a number of sines:: >>> map( math.sin, (1,2,3,4)) [0.841470984808, 0.909297426826, 0.14112000806, -0.756802495308] The operation completes very quickly in such cases. Other examples include the ``join()`` and ``split()`` methods of string objects. For example if s1..s7 are large (10K+) strings then ``"".join([s1,s2,s3,s4,s5,s6,s7])` may be far faster than the more obvious ``s1+s2+s3+s4+s5+s6+s7``, since the "summation" will compute many subexpressions, whereas ``join()`` does all the copying in one pass. For manipulating strings, use the ``replace()`` method on string objects. Use regular expressions only when you're not dealing with constant string patterns. Consider using the string formatting operations ``string % tuple`` and ``string % dictionary``. Be sure to use the ``list.sort()`` builtin method to do sorting, and see the `sorting mini-HOWTO `_ for examples of moderately advanced usage. ``list.sort()`` beats other techniques for sorting in all but the most extreme circumstances. Another common trick is to "push loops into functions or methods." For example suppose you have a program that runs slowly and you use the profiler to determine that a Python function ``ff()`` is being called lots of times. If you notice that ``ff ()``:: def ff(x): ...do something with x computing result... return result tends to be called in loops like:: list = map(ff, oldlist) or:: for x in sequence: value = ff(x) ...do something with value... then you can often eliminate function call overhead by rewriting ``ff()`` to:: def ffseq(seq): resultseq = [] for x in seq: ...do something with x computing result... resultseq.append(result) return resultseq and rewrite the two examples to ``list = ffseq(oldlist)`` and to:: for value in ffseq(sequence): ...do something with value... Single calls to ff(x) translate to ffseq([x])[0] with little penalty. Of course this technique is not always appropriate and there are other variants which you can figure out. You can gain some performance by explicitly storing the results of a function or method lookup into a local variable. A loop like:: for key in token: dict[key] = dict.get(key, 0) + 1 resolves dict.get every iteration. If the method isn't going to change, a slightly faster implementation is:: dict_get = dict.get # look up the method once for key in token: dict[key] = dict_get(key, 0) + 1 Default arguments can be used to determine values once, at compile time instead of at run time. This can only be done for functions or objects which will not be changed during program execution, such as replacing :: def degree_sin(deg): return math.sin(deg * math.pi / 180.0) with :: def degree_sin(deg, factor = math.pi/180.0, sin = math.sin): return sin(deg * factor) Because this trick uses default arguments for terms which should not be changed, it should only be used when you are not concerned with presenting a possibly confusing API to your users. Don't bother applying these optimization tricks until you know you need them, after profiling has indicated that a particular function is the heavily executed hot spot in the code. Optimizations almost always make the code less clear, and you shouldn't pay the costs of reduced clarity (increased development time, greater likelihood of bugs) unless the resulting performance benefit is worth it. For an anecdote related to optimization, see http://www.python.org/doc/essays/list2str.html. Core Language ================== How do you set a global variable in a function? ---------------------------------------------------------- Did you do something like this? :: x = 1 # make a global def f(): print x # try to print the global ... for j in range(100): if q>3: x=4 Any variable assigned in a function is local to that function. unless it is specifically declared global. Since a value is bound to ``x`` as the last statement of the function body, the compiler assumes that ``x`` is local. Consequently the ``print x`` attempts to print an uninitialized local variable and will trigger a ``NameError``. The solution is to insert an explicit global declaration at the start of the function:: def f(): global x print x # try to print the global ... for j in range(100): if q>3: x=4 In this case, all references to ``x`` are interpreted as references to the ``x`` from the module namespace. What are the rules for local and global variables in Python? -------------------------------------------------------------------------- In Python, variables that are only referenced inside a function are implicitly global. If a variable is assigned a new value anywhere within the function's body, it's assumed to be a local. If a variable is ever assigned a new value inside the function, the variable is implicitly local, and you need to explicitly declare it as 'global'. Though a bit surprising at first, a moment's consideration explains this. On one hand, requiring ``global`` for assigned variables provides a bar against unintended side-effects. On the other hand, if ``global`` was required for all global references, you'd be using ``global`` all the time. You'd have to declare as global every reference to a builtin function or to a component of an imported module. This clutter would defeat the usefulness of the ``global`` declaration for identifying side-effects. How do I share global variables across modules? ------------------------------------------------ The canonical way to share information across modules within a single program is to create a special module (often called config or cfg). Just import the config module in all modules of your application; the module then becomes available as a global name. Because there is only one instance of each module, any changes made to the module object get reflected everywhere. For example: config.py:: x = 0 # Default value of the 'x' configuration setting mod.py:: import config config.x = 1 main.py:: import config import mod print config.x Note that using a module is also the basis for implementing the Singleton design pattern, for the same reason. What are the "best practices" for using import in a module? ------------------------------------------------------------------------------ In general, don't use ``from modulename import *``. Doing so clutters the importer's namespace. Some people avoid this idiom even with the few modules that were designed to be imported in this manner. Modules designed in this manner include ``Tkinter``, ``threading``, and ``wxPython``. Import modules at the top of a file. Doing so makes it clear what other modules your code requires and avoids questions of whether the module name is in scope. Using one import per line makes it easy to add and delete module imports, but using multiple imports per line uses less screen space. It's good practice if you import modules in the following order: 1. standard libary modules -- e.g. ``sys``, ``os``, ``getopt``, ``re``) 2. third-party library modules (anything installed in Python's site-packages directory) -- e.g. mx.DateTime, ZODB, PIL.Image, etc. 3. locally-developed modules Never use relative package imports. If you're writing code that's in the ``package.sub.m1`` module and want to import ``package.sub.m2``, do not just write ``import m2``, even though it's legal. Write ``from package.sub import m2`` instead. Relative imports can lead to a module being initialized twice, leading to confusing bugs. It is sometimes necessary to move imports to a function or class to avoid problems with circular imports. Gordon McMillan says: Circular imports are fine where both modules use the "import " form of import. They fail when the 2nd module wants to grab a name out of the first ("from module import name") and the import is at the top level. That's because names in the 1st are not yet available, because the first module is busy importing the 2nd. In this case, if the second module is only used in one function, then the import can easily be moved into that function. By the time the import is called, the first module will have finished initializing, and the second module can do its import. It may also be necessary to move imports out of the top level of code if some of the modules are platform-specific. In that case, it may not even be possible to import all of the modules at the top of the file. In this case, importing the correct modules in the corresponding platform-specific code is a good option. Only move imports into a local scope, such as inside a function definition, if it's necessary to solve a problem such as avoiding a circular import or are trying to reduce the initialization time of a module. This technique is especially helpful if many of the imports are unnecessary depending on how the program executes. You may also want to move imports into a function if the modules are only ever used in that function. Note that loading a module the first time may be expensive because of the one time initialization of the module, but loading a module multiple times is virtually free, costing only a couple of dictionary lookups. Even if the module name has gone out of scope, the module is probably available in sys.modules. If only instances of a specific class use a module, then it is reasonable to import the module in the class's ``__init__`` method and then assign the module to an instance variable so that the module is always available (via that instance variable) during the life of the object. Note that to delay an import until the class is instantiated, the import must be inside a method. Putting the import inside the class but outside of any method still causes the import to occur when the module is initialized. How can I pass optional or keyword parameters from one function to another? ------------------------------------------------------------------------------- Collect the arguments using the ``*`` and ``**`` specifiers in the function's parameter list; this gives you the positional arguments as a tuple and the keyword arguments as a dictionary. You can then pass these arguments when calling another function by using ``*`` and ``**``:: def f(x, *tup, **kwargs): ... kwargs['width']='14.3c' ... g(x, *tup, **kwargs) In the unlikely case that you care about Python versions older than 2.0, use 'apply':: def f(x, *tup, **kwargs): ... kwargs['width']='14.3c' ... apply(g, (x,)+tup, kwargs) How do I write a function with output parameters (call by reference)? ----------------------------------------------------------------------------- Remember that arguments are passed by assignment in Python. Since assignment just creates references to objects, there's no alias between an argument name in the caller and callee, and so no call-by-reference per se. You can achieve the desired effect in a number of ways. 1) By returning a tuple of the results:: def func2(a, b): a = 'new-value' # a and b are local names b = b + 1 # assigned to new objects return a, b # return new values x, y = 'old-value', 99 x, y = func2(x, y) print x, y # output: new-value 100 This is almost always the clearest solution. 2) By using global variables. This isn't thread-safe, and is not recommended. 3) By passing a mutable (changeable in-place) object:: def func1(a): a[0] = 'new-value' # 'a' references a mutable list a[1] = a[1] + 1 # changes a shared object args = ['old-value', 99] func1(args) print args[0], args[1] # output: new-value 100 4) By passing in a dictionary that gets mutated:: def func3(args): args['a'] = 'new-value' # args is a mutable dictionary args['b'] = args['b'] + 1 # change it in-place args = {'a':' old-value', 'b': 99} func3(args) print args['a'], args['b'] 5) Or bundle up values in a class instance:: class callByRef: def __init__(self, **args): for (key, value) in args.items(): setattr(self, key, value) def func4(args): args.a = 'new-value' # args is a mutable callByRef args.b = args.b + 1 # change object in-place args = callByRef(a='old-value', b=99) func4(args) print args.a, args.b There's almost never a good reason to get this complicated. Your best choice is to return a tuple containing the multiple results. How do you make a higher order function in Python? ---------------------------------------------------------- You have two choices: you can use nested scopes or you can use callable objects. For example, suppose you wanted to define ``linear(a,b)`` which returns a function ``f(x)`` that computes the value ``a*x+b``. Using nested scopes:: def linear(a,b): def result(x): return a*x + b return result Or using a callable object:: class linear: def __init__(self, a, b): self.a, self.b = a,b def __call__(self, x): return self.a * x + self.b In both cases:: taxes = linear(0.3,2) gives a callable object where taxes(10e6) == 0.3 * 10e6 + 2. The callable object approach has the disadvantage that it is a bit slower and results in slightly longer code. However, note that a collection of callables can share their signature via inheritance:: class exponential(linear): # __init__ inherited def __call__(self, x): return self.a * (x ** self.b) Object can encapsulate state for several methods:: class counter: value = 0 def set(self, x): self.value = x def up(self): self.value=self.value+1 def down(self): self.value=self.value-1 count = counter() inc, dec, reset = count.up, count.down, count.set Here ``inc()``, ``dec()`` and ``reset()`` act like functions which share the same counting variable. How do I copy an object in Python? ------------------------------------------ In general, try copy.copy() or copy.deepcopy() for the general case. Not all objects can be copied, but most can. Some objects can be copied more easily. Dictionaries have a ``copy()`` method:: newdict = olddict.copy() Sequences can be copied by slicing:: new_l = l[:] How can I find the methods or attributes of an object? -------------------------------------------------------------- For an instance x of a user-defined class, ``dir(x)`` returns an alphabetized list of the names containing the instance attributes and methods and attributes defined by its class. How can my code discover the name of an object? ------------------------------------------------------- Generally speaking, it can't, because objects don't really have names. Essentially, assignment always binds a name to a value; The same is true of ``def`` and ``class`` statements, but in that case the value is a callable. Consider the following code:: class A: pass B = A a = B() b = a print b <__main__.A instance at 016D07CC> print a <__main__.A instance at 016D07CC> Arguably the class has a name: even though it is bound to two names and invoked through the name B the created instance is still reported as an instance of class A. However, it is impossible to say whether the instance's name is a or b, since both names are bound to the same value. Generally speaking it should not be necessary for your code to "know the names" of particular values. Unless you are deliberately writing introspective programs, this is usually an indication that a change of approach might be beneficial. In comp.lang.python, Fredrik Lundh once gave an excellent analogy in answer to this question: The same way as you get the name of that cat you found on your porch: the cat (object) itself cannot tell you its name, and it doesn't really care -- so the only way to find out what it's called is to ask all your neighbours (namespaces) if it's their cat (object)... ....and don't be surprised if you'll find that it's known by many names, or no name at all! Is there an equivalent of C's "?:" ternary operator? ---------------------------------------------------------------------- No. In many cases you can mimic a?b:c with "a and b or c", but there's a flaw: if b is zero (or empty, or None -- anything that tests false) then c will be selected instead. In many cases you can prove by looking at the code that this can't happen (e.g. because b is a constant or has a type that can never be false), but in general this can be a problem. Tim Peters (who wishes it was Steve Majewski) suggested the following solution: (a and [b] or [c])[0]. Because [b] is a singleton list it is never false, so the wrong path is never taken; then applying [0] to the whole thing gets the b or c that you really wanted. Ugly, but it gets you there in the rare cases where it is really inconvenient to rewrite your code using 'if'. The best course is usually to write a simple ``if...else`` statement. Another solution is to implement the "?:" operator as a function:: def q(cond,on_true,on_false): if cond: if not isfunction(on_true): return on_true else: return apply(on_true) else: if not isfunction(on_false): return on_false else: return apply(on_false) In most cases you'll pass b and c directly: ``q(a,b,c)``. To avoid evaluating b or c when they shouldn't be, encapsulate them within a lambda function, e.g.: ``q(a,lambda: b, lambda: c)``. It has been asked *why* Python has no if-then-else expression. There are several answers: many languages do just fine without one; it can easily lead to less readable code; no sufficiently "Pythonic" syntax has been discovered; a search of the standard library found remarkably few places where using an if-then-else expression would make the code more understandable. In 2002, `PEP 308 `_ was written proposing several possible syntaxes and the community was asked to vote on the issue. The vote was inconclusive. Most people liked one of the syntaxes, but also hated other syntaxes; many votes implied that people preferred no ternary operator rather than having a syntax they hated. Is it possible to write obfuscated one-liners in Python? ---------------------------------------------------------------- Yes. Usually this is done by nesting `lambda` within `lambda`. See the following three examples, due to Ulf Bartelt:: # Primes < 1000 print filter(None,map(lambda y:y*reduce(lambda x,y:x*y!=0, map(lambda x,y=y:y%x,range(2,int(pow(y,0.5)+1))),1),range(2,1000))) # First 10 Fibonacci numbers print map(lambda x,f=lambda x,f:(x<=1) or (f(x-1,f)+f(x-2,f)): f(x,f), range(10)) # Mandelbrot set print (lambda Ru,Ro,Iu,Io,IM,Sx,Sy:reduce(lambda x,y:x+y,map(lambda y, Iu=Iu,Io=Io,Ru=Ru,Ro=Ro,Sy=Sy,L=lambda yc,Iu=Iu,Io=Io,Ru=Ru,Ro=Ro,i=IM, Sx=Sx,Sy=Sy:reduce(lambda x,y:x+y,map(lambda x,xc=Ru,yc=yc,Ru=Ru,Ro=Ro, i=i,Sx=Sx,F=lambda xc,yc,x,y,k,f=lambda xc,yc,x,y,k,f:(k<=0)or (x*x+y*y >=4.0) or 1+f(xc,yc,x*x-y*y+xc,2.0*x*y+yc,k-1,f):f(xc,yc,x,y,k,f):chr( 64+F(Ru+x*(Ro-Ru)/Sx,yc,0,0,i)),range(Sx))):L(Iu+y*(Io-Iu)/Sy),range(Sy ))))(-2.1, 0.7, -1.2, 1.2, 30, 80, 24) # \___ ___ \___ ___ | | |__ lines on screen # V V | |______ columns on screen # | | |__________ maximum of "iterations" # | |_________________ range on y axis # |____________________________ range on x axis Don't try this at home, kids! Numbers and strings ========================== How do I specify hexadecimal and octal integers? -------------------------------------------------------- To specify an octal digit, precede the octal value with a zero. For example, to set the variable "a" to the octal value "10" (8 in decimal), type:: >>> a = 010 >>> a 8 Hexadecimal is just as easy. Simply precede the hexadecimal number with a zero, and then a lower or uppercase "x". Hexadecimal digits can be specified in lower or uppercase. For example, in the Python interpreter:: >>> a = 0xa5 >>> a 165 >>> b = 0XB2 >>> b 178 How do I convert a string to a number? ---------------------------------------------- For integers, use the built-in ``int()`` type constructor, e.g. int('144') == 144. Similarly, ``float()`` converts to floating-point, e.g. ``float('144') == 144.0``. By default, these interpret the number as decimal, so that ``int('0144') == 144`` and ``int('0x144')`` raises ``ValueError``. ``int(string, base)`` takes the base to convert from as a second optional argument, so ``int('0x144', 16) == 324``. If the base is specified as 0, the number is interpreted using Python's rules: a leading '0' indicates octal, and '0x' indicates a hex number. Do not use the built-in function ``eval()`` if all you need is to convert strings to numbers. ``eval()`` will be significantly slower and it presents a security risk: someone could pass you a Python expression that might have unwanted side effects. For example, someone could pass ``__import__('os').system("rm -rf $HOME")`` which would erase your home directory. ``eval()`` also has the effect of interpreting numbers as Python expressions, so that e.g. eval('09') gives a syntax error because Python regards numbers starting with '0' as octal (base 8). How do I convert a number to a string? ---------------------------------------------- To convert, e.g., the number 144 to the string '144', use the built-in function ``str()``. If you want a hexadecimal or octal representation, use the built-in functions ``hex()`` or ``oct()``. For fancy formatting, use `the % operator `_ on strings, e.g. ``"%04d" % 144`` yields '0144' and ``"%.3f" % (1/3.0)`` yields '0.333'. See the library reference manual for details. How do I modify a string in place? ------------------------------------------ You can't, because strings are immutable. If you need an object with this ability, try converting the string to a list or use the array module:: >>> s = "Hello, world" >>> a = list(s) >>> print a ['H', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd'] >>> a[7:] = list("there!") >>> ''.join(a) 'Hello, there!' >>> import array >>> a = array.array('c', s) >>> print a array('c', 'Hello, world') >>> a[0] = 'y' ; print a array('c', 'yello world') >>> a.tostring() 'yello, world' How do I use strings to call functions/methods? ---------------------------------------------------------- There are various techniques. * The best is to use a dictionary that maps strings to functions. The primary advantage of this technique is that the strings do not need to match the names of the functions. This is also the primary technique used to emulate a case construct:: def a(): pass def b(): pass dispatch = {'go': a, 'stop': b} # Note lack of parens for funcs dispatch[get_input()]() # Note trailing parens to call function * Use the built-in function ``getattr()``:: import foo getattr(foo, 'bar')() Note that getattr() works on any object, including classes, class instances, modules, and so on. This is used in several places in the standard library, like this:: class Foo: def do_foo(self): ... def do_bar(self): ... f = getattr(foo_instance, 'do_' + opname) f() * Use ``locals()`` or ``eval()`` to resolve the function name:: def myFunc(): print "hello" fname = "myFunc" f = locals()[fname] f() f = eval(fname) f() Note: Using ``eval()`` is slow and dangerous. If you don't have absolute control over the contents of the string, someone could pass a string that resulted in an arbitrary function being executed. Is there an equivalent to Perl's chomp() for removing trailing newlines from strings? -------------------------------------------------------------------------------------------- There are two partial substitutes. If you want to remove all trailing whitespace, use the ``rstrip()`` method of string objects. This removes all trailing whitespace, not just a single newline. Otherwise, if there is only one line in the string ``S``, use ``S.splitlines()[0]``. Is there a scanf() or sscanf() equivalent? -------------------------------------------------- Not as such. For simple input parsing, the easiest approach is usually to split the line into whitespace-delimited words using the ``split()`` method of string objects and then convert decimal strings to numeric values using ``int()`` or ``float()``. ``split()`` supports an optional "sep" parameter which is useful if the line uses something other than whitespace as a separator. For more complicated input parsing, regular expressions more powerful than C's ``sscanf()`` and better suited for the task. What does 'UnicodeError: ASCII [decoding,encoding] error: ordinal not in range(128)' mean? ----------------------------------------------------------------------------------------------------- This error indicates that your Python installation can handle only 7-bit ASCII strings. There are a couple ways to fix or work around the problem. If your programs must handle data in arbitary character set encodings, the environment the application runs in will generally identify the encoding of the data it is handing you. You need to convert the input to Unicode data using that encoding. For example, a program that handles email or web input will typically find character set encoding information in Content-Type headers. This can then be used to properly convert input data to Unicode. Assuming the string referred to by ``value`` is encoded as UTF-8:: value = unicode(value, "utf-8") will return a Unicode object. If the data is not correctly encoded as UTF-8, the above call will raise a ``UnicodeError`` exception. If you only want strings coverted to Unicode which have non-ASCII data, you can try converting them first assuming an ASCII encoding, and then generate Unicode objects if that fails:: try: x = unicode(value, "ascii") except UnicodeError: value = unicode(value, "utf-8") else: # value was valid ASCII data pass It's possible to set a default encoding in a file called ``sitecustomize.py`` that's part of the Python library. However, this isn't recommended because changing the Python-wide default encoding may cause third-party extension modules to fail. Note that on Windows, there is an encoding known as "mbcs", which uses an encoding specific to your current locale. In many cases, and particularly when working with COM, this may be an appropriate default encoding to use. Sequences (Tuples/Lists) ================================= How do I convert between tuples and lists? ------------------------------------------------ The function ``tuple(seq)`` converts any sequence (actually, any iterable) into a tuple with the same items in the same order. For example, ``tuple([1, 2, 3])`` yields ``(1, 2, 3)`` and ``tuple('abc')`` yields ``('a', 'b', 'c')``. If the argument is a tuple, it does not make a copy but returns the same object, so it is cheap to call ``tuple()`` when you aren't sure that an object is already a tuple. The function ``list(seq)`` converts any sequence or iterable into a list with the same items in the same order. For example, ``list((1, 2, 3))`` yields ``[1, 2, 3]`` and ``list('abc')`` yields ``['a', 'b', 'c']``. If the argument is a list, it makes a copy just like ``seq[:]`` would. What's a negative index? -------------------------------------------------------------------- Python sequences are indexed with positive numbers and negative numbers. For positive numbers 0 is the first index 1 is the second index and so forth. For negative indices -1 is the last index and -2 is the pentultimate (next to last) index and so forth. Think of ``seq[-n]`` as the same as ``seq[len(seq)-n]``. Using negative indices can be very convenient. For example ``S[:-1]`` is all of the string except for its last character, which is useful for removing the trailing newline from a string. How do I iterate over a sequence in reverse order? --------------------------------------------------------- If it is a list, the fastest solution is :: list.reverse() try: for x in list: "do something with x" finally: list.reverse() This has the disadvantage that while you are in the loop, the list is temporarily reversed. If you don't like this, you can make a copy. This appears expensive but is actually faster than other solutions:: rev = list[:] rev.reverse() for x in rev: If it's not a list, a more general but slower solution is:: for i in range(len(sequence)-1, -1, -1): x = sequence[i] A more elegant solution, is to define a class which acts as a sequence and yields the elements in reverse order (solution due to Steve Majewski):: class Rev: def __init__(self, seq): self.forw = seq def __len__(self): return len(self.forw) def __getitem__(self, i): return self.forw[-(i + 1)] You can now simply write:: for x in Rev(list): Unfortunately, this solution is slowest of all, due to the method call overhead. How do you remove duplicates from a list? ------------------------------------------------- See the Python Cookbook for a long discussion of many ways to do this: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52560 If you don't mind reordering the list, sort it and then scan from the end of the list, deleting duplicates as you go:: if List: List.sort() last = List[-1] for i in range(len(List)-2, -1, -1): if last==List[i]: del List[i] else: last=List[i] If all elements of the list may be used as dictionary keys (i.e. they are all hashable) this is often faster :: d = {} for x in List: d[x]=x List = d.values() How do you make an array in Python? ---------------------------------------------------- Use a list:: ["this", 1, "is", "an", "array"] Lists are equivalent to C or Pascal arrays in their time complexity; the primary difference is that a Python list can contain objects of many different types. The ``array`` module also provides methods for creating arrays of fixed types with compact representations, but they are slower to index than lists. Also note that the Numeric extensions and others define array-like structures with various characteristics as well. To get Lisp-style linked lists, you can emulate cons cells using tuples:: lisp_list = ("like", ("this", ("example", None) ) ) If mutability is desired, you could use lists instead of tuples. Here the analogue of lisp car is ``lisp_list[0]`` and the analogue of cdr is ``lisp_list[1]``. Only do this if you're sure you really need to, because it's usually a lot slower than using Python lists. How do I create a multidimensional list? --------------------------------------------------------------- You probably tried to make a multidimensional array like this:: A = [[None] * 2] * 3 This looks correct if you print it:: >>> A [[None, None], [None, None], [None, None]] But when you assign a value, it shows up in multiple places: >>> A[0][0] = 5 >>> A [[5, None], [5, None], [5, None]] The reason is that replicating a list with ``*`` doesn't create copies, it only creates references to the existing objects. The ``*3`` creates a list containing 3 references to the same list of length two. Changes to one row will show in all rows, which is almost certainly not what you want. The suggested approach is to create a list of the desired length first and then fill in each element with a newly created list:: A = [None]*3 for i in range(3): A[i] = [None] * 2 This generates a list containing 3 different lists of length two. You can also use a list comprehension:: w,h = 2,3 A = [ [None]*w for i in range(h) ] Or, you can use an extension that provides a matrix datatype; `Numeric Python `_ is the best known. How do I apply a method to a sequence of objects? -------------------------------------------------------------------------- Use a list comprehension:: result = [obj.method() for obj in List] More generically, you can try the following function:: def method_map(objects, method, arguments): """method_map([a,b], "meth", (1,2)) gives [a.meth(1,2), b.meth(1,2)]""" nobjects = len(objects) methods = map(getattr, objects, [method]*nobjects) return map(apply, methods, [arguments]*nobjects) Dictionaries ================== How can I get a dictionary to display its keys in a consistent order? ----------------------------------------------------------------------------- You can't. Dictionaries store their keys in an unpredictable order, so the display order of a dictionary's elements will be similarly unpredictable. This can be frustrating if you want to save a printable version to a file, make some changes and then compare it with some other printed dictionary. In this case, use the ``pprint`` module to pretty-print the dictionary; the items will be presented in order sorted by the key. A more complicated solution is to subclass ``UserDict.UserDict`` to create a ``SortedDict`` class that prints itself in a predictable order. Here's one simpleminded implementation of such a class:: import UserDict, string class SortedDict(UserDict.UserDict): def __repr__(self): result = [] append = result.append keys = self.data.keys() keys.sort() for k in keys: append("%s: %s" % (`k`, `self.data[k]`)) return "{%s}" % string.join(result, ", ") ___str__ = __repr__ This will work for many common situations you might encounter, though it's far from a perfect solution. The largest flaw is that if some values in the dictionary are also dictionaries, their values won't be presented in any particular order. I want to do a complicated sort: can you do a Schwartzian Transform in Python? -------------------------------------------------------------------------------------- Yes, it's quite simple with list comprehensions. The technique, attributed to Randal Schwartz of the Perl community, sorts the elements of a list by a metric which maps each element to its "sort value". To sort a list of strings by their uppercase values:: tmp1 = [ (x.upper(), x) for x in L ] # Schwartzian transform tmp1.sort() Usorted = [ x[1] for x in tmp1 ] To sort by the integer value of a subfield extending from positions 10-15 in each string:: tmp2 = [ (int(s[10:15]), s) for s in L ] # Schwartzian transform tmp2.sort() Isorted = [ x[1] for x in tmp2 ] Note that Isorted may also be computed by :: def intfield(s): return int(s[10:15]) def Icmp(s1, s2): return cmp(intfield(s1), intfield(s2)) Isorted = L[:] Isorted.sort(Icmp) but since this method calls ``intfield()`` many times for each element of L, it is slower than the Schwartzian Transform. How can I sort one list by values from another list? ------------------------------------------------------------ Merge them into a single list of tuples, sort the resulting list, and then pick out the element you want. :: >>> list1 = ["what", "I'm", "sorting", "by"] >>> list2 = ["something", "else", "to", "sort"] >>> pairs = zip(list1, list2) >>> pairs [('what', 'something'), ("I'm", 'else'), ('sorting', 'to'), ('by', 'sort')] >>> pairs.sort() >>> result = [ x[1] for x in pairs ] >>> result ['else', 'sort', 'to', 'something'] An alternative for the last step is:: result = [] for p in pairs: result.append(p[1]) If you find this more legible, you might prefer to use this instead of the final list comprehension. However, it is almost twice as slow for long lists. Why? First, the ``append()`` operation has to reallocate memory, and while it uses some tricks to avoid doing that each time, it still has to do it occasionally, and that costs quite a bit. Second, the expression "result.append" requires an extra attribute lookup, and third, there's a speed reduction from having to make all those function calls. Objects ============= What is a class? ------------------------ A class is the particular object type created by executing a class statement. Class objects are used as templates to create instance objects, which embody both the data (attributes) and code (methods) specific to a datatype. A class can be based on one or more other classes, called its base class(es). It then inherits the attributes and methods of its base classes. This allows an object model to be successively refined by inheritance. You might have a generic ``Mailbox`` class that provides basic accessor methods for a mailbox, and subclasses such as ``MboxMailbox``, ``MaildirMailbox``, ``OutlookMailbox`` that handle various specific mailbox formats. What is a method? ------------------------- A method is a function on some object ``x`` that you normally call as ``x.name(arguments...)``. Methods are defined as functions inside the class definition:: class C: def meth (self, arg): return arg*2 + self.attribute What is self? --------------------- Self is merely a conventional name for the first argument of a method. A method defined as ``meth(self, a, b, c)`` should be called as ``x.meth(a, b, c)`` for some instance ``x`` of the class in which the definition occurs; the called method will think it is called as ``meth(x, a, b, c)``. How do I check if an object is an instance of a given class or of a subclass of it? ------------------------------------------------------------------------------------------- Use the built-in function ``isinstance(obj, cls)``. You can check if an object is an instance of any of a number of classes by providing a tuple instead of a single class, e.g. ``isinstance(obj, (class1, class2, ...))``, and can also check whether an object is one of Python's built-in types, e.g. ``isinstance(obj, str)`` or ``isinstance(obj, (int, long, float, complex))``. Note that most programs do not use ``isinstance()`` on user-defined classes very often. If you are developing the classes yourself, a more proper object-oriented style is to define methods on the classes that encapsulate a particular behaviour, instead of checking the object's class and doing a different thing based on what class it is. For example, if you have a function that does something:: def search (obj): if isinstance(obj, Mailbox): # ... code to search a mailbox elif isinstance(obj, Document): # ... code to search a document elif ... A better approach is to define a ``search()`` method on all the classes and just call it:: class Mailbox: def search(self): # ... code to search a mailbox class Document: def search(self): # ... code to search a document obj.search() What is delegation? --------------------------- Delegation is an object oriented technique (also called a design pattern). Let's say you have an object ``x`` and want to change the behaviour of just one of its methods. You can create a new class that provides a new implementation of the method you're interested in changing and delegates all other methods to the corresponding method of ``x``. Python programmers can easily implement delegation. For example, the following class implements a class that behaves like a file but converts all written data to uppercase:: class UpperOut: def __init__(self, outfile): self.__outfile = outfile def write(self, s): self.__outfile.write(s.upper()) def __getattr__(self, name): return getattr(self.__outfile, name) Here the ``UpperOut`` class redefines the ``write()`` method to convert the argument string to uppercase before calling the underlying ``self.__outfile.write()`` method. All other methods are delegated to the underlying ``self.__outfile`` object. The delegation is accomplished via the ``__getattr__`` method; consult `the language reference `_ for more information about controlling attribute access. Note that for more general cases delegation can get trickier. When attributes must be set as well as retrieved, the class must define a ``__settattr__`` method too, and it must do so carefully. The basic implementation of __setattr__ is roughly equivalent to the following:: class X: ... def __setattr__(self, name, value): self.__dict__[name] = value ... Most __setattr__ implementations must modify self.__dict__ to store local state for self without causing an infinite recursion. How do I call a method defined in a base class from a derived class that overrides it? ---------------------------------------------------------------------------------------------- If you're using new-style classes, use the built-in ``super()`` function:: class Derived(Base): def meth (self): super(Derived, self).meth() If you're using classic classes: For a class definition such as ``class Derived(Base): ...`` you can call method ``meth()`` defined in ``Base`` (or one of ``Base``'s base classes) as ``Base.meth(self, arguments...)``. Here, ``Base.meth`` is an unbound method, so you need to provide the ``self`` argument. How can I organize my code to make it easier to change the base class? ------------------------------------------------------------------------------ You could define an alias for the base class, assign the real base class to it before your class definition, and use the alias throughout your class. Then all you have to change is the value assigned to the alias. Incidentally, this trick is also handy if you want to decide dynamically (e.g. depending on availability of resources) which base class to use. Example:: BaseAlias = class Derived(BaseAlias): def meth(self): BaseAlias.meth(self) ... How do I create static class data and static class methods? ------------------------------------------------------------------- Static data (in the sense of C++ or Java) is easy; static methods (again in the sense of C++ or Java) are not supported directly. For static data, simply define a class attribute. To assign a new value to the attribute, you have to explicitly use the class name in the assignment:: class C: count = 0 # number of times C.__init__ called def __init__(self): C.count = C.count + 1 def getcount(self): return C.count # or return self.count ``c.count`` also refers to ``C.count`` for any ``c`` such that ``isinstance(c, C)`` holds, unless overridden by ``c`` itself or by some class on the base-class search path from ``c.__class__`` back to ``C``. Caution: within a method of C, an assignment like ``self.count = 42`` creates a new and unrelated instance vrbl named "count" in ``self``'s own dict. Rebinding of a class-static data name must always specify the class whether inside a method or not:: C.count = 314 Static methods are possible when you're using new-style classes:: class C: def static(arg1, arg2, arg3): # No 'self' parameter! ... static = staticmethod(static) However, a far more straightforward way to get the effect of a static method is via a simple module-level function:: def getcount(): return C.count If your code is structured so as to define one class (or tightly related class hierarchy) per module, this supplies the desired encapsulation. How can I overload constructors (or methods) in Python? --------------------------------------------------------------- This answer actually applies to all methods, but the question usually comes up first in the context of constructors. In C++ you'd write :: class C { C() { cout << "No arguments\n"; } C(int i) { cout << "Argument is " << i << "\n"; } } in Python you have to write a single constructor that catches all cases using default arguments. For example:: class C: def __init__(self, i=None): if i is None: print "No arguments" else: print "Argument is", i This is not entirely equivalent, but close enough in practice. You could also try a variable-length argument list, e.g. :: def __init__(self, *args): .... The same approach works for all method definitions. I try to use __spam and I get an error about _SomeClassName__spam. -------------------------------------------------------------------------- Variables with double leading underscore are "mangled" to provide a simple but effective way to define class private variables. Any identifier of the form ``__spam`` (at least two leading underscores, at most one trailing underscore) is textually replaced with ``_classname__spam``, where ``classname`` is the current class name with any leading underscores stripped. This doesn't guarantee privacy: an outside user can still deliberately access the "_classname__spam" attribute, and private values are visible in the object's ``__dict__``. Many Python programmers never bother to use private variable names at all. My class defines __del__ but it is not called when I delete the object. ------------------------------------------------------------------------------- There are several possible reasons for this. The del statement does not necessarily call __del__ -- it simply decrements the object's reference count, and if this reaches zero __del__ is called. If your data structures contain circular links (e.g. a tree where each child has a parent reference and each parent has a list of children) the reference counts will never go back to zero. Once in a while Python runs an algorithm to detect such cycles, but the garbage collector might run some time after the last reference to your data structure vanishes, so your __del__ method may be called at an inconvenient and random time. This is inconvenient if you're trying to reproduce a problem. Worse, the order in which object's __del__ methods are executed is arbitrary. You can run ``gc.collect()`` to force a collection, but there *are* pathological cases where objects will never be collected. Despite the cycle collector, it's still a good idea to define an explicit ``close()`` method on objects to be called whenever you're done with them. The ``close()`` method can then remove attributes that refer to subobjecs. Don't call ``__del__`` directly -- ``__del__`` should call ``close()`` and ``close()`` should make sure that it can be called more than once for the same object. Another way to avoid cyclical references is to use the "weakref" module, which allows you to point to objects without incrementing their reference count. Tree data structures, for instance, should use weak references for their parent and sibling references (if they need them!). If the object has ever been a local variable in a function that caught an expression in an except clause, chances are that a reference to the object still exists in that function's stack frame as contained in the stack trace. Normally, calling ``sys.exc_clear()`` will take care of this by clearing the last recorded exception. Finally, if your __del__ method raises an exception, a warning message is printed to sys.stderr. How do I get a list of all instances of a given class? -------------------------------------------------------------- Python does not keep track of all instances of a class (or of a built-in type). You can program the class's constructor to keep track of all instances by keeping a list of weak references to each instance. Modules ============= How do I create a .pyc file? ------------------------------------- When a module is imported for the first time (or when the source is more recent than the current compiled file) a ``.pyc`` file containing the compiled code should be created in the same directory as the ``.py`` file. One reason that a ``.pyc`` file may not be created is permissions problems with the directory. This can happen, for example, if you develop as one user but run as another, such as if you are testing with a web server. Creation of a .pyc file is automatic if you're importing a module and Python has the ability (permissions, free space, etc...) to write the compiled module back to the directory. Running Python on a top level script is not considered an import and no ``.pyc`` will be created. For example, if you have a top-level module ``abc.py`` that imports another module ``xyz.py``, when you run abc, ``xyz.pyc`` will be created since xyz is imported, but no ``abc.pyc`` file will be created since ``abc.py`` isn't being imported. If you need to create abc.pyc -- that is, to create a .pyc file for a module that is not imported -- you can, using the py_compile and compileall modules. The ``py_compile`` module can manually compile any module. One way is to use the ``compile()`` function in that module interactively:: >>> import py_compile >>> py_compile.compile('abc.py') This will write the ``.pyc`` to the same location as ``abc.py`` (or you can override that with the optional parameter ``cfile``). You can also automatically compile all files in a directory or directories using the ``compileall`` module. You can do it from the shell prompt by running ``compileall.py`` and providing the path of a directory containing Python files to compile:: python compileall.py . How do I find the current module name? --------------------------------------------- A module can find out its own module name by looking at the predefined global variable ``__name__``. If this has the value '__main__', the program is running as a script. Many modules that are usually used by importing them also provide a command-line interface or a self-test, and only execute this code after checking ``__name__``:: def main(): print 'Running test...' ... if __name__ == '__main__': main() How can I have modules that mutually import each other? --------------------------------------------------------------- Suppose you have the following modules: foo.py:: from bar import bar_var foo_var=1 bar.py:: from foo import foo_var bar_var=2 The problem is that the interpreter will perform the following steps: * main imports foo * Empty globals for foo are created * foo is compiled and starts executing * foo imports bar * Empty globals for bar are created * bar is compiled and starts executing * bar imports foo (which is a no-op since there already is a module named foo) * bar.foo_var = foo.foo_var The last step fails, because Python isn't done with interpreting ``foo`` yet and the global symbol dictionary for ``foo`` is still empty. The same thing happens when you use ``import foo``, and then try to access ``foo.foo_var`` in global code. There are (at least) three possible workarounds for this problem. Guido van Rossum recommends avoiding all uses of ``from import ...``, and placing all code inside functions. Initializations of global variables and class variables should use constants or built-in functions only. This means everything from an imported module is referenced as ``.``. Jim Roskind suggests performing steps in the following order in each module: * exports (globals, functions, and classes that don't need imported base classes) * ``import`` statements * active code (including globals that are initialized from imported values). van Rossum doesn't like this approach much because the imports appear in a strange place, but it does work. Matthias Urlichs recommends restructuring your code so that the recursive import is not necessary in the first place. These solutions are not mutually exclusive. __import__('x.y.z') returns ; how do I get z? ----------------------------------------------------------------------- Try:: __import__('x.y.z').y.z For more realistic situations, you may have to do something like :: m = __import__(s) for i in s.split(".")[1:]: m = getattr(m, i) When I edit an imported module and reimport it, the changes don't show up. Why does this happen? -------------------------------------------------------------------------------------------------------------------------------------------- For reasons of efficiency as well as consistency, Python only reads the module file on the first time a module is imported. If it didn't, in a program consisting of many modules where each one imports the same basic module, the basic module would be parsed and re-parsed many times. To force rereading of a changed module, do this:: import modname reload(modname) Warning: this technique is not 100% fool-proof. In particular, modules containing statements like :: from modname import some_objects will continue to work with the old version of the imported objects. If the module contains class definitions, existing class instances will *not* be updated to use the new class definition. This can result in the following paradoxical behaviour:: >>> import cls >>> c = cls.C() # Create an instance of C >>> reload(cls) >>> isinstance(c, cls.C) # isinstance is false?!? False The nature of the problem is made clear if you print out the class objects: >>> c.__class__ >>> cls.C From dietmar@schwertberger.de Mon Aug 18 20:16:48 2003 From: dietmar@schwertberger.de (Dietmar Schwertberger) Date: Mon, 18 Aug 2003 21:16:48 +0200 Subject: Python 2.3 for RISC OS Message-ID: ============================================================================ Python 2.3 for RISC OS release 2003-08-03 ============================================================================ I'm pleased to announce that binaries of Python 2.3 for RISC OS are available from http://www.schwertberger.de/python.html . RISC OS Python includes the following highlights: * An integrated interface to the SWI system * Drawfile support * Interfaces to the RISC OS WIMP and toolbox (with examples) * Numeric extension * PeerBoard: share your clipboard contents between multiple RISC OS and win32 computers over TCP/IP connections * SSLRelay: a simple SSL proxy server For use of Python you will need a filing system with long filename and >77 files/directory support. Bug reports etc. ================ RISC OS specific bug reports, contributions, comments, critics, links to RISC OS compatible Python libraries to dietmar@schwertberger.de From brett@python.org Mon Aug 18 22:49:25 2003 From: brett@python.org (Brett C.) Date: Mon, 18 Aug 2003 14:49:25 -0700 Subject: python-dev Summary for 2003-08-01 through 2003-08-15 Message-ID: python-dev Summary for 2003-08-01 through 2003-08-15 ++++++++++++++++++++++++++++++++++++++++++++++++++++ This is a summary of traffic on the `python-dev mailing list`_ from=20 August 1, 2003 through August 15, 2003. It is intended to inform the=20 wider Python community of on-going developments on the list. To comment=20 on anything mentioned here, just post to python-list@python.org or=20 `comp.lang.python`_ with a subject line mentioning what you are=20 discussing. All python-dev members are interested in seeing ideas=20 discussed by the community, so don't hesitate to take a stance on=20 something. And if all of this really interests you then get involved=20 and join `python-dev`_! This is the twenty-third summary written by Brett Cannon (about to move=20 for the umpteenth time). All summaries are archived at http://www.python.org/dev/summary/ . Please note that this summary is written using reStructuredText_ which=20 can be found at http://docutils.sf.net/rst.html . Any unfamiliar=20 punctuation is probably markup for reST_ (otherwise it is probably=20 regular expression syntax or a typo =3D); you can safely ignore it,=20 although I suggest learning reST; its simple and is accepted for `PEP=20 markup`_ and gives some perks for the HTML output. Also, because of the=20 wonders of programs that like to reformat text, I cannot guarantee you=20 will be able to run the text version of this summary through Docutils_=20 as-is unless it is from the original text file. .. _PEP Markup: http://www.python.org/peps/pep-0012.html The in-development version of the documentation for Python can be found=20 at http://www.python.org/dev/doc/devel/ and should be used when looking=20 up any documentation on something mentioned here. Python PEPs (Python=20 Enhancement Proposals) are located at http://www.python.org/peps/ . To=20 view files in the Python CVS online, go to=20 http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/python/ . .. _python-dev: http://www.python.org/dev/ .. _python-dev mailing list:=20 http://mail.python.org/mailman/listinfo/python-dev .. _comp.lang.python: http://groups.google.com/groups?q=3Dcomp.lang.pytho= n .. _Docutils: http://docutils.sf.net/ .. _reST: .. _reStructuredText: http://docutils.sf.net/rst.html .. contents:: .. _last summary:=20 http://www.python.org/dev/summary/2003-07-01_2003-07-31.html =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Summary Announcements =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Well, Michael Chermside responded to my question from the last summary=20 about whether the new format and style of the Summaries was good. Once=20 again a single person has led to how the summaries will be handled. You=20 guys need to speak up (although I like the side that won this time =3D)! I am playing with layout once again. This time I am changing how the=20 "contributing threads" lists are formatted. I know some of you hate=20 inlined links in reST markup, but when these lists become huge it=20 becomes really hard to keep track of the URIs when I have to list them=20 away from the actual item on a separate line below the list of thread nam= es. With `Python 2.3` out the door bug reports have started to come in.=20 Work on 2.3.1 has begun. Please keep running the regression tests=20 (easiest way is to run either ``make test`` or run regrtest.py in the=20 test package; see the docs for the test package for help). On a personal note, if anyone knows of any Python users and such in the=20 San Luis Obispo area of California, drop me a line at brett at python.org. =3D=3D=3D=3D=3D=3D=3D=3D=3D Summaries =3D=3D=3D=3D=3D=3D=3D=3D=3D ----------------------------------------- Python user helping Parrot? Treacherous! ----------------------------------------- Michal Wallace decided to get AM Kuchling's `previous work=20 `__ on getting Python code to run=20 on the Parrot_ virtual machine (which is what Perl 6 will use). Well,=20 the rather nutty fellow managed to get pretty damn far with it as shown=20 at http://pirate.versionhost.com/viewcvs.cgi/pirate/ . Michal was=20 actually almost done with handling pure Python code and was getting=20 ready to try to figure out how to get Parrot to handle C extension=20 modules with that being the biggest sticking point. Since Parrot is not Python it does not have a parser for Python code;=20 problem if your code has an exec statement. This turned out to not be a=20 worry, though, since there are pure Python parsers out there. All of this has direct relevance to python-dev because of the bet=20 between Guido and Dan Sugalski, developer of Parrot. The rules are=20 outlined at http://www.sidhe.org/~dan/blog/archives/2003_07.html#000219=20 . What is going to happen at OSCON 2004 is a benchmark program written=20 in pure Python will be run using a CVS checkout of Python against a=20 Parrot (after converting the bytecode to Parrot's own bytecode)=20 checkout; slowest implementation's author gets a pie in the face, buy=20 the winner's dev team a round of beer, and $10. So why have this bet? This was discussed and basically came down to=20 finding out whether Parrot really can run Python fast. Parrot wants to=20 be the VM for as many languages as possible, including Python. This=20 acts as a way to motivate people to see how feasible this is. And don't think that the CPython interpreter will disappear if Parrot=20 wins. Dan pointed out that even if he did win the bet that Guido would=20 probably want to keep CPython around since that is under his control and=20 allows testing out new language features much easier then having to deal=20 with Parrot and an external dev team. In other words, let other people=20 worry about forcing a Python-shaped peg into a Parrot-sized hole. .. _Parrot: http://www.parrotcode.org/ Contributing threads: * `pirate (python+parrot)=20 `__ ---------------------------------------------------- python-mode gets its own SF project; Vim users laugh ---------------------------------------------------- Barry Warsaw, citing lack of time to "properly maintain python-mode.el",=20 has created a SourceForge project for the Emacs mode at=20 http://sf.net/projects/python-mode . This means all bug reports,=20 patches, etc. should be done at that project. Martin v. L=F6wis suggested removing `python-mode.el`_ from Python itself= =20 and to get it distributed with Emacs_ and XEmacs_. This way there does=20 not have to be any synchronization between the new SF project and the=20 Python CVS tree. As of right now, though, python-mode.el is still in=20 the Python CVS. And to give equal billing to Vim_, my code editor of choice, since it=20 does not get as much coverage on python-dev as XEmacs does, here are=20 some scripts you might want to check out: taglist.vim : http://vim.sourceforge.net/scripts/script.php?script_id=3D2= 73 "provides an overview of the structure of source code files" by=20 splitting the window. python_fold.vim :=20 http://vim.sourceforge.net/scripts/script.php?script_id=3D515 "This script uses the expr fold-method to create folds for python=20 source code." vimDebug : http://vim.sourceforge.net/scripts/script.php?script_id=3D663 " integrates your favorite debugger with vim." .. _python-mode.el: http://sf.net/projects/python-mode .. _Emacs: http://www.gnu.org/software/emacs/emacs.html .. _XEmacs: http://www.xemacs.org/ .. _Vim: http://www.vim.org/ Contributing threads: * `New python-mode project at SourceForge=20 `__ * New place for python-mode bug reports and patches=20 `__ -------------------- Caching tuple hashes -------------------- Raymond Hettinger asked if there was any reason why tuples, being=20 immutable, didn't cache their hash values. Strings cache their hashes=20 and they are immutable, so it seem to make sense. It was pointed out, though, that tuples could contain an object that=20 changed its hash value between hash calls. Guido said, though, that it=20 was the responsibility of the object and not tuples to worry about=20 keeping a consistent hash value. Guido also explained why strings cache their hashes. It turns out that=20 since strings are used so often for keys in dicts that caching their=20 hashes gave a large performance boost for almost any program, so the=20 effort was felt justified. But Guido did not see this same=20 justification for tuples. Thus tuples will not cache their hash values. Contributing threads: * `Caching tuple hashes=20 `__ ------------------------------- PyCon 2004 is under development ------------------------------- Preparation for PyCon_ 2004 have now begun. With us getting the ball=20 rolling much earlier this conference should turn out to be even better=20 than last year (which, in my opinion, was great)! You can go to=20 http://www.python.org/pycon/dc2004/ to find links to lists to get=20 involved in organizing or just to be kept abreast of new developments. .. _PyCon: http://www.python.org/pycon/dc2004/ Contributing threads: * `PyCon DC 2004 Kickoff!=20 `__ ---------------------------- Let the fixing of 2.3 begin! ---------------------------- The maintenance branch of Python 2.3 (named release23-maint) has been=20 created in CVS. Several bugs have already been fixed. For instructions=20 on how to check out a copy of the branch, read=20 http://www.python.org/dev/devfaq.html#c10 . Contributing threads: * `Python 2.3 maintenance branch is now open=20 `__ ------------------------------------ When a void doesn't equal an integer ------------------------------------ After clearing up the confusing issue of the difference between a Python=20 int and a Python Integer (the former is while the latter is=20 the union of and which is what Python is=20 moving towards so that the distinction practically disappears), the=20 discussion of how to handle a quirk of Win64 commenced. It turns out=20 that Win64 thinks that ``sizeof(void *) > sizeof(long)`` is a reasonable=20 thing to do. Well, all other platforms now and most likely for the rest=20 of Tim Peter's life (at least according to Tim's guess) don't and won't=20 hold this to be true. As of right now Python claims that a void pointer can be held in a=20 Python int, but Win64 breaks that claim. Do we muck around with=20 Python's internals for this one strange exception that does not make=20 sense, such as making Python ints use long long? No, of course not.=20 Code would break, let alone the added complexity. So the needed changes=20 to the failing tests were dealt with and all seems to be fine with the=20 world again ... well, Win64 is still thinking on crack, but that is=20 someone else's problem. Contributing threads: * `sizeof(long) !=3D sizeof(void*)=20 `__ ------------------------------------ Where do I put all of my packages?!? ------------------------------------ As it stands now there are four places where packages can reside: 1. standard library 2. site-packages 3. site-python (on UNIX this is the same directory where your python2.3=20 directory exists) 4. PYTHONPATH environment variable It was pointed out that this does not necessarily give one all the=20 options one might want. The above covers the Python core easily, but=20 there is not clear distinction for vendor packages, network-installed=20 packages, system-wide packages or user-installed packages; they are=20 covered by 2-4 above. The suggestion was to make more distinct places=20 available for installation and to make distutils aware of them. A good way to see how this would be useful is to look at how OS X's=20 Panther will handle Python 2.3 . It will have the standard library in=20 the standard location of /usr/local/python2.4 . In that directory, the=20 site-packages directory is a symlink to a more system-aware location.=20 This is fine but what about a sysadmin who would rather avoid the=20 possibility of breaking OS X by messing with the OS's Python=20 installation? What about a user on that system who does not have root=20 but wants to have their own place to put their packages? There is=20 definitely room for adding more standard path locations for package=20 installations. A PEP was being mentioned but appears to not have been written yet. Contributing threads: * `Multiple levels of site-packages=20 `__ ------------------------- Be careful with __slots__ ------------------------- Raymond Hettinger observed that using __slots__ or overriding=20 __getattribute__ fails silently when mistakenly used with old-style=20 classes. This has bitten him and others in the bum so he wanted to add=20 warning/error messages. Guido recommended passing on the warnings=20 because 1) those are "expert use only" tools, 2) PyChecker can already=20 detect the issue, and 3) there are other new-style/classic issues cannot=20 as readily be flagged. It should be known that "__slots__ is a terrible hack with nasty,=20 hard-to-fathom side effects that should only be used by programmers at=20 grandmaster and wizard levels". So only use __slots__ if you can apply=20 the label of "programmer at grandmaster or wizard level" to yourself=20 without your programming peers laughting their bums off; you have been=20 warned. Contributing threads: * `Make it an error to use __slots__ with classic classes=20 `__ -------------- Plugging leaks -------------- Michael Hudson thought he had discovered a leak somewhere and went off=20 on a little hunt. It turned out to be a red herring more or less, but=20 there was some discussion on the best way to find leaks through=20 regression tests. The basic scheme that everyone seemed to use was to run the regression=20 test once to get any caching out of the way and then run the test a set=20 number of times and see if the reference counts seemed to grow. Michael=20 Hudson posted a diff to add such a testing feature to test/regrtest.py=20 at http://mail.python.org/pipermail/python-dev/2003-August/037617.html .=20 Tim Peters also posted a link to Zope's test driver at=20 http://cvs.zope.org/Zope3/test.py which includes a class named TrackRefs=20 which can help keep track of the leaked references as well as leaked=20 objects. Contributing threads: * `CALL_ATTR patch=20 `__ * `refleak hunting fun!=20 `__ ----------------------------------------- Making the interpreter its own executable ----------------------------------------- As it stands now the Python interpreter is distributed as a bunch of=20 files mostly made up of the standard library. But wouldn't it be nice=20 if you could make the interpreter just a single executable that was easy=20 to distribute with your code? Well, that discussion cropped up on=20 `comp.lang.python`_ at=20 http://groups.google.com/groups?hl=3Den&lr=3D&ie=3DUTF-8&safe=3Doff&threa= dm=3Dptji8wgr.fsf%40python.net=20 . The idea was to somehow introduce a hook into Py_Main() that could=20 harness the new zipimport facility. The idea came up of appending the stdlib to the end of the Python=20 interpreter and to have a flag set to signal that the appending had=20 occurred. The problem is that this could cause unzipping problems. But setting the flag is not necessarily simple either. One suggestion=20 was to literally patch the interpreter to set the flag. But there was=20 some confusion over the use of the term "patch"; Thomas Heller thought=20 more of "link with an object file defining this global variable". This thread was still going as of this writing and had not yet reached a=20 clear solution. Contributing threads: * `hook for standalone executable=20 `__ From frank@pc-nett.no Tue Aug 19 12:00:47 2003 From: frank@pc-nett.no (frank) Date: Tue, 19 Aug 2003 13:00:47 +0200 Subject: ANN: soprano 0.003 Message-ID: Soprano is a GUI app that scans a selected range of ip addresses and try to get info about the hosts such as users, localgroups, shares, operating system. This program only runs under windows. changes 0.002 > 0.003:. added settings window setting are saved in xml and are stored under data\setting.xml setting include: "logon as" with username and password or use null request resolv hostname shares users groups info portscanner improved right click menu\submenu new functions: add user add group add share send msg (NetMessageBufferSend) Source code and windows binary at http://sourceforge.net/projects/soprano/ From pdfernhout@kurtz-fernhout.com Thu Aug 21 00:25:31 2003 From: pdfernhout@kurtz-fernhout.com (Paul D. Fernhout) Date: Wed, 20 Aug 2003 19:25:31 -0400 Subject: Pointrel20030812.1 Data Repository System released Message-ID: Pointrel20030812.1 for Python 2.3 is now available at SourceForge: http://sourceforge.net/projects/pointrel/ * Highlights for this version? + Uses 64 bit file positions. + Log file format is XML. + Specification document included. + CRC32 now used for string hashes. + Locks no longer deleted automatically when old by default. + Now uses WILD constant instead of "*" for wildcards in searches. + Data strings can be Unicode (UTF-8), binary, or Python objects. * Release notes? This version is pure-Python and has been tested under Python 2.3. It may work with earlier 2.x Python versions or require only minor changes for them. It was tested only under Debian GNU/Linux, but earlier versions ran under Windows. The biggest change from the previous version is support for very large files (>2GB) by using 64 bit file positions. It still needs more testing though, so don't put all your terabytes of vital enterprise data in it just yet without some kind of parallel system going, just in case. ;-) But seriously, the software comes with NO WARRANTY (see the included file license.txt for details). * In what situations is the Pointrel Data Repository System intended to useful? The Pointrel System is intended to provide a flexible framework for storing information that can co-evolve with your data storage needs. The best match is a situation where you have potentially a lot of adhoc data which you or others may want to use in a variety of ways now and in the future, and you want a solution that lets you get started right now and then keep making changes on the fly, while preserving all data contributed permanently as an archive. An example of this would be an extensible peer-to-peer groupware application supporting continual frequent revision of everything in the repository. I intend to use it in this way, as part of the infrastructure of a project related to collecting manufacturing knowledge. Or, you might have well defined data storage needs and just want to support some sort of complex persistent transactional data storage by including only one or two extra files in your application which don't need special installation or configuration, and you are willing to live with potentially slower performance and some other limitations. There are other potential mini-database candidates for such a role as well (including Python's DBM module), so the Pointrel System might only be selected over them in this case with an eye to future expansion in more adhoc ways, such as supporting third party tools that will use the same store. Or, perhaps, you just might want to stretch your mind after too much SQL coding. :-) * What is the underlying design of the Pointrel Data Repository System? The Pointrel Data Repository System is a variant of an Entity-Relationship (E-R) model database. The Pointrel system provides a way to easily handle loosely structured data stored on disk, like for INI files, version control systems, bug tracking systems, or simple AI type applications. It takes an approach to data storage which emphasizes flexibility over speed. It also emphasizes storing new information for the long term over modifying or deleting old information. It hopefully makes it easier to build new layers of abstraction and indexing over old data. The Pointrel Data Repository System bears some resemblance to the ROSE/STAR system described by William Kent in his book "Data & Reality". It also bears some resemblance to RDF. The Pointrel System is to an extent mainly a mindset about how to build extensible applications using persistent E-R data, and this release is one example of a tool to make such applications easier to build. In a nutshell, the Pointrel Data Repository System helps you build associations which define relationships between entities. These associations are essentially triadal links between things indicating one thing is linked to a second thing in a way defined by a third thing. The simplest way to use such links is to make the equivalent of object properties or a dictionary, such as "Fluffy weight 20kg" which if a dictionary would be Fluffy["weight] = "20kg". However, Pointrel differs from a dictionary in that is supports queries like one for all dictionaries which define a weight of 20kg or all relationships between "Fluffy" and "20kg". Triads are all defined within a specific context space that gives meaning to the associations (making triads actually have four fields). The context allows triads to be handled within an archive in a somewhat more modular fashion using them as filters, since you can easily ignore triads not in the context of interest. All fields of a triad are indefinite length strings (binary, Unicode, or a pickled Python object) -- so they could be anything from the test "foo" to the contents of a binary file to a Python dictionary. * What is the Pointrel Data Repository System not? At this point the Pointrel system is not a polished product. This release is best enjoyed by someone who is more experimentally minded who just wants to have some fun while learning about the entity-relationship model of data storage as another tool for their toolbox. This release is also for those with a desperate need to make sense of a deluge of adhoc data and are willing to take risks on something new in practice (but old in theory). If you are looking for tried and proven methods and software for storing data right now, relational databases like MySQL or PostgreSQL are probably safer bets. Obviously, having said that, I hope you will try this system anyway and supply constructive criticism and positive feedback. * What is a simple example of the Pointrel API being used? See "pointrelTestFluffyExample.py" for an example of using the simplified global function interface. Here is an excerpt from that file: from pointrel20030812 import * Pointrel_initialize("archive_fluffyExample") Pointrel_startTransaction() Pointrel_add("examplecontext", "Fluffy", "weight", "20kg") Pointrel_add("examplecontext", "Fluffy", "color", "beige") Pointrel_add("examplecontext", "Fluffy", "teeth", "pointy") Pointrel_add("examplecontext", "Fluffy", "teeth", "nasty") Pointrel_add("examplecontext", "Fluffy", "preferred food", "Knights who say 'Nie!'") Pointrel_finishTransaction() string = Pointrel_lastMatch("examplecontext", WILD, "weight", "20kg") print string # string would be --> "Fluffy" string = Pointrel_lastMatch("examplecontext", "Fluffy", "weight", WILD) print string # string would be --> "20kg" string = Pointrel_lastMatch("examplecontext", "Fluffy", "teeth", WILD) print string # string would be --> "nasty" list = Pointrel_allMatches("examplecontext", "Fluffy", "teeth", WILD) print list # list would be --> ["pointy", "nasty"] * What is a more complex example of using the Pointrel system? See the file "tkPointrelMemex.py". It implements a version of the Memex archiving system proposed by Vannevar Bush it the 1940s. To my knowledge, it is the first software implementation of something this close to his concept (technically, depending on how you read his work, his trails may be more like trees than the linear trails here). Feel free to send me pointers to earlier software implementations of MEMEX -- I will be happy to retract this claim in exchange for learning more of the history of his great idea. Here is a typical API useage for the more complex OO API: repository = PointrelDataRepositorySystem(archiveName) repository.startTransaction() repository.add(context, a, b, c) repository.finishTransaction() string = repository.lastMatch(context, WILD, b, c) string = repository.lastMatch(context, a, b, WILD) list = repository.allMatches(context, a, b, WILD) string = repository.generateUniqueID() * What is the license? BSDish. See license.txt for details. --Paul Fernhout http://www.pointrel.org -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! -----== Over 100,000 Newsgroups - 19 Different Servers! =----- From knight@baldmt.com Thu Aug 21 04:04:35 2003 From: knight@baldmt.com (Steven Knight) Date: Wed, 20 Aug 2003 22:04:35 -0500 (CDT) Subject: ANNOUNCE: SCons 0.92 fixes a potentially critical Win32 problem Message-ID: SCons is a software construction tool (build tool, or make tool) written in Python. It is based on the design which won the Software Carpentry build tool competition in August 2000. Version 0.92 of SCons has been released and is available for download from the SCons web site: http://www.scons.org/ Or through the download link at the SCons project page at SourceForge: http://sourceforge.net/projects/scons/ RPM and Debian packages and a Win32 installer are all available, in addition to the traditional .tar.gz and .zip files. WHAT'S NEW IN THIS RELEASE? Release 0.92 contains an important fix for a critical bug found shortly after SCons 0.91 was released, plus two other fixes. SCons 0.91 contains a bug that prevents SCons from working on Win32 systems unless either the Microsoft Visual Studio linker (link.exe) or the GCC linker is installed, or a custom-defined linker is used. This bug has been fixed in release 0.92. This bug does not cause incorrect builds and does not damage a source tree or build tree in any way. Anyone with either the Visual Studio or GCC linker installed on their Win32 system, or using a custom-defined linker, will never see this bug and could continue to use 0.91 without any serious repercussions or side effects. Release 0.92 contains two other fixes: - Support for the PharLap linker was not working properly in 0.91, and has been fixed. - When the YACC -o option was used to specify an output file with a different basename than the source file, SCons would mistakenly think that the basename of the generated .h file should match the source file, not the target file. This has been fixed. Additionally, the Debian (.deb) package available from the SCons web site or SourceForge project page has been updated to match the dependencies and other particulars of the (out of date) Debian package available from debian.org. In particular, the package is now dependent on Python 2.2 instead of Python 2.1. ABOUT SCONS Distinctive features of SCons include: - a global view of all dependencies; no multiple passes to get everything built properly - configuration files are Python scripts, allowing the full use of a real scripting language to solve difficult build problems - a modular architecture allows the SCons Build Engine to be embedded in other Python software - the ability to scan files for implicit dependencies (#include files); - improved parallel build (-j) support that provides consistent build speedup regardless of source tree layout - use of MD5 signatures to decide if a file has really changed; no need to "touch" files to fool make that something is up-to-date - easily extensible through user-defined Builder and Scanner objects - build actions can be Python code, as well as external commands An scons-users mailing list is available for those interested in getting started using SCons. You can subscribe at: http://lists.sourceforge.net/lists/listinfo/scons-users Alternatively, we invite you to subscribe to the low-volume scons-announce mailing list to receive notification when new versions of SCons become available: http://lists.sourceforge.net/lists/listinfo/scons-announce ACKNOWLEDGEMENTS Special thanks to Charles Crain, Gary Oberbrunner and Gerard Patel for their contributions to this release. On behalf of the SCons team, --SK From mcfletch@rogers.com Thu Aug 21 03:24:33 2003 From: mcfletch@rogers.com (Mike Fletcher) Date: Wed, 20 Aug 2003 22:24:33 -0400 Subject: Toronto-area Pythonistas meeting Tuesday the 26th of August... Message-ID: Since no-one seems to have announced this yet... PyGTA meeting this upcoming Tuesday at the regular time (8pm) and place (519 Comm. Centre (on Church St., in downtown Toronto)) See: http://web.engcorp.com/pygta/wiki/NextMeeting for details. Feel free to bring questions or problems to ask other Pythonistas about. We've been having good turnouts for the last few meetings, almost enough to overflow the rooms, so you don't have to just listen to Peter and I blathering on ;) . If you'd like to do a short presentation on your Python work please propose it on the pygta-general mailing list. Enjoy all, Mike _______________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://members.rogers.com/mcfletch/ From gregm@iname.com Fri Aug 22 14:10:06 2003 From: gregm@iname.com (Greg McFarlane) Date: Fri, 22 Aug 2003 23:10:06 +1000 Subject: ANNOUNCE: Pmw megawidgets 1.2 Message-ID: Pmw megawidgets for Tkinter Version 1.2 Greg McFarlane http://pmw.sourceforge.net/ --oOo-- A new release of Pmw is out. This release makes Pmw compatable with recent releases of python and Tcl/Tk. This version of Pmw was tested against python 2.3, Tcl/Tk 8.4.2 and Blt 2.4z. Except for Blt, all tests pass. Blt seems to be more flacky than usual, with core dumps occuring in the Graph code. Since this is a problem in Blt (not Pmw), the Blt test script has been removed from the default Pmw test sequence. Several other bug fixes and improvements were made. See the change log for details. To download Pmw or for more information, see the home page at http://pmw.sourceforge.net/ If you have any comments, enhancements or new contributions, please contact me (gregm@iname.com). ===================================================================== What is Pmw? Pmw is a toolkit for building high-level compound widgets, or megawidgets, constructed using other widgets as component parts. It promotes consistent look and feel within and between graphical applications, is highly configurable to your needs and is easy to use. It uses the Tkinter python library. Pmw consists of: - A few base classes, providing a foundation for building megawidgets. - A library of flexible and extensible megawidgets built on the base classes, such as buttonboxes, notebooks, comboboxes, selection widgets, paned widgets, scrolled widgets and dialog windows. - A lazy importer/dynamic loader which is automatically invoked when Pmw is first imported. This gives unified access to all Pmw classes and functions through the Pmw. prefix. It also speeds up module loading time by only importing Pmw sub-modules when needed. - Complete reference documentation, covering all classes and functions including all megawidgets and their options, methods and components. Helpful tutorial material is also available. - A test framework and tests for Pmw megawidgets. - A slick demonstration of the megawidgets. - An interface to the BLT busy, graph and vector commands. The interface to Pmw megawidgets is similar to basic Tk widgets, so it is easy for developers to include both megawidgets and basic Tk widgets in their graphical applications. In addition, Pmw megawidgets may themselves be extended, using either inheritance or composition. The use of the Pmw megawidgets replaces common widget combinations with higher level abstractions. This simplifies code, making it more readable and maintainable. The ability to extend Pmw megawidgets enables developers to create new megawidgets based on previous work. -- Greg McFarlane Really Good Software Pty Ltd Sydney Australia gregm@iname.com From theller@python.net Fri Aug 22 21:18:30 2003 From: theller@python.net (Thomas Heller) Date: Fri, 22 Aug 2003 22:18:30 +0200 Subject: New py2exe binary distribution for Python 2.3 Message-ID: Unfortunately, the py2exe binary distribution, version 0.4.1, contained broken binaries for Python 2.3, for building Windows NT services. I've uploaded a new binary installer for Python 2.3 only, and changed the version number to 0.4.2. If you are still using Python 2.2, there's no need to change anything. Enjoy, Thomas From mj@zope.com Fri Aug 22 20:08:33 2003 From: mj@zope.com (Martijn Pieters) Date: Fri, 22 Aug 2003 15:08:33 -0400 Subject: @python.org and @zope.org email troubles Message-ID: Thanks to the enormously proliferant W32.Sobig.F, the mail.python.org email server has been having real trouble dealing with the flood of email pounding on it's ports. We are currently hard at work trying to bring the mailserver back to sanity again, and you should be seeing email emerge again, although it may take some time still before things will be back to normal operation. In the meantime, we apologize for the inconvenience. -- Martijn Pieters | Software Engineer mailto:mj@zope.com | Zope Corporation http://www.zope.com/ | Creators of Zope http://www.zope.org/ --------------------------------------------- From anthony@computronix.com Fri Aug 22 18:02:45 2003 From: anthony@computronix.com (Anthony Tuininga) Date: 22 Aug 2003 11:02:45 -0600 Subject: cx_Oracle 3.1 Message-ID: What is cx_Oracle? cx_Oracle is a Python extension module that allows access to Oracle and conforms to the Python database API 2.0 specifications with a few exceptions. Where do I get it? http://starship.python.net/crew/atuining http://www.computronix.com/utilities.shtml (it may be a few days before the second site is updated) What's new? 1) Added support for connecting with SYSDBA and SYSOPER access which is needed for connecting as sys in Oracle 9i. 2) Only check the dictionary size if the variable is not NULL; otherwise, an error takes place which is not caught or cleared; this eliminates a spurious "Objects/dictobject.c:1258: bad argument to internal function" in Python 2.3. 3) Add support for session pooling. This is only support for Oracle 9i but is amazingly fast -- about 100 times faster than connecting. 4) Add support for statement caching when pooling sessions, this reduces the parse time considerably. Unfortunately, the Oracle OCI does not allow this to be easily turned on for normal sessions. 5) Add method trim() on CLOB and BLOB variables for trimming the size. 6) Add support for externally identified users; to use this feature leave the username and password fields empty when connecting. 7) Add method cancel() on connection objects to cancel long running queries. Note that this only works on non-Windows platforms. 8) Add method callfunc() on cursor objects to allow calling a function without using an anonymous PL/SQL block. 9) Added documentation on objects that were not documented. At this point all objects, methods and constants in cx_Oracle have been documented. 10) Added support for timestamp columns in Oracle 9i. 11) Added module level method makedsn() which creates a data source name given the host, port and SID. 12) Added constant "buildtime" which is the time when the module was built as an additional means of identifying the build that is in use. 13) Binding a value that is incompatible to the previous value that was bound (data types do not match or array size is larger) will now result in a new bind taking place. This is more consistent with the DB API although it does imply a performance penalty when used. -- Anthony Tuininga anthony@computronix.com Computronix Distinctive Software. Real People. Suite 200, 10216 - 124 Street NW Edmonton, AB, Canada T5N 4A3 Phone: (780) 454-3700 Fax: (780) 454-3838 http://www.computronix.com From cochrane@physics.uq.edu.au Wed Aug 20 05:26:56 2003 From: cochrane@physics.uq.edu.au (cochrane) Date: 20 Aug 2003 04:26:56 GMT Subject: ANN: PyScript 0.4 Message-ID: PyScript 0.4 has just been released! Get it from http://pyscript.sourceforge.net Here is the README: =============== pyscript =============== -------------------------------------------------------------------- Summary -------------------------------------------------------------------- Pyscript is a set of modules and scripts for python that facilitate the creation of high-quality postscript diagrams. The diagrams are scripted rather than drawn. See http://pyscript.sourceforge.net -------------------------------------------------------------------- Instalation -------------------------------------------------------------------- Pyscript is just a python module ... treat it as any other module * Global Instalation As root use > python setup.py install This will install the files, in the appropriate place for your python distribution. This will be something like e.g. /usr/lib/python2.2/site-packages/ * Local instalation: You can supply the base directory using > python setup.py install --home= which will install the files in /lib/python/ for more help and options use > python setup.py install --help also see http://www.python.org/doc/current/inst/ for more details on using the distutils package * By hand copy all the files in the pyscript directory to somewhere in your python path eg cp -r pyscript ~/lib/python/ From bill@unbrandamerica.org Sun Aug 24 10:25:37 2003 From: bill@unbrandamerica.org (bill@unbrandamerica.org) Date: Sun, 24 Aug 2003 09:25:37 GMT Subject: Unbrand America Message-ID: <5b9eb617.35f4749f@unbrandamerica.org> This is a multi-part message in MIME format. --60232383033440286572667710686763763601150348440633 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit In the coming months a black spot will pop up everywhere . . . on store windows and newspaper boxes, on gas pumps and supermarket shelves. Open a magazine or newspaper - it's there. It's on TV. It stains the logos and smears the nerve centers of the world's biggest, dirtiest corporations. This is the mark of the people who don't approve of Bush's plan to control the world, who don't want countries "liberated" without UN backing, who can't stand anymore neo-con bravado shoved down their throats. This is the mark of the people who want the Kyoto Protocol for the environment, who want the International Criminal Court for greater justice, who want a world where all nations, including the U.S.A., are free of weapons of mass destruction, and who pledge to take their country back. -- Some hot painters before the clean highway were solving around the open dorm. --60232383033440286572667710686763763601150348440633 Content-type: text/html; name="xlu.htm" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="xlu.htm" Unbrand America
Adbusters
CampaignsMagazineCreative ResistanceOrders Information


In the coming months a black spot will pop up everywhere . . . on store windows and newspaper boxes, on gas pumps and supermarket shelves. Open a magazine or newspaper - it's there. It's on TV. It stains the logos and smears the nerve centers of the world's biggest, dirtiest corporations.

This is the mark of the people who don't approve of Bush's plan to control the world, who don't want countries "liberated" without UN backing, who can't stand anymore neo-con bravado shoved down their throats.

This is the mark of the people who want the Kyoto Protocol for the environment, who want the International Criminal Court for greater justice, who want a world where all nations, including the U.S.A., are free of weapons of mass destruction, and who pledge to take their country back.

--60232383033440286572667710686763763601150348440633-- this story on TV he had called someone earlier. He told me I have to either sleep around or get marry with a jewish girl like one from his family. Anyway in the later episode I was told by someone that channel 7 and 9 are run by Pro-Israeli Jews who are the richest people in this country. These people support their cause and are well aware of authorities committed by Jews and Jewish Muslims. Apparently it is these people who fund them here in Australia. I have also been told that Israel has deliberately introduced the decease of sleep around in Muslims. I was told that specialized people are train and sent in Muslim areas who then sleep around with Muslim men and women, specially with Muslim women, thanks to drugs and secret services, and those who do not sleep around are forced to sleep around and harassed. The reason this is done is because those who do not sleep around will one day apparently worry about Palestine issue and Islam as they have potential of becoming a good Muslim. So when they sleep around they just move on to other things and live a corrupt life. And it is the Muslim woman who will bring up the next generation so she needs to be corrupted to destroy the faith and family structure. I don?t know I guess Israelies are doing the job of Satan here, I don?t think Satan need to be around considering the amount of work these people are doing. When we Muslims were in control we did not corrupt your religion we protected it and did justice. But anyway insha?Allah things are going to change soon anyway. (More knowledge to follow insha?Allah) This Abu Omar is still at large and is probably living in Hoppers crossing, don?t be scared of this man and don? l From amk@nyman.amk.ca Sun Aug 24 09:38:55 2003 From: amk@nyman.amk.ca (amk@nyman.amk.ca) Date: Sun, 24 Aug 2003 04:38:55 -0400 Subject: Python Library & Extension FAQ Message-ID: This is the last of the new FAQ files assembled from the old 240K FAQ. As usual, comments on existing answers and suggestions for new questions are welcome. --amk ==================================== Python Library and Extension FAQ ==================================== :Date: $Date: 2003/08/19 20:42:47 $ :Version: $Revision: 1.9 $ :Web site: http://www.python.org/ .. contents:: .. sectnum:: General Library Questions =============================== How do I find a module or application to perform task X? ------------------------------------------------------------- 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 able to skip this step.) Search the `Python Package Index `_. Next, check the `Vaults of Parnassus `_, an older index of packages. Finally, try `Google `_ or other Web search engine. Searching for "Python" plus a keyword or two for your topic of interest will usually find something helpful. Where is the math.py (socket.py, regex.py, etc.) source file? --------------------------------------------------------------------- If you can't find a source file for a module it may be a builtin 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: 1) modules written in Python (.py); 2) modules written in C and dynamically loaded (.dll, .pyd, .so, .sl, etc); 3) modules written in C and linked with the interpreter; to get a list of these, type:: import sys print sys.builtin_module_names How do I make a Python script executable on Unix? --------------------------------------------------------- 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 *Don't* do this for CGI scripts. The $PATH variable for CGI scripts is often very minimal, so you need to use the actual absolute pathname of the interpreter. Occasionally, a user's environment is so full that the /usr/bin/env program fails; or there's no env program at all. In that case, you can try the following hack (due to Alex Rezinsky):: #! /bin/sh """:" exec python $0 ${1+"$@"} """ The minor disadvantage is that this defines the script's __doc__ string. However, you can fix that by adding :: __doc__ = """...Whatever...""" Is there a curses/termcap package for Python? ---------------------------------------------------- For Unix variants: The standard Python source distribution comes with a curses module in the Modules/ subdirectory, though it's not compiled by default (note that this is not available in the Windows distribution -- there is no curses module for Windows). The curses module supports basic curses features as well as many additional functions from ncurses and SYSV curses such as colour, alternative character set support, pads, and mouse support. This means the module isn't compatible with operating systems that only have BSD curses, but there don't seem to be any currently maintained OSes that fall into this category. For Windows: use `the consolelib module `_. Is there an equivalent to C's onexit() in Python? -------------------------------------------------------- `The atexit module `_ provides a register function that is similar to C's onexit. Why don't my signal handlers work? -------------------------------------------- The most common problem is that the signal handler is declared with the wrong argument list. It is called as :: handler(signum, frame) so it should be declared with two arguments:: def handler(signum, frame): ... Common tasks ================= How do I test a Python program or component? ---------------------------------------------------- Python comes with two testing frameworks. The `doctest module `_ finds examples in the docstrings for a module and runs them, comparing the output with the expected output given in the docstring. The `unittest module `_ is a fancier testing framework modelled on Java and Smalltalk testing frameworks. For testing, it helps to write the program so that it may be easily tested by using good modular design. Your program should have almost all functionality encapsulated in either functions or class methods -- and this sometimes has the surprising and delightful effect of making the program run faster (because local variable accesses are faster than global accesses). Furthermore the program should avoid depending on mutating global variables, since this makes testing much more difficult to do. The "global main logic" of your program may be as simple as :: if __name__=="__main__": main_logic() at the bottom of the main module of your program. Once your program is organized as a tractable collection of functions and class behaviours you should write test functions that exercise the behaviours. A test suite can be associated with each module which automates a sequence of tests. This sounds like a lot of work, but since Python is so terse and flexible it's surprisingly easy. You can make coding much more pleasant and fun by writing your test functions in parallel with the "production code", since this makes it easy to find bugs and even design flaws earlier. "Support modules" that are not intended to be the main module of a program may include a self-test of the module. :: if __name__ == "__main__": self_test() Even programs that interact with complex external interfaces may be tested when the external interfaces are unavailable by using "fake" interfaces implemented in Python. How do I create documentation from doc strings? ------------------------------------------------------- The `pydoc module `_ can create HTML from the doc strings in your Python source code. An alternative is `pythondoc `_. How do I get a single keypress at a time? ----------------------------------------------- For Unix variants:There are several solutions. It's straightforward to do this using curses, but curses is a fairly large module to learn. Here's a solution without curses:: import termios, fcntl, sys, os fd = sys.stdin.fileno() oldterm = termios.tcgetattr(fd) newattr = termios.tcgetattr(fd) newattr[3] = newattr[3] & ~termios.ICANON & ~termios.ECHO termios.tcsetattr(fd, termios.TCSANOW, newattr) oldflags = fcntl.fcntl(fd, fcntl.F_GETFL) fcntl.fcntl(fd, fcntl.F_SETFL, oldflags | os.O_NONBLOCK) try: while 1: try: c = sys.stdin.read(1) print "Got character", `c` except IOError: pass finally: termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm) fcntl.fcntl(fd, fcntl.F_SETFL, oldflags) You need the ``termios`` and the ``fcntl`` module for any of this to work, and I've only tried it on Linux, though it should work elsewhere. In this code, characters are read and printed one at a time. ``termios.tcsetattr()`` turns off stdin's echoing and disables canonical mode. ``fcntl.fnctl()`` is used to obtain stdin's file descriptor flags and modify them for non-blocking mode. Since reading stdin when it is empty results in an ``IOError``, this error is caught and ignored. Threads ============= How do I program using threads? --------------------------------- Be sure to use `the threading module `_ and not the ``thread`` module. The ``threading`` module builds convenient abstractions on top of the low-level primitives provided by the ``thread`` module. Aahz has a set of slides from his threading tutorial that are helpful; see http://starship.python.net/crew/aahz/OSCON2001/. None of my threads seem to run: why? ------------------------------------------- As soon as the main thread exits, all threads are killed. Your main thread is running too quickly, giving the threads no time to do any work. A simple fix is to add a sleep to the end of the program that's long enough for all the threads to finish:: import threading, time def thread_task(name, n): for i in range(n): print name, i for i in range(10): T = threading.Thread(target=thread_task, args=(str(i), i)) T.run() time.sleep(10) # <----------------------------! But now (on many platforms) the threads don't run in parallel, but appear to run sequentially, one at a time! The reason is that the OS thread scheduler doesn't start a new thread until the previous thread is blocked. A simple fix is to add a tiny sleep to the start of the run function:: def thread_task(name, n): time.sleep(0.001) # <---------------------! for i in range(n): print name, i for i in range(10): T = threading.Thread(target=thread_task, args=(str(i), i)) T.run() time.sleep(10) Instead of trying to guess how long a ``time.sleep()`` delay will be enough, it's better to use some kind of semaphore mechanism. One idea is to use the `Queue module `_ to create a queue object, let each thread append a token to the queue when it finishes, and let the main thread read as many tokens from the queue as there are threads. How do I parcel out work among a bunch of worker threads? ---------------------------------------------------------------- Use the `Queue module `_ to create a queue containing a list of jobs. The ``Queue`` class maintains a list of objects with ``.put(obj)`` to add an item to the queue and ``.get()`` to return an item. The class will take care of the locking necessary to ensure that each job is handed out exactly once. Here's a trivial example:: import threading, Queue, time # The worker thread gets jobs off the queue. When the queue is empty, it # assumes there will be no more work and exits. # (Realistically workers will run until terminated.) def worker (): print 'Running worker' time.sleep(0.1) while True: try: arg = q.get(block=False) except Queue.Empty: print 'Worker', threading.currentThread(), print 'queue empty' break else: print 'Worker', threading.currentThread(), print 'running with argument', arg time.sleep(0.5) # Create queue q = Queue.Queue() # Start a pool of 5 workers for i in range(5): t = threading.Thread(target=worker, name='worker %i' % (i+1)) t.start() # Begin adding work to the queue for i in range(50): q.put(i) # Give threads time to run print 'Main thread sleeping' time.sleep(5) When run, this will produce the following output: Running worker Running worker Running worker Running worker Running worker Main thread sleeping Worker running with argument 0 Worker running with argument 1 Worker running with argument 2 Worker running with argument 3 Worker running with argument 4 Worker running with argument 5 ... Consult the module's documentation for more details; the ``Queue`` class provides a featureful interface. What kinds of global value mutation are thread-safe? ------------------------------------------------------------ A global interpreter lock (GIL) is used internally to ensure that only one thread runs in the Python VM at a time. In general, Python offers to switch among threads only between bytecode instructions; how frequently it switches can be set via ``sys.setcheckinterval()``. Each bytecode instruction and therefore all the C implementation code reached from each instruction is therefore atomic from the point of view of a Python program. In theory, this means an exact accounting requires an exact understanding of the PVM bytecode implementation. In practice, it means that operations on shared variables of builtin data types (ints, lists, dicts, etc) that "look atomic" really are. For example, the following operations are all atomic (L, L1, L2 are lists, D, D1, D2 are dicts, x, y are objects, i, j are ints):: L.append(x) L1.extend(L2) x = L[i] x = L.pop() L1[i:j] = L2 L.sort() x = y x.field = y D[x] = y D1.update(D2) D.keys() These aren't:: i = i+1 L.append(L[-1]) L[i] = L[j] D[x] = D[x] + 1 Operations that replace other objects may invoke those other objects' ``__del__`` method when their reference count reaches zero, and that can affect things. This is especially true for the mass updates to dictionaries and lists. When in doubt, use a mutex! Can't we get rid of the Global Interpreter Lock? -------------------------------------------------------- The Global Interpreter Lock (GIL) is often seen as a hindrance to Python's deployment on high-end multiprocessor server machines, because a multi-threaded Python program effectively only uses one CPU, due to the insistence that (almost) all Python code can only run while the GIL is held. Back in the days of Python 1.5, Greg Stein actually implemented a comprehensive patch set (the "free threading" patches) that removed the GIL and replaced it with fine-grained locking. Unfortunately, even on Windows (where locks are very efficient) this ran ordinary Python code about twice as slow as the interpreter using the GIL. On Linux the performance loss was even worse because pthread locks aren't as efficient. Since then, the idea of getting rid of the GIL has occasionally come up but nobody has found a way to deal with the expected slowdown, and users who don't use threads would not be happy if their code ran at half at the speed. Greg's free threading patch set has not been kept up-to-date for later Python versions. This doesn't mean that you can't make good use of Python on multi-CPU machines! You just have to be creative with dividing the work up between multiple *processes* rather than multiple *threads*. Judicious use of C extensions will also help; if you use a C extension to perform a time-consuming task, the extension can release the GIL while the thread of execution is in the C code and allow other threads to get some work done. It has been suggested that the GIL should be a per-interpreter-state lock rather than truly global; interpreters then wouldn't be able to share objects. Unfortunately, this isn't likely to happen either. It would be a tremendous amount of work, because many object implementations currently have global state. For example, small integers and short strings are cached; these caches would have to be moved to the interpreter state. Other object types have their own free list; these free lists would have to be moved to the interpreter state. And so on. And I doubt that it can even be done in finite time, because the same problem exists for 3rd party extensions. It is likely that 3rd party extensions are being written at a faster rate than you can convert them to store all their global state in the interpreter state. And finally, once you have multiple interpreters not sharing any state, what have you gained over running each interpreter in a separate process? Input and Output ========================= How do I delete a file? (And other file questions...) --------------------------------------------------------- Use ``os.remove(filename)`` or ``os.unlink(filename)``; for documentation, see `the POSIX module `_. The two functions are identical; ``unlink()`` is simply the name of the Unix system call for this function. To remove a directory, use ``os.rmdir()``; use ``os.mkdir()`` to create one. ``os.makedirs(path)`` will create any intermediate directories in ``path`` that don't exist. ``os.removedirs(path)`` will remove intermediate directories as long as they're empty; if you want to delete an entire directory tree and its contents, use ``shutil.rmtree()``. To rename a file, use ``os.rename(old_path, new_path)``. To truncate a file, open it using ``f = open(filename, "r+")``, and use ``f.truncate(offset)``; offset defaults to the current seek position. There's also ```os.ftruncate(fd, offset)`` for files opened with ``os.open()``, where ``fd`` is the file descriptor (a small integer). The ``shutil`` module also contains a number of functions to work on files including ``copyfile``, ``copytree``, and ``rmtree``. How do I copy a file? ----------------------------- The ``shutil`` module contains a ``copyfile()`` function. Note that on MacOS 9 it doesn't copy the resource fork and Finder info. How do I read (or write) binary data? --------------------------------------------- or complex data formats, it's best to use `the struct module `_. It allows you to take a string containing binary data (usually numbers) and convert it to Python objects; and vice versa. For example, the following code reads two 2-byte integers and one 4-byte integer in big-endian format from a file:: import struct f = open(filename, "rb") # Open in binary mode for portability s = f.read(8) x, y, z = struct.unpack(">hhl", s) The '>' in the format string forces big-endian data; the letter 'h' reads one "short integer" (2 bytes), and 'l' reads one "long integer" (4 bytes) from the string. For data that is more regular (e.g. a homogeneous list of ints or thefloats), you can also use `the array module `_. I can't seem to use os.read() on a pipe created with os.popen(); why? ------------------------------------------------------------------------ ``os.read()`` is a low-level function which takes a file descriptor, a small integer representing the opened file. ``os.popen()`` creates a high-level file object, the same type returned by the builtin ``open()`` function. Thus, to read n bytes from a pipe p created with ``os.popen()``, you need to use ``p.read(n)``. How do I run a subprocess with pipes connected to both input and output? -------------------------------------------------------------------------------- Use `the popen2 module `_. For example:: import popen2 fromchild, tochild = popen2.popen2("command") tochild.write("input\n") tochild.flush() output = fromchild.readline() Warning: in general it is unwise to do this because you can easily cause a deadlock where your process is blocked waiting for output from the child while the child is blocked waiting for input from you. This can be caused because the parent expects the child to output more text than it does, or it can be caused by data being stuck in stdio buffers due to lack of flushing. The Python parent can of course explicitly flush the data it sends to the child before it reads any output, but if the child is a naive C program it may have been written to never explicitly flush its output, even if it is interactive, since flushing is normally automatic. Note that a deadlock is also possible if you use ``popen3`` to read stdout and stderr. If one of the two is too large for the internal buffer (increasing the buffer size does not help) and you ``read()`` the other one first, there is a deadlock, too. Note on a bug in popen2: unless your program calls ``wait()`` or ``waitpid()``, finished child processes are never removed, and eventually calls to popen2 will fail because of a limit on the number of child processes. Calling ``os.waitpid`` with the ``os.WNOHANG`` option can prevent this; a good place to insert such a call would be before calling ``popen2`` again. In many cases, all you really need is to run some data through a command and get the result back. Unless the amount of data is very large, the easiest way to do this is to write it to a temporary file and run the command with that temporary file as input. The `standard module tempfile `_ exports a ``mktemp()`` function to generate unique temporary file names. :: import tempfile import os class Popen3: """ This is a deadlock-safe version of popen that returns an object with errorlevel, out (a string) and err (a string). (capturestderr may not work under windows.) Example: print Popen3('grep spam','\n\nhere spam\n\n').out """ def __init__(self,command,input=None,capturestderr=None): outfile=tempfile.mktemp() command="( %s ) > %s" % (command,outfile) if input: infile=tempfile.mktemp() open(infile,"w").write(input) command=command+" <"+infile if capturestderr: errfile=tempfile.mktemp() command=command+" 2>"+errfile self.errorlevel=os.system(command) >> 8 self.out=open(outfile,"r").read() os.remove(outfile) if input: os.remove(infile) if capturestderr: self.err=open(errfile,"r").read() os.remove(errfile) Note that many interactive programs (e.g. vi) don't work well with pipes substituted for standard input and output. You will have to use pseudo ttys ("ptys") instead of pipes. Or you can use a Python interface to Don Libes' "expect" library. A Python extension that interfaces to expect is called "expy" and available from http://expectpy.sourceforge.net. A pure Python solution that works like expect is ` pexpect `_. How do I access the serial (RS232) port? ------------------------------------------------ For Win32, POSIX (Linux, BSD, etc.), Jython: http://pyserial.sourceforge.net For Unix, see a Usenet post by Mitch Chapman: http://groups.google.com/groups?selm=34A04430.CF9@ohioee.com Why doesn't closing sys.stdout (stdin, stderr) really close it? ----------------------------------------------------------------------- Python file objects are a high-level layer of abstraction on top of C streams, which in turn are a medium-level layer of abstraction on top of (among other things) low-level C file descriptors. For most file objects you create in Python via the builtin ``file`` constructor, ``f.close()`` marks the Python file object as being closed from Python's point of view, and also arranges to close the underlying C stream. This also happens automatically in f's destructor, when f becomes garbage. But stdin, stdout and stderr are treated specially by Python, because of the special status also given to them by C. Running ``sys.stdout.close()`` marks the Python-level file object as being closed, but does *not* close the associated C stream. To close the underlying C stream for one of these three, you should first be sure that's what you really want to do (e.g., you may confuse extension modules trying to do I/O). If it is, use os.close:: os.close(0) # close C's stdin stream os.close(1) # close C's stdout stream os.close(2) # close C's stderr stream Network/Internet Programming ======================================= What WWW tools are there for Python? -------------------------------------------- See the chapters titled `"Internet Protocols and Support" `_ and `"Internet Data Handling" `_ in the Library Reference Manual. Python has many modules that will help you build server-side and client-side web systems. A summary of available frameworks is maintained by Paul Boddie at http://www.python.org/cgi-bin/moinmoin/WebProgramming . Cameron Laird maintains a useful set of pages about Python web technologies at http://starbase.neosoft.com/~claird/comp.lang.python/web_python.html The `Web Programming topic guide `_ also points to many useful resources. How can I mimic CGI form submission (METHOD=POST)? ---------------------------------------------------------- I would like to retrieve web pages that are the result of POSTing a form. Is there existing code that would let me do this easily? Yes. Here's a simple example that uses httplib:: #!/usr/local/bin/python import httplib, sys, time ### build the query string qs = "First=Josephine&MI=Q&Last=Public" ### connect and send the server a path httpobj = httplib.HTTP('www.some-server.out-there', 80) httpobj.putrequest('POST', '/cgi-bin/some-cgi-script') ### now generate the rest of the HTTP headers... httpobj.putheader('Accept', '*/*') httpobj.putheader('Connection', 'Keep-Alive') httpobj.putheader('Content-type', 'application/x-www-form-urlencoded') httpobj.putheader('Content-length', '%d' % len(qs)) httpobj.endheaders() httpobj.send(qs) ### find out what the server said in response... reply, msg, hdrs = httpobj.getreply() if reply != 200: sys.stdout.write(httpobj.getfile().read()) Note that in general for URL-encoded POST operations, query strings must be quoted by using ``urllib.quote()``. For example to send name="Guy Steele, Jr.":: >>> from urllib import quote >>> x = quote("Guy Steele, Jr.") >>> x 'Guy%20Steele,%20Jr.' >>> query_string = "name="+x >>> query_string 'name=Guy%20Steele,%20Jr.' What module should I use to help with generating HTML? -------------------------------------------------------------- There are many different modules available: * HTMLgen is a class library of objects corresponding to all the HTML 3.2 markup tags. It's used when you are writing in Python and wish to synthesize HTML pages for generating a web or for CGI forms, etc. * DocumentTemplate and Zope Page Templates are two different systems that are part of Zope. * Quixote's PTL uses Python syntax to assemble strings of text. Consult the `Web Programming topic guide `_ for more links. How do I send mail from a Python script? ------------------------------------------------ Use `the standard library module smtplib `_. Here's a very simple interactive mail sender that uses it. This method will work on any host that supports an SMTP listener. :: import sys, smtplib fromaddr = raw_input("From: ") toaddrs = raw_input("To: ").split(',') print "Enter message, end with ^D:" msg = '' while 1: line = sys.stdin.readline() if not line: break msg = msg + line # The actual mail send server = smtplib.SMTP('localhost') server.sendmail(fromaddr, toaddrs, msg) server.quit() A Unix-only alternative uses sendmail. The location of the sendmail program varies between systems; sometimes it is ``/usr/lib/sendmail``, sometime ``/usr/sbin/sendmail``. The sendmail manual page will help you out. Here's some sample code:: SENDMAIL = "/usr/sbin/sendmail" # sendmail location import os p = os.popen("%s -t -i" % SENDMAIL, "w") p.write("To: receiver@example.com\n") p.write("Subject: test\n") p.write("\n") # blank line separating headers from body p.write("Some text\n") p.write("some more text\n") sts = p.close() if sts != 0: print "Sendmail exit status", sts How do I avoid blocking in the connect() method of a socket? -------------------------------------------------------------------------- The select module is commonly used to help with asynchronous I/O on sockets. To prevent the TCP connect from blocking, you can set the socket to non-blocking mode. Then when you do the ``connect()``, you will either connect immediately (unlikely) or get an exception that contains the error number as ``.errno``. ``errno.EINPROGRESS`` indicates that the connection is in progress, but hasn't finished yet. Different OSes will return different values, so you're going to have to check what's returned on your system. You can use the ``connect_ex()`` method to avoid creating an exception. It will just return the errno value. To poll, you can call ``connect_ex()`` again later -- 0 or ``errno.EISCONN`` indicate that you're connected -- or you can pass this socket to select to check if it's writeable. Databases ===================== Are there any interfaces to database packages in Python? ---------------------------------------------------------------- Yes. Python 2.3 includes the ``bsddb`` package which provides an interface to the `BerkeleyDB `_ library. Interfaces to disk-based hashes such as `DBM `_ and `GDBM `_ are also included with standard Python. Support for most relational databases is available. See the `Database Topic Guide `_ for details. How do you implement persistent objects in Python? ------------------------------------------------------------ The `pickle library module `_ solves this in a very general way (though you still can't store things like open files, sockets or windows), and the `shelve library module `_ uses pickle and (g)dbm to create persistent mappings containing arbitrary Python objects. For better performance, you can use `the cPickle module `_. A more awkward way of doing things is to use pickle's little sister, marshal. `The marshal module `_ provides very fast ways to store noncircular basic Python types to files and strings, and back again. Although marshal does not do fancy things like store instances or handle shared references properly, it does run extremely fast. For example loading a half megabyte of data may take less than a third of a second. This often beats doing something more complex and general such as using gdbm with pickle/shelve. Why is cPickle so slow? -------------------------------- The default format used by the pickle module is a slow one that results in readable pickles. Making it the default, but it would break backward compatibility:: largeString = 'z' * (100 * 1024) myPickle = cPickle.dumps(largeString, protocol=1) If my program crashes with a bsddb (or anydbm) database open, it gets corrupted. How come? -------------------------------------------------------------------------------------------------- Databases opened for write access with the bsddb module (and often by the anydbm module, since it will preferentially use bsddb) must explicitly be closed using the ``.close()`` method of the database. The underlying library caches database contents which need to be converted to on-disk form and written. If you have initialized a new bsddb database but not written anything to it before the program crashes, you will often wind up with a zero-length file and encounter an exception the next time the file is opened. I tried to open Berkeley DB file, but bsddb produces bsddb.error: (22, 'Invalid argument'). Help! How can I restore my data? ------------------------------------------------------------------------------------------------------------------------------------ Don't panic! Your data is probably intact. The most frequent cause for the error is that you tried to open an earlier Berkeley DB file with a later version of the Berkeley DB library. Many Linux systems now have all three versions of Berkeley DB available. If you are migrating from version 1 to a newer version use db_dump185 to dump a plain text version of the database. If you are migrating from version 2 to version 3 use db2_dump to create a plain text version of the database. In either case, use db_load to create a new native database for the latest version installed on your computer. If you have version 3 of Berkeley DB installed, you should be able to use db2_load to create a native version 2 database. You should move away from Berkeley DB version 1 files because the hash file code contains known bugs that can corrupt your data. Mathematics and Numerics ================================ How do I generate random numbers in Python? --------------------------------------------------- The `standard module random `_ implements a random number generator. Usage is simple:: import random random.random() This returns a random floating point number in the range [0, 1). There are also many other specialized generators in this module, such as: * ``randrange(a, b)`` chooses an integer in the range [a, b). * ``uniform(a, b)`` chooses a floating point number in the range [a, b). * ``normalvariate(mean, sdev)`` samples the normal (Gaussian) distribution. Some higher-level functions operate on sequences directly, such as: * ``choice(S)`` chooses random element from a given sequence * ``shuffle(L)`` shuffles a list in-place, i.e. permutes it randomly There's also a ``Random`` class you can instantiate to create independent multiple random number generators. From remi@cherrypy.org Wed Aug 27 10:43:19 2003 From: remi@cherrypy.org (Remi Delon) Date: 27 Aug 2003 02:43:19 -0700 Subject: CherryPy-0.9-gamma released Message-ID: Hello everyone, I am pleased to announce the release of CherryPy-0.9-gamma. This release includes a new thread-pool server, sessions that works, the ability to store session data in a database and many bugfixes and improvements. ------------------------------------------ About CherryPy: CherryPy is a Python-based web application development toolkit: libraries and compiler. It allows us to build web applications in Python in much the same way we would build an other Python program. CherryPy has been used in production for more than a year and it has proven fast and robust. Remi. http://www.cherrypy.org From Raymond Hettinger" Sourceforge is used to track bug reports, feature requests, and patches: https://sourceforge.net/projects/python/ Each of those submissions needs to be reviewed and discussed. A good way to participate in python development is to spend some time adding useful comments to each report. Bug reports ------------ * Sometimes the OP thinks a bug is present when, in fact, Python is behaving as intended. It is useful to gently steer them in the right direction, correct their understanding, and have them close the bug report. * Sometimes the bug is unique to OP's own environment and it is helpful to have another person confirm the bug on another machine. * Often, a bug report is inadequately specific -- "My 200 line script doesn't work". Help is needed to refine the report to the simplest possible demonstration of the error: bool("False")!=False. * It is even more helpful to specifically identify where the error is occurring in the source: line 200 in textwrap.py has an and/or problem. * In many cases, discussion is necessary to ascertain whether the behavior is truly a bug, a documentation issue, or a natural byproduct of other important invariants. * It is also helpful to suggest alternative solutions and discuss the implications of each. Patches -------- * The simplest checks are: - does it work - does it have unittests - does it have a doc patch * More advanced considerations: - are there subtle code breakages (one man's bug is another's feature) - is the change desirable - would a refactoring have simplified the problem - are there unintended consequences - is there a better alternative solution Feature Requests ------------------- The basic idea here is to see whether life would truly be better if the idea were adopted. Considerations include the minimizing the rate of language growth, ease of implementation, how it fits in with the rest of the language, and the existence of practice use cases. Readers of comp.lang.python are also in a good position to make comments on the idea and how it fits in with stated Python design goals. For example, IDLE could easily grow macros, RCS buttons, templates and such, but its design goal is to be a relatively simple yet complete, portable editor/ide written in pure python -- this means that grandiose ideas to transform it into emacs will likely not be accepted. The presence of a feature in another language is neither cause for acceptance or rejection. Just because Perl, PHP, VB, or Ruby does something, it is not necessarily good or necessarily bad. It does at least provide a proof-of-concept and real world experience with the feature so that we can learn from its successes or failures. The itertools module was designed to capture some of the successes in Haskell and ML. Raymond Hettinger From jcribbs@twmi.rr.com Wed Aug 27 19:53:12 2003 From: jcribbs@twmi.rr.com (Jamey Cribbs) Date: Wed, 27 Aug 2003 18:53:12 GMT Subject: ANNOUNCE: KirbyBase 1.4 Message-ID: KirbyBase 1.4 is now available at: http://www.netpromi.com/files/KirbyBase-1.4.zip What is KirbyBase? KirbyBase is a simple, pure-Python, plain-text, flat-file database management system that can be used either embedded in your application or in a client/server, multi-user mode. To find out more about KirbyBase, go to: http://www.netpromi.com/kirbybase.html Changes: Added two new database field types: datetime.date and datetime.datetime. They are stored as strings, but are input and output as instances of datetime.date and datetime.datetime respectively. You can use them just like any other field: you can use them as selection criteria (i.e. db.select('plane.tbl', ['began_service'], ['>=%s' % datetime.date(1937,12,31)) or use them to specify the sort order of the result set of a select statement (i.e. db.select('plane.tbl', ['name'], ['.*'], sortField='range', ascending=False)). Made a few internal optimizations when running queries that have resulted in a 15-20% speed increase when doing large queries or updates. Changed the name of all private methods from starting with two underscores to starting with one underscore based on a discussion in comp.lang.python as to how to properly name private variables. From alexander.dejanovski@laposte.net Wed Aug 27 19:42:11 2003 From: alexander.dejanovski@laposte.net (Alexander DEJANOVSKI) Date: Wed, 27 Aug 2003 20:42:11 +0200 Subject: Retic EAI Server 0.3.2 Released - SQLTreeSource included. Message-ID: I've released a new version of Retic with new components : - Pipes : XPathPipe and FlatToXMLPipe - Source : SQLTreeSource (permits to build complex XML documents from several SQL requests). The Designer is now fully working and supports all components of the current Retic release. It is available on sourceforge : http://sourceforge.net/projects/retic =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D WHAT IS RETIC ? Retic is an EAI Server. The aim is to permit applications to communicate, even if they don't speak the same language (which means transport protocols as well as data structures). This is done by building adaptors. An adaptor is composed of : - One source - Several pipes (process data transformations) - Several sinks (destination of data) - Several loggers (using the logging module of python 2.3) =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D ABOUT THE SQLTreeSource COMPONENT: Sometimes (well, might even be more than that) you need to get more than a bunch of rows from a table translated to XML. You need a whole structured XML document with a complex and deep architecture. The SQLTreeSource is what you need then. It permits to describe an XML tree, each node being the result of an SQL statement. Here's an example : Here is the XML output of the source described above : 1 1 ite_1 1.6 07/04/2003 Mise en recette Valo 2003-04-30 3 1 1 Evironnement de tests unitaires Cr=E9ation d'un environnement de tests= =20 unitaires et de non-r=E9gression. 8 3 2 15 3 1 1 = 5 = ite_1 Scripts de cr=E9ation des donn=E9es= =20 (TERA) Ecriture des scripts de=20 cr=E9ation de base 2003-04-10 3 4.8 0 2003-04-10 16 3 1 1 = 5 = ite_1 Environnement $U - Session et=20 Uprocs Cr=E9ation des sessions et=20 uprocs propres aux tests. 2003-04-16 1 0 1 2003-04-16 ...... ...... ...... This is an extraction of my XPWeb database (THE Extreme Programming management tool - http://xpweb.sourceforge.net ). Three tables are accessed here : iterations, stories and tasks. Iterations may have several stories, which may have several tasks. What I wanted here is to extract all my iterations with their stories and tasks into a single XML document. This permits to get all iterations at the second level (the first being the root one whose name is defined in the rootTag attribute of the source component) of the document. Each iteration will be written to XML, embraced by an tag Providing a new subquery this way : Permits to define a new sublevel under iteration, writing the stories inside tags. parentLink and childLink permit to assign the stories to their iteration (we don't want all stories to be repeated under each iteration). Here, we make a link between the fields : iterations.id and stories.iteration_id At execution time, the SQL statement is modified to include the link. (for example : select * from stories where iteration_id =3D 4) Now, let's add a subquery to stories : Here, we've added a new sublevel, which will come under stories. It will write all tasks for each stories (with a link between stories.id and tasks.story_id). Simple, isn't it ? =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Have fun !! From anthony@computronix.com Wed Aug 27 22:44:20 2003 From: anthony@computronix.com (Anthony Tuininga) Date: 27 Aug 2003 15:44:20 -0600 Subject: cx_Freeze 2.2 Message-ID: What is cx_Freeze? cx_Freeze is a set of utilities for freezing Python scripts into executables using many of the techniques found in Thomas Heller's py2exe, Gordon McMillan's Installer and the Freeze utility that ships with Python itself. Where do I get it? http://starship.python.net/crew/atuining http://www.computronix.com/utilities.shtml (it may be a few days before the second site is updated) What's new? 1) Add option (--ext-list-file) to FreezePython to write the list of extensions copied to the installation directory to a file. This option is useful in cases where multiple builds are performed into the same installation directory. 2) Pass the arguments on the command line through to Win32 GUI applications. Thanks to Michael Porter for pointing this out. 3) Link directly against the python DLL when building the frozen bases on Windows, thus eliminating the need for building an import library. 4) Force sys.path to include the directory in which the script to be frozen is found. 5) Make sure that the installation directory exists before attempting to copy the target binary into it. 6) The Win32GUI base has been modified to display fatal errors in message boxes, rather than printing errors to stderr, since on Windows the standard file IO handles are all closed. -- Anthony Tuininga anthony@computronix.com Computronix Distinctive Software. Real People. Suite 200, 10216 - 124 Street NW Edmonton, AB, Canada T5N 4A3 Phone: (780) 454-3700 Fax: (780) 454-3838 http://www.computronix.com From barry@python.org Thu Aug 28 02:42:38 2003 From: barry@python.org (Barry Warsaw) Date: 27 Aug 2003 21:42:38 -0400 Subject: New SIG: email-sig Message-ID: After unanimous consent on the meta-sig and mimelib-devel lists, I've gone ahead and created the new email-sig. See http://www.python.org/sigs/email-sig for details. This SIG's mission is to design and implement version 3.0 of the email package for Python 2.4. Please use this SIG instead of the mimelib-devel list from now on. -Barry From andy@agmweb.ca Thu Aug 28 16:46:35 2003 From: andy@agmweb.ca (Andy McKay) Date: Thu, 28 Aug 2003 08:46:35 -0700 Subject: Plone Conference, Early Bird registration ends soon Message-ID: Note: Early bird registration ends Friday! The Plone Conference now has a full list of speakers and tutorials. Over three days in New Orleans almost every aspect of using and developing Plone will be covered by the creators of Plone, Archetypes and Page Templates. Some of the highlights: Evan Simpson will be answering questions about Page Templates. Alexander Limi will be giving a full tutorial on customising Plone Ben Saller will be detailing how to use Archetypes with Plone And don't miss Wednesday nights Q & A panel on "Making money with Plone" For a full list of talks see:http://plone.org/events/conferences/1/talks For a full list of tutorials see: http://plone.org/events/conferences/1/tutorials Early bird registration runs out August 31st, sign up today: http://plone.org/events/conferences/1/registration -- Andy McKay http://www.agmweb.ca From alexander.dejanovski@laposte.net Thu Aug 28 20:16:02 2003 From: alexander.dejanovski@laposte.net (Alexander DEJANOVSKI) Date: Thu, 28 Aug 2003 21:16:02 +0200 Subject: Retic EAI Server 0.4 Released - xmlBlaster and Jabber support Message-ID: I've released a new version of Retic with new components : - Source : xmlBlaster - Sinks : Jabber and HTTP The Designer is now fully working (win32 only) and supports all components of the current Retic release (included in the 0.4 release). It is available on sourceforge : http://sourceforge.net/projects/retic ============================================================= WHAT IS RETIC ? Retic is an EAI Server. The aim is to permit applications to communicate, even if they don't speak the same language (which means transport protocols as well as data structures). This is done by building adaptors. An adaptor is composed of : - One source - Several pipes (process data transformations) - Several sinks (destination of data) - Several loggers (using the logging module of python 2.3) ============================================================= Database support extended to mxODBC, DCOracle2, Sybase, mysql and odbc. (for real this time :o) ============================================================= Have fun !! From info@wingide.com Thu Aug 28 21:54:52 2003 From: info@wingide.com (Wing IDE Announce) Date: Thu, 28 Aug 2003 16:54:52 -0400 (EDT) Subject: Wing IDE 1.1.10 Released Message-ID: Hi, Wing IDE is a commercial integrated development environment for the Python programming language. I'm pleased to announce version 1.1.10, the latest maintenance release for Wing IDE Lite and Wing IDE Standard. This is a free upgrade for all Wing IDE 1.1 users. This release enhances support for Python 2.3, adds debugging support for Cygwin Python, adds debugger display of __slots__ defined attributes, improves analysis support for new style classes, and adds a number of other minor features. The release also fixes a range of bugs, including problems affecting wxPython users, and incorrect resizing of maximized windows on Windows platforms. Try demo: http://wingide.com/wingide/demo Upgrade: http://wingide.com/downloads Purchase: http://wingide.com/order Change log: http://wingide.com/pub/wingide/1.1.10/CHANGELOG.txt As of today, purchase of Wing IDE 1.1 includes free upgrade to Wing IDE 2.0 when that becomes available. Please email questions, feedback, or problem reports to support@wingide.com. Thanks, Stephan Deibel -- Wing IDE for Python Archaeopteryx Software, Inc Take Flight! www.wingide.com From zanesdad@bellsouth.net Fri Aug 29 05:07:22 2003 From: zanesdad@bellsouth.net (Jeremy Jones) Date: Fri, 29 Aug 2003 00:07:22 -0400 Subject: ANN: Munkware 0.1 Message-ID: Munkware, a transactional and persistent queueing mechanism, is proud to announce version 0.1 for public consumption. Bug fixes/enhancements include: - improved recoverability in the event of system crash - example code which is more functional (i.e. they die nicely now ;-) - and modification of transactional syntax (from *_ack() to *_commit() and un_*() to *_rollback()) The Sourceforge Project page is located at http://sourceforge.net/projects/munkware/ and the project home page is located at http://munkware.sourceforge.net/ Future plans for Munkware include: - Better documentation with diagrams of state traversal - Auto-commit functionality - Transactional and persistent queueing server with (possibly) a SOAP interface If you have any suggestions, please feel free to email them to me. If you just think that this project sucks, email that, too. Jeremy Jones From jmiller@stsci.edu Fri Aug 29 21:45:04 2003 From: jmiller@stsci.edu (Todd Miller) Date: 29 Aug 2003 16:45:04 -0400 Subject: ANN: numarray-0.7 Message-ID: Release Notes for numarray-0.7 Numarray is an array processing package designed to efficiently manipulate large multi-dimensional arrays. Numarray is modelled after Numeric and features c-code generated from python template scripts, the capacity to operate directly on arrays in files, and improved type promotions. I. ENHANCEMENTS 1. Object Arrays numarray now has an object array facility. numarray.objects provides array indexing and ufuncs for fixed length collections of arbitrary Python objects. 2. Merger of NumArray/ComplexArray classes Numarray's NumArray and ComplexArray classes have been unified into a single class. Thus, a single base class can be used to derive array classes which operate on integer, real or complex numbers. Thanks to Colin Williams for this suggestion. 3. Indexing improvements The implementation of numarray's indexing has been simplified and improved. Ad-hoc logic for getting single array elements fast has been replaced by a full conversion to C of the top level of numarray's Python indexing code. The resulting code is simpler, prototyped in Python, and adds an additional kind of indexing which occurs entirely in C for speed: sub-arrays. Slicing and array indexing, however, still involve significant amounts of Python code. 4. IEEE Special Value Constants Standard constants for nan, plus_inf, minus_inf, and inf have been added to numarray.ieeespecial making it easier to assign IEEE special values to arrays in addition to finding or replacing special values. 5. Better Numeric interoperability (wxPyPlot port) numarray-0.7 addresses a couple compatibility and speed issues which hindered numarray's use with wxPyPlot. numarray now works fine with the wxPyPlot demos by changing "import Numeric" to "import numarray as Numeric". II. BUGS FIXED See http://sourceforge.net/tracker/?atid=450446&group_id=1369&func=browse for more details. 793421 PyArray_INCREF / PyArray_XDECREF deprecated 791354 Integer overflow bugs? 785458 Crash subclassing the NumArray class 784866 astype() fails sometimes 779755 Mac OS 10 installation problem 740035 Possible problem with dot III. CAUTIONS 1. numarray extension writers should note that the documented use of PyArray_INCREF and PyArray_XDECREF (in numarray) has been found to be incompatible with Numeric and has therefore been deprecated. numarray wrapper functions using PyArray_INCREF and PyArray_XDECREF should switch to ordinary Py_INCREF and Py_XDECREF. 2. Writers of numarray subclasses should note that the "protected" _getitem/_setitem interface for NDArray has changed. WHERE ----------- Numarray-0.7 windows executable installers, source code, and manual is here: http://sourceforge.net/project/showfiles.php?group_id=1369 Numarray is hosted by Source Forge in the same project which hosts Numeric: http://sourceforge.net/projects/numpy/ The web page for Numarray information is at: http://stsdas.stsci.edu/numarray/index.html Trackers for Numarray Bugs, Feature Requests, Support, and Patches are at the Source Forge project for NumPy at: http://sourceforge.net/tracker/?group_id=1369 REQUIREMENTS ------------------------------ numarray-0.7 requires Python 2.2.2 or greater. AUTHORS, LICENSE ------------------------------ Numarray was written by Perry Greenfield, Rick White, Todd Miller, JC Hsu, Paul Barrett, Phil Hodge at the Space Telescope Science Institute. Thanks go to Jochen Kupper of the University of North Carolina for his work on Numarray and for porting the Numarray manual to TeX format. Thanks also to Edward C. Jones, Francesc Alted, Paul Dubois, Eric Jones, Travis Oliphant, Pearu Peterson, Colin Williams, and everyone who has contributed with comments and feedback. Numarray is made available under a BSD-style License. See LICENSE.txt in the source distribution for details. -- Todd Miller jmiller@stsci.edu From vincent@unbrandamerica.org Sat Aug 30 20:00:27 2003 From: vincent@unbrandamerica.org (vincent@unbrandamerica.org) Date: Sat, 30 Aug 2003 19:00:27 GMT Subject: Unbrand America Message-ID: <416CAB01.0B2E1BCA@unbrandamerica.org> This is a multi-part message in MIME format. --63437182485774701150873870016481466022155840461241 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit In the coming months a black spot will pop up everywhere . . . on store windows and newspaper boxes, on gas pumps and supermarket shelves. Open a magazine or newspaper - it's there. It's on TV. It stains the logos and smears the nerve centers of the world's biggest, dirtiest corporations. This is the mark of the people who don't approve of Bush's plan to control the world, who don't want countries "liberated" without UN backing, who can't stand anymore neo-con bravado shoved down their throats. This is the mark of the people who want the Kyoto Protocol for the environment, who want the International Criminal Court for greater justice, who want a world where all nations, including the U.S.A., are free of weapons of mass destruction, and who pledge to take their country back. -- He might absolutely burn rural and tastes our blank, short goldsmiths in front of a hill. --63437182485774701150873870016481466022155840461241 Content-type: text/html; name="srpbt.htm" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="srpbt.htm" Unbrand America
Adbusters
CampaignsMagazineCreative ResistanceOrders Information


In the coming months a black spot will pop up everywhere . . . on store windows and newspaper boxes, on gas pumps and supermarket shelves. Open a magazine or newspaper - it's there. It's on TV. It stains the logos and smears the nerve centers of the world's biggest, dirtiest corporations.

This is the mark of the people who don't approve of Bush's plan to control the world, who don't want countries "liberated" without UN backing, who can't stand anymore neo-con bravado shoved down their throats.

This is the mark of the people who want the Kyoto Protocol for the environment, who want the International Criminal Court for greater justice, who want a world where all nations, including the U.S.A., are free of weapons of mass destruction, and who pledge to take their country back.

--63437182485774701150873870016481466022155840461241-- Tells us and tell the rest of those who have been raped for centuries what is our crime. May God show us all the truth, May God give us the ability to seek unbiased justice for all and fee the minds and bodies of humanity from slavery. May God unite all the Muslims, give them ability to pray. May God give rise to his true followers once again who can bring unbiased justice to the world, because, today's religious people only know to stand aside watch and then walk away because the problems facing the rest is not their problem. wa'Salam Mohsin Welcome to Jewish breeding program Assalam u'Alekum all, I know it sound a bit paranoid but Jews have kept up with this breeding program of theirs. As their population spreads through women. They marry their women to men from other races as Jews are a race and these days give some kind of biological weapon to male so his sperms will only be "x" and rarely "y" due to which the family will have only girls as their next generation. It is said that they give some kind of biological weapons to male due to which his genetic organs are affected permanent From jan@jandecaluwe.com Sat Aug 30 14:04:37 2003 From: jan@jandecaluwe.com (Jan Decaluwe) Date: Sat, 30 Aug 2003 15:04:37 +0200 Subject: ANNOUNCE: MyHDL 0.3 Message-ID: I am happy to announce the release of MyHDL 0.3, a Python package for using Python as a hardware description & verification language. This release has several new features to facilitate HDL modeling, including waveform viewing support. For the details on the new features, go here: http://jandecaluwe.com/Tools/MyHDL/whatsnew03/whatsnew03.html For a general overview and starting point, go here: http://jandecaluwe.com/Tools/MyHDL/Overview.html Regards, Jan -- Jan Decaluwe - Resources bvba - http://jandecaluwe.com Losbergenlaan 16, B-3010 Leuven, Belgium Bored with EDA the way it is? Check this: http://jandecaluwe.com/Tools/MyHDL/Overview.html From jeffreymsimpson@cox.net Sun Aug 31 03:08:35 2003 From: jeffreymsimpson@cox.net (Jeff Simpson) Date: 30 Aug 2003 19:08:35 -0700 Subject: ANN: Coil 0.4 Message-ID: Summary ------- Coil is an MVC framework for Python based on the Struts project. The goal of the project is to provide enough features to be useful and no more. Requirements ------------ - Apache 2.x - mod_python 3.x - Python 2.2 or greater - Linux (devel platform) or Windows (not thoroughly tested) Features -------- - Easy configuration - Automatic form handling (via XML config) - Multiple rendering layers or views (Cheetah, Spyce, and PSP) - It's Python instead of Java :) From richardjones@optushome.com.au Sun Aug 31 05:05:44 2003 From: richardjones@optushome.com.au (Richard Jones) Date: Sun, 31 Aug 2003 14:05:44 +1000 Subject: SC-Track Roundup 0.6.1 - an issue tracking system Message-ID: ================================================= SC-Track Roundup 0.6.1 - an issue tracking system ================================================= I'm pleased to announce this maintenance release of Roundup. This release introduces python 2.3 compatibility. My thanks to Paul Dubois for contributing the csv module compatibility layer. If you're upgrading from an older version of Roundup you *must* follow the "Software Upgrade" guidelines given in the maintenance documentation. Unfortunately, the Zope frontend for Roundup is currently broken. I hope to revive it in a future 0.6 maintenance release. Roundup requires python 2.1.3 or later for correct operation. This release fixes some bugs: - Add note about installing cgi-bin with a different interpreter - Importing wasn't setting None values explicitly when it should have been - Fixed import warning regarding 0xffff0000 literal, finally, really this time. Checked on win2k. (sf bug 786711) - Fix CGI editCSV action to handle metakit's integer itemids - Apply fix for "remove" links from Klamer Schutte - Added permission check on "remove" link while I was there.. - Applied CSV fix for python2.3 (sf bug 790363) - Fixed form padding in LHS menu (sf bug 790502) - Fixed upgrading docs for timezones (sf bug 790498) - Set the content type on page templates (can have XML templates now) - Various cosmetic fixes (thanks James Kew for being persistent :) - Applied patch 739314 (sorry John!) To give Roundup a try, just download (see below), unpack and run:: python demo.py Source and documentation is available at the website: http://roundup.sourceforge.net/ Release Info (via download page): http://sourceforge.net/projects/roundup Mailing lists - the place to ask questions: http://sourceforge.net/mail/?group_id=31577 About Roundup ============= Roundup is a simple-to-use and -install issue-tracking system with command-line, web and e-mail interfaces. It is based on the winning design from Ka-Ping Yee in the Software Carpentry "Track" design competition. Note: Ping is not responsible for this project. The contact for this project is richard@users.sourceforge.net. Roundup manages a number of issues (with flexible properties such as "description", "priority", and so on) and provides the ability to: (a) submit new issues, (b) find and edit existing issues, and (c) discuss issues with other participants. The system will facilitate communication among the participants by managing discussions and notifying interested parties when issues are edited. One of the major design goals for Roundup that it be simple to get going. Roundup is therefore usable "out of the box" with any python 2.1+ installation. It doesn't even need to be "installed" to be operational, though a disutils-based install script is provided. It comes with two issue tracker templates (a classic bug/feature tracker and a minimal skeleton) and six database back-ends (anydbm, bsddb, bsddb3, sqlite, metakit and mysql). From Andreas Jung Sun Aug 31 08:16:42 2003 From: Andreas Jung (Andreas Jung) Date: Sun, 31 Aug 2003 09:16:42 +0200 Subject: SLIMP3 V 0.1 - Python interface for the SLIMP3 player Message-ID: The SLIMP3 package for Python provides an interface to the SLIMP3 MP3 player (www.slimp3.com). Content: slimp3.py - the wrapper around the commandline interface of the SLIMP3 server slimp3player.py - replaces the shuffle mode of the SLIMP3 server and can be customized to reflect your personal shuffle preferences (e.g. only play Jazz in the morning and classics in the evening) Current version: 0.1 Author: Andreas Jung (andreas@andreas-jung.com) Download: http://www.andreas-jung.com/SLIMP3/slimp3.tar.gz The SLIMP3 package is published under the MIT Public License. From raims@dot.com Sun Aug 31 14:48:15 2003 From: raims@dot.com (Lawrence Oluyede) Date: Sun, 31 Aug 2003 15:48:15 +0200 Subject: ANN: pyM3U 0.1 Message-ID: Summary ------- pyM3U is a simple script (it can be used also as a module) to generate M3U playlists Requirements ------------ - Python 2.2 or greater - pymad 0.4.1 - id3-py - Linux (devel platform) or Win (not tested) -- Lawrence "Rhymes" Oluyede http://loluyede.blogspot.com rhymes@NOSPAMmyself.com From logistix@cathoderaymission.net Sun Aug 31 19:35:14 2003 From: logistix@cathoderaymission.net (logistix) Date: Sun, 31 Aug 2003 14:35:14 -0400 Subject: PyXR 0.9.3- Cross-Referenced HTML from Python Source Message-ID: PyXR 0.9.3- Cross-Referenced HTML from Python Source PyXR generates HTML pages from python source files. It also generates cross-referenced hyperlinks and integrates with the Python Library Reference as well, which makes it distinctive from the 8 million other prettyprinters out there. It's been tested on 2.3 for Windows, OpenBSD 3.2 and RedHat 7.3. There's no reason it shouldn't work on other platforms with minor configuration. 0.9.3 is a minor release. It was primarily issued as an "official" 2.3-compatible release, although previous versions should run on 2.3 as well. Other features include: - Per-line-number hyperlinks, to make emailing source code references easier and more accurate. - Upgrade of the PyXR'ed source on my website to 2.3's standard library. A PyXR'ed version of Python 2.3's source can be viewed at: http://www.cathoderaymission.net/~logistix/PyXR/python23/src/ More information about PyXR itself is available at: http://www.cathoderaymission.net/~logistix/python/pyxr.html The package is available at: http://www.cathoderaymission.net/~logistix/python/PyXR.zip Enjoy!