From karsten@phy.hw.ac.uk Mon Jul 5 08:52:01 1999 From: karsten@phy.hw.ac.uk (Karsten Ballueder) Date: Mon, 05 Jul 99 07:52:01 GMT Subject: Mahogany 0.23a Message-ID: A new release of Mahogany has been made. Binaries for Debian Linux i386, Debian Linux AXP, Sun Solaris, Windows NT/98/95 and source are available immediately, binaries for RedHat Linux 5.2 and 6.0 will follow within the next two days. Announcing Mahogany Version 0.23a ===================================================================== Mahogany is an OpenSource(TM) cross-platform mail and news client. It is available for X11/Unix and MS Windows platforms, supporting a wide range of protocols and standards, including POP3, IMAP and full MIME support. Thanks to its built-in Python interpreter it can be extended far beyond its original functionality. Mahogany's wealth of features and ease of use make it one of the most powerful clients available, providing a consistent and intuitive interface across all supported platforms. It aims at supporting GNOME (and KDE for that matter) and includes an extendable address book system supporting hierarchical organisation of entries, group aliases, searching the database and easy editing, with support for other program`s address database formats. Currently Mahogany`s native format and (X)Emacs` BBDB address books are supported. Mahogany is being developed using the free wxWindows application framework, building on the GTK+ toolkit on Unix. Mahogany is constantly being tested on Linux-x86, Linux-alpha, Solaris-sparc and MS Windows. It should compile and work on any major Unix platform. CHANGES AGAINST RELEASE 0.22a / UPDATE : ===================================================================== For the Unix versions, there are few differences, minor bug fixes and improvements, especially in the message editor, which behaves almost perfectly now. The major new addition is the Windows version, built from the same source as the Unix one. We hope to keep both platforms in sync for the future, making common releases. Also, work on a MacOS port has left the early stages and is making progress. - First useable, public Windows release for Windows NT/95/98. - All known (crash-inducing) bugs fixed. - Significant message editor/viewer improvements. - Several minor usability fixes and some significant speed-ups. DOWNLOAD ===================================================================== http://mahogany.home.dhs.org/ http://www.phy.hw.ac.uk/~karsten/Mahogany/ ftp://ronnie.phy.hw.ac.uk/pub/Mahogany/ (UK, Europe) ftp://ftp.gdev.net/pub/Mahogany/ (US) NEXT ===================================================================== For the next release we are currently working on the following: completion of filtering rules/scoring code asynchoronous folder access and multi-threading subscription management for NNTP/IMAP/newsspool Templates/style-sheets for message composition and flexible reply handling DND with KDE/Gnome filemanagers (now supported by wxGTK) Messages sorting, threading, scoring and searching possibly also: GPG/PGP support built-in HTML viewer Finish the new message editor code: rich-text editing == Karsten Ballüder http://Ballueder.home.dhs.org/ mailto:karste-@phy.hw.ac.uk Physics Department, Heriot-Watt University, Edinburgh, EH14 4AS, Scotland Tel. +44-(0)-131-4513068 Fax. +44-(0)-131-4513136 "In a world without fences, who needs Gates?"

Mahogany 0.23a - open-source graphical mail/news client for Unix and MS Windows, using the wxWindows toolkit. (29-Jun-99) -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From irmen@bigfoot.com Mon Jul 5 08:52:28 1999 From: irmen@bigfoot.com (Irmen de Jong) Date: Mon, 05 Jul 99 07:52:28 GMT Subject: AmigaPython 1.5.2 Message-ID: ANNOUNCING: AmigaPython 1.5.2 - build 1 The Amiga version of Python. by Irmen de Jong - irmen@bigfoot.com WHAT IT IS: This is the Python interpreter (version 1.5.2) for AmigaDOS. It is provided as an easy to install package. WHAT'S NEW ? Obviously, this version is based on the 1.5.2 source code and libraries. So you'll benefit from all the great new things 1.5.2 has to offer over the previous version (1.5.1). WHERE CAN I GET IT ? >From Aminet , in the dev/lang directory: Python152.lha dev/lang 1.0M 1 Python language 1.5.2 (bin+lib) Python152_Doc.lha dev/lang 897K 1 Python 1.5.2 documentation (HTML) Python152_Src.lha dev/lang 734K 1 Python language 1.5.2 (source) It comes with a Python-style license, but is otherwise free for commercial and non-commercial use. REFERENCE:

AmigaPython 1.5.2 - AmigaDOS port of Python 1.5.2. (29-Jun-99) == Irmen de Jong - irmen@bigfoot.com -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From akuchlin@mems-exchange.org Mon Jul 5 08:53:21 1999 From: akuchlin@mems-exchange.org (Andrew M. Kuchling) Date: Mon, 05 Jul 99 07:53:21 GMT Subject: Remote Microscope 1.0a3 released Message-ID: The latest release of the remote microscope software, version 1.0alpha3, is now available in source code form. The code has been running on CNRI's demo microscope for a few weeks, and I've been pleased with the results; the server seems to be much more reliable than 1.0a2, and people have liked the new Z-axis control. The only significant new feature in this release is that you can now control the Z-axis from the client, in order to manually focus an image when the autofocus produces a blurry result. There's also a host of minor fixes and improvements; most notably, various bugs were found that made the server hang indefinitely. These bugs have been fixed, and consequently the 1.0alpha3 server is a lot more stable than 1.0a2. Remote microscope home page: http://www.mems-exchange.org/exchange/software/microscope/ List of changes: http://www.mems-exchange.org/exchange/software/files/microscope/CHANGES == A.M. Kuchling http://starship.python.net/crew/amk/ Men of action, I notice, are rarely humble, even in situations where action of any kind is a great mistake, and masterly inaction is called for. -- Robertson Davies, _The Table Talk of Samuel Marchbanks_

Remote Microscope 1.0a3 - CNRI Remote Optical Microscope Software. (29-Jun-99) -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From Amos@digicool.com Mon Jul 5 08:54:19 1999 From: Amos@digicool.com (Amos Latteier) Date: Mon, 05 Jul 99 07:54:19 GMT Subject: Zope Weekly News - Wed, 30 Jun 1999 Message-ID: Hi, This week saw the release of ZCatalog, the first component of the Zope Portal Toolkit. Finally searching Zope objects is becoming easier. Behind the scenes work continues on Zope 2.0. Jim Fulton estimated that Zope 2 will enter beta in 3 weeks. In addition, Eric Raymond's mention of Zope this week (at Microsoft and in an essay) is further proof that Zope is becoming an influential open source project. * Jonathan Corbet pointed out that Eric Raymond mentioned Zope in his latest essay, "The Magic Cauldron". He discusses Zope in the context of how to make a living with open source. He calls Digital Creation's model "Give Away the Recipe, Open A Restaurant". http://www.tuxedo.org/~esr/writings/magic-cauldron/ http://www.tuxedo.org/~esr/writings/magic-cauldron/magic-cauldron-9.html #ss9.3 * Michel Pelletier announced the first release of ZCatalog. This is the first component of the Zope Portal Toolkit to be released. ZCatalog allows indexing and searching of Zope objects. http://www.zope.org/Download/ZCatalog http://www.zope.org/pipermail/zope/1999-June/006059.html * Butch Landingin announced release 0.1.5 of his Squishdot Zope news and discussion Product. http://members.tripod.com/squishdot/index.html http://www.zope.org/pipermail/zope/1999-June/006077.html * Mark Pratt announced that the second Berlin Zope Barbecue went well and that the next one is planned for July 16. http://www.zope.org/pipermail/zope/1999-June/006020.html * FTP/DAV editing issues came up once again this week. Customizing FTP and DAV behavior is a complex problem. Some creative ideas were discussed, but no definitive solution has emerged yet. http://www.zope.org/pipermail/zope/1999-June/006115.html http://www.zope.org/pipermail/zope/1999-June/006171.html * Phillip Eby and others worked on a solution to displaying data from a SQL database as a dynamic tree. Cool! http://www.zope.org/pipermail/zope/1999-June/006087.html * @mgmt announced that they will offer Zope hosting services. http://www.mgmt-inc.com/ * Pam Crosby announced some Zope Documentation plans. http://www.zope.org/pipermail/zope/1999-June/006177.html * Thilo Mezger announced a mailing list for the Zope Internationalization Project. http://www.eevolute.com/mailman/listinfo/zip http://www.zope.org/pipermail/zope-dev/1999-June/000651.html Keep on Zoping. -Amos == Amos Latteier mailto:amos@digicool.com Digital Creations http://www.digicool.com -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From Jeff Rush" Python 1.5.2 and Fnorb 1.01 for OS/2 My port of Python and Fnorb to OS/2 has been updated to the latest stable versions. Besides the improvements of 1.5.2, a threading module bug was fixed that prevented Fnorb from multithreading CORBA requests, posix.chdir() was enhanced to support changing the current drive and a bug was fixed in time.sleep(). http://warped.cswnet.com/~jrush/python_os2/

OS/2 Release - of Python 1.5.2 and Fnorb 1.01. (30-Jun-99) Jeff Rush -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From planders@mail.utexas.edu Mon Jul 5 08:56:24 1999 From: planders@mail.utexas.edu (Preston Landers) Date: Mon, 05 Jul 99 07:56:24 GMT Subject: Pagecast 1.0: submit lists of URLs to search engine spiders Message-ID: Announcing the first release of Pagecast, a tool written in Python to aid in submitting (potentially large) lists of URL's to search engine spiders such as AltaVista, Hotbot, Excite, etc. See http://askpreston.com/projects/pagecast/index.html for more information. Pagecast is distributed under the GNU General Public License. Summary -- Pagecast can run from either the command line or as a mail robot. It is easily configured via .conf files. The basic action is to take a line-separated list of URL's from a file, standard input, or the body of a mail message and submit these URL's in a multithreaded fashion to a variety of Internet search engines. Essentially, it automates the "suggest a site" procedure offered by most search engines. Pagecast 1.0 comes pre-configured with 6 popular search engines (Excite, Hotbot, Infoseek, AltaVista, Google, and Lycos.) It is relatively easy to add additional search engines without delving into the actual Python code. There are some 'advanced' features such as the ability to download and scan the URLs for outdated date meta tags or low keyword-to-title relevence. These features could use some refinement. This software is distributed under the GPL. I hope someone finds it useful and perhaps contributes to its further development. I will make bug-fix releases as neccesary, however, I am not actively working on it at the moment having more exciting Python projects in the works. At any rate, I would love to hear anybody's comments. Sincerely, Preston Landers planders@mail.utexas.edu

Pagecast 1.0 - submit lists of URLs to search engine spiders. (02-Jul-99) -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From mwh21@cam.ac.uk Mon Jul 5 09:00:05 1999 From: mwh21@cam.ac.uk (Michael Hudson) Date: Mon, 05 Jul 99 08:00:05 GMT Subject: bytecodehacks 0.50 Message-ID: [Moderator's note: "Abstract: This package contains a library of routines for editing the bytecodes executed by the Python virtual machine, and a set of routines that use the library to do unlikely things to Python functions and methods, such as locally binding references and inlining functions."] It's been a while, but there's a new version of bytecodehacks on the starship: http://starship.python.net/crew/mwh/ Quite a lot has changed, especially under the hood. There's a design-by-contract module, a function that will make another tail recursive, a set of simple rationalizations/optimizations (originally posted comp.lang.python by Corran Webster) and probably lots of stuff I've forgotten about. The documentation has been updated, but there are probably places where it's out of date, or just plain wrong. If you find such a place please do tell me! The documentation contains what I think is quite a nice description of one way of avoiding cycles in complex data structures (look at the doumentation of fleshy). Have fun, and thanks for reading! Michael

bytecodehacks 0.50 - use manipulations of virtual machine bytecodes to do unlikely things in Python! (04-Jun-99) -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From krp02078@my-deja.com Wed Jul 7 02:16:39 1999 From: krp02078@my-deja.com (krp02078@my-deja.com) Date: Wed, 07 Jul 99 01:16:39 GMT Subject: DIALOG.py Message-ID: Hi everybody! [Moderator's note: "Dialog is a program that will let you to present a variety of questions or display messages using dialog boxes from a shell script. Currently, these types of dialog boxes are implemented: yes/no box, menu box, input box, message box, text box, info box, checklist box, radiolist box, and gauge box." (from the Linux man page for "dialog")] Just finished this module, and thought it could be useful: DIALOG.py - an interface to the famous dialog program get it from http://www.brigadoon.de/peter/DIALOG.py ciao, pete == -rw-r--r-- 1 kruse users 66 Nov 2 11:50 .signature

DIALOG.py - interface to the "dialog" program for text-based dialog boxes. (30-Jun-99) -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From fleck@informatik.uni-bonn.de Wed Jul 7 02:18:34 1999 From: fleck@informatik.uni-bonn.de (Markus Fleck) Date: Wed, 07 Jul 99 01:18:34 GMT Subject: [fm] pyWeather 0.1b Message-ID: pyWeather 0.1b groundhog - June 30th 1999, 12:53 EST pyWeather is a small python script that retreaves the local weather conditions from weather.noaa.gov and then mails the results to any given email over an SMTP server. It's beta but it works. Changes: Initial Release - Fixed a small bug with temp file creation in the earlier version. Download: http://members.bellatlantic.net/~rasclkng/pyWeather.tar.gz Homepage: http://members.bellatlantic.net/~rasclkng/ Author: Groundhog License: GPL Category: Console/eMail Freshmeat copyright © 1999 scoop@freshmeat.net

pyWeather 0.1b - retrieve local weather conditions from weather.noaa.gov and forward them via email/SMTP. (30-Jun-99) -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From fleck@informatik.uni-bonn.de Wed Jul 7 02:20:30 1999 From: fleck@informatik.uni-bonn.de (Markus Fleck) Date: Wed, 07 Jul 99 01:20:30 GMT Subject: [fm] wxPython 2.1b1 Message-ID: wxPython 2.1b1 rogue - June 28th 1999, 20:49 EST wxPython is an extension module for Python that wraps the wxWindows cross platform GUI library, and is quickly becoming a very popular alternative to Tkinter and PythonWin. This extension module attempts to mirror the class hierarchy of wxWindows as closely as possible and is very versatile. It can be used to create standalone GUI applications, or can be used in in situations where Python is embedded in a wxWindows C++ application as an internal scripting or macro language. Currently supported GUIs are Win32 and GTK/X-Windows. Changes: Added the Printing Framework, Sizers, and a boatload of minor tweaks and fixes. Download:http://alldunn.com/wxPython/main.html#download Homepage:http://alldunn.com/wxPython/ Author: Robin Dunn License: OpenSource Category: Development/Python Modules Freshmeat copyright © 1999 scoop@freshmeat.net

wxPython 2.1b1 - interface to the wxWindows v2 free cross-platform GUI library; now includes printing framework. (28-Jun-99) -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From arcege@shore.net Wed Jul 7 02:22:22 1999 From: arcege@shore.net (Michael P. Reilly) Date: Wed, 07 Jul 99 01:22:22 GMT Subject: ExpectPy 1.8.2 - Expect extension for Python Message-ID: I've created a patch release for ExpectPy which fixes some Linux bugs and build problems. I have also moved the ExpectPy webpage to Starship Python: http://starship.python.net/crew/arcege/ExpectPy/ The old URL points to the new location. The author's email address is arcege@shore.net. Note: Expect does not support Tcl 8.1 (and is expected to support Tcl 8.2 instead); the regular expression engine and interface in Tcl 8.1 changed making Expect and ExpectPy unusable with that release. This may cause problems when compiling ExpectPy with earlier versions of Tcl, and compiling Tkinter with Tcl/Tk 8.1. -Arcege Changes since 1.8: * Linux has different mechanisms for extended CBAUD and for when a terminal detects EOF (the error EIO is returned). * Add helper macros to the code for better readability. * Make the C code more compilable (K&R C). * Fix various build issues. * Add a new option to the configure script to force using static libraries. * Beta releases of Python include a "bN" in the version string, strip this inside the configure script. * Handle searching for the pthread library. * Make some minor changes for using Tcl 8.1 in a later release. * Change the ask.py example to use the new stty method instead of termios (which I find is not compiled on many systems). * Fix a bug where setattr of the settings object could receive a NULL.

ExpectPy 1.8.2 - Python adaptation of Don Libes's "Expect" library for automation of interactive UNIX processes. (05-Jul-99) -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From Fred L. Drake, Jr." Updated documentation for Python 1.5.2 is now available. The online version is available at: http://www.python.org/doc/ Archives of the documentation in HTML, LaTeX, PDF, and PostScript formats are available at the same location, and may also be downloaded via FTP from: ftp://ftp.python.org/pub/python/doc/ If you have any questions or comments on the documentation, please send email to: python-docs@python.org Many additional modules have been documented (22 more!). Many small improvements have been made to other parts of the documentation as well. The following modules are now documented: asyncore dl sched chunk fpformat SimpleHTTPServer cmp htmlentitydefs statcache cmpcache mutex statvfs codeop new sunau curses nis SUNAUDIODEV dircache pty tty dl rlcompleter Windows users: If you installed Python using the installer rather than by building from source, you can get the updated documentation by downloading the HTML archive and unpacking it into the "Doc" directory of your installation. Most of the new sections were contributions from the Python community; your help makes the Python documentation some of the best available for any free programming language! Enjoy! -Fred == Fred L. Drake, Jr. Corporation for National Research Initiatives

Updated Python 1.5.2 documentation - with 22 additional modules documented and many small improvements. (06-Jul-99) -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From simone@oreilly.com Wed Jul 7 23:56:06 1999 From: simone@oreilly.com (simone@oreilly.com) Date: Wed, 07 Jul 99 22:56:06 GMT Subject: REGISTRATION REMINDER FOR OPEN SOURCE CONVENTION Message-ID: If you're planning to attend this year's O'Reilly Open Source Software Convention in Monterey, CA, August 21-24 (covering Perl, Apache, Linux, sendmail, Tcl/Tk, Python, as well as an Open Source business track) , you'll probably want to register soon -- discounts of up to $200, as well as an exclusive Open Source Convention T-shirt, apply ONLY to registrations before July 15th. Hope to see you there! For more information, or to register, see: http://conferences.oreilly.com Simone Paddock O'Reilly & Associates 101 Morris Street Sebastopol, CA 95472 simone@oreilly.com -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From neale-news@pobox.com Thu Jul 8 00:05:39 1999 From: neale-news@pobox.com (Neale Pickett) Date: Wed, 07 Jul 99 23:05:39 GMT Subject: New location for whiz, html.py phonebook.pl, and my other goodies Message-ID: Apparently more people are using my software than I realized :-) The new location for my stuff (short descriptions follow) is: http://starship.python.net/crew/neale/src/ (Which is probably where it should have been in the first place.) For those keeping track, the major offerings are: whiz -- html forms tool for creating "wizards" (anyone want to integrate this into bobo? I hear they're looking for one.) html.py -- some classes for generating HTML, in the spirit of HTMLgen, but all in a single file, and it spits out indented code. phonebook -- HTTP to LDAP gateway; makes a web server look like RFC 1959; also provides nice web output and homepage redirection. See http://ldap.lanl.gov/ for a live demo. other stuff -- IRC class for writing bots and clients, an interactive choose-your-own-adventure CGI, and some other non-pythonic toys. Enjoy Neale Pickett

Misc. HTML tools (new location) - whiz, for creating HTML "wizards"; html.py, for generating HTML; phonebook, a HTTP to LDAP gateway; IRC bot classes; etc. (07-Jul-99) -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From jcw@equi4.com Thu Jul 8 00:18:17 1999 From: jcw@equi4.com (Jean-Claude Wippler) Date: Wed, 07 Jul 99 23:18:17 GMT Subject: Minotaur 0.1 - bridging Tcl, Python, and Perl Message-ID: This is the first public announcement of a generalized extension which lets you run Python scripts from Tcl, or Tcl from Perl, or any of the other combinations. Minotaur works by loading the appropriate shared library into another script language's context. So, for example, running Tcl from Python means that the Python main program imports the Minotaur extension, which in turn loads the Tcl libraries - thus Tcl becomes "embedded" into the Python runtime environment (which is similar to embedding Tcl in a normal C program). As involved as that sounds, performance is already surprisingly good, and the capability is turning out to be quite useful. Minotaur 0.1 is an alpha level release, meaning: it works, aside from a few quirks (see below), and bugs, but its API and implementation might still change in incompatible ways in future releases. An example, embedding a Tcl script in Python: import Minotaur Minotaur.initTcl() print Minotaur.Tcl("expr {1111 + 2222}") Minotaur.Tcl(""" set result "Tcl version [info patchlevel]" Python "result = '$result'" """) print result As you can see, a value is returned either directly (only if it's an integer), or by using a reverse embedding, i.e. executing a Python statement from the embedded Tcl system. Also, this shows how tricky quoting could get once you start mixing languages in this manner. And last but not least, note that the different language contexts are separate: the two "result" variables used above are not related in any way (one for Tcl, one for Python). Also, Minotaur does not yet let you share data, it merely lets you evaluate scripts (and copy things). Now the gotcha's, quite a list of them right now: - You need shared libraries to use Minotaur. Standard installations, especially of Perl and Python, do not always include these. The Minotaur homepage has some info on rebuilds you might need to do. - Tcl/Python can call Perl but to get results back, I had to introduce a secondary shared library, dynamically bound to the Perl runtime. - There is currently no other interface than evaluating a single string. Passing int/string/whatever args efficiently is planned for later. - The Minotaur extension has only been tested for Linux and Windows, but is built in a way which should also work on the Mac, and on all Unix systems, even those which do not support back-linking in shared libs. - Minotaur uses some global data; it's not yet re-entrant / thread-safe. As a matter of fact, Minotaur is still totally ignorant of threads. - I have not yet succeeded in getting Minotaur working on the Mac, and ran into problems when trying to launch Tk from Python (Win/Linux). - The current release does not include any Minotaur binaries, you may have to do quite a bit of tweaking to get this stuff to work for you. One of my plans is to substantially simplify deployment of all this. And here's the fun part of things: - Minotaur uses Forth as low-level "super-glue" language. This offers the ability to deal with all the inevitable "impedance mismatches" which will occur when crossing widely different software designs. Also, this can be done without compilation (and often portably). - Timing tests indicate that the overhead of calling through Minotaur is very low, when the necessary symbol lookups are done in advance. The C-based Forth in here uses pForth, and includes quite a bit of standard ("ANS") Forth for now, though this may change in the future. - The Minotaur extension is loadable from Perl, Python, and Tcl, 'cause it exports initialization calls for each of them. This is essential, since the embedded language needs to reopen the extension to gain access to the same Forth context as the one which loaded it (this is how each embedded language can call back into its parent context). - Forth primitives have been defined which can open, lookup, and locate routines exported from shared libraries. Due to the flexibility and performance of Forth, everything else needed to embed one language in the other is done in Forth, i.e. at run time. Forth has no idea that it is being used to tie scripting languages together, for example. - Minotaur, and these shared library access functions have been tested on Linux, Windows, and Mac (partially). The Forth code needed to implement such language bindings differs only in pathnames, so far. - But this is only the tip of the iceberg, really. Proof-of-concept bindings have also been created for Java, MS COM, Lua, ICI, and PHP. Minotaur is a spinoff of my long-term "TinyScript" project and is open source, with a BSD-style license (do whatever you like with it, just leave the copyright attributions intact, and don't sue me). Minotaur was written to see how far one could go in bringing scripting worlds together, and to help me tie my own extensions into a range of languages without having to write a whole range of interfaces. It hasn't met this goal yet, but my hope is that it will be of use to others and that a number of language experts will extend and improve the mechanism so it works well with all of them. Minotaur has sort of a homepage here: http://mini.net/pub/ts2/minotaur.html A mirror copy of my working area is being tracked here: http://mini.net/pub/ts2/ (a.k.a. ftp://mini.net/pub/ts2/) And a snapshots of the whole area was recently created as: http://mini.net/pub/ts2-19990704.tar.gz There is no documentation, release 0.1 is a "use the source Luke" kind of project, but if you would like to try this out - or better still: participate in whatever way you like - feel free to subscribe to the Minotaur mailing list, by sending an email to minotaur-add@mini.net. There are a handful of subscribers now, with just a few outbursts of discussions of where to take this, so far. Which, at this stage, is still a very open-ended question, IMO. Comments, suggestions, praise, but especially offering to help with whetever aspect of Minotaur you'd like to improve are most welcome. Language and platform bashing - yawn - will be redirected to /dev/null. If you wish to help lower language barriers, so that more code can be re-used, more interfacing problems can be solved, and perhaps one day even generic extensions can be written which serve multiple contexts, please have a look at Minotaur and consider helping to make it happen. One interesting option, would be to create a binding in SWIG which generates the low-level glue to Forth, as well as language-specific wrappers. The key advantage is that this could let SWIG be used entirely as a run-time tool, with no compiler/compilation in sight (assuming the target library exists in shared library form, that is). -- Jean-Claude Wippler P.S. This announcement was posted to a range of newsgroups, but was not crossposted to avoid serving as flame bait for YAFLC (Yet Another Fruitless Language Comparison). The list of newsgroups is: comp.lang.forth comp.lang.misc comp.lang.perl.moderated comp.lang.python comp.lang.tcl It's a lotta posting for such an early project, but that's because there seems to be no established "intra-lingual" newsgroup for this stuff.

Minotaur 0.1 - run Python scripts from Tcl, or Tcl from Perl, or any of the other combinations. (06-Jul-99) -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From python-announce@python.org Thu Jul 8 00:26:53 1999 From: python-announce@python.org (Markus Fleck) Date: Wed, 07 Jul 99 23:26:53 GMT Subject: Python Language FAQ - Table of Contents Message-ID: This FAQ newsgroup posting has been automatically converted from an HTML snapshot of the original Python FAQ; please refer to the original "Python FAQ Wizard" at if source code snippets given in this document do not work - incidentally some formatting information may have been lost during the conversion. ---------------------------------------------------------------------------- The whole Python FAQ - Table of Contents Last changed on Mon Jun 28 19:36:09 1999 EDT (Entries marked with ** were changed within the last 24 hours; entries marked with * were changed within the last 7 days.) ---------------------------------------------------------------------------- 1. General information and availability 1.1. What is Python? 1.2. Why is it called Python? 1.3. How do I obtain a copy of the Python source? 1.4. How do I get documentation on Python? 1.5. Are there other ftp sites that mirror the Python distribution? 1.6. Is there a newsgroup or mailing list devoted to Python? 1.7. Is there a WWW page devoted to Python? 1.8. Is the Python documentation available on the WWW? 1.9. Are there any books on Python? 1.10. Are there any published articles about Python that I can reference? 1.11. Are there short introductory papers or talks on Python? 1.12. How does the Python version numbering scheme work? 1.13. How do I get a beta test version of Python? 1.14. Are there copyright restrictions on the use of Python? 1.15. Why was Python created in the first place? 1.16. Do I have to like "Monty Python's Flying Circus"? 1.17. What is Python good for? 1.18. Can I use the FAQ Wizard software to maintain my own FAQ? 1.19. Which editor has good support for editing Python source code? ---------------------------------------------------------------------------- 2. Python in the real world 2.1. How many people are using Python? 2.2. Have any significant projects been done in Python? 2.3. Are there any commercial projects going on using Python? 2.4. How stable is Python? 2.5. What new developments are expected for Python in the future? 2.6. Is it reasonable to propose incompatible changes to Python? 2.7. What is the future of Python? 2.8. What is the PSA, anyway? 2.9. How do I join the PSA? 2.10. What are the benefits of joining the PSA? 2.11. Is Python Y2K (Year 2000) Compliant? ---------------------------------------------------------------------------- 3. Building Python and Other Known Bugs 3.1. Is there a test set? 3.2. When running the test set, I get complaints about floating point operations, but when playing with floating point operations I cannot find anything wrong with them. 3.3. Link errors after rerunning the configure script. 3.4. The python interpreter complains about options passed to a script (after the script name). 3.5. When building on the SGI, make tries to run python to create glmodule.c, but python hasn't been built or installed yet. 3.6. I use VPATH but some targets are built in the source directory. 3.7. Trouble building or linking with the GNU readline library. 3.8. Trouble with socket I/O on older Linux 1.x versions. 3.9. Trouble with prototypes on Ultrix. 3.10. Other trouble building Python on platform X. 3.11. How to configure dynamic loading on Linux. 3.12. I can't get shared modules to work on Linux 2.0 (Slackware96)? 3.13. Trouble when making modules shared on Linux. 3.14. How to use threads on Linux. 3.15. Errors when linking with a shared library containing C++ code. 3.16. I built with tkintermodule.c enabled but get 'Tkinter not found' 3.17. I built with Tk 4.0 but Tkinter complains about the Tk version. 3.18. Compilation or link errors for the _tkinter module 3.19. I configured and built Python for Tcl/Tk but "import Tkinter" fails. 3.20. Tk doesn't work right on DEC Alpha. 3.21. Several common system calls are missing from the posix module. 3.22. ImportError: No module named string, on MS Windows. 3.23. Core dump on SGI when using the gl module. 3.24. "Initializer not a constant" while building DLL on MS-Windows 3.25. Output directed to a pipe or file disappears on Linux. 3.26. Syntax Errors all over the place in Linux with libc 5.4 3.27. Crash in XIO on Linux when using Tkinter. 3.28. How can I test if Tkinter is working? 3.29. Is there a way to get the interactive mode of the python interpreter to perform function/variable name completion? 3.30. Why is the Python interpreter not built as a shared library? 3.31. Build with GCC on Solaris 2.6 (SunOS 5.6) fails 3.32. Running "make clean" seems to leave problematic files that cause subsequent builds to fail. ---------------------------------------------------------------------------- 4. Programming in Python 4.1. Is there a source code level debugger with breakpoints, step, etc.? 4.2. Can I create an object class with some methods implemented in C and others in Python (e.g. through inheritance)? (Also phrased as: Can I use a built-in type as base class?) 4.3. Is there a curses/termcap package for Python? 4.4. Is there an equivalent to C's onexit() in Python? 4.5. When I define a function nested inside another function, the nested function seemingly can't access the local variables of the outer function. What is going on? How do I pass local data to a nested function? 4.6. How do I iterate over a sequence in reverse order? 4.7. My program is too slow. How do I speed it up? 4.8. When I have imported a module, then edit it, and import it again (into the same Python process), the changes don't seem to take place. What is going on? 4.9. How do I find the current module name? 4.10. I have a module in which I want to execute some extra code when it is run as a script. How do I find out whether I am running as a script? 4.11. I try to run a program from the Demo directory but it fails with ImportError: No module named ...; what gives? 4.12. I have successfully built Python with STDWIN but it can't find some modules (e.g. stdwinevents). 4.13. What GUI toolkits exist for Python? 4.14. Are there any interfaces to database packages in Python? 4.15. Is it possible to write obfuscated one-liners in Python? 4.16. Is there an equivalent of C's "?:" ternary operator? 4.17. My class defines __del__ but it is not called when I delete the object. 4.18. How do I change the shell environment for programs called using os.popen() or os.system()? Changing os.environ doesn't work. 4.19. What is a class? 4.20. What is a method? 4.21. What is self? 4.22. What is an unbound method? 4.23. How do I call a method defined in a base class from a derived class that overrides it? 4.24. How do I call a method from a base class without using the name of the base class? 4.25. How can I organize my code to make it easier to change the base class? 4.26. How can I find the methods or attributes of an object? 4.27. I can't seem to use os.read() on a pipe created with os.popen(). 4.28. How can I create a stand-alone binary from a Python script? 4.29. What WWW tools are there for Python? 4.30. How do I run a subprocess with pipes connected to both input and output? 4.31. How do I call a function if I have the arguments in a tuple? 4.32. How do I enable font-lock-mode for Python in Emacs? 4.33. Is there a scanf() or sscanf() equivalent? 4.34. Can I have Tk events handled while waiting for I/O? 4.35. How do I write a function with output parameters (call by reference)? 4.36. Please explain the rules for local and global variables in Python. 4.37. How can I have modules that mutually import each other? 4.38. How do I copy an object in Python? 4.39. How to implement persistent objects in Python? (Persistent == automatically saved to and restored from disk.) 4.40. I try to use __spam and I get an error about _SomeClassName__spam. 4.41. How do I delete a file? And other file questions. 4.42. How to modify urllib or httplib to support HTTP/1.1? 4.43. Unexplicable syntax errors in compile() or exec. 4.44. How do I convert a string to a number? 4.45. How do I convert a number to a string? 4.46. How do I copy a file? 4.47. How do I check if an object is an instance of a given class or of a subclass of it? 4.48. What is delegation? 4.49. How do I test a Python program or component. 4.50. My multidimensional list (array) is broken! What gives? 4.51. I want to do a complicated sort: can you do a Schwartzian Transform in Python? 4.52. How to convert between tuples and lists? 4.53. Files retrieved with urllib contain leading garbage that looks like email headers. 4.54. How do I get a list of all instances of a given class? 4.55. A regular expression fails with regex.error: match failure. 4.56. I can't get signal handlers to work. 4.57. I can't use a global variable in a function? Help! 4.58. What's a negative index? Why doesn't list.insert() use them? 4.59. How can I sort one list by values from another list? 4.60. Why doesn't dir() work on builtin types like files and lists? 4.61. How can I mimic CGI form submission (METHOD=POST)? 4.62. If my program crashes with a bsddb (or anydbm) database open, it gets corrupted. How come? 4.63. How do I make a Python script executable on Unix? 4.64. How do you remove duplicates from a list? 4.65. Are there any known year 2000 problems in Python? 4.66. I want a version of map that applies a method to a sequence of objects! Help! 4.67. How do I generate random numbers in Python? 4.68. How do I access the serial (RS232) port? 4.69. Images on Tk-Buttons don't work in Py15? 4.70. Where is the math.py (socket.py, regex.py, etc.) source file? 4.71. How do I send mail from a Python script? 4.72. How do I avoid blocking in connect() of a socket? 4.73. How do I specify hexadecimal and octal integers? 4.74. How to get a single keypress at a time? 4.75. How can I overload constructors (or methods) in Python? 4.76. How do I pass keyword arguments from one method to another? 4.77. What module should I use to help with generating HTML? 4.78. How do I create documentation from doc strings? 4.79. How do I read (or write) binary data? 4.80. I can't get key bindings to work in Tkinter 4.81. "import crypt" fails 4.82. Are there coding standards or a style guide for Python programs? 4.83. How do I freeze Tkinter applications? 4.84. How do I create static class data and static class methods? 4.85. __import__('x.y.z') returns ; how do I get z? 4.86. Basic thread wisdom 4.87. Why doesn't closing sys.stdout (stdin, stderr) really close it? 4.88. What kinds of global value mutation are thread-safe? 4.89. How do I modify a string in place? 4.90. How to pass on keyword/optional parameters/arguments ---------------------------------------------------------------------------- 5. Extending Python 5.1. Can I create my own functions in C? 5.2. Can I create my own functions in C++? 5.3. How can I execute arbitrary Python statements from C? 5.4. How can I evaluate an arbitrary Python expression from C? 5.5. How do I extract C values from a Python object? 5.6. How do I use Py_BuildValue() to create a tuple of arbitrary length? 5.7. How do I call an object's method from C? 5.8. How do I catch the output from PyErr_Print() (or anything that prints to stdout/stderr)? 5.9. How do I access a module written in Python from C? 5.10. How do I interface to C++ objects from Python? 5.11. mSQLmodule (or other old module) won't build with Python 1.5 (or later) 5.12. I added a module using the Setup file and the make fails! Huh? 5.13. I want to compile a Python module on my Red Hat Linux system, but some files are missing. 5.14. What does "SystemError: _PyImport_FixupExtension: module yourmodule not loaded" mean? ---------------------------------------------------------------------------- 6. Python's design 6.1. Why isn't there a switch or case statement in Python? 6.2. Why does Python use indentation for grouping of statements? 6.3. Why are Python strings immutable? 6.4. Why don't strings have methods like index() or sort(), like lists? 6.5. Why does Python use methods for some functionality (e.g. list.index()) but functions for other (e.g. len(list))? 6.6. Why can't I derive a class from built-in types (e.g. lists or files)? 6.7. Why must 'self' be declared and used explicitly in method definitions and calls? 6.8. Can't you emulate threads in the interpreter instead of relying on an OS-specific thread implementation? 6.9. Why can't lambda forms contain statements? 6.10. Why don't lambdas have access to variables defined in the containing scope? 6.11. Why can't recursive functions be defined inside other functions? 6.12. Why is there no more efficient way of iterating over a dictionary than first constructing the list of keys()? 6.13. Can Python be compiled to machine code, C or some other language? 6.14. How does Python manage memory? Why not full garbage collection? 6.15. Why are there separate tuple and list data types? 6.16. How are lists implemented? 6.17. How are dictionaries implemented? 6.18. Why must dictionary keys be immutable? 6.19. How the heck do you make an array in Python? 6.20. Why doesn't list.sort() return the sorted list? 6.21. How do you specify and enforce an interface spec in Python? 6.22. Why do all classes have the same type? Why do instances all have the same type? 6.23. Why isn't all memory freed when Python exits? 6.24. Why no class methods or mutable class variables? 6.25. Why are default values sometimes shared between objects? 6.26. Why no goto? 6.27. How do you make a higher order function in Python? 6.28. Why do I get a SyntaxError for a 'continue' inside a 'try'? 6.29. Why can't raw strings (r-strings) end with a backslash? 6.30. Why can't I use an assignment in an expression? ---------------------------------------------------------------------------- 7. Using Python on non-UNIX platforms 7.1. Is there a Mac version of Python? 7.2. Are there DOS and Windows versions of Python? 7.3. Is there an OS/2 version of Python? 7.4. Is there a VMS version of Python? 7.5. What about IBM mainframes, or other non-UNIX platforms? 7.6. Where are the source or Makefiles for the non-UNIX versions? 7.7. What is the status and support for the non-UNIX versions? 7.8. I have a PC version but it appears to be only a binary. Where's the library? 7.9. Where's the documentation for the Mac or PC version? 7.10. How do I create a Python program file on the Mac or PC? 7.11. How can I use Tkinter on Windows 95/NT? 7.12. cgi.py (or other CGI programming) doesn't work sometimes on NT or win95! 7.13. Why doesn't os.popen() work in PythonWin on NT? 7.14. How do I use different functionality on different platforms with the same program? 7.15. Is there an Amiga version of Python? 7.16. Why doesn't os.popen()/win32pipe.popen() work on Win9x? ---------------------------------------------------------------------------- 8. Python on Windows 8.1. Using Python for CGI on Microsoft Windows 8.2. How to check for a keypress without blocking? 8.3. $PYTHONPATH 8.4. dedent syntax errors 8.5. How do I emulate os.kill() in Windows? 8.6. Why does os.path.isdir() fail on NT shared directories? 8.7. PyRun_SimpleFile() crashes on Windows but not on Unix 8.8. Import of _tkinter fails on Windows 95/98 8.9. Can't extract the downloaded documentation on Windows 8.10. Can't get Py_RunSimpleFile() to work. 8.11. Where is Freeze for Windows? 8.12. Is a *.pyd file the same as a DLL? 8.13. Missing cw3215mt.dll (or missing cw3215.dll) ---------------------------------------------------------------------------- -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From python-announce@python.org Thu Jul 8 00:27:10 1999 From: python-announce@python.org (Markus Fleck) Date: Wed, 07 Jul 99 23:27:10 GMT Subject: Python Language FAQ - Section 1 Message-ID: This FAQ newsgroup posting has been automatically converted from an HTML snapshot of the original Python FAQ; please refer to the original "Python FAQ Wizard" at if source code snippets given in this document do not work - incidentally some formatting information may have been lost during the conversion. ---------------------------------------------------------------------------- The whole Python FAQ - Section 1 Last changed on Mon Jun 28 19:36:09 1999 EDT (Entries marked with ** were changed within the last 24 hours; entries marked with * were changed within the last 7 days.) ---------------------------------------------------------------------------- 1. General information and availability 1.1. What is Python? 1.2. Why is it called Python? 1.3. How do I obtain a copy of the Python source? 1.4. How do I get documentation on Python? 1.5. Are there other ftp sites that mirror the Python distribution? 1.6. Is there a newsgroup or mailing list devoted to Python? 1.7. Is there a WWW page devoted to Python? 1.8. Is the Python documentation available on the WWW? 1.9. Are there any books on Python? 1.10. Are there any published articles about Python that I can reference? 1.11. Are there short introductory papers or talks on Python? 1.12. How does the Python version numbering scheme work? 1.13. How do I get a beta test version of Python? 1.14. Are there copyright restrictions on the use of Python? 1.15. Why was Python created in the first place? 1.16. Do I have to like "Monty Python's Flying Circus"? 1.17. What is Python good for? 1.18. Can I use the FAQ Wizard software to maintain my own FAQ? 1.19. Which editor has good support for editing Python source code? ---------------------------------------------------------------------------- 1. General information and availability ---------------------------------------------------------------------------- 1.1. 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, the best thing to do is to start reading the tutorial from the documentation set (see a few questions further down). See also question 1.17 (what is Python good for). ---------------------------------------------------------------------------- 1.2. Why is it called Python? Apart from being a computer scientist, I'm also a fan of "Monty Python's Flying Circus" (a BBC comedy series from the seventies, in the -- unlikely -- case you didn't know). It occurred to me one day that I needed a name that was short, unique, and slightly mysterious. And I happened to be reading some scripts from the series at the time... So then I decided to call my language Python. But Python is not a joke. And don't you associate it with dangerous reptiles either! (If you need an icon, use an image of the 16-ton weight from the TV series or of a can of SPAM :-) ---------------------------------------------------------------------------- 1.3. How do I obtain a copy of the Python source? The latest complete Python source distribution is always available by anonymous ftp, e.g. ftp://ftp.python.org/pub/python/src/python1.4.tar.gz. It 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. (See section 7 for non-UNIX information.) An index of said ftp directory can be found in the file INDEX. An HTML version of the index can be found in the file index.html, ftp://ftp.python.org/pub/python/index.html. ---------------------------------------------------------------------------- 1.4. 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, in various formats like postscript and html, by anonymous ftp - visit the above URL for links to the current versions. PostScript for a high-level description of Python is in the file nluug-paper.ps (a separate file on the ftp site). ---------------------------------------------------------------------------- 1.5. Are there other ftp sites that mirror the Python distribution? The following anonymous ftp sites keep mirrors of the Python distribution: USA: ftp://ftp.python.org/pub/python/ ftp://gatekeeper.dec.com/pub/plan/python/ ftp://ftp.uu.net/languages/python/ ftp://ftp.wustl.edu/graphics/graphics/sgi-stuff/python/ ftp://ftp.sterling.com/programming/languages/python/ ftp://uiarchive.cso.uiuc.edu/pub/lang/python/ ftp://ftp.pht.com/mirrors/python/python/ ftp://ftp.cdrom.com/pub/python/ Europe: ftp://ftp.cwi.nl/pub/python/ ftp://ftp.funet.fi/pub/languages/python/ ftp://ftp.sunet.se/pub/lang/python/ ftp://unix.hensa.ac.uk/mirrors/uunet/languages/python/ ftp://ftp.lip6.fr/pub/python/ ftp://sunsite.cnlab-switch.ch/mirror/python/ ftp://ftp.informatik.tu-muenchen.de/pub/comp/programming/languages/python/ Australia: ftp://ftp.dstc.edu.au/pub/python/ ---------------------------------------------------------------------------- 1.6. Is there a newsgroup or mailing list devoted to Python? There is a newsgroup, comp.lang.python, and a mailing 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. To subscribe to the mailing list (python-list@python.org) visit its Mailman webpage at http://www.python.org/mailman/listinfo/python-list More info about the newsgroup and mailing list, and about other lists, can be found at http://www.python.org/psa/MailingLists.html. Archives of the newsgroup are kept by Deja News and accessible through the "Python newsgroup search" web page, http://www.python.org/search/search_news.html. This page also contains pointer to other archival collections. ---------------------------------------------------------------------------- 1.7. Is there a WWW page devoted to Python? Yes, http://www.python.org/ is the official Python home page. ---------------------------------------------------------------------------- 1.8. Is the Python documentation available on the WWW? Yes, see http://www.python.org/ (Python's home page). It contains pointers to hypertext versions of the whole documentation set (as hypertext, not just PostScript). If you wish to browse this collection of HTML files on your own machine, it is available bundled up by anonymous ftp, e.g. ftp://ftp.python.org/pub/python/doc/html.tar.gz. An Emacs-INFO set containing the library manual is also available by ftp, e.g. ftp://ftp.python.org/pub/python/doc/lib-info.tar.gz. ---------------------------------------------------------------------------- 1.9. Are there any books on Python? Yes, several: + Internet Programming with Python by Aaron Watters, Guido van Rossum, and James Ahlstrom MIS Press/Henry Holt publishers ISBN: 1-55851-484-8 First published October, 1996 + Programming Python by Mark Lutz O'Reilly & Associates ISBN: 1-56592-197-6 First published October, 1996 + Das Python-Buch (in German) by Martin von Loewis and Nils Fischbeck Addison-Wesley-Longman, 1997 ISBN: 3-8273-1110-1 More are coming: + Python Pocket Reference by Mark Lutz O'Reilly & Associates ISBN 1-56592-500-9 1st Edition October 1998 (est.) 80 pages (est.), $6.95 (est.) ---------------------------------------------------------------------------- 1.10. Are there any published articles about Python that I can reference? If you can't reference the web site, and you don't want to reference the books (see previous question), there are several articles on Python that you could reference. Most publications about Python are collected on the Python web site: http://www.python.org/doc/Publications.html It is no longer recommended to reference this very old article by Python's author: 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. ---------------------------------------------------------------------------- 1.11. Are there short introductory papers or talks on Python? There are several - you can find links to some of them collected at http://www.python.org/doc/Hints.html#intros. ---------------------------------------------------------------------------- 1.12. 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 major changes in functionality or source structure. B is the minor version number, incremented for less earth-shattering changes to a release. C is the patchlevel -- it is incremented for each new patch release. Not all releases have patch releases. Note that in the past, patches have added significant changes; in fact the changeover from 0.9.9 to 1.0.0 was the first time that either A or B changed! Beta versions have an additional suffix of "betaN" for some small number N. Note that (for instance) all versions labeled 1.4betaN precede the actual release of 1.4. 1.4b3 is short for 1.4beta3. ---------------------------------------------------------------------------- 1.13. How do I get a beta test version of Python? If there are any beta releases, they are published in the normal source directory (e.g. ftp://ftp.python.org/pub/python/src/). Alpha releases are only open to PSA members. See http://www.python.org/psa/ for information on how to join ($50/year). ---------------------------------------------------------------------------- 1.14. Are there copyright restrictions on the use of Python? Hardly. 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). In particular, 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, or to sell products that enhance Python or incorporate Python (or part of it) in some form. I would still like to know about all commercial use of Python! ---------------------------------------------------------------------------- 1.15. Why was Python created in the first place? Here's a very brief summary of what got me started: 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 M3 report). M3 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. ---------------------------------------------------------------------------- 1.16. Do I have to like "Monty Python's Flying Circus"? No, but it helps. Pythonistas like the occasional reference to SPAM, and of course, nobody expects the Spanish Inquisition The two main reasons to use Python are: - Portable - Easy to learn The three main reasons to use Python are: - Portable - Easy to learn - Powerful standard library (And nice red uniforms.) And remember, there is no rule six. ---------------------------------------------------------------------------- 1.17. 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. In the area of basic text manipulation core Python (without any non-core extensions) is easier to use and is roughly as fast as just about any language, and this makes Python good for many system administration type tasks and for CGI programming and other application areas that manipulate text and strings and such. When augmented with standard extensions (such as PIL, COM, Numeric, oracledb, kjbuckets, tkinter, win32api, etc.) or special purpose extensions (that you write, perhaps using helper tools such as SWIG, or using object protocols such as ILU/CORBA or COM) 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 with oracledb you can help your SQL database do statistical analysis, or even Fourier transforms. One of the features that makes Python excel in the "glue language" role is Python's simple, usable, and powerful C language runtime API. Many developers also use Python extensively as a graphical user interface development aide. ---------------------------------------------------------------------------- 1.18. Can I use the FAQ Wizard software to maintain my own FAQ? Sure. Version 1.0 is distributed in the Tools subdirectory of the Python 1.5 source release at http://www.python.org/ftp/python/src/py152.tgz ---------------------------------------------------------------------------- 1.19. Which editor has good support for editing Python source code? On Unix, the first choice is Emacs/XEmacs. There's an elaborate mode for editing Python code, which is available from the Python source distribution (Misc/python-mode.el). It's also bundled with XEmacs (we're still working on legal details to make it possible to bundle it with FSF Emacs). And it has its own web page: http://www.python.org/emacs/python-mode/index.html There are many other choices, for Unix, Windows or Macintosh. Richard Jones compiled a table from postings on the Python newsgroup: http://www.bofh.asn.au/~richard/editors.html See also FAQ question 7.10 for some more Mac and Win options. ---------------------------------------------------------------------------- -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From python-announce@python.org Thu Jul 8 00:27:23 1999 From: python-announce@python.org (Markus Fleck) Date: Wed, 07 Jul 99 23:27:23 GMT Subject: Python Language FAQ - Section 3 Message-ID: This FAQ newsgroup posting has been automatically converted from an HTML snapshot of the original Python FAQ; please refer to the original "Python FAQ Wizard" at if source code snippets given in this document do not work - incidentally some formatting information may have been lost during the conversion. ---------------------------------------------------------------------------- The whole Python FAQ - Section 3 Last changed on Mon Jun 28 19:36:09 1999 EDT (Entries marked with ** were changed within the last 24 hours; entries marked with * were changed within the last 7 days.) ---------------------------------------------------------------------------- 3. Building Python and Other Known Bugs 3.1. Is there a test set? 3.2. When running the test set, I get complaints about floating point operations, but when playing with floating point operations I cannot find anything wrong with them. 3.3. Link errors after rerunning the configure script. 3.4. The python interpreter complains about options passed to a script (after the script name). 3.5. When building on the SGI, make tries to run python to create glmodule.c, but python hasn't been built or installed yet. 3.6. I use VPATH but some targets are built in the source directory. 3.7. Trouble building or linking with the GNU readline library. 3.8. Trouble with socket I/O on older Linux 1.x versions. 3.9. Trouble with prototypes on Ultrix. 3.10. Other trouble building Python on platform X. 3.11. How to configure dynamic loading on Linux. 3.12. I can't get shared modules to work on Linux 2.0 (Slackware96)? 3.13. Trouble when making modules shared on Linux. 3.14. How to use threads on Linux. 3.15. Errors when linking with a shared library containing C++ code. 3.16. I built with tkintermodule.c enabled but get 'Tkinter not found' 3.17. I built with Tk 4.0 but Tkinter complains about the Tk version. 3.18. Compilation or link errors for the _tkinter module 3.19. I configured and built Python for Tcl/Tk but "import Tkinter" fails. 3.20. Tk doesn't work right on DEC Alpha. 3.21. Several common system calls are missing from the posix module. 3.22. ImportError: No module named string, on MS Windows. 3.23. Core dump on SGI when using the gl module. 3.24. "Initializer not a constant" while building DLL on MS-Windows 3.25. Output directed to a pipe or file disappears on Linux. 3.26. Syntax Errors all over the place in Linux with libc 5.4 3.27. Crash in XIO on Linux when using Tkinter. 3.28. How can I test if Tkinter is working? 3.29. Is there a way to get the interactive mode of the python interpreter to perform function/variable name completion? 3.30. Why is the Python interpreter not built as a shared library? 3.31. Build with GCC on Solaris 2.6 (SunOS 5.6) fails 3.32. Running "make clean" seems to leave problematic files that cause subsequent builds to fail. ---------------------------------------------------------------------------- 3. Building Python and Other Known Bugs ---------------------------------------------------------------------------- 3.1. Is there a test set? Sure. You can run it after building with "make test", or you can run it manuall with the command import test.autotest In 1.4 or earlier, use import autotest The test set doesn't test all features of Python, but it goes a long way to confirm that Python is actually working. NOTE: if "make test" fails, don't just mail the output to the newsgroup -- this doesn't give enough information to debug the problem. Instead, find out which test fails, and run that test manually from an interactive interpreter. For example, if "make test" reports that test_spam fails, try this interactively: import test.test_spam This generally produces more verbose output which can be diagnosed to debug the problem. ---------------------------------------------------------------------------- 3.2. When running the test set, I get complaints about floating point operations, but when playing with floating point operations I cannot find anything wrong with them. The test set makes occasional unwarranted assumptions about the semantics of C floating point operations. Until someone donates a better floating point test set, you will have to comment out the offending floating point tests and execute similar tests manually. ---------------------------------------------------------------------------- 3.3. Link errors after rerunning the configure script. It is generally necessary to run "make clean" after a configuration change. ---------------------------------------------------------------------------- 3.4. The python interpreter complains about options passed to a script (after the script name). You are probably linking with GNU getopt, e.g. through -liberty. Don't. The reason for the complaint is that GNU getopt, unlike System V getopt and other getopt implementations, doesn't consider a non-option to be the end of the option list. A quick (and compatible) fix for scripts is to add "--" to the interpreter, like this: #! /usr/local/bin/python -- You can also use this interactively: python -- script.py [options] Note that a working getopt implementation is provided in the Python distribution (in Python/getopt.c) but not automatically used. ---------------------------------------------------------------------------- 3.5. When building on the SGI, make tries to run python to create glmodule.c, but python hasn't been built or installed yet. Comment out the line mentioning glmodule.c in Setup and build a python without gl first; install it or make sure it is in your $PATH, then edit the Setup file again to turn on the gl module, and make again. You don't need to do "make clean"; you do need to run "make Makefile" in the Modules subdirectory (or just run "make" at the toplevel). ---------------------------------------------------------------------------- 3.6. I use VPATH but some targets are built in the source directory. On some systems (e.g. Sun), if the target already exists in the source directory, it is created there instead of in the build directory. This is usually because you have previously built without VPATH. Try running "make clobber" in the source directory. ---------------------------------------------------------------------------- 3.7. Trouble building or linking with the GNU readline library. Consider using readline 2.0. Some hints: You can use the GNU readline library to improve the interactive user interface: this gives you line editing and command history when calling python interactively. You need to configure and build the GNU readline library before running the configure script. Its sources are no longer distributed with Python; you can ftp them from any GNU mirror site, or from its home site ftp://slc2.ins.cwru.edu/pub/dist/readline-2.0.tar.gz (or a higher version number -- using version 1.x is not recommended). Pass the Python configure script the option --with-readline=DIRECTORY where DIRECTORY is the absolute pathname of the directory where you've built the readline library. Some hints on building and using the readline library: On SGI IRIX 5, you may have to add the following to rldefs.h: #ifndef sigmask #define sigmask(sig) (1L << ((sig)-1)) #endif On most systems, you will have to add #include "rldefs.h" to the top of several source files, and if you use the VPATH feature, you will have to add dependencies of the form foo.o: foo.c to the Makefile for several values of foo. The readline library requires use of the termcap library. A known problem with this is that it contains entry points which cause conflicts with the STDWIN and SGI GL libraries. The STDWIN conflict can be solved by adding a line saying '#define werase w_erase' to the stdwin.h file (in the STDWIN distribution, subdirectory H). The GL conflict has been solved in the Python configure script by a hack that forces use of the static version of the termcap library. Check the newsgroup gnu.bash.bug news:gnu.bash.bug for specific problems with the readline library (I don't read this group but I've been told that it is the place for readline bugs). ---------------------------------------------------------------------------- 3.8. Trouble with socket I/O on older Linux 1.x versions. Once you've built Python, use it to run the regen.py script in the Lib/linux1 directory. Apparently the files as distributed don't match the system headers on some Linux versions. ---------------------------------------------------------------------------- 3.9. Trouble with prototypes on Ultrix. Ultrix cc seems broken -- use gcc, or edit config.h to #undef HAVE_PROTOTYPES. ---------------------------------------------------------------------------- 3.10. Other trouble building Python on platform X. Please email the details to guido@cnri.reston.va.us and I'll look into it. Please provide as many details as possible. In particular, if you don't tell me what type of computer and what operating system (and version) you are using it will be difficult for me to figure out what is the matter. If you get a specific error message, please email it to me too. ---------------------------------------------------------------------------- 3.11. How to configure dynamic loading on Linux. This is now automatic as long as your Linux version uses the ELF object format (all recent Linuxes do). ---------------------------------------------------------------------------- 3.12. I can't get shared modules to work on Linux 2.0 (Slackware96)? This is a bug in the Slackware96 release. The fix is simple: Make sure that there is a link from /lib/libdl.so to /lib/libdl.so.1 so that the following links are setup: /lib/libdl.so -> /lib/libdl.so.1 /lib/libdl.so.1 -> /lib/libdl.so.1.7.14 You may have to rerun the configure script, after rm'ing the config.cache file, before you attempt to rebuild python after this fix. ---------------------------------------------------------------------------- 3.13. Trouble when making modules shared on Linux. This happens when you have built Python for static linking and then enable *shared* in the Setup file. Shared library code must be compiled with "-fpic". If a .o file for the module already exist that was compiled for static linking, you must remove it or do "make clean" in the Modules directory. ---------------------------------------------------------------------------- 3.14. How to use threads on Linux. [Greg Stein] You need to have a very recent libc, or even better, get the LinuxThreads-0.5 distribution. Note that if you install LinuxThreads normally, then you shouldn't need to specify the directory to the -with-thread configuration switch. The configure script ought to find it without a problem. To make sure everything builds properly, do a "make clean", remove config.cache, re-run configure with that switch, and then build. [Andy Dustman] On glibc systems (i.e. RedHat 5.0+), LinuxThreads is obsoleted by POSIX threads (-lpthread). If you upgraded from an earlier RedHat, remove LinuxThreads with "rpm -e linuxthreads linuxthreads-devel". Then run configure using --with-thread as above. ---------------------------------------------------------------------------- 3.15. Errors when linking with a shared library containing C++ code. Link the main Python binary with C++. Change the definition of LINKCC in Modules/Makefile to be your C++ compiler. You may have to edit config.c slightly to make it compilable with C++. ---------------------------------------------------------------------------- 3.16. I built with tkintermodule.c enabled but get 'Tkinter not found' Tkinter.py (note: upper case T) lives in a subdirectory of Lib, Lib/tkinter. If you are using the default module search path, you probably didn't enable the line in the Modules/Setup file defining TKPATH; if you use the environment variable PYTHONPATH, you'll have to add the proper tkinter subdirectory. For Windows, see question 7.11. ---------------------------------------------------------------------------- 3.17. I built with Tk 4.0 but Tkinter complains about the Tk version. Several things could cause this. You most likely have a Tk 3.6 installation that wasn't completely eradicated by the Tk 4.0 installation (which tends to add "4.0" to its installed files). You may have the Tk 3.6 support library installed in the place where the Tk 4.0 support files should be (default /usr/local/lib/tk/); you may have compiled Python with the old tk.h header file (yes, this actually compiles!); you may actually have linked with Tk 3.6 even though Tk 4.0 is also around. Similar for Tcl 7.4 vs. Tcl 7.3. ---------------------------------------------------------------------------- 3.18. Compilation or link errors for the _tkinter module Most likely, there's a version mismatch between the Tcl/Tk header files (tcl.h and tk.h) and the Tcl/Tk libraries you are using e.g. "-ltk8.0" and "-ltcl8.0" arguments for _tkinter in the Setup file). It is possible to install several versions of the Tcl/Tk libraries, but there can only be one version of the tcl.h and tk.h header files. If the library doesn't match the header, you'll get problems, either when linking the module, or when importing it. Fortunately, the version number is clearly stated in each file, so this is easy to find. Reinstalling and using the latest version usually fixes the problem. (Also note that when compiling unpatched Python 1.5.1 against Tcl/Tk 7.6/4.2 or older, you get an error on Tcl_Finalize. See the 1.5.1 patch page at http://www.python.org/1.5/patches-1.5.1/.) ---------------------------------------------------------------------------- 3.19. I configured and built Python for Tcl/Tk but "import Tkinter" fails. Most likely, you forgot to enable the line in Setup that says "TKPATH=:$(DESTLIB)/tkinter". ---------------------------------------------------------------------------- 3.20. Tk doesn't work right on DEC Alpha. You probably compiled either Tcl, Tk or Python with gcc. Don't. For this platform, which has 64-bit integers, gcc is known to generate broken code. The standard cc (which comes bundled with the OS!) works. If you still prefer gcc, at least try recompiling with cc before reporting problems to the newsgroup or the author; if this fixes the problem, report the bug to the gcc developers instead. (As far as we know, there are no problem with gcc on other platforms -- the instabilities seem to be restricted to the DEC Alpha.) See also question 3.6. There's also a 64-bit bugfix for Tcl/Tk; see http://grail.cnri.reston.va.us/grail/info/patches/tk64bit.txt ---------------------------------------------------------------------------- 3.21. Several common system calls are missing from the posix module. Most likely, all test compilations run by the configure script are failing for some reason or another. Have a look in config.log to see what could be the reason. A common reason is specifying a directory to the --with-readline option that doesn't contain the libreadline.a file. ---------------------------------------------------------------------------- 3.22. ImportError: No module named string, on MS Windows. Most likely, your PYTHONPATH environment variable should be set to something like: set PYTHONPATH=c:\python;c:\python\lib;c:\python\scripts (assuming Python was installed in c:\python) ---------------------------------------------------------------------------- 3.23. Core dump on SGI when using the gl module. There are conflicts between entry points in the termcap and curses libraries and an entry point in the GL library. There's a hack of a fix for the termcap library if it's needed for the GNU readline library, but it doesn't work when you're using curses. Concluding, you can't build a Python binary containing both the curses and gl modules. ---------------------------------------------------------------------------- 3.24. "Initializer not a constant" while building DLL on MS-Windows Static type object initializers in extension modules may cause compiles to fail with an error message like "initializer not a constant". Fredrik Lundh explains: This shows up when building DLL under MSVC. There's two ways to address this: either compile the module as C++, or change your code to something like: statichere PyTypeObject bstreamtype = { PyObject_HEAD_INIT(NULL) /* must be set by init function */ 0, "bstream", sizeof(bstreamobject), ... void initbstream() { /* Patch object type */ bstreamtype.ob_type = &PyType_Type; Py_InitModule("bstream", functions); ... } ---------------------------------------------------------------------------- 3.25. Output directed to a pipe or file disappears on Linux. Some people have reported that when they run their script interactively, it runs great, but that when they redirect it to a pipe or file, no output appears. % python script.py ...some output... % python script.py >file % cat file % # no output % python script.py | cat % # no output % Nobody knows what causes this, but it is apparently a Linux bug. Most Linux users are not affected by this. There's at least one report of someone who reinstalled Linux (presumably a newer version) and Python and got rid of the problem; so this may be the solution. ---------------------------------------------------------------------------- 3.26. Syntax Errors all over the place in Linux with libc 5.4 ``I have installed python1.4 on my Linux system. When I try run the import statement I get the following error message:'' File "", line 1 import sys ^ Syntax Error: "invalid syntax" Did you compile it yourself? This usually is caused by an incompatibility between libc 5.4.x and earlier libc's. In particular, programs compiled with libc 5.4 give incorrect results on systems which had libc 5.2 installed because the ctype.h file is broken. In this case, Python can't recognize which characters are letters and so on. The fix is to install the C library which was used when building the binary that you installed, or to compile Python yourself. When you do this, make sure the C library header files which get used by the compiler match the installed C library. [adapted from an answer by Martin v. Loewis] PS [adapted from Andreas Jung]: If you have upgraded to libc 5.4.x, and the problem persists, check your library path for an older version of libc. Try to clean update libc with the libs and the header files and then try to recompile all. ---------------------------------------------------------------------------- 3.27. Crash in XIO on Linux when using Tkinter. When Python is built with threads under Linux, use of Tkinter can cause crashes like the following: >>> from Tkinter import * >>> root = Tk() XIO: fatal IO error 0 (Unknown error) on X server ":0.0" after 45 requests (40 known processed) with 1 events remaining. The reason is that the default Xlib is not built with support for threads. If you rebuild Xlib with threads enabled the problems go away. Alternatively, you can rebuild Python without threads ("make clean" first!). (Disclaimer: this is from memory.) ---------------------------------------------------------------------------- 3.28. How can I test if Tkinter is working? Try the following: python >>> import _tkinter >>> import Tkinter >>> Tkinter._test() This should pop up a window with two buttons, one "Click me" and one "Quit". If the first statement (import _tkinter) fails, your Python installation probably has not been configured to support Tcl/Tk. On Unix, if you have installed Tcl/Tk, you have to rebuild Python after editing the Modules/Setup file to enable the _tkinter module and the TKPATH environment variable. It is also possible to get complaints about Tcl/Tk version number mismatches or missing TCL_LIBRARY or TK_LIBRARY environment variables. These have to do with Tcl/Tk installation problems. A common problem is to have installed versions of tcl.h and tk.h that don't match the installed version of the Tcl/Tk libraries; this usually results in linker errors or (when using dynamic loading) complaints about missing symbols during loading the shared library. ---------------------------------------------------------------------------- 3.29. Is there a way to get the interactive mode of the python interpreter to perform function/variable name completion? (From a posting by Guido van Rossum) On Unix, if you have enabled the readline module (i.e. if Emacs-style command line editing and bash-style history works for you), you can add this by importing the undocumented standard library module "rlcompleter". When completing a simple identifier, it completes keywords, built-ins and globals in __main__; when completing NAME.NAME..., it evaluates (!) the expression up to the last dot and completes its attributes. This way, you can do "import string", type "string.", hit the completion key twice, and see the list of names defined by the string module. Tip: to use the tab key as the completion key, call readline.parse_and_bind("tab: complete") You can put this in a ~/.pythonrc file, and set the PYTHONSTARTUP environment variable to ~/.pythonrc. This will cause the completion to be enabled whenever you run Python interactively. Notes (see the docstring for rlcompleter.py for more information): * The evaluation of the NAME.NAME... form may cause arbitrary application defined code to be executed if an object with a __getattr__ hook is found. Since it is the responsibility of the application (or the user) to enable this feature, I consider this an acceptable risk. More complicated expressions (e.g. function calls or indexing operations) are not evaluated. * GNU readline is also used by the built-in functions input() and raw_input(), and thus these also benefit/suffer from the complete features. Clearly an interactive application can benefit by specifying its own completer function and using raw_input() for all its input. * When stdin is not a tty device, GNU readline is never used, and this module (and the readline module) are silently inactive. ---------------------------------------------------------------------------- 3.30. Why is the Python interpreter not built as a shared library? (This is a Unix question; on Mac and Windows, it is a shared library.) It's just a nightmare to get this to work on all different platforms. Shared library portability is a pain. And yes, I know about GNU libtool -- but it requires me to use its conventions for filenames etc, and it would require a complete and utter rewrite of all the makefile and config tools I'm currently using. In practice, few applications embed Python -- it's much more common to have Python extensions, which already are shared libraries. Also, serious embedders often want total control over which Python version and configuration they use so they wouldn't want to use a standard shared library anyway. So while the motivation of saving space when lots of apps embed Python is nice in theory, I doubt that it will save much in practice. (Hence the low priority I give to making a shared library.) ---------------------------------------------------------------------------- 3.31. Build with GCC on Solaris 2.6 (SunOS 5.6) fails If you have upgraded Solaris 2.5 or 2.5.1 to Solaris 2.6, but you have not upgraded your GCC installation, the compile may fail, e.g. like this: In file included from /usr/include/sys/stream.h:26, from /usr/include/netinet/in.h:38, from /usr/include/netdb.h:96, from ./socketmodule.c:121: /usr/include/sys/model.h:32: #error "No DATAMODEL_NATIVE specified" Solution: rebuild GCC for Solaris 2.6. You might be able to simply re-run fixincludes, but people have had mixed success with doing that. ---------------------------------------------------------------------------- 3.32. Running "make clean" seems to leave problematic files that cause subsequent builds to fail. Use "make clobber" instead. Use "make clean" to reduce the size of the source/build directory after you're happy with your build and installation. If you have already tried to build python and you'd like to start over, you should use "make clobber". It does a "make clean" and also removes files such as the partially built Python library from a previous build. ---------------------------------------------------------------------------- -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From python-announce@python.org Thu Jul 8 00:27:16 1999 From: python-announce@python.org (Markus Fleck) Date: Wed, 07 Jul 99 23:27:16 GMT Subject: Python Language FAQ - Section 2 Message-ID: This FAQ newsgroup posting has been automatically converted from an HTML snapshot of the original Python FAQ; please refer to the original "Python FAQ Wizard" at if source code snippets given in this document do not work - incidentally some formatting information may have been lost during the conversion. ---------------------------------------------------------------------------- The whole Python FAQ - Section 2 Last changed on Mon Jun 28 19:36:09 1999 EDT (Entries marked with ** were changed within the last 24 hours; entries marked with * were changed within the last 7 days.) ---------------------------------------------------------------------------- 2. Python in the real world 2.1. How many people are using Python? 2.2. Have any significant projects been done in Python? 2.3. Are there any commercial projects going on using Python? 2.4. How stable is Python? 2.5. What new developments are expected for Python in the future? 2.6. Is it reasonable to propose incompatible changes to Python? 2.7. What is the future of Python? 2.8. What is the PSA, anyway? 2.9. How do I join the PSA? 2.10. What are the benefits of joining the PSA? 2.11. Is Python Y2K (Year 2000) Compliant? ---------------------------------------------------------------------------- 2. Python in the real world ---------------------------------------------------------------------------- 2.1. How many people are using Python? I don't know, but the maximum number of simultaneous subscriptions to the Python mailing list before it was gatewayed into the newsgroup was about 180 (several of which were local redistribution lists). I believe that many active Python users don't bother to subscribe to the list, and now that there's a newsgroup the mailing list subscription is even less meaningful. I see new names on the newsgroup all the time and my best guess is that there are currently at least several thousands of users. Another statistic is the number of accesses to the Python WWW server. Have a look at http://www.python.org/stats/. ---------------------------------------------------------------------------- 2.2. Have any significant projects been done in Python? At CWI (the former home of Python), we have written a 20,000 line authoring environment for transportable hypermedia presentations, a 5,000 line multimedia teleconferencing tool, as well as many many smaller programs. At CNRI (Python's new home), we have written two large applications: Grail, a fully featured web browser (see http://grail.cnri.reston.va.us), and the Knowbot Operating Environment, a distributed environment for mobile code. The University of Virginia uses Python to control a virtual reality engine. See http://alice.cs.cmu.edu. The ILU project at Xerox PARC can generate Python glue for ILU interfaces. See ftp://ftp.parc.xerox.com/pub/ilu/ilu.html. ILU is a free CORBA compliant ORB which supplies distributed object connectivity to a host of platforms using a host of languages. Mark Hammond and Greg Stein and others are interfacing Python to Microsoft's COM and ActiveX architectures. This means, among other things, that Python may be used in active server pages or as a COM controller (for example to automatically extract from or insert information into Excel or MSAccess or any other COM aware application). Mark claims Python can even be a ActiveX scripting host (which means you could embed JScript inside a Python application, if you had a strange sense of humor). Python/AX/COM is distributed as part of the PythonWin distribution. The University of California, Irvine uses a student administration system called TELE-Vision written entirely in Python. Contact: Ray Price rlprice@uci.edu. The Melbourne Cricket Ground (MCG) in Australia (a 100,000+ person venue) has it's scoreboard system written largely in Python on MS Windows. Python expressions are used to create almost every scoring entry that appears on the board. The move to Python/C++ away from exclusive C++ has provided a level of functionality that would simply not have been viable otherwise. See also the next question. If you have done a significant project in Python that you'd like to be included in the list above, send me email! ---------------------------------------------------------------------------- 2.3. Are there any commercial projects going on using Python? Yes, there's lots of commercial activity using Python. See http://www.python.org/psa/Users.html for a list. ---------------------------------------------------------------------------- 2.4. How stable is Python? Very stable. While the current version number would suggest it is in the early stages of development, in fact new, stable releases (numbered 0.9.x through 1.4) have been coming out roughly every 3 to 6 or 12 months for the past four years. ---------------------------------------------------------------------------- 2.5. What new developments are expected for Python in the future? Follow the newsgroup discussions! The workshop proceedings (http://www.python.org/workshops/) may also contain interesting looks into the future. ---------------------------------------------------------------------------- 2.6. 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 changes 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. Providing a gradual upgrade path is the only way if a feature has to be changed. ---------------------------------------------------------------------------- 2.7. What is the future of Python? If I knew, I'd be rich :-) Seriously, the formation of the PSA (Python Software Activity, see http://www.python.org/psa/) ensures some kind of support even in the (unlikely!) event that I'd be hit by a bus (actually, here in the U.S., a car accident would be more likely :-), were to join a nunnery, or would be head-hunted. A large number of Python users have become experts at Python programming as well as maintenance of the implementation, and would easily fill the vacuum created by my disappearance. In the meantime, I have no plans to disappear -- rather, I am committed to improving Python, and my current benefactor, CNRI (see http://www.cnri.reston.va.us) is just as committed to continue its support of Python and the PSA. In fact, we have great plans for Python -- we just can't tell yet! ---------------------------------------------------------------------------- 2.8. What is the PSA, anyway? The Python Software Activity http://www.python.org/psa/ was created by a number of Python aficionados who want Python to be more than the product and responsibility of a single individual. It has found a home at CNRI http://www.cnri.reston.va.us. Anybody who wishes Python well should join the PSA. ---------------------------------------------------------------------------- 2.9. How do I join the PSA? The full scoop is available on the web, see http://www.python.org/psa/regtempl.html. Summary: send a check of at least $50 to CNRI/PSA, 1895 Preston White Drive, Suite 100, in Reston, VA 20191. Full-time students pay $25. Prices drop by half the second half of the fiscal year (April - September). Companies can join for a mere $500. Pets may join for only $15! ---------------------------------------------------------------------------- 2.10. What are the benefits of joining the PSA? Like National Public Radio, without your support, Python will wither. If you join, your name will be mentioned on the PSA's web server. Workshops organized by the PSA http://www.python.org/workshops/ are only accessible to PSA members (you can join at the door). The PSA is working on additional benefits, such as reduced prices for books and software, and early access to alpha versions of Python. (The latter has been realized -- the 1.5 alpha testing program is accessible only to PSA members.) You might also consider to become a member of the starship project. It is a free group of Python enthusiasts, and you get a free account. They just happen to admit only PSA members. Check out http://starship.python.net for further information. ---------------------------------------------------------------------------- 2.11. Is Python Y2K (Year 2000) Compliant? Since Python is available free of charge, I don't want to make any absolute guarantees. If there is a problem that I didn't foresee, I don't want to be sued for damages. That said, I'm pretty convinced that there are no Y2K problems anywhere in the core distribution, either 1.5 or 1.4. Python does few date manipulations, and what it does is all based on the Unix representation for time (even on non-Unix systems) which uses seconds since 1970 and won't overflow until 2038. ---------------------------------------------------------------------------- -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From python-announce@python.org Thu Jul 8 00:27:48 1999 From: python-announce@python.org (Markus Fleck) Date: Wed, 07 Jul 99 23:27:48 GMT Subject: Python Language FAQ - Section 5 Message-ID: This FAQ newsgroup posting has been automatically converted from an HTML snapshot of the original Python FAQ; please refer to the original "Python FAQ Wizard" at if source code snippets given in this document do not work - incidentally some formatting information may have been lost during the conversion. ---------------------------------------------------------------------------- The whole Python FAQ - Section 5 Last changed on Mon Jun 28 19:36:09 1999 EDT (Entries marked with ** were changed within the last 24 hours; entries marked with * were changed within the last 7 days.) ---------------------------------------------------------------------------- 5. Extending Python 5.1. Can I create my own functions in C? 5.2. Can I create my own functions in C++? 5.3. How can I execute arbitrary Python statements from C? 5.4. How can I evaluate an arbitrary Python expression from C? 5.5. How do I extract C values from a Python object? 5.6. How do I use Py_BuildValue() to create a tuple of arbitrary length? 5.7. How do I call an object's method from C? 5.8. How do I catch the output from PyErr_Print() (or anything that prints to stdout/stderr)? 5.9. How do I access a module written in Python from C? 5.10. How do I interface to C++ objects from Python? 5.11. mSQLmodule (or other old module) won't build with Python 1.5 (or later) 5.12. I added a module using the Setup file and the make fails! Huh? 5.13. I want to compile a Python module on my Red Hat Linux system, but some files are missing. 5.14. What does "SystemError: _PyImport_FixupExtension: module yourmodule not loaded" mean? ---------------------------------------------------------------------------- 5. Extending Python ---------------------------------------------------------------------------- 5.1. 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" (the LaTeX file Doc/ext.tex). Also read the chapter on dynamic loading. There's more information on this in each of the Python books: Programming Python, Internet Programming with Python, and Das Python-Buch (in German). ---------------------------------------------------------------------------- 5.2. Can I create my own functions in C++? Yes, using the C-compatibility features found in C++. Basically you 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. ---------------------------------------------------------------------------- 5.3. 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 which is executed in the context of 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. ---------------------------------------------------------------------------- 5.4. How can I evaluate an arbitrary Python expression from C? Call the function PyRun_String() from the previous question with the start symbol eval_input (Py_eval_input starting with 1.5a1); it parses an expression, evaluates it and returns its value. ---------------------------------------------------------------------------- 5.5. 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; similar for lists with 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 strlen() is not safe). To test which type an object is, 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 for example interfacing with any kind of Python sequence (e.g. lists and tuples) using calls like PySequence_Length(), PySequence_GetItem(), etc.) as well as many other useful protocols. ---------------------------------------------------------------------------- 5.6. 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. Similar for lists with 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. ---------------------------------------------------------------------------- 5.7. How do I call an object's method from C? Here's a function (untested) that might become part of the next release in some form. It uses to allow passing the argument list on to vmkvalue(): object *call_method(object *inst, char *methodname, char *format, ...) { object *method; object *args; object *result; va_list va; method = getattr(inst, methodname); if (method == NULL) return NULL; va_start(va, format); args = vmkvalue(format, va); va_end(va); if (args == NULL) { DECREF(method); return NULL; } result = call_object(method, args); DECREF(method); DECREF(args); return result; } This works for any instance that has methods -- whether built-in or user-defined. You are responsible for eventually 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 = call_method(f, "seek", "(OO)", 10, 0); if (res == NULL) { ... an exception occurred ... } else { DECREF(res); } Note that since call_object() 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)". ---------------------------------------------------------------------------- 5.8. How do I catch the output from PyErr_Print() (or anything that prints to stdout/stderr)? (Due to Mark Hammond): In Python code, define an object that supports the "write()" method. Redirect sys.stdout and sys.stderr to this object. 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! ---------------------------------------------------------------------------- 5.9. 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. ---------------------------------------------------------------------------- 5.10. 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 (Doc/ext.tex, see also http://www.python.org/doc/). Realize that for the Python run-time system, there isn't a whole lot of difference between C and C++ -- so the strategy to build a new Python type around a C structure (pointer) type will also work for C++ objects. A useful automated approach (which also works for C) is SWIG: http://www.cs.utah.edu/~beazley/SWIG/. ---------------------------------------------------------------------------- 5.11. mSQLmodule (or other old module) won't build with Python 1.5 (or later) Since python-1.4 "Python.h" will have the file includes needed in an extension module. Backward compatibility is dropped after version 1.4 and therefore mSQLmodule.c will not build as "allobjects.h" cannot be found. The following change in mSQLmodule.c is harmless when building it with 1.4 and necessary when doing so for later python versions: Remove lines: #include "allobjects.h" #include "modsupport.h" And insert instead: #include "Python.h" You may also need to add #include "rename2.h" if the module uses "old names". This may happen with other ancient python modules as well, and the same fix applies. ---------------------------------------------------------------------------- 5.12. I added a module using the Setup file and the make fails! Huh? Setup must end in a newline, if there is no newline there it gets very sad. Aside from this possibility, maybe you have other non-Python-specific linkage problems. ---------------------------------------------------------------------------- 5.13. I want to compile a Python module on my Red Hat Linux system, but some files are missing. Red Hat's RPM for Python doesn't include the /usr/lib/python1.x/config/ directory, which contains various files required for compiling Python extensions. Install the python-devel RPM to get the necessary files. ---------------------------------------------------------------------------- 5.14. 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 will be raised. ---------------------------------------------------------------------------- -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From python-announce@python.org Thu Jul 8 00:27:55 1999 From: python-announce@python.org (Markus Fleck) Date: Wed, 07 Jul 99 23:27:55 GMT Subject: Python Language FAQ - Section 7 Message-ID: This FAQ newsgroup posting has been automatically converted from an HTML snapshot of the original Python FAQ; please refer to the original "Python FAQ Wizard" at if source code snippets given in this document do not work - incidentally some formatting information may have been lost during the conversion. ---------------------------------------------------------------------------- The whole Python FAQ - Section 7 Last changed on Mon Jun 28 19:36:09 1999 EDT (Entries marked with ** were changed within the last 24 hours; entries marked with * were changed within the last 7 days.) ---------------------------------------------------------------------------- 7. Using Python on non-UNIX platforms 7.1. Is there a Mac version of Python? 7.2. Are there DOS and Windows versions of Python? 7.3. Is there an OS/2 version of Python? 7.4. Is there a VMS version of Python? 7.5. What about IBM mainframes, or other non-UNIX platforms? 7.6. Where are the source or Makefiles for the non-UNIX versions? 7.7. What is the status and support for the non-UNIX versions? 7.8. I have a PC version but it appears to be only a binary. Where's the library? 7.9. Where's the documentation for the Mac or PC version? 7.10. How do I create a Python program file on the Mac or PC? 7.11. How can I use Tkinter on Windows 95/NT? 7.12. cgi.py (or other CGI programming) doesn't work sometimes on NT or win95! 7.13. Why doesn't os.popen() work in PythonWin on NT? 7.14. How do I use different functionality on different platforms with the same program? 7.15. Is there an Amiga version of Python? 7.16. Why doesn't os.popen()/win32pipe.popen() work on Win9x? ---------------------------------------------------------------------------- 7. Using Python on non-UNIX platforms ---------------------------------------------------------------------------- 7.1. Is there a Mac version of Python? Yes, see the "mac" subdirectory of the distribution sites, e.g. ftp://ftp.python.org/pub/python/mac/. ---------------------------------------------------------------------------- 7.2. Are there DOS and Windows versions of Python? Yes. The core windows binaries are available from http://www.python.org/windows/. There is a plethora of Windows extensions available, including a large number of not-always-compatible GUI toolkits. The core binaries include the standard Tkinter GUI extension. Most windows extensions can be found (or referenced) at http://www.python.org/windows/ Windows 3.1/DOS support seems to have dropped off recently. You may need to settle for an old version of Python one these platforms. One such port is WPY WPY: Ports to DOS, Windows 3.1(1), Windows 95, Windows NT and OS/2. Also contains a GUI package that offers portability between Windows (not DOS) and Unix, and native look and feel on both. ftp://ftp.python.org/pub/python/wpy/. ---------------------------------------------------------------------------- 7.3. Is there an OS/2 version of Python? Yes, see the "pc" and "wpy" subdirectory of the distribution sites (see above). ---------------------------------------------------------------------------- 7.4. Is there a VMS version of Python? Yes, there is a port of Python 1.4 to OpenVMS and a few ports of 1.2 to VMS. See ftp://ftp.python.org/pub/python/contrib/Porting/vms/. Uwe Zessin has ported Python 1.5.x to OpenVMS. See http://decus.decus.de/~zessin/. ---------------------------------------------------------------------------- 7.5. What about IBM mainframes, or other non-UNIX platforms? I haven't heard about these, except I remember hearing about an OS/9 port and a port to Vxworks (both operating systems for embedded systems). If you're interested in any of this, go directly to the newsgroup and ask there, you may find exactly what you need. For example, a port to MPE/iX 5.0 on HP3000 computers was just announced, see http://www.allegro.com/software/. ---------------------------------------------------------------------------- 7.6. Where are the source or Makefiles for the non-UNIX versions? The standard sources can (almost) be used. Additional sources can be found in the platform-specific subdirectories of the distribution. ---------------------------------------------------------------------------- 7.7. What is the status and support for the non-UNIX versions? I don't have access to most of these platforms, so in general I am dependent on material submitted by volunteers. However I strive to integrate all changes needed to get it to compile on a particular platform back into the standard sources, so porting of the next version to the various non-UNIX platforms should be easy. ---------------------------------------------------------------------------- 7.8. I have a PC version but it appears to be only a binary. Where's the library? If you are running any version of Windows, then you have the wrong distribution. The FAQ lists current Windows versions. Notably, Pythonwin and wpy provide fully functional installations. But if you are sure you have the only distribution with a hope of working on your system, then... You still need to copy the files from the distribution directory "python/Lib" to your system. If you don't have the full distribution, you can get the file lib.tar.gz from most ftp sites carrying Python; this is a subset of the distribution containing just those files, e.g. ftp://ftp.python.org/pub/python/src/lib1.4.tar.gz. Once you have installed the library, you need to point sys.path to it. Assuming the library is in C:\misc\python\lib, the following commands will point your Python interpreter to it (note the doubled backslashes -- you can also use single forward slashes instead): >>> import sys >>> sys.path.insert(0, 'C:\\misc\\python\\lib') >>> For a more permanent effect, set the environment variable PYTHONPATH, as follows (talking to a DOS prompt): C> SET PYTHONPATH=C:\misc\python\lib ---------------------------------------------------------------------------- 7.9. Where's the documentation for the Mac or PC version? The documentation for the Unix version also applies to the Mac and PC versions. Where applicable, differences are indicated in the text. ---------------------------------------------------------------------------- 7.10. How do I create a Python program file on the Mac or PC? Use an external editor. On the Mac, BBEdit seems to be a popular no-frills text editor. I work like this: start the interpreter; edit a module file using BBedit; import and test it in the interpreter; edit again in BBedit; then use the built-in function reload() to re-read the imported module; etc. In the 1.4 distribution you will find a BBEdit extension that makes life a little easier: it can tell the interpreter to execute the current window. See :Mac:Tools:BBPy:README. Regarding the same question for the PC, Kurt Wm. Hemr writes: "While anyone with a pulse could certainly figure out how to do the same on MS-Windows, I would recommend the NotGNU Emacs clone for MS-Windows. Not only can you easily resave and "reload()" from Python after making changes, but since WinNot auto-copies to the clipboard any text you select, you can simply select the entire procedure (function) which you changed in WinNot, switch to QWPython, and shift-ins to reenter the changed program unit." If you're using Windows95 or Windows NT, you should also know about PythonWin, which provides a GUI framework, with an mouse-driven editor, an object browser, and a GUI-based debugger. See http://www.python.org/ftp/python/pythonwin/ for details. ---------------------------------------------------------------------------- 7.11. How can I use Tkinter on Windows 95/NT? Starting from Python 1.5, it's very easy -- just download and install Python and Tcl/Tk and you're in business. See http://www.python.org/download/download_windows.html One warning: don't attempt to use Tkinter from PythonWin (Mark Hammond's IDE). Use it from the command line interface (python.exe) or the windowless interpreter (pythonw.exe). ---------------------------------------------------------------------------- 7.12. 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 (eg, GIF) responses may get garbled (resulting in, eg, a "broken image"). ---------------------------------------------------------------------------- 7.13. 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() ---------------------------------------------------------------------------- 7.14. How do I use different functionality on different platforms with the same program? Remember that Python is extremely dynamic and that you can use this dynamism to configure a program at run-time to use available functionality on different platforms. For example you can test the sys.platform and import different modules based on its value. import sys if sys.platform == "win32": import win32pipe popen = win32pipe.popen else: import os popen = os.popen (See FAQ 7.13 for an explanation of why you might want to do something like this.) Also you can try to import a module and use a fallback if the import fails: try: import really_fast_implementation choice = really_fast_implementation except ImportError: import slower_implementation choice = slower_implementation ---------------------------------------------------------------------------- 7.15. Is there an Amiga version of Python? Yes. See the AmigaPython homepage at http://www.bigfoot.com/~irmen/python.html. ---------------------------------------------------------------------------- 7.16. 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. ---------------------------------------------------------------------------- -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From python-announce@python.org Thu Jul 8 00:27:38 1999 From: python-announce@python.org (Markus Fleck) Date: Wed, 07 Jul 99 23:27:38 GMT Subject: Python Language FAQ - Section 4 Message-ID: This FAQ newsgroup posting has been automatically converted from an HTML snapshot of the original Python FAQ; please refer to the original "Python FAQ Wizard" at if source code snippets given in this document do not work - incidentally some formatting information may have been lost during the conversion. ---------------------------------------------------------------------------- The whole Python FAQ - Section 4 Last changed on Mon Jun 28 19:36:09 1999 EDT (Entries marked with ** were changed within the last 24 hours; entries marked with * were changed within the last 7 days.) ---------------------------------------------------------------------------- 4. Programming in Python 4.1. Is there a source code level debugger with breakpoints, step, etc.? 4.2. Can I create an object class with some methods implemented in C and others in Python (e.g. through inheritance)? (Also phrased as: Can I use a built-in type as base class?) 4.3. Is there a curses/termcap package for Python? 4.4. Is there an equivalent to C's onexit() in Python? 4.5. When I define a function nested inside another function, the nested function seemingly can't access the local variables of the outer function. What is going on? How do I pass local data to a nested function? 4.6. How do I iterate over a sequence in reverse order? 4.7. My program is too slow. How do I speed it up? 4.8. When I have imported a module, then edit it, and import it again (into the same Python process), the changes don't seem to take place. What is going on? 4.9. How do I find the current module name? 4.10. I have a module in which I want to execute some extra code when it is run as a script. How do I find out whether I am running as a script? 4.11. I try to run a program from the Demo directory but it fails with ImportError: No module named ...; what gives? 4.12. I have successfully built Python with STDWIN but it can't find some modules (e.g. stdwinevents). 4.13. What GUI toolkits exist for Python? 4.14. Are there any interfaces to database packages in Python? 4.15. Is it possible to write obfuscated one-liners in Python? 4.16. Is there an equivalent of C's "?:" ternary operator? 4.17. My class defines __del__ but it is not called when I delete the object. 4.18. How do I change the shell environment for programs called using os.popen() or os.system()? Changing os.environ doesn't work. 4.19. What is a class? 4.20. What is a method? 4.21. What is self? 4.22. What is an unbound method? 4.23. How do I call a method defined in a base class from a derived class that overrides it? 4.24. How do I call a method from a base class without using the name of the base class? 4.25. How can I organize my code to make it easier to change the base class? 4.26. How can I find the methods or attributes of an object? 4.27. I can't seem to use os.read() on a pipe created with os.popen(). 4.28. How can I create a stand-alone binary from a Python script? 4.29. What WWW tools are there for Python? 4.30. How do I run a subprocess with pipes connected to both input and output? 4.31. How do I call a function if I have the arguments in a tuple? 4.32. How do I enable font-lock-mode for Python in Emacs? 4.33. Is there a scanf() or sscanf() equivalent? 4.34. Can I have Tk events handled while waiting for I/O? 4.35. How do I write a function with output parameters (call by reference)? 4.36. Please explain the rules for local and global variables in Python. 4.37. How can I have modules that mutually import each other? 4.38. How do I copy an object in Python? 4.39. How to implement persistent objects in Python? (Persistent == automatically saved to and restored from disk.) 4.40. I try to use __spam and I get an error about _SomeClassName__spam. 4.41. How do I delete a file? And other file questions. 4.42. How to modify urllib or httplib to support HTTP/1.1? 4.43. Unexplicable syntax errors in compile() or exec. 4.44. How do I convert a string to a number? 4.45. How do I convert a number to a string? 4.46. How do I copy a file? 4.47. How do I check if an object is an instance of a given class or of a subclass of it? 4.48. What is delegation? 4.49. How do I test a Python program or component. 4.50. My multidimensional list (array) is broken! What gives? 4.51. I want to do a complicated sort: can you do a Schwartzian Transform in Python? 4.52. How to convert between tuples and lists? 4.53. Files retrieved with urllib contain leading garbage that looks like email headers. 4.54. How do I get a list of all instances of a given class? 4.55. A regular expression fails with regex.error: match failure. 4.56. I can't get signal handlers to work. 4.57. I can't use a global variable in a function? Help! 4.58. What's a negative index? Why doesn't list.insert() use them? 4.59. How can I sort one list by values from another list? 4.60. Why doesn't dir() work on builtin types like files and lists? 4.61. How can I mimic CGI form submission (METHOD=POST)? 4.62. If my program crashes with a bsddb (or anydbm) database open, it gets corrupted. How come? 4.63. How do I make a Python script executable on Unix? 4.64. How do you remove duplicates from a list? 4.65. Are there any known year 2000 problems in Python? 4.66. I want a version of map that applies a method to a sequence of objects! Help! 4.67. How do I generate random numbers in Python? 4.68. How do I access the serial (RS232) port? 4.69. Images on Tk-Buttons don't work in Py15? 4.70. Where is the math.py (socket.py, regex.py, etc.) source file? 4.71. How do I send mail from a Python script? 4.72. How do I avoid blocking in connect() of a socket? 4.73. How do I specify hexadecimal and octal integers? 4.74. How to get a single keypress at a time? 4.75. How can I overload constructors (or methods) in Python? 4.76. How do I pass keyword arguments from one method to another? 4.77. What module should I use to help with generating HTML? 4.78. How do I create documentation from doc strings? 4.79. How do I read (or write) binary data? 4.80. I can't get key bindings to work in Tkinter 4.81. "import crypt" fails 4.82. Are there coding standards or a style guide for Python programs? 4.83. How do I freeze Tkinter applications? 4.84. How do I create static class data and static class methods? 4.85. __import__('x.y.z') returns ; how do I get z? 4.86. Basic thread wisdom 4.87. Why doesn't closing sys.stdout (stdin, stderr) really close it? 4.88. What kinds of global value mutation are thread-safe? 4.89. How do I modify a string in place? 4.90. How to pass on keyword/optional parameters/arguments ---------------------------------------------------------------------------- 4. Programming in Python ---------------------------------------------------------------------------- 4.1. Is there a source code level debugger with breakpoints, step, etc.? Yes. Check out module pdb. It is documented in the Library Reference Manual; pdb.help() also prints the documentation. You can write your own debugger by using the code for pdb as an example. Pythonwin also has a GUI debugger available, based on bdb, which colors breakpoints and has quite a few cool features (including debugging non-Pythonwin programs). The interface needs some work, but is interesting none the less. A reference can be found in http://www.python.org/ftp/python/pythonwin/pwindex.html Richard Wolff has created a modified version of pdb, called Pydb, for use with the popular Data Display Debugger (DDD). Pydb can be found at http://daikon.tuc.noao.edu/python/, and DDD can be found at http://www.cs.tu-bs.de/softech/ddd/ ---------------------------------------------------------------------------- 4.2. Can I create an object class with some methods implemented in C and others in Python (e.g. through inheritance)? (Also phrased as: Can I use a built-in type as base class?) No, but you can easily create a Python class which serves as a wrapper around a built-in object, e.g. (for dictionaries): # A user-defined class behaving almost identical # to a built-in dictionary. class UserDict: def __init__(self): self.data = {} def __repr__(self): return repr(self.data) def __cmp__(self, dict): if type(dict) == type(self.data): return cmp(self.data, dict) else: return cmp(self.data, dict.data) def __len__(self): return len(self.data) def __getitem__(self, key): return self.data[key] def __setitem__(self, key, item): self.data[key] = item def __delitem__(self, key): del self.data[key] def keys(self): return self.data.keys() def items(self): return self.data.items() def values(self): return self.data.values() def has_key(self, key): return self.data.has_key(key) A2. See Jim Fulton's ExtensionClass for an example of a mechanism which allows you to have superclasses which you can inherit from in Python -- that way you can have some methods from a C superclass (call it a mixin) and some methods from either a Python superclass or your subclass. See http://www.digicool.com/papers/ExtensionClass.html. ---------------------------------------------------------------------------- 4.3. Is there a curses/termcap package for Python? [Andrew Kuchling] The standard Python distribution comes with a curses module in the Modules/ subdirectory, though it's not compiled by default. However, that module only supports plain curses; you can't use ncurses features like colors with it (though it will link with ncurses). Oliver Andrich has an enhanced module that does support such features; there's a version available at http://andrich.net/python/selfmade.html#ncursesmodule . ---------------------------------------------------------------------------- 4.4. Is there an equivalent to C's onexit() in Python? Yes, if you import sys and assign a function to sys.exitfunc, it will be called when your program exits, is killed by an unhandled exception, or (on UNIX) receives a SIGHUP or SIGTERM signal. ---------------------------------------------------------------------------- 4.5. When I define a function nested inside another function, the nested function seemingly can't access the local variables of the outer function. What is going on? How do I pass local data to a nested function? Python does not have arbitrarily nested scopes. When you need to create a function that needs to access some data which you have available locally, create a new class to hold the data and return a method of an instance of that class, e.g.: class MultiplierClass: def __init__(self, factor): self.factor = factor def multiplier(self, argument): return argument * self.factor def generate_multiplier(factor): return MultiplierClass(factor).multiplier twice = generate_multiplier(2) print twice(10) # Output: 20 An alternative solution uses default arguments, e.g.: def generate_multiplier(factor): def multiplier(arg, fact = factor): return arg*fact return multiplier twice = generate_multiplier(2) print twice(10) # Output: 20 ---------------------------------------------------------------------------- 4.6. 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... ---------------------------------------------------------------------------- 4.7. 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; I would consider rewriting parts in C only 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 may consider using a more direct way, e.g. 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 avoid the overhead of kernel system calls. Thus CGI scripts that write all output in "one shot" may be notably faster than those that write lots of small pieces of output. Also, be sure to use "aggregate" operations where appropriate. For example the "slicing" feature allows programs to chop up lists and other sequence objects in a single tick of the interpreter 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 map() function, particularly used with builtin methods or builtin functions can be a convenient accellerator. For example to pair the elements of two lists together: >>> map(None, [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 map operation completes very quickly in such cases. Other examples of aggregate operations include the join, joinfields, split, and splitfields methods of the standard string builtin module. For example if s1..s7 are large (10K+) strings then string.joinfields([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 joinfields does all copying in one pass. For manipulating strings also consider the regular expression libraries and the "substitution" operations String % tuple and String % dictionary. Also be sure to use the list.sort builtin method to do sorting, and see FAQ's 4.51 and 4.59 for examples of moderately advanced usage -- list.sort beats other techniques for sorting in all but the most extreme circumstances. There are many other aggregate operations available in the standard libraries and in contributed libraries and extensions. 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 (profile.run) 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 (A) list = map(ff, oldlist) or (B) 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 (A) to list = ffseq(oldlist) and (B) to for value in ffseq(sequence): ...do something with value... Other single calls 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 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. For an anecdote related to optimization, see http://www.python.org/doc/essays/list2str.html ---------------------------------------------------------------------------- 4.8. When I have imported a module, then edit it, and import it again (into the same Python process), the changes don't seem to take place. What is going on? For reasons of efficiency as well as consistency, Python only reads the module file on the first time a module is imported. (Otherwise a program consisting of many modules, each of which imports the same basic module, would read the basic module over and over again.) 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. ---------------------------------------------------------------------------- 4.9. 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__' you are running as a script. ---------------------------------------------------------------------------- 4.10. I have a module in which I want to execute some extra code when it is run as a script. How do I find out whether I am running as a script? See the previous question. E.g. if you put the following on the last line of your module, main() is called only when your module is running as a script: if __name__ == '__main__': main() ---------------------------------------------------------------------------- 4.11. I try to run a program from the Demo directory but it fails with ImportError: No module named ...; what gives? This is probably an optional module (written in C!) which hasn't been configured on your system. This especially happens with modules like "Tkinter", "stdwin", "gl", "Xt" or "Xm". For Tkinter, STDWIN and many other modules, see Modules/Setup.in for info on how to add these modules to your Python, if it is possible at all. Sometimes you will have to ftp and build another package first (e.g. Tcl and Tk for Tkinter). Sometimes the module only works on specific platforms (e.g. gl only works on SGI machines). NOTE: if the complaint is about "Tkinter" (upper case T) and you have already configured module "tkinter" (lower case t), the solution is not to rename tkinter to Tkinter or vice versa. There is probably something wrong with your module search path. Check out the value of sys.path. For X-related modules (Xt and Xm) you will have to do more work: they are currently not part of the standard Python distribution. You will have to ftp the Extensions tar file, i.e. ftp://ftp.python.org/pub/python/src/X-extension.tar.gz and follow the instructions there. See also the next question. ---------------------------------------------------------------------------- 4.12. I have successfully built Python with STDWIN but it can't find some modules (e.g. stdwinevents). There's a subdirectory of the library directory named 'stdwin' which should be in the default module search path. There's a line in Modules/Setup(.in) that you have to enable for this purpose -- unfortunately in the latest release it's not near the other STDWIN-related lines so it's easy to miss it. ---------------------------------------------------------------------------- 4.13. What GUI toolkits exist for Python? Depending on what platform(s) you are aiming at, there are several. Currently supported solutions: There's a neat object-oriented interface to the Tcl/Tk widget set, called Tkinter. It is part of the standard Python distribution and well-supported -- all you need to do is build and install Tcl/Tk and enable the _tkinter module and the TKPATH definition in Modules/Setup when building Python. This is probably the easiest to install and use, and the most complete widget set. It is also very likely that in the future the standard Python GUI API will be based on or at least look very much like the Tkinter interface. For more info about Tk, including pointers to the source, see the Tcl/Tk home page at http://www.scriptics.com. Tcl/Tk is now fully portable to the Mac and Windows platforms (NT and 95 only); you need Python 1.4beta3 or later and Tk 4.1patch1 or later. There's an interface to X11, including the Athena and Motif widget sets (and a few individual widgets, like Mosaic's HTML widget and SGI's GL widget) available from ftp://ftp.python.org/pub/python/src/X-extension.tar.gz. Support by Sjoerd Mullender sjoerd@cwi.nl. On top of the X11 interface there's the (recently revived) vpApp toolkit by Per Spilling, now also maintained by Sjoerd Mullender sjoerd@cwi.nl. See ftp://ftp.cwi.nl/pub/sjoerd/vpApp.tar.gz. The Mac port has a rich and ever-growing set of modules that support the native Mac toolbox calls. See the documentation that comes with the Mac port. See ftp://ftp.python.org/pub/python/mac. Support by Jack Jansen jack@cwi.nl. The NT port supported by Mark Hammond MHammond@skippinet.com.au (see question 7.2) includes an interface to the Microsoft Foundation Classes and a Python programming environment using it that's written mostly in Python. See ftp://ftp.python.org/pub/python/pythonwin/. There's an object-oriented GUI based on the Microsoft Foundation Classes model called WPY, supported by Jim Ahlstrom jim@interet.com. Programs written in WPY run unchanged and with native look and feel on Windows NT/95, Windows 3.1 (using win32s), and on Unix (using Tk). Source and binaries for Windows and Linux are available in ftp://ftp.python.org/pub/python/wpy/. Obsolete or minority solutions: There's an interface to wxWindows. wxWindows is a portable GUI class library written in C++. It supports XView, Motif, MS-Windows as targets. There is some support for Macs and CURSES as well. wxWindows preserves the look and feel of the underlying graphics toolkit. See the wxPython WWW page at http://www.aiai.ed.ac.uk/~jacs/wx/wxpython/wxpython.html. Support for wxPython (by Harri Pasanen pa@tekla.fi) appears to have a low priority. For SGI IRIX only, there are unsupported interfaces to the complete GL (Graphics Library -- low level but very good 3D capabilities) as well as to FORMS (a buttons-and-sliders-etc package built on top of GL by Mark Overmars -- ftp'able from ftp://ftp.cs.ruu.nl/pub/SGI/FORMS/). This is probably also becoming obsolete, as OpenGL takes over. There's an interface to STDWIN, a platform-independent low-level windowing interface for Mac and X11. This is totally unsupported and rapidly becoming obsolete. The STDWIN sources are at ftp://ftp.cwi.nl/pub/stdwin/. (For info about STDWIN 2.0, please refer to Steven Pemberton steven@cwi.nl -- I believe it is also dead.) There is an interface to WAFE, a Tcl interface to the X11 Motif and Athena widget sets. WAFE is at http://www.wu-wien.ac.at/wafe/wafe.html. (The Fresco port that was mentioned in earlier versions of this FAQ no longer seems to exist. Inquire with Mark Linton.) ---------------------------------------------------------------------------- 4.14. Are there any interfaces to database packages in Python? There's a whole collection of them in the contrib area of the ftp server, see http://www.python.org/ftp/python/contrib/Database/. ---------------------------------------------------------------------------- 4.15. Is it possible to write obfuscated one-liners in Python? Yes. 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! ---------------------------------------------------------------------------- 4.16. Is there an equivalent of C's "?:" ternary operator? Not directly. 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'. ---------------------------------------------------------------------------- 4.17. 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 pointer and each parent has a list of children) the reference counts will never go back to zero. You'll have to define an explicit close() method which removes those pointers. Please don't ever call __del__ directly -- __del__ should call close() and close() should make sure that it can be called more than once for the same object. If the object has ever been a local variable (or argument, which is really the same thing) to 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, deleting (better: assigning None to) sys.exc_traceback will take care of this. If a stack was printed for an unhandled exception in an interactive interpreter, delete sys.last_traceback instead. There is code that deletes all objects when the interpreter exits, but it is not called if your Python has been configured to support threads (because other threads may still be active). You can define your own cleanup function using sys.exitfunc (see question 4.4). Finally, if your __del__ method raises an exception, this will be ignored. Starting with Python 1.4beta3, a warning message is printed to sys.stderr when this happens. See also question 6.14 for a discussion of the possibility of adding true garbage collection to Python. ---------------------------------------------------------------------------- 4.18. How do I change the shell environment for programs called using os.popen() or os.system()? Changing os.environ doesn't work. You must be using either a version of python before 1.4, or on a (rare) system that doesn't have the putenv() library function. Before Python 1.4, modifying the environment passed to subshells was left out of the interpreter because there seemed to be no well-established portable way to do it (in particular, some systems, have putenv(), others have setenv(), and some have none at all). As of Python 1.4, almost all Unix systems do have putenv(), and so does the Win32 API, and thus the os module was modified so that changes to os.environ are trapped and the corresponding putenv() call is made. ---------------------------------------------------------------------------- 4.19. What is a class? A class is the particular object type that is created by executing a class statement. Class objects are used as templates, to create class instance objects, which embody both the data structure and program routines specific to a datatype. ---------------------------------------------------------------------------- 4.20. What is a method? A method is a function that you normally call as x.name(arguments...) for some object x. The term is used for methods of classes and class instances as well as for methods of built-in objects. (The latter have a completely different implementation and only share the way their calls look in Python code.) Methods of classes (and class instances) are defined as functions inside the class definition. ---------------------------------------------------------------------------- 4.21. What is self? Self is merely a conventional name for the first argument of a method -- i.e. a function defined inside a class definition. 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). ---------------------------------------------------------------------------- 4.22. What is an unbound method? An unbound method is a method defined in a class that is not yet bound to an instance. You get an unbound method if you ask for a class attribute that happens to be a function. You get a bound method if you ask for an instance attribute. A bound method knows which instance it belongs to and calling it supplies the instance automatically; an unbound method only knows which class it wants for its first argument (a derived class is also OK). Calling an unbound method doesn't "magically" derive the first argument from the context -- you have to provide it explicitly. Trivia note regarding bound methods: each reference to a bound method of a particular object creates a bound method object. If you have two such references (a = inst.meth; b = inst.meth), they will compare equal (a == b) but are not the same (a is not b). ---------------------------------------------------------------------------- 4.23. How do I call a method defined in a base class from a derived class that overrides it? If your class definition starts with "class Derived(Base): ..." then 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 (see previous question). ---------------------------------------------------------------------------- 4.24. How do I call a method from a base class without using the name of the base class? DON'T DO THIS. REALLY. I MEAN IT. It appears that you could call self.__class__.__bases__[0].meth(self, arguments...) but this fails when a doubly-derived method is derived from your class: for its instances, self.__class__.__bases__[0] is your class, not its base class -- so (assuming you are doing this from within Derived.meth) you would start a recursive call. Often when you want to do this you are forgetting that classes are first class in Python. You can "point to" the class you want to delegate an operation to either at the instance or at the subclass level. For example if you want to use a "glorp" operation of a superclass you can point to the right superclass to use. class subclass(superclass1, superclass2, superclass3): delegate_glorp = superclass2 ... def glorp(self, arg1, arg2): ... subclass specific stuff ... self.delegate_glorp.glorp(self, arg1, arg2) ... class subsubclass(subclass): delegate_glorp = superclass3 ... Note, however that setting delegate_glorp to subclass in subsubclass would cause an infinite recursion on subclass.delegate_glorp. Careful! Maybe you are getting too fancy for your own good. Consider simplifying the design (?). ---------------------------------------------------------------------------- 4.25. 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) ... ---------------------------------------------------------------------------- 4.26. How can I find the methods or attributes of an object? This depends on the object type. For an instance x of a user-defined class, instance attributes are found in the dictionary x.__dict__, and methods and attributes defined by its class are found in x.__class__.__bases__[i].__dict__ (for i in range(len(x.__class__.__bases__))). You'll have to walk the tree of base classes to find all class methods and attributes. Many, but not all built-in types define a list of their method names in x.__methods__, and if they have data attributes, their names may be found in x.__members__. However this is only a convention. For more information, read the source of the standard (but undocumented) module newdir. ---------------------------------------------------------------------------- 4.27. I can't seem to use os.read() on a pipe created with os.popen(). os.read() is a low-level function which takes a file descriptor (a small integer). os.popen() creates a high-level file object -- the same type used for sys.std{in,out,err} and 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). ---------------------------------------------------------------------------- 4.28. How can I create a stand-alone binary from a Python script? The "freeze" tool in "Tools/freeze/" does what you want. See the README. This works by scanning your source recursively for import statements (both forms) and looking for the modules on the standard Python path as well as in the source directory (for built-in modules). It then "compiles" the modules written in Python to 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. Hint: the freeze program only works if your script's filename ends in ".py". ---------------------------------------------------------------------------- 4.29. What WWW tools are there for Python? See the chapter titled "Internet and WWW" in the Library Reference Manual. There's also a web browser written in Python, called Grail -- see http://grail.cnri.reston.va.us/grail/. ---------------------------------------------------------------------------- 4.30. How do I run a subprocess with pipes connected to both input and output? Use the standard 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 can easily have been written to never explicitly flush its output, even if it is interactive, since flushing is normally automatic. 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 data is infinite in size, the easiest (and often the most efficient!) 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 function mktemp() which generates unique temporary file names. 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. There is some undocumented code to use these in the library module pty.py -- I'm afraid you're on your own here. A different answer is a Python interface to Don Libes' "expect" library. A Python extension that interfaces to expect is called "expy" and available from ftp://ftp.python.org/pub/python/contrib/System/. A pure Python solution that works like expect is PIPE by John Croix. A prerelease of PIPE is available from ftp://ftp.python.org/pub/python/contrib/System/. ---------------------------------------------------------------------------- 4.31. How do I call a function if I have the arguments in a tuple? Use the built-in function apply(). For instance, func(1, 2, 3) is equivalent to args = (1, 2, 3) apply(func, args) Note that func(args) is not the same -- it calls func() with exactly one argument, the tuple args, instead of three arguments, the integers 1, 2 and 3. ---------------------------------------------------------------------------- 4.32. How do I enable font-lock-mode for Python in Emacs? If you are using XEmacs 19.14 or later, any XEmacs 20, FSF Emacs 19.34 or any Emacs 20, font-lock should work automatically for you if you are using the latest python-mode.el. If you are using an older version of XEmacs or Emacs you will need to put this in your .emacs file: (defun my-python-mode-hook () (setq font-lock-keywords python-font-lock-keywords) (font-lock-mode 1)) (add-hook 'python-mode-hook 'my-python-mode-hook) ---------------------------------------------------------------------------- 4.33. 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 string.split(), and to convert decimal strings to numeric values using string.atoi(), string.atol() or string.atof(). (Python's atoi() is 32-bit and its atol() is arbitrary precision.) If you want to use another delimiter than whitespace, use string.splitfield() (possibly combining it with string.strip() which removes surrounding whitespace from a string). For more complicated input parsing, regular expressions (see module regex) are better suited and more powerful than C's sscanf(). There's a contributed module that emulates sscanf(), by Steve Clift; see contrib/Misc/sscanfmodule.c of the ftp site: http://www.python.org/ftp/python/contrib/Misc/sscanfmodule.c ---------------------------------------------------------------------------- 4.34. 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). ---------------------------------------------------------------------------- 4.35. How do I write a function with output parameters (call by reference)? [Mark Lutz] The thing to remember is 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. But you can simulate it in a number of ways: 1) By using global variables; but you probably shouldn't :-) 2) 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 3) By returning a tuple, holding the final values of arguments: 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 4) And other ideas that fall-out from Python's object model. For instance, it might be clearer to pass in a mutable dictionary: 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 But there's probably no good reason to get this complicated :-). [Python's author favors solution 3 in most cases.] ---------------------------------------------------------------------------- 4.36. Please explain the rules for local and global variables in Python. [Ken Manheimer] In Python, procedure variables are implicitly global, unless they are assigned anywhere within the block. In that case they are implicitly local, and you need to explicitly declare them as 'global'. Though a bit surprising at first, a moment's consideration explains this. On one hand, requirement of 'global' for assigned vars provides a bar against unintended side-effects. On the other hand, if global were required for all global references, you'd be using global all the time. Eg, 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. ---------------------------------------------------------------------------- 4.37. How can I have modules that mutually import each other? Jim Roskind recommends the following order in each module: First: all exports (like globals, functions, and classes that don't need imported base classes). Then: all import statements. Finally: all active code (including globals that are initialized from imported values). Python's author doesn't like this approach much because the imports appear in a strange place, but has to admit that it works. His recommended strategy is to avoid all uses of "from import *" (so everything from an imported module is referenced as .) and to place all code inside functions. Initializations of global variables and class variables should use constants or built-in functions only. ---------------------------------------------------------------------------- 4.38. How do I copy an object in Python? There is no generic copying operation built into Python, however most object types have some way to create a clone. Here's how for the most common objects: For immutable objects (numbers, strings, tuples), cloning is unnecessary since their value can't change. For lists (and generally for mutable sequence types), a clone is created by the expression l[:]. For dictionaries, the following function returns a clone: def dictclone(o): n = {} for k in o.keys(): n[k] = o[k] return n Finally, for generic objects, the "copy" module defines two functions for copying objects. copy.copy(x) returns a copy as shown by the above rules. copy.deepcopy(x) also copies the elements of composite objects. See the section on this module in the Library Reference Manual. ---------------------------------------------------------------------------- 4.39. How to implement persistent objects in Python? (Persistent == automatically saved to and restored from disk.) The library module "pickle" now solves this in a very general way (though you still can't store things like open files, sockets or windows), and the library module "shelve" uses pickle and (g)dbm to create persistent mappings containing arbitrary Python objects. For possibly better performance also look for the latest version of the relatively recent 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 (on some machines). This often beats doing something more complex and general such as using gdbm with pickle/shelve. ---------------------------------------------------------------------------- 4.40. 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. See the chapter "New in Release 1.4" in the Python Tutorial. ---------------------------------------------------------------------------- 4.41. How do I delete a file? And other file questions. Use os.remove(filename) or os.unlink(filename); for documentation, see the posix section of the library manual. They are the same, unlink() is simply the Unix name for this function. In earlier versions of Python, only os.unlink() was available. To remove a directory, use os.rmdir(); use os.mkdir() to create one. To rename a file, use os.rename(). To truncate a file, open it using f = open(filename, "r+"), and use f.truncate(offset); offset defaults to the current seek position. (The "r+" mode opens the file for reading and writing.) There's also os.ftruncate(fd, offset) for files opened with os.open() -- for advanced Unix hacks only. ---------------------------------------------------------------------------- 4.42. How to modify urllib or httplib to support HTTP/1.1? Apply the following patch to the vanilla Python 1.4 httplib.py: 41c41 < replypat = regsub.gsub('\\.', '\\\\.', HTTP_VERSION) + \ --- > replypat = regsub.gsub('\\.', '\\\\.', 'HTTP/1.[0-9]+') + \ ---------------------------------------------------------------------------- 4.43. Unexplicable syntax errors in compile() or exec. When a statement suite (as opposed to an expression) is compiled by compile(), exec or execfile(), it must end in a newline. In some cases, when the source ends in an indented block it appears that at least two newlines are required. ---------------------------------------------------------------------------- 4.44. How do I convert a string to a number? For integers, use the built-in int() function, e.g. int('144') == 144. Similarly, long() converts from string to long integer, e.g. long('144') == 144L; and float() to floating-point, e.g. float('144') == 144.0. Note that these are restricted to decimal interpretation, so that int('0144') == 144 and int('0x144') raises ValueError. For greater flexibility, or before Python 1.5, import the module string and use the string.atoi() function for integers, string.atol() for long integers, or string.atof() for floating-point. E.g., string.atoi('100', 16) == string.atoi('0x100', 0) == 256. See the library reference manual section for the string module for more details. While you could use the built-in function eval() instead of any of those, this is not recommended, because someone could pass you a Python expression that might have unwanted side effects (like reformatting your disk). ---------------------------------------------------------------------------- 4.45. 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 repr() or the backquote notation (these are equivalent). If you want a hexadecimal or octal representation, use the built-in functions hex() or oct(), respectively. For fancy formatting, use the % operator on strings, just like C printf formats, e.g. "%04d" % 144 yields '0144' and "%.3f" % (1/3.0) yields '0.333'. See the library reference manual for details. ---------------------------------------------------------------------------- 4.46. How do I copy a file? Most of the time this will do: infile = open("file.in", "rb") outfile = open("file.out", "wb") outfile.write(infile.read()) However for huge files you may want to do the reads/writes in pieces (or you may have to), and if you dig deeper you may find other technical problems. Unfortunately, there's no totally platform independent answer. On Unix, you can use os.system() to invoke the "cp" command (see your Unix manual for how it's invoked). On DOS or Windows, use os.system() to invoke the "COPY" command. On the Mac, use macostools.copy(srcpath, dstpath). It will also copy the resource fork and Finder info. There's also the shutil module which contains a copyfile() function that implements the copy loop; but in Python 1.4 and earlier it opens files in text mode, and even in Python 1.5 it still isn't good enough for the Macintosh: it doesn't copy the resource fork and Finder info. ---------------------------------------------------------------------------- 4.47. How do I check if an object is an instance of a given class or of a subclass of it? If you are developing the classes from scratch it might be better to program in a more proper object-oriented style -- instead of doing a different thing based on class membership, why not use a method and define the method differently in different classes? However, there are some legitimate situations where you need to test for class membership. In Python 1.5, you can use the built-in function isinstance(obj, cls). The following approaches can be used with earlier Python versions: An unobvious method is to raise the object as an exception and to try to catch the exception with the class you're testing for: def is_instance_of(the_instance, the_class): try: raise the_instance except the_class: return 1 except: return 0 This technique can be used to distinguish "subclassness" from a collection of classes as well try: raise the_instance except Audible: the_instance.play(largo) except Visual: the_instance.display(gaudy) except Olfactory: sniff(the_instance) except: raise ValueError, "dunno what to do with this!" This uses the fact that exception catching tests for class or subclass membership. A different approach is to test for the presence of a class attribute that is presumably unique for the given class. For instance: class MyClass: ThisIsMyClass = 1 ... def is_a_MyClass(the_instance): return hasattr(the_instance, 'ThisIsMyClass') This version is easier to inline, and probably faster (inlined it is definitely faster). The disadvantage is that someone else could cheat: class IntruderClass: ThisIsMyClass = 1 # Masquerade as MyClass ... but this may be seen as a feature (anyway, there are plenty of other ways to cheat in Python). Another disadvantage is that the class must be prepared for the membership test. If you do not "control the source code" for the class it may not be advisable to modify the class to support testability. ---------------------------------------------------------------------------- 4.48. What is delegation? Delegation refers to an object oriented technique Python programmers may implement with particular ease. Consider the following: from string import upper class UpperOut: def __init__(self, outfile): self.__outfile = outfile def write(self, str): self.__outfile.write( upper(str) ) def __getattr__(self, name): return getattr(self.__outfile, name) Here the UpperOut class redefines the write method to convert the argument string to upper case before calling the underlying self.__outfile.write method, but all other methods are delegated to the underlying self.__outfile object. The delegation is accomplished via the "magic" __getattr__ method. Please see the language reference for more information on the use of this method. Note that for more general cases delegation can get trickier. Particularly when attributes must be set as well as gotten 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. ---------------------------------------------------------------------------- 4.49. How do I test a Python program or component. First, it helps to write the program so that it may be easily tested by using good modular design. In particular 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 tractible 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 "test script interpretation" which invokes 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. For an example of a "fake" interface, the following class defines (part of) a "fake" file interface: import string testdata = "just a random sequence of characters" class FakeInputFile: data = testdata position = 0 closed = 0 def read(self, n=None): self.testclosed() p = self.position if n is None: result= self.data[p:] else: result= self.data[p: p+n] self.position = p + len(result) return result def seek(self, n, m=0): self.testclosed() last = len(self.data) p = self.position if m==0: final=n elif m==1: final=n+p elif m==2: final=len(self.data)+n else: raise ValueError, "bad m" if final<0: raise IOError, "negative seek" self.position = final def isatty(self): return 0 def tell(self): return self.position def close(self): self.closed = 1 def testclosed(self): if self.closed: raise IOError, "file closed" Try f=FakeInputFile() and test out its operations. ---------------------------------------------------------------------------- 4.50. My multidimensional list (array) is broken! What gives? You probably tried to make a multidimensional array like this. A = [[None] * 2] * 3 This makes a list containing 3 references to the same list of length two. Changes to one row will show in all rows, which is probably not what you want. The following works much better: A = [None]*3 for i in range(3): A[i] = [None] * 2 This generates a list containing 3 different lists of length two. If you feel weird, you can also do it in the following way: w, h = 2, 3 A = map(lambda i,w=w: [None] * w, range(h)) ---------------------------------------------------------------------------- 4.51. I want to do a complicated sort: can you do a Schwartzian Transform in Python? Yes, and in Python you only have to write it once: def st(List, Metric): def pairing(element, M = Metric): return (M(element), element) paired = map(pairing, List) paired.sort() return map(stripit, paired) def stripit(pair): return pair[1] This technique, attributed to Randal Schwartz, sorts the elements of a list by a metric which maps each element to its "sort value". For example, if L is a list of string then import string Usorted = st(L, string.upper) def intfield(s): return string.atoi( string.strip(s[10:15] ) ) Isorted = st(L, intfield) Usorted gives the elements of L sorted as if they were upper case, and Isorted gives the elements of L sorted by the integer values that appear in the string slices starting at position 10 and ending at position 15. Note that Isorted may also be computed by def Icmp(s1, s2): return cmp( intfield(s1), intfield(s2) ) Isorted = L[:] Isorted.sort(Icmp) but since this method computes intfield many times for each element of L, it is slower than the Schwartzian Transform. ---------------------------------------------------------------------------- 4.52. How to convert between tuples and lists? The function tuple(seq) converts any sequence 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 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. ---------------------------------------------------------------------------- 4.53. Files retrieved with urllib contain leading garbage that looks like email headers. The server is using HTTP/1.1; the vanilla httplib in Python 1.4 only recognizes HTTP/1.0. See question 4.42 for a patch. ---------------------------------------------------------------------------- 4.54. 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, but unless you're very clever, this has the disadvantage that the instances never get deleted,because your list of all instances keeps a reference to them. (The trick is to regularly inspect the reference counts of the instances you've retained, and if the reference count is below a certain level, remove it from the list. Determining that level is tricky -- it's definitely larger than 1.) ---------------------------------------------------------------------------- 4.55. A regular expression fails with regex.error: match failure. This is usually caused by too much backtracking; the regular expression engine has a fixed size stack which holds at most 4000 backtrack points. Every character matched by e.g. ".*" accounts for a backtrack point, so even a simple search like regex.match('.*x',"x"*5000) will fail. This is fixed in the re module introduced with Python 1.5; consult the Library Reference section on re for more information. ---------------------------------------------------------------------------- 4.56. I can't get signal handlers to 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): ... ---------------------------------------------------------------------------- 4.57. I can't use a global variable in a function? Help! 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 If you did, all references to x in f are local, not global by virtue of the "x=4" assignment. Any variable assigned in a function is local to that function unless it is declared global. Consequently the "print x" attempts to print an uninitialized local variable and will trigger a NameError. ---------------------------------------------------------------------------- 4.58. What's a negative index? Why doesn't list.insert() use them? 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 if the string Line ends in a newline then Line[:-1] is all of Line except the newline. Sadly the list builtin method L.insert does not observe negative indices. This feature could be considered a mistake but since existing programs depend on this feature it may stay around forever. L.insert for negative indices inserts at the start of the list. To get "proper" negative index behaviour use L[n:n] = [x] in place of the insert method. ---------------------------------------------------------------------------- 4.59. How can I sort one list by values from another list? You can sort lists of tuples. >>> list1 = ["what", "I'm", "sorting", "by"] >>> list2 = ["something", "else", "to", "sort"] >>> pairs = map(None, list1, list2) >>> pairs [('what', 'something'), ("I'm", 'else'), ('sorting', 'to'), ('by', 'sort')] >>> pairs.sort() >>> pairs [("I'm", 'else'), ('by', 'sort'), ('sorting', 'to'), ('what', 'something')] >>> result = pairs[:] >>> for i in xrange(len(result)): result[i] = result[i][1] ... >>> result ['else', 'sort', 'to', 'something'] And if you didn't understand the question, please see the example above ;c). Note that "I'm" sorts before "by" because uppercase "I" comes before lowercase "b" in the ascii order. Also see 4.51. ---------------------------------------------------------------------------- 4.60. Why doesn't dir() work on builtin types like files and lists? It should have -- and it does starting with Python 1.5 (currently in development -- see Questions 1.13 and 2.10). Using 1.4, you can find out which methods a given object supports by looking at its __methods__ attribute: >>> List = [] >>> List.__methods__ ['append', 'count', 'index', 'insert', 'remove', 'reverse', 'sort'] ---------------------------------------------------------------------------- 4.61. 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 posts" (the default) query strings must be "quoted" to, for example, change equals signs and spaces to an encoded form when they occur in name or value. Use urllib.quote to perform this quoting. 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.' ---------------------------------------------------------------------------- 4.62. 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 explcitly be closed using the close method of the database. The underlying libdb package caches database contents which need to be converted to on-disk form and written, unlike regular open files which already have the on-disk bits in the kernel's write buffer, where they can just be dumped by the kernel with the program exits. 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. ---------------------------------------------------------------------------- 4.63. How do I make a Python script executable on Unix? You need to do two things: the script file's mode must be executable (include the 'x' bit), and the first line must begin with #! followed by the pathname for 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 way. The most straightforward way is to write #!/usr/local/bin/python as the very first ine of your file - or whatever the pathname is 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. On almost all platforms, the following woll work, assuming the python interpreter is in a directory on the user's $PATH: #! /usr/bin/env python Note -- *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 disadvantage is that this defines the script's __doc__ string. However, you can fix that by adding __doc__ = """...Whatever...""" ---------------------------------------------------------------------------- 4.64. How do you remove duplicates from a list? Generally, if you don't mind reordering the List 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 (ie, they are all hashable) this is often faster d = {} for x in List: d[x]=x List = d.values() Also, for extremely large lists you might consider more optimal alternatives to the first one. The second one is pretty good whenever it can be used. ---------------------------------------------------------------------------- 4.65. Are there any known year 2000 problems in Python? I am not aware of year 2000 deficiencies in Python 1.5. Python does very few date calculations and for what it does, it relies on the C library functions. Python generally represent times either as seconds since 1970 or as a tuple (year, month, day, ...) 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, I cannot vouch for your Python code! Given the nature of freely available software, I have to add that this statement is not legally binding. The Python copyright notice contains the following disclaimer: STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. The good news is that if you encounter a problem, you have full source available to track it down and fix it! ---------------------------------------------------------------------------- 4.66. I want a version of map that applies a method to a sequence of objects! Help! Get fancy! def method_map(objects, method, arguments): """method_map([a,b], "flog", (1,2)) gives [a.flog(1,2), b.flog(1,2)]""" nobjects = len(objects) methods = map(getattr, objects, [method]*nobjects) return map(apply, methods, [arguments]*nobjects) It's generally a good idea to get to know the mysteries of map and apply and getattr and the other dynamic features of Python. ---------------------------------------------------------------------------- 4.67. How do I generate random numbers in Python? The standard library module "whrandom" implements a random number generator. Usage is simple: import whrandom whrandom.random() This returns a random floating point number in the range [0, 1). There are also other specialized generators in this module: randint(a, b) chooses an integer in the range [a, b) choice(S) chooses from a given sequence uniform(a, b) chooses a floating point number in the range [a, b) To force the random number generator's initial setting, use seed(x, y, z) set the seed from three integers in [1, 256) There's also a class, whrandom, whoch you can instantiate to create independent multiple random number generators. The module "random" contains functions that approximate various standard distributions. All this is documented in the library reference manual. Note that the module "rand" is obsolete. ---------------------------------------------------------------------------- 4.68. How do I access the serial (RS232) port? There's a Windows serial communication module (for communication over RS 232 serial ports) at http://www.python.org/ftp/python/contrib/System/siomodule.README http://www.python.org/ftp/python/contrib/System/siomodule.zip For DOS, try Hans Nowak's Python-DX, which supports this, at: http://www.cuci.nl/~hnowak/ For Unix, search Deja News (using http://www.python.org/search/) for "serial port" with author Mitch Chapman (his post is a little too long to include here). ---------------------------------------------------------------------------- 4.69. Images on Tk-Buttons don't work in Py15? They do work, but you must keep your own reference to the image object now. More verbosely, you must make sure that, say, a global variable or a class attribute refers to the object. Quoting Fredrik Lundh from the mailinglist: Well, the Tk button widget keeps a reference to the internal photoimage object, but Tkinter does not. So when the last Python reference goes away, Tkinter tells Tk to release the photoimage. But since the image is in use by a widget, Tk doesn't destroy it. Not completely. It just blanks the image, making it completely transparent... And yes, there was a bug in the keyword argument handling in 1.4 that kept an extra reference around in some cases. And when Guido fixed that bug in 1.5, he broke quite a few Tkinter programs... ---------------------------------------------------------------------------- 4.70. 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). Fredrik Lundh (fredrik@pythonware.com) explains (on the python-list): 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 ---------------------------------------------------------------------------- 4.71. How do I send mail from a Python script? On Unix, it's very simple, using 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" % SENDMAIL, "w") p.write("To: cary@ratatosk.org\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 On non-Unix systems (and on Unix systems too, of course!), you can use SMTP to send mail to a nearby mail server. A library for SMTP (smtplib.py) is included in Python 1.5.1; in 1.5.2 it will be documented and extended. Here's a very simple interactive mail sender that uses it: import sys, smtplib fromaddr = raw_input("From: ") toaddrs = string.splitfields(raw_input("To: "), ',') 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() This method will work on any host that supports an SMTP listener; otherwise, you will have to ask the user for a host. ---------------------------------------------------------------------------- 4.72. How do I avoid blocking in connect() of a socket? The select module is widely known to help with asynchronous I/O on sockets once they are connected. However, it is less than common knowledge how to avoid blocking on the initial connect() call. Jeremy Hylton has the following advice (slightly edited): 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 errno. errno.EINPROGRESS indicates that the connection is in progress, but hasn't finished yet. Different OSes will return different errnos, so you're going to have to check. I can tell you that different versions of Solaris return different errno values. In Python 1.5 and later, you can use connect_ex() 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 (checking to see if it is writeable). ---------------------------------------------------------------------------- 4.73. 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 To verify that this works, you can type "a" and hit enter while in the interpreter, which will cause Python to spit out the current value of "a" in decimal: >>> 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 ---------------------------------------------------------------------------- 4.74. How to get a single keypress at a time? For Windows, see question 8.2. Here is an answer for Unix. There are several solutions; some involve using curses, which is a pretty big thing to learn. Here's a solution without curses, due to Andrew Kuchling (adapted from code to do a PGP-style randomness pool): import termios, TERMIOS, sys, os fd = sys.stdin.fileno() old = termios.tcgetattr(fd) new = termios.tcgetattr(fd) new[3] = new[3] & ~TERMIOS.ICANON & ~TERMIOS.ECHO new[6][TERMIOS.VMIN] = 1 new[6][TERMIOS.VTIME] = 0 termios.tcsetattr(fd, TERMIOS.TCSANOW, new) s = '' # We'll save the characters typed and add them to the pool. try: while 1: c = os.read(fd, 1) print "Got character", `c` s = s+c finally: termios.tcsetattr(fd, TERMIOS.TCSAFLUSH, old) You need the termios module for any of this to work, and I've only tried it on Linux, though it should work elsewhere. It turns off stdin's echoing and disables canonical mode, and then reads a character at a time from stdin, noting the time after each keystroke. ---------------------------------------------------------------------------- 4.75. How can I overload constructors (or methods) in Python? (This actually applies to all methods, but somehow the question usually comes up first in the context of constructors.) Where 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. ---------------------------------------------------------------------------- 4.76. How do I pass keyword arguments from one method to another? Use apply. For example: class Account: def __init__(self, **kw): self.accountType = kw.get('accountType') self.balance = kw.get('balance') class CheckingAccount(Account): def __init__(self, **kw): kw['accountType'] = 'checking' apply(Account.__init__, (self,), kw) myAccount = CheckingAccount(balance=100.00) ---------------------------------------------------------------------------- 4.77. What module should I use to help with generating HTML? Check out HTMLgen written by Robin Friedrich. It's 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. It can be found in the FTP contrib area on python.org or on the Starship. Use the search engines there to locate the latest version. It might also be useful to consider DocumentTemplate, which offers clear separation between Python code and HTML code. DocumentTemplate is part of the Bobo objects publishing system (http:/www.digicool.com/releases) but can be used independantly of course! ---------------------------------------------------------------------------- 4.78. How do I create documentation from doc strings? Use gendoc, by Daniel Larson. See http://starship.skyport.net/crew/danilo/ It can create HTML from the doc strings in your Python source code. ---------------------------------------------------------------------------- 4.79. How do I read (or write) binary data? For complex data formats, it's best to use use the struct module. It's documented in the library reference. It allows you to take a string read from a file 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 bin-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 floats), you can also use the array module, also documented in the library reference. ---------------------------------------------------------------------------- 4.80. I can't get key bindings to work in Tkinter An oft-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 taketocus option). ---------------------------------------------------------------------------- 4.81. "import crypt" fails [Unix] Starting with Python 1.5, the crypt module is disabled by default. In order to enable it, you must go into the Python source tree and edit the file Modules/Setup to enable it (remove a '#' sign in front of the line starting with '#crypt'). Then rebuild. You may also have to add the string '-lcrypt' to that same line. ---------------------------------------------------------------------------- 4.82. Are there coding standards or a style guide for Python programs? Yes, Guido has written the "Python Style Guide". See http://www.python.org/doc/essays/styleguide.html ---------------------------------------------------------------------------- 4.83. How do I freeze Tkinter applications? Freeze is a tool to create stand-alone applications (see 4.28). 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). ---------------------------------------------------------------------------- 4.84. How do I create static class data and static class methods? [Tim Peters, tim_one@email.msn.com] 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. STATIC DATA For example, 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, self.count = 42 creates a new and unrelated instance vrbl named "count" in self's own dict. So rebinding of a class-static data name needs the C.count = 314 form whether inside a method or not. STATIC METHODS Static methods (as opposed to static data) are unnatural in Python, because C.getcount returns an unbound method object, which can't be invoked without supplying an instance of C as the first argument. The intended way to get the effect of a static method is via a 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. Several tortured schemes for faking static methods can be found by searching DejaNews. Most people feel such cures are worse than the disease. Perhaps the least obnoxious is due to Pekka Pessi (mailto:ppessi@hut.fi): # helper class to disguise function objects class _static: def __init__(self, f): self.__call__ = f class C: count = 0 def __init__(self): C.count = C.count + 1 def getcount(): return C.count getcount = _static(getcount) def sum(x, y): return x + y sum = _static(sum) C(); C() c = C() print C.getcount() # prints 3 print c.getcount() # prints 3 print C.sum(27, 15) # prints 42 ---------------------------------------------------------------------------- 4.85. __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 string.split(s, ".")[1:]: m = getattr(m, i) ---------------------------------------------------------------------------- 4.86. Basic thread wisdom If you write a simple test program like this: import thread def run(name, n): for i in range(n): print name, i for i in range(10): thread.start_new(run, (i, 100)) none of the threads seem to run! The reason is that as soon as the main thread exits, all threads are killed. A simple fix is to add a sleep to the end of the program, sufficiently long for all threads to finish: import thread, time def run(name, n): for i in range(n): print name, i for i in range(10): thread.start_new(run, (i, 100)) 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: import thread, time def run(name, n): time.sleep(0.001) # <---------------------! for i in range(n): print name, i for i in range(10): thread.start_new(run, (i, 100)) time.sleep(10) Some more hints: Instead of using a time.sleep() call at the end, it's better to use some kind of semaphore mechanism. One idea is to use a 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. Use the threading module instead of the thread module. It's part of Python since version 1.5.1. It takes care of all these details, and has many other nice features too! ---------------------------------------------------------------------------- 4.87. 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 f you create in Python via the builtin "open" function, 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 happens automatically too, 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: doing sys.stdout.close() # ditto for stdin and stderr marks the Python-level file object as being closed, but does not close the associated C stream (provided sys.stdout is still bound to its default value, which is the stream C also calls "stdout"). 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 the heck out of 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 ---------------------------------------------------------------------------- 4.88. What kinds of global value mutation are thread-safe? [adapted from c.l.py responses by Gordon McMillan & GvR] A global interpreter lock 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 offers to switch can be set via sys.setcheckinterval). Each bytecode instruction-- and all the C implementation code reached from it --is therefore atomic. In theory, this means an exact accounting requires an exact understanding of the PVM bytecode implementation. In practice, it means that operations on shared vrbls of builtin data types (ints, lists, dicts, etc) that "look atomic" really are. For example, these are 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 Note: 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! ---------------------------------------------------------------------------- 4.89. How do I modify a string in place? Strings are immutable (see question 6.2) so you cannot modify a string directly. If you need an object with this ability, try converting the string to a list or take a look at 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!") >>> import string >>> print string.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' ---------------------------------------------------------------------------- 4.90. How to pass on keyword/optional parameters/arguments Q: How can I pass on optional or keyword parameters from one function to another? A: Use 'apply', like: def f1(a, *b, **c): ... def f2(x, *y, **z): ... z['width']='14.3c' ... apply(f1, (a,)+b, c) ---------------------------------------------------------------------------- -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From python-announce@python.org Thu Jul 8 00:27:59 1999 From: python-announce@python.org (Markus Fleck) Date: Wed, 07 Jul 99 23:27:59 GMT Subject: Python Language FAQ - Section 8 Message-ID: This FAQ newsgroup posting has been automatically converted from an HTML snapshot of the original Python FAQ; please refer to the original "Python FAQ Wizard" at if source code snippets given in this document do not work - incidentally some formatting information may have been lost during the conversion. ---------------------------------------------------------------------------- The whole Python FAQ - Section 8 Last changed on Mon Jun 28 19:36:09 1999 EDT (Entries marked with ** were changed within the last 24 hours; entries marked with * were changed within the last 7 days.) ---------------------------------------------------------------------------- 8. Python on Windows 8.1. Using Python for CGI on Microsoft Windows 8.2. How to check for a keypress without blocking? 8.3. $PYTHONPATH 8.4. dedent syntax errors 8.5. How do I emulate os.kill() in Windows? 8.6. Why does os.path.isdir() fail on NT shared directories? 8.7. PyRun_SimpleFile() crashes on Windows but not on Unix 8.8. Import of _tkinter fails on Windows 95/98 8.9. Can't extract the downloaded documentation on Windows 8.10. Can't get Py_RunSimpleFile() to work. 8.11. Where is Freeze for Windows? 8.12. Is a *.pyd file the same as a DLL? 8.13. Missing cw3215mt.dll (or missing cw3215.dll) ---------------------------------------------------------------------------- 8. Python on Windows ---------------------------------------------------------------------------- 8.1. Using Python for CGI on Microsoft Windows Setting up the Microsoft IIS Server/Peer Server: 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 by people who would know 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). However, that issue is beyond this Windows FAQ entry. Netscape Servers: Information on this topic exists at: http://home.netscape.com/comprod/server_central/support/fasttrack_man/programs.htm#1010870 ---------------------------------------------------------------------------- 8.2. How to check for a keypress without blocking? Use the msvcrt module. This is a standard Windows-specific extensions in Python 1.5 and beyond. It defines a function kbhit() which checks whether a keyboard hit is present; also getch() which gets one character without echo. Plus a few other goodies. (Search for "keypress" to find an answer for Unix as well.) ---------------------------------------------------------------------------- 8.3. $PYTHONPATH In MS-DOS derived environments, a unix variable such as $PYTHONPATH is set as PYTHONPATH, without the dollar sign. PYTHONPATH is useful for specifying the location of library files. ---------------------------------------------------------------------------- 8.4. dedent syntax errors Tim sez: the original content of this FAQ (below) makes little sense. The FAQ does not recommend using tabs, and Guido's Python Style Guide recommends 4 spaces for distributed Python code; this is also the Emacs python-mode default; see http://www.python.org/doc/essays/styleguide.html 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. [original follows] The FAQ really means it when it suggests using tabs, not spaces, for indentation control. This may be a bigger problem in windows than in unix. For instance, the Microsoft Visual C++ programmers editor, in its default configuration, does not indicate whether the white space is spaces or tabs. If it is spaces, you are likely to get syntax errors not obviously related to the indentation. ---------------------------------------------------------------------------- 8.5. 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)) ---------------------------------------------------------------------------- 8.6. 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 [Blake Winton responds:] I've had the same problem doing "Start >> Run" and then a directory on a shared drive. If I use "\\rorschach\public", it will fail, but if I use "\\rorschach\public\", it will work. For that matter, os.stat() does the same thing (well, it gives an error for "\\\\rorschach\\public", but you get the idea)... I've got a theory about why this happens, but it's only a theory. NT knows the difference between shared directories, and regular directories. "\\rorschach\public" isn't a directory, it's _really_ an IPC abstraction. This is sort of lended credence to by the fact that when you're mapping a network drive, you can't map "\\rorschach\public\utils", but only "\\rorschach\public". [Clarification by funkster@midwinter.com] It's not actually a Python question, as Python is working just fine; it's clearing up something a bit muddled about Windows networked drives. 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 ---------------------------------------------------------------------------- 8.7. PyRun_SimpleFile() crashes on Windows but not on Unix I've seen a number of reports of PyRun_SimpleFile() failing in a Windows port of an application embedding Python that worked fine on Unix. PyRun_SimpleString() works fine on both platforms. I think this happens because the application was compiled with a different set of compiler flags than Python15.DLL. It seems that some compiler flags affect the standard I/O library in such a way that using different flags makes calls fail. You need to set it for multi-threaded DLL. ---------------------------------------------------------------------------- 8.8. Import of _tkinter fails on Windows 95/98 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.) ---------------------------------------------------------------------------- 8.9. Can't 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.) ---------------------------------------------------------------------------- 8.10. Can't get Py_RunSimpleFile() to work. 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, I think). 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. ---------------------------------------------------------------------------- 8.11. 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 (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). This is recommended for Python 1.5.2 (and betas thereof) only; older versions don't quite work. You need the Microsoft VC++ 5.0 compiler (maybe it works with 6.0 too). You probably need to build Python -- the project files are all in the PCbuild directory. The freeze program is in the Tools\freeze subdirectory of the source tree. ---------------------------------------------------------------------------- 8.12. 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.pyc 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. ---------------------------------------------------------------------------- 8.13. 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). ---------------------------------------------------------------------------- -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From python-announce@python.org Thu Jul 8 00:27:52 1999 From: python-announce@python.org (Markus Fleck) Date: Wed, 07 Jul 99 23:27:52 GMT Subject: Python Language FAQ - Section 6 Message-ID: This FAQ newsgroup posting has been automatically converted from an HTML snapshot of the original Python FAQ; please refer to the original "Python FAQ Wizard" at if source code snippets given in this document do not work - incidentally some formatting information may have been lost during the conversion. ---------------------------------------------------------------------------- The whole Python FAQ - Section 6 Last changed on Mon Jun 28 19:36:09 1999 EDT (Entries marked with ** were changed within the last 24 hours; entries marked with * were changed within the last 7 days.) ---------------------------------------------------------------------------- 6. Python's design 6.1. Why isn't there a switch or case statement in Python? 6.2. Why does Python use indentation for grouping of statements? 6.3. Why are Python strings immutable? 6.4. Why don't strings have methods like index() or sort(), like lists? 6.5. Why does Python use methods for some functionality (e.g. list.index()) but functions for other (e.g. len(list))? 6.6. Why can't I derive a class from built-in types (e.g. lists or files)? 6.7. Why must 'self' be declared and used explicitly in method definitions and calls? 6.8. Can't you emulate threads in the interpreter instead of relying on an OS-specific thread implementation? 6.9. Why can't lambda forms contain statements? 6.10. Why don't lambdas have access to variables defined in the containing scope? 6.11. Why can't recursive functions be defined inside other functions? 6.12. Why is there no more efficient way of iterating over a dictionary than first constructing the list of keys()? 6.13. Can Python be compiled to machine code, C or some other language? 6.14. How does Python manage memory? Why not full garbage collection? 6.15. Why are there separate tuple and list data types? 6.16. How are lists implemented? 6.17. How are dictionaries implemented? 6.18. Why must dictionary keys be immutable? 6.19. How the heck do you make an array in Python? 6.20. Why doesn't list.sort() return the sorted list? 6.21. How do you specify and enforce an interface spec in Python? 6.22. Why do all classes have the same type? Why do instances all have the same type? 6.23. Why isn't all memory freed when Python exits? 6.24. Why no class methods or mutable class variables? 6.25. Why are default values sometimes shared between objects? 6.26. Why no goto? 6.27. How do you make a higher order function in Python? 6.28. Why do I get a SyntaxError for a 'continue' inside a 'try'? 6.29. Why can't raw strings (r-strings) end with a backslash? 6.30. Why can't I use an assignment in an expression? ---------------------------------------------------------------------------- 6. Python's design ---------------------------------------------------------------------------- 6.1. 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. ---------------------------------------------------------------------------- 6.2. Why does Python use indentation for grouping of statements? Basically I believe 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 a while. Some arguments for it: Since there are no begin/end brackets there cannot be a disagreement between grouping perceived by the parser and the human reader. I remember long ago seeing a C fragment like this: if (x <= y) x++; y--; z++; and staring a long time at it wondering why y was being decremented even for x > y... (And I wasn't a C newbie then either.) Since there are no begin/end brackets, Python is much less prone to coding-style conflicts. In C there are loads of different ways to place the braces (including the choice whether to place braces around single statements in certain cases, for consistency). 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 over a program. Ideally, a function should fit on one basic tty screen (say, 20 lines). 20 lines of Python are worth a LOT more than 20 lines of C. This is not solely due to the lack of begin/end brackets (the lack of declarations also helps, and the powerful operations of course), but it certainly helps! ---------------------------------------------------------------------------- 6.3. Why are Python strings immutable? There are two 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. (Adapted from Jim Roskind) ---------------------------------------------------------------------------- 6.4. Why don't strings have methods like index() or sort(), like lists? Good question. Strings currently don't have methods at all (likewise tuples and numbers). Long ago, it seemed unnecessary to implement any of these functions in C, so a standard library module "string" written in Python was created that performs string related operations. Since then, the cry for performance has moved most of them into the built-in module strop (this is imported by module string, which is still the preferred interface, without loss of performance except during initialization). Some of these functions (e.g. index()) could easily be implemented as string methods instead, but others (e.g. sort()) can't, since their interface prescribes that they modify the object, while strings are immutable (see the previous question). ---------------------------------------------------------------------------- 6.5. Why does Python use methods for some functionality (e.g. list.index()) but functions for other (e.g. len(list))? Functions are used for those operations that are generic for a group of types and which should work even for objects that don't have methods at all (e.g. numbers, strings, tuples). Also, 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 really too late to change such things fundamentally now. ---------------------------------------------------------------------------- 6.6. Why can't I derive a class from built-in types (e.g. lists or files)? This is caused by the relatively late addition of (user-defined) classes to the language -- the implementation framework doesn't easily allow it. See the answer to question 4.2 for a work-around. This may be fixed in the (distant) future. ---------------------------------------------------------------------------- 6.7. Why must 'self' be declared and used explicitly in method definitions and calls? By asking this question you reveal your C++ background. :-) When I added classes, this was (again) the simplest way of implementing methods without too many changes to the interpreter. I borrowed the idea from Modula-3. It turns out to be very useful, for a variety of reasons. First, it makes it 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. 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 base class that 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. Lastly, 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. ---------------------------------------------------------------------------- 6.8. Can't you emulate threads in the interpreter instead of relying on an OS-specific thread implementation? 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. ---------------------------------------------------------------------------- 6.9. 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! ---------------------------------------------------------------------------- 6.10. Why don't lambdas have access to variables defined in the containing scope? Because they are implemented as ordinary functions. See question 4.5 above. ---------------------------------------------------------------------------- 6.11. Why can't recursive functions be defined inside other functions? See question 4.5 above. But actually recursive functions can be defined in other functions with some trickery. def test(): class factorial: def __call__(self, n): if n<=1: return 1 return n * self(n-1) return factorial() fact = test() The instance created by factorial() above acts like the recursive factorial function. Mutually recursive functions can be passed to each other as arguments. ---------------------------------------------------------------------------- 6.12. Why is there no more efficient way of iterating over a dictionary than first constructing the list of keys()? Have you tried it? I bet it's fast enough for your purposes! In most cases such a list takes only a few percent of the space occupied by the dictionary. Apart from the fixed header, the list needs only 4 bytes (the size of a pointer) per key. A dictionary uses 12 bytes per key plus between 30 and 70 percent hash table overhead, plus the space for the keys and values. By necessity, all keys are distinct objects, and a string object (the most common key type) costs at least 20 bytes plus the length of the string. Add to that the values contained in the dictionary, and you see that 4 bytes more per item really isn't that much more memory... A call to dict.keys() makes one fast scan over the dictionary (internally, the iteration function does exist) copying the pointers to the key objects into a pre-allocated list object of the right size. The iteration time isn't lost (since you'll have to iterate anyway -- unless in the majority of cases your loop terminates very prematurely (which I doubt since you're getting the keys in random order). I don't expose the dictionary iteration operation to Python programmers because the dictionary shouldn't be modified during the entire iteration -- if it is, there's a small chance that the dictionary is reorganized because the hash table becomes too full, and then the iteration may miss some items and see others twice. Exactly because this only occurs rarely, it would lead to hidden bugs in programs: it's easy never to have it happen during test runs if you only insert or delete a few items per iteration -- but your users will surely hit upon it sooner or later. ---------------------------------------------------------------------------- 6.13. 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". Thus, the performance gain would probably be minimal. Internally, Python source code is always translated into a "virtual machine code" or "byte code" representation before it is interpreted (by the "Python virtual machine" or "bytecode interpreter"). In order to avoid the overhead of parsing and translating modules that rarely change over and over again, this byte code is written on a file whose name ends in ".pyc" whenever a module is parsed (from a file whose name ends in ".py"). 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 (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 will generally improve start-up time of Python scripts. If desired, the Lib/compileall.py module/script can be used to force creation of 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. If you are looking for a way to translate Python programs in order to distribute them in binary form, without the need to distribute the interpreter and library as well, have a look at the freeze.py script in the Tools/freeze directory. This creates a single binary file incorporating your program, the Python interpreter, and those parts of the Python library that are needed by your program. Of course, the resulting binary will only run on the same type of platform as that used to create it. ---------------------------------------------------------------------------- 6.14. How does Python manage memory? Why not full garbage collection? The details of Python memory management depend on the implementation. The standard Python implementation (the C implementation) uses reference counting memory management. This means that when an object is no longer in use Python frees the object automatically, with a few exceptions. On the other hand, JPython relies on the Java runtime; so it uses the JVM's garbage collector. This difference can cause some subtle porting problems if your Python code depends on the behavior of the reference counting implementation. Two exceptions to bear in mind for standard Python are: 1) if the object lies on a circular reference path it won't be freed unless the circularities are broken. EG: List = [None] List[0] = List List will not be freed unless the circularity (List[0] is List) is broken. The reason List will not be freed is because although it may become inaccessible the list contains a reference to itself, and reference counting only deallocates an object when all references to an object are destroyed. To break the circular reference path we must destroy the reference, as in List[0] = None So, if your program creates circular references (and if it is long running and/or consumes lots of memory) it may have to do some explicit management of circular structures. In many application domains this is needed rarely, if ever. 2) Sometimes objects get stuck in "tracebacks" temporarily and hence are not deallocated when you might expect. Clear the tracebacks via import sys sys.exc_traceback = sys.last_traceback = None Tracebacks are used for reporting errors and 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 modulo tracebacks, Python programs need not explicitly manage memory. It is often suggested that Python could benefit from fully general garbage collection. It's looking less and less likely that Python will ever get "automatic" garbage collection (GC). For one thing, unless this were added to C as a standard feature, it's a portability pain in the ass. And yes, I know about the Xerox library. It has bits of assembler code for most common platforms. Not for all. And although it is mostly transparent, it isn't completely transparent (when I once linked Python with it, it dumped core). "Proper" GC also becomes a problem when Python gets embedded into other applications. While in a stand-alone Python it may be 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 JPython, which has garbage collection, the following code (which is fine in C Python) 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. Sure, you can think of ways to fix this. But it's not off-the-shelf technology. 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() All that said, somebody has managed to add GC to Python using the GC library fromn Xerox, so you can see for yourself. See http://starship.python.net/crew/gandalf/gc-ss.html See also question 4.17 for ways to plug some common memory leaks manually. If you're not satisfied with the answers here, before you post to the newsgroup, please read this summary of past discussions on GC for Python by Moshe Zadka: http://www.geocities.com/TheTropics/Island/2932/gcpy.html ---------------------------------------------------------------------------- 6.15. Why are there separate tuple and list data types? This is done so that tuples can be immutable while lists are mutable. Immutable tuples are useful in situations where you need to pass a few items to a function and don't want the function to modify the tuple; for example, point1 = (120, 140) point2 = (200, 300) record(point1, point2) draw(point1, point2) You don't want to have to think about what would happen if record() changed the coordinates -- it can't, because the tuples are immutable. On the other hand, when creating large lists dynamically, it is absolutely crucial that they are mutable -- adding elements to a tuple one by one requires using the concatenation operator, which makes it quadratic in time. As a general guideline, use tuples like you would use structs in C or records in Pascal, use lists like (variable length) arrays. ---------------------------------------------------------------------------- 6.16. How are lists implemented? Despite what a Lisper might think, Python's lists are really variable-length arrays. The implementation uses a contiguous array of references to other objects, and keeps a pointer to this array (as well as its 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. ---------------------------------------------------------------------------- 6.17. 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. ---------------------------------------------------------------------------- 6.18. 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 change. But since whoever changes the key object can't tell that is incorporated in a dictionary, 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, since its hash value is different; and if you try to look up the old value, it won't be found either, since the value of the object found in that hash bin differs. If you think you need to have a dictionary indexed with a list, try to use a tuple instead. The function tuple(l) creates a tuple with the same entries as the list l. 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]] will 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 that I'd rather not see; it 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 again (and again and again). 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. 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. You must 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). 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 may misbehave! In the case of listwrapper above 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. You've been warned! ---------------------------------------------------------------------------- 6.19. How the heck do you make an array in Python? ["this", 1, "is", "an", "array"] Lists are arrays in the C or Pascal sense of the word (see question 6.16). 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 Numerics extensions and others define array-like structures with various characteristics as well. To get Lisp-like lists, emulate cons cells lisp_list = ("like", ("this", ("example", None) ) ) using tuples (or lists, if you want mutability). 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 (it's usually a lot slower than using Python lists). Think of Python lists as mutable heterogeneous arrays of Python objects (say that 10 times fast :) ). ---------------------------------------------------------------------------- 6.20. 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 orted: keys = dict.keys() keys.sort() for key in keys: ...do whatever with dict[key]... ---------------------------------------------------------------------------- 6.21. How do you specify and enforce an interface spec in Python? An interfaces 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 aid 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. A good test suite for a module can at once provide a regression test and serve as a module interface specification (even better since it also gives example usage). Look to many of the standard libraries which often have a "script interpretation" which provides 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. An appropriate testing discipline (if enforced) can help build large complex applications in Python as well as having interface specifications would do (or better). Of course Python allows you to get sloppy and not do it. Also you might want to design your code with an eye to make it easily tested. ---------------------------------------------------------------------------- 6.22. Why do all classes have the same type? Why do instances all have the same type? The Pythonic use of the word "type" is quite different from common usage in much of the rest of the programming language world. A "type" in Python is a description for an object's operations as implemented in C. All classes have the same operations implemented in C which sometimes "call back" to differing program fragments implemented in Python, and hence all classes have the same type. Similarly at the C level all class instances have the same C implementation, and hence all instances have the same type. Remember that in Python usage "type" refers to a C implementation of an object. To distinguish among instances of different classes use Instance.__class__, and also look to 4.47. Sorry for the terminological confusion, but at this point in Python's development nothing can be done! ---------------------------------------------------------------------------- 6.23. Why isn't all memory freed when Python exits? Objects referenced from Python module global name spaces are not always deallocated when Python exits. This may happen if there are circular references (see question 4.17). 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). But in general, Python 1.5 and beyond (in contrast with earlier versions) is quite agressive about cleaning up memory on exit. If you want to force Python to delete certain things on deallocation use the sys.exitfunc hook to force those deletions. For example if you are debugging an extension module using a memory analysis tool and you wish to make Python deallocate almost everything you might use an exitfunc like this one: import sys def my_exitfunc(): print "cleaning up" import sys # do order dependant deletions here ... # now delete everything else in arbitrary order for x in sys.modules.values(): d = x.__dict__ for name in d.keys(): del d[name] sys.exitfunc = my_exitfunc Other exitfuncs can be less drastic, of course. (In fact, this one just does what Python now already does itself; but the example of using sys.exitfunc to force cleanups is still useful.) ---------------------------------------------------------------------------- 6.24. Why no class methods or mutable class variables? The notation instance.attribute(arg1, arg2) usually translates to the equivalent of Class.attribute(instance, arg1, arg2) where Class is a (super)class of instance. Similarly instance.attribute = value sets an attribute of an instance (overriding any attribute of a class that instance inherits). Sometimes programmers want to have different behaviours -- they want a method which does not bind to the instance and a class attribute which changes in place. Python does not preclude these behaviours, but you have to adopt a convention to implement them. One way to accomplish this is to use "list wrappers" and global functions. def C_hello(): print "hello" class C: hello = [C_hello] counter = [0] I = C() Here I.hello[0]() acts very much like a "class method" and I.counter[0] = 2 alters C.counter (and doesn't override it). If you don't understand why you'd ever want to do this, that's because you are pure of mind, and you probably never will want to do it! This is dangerous trickery, not recommended when avoidable. (Inspired by Tim Peter's discussion.) ---------------------------------------------------------------------------- 6.25. Why are default values sometimes shared between objects? It is often expected that a function CALL creates new objects for default values. This is not what happens. Default values are created when the function is DEFINED, that is, there is only one such object that all functions refer to. If that object is changed, subsequent calls to the function will refer to this changed object. By definition, immutable objects (like numbers, strings, tuples, None) are safe from change. Changes to mutable objects (like dictionaries, lists, class instances) is what causes the confusion. Because of this feature it is good programming practice not to use mutable objects as default values, but to introduce them in the function. Don't write: def foo(dict={}): # XXX shared reference to one dict for all calls ... but: def foo(dict=None): if dict is None: dict = {} # create a new dict for local namespace See page 182 of "Internet Programming with Python" for one discussion of this feature. Or see the top of page 144 or bottom of page 277 in "Programming Python" for another discussion. ---------------------------------------------------------------------------- 6.26. Why no goto? Actually, 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. ---------------------------------------------------------------------------- 6.27. How do you make a higher order function in Python? You have two choices: you can use default arguments and override them or you can use "callable objects." For example suppose you wanted to define linear(a,b) which returns a function f where f(x) computes the value a*x+b. Using default arguments: def linear(a,b): def result(x, a=a, b=b): return a*x + b return result Or using callable objects: 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 defaults strategy has the disadvantage that the default arguments could be accidentally or maliciously overridden. The callable objects approach has the disadvantage that it is a bit slower and a bit longer. Note however that a collection of callables can share their signature via inheritance. EG class exponential(linear): # __init__ inherited def __call__(self, x): return self.a * (x ** self.b) On comp.lang.python, zenin@bawdycaste.org points out that an object can encapsulate state for several methods in order to emulate the "closure" concept from functional programming languages, for example: 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 closure containing the variable count.value" (if you like that way of thinking). ---------------------------------------------------------------------------- 6.28. 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 JPython doesn't have this restriction! ---------------------------------------------------------------------------- 6.29. 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\\" ---------------------------------------------------------------------------- 6.30. Why can't I use an assignment in an expression? Many people used to C or Perl complain that they want to be able to use e.g. this C idiom: while (line = readline(f)) { ...do something with line... } where in Python you're forced to write this: while 1: line = f.readline() if not line: break ...do something with line... This issue comes up in the Python newsgroup with alarming frequency -- search Deja News for past messages about assignment expression. 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... } 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 that I use for language change proposals: it should intuitively suggest the proper meaning to a human reader who has not yet been introduced with the construct. The earliest time something can be done about this will be with Python 2.0 -- if it is decided that it is worth fixing. An interesting phenomenon is that most experienced Python programmers recognize the "while 1" idiom and don't seem to be missing the assignment in expression construct much; it's only the newcomers who express a strong desire to add this to the language. One fairly elegant solution would be to introduce a new operator for assignment in expressions spelled ":=" -- this avoids the "=" instead of "==" problem. It would have the same precedence as comparison operators but the parser would flag combination with other comparisons (without disambiguating parentheses) as an error. Finally -- there's an alternative way of spelling this that seems attractive but is generally less robust than the "while 1" 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 one hidden at the bottom of the loop. ---------------------------------------------------------------------------- -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From Amos@digicool.com Thu Jul 8 01:56:46 1999 From: Amos@digicool.com (Amos Latteier) Date: Thu, 08 Jul 99 00:56:46 GMT Subject: Zope Weekly News - Wed, 7 Jul 1999 Message-ID: Hello, It's been a fairly uneventful week in Zopeland. As always lots of people are asking questions and providing good answers. But this week's seen few announcements and software releases, perhaps because of the holiday. Another Zope alpha should be out soon, and that's sure to generate some activity. * Anthony Pfrunder posted an update about his binary distribution of Zope 2.0 alpha for Windows and an upcoming project to make Zope work better with the Python Imaging Library and OpenGL. http://student.uq.edu.au/~s341625 http://www.zope.org/pipermail/zope/1999-July/006298.html * The unstoppable Martijn Pieters posted a patch to allow customizing tree tag decoration. Now longer will you have to use those tired plus and minus boxes. http://www.zope.org/pipermail/zope/1999-July/006401.html * Paul Everitt announced a press release detailing how Digital Creations and UserLand are making Zope and Frontier play nicely together. http://biz.yahoo.com/prnews/990707/tx_digital_1.html * Over on zope-dev list David Jacobs started an interesting discussion of enhancing Zope security features. http://www.zope.org/pipermail/zope-dev/1999-July/000771.html http://www.zope.org/pipermail/zope-dev/1999-July/000773.html * Digital Creations intern Cathi Davey posted documentation to the zope-dev list about some additional type converting facilities she's added to ZPublisher. http://www.zope.org/pipermail/zope-dev/1999-July/000724.html Until next week. -Amos == Amos Latteier mailto:amos@digicool.com Digital Creations http://www.digicool.com -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From fleck@informatik.uni-bonn.de Sat Jul 10 08:49:28 1999 From: fleck@informatik.uni-bonn.de (Markus Fleck) Date: Sat, 10 Jul 99 07:49:28 GMT Subject: [fm] REalizer 0.1 Message-ID: REalizer 0.1 Slayne - July 05th 1999, 18:15 EST REalizer is a GUI for entering and testing regular expressions provided by the python re module. Changes: First release. Download:http://www.globalserve.net/~catlee/REalizer.py Author: Chris AtLee License: GPL Category: Development/Tools Depends on: Python Freshmeat (c) 1999 scoop@freshmeat.net

REalizer 0.1 - GUI for entering and testing regular expressions provided by the python re module. (05-Jul-99) -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From fleck@informatik.uni-bonn.de Sat Jul 10 08:52:08 1999 From: fleck@informatik.uni-bonn.de (Markus Fleck) Date: Sat, 10 Jul 99 07:52:08 GMT Subject: [fm] gimp-python 0.4 Message-ID: gimp-python 0.4 james - July 05th 1999, 12:13 EST Gimp-Python is a set of python modules that allow you to write plugins for the GIMP in python. You get the best of both worlds, with all the power of the C plugin interface available, and the automatic GUI generation of Script-Fu. This plugin is also good if you don't like programming in scheme, perl or tcl. Changes: Added gimp-1.1 support (it should still work with gimp-1.0), made some incompatible changes to the API (removed the drawable type, and moved all its functionality to the layer and channel types), added a script-fu like interface module that handles all the GUI stuff of a plugin for you -- see the example plugins for details. Download:ftp://ftp.daa.com.au/pub/james/pygimp/ Homepage:http://www.daa.com.au/~james/pygimp/ Author: James Henstridge License: GPL Category: Development/Python Modules Depends on: gimp, python, pygtk Freshmeat (c) 1999 scoop@freshmeat.net

gimp-python 0.4 - set of python modules that allow you to write plug-ins for the GIMP (GNU Image Manipulation Program) in Python. (05-Jul-99) -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From neelk@alum.mit.edu Sat Jul 10 08:53:46 1999 From: neelk@alum.mit.edu (neelk@alum.mit.edu) Date: Sat, 10 Jul 99 07:53:46 GMT Subject: Signature 0.1 Message-ID: Signature.py is a module that makes reflecting on the function call signatures of callable objects a lot easier. A common question in Python is "How do I ask the interpreter what arguments a function takes?" and while the information is obviously available, I haven't found any simple, high-level interfaces to it. That's why I wrote Signature -- it's useful enough that it's made it into my personal library of frequently-used utilities. You can find it at: http://www.sff.net/people/neelk/free-software/Signature.py Caveats/TODO: o I don't know if it will work on JPython -- I exploited a lot of undocumented object attributes to figure out what the call signature is, and I have no idea if the same data is available there. o I haven't figured out how to look into C builtins yet -- anyone who can teach me how to do this from within Python will earn my undying gratitude. :) Example of use: >>> def foo(x, y, z=-1.0, *args, **kw): ... return (x+y)**z ... >>> f = Signature(foo) >>> print 'ordinary arglist:', f.ordinary_args() ordinary arglist: ('x', 'y', 'z') >>> print 'special_args:', f.special_args() special_args: {'keyword': 'kw', 'positional': 'args'} >>> print 'full arglist:', f.full_arglist() full arglist: ['x', 'y', 'z', 'args', 'kw'] >>> print 'defaults:', f.defaults() defaults: {'z': -1.0} >>> print 'signature:', str(f) signature: foo(x, y, z=-1.0, *args, **kw) Neel

Signature 0.1 - for reflecting on the function call signatures of callable objects. (09-Jul-99) -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From neelk@alum.mit.edu Sat Jul 10 08:53:46 1999 From: neelk@alum.mit.edu (neelk@alum.mit.edu) Date: Sat, 10 Jul 99 07:53:46 GMT Subject: Signature 0.1 Message-ID: <7m9tnh$6qg$59@rks1.urz.tu-dresden.de> Signature.py is a module that makes reflecting on the function call signatures of callable objects a lot easier. A common question in Python is "How do I ask the interpreter what arguments a function takes?" and while the information is obviously available, I haven't found any simple, high-level interfaces to it. That's why I wrote Signature -- it's useful enough that it's made it into my personal library of frequently-used utilities. You can find it at: http://www.sff.net/people/neelk/free-software/Signature.py Caveats/TODO: o I don't know if it will work on JPython -- I exploited a lot of undocumented object attributes to figure out what the call signature is, and I have no idea if the same data is available there. o I haven't figured out how to look into C builtins yet -- anyone who can teach me how to do this from within Python will earn my undying gratitude. :) Example of use: >>> def foo(x, y, z=-1.0, *args, **kw): ... return (x+y)**z ... >>> f = Signature(foo) >>> print 'ordinary arglist:', f.ordinary_args() ordinary arglist: ('x', 'y', 'z') >>> print 'special_args:', f.special_args() special_args: {'keyword': 'kw', 'positional': 'args'} >>> print 'full arglist:', f.full_arglist() full arglist: ['x', 'y', 'z', 'args', 'kw'] >>> print 'defaults:', f.defaults() defaults: {'z': -1.0} >>> print 'signature:', str(f) signature: foo(x, y, z=-1.0, *args, **kw) Neel

Signature 0.1 - for reflecting on the function call signatures of callable objects. (09-Jul-99) -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From andrew@andrewcooke.free-online.co.uk Sun Jul 11 12:58:40 1999 From: andrew@andrewcooke.free-online.co.uk (Andrew Cooke) Date: Sun, 11 Jul 99 11:58:40 GMT Subject: Alfajor - Cookie Filter Message-ID: Hi, Alfajor is an http cookie filter, written in Python with an optional GUI. It acts as an http proxy (you must configure your browser to use it) and can either contact sites directly or work with a second proxy (eg. a cache). The program allows cookies to be sent from your browser to any address which matches a list of regular expressions. The GUI allows the filter to be turned on and off, sites to be added or removed as they are accessed, and the list of regular expressions to be edited. The program is (c) Andrew Cooke 1999 and released under the GPL. For more info, please look at http://www.andrewcooke.free-online.co.uk/jara/alfajor/index.html Thanks, Andrew Sent via Deja.com http://www.deja.com/ Share what you know. Learn what you don't.

Alfajor - configurable HTTP cookie filter written in Python. (10-Jul-99) -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From akuchlin@mems-exchange.org Mon Jul 12 02:45:23 1999 From: akuchlin@mems-exchange.org (Andrew M. Kuchling) Date: Mon, 12 Jul 99 01:45:23 GMT Subject: Python SECS-I implementation Message-ID: The MEMS Exchange (http://www.mems-exchange.org) is making secs_i.py, a Python implementation of the SECS-I protocol, freely available. For more information, see the following URL: http://www.mems-exchange.org/exchange/software/secs-i/ SECS-I is the SEMI Equipment Control Standard I, a protocol supported by a lot of the equipment used in semiconductor fabs. We needed it to control the optics of the Leica INM200 microscope, but it may be useful to other people who want to talk to various pieces of semiconductor manufacturing equipment. (I was unable to find a free implementation of SECS-I, though various companies sell commercial libraries.) The code has actually been available for a while, buried inside the Remote Microscope distribution that's also available from the MEMS Exchange; secs_i.py is being made separately available to make it easier for outsiders to find the code. Bug reports and improvements are welcome. == A.M. Kuchling http://starship.python.net/crew/amk/ God made the Idiot for practice, and then He made the School Board. -- Mark Twain

SECS-I implementation - Python implementation of the SEMI Equipment Control Standard protocol for equipment used in semiconductor fabs. (11-Jul-99) -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From fleck@informatik.uni-bonn.de Tue Jul 13 16:37:35 1999 From: fleck@informatik.uni-bonn.de (Markus Fleck) Date: Tue, 13 Jul 99 15:37:35 GMT Subject: [fm] HtmlXtract redhog.0 Message-ID: HtmlXtract redhog.0 Egil Moeller - July 06th 1999, 23:12 EST HtmlXtract is a text-utility that let you extract, remove or replace a block from a HTML-document. The block to operate on is pointed out by a "path" through the nested blocks (For example, the path html.body.table{2}.tr.td{3} points out the third td inside the first tr inside the second table (inside the body inside html)). HtmlXtract is divided in three parts; a generic part (That can be used to xtract, remove or replace parts from any block-oriented language), a Html-specific part, and a command-line front-end. The first two parts may be included in any Python-program as ordinary modules. Changes: This is the first release. Download: http://a190.ryd.student.liu.se/Projects/Programming/Xtract/Xtract.tar.gz Author:Egil Möller License:GPL Category:Console/Text Utilities Freshmeat (c) 1999 scoop@freshmeat.net

HtmlXtract redhog.0 - module for extracting, removing or replacing parts of a document in any block-oriented language (Non-regular, context-free), such as HTML or LaTeX. (06-Jul-99) -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From joe@strout.net Tue Jul 13 16:38:40 1999 From: joe@strout.net (Joe Strout) Date: Tue, 13 Jul 99 15:38:40 GMT Subject: PIDDLE 1.0a3 Message-ID: I'm pleased to announce the third alpha release of PIDDLE (Plug-In Drawing, Does Little Else). PIDDLE is a cross-platform, cross-media drawing API; by choosing the desired backend renderer, your Python program can generate output to the PDF, EPS, TK, MacOS QuickDraw, a PIL canvas (and from there to PNG, GIF, JPEG, etc.), and others. This version adds a unified testing framework, and a number of bug fixes. To download, visit the PIDDLE home page: http://www.strout.net/python/piddle/ PIDDLE is written in 100% Python, but some backends require extensions (such as PIL) or may work on only certain platforms (such as MacOS QuickDraw). Comments and feedback are welcome; visit the mailing list at http://www.egroups.com/list/pythonpiddle/info.html to join the discussion. Cheers, -- Joe == ,------------------------------------------------------------------. | Joseph J. Strout Biocomputing -- The Salk Institute | | joe@strout.net http://www.strout.net | `------------------------------------------------------------------'

PIDDLE v1.0a3 - drawing API with backends that do the actual drawing to a variety of formats, including PDF, Postscript, MacOS QuickDraw, Tk, PIL, and eventually OpenGL and Windows. (12-Jul-99) -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From tismer@appliedbiometrics.com Tue Jul 13 16:39:13 1999 From: tismer@appliedbiometrics.com (Christian Tismer) Date: Tue, 13 Jul 99 15:39:13 GMT Subject: Stackless Python 0.3 Message-ID: ANNOUNCING: Stackless Python 0.3 A Python Implementation Which Does Not Use The C Stack What is it? A plugin-replacement for core Python. It should run any program which runs under Python 1.5.2 . But it does not need space on the C stack. Why did I write it? Stackless Python was never written before (afaik), since it was said to be impossible without major rewrites of core Python. I am proving the controverse: It is easy to write, just hard to think. Recent changes: Version 0.3 has been written while developing a continuation module which is about to ship. A couple of enhancements and changes were necessary to make continuations fly. Some drastic changes to frame management have been made. Stackless Python is now also able to keep track of recursive interpreter incarnations and to detect/resolve possible collisions between their frames. As a proof of concept, continuationsmodule.c will ship in a few days. Who needs it? At the moment, this is only useful for C programmers who want to try certain new ideas. Hardcore stuff. It allows to modify the current execution state by changing the frame stack chain without restictions, and it allows for pluggable interpreters on a per-frame-basis. The possibilities are for instance: Continuations, with which we will build Coroutines and Generators Restartable exceptions and Persistent execution state are the next topic to think about. They are possible. Stackless extension modules can be built. The new builtin stackless "map" function is a small example for this. Coroutines are able to run at the speed of a single C function call, which makes them a considerable alternative in certain algorithms. This is no longer a speculation since I have working coroutine prototypes, written with continuations. Status of the project: Stackless-ness has been implemented and tested with pystone. pystone works correctly and is about 10 % slower than with standard Python. What I need at the moment is - time to do the right design of coroutines on top of continuations - your input, your testing, critics and hints. Some still rough documentation is available at http://www.pns.cc/stackless/stackless.htm Source code and a VC++6.0 build for Windows can be found from the document or directly from ftp://ftp.pns.cc/pub/stackless_990712.zip ftp://ftp.pns.cc/pub/stackless_990712_win32.zip cheers - chris == Christian Tismer :^) Applied Biometrics GmbH : Have a break! Take a ride on Python's Kaiserin-Augusta-Allee 101 : *Starship* http://starship.python.net 10553 Berlin : PGP key -> http://wwwkeys.pgp.net PGP Fingerprint E182 71C7 1A9D 66E9 9D15 D3CC D4D7 93E2 1FAE F6DF we're tired of banana software - shipped green, ripens at home

Stackless Python 0.3 - a version of Python 1.5.2 that does not need space on the C stack. (12-Jul-99) -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From grove@infotek.no Thu Jul 15 12:02:09 1999 From: grove@infotek.no (Geir Ove Grønmo) Date: Thu, 15 Jul 99 11:02:09 GMT Subject: tmproc 0.20, a Topic Maps implementation Message-ID: Hello, I'm pleased to announce the second release of tmproc, a Topic Map processor. This release is updated according to the final standard. Suggestions and bug reports should be sent to: grove@infotek.no Enjoy! Geir O. Grønmo -------------------------------------------------------------------------- Title: tmproc Version: 0.20 Released: July 14th 1999 Author: Geir O. Grønmo, grove@infotek.no Homepage: http://www.infotek.no/~grove/software/tmproc/index.html - -- >>> What's new? o This version supports the final release of the standard. o Minor bugfixes o Works with the Java Platform (JPython[1]) - -- >>> What is tmproc? tmproc is an implementation of the new international standard ISO/IEC 13250 Topic Maps[2]. tmproc is written in Python, and should work on any platform to which Python have been ported - including the Java Platform. - -- >>> What are Topic Maps? 'Topic Maps' is a new international standard (ISO/IEC 13250) for layering multidimensional topic spaces on top of information assets. The standard covers concepts like topics, associations, occurrences and facets/metadata. Topic Maps are expected to have a major impact on future information systems. - -- >>> Features o Import, export, query and manipulation of topic maps. o Full set of extensible topic map classes with clearly defined interfaces. o Optional architectural processing [requires xmlarch]. o Introduction and reference documentation. o Statistical and information printing classes o Command line utility for interactive exploration - -- >>> Requirements - Python 1.5.1 or newer [3] - An SGML/XML parser with a SAX driver - SAX for Python [4] - xmlarch 0.25, optional unless architectural processing is needed [5] - -- >>> Licence tmproc is free for both non-commercial and commercial use. Redistribution of tmproc in commercial products requires another licence. See [*] for detailed licence information. - -- >>> References [1] http://www.jpython.org/ [2] http://www.ornl.gov/sgml/SC34/ [3] http://www.python.org/ [4] http://www.stud.ifi.uio.no/~larsga/download/python/xml/saxlib.html [5] http://www.infotek.no/~grove/software/xmlarch/index.html [*] http://www.infotek.no/~grove/software/tmproc/licence.html --------------------------------------------------------------------------

tmproc 0.20 - an implementation of Topic Maps, a new international standard (ISO/IEC 13250:1999) for layering multidimensional topic spaces on top of information assets. (13-Jul-99) -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From Amos@digicool.com Thu Jul 15 12:02:50 1999 From: Amos@digicool.com (Amos Latteier) Date: Thu, 15 Jul 99 11:02:50 GMT Subject: Zope Weekly News - Wed, 14 Jul 1999 Message-ID: Hello, Another Zope alpha release is out. It looks like we're getting fairly close to a Zope 2.0 beta release. Many intrepid people have been using the alpha releases and submitting patches and bug reports. Soon Zope 2 should be ready for wider consumption. * Jim Fulton announced the availability of Zope 2.0a4. This version fixes a lot of bugs and adds a few minor features. It looks like this may be the last alpha release. http://www.zope.org/Download/Releases/Zope-2.0.0a4 http://www.zope.org/Download/Releases/Zope-2.0.0a4/CHANGES.txt * Over on the zope-dev list Bruce Perens offered a patch to make Image object more flexible in the way they represent themselves in HTML. Martijn Pieters followed up with additional improvements. Hours later the enhancements were in CVS. Open source rocks! http://www.zope.org/pipermail/zope-dev/1999-July/000826.html * Christopher Petrilli posted a survey asking folks about what they think of the Gadfly DA. Response was mixed, though many people seem to find it useful. http://www.zope.org/pipermail/zope/1999-July/006457.html * Brian Lloyd posted a query about how to best allow people to upgrade from the existing database format (BoboPOS) to the new ZODB format. Most people seem to think that providing a conversion script is the best option. http://www.zope.org/pipermail/zope/1999-July/006472.html * Alexander Staubo suggest some interesting management interface improvements. Clearly this is an area of Zope that can be improved and community efforts could really make a big difference. http://www.zope.org/pipermail/zope/1999-July/006554.html * Linux Developer's Network is looking for articles about Zope. http://www.zope.org/pipermail/zope/1999-July/006598.html http://linuxdev.net/ * Kam Cheung started a remarkable good natured discussion about the differences between Zope and Frontier. As more folks come to Frontier to Zope it will be interesting to see what Zopistas can learn from them. http://www.zope.org/pipermail/zope/1999-July/006682.html * Apparently Zope 1.10.3 RPMs are available on Redhat's libc6 contrib area. http://www.zope.org/pipermail/zope/1999-July/006665.html * What started out as a documentation bug post by Bruce Perens turned into a discussion of the merits of various documentation formats and which ones are best for open source projects. Right now official Zope documentation is written in FrameMaker. http://www.zope.org/pipermail/zope/1999-July/006613.html * Anthony Pfrunder continues to improve his Zope 2 for Windows distribution. It's now tentatively called Universal Zope Build System, and includes various cool build tools. http://www.zope.org/pipermail/zope-dev/1999-July/000835.html http://student.uq.edu.au/~s341625/ -Amos == Amos Latteier mailto:amos@digicool.com Digital Creations http://www.digicool.com -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From jsight@pair.com Thu Jul 15 12:07:14 1999 From: jsight@pair.com (Jesse D. Sightler) Date: Thu, 15 Jul 99 11:07:14 GMT Subject: [website] The pyPit software library. Message-ID: Announcing the pyPit! URL: http://www.biddin.com/pyPit/ The pyPit is a fledgling attempt to develop an interactive library of Python software libraries and code snippets. Right now, there are fewer than a dozen projects listed, but we are open for submissions. The system is based on a gadfly database, which will ultimately allow keyword and other (as yet unannounced features). For the moment, I am requesting that everyone submit their free software projects for listing at http://www.biddin.com/pyPit/submit.html so that we can have something to work with in order to prototype the full-system in a more "real world" scenario (say, a few hundred software entries, in a variety of categories). Suggestions, and ideas for improvement as well as volunteers to work on the project are certainly welcome. Enjoy.:) == --------------- Jesse D. Sightler

PyPit - interactive library of contributed Python software libraries. (15-Jul-99) -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From ajs@cs.monash.edu.au Thu Jul 15 12:09:18 1999 From: ajs@cs.monash.edu.au (Andrew Snare) Date: Thu, 15 Jul 99 11:09:18 GMT Subject: PQueue 0.1a - Extension priority-queue module Message-ID: This is the first release of a module I've just written, released under the LGPL. It is available for download at: http://www.pigpond.com/~earthpig/PQueue-0.1a.tar.bz2 >From the documentation included with the release: PQueue Extension Module for Python - 0.1a ========================================= This C extension implements a priority-queue object using a fibonacci heap as the underlying data structure. This data structure supports the following operations with the given amortized time-complexity: - insert: O(1) - find-min: O(1) - extract-min: O(lg N) - decrease-key: O(1) - increase-key: O(lg N) (== delete, insert) - delete: O(lg N) (== decrease-key, extract-min) This asymptotic behaviour compares favourably to more traditional structures such as binomial heaps, at the cost of slightly higher constant overheads. This is the first public release of this extension -- feedback is both welcome and encouraged. Thanks must go to James Henstridge for providing such a nice autoconf system for extension modules, and to Aaron Waters for providing the PyModules FAQ resource and his pq3.py module (a slightly modified version of which is included in this distribution for benchmarking purposes). - Andrew Snare == #!/usr/bin/env python print(lambda s:s+"("+`s`+")")\ ('#!/usr/bin/env python\012print(lambda s:s+"("+`s`+")")\\\012') print(lambda x:x%`x`)('print(lambda x:x%%`x`)(%s)') For the web thingy:

PQueue 0.1a - fast priority-queue extension module implemented in C. (15-Jul-99) -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From fleck@informatik.uni-bonn.de Thu Jul 15 12:11:32 1999 From: fleck@informatik.uni-bonn.de (Markus Fleck) Date: Thu, 15 Jul 99 11:11:32 GMT Subject: [fm] PyGCS 1.3.2 Message-ID: PyGCS 1.3.2 Jeff Blaine - July 10th 1999, 12:03 EST PyGCS is a very stripped down MUD-like chat-server written entirely in Python. It has a single "room" and no large database to keep in memory and on disk. PyGCS has no embedded programming language. PyGCS is ideally meant to be a small multi-user real-time chat system for people who have a need to talk to more than one person at a time online. It fits somewhere in between the setup IRC uses (no walking between rooms so to speak) and the MUCK/MUSH/MOO style of server. Changes: Fixed a 'command stacking MUD client' bug which would crash the server. Tested code with newly released Python 1.5.2. Indented code to adhere to Python Style Guide for users wanting to use the source as a starting point. Two other tiny code cleanups. Download: ftp://ftp.shore.net/members2/j/jblaine/Source/pygcs-1.3.2.tar.gz Homepage: http://www.shore.net/~jblaine/code-GCS.html Changelog: http://www.shore.net/~jblaine/PyGCS_ChangeLog.txt Author: Jeff Blaine License: BSD type Category: Daemons/MUD Depends on: Python 1.5 or higher Freshmeat (c) 1999 scoop@freshmeat.net

PyGCS 1.3.2 - stripped down MUD-like chat-server written entirely in Python. (10-Jul-99) -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From fleck@informatik.uni-bonn.de Thu Jul 15 12:12:56 1999 From: fleck@informatik.uni-bonn.de (Markus Fleck) Date: Thu, 15 Jul 99 11:12:56 GMT Subject: TkGS Project to define a new Graphics Subsystem for Tk Message-ID: From: Frederic BONNET Subject: ANNOUNCE: Creation of the TkGS mailing list Date: 14 Jul 1999 02:51:24 -0700 I am pleased to announce the creation of a mailing list dedicated to the TkGS project. The TkGS projects main goal is to define a new graphics subsystem for Tk with device-independence in mind. You can find the complete TkGS specification at: http://www.multimania.com/fbonnet/Tcl/TkGS/specs.htm To subscribe, send an e-mail to: tkgs-list-subscribe@egroups.com The web page for this list is located at: http://www.egroups.com/list/tkgs-list/ Happy reading! == Frédéric BONNET frederic.bonnet@ciril.fr --------------------------------------------------------------- "Theory may inform, but Practice convinces" George Bain -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From tim_one@email.msn.com Tue Jul 20 14:55:29 1999 From: tim_one@email.msn.com (Tim Peters) Date: Tue, 20 Jul 99 13:55:29 GMT Subject: Cyclops 0.9.4 Message-ID: http://www.python.org/ftp/python/contrib/System/Cyclops.py # Module Cyclops version 0.9.4. # Released to the public domain 18-Jul-1999, # by Tim Peters (tim_one@email.msn.com). Cyclops.py implements a CycleTracker class that provides major help in finding and analyzing runtime cycles in Python programs. Strong points: + Much faster than previous similar modules. Searching for cycles takes time linear in the number of objects reachable from the registered objects plus the number of arcs connecting them, and all computation needed to display cycles is delayed until it's really needed (if ever). Tens of thousands of objects and hundreds of thousands of arcs can be analyzed in less than a minute on my creaky old P5-166 system. + Many kinds of optional output reports, from a simple listing of objects found in cycles, to a partitioning of cyclic objects into maximal strongly-connected components. + Easy to add new types to the set of objects CycleTracker knows how to "chase": pass appropriate functions to a CycleTracker instance's chase_type() method. It's done this way instead of via subclassing for speed. + An optional cycle-filter callback can be registered to ignore expected cycles (typically those created by the Python implementation itself). Weak points: + The problems this module helps to address are inherently difficult, and CycleTracker doesn't make them any easier to understand or to fix -- it only helps identify what and where they are. It's a tool, not a solution. + All the optional abilities make for a steep learning curve. + Registering objects can distort the behavior of the program under investigation, by keeping objects alive that would otherwise have died. See the module docstring for discussion and workarounds.

Cyclops.py 0.9.4 - tool for tracking cyclic structures in Python programs. (19-Jul-99) -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From da@ski.org Tue Jul 20 14:56:55 1999 From: da@ski.org (David Ascher) Date: Tue, 20 Jul 99 13:56:55 GMT Subject: Call for Panelists Message-ID: Call for Panelists The program for the O'Reilly Python Conference includes the following moderated, 50-minute panels: o Python Success Stories o Date: Monday, 23 August 1999 o Moderator: Uche Ogbuji of FourThought LLC o Joys and Pains of Building an Open-Source Community o Date: Tuesday, 24 August 1999 o Moderator: Paul Everitt of Digital Creations These panels are intended to be informal, structured discussions of the topics by members of the python community. In addition to panel members already determined, the program committee invites conference attendees and members of the Python community to participate. We seek individuals who have successfully applied Python to interesting computer problems in business, academics, or government; and individuals who have been involved in Python-based open-source projects. Interested parties should send e-mail by August 1 to monterey@egroups.com with the following information: o Name, affiliation, phone number and e-mail address of the panelist o A paragraph on the successful use of Python, or relevant open-source project. o A brief biography of the panelist o Whether or not the panelist has registered to attend the conference The O'Reilly Python conference is part of the O'Reilly Open Source Convention (http://conferences.oreilly.com/) from August 21-24, 1999 in Monterey, California. This conference includes six concurrent conferences featuring a wide array of exciting open-source technologies and personalities. The Python conference includes four tutorials, 15 presentations, birds-of-a-feather sessions, and more. The Program Committe Python Conference -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From Jeff Rush" RPMs for mxDateTime, mxODBC-Solid, python-xml and Fnorb 1.01, Zope (rerelease) I've packaged the Python extension modules, mxDateTime, mxODBC (for Solid SQL only) and the Python-XML SIG's 'python-xml 0.5.1' as Red Hat RPMs. The RPMs for the CORBA ORB Fnorb have been updated from 1.0 to 1.01, and the Zope RPMs have been re-released (1.10.3-3) to fix packaging bugs, such as the omission of Query/Splitter.so libraries needed by Confera, a Zope add-on. All RPMs have been uploaded to the Red Hat Contrib network. http://starship.python.net/crew/jrush/

RedHat RPMs - for mxDateTime, mxODBC-Solid, python-xml and Fnorb 1.01, Zope. (21-Jul-99) Jeff Rush -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From Amos@digicool.com Tue Jul 27 16:11:02 1999 From: Amos@digicool.com (Amos Latteier) Date: Tue, 27 Jul 99 15:11:02 GMT Subject: Zope Weekly News - Wed, 21 Jul 1999 Message-ID: Zope 2.0 beta one should be out *very* soon. This week saw a lot of screw tightening in preparation for the beta release. The public CVS archive is temporarily frozen due to some re-organization but will open up again when the beta release comes out. Most of the traffic on the Zope lists was devoted to Zope community members helping each other solve their various real world problems. One of the most notable discussions this week started with a comparison between Zope and other web development platforms with respect to xml facilities. Folks at DC weighed in with their 2 cents on the subject which includes the imminent release of a Zope product which will allow access to xml objects in Zopish ways. Interestingly many community members have similar ideas of what Zope needs in terms of xml support. It will be exciting to see how Digital Creations and community members collaborate on XML development efforts. * Chris Petrilli announced an new Zope mailing list, zope-announce. If you're overwhelmed with the volume of the currently Zope lists, this one could be for you. http://www.zope.org/mailman/listinfo/zope-announce/ http://www.zope.org/pipermail/zope/1999-July/006993.html * Amos Latteier posted a roadmap details some plans for XML development in Zope. Digital Creations will release an alpha XML Zope product in the next couple days. http://www.zope.org/pipermail/zope/1999-July/007010.html * One of the best IT magazines on the German market, iX Magazine, has a Zope article available in the August 1999 issue by Frank Tegtmeyer. http://www.heise.de/ix/ http://www.heise.de/ix/artikel/1999/08/064/ * Andreas Kostyrka announced Navigate 0-0-4. This product allows you to control which objects are displayed. http://www.zope.org/pipermail/zope/1999-July/006969.html http://www.zope.org/Download/Contrib/ * Arpad Kiss announced a simple Zope chart drawing tool. http://www.zope.org/pipermail/zope/1999-July/006964.html http://starship.python.net/crew/arpadk/downloads/Chart0.3.0.tar.gz * Andy Dustman announced a new Python interface for MySQL, MySQLdb-0.0.3. This package includes a patch to use it with Zope's MySQL database adapter. http://www.zope.org/pipermail/zope/1999-July/006946.html http://starship.python.net/crew/adustman * Hurrah Internet now offers Zope hosting. http://www.hurrah.com/ http://www.zope.org/Community/ZHP * Chris Petrilli posted a note about BLOBs and Zope database adapters on the zope-dev list. http://www.zope.org/pipermail/zope-dev/1999-July/000863.html See you next week. == Amos Latteier mailto:amos@digicool.com Digital Creations http://www.digicool.com -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From nevink@earthlink.net Tue Jul 27 16:15:45 1999 From: nevink@earthlink.net (nevin) Date: Tue, 27 Jul 99 15:15:45 GMT Subject: COMMERCIAL: C-Forge v1.3 (multi-user IDE) Message-ID: Code Forge Inc is proud to announce C-Forge v1.3. C-Forge is a multi-user integrated development environment that provides full project management and complete edit/compile/debug cycle support. Features include: * Complete abstraction of the "makefile" concept, * Project Manager for Visual presentation of project structure and component status using a dependency tree * separate "desktop" area showing work in progress, support for C/C++, Perl, Oracle ProC/C++, Tcl, Java, Python, Qt, Pascal, Free Pascal, FORTRAN, Modula-2 and Assembler, fully configurable integrated editor and more. New This Version: * New integrated (detachable) multi-process log window * Project-specific environment variables * JavaScript support * Etags/Ctags support * Improved Tex/LaTex support It is also our 2nd anniversary. We're throwing a 20%-50% off sale on all our products! Please visit us at www.codeforge.com and download a full featured evaluation version of C-Forge. (Free version also available) Feedback is, as always, welcome. For more please come to our web site, located at http://www.codeforge.com == Nevin Kaplan - Director of Marketing Code Forge, Inc. www.codeforge.com

C-Forge v1.3. - commercial IDE with Python support. (22-Jul-99) -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From Amos@digicool.com Tue Jul 27 16:18:52 1999 From: Amos@digicool.com (Amos Latteier) Date: Tue, 27 Jul 99 15:18:52 GMT Subject: XMLDocument 1.0a1 Message-ID: I am pleased to announce the first alpha release of XML Document. XML Document allows you to use xml objects in the Zope environment. You can create xml documents in Zope and leverage Zope to format, query, and manipulate xml. http://www.zope.org/Download/XMLDocument This release requires Zope 2.0x and the pyexpat parser which will be distributed with Zope come Zope 2.0b1. Until the Zope beta release you can get pyexpat from the Python xml-sig's xml package. http://www.python.org/sigs/xml-sig I'd love feedback on the functionality and design of this product. I think that it has a lot of potential. Also I encourage contributions on this project since I do not have a lot of time to spend on it myself. Happy xml hacking! -Amos P.S. Install it like a normal Zope product, i.e. ungzip and untar in inside your Zope directory. If you are using the xml-sig pyexpat, Zope will expect to find it in xml.parsers.pyexpat. == Amos Latteier mailto:amos@digicool.com Digital Creations http://www.digicool.com _______________________________________________ XML-SIG maillist - XML-SIG@python.org http://www.python.org/mailman/listinfo/xml-sig

XMLDocument 1.0a1 - Zope 2.0x product for formatting, querying and manipulating XML documents. (22-Jul-99) -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From oli@andrich.net Tue Jul 27 16:19:43 1999 From: oli@andrich.net (Oliver Andrich) Date: Tue, 27 Jul 99 15:19:43 GMT Subject: Python4linux -- Mailing list for discussing issues with the Python distribution for Linux and Python on Linux in general. Message-ID: Hi, I like to announce the creation of a new mailing list on starship.skyport.net which was setup to discuss the following topics: - The problems with the Python distribution for RPM based Linux systems (glibc 2.x Systems only) - The problems with Python on Linux in general. I know that this can be discussed in the newsgroup too, but I think that some people like to discuss some very specific things on a low volumen list. - The future of the Python distribution for Linux systems. Currently the whole project is run, administrated and maintained by myself with some very helpful contributors and users. But I like to move the whole thing to a group effort, where I see myself as one contributor to this effort who also tries to coordinate and maintain the whole effort - Discussion of new Linux platforms where we like to port Python too. And all this stuff. - I also like to focus the verious efforts to package Python stuff for Linux in one way. So that we can offer one location where Linux users interested in prepackaged stuff can go to and fetch what they want. The whole thing shouldn't be a "Oliver Andrich did it." show or so, but I want to spread Python as Perl has spread. And starship.python.net and python.org do a very good job. And we can supply an extra service for Linux users. I hope a lot of people will subscribe to this list and that we can coordinate the effort in a better way. And my personal mailbox get's a little bit smaller. Don't read this as "go away, I am to busy." but I think the whole project is way to big so that I can maintain it alone. ;-)))) Best regards, Oliver Andrich

Python4Linux mailing list - mailing list for discussing issues with the Python distribution for Linux and Python on Linux in general. (23-Jul-99) -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From Fred L. Drake, Jr." I've received enough hostile mail from Windows users not understanding how to unpack .tgz archives (er, WinZip works for me...) that I will be making most of the documentation packages available as ZIP archives as well as .tgz archives. For the most part, the ZIP archives are approximately the same size as the .tgz archives, but be aware that, even with maximal compression, the HTML ZIP archive is substantially larger than the .tgz equivalent. This is likely caused by the ZIP format having two directory entries for each file instead of one; with a lot of small files, this can make a difference. The new files are now available on the master FTP and Web sites at python.org; they should appear on mirrors over the coming week. -Fred == Fred L. Drake, Jr. Corporation for National Research Initiatives -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From skaller@maxtal.com.au Tue Jul 27 16:22:31 1999 From: skaller@maxtal.com.au (John MaxSkaller) Date: Tue, 27 Jul 99 15:22:31 GMT Subject: unicode data tables Message-ID: I have posted the unicode (and other) encoding subdocument of interscript v1.0a9 to the Web. At http://www.xenon.triode.net.au/~skaller/unicode/index.html you will find documented Python source for conversion of various character sets, including ISO-8859-X, Wansung, Johab, GB, Big5, ShiftJis, and various Microsoft/IBM proprietary code pages. The document contains a character by character description of the Unicode subset of ISO-10646, routines for converting UCS-2, USC2le, UCS-4, UCS4-le to UTF-8 (the native encoding used by interscript), and compact tables of all the glyphs (for unicode and each of the foreign character sets). If you're interested in internationalisation, you may find this web useful. You can browse online, or download it as a tarball (using http). You will need a browser with appropiate fonts to see Chinese, Japanese, Korean, Arabic and other glyphs. [Note: the table of contents uses a folding tree under MSIE4-5, it takes some time for my ECMA script to process the table. It's not broken, just slow!] John Max Skaller ph:61-2-96600850 mailto:skaller@maxtal.com.au 10/1 Toxteth Rd http://www.maxtal.com.au/~skaller Glebe 2037 NSW AUSTRALIA

unicode data tables - documented Python source for conversion of various character sets, including ISO-8859-X, Wansung, Johab, GB, Big5, ShiftJis, and various Microsoft/IBM proprietary code pages. (25-Jul-99) -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From gmcm@hypernet.com Tue Jul 27 16:23:14 1999 From: gmcm@hypernet.com (Gordon McMillan) Date: Tue, 27 Jul 99 15:23:14 GMT Subject: Win32 Installer - new release Message-ID: A new release (01a) of the Win32 Installer package is available on starship: http://starship.python.net/crew/gmcm/install.html This release incorporates bug fixes and some enhancements from (and inspired by) Robin Dunn. - A generated install script is now "safe" - File atimes, mtimes copied if possible - Install packages can be built from any directory - Ability to gather all dependencies in a directory, so you can use WinZip or WIse or whatever to distribute the results. What is it? Briefly, it is a sort of compilerless Freeze - a way of distributing Python apps with all the required Python support included. Python-style license. Contact: gmcm@hypernet.com

Win32 Installer release 01a - a compiler-less way of distributing Python apps on Windows. (25-Jul-99) -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From hinsen@cnrs-orleans.fr Tue Jul 27 16:25:06 1999 From: hinsen@cnrs-orleans.fr (Konrad Hinsen) Date: Tue, 27 Jul 99 15:25:06 GMT Subject: ScientificPython 2.0b1 Message-ID: The first public beta release of ScientificPython 2.0 is now available from http://starship.python.net/crew/hinsen/scientific.html and http://dirac.cnrs-orleans.fr/programs/scientific.html This is a completely revised release and *not* compatible with earlier releases. The major difference is the introduction of a package structure; all modules are now submodules of the top-level module Scientific. Version 2 also includes the netCDF interface module, which was previously in a separate distribution. Another important new feature is full documentation :-) Following established traditions in the Python community, I will be on vacation for three weeks from Wednesday. Please take your time to fix any bugs before reporting them to me ;-) == ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hinsen@cnrs-orleans.fr Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-2.38.25.55.69 Rue Charles Sadron | Fax: +33-2.38.63.15.17 45071 Orleans Cedex 2 | Deutsch/Esperanto/English/ France | Nederlands/Francais -------------------------------------------------------------------------------

ScientificPython 2.0 - Konrad Hinsen's collection of scientific/math modules; now includes netCDF module and full documentation. (26-Jul-99) -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From wolfgang.grafen@de.bosch.com Tue Jul 27 16:27:20 1999 From: wolfgang.grafen@de.bosch.com (Wolfgang Grafen) Date: Tue, 27 Jul 99 15:27:20 GMT Subject: seqdict 0.0 - 2 sequential dictionary emulations Message-ID: 26.7.1999 http://www.germany.net/teilnehmer/100,366919/Python/Modules/Modules.html Package seqdict Module seqdict version 0.0 Module mseqdict version 0.0 ================================================ seqdict - single value dictionary msedict - multiple value dictionary The Python built-in dictionary has no reliable sequence order because of performance reasons. The two new dictionaries introduced here keep their entries in sequence. * seqdict keeps one value for one key * mseqdict keeps multiple values per key and is the closest emulation of areal world dictionary. As the sequential dictionary is a combination of a list and a dictionary you can do most operations defined with lists as well and much more. Now you can slice, add, sort with dictionaries. The functional operations map, filter, reduce are implemented as well. Use a dictionary like a stack with push and pop. Split it, reverse it and swap keys and values. A small tutorial is provided as HTML and Postscript Source and is subject to become improved some other day. I think both dictionaries are candidates for the python standard library. Use the seqdicts to emulate a printed dictionary. Use them for csv-tables. Keep parsed code in a seqdict, modify it and write it back ... Download from http://www.germany.net/teilnehmer/100,366919/Python/Modules/Modules.html Wolfgang Grafen mailto:WolfgangGrafen@gmx.de For the web thingy:

seqdict 0.0 - package with two sequential dictionary emulations. (26-Jul-99) Wolfgang Grafen mailto:WolfgangGrafen@gmx.de -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From kernr@mail.ncifcrf.gov Tue Jul 27 16:27:58 1999 From: kernr@mail.ncifcrf.gov (Robert Kern) Date: Tue, 27 Jul 99 15:27:58 GMT Subject: Updated compile tools for egcs/mingw32 Message-ID: Hello all, compmgw.py and makemgw.py are Python scripts that ease the compilation of Python extensions on Win32 using the free egcs 1.1.2 compiler on the i386-mingw32 target. compmgw.py processes a Setup file and generates a Makefile that will compile your extension. makemgw.py processes a Setup file but runs the compiler commands itself and bypasses the Makefile. It uses a very simple (and probably inefficient and wrong) dependancy checker to generate the list of commands to run. WARNING: The code in both of these modules is incredibly bad. "hacks upon hacks upon hacks" sums up the state of these scripts pretty well. Do not read them if you have a heart condition. *Please* don't use them for anything else. Instead join the distutils-SIG and work with them to create a general mechanism. Both of these scripts will be dropped unceremoniously once the distutils-SIG gets far enough in its work. The scripts are available separately: * http://starship.python.net/crew/kernr/mingw32/compmgw.py * http://starship.python.net/crew/kernr/mingw32/makemgw.py or together with other tools: * http://starship.python.net/crew/kernr/mingw32/Py-mingw32-tools.zip Robert Kern

Updated compile tools for egcs/mingw32 - updated scripts to parse Setup files for compiling on Win32 systems with egcs/mingw32. (27-Jul-99) -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From fleck@informatik.uni-bonn.de Tue Jul 27 16:39:03 1999 From: fleck@informatik.uni-bonn.de (Markus Fleck) Date: Tue, 27 Jul 99 15:39:03 GMT Subject: [fm] Zope 2.0.0b1 Message-ID: Zope 2.0.0b1 amos - July 25th 1999, 14:50 EST Zope is a free, Open Source web application platform used for building high-performance, dynamic web sites. It contains a powerful and simple scripting object model and high-performance, integrated object database. Changes: Major changes include: ZODB 3, the next generation of the Zope Object Database, Z Classes, a new mechanism for building Zope applications, WebDAV support, and ZServer, the integration of Zope and Medusa. Download:http://www.zope.org/Download/ Homepage:http://www.zope.org/ Changelog:http://www.zope.org/Download/Releases/Zope-2.0.0b1/CHANGES.txt Author: Digital Creations License: OpenSource Category: Web/Development Freshmeat (c) 1999 scoop@freshmeat.net

Zope 2.0.0b1 - Zope is a free, open source web application platform used for building high-performance, dynamic web sites. (25-Jul-99) -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From fleck@informatik.uni-bonn.de Tue Jul 27 16:44:39 1999 From: fleck@informatik.uni-bonn.de (Markus Fleck) Date: Tue, 27 Jul 99 15:44:39 GMT Subject: [fm] FXPy 0.99.55 Message-ID: FXPy 0.99.55 Lyle Johnson - July 22nd 1999, 04:06 EST FXPy is a Python extension module which provides an interface to the FOX cross-platform GUI library. With a few minor exceptions, FXPy provides a complete interface to FOX. FOX is a C++-based toolkit for developing graphical user interfaces easily and effectively, and it runs natively under both Unix/X and Microsoft Windows. Some of the significant features of FOX include a rich set of widgets, powerful but easy-to-use layout managers, extensive support for 3-D modeling using OpenGL or Mesa, drag-and-drop (using the XDND protocol) and a registry for persistent application settings. Changes: This is the first official announcement. Download:ftp://ftp.cfdrc.com/pub/FOX/FXPy-0.99.55.tar.gz Homepage:http://www.airnet.net/ljohnson/FXPy/ Author: Lyle Johnson License: LGPL Category: Development/Python Modules Depends on: Python, FOX (and optionally PyOpenGL) Freshmeat (c) 1999 scoop@freshmeat.net

FXPy 0.99.55 - Python interface to the FOX free cross-platform C++ graphical user interface library for Unix/X11 and Microsoft Windows. (22-Jul-99) -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From M.Wise@ccsr.cam.ac.uk Wed Jul 28 19:13:37 1999 From: M.Wise@ccsr.cam.ac.uk (Michael Wise) Date: Wed, 28 Jul 99 18:13:37 GMT Subject: Agrepy 1.0: Python port of agrep string matching with errors Message-ID: agrep is a suite of command-line (i.e. UNIX user level) string matching functions, written by Sun Wu and Udi Manber (described in "Fast Text Searching Allowing Errors", CACM, 35(10), 1992). While the majority of the functionality is already found in Python, the ability to perform string searches accepting a limited number of errors has not been available till now. Such searches are able to deal, for example, with spelling errors, or the differences between North American and British English. Alternatively, this form of string matching is able to model the attachment of a primer to a target DNA sequence (i.e. attachment occurs if there are no more than, say, 2 indels).

agrepy 1.0 - Python interface to the agrep approximate string matching implementation. (27-Jul-99) -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From dsnider@mindspring.com Wed Jul 28 19:17:21 1999 From: dsnider@mindspring.com (Dan Snider) Date: Wed, 28 Jul 99 18:17:21 GMT Subject: COMMERCIAL: ObjectDomain 2.5 (UML modeling tool) Message-ID: The final release of ObjectDomain 2.5 is now available! See download information below. Object Domain Systems unveils ObjectDomain 2.5, the latest version of our flagship UML modeling tool. Implemented in pure Java, ObjectDomain provides a scalable, multi-platform, user extendable CASE tool that redefines the expectations of object modeling software. NEW FEATURES: - Support for all nine UML diagrams backed by a true UML meta-model - Better performance with smaller memory footprint - Version control and multi-user support via file-based repository - HTML documentation and glossary generation for user models - Advanced model searching with regular expression support - Full round-trip for Java - Various UI enhancements Note: Some features may not be available in the standard edition. FEATURES PREVIOUSLY INCLUDED: - Code generation and reverse engineering for Java, C++, and Python - Powerful diagramming with auto-layout, bezier curves, color support, stereotype icons, and extensive control of presentation aspects using "styles" - Intuitive user interface with switchable look-and-feel and theme support. Open architecture allows additional language support, user customization and third-party add-ins - Python scripting support with integrated command console - Interface features include multi-perspective browsing, unlimited undo/redo, and a diagram thumbnail view that allows panning and zooming QUANTITY DISCOUNTS In addition to our standard quantity discount, we are also offering a special discount or the purchase of multiple copies. For further information call 919-461-4904. OBJECTDOMAIN 2.6 WILL BE A FREE UPGRADE! Although the exact feature set is not finalized, we have committed to providing 2.6 as a FREE upgrade to 2.5. Features we plan for 2.6 include: - Round trip engineering for C++ (currently have round trip engineering for Java) - Full import/export Rational Rose model files - Support for Java 2 (previously known as Java 1.2) - Enhanced printing - Updated alignment UML 1.3 - Various UI enhancements - IDL generation ------------------------------------------------------------------------ Learn more about ObjectDomain 2.5: http://www.objectdomain.com/domain Download ObjectDomain 2.5: http://www.objectdomain.com/odEvalUser The ObjectDomain Development Team Object Domain Systems Inc. support@objectdomain.com http://www.objectdomain.com

ObjectDomain 2.5 - commercial UML modeling tool with Python scripting support. (27-Jul-99) -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From mmuller@enduden.com Wed Jul 28 19:19:38 1999 From: mmuller@enduden.com (Michael Muller) Date: Wed, 28 Jul 99 18:19:38 GMT Subject: PyESD - Python Wrapper for EsounD library Message-ID: PyESD is a SWIGged wrapper around the Enlightenment Sound Daemon client library with some additional classes to provide a more object-oriented interface. URL: http://www.users.cloud9.net/~proteus/pyesd/ Contact: proteus@cloud9.net License: Variation on BSD, free for commercial and non-commercial use ============================================================================= michaelMuller = proteus@cloud9.net | http://www.cloud9.net/~proteus ----------------------------------------------------------------------------- We are explorers in the further reaches of experience: demons to some, angels to others. - "Pinhead" from "Hellraiser" =============================================================================

PyESD - Python interface to the Enlightenment Sound Daemon client library for UNIX. (27-Jul-99) -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From gherman@my-deja.com Wed Jul 28 19:20:45 1999 From: gherman@my-deja.com (Dinu C. Gherman) Date: Wed, 28 Jul 99 18:20:45 GMT Subject: codeplot Message-ID: Codeplot This is something like a toy example for Piddle that you might use as well to visually fingerprint Python code in a weird way, a bit like in the "Matrix", perhaps. ;-) Introduction (from codeplot's doc string): This module takes a Python source code file and creates a two-dimensional plot out of it. The plot generated is a symmetrical one, much like a 2D matrix where a dot at (i,j) indicates that lines i and j in the input file are the same. Sounds silly? Maybe, yes. After all, this is a one day fun 'project' while reading a book on, you guessed it, patterns. But I guess you'll be surprised of what you can see in these silly plots. Peaks result by definition from identical lines (in red). Very often this will be the case due to empty lines, therefore these lines are marked distinctly (grey). Other interesting things come from lines that are similar, but not identical. In the current implementation, "similar" means lines that are identical modulo an arbitrary inden- tation (marked in blue). So this is a little bit only of a bias towards Python as a language, but in fact you can run codeplot on any kind of ASCII file (that is made of individual lines, separated by newlines). The plots are generated using the new PIDDLE interface (during development codeplot created PDF files) in the version 1.0.3. Some words of praise for PIDDLE: it's cool! Without it codeplot would never have happened. What's the future of this thing?! I don't know! I'll do a bit more here and there, maybe create a proper EPS file instead of PDF (such that it can be included some- where else more easily). There's likely still something to improve to handle indentation by tabs properly as well. It could be faster, perhaps, but it's inherently O(n^2), so don't use it on a 200 KB C file (yes - they DO exist, sigh...). Using Numeric might be an idea, not sure... If you think you can do something to improve it let me know. If you use it in some interesting way, let me know, too. Installation: Put codeplot.py somewhere in your Python path. Also make sure you have Piddle already installed. You can find Piddle here: http://www.strout.net/python/piddle/ Files: README.txt - This file. codeplot.py - The Python codeplot module. samples.zip - Some sample PDF files. The samples were more or less randomly selected from the following packages: pythondoc, idle, pdfgen, piddle, consdiag, Zope, the Python Interpreter (a C file) and codeplot itself (the filenames should suffice to get an idea of where they awere taken from). The original python files are not included, though (except codeplot.py). Several differences can be observed, but these are to be explained elsewhere. Contact: Author: Dinu C. Gherman, gherman@europemail.com.nospam Web-Site: http://starship.python.net/crew/gherman/playground/codeplot/ Copyright: Do with it whatever you want, but don't sue me! If you make money with codeplot, pay me half of it as royalities! ;-) 1999-07-28 (codeplot 0.1) Sent via Deja.com http://www.deja.com/ Share what you know. Learn what you don't.

codeplot 0.1 - visually fingerprint Python code in a weird way... (28-Jul-99) -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From Amos@digicool.com Wed Jul 28 21:32:29 1999 From: Amos@digicool.com (Amos Latteier) Date: Wed, 28 Jul 99 20:32:29 GMT Subject: Zope Weekly News - Wed, 28 Jul 1999 Message-ID: Hello, The big news this week was the release of Zope 2.0 beta one. Zope 2 final is getting closer and closer. Beta one increases stability over the alpha releases and also adds a few missing pieces like the ability to tie permissions to factories. Also you can now export Zope objects to XML. Speaking of XML, as of beta one all basic Zope objects support a subset of the DOM Element interface, and the unsupported XML Document product is out and in CVS. * Zope 2.0 beta one was released this week. Now you can download a binary release of Zope 2. http://www.zope.org/Download/Releases/Zope-2.0.0b1 * The Zope site received a look and feel makeover. Most people seem to like the new design. A couple people posted describing the strange feeling of having the entire site change while browsing it. Zope sessions are cool! http://www.zope.org/pipermail/zope/1999-July/007368.html * Amos Latteier announced the availability of XML Document 1.0a1 a Zope product for using XML. A couple days later, XML Document made it into public CVS. http://www.zope.org/pipermail/zope/1999-July/007126.html http://www.zope.org/Download/XMLDocument http://www.zope.org/pipermail/zope-dev/1999-July/000990.html * Anthony Pfrunder announced a new version of his Zope for windows distribution. http://www.zope.org/pipermail/zope/1999-July/007189.html * Michel Pelletier announced Zippy Tag which allows you to insert random Zippy the Pinhead quotes in your Zope documents. Yes! http://www.zope.org/pipermail/zope/1999-July/007190.html http://www.zope.org/Download/Contrib/Zippy.tgz * Paul Everitt discusses how you can now export Zope objects to XML. Basically the XML format describes Python pickles. http://www.zope.org/pipermail/zope/1999-July/007200.html * Michel Pelletier posted an extremely simple summary of how to hook a form to a database. This is a good read for those new to Zope. http://www.zope.org/pipermail/zope/1999-July/007336.html * Andreas Kostyrka posted a patch to allow Zope to server multiple sites from one process. Very interesting, multiple sites from one object database! http://www.zope.org/pipermail/zope-dev/1999-July/000931.html http://www.mtg.co.at/projects/subhosting/ * Eric Kidd posted a Zope/XML-RPC todo list. Follow up posts confirmed that a number of the items have already been done. http://www.zope.org/pipermail/zope-dev/1999-July/000972.html * Brian Lloyd posted an insightful message describing the 'Owner' role and how to use proxy roles to allow limited access to restricted functions. http://www.zope.org/pipermail/zope-dev/1999-July/000987.html * Chris Petrilli mentioned that Gadfly is finally being updated to the latest version. Alright! http://www.zope.org/pipermail/zope-dev/1999-July/001002.html See you next week, same time, same channel. -Amos == Amos Latteier mailto:amos@digicool.com Digital Creations http://www.digicool.com -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From mal@lemburg.com Fri Jul 30 15:26:34 1999 From: mal@lemburg.com (M.-A. Lemburg) Date: Fri, 30 Jul 99 14:26:34 GMT Subject: mxTextTools Package - Version 1.1.0 Message-ID: ANNOUNCING: mxTextTools Version 1.1.0 A Python extension package providing fast text scanning and processing tools WHAT IT IS: mxTextTools is an extension package for Python that provides * a fast text search type (using a modified Boyer-Moore algorithm) * a finite state machine for marking and analysing text (the Tagging Engine) * a set of specialized text processing functions * a set of functions that work with character sets Applications include parsing structured text, finding and extracting text (either exact or using translation tables) and recombining strings to form new text. Everything was implemented having high performance in mind. WHAT'S NEW ? The 1.1.0 release adds several new text processing functions to the already large set: splitlines(), countlines(), suffix(), prefix(), str2hex() and hex2str(). Many existing functions/objects were enhanced to work in a more general context. All the details are available at: http://starship.skyport.net/~lemburg/mxTextTools.html#History This release also includes a precompiled Windows DLL so that you can use the package right away. Installing on that platform boils down to a simple unzip in the \Python\Lib directory. WHERE CAN I GET IT ? The full documentation and instructions for downloading and installing can be found at: http://starship.skyport.net/~lemburg/mxTextTools.html WHAT DOES IT COST ? It comes with a Python-type license, but is free otherwise. WHERE CAN I GET SUPPORT ? I am offering commercial support for this package through Python Professional Services Inc. (http://www.pythonpros.com). Look on their support pages for details or contact me directly. REFERENCE:

RTSP proxy - quick-and-dirty proxy server for the RTSP/RTP streaming media protocols, written in Python. (29-Jul-99) -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From jonathan@onegoodidea.com Fri Jul 30 15:33:21 1999 From: jonathan@onegoodidea.com (Jonathan Hogg) Date: Fri, 30 Jul 99 14:33:21 GMT Subject: Python/PostgreSQL interface module Message-ID: well after much lurking and occasional commenting on these groups, here is my first contribution to the community. it's a module for accessing PostgreSQL databases from Python. yes, i know there already is one, but i wanted to play with some different features and to get the hang of writing extension modules. you are free to not use this module. please don't email me to tell me i've wasted my time - all learning is worthwhile and maybe someone else will get something useful from this. i'm afraid it doesn't have a proper name yet because i can't think of one - a free copy of the source for the best idea ;-) i welcome feedback, :-j (extracted from the README:) Python/PostgreSQL Interface Module (Version: 1.0) ---------------------------------- Summary: -------- PostgreSQL is a neat, free, relational database system which can be found at: This is a module that provides the PostgreSQL programmers' API to Python programmers. It is written in C and compiles down to a shared-object file that can be dynamically loaded into the Python interpreter. It is basically a wrapper around the 'libpq' library that comes with PostgreSQL. Limitations: ------------ This interface has not been used in anger yet. It's been written as part of a one good idea project and I'm releasing it more widely because it may be of use to other people and might result in some useful feedback. License: -------- There should be a LICENSE file accompanying this distribution (and at the top of each source file). I've used the Berkeley license because I've always liked it. This code is not copylefted, feel free to stick it into a commercial product and sell it, become rich, buy a small island in the pacific, retire young and happy. However, you have to retain the copyright on the code, and it would be polite to send me a note of thanks ;-) Obtaining The Latest Distribution: ---------------------------------- You should be able to find it by following the obvious links on the one good idea webpages for 'Projects': As of this distribution, the appropriate URL was: PyGreSQL -------- This module is not PyGreSQL. PyGreSQL is written by D'Arcy J.M. Cain, . It is another Python/PostgreSQL interface which has been around longer than this one. I wrote this module because I wanted a different mechanism for accessing named fields in query results (and partly as an exercise in extending Python). == jonathan hogg, one good idea limited, 25 clouston street, glasgow g20 8qr, uk jonathan@onegoodidea.com www.onegoodidea.com t:(0)976-614338 f:(0)7970-537451

Python/PostgreSQL API - access PostgreSQL programmers' API from Python. (29-Jul-99) -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From bwarsaw@cnri.reston.va.us (Barry A. Warsaw) Sat Jul 31 00:40:51 1999 From: bwarsaw@cnri.reston.va.us (Barry A. Warsaw) (Barry A. Warsaw) Date: Fri, 30 Jul 99 23:40:51 GMT Subject: Wash. D.C. Area: DCPIGgies Get Together Message-ID: Notice to all Washington DC area Python users: We are pleased to be resurrecting the DC area Python interest group meetings, now called DCPIGgies. We will be having our first meeting at CNRI in Reston, Virginia on Tuesday August 31, 1999 from 7:30pm to 9:30pm. The aim is to keep this meeting pretty technical. To that goal, we're going to have two exciting presentations. For the first hour, the Digital Creations guys will be giving a talk on Zope 2.0's unique object model (acquisition, run-time classes, transactional objects, etc.) including how Python programmers might use this in their own non-Zope projects. In the second hour, Andrew Kuchling will be talking about something XML-ish, probably processing the Open Directory Project's (www.dmoz.org) RDF dumps. There will be question and answer periods after each talk, and we may have an "open phones" going later than 9:30 if there's interest and if Guido or I am still awake. :) Pizza, salad, and soda will be provided. We are asking for a voluntary $5 donation at the door to cover the costs of food. It is very important that you RSVP by email to bwarsaw@cnri.reston.va.us so that I can get an accurate head count (otherwise you may go hungry!). We also need to make sure that we can fit everyone into our conference room, so let me know if you're coming, even if you aren't going to eat. Directions to CNRI can be found on the Web: http://www.cnri.reston.va.us/directions.html See you then! -Barry -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From bwarsaw@cnri.reston.va.us (Barry A. Warsaw) Sat Jul 31 00:43:42 1999 From: bwarsaw@cnri.reston.va.us (Barry A. Warsaw) (Barry A. Warsaw) Date: Fri, 30 Jul 99 23:43:42 GMT Subject: Mailman 1.0 Message-ID: On behalf of the rest of the Mailman Cabal, I'm very happy (and somewhat relieved) to announce the release of Mailman 1.0. I've just uploaded the tarball to www.list.org so follow the links there to download it. Mailman -- the GNU Mailing List Manager -- is software to help manage email discussion lists, much like Majordomo and Smartmail. Unlike most similar products, Mailman gives each mailing list a web page, and allows users to subscribe, unsubscribe, etc. over the web. Even the list manager can administer his or her list entirely from the web. Mailman also integrates most things people want to do with mailing lists, including archiving, mail-to-news gateways, and so on. Mailman is written almost completely in Python (there's a little bit of C for security purposes). Mailman is distributed under the terms of the GPL. >From the NEWS file, here are the list of changes since 1.0rc3: - Configure script now allows $PREFIX (by default /home/mailman) to be permissions 02755. Also, configure now tests for vsnprintf() - Workaround, taken from GNU screen, for systems missing vsnprintf() - Return-Receipt-To: and Disposition-Notification-To: headers are always removed from posted messages (they can be used to troll for list membership). - Workaround for MSIE4.01 (and possibly other versions) bug in the handling of cookies. - A small collection of other bug fixes. Enjoy, -Barry

Mailman 1.0 - the GNU Mailing List Manager, written in Python; features a web-based subscription and list maintenance interface. (30-Jul-99) -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From samschul@pacbell.net Sat Jul 31 05:15:32 1999 From: samschul@pacbell.net (Sam Schulenburg) Date: Sat, 31 Jul 99 04:15:32 GMT Subject: A Python SCSI hard drive development environment for Windows95/98/NT Message-ID: ASPYPython is a environment for the testing and development of SCSI hard drives. Using Guido van Rossum's IDLE environment allows for the rapid development of test scripts that can be used in the evaluation and testing of SCSI hard drives using the ASPI (Advanced SCSI Programming Interface) that is available under Windows 95/98/NT. The low level SCSI interface functions are incorporated in a DLL (ASPIPy.dll) that behaves like a traffic cop between the user and the hard drive. all commands from the user are sent from Python to the dll, and all drive responses are sent from the dll to either the log file, the user via Python, or both. Higher level scripts and error messages are provided by ASPI.py. This file contains all the startup and initializing function needed by the DLL. Some of the following features are provided by the DLL,and ASPI.py 1) Six byte, Ten byte, and Twelve byte commands are supported with io6(),io10(),and io12() functions that take either hex or decimal parameters i.e Inquiry command would be io6(0x12,0x00,0x00,0x00,0xff,0x00) or io6(18,0,0,0,255,0). 2) Sensekey and Sensecode values are translated to English statements for the user. i.e 0x06,0x29,0x00 would be displayed as 'Unit Attention ', 'Power On Reset, Or Bus Device Reset Occurred ' 3) Added help has been placed in the help menu under IDLE this help contains the folling items: a) Help for ASPIPython. All functions are documented here and in documentation string within each function b) Help of Python itself. A link is provided to a public domain browser that brings up the Python Documentation c) A makedocs link that allows users to add their own help messages to their scripts (See Documentation) 4) All of the advantages of Python for rapid modification and development of test scripts 5) Sample script files that demonstrate the use of these libraries. For further information see the Documentation at http://starship.python.net/crew/schulenburg

ASPIPython - an ACPI/SCSI hard drive development environment for Windows95/98/NT. (30-Jul-99) ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From fleck@informatik.uni-bonn.de Sat Jul 31 06:26:19 1999 From: fleck@informatik.uni-bonn.de (Markus Fleck) Date: Sat, 31 Jul 99 05:26:19 GMT Subject: [fm] Pagecast 1.1.0 Message-ID: Pagecast Preston Landers - July 01st 1999, 20:27 EST Pagecast submits lists of URL's to various search engines such as AltaVista, Infoseek, Excite, Google, etc to be indexed. It can run from the command-line or as a mail-robot (email a list of URL's to pagecast@yourmachine). It has a few advanced features such as the ability to rate a URL's keyword-to-title relevance and fix broken meta tags. Pagecast requires Python (with threading.) Download: http://askpreston.com/projects/pagecast/pagecast-1.1.0.tar.gz Homepage: http://askpreston.com/projects/pagecast/index.html Changelog: http://askpreston.com/projects/pagecast/ChangeLog.txt Stable Version: 1.1.0 Author: Preston Landers License: GPL Category: Web/Tools Depends on: Python Appindex ID: 930875279 Announcements * Pagecast 1.1.0 - by Preston Landers on July 28th 1999, 05:12 * Pagecast 1.0.1 - by Preston Landers on July 05th 1999, 12:07 * Pagecast 1.0 - by Preston Landers on July 02nd 1999, 17:14 Comments: new mailing list for Pagecast Preston Landers - July 06th 1999, 23:06 EST Visit the Pagecast home page (listed above) for information about joining the new Pagecast mailing list. Possible incompatibility Preston Landers - July 15th 1999, 19:12 EST Some users are reporting problems with Pagecast and other Python software when they are running both the newest Python 1.5.2 *and* the Linux Kernel version 2.0.x. The solution pending further debugging is to either upgrade to Linux 2.2.x or downgrade Python to 1.5.1. Freshmeat (c) 1999 scoop@freshmeat.net

Pagecast 1.1.0 - submit lists of URLs to search engine spiders. (28-Jul-99) -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From fleck@informatik.uni-bonn.de Sat Jul 31 06:30:06 1999 From: fleck@informatik.uni-bonn.de (Markus Fleck) Date: Sat, 31 Jul 99 05:30:06 GMT Subject: [fm] Gnumeric 0.31 Message-ID: Gnumeric Miguel de Icaza - September 30th 1998, 17:52 EST Gnumeric is a powerful and easy to use spreadsheet program from the GNOME project. The goal for this spreadsheet is to compete with the commercial offerings. Users of Excel should be already familiar with Gnumeric advanced features. A plugin system lets you extend Gnumeric with GPL extensions, and an optional Python and Perl plugins let you define complex functions in those popular languages. Download: ftp://ftp.gnome.org/pub/GNOME/sources/gnumeric/ Red Hat packages: ftp://ftp.gnome.org/pub/GNOME/redhat/ Mirror List: http://www.gnome.org/ftpmirrors.shtml Homepage: http://www.gnome.org/gnumeric/ Changelog: http://www.gnome.org/gnumeric/gnumeric-0.31 Stable Version: 0.27 Development Version: 0.31 Author: Miguel de Icaza License: GPL Category: GNOME/Applications Appindex ID: 907192372 Freshmeat (c) 1999 scoop@freshmeat.net

Gnumeric 0.31 - another snapshot of the GNOME project's spreadsheet application; allows writing complex functions in Python and Perl. (30-Jul-99) -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From fleck@informatik.uni-bonn.de Sat Jul 31 06:34:09 1999 From: fleck@informatik.uni-bonn.de (Markus Fleck) Date: Sat, 31 Jul 99 05:34:09 GMT Subject: [fm] The BeOpen.com OO-Browser Message-ID: The BeOpen.com OO-Browser RSW - July 29th 1999, 23:15 EST The BeOpen.com OO-Browser is a multi-windowed, interactive object-oriented class browser similar in use to the well-known Smalltalk browsers. It is unique in a number of respects foremost of which is that it works well with a multiplicity of object-oriented languages. It provides both textual views within an editor and graphical views under the X window system and Windows. Support for C, C++, Common Lisp and its Object System (CLOS), Eiffel, Java, Objective-C, Python and Smalltalk class browsing is included. Download: http://www.BeOpen.com/products.html Homepage: http://www.BeOpen.com/ Changelog: http://www.BeOpen.com/BR-RELEASE Stable Version: 4.06 Author: BeOpen.com License: GPL Category: Development/Tools Depends on: BeOpen.com InfoDock, XEmacs or Emacs Appindex ID: 933304552 Freshmeat (c) 1999 scoop@freshmeat.net

BeOpen.com OO-Browser - multi-windowed, interactive object-oriented class browser; includes support for Python class browsing. (30-Jul-99) -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------ From tim_one@email.msn.com Sat Jul 31 06:34:37 1999 From: tim_one@email.msn.com (Tim Peters) Date: Sat, 31 Jul 99 05:34:37 GMT Subject: NatLink v001: Talk to your Python! Message-ID: Apologies if you've seen this before: a coworker posted it to the python and announce groups, but I never saw it come across on their mailing-list versions. So I'm mailing it to both. Original msg, w/ HTML citation appended: NatLink v001 by Joel Gould I would like to announce the availability of a package which allows Python programs to use large vocabulary speech recognition by interfacing to Dragon NaturallySpeaking. NatLink is a Python extension module which allows direct access and control of Dragon NaturallySpeaking. Dragon NaturallySpeaking is the best selling large vocabulary (i.e. dictation) speech recognition program commercially available. NatLink requires that you already have a copy of Dragon NaturallySpeaking (sorry). It also only runs under Windows 95/98/NT (sorry again). But with NatLink, you can: (1) add speech recognition to your Python programs (2) control Dragon NaturallySpeaking from Python (3) write voice macros in Python for Dragon NaturallySpeaking For more details, visit: http://www.synapseadaptive.com/joel/natlink.htm Note: NatLink is not a product but a freely downloadable package. Joel Gould joelg@alum.mit.edu

NatLink v001 - speech recognition via Dragon NaturallySpeaking. (31-Jul-99) -- ----------- comp.lang.python.announce (moderated) ---------- Article Submission Address: python-announce@python.org Python Language Home Page: http://www.python.org/ Python Quick Help Index: http://www.python.org/Help.html ------------------------------------------------------------