From hokiegal99 at vt.edu Mon Aug 18 21:06:00 2003 From: hokiegal99 at vt.edu (hokiegal99) Date: Mon, 18 Aug 2003 21:06:00 -0400 Subject: a twisted question References: Message-ID: <3F4177F8.2000406@vt.edu> On my RH boxes, the distro's Python pkg is installed in /usr/bin/ however, when you download and install the latest stable Python (2.3), it should install into /usr/local/bin/. This setup works for me. I used it for testing when I needed 2.3b2 functionality w/o problem. xam wrote: > Hi All, > I have got a bit of a complicated situation here: > I need to get buildBot (and hence twisted) running on RH 7.1, which > currently has python 1.5 installed. From browsing newsgroups it appears that > I cannot overwritte 1.5 due to some RH scripts relying on that version. So: > 1) can twisted run on 1.5? I could not find this info in the docs. > 2) if not, can it run on parallel-installed later version? > 3) if so, could someone give me a hint on installing a parallel version? > > thanks, > max. From tismer at tismer.com Thu Aug 28 22:42:33 2003 From: tismer at tismer.com (Christian Tismer) Date: Fri, 29 Aug 2003 04:42:33 +0200 Subject: [Zope-dev] Zope 2.7 running with Stackless 3.0 In-Reply-To: References: <3F4D44EB.5010500@tismer.com> <3F4DF1E7.1010103@zope.com> <3F4E3CE1.5030405@tismer.com> Message-ID: <3F4EBD99.2050406@tismer.com> Michael Geary wrote: ... > As much as like Python, I *really* miss the Edit and Continue feature from > Visual C++. It's truly liberating to be able to change my code right in the > midst of debugging it, with all its state preserved. I often write a > skeleton for a function, start it up, and then finish coding it while I'm > running it. There is the general Python problem, that a running frame does not exactly know about its function object. There is only a name and a filename available in the code object, and the code object is the only thing a frame knows about. I think to propose a PEP about this. > Even short of that, none of the Python debuggers I've tried support a Set > Next Statement command like Visual C++ does. That itself is mighty useful. > Maybe Stackless would make it possible to support this? In most cases Stackless could do that. Given a reliable way to deduce the module/function from a frame (see above), it would be possible to edit the function, create a new code object, and create a new frame. not-a-task-for-this-weekend-anyway -- ly 'yrs - chris p.s.: Please Delete.This. - we are all fighting SPAM. -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 mobile +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From tzot at sil-tec.gr Sun Aug 24 01:18:27 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Sun, 24 Aug 2003 08:18:27 +0300 Subject: How to import a standard module in source file with same name? References: <420ced91.0308232052.70e905d5@posting.google.com> Message-ID: On 23 Aug 2003 21:52:11 -0700, rumours say that sdhyok at yahoo.com (sdhyok) might have written: [snip of problem description as per the subject] >Under the condition that the absolute path to the standard module >is variable in different machines >(so, imp.find_module may not be a solution), >is there an elegant way to solve this problem? You might try changing the case... call it DateTime for example; there must be some magic in the C code (if you work on Windows) that matches in a case-sensitive way. Or you can do (in the importing module, possibly your main program): import datetime import vp.datetime vp.datetime.datetime = datetime -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From bignose-hates-spam at and-benfinney-does-too.id.au Sun Aug 3 22:55:59 2003 From: bignose-hates-spam at and-benfinney-does-too.id.au (Ben Finney) Date: 4 Aug 2003 12:45:59 +0950 Subject: Determining if a filename is greater than X characters References: <93f5c5e9.0308021815.44c57a2d@posting.google.com> <3F2DC543.70700@vt.edu> Message-ID: On Sun, 03 Aug 2003 22:30:27 -0400, hokiegal99 wrote: > How would I append a string to the end of each file that I've > truncated? The concatenation operator for strings is '+': It would behoove you to work through the Python tutorial all the way, to get a solid grounding in the language: > Researching a bit on Google told me that in Python strings are > unchangeable. You're probably reading the word "immutable" (which, in English, means pretty much the same thing, so the confusion is understandable). String objects can't be changed (they are immutable), but you can bind the name (the "variable") to a new string object, thus changing the value referred to by the name. Same thing happens when you perform arithmetic on a name bound to an integer object: >>> foo = 1 >>> foo 1 >>> foo = foo + 2 >>> foo 3 >>> What's happening here? The name 'foo' is being bound to the integer object '1'. Then a new integer object is created with value '3' (as a result of the arithmetic) and the name 'foo' is bound to the new object (as a result of the assignment). Thus, integer objects are immutable, but the name can be bound to a new object with a different value by an assignment operation. At the level of strings and integers, the distinction between "string objects can be changed by assigning a new value" (incorrect) and "string objects are immutable, assignment binds to a new object" (correct) seems to make no difference. If you learn this, though, other aspects of object behaviour will be much easier to understand. -- \ "If you're a horse, and someone gets on you, and falls off, and | `\ then gets right back on you, I think you should buck him off | _o__) right away." -- Jack Handey | Ben Finney From vze4rx4y at verizon.net Thu Aug 14 02:01:01 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Thu, 14 Aug 2003 06:01:01 GMT Subject: Py2.3: Feedback on Sets References: <1rnljv8527o2phdjup4e9uji0kssf93svt@4ax.com> Message-ID: > >"iterable" *is* . If something is "iterable" it has a well-defined interface - specifically: > > I get what you mean, but let me point out that "iterable" does not appear > in the index of either the Language Reference or Library Reference, nor do > I see it in the introduction. Actually, the introduction would really > benefit from a description of all the conventions used in the manual. As > it stands, one has to come across this usage several times to realize it's > a convention (and that's not the way many people use reference manuals). > > What would be really cool, and probably easy, is to just make sure that > every occurrence of "iterable" is a link to a page that describes that > well-defined interface. > > This is still beyond the scope of the question about the Set documentation. > I appreciate the responses, but I'm not sure whether this is the right time > to continue this sort of discussion. It is exactly the right time and place. I frequently make documentation fixes based on the comp.lang.python discussions. Each fresh pair of eyes sees something new. Achieving excellent documentation is a journey and not a destination. Raymond Hettinger From querdenker at mtsi.de Wed Aug 27 15:02:12 2003 From: querdenker at mtsi.de (querdenker) Date: 27 Aug 2003 12:02:12 -0700 Subject: Python Windows 2.3 Installer problems References: Message-ID: <34c5e5ce.0308271102.46312bad@posting.google.com> Timothy Martens wrote in message news:... > When I run the Python-2.3.exe on my WIN2K box and go through the initial > dialogues, the installer frezes at 1% when it's "Copying File > C:\Python23\UNWISE.exe" > > Any ideas ANYONE? > > tim. just another sysadmin/techie/proggie : i got the same prob on 2 different hardwares, only the Software is nearly identic. I'd turned off almost all software-components like vir-scan and firewall. After all i guess it won't help to change anything in the hardware, because a file-mon like sysinterals one will show you, what's on with it: FileNotFound / DirectoryNotFound. The Setup got stuc in the depth of your SystemDir. As far as i can see (and think, of course), the problem's reason must be nearby .net. So, as Christopher has written, it really may be the best solution to reinstall Windows. Or you compile it :? syl, querdenker From borcis at users.ch Fri Aug 22 15:10:15 2003 From: borcis at users.ch (Borcis) Date: Fri, 22 Aug 2003 21:10:15 +0200 Subject: What's better about Ruby than Python? References: <3F41505F.69D18CC8@alcyone.com> <66d7kvonvb2n0nqbqahhd5roak7ur81sob@4ax.com> <3f43ef5d_4@127.0.0.1> <3F440A35.9030602@nyc.rr.com> <4o_0b.1665$Ej6.1182@newsread4.news.pas.earthlink.net> <8D01b.1721$Ej6.702@newsread4.news.pas.earthlink.net> <3F44ED2E.9070308@nyc.rr.com> <0V61b.1900$Ej6.1012@newsread4.news.pas.earthlink.net> <3F4504D7.20008@nyc.rr.com> Message-ID: <3F466A97.9090509@users.ch> Andrew Dalke wrote: > > Quantum mechanics is simple. It's just H | psi> = E | psi> > > What's H mean? And psi? And bra-ket notation? > > The reason my original forays into Lisp around 1990 failed was > because the documentation I had for learning it didn't talk about > anything I found interesting, like doing file I/O and graphics. It > went on-and-on about data structures and manipulating them. > > My later attempts were by trying to customize my Emacs LISP > setup, and getting various errors because I didn't know the > quoting rules well enough. The only thing I ever did in (X)emacs was a nicely working code animator for MOO procedures, actually it was a client-server thing, there was a reversible code decorator, and the decoration led the code upon execution by the MOO to surround each one of its steps by a handshake with the XEmacs client, that the latter converted to an animating transformation of the source code text before the user's eyes and control. I was left with the impression that Xemacs (and its lisp) were dependable. > > Since then it's been limited to incidental learning, like seeing examples > and trying to figure them out. Eg, consider Gabriel's "Worse is > Better" essay. The section "Good Lisp Programming is Hard" > http://www.ai.mit.edu/docs/articles/good-news/subsubsection3.2.2.4.html > gives this example > > (defun make-matrix (n m) > (let ((matrix ())) > (dotimes (i n matrix) > (push (make-list m) matrix)))) > > (defun add-matrix (m1 m2) > (let ((l1 (length m1)) > (l2 (length m2))) > (let ((matrix (make-matrix l1 l2))) > (dotimes (i l1 matrix) > (dotimes (j l2) > (setf (nth i (nth j matrix)) > (+ (nth i (nth j m1)) > (nth i (nth j m2))))))))) > > and says the above is both "absolutely beautiful, but it adds > matrices slowly. Therefore it is excellent prototype code and > lousy production code." The pythonist can only wonder, before such code, whether the transform consisting in replacing all parentheses with zeroes (eg null strings) is reversible; and how it could be doctored to be reversible, if it isn't. On a sideline, shouldn't the "absolute beauty" of the code mean that a good enough compiler should *understand* well enough its intent to substitute more appropriate code ? Of course, we would supply the compiler simultaneously with the complete layer of methods. The next step would be to integrate our intelligent compiler in the IDE, so that the student having typed the above would be proposed coherent completion upon typing " (defun substract-matrix ..." or " (defun multiply-matrix ..." :) Cheers B From adalke at mindspring.com Wed Aug 27 13:33:28 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Wed, 27 Aug 2003 17:33:28 GMT Subject: Celebrity advice (was: Advice to a Junior in High School?) References: <3F4CD2A2.DE7D05D2@engcorp.com> Message-ID: Peter Hansen > Were there "100s of millions of murders" in the 20th century, assuming > commonplace definitions of "murder" (killing humans), "million" > (10 to the 6th power), and "20th century" (period beginning roughly > January 1, 1900 and ending on or one year before December 31, 2000)? > > That's a lot of people getting themselves killed, whatever the cause... I think Terry means deaths related to war, genocide, and various internal purges. Here's one source http://users.erols.com/mwhite28/atrox.htm which totals 155 million. Not all were deaths from arms. Bombs, knives, disease, famine all played a role. I read one account of the Armenian massacre which said that people were just forced over a cliff. (Though the people doing the forcing were armed.) Figure, what, 1/2 of the people died directly as a consequence of an "armed govern-man"? gives 77 million. US homicide rates are 9.2 +/- 1.0 per 100,000 claims http://www.sumeria.net/politics/homrate1.html Given a population of 4 billion (roughly, over the century) and assuming the US rate is average for the world, that's >>> 4000000000 / 100000. * 9.2 368000.0 >>> or roughly 0.5% of the deaths attributed to murders in the cause of war. Roughly in line with Terry's claims. Only we don't normally call those murder. "killing humans" because you want to do it is usually considered bad. "killing humans" because enough other people also want them dead is usually considered okay. Andrew dalke at dalkescientific.com From mpeuser at web.de Sat Aug 16 01:19:57 2003 From: mpeuser at web.de (Michael Peuser) Date: Sat, 16 Aug 2003 07:19:57 +0200 Subject: GUI builder for Python References: Message-ID: "dan" schrieb im Newsbeitrag news:fbf8d8f2.0308151938.135cf6a6 at posting.google.com... > "henry" wrote in message news:... > > Hi, > > > > Just wondering if there's a good GUI builder for Python. Something like > > Visual Tcl, where you just drag and drop objects. > > > > Not too good with creating user interfaces from code along. > > > > Thanks > > Been wondering myself. How is http://sourceforge.net/projects/wxworkshop/? > > this looks nice and it's free. Have you tried it? It is not a Python tool ;-) And there had been not much move there for more than a year... There is a well known set of GUI Builders for Pyhon around, most of them mentioned in this thread. The most important decision is what GUI-Toolkit to use. This will influence much of your *programming* tasks that follows the *layout*. Printing? HTML-Widget? Drag-and-Drop? Of course there are well known GUI-Builders like Delphi or RealBasic (on Mac) who support you seamlessly in all your tasks. But in every case you need a *thorough* understanding of how the Toolkit Works. Tk/Tcl is simple at the surface but there is a lot of rickery with event bindings, and you sometimes need TIX at well, because HList is a strong power horse... If you want to have the choice do C++ (a lott of ttools there!) or buy Delphi (some tthousend bucks butt Object Pascal is a nice language as well ;-)) There is no silver bullet at the Python market at the moment... Kindly Michal P From adalke at mindspring.com Fri Aug 1 17:35:41 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Fri, 1 Aug 2003 15:35:41 -0600 Subject: time, calendar, datetime, etc References: <153fa67.0307300326.45a29380@posting.google.com> <1sScnW0Sv7DzrrSiRTvUpQ@speakeasy.net> Message-ID: John Roth: > Because I need to be able to deal with BC dates, obviously. Fudging > the base date won't handle that. Ahhh, I see. I figured you just had dates in Julian, and algorithms for dealing with dates in Julian, so what you needed was the ability to deal with present dates (within a few decades at most) and not define some date in history. Just to point out though, before 2.3 you couldn't have used Python's libraries for that either, since the C epoch doesn't handle dates before 1970. Instead, you would have used mxDateTime, which does a good job at this, and still does. > > Why would supporing you be reasonable to the other 99+% of the > > users who don't care about doing astronomical measurements, nor > > even about the "was there a year 0?" debate. > > Mostly because I don't see a particular reason for the actual > decision tha was reached. To be complete, a datetime library needs to handle a *lot* of details. That makes the library hard to implement and maintain. Eg, what about the days that 'disappeared' between Julian and Gregorian, leap seconds, and other worries? Most people don't need that. For them and me, datetime is good enough. The datetime module needs a 0 point (the creation of the universe being rather long ago and the exact time not well known). Given the questions of "when is year 0?" in different calendar systems, it's easy for me to understand why Jan. 1st, 1AD is a good starting point. (Easier than Jan 1st, 1970 - I prefered the Mac's epoch of 1900.) > used. If you do any kind of historical research, you suddenly discover > that what you thought you knew about dates doesn't work in practice, > even in Western Europe. Well, I don't do historical research. I'm pretty insular that way. I know there are problems in interpreting dates - my religious training taught me that if nothing else. > This is why astronomical dating is important: > it provides a single, well understood and accepted dating system that > can be tied to the (unfortunatelly rare) comments about astronomical > phenomena, and it goes back far enough that all dates of historical > interest are positive numbers. Understood. I still maintain that a library which handles all the specialized datetime issues (historical, religious, astronomical, navigation, ...) is too complex for inclusion in Python's standard library. Specialists should use a specialist's library. What Python has is quite good enough for just about everyone's needs. Put it this way - FixedPoint still isn't part of Python's standard library even though it's very important for people dealing with money. Then again, for most people, floats (!) are good enough. > Usually, that's handled by a separate conversion from UT (Universal > Time) to ET (Ephemeris time.) And leap seconds are a modern innovation: > for accuracy there are a number of correction formulae that you apply > depending on the exact historical era in question. And it makes sense for Python's standard library to handle all that? > Funny about that: the Unix system specifications that I've seen > have always said that there may be 61 seconds in a minute. It's built > into the API. And there's where I learned it from. Doesn't mean the libraries support it. And I'm told the C spec's comment about "double leap seconds" is based on a misunderstanding and those don't actually exist. One of the reasons for Python to do it's own datetime code is because of the broken nature of many platforms native time functions. > Andrew, you've brought in an army of straw men. The **ONLY** > thing I was criticising was the decision to limit the module to dates > beginning with 1 AD. All the other things you bring up are things that > I either don't care about, or that I agree shouldn't complicate the API. Then you misunderstand my comments. You have a very specialized need to handle dates before 1AD. Others have a specialized need to handle leap seconds. Others need to deal with differences between UTC, UT1, GPS, and other time systems. Still others need to handle complicated timezones (like "double daylight savings", which I think datetime doesn't handle). Others again need better than microsecond timestamps. For all I know, some need a general relativity compensation term. To handle all of these and maintain them as the various time standards change requires effort. There aren't all that many people working on Python. They decided that most people only need what I termed 'vernacular' time in a previous post in this thread, and that time system works for 99+% of the datetime needs in the world, and that's what they implemented. And I commend the developers for defining what "good enough" means, and defering perfection to other libraries and future inclusion. Very Pythonic. Andrew dalke at dalkescientific.com From tebeka at cs.bgu.ac.il Thu Aug 28 04:30:34 2003 From: tebeka at cs.bgu.ac.il (Miki Tebeka) Date: 28 Aug 2003 01:30:34 -0700 Subject: Comments on my "Python Introduction" slides References: <33803989.0308240000.35b9bf1f@posting.google.com> <3f4b2599@news.comindico.com.au> Message-ID: <33803989.0308280030.652db780@posting.google.com> Hello Eddie, > Comments from an old programmer (but an absolute beginnner in Python) So old dogs CAN learn new tricks ;-) > Re: slide 6 on data types - it implies integer only for numeric types - I'd > suggest mentioning floating point, arbitrary length numbers (this is implied > in slide 5 on Fibonacci) and, of course, complex numbers are very important > for some uses. I've added them. 10x. Miki From sjmachin at lexicon.net Sat Aug 2 03:08:20 2003 From: sjmachin at lexicon.net (John Machin) Date: Sat, 02 Aug 2003 07:08:20 GMT Subject: bug in file.write() ? References: <13a4e2e3.0307311443.299bd59d@posting.google.com> Message-ID: <3f2b5e60.36345431@news.lexicon.net> On 31 Jul 2003 15:43:34 -0700, pu at vo.lu (Patrick Useldinger) wrote: >Hi, > >I think I found a bug in the write method of file objects. It seems as >if before writing each block, a check was done in order to verifiy >that there is enough space left for the *whole* file, not for the >*remaining* data to be written. This is very unlikely --- it is difficult to determine reliably the available space on a disk or tape volume; if one were really interested, one would do it once before trying to write the file, not before writing each block. No, the expected implementation, which you can check against reality by inspecting the source (fileobject.c), is just to attempt to write, and throw an informative-as-possible exception if the write fails. Despite the appearance that you have about 6KB margin of safety, you will probably find that you don't have any --- the quoted size of the source file doesn't include the unused space in the last cluster or block or whatever. It's a while since I've had to concern myself with this sort of detail, but it's a good bet that the "chunk" size on your disk is 8Kb or more and you're out of luck. > >It happens both under 2.3 and 2.2.3. >Any ideas? [snip] > File "C:\Python23\lib\shutil.py", line 39, in copyfile > copyfileobj(fsrc, fdst) > File "C:\Python23\lib\shutil.py", line 24, in copyfileobj > fdst.write(buf) >IOError: [Errno 28] No space left on device > >I:\My Programs\dfc>dir f: > Volume in drive F is Backup 01 > Volume Serial Number is E2CB-1650 > > Directory of F:\ > >18/05/2002 15:39 . >18/05/2002 15:39 .. >01/08/2003 00:25 299.630.592 dfcArchive cheetah >20030731-234648 F.zip > 1 File(s) 299.630.592 bytes > 2 Dir(s) 299.636.736 bytes free > [snip] From adalke at mindspring.com Tue Aug 26 20:55:52 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Wed, 27 Aug 2003 00:55:52 GMT Subject: My own 12 points list References: Message-ID: A. Lloyd Flanagan: > open() is deprecated [in favor of 'file'], I don't know about plans > to eliminate it. I think formally speaking it isn't deprecated. The docs say open is "An alias for the file() function" http://www.python.org/doc/2.3/lib/built-in-funcs.html Andrew dalke at dalkescientific.com From alexander at deGreiff.com Fri Aug 29 08:01:36 2003 From: alexander at deGreiff.com (adegreiff) Date: 29 Aug 2003 05:01:36 -0700 Subject: howto format currency string? Message-ID: hi, using zope/pythons/page templates i need to format a float number to a string like 10,250.10 (note the thousand separator and the trailing zero in the decimal) i was able to use %0.2f bit that returned no thousand separator. i was able to use thousands_commas function but that returned "10,250.1" which is wrong. any ideas? thanks alexander From ramiak2000 at yahoo.com Sat Aug 16 03:48:46 2003 From: ramiak2000 at yahoo.com (Rami A. Kishek) Date: Sat, 16 Aug 2003 03:48:46 -0400 Subject: One more PythonWin issue Message-ID: <3F3DE1DE.79D51470@yahoo.com> Can any Pythonwin guru help me here? I had this problem with Python 1.5.2 and thought upgrading to 2.2.3 would help, but it didn't. Note I get this error on a win ME machine. Prior to that, I ran Pythonwin on a Win 98 and never got this problem. Very frequently, when I try to open Pythonwin it refuses to open and nothing happens, until I try to open another copy, then use the Windows task Monitor to kill the first one, in which case I get a warning about an error in the DDE conversion, after which Python win starts up. This happens more frequently after I have been using the computer for a while (so probably memory not so clean). In other words, rebooting helps. From redrumjack at hotmail.com Thu Aug 28 10:53:01 2003 From: redrumjack at hotmail.com (Jesse) Date: Thu, 28 Aug 2003 14:53:01 GMT Subject: Windows Remote Log in In-Reply-To: References: Message-ID: Thanks I'll check this out and also try to further clarify myself. This is a mixture of NT 4 and Win2K Servers. WMI may not be installed on all the remote systems. We have quite a few NT domains that our servers are spread out over and sometimes the machine I would execute the script from would not be in the same Domain and need different Logon Credentials to access the remote machine. We don't have control over this our primary responsibility is for the applications that reside on these servers. We have Administrator Access to the servers but not complete control on how they are setup. Ahhh the wonderful Politics of Big Business. Often certian services for the applications we maintain will need to be restarted on these remote machines. I've found a way to this this with a Python Module called WService. In the App I'm making that will reside on the clients machine they will enter a server name or ip address and click a button that will restart the req'd service. As long as we are in the same NT Domain no big deal, but not all servers are in the same domain and we use different accounts to access them. What I need is some way for user to enter the proper credentials so Python could restart the service on the remote machine. If this isn't making sense please disregard and I'll move on to something a bit easier. Tim Golden wrote: > From: Jesse [mailto:redrumjack at hotmail.com] > > >>I guess it is how can I have a user enter their NT Domain Authentication >>and the script use it to log into NT Domains the computer it is running >>on it not a member of. > > > I have the impression that you're not 100% clear on how you might be > doing these remote operations. Do you envisage remotely "typing in" > usernames and passwords, and then remotely "opening up dialogs and > pressing buttons"? If so, you're a bit off beam (and a not atypical > NT Administrator). If not, then I apologise. (Actually, I apologise > anyway; it was a bit rude). > > I suggest you have a look at WMI. > > Pick up the module from: > > http://tgolden.sc.sabren.com/python/wmi.html > > and have a look at some of the examples in: > > http://tgolden.sc.sabren.com/python/wmi_cookbook.html > > Try using it without any particular security qualifiers > first; if you really need an explicit log on (you probably > won't if you're a Domain Admin and using your own or a > trusted domain) then you can specify an explicit wmi > moniker in the constructor. > > TJG > > ________________________________________________________________________ > This e-mail has been scanned for all viruses by Star Internet. The > service is powered by MessageLabs. For more information on a proactive > anti-virus service working around the clock, around the globe, visit: > http://www.star.net.uk > ________________________________________________________________________ > From eppstein at ics.uci.edu Tue Aug 19 02:50:43 2003 From: eppstein at ics.uci.edu (David Eppstein) Date: Mon, 18 Aug 2003 23:50:43 -0700 Subject: What's TOTALLY COMPELLING about good newsreaders? References: <3F41A877.995F9C35@alcyone.com> Message-ID: In article , aahz at pythoncraft.com (Aahz) wrote: > In article , > Ben Finney wrote: > > > >Brandon accesses comp.lang.python via Usenet, not email. His > >X-Newsreader header shows he is using Outlook Express. I don't know of > >any newsreaders that can allow you to filter on the person(s) to whom > >the current post is responding -- nor any email clients with the > >facility, for that matter. > > > >The "References" header could theoretically allow you get that > >information, but it would be expensive to do so for every message, > >especially in long-running threads. > > Supposedly gnus and slrn do that, though. MT-Newswatcher has no problem with filtering on References: I use it to make sure I see replies to my own messages, but I have a distinctive string on the user side of my message-ID's. Brandon doesn't seem to, but does seem to use a distinctive host: ID-203719.news.uni-berlin.de. Googling for that, it seems that the only other stuff you would lose by killfiling references containing that hostname would be his six-way crossposts to alt.atheism, alt.politics.bush, alt.fan.noam-chomsky, soc.culture.iraq, soc.culture.jewish, soc.culture.russian, and soc.history.war.misc... Some people are still saying he isn't a troll? -- David Eppstein http://www.ics.uci.edu/~eppstein/ Univ. of California, Irvine, School of Information & Computer Science From =?iso-8859-1?b?IkrpcvRtZQ==?= Fri Aug 22 17:05:46 2003 From: =?iso-8859-1?b?IkrpcvRtZQ==?= (=?iso-8859-1?b?IkrpcvRtZQ==?=) Date: Fri, 22 Aug 2003 23:05:46 +0200 Subject: Python/C API - PyArg_ParseTuple problem ? References: <7h3fzjt1rlh.fsf@pc150.maths.bris.ac.uk> Message-ID: On Fri, 22 Aug 2003 18:23:28 +0000, Michael Hudson wrote: >> If I do this: >> >> >> s = 'hi' >> >> t = NewType(0, 42, s) >> >> everything is well... > > Even after a 'del s'? Just tried it, even after a 'del s' everything's right. >> Precisions: I'm running Python 2.2.3 on Linux, and I don't free() the >> buffer retrieved via PyArg_ParseTuple or PyString_AsString :) > > No, but I bet you're stuffing it into your data structure somewhere > along the line. I think you need to copy the string data. That's the whole point, I took a great care to copy it, and never keep a reference to the original buffer. As a precision, the binding is for fltk2 (http://www.fltk.org/). I still haven't been able to reproduce it with a minimal source code, but if you want to try it the source should be available at http://fraca7.homeunix.net/pyfltk2-0.0.0.tar.gz at least if I didn't screw up with the whole NAT thingies. As you can see, the string buffer is passed to WidgetWrapper::WidgetWrapper, which copies it by using fltk::Widget::copy_label. I've checked the fltk code to ensure the buffer was copied via strdup(). What really puzzles me is that difference between the "ii|s" and "ii|O"/PyString_AsString stuff. Wouldn't one expect to have the same result, right or wrong, from both techniques ? -- J?r?me Laheurte The human mind treats a new idea the way the body treats a strange protein -- it rejects it. -- P. Medawar From jjl at pobox.com Tue Aug 26 08:08:38 2003 From: jjl at pobox.com (John J. Lee) Date: 26 Aug 2003 13:08:38 +0100 Subject: ClientCookie bug (followup) References: <87fzk4sav2.fsf@pobox.com> <87znibzrnx.fsf@pobox.com> <87oeypdh92.fsf@pobox.com> <87k79a25pi.fsf@pobox.com> <87isos0zng.fsf@pobox.com> Message-ID: <87ptis39kp.fsf@pobox.com> cartermark46 at ukmail.com (Mark Carter) writes: > jjl at pobox.com (John J. Lee) wrote in message news:<87isos0zng.fsf at pobox.com>... > > cartermark46 at ukmail.com (Mark Carter) writes: [...] > I've looked again, and add_cookie_header() definitely(!) is required > for the following code to work: Oh, sorry, I missed something: you're using urllib.urlopen. You need to call ClientCookie.urlopen instead (this is still using urllib2 -- ClientCookie uses urllib2 to do most of the work). You seem to be opening the same URL twice for no obvious reason, so I removed that below: def go10(): #works with win xp import ClientCookie c = ClientCookie.MSIECookieJar(delayload=1) c.load_from_registry(username='mcarter') #only need username for win9x url = 'http://businessplus.hemscott.net/corp/crp03733.htm' response = ClientCookie.urlopen(url) print response.info() # headers print response.read() # body John From bokr at oz.net Sun Aug 10 01:03:07 2003 From: bokr at oz.net (Bengt Richter) Date: 10 Aug 2003 05:03:07 GMT Subject: crossplatform py2exe - would it be useful? References: <2UyYa.50516$cl3.1586459@news2.tin.it> Message-ID: On Sat, 09 Aug 2003 19:59:42 +0100, Marc Wilson wrote: >In comp.lang.python, Alex Martelli (Alex Martelli) wrote >in :: > >|That's two strikes against the ".uff" approach and in favour of the >|'.exe' one. I can see potential advantages for the '.uff', too, in >|widely different scenarios; but these issues indicate to me that it >|just can't replace the '.exe'. Therefore, I would suggest you pursue >|the .uff as a third-party alternative -- while, on the other hand, >|"makers of .exe's" have long been available as third-party alternatives, >|and the thrilling aspect of this latest round of ideas is that we seem >|to be very close to being able to integrate them in the Python standard >|distribution, with a resulting potential for an interesting boost to >|Python's popularity. It makes a psychological difference, quite a big >|one, whether some functionality is integrated in a standard distribution >|or has to be separately downloaded and installed as a third-party add-on. >| >|"Ability to build directly executable files" would make a big 'selling' >|point if it were in Python's standard distribution, while "ability to >|wrap files into an archive which still needs a separate utility to >|unwrap and run", useful as it may be, just doesn't have the same level >|of raw appeal to typical punters currently wondering about Python. > >For instance, I have written a couple of little progs in Python to solve >problems for a client. I need to make them into executables, because, while >he's willing to install an .exe I've written, he's less sure about one >written by someone who has no contract with him, and no comeback if it goes >taters. You make the contract. If you use open source, he'll come back to you, and you'll be able to fix it, or find someone here who can. Python itself is written "by someone who has no contract with him" (presumably). How do you square that? How does he feel about installing via something you've made with Installshield (commercial installer .exe packager)? He will certainly have no easy way to deal with any problem with that other than call you, and you will have no easy way to check on what happened, because you can't just look at the code, or ask someone here who knows about the code, because it isn't openly available (AFAIK; for a price most commercial things are possible). uff.exe is (well, might be if I don't use up my time budget here ;-) just a tool either just to install or to install and automatically execute something in a way you decided, and having the possibility that automatically executing means getting some files in place and maybe doing some preliminary things you don't really want embedded in your app just because you have a "single-exe" requirement. If it's open source and all available through python.org, where's the problem with that? ISTM, he's better protected, and has all kinds of options. Regards, Bengt Richter From skip at pobox.com Wed Aug 6 19:49:12 2003 From: skip at pobox.com (Skip Montanaro) Date: Wed, 6 Aug 2003 18:49:12 -0500 Subject: dl + getenv (without arguments) = segfault (python2.p2, python2.3) In-Reply-To: <39281.24.199.120.198.1060208803.squirrel@mail.darkscape.net> References: <39281.24.199.120.198.1060208803.squirrel@mail.darkscape.net> Message-ID: <16177.37880.460543.46380@montanaro.dyndns.org> import dl a=dl.open("libc.so.6") print a.call("getenv") sabu> Now, my problem is not with the obvious.. but with the fact that sabu> Python segfaulted instead of raising an exception or returning 0 Just because a.call() can call getenv() indirectly doesn't absolve you of the responsibility of calling it with the right arguments. Python has no way of knowing the prototype of getenv(). The dl module is one of those "dangerous" modules. It gives you the ability to make essentially unchecked calls directly to C code. Skip From cbarber at curl.com Wed Aug 13 18:40:12 2003 From: cbarber at curl.com (Christopher Barber) Date: 13 Aug 2003 18:40:12 -0400 Subject: Python vs. C# References: Message-ID: Andrew Bennetts writes: > On Tue, Aug 12, 2003 at 02:03:58AM -0700, Brandon J. Van Every wrote: > > Joe Cheng wrote: > > And how, in a large scale industrial systems context, are you supposed to > > ensure that Joe Programmer doesn't in fact screw it up? > > By writing tests. > > Just because C++, C# or Java code compiles cleanly doesn't mean it's > correct. > Just because Python code parses correctly and gives clean PyChecker output > doesn't mean it's correct, either. > > In both cases, you need tests, preferably comprehensive, automated tests, to > verify that your code actually works correctly. I like the sentiment, but in practice there is no such thing as comprehensive tests. From patrick at novaroot.com Sun Aug 24 20:41:35 2003 From: patrick at novaroot.com (Patrick Lioi) Date: 24 Aug 2003 17:41:35 -0700 Subject: python gripes survey References: Message-ID: <2a82921f.0308241641.5bf82d6d@posting.google.com> I would like to see a shorthand for list.append(), borrowed from PHP: foo = [1, 2, 3] foo[] = 4 # foo now equals [1, 2, 3, 4] I would also like to see what would probably end up being called "generator comprehensions". That is definitely not my own idea, but for the life of me I can't remember where I first heard about it. Imagine being able to throw the yield keyword into a list comprehension syntax in order to take advantage of list comprehension's in a memory-efficient way, something kinda like this: foo = [yield i*i for i in xrange(100)] From aahz at pythoncraft.com Mon Aug 18 18:16:39 2003 From: aahz at pythoncraft.com (Aahz) Date: 18 Aug 2003 18:16:39 -0400 Subject: overriding a tuple's __init__ References: Message-ID: In article , Bengt Richter wrote: > >so far, just > > class pair(tuple): pass > >should do it, no? Unless you want to take the name as suggesting that >length 2 should be enforced. Don't know what other methods are planned, >but ISTM you get the vanilla __new__ for free. Or am I missing something? Certainly; I'm just illustrating the principle if you wanted to do something useful. ;-) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From sdhyok at yahoo.com Sun Aug 10 15:27:09 2003 From: sdhyok at yahoo.com (sdhyok) Date: 10 Aug 2003 12:27:09 -0700 Subject: How to print floating point in scientific format? References: <420ced91.0308081115.7060e551@posting.google.com> Message-ID: <420ced91.0308101127.644f9813@posting.google.com> As you recommend, I won't modify the default behavior of python. But, still I need a better treatment of python on arrays. Daehyok Shin Alex Martelli wrote in message news:... > sdhyok wrote: > > > I want to change the DEFAULT behavior of python > > to print out all floating points in scientific format? > > For instance, > > > >>x=0.01 > >>print x > > 1.000000E-2 #Like print "%E"%x > > > > How can I do it? > > You need to download Python's sources, modify them, and build a modified > Python interpreter and libraries that impose the behavior you want rather > than what the normal Python interpreter and libraries do. > > Specifically, look at function format_float, line 233 of file > Objects/floatobject.c in the current 2.3 maintenance branch for example. > Currently it formats the float with "%.*g" [variable precision passed > in as an argument to format_float]; if you want to use a different C level > format string, that string is the one you need to change. > > Of course, that's likely to break some of the tests in Python's unit-tests > suite, so you'll probably want to modify those, too. And then, you get to > maintain your "slightly divergent" Python yourself forevermore. I do not > think there is much likelihood that a patch in this regard would be > accepted in the Python core, even if you made it flexible enough to keep > the current behavior by default and change it only upon specific request > (e.g., use a variable string for the format, and let the Python coder > modify the letter in it, only, keeping "%.*g" as the default but letting > the 'g' be changed) -- such "big global" settings, which would let one > idiosyncratic library module modify Python behavior enough to break other > innocent modules, are looked at with disfavour, for reasons that should > be obvious (each and every such 'big global' _damages_ Python's suitability > for writing very large, multi-authors applications -- that suitability is > currently very high, and _extremely_ convincing arguments would need to > be brought to bear in order to convince Guido to deliberately lower it). > > > Alex From jdhunter at ace.bsd.uchicago.edu Mon Aug 4 10:42:20 2003 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Mon, 04 Aug 2003 09:42:20 -0500 Subject: better way to do this in Numeric Message-ID: I have a list of indices and want to assign the number of times an index shows up in the list to an array with the count specified at the index; ie, from Numeric import * a = zeros((10,), Int) ind = [1,1,4,4,4,4,7,7,9,9,9,9,9] for i in ind: a[i] += 1 I'm wondering if there is a way to use some combination of Numeric array functions to make this speedy. Thanks, John Hunter From gcash at luncheonmeat.cfl.rr.com Sat Aug 2 01:47:55 2003 From: gcash at luncheonmeat.cfl.rr.com (gcash) Date: Sat, 02 Aug 2003 05:47:55 GMT Subject: FOUND! how to attach to running instances of Internet Explorer Message-ID: Most folks know you can start up an instance of Internet Explorer by saying "x=win32com.client.Dispatch('InternetExplorer.Application.1')" and you get a WIN32 object with a "Document" object that has arrays of "Link"/"Form"/"Frame" subobjects, and methods like "Navigate" where you can force the IE instance to browse to a new URL. What folks would like to do is to connect to an already running version of explorer, and this isn't so obvious. The MS KB article you usually find is 176792 which mentions using SHDocVw.ShellWindows to iterate through the instances. However Mark Hammond sayes this is a "vtable interface" (whatever that is) and "not supported by python" in http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&newwindow=1&safe=off&selm=3D106564.4040602%40pretection.com HA! well, I happened to discover you can do: import win32com.client # look in the makepy output for IE for the "CLSIDToClassMap" # dictionary, and find the entry for "ShellWindows" clsid='{9BA05972-F6A8-11CF-A442-00A0C90A8F39}' ShellWindows=win32com.client.Dispatch(clsid) for i in range(ShellWindows.Count): print i # this is the titlebar value print ShellWindows[i].LocationName # this is the current URL print ShellWindows[i].LocationURL print and the object returned by ShellWindows[n] is the exact same as the one returned by Dispatch('InternetExplorer.Application.1') I'm posting this here for future generations of Googlers. So I'm running Win2K Pro... and I'm curious about what versions this works under. I'm pretty sure you have to have IE 5.0 or newer, but could folks try this code on 95/98 and tell me (gcash-at-cfl.rr.com) if it works?? Also, I haven't been able to determine if there's a better name of the form 'InternetExplorer.Application.1' instead of using the horrid class-id. How do you do that? The makepy output for explorer doesn't list one. Thanks to Mark Hammond for win32all, it is a true work of art, and is teaching an old UNIX hack lots of Windows stuff. -gc -- I've never tried emacs because I already _have_ an OS on this peecee. -- mikea at mikea.ath.cx (Mike Andrews) From tom_chansky at rocketmail.com Thu Aug 7 09:03:00 2003 From: tom_chansky at rocketmail.com (chansky) Date: 7 Aug 2003 06:03:00 -0700 Subject: generator function Message-ID: <215fa0fc.0308070503.2344dd66@posting.google.com> I read the following link about generator: http://www.python.org/peps/pep-0255.html but I am still not so clear on the use/purpose of a generator function other than the fact that a generator can retain the state of the local variables within the fuction body. Can someone out there shed some lights on this topic or share about how/when you would ever use a generator function. From ialbert at mailblocks.com Sun Aug 10 23:01:22 2003 From: ialbert at mailblocks.com (Istvan Albert) Date: Sun, 10 Aug 2003 23:01:22 -0400 Subject: ANNOUNCE: Rekall V2.0.2 In-Reply-To: References: <5.2.1.1.0.20030810065523.02c3ed10@66.28.54.253> Message-ID: john at rygannon.com wrote: > I have made a lot of changes many of them as a direct result to everybodies > suggests. I hope that I have got it right this time > BTW I have add a lot of screen shots to the Contents->About Rekall->Screen > Shots page This is still so silly. On your page instead of directly linking to the screenshots you are (just as abouve) listing the steps one needs to take to get there. The whole site makes no sense. If you have a product to sell you must allow people to understand everything right away. I would get rid of this whole you must register first nonsense. cheers, Istvan. From pu at nodomain.lu Mon Aug 18 15:10:18 2003 From: pu at nodomain.lu (Patrick Useldinger) Date: Mon, 18 Aug 2003 21:10:18 +0200 Subject: What's TOTALLY COMPELLING about Ruby over Python? In-Reply-To: References: Message-ID: <3f412432$1_1@news.vo.lu> Brandon J. Van Every wrote: > What's ***TOTALLY COMPELLING*** about Ruby over Python? What makes you jump > up in your chair and scream "Wow! Ruby has *that*? That is SO FRICKIN' > COOL!!! ***MAN*** that would save me a buttload of work and make my life > sooooo much easier!" The simple fact that *you* are not active on c.l.ruby? A time-saver, certainly ;-) -- Real e-mail address is 'cHVAdm8ubHU=\n'.decode('base64') Visit my Homepage at http://www.homepages.lu/pu/ From ktilton at nyc.rr.com Mon Aug 25 19:32:46 2003 From: ktilton at nyc.rr.com (Kenny Tilton) Date: Mon, 25 Aug 2003 23:32:46 GMT Subject: Advice to a Junior in High School? References: Message-ID: <3F4A9D78.9040306@nyc.rr.com> Howard Nease wrote: > Hello, everyone. I would appreciate any advice that someone could give me on > my future career path. Here is my situation: > > I am a bright Junior in a very well-respected private high school, taking > almost all AP and accelerated classes. I am HIGHLY interested in technology, > more specifically the field of Computer Science and software engineering. I > have heard a whole lot about the fact that the market for software engineers > nowadays is *HORRIBLE*, and that I should double major or perhaps go into a > field of study in which I'm not very interested. By the time you graduate it will be a different world. There will be a shortage because everyone is being told the same thing you are. A glut arose because folks were being told the opposite. These same folks give up looking for a job in compsci after a month, you'll get a job as a waiter and look for a year. and you can settle for less because you love the work. the latter will also make you better at it than money chasers, and will help you interview better. btw, i would say this even if you were from a highly-disrespected inner city public school. :) -- kenny tilton clinisys, inc http://www.tilton-technology.com/ --------------------------------------------------------------- "Career highlights? I had two. I got an intentional walk from Sandy Koufax and I got out of a rundown against the Mets." -- Bob Uecker From mark at diversiform.com Tue Aug 5 13:42:40 2003 From: mark at diversiform.com (Mark Daley) Date: Tue, 5 Aug 2003 10:42:40 -0700 Subject: Question about import In-Reply-To: <18fe8c2.0308050828.771de40d@posting.google.com> Message-ID: The difference is how you access the methods in the module. If you use: import Module you will only be able to use the Module.Method usage. If you use: from Module import * you can access the Methods directly. The drawback to using from Module import * comes from conflicts if you import multiple Modules, which may have identically named Methods, where you will only be able to get the Method from the most recently imported Module. Better to import the Module, IMO. Any thoughts, all? - Mark -----Original Message----- From: python-list-admin at python.org [mailto:python-list-admin at python.org]On Behalf Of Kevin MacKenzie Sent: Tuesday, August 05, 2003 9:29 AM To: python-list at python.org Subject: Question about import I'm a complete newbie to using Python. I have a small question about importing modules. Is there any difference between the two following statements, and what (if any) are they? >>> from Module import * and >>> import Module Thanks. kjm -- http://mail.python.org/mailman/listinfo/python-list From adalke at mindspring.com Wed Aug 20 18:00:19 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Wed, 20 Aug 2003 22:00:19 GMT Subject: how fast is Python? References: Message-ID: dan: > However, there are definitely cases where a lot of code would need to > be optimized, and so I ask the question: How fast is Python, compared > to say a typical optimizing C/C++ compiler? Highly dependent on context. I use factor of 10-20 as a ballpark, with factor of 100 for some things like low-level string processing. Eg, I've got a pure Python regexp engine which clocks at about x80 slower than sre. > what could be done to optimize the interpreter? Are any parts written > in assembly? Could things like hash tables be optimized with parallel > units such as MMX? Etc. Spend a few tens of millions on developing just-in-time compilers and program analysis. That worked for Java. Nothing is written in assembly, except that C can be considered a portable assembly language. Otherwise ports to different platforms would be a lot more difficult. I would hope that the C compiler could optimize the C code sufficiently well for the hardware, rather than tweaking the code by hand. (Though I know of at least one person who sent in a patch to gcc to optimize poorly written in-house code. Rather circuitous way to fix things, but it worked.) Andrew dalke at dalkescientific.com From Juha.Autero at iki.fi Tue Aug 12 16:53:30 2003 From: Juha.Autero at iki.fi (Juha Autero) Date: Tue, 12 Aug 2003 23:53:30 +0300 Subject: TarFile using binary strings References: <3F38CB87.5831C2EE@dlr.de> Message-ID: <87lltyha2d.fsf@jautero.no-ip.org> "Marc Poinot (Onera)" writes: > Is it possible to avoid the temporary files, and read the stream > from the binary string coming from DBMS ? The TarInfo object uses a > fileobj Python type, is there any trick (or module) to make TarInfo > happy with a 'possible' fileobj-like on a memory zone ? Well, StringIO provides file-like interface to strings you should be able to use. Just create TarInfo object, fill up the fields (especially the size) and then pass it and StringIO object to TarFile.addfile. -- Juha Autero http://www.iki.fi/jautero/ Eschew obscurity! From dave at nullcube.com Tue Aug 5 21:01:04 2003 From: dave at nullcube.com (Dave Harrison) Date: Wed, 6 Aug 2003 11:01:04 +1000 Subject: CGI Webcounter not quite working...help, please In-Reply-To: References: Message-ID: <20030806010104.GA1013@dave@alana.ucc.usyd.edu.au> > I got this webcounter to be called directly (I still can't get it to be > called from an HTML file with #exec or #include or anything). you might want to try embedding the page itself in the code (ugly, but if you're just starting out with python maybe the way to go). > #!/usr/pkg/bin/python > > print "Content-Type: text/html\n\n" > print "\n\n" this part is unnecessary, you already have the two \n's from the statement above it. > import os > import string > > print "" > print "" > filenames = os.listdir(os.curdir) > > if "count.txt" in filenames: > input = open('count.txt', 'r') > i = string.atoi(input.read(1)) > else: > i = 0 > print "File doesnt exist
" > > i = i + 1 > print "This page has been accessed " + `i` + " times.
" > print "" > print "" > > #it doesn't seem to execute this at all > output = open('count.txt', 'w') > output.write(`i`) > output.close() > > Do you see any obvious problems with this? It works fine when I call it > from the command line. hmmm ... ok well here's how I would do something similar, we dont want to just guess if a file is there, we want it to be there and error else (or so I think, it is a counting script, and a couting script without a file cant really work ;-) Now while Im sure this isnt the best way to do it (tho I dont think its all that bad either ;-) .... #!/usr/bin/env python import string print 'Content-Type: text/html\n\n' print '' count = '0' try: count = open('count.txt').read() count = string.strip(count) num = string.atoi(count) print "You are the "+str(num+1)+"th visitor to this page" except IOError: print "No valid file" except ValueError: print "No valid count value" print '' From tim at remove_if_not_spam.digitig.co.uk Tue Aug 19 18:35:43 2003 From: tim at remove_if_not_spam.digitig.co.uk (Tim Rowe) Date: Tue, 19 Aug 2003 23:35:43 +0100 Subject: Brandon's abrasive style (was Re: What's better about Ruby than Python?) References: <38ec68a6.0308172319.431a4fde@posting.google.com> Message-ID: On Mon, 18 Aug 2003 21:43:12 -0700, "Brandon J. Van Every" wrote: >- Python is not a good language for low-level 3D graphics problems. C++ is >better. Agreed. And there are probably special purpose low-level 3D graphics languages that would beat the pants off C++, which I would look for if I had to do low-level 3D graphics. And then see if they could be integrated with Python, because few problems are /just/ low-level 3D graphics. >- Python isn't a rapid prototyping godsend for every problem out there. Agreed in theory, though I've yet to find a problem for which it isn't. That said, for designing GUIs I prefer Delphi or VB -- but if I'd spent the same money on Python tools as I did on Delphi and VB I expect I could have a nice GUI designer for Python too (could I?) >- GUI and tools support can end up being more important than language >niceties. Agreed. Lucky Python is so good there, isn't it? :-) >- Microsoft C# and .NET are strategic threats to Python's prosperity and >vitality, if not survival. In the case of C# I think the effect is marginal. There are /some/ Python applications for which C# would be a contender, and may be good enough for Microsoft's marketing to overcome Python's natural superiority (tongue only /partly/ in cheek). But for most applications I can't imagine C# even approaching Python's productivity, and I have enough confidence in human nature to believe that there will always be those who value that productivity more than they value the words of the marketeers. And that's before we even start on platform issues and whether Microsoft will keep moving goalposts to keep mono incompatible -- or whether developers will trust them not to, even if they don't. .NET is orthogonal to language choice. Clearly Python has to coexist with it, but I don't see how it's a threat. >- Pythonistas should consider trying to eat Java's lunch, because they >aren't going to eat Microsoft's lunch. This Pythonista isn't interested in eating anybody else's lunch. I'm getting on with the job, and have found a very nice tool for it, thanks. >- Ruby has some mindshare among people with knowledge of Python. Agreed, because AFAICS they both arose from the same need: to make scripting languages more scaleable. They have both grown far beyond what that origin would indicate. Similarly, Pascal has some mindshare among people with knowledge of C. So? >- Yet unnamed languages are capable of taking Python's place on the food >chain. Agreed. Python will eventually decline and be replaced by something newer and better. It may be Python++ (sorry, Python += 1) or it may be some completely different language and programming paradigm. I look forward to it. I love Python, but I am fickle. If a language comes along that makes my life easier or more fun, I'll go with the fun and the easy life, thank you. I don't see it happening RSN, though. >- You have to promote your language, grow its market share, to prevent that >from happening. Why prevent it from happening? It's life, it's evolution, it will happen whatever we do. If something better /does/ come along, why should we try to stop people using it? Why should we not use it ourselves? My first programming language was Focal, but when I saw Fortran I lost any interest I had in fighting for Focal's market share. >These analyses are called "sanity" in the Windows world. It's Reality On >The Ground. It's really odd to come to a developer community where people >are insular and freak out about these kinds of pronouncements. It makes >Windows people wonder if Python people are capable of industrial relevancy. Industrial relevancy [sic] in which sense? Making Python tools or making products /using/ Python? Your comments only seem relevant to the former, which is a minority interest when so much good stuff is free. >The rest of you: wake up! Smell the Windows! Agreed. Some versions of Windows do stink a bit, don't they? From mhammond at skippinet.com.au Tue Aug 12 04:27:29 2003 From: mhammond at skippinet.com.au (Mark Hammond) Date: Tue, 12 Aug 2003 18:27:29 +1000 Subject: COM :: VARIANT -eek In-Reply-To: <5f5c82ec.0308110207.1d42251@posting.google.com> References: <5f5c82ec.0308110207.1d42251@posting.google.com> Message-ID: Matt Smith wrote: > Hi, all. > > Just a quick question, when setting a COM process to read a value from > a pre-defined register index, I think, I have to change the variable > that the value will be returned to (as I have to do for the same > function in perl), into a VARIANT, However when i run the variant > code.... > > 'serialIndex = win32com.client.pythoncom.VT_VARIANT' > > no matter what extension I use (i.e. VT_I4 or VT_BOOL etc etc) it > still returns a type mismatch error. I may be doing something wrong or > getting confused with variant processes in python. I do know the code > I use in perl to do this works but I dont know how to translate this, > fully, into python. > > perl code for variant = > Win32::OLE::Variant::Variant(Win32::OLE::Variant::VT_VARIANT|Win32::OLE::VARIANT::VT_BYREF, > 0) Unfortunately, you really can't do this in a clean way. The best thing to do is to ensure "makepy" has been run for your COM object, and the right magic should always happen. Mark. From cnetzer at sonic.net Wed Aug 27 20:46:35 2003 From: cnetzer at sonic.net (Chad Netzer) Date: Wed, 27 Aug 2003 17:46:35 -0700 Subject: Class level variables in Python In-Reply-To: References: Message-ID: <1062031595.1852.87.camel@adsl-209.204.179.133.sonic.net> On Wed, 2003-08-27 at 16:43, Brian Munroe wrote: > I am just starting to learn the OO side of Python scripting, and I am > a little confused on the following. Take the following example class: > > >>> class rectangle(object): > z = 1 z is an attribute of the classes, and is shared across all instantiated members of the class (ie. the objects constructed by calling rectangle()) > def __init__(self): > self.x = 2 This sets the x object in the specific object referred to by 'self' to 2. This object can set the value to something other than 2, outside of __init__, and it won't be set in other rectangle objects so, using your class: >>> class rectangle(object): ... z = 1 ... def __init__(self): ... self.x = 2 ... >>> a=rectangle() >>> b=rectangle() >>> a.z 1 >>> rectangle.z = 5 # here I assign a new value to the class variable >>> a.z # Both instances 'see' the new value 5 >>> b.z 5 Note that the following will NOT work like you might expect! >>> a.z = 7 # Assign to the z attribute of the a object >>> b.z 5 Ie. 'b' did NOT get 5. You have to assign to the class object. So, each object can choose to "shadow" the class variables. If you need to access the class variable, you can use the class name, or the __class__ attribute. >>> rectangle.z 5 >>> a.__class__.z 5 Python is pretty simple and consistent. In the class definition, z = 1 assigns the 1 object to the name z in rectangle's namespace. The "def __init__" *ALSO* assigns to the class's namespace, but this time it is a function object which it calls '__init__'. All instantiations share these attributes. Calling a member function is the same as accessing a class attribute variable. Also, since you assign the 'x' name to each instantiated object in the initialization method, all the objects start with an 'x' attribute. But, each object can change that 'x' name to something different, and 'x' is NOT part of the class namespace. >>> a.x = 10 >>> b.x # b does not 'see' the change to a 2 >>> rectangle.x # classes are objects, separate from their creations Traceback (most recent call last): File "", line 1, in ? AttributeError: type object 'rectangle' has no attribute 'x' There's more to be said, but this is a start. Here is a link: http://diveintopython.org/fileinfo_classattributes.html -- Chad Netzer From cookedm+news at physics.mcmaster.ca Mon Aug 4 00:23:59 2003 From: cookedm+news at physics.mcmaster.ca (David M. Cooke) Date: Mon, 04 Aug 2003 00:23:59 -0400 Subject: uTidyLib --I'm lost References: Message-ID: At some point, james roush wrote: > I'm tryinh to switch from mx.tidy to uTidyLin and it isn't going well. > So far I can't even import TidyLib. Below is what I get when trying to > import into Idle. I'm using Python 2.1. > >>>> from tidylib.lib import parse, parseString > Traceback (most recent call last): > File "", line 1, in ? > from tidylib.lib import parse, parseString > File "K:\Python21\tidylib\lib.py", line 47 > yield n > ^ because yield (and generators) weren't added until python 2.2. (you'll need to upgrade.) -- |>|\/|< /--------------------------------------------------------------------------\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca From hokiegal99 at vt.edu Sun Aug 3 22:30:27 2003 From: hokiegal99 at vt.edu (hokiegal99) Date: Sun, 03 Aug 2003 22:30:27 -0400 Subject: Determining if a filename is greater than X characters References: <93f5c5e9.0308021815.44c57a2d@posting.google.com> Message-ID: <3F2DC543.70700@vt.edu> One last question and then I'll leave you guys alone for awhile: How would I append a string to the end of each file that I've truncated? I'd like to put '.txt' on the end, but I don't understand how to go about it. When I tried this: old_fname = files new_fname = old_fname.append('.txt') .txt was added as a string to the files list. Researching a bit on Google told me that in Python strings are unchangeable. So, how would I go about changing a string? Thanks!!! hokiegal99 wrote: > How would I determine if a filename is greater than a certain number > of characters and then truncate it to that number? For example a file > named XXXXXXXXX.txt would become XXXXXX > > fname = files > if fname[0] > 6 > print fname[0] > > Thanks!!! From stephan.diehl at gmx.net Fri Aug 22 14:48:49 2003 From: stephan.diehl at gmx.net (Stephan Diehl) Date: Fri, 22 Aug 2003 20:48:49 +0200 Subject: __getattr__ weirdness References: Message-ID: Greg Brunet wrote: > In adding the ability to refer to field values using dbfFile.field > notation, I learned how to use __getattr__ and __setattr__ . After some > trial and error, I got it working. But as part of my trials, I added > some print statements to debug stuff. The ones I added to __setattr__ > work as expected, but the one in __getattr__ seems to get called just > under 1000 times for every __getattr__ call! > > Something is obviously not right here - but I'm at a loss to understand > what's going on. I've pared down my code to still show it happening & > included it below. If you run this program & pipe the output to a file, > you'll get just under 14000 debug lines. Any ideas? Thanks! > Within the __getattr__ method, you can't just do normal attribute access as this will trigger another call to __getattr__, so you where stuck in an infinite loop. try to access the required attribute directly from the __dict__ def __getattr__(self, key): """ Return DBF record values by field name """ print "_ga: " + key try: # return self._rec[self._fldNames.index(key.upper())] ^^^^ return self.__dict__['_rec'][self._fldNames.index(key.upper())] except: raise AttributeError("Unknown Field: %s" % ( key )) Hope that helps Stephan From tjreedy at udel.edu Fri Aug 29 12:20:11 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 29 Aug 2003 12:20:11 -0400 Subject: method (a, b = '', *c, **d): gets a syntax error? References: <3F4F644D.2060003@uni-bonn.de> Message-ID: <3dqcndZe5u2g4NKiXTWJiA@comcast.com> "Andreas Neudecker" wrote in message news:3F4F644D.2060003 at uni-bonn.de... > class WhatsUp: > __call__ ( > self, > var1, > var2 = '', > *moreVars, > **moreNamedVars, > ): > pass > > > I always get an error for the **moreNamedVars, line where the '^' points > at the comma at the end (or, if I remove the comma, it points at the > colon). ...What is wrong? Generaly, when reporting 'I got an error', you should copy the actual error message. In this case, I presume you got 'SyntaxError: invalid syntax' for each of your two syntax errors. 1. When you make a function call and use **whatever, it must be the last item in the argument list, just as in a function definition. A following comma is not allowed for either defs or calls. So when you add 'def' to correct your actual error, you also need to omit the comma. 2. The colon suffix is required for defs but forbidden for calls. With the comma present, the parser never got far enough to this. Unlike most batch compilers, the CPython parser quits at the first error it sees. So when you correct one error and resubmit, you may expose another further in your code. Welcom to Python. Enjoy. Terry J. Reedy From vze4rx4y at verizon.net Sat Aug 30 22:33:06 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Sun, 31 Aug 2003 02:33:06 GMT Subject: list.sort(func) speed References: Message-ID: [mackstann] > I have the following function that compares two filenames based on their > basename only: > > _basenameCmp = lambda self, *pair: cmp(*map(os.path.basename, pair)) > > This is so that I can sort a list of files, and the sorting will be done > by filename, ignoring path. There is a minor issue which is not so much > a problem (yet) per se, but just made me curious if there was a better > way to go about this. When calling .sort() on my list, it takes 16ms to > complete. Calling .sort(_basenameCmp) on the same list takes 244ms. > This list could very well be 5 or 10 times the size, in use. Now, I > believe that my _basenameCmp() needs to be called a lot of times (er.. > can't figure out exactly how many, (len(mylist)/2)^2 ?) and doing a > string operation that many times is obviously going to slow it down. > > So my question is: Is there anything I could do differently or better > to speed this up? A Schwartzian transform will completely remove the function call overhead: http://www.python.org/cgi-bin/faqw.py?req=all#4.51 Raymond Hettinger From yinyang at eburg.com Tue Aug 12 13:29:16 2003 From: yinyang at eburg.com (Gordon Messmer) Date: Tue, 12 Aug 2003 10:29:16 -0700 Subject: IO timeout in threaded application In-Reply-To: <16183.61048.228691.131382@montanaro.dyndns.org> References: <3F37EB6E.4080306@real.com> <16183.61048.228691.131382@montanaro.dyndns.org> Message-ID: <3F3923EC.9000703@eburg.com> Skip Montanaro wrote: > Gordon> What's the easiest way to accomplish that? Should I just > Gordon> subclass smtplib's SMTP class and override the "connect" > Gordon> function with one that creates a socket with a timeout? > > Right now that's probably your best bet. Setting timeouts from higher-level > packages which use sockets has not yet been tackled. The only concern I have with that approach is that the behavior of the parent's function may change, and the class will break. The other approach I'd thought about would be to open a pipe and fork a process to do the check. The external process could handle signals properly. So... following a fork(), how would I prepare the new process to receive signals (i.e. make the new process a single "thread" again)? From cnetzer at sonic.net Thu Aug 28 01:03:36 2003 From: cnetzer at sonic.net (Chad Netzer) Date: Wed, 27 Aug 2003 22:03:36 -0700 Subject: Celebrity advice (was: Advice to a Junior in High School?) In-Reply-To: References: Message-ID: <1062047016.1853.167.camel@adsl-209.204.179.133.sonic.net> On Wed, 2003-08-27 at 21:12, Tom Plunket wrote: > Ironically the states with the loosest gun laws also have the > least crime. Perhaps that is because the states with the least crime need the least stringent gun laws. :) > Remember that automobiles kill something like 100x the number of > people in the US every year over guns. You know, instead of making things up, we can use the web these days. According to the National Center for Injury Prevention and Control: http://www.cdc.gov/ncipc/wisqars/default.htm In 2000, there were 43,604 automobile related deaths in the U.S. In 2000, there were 28,663 firearm related deaths in the U.S. BTW. That gun death figure is down from years before; usually it is above 30,000. Perhaps it was the strong economy (my opinion), or perhaps it was due to tougher gun laws (both state and federal). See http://webapp.cdc.gov/sasweb/ncipc/mortrate10.html to check for yourself. For more automobile data, see FARS: http://www-nrd.nhtsa.dot.gov/departments/nrd-30/ncsa/fars.html Also, apparently over half of the gun deaths are suicides. http://www.ichv.org/suicideandguns.htm And, about 40% of automobile accident deaths are 'alcohol related'. http://www.cdc.gov/ncipc/factsheets/drving.htm So, your figure of 100x is ridiculous on the face of it, and does not stand up to even minimal fact checking. -- Chad Netzer From tomas at fancy.org Thu Aug 28 00:08:21 2003 From: tomas at fancy.org (Tom Plunket) Date: Wed, 27 Aug 2003 21:08:21 -0700 Subject: Advice to a Junior in High School? References: Message-ID: Howard Nease wrote: > I have heard a whole lot about the fact that the market for > software engineers nowadays is *HORRIBLE*... You could go to work in the video game industry. Like most entertainment industries it fares pretty well especially when there's a downturn in society. I've been a video game programmer for seven years. It's a lot of work and not a lot of money, but it feels cool to me to work on the programs that people use *after* work. ;) We make the software that people choose to use individually. > I would be devastated were I to find the need to leave computer > science. There will always be a call for programmers. The key to securing yourself in whatever position you want to be in is simply to be better than everyone else around you at that role. Study hard, go after internships while in college (or even before, I recently had a 16-year old intern in programming who was hot-shit), and absorb everything you can. Learn Python, learn C++, learn Lisp. Understand what you like and don't like about each of these languages. Good luck, -tom! -- There's really no reason to send a copy of your followup to my email address, so please don't. From hokiegal99 at hotmail.com Mon Aug 4 08:23:24 2003 From: hokiegal99 at hotmail.com (hokiegal99) Date: 4 Aug 2003 05:23:24 -0700 Subject: Determining if a filename is greater than X characters References: <93f5c5e9.0308021815.44c57a2d@posting.google.com> <3F2DC543.70700@vt.edu> Message-ID: <93f5c5e9.0308040423.4710b3b0@posting.google.com> Thank you both for the information on strings. I got it to work with this: old_fname = files for old_fname in files: new_fname = old_fname + '.txt' print new_fname I am reading the tutorials, but I'm also learning as I go. This board is very helpful to me along with the documentation. Thanks!!! Alex Martelli wrote in message > You cannot change a given string-object, any more than you can change > a given number-object -- the object 23 will always have value 23 (never > 22 nor 24 nor any other number), the object 'foo' will always have > value 'foo' (never 'bar' nor 'foobar' nor any other string). > > However, you can re-bind a name to refer to a different object than > the one it previously referred to. Thus, for example: > > x = 23 > x = x + 1 > > this has not changed the number 23, whose value IS still 23, but name > x now refers to a different number, namely, the number 24. Similarly: > > x = 'foo' > x = x + '.txt' > > this has not changed the string 'foo', whose value IS still 'foo', but name > x now refers to a different string, namely, the string 'foo.txt'. > > The unchangeability of strings doesn't inhibit string manipulation any > more than the unchangeability of numbers inhibits arithmetics. Simply, > operations on strings build and return new strings, just like operations > on numbers build and return new numbers, and in either case you may, if > you wish, re-bind some pre-existing name to refer to the new objects. > > > Alex From bdesth.nospam at removeme.free.fr Mon Aug 18 18:47:40 2003 From: bdesth.nospam at removeme.free.fr (Bruno Desthuilliers) Date: Tue, 19 Aug 2003 00:47:40 +0200 Subject: What's TOTALLY COMPELLING about Ruby over Python? In-Reply-To: References: <3F412484.69867AED@alcyone.com> Message-ID: <3f415560$0$1124$626a54ce@news.free.fr> Istvan Albert wrote: > Erik Max Francis wrote: > >>> What's ***TOTALLY COMPELLING*** about Ruby over Python? >> >> >> comp.lang.ruby doesn't have Brandon Van Every. > > > LOL > LOL 2 Bruno (yes, I want to be in Brandon's killfile. It's the new game on clp : being in Brandon's killfile. Just imagine what will happen when every clp regulars will be in Brandon's kill file...) From msolem at firstlinux.net Wed Aug 13 22:49:46 2003 From: msolem at firstlinux.net (Mike solem) Date: Thu, 14 Aug 2003 02:49:46 GMT Subject: Non blocking tty I/O Message-ID: <1104_1060829342@news-server.optonline.net> I'm reading data from the comport on linux, using 'read(1)'. This blocks until it gets a byte. How can I get it to not block, so that it doesn't hang forever waiting for a byte. Mike From rxs141 at cwru.edu Sat Aug 2 17:39:26 2003 From: rxs141 at cwru.edu (Ravi) Date: Sat, 02 Aug 2003 17:39:26 -0400 Subject: Match beginning of two strings Message-ID: Hi, I have about 200GB of data that I need to go through and extract the common first part of a line. Something like this. >>>a = "abcdefghijklmnopqrstuvwxyz" >>>b = "abcdefghijklmnopBHLHT" >>>c = extract(a,b) >>>print c "abcdefghijklmnop" Here I want to extract the common string "abcdefghijklmnop". Basically I need a fast way to do that for any two given strings. For my situation, the common string will always be at the beginning of both strings. I can use regular expressions to do this, but from what I understand there is a lot of overhead. New data is being generated at the rate of about 1GB per hour, so this needs to be reasonably fast while leaving CPU time for other processes. Thanks Ravi From steve.horsley1 at virgin.NO_SPAM.net Thu Aug 28 15:40:59 2003 From: steve.horsley1 at virgin.NO_SPAM.net (Steve Horsley) Date: Thu, 28 Aug 2003 20:40:59 +0100 Subject: how fast is Python? References: Message-ID: On Wed, 20 Aug 2003 22:00:19 +0000, Andrew Dalke wrote: > Spend a few tens of millions on developing just-in-time compilers > and program analysis. That worked for Java. Have you heard of Jython - python language running on a java VM? It's kind of double interpreted - the python source is converted to JVM bytecode, and then the JVM runs it however that JVM runs bytecode. I guess it should be many times faster than python because of the JVM performance, and wopuld be interested to hear any comparisons. Steve From chris.gonnerman at newcenturycomputers.net Fri Aug 8 08:35:54 2003 From: chris.gonnerman at newcenturycomputers.net (Chris Gonnerman) Date: Fri, 8 Aug 2003 07:35:54 -0500 Subject: [Python] Re: Building extensions with mingw32 -- bdist_wininst fails. References: Message-ID: <002901c35da9$9c2480c0$1f00000a@house> ----- Original Message ----- From: "Thomas Heller" > > OK, here's the problem. The distutils bdist_wininst > > script calls build (illustrated below) but does not > > accept --compiler=mingw32. This is obviously wrong, > > but I'm unsure how to fix it (I'm still trying to wrap > > my fuzzy and tired mind around the entire distutils > > thing). > > > There's an easy workaround. > python setup.py bdist_wininst --compiler=mingw32 > does *not* work. > But this one does: > > python setup.py build --compiler=mingw32 bdist_wininst > > Maybe this should be documented somewhere? > > I've tried it with one of my simple extension modules at > least, and after hacking msvccompiler so that this one > isn't found any longer. Well, whaddaya know, it works! Thanks! I still think the bdist*.py scripts should accept --compiler=mingw32 (or whatever) as a matter of correctness, if nothing else; but I can live with this. Perhaps if I get time I'll work up a patch. Chris Gonnerman -- chris.gonnerman at newcenturycomputers.net http://newcenturycomputers.net From writeson at earthlink.net Thu Aug 28 09:45:44 2003 From: writeson at earthlink.net (Doug Farrell) Date: 28 Aug 2003 06:45:44 -0700 Subject: SOAPpy : How do I prefix items with a string in a SOAP/XML request? Message-ID: <88bc63c6.0308280545.54efabcb@posting.google.com> Hi everyone, I'm trying to build a program to interface to a SOAP/XML interface provided by one of our vendors. This interface is built with MS SOAP Toolkit 3.0, so I'm guessig they are running a .NET server. I'm trying to build my program with Python as I've got to deploy on both Linux and Sun/Solaris platforms. I'm developing on RedHat Linux 8.0 using Python 2.2.1 and SOAPpy 0.10.2. My experimental program almost works, but it isn't putting a necessary prefix string on the XML items in the request. Here is the incorrect request my program is generating: doug beta.grolier.doug Here is what a working request should look like: doug beta.grolier.doug The difference is the 'ns1:' prefix in front of the userPwd, userID and profileID items in the XML part of the request. Here is my sample code that is generating the incorrect SOAP request: #!/usr/bin/python from SOAPpy import SOAPProxy from SOAPpy import SOAPConfig url = "http://some.web.service/direct/direct.asmx" ns = "http://some.web.service/" sa = "http://some.web.service/Init" server = SOAPProxy(url, namespace=ns, soapaction=sa, config=SOAPConfig(debug=1)) rsp = server._ns('ns1', ns).Init(authRequest={'userID':'beta.grolier.doug', 'userPwd':'doug', 'profileID':''}) print "I'm outta here" The degug=1 flag makes the program dump the XML requests/responses, but then it crashes with a traceback because the message I'm getting back is the server error message, not the expected response. Does anyone have any ideas/suggestions on how I can tell the SOAPpy module to add the 'ns1:' prefix to the the items in the request? Thanks for your help, Doug Farrell From gh at ghaering.de Tue Aug 12 04:40:29 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Tue, 12 Aug 2003 10:40:29 +0200 Subject: Running Python 2.3 on a Windows 2000 network In-Reply-To: References: Message-ID: <3F38A7FD.7040302@ghaering.de> John Ochiltree wrote: > Hello group, > > What do I have to do to set up python 2.3 to run centrally on a Win 2000 > network instead of installing it on every workstation? Well, if you have a Windows network, you need scripted installs :-P Otherwise administering a Windows network is too much of a PITA in my opinion. > Is it possible? Sure. Get an installed Python, copy the c:\python23 directory to a network share, then grab the file %SYSTEMROOT%\system32\python23.dll and copy it alongside python.exe. Now all your clients can access Python via the share name. > How do I go about updating individual registeries? I'd appreciate some > pointers and advice if any one can help. Python itself doesn't need any registry entries. If you use the COM stuff of the win32 extensions, though, this might be different. -- Gerhard From mack at incise.org Sun Aug 31 06:07:18 2003 From: mack at incise.org (mackstann) Date: Sun, 31 Aug 2003 05:07:18 -0500 Subject: list.sort(func) speed In-Reply-To: References: Message-ID: <20030831100718.GG9311@incise.org> On Sun, Aug 31, 2003 at 11:21:59AM +0200, Peter Otten wrote: > > (The other issue (decorated sorting) is more relevent of course.) > D'accord. Namely, basename() is not the bottleneck here. Not sure exactly what the bottleneck is, but take this code: print time.time() songs = [ pair[::-1] for pair in enumerate(map(os.path.basename, self.songs)) ] print time.time() songs.sort() print time.time() self.songs = [ self.songs[index] for basename,index in songs ] print time.time() and the output is: 1062322841.2 1062322841.25 1062322841.25 1062322841.26 So it seems that the first list comp with [::-1] and basename and whatnot is the bottleneck, although I'm not sure exactly which aspect of it is the bottleneck. The time between the first two time.time() outputs is always either .05 or .06 seconds. I added this little function: def f(fname): place = fname.rfind("/") if place != -1: return fname[place:] else: return fname And changed the aforementioned line to this: songs = [ pair[::-1] for pair in enumerate(map(f, self.songs)) ] This reduced it to .04 seconds. So I can shave about 10-20 milliseconds using this, although I tend to avoid doing things like this, since it involves more code for me to worry about, and I definitely like to take advantage of Python's "batteries" that they say are included. :) (and generally work well and are silly to duplicate) So basename() is not the bottleneck, but accounts for perhaps 1/6th of the time needed overall. I just wonder if the other 5/6th could be reduced further by doing something that I'm not thinking of. -- m a c k s t a n n mack @ incise.org http://incise.org The sooner all the animals are dead, the sooner we'll find their money. -- Ed Bluestone, "The National Lampoon" From max at nospam.com Tue Aug 5 11:28:40 2003 From: max at nospam.com (max) Date: Tue, 05 Aug 2003 15:28:40 GMT Subject: py2exe 2.3 In-Reply-To: <4IPXa.96711$852.19099@twister.nyc.rr.com> References: <3F2FC633.6090408@nospam.com> <4IPXa.96711$852.19099@twister.nyc.rr.com> Message-ID: Sorry, my bad, I screwed up my versions! Figured it out. From ngps at netmemetic.com Fri Aug 8 02:15:05 2003 From: ngps at netmemetic.com (Ng Pheng Siong) Date: 8 Aug 2003 06:15:05 GMT Subject: streams (was: Re: Itertools) References: Message-ID: According to Mike Rovner : > I made an intensive search on internet and convinced now that term 'streams' > is globaly associated with i/o. I still think using this term for universal > data > structure will be misleading. However I can't come with a good word > (my best is LazyList). Once upon a time, in the days of 386BSD, certain people claimed to be reinnovating Sys V streams for 386BSD, which were to be called "currents". Somehow this episode stuck in my mind. (I think it was the sound of a balloon bursting from too much hot air. ;-) -- Ng Pheng Siong http://firewall.rulemaker.net -+- Manage Your Firewall Rulebase Changes http://www.post1.com/home/ngps -+- Open Source Python Crypto & SSL From gry at ll.mit.edu Tue Aug 26 09:29:40 2003 From: gry at ll.mit.edu (George Young) Date: Tue, 26 Aug 2003 09:29:40 -0400 Subject: reading hex values elegantly from a datagram References: Message-ID: On Tue, 26 Aug 2003 05:29:46 -0700, Dave wrote: > This is doubtless a really dumb question but is there an elegant way > of reading numbers formatted as hex from a datgram? > > I get a datgram which contains values like this: > > ---DATAGRAM--- > 2aef2d43etc... > ---/DATAGRAM-- > where this represents 4 numbers: 2a, ef, and 2d43. > > At the moment I am doing crazy things like converting it to a string, > slicing characters off (ie id = packet[0:2]), adding 0x to the front > and exec-ing the whole thing to get an integer. > > I'll put my code in if you really want but it's just embarassing. > > This is my first time trying to do something with sockets, so please > tell me if I have entirely missed the point. I know that you can use > read to get a number of bytes, but will that solve my problem? Can > anyone point me in the direction of a fool (ie me) proof tutorial on > using bits in python because I can't find anything. For example, is > it possible to read the binary data? At least then I am sure about > the packet structure (for a RADIUS RFC 2865 server, in the unlikely > event that anyone is interested). First order improvement: instead of adding 0x and exec'ing, use the built in "int" function: int('2a', 16) ==> 42 . Better, use the "struct" standard library module, something like: import struct data = mysocket.recv(MAX_UDP_LEN) struct.unpack('BBH', data[0:4]) ==> (42, 239, 17197) Of course you must look carefully at byte order, signed/unsigned, etc. Do: import struct help(struct) for details. From czoretich at octigabay.com Thu Aug 7 19:38:51 2003 From: czoretich at octigabay.com (Craig Zoretich) Date: 7 Aug 2003 16:38:51 -0700 Subject: modifying def behaviour References: Message-ID: "Terry Reedy" wrote in message news:... > "Craig Zoretich" wrote in message > news:e7d0b08f.0308061508.5b5228c7 at posting.google.com... > > Is it possible to change how the "def" builtin command works? > > Sure, if you are willing to change the interpreter. But no, there is > not an exposed 'metafunction' facility analogous to metaclasses. > > > Specifically I want to modify def to write to a log file when a > > function executes (for instance the name of the function, when it > was > > executed - that sort of thing). I want to avoid having to put some > > code in each and every function I write to do this logging for me. > > However, the def code has nothing to do with what happens when a > function is called. All it could do is what you don't want (put code > in eash function). So you would need to hook into the function call > mechanism. To do this in Python (rather than in C and recompile the > interpreter) wrap the functions you want logged as instances of a > logger class. Others have previously posted examples like this: > > class logger: > def __init__(self, func): > self.func = func > def __call__(self, *args): > print "Called: %s with args %s" % (self.func.func_name, args) > return self.func(*args) > > def myfunc(a): return a > > myfunc = logger(myfunc) > > >>> myfunc(3) > Called: myfunc with args (3,) > 3 > > Terry J. Reedy Thanks, this was great stuff. Another question somewhat (maybe) related. Are there going to be any performance issues related to doing this, speed and memory wise? I am assuming this will double the amount of objects that will be created (another object for each function), but being new to python, I don't know if functions take up a lot of memory or not, and whether I'll notice the memory difference. Thanks, Craig From jacek.generowicz at cern.ch Tue Aug 26 10:12:28 2003 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 26 Aug 2003 16:12:28 +0200 Subject: Advice to a Junior in High School? References: Message-ID: "Sean Ross" writes: > Okay. "..., or some other language that supports functional programming > style)" (which would include those mentioned, and many more besides). For > instance, > > http://directory.google.com/Top/Computers/Programming/Languages/Functional/?tc=1 > Aleph (1) > BETA (8) > Caml (2) > Clean (6) > Dylan (19) < > Erlang (313) > Haskell (48) < > Leda (5) > Lisp (378) < > Logo (46) > Lua (18) > Mercury (4) > Miranda (10) > ML (35) > Mozart (2) > Objective Caml (5) < > Pliant (16) > POP-11 (6) > REBOL (95) > Scheme (127) > Sisal (12) They seem to have forgotten Python. From mpeuser at web.de Mon Aug 25 11:44:59 2003 From: mpeuser at web.de (Michael Peuser) Date: Mon, 25 Aug 2003 17:44:59 +0200 Subject: Coloring print lines References: Message-ID: "Risto Per?nen" schrieb im Newsbeitrag news:bid63i$oj9$1 at mordred.cc.jyu.fi... > Sami Viitanen wrote: > > Hello, > > > > Is there an easy way to make script print text with differents colors to > > screen (shell)? ... > If you're using python at X, best advice I canv give is Text-widget at > Tkinter and RTFM (sorry couldn't resist temptation :) . Otherwise you > probably have to fiddle with curses-library (unix-only). Some month's ago Adam Vandenberg released some alpha curses for Windows http://flangy.com/dev/python/curses/ I worked with my Win2000 but is only a partial implementation. It has some color support that migth suffice for the request of the OP. Kindly Michael P From grante at visi.com Tue Aug 12 10:38:43 2003 From: grante at visi.com (Grant Edwards) Date: 12 Aug 2003 14:38:43 GMT Subject: Is Python your only programming language? References: Message-ID: <3f38fbf3$0$158$a1866201@newsreader.visi.com> In article , Joe Cheng wrote: > I want to ask you hard-core c.l.p Pythonistas: Do you use > Python for everything? No. I still use C for Linux device drivers, and embedded code (as well as some assemlby). I use bash and awk sometimes. I also use a bit of JavaScript for web pages. > (and I'm counting Python + C extensions as just Python) Or do > you keep another language equally close at hand, and if so, > what is it? And finally, do you foresee a day when Python can > be, for all practical intents and purposes, your only > programming language? Never. Anybody who thinks there's only one programming language for all tasks is seriously deluded. -- Grant Edwards grante Yow! Yow! I'm UNEMPLOYED! at visi.com From jjl at pobox.com Wed Aug 13 08:50:55 2003 From: jjl at pobox.com (John J. Lee) Date: 13 Aug 2003 13:50:55 +0100 Subject: FTP with urllib2 behind a proxy References: <7d6b0b33.0308070304.53588bf0@posting.google.com> <87d6feykl8.fsf@pobox.com> <84fc4588.0308130237.69d480a1@posting.google.com> Message-ID: <87wudhoh5c.fsf@pobox.com> pythonguy at Hotpop.com (Anand Pillai) writes: > You need to install a proxyhandler, authhandler, > ftphandler and httphandler. Then build yourself > an opener, that opens the doors for you ... :-) > > The following does the trick. > > proxy_handler = urllib2.ProxyHandler( {'http': 'myhttpproxy:80', > 'https' : 'myhttpsproxy:443', > 'ftp' : 'myftpproxy:21' } ) > > opener= urllib2.build_opener(proxy_handler, urllib2.HTTPBasicAuthHandler(), > urllib2.HTTPHandler, urllib2.HTTPSHandler, > urllib2.FTPHandler) > > # install this opener > urllib2.install_opener(opener) > > # Go ahead, knock knock! > > req=urlli2.Request('ftp://ftp.gnu.org') > data=urllib2.urlopen(req).read() A couple of things to add: you don't need to add handlers that already get added by default by build_opener (FTPHandler and HTTPHandler, for example). ProxyHandler is one of these default handlers, so if your environment is set up for it (http_proxy, etc. environment variables), you don't need to supply a ProxyHandler (of course, if your environ. *isn't*, then you do need to supply one, to give it the proxy details). You don't need Request objects (unless you want to add headers to a Request, or pass Requests around). You don't need to install a global opener, unless your code expects it -- it's just a convenience (or an inconvenience, sometimes). Actually, did the OP say proxy basic auth. was involved? Don't recall. I've never needed it for proxies, but there seems to be a ProxyBasicAuthHandler in urllib2, so I guess that's what you meant to use, rather than HTTPBasicAuthHandler (which is for website auth., not proxy auth). So, after all that, you end up with: opener = urllib2.build_opener(urllib2.ProxyBasicAuthHandler) data = opener.open('ftp://ftp.gnu.org').read() (I like to close the response explicitly, though) John From vanevery at 3DProgrammer.com Mon Aug 18 13:52:09 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Mon, 18 Aug 2003 10:52:09 -0700 Subject: What's better about Ruby than Python? References: Message-ID: Sean 'Shaleh' Perry wrote: > > If you joined a Chevy car mailing list and asked "what is better > about Ford than Chevy?" would you expect to hear intelligent, > insightful responses? Perhaps you would receive good answers, perhaps > not. But if you never actually looked at a Ford how would you know? Let me make myself as clear as I can. I am not the slightest bit interested in yours or anyone else's philosophy of whether I should have asked the question, or what manner I should have asked it. I asked a very simple question, and in some cases was rewarded with very simple, helpful answers. Whereas this meta-debate is a complete waste of time. > BTW, my reason, like many here is Ruby looks like Perl and I prefer > Python's syntax and design approach. Not a very scientific reason, > about the same as saying "well, I like blue ones more than red ones". Thanks for the info. You seem to agree with the Ruby FAQ on this point, that the langauges have different design styles and people may prefer one or the other. IMO this isn't a "better" because I'm a pragmatist. My rating for stylism is "is it much less painful than C++ ?" If so then I don't care. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From agh at tpg.com.au Sun Aug 17 23:23:59 2003 From: agh at tpg.com.au (Alastair G. Hogge) Date: Mon, 18 Aug 2003 13:23:59 +1000 Subject: Tuple to string problems References: <3f3b9080@dnews.tpgi.com.au> <3f3eea56@dnews.tpgi.com.au> Message-ID: <3f4046c6@dnews.tpgi.com.au> Heather Coppersmith wrote: > On Sun, 17 Aug 2003 12:37:19 +1000, > "Alastair G. Hogge" wrote: > >> Sean Ross wrote: >>> >>> "Alastair G. Hogge" wrote in message >>> news:3f3b9080 at dnews.tpgi.com.au... >>>> So basicly final_qu would be >>>> ('1','two','hello','2003-08-14','23:32:07') However has stated above >>>> type(final_qu) return tuple. >>> >>> If final_qu is already a tuple of strings, and what you need is one >>> string with each string in the tuple concatenated, then you can do this: >>> >>>>>> final_qu = ('1','two','hello','2003-08-14','23:32:07') >>>>>> final_qu_str = ' '.join(final_qu) >>>>>> final_qu_str >>> '1 two hello 2003-08-14 23:32:07' >>>>>> >>> >>> If you can't guarantee that each tuple element is a string, try this: >>>>>> final_qu_str = ' '.join([str(e) for e in final_qu]) >>>>>> final_qu_str >>> '1 two hello 2003-08-14 23:32:07' >>>>>> >>> >>> [str(e) for e in final_qu] creates a list of a strings from the elements >>> [in >>> final_qu. >>> >>> HTH >>> Sean >> OK. Sorry I didn't quite make myslef clear. >> final_qu is a string for pydb. The string should be something link: >> INSERT INTO foo VALUES "('1','two','hello','2003-08-14','23:32:07')" >> I need the () and each value must be inclosed in '' for the database >> interface. > > Having just been through this myself, you're playing with fire: what if > one of those strings contains a quote character (single or double)? > > Let the database interface do the quoting for you. I don't know what > your table looks like, but I see two possibilities (all code untested): > > If your table contains a single column in which you're trying to put > that whole string: > > sql = """INSERT INTO foo VALUES (%s)""" > params = (repr( final_qu ),) # "str" may work here, too > pydbcursor.execute( sql, params ) > > If your table contains five columns, one for each element of that tuple: > > sql = """INSERT INTO foo VALUES (""" \ > + ','.join( ['%s'] * len( final_qu ) ) \ > + """)""" > params = final_qu > pydbcursor.execute( sql, params ) > > HTH, > Heather > OK I removed the all the 's from the string. But now I get this: raise DatabaseError, "error '%s' in '%s'" % ( msg, sql ), referer: http://nova/~agh/house.html pgdb.DatabaseError: error 'ERROR: parser: parse error at or near ":" at character 155, referer: http://nova/~agh/house.html ' in 'INSERT INTO house VALUES (1,two,three,four,five,six,seven,eight,nine,ten,eleven,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,N/A,2003-08-18,13:19:06)', referer: http://nova/~agh/house.html As my modifed code: #!/usr/local/bin/python import cgi import time import pgdb def Initialise(): _dbuser = "agh" _dbsource = "127.0.0.1:foo" # dsn. _dbname = "foo" return (pgdb.connect(dsn=_dbsource, user=_dbuser, database=_dbname)) def AddData(query): db = Initialise() cur = db.cursor() cur.execute(query) db.commit() cur.close() db.close() # Begin form = cgi.FieldStorage() # Grab the data from web page form qu = "" # Now we put all the form data into one big string for the db query. for name in form.keys(): if form[name].value == "Submit": qu += str(time.strftime("%Y-%m-%d")) + "," + str(time.strftime("%H:%M:%S")) break else: qu += form[name].value + "," StoreData.AddData("INSERT INTO house VALUES (%s)" % (qu)) DisplayContent.WebPage(qu) From speakstofish at hotmail.com Tue Aug 26 20:03:46 2003 From: speakstofish at hotmail.com (Fahd Khan) Date: 26 Aug 2003 17:03:46 -0700 Subject: crazy programming language thoughts References: <3f457487_7@corp.newsgroups.com> Message-ID: <5d855b4b.0308261603.22b69584@posting.google.com> You could alias __getitem__ to "at" and word it as following, keeping entirely in the spirit of this thread: location = self stringCache at: string "Paul D. Fernhout" wrote in message news:<3f457487_7 at corp.newsgroups.com>... > > def addOrFindStringRecord: string readOnlyFlag: readOnlyFlag = 0 > if not readOnlyFlag > self refreshLockFileIfNeeded > self checkOpen > if Options caching > try > if self stringCache has_key: string > location = self stringCache[string] > return self readStringIndexRecord: location > except TypeError, e > # may generate type error if object not hashable > pass > ... > > (Not sure what to do about brackets, so I left them...) > From tjreedy at udel.edu Sun Aug 31 11:51:56 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 31 Aug 2003 11:51:56 -0400 Subject: confirm unsubscribe from zsh-users@sunsite.dk References: <20030831.095012515090500@csa-net.dk> Message-ID: <9gednbZOl6UBhM-iXTWJiA@comcast.com> "Claus Alboege" wrote in message news:20030831.095012515090500 at csa-net.dk... > "Terry Reedy" writes: > > >> I haven't checked whether your address is currently on the mailing > > list. > > > > Then you are a pretty dumb program. Not checking for the subscriber list is what I thought dumb. > Ever heard of sublists? I would expect sublists to be specially configured, by or with list owner approval, as you seem to imply below, rather than added thru public subscribe mechanism. > And about people using different addresses for > each list they subscribe to, such as user-xxx-list at dom.tld? No. I have never had unlimited address availability. I have exactly 1 from udel and 7 for the family from ISP. But it soulds like a great idea. Just yesterday I got virus spam sent to names harvested from a particular list. If I had a special address for that list, I would resubscribe with a new name. If I ever buy a domain-name service with 'unlimited' email accounts, I will try this. Thanks. > will reject messages containing a "Mailing-List" header. (Unless it has > been configured as a sublist) TJR From joost at nowhere.invalid Mon Aug 18 07:13:13 2003 From: joost at nowhere.invalid (Joost van Rooij) Date: Mon, 18 Aug 2003 13:13:13 +0200 Subject: python based tools for developing web-based apps Message-ID: <3f40b630$0$49105$e4fe514c@news.xs4all.nl> Hello, For business purposes I would like to develop several web based application, all based on the the same foundation. I looked at several options like zope, mod_py, webware, skunkweb. Based on the information I found, I now basically considder two options 1. writing a xml-rpc server in Python which provides all the logic. And a seperate frontend in php which reads the data from the Python xml-rpc server and presents it in nice html. (Won't this be a performance hog?) 2. write it on top of a application server like webware or skunkweb. (Are these projects mature enough?) 3. any other good idea, I haven't thought of.... :) I'd appreciate your opinion. Joost van Rooij From kmj9907 at cs.rit.edu Mon Aug 4 16:57:24 2003 From: kmj9907 at cs.rit.edu (Keith Jones) Date: Mon, 04 Aug 2003 20:57:24 GMT Subject: open('.', 'rb') on python 2.3 References: Message-ID: Well, open is just an alias for file, so my novice butt is guessing bugfix. And once you've opened it; it doesn't seem there's much you can do with it anyway. (this is in 2.2) >>> x = file('.', 'rb') >>> x.readline() Traceback (most recent call last): File "", line 1, in ? x.readline() IOError: [Errno 21] Is a directory Keith From gregbrunet at NOSPAMsempersoft.com Thu Aug 7 11:12:53 2003 From: gregbrunet at NOSPAMsempersoft.com (Greg Brunet) Date: Thu, 7 Aug 2003 10:12:53 -0500 Subject: Class design issues: multiple constructors References: <33803989.0308070349.29d8604e@posting.google.com> Message-ID: Hi Miki: > I see two ways: > 1. Module (not class) methods: db = opendb(..), db = createdb(...) > 2. Passing keyword arguments. > def __init__(selfk, filename, **kw): > if kw.has_key(create): > .... > > I vote for the former. Thanks for the response. I lie the first also - what function is being called is more clear than option 2 which would require extra tests (depending on how many __init__ variations there are). If I can understand the staticmethod stuff that Alex mentioned in his message, I may try that path , since I'd like to have the methods actually in the class definition, but defining them in the module itself is definitely a good option. Thanks, -- Greg From danielk at aracnet.com Wed Aug 20 09:07:56 2003 From: danielk at aracnet.com (Daniel Klein) Date: Wed, 20 Aug 2003 06:07:56 -0700 Subject: class factory References: <8ad2cfb3.0308200015.4f5bd504@posting.google.com> Message-ID: On 20 Aug 2003 01:15:44 -0700, nick.keighley at marconi.com (Nick Keighley) wrote: >I'd like to generate a class on-the-fly from a parameter (a dictionary). >>> class MyClass(object): def __init__(self, deadparrot): self.deadparrot = deadparrot >>> mydict = { 'MyClass' : 'foobar'} # { className : constructorArgument } >>> >>> className = mydict.keys()[0] >>> arg = mydict.values()[0] >>> >>> myInstance = eval(className + '(arg)') >>> myInstance <__main__.MyClass object at 0x00A7DE30> >>> myInstance.deadparrot 'foobar' HTH, Daniel Klein Member of the Dead Parrot Society From gafStopSpamData at ziplink.stopallspam.net Wed Aug 13 17:16:05 2003 From: gafStopSpamData at ziplink.stopallspam.net (Gary Feldman) Date: Wed, 13 Aug 2003 21:16:05 GMT Subject: Py2.3: Feedback on Sets References: Message-ID: <3v8ljvo5amvbaq5qdd4e8h9lf47q7afhqk@4ax.com> On Tue, 12 Aug 2003 06:02:17 GMT, "Raymond Hettinger" wrote: >* Are the docs clear? Can you suggest improvements? I haven't used them yet, but since I'm working my way through the docs in general, I thought I'd check them out and comment. 5.12 If the optional iterable parameter is supplied, updates the set with elements obtained from iteration. Iteration over what? Presumably "iterable." However, this being a reference manual, my expectations are a bias in favor of being complete to the point of pedantry. People shouldn't be forced to derive inferences like this. I think it should read "...elements obtained from iterating over iterable." Also, I'd like to see "iterable must be ", though this is a general flaw in the Python doc and is perhaps biased by my C/C++ background where you'd never dream of doing a reference manual without explicitly indicating the types of every parameter. 5.12.1 so none of the following are true: ab A positive phrasing is always preferable to a negative one, and it's always more helpful to say what things do return rather than what they don't. In this case, I'd say "so each of the following returns false: ...." 5.12.1 s.remove(x) remove x from set s s.discard(x) removes x from set s if present The implication being that remove does something else if x isn't in s. Again, my bias towards total completeness is that it should say (presuming my intuition is correct) "remove x from set s; throws an exception if x is not a member of s". (Again, this is a more general problem than just here, though I admit that there's an awful lot of C++ documentation that doesn't document the exceptions that are thrown.) Personally, I have hard time imagining where I'd want that. If I really cared, I could check beforehand, so I think I'd just always use discard. Ditto for s.pop(), i.e. what does it do if s is empty? s.issubset(t) test whether every element in s is in t; I'd prefer "Tests whether s is a subset of t," and likewise for issuperset. I think it's fair that the reader is familiar with sets, so the only real question is whether s.is...(t) means s is t or t is s. Or state both. But being forced to parse a clumsy English phrase to figure it out isn't clear enough. 5.12.2 engineering_management = engineers & programmers Shouldn't this be engineers & management? Also (and here's my pedantry again) if you're using the plural form for engineers and programmers, then it should be managers, not management. Please don't take my pedantry as criticism. It's more just a data point - this is the one way experienced engineer expects to see things. Gary PS I suppose I should mention my strongest pet peeve with the Python documentation, which is the practice of putting the member functions on a different page than the class overview. But that's not your issue, either. From kenfavrow at comcast.net Tue Aug 12 11:10:41 2003 From: kenfavrow at comcast.net (Ken Favrow) Date: Tue, 12 Aug 2003 15:10:41 GMT Subject: mouse control with python References: Message-ID: Very nice. Very helpful! Thank you!! I ran around looking at ctypes and the User32 dll looking for mouse click control and couldn't find anything. Is there a way for me to send a mouse click too? "Richie Hindle" wrote in message news:mailman.1060685779.10849.python-list at python.org... > > [Ken] > > Is there a way I can control the mouse with python? > > I assume you're on Windows. Here's how to move the mouse: > > >>> from ctypes import * > >>> windll.user32.SetCursorPos(100, 100) > > You can get ctypes from http://starship.python.net/crew/theller/ctypes/ > > As an added bonus, here's something that moves it relative to the > currently-focussed window, which is probably useful for what you want > (note that this one doesn't work on 95 or NT4 pre SP3, and it could use > some error handling). > > from ctypes import * > > user32 = windll.user32 > kernel32 = windll.kernel32 > > class RECT(Structure): > _fields_ = [ > ("left", c_ulong), > ("top", c_ulong), > ("right", c_ulong), > ("bottom", c_ulong) > ] > > class GUITHREADINFO(Structure): > _fields_ = [ > ("cbSize", c_ulong), > ("flags", c_ulong), > ("hwndActive", c_ulong), > ("hwndFocus", c_ulong), > ("hwndCapture", c_ulong), > ("hwndMenuOwner", c_ulong), > ("hwndMoveSize", c_ulong), > ("hwndCaret", c_ulong), > ("rcCaret", RECT) > ] > > def moveCursorInCurrentWindow(x, y): > # Find the focussed window. > guiThreadInfo = GUITHREADINFO(cbSize=sizeof(GUITHREADINFO)) > user32.GetGUIThreadInfo(0, byref(guiThreadInfo)) > focussedWindow = guiThreadInfo.hwndFocus > > # Find the screen position of the window. > windowRect = RECT() > user32.GetWindowRect(focussedWindow, byref(windowRect)) > > # Finally, move the cursor relative to the window. > user32.SetCursorPos(windowRect.left + x, windowRect.top + y) > > if __name__ == '__main__': > # Quick test. > moveCursorInCurrentWindow(100, 100) > > > Hope that helps, > > -- > Richie Hindle > richie at entrian.com > > From theller at python.net Thu Aug 7 11:28:03 2003 From: theller at python.net (Thomas Heller) Date: Thu, 07 Aug 2003 17:28:03 +0200 Subject: py2exe problems References: <8utYa.48785$cl3.1524137@news2.tin.it> Message-ID: "Alessandro Crugnola *sephiroth*" writes: > i'm sorry, but it gives me the same warning also using python 2.2.3 The canonical test I use is to run the test_c14n.py test from the PyXML source distribution through py2exe. It works for me, on Windows XP Pro, SP 1, py2exe-0.4.1, Python 2.2.2, PyXML-0.8.3, with the command line 'python setup.py py2exe p encodings' and this script: from distutils.core import setup import py2exe setup(name='test_c14n', scripts=['test_c14n.py'], version='0') If I don't include the '-p encodings' flag, the exe fails with this error: C:\PyXML-0.8.3\test\dist\test_c14n>test_c14n Traceback (most recent call last): File "", line 170, in ? File "imputil.pyc", line 132, in _import_hook File "", line 70, in _finish_import File "imputil.pyc", line 316, in _load_tail File "imputil.pyc", line 271, in _import_one File "", line 128, in _process_result File "xml\dom\ext\reader\__init__.pyc", line 20, in ? LookupError: unknown encoding: utf-8 Can you try this and report back? Thanks, Thomas PS: With Python 2.3 and py2exe-0.4.1, the traceback is this (even if -p encodings had been given), note the different error message: C:\PyXML-0.8.3\test\dist\test_c14n>test_c14n Traceback (most recent call last): File "", line 170, in ? File "imputil.pyc", line 132, in _import_hook File "", line 70, in _finish_import File "imputil.pyc", line 316, in _load_tail File "imputil.pyc", line 271, in _import_one File "", line 128, in _process_result File "xml\dom\ext\reader\__init__.pyc", line 20, in ? LookupError: no codec search functions registered: can't find encoding From adalke at mindspring.com Thu Aug 7 15:50:38 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Thu, 7 Aug 2003 13:50:38 -0600 Subject: catching exceptions in expressions References: Message-ID: Vaclav Dvorak: > Well, list comprehensions were implemented, and that feature didn't even > need anything new - not even functions, let alone syntax: True, which is why I did say "generally." When list comprehensions came out, one of the things I found I liked about it was it replaced a lot of code like new_data = [] for x in data: new_data.append(x.attr) data = new_data I tried to abstract that into a function, like def get_list_attr(data, attrname): new_data = [] ... but could never come up with a good name for that function. List comprehensions made the code shorter, easier to read, and solved my naming problem. While what you want has a meaningful name, like 'safe_int' or 'int_with_default' or .... > Well, it's good when you will use than a hundred times. But when you > need it only here and there, it's more hassle than it's worth. Your syntax-based default value on exception could have the same principle applied to it - is the number of times of use worth making the change to the language? > >>a = int(s) or 99 if ValueError > > > > Parse ambiguity. > > I'm not an expert in parsers, but wouldn't the "if" disambiguate it, as > it's not otherwise found inside expressions? In general, yes. But Python uses a lookahead-one parser, meaning that the next token should be sufficient to figure things out. Suppose you have x = a or b or [....] is the last or part of the 'or' expression x = a or b or c or is it part of an exception catcher x = a or b or c if ValueError Parsers can figure things out, but that makes the code harder to implement and the language harder to read. > >>except ValueError: > >> continue [execution on next line - my comment] > > 'continue' already has meaning in current Pythons. > > That's why I chose that - no new keyword. But I retract this one, and > the "retry" statement too. I don't really like them myself. :-) What I meant is that for x in data: try: f(x) except ValueError: continue .. already has meaning in Python, not that the word 'continue' by itself exists as a keyword. > Why? You're the only one who doesn't like it, so far. ;-) Of course, > you're also the only one who voiced any opinion, so that leaves me with > a not so huge statistical sample of one. :-) Plenty of history using Python and reading c.l.py and seeing discussions about changing the syntax before, and seeing an utter dearth of people asking for this sort of feature, and applying my own sense of sensability and estimating how rarely I would use the construct. Andrew dalke at dalkescientific.com From ajr at dynacap.com Fri Aug 1 13:53:38 2003 From: ajr at dynacap.com (Arnaldo Riquelme) Date: Fri, 1 Aug 2003 09:53:38 -0800 Subject: A very simple question References: Message-ID: Thanks everyone for all the clarification ajr From mertz at gnosis.cx Wed Aug 27 13:30:24 2003 From: mertz at gnosis.cx (Lulu of the Lotus-Eaters) Date: Wed, 27 Aug 2003 13:30:24 -0400 Subject: Celebrity advice References: <3F4CD2A2.DE7D05D2@engcorp.com> Message-ID: |Terry Reedy wrote: |> (I think it safe to say that during the 20th century, 99% of the 100s of |> millions of murders were committed by armed govern-men rather than by |> private persons acting alone.) Peter Hansen wrote previously: |It may be safe to say it, but is it true, or merely hyperbole? |Were there "100s of millions of murders" in the 20th century The 99% seems like an overstatement. But the 100s of millions does not. "State sponsored" murder was awfully prevalent in the 20th C (and before, and since). A good resource is: http://users.erols.com/mwhite28/warstats.htm It's unlikely that a single one of those listed occurrences would have been substantially different because of local ESR-style gun-nuts in the various places. In fact, in many or most of the places, the murdered populations -were- armed in the way ESR advocates. ESR's "arguments" boil down to: (1) Wow, isn't it fun hearing guns make a loud bang; (2) Oh yeah, be careful not to point them at people by accident; (3) This bunch of invented history kinda-sorta supports my nutsiness, if you squint and don't think about it too hard; (4) Did I mention that I like to hear loud bangs? Yours, Lulu... -- mertz@ _/_/_/_/_/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY:_/_/_/_/ v i gnosis _/_/ Postmodern Enterprises _/_/ s r .cx _/_/ MAKERS OF CHAOS.... _/_/ i u _/_/_/_/_/ LOOK FOR IT IN A NEIGHBORHOOD NEAR YOU_/_/_/_/_/ g s From pobrien at orbtech.com Fri Aug 29 19:52:34 2003 From: pobrien at orbtech.com (Patrick K. O'Brien) Date: 29 Aug 2003 18:52:34 -0500 Subject: Need good example database schema References: Message-ID: Istvan Albert writes: > Mark Carter wrote: > > > I found a link: > > http://www.geocities.com/tablizer/oopbad.htm > > (and there are others) who suggest that object-oriented databases > > aren't a good idea. Tabular databases (and in fact a tabular > > design > > Actually what the link above suggests is that OOP is evil in > general. The brief discourse on OOP not being appropriate for data > modeling is just a tiny part of it. To sum it up for those that do > not want to read it: > > OOP = Communism And his comparison of OO vs. Relational shows equally deep insights. Here is his summary of that situation: "The base philosophical differences I seem to have with the OO paradigm seem to boil down to the appropriateness of trees, the appropriateness of global taxonomies compared to local or ad-hoc taxonomies, and the network-database-like structure of OO versus relational." He can't seem to see the forest for the trees, or so it seems. ;-) -- Patrick K. O'Brien Orbtech http://www.orbtech.com/web/pobrien ----------------------------------------------- "Your source for Python programming expertise." ----------------------------------------------- From mis6 at pitt.edu Wed Aug 13 12:04:39 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 13 Aug 2003 09:04:39 -0700 Subject: Summer reading list References: Message-ID: <2259b0e2.0308130804.492aa1ac@posting.google.com> "Joe Cheng" wrote in message news:... > To me it sounds disturbingly like "Procedures are more flexible than > classes because you can compose classes out of procedures." I would subscribe that. Not that I dislike inheritance, but I don't kill a mosquito with a bazooka. Let me give a real life example, happened to me recently. I had a class manipulating text, with a "dedent" method. It turns out that the "textwrap" module included in the Python 2.3 distribution contains a "dedent" function doing exactly the same. Then I had the satisfaction of killing my own implementation, and to add to my class the textwrap.dedent function just with one line of code, "dedent=staticmethod(textwrapper.dedent)". I am very happy with that because: 1) I shortened my class; 2) I reused pre-existing code; 3) I trust the developers of the standard library more than myself; 4) If the standard library contains bugs, they are much more easily discovered than my own bugs; 5) the burden to fix them is up the Python developers, not me ;) The fact that "dedent" was a function and not a method in a class made my life easier. I had not to worry about inheriting from another class with potential name clashes with my own, and "dedent" was the only function I needed. Fortunately, quite a lot of modules in the standard library are written without a class interface and I would date say I have never seen an example of usage of a class when the class is not needed. In other words: most of the time a lightweight approach is more than appropriate, why should I be forced to take a heavy weight approach? The fact of having "free" functions (i.e. not bounded to classes) is to me a big strenght of Python and it helps reuse of code quite a lot. To reuse classes is good, but typically only works when you know about the class you want to inherit *before* you start coding your own class; on the other hand, it is quite easy to add functions or methods to your class even *after* you wrote it. Moreover, this is nothing wrong about using many short modules collecting utilities functions, you will never clutter your namespace, if you use a minimum of care (even globals are globals only in their module, I love that! ;) I tend to code in terms of small functions, then I compose them in small classes, then I compose the classes in modules. When I am done, I play with metaclasses if I need to modify what I wrote with a minimum of effort. There are quite few languages that can give you such a flexibility, and no one simpler to use than Python. Just my own view, Michele From hokiegal99 at hotmail.com Tue Aug 26 21:58:30 2003 From: hokiegal99 at hotmail.com (hokiegal99) Date: Tue, 26 Aug 2003 21:58:30 -0400 Subject: String find and replace References: <3F4C04F8.5070401@vt.edu> Message-ID: <3F4C1046.1030704@hotmail.com> I hate to answer my own post, but I think I understand what I'm doing wrong. I'm finding and replacing 'this' with 'that' in the varible named mystr, not the actual files. So, how would I go about making the change to the actual files instead of a variable that contains their content? If I've got this completely wrong, someone let me know... I've been wrong before ;) hokiegal99 wrote: > Thanks for the explanation, I can make it work this way: > > import os, string > setpath = raw_input("Enter the path: ") > for root, dirs, files in os.walk(setpath): > fname = files > x = 'THIS' > y = 'THAT' > for fname in files: > myfile = file(os.path.join(root,fname), 'r') > mystr = myfile.read() > myfile.close() > search = string.find(mystr, x) > if search >=1: > string.replace(mystr, x, y) > print "Replacing", x, "with", y, "in", fname > > If only I could actually make the change to the files! It works in > theory, but not in practice ;) Anyone recommend how to actual write the > change to the file? I'm new to this, so be kind. > > Thanks Everyone!!! From mwh at python.net Fri Aug 15 08:36:27 2003 From: mwh at python.net (Michael Hudson) Date: Fri, 15 Aug 2003 12:36:27 GMT Subject: 2.3: test test_normalization failed References: <7h33cg4403q.fsf@pc150.maths.bris.ac.uk> <6e990e29.0308150215.62730c02@posting.google.com> Message-ID: <7h3u18j2j6t.fsf@pc150.maths.bris.ac.uk> hjwidmaier at web.de (Hans-Joachim Widmaier) writes: > Michael Hudson wrote in message news:<7h33cg4403q.fsf at pc150.maths.bris.ac.uk>... > > [test failure with 4.0.0] > > > This is known: Python from CVS explicitly requests the 3.2 file. > > Maybe test_normalization.py should look at the file version itself and > tell the unsuspicious that it really wants the 3.2 version. It's kind of hard to do that for the already released 2.3 :-) > > I would imagine it being something like unicode 4 adding more > > characters, but Python 2.3 -- being built on 3.2 normalization data -- > > doesn't know how these new character compose or decompose. Just a > > guess. > > Sounds reasonable. So the 2.3 normalization is just incomplete > regarding the newest standard. Yep. I would guess it likely that 2.4 will be up to date again, but it's not really my field. Cheers, mwh -- Java is a WORA language! (Write Once, Run Away) -- James Vandenberg (on progstone at egroups.com) & quoted by David Rush on comp.lang.scheme From usenet_poster_a at tranzoa.com Fri Aug 22 15:19:36 2003 From: usenet_poster_a at tranzoa.com (Alex) Date: Fri, 22 Aug 2003 12:19:36 -0700 Subject: Script to remove SoBig/F virus from POP3 mailbox Message-ID: Under the gun, I've written a Python script to delete emails containing this latest virus/worm (Sobig-F) from a POP3 mailbox. http://www.tranzoa.com/extras.htm#remove_email_virus The script is a quick-and-dirty, no question, but it's sure doing the job on megabytes of garbage without too much bandwidth use (it gets the top 150 text lines of the emails). Interestingly enough, it shows that most of the bad email we're getting can be traced back to a few IP addresses. (Are you listening, 206.228.159.186 and 212.234.58.156 and 81.96.121.126?) That fact indicates that if an ISP or net admin were to pull the plug on a just a few connections, the net would lose a lot of wasted bytes and traffic. Alex From tjreedy at udel.edu Sat Aug 30 15:50:15 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 30 Aug 2003 15:50:15 -0400 Subject: Celebrity advice References: <3F4CD2A2.DE7D05D2@engcorp.com> <23891c90.0308280317.ac68b38@posting.google.com> <3f4e19b3$0$254$626a54ce@news.free.fr> Message-ID: "A.M. Kuchling" wrote in message news:SrSdnYjxF7iCds2iRTvUqA at speakeasy.net... > On Thu, 28 Aug 2003 17:03:14 +0200, > Damien Wyart wrote: > > What about his forthcoming "taoup"* ? Proofreading by several important > > people from the Unix world should make it quite solid, I think. And > > I read a few of the early chapters a long time ago and quite liked it, > though there were occasional flashes of smugness and "we invented the > Internet" grandiosity. At some point I'll get around to reading the whole > thing. He switches from Part 1 Context (Philosophy, History, Other OSes) to Part 2 Design at chapter 4. One could easily skip some of 1 and perhaps all of 2 and 3. I am up to 11 of 20 and have learned quite a bit. And the price is right for the online copy http://catb.org/~esr/writings/taoup/html/index.html Terry From irmen at -NOSPAM-REMOVETHIS-xs4all.nl Tue Aug 12 10:50:21 2003 From: irmen at -NOSPAM-REMOVETHIS-xs4all.nl (Irmen de Jong) Date: Tue, 12 Aug 2003 16:50:21 +0200 Subject: dumb questions! In-Reply-To: References: Message-ID: <3f38fead$0$49117$e4fe514c@news.xs4all.nl> Emmanuel Jean-Louis wrote: > Guys please bear with me. I'm new to the hole ball game. I'm an > electrical engineer who fall in love with programming. I might be the > dummiest guys in list right now about programming but it's all good. > Hopefully in a year or so, I will sound just like you guys. You will be > seeing a lot of none sense questions, please help me out. Will do, but it is highly recommended to read the following page thoroughly: http://www.python.org/topics/learn/ It points to a lot of invaluable online information, documentation, FAQs, guides, and more. --Irmen From bokr at oz.net Fri Aug 1 17:51:47 2003 From: bokr at oz.net (Bengt Richter) Date: 1 Aug 2003 21:51:47 GMT Subject: How do I combine instance+string for variable References: <4378fa6f.0308011305.183c291a@posting.google.com> Message-ID: On 1 Aug 2003 14:05:19 -0700, mnations at airmail.net (Marc) wrote: >Hi all, > >I can't remember how to do this. > >I have several instances of telnet connections that I label How do you "label" them? By assigning, like conn2 = someSourceOfConn(...)? >conn2,conn3, etc. Later when I want to scroll through all of these I >wanted to do something like this: > > for int in range(2, 9): ^^^-- BAD name!! you are shadowing the builtin int. > use... conn+str(int) {I'm passing it into another >function} Do you want to pass a name in the form of a string, like 'conn2' or do you want the conn2 that you assigned before? If you know the names, you could just write for aConn in (conn2, conn3, ..., conn8): # filling in the rest in place of '...' usingFunc(aConn) If you had stored the conn's in a list instead of individual names, you could write for aConn in theList: usingFunc(aConn) If you want to pick them up by generated string name from the local namespace, you could write something like you started with, e.g., for i in range(2, 9): name = 'conn%s' % i aConn = vars()[name] # or use globals() in place of vars() if not in local namespace usingFunc(aConn) or in one line for i in range(2, 9): usingFunc(vars()['conn%s'%i]) # ditto re globals() vs vars() > >I can't get it to work. I've tried using setattr and eval, but nothing >seems to work. Can I get a little help. Post the code that creates the conn2 etc bindings if the above does not work for you. Regards, Bengt Richter From osuchw at ecn.ab.ca Wed Aug 13 14:31:23 2003 From: osuchw at ecn.ab.ca (Waldemar Osuch) Date: 13 Aug 2003 11:31:23 -0700 Subject: list groups and users of NT domain References: Message-ID: "Marko Faldix" wrote in message news:... > Hello, > > I am looking for a language to achieve lists of all NT users and groups of a > given NT domain on a Windows 2000 Server. It has to run within a webscript, > so vbscript with windows scripting host is considered first. But before I > dive into this, isn't it possible to do it with win32all? Look into \Lib\site-packages\win32\demos folder. In your case you are most interested in win32netdemo.py but it will not hurt if you browse other files. There is a lot of useful examples there > An ideal result would be something like the listings one get while changing > file permissions on a file on a NT machine. I think, this extends too far, > because you browse all accessible domains (isn't it?), but maybe it is > sufficient enough to concentrate on one given known NT domain. > > Must I really use WSH and this combined with vbscript? > > > Thanks for suggestions, Waldemar Osuch From paul.baines at ecb.int Wed Aug 6 07:29:20 2003 From: paul.baines at ecb.int (paul.baines at ecb.int) Date: Wed, 6 Aug 2003 13:29:20 +0200 Subject: Get the hostname Message-ID: <1C8C392782F75943A67C1978F88AF877BE18D4@cimexc01.ecb01.ecb.de> I do this on AIX: import commands hostname=commands.getoutput("uname -n") Paul. -----Original Message----- From: Lukas Schnieper [mailto:schnieper at semafor.ch] Sent: 06 August 2003 13:23 To: python-list at python.org Subject: Get the hostname Hi How can i get the hostname of my Linux PC? I tried os.system('hostname') but i cant save the hostname in a variable like hostname = os.system('hostname') thanks Lukas Schnieper -- http://mail.python.org/mailman/listinfo/python-list Any e-mail message from the European Central Bank (ECB) is sent in good faith but shall neither be binding nor construed as constituting a commitment by the ECB except where provided for in a written agreement. This e-mail is intended only for the use of the recipient(s) named above. Any unauthorised disclosure, use or dissemination, either in whole or in part, is prohibited. If you have received this e-mail in error, please notify the sender immediately via e-mail and delete this e-mail from your system. From mariuszb at janus.law.usyd.edu.au Sun Aug 24 20:40:16 2003 From: mariuszb at janus.law.usyd.edu.au (Mariusz Bartoszewicz) Date: Mon, 25 Aug 2003 10:40:16 +1000 (EST) Subject: (no subject) Message-ID: <200308250040.h7P0eGf09477@janus.law.usyd.edu.au> I am not working for the faculty now. Please contact Donna Wilson on 9351 0346 or donnaw at law.usyd.edu.au Thanks, Mariusz From rtw at freenet.REMOVE.co.uk Mon Aug 11 01:32:10 2003 From: rtw at freenet.REMOVE.co.uk (Rob Williscroft) Date: 11 Aug 2003 05:32:10 GMT Subject: [wxPython] Updating the status bar? References: Message-ID: Steve Lamb wrote in news:slrnbje71n.k27.grey at teleute.dmiyu.org: > Ok, this one I did try before coming here... :) > > I am trying to report the status of what is going on to the status > bar of the main window of my wxPython app. I know I'm on the right > track with SetStatusText() but it doesn't always alter the text. What > the program is doing is taking a filename and passing it through two > different external programs. One of them is taking a little bit of > time to process the file (sa-learn) so the user needs to know what is > going on. Right now I have the call to update the status bar > preceding the external call like so: > > self.MainStatus.SetStatusText('Reporting message as > spam.',0) code = os.system("%s '%s'" % (vars.razor_spam, > filepath)) > > The status bar is not being updated. I know it works because > other calls I have to the same method work fine. Is there some > call I need to make to refresh the window or at least the status > bar? >From the wxWindows help file: wxWindow::Update virtual void Update() Calling this method immediately repaints the invalidated area of the window while this would usually only happen when the flow of control returns to the event loop. Notice that this function doesn't refresh the window and does nothing if the window hadn't been already repainted. Use Refresh first if you want to immediately redraw the window unconditionally. So I would guess at: self.MainStatus.Refresh() self.MainStatus.Update() HTH Rob. -- http://www.victim-prime.dsl.pipex.com/ From __peter__ at web.de Sun Aug 31 05:21:59 2003 From: __peter__ at web.de (Peter Otten) Date: Sun, 31 Aug 2003 11:21:59 +0200 Subject: list.sort(func) speed References: Message-ID: Michael Peuser wrote: > It drove me nearly crazy when I detected that os.path split and join > operations took even longer than raw disk access in a directory scan > program.... Now, that was a fast disk :-) I fear, that some data was already in the cache when your improved version was executed. Please post some sample code/timings for the unbelieving. > Please note that all os.path functions are *awfully* slow! If ever > possible use a nonportable self made scheme. If ever possible, use a *portable* scheme shipped with the distribution. Chances are that it is ahead of your ad hoc solution in terms of correctness. If you have written code that greatly improves on the current implementations, you might consider submitting a patch... > (The other issue (decorated sorting) is more relevent of course.) D'accord. Namely, basename() is not the bottleneck here. Backslashes-removingly yours, Peter From vanevery at 3DProgrammer.com Tue Aug 12 00:29:30 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Mon, 11 Aug 2003 21:29:30 -0700 Subject: Slogan: Getting Rich Overnight References: Message-ID: smarter_than_you wrote: > I know this is an old thread already, but my 2c -- > > If that Brandon idiot hates it, it's a great slogan. Use it and let > the doubters be damned. Anyone who doesn't get the irony is not > worthy of understanding the sentiment. Wow, I know I've been a provocateur on this point, but surely that is throwing business rationality right out the window! At any rate, welcome to my killfile. If knee-jerkism is the extent of your marketing analysis, I surely don't need to hear about it. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From clifford.wells at comcast.net Thu Aug 7 23:36:54 2003 From: clifford.wells at comcast.net (Cliff Wells) Date: Thu, 07 Aug 2003 20:36:54 -0700 Subject: Python's biggest compromises In-Reply-To: References: Message-ID: <1060313813.4813.101.camel@devilbox.homelinux.net> On Thu, 2003-08-07 at 17:54, Bengt Richter wrote: > The world's first programmer was Eve, when she gave Adam a list of things to do ;-) > Real time programming emerged when she told him to what to do when, in order to > get all the food served hot at the same time ;-) And choosing Apple was a mistake even back then Regards, Cliff -- People climbing up the walls, breaking all of my wretched dolls Fingernails they scratch outside, in the attic is where I'll hide -Switchblade Symphony From davesum99 at yahoo.com Wed Aug 13 09:03:43 2003 From: davesum99 at yahoo.com (smarter_than_you) Date: 13 Aug 2003 06:03:43 -0700 Subject: CLI+GUI References: <2259b0e2.0308080948.5a95e383@posting.google.com> <2259b0e2.0308121335.7f1ad18a@posting.google.com> Message-ID: mis6 at pitt.edu (Michele Simionato) wrote in message news:<2259b0e2.0308121335.7f1ad18a at posting.google.com>... > danbmil99 at yahoo.com (dan) wrote in message news:... > > Late to this thread, but -- > > > > in a similar situation, I just put: > > > > _tkinter.dooneevent(_tkinter.DONT_WAIT) > > > > in my main logic loop (cmd interpreter in your case), instead of > > calling Frame.mainloop(). I believe Frame.update() does something > > similar but for some reason this worked better. > > > > ISTM this would be cleaner (and safer) than using threads. You can do > > all your draw operations from your command line routines, and they > > will get displayed as soon as the routine returns to your main loop to > > wait for more input. > > > > Am I missing something? > > > > -dbm > > I like quite a lot you suggestion! "dooneevent" was the method I was > looking for! Actually, I would rather prefer to avoid threads for such a > simple program. Thanks to the power of Python I wrote down a working > script in less than five minutes, even if probably I will need more > than five minutes to understand what I wrote ;) > Here it is: > > import Tkinter as t > import cmd > > root=t.Tk() > s=t.StringVar() > s.set('ciao') > label=t.Label(root,textvariable=s) > label.pack() > > class Cmd(cmd.Cmd): > def do_display(self,arg): > s.set(arg) > root.tk.dooneevent(0) > def do_quit(self,arg): > root.quit() > return 'quit' # anything != None will do > > Cmd().cmdloop() > > > I will later try it on Windows 98. Dunno exactly what "dooneevent" is doing, > I searched my python directories for "dooneevent" and found only one > usage of "doonevent" and copied it ;) Unfortunately "dooneevent" > has no docstring, however few experiments show that "dooneevent()" > is the same that "dooneevent(0)" whereas "dooneevent(1)" hangs up > (it is waiting for what??) > the problem is that most of the documentation is in TK/TCL itself. TKinter is just a wrapper. There are some docs on how the stuff is wrapped, then you have to go to Tk/tcl docs to get the real info. My best guess is that it's a wrapper to this call: http://www.tcl.tk/man/tcl8.4/TclLib/DoOneEvent.htm note the confusion because it's really a tcl call, but Tkinter doesn't make a distinction between tk & tcl. Also note that there are at least three ways to get this behavior: _tkinter.dooneevent(TCL_DONT_WAIT) Frame.update() Tkinter.dooneevent(0) #this is new to me! You found a third way to call it it's all a bit mysterious, but basically you're calling the event handler within TK's mainloop. best - dan From fawcett at teksavvy.com Mon Aug 18 00:34:26 2003 From: fawcett at teksavvy.com (Graham Fawcett) Date: Mon, 18 Aug 2003 00:34:26 -0400 Subject: What's better about Ruby than Python? In-Reply-To: References: Message-ID: <3F405752.7010409@teksavvy.com> Brandon J. Van Every wrote: >What's better about Ruby than Python? I'm sure there's something. > Of course there is. >What is >it? > > You're never going to get an answer to this question that satisfies you. Even if everyone chips in and describes their favourite features, those features may be worthless to you personally. So why bother asking? Try the languages out yourself, both of them; program a non-trivial application in both languages. See how each feels to you, and which better suits your development style. Determine which language has, in your opinion, better support via documentation and community. Then come back to the list and tell us which is the better language. ;-) >This is not a troll. I'm language shopping and I want people's answers. I >don't know beans about Ruby or have any preconceived ideas about it. > Exactly: so don't ask for others' ideas. Since you haven't used Ruby yet, their ideas will simply give you preconceived ideas. What you need are postconceived ideas; harder to gain, but infinitely more valuable. -- Graham From mwh at python.net Wed Aug 27 14:28:09 2003 From: mwh at python.net (Michael Hudson) Date: Wed, 27 Aug 2003 18:28:09 GMT Subject: Filtering virus-related e-mails? References: <3f4ce4d6$0$166$a1866201@newsreader.visi.com> Message-ID: <7h3ad9v6jqu.fsf@pc150.maths.bris.ac.uk> grante at visi.com (Grant Edwards) writes: > Would it be possible for the python mailing list to filter out > the "virus-warning" emails rather than posting them to the > newsgroup? Possibly, but I think the admins are busier trying to stop the network cables and the server melting due to the load... maybe now they've done that they can turn to secondary effects. I gather virus warning emails are quite hard to filter due to each virus program having a different format. Posting here is probably not the optimal way of making this request, BTW. (Earlier on today, Greg Ward brought up exim on the new version of the starship; within ten minutes, the number of SMTP connections had maxed out. Ten minutes after instituting the clever hack that saved mail.python.org, about 250 hosts were being rejected at the firewall level). Cheers, mwh -- That's why the smartest companies use Common Lisp, but lie about it so all their competitors think Lisp is slow and C++ is fast. (This rumor has, however, gotten a little out of hand. :) -- Erik Naggum, comp.lang.lisp From cjw at sympatico.ca Wed Aug 13 07:53:15 2003 From: cjw at sympatico.ca (Colin J. Williams) Date: Wed, 13 Aug 2003 07:53:15 -0400 Subject: Python IDE - "Lite" version available for non commercial use In-Reply-To: <3F395CC7.EFBE63C6@pobox.com> References: <3F395CC7.EFBE63C6@pobox.com> Message-ID: Rick Thomas wrote: > http://wingide.com/wingide The requirements are below, is this "Lite"? Colin W. Free Licenses for Non-Commercial Open Source Developers Free licenses for non-commercial open source development are also available. These require that you provide us with (1) your project's website or ftp address, (2) at least one public release of your open source code, (3) a description of your project, if not on your web or ftp site, (4) the name of the open source license you are using for the project (or a copy of the license if it's not one of the commonly used licenses), and (5) a signed statement that the license(s) will be used only for non-commercial development of an open source product from which you are not deriving income. You must also (6) agree to send us email notification as you release new versions of your product. If you are just getting started on your project, cannot provide all of these materials, or at our discretion based on a review of your project materials, we may issue a 6 month limited term license instead of a permanent license. Recipients of a limited term license may reapply for a permanent license at any time. However, the limited term license is only available on platforms for which Wing IDE is available as a binary distribution. These requirements are duplicated on the order form. We reserve the right to refuse to issue any free license. From tdelaney at avaya.com Thu Aug 7 19:30:29 2003 From: tdelaney at avaya.com (Delaney, Timothy C (Timothy)) Date: Fri, 8 Aug 2003 09:30:29 +1000 Subject: win32com error Message-ID: <338366A6D2E2CA4C9DAEAE652E12A1DE9DFE83@au3010avexu1.global.avaya.com> From: Oliver Emrich [mailto:krummbeersupp at web.de] > Any help would be appreciated OK. Don't post HTML. Other than that, search google for: "-2147352567" excel "-2147024809" excel and also look at the Excel automation interface in MSDN. Tim Delaney From hokiegal99 at hotmail.com Wed Aug 27 18:33:21 2003 From: hokiegal99 at hotmail.com (hokiegal99) Date: Wed, 27 Aug 2003 18:33:21 -0400 Subject: Script Discussion & Critique Message-ID: <3F4D31B1.6080802@hotmail.com> Is there a forum where one could post a Python script and have it critiqued by others? Something like: Y would be more efficent if you did it this way, or doing it that way could cause problems with X, etc. Thanks!!! From http Fri Aug 1 17:38:37 2003 From: http (Paul Rubin) Date: 01 Aug 2003 14:38:37 -0700 Subject: Python's biggest compromises References: Message-ID: <7xr8456ote.fsf@ruckus.brouhaha.com> Brian Quinlan writes: > I'm not sure that I believe this. In Python, everything is an object > that participates in GC including integers and other light-weight types. > Imagine that you have a mathematic expression that creates a dozen > floats objects as part of its evaluation. Do you believe that it is > faster to add those dozen floats to a list for later collection than to > decrement an integer, notice that the decremented value is 0 and > immediately reclaim the memory? That would not be my intuition (but my > intuition is often wrong :-)). In a fast GC system you would just allocate the floats from a contiguous block. Later you would copy the reachable floats from that block to another block. If no floats are reachable, you don't copy anything. There are all kinds of optimizations you can use, including making clever use of memory protection hardware to notice when your allocator has run over the end of a block so you don't have to even make an explicit pointer comparison, that can make all this run very fast. Andrew Appel has a book about garbage collection where he discusses these methods in detail. From mhammond at skippinet.com.au Tue Aug 5 19:20:05 2003 From: mhammond at skippinet.com.au (Mark Hammond) Date: Wed, 06 Aug 2003 09:20:05 +1000 Subject: pychecking current source file in pythonwin In-Reply-To: <44254d3d.0308050441.3ae97677@posting.google.com> References: <44254d3d.0308050441.3ae97677@posting.google.com> Message-ID: Henrik Weber wrote: > Hi. > > I have tried to add pychecker as an extension to pythonwin. Now I can > have pychecker check the source file that is currently open in the > editor with a single keypress. If someone is interested, here is how > to do it: Cool. Would you be interested in sending me a patch file? This makes it much easier for me to integrate properly. > The script should write something like "pychecker is checking your > source" into the status bar, but I haven't found out how to do that > yet. Maybe some helpful soul can help out with that. win32ui.SetStatusText(message, True) Mark. From creedy at mitretek.org Wed Aug 27 10:52:11 2003 From: creedy at mitretek.org (Chris Reedy) Date: Wed, 27 Aug 2003 10:52:11 -0400 Subject: Aspect oriented Everything? In-Reply-To: <8ef9bea6.0308261857.1b44a5b7@posting.google.com> References: <32cc321c.0308221316.2f5793ac@posting.google.com> <6ee58e07.0308230459.24f53b64@posting.google.com> <8ef9bea6.0308261857.1b44a5b7@posting.google.com> Message-ID: <3f4cc593$1_4@127.0.0.1> If you're interested in this topic, you might check out the work of Harold Ossher at IBM on "Multi-Dimensional Separation of Concerns". (I can provide a detailed reference if you email me.) Even though he's become part of the AOP community, I always found the arguments in his original papers more compelling than more current AOP work. Chris Hung Jung Lu wrote: > Steven Ketcham wrote in message > >>AOP was very difficult to explain, debug and implement. It did not >>obviously replace any of our current procedures and at best it was >>perceived as very heavy-weight. The conclusion on AOP was that it was a >>neat concept but there was no immediate benefit for using it. >> >>On Sat, 23 Aug 2003 22:00:22 +0900, Lothar Scholz wrote: >> >>>I don't like it because it breaks encapsulation and splitters the code >>>over a few files. Maybe that can be solved with new kind of editors >>>but it is much more easy to result in a big confusion. > > > AOP is the latest effort in code factorization. Code factorization > started with the goto statement, then loops, then functions, then > classes and methods. And now, AOP. > [snip] > If we view OOP and inheritance as a vertical dimension in code > factorization, AOP would be a new horizontal dimension in code > factorization. Hence, people use terms like "aspect weaving". > > Some people don't like AOP because it violates encapsulation in the > vertical dimension. But this way of thinking is kind of, erh, > unidimensional. Because conversely, a program that is built from > purely AOP is encapsulated in its own aspect dimension, and the usage > of OOP in that case would violate the encapsulation in the horizontal > dimension. The fact is, both factorizations are needed in the real > world. Aspect-oriented coding and object-oriented coding are like the > conjugate variables in quantum mechanics, whether you use one picture > or the other, at the end of the day they are equivalent, but in some > circumstances it's better to use one than the other. (If you know > Fourier transform, you know what I mean. A localized wave packet in > time necessarily means a spread-out packet in frequency, and > vice-versa. You can't have encapsulation both ways.) > > regards, > > Hung Jung From mhammond at skippinet.com.au Thu Aug 7 07:08:21 2003 From: mhammond at skippinet.com.au (Mark Hammond) Date: Thu, 07 Aug 2003 21:08:21 +1000 Subject: win32, COM, and Solidworks (again) - Still Trying In-Reply-To: References: Message-ID: Markus Wankus wrote: > Hmmm...'Not Implemented'. Because this fails, I can't obtain the CLSID > of itself, thus it can't use the makepy generated code to bind itself > properly. I always get back dumb CDispatch objects. I have been trying > to hack a way of getting the CLSID of the dispatch object, but it just > isn't there. > > Anyway - if anyone reading this knows anything about what I am talking > about, your help would be greatly appreciated. You should use code similar to: mod = gencache.EnsureModule("...", ...) ob = Dispatch("Whatever.Object") # ob now "dumb dispatch", but should be object "foo" # in the gencache module # Explicitly convert ob to one of these object. ob = mod.Foo(ob) Mark. From news at yebu.de Tue Aug 5 12:33:47 2003 From: news at yebu.de (Karl Scalet) Date: Tue, 05 Aug 2003 18:33:47 +0200 Subject: ANN: Snakelets 1.1 (simple-to-use web app server with dynamic pages) In-Reply-To: <87n0eods5s.fsf@pobox.com> References: <3f2ea0a0$0$49110$e4fe514c@news.xs4all.nl> <3f2f7bf4$0$49103$e4fe514c@news.xs4all.nl> <87n0eods5s.fsf@pobox.com> Message-ID: John J. Lee schrieb: > Karl Scalet writes: > [...] > >>the reason why I asked for CGI was that I potentially >>will hold a course about python/webprogramming (very > > [...] > >>CGI capabilities there. Why CGI at all: Simple because >>if I introduce some simple web-applications in the course >>the attendees could take them and most easily transport >>them to a common web-hoster. I know about CGIHTTPServer > > [...] > > Albatross might be worth a look too (also simple, pure-Python hence > easy install, small step up from plain CGI). > I will have a look at this animal, thank you for the info. Karl From dave at boost-consulting.com Thu Aug 21 17:39:02 2003 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 21 Aug 2003 17:39:02 -0400 Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> Message-ID: Roy Smith writes: > One of the few things I like about C++ is that between const, templates, > and inline, the need for the macro preprocessor has been almost > eliminated. Har! If anything it has been increased! Boost, a haven for template experts, has a whole library which formalizes a programming system for the preprocessor (http://www.boost.org/libs/preprocessor) just so we can eliminate the nasty boilerplate that arises in our template code. > Still, you see a lot of code which goes out of its way to > do fancy things with macros, almost always with bad effect. I guess it's a question of how badly you hate maintaining 25 different copies of similar code. And, BTW, I tried to "just use Python to generate C++" first and using the preprocessor turns out to be significantly better. BTW, the C++ preprocessor is a fairly weak macro system. A higher level metaprogramming facility that knows more about the underlying language could be a lot cleaner, clearer, safer, and more expressive. -- Dave Abrahams Boost Consulting www.boost-consulting.com From aleax at aleax.it Thu Aug 7 08:37:27 2003 From: aleax at aleax.it (Alex Martelli) Date: Thu, 07 Aug 2003 12:37:27 GMT Subject: crossplatform py2exe - would it be useful? References: Message-ID: Oren Tirosh wrote: > On Wed, Aug 06, 2003 at 08:36:20PM +0200, Thomas Heller wrote: >> I'm currently working on a new version of py2exe, which will require >> Python 2.3 and later, because it uses the zipimport mechanism. > > Now that zipimport is part of Python the code required for bootstrapping > a py2exe runtime is just: > > myscript -c "import sys; sys.path.insert(0, sys.executable); import foo" > > This reduces the difference between the custom interpreter supplied with > py2exe and the standard interpreter to just a few lines of C. > > The obvious question is - why not go all the way and put this little > hook into the standard Python distribution? This way py2exe could be a > platform-independent pure Python application. In fact, py2exe wouldn't > actually be necessary because anyone could create a zip file manually and > append it to the executable but it's more convenient to have a tool that > automates the process and finds the required dependencies. Sounds like a good idea to me, if a sensible name is chosen for the "main module" (I propose 'main':-). Take it to Python-Dev...? I even wonder if it's unobtrusive enough to be considered (as a "bugfix"...:-) for 2.3.1, rather than having to get into 2.4 and thus wait a LONG time... Alex From tjreedy at udel.edu Wed Aug 27 11:31:21 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 27 Aug 2003 11:31:21 -0400 Subject: Replacement for rexec/Bastion? References: Message-ID: "Michael Chermside" wrote in message news:mailman.1061992484.17157.python-list at python.org... > > Yes, this is messy UNIXy stuff, and loses portability, which is bad, > > but it at least seems to make it possible to do this stuff. Even though (and because!) I currently have a Windows desktop, I would expect and want to run a *nix server if I wanted to run untrusted code. A non-portable (but relatively easily implemented) solution is far better than none at all. > If you DO wind up going this route, I'm guessing that the code > to launch an untrusted-code-runner in a separate process would be > quite popular if it were released back to the Python community, > judging from the number of times this question gets raised. Seconded. A good solution would, for instance, make it possible to run the Python tutorial online. "Try before you buy" etc. Terry J. Reedy From adalke at mindspring.com Thu Aug 21 13:15:22 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Thu, 21 Aug 2003 17:15:22 GMT Subject: What's better about Ruby than Python? References: <3F41505F.69D18CC8@alcyone.com> <66d7kvonvb2n0nqbqahhd5roak7ur81sob@4ax.com> <3f43ef5d_4@127.0.0.1> <3F440A35.9030602@nyc.rr.com> <3F44CF06.4080003@nyc.rr.com> Message-ID: Kenny Tilton > C? does something similar to what you think, but at with an order of > magnitude more power. Estimated. :) Here is how C? can be used: > > [.. some lisp example ...] You have got to stop assuming that a description in Lisp is intuitive to me. I don't know anywhere near enough of that language to know what's normal vs. what's novel. > So I do not have to drop out of the work at hand to put /somewhere else/ > a top-level function which also caches, Didn't you have to "drop out of the work at hand" to make the macro? I tried to understand the lisp but got lost with all the 'defun' vs 'function' vs 'funcall' vs 'defmodel' vs 'defclass' vs 'destructuring-bind' I know Lisp is a very nuanced language. I just don't understand all the subtleties. (And since Python works for what I do, I don't really see the need to understand those nuances.) > Cool. But call cachedCall "memoize". :) Maybe the difference is that you > are cacheing a specific computation of 3, while my macro in a sense > caches the computation of arbitrary code by writing the necessary > plumbing at compile time, so I do not have to drop my train of thought > (and scatter my code all over the place). Sure, I'll call it memoize, but I don't see what that's to be prefered. The code caches the result of calling a given function, which could compute 3 or could compute bessel functions or could compute anything else. I don't see how that's any different than what your code does. And I still don't see how your macro solution affects the train of thought any less than my class-based one. > That is where Lisp macros step up--they are just one way code is treated > as data, albeit at compile time instead of the usual runtime consideration. The distinction between run-time and compile time use of code is rarely important to me. Suppose the hardware was 'infinitely' fast (that is, fast enough that whatever you coded could be done in within your deadline). On that machine, there's little need for the extra efficiencies of code transformation at compile time. But there still is a need for human readablity, maintainability, and code sharing. And for most tasks these days, computers are fast enough. Andrew dalke at dalkescientific.com From nospam at here.com Thu Aug 14 16:32:18 2003 From: nospam at here.com (Richard Townsend) Date: Thu, 14 Aug 2003 21:32:18 +0100 Subject: Tkinter program crashes References: <221d8dbe.0308140955.658000d0@posting.google.com> Message-ID: <1060892976.69114.0@eunomia.uk.clara.net> > Any idea - why the following code crashes on my Win 98 machine with > Python 2.3? Everytime I run this code, I have to reboot my machine. > I also have Win32all-157 installed. > I just pasted your code into a file and it runs OK on Windows 2000 + Python 2.3 Richard From vanevery at 3DProgrammer.com Mon Aug 18 18:14:52 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Mon, 18 Aug 2003 15:14:52 -0700 Subject: What's better about Ruby than Python? References: <38ec68a6.0308172319.431a4fde@posting.google.com> Message-ID: Lulu of the Lotus-Eaters wrote: > The second surest sign that a post is a troll is if the author > includes: > >>> This is not a troll. > > The first surest sign that a post is a troll is if the author is: > >> "Brandon J. Van Every" Man, it's clear that I've got an entire hate group around here to exterminate! I wonder how long it's going to take? Maybe this is a positive sign of Python's growth: it's got enough critical mass to attract just about anybody, not just people who want to get things done. At any rate, welcome to my killfile. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From gerrit at nl.linux.org Thu Aug 28 01:50:56 2003 From: gerrit at nl.linux.org (Gerrit Holl) Date: Thu, 28 Aug 2003 07:50:56 +0200 Subject: Celebrity advice (was: Advice to a Junior in High School?) In-Reply-To: <_M2cnY22TvKT69CiXTWJjA@comcast.com> References: <_M2cnY22TvKT69CiXTWJjA@comcast.com> Message-ID: <20030828055056.GC2515@nl.linux.org> Terry Reedy wrote: > Back to my understanding of what started this subthread and my concern > thereof. Budding CS student A asks for advice about going into CS. > Person B suggests that A read various CS-related writings by CS > celebrities, including C. Poster D says something like 'No, Don't > read C' because he has written 'dangerous' stuff on other topics > (disconnected from CS). Quite aside from my disagreement about the > 'dangerous' characterization, is the boycott suggestion sensible and > legitimate, or just flamebait? I am not sure. I have read the Cathedral but didn't know about ESR's gun statements then. I don't think it is a big problem, objectively. I would find it difficult in more extreme cases however: e.g., I would not read a work from Hitler in 1920 about musquitoes. Elsewhere in this thread, Marx in mentioned. In western Europe, a lot of intelligent people exist who have earlier (mostly in their student period) read and sometimes even written prose which could not be classified as very thoughful (e.g., about Stalin, Mao). This is comparable: "A has written B so C, written by A, is dangerous". However, the differenc is, that in this case (Dutch politicians (Marijnissen and others), Dutch writers (van Zomeren, van Loon, and others), they have all withdrawn their previous statements. > Let's consider celebrity K(nuth). I believe he has written something > on a somewhat different non-CS topic (religion ). Suppose I were to > read it (I have not as yet) and view it as 'dangerous nonsense'. > Would that justify me suggesting to A, on this newsgroup, that he not > read K's CS writings? No; reading Newton is also perfectly valid. Gerrit. -- 100. ... interest for the money, as much as he has received, he shall give a note therefor, and on the day, when they settle, pay to the merchant. -- 1780 BC, Hammurabi, Code of Law -- Asperger Syndroom - een persoonlijke benadering: http://people.nl.linux.org/~gerrit/ Het zijn tijden om je zelf met politiek te bemoeien: http://www.sp.nl/ From newsgroups at jhrothjr.com Sun Aug 17 07:56:33 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Sun, 17 Aug 2003 07:56:33 -0400 Subject: Tuple to string problems References: <3f3b9080@dnews.tpgi.com.au> Message-ID: "Alastair G. Hogge" wrote in message news:3f3b9080 at dnews.tpgi.com.au... > Hello *, > > I'm using Python and the cgi module to retrive data from a HTML form. > I'm then trying to get that information into a string. But efforts fail when > I run type(foo) on my string. type() returns tuple. At a guess, the problem is in the SeAnRe package. I suspect that it's using eval() on the input, which will detect the parenthesis and convert the input into a tuple. This is, by the way, a *very bad thing to do*, because it can lead to interesting results when you feed it unchecked data. At least, they're interesting if you're interested in breaking (or breaking into) a system. So the short answer is to not put parenthesis around the string. The long answer is to use a different package; one that doesn't use eval(), exec or equivalent. HTH John Roth > > My codes follows: > #!/usr/local/bin/python > > import cgi > import time > import SeAnRe > > # Begin > form = cgi.FieldStorage() # Grab the data from web page form > > qu = "(" > for name in form.keys(): > qu += "'" + str((form[name].value)) + "'," > > > # Now we remove the 'Submit' text added by form key above and replace it > with it with the date, time and a closing ")" > tail = "'" + str(time.strftime("%Y-%m-%d")) + "','" + > str(time.strftime("%H:%M:%S")) + "')" > final_qu = SeAnRe.Action("'Submit',", tail, qu) > > So basicly final_qu would be ('1','two','hello','2003-08-14','23:32:07') > However has stated above type(final_qu) return tuple. > I did get a little advice on running str on every element of final_qu like > this: > foo = "" > for k in final_qu.get_each_value: > foo += str(k) > > But then I get "AttributeError: 'tuple' object has no attribute > 'get_each_value" > > The reason I need foo to be a string is because I'm using pgdb. A Python > interface to PostgreSQL. > > Any would be great. > Thanks in advance > -Al From dave at pythonapocrypha.com Sat Aug 23 10:31:41 2003 From: dave at pythonapocrypha.com (Dave Brueck) Date: 23 Aug 2003 07:31:41 -0700 Subject: large-scale app development in python? References: Message-ID: <477762c2.0308230631.7203b0bf@posting.google.com> gabor wrote in message news:... > hi, > > at the company where i'm working we have to rewrite a part of our > java-based application in a different language. Why? > -you can't compile python, as you can c++ or java => there's no type > checking before starting the program => if one programmer changes a > method name or method signature, then how do we know we changed all the > code that calls that method? It's not really that different in Python - you need to check the callers. It's tempting to say that, for example, the C++ compiler will provide a safety net for you, but it's not always reliable. For example: int func(int a, int c=0); If a programmer changes the method signature to: int func(int a, int b, int c=0) then some bugs can still slip through even though the compiler declares the program "good". It's just a fact of life that refactoring a method signature, regardless of the language, implies that you double-check the callers. Anything less is a gamble. But, in practice it's not as bad as it sounds for Python or any other language because of the nature of programs - as they get bigger, most of the refactoring you do will be "local" to a small subset of modules. The coupling of the separate modules is such that you don't have every part of the program talking to every other part of the program. In any language, APIs that are used extensively throughout require more thought and design, and more work to refactor. *In practice* Python isn't really any different in this area. > how do you solve these kind of problems? i know that unit tests are a > good thing, but i don't know if they can help in this situation? Yes, they can. It's not that you write unit tests to test for this specific problem - you write tests for the functionality of your application - and you get coverage on these sorts of problems mostly for free. IOW, these problems *can* be a bigger factor if you don't have good tests, but if you don't have good tests then you are likely to have even bigger problems than these anyway. :) > are there any people who wrote a big program in python? how did they > handle these problems? Yes, there are quite a few large Python applications out there. My personal opinion is that these problems don't occur in practice as often as they do in theory. :) > or python simply isn't suited to write bigger (more complex) apps? In many ways languages like Python are *more* suited than C++ or Java for larger and more complex applications. There are many reasons why this is the case but if nothing else there's this one: for an equivalent set of functionality, the Python version is often much, much shorter, so you can implement *way* more functionality before you begin running into problems that are inherent in large applications. That is a pretty big benefit in and of itself, and a direct "bonus" side effect is that you have to change a lot less code to change some portion of your application. So, if your application evolves over time (as they always do), then there's less risk if you use Python or a similar higher-level language. If you can't clearly define all your requirements up front, you can adapt more easily if you use Python. If you just plain decided wrong in some aspect of your architecture, you have a better chance of being able to correct your mistake if you used Python. -Dave From adalke at mindspring.com Wed Aug 6 16:00:13 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Wed, 6 Aug 2003 14:00:13 -0600 Subject: Stupid string.split question References: <3f314721$0$3936$b45e6eb0@senator-bedfellow.mit.edu> Message-ID: Brian Kelley: > "ABCDEF".split("") shouldn't equal ["A", "B", "C", "D", "E", "F"]? (which, btw, raises a ValueError.) Hmm. Perl does that, right? I see your point about the symmetry, > It seems that if you can join with an empty seperator, you should be > able to split with one. Even better, newer splits take a substring to split on, as in >>> "ABCDEFG".split("BCD") ['A', 'EFG'] >>> "ABCDEFG".split("DCE") ['ABCDEFG'] >>> arguing for a closer similarity. > I suppose the pythonic way is [x for x in "ABCDEF"] which doesn't make > as much sense to be. list("ABCDEF") [to reverse a string] > l = [x for x in forward_string] > l.reverse() > reversed_string = "".join(l) or in Python 2.3 >>> "ABCDEF"[::-1] 'FEDCBA' >>> Andrew dalke at dalkescientific.com From damien.wyart at free.fr Wed Aug 6 08:24:17 2003 From: damien.wyart at free.fr (Damien Wyart) Date: Wed, 06 Aug 2003 14:24:17 +0200 Subject: Checking for an "undefined" variable - newbie question References: Message-ID: <3f30f372$0$27815$626a54ce@news.free.fr> * Alex Martelli in comp.lang.python: > If you can't rule out (e.g.) None as a valid value for your variable, > just make a unique placeholder value such as [be sure to use a MUTABLE > value, else uniqueness is not guaranteed]: Could you expand on this "uniqueness" point ? I don't see very well what you mean. Thanks in advance, -- Damien Wyart From usenet_spam at janc.invalid Mon Aug 25 22:15:14 2003 From: usenet_spam at janc.invalid (JanC) Date: Tue, 26 Aug 2003 02:15:14 GMT Subject: [OT] Why is it called string? References: <3f44ce77$0$556$b45e6eb0@senator-bedfellow.mit.edu> <3F44DBF2.1010403@draigBrady.com> <3f453a22$1_1@themost.net> Message-ID: Jarek Zgoda schreef: >>JZ> I remember that "byte" in French is expressed as "octet", even if >>it has JZ> only 7 bits... >> >> Are you sure. Several international organisations use the word >> 'octet' in their official specifications, to make sure that an 8-bit >> byte is meant. > > I cann't recall the machine I'm referring to (it was product of Bull), > but I am sure that lecturer called 7 bit units as "octets". Most of the time, in French "octet(s)" is used like "byte(s)" in English. On French sites you'll see "Ko", "Mo", etc. to indicate download-sizes. Look here for an example: (t?l?charger = to download) -- JanC "Be strict when sending and tolerant when receiving." RFC 1958 - Architectural Principles of the Internet - section 3.9 From gtalvola at nameconnector.com Tue Aug 26 12:14:54 2003 From: gtalvola at nameconnector.com (Geoffrey Talvola) Date: Tue, 26 Aug 2003 12:14:54 -0400 Subject: Win32All - Services and current path Message-ID: <61957B071FF421419E567A28A45C7FE59AF600@mailbox.nameconnector.com> Jeff Hinrichs wrote: > I'm having trouble nailing down the path to the script directory when > building a service. I am trying to read in a config file via > ConfigParser. When I run the service in debug mode all is well. > When I start it up normally, via 'myservice.py start' I can't get > the directory where my service lives. > > When starting the service normally the current path when I try to > read the file gets set to: > G:\Python22\lib\site-packages\win32 > probably because that is where pythonservice lives. So I can't use > sys.path[0] or parse sys.argv[0] > to find directory where my config file lives. I don't want to > hardcode the path to the config file but > currently that is the only way I can get the ConfigParser object to > find my file. > > What am I missing? I've noticed the same problem. The __file__ variable helps you out here, but unfortunately that variable is not defined if the script is run as the main program (if you're using Python 2.2.X). Put something like this at the top of the module: import os, sys if __name__ != '__main__': mydir = os.path.dirname(os.path.abspath(__file__)) else: mydir = os.path.dirname(os.path.abspath(sys.argv[0])) and I think mydir will be correct regardless of whether the module is imported, run as a program, or started as a service. If you're using Python 2.3, it looks like __file__ is always defined, so import os, sys mydir = os.path.dirname(os.path.abspath(__file__)) would probably be sufficient. - Geoff From dieter at handshake.de Tue Aug 19 16:41:43 2003 From: dieter at handshake.de (Dieter Maurer) Date: 19 Aug 2003 22:41:43 +0200 Subject: client derived from async_chat References: <3f3fdb48_1@news.vo.lu> <3F3FF26F.3D6538F4@alcyone.com> <3f3fff3c_1@news.vo.lu> Message-ID: Patrick Useldinger writes on Mon, 18 Aug 2003 00:20:18 +0200: > Erik Max Francis wrote: > > > I tried to run your sample but you didn't include enough material for me > > to run it as a standalone application. When I tried to stub out the > > additional material you didn't include, I got connection refused errors, > > presumably because the server wasn't running at the point your clients > > tried to connect. > > Look at the following code: > > sock=socket.socket(socket.AF_INET,socket.SOCK_STREAM) > #sock.setblocking(0) > print 'connect rc=',sock.connect_ex((EBHost,EBPort)) > try: > sock.send(message+BLOCKEND) > response=sock.recv(BUFFSIZE) > finally: > sock.close() > > If I run it without the 'sock.setblocking(0)', it works fine. If > uncomment that line, I receive the following error: > > > File "I:\My Programs\sas\sasLA0.py", line 18, in ? > response=sock.recv(BUFFSIZE) > socket.error: (10035, 'The socket operation could not complete without > blocking') This is as it should be: "setblocking(0)" tells all socket operations not to wait but to return immeadiately. If the operation could not be performed, you receive this exception. > This is exactly what seems to happen with the async_chat class, as in > dispatcher.create_socket the same setblocking(0) is done. Sure. "async" stands for "asynchronous". Your program above uses a "synchronous" programming style: you wait until the socket can perform the operation. Once, this synchronization is done, the operation is performed and your program continues. This style calls for "setblocking(1)". "async_chat" on the other hand uses an "asynchronour" programming style. Your program registers requests and waits on a main loop (the "asyncore" main loop) when it has no more requests to do. The "asyncore" main loop notices when one of the requests can execute. Then, it calls back the corresponding request handler It performs the request and may register more requests. We have implemented clients and servers with "asyncore/async_chat". Dieter From newsgroups at jhrothjr.com Fri Aug 1 10:08:13 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Fri, 1 Aug 2003 10:08:13 -0400 Subject: update eclipse plugin, work in progress? References: Message-ID: Which one? The community pages show three(!) different plugins, two of which are hosted on Sourceforge and look pretty moribund to me. The third (Truestudio) looks quite active, with a current update on June 29, 2003. For the ones on Sourceforge, get in touch with the project owners. John Roth "Raaijmakers, Vincent (IndSys, GE Interlogix)" wrote in message news:mailman.1059742743.26743.python-list at python.org... Does anyone know if work is in progress to update the python plugin for eclipse? www.eclipse.org The features of the current plugin is weak compared to the features of for example java. My background from the VA environment for Java and Smalltalk makes me hungry in getting the same strong IDE for Python. Don't mind looking at ways to expand this Python plugin, if possible and if time, but definitely don't have the time to reinvent the wheel. Please feedback. Vincent From vanevery at 3DProgrammer.com Tue Aug 19 01:51:57 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Mon, 18 Aug 2003 22:51:57 -0700 Subject: Why "troll"? (was Re: What's better about Ruby than Python?) References: Message-ID: Aahz wrote: > > Speaking as someone with a well-deserved reputation for abrasiveness > (nothing approaching yours, but established over more than a decade > on-line), when someone as obviously intelligent as you persists in > writing in ways that piss people off, the only likely answers for > "why?" are "troll" or "insane". > Frankly, your list of alternatives is insufficient. It's never a good policy to examine someone else's motives by saying, "If they don't fit into this neat box of mine, they're insane." Nor do statistics have any relevancy, i.e. "likely answers." I'm not going to try to explain things to you unless you can do better. Meanwhile, I'd suggest looking up a Meyers-Briggs test. FWIW I am an INTP. Suggest you zero in on the "T," if you really are interested in explanations rather than confirming your "insanity" world view. > Since "troll" implies volition, it's actually less pejorative than the > alternative. One definition of insanity: performing the same action > over and over again, expecting a different result each time. That definition didn't show relevance the last time either. Frankly, your definition sucks rocks. Get a better one. It fails to explain all sorts of insanities, although it might be ok for schizophrenia. It also overlaps with all sorts of phenoms that vary, but aren't insanity. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From __peter__ at web.de Sat Aug 30 11:30:52 2003 From: __peter__ at web.de (Peter Otten) Date: Sat, 30 Aug 2003 17:30:52 +0200 Subject: Python zipfile: Zip empty directories. References: Message-ID: Mark Wondratschek wrote: > but this must be supported by the zip format > ('cause winzip etc. does it this way). The empty-file idea was one of my > reflections, too. But I'm sure there must be better ways... See what I've found (did not test it myself) googling for zip empty directory: http://mail.python.org/pipermail/python-list/2003-June/170517.html Peter From joel.quinet at be.unisys.com Fri Aug 8 04:13:05 2003 From: joel.quinet at be.unisys.com (Quinet, Joel) Date: Fri, 8 Aug 2003 03:13:05 -0500 Subject: Win32 Extension ADO with SQL Server Problem to insert money data type with a stored procedure Message-ID: <8D7B1A876CBBD2119E6A00105AC57EF00736ED64@BE-BRU-EXCH-1> Hi all, I use the Win32 extension (Build 157) module with Python 2.3 to add row in a sql server 2000 sp3 DB. My problem is I can not insert data of type money in the DB. I use the following command to create the parameter : prm = cmd.CreateParameter('Open', constants.adCurrency, constants.adParamInput, 8, 12.10) cmd.Parameters.Append(prm) Here is the error message I receive | rs, res = cmd.Execute() | File "C:\Python23\lib\site-packages\win32com\gen_py\EF53050B-882E-4776-B64 3-EDA472E8E3F2x0x2x7.py", line 1823, in Execute | return self._ApplyTypes_(5, 1, (9, 0), ((16396, 18), (16396, 17), (3, 49 )), 'Execute', '{00000556-0000-0010-8000-00AA006D2EA4}',RecordsAffected, Paramet ers, Options) | File "C:\Python23\lib\site-packages\win32com\client\__init__.py", line 445 , in _ApplyTypes_ | return self._get_good_object_(self._oleobj_.InvokeTypes(*((dispid, 0, wF lags, retType, argTypes) + args)), user, resultCLSID) | com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft OLE DB Provid er for SQL Server', 'Error converting data type char to int.', None, 0, -2147217 913), None) Thanks in advance for your help Joel From jjl at pobox.com Mon Aug 18 14:45:03 2003 From: jjl at pobox.com (John J. Lee) Date: 18 Aug 2003 19:45:03 +0100 Subject: advice choosing IDE References: Message-ID: <87vfsudcuo.fsf@pobox.com> pinard at iro.umontreal.ca (Fran?ois Pinard) writes: [...] > I progressively learned to write without bugs, [...] Fran?ois is clearly just about to become obscenely rich from NASA & defence contract work. ;-) John, wondering where that GNU recode bug I spent some effort trying to track done can have come from <0.5 wink> From cnetzer at sonic.net Thu Aug 28 02:14:15 2003 From: cnetzer at sonic.net (Chad Netzer) Date: Wed, 27 Aug 2003 23:14:15 -0700 Subject: Py2.3: Feedback on Sets In-Reply-To: <3f4d9347$0$190$7a214f24@news.kaist.ac.kr> References: <%BX%a.4999$N37.3051@nwrdny02.gnilink.net> <7h3d6f3143s.fsf@pc150.maths.bris.ac.uk> <3F4D8BF7.90401@pobox.com> <3f4d9347$0$190$7a214f24@news.kaist.ac.kr> Message-ID: <1062051255.1852.178.camel@adsl-209.204.179.133.sonic.net> On Wed, 2003-08-27 at 22:29, Seo Sanghyeon wrote: > Huh? list * int does repetition. How does it relate to scalar > multiplication of vectors? They both preserve rank. ;) -- Chad Netzer From jdhunter at ace.bsd.uchicago.edu Mon Aug 25 18:42:03 2003 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Mon, 25 Aug 2003 17:42:03 -0500 Subject: Determinig position of a element in a list In-Reply-To: ("Przemo Drochomirecki"'s message of "Tue, 26 Aug 2003 00:29:04 +0200") References: Message-ID: >>>>> "Przemo" == Przemo Drochomirecki writes: Przemo> Hello, i'm wondering if there is any tricky way for doing Przemo> following thing: A - list of distinct integers (e.x. A = Przemo> [1,3,7,11,14,15]) very fast function determinig position Przemo> of number x in list A or -1 if x doesnt belong to A Przemo> Operator IN returns only false/true values i can implement Przemo> function index (e.x. index(5,A) = -1, index(7,A) = 2), but Przemo> maybe there's is simpler(builtin?) solution Is your list sorted, as it is in your example. If so use a binary search. If you are interested in efficient processing of sequences of numbers, you should probably be using the Numeric module. If your sequence is sorted and you can use Numeric, then the following will do what you want with blazing speed from Numeric import * a = array([1,3,7,11,14,15]) val = 7 ind = searchsorted(a,val) if a[ind]==val: print '%d is at position %d' % (val, ind) else: print '%d is not in array' % val If your data is sorted and you don't want to do use Numeric, here is an example of a pure python binary search. http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81188 Finally, if your data is not sorted and you don't want to use numeric, then some variant of the following will provide near-best performance, at least until the next 20 posters weigh in with psycho, pyrex and god knows what other optimizations ind = None for i,thisval in enumerate(a): if thisval==val: ind = i break if ind is None: # val isn't in a else: # val is at position ind enumerate is built-in with python2.3. If you have an earlier version, you can find a recipe in the Active State cookbook to do the job. Cheers, John Hunter From mpeuser at web.de Mon Aug 18 06:42:56 2003 From: mpeuser at web.de (Michael Peuser) Date: Mon, 18 Aug 2003 12:42:56 +0200 Subject: Python form oriented library References: Message-ID: I remembered wrong: > > Someone mentioned PyCard which is a good product, but there is only a > limited number of widgets available. You should give it a try because it > supports (no, that is wrong: it can live with) a lot of basis GUIs.; > Generate a 6 column list, fill it with 1000 entries, sort it, and then try > to print some of it. PyCard depends fully on wxWindows (I was on the AnyGui trip....) Kindly Michael P From usenet_spam at janc.invalid Fri Aug 15 22:58:39 2003 From: usenet_spam at janc.invalid (JanC) Date: Sat, 16 Aug 2003 02:58:39 GMT Subject: ClientCookie bug (fix offered) References: Message-ID: cartermark46 at ukmail.com (Mark Carter) schreef: > BTW, I can't seem to locate the project on Sourceforge. -- JanC "Be strict when sending and tolerant when receiving." RFC 1958 - Architectural Principles of the Internet - section 3.9 From pythonguy at Hotpop.com Wed Aug 20 14:56:36 2003 From: pythonguy at Hotpop.com (Anand Pillai) Date: 20 Aug 2003 11:56:36 -0700 Subject: ClientCookie bug (followup) References: <87znibzrnx.fsf@pobox.com> <87oeypdh92.fsf@pobox.com> <87k79a25pi.fsf@pobox.com> <84fc4588.0308182207.4c649b93@posting.google.com> <87ada5de3j.fsf@pobox.com> <84fc4588.0308200242.3e74e0a1@posting.google.com> <87smnwh3lp.fsf@pobox.com> Message-ID: <84fc4588.0308201056.305dd5a9@posting.google.com> In fact, I am not aware of how Nirmal has done it. He is wrapping up the coding soon, when I will get to see how he has done it. He is doing the persistency part of the cookies, and I guess he is using anydbm for it. Details later. I will send a mail to you, once I get the code from him and review it. Meanwhile you can visit his homepage here http://nirmalc.freezope.org There might be some details on the work there. Regards -Anand jjl at pobox.com (John J. Lee) wrote in message news:<87smnwh3lp.fsf at pobox.com>... > pythonguy at Hotpop.com (Anand Pillai) writes: > [...] > > 'We', nothing royal about it. It is just me and my friend > > & co-developer Nirmal Chidambaram. Apparently he has found > > a way around some of the bugs in Clientcookie. He has written > > It'd be great if you made me aware what those bugs are! > > (BTW, no intent to offend with my comment about your plurality, or > lack thereof -- it's just that the convention of using 'we' in source > code comments is common enough that I've sometimes found myself using > it even when writing code alone, which is funny.) > > > > a new module using the existing Cookie module of python & > > urllib2. One of the problems 'we' had with Clientcookie is that > > it uses its own 'urlopen' methods which does not fit our > > applications needs, so 'we' had to find a way around it. > > As I said before, if you know how to do that, please comment on the > RFE I referenced in my last post. Jeremy Hylton is planning to look > at the patch associated with that RFE in detail sometime, and you > could save him some time if you know a way to do this without patching > urllib2. And I'd like to know how to do it, too :-) > > > > Once the code is ready, I will post it on my webpage, and > > of course it is not a module in itself, so I think an > > announcement to c.l.py is out of place. > [...] > > Would you mind sending me an email? > > Thanks > > > John From adalke at mindspring.com Thu Aug 21 18:51:13 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Thu, 21 Aug 2003 22:51:13 GMT Subject: [OT] Why is it called string? References: <3f44ce77$0$556$b45e6eb0@senator-bedfellow.mit.edu> <3F44DBF2.1010403@draigBrady.com> <3f453a22$1_1@themost.net> Message-ID: Paul Watson > My CS professor would insist that a byte is a collection of bits, and not > necessarily eight. There are machines which do not have 8-bit addressable > bytes. I thought that was called a word, as in "the CDC 6400 had a 60 bit word size" Andrew dalke at dalkescientific.com From jjl at pobox.com Sun Aug 3 07:31:37 2003 From: jjl at pobox.com (John J. Lee) Date: 03 Aug 2003 12:31:37 +0100 Subject: Changing base class of a big hierarchy Message-ID: <873cgjyo2u.fsf@pobox.com> I'm trying to change a base class of a big class hierarchy. The hierarchy in question is 4DOM (from PyXML). 4DOM has an FtNode class that defines __getattr__ and __setattr__ that I need to override. Lots of classes derive from FtNode, often through further base classes, eg. HTMLDirectoryElement --> HTMLElement --> Element --> FtNode There are many leaf classes like HTMLDirectoryElement. The problem is, I need to get new classes identical to the leaf classes, but deriving from BrowserFtNode: class BrowserFtNode(FtNode): def __init__(self, *args, **kwargs): ... def __getattr__(self, name): ... def __setattr__(self, name, value): ... Obviously, I don't want to manually derive from every damned leaf class. I want to say "give me a new class hierarchy just like this one, but derived from BrowserFtNode instead of FtNode". I also don't want to actually mutate the xml.dom module, of course because other code may be using it. What's the easiest way to do that? Maybe deep-copying the module or something, then fiddling with __bases__?? Or a metaclass? While I'm on the subject, does anybody have code to get a list of all classes in a package that derive from a particular class? Or something I could use to do that easily? John From irmen at -NOSPAM-REMOVETHIS-xs4all.nl Fri Aug 29 12:15:17 2003 From: irmen at -NOSPAM-REMOVETHIS-xs4all.nl (Irmen de Jong) Date: Fri, 29 Aug 2003 18:15:17 +0200 Subject: how fast is Python? In-Reply-To: <3F4F63B5.D2684868@hotmail.com> References: <8765khzhl8.fsf@voodoo.fake> <3F4F63B5.D2684868@hotmail.com> Message-ID: <3f4f7c0f$0$49111$e4fe514c@news.xs4all.nl> Alan Kennedy wrote: > Please bear in mind that the test code included the start up time for > interpreter. For jython, this is a high cost, because starting a JVM > often takes up to 10 seconds or more. 10?! On my machine, starting one of the swing demos from the 1.4.2 JDK takes anywhere between zero and two seconds. While (C)Python is quicker than that, it can only be quicker by two seconds, which can be ignored IMHO. Mabe you meannot the startup time, but the time it takes when the (server)HotSpot JIT reaches full speed. That sometimes takes a while because it incrementally compiles the bytecodes. --Irmen From bh at intevation.de Wed Aug 13 06:27:32 2003 From: bh at intevation.de (Bernhard Herzog) Date: Wed, 13 Aug 2003 12:27:32 +0200 Subject: Python vs. C# References: Message-ID: <6qsmo5vomj.fsf@salmakis.intevation.de> Brian Quinlan writes: >> > I think that depends on how efficient you are at writing tests. >> > Python offers a great testing framework to help you. >> >> No, writing tests consumes time. > > Of course. The question is whether writing tests results in less net > development time (due to more rapid bug discovery and elimination). My > experience is that it usually does. And not only that. If you don't have automated tests it means that you have to run at least some tests manually every time you make a change. That costs time too and requires attention. With an automated test suite, after you've written the test it's only a key-stroke or button-click to lauch the test suite and it only really requires attention when some tests fail. Also, with a test suite it's easy to run all tests very often, with manual tests run during developement you usually only test very few things related to the changes you just made and may not notice some of the bugs you just introduced. Bernhard -- Intevation GmbH http://intevation.de/ Sketch http://sketch.sourceforge.net/ Thuban http://thuban.intevation.org/ From bokr at oz.net Sun Aug 3 15:59:10 2003 From: bokr at oz.net (Bengt Richter) Date: 3 Aug 2003 19:59:10 GMT Subject: Determining if a filename is greater than X characters References: <93f5c5e9.0308021815.44c57a2d@posting.google.com> Message-ID: On Sun, 03 Aug 2003 02:45:31 GMT, "Cy Edmunds" wrote: >"hokiegal99" wrote in message >news:93f5c5e9.0308021815.44c57a2d at posting.google.com... >> How would I determine if a filename is greater than a certain number >> of characters and then truncate it to that number? For example a file >> named XXXXXXXXX.txt would become XXXXXX >> >> fname = files >> if fname[0] > 6 >> print fname[0] >> >> Thanks!!! > >filename = "abcdefgh" >if len(filename) > 6: > filename = filename[:6] >print filename >abcdef Why the if test? >>> for filename in ['abcdefgh'[:i] for i in range(8)]: ... print 'filename=%r gets you filename[:6] => %r' % (filename, filename[:6]) ... filename='' gets you filename[:6] => '' filename='a' gets you filename[:6] => 'a' filename='ab' gets you filename[:6] => 'ab' filename='abc' gets you filename[:6] => 'abc' filename='abcd' gets you filename[:6] => 'abcd' filename='abcde' gets you filename[:6] => 'abcde' filename='abcdef' gets you filename[:6] => 'abcdef' filename='abcdefg' gets you filename[:6] => 'abcdef' I wonder about the application of this for filenames though, since filenames often share prefixes. Regards, Bengt Richter From mwh at python.net Thu Aug 14 09:06:21 2003 From: mwh at python.net (Michael Hudson) Date: Thu, 14 Aug 2003 13:06:21 GMT Subject: Py2.3: Feedback on Sets References: Message-ID: <7h3smo44cgu.fsf@pc150.maths.bris.ac.uk> "Raymond Hettinger" writes: > I've gotten lots of feedback on the itertools module > but have not heard a peep about the new sets module. > > * Are you overjoyed/outraged by the choice of | and & > as set operators (instead of + and *)? I'd actually rather sets didn't overload any operators at all, but appreciate that this may be a minority position. | and & is the only sane choice, however. > * Is the support for sets of sets necessary for your work > and, if so, then is the implementation sufficiently > powerful? I don't use them as much as I should, I suspect. > * Is there a compelling need for additional set methods like > Set.powerset() and Set.isdisjoint(s) or are the current > offerings sufficient? I've not reached for something and not found it there yet. > * Does the performance meet your expectations? My uses so far have not had even the faintest of performance demands, so, yes. > * Do you care that sets can only contain hashable elements? Not yet. Cheers, mwh -- The website looks like the Hi-Score sheet from a Bullshit Bingo tournament. -- Dan Holdsworth, asr From vincent at visualtrans.de Sun Aug 3 13:06:26 2003 From: vincent at visualtrans.de (vincent wehren) Date: Sun, 03 Aug 2003 19:06:26 +0200 Subject: command history broken in Python2.3 ? References: Message-ID: Nicola Mingotti wrote: > Hello , > > I'm tring Python 2.3 ( on source and binary distribution , > on Linux and Windows ) and i think > the command history doesn't work . > > When i use the Up-Arrow in Python2.3 > started in an xterm i get '^[[A' . > In IDLE under Windows using Alt-p produce nothig . > In IDLE under Linux Alt-p works !! . > > Do you have the same behavior in you > interpreter ? > > Bye . > > (p.s. please forgive english mistakes ) Just installed 2.3 final release on Linux Same problem here... Vincent Wehren From davecook at nowhere.net Wed Aug 20 12:30:35 2003 From: davecook at nowhere.net (David M. Cook) Date: Wed, 20 Aug 2003 16:30:35 GMT Subject: "_pg" (Postgresql) module for win32 References: Message-ID: In article , User At Domain Dot Invalid wrote: > Where can I find "_pg" module for postgresql? I would prefer a module > not intedend for "cygwin","mingw" or some thing similar to that. pyPgSQL has a win32 binary available for download: http://pypgsql.sourceforge.net/ Dave Cook From sminni_news at minisoftindia.com Sat Aug 30 21:41:30 2003 From: sminni_news at minisoftindia.com (Sanjay Minni) Date: 30 Aug 2003 18:41:30 -0700 Subject: python for dev of CAD type software References: <836a2f21.0308162222.413fefaa@posting.google.com> Message-ID: <836a2f21.0308301741.3bb388a6@posting.google.com> Graham Fawcett wrote in message news:... > Sanjay Minni wrote: > > >is python suitable for a production level > >deployment of CAD type of software. > > http://www.pythoncad.org/ > PythonCAD appears to be only for Linux Anything for MS-Windows platforms Sanjay Minni From dtolton at yahoo.com Wed Aug 13 15:46:33 2003 From: dtolton at yahoo.com (Doug Tolton) Date: Wed, 13 Aug 2003 19:46:33 GMT Subject: The importance of using Library Functions References: <3F3A4CBA.BCACEC50@engcorp.com> Message-ID: On Wed, 13 Aug 2003 10:35:38 -0400, Peter Hansen wrote: >Doug Tolton wrote: >> >> Interestingly TextWrap choked on the text I'm running it against. I'm >> sure it's more an issue of complete craziness in these files than an >> actual problem with TextWrap. > >I believe textwrap.py has some fairly extensive unit tests.** Could >you please post your failing example (if it's not too big), or email >it to me and/or Greg Ward to investigate? Thanks. > >-Peter > >** (I believe this since Greg wrote them and I ported them to PyUnit. >I don't know if that's what's still with the module in Py2.3.) The Text field it was trying to wrap was over 3.6 million characters. I haven't yet had a chance to look and see what specifically was causing it to fail. I'll poke around with it today and see if I can figure it out. I'll post a status update later today. From sross at connectmail.carleton.ca Thu Aug 7 10:49:04 2003 From: sross at connectmail.carleton.ca (Sean Ross) Date: Thu, 7 Aug 2003 10:49:04 -0400 Subject: filter()ing a dict References: <16469f07.0308070559.aed41a@posting.google.com> Message-ID: "John Roth" wrote in message news:vj4p5t8l96201 at news.supernews.com... > A dict is none of those things, unless it supports the iterator > protocol, which is not mentioned in the documentation > as of 2.2.3. Possibly it does in 2.3.0. d = {"key 1": ["value 1", "value 2", "value 3", "value 4"], "key 2": ["value 1", "value 2"], "key 3": ["value2", "value 3", "value 4"], "key 4": ["value 1", "value 2", "value 3", "value 4"]} # dict is an iterator that returns its keys for key in d: print key # output key 1 key 2 key 3 key 4 From westernsam at hotmail.com Wed Aug 13 08:25:26 2003 From: westernsam at hotmail.com (sam) Date: 13 Aug 2003 05:25:26 -0700 Subject: jython and jnios Message-ID: <292c8da4.0308130425.3b19d63d@posting.google.com> Hello, I'm looking at jython and jnios to migrate some Java processes running as NT service to Linux daemons. It seems very tricky to do this kind of thing in just Java and bash. However the jnios project seems not to have been worked on for more than 2 years. Does anyone know if the project is still going? Regards, Sam Owen From syver-en+usenet at online.no Wed Aug 6 17:40:27 2003 From: syver-en+usenet at online.no (Syver Enstad) Date: 06 Aug 2003 23:40:27 +0200 Subject: Kill a named process in win2K not spawned by python References: Message-ID: PoulsenL at capanalysis.com writes: > Can someone give me a clue how to rewrite this kludgy workaround in > python? > > > import os > from win32pdhutil import * > pid = FindPerformanceAttributesByName("WINWORD")[0] import win32process, win32api, win32con handle = win32api.OpenProcess(win32con.SYNCHRONIZE|win32con.PROCESS_QUERY_INFORMATION|win32con.PROCESS_TERMINATE, 1, pid) win32api.TerminateProcess(handle, 1) # exit status -- Vennlig hilsen Syver Enstad From jacek.generowicz at cern.ch Fri Aug 22 05:14:17 2003 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 22 Aug 2003 11:14:17 +0200 Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> <6dj2kv8ugkieehs7guh786cl40o5lj6mcs@4ax.com> <599a6555.0308202108.397bb1a0@posting.google.com> Message-ID: Alex Martelli writes: > Jacek Generowicz wrote: > ... > > For this reason it is rarely a good idea to define a macro for a > > single use. However, it becomes an excellent idea if the idea the > > macro expresses must be expressed repeatedly. The same is true of > > functions, classes, modules ... > > Not at all. "Defining a function for a sinmgle use" is often a > perfectly valid way to make a program MUCH CLEARER. You are, of course, absolutely right. However, I maintian that it is not _always_ a good idea. (eg Reductio ad absurdum.) From ktilton at nyc.rr.com Fri Aug 22 01:15:27 2003 From: ktilton at nyc.rr.com (Kenny Tilton) Date: Fri, 22 Aug 2003 05:15:27 GMT Subject: For Kenny Tilton: Why do I need macros revisited. References: <3f45484f$1_6@corp.newsgroups.com> Message-ID: <3F45A7BF.4060806@nyc.rr.com> Chris Reedy wrote: > For everyone - > > Apologies for the length of this message. If you don't want to look at > the long example, you can skip to the end of the message. > > And for the Python gurus among you, if you can spare the time, I would > appreciate any comments (including words like evil and disgusting, if > you think they are applicable :-}) on the example here. > > Kenny - > > I asked my question about macros with some malice aforethought. This > is a topic I've thought about in the past. > >> Andrew Dalke wrote: >> >>> Kenny Tilton: >>> >>>> This macro: >>>> >>>> (defmacro c? (&body code) >>>> `(let ((cache :unbound)) >>>> (lambda (self) >>>> (declare (ignorable self)) >>>> (if (eq cache :unbound) >>>> (setf cache (progn , at code)) >>>> cache)))) >>> >>> >>> >>> >>> I have about no idea of what that means. Could you explain >>> without using syntax? My guess is that it caches function calls, >>> based only on the variable names. Why is a macro needed >>> for that? >> > > I sympathize with Andrew on this. I had to study this and the following > code for awhile before I figured out what you are doing. However, I do > have an advantage, I know lisp and the macro system and just how > powerful the macro system is. > >> (defun get-cell (self slotname) ;; this fn does not need duplicating >> (let ((sv (slot-value self slotname))) >> (typecase sv >> (function (funcall sv self)) >> (otherwise sv)))) >> >> (defmethod right ((self box)) ;; this needs duplicating for each slot >> (get-cell box right)) >> >> But I just hide it all (and much more) in: >> >> (defmodel box () >> ((left :initarg :left :accessor left) >> (right :initarg :right :accessor right))) >> >> ....using another macro: >> >> (defmacro defmodel (class superclasses (&rest slots)) >> `(progn >> (defclass ,class ,superclasses >> ,slots) >> ,@(mapcar (lambda (slot) >> (destructuring-bind >> (slotname &key initarg accessor) >> slot >> (declare (ignore slotname initarg)) >> `(defmethod ,accessor ((self ,class)) >> (get-cell self ',slotname)))) >> slots))) > > > Ok. The following is more lines of code than you have here. On the other > hand, I think it does about the same thing: > > > > class cellvalue(object): > def __init__(self): > self._fn = None > def _get_value(self, obj): > if hasattr(self, '_value'): > return self._value > else: > value = self._fn > if callable(self._fn): > value = value(obj) > self._value = value > return value > def _set_value(self, value): > self._value = value > def _del_value(self): > del self._value > def _set_fn(self, fn): > self._fn = fn > if hasattr(self, '_value'): > self._del_value() > > class modelproperty(object): > def _init_cell(self, obj): > obj.__dict__[self.name] = cellvalue() > def __get__(self, obj, cls): > if obj is None: > return self > else: > return obj.__dict__[self.name]._get_value(obj) > def __set__(self, obj, val): > obj.__dict__[self.name]._set_value(val) > def __delete__(self, obj): > obj.__dict__[self.name]._del_value() > def setfn(self, obj, fn): > obj.__dict__[self.name]._set_fn(fn) > def setname(self, name): > self.name = name > self.__doc__ = 'Model Property '+str(name) > > class modeltype(type): > def __init__(cls, name, bases, dict): > super(modeltype, cls).__init__(name, bases, dict) > modelprops = [] > for attr, decl in dict.items(): > if isinstance(decl, modelproperty): > decl.setname(attr) > modelprops.append(attr) > if modelprops: > __originit = getattr(cls, '__init__') > def _modeltype_init(self, *args, **kw): > for attr in modelprops: > getattr(self.__class__, attr)._init_cell(self) > if __originit is not None: > __originit(self, *args, **kw) > setattr(cls, '__init__', _modeltype_init) > > >>> class foo: > ... __metaclass__ = modeltype > ... x = modelproperty() > ... def __init__(self, x=None): > ... self.__class__.x.setfn(self, x) > >>> z = foo(x=lambda self: self.a + 2) > >>> z.a = 5 > >>> print z.x > 7 > >>> z.x = -3 > >>> print z.x > -3 > >>> z.a = 15 > >>> print z.x > -3 > >>> del z.x > >>> print z.x > 17 > > I think that has most of the behavior you were looking for. As you can > see from the example, I leaned (I'm not sure leaned is a strong enough > work :-)) on the newer capabilities for metaclasses and descriptors. > (And learned a lot about exactly how they work by writing this up!) looks a lot like the code I was writing when I began a Python port of my Cells project. I'll be open-sourcing the Lisp version soon, you can do the Python port. :) You are absolutely right. Metaclasses are killer. I am surprised Pythonistas afraid of macros let them into the language! I actually had a metaclass implementation of Cells until I decided to release the source. The MOP is not part of the standard, and it shows across implementations. Hell, MCL does not even expose a MOP. > > > > Having looked at the two pieces of code, the only thing that struck me > about how they're used is that the lambda expression needed in the > Python version is clunkier than the version in the Lisp version. You will be delighted to know that one of Lisp priesthood sees no need for macros since what they do can be done with lambdas. Not sure if that is so where one is generating multiple top-level forms from one clause. Me, I like hiding implementation details as mush as possible, and having just one place to go when changing how something works. As for the lambda being clunkier, un-hunh, and if you decide to change the mechanism after a lot of them have been coded, perhaps passing a second argument, here comes the mega-edit. Worse, what happens when the toy hack reaches maturity and you get the final version of the macro: this: (c? (+ 10 (left self))) expands to: (make-c-dependent :code '((+ 10 (left self))) :rule (lambda (c &aux (self (c-model c))) (+ 10 (left self)))) One funny thing is that even if one open codes that, the readers you all are so worried about still do not know what C-DEPENDENT is. Now picture a make-instance with five of those in a row. The text widget font is a function of a user preference, all four dimensions are a function of the font size and string length, the color may be a function of sysntax judgment for highlighting, etc etc. Now you cannot see the semantics for all the redundant, essentially meaningless wiring. > So back to my original question, why do I want macros in Python? Hiding the wiring, where a function will not do because the argument is your source code. > > Let me provide a candidate answer and rebuttal: > > The real reason I want to do macros in Lisp is that they allow me to > easily write new custom languages. No, that is not a big reason. It is cool that one could do that readily if one stuck to the basic sexpr notation, but my experience to date is that I do not need a wholly new language as long as I can drop into new syntax (c?...) periodically to get what I would have created in a wholly new embedded language. > Which brings me back to my original question: Would a macro facility in > Python really buy me anything? And, in view of Alex's arguments, would > that benefit outweigh the potential significant costs in other areas? Lispniks have not seen code become unreadable because of macros. That is something you all (well, most) are imagining. You are almost positing it as given. And it is simply not so. We have pointed out again and again that macros are no harder to understand than functions or classes, but no one addresses that point. Some say "I want to see all the legal Pythion instructions". Except when it is in a function, I guess. Strangely, quite a few of you have also conceded macros can leverage a language. Well, it seems like we have covered everything pretty thoroughly. Back to RoboCup! -- kenny tilton clinisys, inc http://www.tilton-technology.com/ --------------------------------------------------------------- "Career highlights? I had two. I got an intentional walk from Sandy Koufax and I got out of a rundown against the Mets." -- Bob Uecker From martin at v.loewis.de Sun Aug 3 03:50:26 2003 From: martin at v.loewis.de (Martin v. =?iso-8859-15?q?L=F6wis?=) Date: 03 Aug 2003 09:50:26 +0200 Subject: 2.3 Redhat 9 Tkinter IDLE References: Message-ID: "RT Lange" writes: > im trying to get idle to work and its really getting frustrating > (and from what ive read on other posts i am not alone) > > i think i have to edit the Modules/Setup file but im confused as > to what to uncoment and what to change. No, you don't have to edit Modules/Setup. _tkinter is built automatically if you have the header files installed. > Why does this have to be so difficult? Because you have limited disk space. As a result of that, Redhat decides not to install all header files by default. As a result of that, you have to make an explicit choise as to what header files to install. > Can anyone provide step by step inststructions? Sorry, I don't have Redhat 9, so I don't know what the name of the package is that contains the Tk header files. It probably has the strings "tcl" and "dev" in their name. I also don't know whether you installed the system from CD-ROM, DVD, or via the network, so I can't give precise instructions as to what media to insert into what slot. It would be better if you reported the steps you have been doing, and the problems you see. Regards, Martin From rmunn at pobox.com Tue Aug 12 13:32:43 2003 From: rmunn at pobox.com (Robin Munn) Date: Tue, 12 Aug 2003 17:32:43 GMT Subject: Finding the path to a file References: Message-ID: Todd Johnson wrote: > So basically, I want to know how to find the directory > my script is in, even when it is invoked from another > directory. Any help would be greatly appreciated. Basically, you want to use sys.argv[0] -- but make sure to call os.path.abspath() on it first. Try this: --- begin sample code --- #!/usr/bin/python import os, sys print "sys.argv[0] is", sys.argv[0] print "os.path.abspath(sys.argv[0]) is", os.path.abspath(sys.argv[0]) mypath, myname = os.path.split(os.path.abspath(sys.argv[0])) print "Script name is", myname print "Script path is", mypath ---- end sample code ---- I can run this in a variety of ways and get the same value for mypath: --- begin transcript --- [rmunn at localhost ~/tmp]$ ./test.py sys.argv[0] is ./test.py os.path.abspath(sys.argv[0]) is /home/rmunn/tmp/test.py Script name is test.py Script path is /home/rmunn/tmp [rmunn at localhost ~/tmp]$ python test.py sys.argv[0] is test.py os.path.abspath(sys.argv[0]) is /home/rmunn/tmp/test.py Script name is test.py Script path is /home/rmunn/tmp [rmunn at localhost ~/tmp]$ cd .. [rmunn at localhost ~]$ python tmp/test.py sys.argv[0] is tmp/test.py os.path.abspath(sys.argv[0]) is /home/rmunn/tmp/test.py Script name is test.py Script path is /home/rmunn/tmp [rmunn at localhost ~]$ python /home/rmunn/tmp/test.py sys.argv[0] is /home/rmunn/tmp/test.py os.path.abspath(sys.argv[0]) is /home/rmunn/tmp/test.py Script name is test.py Script path is /home/rmunn/tmp ---- end transcript ---- Hope this helps. -- Robin Munn | http://www.rmunn.com/ | PGP key 0x6AFB6838 -----------------------------+-----------------------+---------------------- "Remember, when it comes to commercial TV, the program is not the product. YOU are the product, and the advertiser is the customer." - Mark W. Schumann From max at alcyone.com Mon Aug 18 18:27:34 2003 From: max at alcyone.com (Erik Max Francis) Date: Mon, 18 Aug 2003 15:27:34 -0700 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: <3F412484.69867AED@alcyone.com> Message-ID: <3F4152D6.2EEF381D@alcyone.com> "Brandon J. Van Every" wrote: > Erik has been in my killfile forever, from other newsgroups. I even > had to > put him back in after letting him out. I thought a year would have > been > enough, but apparently not. There's been at least four of five times where Brandon has claimed to have put me in his killfile; he keeps "forgetting." Not that that is terribly surprising coming from someone who is so fond of telling people about the contents of his killfile. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ I want a martini that could be declared a disaster area. \__/ Capt. Benjamin "Hawkeye" Pierce From mpeuser at web.de Wed Aug 13 08:23:39 2003 From: mpeuser at web.de (Michael Peuser) Date: Wed, 13 Aug 2003 14:23:39 +0200 Subject: Determine file type (binary or text) References: Message-ID: Hi, yes there is more than just Unix in the world ;-) Windows directories have no means to specify their contents type in any way. The approved method is using three-letter extensions, though this rule is not strictly followed (lot of files without extension nowadays!) When I had a similar problem I read 1000 characters, counted the amount of <32 and >255 characters and classified it "binary when this qota exceeded 20%. I have no idea whether it will work good with chinese unicode files or some funny depositories or project files that store uncompressed texts.... KIndly Michael P "Sami Viitanen" schrieb im Newsbeitrag news:v7p_a.1558$k4.32814 at news2.nokia.com... > Works well in Unix but I'm making a script that works on both > Unix and Windows. > > Win doesn't have that 'file -bi' command. > > "bromden" wrote in message > news:bhd559$ku9$1 at absinth.dialog.net.pl... > > > How can I check if a file is binary or text? > > > > >>> import os > > >>> f = os.popen('file -bi test.py', 'r') > > >>> f.read().startswith('text') > > 1 > > > > (btw, f.read() returns 'text/x-java; charset=us-ascii\n') > > > > -- > > bromden[at]gazeta.pl > > > > From anton at vredegoor.doge.nl Mon Aug 11 04:30:23 2003 From: anton at vredegoor.doge.nl (Anton Vredegoor) Date: Mon, 11 Aug 2003 10:30:23 +0200 Subject: Need elegant way to cast four bytes into a long References: <3f33c209$1@news.si.com> Message-ID: "William S. Huizinga" wrote: >I've got an array.array of unsigned char and would like to make a slice >of that array (e.g. a[0:4]) become one long like I would in "C" : > > l = ((unsigned long *) (&a[0]))[0]; > >I have been getting what I want in this sort of manner : > > l = 0L > l = a[0] > l += a[1] << 8 > l += a[2] << 16 > l += a[3] << 24 > >but I think that's too wordy. Is there a more intrinsic and elegant way >to do this? Just for completeness, it's also possible to go back to basic style programming. Anton from string import hexdigits def hexchr(i): return hexdigits[i/16]+hexdigits[i%16] asc = dict([(chr(i), hexchr(i)) for i in range(256)]) def tolong(s): return long(''.join(map(asc.get,s[::-1])),16) def test(): a = '\x01\x02\x03\x04' print tolong(a) if __name__=='__main__': test() From __peter__ at web.de Tue Aug 5 07:36:08 2003 From: __peter__ at web.de (Peter Otten) Date: Tue, 05 Aug 2003 13:36:08 +0200 Subject: Classes in Python References: <14dsivkn40c0grotsti39cgsrde7v03hq4@4ax.com> Message-ID: Wiebke P?tzold wrote: > So I think that something is wrong with line: > vf = vw.filter(PatternFilter("Ge.*")) The PatternFilter class looks OK now, and so does the line you suspect to be wrong. Are you sure there are any records in the database with Nachname containing Ge (and not GE or ge)? The only difference I could spot: - with the function you are looking for Nachname(n), that contain "ra" - with the class you are looking for Nachname(n) that contain "Ge" Being no regular expressions expert, I think that appending ".*" here has no effect for your purpose (If you want Nachname to start with Ge, the expression should be "^Ge"). > But here I get an error: returned exit code 0. What's that? Please cut and paste the exact output. Peter From mcherm at mcherm.com Thu Aug 21 14:46:33 2003 From: mcherm at mcherm.com (Michael Chermside) Date: Thu, 21 Aug 2003 11:46:33 -0700 Subject: Removing language comparisons Message-ID: <1061491593.3f45138984e4b@mcherm.com> A.M. Kuchling writes: > I'm planning to drop this page from python.org because it's so outdated and > no one is around to maintain it. If anyone wants to grab the contents and > turn them into a Wiki page, Done. I've captured everything I thought was useful (just 8 links) at http://www.python.org/cgi-bin/moinmoin/LanguageComparisons. I also added two fully-detailed point-by-point comparisons. Feel free to add more... it's a wiki. -- Michael Chermside From runeb at [remove].diningphilosopher.com Wed Aug 13 05:30:02 2003 From: runeb at [remove].diningphilosopher.com (Rune Braathen) Date: Wed, 13 Aug 2003 11:30:02 +0200 Subject: Python vs. C# In-Reply-To: References: <2259b0e2.0308100616.55b651ca@posting.google.com> <3f36af20@shknews01> Message-ID: Brandon J. Van Every wrote: ( ... ) > I decided that I should do the low level AI stuff in whatever > langauge was appropriate, probably C++. Once I had a more stable, high > level API for what I was doing, then worry about user AI. So now I had no > immediate reason to use Python. Aha, this explains why you have so much time for usenet; you are rebuilding all the time. -- runeb From tdelaney at avaya.com Thu Aug 7 19:47:18 2003 From: tdelaney at avaya.com (Delaney, Timothy C (Timothy)) Date: Fri, 8 Aug 2003 09:47:18 +1000 Subject: FWD: Re: Problem w/ IDLE on Win2000 Message-ID: <338366A6D2E2CA4C9DAEAE652E12A1DE9DFEA0@au3010avexu1.global.avaya.com> > From: Thomas Heller [mailto:theller at python.net] > > If it helps, I'm willing to take over the windows installer - > although I would probably stay with Wise. I've thought about seeing what it would take to produce an NSIS Python installer. But I'm not volunteering... http://nsis.sourceforge.net/ We're looking at moving to NSIS for all our installers at work. Apart from anything else, it works very nicely with source control (have you ever tried merging a Wise installer from 3 branches in clearcase?). Tim Delaney From tjland at iserv.net Sun Aug 24 23:17:59 2003 From: tjland at iserv.net (tjland at iserv.net) Date: Sun, 24 Aug 2003 23:17:59 -0400 (EDT) Subject: Strange tab problem! Message-ID: <1799.68.75.130.96.1061781479.squirrel@webmail.iserv.net> Okay i wrote a small program that allows users to creat book listings featuring copyright date author and title. Now when i display the book listings i get this. Book: testover6 Author: ??? Copyright: 2003 Book: testu6 Author: ??? Copyright: 2003 Okay now after the book title their is supposed to a tab the coding goes like this. for x in title_author.keys(): print "Book: ",x," \tAuthor: ",title_author[x]," \tCopyright:",title_copyright[x] it seems that whenever i go over six characters it adds another tab. Is there a preset field limit to six bytes. What is happening? Thanx in advance. When you see the net take the shot When you miss your shot shoot again When you make your shot you win! Just remember Offense sells tickets But defense wins championships! From Smille at mail.com Thu Aug 14 20:41:18 2003 From: Smille at mail.com (Smille Purusa) Date: Fri, 15 Aug 2003 00:41:18 +0000 Subject: GUI builder for Python References: Message-ID: henry wrote: > Hi, > > Just wondering if there's a good GUI builder for Python. Something like > Visual Tcl, where you just drag and drop objects. > > Not too good with creating user interfaces from code along. > > Thanks You can try boa or pythoncard. Smille From opstad at batnet.com Thu Aug 21 10:25:24 2003 From: opstad at batnet.com (David Opstad) Date: Thu, 21 Aug 2003 07:25:24 -0700 Subject: [OT] Why is it called string? References: <3f44ce77$0$556$b45e6eb0@senator-bedfellow.mit.edu> Message-ID: In article <3f44ce77$0$556$b45e6eb0 at senator-bedfellow.mit.edu>, Brian Kelley wrote: > That being said, what is the programming-centric etymology of "string"? It goes back at least to 1962, because that's when SNOBOL was invented, and the 'S' stands for "String" in that acronym. Dave From tjreedy at udel.edu Fri Aug 29 16:18:40 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 29 Aug 2003 16:18:40 -0400 Subject: Celebrity advice References: <000701c36ce7$a6ff24d0$0c02a8c0@Arts> Message-ID: <0o6dneIqn_m8KNKiU-KYvw@comcast.com> "Cliff Wells" wrote in message news:mailman.1062150716.7297.python-list at python.org... > I'd have to agree with Art on this. ESR's thoughts on guns have little > to do with programming, and unless he likes to use "nra" or "bullet" as > metavariables, his politics would best be omitted from the discussion. I recomment his new book The Art of Unix Programming (text online here http://catb.org/~esr/writings/taoup/) to anyone interested in the topic. Terry J. Reedy From aahz at pythoncraft.com Tue Aug 19 01:13:49 2003 From: aahz at pythoncraft.com (Aahz) Date: 19 Aug 2003 01:13:49 -0400 Subject: What's TOTALLY COMPELLING about good newsreaders? References: <3F41A877.995F9C35@alcyone.com> Message-ID: In article , Ben Finney wrote: > >Brandon accesses comp.lang.python via Usenet, not email. His >X-Newsreader header shows he is using Outlook Express. I don't know of >any newsreaders that can allow you to filter on the person(s) to whom >the current post is responding -- nor any email clients with the >facility, for that matter. > >The "References" header could theoretically allow you get that >information, but it would be expensive to do so for every message, >especially in long-running threads. Supposedly gnus and slrn do that, though. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From anton at vredegoor.doge.nl Thu Aug 21 17:06:47 2003 From: anton at vredegoor.doge.nl (Anton Vredegoor) Date: Thu, 21 Aug 2003 23:06:47 +0200 Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> <6dj2kv8ugkieehs7guh786cl40o5lj6mcs@4ax.com> <599a6555.0308202108.397bb1a0@posting.google.com> <3f61b.24172$zN5.741744@news1.tin.it> Message-ID: Alex Martelli wrote: >Anton Vredegoor wrote: > ... >> tiny chance. Suppose you could make a bet for a dollar with an >> expected reward of a thousand dollars? Statistically it doesn't matter >> whether you get a .999 chance of getting a thousand dollars or a >> .00999 chance of getting a million dollars. > >This assertion is false and absurd. "Statistically", of course, >expected-value is NOT the ONLY thing about any experiment. And >obviously the utility of different sums need not be linear -- it >depends on the individual's target-function, typically influenced >by other non-random sources of income or wealth. Non linear evaluation functions? Other random sources? Seems you're trying to trick me. I did write statistically, which implies a large number of observations. Of course people seldom get to experiment with those kinds of money, but a simple experiment in Python using a random number generator should suffice to prove the concept. [snip tricky example cases] >> Another relevant meme that is running around in this newsgroup is the >> assumption that some people are naturally smarter than other people. >> While I can certainly see the advantage for certain people for keeping >> this illusion going (it's a great way to make money, the market >> doesn't pay for what it gets but for what it thinks it gets) there is >> not a lot of credibility in this argument. > >*FOR A GIVEN TASK* there can be little doubt that different people >do show hugely different levels of ability. Mozart could write >far better music than I ever could -- I can write Python programs >far better than Silvio Berlusconi can. That does not translate into >"naturally smarter" because the "given tasks" are innumerable and >there's no way to measure them all into a single number: it's quite >possible that I'm far more effective than Mozart at the important >task of making and keeping true friends, and/or that Mr Berlusconi >is far more effective than me at the important tasks of embezzling >huge sums of money and avoiding going to jail in consequence (and >THAT is a great way to make money, if you have no scruples). And you're eliminating mr. Berlusconis friends out of the equation? Seems like trick play again to me. Why are there so few famous classic female philosophers or musicians? Surely you're not going to tell me that's just because only the very gifted succeed in becoming famous? >> there are those that first leap and then look. It's fascinating to see >> "look before you leap" being deprecated in favor of "easier to ask >> forgiveness than permission" by the same people that would think twice >> to start programming before being sure to know all the syntax. > >Since I'm the person who intensely used those two monickers to >describe different kinds of error-handling strategies, let me note >that they're NOT intended to generalize. When I court a girl I >make EXTREMELY sure that she's interested in my advances before I >push those advances beyond certain thresholds -- in other words in >such contexts I *DEFINITELY* "look before I leap" rather than choosing >to make inappropriate and unwelcome advances and then have to "ask >forgiveness" if/when rebuffed (and I despise the men who chose the >latter strategy -- a prime cause of "date rape", IMHO). > >And there's nothing "fascinating" in this contrast. The amount of >damage you can infert by putting your hands or mouth where they >SHOULDN'T be just doesn't compare to the (zero) amount of "damage" >which is produced by e.g. an attempted access to x.y raising an >AttributeError which you catch with a try/except. Somehow one has to establish that a certain protocol is supported. However trying to establish a protocol implies supporting the protocol oneself. Perhaps not initiating protocols that one doesn't want to see supported is the best way to go here. Anton From sismex01 at hebmex.com Tue Aug 19 11:51:03 2003 From: sismex01 at hebmex.com (sismex01 at hebmex.com) Date: Tue, 19 Aug 2003 10:51:03 -0500 Subject: wxPython launches DOS shell Message-ID: [matthew.rapoport at accenture.com] > Does anyone know how to avoid getting a DOS shell launched everytime > you run a wxPython script? The shell is used to run Python.exe but it > doesn't look very professional when a black window pops up along with > your GUI. That's what pythonw.exe is for. -gustavo Advertencia:La informacion contenida en este mensaje es confidencial y restringida, por lo tanto esta destinada unicamente para el uso de la persona arriba indicada, se le notifica que esta prohibida la difusion de este mensaje. Si ha recibido este mensaje por error, o si hay problemas en la transmision, favor de comunicarse con el remitente. Gracias. From pu at nodomain.lu Mon Aug 18 18:00:49 2003 From: pu at nodomain.lu (Patrick Useldinger) Date: Tue, 19 Aug 2003 00:00:49 +0200 Subject: What's TOTALLY COMPELLING about Ruby over Python? In-Reply-To: References: <3f412432$1_1@news.vo.lu> Message-ID: <3f414c28$1_1@news.vo.lu> Brandon J. Van Every wrote: > I wonder how large my c.l.p killfile is now? Humour is a sign of intelligence; being able to joke about oneself even more so. Try it! ;-) -- Real e-mail address is 'cHVAdm8ubHU=\n'.decode('base64') Visit my Homepage at http://www.homepages.lu/pu/ From hokiegal99 at hotmail.com Wed Aug 27 22:38:35 2003 From: hokiegal99 at hotmail.com (hokiegal99) Date: Wed, 27 Aug 2003 22:38:35 -0400 Subject: Script Discussion & Critique References: <3F4D31B1.6080802@hotmail.com> <06eqkv4onjh5m4tcbbqkmh8lscaj5niatp@4ax.com> <3F4D4402.3060209@hotmail.com> Message-ID: <3F4D6B2B.7030804@hotmail.com> Sean Ross wrote: > "hokiegal99" wrote in message > news:3F4D4402.3060209 at hotmail.com... > > Here's a some trivial (mostly cosmetic) changes: > > # multi-line string > print """ > ****************************************************** > Three Easy Steps to a Recursive Find and Replace > ****************************************************** > """ > text = raw_input("1. Enter the string that you'd like to find: ") > replacement = raw_input("\n2. What would you like to replace '%s' with: > "%text) > path = raw_input("\n3. Enter the path where the program should run: ") > print > # " " is not required. > > for root, dirs, files in os.walk(path): > for fname in files: > filename = os.path.join(root,fname) > fd = file(filename, 'r') > data = fd.read() > fd.close() > if string.find(data, text) >=1: > data = data.replace(text, replacement) > fd = file(filename, 'w') > fd.write(data) > fd.close() > print "Replacing '%s' with '%s' in '%s'" % (text, replacement, > fname) > > print """ > ********** > Done > ********** > """ > > # Note: I haven't tested the changes. > > Hope that's useful, > Sean > > Yes, that's useful. The newlines saves space as does the print """ command. Thanks!!! From panbru at comcast.net Tue Aug 5 10:59:57 2003 From: panbru at comcast.net (panbru) Date: Tue, 05 Aug 2003 08:59:57 -0600 Subject: Contiguous memory blocks Message-ID: <3F2FC66D.1070000@comcast.net> I'm doing some native code stuff and want to pass continguos memory blocks of data back and forth between Python and C, with the memory blocks modifiable in both realms. What is a good way to do that? As I understand it, "buffer interface" objects (e.g. strings or arrays) won't work because memory is not guaranteed to be continguous. Tim From tayss_temp at yahoo.com Thu Aug 28 23:05:38 2003 From: tayss_temp at yahoo.com (Tayss) Date: 28 Aug 2003 20:05:38 -0700 Subject: OT: Americans love their guns References: Message-ID: <5627c6fa.0308281905.152eb4e4@posting.google.com> "Cliff Wells" wrote in message news:... > I just watched "Bowling for Columbine" last weekend. Interesting watch > if you're interested in the topic. That was a well made documentary, that did not take the easy route in blaming guns for murder. The irony though is that it raised suspicions on the media, but of course this documentary is really part of the media. It steered the audience very strongly at times, and I wish he released the unedited footage of scenes like the surprise interview at the end. From berkleehotmail.com Tue Aug 19 06:54:16 2003 From: berkleehotmail.com (berklee just berklee (@)) Date: Tue, 19 Aug 2003 06:54:16 -0400 Subject: httplib usage for images Message-ID: I have an ASP page which is returning a chart image that's being dynamically generated (by writing to the response object). When I try and access that page with httplib (to download said image), I keep encountering an HTTP1.1 server error. However, I've tried the same URL in Internet Explorer and Mozilla with no problems at all. Is there a possibility that it could be the httplib module causing the error? If so, anyone have a suggested workaround? Thanks, B. From dev-python at smartology.nl Thu Aug 21 09:09:18 2003 From: dev-python at smartology.nl (Remy Cool) Date: Thu, 21 Aug 2003 15:09:18 +0200 Subject: imputils - import problem modules from sys.modules Message-ID: Hello, I've created an archive import class (with the help of importers.py from the python /demo/imputil dir) which imports packages and modules from a dictionary. So far so good. The problem is that every import statement after the code: imputil.ImportManager().install() sys.path.insert(0, DictImporter(archive)) sys.path.insert(0, imputil.BuiltinImporter()) tries to import from the dictionary and doesn't use the modules that were imported before. For example, I would like to use os in a module that's stored in the dictionary. The import os statement tries to import os from the dictionary and does not 'use' the already imported os module that is in the modules list. Is it possible to get access to both, already loaded modules in the modules list and modules in the dictionary? Regards, Remy Cool From trader at terray.com Tue Aug 26 13:36:42 2003 From: trader at terray.com (Trader) Date: 26 Aug 2003 10:36:42 -0700 Subject: Extracting Rich Text data formats from win32clipboard References: Message-ID: Thanks for your help, Neil! Your example code gave me an idea what I should be seeing when the HTML/RTF stuff is working properly. I'd been using a non-IE browser (Firebird) for testing, and it wasn't giving me those results. Thanks for getting me on track! Trader "Neil Hodgson" wrote in message news:... > Trader: > > >>> clipboard_grab() > > FORMAT: 49171 > > FORMAT: 16 > > FORMAT: 7 > > FORMAT: 0 > > Now add in: > > for f in formats: > if f >= 0xC000: > print win32clipboard.GetClipboardFormatName(f) > > Formats above 0xC000 are dynamically registered clipboard types. I get: > > FORMAT: 13 > FORMAT: 49278 > FORMAT: 49245 > FORMAT: 49171 > FORMAT: 16 > FORMAT: 7 > FORMAT: 0 > > HTML Format > Rich Text Format > Ole Private Data > > The HTML has a prologue and then some HTML: > > Version:1.0 > StartHTML:000000195 > EndHTML:000001891 > StartFragment:000001597 > EndFragment:000001710 > StartSelection:000001597 > EndSelection:000001710 > SourceURL:http://sydney.citysearch.com.au/ > > > CitySearch.com.au Australia - Your guide to the city of > Sydney > ... > > The RTF looks normal: > > {\rtf1\ansi\ansicpg-1\deff0\deflang3081{\fonttbl{\f0\froman\fcharset0 Times > New Roman;}{\f1\ftech\fcharset0 Symbol;}{\f2\fswiss\fcharset0 > Arial;}{\f3\fswiss\fcharset0 Courier New;}{\f4\ftech\fcharset0 > Wingdings;}}{\colortbl\red0\green0\blue0;\red0\green0\blue255;\red0\green255 > \blue255;\red0\green255\blue0;\red255\green0\blue255;\red255\green0\blue0;\r > ed255\green255\blue0;\red255\green255\blue255;\ > ... > > Neil From bokr at oz.net Sun Aug 17 15:29:26 2003 From: bokr at oz.net (Bengt Richter) Date: 17 Aug 2003 19:29:26 GMT Subject: Path Problem on W2K? References: <93f5c5e9.0308170927.6e0bdc38@posting.google.com> Message-ID: On 17 Aug 2003 10:27:17 -0700, hokiegal99 at hotmail.com (hokiegal99) wrote: >I installed Python-2.3 into c:\Program Files\Python23 on a new W2K SP4 >computer. When I write a Python script and run it from the command >prompt, I get the following error: > >C:\>python 'name-of-script.py' >'python' is not recognized as an internal or external command, >operable program or batch file. > >Here's what my path contains: > >C:\>path >PATH=C:\WINNT\system32;C:\WINNT;C:\WINNT\System32\Wbem;"C:\Program >Files\Norton >SystemWorks\Norton Ghost\";C:\Program Files\SSH Communications >Security\SSH Secu >re Shell > >Any ideas? I've reinstalled and rebooted several times. Also tried >adding c:\Program Files\Python23 to my path... still get the error. I generally avoid installing in c:\ProgramFiles\anything. The space just creates a nuisance when you want to use the path simply in other contexts than they had in mind. Could be that's happening. If you don't get a simple answer, I would uninstall and then reinstall as c:\python23\... or c:\myInstalls\python23\ etc. I use a separate partition and put it at D:\python23\... Then add ;C:\python23 or whatever you decide (something without embedded spaces ;-) onto the path. ( probably settings>control panel>system>environment>... or similar on your system). If you are in a console window, you will have to restart that, at least, for the path change to show up, if it works like mine. HTH Regards, Bengt Richter From skchim0 at engr.uky.edu Tue Aug 19 22:21:14 2003 From: skchim0 at engr.uky.edu (satish k.chimakurthi) Date: Tue, 19 Aug 2003 22:21:14 -0400 Subject: Import error !! Message-ID: <200308192221.14129.skchim0@engr.uky.edu> Hello all, I am trying to import a module which was generated by a PYTHON-C++ interface generator tool, which failed, and generated the following error : Traceback (innermost last): File "", line 1, in ? ImportError: /home/world0/OVERTURE/Overture.v19/lib/libRapsodi.so: undefined symbol: __as__17ReferenceCountingRC17ReferenceCounting I then, did the following hoping to trace the fault python -v # /usr/lib/python1.5/exceptions.pyc matches /usr/lib/python1.5/exceptions.py import exceptions # precompiled from /usr/lib/python1.5/exceptions.pyc # /usr/lib/python2.2/site.pyc has bad magic 'import site' failed; traceback: File "/usr/lib/python2.2/site.py", line 64 dir = os.path.abspath(os.path.join(*paths)) ^ SyntaxError: invalid syntax Python 1.5.2 (#1, Apr 3 2002, 18:16:26) [GCC 2.96 20000731 (Red Hat Linux 7.2 2 on linux-i386 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam import readline # dynamically loaded from /usr/lib/python1.5/lib-dynload/readline.so I don't understand much from the above. Can someone suggest what this means ?? Sorry if I have overlooked anything Thanks in advance, Regards, SATISH From shane at zope.com Thu Aug 28 08:13:27 2003 From: shane at zope.com (Shane Hathaway) Date: Thu, 28 Aug 2003 08:13:27 -0400 Subject: [Zope-dev] Zope 2.7 running with Stackless 3.0 In-Reply-To: <3F4D44EB.5010500@tismer.com> References: <3F4D44EB.5010500@tismer.com> Message-ID: <3F4DF1E7.1010103@zope.com> On 08/27/2003 07:55 PM, Christian Tismer wrote: > just by chance, I got into the position to try out > Zope 2.7.0 beta 1/2, and since it needs Python 2.2.3 > at least, and Stackless 3.0 was just ported to that, I tried > to build Zope with Stackless 3.0. > > It works very very well! After a few patches to get the includes > right, here the installation instructions. I am in awe. Cool. :-) However, I am also a little confused. As I understand it, Stackless needs all C code to be non-reentrant, i.e. C code must never call back into Python. But Zope has a lot of reentrant code, especially in Acquisition and ZODB. Doesn't that prevent Zope from taking advantage of Stackless continuations? Shane From aleaxit at yahoo.com Sat Aug 16 08:03:53 2003 From: aleaxit at yahoo.com (Alex Martelli) Date: Sat, 16 Aug 2003 14:03:53 +0200 Subject: Style in list comprehensions References: Message-ID: Dave Kuhlman wrote: ... > def func1(x): > return x*3 > def t1(lst): > return [func1(x) for x in lst] > def t2(lst): > result = [] > for x in lst: > result.append(func1(x)) > return result With Python 2.3's timeit.py, I think the performance differences are more easily and reliably measured -- both those stemming directly from using list comprehensions rather than loops of .append calls, and the ones often enabled by a list comprehension's better suitability for "inlining" whatever operations you're performing. To wit: bash-2.05b$ cd /usr/lib/python2.3 bash-2.05b$ python2.3 timeit.py -s'def f1(x): return x*3' \ > 'result=[]' 'for x in range(10000): result.append(f1(x))' 10 loops, best of 3: 3.7e+04 usec per loop bash-2.05b$ python2.3 timeit.py -s'def f1(x): return x*3' \ > 'result=[f1(x) for x in range(10000)]' 10 loops, best of 3: 2.94e+04 usec per loop bash-2.05b$ python2.3 timeit.py -s'def f1(x): return x*3' \ > 'result=[x*3 for x in range(10000)]' 100 loops, best of 3: 1.79e+04 usec per loop In some (rare) bottleneck situations, these performance differences might perhaps be significant. Similarly for good old map...: bash-2.05b$ python2.3 timeit.py -s'def f1(x): return x*3' \ > 'result=map(f1, range(10000))' 100 loops, best of 3: 1.87e+04 usec per loop bash-2.05b$ python2.3 timeit.py -s'def f1(x): return x*3' \ > 'result=map(lambda x:x*3, range(10000))' 100 loops, best of 3: 1.84e+04 usec per loop No "inlining" (as you can see, pseudo-inlining via lambda does not buy you any performance advantage), but if you're stuck in a situation where you just can't inline map may well be faster than list comprehensions -- perhaps significantly so, if this happens to fall right on a performance bottleneck of your program. Finally, in some cases, you can "preallocate" the result list to the length it will have in the end, and then rebind its items one by one, rather than "growing" the result list as you go. When this is feasible, it's often the fastest approach you can possibly use, to wit: bash-2.05b$ python2.3 timeit.py -s'result=10000*[None]' \ > 'for i in range(10000): result[i] = i*3' 100 loops, best of 3: 9.75e+03 usec per loop ...almost twice as fast than the best map or list comprehension, in this specially favourable case. Of course, talking of specially favourable cases, when some time consuming operation DOES represent such a case one might be well advised to keep an eye out for totally different possibilities...: bash-2.05b$ python2.3 timeit.py 'result=range(0,30000,3)' 100 loops, best of 3: 2.22e+03 usec per loop Yes, this IS "cheating" -- but it does produce the same 'result' list as each of the other approaches, and it does so 4 or 5 times faster than the second-best approach (preallocated list, taking some advantage of this being a special case), almost 10 times faster than the best "generalized" approach. Any time you need to produce any kind of arithmetic progression, do consider using just a special-purpose 'range' call, if you care about speed!-) Alex From zanesdad at bellsouth.net Fri Aug 15 00:55:32 2003 From: zanesdad at bellsouth.net (Jeremy Jones) Date: Fri, 15 Aug 2003 00:55:32 -0400 Subject: ANN: munkware In-Reply-To: <20030815005125.51c53963.zanesdad@bellsouth.net> References: <20030815005125.51c53963.zanesdad@bellsouth.net> Message-ID: <20030815005532.20981c80.zanesdad@bellsouth.net> Sorry - I am a doofus. I couldn't get mutt to send out the email, so I copied and pasted into another mail client, but failed to copy my subject line correctly. The project's anme is "munkware" with an "e" and not "munkwar." On Fri, 15 Aug 2003 00:51:25 -0400 Jeremy Jones wrote: > I am happy to announce the creation of Munkware, a brand new project on Sourceforge. > > Munkware is a transactional and persistent queueing system inspired by Queue.Queue() in the Python standard library. The project can be found at: > http://sourceforge.net/projects/munkware/ > > Currently, the SourceForge project homepage doesn't seem to be updating with the index page that I uploaded earlier. Sorry for that. > > Anyhow, feedback is ecstatically welcome. > > Jeremy Jones From bkc at murkworks.com Mon Aug 18 15:40:16 2003 From: bkc at murkworks.com (Brad Clements) Date: Mon, 18 Aug 2003 15:40:16 -0400 Subject: Py2exe for 2.3 also copies python22.dll Message-ID: <3F40F47C.28928.10D294BE@localhost> Here's a "screen shot" I'm running python setup.py -d c:\temp\rose s UMXService I have python 2.2 installed, and 2.3. 2.3 is the 'default' for .py files but it seems that py2exe's setup copies pythonxx.dll from system32, rather than picking the specific version that's needed adding 'Scripts.py2exe\support.py' warning: py2exe: could not parse version number '' No VersionInfo will be created copying d:\python23\DLLs\_sre.pyd -> c:\temp\rose\UMXWIN32SVC copying C:\WINNT\System32\PyWinTypes23.dll -> c:\temp\rose\UMXWIN32SVC copying C:\WINNT\System32\python23.dll -> c:\temp\rose\UMXWIN32SVC copying D:\Python23\lib\site-packages\win32\perfmon.pyd -> c:\temp\rose\UMXWIN32SVC copying D:\Python23\lib\site-packages\win32\win32api.pyd -> c:\temp\rose\UMXWIN32SVC copying C:\WINNT\System32\python22.dll -> c:\temp\rose\UMXWIN32SVC copying D:\Python23\lib\site-packages\win32\win32service.pyd -> c:\temp\rose\UMXWIN32SVC copying D:\Python23\lib\site-packages\win32\win32event.pyd -> c:\temp\rose\UMXWIN32SVC -- Brad Clements, bkc at murkworks.com (315)268-1000 http://www.murkworks.com (315)268-9812 Fax http://www.wecanstopspam.org/ AOL-IM: BKClements From newsgroups at jhrothjr.com Sun Aug 24 20:58:21 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Sun, 24 Aug 2003 20:58:21 -0400 Subject: python gripes survey References: <7s6gkv031b940dsc522pbh5g30q4nj5vd1@4ax.com> Message-ID: "nnes" wrote in message news:d8778a53.0308241450.1a0d6645 at posting.google.com... > Geoff Howland wrote in message news:<7s6gkv031b940dsc522pbh5g30q4nj5vd1 at 4ax.com>... > > On Sat, 23 Aug 2003 15:39:27 GMT, "Ryan Lowe" > > wrote: > > > > Just to point some things out since I started the {} [] thread. I was > > trying to do something hacky, and while I wanted the [].len() type > > calls for my team mates, I never had a problem with the current len() > > and understand the reasoning behind it. [].len() is more uniform, but > > it also changes the requirements for the language in a duplicated > > fashion, since the test for __len__() will always exist as well. > > > > So while I think they may have been reasonable requests, Im not sure > > theyre really pitfalls, and Im not sure they would even work out that > > well on a large scale which is why I wanted to implement it and test > > it out myself. > > > > > > -Geoff Howland > > http://ludumdare.com/ > > Can you post a link to that thread? > > I have never understood why python has [].count() or "".count() but > len([]) and len(""). > > Why not make len, sum, str, repr, etc just methods of the base object > class with specific implementations for different types. Instead of > doing len([]) we could do [].len(). > > This is actually possible already in part. I think you can do > [].__len__(). But I never understood the reasoning behind making these > special __x__() methods instead of doing a plain x() and using it like > obj.x(). > > The only case I can think of, where it would look kind of odd would be > floating points like: > > niceoutput=2.3.str() > > Anyway since Pythonistas are smart, it can not be a wart of the > language and must be some lack in my understanding :) > > awaiting-to-be-enlightened-yours Mostly history. Python doesn't have a standard class that's a base class for everything, although it's moving that way with the object class in 2.2 So while it would have been a nice idea for there to be an object.len() method inherited by all classes, this wasn't (and still isn't) really possible. The __method__ methods are implementation details; they are (mostly) required private methods that are used by the various operators and global functions. The len() global function, for example, calls the __len__() method. I'm not sure what the ramifications of just dumping the relevant global functions into the type and object classes would be. I suspect that, since old code isn't expecting most of them, you'd get a strange mismash of methods that sometimes work, sometimes don't, and sometimes are used for unrelated purposes. John Roth > > Nestor From harry.g.george at boeing.com Wed Aug 13 12:55:19 2003 From: harry.g.george at boeing.com (Harry George) Date: Wed, 13 Aug 2003 16:55:19 GMT Subject: "drop-in" DOM replacement for minidom? References: Message-ID: Paul Miller writes: > We've run into minidom's inabilty to handle large (20+MB) XML files, and > need a replacement that can handle it. Unfortunately, we're pretty > dependent on a DOM, so a pulldom or SAX replacement is likely out of the > question for now. > > Has someone done a more efficient minidom replacement module that we can > just drop in? Preferrably written in C? > > We had a similarly large file, and could not handle it in DOM. It was not a minidom issue. Rather it was the fact that DOM in general takes a lot of memory and that was putting us into swapping. Switching to SAX was a major improvement in mem usage and thus in parse time. Our architecture made moving from DOM to SAX pretty straightforward. We use XML to build our own "neutral representation" of Python classes, and then traverse that for our applications. This is instead of hardcoding DOM (or SAX) calls throughout the applications. If you have the hardcoding approach, you may want to look at the neutral rep approach -- it pays off in many ways. -- harry.g.george at boeing.com 6-6M31 Knowledge Management Phone: (425) 342-5601 From fmm at cca.iac.es Wed Aug 13 23:16:52 2003 From: fmm at cca.iac.es (Francisco Miguel Montenegro Montes) Date: Thu, 14 Aug 2003 04:16:52 +0100 Subject: Error with Python 2.3 as a shared Library Message-ID: <3F3AFF24.6050809@cca.iac.es> Hi, perhaps some of you can help me... I'm installing Python 2.3 (in Linux RedHat 8.0) and I need to build it like a shared library, because I want to interact Python with PostgreSQL. Following the README instructions, I try: ./configure --enable-shared --prefix=/whatever (I'm not root of my system, so I can't use /usr/local/) make make install it seems to be ok, without errors. And when I try : /whatever/bin/python it says: whatever/bin/python error while loading shared libraries: libpython2.3.so.1.0: cannot open shared object file: No such file or directory but this library (libpython2.3.so.1.0 ) is in the whatever/lib directory. What's wrong? Is it something related to the path? How can I tell python where the library is? Or is it not the problem? Thanks. From skip at pobox.com Tue Aug 5 16:09:56 2003 From: skip at pobox.com (Skip Montanaro) Date: Tue, 5 Aug 2003 15:09:56 -0500 Subject: Exploratory query In-Reply-To: References: Message-ID: <16176.3860.721220.302232@montanaro.dyndns.org> >>>>> "Don" == Don Todd writes: Don> In article , Skip Montanaro wrote: >> Don> Would python allow me to run flist and use its output, or would I Don> need to re-write flist? The idea is to keep something on the screen Don> and poll the mailboxes every n seconds and update the display. >> >> You can do this quite easily. Presuming you just want to display flist's >> output for now, but maybe mangle it later, you can probably get away with >> something simple like this: >> >> import time >> import commands >> >> while True: >> status, output = commands.getstatusoutput("flist") >> if status != 0: >> print "flist barfed... exiting" >> # right here you could massage output >> print output >> time.sleep(300) # five minutes >> >> Skip Don> Thanks, Skip! That pretty much does what I want; I modified it to Don> do "flist mailbox1", "flist mailbox2" etc. Also, note that I forgot the break statement in the exit branch. Should have been: if status != 0: print "flist barfed... exiting" break Don> Is there a way to run this in a terminal and have it uptate the new Don> over the old? I'm thinking it would be sweet to run it in Don> tranparent terminal. Perhaps I'll look into using a gui, too. Sure. There are a couple ways to do it. The crude way might just be to put commands.getstatusoutput("clear") at the top of the list. The cleaner way would probably be to use the curses module. I've no experience to make any suggestions, but the curses module docs at http://www.python.org/doc/current/lib/module-curses.html have a link to Andrew Kuchling's "Curses with Python" tutorial. Skip From newsgroups at jhrothjr.com Tue Aug 26 21:54:19 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Tue, 26 Aug 2003 21:54:19 -0400 Subject: String find and replace References: <3F4C04F8.5070401@vt.edu> <3F4C0CC4.20400@hotmail.com> Message-ID: "hokiegal99" wrote in message news:3F4C0CC4.20400 at hotmail.com... > John Roth wrote: > > Are you trying to rename the file? Look under os - Files and Directories > > for the rename() function. It's 6.1.4 in the 2.2.3 docs. > > > > John Roth > > No, I'm trying to find 'this' in files and replace it with 'that' > recursively through a directory. It works, but it doesn't actually > commit the change to the files, it finds 'this' and reports that it > replaced it with 'that', but when I run the scipt again it reports the > same files that it just fixed. Oh. You need to open it again for write and write the changed string back out. The string doesn't have any persistant connection to the file. John Roth > From belred1 at yahoo.com Mon Aug 4 10:08:03 2003 From: belred1 at yahoo.com (Bryan) Date: Mon, 04 Aug 2003 14:08:03 GMT Subject: pyrex error References: <8YPWa.48874$YN5.38312@sccrnsc01> Message-ID: <7NtXa.62774$uu5.6090@sccrnsc04> "Gerhard H?ring" wrote in message news:mailman.1059853685.20382.python-list at python.org... > Bryan wrote: > > [PyRex produces code using staticforward that won't work in the combination Python 2.3/MSVC] > > 1) Please don't top-post. > > 2) The other way to temporarily solve this problem is to use MINGW > instead of MSVC. > > In the PySQLite sources, I added this snippet on top: > > #ifdef _MSC_VER > #define staticforward extern > #endif > > to make it compilable under MSVC/Python 2.3. *After* #include-ing > "Pyhton.h" of course. > > -- Gerhard > i've decided to go with gerhard's approach with one minor modification: #ifdef _MSC_VER #undef staticforward #define staticforward extern #endif this solution is best for me because i want to take the resulting c file and give it to others so they can compile it on other OS's and compilers. why can't this code be placed in the pyrex header? seems like a simple fix. bryan From __peter__ at web.de Fri Aug 29 04:07:20 2003 From: __peter__ at web.de (Peter Otten) Date: Fri, 29 Aug 2003 10:07:20 +0200 Subject: Are lists at least as efficient as dictionaries? References: <781faf41.0308281604.51e48f45@posting.google.com> Message-ID: Narendra C. Tulpule wrote: > If I have a list with 100 elements, each element being a long string, > is it more efficient to maintain it as a dictionary (with a key = a > string from the list and value = None) for the purpose of insertion > and removal? Wild guess: I suppose that both implementations will not significantly affect the overall speed of your application, e.g. if the strings are *really* large (as opposed to the list of *only* 100 elements), reading from disk will take much longer than inserting into the list, even at arbitrary positions. Also, note that no particular order is preserved for the keys in a dictionary. And now for something completely different: >>>> x = ([],) >>>> x[0] += ['something'] > Traceback (most recent call last): > File "", line 1, in ? > TypeError: object doesn't support item assignment += calls the list.__iadd__(self, other) method, which seems to be implemented as def __iadd__(self, other): self.append(other) return self The call of this method succeds, but the following assignment fails, because tuples are immutable. This could only be remedied if all assignments a = a were silently ignored, or, if the += operator would not perform an assignment, which has the disadvantage that it would no longer work for immutables, so that >>> i = 1 >>> i += 1 >>> print i 1 # admittedly faked >>> You could change __iadd__() to def __iadd__(self, other): return self + other but then sane behaviour in one special case comes at the cost of always creating a copy of a potentially large (say more than 100 items :-) list. By the way, one topic per post is always a good idea :-) Peter From bokr at oz.net Mon Aug 4 05:34:16 2003 From: bokr at oz.net (Bengt Richter) Date: 4 Aug 2003 09:34:16 GMT Subject: Changing base class of a big hierarchy References: <873cgjyo2u.fsf@pobox.com> Message-ID: On 03 Aug 2003 12:31:37 +0100, jjl at pobox.com (John J. Lee) wrote: >I'm trying to change a base class of a big class hierarchy. The >hierarchy in question is 4DOM (from PyXML). 4DOM has an FtNode class >that defines __getattr__ and __setattr__ that I need to override. > If FtNode lived in a separate module that was imported, could you import an impostor module which would override subsequent imports? If it's all one big file, I guess that won't work, but maybe it would be a way to factor the problem if you have to do surgery anyway. Maybe base classes should always come from separate modules, and have a convention for precomposing the mix before importing the main app and running that. Just a casual idea, don't know what it'll look like the morning ;-P Regards, Bengt Richter From guettler at thomas-guettler.de Thu Aug 21 06:17:01 2003 From: guettler at thomas-guettler.de (Thomas =?ISO-8859-15?Q?G=FCttler?=) Date: Thu, 21 Aug 2003 12:17:01 +0200 Subject: Regex Question References: Message-ID: Istvan Albert wrote: > Thomas G?ttler wrote: >> Hi! >> >> I want to parse a file that looks like this: >> >> a0001: basbasdb >> asbddsb >> asdbasdb >> abasbd >> a0002: fffff >> ffff >> ffffff >> ffff > >> I think there is a better solution than this, don't you? > It is not clear from what you are saying what are the limitations > for possible key and values. If the ":" character cannot appear > in a key or a value you could do something a lot simpler: > > elems = line.split(":") Thank you for this reply. With re.split() it is the way I like it: regex=re.compile(r'((?:^|\n)\w\d*:)') splits=regex.split(content) thomas From bokr at oz.net Sun Aug 10 00:39:10 2003 From: bokr at oz.net (Bengt Richter) Date: 10 Aug 2003 04:39:10 GMT Subject: crossplatform py2exe - would it be useful? References: <2UyYa.50516$cl3.1586459@news2.tin.it> Message-ID: On Sat, 09 Aug 2003 17:11:57 GMT, Alex Martelli wrote: >Bengt Richter wrote: > ... >> Is there a big difference for you between e.g., >> >> wget /py2exefiedapp.exe >> py2exefiedapp >> >> and >> >> wget /py2exefiedapp.uff >> uffunwrap --launch exefiedapp.uff > >Yes. Specifically, in the first case (on a Unix-like system) I could >interpose a suitable set-userid setting change such as: > > sudo chmod u+s py2exefiedapp > >while in the second case I couldn't. If you know enough to use sudo, I think you would find it trivial to use uffunwrap without auto-launch (i.e., just like an installer or untarrer or unzipper etc.) and do your sudo chmod on whatever you liked. I don't think this is a areal argument against uffunwrap. In fact, by including a cmd/bash/sh/whatever file and launching that instead of the main app, you could have a prompted automated sequence where you might just have to remember the password when prompted (and maybe confirm that, yes, you really mean it ;-) I think there is good reason to minimize the number of times one gives control to .exe's one hasn't very well authenticated. Imagine if all zip files came in the form of .exe's! Wouldn't that make you nervous? Much better IMO to have a single trusted tool that deals with them all as safely as possible. > >Furthermore, my cousin, who has installed no extras at all compared >to what comes with his operating system (and runs an operating system >without 'apt-get', 'urpmi', or similar 'download-on-demand' functionality) >would still be able to take full advantage of the first approach w/o >having to previously install ANY other piece of software; to take >advantage of the second approach, he would have to first download and >install 'uffunwrap', and he just ain't gonna do that. For a one-time thing, I think he *should*, and you should twist his arm, because I think it would result in a safer modus operandi. If the plan for Python is to generate .exe's per se as self-executing distribution containers, (other than the major wise installer distribution files, which have md5's posted) then I really think some considerable thought ought to be expended on making that safe. I have no problem checking md5's, but your cousin might. I would envision uffunwrap to be a small executable that can unwrap,launch, check integrity, and potentially do an automatic autenticity check (though featuritis can cause growth). The packing partner program would be in Python, say uff.py, and be able to package a uff file automatically based on a uff header template edited to specify the requisite file sources on lines inserted following each normal header line (which specifies an included file and where it goes in the unwrapping context). The normal header lines also have text/binary flags and either actual sizes and dates and optional digests, or placeholders for them to be created from specified sources. That way an option to revalidate a new packing with only one file changed can be supported, and only the header line for the new source should be updated. I like short names, so maybe uffunwrap should just be uff.exe and the packer uff.py (which also can have command line options for unpacking and various fancy stuff, since it is python. But if the heart it set on a single .exe for the user experience of having an apparent single executable to run, then as I mentioned previously, it's not that hard, and as you mentioned, there are various .exe builder out there. Indeed, I believe winzip can generate an auto-extracting, auto-launching exe that it can also recognize as a zip archive. Mabe even old pkzip could so something similar. A single exe could be built on tar, tgz, zip or most any archive format as a multi-file container embedded as a single binary resource. I got interested in factoring out the container. The information itself is not that different from a zip or tar file, but I have long been bugged by the IMO severely kludgy way file content types are represented and/or inferred through magic and/or extension hints etc. etc. IMO there ought to be a way of associating file type and other metadata with file data other than through file names and/or extensions or multi/nefarious magic. So I thought, what about introducing a single open-ended magic prefix (postfix or indirection can work too) to data that could do the job. So I got to thinking, maybe a utf-8 header having some general structure that can identify what you'd like to say about the data itself, as opposed the the particular file system container that happens to contain it. My original thought was to have a metadata prefix for single files, and just tweak a file system implementation to keep this data in the first n 512-byte blocks of what would ordinarily be data space, but add an offset into the file definition, so that the header could be skipped transparently for seek and open etc., and look like an ordinary file, but allow some kind of access to the metadata, maybe by opening with an 'm' mode to include the metadata prefix as part of the apparent file. Or maybe to exclude it, so naive opens will see the metadata. To have international content description I thought utf-8 would work. Then it was a matter of choosing a standard format an minimal content for the header. Then I got interested in something else ;-) One reason for a universal text header is that then any file can be opened in a text editor and you should at least see the header. Or just do head -20 some.uff to have a peek. Well, this latest thread came up, and I thought to expand the idea to a segmented file. with a header field for every segment. rfc2822 seemed like a possible format for the header, other than it's supposed to be ascii. I wanted a universal format. So I'm debating utf-8 or -16, and settled on 8 for now, because it's more readable if you see it raw. I thought I could fairly easily implement packing methodology and at first I thought to use the data as embedded/appended .exe resource, but had second thoughts about .exe's. Anyway, it could obviously work as a microinstaller tool as well as a launcher. So what does it have that wise or winzip etc don't have? ++ Potential for really simple and small open source code, both python and C. + support for unicode descriptions etc. (On windows it wouldn't be so hard to send the header to the clipboard for insertion into an editor that can show unicode, e.g., notepad.) + Potential to detect current console encoding and output header accordingly for localized interactive viewing w/o editor (instead of just assuming latin-1 and printing ?'s) + probable pretty good portability for a lot of the unwrapper. ++ platform independence of the .uff format (since endianness, packing, encoding, whatever can all be specified in the utf-8 header, and the rest is binary with specified endianness overall, and segment-wise also describable. To get fast unpacking, I'd probably specify align=512 in the X-UFF-Packing: field. To get really fast unpacking, I might spawn separate threads to copy segments to files in parallel, but that's a future optimization. YM would vary with OS, controllers, etc. Yet another self-unpacking archive is not rocket science or that interesting, but the idea of a universal, file-system-independent, self-describing data format, seems to me the important part. It would be like a universal bar code system for data, and would mean you could do away with file extension associations, and you could see the orignal name for the data in some native language, no matter how many times it had been contained in variously named and dated files -- which are really only container names, not data names (except by unreliable dual name usage). When you make new data, or modify existing data, that's when the data descriptions should change. The file system names in use will only be temporary locator info, and are really separate semantically. Yada, yada ... It wouldn't be that hard to do a single-exe version that can carry the data appended. (Though I'm not 100% sure all .exe formats permit that any more, so it might be a matter of getting some template pieces and faking what the linker does to include a binary resource officially within an exe. But you still need un unpacking function to put python.exe and theapp.py and theextension.dll and config.txt etc. into separate files, and maybe setting environment and path, before kicking off python.exe. You can also buy a copy of winzip to create self-extracting-and-launching launching zip files, I think. UFF is different. For one thing it is platform independent as a container format. Of course executable binary contents destined for different platforms will be different (and BTW the opportunity exists to package several versions selectable at startup, even if just localization strings for a given app). But the basic content is binary or text, and text is stored in the uff file with \n EOLs, unless it is some special encoding, in which case it should be flagged as binary. When it is unwrapped, text destination file is opened with 'w' not 'wb', so it becomes what is normal for the platform. Of course you can ship ascii as binary too. My current concept for packing (as opposed to unwrapping) a uff file, is to drive it using a copy of the header as a template, and just e.g., add in a source: specification after each line that needs a file to pack into the whole, e.g., ... X-UFF-Pkt: 3: t 456 ./myConfig.txt ... source: build2/cfg.dat ... where relative paths are taken re a prefix specified elsewhere, maybe a packing command line option. Anyway, it becomes a simple and I think flexible framework for lots of possibilites. Since you can include whatever you want and launch anything you want from the included -- or from an assumed user environment, since it's like having an internal command line. Speaking of which, you could possibly prefix e.g. #! uffunwrap -x and make the resulting .uff executable. BTW, does sudo chmod u+s get the setuid effect passed on to the interpreting executable? > >That's two strikes against the ".uff" approach and in favour of the >'.exe' one. I can see potential advantages for the '.uff', too, in >widely different scenarios; but these issues indicate to me that it >just can't replace the '.exe'. Therefore, I would suggest you pursue >the .uff as a third-party alternative -- while, on the other hand, >"makers of .exe's" have long been available as third-party alternatives, >and the thrilling aspect of this latest round of ideas is that we seem >to be very close to being able to integrate them in the Python standard >distribution, with a resulting potential for an interesting boost to >Python's popularity. It makes a psychological difference, quite a big >one, whether some functionality is integrated in a standard distribution >or has to be separately downloaded and installed as a third-party add-on. Agreed. But I don't see why uff.exe and uff.py couldn't be standard. Since downloading and running .exe's with a big python payload is attractive to some, why wouldn't downloading a 50k or 100k uff.exe be attractive? ;-) > >"Ability to build directly executable files" would make a big 'selling' >point if it were in Python's standard distribution, while "ability to >wrap files into an archive which still needs a separate utility to >unwrap and run", useful as it may be, just doesn't have the same level >of raw appeal to typical punters currently wondering about Python. Not that hard to take a copy of uff.exe and append the payload and have your directly executable file. I can do it, but I'm not sure it's a good idea. It could be fine for official python stuff, just like the windows installer .exes are fine (but I only say that because I trust the Timbot ;-) And I can check the md5's on those. But in general, I don't see that the executable buys me much except worry. The final executable is prepared by some few actions in any case. I'd rather be having a data-driven tool I trust do it than something I don't wholly trust maybe do it on the fly. Plus if the content really is multiple files, re-executing the original exe may mean loading the whole thing, even if it notices that it doesn't need to repeat its initial disgorging of content. I just don't like the work of first making sure it's really the .exe I intended to get. If I have a separate trusted tool that makes checking and looking easy, I prefer it. It's why I prefer zipped or tgz files to gee-whiz Installshield-prepared or any other installation .exes. You can never trust those buggers to ask you politely whether you would like their latest and greatest to override current file associations (or which), or replace ctl3d.dll with something newer and supposedly better, etc. (Unless, of course, you know the timbot put it together ;-) Regards, Bengt Richter From adalke at mindspring.com Wed Aug 20 04:28:39 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Wed, 20 Aug 2003 08:28:39 GMT Subject: class factory References: <8ad2cfb3.0308200015.4f5bd504@posting.google.com> Message-ID: Nick Keighley: > I'm a Python beginner and I'm would like to write a function that > returns a class (perhaps a tad ambitious...). There's class MyClass: pass def fctn(): return MyClass or you can make the class inside of the function def fctn(): class MyClass: pass return MyClass > I'd like to generate a class on-the-fly from a parameter (a dictionary). > Can Python do this sort of stuff? Does the mean I have to mess with > the dreaded meta-classes? Well, *what* do you want to do? >>> def fctn(d): ... class MyClass: ... def get(self, x): ... return d[x] ... return MyClass ... >>> klass = fctn({"A": 1, 2: "B"}) >>> klass >>> instance = klass() >>> instance.get("A") 1 >>> >>> import types >>> def fctn(name, d): ... return types.ClassType(name, (), d) ... >>> fctn("YoYo", {"around": "world", "walk": "dog"}) >>> klass = _ >>> inst = klass() >>> inst.walk 'dog' >>> Andrew dalke at dalkescientific.com From josh+news at nextyme.net Mon Aug 4 16:29:34 2003 From: josh+news at nextyme.net (Josh Smith) Date: Mon, 04 Aug 2003 15:29:34 -0500 Subject: tarfile and end-of-tape Message-ID: In Python 2.3 there is a new library for handling tarfiles. However, there doesn't seem to be any documentation on handling end-of-tape conditions. I've googled for it and checked the docs, I've even looked into the modules src and all I found was an end of file exception that might do what I'm looking for, but might not. Anyone have any pointers/help? TIA -jbs From bokr at oz.net Fri Aug 8 23:57:38 2003 From: bokr at oz.net (Bengt Richter) Date: 9 Aug 2003 03:57:38 GMT Subject: Recommendation of a parser generator References: Message-ID: On 8 Aug 2003 15:06:33 -0700, fortepianissimo at yahoo.com.tw (Fortepianissimo) wrote: >I'm about to start a new project which will be mostly written in >Python. The first task is to parse some formula-like expressions into >an internal data structure so they can be evaluated. > >This parser would be run extensively in the future, so speed is a >consideration, although at this point to get something up and running >is more important. Also there's a strong possibility of changing the >formula grammar in the future (although the change probably would be >some minor addition/changes). > >I took a look at http://www.python.org/sigs/parser-sig/towards-standard.html, >and went to check BisonGen and found out it's 2-year old now (this is >the fastest one reported in the survey). I checked YAPPS but accordint >to the author it's not designed for efficiency and the parsing >technique has limitations compared to others. Also checked Simpleparse >and found it has to be installed with another toolkit, etc. > >I'd appreciate very much some expert suggestions from the group, like >on the speed, flexibility, portability, and the future prospect (like >to be adopted as the standard etc.). > A while ago now I wrote a specialized parser for HTML using GNU flex and C++ with some minimal STL, and it turned out fast, I thought. Flex is 'way more flexible than a simple tokenizer. There may be something better now, but that's where I'd go (obviously familiarity biases ;-) if I was worried about speed faster than Python. BTW, I wonder if there is a Python parser generator that will take a flex-format grammar as input. Then a transition would be easier. Regards, Bengt Richter From timr at probo.com Fri Aug 22 01:31:24 2003 From: timr at probo.com (Tim Roberts) Date: Thu, 21 Aug 2003 22:31:24 -0700 Subject: wxTreeCtrl not wxListCtrl References: Message-ID: "Krzysztof Kaczkowski" wrote: > >Hello >Im having problem, my class inherit in wxTreeItemData. >(Python2.3 i wxPython2.4.1.2u) That's not the correct way to use wxTreeItemData. You need to send an actual instance of wxTreeItemData to AppendItem, but you can pass an arbitrary Python object as a parameter to the constructor. Then you can use GetData() to fetch that object. Check out the pyTree.py demonstration in the wxPython "demo" directory. -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From calfdog at yahoo.com Sat Aug 2 01:12:22 2003 From: calfdog at yahoo.com (calfdog at yahoo.com) Date: 1 Aug 2003 22:12:22 -0700 Subject: HTML DOM parser? References: <7x7k5y5wfh.fsf_-_@ruckus.brouhaha.com> <4de76ee2.0308011420.14f309f8@posting.google.com> Message-ID: Here is a quick example of using automation with IE # This is a sample of automating IE using Python. from win32com.client import Dispatch import time # wait for IE. def wait(ie): "Given an IE object, wait until the object is ready for input." while ie.Busy: time.sleep(.1) # create the browser window and make it visible ie = Dispatch('InternetExplorer.Application') ie.Visible = 1 ie.Navigate('http://samie.sf.net/simpleform.html') wait(ie) # Some text to add into the text edit box settext1= 'TEST' settext1 = '30' # There is only one form here form = ie.Document.forms[0] # Loop thru the elements and count the elements count = 0 while count < form.elements.length: elements = form.elements[count] # Debug - check variables print elements.attributes print "---------------------" print elements.type print "---------------------" print elements.name # Debug - check variables print settext1 print settext2 # Set text in the text edit box elements.value = settext1 elements.value = settext2 count +=1 # Submit the form form.submit() wait(ie) From frobozz_electric at hotmail.com Sat Aug 30 09:47:13 2003 From: frobozz_electric at hotmail.com (Sean Ross) Date: 30 Aug 2003 13:47:13 GMT Subject: My script is taking 12 hours+ any suggestions? References: <3f4ff9f8$0$23588$5a62ac22@freenews.iinet.net.au> Message-ID: For anyone who is interested, the OP's code can be viewed (with indentation intact) here: http://mail.python.org/pipermail/python-list/2003-August/181365.html (I know, because that was the only place I could view it - no indentation here as well) HTH Sean From theller at python.net Tue Aug 19 04:04:08 2003 From: theller at python.net (Thomas Heller) Date: Tue, 19 Aug 2003 10:04:08 +0200 Subject: XML parser and py2exe References: <84fc4588.0307200721.970b9d9@posting.google.com> <4r1dkuho.fsf@python.net> <84fc4588.0308182226.58063c8a@posting.google.com> Message-ID: pythonguy at Hotpop.com (Anand Pillai) writes: > > Thomas Heller wrote in message news:<4r1dkuho.fsf at python.net>... >> The released version of py2exe isn't able to handle PyXML correctly. >> Although the current CVS version can do it. If you can build it >> yourself, you should try it. >> >> I'm hesitating to make a new release at the moment because I hope to >> solve the Python 2.3 problems, and also I have got a patch from Mark >> Hammond for inproc com servers, which I would like to integrate. > I am sure it would be a lot of fun :-) > > Could you tell me how to get a start on it? > > Thanks > > -Anand The 0.4.1 version contains all this stuff (although services with Python 2.3 are broken a bit). Thomas From maxm at mxm.dk Tue Aug 26 03:49:34 2003 From: maxm at mxm.dk (Max M) Date: Tue, 26 Aug 2003 09:49:34 +0200 Subject: Python Midi package 0.1 Message-ID: <3f4b110d$0$97271$edfadb0f@dread12.news.tele.dk> If anybody is interrested in Midi, but are not on the Python Midi list, I will just notify that I have released the first version of a high level midi package for Python. It is fully functional. It reads and writes midi files! It is *very* easy to write your own event handlers to make midi files do whatever you want them to. It uses the same general ideas as the Sax parser for xml. ######################################### # example #1 """ This prints all note_on events on midi channel 0. It's a short example of creating your own event handler by subclassing the MidiOutStream. """ from MidiOutStream import MidiOutStream from MidiInFile import MidiInFile class NoteOnPrinter(MidiOutStream): "Prints all note_on events on channel 0" def note_on(self, channel=0, note=0x40, velocity=0x40): if channel == 0: print channel, note, velocity, self.rel_time() event_handler = NoteOnPrinter() in_file = 'midiout/minimal_type0.mid' midi_in = MidiInFile(event_handler, in_file) midi_in.read() ######################################### ######################################### # example #2 """ This is an example of how to create the smallest possible type 0 midi file, where all the midi events are in the same track. """ from MidiOutFile import MidiOutFile out_file = 'midiout/minimal_type0.mid' midi = MidiOutFile(out_file) # non optional midi framework midi.header() midi.start_of_track() # musical events midi.update_time(0) midi.note_on(channel=0, note=0x40) midi.update_time(192) midi.note_off(channel=0, note=0x40) # midi framework midi.update_time(0) midi.end_of_track() # not optional! midi.eof() ######################################### It cannot read/write midi ports at this point. So no realtime stuff yet. Get it at: http://www.mxm.dk/technologies/pythonmidi/ regards Max M From jjl at pobox.com Tue Aug 19 08:30:24 2003 From: jjl at pobox.com (John J. Lee) Date: 19 Aug 2003 13:30:24 +0100 Subject: ClientCookie bug (followup) References: <87fzk4sav2.fsf@pobox.com> <87znibzrnx.fsf@pobox.com> <87oeypdh92.fsf@pobox.com> <87k79a25pi.fsf@pobox.com> <84fc4588.0308182207.4c649b93@posting.google.com> Message-ID: <87ada5de3j.fsf@pobox.com> pythonguy at Hotpop.com (Anand Pillai) writes: > I am working on a Cookie module which works *with* urllib2 rather > than on top of it like the existing ClientCookie module. It uses > the Cookie module which comes with python standard library. Interesting, though I don't know quite what you mean. First, if there's a way to work more closely with urllib2 than I've figured out (which is quite possible), this patch needs to know about it, so please post a comment: http://www.python.org/sf/759792 If I understand what you mean, ClientCookie only works 'on top of' rather than 'with' urllib2 to the extent that it currently has to cut-n-paste code to add cookie handling to urllib2. That patch is designed to remove the need to cut-n-paste, which would mean you'd do urllib2.urlopen (after building an OpenerDirector that has an HTTPCookieProcessor from ClientCookie) instead of ClientCookie.urlopen as is required at present. Second: is your module intended to do what ClientCookie does (ie. figure out what cookies should be set and returned, and do so), or is it just a more OO way of getting and returning Cookie headers? I guess the latter? > This module is written as an extension of my Harvestman webcrawler. > The alpha code is ready. We are doing testing right now. Is this the Royal We? ;-) > Details will be posted to my website at > http://members.lycos.co.uk/anandpillai within say 2 weeks or so. [...] Please do post an announcement to c.l.py.announce, or I'll forget. John From anthonyr-at-hotmail-dot-com at nospam.com Wed Aug 27 21:50:52 2003 From: anthonyr-at-hotmail-dot-com at nospam.com (Anthony Roberts) Date: Thu, 28 Aug 2003 01:50:52 GMT Subject: Style question... References: Message-ID: <0ed3b.854759$ro6.16946876@news2.calgary.shaw.ca> > Hi. I tried to do something like that too, early on. (I recall being > frustrated to find I couldn't just alias "end = pass", and use 'end' as a > block delimiter... heh). I didn't actually want to use 'end' (I like > significant whitespace), I just saw a lot of posts with complaints about > "no-block-delimiter", and I thought, I wonder if you can make one. Well, you > can (of course), but not like that. > > Anyway. I think the suggested idiom for people who must have a visible block > delimiter is "# end ". If you use this, I think emacs can "figure > it out" (I don't know, I don't use emacs, but I think pymode can handle > this), and you can also use Tools/scripts/pindent.py, if you like. My emacs can't handle it... I think I'm going to subject myself to a bit more of the Python way to see if I change my mind. From sjmachin at lexicon.net Tue Aug 5 20:33:46 2003 From: sjmachin at lexicon.net (John Machin) Date: 5 Aug 2003 17:33:46 -0700 Subject: How do I get a reference to a KEY value of a dictionary? References: <645db655.0307311636.71923378@posting.google.com> Message-ID: aahz at pythoncraft.com (Aahz) wrote in message news:... > In article , > Andy C wrote: > > > >OK, you're right -- I assumed that the key and value were duplicated, > >but that's not the case. I don't know why I thought that, maybe since > >the key must be immutable and the value is mutable. So I guess having > >a dictionary of the form { 'A': 'A', 'B': 'B' } is not as stupid as it > >first seems, since only a reference is stored. But still I wonder why > >the language doesn't have a facility for getting a reference to the key > >value in constant time. Apparently someone did it by modifying the C > >source for the dictionary to add a ref_key() accessor. It seems like > >it would be useful quite often. > > Well, you're the first person I recall caring about this specific issue. > Of course, general caching issues come up quite frequently. All the > people I've seen wanting to use intern() come at it from a performance > rather than memory perspective, for which a dict would be no use. ;-) Human recall can be defective, or input-deficient. I say again: Google("intern-like memory saver") (in this news group). As I said in that thread, when you run out of physical memory and you start to access your swapfile, you have a performance problem. As far as a dict being of no use, in my case I *already* have a dict, which is used for frequency counting, and the algorithm being used wants to maintain all of its data in memory as well. Thus being able to get a reference to the frequency dict key and store that in the data structure is a major win. These days I have an extension which merely subclasses dict to add on a key reference method and an increment method which does something like: def increment(self, key): if key in self: self[key] += 1 else: self[key] = 1 Regards, "someone" From eppstein at ics.uci.edu Tue Aug 12 16:52:06 2003 From: eppstein at ics.uci.edu (David Eppstein) Date: Tue, 12 Aug 2003 13:52:06 -0700 Subject: Python should try to displace Java References: <7pchjvkldv6li5n80p5ra6n33sa6ainut4@4ax.com> Message-ID: In article , "Brandon J. Van Every" wrote: > I see. So when confronted with data that contradicts your Python world > view, you change from "that's not true" to "who cares?" Contemplate it > later, when you've gotten over your first moments of denial. Ok. I agree with everyone else who's already said it. He's a troll. -- David Eppstein http://www.ics.uci.edu/~eppstein/ Univ. of California, Irvine, School of Information & Computer Science From jacek.generowicz at cern.ch Sun Aug 24 05:46:13 2003 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 24 Aug 2003 11:46:13 +0200 Subject: macro FAQ References: <33803989.0308240058.2878a349@posting.google.com> Message-ID: tebeka at cs.bgu.ac.il (Miki Tebeka) writes: > My personal favorites are the anaphoric macros (aif ...) Though, you do realize that these are buggy, in terms of their interaction with the package system :-) From gcash at cfl.rr.com Sat Aug 30 20:57:10 2003 From: gcash at cfl.rr.com (gcash) Date: Sun, 31 Aug 2003 00:57:10 GMT Subject: win32: disappearing IE attributes Message-ID: I'm having problems with some attributes in Internet Explorer. I'm trying to figure out how to set things up so I don't have to do my own event loop even though I'm using DispatchWithEvents() The reason why is that I'm doing lots of "looking at the IE Document object then poking IE" processing. Specifically I'm trying to implement an IE "object" that you can use to write "macro" scripts to do long and boring point'n'click routines in Oracle Portal. One of the reasons I need to use DispatchWithEvents() is to grab the OnNewWindow2 event and get a reference to any new windows that get opened either by javascript or targeted links. Otherwise I'd not use events, which releases you from needing to pump events. I've read "Python Programming on Win32" (and tried really hard to grok Appendix D) and googled until they threatened to block my IP address. example #1 import time import pythoncom as pc import win32com.client as wc class EventsClass: pass ie=wc.DispatchWithEvents('InternetExplorer.Application.1', EventsClass) ie.Visible=1 ie.Navigate('http://www.webexpressions.com/how-to/examples/frames/frame4.htm') while ie.ReadyState != 4: time.sleep(0.25) pc.PumpWaitingMessages() print ie.Document.frames print ie.Document.frames.length for i in range(ie.Document.frames.length): print ie.Document.frames[i].name print ie.Document.parentWindow while 1: time.sleep(0.25) pc.PumpWaitingMessages() OK, you run this and it prints: [object] 3 menu header main [object] This is ok except for the event loop. So experimented with sys.coinit_flags, which does get rid of the need to pump events, but then the "parentWindow" and "frames" attributes no longer work!!! (the "frames" collection is the IE instances (I think) for each of the frame subwindows, each with their own Document objects, etc) example #2 import sys sys.coinit_flags = 0 import time import win32com.client as wc class EventsClass: pass ie=wc.DispatchWithEvents('InternetExplorer.Application.1', EventsClass) ie.Visible=1 ie.Navigate('http://www.webexpressions.com/how-to/examples/frames/frame4.htm') while ie.ReadyState != 4: time.sleep(0.25) print ie.Document.frames print ie.Document.frames.length for i in range(ie.Document.frames.length): print ie.Document.frames[i].name print ie.Document.parentWindow Traceback (most recent call last): File "C:\example2.py", line 15, in ? print ie.Document.frames File "C:\PROGRA~1\PYTHON\lib\site-packages\win32com\client\dynamic.py", line 4 54, in __getattr__ raise pythoncom.com_error, details pywintypes.com_error: (-2147467262, 'No such interface supported', None, None) >>> Why is this? What's going on here? -gc -- Windows users [are like] people stuck in abusive relationships. They get beat up over and over again, but they won't leave. -- Steve VanDevender (alt.sysadmin.recovery) From aahz at pythoncraft.com Sun Aug 3 14:32:04 2003 From: aahz at pythoncraft.com (Aahz) Date: 3 Aug 2003 14:32:04 -0400 Subject: time, calendar, datetime, etc References: Message-ID: In article , Andrew Dalke wrote: > >Any suggestions for a decent usenet reader for OS X? Pick any standard Unix reader: trn3.6, trn4, slrn, tin, pine, gnus, ... -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From anthony_barker at hotmail.com Fri Aug 1 12:33:25 2003 From: anthony_barker at hotmail.com (Anthony_Barker) Date: 1 Aug 2003 09:33:25 -0700 Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> Message-ID: <899f842.0308010833.129bc1d1@posting.google.com> > > What to you think python largest compromises are? > > > > The three that come to my mind are significant whitespace, dynamic > > typing, and that it is interpreted - not compiled. These three put > > python under fire and cause some large projects to move off python or > > relegate it to prototyping. > > I don't view any of these as "compromises". That word suggests that > something was conceded, or that an intermediate position between two > extremes was chosen to appease. I don't think that either sense really > applies to these features. > > The three items that you listed are merely design choices. While arguments > over them are continuous, two of the design choices (interpreter, dynamic > typing) are consistent with Python's intended use as a language which > excels at rapid prototyping. The third (white space) is merely a stylistic > choice which is designed to encourage readable programs. > > "Compromises" in language design occur usually when a committee tries to > standardize a language, and each has differing views about how the language > should be used. While this occurs somewhat in Python, other languages > have suffered more mightily from this particular disorder. > > Mark Excellent points - you are correct the ones I listed are design choices. Some people could be interpreted them as design "compromises". The kind of people who would like to use the same tool for all problems. From shalehperry at comcast.net Sun Aug 10 23:44:42 2003 From: shalehperry at comcast.net (Sean 'Shaleh' Perry) Date: Sun, 10 Aug 2003 20:44:42 -0700 Subject: python spam filter: random words? In-Reply-To: References: Message-ID: <200308102044.42253.shalehperry@comcast.net> On Sunday 10 August 2003 18:28, Ben Finney wrote: > What I'm seeing now is spam with words taken straight from the "likely > good" word lists of Bayesian filters :-) > this was recently discussed on the spambayes list (the nifty Python implementation of Paul Graham's ideas). Apparently there are not enough uses of the word to make it statistically interesting so spambayes ignores it. Or something like that. See the thread there for full details. From skip at pobox.com Tue Aug 19 11:17:23 2003 From: skip at pobox.com (Skip Montanaro) Date: Tue, 19 Aug 2003 10:17:23 -0500 Subject: An advertising message from a Microsoft agent In-Reply-To: References: <3F403078.3010006@sympatico.ca> Message-ID: <16194.16259.915249.366277@montanaro.dyndns.org> Nick> "Colin J. Williams" writes: >> microsoft.ca/vs2003launch Experience a more productive toolset - Nick> At first I thought it read "Experience a more productive toilet", Nick> which is probably just as inaccurate, but more appropriate. I don't know. I've never experienced a toilet that produced anything under normal circumstances. Where I live, toilets are generally consumers. Skip From pdfernhout at kurtz-fernhout.com Fri Aug 29 14:43:37 2003 From: pdfernhout at kurtz-fernhout.com (Paul D. Fernhout) Date: Fri, 29 Aug 2003 14:43:37 -0400 Subject: Object Database (ODBMS) for Python In-Reply-To: References: <1DAECE9E8F34E04AA0E5699AF7D9FF090708D440@stpmsg00.corp.fairisaac.com> <3f4f7af6_3@corp.newsgroups.com> Message-ID: <3f4f9e88_3@corp.newsgroups.com> Patrick K. O'Brien wrote: > Let me start by saying I'd love to cooperate, even if I am > competitive by nature. ;-) Nothing like a good controversy to get people paying attention. :-) > This API looks rather verbose to me. I think mine would look like: >>>> t = tx.Create('User', name='Sir Galahad') user = db.execute(t) I think your notion of transactions is growing on me. :-) I can see how you can generalize this to construct a transaction in a view of a database, querying on DB + T1 + T2 etc. while they are uncommitted and then commit them all (perhaps resolving multiuser multitransaction issues on commits). Kind of neat concept, I'll have to consider for some version of the Pointrel System. I think it is the special syntax of: tx.Update(u1, name='Joe') or: tx.Create('User', name='Sir Galahad') which I am recoiling some from. I think part of this comes from thinking as a transaction as something that encloses other changes, as opposed to something which is changed. Thus my discomfort at requesting services from a transaction other than commit or abandon. I'm not saying maybe I couldn't grow to love tx.Update(), just that it seems awkward at first compared to what I am used to, as well compared to making operations on a database itself after having told the database to begin a transaction. I'm also left wondering what the read value of the "name" field is when accessed directly as "u1.name" after doing the "wx.Update()" and before doing the "db.execute()". [By the way, pickly, picky, and I fall down on it too, but you use different capitalizations for those two functions.] So is it that in PyPerSyst there appears to be one way to access information (directly through the object using Python object attribute access dot syntax) [not sure about database queries?] and another way to change objects -- using tx.XYZ()? This mixing of mindsets could be confusing (especially within an object that changes its own values internally). Using tx.Update also becomes an issue of how to convert existing code to persistant code. Mind you, the Pointrel System can't do this transparently either, but it doesn't try to do it at all. The Pointrel System requires both looking up a value and storing it to use a different syntax. Is it just a matter of aesthetics about whether it is better to have the whole approach be unfamiliar or whether it is better to have only half of it be unfamiliar? Or is there something more here, some violation of programmer expectations? [See below.] > And unique ids (immutable, btw) are assigned by PyPerSyst: >>>> user.oid > 42 Being competetive here :-) I would love to know if you have a good approach for making them globally unique across all possible users of all PyPerSyst repositories for all time. The Pointrel has an approach to handle this (I don't say it will always work, or is efficient, but it tries). :-) Feel free to raid that code (BSDish license, see license.txt), but that issue may have other deeper implications for your system. > And you can still access attributes directly, you just can't change > them outside of a transaction: > > >>>> user.name > > 'Sir Galahad' > > And the generic Update transaction is equally simple: > > >>>> t = tx.Update(user, name='Brian') db.execute(t) user.name > 'Brian' I know one rule of user interface design (not nexceesarily API of course) is that familiar elements should act familiar (i.e. a drop down list should not launch a dialog window on drop down) and that if you are going to experiment it should look very different so expectations are not violated. The issue here is in part that when you can reference "u1.name" and then "u1.name = 'Joe'" generates an exception (instead of automatically making an implict transaction), some user expectation of API symmetry may be violated... Also, on another issue, it seems like the persistant classes need to derive from a special class and define their persistant features in a special wy, i.e. class Realm(Entity): _attrSpec = [ 'name', ] etc. Again, this is going somewhat towards Python language integration yet not all the way. While I'd certainly agree your version is more concise than what I posted first (just an example of a system that does not attempt to use Python language features), later in the email (perhaps you'll get to it in your next reply) was the simpler: import persistanceSystem import * foo = MyClass() PersistanceSystem_Wrap(foo) # the following defaults to a transaction foo.x = 10 # this makes a two change transaction PersistanceSystem_StartTransaction() foo.y = 20 foo.z = 20 foo.info = "I am a 3D Point" PersistanceSystem_EndTransaction() That approach does not violate any symmetry expectations by users -- you can assign and retrieve values just like always. >> Granted, the Pointrel System is essentially a single user single >> transaction system at the core. It (in theory, subject to bugs) >> supports atomicity (transactions), isolation (locking) and >> durability (logging&recovery). It only supports consistency by how >> applications use transactions as opposed to explicit constraints or >> rules maintained by the database, so one could argue it fails the >> ACID test there. (Although would any typical ODBMS pass consistency >> without extra code support? Does PyPerSyst have this as the >> database level?) > > > PyPerSyst can persist *any* picklable object graph. Are the graphs stand alone can they reference other previously persisted Python objects (not derived from "Root" or "Entity")? > But it also comes with an Entity class and a Root class (that > understands Entity classes) that provides additional functionality, > such as alternate indexes, referential integrity, instance > validation, etc. I guess I need to learn more about when these are better handled by the persistance system as opposed to the applications that use it. > I don't mind a friendly challenge. I'm just surprised that the bulk > of this thread is debating an API that has barely seen the light of > day, and that I consider to be drop-dead simple. I guess I need to > get a demo app created soon, just to put this to rest. Or at least > make sure we're all debating about the same thing. ;-) Good point. I think the issue is that with the other systems out there (MySQL, ZODB, etc.) it seems like a new system has to offer something really new (speed, footprint, simplicity, robustness, documentation :-) etc.). Presumably a very transaparent API for persistance is still needed for an ODBMS which is Python friendly? (Does ZODB do any of this?) If I need to write any extra code at all for an object to be persistant, or derive from a specialized class, I could just derive from a class that knows how to use SQL to store pickled fields. Obviously, PyPerSyst may have many wonderful features (not having used it yet) which make it worth it to do a special derivation or write special code, but it just seems like it would have language transparency too. But, I haven't tried to do that in Python, so maybe it's not possible. > Right now we're debating an API that nobody on this thread has really > seen or used, other than me. The other thing I can say is that, > imo, the way you interact with persistent class instances is not the > same way you interact with regular class instances. Not if you value > the integrity and reliability of your data. And trying to make it > appear so is a disservice. I know everyone seems to think > transparent persistence is the holy grail, but I've come to think > otherwise. I think this is the core of the question of this part of the thread. You wrote "I've come to think otherwise". I'd be curious to hear more on any use cases or examples on why transaparency is not so compatible with reliability etc. I frankly don't know. I just don't see them being mutually exclusive, especially based on what I have read of Smalltalk systems that do persistance using proxies. But again, Smalltalk has "become:" which can essentially swap any arbitray instance and a proxy, thus making it easy to suddenly start using a proxy for a previously used instance and have all previous references point to the proxy. Maybe Python need's become? I could use it elsewhere. Maybe it has it and I never noticed? > Unfortunately, I don't have time to fully elaborate my position. But > you don't have to agree with me on this point. PyPerSyst is very > modular, and there implementations of transparent proxies in the > PyPerSyst CVS sandbox that some other developers on the team have > written. So it can be done. OK. Thanks for the reply. --Paul Fernhout http://www.pointrel.org -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! -----== Over 100,000 Newsgroups - 19 Different Servers! =----- From BjornPettersen at fairisaac.com Wed Aug 27 03:02:14 2003 From: BjornPettersen at fairisaac.com (Pettersen, Bjorn S) Date: Wed, 27 Aug 2003 02:02:14 -0500 Subject: sending a byte on a socket Message-ID: <1DAECE9E8F34E04AA0E5699AF7D9FF0906BE6911@stpmsg00.corp.fairisaac.com> > From: Daniel Timothy Bentley [mailto:dbentley at stanford.edu] > > Slamming my head against what should be an easy problem: > > How do I send a byte across an open, connected socket? > > Do I have to implement my own type that implements some > method a string > normally does? > > Or is there some hidden encoding that will let me turn a byte into a > string? > > This is surely a simple question for anyone who remembers the answer. A one character string is a byte... byteString = chr(byte) hth, -- bjorn From afriere at yahoo.co.uk Mon Aug 4 22:22:12 2003 From: afriere at yahoo.co.uk (Asun Friere) Date: 4 Aug 2003 19:22:12 -0700 Subject: IDLE function 'tooltips' References: <38ec68a6.0308032215.2db836c0@posting.google.com> <45e6545c.0308040307.49eb580c@posting.google.com> Message-ID: <38ec68a6.0308041822.f275c0a@posting.google.com> unendliche at hanmail.net (Seo Sanghyeon) wrote in message news:<45e6545c.0308040307.49eb580c at posting.google.com>... > You can turn it off by editing IDLE's extension config file. In case of > Python 2.3 on Windows XP, make a file named "config-extensions.cfg" under > .idlerc directory, which would be under your home directory. And write: > > [CallTips] > enable = 0 Thanks a tonne! I'm not an IDLE user (my usual 'IDE' is 3 terminal windows, one with the intepreter running, one with vi running, and the other simply at the shell), but I thought I would check it out. It's kind of handy when there are longer functions you want to write out (and might not get right the first time), but you don't necessarily need to commit them to file. It was a hassle having to keep my eyes closed while I supplied arguments to functions though. Just seeing the call tip instantly made me forget what I was about to write. (And I'm not even a blonde!) Though it would be a nice feature on the occasions you are using an unfamiliar function. I don't use Windows, but I found 'config-extensions.def' in the the 'idelib' directory and made the change there. Just knowing that they are called 'CallTips' was a great help. > It would be nice to make this configurable in the configuration dialog. > Perhaps you must submit this one as a feature request? Its so obvious a candidate for a configuration dialog, I don't really think such a request would be necessary ;) Thanks again. From usenet_spam at janc.invalid Mon Aug 25 23:46:41 2003 From: usenet_spam at janc.invalid (JanC) Date: Tue, 26 Aug 2003 03:46:41 GMT Subject: Indentation question References: Message-ID: Christos "TZOTZIOY" Georgiou schreef: >>A lot of editors use the method of: >> >>1. Select lines of text >>2. Press TAB or SHIFT+TAB to change indentation out or in >>respectively. > >>I dont know about those editors though. > > This works for PythonWin AFAIK PythonWin uses the Scintilla editor component? This should (could?) work with all other Scintilla-based editors too: SciTE, pyCrust, Eric3, Wing IDE, Boa Constructor, Black Adder, etc. -- JanC "Be strict when sending and tolerant when receiving." RFC 1958 - Architectural Principles of the Internet - section 3.9 From adalke at mindspring.com Mon Aug 18 05:21:17 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Mon, 18 Aug 2003 03:21:17 -0600 Subject: What's better about Rattlesnakes than Pythons? References: <8e482ba2.0308171939.7de4a288@posting.google.com> Message-ID: Brandon J. Van Every: > If > you want to live in a desert, and you want to hear your pet easily, you're > better off with a rattlesnake. So I live in a desert. I recently involuntarily acquired some mouse housemates, which I want to get rid of (and are keeping me up late tonight because I can hear the occasional rustle.) Would Rattlesnake or Python be better at de-mousing my house? Do either come with an IDE? (Infestation Devouring Engine) Do either need a lot of support? Are there books on the topic? Blah. I'm up too late to make even my normal medium quality quips. Tomorrow it'll be trap shopping day. Again. Caught two already in glue traps. Andrew dalke at dalkescientific.com From bernd.lueth_no_spam_ at heidelberg.com Thu Aug 7 04:47:27 2003 From: bernd.lueth_no_spam_ at heidelberg.com (Bernd Lueth) Date: Thu, 7 Aug 2003 10:47:27 +0200 Subject: newbee : wxPython Message-ID: <1060246052.783343@wienet00038.ceu.heidelberg.com> Dear Group, I've tried to use wxDir / wxFile ( read about them in the wxwindows docs coming with the wxPython distribution ) but somehow I'm not able to find out how to import these classe(s). Any help would be greatly appreciated. Regards, Bernd From mis6 at pitt.edu Fri Aug 1 12:59:30 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 1 Aug 2003 09:59:30 -0700 Subject: How do you do unittest? References: Message-ID: <2259b0e2.0308010859.ff83228@posting.google.com> hwlgw at hotmail.com (Will Stuyvesant) wrote in message news:... > I have a unittest testfile like this: > > ----------------------- test_mod.py --------------------- > import sys > sys.path.append('..') > import unittest > import mod > > class Test_rmlutils(unittest.TestCase): > > def testNormalCase(self): > self.assertEqual(.... > > > if __name__ == '__main__': > unittest.main() > --------------------------------------------------------- > > It is exactly the same as example 17-2 in "Python in a > Nutshell" (PiaN), except for the first two lines. To > quote PiaN: > "...name the test module...with a prefix such as 'test_', > and put it in a subdirectory named 'test' of the directory > where you keep the sources." > > PiaN did not mention the ugly sys.path.append('..') trick > I had to use when following its advice. I need to use it > because mod.py is in the directory above the 'test' > directory. > > To run a test from the source directory I have to change > to the 'test' directory and run test_mod.py there from the > commandline. Okay, I can do that from a batchfile: > > ----------------------- test.bat ------------------------ > cd test > test_mod.py > cd .. > --------------------------------------------------------- > > But: I would like to get rid of the need for > sys.append('..') and I don't see a nice way to do that, do > you? Maybe something from a Python script instead of a > DOS script...I am thinking about importing sys there and > then doing some advanced unittest function like > 'runsuite(blah, foo)' but I am still reading the unittest > docs and there must be somebody who did this before? > > I guess the author of PiaN does not use a 'test' subdirectory > himself, as it is now the example 17-2 does only work in the > source directory. It is interesting that I had a similar issue with doctest, and I was forced to add >>> import sys; sys.path.append('.') to my tests. Quite ugly and at the end I wrote a script that did this automatically. I would be curious to know what's the origin of this path issue. Michele From johng2001 at rediffmail.com Tue Aug 12 04:02:07 2003 From: johng2001 at rediffmail.com (John) Date: 12 Aug 2003 01:02:07 -0700 Subject: Python vs. C# References: Message-ID: > I've used Python for most of my university projects so far (at least > where I could choose what to use), and I've had professors look at me > asking why I chose "an outsider" like Python over languages (considered > to be "stronger") such as C++ and SML (whatever...). > They only asked until they had a look at the code I had produced. :) Likewise. And I actually succeeded in getting several people interested. I love Python. But I love C# just as much and it is hard to say which one I love better. No too long ago, I had to create a tool for an information retrieval project. I needed RegEx, GUI, Containers and Database features. And I needed to make this fast. First I looked at Delphi. It had by far the BEST GUI framework. Nothing else even comes close for GUI RAD. In most cases, I just need to go a web site like www.torry.net and simply pick from a choice of open source components. BUT it did not have RegEx. Sure there was a lib or 2 out there but nothing standard. Same story with containers. Then I started with Python. Python had everything I needed. But my app was GUI rich and it was taking too long to layout the interface. Even with Boa Contructor, it still was taking a while. I had already finished writing most of the classes for the app. I switched to C#. Surprise. It took me hardly any time to port the Python code to it. For everything I needed from Python, I had direct analogues in C# (at least in the context of my app). And I finally wrapped everything up quite quickly. I enjoyed C# as much I enjoyed Python. Of course, the user was quite dismayed when I told him about the 28 MB of dependencies. But the software did exactly what it was expected to. As for static typing, that never slows me down. What makes C++ slower to program in not declaring types. It's the memory details to watch, complex developmental cycles (not just compile time), lack of quick libraries (batteries included) that we get with languages like Perl and Python etc. What enhanced my C# experience has a lot to do with mature tools than with the language per se. The VS2003 IDE is far more complete than PythonWin and Boa. Code Completion, Help integration for example is far more mature and often means I rarely have to refer to the docs. The standard library is fantastic as well. MS finally made a developmental tool that is hard to point fingers at. Personally I would like to see Python in a .NET environment. Not some silly IDE add-in like Visual Python. One comment in this thread was that Python's dynamic typing makes it difficult to port it to .NET. But Perl is dynamically typed too. And ActiveState has a feasible .NET language with Perl. What gives for Python? I don't know much about the language internals but I believe true integration of Python into VS will do it a world of good. Adding onto "what C# can do that Python can't?", I am now developing an app for the PocketPC with the Compact Framework in C#. The app is every bit as professional as an experienced programmer might have developed with eVC. And I was able to do it in a fraction of time of it might have taken with C++ and MFC and this is my FIRST PocketPC app. Python cannot do that at this point of time. Similarly ASP.NET like development experience is hard to get from Python at this point. Yes! There are several webapp frameworks for Python and then there is Zope. But ASP.NET is something else and suits certain kind of web apps quite well (Though Zope is way to go for CMS). I am sure Python community will catch up eventually to this paradigm but for now it doesn't. From mwh at python.net Wed Aug 20 06:21:27 2003 From: mwh at python.net (Michael Hudson) Date: Wed, 20 Aug 2003 10:21:27 GMT Subject: Problem with garbage collection (sort of) References: <246a4e07.0308180608.2b8d685a@posting.google.com> <246a4e07.0308200126.76a3dc78@posting.google.com> Message-ID: <7h3u18c4oo2.fsf@pc150.maths.bris.ac.uk> frank at chagford.com (Frank Millman) writes: > Thanks for all the replies - I have learned a lot. It seems that this > whole thing is not a problem at all. [...] > Many thanks to all. Glad to be of help! Cheers, mwh -- I'm all for this proposal, but I'm afraid their may be some confusion with proto-PEP 7334(Romansch Numerals) and PEP 2/14 (Romantic numerals), not to mention PEPS 3.95/# (Romaine Minerals) and 5/$1 (Ramen noodles). -- rzed comments on PEP 313 on c.l.py From prouleau001 at sympatico.ca Sat Aug 23 17:00:02 2003 From: prouleau001 at sympatico.ca (Pierre Rouleau) Date: Sat, 23 Aug 2003 17:00:02 -0400 Subject: Where is sys.path set? Message-ID: I can't remember where/how sys.path is set (aside from the automatically loaded site.py) and i get a strange entry in it. Can anyone remind me where/how to control sys.path on a Win32 machine (i'm running XP on the one where the issue arises). I can't figure out why the 'C:\WINDOWS\System32\python23.zip' entry is inside sys.path. That file/dir does not exist on the disk. Could a failing (crashing) Pythonwin installation caused that? Here is what I have: [Shell buffer started: python] Python 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> for n in sys.path: ... print n ... C:\dev\python C:\WINDOWS\System32\python23.zip C:\Python23\lib\site-packages\Pythonwin C:\Python23\lib\site-packages\win32 C:\Python23\lib\site-packages\win32\lib C:\Python23\lib\site-packages c:\python23\DLLs c:\python23\lib c:\python23\lib\plat-win c:\python23\lib\lib-tk c:\python23 c:\python23\lib\site-packages\Numeric >>> Thanks /Pierre From mwh at python.net Wed Aug 27 14:30:01 2003 From: mwh at python.net (Michael Hudson) Date: Wed, 27 Aug 2003 18:30:01 GMT Subject: Replacement for rexec/Bastion? References: Message-ID: <7h31xv76jnq.fsf@pc150.maths.bris.ac.uk> "Andrew Dalke" writes: > Michael Chermside: > > If you DO wind up going this route, I'm guessing that the code > > to launch an untrusted-code-runner in a separate process would be > > quite popular if it were released back to the Python community, > > judging from the number of times this question gets raised. > > Maybe we can convince the Twisted folks to do this? ;) Sounds like a plan :-) Cheers, mwh -- I located the link but haven't bothered to re-read the article, preferring to post nonsense to usenet before checking my facts. -- Ben Wolfson, comp.lang.python From jzgoda at gazeta.usun.pl Tue Aug 12 17:12:13 2003 From: jzgoda at gazeta.usun.pl (Jarek Zgoda) Date: Tue, 12 Aug 2003 21:12:13 +0000 (UTC) Subject: Is Python your only programming language? References: <2ec1bc1c.0308121224.5455f929@posting.google.com> Message-ID: Larry pisze: > At home I'm currently about 40% Unreal Tournament 2003 and 60% Civ > III. I'm 100% Steel Panthers World At War 7.1 and I clearly see, that pythonic tactics makes me winner in most of cases. ;) Thanks God, I have wife that allows me run "unknown binaries" on her W2K box. And she has 80GB HDD, just enough for all our collected music. -- Jarek Zgoda Registered Linux User #-1 http://www.zgoda.biz/ JID:zgoda at chrome.pl http://zgoda.jogger.pl/ From roy at panix.com Mon Aug 18 16:09:47 2003 From: roy at panix.com (Roy Smith) Date: Mon, 18 Aug 2003 16:09:47 -0400 Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> Message-ID: Alex Martelli wrote: > I do hope that Python never gets such a powerful macro system I'm with Alex on this. Macros suck. What you usually end up with is essentially two different languages, with different syntaxes, and which don't interract very well. If nothing else, this really screws up emacs auto-indenting :-( One of the few things I like about C++ is that between const, templates, and inline, the need for the macro preprocessor has been almost eliminated. Still, you see a lot of code which goes out of its way to do fancy things with macros, almost always with bad effect. I don't even want to talk about the various systems which make use of things like m4. Why do you need macros? There's a few things people do with them: 1) Define constants. In Python, you just define symbols in your module, and get over the fact that there really is no such thing as a constant in Python. 2) Define efficient pseudo-functions. In Python, you just define a function (or method) and get over the fact that it's not as efficient as a macro. If I cared about microseconds, I wouldn't be writing in Python. 3) File inclusion. In Python, you don't include files, you import modules. 4) Conditional compilation. In Python, you can conditionally define anything you want at import time. 5) Inventing your own language constructs. In Python, you just don't do this. From nhodgson at bigpond.net.au Sat Aug 23 05:43:04 2003 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Sat, 23 Aug 2003 09:43:04 GMT Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> Message-ID: David Abrahams: > BTW, the C++ preprocessor is a fairly weak macro system. A higher > level metaprogramming facility that knows more about the underlying > language could be a lot cleaner, clearer, safer, and more expressive. What do you think of OpenC++? http://www.csg.is.titech.ac.jp/~chiba/openc++.html Neil From tim at remove_if_not_spam.digitig.co.uk Wed Aug 13 18:27:10 2003 From: tim at remove_if_not_spam.digitig.co.uk (Tim Rowe) Date: Wed, 13 Aug 2003 23:27:10 +0100 Subject: Is Python your only programming language? References: Message-ID: On Wed, 13 Aug 2003 10:13:53 -0700, Donn Cave wrote: >Sure, within the domain of computer programming problems, >no single language can adequately serve for everything. >But that's a much broader range than most of us encompass, Most, maybe, but as, loosely, a computer scinece consutant, I probably get a broader range than most! I have to know at least the basic characteristics of any language I may encounter, even if I don't have to code it, and my experience is that the best way to do it is to code it -- whatever it is -- at least a bit. >and I think it's really rather reasonable in principle for >a single language to satisfy a single programmer's needs. I'd suggest that that depends on the level of the programmer. Certainly I'd say get to know one really well. But then I reckon getting another language under the belt -- the /right/ another language that complements the first -- offers massive advantages over the programmer with only one. >For my purposes, there seem to be three programming language >roles: a low level system interface language (C, for UNIX), >an application language, and a high level system interface >language (shell, for UNIX.) In practice, the application >language is sometimes Python, more commonly C, and in my >dreams it could be Haskell. If I want to get something up and running quickly then I go straight to Python. If thousands of lives depend on the code working right I would not be allowed to use Python, and, IMHO, quite rightly too. It just doesn't have what it needs for proving correctness, and adding those things would scupper the getting things up and running quickly. From info at kandidates.com Tue Aug 12 16:40:23 2003 From: info at kandidates.com (Kandidates) Date: Tue, 12 Aug 2003 16:40:23 -0400 Subject: JOB: Python Technical Lead & Head of Data Quality Assurance, NYC Message-ID: <03a801c36111$f87a2a80$0300a8c0@nyc.rr.com> If you are interested in a position, please review the requirements and reply with your salary requirement. My clients main concern with these positions is Python. Elaborating on your knowledge of Python when replying to me will greatly increase your chances of landing an interview. JOB #1: Python Technical Lead, New York, NY DETAILS: http://www.nyc-search.com/jobs/python.html JOB #2: Head of Data Quality Assurance, New York, NY DETAILS: http://www.nyc-search.com/jobs/headQA.html Thank you, Beau J. Gould Kaandidates.com Python Jobs Yahoo Group >> http://groups.yahoo.com/group/pythonjobs -------------- next part -------------- An HTML attachment was scrubbed... URL: From skip at pobox.com Tue Aug 19 17:45:09 2003 From: skip at pobox.com (Skip Montanaro) Date: Tue, 19 Aug 2003 16:45:09 -0500 Subject: Why does this (not) work? In-Reply-To: <16194.39277.920636.140954@montanaro.dyndns.org> References: <16194.39277.920636.140954@montanaro.dyndns.org> Message-ID: <16194.39525.989563.645007@montanaro.dyndns.org> Skip> To force the * operation to be evaluated first you need to add some parens: Skip> ("%s - %s - %s" % (("test",))*3) Ack! Should have been what I entered at the >>> prompt: "%s - %s - %s" % (("test",)*3) (Stupid copy-n-paste!) Skip From mwh at python.net Fri Aug 22 08:56:29 2003 From: mwh at python.net (Michael Hudson) Date: Fri, 22 Aug 2003 12:56:29 GMT Subject: max length of a python program References: <1ed07caf.0308210513.6556978a@posting.google.com> Message-ID: <7h3ptix26qe.fsf@pc150.maths.bris.ac.uk> Christos "TZOTZIOY" Georgiou writes: > On Thu, 21 Aug 2003 17:25:51 GMT, rumours say that "Andrew Dalke" > might have written: > > >Many years ago there was a limit of 64K lines, because of how > >the line number opcode worked in Python. Only machine > >generated Python code ever ran into that limit. > > What is the width of JUMP opcode offsets? If it is 16 bit, is there a > chance that someday somebody is going to write such a large basic block > that their program will fail? I'm pretty sure that limit has been lifted too (in the 2.0 timeframe? Not sure). I think you can have basic blocks the full 2^32 bytes long now :-) Cheers, mwh -- Check out the comments in this source file that start with: # Oh, lord help us. -- Mark Hammond gets to play with the Outlook object model From mwh at python.net Wed Aug 6 08:44:36 2003 From: mwh at python.net (Michael Hudson) Date: Wed, 6 Aug 2003 12:44:36 GMT Subject: Checking for an "undefined" variable - newbie question References: <3f30f372$0$27815$626a54ce@news.free.fr> Message-ID: <7h3n0en6jny.fsf@pc150.maths.bris.ac.uk> Damien Wyart writes: > * Alex Martelli in comp.lang.python: > > If you can't rule out (e.g.) None as a valid value for your variable, > > just make a unique placeholder value such as [be sure to use a MUTABLE > > value, else uniqueness is not guaranteed]: > > Could you expand on this "uniqueness" point ? I don't see very well what > you mean. I think Alex is talking about things like this: >>> 2 is (1 + 1) True >>> 200 is (199 + 1) False Two references to equal immutable objects might as well reference the same object, and sometimes this happens (e.g. there is only *one* int object for each integer in some range -- I think it's -10..100 in today's Python) and sometimes it doesn't. TBH, I'm not sure Alex is doing the OP a favour in bringing this aspect of the implementation to his attention... Cheers, mwh -- To summarise the summary of the summary:- people are a problem. -- The Hitch-Hikers Guide to the Galaxy, Episode 12 From wt at nic.fi Sun Aug 3 15:01:01 2003 From: wt at nic.fi (Timo Virkkala) Date: Sun, 03 Aug 2003 22:01:01 +0300 Subject: 'print' in a CGI app. In-Reply-To: References: Message-ID: Andrew Chalk wrote: > In a Python 2.2 app. running under CGI the statements > > print "Hello\n" > print "World" > > print both words on the same line in IE6. How do I print the second one on a > new line (i.e. respect the \n in the first statement). How about (untested): print "Hello
\n" print "World" ...since, AFAIK, it should be HTML that CGI's output...? -- Timo Virkkala | wt at nic.fi "In the battle between you and the world, bet on the world." From jordan at krushen.com Wed Aug 20 19:06:35 2003 From: jordan at krushen.com (Jordan Krushen) Date: Wed, 20 Aug 2003 23:06:35 GMT Subject: Python: executing ping and whois References: <538fc8e.0308201303.46c58c8b@posting.google.com> Message-ID: On 20 Aug 2003 14:03:18 -0700, WIWA wrote: > Anybody that could tell me how to execute some Linux commands using > Python. > The application is that I want to be able from a website to launch a > Python script and that python script should be able to ping to the > provided IP address, or should do a whois of that IP address. I want > to use the existing Linux commands if possible. > > Anyone has an idea or tutorial? http://python.org/doc/current/lib/module-commands.html Should be just what you want. J. From mertz at gnosis.cx Sat Aug 23 23:33:03 2003 From: mertz at gnosis.cx (Lulu of the Lotus-Eaters) Date: Sat, 23 Aug 2003 23:33:03 -0400 Subject: macro FAQ References: Message-ID: Jacek Generowicz wrote previously: |Could you please give me a reference to someone "with plenty of |experience using macros in Lisp" arguing this ? At least Laura Creighton and Alex Martelli stand out as examples. I'm not sure either of them wants to be named specifically in this FAQ, just to attract a lot of argumentative email. Yours, Lulu... -- Keeping medicines from the bloodstreams of the sick; food from the bellies of the hungry; books from the hands of the uneducated; technology from the underdeveloped; and putting advocates of freedom in prisons. Intellectual property is to the 21st century what the slave trade was to the 16th. From mwh at python.net Thu Aug 28 07:36:10 2003 From: mwh at python.net (Michael Hudson) Date: Thu, 28 Aug 2003 11:36:10 GMT Subject: Filtering virus-related e-mails? References: <3f4ce4d6$0$166$a1866201@newsreader.visi.com> <7h3ad9v6jqu.fsf@pc150.maths.bris.ac.uk> Message-ID: <7h3smnm585k.fsf@pc150.maths.bris.ac.uk> Francois Pinard writes: > > Ten minutes after instituting the clever hack that saved mail.python.org, > > about 250 hosts were being rejected at the firewall level. > > What is that clever hack? I'm mostly curious, but maybe interested too! :-) Basically, any host that makes five or more attempts to send the Sobig virus in 15 minutes is blocked by the Linux ipchain firewall. I'm not sure how Sobig is detected; may just be the subject lines. Martijn Pieters has a shell sitting on the machine doing this: tail --follow=name /var/log/exim/reject.log | grep SOBIG | ~martijn/ipchain_deny_sobig.py The script filters out the IP of sobig infected machines and tells the firewall about them. Cheers, mwh -- The above comment may be extremely inflamatory. For your protection, it has been rot13'd twice. -- the signature of "JWhitlock" on slashdot From mpeuser at web.de Sun Aug 31 09:29:15 2003 From: mpeuser at web.de (Michael Peuser) Date: Sun, 31 Aug 2003 15:29:15 +0200 Subject: Newbie question! Plotting with Tkinter... References: <9193c0d1.0308291322.12538c14@posting.google.com> Message-ID: I should have added there is something called CHACO which totally had slipped my mind. I had the impresion it is a wxWindows package but it works with Tkinter as well. No experience with it, though. Kindly Michael P From spam-trap-095 at at-andros.demon.co.uk Fri Aug 22 11:32:55 2003 From: spam-trap-095 at at-andros.demon.co.uk (Andrew McLean) Date: Fri, 22 Aug 2003 16:32:55 +0100 Subject: Problem with py2exe and installer5b5_5 References: <5b8834c2.0308212317.68acf539@posting.google.com> Message-ID: In article , Eric Brunel writes >hellprout wrote: >> hi , i want to use py2exe or installer5b5_5 with my python source >>so no problem when i execute the source , but when i use installer or >> py2exe to create an exe file on windows , i have some problems >> when my program want to read a xml file i have an error 2.2.3 (#42, >>May 30 2003, 18:12:08) [MSC 32 bit (Intel)] >> Traceback (most recent call last): >> File "wxFrame1.pyc", line 287, in OnButton1Button >> File "EIM_xml.pyc", line 135, in main_xml >> File "EIM_xml.pyc", line 44, in construction_liste_xml >> File "xml\sax\__init__.pyc", line 33, in parse >> File "xml\sax\expatreader.pyc", line 86, in parse >> File "xml\sax\saxutils.pyc", line 250, in prepare_input_source >> File "ntpath.pyc", line 274, in isfile >> LookupError: no codec search functions registered: can't find encoding > >Apparently, there is some weird code importing the codecs that py2exe >or McMillan installer cannot correctly figure out. I had the same >problem some time ago, which I solved by simply importing explicitely >the codecs module via an: > >import codecs > >somewhere in the code. This seems to fix up things for McM's installer >(never used py2exe). I had a similar problem with the McMillan installer. This wasn't solved by adding: import codecs but it was solved by adding import encodings -- Andrew McLean From tjreedy at udel.edu Fri Aug 29 16:51:07 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 29 Aug 2003 16:51:07 -0400 Subject: nested data structures in classes References: Message-ID: "Joel" wrote in message news:e31c4866.0308291220.776a92a5 at posting.google.com... > Does anyone have any thoughts on this? > > My Python use involves organizing nested list information. In a > > simplified example, you could imagine a list of reactants and products in > > a chemical reaction. Thus, I would think about keeping reaction data together rather than in separate lists. Perhaps you need to add a reaction attribute dict or define a reaction class. Perhaps your need a reactant class. But I would not say more without knowing much more about your specific project and its goals. Terry J. Reedy From wiebke.paetzold at mplusr.de Fri Aug 1 06:18:08 2003 From: wiebke.paetzold at mplusr.de (Wiebke Pätzold) Date: Fri, 01 Aug 2003 12:18:08 +0200 Subject: regular expression References: Message-ID: <5hfkiv8abk7h0nu3foirhkn2l9f8c704d6@4ax.com> On Thu, 31 Jul 2003 10:46:59 -0500, Jeff Epler wrote: >These are all untested, because I don't have Mk4py or your datafile to >try it on. > >I might write this: > import re > pattern = re.compile("^Ge") > def func(row): > try: > nachname = row.Nachname > except AttributeError: > return 0 > return pattern.search(nachname) is not None > > vf = vw.filter(func) > >If you're using a Python version with nested scopes, you could use them >in this case: > import re > def make_func(pattern): > pattern = re.compile(pattern) > def func(row): > try: > nachname = row.Nachname > except AttributeError: > return 0 > return pattern.search(nachname) is not None > return func > > vf = vw.filter(make_func("^Ge")) > >or you can make a callable filter object by using classes: > import re > class PatternFilter: > def __init__(self, pattern): > self.pattern = re.compile(pattern) > > def __call__(self, row): > try: > nachname = row.Nachname > except AttributeError: > return 0 > return self.pattern.search(Nachname) is not None > vf = vw.filter(PatternFilter("^Ge")) > >Jeff I have found the error I have made. Your program was all right. Thank you very much. From tzot at sil-tec.gr Wed Aug 20 12:53:20 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Wed, 20 Aug 2003 19:53:20 +0300 Subject: for statement list comprehension-like extention proposal References: Message-ID: On Wed, 20 Aug 2003 00:31:27 GMT, rumours say that "Ryan Lowe" might have written: >>>> for x in y if x < 10 : [snip] >seem reasonable? Why bother writing a PEP? Modify the parser yourself and suit the language to your taste, it's open source after all. You see, your idea isn't original at all, that is why my reply is so depressed :) ... this has been discussed already quite a few times (you'd know that if you did a search in groups.google.com), and the general consensus is against such syntactic sugar, as you correctly yourself characterised it. -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From missive at frontiernet.net Mon Aug 4 18:53:42 2003 From: missive at frontiernet.net (Lee Harr) Date: Mon, 04 Aug 2003 22:53:42 GMT Subject: Python and cron jobs. References: <7b454334.0308041023.6e688b4d@posting.google.com> Message-ID: In article <7b454334.0308041023.6e688b4d at posting.google.com>, Fazer wrote: > Hello, > > I am wondering that if it is possible to add cron jobs via a web or > shell interface? I can make Python act as a shell script and be > called by a PHP script. But my main goal here is to be able to manage > cronjobs. Add or remove certain crjob jobs etc... > > Can any kind soul shed some light on how I would accomplish this? > I think adding them from the shell is probably the "normal" way. For adding cron jobs from the web, you might look at webmin. Basically, the crontab is just a file, so if you can edit the file from your program and then force cron to reload the crontab you are all set. From stuart at bmsi.com Sun Aug 24 00:58:20 2003 From: stuart at bmsi.com (Stuart D. Gathman) Date: Sun, 24 Aug 2003 00:58:20 -0400 Subject: more bugs in email module Message-ID: I am trying to convert an application using rfc822, mimetools and multifile to use the new email package. In addition to the param parsing anomoly noted earlier, here is a test message that the email module can't even read in andd write back out. It drops a whole section of headers for the message/rfc822 part. http://bmsi.com/python/test/test8 The old system works fine on this example. -- Stuart D. Gathman Business Management Systems Inc. Phone: 703 591-0911 Fax: 703 591-6154 "Confutatis maledictis, flamis acribus addictis" - background song for a Microsoft sponsored "Where do you want to go from here?" commercial. From zanesdad at bellsouth.net Fri Aug 29 00:07:22 2003 From: zanesdad at bellsouth.net (Jeremy Jones) Date: Fri, 29 Aug 2003 00:07:22 -0400 Subject: ANN: Munkware 0.1 Message-ID: <20030829000722.4f2b269f.zanesdad@bellsouth.net> Munkware, a transactional and persistent queueing mechanism, is proud to announce version 0.1 for public consumption. Bug fixes/enhancements include: - improved recoverability in the event of system crash - example code which is more functional (i.e. they die nicely now ;-) - and modification of transactional syntax (from *_ack() to *_commit() and un_*() to *_rollback()) The Sourceforge Project page is located at http://sourceforge.net/projects/munkware/ and the project home page is located at http://munkware.sourceforge.net/ Future plans for Munkware include: - Better documentation with diagrams of state traversal - Auto-commit functionality - Transactional and persistent queueing server with (possibly) a SOAP interface If you have any suggestions, please feel free to email them to me. If you just think that this project sucks, email that, too. Jeremy Jones From heikowu at ceosg.de Sun Aug 10 23:47:09 2003 From: heikowu at ceosg.de (Heiko Wundram) Date: 11 Aug 2003 05:47:09 +0200 Subject: ANN: yawPyCrypto 0.1 and Flatten 0.2 In-Reply-To: <1060559669.822.13.camel@d168.stw.stud.uni-saarland.de> References: <1060559669.822.13.camel@d168.stw.stud.uni-saarland.de> Message-ID: <1060573629.843.15.camel@d168.stw.stud.uni-saarland.de> On Mon, 2003-08-11 at 01:54, Heiko Wundram wrote: > URL: http://www.sourceforge.net/projects/yawpycrypto Due to the server outage, the fresh packages have only just now been made available on SourceForge. They are ready for download from now on. Feel free to contact me if you have any questions. From info at kandidates.com Wed Aug 13 18:24:43 2003 From: info at kandidates.com (Kandidates) Date: Wed, 13 Aug 2003 18:24:43 -0400 Subject: 3 PYTHON JOBS - New York and California Message-ID: <03e301c361e9$b2846080$0300a8c0@nyc.rr.com> 3 PYTHON JOBS >> http://www.nyc-search.com/positions.htm -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Sat Aug 30 19:26:24 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 30 Aug 2003 19:26:24 -0400 Subject: complex - unexpected behavior References: Message-ID: "Mirek Rusin" wrote in message news:bir1nb$o2$1 at atlantis.news.tpi.pl... > > ...i've got different results on linux / windows box > with complex nums, why? Floating point behaviour in detail and in corner cases in general and NaN versus overflow in particular is C compiler dependent. Says so somewhere in manual (and previous postings on clpy. In other words, this is one area where Python does not shield you from unnecessary variation in C compiler behavior and standards that do not standardize. Terry J. Reedy > linux: > >>> print (2.83527944266e+184-3.10413674648e+186j) ** 2 > (nan+nanj) > ...m$ win: > >>> print (2.83527944266e+184-3.10413674648e+186j) ** 2 > Traceback (most recent call last): > File "", line 1, in ? > OverflowError: complex exponentiaion From alloydflanagan at comcast.net Tue Aug 26 14:59:17 2003 From: alloydflanagan at comcast.net (A. Lloyd Flanagan) Date: 26 Aug 2003 11:59:17 -0700 Subject: Advice to a Junior in High School? References: Message-ID: "Howard Nease" wrote in message news:... > Hello, everyone. I would appreciate any advice that someone could give me on > my future career path. Here is my situation: > ... > Does anyone have any advice for me and my future? What should I study in > college? Will the market for jobs get better? Do I have any hope at all of > finding a decent-paying job in compsci? What languages do you suggest that I > study (I'm already studying Python)? > I would say that more important than learning any particular language is learning the theoretical aspects of the job, including the math. Languages change, the theory will benefit you all your life. That said, I agree that you should learn and study a variety of languages. Each carries with it a particular way of thinking about a problem, and once you understand that way of thinking you can apply it elsewhere. As for a job in CompSci, I'd say if you were in it for a steady job, doing the same sort of thing for years, getting good pay without too much work, you're really in the wrong field. Amazingly, a lot of people working today have that attitude. Many more are trying to figure out where their jobs went. You sound like someone with a real love for the field and a desire to keep learning and improving yourself. If that's the case, you'll do fine. From gh at ghaering.de Mon Aug 4 09:31:34 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Mon, 04 Aug 2003 15:31:34 +0200 Subject: Script In-Reply-To: References: Message-ID: <3F2E6036.4030806@ghaering.de> zze-Support activite PCL RAMSI A ext DvSI/SIReS/LAN wrote: > Hello everybody, > > I try to execute an ifconfig command in my python code using: > stat, wdsout = commands.getstatusoutput("./script.sh " + interface + " " > + ipadrr) > > The script.sh executes the ifconfig command as: > Ifconfig $1 plumb && ifconfig $1 $2 netmawk 255.255.255.0 up > > this script is created by the root, and have 4755 as chmod. > > When the script is executed by th root, it works normaly but when it's > launched from the python file it doesn't work: > and i have a Permission denied message. > > Is something wrong in what I do? Yes, non-root users cannot set IP addresses or netmasks on Unix. All they can do is query this information, but not change it. -- Gerhard From duncan at NOSPAMrcp.co.uk Wed Aug 6 07:27:08 2003 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Wed, 6 Aug 2003 11:27:08 +0000 (UTC) Subject: Checking for an "undefined" variable - newbie question References: Message-ID: Dan Rawson wrote in news:bgqmce$qk3d1$1 at ID-122008.news.uni-berlin.de: > I have only one (ugly) solution: > > try: > variable > except NameError: > ... > > which works, but is a bit clumsy if I just want to know if the thing > already exists. You could check whether the name of the variable is present in 'locals', 'globals', or 'vars' as appropriate: >>> 'variable' in vars() 0 -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From mis6 at pitt.edu Sat Aug 23 07:18:12 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 23 Aug 2003 04:18:12 -0700 Subject: how fast is Python? References: <3f43e5cf$0$49115$e4fe514c@news.xs4all.nl> <3f447f49$0$49116$e4fe514c@news.xs4all.nl> Message-ID: <2259b0e2.0308230318.72b34ace@posting.google.com> Alex Martelli wrote in message news:... > Irmen de Jong wrote: > ... > > Nevertheless, a Psyco-optimized piece of Python code > > that runs as fast as compiled C is still very impressive > > to me. I know that JIT compiler technology theoretically > > could produce better optimized code than a static optimizing > > compiler, but am happy already if it reaches equal level :-) > > If anybody does have an actual example (idealy toy-sized:-) > where psyco's JIT does make repeatably faster code than a > C compiler (well-used, e.g. -O3 for gcc, NOT just -O...!-) > I'd be overjoyed to see it, by the way. > > > Alex Actually, as I posted in the C sharp thread of few weeks ago, on my machine psyco+psyco was FASTER than C. The numbers quoted are for C with option -o, but even for -o3 psyco was still faster and, notice, with pow(x,2) replacedby x*x in C too. I would be happy if somebody can reproduce that. Here is the link: http://groups.google.it/groups?hl=it&lr=&ie=UTF-8&threadm=2259b0e2.0308041106.7ac111cc%40posting.google.com&rnum=1&prev=/groups%3Fhl%3Dit%26lr%3D%26ie%3DISO-8859-1%26q%3Dsimionato%2Bspeed%2Bgroup%253Acomp.lang.python.*%2Bgroup%253Acomp.lang.python.*%26meta%3Dgroup%253Dcomp.lang.python.* Michele Simionato, Ph. D. MicheleSimionato at libero.it http://www.phyast.pitt.edu/~micheles --- Currently looking for a job --- From cartermark46 at ukmail.com Thu Aug 21 12:11:51 2003 From: cartermark46 at ukmail.com (Mark Carter) Date: 21 Aug 2003 09:11:51 -0700 Subject: how fast is Python? Message-ID: cartermark46 at ukmail.com (Mark Carter) wrote in message > It was discovered that uncompiled VB code in VB 6.0 ran at the same > speed as VBA code in Excel. It was half the speed of compiled VB code, > 5 times the speed of Python, and 1/20th the speed of C++/Fortran. Although, as the saying goes, there's no such thing as a slow language - only slow implementations. From madsurfer2000 at hotmail.com Fri Aug 22 10:47:33 2003 From: madsurfer2000 at hotmail.com (-) Date: 22 Aug 2003 07:47:33 -0700 Subject: Adding a column in a tab delimited txt file References: Message-ID: gcf78 at hotmail.com (Garry) wrote in message news:... > Hi, I am new to python, hope someone can help me here: > I have a MS Access exported .txt file which is tab delimited in total > 20 columns, now I need to add another column of zero at the 4th column > position and a column of zero at the 9th column position. What is the > best way to do this? I don't know the best way, but one way is this. import re infile = file("in.txt","r") outfile = file("out.txt","w") pattern = re.compile(r'^((?:[^\t]+\t){3})((?:[^\t]+\t){5})') replace = '\g<1>0\t\g<2>0\t' for line in infile: outfile.write(pattern.sub(replace,line)) From nobbi_at_theorie3.physik.uni-erlangen.de at NOSPAM.COM Sat Aug 16 08:16:40 2003 From: nobbi_at_theorie3.physik.uni-erlangen.de at NOSPAM.COM (Norbert Nemec) Date: Sat, 16 Aug 2003 14:16:40 +0200 Subject: IEEE special values Message-ID: Hi there, is there any simple reason why IEEE special values are so poorly supported in python? Are there any serious efforts to change that? NaN and Inf are an extremely useful concept for numerical calculations and they would mix perfectly with the concepts in NumPy, anyhow, the support seems to be absolutely minimal. (The ideas in PEP 754 do not really change much: There is little use in easy access to those values, if the math functions don't accept them as input but break down.) Ciao, Nobbi From martin at v.loewis.de Sat Aug 30 22:16:15 2003 From: martin at v.loewis.de (Martin v. =?iso-8859-15?q?L=F6wis?=) Date: 31 Aug 2003 04:16:15 +0200 Subject: bsddb read-only requires rw access to close? References: <70df36e9.0308291220.527fcdfc@posting.google.com> Message-ID: harry.pehkonen at hotpop.com (Harry Pehkonen) writes: > Is this a bug? Yes. Without further investigation, it might be a bug in Python, _bsddb, Sleepycat BSDDB, or the operating system, though. Regards, Martin From uj797 at victoria.tc.ca Fri Aug 22 15:42:25 2003 From: uj797 at victoria.tc.ca (Arthur T. Murray) Date: 22 Aug 2003 11:42:25 -0800 Subject: Python AI Blog Message-ID: <3f466411@news.victoria.tc.ca> A Python AI Weblog for coding AI mind-modules is at http://mentifex.virtualentity.com/python.html (q.v.). The theory and practice of artificial intelligence have advanced sufficiently that it is time to let one hundred AI algorithms blossom, let one hundred AI species evolve and spread. -- http://mentifex.virtualentity.com/acm.html -- DIY AI Steps From skip at pobox.com Thu Aug 7 10:38:58 2003 From: skip at pobox.com (Skip Montanaro) Date: Thu, 7 Aug 2003 09:38:58 -0500 Subject: generator function In-Reply-To: <215fa0fc.0308070503.2344dd66@posting.google.com> References: <215fa0fc.0308070503.2344dd66@posting.google.com> Message-ID: <16178.25730.329103.317173@montanaro.dyndns.org> >>>>> "tom" == tom chansky writes: tom> I read the following link about generator: tom> http://www.python.org/peps/pep-0255.html tom> but I am still not so clear on the use/purpose of a generator function tom> other than the fact that a generator can retain the state of the local tom> variables within the fuction body. That's generally a more than sufficient reason. Have a look at the SpamBayes tokenizer module and the several tokenize* methods and functions it contains for some fairly elaborate examples: http://tinyurl.com/jaun Skip From ivomirb at hotmail.com Thu Aug 7 00:56:56 2003 From: ivomirb at hotmail.com (Ivo) Date: Thu, 07 Aug 2003 04:56:56 GMT Subject: Sources for Python 2.3? Message-ID: Hi. I'm looking for the Win32 sources for Python 2.3. I installed the latest version, but it only came with headers and libraries - no C files. I found http://cvs.perl.org/snapshots/python/python/, but it contains only the latest 2.4 version... Where can I find the sources for the official stable 2.3 release? Thanks Ivo From claird at lairds.com Mon Aug 25 15:33:06 2003 From: claird at lairds.com (Cameron Laird) Date: Mon, 25 Aug 2003 19:33:06 -0000 Subject: Help embedding python References: <3F4A469E.58B94F7C@engcorp.com> <3F4A57B0.E91D89FC@engcorp.com> Message-ID: In article <3F4A57B0.E91D89FC at engcorp.com>, Peter Hansen wrote: >Zora Honey wrote: >> >> Peter Hansen wrote: >> > Zora Honey wrote: >> > >> >>My husband and I are writing a program that does a lot of math behind >> >>the scenes (c++) with a gui front (python/Tkinter). We've decided that >> >>we want the c++ to be the "driver", and so we want to embed the python. >> > >> > >> > It's a little unclear (to me) exactly what you're trying to do, >> > but in any case I can't imagine why you'd want to have C++ "drive" >> > the Python code (if that's what you meant by "driver", as opposed to >> > the more common sense as in "device driver") instead of the other >> > way around. >> > >> > And my inability to imagine why you want this is compounded by your >> > choice of Python and Tkinter for the front end. It is much more >> > common to have the front end be the "driving" code, and the back end >> > be "driven", especially in CPU-intensive applications as it sounds >> > like you have here. >> > >> > -Peter >> >> Okay. Let's assume that the choice to embed the python was a >> well-reasoned decision. Or assume that I want to embed some python for >> the pure joy of doing so. Can you help? > >No, sorry. I have no particular expertise in embedding Python in a >C++ application in the way you wish. > >(If I did, and I had an easy answer, I would offer it. If, on the other hand, >I had no easy answer, and it was going to take some effort on my part, >I'd be happy to provide that effort if the person I was helping would >take a moment of his/her time to convince me that it was a well-reasoned >decision. If, on the other hand, the decision was based on ignorance >or merely on a frivolous desire to experience the joy of doing so at the >cost of another's valuable time, I would probably be less inclined to help...) > >(If you assume for a moment that the person who actually *can* help you >might feel somewhat the same way, you might take a moment to explain >the background rather than risk looking like you treat others' time as >less valuable than your own. It may not look that way to you, but I >was merely trying to help by showing you that at least one person was >puzzled by your choice. I'm also always interested in learning, so >I'd still be quite interested in your rationale, if you are willing to >provide it.) . . . Me, too. As usual, Peter writes for me. Perhaps it'll be useful to supplement his remarks, though. In general, Python's easy to embed; many, MANY people have found suc- cess with no or little more help than affords. HOWEVER, I've never embedded Tkinter in that sense. Moreover, I can't think of a reason I'd want to start now. While I respect the clarity of your advice to "... assume the choice ...", my own experience has sooooooo much inclined me to favor extending over embedding (in the sense of this thread) that I feel no inclination to pursue what I understand you're describing. Let me summarize, again: there's abundant material on embedding Python; I know of none on embedding Tkinter (but wait; does John's book say anything on the subject? I don't have my copy at hand ...). -- Cameron Laird Business: http://www.Phaseit.net Personal: http://phaseit.net/claird/home.html From tismer at tismer.com Sun Aug 10 21:09:47 2003 From: tismer at tismer.com (Christian Tismer) Date: Mon, 11 Aug 2003 03:09:47 +0200 Subject: Slogan: Getting Rich Overnight In-Reply-To: References: Message-ID: <3F36ECDB.1020501@tismer.com> Ben Finney wrote: > On Sun, 10 Aug 2003 23:56:01 +0200, Christian Tismer wrote: > >>But is there any way for such a slogan to pass spam at all? > > > The much greater battle is: if it passes electronic/programmatic > filters, how are you going to get it past the wetware filters -- i.e., > the fact that it just sounds like spam when you hear it? It does not sound like spam when you read it. Getting you to read it is the trick. >>If I remove the ambiguity, the slogan gets lame. > > Anything with "get rich {quick,fast,overnight}" already has far too many > negative connotations to sound un-lame. Right. But is this my fault? > Choose another slogan, forget the "get rich" nonsense. While the > sentiment is great, and I agree it's a wonderful feeling when you > realise how much your options have increased with little effort, the > "get rich overnight" just doesn't jibe with me. Yeah, true. The bare fact that "getting rich overnight" has become something that we regard as spam: Isn't that telling us a *very very* bad story? The spammers *have* won, we are playing *their* games. Can you see it? > The feeling isn't one of being (financially) rich; it's one of being > free from restrictions. Another thread recently mentioned the idea > that, opposed to other languages, Python lets you go home on time. > That's closer to the mark. Fine. And you let spammers dictate to you what they want you to think? I do think this is going way too far. We have already allowed them to get too far. Did I say anything bad? Nothing at all, this was said by other people. And those are dictating to us, what to say and what not to say. SHould we really continue to support this? I hereby simply propose to prohibit SPAM. Really, really prohibiting it, with all legal consequences. I do want to be able to say that I got rich overnight, by using Python. When *we* are unable to accept such a statement, because *some* people are claiming this to be *their* spamming vocabulary, whose fault is this, then? I do believe this is *our* fault, because we allowed this to happen, silently. Shame on US. Shame on me as well, since I installed a SPAM filter, instead of starting a real fight which they can't win. cheers - chris -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 pager +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From gh at ghaering.de Tue Aug 19 08:50:25 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Tue, 19 Aug 2003 14:50:25 +0200 Subject: python & postgresql ? In-Reply-To: References: Message-ID: <3F421D11.3050709@ghaering.de> Dave Kuhlman wrote: > GuineaPig wrote: > > [snip] > >>I've looked into pyPgSQL too, and this works fine under windows, >>but I cannot get this to run on my linux-machine (suse 8.2). > > What problems are you having. I'm using pyPgSQL-2.3 on Debian > GNU/Linux and it seems to work fine, though I'll admit that my > usage does not stress it heavily. A simple "apt-get install python-pgsql", though on Woody this will still get you version 2.0 of pyPgSQL. I'd recommend to install from sources in this case (or backport from unstable). -- Gerhard From grante at visi.com Wed Aug 27 16:33:04 2003 From: grante at visi.com (Grant Edwards) Date: 27 Aug 2003 20:33:04 GMT Subject: Filtering virus-related e-mails? References: <3f4ce4d6$0$166$a1866201@newsreader.visi.com> Message-ID: <3f4d1580$0$153$a1866201@newsreader.visi.com> In article , Jos? Mar?a Mateos wrote: >> Would it be possible for the python mailing list to filter out >> the "virus-warning" emails rather than posting them to the >> newsgroup? > > Filtering out all the posts with the word "virus" in the > subject line helps a log. Setting up scoring in slrn is probably what I ought to do. It would be useful for other stuff too. -- Grant Edwards grante Yow! I'm encased in the at lining of a pure pork visi.com sausage!! From aleax at aleax.it Thu Aug 21 11:51:44 2003 From: aleax at aleax.it (Alex Martelli) Date: Thu, 21 Aug 2003 15:51:44 GMT Subject: Which way to say 'private'? References: <14f9kv4fvuf67k6j12lpgt6vk9dcpefchm@4ax.com> Message-ID: Daniel Klein wrote: > There are 2 ways to indicate private members of classes, by prepending > 1 or 2 underscore characters, the latter causing name mangling. My > question is: When would I use which kind to indicate privacy? You would normally use a single underscore, which is an advisory indication of privacy. You would use two underscores, with the mangling they produce, when you need to ensure against any risk of accidental conflict with other existing names in the same space. For example, if your class injects for its own purposes attributes in other unrelated objects, it might be quite prudent to use the double-underscore syntax for the names of those 'alien' attributes, otherwise name clashes are far too likely to occur. Alex From nicodemus at globalite.com.br Tue Aug 26 20:46:01 2003 From: nicodemus at globalite.com.br (Nicodemus) Date: Tue, 26 Aug 2003 21:46:01 -0300 Subject: modifying method behaviour In-Reply-To: References: Message-ID: <3F4BFF49.80202@globalite.com.br> Craig Zoretich wrote: >Hi, > >I am trying to modify the behaviour of a method so it will >automatically log information for me. I have been able to do this >with functions by using the code that was kindly submitted to this >newsgroup: > > >>class logger: >> def __init__(self, func): >> self.func = func >> def __call__(self, *args): >> print "Called: %s with args %s" % (self.func.func_name, args) >> return self.func(*args) >> >>def myfunc(a): return a >> >>myfunc = logger(myfunc) >> > >This code works great for functions, but it doesn't work too well for >methods within a class. Here's an example of my code: > > >>class logger: >> def __init__(self, func): >> self.func = func >> def __call__(self, *args): >> print "Called: %s with args %s" % (self.func.func_name, args) >> return self.func(self, *args) >> >>class myClass: >> def myfunc(self, a): return a >> >> myfunc = logger(myfunc) >> > >What happens is that the "self" argument in myClass.myfunc is being >filled with an instance of the logger class, so it doesn't see any of >the attributes of "myClass". Is there a simple way of tweeking this >code, or do I need to redesign how I am doing this? > Use the new descriptor protocol: class logmethod(object): def __init__(self, func): self.func = func def __get__(self, obj, class_): def logger(s, *args, **kwargs): result = self.func(s, *args, **kwargs) params = [repr(x) for x in args] params += ['%s=%r' % (name, value) for name, value in kwargs.items()] print 'LOG: %s(%s)' % (self.func.__name__, ', '.join(params)) return result return logger.__get__(obj) class C(object): def foo(self, *args, **kwargs): print 'foo called!' print self.x print args print kwargs foo = logmethod(foo) c = C() c.x = 12 c.foo(1, 2, msg="Hello!") This script will print: foo called! 12 (1, 2) {'msg': 'Hello!'} LOG: foo(1, 2, msg='Hello!') To learn more about descriptors, read the excelent article by Raymond Hettinger: http://users.rcn.com/python/download/Descriptor.htm HTH, Nicodemus. From aleax at aleax.it Mon Aug 11 10:38:24 2003 From: aleax at aleax.it (Alex Martelli) Date: Mon, 11 Aug 2003 14:38:24 GMT Subject: Fun with numbers - dammit, but I want a cast! References: <3f378fac$0$10778$afc38c87@auth.uk.news.easynet.net> <3f3792f2$0$18258$afc38c87@auth.uk.news.easynet.net> Message-ID: Graham Nicholls wrote: ... >> xscale = xframe / float(img_x) > > Thats what I wanted to do, but was sure I'd read that python didn't have > casts, and that _looks_ like a cast to me! Well, Python surely has the ability to create new objects, and the most typical way to do that is to call a type, possibly passing it, as the call's arguments, the value[s] that direct the new object's creation. So, for example, if you have a string S and want to create a list L whose items are the string's characters, you typically code: L = list(S) Similarly, if you have a number N and want to create a float F whose value is the floating-point equivalent of N's value, you code: F = float(N) Whether these are "casts" is, I guess, a pretty moot issue. Me, I'd call them "type calls" (or "explicit constructor calls" if I were in a C++ mood:-), reserving the terminology "cast" for the C/Java notation: (sometype)somevalue or the C++ notations of forms such as: static_cast(somevalue) But, of course (in C++), explicitly calling a costructor of (e.g.) float, with an integer argument; or statically casting an int to float; or even using the old C-ish "prepended type in parenthesis" notation; have much the same effect in most contexts. As long as you're quite clear that what you're actually doing is "create a new value of a specified type by calling the type with suitable argument[s]", rather than (the typical idea of "cast") "reinterpreting an existing value AS IF it was of some other type rather than of the type it actually is", it may not be a problem if you like to call the operation "a cast". Alex From robin.cull at pace.co.uk Thu Aug 7 09:59:37 2003 From: robin.cull at pace.co.uk (Robin Cull) Date: 7 Aug 2003 06:59:37 -0700 Subject: filter()ing a dict Message-ID: <16469f07.0308070559.aed41a@posting.google.com> Imagine I have a dict looking something like this: myDict = {"key 1": ["value 1", "value 2", "value 3", "value 4"], "key 2": ["value 1", "value 2"], "key 3": ["value2", "value 3", "value 4"], "key 4": ["value 1", "value 2", "value 3", "value 4"]} That is, a set of keys which have a variable length list of associated values after them. What I want to do is filter out a subset of this dict to produce another dict that satisfies a set of criteria (in this case whether it contains all four values) to end up with something like this: {"key 1": ["value 1", "value 2", "value 3", "value 4"], "key 4": ["value 1", "value 2", "value 3", "value 4"]} I've tried using the filter() function so I wrote a small function that returned True or False depending on whether the length of the list was what I wanted e.g. def f(item): if len(item) == 4: return True else: return False I then called filter(f, myDict). I was expecting to be returned a dict which was the subset of myDict that satisfied f. This did not happen; the item passed to f was each key of the dict, not each value list. The call to filter returned an empty list (as obviously none of the keys satisfied the criteria). If anything I would have expected an empty dict back as according to the docs: ""filter(function, sequence)" returns a sequence (of the same type, if possible) consisting of those items from the sequence for which function(item) is true." The important bit here is "of the same type, if possible" which I understood to mean if passed a dict it would return a dict. I've tried calling filter(f, myDict.values()) which works and I get a list like this returned: [["value 1", "value 2", "value 3", "value 4"], ["value 1", "value 2", "value 3", "value 4"]] Sort of what I want but I've lost the associativity with the key which was kind of the point in using a dict in the first place. I'm guessing that filter() does not work on a dict in the way I think it should. I can write something to get around the behaviour in this particular case (although suggestions would be welcome). My question is, does anybody else think that when calling filter(f, dict), it should return a dict of the keys and values of the former dict where the values satisfy the conditions defined by f()? Are there reasons for it not to work this way? I must admit I've not looked into this carefully, just in the context of my script it'd be useful to. What are the side effects of making filter() work this way? Thanks all. Regards, Robin From danbmil99 at yahoo.com Sun Aug 3 13:39:38 2003 From: danbmil99 at yahoo.com (dan) Date: 3 Aug 2003 10:39:38 -0700 Subject: looking for win32 (or cross-platform) midi module References: <3F2B84C9.5050507@mxm.dk> Message-ID: Max M wrote in message news:<3F2B84C9.5050507 at mxm.dk>... > dan wrote: > > is there anything like the nice midipy.pyd, but up to date (ie works > 2.0)??? > > > No > > regards Max M the website (http://www.josos.org/midipy/) says: "MidiPY - real-time MIDI input module for python (win32) - If someone can compile for newer python versions, please!" So modules need to be recompiled every time a major release comes out? There's a .cpp file in midipy.zip but no instructions, makefile, includes, project files etc. From tzot at sil-tec.gr Sat Aug 23 22:40:56 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Sun, 24 Aug 2003 05:40:56 +0300 Subject: Bug with win32 open and utf-16 file References: <27vekvc6evvn3m5jg8n1en2u42skat42qn@4ax.com> <2i1gkv0s7762vcs85rkdq6uvgk6oitje12@4ax.com> Message-ID: On Sun, 24 Aug 2003 00:29:27 GMT, rumours say that derek / nul might have written: >>[snip opening 'rb' a UTF-16 file] >> >>>The original file has line terminator characters of 00 0d 00 0a. >>>After being read into a variable or a list the line termination characters have >>>been changed to 00 0a 00 0a I believe you don't explain completely your situation, or maybe I am missing something. The code you posted, which I will quote right here: >#!c:/program files/python/python.exe ># win32 python 2.3 > >import sys, string, codecs >#eng_file = list (open("c:/program files/microsoft games/train >simulator/trains/trainset/dash9/dash9.eng", "rb").read()) # read the whole file >eng_file = open("c:/program files/microsoft games/train >simulator/trains/trainset/dash9/dash9.eng", "rb").read() # read the whole file > >print hexdump (eng_file) # ok opens the file in 'read binary' mode, and without further processing you pass the data just read to the function hexdump (presumably written by you). The output of the hex dump shows only \u000a and not any \u000d. I tried it by downloading your file and ran: >>> data = file("c:/dash9.eng", "rb").read() >>> data[-10:] '\r\x00\n\x00)\x00\r\x00\n\x00' which seems correct to me (\r is 0x0d, \n is 0x0a, and the file is indeed utf-16 le (little endian). Which open command are you using? If you just enter open in the python prompt, does it show: >>> open or what? -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From sami.viitanen at nokia.com Thu Aug 7 06:25:58 2003 From: sami.viitanen at nokia.com (Sami Viitanen) Date: Thu, 07 Aug 2003 10:25:58 GMT Subject: Getting output from executed command that is not STDIN Message-ID: Hello, I'm using os.popen and read for reading command input to string but the string doesn't contain the same output that running the command manually or with os.system contains. with os.system: cvs server: Diffing //Project1 File //Project1/testiware.txt is new; current revision 3.13 File //Project1/what_is_version_control.txt is new; current revision 3.3 cvs server: Diffing //Project1/Dir1 File //Project1/Dir1/seltest.c is new; current revision 1.4 File //Project1/Dir1/testi.c is new; current revision 1.2 with os.popen and read: File //Project1/testiware.txt is new; current revision 3.13 File //Project1/what_is_version_control.txt is new; current revision 3.3 File //Project1/Dir1/seltest.c is new; current revision 1.4 File //Project1/Dir1/testi.c is new; current revision 1.2 --- Script doesn't read those "cvs server: Diffing" lines --- From tjreedy at udel.edu Wed Aug 27 23:25:01 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 27 Aug 2003 23:25:01 -0400 Subject: Celebrity advice (was: Advice to a Junior in High School?) References: Message-ID: <_M2cnY22TvKT69CiXTWJjA@comcast.com> "Gerrit Holl" wrote in message news:mailman.1062010433.31609.python-list at python.org... > Terry Reedy wrote: > > " Every political choice ultimately reduces to a choice about when and > > how to use lethal force, because the threat of lethal force is what > > makes politics and law more than a game out of which anyone could opt > > at any time." > > > > Do you disagree? > > Yes. I knew someone would ;-) I'll just note that George Washington has been quoted as saying something nearly identical about the time he retired. Back to my understanding of what started this subthread and my concern thereof. Budding CS student A asks for advice about going into CS. Person B suggests that A read various CS-related writings by CS celebrities, including C. Poster D says something like 'No, Don't read C' because he has written 'dangerous' stuff on other topics (disconnected from CS). Quite aside from my disagreement about the 'dangerous' characterization, is the boycott suggestion sensible and legitimate, or just flamebait? Let's consider celebrity K(nuth). I believe he has written something on a somewhat different non-CS topic (religion ). Suppose I were to read it (I have not as yet) and view it as 'dangerous nonsense'. Would that justify me suggesting to A, on this newsgroup, that he not read K's CS writings? Terry J. Reedy From nushin2 at yahoo.com Mon Aug 4 14:27:15 2003 From: nushin2 at yahoo.com (nushin) Date: 4 Aug 2003 11:27:15 -0700 Subject: spawnv( ) or spawnl( ) do not launch a normal running process in Python 2.2.2? Message-ID: Try to launch a test program that prints hello world for a minute or so using, spawnv( ) or spawnl( ). Check to see the process state code that the program is running. I am using RedHat Linux 7.3 and Python 2.2.2 and i see that the program is either launched as Zombie state using spawnv(), or running in State "S" sleep in spawnl( ). Here's the sample code that launches my program: os.spawnv(os.P_NOWAIT,'/usr/bin/python',('python hello.py >/dev/null &')) os.spawnl(os.P_NOWAIT,'/usr/bin/python',('python hello.py >/dev/null &')) When you launch a program in Linux, you want it to run in state "R" , a running state. Am i the only one who has this problem? Would the author of spawnv(), spawnl() look into this problem please. Regards, Nushin From aleax at aleax.it Thu Aug 21 02:09:58 2003 From: aleax at aleax.it (Alex Martelli) Date: Thu, 21 Aug 2003 06:09:58 GMT Subject: What's better about Ruby than Python? References: <3F41505F.69D18CC8@alcyone.com> <66d7kvonvb2n0nqbqahhd5roak7ur81sob@4ax.com> Message-ID: Andrew Dalke wrote: ... > I confess to being fond of the > > atom = Atom() > > idiom. I know it breaks down, eg, for a function which returns > a newly created class, but it's too ingrained in me. Back when I gave Eiffel a serious try, I easily slid into [the equivalent of]: itsAtom = Atom() [for an instance member variable -- anAtom for a local, theirAtom for a class-variable, etc -- Robert Martin's idea to distinguish those lexically in languages which confuse the scopes]. In other words, naming a basically-anonimous "generic instance of class Atom" hardly requires a case sensitive language, IMHO. Alex From bignose-hates-spam at and-benfinney-does-too.id.au Sun Aug 10 23:33:28 2003 From: bignose-hates-spam at and-benfinney-does-too.id.au (Ben Finney) Date: 11 Aug 2003 13:23:28 +0950 Subject: How to print floating point in scientific format? References: <420ced91.0308081115.7060e551@posting.google.com> <420ced91.0308101941.64361991@posting.google.com> Message-ID: On 10 Aug 2003 20:41:35 -0700, sdhyok wrote: > Writing my own function is definitely one choice. > But, my point is that if some of us are really serious about > scientific/engineering programming, we must have a common function or > command to print out whole array elements easily with any format we > want. We eagerly await your patches for improving the Numeric code in whatever way you want. -- \ "If I melt dry ice, can I swim without getting wet?" -- Steven | `\ Wright | _o__) | Ben Finney From mpeuser at web.de Mon Aug 18 04:44:49 2003 From: mpeuser at web.de (Michael Peuser) Date: Mon, 18 Aug 2003 10:44:49 +0200 Subject: What's better about Ruby than Python? References: Message-ID: "Brandon J. Van Every" schrieb im Newsbeitrag news:bhpbc6$1plpe$1 at ID-203719.news.uni-berlin.de... > What's better about Ruby than Python? I'm sure there's something. What is > it? There have been very profound answers in this thread (I like Asun Friere's and Graham Fowcett's best so far ;-) I don't know much about Ruby but I did some substantial programming in Python and Perl. I should now consider side issues more important than language features itself: - How fast does the code run - Is there an acceptable IDE (best: GUI/IDE RAD-Framework) - Is there a flexible and fast GUI Toolkit -Can you access OpenGL - Which platforms are supported - How easy is multimedia (Sound/Movie in- and output) - How can you deploy your program - How large is a self contained EXE file - Is there mathematical support (array arithmetic, statistical functions, plotting) - Is there documentation - Are there books Theses questions are quite unordered as they just orrured to me. However it has turned out that answering them or working around negative answers will probably cost you more time than any flaws in the language itself.... Kindly Michael P From skip at pobox.com Fri Aug 15 01:19:51 2003 From: skip at pobox.com (Skip Montanaro) Date: Fri, 15 Aug 2003 00:19:51 -0500 Subject: dict->XML->dict? Or, passing small hashes through text? In-Reply-To: <20030815042536.GA19960@incise.org> References: <20030815042536.GA19960@incise.org> Message-ID: <16188.28023.216400.94715@montanaro.dyndns.org> mack> I'm basically passing little messages around, which are basically mack> just hashes, and up until now, I was using a dict that I formatted mack> to/parsed from a special syntax, but I keep running into growing mack> pains with that. I'm using SocketServer, and each connection mack> sends one line of data, and then the connection is closed by the mack> server. Check out xmlrpclib in the Python distribution for quite awhile. It also interoperates with XML-RPC libraries written in other languages. There are plenty of other choices as well, including Pyro (Irmen de Jong I believe) and an XML-based pickle format from David Mertz (check http://www.gnosis.cx/), not to mention using marshal or pickle then transporting the strings using SocketServer. Skip From osuchw at ecn.ab.ca Sun Aug 3 00:41:32 2003 From: osuchw at ecn.ab.ca (Waldemar Osuch) Date: 2 Aug 2003 21:41:32 -0700 Subject: ODBC & DbiData problem References: <5oonivsud5jrt522bldbevo6nvdf8ktqdp@4ax.com> Message-ID: Wedrowiec wrote in message news:<5oonivsud5jrt522bldbevo6nvdf8ktqdp at 4ax.com>... > I have a problem for experienced programmers. I do know if I am experienced enough but I have a suggestion. > The following code > should copy data between two different databases: > > import dbi,odbc > conn1=odbc.odbc('mysql'); conn2=odbc.odbc('sqlite') > c1 = conn1.cursor(); c2 = conn2.cursor() > > c1.execute("SELECT field1, field2 FROM table1") > rows = c1.fetchall() > c2.executemany('INSERT INTO table1 (field1=%s,field2=%s)', rows) Try using sql statements with ODBC parameter placeholders. For example: c2.executemany('INSERT INTO table1 (field1,field2) values (?,?)', rows) should do the trick. > c1.close();c1=None; c2.close();c1=None; > conn1.close();conn1=None; conn2.close();conn2=None Also you do not have to set cursor and connections to None when you are finished. Time to forget the VB way of doing things. Closing them is enough. > The problem is: field 'field2' is DATE type and after fetchmany() > method I got DbiDate object instead of string 'YYYY-MM-DD > HH:MM:SS'. So my code breaks because Python cannot > insert such object to another database. > > I know how to convert this object to the correct string > (http://www.python.org/windows/OdbcHints.html) but it must be done for > every field in every row. :( So my question is: Is it possible to make > odbc module to *automatically convert* this field from DbiDate object > to string? Maybe is there any special parameter to set up? I do not > want to write special code to convert all such fields. It suppose, it > can be done more automatically by odbc module, bu I do not know > how.... Even if the above suggestion did not work and you had to convert rows it is not too much work. One of the ways to do it could be: conv = lambda x: (x[0], time.strftime('%Y-%m-%d',time.localtime(x[1]))) rows = map(conv, rows) One last thing. I believe that odbc module is not maintained actively anymore. You probably be better off using native dirvers for mysql and sqlite. Waldemar Osuch From hancock at anansispaceworks.com Sat Aug 2 08:41:41 2003 From: hancock at anansispaceworks.com (Terry Hancock) Date: Sat, 02 Aug 2003 05:41:41 -0700 Subject: anti-aliased 2D vector graphics References: Message-ID: Andy C wrote: > Where can I get a python package to draw such figures? I googled and > found > PyX, I guess it outputs PostScript. I guess I can get a PostScript to BMP > converter or something. Is there any other alternative? > > I have looked at PIL, but it doesn't seem to support drawing anti-aliased > figures. Thanks for any suggestions. In addition to the other suggestions made, you might want to consider Sketch. It's normally billed as an application, but it's also a pretty powerful drawing library for python. I'm uncertain about installation issues, it may be a little harder to build on Windows than on Linux, (but I suspect this is less of a problem if you just want to use it as a library). But it certainly can do everything that you've mentioned. I'm pretty sure that Sketch has anti-aliased rendering, but you should also be aware that you can get pretty good results simply by oversampling -- I usually draw at 4X the intended scale and then scale down by 1/4 to get the final result. This is somewhat coarse, but it works pretty well visually. See http://sketch.sourceforge.net/ and links therein. Cheers, Terry -- Terry Hancock Anansi Spaceworks http://www.AnansiSpaceworks.com/ From tdelaney at avaya.com Mon Aug 11 19:43:36 2003 From: tdelaney at avaya.com (Delaney, Timothy C (Timothy)) Date: Tue, 12 Aug 2003 09:43:36 +1000 Subject: stretching list comprehensions Message-ID: <338366A6D2E2CA4C9DAEAE652E12A1DE9E0325@au3010avexu1.global.avaya.com> > From: Simon Burton [mailto:simonb at webone.com.au] > > >>> del y > >>> nums = [ x+y for x in range(y) for y in range(10) ] > Traceback (most recent call last): > File "", line 1, in ? > NameError: name 'y' is not defined > >>> That is exactly equivalent to: nums = [] for x in range(y): for y in range(10): nums.append(x + y) I'll leave it to you to work out the required modification to make the above list comprehension work. As a rule of thumb - keep list comprehensions very simple. Otherwise they become incomprehensible ... Tim Delaney From duncan at NOSPAMrcp.co.uk Wed Aug 6 07:27:08 2003 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Wed, 6 Aug 2003 11:27:08 +0000 (UTC) Subject: round(22.47,2) gives 22.469999999999999? References: <3f30e294$0$125$e4fe514c@dreader5.news.xs4all.nl> Message-ID: Eric van Riet Paap wrote in news:3f30e294$0$125$e4fe514c at dreader5.news.xs4all.nl: > Hi, > > On python2.1.3, python2.2.1 and python2.2.3 round(22.47,2) gives > 22.469999999999999 . Does anyone know if this is a bug or some weird, > yet unexpected, behaviour? > > P.S. I haven't tested python2.3, but python1.5.2 doesn't have this > problem. > > Please read the FAQ, particularly entry 4.98 Why are floating point calculations so inaccurate? http://www.python.org/cgi-bin/faqw.py?req=show&file=faq04.098.htp -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From cappy2112 at yahoo.com Tue Aug 26 13:50:45 2003 From: cappy2112 at yahoo.com (Tony C) Date: 26 Aug 2003 10:50:45 -0700 Subject: Default value for PYTHONPATH Message-ID: <8d3e714e.0308260950.40ad4a7b@posting.google.com> Is there a default value for PYTHONPATH ? I've installed Python on both Windows and Linux, and was surprised to see that this variable is empty. IS this normal ? From jjl at pobox.com Mon Aug 4 13:58:18 2003 From: jjl at pobox.com (John J. Lee) Date: 04 Aug 2003 18:58:18 +0100 Subject: Changing base class of a big hierarchy References: <873cgjyo2u.fsf@pobox.com> <87oez5wrw3.fsf@pobox.com> Message-ID: <87ispds3t1.fsf@pobox.com> Alex Martelli writes: > John J. Lee wrote: [...] > > How would you go about it? > > Well, you could: > -- import the original FtNode (say "import FtNode") > -- save xxx = sys.modules['FtNode'] > -- patch sys.modules['FtNode'] = yourhackedmodule > -- do the deed > -- restore sys.modules['FtNode'] = xxx [...] Ick. I don't understand that, and I don't think I want to. :-) I'll stick with your class-mapping idea, I think. Thanks all. John From cartermark46 at ukmail.com Sat Aug 9 09:07:29 2003 From: cartermark46 at ukmail.com (Mark Carter) Date: 9 Aug 2003 06:07:29 -0700 Subject: Python/Excel VBComponents crash References: Message-ID: > Mark Carter wrote: > > wbc = wb.VBProject.VBComponents # <---- CAUSES CRASH IN 2.3 > I think this is a bug in Excel, I had raised this as issue 785258 in Sourceforge's pywin32 page. Your response has been added to the issue, and I reclassified the issue as Invalid (because we are saying that it was raised in error). From just at xs4all.nl Sun Aug 17 16:28:45 2003 From: just at xs4all.nl (Just) Date: Sun, 17 Aug 2003 22:28:45 +0200 Subject: Py2.3: Feedback on Sets References: Message-ID: In article , cben at techunix.technion.ac.il (Beni Cherniavsky) wrote: > What I do like is the auto-copying of mutable sets when used a set items; I > wouldn't mind something like this to be extended into other Python types > (primarily dicts). Me too. I once proposed this on python-dev but there didn't seem to be much interest: http://mail.python.org/pipermail/python-dev/2003-February/033043.html (I must admit, the second case I mention there has more or less gone away in the meantime, leaving only the C implementation for sets...) Just From mnh at cogitation.org Mon Aug 18 23:53:29 2003 From: mnh at cogitation.org (Mark Hertel) Date: Tue, 19 Aug 2003 03:53:29 +0000 (UTC) Subject: displaying video in a tkinter GUI Message-ID: I've looked around the web and looked through google groups, but I haven't seen anything I can use. Is it possible to embed a video player on a tkinter frame? I'm looking to create something that displays the video and its associated controls in the upper right quandrant while the other screen quandrants are used for user input. It would be great if the solution was cross platform (windows/linux) but the initial target would be winXP/2K. Thanks, --Mark From borcis at users.ch Thu Aug 21 04:48:26 2003 From: borcis at users.ch (Borcis) Date: Thu, 21 Aug 2003 10:48:26 +0200 Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> <6dj2kv8ugkieehs7guh786cl40o5lj6mcs@4ax.com> <599a6555.0308202108.397bb1a0@posting.google.com> Message-ID: <3F44875A.6020104@users.ch> Andrew Dalke wrote: > Olivier Drolet: > >>Macros, as found in Common Lisp, do not change the underlying language >>at all! Common Lisp macros, when run, always expand into 100% ANSI >>Common Lisp code! > > > I've created a new language, called Speech. It's based on the core > primitives found in the International Phonetic Alphabet. I've made some > demos using Speech. One is English and another is Xhosa. This just > goes to show how powerful Speech is because it can handle so many > domains. And it's extensible! Anything you say can be expressed in > Speech! I believe you unwittingly locate an issue. Machine translation of human languages has been an unescapable project for computer scientists, a challenge that has consistently revealed harder to achieve than expected. Idiomatic machine translation of *programming* languages, in comparison, looks like a toy problem, an appetizer. But all the endless debates in the p.l. newsgroups certainly show one thing : we don't expect idiomatic translation between computer languages to solve our problems. While it clearly could. I believe our reasons for not doing it boil down to : (a) the issue of *conservation* of programming languages *biodiversity* not having gained attention as the key issue it is (b) lack of imagination by programmers too engrossed with pet language advocacy. What I mean is that the metaphor you use puts the joke on you (or us). You should really distinguish between the case of translating between *existing* "sibling" languages (be they human languages or programming languages) and otoh the case of translating between a newly-bred variant of a language and a parent language. Isn't it the case that most objections to macros fail to persist invariant if we set the purpose of our "macro" facility, to that of *grafting some language's surface syntax and basic control structures onto some other language's objects and library ? This, to illustrate and set a positive criterion, well enough that (say) we will be able to manage with (basically) the first language's syntax mode under emacs, what will really run as code in the second language* ? From robin at jessikat.fsnet.co.uk Thu Aug 14 05:35:57 2003 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Thu, 14 Aug 2003 10:35:57 +0100 Subject: To all UK Python Users References: <3f3b4ba2$0$244$fa0fcedb@lovejoy.zen.co.uk> Message-ID: In article <3f3b4ba2$0$244$fa0fcedb at lovejoy.zen.co.uk>, BadJake writes >Hi >I have noticed that there does not seem to be a Python User Group anywhere >in the UK. Therefore, I would like to put that to rights. I am willing to >donate space on one of my web servers if there is sufficient interest. If >anybody is interested in joining with me to set up a UK Python User Group >please contact me at john at rygannon.com > >Best Regards >John Dean There is a python-uk mailing list and Andy Robinson, Simon Brunning and others used to organise beer outings. -- Robin Becker From mwh at python.net Mon Aug 18 11:08:59 2003 From: mwh at python.net (Michael Hudson) Date: Mon, 18 Aug 2003 15:08:59 GMT Subject: Py2.3: Feedback on Sets References: <%BX%a.4999$N37.3051@nwrdny02.gnilink.net> <7h3d6f3143s.fsf@pc150.maths.bris.ac.uk> <3F40EC14.4030202@users.ch> Message-ID: <7h3zni7yph1.fsf@pc150.maths.bris.ac.uk> Borcis writes: > Michael Hudson wrote: > > + isn't totally silly (strings and lists are > > monoids, at least :-). list * int, OTOH, seems a bit smelly to me > > (though I'm not sure what a better spelling would be...). > > But strings/lists form a non-commutative monoid, so list * list > would be better imho, ans a corresponding list ** int Hmm, you're right of course,, but for some reason I prefer +. Maybe it's the commutation with len()? Anyhoo, this is all pointless gassing :-) Cheers, mwh -- My hat is lined with tinfoil for protection in the unlikely event that the droid gets his PowerPoint presentation working. -- Alan W. Frame, alt.sysadmin.recovery From tzot at sil-tec.gr Fri Aug 22 04:20:37 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Fri, 22 Aug 2003 11:20:37 +0300 Subject: tarfile woes References: Message-ID: <76kbkvs6mcsbqmmr24ij7on0id0s3soat6@4ax.com> On Thu, 21 Aug 2003 18:20:20 -0300, rumours say that Gustavo Niemeyer might have written: >> - It does not handle compressed (.Z) archives. Of course there's >> noone to blame. The gzip utility (which is used by gnu tar) handles >> this ancient algorithm, but apparently, zlib does not. :-( > > >>> import bz2 > >>> print bz2.decompress.__doc__ > decompress(data) -> decompressed data [snip] I fell into the same trap; Hans talks about files compressed with "compress", the old unix compression mechanism (not as old as 'pack', though), that had an extension of '.Z'. -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From irmen at -NOSPAM-REMOVETHIS-xs4all.nl Sun Aug 3 07:52:18 2003 From: irmen at -NOSPAM-REMOVETHIS-xs4all.nl (Irmen de Jong) Date: Sun, 03 Aug 2003 13:52:18 +0200 Subject: 2.3 win installer In-Reply-To: References: Message-ID: <3f2cf771$0$49108$e4fe514c@news.xs4all.nl> Timothy Martens wrote: > Well - thanks for the suggestions everyone, but I still have had no > luck. Try booting in 'safe mode' and installing again. --irmen From fale.delete at remove.skidata.com Fri Aug 1 08:12:37 2003 From: fale.delete at remove.skidata.com (Leopold Faschalek) Date: Fri, 1 Aug 2003 14:12:37 +0200 Subject: How to run Python script on WindowXP References: Message-ID: <5PsWa.7$MV1.1223773@news.salzburg-online.at> How to run Python script on WindowXPHI, make a .bat or .cmd file with following lines: REM START of FILE assoc .py=Python.File assoc .pyc=Python.CompiledFile assoc .pyw=Python.NoConFile ftype Python.File=C:\Python23\python.exe "%%1" %%* ftype Python.CompiledFile=C:\Python23\python.exe "%%1" %%* ftype Python.NoConFile=C:\Python23\pythonw.exe "%%1" %%* rem this should be done in the system settings set PATHEXT=%PATHEXT%;.py;.pyc;.pyw rem END of FILE greetings Leopold "Yunxian Mak" wrote in message news:mailman.1059704283.30356.python-list at python.org... Dear Sir/Madam, I'm doing my PhD in APAF and I installed Python 2.2 interpreter in WindowNT before and it worked OK on my old computer. However, our company has upgraded the systems to WindowXP recently. I installed Python2.2.3, which includes IDLE (Python GUI), Module Docs, Python (command line) and Python Manuals, on my new computer. I can open my Python code from IDLE (Python GUI), but I don't know how to run it. If you could please tell me whether the Python interpreter compatible to WindowXP and how to run the Python script on WindowXP, I'll be much appreciated. Thank you very much again. Best regards, Yunxian Mak -------------- next part -------------- An HTML attachment was scrubbed... URL: From member35572 at dbforums.com Tue Aug 12 09:15:43 2003 From: member35572 at dbforums.com (sleepinggiant) Date: Tue, 12 Aug 2003 13:15:43 +0000 Subject: Variant.com problems Message-ID: <3228825.1060694143@dbforums.com> Hi, all Reletivly new to python (all of one week now) and have stumbled across a nasty problem, hopefully you will be able to help me with it. When setting a COM process to read a value from a pre-defined register index, I think, I have to change the variable that the value will be returned to (as I have to do for the same function in perl), into a VARIANT, However when i run the variant code.... 'serialIndex = (win32com.client.pythoncom.VT_BYREF|win32com.clien- t.pythoncom.VT_I2,0)' no matter what extension I use (i.e. VT_VARIANT or VT_BOOL etc etc) it still returns a type mismatch error. I may be doing something wrong or getting confused with variant processes in python. I do know the code I use in perl to do this works so there is nothing wrong with the program I am calling. I have looked about on the internet abit and found it said I need to run the programs .tlb file through makepy.py, however when i go to run makepy (from pythonwin) it brings up a box with all of its recognised .tlb files on my system and the one i wish to change is not there. So I went back to google (where else ;) ) and it was suggested I should instance my COM communication through PyIDispatch.InvokeTypes. However as I have very little knowledge of python, I have not got a clue how to do this. Can someone show me how I might go about doing this? Cheers in advance, Matt p.s. I have seen the very 'moderate' readme file for invokeTypes on aspn, and couldn't make anything of it. -- You ahve nothing to fear except fear itself Posted via http://dbforums.com From tzot at sil-tec.gr Sat Aug 23 10:00:43 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Sat, 23 Aug 2003 17:00:43 +0300 Subject: Indentation question References: Message-ID: On Sat, 23 Aug 2003 05:50:25 GMT, rumours say that Geoff Howland might have written: [David Lees asks how to indent and unindent a group of lines in his code, referring to PythonWin and EditPadLight] >A lot of editors use the method of: > >1. Select lines of text >2. Press TAB or SHIFT+TAB to change indentation out or in >respectively. >I dont know about those editors though. This works for PythonWin, I don't know for EditPadLite. In IDLE (in windows at least), the keypresses are ^[ and ^] for unindenting and indenting, respectively; check the Edit menu for the actual shortcuts. -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From danielk at aracnet.com Sat Aug 9 23:22:48 2003 From: danielk at aracnet.com (Daniel Klein) Date: Sat, 09 Aug 2003 20:22:48 -0700 Subject: Python vs. C# References: <3f357a9b@shknews01> Message-ID: On Sat, 9 Aug 2003 15:59:05 -0700, "Brandon J. Van Every" wrote: >What can I do with Python that I can't do with C#? You can go home on time at the end of the day. Dan From staschuk at telusplanet.net Sun Aug 3 19:45:00 2003 From: staschuk at telusplanet.net (Steven Taschuk) Date: Sun, 3 Aug 2003 17:45:00 -0600 Subject: [OT] Google URLs (was Re: popen eating quotes?) In-Reply-To: <20030803202417.GA10412@unpythonic.net>; from jepler@unpythonic.net on Sun, Aug 03, 2003 at 03:24:18PM -0500 References: <20030803202417.GA10412@unpythonic.net> Message-ID: <20030803174500.A1930@tibia.amotlpaa.bogus> Quoth Jeff Epler: > http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&threadm=0000161b%40bossar.com.pl&rnum=1&prev=/groups%3Fq%3Dshell%2Bquoting%2Bnt%2Bgroup:comp.lang.python%26hl%3Den%26lr%3D%26ie%3DUTF-8%26selm%3D0000161b%2540bossar.com.pl%26rnum%3D1%26filter%3D0 > [apologies for the long URL, I don't know how to get a good memorable > URL for a google groups search] Not memorable, but at least shorter, is In general all you need is the threadm or selm parameter, which gives the message-id of the post in question; if memory serves, threadm and selm differ in whether the resulting page shows the rest of the thread. (Ignore the selm in your URL above; it's inside the prev parameter, which stores information about where you were before arriving at the page the URL is actually for.) It seems that Google also assigns an id to each thread; with suitable poking around (see, e.g., the source for the page at the above URL) you can locate a 'th' parameter which can be used in place of the threadm/selm parameter if you wish to refer to the thread as a whole. In your case that's (As this illustrates, the resulting URL is often shorter than one using the message-id.) The first ten messages in the thread appear on the page obtained thus, with anchors, so you can refer to them individually by appending '#link1', '#link2', etc. This makes nice short URLs too (though I'm not certain that *which* messages such anchors refer to is constant over time as the thread grows). All discovered empirically. Use at your own risk. -- Steven Taschuk staschuk at telusplanet.net "Telekinesis would be worth patenting." -- James Gleick From srijit at yahoo.com Sat Aug 23 08:06:31 2003 From: srijit at yahoo.com (srijit at yahoo.com) Date: 23 Aug 2003 05:06:31 -0700 Subject: Class Variables (Python 2.2/2.3) Message-ID: <221d8dbe.0308230406.6d07cfdd@posting.google.com> Hello Members, I do not see any direct mention of class variables in new style classes. Only class methods. Have I missed or is it trivial? If not, how to define/implement class variables for new style classes? Regards, Srijit From adalke at mindspring.com Mon Aug 18 19:33:52 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Mon, 18 Aug 2003 17:33:52 -0600 Subject: python-dev Summary for 2003-08-01 through 2003-08-15 References: Message-ID: Brett C.: > [...] As always, thank you for your summary! > Python user helping Parrot? Treacherous! Just like Python on Java and Python on .Net? :) > What is going to happen at OSCON 2004 is a benchmark > program written in pure Python will be run using a CVS > checkout of Python against a Parrot [...] checkout; Any thoughts yet on what the benchmark might be? > There is definitely room for adding more standard path > locations for package installations. AAAAAAHHHHHHHHhhhhhhhhhh,,,,,......... (That was the sound of me running away screaming.) I just use distutils and assume the person installing has told it where to install. I got confused amoung the options we have now, esp. since there's no "site-packages" under MS Windows. > grandmaster and wizard levels". So only use __slots__ if you can apply > the label of "programmer at grandmaster or wizard level" to yourself > without your programming peers laughting their bums off; you have been > warned. Is there a PEP somewhere describing the levels? I couldn't find one. I want to make sure I only use those features of Python I'm qualified to use. Wouldn't want my head to explode. ;) Andrew dalke at dalkescientific.com From nicholas_wieland at yahoo.it Tue Aug 19 07:10:31 2003 From: nicholas_wieland at yahoo.it (Nicholas Wieland) Date: Tue, 19 Aug 2003 13:10:31 +0200 Subject: usage of python 2.3 and Tk on freebsd ? References: <3F41A7D4.7020002@epost.de> Message-ID: <76d911-it.ln1@lorien.ilweran.home> -Gerald Hein: > Hi, > > I'm using FreeBSD 4.8 and upgraded to python 2.3. > I tried import Tk and got an error message telling me that python is not > configured for Tk. I never tried importing Tk before, so I don't know > what t I've to do to fix this. Python seems to have a problem with _tkinter. > What could be done in order to get python configured for Tk ? Have you installed Tk under x11-toolkits/py-tkinter ? :) From adalke at mindspring.com Wed Aug 27 18:32:20 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Wed, 27 Aug 2003 22:32:20 GMT Subject: Rebol Size References: <3f4a9b9d_2@nova.entelchile.net> Message-ID: Rodrigo Benenson: > Everything until now can be rivalized by Python. My point is: > > All of the above comes the 500 Kb Rebol/View distribution !! ... > To do the same thing in python I would need: ... > More than 10 Mb > But how to explain such a difference ? That 10MB includes many things not present in Rebol. Eg, both Python and Twisted provide different types of web servers (not sure about Rebol, but I think it's client-oriented). Twisted also includes a web app development system (Woven). What feature of PIL exceed those of Rebol? How small could you make a Python distribution and still include the functionality you need? I would hazard to say quite a bit. Andrew dalke at dalkescientific.com From tjreedy at udel.edu Thu Aug 7 13:36:45 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 7 Aug 2003 13:36:45 -0400 Subject: True References: <3F312A65.5312B6EA@engcorp.com> <3F326BEC.9CF89FEC@engcorp.com> Message-ID: "Martin v. L?wis" wrote in message news:m34r0tmmcm.fsf at mira.informatik.hu-berlin.de... > If you prefer compactness, use > > def boolean2str(val, results=('1', '0')): > return results[not val] -or, more safely (no default arg to accidently overwrite)- def boolean2str(val): return val and '1' or '0' But one might want the flexibility of intentionally replacing the results default, as in print boolean2str(somevalue, ('T', 'F')) Terry J. Reedy From apm35 at student.open.ac.uk Mon Aug 18 03:02:10 2003 From: apm35 at student.open.ac.uk (apm) Date: 18 Aug 2003 00:02:10 -0700 Subject: omniORB 4.0.2 and omniORBpy 2.2 released References: <2428b$3f33cfec$516049d2$15672@nf1.news-service.com> Message-ID: Duncan Grisby wrote in message news:<2428b$3f33cfec$516049d2$15672 at nf1.news-service.com>... > omniORB version 4.0.2 and omniORBpy 2.2 are now available. > > omniORB is a robust, high performance CORBA ORB for C++. omniORBpy is > a version for Python. They are freely available under the terms of the > GNU LGPL. [snip] > For general omniORB details, see this page: > > http://omniorb.sourceforge.net/ That web page says that it is CORBA 2.1 compliant but another page on the same site says it is 1.6 compliant. Maybe the first page is out-of-date? -Andrew Marlow From hjwidmaier at web.de Thu Aug 14 13:29:03 2003 From: hjwidmaier at web.de (Hans-Joachim Widmaier) Date: Thu, 14 Aug 2003 19:29:03 +0200 Subject: 2.3: test test_normalization failed Message-ID: When I compiled Python 2.3 at home, everything went well. make test reported no problems. At work, though, I got: test test_normalization failed -- 03F9;03F9;03F9;03A3;03A3; At first I thought it might be a problem with a somewhat inconsistently upgraded system, but a few looks showed me the real difference. At home I had updated Python quite frequently and downloaded NormalizationTest.txt some months ago. At work, I downloaded it last week. With revision 3.2.0 of said file the test passes, with revision 4.0.0 it fails. I have almost zip knowledge of the whole unicode business 'til now, so I'm not overly concerned. Was 3.2.0 buggy? Is 4.0.0 buggy? Are there different, incompatible specs? (Now _that_ I can't think of!) Whatever, maybe someone can give a little insight. Thanks for a great 2.3! Hans-Joachim From detlefsend at enovatia.com Mon Aug 4 13:04:07 2003 From: detlefsend at enovatia.com (David Detlefsen) Date: Mon, 04 Aug 2003 13:04:07 -0400 Subject: Freeze Question Message-ID: I'm trying to distribute a python program on SunOS 5.8 with python 2.2.1 and I think I'm having a shared library problem. I've tried running the 'frozen' program on two different machines and I get the following error message... 'import site' failed; use -v for traceback Traceback (most recent call last): File "vnmrXserver.py", line 1, in ? File "/usr/local/lib/python2.2/SocketServer.py", line 131, in ? File "/usr/local/lib/python2.2/socket.py", line 41, in ? ImportError: No module named _socket I've read the warning in the freeze README about shared libraries and I do indeed see the "Warning: unknown modules remain..." message. So I guess I this means I have to rebuild python with static linking (this is a mystery to me) OR is there a way to hack the makefile (or perhaps some other file) and have the missing modules found and included in the frozen program without a rebuild of python? From jarausch at skynet.be Thu Aug 7 03:42:11 2003 From: jarausch at skynet.be (Helmut Jarausch) Date: Thu, 07 Aug 2003 09:42:11 +0200 Subject: round(22.47,2) gives 22.469999999999999? In-Reply-To: <3f30e294$0$125$e4fe514c@dreader5.news.xs4all.nl> References: <3f30e294$0$125$e4fe514c@dreader5.news.xs4all.nl> Message-ID: <3F3202D3.5030200@skynet.be> Eric van Riet Paap wrote: > Hi, > > On python2.1.3, python2.2.1 and python2.2.3 round(22.47,2) gives > 22.469999999999999 . Does anyone know if this is a bug or some weird, yet > unexpected, behaviour? You're asking too much. There simply is no number 22.47 representable in binary arithmetic with a finite number of bits. Remember most current CPUs use binary and not decimal arithmetic. So 22.469999999999999 is the best you can get and it doesn't make sense to print a rounded number with many more digits after the decimal point. If you printed print '%6.2f' % 22.47 you got '22.47' so this limited precision (nearly 16 decimal digits) doesn't hurt. You still could write a fix-point class which internally store the value multiplied by 10**d with a given 'd'. You'd have to overload the standard math operators (and perhaps functions) and especially the '__str__' method. -- Helmut Jarausch Lehrstuhl fuer Numerische Mathematik RWTH - Aachen University D 52056 Aachen, Germany From adalke at mindspring.com Mon Aug 4 14:40:01 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Mon, 4 Aug 2003 12:40:01 -0600 Subject: time, calendar, datetime, etc References: Message-ID: John Roth > On the > same token, though, it shouldn't get in the way of people who want to > extend it to handle additional calendar types, or bring dates back before > 1AD. But it doesn't. I showed an easy way to derive from the datetime class to support dates before 1AD, by doing an offset of 6,000 years. class RothDate(object): def __init__(self, year, month, day): self._date = datetime.date(year + 6000, month, day) year = property(lambda self: self._date.year - 6000) month = property(lambda self: self._date.month) day = property(lambda self: self._date.day) def weekday(self): self._date.weekday ... d = RothDate(-200, 2, 10) print d.year, d.month. d.day print d.weekday() Andrew dalke at dalkescientific.com From adsr at poczta.onet.pl Tue Aug 26 05:36:24 2003 From: adsr at poczta.onet.pl (AdSR) Date: 26 Aug 2003 02:36:24 -0700 Subject: My own 12 points list References: Message-ID: <422a840f.0308260136.55cb1f56@posting.google.com> pruebauno at latinmail.com (nnes) wrote... > 8.) Eliminate `x` for repr() I have a different idea for backticks use: something like `foo` in Unix shells. It would behave more or less like popen("foo"), just a bit smarter. You could either: >>> print `ls` and get the whole output of /bin/ls - or - >>> for line in `ls` ... print line and read output of /bin/ls line by line. I would add other behavior of string types, like % formatting, so you could do: >>> print `ls %s %s` % ('-a', '*foo*') One potential problem is closing the underlying popen() object early enough. And it's not really a big advantage over popen() either. > 11.) Add a big decimal type (something like java) in the standard > library. To be able to do bean counter type math easily. Are there so > few python applications that deal with money? I second that. We already have unlimited longs, but with floats we're limited to platform-specific values. > 12.) Int division: return float (for engineers) or big decimal (for > bean counters) Rational type also fits here to some extent. I wouldn't make it part of the language though, but rather a standard library type, rational(a, b=1). AdSR From bgailer at alum.rpi.edu Sun Aug 10 08:59:17 2003 From: bgailer at alum.rpi.edu (Bob Gailer) Date: Sun, 10 Aug 2003 06:59:17 -0600 Subject: ANNOUNCE: Rekall V2.0.2 In-Reply-To: <003501c35ec1$cf1a6b20$0501a8c0@sun.thekompany.co.uk> Message-ID: <5.2.1.1.0.20030810065523.02c3ed10@66.28.54.253> At 11:01 PM 8/9/2003 +0100, john at rygannon.com wrote: >Hi >I would like to take this opportunity to announce the release of Rekall for >Windows and Linux. >Rekall is an attempt to produce an application to rival Microsoft Access, >without the huge price tag. With Rekall you can produce full blown >applications. Rekall's programmability and power comes through the use of >Python. There is also a Run Time version of Rekall which allows you ship >your Rekall application to your customers. Rekall includes a syntax >highlighting editor and a debugger. You can import and export data and table >structures to and from all the databases supported by Rekall. Included in >the standard package are drivers for MySQL, xBase and PostreSQL. You can get >drivers for DB2, ODBC and Oracles separately from us at a fraction of the >cost of buying from the big vendors. >Why not take a Rekall Demo out for a test drive. Our demos are fully >functional with a 60 minute time limitation (the Windows demo has a 15 day >time limit), but they will run again. You can find the demos on either of >two web sites, http://www.rygannon.com I just spent more than a reasonable amount of time staring at this page. I can't make sense of it! I don't see any helpful information that would entice me to get the product, and no links for demos. >and http://www.totalrekall.co.uk This page makes a lot more sense. I suggest dropping the first link or improving the page. Bob Gailer bgailer at alum.rpi.edu 303 442 2625 -------------- next part -------------- --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.506 / Virus Database: 303 - Release Date: 8/1/2003 From amk at amk.ca Thu Aug 14 14:53:41 2003 From: amk at amk.ca (A.M. Kuchling) Date: Thu, 14 Aug 2003 13:53:41 -0500 Subject: 3 new slogans References: Message-ID: <3I-dnTQzSbYoR6aiRTvUrg@speakeasy.net> On Thu, 14 Aug 2003 10:29:47 -0700, Dave Kuhlman wrote: > By the way, at one time I found a set of Python icons that could > be freely used, for example on Web sites. Is that still > available? I couldn't find it. If it still exists, perhaps the http://www.python.org/community/logos.html, perhaps? --amk From dev-python at smartology.nl Wed Aug 27 10:25:10 2003 From: dev-python at smartology.nl (Remy Cool) Date: Wed, 27 Aug 2003 16:25:10 +0200 Subject: imputils - import problem modules from sys.modules References: Message-ID: Problem solved!!! Switched to python 2.3 and created a class using the brand new sys.path_hooks. See python PEP302 for more info on this subject. Remy > Hello, > > I've created an archive import class (with the help of importers.py from > the python /demo/imputil dir) which imports packages and modules from a > dictionary. So far so good. > > The problem is that every import statement after the code: > > imputil.ImportManager().install() > sys.path.insert(0, DictImporter(archive)) > sys.path.insert(0, imputil.BuiltinImporter()) > > tries to import from the dictionary and doesn't use the modules that were > imported before. > > For example, I would like to use os in a module that's stored in the > dictionary. The import os statement tries to import os from the dictionary > and does not 'use' the already imported os module that is in the modules > list. > > Is it possible to get access to both, already loaded modules in the > modules list and modules in the dictionary? > > Regards, > Remy Cool From __peter__ at web.de Thu Aug 28 17:10:15 2003 From: __peter__ at web.de (Peter Otten) Date: Thu, 28 Aug 2003 23:10:15 +0200 Subject: pmw menu item's 'command' attribute References: <3f4e5687_4@corp.newsgroups.com> Message-ID: "Tina Li" wrote: > for size in ('tiny', 'small', 'average', 'big', 'huge'): > self.menuBar.addmenuitem('Size', 'command', 'Set size to ' + > size, > command = lambda: cmd.do('change size ' + size), > label = size) The variable size in the lambda expression is bound to the global variable size, so if you do size = 42 later, the menu command will even raise an exception. Solution: command=lambda size=size: cmd.do('change size ' + size) This creates a local variable size that defaults to the same string that the outer size variable is bound to when the lambda expression is created. (Don't know if the explanation works, but the code should :-) Peter From aleax at aleax.it Thu Aug 21 01:36:17 2003 From: aleax at aleax.it (Alex Martelli) Date: Thu, 21 Aug 2003 05:36:17 GMT Subject: Newbie problem with codecs References: Message-ID: derek / nul wrote: ... > Traceback (most recent call last): > File "apply_physics.py", line 12, in ? > codecs.lookup(BOM_UTF16_LE) > NameError: name 'BOM_UTF16_LE' is not defined > > Could someone point to my mistake please? Change the statement to: codecs.lookup(codecs,BOM_UTF16_LE) Alex From jjl at pobox.com Fri Aug 15 18:25:23 2003 From: jjl at pobox.com (John J. Lee) Date: 15 Aug 2003 23:25:23 +0100 Subject: Dictionary assignment References: Message-ID: <874r0isgmk.fsf@pobox.com> "Mark Daley" writes: > I've been using this to save one dictionary as an entry in another > dictionary. I was working, but now it seems I've done something to break > it. Here's the code in question: > > def formatsave(self, args = None): > if self.formats.get() == '': > tkMessageBox.showwarning("No Format", "You must specify a format > name.") > else: > for key in current.keys(): > format[self.formats.get()][key] = current[key] > temp = format.keys() > temp.sort() > list = tuple(temp) Yuck. You've assigned something to a builtin (list). Strangely, the object you chose to bind to list is a tuple! > gui.formats._list.setlist(list) > > > Here's the error I'm getting: > > Traceback (most recent call last): > File "C:\PYTHON23\lib\lib-tk\Tkinter.py", line 1345, in __call__ > return self.func(*args) > File "C:\Python23\Layout.py", line 191, in formatsave > format[self.formats.get()][key] = current[key] > KeyError: 'Format 1' > > > Any ideas? Nobody here is likely to solve it for you. Get aquainted with the print statement! There are three indexes there -- which one is the exception coming from? Split them up, one index per line, and print out the results. You'll soon see the problem. print format[self.formats.get()] print format[self.formats.get()][key] print current[key] If you're like me, you'll want to make sure all debug print statements have a label, though, or you'll inevitably end up wondering (not now, but later) where the hell the output you're seeing on the screen is coming from. print "format[self.formats.get()]", format[self.formats.get()] print "format[self.formats.get()][key]", format[self.formats.get()][key] print "current[key]", current[key] John From aleax at aleax.it Mon Aug 4 08:01:04 2003 From: aleax at aleax.it (Alex Martelli) Date: Mon, 04 Aug 2003 12:01:04 GMT Subject: boost python & 2.3 References: Message-ID: <4WrXa.16855$an6.616226@news1.tin.it> Dave Reed wrote: ... > What version of boost are you using? 1.30.0 won't work with Python > 2.3; however, the CVS version of boost does work with Python > 2.3. David Abrahams has indicated this on the boost list and I can > confirm that it does work with Python 2.3 (at least on a Solaris 9 > system). On Linux too -- if and when you can get it all downloaded from sourceforge (this has proved to be a real problem for me -- I did manage once on my own machine, but later failed twice on another machine despite the latter having excellent net backbone access), and with an annoying but apparently ineliminable warning about double definition of _POSIX_C_SOURCE on just about each file that does get compiled (it gets defined in both /usr/include/features.h and /usr/local/include/python2.3/pyconfig.h), which, however, does seem to be "benign" (quite annoying, but not really problematic). Alex From andrew-pythonlist at puzzling.org Tue Aug 12 20:45:02 2003 From: andrew-pythonlist at puzzling.org (Andrew Bennetts) Date: Wed, 13 Aug 2003 10:45:02 +1000 Subject: Python vs. C# In-Reply-To: References: Message-ID: <20030813004501.GA7207@frobozz> On Tue, Aug 12, 2003 at 11:56:07AM -0700, Brandon J. Van Every wrote: > Andrew Bennetts wrote: > > On Tue, Aug 12, 2003 at 02:03:58AM -0700, Brandon J. Van Every wrote: > >> > >> And how, in a large scale industrial systems context, are you > >> supposed to ensure that Joe Programmer doesn't in fact screw it up? > > > > By writing tests. > > Compiler checking is a kind of test that is done for you all the time, > without you having to reimplement it over and over again. I agree that > people should write tests, but having written many, many of those for my own > project, it is equally true that writing test cases slows down development. > Anything that provides testing "for free" is a boon. Static type checking, as implemented in C++, C# and Java, is laughably minimal, seeing as it doesn't verify *logic* at all. Show me a compiler than can say "your binary search has an off-by-one bug in it" as part of the compilation process. Considering how much static typing hinders the development process, I'd hardly consider that tradeoff to be "for free". And I'll emphasis *again*, seeing as you snipped it, that Python is much easier to write tests in, which speeds up development. You admit that you still need tests in a statically typed language... so what exactly is your compiler checking doing for you? Minimal correctness checking for something you're testing anyway? > > Besides, if you don't trust the "Joe Programmer"s of your team to > > write code competently, I suspect your project is doomed already. > > Big projects are filled with the bell curve. Not to mention stress under > deadlines, which ruins the code of even good programmers. I doubt that trivial typos are the worst bug a stressed programmer would introduce. -Andrew. From GavinT at ResMed.com.au Mon Aug 25 19:34:31 2003 From: GavinT at ResMed.com.au (Gavin Tomlins) Date: Tue, 26 Aug 2003 09:34:31 +1000 Subject: Python MySQLDump Scripts Message-ID: Greetings All, I've done a bit of search on the web for python scripts to automate the backup of MySQL databases but haven't had much success. I've come across a decent PERL module and are thinking about porting that, however I just wished to see if anyone has any snippets available prior to taking this path. I do have specific criteria however I'm just wishing to see in general what people have done and what solutions may be available. Regards Gavin Warning: Copyright ResMed. Where the contents of this email and/or attachment includes materials prepared by ResMed, the use of those materials is subject exclusively to the conditions of engagement between ResMed and the intended recipient. This communication is confidential and may contain legally privileged information. By the use of email over the Internet or other communication systems, ResMed is not waiving either confidentiality of, or legal privilege in,the content of the email and of any attachments. If the recipient of this message is not the intended addressee, please call ResMed immediately on +61 2 9886 5000 Sydney, Australia. From elainejackson7355 at home.com Thu Aug 28 01:09:22 2003 From: elainejackson7355 at home.com (Elaine Jackson) Date: Thu, 28 Aug 2003 05:09:22 GMT Subject: another puzzled newbie Message-ID: <68g3b.855589$ro6.16997110@news2.calgary.shaw.ca> The analogous thing works fine in interactive mode, but when I put it in a script, the function singlePass (below) causes a compile-time error. (Interpret-time error? What I mean is, the message appears as soon as the shell window opens.) Can anybody tell me what I'm stumbling over? As a point of historical interest, this stuff was suggested by some material in Chapter 15 of the ibiblio tutorial at http://www.ibiblio.org/obp/thinkCSpy/chap15.htm Peace, EJ def shuffleList(preshuffled): from random import randrange n=len(preshuffled) shuffler=[] for i in range(n): shuffler+=[randrange(i,n)] return shuffler def singlePass(shuffler,preshuffled,postshuffled): postshuffled+=[preshuffled[shuffler[0]] del(preshuffled[shuffler[0]]) del(shuffler[0]) for i in range(len(shuffler)): shuffler[i]+=(-1) def shuffle(preshuffled): shuffler=shuffleList(preshuffled) postshuffled=[] for i in range(len(preshuffled)): singlePass(shuffler,preshuffled,postshuffled) preshuffled=postshuffled From clay at shirky.com Sat Aug 16 21:33:39 2003 From: clay at shirky.com (Clay Shirky) Date: 16 Aug 2003 18:33:39 -0700 Subject: Jython and J2ME Message-ID: <25373bfe.0308161733.2fd5bb64@posting.google.com> Can Jython be used to write applications to run in J2ME environments? I ask because Python seems an ideal language for teaching students to write applications for the phone or other mobile devices. If this is possible, I would be grateful for any pointers to a Jython/J2ME reference. -clay From Rastm2 at users.sourceforge.net Mon Aug 11 04:10:55 2003 From: Rastm2 at users.sourceforge.net (Raymond A. St. Marie) Date: 11 Aug 2003 01:10:55 -0700 Subject: Slogan: Getting *Slogan* Overnight References: Message-ID: <5540514a.0308110010.75d21f2a@posting.google.com> Christian Tismer wrote in message news:... > Ben Finney wrote: > > > On Sun, 10 Aug 2003 23:56:01 +0200, Christian Tismer wrote: > > > >>But is there any way for such a slogan to pass spam at all? > > > > > > The much greater battle is: if it passes electronic/programmatic > > filters, how are you going to get it past the wetware filters -- i.e., > > the fact that it just sounds like spam when you hear it? > > It does not sound like spam when you read it. > Getting you to read it is the trick. > Hey, Christian, How about... P rograms Y ou T hink-up H appen O ver N ight >From some thoughts I was having along the lines of... P rogram (-ming? | -s? [ending sounds like mind contol]) Y our T houghts (thinking) H appen-ing (-s?) (handleing objects [naturally | natively]) O bjectivley N ow I nterpret (-ed | -er) (Indented? [this is implied]) S tyle (scripts) T hat A ll ({anyone sees}|{accomodates seeing}) S ee Ray St. Marie Rastm2 at users.sPAMBLOCKERourceforge.net From heikowu at ceosg.de Tue Aug 12 10:28:04 2003 From: heikowu at ceosg.de (Heiko Wundram) Date: 12 Aug 2003 16:28:04 +0200 Subject: union in Python In-Reply-To: References: Message-ID: <1060698484.844.45.camel@d168.stw.stud.uni-saarland.de> On Tue, 2003-08-12 at 15:00, Wiebke P??tzold wrote: > about union I found still something else. Perhaps it is better. But > here the program doesn't run too. > Can me somebody help? First thing to do, again, when asking about errors in a Python program, cut+paste your exception here, as nobody will be able to run the code on his machine with e.g. the file datafile.mk missing. Second thing to do, again, go and learn some Python, so that you can fix the bugs and understand the error messages yourself, it doesn't seem that you can (otherwise you wouldn't have posted without an Exception Traceback in the first place, I guess). Third thing to do, again, don't ask the group this bluntly to write your code. If you pay me, I'll do so, if you don't, I won't. It's about helping here, not about getting something done in time for another because he/she has no interest to get into Python him/herself. And at least I won't help in such a case. Heiko. From jerry at jerrysusedcars.com Sat Aug 30 14:15:14 2003 From: jerry at jerrysusedcars.com (www.jerrysusedcars.com) Date: Sat, 30 Aug 2003 11:15:14 -0700 Subject: Jerry Brewster's new email address Message-ID: Due to the overwhelming number of SPAM emails we are receiving, we are forced to change our email address. TO EMAIL US regarding an eBay auction or anything else, you will have to do 1 of 2 things: 1) goto www.jerrysusedcars.com and click on the email link on the left side of the page; OR 2) goto one of our eBay auctions and click on our eBay USER ID at the top of the page: jerrysusedcars We are sorry for the inconvenience. Jerry Brewster From prouleau_nospam_atall_ at impathnetworks.com Wed Aug 20 11:55:49 2003 From: prouleau_nospam_atall_ at impathnetworks.com (Pierre Rouleau) Date: Wed, 20 Aug 2003 11:55:49 -0400 Subject: It is possible to pass a Python callback to C-extensions? Message-ID: I have a GUI application written in Python (with WxPython) which uses some low level classes also written in Python. These low level Python classes are given a pointer to some GUI Python object. The low level Python classes callback some of the methods of the GUI object. All works fine. Now I want to convert the low level Python classes to C++. I will be using SWIG to create the marshaling so the top level GUI, written in Python stays that way. The problem: is it possible to continue using call backs? The C++ code would need to call the Python methods back. Is there an easy way to do this? This is a little different from extending or embedding. I have a Python program that uses Python extensions written in C++. This C++ code would need to pass some information back to the Python code (and currently, the all-round Python code uses call backs). My quick review of the SWIG documentation did not help me find a solution to this. Thanks in advance for any help. /Pierre From Simon.Wittber at perth.maptek.com.au Mon Aug 11 22:26:07 2003 From: Simon.Wittber at perth.maptek.com.au (Simon Wittber (Maptek)) Date: Tue, 12 Aug 2003 10:26:07 +0800 Subject: Python should try to displace Java Message-ID: <20E0F651F8B82F45ABCBACC58A2D995B032BAC@mexper1> Istvan Albert wrote: >still trolling eh, > >but you try too hard and it shows, It is fun to watch though! From danbmil99 at yahoo.com Fri Aug 8 10:12:46 2003 From: danbmil99 at yahoo.com (dan) Date: 8 Aug 2003 07:12:46 -0700 Subject: midi with ctypes References: Message-ID: Ok, interesting points. But what I think is important is that we agree on a cross-platform interface, ie a set of python routines that cover everything you want to do with MIDI. I agree that ctypes looks like an easy way to do this quickly. Later on, we could re-implement in C/C++ if this seems necessary for performance reasons or any other. One point worth thinking about: a serious MIDI library would include a method for scheduling low-level routines at exact times (similar to a sound output buffer). This would almost by definition require some C code. anton at vredegoor.doge.nl (Anton Vredegoor) wrote in message news:... > danbmil99 at yahoo.com (dan) topposted: > > >Interesting idea, but frankly it seems like alot of extra overhead. > >Now that midipy is compiling, I'm more inclined to add features in C > >than using ctypes. > > The microsoft visual C compiler is about half a gigabyte size, the > soundfont SDK from creative labs is about 20 megabyte size, the OSC > toolkit is about 3 megabyte size, the midipy.cpp is a few kilobyte > size. > > Compare this with the ctypes solution: ctypes itself is about half a > megabyte size and the ctypesmidipy.py is taking a few kilobytes. > > From this comparison one could conclude that the overhead is largely > on the side of the current solution using C. > > >What advantages can we expect from doing it this way? > > The ctypes solution is cheaper, there are less license issues because > there are less parties involved, it's a lot less code so it's easier > to understand and maintain, programming this module in Python gives > extra flexibility, and most importantly this could be a platform > independent solution for MIDI programming. That would earn Python > extra kudos from music programmers. > > Anton From jjl at pobox.com Sat Aug 2 09:34:36 2003 From: jjl at pobox.com (John J. Lee) Date: 02 Aug 2003 14:34:36 +0100 Subject: HTML DOM parser? References: <7x7k5y5wfh.fsf_-_@ruckus.brouhaha.com> <4de76ee2.0308011420.14f309f8@posting.google.com> <7x4r10oc8l.fsf@ruckus.brouhaha.com> Message-ID: <87el04yyhf.fsf@pobox.com> Paul Rubin writes: > calfdog at yahoo.com writes: > > Here is a quick example of using automation with IE > > # This is a sample of automating IE using Python. > > Thanks, I should have said I'm running under gnu/linux and I was > hoping for a standalone solution (some of the ones suggested sound > worth looking into). Even connecting up Python to Mozilla sounds > awfully heavyweight. PyKDE is less hassle, I think. It's certainly heavyweight, though. Probably more lightweight still is HttpUnit on Jython. I haven't used either, but I have compiled PyKDE recently, and didn't run into problems (but if you're unlucky, you may have to compile Qt, KDE, sip and PyQt first!). I seem to have got a basic JavaScript wrapper working now (I'm using libjs from Mozilla's standalone spidermonkey distribution), bound 4DOM to it, and extracted & executed the script from a web page. Quite a lot more to do, though (browser-like interface of some sort, javascript: scheme URLs, implement window object, wiring up event attributes to the JS interpreter, getting the DOM actually working propertly, understanding what document.write does, trying to connect the DOM to my Python HTML form and HTTP cookies interfaces...). Anybody happen to know where JavaScript's document.some_form is documented? Official W3C DOM has document.forms, but real browser DOMs apparently have forms directly on the document object. John From duncan at NOSPAMrcp.co.uk Thu Aug 7 10:53:47 2003 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Thu, 7 Aug 2003 14:53:47 +0000 (UTC) Subject: filter()ing a dict References: <16469f07.0308070559.aed41a@posting.google.com> Message-ID: "John Roth" wrote in news:vj4p5t8l96201 at news.supernews.com: > According to the doc, filter() processes sequences, > iterators and objects that support the iterator protocol. > A dict is none of those things, unless it supports the iterator > protocol, which is not mentioned in the documentation > as of 2.2.3. Possibly it does in 2.3.0. It looks to me like there is a hole in the Python documentation. The "what's new in Python 2.2" said: > Iterator support has been added to some of Python's basic types. > Calling iter() on a dictionary will return an iterator which loops > over its keys: However, the library reference documentation for mapping types doesn't seem to mention that dictionaries support the iterator protocol directly, although it does mention the explicit ways to get iterators out of dictionaries (such as iteritems()). -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From simon_place at whsmithnet.co.uk Thu Aug 7 18:39:04 2003 From: simon_place at whsmithnet.co.uk (simon place) Date: Thu, 07 Aug 2003 23:39:04 +0100 Subject: Hints about a script that read ftp contents .... In-Reply-To: References: <3f318f5d_3@mk-nntp-1.news.uk.worldonline.com> Message-ID: <3f32d51c_1@mk-nntp-1.news.uk.worldonline.com> according to the info i've got reply '211' like all the '2??' replies are confirmation of a correctly completed command? 'stat' transfers its result over the control socket, i think retrlines is looking for a result on the data socket, which is what the 'list' command does, or 'nlst' which just includes file names. so: from ftplib import FTP ftp = FTP('ftp.python.org') # connect to host, default port ftp.login() a=ftp.sendcmd('stat *',a.append) ftp.quit() print a or for a list; from ftplib import FTP ftp = FTP('ftp.python.org') # connect to host, default port ftp.login() a=[] ftp.retrlines('list *',a.append) ftp.quit() print a or for a file name list; from ftplib import FTP ftp = FTP('ftp.python.org') # connect to host, default port ftp.login() a=[] ftp.retrlines('nlst *',a.append) ftp.quit() print a unfortunately none of these do a recursive search if you add the extension ,so 'nlst *.pdf' only searches the current directory, but your going to have to manipulate the list returned anyway so filtering pdf is trivial. From mschneider.pad at t-online.de Sat Aug 16 14:38:28 2003 From: mschneider.pad at t-online.de (Marcus Schneider) Date: 16 Aug 2003 11:38:28 -0700 Subject: Modifying TKinter widgets defined in Modules References: <3f443b52.0308151251.7e6bbaaf@posting.google.com> Message-ID: <3f443b52.0308161038.1af149d9@posting.google.com> Michael, that is very interesting; in the meantime I managed for the first time to create an instance of a class that contains my TKinter widgets in a module, so I obviously messed around with some basics... But my questionw as also about "style" of programming Python. Would I want to use modules just for the widget definition or would I rather want to put widgets and functions together in one module? What kind of structure is considered to by "good style" in Python? Thanks for the patience... "Michael Peuser" wrote in message news:... > Marcus, > I have no clear concept of your problem ("nix verstehen"). Newbie? What is a > "main"? What in fact is the overall structure of your software system? You > have first di decide where to put your "variables". In Python you will > generally use an object. This can be made visible as you like. You however > have do decide who instantiates this object ("main" or one of the "moduls")? > > The best way seems to do this in your "main": > > class Data: pass > myData=Data() > > Put all your 25 variables into it (myData.varX=None ....), then you pass > "myData" as a parameter to your moduls... > > Is this what helps? > Kindly > Michael P > > > "Marcus Schneider" schrieb im Newsbeitrag > news:3f443b52.0308151251.7e6bbaaf at posting.google.com... > > Sorry if this is an extremely stupid question: > > > > I produced some Python modules with TKinter stuff and now I want to > > use that from my main program. The windows have wuite some user > > interaction. It's easy to bring them to the screen, but how do I make > > the communication (i.e. variables) between the main and the modules > > happen? > > > > Currently I call a function from the main and pass all variables in > > the function call, but with more then 25 variables this looks odd. > > > > And now I have to change variables in the main from the module and > > that doesn work at all, does it? > > > > Or can I access widget definitions from the main?? > > > > What is the usual, elegant way to handle that? > > > > Thanks for any hint ;) From geoff at gerrietts.net Tue Aug 26 19:34:58 2003 From: geoff at gerrietts.net (Geoff Gerrietts) Date: Tue, 26 Aug 2003 16:34:58 -0700 Subject: String find and replace In-Reply-To: References: Message-ID: <20030826233458.GF27158@thoth.homegain.com> Quoting hokieghal99 (hokiegal99 at hotmail.com): > import os, string > print " " > setpath = raw_input("Enter the path: ") > def find_replace(setpath): > for root, dirs, files in os.walk(setpath): > fname = files > for fname in files: > find = string.find(file(os.path.join(root,fname), 'rb').read(), 'THIS') ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this string is never bound to a name (ie, you never assign str=file(...).read()) > print find > if find >=1: > replace = string.replace(str, 'THIS', 'THAT') ^^^ this name is currently bound to the builtin function str() > find_replace(setpath) > print " " You might consider the fragment below, instead. It's a couple lines longer, but safer (your .close() happens exactly when you want it to) and probably more readable. for root, dirs, files in os.walk(setpath): fname = files for fname in files: myfile = file(os.path.join(root,fname), 'rb') mystr = myfile.read() myfile.close() find = string.find(mystr, 'THIS') print find if find >=1: replace = string.replace(mystr, 'THIS', 'THAT') Luck, --G. -- Geoff Gerrietts "information 'wants' to be free in the same way nature 'abhors' a vacuum: it's not some moral view, it's http://www.gerrietts.net/ just the natural state of affairs." -- jwz From gregadelliot at hotmail.com Sat Aug 16 09:18:53 2003 From: gregadelliot at hotmail.com (jeff) Date: 16 Aug 2003 06:18:53 -0700 Subject: detecting -addition, deletion or change to files Message-ID: Hiya I just woundering how would I go about detecting addition, deletion or change to files in a folder? Ideally id like to look at a linux directory and say watch all its contents and then have my script flag up a message when one of these events occurs not only would it want to watch the directory, but also the subdirectorys off of it cheers greg From gh at ghaering.de Tue Aug 5 12:26:55 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Tue, 05 Aug 2003 18:26:55 +0200 Subject: Needs programming tip using date In-Reply-To: <55939F05720D954E9602518B77F6127F030967EB@FTWMLVEM01.e2k.ad.ge.com> References: <55939F05720D954E9602518B77F6127F030967EB@FTWMLVEM01.e2k.ad.ge.com> Message-ID: <3F2FDACF.9010600@ghaering.de> Raaijmakers, Vincent (IndSys, GE Interlogix) wrote: > I think this is a bit of a newbie question in the dates area. Ok, the first thing you should do is download and install the eGenix BASE package [1]. If you have a half-way decent operating system, you can also install it via the package manager or ports system ;-) > So before I end up in very ugly coding, > What is THE/recommended way in checking if a date formatted as "08/05/2003", so "month/day/year" > is the date of today or a date of the current week? from mx.DateTime import DateTimeFrom, now dt = DateTimeFrom("08/05/2003") if dt.iso_week[1] == now().iso_week[1]: print "date is in current week" You'll want to check if the definition of iso_week matches your definition of 'week'. [2] -- Gerhard [1] http://www.egenix.com/files/python/eGenix-mx-Extensions.html [2] http://www.egenix.com/files/python/mxDateTime.html From adechert at earthlink.net Fri Aug 8 11:35:15 2003 From: adechert at earthlink.net (Alan Dechert) Date: Fri, 08 Aug 2003 15:35:15 GMT Subject: Python - PC based Voting Machine Project Announcement Message-ID: Just getting underway on SourceForge.... 15 volunteers so far including several from CLPY. We can still use more help! *********** Silicon Valley Computer Scientists Team Up To Demonstrate Free Voting Machine Alan Dechert Friday, August 8, 2003 Scientists and engineers from the Silicon Valley have started a project aimed at developing a PC based voting machine they claim will be easier to use, more tamper-resistant, and cheaper than commercially available voting machines. The target for completion of the demonstration project is mid-October. If successful and fully funded, certified ready-to-use software could be available in about a year. Computerized voting offers many advantages over traditional systems, including, - The ability to easily handle multiple languages, - Meeting the needs of voters with disabilities, - Eliminates problems such as overvoting and other voter intent issues. High quality refurbished PC's that are only one generation old exist in great abundance and have more than enough power to make great voting machines. More than 25 million such PCs are retired annually in the United States alone. Less than 10 percent of these PCs would be needed for all the voting booths in the U.S. The concept has already been demonstrated in Australia where, in 2001, the Australian Capital Territory government commissioned the development of open source software to run on trailing-edge PCs set up in polling places as voting machines. The current open source software development project, known as EVM, includes participants from around the United States as well as developers from overseas. EVM will differ from the Australian system in several ways. Most importantly, the machine will include a printer from which a completed paper ballot will be produced. It will work with either a touch screen PC monitor or a regular PC monitor and mouse. The project developer, Alan Dechert, got EVM going with help from Stanford computer scientist David Dill, who referred several people to him. Arthur Keller, a UC Santa Cruz computer science professor, recruited one of his former students, Adrianne Yu Wang of San Jose, to be the Team Lead. Along with Ed Cherlin of Cupertino and Jack Walther of Santa Cruz, they chose to use the Python computer language for development of the demonstration system. Douglas W. Jones, a University of Iowa computer science professor and world-renowned expert on voting technology, is taking a very active role as advisor and mentor. Other volunteers include Dr. David Mertz of Massachusetts, a well-known writer on computer programming issues, who has also taken a very active role. Additional key people include QA Lead Matt Shomphe of Los Angeles, and Lead Developer Anand Pillai of Bangalore, India. Van Lindberg (Utah), Skip Montanaro (Illinois), Dennis Paull (California), and Matteo Giacomazzi (Italy) are all contributing their expertise to the project. Jay Tefertiller, Ben Strednak, and Steve Gardner of ISIS Technology (Oklahoma City) are developing the non-proprietary hardware design, and working on establishing a trade association, tentatively called the "Open Voting Consortium," that will establish and maintain high standards for the open voting hardware. The EVM project is using the services offered at SourceForge.net, the world's largest Open Source software development web site, to store source code and documentation, track issues, and manage the project. Developers want to demonstrate a voting system where all components are open for public inspection and debate. Consistent with this idea, all aspects of the development of the software are open to the public also. The direct URL for the project is at, http://sourceforge.net/projects/evm2003 The demonstration standalone voting machines will be set up at strategic locations, for example, in the Silicon Valley area and Sacramento. A web based version will also be available so that anyone with Internet access can try out the look and feel of the system. EVM project proponents hope that this successful demonstration project will lead to a very large well-funded academic study that will capitalize on other efforts to bring about a modern, reliable, affordable, uniform, and fully auditable voting system. While designed to be certified in the United States first, it will be built from the ground up as an international voting machine. The larger study will include not only the development of voting machine software, but all software necessary for election administration, and an Election Rules Database that will document all election rules in effect in all jurisdictions in the United States. More background information can be found here: http://home.earthlink.net/~adechert If you want to help with the EVM project, contact, Alan Dechert 916-791-0456 4700 Allegretto Way Granite Bay, CA 95746 adechert at earthlink.net To receive updates about EVM via email, write to EVMinfo at aol.com From mike at nospam.com Fri Aug 15 13:38:12 2003 From: mike at nospam.com (Mike Rovner) Date: Fri, 15 Aug 2003 10:38:12 -0700 Subject: Strange re behavior: normal? References: Message-ID: Fredrik Lundh wrote: > Mike Rovner wrote: >> IMHO that split behavior is a bug although technicaly it is not. >> (From re manual: >> "This module provides regular expression matching operations similar >> to those found in Perl.") > > is "split" really a matching operation? > > fact is, all methods have Python-specific behaviour. it's just the RE > language itself that's based on Perl. With all due respect to Python and not trying to bend it to any other language I believe it trys to do what user expects. string.split() splits on (clearly documented nonempty) substring. re.split() splits on RE. splut(r'\b',...) clearly means (at least for me) 'split on word boundary' It doesn't reject it (as in r'\b?') nor provide expected behavior. I understand why it does what it does, but don't agree with it. Regards, Mike From skip at pobox.com Wed Aug 6 21:54:15 2003 From: skip at pobox.com (Skip Montanaro) Date: Wed, 6 Aug 2003 20:54:15 -0500 Subject: dl + getenv (without arguments) = segfault (python2.p2, python2.3) In-Reply-To: <39929.24.199.120.198.1060217799.squirrel@mail.darkscape.net> References: <39929.24.199.120.198.1060217799.squirrel@mail.darkscape.net> Message-ID: <16177.45383.609658.100507@montanaro.dyndns.org> Xavier> Do note that my previous e-mail was not implying my possible Xavier> ignorance to the 'dl' module's functionality, but instead Xavier> inquiring wether there is or may be a solution in the future for Xavier> Python to handle such an erronous outcome. And plus, segfaults Xavier> are ugly and make me cry. I understand. Given the nature of the problem here, I suspect the segfault occurred in getenv() (I can't check to be sure, as I don't have the dl module). It's kind of hard for Python to gracefully recover when it doesn't control the program counter. Skip From sismex01 at hebmex.com Wed Aug 27 15:34:01 2003 From: sismex01 at hebmex.com (sismex01 at hebmex.com) Date: Wed, 27 Aug 2003 14:34:01 -0500 Subject: Rebol Size Message-ID: [Rodrigo Benenson] > (http/ftp/telnet/etc/etc/etc) > All of the above comes the 500 Kb Rebol/View distribution !! > ["otoh"] > To do the same thing in python I would need: > > Python (>5 Mb) > Twisted (>5 Mb) > Imaging (>400Kb) > ------------------- > More than 10 Mb > ["question"] > > But how to explain such a difference ? > [true answer] > Ok, python probably is a little faster > and is a programming language, not a scripting one. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ See, I knew you already knew. :-) > > Rodrigo Benenson. > -gustavo Advertencia:La informacion contenida en este mensaje es confidencial y restringida, por lo tanto esta destinada unicamente para el uso de la persona arriba indicada, se le notifica que esta prohibida la difusion de este mensaje. Si ha recibido este mensaje por error, o si hay problemas en la transmision, favor de comunicarse con el remitente. Gracias. From ozzyparrot at rocketmail.com Mon Aug 4 19:45:31 2003 From: ozzyparrot at rocketmail.com (Darren) Date: Mon, 04 Aug 2003 16:45:31 -0700 Subject: Python and Robotics? In-Reply-To: <3F2D58AF.9000705@norfolkgraphics.com> References: <3f2d1e1d$0$4192$afc38c87@news.optusnet.com.au> <3F2D58AF.9000705@norfolkgraphics.com> Message-ID: <3f2e0061$0$4189$afc38c87@news.optusnet.com.au> Thank you to all that gve me the pyro (Python Robotic) webpage! I think this may do nicely:) all i have to do is read and learn now lol. Many Thanks Darren Alan McIntyre wrote: > There's Pyro, which is # 3 on this list: > > http://www.google.com/search?hl=en&lr=&ie=UTF-8&oe=UTF-8&q=python+robotics > > Hope this helps, > Alan > > Darren wrote: > >> Hello All, >> Hope everyone is well. >> I am really new to python, so my question maybe some what stupid to >> some. The question is, can python be used as a programming language >> for robotics? eg, controling motors and sensors? >> If so, do you know any website that would contain such information ? >> >> Many thanks >> Darren >> > From imbosol at aerojockey.invalid Wed Aug 20 23:56:54 2003 From: imbosol at aerojockey.invalid (Carl Banks) Date: Thu, 21 Aug 2003 03:56:54 GMT Subject: Backtick Virgins Message-ID: Who else? -- CARL BANKS http://www.aerojockey.com/software "You don't run Microsoft Windows. Microsoft Windows runs you." From james.kew at btinternet.com Wed Aug 20 17:48:01 2003 From: james.kew at btinternet.com (James Kew) Date: Wed, 20 Aug 2003 22:48:01 +0100 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: Message-ID: "Brandon J. Van Every" wrote in message news:bhrh1b$29lum$1 at ID-203719.news.uni-berlin.de... > Jeff Epler wrote: > > PS I'd just like to state for the record that neither Python nor Ruby > > have a totally compelling advantage compared to the following > > > > K&R C > > Even as one who hasn't converted to Python yet, that statement is clearly > insane. Not at all: there are many applications in which K&R C is a more appropriate language than Python. Compelling advantages, yes. But "totally" compelling, no: if that were the case it'd be Python-or-not-at-all in all cases. James From dave at boost-consulting.com Tue Aug 26 21:17:00 2003 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 26 Aug 2003 21:17:00 -0400 Subject: OT: Ocaml? References: <7xk795xde6.fsf_-_@ruckus.brouhaha.com> <7h3wud0zihr.fsf@pc150.maths.bris.ac.uk> Message-ID: Michael Hudson writes: > Donn Cave writes: > >> Incidentally, a few years back someone got fairly far along on >> implementing Python (or something like it) from scratch in >> Objective CAML. > > That was John Max Skaller, and the code is still on sf: > > http://vyper.sf.net > > If you're really curious and the anon CVS isn't working, I can stick a > tarball somewhere. Now he's on to his next interesting OCaml based language, Felix: http://felix.sf.net -- Dave Abrahams Boost Consulting www.boost-consulting.com From mack at incise.org Wed Aug 27 20:22:30 2003 From: mack at incise.org (mackstann) Date: Wed, 27 Aug 2003 19:22:30 -0500 Subject: Script Discussion & Critique In-Reply-To: <3F4D4402.3060209@hotmail.com> References: <3F4D31B1.6080802@hotmail.com> <06eqkv4onjh5m4tcbbqkmh8lscaj5niatp@4ax.com> <3F4D4402.3060209@hotmail.com> Message-ID: <20030828002230.GA1695@incise.org> Looks good, there is one small bug and a couple very minor things that basically boil down to style and personal preference. ----------------------------------------------------------- import os # no need for string # this can just go in one print with triple quotes print """ ****************************************************** Three Easy Steps to a Recursive find and Replace ****************************************************** """ x = raw_input("1. Enter the string that you'd like to find: ") # if you just want a newline, you can just do a print by itself print y = raw_input("2. What would you like to replace %s with: " %x) print setpath = raw_input("3. Enter the path where the prgroam should run: ") print for root, dirs, files in os.walk(setpath): fname = files # what's this for? fname will just get reassigned on # the next line. for fname in files: inputFile = file(os.path.join(root,fname), 'r') data = inputFile.read() inputFile.close() search = data.find(x) # .find is a method of str, you don't need # the string module for it. # bug #if search >=1: # this won't find it at the beginning of the file. if search >= 0: # change to this (find returns -1 when it finds # nothing) data = data.replace(x, y) outputFile = file(os.path.join(root,fname), 'w') outputFile.write(data) outputFile.close() print "Replacing", x, "with", y, "in", fname # You could also do something like this to print out the centered # messages: print "*"*10 print "Done".center(10) print "*"*10 ----------------------------------------------------------- HTH, -- m a c k s t a n n mack @ incise.org http://incise.org Dentist, n.: A Prestidigitator who, putting metal in one's mouth, pulls coins out of one's pockets. -- Ambrose Bierce, "The Devil's Dictionary" From martin at v.loewis.de Sun Aug 3 16:11:46 2003 From: martin at v.loewis.de (Martin v. =?iso-8859-15?q?L=F6wis?=) Date: 03 Aug 2003 22:11:46 +0200 Subject: Python and XML References: <3F2D5656.5020602@frheaven.com> Message-ID: "Matthieu M." writes: > In fact I've done all this things in the Python Shell, otherwise, when > I lauch it with "python foo.py" I've got the same kind of errors. > I think the problem comes from here, but I'm not skilled in Python, so... Sorry, I have no idea why it fails to find the dom package. Regards, Martin From mwilson at the-wire.com Fri Aug 1 10:19:17 2003 From: mwilson at the-wire.com (Mel Wilson) Date: Fri, 01 Aug 2003 10:19:17 -0400 Subject: string/file manipulation simple References: Message-ID: In article , gregadelliot at hotmail.com (jeff) wrote: >I was just creating an encryption/ decryption program in python, ive >got no problem with the algothims or anything like that. my only >difficulty is how to i take a file and read in each charecter and then >preform and operation to it and then output it to another file, >basically i just wanna know how to take a string and then perform >actions to each charecter I think (untested code ahead), for small files whose contents fit comfortably in memory: for character in my_input_file.read(): my_output_file.write (modified (character)) For large files, some variant of characters = my_input_file.read (1024) while characters: for char in characters: my_output_file.write (modified (char)) characters = my_input_file.read (1024) with the buffer-size changed from 1024 to some better number, if necessary. Regards. Mel. From R.Brodie at rl.ac.uk Wed Aug 6 07:49:27 2003 From: R.Brodie at rl.ac.uk (Richard Brodie) Date: Wed, 6 Aug 2003 12:49:27 +0100 Subject: Isn't there a substring(start, end)-function???? References: Message-ID: "Dave" wrote in message news:a3fc8520.0308060344.6c2302e4 at posting.google.com... > Am I blind, or what? >>> "If someone attacks you with a banana"[0:3] 'If ' From spam at yourself.pl Thu Aug 21 04:58:11 2003 From: spam at yourself.pl (Matthias) Date: Thu, 21 Aug 2003 10:58:11 +0200 Subject: What's better about Ruby than Python? References: <3F41505F.69D18CC8@alcyone.com> <66d7kvonvb2n0nqbqahhd5roak7ur81sob@4ax.com> <3f43ef5d_4@127.0.0.1> Message-ID: Chris Reedy wrote: > I'm curious. Why do you feel such a need for macros? With metaclasses, > etc., etc., what significant advantage would macros buy you? Do you have > any examples where you think you could make a significantly crisper and > easier to read and understand program with macros than without. The first thing I would do with macros in Python is build an inline-facility which allows certain functions being expanded whenever they are called. This would hopefully increase speed at the sake of space efficiency. Historically, macros have been used for building Prolog-like languages, constrained-programming languages, lazy languages, very flexible object oriented languages, etc. on top of Lisp. In newer days, Design Patterns can be coded into the language via macros. This enables you to program on a higher level of abstraction than with classes. You can express your patterns more clearly and much shorter than without them. Indeed, the C++ community, which does not have macros, uses (some would say: misuses) their template facility to do metaprogramming. They implement design patterns, inline numerical code, etc. The resulting template code is ugly. Compiler messages unreadable. Programming painful. But developers feel it is worth to do because the abstractions they build are powerful and run fast. Having said that, I totally agree with earlier posters who said that macros in the hand of bad programmers are catastophic. Where I don't agree is that therefore the language should be more limited than necessary. Matthias From gabriel.cooper at mediapulse.com Tue Aug 12 13:01:24 2003 From: gabriel.cooper at mediapulse.com (Gabriel Cooper) Date: Tue, 12 Aug 2003 13:01:24 -0400 Subject: Test to see if variable exists In-Reply-To: <2c6431ab.0308120759.26d6e124@posting.google.com> References: <2c6431ab.0308120759.26d6e124@posting.google.com> Message-ID: <3F391D64.6030108@mediapulse.com> lamar_air wrote: >I need an if statement to test if a variable exists in a pyton script > >eg. if var1 exists: > do this > else: > do this > If it's in a dictionary you can do this: var1.get('key','not found') ( just learned that all of 2 minutes ago ;] ) From rdacker at pacbell.net Mon Aug 11 18:22:17 2003 From: rdacker at pacbell.net (rdack) Date: 11 Aug 2003 15:22:17 -0700 Subject: mysql fieldnames Message-ID: <644f6688.0308111422.2f2c4a05@posting.google.com> how can i retrieve database names and fieldnames from mysql 4 using MySQLdb 0.9.2 from python 2.3? (on mac osx 10.2.6) From adsr at poczta.onet.pl Wed Aug 13 13:10:47 2003 From: adsr at poczta.onet.pl (AdSR) Date: 13 Aug 2003 10:10:47 -0700 Subject: Is Python your only programming language? References: Message-ID: <422a840f.0308130910.32af50d9@posting.google.com> "Joe Cheng" wrote... > I want to ask you hard-core c.l.p Pythonistas: Do you use Python for > everything? (and I'm counting Python + C extensions as just Python) Or do > you keep another language equally close at hand, and if so, what is it? And > finally, do you foresee a day when Python can be, for all practical intents > and purposes, your only programming language? At home, I use Python almost exclusively. This includes Jython from time to time. At work, I use whatever is needed, usually Java or C++. I haven't used Python "officially", but it was very helpful when I had to rewrite a couple of database tables into a different format/design. I also use it to try out concepts. Interactive mode/IDLE is a good replacement for a calculator too, as advertised. And man, does Python make me lazy :) It really makes you appreciate Guido & Co.'s work when you get back to some other language and have to do some "basic" thing like list or dictionary manipulation. Would I want Python to be my only language? Not really - it would be monotonous. That's why I read at least a tutorial for a new language from time to time. Slightly off-topic, I went to a zoo last Saturday and saw there a huge python that had just had its lunch. A truly terrifying sight. AdSR From imbosol at aerojockey.com Thu Aug 7 18:07:08 2003 From: imbosol at aerojockey.com (Carl Banks) Date: Thu, 07 Aug 2003 22:07:08 GMT Subject: filter()ing a dict References: <16469f07.0308070559.aed41a@posting.google.com> Message-ID: Robin Cull wrote: > My question is, does anybody else think that when calling filter(f, > dict), it should return a dict of the keys and values of the former > dict where the values satisfy the conditions defined by f()? Why shouldn't filter apply to the keys? You want it to apply to values, but don't you think someone else might want it for the keys? Who's to say what it should be? Better to just leave it take care of sequences. -- CARL BANKS "You don't run Microsoft Windows. Microsoft Windows runs you." From gerritvd at decillion.net Thu Aug 28 02:04:20 2003 From: gerritvd at decillion.net (Gerrit van Dyk) Date: Thu, 28 Aug 2003 08:04:20 +0200 Subject: My future Python IDE article References: Message-ID: <3f4d9aa8$0$64721@hades.is.co.za> Just my 2 cents worth: Xemacs/Emacs with python-mode bindings + pychecker and some screen editor for gui apps (wxDesigner/Boa for wxPython,BlackAdder/Qt Designer for Qt etc) Regards Gerrit From bokr at oz.net Sat Aug 9 12:49:19 2003 From: bokr at oz.net (Bengt Richter) Date: 9 Aug 2003 16:49:19 GMT Subject: Recommendation of a parser generator References: <87ptjfx7tg.fsf@pobox.com> Message-ID: On 09 Aug 2003 14:46:19 +0100, jjl at pobox.com (John J. Lee) wrote: >bokr at oz.net (Bengt Richter) writes: >[...] >> BTW, I wonder if there is a Python parser generator that will take >> a flex-format grammar as input. Then a transition would be easier. > >I agree, but flex isn't a parser generator, is it -- it's a >lexical scanner generator? > You're right. GNU Bison is that, but with the start-condition logic in flex I found I didn't need it. Regards, Bengt Richter From tdelaney at avaya.com Thu Aug 7 19:36:31 2003 From: tdelaney at avaya.com (Delaney, Timothy C (Timothy)) Date: Fri, 8 Aug 2003 09:36:31 +1000 Subject: Stupid string.split question Message-ID: <338366A6D2E2CA4C9DAEAE652E12A1DE9DFE8F@au3010avexu1.global.avaya.com> > From: Duncan Booth [mailto:duncan at NOSPAMrcp.co.uk] > > Brian Kelley wrote in > news:3f326199$0$3951$b45e6eb0 at senator-bedfellow.mit.edu: > > > Now, as for old chesnuts and long hot summers, if one could just do: > > > > "".join(list("ABCDEF").reverse()) > > > In what way would that be an improvement on writing > > "ABCDEF"[::-1] In-place reverse *and* returning the result. *stands proudly tall, smug expression on face* TIm Delaney From grante at visi.com Wed Aug 27 13:05:26 2003 From: grante at visi.com (Grant Edwards) Date: 27 Aug 2003 17:05:26 GMT Subject: Filtering virus-related e-mails? Message-ID: <3f4ce4d6$0$166$a1866201@newsreader.visi.com> Would it be possible for the python mailing list to filter out the "virus-warning" emails rather than posting them to the newsgroup? -- Grant Edwards grante Yow! Eisenhower!! Your at mimeograph machine upsets visi.com my stomach!! From graham at rockcons.co.uk Thu Aug 7 12:24:53 2003 From: graham at rockcons.co.uk (Graham Nicholls) Date: Thu, 07 Aug 2003 17:24:53 +0100 Subject: Extracting a short using struct - won't print. References: <3f3273f7$0$10777$afc38c87@auth.uk.news.easynet.net> <3F32758E.5734C64F@engcorp.com> <3f32779d$0$10780$afc38c87@auth.uk.news.easynet.net> <3f327aaf$0$10770$afc38c87@auth.uk.news.easynet.net> Message-ID: <3f327d55$0$18274$afc38c87@auth.uk.news.easynet.net> Graham Nicholls wrote: > Richard Brodie wrote: > >> ...snipped > > I told you it'd be something stupid! > I mean > x=data[1] > y=data[2] > don't I! > Thanks!!!! > Graham Which, of course works - one of the annoying things about learning a language is that you tend to assume its something more complex than it really is when you get an error. I'd see that in 2 seconds flat in a c program , of course, but then the compiler would help.. BTW How does one test python programs - because its interpreted, it often won't run bits of code till unexpected circumstances, so a syntax error can be hidden until runtime? Graham -- Graham Nicholls Rock Computer Consultancy From imbosol at aerojockey.com Tue Aug 12 00:13:07 2003 From: imbosol at aerojockey.com (Carl Banks) Date: Tue, 12 Aug 2003 04:13:07 GMT Subject: Fun with numbers - dammit, but I want a cast! References: <3f378fac$0$10778$afc38c87@auth.uk.news.easynet.net> <3f3792f2$0$18258$afc38c87@auth.uk.news.easynet.net> Message-ID: Terry Reedy wrote: > > "Carl Banks" wrote in message > news:yVVZa.764$u%2.33 at nwrdny02.gnilink.net... >> Terry Reedy wrote: >> > No, quite different. A C cast (at least usually) recasts a block > of >> > bits in a new role without changing the bits. >> >> Certainly not. Most type casts actually change bits. > > From what I remember both in my own code and others that I have read, > most casts, where 'most' is measured in frequency of occurence in > actual code, which is what I meant by 'usually'. I didn't like the wording. The way you said it, it sounded (whether you intended it or not) like you were saying: "C generally casts by preserving the bit pattern, except for a few exceptions," but that's not how it is. Even if they are more commonly used, casts that preserve the bit pattern are the special ones. The general rule is that C casts preserve "value." Sometimes the equivalent "value" happens to have equivalent bits: that's the case for int-to-pointer and pointer-to-pointer. [snip] >> and the C standard doesn't even guarantee that (unless >> C 2000 changed it). In fact, the C standard says (or used to say) >> that 0 must always cast to a null pointer, even if the system >> represents integer 0 and null pointer with different bits, which > does >> (or used to) happen. > > On which systems? How widely used? I also added 'at least usually' > to account for systems I don't know about ;-) Don't know of any examples off hand. The comp.lang.c FAQ lists some. >> IMO, a type cast is just a fancy name for an operator that takes an >> object and returns an object with the same "value" (whatever that >> means) but a different type. In C, type casting happens to have a >> funny syntax. In Python, it does not. If someone asked, "does > Python >> have type casting?", I would say yes, except there's no special > syntax >> for it. Rather, type casting is done by the calling type objects >> themselves. > > In my opinion, it is unhelpful to refer to type-function calls as > casts. To me, the baggage 'cast' carries is more confusing than > helpful. For instance, a common conversion, between number and > string, cannot be done in C with a type cast but must also (as in > Python) be done with a function call. Would you call C's atoi(), > atof(), and sprintf casts? In C, the 'funny syntax' defines what I > believe most people call a type cast versus a function call. This is > certainly true for both K&R and the Standard C committee. On one hand, I respect that opinion. OTOH, I think the assertion that Python has no type casting leads to misunderstanding. Take the OP for example. Because of the statement that Python has no type casts, he didn't realize that Python does have functionality of type casting. So I don't think anyone should say simply, "Python does not have type casts." Better, I think, to say, yes, Python has type casts, although we don't call them type casts 'round here because they look and act like regular function calls. And to answer your question, no: atoi, atof, and sprintf are not type casts even by my definition, because string is not a type in C. -- CARL BANKS "You don't run Microsoft Windows. Microsoft Windows runs you." From vze4rx4y at verizon.net Wed Aug 27 11:24:56 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Wed, 27 Aug 2003 15:24:56 GMT Subject: Proposal: Magic Constants References: Message-ID: [Chris Gonnerman] > The gist is this: Constants would be allowed to > be trailed by any single alphabetic character. > When compiled, a constant with a nonstandard > letter code would be stored in the compiled code > in the form of a text literal, appropriately > marked. > > When the code is executed, and the special > literal is processed, the interpreter would look > up a conversion function in an internal list. If > no conversion is found, a runtime error would be > raised. > > Modules to handle alternate numeric formats, such > as decimal, fixed-point, rational, etc. would > include a call to a builtin registration function > which would allow them to "take over" a specific > alphabetic specifier. -1 This should not be done for several reasons: * Constructors are more explicit: Rational(12, 3) * The appearance unpleasantly reminds me of VB * There are potential conflicts between alphabetic specifiers which results in hard to spot bugs. Doest "1.25D" represent the decimal class, Dewey decimals, or US dollars? * Previous discussions on special syntaxes initially found them to be enticing and then someone would realize that real programs rarely have more than a handful of constants that would benefit from the syntax. For instance, an accounting program is not filled with specific values like $1.83. Instead, it constructs nearly all of its data from user input or files. The program itself likely checks for zero and amounts being under $1.00. Those constants are easily and explicitly codeable with a normal constructor: Decimal("1.00", 2) or some such. * The registration process by-passes Python's elegant namespaces and makes global changes resulting in hard to diagnose effects: import bookaccounting # Hmm, did this just set D to DeweyDecimal? import Decimal # Did this just reset the value of D or was it F? . . . if foreign_currency: import Francs val = 15F # Was this the original F (for Fixed) or the # new F (for Francs) ? # Does it automatically convert from Euros? * Guido is already uncomfortable with the number of kinds of string literals: 'abc', u'abc', ur'abc', r'abc', etc. He is unlikely to adopt any related ideas for numbers. Other than that, it is a great idea ;-) Raymond Hettinger From newsgroups at jhrothjr.com Mon Aug 18 16:22:01 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Mon, 18 Aug 2003 16:22:01 -0400 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: <3F41208F.40021A68@engcorp.com> Message-ID: "Peter Hansen" wrote in message news:3F41208F.40021A68 at engcorp.com... > Daniel Dittmar wrote: > > > > Brandon J. Van Every wrote: > > > What's ***TOTALLY COMPELLING*** about Ruby over Python? What makes you jump > > > up in your chair and scream "Wow! Ruby has *that*? That is SO FRICKIN' > > > COOL!!! ***MAN*** that would save me a buttload of work and make my life > > > sooooo much easier!" > > > > Code blocks, although I'd rather go to the source and steal them from > > Smalltalk. > > What is it about code blocks that would let "save *me* a buttload of work > and make *my* life sooooo much easier"? It's not so much code blocks. It's that Ruby's syntax gives you one code block for free in every method call. And the Ruby library is organized so that the facility is useful, which Python's isn't (or at least, it isn't as useful.) All of the Ruby collections implement a .each method, which is essentially a version of the Visitor pattern. If I want to do something to every element in a list or a dict (or any kind of collection,) all I have to do is say something like (using Python syntax): collectObj.each() In Python, that's either a lambda (which restricts what you can do with it,) or a named function (which is overkill a huge amount of the time.) And you have to worry about distinctions between functions and methods. In other words, it's a mess compared to Ruby. Now, you can say: "We've got that with map()." Well, we've got it when your inputs are either lists (or implement the correct protocol) but the result is a list, it's not an internal modification to the object's state. You can also say: we can do that with for. Well, duh. For is a statement, not a method call. To continue on this vein, Ruby directly implements Visitor, Observer, Delegate and Singleton. I don't particularly like the way it does some of them, but Python can't claim any one of the four! Granted, you can do a clean singleton using new style classes and the __new__() method, but (as of 2.3) it's not anywhere in the core documentation that I could find. Observer is simply a couple of classes. Visitor I've discussed above, and I'll leave Delegate for the reader. > If one can't answer that, one shouldn't expect to be able to answer whatever > the heck it is Brandon has in mind (which is clearly not much), since > only he has any idea what it is he wants, and we're not even sure about that... It might be better to simply take the question at face value, rather than slanging Brandon. I don't find the personalities to add anything of value to the conversation. John Roth > > -Peter From enoch at gmx.net Wed Aug 6 11:05:02 2003 From: enoch at gmx.net (enoch) Date: 6 Aug 2003 08:05:02 -0700 Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> Message-ID: anthony_barker at hotmail.com (Anthony_Barker) wrote in message news:<899f842.0307310555.56134f71 at posting.google.com>... > I have been reading a book about the evolution of the Basic > programming language. The author states that Basic - particularly > Microsoft's version is full of compromises which crept in along the > language's 30+ year evolution. > > What to you think python largest compromises are? Its non existant SMP scalability. If you try to sell clients somewhat bigger server apps, they don't want to hear that having these run on a SMP system might (and will) actually _hurt_ performance without special administrative interference (processor binding), which isn't even possible on some older operating systems. We seem to be more or less at the end concerning ramping up single processor speeds, and SMP like hardware becomes more and more ubiquitous, e.g. Intel's Hyperthreading, IBM's SMP-on-a-chip, Sun's "Throughput Computing". As far as I know, there seems to be no interest to get rid of the GIL. To do this might be a big technical problem, but I fear if it stays the way it is, the actual trend in the hardware industry might work against python (in server apps) big time. From mwh at python.net Tue Aug 5 10:44:36 2003 From: mwh at python.net (Michael Hudson) Date: Tue, 5 Aug 2003 14:44:36 GMT Subject: xrange() question References: Message-ID: <7h3el0088rt.fsf@pc150.maths.bris.ac.uk> George Trojan writes: > Why do I get an overflow error here: > > > /usr/bin/python > Python 2.2.2 (#1, Feb 24 2003, 19:13:11) > [GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-4)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import sys > >>> for n, x in zip(range(4), xrange(0, sys.maxint, 2)): > ... print n, x > ... > Traceback (most recent call last): > File "", line 1, in ? > OverflowError: integer addition > > but not here: > > >>> for n, x in zip(range(8), xrange(0, sys.maxint)): > ... print n, x > ... > 0 0 > 1 1 > 2 2 > 3 3 > 4 4 > 5 5 > 6 6 > 7 7 The first thing to note is that it's not as subtle as you paint: >>> xrange(0, sys.maxint) xrange(2147483647) >>> xrange(0, sys.maxint, 2) Traceback (most recent call last): File "", line 1, in ? OverflowError: integer addition as to why, I imagine the latter computes something-or-other in a suboptimal way and overflows. You could try reading the source if you really care. Cheers, mwh -- Never meddle in the affairs of NT. It is slow to boot and quick to crash. -- Stephen Harris -- http://home.xnet.com/~raven/Sysadmin/ASR.Quotes.html From klappnase at web.de Fri Aug 8 06:52:07 2003 From: klappnase at web.de (klappnase) Date: 8 Aug 2003 03:52:07 -0700 Subject: Tkinter programming problem References: Message-ID: Alex Martelli wrote in message news:... > > IDLE 1.0 > > >>> import sys > > >>> sys.exit(23) > > > > Traceback (most recent call last): > > File "", line 1, in -toplevel- > > sys.exit(23) > > SystemExit: 23 > > >>> > > As you see, with the IDLE 1.0 which comes with Python 2.3, the > exception raised by sys.exit is captured and displayed as such > [and similarly if sys.exit is called from a module run within > the IDLE session, rather than directly at the IDLE prompt]. > Oh, that is interesting, my IDLE (python-2.2.2) exits on this. Does this happen with sys.exit(0) too? > Often one may want to do some kind of clean-up at that point, but you > may achieve that with a try/finally around the mainloop call (putting > the cleanup code in the finally clause, of course). > Seems like you mean something like: def quitcmd(): mainwindow.quit() do_this() do_that() If this is what you meant, what is the problem with: def exitcmd(): do_this() do_that() sys.exit(0) I do not think that there is much difference in the behavior of these. May be if I launched the application from a menu and the do_that() function does something really stupid that causes an endless loop, I think with quitcmd() it might occur that the window is closed and I think "Fine, the application is shut down" but the buggy do_that() is still running in the background. With exitcmd() this won't happen, the window will not close before do_that() comes to an end, so I will see that there is something wrong. Best regards Michael From dave at nullcube.com Thu Aug 7 00:43:06 2003 From: dave at nullcube.com (Dave Harrison) Date: Thu, 7 Aug 2003 14:43:06 +1000 Subject: using like and % in MySQLdb Message-ID: <20030807044306.GA442@dave@alana.ucc.usyd.edu.au> Im sure this is a really obvious problem but : self.curs.execute( """SELECT * FROM user WHERE login LIKE '%%s%'""", [login] ) will not work ... gives me an "unsupported format character ''' (0x27)" escaping the %'s with % as the doco recommends wont work either. however this : self.curs.execute( """SELECT * FROM user WHERE login LIKE '%dave%'""" ) does work so what's the go ? cheers Dave From adalke at mindspring.com Mon Aug 4 00:32:17 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Sun, 3 Aug 2003 22:32:17 -0600 Subject: True References: Message-ID: Daniel Klein: > > true = (1 == 1) > > false = not true > > > > This was at the recommendation of someone on this list some time ago. John Roth > There were no true booleans in 2.2 and earlier. Whoever recommended > that didn't know what he was talking about. There was no difference. Indeed, there were no true booleans in Python, but there were actual PyTrue and PyFalse objects at the C level. Doing the "1 == 1" trick would expose that implementation choice to Python. This was rarely used. The only place I know of is in the win32 code, where a COM API can take a boolean or an integer function. The win32 interface checks if the value is PyTrue/PyFalse, Here's relevant links http://mail.python.org/pipermail/python-list/1999-November/015260.html http://mailman.pythonpros.com/pipermail/pycom-dev/1999q1/000106.html Andrew dalke at dalkescientific.com From bsass at edmc.net Sat Aug 2 16:45:17 2003 From: bsass at edmc.net (Bruce Sass) Date: Sat, 2 Aug 2003 14:45:17 -0600 (MDT) Subject: useful tool for c.l.p In-Reply-To: <3F2BC264.55DE0865@hotmail.com> References: <3F2BC264.55DE0865@hotmail.com> Message-ID: On Sat, 2 Aug 2003, Alan Kennedy wrote: > [Behrang Dadsetan wrote] > > Would it not be wonderful to have some kind of integrated python > > interpreter within the news agent/email program, so one could kinda > > select the concerned code (or better, it is automaticly spotted) and > > just let it run within the mail? :) > > That's a nice idea. > > However, were you to actually go ahead and implement this idea, we > would then be exposing ourselves to serious security risks, since > people could post malicious code in their posts. As long as the code is not automatically executed it would not be much more of a security issue... > As Terry Reedy pointed out, it's not hard to fire up the interpreter > and paste the script into it. Python's conciseness makes that very > easy, even if the whitespace issue sometimes results in mangled code. ...because I don't see a difference between selecting code then executing it and select, cut'n'paste then execute. A standard [or] tool could include a sandbox, which you don't get with a simple cut'n'past into an interpreter. > And I always like to cast an eye over code before I run it, as a quick > sanity check that its not going to do anything I don't want or like > the look of. Always a good idea. While playing with Literate Programing (LP) and generally exploring Python awhile back I put together a proof-of-concept which lets you place code (noweb markup, can handle multiple files) in an email, have it automatically extracted when it hits the mail reader, then sent to an editor or IDE. Executing the code is just a click or keypress away. I figured that noweb markup was simple and unobtrusive, and treating the message as LP (with its "flexible order of elaboration") would be a good way to include programs, especially long examples, in email. However, since that sorta thing doesn't happen very often and it is easy to cut'n'paste, I didn't bother to develop it further. --- message body example --- lpmail: label1 label2 ...text... <>= ...code... @ ...more text... <>= ...code... @ ----- The code is on the 'net at: http://home.edmc.net/~bsass/lpmail.py Beware: it is a couple of years old and was a stream-of-conciousness project... but it works and should only be a security problem if the code text can tell the editor or IDE to automatically execute a buffer. - Bruce From chrisahlers at yahoo.com Wed Aug 27 21:17:52 2003 From: chrisahlers at yahoo.com (Chris) Date: 27 Aug 2003 18:17:52 -0700 Subject: asyncore: handle_accept() question? References: <3F4D3656.9119ECC1@alcyone.com> Message-ID: Everything works fine now. Your message made perfect sense. Thank you, Chris Erik Max Francis wrote in message news:<3F4D3656.9119ECC1 at alcyone.com>... > Chris wrote: > > > self.set_reuse_addr() # needed? > > This is definitely not needed in the connection; it's only useful in the > server. (I doubt this is your problem.) > > > My basic problem is that I don't know any other way to 'hand off' the > > incoming connection - if there is a better way to do this please let > > me know. conn.fileno() appears to work, and I don't understand why > > this error comes up. > > > > Any ideas? > > It looks like you're trying to do too much in your connection class > constructor. In the way you're using it, after accept is called, the > connection socket is already open and ready. You need not create or > initialize it; the fact that you're doing so is invariably what's > causing your error, although I'll admit I haven't tried to actually > reproduce it. In fact, after accept, initializing a connection is > simpler than simple. All you need to do is pass the socket into the > asyncore.dispatcher/asynchat.async_chat constructor: > > class Connection(asyncore.dispatcher): > def __init__(self, host, port, sock): > asyncore.dispatcher.__init__(self, sock) > # all done, your connection is ready to go > > As it stands, you're creating new sockets and attempting to connect to > the connection address of the _accepted_ socket (where there isn't a > server listening), so it looks like you're getting a partially > initialized socket which would explain your problem. From mark at diversiform.com Fri Aug 15 18:58:46 2003 From: mark at diversiform.com (Mark Daley) Date: Fri, 15 Aug 2003 15:58:46 -0700 Subject: Dictionary assignment In-Reply-To: <874r0isgmk.fsf@pobox.com> Message-ID: I'm becoming aware that my coding techniques leave much to be desired. That's ok, because I'm really just a hack with no education whatsoever. At any rate, I realize I didn't supply enough information. Here is the core of my dilemma: format[self.formats.get()][key] = current[key] Now, all disgust from my example aside, shouldn't this line cause a new key (whatever self.formats get() produces) whose contents are an exact copy of current? BTW, I do this to avoid those location references. I need to get an actual copy and this is the only way I can (currently) guarantee it. Believe me, I'm only treading water here! - Mark -----Original Message----- From: python-list-admin at python.org [mailto:python-list-admin at python.org]On Behalf Of John J. Lee Sent: Friday, August 15, 2003 3:25 PM To: python-list at python.org Subject: Re: Dictionary assignment "Mark Daley" writes: > I've been using this to save one dictionary as an entry in another > dictionary. I was working, but now it seems I've done something to break > it. Here's the code in question: > > def formatsave(self, args = None): > if self.formats.get() == '': > tkMessageBox.showwarning("No Format", "You must specify a format > name.") > else: > for key in current.keys(): > format[self.formats.get()][key] = current[key] > temp = format.keys() > temp.sort() > list = tuple(temp) Yuck. You've assigned something to a builtin (list). Strangely, the object you chose to bind to list is a tuple! > gui.formats._list.setlist(list) > > > Here's the error I'm getting: > > Traceback (most recent call last): > File "C:\PYTHON23\lib\lib-tk\Tkinter.py", line 1345, in __call__ > return self.func(*args) > File "C:\Python23\Layout.py", line 191, in formatsave > format[self.formats.get()][key] = current[key] > KeyError: 'Format 1' > > > Any ideas? Nobody here is likely to solve it for you. Get aquainted with the print statement! There are three indexes there -- which one is the exception coming from? Split them up, one index per line, and print out the results. You'll soon see the problem. print format[self.formats.get()] print format[self.formats.get()][key] print current[key] If you're like me, you'll want to make sure all debug print statements have a label, though, or you'll inevitably end up wondering (not now, but later) where the hell the output you're seeing on the screen is coming from. print "format[self.formats.get()]", format[self.formats.get()] print "format[self.formats.get()][key]", format[self.formats.get()][key] print "current[key]", current[key] John -- http://mail.python.org/mailman/listinfo/python-list From nospamius at lundhansen.dk Sun Aug 31 10:29:50 2003 From: nospamius at lundhansen.dk (Bertel Lund Hansen) Date: Sun, 31 Aug 2003 16:29:50 +0200 Subject: Declaration of an array of unspecified size Message-ID: Hi all I am relatively new to Python but have som programming experience. I am experimenting wit a POP3-program and it's fairly easy. I want to read the mails into an array of lists so I later can choose which one to display. But I need to declare an array of unknown size before I can use it in the code. How do I manage that? class PopMailServer: host = "" user = "" password = "*" mails = 0 mail[] # This is wrong but what do I do? def __init__ (self): pop=poplib.POP3(self.host) pop.user(self.user) pop.pass_(self.password) self.mails=len(pop.list()[1]) for i in range(self.mails): self.mail[i]=pop.retr(i+1)[1] # This is also wrong. pop.quit() print "Antal mails: %d\n" % self.mails -- Bertel http://bertel.lundhansen.dk/ FIDUSO: http://fiduso.dk/ From jepler at unpythonic.net Sun Aug 3 22:47:55 2003 From: jepler at unpythonic.net (Jeff Epler) Date: Sun, 3 Aug 2003 21:47:55 -0500 Subject: popen eating quotes? In-Reply-To: References: Message-ID: <20030804024751.GC10412@unpythonic.net> The problem semes to be surmountable when the executable doesn't have any spaces in its name. You just need to determine the "8.3" name of the executable, and use that when constructing the command to execute. Try win32api.GetShortPathName for this purpose. From martin at v.loewis.de Thu Aug 7 13:03:21 2003 From: martin at v.loewis.de (Martin v. =?iso-8859-15?q?L=F6wis?=) Date: 07 Aug 2003 19:03:21 +0200 Subject: True References: <3F312A65.5312B6EA@engcorp.com> <3F326BEC.9CF89FEC@engcorp.com> Message-ID: Peter Hansen writes: > As Skip said... but it should have had a comment anyway, since it > wasn't clear. You could also consider using "not not boolVal" if > you want to make the code _slightly_ (IMHO) more readable, and slightly > slower, but I think one still needs a comment explaining it. :-( I find def boolean2str(val): if val: return '1' else: return '0' both more readable, and twice as fast. It doesn't need to create a dictionary each time, and it does not to perform a dictionary lookup. If you prefer compactness, use def boolean2str(val, results=('1', '0')): return results[not val] Regards, Martin From pobrien at orbtech.com Fri Aug 29 13:26:30 2003 From: pobrien at orbtech.com (Patrick K. O'Brien) Date: 29 Aug 2003 12:26:30 -0500 Subject: Object Database (ODBMS) for Python References: <1DAECE9E8F34E04AA0E5699AF7D9FF090708D440@stpmsg00.corp.fairisaac.com> <3f4f7af6_3@corp.newsgroups.com> Message-ID: "Paul D. Fernhout" writes: > Well, to chime in here, in a "friendly" competition / cooperation Let me start by saying I'd love to cooperate, even if I am competitive by nature. ;-) Please keep that in mind as I agree/disagree with some of your points. ;-) > sort of way, the Pointrel Data Repository System, > http://sourceforge.net/projects/pointrel/ > while not quite an object database (and admittedly its case being > easier) has a simple API in the bare minimum use case (it has more > complex variants). Here is an example of its use (with fragments > inspired in response to an earlier c.l.p poster's use case a few days > ago): > > from pointrel20030812 import * > > # add a first attendant -- uses built in unique ID function > # each change will be implicitely a seperate transaction > attendantID = Pointrel_generateUniqueID() > Pointrel_add("congress", attendantID, 'object type', 'user') > Pointrel_add("congress", attendantID, 'name', 'Sir Galahad') > > # add a second attendant, this time as an atomic transaction > attendantID = Pointrel_generateUniqueID() > Pointrel_startTransaction() > Pointrel_add("congress", attendantID, 'object type', 'user') > Pointrel_add("congress", attendantID, 'name', 'Brian') > Pointrel_finishTransaction() > > In the first case, the changes are automatically made into > transactions, in the second, they are lumped under the current > transaction. > > Note that Python objects could be added to the database, as in: > > Pointrel_add("test", 10, ["hello", "goodbye"], MyClass) > > This simple API is made possible by two decisions: This API looks rather verbose to me. I think mine would look like: >>> t = tx.Create('User', name='Sir Galahad') >>> user = db.execute(t) And unique ids (immutable, btw) are assigned by PyPerSyst: >>> user.oid 42 And you can still access attributes directly, you just can't change them outside of a transaction: >>> user.name 'Sir Galahad' And the generic Update transaction is equally simple: >>> t = tx.Update(user, name='Brian') >>> db.execute(t) >>> user.name 'Brian' > Granted, the Pointrel System is essentially a single user single > transaction system at the core. It (in theory, subject to bugs) > supports atomicity (transactions), isolation (locking) and > durability (logging&recovery). It only supports consistency by how > applications use transactions as opposed to explicit constraints or > rules maintained by the database, so one could argue it fails the > ACID test there. (Although would any typical ODBMS pass consistency > without extra code support? Does PyPerSyst have this as the database > level?) PyPerSyst can persist *any* picklable object graph. But it also comes with an Entity class and a Root class (that understands Entity classes) that provides additional functionality, such as alternate indexes, referential integrity, instance validation, etc. So if your schema describes classes that subclass Entity, you get lots of functionality built into the database itself, without having to write any additional code, other than the additional validity checking that only your subclass knows. But I'd like to make more of that declarative as well. I'm also working on Fields, which provide validation and other features at the individual Entity attribute level. Fields have lots of metadata, like fields in an RDBMS. My goal is to have as much behavior as possible in the database, and have that behavior controlled declaratively within the schema. > To be clear, I'm not holding this out as "Pointrel System great" and > "PyPerSystem not so great", since obviously the two systems do > different things, each have its own focus, your task is perhaps > harder, I don't fully understand everything that is going on here in > your design and requirements, etc. What I am trying to get at is > more to challenge you (in a friendly way) to have a very simple API > in a default case by throwing down a pseudo-gauntlet of a simpler > system API. I don't mind a friendly challenge. I'm just surprised that the bulk of this thread is debating an API that has barely seen the light of day, and that I consider to be drop-dead simple. I guess I need to get a demo app created soon, just to put this to rest. Or at least make sure we're all debating about the same thing. ;-) Right now we're debating an API that nobody on this thread has really seen or used, other than me. The other thing I can say is that, imo, the way you interact with persistent class instances is not the same way you interact with regular class instances. Not if you value the integrity and reliability of your data. And trying to make it appear so is a disservice. I know everyone seems to think transparent persistence is the holy grail, but I've come to think otherwise. Unfortunately, I don't have time to fully elaborate my position. But you don't have to agree with me on this point. PyPerSyst is very modular, and there implementations of transparent proxies in the PyPerSyst CVS sandbox that some other developers on the team have written. So it can be done. I'll reply to other stuff separately to keep the message size down. -- Patrick K. O'Brien Orbtech http://www.orbtech.com/web/pobrien ----------------------------------------------- "Your source for Python programming expertise." ----------------------------------------------- From maxm at mxm.dk Sat Aug 2 05:30:49 2003 From: maxm at mxm.dk (Max M) Date: Sat, 02 Aug 2003 11:30:49 +0200 Subject: looking for win32 (or cross-platform) midi module In-Reply-To: References: Message-ID: <3F2B84C9.5050507@mxm.dk> dan wrote: > is there anything like the nice midipy.pyd, but up to date (ie works > 2.0)??? No regards Max M From news at exultants.org Sun Aug 24 00:07:38 2003 From: news at exultants.org (Van Gale) Date: Sun, 24 Aug 2003 04:07:38 GMT Subject: Python is darn fast (was: How fast is Python) In-Reply-To: References: <2259b0e2.0308230737.8a9bc1c@posting.google.com> <3F47AA73.7040104@draigBrady.com> Message-ID: Lawrence Oluyede wrote: > P at draigBrady.com wrote: > >>If you want to try different machines >>then http://www.pixelbeat.org/scripts/gcccpuopt will give >>you the appropriate machine specific gcc options to use. > > Very cool script, thanks :) Anyway it didn't change so much with erf.c > erfCPU is compiled with the flags suggested by gcccpuopt script: > > $ gcccpuopt > -march=athlon-xp -mfpmath=sse -msse -mmmx -m3dnow You still need some -O optimization flags. The -m options just let gcc generate some nice instructions specific to your Athlon CPU. Also, I don't think that script is all that useful because at least some (if not all) of those -m options are already implied by -march=athlon-xp (I don't recall which ones off the top of my head but I'll find a reference for anyone interested... you can also find out by looking at the gcc command line option parsing code). Anyone who wants some other good ideas for the best flags on their machine check out ccbench: http://www.rocklinux.net/packages/ccbench.html The problem here of course is that not all applications behave like the benchmarks :( Van Gale From vanevery at 3DProgrammer.com Tue Aug 19 00:25:44 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Mon, 18 Aug 2003 21:25:44 -0700 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: <3F41208F.40021A68@engcorp.com> Message-ID: John Roth wrote: > "Andrew Dalke" wrote in message > >> Despite my best attempts, I find it almost impossible to slag someone >> without including information to back up my view. Eg, I thought my >> numbers and trends of mentions of other programming languages was >> pretty interesting, but I guess it was of no value to you. :( > > I found it interesting, but not to the point. If there is one, > it's simply a question of whether any of the differences are > significant enough so someone who knows one language would > consider switching to another one. The conclusion around here is pretty ironclad. From a Python standpoint, Ruby does not matter. And from a technical standpoint, I am not shocked. Python is already "more exotic" than mainstream industry knows it needs. Ruby attempts to be "more exotic" than Python. At some point, exoticism is not what one needs. > Google searches won't tell > you that, only looking for people who've made that switch > will tell you. > > And I doubt if you'll find them on this newsgroup. That's the > one problem I have with Brandon's questions. If I wanted > to find out whether someone considered Ruby to be sufficiently > better than Python to switch, I'd look on the Ruby newsgroup, > not this one. Actually, I didn't think of looking for converts. Rather, I thought of looking for language wonks who are knowledgeable about Python + other languages, who had been through their own analysis of the pros and cons already. And I found some. But, I will try your idea because it's a good one. Get your marshmellows out for c.l.p, "Why did you switch from Python to Ruby?" -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From belred1 at yahoo.com Sat Aug 2 10:32:36 2003 From: belred1 at yahoo.com (Bryan) Date: Sat, 02 Aug 2003 14:32:36 GMT Subject: pyrex error References: Message-ID: <8YPWa.48874$YN5.38312@sccrnsc01> thank you... i worked. "Austin Luminais" wrote in message news:a4a36a6c.0308020136.58a769c9 at posting.google.com... > "Bryan" wrote in message news:... > > i'm having trouble building the pyrex demos. i also can't compile a simple > > hello word example. i keep getting this '__pyx_f' unknown size error. > > here's the error i'm getting when executing the following script. > > > > i'm using vc 6.0 on windows xp > > python 2.3 > > > > I've been experiencing the same problem since upgrading python to 2.3. > I think the definition of "staticforward" must have been changed. > > A temporary fix that seems to work (with MSVC 6.0) is changing this > line in the generated code: > > staticforward char *__pyx_f[]; > > to: > > extern char *__pyx_f[]; From sross at connectmail.carleton.ca Sat Aug 9 22:08:08 2003 From: sross at connectmail.carleton.ca (Sean Ross) Date: Sat, 9 Aug 2003 22:08:08 -0400 Subject: obj.__dict__ expected behavior or bug? References: Message-ID: <1OhZa.9822$pq5.1284169@news20.bellglobal.com> Hi. It's expected behaviour. Let's go through your code with a few additional print statements to see if we can demonstrate what's happening; class Config: a = 1 b = 2 c = 3 d = None e = None h = {'d' : 22, 'e' : 33} def __init__(self, factor): for attr in self.h.keys(): self.__dict__[attr] = self.h[attr] * factor def moda(self): self.a *= 5 c = Config(2) # Here's what to pay attention to ........... print "c.__dict__: ", c.__dict__ # this is the instance dictionary print "c.__class__.__dict__: ", c.__class__.__dict__ # this is the class dictionary print c.a, c.b, c.c, c.d, c.e for attr in c.__dict__: print 'c.%s = %s' % (attr, c.__dict__[attr]) print c.moda() print "c.moda() --------------" print "c.__dict__: ", c.__dict__ print "c.__class__.__dict__: ", c.__class__.__dict__ print c.a, c.b, c.c, c.d, c.e for attr in c.__dict__: print 'c.%s = %s' % (attr, c.__dict__[attr]) print Now, here's the output with #annotations: c.__dict__: {'e': 66, 'd': 44} c.__class__.__dict__: {'a': 1, 'moda': , '__module__': '__main__', 'b': 2, 'e': None, 'd': None, 'h': {'e': 33, 'd': 22}, 'c': 3, '__init__': , '__doc__': None} 1 2 3 44 66 c.e = 66 c.d = 44 # Okay. We can see that the values for 'a', 'b', 'c' were all found # in the class dictionary of instance c, while 'd', and 'e' were # found in the instance dictionary of c. More on this later.... # Now we're about to call moda() .... c.moda() -------------- # What's changed? c.__dict__: {'a': 5, 'e': 66, 'd': 44} c.__class__.__dict__: {'a': 1, 'moda': , '__module__': '__main__', 'b': 2, 'e': None, 'd': None, 'h': {'e': 33, 'd': 22}, 'c': 3, '__init__': , '__doc__': None} 5 2 3 44 66 c.a = 5 c.e = 66 c.d = 44 # This time only 'b' and 'c''s values were pulled from instance c's class' dictionary. # What about 'a'? 'a' was pulled from c's instance dictionary. Nothing's changed # for 'd' and 'e'. Okay then. What's going on? class Config: a = 1 b = 2 c = 3 d = None e = None h = {'d' : 22, 'e' : 33} The code above adds class variables a - h to the class Config. So, if you have an instance c of Config, variables a-h are stored in c's class dictionary (c.__class__.__dict__) and NOT c's instance dictionary (c.__dict__). Moving on... def __init__(self, factor): for attr in self.h.keys(): self.__dict__[attr] = self.h[attr] * factor Inside the constructor, you call self.h.keys(). To find self.h, Python looks first in self.__dict__. But 'h' isn't there. Next it looks in self.__class__.__dict__. That's were 'h' is! Now this: self.__dict__[attr] = self.h[attr] * factor Here, you're assigning NEW attributes 'd' and 'e' to self's __dict__. What you are not doing is assigning new values to class variables 'd' and 'e' in self.__class__.__dict__ . def moda(self): self.a *= 5 Something similar is happening in here. This one is a bit more complicated. self.a *= 5 is the same as self.a = self.a * 5 What does this really mean? Well, self.a = .... is equivalent to self.__dict__['a'] = .... But self.a = self.a .... is not necessarily equivalent to self.__dict__['a'] = self.__dict__['a'] because the self.a on the right hand side of the assignment has to be looked up by Python. And, as we showed earlier, look up starts with self.__dict__. But 'a' is not yet a key in that dictionary, so we move up to self.__class__.__dict__. That's where 'a' is! It's value is '1', so we get self.__dict__['a'] = 1*5 ^ self.__class__.__dict__['a'] We finish the evaluation, and assign 5 to self.__dict__['a'], creating a new instance variable. The class variable 'a' is unchanged. If you call c.moda() again later then, that time, Python's lookup would find 'a' in self.__dict__, and the expression self.a *= 5 would be equivalent to self.__dict__['a'] = 5*5 ^ self.__dict__['a'] So, the thing is, yes the behaviour is expected, if you know what behaviour to expect ... Okay, then. Hopefully that was helpful. Sean From jroznfgre at jngpugbjreXEBCXNbet.cy Mon Aug 18 19:46:35 2003 From: jroznfgre at jngpugbjreXEBCXNbet.cy (JZ) Date: Tue, 19 Aug 2003 01:46:35 +0200 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: Message-ID: <0ap2kv47tc2g3pn7t6djf29vl4b07jgupl@4ax.com> "Ruby still looks to me like a language that was invented because you couldn't (rationally) use objects or references in Perl, so it has Perl-ish syntax, which I don't think is very helpful (someday I may learn it, but Python continues to be far more compelling to me)" Bruce Eckel http://mindview.net/FAQ/FAQ-008 From borcis at users.ch Mon Aug 18 14:27:31 2003 From: borcis at users.ch (Borcis) Date: Mon, 18 Aug 2003 20:27:31 +0200 Subject: Py2.3: Feedback on Sets References: <%BX%a.4999$N37.3051@nwrdny02.gnilink.net> <7h3d6f3143s.fsf@pc150.maths.bris.ac.uk> Message-ID: <3F411A93.70807@users.ch> David Eppstein wrote: > > Multiplication by (nonnegative) integers is a pretty standard thing to > do in monoids, and means close to what Python's list*int syntax does: > add the thing to itself that many times. "God is a superfluous hypothesis, I need just an initial condition" > > I'm not sure why multiplying a list by a negative number produces the > empty list instead of an exception, though. > If it is illogical for it not to raise an exception, then in an appropriate universe the theory is logically permitted that some other value than the empty list is more logical as a result, than the empty list itself. The-anthropy-of-the-universe-is-everrising-ly-yours-ly From pythonguy at Hotpop.com Mon Aug 11 16:21:45 2003 From: pythonguy at Hotpop.com (Anand Pillai) Date: 11 Aug 2003 13:21:45 -0700 Subject: convert tuple to string References: Message-ID: <84fc4588.0308111221.528e478e@posting.google.com> Assuming 't' is your tuple of values, print reduce(lambda x, y: x + ',' + y, map(lambda x: x[0], t)) will print a string with all first elements of the tuple (your strings), separated by a comma. -Anand Alex Martelli wrote in message news:... > Lukas Kasprowicz wrote: > > > My Proglem is, I get after a query on a mysql database with module MySQLdb > > a tuple but I need this output from database as a string. > > can anybody help? > > Sure! Just bind that tuple, which you are currently returning, to a > variable (so you can in fact close the connection -- you're not doing > it now, since return ends your function), and then use that tuple as > you prefer. As it's a tuple of tuples you'll probably want to loop > over it rather than just calling "//".join or whatever, of course. > > Unless you know how you want to format the resulting string, it's > unlikely that the result is going to be satisfactory to you, of course. > > > Alex From nhodgson at bigpond.net.au Sat Aug 9 19:48:56 2003 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Sat, 09 Aug 2003 23:48:56 GMT Subject: ANNOUNCE: Rekall V2.0.2 References: Message-ID: John: > Why not take a Rekall Demo out for a test drive. Our demos are fully > functional with a 60 minute time limitation (the Windows demo has a 15 day > time limit), but they will run again. You can find the demos on either of > two web sites, http://www.rygannon.com and http://www.totalrekall.co.uk All links from the top level page require registration, even those that may explain what the product does. Neil From donn at u.washington.edu Tue Aug 26 13:09:00 2003 From: donn at u.washington.edu (Donn Cave) Date: Tue, 26 Aug 2003 10:09:00 -0700 Subject: OT: Ocaml? References: <7xk795xde6.fsf_-_@ruckus.brouhaha.com> <7h3wud0zihr.fsf@pc150.maths.bris.ac.uk> Message-ID: In article <7h3wud0zihr.fsf at pc150.maths.bris.ac.uk>, Michael Hudson wrote: > Donn Cave writes: > > > Incidentally, a few years back someone got fairly far along on > > implementing Python (or something like it) from scratch in > > Objective CAML. > > That was John Max Skaller, and the code is still on sf: > > http://vyper.sf.net > > If you're really curious and the anon CVS isn't working, I can stick a > tarball somewhere. No thanks! Donn Cave, donn at u.washington.edu From tismer at tismer.com Tue Aug 12 14:39:39 2003 From: tismer at tismer.com (Christian Tismer) Date: Tue, 12 Aug 2003 20:39:39 +0200 Subject: Howto MACRO in python ? In-Reply-To: References: <3F38D039.2B28800A@engcorp.com> <001201c360cd$3da065b0$6400a8c0@EVOD31> Message-ID: <3F39346B.4060502@tismer.com> Richie Hindle wrote: ... > Anyone know how I could retrieve function attributes from within a trace > function? It would be neater. Do you really mean function attributes, or just local variables? The latter are easily obtainable through the frame's f_locals. If you are just after the locals, you don't need to read on. When a frame is executed, the function is no longer available, just the source filename (from the code object), the name of the function and the frame's f_lineno. Guessing the function object from this info is not guaranteed to work, but will probably work if your code is static (not created dynamically, compiled and thrown away after starting it). With some luck, you can use the filename and the function name, import the according module and get the function object by the name. Then you can use function attributes. cheers - chris -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 pager +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From cartermark46 at ukmail.com Thu Aug 7 09:36:44 2003 From: cartermark46 at ukmail.com (Mark Carter) Date: 7 Aug 2003 06:36:44 -0700 Subject: wxPython resource editor bug (syntax error) Message-ID: Running xrced.py produced: Traceback (most recent call last): File "C:\Python23\Lib\site-packages\wxPython\tools\XRCed\xrced.py", line 28, in ? from tree import * # imports xxx which imports params File "C:\Python23\Lib\site-packages\wxPython\tools\XRCed\tree.py", line 1174 ^ SyntaxError: invalid syntax --- I've not been having much luck with python lately! --- Python 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] on win32 --- # Name: tree.py # Purpose: XRC editor, XML_tree class # Author: Roman Rolinsky # Created: 02.12.2002 # RCS-ID: $Id: tree.py,v 1.1.2.7 2003/05/12 14:11:30 ROL Exp $ From davecook at nowhere.net Fri Aug 15 05:31:50 2003 From: davecook at nowhere.net (David M. Cook) Date: Fri, 15 Aug 2003 09:31:50 GMT Subject: GUI builder for Python References: Message-ID: In article , henry wrote: > Just wondering if there's a good GUI builder for Python. Something like > Visual Tcl, where you just drag and drop objects. I like the way glade produces an xml file that can be loaded dynamically by libglade. PyQT/qtdesigner and wxpython/wxglade have similar features apparently. There's an article on pygtk and glade in September's Linux Journal: http://www.linuxjournal.com/article.php?sid=6586 Though the author seems to have missed the autoconnect method, which will automatically connect callback functions/methods with the same name as the handlers you define in glade. > Not too good with creating user interfaces from code along. Not one of programming's most thrilling chores. Dave Cook From aahz at pythoncraft.com Sat Aug 16 01:11:46 2003 From: aahz at pythoncraft.com (Aahz) Date: 16 Aug 2003 01:11:46 -0400 Subject: Why doesn't __call__ lead to infinite recursion? References: <2a82921f.0308151158.b8c9154@posting.google.com> Message-ID: In article , bromden wrote: >> foo is a function >> foo is a callable object >> foo has method __call__ defined > >true >true >false Wrong. See my followup. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From kjmacken at yorku.ca Tue Aug 5 12:28:54 2003 From: kjmacken at yorku.ca (Kevin MacKenzie) Date: 5 Aug 2003 09:28:54 -0700 Subject: Question about import Message-ID: <18fe8c2.0308050828.771de40d@posting.google.com> I'm a complete newbie to using Python. I have a small question about importing modules. Is there any difference between the two following statements, and what (if any) are they? >>> from Module import * and >>> import Module Thanks. kjm From aleax at aleax.it Fri Aug 8 08:25:15 2003 From: aleax at aleax.it (Alex Martelli) Date: Fri, 08 Aug 2003 12:25:15 GMT Subject: Tkinter programming problem References: Message-ID: klappnase wrote: ... >> > IDLE 1.0 >> > >>> import sys >> > >>> sys.exit(23) >> > >> > Traceback (most recent call last): >> > File "", line 1, in -toplevel- >> > sys.exit(23) >> > SystemExit: 23 >> > >>> >> >> As you see, with the IDLE 1.0 which comes with Python 2.3, the >> exception raised by sys.exit is captured and displayed as such >> [and similarly if sys.exit is called from a module run within >> the IDLE session, rather than directly at the IDLE prompt]. >> > Oh, that is interesting, my IDLE (python-2.2.2) exits on this. One of the several good reasons to upgrade to 2.3, yes. > Does this happen with sys.exit(0) too? Sure. >> Often one may want to do some kind of clean-up at that point, but you >> may achieve that with a try/finally around the mainloop call (putting >> the cleanup code in the finally clause, of course). >> > Seems like you mean something like: > > def quitcmd(): > mainwindow.quit() > do_this() > do_that() Nope. There's no reason to have to bundle the cleanup as sub-functions inside another function and so on. Rather, the concept is that cleanup is generally best done at the same level in which (e.g.) a resource is acquired. The try/finally-free approach would be structured like: channel = channels_library.open_channel('blah', 'blah') # here: set up the GUI; then: mainwindow.mainloop() # start and run the GUI # when the GUI is done (and exits with quit) we can do our cleanup channel.flush_any_unsent_data() # initiate lenghty flush operation channel.wait_up_to(10.0) # may take up to 10 seconds' wait here channel.final_close() # and then we finally give up This only works if the mainloop exits without exiting the whole Python session, of course. If you want to ensure the flushing &c happen in any case, including uncaught exceptions, then a more solid structure, as I mentioned, is try/finally: try: mainwindow.mainloop() finally: channel.flush... &c &c > If this is what you meant, what is the problem with: > > def exitcmd(): > do_this() > do_that() > sys.exit(0) Hard to say without knowing what do_this and do_that do, but in general (unless you have full control on them and can guarantee they're done very VERY fast) this is a disaster -- the GUI freezes (for up to 10 seconds, or a minute, or... who can tell?) while the program performs its potentially-lengthy cleanup operations. When you do background clean-up operations AFTER terminating the GUI, this is generally quite preferable. A clean-up operation can be considered a "background" one if you're not going to give the user feedback about what happens in it (you may e.g. log info to a logfile, but aren't going to popup a message box or the like). Of course, this doesn't matter if all cleanup operations can be guaranteed to terminate within, say, a couple of seconds, but e.g. when the ner is involved, that is quite rarely true. Since there are no advantages in doing background clean-up while still not closing the GUI, but there may be disadvantages, it is best to choose the approach that never gives problems -- do the background clean-up after closing the GUI. > I do not think that there is much difference in the behavior of these. You may not have thought the issue through, then; for example, you may never have needed to perform length background clean-ups. > May be if I launched the application from a menu and the do_that() > function does something really stupid that causes an endless loop, I > think with quitcmd() it might occur that the window is closed and I > think "Fine, the application is shut down" but the buggy do_that() is > still running in the background. With exitcmd() this won't happen, the > window will not close before do_that() comes to an end, so I will see > that there is something wrong. But taking many seconds to finish handshaking with communication partners, and other such background clean-up operations, does not mean "there is something wrong" -- such delays can be perfectly normal, yet there is no reason to keep the user staring at a frozen GUI while the delays go on. Alex From mwilson at the-wire.com Sun Aug 31 10:32:08 2003 From: mwilson at the-wire.com (Mel Wilson) Date: Sun, 31 Aug 2003 10:32:08 -0400 Subject: list as paremeters... References: <3f51ce6e$0$26843$626a54ce@news.free.fr> Message-ID: In article , "Ulrich Petri" wrote: >IIRC Default values are not created each time the function called but rather >only the first time (am i correct here?). And since a list is mutable it >"rememberes" the previous value. Default values are created when the 'def' statement is executed, for example: def f1 (t, usual=[]): usual.append (t) print 'F1:', usual for x in [1, 2, 3, 4, 5]: def f2 (t, usual=[]): usual.append (t) print 'F2:', usual f1 (x) f2 (x) Results in F1: [1] F2: [1] F1: [1, 2] F2: [2] F1: [1, 2, 3] F2: [3] F1: [1, 2, 3, 4] F2: [4] F1: [1, 2, 3, 4, 5] F2: [5] Regards. Mel. From theller at python.net Thu Aug 7 08:41:43 2003 From: theller at python.net (Thomas Heller) Date: Thu, 07 Aug 2003 14:41:43 +0200 Subject: crossplatform py2exe - would it be useful? References: Message-ID: Oren Tirosh writes: > On Wed, Aug 06, 2003 at 08:36:20PM +0200, Thomas Heller wrote: >> I'm currently working on a new version of py2exe, which will require >> Python 2.3 and later, because it uses the zipimport mechanism. > > Now that zipimport is part of Python the code required for bootstrapping > a py2exe runtime is just: > > myscript -c "import sys; sys.path.insert(0, sys.executable); import foo" > Yes, something like this is also what I am thinking now. And 'myscript' is just a copy of the standard interpreter. Although the sys.path entry must be present *before* Py_Initialize is called. > This reduces the difference between the custom interpreter supplied with > py2exe and the standard interpreter to just a few lines of C. > > The obvious question is - why not go all the way and put this little > hook into the standard Python distribution? This way py2exe could be a > platform-independent pure Python application. In fact, py2exe wouldn't > actually be necessary because anyone could create a zip file manually and > append it to the executable but it's more convenient to have a tool that > automates the process and finds the required dependencies. Yes, and modulefinder is now in the standard library. OTOH, py2exe does a little bit more: It has a mechanism to supply modules to include which modulefinder doesn't find, exclude modules which are unneeded although found, can detect whether Tkinter is used and copy it, scan (on Windows) extensions for dlls they need (wxPython needs the wxWindows dll, for example), handle hidden imports from C code in Python itself and extensions, and so on. And it works around the fact that extension modules cannot be loaded from zipfiles, it creates a pure Python loader included in the zip for them. Having said that, I would have nothing against py2exe included in the standard distribution, and the hooks in place. Thanks, Thomas From martin at v.loewis.de Sat Aug 30 21:37:24 2003 From: martin at v.loewis.de (Martin v. =?iso-8859-15?q?L=F6wis?=) Date: 31 Aug 2003 03:37:24 +0200 Subject: 2.3: test test_normalization failed References: <7h33cg4403q.fsf@pc150.maths.bris.ac.uk> <6e990e29.0308150215.62730c02@posting.google.com> <7h3u18j2j6t.fsf@pc150.maths.bris.ac.uk> Message-ID: Michael Hudson writes: > > Sounds reasonable. So the 2.3 normalization is just incomplete > > regarding the newest standard. > > Yep. I would guess it likely that 2.4 will be up to date again, but > it's not really my field. It will be tricky to update. Python now also supports IDNA (encodings/idna.py), which implements RFC 3490/91/92, which requires the Unicode 3.2 database; updating to 4.0 would be a violation of that RFC. So if we want to update the database, we need to find a way still to keep the old one. Regards, Martin From paul at fxtech.com Wed Aug 13 12:09:39 2003 From: paul at fxtech.com (Paul Miller) Date: Wed, 13 Aug 2003 11:09:39 -0500 Subject: "drop-in" DOM replacement for minidom? Message-ID: We've run into minidom's inabilty to handle large (20+MB) XML files, and need a replacement that can handle it. Unfortunately, we're pretty dependent on a DOM, so a pulldom or SAX replacement is likely out of the question for now. Has someone done a more efficient minidom replacement module that we can just drop in? Preferrably written in C? From code at joecheng.com Tue Aug 12 10:16:33 2003 From: code at joecheng.com (Joe Cheng) Date: Tue, 12 Aug 2003 14:16:33 GMT Subject: Python vs. C# References: <2259b0e2.0308100616.55b651ca@posting.google.com> <3f36af20@shknews01> <0b0hjv4q40mdf3msnur9q4bcih3tqb8iq3@4ax.com> Message-ID: <5F6_a.8537$M6.695850@newsread1.prod.itd.earthlink.net> Hi Doug, I have no particular love for C#, but your criticism seems a little too harsh... > I've used C# full time for over two years. Finally I got disgusted > with it and swtiched my entire company over to Python. That must include plenty of time with the beta, then? Is that where most of your bad experiences with C# were encountered? > From my experience I have found the following: > -C# is buggy and inconsistent. I haven't seen this... > -C# debugger is a piece of crap, the immediate window is worthless I've found the debugger (VS.NET, VS.NET 2003) to be easy to use, and work as expected. You can easily hook into existing processes, so you can for example debug client and server pieces from the same window. The main complaint you might have is a lack of "Edit & Continue" support. Is there something as good for Python? (an honest question) > -C# Garbage Collection algorithm is worthless, essentially it never > collects until it's way to late. By that time you are screwed. Can you elaborate? My understanding is that the CLR's GC is a quite sophisticated, performant, generational garbage collector. And if I'm not mistaken, interacts with the OS memory manager to vary its parameters depending on how much free memory is available system-wide. > -C# static typing is a major pain in the ass, it causes far more bugs > and errors than having loose types like C ever did. I've heard the argument that static typing slows down development, but actually *causing* bugs?? Over C-style typing!? I'd like to hear more. > -The .net widgets are slow and *really* buggy. Events get lost, they > choke are large volumes of text, and the drawing.dll just pukes on > load randomly. OK, some of the widgets are slow and buggy... but I believe most of the few bugs I've encountered have been due to problems in the underlying native Win32 widgets. But I agree, this is an area where they could stand some improvement. > -The lack of a multi-line string drives me bananas. Try building up a > big HTML form using a string builder sometime. > (this is just the beginning of a long list) I believe if you prepend the string with @, then multi-line strings are accepted. (However, you still need to \escape any literal double quotes.) They really need to add multi-line strings to Java... long SQL statements are also pretty annoying to concatenate, grrrr. > Python: > -Internally consistent, cleanly designed, to the point of being > beautiful It is pretty nice. > -Dynamic typing is amazing Sure, if that's what you're into... > -First class functions (try mimicking that in C# - ha) Delegates get you a lot of what you need in C#. They are less convenient than fcfs in the same way that C# collections or arrays are less convenient than Python's (from a static/dynamic typing point of view). And C# will get anonymous delegates in the next version, which will be nice--a little bit like Ruby blocks. > -Tuple unpacking is a god send > -List types are the cats meow > -Dictionaries are blazingly fast > -using metaclasses and the magic methods gives you amazing power and > flexibility Agreed, agreed, agreed, agreed. Working with collections in Python is a joy, and metaclasses and magic methods are things you simply can't get in C#. (Well, there are dynamic proxies... but it's definitely not the same) > Overal C# is a buggy, slow, half implementation of Java. It's written > by committe for people dumber than themselves. If you need to perform > some function that pushes the limits of the language, it will either > choke, or throw an error saying it was explicitly disallowed. It's > painful attempting to write real world apps in C#. I've encountered more bugs in Java than C# (ok, I've worked a lot longer with Java...) and certainly would not call C# slow compared to Java. And it's *certainly* faster than Python, by 5-10x if I remember correctly (unless you count C... but then you could pull the same trick with C#). C#'s startup time compared to Java is nil, and the benchmarks between the two for sustained performance have been inconclusive from what I've seen. Certainly the designers of C# were designing for people dumber than themselves--that includes almost everyone else in the world. :) But I disagree with the lowest-common-denominator argument you're making. The same has been said of Java since its inception, yet Gosling insists at every turn that he designed the language so *he* could work faster and better. If anything, C# gives you more rope to hang yourself with than Java. > When you can come back with some real world experience using some of > these languages you are bashing then your opinion might mean > something. Right now you are just spewing Microsoft hyperbole and > propaganda. On the flip side, I think Python can stand on its own merits without needing its advocates to exaggerate the shortcomings of its competition--assuming that is what you're doing. If not, and you encountered the behavior you described above with a release version of .NET, I (and a whole legion of rabid Java coders on TheServerSide.com) would love to hear about it... Please take this post in the spirit in which it was intended--I want only to balance your unrestrained criticism of C# from the perspective of one who has had a pretty OK experience with it, not take anything away from Python. And again, C# is not my favorite language--not even over Java. From trivas7 at rawbw.com Wed Aug 6 00:12:26 2003 From: trivas7 at rawbw.com (Thomas Rivas) Date: Tue, 5 Aug 2003 21:12:26 -0700 Subject: Problem w/ IDLE on Win2000 Message-ID: Unable to launch IDLE(fork?) from the new Py 2.3. Anybody else have this problem. Solutions? Thanks. Tom Rivas From alessandro at sephiroth.it Thu Aug 7 15:55:46 2003 From: alessandro at sephiroth.it (Alessandro Crugnola *sephiroth*) Date: Thu, 07 Aug 2003 19:55:46 GMT Subject: py2exe problems References: <8utYa.48785$cl3.1524137@news2.tin.it> Message-ID: <69yYa.29586$an6.1032525@news1.tin.it> > Ok, I've installed 2.2.3 and verified the behaviour you observed. > And I have a workaround: > > run the setup script with these options, and the test_c14n.py script > works as executable: > > python py2exe --packages encodings --force-imports encodings thank you, i'll try asap -- Alessandro Crugnola [sephiroth] Flash | PHP Developer http://www.sephiroth.it Team Macromedia Volunteer for Flash http://www.macromedia.com/go/team From peter at engcorp.com Wed Aug 13 14:21:13 2003 From: peter at engcorp.com (Peter Hansen) Date: Wed, 13 Aug 2003 14:21:13 -0400 Subject: Running Python 2.3 on a Windows 2000 network References: Message-ID: <3F3A8199.B42F1BF5@engcorp.com> John Ochiltree wrote: > > Worked like a dream. I now have a shared python shell Can you check whether "import pythoncom" and "import pywintypes" and (if you've installed the Win32 extensions) "import win32api" all work? If these work without your having to do anything to the registry, I'm curious about the installation process you used, since we had to do additional steps to get the same result. Thanks. -Peter From simon_place at whsmithnet.co.uk Wed Aug 6 19:29:21 2003 From: simon_place at whsmithnet.co.uk (simon place) Date: Thu, 07 Aug 2003 00:29:21 +0100 Subject: Hints about a script that read ftp contents .... In-Reply-To: References: Message-ID: <3f318f5d_3@mk-nntp-1.news.uk.worldonline.com> On the ftp holding my web space (ftp server: ProFTPD 1.2.0pre10 ) a 'stat *.pdf' command will list all pdf files in all sub directories recursively, ( and this is meant to be fairly standard,) unfortunately using ftp commands directly shows up the server os dependent format that directories are listed in ( usually UNIX ) but the functions to interpret this are in the ftp lib and there's a more general interpretation module out there somewhere ( handles more server os's ) From robin at jessikat.fsnet.co.uk Fri Aug 1 11:25:37 2003 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Fri, 1 Aug 2003 16:25:37 +0100 Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> <23bcqKAykjK$Ewhy@jessikat.fsnet.co.uk> Message-ID: In article , John Roth writes >> >> I don't have any data here, but I believe Python is just a little too >> weakly typed for compiling to float*float type assembler efficiently. > >The trick with JITs is that they don't depend on absolute type >consistency. They depend on the observation that 99.44% of your >code is type consistent, and that consistency will turn up at run time. So >the code they generate depends on that discovered consistency, and >checks in front of each section to discover if the types are what the >code expects. > >If it is, they execute it, if it isn't, they abandon it and go back to >the intepreter to discover what happened. > >John Roth Yes I suspected they have to do that, but that implies that a discovered 'float' object must carry along a whole lot of baggage (I guess I mean be a more generic object) to allow for the testing. Loops without method or function calls would be good candidates for JIT as methods and functions could alter attribute types. Is the JIT object literally just a union of type,values or would it be an actual Python object? For example would an innerproduct be over a pair of lists or would the magic convert these into actual double arrays. -- Robin Becker From adalke at mindspring.com Sun Aug 3 14:23:27 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Sun, 3 Aug 2003 12:23:27 -0600 Subject: time, calendar, datetime, etc References: Message-ID: Uncle Tim: > Did you actually run the example you pasted, or just assume that the second > line would display 5 too, or didn't paste the actual example you ran and > made a typo? Typo. I do usenet through MS Windows and haven't upgraded yet. It's my OS X box's Python which has datetime support. When copying I thought to myself "add 6000 years" which got turn into "replace the thousand year position with a 6". Guess it's time to break out the sackcloth and ashes. :) Any suggestions for a decent usenet reader for OS X? Andrew dalke at dalkescientific.com From raims at dot.com Fri Aug 29 11:14:00 2003 From: raims at dot.com (Lawrence Oluyede) Date: Fri, 29 Aug 2003 17:14:00 +0200 Subject: how fast is Python? References: <8765khzhl8.fsf@voodoo.fake> <3F4F63B5.D2684868@hotmail.com> Message-ID: <87ad9sjy2v.fsf@voodoo.fake> Alan Kennedy writes: > Please bear in mind that the test code included the start up time for > interpreter. For jython, this is a high cost, because starting a JVM > often takes up to 10 seconds or more. Yeah, you right. But here comes a question: why do you think that Jython (and JVM) are faster than Python (and its VM)? In my own little tests is Jython is always slower and GUI (with Swing) is not responsive as GTK for example. I think Jython is an amazing and awesome "tool" for Python and Java developers but I'm not so sure that is also faster than CPython. Bye! -- Lawrence "Rhymes" Oluyede http://loluyede.blogspot.com rhymes at NOSPAMmyself.com From tjreedy at udel.edu Wed Aug 27 14:46:12 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 27 Aug 2003 14:46:12 -0400 Subject: Celebrity advice (was: Advice to a Junior in High School?) References: <3F4CD2A2.DE7D05D2@engcorp.com> Message-ID: "Peter Hansen" wrote in message news:3F4CD2A2.DE7D05D2 at engcorp.com... > Terry Reedy wrote: > > > > (I think it safe to say that during the 20th century, 99% of the 100s of > > millions of murders were committed by armed govern-men rather than by > > private persons acting alone.) > > It may be safe to say it, but is it true, or merely hyperbole? Perhaps both: revise 100s to 200 million, which is close to what I meant (200-300 mill). http://users.erols.com/mwhite28/warstat1.htm (thanks all for the link with the list I had in mind) tabulates +/ 150 million as "maybe ? of all deaths by atrocity in the 20th Century". I am, of course, labelling insufficiently provoked mass-killing, direct and indirect, by gangs called armies, militias, security forces, or whatever as murder, regardless of the 'legal' decrees and excuses made by the directors of such gangs. (I am also aware that some would not make such a labelling, and that there are 'degrees' of provocation, but both topics are beyond the scope of this explanation.) > That's a lot of people getting themselves killed, whatever the cause... and whatever the even approximately exact number. Terry J. Reedy From mwilson at the-wire.com Wed Aug 20 10:05:42 2003 From: mwilson at the-wire.com (Mel Wilson) Date: Wed, 20 Aug 2003 10:05:42 -0400 Subject: Float + min/max? References: Message-ID: <2A4Q/ks/KXQb089yn@the-wire.com> In article , "Shu-Hsien Sheu" wrote: >Hi, > >I am new to Python, and just wrote a small program to generate the maximum >number of the cartisian coordinates among all atoms in a given molecule. >However, I found the float function, if combined with max function, to be >kind of confusing. It would give a number with uneccessary decimals from >nowhere. > >Not converting to float: > >x = [] >for i in (0, length-2): > slines[i] = lines[i].split() > if slines[i][0] == "ATOM": > x.append(slines[i][6]) > >print "xmax = " + max(x) + " " + "xmin = " + min(x) > >Output: >xmax = 90.179 xmin = 64.112 I think you misunderstand what's going on here. At this point x contains strings. If you coded print max(x) + min(x) you would see 90.17964.112 and if you then coded x.append ('123.3') print "xmax = " + max(x) + " " + "xmin = " + min(x) you'd get xmax = 90.179 xmin = 123.3 so conversion to float is not something you can skip. >Converting to float numbers: > >x = [] >for i in (0, length-2): > slines[i] = lines[i].split() > if slines[i][0] == "ATOM": > x.append( float(slines[i][6]) ) > >print "xmax = " + max(x) + " " + "xmin = " + min(x) > >Output: >xmax = 90.179000000000002 xmin = 64.111999999999995 > > >The original data file apparantly does not have those decimals. May I ask >how does it happend? Thank! Short answer, you want to format your float results (not just these, any float results) when you print them: print "xmax = %6g xmin = %6g" % (max(x), min(x)) or print "xmax = %6.3f xmin = %6.3f" % (max(x), min(x)) or for the die-hard scientific print "xmax = %6e xmin = %6e" % (max(x), min(x)) Regards. Mel. I was going to bitch about %6f printing 6 places of decimals instead of a total field width of 6, but I see C does this too. Python-specific '%6g' prints a 6-character field. Very nice. MPW From vze4rx4y at verizon.net Fri Aug 29 02:14:57 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Fri, 29 Aug 2003 06:14:57 GMT Subject: opposite of dict.items() References: <3f4e708c$0$64719@hades.is.co.za> Message-ID: [Tertius wrote] > > Is there a method to create a dict from a list of keys and a list of > > values ? [Peter Otten] > >>> dict(zip(range(3), "abc")) > {0: 'a', 1: 'b', 2: 'c'} If you're using Py2.3, then the itertools way is a bit nicer: >>> dict(itertools.izip(range(3), "abc")) {0: 'a', 1: 'b', 2: 'c'} Raymond Hettinger From usenet_spam at janc.invalid Sat Aug 9 21:27:56 2003 From: usenet_spam at janc.invalid (JanC) Date: Sun, 10 Aug 2003 01:27:56 GMT Subject: email client written with python + wxWindows References: <409a56e2.0308062211.456575df@posting.google.com> Message-ID: Vadim Zeitlin schreef: [about Mahogany] > And the next release should happen really soon now (no joking). > Unfortunately, Python support will almost surely be disabled in it > because there is not enough interest in it to motivate me to maintain > it and so right now it doesn't even support 2.2 without speaking of > 2.3 (only 1.5, 1.6 and 2.1). But if someone would like to have a > relatively powerful cross-platform mail client scriptable in Python > Mahogany would be a great to start and any help with the embedded > Python interpreter would be very welcome. I was just looking at it as a replacement for my current mail client, and Python scripting was one of the things which made me look at it (I found a link to it on the wxWindows site). But scripting (Python or other) is not something I really need in a mail client currently... Mahogany itself has many good & sometimes unique features. :-) But it has some strange bugs too. :-( I'll try a new install and not play with the "Calendar" module this time, as it seems the problems started after activating it... -- JanC "Be strict when sending and tolerant when receiving." RFC 1958 - Architectural Principles of the Internet - section 3.9 From roy at panix.com Thu Aug 21 21:44:59 2003 From: roy at panix.com (Roy Smith) Date: Thu, 21 Aug 2003 21:44:59 -0400 Subject: What's better about Ruby than Python? References: <6dj2kv8ugkieehs7guh786cl40o5lj6mcs@4ax.com> <599a6555.0308202108.397bb1a0@posting.google.com> <599a6555.0308210631.441f76cd@posting.google.com> <599a6555.0308211704.5be5e10d@posting.google.com> Message-ID: trimtab at mac.com (Olivier Drolet) wrote: > Common Lisp macros can often significantly improve code readability by > merely reducing the amount of code. If what you're talking about is basicly refactoring, then it seems like you could get the same code reduction by defining new functions/methods. What does a macro give you that a function doesn't? In C, the answer was "faster code", which I claim is simple a non-issue for Python (we're not after speed in the same way C guys are). In C++ the answer seems to be "generic programming", in the sense that templates let you factor out the data type from the algorithm. Again, a non-issue in a dynamic language like Python, where type information is carried in the object, not the container. So, is there something else that macros buy you that I'm not seeing? People keep talking about how lisp macros are nothing like C/C++ macros. OK, I'm willing to be educated. How are they different? Can somebody give an example? Keep in mind that the last time I did any serious lisp was about 20 years ago. From mack at incise.org Fri Aug 22 22:24:53 2003 From: mack at incise.org (mackstann) Date: Fri, 22 Aug 2003 21:24:53 -0500 Subject: Sort a Dictionary In-Reply-To: References: Message-ID: <20030823022453.GK1695@incise.org> On Sat, Aug 23, 2003 at 02:03:09AM +0000, Afanasiy wrote: > This is fairly simple in PHP, how do I do it in Python? In PHP, associative arrays are still regular arrays too, you can access them by index (IIRC), and when you loop through them, they maintain the order in which you assigned their items. Python seperates associative arrays (dicts/hashes) from numerically indexed arrays (lists). You can't sort a dict, because a dict has no order. You could do something like: mydict = { ..whatever.. } sortedkeys = mydict.keys() sortedkeys.sort() for key in sortedkeys: print key, mydict[key] Then we run into the issue of why we have to do list.sort() in place, and I'm sure that's been discussed here a billion times (can't say I've been part of any of those discussions though). -- m a c k s t a n n mack @ incise.org http://incise.org After a few boring years, socially meaningful rock 'n' roll died out. It was replaced by disco, which offers no guidance to any form of life more advanced than the lichen family. -- Dave Barry, "Kids Today: They Don't Know Dum Diddly Do" From czoretich at octigabay.com Wed Aug 6 19:08:27 2003 From: czoretich at octigabay.com (Craig Zoretich) Date: 6 Aug 2003 16:08:27 -0700 Subject: modifying def behaviour Message-ID: Hi, Is it possible to change how the "def" builtin command works? Specifically I want to modify def to write to a log file when a function executes (for instance the name of the function, when it was executed - that sort of thing). I want to avoid having to put some code in each and every function I write to do this logging for me. Thanks, Craig From chris.gonnerman at newcenturycomputers.net Fri Aug 8 08:33:37 2003 From: chris.gonnerman at newcenturycomputers.net (Chris Gonnerman) Date: Fri, 8 Aug 2003 07:33:37 -0500 Subject: [Python] Re: Building extensions with mingw32 -- bdist_wininst fails. References: <87adak1vez.fsf@smtp.gsi.de> Message-ID: <002301c35da9$4aa09540$1f00000a@house> ----- Original Message ----- From: "Pierre Schnizer" > Please excuse, if it is a bit out topic. > > When I tried to build an extension module for Python2.2 with MingW3.0 I had > problems with the conversion of files. So > > myfile = PyFile_AsFile(object); > > would crash python2.2 when a standard Python2.2 was invoking an extension > module compiled with MinGW. > > Do you use such conversions in your Module? No, I don't. That's interesting, though... thanks for the information. Chris Gonnerman -- chris.gonnerman at newcenturycomputers.net http://newcenturycomputers.net From holmboe at kth.se Fri Aug 29 17:22:05 2003 From: holmboe at kth.se (Michael) Date: 29 Aug 2003 14:22:05 -0700 Subject: Newbie question! Plotting with Tkinter... Message-ID: <9193c0d1.0308291322.12538c14@posting.google.com> Hi! Im a supernewbie who wants to plot simple x/y-diagrams, one list[] against an other. Can I use Tkinter? Can i plot 3D, and/or interactivly with Tkinter? Does anyone know about a easy to use tutorial or code to use? Or whatabout Numeric? Can i use Numeric to plot some simple graphs? I?ve been looking around for a while and cant find any simple, easy to use or install program/module... /Michael From unendliche at hanmail.net Sat Aug 23 20:33:19 2003 From: unendliche at hanmail.net (Seo Sanghyeon) Date: 23 Aug 2003 17:33:19 -0700 Subject: Modifying the {} and [] tokens References: Message-ID: <45e6545c.0308231633.746fc154@posting.google.com> Geoff Howland asked: (about extending builtin literal types.) You _could_ do that in Python 2.2, though it was a bug, not a feature. ---- Python 2.2 >>> def add(self, key, value): self[key] = value >>> dict.add = add TypeError: can't set attributes of built-in/extension type 'dict' >>> object.__setattr__(dict, "add", add) # !! >>> x = {} >>> x.add(1, 1) >>> x {1: 1} ---- Don't tell others that I said this. Why this is a bug, not a feature? I think that is because Python is not Ruby. Another evidence is that this behaviour is _fixed_ in Python 2.3: ---- Python 2.3 >>> object.__setattr__(dict, "add", add) TypeError: can't apply this __setattr__ to type object ---- Obviously somebody put a sanity check there. Seo Sanghyeon From mack at incise.org Thu Aug 21 21:50:36 2003 From: mack at incise.org (mackstann) Date: Thu, 21 Aug 2003 20:50:36 -0500 Subject: crazy programming language thoughts In-Reply-To: References: Message-ID: <20030822015036.GH1695@incise.org> Applescript has some interesting use of the English language. -- m a c k s t a n n mack @ incise.org http://incise.org Avoid Quiet and Placid persons unless you are in Need of Sleep. -- National Lampoon, "Deteriorata" From bignose-hates-spam at and-benfinney-does-too.id.au Mon Aug 18 02:01:17 2003 From: bignose-hates-spam at and-benfinney-does-too.id.au (Ben Finney) Date: 18 Aug 2003 15:51:17 +0950 Subject: slight csv misbehavior under Windows References: Message-ID: On 18 Aug 2003 06:55:25 +0100 (BST), Thomas Womack wrote: > Please tell me if this is not the appropriate place to make this kind > of bug report. Python is a project registered at SourceForge: That has a "Bugs" link, where you can track and submit bug reports: -- \ "Outside of a dog, a book is man's best friend. Inside of a | `\ dog, it's too dark to read." -- Groucho Marx | _o__) | Ben Finney From koenig at v-i-t.de Wed Aug 27 12:46:16 2003 From: koenig at v-i-t.de (Mirko Koenig) Date: Wed, 27 Aug 2003 18:46:16 +0200 Subject: wxPython: need return value from wxFrame References: Message-ID: Hi On Tue, 26 Aug 2003 23:02:23 +0200, Cliff Wells wrote: > Maybe a better idea of exactly what you want would help. Your app has > only a single wxFrame? You want that frame to return something? To > what? I would think when the frame "returns" the app would exit if it's > the only frame. OK. I try again to explain: I have two stand-alone apps: 1) customer addressbook 2) invoice Both made with wxpython. Both contain: class cabGui( wxApp ): def OnInit( self ): self.frame = cabMainFrame( NULL ) self.frame.Show() self.SetTopWindow( self.frame ) return true ... if __name__ == '__main__': app = cabGui(0) b = app.MainLoop() In the customer addressbook the cabMainFrame is the addressbook frame. In the invoice app the cabMainFrame is the frame containing invoice specific buttons/field etc. The cabMainFrame is a wxFrame derivered class. it contains other frames and a status bar and so on. What i want is to call the customeraddressbook from within the invoice app. To give the user the chance to select an address from the addressbook. That address should then be inserted into the invoice Gui. I thought this is perhaps possible, so i don't have to write the addressbokk code twice. I thought i can just use the addressbook and give back the selected address. So that i can use it in the invoice Gui. The only solution i found until now is to set an variable in the customer addressbook that points to one from the invoice Gui if i want to set it. If not it points to None. customerFrame.setAddrVar( invoiceAddr ) customerFrame.Show() Mirko Koenig From vze4rx4y at verizon.net Fri Aug 1 19:53:00 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Fri, 01 Aug 2003 23:53:00 GMT Subject: How do you do unittest? References: Message-ID: "Will Stuyvesant" wrote in message news:cb035744.0308010633.3fd4e805 at posting.google.com... > I have a unittest testfile like this: > > ----------------------- test_mod.py --------------------- > import sys > sys.path.append('..') > import unittest > import mod > > class Test_rmlutils(unittest.TestCase): > > def testNormalCase(self): > self.assertEqual(.... > > > if __name__ == '__main__': > unittest.main() > --------------------------------------------------------- > > It is exactly the same as example 17-2 in "Python in a > Nutshell" (PiaN), except for the first two lines. To > quote PiaN: > "...name the test module...with a prefix such as 'test_', > and put it in a subdirectory named 'test' of the directory > where you keep the sources." > > PiaN did not mention the ugly sys.path.append('..') trick > I had to use when following its advice. I need to use it > because mod.py is in the directory above the 'test' > directory. You can avoid that sort of mambo jambo by avoiding unittest.main() and running the tests directly. I added a simple example to the Py2.3 docs: http://www.python.org/doc/current/lib/minimal-example.html Raymond Hettinger > > To run a test from the source directory I have to change > to the 'test' directory and run test_mod.py there from the > commandline. Okay, I can do that from a batchfile: > > ----------------------- test.bat ------------------------ > cd test > test_mod.py > cd .. > --------------------------------------------------------- > > But: I would like to get rid of the need for > sys.append('..') and I don't see a nice way to do that, do > you? Maybe something from a Python script instead of a > DOS script...I am thinking about importing sys there and > then doing some advanced unittest function like > 'runsuite(blah, foo)' but I am still reading the unittest > docs and there must be somebody who did this before? > > I guess the author of PiaN does not use a 'test' subdirectory > himself, as it is now the example 17-2 does only work in the > source directory. From klappnase at web.de Tue Aug 5 11:20:56 2003 From: klappnase at web.de (klappnase) Date: 5 Aug 2003 08:20:56 -0700 Subject: Tkinter programming problem References: <2830c89c.0308010048.403a2a19@posting.google.com> <2830c89c.0308040201.7c70695d@posting.google.com> Message-ID: Eric Brunel wrote in message news:... > This may also work, but the most common way is the one I describe above. If you > want to do it here, you can do: > > def quit(self, event): > print "Quitting..." > self.master.quit() > > AFAIK, all Tkinter widgets have a quit method that will quit the Tk mainloop. > > HTH I think Tkinter's quit() method will not work while running from within the interpreter, because there is no mainloop. I think you will have to destroy() there. Best regards Michael From andreas at andreas-jung.com Wed Aug 27 23:35:43 2003 From: andreas at andreas-jung.com (Andreas Jung) Date: Thu, 28 Aug 2003 05:35:43 +0200 Subject: [Zope-dev] Zope 2.7 running with Stackless 3.0 In-Reply-To: <3F4D44EB.5010500@tismer.com> References: <3F4D44EB.5010500@tismer.com> Message-ID: <2147483647.1062048943@[192.168.0.100]> What are the benefits of running Zope with Stackless Python? Cheers, Andreas --On Donnerstag, 28. August 2003 1:55 Uhr +0200 Christian Tismer wrote: > Dear friends, > > just by chance, I got into the position to try out > Zope 2.7.0 beta 1/2, and since it needs Python 2.2.3 > at least, and Stackless 3.0 was just ported to that, I tried > to build Zope with Stackless 3.0. > > It works very very well! After a few patches to get the includes > right, here the installation instructions. > > Get the current Stakless 3.0 beta. > > CVSROOT=:pserver:anonymous at centera.de:/home/cvs > export CVSROOT > > cvs co stackless > > cd stackless/src > ./configure > make ># su if your weren't root > make install > > Then, install the Zope source, and make the same dance as usual. > > Just a note: > Zope doesn't (yet) use any of the Stackless features. > It just builds and works with it. But of course, *you* > can use the stackless features, of course. > > I also expect, that Zope will create a branch in some future > and implement a new Medusa which doesn't need real threads. > > cheers and let me know of your experience -- chris > -- > Christian Tismer :^) > Mission Impossible 5oftware : Have a break! Take a ride on Python's > Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ > 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ > work +49 30 89 09 53 34 home +49 30 802 86 56 mobile +49 173 24 18 776 > PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 > whom do you want to sponsor today? http://www.stackless.com/ > > > > > _______________________________________________ > Zope-Dev maillist - Zope-Dev at zope.org > http://mail.zope.org/mailman/listinfo/zope-dev > ** No cross posts or HTML encoding! ** > (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce > http://mail.zope.org/mailman/listinfo/zope ) From none at nowhere.com Tue Aug 19 17:07:07 2003 From: none at nowhere.com (news1.sympatico.ca) Date: Tue, 19 Aug 2003 17:07:07 -0400 Subject: Help with py2exe...com dll Message-ID: I am developping a com (dll based) in python. I obviously use py2exe to create the *.dll file. My program is based on 3 modules (the first one is calling the two others). If all 3 modules are located inside the same directory everything goes compiles and the com is created. However if I put one of the module in a subfolder and try using the -i argument of py2exe nothing compiles and python tells me that it cannot find the subfolderX.packageX.py module. I have tried all the above: python.exe com_script.py py2exe -i subfoldername.modulename.py --com-dll python.exe com_script.py py2exe -i subfoldername.modulename --com-dll python.exe com_script.py py2exe -i subfoldername\modulename.py --com-dll python.exe com_script.py py2exe -p subfoldername --com-dll here is my startup script also: import sys sys.path.append("d:\\project\\projectX") sys.path.append("d:\\projets2\\projectX\\subfolderName") from distutils.core import setup import py2exe setup(name="The Big TEst", scripts=["MainModule", "Module2", "Module3"], version="1.0") From skip at pobox.com Mon Aug 18 23:24:18 2003 From: skip at pobox.com (Skip Montanaro) Date: Mon, 18 Aug 2003 22:24:18 -0500 Subject: Design idea for Ping Application In-Reply-To: References: <4378fa6f.0308181546.548daff7@posting.google.com> Message-ID: <16193.39010.853126.317223@montanaro.dyndns.org> Marc> I need an application that will continuously ping 11 different Marc> hosts and track the status of the pings. >> Why not use a purpose built network monitoring tool like Nagios >> (http://www.nagios.org/)? Marc> If my company had wanted to spend money on something they wouldn't Marc> have asked me to do it ;) Nagios is Open Source, so you can use it without charge. If you're looking to do network monitoring it does much more than ping a few hosts periodically. Skip From tebeka at cs.bgu.ac.il Tue Aug 26 06:10:50 2003 From: tebeka at cs.bgu.ac.il (Miki Tebeka) Date: 26 Aug 2003 03:10:50 -0700 Subject: Comments on my "Python Introduction" slides References: <33803989.0308240000.35b9bf1f@posting.google.com> <33803989.0308240644.3090f039@posting.google.com> <3f492761$0$49117$e4fe514c@news.xs4all.nl> Message-ID: <33803989.0308260210.4c1e058@posting.google.com> Hello Bryan, > not sure it's any better, faster, more readable... just my preference. so your frame 7 would be: > > def unique(fname): > '''Prints unique lines in fname''' > h = {} > for line in file(fname): > line = line.strip() > if line not in h: > h[line] = True > print line > Taken. It's in. > frame 8: you should also list empty tuple, list and dict as having a False value too) Don't they fall under "empty collection"? > frame 9: needs a note that it's for 2.3+ That's the current official release. > frame 10: IMO "Magic methods" has a negative connotation. but maybe it's the correct terminology I'll try to find a better alternative. > frame 12: i know python has a c interface for c extension modules, but can't modules also be written is c++ (ie. boost?) You're right. I guess I hate C++ to much :-) > frame 18-19: i would show the exact same example in each. I'll do this oraly. > it appears from your slide that wxPython is way more complicated than TK wxPython is more sutibale for large project and requires a bit more overhead than Tk to start up. Can't think of anything shorter. > i enjoyed going though it... nice work... Thanks. Thanks for you comments. Miki From mwh at python.net Thu Aug 14 09:16:41 2003 From: mwh at python.net (Michael Hudson) Date: Thu, 14 Aug 2003 13:16:41 GMT Subject: Python signal delivery under BSD 4.4 References: Message-ID: <7h3isp04bzm.fsf@pc150.maths.bris.ac.uk> "Elf M. Sternberg" writes: > Right now, I just want a way to make signal delivery work. At some point, the threads implementation got changed so that new threads get their signal mask set to "block everything and it's cat" (there was a reason for this, but I'm not really sure what it was). As I see it, you have two options: 1) write a little C to unset the procmask after fork() but before execve() 2) only launch apps from the main thread. I did write wrappers for sigprocmask & so on for inclusion in Python 2.3, but the x-platform behaviour was insane (and *some* version of FreeBSD contains fixes to libc_r that my code provoked, but I'm not sure which version) so the code got backed out again. Cheers, mwh -- 41. Some programming languages manage to absorb change, but withstand progress. -- Alan Perlis, http://www.cs.yale.edu/homes/perlis-alan/quotes.html From pdfernhout at kurtz-fernhout.com Sun Aug 31 14:18:18 2003 From: pdfernhout at kurtz-fernhout.com (Paul D. Fernhout) Date: Sun, 31 Aug 2003 14:18:18 -0400 Subject: Object Database (ODBMS) for Python In-Reply-To: References: <1DAECE9E8F34E04AA0E5699AF7D9FF090708D440@stpmsg00.corp.fairisaac.com> <3f4f7af6_3@corp.newsgroups.com> <3f4f9e88_3@corp.newsgroups.com> Message-ID: <3f523b97$1_8@corp.newsgroups.com> Patrick- I think based on this and your other posts I now understand better where you are coming from. Thanks for the explainations and comments. To try to restate (and better justify) what I now think I see as your point of view on this transactional API issue, let me present this analogy. When one builds a modern GUI application that supports complete multicommand "Undo" and "Redo" such as built on the Macintosh MacApp framework http://developer.apple.com/documentation/mac/MacAppProgGuide/MacAppProgGuide-44.html or any other similar approach, the stategy generally is to have a stack of Command (subclassed) objects, where each such object supports "do", "undo" and "redo". We use a general purpose system like this for example in our Garden Simulator software (and other Delphi applications -- hopefully someday to be ported to Python). http://www.gardenwithinsight.com/progmanlong.htm Rather than mess with the application's data domain directly, every user action in such an undoable application, from selecting an object in a drawing program, to making a change with a slider, to dragging an object, to deleting an item, to even setting multiple options in a dialog (if each change isn't itself a command), creates a command (i.e. a transaction), which changes the domain and then continues to modify the domain while it is active (say at the top of the command stack while a mouse is dragged) and then completely finishes modifying the domain and is left on the stack when all the related GUI activity is done. While the command (transaction) itself may fiddle with the domain, no button press, or mouse click, or drop down selection ever messes directly with the data domain (or what might in another context be sort of like the business logic and business data). By constraining changes to this approach, one can readily do, undo, and redo a stack of commands to one's heart's content -- and subject to available memory :-) or other limits. Your transaction notion in PyPerSyst, now that I understand it better, seems to have something of this GUI command system flavor. And that emphasis is perhaps why you do not feel it is inconsistent to have one way to read values and another way to change values, since changing values is something in this model requiring significant forethought as an application level transaction. Implicitely, what you are getting at here is a development methodology where all data domain changes go through transactions (commands), and the transactions have been consciously considered and designed (rather than just resulting from randomly poking around in the data domain). And that is perhaps why you are so against the implicit transactions -- they violate this development methodology of being explicit about what chunks of changes are a transaction (as an atomic unit). The same sort of issues come up whan people try to avoid COmmand type framekworks, thinking it is easier to just fire off changes directly to the data domain from GUI events (and it is easier -- just not undoable or consistent). Adhering to a transactional (command-al?) development methodology makes it very straightforward to understand how the application is structured and what it can or cannot do (i.e just look in the transaction (or command) class hierarchy). And so, from your perspective, it is quite reasonable to have a lot of work go into crafting transaction objects (or subclassing them from related ones etc.) in the same way that it is expected that GUI applications with undo/redo capabilities will have a lot of effort put into their analogous "Command" class hierarchy. To step back a minute, in general, a transactional development methodology is in a way a step up from the random flounderings of how many programs work, with code that changes the data domain potentially sprinkled throughout the application code based, rather than cleanly specified in a set of Command or Transaction subclasses. So you are sort of proposing generally a step up in people's understanding and practice of how to deal with applications and persistent data. Does this sort of capture an essential part of what you are getting at here with your PyPerSyst application architecture development strategy? If so, I like it. ;-) All the best. --Paul Fernhout http://www.pointrel.org P.S. The Pointrel System supports abandoning in process transactions by sotrign all the data it changes long the way, and being able to roll back to this state. But, with an object database as you have outlined it, I think this would naturally be a lot more complicated -- although perhaps you could adopt the "undo" and "redo" aspect of Commands (including stashing the old objects somewhere in case of a redo...) Patrick K. O'Brien wrote: [Lots of good stuff snipped, and thanks for the interesting dialogue. :-)] > If users expect symmetry it is because they are used to writing single > process programs that do not share objects. Does anyone expect this > kind of symmetry and transparency when writing a multi-threaded > application? Why not? Granted, having start/end transaction > semantics might change some of the rules. But even if we had those in > PyPerSyst, I would probably only use them inside of Transaction > classes, not embedded in application code where they are harder to > find and test. Explicit transaction objects have many benefits. > > It's sort of similar to the notion of separating your application > logic from your gui code. Sure its easier to just put a bunch of code > in the event handler for a button. But is that the best way to code? > In my mind, implicit transactions, or commit/rollback in application > code, is like putting all your business logic in the event handlers > for your gui widgets. I'm trying to keep people from writing crappy > persistent applications. >>I think this is the core of the question of this part of the thread. >>You wrote "I've come to think otherwise". I'd be curious to hear >>more on any use cases or examples on why transaparency is not so >>compatible with reliability etc. > > I just think implicit transparent transactions would lull users into a > false sense of integrity and make them write sloppy applications that > didn't actually maintain the integrity of their objects when used in a > multi-user environment. I think the kind of applications I want to > use PyPerSyst for demand that it be difficult for application > programmers to do the wrong thing with regards to the integrity of the > persisted data. I think having transactions as explicit objects > provides more control over the integrity of the database. If users > want transparency, it can be done, using PyPerSyst, it just isn't the > focus of my current efforts. And I don't think explicit transactions > are that much of a burden. Transaction code is a small percentage of > application code, compared to all the interface code you have to > write. And you could easily write wrappers for transactions that make > them less burdensome. -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! -----== Over 100,000 Newsgroups - 19 Different Servers! =----- From tjreedy at udel.edu Mon Aug 11 22:09:52 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 11 Aug 2003 22:09:52 -0400 Subject: Fun with numbers - dammit, but I want a cast! References: <3f378fac$0$10778$afc38c87@auth.uk.news.easynet.net> <3f3792f2$0$18258$afc38c87@auth.uk.news.easynet.net> Message-ID: "Carl Banks" wrote in message news:yVVZa.764$u%2.33 at nwrdny02.gnilink.net... > Terry Reedy wrote: > > No, quite different. A C cast (at least usually) recasts a block of > > bits in a new role without changing the bits. > > Certainly not. Most type casts actually change bits. >From what I remember both in my own code and others that I have read, most casts, where 'most' is measured in frequency of occurence in actual code, which is what I meant by 'usually'. are pointer casts where no bits are changed (at least on platforms I have had experience with). Your experience could be different. > For example, > supposing floats and longs are both 32 bits, the expression (float)1L > will *not* return the floating point number with the same bit pattern > as 1L. It returns 1.0. My awareness of this possibility is one reason I added the qualifier 'at least usually'. However, C's coercion rules make (in my experience) explicit number casts rare in actual occurances. Standard C made them even rarer than in K&R C by adding autoconversion of function arguments, so that, for instance, sqrt((double) 4) could shrink to sqrt(4). > Usually, the only casts that preserve the bit pattern are integer to > pointer casts, You left out pointer to pointer casts, which I believe are the most common of all! > and the C standard doesn't even guarantee that (unless > C 2000 changed it). In fact, the C standard says (or used to say) > that 0 must always cast to a null pointer, even if the system > represents integer 0 and null pointer with different bits, which does > (or used to) happen. On which systems? How widely used? I also added 'at least usually' to account for systems I don't know about ;-) > IMO, a type cast is just a fancy name for an operator that takes an > object and returns an object with the same "value" (whatever that > means) but a different type. In C, type casting happens to have a > funny syntax. In Python, it does not. If someone asked, "does Python > have type casting?", I would say yes, except there's no special syntax > for it. Rather, type casting is done by the calling type objects > themselves. In my opinion, it is unhelpful to refer to type-function calls as casts. To me, the baggage 'cast' carries is more confusing than helpful. For instance, a common conversion, between number and string, cannot be done in C with a type cast but must also (as in Python) be done with a function call. Would you call C's atoi(), atof(), and sprintf casts? In C, the 'funny syntax' defines what I believe most people call a type cast versus a function call. This is certainly true for both K&R and the Standard C committee. Terry J. Reedy From wiebke.paetzold at mplusr.de Tue Aug 5 08:52:17 2003 From: wiebke.paetzold at mplusr.de (Wiebke Pätzold) Date: Tue, 05 Aug 2003 14:52:17 +0200 Subject: abstraction of the column names (classes) Message-ID: Hi all! I create a database that contains a table. 'Nachname' is one of 13 column names. This program can search for a special letter. In my example it is 'ra'. and the search takes place in 'Nachname'. 'ra' takes place within a word. This is solved with regular expression. So that I can limit my search. For example: I can search for 'ra' and it is not relevant wich letters follow or wich letters are in front of 'ra'. Now I want to abstract the column name 'Nachname'. So I search in an unknown column. Only the user of the program should determine in wich class the search takes place. This input should happen in the view lines of testing the class. My task is it to change the program that a abstraction of the column names takes place. Please give me a detailed answer. If it is possible the changed program because I am very new in Python and I am orientationless. This is the program import sys import Mk4py import re db = Mk4py.storage("c:\\datafile.mk",1) vw = db.view("people") class PatternFilter: def __init__(self, pattern): self.pattern = re.compile(pattern) def __call__(self, row): try: nachname = row.Nachname except AttributeError: return 0 return self.pattern.search(nachname)is not None vf = vw.filter(PatternFilter("ra.*")) for r in vf: print vw[r.index].Nachname From martin at v.loewis.de Tue Aug 5 16:34:24 2003 From: martin at v.loewis.de (Martin v. =?iso-8859-15?q?L=F6wis?=) Date: 05 Aug 2003 22:34:24 +0200 Subject: Win32All Crashes Python 2.3? References: <1tkngb.2h1.ln@boundary.tundraware.com> Message-ID: Tim Daneliuk writes: > > Please verify that there is only a single copy of the CRT in your > > process. > > > ^^^^^^^^^^^^^^^^^^^^^^^^ > > Please clarify what you mean by this - I am unclear with "CRT" in this > context. C Runtime Library: msvcrt.dll, mscvrt4.dll, crtdll.dll, msvcr7.dll, msvcr71.dll, etc. Regards, Martin From nospam at the.net Tue Aug 26 15:12:36 2003 From: nospam at the.net (Rune) Date: Tue, 26 Aug 2003 21:12:36 +0200 Subject: Uncatchable socket.error in socket.py (?) References: <3f4ba0bb$0$49103$e4fe514c@news.xs4all.nl> Message-ID: Irmen de Jong wrote: >Rune wrote: >> Now, enough words: What I wonder is: Can I catch that socket.error? > >By not doing > > from socket import * > >but rather > > import socket > >(and prefixing your code with "socket." where it's needed). > >The socket.error you tried to catch is coming from the socket >object that you placed in your namespace by doing the "from" >import. And the socket class doesn't have an "error" attribute ;) Thanks Irmen, but the problem seems to be that the server is actually crashed before I can catch the exception. There is no connection to send output to. I have no idea how to avoid this. Rune From aahz at pythoncraft.com Thu Aug 28 20:26:41 2003 From: aahz at pythoncraft.com (Aahz) Date: 28 Aug 2003 20:26:41 -0400 Subject: Garbage Collection Question References: <2ce55ce2.0308281518.4be94efc@posting.google.com> Message-ID: In article <2ce55ce2.0308281518.4be94efc at posting.google.com>, Chaman Singh Verma wrote: > >I am trying to integrate C++ with Python. I read that Python does >automatic garbage collection. I am creating new objects in C++ and >passing to Python, I don't know now who should control deleting the >objects. If I create objects in C++ do I have to clean them or Python >will use GC to remove unwanted objects. Depends whether it's a Python object created with a Python API call. If not, your objects will never be touched by Python. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From tzot at sil-tec.gr Sun Aug 24 00:45:44 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Sun, 24 Aug 2003 07:45:44 +0300 Subject: Bug with win32 open and utf-16 file References: <27vekvc6evvn3m5jg8n1en2u42skat42qn@4ax.com> <2i1gkv0s7762vcs85rkdq6uvgk6oitje12@4ax.com> <78egkvg1tu0j1kvedclcefn01hr3vkqh4v@4ax.com> Message-ID: On Sun, 24 Aug 2003 04:37:42 GMT, rumours say that derek / nul might have written: >errr, no, just a small p programmer from vb and perl trying to learn an OO >language. Welcome aboard then, fellow Agent user (I have missed some upgrades it seems...) You'll be fine with Python (what's a small p programmer? unless you stutter when you type! ;-), especially with the newsgroup, and keep in mind that should we fail to help you, it's guaranteed you'll get DOUBLE your money back! Now, to re-instate seriousness, try again the tutorial and then make yourself comfortable with the documentation index. We'll be here for more help. -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From http Sun Aug 31 13:23:32 2003 From: http (Paul Rubin) Date: 31 Aug 2003 10:23:32 -0700 Subject: SF deploys SA, lauds P & BC References: Message-ID: <7x8yp991wr.fsf@ruckus.brouhaha.com> "Terry Reedy" writes: > In Friday's occasional newsletter to registerees, SourceForge > announced that it has deployed SpamAssassin (written in Python) Huh? There are some nice Python spam filters, but SpamAssassin is written in Perl. From theller at python.net Thu Aug 14 14:18:45 2003 From: theller at python.net (Thomas Heller) Date: Thu, 14 Aug 2003 20:18:45 +0200 Subject: py2exe service and tool-tray app combined? In-Reply-To: <3F3BCA55.5040201@teksavvy.com> (Graham Fawcett's message of "Thu, 14 Aug 2003 13:43:49 -0400") References: <3F3A8371.840.20CD3615@localhost> <1xvop3ad.fsf@python.net> <3F3BCA55.5040201@teksavvy.com> Message-ID: <3cg4qf0a.fsf@python.net> Graham Fawcett writes: > Thomas Heller wrote: > >>If you discovered a bug in an .sll file, you could either buid and >>distribute a new version of it, or you could create an additional, new >>.sll file containing the fixed methods. And you would make sure to list >>this new .sll in the myapp.bnd file, before the buggy one. This way the >>size of the upgrade could be kept as small as possible. >> >>Now, isn't this '.bnd' file mechanism also a nice idea for py2exe? >> > "Nice idea" is an understatement, Thomas -- it would be heaven! > > Presumably the Python analog of the .sll file would have to contain > new/corrected modules, rather than just new/corrected methods, unless > you're one of those wild aspect-weaving types. > > And presumably there would be inspection mechanisms to allow for > examination of the .bnd file, and provide an opportunity for fetching > updates when the program boots... > > An installed app could "phone home" to an update-server, send nothing > but a message digest of its .bnd file, fetch a new .bnd if the old one > is stale, and pull down the missing-but-requisite .sll files... all > before the __main__ module starts importing the app logic. That's cool. > > It would be nice, for long-running apps, if there were a facility for > restarting the app automatically (under permitted conditions) if > updated code were detected at the update server. Maybe just a runtime > api for determining if the codebase is up to date, and then let the > app make the decision whether to restart. The .bnd file would trigger three actions: The first part is done before Py_Initialize is called - setting the Python interpreter flags, and preparing an initial PYTHONPATH. This would have to be done from C code alone, so it must be trivial. The second part would run after Py_Initialize has been called, and so it could be implemented with Python code: downloading updated packages, and preparing the final environment. The third and final part would then probably run the script itself. > All this could be done in the absence of py2exe, of course, but a > standardized framework for this kind of thing would be ideal. It could > complement PyPI and distutils as well, I would imagine. > > So, having swooned for a moment, let me ask: are you considering > adding such a mechanism to the new py2exe? Currently, I'm thinking about the possibilities. And I'm trying to convince the relevant people to accept a patch for Py_Main(), implementing all this and thus making it cross-platform. Thomas From martin at v.loewis.de Tue Aug 5 15:35:01 2003 From: martin at v.loewis.de (Martin v. =?iso-8859-15?q?L=F6wis?=) Date: 05 Aug 2003 21:35:01 +0200 Subject: MSVC 6.0 Unsupported? References: Message-ID: Syver Enstad writes: > It seems that the #defines that makes staticforward into extern when > using the MSVC 6 compiler has been removed from object.h. So I guess > this means I should use VC++ 7.0 to compile python with? That assumption is definitely wrong. If VC6 fails to compile some code, it is likely a problem in that code, not in Python. Regards, Martin From jacek.generowicz at cern.ch Mon Aug 25 09:39:24 2003 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 25 Aug 2003 15:39:24 +0200 Subject: macro FAQ References: <2259b0e2.0308240103.3966476b@posting.google.com> <87znhzi4k4.fsf@pobox.com> <87k791di9w.fsf@pobox.com> Message-ID: jjl at pobox.com (John J. Lee) writes: > Jacek Generowicz writes: > > > - I do _not_ necessarily advocate the inclusion of macros in Python. > > But you do advocate them in other languages, right? And that was a > significant part of the argument. You've lost me. What I advocate is that, in the process of constructing an FAQ or article about macros in Python, one should try to exclude material which sounds like this: Q: What is static typing, and why isn't it included in Python? A: Static typing is the requirement that the programmer write his code while standing up. Some people believe that this causes infertility. Or, to make a closer analogy: Q: What are functions, and why aren't they included in Assembler ? A: Functions are a very powerful means of creating abstarctions. Some people believe that functions make a program more difficult to understand. Functions also cause languages to split, as evidenced by the existence of many different languages which support functions. If any programmer on your project writes a function, random parts of the code _you_ wrote will stop working; shortly thereafter frogs will rain from the sky for forty days. Put another way, I advocate avoiding FUD. To this end, I have tried to provide information which would help readers of this list, who are unfamiliar with Lisp-style macros, to understand what Lisp-style macros are. If I am involved in an argument, then it is an argument about what Lisp-style macros _are_ and what they can or can't do ... completely independently of any language in which they may or may not be available, now or in the future. I offer no opinion on whether Lisp-style macros are a good idea. I would like people to form their own opinions on the matter, but I would like those opinions to be based on fact rather than on FUD. Now, what is it that _you_ are arguing ? From goodger at python.org Thu Aug 21 11:42:08 2003 From: goodger at python.org (David Goodger) Date: Thu, 21 Aug 2003 11:42:08 -0400 Subject: docutils: ImportError: No module named roman In-Reply-To: <6f03c4a5.0308210640.46504655@posting.google.com> References: <6f03c4a5.0308210640.46504655@posting.google.com> Message-ID: Rim wrote: > ImportError: No module named roman > > What provides the roman module? It comes with Docutils, and is installed by the same "python setup.py install" as Docutils itself. It's in the "extras" directory (3rd party code), and is only installed if not already present. > I can't run docutils/tools since I upgraded to python2.3. After you upgraded, did you reinstall Docutils? . Use the snapshot for the latest code: . -- David Goodger From joch at blueyonder.co.uk Tue Aug 12 04:22:49 2003 From: joch at blueyonder.co.uk (John Ochiltree) Date: Tue, 12 Aug 2003 09:22:49 +0100 Subject: Running Python 2.3 on a Windows 2000 network Message-ID: Hello group, What do I have to do to set up python 2.3 to run centrally on a Win 2000 network instead of installing it on every workstation? Is it possible? How do I go about updating individual registeries? I'd appreciate some pointers and advice if any one can help. Thanks John From tyler at scalegen.com Fri Aug 1 21:42:06 2003 From: tyler at scalegen.com (Tyler Eaves) Date: Fri, 01 Aug 2003 21:42:06 -0400 Subject: String Replacement References: <7b454334.0308011400.266438f9@posting.google.com> <7b454334.0308011726.15d12be9@posting.google.com> Message-ID: On Fri, 01 Aug 2003 18:26:26 -0700, Fazer wrote: > Hmm... > > This works: > print string.replace(str, "\n", "
") > > But I can't assign the result into a variable but only print it like > the code above. > > What can I do to assign the repalced string to a variable? Because I > Have other string replacements to do with that very same string. > > Thanks, str = str.replace("\n", "
") From tim.one at comcast.net Fri Aug 8 13:06:24 2003 From: tim.one at comcast.net (Tim Peters) Date: Fri, 8 Aug 2003 13:06:24 -0400 Subject: random changes In-Reply-To: Message-ID: [Raymond Hettinger] > ... > The OP's original concern was traced back to a change between > Py2.0 and Py2.1 where the WichmannHill seed routine was > improved (doubling the key space and reducing duplicate > states generated from different seeds). It was closer to squaring the useful seed space; merely doubling it wouldn't have been worth the bother. From james.kew at btinternet.com Sat Aug 30 08:13:51 2003 From: james.kew at btinternet.com (James Kew) Date: Sat, 30 Aug 2003 13:13:51 +0100 Subject: Win32 documentation in CHM? References: Message-ID: "Robin Becker" wrote in message news:CDURXJA3QHU$EwUz at jessikat.fsnet.co.uk... > The argument is made that .chm is a better mechanism (more searchable > indexable etc) for help/documentation than html. Is that really so? I've certainly found it so in the ActiveState distribution, which packages the Python docs, plus selected third-party docs -- win32all, Dive Into Python -- into a unified HTML Help package. Very, very handy to be able to quickly look things up in a common index, or search across the whole lot. (Still waiting for a 2.3 ActiveState distro, though...) James From nplejic.remove at programiranje.nospam.net Tue Aug 12 04:38:53 2003 From: nplejic.remove at programiranje.nospam.net (Nikola Plejic) Date: Tue, 12 Aug 2003 10:38:53 +0200 Subject: Is Python your only programming language? References: <3F389887.F7AB871E@alcyone.com> Message-ID: In news:3F389887.F7AB871E at alcyone.com, Erik Max Francis wrote: > Joe Cheng wrote: > >> I want to ask you hard-core c.l.p Pythonistas: Do you use Python for >> everything? (and I'm counting Python + C extensions as just Python) >> Or do >> you keep another language equally close at hand, and if so, what is >> it? And >> finally, do you foresee a day when Python can be, for all practical >> intents >> and purposes, your only programming language? > > I get paid to write C++ or C, use Python for recreational projects, > and use shell, Python, or (rarely) Perl for administration tasks. For > recreation and exploration I play around with a variety of other > languages, including Io, APL/J, Logo, Prolog, Scheme, and so on. I use Python for most of my projects, but for web I use PHP. I also have some knowledge of C++ (but very limited), and I am planning on expanding that knowledge soon. I started learning C++ before Python, but when I saw Python, I paused learning C++ and turned to Python. Python can suit most of the programming needs today, but not all. It has limitations, just as any other programming language and I think there will always be cases where using some other programming language will be more efficient or more suitable for some projects. As for me, personally, Python suits my needs even now, as I am not some advanced programmer, but I suppose I will see some limitations and downsides as I progress. I also play around with Visual Basic with my friend a bit when we're at school, but he knows VB way better than I do. -- Greets, Nikola ( http://zweistein.cjb.net ) From Spam.Buster at web.de Wed Aug 20 15:50:43 2003 From: Spam.Buster at web.de (Lars Behrens) Date: Wed, 20 Aug 2003 21:50:43 +0200 Subject: 'name is too long' (tarfile, python 2.2, Debian Woody) In-Reply-To: <3F43BBCB.99C3E163@engcorp.com> References: <3F43306D.3080704@skynet.be> <3F43BBCB.99C3E163@engcorp.com> Message-ID: Peter Hansen wrote: > Perhaps this is a sign that the problem was really somewhere else. What > you say you did is not likely to have solved the problem given the > documentation above. It says that setting tar.posix to *False* would > allow longer path names, not the other way around. If you think you > just got longer names to work and your problems went away, you > are probably missing something here... Sorry, a typo, of course I set tar.posix to false. Mea culpa... Cheerz Lars From Hengsun.Chao at Cognos.Com Mon Aug 25 15:05:00 2003 From: Hengsun.Chao at Cognos.Com (Chao, Heng Sun) Date: Mon, 25 Aug 2003 15:05:00 -0400 Subject: [Stackless] Stackless ported to 2.2.3 Message-ID: That did the trick. Thanks. Heng Sun Chao System Solution Testing Cognos Inc. 738-1338 x 5051 -----Original Message----- From: Christian Tismer [mailto:tismer at tismer.com] Sent: Monday, August 25, 2003 2:26 PM To: Chao, Heng Sun Cc: Pythonistas; Stackless at tismer.com Subject: Re: [Stackless] Stackless ported to 2.2.3 Chao, Heng Sun wrote: > I did so. The help works fine. However, I remember there was some > variable I had to set to make the recursion work for 100000. Right now, > recursion dies at before 1000 depth. sys.setrecursionlimit is a standard Python function. ciao - chris -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 pager +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ Join us at Cognos' biggest event of the year Enterprise 2003, The Cognos Business Forum. Taking place in over 25 cities around the world, it's an opportunity for Business and IT leaders to learn about strategies for driving performance. Visit http://www.cognos.com/enterprise03 for more details. This message may contain privileged and/or confidential information. If you have received this e-mail in error or are not the intended recipient, you may not use, copy, disseminate or distribute it; do not open any attachments, delete it immediately from your system and notify the sender promptly by e-mail that you have done so. Thank you. -------------- next part -------------- An HTML attachment was scrubbed... URL: From skip at pobox.com Mon Aug 18 11:49:33 2003 From: skip at pobox.com (Skip Montanaro) Date: Mon, 18 Aug 2003 10:49:33 -0500 Subject: python & postgresql ? In-Reply-To: References: Message-ID: <16192.62861.313218.518622@montanaro.dyndns.org> Tom> I'm trying to develop a cross-platform python-gui for a postgresql Tom> db. Of course, I need some postgresql-module for python... Tom> Pygresql seems the obvious choice, but I'm developing on windows Tom> xp. To get pygresql to work I need to compile pygresql with a Tom> visual c++ compiler (wich I don't have). I think you're going to have to find a way to compile C code on your machine (mingw, cygwin, etc) or find a binary distribution of one of the PostgreSQL modules. I use psycopg. You should be able to find a binary installer for one of the possibilities. You could also start development on Linux and when it's good enough, maybe a Windows person will step in to help out. Skip From trimtab at mac.com Thu Aug 21 01:08:27 2003 From: trimtab at mac.com (Olivier Drolet) Date: 20 Aug 2003 22:08:27 -0700 Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> <6dj2kv8ugkieehs7guh786cl40o5lj6mcs@4ax.com> Message-ID: <599a6555.0308202108.397bb1a0@posting.google.com> Alex Martelli wrote in message news:... > Doug Tolton wrote: > ... > > Linux is based on... (...) >... a zillion mediocre ones. > > > Alex Macros, as found in Common Lisp, do not change the underlying language at all! Common Lisp macros, when run, always expand into 100% ANSI Common Lisp code! Using macros to become more productive is no different from using function abstractions or class hierarchies to become more productive. They all require that you, the programmer, become familiar with them. Macros don't cause Common Lisp to fork anymore than function or class abstractions do. They only alter the readability of "program code" (usually for the better), just like function or class abstractions do. Saying that all hell will break loose in the Python community seems rather unfounded and a bit knee-jerk. None of what you claim would eventually happen within Python circles is currently happening within the Common Lisp community. After years of macro use, ANSI Common Lisp is till the same. Macros don't bypass ANSI committees anymore than they would the Guidos of this world. On the contrary, they preclude the need to bypass them in the first place, and all parties end up getting what they need: on the one hand, a static base language, and on the other, much greater expressiveness. Speaking of expressiveness, someone asked on comp.lang.lisp.fr what macros were good for, concretely, and what quantitative difference they made in commercial applications (cf. "Macros: est-ce utile ? (attn Marc)"). The responses (in French) were quite enlightening. It boils down to using multiple macros, in multiple instances, thus allowing to reduce total code size (of otherwise pure CL code) by VERY significant margins. You can think of it as reuse (as per OOP) or as code compression. Macros do not have to be used all the time or at all. There are times when a macro should not be used, e.g. when a function would do just fine. But they are very powerful. As Paul Graham put it, macros allow you to program up towards the problem at hand, as opposed to adapting the problem to fit the language specification. They allow greater expressiveness, when you need it. They allow you to "use" many lines of code you no longer have to write. And the lines of code you don't have to write are also the lines of code you don't have to debug (as it were). Cheers. From mpeuser at web.de Sat Aug 16 15:12:15 2003 From: mpeuser at web.de (Michael Peuser) Date: Sat, 16 Aug 2003 21:12:15 +0200 Subject: GUI builder for Python References: Message-ID: "dan" schrieb im Newsbeitrag news:fbf8d8f2.0308160831.6d03aadd at posting.google.com... > "Michael Peuser" wrote in message news:... > > > Have you tried it? It is not a Python tool ;-) And there had been not much > > move there for more than a year... > > What do you mean about it not being a Python tool? It supports > wxPython, right? If you mean it wasn't written in Python, why should > I care about that? Well, I haven't found out what it can do with Python let alone what it can do in the first place .... Michael P > > > > There is a well known set of GUI Builders for Pyhon around, most of them > > mentioned in this thread. > > The most important decision is what GUI-Toolkit to use. This will influence > > much of your *programming* tasks that follows the *layout*. Printing? > > HTML-Widget? Drag-and-Drop? > > Agreed. > > > > > There is no silver bullet at the Python market at the moment... > > Too bad. > > -dbm From alan_salmoni at yahoo.com Wed Aug 27 10:47:11 2003 From: alan_salmoni at yahoo.com (Alan James Salmoni) Date: 27 Aug 2003 07:47:11 -0700 Subject: My future Python IDE article References: Message-ID: Hi David, Although a lot of posters have recommended Emacs (and maybe Vim too?), I would avoid reviewing it (them) simply because it's been done so many times already. Personally, I would include: 1) SciTE - cross-platform, multi-language etc. It alters the font for different elements of code (eg, comments are in one font, code in another which, along with different colours, makes different sections easy to locate - for me at least!). 2) Leo - I have tried to use this, but am not really up to speed with it. However, it seems interesting, and like a previous poster said, it could be used for many tasks. It seems quite powerful once it is learned. All the best! Alan James Salmoni SalStat Statistics http://salstat.sunsite.dk mertz at gnosis.cx (David Mertz) wrote in message news:... > Pythonistas, > > My loyal fans :-) will remember that I did a Python IDE roundup for > _Charming Python_ a couple years back. Now I have another such roundup > lined up... not the very next article, but it's there on the list. > > In the intervening years, I've hardly touched anything one might call an > IDE. I've looked at screenshots from time to time, and read various > announcements. But really I just use text editors and command lines. > > Here's the thing: I probably have room to look at about four different > tools in one article. In fact, it wouldn't be absurd to only do three. > Past that, I cannot do more than list contact information and platform > in the available words. I'm sure there are more than four IDEs that > -someone- loves to work with out there... but I need to have a cutoff. > > So c.l.py readers... make the case for your favorite one getting on the > list. I have a while to ponder the opinions advanced, should this > prompt some discussion (it may take a little while to order review > copies of commercial tools and/or get things installed). > > Yours, David... From gherron at islandtraining.com Thu Aug 7 12:20:32 2003 From: gherron at islandtraining.com (Gary Herron) Date: Thu, 7 Aug 2003 09:20:32 -0700 Subject: Gmpy In-Reply-To: <8578e2c1.0308070630.5fb70c22@posting.google.com> References: <8578e2c1.0308070630.5fb70c22@posting.google.com> Message-ID: <200308070920.32886.gherron@islandtraining.com> On Thursday 07 August 2003 07:30 am, Jean-Pierre Andreaux wrote: > Gmpy module was a wrapper of the GNU MP library. It seems that no > evolution is done on this module since 2001. Indeed, Gmpy is not > supported in Python 2.2 nor 2.3. > > My question is the following: what is the better replacement solution > for manipulating long numbers. I want to do long numbers > exponentiations. Thanks in advance for your answers. > > JP Python has (arbitrarily) long integer support built right in. For instance: >>> ((2**10)**10)**10 10715086071862673209484250490600018105614048117055336074437503883703510511249361224931983788156958581275946729175531468251871452856923140435984577574698574803934567774824230985421074605062371141877954182153046474983581941267398767559165543946077062914571196477686542167660429831652624386837205668069376L Notice the 'L' on the end of the result implies the value is a "long' integer, not a 32-bit integer. In recent versions of Python, arithmetic on normal integers will convert to long integers when an overflow occurs. Is this what you wanted? Gary Herron From bucket79 at daum.net Thu Aug 21 04:10:41 2003 From: bucket79 at daum.net (bucket79) Date: 21 Aug 2003 01:10:41 -0700 Subject: gdbm compatibility between linux and freebsd Message-ID: <95f72778.0308210010.5b493c9b@posting.google.com> here's a problem A is redhatlinux and B is freebsd A) $uname -a Linux xxxxxxxxx 2.4.7-10 #1 Thu Sep 6 17:27:27 EDT 2001 i686 unknown $python -V Python 2.2.2 $ldd /usr/local/lib/python2.2/lib-dynload/gdbm.so libgdbm.so.2 => /usr/lib/libgdbm.so.2 (0x4000a000) libc.so.6 => /lib/i686/libc.so.6 (0x40011000) /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x80000000) B) $uname -a FreeBSD xxx.xxx.xxx 5.1-CURRENT FreeBSD 5.1-CURRENT #0: Mon Aug 18 11:34:38 KST 2003 xxxxxxxxxxxxxxxxxxxxxx i386 $python -V Python 2.2.3 $ldd /usr/local/lib/python2.2/site-packages/gdbm.so libc_r.so.5 => /usr/lib/libkse.so.1 (0x2815e000) libgdbm.so.3 => /usr/local/lib/libgdbm.so.3 (0x28180000) and the problem is gdbm db file is not compatible between two system for example in system A) >>import gdbm >>f = gdbm.open("test.db", "c") >>f["1"] = "first" >>f.close() and copy this file to freebsd system and try to open this file then it fails !! like this in system B) >>import gdbm >>f = gdbm.open("test.db", "r") Traceback (most recent call last): File "", line 1, in ? gdbm.error: File read error and reverse case is also fails. more precisely say in this case python occurs gdbm FATAL error :( anyone know what is the casuse of this problem? From aleax at aleax.it Fri Aug 29 10:31:21 2003 From: aleax at aleax.it (Alex Martelli) Date: Fri, 29 Aug 2003 14:31:21 GMT Subject: string.count issue (simple) References: Message-ID: Halfdan Holger Knudsen wrote: > ok first off: Has the string.count function been replaced in python 2.2 > (as compared to 1.5)?m And second: > > I need this in relation to a stringsearch program > assuming a text file has been loaded into allLines and word contains the > string you're searching for I want to count all occurences of the search > string the following should do it (but doesn't - please disregard any > missing colons or such this has not been copy/pasted): > > count = 0 > > for eachLine in allLines: > if eachLine.find(word) > -1: > count = count + eachLine.count(word, beg=0, end=len(eachLine) Method count does not take keyword arguments. Besides, the ones you're specifiying are redundant, and the if's condition is double work. > print eachLine > print count I would recode this as: count = 0 for eachLine in allLines: countOnLine = eachLine.count(word) if countOnLine: count = count + countOnLine print eachLIne print count > what am I missing - it only outputs the nubmer of lines (as if the count > statement had been count = count + 1) Hard to explain, since the code you're posting (with the keyword arguments) can't possibly be the one you're running. Alex From guineapig at pi.be Thu Aug 21 07:31:43 2003 From: guineapig at pi.be (Tom Van den Brandt) Date: Thu, 21 Aug 2003 13:31:43 +0200 Subject: what to do when instance of class fails to initialize ? References: Message-ID: Tnx guys, Problem solved... From newsgroups at jhrothjr.com Mon Aug 4 07:12:49 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Mon, 4 Aug 2003 07:12:49 -0400 Subject: time, calendar, datetime, etc References: Message-ID: "Tim Peters" wrote in message news:mailman.1059967687.8907.python-list at python.org... > [Dan Bishop] > >>> There were no leap years between 10 BC and AD 4, because after > >>> Julius Caesar's death, the priests in charge of the calendar > >>> mistakenly added leap days every 3 years instead of 4, and this had > >>> to be corrected. > >>> > >>> I wouldn't expect the datetime module to deal with that, though ;-) > > [Tim] > >> Thank you -- some people did . > > [John Roth] > > I don't think I noticed that: > > Were you a participant in datetime's design process (the fishbowl on > zope.org, previously referenced)? If so, sorry, I don't recall it. No. I didn't even know about it until recently. > > the entire point behind the proleptic calender is that you're > > projecting the current practice back to times where they weren't > > doing it that way. > > And forward too, of course. But not everyone *wanted* a proleptic calendar > (of any flavor). The use cases on the datetime wiki turned out not to care > either way (business uses generally don't give a rip about years before > 1900), so I pushed for the conceptual simplicity of the proleptic Gregorian > (which coincides with current reckoning in much of the world, so satisfied > the use cases). And I agree with that reasoning. There's no way that the module core can deal with historical and other cultural dates in any consistent or comprehensive fashion, so it shouldn't waste effort and try. On the same token, though, it shouldn't get in the way of people who want to extend it to handle additional calendar types, or bring dates back before 1AD. > > That's clearly an opportunity for someone to add an extension - > > except that there are other problems in that era, and the lack > > of leap years is the least of them. > > People who care can scratch their own itches. Exactly. John Roth > > From mal at egenix.com Tue Aug 12 08:19:39 2003 From: mal at egenix.com (M.-A. Lemburg) Date: Tue, 12 Aug 2003 14:19:39 +0200 Subject: ANN: eGenix.com mx Experimental Package 0.8.0 Message-ID: <3F38DB5B.1030207@egenix.com> ________________________________________________________________________ ANNOUNCING: eGenix.com mx Experimental Extension Package for Python 1.5.2 - 2.3 Version 0.8.0 Experimental Python extensions providing important and useful services for Python programmers. ________________________________________________________________________ WHAT IS IT ?: The eGenix.com mx Experimental Extensions for Python are a collection of alpha and beta quality software tools for Python which will be integrated into the other mx Extension Packages after they have matured to professional quality tools. Python is an object-oriented Open Source programming language which runs on all modern platforms (http://www.python.org/). By integrating ease-of-use, clarity in coding, enterprise application connectivity and rapid application design, Python establishes an ideal programming platform for todays IT challenges. ________________________________________________________________________ WHAT'S NEW ? The new version includes patches needed to compile the packages under Python 2.3. As always we are providing precompiled versions of the package for Windows and Linux as well as sources which allow you to install the package on all other supported platforms. ________________________________________________________________________ EGENIX.COM MX EXPERIMENTAL PACKAGE OVERVIEW: mxNumber - Python Interface to GNU MP Number Types mxNumber provides direct access to the high performance numeric types available in the GNU Multi-Precision Lib (GMP). This library is licensed under the LGPL and runs on practically all Unix platforms. eGenix.com has ported the GMP lib to Windows, to also provide our Windows users with the added benefit of being able to do arbitrary precision calculations. The package currently provide these numerical types: 1. Integer(value) -- arbitrary precision integers much like Python longs only faster 2. Rational(nom,denom) -- rational numbers with Integers as numerator and denominator 3. Float(value[,prec]) -- floating point number with at least prec bits precision 4. FareyRational(value, maxden) -- calculate the best rational represenation n/d of value such that d < maxden mxTidy - Interface to HTML Tidy (HTML/XML cleanup tool) mxTidy provides a Python interface to a thread-safe, library version of the HTML Tidy. command line tool. HTML Tidy helps you to cleanup coding errors in HTML and XML files and produce well-formed HTML, XHTML or XML as output. This allows you to preprocess web-page for inclusion in XML repositories, prepare broken XML files for validation and also makes it possible to write converters from well-known word processing applications such as MS Word to other structured data representations by using XML as intermediate format. mxURL - A URL Datatype mxURL provides a new datatype for storing and manipulating URL values as well as a few helpers related to URL building, encoding and decoding. The main intention of the package is to provide an easy to use, fast and lightwheight datatype for Universal Resource Locators (note the W3C now calls these URIs). mxUID - A UID Datatype mxUID provides a fast mechanism for generating universal identification strings (UIDs). The intent is to make these UIDs unique with high probability in order to serve as object or data set identifiers. A typical use lies in generating session IDs. Other areas where unique IDs play an important role are RPC-implementations, ORBs, etc. ________________________________________________________________________ WHERE CAN I DOWNLOAD IT ? The download archives and instructions for installing the packages can be found at: http://www.egenix.com/ Note that in order to use the eGenix.com mx EXPERIMENTAL package you will first need to install the eGenix.com mx BASE package which can be downloaded from the same location. ________________________________________________________________________ WHAT DOES IT COST ? The EXPERIMENTAL packages uses different licenses in its subpackages. Please refer to the subpackage documentation for details. Some of them may be integrated into the BASE package, others will be integrated into the COMMERCIAL package. The package comes with full source code ________________________________________________________________________ WHERE CAN I GET SUPPORT ? Commercial quality support for these packages is available from eGenix.com. Please see http://www.egenix.com/files/python/eGenix-mx-Extensions.html#Support for details about our support offerings. ________________________________________________________________________ Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 12 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From bokr at oz.net Fri Aug 8 16:06:00 2003 From: bokr at oz.net (Bengt Richter) Date: 8 Aug 2003 20:06:00 GMT Subject: ???? i can`t understand it References: Message-ID: On Fri, 8 Aug 2003 08:05:11 -0300, "Batista, Facundo" wrote: >This message is in MIME format. Since your mail reader does not understand >this format, some or all of this message may not be legible. If you could eliminate the HTML, it would improve reception on this end ;-) Regards, Bengt Richter From fredrik at pythonware.com Wed Aug 6 06:33:42 2003 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 6 Aug 2003 12:33:42 +0200 Subject: Problems with path References: <3F30D724.AE91F3F0@tmsk.itm.edu.my> Message-ID: "hamido" wrote: > Why this statement will generate errors > > shutil.copy2("c:\hamido.sql", "c:\ali1.ali") > shutil.copy2('c:\hamido.sql', 'c:\ali1.ali') because "\a" is a character escape (ascii code 7), not a backslash followed by an "a". three solutions: - use forward slashes instead ("c:/ali1.ali") - double the backslashes ("c:\\ali1.ali") - use "raw" strings (r"c:\ali1.ali") to get the full story, check the section on strings in your favourite python book, or read the on-line manual: http://www.python.org/doc/current/tut/node5.html#SECTION005120000000000000000 http://www.python.org/doc/current/ref/strings.html From bouquin at imaginet.fr Thu Aug 7 11:51:15 2003 From: bouquin at imaginet.fr (bouquin at imaginet.fr) Date: Thu, 07 Aug 2003 15:51:15 GMT Subject: The Clyde collection Message-ID: <20030708.155115.dfa98e86@imaginet.fr> An HTML attachment was scrubbed... URL: From mpeuser at web.de Thu Aug 14 09:58:24 2003 From: mpeuser at web.de (Michael Peuser) Date: Thu, 14 Aug 2003 15:58:24 +0200 Subject: uiToolkit and some GUI benchmarking Message-ID: Hi, is there an official way to acquire SecretLabs uiToolkit? I understand they no longer sell PythonWorks. I recently became a fan of Fredrik Lundh's WCK which gives fresh wind to Tkinter. It seems that this is the "open source spin off" of uiToolkit. WCK can be very fast. I benchmarked some hundered redraws of some thousend characters: 0.8 sec a simple WCK widget 0.9 sec Tkinter.Message (a widget which is somewhat underestimated!) 4.3 sec Tkinter.Text 5.8 sec Tkinter.ListBox Most of the time is spend in internal working of update() however; these figures also change depending on screen depth. But there is great potial in WCK in annotating the displayed text. I added small coloured rectangle to each and every character just for fun. Well, after that it took 17 sec for 200 updates - this however means less than 0.1 sec for something Canvas would take 3+ sec (on my laptop at least...) Kindly Michael P From pu Tue Aug 12 17:21:04 2003 From: pu (Patrick Useldinger) Date: Tue, 12 Aug 2003 23:21:04 +0200 Subject: Python vs. C# In-Reply-To: References: <2259b0e2.0308100616.55b651ca@posting.google.com> <3f36af20@shknews01> Message-ID: <3f3959e3_1@news.vo.lu> Brandon J. Van Every wrote: > [...] Some time ago, you started a similar discussion on C++ vs. Python. You pretended to be just as objective, and you turned out to be just as decided as you are now (funny, isn't it ?). So what the heck is the purpose? I cannot help but think that you are just bored. Maybe 3D-programming isn't that interesting after all ... -Patrick From hans at zephyrfalcon.org Fri Aug 22 15:13:26 2003 From: hans at zephyrfalcon.org (Hans Nowak) Date: Fri, 22 Aug 2003 15:13:26 -0400 Subject: visual indentation In-Reply-To: References: Message-ID: <3F466B56.7010101@zephyrfalcon.org> Hilbert wrote: > Hello, > > I'm using python to output RIB streams for Renderman. > The RIB stream is a bunch of statements which describes > a 3d image. The Rib standard allows for blocks which we > usually indent for better visualization for example: > > WorldBegin > Color [1 1 1] > Surface "constant" > Sphere(1.0, -1.0, 1.0, 360) > WorldEnd > > I'm using CGKit in python which has a Renderman binding, > so to output the same RIB I'd write: > > RiWorldBegin() > RiColor(1.0,1.0,1.0) > RiSurface('constant') > RiSphere(1.0,-1.0,1.0,360) > RiWorldEnd() > > But I get an error, because python interprets my indentation > as a block in the python code. So the only way to write this > is without the indentation: > > RiWorldBegin() > RiColor(1.0,1.0,1.0) > RiSurface('constant') > RiSphere(1.0,-1.0,1.0,360) > RiWorldEnd() > > But this is a lot harder to read. > > Is there any way to use such "visual" indentation in python? I can think of various ugly solutions, none of them very satisfying... First, you can fake an indented block, e.g. like this: RiWorldBegin() if 1: RiColor(1.0, 1.0, 1.0) # etc... RiWorldEnd() Or you can put the function calls in a dummy list/tuple: RiWorldBegin() [ RiColor(1.0, 1.0, 1.0), RiSurface('constant'), RiSphere(1.0,-1.0,1.0,360), ] RiWorldEnd() Or you can put some dummy statements in front... RiWorldBegin() (); RiColor(1.0, 1.0, 1.0) (); RiSurface('constant') (); RiSphere(1.0,-1.0,1.0,360) RiWorldEnd() I warned you they were ugly... :-) Maybe the best solution would be judicious use of comments, e.g. RiWorldBegin() # RiColor(1.0, 1.0, 1.0) RiSurface('constant') RiSphere(1.0,-1.0,1.0,360) # RiWorldEnd() This doesn't give you indentation, but at least the statements in the "block" stand out more. But maybe somebody else has a better solution...? -- Hans (hans at zephyrfalcon.org) http://zephyrfalcon.org/ From cliechti at gmx.net Sun Aug 3 12:47:47 2003 From: cliechti at gmx.net (Chris Liechti) Date: 3 Aug 2003 18:47:47 +0200 Subject: Parallel port monitoring References: Message-ID: Dennis Lee Bieber wrote in news:m7duv-uk3.ln1 at beastie.ix.netcom.com: > Mark Daley fed this fish to the penguins on Friday 01 August 2003 > 09:38 am: >> I've read many threads regarding parallel port manipulation, but is >> there anything that can simply monitor what's happening on the >> parallel port, and >> perhaps react to certain events on said port? I would much rather do >> that than simply program a preset wait time. dpends what you mean with events... depending on the parallelport mode and which pins you use, thee are no interrupts available. so that you need to do polling and wont be able to detect short events. > You are using M$ Outlook to post... Are you using W9x or an NT > derivative (NT, 2K, XP)? > > On the latter, low-level access to the I/O port addresses > requires > privileged drivers... the W9x line still allows user programs to do > direct I/O port access... So the next question would be "Does Python > have a library that allows for machine code access to "in" and "out" > instruction. yes it has :-) i have a modules on http://pyserial.sourceforge.net/pyparallel.html it works on win nt/2k/xp and 9x/me (linux under slow developement) > Not sure, but I suspect Linux also puts those in the > privileged mode. there is the ppdev kernel module for the parallelport, or you can access it with ioctls and ioperms. > These also ignore such things as USB -> Parallel adapters. yep, but as there is no parallelport abstraction in Windows and not on all linux (not all have ppdev) there isn't much choice :-( chris -- Chris From bgailer at alum.rpi.edu Fri Aug 15 21:01:34 2003 From: bgailer at alum.rpi.edu (Bob Gailer) Date: Fri, 15 Aug 2003 19:01:34 -0600 Subject: how does the main module notice when I change a module In-Reply-To: <3f443b52.0308151255.50c58885@posting.google.com> Message-ID: <5.2.1.1.0.20030815190030.026e4bd0@66.28.54.253> At 01:55 PM 8/15/2003 -0700, Marcus Schneider wrote: >I use PythonWin on WinXP. Every time I change a module, I have to >leave PythonWin and re enter to make it notice I have made changes. I >guess this is not the normal way to do that.. do I have to store the >module at a specific place? Is there a kind of "reset" command to make >the main module update specific data? Notice File -> Import (ctrl+I) and its toolbar icon. Bob Gailer bgailer at alum.rpi.edu 303 442 2625 -------------- next part -------------- --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.506 / Virus Database: 303 - Release Date: 8/1/2003 From aleax at aleax.it Thu Aug 7 10:28:25 2003 From: aleax at aleax.it (Alex Martelli) Date: Thu, 07 Aug 2003 14:28:25 GMT Subject: Tkinter programming problem References: Message-ID: klappnase wrote: > "Mark Daley" wrote in message > news:... >> I have problems with sys.exit() when I'm running under IDLE, since it >> seems >> to cause ALL mainloops to exit, killing IDLE. I can't really give a >> whole lot of detail on this, since I tend to use the command line to >> launch my GUIs, anyway. >> > sys.exit()will stop (exit) the python interpreter. If you are running > your program from within IDLE it will exit IDLE, too, because IDLE > runs in the interpreter as well. Depends on what release of IDLE you're running...: > Python 2.3+ (#1, Aug 5 2003, 17:15:06) > [GCC 3.2.2 (Mandrake Linux 9.1 3.2.2-3mdk)] on linux2 > Type "copyright", "credits" or "license()" for more information. > > **************************************************************** > Personal firewall software may warn about the connection IDLE > makes to its subprocess using this computer's internal loopback > interface. This connection is not visible on any external > interface and no data is sent to or received from the Internet. > **************************************************************** > > IDLE 1.0 > >>> import sys > >>> sys.exit(23) > > Traceback (most recent call last): > File "", line 1, in -toplevel- > sys.exit(23) > SystemExit: 23 > >>> As you see, with the IDLE 1.0 which comes with Python 2.3, the exception raised by sys.exit is captured and displayed as such [and similarly if sys.exit is called from a module run within the IDLE session, rather than directly at the IDLE prompt]. (Why KNode only lets me "Paste as Quotation", not plain "Paste", what I have "Select All" / "Copy" - ed from IDLE's PythonShell window, is one of those mysteries which may need Poirot to unravel... mah...!). > If you run your program from the command line sys.exit() will exit the > interpreter and stop the program, of course any instructions in the > code after sys.exit() won't be executed. > I think normally that is exactly what I want in a gui program - stop > everything if the main window is closed. Often one may want to do some kind of clean-up at that point, but you may achieve that with a try/finally around the mainloop call (putting the cleanup code in the finally clause, of course). > widget.destroy() will destroy "widget" and if "widget" is the main > window of your application it will be destroyed - and all it's > children with it. > That's the way it should work if you are running from within the > interpreter: > your application is stopped but the interpreter won't be affected by > this. IDLE 1.0 agrees with you. However, the interactive text-mode Python shell disagrees (it doesn't capture SystemExit and does terminate). Alex From pedrosch at gazeta.pl Fri Aug 15 12:39:26 2003 From: pedrosch at gazeta.pl (Drochom) Date: Fri, 15 Aug 2003 18:39:26 +0200 Subject: cPickle alternative? References: Message-ID: > What protocol did you pickle your data with? The default (protocol 0, > ASCII text) is the slowest. I suggest you upgrade to Python 2.3 and > save your data with the new protocol 2 -- it's likely to be fastest. > > > Alex > Thanks:) i'm using default protocol, i'm not sure if i can upgrade so simply, because i'm using many modules for Py2.2 From peter at engcorp.com Thu Aug 28 13:52:53 2003 From: peter at engcorp.com (Peter Hansen) Date: Thu, 28 Aug 2003 13:52:53 -0400 Subject: Binary data handling ? References: <3F4E1B82.E4F7AC6D@engcorp.com> <001601c36d89$dca98470$6400a8c0@EVOD31> Message-ID: <3F4E4175.53A637E2@engcorp.com> Bill Loren wrote: > > about the code problem, I did fix that bug you mentioned, but it still > doesn't work. > the code is: > data = data.replace(...the two options I mentioned before...) > but alas... no replacement... Since the following clearly works, you must be confused about what is in the string called "data" prior to the replacement: C:\>python22 Python 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> s = 'test 1\r\ntest 2\rtest 3\ntest4\r\n\r\ntest5' >>> s 'test 1\r\ntest 2\rtest 3\ntest4\r\n\r\ntest5' >>> t = s.replace('\r\n', '\n') >>> u = s.replace('\x0d\x0a', '\x0a') >>> v = s.replace('%c%c' % (13, 10), '%c' % (10)) >>> t 'test 1\ntest 2\rtest 3\ntest4\n\ntest5' >>> u 'test 1\ntest 2\rtest 3\ntest4\n\ntest5' >>> v 'test 1\ntest 2\rtest 3\ntest4\n\ntest5' (Please post to the newsgroup/mailing list instead of mailing directly, so that others can benefit from or participate in the discussion.) -Peter From hanzspam at yahoo.com.au Mon Aug 25 16:52:21 2003 From: hanzspam at yahoo.com.au (=?ISO-8859-1?Q?Hannu_Kankaanp=E4=E4?=) Date: 25 Aug 2003 13:52:21 -0700 Subject: macro FAQ References: Message-ID: <840592e1.0308251252.74382e29@posting.google.com> Jacek Generowicz wrote in message news:... > ==== Example 1: a debugging aid ================================ > === Example 2: Alexander Schmolck's updating classes =============== Here's another example of a real life situation where I thought it'd be good to have macros in Python. I was writing a GUI system and I had to define lots of code twice, both for the x-axis and y-axis. Such as if y > self.y - bs and y < self.y + bs + self.height: return (abs(x - self.x) < bs, abs(x - (self.x + self.width)) < bs) else: return False, False and then if x > self.x - bs and x < self.x + bs + self.width: return (abs(y - self.y) < bs, abs(y - (self.y + self.height)) < bs) else: return False, False Obviously this was quite unsatisfactory. I ended up putting the axis code in a separate class so I could use them interchangeably. I.e. If I passed func(self.y, self.x) and then func(self.x, self.y) I would get the same effect on both axises. But this would've been an excellent place for macros IMO (unless there's a more clever solution as a whole). Using macros that combine both function call and "code block" syntax, I could've written a simple function like this: defBoth getSize(self): return self.size And it would've been expanded to def getWidth(self): return self.width def getHeight(self): return self.height The macro would've had to change all "size" to either "width" or "height", and also change "pos" to either "x" or "y" and so on. This way, I could've got no duplicated code but also a more intuitive interface than I currently have (to get width, one needs to type obj.x.getSize() instead of obj.getWidth()). And it's obvious this kind of "defBoth" wouldn't be added as a language level construct -- Thus macros are the only good solution. From anthonyr-at-hotmail-dot-com at nospam.com Wed Aug 27 21:48:04 2003 From: anthonyr-at-hotmail-dot-com at nospam.com (Anthony Roberts) Date: Thu, 28 Aug 2003 01:48:04 GMT Subject: Style question... References: Message-ID: > Pressing backspace once (to undo the auto-indent that emacs gives inside > loops) is less typing than 'pass'. And if you need to reindent large > chunks of code, you are better off using emacs block indent/dedent > feature than relying on "pass" as defacto block delimiter (this has been > my experience) What's the keystroke for that? From aleaxit at yahoo.com Sun Aug 17 08:55:06 2003 From: aleaxit at yahoo.com (Alex Martelli) Date: Sun, 17 Aug 2003 14:55:06 +0200 Subject: Py2.3: Feedback on Sets (fwd) References: <2e363c08.0308161306.47a010ae@posting.google.com> Message-ID: David Mertz wrote: ... > Raymond Hettinger also wrote: > |from sets import Set > |def powerset(iterable): > | data = list(iterable) > | for i in xrange(2**len(data)): > | yield Set([e for j,e in enumerate(data) if i&(1< > Hmmm... I should have checked the docs first. A sample implementation > obviously helps. That said, this isn't REALLY an implementation of > powerset. It returns an iterator, not a set. Now, sure... an iterator > is a BETTER thing to get, for lots of reasons. But I'm not sure it > lives up to the function name. Surely writing def therealpowerset(iterable): return Set(powerset(iterable)) (or just inlining the Set call) isn't beyond the abilities of most prospective users. Just like one calls list(x) on any iterable x if one needs specifically a list, so does one call Set(x) if one needs specifically a set. Sure, the name is debatable, and maybe 'subsetsof' would be neater. But I think this is quibbling. IMHO, one 'real' issue with this function is that it behaves strangely (to me) when iterable has duplicated elements -- namely, the resulting iterator also has duplications. Changing the single statement that is currently: data = list(iterable) into data = Set(iterable) would make duplications in 'iterable' irrelevant instead. Alex From dave at boost-consulting.com Mon Aug 4 15:16:15 2003 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 04 Aug 2003 15:16:15 -0400 Subject: boost python & 2.3 References: <4WrXa.16855$an6.616226@news1.tin.it> Message-ID: Alex Martelli writes: > Dave Reed wrote: > ... >> What version of boost are you using? 1.30.0 won't work with Python >> 2.3; however, the CVS version of boost does work with Python >> 2.3. David Abrahams has indicated this on the boost list and I can >> confirm that it does work with Python 2.3 (at least on a Solaris 9 >> system). > > On Linux too -- if and when you can get it all downloaded from > sourceforge (this has proved to be a real problem for me -- I did > manage once on my own machine, but later failed twice on another > machine despite the latter having excellent net backbone access), We now have a mirror at boost-consulting: cvs -d :pserver:anonymous at boost-consulting.com:/boost login cvs -d :pserver:anonymous at boost-consulting.com:/boost checkout boost > and with an annoying but apparently ineliminable warning about > double definition of _POSIX_C_SOURCE on just about each file that > does get compiled (it gets defined in both /usr/include/features.h and > /usr/local/include/python2.3/pyconfig.h), which, however, does seem > to be "benign" (quite annoying, but not really problematic). I'm pretty sure this is just the "must include Python.h before any other system header" problem. That translates into "must include a Boost.Python header before any system header" when using Boost.Python. This issue is non-boost/non-python-specific. It's all about Posix. -- Dave Abrahams Boost Consulting www.boost-consulting.com From marko.komssi at helsinki.fi Fri Aug 29 08:01:14 2003 From: marko.komssi at helsinki.fi (Marko Komssi) Date: 29 Aug 2003 05:01:14 -0700 Subject: Problem installing Python 2.2/2.3 on Windows 98 SE References: <3F41ADC4.3642D39B@yahoo.com> Message-ID: <43ef9556.0308290401.642cb3ab@posting.google.com> "Rami A. Kishek" wrote in message news:<3F41ADC4.3642D39B at yahoo.com>... > Obvious problems: > * IDLE doesn't start at all You mentioned below that you have installed it under C:\Program Files\Python. See the page http://www.python.org/2.3/bugs.html. It is a bug in Python. > ----------------- > D:\PROGRAMS\PYTHON22\lib\site-packages\Pythonwin\pywin\framework\winout.py:455: > DeprecationWarning: strop functions are obsolete; use string methods > self.currentView.dowrite(string.join(items,'')) > PythonWin 2.2.3 (#42, May 30 2003, 18:12:08) [MSC 32 bit (Intel)] on > win32. I had similar looking problem myself. I had e.g. the error message "strop functions are obsolete; use string methods" over and over again. The problem occured because I had left Windows Command Prompt open when installing newer Python version and editing path in environment variables from System Properties. Naturally, path was not updated for already opened Command Prompt and that cause the problem. Just in case, check that there is correct python path in environment variables. However, you need to reinstall Python in a different directory to handle the IDLE problem. -- mko From davidhe at email.com Wed Aug 6 07:44:27 2003 From: davidhe at email.com (Dave) Date: 6 Aug 2003 04:44:27 -0700 Subject: Isn't there a substring(start, end)-function???? Message-ID: Hi all, Am I blind, or what? I can't find any quick way to do the following in Python: substring(beginIndex, endIndex) witch returns the substring between beginIndex and endIndex. Like: text = "If someone attacks you with a banana" print text.substring(0,3) Should print "If " I've found absolutely everything else that I expect from a modern programming language, but none of the modules (not even "string"!) seems to have what I'm looking for. Please tell me I'm blind! Dave From P.Schnizer at nospam.gsi.de Fri Aug 8 03:05:24 2003 From: P.Schnizer at nospam.gsi.de (Pierre Schnizer) Date: 08 Aug 2003 09:05:24 +0200 Subject: Building extensions with mingw32 -- bdist_wininst fails. References: Message-ID: <87adak1vez.fsf@smtp.gsi.de> "Chris Gonnerman" writes: > ----- Original Message ----- > From: "Thomas Heller" > > > > I checked the archives regarding that error message and > > > found a conversation wherein Jeremy Hylton claimed he > > > might have added the code to detect this, and Paul Moore > > > asked to have it removed/disabled at least for mingw32 > > > (which makes binaries 100% compatible with MSVC6). In > > > the case given then, the extension wouldn't build at > > > all; now it builds but I can't make a Windows installer > > > from it. Please excuse, if it is a bit out topic. When I tried to build an extension module for Python2.2 with MingW3.0 I had problems with the conversion of files. So myfile = PyFile_AsFile(object); would crash python2.2 when a standard Python2.2 was invoking an extension module compiled with MinGW. Do you use such conversions in your Module? Thanks for your help Best Regards Pierre From a.neudecker at uni-bonn.de Fri Aug 29 14:18:06 2003 From: a.neudecker at uni-bonn.de (Andreas Neudecker) Date: Fri, 29 Aug 2003 20:18:06 +0200 Subject: method (a, b = '', *c, **d): gets a syntax error? In-Reply-To: References: <3F4F644D.2060003@uni-bonn.de> <3dqcndZe5u2g4NKiXTWJiA@comcast.com> Message-ID: Sorry, have to correct myself on the comma topic: class WhatsUp: # No comma at the end of the list. This works fine. def method1 ( self, var1, var2 = '', *more, **moreNamed ): print "This works fine." # This also works fine, even with the comma at the end. def method2 ( self, var1, var2 = '', var3 = '', # <- THIS COMMA IS FINE. ): print "This works fine." # This will raise a Syntax error because of the comma. def method3 ( self, var1, var2 = '', *more, **moreNamed, # <- THIS COMMA IS NOT ALLOWED. ): print "The comma at the end of the parameter list will \ raise a syntax error." So to me it looks like it makes a difference whether the list contains a variable parameter list or not. I use the version as in method2 often for reasons stated in my previous posting. Still it puzzles me that in one case it is okay in the other one not. Seems unlogical to me. Can anyone enlighten me to why this is so? Thanks to all of you who bothered to point me to my stupid error of forgetting the 'def' and discussing with me the comma problem. Kind regards Andreas From LISTSERV at NIC.SURFNET.NL Sat Aug 30 02:43:28 2003 From: LISTSERV at NIC.SURFNET.NL (L-Soft list server at SURFnet (The Netherlands) (1.8e)) Date: Sat, 30 Aug 2003 08:43:28 +0200 Subject: Message ("Your message dated Sat, 30 Aug 2003 0:43:26...") Message-ID: Your message dated Sat, 30 Aug 2003 0:43:26 --0600 with subject "Re: Details" has been submitted to the moderator of the TEX-NL list: "Jules van Weerden, DIVA, VET, UU, NL" . From mpeuser at web.de Tue Aug 12 18:16:32 2003 From: mpeuser at web.de (Michael Peuser) Date: Wed, 13 Aug 2003 00:16:32 +0200 Subject: drop down feature References: Message-ID: IDLE can help with its Class Browser feature. Although this not "automatic", it will help a lot when using site-packages or even your own old code ;-) For the beginner, of course even properties (attributes and methodes) of standard types are not obvious. I must say, that Python can really be a little bit cryptical (consider *get* oder *has_key* for directories ). I generally have to look it up, when *haskey* or *has* does not work ;-) But you can very well organize yourself with man pages.... The main problem seems to be that Python has no static typing. So it *generally* is not possible for an editor to know what type will dynamically be used. Though in most cases - especially with callable objects - there can be a good guess. Nevertheless I also think that the problem is not so much, that there can be no solution but - as you said - not everyone is aware of the benefits of those feature.... Problems increase especially with GUIs - I would be lost even in Tkinter without a paper reference ;-) Kindly Michael Peuser "Greg Brunet" schrieb im Newsbeitrag news:vjiiditehj6i84 at corp.supernews.com... > Somewhat, depending on the IDE you choose, but not really. Search the > newsgroup (or use google) to find a thread titled "'Intellisense' > possible for Python?" started (by me) on Dec 18, 2002. It discusses why > this isn't really possible with Python (short version: dynamic typing > doesn't allow them to do this). Generally, the interactive > interepreter windows support this better than the editors. Pat O'Brien > did some work on improving this in the PyAlaCarte series of editors, but > I've not been able to get it working completely, and he seems to not be > doing any additional work on it at this time. As someone who also came > from VB, support for intellisense-type capabilities would be the largest > practical improvement that could be made to ease-of-use & adoption of > Python. I think that it's hard for those folks who haven't benefited > from it to understand how nice it really is. Good luck, > > -- > Greg > > "Emmanuel Jean-Louis" wrote in message > news:mailman.1060692918.5794.python-list at python.org... > > Does python 2.2 has a drop down feature like VB does so that you can > list of methods and variables associate with that particular class? If > it does, how do I turn it on? > > Thx. > From adalke at mindspring.com Mon Aug 18 21:11:41 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Mon, 18 Aug 2003 19:11:41 -0600 Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> Message-ID: Alexander Schmolck: > No it isn't. Like every other language I know python sucks in a variety of > ways (only on the whole, much less so), but I don't claim I know how to fix > this with a macro system. What about the other way around? Make a macro for Lisp or Scheme which converts Python into the language then evals the result? Given how easy it is to parse Python (there are several Python parsers for Python) and the number of people who have popped up with Lisp background, I'm surprised no one has done that for fun. After all, there is Python for C, Java, .Net, and for Python (PyPy) and variations like Pyrex and Vyper. But none for Lisp? (I think I remember mention of one some years ago, .. I think *I* posted that link to c.l.py, but I don't remember when and can't find it via Google.) > But show me how to write something like CL's series package that way (or > better yet, something similar for transforming array and matrix manipulations > from some reader-friendly representation into something efficient). The Boost code for C++ suggests a different way to do the latter. (I don't think templates are the same as hygenic macros.) Andrew dalke at dalkescientific.com From matthew.rapoport at accenture.com Tue Aug 19 11:48:15 2003 From: matthew.rapoport at accenture.com (Matt Rapoport) Date: 19 Aug 2003 08:48:15 -0700 Subject: wxPython launches DOS shell Message-ID: <4150f6c8.0308190748.7633e5c9@posting.google.com> Does anyone know how to avoid getting a DOS shell launched everytime you run a wxPython script? The shell is used to run Python.exe but it doesn't look very professional when a black window pops up along with your GUI. Thanks, Matt From simonb at webone.com.au Sat Aug 23 20:14:07 2003 From: simonb at webone.com.au (Simon Burton) Date: Sun, 24 Aug 2003 10:14:07 +1000 Subject: Python is darn fast (was: How fast is Python) References: <2259b0e2.0308230737.8a9bc1c@posting.google.com> <3F47AA73.7040104@draigBrady.com> <3f47bbc3$0$49114$e4fe514c@news.xs4all.nl> <87wud4x870.fsf@pobox.com> Message-ID: On Sun, 24 Aug 2003 00:31:15 +0100, John J. Lee wrote: > Irmen de Jong writes: > >> P at draigBrady.com wrote: >> ... >> but Python+Psyco still wins :-) > > So, the interesting part is: why? > > > John My suspicion is that when psyco looks at erfc, it finds that nothing changes and so replaces the function call with the resulting number (am i right? it's the same each time?). This is what a "specializing compiler" would do, me thinks. So, try using a different number with each call. Simon. From vanevery at 3DProgrammer.com Mon Aug 11 02:51:22 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Sun, 10 Aug 2003 23:51:22 -0700 Subject: Slogan: Getting Rich Overnight References: Message-ID: <3f373ac6@shknews01> Christian Tismer wrote: > Ben Finney wrote: >> >> Anything with "get rich {quick,fast,overnight}" already has far too >> many negative connotations to sound un-lame. > > Right. But is this my fault? Yes, it's your fault. The language already exists, and you know it's out there, so you are guilty of picking the extant lame words. Are you guilty of inventing the lame words? No, of course not. But if you say "fuck you" to someone, does it matter who invented it? > Fine. And you let spammers dictate to you what they want > you to think? Dude, "get rich overnight" was lame way before spammers. Face it, your slogan only sounds good to the choir. Someone like me, who isn't converted on Python yet, rightfully asks "How stupid do you think I am?" > I do think this is going way too far. > We have already allowed them to get too far. > Did I say anything bad? Nothing at all, this was said by > other people. And those are dictating to us, what to say > and what not to say. > SHould we really continue to support this? Get over it. Go back to the drawing board, design another slogan. You test marketed your slogan, it failed. That's life. It doesn't take that much time and energy to come up with other slogans. Heck, given enough iterations, maybe you'll find a new career in marketing. Marketing is actually pretty important to the success of software, so you could even stick to high tech marketing. > I hereby simply propose to prohibit SPAM. Really, really > prohibiting it, with all legal consequences. We couldn't even get the UN to prohibit WMDs in a timely, accountable fashion. 12 years of Saddam's stonewalling, followed by a French suggestion that we should do 12..18 months more of it, despite the obvious implacability of the dictator. Suggest you look to illegal consequences, because legal ones can't do anything. The problem with illegal consequences in anti-SPAM arenas is the tend to only do collateral damage, not hit the perps. > I do want to be able to say that I got rich overnight, by using Python. Generally speaking, that's a Testimonial. > When *we* are unable to accept such a statement, because > *some* people are claiming this to be *their* spamming > vocabulary, whose fault is this, then? Yours. You are way too idealistic, worrying about langauge ownership issues that are completely beyond your control. Your idealism is your own fault. Pragmatists simply observe "this won't work" and move on with something that will. > Shame on me as well, since I installed a SPAM filter, > instead of starting a real fight which they can't win. Your idealism also inhibits your ability to make a realistic analysis on this point. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From blended_reality at yahoo.com Sun Aug 17 00:24:38 2003 From: blended_reality at yahoo.com (Aaron Griffith) Date: 16 Aug 2003 21:24:38 -0700 Subject: Pausing a Process in Windows Message-ID: <49de2314.0308162024.6529bf1@posting.google.com> Hi. I'm semi-new to python and was wondering if you could help me out. I'm trying to design a program that will start rendering an image with a raytracer. I want to be able to pause the raytracing, exit the program that started the raytracer, and restart the program, using the same paused process as before. I figured I'd save th PID in a file, but I don't know how to pause a process in windows. Thanks in advance! From bokr at oz.net Fri Aug 15 22:33:21 2003 From: bokr at oz.net (Bengt Richter) Date: 16 Aug 2003 02:33:21 GMT Subject: Replace every n instances of a string References: <62de87da.0308151325.41ea4622@posting.google.com> Message-ID: On 15 Aug 2003 14:25:57 -0700, thomasacross at hotmail.com (Tom Cross) wrote: >Hello- > >I have a function that returns to me a text representation of Unicode >data, which looks like this: > >\u0013\u0021\u003c\u003f\u0044\u001f\u006a\u005a\u0050\u0015\u0018\u001d\u007e\u006b\u004e\u007d\u006a\u006e\u0068\u0042\u0026\u003c\u004f\u0059\u0056\u002b\u001a\u0077\u0065\u006a\u000a\u0021\u005f\u0025\u003f\u0025\u0024\u007e\u0020\u0011\u0060\u002c\u0037\u0067\u007a\u0074\u0074\u0003\u0003\u000f\u0039\u0018\u0059\u0038\u0029\u0001\u0073\u0034\u0009\u0069\u005e\u0003\u006e\u000d\u004c\u001d\u00 >f\u006e\u001b\u006e\u0063\u000b\u0014\u0071\u007c\u004e\u006a\u0011\u004a\u001f\u0063\u0016\u003d\u0020\u0065\u003e\u0043\u0012\u0047\u0026\u0062\u0004\u0025\u003b\u0005\u004c\u002e\u005a\u0070\u0048 > >I would like to add carriage returns to this for usability. But I >don't want to add a return after each "\u" I encounter in the text >(regexp comes to mind if I did). I want to add a return after each 12 >"\\u"s I encounter in the string. > >Any ideas? Do I not want to search for "\\u" but instead just insert >a \n after each 72 characters (equivalent to 12 \uXXXX codes)? Would >this provide better performance? If so, what would be the easiest way >to do that? > >Thanks much! If you are sure of the uniform format, you might try (testes as far as you see here ;-): >>> def breakatn(s, n=72): return '\n'.join([s[i:i+n] for i in xrange(0,len(s),n)]+['']) ... >>> print breakatn('0123456789'*20, 72) 012345678901234567890123456789012345678901234567890123456789012345678901 234567890123456789012345678901234567890123456789012345678901234567890123 45678901234567890123456789012345678901234567890123456789 >>> print breakatn('0123456789'*6, 25) 0123456789012345678901234 5678901234567890123456789 0123456789 The [''] is to get a last item for join to put a \n between it and what precedes. Regards, Bengt Richter From florian.proff.schulze at gmx.net Sun Aug 24 17:10:25 2003 From: florian.proff.schulze at gmx.net (Florian Schulze) Date: Sun, 24 Aug 2003 23:10:25 +0200 Subject: Python 2.3 problem References: <51092f25c1b12d2bedc9c63d2dfa14f3@dizum.com> Message-ID: There is way to few information in this mail, but I guess you meant the following: def pinhtranh(*args, laoc_te): phnoi_crek(*args, laoc_te) Note the *args on the second line. Regards, Florian On Sun, 24 Aug 2003 22:00:01 +0200 (CEST), Nomen Nescio wrote: > Hi > > When I does this like hear failre goes: > > def pinhtranh(*args, laoc_te): > phnoi_crek(args, laoc_te) > > I do "laoc_te" last praemetr name always. > > > Qinh > > > -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/ From jdhunter at ace.bsd.uchicago.edu Tue Aug 26 22:37:46 2003 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Tue, 26 Aug 2003 21:37:46 -0500 Subject: ezPyCrypto keys Message-ID: I have been playing around with ezPyCrypto. I generated and printed a key with >>> import ezPyCrypto >>> k = ezPyCrypto.key(2048) >>> print k.exportKey() I noticed there were a lot of N's and M's, too many to occur by chance s=k.exportKeyPrivate() >>> s.count('N')/float(len(s)) 0.09788189987163029 >>> s.count('M')/float(len(s)) 0.11 I quit python and restarted it and generated a new key and found the same thing. Ditto when I exported the private key. I also found the keys generated in the two sessions to be quite similar (35% characters at a given position identical). What's going on? Is it abnormal for so many of the characters in the exported string to be the same? The machine I am running on is a server that rarely has anyone logged in directly. Is this a problem with not enough randomness in /dev/random? Thanks for any suggestions, John Hunter ezPyCrypto-0.1.1 pycrypto-1.9a6 python2.2 mother:/var/tmp/ezPyCrypto-0.1.1> uname -a Linux mother.paradise.lost 2.4.9 #7 Fri Oct 12 15:20:49 CDT 2001 i686 unknown From pinard at iro.umontreal.ca Wed Aug 20 09:26:55 2003 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois_Pinard?=) Date: 20 Aug 2003 09:26:55 -0400 Subject: List and net abuses [was: Re: Trolling levels] In-Reply-To: <7h33cfw64pf.fsf@pc150.maths.bris.ac.uk> References: <7h33cfw64pf.fsf@pc150.maths.bris.ac.uk> Message-ID: [Michael Hudson] > Without wanting to sound overly pissy, can I just point out that I don't > want to read threads about "Ruby vs Python" and the trolls therein (which > I already don't, thanks to a nicely sharpened score file) but I also don't > want to read people *talking about* silly threads and the trolls therein, > which due to rampant subject changing keep reappearing in my news reader. > Enough already! Exactly the same feelings here. Despite not much, it takes a bit more time every week for tuning up score files so un-interesting messages get filtered out. The noise ratio on `python-list' is progressively climbing, there is danger that we loose some of the pleasure of reading it in the long run. > And now if we can just shoot those responsible for sending out viruses > with "From python-list at python.org", maybe I wont be killing 70% of the > posts in the group... This might not be easy. One of my (mostly unpublished) domain name and my own addresses are being abused from far away sites for widely broadcasted UCE, either with `From' or some fake initial `Received:'. Seeing my own name abused has been rampant for years (and it happened to many maintainer-friends as well, probably because we were known as good guys), but for relatively recently, such abuse is becoming extremely aggressive and pretty difficult to counter-fight. My filters have to cope with hundreds of rejects every hour for the mere abuse of my own name. And for the abuse of my domain (forgeries seemingly emanating from random non-existing users from that domain), the generated rejects have been the source, on the domain MX, of several hundreds of SMTP connection attempts, sustained at all times, night and day, for many months. (Other people take care of our network bills, I should evaluate the impact.) Yet, as this is all originated elsewhere, this is a bit outside our control. And I'm nobody. I barely imagine what `python-list' might be living, for those having to administer lists and servers. It might be frightening! Happily some Python project, for any counter-measure system that might demonstrate some efficiency against this! But it might be difficult... -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From naren at trillium.com Thu Aug 28 20:04:04 2003 From: naren at trillium.com (Narendra C. Tulpule) Date: 28 Aug 2003 17:04:04 -0700 Subject: Are lists at least as efficient as dictionaries? Message-ID: <781faf41.0308281604.51e48f45@posting.google.com> Hi, if you know the Python internals, here is a newbie question for you. If I have a list with 100 elements, each element being a long string, is it more efficient to maintain it as a dictionary (with a key = a string from the list and value = None) for the purpose of insertion and removal? Basically, if Python really implements lists as linked lists but dictionaries as hash tables, it may well be that hashing a key takes negligible time as compared to comparing it against every list element. Oh and here is (as a non-sequiter) something I don't understand either: >>> x = ([],) >>> x[0] += ['something'] Traceback (most recent call last): File "", line 1, in ? TypeError: object doesn't support item assignment >>> x (['something'],) <---- complained but did it anyway?? >>> x[0].append('and another thing') <------- no complaint! >>> x (['something', 'and another thing'],) From raims at dot.com Wed Aug 27 10:02:51 2003 From: raims at dot.com (Lawrence Oluyede) Date: Wed, 27 Aug 2003 16:02:51 +0200 Subject: problem installing PyQt for eric3 References: <87oeyb4iv7.fsf@voodoo.fake> Message-ID: <877k4zryes.fsf@voodoo.fake> Lupe writes: > how could I install support for OpenGL in QT? You need xlibmesa glu package i think -- Lawrence "Rhymes" Oluyede http://loluyede.blogspot.com rhymes at NOSPAMmyself.com From timr at probo.com Wed Aug 27 23:07:20 2003 From: timr at probo.com (Tim Roberts) Date: Wed, 27 Aug 2003 20:07:20 -0700 Subject: Bug with win32 open and utf-16 file References: <27vekvc6evvn3m5jg8n1en2u42skat42qn@4ax.com> <2i1gkv0s7762vcs85rkdq6uvgk6oitje12@4ax.com> <78egkvg1tu0j1kvedclcefn01hr3vkqh4v@4ax.com> Message-ID: <0csqkvgli56h04jthltpd7dbqv5am52sb0@4ax.com> Tim Roberts wrote: >derek / nul wrote: >> >>>>>> data = file("c:/dash9.eng", "rb").read() >>>>>> data[-10:] >>>'\r\x00\n\x00)\x00\r\x00\n\x00' >> >>Interesting, I have just done the same and it would appear that the hexdump >>routine is changing 0d to 0a ??? > >I cut-and-pasted your version of hexdump onto my machine, fetched your >dash9.eng file, and ran this: > > from hexdump import hexdump > f = open('dash9.eng','rb').read() > print hexdump(f) > >The output seems to be exactly correct: For those who have been following this thread, Derek and I had a private e-mail exchange about this. When I asked to send me the exact files he was using, he discovered with some embarrassment that HIS version of his dash9.eng had been modified during testing, and actually DID contain 0a 00 0a 00 0a 00 0a 00. Problem solved. -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From tundra at tundraware.com Wed Aug 6 23:30:07 2003 From: tundra at tundraware.com (Tim Daneliuk) Date: 07 Aug 2003 03:30:07 GMT Subject: Win32All Crashes Python 2.3? In-Reply-To: References: Message-ID: Tim Daneliuk wrote: > For those running 'twander' who wish to upgrade to Python 2.3 as > released, please contact me privately via email for a workaround... I have posted the workaround (a patch for twander itself) which will allow it to work with Python 2.3 as released, on the twander web page: http://www.tundraware.com/Software/twander -- ---------------------------------------------------------------------------- Tim Daneliuk tundra at tundraware.com PGP Key: http://www.tundraware.com/PGP/ From andymac at bullseye.apana.org.au Thu Aug 7 09:06:01 2003 From: andymac at bullseye.apana.org.au (Andrew MacIntyre) Date: Thu, 7 Aug 2003 23:06:01 +1000 (EST) Subject: win32, COM, and Solidworks (again) - Still Trying In-Reply-To: References: Message-ID: <20030807230104.Y15338@bullseye.apana.org.au> On Wed, 6 Aug 2003, Markus Wankus wrote: > For my objects, dispatch.GetTypeInfo() causes the following exception: > > Traceback (most recent call last): > File "F:\_DEV\solidworks\swpycom.py", line 12, in ? > print sw._oleobj_.GetTypeInfo() > pywintypes.com_error: (-2147467263, 'Not implemented', None, None) If you need to go beyond the IDispatch interface, Thomas Heller's ctypes package looks to be your only option, short of creating a full-blown Pythonwin wrapper (ala Pythonwin's MAPI support) for the SolidWorks COM API. Regards, Andrew. -- Andrew I MacIntyre "These thoughts are mine alone..." E-mail: andymac at bullseye.apana.org.au (pref) | Snail: PO Box 370 andymac at pcug.org.au (alt) | Belconnen ACT 2616 Web: http://www.andymac.org/ | Australia From achrist at easystreet.com Sun Aug 3 16:53:00 2003 From: achrist at easystreet.com (achrist at easystreet.com) Date: Sun, 03 Aug 2003 13:53:00 -0700 Subject: PyChecker work with Python 2.3? References: <3F2C5300.FA223CBA@easystreet.com> <3F2CBCC2.3FC51D57@easystreet.com> <3F2D3EF5.DAF09C1C@easystreet.com> Message-ID: <3F2D762C.1B5A0143@easystreet.com> Skip Montanaro wrote: > > >> If you think you are so smart, why don't you use your time more > >> economically then and just try it out? > > al> If I upgrade python to 2.3 I also must upgrade: > > al> ctypes > al> py2exe > al> pysqlite > al> win32all > al> wxPython > > Just to see if pychecker works? Just to see if pychecker works for the software for which it matters to me if pychecker works. > Why not just configure Python with a > different --prefix=... flag? That's assuming you're on a unix-like > system. I'm not. > If you're on Windows (as it appears you are), Python 2.3 installs in > c:\Python23 by default which shouldn't disturb your earlier Python > installation unless you were tanked the day you installed it and put > it in > c:\Python23. > If I'm on a Windows system, and I am, I am very suspicious of any claims that it is possible to install and uninstall anything easily and come out exactly where I was before. About a month ago I noticed that my jaz drive was working not too well, so I upgraded Iomega's tools. That broke NT, it wouldn't uninstall, and I spent 3.5 days trying to fix NT. (This was actually within a week after NT had been dropped from Microsoft's supported list, and all the MS knowledgebase articles about NT and NT workstation service packs and patches had been purged from the MS website). If you work with Windows much, you learn the downside of promiscuous installing. There's always a risk. Better to ask twice and install once. Al From bokr at oz.net Mon Aug 18 17:21:11 2003 From: bokr at oz.net (Bengt Richter) Date: 18 Aug 2003 21:21:11 GMT Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> Message-ID: On Mon, 18 Aug 2003 17:26:30 +0200, Alex Martelli wrote: [...] > >One syntax difference that I do find important, and in Python's >favour -- but other people will no doubt think just the reverse -- >is "how do you call a function which takes no parameters". In >Python (like in C), to call a function you always apply the >"call operator" -- trailing parentheses just after the object >you're calling (inside those trailing parentheses go the args >you're passing in the call -- if you're passing no args, then >the parentheses are empty). This leaves the mere mention of >any object, with no operator involved, as meaning just a >reference to the object -- in any context, without special >cases, exceptions, ad-hoc rules, and the like. In Ruby (like >in Pascal), to call a function WITH arguments you pass the >args (normally in parentheses, though that is not invariably >the case) -- BUT if the function takes no args then simply >mentioning the function implicitly calls it. This may meet >the expectations of many people (at least, no doubt, those >whose only previous experience of programming was with Pascal, >or other languages with similar "implcit calling", such as >Visual Basic) -- but to me, it means the mere mention of an >object may EITHER mean a reference to the object, OR a call >to the object, depending on the object's type -- and in those >cases where I can't get a reference to the object by merely >mentioning it I will need to use explicit "give me a reference >to this, DON'T call it!" operators that aren't needed otherwise. >I feel this impacts the "first-classness" of functions (or >methods, or other callable objects) and the possibility of >interchanging objects smoothly. Therefore, to me, this specific >syntax difference is a serious black mark against Ruby -- but >I do understand why others would thing otherwise, even though >I could hardly disagree more vehemently with them:-). > This is interesting, because I presume you are happy with properties ;-) So is this basically a thing about the global namespace? I.e., if we had way to introduce a subclassed module types into the import mechanism, we could have module properties, which presumbaly could be accessed much like parameterless Pascal functions. Regards, Bengt Richter From max at alcyone.com Wed Aug 20 13:40:09 2003 From: max at alcyone.com (Erik Max Francis) Date: Wed, 20 Aug 2003 10:40:09 -0700 Subject: Newbie Variable Substitution Question References: Message-ID: <3F43B279.89C06403@alcyone.com> ckrieg at shaw.ca wrote: > for c in range(1, 3): > print "%(c)s %(1)s" % (locals(), dict01) > > Results in an error: TypeError: format requires a mapping > > Why doesn't the second loop work? It seems to be a cleaner way of > doing this. Am I missing something? Because when used this way, the string formatting operator % requires one argument on the left, which is a mapping type. You're passing it two. Consider what would happen if both dictionaries had the same key; which should be used? Presuming you wanted them to be checked in order, try: d = dict01.copy() d.update(locals()) print ... % d -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ I'm the woman whose / Three wishes came true \__/ Lamya From aleax at aleax.it Thu Aug 7 18:11:39 2003 From: aleax at aleax.it (Alex Martelli) Date: Thu, 07 Aug 2003 22:11:39 GMT Subject: Gmpy References: <8578e2c1.0308070630.5fb70c22@posting.google.com> Message-ID: Carl Banks wrote: > Jean-Pierre Andreaux wrote: >> Gmpy module was a wrapper of the GNU MP library. It seems that no >> evolution is done on this module since 2001. Indeed, Gmpy is not >> supported in Python 2.2 nor 2.3. >> >> My question is the following: what is the better replacement solution >> for manipulating long numbers. I want to do long numbers >> exponentiations. Thanks in advance for your answers. > > > An alternative is egenix mxNumber package, still in beta stage. > > http://www.egenix.com/files/python/mxNumber.html > > I couldn't use gmpy because I needed floating point, and mxNumber also > wraps the floating point functionality. It seemed to work ok. gmpy also wraps the floating-point functionality of GMP: >>> print gmpy.mpf(7,99)/3 2.333333333333333333333333333333333333333 Alex From aleax at aleax.it Wed Aug 20 17:15:16 2003 From: aleax at aleax.it (Alex Martelli) Date: Wed, 20 Aug 2003 21:15:16 GMT Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> <6dj2kv8ugkieehs7guh786cl40o5lj6mcs@4ax.com> Message-ID: Doug Tolton wrote: ... > Linux is based on this concept of allowing people to extend the > system, it doesn't seem to have suffered from it. Linus Thorvalds sits at the center and rejects a LOT of proposed modifications to the kernel -- everybody's free to distribute such patches separately, but they're NOT part of Linux. You can do exactly the same with Python: send patches to Guido, have him reject them, distribute them separately with no claim they're part of Python (e.g., Stackless is in exactly this situation). Powerful macros in Python would *BYPASS* the crucial filtering role of the chief architect -- Linus or Guido in these cases. And here's where the "attractive nuisance" side of powerful macros, the allure that would make oodles of youngsters flock to them, amplifies their danger: as it's much easier -- and satisfying to many -- to "play the amateur language designer" by coding macros, rather than (e.g.) to write device drivers for Linux, the flood would quite likely be huge. > Same argument as above, I don't agree with this logic. Python is a > great language, that doesn't mean it couldn't be better though. If > that were the case development would be cease. But WHO will make it better: Guido, whose skill as a language designer is proven, or a hundred authors of sets of macros? It is just too easy to "play language designer" -- far more people will do it than are actually GOOD at language design. > Why do we allow people to write functions even, I mean you have to Because "once and only once" is the mantra of programming: in a language that lacks user-written functions or procedures, application programmers have to copy-and-paste code, a horrid way to program. > learn the syntax for calling them, what the variables are and what > they do. Bah, we should make everyone use only built in functions, if > they want a different one, use a different language. What? It makes > no sense to me. It doesn't, because the number of different SYNTAX FORMS needed for powerful expression is incredibly tiny (so that even Python, which is a small language, can easily afford redundance there!) while the number of different COMPUTATIONS (functions and procedures) needed for even a small application exceeds the numbers that can be reasonably provided as built-ins. In other words, it makes no sense because you are comparing, not even apples and oranges, but rather cantaloupes and termites -- completely different things. > So don't allow people to customize the system huh? They why is Python > Open Source? That's the *entire* point of Open Source, so that people > can tweak and customize to their own environment. Do you have any People can "tweak and customize" "their own environment" in Windows, too (ever seen TweakUI and friends?!), so if your point was well taken open-source would not exist. Since it does, it proves your point is deeply mistaken. > Designing a good language is all about designing the right high level > abstractions. Even a medium skilled designer should be able to design > a language that maps better to their specific domain than a general I entirely, utterly, totally and completely disagree with this point. This is like saying that even a medium skilled musician should be able to write music that plays better to their specific audience than great music written by a genius who's never personally met any of the people in the audience: it's just completely false. I want to use a language designed by a genius, and I want to listen to music written by Bach, Haendel, Mozart, and the like. Moreover, judging by the way BY FAR most languages around are in fact designed, it's abundantly clear that "medium skilled language designers" are a VERY scarce breed indeed. And yet with powerful macros everybody and their cousin WILL play the amateur language designer. No thanks. If you want Dylan, Common Lisp, or Scheme, you know where to find them. Please leave *ONE* language alone, with the integrity and conceptual beauty AND usefulness that can only come from having *ONE* designer -- a genius-level one -- firmly at the helm. > abuse something. That paradigm is filled, there are many languages > that restrict programmers because they might misuse a feature, or they > are just too dumb to get it right. I say fine, leave the languages > like Java / C# / VB to those people, but let's make Python a language > that allows people the room to do it the way it needs to be done, not > so much the way Guido or whoever thinks it should be done. Let's leave Python as *ONE* language, WITHIN which everything does work as you say -- not a *MYRIAD* subtly incompatible languages, each partly designed by a different guys, mostly mediocre at language design. Just as many languages are overly restrictive, so many others are overly permissive (see the above mentioned examples) thanks to powerful macro systems. PLEASE leave Python alone at the SWEET SPOT, at JUST THE RIGHT COMPROMISE -- neither too permissive nor too restrictive. GvR's genius (and/or luck) made it that way; don't branch the language into a zillion mediocre ones. Alex From lists at webcrunchers.com Thu Aug 7 01:55:46 2003 From: lists at webcrunchers.com (John D.) Date: Wed, 6 Aug 2003 22:55:46 -0700 Subject: Database question..... Message-ID: I have a small (fewer than a few thousand records) database with the following properties: Each record has four fields: A, B, C, D. Fields A and B are unique: there is one B for every A and one A for every B. Fields C and D are not unique. Sometimes I need to use A as the key, other times B is the key: I use A to return B, C, D and also B to return A, C, D. The items may all be represented as short ASCII strings. Currently I am storing this in a 100KB file and converting this to two dictionaries. I am reading and writing the entire file to update single records, which is inefficient. I am thinking about using anydbm, but then how do I do the two-way dictionary lookup? Would I have to store the whole database twice? What if I had ten items, would I have to store it ten times? Is this what a relational database allows? John From gh at ghaering.de Wed Aug 27 11:38:39 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Wed, 27 Aug 2003 17:38:39 +0200 Subject: My future Python IDE article In-Reply-To: References: Message-ID: <3F4CD07F.7040806@ghaering.de> Alan James Salmoni wrote: > Personally, I would include: > > 1) SciTE [...] > 2) Leo [...] Neither one is an IDE (they lack a debugger). They're only editors. -- Gerhard From vanevery at 3DProgrammer.com Mon Aug 11 17:49:23 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Mon, 11 Aug 2003 14:49:23 -0700 Subject: Slogan: Getting Rich Overnight References: Message-ID: Graham Fawcett wrote: > > "Python: stimulate powerful organisms under your fingertips, without > all the GUI mess!" "Organisms" is easily misread as "orgasms." -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From anthonyr-at-hotmail-dot-com at nospam.com Wed Aug 27 18:45:08 2003 From: anthonyr-at-hotmail-dot-com at nospam.com (Anthony Roberts) Date: Wed, 27 Aug 2003 22:45:08 GMT Subject: Style question... Message-ID: If I end indentation levels with "pass" statements, will I piss off people that have to read my code? eg: for i in xrange(0,5): if i: print i pass print i * -1 pass I ask for two reasons... a) it helps emacs figure it out, and b) I'm more comfortable ending compound statements with a token. From R.Brodie at rl.ac.uk Tue Aug 5 04:47:47 2003 From: R.Brodie at rl.ac.uk (Richard Brodie) Date: Tue, 5 Aug 2003 09:47:47 +0100 Subject: (VERY) New to Python. Need Help! References: Message-ID: "Don Bruder" wrote in message news:tqJXa.8564$dk4.364945 at typhoon.sonic.net... > Looks pretty obvious that something it wants can't be found. Yes, It can't find the getpid function within the os module. It isn't available on the Mac (at least not classic Mac). Reading http://www.dessent.net/btfaq/ may help. From sross at connectmail.carleton.ca Mon Aug 25 21:09:15 2003 From: sross at connectmail.carleton.ca (Sean Ross) Date: Mon, 25 Aug 2003 21:09:15 -0400 Subject: Advice to a Junior in High School? References: Message-ID: "Howard Nease" wrote in message news:Ivw2b.1305$Ce2.314 at clmboh1-nws5.columbus.rr.com... > What should I study in college? Hi. Are you asking which areas in the field of computer science you should try to specialize in (take courses in)? Are you asking which comp. sci. (or non-comp.sci. courses) would be beneficial (for getting work, for rounding your knowledge, for making you happy, for all of the above and more)? What you should study in college may well depend on your chosen college's degree requirements. My university, for instance, requires us to take atleast 8 classes outside of our discipline (I chose to do a minor in philosophy, in order to meet that requirement). It's hard to say what you should study. What are your goals? What would you like to learn? What would you like to do? Do you want to be a computer scientist? a programmer? a software engineer? a network administrator? a security professional? a web-application developer, or something else? Depending upon what you want to do, what you should learn may differ. For the time being, you're still in high school, so let's start there. Take all of the math and science courses you can. Finite (discrete) mathematics, if it is offered, is particularly useful. If your school offers any kind of logic course, take that. If you're looking to be in management, business courses might be useful. Take literature courses (you'll have to write papers as you move further towards being a computer scientist, best get some practice writing now). But, most importantly, take what interests you! In university (or college), you can follow advice similar to that above. Especially, "take what interests you". Take any required maths, and, if you like, take any other discrete math courses. As for computer science courses: You'll likely have a core curriculum to follow for the first 2-3 years, so you may not have a lot of choice in which courses to take. In 3rd and 4th year you'll likely get to specialize more. If your school offers a compiler course, take it. Most of what you learn there is applicable in other domains. If your school offers an interface design course, take that. If your school offers software design courses, take those. Other than this, it's difficult to suggest courses. It depends on your interests and the courses that are offered. Are you interested in AI, A-Life, evolutionary computing? Are you interested in cryptography, security, networking? Are you interested in distributed or parellel computing? Again, "take what interests you". > What languages do you suggest that I study (I'm already studying Python)? Learn C (atleast, and maybe C++). Learn an assembly language. Learn Scheme (Lisp, Dylan, Haskell, ocaml, or some other functional programming language). Learn Prolog (or some other logic programming language). Learn Java. Learn Perl. Learn what interests you. I hope that was somewhat helpful, Sean From glingl at aon.at Sat Aug 16 14:58:59 2003 From: glingl at aon.at (Gregor Lingl) Date: Sat, 16 Aug 2003 20:58:59 +0200 Subject: Py2.3: Feedback on Sets (fwd) In-Reply-To: References: Message-ID: <3f3e7f4e$0$18754$91cee783@newsreader02.highway.telekom.at> David Mertz schrieb: >>* Is there a compelling need for additional set methods like >> Set.powerset() and Set.isdisjoint(s) or are the current >> offerings sufficient? > > > I confess that I have not used sets for anything beyond testing. I love > the concept, but I just haven't had the need yet (especially in > something where I want to require 2.3). > > The mention of Set.powerset() above is quite interesting to me. It > feels both exciting and dangerous :-). I think it would be more general and versatile to provide a method for the Cantorproduct of two sets, set1.cantorproduct(set2), which could be used to define Set.powerset. Additionally implementing this as __mul__ and __pow__ methods, so you could write set1*set2 and set**n would be funny. Regards, Gregor > > As we all know, the size of the powerset of S, for len(S)==N, is 2**N. > Seems like it would be really easy to run into some long runtimes and > memory usage. Then again, power set really is a fundamental operation > on sets. And making users rewrite it each time is error prone. > > So I think I would advocate it, but with a fairly harsh warning in the > documentation about complexity issues. > > Yours, David... > > -- > mertz@ | The specter of free information is haunting the `Net! All the > gnosis | powers of IP- and crypto-tyranny have entered into an unholy > .cx | alliance...ideas have nothing to lose but their chains. Unite > | against "intellectual property" and anti-privacy regimes! > ------------------------------------------------------------------------- > X-Shameless-Plug: Buy Text Processing in Python: http://tinyurl.com/jskh > > From ayc8NOSPAM at cornell.edu Sat Aug 2 19:34:20 2003 From: ayc8NOSPAM at cornell.edu (Andy C) Date: Sat, 02 Aug 2003 23:34:20 GMT Subject: How do I get a reference to a KEY value of a dictionary? References: <645db655.0307311636.71923378@posting.google.com> Message-ID: <0UXWa.416$_57.26378288@newssvr21.news.prodigy.com> > Google("intern-like memory saver"). Well, that seems very sensical, so how come it hasn't made it into the language? And what's wrong with intern? (Though intern only works on strings, not for immutable objects in general. I believe someone was asking a pretty much identical question here, and someone replied with the 'memoize' pattern). Can this be done without C, now that you can subclass the built-in dictionary? Andy From uche at ogbuji.net Fri Aug 22 11:55:51 2003 From: uche at ogbuji.net (Uche Ogbuji) Date: 22 Aug 2003 08:55:51 -0700 Subject: resolving relative paths for external entities with xml.sax References: Message-ID: Bart wrote in message news:... > On Fri, 15 Aug 2003 06:24:02 -0700, Uche Ogbuji wrote: > > >> From what I understand of XML specs, relative paths in external entities > >> are relative to the location of the document *in which they are defined*. > >> However, using xml.sax (which calls expat, I presume), the paths are > >> resolved relative to the current working directory. So the parser can not > >> find the test.inc when the current working directory is e.g. dir1. > > > > I, for one, need to see your Python code to tell, because if you're > > using the APIs rightly parsing the first file as a URI rather than, > > say, reading it in as a string first), then you should not have the > > problem you report. > > something like: > from xml.sax import make_parser > from xml.sax.saxutils import XMLGenerator > reader = make_parser() > reader.setContentHandler(XMLGenerator()) > reader.parse('test.xml') > > this is run in the test1 dir. > > I also tried using absolute paths, xml.sax.InputSource, 'file:' URLs and > combinations of these. > > The result is either: > OSError: [Errno 2] No such file or directory: 'test.inc' > or (when using 'file://tmp/xmltest/test1/test.xml'): > OSError: [Errno 2] No such file or directory: '/tmp/xmltest/test1/test.inc' > or (when using 'file:test.xml'): > OSError: [Errno 2] No such file or directory: '/test.inc' I'm not sure what's up. This works for me (on PyXML 0.8.3): [uogbuji at borgia uogbuji]$ cat test.py #!/usr/bin/env python from xml.sax import make_parser from xml.sax.saxutils import XMLGenerator reader = make_parser() reader.setContentHandler(XMLGenerator()) reader.parse('dummy.xml') [uogbuji at borgia uogbuji]$ python test.py --Uche http://uche.ogbuji.net From tebeka at cs.bgu.ac.il Sun Aug 3 06:11:34 2003 From: tebeka at cs.bgu.ac.il (Miki Tebeka) Date: 3 Aug 2003 03:11:34 -0700 Subject: wxPython: Default Frame button? Message-ID: <33803989.0308030211.10b31e97@posting.google.com> Hello All, I have a frame that contains a panel and several buttons. I'd like to make one of the button the default button but self.SetDefaultItem(btn) or btn.SetFocus() don't work. The item in focus is a text control inside the panel. Any Ideas? (see short example below) Thanks. Miki --- btn.py --- import wx class P(wx.Panel): def __init__(self, parent, id=-1): wx.Panel.__init__(self, parent, id) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(wx.TextCtrl(self, -1, size=(250, -1), value="XXX")) self.SetAutoLayout(True) self.SetSizer(sizer) sizer.Fit(self) class F(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, -1, "Test Frame") sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(P(self), 0, wx.EXPAND) b = wx.Button(self, wx.NewId(), "Quit") wx.EVT_BUTTON(self, b.GetId(), self.on_quit) sizer.Add(b, 0, wx.EXPAND) self.SetDefaultItem(b) b.SetFocus() self.SetAutoLayout(True) self.SetSizer(sizer) sizer.Fit(self) def on_quit(self, e): self.Close(True) def main(): app = wx.PySimpleApp() f = F() f.Show(True) app.MainLoop() if __name__ == "__main__": main() --- btn.py --- From afriere at yahoo.co.uk Tue Aug 26 22:56:22 2003 From: afriere at yahoo.co.uk (Asun Friere) Date: 26 Aug 2003 19:56:22 -0700 Subject: Celebrity advice (was: Advice to a Junior in High School?) References: Message-ID: <38ec68a6.0308261856.3c5f85d@posting.google.com> "Tim Churches" wrote in message news:... > Except when it comes to guns You should know better than getting into a discussion with Americans about guns. From adalke at mindspring.com Sun Aug 24 00:14:45 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Sun, 24 Aug 2003 04:14:45 GMT Subject: email bug? References: Message-ID: Stuart D. Gathman: > Content-Type: image/pjpeg; name="Jim&&Jill" > What IE apparently gets is: > > [('image/pjpeg', ''), ('name', '"Jim&&Jill"')] > > Is this a bug (in the email package, I mean - obviously IE is buggy)? > > Do I have to write my own custom param parsing routines to handle this? BTW, I verified this in 2.3. Looks like the Content-Type syntax is defined in http://www.faqs.org/rfcs/rfc2045.html 5.1. Syntax of the Content-Type Header Field content := "Content-Type" ":" type "/" subtype *(";" parameter) parameter := attribute "=" value value := token / quoted-string token := 1* tspecials := "(" / ")" / "<" / ">" / "@" / "," / ";" / ":" / "\" / <"> "/" / "[" / "]" / "?" / "=" ; Must be in quoted-string, ; to use within parameter values So the ";" must be in a quoted string. That's defined in RFC 822, http://www.faqs.org/rfcs/rfc822.html (now obsolete) quoted-string = <"> *(qtext/quoted-pair) <"> qtext = , ; => may be folded "\" & CR, and including linear-white-space> CHAR = The ';' is in CHAR and is not "\" nor CR so it's in qtext, so it's part of quoted-string, so it's allowed in a value without extra interpretation. I looks like 2822 (the updated version of 822) a http://www.faqs.org/rfcs/rfc2822.html agrees. So I think it's a bug in the email module's parser. The actual bug is in email/Parser.py with # Regular expression used to split header parameters. BAW: this may be too # simple. It isn't strictly RFC 2045 (section 5.1) compliant, but it catches # most headers found in the wild. We may eventually need a full fledged # parser eventually. paramre = re.compile(r'\s*;\s*') A quick scan of the code suggests that it isn't a quick fix (eg, not just a matter of tweaking that regexp. Could you file a bug report against it? Andrew dalke at dalkescientific.com From grante at visi.com Mon Aug 18 09:11:19 2003 From: grante at visi.com (Grant Edwards) Date: 18 Aug 2003 13:11:19 GMT Subject: bitwise not - not what I expected References: <1YD%a.747879$3C2.17342633@news3.calgary.shaw.ca> Message-ID: <3f40d077$0$164$a1866201@newsreader.visi.com> In article , Michael Peuser wrote: > A very good point! I might add that this is my no means an exotic feature. > Mathematically speaking there is great charme in computing just inside the > invervall (-1,+1). And if you have no FPU you can do *a lot* of pseudo real > operations. You have get track of the scale of course - it is a little bit > like working with sliding rules if anyone can remember those tools ;-) Sure. I've got two sitting at home. :) FWIW, it used to be fairly common for process-control systems to define operations only over the interval (-1,+1). This made implimentation easy, and the input and output devices (temp/pressure sensors, valves, whatnot) all had pre-defined ranges that mapped logically to the (-1,+1) interval. -- Grant Edwards grante Yow! The SAME WAVE keeps at coming in and COLLAPSING visi.com like a rayon MUU-MUU... From nhodgson at bigpond.net.au Fri Aug 22 21:11:06 2003 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Sat, 23 Aug 2003 01:11:06 GMT Subject: large-scale app development in python? References: Message-ID: gabor: > but i got a question, that i couldn't answer: > -you can't compile python, as you can c++ or java => there's no type > checking before starting the program => if one programmer changes a > method name or method signature, then how do we know we changed all the > code that calls that method? http://pychecker.sourceforge.net/ Neil From pobrien at orbtech.com Sat Aug 30 10:14:59 2003 From: pobrien at orbtech.com (Patrick K. O'Brien) Date: 30 Aug 2003 09:14:59 -0500 Subject: Need good example database schema References: Message-ID: Steve Williams writes: > Patrick K. O'Brien wrote: > > I'm looking for a good schema to use as an example for an object > > database system. Something like a books/authors/publishers or > > teachers/students/courses kind of thing. There are plenty of examples > > of such to be found, especially in the academic literature involving > > object databases, but most of them are pathetic. It's hard to take a > > schema seriously when it shows MarriedTeacher inheriting from Teacher, > > etc. I want something that makes proper use of inheritance, has > > classes with reasonable attributes, and does a decent job reflecting > > reality (ie, books can have more than one author, a teacher of one > > course could be a student of another, etc.). Any suggestions? > > > > There are objects and then there are relationships between objects. Agreed. > Expand your concept of schemas to include relationships as > independent objects (I call them Relators in my work) and you'll > have more luck with reflecting reality. While I agree that many relationships deserve to be independent objects, I've never been comfortable with the notion that they deserve a category of their own (Relators, for example). Especially when they aquire attributes of their own (Royalty as attribute of book contract, for example). To me there are just entities: book, person, authorship, contract, publisher (actually should be a role played by an organization with respect to a book), etc. Can you provide more details about your Relators? Do they have functionality that other entities do not? Where do you draw the line between an entity and a relator? > - Author is a relationship between book and person > > - Book contract is a relationship between author and publisher > > - Royalty is an attribute of book contract > > The hierarchy of object inheritance misses out on the web of > relationships. Again, I agree. Do you have any examples that don't miss out on this? > Now add the time dimension to your objects and relationships and > metadata, and you'll *really* start to reflect reality. Google > bitemporal. Interesting stuff there. Thanks for the Google tip. I'm curious about your work. Can you tell me more? -- Patrick K. O'Brien Orbtech http://www.orbtech.com/web/pobrien ----------------------------------------------- "Your source for Python programming expertise." ----------------------------------------------- From a.schmolck at gmx.net Mon Aug 18 18:51:43 2003 From: a.schmolck at gmx.net (Alexander Schmolck) Date: 18 Aug 2003 23:51:43 +0100 Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> Message-ID: "Brandon J. Van Every" writes: > Alexander Schmolck wrote: > > > > Would you still have a problem with macros in python if utilizing them > > required some obvious and explicit mechanism (say a > > 'use_custom_syntax' statement right at the beginning of a module that > > wants to use macros), so that their use could easily be controlled by > > e.g. project managers? > > Yes you would. In open source communities, you'd get different > philosophical camps, and people in one camp would embed 'use_custom_syntax' > in some *.h file (yeah yeah I'm a C++ programmer) that all the other *.h > files use. In the proposed scheme every module that wants to use custom syntax has to say so, period. So there is no silent infestation (these syntaxes can't be stealthily exported). > When you grab that code, you're not really going to want to do the work of > making more specific 'use_custom_syntax' directives, as it would break in > all sorts of subtle ways. So now the 'culture of feature' supplants the > culture of control. The same could happen in a big commerical project, for > that matter. Thus it may be wise not to allow this kind of customization at > all. I don't really understand what you're saying. To reiterate my point: the language could force every module that wants to use some custom syntax internally to explicitly say so at its beginning. It would be easy (from a technical perspective) for project managers (open source or otherwise) to only allow certain, particularly trusted programers to create such modules or ban them outright. Or allow the use of certain custom syntaxes but only approved ones (created by experienced programers) and only in special situations. Just like you wouldn't allow every second rate programmer to write the system-critical libraries everything is built upon, you wouldn't allow just about anybody to create their own mini-languages without a need. OTOH if that need arises, you can get some good programmers to design the necessary syntax transformations and I can't really see how this would be worse than having them write some ad-hoc interpreter from scratch which likely will suffer from an inferior design and worse reliability and performance. 'as From newsgroups at jhrothjr.com Fri Aug 1 15:40:41 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Fri, 1 Aug 2003 15:40:41 -0400 Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> Message-ID: "Anthony_Barker" wrote in message news:899f842.0307310555.56134f71 at posting.google.com... > I have been reading a book about the evolution of the Basic > programming language. The author states that Basic - particularly > Microsoft's version is full of compromises which crept in along the > language's 30+ year evolution. > > What to you think python largest compromises are? I'm not sure if we've beaten this one to death or not, but a real example of a compromise just floated through my head. Consider .sort() and .reverse(). These two otherwise admirable methods don't return the object, so they can't be chained. Why not? Because they update the list in place, and Guido decided that not returning the object was a cheap way to make it clear that they were doing something unusual. Now, *that's* a compromise. The worst of both worlds. John Roth From wiebke.paetzold at mplusr.de Wed Aug 6 07:49:29 2003 From: wiebke.paetzold at mplusr.de (Wiebke Pätzold) Date: Wed, 06 Aug 2003 13:49:29 +0200 Subject: classes (table) References: Message-ID: <0dq1jv8lr19gph86urpi214bjpb3tlskkh@4ax.com> On Wed, 06 Aug 2003 11:31:39 GMT, Alex Martelli wrote: >Wiebke P?tzold wrote: > ... >> import Mk4py > >I'm not experienced in this package, so I'm not sure this will >work and can't test, but: > >> def __call__(self, row): >> try: >> nachname = row.Nachname > >Just change this to > > whatever = getattr(row, self.attributeName) > >Where self.attributeName can be any string, e.g. defaulting >to 'Nachname' if you wish, as set e.g. in __init__. > > >Alex but the user of the program should have the possibility to select in wich column the search takes place. On the one hand the program must be in the situation to search in all columns of the table for a special word. And on the other hand the user have to determine in wich column the search after this special word takes place. This is the task. And this two things must combined in one program. From chris.gonnerman at newcenturycomputers.net Wed Aug 27 09:00:52 2003 From: chris.gonnerman at newcenturycomputers.net (Chris Gonnerman) Date: Wed, 27 Aug 2003 08:00:52 -0500 Subject: Proposal: Magic Constants Message-ID: <000a01c36c9b$3ef54d20$1f00000a@house> A while back (a long while actually) I was a participant in a long argument over decimal and rational numbers, and their inclusion into the core of Python. Last night in a dream I came up with an interesting solution (no, really!) which, in the cold light of morning, still seems pretty cool. The gist is this: Constants would be allowed to be trailed by any single alphabetic character. When compiled, a constant with a nonstandard letter code would be stored in the compiled code in the form of a text literal, appropriately marked. When the code is executed, and the special literal is processed, the interpreter would look up a conversion function in an internal list. If no conversion is found, a runtime error would be raised. Modules to handle alternate numeric formats, such as decimal, fixed-point, rational, etc. would include a call to a builtin registration function which would allow them to "take over" a specific alphabetic specifier. So, to use a supposed Decimal.py module, one would do thusly: "decimal arithmetic example" import Decimal a = 1.05D and so on. Limitations: The literal would be required by the compiler to match the format of a real number (float or integer); the conversion function could raise its own runtime error if the text string were out of its range. So, to write a rational number: "rational arithmetic example" import Rational b = 1R/15 Note that the 1R is actually the rational 1/1, whereas the 15 is an integer; the division sign is not part of the rational here, but actually indicates division. The result would be the rational 1/15, which is assigned to the variable b. The only other disadvantage I can see is that a small class of syntax errors become runtime errors. I'm don't think this is a major thing though. Thoughts and opinions welcome... Chris Gonnerman -- chris.gonnerman at newcenturycomputers.net http://newcenturycomputers.net From gh at ghaering.de Wed Aug 6 08:27:01 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Wed, 06 Aug 2003 14:27:01 +0200 Subject: Python 2.3 and MySQL on Windows XP? In-Reply-To: References: Message-ID: <3F30F415.5070404@ghaering.de> M Wells wrote: > Hi All, > > Well, laugh, it appears my progress in learning Python is going to be > a little more complex than I first thought. > > Am I right in understanding that currently MySQLdb isn't available for > Windows to support Python 2.3? This is my primary purpose for Python, > so I'm wondering if anyone knows when MySQLdb will be available in a > version for windows xp supporting 2.3? I've built the binaries, as usual, and sent them to the maintainer. But he hasn't uploaded them to Sourceforge, yet. So in the meantime you can get them from my server: http://ghaering.de/python/unsupported/MySQL-python.exe-0.9.2.win32-py2.3.exe As soon as the binaries are uploaded to the official place I'll delete them from my server. -- Gerhard From NAICH-SYDNEYCH-EXCHANGE at cowleyhearne.com.au Mon Aug 25 00:54:26 2003 From: NAICH-SYDNEYCH-EXCHANGE at cowleyhearne.com.au (GroupShield for Exchange (CH-EXCHANGE)) Date: Mon, 25 Aug 2003 14:54:26 +1000 Subject: ALERT - GroupShield ticket number OA1808_1061787260_CH-EXCHANGE_ 3 was generated Message-ID: <540F61BD2C9BD64DA18FCB9B7367424D897CA9@CH-EXCHANGE.cowleyhearne.com.au> Action Taken: The attachment was quarantined from the message and replaced with a text file informing the recipient of the action taken. To: mailbox at cowleyhearne.com.au From: python-list at python.org Sent: -187607424,29584068 Subject: Thank you! Attachment Details:- Attachment Name: wicked_scr.scr File: wicked_scr.scr Infected? No Repaired? No Blocked? Yes Deleted? No Virus Name: -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/ms-tnef Size: 1958 bytes Desc: not available URL: From adalke at mindspring.com Thu Aug 21 13:00:44 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Thu, 21 Aug 2003 17:00:44 GMT Subject: What's better about Ruby than Python? References: <3F41505F.69D18CC8@alcyone.com> <66d7kvonvb2n0nqbqahhd5roak7ur81sob@4ax.com> <3f43ef5d_4@127.0.0.1> <3F440A35.9030602@nyc.rr.com> <4o_0b.1665$Ej6.1182@newsread4.news.pas.earthlink.net> <8D01b.1721$Ej6.702@newsread4.news.pas.earthlink.net> <3F44ED2E.9070308@nyc.rr.com> Message-ID: <0V61b.1900$Ej6.1012@newsread4.news.pas.earthlink.net> Kenny Tilton > Lisp hashtables can key off any Lisp datum, but... Bear with my non-existant Lisp knowledge Suppose the code is modified. How does the hash table get modified to reflect the change? Written in Python, if I have a = (1, 2, (3, [4, 5])) I can't hash it because someone could come by later and do a[2][1].append(6) so the hash computation and test for equality will give different results. > The next step would > have been to determine when the closure had best re-execute the code > body to see if the world had changed in interesting ways, but that is a > big step and requires dependency tracking between cells. Ahhh, so the Python code was comparable in power without using macros? > Once a Cell is told an input has changed, it re-runs its body to see if > it comes up with a different result, in which case it caches that and > tells other dependents to rethink their caches. Err, or maybe not. I don't see how this is done in the Lisp code. Still, such flexibility is available in Python without recourse to macros. > So what is shown in my example is fun but halfbaked. I was just trying > to show how a macro could hide the plumbing of an interesting mechanism > so the reader can focus on the essence. Could the same code be written in Lisp using an approach like I did for Python? How would a non-macro solution look like? What's the advantage of the macro one over the non-macro one? Just performance? Andrew dalke at dalkescientific.com From ialbert at mailblocks.com Mon Aug 11 09:47:09 2003 From: ialbert at mailblocks.com (Istvan Albert) Date: Mon, 11 Aug 2003 09:47:09 -0400 Subject: Fun with numbers - dammit, but I want a cast! In-Reply-To: <3f3792f2$0$18258$afc38c87@auth.uk.news.easynet.net> References: <3f378fac$0$10778$afc38c87@auth.uk.news.easynet.net> <3f3792f2$0$18258$afc38c87@auth.uk.news.easynet.net> Message-ID: Graham Nicholls wrote: >>Have you tried doing it this way: >>xscale = xframe / float(img_x) > > > Thats what I wanted to do, but was sure I'd read that python didn't have > casts, and that _looks_ like a cast to me! You can also force floating point math by muliplying with 1.0 before the division: xscale = 1.0 * xframe/img_x Istvan. From bokr at oz.net Fri Aug 15 18:04:10 2003 From: bokr at oz.net (Bengt Richter) Date: 15 Aug 2003 22:04:10 GMT Subject: Module access from inside itself References: Message-ID: On Fri, 15 Aug 2003 16:20:43 GMT, Steven wrote: >I'm writing a Python script which can be called from the command-line, and >I want to use my module doc string as the CL help text, but I don't know >how to access my module object from inside the module. > >I've tried searching for an answer, but haven't found anything. Please >excuse me if I'm missing something simple, I'm a newbie to Python. > >I'm doing something like this: > > > >#!/usr/bin/python >"""Module doc string goes here. >""" > >import getopt, sys > >def MyFunction(args): >? ? pass > >if __name__ == "__main__": >? ? opts, args = getop.getopt(sys.argv[1:], [], ["help"]) >? ? for opt in opts: >? ? ? ? if opt == "--help": >? ? ? ? ? ? print MY_MODULE.__doc__ ? ?# How do I get this? ? ? ? ? ? ? print __doc__ ? ?# should get it >? ? ? ? else: >? ? ? ? ? ? MyFunction(args) > > > >How do I get a reference to the module from inside the module? Is this >the Pythonic way of generating help strings for CL scripts? > You are already inside the module, so an unqualified name will refer to module globals unless it's being used in some local scope that has a binding shadowing the global name. Regards, Bengt Richter From martin at v.loewis.de Sun Aug 3 13:45:01 2003 From: martin at v.loewis.de (Martin v. =?iso-8859-15?q?L=F6wis?=) Date: 03 Aug 2003 19:45:01 +0200 Subject: 2.3 Redhat 9 Tkinter IDLE References: Message-ID: "RT Lange" writes: > /usr/lib/Python-2.3/Modules/_tkinter.c:96:2: #error "unsupported Tcl configuration" That is the problem. Quoting from README: Red Hat Linux: Red Hat 9 built Python2.2 in UCS-4 mode and hacked Tcl to support it. To compile Python2.3 with Tkinter, you will need to pass --enable-unicode=ucs4 flag to ./configure. In this case "it is so difficult" because Redhat chose to hack Tcl. HTH, Martin From danielk at aracnet.com Sun Aug 10 21:49:31 2003 From: danielk at aracnet.com (Daniel Klein) Date: Sun, 10 Aug 2003 18:49:31 -0700 Subject: .idlerc Message-ID: Can someone tell me where this file is suppose to go, so that I can automatically load certain modules when IDLE starts up? Thanks Daniel Klein From newsgroups at jhrothjr.com Thu Aug 7 10:39:44 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Thu, 7 Aug 2003 10:39:44 -0400 Subject: filter()ing a dict References: <16469f07.0308070559.aed41a@posting.google.com> Message-ID: According to the doc, filter() processes sequences, iterators and objects that support the iterator protocol. A dict is none of those things, unless it supports the iterator protocol, which is not mentioned in the documentation as of 2.2.3. Possibly it does in 2.3.0. If you want to use filter() to process a dict, use the .items() method. That will get you a list of tuples, where each tuple contains the key and value. .iteritems() will also work, of course. What is returned will be a list of tuples, which you can use to build a dict. I'm surprised that what you tried worked at all. The 2.2.3 documentation on dictionaries doesn't suggest that a dictionary supports the iteration protocol, or what it returns in that context. John Roth "Robin Cull" wrote in message news:16469f07.0308070559.aed41a at posting.google.com... > Imagine I have a dict looking something like this: > > myDict = {"key 1": ["value 1", "value 2", "value 3", "value 4"], "key > 2": ["value 1", "value 2"], "key 3": ["value2", "value 3", "value 4"], > "key 4": ["value 1", "value 2", "value 3", "value 4"]} > > That is, a set of keys which have a variable length list of associated > values after them. What I want to do is filter out a subset of this > dict to produce another dict that satisfies a set of criteria (in this > case whether it contains all four values) to end up with something > like this: > > {"key 1": ["value 1", "value 2", "value 3", "value 4"], "key 4": > ["value 1", "value 2", "value 3", "value 4"]} > > I've tried using the filter() function so I wrote a small function > that returned True or False depending on whether the length of the > list was what I wanted e.g. > > def f(item): > if len(item) == 4: > return True > else: > return False > > I then called filter(f, myDict). > > I was expecting to be returned a dict which was the subset of myDict > that satisfied f. > > This did not happen; the item passed to f was each key of the dict, > not each value list. The call to filter returned an empty list (as > obviously none of the keys satisfied the criteria). If anything I > would have expected an empty dict back as according to the docs: > > ""filter(function, sequence)" returns a sequence (of the same > type, if possible) consisting of those items from the sequence for > which function(item) is true." > > The important bit here is "of the same type, if possible" which I > understood to mean if passed a dict it would return a dict. > > I've tried calling filter(f, myDict.values()) which works and I get a > list like this returned: > > [["value 1", "value 2", "value 3", "value 4"], ["value 1", "value 2", > "value 3", "value 4"]] > > Sort of what I want but I've lost the associativity with the key which > was kind of the point in using a dict in the first place. > > I'm guessing that filter() does not work on a dict in the way I think > it should. > > I can write something to get around the behaviour in this particular > case (although suggestions would be welcome). > > My question is, does anybody else think that when calling filter(f, > dict), it should return a dict of the keys and values of the former > dict where the values satisfy the conditions defined by f()? > > Are there reasons for it not to work this way? I must admit I've not > looked into this carefully, just in the context of my script it'd be > useful to. > > What are the side effects of making filter() work this way? > > Thanks all. > > Regards, > > Robin From sfb at alysseum.com Sun Aug 10 05:02:06 2003 From: sfb at alysseum.com (Simon Bayling) Date: Sun, 10 Aug 2003 09:02:06 +0000 (UTC) Subject: % Documentation References: <87y8y2lq84.fsf@flibuste.net> Message-ID: Wilk wrote in news:87y8y2lq84.fsf at flibuste.net: > Simon Bayling writes: > >> Hello, >> >> Where is the % operator documented? > > http://www.python.org/doc/current/lib/typesseq-strings.html Ah yes, thank you. I wasn't thinking "string... sequence type" at all. Cheers, Simon. From tomas at fancy.org Wed Aug 13 14:10:22 2003 From: tomas at fancy.org (Tom Plunket) Date: Wed, 13 Aug 2003 11:10:22 -0700 Subject: Multi-Line Comment References: <4qofjvg3bh9smlnb1do4f0lhjga7bacnu3@4ax.com> <200308122306.48320.shalehperry@comcast.net> Message-ID: Chad Netzer wrote: > > In emacs what are the key strocks for block indent and dedent? > > In python-mode: > > C-c > > C-c < Oh cool. I've been using C-x r o and C-x r k to open and kill rectangles. Your way seems much easier. ;) Thanks. ;) -tom! -- There's really no reason to send a copy of your followup to my email address, so please don't. From info at nyc-search.com Wed Aug 13 16:53:00 2003 From: info at nyc-search.com (NYC-SEARCH) Date: 13 Aug 2003 13:53:00 -0700 Subject: JOB: Software Engineer (Python/C++): San Mateo, CA Message-ID: JOB: Software Engineer (Python/C++): San Mateo, CA DETAILS: http://www.nyc-search.com/jobs/python-c.htm From soundwave56 at yahoo.ca Thu Aug 28 14:44:06 2003 From: soundwave56 at yahoo.ca (Hank) Date: 28 Aug 2003 11:44:06 -0700 Subject: changing color on the command prompt References: <731fc603.0308271213.4d91ab29@posting.google.com> <3F4D34C5.150FD96E@engcorp.com> Message-ID: <731fc603.0308281044.7e545096@posting.google.com> Sorry I wasn't being clear enough. I meant the prompt for Windows operating system C:>. And by error messages i just mean printouts like print "Error in Process" If its just an environment variable, i should be able to change it, print it out and change it back to the original color right? Anyone know which variable i have to modify? Thanks Peter Hansen wrote in message news:<3F4D34C5.150FD96E at engcorp.com>... > Hank wrote: > > > > does anyone know how to change the foreground color of the command > > prompt through python? > > > > For example if i was printing out an error message, I would like it to > > be red where the normal text color is white. > > The question is underspecified/unclear. > > 1. What operating system? > > 2. By "command prompt", do you just mean the console, where text appears, > or do you really mean the *prompt* for the operating system, which under > Linux is usually something like "[user at host]#" and which under Windows > is usually something like "C:\>"? > > 3. Now you mention error messages... that implies you just mean changing > the color of your program's output. > > If you mean the actual *prompt*, you need to change the right environment > variable, which usually needs a separate script. > > If you mean the console text color, check the archives for the last couple > of days for responses to a similar question (search for "ansi.sys" perhaps). > > -Peter From bdesth.nospam at removeme.free.fr Tue Aug 26 20:12:03 2003 From: bdesth.nospam at removeme.free.fr (Bruno Desthuilliers) Date: Wed, 27 Aug 2003 02:12:03 +0200 Subject: My future Python IDE article In-Reply-To: References: Message-ID: <3f4bf501$0$265$626a54ce@news.free.fr> Skip Montanaro wrote: > David> So c.l.py readers... make the case for your favorite one getting > David> on the list. > > This doesn't really count as an IDE in the usual sense, but Emacs/XEmacs > with python-mode provides a fair amount of leverage to the programmer. It > should probably be mentioned, if not tested. (snip a whole lot of functionalities) Oddly enough, I was just about to mention it... Bruno From achrist at easystreet.com Fri Aug 22 14:28:27 2003 From: achrist at easystreet.com (achrist at easystreet.com) Date: Fri, 22 Aug 2003 11:28:27 -0700 Subject: visual indentation References: Message-ID: <3F4660CB.FF72D945@easystreet.com> Hilbert wrote: > > Hello, > > I'm using python to output RIB streams for Renderman. > The RIB stream is a bunch of statements which describes > a 3d image. The Rib standard allows for blocks which we > usually indent for better visualization for example: > > WorldBegin > Color [1 1 1] > Surface "constant" > Sphere(1.0, -1.0, 1.0, 360) > WorldEnd > > I'm using CGKit in python which has a Renderman binding, > so to output the same RIB I'd write: > > RiWorldBegin() > RiColor(1.0,1.0,1.0) > RiSurface('constant') > RiSphere(1.0,-1.0,1.0,360) > RiWorldEnd() > > But I get an error, because python interprets my indentation > as a block in the python code. So the only way to write this > is without the indentation: > > RiWorldBegin() > RiColor(1.0,1.0,1.0) > RiSurface('constant') > RiSphere(1.0,-1.0,1.0,360) > RiWorldEnd() > > But this is a lot harder to read. > > Is there any way to use such "visual" indentation in python? > If the code is purely sequential, how about something like this: import string def RunTheseStatements(s): stmts = map(string.strip, s.split("\n")) for stmt in stmts: eval(stmt) RunTheseStatements(""" RiWorldBegin() RiColor(1.0,1.0,1.0) RiSurface('constant') RiSphere(1.0,-1.0,1.0,360) RiWorldEnd() """) Al From aleax at aleax.it Thu Aug 7 09:17:50 2003 From: aleax at aleax.it (Alex Martelli) Date: Thu, 07 Aug 2003 13:17:50 GMT Subject: generator function References: <215fa0fc.0308070503.2344dd66@posting.google.com> Message-ID: <2ksYa.28254$an6.994967@news1.tin.it> chansky wrote: > I read the following link about generator: > http://www.python.org/peps/pep-0255.html > but I am still not so clear on the use/purpose of a generator function > other than the fact that a generator can retain the state of the local > variables within the fuction body. Can someone out there shed some > lights on this topic or share about how/when you would ever use a > generator function. You'll use a generator when you want to 'return', one after the other, a sequence of results that are best computed sequentially. The alternative is to return the whole sequence of results at once, for example as a list, but that may be an inferior choice if the number of results is large, particularly if it's possible that the "consumer" of the results may only be interested in a prefix of the whole sequence of results. Suppose for example that you have a file, that you knos is open for binary input but need not be seekable (e.g. it COULD be standard-input, a pipe, etc etc); you know the file is made up of a number of chunks, with each chunk being N bytes, and want to process the file sequentially by chunks. I.e., the purpose is to be able to write: # maybe after: thefile = open('whatever', 'rb') for chunk in chunker(thefile, N): if process(chunk) == WE_ARE_DONE: break Without generators, you could write chunker as a function returning a list of chunks: def chunker(afile, N): results = [] while 1: chunk = afile.read(N) if not chunk: break results.append(chunk) return results However, the list built and returned by this version of chunker is potentially huge -- that could be a terrible waste of memory, and of time, particularly (but not exclusively) if it's at all likely that processing the first few chunks may already find one causing a WE_ARE_DONE return value from the (hypothetical) 'process' function. So, a generator gives you an elegant alternative (in Python 2.3 or with "from __future__ import generators" in 2.2!): def chunker(afile, N): while 1: chunk = afile.read(N) if not chunk: break yield chunk voila -- now the chunks are returned one at a time and there is no waste of memory nor time. What could be neater...? Alex From rganesan at myrealbox.com Tue Aug 19 07:04:27 2003 From: rganesan at myrealbox.com (Ganesan R) Date: Tue, 19 Aug 2003 16:34:27 +0530 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: <3F412484.69867AED@alcyone.com> <3f415560$0$1124$626a54ce@news.free.fr> Message-ID: >>>>> "Bruno" == Bruno Desthuilliers writes: > Istvan Albert wrote: >> Erik Max Francis wrote: >> >>>> What's ***TOTALLY COMPELLING*** about Ruby over Python? >>> >>> comp.lang.ruby doesn't have Brandon Van Every. >> LOL >> > LOL 2 > Bruno > (yes, I want to be in Brandon's killfile. It's the new game on clp : > being in Brandon's killfile. Just imagine what will happen when every > clp regulars will be in Brandon's kill file...) I am not a clp regular (mostly a lurker), but I also wanna play. *please* ;-). Ganesan -- Ganesan R From vze4rx4y at verizon.net Wed Aug 27 01:35:05 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Wed, 27 Aug 2003 05:35:05 GMT Subject: getopt issues References: Message-ID: [David Bear] > I'm stumped. Trying to follow the docs and .. failure. > > here's the args > > >>> args > '-Middwb at mainex1.asu.edu -AKHAAM at prlinux+898 -CA --D2003-08-20-09:28:13.417 -Ff -Hprlinux --JTCPIP_NPF_TEST_DARS_PORTRAIT -NTCPIP_NPF_TEST_DARS_PORTRAIT --Phold queue -Qholdqueue -aacct -b2895 -d/var/spool/lpd/holdqueue -edfA898prlinux -fTCP IP_NPF_TEST_DARS_PORTRAIT -hprlinux -j898 -kcfA898prlinux -l66 -nKHAAM -sstatus -t2003-08-20-09:28:13.000 -w80 -x0 -y0 acct \n' > > > I know, they're long. sorry. they just are. and maybe thats the > bug. > > here's what happens > > >>> a, b = getopt.getopt(args, 'APQn') > >>> a > [] > >>> b > '-Middwb at mainex1.asu.edu -AKHAAM at prlinux+898 -CA --D2003-08-20-09:28:13.417 -Ff -Hprlinux --JTCPIP_NPF_TEST_DARS_PORTRAIT -NTCPIP_NPF_TEST_DARS_PORTRAIT --Phold queue -Qholdqueue -aacct -b2895 -d/var/spool/lpd/holdqueue -edfA898prlinux -fTCP IP_NPF_TEST_DARS_PORTRAIT -hprlinux -j898 -kcfA898prlinux -l66 -nKHAAM -sstatus -t2003-08-20-09:28:13.000 -w80 -x0 -y0 acct \n' > > > not at all what the docs lead me to believe. Is getopt buggy? Normally, it is prudent to suspect your own code first rather than the module. In this case, getopt is expecting a list for the args argument which normally comes from sys.argv. Try this: args = args.split() a, b = getopt.getopt(args, 'APQn') That will get you closer. The next step is define the missing codes like -M. Raymond Hettinger From newsgroups at jhrothjr.com Sun Aug 3 23:12:52 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Sun, 3 Aug 2003 23:12:52 -0400 Subject: True References: Message-ID: "Daniel Klein" wrote in message news:fucrivcvd2mel7k51ij1hktb55gqnmk9ic at 4ax.com... > In Python 2.2 I use to have > > true = (1 == 1) > false = not true > > This was at the recommendation of someone on this list some time ago. > The reason (if I remember correctly) was that setting > > true = 1 > false = 0 > > were not true booleans. There were no true booleans in 2.2 and earlier. Whoever recommended that didn't know what he was talking about. There was no difference. > Now the expression (1 == 1) returns 'True', and caused a bug in my > code. So my question is what is the proper method for setting booleans > in 2.3? I presume what broke your code was depending on the return from either str() or repr(), or the % operator. That was, unfortunately, one of the incompatibilites between 2.2 and 2.3. In 2.3, Boolean is a subtype of Int, and has two values: True and False. Both of these are built in constants, so just use them. That's what they're for. For most purposes, the are the same as 1 and 0, except for what they return from str() and repr(), and how they get formatted with %. John Roth > > Really confused, > > Daniel Klein From detlev at die-offenbachs.de Sat Aug 16 15:39:15 2003 From: detlev at die-offenbachs.de (Detlev Offenbach) Date: Sat, 16 Aug 2003 21:39:15 +0200 Subject: GUI builder for Python References: Message-ID: henry wrote: > Hi, > > Just wondering if there's a good GUI builder for Python. Something like > Visual Tcl, where you just drag and drop objects. > > Not too good with creating user interfaces from code along. > > Thanks If you are about to go with PyQt I would recommend you try eric3 (http://www.die-offenbachs.de/detlev/eric3.html). It is an IDE built for Python coded with Python and PyQt. And most of all, eric3 is free. As its GUI-Builder it uses Qt-Designer. Detlev -- Detlev Offenbach detlev at die-offenbachs.de From edreamleo at charter.net Fri Aug 29 10:00:00 2003 From: edreamleo at charter.net (Edward K. Ream) Date: Fri, 29 Aug 2003 09:00:00 -0500 Subject: Hunting a memory leak References: Message-ID: > I'm trying to discover a memory leak on a program of mine. I've taken > several approaches, but the leak still resists to appear. First, single-stepping through C code is surprisingly effective. I heartily recommend it. Here are some ideas you might use if you are truly desperate. You will have to do some work to make them useful in your situation. 1. Keep track of all newly-created objects. Warning: the id trick used in this code is not proper because newly allocated objects can have the same address as old objects, so you should devise a better way by creating a more unique hash. Or just use the code as is and see whether the "invalid" code tells you something ;-) global lastObjectsDict objects = gc.get_objects() newObjects = [o for o in objects if not lastObjectsDict.has_key(id(o))] lastObjectsDict = {} for o in objects: lastObjectsDict[id(o)]=o 2. Keep track of the number of objects. def printGc(message=None,onlyPrintChanges=false): if not debugGC: return None if not message: message = callerName(n=2) # Left as an exercise for the reader. global lastObjectCount try: n = len(gc.garbage) n2 = len(gc.get_objects()) delta = n2-lastObjectCount if not onlyPrintChanges or delta: if n: print "garbage: %d, objects: %+6d =%7d %s" % (n,delta,n2,message) else: print "objects: %+6d =%7d %s" % (n2-lastObjectCount,n2,message) lastObjectCount = n2 return delta except: traceback.print_exc() return None 3. Print lots and lots of info... def printGcRefs (verbose=true): refs = gc.get_referrers(app().windowList[0]) print '-' * 30 if verbose: print "refs of", app().windowList[0] for ref in refs: print type(ref) if 0: # very verbose if type(ref) == type({}): keys = ref.keys() keys.sort() for key in keys: val = ref[key] if isinstance(val,leoFrame.LeoFrame): # changes as needed print key,ref[key] else: print "%d referers" % len(refs) Here app().windowList is a key data structure of my app. Substitute your own as a new argument. Basically, Python will give you all the information you need. The problem is that there is way too much info, so you must experiment with filtering it. Don't panic: you can do it. 4. A totally different approach. Consider this function: def clearAllIvars (o): """Clear all ivars of o, a member of some class.""" o.__dict__.clear() This function will grind concrete walls into grains of sand. The GC will then recover each grain separately. My app contains several classes that refer to each other. Rather than tracking all the interlocking references, when it comes time to delete the main data structure my app simply calls clearAllIvars for the various classes. Naturally, some care is needed to ensure that calls are made in the proper order. HTH. Edward -------------------------------------------------------------------- Edward K. Ream email: edreamleo at charter.net Leo: Literate Editor with Outlines Leo: http://webpages.charter.net/edreamleo/front.html -------------------------------------------------------------------- From usenet at microtonal.co.uk Mon Aug 25 18:56:43 2003 From: usenet at microtonal.co.uk (Graham Breed) Date: Mon, 25 Aug 2003 23:56:43 +0100 Subject: Determinig position of a element in a list In-Reply-To: References: Message-ID: <4uw2b.240$i27.74@news-binary.blueyonder.co.uk> Przemo Drochomirecki wrote: > Hello, > i'm wondering if there is any tricky way for doing following thing: > A - list of distinct integers (e.x. A = [1,3,7,11,14,15]) > very fast function determinig position of number x in list A > or -1 if x doesnt belong to A > Operator IN returns only false/true values > i can implement function index (e.x. index(5,A) = -1, index(7,A) = 2), but > maybe there's is simpler(builtin?) solution Yes, there is a builtin solution Python 2.2.2 (#2, Feb 5 2003, 10:40:08) [GCC 3.2.1 (Mandrake Linux 9.1 3.2.1-5mdk)] on linux-i386 Type "help", "copyright", "credits" or "license" for more information. >>> [1,3,7,11,14,15].index(7) 2 >>> [1,3,7,11,14,15].index(5) Traceback (most recent call last): File "", line 1, in ? ValueError: list.index(x): x not in list >>> All you have to do is handle the exception instead of testing for -1. I wouldn't count it as "very fast" though because it has to do a linear search. If you need to do this a lot with a list that doesn't change, it might be worth converting it to a dictionary >>> original = [1,3,5,6,11,14,15] >>> reverse_lookup = {} >>> for i in range(len(original)): ... reverse_lookup[original[i]] = i ... >>> reverse_lookup.get(7, -1) -1 >>> reverse_lookup.get(5, -1) 2 but if the list's big enough that speed's a problem, the extra memory usage might be as well. Alternatively, if (as in the example) the integers are in order, a binary search will be more efficient than a linear one. Hopefully, you'll find you don't need it to be very fast at all. Graham From skip at pobox.com Sun Aug 3 22:05:34 2003 From: skip at pobox.com (Skip Montanaro) Date: Sun, 3 Aug 2003 21:05:34 -0500 Subject: Example code for anydbm wanted... In-Reply-To: References: Message-ID: <16173.49006.847887.350886@montanaro.dyndns.org> John> Does anyone have any good example code that shows how to use the John> "anydbm" wrapper tp interface with a very simple database. like John> some examples of how to use "dumbdbm"? Then perhaps at a later John> time, I'm going to want to then interface it to a more robust John> database like PostGreSQL or mySQL. But I want to external John> interface to "hide" the specifics and have a really generic John> interface. The anydbm module and the modules it wraps (dumbdbm, bsddb, dbm and gdbm) are really persistent dictionaries, not true databases. They offer no query capabilities beyond searching for specific keys and provide few, if any, of the features you would expect from a database (SQL, transactions, multi-threading, etc). If what you will eventually want is a relational database like PostgreSQL or MySQL, then take a look at the DB API Spec, aka PE 249: http://www.python.org/peps/pep-0249.html and choose a relational database to use. Skip From danielk at aracnet.com Sat Aug 30 23:55:30 2003 From: danielk at aracnet.com (Daniel Klein) Date: Sat, 30 Aug 2003 20:55:30 -0700 Subject: Polymorphism the Python way Message-ID: Given the following code,,, class Dead(object): def __init__(self, adeadthing): self.deadthing = adeadthing def getthing(self): return self.deadthing class Parrot(object): def __init__(self, aparrotthing): self.parrotthing = aparrotthing def getthing(self): return self.parrotthing ...and then somewhere in some script I use... self.getthing() to get whatever 'thing' I want to get. Isn't there a better way to do this in Python? I hate doing these 'get' type methods. The seem ugly to me. Thanks, Daniel Klein From adalke at mindspring.com Mon Aug 4 14:36:56 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Mon, 4 Aug 2003 12:36:56 -0600 Subject: time, calendar, datetime, etc References: Message-ID: John Roth: > Well, where's the hook in the module for someone to add additonal > calendar classes? Why does the module need a hook? Write a new module, possibly deriving from existing classes or interfaces. Andrew dalke at dalkescientific.com From mis6 at pitt.edu Mon Aug 18 18:01:38 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 18 Aug 2003 15:01:38 -0700 Subject: What's better about Ruby than Python? References: Message-ID: <2259b0e2.0308181401.791bb223@posting.google.com> "John Roth" wrote in message news:... > 3. Not having to write "self" in the method definition. This falls out of > item 2: since every function/method has an instance, there's no need to > declare it. I've thought of writing a PEP for this one. Out of curiosity: how does Ruby manages inner classes like this? class MyClass(object): def __init__(self,x): class InnerClass(object): def __init__(innerself,a): innerself.a=a self.b=2*a self.x=InnerClass(x) c=MyClass(1) print c.x.a # =>1 print c.b # =>2 an-ex-enemy-of-self-now-converted-ly-your's Michele From terosaarni at hotmail.com Tue Aug 5 15:08:03 2003 From: terosaarni at hotmail.com (Tero Saarni) Date: Tue, 5 Aug 2003 22:08:03 +0300 Subject: Problem with blocking portably on sockets and Queue? Message-ID: Hi, I have several threads communicating with each other using events stored in Queues. Threads block on Queue.get() until somebody publishes an event in thread's event queue. I need to add support for sockets to the system. Thread needs to unblock when: - there is socket ready to be read, or - there is event waiting in the queue My first tought was to replace blocking on Queue.get() with blocking on poll or select and dedicating file descriptors (created with os.pipe()) as an semaphore. Event publisher would write something to the write end of the pipe when it puts an event to the queue, effectively unblocking the receiver. BUT I noticed that select.poll() is not available on Windows and secondly Windows version of select.select() will accept only socket descriptors. What options do I have that are still portable also to Windows platform? --- Tero From logiplex at qwest.net Mon Aug 4 14:24:53 2003 From: logiplex at qwest.net (Cliff Wells) Date: Mon, 04 Aug 2003 11:24:53 -0700 Subject: wxPython: Default Frame button? In-Reply-To: <33803989.0308040522.2edbd0ec@posting.google.com> References: <33803989.0308030211.10b31e97@posting.google.com> <33803989.0308040522.2edbd0ec@posting.google.com> Message-ID: <1060021493.1518.22.camel@software1.logiplex.internal> On Mon, 2003-08-04 at 06:22, Miki Tebeka wrote: > Hello Cliff, > > > In general, the only child of a frame should be a panel or some other > > container (like a splitter). Frames should generally only have one > > child. Make the button a child of the panel rather than a sibling. > 10x. Works like a charm. > > >class F(wx.Frame): > > def __init__(self): > > wx.Frame.__init__(self, None, -1, "Test Frame") > > panel = P(self) > > self.Fit() > > Is there a default frame that does the above? No. However, you can combine the frame and panel code into a single class if you like: import wx class F(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, -1, "Test Frame") panel = wx.Panel(self, -1) sizer = wx.BoxSizer(wx.VERTICAL) b = wx.Button(panel, -1, "Quit") wx.EVT_BUTTON(panel, b.GetId(), self.on_quit) sizer.AddMany([ (wx.TextCtrl(panel, -1, size = (250, -1), value = "XXX")), (b, 0, wx.EXPAND), ]) panel.SetDefaultItem(b) b.SetFocus() panel.SetAutoLayout(True) panel.SetSizer(sizer) sizer.Fit(panel) self.Fit() def on_quit(self, e): self.Close(True) def main(): app = wx.PySimpleApp() f = F() f.Show(True) app.MainLoop() if __name__ == "__main__": main() Alternatively, you can dispense with creating a custom class for the frame (which is perhaps a bit closer to what you are asking): import wx class P(wx.Panel): def __init__(self, parent, id = -1): wx.Panel.__init__(self, parent, id) sizer = wx.BoxSizer(wx.VERTICAL) b = wx.Button(self, -1, "Quit") wx.EVT_BUTTON(self, b.GetId(), lambda evt: parent.Close(True)) sizer.AddMany([ (wx.TextCtrl(self, -1, size = (250, -1), value = "XXX")), (b, 0, wx.EXPAND), ]) self.SetDefaultItem(b) b.SetFocus() self.SetAutoLayout(True) self.SetSizer(sizer) sizer.Fit(self) def main(): app = wx.PySimpleApp() f = wx.Frame(None, -1, "Test Frame") P(f) f.Fit() f.Show(True) app.MainLoop() if __name__ == "__main__": main() Personally, I prefer to keep objects discrete, especially for panels which might at some point get moved to some other container (say you decide to put a notebook or splitter in the frame), but if you're not concerned about that then these are both valid approaches. Regards, -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 (800) 735-0555 From mpeuser at web.de Sun Aug 17 09:41:44 2003 From: mpeuser at web.de (Michael Peuser) Date: Sun, 17 Aug 2003 15:41:44 +0200 Subject: The Snack Sound Toolkit Message-ID: There is not so much multimedia for Python. So I became quite excited about this nice sound output and manipulation tool. The DLL is not small but it can do a lot of things. Seems that it is in ActiveState's distribution nowadays. http://www.speech.kth.se/snack/ Kindly Michael P From user at invalid.domain Tue Aug 19 03:37:20 2003 From: user at invalid.domain (Invalid User) Date: Tue, 19 Aug 2003 09:37:20 +0200 Subject: decode a url Message-ID: Is there a function/module to decode url's in python? So far, I have come across "urllib.encode" for encoding, which the opposite of I am looking for. From fredrik at pythonware.com Tue Aug 19 17:57:36 2003 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 19 Aug 2003 23:57:36 +0200 Subject: Why does this (not) work? References: Message-ID: Michael C. Neel wrote: > Hmmm, can't say I like what this implies. In one case % is shorthand > for a sprintf function, the other it's a mathematical expression at the > same level of precedence of * and /. But the sprintf version is > "granted" the precedence of the mathematical version? What's the > logic behind that? it's the same "%", and the same "*". consider the expression "a % b * c". using your logic, do you really expect the evaluation order to vary depending on the actual types of the objects a, b, and c? From skip at pobox.com Mon Aug 25 17:01:49 2003 From: skip at pobox.com (Skip Montanaro) Date: Mon, 25 Aug 2003 16:01:49 -0500 Subject: python gripes survey In-Reply-To: <3f4a70e6$0$167$a1866201@newsreader.visi.com> References: <3f4a70e6$0$167$a1866201@newsreader.visi.com> Message-ID: <16202.31037.548305.759911@montanaro.dyndns.org> Grant> ... this is Usenet. No matter what you write, somebody is going Grant> to interpret it as a proposal to cook and eat babies. QOTW if ever I saw one. ;-) Skip From val at vtek.com Sun Aug 10 23:01:21 2003 From: val at vtek.com (val) Date: Sun, 10 Aug 2003 23:01:21 -0400 Subject: Slogan: Getting Rich Overnight Message-ID: Hi Christian, If the slogan concept is set aside for awhile, i independently came to the same/close idea of 'application-specific' or 'enriched' (in the spirit of IPython) command line (CL), a python-based one, of course. The interactive mode you are talking about indeed provides a unique *fast* feedback-driven capabilities for an app analysis and running. I'm working (on and off) on a 'lawyer CL', 'dentist CL', 'project manager CL', etc trying to abstract a generic CL functionality and the limits of the CL concept. A command line in combination with the PythonWin like intellisense and Python help is a very flexible and powerful interactive environment. It may combine a purely CL facilities and quick GUIs fired from CL when necessary. Such a CL may provide an interactive access to rich business objects/methods and their functionality. A standard GUI is a great concept, but it has a fixed structure which may become a highly complicated for real-world apps. A well-designed CL actually splits a potentially huge GUI into manageable and app-specific "time slices" (CL+GUI) driven by the current output of the app. In some cases, a CL can be driven or evolve in a semiautomatic mode displaying (for a user) only pre-specified or dynamically generated critical elements of the application dynamics. Thus, a CL design (business objects accessed and their user control) may be highly flexible comparing with a fully pre-specified (and thus too rigid) program control. So, business objects' power under user fingertips seems to be a powerful concept, indeed. In fact, a living organism' functionality in an environment is split similarly into stimuli (inputs) and responses (outputs); an output, in turn, can represent a (pre-specified) sequence of responses potentially modifiable by the environment (user inputs). This way the virtual/autonomous users/agents can be setup and configured with various degree of decision-making capabilities beginning from simple user models ('beginner') and finishing with sophisticated user models ('expert') with a significant built-in knowledge of the application dynamics and, therefore, potential responses. So, a part of the app processing gets transferred into a user model with control, monitoring, debugging(?) and other 'who-knows' functions. Ok, enough nice dreams.. Interactive-ly y'rs, val ----- Original Message ----- From: "Christian Tismer" Newsgroups: comp.lang.python Sent: Friday, August 08, 2003 10:59 PM Subject: Slogan: Getting Rich Overnight > Dear friends. > > During a conversation with good friends and newly acquired > Pythonista, we were discussing Python, what it is in essence, > and what it is giving to us. > > The people were Dinu Gherman, Giorgio Giacomazzi, > a promising newcomer in the Python noosphere, and myself. > > We were discussing how to advertise for Python, and Dinu > spread some of the recent library enhancements, like > > - email package > - XML parsers > - distutils > - add lots of other great stuff, here. > > Then, after a while of silence, Giorgio said something like > """ > Well, right. > But despite of the libraries, I was hit by pure Python, > by the following, simply by using it interactively: > > There are these lists, these tuples, and these dicts. > They are immediately there, at my fingertips. And this is > a feeling that I never had, before. Especially these dicts > are incredible. > > This was a feeling like 'getting rich overnight'. > """ > > I loved this statement very much, and I have to say, this > is essentially my feeling for myself, since many years now. > I could imagine that this might be a candidate for next year's > Python congress' slogan. "Python makes you rich, overnight". > Not by money, in the first place, but by multiplying your > own capabilities, immediately. > > It needed the fresh experience of a newcomer to become aware > of this, again. > > The ambiguity is obvious. On first reading, it will attract > many. On second reading, those who are thinking "ahh, ohh, yes, > not I understand" will remain. But that's ok for a good slogan! > > got rich overnight by Python! > > being rich since 1800 nights now - sincerely -- chris > > -- > Christian Tismer :^) > Mission Impossible 5oftware : Have a break! Take a ride on Python's > Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ > 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ > work +49 30 89 09 53 34 home +49 30 802 86 56 pager +49 173 24 18 776 > PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 > whom do you want to sponsor today? http://www.stackless.com/ > > > > From dkuhlman at rexx.com Thu Aug 21 13:32:53 2003 From: dkuhlman at rexx.com (Dave Kuhlman) Date: Thu, 21 Aug 2003 10:32:53 -0700 Subject: docutils: ImportError: No module named roman References: <6f03c4a5.0308210640.46504655@posting.google.com> Message-ID: Rim wrote: > Hi, > > ImportError: No module named roman > > What provides the roman module? I can't run docutils/tools since I > upgraded to python2.3. It's in: docutils/extras/roman.py Did you re-run the docutils installation after installing Python 2.3? If you upgraded from Python 2.2, your Python will be installed in a new location (on my Linux GNU/Debian system, in /usr/local/lib/python2.3 instead of /usr/local/lib/python2.2). So, you need to re-install docutils in order to put it in that new location. Dave -- Dave Kuhlman http://www.rexx.com/~dkuhlman dkuhlman at rexx.com From a.neudecker at uni-bonn.de Fri Aug 29 14:20:14 2003 From: a.neudecker at uni-bonn.de (Andreas Neudecker) Date: Fri, 29 Aug 2003 20:20:14 +0200 Subject: Getting class name In-Reply-To: References: Message-ID: > class XXX: > ... > method YYY(self, ...): > ... > print self.__class__.__name__ Is there a similar solution to get the name of the function or method you are currently "in"? Regards Andreas From gh at ghaering.de Tue Aug 26 19:32:24 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Wed, 27 Aug 2003 01:32:24 +0200 Subject: String find and replace In-Reply-To: References: Message-ID: <3F4BEE08.5070302@ghaering.de> hokieghal99 wrote: > import os, string > print " " > setpath = raw_input("Enter the path: ") > def find_replace(setpath): > for root, dirs, files in os.walk(setpath): > fname = files > for fname in files: > find = string.find(file(os.path.join(root,fname), 'rb').read(), > 'THIS') > print find > if find >=1: > replace = string.replace(str, 'THIS', 'THAT') ^^^ In your app, what do you think 'str' is? You haven't defined it, but it still exists. It's the string type, *not* a particular string (cos you haven't defined it). That's why you get the error below: > find_replace(setpath) > print " " > > Why doesn't this work? I get this error: > > Traceback (most recent call last): > File "html_find_replace.py", line 12, in ? > find_replace(setpath) > File "html_find_replace.py", line 11, in find_replace > replace = string.replace(str, 'THIS', 'THAT') > File "/usr/local/lib/python2.3/string.py", line 370, in replace > return s.replace(old, new, maxsplit) > TypeError: expected a character buffer object -- Gerhard From nonotreally999 at yahoo.com Tue Aug 12 23:45:52 2003 From: nonotreally999 at yahoo.com (Tom) Date: 12 Aug 2003 20:45:52 -0700 Subject: Python vs. C# References: <2259b0e2.0308100616.55b651ca@posting.google.com> <3f36af20@shknews01> <3f3959e3_1@news.vo.lu> Message-ID: Patrick Useldinger wrote in message news:<3f3959e3_1 at news.vo.lu>... > Brandon J. Van Every wrote: > > > [...] > > Some time ago, you started a similar discussion on C++ vs. Python. You > pretended to be just as objective, and you turned out to be just as > decided as you are now (funny, isn't it ?). > > So what the heck is the purpose? I cannot help but think that you are > just bored. Maybe 3D-programming isn't that interesting after all ... > > -Patrick Quite right, Patrick. For anyone who hasn't seen the old C++ threads and might still think that Mr. Van Avery is a non-Troll, please do a search, read his old C++ stuff and make your own judgement. I think it's a 'slam-dunk'. The only reason I have bothered posting about this is that I think valuable c.l.p. cycles are being wasted and the generosity and open-mindedness of the c.l.p. community are being taken advantage of by someone who appears to be, as Patrick noted, "just bored". Sorry to be harsh, Mr. Van Avery. I have a suggestion, though. I think you've chosen the wrong group to play in. I think you should read a book about Lisp (maybe even two) and then share your thoughts with the comp.lang.lisp folks. Lisp is a really neat language (not sure but maybe there's a Lisp.NET to explore!!!) and the c.l.l. folks will be really interested in your insights. I think you and Erik will hit it off big time. End of rant. Don't feed trolls. From op73418 at mail.telepac.pt Wed Aug 6 18:22:14 2003 From: op73418 at mail.telepac.pt (Gonçalo Rodrigues) Date: Wed, 06 Aug 2003 23:22:14 +0100 Subject: Bug? If not, how to work around it? References: <060820031458029244%mday@apple.com> Message-ID: On Wed, 06 Aug 2003 14:58:02 -0700, Mark Day wrote: >In article , Gon?alo >Rodrigues wrote: > >> >>> class Test(object): >> ... def __init__(self, obj): >> ... self.__obj = obj >> ... def __getattr__(self, name): >> ... return getattr(self.__obj, name) >> ... >> >> Now: >> >> >>> a = Test([]) >> >>> a.__iter__ >> >> >>> iter(a) >> Traceback (most recent call last): >> File "", line 1, in ? >> TypeError: iteration over non-sequence >> >>> >> >> Is this a bug? If not, how to code Test such that iter sees the >> __iter__ of the underlying object? > >I'm guessing that iter() is looking for an __iter__ attribute without >going through __getattr__ to find it. So, I tried adding the following >method to the Test class: > > def __iter__(self): > return self.__obj.__iter__ > >but that returned the following error: > >TypeError: iter() returned non-iterator of type 'method-wrapper' > You forgot the parenthesis. >I changed the __iter__ method to the following, and it seems to do what >you want: > > def __iter__(self): > return iter(self.__obj) > But this is precisely what I don't want to do. With my best regards, From fatherbob70 at yahoo.com Wed Aug 27 16:12:44 2003 From: fatherbob70 at yahoo.com (Rob Andrews) Date: Wed, 27 Aug 2003 20:12:44 GMT Subject: homebrew 2.3 install on RedHat9 not playing nice with Tkinter Message-ID: <0h83b.953$8v3.90271@twister.austin.rr.com> I'm on a Red Hat 9 system, which has Python 2.2.2 installed, and I installed 2.3 separately into /home/rob/Python-2.3/ (creating the symbolic link "py23" to point to my 2.3 installation). Now I'm trying to work out the kinks in the process. Unable to run Idle using 2.3 the way I've got things set up, I created a super simple Tkinter test program that just pops up a Label widget. I pasted below an example of how the RH-provided 2.2 runs the script without incident, but running the script with 2.3 produces a traceback. If someone can help me see the error of my ways, I'll be most appreciative. [Wed Aug 27][03:01 PM] ~/Python-2.3/test $ python -V Python 2.2.2 [Wed Aug 27][03:04 PM] ~/Python-2.3/test $ py23 -V Python 2.3 [Wed Aug 27][03:01 PM] ~/Python-2.3/test $ py23 test2.py Traceback (most recent call last): File "test2.py", line 1, in ? from Tkinter import Label File "/home/rob/Python-2.3/Lib/lib-tk/Tkinter.py", line 38, in ? import _tkinter # If this fails your Python may not be configured for Tk ImportError: No module named _tkinter [Wed Aug 27][03:01 PM] ~/Python-2.3/test $ python test2.py -Rob (mediocre with Python, incompetent with linux) From gregbrunet at NOSPAMsempersoft.com Fri Aug 22 16:29:08 2003 From: gregbrunet at NOSPAMsempersoft.com (Greg Brunet) Date: Fri, 22 Aug 2003 15:29:08 -0500 Subject: __getattr__ weirdness References: Message-ID: "Stephan Diehl" wrote in message news:bi5ofn$uo3$04$1 at news.t-online.com... > Within the __getattr__ method, you can't just do normal attribute access as > this will trigger another call to __getattr__, so you where stuck in an > infinite loop. > try to access the required attribute directly from the __dict__ > > def __getattr__(self, key): > """ Return DBF record values by field name """ > print "_ga: " + key > try: > # return self._rec[self._fldNames.index(key.upper())] > ^^^^ > return self.__dict__['_rec'][self._fldNames.index(key.upper())] > except: > raise AttributeError("Unknown Field: %s" % ( key )) > > Hope that helps > > Stephan Hey Stephan: That did the trick! Actually, I had to do the same for self._fldNames as well. Also, I changed them in the _sa code section instead of the _ga code, since now that I look at it again with a little better understanding, the original _sa code was referring to the _rec & _fldNames variables/attributes directly, so as long as they weren't defined, it was triggering the _ga calls. So now the _ga code doesn't get called unless I specifically ask for it - like I would want. The code now looks like: #---------------------------------------- def __getattr__(self, key): """ Return DBF record values by field name """ print "_ga: " + key try: return self._rec[self._fldNames.index(key.upper())] except: raise AttributeError("Unknown Field: %s" % ( key )) #---------------------------------------- def __setattr__(self, key, val): """ Update DBF record values by field name """ print "_sa: %s: %s" % (key, val) try: self.__dict__['_rec'][self.__dict__['_fldNames'].index(key.upper())] = val print " (DBF field assignment)" except: self.__dict__[key] = val # use the regular variable! #raise AttributeError("Unknown Field: %s" % ( key )) Thanks for everyone's help! -- Greg From aleax at aleax.it Thu Aug 7 17:04:47 2003 From: aleax at aleax.it (Alex Martelli) Date: Thu, 07 Aug 2003 21:04:47 GMT Subject: crossplatform py2exe - would it be useful? References: <3cgdfnzo.fsf@python.net> Message-ID: Thomas Heller wrote: ... >> Ah, yes, good point. So, the executable needs to know whether to do >> the usual commandline and environment processing, or not, _before_ >> calling Py_Inizialize. > > Exactly. And it may even be useful to do specail command line > processing, an PY2EXEVERBOSE flag might be useful. I guess it might, yes. >> One approach might be to trigger this based >> on the executable's own *name* -- do the full commandline and environment >> processing if and only if the executable's name starts with (case- >> insensitive, probably, to be safe...) the six letters 'python', but >> not otherwise. There are, no doubt, other alternative ways, too, but >> this one seems dirt-simple and practically sufficient. > > On windows, where the interpreter is in a dll, providing a custom > equivalent to python.exe (as py2exe currently does) is pretty simple. > On systems where the interpreter is staically linked, there's no other > choice than to recompile and relink the whole pythonm if I understand > correctly. Python 2.3 now supports building a .so (or whatever) on many systems, needing just a switch on ./configure. If one chooses to go for a static build anyway, sure, one will have to link statically. But no recompile and relink would be needed (unless 'pythonm' is something I don't know about rather than just a typo for 'python'...?). E.g., on Linux: $ cat main.py print "Hello world" $ python -c 'import main' Hello world $ zip main main.pyc adding: main.pyc (deflated 31%) $ cp /usr/local/bin/python2.3 ./myapp $ cat main.zip >>myapp $ ./myapp -c 'import sys; sys.path.insert(0,"myapp"); import main' Hello world $ So, if I could just insert that "-c string" into myapp in some way -- and have myapp, which is just a copy of the python 2.3 interpreter, execute it in some way instead of the arguments [leaving the arguments to use for sys.argv] -- I'd be in clover, quite indifferently as to whether myapp is statically OR dynamically linked. Admittedly at this level it doesn't work with __main__, as Oren suggested ('import __main__' is a noop unless one deletes sys.modules['__main__'], and if one does it's "ImportError: Cannot re-init internal module __main__"). Which is why I've reverted to 'main' without underscores;-). Anyway, the zipfile would of course be prepared in much more sophisticated (but presumably platform independent?) ways, and the suitable string (including e.g. a -O or whatever) could be inserted (by a py2exe tool or the like) into a suitable config area in the executable, as Oren suggested. >>> And I hope that the options set by the command line flags and env vars >>> should now come from the __main__ script itself. >> >> I'm not sure I understand what you mean. Anyway, I do see that if >> my 'foobar.exe' is a python.exe + appended zipfile, then running >> 'foobar -i' should just put '-i' in sys.argv[1], and NOT gobble it up >> to mean "enter interactive mode", for example. > > You understood. Yes, the command line flags must be passed into > sys.argv. But I still want to set the optimize flag and the unbuffered > flag at *build* time. I'm quite sure all this cannot be encoded into the > filename. Right. But it COULD easily be encoded in a "configuration area". > Right now, py2exe embeds a struct containing a magic value plus these > flags into the exe, just before the zip-archive, but all this unpacking > has to be done from C code (because these flags are not writable from > Python code), so all this has to be part of the hook. Oh yes, it surely would need to be part of the hook. > Thomas > > PS: Since py2exe, even on Linux, doesn't really create a single file > executable, there are always some shared libs needed, maybe the first > step would be to create a directory containing the interpreter > executable with an appended ziparchive, the shared libs needed (zlib.so, Perhaps this step could be left to a separate tool (basically we're talking about a self-unpackaging zipfile, it seems to me). > maybe more), and a bash script containing something like this (you'll > probably see how rusty my *nix skills are nowadays): > > #!/bin/sh > exec python_with_zip -c "< the script itself > " > EOF > > > What are the disadvantages of a shell-script against an (elf) executable? For example, a shell script cannot be set-userid (it wouldn't be secure). Alex From pythonguy at Hotpop.com Wed Aug 13 06:37:37 2003 From: pythonguy at Hotpop.com (Anand Pillai) Date: 13 Aug 2003 03:37:37 -0700 Subject: FTP with urllib2 behind a proxy References: <7d6b0b33.0308070304.53588bf0@posting.google.com> <87d6feykl8.fsf@pobox.com> Message-ID: <84fc4588.0308130237.69d480a1@posting.google.com> You need to install a proxyhandler, authhandler, ftphandler and httphandler. Then build yourself an opener, that opens the doors for you ... :-) The following does the trick. proxy_handler = urllib2.ProxyHandler( {'http': 'myhttpproxy:80', 'https' : 'myhttpsproxy:443', 'ftp' : 'myftpproxy:21' } ) opener= urllib2.build_opener(proxy_handler, urllib2.HTTPBasicAuthHandler(), urllib2.HTTPHandler, urllib2.HTTPSHandler, urllib2.FTPHandler) # install this opener urllib2.install_opener(opener) # Go ahead, knock knock! req=urlli2.Request('ftp://ftp.gnu.org') data=urllib2.urlopen(req).read() Of course, replace the arbit proxy values I wrote with your proxy values. If your proxy need authentication , you will need to do a bit more here. proxyauth='http://' + username + '@' + password + 'myproxy:myproxport' Then your proxy handler becomes ( I am assuming a generic proxy for all protocols here!) proxy_handler = urllib2.ProxyHandler ( {'http' : proxyauth, 'https' : proxyauth, 'ftp' : proxyauth } ) HTH. -Anand jjl at pobox.com (John J. Lee) wrote in message news:<87d6feykl8.fsf at pobox.com>... > Zappelphillip at gmx.de (O. Koch) writes: > > > Until now, i know that ftplib doesn't support proxies and that i have > > to use urllib2. But i don't know how to use the urllib2 correct. I > > found some examples, but i don't understand them. > > > > Is there anyone who can help me? > > import urllib2 > response = urllib2.urlopen("ftp://ftp.example.com/pub/myfile") > data = response.read() > response.close() > > > Does that do the trick? > > > John From adalke at mindspring.com Wed Aug 27 19:00:35 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Wed, 27 Aug 2003 23:00:35 GMT Subject: how fast is Python? References: Message-ID: Steven Taschuk: > A bit off-topic perhaps, but I'd be interested in the details of > [your] anecdote. Okay. I know someone who really likes optimized programming. The kind of person who will develop an in-memory compiler to generate specialized assembly for the exact parameters used, thus squeezing out a few extra cycles. He works in a C++ company. They used an idiom, the details of what I don't know. Most people wouldn't use that idiom because it didn't translate well to assembly, but the compiler in theory could figure it out. He submitted a patch to do that optimization. It was originally rejected because they couldn't see that anyone would write code that way. He dug around in gcc itself to find some place which used that code, to show that it is used. It was accepted. Moral: it's easier to change the technical details (gcc) than the social ones (getting people to use a better idiom). That's about all I know of the story. Andrew dalke at dalkescientific.com From timfm at hawaii.rr.com Fri Aug 1 18:34:06 2003 From: timfm at hawaii.rr.com (Timothy Martens) Date: Fri, 01 Aug 2003 12:34:06 -1000 Subject: Python Windows 2.3 Installer problems Message-ID: <3F2AEADE.8030706@hawaii.rr.com> When I run the Python-2.3.exe on my WIN2K box and go through the initial dialogues, the installer frezes at 1% when it's "Copying File C:\Python23\UNWISE.exe" Any ideas ANYONE? tim. From dreico at wanadoo.fr Sat Aug 30 15:20:35 2003 From: dreico at wanadoo.fr (Andrei) Date: Sat, 30 Aug 2003 21:20:35 +0200 Subject: cannot get pexpect to work References: <3F4F6AF0.CA9BB337@engcorp.com> <3F4F9152.ABC73E49@engcorp.com> <3F4FC7A6.37CF2C3@engcorp.com> Message-ID: "Peter Hansen" wrote in message news:3F4FC7A6.37CF2C3 at engcorp.com... > Best solution: this is Python (!), so just start up an interactive > session and type the relevant commands yourself, based on what you > see in pexpect.py. Not only will you solve the problem, but you'll > end up with a much better understanding of pexpect.py and the passmass.py > script as well. An interactive session certainly did the trick. >>> child = pexpect.spawn('ssh lxplus003 uptime') >>> try: ... child.expect('password:') ... print "problem encountered, password needed" ... except Exception: ... print "ok no passwd required" ... 0 problem encountered, password needed I still haven't figured out why passmass.py isn't finishing and indeed times out yet, but a basic understanding of pexpect is now creeping up on me, and how it could help my project. Thanks, A. From mpeuser at web.de Fri Aug 15 03:42:57 2003 From: mpeuser at web.de (Michael Peuser) Date: Fri, 15 Aug 2003 09:42:57 +0200 Subject: GUI builder for Python References: Message-ID: Hi Henry, there is a discussion of this topic from time to time - every week I should say ;-) Everything depends on the GUI-Toolkit you have selected: Tkinter? PyQt? wxPython? Or an even more exotic one like FOX, FLTK, GTK+ or PyUI? There are some commercial GUI Builders out of the normal budget. Free ones are Black Adder for Qt, BoaConstructor for wx and some stuff like PAGE or SpecTIX for TIX. Kindly Michael P "henry" schrieb im Newsbeitrag news:nx%_a.730754$3C2.17094058 at news3.calgary.shaw.ca... > Hi, > > Just wondering if there's a good GUI builder for Python. Something like > Visual Tcl, where you just drag and drop objects. > > Not too good with creating user interfaces from code along. > > Thanks > From tonym1972/at/club-internet/in/fr Wed Aug 13 06:38:07 2003 From: tonym1972/at/club-internet/in/fr (Anthony McDonald) Date: Wed, 13 Aug 2003 12:38:07 +0200 Subject: bsddb.btopen() Message-ID: <3f3a1387$0$9624$7a628cd7@news.club-internet.fr> PythonWin 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] on win32. Portions Copyright 1994-2001 Mark Hammond (mhammond at skippinet.com.au) - see 'Help/About PythonWin' for further copyright information. >>> import os >>> import bsddb >>> os.chdir("c:/test") >>> my_data = bsddb.btopen("testing", 'c') >>> for i in range(10): ... if i == 5: ... pass ... else: ... my_data['%d'%i] = '%d'% (i*i) ... >>> my_data.keys() ['0', '1', '2', '3', '4', '6', '7', '8', '9'] >>> my_data.sync() Now heres where my problem is. The documentation explicitly states that a btopen database when asked to locate a key that doesn't exist in the dataset, will return the next sorted key from the dataset. So my_data.set_location('5') should return as if I'd called my_data.set_location('6') >>> my_data.set_location('5') Traceback (most recent call last): File "", line 1, in ? File "C:\Python23\lib\bsddb\__init__.py", line 117, in set_location return self.dbc.set(key) DBNotFoundError: (-30991, 'DB_NOTFOUND: No matching key/data pair found') Okay maybe it has positioned the cursor, but is just raising the exception to politely tell me that I'm not pointing at the key I asked for. So my_data.previous() will return the key/data pair for key "4". >>> my_data.previous() ('9', '81') Okay its pointing at the end of the database. Erm thats not as advertised. Okay whats broken? Is the documentation wrong? Is my version of Python wrong?, or do I need to drink some more coffee? TonyM From aleax at aleax.it Fri Aug 29 10:14:50 2003 From: aleax at aleax.it (Alex Martelli) Date: Fri, 29 Aug 2003 14:14:50 GMT Subject: howto format currency string? References: <8oH3b.15528$d66.362183@news2.tin.it> Message-ID: Peter Otten wrote: ... >>>> locale.setlocale(locale.LC_ALL, 'de') > Traceback (most recent call last): > File "", line 1, in ? > File "locale.py", line 381, in setlocale > return _setlocale(category, locale) > locale.Error: locale setting not supported >>>> > > The second (not working) variant is taken directly from the documentation. > The error message led me to assume that my version of Python didn't > support locale setting at all. > > Maybe I should file a bug report? Yes, I believe that the error message is potentially misleading, and filing a bug report is a good way to have it fixed ASAP, thanks. Alex From john at rygannon.com Sun Aug 24 07:44:31 2003 From: john at rygannon.com (BadJake) Date: Sun, 24 Aug 2003 11:44:31 GMT Subject: ANN: BlackAdder V1.0.0 Message-ID: <3f48a498$3$219$fa0fcedb@lovejoy.zen.co.uk> BlackAdder is an application development environment that allows professional and hobbyist programmers alike to produce complex applications for the Windows and Linux platforms. BlackAdder brings together the Python programming language, the Qt graphical user interface (GUI) toolkit, ODBC database connectivity and an Integrated Development Environment (IDE) that includes an editor, a GUI designer, a debugger and an interactive Python interpreter. BlackAdder gives the programmer, in a single package, all they need to develop sophisticated applications. Key Features A complete cross-platform Integrated Development Environment for developing GUI applications in Python. You don't need anything else. Applications run unchanged under Windows and Linux. Protect your investment in your development. Personal and Business Editions. The Business Edition includes optional support and the rights to distribute the run-time elements with your application at no extra charge. A limited functionality, freely available demonstration version can be downloaded from http://www.totalrekall.co.uk or http://www.rygannon.com Detailed Features Organises your Python and Ruby scripts and GUI designs into easy to manage projects. An editor that includes highlighting of Python keywords, code folding, automatic indentation, and user configurable fonts and colors. An interactive Python interpreter (v2.2.x) that allows you to execute any Python commands while your application is running. The Professional version of the Qt GUI toolkit (v3.x) including: the Canvas module the Table module the Database module QSocket, QServerSocket, and Qhost Address classes from the Network module. A GUI designer with all the features of Qt Designer and generates Python code. A debugger that supports single stepping and breakpoints and the display of local and global objects in any active Python or Ruby frame. ODBC database connectivity (using mxODBC v2.0, see ). 10mb of PyQt documentation with lots of examples and two tutorials, this is also available as a stand alone product called PyDoc All that in a fully integrated IDE environment. Personal Edition Features For home use. Includes Windows and Linux versions. Optional subscription service to receive updates. Informal mailing list support. Business Edition Features For commercial use. Includes Windows and Linux versions. Optional subscription service to receive updates. Optional formal email support. Includes the rights to distribute the run-time elements (except mxODBC) with your application. BlackAdder Developer Network The optional subscription service called BlackAdder Developer Network provides you with up to 4 annual updates of your BlackAdder version. Stay up to date with the latest updates and improvements with the Developer Network, available in packages for personal and business use. Requirements BlackAdder requires Python version 2.2.x. Pricing and Availability BlackAdder Personal Full Version: $79.99 Black Adder Developer Network Personal: $59.99 per year ($39.99 if purchased during the Beta period) BlackAdder Business Full Version: $399.99 Black Adder Developer Network Business: $299.99 per year ($199.99 if purchased during the Beta period From anthonyr-at-hotmail-dot-com at nospam.com Wed Aug 27 23:36:39 2003 From: anthonyr-at-hotmail-dot-com at nospam.com (Anthony Roberts) Date: Thu, 28 Aug 2003 03:36:39 GMT Subject: Style question... References: <3F4D637B.7ADB0BC4@alcyone.com> Message-ID: > C-c < and C-c >. Thanks. :) BTW: I've had your website bookmarked since 2001 because a number of the things there are useful and cool. From abelikov72 at hotmail.com Fri Aug 22 22:03:09 2003 From: abelikov72 at hotmail.com (Afanasiy) Date: Sat, 23 Aug 2003 02:03:09 GMT Subject: Sort a Dictionary Message-ID: This is fairly simple in PHP, how do I do it in Python? http://www.php.net/manual/en/function.ksort.php From parente at cs.unc.edu Sat Aug 23 10:28:50 2003 From: parente at cs.unc.edu (Peter Parente) Date: 23 Aug 2003 07:28:50 -0700 Subject: Keystroke logger for Windows References: Message-ID: <85b6a599.0308230628.49ba3c74@posting.google.com> I have a Python library that can capture system wide keystrokes and mouse events. Basically, the windows hooking code is in a C Python extension that passes callback information back to Python when an event occurs. I'll post it to our Python tools sourceforge site in the near future. (I need to clean it up a bit and provide an example before it will be the least bit useful to you.) When it's posted, it will appear at http://sourceforge.net/projects/uncpythontools/ as the pyHook project. Pete hokieghal99 wrote in message news:... > Does anyone know of a keystroke logger that has been written in Python > for Windows machines? I'd like to see such a script and use it as a > point of reference for a real-time backup project that I'm working on. > Basically, I'd like to be able to capture all keystrokes from the > keyboard buffer and write them to a text file so I could reporduce > emails, documents, etc. in the event of file loss that occurs between > nightly backups. For example, my boss comes to me, he has deleted an > email that he was writing... he has been working on the email all day... > and he expects me to wave a magic wand and bring it back. > > Thanks for any advice, code or pointers. Also, if Python isn't suited > for this, let me know and I'll look at doing this in c From mwh at python.net Thu Aug 14 08:11:01 2003 From: mwh at python.net (Michael Hudson) Date: Thu, 14 Aug 2003 12:11:01 GMT Subject: CLI+GUI References: <2259b0e2.0308080948.5a95e383@posting.google.com> Message-ID: <7h365l05tli.fsf@pc150.maths.bris.ac.uk> mis6 at pitt.edu (Michele Simionato) writes: > I wonder what is the recommended way of using Tkinter > together with a command line oriented application. > I have in mind something like that: [...] Um. I'm coming to this thread late, but my pyrepl package works quite nicely with Tkinter programs (on Unix, anyway). $ pythoni Python 2.2.1 (#1, Apr 9 2002, 13:10:27) [GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-98)] on linux2 Type "help", "copyright", "credits" or "license" for more information. ->> import Tk Traceback (most recent call last): File "", line 2, in ? ImportError: No module named Tk ->> import Tkinter ->> root = Tkinter.Tk() ->> label = Tkinter.Label(root, text="hi!") ->> label.pack() ... just like the native toplevel (which isn't surprising, as that's where I cribbed the code from). HTH, mwh -- QNX... the OS that walks like a duck, quacks like a duck, but is, in fact, a platypus. ... the adventures of porting duck software to the platypus were avoidable this time. -- Chris Klein, alt.sysadmin.recovery From dbrown2 at yahoo.com Wed Aug 13 16:29:21 2003 From: dbrown2 at yahoo.com (dbrown2 at yahoo.com) Date: 13 Aug 2003 13:29:21 -0700 Subject: help for using msvcrt.kbhit() with Python 2.3 editors? Message-ID: I'm having some trouble using kbhit inside the editor enviroments. I'm using win2000 with Python2.3 and win32all v157 versions. Any pointer on how this should be handled would be appreciated. Is there another non-blocking way to detect a key press? Here's the code that is causing the trouble. If I run this by double-clicking then it works as expected. But if I run from IDLE or PythonWin it basically never returns. msvcrt.kbhit() always returns 0 as far as I can tell by adding print statements. I can't confirm it but I seem to recall this worked at least with the PythonWin editor environment under my previous Python 2.2 setup. ########### import serial # access to serial port import time # sleep command import msvcrt # detect keyboard key press events ser = serial.Serial(0, 4800, timeout=0.25) data = '' while not msvcrt.kbhit(): buf = ser.read(10) if buf <> '': print buf #time.sleep(1) data = data + buf # concatenate buf onto data ser.close() ########### -- David From irmen at -NOSPAM-REMOVETHIS-xs4all.nl Thu Aug 7 12:56:58 2003 From: irmen at -NOSPAM-REMOVETHIS-xs4all.nl (Irmen de Jong) Date: Thu, 07 Aug 2003 18:56:58 +0200 Subject: MSVC 6.0 Unsupported? In-Reply-To: References: <3F302764.8010301@ghaering.de> Message-ID: <3f3284d8$0$49098$e4fe514c@news.xs4all.nl> Syver Enstad wrote: > But Gerhard, what can I do? Every python extension that I will try to > compile will fail if it depends on a working staticforward. The most > rational thing to me is to patch object.h instead of patching every > .cpp/.c file that needs this define. Can't you just add a single compiler option (for cl.exe) to your project? /Dstaticforward=extern wouldn't that work? --Irmen From s0199583 at sms.ed.ac.uk Thu Aug 14 09:02:26 2003 From: s0199583 at sms.ed.ac.uk (Matt Smith) Date: 14 Aug 2003 06:02:26 -0700 Subject: 3 new slogans References: <3F3B5F80.3E7DE934@hotmail.com> Message-ID: <5f5c82ec.0308140502.36af5ce6@posting.google.com> Alan Kennedy wrote in message news:<3F3B5F80.3E7DE934 at hotmail.com>... > Graham Fawcett wrote: > > > or, with apologies to Clarke, > > > > "Any sufficiently advanced technology is indistinguishable from Python" > > I *really* like this one. > > Only problem is, you have to be a sci-fi head to get it: No problem > for me: I've been reading Arthur C. Clarke since I was 8 years old. > > regards, those all suck, how about..... Get wrapped up in python nah thats shit too, emmm how about..... Python is your daddy no equally shit how about..... The high level programming language in front is Python... oh dear...think i might just leave it there.. ;P matt. From chris at no.spam Thu Aug 28 09:03:59 2003 From: chris at no.spam (Chris Q) Date: Thu, 28 Aug 2003 14:03:59 +0100 Subject: slow progress with IDE's ... Message-ID: <1062075845.449417@adsl> hello list. i'm newish to python - i have written a program involving win32com and wxPython, and making progress... but not as much as i had expected! for starters i have yet to find an adequate means of discovering class methods (and onwards through inheritance) through either the IDLE or pythonwin ide's. given the degree of introspection possible, and with docstrings too, is there no tool yet to point-and-click through a piece of source code to discern what methods are available, their 'def xyz(...)' beginnings, and their description? are my expectations running ahead of reality? my next difficulty stems from, admittedly my own poor code, the regular occurrence of windows C++ library failure messages which wipes out completely my IDE (idle and pythonwin) - if i was not so keen to run my code immediately, then i should be forced to run the debugger every change i made to be certain not to lose a dozen open editing windows! is it me or the IDE at fault here? another thing is breaking into looping code - how the hell is it done? if i run BaseHTTPServer.HTTPServer.serve_forever() under IDLE, for instance, i can close the interactive window but re-running the module causes a complete hang, which only the windows task manager can deal with, again with the loss of the entire IDE. with pythonwin even the interactive window is not amenable to closing and Control-C does not work. GUI code gives the same trouble. i do not seem to have reached the 'comfort zone' of developing with python. any recommendations welcome on best development setup/efficient development habits on windows w2k platform, issues not covered by the python tutorials i have seen. thanks chris From mpeuser at web.de Sun Aug 17 03:48:15 2003 From: mpeuser at web.de (Michael Peuser) Date: Sun, 17 Aug 2003 09:48:15 +0200 Subject: cPickle alternative? References: <3f3de5af-3dcdcb9a-e4f8-43c2-a49e-2e5009909839@news.szn.dk> Message-ID: This a highly interesting product - I for sure shall come back to it when I have to store more data... Kindly Michael P "Klaus Alexander Seistrup" schrieb im Newsbeitrag news:3f3de5af-3dcdcb9a-e4f8-43c2-a49e-2e5009909839 at news.szn.dk... > Drochom wrote: > > >> import cPickle > >> > >> plik = open("mealy","r") > >> mealy = cPickle.load(plik) > >> plik.close() > > > > this takes about 30 seconds! > > How can I accelerate it? > > Perhaps it's worth looking into PyTables: > > > > > Cheers, > > // Klaus > > -- > ><> unselfish actions pay back better From essai1 at mci.local Wed Aug 27 16:31:29 2003 From: essai1 at mci.local (News M Claveau /Hamster-P) Date: Wed, 27 Aug 2003 22:31:29 +0200 Subject: Copying a PIL image to windows clipboard? References: <10ebb92.0308211823.6fe428f7@posting.google.com> Message-ID: Hi ! I have pb with... My code : import Image,ImageGrab buffer = ImageGrab.grab() And result : Traceback (most recent call last): File "D:\dev\python\ess.py", line 1, in ? import Image,ImageGrab File "C:\PYTHON22\Lib\site-packages\PIL\ImageGrab.py", line 32, in ? import _grabscreen ImportError: No module named _grabscreen Other PIL's fonction run OK. Oups ! I remember : Python 2.2 & PIL 1.1.4 An idea ? Thanks. And sorry for my poor english. @+ -- Michel Claveau From john at rygannon.com Sat Aug 9 18:01:38 2003 From: john at rygannon.com (john at rygannon.com) Date: Sat, 9 Aug 2003 23:01:38 +0100 Subject: ANNOUNCE: Rekall V2.0.2 Message-ID: <003501c35ec1$cf1a6b20$0501a8c0@sun.thekompany.co.uk> Hi I would like to take this opportunity to announce the release of Rekall for Windows and Linux. Rekall is an attempt to produce an application to rival Microsoft Access, without the huge price tag. With Rekall you can produce full blown applications. Rekall's programmability and power comes through the use of Python. There is also a Run Time version of Rekall which allows you ship your Rekall application to your customers. Rekall includes a syntax highlighting editor and a debugger. You can import and export data and table structures to and from all the databases supported by Rekall. Included in the standard package are drivers for MySQL, xBase and PostreSQL. You can get drivers for DB2, ODBC and Oracles separately from us at a fraction of the cost of buying from the big vendors. Why not take a Rekall Demo out for a test drive. Our demos are fully functional with a 60 minute time limitation (the Windows demo has a 15 day time limit), but they will run again. You can find the demos on either of two web sites, http://www.rygannon.com and http://www.totalrekall.co.uk Regards John From jorolat at msn.com Fri Aug 1 08:57:23 2003 From: jorolat at msn.com (John Latter) Date: Fri, 01 Aug 2003 13:57:23 +0100 Subject: Problem with Unzipping/Installing Python-2.3.exe Message-ID: Hi, I downloaded Python-2.3.exe but when I used winzip it kept asking me if I wanted to replace old files with new ones, and in some instances, new files with old ones. I've never downloaded/installed Python before, and as something of a computer novice, would like to know what I may be doing wrong! This is the link I downloaded from: >Windows users should download the Windows installer, Python-2.3.exe >, run it and follow the friendly instructions on the screen to complete >the installation. which is on this page; http://www.python.org/2.3/ Hope someone can help! -- John Latter Model of an Internal Evolutionary Mechanism (based on an extension to homeostasis) linking Stationary-Phase Mutations to the Baldwin Effect. http://members.aol.com/jorolat/TEM.html 'Where Darwin meets Lamarck?' Discussion Egroup http://groups.yahoo.com/group/evomech From nhodgson at bigpond.net.au Tue Aug 12 04:52:02 2003 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Tue, 12 Aug 2003 08:52:02 GMT Subject: Is Python your only programming language? References: Message-ID: Joe Cheng: > I want to ask you hard-core c.l.p Pythonistas: Do you use Python for > everything? At work I mostly use Python but with some SQL and other bits and pieces including Java. At home the main language is C++ as libraries that are destined to be used from many languages are easiest accessed through a C interface and performance is important. Neil From nicodemus at globalite.com.br Sat Aug 23 16:48:45 2003 From: nicodemus at globalite.com.br (Nicodemus) Date: Sat, 23 Aug 2003 17:48:45 -0300 Subject: large-scale app development in python? In-Reply-To: <20030822144228.GA8130@core.realtime.sk> References: <20030822144228.GA8130@core.realtime.sk> Message-ID: <3F47D32D.3030905@globalite.com.br> Hi Gabor, gabor wrote: >hi, > > >or python simply isn't suited to write bigger (more complex) apps? > In our company, we work with scientific software, mostly in the area of oil extraction. Our applications were being developed only in C++, and since the beginning of the year, we have switched to a Python/C++ approach, and we are *very* impressed. Our applications are being developed *much* quickly, features can be added very fast, and the Python code is at least 1/5th of the equivalent C++ code. Plus, thanks to Python simplicity and elegance, the code is much more readable and easy to understand. We implement the heavy duty processes in C++, and export those to Python using Boost.Python, and the performance is just great, ie, we can't see any difference between an application written entirely in C++ and other in Python/C++. We were a little worried that our application would be slower because of Python, but that just didn't happen, and more and more code that we thought we would have to implement in C++ ended up being implemented in Python anyway. We have a limited use of unit tests (we're still adapting to that), but event then we have very few of the problems you mentioned, like changing the name of method. And I'm confident that this problems would disappear if we could count on a comprehensive test suite. So, in practice, this is not a problem at all. In our experience, Python is more than suitable to develop large-scale applications. 8) Regards, Nicodemus. From peter at engcorp.com Mon Aug 18 17:05:16 2003 From: peter at engcorp.com (Peter Hansen) Date: Mon, 18 Aug 2003 17:05:16 -0400 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: <3F41208F.40021A68@engcorp.com> Message-ID: <3F413F8C.47AAE514@engcorp.com> John Roth wrote: > > "Peter Hansen" wrote: > > What is it about code blocks that would let "save *me* a buttload of work > > and make *my* life sooooo much easier"? > > It's not so much code blocks. It's that Ruby's syntax gives you one code > block for > free in every method call. And the Ruby library is organized so that the > facility > is useful, which Python's isn't (or at least, it isn't as useful.) > > All of the Ruby collections implement a .each method, which is essentially > a version of the Visitor pattern. If I want to do something to every element > in a list or a dict (or any kind of collection,) all I have to do is say > something > like (using Python syntax): > > collectObj.each() > > In Python, that's either a lambda (which restricts what you can do with it,) > or a named function (which is overkill a huge amount of the time.) And you > have to worry about distinctions between functions and methods. In other > words, it's a mess compared to Ruby. > > Now, you can say: "We've got that with map()." Well, we've got it when > your inputs are either lists (or implement the correct protocol) but the > result is a list, it's not an internal modification to the object's state. > > You can also say: we can do that with for. Well, duh. For is a > statement, not a method call. So what you seem to be saying is that Ruby has some features which in some cases can save some time or somewhat simplify code that when written in Python would take slightly longer or be slightly more complicated. (This probably underemphasizes the value you place on such a thing, but I think that's the gist of it.) While I do acknowledge that Python is often touted as a great solution over other languages just because it saves time and simplifies the resulting solutions, I'm not clear on why these few small differences would amount to a *TOTALLY COMPELLING* reason, to anyone, to use Ruby over Python. -Peter From cjw at sympatico.ca Wed Aug 13 07:46:58 2003 From: cjw at sympatico.ca (Colin J. Williams) Date: Wed, 13 Aug 2003 07:46:58 -0400 Subject: random value generation In-Reply-To: References: Message-ID: Brandon Michael Moore wrote: > I'm trying to test a web application using a tool written in python. I > would like to be able to generate random values to put in fields. I would > like to be able to generate random dates (in a specified range), random > strings (specifying allowed characters and a distribution of lengths), or > choose randomly between several generators (for better control of the > distribution of values). > > Is there any library for this sort of thing in Python? I've started a > library heavily based off the generators of Haskell's QuickCheck library, > that represents generators as objects with a generate() method, with > constructor parameters (maybe other generators) the control the resulting > distribution. > > I've got Choose that takes a list of generators and chooses between them > (with random.choice), GMap that maps a function over the output of another > generator, Choice that chooses an element from a list, Expo that wraps > random's expovariate, and List that takes a number generator and an > element generator and generates lists with lengths drawn from the first > generator and elements drawn from the second, and String that's like List > but joins the resulting list with ''. > > I can use these classes like Choice(['red','blue','green']), or > String(Expo(1.0/3),Choice(string.lower)). > > Are there any existing libraries for this sort of thing? Or at least, can > anyone suggest a cleaner way of doing this? (I don't like creating classes > for things that should really be functions, but I need to call the random > number generator each time I use the generator, not once when I define it) > > Brandon > > > numarray, the package which is being developed to replace Numeric has random_array. It permits one to generate random arrays or single values, with a number of statistical distributions. Colin W. From mpeuser at web.de Sat Aug 30 03:22:54 2003 From: mpeuser at web.de (Michael Peuser) Date: Sat, 30 Aug 2003 09:22:54 +0200 Subject: Newbie question! Plotting with Tkinter... References: <9193c0d1.0308291322.12538c14@posting.google.com> Message-ID: "Michael" schrieb im Newsbeitrag news:9193c0d1.0308291322.12538c14 at posting.google.com... > Hi! > > Im a supernewbie who wants to plot simple x/y-diagrams, one list[] > against an other. Can I use Tkinter? Can i plot 3D, and/or > interactivly with Tkinter? Does anyone know about a easy to use > tutorial or code to use? Or whatabout Numeric? Can i use Numeric to > plot some simple graphs? I?ve been looking around for a while and cant > find any simple, easy to use or install program/module... > > /Michael There is an extension to Pmw (Mega widgts, which themselves are extensions to Tkinter) called BLT, these work quite fine and are very well documented. They are interactive as well because they use the Canvas widget. (I remember rumors however, that BLT will not work with the most recent Pmw for Python 2.3. I also recall there was some installation trick for BLT...... Ask in this group if you encounter problems...) The drawback with BLT is, that it is not the fastest; otherwise it is fine. A much more profesional plot package is DISLIN which is very fast and (at least under win32) easily installed. It as well has a limited GUI of its own with some widgets, so you not necessarily have to use Tk at all. I can recommend it. Kindly Michael P From scottholmes at sbcglobal.net Mon Aug 18 10:05:58 2003 From: scottholmes at sbcglobal.net (Scott Holmes) Date: Mon, 18 Aug 2003 07:05:58 -0700 Subject: ButtonRelease and ButtonPress Message-ID: <3F40DD46.1010200@sbcglobal.net> Having just seen mention of problems with ButtonRelease in a thread on Tkinter, I thought I'd experiment with my previously posted problem of event binding and component.config, namely the inability to set a button to relief="sunken". I changed my code to ButtonPress and the relif setting now behaves properly. I don't know if the two issues are related at all but the fix works for me. -- --------------------------------------------------------------------- Scott Holmes http://sholmes.ws http://pages.sbcglobal.net/scottholmes scottholmes at sbcglobal.net Independent Programmer/Analyst Passport 4GL PHP HTML Composer PostgreSQL Informix 4GL, SQL --------------------------------------------------------------------- There are more things in heaven and earth, Horatio, than are dreamt of in your philosophy --------------------------------------------------------------------- From gh at ghaering.de Thu Aug 21 11:00:59 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Thu, 21 Aug 2003 17:00:59 +0200 Subject: freeze utility and pickle In-Reply-To: References: Message-ID: <3F44DEAB.30304@ghaering.de> Aki Niimura wrote: > Hello everyone, > > I'm having a problem "freezing" my program using freeze.py under Solaris. > My program works fine if I invoke it as a Python script. > However, it generates a LookupError when I started the "frozen" program. > [...] > File "/usr/local/lib/python2.3/pickle.py", line 985, in load_string > self.append(rep.decode("string-escape")) > LookupError: unknown encoding: string-escape Your frozen executable needs stuff from the 'encodings' package. At least encodings.string_escape. -- Gerhard From claird at lairds.com Fri Aug 1 12:21:38 2003 From: claird at lairds.com (Cameron Laird) Date: Fri, 01 Aug 2003 16:21:38 -0000 Subject: Potentially important real-time on-line discussion Message-ID: *The Chronicle of Higher Education*, which is more-or-less authoritative for US university administrations, is spon- soring a discussion on the place of open-source in universities ("... are such choices too risky for colleges ...?"), starting in about an hour. Bluntly, I think it's time to rally 'round the flag. http://chronicle.com/colloquylive/2003/08/opensource/chat.php Pass it on. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://phaseit.net/claird/home.html From alessandro at sephiroth.it Thu Aug 7 12:19:14 2003 From: alessandro at sephiroth.it (Alessandro Crugnola *sephiroth*) Date: Thu, 07 Aug 2003 16:19:14 GMT Subject: py2exe problems References: <8utYa.48785$cl3.1524137@news2.tin.it> Message-ID: <6_uYa.49293$cl3.1541558@news2.tin.it> > Then I have no idea. Installing 2.2.3 instead of 2.2.2 is something I > cannot currently do (and I doubt it would help). do you think something can change installing 2.2.2 ? anyway.. is there no other solution? sorry, but i'm a newbie P.S. thanks for your support anyway -- Alessandro Crugnola [sephiroth] From wtrenker at shaw.ca Fri Aug 8 09:36:04 2003 From: wtrenker at shaw.ca (William Trenker) Date: Fri, 08 Aug 2003 13:36:04 +0000 Subject: Socket Memory Leak Message-ID: <20030808133604.702ae762.wtrenker@shaw.ca> During the past week a serious memory leak was reported in the Socket module for Python 2.3 (Bug #783312). This was confirmed and fixed with a patch. According to the Python bug tracker the bug report is now closed with a note that socketmodule.c was updated in CVS to fix the problem. When I look at the Python patches on Sourceforge I can't see the patch that fixes problem 783312. This is probably because I don't understand the process of what happens between the time a fix is implemented in CVS and the time it shows up as a patch on the patch list. Can someone enlighten me on this process? Also, when a significant bug like this is identified and fixed, is this announced on a list somewhere so we can incorporate critical fixes like this? Of course this might all be documented on the Python site and I've overlooked it. A link to such documentation would be greatly appreciated. Thanks very much, Bill From gcash at luncheonmeat.cfl.rr.com Sat Aug 2 15:52:33 2003 From: gcash at luncheonmeat.cfl.rr.com (gcash) Date: Sat, 02 Aug 2003 19:52:33 GMT Subject: FOUND! how to attach to running instances of Internet Explorer References: Message-ID: "Cousin Stanley" writes: > Your win32 script for connecting to open IE instances > works fine for me using .... > > Win98_SE > Python 2.2.1 Awesome! That gives me hope it isn't some one-off WIN2K thing. Cool! Thanks. -gc -- I've never tried emacs because I already _have_ an OS on this peecee. -- mikea at mikea.ath.cx (Mike Andrews) From Mike at DeleteThis.Geary.com Tue Aug 19 02:18:09 2003 From: Mike at DeleteThis.Geary.com (Michael Geary) Date: Mon, 18 Aug 2003 23:18:09 -0700 Subject: Brandon's personal style (was) References: <38ec68a6.0308172319.431a4fde@posting.google.com> Message-ID: > > Would you do that in a face to face conversation? I didn't think so. > > Most people don't have this much trouble face-to-face. There's so much > extra information: tone, facial expression, body posture, hand gestures. > It's easier for people to take comments in the manner they were intended, > and it's easier for people to see they're pissing someone else off and back > down. E-mail and newsgroups are inherently imperfect media, and I will not > try to change them. That's an excellent point that we would all do well to heed. (Myself included.) Being half Italian, I have plenty of experience with heated discussions conducted in total friendship. But that definitely works only in person! Personally, I think it's worth taking a little extra effort to try to compensate for the limitations of the medium. If you know that people are more likely to misunderstand your intentions, why egg them on? You've certainly made some insightful comments here, such as the Reality On The Ground list you just posted. It's unfortunate that the message has been obscured by the tone of the conversation. (Not placing blame--it takes more than one to tango.) -Mike (Windows programmer for 17 years and Python newbie...) From BPettersen at NAREX.com Sat Aug 2 02:12:36 2003 From: BPettersen at NAREX.com (Bjorn Pettersen) Date: Sat, 2 Aug 2003 00:12:36 -0600 Subject: How do I combine instance+string for variable Message-ID: <60FB8BB7F0EFC7409B75EEEC13E2019202CE4817@admin56.narex.com> > From: Marc [mailto:mnations at airmail.net] > > Hi all, > > I can't remember how to do this. > > I have several instances of telnet connections that I label > conn2,conn3, etc. Later when I want to scroll through all of these I > wanted to do something like this: > > for int in range(2, 9): > use... conn+str(int) {I'm passing it into another > function} > > I can't get it to work. I've tried using setattr and eval, but > nothing seems to work. Can I get a little help. Enumerating something by using variable names containing the index quickly becomes unweildly, storing the enumeration in a collection object is usually much more managable. These hand numbered pseudo-collections are most frequently encountered in beginning programmers' design, presumably because it's the way you'd do it by hand, however the general idea sometimes make tedious things trivial... If you can switch to using a collection, there are several variations... Assuming sequential creation of connection objects possibly in different code locations (scopes), use append to build the list: conn = [] conn1 = ... conn.append(conn1) conn2 = ... conn.append(conn2) ... or simpler -- if connections are all created in the same scope, construct through list literal: conn1 = ... conn2 = ... ... conn = [conn1, conn2, ...] or alternatively if connections are created in different places out-of-order (introducing the need to deal with None -- easily alleviated by a trivial list subclass to deal with error checking, append capability, support for sparceness, etc): conn = [None] * numConnections ... conn[5] = createConnObject(...) For all of the above you'll use it the obvious way: for cn in conn[2:9]: cn.someMethod(...) Note that using collections lose the "name property" of the object, i.e. in the general case there is no way to go from the connection object (e.g. cn in the for loop above) to the variable name the object was initially created under). That is normally the underlying reason for more interesting uses of named values. For enumerations like yours, it shouldn't be a problem. If you do need the stringified name, a layer of indirection is required (and introduces a synchronization problem): conn1 = createConnObject(...) conn2 = createConnObject(...) ... conn = { 'conn1' : conn1, 'conn2' : conn2, 'conn3' : ... } for i in range(2,9): conn_name = 'conn' + `i` # construct var name cn = conn[conn_name] # print 'using:', conn_name cn.someMethod(...) And yes, I will also answer your real question . Giving a variable name to eval() will return the object bound to that variable in the current scope (implicit): conn1 = ... conn2 = ... ... for i in range(2,9): cn = eval('conn' + `i`) cn.someMethod(...) (note: using eval() this way is not a security risk.) Using vars(), locals(), globals(), or a module prefix gives you the possiblity of explicitly specifying the scope. The scope issues, along with the frequent name constructions, makes a class based solution seem more appropriate and flexible, e.g. something like: class NamedValueCollection(object): def __sortedNames(self): """Sorted list of contained values.""" # I'd still like to be able to say self.__dict__.keys().sort(), # I'm grown-up enough to know it could be expensive and still # not care . names = self.__dict__.keys() names.sort() return names def __setitem__(self, key, obj): if isinstance(key, (int, long)): # key += 1 here, if you want the indexing to be 1-based names = self.__sortedNames() self.__dict__[names[key]] = obj elif isinstance(key, slice): raise TypeError('Slice assignment left as an excercise.') else: self.__dict__[key] = obj def __getitem__(self, key): """Hybrid __getitem__, supporting the sequence protocol (number/slice keys) and the mapping protocol (string key). """ if isinstance(key, slice): # coll[a:b], returns (name, value) tuples, cf. __iter__ below. import itertools as itools return itools.islice(self, key.start, key.stop) elif isinstance(key, (int, long)): # not quite unified yet :-) # coll[5] names = self.__sortedNames() return self.__dict__[names[key]] else: # coll['conn1'] return self.__dict__[key] def __iter__(self): for name in self.__sortedNames(): yield (name, self[name]) conn = NamedValueCollection() # set trough string value of variable name conn['cn1'] = createConnObject(...) # set trough attribute conn.cn2 = createConnObject(...) # get through attribute print conn.cn1 # get through variable name print conn['cn2'] # get through index (zero based) print conn[1] # replace through index (zero based) conn[2] = createConnObject(...) # iterate (calling __iter__) for varname, cn in conn: print varname, cn # iterate through slice (calling __getitem__) for varname, cn in conn[:1]: print varname, cn hth, -- bjorn ps: to relight another religious issue, this is a place where type declarations could be useful. Not for type checking, but overloading/pattern matching (as an excercise, try to give the type of __getitem__ :-) Overloading __lt__ on type objects to mean isinstance, <, <=, or <: are normally used to indicate subtype-of relationships, would make the current version look better to a type-theorist, but is probably used too infrequently to be justified... From info at GynnNet.com Mon Aug 11 01:12:00 2003 From: info at GynnNet.com (info at GynnNet.com) Date: Sun, 10 Aug 2003 22:12:00 -0700 Subject: Web Site Development, Custom Databases, Graphics... Message-ID: We design, develop, host and guide you through any and all parts of the process of web site development, custom database design and development and graphics. If you`ve thought about doing something more with what you have but are not sure how to go about it, let us help. Gynn Communications, Inc. To remove yourself from our list type REMOVE in the subject line and forward this email to info at BizBulk.com with the email address you would like removed. From mack at incise.org Sun Aug 31 20:14:00 2003 From: mack at incise.org (mackstann) Date: Sun, 31 Aug 2003 19:14:00 -0500 Subject: MySQLdb: execute query results... In-Reply-To: References: Message-ID: <20030901001400.GM9311@incise.org> On Sun, Aug 31, 2003 at 11:57:07PM +0000, Sheila King wrote: > Here is what I *think* I know...let me know if I'm wrong, for crying out > loud!!! > > [...] > > >>> result = c.execute("""""") > > doesn't result always return the number of affected rows? > > [...] > > Can I *RELY* on that "2L" result of the UPDATE statement under the cursor's > "execute" method representing the number of rows updated? Or am I assuming > too much? Looked in site-packages/MySQLdb/cursors.py, and it seems you are correct. >>> from MySQLdb import cursors >>> help(cursors.BaseCursor.execute) Help on method execute in module MySQLdb.cursors: execute(self, query, args=None) unbound MySQLdb.cursors.BaseCursor method Execute a query. [...] Returns long integer rows affected, if any HTH, -- Nick Welch aka mackstann | mack @ incise.org | http://incise.org Harris's Lament: All the good ones are taken. From jussij at zeusedit.com Sun Aug 31 21:27:43 2003 From: jussij at zeusedit.com (Jussi Jumppanen) Date: Mon, 01 Sep 2003 11:27:43 +1000 Subject: Win32 documentation in CHM? References: <3f5262ea$0$1667$e4fe514c@dreader3.news.xs4all.nl> Message-ID: <3F52A08F.55FE@zeusedit.com> Iwan van der Kleyn wrote: > Great initiative. Are there any compiled CHM files available > for 2.3, perhaps from other sources then PythonLabs? Slightly off topic but still related to Windows help files :) You can also turn HTML files into the older Win32 WinHelp using this nice little tool: http://www.confluent.fr/javadoc/htmltohlpe.html Jussi Jumppanen Author of: Zeus for Windows (All new version 3.90 out now) "The C/C++, Cobol, Java, HTML, Python, PHP, Perl programmer's editor" Home Page: http://www.zeusedit.com From simonb at webone.com.au Mon Aug 18 04:35:22 2003 From: simonb at webone.com.au (Simon Burton) Date: Mon, 18 Aug 2003 18:35:22 +1000 Subject: overriding a tuple's __init__ References: Message-ID: On Mon, 18 Aug 2003 08:24:21 +0000, Duncan Booth wrote: > Simon Burton wrote in > news:pan.2003.08.18.07.37.44.108933 at webone.com.au: > >>>>> class pair(tuple): >> ... def __init__(self,a,b): >> ... tuple.__init__(self, (a,b) ) >> ... >>>>> a=pair(1,2) >> Traceback (most recent call last): >> File "", line 1, in ? >> TypeError: tuple() takes at most 1 argument (2 given) >>>>> >> >> What gives? (yes it works with a list, but i need immutable/hashable) > > You need to override __new__ instead of __init__: > :) I need to grow a brain. thanks Duncan. Simon. From jepler at unpythonic.net Fri Aug 29 22:12:59 2003 From: jepler at unpythonic.net (Jeff Epler) Date: Fri, 29 Aug 2003 21:12:59 -0500 Subject: locale.nl_langinfo(RADIXCHAR) vs locale.localeconv()['decimal_point'] Message-ID: <20030830021259.GB18871@unpythonic.net> I'd expect these two to be identical, but they don't seem to be. [This session from 2.2.2 on RedHat Linux 9; same behavior in 2.3b1] >>> import locale >>> locale.setlocale(locale.LC_ALL, "fr_FR") 'fr_FR' >>> locale.nl_langinfo(locale.DAY_1) 'dimanche' >>> # Okay, we *are* in France now >>> locale.localeconv()['decimal_point'] ',' >>> # Yep, they use this in place of the decimal point >>> locale.nl_langinfo(locale.RADIXCHAR) '.' >>> # But not if you use nl_langinfo() !? I know that Python plays some nasty games under the covers with LC_NUMERIC, but I would expect the "emulated" LC_NUMERIC to extend to locale.nl_langinfo(). The documentation (doc/lib/module-locale.html or pydoc locale) doesn't reflect this limitation of nl_langinfo() as far as I can tell. Should I file an SF bug over this, am I confused about what's going on, or will this likely be fixed anyway in 6.4? It's not a pressing need for me, since code can just use localeconv() anyway (or locale.atof and friends, for that matter)... Jeff From careye at spamcop.net Mon Aug 18 21:43:15 2003 From: careye at spamcop.net (Carey Evans) Date: Tue, 19 Aug 2003 13:43:15 +1200 Subject: Replacing the crypt module in Windows References: Message-ID: <87oeymmngs.fsf@psyche.dnsalias.org> Jorge Godoy writes: > What do you use to replace the crypt module in Windows? There are pure Python implementations of the MD5- and DES-based crypt algorithms available from, respectively: http://www.sabren.net/code/python/crypt/ (by michal j wallace) http://home.clear.net.nz/pages/c.evans/sw/ (by me) The former should be quite a bit more secure. It may also be faster since it uses the md5 module internally, but I've never tested them. -- "Hanging is too good for a man who makes puns; he should be drawn and quoted." -- Fred Allen From jwbaxter at spamcop.net Sat Aug 2 00:32:03 2003 From: jwbaxter at spamcop.net (John Baxter) Date: Fri, 01 Aug 2003 21:32:03 -0700 Subject: time, calendar, datetime, etc References: Message-ID: In article , "Tim Peters" wrote: > [Andrew Dalke] > > ... > > The datetime module needs a 0 point (the creation of the universe > > being rather long ago and the exact time not well known). Given the > > questions of "when is year 0?" in different calendar systems, it's easy > > for me to understand why Jan. 1st, 1AD is a good starting point. > > (Easier than Jan 1st, 1970 - I prefered the Mac's epoch of 1900.) 1904 for Mac, actually. The story is fairly well documented, but... It was desired to include the entire team's set of birth dates That didn't get back to 1904, but it got reasonably close to 1900 1900 was rejected because they didn't want to start out in a leap year exception They did want to start in a leap year...hence 1904 The 1904 choice has meant that considered as a signed 32-bit number, Macintosh time has always been negative. "Always" in the sense of when there were Macintosh machines...the sign change was sometime in 1972, I think. And since Pascal was the base higher level language, time was indeed negative. (Macintosh time became signed 64 bits--with 32-bit clock hardware--around 1991: plenty early to beat the End of Time early in 2040.) --John (steadfastly ignoring leap seconds) From gh at ghaering.de Wed Aug 20 12:28:12 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Wed, 20 Aug 2003 18:28:12 +0200 Subject: It is possible to pass a Python callback to C-extensions? In-Reply-To: References: Message-ID: <3F43A19C.8080806@ghaering.de> Sure. Explanation by example: Python code: #v+ def myfunc(): pass foobar.register_callback(myfunc) #v- C code: #v+ PyObject* register_callback(FooType* self, PyObject* args, PyObject** kwargs) { /* ParseTupleAndKeywords */ /* PyCallable_Check */ self->callback = ... } ... function_result = PyObject_CallObject(callback, calling_args); ... #v- No idea about SWIG, but I do this a lot in the PySQLite code using Python's raw C API, which you could use as an example: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/pysqlite/pysqlite/_sqlite.c?rev=HEAD&content-type=text/vnd.viewcvs-markup HTH, -- Gerhard From mwh at python.net Tue Aug 5 08:48:31 2003 From: mwh at python.net (Michael Hudson) Date: Tue, 5 Aug 2003 12:48:31 GMT Subject: Wow: list of immediate subclasses? References: <7h3k79xaavf.fsf@pc150.maths.bris.ac.uk> <7h3fzklaa75.fsf@pc150.maths.bris.ac.uk> Message-ID: <7h3ispc8e5a.fsf@pc150.maths.bris.ac.uk> "Andrew Dalke" writes: > Michael Hudson: > > >>> A.__dict__['__weakref__'].__objclass__ is A > > Ahhh... And *then* I find how I should have found the cycle: >>> class A(object): pass ... >>> pprint.pprint([r for r in gc.get_referrers(A) if r is not __main__.__dict__]) [, , (, )] Forgot about the obvious A.__mro__[0] is A cycle! Cheers, mwh -- A difference which makes no difference is no difference at all. -- William James (I think. Reference anyone?) From afriere at yahoo.co.uk Mon Aug 11 20:48:17 2003 From: afriere at yahoo.co.uk (Asun Friere) Date: 11 Aug 2003 17:48:17 -0700 Subject: Multi-Line Comment References: <4qofjvg3bh9smlnb1do4f0lhjga7bacnu3@4ax.com> Message-ID: <38ec68a6.0308111648.71125c94@posting.google.com> Doug Tolton wrote in message news:<4qofjvg3bh9smlnb1do4f0lhjga7bacnu3 at 4ax.com>... > I've been using Python for quite some time now, and I'm a bit stumped. > > Does it really not have a multi-line comment? I think I must just be > missing something simple and stupid. > > Thanks in advance. > > Doug Tolton #!/usr/bin/env python """This is a multiline comment. OK?""" From mark at diversiform.com Fri Aug 15 16:40:07 2003 From: mark at diversiform.com (Mark Daley) Date: Fri, 15 Aug 2003 13:40:07 -0700 Subject: Dictionary assignment Message-ID: I've been using this to save one dictionary as an entry in another dictionary. I was working, but now it seems I've done something to break it. Here's the code in question: def formatsave(self, args = None): if self.formats.get() == '': tkMessageBox.showwarning("No Format", "You must specify a format name.") else: for key in current.keys(): format[self.formats.get()][key] = current[key] temp = format.keys() temp.sort() list = tuple(temp) gui.formats._list.setlist(list) Here's the error I'm getting: Traceback (most recent call last): File "C:\PYTHON23\lib\lib-tk\Tkinter.py", line 1345, in __call__ return self.func(*args) File "C:\Python23\Layout.py", line 191, in formatsave format[self.formats.get()][key] = current[key] KeyError: 'Format 1' Any ideas? - Mark -------------- next part -------------- An HTML attachment was scrubbed... URL: From hanzspam at yahoo.com.au Tue Aug 26 14:33:38 2003 From: hanzspam at yahoo.com.au (=?ISO-8859-1?Q?Hannu_Kankaanp=E4=E4?=) Date: 26 Aug 2003 11:33:38 -0700 Subject: My own 12 points list References: Message-ID: <840592e1.0308261033.269c7fcb@posting.google.com> pruebauno at latinmail.com (nnes) wrote in message news:... > I have really no mayor gripes, and the few things I would change would > break backward compatibility, but here is the list anyway: > > 2.) Eliminate map (), filter (), reduce (). It can be replaced with > list comprehensions and for loops, which are easier to read. How do you pass a list comprehension to a function? With map as a function, you could do something wicked like do_something_wicked([map, my_map, his_map]) Where my_map and his_map are alternative implementations for map, and do_something_wicked would use all those functions for something crazy. But sure, map could be implemented with list comprehensions if it was really needed, probably like this: def map(fn, *lists): return [fn(*args) for args in zip(*lists)] Soo.. Do I have an optinion? Maybe, maybe not.. I just wanted to point out that some things are useful as being functions instead of plain syntax. > 4.) Eliminate xrange(), replace range() with xrange() implementation Then people would have to use list(range[10]) to get the list when needed.. I always use range() since Psyco seems to optimize it to a simple for loop of integers (on my tests with Psyco, "for x in range(n)" is -faster- than "for x in xrange(n)"!). So xrange() could be removed, and then people would just rely on JIT compiler optimizations to do the right thing. Maybe not yet though. > 6.) Eliminate lambda, use local ?def somename(param):return expr' > instead. Noo, lambda is so lovely and compact. It only obfuscates on the purposedly obfuscated code. It's too long word for my taste though.. A symbol for it would be better (I'm not joking). From mack at incise.org Sun Aug 24 17:32:58 2003 From: mack at incise.org (mackstann) Date: Sun, 24 Aug 2003 16:32:58 -0500 Subject: Alphabetizing? In-Reply-To: <1115.68.73.71.83.1061659672.squirrel@webmail.iserv.net> References: <1115.68.73.71.83.1061659672.squirrel@webmail.iserv.net> Message-ID: <20030824213258.GQ1695@incise.org> On Sat, Aug 23, 2003 at 01:27:52PM -0400, tjland at iserv.net wrote: > Ok, im trying to creat a small simple program that alphabetizes user > inputed words. I thought why not just create a def that splits all the > words down into char's then take the first char and crosscheck it with all > lowercase letters. Then find its position and return the results to the > user in order or 1-26! But this takes a long time and the code gets > confusing. Any suggestion? Thanx in advance! Put them in a list and sort them? >>> text = "hello how are you? i'm just fine, blah blah." >>> l = text.split() >>> l ['hello', 'how', 'are', 'you?', "i'm", 'just', 'fine,', 'blah', 'blah.'] >>> l.sort() >>> l ['are', 'blah', 'blah.', 'fine,', 'hello', 'how', "i'm", 'just', 'you?'] -- m a c k s t a n n mack @ incise.org http://incise.org Excellent time to become a missing person. From mpeuser at web.de Sat Aug 16 15:31:33 2003 From: mpeuser at web.de (Michael Peuser) Date: Sat, 16 Aug 2003 21:31:33 +0200 Subject: Modifying TKinter widgets defined in Modules References: <3f443b52.0308151251.7e6bbaaf@posting.google.com> <3f443b52.0308161038.1af149d9@posting.google.com> Message-ID: Marcus, there is no short answer of course ;-) The general acknowledged concept is still some variation of MVC (modell - view - control) which means: encapsulate your "functions" so they principally can be used by diffrent visualisation concepts (or even used from an CLI). On the other hand a general problem is when to "derive" from a class, especially from a widget class and when just "associate" the widgets. There is a lot of theory ("is-a", "has-a") but no strict rules. (A motor cycle "has-a" motor of course, but when you see it from some weird angle, it somehow "is-a" fancy motor....) It has turned out for me that it generally had disadvantages to derive from a widget and put application code in that sub class. Derive from a widget just to make new widgets. When you put it together you can use this fancy "multiple inheritence". Derive from from your "modell class" and mixin your "view widget". You can find nice examples in a book you are able to read by chance ;-) (Michael Lauer: Python und GUI-Toolkits) He explains Tkinter, wxPython, PyQt und GTK using a quite extensive example... Kindly Michael P "Marcus Schneider" schrieb im Newsbeitrag news:3f443b52.0308161038.1af149d9 at posting.google.com... > Michael, > > that is very interesting; in the meantime I managed for the first time > to create an instance of a class that contains my TKinter widgets in a > module, so I obviously messed around with some basics... > > But my questionw as also about "style" of programming Python. Would I > want to use modules just for the widget definition or would I rather > want to put widgets and functions together in one module? > > What kind of structure is considered to by "good style" in Python? > > Thanks for the patience... > > > > "Michael Peuser" wrote in message news:... > > Marcus, > > I have no clear concept of your problem ("nix verstehen"). Newbie? What is a > > "main"? What in fact is the overall structure of your software system? You > > have first di decide where to put your "variables". In Python you will > > generally use an object. This can be made visible as you like. You however > > have do decide who instantiates this object ("main" or one of the "moduls")? > > > > The best way seems to do this in your "main": > > > > class Data: pass > > myData=Data() > > > > Put all your 25 variables into it (myData.varX=None ....), then you pass > > "myData" as a parameter to your moduls... > > > > Is this what helps? > > Kindly > > Michael P > > > > > > "Marcus Schneider" schrieb im Newsbeitrag > > news:3f443b52.0308151251.7e6bbaaf at posting.google.com... > > > Sorry if this is an extremely stupid question: > > > > > > I produced some Python modules with TKinter stuff and now I want to > > > use that from my main program. The windows have wuite some user > > > interaction. It's easy to bring them to the screen, but how do I make > > > the communication (i.e. variables) between the main and the modules > > > happen? > > > > > > Currently I call a function from the main and pass all variables in > > > the function call, but with more then 25 variables this looks odd. > > > > > > And now I have to change variables in the main from the module and > > > that doesn work at all, does it? > > > > > > Or can I access widget definitions from the main?? > > > > > > What is the usual, elegant way to handle that? > > > > > > Thanks for any hint ;) From imbosol at aerojockey.com Wed Aug 6 23:20:26 2003 From: imbosol at aerojockey.com (Carl Banks) Date: Thu, 07 Aug 2003 03:20:26 GMT Subject: dl + getenv (without arguments) = segfault (python2.p2, python2.3) References: <39929.24.199.120.198.1060217799.squirrel@mail.darkscape.net> Message-ID: <_zjYa.15215$W%3.10507@nwrdny01.gnilink.net> Skip Montanaro wrote: > > Xavier> Do note that my previous e-mail was not implying my possible > Xavier> ignorance to the 'dl' module's functionality, but instead > Xavier> inquiring wether there is or may be a solution in the future for > Xavier> Python to handle such an erronous outcome. And plus, segfaults > Xavier> are ugly and make me cry. > > I understand. Given the nature of the problem here, I suspect the segfault > occurred in getenv() (I can't check to be sure, as I don't have the dl > module). It's kind of hard for Python to gracefully recover when it doesn't > control the program counter. Theoretically, it could trap SIGSEGV and have the handler return control to Python. (You'd probably have to wrap the dl call with setjmp, and use longjmp in the handler.) I wouldn't count on the Python process being in great shape afterwards, though. -- CARL BANKS "You don't run Microsoft Windows. Microsoft Windows runs you." From peter at engcorp.com Sun Aug 24 12:09:50 2003 From: peter at engcorp.com (Peter Hansen) Date: Sun, 24 Aug 2003 12:09:50 -0400 Subject: python gripes survey References: <7s6gkv031b940dsc522pbh5g30q4nj5vd1@4ax.com> Message-ID: <3F48E34E.E45F96C8@engcorp.com> Ryan Lowe wrote: > > "Andrew Dalke" wrote: > > >>> d = {1: "a"} > > >>> d.update({True: "b"}) > > >>> d > > {1: 'b'} > > that is weird; i thought 2.3 made bool its own type? but i guess its still a > subtype of int. though, i cant imagine when this would come up in a real > situation anyway. It could easily come up, and in any case notice that the result is the same even if the True is replaced with a floating point value 1.0 in the above example. Dictionary keys are not matched by identity. -Peter From member36136 at dbforums.com Mon Aug 18 11:21:15 2003 From: member36136 at dbforums.com (WIWA) Date: Mon, 18 Aug 2003 11:21:15 -0400 Subject: Python problem Message-ID: <3256252.1061220075@dbforums.com> Hi all, I'm trying to write the following in python: j=0 for i in range(len(datumlijst)+1): if (datumlijst[i+1]!=datumlijst): datum[j]=datumlijst j=j+1 print datum[:] it complains about the part: datumlijst[i+1]!=datumlijst it produces the following error: File "hits_per_dag.py", line 24, in ? datum[j]=datumlijst IndexError: list assignment index out of range Anyone know why this happens -- Posted via http://dbforums.com From andy47 at halfcooked.com Tue Aug 5 09:58:30 2003 From: andy47 at halfcooked.com (Andy Todd) Date: Tue, 05 Aug 2003 14:58:30 +0100 Subject: Python vs PHP In-Reply-To: <4e2216a.0308050406.18edeb@posting.google.com> References: <3F094FA4.9030800@ploiesti.astral.ro> <3F0C8A87.8070505@removeme.free.fr> <4e2216a.0308050406.18edeb@posting.google.com> Message-ID: Graham Bloice wrote: > Bruno Desthuilliers wrote in message news:<3F0C8A87.8070505 at removeme.free.fr>... > > (snip) > >>Too bad I can't afford Python-powered hosting) > > > See http://www.34sp.com". I've used them for two years and are > excellent value at GBP 15.00 per year. > > Graham Don't forget the list of hosting providers you can find on the Wiki; http://www.python.org/cgi-bin/moinmoin/PythonHosting I'd be suprised if there wasn't someone on there who doesn't fulfil your requirements. Regards, Andy -- -------------------------------------------------------------------------------- From the desk of Andrew J Todd esq - http://www.halfcooked.com/ From mal at lemburg.com Tue Aug 12 08:18:50 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue, 12 Aug 2003 14:18:50 +0200 Subject: ANN: eGenix.com mx Base Extension Package 2.0.5 Message-ID: <3F38DB2A.40107@lemburg.com> ________________________________________________________________________ ANNOUNCING: eGenix.com mx BASE Extension Package for Python 1.5.2 - 2.3 Version 2.0.5 Open Source Python extensions providing important and useful services for Python programmers. ________________________________________________________________________ WHAT IS IT ?: The eGenix.com mx Base Extensions for Python are a collection of professional quality software tools which enhance Python's usability in many important areas such as fast text searching, date/time processing and high speed datatypes. Python is an object-oriented Open Source programming language which runs on all modern platforms (http://www.python.org/). By integrating ease-of-use, clarity in coding, enterprise application connectivity and rapid application design, Python establishes an ideal programming platform for todays IT challenges. The tools have a proven record of being portable across many Unix and Windows platforms. You can write applications which use the tools on Windows and then run them on Unix platforms without change due to the consistent platform independent interfaces. All available packages have proven their stability and usefulness in many mission critical applications and various commercial settings all around the world. ________________________________________________________________________ WHAT'S NEW ? The new version includes patches needed to compile the packages under Python 2.3. As always we are providing precompiled versions of the package for Windows and Linux as well as sources which allow you to install the package on all other supported platforms. ________________________________________________________________________ EGENIX.COM MX BASE PACKAGE OVERVIEW: mxDateTime - Generic Date/Time Types mxDateTime is an extension package that provides three new object types, DateTime, DateTimeDelta and RelativeDateTime, which let you store and handle date/time values in a much more natural way than by using ticks (seconds since 1.1.70 0:00 UTC; the encoding used by the time module). You can add, subtract and even multiply instances, pickle and copy them and convert the results to strings, COM dates, ticks and some other more esoteric values. In addition, there are several convenient constructors and formatters at hand to greatly simplify dealing with dates and times in real-world applications. In addition to providing an easy-to-use Python interface the package also exports a comfortable C API interface for other extensions to build upon. This is especially interesting for database applications which often have to deal with date/time values (the mxODBC package is one example of an extension using this interface). mxTextTools - Fast Text Processing Tools mxTextTools is an extension package for Python that provides several useful functions and types that implement high-performance text manipulation and searching algorithms in addition to a very flexible and extendable state machine, the Tagging Engine, that allows scanning and processing text based on low-level byte-code "programs" written using Python tuples. It gives you access to the speed of C without the need to do any compile and link steps every time you change the parsing description. Applications include parsing structured text, finding and extracting text (either exact or using translation tables) and recombining strings to form new text. mxStack - Fast and Memory-Efficient Stack Type mxStack is an extension package that provides a new object type called Stack. It works much like what you would expect from such a type, having .push() and .pop() methods and focusses on obtaining maximum speed at low memory costs. mxTools - Collection of Additional Builtins mxTools is an extension package that includes a collection of handy functions and objects giving additional functionality in form of new builtins to the Python programmer. The package auto-installs the new functions and objects as builtins upon first import. This means that they become instantely available to all other modules without any further action on your part. Add the line import NewBuiltins to your site.py script and they will be available to all users at your site as if they were installed in the Python interpreter itself. mxProxy - Generic Proxy Wrapper Type mxProxy is an extension package that provides a new type that is suitable to implement Bastion like features without the need to use restricted execution environments. The type's main features are secure data encapsulation (the hidden objects are not accessible from Python since they are stored in internal C structures), customizable attribute lookup methods and a cleanup protocol that helps in breaking circular references prior to object deletion. The latest version adds a very interesting new feature: weak references which help you work with circular references in a way that doesn't cause memory leakage in a Python system. Note that even though Python 2.1+ has its own weak reference implemetation, this package can be used to write applications which also work on Python 1.5.2 and 2.0. mxBeeBase - On-disk B+Tree Based Database Kit mxBeeBase is a high performance construction kit for disk based indexed databases. It offers components which you can plug together to easily build your own custom mid-sized databases (the current size limit is sizeof(long) which gives you an address range of around 2GB on 32-bit platforms). The two basic building blocks in mxBeeBase are storage and index. Storage is implemented as variable record length data storage with integrated data protection features, automatic data recovery and locking for multi process access. Indexes use a high performance optimized B+Tree implementation built on top of Thomas Niemann's Cookbook B+Tree implementation (http://epaperpress.com/). ________________________________________________________________________ WHERE CAN I GET IT ? The download archives and instructions for installing the packages can be found at: http://www.egenix.com/ ________________________________________________________________________ WHAT DOES IT COST ? The Base package comes with a Python 2.0 style license, which means that you can use it in both commercial and non-commercial settings without fee or charge. Full source code is included. ________________________________________________________________________ WHERE CAN I GET SUPPORT ? Commercial quality support for these packages is available from eGenix.com Software GmbH. Please see http://www.egenix.com/files/python/eGenix-mx-Extensions.html#Support for details about the eGenix support offerings. ________________________________________________________________________ Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 12 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From op73418 at mail.telepac.pt Sun Aug 31 17:22:15 2003 From: op73418 at mail.telepac.pt (Gonçalo Rodrigues) Date: Sun, 31 Aug 2003 22:22:15 +0100 Subject: exception question Message-ID: Hi, For error processing I found convenient maintaining a dictionary where the keys are exception *classes* and the values are callables. Of course, for this to work, exception classes have to be hashable which I happily found that they were. So my question is, can I count on this behaviour? Or is this behaviour I should not count on? (I found nothing on the docs about it, thus the question). With my best regards, G. Rodrigues From peter at engcorp.com Thu Aug 28 08:56:56 2003 From: peter at engcorp.com (Peter Hansen) Date: Thu, 28 Aug 2003 08:56:56 -0400 Subject: OT: Celebrity advice (was: Advice to a Junior in High School?) References: <3F4D0D8B.5E5F9488@engcorp.com> <3F4D3560.71995AEB@engcorp.com> Message-ID: <3F4DFC18.4B309330@engcorp.com> Gerrit Holl wrote: > > OK; but the last lethal stage is reached *only* if the civilian involved > *also* defends himself with the same means as the government. So, things > will get lethal ulmitately *only* if the civilian owns the same arms as > the government. Consequently, ESR's statement is only applicable to the > situation he promotes. > > If I resist and keep resisting using only my fists or even a knife, the > Dutch police will be able to take me to prison without killing me. A > qualified police force should even be able to do this even when I am > using a gun, but does not always succeed in this. You just aren't cut out for this resistance stuff, are you? ;-) If I had a knife, I'd grab the nearest bystander (one of those types who hasn't chosen to opt out with me, and is therefore not "innocent" ;-) and I'd hold him or her hostage. After a while, the state would get tired of this and just shoot me. Lulu talks about biological and physical restrictions, but also ignores the process needed to *get me into those handcuffs* in the first place. I could be pretty imaginative in finding ways to avoid that, which did not involve a gun, if you insisted. But at this point the discussion quickly degrades, because my sole point was that ESR used the word "ultimately" for a good reason, to try to communicate to his audience a link between personal choice with respect to laws and such, and lethal force. I accept his point as made, even if I agree more with you guys that generally speaking it's a bit of a reach. -Peter From tjreedy at udel.edu Thu Aug 7 03:01:38 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 7 Aug 2003 03:01:38 -0400 Subject: itertools.ilen? References: Message-ID: "Jeremy Fincher" wrote in message news:bgsqj5$228$1 at news.cis.ohio-state.edu... > Sometimes I find myself simply wanting the length of an iterator. An iterator is a function/method that traverses (or possibly generates) a seqeuence. The sequence has a length (actual or potential) but the iterator does not. > For example, to collect some (somewhat useless ;)) > statistics about a program of mine, I've got code like this: > > objs = gc.get_objects() > classes = len([obj for obj in objs if inspect.isclass(obj)]) > functions = len([obj for obj in objs if inspect.isroutine(obj)]) > modules = len([obj for obj in objs if inspect.ismodule(obj)]) > dicts = len([obj for obj in objs if type(obj) == types.DictType]) > lists = len([obj for obj in objs if type(obj) == types.ListType]) > tuples = len([obj for obj in objs if type(obj) == types.TupleType]) Alternative: initialize six counters to 0. Scan list once and update appropriate counter. > Now, obviously I can (and will, now that 2.3 is officially released :)) > replace the list comprehensions with itertools.ifilter, but I need an > itertools.ilen to find the length of such iterators. You mean the associated sequence. > I can imagine such a need arises in more useful situations than this, but > this is the particular case that brought the need to mind. > > The Python code is simple, obviously: > > def ilen(iterator): > i = 0 > for _ in iterator: > i += 1 > return i > > But it's a pity to use itertools' super-fast iterators and have to use slow, > raw Python to determine their length :) If you mean a c-coded counter (which would not be an iterator itself) equivalent to the above, that could be done. Perhaps len() could be upgraded/extended to accept an iterator and count when it can't get a __len__ method to call. The main downside is that iterators are sometimes destructive (run once only). In the meanwhile, is this really a bottleneck for you? or merely the 'pity' of a program running in 1 sec when 0.1 is possible? Terry J. Reedy From s at 3ntra.donotfreakingspamme.net Tue Aug 19 08:40:00 2003 From: s at 3ntra.donotfreakingspamme.net (s) Date: Tue, 19 Aug 2003 12:40:00 GMT Subject: Python newbie help References: <87fa5cfa.0308181126.c61bfa2@posting.google.com> <9f2a0b6e.0308181857.5ebfc56f@posting.google.com> Message-ID: On 18 Aug 2003 19:57:03 -0700, ldrhcp at yahoo.com (Lenny D) wrote: >I too am new to Python. I found a very good tutorial called Dive Into >Python that explains the idea behind the >language, which seems to be what you want. The tutorial is very >complex and thorough understanding of OOP is a prerequisite. Dive into Python seems to be more the direction I'm looking for, however it is not quite there yet. There does seem to be a logical progression of lessons building into one program which I like. I will look into it further, thanks! From danbmil99 at yahoo.com Tue Aug 26 23:58:35 2003 From: danbmil99 at yahoo.com (dan) Date: 26 Aug 2003 20:58:35 -0700 Subject: Python is darn fast (was: How fast is Python) References: <2259b0e2.0308230737.8a9bc1c@posting.google.com> <2259b0e2.0308240638.38350cba@posting.google.com> <87wud05e50.fsf@pobox.com> Message-ID: right, pyrex -- looked at that a while ago. Compiled Python with C-style type declarations, right? Kinda like common lisp??? (I'm stretching my memory cells now) will review jjl at pobox.com (John J. Lee) wrote in message news:<87wud05e50.fsf at pobox.com>... > danbmil99 at yahoo.com (dan) writes: > > > mis6 at pitt.edu (Michele Simionato) wrote in message > > news:<2259b0e2.0308240638.38350cba at posting.google.com>... > [...] > > This is a far cry from the factor of 10-30 I've been seeing with pure > > python. For performance-critical code, this could be the difference > > between hand-coding 5% versus 20% of your code. > > > > Excellent news!! > > If you care about this a lot, don't forget Pyrex. > > > John From s0199583 at sms.ed.ac.uk Thu Aug 14 06:29:58 2003 From: s0199583 at sms.ed.ac.uk (Matt Smith) Date: 14 Aug 2003 03:29:58 -0700 Subject: COM :: VARIANT -eek References: <5f5c82ec.0308110207.1d42251@posting.google.com> <5f5c82ec.0308130542.6857fe74@posting.google.com> Message-ID: <5f5c82ec.0308140229.3451dd2d@posting.google.com> hi again, sorry about all these updates but cant remember what I posted in the last message and google ahsnt updated yet :/. My current probelm is that I have generated a makepy file and then run ensureModule on it to ensure early binding. However when I came to run Dispatch it still ran with late binding :(. If i ran the script with ensureDispatch would that help (instead of normal client.Dispatch that is) thanks again, matt. p.s. forgot to post the .tlb register website address here it is: http://www.vbaccelerator.com/codelib/tlb/vbregtlb.htm From bhoel at web.de Fri Aug 29 12:03:12 2003 From: bhoel at web.de (Berthold Hoellmann) Date: Fri, 29 Aug 2003 18:03:12 +0200 Subject: opposite of dict.items() References: <3f4e708c$0$64719@hades.is.co.za> <3f4e7544$0$64724@hades.is.co.za> Message-ID: Tertius writes: > Tertius wrote: >> Is there a method to create a dict from a list of keys and a list of >> values ? >> TIA >> Tertius >> > > I found a way... > > a = {} > for k , v in zip(keys,values): > a[k] = v > Or: >python Python 2.3 (#1, Jul 30 2003, 21:59:29) [GCC 3.3 (SuSE Linux)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> a=(1,2,3) >>> b=(4,5,6) >>> dict(zip(a,b)) {1: 4, 2: 5, 3: 6} >>> Greetings Berthold -- bhoel at web.de / http://starship.python.net/crew/bhoel/ It is unlawful to use this email address for unsolicited ads (USC Title 47 Sec.227). I will assess a US$500 charge for reviewing and deleting each unsolicited ad. From anton at vredegoor.doge.nl Fri Aug 8 04:42:25 2003 From: anton at vredegoor.doge.nl (Anton Vredegoor) Date: Fri, 08 Aug 2003 10:42:25 +0200 Subject: midi with ctypes References: Message-ID: danbmil99 at yahoo.com (dan) topposted: >Interesting idea, but frankly it seems like alot of extra overhead. >Now that midipy is compiling, I'm more inclined to add features in C >than using ctypes. The microsoft visual C compiler is about half a gigabyte size, the soundfont SDK from creative labs is about 20 megabyte size, the OSC toolkit is about 3 megabyte size, the midipy.cpp is a few kilobyte size. Compare this with the ctypes solution: ctypes itself is about half a megabyte size and the ctypesmidipy.py is taking a few kilobytes. >From this comparison one could conclude that the overhead is largely on the side of the current solution using C. >What advantages can we expect from doing it this way? The ctypes solution is cheaper, there are less license issues because there are less parties involved, it's a lot less code so it's easier to understand and maintain, programming this module in Python gives extra flexibility, and most importantly this could be a platform independent solution for MIDI programming. That would earn Python extra kudos from music programmers. Anton From ghowland at lupineNO.SPAMgames.com Sat Aug 23 00:32:03 2003 From: ghowland at lupineNO.SPAMgames.com (Geoff Howland) Date: Sat, 23 Aug 2003 04:32:03 GMT Subject: Modifying the {} and [] tokens Message-ID: I want to modify the {} and [] tokens to contain additional functionality they do not currently contain, such as being able to add dicts to dicts, and other things that would be very helpful for me and my team mates to have. (Please dont kick off a bunch of responses about how this may be a problem for people supporting code, or copying it out and it doesnt work. :) ) I have currently tried this: >>> class dict(dict): ... def add(self, name, value): ... self.__setitem__(name, value) >>> a = dict() >>> a.add('five', 'six') >>> a {'five': 'six'} >>> b = {} >>> dict.add('blah', 5) Traceback (most recent call last): File "", line 1, in ? AttributeError: 'dict' object has no attribute 'add' So I can obviously override dict and it works when I specifically call dict(), but it does not work with the syntax sugar {}. How can I make this work? Can this also work to overload strings with the "" and '' tokens? -Geoff Howland http://ludumdare.com/ From clifford.wells at comcast.net Tue Aug 19 03:29:57 2003 From: clifford.wells at comcast.net (Cliff Wells) Date: Tue, 19 Aug 2003 00:29:57 -0700 Subject: Brandon's personal style (was) In-Reply-To: References: Message-ID: <1061278197.27697.117.camel@devilbox.homelinux.net> On Mon, 2003-08-18 at 23:30, Brandon J. Van Every wrote: > Cliff Wells wrote: > > Brandon, on the other hand, is annoying and arrogant without the > saving grace of being either stupid or insane. > > Well, at least my sanity is vouched for! Would be interesting for you to > debate with Aahz. Threading is almost worthless with Python. Just typing "import threading" practically guarantees a 40% slowdown in a Python application. Plus the fact that you can't stop a running thread makes them useless anyway. That should do it. Regards, Cliff -- Should I stand midst the breakers, Should I lie with Death my bride? -This Mortal Coil From mertz at gnosis.cx Sat Aug 16 12:25:41 2003 From: mertz at gnosis.cx (David Mertz) Date: Sat, 16 Aug 2003 12:25:41 -0400 Subject: Recommendation of a parser generator (fwd) Message-ID: fortepianissimo at yahoo.com.tw (Fortepianissimo) wrote previously: |Hi Andrew (and others who replied) - thanks for the extensive tip. |However I ended up in using Simpleparse, cuz (1) I read from Charming |Python column that SPARK is *very* slow (it uses Earley algorithm) (2) |Simpleparse turns out to be not that outdated - the latest one (2.0, |in alpha) was released in 2002. FWIW, in my book, I document and compare mxTextTools, SimpleParse, and PLY in some detail. I decided to look at PLY rather than SPARK for the book; the approaches of SPARK and PLY are similar, but I liked a few things better in the latter (post my CP installment on SPARK). You can read the book for free at: . But if you feel like buying the dead-trees version, use the link below to give me a few extra dollars: X-Shameless-Plug: Buy Text Processing in Python: http://tinyurl.com/jskh -- mertz@ _/_/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY: \_\_\_\_ n o gnosis _/_/ Postmodern Enterprises \_\_ .cx _/_/ \_\_ d o _/_/_/ IN A WORLD W/O WALLS, THERE WOULD BE NO GATES \_\_\_ z e From andrew-pythonlist at puzzling.org Fri Aug 22 03:42:12 2003 From: andrew-pythonlist at puzzling.org (Andrew Bennetts) Date: Fri, 22 Aug 2003 17:42:12 +1000 Subject: Match beginning of two strings In-Reply-To: References: <3f2c429e@nntp0.pdx.net> <3f2c7806.20532894@news.lexicon.net> <48d1f86b.0308212251.b9dcf4a@posting.google.com> Message-ID: <20030822074212.GB8563@frobozz> On Fri, Aug 22, 2003 at 07:28:11AM +0000, Andrew Dalke wrote: > > There's something to be said for simplicity. I also > wonder if modern optimizing compliers could figure > out some of this automatically, but I don't wonder > enough to find out. Judging from this URL, I'd say they problem can: http://lwn.net/Articles/45404/ -Andrew. From bdesth.nospam at removeme.free.fr Sat Aug 16 15:55:02 2003 From: bdesth.nospam at removeme.free.fr (Bruno Desthuilliers) Date: Sat, 16 Aug 2003 21:55:02 +0200 Subject: Python should try to displace Java In-Reply-To: References: Message-ID: <3f3e89f3$0$225$626a54ce@news.free.fr> Doug Tolton wrote: (snip) > Java and Python are really > entirely different things. Python is meant as a scripting language, > Java is a Systems programming language. Err... Is this another troll ? Or is it me being just dumb ? I'd like to see some 'System programming' (I think we don't give 'system programming' the same meaning) in Java, that can't be done in Python. (snip the rest) Bruno From Simon.Wittber at perth.maptek.com.au Mon Aug 11 01:55:45 2003 From: Simon.Wittber at perth.maptek.com.au (Simon Wittber (Maptek)) Date: Mon, 11 Aug 2003 13:55:45 +0800 Subject: Python vs. C# Message-ID: <20E0F651F8B82F45ABCBACC58A2D995B0518B9@mexper1> >-----Original Message----- >From: Brandon J. Van Every [mailto:vanevery at 3DProgrammer.com] >Subject: RE: Python vs. C# >Your e-mails are *not* welcome. If you send me e-mail again, I will be >contacting your ISP about account abuse. >Cheers, www.3DProgrammer.com >Brandon Van Every Seattle, WA You are going to contact my ISP about what exactly? Account abuse? How exactly am I abusing my account? By expressing my opinion that you are a troll? If you do not like being thought of as a troll, I suggest you stop making what appear to be deliberately inflammatory comments cunningly hidden among rather innocuous questions. I am certain, of course, that this advice falls on deaf ears. You have a history of trolling. In fact, you are quite good at it! (154 posts on this one) http://groups.google.com/groups?threadm=3e36d04e_2%40news.vo.lu&rnum=1&p rev=/groups%3Fq%3Dg:thl716342609d%26dq%3D%26hl%3Den%26lr%3D%26ie%3DUTF-8 %26oe%3DUTF-8%26safe%3Doff%26selm%3D3e36d04e_2%2540news.vo.lu I will list two more troll posts. Finding more is an interesting exercise for the bored reader. http://groups.google.com/groups?selm=6oli0c%24qng%241%40guysmiley.blarg. net http://groups.google.com/groups?selm=ltC0a.2919%24tO2.327679%40newsread1 .prod.itd.earthlink.net Others, too, have thought your posts are deliberately provoking. http://groups.google.com/groups?selm=1998062601400000.VAA23852%40ladder0 1.news.aol.com You often aggravate others, seemingly intentionally. Once, it even escalated to the point of threats of physical violence. http://groups.google.com/groups?q=brandon+van+every&hl=en&lr=&ie=UTF-8&o e=UTF-8&safe=off&selm=7ui75g%24918%241%40panix3.panix.com&rnum=9 So please refrain from posting your troll-comments to the list, and stop polluting it with your contentious remarks. Cheers, Simon. PS. Pythonistas: please don't feed this troll. From sross at connectmail.carleton.ca Wed Aug 27 19:38:59 2003 From: sross at connectmail.carleton.ca (Sean Ross) Date: Wed, 27 Aug 2003 19:38:59 -0400 Subject: Style question... References: Message-ID: "Anthony Roberts" wrote in message news:Uva3b.49430$la.826046 at news1.calgary.shaw.ca... > If I end indentation levels with "pass" statements, will I piss off people > that have to read my code? eg: > > for i in xrange(0,5): > if i: > print i > pass > print i * -1 > pass > > I ask for two reasons... a) it helps emacs figure it out, and b) I'm more > comfortable ending compound statements with a token. > Hi. I tried to do something like that too, early on. (I recall being frustrated to find I couldn't just alias "end = pass", and use 'end' as a block delimiter... heh). I didn't actually want to use 'end' (I like significant whitespace), I just saw a lot of posts with complaints about "no-block-delimiter", and I thought, I wonder if you can make one. Well, you can (of course), but not like that. Anyway. I think the suggested idiom for people who must have a visible block delimiter is "# end ". If you use this, I think emacs can "figure it out" (I don't know, I don't use emacs, but I think pymode can handle this), and you can also use Tools/scripts/pindent.py, if you like. "from pindent.py" # This file contains a class and a main program that perform three # related (though complimentary) formatting operations on Python # programs. When called as "pindent -c", it takes a valid Python # program as input and outputs a version augmented with block-closing # comments. When called as "pindent -d", it assumes its input is a # Python program with block-closing comments and outputs a commentless # version. When called as "pindent -r" it assumes its input is a # Python program with block-closing comments but with its indentation # messed up, and outputs a properly indented version. [snip] # Secret feature: # - On input, a block may also be closed with an "end statement" -- # this is a block-closing comment without the '#' sign. Hmm. Looks like you can also use "end", or perhaps 'end' . I don't know if the is optional or not, having never used this module. Anyway, if you use this format, then, if someone doesn't like seeing all that noise when they read your code, they can strip it out with "pindent -d". Handy. And, when you read other peoples code, you can clutter it up nicely with "pindent -c". Best of both worlds, really. HTH Sean From joch at blueyonder.co.uk Wed Aug 13 12:51:23 2003 From: joch at blueyonder.co.uk (John Ochiltree) Date: Wed, 13 Aug 2003 17:51:23 +0100 Subject: Running Python 2.3 on a Windows 2000 network In-Reply-To: References: Message-ID: Gerhard H?ring wrote: > John Ochiltree wrote: > >> Hello group, >> >> What do I have to do to set up python 2.3 to run centrally on a Win >> 2000 network instead of installing it on every workstation? > > > Well, if you have a Windows network, you need scripted installs :-P > Otherwise administering a Windows network is too much of a PITA in my > opinion. > >> Is it possible? > > > Sure. Get an installed Python, copy the c:\python23 directory to a > network share, then grab the file %SYSTEMROOT%\system32\python23.dll and > copy it alongside python.exe. Now all your clients can access Python via > the share name. > >> How do I go about updating individual registeries? I'd appreciate some >> pointers and advice if any one can help. > > > Python itself doesn't need any registry entries. If you use the COM > stuff of the win32 extensions, though, this might be different. > > -- Gerhard > Cheers Gerhard, Worked like a dream. I now have a shared python shell John From Spam.Buster at web.de Wed Aug 20 03:52:02 2003 From: Spam.Buster at web.de (Lars Behrens) Date: Wed, 20 Aug 2003 09:52:02 +0200 Subject: 'name is too long' (tarfile, python 2.2, Debian Woody) Message-ID: Hi, Pythonistas! I'm quite new to Python and have a problem with a simple backup script. This code: tar = tarfile.open('/home/lars/test.tar.gz', 'w:gz') tar.addfile('/home/lars') brings up the following error message: ********************************************************************** /usr/lib/python2.2/site-packages/tarfile.py in addfile(self, tarinfo, fileobj) 1289 1290 if not prefix or len(name) > LENGTH_NAME: -> 1291 raise ValueError, "name is too long (>%d)" \ 1292 % (LENGTH_NAME) 1293 ValueError: name is too long (>100) ********************************************************************** Any hints for me? Thanks in advance Lars From fredrik at pythonware.com Sun Aug 17 14:40:31 2003 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 17 Aug 2003 20:40:31 +0200 Subject: Strange re behavior: normal? References: Message-ID: Michael Janssen wrote: > Well, I belive it's good choice, to not split a string by an empty > string, but when you really want (version with empty results on start > and end omitted): > > def boundary_split(s): > back = [] > while 1: > try: > # r'.\b' and +1 prevents endless loop > pos = re.search(r'.\b', s, re.DOTALL).start()+1 > except AttributeError: > if s: back.append(s) > break > back.append(s[:pos]) > s = s[pos:] > return back note that \b is defined in terms of \w and \W, so you can replace the above with: def boundary_split(text): return re.findall("\w+|\W+", text) > What's the good of splitting by boundaries? Someone else wanted this a > few days ago on tutor and I can't figure out a reason by now. the function extracts the words from a text, but includes the non-word parts in the list as well (unlike, e.g. text.split() and re.findall("\w+")). might be useful if you're writing some kind of text filter. for part in re.findall("\w+|\W+", text): ... here's an alternative pattern, which might be easier to use: for word, sep in re.findall("(\w+)(\W*)", text): ... PS. for proper support of non-ASCII text, prefix the pattern with (?u) for ISO-8859-1 or Unicode strings, or (?L) to support localized text (locale.setlocale). From PoulsenL at capanalysis.com Wed Aug 6 15:10:45 2003 From: PoulsenL at capanalysis.com (PoulsenL at capanalysis.com) Date: Wed, 6 Aug 2003 15:10:45 -0400 Subject: Kill a named process in win2K not spawned by python Message-ID: <72F73B808A78D511A73600034771D9FF71862D@dc_exchange2.howrey.com> Can someone give me a clue how to rewrite this kludgy workaround in python? import os from win32pdhutil import * pid = FindPerformanceAttributesByName("WINWORD")[0] os.system("C:\CMDUtils\kill " + str(pid)) Thanks, Loren Poulsen -------------------------------------------------------------------------------------------------------------------- This email and any attachments contain information from CapAnalysis, LLC, which may be confidential and/or privileged. The information is intended to be for the use of the individual or entity named on this email. If you are not the intended recipient, be aware that any disclosure, copying, distribution or use of the contents of this email is prohibited. If you receive this email in error, please notify us by reply email immediately so that we can arrange for the retrieval of the original documents at no cost to you. From cpbarton at pacific.net.au Sat Aug 30 13:08:24 2003 From: cpbarton at pacific.net.au (Ideasman) Date: Sat, 30 Aug 2003 13:08:24 -0400 Subject: My script is taking 12 hours+ any suggestions? Message-ID: <3f4ff9f8$0$23588$5a62ac22@freenews.iinet.net.au> Hi I have a made a script that process normals for a flat shaded 3D mesh's. It compares every vert with every other vert to look for verts that can share normals and It takes ages. I'm not asking anyone to rewrite the script- just have a look for any stupid errors that might be sucking up time. #!/usr/bin/python ############## # AUTOSMOOTH # ############## import sys import os import string import math # Used to write floats that dont' contain letters/ def saneFloat(float): #return '%(float)b' % vars() # 6 fp as house.hqx return '%f' % float # 10 fp #Open file from the command line, turn into a list and close it. file = open(sys.argv[-1], 'r') fileLineList = file.readlines() file.close # Remember the number of lines for progress indication. fileLen = len(fileLineList) # Autosmooth value. Higher will autosmooth larger angles. maxDiff = 1.66 # Loop through the lines. lineIndex = 0 while lineIndex < len(fileLineList): #Find Geom TAG.. if str(fileLineList[lineIndex])[0:8] == 'Geometry': lineIndex += 1 # break if looping beyong the file, if lineIndex > len(fileLineList): break # Here we remember lines that have been processed. # it needs to be reset for each geom object. listOfDoneLines = [] # Start a new loop that checks the current vert against all the others newLoopindex = lineIndex while len(string.split(fileLineList[newLoopindex])) == 12: print '\n', fileLen, newLoopindex, #vertexnum = newLoopindex - lineIndex # Compare the 2 lines newCompareLoopindex = newLoopindex + 1 # compare the current vert to this new one. thisPassDoneLines = [] # act apon this after comparing with each vert thisPassDoneNormals = [] while len(string.split(fileLineList[newCompareLoopindex])) == 12: # Speed up the process by using 2 if's, splitting the string only if it has not been evaluated already. if newCompareLoopindex not in listOfDoneLines: comp1 = string.split(fileLineList[newLoopindex]) comp2 = string.split(fileLineList[newCompareLoopindex]) if [comp1[0], comp1[1], comp1[2]] == [comp2[0], comp2[1], comp2[2]]: if newLoopindex not in listOfDoneLines: # Only needs to be added once listOfDoneLines.append(newLoopindex) if newLoopindex not in thisPassDoneLines: # Only needs to be added once thisPassDoneLines.append(newLoopindex) thisPassDoneNormals.append([eval(comp1[8]), eval(comp1[9]), eval(comp1[10])]) listOfDoneLines.append(newCompareLoopindex) thisPassDoneLines.append(newCompareLoopindex) thisPassDoneNormals.append([eval(comp2[8]), eval(comp2[9]), eval(comp2[10])]) print '#', newCompareLoopindex += 1 if len(thisPassDoneLines) > 1: # Ok We have some verts to smooth. # This loops through all verts and assigns each a new normal. for tempLineIndex in thisPassDoneLines: tempSplitLine = string.split(fileLineList[tempLineIndex]) # We add to these for every vert that is similar, then devide them to get an average. NormX = 0 NormY = 0 NormZ = 0 # A list of vert line indicies that we will create to store verts that have normals close to ours. thisVertFrendsCount = 0 # This compares the current vert with all the others, if they are close then add to vertFrends. for tNorm in thisPassDoneNormals: # tNorm is just used for one of the normals in the thisPassDoneNormals if abs(eval(tempSplitLine[8]) - tNorm[0]) + abs(eval(tempSplitLine[9]) - tNorm[1]) + abs(eval(tempSplitLine[10]) -tNorm[2])< maxDiff: #maxDiff NormX += tNorm[0] NormY += tNorm[1] NormZ += tNorm[2] thisVertFrendsCount += 1 #Now devide the normals by the number of frends. NormX /= thisVertFrendsCount NormY /= thisVertFrendsCount NormZ /= thisVertFrendsCount # make unit length vector. d = NormX*NormX + NormY*NormY + NormZ*NormZ if d>0: d = math.sqrt(d) NormX/=d; NormY/=d; NormZ/=d # Write the normal to the current line tempSplitLine[8] = str(saneFloat(NormX)) tempSplitLine[9] = str(saneFloat(NormY)) tempSplitLine[10] = str(saneFloat(NormZ)) fileLineList[tempLineIndex] = string.join(tempSplitLine) + '\n' newLoopindex += 1 lineIndex += 1 # Writing to file # file to write file = open(sys.argv[-1], 'w') file.writelines(fileLineList) file.close() From surfing214 at msn.com Sat Aug 23 00:36:43 2003 From: surfing214 at msn.com (planeglenn) Date: Sat, 23 Aug 2003 00:36:43 -0400 Subject: Testing Message-ID: <1061613394.311279@www.vif.com> Hello, I am trying a test to se if this works. Thank you. From tjreedy at udel.edu Tue Aug 5 01:50:53 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 5 Aug 2003 01:50:53 -0400 Subject: PyChecker work with Python 2.3? References: <3F2C5300.FA223CBA@easystreet.com> <3F2EB773.4895B5DD@easystreet.com> <3F2EE9C7.A38F7912@easystreet.com> Message-ID: <1MKcnR3fbYoj2LKiXTWJgA@comcast.com> wrote in message news:3F2EE9C7.A38F7912 at easystreet.com... > I didn't have to change anything else. I guess that I'm still ok > importing generators from the future even though they are no longer > in the future. It is quite intentional that future imports be simply ignored when 'obsolete' and not suddenly make program not run. tjr From brian at sweetapp.com Sun Aug 10 20:31:04 2003 From: brian at sweetapp.com (Brian Quinlan) Date: Sun, 10 Aug 2003 17:31:04 -0700 Subject: Python vs. C# In-Reply-To: <3f36af20@shknews01> Message-ID: <000001c35f9f$d96cc990$21795418@dell1700> > Microsoft does almost all of its internal development in C# now. Do you have any basis for this claim? I would imagine that most of Microsoft's development effort goes into Office and Windows, and neither of those products currently use the .NET framework. > It is not going away. I agree. > C# is, essentially, the .NET Framework. Nope. That statement is as meaningless as "C++ is, essentially, the STL". > But comparing C# to Python, Python isn't much higher level than C#. Yes it is. I find it odd that you claim to have very little knowledge of C# yet you make some very bold claims as to its characteristics (actually, IIRC, you have only made one specific claim about the semantics of the language and that was incorrect). > They've got "similar stuff," with Python adding some exotic features. No, they don't have "similar stuff". C# is missing a lot of features with respect to Python. And Python has, at least for GUI programming, no equivalent to the .NET framework. > Python gets style points, but tools maturity, ubiquity, and future > count for more than style points. I wouldn't use the word "maturity" when discussing C# tools but the VS .NET IDE is quite impressive when it works correctly. I'm starting to think that you are trolling. Are you? Cheers, Brian From peterenis at gmx.net Sat Aug 30 13:20:15 2003 From: peterenis at gmx.net (Peter Enis) Date: 30 Aug 2003 19:20:15 +0200 Subject: variable in regexp Message-ID: <1062264015.4586.4.camel@localhost.localdomain> hello, does anyone know how to use variables in regular expressions? var = '%%bob%%' replace = 'bob' var = re.sub("%%[^%%]*replace%%', 'peter', var) how do i have to mask the replace-variable? thanx From jroznfgre at jngpugbjreQBGbet.cy Wed Aug 13 10:48:26 2003 From: jroznfgre at jngpugbjreQBGbet.cy (JZ) Date: Wed, 13 Aug 2003 16:48:26 +0200 Subject: libmysqld.dll & Python API seeking... References: Message-ID: On Wed, 13 Aug 2003 13:50:48 +0200, Gerhard H?ring wrote: >MySQLdb can be built against MySQL 4.x. It should be certainly possible >to make it work against the embedded version of MySQL. Last time I tried >the result was that at .connect time it crashed. But if you invest more >time than me (more than 2 minutes), you can probably get it working ;-) It is not so easy, because I need Win32 version of such MySQLdb :( I try to compile the source using Bloodsheed DevC++ 4.9.8.1 (http://www.bloodshed.net/) but without result. I added header files from Python 2.2.3 but it did not help. :( From vanevery at 3DProgrammer.com Tue Aug 19 01:39:09 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Mon, 18 Aug 2003 22:39:09 -0700 Subject: Brandon's personal style (was) References: <38ec68a6.0308172319.431a4fde@posting.google.com> Message-ID: Michael Geary wrote: > > But my goodness! Now I can see what all the fuss was about. You even > killfiled Doug Tolton, Is Doug Tolton pure? Let's see, what did I killfile him for... ah, here was the first bit. Doug Tolton wrote: > On Mon, 11 Aug 2003 14:16:35 +0200, Max M wrote: >> Bob Gailer wrote: >>> What is "trolling"? > > Ugh...he got me. So at this point, Doug has already decided that I'm a troll. He hasn't applied critical thinking, he's just running with the pack. I responded, explaining myself, but didn't killfile him. Later on, Doug makes a post that explicitly flames me and doesn't include any info about Python or Ruby whatsoever. He said I was ranting, whining, and begging, and he wasn't trying to be at all useful about it. So I killfiled him. Surprised? > who made some very insightful comments about > the benefits of macros today in this Ruby thread. So what? Sometimes you forego information when the source is too much trouble. Besides, if it's a really really really great point, someone else will reply to it and I'll see an executive summary indirectly. > Brandon, learn to roll with the punches and have some fun with the > rest of us. I'm a pugilist. If someone punches me, I'd sooner smash their face in and be done with it. There are so many other people to talk to that don't take jabs at you. > What good does it do *you* when you say to someone, "You > said something I don't like. You failed to satisfy my needs in this > conversation. I will never listen to anything you ever say again!" Oh, I don't killfile people *forever*. The first reprieve generally comes at system reinstall. When all the killfiles acidentally get wiped out, or I change newsreaders, or something like that. Everybody gets a second chance at that point. People who still insist on being trouble at that point, get killfiled for many years. I've known a few, like 2 or 3. Even they mellow out with age. But that can be as long as 5 years. At some point, such people look back over those 5 years and realize I wasn't personally around to be their whipping boy or irritant for most of that time. So, they realize it was them, not me. > Would you do that in a face to face conversation? I didn't think so. Most people don't have this much trouble face-to-face. There's so much extra information: tone, facial expression, body posture, hand gestures. It's easier for people to take comments in the manner they were intended, and it's easier for people to see they're pissing someone else off and back down. E-mail and newsgroups are inherently imperfect media, and I will not try to change them. > So try this: delete that silly killfile, cultivate the sense of humor > you've shown in the rattlesnake thread--I knew you could do it!--and > be willing to say, "Folks, I know I've been a bit abrasive and > antagonistic in the past, and I apologize for that. I really would > like to get a fresh start here and I'm curious to hear your thoughts > on these questions." No, I shall not. I acknowledge and own my abrasion, I don't apologize for it. Nothing I say should be that tough for people to swallow. But, there are always people who are emotional and reactive, who think something big is at stake. I know these people are always out there... I recognize that I reap what I sow. But I will continue to sow. Because I've tried the other way, the polite way, the diplomatic way, and you know what? People flame anyways. That has always been the pattern. No matter what you say, *someone* has to make a problem out of it. And those people, they go in the killfile and stay there. Case in point: my first "What's better about Ruby than Python?" post. I explicitly said, this is not a troll. Some chose to flame and accuse anyways. Such people are useless, there is nothing you can do with them. > Fair enough? My smiles are for those who smile. Or for those who frown, but realize their frown is a mirror. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From camelo at esss.com.br Wed Aug 27 15:52:47 2003 From: camelo at esss.com.br (Marcelo A. Camelo) Date: Wed, 27 Aug 2003 16:52:47 -0300 Subject: Python memory management In-Reply-To: <7h3ekz76jyd.fsf@pc150.maths.bris.ac.uk> Message-ID: <000001c36cd4$ca7779c0$0d00000a@esss.com.br> > From: python-list-admin at python.org > [mailto:python-list-admin at python.org] On Behalf Of Michael Hudson > > "Marcelo A. Camelo" writes: > > > Currently, the most popular platform for game applications are > > videogame consoles. Memory on these special purpose machines are a > > premium resource and one should used it judiciously. Python's RTE > > footprint and memory fragmentation issues make it a hard > > sell for game programmers (many tend to prefer LUA). > > Um, *I*, at least, would say they have a point. I love > Python and think it has many, many virtues, but being miserly > with RAM is not one of them (at least, for the current > implementation). Yes, I will be saying that. But, if I can't change the way Python behaves, at least I want a way to diagnose what he is doing. I've found some references about Pymalloc, now the default Python memory manager, and how it can report statistics about memory usage, but the documentation is a bit light on details. Any pointer to some resources on the subject? Maybe python-dev is a better place to ask these questions. Thank you any way, --camelo From skip at pobox.com Thu Aug 21 10:37:16 2003 From: skip at pobox.com (Skip Montanaro) Date: Thu, 21 Aug 2003 09:37:16 -0500 Subject: Removing language comparisons In-Reply-To: References: Message-ID: <16196.55580.321253.88086@montanaro.dyndns.org> Duncan> How about getting some new articles to be written by pairs of Duncan> people, one Python user who knows a bit of the other language Duncan> and one person who lives and breathes Perl/Java/Ruby/etc but Duncan> knows a bit of Python? Did I just hear you volunteer to head up the effort? ;-) Skip From rowen at cesmail.net Fri Aug 15 13:38:31 2003 From: rowen at cesmail.net (Russell E. Owen) Date: Fri, 15 Aug 2003 10:38:31 -0700 Subject: ftp get from a Tkinter gui: advice wanted Message-ID: I'm writing a Tkinter app (telescope remote controller). The application presently runs on unix and MacOS X and I think some users will want to use Windows. It's going just fine, but I'm trying to add the ability to automatically get images via binary ftp (i.e. as each image is recorded) and am realizing it's harder than I though. Ideally, I'd like image download to work like a typical web browser download: a status window that shows each transfer, how far along it is, allows the user to cancel it, etc. This sounds messy to write, though I'll certainly do it if it comes to that. So I'm asking for advice before diving in -- especially as I hate to reinvent the wheel. I'm hoping somebody has either written such a beast already (in Tkinter or Tk), but a Google search hasn't turned up anything yet. Anybody have any hints where to look? I'd also be fairly happy to have a web browser to do the download (it's not perfect -- one loses the ability to automatically put the files in the right place -- but it'd do). However, my attempts to use the webbrowser module for this on MacOS X are not working. I have unix command-line 2.2.2 and aqua framework 2.3 both installed. Neither actually ever calls my web browser when I supply the ftp link. The unix version does try to download the file (with no feedback) and ends up downloading an empty file with no feedback (not much use). The latter reliably hangs the Finder (I'm about to file a bug report). Any advice or suggestions would be very much appreciated. -- Russell From mb at muenster.de Sat Aug 2 05:20:52 2003 From: mb at muenster.de (Martin Bless) Date: Sat, 02 Aug 2003 09:20:52 GMT Subject: Detect PythonWin? References: <3f29fe44.104328@news.muenster.de> <3nednT2SvbmC-reiXTWJjQ@comcast.com> Message-ID: <3f2c7aaf.3486640@news.muenster.de> [Brett g Porter:] >Is there a subtle reason that you can't pass the arguments using the >"Arguments" field on the PythonWin "Run Script" dialog? (1) Yes, there is, very subtle =:-) [shame ON] I simply have overlooked the argument field since that long - unbelievable. [shame OFF] Got that very much used to pressing ctrl+r or F10 that I never really noticed the dialog anymore. Once you're blind, ... (2) But: I need the PythonWin detector as well - to skip code that doesn't run (well) in PythonWin (e. g. low level stuff) - to conditionally set hardcoded breakpoints for analyses - to turn off verbose output, for instance a counter which is displayed in a single line of the command window. Now I can do #untested cnt = 0 for item in items: cnt += 1 if sys.modules.has_key('pywin'): pass "or display in a message box. How is that done???" else: print cnt, # stay in line msvcrt.putchr('\r') # carriage return to beginning of line (3) Thank you all for answering. Writing either if 'pywin' in dir(): pass or, I think, better: CHECKPYWIN = True ... import sys if CHECKPYWIN and sys.modules.has_key('pywin'): "work" is exactly what I need. Seems robust enough. And additionally, to be on the safe side, I will set the 'constant' CHECKPYWIN to False once testing is done, leaving no ambiguities. (4) I'd love to see this issue addressed somewhere in the PythonWin helpfiles!? thank you all Martin From tim.one at comcast.net Wed Aug 6 14:38:11 2003 From: tim.one at comcast.net (Tim Peters) Date: Wed, 6 Aug 2003 14:38:11 -0400 Subject: FWD: Re: Problem w/ IDLE on Win2000 In-Reply-To: <1060194518.3f3148d6d9f43@mcherm.com> Message-ID: [Tim] >> Speaking of which, that doesn't look likely to change anytime soon, >> so if someone else is willing to take over the PLabs Windows >> installer, it's yours. [Michael Chermside] > I know nothing about the installer (or about installers in general). > If it's just a matter of testing it out for releases, no problem, but > how much difficulty am I going to be in if I volunteer here? You would need a copy of Wise, and would be signing up to "deal with" installer bug reports, feature requests, random whining, and changes to the installer to cope with changes in the set of files we need to install (the Unix-heads routinely make changes that break the Windows installer, and the latter needs to be taught about the changes the former make -- no file gets installed unless the installer is told about it). But if you had to ask, you don't want to volunteer . From mschneider.pad at t-online.de Sun Aug 17 18:54:49 2003 From: mschneider.pad at t-online.de (Marcus Schneider) Date: 17 Aug 2003 15:54:49 -0700 Subject: closing a widget Message-ID: <3f443b52.0308171454.c00a287@posting.google.com> Normally I close my windows/widgets with destroy and it works fine. Now I have a window (let's call it 1) from where I open an additional window (let's call it 2). I close it. Each window has its own main loop. Now I want to open another window outside the mainloop of window 1. So I quit that mainloop, go to a new window, destroy that, enter the mainloop of window 1 again and finally exit with destroy. All this works in princial, but here's the funny behaviour: 1) If I don't enter 2 quit works, if I do enter 2, I have to press the "quit button" 2 times. Actually I have to press it an additional time for every time I opened the window 2. What is happening? How can I stop that??? 2) For whatever reason I also have to click two times on the "destroy" button at the end of the example. The destroy command is only executed the second time I press the button ???!!! All the widgest/windows are stand alone object and use their own variables.. From andrew-pythonlist at puzzling.org Fri Aug 1 01:34:21 2003 From: andrew-pythonlist at puzzling.org (Andrew Bennetts) Date: Fri, 1 Aug 2003 15:34:21 +1000 Subject: A very simple question In-Reply-To: References: Message-ID: <20030801053421.GC32720@frobozz> On Thu, Jul 31, 2003 at 05:13:36PM -0800, Arnaldo Riquelme wrote: > > I'm getting familiar with Python and I have a simple question: > > class abc: > x = 100 > y = 200 > z = 300 > > > ac = abc() > > Shouldn't I have a attribute named __dict__ for ac that contains a > dictionary of all the variables? > > Instead when I do: > print ac__dict__ > > I get an empty dictionary {} > > However: > > print abc.__dict__ works. > > I'm missing something somewhere, can anyone please enlight me on this > matter. You've practically answered your own question ;) Those variables (x, y and z) are defined on the *class*, so they appear in the class's dictionary. Your instance doesn't have any variables of its own, so its dictionary is empty. Note that "print ac.x" would still print 100, because attribute lookup on instances (by default) does this: - first, check for the attribute on the instance - if not found, then check for the attribute on the class [Similarly, attribute lookup on classes does this: - first, check for the attribute on this class - if not found, then check each of this class's immediate base classes in turn (more-or-less... cyclic inheritance graphs change this a little). This gives a 'depth-first' search. ] So, your code probably will work how you expect, even though the attributes might not be where you expect them. ;) If you want to define those attributes per-instance automatically, write your class like this: class ABC: def __init__(self): self.x = 100 self.y = 200 self.z = 300 Now you'll get these results: >>> a = ABC() >>> a.__dict__ {'y': 200, 'x': 100, 'z': 300} >>> ABC.__dict__ {'__module__': '__main__', '__doc__': None, '__init__': } -Andrew. From mwh at python.net Tue Aug 19 06:34:41 2003 From: mwh at python.net (Michael Hudson) Date: Tue, 19 Aug 2003 10:34:41 GMT Subject: union in Python References: Message-ID: <7h3he4eym2r.fsf@pc150.maths.bris.ac.uk> bokr at oz.net (Bengt Richter) writes: > I wonder why find doesn't take advantage of the same thing, whatever > it is (Boyer-Moore? or some running fifo window hash > check?). Probably the usual ... people who can do it are too busy > to do it in free time, and no-one's throwing money ;-) I really don't think it's expected that people are using str.find with data big enough for this to make a difference. There's mxTextTools (at least) for that. Cheers, mwh -- if-you-need-your-own-xxx.py-you-know-where-to-shove-it-ly y'rs - tim -- Tim Peters dishes out versioning advice on python-dev From gregbrunet at NOSPAMsempersoft.com Sat Aug 30 03:48:20 2003 From: gregbrunet at NOSPAMsempersoft.com (Greg Brunet) Date: Sat, 30 Aug 2003 02:48:20 -0500 Subject: Add two dicts References: <86ktkvkd05e88hu14hjudmfvbul7slfgkt@4ax.com> <3F4EDF7A.C9CF6DA3@alcyone.com> <0mrtkv8b1bnnk1v310kf3b8tmjo8d9higo@4ax.com> Message-ID: "Greg Brunet" wrote in message news:vl0heutm63na0 at corp.supernews.com... > "Greg Brunet" wrote in message > news:vl0gbotgl3sibf at corp.supernews.com... > > But what about something like this: > > > > >>> class xdict(dict): > > ... def __add__(self,dict2): > > ... result = self.copy() > > ... result = result.update(dict2) ... I was getting sloppy in the interactive mode. Instead I did this & it seems to work properly: class xdict(dict): def add(self,dict2): result = self.copy() result.update(dict2) return result def __add__(self,dict2): result = self.copy() result.update(dict2) return result def __iadd__(self,dict2): self.update(dict2) return self a=xdict({'x':1}) b=xdict({'y':2}) print print "Add:", a.add(b) print "+:", a+b print "a:",a,"b:",b a+=b print "+= (a=):", a Results: Add: {'y': 2, 'x': 1} +: {'y': 2, 'x': 1} a: {'x': 1} b: {'y': 2} += (a=): {'y': 2, 'x': 1} -- Greg From dmgriffith_not_ at tasc.com Tue Aug 5 15:42:43 2003 From: dmgriffith_not_ at tasc.com (Dang Griffith) Date: Tue, 05 Aug 2003 15:42:43 -0400 Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> Message-ID: Anthony_Barker wrote: .. > What about immutable strings? I'm not sure I understand Guido's > preference for them. .. Strings are also immutable in Java. Maybe Guido likes Java? ;-) --dang From mis6 at pitt.edu Sun Aug 24 07:46:26 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 24 Aug 2003 04:46:26 -0700 Subject: Metaclass discussons References: Message-ID: <2259b0e2.0308240346.35319743@posting.google.com> Gustavo Niemeyer wrote in message news:... > Hi everyone! > > I was just part of a small discussion concerning metaclass features on > Python, and one limitation that was appointed was the inability to > redefine metaclasses on existent code. Than I thought it was a good > way to explore some more the metaclass concepts.. > > Basically, people were arguing that there are some uses for that, based > on plugging new knowledge on existent classes and instances. Without > complaining too much about usage issues, I started looking for ways to > dismiss that limitation. > > Without yet considering interpreter hacks, that's what I had as a first > solution (a very limited one, I must admit): > > class M(type): pass > __metaclass__ = M > class object: > __metaclass__ = M > execfile("somemodule.py", globals(), locals()) > > Can you imagine any alternative which is not based on the same concept > (executing the module code on a hacked context)? Oh, what a wonderfully evil hack! Thanks Gustavo, I never come to my mind that I could redefine the object class! I was using the hack of modifing the source code by adding a __metaclass__ atribute and re-exec-uting it, but I didn't like the trick. Then I wrote a script to regenerate an entire hierarchy with a different metaclass. Much less hackish, but a bit non-trivial. Your idea is perfect for easy hacks in the debugging phase (i.e. add a metaclass generating logging capabilities or other more general debugging utilities). You can spell it even as class object(object): class __metaclass__(type): pass # rest of the code Michele Simionato, Ph. D. MicheleSimionato at libero.it http://www.phyast.pitt.edu/~micheles --- Currently looking for a job --- From stephan.diehl at gmx.net Tue Aug 12 09:28:37 2003 From: stephan.diehl at gmx.net (Stephan Diehl) Date: Tue, 12 Aug 2003 15:28:37 +0200 Subject: MySQLdb and Python2.3 Message-ID: Since using Python2.3, MySQLdb doesn't work anymore correctly. Inserting data fails with "IndexError: list index out of range". Since the MySQLdb website states, that it runs up to version 2.2, I definatelly shouldn't complain :-) Is there somebody whose MySQLdb is running with 2.3? MySQLdb 0.9.2 Python 2.3 Linux Thanks a lot for your help Stephan From Rastm2 at users.sourceforge.net Thu Aug 7 18:21:03 2003 From: Rastm2 at users.sourceforge.net (Raymond A. St. Marie) Date: 7 Aug 2003 15:21:03 -0700 Subject: Newbie Testing IDLE 1 on win98 Message-ID: <5540514a.0308071421.37663e8b@posting.google.com> Hi Y'all Newbie Ray here. Running win32 installer version of Python2.3 on win98(notSE) I decided to run the autotest from IDLE 1 window. """ 1 skip unexpected on win32: test_univnewlines """ I need to know if this is significant. Also, the test_descr failed, so I ran it separatly and here's where it crashed. """ Testing special operators... Traceback (most recent call last): File "C:\Python23\Lib\test\test_descr.py", line 4029, in -toplevel- test_main() File "C:\Python23\Lib\test\test_descr.py", line 3973, in test_main specials() File "C:\Python23\Lib\test\test_descr.py", line 1875, in specials print Letter('w') PicklingError: Can't pickle : attribute lookup __main__.Letter failed """ Am I in trouble? Is this a Biggie? TIA Ray St. Marie Rastm2 at users.sourceforge.net From aleax at aleax.it Thu Aug 21 12:18:49 2003 From: aleax at aleax.it (Alex Martelli) Date: Thu, 21 Aug 2003 16:18:49 GMT Subject: Removing language comparisons References: Message-ID: A.M. Kuchling wrote: > On Thu, 21 Aug 2003 12:07:33 +0000 (UTC), > Duncan Booth wrote: >> How about getting some new articles to be written by pairs of people, one >> Python user who knows a bit of the other language and one person who >> lives and breathes Perl/Java/Ruby/etc but knows a bit of Python? That way >> you > > A good idea, but unless some volunteer steps forward to do the work, it's > not going to happen. Oh, I _have_ "volunteered" to write the Python side of this if we can find the right person for the Ruby side -- and Dave Thomas appeared interested when I mentioned this to him at his OSCON Ruby seminar, and Cameron Laird appeared fascinated by the idea and volunteered to be the "referee" and 3rd co-author if we need one. Now we "just" need to find some slice of time &c reasonably free and mutually agreeable to Dave, Cameron AND me (admittedly no easy task) and we could try... Alex From dreico at wanadoo.fr Fri Aug 29 10:21:28 2003 From: dreico at wanadoo.fr (Andrei) Date: Fri, 29 Aug 2003 16:21:28 +0200 Subject: cannot get pexpect to work Message-ID: Hi, I'm at a crucial stage in the development of a wide area (multi-host) ssh wrapper, and need to control what happens when a host requires password authentication. After installing pexpect, the example script that looks most inclined to help me (by basically handling this situation,) "passmass.py" seems to fail, from whatever host to whatever host eg. [user1 at baddog01 scripts]$ ./passmass.py localhost Username: user1 Current Password: New Password: Confirm New Password: 'Timeout exceeded in read().' <<< ? Does anyone have a clue what's going on? Many thanks Andrei. From gusd at handsome.com.cn Thu Aug 7 21:41:43 2003 From: gusd at handsome.com.cn (Gu Shaodong) Date: Fri, 08 Aug 2003 09:41:43 +0800 Subject: Phthon2.3 on win2ksp4 problem Message-ID: <3F32FFD7.8010803@handsome.com.cn> Hi, guys: It's my first time to be here, forgive me if I'm asking a question in wrong place. If so, please tell me where is suitable for my question. I just installed Phthon2.3 on win2k sp4, everything is fine through the installation process.After that, I try to launth the IDLE(Python GUI) icon from the start menu. Then, I mentioned there's some hard-disk traffic. But to my surprise, no gui windows come out to me. I also checked the taskmanager, there's a phthonw process running. Any help about this ? TIA -gusd From theller at python.net Thu Aug 7 09:22:47 2003 From: theller at python.net (Thomas Heller) Date: Thu, 07 Aug 2003 15:22:47 +0200 Subject: crossplatform py2exe - would it be useful? References: Message-ID: <4r0thaag.fsf@python.net> Alex Martelli writes: > Thomas Heller wrote: > ... >>>> myscript -c "import sys; sys.path.insert(0, sys.executable); import foo" > ... >>> Sounds like a good idea to me, if a sensible name is chosen for the >>> "main module" (I propose 'main':-). >> >> My choice would have been __main__ :-) Is it really the correct way to >> 'import __main__' instead of 'running' it? > > Well, most main scripts ARE coded with the "if __name__=='__main__':" > convention, after all, so an "import __main__" can be seen as a way > to just piggyback on that existing convention rather than inventing a > new one in addition. So, I concede it's better than "import main". Ok. So who writes the PEP ? Thomas From vanevery at 3DProgrammer.com Mon Aug 18 14:07:56 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Mon, 18 Aug 2003 11:07:56 -0700 Subject: What's TOTALLY COMPELLING about Ruby over Python? Message-ID: I'm realizing I didn't frame my question well. What's ***TOTALLY COMPELLING*** about Ruby over Python? What makes you jump up in your chair and scream "Wow! Ruby has *that*? That is SO FRICKIN' COOL!!! ***MAN*** that would save me a buttload of work and make my life sooooo much easier!" As opposed to minor differences of this feature here, that feature there. Variations on style are of no interest to me. I'm coming at this from a C++ background where even C# looks like an improvement. ;-) From 10,000 miles up, is there anything about Ruby that's a "big deal" compared to Python? One person mentioned Japanese documentation. I'm sure that's Totally Kewl to the Japanese.... -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From tzot at sil-tec.gr Fri Aug 22 05:49:01 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Fri, 22 Aug 2003 12:49:01 +0300 Subject: itertools expansion time has arrived? Message-ID: Hi all, although more like "hi Raymond" :) Since 2.3 is out, now, perhaps it's time to add the itertools.window, itertools.weave (and maybe others I did not happen to read about). I don't know if Raymond needs any help, I'd be glad to. Basically this is a reminder :) -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From peter at engcorp.com Fri Aug 29 11:02:08 2003 From: peter at engcorp.com (Peter Hansen) Date: Fri, 29 Aug 2003 11:02:08 -0400 Subject: cannot get pexpect to work References: Message-ID: <3F4F6AF0.CA9BB337@engcorp.com> Andrei wrote: > > Hi, > > I'm at a crucial stage in the development of a wide area (multi-host) ssh > wrapper, and need to control what happens when a host requires password > authentication. After installing pexpect, the example script that looks most > inclined to help me (by basically handling this situation,) "passmass.py" > seems to fail, from whatever host to whatever host eg. > > [user1 at baddog01 scripts]$ ./passmass.py localhost > Username: user1 > Current Password: > New Password: > Confirm New Password: > 'Timeout exceeded in read().' <<< ? > > Does anyone have a clue what's going on? No, but why is it asking for a new password confirmation? You're just trying to log in, not change the password, aren't you? Or does passmass.py actually change the passwords, not just log in? (I don't have the script.) Have you read it? Perhaps you've misinterpreted what it is supposed to do. -Peter From tzot at sil-tec.gr Mon Aug 4 11:46:59 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Mon, 04 Aug 2003 18:46:59 +0300 Subject: anti-aliased 2D vector graphics References: Message-ID: <0pvsivgtkgv7b7f0tcekmr11tanbqmhq8e@4ax.com> On Sat, 02 Aug 2003 01:43:50 GMT, rumours say that "Andy C" might have written: >A little off topic, but is this how it is typically done? Is there a >special case for lines vs. fonts? Ah, *that* was your question (I was hasty in answering a few minutes earlier). I believe that yes, this is what is typically done for line art; but my answer is not authoritative. For fonts, I do not know for certain, although I know for certain that this is what *I* have done in a simple "ClearType"-like-display text reader I have written for reading texts in my Win2K notebook (I won't bother installing XP *only* for the ClearType capability). -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From csa at csa-net.dk Sun Aug 31 03:50:12 2003 From: csa at csa-net.dk (Claus Alboege) Date: Sun, 31 Aug 2003 09:50:12 +0200 Subject: confirm unsubscribe from zsh-users@sunsite.dk References: Message-ID: <20030831.095012515090500@csa-net.dk> "Terry Reedy" writes: > wrote in message > news:mailman.1062283998.26328.python-list at python.org... >> Hi! This is the ezmlm program. I'm managing the > > Hi, exmlm > >> zsh-users at sunsite.dk mailing list. >> >> To confirm that you would like >> >> python-list at python.org >> >> removed from the zsh-users mailing list, please send an empty reply >> to this address: >> >> > zsh-users-uc.1062283803.okifnhokaldgjdaajooj-python-list=python.org at su > nsite.dk >> >> Usually, this happens when you just hit the "reply" button. >> If this does not work, simply copy the address and paste it into >> the "To:" field of a new message. >> >> I haven't checked whether your address is currently on the mailing > list. > > Then you are a pretty dumb program. I bet it is not. You should know > that any 'user' called xxx-list is another mailing list and that any > attempt to subscript or unsubscript such is a casual or malicious joke > (possibly from viruses, as probably with this case). Ever heard of sublists? And about people using different addresses for each list they subscribe to, such as user-xxx-list at dom.tld? > What would you do if I forged an email trying to subscribe/unsubscribe > zsh-users to/from itself? Would you send a messege asking it to reply? Yes, but the confirmation request would never reach the list. Ezmlm will reject messages containing a "Mailing-List" header. (Unless it has been configured as a sublist) Probably Mailman should do the same!? /Claus A From andrew-pythonlist at puzzling.org Fri Aug 22 01:08:23 2003 From: andrew-pythonlist at puzzling.org (Andrew Bennetts) Date: Fri, 22 Aug 2003 15:08:23 +1000 Subject: Running one single test... In-Reply-To: <200308212116.09167.tjg@craigelachie.org> References: <200308212116.09167.tjg@craigelachie.org> Message-ID: <20030822050823.GA8563@frobozz> On Thu, Aug 21, 2003 at 09:16:08PM -0700, Timothy Grant wrote: > At work we use Perl and a home rolled unittesting mechanism. One of the things > I love about That testing mechanism is that I can run one single test. In > fact, I've configured Vim to run the current test and either tell me if it > passes or tell me the error when it doesn't. > > I'd love to do something similar with PyUnit, but I have yet to figure out how > to run one single test. > > Any help would be greatly appreciated. Twisted has a PyUnit-compatible unit testing tool called trial that can do this; it has a command-line utility that allows you do all of these: $ trial twisted.test $ trial twisted.test.test_imap # ("trial twisted/test/test_imap.py" # works too) $ trial twisted.test.test_imap.IMAP4ServerTestCase $ trial twisted.test.test_imap.IMAP4ServerTestCase.testLogout (i.e. run a package of modules with testcases, or run a module of testcases, or run a single testcase, or run a single test in a test case). -Andrew. From clarence at netlojix.net Thu Aug 7 20:34:12 2003 From: clarence at netlojix.net (Clarence Gardner) Date: Thu, 07 Aug 2003 17:34:12 -0700 Subject: urllib2 References: Message-ID: On Thu, 07 Aug 2003 16:00:17 +0000, Clarence Gardner wrote: > I must not be getting the point of this from the documentation. > I want to connect to a URL and see what it redirects to. I built > a redirect handler that does nothing much (for testing) and installed > it thusly: > import urllib2 > > class R(urllib2.HTTPRedirectHandler): > def redirect_request(req,fp,code,msg,hdrs): > print "%s, %s, %s, %s, %s" % (req,fp,code,msg,hdrs) > raise urllib2.HTTPError > > o = urllib2.build_opener(R()) > urllib2.install_opener(o) > f = urllib2.urlopen('http://sony.com/walkmanreg') > print f.read()[:200] > > but instead of printing the message from my redirect handler, it prints > out the text of the redirected-to URL. > > Any help appreciated. > clarence at silcom.com Things changed amazingly upon upgrading to Python2.3 Sorry. From cartermark46 at ukmail.com Tue Aug 5 11:04:44 2003 From: cartermark46 at ukmail.com (Mark Carter) Date: 5 Aug 2003 08:04:44 -0700 Subject: boa-constructor bug: import string Message-ID: In v0.2.0 starting boa.py produces the error message: File "C:\Python23\Lib\site-packages\wxPython\tools\boa\About.py", line 301, in write ss = string.strip(s) NameError: global name 'string' is not defined It appears that string is not imported in many modules, because fixing this gives the further error: File "C:\Python23\Lib\site-packages\wxPython\tools\boa\PropEdit\PropertyEditors.py", line 1050, in NamePropEdit identifier = string.letters+string.digits+'_' NameError: name 'string' is not defined Can someone confirm that this is a bug? I don't want to post it to their list inadvertantly. From rupole at hotmail.com Sat Aug 2 00:18:12 2003 From: rupole at hotmail.com (Roger Upole) Date: Fri, 1 Aug 2003 21:18:12 -0700 Subject: Detect PythonWin? References: <3f29fe44.104328@news.muenster.de> Message-ID: <3f2b0d63$1_1@corp-news.newsgroups.com> Try this: >>> import win32ui >>> win32ui.GetCommandLine() '"C:\\Python23\\Pythonwin.exe" ' hth Roger "Martin Bless" wrote in message news:3f29fe44.104328 at news.muenster.de... > IMHO PythonWin is great help in developing. > > How can I do something like: > > if detect("running on PythonWin"): > pass > # fake arguments ... > else: > "proceed normal" > > ? > > Martin From tundra at tundraware.com Tue Aug 5 23:40:07 2003 From: tundra at tundraware.com (Tim Daneliuk) Date: 06 Aug 2003 03:40:07 GMT Subject: Win32All Crashes Python 2.3? In-Reply-To: <3f30680c_4@corp-news.newsgroups.com> References: <3f30680c_4@corp-news.newsgroups.com> Message-ID: Roger Upole wrote: > I get the same thing on Win2k, Python 2.3 anytime a unicode string is > passed to os.lstat (without invoking any win32all modules) This may well be my problem as well since the routine in question sometimes gets passed a unicode string, and sometimes not ... (I think) ... > ... > Looks like the problem is in posixmodule.c > PyUnicodeObject *po; > if (PyArg_ParseTuple(args, wformat, &po)) { > wformat at run time is "u:lstat", which should have > a unicode pointer for the receiving argument, not a PyUnicodeObject. > os.stat (which works for a unicode string) uses uppercase U in the format. > > Roger > > > "Tim Daneliuk" wrote in message > news:jchngb.pr.ln at boundary.tundraware.com... > >>Some time ago I wrote a portable file system browser, twander, that, >>when runnning on Win32, will make use of the Win32All extensions if they >>are present on the target system. > > (http://www.tundraware.com/Software/twander) > >>twander primarily uses Win32All to get file attribute and ownership >>information back in Win32-specific ways each time a new directory is >>entered. (Ordinarily (if Win32All is not installed), it just displays an >>'ls -al' style output and dummies up ownership and group membership.) >> >>Now the problem - twander has worked fine with previous versions of >>Python/Win32All up to and including 2.2.x. It also works fine >>with 2.3. HOWEVER, if I install any of the 2.3 relevant versions >>of Win32All, when I change to a new directory, Python crashes. >>No traceback information is given so I cannot determine exactly >>why this is happening. What is strange is that the program >>starts OK, which means it is using Win32All calls to determine >>file system information for the initial directory. It is only >>upon changing directories that Python gets blown out of the water. >> >>While it is certainly possible that this is a bug in my code, I >>cannot imagine what it might be. The program has worked flawlessly >>on a wide variety of Unix/FreeBSD/Win32 systems with no reports >>of this sort of thing. >> >>Anyone have any ideas what could cause this? Is this a reported >>Win32All bug? >> >>TIA, >>-------------------------------------------------------------------------- > > -- > >>Tim Daneliuk tundra at tundraware.com >>PGP Key: http://www.tundraware.com/PGP/ >> > > > -- ---------------------------------------------------------------------------- Tim Daneliuk tundra at tundraware.com PGP Key: http://www.tundraware.com/PGP/ From rastm2 at aol.commorespam Thu Aug 7 22:53:58 2003 From: rastm2 at aol.commorespam (Raymond Arthur St. Marie) Date: 08 Aug 2003 02:53:58 GMT Subject: Newbie Testing IDLE 1 on win98 References: Message-ID: <20030807225358.24371.00000145@mb-m19.aol.com> >[Raymond A. St. Marie] >> Newbie Ray here. >> I decided to run the autotest from IDLE 1 window. > >There you go: don't. The tests are intended to be run from a DOS box, and >all sorts of weird things can happen if you try to run them from IDLE. > >If you want to run the tests, open a DOS box and do this: > >C:\Python23>python lib/test/regrtest.py > >mixing-tests-and-guis-is-like-mixing-peanut-butter-and-jello-ly y'rs > - tim You know Tim, after I posted, I went and tried the test in the DOS box --hunch--. Wished I'd a dun that first, I'd a never thought about runing the test in the IDE. Of course everything passed. Thanks for confiming this for me. Another question tho. When making a "Top of Startmenu" shortcut for Pythonwin2.3, is it better to ref the "start_pythonwin.py" in the Pywin dir or should I use the pythonwin.py in Python23 dir. I had it the latter way but it would come up a DDE error in the interp window. Did I just answer my own question? I don't understand why if I did. Mucho Thanks--ias Ray From alexander.dejanovski at laposte.net Wed Aug 27 15:30:10 2003 From: alexander.dejanovski at laposte.net (Alexander DEJANOVSKI) Date: Wed, 27 Aug 2003 21:30:10 +0200 Subject: Retic EAI Server 0.3.2 Released - SQLTreeSource included. Message-ID: <5.1.0.14.2.20030827212040.02790a50@194.214.207.101> I've released a new version of Retic with new components : - Pipes : XPathPipe and FlatToXMLPipe - Source : SQLTreeSource (permits to build complex XML documents from several SQL requests). The Designer is now fully working and supports all components of the current Retic release. It is available on sourceforge : http://sourceforge.net/projects/retic ============================================================= WHAT IS RETIC ? Retic is an EAI Server. The aim is to permit applications to communicate, even if they don't speak the same language (which means transport protocols as well as data structures). This is done by building adaptors. An adaptor is composed of : - One source - Several pipes (process data transformations) - Several sinks (destination of data) - Several loggers (using the logging module of python 2.3) ============================================================= ABOUT THE SQLTreeSource COMPONENT: Sometimes (well, might even be more than that) you need to get more than a bunch of rows from a table translated to XML. You need a whole structured XML document with a complex and deep architecture. The SQLTreeSource is what you need then. It permits to describe an XML tree, each node being the result of an SQL statement. Here's an example : Here is the XML output of the source described above : 1 1 ite_1 1.6 07/04/2003 Mise en recette Valo 2003-04-30 3 1 1 Evironnement de tests unitaires Cr?ation d'un environnement de tests unitaires et de non-r?gression. 8 3 2 15 3 1 1 5 ite_1 Scripts de cr?ation des donn?es (TERA) Ecriture des scripts de cr?ation de base 2003-04-10 3 4.8 0 2003-04-10 16 3 1 1 5 ite_1 Environnement $U - Session et Uprocs Cr?ation des sessions et uprocs propres aux tests. 2003-04-16 1 0 1 2003-04-16 ...... ...... ...... This is an extraction of my XPWeb database (THE Extreme Programming management tool - http://xpweb.sourceforge.net ). Three tables are accessed here : iterations, stories and tasks. Iterations may have several stories, which may have several tasks. What I wanted here is to extract all my iterations with their stories and tasks into a single XML document. This permits to get all iterations at the second level (the first being the root one whose name is defined in the rootTag attribute of the source component) of the document. Each iteration will be written to XML, embraced by an tag Providing a new subquery this way : Permits to define a new sublevel under iteration, writing the stories inside tags. parentLink and childLink permit to assign the stories to their iteration (we don't want all stories to be repeated under each iteration). Here, we make a link between the fields : iterations.id and stories.iteration_id At execution time, the SQL statement is modified to include the link. (for example : select * from stories where iteration_id = 4) Now, let's add a subquery to stories : Here, we've added a new sublevel, which will come under stories. It will write all tasks for each stories (with a link between stories.id and tasks.story_id). Simple, isn't it ? Note : Although it is not said yet in the doc, supported databases are : mysql, odbc (not mxOdbc), sybase, dcoracle2, cx_oracle (dbtype in the config file must take one of those values spelled exactly this way). Of course, they'll only work if corresponding db modules are correctly installed. I've tested mysql and odbc but couldn't yet test the others (feedback is welcome !!). Upcoming components are : - xmlBlasterSource (already developped - will be shipped in the next release this week) - JabberSink (already developped - will be shipped in the next release this week) - httpSink - SoapSource - SoapSink - xmlBlasterSink - MQSeries source and sink (if I manage in compiling it with python 2.3 and MinGw32 under win32 - help appreciated - Compile is ok but I get an error at import : blablabla : Memory could not be read) - Support for other popular databases (DB/2, PostgreSQL, etc...) ============================================================= Have fun !! PS : One last thing ==> Tell me if you're interested by Retic (good for my morale). From mpyle at legato.com Wed Aug 27 10:22:32 2003 From: mpyle at legato.com (Michael Pyle) Date: Wed, 27 Aug 2003 07:22:32 -0700 Subject: Aspect oriented Everything? Message-ID: <96F3EC4BDF504540BB9715CBE9DACB8B187039@pa-mail1.legato.com> I hear what your saying but have to admit it's not sinking in very well. Can you provide a simple concrete example contrasting an OOP approach to an AOP with code snipets? --Mike Pyle > -----Original Message----- > From: hungjunglu at yahoo.com [mailto:hungjunglu at yahoo.com] > Sent: Tuesday, August 26, 2003 7:58 PM > To: python-list at python.org > Subject: Re: Aspect oriented Everything? > > Some people don't like AOP because it violates encapsulation > in the vertical dimension. But this way of thinking is kind > of, erh, unidimensional. Because conversely, a program that > is built from purely AOP is encapsulated in its own aspect > dimension, and the usage of OOP in that case would violate > the encapsulation in the horizontal dimension. The fact is, > both factorizations are needed in the real world. > Aspect-oriented coding and object-oriented coding are like > the conjugate variables in quantum mechanics, whether you use > one picture or the other, at the end of the day they are > equivalent, but in some circumstances it's better to use one > than the other. (If you know Fourier transform, you know what > I mean. A localized wave packet in time necessarily means a > spread-out packet in frequency, and vice-versa. You can't > have encapsulation both ways.) > > regards, > > Hung Jung > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From duncan at NOSPAMrcp.co.uk Fri Aug 8 06:02:39 2003 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Fri, 8 Aug 2003 10:02:39 +0000 (UTC) Subject: itertools.ilen? References: <98s4jvkqv94c0gj99epjanq9b3aqvq8i2q@4ax.com> Message-ID: Christos "TZOTZIOY" Georgiou wrote in news:98s4jvkqv94c0gj99epjanq9b3aqvq8i2q at 4ax.com: > Another way to count objects: > > # code start > import types, gc > > type2key = { > types.ClassType: "classes", > types.FunctionType: "functions", > types.MethodType: "functions", > types.ModuleType: "modules", > types.DictType: "dicts", > types.ListType: "lists", > types.TupleType: "tuples" > } > > sums = { > "classes": 0, "functions": 0, "modules": 0, "dicts": 0, > "lists": 0, "tuples": 0 > } > > for obj in gc.get_objects(): > try: > sums[type2key[type(obj)]] += 1 > except KeyError: > pass > # code end > I'm just curious, why did you decide to map the types to strings instead of just using the types themselves? e.g. >>> import gc >>> sums = {} >>> for obj in gc.get_objects(): if type(obj) not in sums: sums[type(obj)] = 1 else: sums[type(obj)] += 1 >>> for typ, count in sums.iteritems(): print typ.__name__, count instance 525 tuple 4273 class 162 getset_descriptor 14 traceback 2 wrapper_descriptor 165 list 258 module 71 instance method 279 function 1222 weakref 18 dict 1647 method_descriptor 82 member_descriptor 75 frame 18 >>> -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From danbmil99 at yahoo.com Mon Aug 4 01:41:21 2003 From: danbmil99 at yahoo.com (dan) Date: 3 Aug 2003 22:41:21 -0700 Subject: looking for win32 (or cross-platform) midi module References: <3F2B84C9.5050507@mxm.dk> Message-ID: Alex Martelli wrote in message news:... ... > [looks like a strange URL but it's the one I found on that "hammer" > site] or perhaps an earlier version (I wouldn't know). Once you do > have that, rebuilding the .pyd from the .cpp shouldn't be any harder > (assuming you do have VC++ 6 installed) than writing and using the > usual setup.py file for extension building, as documented on the > Python online manuals and elsewhere. > Oh that sounds like so much fun! I think it will be easier to just write some glue code to the Win32 calls myself. For now I'll stick with Python 2.0.x until something else breaks. Hmmm, something just did (break) -- can't use the // operator prior to 2.2! No offense, but I think it was a pretty bad choice to change the fundamental behavior of the division operator. Better to have added two new ones -- say \ for integer division, and // for full (returns floating pt) division. Oh well. From blunck at gst.com Wed Aug 13 01:05:37 2003 From: blunck at gst.com (Christopher Blunck) Date: Wed, 13 Aug 2003 01:05:37 -0400 Subject: Python should try to displace Java References: Message-ID: On Mon, 11 Aug 2003 18:43:08 -0700, Brandon J. Van Every wrote: > - Sun is about to die. It has done nothing for anyone lately and has no > further tricks up its sleeve. Sun will be acquired but will not die. > - Sun has failed to make Java live up to its claims of universality. Java > is for all intents and purposes simply a widespread programming language, > not a portable computing environment. Portable computing environments are, > in general, a pipe dream as long as Microsoft is around. It will always be > Windows vs. open standards. Disagreed. Sun has done a great job for universality by promoting job mobility. For example, a couple of years ago, I as a WebSphere developer could not obtain a position on a project using WebLogic or iPlanet. But now with the "J2EE Standards for Packaging", deployment is universal. As long as I understand the spec, I'm mobile across environments. That unifies the job market for J2EE developers, and creates a situation whereby an employer has many *many* more potential workers to draw upon. That in and of itself makes Java a viable strategic platform. To prove my point, I'll extend my argument to database access. Awhile back, there were thick and thin database drivers. The thick drivers were native and proprietary, but were gleefully fast. As JDBC caught on and became more robust, more and more vendors switched to thin clients that implemented the JDBC spec. When this happened, Java developers stopped writing to the proprietary thick client interfaces and instead adopted JDBC. All of the sudden they became more mobile - they could now work for another company using a different database vendor because they were familiar with coding at the interface (or specification) level. Sun has done a fabulous job of defining a specification, and providing an reference implementation. The suite of XML parsers is a perfect example. JAXP, JAXM, JAXB, etc etc etc are specs that a programmer familiarizes themselves with by using the underlying implementations of Xerces, Dom4J, Axis, etc. But, because they code to a specification they are mobile. So, can you take a piece of bytecode off a Windows platform and run it on a Solaris platform? Most of the time yes. In some odd occasions you cannot. Big whoop. But, the other benefits that Sun has provided via Java far outweigh the downsides imo. > - Java is proprietary. Python is open source. Open Source is the best shot > that anyone has at competing with Windows. Why compete with Windows? What do you hope to gain other than personal satisfaction? > - Ergo, Java is the weakling of the litter for Python to attack. Don't attack Java. Please don't. Python has it's place (I actually prefer to code Python over Java), but don't turn it into what it's not - a martyr. Let Python evolve as it will. It solves a *huge* amounts of problems in a pragmatic fashion that other languages don't come close to. Be happy that Python does that. Do you really want to have a "Python One" conference costing $2000 that is filled with mostly mid level manager donkeys handing out their business cards and giving away plush animals? I don't. ... In my opinion, where Python excels over Java is in it's usability. This goes back to the statement (was it Kevin? or Skip?): "batteries included." Python's built-in types are top shelf and extremely easy to manipulate and use. Capitalize on those benefits. Show coworkers how they can gain efficiencies by exploiting the built-in capabilities of python. Lead by example, not by commanding an army of cavalry. Python has always been a grass roots effort (which may be why it is so technically successful). You're not going to achieve the same level of penetration that C# and Java have achieved - Sun and MS have thousands of marketing and salespeople working around the clock at booking Java and C# as the "enterprise development platforms". Instead of fighting the beast head, subvert from within (to quote Dana Moore from last year's PyCon). Show people where Python excels in areas that their Java or C# environments cannot touch. Make a MS wizard obey the commands of a Java applet by using Jython and CPython. Show people that you can implement 90% of a feature in 3 days, and offer to gut it in 6 months when the Java or C# alternative rolls out. Make a subtle joke about your coworkers giving you $100 to hold onto until such time that they replace your Python implementation with a Java or C# impelmentation. That'll get them thinking. In Summary - Java provides benefits. Java has weaknesses tho. Don't go head to head with Java or C# - you'll lose. Instead, make use of the grass roots history of Python and lead by example. Best of luck Brandon - good post!!! :) -c From hanzspam at yahoo.com.au Tue Aug 26 04:44:37 2003 From: hanzspam at yahoo.com.au (=?ISO-8859-1?Q?Hannu_Kankaanp=E4=E4?=) Date: 26 Aug 2003 01:44:37 -0700 Subject: python gripes survey References: <0dw2b.194888$_R5.73038469@news4.srv.hcvlny.cv.net> Message-ID: <840592e1.0308260044.6e814890@posting.google.com> "Ryan Lowe" wrote in message news:<0dw2b.194888$_R5.73038469 at news4.srv.hcvlny.cv.net>... > are there more > complicated uses of code blocks that would make them more powerful than > python's generators? When you want to do something else than iteration. Such as the common example (adapting Ruby's |variable|-syntax) with_file('file.dat', 'rb') |f|: data = f.read() Which currently has to be written as f = file('file.dat', 'rb') try: data = f.read() finally: f.close() And that's pretty verbose. If an exception is thrown inside iteration, there's no way for the generator to catch it. So Python can't do it like this: for f in with_file('file.dat', 'rb'): data = f.read() def with_file(*args): f = file(*args) try: yield f finally: f.close() It would look pretty strange too. One could do this with lambdas or nested functions in Python, since they are "code blocks". But their definition and access to local variables is awkward (for this situation): data = [None] def reader(f): data[0] = f.read() with_file('file.dat', 'rb', reader) Way too ugly to be used. From dtolton at yahoo.com Mon Aug 18 18:51:21 2003 From: dtolton at yahoo.com (Doug Tolton) Date: Mon, 18 Aug 2003 22:51:21 GMT Subject: What's TOTALLY COMPELLING about Ruby over Python? References: <3F412484.69867AED@alcyone.com> Message-ID: On Mon, 18 Aug 2003 12:09:56 -0700, Erik Max Francis wrote: >"Brandon J. Van Every" wrote: > >> I'm realizing I didn't frame my question well. >> >> What's ***TOTALLY COMPELLING*** about Ruby over Python? > >comp.lang.ruby doesn't have Brandon Van Every. That has got to be the best point in favor of Ruby I've seen so far. Doug Tolton (format t "~a@~a~a.~a" "dtolton" "ya" "hoo" "com") From tjreedy at udel.edu Thu Aug 7 11:53:05 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 7 Aug 2003 11:53:05 -0400 Subject: itertools.ilen? References: Message-ID: <15GdnTTlAO5_6K-iXTWJiw@comcast.com> "Jeremy Fincher" wrote in message news:bgt50s$7no$1 at news.cis.ohio-state.edu... > Terry Reedy wrote: > > An iterator is a function/method that traverses (or possibly > > generates) a seqeuence. The sequence has a length (actual or > > potential) but the iterator does not. > > Even some sequences don't have a length; I was allowing for 'infinity' > Or any class with a somehow non-terminating __len__. If the instance wraps or somehow comprises a finite collection, so that it conceptually has a len, then such a __len__ function would be a bug. >> Alternative: initialize six counters to 0. Scan list once and update >> appropriate counter. >Yes, that works in this particular case, and is probably a superior solution. I though the OP should get something practical from the discussion. [..] > That's why I don't think such a change should be made to len(); *all* > iterators are destructive Iterating over tuple, list, or dict is not destructive at all as I meant the word. Ditto for counting the output of a terminating generator whose function and args are still available to reproduce the generator. I regard (irange, n) as a condensed representation of the sequence generated. The iterator 'self destructs' in usage, so that len(iterator) would work only once, but the process may or may not prevent re-iteration. For many generators, it is possible to calculate the total length from the arguments (one of which may actually be the length), and to do so much faster than counting. When the length is not trivial, adding the formula to the doc string could be helpful. But if there is no such formula (such as with the filter examples) then we are back to counting one by one. > and len() silently destroying them doesn't seem > generally useful enough for the potential for mistake. Which is why I 'tossed out an idea' rather than 'made a proposal' ;-) One conceptual problem is that each .next() call reduces the remaining length of the underlying sequence. The OP's count function would only measure this shrinking length rather than the starting length. Terry J. Reedy > > > In the meanwhile, is this really a bottleneck for you? or merely the > > 'pity' of a program running in 1 sec when 0.1 is possible? From tim.one at comcast.net Thu Aug 7 22:32:28 2003 From: tim.one at comcast.net (Tim Peters) Date: Thu, 7 Aug 2003 22:32:28 -0400 Subject: FWD: Re: Problem w/ IDLE on Win2000 In-Reply-To: Message-ID: [Thomas Heller] > ... > IIRC the past discussions, inno was lacking an important feature. Had > this to do with admin/non-admin installs, or is it fixed now? Inno had no conditional commands of any sort, so *some* things we want to do differently between admin and non-admin installs couldn't be handled. Most PLabs users probably couldn't care less. The difference in the Wise script is accomplished via massive and error-prone script near-duplication, in the two branches of multiple if/else blocks, where the guts usually differ just in whether the target hive is HKLM or HKCU. Inno automatically does most of that by itself, but not all. The most recent Inno incorporates a previously popular addin, which embeds a full-blown Pascal(!) interpreter into the installer. This lets you do just about anything (or so I'm told). > Anyway, I know wise much better than inno, OTOH, Inno is much simpler than Wise. For example, Fred Drake built a Windows installer for expat with it in a day, despite not even knowing how to spell Windows. Mark Hammond is building the spambayes Outlook addin installer with Inno, and also speaks Wise, so his perspective would be worth sucking out of his upside-down brain too. > and anyone Indeed . > ... > And while we're on it: what's the state of the htmlhelp file for > windows? Last time I looked, the build script was in CVS, and it even > worked. I spent a fair bit of time on that, and so did Fred, and we left it in good shape when we stopped. There was no sanction to put any company time into it, and we both ran out of spare time to pursue it. Instead we ship 1,200+ HTML files that don't compress well in zip format, and are nearly impossible to search. IOW, win-win . From cnetzer at sonic.net Wed Aug 27 21:24:15 2003 From: cnetzer at sonic.net (Chad Netzer) Date: Wed, 27 Aug 2003 18:24:15 -0700 Subject: timing a function with timeit? (newbie problem) In-Reply-To: References: Message-ID: <1062033855.1852.121.camel@adsl-209.204.179.133.sonic.net> On Wed, 2003-08-27 at 16:45, news.west.cox.net wrote: > Why do I get the exception "global name 'test' is not defined" in this code > (next to last line) and how do I fix it? > > import timeit > def test(): > x=2+2 > t = timeit.Timer('test()') > print t.timeit() You need to tell it about test() with the setup argument (by either defining it directly, or importing it. >>> t = timeit.Timer('test()', 'def test(): x = 2+2') >>> t.timeit() 0.61572694778442383 >>> t = timeit.Timer('test()', 'from __main__ import test') >>> t.timeit() 0.71046602725982666 This is because globals are at the module scope. The timeit module is separate from the interactive (ie. '__main__') namespace. The Timer function compiles your code in the namespace where it is defined, not where it is called. So, it's 'globals' are the globals in the timeit module, and thus, it cannot see your test() function as a global. -- Chad Netzer From sross at connectmail.carleton.ca Thu Aug 14 11:29:36 2003 From: sross at connectmail.carleton.ca (Sean Ross) Date: Thu, 14 Aug 2003 11:29:36 -0400 Subject: 3 new slogans References: <3f3b9cfe@news.swissonline.ch> Message-ID: Python. Fat Free Programming From anton at vredegoor.doge.nl Sat Aug 9 05:43:16 2003 From: anton at vredegoor.doge.nl (Anton Vredegoor) Date: Sat, 09 Aug 2003 11:43:16 +0200 Subject: midi with ctypes References: Message-ID: danbmil99 at yahoo.com (dan) wrote: >One point worth thinking about: a serious MIDI library would include a >method for scheduling low-level routines at exact times (similar to a >sound output buffer). This would almost by definition require some C >code. At some level these samples must be computed by the hardware, but MIDI is about controlling this hardware at a higher level. Maybe we can get away with less exact timing for which Python would be fast enough. Anton From richie at entrian.com Tue Aug 12 06:54:56 2003 From: richie at entrian.com (Richie Hindle) Date: Tue, 12 Aug 2003 11:54:56 +0100 Subject: mouse control with python In-Reply-To: References: Message-ID: [Ken] > Is there a way I can control the mouse with python? I assume you're on Windows. Here's how to move the mouse: >>> from ctypes import * >>> windll.user32.SetCursorPos(100, 100) You can get ctypes from http://starship.python.net/crew/theller/ctypes/ As an added bonus, here's something that moves it relative to the currently-focussed window, which is probably useful for what you want (note that this one doesn't work on 95 or NT4 pre SP3, and it could use some error handling). from ctypes import * user32 = windll.user32 kernel32 = windll.kernel32 class RECT(Structure): _fields_ = [ ("left", c_ulong), ("top", c_ulong), ("right", c_ulong), ("bottom", c_ulong) ] class GUITHREADINFO(Structure): _fields_ = [ ("cbSize", c_ulong), ("flags", c_ulong), ("hwndActive", c_ulong), ("hwndFocus", c_ulong), ("hwndCapture", c_ulong), ("hwndMenuOwner", c_ulong), ("hwndMoveSize", c_ulong), ("hwndCaret", c_ulong), ("rcCaret", RECT) ] def moveCursorInCurrentWindow(x, y): # Find the focussed window. guiThreadInfo = GUITHREADINFO(cbSize=sizeof(GUITHREADINFO)) user32.GetGUIThreadInfo(0, byref(guiThreadInfo)) focussedWindow = guiThreadInfo.hwndFocus # Find the screen position of the window. windowRect = RECT() user32.GetWindowRect(focussedWindow, byref(windowRect)) # Finally, move the cursor relative to the window. user32.SetCursorPos(windowRect.left + x, windowRect.top + y) if __name__ == '__main__': # Quick test. moveCursorInCurrentWindow(100, 100) Hope that helps, -- Richie Hindle richie at entrian.com From hokiegal99 at hotmail.com Sun Aug 17 13:27:17 2003 From: hokiegal99 at hotmail.com (hokiegal99) Date: 17 Aug 2003 10:27:17 -0700 Subject: Path Problem on W2K? Message-ID: <93f5c5e9.0308170927.6e0bdc38@posting.google.com> I installed Python-2.3 into c:\Program Files\Python23 on a new W2K SP4 computer. When I write a Python script and run it from the command prompt, I get the following error: C:\>python 'name-of-script.py' 'python' is not recognized as an internal or external command, operable program or batch file. Here's what my path contains: C:\>path PATH=C:\WINNT\system32;C:\WINNT;C:\WINNT\System32\Wbem;"C:\Program Files\Norton SystemWorks\Norton Ghost\";C:\Program Files\SSH Communications Security\SSH Secu re Shell Any ideas? I've reinstalled and rebooted several times. Also tried adding c:\Program Files\Python23 to my path... still get the error. From gh at ghaering.de Wed Aug 20 10:30:31 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Wed, 20 Aug 2003 16:30:31 +0200 Subject: "_pg" (Postgresql) module for win32 In-Reply-To: References: Message-ID: <3F438607.9090309@ghaering.de> User At Domain Dot Invalid wrote: > Where can I find "_pg" module for postgresql? I would prefer a module > not intedend for "cygwin","mingw" or some thing similar to that. I'm not aware of such binaries. I recommend that people use pyPgSQL instead, as this project offers Windows binaries. http://pypgsql.sf.net/ http://sourceforge.net/project/showfiles.php?group_id=16528 OT: FWIW mingw creates native win32 binaries, and pyPgSQL win32 binaries are indeed created using mingw, though MSVC6 compatibility is checked from time to time. mingw is *not* a runtime environment, so you shouldn't care wether a Python extension module is compiled with mingw, MSVC6 or the foobar compiler. Cygwin, on the other hand, is also a runtime environment. -- Gerhard From tjreedy at udel.edu Thu Aug 7 18:55:27 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 7 Aug 2003 18:55:27 -0400 Subject: catching exceptions in expressions References: Message-ID: "Andrew Dalke" wrote in message news:bgua9j$oll$1 at slb4.atl.mindspring.net... > When list comprehensions came out, one of the things I found > I liked about it was it replaced a lot of code like > > new_data = [] > for x in data: > new_data.append(x.attr) > data = new_data Isn't this the same as data = map(lambda d: d.attr, data) ? > I tried to abstract that into a function, like > > def get_list_attr(data, attrname): > new_data = [] > ... > > but could never come up with a good name for that function. mapattr? Terry J. Reedy From guineapig at pi.be Mon Aug 18 09:22:29 2003 From: guineapig at pi.be (GuineaPig) Date: Mon, 18 Aug 2003 15:22:29 +0200 Subject: python & postgresql ? Message-ID: Hello, I'm trying to develop a cross-platform python-gui for a postgresql db. Of course, I need some postgresql-module for python... Pygresql seems the obvious choice, but I'm developing on windows xp. To get pygresql to work I need to compile pygresql with a visual c++ compiler (wich I don't have). I've looked into pyPgSQL too, and this works fine under windows, but I cannot get this to run on my linux-machine (suse 8.2). Is there no other simple, cross-over, newbie-proof module for postgresql ? What solutions do other people on this list use and why ? Tnx Tom From postmaster at 127.0.0.1 Thu Aug 21 00:08:17 2003 From: postmaster at 127.0.0.1 (David McNab) Date: Thu, 21 Aug 2003 16:08:17 +1200 Subject: popen problems Message-ID: Hi, When using os.popen, or popen2.Popen3 objects, I see a situation when the child process sometimes doesn't get terminated, even when the child program has exited. It's like Python (2.2.3) intermittently leaves the process dangling. Sometimes 'killall python' doesn't clean up these dead tasks. The only solution I've found has been to write a temporary input file, call os.system("myprog < /tmp/infile > /tmp/outfile"), read the outfile, then delete the temporary in/out files. The child program in my case is filter programs in SpamBayes, which I've always observed as terminating properly. Any ideas? Cheers David From pedro.werneck at bol.com.br Fri Aug 1 22:25:27 2003 From: pedro.werneck at bol.com.br (Pedro Werneck) Date: 1 Aug 2003 19:25:27 -0700 Subject: Singleton-like pattern References: <2259b0e2.0308010815.5dcb0b58@posting.google.com> Message-ID: On 1 Aug 2003, Bengt Richter wrote: > >> class MultiSingleton(type): > class MultiSingleton(object): > >> def __call__(cls, *args, **kwds): > def __new__(cls, *args, **kwds): > >> cache = cls.__dict__.get('__cache__') > >> if cache is None: > >> cls.__cache__ = cache = {} > >> tag = str(args) + str(kwds) > tag = '%r%r'% (args, kwds) # might be an alternative > >> if tag in cache: > >> return cache[tag] > >> obj = object.__new__(cls) > >> obj.__init__(*args, **kwds) > >> cache[tag] = obj > >> return obj This is exactly what I did at first... I only changed it to a metaclass because I was adding it to a module that already contain some other metaclasses I use; I think it's more elegant as I said before... a 'quick and dirty' benchmark with the timeit module returned the folowing results, and in this project I will be dealing with a database of 7000+ items, this 20% bit may help a little: __metaclass__: [39.744094967842102, 40.455733060836792, 42.027853965759277] __new__: [47.914013981819153, 48.721022009849548, 49.430392026901245] On 1 Aug 2003, Michele Simionato wrote: > "memoize" is a possible name for this. Notice that the metaclass is a > bit of overkill, you may well use a simple function for this job. Hey... you wrote such a good article on python metaclasses and now don't want people to use them ? :) > Does (args,kw) work in general? IWT you could easily get something unhashable? > IWT using a tuple of actual args may also be a bad idea since it would prevent callers' > temp args from being garbage collected. I use repr to avoid that, maybe mistakenly? > About the issue of finding a suitable key, in the same situation I have > used the tuple (args,kw) as key. But me too I would like to ask if this is a > good idea. What's the custom solution for getting a good key from > a dictionary ? Actually, (args, kw) doesn't work at all, even if you only get hashable arguments... the 'kw' dict invalidate it as a key... besides, there's the garbage collection problem, as Bengt Richter mentioned... The "%r%r"%(args, kwds) works, as well as str((args, kwds))), but it breaks if you get as argument an object with the default __repr__, as the object id may be different, even if they are equal. Overriding __repr__ and returning a real representation avoids this problem. Thanks for your time. Pedro Werneck From cpl.19.ghum at spamgourmet.com Fri Aug 22 16:30:56 2003 From: cpl.19.ghum at spamgourmet.com (Harald Massa) Date: Fri, 22 Aug 2003 22:30:56 +0200 Subject: Adding a column in a tab delimited txt file References: Message-ID: ... 20 columns, now I need to add another column of zero at the 4th column position and a column of zero at the 9th column position. What is the import csv reader = csv.reader(open("sample.csv")) writer = csv.writer(open("sample2.csv","w") for data in reader: writer.writerow([data[:4]+[0]+data[4:7]+[0]+data[7:]) http://online.effbot.org/2003_08_01_archive.htm#librarybook-csv-module Maybe optimization with the list concatenation is possible. But first test, if it is not fast enough. (csv is included with python 2.3, is available seperately in the internet for 2.2 also) Harald From someone at somewhere.com Wed Aug 20 19:23:25 2003 From: someone at somewhere.com (reh) Date: Wed, 20 Aug 2003 23:23:25 GMT Subject: PyQT installation problems References: Message-ID: Stelian Iancu wrote: > Hello all! > > I am trying to install eric3, the Python IDE. I've downloaded and > installed successfully sip-3.8, QScintilla-1.2 and PyQT-3.8. However, > when I try to install eric, I get the following error: > > Sorry, please install PyQt. > > I looked into the install script, then I opened a Python window and > there I tried import qt and I got the following error: > > Traceback (most recent call last): > File "", line 1, in ? > File "/usr/lib/python2.2/site-packages/qt.py", line 25, in ? > import libqtc > ImportError: /usr/lib/python2.2/site-packages/libqtcmodule.so: > undefined symbol: _ZNK9QSGIStyle9classNameEv > > I am using Mandrake 9.1 with the default Python (2.2.3) and Qt. > Make sure you build them in the correct order. Qscintilla sip PyQt I had some kind of .so problem and Detlev mentioned to run ldconfig. Problem solved. If it doesn't fix your problem, he'll probably be along shortly. Haven't been using it long, but eric and qt designer is pretty nice stuff. -- robert redhat 9.0 From gh at ghaering.de Fri Aug 8 09:05:09 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Fri, 08 Aug 2003 15:05:09 +0200 Subject: OCR with Python In-Reply-To: <3F33B87B.2222.13B98A4F@localhost> References: <3F33B87B.2222.13B98A4F@localhost> Message-ID: <3F33A005.4040309@ghaering.de> A wrote: > Hi, > Does anyone have any experience with Optical Character Recognition in Python? > I would like to automatically register emails with a free emails provider e.g. Yahoo or Hotmail. > The problem is that, for a successful registration, I must fill in characters shown in a picture. The goal of this is to prevent automatic account registration. And most certainly their Terms Of Service forbid doing so, anyway. what I'd recommend instead is to register yourself a domain. You can use unlimited email addresses that end in @your.domain then. -- Gerhard From ktilton at nyc.rr.com Fri Aug 22 12:54:17 2003 From: ktilton at nyc.rr.com (Kenny Tilton) Date: Fri, 22 Aug 2003 16:54:17 GMT Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> <6dj2kv8ugkieehs7guh786cl40o5lj6mcs@4ax.com> <3F455BF0.5070700@nyc.rr.com> Message-ID: <3F464B8A.3000305@nyc.rr.com> Andrew Dalke wrote: > Kenny Tilton: > >>>>as when we go for the >>>>productivity win of untyped variables and give up on bugs strong >>> > static > >>>>typing is supposed to find. >>> > > Jacek Generowicz: > >>Note that Kenny said "untyped _variables_" not "untyped objects" or >>"untyped language". > > > Ahh, I hadn't caught that. > > I did know Lisp had strong dynamic typing with optional static typing, > which was why I was surprised he mentioned it. I still don't understand > why he said it given that Python similarly meets the quoted statement. ?? I was just giving another example of how lisp errs on the side of letting us shoot ourselves in the foot. I was not saying anything about Python. -- kenny tilton clinisys, inc http://www.tilton-technology.com/ --------------------------------------------------------------- "Career highlights? I had two. I got an intentional walk from Sandy Koufax and I got out of a rundown against the Mets." -- Bob Uecker From alloydflanagan at comcast.net Thu Aug 21 13:04:39 2003 From: alloydflanagan at comcast.net (A. Lloyd Flanagan) Date: 21 Aug 2003 10:04:39 -0700 Subject: What's better about Ruby than Python? References: <3F40892D.AEF4AAE@alcyone.com> <87isov6pk4.fsf@pobox.com> <3F412081.5EF7279C@alcyone.com> <874r0ey9bx.fsf@pobox.com> <87brulnui2.fsf@pobox.com> Message-ID: Alex Martelli wrote in message news:... > John J. Lee wrote: > > > Nick Vargish writes: > > > > I do wonder if the tight constraint on C++ of being C+extra bits was > > ever really justified. > > I think it was: it allowed C++ to enter into MANY places that just > wouldn't have given it a thought otherwise, and to popularize OO > in this -- albeit indirect -- way. > > > Alex You're right. The characterization of C++ as a "better C" got it into a lot of places. It also, unfortunately, resulted in a huge amount of C++ code full of C idioms and procedural thinking. So management thinks they're doing object-oriented programming because they are using an object-oriented language. But the problems of C become even worse when you do C++ wrong. The result: people end up thinking this whole 'object-oriented' thing is a bunch of hooey. Don't get me wrong: you can do great things with C++ if you're an expert. Problem is, if you're not, you can do tremendous damage. From usenet at microtonal.co.uk Tue Aug 12 12:32:28 2003 From: usenet at microtonal.co.uk (Graham Breed) Date: Tue, 12 Aug 2003 17:32:28 +0100 Subject: Test to see if variable exists In-Reply-To: <2c6431ab.0308120759.26d6e124@posting.google.com> References: <2c6431ab.0308120759.26d6e124@posting.google.com> Message-ID: lamar_air wrote: > I need an if statement to test if a variable exists in a pyton script locals().has_key('var1') From ray at rays-web.com Thu Aug 7 05:08:00 2003 From: ray at rays-web.com (Ray Smith) Date: Thu, 07 Aug 2003 09:08:00 GMT Subject: email client written with python + wxWindows In-Reply-To: <409a56e2.0308062211.456575df@posting.google.com> References: <409a56e2.0308062211.456575df@posting.google.com> Message-ID: <3f3216c8@news.syd.ip.net.au> Shagshag wrote: > hello, > > does anyone know of a full python + wxWindows email client ? > > google didn't help me... > > thanks, http://mahogany.sourceforge.net/ Regards, Ray Smith From alanmk at hotmail.com Fri Aug 8 10:39:16 2003 From: alanmk at hotmail.com (Alan Kennedy) Date: Fri, 08 Aug 2003 15:39:16 +0100 Subject: OCR with Python References: Message-ID: <3F33B614.C4E4BA99@hotmail.com> A wrote: > Does anyone have any experience with Optical Character Recognition > in Python? I would like to automatically register emails with a > free emails provider e.g. Yahoo or Hotmail. What's wrong with the manual registration process? You wouldn't be thinking of automating abuse of the Yahoo or Hotmail free email services, would you? e.g. SPAM transmission? > The problem is that, for a successful registration, I must fill in > characters shown in a picture. Precisely. That's the whole point. To stop people from automating registration. > So I need to recognize the characters in a picture. I think you'll find that those characters have been rendered specifically to prevent machine recognition. The only machine that can read them is the human brain. If someone can come up with an computer algorithm that can read them, then the pictures will have to be changed. And I'm glad it's that way. That prevents automated abuse of free email services for sending SPAM, etc. So we all might get less SPAM. -- alan kennedy ----------------------------------------------------- check http headers here: http://xhaus.com/headers email alan: http://xhaus.com/mailto/alan From tzot at sil-tec.gr Thu Aug 7 05:54:15 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Thu, 07 Aug 2003 12:54:15 +0300 Subject: Python and cron jobs. References: <7b454334.0308041023.6e688b4d@posting.google.com> <7b454334.0308050947.3d1d51fb@posting.google.com> Message-ID: On Tue, 5 Aug 2003 16:27:22 -0600, rumours say that Steven Taschuk might have written: >> [...] I just wish to know how to get the cron deamon to >> reload the crontab. Are you certain that it checks for changes or >> reloads every minute? > >No. There's lots of cron implementations, and I certainly haven't >used all of them; perhaps some need a SIGHUP to reload, for >example. Check your local documentation to be sure, 'man 8 cron' >or what have you, and/or just try it as Michael suggested. Interfacing through the crontab executable should suffice for every cron out there... -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From akineko at pacbell.net Thu Aug 21 10:45:25 2003 From: akineko at pacbell.net (Aki Niimura) Date: 21 Aug 2003 07:45:25 -0700 Subject: freeze utility and pickle Message-ID: Hello everyone, I'm having a problem "freezing" my program using freeze.py under Solaris. My program works fine if I invoke it as a Python script. However, it generates a LookupError when I started the "frozen" program. evelyn neko [33] >> websc Traceback (most recent call last): File "websc.py", line 312, in ? main() File "websc.py", line 171, in main account = Account() File "websc_account.py", line 65, in __init__ dict = pickle.loads(binascii.a2b_base64(passcode_encoded)) File "/usr/local/lib/python2.3/pickle.py", line 1394, in loads return Unpickler(file).load() File "/usr/local/lib/python2.3/pickle.py", line 872, in load dispatch[key](self) File "/usr/local/lib/python2.3/pickle.py", line 985, in load_string self.append(rep.decode("string-escape")) LookupError: unknown encoding: string-escape I had this problem with Python 2.2.3 and I was hoping this would be gone in the new release, Python 2.3 but it turned out otherwise. It seems some package is missing from the list of modules to be included in the freeze process. I tried to figure out which is missing. But due to my shallow knowledge, I failed to track down the culprit. Can anybody give me a clue where to look for? Any suggestions are highly appreciated. Best regards, Aki Niimura From ajsiegel at optonline.net Sun Aug 31 13:01:48 2003 From: ajsiegel at optonline.net (Arthur) Date: Sun, 31 Aug 2003 13:01:48 -0400 Subject: artificial intelligence? Message-ID: <000601c36fe1$915f4310$0c02a8c0@Arts> Terry writes - >Is there another Mark Lutz who writes geophysics books? Well, of course ;), that there is the Mart Lutz, actor, who has the recurring role of Groosalugg on the TV show Angel. but his bio at http://www.tvtome.com/tvtome/servlet/PersonDetail/personid-20984 does not mention a passion for either Python or geophysics. Perhaps I need to google further. Art From bh at intevation.de Wed Aug 27 11:05:13 2003 From: bh at intevation.de (Bernhard Herzog) Date: Wed, 27 Aug 2003 17:05:13 +0200 Subject: Proposal: Magic Constants References: Message-ID: <6q7k4zi1jq.fsf@salmakis.intevation.de> "John Roth" writes: > "Chris Gonnerman" wrote: >> Modules to handle alternate numeric formats, such >> as decimal, fixed-point, rational, etc. would >> include a call to a builtin registration function >> which would allow them to "take over" a specific >> alphabetic specifier. > > There's another namespace with a possibility > of collisions here, and also the same old "we > can't make one of these a builtin because it > might break user code." This could be alleviated by doing something similar to how metaclasses can be specified at the module level. Put a dictionary mapping suffixes to constructors into a module level variable called e.g. __literals__ so that you'd either do it by hand like this: __literals__ = {"r": Rational} or if you only need e.g. rational literals in your module could do from rational import __literals__ Assuming the rational module provides a suitable dictionary for the user's convenience. > One overall thought: why limit it to numbers? > The new datetime module would benefit from > a datetime literal, but that would have to be > a character string. Indeed. Allowing this for strings would also provide a way to get self interpolating string literals because the constructor could use introspection to get a dictionary with all local variables in the calling scope. > Another thing to think about is whether > this could cause problems with existing > code. I can't immediately think of a case > where a literal can be next to a character, I think "1.or 2" would have to produce a syntax error under the new rules. Bernhard -- Intevation GmbH http://intevation.de/ Sketch http://sketch.sourceforge.net/ Thuban http://thuban.intevation.org/ From max at alcyone.com Tue Aug 19 01:16:06 2003 From: max at alcyone.com (Erik Max Francis) Date: Mon, 18 Aug 2003 22:16:06 -0700 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: <3F41A877.995F9C35@alcyone.com> Message-ID: <3F41B296.BC2CACC0@alcyone.com> Ben Finney wrote: > Seeing second-hand comments (as quoted by others) from people in one's > killfile is a hazard of Usenet. Of course. And it's easily avoided with the tiniest bit of self-restraint. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ No man is more cheated than the selfish man. \__/ Henry Ward Beecher From mpeuser at web.de Sat Aug 16 03:42:25 2003 From: mpeuser at web.de (Michael Peuser) Date: Sat, 16 Aug 2003 09:42:25 +0200 Subject: How remove Tcl/Tk fom py2exe distribution? References: Message-ID: Hi Graham - thnak you for your answer! "Graham Fawcett" schrieb im Newsbeitrag news:mailman.1061014105.16562.python-list at python.org... > Michael Peuser wrote: > > >Hi, > >I should like to make a distribution (using Tkinter), with standard DLLs > >removed. [..details in first posting ...] > > It's a bit unclear, Michael, what you're trying to accomplish. On the > one hand, you're using py2exe to deploy your application, which suggests > that you don't expect your users to have a Python distribution on their > computers. On the other hand, you're looking to deploy a Tkinter app, > but without any tcl/tk files, because they "belong to the standard > distribution", suggesting that you *do* expect your users to have a > Python distribution. It is more difficult: I *can* request the potiential user to install a "standard" Python of a given version, but not more! And by no means do I want to interfere with his or her installation. This means *everything* except minimal Python (includingTcl/Tk) must be packed somehow..... The program shall not be *installed* but run from a double click! Only on special request I can deliver thePython-, Tcl-, Tk- dlls and this phantastic Tcl folder with megabytes of chinese character sets.... But I mostly want to reduce the size of the distribution, especially in upgrade and bug-fix situations. > In case I'm missing something: you could always, as part of your build, > just delete files from the py2exe-generated build directory. For > example, at the end of your setup.py script, add some lines to delete > the tk/tcl files from your build path. I've used this "strategy" > sometimes when building py2exe apps that use the Python Imaging Library. > (PIL has tcl/tk import dependencies, but doesn't actually need tcl/tk > for the majority of its functions.) > > -- Graham > I tried this! This will not help, because - in this case - Tkinter *is* used. The importer just does not find it (probably because py2exe modifies its behaviour.... This is why I use Tkinter= __import__("Tkinter") But this does not wort either... Kindly Michael P > From sscherer at rocketmail.com Sat Aug 23 07:10:58 2003 From: sscherer at rocketmail.com (Bgc) Date: 23 Aug 2003 04:10:58 -0700 Subject: Using the C Source Code from Tcl/Tk References: Message-ID: I had a look at Tcl/Tk. And you know what? I like it better than Python. I'm sick of "bindings" for everything. Tcl/Tk is just awesome, so why not use it instead? That's what I'm going to do. What a relief. Sorry if I offended any Tclers with the original post. I'm very excited, and relieved about my decision. Steve > > What is interesting right now is that the Tcl/Tk group is talking the > need to revitalize Tcl/Tk: > > http://tcl.projectforum.com/tk/Home > > So, here the Python group is without a Python-native GUI (the Tkinter > module being a wrapper around Tcl/Tk). And here is the Tcl/Tk group > struggling with the problem of Tcl's popularity (and maybe some of > that is Tk's fault, who knows). And then there is that excellent > cross platform compatible C code sitting at Sourceforge under the BSD > license? The mind boggles? Maybe its time to take the C code > underlying Tcl/Tk and port it for Python-native use without the Tcl/Tk > layer? From sympa at ens.fr Thu Aug 21 01:33:03 2003 From: sympa at ens.fr (SYMPA) Date: Thu, 21 Aug 2003 07:33:03 +0200 (CEST) Subject: Results of your commands Message-ID: <200308210533.h7L5X3eO020956@nef.ens.fr> > Please see the attached file for details. Command not understood: ignoring end of message. No command found in message From mack at incise.org Sat Aug 30 19:25:32 2003 From: mack at incise.org (mackstann) Date: Sat, 30 Aug 2003 18:25:32 -0500 Subject: list.sort(func) speed Message-ID: <20030830232532.GE9311@incise.org> I have the following function that compares two filenames based on their basename only: _basenameCmp = lambda self, *pair: cmp(*map(os.path.basename, pair)) This is so that I can sort a list of files, and the sorting will be done by filename, ignoring path. There is a minor issue which is not so much a problem (yet) per se, but just made me curious if there was a better way to go about this. When calling .sort() on my list, it takes 16ms to complete. Calling .sort(_basenameCmp) on the same list takes 244ms. This list could very well be 5 or 10 times the size, in use. Now, I believe that my _basenameCmp() needs to be called a lot of times (er.. can't figure out exactly how many, (len(mylist)/2)^2 ?) and doing a string operation that many times is obviously going to slow it down. So my question is: Is there anything I could do differently or better to speed this up? TIA, -- m a c k s t a n n mack @ incise.org http://incise.org Pascal is not a high-level language. -- Steven Feiner From m.liddle at cosc.canterbury.ac.nz Mon Aug 18 22:21:14 2003 From: m.liddle at cosc.canterbury.ac.nz (Marcus Liddle) Date: Tue, 19 Aug 2003 14:21:14 +1200 Subject: threads and timeout -> running a shell command / want to guard against infinite loops Message-ID: <3F41899A.5090306@cosc.canterbury.ac.nz> Hi I'm trying to get a really simple python program to run a bash testing script and kill itself if its been running to long (ie infinite loop) create the thread object - test = TestThread() run the command - test.do_command("infloop.bash") if t.isAlive(): ...stop it any good ideas? cheers Marcus -- Senior Assistant [mailto:m.liddle at cosc.canterbury.ac.nz] Dept. of Computer Science University of Canterbury Phone: +64 3 366-7001 ext: 7871 Office: 323 [ http://www.cosc.canterbury.ac.nz/~marcus/index.html ] From adalke at mindspring.com Tue Aug 12 20:00:25 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Tue, 12 Aug 2003 18:00:25 -0600 Subject: Summer reading list References: <5d0_a.288$jw4.85@nwrdny03.gnilink.net> Message-ID: Joe Cheng: > It might just be my Java background creeping in (I'm a Python newbie), but, > wouldn't it be better if this was OO? Here's perhaps the definitive statement on the topic, from Tim Peters: http://aspn.activestate.com/ASPN/Mail/Message/python-dev/1620162 Summary: heapq is a concrete interface, not an abstract one. It doesn't try to encompass the different ways to do heaps. It's like bisect in that it works on an existing data type. Andrew dalke at dalkescientific.com From sminni_news at minisoftindia.com Sun Aug 17 02:22:04 2003 From: sminni_news at minisoftindia.com (Sanjay Minni) Date: 16 Aug 2003 23:22:04 -0700 Subject: python for dev of CAD type software Message-ID: <836a2f21.0308162222.413fefaa@posting.google.com> is python suitable for a production level deployment of CAD type of software. we may have to develop a specific purpose visual designing software for an interior designer to be deployed at several locations Sanjay Minni www.planage.com From h.goebel at goebel-consult.de Fri Aug 1 02:26:46 2003 From: h.goebel at goebel-consult.de (Hartmut Goebel) Date: Fri, 01 Aug 2003 08:26:46 +0200 Subject: ANN: managesieve 0.3 Message-ID: Announcing: managesieve ============= Version 0.3 A MANGAGESIEVE client library for remotely managing Sieve scripts, including an interactive 'sieveshell'. This module allows accessing a Sieve-Server for managing Sieve scripts there. For more information about the MANAGESIEVE protocol see draft http://www.ietf.org/internet-drafts/draft-martin-managesieve-04.txt . Changes since 0.2 ----------------- * managesieve: - MANAGESIEVE.authenticate() now only returns a OK/NO/BYE result like any command not asking data from the server * sieveshell: - added 'edit', which may create scripts, too. (posix only) - now prints out the server capabilities, thus the user knows what ther server is capable of (and which Sieve-Commands may be used). - fixed some minor bugs - sieveshell was missing in archive What is MANAGESIEVE? -------------------- Sieve scripts allow users to filter incoming email. Message stores are commonly sealed servers so users cannot log into them, yet users must be able to update their scripts on them. This module implements a protocol "managesieve" for securely managing Sieve scripts on a remote server. This protocol allows a user to have multiple scripts, and also alerts a user to syntactically flawed scripts. This an interim measure as it is hoped that eventually Sieve scripts will be stored on ACAP. Availablity ----------- 'managesieve' is available for download at http://www.crazy-compilers.com/py-lib/managesieve.html Requirements ------------ Requires Python >= 2.0 Not yet implemented ------------------- - Only athentication method LOGIN is currently supported. - STARTTLS is not yet implemented. - sieve-names are only quoted dump (put into quotes, but no escapes yet). Copyright/License ----------------- (C) Copyright 2003 by Hartmut Goebel License: Python Software Foundation License http://www.opensource.org/licenses/PythonSoftFoundation.html License for 'sieveshell' and test suite: GPL http://www.opensource.org/licenses/gpl-license.php Credits ------- Based on Sieve.py from Ulrich Eck which is part of of 'ImapClient' (see http://www.zope.org/Members/jack-e/ImapClient), a Zope product. Some ideas taken from imaplib written by Piers Lauder et al. -- Regards Sch?nen Gru? Hartmut Goebel -- | Hartmut Goebel | IT-Security -- effizient | | h.goebel at goebel-consult.de | www.goebel-consult.de | From pu Sun Aug 17 03:46:23 2003 From: pu (Patrick Useldinger) Date: Sun, 17 Aug 2003 09:46:23 +0200 Subject: asynchat question In-Reply-To: <3F3EBE44.FA29DC66@alcyone.com> References: <3f3ebaa8_2@news.vo.lu> <3F3EBE44.FA29DC66@alcyone.com> Message-ID: <3f3f326a_1@news.vo.lu> Erik Max Francis wrote: > There are several problems here. For starters, your server class isn't > really a server, since it doesn't derive from asyncore.dispatcher, and > doesn't bind to a port, so connections never come in. (And you wanted > to override handle_accept, not handle_connect.) Try something like this > for your server: Eric, my problem is with the client. The server is working correctly, I only posted the part of the code I thought was relevant for my particular problem. The full code is here: from sasUtils import now,SingleServer from sasParms import EBPort,BLOCKEND import asyncore,socket class Dispatcher(asyncore.dispatcher): def __init__(self,port): asyncore.dispatcher.__init__(self) self.create_socket(socket.AF_INET,socket.SOCK_STREAM) self.bind(('',port)) print now(),'listening to port',port self.listen(5) def handle_accept(self): newSocket, address=self.accept() print 'connected from',address SecondaryServer(newSocket) class SecondaryServer(SingleServer): def processData(self,data): response='??' peer=self.getpeername() print now(),'from %s received %s' % (peer,repr(data)) if data == 'quit': if peer[0]=='127.0.0.1': response='OK' dispatcher.close() else: response='KO' response=response+' '+data print now(),'to %s responding %s' % (peer,repr(response)) self.push(response+BLOCKEND) if __name__ == '__main__': print now(),'start sasEM' dispatcher=Dispatcher(EBPort) asyncore.loop() print now(),'end sasEM' Cheers, -Patrick -- Real e-mail address is 'cHVAdm8ubHU=\n'.decode('base64') Visit my Homepage at http://www.homepages.lu/pu/ From n/a Wed Aug 27 19:26:06 2003 From: n/a (Mike Thompson) Date: Thu, 28 Aug 2003 09:26:06 +1000 Subject: My future Python IDE article References: <3f4ca68c$0$4190$afc38c87@news.optusnet.com.au> Message-ID: <3f4d3e12$0$4190$afc38c87@news.optusnet.com.au> "Gerhard H?ring" wrote in message news:mailman.1061989090.23114.python-list at python.org... > Mike Thompson wrote: > > "David Mertz" wrote: > >>So c.l.py readers... make the case for your favorite one getting on the > >>list. > > > > I'm surprised no one has mentioned Boa. I tryed Wing & Komodo, before finding > > Boa. > > Boa is far from finished. Depending on your wxPython version and how you > use the IDE, it could work surprisingly well or annoy you to no end in > my experience. > > I'd recommend to not review alpha software like Boa. > That's not my experience. I've found Boa both stable, functional and well priced. I tried Wing and generally liked it, except that I'm used to an editor with tabs for each open file and I found Wing's "one file at a time arrangement" didn't match my way of working. I tried Komodo, which has an enormous feature set that goes well beyond python, which I liked until I came to run my first wxPython based program under the debugger and it froze. I never did get to the bottom of why. In between all this I attempted to use Eric but had difficulty getting it setup. From memory, after some googling around, I found a few similar reports and abandoned the effort. I then tried Boa and haven't moved since. My search has occurred over the last six months. About twelve months ago I also tried the Secret Labs IDE (can't remember the name) which I found a bit of work initially, but ended up quite liking. However this product now seems to have been withdrawn from the market. If you have to restrict it to 3, my suggestion would be: Wing Boa IDLE That would give you a mix of commerical and free. All are cross-platform. If not IDLE, then Komodo which has a very inexpensive licence for personal use.. -- Mike From bobx at linuxmail.org Fri Aug 1 16:51:15 2003 From: bobx at linuxmail.org (Bob X) Date: Fri, 01 Aug 2003 20:51:15 GMT Subject: 2.3 win installer References: Message-ID: <7pAWa.7762$gi.4246099@news2.news.adelphia.net> "Timothy Martens" wrote in message news:mailman.1059732547.2422.python-list at python.org... > Anyone having problems with the 2.3 win installer? I'm running win2k pro > (sp4) and the installer is freezing after the initial dialogues, just as > teh install starts. > If you have any anti-virus going...turn it off. Oh and download it again. From logiplex at qwest.net Fri Aug 29 15:25:46 2003 From: logiplex at qwest.net (Cliff Wells) Date: Fri, 29 Aug 2003 12:25:46 -0700 Subject: How do I prevent master window from being accessed with child window present? In-Reply-To: <4378fa6f.0308291012.f660cdf@posting.google.com> References: <4378fa6f.0308291012.f660cdf@posting.google.com> Message-ID: <1062185146.32726.785.camel@software1.logiplex.internal> On Fri, 2003-08-29 at 11:12, Marc wrote: > Hi, > > I am doing a gui application where child windows pop up with options > after the user selects particular buttons from the master window. > However, the master window is still active underneath the child > window. If they accidentally press the same button again they can get > the same copy of two child windows, and that screws up a bunch of the > database stuff that I am trying to collect. > > I have tried using the 'transient' method, and that prevents the > master window from being highlighted. But the user can still push > buttons on the master window if the child window is moved aside. > > How do I disable the master window until the child window is closed? And which GUI toolkit are you using? Most have an option to open a window as "modal" (although this might be limited to dialogs for your particular toolkit) which means it retains the focus exclusively until it's dismissed. -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 (800) 735-0555 From hwlgw at hotmail.com Fri Aug 1 10:55:01 2003 From: hwlgw at hotmail.com (Will Stuyvesant) Date: 1 Aug 2003 07:55:01 -0700 Subject: Interview with Guido in the Wall Street Journal Message-ID: Daily Python mentions: "Lee Gomes: Two men, two ways to speak computerese [The Wall Street Journal reports on Python and Perl, and interviews their respective authors.] " If you click on the link then you will find TWSJ works with subscription, "2 weeks for free!". Hurray! Forcing people to subscribe and then (later) asking money for it is against my principles of free information exchange so I didn't read it. Anybody has the interview? Any good? Afraid to post it here because of legal issues? From pinard at iro.umontreal.ca Tue Aug 5 16:20:18 2003 From: pinard at iro.umontreal.ca (Francois Pinard) Date: 05 Aug 2003 16:20:18 -0400 Subject: Python and cron jobs. In-Reply-To: <7b454334.0308050947.3d1d51fb@posting.google.com> References: <7b454334.0308041023.6e688b4d@posting.google.com> <7b454334.0308050947.3d1d51fb@posting.google.com> Message-ID: [Fazer] > I just wish to know how to get the cron deamon to reload the crontab. You could stop and restart the deamon (the same as for any other deamon). There is also a `crontab' program, for which there is a `man' page. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From carroll at tjc.com Mon Aug 25 23:40:59 2003 From: carroll at tjc.com (carroll at tjc.com) Date: Mon, 25 Aug 2003 20:40:59 -0700 Subject: python gripes survey References: Message-ID: On Sat, 23 Aug 2003 15:39:27 GMT, "Ryan Lowe" wrote: > id like to make a list of some of the aspects people >find most annoying, regardless of their feasibility of implementation. No kidding: I'd really like a GOTO. I know, that's heresy, but I like it during development. Sometimes I have a whole bunch of tests, and change something that will only affect a test near the end. I'd love to GOTO around the early stuff. If Python used {} to delimit blocks, I could just make the skipped code a block and add a condition to skip it, but with the indentation as the way of showing block scope (which I *love*), I have to indent a big chunk of code to use that method. From ktilton at nyc.rr.com Thu Aug 21 09:50:48 2003 From: ktilton at nyc.rr.com (Kenny Tilton) Date: Thu, 21 Aug 2003 13:50:48 GMT Subject: What's better about Ruby than Python? References: <3F41505F.69D18CC8@alcyone.com> <66d7kvonvb2n0nqbqahhd5roak7ur81sob@4ax.com> <3f43ef5d_4@127.0.0.1> <3F440A35.9030602@nyc.rr.com> Message-ID: <3F44CF06.4080003@nyc.rr.com> Andrew Dalke wrote: > Kenny Tilton: > >>This macro: >> >>(defmacro c? (&body code) >> `(let ((cache :unbound)) >> (lambda (self) >> (declare (ignorable self)) >> (if (eq cache :unbound) >> (setf cache (progn , at code)) >>cache)))) > > > I have about no idea of what that means. Could you explain > without using syntax? My guess is that it caches function calls, > based only on the variable names. Why is a macro needed > for that? C? does something similar to what you think, but at with an order of magnitude more power. Estimated. :) Here is how C? can be used: (make-instance 'box :left (c? (+ 2 (right a))) :right (c? (+ 10 (left self)))) So I do not have to drop out of the work at hand to put /somewhere else/ a top-level function which also caches, and then come back to use it in make-instance. That's a nuisance, and it scatters the semantics of this particular box all over the source. Note, btw: (defun test () (let* ((a (make-instance 'box :left 0 :right (c? (random 30)))) (b (make-instance 'box :left (c? (+ 2 (right a))) :right (c? (+ 10 (left self)))))) (print (list :a a (left a) (right a))) (print (list :b b (left b) (right b))))) ...that different instances of the same class can have different rules for the same slot. Note also that other plumbing is necessary to make slot access transparent: (defun get-cell (self slotname) ;; this fn does not need duplicating (let ((sv (slot-value self slotname))) (typecase sv (function (funcall sv self)) (otherwise sv)))) (defmethod right ((self box)) ;; this needs duplicating for each slot (get-cell box right)) But I just hide it all (and much more) in: (defmodel box () ((left :initarg :left :accessor left) (right :initarg :right :accessor right))) ...using another macro: (defmacro defmodel (class superclasses (&rest slots)) `(progn (defclass ,class ,superclasses ,slots) ,@(mapcar (lambda (slot) (destructuring-bind (slotname &key initarg accessor) slot (declare (ignore slotname initarg)) `(defmethod ,accessor ((self ,class)) (get-cell self ',slotname)))) slots))) > > >>>>import time >>>>def CachedCall(f): >>> > ... cache = {} > ... def cached_call(self, *args): > ... if args in cache: > ... return cache[args] > ... x = f(self, *args) > ... cache[args] = x > ... return x > ... return cached_call > ... > >>>>class LongWait: >>> > ... def compute(self, i): > ... time.sleep(i) > ... return i*2 > ... compute = CachedCall(compute) > ... > >>>>t1=time.time();LongWait().compute(3);print time.time()-t1 >>> > 6 > 3.01400005817 > >>>>t1=time.time();LongWait().compute(3);print time.time()-t1 >>> > 6 > 0.00999999046326 > > Cool. But call cachedCall "memoize". :) Maybe the difference is that you are cacheing a specific computation of 3, while my macro in a sense caches the computation of arbitrary code by writing the necessary plumbing at compile time, so I do not have to drop my train of thought (and scatter my code all over the place). That is where Lisp macros step up--they are just one way code is treated as data, albeit at compile time instead of the usual runtime consideration. -- kenny tilton clinisys, inc http://www.tilton-technology.com/ --------------------------------------------------------------- "Career highlights? I had two. I got an intentional walk from Sandy Koufax and I got out of a rundown against the Mets." -- Bob Uecker From fredrik at pythonware.com Mon Aug 4 08:55:32 2003 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 4 Aug 2003 14:55:32 +0200 Subject: Example code for anydbm wanted... References: Message-ID: "John D." wrote: > Does anyone have any good example code that shows > how to use the "anydbm" wrapper tp interface with a > very simple database. like some examples of how to > use "dumbdbm"? you'll find some simple examples in the "data storage" chapter in my python standard library book: http://www.effbot.org/zone/librarybook-index.htm From bokr at oz.net Sun Aug 31 19:17:19 2003 From: bokr at oz.net (Bengt Richter) Date: 31 Aug 2003 23:17:19 GMT Subject: Update to Python 2.3 on Red Hat Linux 9 References: <8242f4a7.0308282240.4c87f997@posting.google.com> Message-ID: On 31 Aug 2003 23:18:49 +0200, martin at v.loewis.de (Martin v. =?iso-8859-15?q?L=F6wis?=) wrote: >bokr at oz.net (Bengt Richter) writes: > >> >> Or do I really need to find out all the libraries in use with >> >> 2.2.2 and compile these for 2.3? >> > >> >Yes. >> > >> Is this highly automated, or a gross PITA? > >Can you elaborate? What is this "this" you are referring to? >And what do you mean by "highly automated"? > s/this/finding out all the libraries ... and compiling these for 2.3/ s/highly automated/make -someopts someargs/ or some setup.py stuff? distutils? More or less ;-) E.g., for 2.2 I recompiled PIL and zlib from sources on windows, and if there was a precanned deal, I missed it & re-invented just enough to get by ;-/ So I reacted to the OP's question in terms of my own experience, and wonder what the current vision is re making upgrading a whole installation to a new version easy and reliable. Regards, Bengt Richter From irmen at -NOSPAM-REMOVETHIS-xs4all.nl Fri Aug 15 17:12:43 2003 From: irmen at -NOSPAM-REMOVETHIS-xs4all.nl (Irmen de Jong) Date: Fri, 15 Aug 2003 23:12:43 +0200 Subject: how does the main module notice when I change a module In-Reply-To: <3f443b52.0308151255.50c58885@posting.google.com> References: <3f443b52.0308151255.50c58885@posting.google.com> Message-ID: <3f3d4cca$0$49103$e4fe514c@news.xs4all.nl> Marcus Schneider wrote: > I use PythonWin on WinXP. Every time I change a module, I have to > leave PythonWin and re enter to make it notice I have made changes. I > guess this is not the normal way to do that.. do I have to store the > module at a specific place? Is there a kind of "reset" command to make > the main module update specific data? Doesn't "reload(MyModule)" work? Type it at the interactive prompt. --Irmen From aahz at pythoncraft.com Sat Aug 16 13:44:06 2003 From: aahz at pythoncraft.com (Aahz) Date: 16 Aug 2003 13:44:06 -0400 Subject: Py2.3: Feedback on Sets (fwd) References: Message-ID: In article , David Mertz wrote: > >The mention of Set.powerset() above is quite interesting to me. It >feels both exciting and dangerous :-). > >As we all know, the size of the powerset of S, for len(S)==N, is 2**N. >Seems like it would be really easy to run into some long runtimes and >memory usage. Then again, power set really is a fundamental operation >on sets. And making users rewrite it each time is error prone. Maybe make it an iterator? <0.3 wink> -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From davidcfox at post.harvard.edu Fri Aug 15 09:20:00 2003 From: davidcfox at post.harvard.edu (David C. Fox) Date: Fri, 15 Aug 2003 13:20:00 GMT Subject: Strange re behavior: normal? In-Reply-To: References: Message-ID: <465%a.119197$It4.50912@rwcrnsc51.ops.asp.att.net> Robin Munn wrote: > How is re.split supposed to work? This wasn't at all what I expected: > > [rmunn at localhost ~]$ python > Python 2.2.2 (#1, Jan 12 2003, 12:07:20) > [GCC 3.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>>>import re >>>>re.split(r'\W+', 'a b c d') > > ['a', 'b', 'c', 'd'] > >>>># Expected result. > > ... > >>>>re.split(r'\b', 'a b c d') > > ['a b c d'] > >>>># Huh? > > > Since \b matches the empty string, but only at the beginning and end of > a word, I would have expected re.split(r'\b', 'a b c d' to produce > either: > > ['', 'a', ' ', 'b', ' ', 'c', ' ', 'd', ''] > > or: > > ['a', ' ', 'b', ' ', 'c', ' ', 'd'] > > But I didn't expect that re.split(r'\b', 'a b c d') would yield no splits > whatsoever. The module doc says "split(pattern, string[, maxsplit = 0]): > split string by the occurrences of pattern". re.findall() seems to think > that \b occurs eight times in 'a b c d': > > >>>>re.findall(r'\b', 'a b c d') > > ['', '', '', '', '', '', '', ''] > > So why doesn't re.split() think so? I'm puzzled. > It looks like re.split is not splitting on zero-length matches. I get similar behavior (in Python 2.2.2) if I try: re.split('x*', 'a b c d') or re.split('(?=c)', 'a b c d') I don't have the Python source handy to verify this hypothesis, though. If this is correct, it should at least be documented. David From fredrik at pythonware.com Wed Aug 13 04:26:10 2003 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 13 Aug 2003 10:26:10 +0200 Subject: Python vs. C# References: <2259b0e2.0308100616.55b651ca@posting.google.com> <3f36af20@shknews01> <3f3959e3_1@news.vo.lu> <3F39B8A3.68B9D623@alcyone.com> Message-ID: Erik Max Francis wrote: > He's probably going to think you're talking about me, rather than Erik > Naggum :-). is naggum still posting to the net? From mark at hahnca.com Thu Aug 28 00:14:42 2003 From: mark at hahnca.com (Mark Hahn) Date: Wed, 27 Aug 2003 21:14:42 -0700 Subject: finding object using IS instead of == Message-ID: If I have a large collection (list, tuple, or dict) of objects, can I locate one quickly that matches a given object using the IS equivalence operator instead of the value == operator? From buzzard at urubu.freeserve.co.uk Mon Aug 4 14:44:56 2003 From: buzzard at urubu.freeserve.co.uk (Duncan Smith) Date: Mon, 4 Aug 2003 19:44:56 +0100 Subject: better way to do this in Numeric References: Message-ID: "Duncan Smith" wrote in message news:bgm930$nce$1 at newsg4.svr.pol.co.uk... > > "John Hunter" wrote in message > news:mailman.1060008547.3901.python-list at python.org... > > > > I have a list of indices and want to assign the number of times an > > index shows up in the list to an array with the count specified at the > > index; ie, > > > > from Numeric import * > > > > a = zeros((10,), Int) > > ind = [1,1,4,4,4,4,7,7,9,9,9,9,9] > > > > for i in ind: > > a[i] += 1 > > > > I'm wondering if there is a way to use some combination of Numeric > > array functions to make this speedy. > > > > Thanks, > > John Hunter > > > > import Numeric > > >>> ind = [1,1,4,4,4,4,7,7,9,9,9,9,9] > >>> res = Numeric.searchsorted(ind, Numeric.arange(10)) > >>> res = Numeric.concatenate([res, [len(ind)]]) > >>> res[1:] - res[:-1] > array([0, 2, 0, 0, 4, 0, 0, 2, 0, 5]) > >>> > > Duncan > > I assumed the list was sorted. If not, >>> ind = [7,1,9,1,4,4,4,7,9,9,9,4,9] >>> res = Numeric.searchsorted(Numeric.sort(ind), Numeric.arange(10)) >>> res = Numeric.concatenate([res, [len(ind)]]) >>> res[1:] - res[:-1] array([0, 2, 0, 0, 4, 0, 0, 2, 0, 5]) >>> Duncan From jarausch at igpm.rwth-aachen.de Wed Aug 6 05:48:02 2003 From: jarausch at igpm.rwth-aachen.de (Helmut Jarausch) Date: Wed, 06 Aug 2003 11:48:02 +0200 Subject: check if running under IDLE In-Reply-To: <13a533e8.0308051237.6bfa05d3@posting.google.com> References: <3f2ec16b$0$285$ba620e4c@reader0.news.skynet.be> <13a533e8.0308051237.6bfa05d3@posting.google.com> Message-ID: <3F30CED2.7070609@igpm.rwth-aachen.de> Peter Abel wrote: > Helmut Jarausch wrote in message news:<3f2ec16b$0$285$ba620e4c at reader0.news.skynet.be>... > >>Hi, >> >>I'd like to check a script which needs sys.argv >>I haven't seen a method to set this when running the script >>in IDLE's shell or editor window. >>The only way I've found is to assign (test values) >>to sys.argv but only if the script is running under IDLE >> >>Is there a mean either to set sys.argv without modifying >>the script or to check if the script is running under IDLE's >>control. >> >>Thanks for a hint, >> >>Helmut Jarausch >> >>Lehrstuhl fuer Numerische Mathematik >>RWTH - Aachen University >>D 52056 Aachen, Germany > > > > I doen't think that your problem is to know if > you're running under Idle or PythonWin or Pythonshell > or .. > I think your problem is to know if there are command line > parameters passed to your script or not. And this is simply > done by: > if len(sys.argv) > 1: > do_something_with(sys.argv[1:]) > else: > do_something_else_with_explicit(['Para_1','Para_2', ... ,'Para_Last'] > > Hope I'm not wrong. I think so. To check a script accessing sys.argv I have to set it. Unfortunately the 'Run' pulldown menu of IDLE doesn't have an item to set sys.argv as it's common with debuggers for C. Now in Python I can set sys.argv within the script, but forgetting to comment this out afterwards makes the script wrong outside of IDLE So I'd like to say if __IDLE_IS_RUNNUNG__: sys.argv=['test','-a','/home/jarausch/BackUp'] but I haven't work how to check if the script is running under IDLE's supervision. Thanks, Helmut. -- Helmut Jarausch Lehrstuhl fuer Numerische Mathematik RWTH - Aachen University D 52056 Aachen, Germany From aahz at pythoncraft.com Sat Aug 2 10:16:13 2003 From: aahz at pythoncraft.com (Aahz) Date: 2 Aug 2003 10:16:13 -0400 Subject: How do I get a reference to a KEY value of a dictionary? References: <645db655.0307311636.71923378@posting.google.com> Message-ID: In article , Andy C wrote: > >I don't see how I can do this and let me eliminate duplicates. I need >to assign the old duplicate string to the unique string that already >exists. Hence the question, how do I get a reference to the KEY value? >I know I can use keys() and do a linear search, but that is much more >inefficient. I would like to get a reference to the key value in the >same time that it takes to do a hash lookup (constant time). Ahhhh.... Right. Hmmmmm.... You're correct, you do need to set the value to the key. I think using a dict is better than using intern(). Here's an optimization: node2 = node_cache.setdefault(node2, node2) >The intern solution seems reasonable, and it appears that it was >designed specifically for this problem. I wasn't aware of the >implementation problems. But I'm still curious about different ways to >do it. intern() is intended more for a small-scale optimization of frequently-used strings rather than as a mechanism for memory management. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From timr at probo.com Wed Aug 27 23:43:38 2003 From: timr at probo.com (Tim Roberts) Date: Wed, 27 Aug 2003 20:43:38 -0700 Subject: Decoding MIME email References: Message-ID: Thomas Williams wrote: > >Thanks, I tried it and it stop at: >f = file("mail.txt") >with the error message. > >TypeError: 'str' object is not callable I'll wager you have a line something like this before that: file = sys.argv[0] .... f = file("mail.txt") Either do not use variables called "file", or replace the "file" with "open" in your function call. -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From brian at sweetapp.com Sun Aug 10 01:51:44 2003 From: brian at sweetapp.com (Brian Quinlan) Date: Sat, 09 Aug 2003 22:51:44 -0700 Subject: Python vs. C# In-Reply-To: <3f35c30d@shknews01> Message-ID: <000601c35f03$7ab1a930$21795418@dell1700> > 4. forcing everything into a class is stupid e.g. does anyone really > > like writing Math.sin(x) over sin(x)? > > Although tacky at first glance, it's not entirely stupid. I've written > many, many variations on sin(x) cos(x) because one often wants an > efficient approximation for some algorithmically specific purpose. They > all end up with slightly funny different names, so why not namespace 'em? Sure, putting everything in a namespace makes sense and, in C#, everything must be in a namespace (in .NET, Math is in the System namespace). So why force two levels of namespacing? You could have: System.sin() AND TableTrig.sin() AND CORDIC.sin() That is unambiguous without adding the extra level of indirection through a class name. The Python system is even more flexible: import math math.sin(1.0) OR: from math import sin sin(1.0) OR: from math import sin as msin from CORDIC import sin as csin import TableTrig msin(1.0) csin(1.0) TableTrig.sin(1.0) > And IIUC, you could simply write > > using Math > > and be done with the issue, I think. Nope. The using statement is for namespaces not classes. Cheers, Brian From ark at acm.org Wed Aug 20 07:18:53 2003 From: ark at acm.org (Andrew Koenig) Date: Wed, 20 Aug 2003 11:18:53 GMT Subject: for statement list comprehension-like extention proposal References: Message-ID: Ryan> i thought id ask here before wirting a PEP, if people thought it Ryan> would be a good enhancement to allow if clauses in regular Ryan> for-statements like so: >>>> for x in y if x < 10 : Ryan> is semantically equivalent to >>>> for x in [x for x in y if x < 10] : Ryan> but is shorter and easier to read. basically, the if works as a Ryan> filter for the values in the iterator. its not a major change, Ryan> purely syntactic sugar. and clearly backwards-compatible. Ryan> seem reasonable? Dunno -- is it really better than writing for x in y: if x < 10: as is already possible? If you could write it in one line, would you ever do so? -- Andrew Koenig, ark at acm.org From pu at vo.lu Sun Aug 3 03:06:04 2003 From: pu at vo.lu (Patrick Useldinger) Date: Sun, 03 Aug 2003 09:06:04 +0200 Subject: bug in file.write() ? In-Reply-To: References: <13a4e2e3.0307311443.299bd59d@posting.google.com> <3f2b5e60.36345431@news.lexicon.net> <3f2b7816_2@news.vo.lu> Message-ID: <3f2cb414_2@news.vo.lu> Hi all, > What Patrick's output seems to show is that after the failed copy, the > CDRom is almost exactly half full. This is suspicious. It's also > suspicious that the total is about 600Mb; shouldn't it be 640Mb or > 700Mb?? It's a CD-RW 80 min, formatted with B's Clip with file system UDF1.50. After formatting, Windows Explorer shows a capacity of 572MB, with 50KB being used (for catalogue nd allocation tables, I suppose). > What Patrick's output doesn't show is what is the size of the input > file (from the I: drive). This would be very useful information. After > the failure, there is a 299Mb file on the CDRom. Is that the whole > file or not? The original file is 308.711KB in size; so the copied file is 94,94% of the original. > Does the failure happen after 0% 50% or 100% of the time > taken by a successful copy using the NT Explorer? I just did a test, it is after 92,5% of the time used by Explorer. > After the failure, > can you copy say 100Kb file to the CDRom i.e. is the 299Mb free space > spurious? I just copied OpenOffice 1.02, i.e. 50MB, without any problem: Directory of F:\ 02/08/2003 22:41 . 02/08/2003 22:41 .. 03/08/2003 08:58 300.122.112 dfcArchive cheetah 20030731-234648 F.zip 12/04/2003 18:54 51.955.157 OOo_1.0.3_Win32Intel_install.zip 2 File(s) 352.077.269 bytes 2 Dir(s) 248.174.592 bytes free > [Bengt] I wonder if 1) the error message is for real or is another > error condition improperly reported > John> Me too. It's not impossible for a write failure of various sorts > to be reported as "file full. Quite possible, as I repeated a similar test with a floppy disk, but that one worked OK (with a file larger than 50% of the disks capacity). I have also repeated the procedure with different CD-RWs of different makes and capacities, but the percentage of 50 stays the same. > Further observations: (1) IMHO you are taking a big gamble using stdio > to copy to a CDrom. Is I: a network drive? I was under the impression > that even with "professional" purpose-built CD-burning software, one > should burn from a hard-drive, not be running other applications at > the same time, ... I: is my local 2nd harddisk, so I am really copying from a local harddisk to a CD-RW. Is there any other means I should have used in Python? Is used shutil.copy because it works cross-platform, and because it copies permission information. > Is the type of CD that you are using the sort that allows you to write > multiple times but only the last "session" is visible, and the > previous sessions still take up space -- i.e. it's not erasable, you > can't treat it in all respects just like a big fat 700Mb floppy disk? Not with UDF1.5, as far as I know. I've been using CD-RWs for a few years now,and never experienced this situation. Regards, -Patrick -- Real e-mail address is 'cHVAdm8ubHU=\n'.decode('base64') Visit my Homepage at http://www.homepages.lu/pu/ From illo at students.cs.unibo.it Mon Aug 4 10:38:08 2003 From: illo at students.cs.unibo.it (Illo de' Illis) Date: 4 Aug 2003 14:38:08 GMT Subject: Python and SSL Message-ID: While I was coding a software which needs to set up a SSL transaction with a client using an underlying proprietary protocol, I found that the _ssl module works only in SSL client mode. Moreover it is impossible to write a select()-based polling algorithm with it since I can't query SSLObject for any available data in input (this occurs only for nonblocking sockets of course), or alternatively I can't push the characters I read back into the OpenSSL BIO cache. Since the patch to apply to _ssl for this stuff to work is trivial, I would like to know whether somebody is doing that. Ciao, Illo. -- De hierboven vermelde uitspraken behoren volledig toe aan mezelf en vertegenwoordigen niet de uitspraken, praktijken, of interpretaties van gelijk welke derde persoon of officiele instantie. From tzot at sil-tec.gr Fri Aug 22 21:12:43 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Sat, 23 Aug 2003 04:12:43 +0300 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: <3F412484.69867AED@alcyone.com> <3f415560$0$1124$626a54ce@news.free.fr> Message-ID: On Tue, 19 Aug 2003 00:47:40 +0200, rumours say that Bruno Desthuilliers might have written: >Just imagine what will happen when every >clp regulars will be in Brandon's kill file... "Where is everybody?" -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From tim.one at comcast.net Sun Aug 3 23:26:57 2003 From: tim.one at comcast.net (Tim Peters) Date: Sun, 3 Aug 2003 23:26:57 -0400 Subject: time, calendar, datetime, etc In-Reply-To: Message-ID: [Dan Bishop] >>> There were no leap years between 10 BC and AD 4, because after >>> Julius Caesar's death, the priests in charge of the calendar >>> mistakenly added leap days every 3 years instead of 4, and this had >>> to be corrected. >>> >>> I wouldn't expect the datetime module to deal with that, though ;-) [Tim] >> Thank you -- some people did . [John Roth] > I don't think I noticed that: Were you a participant in datetime's design process (the fishbowl on zope.org, previously referenced)? If so, sorry, I don't recall it. > the entire point behind the proleptic calender is that you're > projecting the current practice back to times where they weren't > doing it that way. And forward too, of course. But not everyone *wanted* a proleptic calendar (of any flavor). The use cases on the datetime wiki turned out not to care either way (business uses generally don't give a rip about years before 1900), so I pushed for the conceptual simplicity of the proleptic Gregorian (which coincides with current reckoning in much of the world, so satisfied the use cases). > That's clearly an opportunity for someone to add an extension - > except that there are other problems in that era, and the lack > of leap years is the least of them. People who care can scratch their own itches. From ryanlowe0 at msn.com Sun Aug 24 11:42:29 2003 From: ryanlowe0 at msn.com (Ryan Lowe) Date: Sun, 24 Aug 2003 15:42:29 GMT Subject: python gripes survey References: <7s6gkv031b940dsc522pbh5g30q4nj5vd1@4ax.com> Message-ID: "Andrew Dalke" wrote in message news:MOX1b.1042$Jh2.797 at newsread4.news.pas.earthlink.net... > Ryan Lowe: > > i was actually more impressed with the union/intersection of lists and > > dictionaries. why the hell cant you join two dictionaries like you can two > > list? the len thing is a pretty minor issue in my mind. > > Mostly because there isn't a good reason for what > > a = {1: "a"} + {1: "b"} > > should be. The most likely solution is > > a = {1: "a"} > a.update({1:"b"}) works for me, but i dont want to argue about it when there is another thread about this. > > However, there is something tricky even here. Watch this: > > >>> d = {1: "a"} > >>> d.update({True: "b"}) > >>> d > {1: 'b'} that is weird; i thought 2.3 made bool its own type? but i guess its still a subtype of int. though, i cant imagine when this would come up in a real situation anyway. > Missing language functionality is not the same as missing Python > functionality. What you're asking is - why do other languages > exist? Python lacks native support for: yea, this is what im talking about. maybe you could explain a couple of these a bit? > code blocks (like Smalltalk) is this what it sounds like? do you name a block of code and call it like an inline function with no parameters? > macros (like Lisp) > lazy evaluation (like .. Haskell? One of the functional languages) i learned and forgot what lazy evaluation was. does it buy you anything other than speed in certain cases > rich N-dimensional operators (like APL) python could do the same with functions or named operators > symbolic math manipulation (like Mathematica) this is approaching the limited domain area. plus mathematica spent a LOT of money and time writing that software. its not something your average open-sourcer would probably wish to tackle in their spare time. of course, it would be nice to have a symbolic module :) > color as part of syntax (like ColorForth) color meaning built-in? this i have never heard of. how does it work? > predicate logic (like Prolog) > literate programming (like WEB -> Pascal/TeX) > aspect-oriented programming (like AspectJ) > stack nature (like Postscript (I had Forth here but didn't want a dup :)) > programming by contract (like Eiffel) can any of these be explained quickly? > support for high-performance multiprocessor computing (like Fortran90) > fixed-point data types, as for money (like REXX) > control over the memory arenas use by an object (like C++) > direct access to memory, eg, as for I/O to periphials (like C) > (some are available as external modules, like FixedPoint, but are > not native.) > > There's easily more - just look at how many languages have > been invented over the last few decades. > > Andrew > dalke at dalkescientific.com > From bokr at oz.net Sun Aug 17 04:51:19 2003 From: bokr at oz.net (Bengt Richter) Date: 17 Aug 2003 08:51:19 GMT Subject: Eight Queens Puzzle by Magnus Lie Hetland References: <215fa0fc.0308130557.7f1c950b@posting.google.com> <3f3c1007$0$177$a1866201@newsreader.visi.com> <3F3CC067.5010102@users.ch> Message-ID: On Sat, 16 Aug 2003 12:12:47 +0200, anton at vredegoor.doge.nl (Anton Vredegoor) wrote: >bokr at oz.net (Bengt Richter) wrote: > >>I decided to see how it would go if I did the same thing using a set of position tuples >>to represent a board. I found that the strict ordering of the bitmap in a long was doing >>stuff I wanted (i.e., allowing me to use it as a unique dict key), so I wound up representing >>solutions as tuples of the set tuples, sorted. I changed the printout to print any of the 92 >>showing a selected unique solution along with the transformation(s) to transform the unique >>to the other. > >First of all, I explicitly disclaim to be able to follow precisely >what you have been programming. This reply is just because some of the >things you are talking about seem to be vaguely reminiscent of the >things I'm doing. I suspect you are being too modest. Maybe immodestly modest ;-) OTOH, I think my code has some silliness in it that is probably hard to understand the reason for ;-P (E.g., the redundancies in the transforms returned by the transform function generator. I really didn't need two kinds of flips. Obviously (after seeing your code and on thinking ;-) a board has two sides with four rotational positions each, for a total of 8 == 1 identity plus 7 T's ;-/ ) > >IMO it would be best to find a unique representative for a solution, >for example by hashing all its mirror images and always choosing the >mirror image with the smallest hash value as a canonical >representative for a solution. > I like the general idea, but in this case ISTM we are filtering an original set of solutions to eliminate some of them according to a filter which happens to check for symmetries mapping to the already chosen. Pre-calculating a canonical choice amongst the symmetries seems like potential extra work, since it doesn't allow short cut logic to notice that one of the transforms already happens to *be* the canonical version and can be found already in the unique set. See code below for a bitvector version that shortcuts in uniqueness testing. > >>I guess I might think that a set of small integers might map nicely to bits in an int or long >>and back, and might be useful as a hidden optimization. >> >>Another useful thing might be to make a set hashable by sorting the element list and >>hashing that as a tuple, the way I did manually. Of course it wouldn't always work, but >>if e.g., the underlying representation was a bit vector, it could work fast. You'd >>want a coercion method to accept a long or int as a bit vector integer set representation, >>or maybe an as_bitvec property that you could operate through, e.g., >> >> mySet = sets.Set() >> mySet.as_bitvec |= 0xff >> >>could mean the same as >> >> msSet = sets.Set() >> mySet |= sets.Set(range(256)) > >The comment I made above is still valid here, so please take my >remarks with a grain of salt. I *think* you are advocating that sets >could (and should) sometimes be represented with long integers, which >I heartily agree with. Dictionaries are close competitors for set >programming and have the advantage of being faster. In order for sets >to have a niche in the programmers mind they should be blazingly fast >and this can be done nicely by representing them by long integer >*bitfields*. This has been discussed before, see for example: > >http://home.hccnet.nl/a.vredegoor/universe Sorry to say, that got me -- Not Found The requested URL /a.vredegoor/universe/default.css was not found on this server. Apache/1.3.26 Server at home.hccnet.nl Port 80 -- > >(the link above points to a broken set implementation, I'm just using >it as an example of a possible alternative way of programming sets, I >still think that it is possible to program sets this way, but progress >in this area has been halted for quite some time now, and the project >is lingering in limbo) > I think the sets implementation could hide the representation transparently, something like integers can be represented as 32-bit ints until they are automatically promoted to longs. I.e., if you create a set whose members are always from range(32), then an int can be used internally. Similarly for some reasonable number of bits of long. That's just a hidden optimization until you want to convert the set to something else. The thing is that the representation has implicit order, which you don't have to use, but which eliminates sorting to get a canonical representation of the set, when/if you want that, or other mappings dependent on canonical order. >Specific for the queen solving problem however is the need to reduce >the search space (I'm just assuming people generalize the problem to >n-sized boards) and this can be done by using symmetry to find >solutions which represent whole categories of solutions. I'm >interested in the problem because finding representative solutions is >used in a lot of other areas too. For example -in my case- programming >go -baduk- can use it effectively and also it can be used for >programming solutions to rubiks cubes of size 5x5x5 and up. > >What I like to do is to find the canonical representatives first and >to generate the list of solutions later, by applying the different >transforms to them. I think neither my code below nor your code -which >is much appreciated- do that. > >A completely different problem is the need to write readable code, >which I have not solved yet. When the subject of the code is getting >more and more abstract -as is the case with mirror transforms of >abstractions from solution spaces- the advantages of Python as a >readable programming language dwindle fast. The same kind of problems >can be observed when trying to read numerical Python code or code >about three -or more- dimensional computations or when reading >difficult combinatorics code. That territory seems interesting and pretty, but I have hardly explored any of it at all. > >While the code is readable for the coder, anyone else has a hard time >to reproduce the *history* of code creation which IMO is an important >cue for why the code has become as it is instead of having been done >in a different way. Since you're posting different developmental >versions the readers get a view in your kitchen and can have a look at >your coding recipes and follow the creative process, which is much >appreciated. Well, as you see, first versions are hardly ever worth much as code, except to communicate a general approach. But I think it's often worth more to post something that seems to work and communicates the idea than to try to polish prematurely. Almost inevitably, if someone is interested, they will at least stimulate some ideas on evolving the design, and often much more. > >As a counterexample I'm giving a piece of code of mine -also meant to >slow you down a bit to give me time to follow :-) - which does more or >less the same as your code (no competition however, your code is a lot >better) and is a bit easier to follow for *me only* [1] because I >programmed it. I wouldn't say my code is better. (but I will say the code below is faster ;-) > >I wouldn't be surprised if even seasoned coders would have a hard time >following it, while it's only very simple code. If true, the audience >can give the verdict about what kind of code is easier to read and >which guidelines should be followed to make it easier to mentally >reproduce the *flow* of the program. > I think the only speed bump I hit was how that first yield in queens() really works. >Anton > >[1] A friend of mine when asked for solutions to difficult >mathematical problems, sometimes replies by sending me the solution in >the form of an -incomprehensible- excel spreadsheet :-) I'm still >trying to get even the idea of using Python for communicating >solutions across, in order to not replace one problem with a solution >inside another problem. > > >< snip much appreciated yet hard to follow code > Sorry, I will try to comment better. And I should have factored aside the interactive presentation part. I was hacking things in to feed that. >>====< queenset.py >======================================================== >< and returning the favor (maybe it's a lot easier to read? I don't >think so :-) > First some timings. I changed your code so test just returns the appends to a list of solutions instead of printing them, and then returns the list, so I wouldn't be timing the printing. A version I made is almost identical in timing, even though it pre-creates various mappings and helper functions (all of which is part of the time measured, for fairness). I won't show the code here. Then I decided to illustrate what I meant by early out logic in filtering for uniqueness vs calculating all mirrorings and choosing a canonical, and only then checking. Of course using bit maps makes things faster, and accounts for most of it. I also wonder whether putting the identity function first or last is better. I will resist temptation to test right now ;-) [ 0:45] C:\pywk\clp\queens>tanton.py 4 testing 4 x 4 ... anton_orig2: 0.010149 anton (new): 0.010964 bitqueens: 0.005826 [ 0:47] C:\pywk\clp\queens>tanton.py 5 testing 5 x 5 ... anton_orig2: 0.052339 anton (new): 0.047755 bitqueens: 0.017368 [ 0:47] C:\pywk\clp\queens>tanton.py 6 testing 6 x 6 ... anton_orig2: 0.242987 anton (new): 0.236497 bitqueens: 0.025699 [ 0:47] C:\pywk\clp\queens>tanton.py 7 testing 7 x 7 ... anton_orig2: 1.549231 anton (new): 1.507050 bitqueens: 0.104489 [ 0:47] C:\pywk\clp\queens>tanton.py 8 testing 8 x 8 ... anton_orig2: 10.707655 anton (new): 10.630505 bitqueens: 0.315929 [ 0:48] C:\pywk\clp\queens>tanton.py 9 testing 9 x 9 ... anton_orig2: 81.656248 anton (new): 81.697701 bitqueens: 1.340059 [ 0:51] C:\pywk\clp\queens>tanton.py 10 testing 10 x 10 ... anton_orig2: 675.432185 anton (new): 679.048513 bitqueens: 4.385570 The screen saver came into this last one, but you can see bitqueens is increasing its advantage. One more from the kitchen ;-) ====< bitqueens.py >====================================================== """ bitmap of board 0 1 2 ... n-1 n n+1 n+2 ... 2*n-1 2*n 2*n+1 2*n+2 ... 3*n-1 ... (n-1)*n (n-1)*n+1 (n-1)*n+2 ... n*n-1 """ threatfrom = {} queenat = {} def qandt(n): """generate two dictionaries mapping i,j board index tuples to a single bit vector board representation with a single bit for a single queen in the queenat dict, and all the bits covered by that queen in the bit vector for threatfrom.""" for row in xrange(n): for col in xrange(n): queenat[row,col] = 1L<<(n*row+col) threat = 0L for r in xrange(n): for c in xrange(n): if r==row or c==col or abs(r-row)==abs(c-col): threat |= 1L<<(n*r+c) threatfrom[row,col] = threat def printsol(sol, n=8): """print a bit vector solution with Q in queen positions and + elsewhere.""" for row in range(n): for col in range(n): print '+Q'[(sol>>(row*n+col))&1], print def solok(sol, n=8): """check that each queen doesn't threaten the rest""" for row in range(n): for col in range(n): if (sol>>(row*n+col))&1: q = 1L<<(row*n+col) if (sol^q) & threatfrom[row,col]: return False return True def doqueens(n): """recursively place a queen in each successive row from 0 to n-1 by checking each column still available to see if threat from that position attacks any queens so far on the board. If not, place a queen there and recurse to the next row and remaining cols, until all rows are occupied. Append that board bitvector to the solution list and return to outer loops until every column of the first row has been recursed through. Return the whole list.""" solutions = {} def tryplace(board, row, cols): for col in cols: if (board&threatfrom[row,col]): continue qboard = board|queenat[row,col] if row>=1 return board mirrorfuns.append(mirrorboard) mirrorfuns.append(lambda b:b) #I def unique(solutions, n): """return the unique subset of the solution list, such that none is a mirroring of another.""" mkmirrorfuns(n) # make list of the 8 functions (identity last) unique = {} for sol in solutions: for mf in mirrorfuns: if mf(sol) in unique: break # early out if match else: unique[sol]=None # no match, so unique return unique.keys() def test(n): """set up tables mapping coordinates i,j to bitvector board representations of single queens in queenat, and the squares they cover as a multibit vector in threatfrom. Then generate a set of functions that do the eight kinds of mirroring of bitvector boards. Then generate the full set of solutions. Then filter the full set by accumulating a set that is not added to unless a candidate solution has no mirrored solutions in the unique set being accumulated.""" qandt(n) # queenat and threatfrom dicts keyed by [i,j] solutions = doqueens(n) return unique(solutions, n) if __name__ == '__main__': import sys n = int(sys.argv[1]) solutions = test(n) loop = '' nsolutions = len(solutions) for i, sol in enumerate(solutions): assert solok(sol,n) # just for warm fuzzies if loop in ['', 'a']: print '\n====[ Solution # %s of %s ]====[ bitmap %X ]====\n'%( i+1, nsolutions, sol) printsol(sol,n) if loop=='': loop ='x' while loop not in ['','a','q']: loop = raw_input('\nPress Enter for another, a for all, q to quit: ') if loop =='q': break ========================================================================== Oops, some of the description of test should be in unique, where the mirror function setup got moved. I don't like the globals, but time to close the kitchen for now ;-) Regards, Bengt Richter From joshway_without_spam at myway.com Thu Aug 21 04:02:55 2003 From: joshway_without_spam at myway.com (Joshua Marshall) Date: Thu, 21 Aug 2003 08:02:55 +0000 (UTC) Subject: What's better about Ruby than Python? References: Message-ID: Alex Martelli wrote: ... > But with try/finally, or hopefully some syntax tweak making > try/finally semantics even easier to use, this is a kind of idiom > that's gonna stay. What sort of syntax tweak? From pobrien at orbtech.com Thu Aug 28 22:46:02 2003 From: pobrien at orbtech.com (Patrick K. O'Brien) Date: 28 Aug 2003 21:46:02 -0500 Subject: Object Database (ODBMS) for Python References: <1DAECE9E8F34E04AA0E5699AF7D9FF090708D440@stpmsg00.corp.fairisaac.com> Message-ID: Jeremy Bowers writes: > On Thu, 28 Aug 2003 20:26:41 -0500, Patrick K. O'Brien wrote: > >>>> u1.name > > 'Bob' > >>>> u1.name = 'Joe' > > Traceback (most recent call last): > > File "", line 1, in ? > > File "/home/pobrien/Code/pypersyst/entity/entity.py", line 94, in > > __setattr__ > > raise AttributeError, 'Modifications can only be made by transactions' > > AttributeError: Modifications can only be made by transactions > > > > So, let's use a transaction: > > So why *isn't* it a transaction? Unless you have a good reason not > to, I'd suggest automatically "coercing" that into a transaction > instead of throwing an error. These are some of my reasons: 1) every transaction gets pickled and logged before executed, so that the database can recover from a crash, 2) most of the other cool features depend on mutations passing through the extent manager for each class, 3) transparent transactions only seem like a good idea, 4) security is hard to enforce without explicit boundaries (read the Twisted docs regarding Perspective Broker), 5) explicit is better than implicit, especially when valuable persistent data is involved. > Give an indication in the docs about the performance issues if you > like, but make the trivially easy case easy. Performance has nothing to do with it, actually. Integrity and security are to blame. > (I'm only really entering my maturity (IMHO) as a software engineer, > but one of my rules of thumb for developing software for other > people to use is that the API can ***never*** be too easy. Doing > something hard may be a little tricky but if you can make the easy > case still work, you're way ahead. And Python is one ass-kicking > language in that regard; it's one of the reasons I love it so much, > the APIs can be made so easy to use they sometimes fade into > complete transparency, like "u1.name = 'joe'". (I've been focusing > on how to write APIs for others to use, esp. in Open Source though > it applies equally to any team effort, that will be successful, > rather then ignored.)) I agree that APIs are very important, and I've worked very hard on the API for PyPerSyst. At the same time, everything has a tradeoff. When I gave up on the dream of transparent transactions, there were a lot of benefits, and lots of other features fell into place. Even though I think PyPerSyst is one of the most elegant things I've ever coded, especially in terms of the API, I'm sure it can be better. So I welcome suggestions for improving it. If you can figure out a way to have transparent transactions, without giving up on any ACID properties considered mandatory for a DBMS, I would love to hear about it. Have you worked with any other object databases? -- Patrick K. O'Brien Orbtech http://www.orbtech.com/web/pobrien ----------------------------------------------- "Your source for Python programming expertise." ----------------------------------------------- From mark at hahnca.com Wed Aug 27 23:51:10 2003 From: mark at hahnca.com (news.west.cox.net) Date: Wed, 27 Aug 2003 20:51:10 -0700 Subject: can generators be nested? Message-ID: This doesn't work, but is there any elegant way to do something like this? def gen2(): yield "hello" def gen1(): gen2() yield "world" for i in gen1(): print i ---- output ---- hello world I'm doing it this way now: def gen2(): yield "hello" def gen1(): for i in gen2(): yield i yield "world" From pedro.werneck at bol.com.br Mon Aug 18 11:30:19 2003 From: pedro.werneck at bol.com.br (Pedro Werneck) Date: Mon, 18 Aug 2003 15:30:19 +0000 Subject: Emacs python-mode,py-pychecker-run problem. In-Reply-To: <16192.65324.510002.620091@montanaro.dyndns.org> References: <20030818130844.7e5c1296.pedro.werneck@bol.com.br> <16192.65324.510002.620091@montanaro.dyndns.org> Message-ID: <20030818153019.1383649b.pedro.werneck@bol.com.br> On Mon, 18 Aug 2003 11:30:36 -0500 Skip Montanaro wrote: > And here's its implementation (from minibuf.el): > > (defun read-shell-command (prompt &optional initial-input history default-value) > "Just like read-string, but uses read-shell-command-map: > \\{read-shell-command-map}" > (let ((minibuffer-completion-table nil)) > (read-from-minibuffer prompt initial-input read-shell-command-map > nil (or history 'shell-command-history) > nil default-value))) > > Can you see if that definition works for you? If not, what about simply > substituting (read-string ...) for (read-shell-command ...)? Ok.. defining and using it returns the same error with "read-shell-command-map", but substituting for read-string works perfectly. Thank you, Skip Pedro From ayc8NOSPAM at cornell.edu Mon Aug 4 23:31:27 2003 From: ayc8NOSPAM at cornell.edu (Andy C) Date: Tue, 05 Aug 2003 03:31:27 GMT Subject: How do I get a reference to a KEY value of a dictionary? References: <645db655.0307311636.71923378@posting.google.com> <0UXWa.416$_57.26378288@newssvr21.news.prodigy.com> Message-ID: > >is fine for me. But if I'm not mistaken, your solution still stores the > >node names in the values of the dictionary (via the Node objects). So in > No, just references, not duplicate strings. OK, you're right -- I assumed that the key and value were duplicated, but that's not the case. I don't know why I thought that, maybe since the key must be immutable and the value is mutable. So I guess having a dictionary of the form { 'A': 'A', 'B': 'B' } is not as stupid as it first seems, since only a reference is stored. But still I wonder why the language doesn't have a facility for getting a reference to the key value in constant time. Apparently someone did it by modifying the C source for the dictionary to add a ref_key() accessor. It seems like it would be useful quite often. > One caveat though, if your graph has cycles, changing the adjacency lists to direct node > references instead of names will create reference cycles that may have to be broken for > the gc. I have to look into that. You can comment that fixup loop out if you want to > keep adjacency lists as name string references instead of node references. Good point... I thought though that the new python (2.3?) will GC data with cycles. > BTW, have you looked at the sets module of 2.3? That would let you have a set of strings > with no associated values, and no duplicates (but how do you represent adjacency lists then?) Actually, I did run across the sets type recently. It is actually built *on top of* dict, so it's no better. Ex: >>> a = Set([1,2,3]) >>> a Set([1, 2, 3]) >>> a._data {1: True, 2: True, 3: True} It just stores a dummy value as the value of the dict. BTW I am using a regular dictionary for the adjacency list, with the list of destination edges. I was using another dictionary for the 'cache' of names. Thanks for the help. Andy From sjmachin at lexicon.net Mon Aug 4 08:04:20 2003 From: sjmachin at lexicon.net (John Machin) Date: 4 Aug 2003 05:04:20 -0700 Subject: pyrex error References: <8YPWa.48874$YN5.38312@sccrnsc01> Message-ID: Gerhard H?ring wrote in message news:... > Bryan wrote: > > [PyRex produces code using staticforward that won't work in the combination Python 2.3/MSVC] > 2) The other way to temporarily solve this problem is to use MINGW > instead of MSVC. *One* other way, not *the* other way. If the OP wanted to muck about downloading and becoming familiar with a different compiler, he could also try the free Borland compiler. And here is a third, easier other way: fiddle with your ....\include\object.h so that it defines staticforward as extern. It appears we have a change from 2.2 to 2.3 that breaks extensions compiled with the MS C compiler, which is used to build the win32 version of Python ... say it ain't so, Joe! ==== from v2.2 object.h ==== /* A common programming style in Python requires the forward declaration of static, initialized structures, e.g. for a type object that is used by the functions whose address must be used in the initializer. Some compilers (notably SCO ODT 3.0, I seem to remember early AIX as well) botch this if you use the static keyword for both declarations (they allocate two objects, and use the first, uninitialized one until the second declaration is encountered). Therefore, the forward declaration should use the 'forwardstatic' keyword. This expands to static on most systems, but to extern on a few. The actual storage and name will still be static because the second declaration is static, so no linker visible symbols will be generated. (Standard C compilers take offense to the extern forward declaration of a static object, so I can't just put extern in all cases. :-( ) */ #ifdef BAD_STATIC_FORWARD #define staticforward extern #define statichere static #else /* !BAD_STATIC_FORWARD */ #define staticforward static #define statichere static #endif /* !BAD_STATIC_FORWARD */ ==== from v2.3 object.h ==== /* Define staticforward and statichere for source compatibility with old C extensions. The staticforward define was needed to support certain broken C compilers (notably SCO ODT 3.0, perhaps early AIX as well) botched the static keyword when it was used with a forward declaration of a static initialized structure. Standard C allows the forward declaration with static, and we've decided to stop catering to broken C compilers. (In fact, we expect that the compilers are all fixed eight years later.) */ #define staticforward static #define statichere static From max at nospam.com Mon Aug 4 09:40:55 2003 From: max at nospam.com (max) Date: Mon, 04 Aug 2003 13:40:55 GMT Subject: win32serviceutil.ServiceFramework options? In-Reply-To: References: <%LAWa.52662$On.7421180@twister.nyc.rr.com> Message-ID: > You install it using "--startup=auto". See > win32serviceutil.HandleCommandLine() for more details. > > Mark. > Mark, this works OK with the original service, but after py2exe the option is gone... max. From FBatista at uniFON.com.ar Fri Aug 1 13:52:37 2003 From: FBatista at uniFON.com.ar (Batista, Facundo) Date: Fri, 1 Aug 2003 14:52:37 -0300 Subject: list indexing Message-ID: #- But this only works for single instances, since it finds the first: #- >>> li = 'this is a list with a repeated word in this list'.split() #- >>> for item in li: print li.index(item), item #- ... #- 0 this #- 1 is #- 2 a #- 3 list #- 4 with #- 2 a #- 6 repeated #- 7 word #- 8 in #- 0 this #- 3 list #- #- I wondered at first if there was a way to do it directly, #- but I usually #- ended up making a companion range of indexes to zip(), and #- now will use #- enumerate(). Was there a direct method that I never found? What is the specific behaviour are you searching for? Ask for the index and receive a tuple with all the indeces? . Facundo From speakstofish at hotmail.com Tue Aug 26 13:44:03 2003 From: speakstofish at hotmail.com (Fahd Khan) Date: 26 Aug 2003 10:44:03 -0700 Subject: Preferred standalone TAL module? References: <5d855b4b.0308251419.31e894e6@posting.google.com> <20030826085001862-0400@braeburn.themorgue.org> Message-ID: <5d855b4b.0308260944.380e59d4@posting.google.com> Ah I hadn't realized that when people spoke of ZPT they were referring to a specific package, rather I thought they meant Zope itself. This will be a good opportunity to see how my current templates and scripts work when I drop in another implementation. And seeing as my current application involves analyzing SAS output in Python, I'll take this as a sign. ;) Kevin Smith wrote in message news:<20030826085001862-0400 at braeburn.themorgue.org>... > http://zpt.sf.net uses the actual Zope sources with just a thin wrapper > around them to make them work outside the Zope framework. They aren't > currently in development simply because they are up to date with the > Zope source. > > In <5d855b4b.0308251419.31e894e6 at posting.google.com> Fahd Khan wrote: > > The web-based Python software I've written thus far lacks a consistent > > approach to generating output. After reading Graham Fawcett's > > endorsement of Zope Template Pages in the recent web programming > > thread, I looked up TAL and found it to be quite nice. Going through > > recent postings on Google it seems SimpleTAL is the standalone TAL > > module in most active usage and development just now, would the > > community concur or suggest alternatives? > > > > Here's the post I'm referencing: > > http://groups.google.com/groups?safe=images&ie=UTF-8&oe=UTF-8&as_ > > umsgid=e9570f37.0304070923.70612d28 at posting.google.com%20&lr=&hl=en > > > > I'm also motivated by the web programming thread's underlying message > > of seeking "industrial strength" solutions that work in many domains > > using existing tools, so that I spend more time coding and less time > > "shopping" for modules. TAL seems a good way to do that (I'm most > > certainly not ready to take the plunge into Zope). Any comments there? > > > > Fahd Khan > > From zooko at zooko.com Wed Aug 6 10:11:45 2003 From: zooko at zooko.com (Zooko) Date: 6 Aug 2003 10:11:45 -0400 Subject: Freeze Question Message-ID: Skip: Thank you very much for posting this recipe. It happens to be exactly what I need right now. I think maybe steps 2 and 3 are in reversed order. Regards, Zooko Skip Montanaro wrote: > > I think Modules/Setup is about it. If I had to do this today, here's what > I'd do. > > 1. Starting from a clean source tree, run the 'script' command to get > a log of the session in a file named 'typescript'. > > 2. Exit the script session. > > 3. Run the usual 'configure ; make' commands. > > 4. Edit Modules/Setup, uncommenting those modules which you want built > statically. Many are simple and require no extra compile or link > flags. For others, use the build commands found in the typescript > file to identify -I..., -L..., and -l... flags. Obviously, omit or > modify any flags that would be used to generate a shared library > (-shared, -Bshared, -fPIC, etc). > > 5. Run 'make clean ; make' > > 6. Test the resulting executable. > > 7. Repeat steps 4-6 as necessary. > > 8. Congratulate yourself on a job well done and buy yourself a beer. From pedro.werneck at bol.com.br Mon Aug 25 16:20:53 2003 From: pedro.werneck at bol.com.br (Pedro Werneck) Date: Mon, 25 Aug 2003 20:20:53 +0000 Subject: Determinig position of a element in a list In-Reply-To: References: Message-ID: <20030825202053.1ad66645.pedro.werneck@bol.com.br> On Tue, 26 Aug 2003 00:29:04 +0200 "Przemo Drochomirecki" wrote: > i can implement function index (e.x. index(5,A) = -1, index(7,A) = 2), > but maybe there's is simpler(builtin?) solution I have a strange feeling that I misunderstood your question, because the list.index() builtin is pretty obvious: list.index(value, [start, [stop]]) If this is what you want, maybe you can use something like this: def index(value, lst): try: i = list.index(lst, value) return i except ValueError: return -1 a = [1,3,7,11,14,15] assert index(3, a) == 1 assert index(12, a) == -1 or maybe: class Ilist(list): def index(self, *args): try: i = list.index(self, *args) return i except ValueError: return -1 a = Ilist([1,3,7,11,14,15]) assert a.index(3) == 1 assert a.index(12) == -1 Rgds Pedro From spam at magnetic-ink.dk Sat Aug 16 04:05:03 2003 From: spam at magnetic-ink.dk (Klaus Alexander Seistrup) Date: Sat, 16 Aug 2003 08:05:03 +0000 (UTC) Subject: cPickle alternative? References: Message-ID: <3f3de5af-3dcdcb9a-e4f8-43c2-a49e-2e5009909839@news.szn.dk> Drochom wrote: >> import cPickle >> >> plik = open("mealy","r") >> mealy = cPickle.load(plik) >> plik.close() > > this takes about 30 seconds! > How can I accelerate it? Perhaps it's worth looking into PyTables: Cheers, // Klaus -- ><> unselfish actions pay back better From lyle at users.sourceforge.net Thu Aug 14 15:38:01 2003 From: lyle at users.sourceforge.net (Lyle Johnson) Date: Thu, 14 Aug 2003 14:38:01 -0500 Subject: SWIG and __int64 In-Reply-To: References: Message-ID: <3F3BE519.3060802@users.sourceforge.net> Matt Whelan wrote: > Supposedly, recent versions of SWIG can be made to work with MS VC++'s > non-standard integer data types. According to a recent SWIG ChangeLog > entry: > > %apply long long { __int64 }; > > should make Swig happy. But it doesn't. I get Syntax Errors on each > line where __int64 appears. Just to clarify: are you getting errors when running SWIG (i.e. to generate the wrapper code) or when compiling the code that SWIG generated for you? From dave at pythonapocrypha.com Sat Aug 23 06:44:18 2003 From: dave at pythonapocrypha.com (Dave Brueck) Date: Sat, 23 Aug 2003 04:44:18 -0600 Subject: python gripes survey In-Reply-To: References: Message-ID: <200308230444.18350.dave@pythonapocrypha.com> On Saturday 23 August 2003 09:39 am, Ryan Lowe wrote: > python is a big improvement on most languages that came before it, but no > language is perfect. id like to make a list of some of the aspects people > find most annoying, regardless of their feasibility of implementation. for > instance, i discussed putting if clauses in for loops, and i noticed > another thread about allowing {} and [] to be added and subtracted. if its > something from another language (especially an obscure one), please explain > how it works in case people like myself dont know the language. Well, will your list include anti-gripes, as in things a few people gripe about but that many others consider to be positive features? Here's a short list of my anti-gripes - features that I like but some people complain about; features that, if removed or changed too much, would make me like Python less: - no assignment in if/while - whitespace significant to both programmer and the language - {} + {} not allowed ;-) - private variables are a language-encouraged convention instead of an attempt to babysit the programmer - no macros - no end-block tag required - list comprehensions - a "self" parameter is passed to all class methods, and by convention we all call it "self" - tendency to prefer keywords over special characters - thread-safe operations on fundamental objects (e.g. two threads doing somedict['foo'] = x at the same time won't cause Python to crash or corrupot somdict) - list.sort() doesn't return the sorted list There are more, but this list is just off the top of my head. :) -Dave From mpeuser at web.de Sat Aug 16 12:35:13 2003 From: mpeuser at web.de (Michael Peuser) Date: Sat, 16 Aug 2003 18:35:13 +0200 Subject: How to terminate a TkinterApp correctly? References: <3F3DFCF4.5020109@aon.at> <3f3e37c6$0$19888$91cee783@newsreader01.highway.telekom.at> Message-ID: ----- Original Message ----- From: "Gregor Lingl" Newsgroups: comp.lang.python Sent: Saturday, August 16, 2003 3:53 PM Subject: Re: How to terminate a TkinterApp correctly? .... > Thanks for your remarks and your example. The > following solution finally did it: > > def exit(): > global done > done = True # so the animation will terminate, but > # not immediately! The actual pass through > # the loop has to be finished. > print "done!" > import sys > # after_idle seems to be crucial! Waits for terminating > # the loop (which is in a callback function) > cv.after_idle(sys.exit, (0,)) Why don't you just return? The mainloop can handle everything!? Example: def exit(self): self.done=1 return (If you can put it into an appropriate class ....) > > cv.master.protocol("WM_DELETE_WINDOW", exit) > > if not usingIDLE: > root.mainloop() > > Regards, Gregor > From see at below.invalid Sat Aug 23 06:00:35 2003 From: see at below.invalid (Paul Foley) Date: Sat, 23 Aug 2003 22:00:35 +1200 Subject: For Kenny Tilton: Why do I need macros revisited. References: <3f45484f$1_6@corp.newsgroups.com> <3F45A7BF.4060806@nyc.rr.com> <8dk1b.2825$Ej6.1159@newsread4.news.pas.earthlink.net> <40udnfEuVojnr9uiXTWJjg@comcast.com> Message-ID: On Fri, 22 Aug 2003 11:10:49 -0400, Terry Reedy wrote: >> Scheme macros are not the same as Lisp macros. Scheme macros are a >> lot more complicated (and less useful; but most Scheme implementations >> also offer Lisp-style macros...) > Please excuse my confusing of Scheme with Lisp. I am pleased to find > that my difficulty in reading the Scheme macro stuff wasn't just me. > But note that there have been proposals that if Python were to have a > macro facility, it should be 'hygenic', which I presume means like > Scheme macros. > Until some advocate of a Python macro facility adds more detail to the > proposal beyound 'Lisp/Scheme-like maco facility', it is really hard > for someone like me, who has used neither, to have much of any > concrete idea of what is being proposed. I don't know what others are proposing. In Lisp, a macro is really just a function like any other (so people arguing against macros who are not also against functions are clearly insane!). It takes two arguments: a "form" (i.e., some Lisp code) and an "environment" (a fairly useless opaque object), and returns more Lisp code. So (a simplified version of) EVAL in a Lisp without macros might look something like (defun eval (form) (typecase form (symbol (symbol-value form)) (atom form) (cons (apply (first form) (mapcar #'eval (rest form)))))) and to add macros, all that's necessary is (defun macroexpand (form) (if
(macroexpand (funcall (macro-function (first form)) form )) form)) (defun eval (form) (let ((form (macroexpand form))) (typecase form (symbol (symbol-value form)) (atom form) (cons (apply (first form) (mapcar #'eval (rest form))))))) If you write a macro, LIST2, such that (LIST2 1 2 3 ...) expands into (LIST (LIST 1) (LIST 2) (LIST 3) ...), and then you use it in a function like (defun foo (list) (let ((x (list2 1 2 3))) ...)) in a Lisp-2 (i.e., a language with separate namespaces for variables and functions, so you can have both a variable and a function with the same name at the same time) there's no problem, but in a Lisp-1 (single shared namespace, like Scheme and Python) you'd have a big problem: when the list2 macro is expanded, "list" is a variable -- the argument to "foo" -- not the list-constructing function the macro-writer expected. So Scheme introduced the so-called "hygienic" macros [a bad name, implying that non-hygienic macros are "dirty" and to be avoided; "hygienic" macros are the ones I want to avoid!], where names used in the macro expansion are in the scope where the macro was defined, rather than the scope that's in effect where it's expanded, so that "list" in the expansion refers to the list function, not the argument to foo, and bindings made by the macro are not visible to code that comes in from user code. But Scheme macros are not just functions like Lisp macros, either. A Scheme macro is defined as a set of patterns to be matched against the code, and an associated rewrite rule which specifies the code to use instead. [I don't see any reason why these rules need to be written in a Lispy syntax...] -- Just because we Lisp programmers are better than everyone else is no excuse for us to be arrogant. -- Erann Gat (setq reply-to (concatenate 'string "Paul Foley " "")) From fincher.* at osu.edu Fri Aug 8 13:51:20 2003 From: fincher.* at osu.edu (Jeremy Fincher) Date: Fri, 08 Aug 2003 13:51:20 -0400 Subject: itertools.ilen? References: <98s4jvkqv94c0gj99epjanq9b3aqvq8i2q@4ax.com> Message-ID: Duncan Booth wrote: > I'm just curious, why did you decide to map the types to strings instead > of just using the types themselves? So I can pluralize them in my output. Jeremy From s0199583 at sms.ed.ac.uk Thu Aug 14 05:11:23 2003 From: s0199583 at sms.ed.ac.uk (Matt Smith) Date: 14 Aug 2003 02:11:23 -0700 Subject: COM :: VARIANT -eek References: <5f5c82ec.0308110207.1d42251@posting.google.com> <5f5c82ec.0308130542.6857fe74@posting.google.com> Message-ID: <5f5c82ec.0308140111.2356558e@posting.google.com> Mark Hammond wrote in message news:... > Matt Smith wrote: > > Mark Hammond wrote in message news:... > > > My problem is now this, when i go to makepy tool in pythonwin, it does > > not see/recognise the type library file I want it to convert. Is there > > anyway to add the file to the list of .tlb files it does does? > > These type libraries are in the registry. You may be able to pass the > filename on the commandline to makepy. > > > p.s. How do I include the generated makepy file into my code ? > > In generaly, you just need to generate the file and do nothing else. At > runtime, Python will see these generated files and automatically use them. > > I don't know how that will go with your type library though. > okay update on present situation ran (in pythonwin interactive window): >>> import win32com.client >>> from win32com.client import gencache >>> from win32com.client import pythoncom >>> gencache.EnsureModule('{AF684923-D245-11D3-8DE8-00A024ACAB85}', 0, 1, 0) >> v = win32com.client.Dispatch("v2wreg.Application") >>> print v as you can see the module is now being found but when I go to use dispatch it does not use the module as it was intructed to ? cheers, matt. From mis6 at pitt.edu Fri Aug 29 08:40:15 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 29 Aug 2003 05:40:15 -0700 Subject: Add two dicts References: <86ktkvkd05e88hu14hjudmfvbul7slfgkt@4ax.com> Message-ID: <2259b0e2.0308290440.670d316f@posting.google.com> Afanasiy wrote in message news:<86ktkvkd05e88hu14hjudmfvbul7slfgkt at 4ax.com>... > I have some code like this... > > self.write( > ''' > lots of stuff here with %(these)s named expressions > ''' > % vars(self) > ) > > Then I wanted to add an item to the dict vars(self), so I tried : > > vars(self)+{'x':'123','y':'345'} > > This doesn't work, perhaps because no one could decide what should happen > to keys which already exist in the dict? (I'd say throw an exception). > > Can I add two dicts in a way which is not cumbersome to the above % string > operation? Is this another case of writing my own function, or does a > builtin (or similar) already exist for this? Here is a possibile solution: class attributes(dict): def __init__(self,obj): if isinstance(obj,dict): self.update(obj) elif hasattr(obj,'__dict__'): self.update(obj.__dict__) else: raise TypeError("Dictionary or object with a __dict__ required") def __add__(self,other): self.update(other) return self.__class__(self) __radd__=__add__ class C(object): def __init__(self,x,y): self.x=x self.y=y c=C(1,2) print attributes(c) print attributes(c)+{'z':3} print {'z':3}+attributes(c) Michele Simionato, Ph. D. MicheleSimionato at libero.it http://www.phyast.pitt.edu/~micheles --- Currently looking for a job --- http://www.strakt.com/dev_talks.html http://www.ibm.com/developerworks/library/l-pymeta2/?ca=dnt-434 From electricity at uymail.com Mon Aug 25 12:13:20 2003 From: electricity at uymail.com (U. N. Owen) Date: Mon, 25 Aug 2003 18:13:20 +0200 Subject: Common tasks in python Message-ID: <20030825161320.3484.qmail@uymail.com> Starship seems ok, but have a look at the "updir" : http://starship.python.net/~da/ Here are the page contents (it's short !) I got rid of this web site because I could never keep it up to date. I'm too busy at ActiveState. If you need something that you think I have, find me and ask me nicely. My email address is made up of my first name and my first initial, at my employer's domain name. David Ascher Bye -- _______________________________________________ Get your free email from http://www.uymail.com Powered by Outblaze From aahz at pythoncraft.com Thu Aug 14 11:25:21 2003 From: aahz at pythoncraft.com (Aahz) Date: 14 Aug 2003 11:25:21 -0400 Subject: No doubt I should know this regex point but .. References: <545cb8c2.0308140709.281fb610@posting.google.com> Message-ID: In article <545cb8c2.0308140709.281fb610 at posting.google.com>, Jim Hefferon wrote: > >I am writing a class that walks through a file tree and (among other things) >filters out which files it considers. So I want to have > __init__( .. ,filterExpression='..') >For the default I want to filter nothing. So I need a Python regular >expression that never matches. What is (the best) one? None Seriously, make the default None, and test for it before trying a regex. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From jerf at jerf.org Thu Aug 21 22:20:05 2003 From: jerf at jerf.org (Jeremy Bowers) Date: Fri, 22 Aug 2003 02:20:05 GMT Subject: Which way to say 'private'? References: <14f9kv4fvuf67k6j12lpgt6vk9dcpefchm@4ax.com> Message-ID: On Thu, 21 Aug 2003 09:45:09 -0700, Daniel Klein wrote: > I should probably have mentioned that I am concerned about advertising the > 'public' interface (so that users of the class know how best to use it and > what my intentions were) more than 'restricting' access to 'private' > members, which we all know is pretty much pointless in Python ;-) I personally recommend "If it's not documented, it doesn't exist". Of course this requires rather better documentation procedures then most people use typically. The idea here is that the docstrings document what should be done with the class, and Python comments (# stuff) documents stuff private to the class. (Especially critical warnings about things that should *not* be done can go into the docstrings as well.) (Actually, IMHO, "if it's not documented it doesn't exist" is *already* a truth and this technique simply harnesses that, but again, this opinion is not as popular as it should be.) From fawcett at teksavvy.com Thu Aug 14 13:43:49 2003 From: fawcett at teksavvy.com (Graham Fawcett) Date: Thu, 14 Aug 2003 13:43:49 -0400 Subject: py2exe service and tool-tray app combined? In-Reply-To: <1xvop3ad.fsf@python.net> References: <3F3A8371.840.20CD3615@localhost> <1xvop3ad.fsf@python.net> Message-ID: <3F3BCA55.5040201@teksavvy.com> Thomas Heller wrote: >If you discovered a bug in an .sll file, you could either buid and >distribute a new version of it, or you could create an additional, new >.sll file containing the fixed methods. And you would make sure to list >this new .sll in the myapp.bnd file, before the buggy one. This way the >size of the upgrade could be kept as small as possible. > >Now, isn't this '.bnd' file mechanism also a nice idea for py2exe? > > "Nice idea" is an understatement, Thomas -- it would be heaven! Presumably the Python analog of the .sll file would have to contain new/corrected modules, rather than just new/corrected methods, unless you're one of those wild aspect-weaving types. And presumably there would be inspection mechanisms to allow for examination of the .bnd file, and provide an opportunity for fetching updates when the program boots... An installed app could "phone home" to an update-server, send nothing but a message digest of its .bnd file, fetch a new .bnd if the old one is stale, and pull down the missing-but-requisite .sll files... all before the __main__ module starts importing the app logic. That's cool. It would be nice, for long-running apps, if there were a facility for restarting the app automatically (under permitted conditions) if updated code were detected at the update server. Maybe just a runtime api for determining if the codebase is up to date, and then let the app make the decision whether to restart. All this could be done in the absence of py2exe, of course, but a standardized framework for this kind of thing would be ideal. It could complement PyPI and distutils as well, I would imagine. So, having swooned for a moment, let me ask: are you considering adding such a mechanism to the new py2exe? -- Graham From gh at ghaering.de Wed Aug 13 11:21:38 2003 From: gh at ghaering.de (=?ISO-8859-2?Q?Gerhard_H=E4ring?=) Date: Wed, 13 Aug 2003 17:21:38 +0200 Subject: libmysqld.dll & Python API seeking... In-Reply-To: References: Message-ID: <3F3A5782.5070601@ghaering.de> JZ wrote: > On Wed, 13 Aug 2003 13:50:48 +0200, Gerhard H?ring > wrote: > >>MySQLdb can be built against MySQL 4.x. It should be certainly possible >>to make it work against the embedded version of MySQL. Last time I tried >>the result was that at .connect time it crashed. But if you invest more >>time than me (more than 2 minutes), you can probably get it working ;-) > > It is not so easy, because I need Win32 version of such MySQLdb :( I > try to compile the source using Bloodsheed DevC++ 4.9.8.1 > (http://www.bloodshed.net/) but without result. I added header files > from Python 2.2.3 but it did not help. :( The problem is that you can't use MINGW to compile against the MySQL libraries MySQL AB offers. AFAIC they reference LIBCMT while MINGW can only work with MSVCRT. There used to be MySQL binaries/libraries for Windows that were built with a patched version of the MySQL sources and MINGW. Unfortunately, these are no longer available. That's why I still use MSVC6 to build the MySQLdb binaries on win32 :-( Btw. the method to build MySQLdb is to use distutils. If you use something else, you'd better know about your tools :) If somebody manages to change MySQldb or its build process so that it can link to the embedded version of MySQL (on a more developer-friendly platform), I'll be happy to use this patch and create the corresponding win32 binaries. But I won't put much effort in this myself, because I personally have exactly zero interest in MySQL. My only motivation for offering the binaries is to promote Python as a language for MySQL users. -- Gerhard From chris.gonnerman at newcenturycomputers.net Wed Aug 6 08:53:40 2003 From: chris.gonnerman at newcenturycomputers.net (Chris Gonnerman) Date: Wed, 6 Aug 2003 07:53:40 -0500 Subject: Building extensions with mingw32 -- bdist_wininst fails. Message-ID: <000701c35c19$c2fe7660$2100000a@house> I'll be quick. Here's a transcript: C:\usr\WConio-1.5>python setup.py build --compiler=mingw32 running build running build_py running build_ext building '_WConio' extension writing build\temp.win32-2.3\Release\_WConio.def C:\MINGW32\BIN\dllwrap.exe -mno-cygwin -mdll -static --output-lib build\temp.win 32-2.3\Release\lib_WConio.a --def build\temp.win32-2.3\Release\_WConio.def -s bu ild\temp.win32-2.3\Release\wconiomodule.o -LC:\PYTHON\libs -LC:\PYTHON\PCBui ld - lpython23 -o build\lib.win32-2.3\_WConio.pyd C:\usr\WConio-1.5>python setup.py bdist_wininst running bdist_wininst running build running build_py running build_ext error: Python was built with version 6 of Visual Studio, and extensions need to be built with the same version of the compiler, but it isn't installed. I checked the archives regarding that error message and found a conversation wherein Jeremy Hylton claimed he might have added the code to detect this, and Paul Moore asked to have it removed/disabled at least for mingw32 (which makes binaries 100% compatible with MSVC6). In the case given then, the extension wouldn't build at all; now it builds but I can't make a Windows installer from it. mingw32 should be treated as 100% equivalent to MSVC6 in all cases... please. I've got people clamoring for two of my extensions (and I didn't even think they were popular) but I can't build installers. Is there any way I can get this to work? If I have to I'll hack that check out of Distutils with an axe, but still this should be fixed. Chris Gonnerman -- chris.gonnerman at newcenturycomputers.net http://newcenturycomputers.net From stauffer at swarthmore.edu Fri Aug 15 23:42:21 2003 From: stauffer at swarthmore.edu (Glenn Stauffer) Date: Fri, 15 Aug 2003 21:42:21 -0600 Subject: cx_Oracle & prepared statements Message-ID: <3F3DA81D.5050303@swarthmore.edu> Does anyone have a reference to a quick how-to for using the cx_Oracle prepare and execute methods to pre-parse a sql statement and execute it in a loop to perform efficient inserts into Oracle tables? I've been looking around and haven't come across anything. My assumptions for using this aren't working as expected. Thanks, Glenn Stauffer From jubafre at brturbo.com Tue Aug 5 17:51:42 2003 From: jubafre at brturbo.com (jubafre at brturbo.com) Date: Tue, 5 Aug 2003 18:51:42 -0300 (BRT) Subject: pyc to py?? Message-ID: <1034514.1060120302480.JavaMail.nobody@webmail1.brturbo.com> is it possible to transform the .pyc file in .py file??? if it's possible, how can i get this??? Juliano Freitas From mugginsm at under-the-fridge.com Tue Aug 26 06:28:03 2003 From: mugginsm at under-the-fridge.com (Colin Coghill (SFive)) Date: Tue, 26 Aug 2003 10:28:03 GMT Subject: Replacement for rexec/Bastion? Message-ID: <862bb9d6ecb44848b676dc4a7dd9ffd5@news.teranews.com> Hi, a year or so back some students of mine and I wrote some software which made use of the rexec module to run untrusted user code relatively safely. (We were creating a prototype of a mobile-code style app) I'm now working on another project which will need to be able to do something similar, and I noticed that rexec and Bastion have been withdrawn for (in)security reasons. I've searched fairly hard, and have been unable to find any replacement, but notice that the source still seems to have some form of restricted environment available (involving __builtins__ manipulation), but I can't find any documentation or discussion of this. Is Python (preferably CPython 2.3) still able to "sandbox" bits of code under an application provided API safely? Even Jython or Stackless would be ok, I suppose. I'd like to be able to have (possibly malicious) users of my software able to script behavior using small snippets of python code. Anything from a line to maybe a few pages in length each. I can trap endless loops and the like, but I need something to stop them just importing sys and raising havoc. - Colin From jerf at jerf.org Sun Aug 24 15:53:20 2003 From: jerf at jerf.org (Jeremy Bowers) Date: Sun, 24 Aug 2003 19:53:20 GMT Subject: Modifying the {} and [] tokens References: <04cekv0s6ghjtuhl5j2gph7ltobdb5rsam@4ax.com> <62rekv0k4ucgrh46lkp27klq13pq8ppp5p@4ax.com> <1h3fkvg8mkeq69a8hriojugqfcp75hafjj@4ax.com> Message-ID: On Sun, 24 Aug 2003 01:50:01 +0000, Geoff Howland wrote: > Since > it's not possible, I'll think up some other less hacky slightly more > verbose way to handle the issues. Well, if this is internal code only, you can always simply do from MyDictClassThiny import D a = D('a', 'b', 'c', 'd') or whatever syntax you can cook up in Python that you might desire. The other route you might consider, again for internal code only, is just biting the bullet and writing a quick code pre-processor that converts {} into a call to your class instead. (Getting it to understand {a: 2}, etc, would not be hard.) The odds of the general Python language supporting what you are looking for are slim to none, but you aren't necessarily stuck with *pure* Python if you've got group resources. Personally I'd recommend the pre-processor, because it could be run separately later to produce "pure" Python which could be useful, rather then hacking the C, which will never be generally useful. The pre-processor is pretty easy to write here. You might also consider taking a little time a few weeks into the project and experimenting with just using the pre-processor output directly. You might find the perceived advantages failed to materialize. (Or not.) From pu Sun Aug 17 18:20:18 2003 From: pu (Patrick Useldinger) Date: Mon, 18 Aug 2003 00:20:18 +0200 Subject: client derived from async_chat In-Reply-To: <3F3FF26F.3D6538F4@alcyone.com> References: <3f3fdb48_1@news.vo.lu> <3F3FF26F.3D6538F4@alcyone.com> Message-ID: <3f3fff3c_1@news.vo.lu> Erik Max Francis wrote: > I tried to run your sample but you didn't include enough material for me > to run it as a standalone application. When I tried to stub out the > additional material you didn't include, I got connection refused errors, > presumably because the server wasn't running at the point your clients > tried to connect. Look at the following code: sock=socket.socket(socket.AF_INET,socket.SOCK_STREAM) #sock.setblocking(0) print 'connect rc=',sock.connect_ex((EBHost,EBPort)) try: sock.send(message+BLOCKEND) response=sock.recv(BUFFSIZE) finally: sock.close() If I run it without the 'sock.setblocking(0)', it works fine. If uncomment that line, I receive the following error: File "I:\My Programs\sas\sasLA0.py", line 18, in ? response=sock.recv(BUFFSIZE) socket.error: (10035, 'The socket operation could not complete without blocking') This is exactly what seems to happen with the async_chat class, as in dispatcher.create_socket the same setblocking(0) is done. If you just could shed some light on what this error means, I haven't found any explanation up to now. Thanks. -- Real e-mail address is 'cHVAdm8ubHU=\n'.decode('base64') Visit my Homepage at http://www.homepages.lu/pu/ From mpeuser at web.de Sun Aug 24 07:51:47 2003 From: mpeuser at web.de (Michael Peuser) Date: Sun, 24 Aug 2003 13:51:47 +0200 Subject: BlackAdder V1.0.0 References: <3f48a498$3$219$fa0fcedb@lovejoy.zen.co.uk> Message-ID: Seems it's time to try to get eric running ..... Kindly Michael P From vze4rx4y at verizon.net Sun Aug 24 22:38:32 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Mon, 25 Aug 2003 02:38:32 GMT Subject: list re-orderng headache References: Message-ID: "Gordon Airport" wrote in message news:RQ6dnRssSL3x39SiU-KYvA at comcast.com... > I don't know why, but I am wearing myself out trying to get this > to work with reasonable looking code. I need to take a list of even size > (probably >= 14, but generality never hurts) and produce a code by > looking at the items at odd indexes from the right half and the evens > from the left. To make things worse, the left half needs to either be > read from the center out or reversed later. > > For example from [0, 1, 2, 3, 4, 5, 6, 7. 8, 9, 10, 11, 12, 13, 14, 15] > I would encode [7, 5, 3, 1] and [8, 10, 12, 14] > and [0, 1, 2, 3, 4, 5, 6. 7, 8, 9, 10, 11, 12, 13] > gives [5, 3, 1] and [8, 10, 12] > > My problem has been that with every additional 2 items you swap the odd > and even at the middle of the list, so reading out from the center by > two only works half the time... Maybe I want to use the extended 2.3 > index slicing too much. >>> def f(x): n = len(x) return x[1:n//2:2][::-1], x[-2:-n//2-1:-2][::-1] >>> f(range(16)) ([7, 5, 3, 1], [8, 10, 12, 14]) >>> f(range(14)) ([5, 3, 1], [8, 10, 12]) Raymond Hettinger From skip at pobox.com Tue Aug 12 17:16:48 2003 From: skip at pobox.com (Skip Montanaro) Date: Tue, 12 Aug 2003 16:16:48 -0500 Subject: problems importing "bsddb" In-Reply-To: References: Message-ID: <16185.22848.524146.916237@montanaro.dyndns.org> John> We are using OpenBSD latest release of Python (2.3), and want to John> use the "bsddb" module. Our python release has a directory John> called "bsddb", but when we try and import it, it says >>> import bsddb Traceback (most recent call last): File "", line 1, in ? File "/usr/local/lib/python2.3/bsddb/__init__.py", line 40, in ? import _bsddb ImportError: No module named _bsddb You need to install version 3 or 4 of Berkeley DB. It may be available as part of OpenBSD or as a port, but you can get the source from http://www.sleepycat.com/ and install it from source easily. Once you've done that, rerun python setup.py install in the Python source tree. Skip From Vincent.Raaijmakers at ge.com Tue Aug 5 12:13:15 2003 From: Vincent.Raaijmakers at ge.com (Raaijmakers, Vincent (IndSys, GE Interlogix)) Date: Tue, 5 Aug 2003 11:13:15 -0500 Subject: Needs programming tip using date Message-ID: <55939F05720D954E9602518B77F6127F030967EB@FTWMLVEM01.e2k.ad.ge.com> I think this is a bit of a newbie question in the dates area. So before I end up in very ugly coding, What is THE/recommended way in checking if a date formatted as "08/05/2003", so "month/day/year" is the date of today or a date of the current week? Thanks, Vincent From mark at hahnca.com Thu Aug 28 01:17:04 2003 From: mark at hahnca.com (Mark Hahn) Date: Wed, 27 Aug 2003 22:17:04 -0700 Subject: finding object using IS instead of == References: Message-ID: Now that is just plain evil! "Andrew Bennetts" wrote in message news:mailman.1062046190.2338.python-list at python.org... > On Wed, Aug 27, 2003 at 09:35:46PM -0700, Mark Hahn wrote: > > Clarification: Is there a FASTER way that takes advantage of the IS > > equivalence than using the available == method. I assume the == method does > > a linear search, except for a dict key lookup, which is not what I'm talking > > about. > > > > Obviously if two references are the same object (IS equivalent) then they > > are == also so you could find based on == and then check for IS, but I want > > something faster. > > Actually, (x != y) doesn't necessarily imply that (x is not y): > > >>> class NeverEqual: > ... def __eq__(self, other): > ... return False > ... > >>> ne = NeverEqual() > >>> ne == ne > False > >>> ne is ne > True > > I'm not sure how much this matters to you, though :) > > -Andrew. > > From tzot at sil-tec.gr Fri Aug 22 06:58:00 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Fri, 22 Aug 2003 13:58:00 +0300 Subject: max length of a python program References: <1ed07caf.0308210513.6556978a@posting.google.com> Message-ID: <1itbkv4m8ro99a709jtndtu9hn9vesk66e@4ax.com> On Thu, 21 Aug 2003 15:22:30 +0200, rumours say that Gerhard H?ring might have written: >Ragu wrote: >> Is there a limit to the # of lines that can be in a Python program? > >The free version from python.org is limited to 500 lines per module. >I'll gladly sell you Python Enterprise 2003, which has no lines of code >limits at all and where code size is only limited by available memory. > >The current price is EUR 250 per seat or EUR 5000 for a site-license. >One year of free support via Usenet (comp.lang.python) is included. Really? A few years ago, when I bought Python for the first time, the entry price I paid was my right hand and rights on my firstborn. Things have changed... Microsoft Python: bringing innovation to higher levels at a friendly price. -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From duke99 at email.ro Sat Aug 30 13:10:16 2003 From: duke99 at email.ro (soso) Date: 30 Aug 2003 10:10:16 -0700 Subject: PyList_New Message-ID: Hi everybody, Does PyList_New() increments the reference count? I believe yes but I want to be sure because I saw some code from a module that has a function that increments it before returning the list. Thanks in advance, soso From margerum at yahoo.com Tue Aug 19 12:17:09 2003 From: margerum at yahoo.com (Mike Margerum) Date: 19 Aug 2003 09:17:09 -0700 Subject: Python should try to displace Java References: Message-ID: C++ is dead? Better not tell that to the embedded/PDA/Phone world. Seems to be working really well there and thats where the growth is. Why do you think Sun is putting so much effort into J2ME? From dreico at wanadoo.fr Fri Aug 29 12:14:28 2003 From: dreico at wanadoo.fr (Andrei) Date: Fri, 29 Aug 2003 18:14:28 +0200 Subject: cannot get pexpect to work References: <3F4F6AF0.CA9BB337@engcorp.com> Message-ID: the following is completely wrong of course in my own hacked version of the script linked in the previous msg: # SHELL_PROMPT = '[#\$] ' SHELL_PROMPT = '[$?] ${PWD#${PWD%/*/*/*}/}> ' but even when the login shell prompt on remote machine must end in # or $ as the script insists, and you leave SHELL_PROMPT = '[#\$] ' the "timed out" message persists, hence my puzzlement ... A. From theller at python.net Fri Aug 8 15:52:45 2003 From: theller at python.net (Thomas Heller) Date: Fri, 08 Aug 2003 21:52:45 +0200 Subject: crossplatform py2exe - would it be useful? References: <2UyYa.50516$cl3.1586459@news2.tin.it> Message-ID: bokr at oz.net (Bengt Richter) writes: > PMJI, since I haven't read all the prior thread, but if the point is > just to have an executable that self-unpacks and starts, IWT the safest > (for platform independence -- not security, see my conclusion later below) > approach would be to have a tool that makes a light-weight self-unpacking > "exe" wrapper for any/each platform. No, that's not the goal (at least not for me). I don't want to unpack something at runtime, I want exactly that what py2exe currently does: One executable, plus maybe a handful of files (.dll/.pyd/.so). > I think it would be relatively trivial on win32. I think you could do it all > in Python once you have a little C boilerplate exe template compiled and a > few special locations and segments defined (i.e., .exe's have provision > for simple embedded resource entities. Well, for PE files on win32, the special locations can easily be stored as resources, but IIUC that's not possible under Linux, for example. But appending random stuff at the end of a valid executable is possible there. > For that purpose, I've been thinking a unicode utf-8 representation of > an rfc2822 header might be cool. Ok, once you can execute Python code, you can do very fancy stuff. But the problem is to 'boot' the Python interpreter into existance, the first setp of this must be done from C code, and so it must be as simple as possible. Thomas From jbar at lf1.cuni.cz Thu Aug 21 07:03:01 2003 From: jbar at lf1.cuni.cz (Jiri Barton) Date: Thu, 21 Aug 2003 13:03:01 +0200 Subject: MySqlDB Question - CompatMySqlDB is all I can find ? References: <282f826a.0308210238.11ef6a97@posting.google.com> Message-ID: <3f44a6e7@shknews01> See, I don't know if that's causing it (it is on Linux, actually) but you may want to use import MySQLdb next time (mind the case sensitivity) just to stay platform independent. HTH, Jiri From aleax at aleax.it Mon Aug 4 04:25:32 2003 From: aleax at aleax.it (Alex Martelli) Date: Mon, 04 Aug 2003 08:25:32 GMT Subject: Python speed vs csharp References: <1h5f2rzthqgid.8watonaa4cjt.dlg@40tude.net> <3F551D29.1040407@kfunigraz.ac.at> Message-ID: <0MoXa.21930$cl3.850221@news2.tin.it> Siegfried Gonzi wrote: ... > I am sure you know what you are after, but Python for numerical > computations is more or less crap. Not only has Python a crippled ...Note for the unwary...: It's interesting that "gonzi", in Italian, means "gullible" (masculine plural adjective, also masculine plural noun "gullible individuals") -- this may or may not give a hint to the purpose of this troll/flamewar:-). Anyway, a challenge is a challenge, so: > times. Also included a C program. The timings on a simple Celeron > laptop are as follows: > > g++ -O3 erf.c : 0.5 seconds > bigloo -Obench erf.scm: 1.1 seconds Never having been as silly as to purchase such a deliberately crippled chip as a Celeron, I cannot, unfortunately, reproduce these timings -- I will, however, offer my own timings on a somewhat decent CPU, an old but reasonably well-configured early Athlon. No bigloo here, so I started with the C program: > ;;; C ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; > #include > #include > > > double erfc( double x ) > { > double p, a1, a2, a3, a4, a5; > double t, erfcx; > > p = 0.3275911; > a1 = 0.254829592; > a2 = -0.284496736; > a3 = 1.421413741; > a4 = -1.453152027; > a5 = 1.061405429; > > t = 1.0 / (1.0 + p*x); > erfcx = ( (a1 + (a2 + (a3 + > (a4 + a5*t)*t)*t)*t)*t ) * exp(-pow(x,2.0)); > > return erfcx; > } > > int main() > { > double erg=0.0; > int i; > > for(i=0; i<1000000; i++) > { > erg += erfc(0.456); > } > printf("%f",erg); > > return 1; > } > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; saved this to gonzi.c, compiled it and ran/timed it: [alex at lancelot swig_wrappers]$ gcc -O -o gonzi gonzi.c -lm [alex at lancelot swig_wrappers]$ time ./gonzi 519003.933831Command exited with non-zero status 1 0.37user 0.01system 0:00.39elapsed 96%CPU (0avgtext+0avgdata 0maxresident)k 0inputs+0outputs (107major+13minor)pagefaults 0swaps (that silly "return 1" must be connected to some in-joke or other... why's the program unconditionally returning an error-indication!?-)] Then I "converted" it to Python, a trivial exercise to be sure: import math def erfc(x): exp = math.exp p = 0.3275911 a1 = 0.254829592 a2 = -0.284496736 a3 = 1.421413741 a4 = -1.453152027 a5 = 1.061405429 t = 1.0 / (1.0 + p*x) erfcx = ( (a1 + (a2 + (a3 + (a4 + a5*t)*t)*t)*t)*t ) * exp(-x*x) return erfcx def main(): erg = 0.0 for i in xrange(1000000): erg += erfc(0.456) print "%f" % erg if __name__ == '__main__': main() and ran that: [alex at lancelot swig_wrappers]$ time python gonzi.py 519003.933831 5.32user 0.05system 0:05.44elapsed 98%CPU (0avgtext+0avgdata 0maxresident)k 0inputs+0outputs (473major+270minor)pagefaults 0swaps then I put a huge effort into optimization -- specifically, I inserted after the "import math" the two full lines: import psyco psyco.full() [must have taken me AT LEAST 3 seconds of work, maybe as much as 4] and ran it again: [alex at lancelot swig_wrappers]$ time python gonzi.py 519003.933831 0.15user 0.02system 0:00.24elapsed 69%CPU (0avgtext+0avgdata 0maxresident)k 0inputs+0outputs (547major+319minor)pagefaults 0swaps There -- optimized Python over twice as fast as optimized C in terms of user-mode CPU consumption, almost twice as fast in terms of elapsed time (of course, using programs as tiny and fast as this one for such purposes is not clever, since they run so fast their speed is hard to measure, but "oh well"). No need to declare types, of course, since psyco can easily infer them. Of course, there IS a "subtle" trick here -- I write x*x rather than pow(x,2.0). Anybody whose instincts fail to rebel against "pow(x,2.0)" (or x**2, for that matter) doesn't _deserve_ to do numeric computation... it's the first trick in the book, routinely taught to every freshman programmer before they're entrusted to punch in the first card of their first Fortran program (or at least, so it was in my time in university, both as a student and as a professor). Correcting this idiocy in the C code (and removing the return 1 since we're at it -- return 0 is the only sensible choice, of course:-) we turn C's performance from the previous: [alex at lancelot swig_wrappers]$ time ./gonzi 519003.933831Command exited with non-zero status 1 0.37user 0.01system 0:00.39elapsed 96%CPU (0avgtext+0avgdata 0maxresident)k 0inputs+0outputs (107major+13minor)pagefaults 0swaps to a more respectable: [alex at lancelot swig_wrappers]$ time ./gonzi 519003.9338310.20user 0.00system 0:00.19elapsed 103%CPU (0avgtext+0avgdata 0maxresident)k 0inputs+0outputs (105major+13minor)pagefaults 0swaps (the "103%" of CPU being a funny artefact of my Linux kernel, no doubt). So, about HALF the elapsed time was being squandered in that absurd call to pow -- so much for Mr Gonzi's abilities as a numerical programmer:-). With the program having been made decent, C's faster than optimized Python again, not in CPU time (0.20 all usermode for C, 0.15 usermode + 0.02 systemmode for Python) but in elapsed time (0.19 for C vs 0.24 for Python) -- the inversion being accounted for in psyco's lavish use of memory and resulting pagination. Still, the performance ratio of psyco-optimized Python vs C on my machine is much better than that of bigloo vs C on Mr Gonzi's Celeron, and with no need for type declarations either. So much, then, for Mr Gonzi's claims about Python being "more or less crap"!-) Alex From sheila at spamcop.net Thu Aug 21 14:19:56 2003 From: sheila at spamcop.net (Sheila King) Date: Thu, 21 Aug 2003 18:19:56 GMT Subject: Got Python web host, yay! Now what? References: Message-ID: On Thu, 21 Aug 2003 16:47:07 GMT, "Robert Oschler" wrote in comp.lang.python in article : > I found a good web host that has Python 2.x support and I've set up an > account. It's LunarPages.com if you're interested . Do I have to do > anything special to run Python scripts, besides upload the script to the > cgi-bin directory? If so, please direct me to a good web page or doc that > goes into the necessary details. > > thx This will depend on the set up that your web host provides. On the server where I host, I simply upload my scripts to cgi-bin and they run. However, I recently helped someone set up a script on a different server, and after a couple of hours of tearing our hair out, we found out that on that server, all scripts had to be renamed to have a .cgi extension, or they would not run. (I've usually run my scripts with a .py extension.) So, you should check with your host to find out what requirements they may have for running cgi scripts. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From aleax at aleax.it Tue Aug 5 14:27:31 2003 From: aleax at aleax.it (Alex Martelli) Date: Tue, 05 Aug 2003 18:27:31 GMT Subject: Question about import References: Message-ID: Mark Daley wrote: > The difference is how you access the methods in the module. If you use: > > import Module > > you will only be able to use the Module.Method usage. If you use: > > from Module import * > > you can access the Methods directly. > > > The drawback to using from Module import * comes from conflicts if you > import multiple Modules, which may have identically named Methods, where > you will only be able to get the Method from the most recently imported > Module. Better to import the Module, IMO. > > Any thoughts, all? There are also other drawbacks to using the 'from' statement rather than the 'import' statement. For example, if you ever reload() the module, this will have no effect in other modules that used 'from', while it will cause usage of the updated (reloaded) module in other modules that used 'import'. Personally, I think a beginner would be best served by totally forgetting the existence of 'from' and using only 'import' instead -- perhaps 'import ... as' if the need to abbreviate the name used to refer to the module is strongly felt. Alex From max at alcyone.com Fri Aug 29 01:07:06 2003 From: max at alcyone.com (Erik Max Francis) Date: Thu, 28 Aug 2003 22:07:06 -0700 Subject: Add two dicts References: <86ktkvkd05e88hu14hjudmfvbul7slfgkt@4ax.com> Message-ID: <3F4EDF7A.C9CF6DA3@alcyone.com> Afanasiy wrote: > Can I add two dicts in a way which is not cumbersome to the above % > string > operation? Is this another case of writing my own function, or does a > builtin (or similar) already exist for this? combinedDict = aDict.copy() combinedDict.update(anotherDict) If that's cumbersome, don't really know what you'd consider non-cumbersome. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ The revolution will not televised \__/ Public Enemy From bac at OCF.Berkeley.EDU Mon Aug 18 17:49:25 2003 From: bac at OCF.Berkeley.EDU (Brett C.) Date: Mon, 18 Aug 2003 14:49:25 -0700 Subject: python-dev Summary for 2003-08-01 through 2003-08-15 Message-ID: <3F4149E5.7020704@ocf.berkeley.edu> python-dev Summary for 2003-08-01 through 2003-08-15 ++++++++++++++++++++++++++++++++++++++++++++++++++++ This is a summary of traffic on the `python-dev mailing list`_ from August 1, 2003 through August 15, 2003. It is intended to inform the wider Python community of on-going developments on the list. To comment on anything mentioned here, just post to python-list at python.org or `comp.lang.python`_ with a subject line mentioning what you are discussing. All python-dev members are interested in seeing ideas discussed by the community, so don't hesitate to take a stance on something. And if all of this really interests you then get involved and join `python-dev`_! This is the twenty-third summary written by Brett Cannon (about to move for the umpteenth time). All summaries are archived at http://www.python.org/dev/summary/ . Please note that this summary is written using reStructuredText_ which can be found at http://docutils.sf.net/rst.html . Any unfamiliar punctuation is probably markup for reST_ (otherwise it is probably regular expression syntax or a typo =); you can safely ignore it, although I suggest learning reST; its simple and is accepted for `PEP markup`_ and gives some perks for the HTML output. Also, because of the wonders of programs that like to reformat text, I cannot guarantee you will be able to run the text version of this summary through Docutils_ as-is unless it is from the original text file. .. _PEP Markup: http://www.python.org/peps/pep-0012.html The in-development version of the documentation for Python can be found at http://www.python.org/dev/doc/devel/ and should be used when looking up any documentation on something mentioned here. Python PEPs (Python Enhancement Proposals) are located at http://www.python.org/peps/ . To view files in the Python CVS online, go to http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/python/ . .. _python-dev: http://www.python.org/dev/ .. _python-dev mailing list: http://mail.python.org/mailman/listinfo/python-dev .. _comp.lang.python: http://groups.google.com/groups?q=comp.lang.python .. _Docutils: http://docutils.sf.net/ .. _reST: .. _reStructuredText: http://docutils.sf.net/rst.html .. contents:: .. _last summary: http://www.python.org/dev/summary/2003-07-01_2003-07-31.html ===================== Summary Announcements ===================== Well, Michael Chermside responded to my question from the last summary about whether the new format and style of the Summaries was good. Once again a single person has led to how the summaries will be handled. You guys need to speak up (although I like the side that won this time =)! I am playing with layout once again. This time I am changing how the "contributing threads" lists are formatted. I know some of you hate inlined links in reST markup, but when these lists become huge it becomes really hard to keep track of the URIs when I have to list them away from the actual item on a separate line below the list of thread names. With `Python 2.3` out the door bug reports have started to come in. Work on 2.3.1 has begun. Please keep running the regression tests (easiest way is to run either ``make test`` or run regrtest.py in the test package; see the docs for the test package for help). On a personal note, if anyone knows of any Python users and such in the San Luis Obispo area of California, drop me a line at brett at python.org. ========= Summaries ========= ----------------------------------------- Python user helping Parrot? Treacherous! ----------------------------------------- Michal Wallace decided to get AM Kuchling's `previous work `__ on getting Python code to run on the Parrot_ virtual machine (which is what Perl 6 will use). Well, the rather nutty fellow managed to get pretty damn far with it as shown at http://pirate.versionhost.com/viewcvs.cgi/pirate/ . Michal was actually almost done with handling pure Python code and was getting ready to try to figure out how to get Parrot to handle C extension modules with that being the biggest sticking point. Since Parrot is not Python it does not have a parser for Python code; problem if your code has an exec statement. This turned out to not be a worry, though, since there are pure Python parsers out there. All of this has direct relevance to python-dev because of the bet between Guido and Dan Sugalski, developer of Parrot. The rules are outlined at http://www.sidhe.org/~dan/blog/archives/2003_07.html#000219 . What is going to happen at OSCON 2004 is a benchmark program written in pure Python will be run using a CVS checkout of Python against a Parrot (after converting the bytecode to Parrot's own bytecode) checkout; slowest implementation's author gets a pie in the face, buy the winner's dev team a round of beer, and $10. So why have this bet? This was discussed and basically came down to finding out whether Parrot really can run Python fast. Parrot wants to be the VM for as many languages as possible, including Python. This acts as a way to motivate people to see how feasible this is. And don't think that the CPython interpreter will disappear if Parrot wins. Dan pointed out that even if he did win the bet that Guido would probably want to keep CPython around since that is under his control and allows testing out new language features much easier then having to deal with Parrot and an external dev team. In other words, let other people worry about forcing a Python-shaped peg into a Parrot-sized hole. .. _Parrot: http://www.parrotcode.org/ Contributing threads: * `pirate (python+parrot) `__ ---------------------------------------------------- python-mode gets its own SF project; Vim users laugh ---------------------------------------------------- Barry Warsaw, citing lack of time to "properly maintain python-mode.el", has created a SourceForge project for the Emacs mode at http://sf.net/projects/python-mode . This means all bug reports, patches, etc. should be done at that project. Martin v. L?wis suggested removing `python-mode.el`_ from Python itself and to get it distributed with Emacs_ and XEmacs_. This way there does not have to be any synchronization between the new SF project and the Python CVS tree. As of right now, though, python-mode.el is still in the Python CVS. And to give equal billing to Vim_, my code editor of choice, since it does not get as much coverage on python-dev as XEmacs does, here are some scripts you might want to check out: taglist.vim : http://vim.sourceforge.net/scripts/script.php?script_id=273 "provides an overview of the structure of source code files" by splitting the window. python_fold.vim : http://vim.sourceforge.net/scripts/script.php?script_id=515 "This script uses the expr fold-method to create folds for python source code." vimDebug : http://vim.sourceforge.net/scripts/script.php?script_id=663 " integrates your favorite debugger with vim." .. _python-mode.el: http://sf.net/projects/python-mode .. _Emacs: http://www.gnu.org/software/emacs/emacs.html .. _XEmacs: http://www.xemacs.org/ .. _Vim: http://www.vim.org/ Contributing threads: * `New python-mode project at SourceForge `__ * New place for python-mode bug reports and patches `__ -------------------- Caching tuple hashes -------------------- Raymond Hettinger asked if there was any reason why tuples, being immutable, didn't cache their hash values. Strings cache their hashes and they are immutable, so it seem to make sense. It was pointed out, though, that tuples could contain an object that changed its hash value between hash calls. Guido said, though, that it was the responsibility of the object and not tuples to worry about keeping a consistent hash value. Guido also explained why strings cache their hashes. It turns out that since strings are used so often for keys in dicts that caching their hashes gave a large performance boost for almost any program, so the effort was felt justified. But Guido did not see this same justification for tuples. Thus tuples will not cache their hash values. Contributing threads: * `Caching tuple hashes `__ ------------------------------- PyCon 2004 is under development ------------------------------- Preparation for PyCon_ 2004 have now begun. With us getting the ball rolling much earlier this conference should turn out to be even better than last year (which, in my opinion, was great)! You can go to http://www.python.org/pycon/dc2004/ to find links to lists to get involved in organizing or just to be kept abreast of new developments. .. _PyCon: http://www.python.org/pycon/dc2004/ Contributing threads: * `PyCon DC 2004 Kickoff! `__ ---------------------------- Let the fixing of 2.3 begin! ---------------------------- The maintenance branch of Python 2.3 (named release23-maint) has been created in CVS. Several bugs have already been fixed. For instructions on how to check out a copy of the branch, read http://www.python.org/dev/devfaq.html#c10 . Contributing threads: * `Python 2.3 maintenance branch is now open `__ ------------------------------------ When a void doesn't equal an integer ------------------------------------ After clearing up the confusing issue of the difference between a Python int and a Python Integer (the former is while the latter is the union of and which is what Python is moving towards so that the distinction practically disappears), the discussion of how to handle a quirk of Win64 commenced. It turns out that Win64 thinks that ``sizeof(void *) > sizeof(long)`` is a reasonable thing to do. Well, all other platforms now and most likely for the rest of Tim Peter's life (at least according to Tim's guess) don't and won't hold this to be true. As of right now Python claims that a void pointer can be held in a Python int, but Win64 breaks that claim. Do we muck around with Python's internals for this one strange exception that does not make sense, such as making Python ints use long long? No, of course not. Code would break, let alone the added complexity. So the needed changes to the failing tests were dealt with and all seems to be fine with the world again ... well, Win64 is still thinking on crack, but that is someone else's problem. Contributing threads: * `sizeof(long) != sizeof(void*) `__ ------------------------------------ Where do I put all of my packages?!? ------------------------------------ As it stands now there are four places where packages can reside: 1. standard library 2. site-packages 3. site-python (on UNIX this is the same directory where your python2.3 directory exists) 4. PYTHONPATH environment variable It was pointed out that this does not necessarily give one all the options one might want. The above covers the Python core easily, but there is not clear distinction for vendor packages, network-installed packages, system-wide packages or user-installed packages; they are covered by 2-4 above. The suggestion was to make more distinct places available for installation and to make distutils aware of them. A good way to see how this would be useful is to look at how OS X's Panther will handle Python 2.3 . It will have the standard library in the standard location of /usr/local/python2.4 . In that directory, the site-packages directory is a symlink to a more system-aware location. This is fine but what about a sysadmin who would rather avoid the possibility of breaking OS X by messing with the OS's Python installation? What about a user on that system who does not have root but wants to have their own place to put their packages? There is definitely room for adding more standard path locations for package installations. A PEP was being mentioned but appears to not have been written yet. Contributing threads: * `Multiple levels of site-packages `__ ------------------------- Be careful with __slots__ ------------------------- Raymond Hettinger observed that using __slots__ or overriding __getattribute__ fails silently when mistakenly used with old-style classes. This has bitten him and others in the bum so he wanted to add warning/error messages. Guido recommended passing on the warnings because 1) those are "expert use only" tools, 2) PyChecker can already detect the issue, and 3) there are other new-style/classic issues cannot as readily be flagged. It should be known that "__slots__ is a terrible hack with nasty, hard-to-fathom side effects that should only be used by programmers at grandmaster and wizard levels". So only use __slots__ if you can apply the label of "programmer at grandmaster or wizard level" to yourself without your programming peers laughting their bums off; you have been warned. Contributing threads: * `Make it an error to use __slots__ with classic classes `__ -------------- Plugging leaks -------------- Michael Hudson thought he had discovered a leak somewhere and went off on a little hunt. It turned out to be a red herring more or less, but there was some discussion on the best way to find leaks through regression tests. The basic scheme that everyone seemed to use was to run the regression test once to get any caching out of the way and then run the test a set number of times and see if the reference counts seemed to grow. Michael Hudson posted a diff to add such a testing feature to test/regrtest.py at http://mail.python.org/pipermail/python-dev/2003-August/037617.html . Tim Peters also posted a link to Zope's test driver at http://cvs.zope.org/Zope3/test.py which includes a class named TrackRefs which can help keep track of the leaked references as well as leaked objects. Contributing threads: * `CALL_ATTR patch `__ * `refleak hunting fun! `__ ----------------------------------------- Making the interpreter its own executable ----------------------------------------- As it stands now the Python interpreter is distributed as a bunch of files mostly made up of the standard library. But wouldn't it be nice if you could make the interpreter just a single executable that was easy to distribute with your code? Well, that discussion cropped up on `comp.lang.python`_ at http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&safe=off&threadm=ptji8wgr.fsf%40python.net . The idea was to somehow introduce a hook into Py_Main() that could harness the new zipimport facility. The idea came up of appending the stdlib to the end of the Python interpreter and to have a flag set to signal that the appending had occurred. The problem is that this could cause unzipping problems. But setting the flag is not necessarily simple either. One suggestion was to literally patch the interpreter to set the flag. But there was some confusion over the use of the term "patch"; Thomas Heller thought more of "link with an object file defining this global variable". This thread was still going as of this writing and had not yet reached a clear solution. Contributing threads: * `hook for standalone executable `__ From dtolton at yahoo.com Wed Aug 20 12:25:12 2003 From: dtolton at yahoo.com (Doug Tolton) Date: Wed, 20 Aug 2003 16:25:12 GMT Subject: Python should try to displace Java References: <3f3e89f3$0$225$626a54ce@news.free.fr> Message-ID: On Sat, 16 Aug 2003 21:55:02 +0200, Bruno Desthuilliers wrote: >Doug Tolton wrote: >(snip) >> Java and Python are really >> entirely different things. Python is meant as a scripting language, >> Java is a Systems programming language. > >Err... Is this another troll ? Or is it me being just dumb ? > >I'd like to see some 'System programming' (I think we don't give 'system >programming' the same meaning) in Java, that can't be done in Python. > No that is not a troll. I think Java is better at building some large systems than Python is. That's what it was designed for, python was designed to be a scalable scripting language. Python wasn't designed to be a replacement for C++ to my knowledge. Are you saying that python was designed to be a replacement for C / C++ for building large scale systems? If so I'm suffering under a mis-apprehension of what Python is all about. I'm using System in the generic sense rather than the specific sense of Operating System. It isn't a matter of whether it can be done in Python. You can write anything in assembly for that matter, the reason you don't is typically productivity. That doesn't mean you shouldn't write anything in Assembly does it? I don't know how stating the obvious 'that some languages are better at some tasks than other languages' would be considered a troll. Doug Tolton (format t "~a@~a~a.~a" "dtolton" "ya" "hoo" "com") From staschuk at telusplanet.net Tue Aug 5 03:31:03 2003 From: staschuk at telusplanet.net (Steven Taschuk) Date: Tue, 5 Aug 2003 01:31:03 -0600 Subject: Python and cron jobs. In-Reply-To: <7b454334.0308041023.6e688b4d@posting.google.com>; from faizan@jaredweb.com on Mon, Aug 04, 2003 at 11:23:50AM -0700 References: <7b454334.0308041023.6e688b4d@posting.google.com> Message-ID: <20030805013103.A476@tibia.amotlpaa.bogus> Quoth Fazer: > I am wondering that if it is possible to add cron jobs via a web or > shell interface? I can make Python act as a shell script and be > called by a PHP script. But my main goal here is to be able to manage > cronjobs. Add or remove certain crjob jobs etc... > > Can any kind soul shed some light on how I would accomplish this? The question is a bit vague, I'm afraid. If you just want to know how to invoke crontab(1) from a Python script, look up os.popen() and friends in the standard library documentation. As for getting the cron daemon to reload the changed crontab, that's a nop in the crons I've seen; they check for changes every minute anyway. If you want to know something else, please specify. -- Steven Taschuk staschuk at telusplanet.net "What I find most baffling about that song is that it was not a hit." -- Tony Dylan Davis (CKUA) From skip at pobox.com Fri Aug 22 10:42:31 2003 From: skip at pobox.com (Skip Montanaro) Date: Fri, 22 Aug 2003 09:42:31 -0500 Subject: Python preinstalled on Windows - looking for details Message-ID: <16198.11223.819718.364893@montanaro.dyndns.org> Folks, It appears that HP and perhaps some other computer manufacturers who deliver Windows systems have begun delivering systems with Python pre-installed. We've begun to get frequent questions about this at the webmaster at python.org email address. I contacted HP about this, but have so far received no firm details about why Python is installed or what applications on their boxes use it. It's not clear how to respond to people who ask, "What's this Python thing? Can I delete it?", other than to say, "No, you probably shouldn't delete it.". If you have any details about who in the Windows world preinstalls Python and what they use it for, please let me know. I'd like to add a question to the Python FAQ, but would like some details. Thanks, Skip From mack at incise.org Sun Aug 31 15:07:46 2003 From: mack at incise.org (mackstann) Date: Sun, 31 Aug 2003 14:07:46 -0500 Subject: list.sort(func) speed In-Reply-To: References: Message-ID: <20030831190745.GH9311@incise.org> On Sun, Aug 31, 2003 at 02:20:46PM +0200, Peter Otten wrote: > However, your songs seem to correspond to files, so why not store them in > your list as (filename, directory) or (filename, fullpath) tuples in the > first place? That's a pretty good idea, I think I'll do that. songs => [("foo.mp3", "/path/to"), ...] Then the biggest speed hit (splitting the paths and adding the files) will only happen when adding files, and say, if I add 5 files to the list, I won't have to suffer the speed hit for ALL of the files, only those 5, which would be negligable. > Personally, I would go with a Song class, where the artist, length etc. > could successively be added, but that would rather be trading speed for > features... Yeah, I have thought about it, and it would definitely be the more OOPey way to go, but I figured that anyone using this with 20,000 files would get a little grumpy at the speed hit. :) -- m a c k s t a n n mack @ incise.org http://incise.org It was one of those perfect summer days -- the sun was shining, a breeze was blowing, the birds were singing, and the lawn mower was broken ... -- James Dent From bitbucket at safe-mail.net Thu Aug 28 19:34:29 2003 From: bitbucket at safe-mail.net (poiboy) Date: 28 Aug 2003 16:34:29 -0700 Subject: Celebrity advice (was: Advice to a Junior in High School?) References: Message-ID: Alex Martelli wrote: >> In this day and age it's hard to make a case for deliberately >> inefficient arrangements, although it IS possible to do so (e.g., >> the mandatory trailing ':' in the head clauses of several Python >> statements;-). People who don't want ID cards to exist, don't want >> government DB's to be cross-linked, etc, plead much the same case >> -- they prefer inefficient government (whose inefficiencies may >> help terrorists and other criminals) to efficient government (whose >> efficiency might allow more effective oppression). Dear Alex, Thank you for your segway. I was looking for an excuse.. I disagree that vestigial colons are in any way sympathetic to terrorists. Their requirement is a common law which arose from the practice of writing some doohickey after certain conjunctive clauses. Their 'inefficiency' is analagous to the inefficiency of joining nouns and adjectives with an indicative ('is'.join(['car', 'fast'])). A violation of common *law*, failure to include vestigial colons results in swift, unavoidable, and equally applied punishment from the governing authority (specifically, the interpretive branch). Compare this with violations of common *practice* (here, leaving out an 'is') which normally just throw user-level warnings. In contrast, __slots__ do appear to favor a criminal element by making it appallingly easy to frustrate common practice (however, I'll be the first to admit that it is my own fear and inadequacy which motivates my branding __slots__ use as criminal). 'Inefficiency' should not be confused with 'scope'. 'Scope' implies a social contract or order, the enforcement of which is frustrated by and disruption of which is inflamed by 'inefficiency'. As it turns out, not merely inefficiencies but also blatant errors in logic are found more often in the mechanics of things which try to order larger scopes (however it is interesting to note that even blatant errors in logic can be swallowed with a heavy enough dose of MS/NBC). I believe that people who value freedom prefer limited governed scopes, not inefficiencies. In particular, inefficiencies of vanilla Python (perchance indirectly, tacitly accomodating terrorism of the C#/.NET ilk) are *neither required nor preferred* by the righteous and are suffered only because of allegiances to much higher authorities (in the case of vestigial colons we pledge aesthetic allegiance). And in defense of those who may be mistakenly charged as terrorists by a modern, sophisticated community like comp.lang.python: Those who won't "go along to get along" by giving up their semi-colons and braces and subjecting themselves to communal indentation exemplify the rugged individualism that built the foundation upon which *our ability to choose* communal indentation rests. And it is the freedom to opt into or out of indented or braced communities which encourages the improvement of both. Peace-love-hope, ze Poiboy :) From theller at python.net Thu Aug 7 03:19:18 2003 From: theller at python.net (Thomas Heller) Date: Thu, 07 Aug 2003 09:19:18 +0200 Subject: dl + getenv (without arguments) = segfault (python2.p2, python2.3) References: <39929.24.199.120.198.1060217799.squirrel@mail.darkscape.net> <_zjYa.15215$W%3.10507@nwrdny01.gnilink.net> Message-ID: <3cge7x55.fsf@python.net> Carl Banks writes: > Skip Montanaro wrote: >> >> Xavier> Do note that my previous e-mail was not implying my possible >> Xavier> ignorance to the 'dl' module's functionality, but instead >> Xavier> inquiring wether there is or may be a solution in the future for >> Xavier> Python to handle such an erronous outcome. And plus, segfaults >> Xavier> are ugly and make me cry. >> >> I understand. Given the nature of the problem here, I suspect the segfault >> occurred in getenv() (I can't check to be sure, as I don't have the dl >> module). It's kind of hard for Python to gracefully recover when it doesn't >> control the program counter. > > Theoretically, it could trap SIGSEGV and have the handler return > control to Python. (You'd probably have to wrap the dl call with > setjmp, and use longjmp in the handler.) I wouldn't count on the > Python process being in great shape afterwards, though. ctypes (but only when run under windows) handles this with win32 structured exception handling (c_char_p is the ctypes way to specify 'char *'): c:\test>python Python 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from ctypes import * >>> cdll.msvcrt.getenv.restype = c_char_p >>> cdll.msvcrt.getenv("windir") 'C:\\WINDOWS' >>> cdll.msvcrt.getenv(32) Traceback (most recent call last): File "", line 1, in ? WindowsError: exception: access violation >>> ctypes is cross platform, but it doesn't trap SIGSEGV as Carl suggested. I wonder if someone comes up with a patch . Having said that, it is possible to specify the arguments that getenv accepts, and so at least make it somewhat harder to crash it: >>> cdll.msvcrt.getenv.argtypes = [c_char_p] >>> cdll.msvcrt.getenv(32) Traceback (most recent call last): File "", line 1, in ? TypeError: while constructing argument 1: string expected instead of int instance >>> cdll.msvcrt.getenv("PATH") 'C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;.....' >>> ctypes lives at Thomas From bkelley at wi.mit.edu Wed Aug 6 14:22:40 2003 From: bkelley at wi.mit.edu (Brian Kelley) Date: Wed, 06 Aug 2003 14:22:40 -0400 Subject: Stupid string.split question Message-ID: <3f314721$0$3936$b45e6eb0@senator-bedfellow.mit.edu> Is there any conceptual reason why "ABCDEF".split("") shouldn't equal ["A", "B", "C", "D", "E", "F"]? The error says empty seperator, but the result makes sense given that fact and the fact that: "".join(["A", "B", "C", "D", "E", "F"]) == "ABCDEF" It seems that if you can join with an empty seperator, you should be able to split with one. I suppose the pythonic way is [x for x in "ABCDEF"] which doesn't make as much sense to be. This question is also equivalent to "ABCDEF".reverse() since that is what I am using these for. Currently the code is l = [x for x in forward_string] l.reverse() reversed_string = "".join(l) Just asking. Brian From sjmachin at lexicon.net Sat Aug 9 01:16:30 2003 From: sjmachin at lexicon.net (John Machin) Date: 8 Aug 2003 22:16:30 -0700 Subject: regular expression back references References: Message-ID: sjmachin at lexicon.net (John Machin) wrote in message news:... > ruach at chpc.utah.edu (Matthew) wrote in message news:... > > macExpression = "^[0-9A-F]{1,2}(\:|\.|\-)[0-9A-F]{1,2}\1[0-9A-F]{1,2}\1[0-9A-F]{1,2}\1[0-9A-F]{1,2}\1[0-9A-F]{1,2}$: > Four problems (1) Your pattern has 5 occurrences of [0-9-A-F] but your > data has 6 Make that 3 problems. I can't count -- that's why i use computers! From paul at fxtech.com Fri Aug 15 09:44:08 2003 From: paul at fxtech.com (Paul Miller) Date: Fri, 15 Aug 2003 08:44:08 -0500 Subject: "drop-in" DOM replacement for minidom? References: Message-ID: >>Has someone done a more efficient minidom replacement module that we can >>just drop in? Preferrably written in C? >> >I'm curious how DOM dependent you really are. I.e., what minidom methods do you really use? >Can you assume that you are dealing with valid (error-free) XML as input? Yes, it is assumed to be valid. We don't even use a DTD. But we use the DOM to point to later nodes in the tree by following references in nodes higher in the tree. But, building a sparse object model initially and resolving references later might be the right solution. From adalke at mindspring.com Fri Aug 8 22:40:27 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Fri, 8 Aug 2003 20:40:27 -0600 Subject: regular expression back references References: <25373bfe.0308081756.77ac86a8@posting.google.com> Message-ID: Clay Shirky > # use regexes to see what to split on > if re.search(":", new_address): or use if ":" in new_address: > elif re.search("-", new_address): > new_list = new_address.split("-") > elif re.search(".", new_address): > new_list = new_address.split(".") and include a else: raise Exception("I have no idea what you're asking for") and maybe some ValueError catching in the int call. Andrew From nav+posts at bandersnatch.org Tue Aug 26 09:09:12 2003 From: nav+posts at bandersnatch.org (Nick Vargish) Date: 26 Aug 2003 09:09:12 -0400 Subject: ANN: BlackAdder V1.0.0 References: <3f48a498$3$219$fa0fcedb@lovejoy.zen.co.uk> <1Kj2b.61523$bo1.38258@news-server.bigpond.net.au> <3f4a7ba0$0$250$fa0fcedb@lovejoy.zen.co.uk> Message-ID: "BadJake" writes: > This way I get my resellers commission. Ah, greed. > If I was to link to theKompany.com BA page I would get nothing Imagine how sad we would be then... Not. Nick -- # sigmask || 0.2 || 20030107 || public domain || feed this to a python print reduce(lambda x,y:x+chr(ord(y)-1),' Ojdl!Wbshjti!=obwAcboefstobudi/psh?') From wiebke.paetzold at mplusr.de Mon Aug 4 06:53:54 2003 From: wiebke.paetzold at mplusr.de (Wiebke Pätzold) Date: Mon, 04 Aug 2003 12:53:54 +0200 Subject: Classes in Python References: <14dsivkn40c0grotsti39cgsrde7v03hq4@4ax.com> Message-ID: On Mon, 04 Aug 2003 12:30:11 +0200, Wiebke P?tzold wrote: >Hi all! > >Could somebody help me with a task? > >import sys >import Mk4py >import re > >db = Mk4py.storage("c:\\datafile.mk",1) >vw = db.view("people") > >class PatternFilter: > def _init_(self, pattern): > self.pattern = re.compile(pattern) > > def _call_(self, row): > try: > nachname = row.Nachname > except AttributeError: > return 0 > return self.pattern.search(nachname)is not None > >vf = vw.filter(PatternFilter("Ge.*")) > >for r in vf: > print vw[r.index].Nachname > > > >I wrote this program, but it returns nothing. I can't find the error. >Can somebody help me? >Can somebody tell me why the part: "class PatternFilter:" doesn't >return the expressions it should return? > >Wiebke It has to be something wrong with line: vf = vw.filter(PatternFilter("Ge.*")) From bokr at oz.net Sun Aug 10 17:00:54 2003 From: bokr at oz.net (Bengt Richter) Date: 10 Aug 2003 21:00:54 GMT Subject: How to print floating point in scientific format? References: <420ced91.0308081115.7060e551@posting.google.com> Message-ID: On 8 Aug 2003 12:15:53 -0700, sdhyok at yahoo.com (sdhyok) wrote: >I want to change the DEFAULT behavior of python >to print out all floating points in scientific format? >For instance, > >>x=0.01 >>print x >1.000000E-2 #Like print "%E"%x > >How can I do it? > Do you have to use the print statement per se for output? I.e., why couldn't you write sciPrint( x, whatever, etc ) instead of print x, whatever, etc Then you could customize sciPrint as you please. Or do you have to change the behaviour of existing modules without changing their source? Regards, Bengt Richter From jeremy+plusnews at jeremysanders.net Sun Aug 24 11:38:30 2003 From: jeremy+plusnews at jeremysanders.net (Jeremy Sanders) Date: Sun, 24 Aug 2003 16:38:30 +0100 Subject: building rpms with distutils Message-ID: I've searched in vain for ages on the web about this problem. I'm trying to generate an rpm for the "numarray" python package. The catch is the system is a RedHat 7.3 system, so I need to use the python2 executable (the package is python-2 only, and I don't write python-1 code) rather than the ancient python executable. Obviously python ./setup.py bdist_rpm fails, but so does python2 ./setup.py bdist_rpm when it tries to build the rpm. The spec file generated mentions the "python" executable rather than "python2", so rpm tries to run setup.py with python rather than python2. Is there an easy way to fix this (other than updating my distribution)? Thanks Jeremy From oren-py-l at hishome.net Thu Aug 7 07:28:46 2003 From: oren-py-l at hishome.net (Oren Tirosh) Date: Thu, 7 Aug 2003 07:28:46 -0400 Subject: crossplatform py2exe - would it be useful? In-Reply-To: References: Message-ID: <20030807112846.GA86353@hishome.net> On Wed, Aug 06, 2003 at 08:36:20PM +0200, Thomas Heller wrote: > I'm currently working on a new version of py2exe, which will require > Python 2.3 and later, because it uses the zipimport mechanism. Now that zipimport is part of Python the code required for bootstrapping a py2exe runtime is just: myscript -c "import sys; sys.path.insert(0, sys.executable); import foo" This reduces the difference between the custom interpreter supplied with py2exe and the standard interpreter to just a few lines of C. The obvious question is - why not go all the way and put this little hook into the standard Python distribution? This way py2exe could be a platform-independent pure Python application. In fact, py2exe wouldn't actually be necessary because anyone could create a zip file manually and append it to the executable but it's more convenient to have a tool that automates the process and finds the required dependencies. Oren From jimmy at retzlaff.com Mon Aug 11 20:42:15 2003 From: jimmy at retzlaff.com (Jimmy Retzlaff) Date: Mon, 11 Aug 2003 17:42:15 -0700 Subject: Python vs. C# Message-ID: Brandon J. Van Every (vanevery at 3DProgrammer.com) wrote: >Ok, so Python is "more flexible" than C#. If I start doing problems that >require a lot of flexibility, I'll remember this about Python and consider >it. To date I've not been working on such problems, but that could change. >And C# might still prove to be "flexible enough." You almost get it. While not many problems "require" Python's flexibility, a large number of problems can be more effectively addressed by leveraging that flexibility. Put another way, you can often create better solutions in less time. Not many of Python's individual features are unique among languages available today, but there is an amazing synergy among Python's features that is hard to comprehend until you've used them to solve some non-trivial problems. In the early days of the PC there was a similar debate over the use of Assembly versus higher level languages like C and Pascal. Not many problems "required" the features of those higher level languages, but people came to understand the benefits in the vast majority of applications (benefits like time/money, maintainability, and reliability). Jimmy From adalke at mindspring.com Wed Aug 27 15:01:20 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Wed, 27 Aug 2003 19:01:20 GMT Subject: Celebrity advice (was: Advice to a Junior in High School?) References: <3F4CD2A2.DE7D05D2@engcorp.com> Message-ID: <4e73b.6416$Jh2.2462@newsread4.news.pas.earthlink.net> Me: > Given a population of 4 billion (roughly, over the century) and assuming > the US rate is average for the world, that's > > >>> 4000000000 / 100000. * 9.2 > 368000.0 > >>> > > or roughly 0.5% of the deaths attributed to murders in the cause of > war. Roughly in line with Terry's claims. Oops! That's *per* *year*. Multiply by 100 to get the number of homicides in a century == 37 million. Andrew dalke at dalkescientific.com From enrique.palomo at xgs-spain.com Fri Aug 8 04:11:14 2003 From: enrique.palomo at xgs-spain.com (Enrique) Date: Fri, 8 Aug 2003 10:11:14 +0200 Subject: ???? i can`t understand it Message-ID: >>> a=[1,2,3,4,5] >>> for b in a: ... a.remove(b) ... >>> a [2, 4] >>> -------------- next part -------------- An HTML attachment was scrubbed... URL: From mwh at python.net Mon Aug 18 10:59:25 2003 From: mwh at python.net (Michael Hudson) Date: Mon, 18 Aug 2003 14:59:25 GMT Subject: Problem with garbage collection (sort of) References: <246a4e07.0308180608.2b8d685a@posting.google.com> Message-ID: <7h34r0f10ab.fsf@pc150.maths.bris.ac.uk> frank at chagford.com (Frank Millman) writes: [...] > The problem is that class a keeps a reference to class b (self.b) and > class b keeps a reference to class a (self.p), so the reference counts > do not go down to zero without some additional action. Sure, but since 2.0, Python supplies that additional action itself... the problems are the __del__ methods. This must be documented somewhere... ah, here: http://www.python.org/doc/current/ref/customization.html#l2h-175 though that's not totally clear. Basically, a cycle will not be cleared if one of the objects making up the cycle has a __del__ method. Sometimes it is possible to arrange things so only "leaf" objects have __del__ methods, then all this ceases to be a problem. Cheers, mwh -- I think my standards have lowered enough that now I think ``good design'' is when the page doesn't irritate the living fuck out of me. -- http://www.jwz.org/gruntle/design.html From postmaster at psdc.com Fri Aug 22 13:42:08 2003 From: postmaster at psdc.com (postmaster at psdc.com) Date: Fri, 22 Aug 2003 10:42:08 -0700 Subject: Delivery Status Notification (Failure) Message-ID: This is an automatically generated Delivery Status Notification. Delivery to the following recipients failed. yosikawa at psdc.com -------------- next part -------------- An embedded message was scrubbed... From: Subject: Re: Wicked screensaver Date: Fri, 22 Aug 2003 10:43:39 --0700 Size: 1445 URL: From jjl at pobox.com Mon Aug 4 14:11:36 2003 From: jjl at pobox.com (John J. Lee) Date: 04 Aug 2003 19:11:36 +0100 Subject: Passing Global Variables between imported modules References: Message-ID: <873cghs36v.fsf@pobox.com> sean at activeprime.com (Sean) writes: > Is there any way to access global variables defined from within an > imported module? For example, lets say have a file called test2.py > that defines a simple class: [...] > Now I have another file that imports test2, sets a global variable > called globalVar, and calles printGlobal() like so: [...] You could explicitly pass MyClass constructor the globals dict (globals()), and have it use that. Not very nice. What's your end goal with this, though? Why not have a class to represent this 'global' state (since it seems it isn't really global)? John From tjreedy at udel.edu Fri Aug 1 20:44:18 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 1 Aug 2003 20:44:18 -0400 Subject: Python's biggest compromises References: <7xr8456ote.fsf@ruckus.brouhaha.com> Message-ID: <-JecnbRfsp3-lLaiXTWJkQ@comcast.com> "Paul Rubin" wrote in message news:7xr8456ote.fsf at ruckus.brouhaha.com... > Brian Quinlan writes: > > I'm not sure that I believe this. In Python, everything is an object > > that participates in GC including integers and other light-weight types. > > Imagine that you have a mathematic expression that creates a dozen > > floats objects as part of its evaluation. Do you believe that it is > > faster to add those dozen floats to a list for later collection than to > > decrement an integer, notice that the decremented value is 0 and > > immediately reclaim the memory? That would not be my intuition (but my > > intuition is often wrong :-)). > > In a fast GC system you would just allocate the floats from a > contiguous block. Later you would copy the reachable floats from that > block to another block. If no floats are reachable, you don't copy > anything. There are all kinds of optimizations you can use, including > making clever use of memory protection hardware to notice when your > allocator has run over the end of a block so you don't have to even > make an explicit pointer comparison, that can make all this run very fast. The proof of such assertions, either way, is in real code. Before circular ref GC was added, at least one person tried replacing ref count GC with 'real' GC. The resulting benchmarks were about the same. So Guido stuck with what was familiar, simpler to understand, and seemed less likely to interfere with other improvements. The type of GC didn't seem to matter too much. But anyone is welcome to prove this wrong. However, acceptance into the core requires some degree of system/hardware independence. As I understand it, Psyco unboxes some types and does away with some of the need for any GC. *That* does seem to make a difference. Terry J. Reedy From just at xs4all.nl Sun Aug 24 03:57:07 2003 From: just at xs4all.nl (Just) Date: Sun, 24 Aug 2003 09:57:07 +0200 Subject: Modifying the {} and [] tokens References: <2259b0e2.0308230718.53d22c14@posting.google.com> <774fkvg920qibnnp83r17inqmk311tqcsv@4ax.com> Message-ID: In article , "Terry Reedy" wrote: > "> If you can conjure up the right Google Groups query, this has been > discussed > > many times in the past (and by that I mean some good points have > been raised > > that you might find interesting). In particular, I remember Alex > Martelli > > making a good argument for len(obj) over obj.len(). > > One point someone made is summarized by the following contrast: > > collections = (atuple, alist, adict, someothercollection) > flengths = map(len, collections) #actual > mlengths = map(lambda obj: gettattr(obj, 'len')(), collections) > #hypothetical Uh? mlengths = map(lambda obj: obj.len(), collections) > # or listcomp equivalents That would be much better than the lambda version: mlengths = [x.len() for x in collections] Just From shagshag13 at yahoo.fr Wed Aug 13 03:29:04 2003 From: shagshag13 at yahoo.fr (Shagshag) Date: 13 Aug 2003 00:29:04 -0700 Subject: email client written with python + wxWindows References: <409a56e2.0308062211.456575df@posting.google.com> <3f32bffa_1@news.unc.edu> Message-ID: <409a56e2.0308122329.10060f42@posting.google.com> "Gary Bishop" wrote in message news:<3f32bffa_1 at news.unc.edu>... > On Wed, Aug 06, 2003 at 11:11:52PM -0700, Shagshag wrote: > > does anyone know of a full python + wxWindows email client ? > > I wrote GBMail for my own use. I like it a lot. It likely wouldn't > suit anyone else but writing it was sure a fun way to learn Python. I > haven't posted the source anywhere but I'd be happy to share it with > anyone interested. this could interest me. (and i also started this thread because i would like to learn wxWindows in a useful way...) thanks, From gh at ghaering.de Mon Aug 4 06:39:10 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Mon, 04 Aug 2003 12:39:10 +0200 Subject: Plotting Package for Python 2.3 In-Reply-To: <3F559DF5.6060209@kfunigraz.ac.at> References: <221d8dbe.0308032301.2c0e801f@posting.google.com> <3F559DF5.6060209@kfunigraz.ac.at> Message-ID: <3F2E37CE.8020605@ghaering.de> Siegfried Gonzi wrote: > srijit at yahoo.com wrote: >> Hi, >> I am looking for a good plotting package (preferably with 3D plotting >> capabilities) based on Python 2.3 (Windows 98). Unfortunately Dislin >> does not exist for Python 2.3. >> I look forward to suggestions from members. > > Hi: > > Do you know this from experience that DISLIN will not work on Python > 2.3? I mean it would be strange, though. It's just the typical Windows luser's way of saying (s)he hasn't found a binary package and (s)he doesn't have any free or commercial compiler for Windows installed :-/ -- Gerhard From jpb at ApesSeekingKnowledge.net Sat Aug 16 12:52:49 2003 From: jpb at ApesSeekingKnowledge.net (Joe Block) Date: Sat, 16 Aug 2003 16:52:49 GMT Subject: ANN: Rekall V2.1 beta0 References: <3f3ddb46$0$226$fa0fcedb@lovejoy.zen.co.uk> Message-ID: In article <3f3ddb46$0$226$fa0fcedb at lovejoy.zen.co.uk>, "BadJake" wrote: > Hi > We are please to announce that we have just started beta testing Rekall V2.1 > beta0. This release is considered unstable, therefore it should not be used > in a production environment. > If you would like to help us beta test Rekall V2.1 beta0, please me an email > and I will send you the details of my private anonymous FTP server. Please > email your request to john at totalrekall.co.uk or john at rygannon.com for the > Windows version and mike at quaking.demon.co.uk for the Linux version. > New for this release are: Macros and Wizards What does it do? From grante at visi.com Wed Aug 13 14:10:22 2003 From: grante at visi.com (Grant Edwards) Date: 13 Aug 2003 18:10:22 GMT Subject: Determine file type (binary or text) References: Message-ID: <3f3a7f0e$0$172$a1866201@newsreader.visi.com> In article , Sami Viitanen wrote: > How can I check if a file is binary or text? In order to provide an answer, you'll have to define "binary" and "text". > There was some easy way but I forgot it.. To _me_ a file isn't "binary" or "text". Those are two modes you can use to read a file. The file itself is neutral on the matter. At least under Windows and Unix. VMS and FILES-11 contained a _lot_ more meta-data and actually did have several different fundamental file types (fixed length records, variable length records, byte-stream, etc.). -- Grant Edwards grante Yow! Will it improve my at CASH FLOW? visi.com From mack at incise.org Sun Aug 24 17:29:44 2003 From: mack at incise.org (mackstann) Date: Sun, 24 Aug 2003 16:29:44 -0500 Subject: A strange behavior of list.extend() In-Reply-To: <420ced91.0308241311.734cbc9c@posting.google.com> References: <420ced91.0308241311.734cbc9c@posting.google.com> Message-ID: <20030824212944.GP1695@incise.org> On Sun, Aug 24, 2003 at 02:11:15PM -0700, sdhyok wrote: > I think the two script should produce the same results, but not. > Why? > > ---------------- Script #1 > ls = [1] > ls.extend([2,3]) > print ls > -> [1,2,3] > > --------------- Script #2 > ls = [1].extend([2,3]) > print ls > -> None list.extend happens in place and returns None, so your ls variable is just getting the returned None. Same thing happens with sort: >>> [4,2,3,1].sort() >>> or: >>> f = [4,2,3,1] >>> f.sort() >>> f [1, 2, 3, 4] -- m a c k s t a n n mack @ incise.org http://incise.org Excellent time to become a missing person. From wtrenker at shaw.ca Thu Aug 14 09:43:09 2003 From: wtrenker at shaw.ca (William Trenker) Date: Thu, 14 Aug 2003 13:43:09 +0000 Subject: Recommendation of a parser generator In-Reply-To: References: Message-ID: <20030814134309.1bf06499.wtrenker@shaw.ca> On Fri, 08 Aug 2003 15:06:33 -0700 fortepianissimo at yahoo.com.tw (Fortepianissimo) wrote regarding Recommendation of a parser generator: > I'd appreciate very much some expert suggestions from the group, like > on the speed, flexibility, portability, and the future prospect (like > to be adopted as the standard etc.). The lemon parser generator program does the same job as YACC or BISON, but uses a less error-prone grammar syntax and a different parsing algorithm to yield a faster, re-entrant and thread-safe parser. It's open source and you can get it at http://hwaci.com/sw/lemon/index.html Regards, Bill From mis6 at pitt.edu Fri Aug 8 07:23:48 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 8 Aug 2003 04:23:48 -0700 Subject: Bug? If not, how to work around it? References: <2259b0e2.0308070919.2bedce6@posting.google.com> <2259b0e2.0308071454.1f2869aa@posting.google.com> Message-ID: <2259b0e2.0308080323.1a2a8dfa@posting.google.com> bokr at oz.net (Bengt Richter) wrote in message news:... > Not very tested, but maybe you have to write it something like this: > > >>> class M(type): > ... def __new__(cls, name, bases, cdict): > ... cdict['__len__'] = lambda self:0 > ... return type.__new__(cls, name, bases, cdict) > ... > >>> class F: __metaclass__ = M > ... > >>> f=F() > >>> F.__len__ > > > >>> F.__len__(f) > 0 > >>> len(f) > 0 > > >>> hasattr(M,'__len__') > False > >>> hasattr(F,'__len__') > True > > Or am I missing the point? ;-/ > > Regards, > Bengt Richter Yes, you are missing the point, indeed ;) The point is that if you define a fake special method via __getattr__, it works if it is called as F.__len___(f), but it DOES not work if it is called as len(f). I suspect Gonzalo's problem is the same with iter. Built-in like iter, len, etc. look directly for special methods __iter__, __len__ etc., *without* checking if they are defined by __getattr__. I am not saying that this is necessarely a bug, I am saying that this is not documented and that at least three persons have been beaten by this issue in the last few months. Not me personally, hence the reason why I didn't submit a bug report, but this time (if Gonzalo is not going to do that), I will submit the report, unless Alex is going to prove that this is already documented ;) Michele From ny_r_marquez at yahoo.com Tue Aug 26 15:09:38 2003 From: ny_r_marquez at yahoo.com (R.Marquez) Date: 26 Aug 2003 12:09:38 -0700 Subject: need code-snippet for a simple dialog window in wxPython References: Message-ID: <8a27e309.0308261109.2adaafe0@posting.google.com> Christoph Lehmann wrote in message news:... > Hi > > I am a newbie and have a very simple python code, doing some calculations. > > maybe there is one already having a code snippet in wxPython for what I need: > > (i) simple dialog box, where the user can enter an integer. after > closing the dialog I get this integer. nothing more > > (ii) similar for getting a file-name (with a file-dialog) > > thanks a lot > > > christoph There is a nice little example on the "Python Introduction Slides" currently being discussed in a separate thread of this news group. This is the link to the presentation: http://www.cs.bgu.ac.il/~tebeka/pyintro_files/frame.htm See the second example after the "GUI" slide. From mitchchapman at earthlink.net Mon Aug 25 10:29:24 2003 From: mitchchapman at earthlink.net (Mitch Chapman) Date: Mon, 25 Aug 2003 14:29:24 GMT Subject: Python Library & Extension FAQ In-Reply-To: References: Message-ID: <3F4A1D83.50407@earthlink.net> amk at nyman.amk.ca wrote: > This is the last of the new FAQ files assembled from the old 240K FAQ. > As usual, comments on existing answers and suggestions for new > questions are welcome. > > --amk Thanks, Andrew. It's amazing how much you do for this community. Here's a context diff, with repairs for the few broken links I've found while using the FAQ. (This is a sort of proof that people find your work immediately useful :) -- Mitch Chapman *** PythonLibraryAndExtensionFAQ.txt Mon Aug 25 08:11:08 2003 --- PythonLibraryAndExtensionFAQ.txt.orig Mon Aug 25 08:03:05 2003 *************** *** 677,685 **** http://www.python.org/cgi-bin/moinmoin/WebProgramming . Cameron Laird maintains a useful set of pages about Python web technologies at ! http://phaseit.net/claird/comp.lang.python/web_python.html ! The `Web Programming topic guide `_ also points to many useful resources. --- 677,685 ---- http://www.python.org/cgi-bin/moinmoin/WebProgramming . Cameron Laird maintains a useful set of pages about Python web technologies at ! http://starbase.neosoft.com/~claird/comp.lang.python/web_python.html ! The `Web Programming topic guide `_ also points to many useful resources. *************** *** 738,744 **** * Quixote's PTL uses Python syntax to assemble strings of text. Consult the `Web Programming topic guide ! `_ for more links. How do I send mail from a Python script? --- 738,744 ---- * Quixote's PTL uses Python syntax to assemble strings of text. Consult the `Web Programming topic guide ! `_ for more links. How do I send mail from a Python script? From bergeston at yahoo.fr Sun Aug 31 11:14:21 2003 From: bergeston at yahoo.fr (Bertrand Geston) Date: Sun, 31 Aug 2003 17:14:21 +0200 Subject: Declaration of an array of unspecified size References: Message-ID: "Bertel Lund Hansen" a ?crit dans le message news: m814lvc8h44vbd5g1m2iv05r33qg8ag9ta at news.stofanet.dk... > Hi all > > I am relatively new to Python but have som programming > experience. I am experimenting wit a POP3-program and it's fairly > easy. > > I want to read the mails into an array of lists so I later can > choose which one to display. But I need to declare an array of > unknown size before I can use it in the code. How do I manage > that? > > > class PopMailServer: > host = "" > user = "" > password = "*" > mails = 0 > mail[] # This is wrong but what do I do? mail=[] > > def __init__ (self): > pop=poplib.POP3(self.host) > pop.user(self.user) > pop.pass_(self.password) > self.mails=len(pop.list()[1]) > for i in range(self.mails): > self.mail[i]=pop.retr(i+1)[1] # This is also wrong. self.mail.append(pop.retr(i+1)[1]) > pop.quit() > print "Antal mails: %d\n" % self.mails > > -- > Bertel > http://bertel.lundhansen.dk/ FIDUSO: http://fiduso.dk/ Hi, Above, in your code, the answer to your question. I suggest this code (not tested - I didn't check neither the poplib - but gives some ideas like instance variables, default args, ...): class PopMailServer: def __init__ (self, host = "", user = "", password = "*"): self.host=host self.user=user self.password=password self.mails=[] pop=poplib.POP3(self.host) pop.user(self.user) pop.pass_(self.password) countMails=len(pop.list()[1]) for i in range(countMails): self.mails.append(pop.retr(i+1)[1]) pop.quit() print "Antal mails: %d\n" % len(self.mails) bg From max at alcyone.com Tue Aug 19 00:32:55 2003 From: max at alcyone.com (Erik Max Francis) Date: Mon, 18 Aug 2003 21:32:55 -0700 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: Message-ID: <3F41A877.995F9C35@alcyone.com> "Brandon J. Van Every" wrote: > Erik, every time you have ever been "responded to," it's been an > indirect > quote. You have been in my killfile, and off my radar, for at least a > year > if not longer. Sometimes I forget you exist. But every once in > awhile I > see your name, quoted, in the groups I participate in. Brandon (gotta love that; direct address to someone he's "killfiled"), adults use killfiles so that they don't have to see posts they've decided, for whatever reason, that they wish not to read anymore. If you really wanted to killfile me to avoid reading my posts, you'd adjust your killfile to toss emails that were in response to me, or at least show the self-restraint not to read -- and respond! -- to them. It's clear enough from your behavior in this group (and in other groups over the years; there's nothing new here) that you say, "Welcome to my killfile" in order to somehow feel superior over people who really couldn't give a crap who is in your killfile or isn't. Announcing to the world who is in your killfile and who isn't is just childish and stupid. Replying to people who are supposed to be in your killfile to tell them they are, in fact, in your killfile, is just beyond stupid. > But you'll notice I never > sustain > any debate with you, let alone respond to your muckraking drivel. Man alive! > Notice, > in the present instance, that there is no direct response to your quip > about > c.l.r being more useful because I'm not in it. I learned about it > secondhand. But you still felt it necessary to mention it, huh? -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ All the people in his neighborhood turn around and get mad and sing \__/ Public Enemy From mertz at gnosis.cx Fri Aug 22 14:24:23 2003 From: mertz at gnosis.cx (David Mertz) Date: Fri, 22 Aug 2003 14:24:23 -0400 Subject: For Kenny Tilton: Why do I need macros revisited. References: <3f45484f$1_6@corp.newsgroups.com> <3F45A7BF.4060806@nyc.rr.com> <8dk1b.2825$Ej6.1159@newsread4.news.pas.earthlink.net> Message-ID: "Andrew Dalke" wrote previously: |I've seen David Mertz' xml_pickle code which makes good use of |[metaclasses], but don't yet follow how it works. I'm afraid I must insist here that the use of metaclasses in gnosis.xml.pickle is utterly trivial, and just for show. You'll have to look elsewhere for "good use" of them :-). Yours, David... -- mertz@ _/_/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY: \_\_\_\_ n o gnosis _/_/ Postmodern Enterprises \_\_ .cx _/_/ \_\_ d o _/_/_/ IN A WORLD W/O WALLS, THERE WOULD BE NO GATES \_\_\_ z e From neel at mediapulse.com Tue Aug 19 17:25:19 2003 From: neel at mediapulse.com (Michael C. Neel) Date: Tue, 19 Aug 2003 17:25:19 -0400 Subject: Why does this (not) work? Message-ID: I've got this string in which I need to sub in the same word several times; i.e: >>> "%s - %s - %s" % ("test","test","test") 'test - test - test' >>> But I want to use the * to make life easier to read, so I tried: >>> ("test",)*3 ('test', 'test', 'test') >>> "%s - %s - %s" % ("test",)*3 Traceback (most recent call last): File "", line 1, in ? TypeError: not enough arguments for format string >>> Which seemed like a good idea, but after some playing around I found that: >>> eval(str(("test",)*3)) ('test', 'test', 'test') >>> "%s - %s - %s" % eval(str(("test",)*3)) 'test - test - test' >>> Did work. Odd because: >>> type(("test",)*3) >>> type(eval(str(("test",)*3))) >>> Any idea why the tuple to str to tuple works and not the tuple straight? Mike From niemeyer at conectiva.com Sun Aug 24 20:56:44 2003 From: niemeyer at conectiva.com (Gustavo Niemeyer) Date: Sun, 24 Aug 2003 21:56:44 -0300 Subject: Metaclass discussons In-Reply-To: <2259b0e2.0308240346.35319743@posting.google.com> References: <2259b0e2.0308240346.35319743@posting.google.com> Message-ID: <20030825005644.GA31115@ibook> Hello Michele! > class object(object): > class __metaclass__(type): > pass Thanks for the hint! After sending I found out that it should have the real object as parent. OTOH, your nested definition is really elegant! :-) -- Gustavo Niemeyer http://niemeyer.net From dyoo at hkn.eecs.berkeley.edu Tue Aug 19 17:02:45 2003 From: dyoo at hkn.eecs.berkeley.edu (Daniel Yoo) Date: Tue, 19 Aug 2003 21:02:45 +0000 (UTC) Subject: python for non-programmers tutorial? References: Message-ID: Anthony Baxter wrote: : I'm writing a half-day tutorial at work for the non-programmer techies : (network engineers, database admins, sysadmins, that sort of thing) : and was wondering if anyone else has already done this and made their : materials available? I plan to put my slides up on the web after they're : done... Hi Anthony, Python.org has a topic guide for beginners who'd like to learn Python: http://www.python.org/topics/learn/ For your target audience, you may find Jacek Artymiak's article on "Python Programming for Beginners" a good one, as it focuses on some system administration and shell-scripting issues: http://www.linuxjournal.com/article.php?sid=3946 and all of the tutorials on the Beginners topic guide are pretty good. You're also always welcome to ask learning questions on the Python-Tutor mailing list: http://mail.python.org/mailman/listinfo/tutor Good luck to you! From vze4rx4y at verizon.net Mon Aug 4 03:05:57 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Mon, 04 Aug 2003 07:05:57 GMT Subject: PyChecker work with Python 2.3? References: <3F2C5300.FA223CBA@easystreet.com> Message-ID: wrote in message news:3F2C5300.FA223CBA at easystreet.com... > The pychecker site says that pychecker works with versions > 1.5 through 2.2. Any reason to expect that 2.3 breaks it? > Anyone tried it to see? FWIW, just before the 2.3 release, Neal posted as couple of issues that PyChecker had detected. This is a pretty good indication that it runs fine on Py2.3. Raymond Hettinger From vanevery at 3DProgrammer.com Tue Aug 12 05:03:58 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Tue, 12 Aug 2003 02:03:58 -0700 Subject: Python vs. C# References: Message-ID: Joe Cheng wrote: > > Python has dynamic strong typing. So, if you can keep the types of > your objects straight without the help of the compiler, you get the > benefits of a concise syntax while enjoying type safety at runtime. And how, in a large scale industrial systems context, are you supposed to ensure that Joe Programmer doesn't in fact screw it up? -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From mpeuser at web.de Mon Aug 18 10:35:25 2003 From: mpeuser at web.de (Michael Peuser) Date: Mon, 18 Aug 2003 16:35:25 +0200 Subject: advice choosing IDE References: Message-ID: My apologies! I was of course refering to the Trolltech QT Builder which is a fine product but no integrated Python tool. I have heard of "eric" but never used it.... I certainly will! Kindly Michael P "Phil Thompson" schrieb im Newsbeitrag news:mailman.1061213069.4810.python-list at python.org... > On Monday 18 August 2003 1:18 pm, Michael Peuser wrote: > > > > There are two GUI Toolkits you might like: > > PyQt and their GUI Builder (that would be free for non commercial work) if > > you plan to do *a lot* of GUI applications. The GUI Builder is *not* an > > Python IDE, so that is somewhat off topic ;-) > > I'll beat Detlev to it this time... > > eric at http://www.die-offenbachs.de/detlev/eric3.html is a full IDE, written > in PyQt, that integrates with Qt Designer. It does the usual editing, > debugging, project management, class browsing - plus access to source code > control systems, syntax checking, unit testing, profiling, code coverage. > Latest snaphots include refactoring tools. Etc, etc, etc. > > Phil > > From alienoid at is.lg.ua Mon Aug 4 06:58:52 2003 From: alienoid at is.lg.ua (Ruslan Spivak) Date: Mon, 04 Aug 2003 13:58:52 +0300 Subject: how to convert ip address to dot notation Message-ID: <3F2E3C6C.2060707@is.lg.ua> Hello, python users! I have ip addresses in my mysql db in int value - 3232261127, for example. How can i convert that to usual dot notation like 192.168.100.7? Thanks in advance. Your help is very appreciated. Best regards, Ruslan From mack at incise.org Sun Aug 17 16:28:49 2003 From: mack at incise.org (mackstann) Date: Sun, 17 Aug 2003 15:28:49 -0500 Subject: os.system stdout redirection... In-Reply-To: References: Message-ID: <20030817202849.GC22065@incise.org> On Sun, Aug 17, 2003 at 02:43:44PM -0500, Terry Gray wrote: > mackstann wrote: > >On Sun, Aug 17, 2003 at 01:01:41AM -0500, Terry Gray wrote: > >You can use os.popen (popen2 and 3 as well), or the popen2 module's > >Popen3 and 4 classes, or commands.getoutput (and there are probably even > >more ways :). > > > All the Python docs I've been looking at must have been pre-2.0, because > this is the first I've heard of the popen2/3/Popen3/4 calls. Anyway, is > there a recommended way of capturing 'make's' output, line by line, and > redirecting it to a PyQt window? The window in question is a QTextEdit > control with a 'def write' function. > > Again, thanks for the help. Probably the simplest way is something like: import os prog = os.popen("echo hello") print prog.read() --> 'hello\n' It's basically a file-like interface for running shell commands. You can also open with "w" or "rw" and write to the command's stdin, or you can use popen2/3/4 to have individual descriptors for stdin / stdout / stderr. The popen2 module seems to be less cross-platform, at least with regard to the Popen3/4 classes, as I see this in popen2.py: if sys.platform[:3] == "win": # Some things don't make sense on non-Unix platforms. del Popen3, Popen4 But if you plan on only using unix, then Popen3/4 are kinda nice, if you like a more OOPey interface, or want more process management abilities. Example: import popen2 prog = popen2.Popen3("echo hello; read i; echo $i") print prog.fromchild.read() --> 'hello\n' There's also .tochild, to write to its stdin, and Popen4 has childerr, for reading stderr. You can also do prog.poll() and prog.wait(), if you need to check if it's still running, or wait for it to exit, and you can get its pid via prog.pid. So it kinda depends on whether you need to read from the command as you're doing something else, or you want to just wait for it all to come out at once. import popen2 prog = popen2.Popen3("make spaghetti 2>&1") output = "" while 1: text = prog.read() if text: output += text At least, I'm pretty sure that's how you detect that the program is done (reading ''). I've only used Popen3 to interface with mpg321, and it sends a little quit message when it's done, and then I close it, so I haven't had to check for when it exits. If you need to read bits from it while you're simultaneously doing other things, you can use prog.fromchild.fileno() with select.select(), for example. Or launch a thread, or other things I'm sure. -- m a c k s t a n n mack @ incise.org http://incise.org My weight is perfect for my height -- which varies From nika at kassube.de Fri Aug 22 08:47:03 2003 From: nika at kassube.de (Nils Kassube) Date: Fri, 22 Aug 2003 14:47:03 +0200 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: <240b1020.0308201722.d1b991c@posting.google.com> Message-ID: <81smnteu60.fsf@darwin.lan.kassube.de> A nice feature of Ruby is that exceptions are resumable like in Smalltalk, ie. you can have a "retry" statement in your exception handling that allows you to "try again". http://www.rubycentral.com/book/tut_exceptions.html From hwlgw at hotmail.com Tue Aug 19 16:05:16 2003 From: hwlgw at hotmail.com (Will Stuyvesant) Date: 19 Aug 2003 13:05:16 -0700 Subject: How to save web pages for offline reading? References: <84fc4588.0308182224.6186a988@posting.google.com> Message-ID: > [Anand Pillai] > I hope this thread is not dead. > > I would like to know what you decided at the end :-) > Harvestman has about 10 active subscribers right now > and some corporates in India and umpteen of my own friends > use it for their personal 'harvesting' needs :-> > > I hope you downloaded at least the (new) binaries > and gave it a go! Just downloaded it and I will study it. Thanks! What I use now is suboptimal, but works good enough for simple offline reading of blogs and it is fast (no .GIFs etc.). It stores a bunch of blogs I want to read in a directory (if they are new, checked by content-size and stuff). I am sure it can be improved a lot, comments welcome :-) # file getsites.py ## # DEFINITION bloglist.ini format # This is like what effnews (www.effbot.org) uses. But I stopped # using it because it gets too expensive to read online with a # telephone connection. # A file in bloglist.ini format contains a sequence of URI and Title # pairs: URIs are on a line that starts with a '+', and then the title # for that URI follows. # # for instance: # # +http://www.python.org # Python Language Website # +http://online.effbot.org # online.effbot.org ### import sys import os import urllib TMPDIR = 'getsites' NEWDELTA = 60 # If a new blogentry differs less than NEWDELTA bytes from the old # entry, then it is considered not new (suspicion of only a date # change etc.) # For instance, Simon Willison's weblog changed 57 bytes but without # new content: only the "2 days 7 hours ago" message changed. # Pyzine.com changed 400 bytes because of a new "random abstract". # So far, Industry Toulouse is the only site that changes bytes # without new content but does send a content-length, it is because it # has a random quote every time you visit it. # Some titles need in a bloglist.ini file may need editing, for instance # the title 'zone ::: effbot' will create an IOError: "No such file or # directory 'zone ::: effbot'" (on my Windows laptop). DEFAULTFILE = 'bloglist.ini' wfm = "This file has a size but can not have its date changed?" # weird file message ## # Change the date of a file # # @param filename The file that will have its date changed # @param ddmmyyyy String with date # @return Side-effect: file's date changed to ddmmyyyy ## def setdate(filename, ddmmyyyy): import os import time d = int(ddmmyyyy[2:4]) m = int(ddmmyyyy[:2]) y = int(ddmmyyyy[4:]) # 12 hours, 1 minute: gives 01:01 PM, odd t = time.mktime((y, d, m, 12, 1, 0, 0, 0, 0)) os.utime(filename, (t, t)) ## # An example of a list returned: # [{'http://myurl.com/index.html: 'My Site Name'}, # {'http://other.net/c.htm': 'spam'}] # # @param bloglistfile Open file in bloglist.ini format # @return List of dict, every dict has one uri:title pair ## def getsitedict(bloglistfile): lines = [] for line in bloglistfile: lines.append(line) entry = {} # a dict with a uri:title pair haveurl = '' # the uri of the entry we are adding now sites = [] # a list with dicts with url:title for line in lines: line = line.strip() if line[0] == '+': # a new url haveurl = line[1:] if entry: # if a uri:title available sites.append(entry) entry = {} elif haveurl: # collecting a title if entry.has_key(haveurl): entry[haveurl] = entry[haveurl] + line else: entry[haveurl] = line continue return sites ## # Check and maybe download sites # # @param sites List of dict, every dict has one uri:title pair # @return Side-effect: new HTML in TMPDIR ## def getsites(sites): for site in sites: uri = site.keys()[0] title = site[uri] filename = os.path.join(TMPDIR, title + '.html') print print title print uri try: fp = urllib.urlopen(uri) except IOError: print 'ERROR: no connection' continue oldsize = 0 try: oldsize = os.path.getsize(filename) except: pass newsize = 0 for k, v in fp.headers.items(): if k.lower() == 'content-length': newsize = long(v) break if (oldsize == 0) or (newsize != oldsize): # There is a HTTP content-length and it is not the same as # the file we already have (new != old), or we don't have # a file already (old == 0). print 'oldsize', oldsize, 'newsize', newsize print 'Downloading: ' try: op = file(filename, "wb") except IOError: print 'Illegal filename:', filename continue n = 0 while 1: s = fp.read(8192) if not s: break op.write(s) n = n + len(s) fp.close() op.close() for k, v in fp.headers.items(): print k, "=", v print "stored %s (%s bytes)" % (filename, n) if ( (oldsize > 0) # there is an old file and (newsize == 0) # no HTTP content-length and (abs(n - oldsize) <= NEWDELTA) # "no change" ): # Change date of saved blogs that do not send HTTP # content-length and that do not appear to have # changed. # TODO: this also removes NEW pages that have the same # length as the old ones. It would be better to check # the file content, viz. >= 95% same content. Or # check the content of the first 8192 bytes? try: setdate(filename, '31012001') except IOError: print wfm print 'Setting date to 01012001 (untrusted "new")' if __name__ == '__main__': # handle commandline options if len(sys.argv) < 2: filename = DEFAULTFILE else: filename = sys.argv[1] # check and maybe setup download directory try: os.chdir(TMPDIR) except OSError: os.mkdir(TMPDIR) os.chdir(TMPDIR) os.chdir('..') # get dict with sites sites = getsitedict(file(filename, 'r')) # check and maybe download sites getsites(sites) From mwh at python.net Fri Aug 1 07:40:05 2003 From: mwh at python.net (Michael Hudson) Date: Fri, 1 Aug 2003 11:40:05 GMT Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> <840592e1.0307312304.77a0a05f@posting.google.com> Message-ID: <7h3brv9a9oz.fsf@pc150.maths.bris.ac.uk> hanzspam at yahoo.com.au (Hannu Kankaanp??) writes: > Worst of both indeed. Maybe the decision to choose reference > counting was driven by speed considerations. Ease of implementation, portability and playing nicely with C extensions are more likely candidates, IMO. > That might've been reasonable back in early 90's, but GC techniques > have evolved from those days and so GC would be a superior technique > now. Saying "Ref. counting sucks, let's use GC instead" is a statement near as dammit to meaningless. Given the desires above, I really cannot think of a clearly better GC strategy for Python that the one currently employed. AFAICS, the current scheme's biggest drawback is its memory overhead, followed by the cache-trashing tendencies of decrefs. What would you use instead? Cheers, mwh -- After a heavy night I travelled on, my face toward home - the comma being by no means guaranteed. -- paraphrased from cam.misc From donot at likespam.com Wed Aug 27 22:13:34 2003 From: donot at likespam.com (Rich) Date: Wed, 27 Aug 2003 19:13:34 -0700 Subject: learning to program References: <3F4CED6E.D04D35D6@engcorp.com> <5bspkv87u1q0v9aupajrrkjuutuh3f5o44@4ax.com> <3F4CF363.CAF6A14E@engcorp.com> <6b2qkv4nf549o8clg3bagphd02f92dadub@4ax.com> <3F4D0AD6.1CE798D2@engcorp.com> Message-ID: I put this post in the wrong place first, that is why it is on here twice I am going through one of the tutorials on the Python site and have ran into a problem. During the tutorial it talked about TCI, and gave some commands to do. I went to the site and downloaded TCI. but was unable to do any of the tasks. I think my question is, when the tutorial say the Dos prompt, do I use my Dos prompt in windows, or the Dos prompt in the Python program? I am using the Tutorial by Alan Gauld, and I am at the bottom of simple sequences (left side of page). On Wed, 27 Aug 2003 15:47:14 -0400, Peter Hansen wrote: >Rich wrote: >> >> On Wed, 27 Aug 2003 14:07:31 -0400, Peter Hansen >> wrote: >> >> >Rich wrote: >> >> >> >> This is the only post I am able to see, sorry about re posting. I >> >> thought if I changed the subject heading I might be able to see the >> >> post. >> > >> >You should be able to see the replies that you missed via Google Groups, >> >as soon as they are indexed and on the web: >> How long does it usually take to post on Google? > >In my experience, usually quite a few hours (maybe four or more?). Right >now I can see posts there which I read only a short time before seeing >yours, so that estimate feels about right. > >(By the way, it would be helpful if, when you quote material in a post >to which you're replying, if you used whitespace to separate your >own text from the quoted material. I almost didn't see your message >at all, thinking you'd accidentally posted an empty reply. Thanks. :-) > >-Peter On Wed, 27 Aug 2003 15:47:34 -0400, Peter Hansen wrote: >Rich wrote: >> >> On Wed, 27 Aug 2003 14:07:31 -0400, Peter Hansen >> wrote: >> >> >Rich wrote: >> >> >> >> This is the only post I am able to see, sorry about re posting. I >> >> thought if I changed the subject heading I might be able to see the >> >> post. >> > >> >You should be able to see the replies that you missed via Google Groups, >> >as soon as they are indexed and on the web: >> How long does it usually take to post on Google? > >In my experience, usually quite a few hours (maybe four or more?). Right >now I can see posts there which I read only a short time before seeing >yours, so that estimate feels about right. > >(By the way, it would be helpful if, when you quote material in a post >to which you're replying, if you used whitespace to separate your >own text from the quoted material. I almost didn't see your message >at all, thinking you'd accidentally posted an empty reply. Thanks. :- c ) > >-Peter From tzot at sil-tec.gr Fri Aug 22 20:34:02 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Sat, 23 Aug 2003 03:34:02 +0300 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: <3F412484.69867AED@alcyone.com> Message-ID: On Mon, 18 Aug 2003 14:55:21 -0700, rumours say that "Brandon J. Van Every" might have written: >Istvan Albert wrote: >> Erik Max Francis wrote: >> >>>> What's ***TOTALLY COMPELLING*** about Ruby over Python? >>> >>> comp.lang.ruby doesn't have Brandon Van Every. > >Erik has been in my killfile forever, from other newsgroups. I even had to >put him back in after letting him out. I thought a year would have been >enough, but apparently not. > >> LOL >> >> Istvan. > >So, you're guilty by association. Goodbye! Brandon, I have no reason to call you names, and I won't bother pretending to be a practical psychologist laying out my opinion about your social interoperability; however, I will give your sense of humour a test :) You have reported that you once in a while lose your killfile[1] because of newsreader changes, "OS" (quotes intended to humour MS Windows) reinstallations etc. A way to do comparisons between two languages is to test them on practical matters. So, based on that periodical loss of killfile, and on your keen-ness of informing your "victimfiles", I have an idea for you. Write a program in Python and Ruby that reproduces anytime your killfile by googling your posts and selecting those containing a combination of the words "killfile", "killfiling", "goodbye" and possibly "plonk!" (don't know if you use that one); these are replies to people you killfiled. In the process, taste the languages. Request for support in the groups (disabling temporarily your newly recreated killfile :). Join the communities. Share the experience. Answer yourself your own questions --and CC the groups in that answer! I can't talk for Ruby, but I have lived the above for Python (and for a long time just by lurking in the group; we're different in that, but I don't imply I'm better than you). Ruby sounds interesting, but Python has my heart (yes, geeks fall in love with computer languages, just like with any other human product for which a lot of craftsmanship has been invested). Now, after all the sweet talk, I'll show you my true teeth (I'm a faulty lying human sun of a beach after all) and tell you: "Stop believing you're a leader and a lone wolf; there can't be two of us" :) Cheer up, man. If people disappoint you, don't shut them off your world; try charming them, for a change. [1] It was you who reminded me the word "killfile"; I really had forgotten about it and *plonk* etc, because c.l.py (ok, and a.h.bou) have been the only ng's I invest time in lately... ...and PS: : "was that OK? or did I sound too hippy? perhaps we should lose the San Francisco background and, people, somebody stop the Ten Years track, OK??!" -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From bit_bucket5 at hotmail.com Thu Aug 7 11:14:45 2003 From: bit_bucket5 at hotmail.com (Chris) Date: 7 Aug 2003 08:14:45 -0700 Subject: using like and % in MySQLdb References: Message-ID: Dave Harrison wrote in message news:... > Im sure this is a really obvious problem but : > > self.curs.execute( > """SELECT * FROM user WHERE login LIKE '%%s%'""", [login] > ) > > will not work ... gives me an "unsupported format character ''' (0x27)" > > escaping the %'s with % as the doco recommends wont work either. > > however this : > > self.curs.execute( > """SELECT * FROM user WHERE login LIKE '%dave%'""" > ) > > does work > > so what's the go ? > cheers > Dave I just posted a reply and realized I made one mistake. I said to use "select * from user where login like %s" % ('%%%s%%' % login) But it should be like "select * from user where login like %s", ('%%%s%%' % login) as in self.curs.execute("select * from user where login like %s", ('%%%s%%' % login)) That should work. -Chris From graham at rockcons.co.uk Thu Aug 7 11:44:54 2003 From: graham at rockcons.co.uk (Graham Nicholls) Date: Thu, 07 Aug 2003 16:44:54 +0100 Subject: Extracting a short using struct - won't print. Message-ID: <3f3273f7$0$10777$afc38c87@auth.uk.news.easynet.net> Thanks to Richard and Alex, I'm doing this: seg_stru=">BHH" seg_data=self.fhand.read(struct.calcsize(seg_stru)) data=struct.unpack(seg_stru,seg_data) x=seg_data[1] y=seg_data[2] if debug: print ("DEBUG: Image [%s] is [%d] by [%d] pixels" % (self.fname,x,y)) Expecting to extract a filler byte (ignored), then a big-endian short (a python integer) , then another of the same. When I try to print, I get this: File "./pdf_merge", line 426, in getsize print ("DEBUG: Image [%s] is [%d] by [%d] pixels" % (self.fname,x,y)) TypeError: int argument required What am I missing - its probably something simple - earlier I spent half an hour wondering why I was getting a message that "img_file has no object getsize()" from x,y=img.getsize(). It turned out to be because I had got def getsize: indented one indent too far in the class definition. Aaargh! Python is 2.3b1. Thanks -- Graham Nicholls Rock Computer Consultancy From max at alcyone.com Mon Aug 18 18:17:03 2003 From: max at alcyone.com (Erik Max Francis) Date: Mon, 18 Aug 2003 15:17:03 -0700 Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> Message-ID: <3F41505F.69D18CC8@alcyone.com> Roy Smith wrote: > 5) Inventing your own language constructs. In Python, you just don't > do > this. My view of this is that if you really want to do this, you're better off inventing a separate language -- however similar to Python -- and using a processor to turn that language into real Python, which can then be interpreted. In an interpreted language, especially one as dynamic as Python, translation often strikes me as superior to incorporating macros. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ I want a martini that could be declared a disaster area. \__/ Capt. Benjamin "Hawkeye" Pierce From anton at vredegoor.doge.nl Sun Aug 24 05:07:18 2003 From: anton at vredegoor.doge.nl (Anton Vredegoor) Date: Sun, 24 Aug 2003 11:07:18 +0200 Subject: Comments on my "Python Introduction" slides References: <33803989.0308240000.35b9bf1f@posting.google.com> Message-ID: tebeka at cs.bgu.ac.il (Miki Tebeka) wrote: >If you have the time I'd appriciate any comments on my slides at >http://www.cs.bgu.ac.il/~tebeka/pyintro.html This got me a 404. Anton Not Found The requested URL /~tebeka/pyintro.html was not found on this server. Apache/1.3.27 Server at www.cs.bgu.ac.il Port 80 From skip at pobox.com Mon Aug 4 23:49:02 2003 From: skip at pobox.com (Skip Montanaro) Date: Mon, 4 Aug 2003 22:49:02 -0500 Subject: New place for python-mode bug reports and patches Message-ID: <16175.10542.302239.792809@montanaro.dyndns.org> As many of you are already aware, Barry Warsaw recently created a new project on SourceForge to house the python-mode.el code which makes Emacs and XEmacs so delightful to edit Python code. I just completed migrating all open bugs and patches which mention python-mode from the python project to the new python-mode project. In the future, please submit all bugs and patches at http://sourceforge.net/projects/python-mode/ All new bugs and patches regarding python-mode should be submitted to the new project. There's also a mailing list, python-mode at python.org, to which you can subscribe in the usual Pythonic fashion: http://mail.python.org/mailman/listinfo/python-mode Skip From bellman at lysator.liu.se Fri Aug 22 19:19:50 2003 From: bellman at lysator.liu.se (Thomas Bellman) Date: Fri, 22 Aug 2003 23:19:50 +0000 (UTC) Subject: [OT] Why is it called string? References: <3f44ce77$0$556$b45e6eb0@senator-bedfellow.mit.edu> <3F44DBF2.1010403@draigBrady.com> <3f453a22$1_1@themost.net> Message-ID: "Andrew Dalke" wrote: > Paul Watson >> My CS professor would insist that a byte is a collection of bits, and not >> necessarily eight. There are machines which do not have 8-bit addressable >> bytes. > I thought that was called a word, as in "the CDC 6400 had a 60 > bit word size" A word is the natural unit for operation in a machine. The registers are word sized (if there are registers, that is), reads and writes to memory use words (at least from the machine code programmers point of view), and so on. A byte is a, typically smaller, unit of bits that is semiconvenient to operate on, but usually requires a bit more work by the hardware to extract and deposit a single byte in a whole word. Today many CPUs have a word size of 32 bits, and a byte size of 8?bits; there are instructions for operating on a quarter of a word. But on a 36 bit machine, 8 bit bytes would not be very convenient - you'd probably prefer bytes being 6 or 9 bits in size. The DEC PDP-10 was a 36 bit machine. Bytes, however, were variable sized, and could be anywhere between 1 and 36 bits. The instructions LDB (LoaD Byte) and DPB (DePosit Byte) took, in addition to the destination/source register and the word address to load/store from, also an offset (measured in bits) within the word, and a byte size (also measured in bits). -- Thomas Bellman, Lysator Computer Club, Link?ping University, Sweden "We don't understand the software, and ! bellman @ lysator.liu.se sometimes we don't understand the hardware, ! but we can *see* the blinking lights!" ! Make Love -- Nicht Wahr! From aleax at aleax.it Mon Aug 11 10:42:32 2003 From: aleax at aleax.it (Alex Martelli) Date: Mon, 11 Aug 2003 14:42:32 GMT Subject: convert tuple to string References: Message-ID: Lukas Kasprowicz wrote: > My Proglem is, I get after a query on a mysql database with module MySQLdb > a tuple but I need this output from database as a string. > can anybody help? Sure! Just bind that tuple, which you are currently returning, to a variable (so you can in fact close the connection -- you're not doing it now, since return ends your function), and then use that tuple as you prefer. As it's a tuple of tuples you'll probably want to loop over it rather than just calling "//".join or whatever, of course. Unless you know how you want to format the resulting string, it's unlikely that the result is going to be satisfactory to you, of course. Alex From glingl at aon.at Sat Aug 16 15:42:08 2003 From: glingl at aon.at (Gregor Lingl) Date: Sat, 16 Aug 2003 21:42:08 +0200 Subject: How to terminate a TkinterApp correctly? In-Reply-To: References: <3F3DFCF4.5020109@aon.at> <3f3e37c6$0$19888$91cee783@newsreader01.highway.telekom.at> Message-ID: <3f3e896b$0$37198$91cee783@newsreader01.highway.telekom.at> Michael Peuser schrieb: > ----- Original Message ----- > From: "Gregor Lingl" > Newsgroups: comp.lang.python > Sent: Saturday, August 16, 2003 3:53 PM > Subject: Re: How to terminate a TkinterApp correctly? > > .... > > >>Thanks for your remarks and your example. The >>following solution finally did it: >> >>def exit(): >> global done >> done = True # so the animation will terminate, but >> # not immediately! The actual pass through >> # the loop has to be finished. >> print "done!" >> import sys >> # after_idle seems to be crucial! Waits for terminating >> # the loop (which is in a callback function) >> cv.after_idle(sys.exit, (0,)) > > > > Why don't you just return? The mainloop can handle everything!? > Example: > def exit(self): > self.done=1 > return Here I apparently don't understand something fundamental: What is the effect of a return statement as the last statement of a function? When I put this exit into the cv.master.protocol call as shown below, I cannot close the application at all. (I think it's clear to me why) Regards, Gregor > (If you can put it into an appropriate class ....) > > >>cv.master.protocol("WM_DELETE_WINDOW", exit) >> >>if not usingIDLE: >> root.mainloop() >> >>Regards, Gregor >> > > > From mat at frheaven.com Mon Aug 4 17:44:25 2003 From: mat at frheaven.com (Matthieu M.) Date: Mon, 04 Aug 2003 23:44:25 +0200 Subject: Python and XML In-Reply-To: References: Message-ID: <3F2ED3B9.6060008@frheaven.com> Lee Harr wrote: > I think the problem is that your program is called xml.py > > so, when you say: > > from xml import .... > > it is trying to import from YOUR PROGRAM instead of the standard lib. > Try renaming your program. you were right :) Thanks a lot, I didn't know that python searched in the active directory by default... -- Matthieu M. http://www.frheaven.com From tjreedy at udel.edu Sat Aug 23 13:39:15 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 23 Aug 2003 13:39:15 -0400 Subject: Modifying the {} and [] tokens References: Message-ID: "Geoff Howland" wrote in message news:km4fkv8qbbge3mvckv5gsim9amq59qvohb at 4ax.com... > For the [].len() type things, this is obviously a matter of taste There is also history (and backwards compatibility). Once upon a time, neither strings nor tuples had methods, so neither 'abc'.len() nor (1,2,3).len() would have been possible. With respect to {}+{}. An in-place version of this is currently spelled {}.update({}). Yes, more chars to type, but also more 'honest' in not implying symmetry between the two dicts. As the name suggests, duplicate key with new value overrides previous value. Terry J. Reedy From donn at drizzle.com Sat Aug 23 22:50:09 2003 From: donn at drizzle.com (Donn Cave) Date: Sun, 24 Aug 2003 02:50:09 -0000 Subject: OT: Ocaml? References: <7xk795xde6.fsf_-_@ruckus.brouhaha.com> <87lltkuluy.fsf@gmx.net> <7xwud41322.fsf@ruckus.brouhaha.com> Message-ID: <1061693407.954232@yasure> Quoth Paul Rubin : | Arne Koewing writes: |>> Anyone here use OCAML? How do you like it? Is it a language a |>> Pythonista can learn to love? From what little I've seen, it looks |>> interesting, but I haven't actually tried installing or using it yet. |> Yes and I think it's a great language, but it's a little bit harder |> to start learning it. (you must learn how to read the types). |> But you get a very 'save' language with a very efficient compiler. | | Do you find that the strict type system gets in your way like it does | in Java? I have used ocaml only casually, and Java never, but one thing that has worked for me is sort of a functional counterpart of OOP, ``partial application.'' let multiply a b = a * b let double = multiply 2 So supposing I want something like Python's file object. let read_file fp sz = ... let write_file fp data sz = ... let make_file_file fp = { read = read_file fp; write = write_file fp } let f = make_file_file (open filename) in let data = f.read 512 ... let read_buffer buffer sz = ... The point being that the type system, though probably stricter than Java's, does allow ways to conveniently implement the same interface for radically different types, in this case with a feature that's just a basic natural part of any functional programming language. Maybe Java could do the same? Then there is a lot of stuff in Objective CAML's module system that directly addresses type issues, and it also has a fairly complicated OOP system. Donn Cave, donn at drizzle.com From ask at me.com Thu Aug 21 13:06:30 2003 From: ask at me.com (Greg Krohn) Date: Thu, 21 Aug 2003 17:06:30 GMT Subject: [OT] Why is it called string? References: <3f44ce77$0$556$b45e6eb0@senator-bedfellow.mit.edu> <3F44DBF2.1010403@draigBrady.com> Message-ID:

wrote in message news:3F44DBF2.1010403 at draigBrady.com... ... > bit is a contraction of "Binary digIT" > byte is a pun on the word bit (8 bits) > nibble is a pun on the word byte (4 bits) I could swear there where more of these. Isn't there one for 2 bits and 32bits, etc? While using [http://labs.google.com/sets] to see if I could find any others, I ran across [http://www.intuitor.com/counting/HandCounter.html]. Look at the represenation of 4 in binary. I hope that's just a joke. From aleax at aleax.it Fri Aug 8 09:00:10 2003 From: aleax at aleax.it (Alex Martelli) Date: Fri, 08 Aug 2003 13:00:10 GMT Subject: Accessing c objects in python References: Message-ID: Dave Kuhlman wrote: ... [snipped: C API usage directions] > Is there an easier way? I'm not sure, but I'd certainly read the > following section of the Pyrex documentation. It's about how to > wrap C structures: > > http://ldots.org/pyrex-guide/3-structures.html ... > Any Pyrex experts listening in? Am I on the right track here? I'm no pyrex expert, but I recently re-evaluated various options for wrapping large existing C libraries: C API, Boost Python, Pyste, pyrex, ctypes, and Swig. Somewhat to my surprise (I had bad memories about it from the past...), Swig came up on top in terms of simplicity. Pyste might easily be best for _C++_ libraries, already organized into classes and possibly using templates &c -- it, in turn, "rests" om Boost Python. Boost itself -- or pyrex if you'd rather not use C++ for the purpose -- might likely be best if you want to code some significant amount of fast logic, not just wrappers. But for "just wrappers", and C libraries as opposed to C++ ones, Swig rules. I'd use the C API directly only if the other tools were ruled out for some reason (e.g., licensing); it's by far the largest amount of work -- all other tools rest on top of it and can be seen as "code generators" for it that save you aggravation. Alex From fawcett at teksavvy.com Sun Aug 31 03:47:49 2003 From: fawcett at teksavvy.com (Graham Fawcett) Date: Sun, 31 Aug 2003 03:47:49 -0400 Subject: Polymorphism the Python way In-Reply-To: References: Message-ID: <3F51A825.30802@teksavvy.com> Daniel Klein wrote: >Given the following code,,, > >class Dead(object): > def __init__(self, adeadthing): > self.deadthing = adeadthing > > def getthing(self): > return self.deadthing > >class Parrot(object): > def __init__(self, aparrotthing): > self.parrotthing = aparrotthing > > def getthing(self): > return self.parrotthing > >...and then somewhere in some script I use... > > self.getthing() > >to get whatever 'thing' I want to get. > >Isn't there a better way to do this in Python? I hate doing these >'get' type methods. The seem ugly to me. > >Thanks, >Daniel Klein > > Why not just use the same attribute name in each class? class Dead(object): def __init__(self, deadthing): self.thing = deadthing class Parrot(object): def __init__(self, parrotthing): self.thing = parrotthing Then you can access the attribute as `someobj.thing`. Given that you hate getters, and that you didn't title your message, "Encapsulation the Python Way", accessing instance attributes directly is fair game. ;-) -- Graham From ben at dadsetan.com Fri Aug 1 21:21:04 2003 From: ben at dadsetan.com (Behrang Dadsetan) Date: Sat, 02 Aug 2003 03:21:04 +0200 Subject: useful tool for c.l.p Message-ID: I just read through a few posts and something striked me. Many people, just like myself, are too lazy to test the python code they post here. Most of the time, of course, the code either runs well or the person asking at least understands what is meant and can fix eventual bugs. Would it not be wonderful to have some kind of integrated python interpreter within the news agent/email program, so one could kinda select the concerned code (or better, it is automaticly spotted) and just let it run within the mail? :) Sorry.. it is late here (past 3am) and since a few weeks I really wonder what the point is being in 2003.. somehow I so often feel that we are in stone age... Especially we, in the IT world, are really late in Information Technology.. :) Regards, Ben. PS: Yes I know.. making a super-addin working with all email/news agents of the planet does not seem neither worth the effort nor very easily implemented. PPS: No, do not worry. I am going to sleep right now and will stop complaining about why the world is so annoying by the end of this sentence. From panbru at comcast.net Fri Aug 29 13:26:16 2003 From: panbru at comcast.net (N.E. Daynow) Date: Fri, 29 Aug 2003 11:26:16 -0600 Subject: Detecting nan and inf In-Reply-To: References: Message-ID: <4cGdnbgJarhvEdKiXTWJjA@comcast.com> Are there better ways than the following to determine whether a float is nan or inf? strg=val.__repr__() if strg=='nan' or strg=='inf': ** do something ** where 'val' is the float. Tim From robin at jessikat.fsnet.co.uk Sun Aug 10 19:31:44 2003 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Mon, 11 Aug 2003 00:31:44 +0100 Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> <3f36c43a$0$49105$e4fe514c@news.xs4all.nl> Message-ID: In article <3f36c43a$0$49105$e4fe514c at news.xs4all.nl>, Irmen de Jong writes >Robin Becker wrote: > ..... >> I believe pyro can almost do that, but I haven't tried it. > >Could you please elaborate on this a bit? >What exactly did you have in mind when talking about >"migrating threads or tasklets" ? > Well I had in mind the grid concept, which I believe implies the distribution of code to multiple nodes and then the ability to execute on them (I suppose that includes re-sending data to already distributed instances). I imagine that a proper grid would allow reloading of modules as the overall application requires, but that would be relatively trivial if we could capture 'execution state'. Moving a running thread to another process would be fairly hard I imagine, but I guess that's what we want for load balancing etc. >Does this involve transporting code across nodes, >or only the 'execution' (and data)? > >Pyro supports transporting code, but with a few important limitations, >such as "once loaded, not reloaded". > >--Irmen de Jong > -- Robin Becker From sybrenUSE at YOURthirdtower.imagination.com Tue Aug 26 18:24:38 2003 From: sybrenUSE at YOURthirdtower.imagination.com (Sybren Stuvel) Date: 26 Aug 2003 22:24:38 GMT Subject: Best way to write a file n-bytes long References: <8d3e714e.0308261404.12045d96@posting.google.com> Message-ID: Tony C enlightened us with: > Sure, I could create a string that is n Megabytes long, and pass it to > write, but it seems as though there should be a better way ??? > String manipulation is typically considered slow. Why not create a string that is 1 KB long and write that n*1024 times? Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? From mpeuser at web.de Tue Aug 12 11:01:58 2003 From: mpeuser at web.de (Michael Peuser) Date: Tue, 12 Aug 2003 17:01:58 +0200 Subject: drop down feature References: Message-ID: I think it would reduce trafic here if you read an elementary book about how to program with Python. Please, I do not want to be rude! But Python generally has more or less plain vanilla IDEs. You just have to try them out! Most popular is IDLE or course, but there is definitely more. Some of them cost money! SecretLab's PythonWorks Pro, ActiveState's KOMODO, ... Sometimes those IDEs are coupled to GUIs and have GUI Builder Feature.However you have to decide which GUI-Toolkit you want to use (Qt, wx, Tkinter,GTK,......) There is more than one way to do it, as they say at the other place ;-) Kindly Michael Peuser "Emmanuel Jean-Louis" schrieb im Newsbeitrag news:mailman.1060692918.5794.python-list at python.org... Does python 2.2 has a drop down feature like VB does so that you can list of methods and variables associate with that particular class? If it does, how do I turn it on? Thx. -------------- next part -------------- An HTML attachment was scrubbed... URL: From theller at python.net Wed Aug 6 11:51:40 2003 From: theller at python.net (Thomas Heller) Date: Wed, 06 Aug 2003 17:51:40 +0200 Subject: Building extensions with mingw32 -- bdist_wininst fails. References: Message-ID: [posted and mailed] "Chris Gonnerman" writes: > I'll be quick. Here's a transcript: > > C:\usr\WConio-1.5>python setup.py build --compiler=mingw32 > running build > running build_py > running build_ext > building '_WConio' extension > writing build\temp.win32-2.3\Release\_WConio.def > C:\MINGW32\BIN\dllwrap.exe -mno-cygwin -mdll -static --output-lib > build\temp.win > 32-2.3\Release\lib_WConio.a --def > build\temp.win32-2.3\Release\_WConio.def -s bu > ild\temp.win32-2.3\Release\wconiomodule.o -LC:\PYTHON\libs -LC:\PYTHON\PCBui > ld - > lpython23 -o build\lib.win32-2.3\_WConio.pyd > > C:\usr\WConio-1.5>python setup.py bdist_wininst > running bdist_wininst > running build > running build_py > running build_ext > error: Python was built with version 6 of Visual Studio, and extensions need > to > be built with the same version of the compiler, but it isn't installed. > > I checked the archives regarding that error message and found a conversation > wherein Jeremy Hylton claimed he might have added the code to detect this, > and Paul Moore asked to have it removed/disabled at least for mingw32 (which > makes binaries 100% compatible with MSVC6). In the case given then, the > extension wouldn't build at all; now it builds but I can't make a Windows > installer from it. Can you point me to this discussion, please? Then I'll try to look after this. Thomas From pyabo at novamens.com Mon Aug 11 15:30:03 2003 From: pyabo at novamens.com (Pablo Yabo) Date: Mon, 11 Aug 2003 16:30:03 -0300 Subject: Reference count References: <002a01c3603b$73442a90$417290c8@paraopeba> <16183.60555.59705.762835@montanaro.dyndns.org> Message-ID: <007601c3603e$f6bd5d30$0601a8c0@hq.novamens.com> Hi, I need to keep a object alive even if its reference count if zero. Is there any way to increment its reference count using Python code, not Py_INCREF or there is any way to avoid deletion of the object? Thanks, in advance Pablo Yabo From pdfernhout at kurtz-fernhout.com Tue Aug 26 16:17:28 2003 From: pdfernhout at kurtz-fernhout.com (Paul D. Fernhout) Date: Tue, 26 Aug 2003 16:17:28 -0400 Subject: pure Python DB In-Reply-To: References: Message-ID: <3f4bc002_5@corp.newsgroups.com> Patrick- You might try out the Pointrel Data Repository System I wrote -- it's all in Python. http://sourceforge.net/projects/pointrel/ You need to learn to frame the data storage problem in its terms (triads or somewhat Entity-Relation-al, similar in some ways to RDF). It does provide single-user transactions using a lock file, but this lock file approach has not been tested on lots of platforms. Compared to other systems, you might find it less efficient in disk use (it now supports 64 bit offsets) and more difficult to delete thigns (the short answer is, you can't delete anything -- without writing application level support on top of it). On the plus side, you only need to add one Python file to your project. However, it does not yet have the level of testing yet one might want for something mission critical. Naturally, how well suported it is is a matter of chicken and egg -- if it is not well supported people won't try it or improve it (until it magically makes it over some level of general interest). For an example of its current bleeding edge state, I just discovered what I think may be a potential bug where abandoned transactions could create problems if you are using caching (the cache could hold onto no longer valid handles for added new strings) -- I've patched that for the next release (and you can always just turn off caching), but that's the sort of bleeding edge thing you might encounter if you try it. You can see the recent announcement of the latest version in comp.lang.python.announce. http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&th=6de75a999a0ca969&rnum=3 Or this recent post: http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=3f482037_5%40corp.newsgroups.com&rnum=5 I can say that I'd be interested in making the Pointrel Data Repository a stable and well supported popular platform, although I won't commit to any specific time frame or level of effort for it. I think it would be more ready to go when or if I make the transition to using it to store all my email (gulp -- that's commitment! :-) But that hasn't happened yet. I'm thinking of using it in a web proxy first as that's a little more forgiving application area for me (but the issues of making a good proxy are stalling that some). A year or two or so back I looked at the Gadfly source with a notion of using some of it to put a SQL front end onto Pointrel. Maybe that would make it more apalatable for general use? But I'm not generally interested in using SQL, so I'm not sure how far down that road I want to go. In any case, all the best. And the databases written in C might be worth your exploration -- some of the appear to be quite good and fairly cross platform in their own terms. --Paul Fernhout Patrick Useldinger wrote: > Hello, > for a cross-platform project, I am looking for a Python DB. It should be > lightweight, but provide transactions an of course reliable. > Is there such a thing out there? > I have read about Gadfly, is this still maintained? > Thanks, > -Patrick -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! -----== Over 100,000 Newsgroups - 19 Different Servers! =----- From skip at pobox.com Fri Aug 22 23:52:36 2003 From: skip at pobox.com (Skip Montanaro) Date: Fri, 22 Aug 2003 22:52:36 -0500 Subject: JavaScript web scraping test cases? In-Reply-To: <87zni1ztzl.fsf@pobox.com> References: <87ekzg0y6e.fsf@pobox.com> <87zni1ztzl.fsf@pobox.com> Message-ID: <16198.58628.882106.235626@montanaro.dyndns.org> >> Anyway, the point of this post is that I'm looking for pages to test >> it on, so if you have a page that you'd like scraped (one that uses >> JavaScript in some non-trivial way, of course! ... John> Nobody? Sorry, I couldn't think of anything off the top of my head. In my own pages I've only ever used JS in trivial ways. Aside from a calendar on the Mojam search results pages, I don't think JS is used on our sites at all. Still, you're welcome to try it out on something like http://www.mojam.com/concerts/search?key=performer&value=greg+brown Skip From LONGR at nigms.nih.gov Wed Aug 20 08:17:18 2003 From: LONGR at nigms.nih.gov (Long, Rochelle (NIH/NIGMS)) Date: Wed, 20 Aug 2003 08:17:18 -0400 Subject: Out of Office AutoReply: That movie Message-ID: I will be out of the office the week of August 18 - 22. I will not stay caught up on e-mails. For urgent matters, please call my assistant Michelle Blanco at (301) 594-1826; she will be able to re-direct your inquiry. Thanks. - Rochelle Long, NIGMS From Hengsun.Chao at Cognos.Com Fri Aug 22 15:12:09 2003 From: Hengsun.Chao at Cognos.Com (Chao, Heng Sun) Date: Fri, 22 Aug 2003 15:12:09 -0400 Subject: [Stackless] Stackless ported to 2.2.3 Message-ID: I have replaced the python22.dll. Unfortunately, the stackless capability does not appear to be on. Are there any variables I have to set? Heng Sun Chao System Solution Testing Cognos Inc. 738-1338 x 5051 -----Original Message----- From: Christian Tismer [mailto:tismer at tismer.com] Sent: Thursday, August 21, 2003 3:22 PM To: Pythonistas Cc: Stackless at tismer.com Subject: [Stackless] Stackless ported to 2.2.3 Dear community, with the help of Giovanni Bajo, Stackless Python 3.0 beta is now available for (and only for) Python 2.2.3 . CVS checkout: CVSROOT=:pserver:anonymous at centera.de:/home/cvs cvs co stackless A tgz snapshot can be found here: http://www.stackless.com/stackless-py223-030821.tgz Here are the updated windows binaries: http://www.stackless.com/binaries-pc/ Installation: run Python in the folder where you unpacked python22.dll, or replace this file in c:\windows\system32 have fun -- chris -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 mobile +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ _______________________________________________ Stackless mailing list Stackless at www.tismer.com http://www.tismer.com/mailman/listinfo/stackless Join us at Cognos' biggest event of the year Enterprise 2003, The Cognos Business Forum. Taking place in over 25 cities around the world, it's an opportunity for Business and IT leaders to learn about strategies for driving performance. Visit http://www.cognos.com/enterprise03 for more details. This message may contain privileged and/or confidential information. If you have received this e-mail in error or are not the intended recipient, you may not use, copy, disseminate or distribute it; do not open any attachments, delete it immediately from your system and notify the sender promptly by e-mail that you have done so. Thank you. -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjland at iserv.net Sat Aug 23 13:27:52 2003 From: tjland at iserv.net (tjland at iserv.net) Date: Sat, 23 Aug 2003 13:27:52 -0400 (EDT) Subject: Alphabetizing? Message-ID: <1115.68.73.71.83.1061659672.squirrel@webmail.iserv.net> Ok, im trying to creat a small simple program that alphabetizes user inputed words. I thought why not just create a def that splits all the words down into char's then take the first char and crosscheck it with all lowercase letters. Then find its position and return the results to the user in order or 1-26! But this takes a long time and the code gets confusing. Any suggestion? Thanx in advance! When you see the net take the shot When you miss your shot shoot again When you make your shot you win! Just remember Offense sells tickets But defense wins championships! From zmrzlina at volny.cz Fri Aug 15 11:13:01 2003 From: zmrzlina at volny.cz (Dave) Date: 15 Aug 2003 08:13:01 -0700 Subject: debug python like set -x Message-ID: <15fe3ffc.0308150713.10c30841@posting.google.com> Hi, Newbie here. Is there a way to have output from a python program go to the screen the way it does if I use "set -x" in a shell script? thanks in advance From vanevery at 3DProgrammer.com Tue Aug 19 03:37:07 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Tue, 19 Aug 2003 00:37:07 -0700 Subject: Brandon's abrasive style (was Re: What's better about Ruby than Python?) References: <38ec68a6.0308172319.431a4fde@posting.google.com> Message-ID: Ben Finney wrote: > On Mon, 18 Aug 2003 21:43:12 -0700, Brandon J. Van Every wrote: >> Cliff Wells wrote: >>> finally I've come to the conclusion that you're not trolling, rather >>> merely arrogant and abrasive. >> >> Bingo! Guilty as charged. And I get more and more abrasive the more >> people call me a troll. As do most people who aren't actually >> trolling. > > Quite the opposite -- "get[ting] more and more abrasive the more > people call [one] a troll" is *exactly* how a troll acts. So? Squares are rectangles, but rectangles are not squares. > People who aren't actually trolling will make efforts to depart from > troll-like behaviour when accused of it, to avoid confirming the > accusation. Only in your world view. It's not a IFF. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From nospam at the.net Tue Aug 26 16:13:48 2003 From: nospam at the.net (Rune) Date: Tue, 26 Aug 2003 22:13:48 +0200 Subject: Uncatchable socket.error in socket.py (?) References: <3f4ba0bb$0$49103$e4fe514c@news.xs4all.nl> <3F4BB475.DCECCAA4@alcyone.com> Message-ID: Erik Max Francis wrote: >Rune wrote: > >> Thanks Irmen, but the problem seems to be that the server is actually >> crashed before I can catch the exception. There is no connection to >> send output to. I have no idea how to avoid this. > >If you catch the error, then the server won't have "crashed," and you'll >be able to recover however you like. I am able to catch the exception, but thie connection object from connection, address = sockobj.accept(), is lost. I cannot connect to the server any longer and connection.send(data) will generate a new socket.error: (9, 'Bad file descriptor') I can't find a way out of this but to restart the server. R From daniel.rawson.take!this!out! at asml.nl Wed Aug 13 09:25:04 2003 From: daniel.rawson.take!this!out! at asml.nl (Dan Rawson) Date: Wed, 13 Aug 2003 09:25:04 -0400 Subject: Namespaces, classes, and using standard modules Message-ID: I have several simple classes which need to us "standard" modules like os and sys A class might look like: # --------- MyClass.py ----------------------- class MyClass: def __init__ (self): self.data = '' self.data2 = 'mydata' def show (self): print "Data is " + self.data print "Other data is " + self.data2 print "Directory is " + os.getcwd() # -------------------------------------------- If I do: >>> import os >>> from MyClass import MyClass >>> x = MyClass() >>> x.show() it fails with NameError: global name 'os' is not defined However, if I put the 'import os' statement in MyClass.py, but OUTSIDE the class definition, it works fine. I can also (obviously) put the import inside the class definition, then use 'self.os.getcwd()' but that seems to me to be needlessly complicated. I would have expected that importing os from the interactive prompt would have worked, and that the 'import os' statement in MyClass.py would have been ignored. Any comments or clues about how this SHOULD work would be appreciated! TIA . . . . Dan From davbucko at yahoo.com Tue Aug 26 08:29:46 2003 From: davbucko at yahoo.com (Dave) Date: 26 Aug 2003 05:29:46 -0700 Subject: reading hex values elegantly from a datagram Message-ID: Hi, This is doubtless a really dumb question but is there an elegant way of reading numbers formatted as hex from a datgram? I get a datgram which contains values like this: ---DATAGRAM--- 2aef2d43etc... ---/DATAGRAM-- where this represents 4 numbers: 2a, ef, and 2d43. At the moment I am doing crazy things like converting it to a string, slicing characters off (ie id = packet[0:2]), adding 0x to the front and exec-ing the whole thing to get an integer. I'll put my code in if you really want but it's just embarassing. This is my first time trying to do something with sockets, so please tell me if I have entirely missed the point. I know that you can use read to get a number of bytes, but will that solve my problem? Can anyone point me in the direction of a fool (ie me) proof tutorial on using bits in python because I can't find anything. For example, is it possible to read the binary data? At least then I am sure about the packet structure (for a RADIUS RFC 2865 server, in the unlikely event that anyone is interested). TIA Dave From adalke at mindspring.com Mon Aug 18 22:39:23 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Mon, 18 Aug 2003 20:39:23 -0600 Subject: Design idea for Ping Application References: <4378fa6f.0308181546.548daff7@posting.google.com> Message-ID: Marc: > Actually I already have my threads running and can use them to ping using a > direct call under the os module. But my problem was being able to have them > running continuously. ... > I guess the main question is are there any file functions, like readlines, > that will only look at the available data and not look for EOF? Ahh, in that case your problem is you are using 'readlines', which reads all the lines at once, and waits for the end. Since you really only want a line, and it's okay to wait in your thread for that line, use 'readline()' instead of 'readlines()'. Andrew dalke at dalkescientific.com From clifford.wells at comcast.net Fri Aug 29 05:11:04 2003 From: clifford.wells at comcast.net (Cliff Wells) Date: Fri, 29 Aug 2003 02:11:04 -0700 Subject: OT: Americans love their guns In-Reply-To: <5627c6fa.0308281905.152eb4e4@posting.google.com> References: <5627c6fa.0308281905.152eb4e4@posting.google.com> Message-ID: <1062148264.7273.4.camel@devilbox.homelinux.net> On Thu, 2003-08-28 at 20:05, Tayss wrote: > "Cliff Wells" wrote in message news:... > > I just watched "Bowling for Columbine" last weekend. Interesting watch > > if you're interested in the topic. > > That was a well made documentary, that did not take the easy route in > blaming guns for murder. > > The irony though is that it raised suspicions on the media, but of > course this documentary is really part of the media. It steered the > audience very strongly at times, and I wish he released the unedited > footage of scenes like the surprise interview at the end. It was interesting that he didn't really emphasize his own conclusion at the end. I had the feeling that he didn't really intend to draw a supportable conclusion, but rather simply point out how silly some people's theories were and draw a conclusion *different* than what had come before. Obviously the ultimate goal was to provoke thought on the subject. His own conclusion, while made clear, can't be taken out of the greater context of his efforts to show how any conclusion is misleading at best and outright wrong in most cases. Regards, Cliff From doug.hendricks at tnzi.com Wed Aug 6 23:48:47 2003 From: doug.hendricks at tnzi.com (the_rev_dharma_roadkill) Date: 6 Aug 2003 20:48:47 -0700 Subject: Skipping on memory in Python classes Message-ID: Hi, I'm a Python newbie, but I have some experience in other languages. I need to create about 100,000 instances of one class. Each instance has two lists, one usually empty, the other containing exactly 200 elements which differ widely between the 100,000 instances, but about half of the elements in these lists will be empty strings: instance x (one of 100,000) contains: list A, 200 elements but half are emptyString list B, usually empty (None, not []), but can contain a few small elements variable X, a fairly short string. I also set __init__, __cmp__, and an attribute access function. Question: How can a reduce the memory used to a minimum? I have already set __slots__ = A,B,X and this shaved about 10% off of the used memory, which is well worth it. Any other proven techniques out there? Is there much point in creating a new metaclass for my class? How about replacing emptyStrings with Nones? Is there a fast (runtime) way of translating between '' and None? Cheers, Doug From mporter at despammed.com Wed Aug 27 07:03:46 2003 From: mporter at despammed.com (Michael Porter) Date: Wed, 27 Aug 2003 12:03:46 +0100 Subject: Best way to write a file n-bytes long References: <8d3e714e.0308261404.12045d96@posting.google.com> Message-ID: <3f4c8ebc$0$256$cc9e4d1f@news.dial.pipex.com> "Tony C" wrote in message news:8d3e714e.0308261404.12045d96 at posting.google.com... > Does Python have a function that is analogous to C's write() or > fwrite()- > > that is , I want to write a file (of arbitrary data) that is 100K, or > 1MB (or more) bytes long.. > > Both write() and fwrite() in C allow the user to specify the size of > the data to be written. > > Python's write only allows a string to be passed in. > > Sure, I could create a string that is n Megabytes long, and pass it to > write, but it seems as though there should be a better way ??? > String manipulation is typically considered slow. > > st="X" * 1048576 > fh=open("junk","wb") > fh.write(st) > fh.close() > > > > thanks Another alternative is to seek to required position and write (at least) one byte... reqSize = 1048576 fh = open('junk', 'wb') fh.seek(reqSize - 1) fh.write('\0') fh.close() Mike. From theller at python.net Tue Aug 19 16:00:41 2003 From: theller at python.net (Thomas Heller) Date: Tue, 19 Aug 2003 22:00:41 +0200 Subject: Py2exe for 2.3 also copies python22.dll References: Message-ID: "Brad Clements" writes: > "Thomas Heller" wrote in message > news:oeymloja.fsf at python.net... >> Due to a bug, the run_svc.exe distributed with py2exe for Python 2.3 >> is linked with pywintypes22.dll instead of pywintypes23.dll. >> >> Rebuilding py2exe from source should help (currently I have no time >> to do it myself). >> > Great, I expect that answers my other post about 'can't connect to > service controller' as well. > > are the win32 sources still required to rebuild run_svc? Yes. It has also been suggested by Keith Metcalf to open run_svc.exe with a hex-editor and change the 'pywintypes22.dll' string into 'pywintypes23.dll': http://tinyurl.com/kitg Thomas From Kyler at news.Lairds.org Sat Aug 2 22:18:20 2003 From: Kyler at news.Lairds.org (Kyler Laird) Date: Sun, 03 Aug 2003 02:18:20 GMT Subject: Potentially important real-time on-line discussion References: Message-ID: "Luciano ES" writes: >I think that another big question that strikes many companies is: "if I >make the source available, what will stop anyone from compiling the >source themselves and using it for free (illegally)?", or "if I make >the source available, what will stop anyone from using some of my best >ideas and becoming my competitor?" People pay (what I consider to be) lots of money for me to write software for them. I insist that it be open source (which makes for interesting contract negotiations sometimes). I would be *thrilled* if someone took my code and used it. My value is in providing solutions - not shielding intellectual property from use. --kyler From jacek.generowicz at cern.ch Fri Aug 22 06:56:28 2003 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 22 Aug 2003 12:56:28 +0200 Subject: Which way to say 'private'? References: <14f9kv4fvuf67k6j12lpgt6vk9dcpefchm@4ax.com> Message-ID: Daniel Klein writes: > On Thu, 21 Aug 2003 11:42:02 -0400, "Sean Ross" > wrote: > > >"Daniel Klein" wrote in message > > >Personally, I use single underscore to denote "protected", and double > >underscore to denote "private" (if I use them at all). This is not the orthodox convention: single underscore indicates "privacy" (more accurately: "this isn't part of the interface"): double underscore is actually a mechanism for avioiding name clashes. > I should probably have mentioned that I am concerned about advertising the > 'public' interface (so that users of the class know how best to use it and > what my intentions were) more than 'restricting' access to 'private' members, > which we all know is pretty much pointless in Python ;-) Definitely single underscore. (Also, remember that, with properties, you can have things which look like direct attributes actulally be set and read with setter and getter functions, so it is perfectly OK to make data attributes be part of the interface, as you can later install getters and setters for them without changing the interface.) From electricity at uymail.com Wed Aug 27 11:53:29 2003 From: electricity at uymail.com (U. N. Owen) Date: Wed, 27 Aug 2003 17:53:29 +0200 Subject: newbie Message-ID: <20030827155329.17770.qmail@uymail.com> You should have a look at the documentation at www.python.org/doc, especially these links "Tutorial", "Language Reference", "Library Reference". It is very helpful to try examples from this doc, or any example on the web. Then you can look at the files in python library (.py files), and you'll find lots of well written code. I don't know if you are a newbie with Python or with programming in general. In the latter case, begin with small "challenges", like simple arithmetic : fibonacci numbers, factorization, etc. Arithmetic is full of pretty easy algorithms. Another idea: look for most important things, like open/close a file, print a string, convert between types (and what are the common types). I hope you will enjoy your Python learning ! -- _______________________________________________ Get your free email from http://www.uymail.com Powered by Outblaze From grante at visi.com Tue Aug 5 22:27:14 2003 From: grante at visi.com (Grant Edwards) Date: 06 Aug 2003 02:27:14 GMT Subject: managing stdout and stderr neatly while doing parallel processing References: Message-ID: In article , Andrei D. wrote: > Anyway, what I wanted to ask was about managing the output of stderr as well > as stdout, using select.select and your common garden os.popen in this case. Sorry, can't be done. os.popen() returns a pipe that is hooked to stdout. stderr is still going to where it was before. The stderr stream isn't being handled by your Python program at all. You've got a several options: 1) use os.popen3(), so that you get separate pipes for stdout and stderr. 2) use os.popen4(), so that you get a pipe with combined stdout+stderr. 3) use a pseudo-terminal (pty) so that your child process is running in a more "natural" environment, and you'll get both stderr and stdout that way too. Don't know if there's handy Python "pty" module or not... Some programs act differently when attached to ttys than they do when attached to pipes. If this is a problem, 3) is what you'll need to do. -- Grant Edwards grante Yow! ... I want a COLOR at T.V. and a VIBRATING BED!!! visi.com From adalke at mindspring.com Fri Aug 1 18:45:19 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Fri, 1 Aug 2003 16:45:19 -0600 Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> <840592e1.0307312304.77a0a05f@posting.google.com> <7h37k5xa3sr.fsf@pc150.maths.bris.ac.uk> <7xadat8nic.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin: > I'd say the opposite, the Lisp implementations I've worked on are > considerably easier to write C extensions for, partly BECAUSE you > don't have to worry about constantly tweaking ref counts. I've mentioned in c.l.py before a library I used which can be called from both C and FORTRAN. The latter doesn't support pointers, so instead the library has a global instance table, indexed by integers. The C/FORTRAN code just passes integers around. In addition, there are dependencies between the objects, which means that user code object deallocation can only occur in a certain order. With CPython it's possible to put a high-level OO interface to that library, and provide hooks for the ref-counted gc to call the proper deallocators in the correct order. This is done by telling the finalizer how to do it and paying careful attention to order. The library also has Java bindings. As far as I can tell, it's impossible to hook into Java's automatic gc. A C-level gc like Boehm can't ever tell that data is no longer needed, because the global table keeps a reference to every created object, and Java's native gc doesn't make the proper guarantees on finalization order. Andrew dalke at dalkescientific.com From mwh at python.net Wed Aug 27 14:29:06 2003 From: mwh at python.net (Michael Hudson) Date: Wed, 27 Aug 2003 18:29:06 GMT Subject: Proposal: Magic Constants References: <7h3r837ce12.fsf@pc150.maths.bris.ac.uk> Message-ID: <7h365kj6jp8.fsf@pc150.maths.bris.ac.uk> "John Roth" writes: > "Michael Hudson" wrote in message > news:7h3r837ce12.fsf at pc150.maths.bris.ac.uk... > > "John Roth" writes: > > > > > But these are existing literal syntax. I was thinking > > > more of random code where someone could currently > > > juxtapose a literal and an identifier, say, without an > > > intervening white space character. > > > > >>> 10and 1 > > 1 > > >>> 5or 7 > > 5 > > > > Very much a wart of the tokenizer, though. > > Ah, right. I forgot about alphabetic operators. > > Why do you call it a wart, though? I would have > thought that not requiring white space in that context > was a feature. Well, it's just odd. I'm pretty sure it's not intentional, and fairly sure it's not documented. I don't care enough to check, though :-) Cheers, mwh -- In many ways, it's a dull language, borrowing solid old concepts from many other languages & styles: boring syntax, unsurprising semantics, few automatic coercions, etc etc. But that's one of the things I like about it. -- Tim Peters, 16 Sep 93 From belred1 at yahoo.com Sat Aug 9 10:45:57 2003 From: belred1 at yahoo.com (Bryan) Date: Sat, 09 Aug 2003 14:45:57 GMT Subject: Python for .NET preview 2 release References: <5t_Ya.102789$YN5.72026@sccrnsc01> <87u18rx84u.fsf@pobox.com> Message-ID: "John J. Lee" wrote in message news:87u18rx84u.fsf at pobox.com... > "Bryan" writes: > > > is this the same visual python .net that at activestate? i didn't > > know they python .net is still moving forward. i also thought i > > read somewhere that there were some limitations about using a > > typeless language on the clr. is this not true anymore? > > Visual Python is a plugin for the Visual Studio IDE, I believe. > > Python.NET was an implementation of Python directly on the CLR virtual > machine. It never got anywhere, and never will -- the CLR is hostile > to languages like Python. > > I think Python for .NET is an interoperability framework -- I presume > you can run CPython from .NET, and .NET from CPython, but it isn't > Python *in* .NET. > > It would be nice if all this context were made clear on the Python for > .NET page. > > > John but kobra is a way to scripts .NET services from python, and is supposedly very fast and efficient. wasn't there a pycon speech about this? is this the same Python.NET that was referenced in that speech? --- Reuse Mark Hammond's work on Python.NET - port python itself to the .NET. Advantages "Pure" .NET implementation Other .NET modules can use Python based modules seamlessly Easier to support complete .NET functionality This would be a somewhat "brute force" approach - so perhaps better performing than other approaches. (unverified) Disadvantages a. Poor performance (ref: Mark Hammond) b. Cannot easily access native python extensions c. A significant amount of work - again suitable for a more purist approach. --- sorry, i was under the impression that all the different python .NET solutions were giving way to Kobra as being the best python solution. i thought the python community as a whole was going to rally around it.... i don't mean to take away anything from the work and effort that has been done on Python.NET. i was just surprised to see a new posting about other .NET solutions for python continuing. bryan From logistix at cathoderaymission.net Fri Aug 1 11:29:29 2003 From: logistix at cathoderaymission.net (logistix at cathoderaymission.net) Date: 1 Aug 2003 08:29:29 -0700 Subject: Detect PythonWin? References: <3f29fe44.104328@news.muenster.de> Message-ID: <3c91a864.0308010729.1d94c024@posting.google.com> Martin Bless wrote in message news:... > [Andrew Dalke]: > > >To see if you're on Windows, > [...] > >To see if the win32 extensions are installed > > Ok, > but how can my script know it its running from inside PythonWin? > > I often have the situation that while developing with PythonWin I have > to insert code like > > if 1 and "developing in PythonWin": > sys.argv[1:] = ['fake', 'arguments'] > > Later on or when running the same script from the commandline I need > to disable this if statement. Nasty. > > I'm looking for a predicate functions that will let my script know if > it's running from inside PythonWin. And the function shouldn't use > much time or resources if we are not in PythonWin. > > Anybody knows? > > Martin >>> import sys >>> if sys.modules.has_key('pywin'): ... print "pythonwin running" ... else: ... print "pythonwin not running" ... pythonwin running >>> This shouldn't have any overhead. Writing a predicate function is left as an exercise to the reader. From frank at chagford.com Thu Aug 21 03:30:18 2003 From: frank at chagford.com (Frank Millman) Date: 21 Aug 2003 00:30:18 -0700 Subject: Problem with garbage collection (sort of) References: <246a4e07.0308180608.2b8d685a@posting.google.com> <246a4e07.0308200126.76a3dc78@posting.google.com> <84fc4588.0308200654.18284b50@posting.google.com> Message-ID: <246a4e07.0308202330.3d6c2a9d@posting.google.com> pythonguy at Hotpop.com (Anand Pillai) wrote in message news:<84fc4588.0308200654.18284b50 at posting.google.com>... > Off topic, no doubt, but are you Frank Weiner, > IBM consultant? > > If you are, I can divulge from where I got the > information, otherwise pardon me for the inconvenience. > > -Anand > No, I really am Frank Millman - honestly :-) From wiebke.paetzold at mplusr.de Wed Aug 6 06:56:07 2003 From: wiebke.paetzold at mplusr.de (Wiebke Pätzold) Date: Wed, 06 Aug 2003 12:56:07 +0200 Subject: classes (table) Message-ID: Hi all, I create a database that contains a table. 'Nachname' is one of 13 column names. This program can search for a special letter. In my example it is 'ra'. and the search takes place in 'Nachname'. 'ra' takes place within a word. This is solved with regular expression. So that I can limit my search. For example: I can search for 'ra' and it is not relevant wich letters follow or wich letters are in front of 'ra'. This is the program that I wrote: import sys import Mk4py import re db = Mk4py.storage("c:\\datafile.mk",1) vw = db.view("people") class PatternFilter: def __init__(self, pattern): self.pattern = re.compile(pattern) def __call__(self, row): try: nachname = row.Nachname except AttributeError: return 0 return self.pattern.search(nachname)is not None vf = vw.filter(PatternFilter("ra.*")) for r in vf: print vw[r.index].Nachname The program should have two possibilities to search for regular expressions. The first possibility is in this program. Here I can look for a certain expression. In my example I can look for 'ra' and it is not relevant wich letters follow or wich letters are in front of 'ra'. But this search can ONLY takes place in the column 'Nachname'. 'Nachname is fixed by the programmer. The second possibility is that the user and NOT the programmer determine the column name in which the user want to look for a regular expression. Only the user can determine in which column the search takes place. These 2 kinds of the search must be combined in the program. I hope somebody can help me with my problem! Wiebke From aleaxit at yahoo.com Tue Aug 19 07:06:22 2003 From: aleaxit at yahoo.com (Alex Martelli) Date: Tue, 19 Aug 2003 13:06:22 +0200 Subject: What's better about Ruby than Python? References: Message-ID: Alexander Schmolck wrote: ... > To recap: usually, if I change a class I'd like all pre-existing instances > to become updated (Let's say you develop your program with a running If you CHANGE a class (mutate a class object), that does indeed happen. You seem to have some deep level of confusion between "changing an object" and "rebinding a name (that happened to be previously bound to a certain object) so it's now bound to a different object". Rebinding a name *NEVER* has any effect whatsoever on the object that might have, by happenstance, previously bound to that name (except that, when _all_ references to an object disappear, Python is free to make that object disappear whenever that's convenient -- but that doesn't apply here, since if a class object has instances it also has references to it, one per instance). This rule is universal in Python and makes it trivially simple to understand what will happen in any given occasion -- just as long as you take the minimal amount of trouble to understand the concepts of names, objects, binding (and rebinding) and mutation. If a language has no such clear universal rule, you're likely to meet with either deep, complex trouble, or serious limitations with first-classness of several kinds of objects. In Python everything is first-class, and yet there is no substantial confusion at all. Repeat with me: rebinding a name has just about NOTHING to do with mutating an object. These are VERY different concepts. Until you grasp them, you won't be a very effective programmer. > python session; you notice a mistake in a method-definition but don't want > to start over from scratch; you just want to update the class definition > and have this update percolate to all the currently existing instances. I assume that by "update the class definition" you mean that you want *necessarily* to use some: class X: ... statement that defines a NEW class object (which may happen to have the same name as an existing class object -- quite irrelevant, of course). OK, then, so arrange (easily done with some function or editing macro, if you have a decent editor / IDE) to do the following: oldX = X # save the existing classobject under a new temporary name class X: ... # define a completely new and unrelated classobject oldX.__dict__.clear() oldX.__bases__ = X, # in case you also want to change the old class's name, you might: oldX.__name__ = X.__name__ # so you're not constrained in this sense # optionally, you can now remove the temporary name del oldX There. What's so hard about this? How does this fail to meet your desiderata? Wouldn't it have been easier to ask, in the first place, "I would like to obtain this effect, is there a Python way" (being a BIT more precise in describing "this effect", of course!-), rather than whining about "Python can't do this" and complaining of this as being "unreasonable"? > AFAIK doing this in a general and painfree fashion is pretty much > impossible in python (you have to first track down all instances -- not an I personally wouldn't dream of doing this kind of programming in production level code (and I'd have a serious talk with any colleague doing it -- or changing __class__ in most cases, etc). But depending on one's development style and usage it may perhaps be helpful. If I did that often, of course, I would ensure that the simple function: def updateClass(oldClass, newClass): oldClass.__dict__.clear() oldClass.__bases__ = newClass, oldClass.__name__ = newClass.__name__ was automatically loaded at entry in the interactive environment (see e.g. the PYTHONSTARTUP environment variable for doing this in the usual text-mode interactive interpreter). > I think this sucks big time, because it greatly devalues the interactive > programming experience for certain tasks, IMHO, but maybe I'm just missing > something since typically nobody complains. I don't think the fact that nobody complains is strongly connected to the fact that most Python users grasp the possibility of updating a class by modyfying its __dict__ etc; indeed, one great thing about Python is that most users typically tend to SIMPLICITY rather than "cleverness" -- if they wanted to modify a class X's method Y they'd code it as a function F and then simply do X.Y=F -- extremely simple, rapid, effective, and no need to much with redoing the whole 'class' statement (a concept I personally find quite terrible). Rarely does one want to modify an existing class object any more 'deeply' than by just redoing a method or two, which this utterly simple assignment entirely solves -- therefore, no real problem. If your style of interactive programming is so radically different from that of most other Pythonistas, though, no problem -- as you see, if you put some effort in understanding how things work (particularly the difference between *MODIFYING AN OBJECT* and *REBINDING A NAME*), Python supports you with power and simplicity in MOST (*NOT* all) metaprogramming endeavours. If you DO want total untrammeled interactive and dynamic metaprogramming power, though, *THEN* that's an area in which Ruby might support you even better -- for example, this Python approach would *NOT* work if oldClass was for example str (the built-in string class -- you CANNOT modify ITS behavior). Personally, for application programming, I much prefer clear and well-defined boundaries about what can and what just CANNOT change. But if you want EVERYTHING to be subject to change, then perhaps Ruby is exactly what you want. Good luck with keeping track of what names are just names (and can be freely re-bound to different objects) and which ones aren't (and are more solidly attacked to the underlying objects than one would expect...). Alex From mpeuser at web.de Sun Aug 31 09:58:11 2003 From: mpeuser at web.de (Michael Peuser) Date: Sun, 31 Aug 2003 15:58:11 +0200 Subject: list as paremeters... References: <3f51ce6e$0$26843$626a54ce@news.free.fr> Message-ID: "shagshag13" schrieb im Newsbeitrag news:3f51ce6e$0$26843$626a54ce at news.free.fr... > hello, > > i have an unexpected behaviour that i didn't understand, can someone explain > this to me ? This is a feature, nor a bug ;-) As Python has no 'static' local variables, you can use this trickily to emulate them. Note however that the preset value has to be mutable, {} e.g. Kindly Michael P From SBrunning at trisystems.co.uk Tue Aug 19 09:53:25 2003 From: SBrunning at trisystems.co.uk (Simon Brunning) Date: Tue, 19 Aug 2003 14:53:25 +0100 Subject: 3 new slogans Message-ID: <31575A892FF6D1118F5800600846864D01200B86@intrepid> > From: Nick Vargish [SMTP:nav+posts at bandersnatch.org] > I'm all in favor of Python advocacy, but I much prefer conversion by > example rather than sword. Kill them all. Guido will recognise his own. Cheers, Simon Brunning TriSystems Ltd. sbrunning at trisystems.co.uk ----------------------------------------------------------------------- The information in this email is confidential and may be legally privileged. It is intended solely for the addressee. Access to this email by anyone else is unauthorised. If you are not the intended recipient, any disclosure, copying, distribution, or any action taken or omitted to be taken in reliance on it, is prohibited and may be unlawful. TriSystems Ltd. cannot accept liability for statements made which are clearly the senders own. From pu Sun Aug 17 15:46:55 2003 From: pu (Patrick Useldinger) Date: Sun, 17 Aug 2003 21:46:55 +0200 Subject: client derived from async_chat Message-ID: <3f3fdb48_1@news.vo.lu> Has anybody got such an example? My server works fine, but my client does not :-( -- Real e-mail address is 'cHVAdm8ubHU=\n'.decode('base64') Visit my Homepage at http://www.homepages.lu/pu/ From pyabo at novamens.com Wed Aug 6 09:44:48 2003 From: pyabo at novamens.com (Pablo Yabo) Date: Wed, 6 Aug 2003 10:44:48 -0300 Subject: Interactive Console in embedded Python Message-ID: <00ac01c35c20$e71d93d0$0601a8c0@hq.novamens.com> Hi, I'm runing some python code from a C++ win32 application. I need a tool to debug the code in python that I run. I would like to know if I can run a interactive console to dump objects, etc. Is it possible to get the string of the error messages instead of using PyErr_Print? Thanx in advance Pablo Yabo From speakstofish at hotmail.com Mon Aug 25 18:19:52 2003 From: speakstofish at hotmail.com (Fahd Khan) Date: 25 Aug 2003 15:19:52 -0700 Subject: Preferred standalone TAL module? Message-ID: <5d855b4b.0308251419.31e894e6@posting.google.com> The web-based Python software I've written thus far lacks a consistent approach to generating output. After reading Graham Fawcett's endorsement of Zope Template Pages in the recent web programming thread, I looked up TAL and found it to be quite nice. Going through recent postings on Google it seems SimpleTAL is the standalone TAL module in most active usage and development just now, would the community concur or suggest alternatives? Here's the post I'm referencing: http://groups.google.com/groups?safe=images&ie=UTF-8&oe=UTF-8&as_umsgid=e9570f37.0304070923.70612d28 at posting.google.com%20&lr=&hl=en I'm also motivated by the web programming thread's underlying message of seeking "industrial strength" solutions that work in many domains using existing tools, so that I spend more time coding and less time "shopping" for modules. TAL seems a good way to do that (I'm most certainly not ready to take the plunge into Zope). Any comments there? Fahd Khan From news at yebu.de Tue Aug 5 09:42:47 2003 From: news at yebu.de (Karl Scalet) Date: Tue, 05 Aug 2003 15:42:47 +0200 Subject: ANN: Snakelets 1.1 (simple-to-use web app server with dynamic pages) In-Reply-To: <3f2fab63$0$49103$e4fe514c@news.xs4all.nl> References: <3f2ea0a0$0$49110$e4fe514c@news.xs4all.nl> <3f2f7bf4$0$49103$e4fe514c@news.xs4all.nl> <3f2fab63$0$49103$e4fe514c@news.xs4all.nl> Message-ID: Irmen de Jong schrieb: > Karl Scalet wrote: > >> the reason why I asked for CGI was that I potentially >> will hold a course about python/webprogramming (very >> newbie level) and was thinking about an easy way to set >> up an environment of such. > > > Well, setting up Snakelets is as simple as untarring the tarball > and starting serv.py. Presto, a running web server with > several demo applications ready to go. > Adding your own app is as simple as creating a directory very easy and nice, indeed. BTW after a change of the port-number and a restart, the server crashed: snakeserver/server.py line 511: the clearPageCache argument is missing > and stuffing some .html files (or .y files) into it. > > But it depends on what you want to *achieve* with the web > app in your course. If it is a few simple pages, CGI is > good enough. But if you want to do stuff with sessions, > or more complex pages or page interactions, IMHO CGI > is quickly becoming too cumbersome. see below (current web-hosting situation) >> Previously I was thinking >> about twisted, but did not yet investigate about the >> CGI capabilities there. Why CGI at all: Simple because >> if I introduce some simple web-applications in the course >> the attendees could take them and most easily transport >> them to a common web-hoster. I know about CGIHTTPServer >> and might end up with it. > > > FWIW, it is trivial to create a Ypage in Snakelets or > a true Snakelet that 'calls' your designated "cgi" script > with the current request environment. But one thing is > certain: the web app you're creating won't easily be > transported to a common web-hoster, while plain old > CGI scripts would. It seems that going with CGIHTTPServer > (or even a pre-configured apache server that can run > your python cgi scripts) is your best option. I will play around with Snakelets even more. As far as I can see now, it's pretty right for educational purposes (at the least). Do you intend to bring Snakelets up to a production level? Which one of the current products (Webware?) do you think is closest to yours? Thank you anyhow for Snakelets. Karl, hopefully not initiating a huge thread :-) From faizan at jaredweb.com Sun Aug 3 00:35:46 2003 From: faizan at jaredweb.com (Fazer) Date: 2 Aug 2003 21:35:46 -0700 Subject: Problem dealing with cookies Message-ID: <7b454334.0308022035.25482d72@posting.google.com> Hello, I have the following code: #!/usr/local/bin/python import cgi import Cookie C = Cookie.SimpleCookie() C["moo"] = "f" C["moo"]["path"] = "/" C["moo"]["expires"] = 60*60*60*60 #Print the headers print C print "Content-Type: text/html\n" #Print starting html print "Cookie" form = cgi.FieldStorage() if C['moo'].value != "f": print "I remember you %s" % (C["moo"].value) elif form.has_key("name") and C["moo"].value == "f": print "Thank you %s!" % (form["name"].value) C["moo"] = form['name'].value else: print '' print '' print '' print "" I am new in learning Python and I can't get this to work. Basically, it asks you to input something and thanks you with the display of what you entered. It should remember you. SO when you refresh, it should say that it remembers you. But it doesn't and shows the input box again. What could possibly be wrong here? Thanks in advance! Fazer From syver at inout.no Thu Aug 14 06:29:59 2003 From: syver at inout.no (Syver Enstad) Date: 14 Aug 2003 12:29:59 +0200 Subject: ClientCookie bug References: Message-ID: cartermark46 at ukmail.com (Mark Carter) writes: > I am using Windows 98, python 2.3, ClientCookie 0.4.3a. > > When I do: > import ClientCookie > import os > c = ClientCookie.MSIECookieJar(delayload=1) > c.load_from_registry() > > I get the response: > Traceback (most recent call last): > File "C:\My Documents\mycookies.py", line 33, in ? > c.load_from_registry() > File "C:\PYTHON23\Lib\site-packages\ClientCookie\_MSIECookieJar.py", > line 230, in load_from_registry > self.load(filename, ignore_discard, ignore_expires) > File "C:\PYTHON23\Lib\site-packages\ClientCookie\_MSIECookieJar.py", > line 245, in load > self._really_load(index, filename, ignore_discard, ignore_expires) > File "C:\PYTHON23\Lib\site-packages\ClientCookie\_MSIECookieJar.py", > line 258, in _really_load > user_name = string.lower(os.environ['USERNAME']) > File "C:\PYTHON23\Lib\os.py", line 417, in __getitem__ > return self.data[key.upper()] > KeyError: 'USERNAME' > > Basically, it doesn't like USERNAME as an environment variable. I suspect this only works on "real" win32 (the NT family) operating systems, which define USERNAME, and not hybrid dos/win32 systems like the win9x family. From soundinmotiondj at yahoo.com Tue Aug 26 16:46:27 2003 From: soundinmotiondj at yahoo.com (Stan Graves) Date: 26 Aug 2003 13:46:27 -0700 Subject: Advice to a Junior in High School? References: Message-ID: <3d6c6fc3.0308261246.32db39d5@posting.google.com> "Howard Nease" wrote in message news:... > I would be devastated were I to find the need to leave computer science. I suppose we should just chalk that up to the angst of a 17 year old. There is nothing magical, mystical, or more enlightening about computer science compared with any other profession, vocation or avocation. If you really would be "devastated" to not be a computer scientist, I would recommend some counseling to address your perceptions of your worth and value as a person. > I > love the subject, and I've wanted to be a computer scientist ever since I > was 12 years old. I've changed professional aspirations at least a dozen times since I was 12 years old. I've actually changed professions 6 times since I was 12 years old. > Does anyone have any advice for me and my future? Yes. Volunteer in your community, read to children, talk to your grandparents and find out where you came from, visit art galleries, learn to cook, be a good listener, support your local animal shelters, always stop and buy lemonade from kids in the neighborhood, read one really good book a year - start with Shakespeare or Mark Twain, learn to dance, attend at least one ballet or symphony a year, take a nap at least once a month, stretch before exercising, tip generously, travel, spend less than you earn, and finally - understand that what you do for a living does not define who you are as a person. > What should I study in > college? You should learn to think and to learn in college. Focus on problem decomposition - there are no interesting problems that can be solved in one bite...everything has to be broken down into smaller pieces. Study literature - I have yet to see a single computer scientist who can manipulate symbols as well as Shakespeare. Take a music appreciation class. The development of musical theory and composition provides a good parallel for the understanding of complex systems interactions. I have yet to meet a single computer scientist who can manage complex systems architecture as well as Beethoven. > Will the market for jobs get better? Do I have any hope at all of > finding a decent-paying job in compsci? The market is going to be different than it is today. Better is a judgment that I do not care to make. The advice I received was to get a good education and increase your odds of remaining gainfully employed. It was, and still is, good advice. > What languages do you suggest that I > study (I'm already studying Python)? I'd suggest English. The ability to communicate effectively is probably more important than any technical skill. If you get tired of studying English, then you might try German. I love the structure of the Germanic languages. If you live in the southwest, perhaps Spanish would be a good language to study. If you still insist that specific topics in computer science have any more value than something else, I'd recommend the following: - Pick a text editor. Learn it inside and out. Use it for everything. - Pick a unix shell. Learn it inside and out. Use it for everything. - Use a source code control system for everything - no matter how large or small the project. - Use make for every project, no matter how small. - Favor "standards" over proprietary tools. - Learn to write web pages...using the standards! - Learn C. - Learn C++. Learn it both as an OO language, and as a proceedural language. - Learn one new language a year. --Stan Graves From jjl at pobox.com Sat Aug 23 10:24:15 2003 From: jjl at pobox.com (John J Lee) Date: Sat, 23 Aug 2003 15:24:15 +0100 Subject: JavaScript web scraping test cases? In-Reply-To: <16198.58628.882106.235626@montanaro.dyndns.org> References: <87ekzg0y6e.fsf@pobox.com> <87zni1ztzl.fsf@pobox.com> <16198.58628.882106.235626@montanaro.dyndns.org> Message-ID: On Fri, 22 Aug 2003, Skip Montanaro wrote: > > >> Anyway, the point of this post is that I'm looking for pages to test > >> it on, so if you have a page that you'd like scraped (one that uses > >> JavaScript in some non-trivial way, of course! ... > > John> Nobody? > > Sorry, I couldn't think of anything off the top of my head. In my own pages [...] Oh, I'm sure I'll have no trouble finding test cases -- I just thought that, rather than some random sites that are of no use to anyone, there is bound to be somebody out there who actually wanted to scrape a particular page in the past, and had not bothered previously thanks to the inconvenience of having to read & reproduce the effect of the JS code (particularly code that messes about with forms). It would be nice to be doing something useful at the same time as writing tests! Of course, I already have those sites that gave rise to the 'itch' to do this in the first place, but I'm sure there's lots of the browser object model that they don't exercise... John From grey at despair.rpglink.com Wed Aug 13 14:38:06 2003 From: grey at despair.rpglink.com (Steve Lamb) Date: Wed, 13 Aug 2003 18:38:06 -0000 Subject: Is Python your only programming language? References: Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Tue, 12 Aug 2003 05:44:45 GMT, Joe Cheng wrote: > I want to ask you hard-core c.l.p Pythonistas: Do you use Python for > everything? (and I'm counting Python + C extensions as just Python) Or do > you keep another language equally close at hand, and if so, what is it? And > finally, do you foresee a day when Python can be, for all practical intents > and purposes, your only programming language? Ever since I learned Python 3-4 years back I have been making an effort to program more and more in Python. I attempted to get my work to switch over to no avail. Presently I write 95% in Python, 5% in shell and that 5% in shell is limited to the command-line. If the tast is too complex for me to pipe together a few shell utils I fire up vim and into Python I go. Recently I've expanded into coding in wxPython thanks to the wonderful efforts of the Boa-Constructor team. First time I've seriously delved into GUI work and it is, as with other Python projects, extremely fun to work on. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (GNU/Linux) iD8DBQE/OoWOel/srYtumcURAjqSAKCX/gniUjQhCsR78aHld647+DBxxgCfXR5Z RBkUaMiVBgYoCqsRWLKc4TQ= =GYLW -----END PGP SIGNATURE----- -- Steve C. Lamb | I'm your priest, I'm your shrink, I'm your PGP Key: 8B6E99C5 | main connection to the switchboard of souls. | -- Lenny Nero - Strange Days -------------------------------+--------------------------------------------- From nushin2 at yahoo.com Tue Aug 5 13:56:14 2003 From: nushin2 at yahoo.com (nushin) Date: 5 Aug 2003 10:56:14 -0700 Subject: spawnv( ) or spawnl( ) do not launch a normal running process in Python 2.2.2? References: <3f2ec9dd$1_2@news.vo.lu> Message-ID: Patrick Useldinger wrote in message news:<3f2ec9dd$1_2 at news.vo.lu>... > nushin wrote: > > > os.spawnv(os.P_NOWAIT,'/usr/bin/python',('python hello.py >/dev/null > > &')) > > > > > > os.spawnl(os.P_NOWAIT,'/usr/bin/python',('python hello.py >/dev/null > > &')) > > Did you try *without* the redirections? Yes, i did try *without* redirections, the process doesn't run in normal *R* state. In addition to this bug, if you try to launch the program with P_WAIT parameter, you always get pid 127 back, and pid 127 can not be found in the system. You may try this as: pid = os.spawnv(os.P_WAIT,'/usr/bin/python',(' python hello.py ')) print "hello.py is launched as pid# ",pid and it always returns pid# 127. This proves that this API is not functioning properly. Please correct me if i am wrong. I am using Linux RedHat 7.2 and Python 2.2.2. I use *os.popen()* API to launch hello.py program and it works properly and hello.py runs in state code of *R*. Could someone confirm os.spawnv/spawnl API bugs in Python 2.2.2/Redhat Linux? Regards, Nushin From jfmoxley at mit.edu Sun Aug 24 16:08:46 2003 From: jfmoxley at mit.edu (Joel) Date: 24 Aug 2003 13:08:46 -0700 Subject: nested data structures with classes Message-ID: [sent to python-list at python.org at Sun, 24 Aug 2003 13:31:58 but didn't seem to show up here] Greetings python-list! The good news is that I've been having a blast with Python since early Spring. I've had great success in both learning the language from online / usegroup resources and implementing it in one of my projects. However, I can't pretend to be an expert, and I do not have a strong comp sci background. This is a question that I've had for a while. Usually, I'll stumble across the answer with repeated attempts and re-searching the groups, but I didn't have luck with this one, even in a Dietel book I picked up at the library. I'm assuming there's an obvious answer, so maybe ya'll can save me some time. My Python use involves organizing nested list information. In a simplified example, you could imagine a list of reactants and products in a chemical reaction. Thus, len(nested_list_of_reactants) = len(nested_list_of_products) => "number of reactions" where: nested_list_of_reactants[i] => "list of reactants for reaction i" where: nested_list_of_reactants[i][j] => "reactant j of reaction i" And so forth. Obviously, there are many attributes associated with a specific reaction. Currently, I just pass these attribute lists (nested and non-nested) into and out of functions. However, I'd like to be able to create a class that would streamline this. E.g., (this is a MATLAB structure whose qualities I'd like to emulate): reaction(27).name = 'fawlty towers' reaction(27).reactant(2).name = 'john cleese' Currently, I'd have a list and a nested list to take care of this... reaction_name[27] = 'fawlty towers' and reactants[27][2] = 'john cleese' if this makes sense. Any thoughts or suggestions on this type of data structuring would be greatly appreciated. Python love, Joel From peter at engcorp.com Fri Aug 29 13:48:31 2003 From: peter at engcorp.com (Peter Hansen) Date: Fri, 29 Aug 2003 13:48:31 -0400 Subject: python and webcam?? References: <3F4F56AB.19EFE5AB@engcorp.com> <3F4F6A31.1598071A@engcorp.com> Message-ID: <3F4F91EF.10B944A6@engcorp.com> Michael Peuser wrote: > > "Peter Hansen" schrieb im Newsbeitrag > news:3F4F6A31.1598071A at engcorp.com... > > Mike Kier wrote: > > > > > > > Try this... > > > http://videocapture.sourceforge.net/ > > > > Ah, that's the one. Uses it's own .pyd actually, not calldll as I > > thought. > > > > Doesn't work with my webcam though. Might help if the OP could specify > > what he has. > > > > Works fine with my lowcost cam (AIPTEK 3M). USB Driver from AIPTEK > installed - no problems with VideoCapture. Have you tried the AMCAP.EXE in > folder AMCAP? This is not Pytthon but checks the same interface... No point trying. My webcam is an Axis Communications networked camera which hooks up to Ethernet and responds via HTTP requests. :-) I *think*, though I'm not certain, that the term "webcam" is still generic enough that it doesn't automatically mean a particular kind of camera that is always hooked up through USB and available via the VideoCapture driver... -Peter From jonaomi at excite.com Sun Aug 10 02:35:54 2003 From: jonaomi at excite.com (Jonathan) Date: 9 Aug 2003 23:35:54 -0700 Subject: exec(), execfile() and local-variable binding? References: Message-ID: jonaomi at excite.com (Jonathan) wrote in message news:... > I'm puzzled by Python's behavior when binding local variables which > are introduced within exec() or execfile() statements. [...] I now think I understand the gist of the problem. A Google group search turned up some very similar past discussions. Essentially, execfile() is a function, and so can't (reliably) change the local-variable dictionary (locals()) which is passed into it. So any local-variable settings which happen in the file which execfile() executes are lost when it returns. In contrast, exec() is a *statement*, not a function. Therefore, the locals() dictionary passed into it is mutable. So variable assignments in the string of an exec() *will* affect the local-variable dictionary of the function which calls it. Python's usual static compile-time variable binding can't cope with these potential dynamically-defined variables. So therefore, if any exec() statement is seen in a function body at compile-time, static binding is switched off, and a slower form of run-time binding is used. This dynamically searches the enclosing variable scopes (dictionaries) for variable definitions. The run-time binding triggered by exec() explains a weird effect which I stumbled on after I posted my original message. That is, the execfile() version of the code *will* work if an exec() appears anywhere before or after it in the f() function definition. This is because run-time binding is now used for the whole function - even for the execfile(). That's why I said above that execfile() can't *reliably* change the calling function's local-variable dictionary - it can if this run-time-binding mode is in effect. Such sneaky insertion of a dummy exec() is not great form, though. The recommended way to allow execfile() code to affect current variables is to pass in an explicit context dictionary as an argument to execfile(). Then you are free to use that dictionary as you see fit (notably, using it for other exec()'s or execfile()'s). Another way to implement more of a #include-type effect is to replace this: execfile("blah.py") with this: exec open("blah.py").read() However, once again, this solution will trigger the use of the slower run-time binding for the whole enclosing function. I trust the experts out there will comment if I misrepresented any of these issues. -- Jonathan From Scott.Daniels at Acm.Org Fri Aug 15 13:58:07 2003 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 15 Aug 2003 10:58:07 -0700 Subject: Module access from inside itself In-Reply-To: References: Message-ID: <3f3d1f2d$1@nntp0.pdx.net> Steven wrote: > I'm writing a Python script which can be called from the command-line, and > I want to use my module doc string as the CL help text, but I don't know > how to access my module object from inside the module. How about this: # demo of accessing the docstring: """ This is a test. Had this been a real document, it would have said something. """ if __name__ == '__main__': import __main__ print __main__.__doc__ From NAICH-SYDNEYCH-EXCHANGE at cowleyhearne.com.au Mon Aug 25 03:10:26 2003 From: NAICH-SYDNEYCH-EXCHANGE at cowleyhearne.com.au (GroupShield for Exchange (CH-EXCHANGE)) Date: Mon, 25 Aug 2003 17:10:26 +1000 Subject: ALERT - GroupShield ticket number OA1981_1061795424_CH-EXCHANGE_ 3 was generated Message-ID: <540F61BD2C9BD64DA18FCB9B7367424D897DF7@CH-EXCHANGE.cowleyhearne.com.au> Action Taken: The attachment was quarantined from the message and replaced with a text file informing the recipient of the action taken. To: alucas at cowleyhearne.com.au From: python-list at python.org Sent: 468013952,29584088 Subject: Re: Thank you! Attachment Details:- Attachment Name: application.pif File: application.pif Infected? No Repaired? No Blocked? Yes Deleted? No Virus Name: -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/ms-tnef Size: 1958 bytes Desc: not available URL: From tjreedy at udel.edu Sat Aug 23 19:16:50 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 23 Aug 2003 19:16:50 -0400 Subject: Modifying the {} and [] tokens References: <04cekv0s6ghjtuhl5j2gph7ltobdb5rsam@4ax.com> <62rekv0k4ucgrh46lkp27klq13pq8ppp5p@4ax.com> <1h3fkvg8mkeq69a8hriojugqfcp75hafjj@4ax.com> Message-ID: "Geoff Howland" wrote in message news:veefkvs764jl56ub2b0bt4cn4lekcv0mhf at 4ax.com... > On Sat, 23 Aug 2003 21:56:08 +0300, Christos "TZOTZIOY" Georgiou > wrote: > > >>>[snip of python's by design inability to modify the base C types: dict, > >>>str, list etc] > >> > >>This post begins to read as an insult here, and continues. My > >>incredible gall at thinking something may be better if it was changed > >>and wanting to try it! I should be pelted with rocks for speaking the > >>name Jehova. > > > >I am sorry, Geoff, but I can't understand how you perceived my post as > >insulting. If I did understand a way, I would apologise. I just > >snipped stuff in order to make my post shorter, according to netiquette. > >How can the phrase inside the brackets seem insulting to you? Geoff, > >please justify your clause, and I will gladly apologise. > > If you didn't mean it as insulting, than I am very sorry for taking it > so and responding in the way I did. > > I saw it as I was being told that I am ignoring the good design > philosophies of Python, and as such I should move on to another > language. I have been told exactly this thing before (without being > mistaking) so I suppose I am more sensitive to it than I would have > been had I not had it said before. > > Sorry for misunderstanding you and becoming upset about it. :) > > >>Is this really the way this group is going to continue? > > > >I don't know, I can speak for myself only. How many people have > >responded to you this "way" to make you wonder about the whole group? > > Maybe 2 here, to more or lesser degrees. Probably about 5 times on > python IRC channels. > > >>Why? I respect Guidos decsions, Python needs a strong leader to make > >>them and it got where it is (great language) by having him and the > >>rest of the community help out in this regard. > > > >This is the deal, indeed; for example, I would enjoy very much generator > >comprehensions in the language, and yet they were rejected. > > Exactly, and as long as it's ok to bring them up, then all is well. I > was just feeling like I was being rebuked for doing so. In > retrospect, I probably should have just not responded at all to the > thread portion that I felt that way about, as other people were giving > me answers I thought were completely even. > > I do appreciate Python's design decisions. It's what keeps it from > becomming the things I dont like about Perl, where that does not seem > to be the case. However, I still like having the rope to shoot myself > in the foot if I so desire, but if it doesnt exist I'll get by without > it. :) > > >>Is now no one allowed to say "hey, I think this should be done, and > >>I'd like to make it happen to give it a try"? It's not like if it > >>becomes a problem it couldn't be reverted and lesson learned right? > >>Programming is ABOUT experimentation, not dogmatic obedience. > > > >My reply came to your specific feature request, ie Python allowing you > >to modify the base types; your asking if *any* feature request is > >disallowed is not justified. I consider your question similar to the > >following dialog: > > > >- Can I have cherry pie with my meal? > >- No, because the cook has decided it does not match with your meal, > >which is fish. > >- So no one is allowed to ask for dessert here? > > Well, this was because I took your post as hostility. I'm not sure I > was out there in interpretting this way, as usually telling someone to > "go somewhere else" when they inquire about things is meant that way. > > >I believe that the symbolism is childish, and this indeed you might find > >it insulting, although it isn't. I am not as fluent in English as I > >would like, so this is my way to express the general feeling I got from > >your reply; I call it "black-and-white", or "ping-pong", lacking a > >better English word, and describes a two-way communication where a > >disagreement on the one side is perceived magnified as total rejection > >on the other side. > > Im fine with the things being one way or another, no problems at all > with it. I understand why base types arent allowed to be modified, > cause while you could do it without damaing things, it would be a lot > more likely that things would be damaged over time and you might never > know you're including a module that changes behavior. It makes sense. > > That doesn't mean it wouldnt be useful, which is why I was inquiring. > If it was possible, I'd probably do it because of it's usefulness. If > it became a problem later, I could correct that. I am flexible that > way, it is probably a good thing Guido and the Python community that > helps design Python is not. Checks and balances. > > As long as it's still ok to inquire. > > I think the last thing that was really brought up in this "how dare > you" type style was someone inquiring about protecting their code from > people reading it. Some people near-flamed the guy for asking how to > do this, and I think it is ridiculous. Everyone has their own > purposes for tools, so my ire was up. :) > > >>>I really don't mind subclassing base types and using MyDict() instead of > >>>{}. I want to be able to make my own APIs (MyDict.update *could* blow > >>>whistles and roll twice on the floor before resetting the machine), but > >>>I also want a steady and well-known API for base types (dict.update > >>>*should* update a dictionary from another one). > >> > >>Why should it matter what you mind? It's my code. > > > >What should it matter what you mind then? It's Guido's language. > >Either we both are allowed to say our minds, or not. My opinion is as > >important as yours. Keep that in mind, please. > > Sure, but you were answering a question and saying "no" based on your > opinions. That's tangential to the question, which is that I want to > do something. That it's not possible is topical. That > Guido/PythonLabs doesnt approve is topical, in the sense of a style > guide. That you don't approve is topical on an advice level, but not > on a "how do I do this" level. > > Thats my view of it, and since I was thinking you were saying I should > "move on to another language for not liking everything exactly as it > is now", then I took it as a judgement placement, rather than advise. > > Again, my misunderstanding and my appology. > > >The fact is, the subject has been brought up in the past, and it has > >been skipped. I am not sure if has been rejected, so you might have a > >chance. If you are as warm about this subject as you seem to be, write > >a PEP; my vote will probably be positive. But Guido is the one to > >convince, and he listens; my experience so far has shown that he never > >replies the way you do, and that is good. > > > >This URL should be useful: > >http://www.python.org/peps/pep-0001.html > > I actually wanted to do a proof of concept and try it before writing a > PEP. Cause if it turns out to suck in practice, why bother with the > PEP? I think now I would have to change the Python C code in order to > try it, and that isnt acceptable to me as I wouldnt be able to really > put it into effect in the real world and see if it works. > > I'm all for putting in the time to write and push a PEP if I think > something is really worth it and I have proof in my own eyes. I'm > also accepting if it gets rejected because it doesn't fit with the > language. So far I haven't gotten to a point where I am confident > enough about something I think should work a different way to do this. > Maybe someday it will happen, maybe it wont. I'd like to help, but > dont want to make suggestions that aren't really helpful until I'm > convinced myself that they are. > > >>>With all due respect, Geoff, if this stuff is really important to you, > >>>use Ruby. > > > >>Yes, throw the heathen into another language. I'm not good enough for > >>this one. > > > >Your last statement is unjustified too, and "black-and-white", assuming > >hidden meanings in my words. Geoff, I am picking my words very > >carefully because I don't want to make you jump to the ceiling with > >rage. Please read, don't assume. > > The difficulties of reading text. I showed this message to 2 other > people, and they also thought it was telling me off instead of just > explaining something to me. However, I still appologize for > misreading your intentions and my response. > > >My sentence was a practical (and respectful!) suggestion; Ruby already > >has what you want, and you like it, so why not use it, since the Python > >community (and Guido most of all) are against such a modification? Did > >you do a research in older newsgroup threads before posting? > > Yeah, I searched around for about 6 hours before posting this, also > poking around in different books and the python interpretter. I > didn't find this topic covered, but sometimes it's very hard to find > things with common words like: python, dict, modification/override, > etc. > > Ruby is a great language, but there are a couple reasons it wont be > used in this circumstance. If it was possible and practical, then I > would use it. > > >Don't spend your energy fighting with me (one-side fights: only on > >USENET :), write a PEP and find good arguments for it. > > I dont intend to, I'm glad there was a misunderstanding and sorry I > misunderstood (hope thats parseable). > > Maybe there will be a PEP on this someday, but it'll be harder to do > without evidence that it works well in the real world first. > > > -Geoff Howland > http://ludumdare.com/ From anthonyr-at-hotmail-dot-com at nospam.com Wed Aug 27 21:48:48 2003 From: anthonyr-at-hotmail-dot-com at nospam.com (Anthony Roberts) Date: Thu, 28 Aug 2003 01:48:48 GMT Subject: Style question... References: Message-ID: <4cd3b.50331$la.863381@news1.calgary.shaw.ca> > Isn't there some kind of emacs plugin, macro or mode that > handles Python? I'm not an emacs person, but I've heard that > there is, and I would expect that it would handle things like > auto-indent for you. There is, but it can't tell if I want some stuff indented or not. From none at none.net Wed Aug 13 04:29:20 2003 From: none at none.net (Sami Viitanen) Date: Wed, 13 Aug 2003 08:29:20 GMT Subject: Determine file type (binary or text) Message-ID: Hello, How can I check if a file is binary or text? There was some easy way but I forgot it.. Thanks in adv. From news.collectivize at scandaroon.com Mon Aug 11 17:24:31 2003 From: news.collectivize at scandaroon.com (John Baxter) Date: Mon, 11 Aug 2003 14:24:31 -0700 Subject: python for .NET (question/idea) References: <3f3755be$0$8308$4d4ebb8e@news.nl.uu.net> Message-ID: In article <3f3755be$0$8308$4d4ebb8e at news.nl.uu.net>, "Guyon Mor?e" wrote: > I know it is probably 'windows-only' and the.NET runtime is required, but > what could be other drawbacks on using the .NET framework for gui's? Fewer than all (I don't know how many fewer, but I know 3 machines...one my laptop and two the local computer club) Windows users download the .NET stuff which MS keeps pushing in Windows update. If you have some control over the users, that problem goes away. --John -- Email to above address discarded by provider's server. Don't bother sending. From tjreedy at udel.edu Sun Aug 31 19:50:34 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 31 Aug 2003 19:50:34 -0400 Subject: artificial intelligence? References: <7ZCdnQAI0aeAo8-iU-KYuA@giganews.com> Message-ID: "Istvan Albert" wrote in message news:7ZCdnQAI0aeAo8-iU-KYuA at giganews.com... > Arthur wrote: > > """ > > Dear Amazon.com Customer, > > > > We've noticed that customers who have purchased books by Mark Lutz often > > enjoy the books of Sedi 200. So you might like to know that Sedi 200's > > newest book, Earth's Core and Lower Mantle (Fluid Mechanics of Astrophysics > > and Geophysics, V.11), > > > > """ > > > > Sure read my mind, didn't they? > > > > Any theories on how the Amazon.com AI machine got this far off track? > > The way I interpret this is that your tastes are similar to those > of "Sedi 200". This user's latest purchase was a geophysics books. > Discovering so called "serendipitous" items, items that cannot > be related with classical methods (say content or author) yet > are very desirable to the consumer is the holy > grail of personalization. As the example above shows it > can go totally gaga. Really. SEDI is the acronym of the symposium (7th) that this is the proceedings of. The Sedi 200 would be the participants listed collectively as authors. There are also 5 individual humans listed (as editors). Maybe there was some notice about using Python in geophysic and the symposium book in one journal, so there was a sudden spat of, say, three people who bought both. (The SEDI book is $120 so Mark's book would look cheap by comparison. Terry J. Reedy From wiebke.paetzold at mplusr.de Tue Aug 5 07:55:16 2003 From: wiebke.paetzold at mplusr.de (Wiebke Pätzold) Date: Tue, 05 Aug 2003 13:55:16 +0200 Subject: Classes in Python References: <14dsivkn40c0grotsti39cgsrde7v03hq4@4ax.com> Message-ID: <7b6vivcobi3jmgv0akhllaqvhjn9pgb12j@4ax.com> On Tue, 05 Aug 2003 13:36:08 +0200, Peter Otten <__peter__ at web.de> wrote: >Wiebke P?tzold wrote: > >> So I think that something is wrong with line: >> vf = vw.filter(PatternFilter("Ge.*")) > >The PatternFilter class looks OK now, and so does the line you suspect to be >wrong. Are you sure there are any records in the database with Nachname >containing Ge (and not GE or ge)? That was it, why the program did not run. There I could have lookedl for a long time for the error. Thank you very very very much that you help me with this task. It was very difficult for me because I am very new in Python. > >The only difference I could spot: >- with the function you are looking for Nachname(n), that contain "ra" >- with the class you are looking for Nachname(n) that contain "Ge" > >Being no regular expressions expert, I think that appending ".*" here has no >effect for your purpose (If you want Nachname to start with Ge, the >expression should be "^Ge"). > >> But here I get an error: returned exit code 0. >What's that? Please cut and paste the exact output. > >Peter From peter at engcorp.com Thu Aug 7 14:04:52 2003 From: peter at engcorp.com (Peter Hansen) Date: Thu, 07 Aug 2003 14:04:52 -0400 Subject: Extracting a short using struct - won't print. References: <3f3273f7$0$10777$afc38c87@auth.uk.news.easynet.net> <3F32758E.5734C64F@engcorp.com> <3f32779d$0$10780$afc38c87@auth.uk.news.easynet.net> <3f327aaf$0$10770$afc38c87@auth.uk.news.easynet.net> Message-ID: <3F3294C4.20760CA2@engcorp.com> Graham Nicholls wrote: > > Richard Brodie wrote: > > > > > "Graham Nicholls" wrote in message > > news:3f32779d$0$10780$afc38c87 at auth.uk.news.easynet.net... > > > >> >> seg_stru=">BHH" > >> >> seg_data=self.fhand.read(struct.calcsize(seg_stru)) > >> >> data=struct.unpack(seg_stru,seg_data) > >> >> x=seg_data[1] > >> >> y=seg_data[2] > >> > > >> > Why are you unpacking the struct if you aren't going to use the > >> > unpacked data? > >> > >> Err, I'm trying to extract two shorts - the x and y size in pixels of an > >> image, which I'll use to scale it to fit another pair of parameters. > >> What makes you think I'm not using the data? Am I not - I thought I was! > > > > You aren't using the returned value from struct.unpack() anywhere. > > You need something like x, y = struct.unpack(seg_stru,seg_data) > > I told you it'd be something stupid! > I mean > x=data[1] > y=data[2] > don't I! Yes, you do! :-) Sorry for not being more obvious about the answer, and I thought you might figure it out yourself by using the "import pdb" trick I showed. "Teach a man to fish" and all that. -Peter From aleax at aleax.it Mon Aug 4 06:01:44 2003 From: aleax at aleax.it (Alex Martelli) Date: Mon, 04 Aug 2003 10:01:44 GMT Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> <87el06d2i6.fsf@pobox.com> Message-ID: Andy C wrote: > OK, then unless I'm missing something, tabs vs. spaces shouldn't matter > for > you. The editor should be able to handle tabs in a satisfactory manner as > well. There seems to be an unspoken assumption here that an editor is the only program that will need to deal with Python code I receive. It isn't -- mail and news readers, for example, are often involved -- and those often can't deal satisfactorily with tabs. Thus, it should be the job of the editor of the person who PRODUCES code (if said code is to be sent outside at all) to store spaces, not tabs. Alex From jjl at pobox.com Sat Aug 9 09:39:29 2003 From: jjl at pobox.com (John J. Lee) Date: 09 Aug 2003 14:39:29 +0100 Subject: Python for .NET preview 2 release References: <5t_Ya.102789$YN5.72026@sccrnsc01> Message-ID: <87u18rx84u.fsf@pobox.com> "Bryan" writes: > is this the same visual python .net that at activestate? i didn't > know they python .net is still moving forward. i also thought i > read somewhere that there were some limitations about using a > typeless language on the clr. is this not true anymore? Visual Python is a plugin for the Visual Studio IDE, I believe. Python.NET was an implementation of Python directly on the CLR virtual machine. It never got anywhere, and never will -- the CLR is hostile to languages like Python. I think Python for .NET is an interoperability framework -- I presume you can run CPython from .NET, and .NET from CPython, but it isn't Python *in* .NET. It would be nice if all this context were made clear on the Python for .NET page. John From scottholmes at sbcglobal.net Fri Aug 1 12:40:23 2003 From: scottholmes at sbcglobal.net (Scott Holmes) Date: Fri, 01 Aug 2003 09:40:23 -0700 Subject: Closing Toplevel windows Message-ID: <3F2A97F7.6050903@sbcglobal.net> I'm trying to determine best practices as well as learn basic coding syntax. I wish to open an input screen to view/enter data. The screen also requires a menu. This is part of the code I have so far: import Tkinter import tkMessageBox import Pmw import wcgc_pg class calendarWindow: def __init__(self, parent): megaToplevel = Pmw.MegaToplevel(parent, title = 'Calendar Program') toplevel = megaToplevel.interior() self.balloon = Pmw.Balloon(toplevel) menuBar = Pmw.MainMenuBar(toplevel, balloon = self.balloon) toplevel.configure(menu = menuBar) self.menuBar = menuBar ... This is basically code taken from the Pmw demos. What I wish to determine now is how to close this window from a menu option and/or a button. Neither withdraw() nor deactivate() work. Thanks... -- --------------------------------------------------------------------- Scott Holmes http://sholmes.ws http://pages.sbcglobal.net/scottholmes scottholmes at sbcglobal.net Independent Programmer/Analyst Passport 4GL PHP HTML Composer PostgreSQL Informix 4GL, SQL --------------------------------------------------------------------- There are more things in heaven and earth, Horatio, than are dreamt of in your philosophy --------------------------------------------------------------------- From jonathan.hayward at pobox.com Sat Aug 16 21:18:40 2003 From: jonathan.hayward at pobox.com (Jonathan Hayward) Date: 16 Aug 2003 18:18:40 -0700 Subject: PS: Help pickling across sockets Message-ID: Just after posting the previous request, I realised that my test case worked after I added flushes. The next problem I have is that, in the real program, the server gets an EOFError when it first tries to read from the socket. Relevant portions follow the error message below: Traceback (most recent call last): File "/var/www/cgi-bin/datamine", line 1633, in ? find_and_output_appropriate_page() File "/var/www/cgi-bin/datamine", line 1461, in find_and_output_appropriate_page sys.stdout.write(get_output()) File "/var/www/cgi-bin/datamine", line 1497, in get_output return multitasking.get_page_from_oracle() File "/var/www/cgi-bin/datamine", line 976, in get_page_from_oracle self.check_and_start_oracle() File "/var/www/cgi-bin/datamine", line 972, in check_and_start_oracle self.start_oracle() File "/var/www/cgi-bin/datamine", line 1083, in start_oracle self.run_oracle() File "/var/www/cgi-bin/datamine", line 1056, in run_oracle self.handle_oracle_query(newsocket, address) File "/var/www/cgi-bin/datamine", line 1015, in handle_oracle_query self.get_thread_specific_storage()["environment_variables"] = \ EOFError Traceback (most recent call last): File "/var/www/cgi-bin/datamine", line 1633, in ? find_and_output_appropriate_page() File "/var/www/cgi-bin/datamine", line 1461, in find_and_output_appropriate_page sys.stdout.write(get_output()) File "/var/www/cgi-bin/datamine", line 1497, in get_output return multitasking.get_page_from_oracle() File "/var/www/cgi-bin/datamine", line 988, in get_page_from_oracle result = cPickle.load(sockIn) IOError: [Errno 104] Connection reset by peer >From the server side, here are run_oracle() and handle_oracle_query(): def run_oracle(self): #thread.start_new_thread(\ #self.initialize, ()) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock.bind(("", configuration.get_search_server_port())) sock.listen(5) while 1: try: newsocket, address = sock.accept() self.handle_oracle_query(newsocket, address) #thread.start_new_thread(self.handle_oracle_query, (newsocket, \ #address)) except socket.error: sock.close() sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock.bind(("", configuration.get_search_server_port())) sock.listen(5) def handle_oracle_query(self, sock, address): sockIn = sock.makefile("rb") sockOut = sock.makefile("wb") sockIn.flush() ### Line 1015, immediately below, is where the EOF error is reported. self.get_thread_specific_storage()["environment_variables"] = \ cPickle.load(sockIn) sockIn.flush() self.get_thread_specific_storage()["cgi"] = cPickle.load(sockIn) generate_output() print_output(sockOut) sockOut.flush() sock.close() sockIn.close() sockOut.close() >From the client side, here is get_page_from_oracle(): def get_page_from_oracle(self): self.check_and_start_oracle() sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: sock.connect((configuration.get_search_server_ip(), \ configuration.get_search_server_port())) sockIn = sock.makefile("rb") sockOut = sock.makefile("wb") cPickle.dump(os.environ, sockOut) sockOut.flush() cPickle.dump(cgi.FieldStorage(), sockOut) sockOut.flush() sockIn.flush() ### Line 988, immediately below, also gets an error, but I believe this is secondary damage. result = cPickle.load(sockIn) sock.close() sockIn.close() sockOut.close() return result TIA, ++ Jonathan Hayward, jonathan.hayward at pobox.com ** To see an award-winning website with stories, essays, artwork, ** games, and a four-dimensional maze, why not visit my home page? ** All of this is waiting for you at http://JonathansCorner.com From skg at fluent.co.in Fri Aug 29 00:21:25 2003 From: skg at fluent.co.in (Surya Kiran) Date: 28 Aug 2003 21:21:25 -0700 Subject: eric3 debugger Message-ID: <5946f326.0308282021.6baa6f9c@posting.google.com> Hi, I'm a newbie to eric3 debugger. I'm facing a problem in debugging. Let me explain my problem. I'm using eric3.2 with python2.3, qt-3.2.0 and pyqt-3.7 I've a project, which spans over a number of files. so i've created a .e3p project file for eric3 debugging purposes. when i load the project file, eric3 was not listing all the sources (i expect the eric3 to load all the source python files from .e3p file). i had to manually say, add python directory. even then, if i debug the main script, i expect the debugger to jump over to other file, when it encounters a function in a file different from the current one. thats not happening. what could have been the reason. how can i overcome this difficulty Thanks, Surya From grey at despair.rpglink.com Fri Aug 15 22:59:10 2003 From: grey at despair.rpglink.com (Steve Lamb) Date: Sat, 16 Aug 2003 02:59:10 -0000 Subject: [wxPython] Updating the status bar? References: Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Fri, 15 Aug 2003 14:09:50 -0700, Cliff Wells wrote: > Try adding a wxYield() after the Update(). The Refresh() probably isn't > necessary. That did it. Thanks much! -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (GNU/Linux) iD8DBQE/PZ39el/srYtumcURAvuXAKCVKQ9LNLzCc+b3lP4j4x4tWrd9VgCfSrFv IDikEMBsT5n9MKKVygYawi4= =NYX+ -----END PGP SIGNATURE----- -- Steve C. Lamb | I'm your priest, I'm your shrink, I'm your PGP Key: 8B6E99C5 | main connection to the switchboard of souls. | -- Lenny Nero - Strange Days -------------------------------+--------------------------------------------- From fabsk+news at free.fr Fri Aug 22 10:03:05 2003 From: fabsk+news at free.fr (Fabien SK) Date: Fri, 22 Aug 2003 16:03:05 +0200 Subject: pythoncom + set property Message-ID: <3f4622e5$0$26423$626a54ce@news.free.fr> Hi, I am using "MSSOAP" as COM object and I would like to put a property to an object, but I can not make it work. My code looks like that: obj = win32com.client.Dispatch("MSSOAP.SoapClient30") obj.MSSoapInit("http://server/wsdl"); obj.ClientProperty("ServerHTTPRequest") = 1 But it doesn't work. "ClientProperty("ServerHTTPRequest")" should return a COM property that I should be able to get or set. I know that for simpler problem the work around is: obj.SetSomeProperty(123) print obj.SomeProperty( The problem is that I get the property by a function call, and win32com converts it directly to the value: print obj.ClientProperty("ServerHTTPRequest") >>> print type(obj.ClientProperty("ServerHTTPRequest")) If you have any idea... Fabien From theller at python.net Thu Aug 7 08:46:24 2003 From: theller at python.net (Thomas Heller) Date: Thu, 07 Aug 2003 14:46:24 +0200 Subject: crossplatform py2exe - would it be useful? References: Message-ID: Alex Martelli writes: > Oren Tirosh wrote: > >> On Wed, Aug 06, 2003 at 08:36:20PM +0200, Thomas Heller wrote: >>> I'm currently working on a new version of py2exe, which will require >>> Python 2.3 and later, because it uses the zipimport mechanism. >> >> Now that zipimport is part of Python the code required for bootstrapping >> a py2exe runtime is just: >> >> myscript -c "import sys; sys.path.insert(0, sys.executable); import foo" >> >> This reduces the difference between the custom interpreter supplied with >> py2exe and the standard interpreter to just a few lines of C. >> >> The obvious question is - why not go all the way and put this little >> hook into the standard Python distribution? This way py2exe could be a >> platform-independent pure Python application. In fact, py2exe wouldn't >> actually be necessary because anyone could create a zip file manually and >> append it to the executable but it's more convenient to have a tool that >> automates the process and finds the required dependencies. > > Sounds like a good idea to me, if a sensible name is chosen for the > "main module" (I propose 'main':-). My choice would have been __main__ :-) Is it really the correct way to 'import __main__' instead of 'running' it? > Take it to Python-Dev...? I even wonder if it's unobtrusive enough to > be considered (as a "bugfix"...:-) for 2.3.1, rather than having to > get into 2.4 and thus wait a LONG time... > > > Alex Thomas From rwgk at yahoo.com Fri Aug 8 19:59:48 2003 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: 8 Aug 2003 16:59:48 -0700 Subject: Computational Scientist Position Message-ID: <8be7693c.0308081559.3327b0d4@posting.google.com> Computational Scientist Requisition Number: 016273 Division: Physical Biosciences Date Opened: 07/24/2003 DUTIES: Essential -- Working as a member of a group at the fore-front of high-throughput structural biology software development, this computational scientist appointment has primary responsibility for the development of a new software package called SPARX for high-throughput electron microscopy single particle image reconstruction. This will entail developing features in the PHENIX graphical user environment to enhance support for single particle image reconstruction algorithms written in C++, and implementing job-level parallelism combined with task management within the PHENIX framework. The work will be carried out as part of a collaboration with leaders in the field of single particle image reconstruction, high-performance computing, and applied mathematics. There will be a close interaction with researchers at Baylor College of Medicine, Houston to incorporate the algorithms from the EMAN package into the PHENIX environment. The resulting SPARX software will be distributed to the electron microscopy community. QUALIFICATIONS: Essential -- Demonstrated high-level skills, knowledge and work experience in computational structural biology, chemistry, physics, mathematics, or computer science, in particular the development of code for scientific applications. Must have high analytical skill and programming skill (language unspecified but prefer C++, or similar object oriented language), familiarity with tools such as Python and CVS. Experience in the development of graphical user interfaces and/or the practical implementation of parallel programming paradigms. Ability to creatively work with problems in software design and implementation. Effective interpersonal, verbal and written communication skills with the ability to accomplish goals as a team member working collaboratively with programmers, engineers, post-docs, graduate students, and undergraduates from multiple backgrounds. Must have the ability to handle multiple projects and tasks in parallel and meet programmatic milestones and project timelines. To apply: visit http://cjo.lbl.gov/ and search for the keyword PHENIX or the job number 016273. Please see http://cjo.lbl.gov/app_instr.html for details of how to apply. From mpeuser at web.de Wed Aug 13 08:12:14 2003 From: mpeuser at web.de (Michael Peuser) Date: Wed, 13 Aug 2003 14:12:14 +0200 Subject: Scanning through Directory References: <84fc4588.0308130217.4e64c3a@posting.google.com> Message-ID: Hi Anand, os.path.walk is just a conveniance function around listdir, although a *very* conveniant one where you can write scanning programs quite readable. The timing on Windows 2000 is somewhat complicated, as there seems to be some OS internal caching, so effective reading of the drive is somtimes suppressed. Even the drive internal cache might influence the situation: I can give you the following benchmark: 40 GB 2'' Laptop disk, 8 GB in 120.000 files win32.FindFiles: initial: 43 s follow-up: 3,5s walk or listdir: initial: 85 s follow-up: 42 s This means that in one-shot cases the speed-up (2x) does not look so tremendeous, it will increase with faster disks (and decrease with faster processors) However, the potential speed-up in repeated situations is tremendious. My initial question, how this could be possible is still valid, because the implementation of listdir will use the API function FindFiles eventually.... Kindly Michael P "Anand Pillai" schrieb im Newsbeitrag news:84fc4588.0308130217.4e64c3a at posting.google.com... > Did you try os.path.walk() in your experiments? > If you did, you could post the profile data for it too. > I find it one of the most useful functions defined in > the os.path module. > > Thanks! > > Anand > > "Michael Peuser" wrote in message news:... > > There is a portable way of reading directories > > os.listdir > > in conjunction with > > os.stat and a little help from os.path.split and os.path.join > > Though using os.stat gives programs a somewhat clumbsy look, > > I had not been too annoyed with it until I tried to scan a whole disk. > > Reworking the join and split operations already gave a considerable > > speed-up > > > > As I need it for Windows I then with very little effort changed to: > > win32api.FindFiles > > (I already had used win32api.GetDiskFreeSpace) > > > > This was a breakthrough: 5 secs instead of 50+ ! > > > > os.listdir seems to do little more than win32api FindFiles > > How can it be so slow??? > > Why is there no portable way of getting "DiskFreeSpace" info > > Questions and Questions.... > > > > I strongly recommend the win32api calls it you have similar applications. > > The interface is extremely simple and the only penalty is non-compatibility > > ;-) > > > > I also recommend to use the Python profiler from time to time for programms > > running more than one second. It might give you interesting insights... > > > > Kindly > > Michael Peuser From s0199583 at sms.ed.ac.uk Tue Aug 12 04:38:11 2003 From: s0199583 at sms.ed.ac.uk (Matt Smith) Date: 12 Aug 2003 01:38:11 -0700 Subject: Importerror no module named WIN32API References: <5f5c82ec.0308110740.550d5f43@posting.google.com> Message-ID: <5f5c82ec.0308120038.20c6f70d@posting.google.com> Joe Francia wrote in message news:... > Matt Smith wrote: > > > hi all, again.... > > > > having another problem with python COMs, I run a python script on a > > win2000 machine, that uses win32com.client and it runs perfectly, > > whereas when I come to run it on a win98 machine (the machine that the > > code, when completed, will be running from in the future) it returns > > the error: > > > > Traceback (most recent call last): > > File "firsttry.py", line 1, in ? > > import helloworld > > File "G:\msmith\python\helloworld.py", line 2, in ? > > import win32com > > File "C:\PYTHON23\lib\site-packages\win32com\__init__.py", line 5, > > in ? > > import win32api, sys > > ImportError: No module named win32api > > > > Any clues as to how to rectify this problem would be greatly > > appreciated > > > > cheers, > > matt. > > Maybe you need to install the win32all extensions on the Win98 machine? > http://starship.python.net/crew/mhammond/ > > jf jf was that supposed to be funny ? no i would like a serious answer to this problem, as it is seriously hampering my current project. cheers, matt From adalke at mindspring.com Wed Aug 20 04:17:12 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Wed, 20 Aug 2003 08:17:12 GMT Subject: Float + min/max? References: Message-ID: Shu-Hsien Sheu: > I am new to Python, and just wrote a small program to generate the maximum > number of the cartisian coordinates among all atoms in a given molecule. Have you looked at tools like MMTK, PyMol, VMD, Biopython, and OEChem? All of those have Python APIs for dealing with molecules with 3D coordinates. > x = [] > for i in (0, length-2): > slines[i] = lines[i].split() > if slines[i][0] == "ATOM": > x.append(slines[i][6]) I so desparately hope you aren't parsing PDB files with this code. It will break, and break silently, because the format definition is column oriented and might not have spaces between the fields, so you'll include the beta or occupancy fields in your code. Those are also floats, so no error will be raised. > The original data file apparantly does not have those decimals. May I ask > how does it happend? Thank! As for that, take Terry's suggestion and read the FAQ. Then look at some of the existing tools to see if they meet your needs. If they don't, look again - you've probably missed it. If they still don't, dig up old posts on parsing the PDB files and all the dangers you might run into, then look for old posts from me, and from Gert Vriend (of WHATIF fame) and from others on all the problems you will run into. Andrew dalke at dalkescientific.com From cben at tx.technion.ac.il Sun Aug 3 05:36:21 2003 From: cben at tx.technion.ac.il (Beni Cherniavsky) Date: 3 Aug 2003 02:36:21 -0700 Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> Message-ID: anthony_barker at hotmail.com (Anthony_Barker) wrote: > What to you think python largest compromises are? > As everybody said, whitespace, dynamic typing and interpretedness are not compromises. One real compromise is the fact that you can't rebind an outer variable from a closure. That allows lexical scoping without any variable declrations at the price of giving up a useful ability of closures. When you do want it, you must either use the singleton list hack (but charactertistically, it isn't used even once in the standard library - I once performed an almost reliable search), or turn your nested function into a class just for that, which is annoying (see Java ). It's noty impossible to fix, it will just require some sort of "declration" (per assignment, per variable per function (like ``global``) or per function) for the cases when you want this). From tzot at sil-tec.gr Fri Aug 22 21:11:40 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Sat, 23 Aug 2003 04:11:40 +0300 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: <3F412484.69867AED@alcyone.com> Message-ID: On Sat, 23 Aug 2003 03:34:02 +0300, I said: >Ten Years track and I meant Ten Years AFTER. -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From raims at dot.com Wed Aug 20 17:34:50 2003 From: raims at dot.com (Lawrence Oluyede) Date: Wed, 20 Aug 2003 23:34:50 +0200 Subject: Python: executing ping and whois References: <538fc8e.0308201303.46c58c8b@posting.google.com> Message-ID: WIWA wrote: > I want > to use the existing Linux commands if possible. Checkout os.system or (better) os.popen* functions -- Lawrence "Rhymes" Oluyede http://loluyede.blogspot.com rhymes at NOSPAMmyself.com From abelikov72 at hotmail.com Fri Aug 29 13:42:18 2003 From: abelikov72 at hotmail.com (Afanasiy) Date: Fri, 29 Aug 2003 17:42:18 GMT Subject: Add two dicts References: <86ktkvkd05e88hu14hjudmfvbul7slfgkt@4ax.com> <3F4EDF7A.C9CF6DA3@alcyone.com> <0mrtkv8b1bnnk1v310kf3b8tmjo8d9higo@4ax.com> Message-ID: On Fri, 29 Aug 2003 08:40:01 GMT, Alex Martelli wrote: >Afanasiy wrote: > >> On Thu, 28 Aug 2003 22:07:06 -0700, Erik Max Francis >> wrote: >> >>>Afanasiy wrote: >>> >>>> Can I add two dicts in a way which is not cumbersome to the above % >>>> string >>>> operation? Is this another case of writing my own function, or does a >>>> builtin (or similar) already exist for this? >>> >>>combinedDict = aDict.copy() >>>combinedDict.update(anotherDict) >>> >>>If that's cumbersome, don't really know what you'd consider >>>non-cumbersome. >> >> Don't really know if you're asking, but : >> >> vars(self)+{'x':'123','y':'345'} >> >> I would consider that non-cumbersome. ;-) > >[snipped alex code] > >and now, dad(vars(self), x='123', y='345') -- ain't that even >LESS cumbersome? You can't do that with the syntax of + (no >keyword arguments) Since you asked... To me, this clouds the issue and developers using dad() may not actually be aware they are adding dictionaries. Any function you write is fine for your own use of course. I would just simply prefer {}+{}. I know I can write a function to add them and call that. Thank you. From ge.net at wanadoo.fr Fri Aug 1 11:30:13 2003 From: ge.net at wanadoo.fr (GE) Date: Fri, 1 Aug 2003 17:30:13 +0200 Subject: PB with Python ActiveX Scripting Engine registration (Python 2.2.3/2.3) Message-ID: I execute the Python program win32com\axscript\client\pyscript_rexec.py and the engine is successfully registered But the python engine isn't active in IE (tested with demo.htm, even after a reboot) I did not have probleme with Python 2.1 and win32all-151 The path of win32com have changed ( now in python 2.2 we have the directory "site-packages" in more) is-it a way??? Thanks for your help PS/ Same probleme with W2K and XP From geoff at gerrietts.net Thu Aug 28 16:57:30 2003 From: geoff at gerrietts.net (Geoff Gerrietts) Date: Thu, 28 Aug 2003 13:57:30 -0700 Subject: OT: Americans love their guns In-Reply-To: References: Message-ID: <20030828205730.GD18211@thoth.homegain.com> Quoting maxx at easynews.com (maxx at easynews.com): > On Thu, 28 Aug 2003 02:12:34 -0400, Lulu of the Lotus-Eaters > wrote: > > >USA gun-related deaths are ~29k/year > > And my probability of being one of them is pretty low - because I am usually > armed ;) I think (though I don't know), from self-defense courses run by police a long, long time ago at a university far, far away, that your statement alone actually /elevates/ the probability that you will be one of them. To /lower/ the probability, you'll need to talk about the time you've spent on a tactical course or in police training. -- Geoff Gerrietts "That's it! I've had it with your sassy mouth! I didn't want to do this! (Well, actually, http://www.gerrietts.net/ I did....)" -- Mojo Jojo, "Bubblevicious" From adalke at mindspring.com Tue Aug 19 19:17:49 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Tue, 19 Aug 2003 23:17:49 GMT Subject: 2 funny Py2.3 Issues: 'datetime', string.join() References: <3F42AB3D.F9B456F4@yahoo.com> Message-ID: Rami A. Kishek: > string. However, wouldn't it make more sense if the "join" mehtod > actually belonged to the List object, since it primarily operates on > lists? http://www.python.org/cgi-bin/faqw.py?req=show&file=faq04.096.htp > 2) I had a difficult time trying to subclass the new datetime.date > class. I basically had written something similar for my own > applications, and now want to convert my class to take advantage of the > 'datetime.date' class. See the documentation for __new__ >>> class MyDT(datetime.datetime): ... def __new__(cls, year, month = None, day = None): ... if isinstance(year, tuple): ... year, month, day = year ... return datetime.datetime(year, month, day) ... >>> MyDT( (2003, 8, 19) ) datetime.datetime(2003, 8, 19, 0, 0) >>> You'll need to use __new__ for any immutable object. Andrew dalke at dalkescientific.com From mal at lemburg.com Fri Aug 1 03:33:13 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri, 01 Aug 2003 09:33:13 +0200 Subject: Problem with inserting dates using mx.ODBC.Windows driver In-Reply-To: <1059669056.14359@news-ext.oce.nl> References: <1059669056.14359@news-ext.oce.nl> Message-ID: <3F2A17B9.5020704@lemburg.com> Fons Dijkstra wrote: > Hello, > > I'm using the mx.ODBC.Windows package in order to read/write a MSAccess > database. Everything works fine apart from the DATE format handling. I'm > using the default "datetimeformat" (i.e. DATETIME_DATETIMEFORMAT) as > suggested. The date columns in the MSAccess database have "Short Date" > format. > > When I read a DATE item everything works fine, like: > > >>>>conn = mx.ODBC.Windows.connect(database) >>>>cursor = conn.cursor() >>>>cursor.execute("SELECT * FROM table") >>>>data = cursor.fetchall() >>>>print data > > [(..., , ...)] > > But when I try to update the table I get a ProgrammingError, like: > > >>>>date = mx.ODBC.Windows.Date(2003, 07, 31) >>>>conn = mx.ODBC.Windows.connect(database) >>>>cursor = conn.cursor() >>>>cursor.execute("INSERT INTO table (..., DATE, ...) VALUES (..., ?, > > ...)", (..., date, ...)) > ProgrammingError: Syntax Error in INSERT INTO statement. > > Is it possible to use the mx.DateTime type for MSAccess databases? If so, > how should it be done? If not, how can I insert dates into a MSAccess > database? That's strange: if you pass in an mxDateTime value as bound parameter to .execute() then underlying ODBC driver will take care of converting it to the format needed by the database. If that fails for MS Access, then something in their driver must be broken or the driver is requesting the date value as string which it really shouldn't. As work-around you could convert the mxDateTime value to a string in the needed format and pass the string instead of the original value. > Thank you in advance, Fons -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 01 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From syver-en+usenet at online.no Sat Aug 2 16:38:32 2003 From: syver-en+usenet at online.no (Syver Enstad) Date: 02 Aug 2003 22:38:32 +0200 Subject: Python debugger References: Message-ID: Dave Kuhlman writes: > Andrew Chalk wrote: > > > I am sure that it has been asked before but could someone tell a > > newbie whether there is a Python debugger out there? > > > > See: > > http://www.python.org/doc/current/lib/module-pdb.html And in case you don't like using a commandline debugger, you can use pythonwin's debugger or Emacs together with pdb. -- Syver Enstad From jmiller at stsci.edu Mon Aug 4 14:16:37 2003 From: jmiller at stsci.edu (Todd Miller) Date: Mon, 04 Aug 2003 14:16:37 -0400 Subject: better way to do this in Numeric References: Message-ID: <3F2EA305.10109@stsci.edu> John Hunter wrote: > I have a list of indices and want to assign the number of times an > index shows up in the list to an array with the count specified at the > index; ie, > > from Numeric import * > > a = zeros((10,), Int) > ind = [1,1,4,4,4,4,7,7,9,9,9,9,9] > > for i in ind: > a[i] += 1 > > I'm wondering if there is a way to use some combination of Numeric > array functions to make this speedy. > > Thanks, > John Hunter > There's a simple histogram function defined in the Numeric manual, based on the searchsorted function. >>> def histogram(a, bins): ... n = searchsorted(sort(a), bins) ... n = concatenate([n, [len(a)]]) ... return n[1:]-n[:-1] If you set bins: >>> bins = arange(0.5,10.5,1) I think it does what you want: >>> ind = [1,1,4,4,4,4,7,7,9,9,9,9,9] >>> histogram(ind, bins) array([0, 0, 2, 0, 0, 4, 0, 0, 2, 0, 5]) In numarray CVS, histogram improves performance by a factor of ~7x versus the 2 lines of code you defined the problem with. (I tried this with test cases of 10**5 and 10**6 elements.) Sadly, Numeric has much slower sort functions than numarray so histogram winds up being a net loss of ~2x. I think you probably need an extension function to get really good performance. Todd From ialbert at mailblocks.com Mon Aug 18 15:50:21 2003 From: ialbert at mailblocks.com (Istvan Albert) Date: Mon, 18 Aug 2003 15:50:21 -0400 Subject: What's TOTALLY COMPELLING about Ruby over Python? In-Reply-To: <3F412484.69867AED@alcyone.com> References: <3F412484.69867AED@alcyone.com> Message-ID: Erik Max Francis wrote: >>What's ***TOTALLY COMPELLING*** about Ruby over Python? > > comp.lang.ruby doesn't have Brandon Van Every. LOL Istvan. From peter at engcorp.com Thu Aug 14 12:35:42 2003 From: peter at engcorp.com (Peter Hansen) Date: Thu, 14 Aug 2003 12:35:42 -0400 Subject: Is Python your only programming language? References: Message-ID: <3F3BBA5E.1A8993A0@engcorp.com> Terry Reedy wrote: > > "Richard Brodie" wrote in message > news:bhg9nc$161k at newton.cc.rl.ac.uk... > > The full text of the [Ariane 5 failure]report is on the web, and > should be required > > reading: > > http://www.mssl.ucl.ac.uk/www_plasma/missions/cluster/about_cluster/cluster1/ariane5rep.html > > Having just read this, I second the suggestion. What the report hints > at is that the 'root' cause of the failure was pride leading to > complacency -- a trap most anyone can fall into -- and one which one > language can completely protect against. Which one? Ah, perhaps you meant the "language of humility"? ;-) Or maybe you meant "one which *no* language can completely protect against". :) -Peter From gh at ghaering.de Sat Aug 16 09:43:10 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Sat, 16 Aug 2003 15:43:10 +0200 Subject: detecting -addition, deletion or change to files In-Reply-To: References: Message-ID: <3F3E34EE.9060701@ghaering.de> jeff wrote: > Hiya > > I just woundering how would I go about detecting addition, deletion or > change to files in a folder? [...] FAM is designed for this purpose. Here's the Python wrapper for it: http://python-fam.sourceforge.net/ -- Gerhard From ta-meyer at ihug.co.nz Mon Aug 11 00:40:44 2003 From: ta-meyer at ihug.co.nz (Tony Meyer) Date: Mon, 11 Aug 2003 16:40:44 +1200 Subject: Spell Checker In-Reply-To: <1ED4ECF91CDED24C8D012BCF2B034F1302BB810D@its-xchg4.massey.ac.nz> Message-ID: <1ED4ECF91CDED24C8D012BCF2B034F13026F286F@its-xchg4.massey.ac.nz> > > http://sourceforge.net/projects/pyspelling/ > > This one doesn't have too much to offer... According to SF: > "this project did not release any files" and its state is "pre-alpha". Check again - it's now alpha and has a release (9th August). =Tony Meyer From mertz at gnosis.cx Thu Aug 14 21:53:03 2003 From: mertz at gnosis.cx (David Mertz) Date: Thu, 14 Aug 2003 21:53:03 -0400 Subject: Py2.3: Feedback on Sets References: Message-ID: > * Is there a compelling need for additional set methods like > Set.powerset() and Set.isdisjoint(s) or are the current > offerings sufficient? I confess that I have not used sets for anything beyond testing. I love the concept, but I just haven't had the need yet (especially in something where I want to require 2.3). The mention of Set.powerset() above is quite interesting to me. It feels both exciting and dangerous :-). As we all know, the size of the powerset of S, for len(S)==N, is 2**N. Seems like it would be really easy to run into some long runtimes and memory usage. Then again, power set really is a fundamental operation on sets. And making users rewrite it each time is error prone. So I think I would advocate it, but with a fairly harsh warning in the documentation about complexity issues. Yours, David... -- mertz@ | The specter of free information is haunting the `Net! All the gnosis | powers of IP- and crypto-tyranny have entered into an unholy .cx | alliance...ideas have nothing to lose but their chains. Unite | against "intellectual property" and anti-privacy regimes! ------------------------------------------------------------------------- X-Shameless-Plug: Buy Text Processing in Python: http://tinyurl.com/jskh From elainejackson7355 at home.com Sun Aug 17 19:35:43 2003 From: elainejackson7355 at home.com (Elaine Jackson) Date: Sun, 17 Aug 2003 23:35:43 GMT Subject: bitwise not - not what I expected References: <1YD%a.747879$3C2.17342633@news3.calgary.shaw.ca> Message-ID: In case any fellow newbies have been following this thread, here is the finished Nim script. It doesn't use bit-manipulation as much as I thought it would. (Still, I got the basics straight. Thanks again to everyone who helped out!) For a readable account of the optimal strategy for Nim, see Hardy & Wright's "Introduction to the Theory of Numbers". Peace. ## NIM from random import random piles=[0,0,0] ######################################## def take(n,pileNum): if piles[pileNum]>=n: piles[pileNum]=piles[pileNum]-n print piles else: print "illegal move" ######################################## def newGame(): for i in range(3): piles[i]=int(9*random())+1 print piles ######################################## def indexOfMax(): returnValue=0 for i in range(1,3): if piles[i]>piles[returnValue]: returnValue=i return returnValue ######################################## def leftmostBitIndex(n): if 0n: return (i-1) else: raise ######################################## def yourMove(): magicNum=piles[0]^piles[1]^piles[2] if magicNum==0: i=indexOfMax() piles[i]=piles[i]-1 else: magicIndex=leftmostBitIndex(magicNum) targetIndex=(-1) for i in range(3): if (piles[i]>>magicIndex)%2==1: targetNum=piles[i] targetIndex=i break replacement=0 for i in range(magicIndex): magicDigit=(magicNum>>i)%2 targetDigit=(piles[targetIndex]>>i)%2 if magicDigit==1: replacementDigit=(magicDigit-targetDigit) else: replacementDigit=targetDigit replacement=replacement+replacementDigit*pow(2,i) newNum=targetNum-(targetNum%pow(2,magicIndex+1))+replacement piles[targetIndex]=newNum print piles ############ not used in this script: def matilda(n): if 0<=n Message-ID: At some point, Simon Burton wrote: > Looks like the pyrex guy uses emacs... > > Anyone have any hints/ideas/scripts for getting some vim syntax colors for > pyrex ? Add this to your .vimrc: if !exists("autocommands_loaded") let autocommands_loaded=1 augroup filetypedetect au! BufRead,BufNewFile *.pyx setfiletype python augroup END endif That'll use the python syntax for pyrex files. -- |>|\/|< /--------------------------------------------------------------------------\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca From mertz at gnosis.cx Sat Aug 23 23:50:58 2003 From: mertz at gnosis.cx (David Mertz) Date: Sat, 23 Aug 2003 23:50:58 -0400 Subject: Metaclass discussons References: Message-ID: Gustavo Niemeyer wrote previously: |Can you imagine any alternative which is not based on the same concept |(executing the module code on a hacked context)? In Gnosis Utilities, the function gnosis.magic.import_with_metaclass() does basically the same thing, but a bit more neatly packaged up. You might give that a try for imposing metaclasses on older code. Michele Simionato has proposed some enhancements to resolve issues of metatype conflicts, but I haven't quite decided to bundle them up in Gnosis, since that add quite a bit of complication that is not needed 95% of the time. But one day, I suppose I will. However, he has posted the same general concepts to ActiveState's Python Cookbook; and the article by my Michele and I that discusses some of this should FINALLY appear at IBM developerWorks this week (we wrote it quite some months ago; and it's been available on my website for some of the interim). Yours, David... -- Keeping medicines from the bloodstreams of the sick; food from the bellies of the hungry; books from the hands of the uneducated; technology from the underdeveloped; and putting advocates of freedom in prisons. Intellectual property is to the 21st century what the slave trade was to the 16th. -- X-Shameless-Plug: Buy Text Processing in Python: http://tinyurl.com/jskh From donn at drizzle.com Sun Aug 17 12:51:27 2003 From: donn at drizzle.com (Donn Cave) Date: Sun, 17 Aug 2003 16:51:27 -0000 Subject: os.system stdout redirection [to PyQt window] References: Message-ID: <1061139086.812238@yasure> Quoth mackstann : | On Sun, Aug 17, 2003 at 01:01:41AM -0500, Terry Gray wrote: |> Using Python 2.2 in Debian linuxI am trying to change to a different |> directory, execute a 'make all' command, and redirect the output of the |> subshell to a PyQt window... I should be able to execute the |> os.system('cd newdirectory; make all'), but how do I redirect stdout of |> the new subshell created by the os.system call? | You can use os.popen (popen2 and 3 as well), or the popen2 module's | Popen3 and 4 classes, or commands.getoutput (and there are probably even | more ways :). Yes, very good, there are many ways to redirect output, but you need to know how to make PyQt monitor a file and copy it to a window before it matters much either way. I don't know, so I've changed the subject line, replacing the elipsis ("..." - what was that for?) with [to PyQt window] to attract the attention of someone who might have a clue. Do you need to write this output line by line as it comes out of make? Or would it be fine to run make, and then wait to present all the output after it's finished? The latter is likely to be significantly easier. # make output goes to both units 1 and 2 (output and error/diagnostic) os.system('cd newdirectory; make all > make.log 2>&1') displayfile('newdirectory/make.log') Donn Cave, donn at drizzle.com From gerrit at nl.linux.org Thu Aug 28 01:39:23 2003 From: gerrit at nl.linux.org (Gerrit Holl) Date: Thu, 28 Aug 2003 07:39:23 +0200 Subject: OT: Celebrity advice (was: Advice to a Junior in High School?) In-Reply-To: <5.2.1.1.0.20030827154824.044e9dc0@66.28.54.253> References: <3F4D0D8B.5E5F9488@engcorp.com> <3F4D0D8B.5E5F9488@engcorp.com> <5.2.1.1.0.20030827154824.044e9dc0@66.28.54.253> Message-ID: <20030828053923.GA2515@nl.linux.org> Bob Gailer wrote: > At 10:12 PM 8/27/2003 +0200, Gerrit Holl wrote: > >[snip] > > OK; I'll bite. Why do you quote from Hammurabi, Code of Law? Heh; it is always in my signature. It has absolutely nothing to do with this discussion; I don't even notice what's in it exactly... Gerrit. -- 263. If he kill the cattle or sheep that were given to him, he shall compensate the owner with cattle for cattle and sheep for sheep. -- 1780 BC, Hammurabi, Code of Law -- Asperger Syndroom - een persoonlijke benadering: http://people.nl.linux.org/~gerrit/ Het zijn tijden om je zelf met politiek te bemoeien: http://www.sp.nl/ From ialbert at mailblocks.com Tue Aug 12 12:24:40 2003 From: ialbert at mailblocks.com (Istvan Albert) Date: Tue, 12 Aug 2003 12:24:40 -0400 Subject: Py2.3: Feedback on Sets In-Reply-To: References: Message-ID: Raymond Hettinger wrote: First of all, thanks for the work on it, I need to use sets in my work all the time. I had written my own (simplistic) implementation but that adds another layer of headaches when distributing programs since then I have to distribute multiple modules. Sometimes I ended up with a little set function in every big module. Pretty silly. For me sets are a greatly useful addition. > * Is the support for sets of sets necessary for your work > and, if so, then is the implementation sufficiently > powerful? One pattern that I constantly need is to remove duplicates from a sequence. I don't know if this an often enough used pattern to warrant an API change, for me it would be most useful if I could get the contents of a set as a sequence right away, without having to explicitly code it. > * Are you overjoyed/outraged by the choice of | and & as > set operators (instead of + and *)? I think that since you have have - as a difference operator it would make sense to also have + as a union operator. Takes nothing away from |. The & operator is the right one, * would not be appropriate IMO. > * Do you care that sets can only contain hashable elements? I don't really care, on the other hand, it might be better to call the class HashSet, so that it conveys right away that it uses hashing to store the elements. > * Are the docs clear? Can you suggest improvements? I wondered whether it would be better to specify the immutability of the class at the constructor level. Then there is the update method. It feels a little bit redundant since there is an add() method that seems to be doing the same thing only that add() adds only one element at a time. Would it be possible to have add() handle all additions, iterable or not, then scrap update() altogether. Then just by looking at the docs, it feels a little bit confusing to have discard() and remove() do essentially the same thing but only one of them raising an exception. Which one? I already forgot. I don't know which one I would prefer though. Another aspect that I did not understand, what is difference between update() and union_update(). The long winded method names, such as difference_update() also feel redundant when one can achieve the same thing with the -= operator. I would drop these and instead show in the docs how to accomplish these with the operators. Would considerably cut down on the documentation, and apparent complexity. I'm a big fan of having the minimal number of methods as long it is easy to obtain the result. For example methods like x.issubset(y) is the same as bool(x-y) so may not be all that necessary, just a thought. > * Are sets helpful in your daily work or does the need arise > only rarely? I use them very often and they are extremely useful. thanks again, Istvan. From nav+posts at bandersnatch.org Thu Aug 14 09:47:52 2003 From: nav+posts at bandersnatch.org (Nick Vargish) Date: 14 Aug 2003 09:47:52 -0400 Subject: 3 new slogans References: Message-ID: Graham Fawcett writes: > or, with apologies to Clarke, > > Any sufficiently advanced technology is indistinguishable from Python I'd wear that on a T-shirt. Or, with apologies to Sturgeon: 90% of code is crud The rest is Python Nick -- # sigmask || 0.2 || 20030107 || public domain || feed this to a python print reduce(lambda x,y:x+chr(ord(y)-1),' Ojdl!Wbshjti!=obwAcboefstobudi/psh?') From aleax at aleax.it Thu Aug 21 04:50:30 2003 From: aleax at aleax.it (Alex Martelli) Date: Thu, 21 Aug 2003 08:50:30 GMT Subject: how fast is Python? References: <3f43e5cf$0$49115$e4fe514c@news.xs4all.nl> <3f447f49$0$49116$e4fe514c@news.xs4all.nl> Message-ID: Irmen de Jong wrote: ... > Nevertheless, a Psyco-optimized piece of Python code > that runs as fast as compiled C is still very impressive > to me. I know that JIT compiler technology theoretically > could produce better optimized code than a static optimizing > compiler, but am happy already if it reaches equal level :-) If anybody does have an actual example (idealy toy-sized:-) where psyco's JIT does make repeatably faster code than a C compiler (well-used, e.g. -O3 for gcc, NOT just -O...!-) I'd be overjoyed to see it, by the way. Alex From jzgoda at gazeta.usun.pl Tue Aug 19 14:33:31 2003 From: jzgoda at gazeta.usun.pl (Jarek Zgoda) Date: Tue, 19 Aug 2003 18:33:31 +0000 (UTC) Subject: What's TOTALLY COMPELLING about Ruby over Python? References: <3F412484.69867AED@alcyone.com> <3f415560$0$1124$626a54ce@news.free.fr> <3f4216a3$0$16514$626a54ce@news.free.fr> Message-ID: Bruno Desthuilliers pisze: >> I am not a clp regular (mostly a lurker), but I also wanna play. *please* >> >> ;-). >> > Easy : answer to any post from Brandon, singing 'Brandon is a troll, is > a troll, is a troll' !-) Ugh, I cann't... I cann't see his posts, I accidentally pressed 'k' while reading some of his writings, than accidentally few times pressed "Enter" followed by "y" key -- of course by accident... -- Jarek Zgoda Registered Linux User #-1 http://www.zgoda.biz/ JID:zgoda at chrome.pl http://zgoda.jogger.pl/ From news at yebu.de Fri Aug 1 04:40:04 2003 From: news at yebu.de (Karl Scalet) Date: Fri, 01 Aug 2003 10:40:04 +0200 Subject: Secure FTP in Python? In-Reply-To: References: Message-ID: Cameron Laird schrieb: > In article , > Kyler Laird wrote: > >>"d z e k y l" writes: >> >> >>>Or is there some other >>>(noncomplicated) way how secure uploading can be implemented in Python? >> >>About anything is less needlessly complicated than FTP. >>SSH is often the obvious choice, but WebDAV can also >>run over SSL. >> >>--kyler > > > rsync, in particular, is a good fit for what many people > mean by "uploading", and rsync is ssh-savvy. or, on top of rsync-libs, you can run duplicity. Written in Python :-) and does encryption also of the backup-store using GPG. Interesting especially if other people have root access on the backup-server. The transfer intself can be done in plain ftp or ssh/scp. http://www.nongnu.org/duplicity/ Maybe too far from what OP actually is interested in. Karl From sross at connectmail.carleton.ca Sat Aug 30 01:20:39 2003 From: sross at connectmail.carleton.ca (Sean Ross) Date: Sat, 30 Aug 2003 01:20:39 -0400 Subject: My script is taking 12 hours+ any suggestions? References: <3f4ff9f8$0$23588$5a62ac22@freenews.iinet.net.au> Message-ID: <0uW3b.4392$_F1.665478@news20.bellglobal.com> Hi. First, it might be helpful to see a sample of the contents of the file your pulling your information from. What do the lines look like? What information do they contain? Does each line contain the same type of information? What are the parts of the information contained in each line, and how do they relate to the problem you're trying to solve? How many 'verts' (vertices?) are there? Describe the algorithm your applying in english. What are the steps you're taking in order to solve this problem? They are not apparent from this code. Can you not use some functions to break this mass of code into manageable chunks? To be honest, I have no idea what your code is trying to do. You say it does this: "Ideasman" wrote in message news:3f4ff9f8$0$23588$5a62ac22 at freenews.iinet.net.au... > Hi I have a made a script that process normals for a flat shaded 3D mesh's. > It compares every vert with every other vert to look for verts that can > share normals and It takes ages. OK. I'm going to assume that each line in the file represents the information relevant to one 'vert' (whatever that is). So, I would suggest, going through the file, one line at a time, constructing a list of vert objects, which hold this information. Something like: fd = file(filename) verts = [Vert(*line.split()) for line in fd] fd.close() where Vert() is a constructor for the class Vert: class Vert(object): def __init__(self, what, ever, information, will , be, split, from, the, line): self.what = what ... def share_normals(self, other): "returns True when self and other can share normals" ... ... So, now you have a list of Verts. If you don't have the 'normals' for these Verts from the file, and have to calculate them, add a 'normalize(self)' method to the Vert class, and call that inside __init__() at the appropriate time. So, now we have a list of normalized Verts. And we want to compare every Vert to each other to look for Verts that can share normals. OK. Suppose verts = [v0, v1, v2, v3] # where v0, v1, v2, v3 are all Vert instances. We want to see if v0 can share normals with v1, v2, and/or v3; and if v1 can share normals with v0, v2, and/or v3; and so on. If I check v0.share_normals(v1), do I need to check v1.share_normals(v0)? Probably not. But then again, I haven't a clue what I'm talking about :) Assuming I'm correct, and we don't need to check v1.share_normals(v0), then we should probably keep a record. I'll assume that a vert can share a normal with itself, so we don't need to keep a record for that. I suggest making a jagged array. Call it 'SHARED'. Build it as follows: SHARED = [[vert.share_normal(other) for other in verts[i+1:]] for i, vert in enumerate(verts[:-1])] And, when we're done, 'SHARED' is a jagged array filled with zeroes and ones, something like this: 0 1 2 3 0 - [[1, 0, 1], 1 - - [ 0, 1], 2 - - - [0]] 3 - - - - # verts indices are listed on the outside of the table SHARED == [ [1, 0, 1], [0, 1], [0] ] then we make a function like: def is_shared(index1, index2): if index1 == index2: return True # a vert shares a normal with itself # adjust for jagged list indexing if index1 > index2: index1, index2 = index2, index1 index2 -= index1 + 1 return SHARED[index1][index2] so we can use it to ask, later, if v0, and v3 share normals by using 'is_shared(0,3)' or 'is_shared(3,0)' # SHARED[0][2] == True and then we can do whatever action is appropriate using verts[0] and verts[3]. By storing this information, we avoid having to re-calculate whether v0 and v3 share normals every time we need to know that. And, by storing the information in a jagged array, we save some space. # NOTE: if v0.share_normal(v1) and v1.share_normal(v2), # then v0.share_normal(v2) must also be True. # so we could make SHARED a dictionary instead SHARED = {0: [0,1,3], # v0 shares normals with itself, v1 and v3 1: [0,1,3], 2: [2] 3: [0,1,3]} Building this dictionary may save some share_normal() calls: SHARED = {} for i, vert in enumerate(verts): SHARED[i] = [i] for j, other in enumerate(verts): if j == i: continue if vert.share_normal(other): if j < i: # the earlier vert will have accumulated all # of this verts share partners, so just use those SHARED[i] = SHARED[j] break else: SHARED[i].append(j) Then, to see whether v0.share_normal(v3), we can just ask 3 in SHARED[0] # and vice versa But, this takes up more space than the jagged list version. And the look-up is slower. What might be better is a straight partition, like this: SHARED = [[0,1,3], [2]] # I'll leave how to get this up to you... This takes up less space than each of the previous versions. How do we use it to tell whether v0.share_normal(v3) ? A new version of is_shared(index1, index2) would have to find the tuple containing index1, then see if index2 is also in that tuple. This look-up is the slowest of all! And, after all of that, I still can't say whether this has been of use for you, because I have very little understanding as to what you meant for your code to be doing. Hopefully, this was somewhat near the mark. Also, be aware that none of the code above has been tested. Good luck with what you're doing, Sean From tim.one at comcast.net Fri Aug 1 22:36:42 2003 From: tim.one at comcast.net (Tim Peters) Date: Fri, 1 Aug 2003 22:36:42 -0400 Subject: 2.3 win installer In-Reply-To: Message-ID: [Bob X] >> If you have any anti-virus going...turn it off. Oh and download it >> again. [Jarek Zgoda] > Does Python 2.3 have any known viral activity? No. The real reason is that virus scanners often interfere with the normal operation of benign programs. For whatever reason, installers seem especially vulnerable to scanner bugs. If you think your virus scanner doesn't have bugs, you've never tried to write one on Windows . From R.Brodie at rl.ac.uk Thu Aug 7 12:06:22 2003 From: R.Brodie at rl.ac.uk (Richard Brodie) Date: Thu, 7 Aug 2003 17:06:22 +0100 Subject: Extracting a short using struct - won't print. References: <3f3273f7$0$10777$afc38c87@auth.uk.news.easynet.net> <3F32758E.5734C64F@engcorp.com> <3f32779d$0$10780$afc38c87@auth.uk.news.easynet.net> Message-ID: "Graham Nicholls" wrote in message news:3f32779d$0$10780$afc38c87 at auth.uk.news.easynet.net... > >> seg_stru=">BHH" > >> seg_data=self.fhand.read(struct.calcsize(seg_stru)) > >> data=struct.unpack(seg_stru,seg_data) > >> x=seg_data[1] > >> y=seg_data[2] > > > > Why are you unpacking the struct if you aren't going to use the > > unpacked data? > > Err, I'm trying to extract two shorts - the x and y size in pixels of an > image, which I'll use to scale it to fit another pair of parameters. What > makes you think I'm not using the data? Am I not - I thought I was! You aren't using the returned value from struct.unpack() anywhere. You need something like x, y = struct.unpack(seg_stru,seg_data) From tcronj at ananzi.co.za Thu Aug 28 17:14:38 2003 From: tcronj at ananzi.co.za (Tertius) Date: Thu, 28 Aug 2003 23:14:38 +0200 Subject: opposite of dict.items() Message-ID: <3f4e708c$0$64719@hades.is.co.za> Is there a method to create a dict from a list of keys and a list of values ? TIA Tertius From skip at pobox.com Fri Aug 1 21:19:06 2003 From: skip at pobox.com (Skip Montanaro) Date: Fri, 1 Aug 2003 20:19:06 -0500 Subject: Potentially important real-time on-line discussion In-Reply-To: References: Message-ID: <16171.4490.510389.34756@montanaro.dyndns.org> Bengt> But I think open source needs a simple metaphor for politicians Bengt> and non-geeks to understand. I keep thinking that the constant security problems with Microsoft-based systems should be a wake-up call for IT departments of all large organizations and get them to start diversifying their systems. In theory, no metaphor needed. So far that hasn't happened though. Skip From jjl at pobox.com Sun Aug 3 13:43:55 2003 From: jjl at pobox.com (John J. Lee) Date: 03 Aug 2003 18:43:55 +0100 Subject: Changing base class of a big hierarchy References: <873cgjyo2u.fsf@pobox.com> Message-ID: <87el02eiw4.fsf@pobox.com> Alex Martelli writes: > John J. Lee wrote: > > > I'm trying to change a base class of a big class hierarchy. The > > hierarchy in question is 4DOM (from PyXML). 4DOM has an FtNode class > > that defines __getattr__ and __setattr__ that I need to override. [...] > OK, so you want to do two things: > -- "deep-copy" a class hierarchy H to H' > -- in the copied hierarchy H', change each occurrence in any __bases__ > of a class X' to a class Y', and any other class T that is in H to > the corresponding class T' in H' Yes. > > What's the easiest way to do that? > > I think performing these two steps in order is probably simplest. You > do have to identify every class in your starting hierarchy H, of course. > > > Maybe deep-copying the module or something, then fiddling with > > __bases__?? Or a metaclass? > > Deep copying might not help -- copy.deepcopy(X), when X is a class, > still leaves __bases__ unchanged. A custom metaclass that does :-( > bases-alteration as you require would be reasonably easy to write, > but would be more helpful than just doing the same job in a > function if, and only if, you were to re-execute every affected > 'class' statement using the new metaclass. I doubt that getting > and re-executing those class statements is simplest in this case. So I do have to fiddle with __bases__ after all, contrary to my follow-up to my OP. In fact: >>> class bar: pass >>> bar2 = copy.copy(bar) >>> bar2 is bar True >>> bar3 = copy.deepcopy(bar) >>> bar3 is bar True >>> (because the registered class-copying functions for copy and deepcopy just return the original object). I suppose I have to use new.classobj(klass.__name__, bases, klass.__dict__) > > While I'm on the subject, does anybody have code to get a list of all > > classes in a package that derive from a particular class? Or [...] > from X, so you'd filter that with issubclass); but offhand I can't > think of a handy, elegant and robust way to ensure you're walking > all over a package (including sub-packages), nor even that all of > a package (cum subpackages) is actually LOADED at this time. I That's a shame. Still, for my particular case, I think I can get a list of the relevant classes using some package-specific data, a bit of string processing and a few hard-coded cases. [...] > # seed this with the base class transformation > trans_dict = {X: transformed_X} > # recursive way to transform a class between hierarchies > def transform_class(C): > if not issubclass(C, X): > return C > if C in trans_dict: > return trans_dict(C) > bases = tuple([transform(B) for B in C.__bases__]) > newclass = type(C)('C', bases, C.__dict__) > trans_dict[C] = newclass > return newclass Thanks. That's simpler than I expected. The type(C)(...) there is equivalent to my new.classobj, I see (except you wrote 'C' when you meant C.__name__). I suppose one could then write a deepcopying function _deepcopy_cls, similar to your function (and analogous to copy._deepcopy_inst(x, memo)), and then create one's own deepcopy function essentially identical to copy.deepcopy, except that it uses _deepcopy_cls(x, memo). In my case, I think I can just use your function directly in 4DOM's HTMLDocument._4dom_createHTMLElement(self, tagName) Side issue: I wonder why new.classobj is there, given that even in 1.5.2 ClassType(name, bases, type) does exactly the same? I guess new.classobj predates ClassType. > Of course, if the classes in the hierarchy use each other in > more ways than just a base/subclass inheritance [e.g, some > classes have other classes as attributes, not just as bases] > you may need a bit more work [e.g., on C.__dict__ as well as > on C.__bases__]. Hadn't thought of that. Maybe I should write a _deepcopy_cls after all. I'll have to check whether 4DOM uses classes as attributes. [...] > to get the class-objects it uses. You may need to alter the > semantics of 'import' statements in that using-code, too, since Thankfully not, in 4DOM, since it calls the method I mentioned above to get a new Element (the implementation uses __import__). John From tzot at sil-tec.gr Mon Aug 25 03:50:07 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Mon, 25 Aug 2003 10:50:07 +0300 Subject: How to import a standard module in source file with same name? References: <420ced91.0308232052.70e905d5@posting.google.com> <420ced91.0308241013.3023de54@posting.google.com> Message-ID: <8tfjkvk2h8hf3t7f7203p4vq7jheu0ata3@4ax.com> On 24 Aug 2003 11:13:32 -0700, rumours say that sdhyok at yahoo.com (sdhyok) might have written: >As Michael indicates, the usage of different case is not a good solution. And Michael is correct, my fault for not mentioning it. -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From peter at engcorp.com Tue Aug 26 13:58:12 2003 From: peter at engcorp.com (Peter Hansen) Date: Tue, 26 Aug 2003 13:58:12 -0400 Subject: file object, details of modes and some issues. References: <3f4b800f_3@mk-nntp-1.news.uk.worldonline.com> Message-ID: <3F4B9FB4.6AB14581@engcorp.com> simon place wrote: > > 'b', all modes can have a 'b' appended to indicate binary mode, i think this > is something of a throw-back to serial comms ( serial comms being bundled into > the same handlers as files because when these things were developed, 20+ years > ago, nothing better was around. ) It has nothing to do with serial communications, AFAIK. > Binary mode turns off the 'clever' handling > of line ends and ( depending on use and os ) other functional characters ( > tabs expanded to spaces etc ), the normal mode is already binary on windows so > binary makes no difference on win32 files. I think this is mostly wrong. The normal mode on windows is *text*, not binary, so it very much makes a difference. Also, I've never heard of binary mode having *any* effect on tabs, spaces, etc., other than the newline character(s), so could you please provide a reference. Or was this supposition on your part? > But since in may do on other > o.s.'s, ( or when actually using the file object for serial comms.) i think > you should actually ALWAYS use the binary version of the mode, and handle the > line ends etc. yourself. Your program will not be portable if you do this. Use text mode on text files and binary mode on binary files. Understand the difference, so you know when to use which. > suffice to say, i wasn't entirely impressed with the python file object Where is your programming background from? I've never used a language where the "file object" or equivalent did anything more than, let alone even as much as, the Python file object. (Not intended as an insult, just pure curiosity.) > i remembered the cross platform problems its dealing with and all > the code that works ok with it, and though i'd knock up this post of my > findings to try to elicit some discussion / get it improved / stop others > making mistakes. A laudable goal. Let the discussion ensue! :-) -Peter From mpeuser at web.de Sun Aug 17 06:38:09 2003 From: mpeuser at web.de (Michael Peuser) Date: Sun, 17 Aug 2003 12:38:09 +0200 Subject: simple text parser? References: Message-ID: This is a little bit confusing. (1) Do you want to dump "internal" data? Of course you cannnot expect those data to be portabel between Python and C#!!! (2) Do you have your data already converted to some standard ASCII format? Then just write it into a textfile! (3) Do you have a very special structure in mind to be serialized (i.e. list of string - integer tuples; an "array of structs of a row of char and an int" as you would say in C ;-))? Then you probably should store it in XML. Lots of tools with Python, probably as many in C# Kindly Michael P "Brandon J. Van Every" schrieb im Newsbeitrag news:bhng7f$16uiu$1 at ID-203719.news.uni-berlin.de... > I'm making a 2D game with a simple "adjacent freeform territories" map. I > need to make save files for this. I figure I could store the data in either > binary or text. The amount of data to be stored should be small enough that > efficiency and size do not matter. What does matter, is I don't want to > spend any time at all on this. I want something off-the-shelf. > > Can anyone recommend simple text parsers implemented in Python? > > Alternately, doesn't Python have some kind of automagical serialization > pack/unpack functionality? How does that work? I remember reading > something about that in the Python docs awhile ago. Before you scream RTFM, > bear in mind that my current plan is to write versions of this game in C# / > .NET and Python / WhateverWidgets simultaneously. I'm ignorant of both > platforms, this is an excuse to do a comparo. And, the whole point of > moving to higher level language development is to minimize pain. Asking > questions here rather than reinventing the wheel is part of that agenda. I > want to handle this problem off-the-shelf. > > -- > Cheers, www.3DProgrammer.com > Brandon Van Every Seattle, WA > > 20% of the world is real. > 80% is gobbledygook we make up inside our own heads. > From mpeuser at web.de Tue Aug 19 12:53:56 2003 From: mpeuser at web.de (Michael Peuser) Date: Tue, 19 Aug 2003 18:53:56 +0200 Subject: Pmw BLT problems References: Message-ID: May be this helps: http://mail.python.org/pipermail/python-win32/2002-September/000497.html Kindly Michael P "Sriram Chadalavada" schrieb im Newsbeitrag news:f2800d70.0308181241.5f5170f3 at posting.google.com... > Hello fellow python users, > I am trying to use Python Mega widgets and the BLT extension to Tk > for my project. Pmw scripts seem to work fine. > > However, I could not run the BLT examples since BLT was not > installed. > BLT installation was interesting since while the INSTALL file in the > tar ball indicated that the default install directory is /usr/local, > even after specifying the prefix directory during 'configure', the > files were installed w.r.t /usr directory. > > Running a HELLO program that makes use of blt graph gave the following > error message: > Traceback (most recent call last): > File "./HelloGraph.py", line 33, in ? > g = Pmw.Blt.Graph(master) > File "/usr/lib/python2.2/site-packages/Pmw/Pmw_1_2/lib/PmwBlt.py", > line 260, in __init__ > Tkinter.Widget.__init__(self, master, _graphCommand, cnf, kw) > File "/usr/lib/python2.2/lib-tk/Tkinter.py", line 1764, in __init__ > self.tk.call( > TclError: invalid command name "::blt::graph" > > A quick search on the group archive suggested that > this might be because BLT has not been installed. In my case, that > might be 'not properly installed'. > Any suggestions on how to get the installation > right? Did anyone deal with this kind of problem before? > > Thanks in advance, > Sriram From alessandro at sephiroth.it Sun Aug 24 05:36:32 2003 From: alessandro at sephiroth.it (Alessandro Crugnola *sephiroth*) Date: Sun, 24 Aug 2003 09:36:32 GMT Subject: detecting document changes Message-ID: Hi, i'm using wxPython and wxTextStyled. How can I intercept document changes for active documents (for example modified with others external editors)? thanks in advance -- Alessandro Crugnola [sephiroth] Flash | PHP Developer http://www.sephiroth.it Team Macromedia Volunteer for Flash http://www.macromedia.com/go/team Flash-php mailing list http://www.flash-php.it/index.php?ml=fpcoders&action=subscribe From jack at performancedrivers.com Mon Aug 11 12:23:10 2003 From: jack at performancedrivers.com (Jack Diederich) Date: Mon, 11 Aug 2003 12:23:10 -0400 Subject: proper loop syntax? In-Reply-To: ; from JLowder@360commerce.com on Mon, Aug 11, 2003 at 11:04:02AM -0500 References: Message-ID: <20030811122309.A3501@bitch.nowhere.blah> On Mon, Aug 11, 2003 at 11:04:02AM -0500, JLowder at 360commerce.com wrote: > Standard disclaimer here, I'm new to Python/Jython.. > > I have what should be a really simple for loop with nested if/elif's which > doesn't seem to function correctly. > > elif y == "a" or "S": is equivalent to: elif (y == "a"): # do stuff elif ("S"): # do stuff try one of these instead elif y in ("a", "S"): # do stuff elif y in "aS": # shorter, but obscures the intent a little # do stuff elif (y == "a" or y == "S"): # do stuff -jack From aleax at aleax.it Sat Aug 9 13:11:57 2003 From: aleax at aleax.it (Alex Martelli) Date: Sat, 09 Aug 2003 17:11:57 GMT Subject: crossplatform py2exe - would it be useful? References: <2UyYa.50516$cl3.1586459@news2.tin.it> Message-ID: Bengt Richter wrote: ... > Is there a big difference for you between e.g., > > wget /py2exefiedapp.exe > py2exefiedapp > > and > > wget /py2exefiedapp.uff > uffunwrap --launch exefiedapp.uff Yes. Specifically, in the first case (on a Unix-like system) I could interpose a suitable set-userid setting change such as: sudo chmod u+s py2exefiedapp while in the second case I couldn't. Furthermore, my cousin, who has installed no extras at all compared to what comes with his operating system (and runs an operating system without 'apt-get', 'urpmi', or similar 'download-on-demand' functionality) would still be able to take full advantage of the first approach w/o having to previously install ANY other piece of software; to take advantage of the second approach, he would have to first download and install 'uffunwrap', and he just ain't gonna do that. That's two strikes against the ".uff" approach and in favour of the '.exe' one. I can see potential advantages for the '.uff', too, in widely different scenarios; but these issues indicate to me that it just can't replace the '.exe'. Therefore, I would suggest you pursue the .uff as a third-party alternative -- while, on the other hand, "makers of .exe's" have long been available as third-party alternatives, and the thrilling aspect of this latest round of ideas is that we seem to be very close to being able to integrate them in the Python standard distribution, with a resulting potential for an interesting boost to Python's popularity. It makes a psychological difference, quite a big one, whether some functionality is integrated in a standard distribution or has to be separately downloaded and installed as a third-party add-on. "Ability to build directly executable files" would make a big 'selling' point if it were in Python's standard distribution, while "ability to wrap files into an archive which still needs a separate utility to unwrap and run", useful as it may be, just doesn't have the same level of raw appeal to typical punters currently wondering about Python. Alex From vanevery at 3DProgrammer.com Mon Aug 11 05:26:13 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Mon, 11 Aug 2003 02:26:13 -0700 Subject: Slogan: Getting *Slogan* Overnight References: <5540514a.0308110010.75d21f2a@posting.google.com> Message-ID: <3f375f17@shknews01> Raymond A. St. Marie wrote: > > How about... > > P rograms > Y ou > T hink-up > H appen > O ver > N ight [Faced with Programmer Marketing, a person runs screaming from the newsgroup.] Please You're Trying Hard Over Nothing -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From gh at ghaering.de Thu Aug 7 05:15:53 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Thu, 07 Aug 2003 11:15:53 +0200 Subject: Python 2.3 Breaks PySQLite a Little In-Reply-To: References: <3F314D84.E336C01F@easystreet.com> Message-ID: <3F3218C9.9000408@ghaering.de> Greg Brunet wrote: > "Gerhard H?ring" wrote: >>[1] And I intend to drop all this politically correct isinstance stuff >>in a future version for performance reasons. > > Hey Gerhard: > > What will you be using to replace it with that will improve the > performance? Is just doing a: type(value) that much faster? Well, my plan is to rewrite PySQLite completely in C (maybe using PyRex). You're right, it doesn't make a big difference if you use issubclass() or type() in an if-elif chain. But using type() makes it possible to use a dictionary to map types to quote functions, which *should* be faster. Note the "should" ;-) I'll have to benchmark a little more. However I really want to add the feature of being able to register new quote functions without subclassing the type in question and adding a _quote() method, which is currently the only way. Apart from directly hacking the PySQLite sources, like you did ;-) -- Gerhard From abuseonly at sgrail.org Sat Aug 23 21:59:30 2003 From: abuseonly at sgrail.org (derek / nul) Date: Sun, 24 Aug 2003 01:59:30 GMT Subject: List and array code? Message-ID: Is there any list or array code that can load lines from a file? ie what I would like is to open a file and load line by line into a list or array. Any pointers most appreciated. Derek From tim at lesher.ws Fri Aug 15 15:16:26 2003 From: tim at lesher.ws (Tim Lesher) Date: 15 Aug 2003 12:16:26 -0700 Subject: Style in list comprehensions Message-ID: Suppose I have a list of objects and I want to call a method on each. I can do the simple: for i in objs: i.meth(arg1, arg2) or using list comprehensions: [i.meth(arg1, arg2) for i in objs] The second feels more Pythonic, but do I incur any overhead for creating the list of results when I'm not going to use it? -- Tim Lesher tim at lesher.ws From fawcett at teksavvy.com Sun Aug 17 01:35:29 2003 From: fawcett at teksavvy.com (Graham Fawcett) Date: Sun, 17 Aug 2003 01:35:29 -0400 Subject: bitwise not - not what I expected In-Reply-To: <1YD%a.747879$3C2.17342633@news3.calgary.shaw.ca> References: <1YD%a.747879$3C2.17342633@news3.calgary.shaw.ca> Message-ID: <3F3F1421.2050803@teksavvy.com> Elaine Jackson wrote: >Is there a function that takes a number with binary numeral a1...an to the >number with binary numeral b1...bn, where each bi is 1 if ai is 0, and vice >versa? (For example, the function's value at 18 [binary 10010] would be 13 >[binary 01101].) I thought this was what the tilde operator (~) did, but when I >went to try it I found out that wasn't the case. I discovered by experiment (and >verified by looking at the documentation) that the tilde operator takes n >to -(n+1). I can't imagine what that has to do with binary numerals. > It has a lot to do with binary! Google for "two's complement". In the meantime, try this: >>> ~18 & 31 13 The '~' operator cannot care about precision -- that is, how many bits you're operating on, or expecting in your result. In your example, you represent decimal 18 as '10010', but '000000010010' is also correct, right? In two's complement math, both inverses, '01101' and '111111101101' respectively, are equivalent to decimal -19. And-ing with a mask that is the of length 'n' will ensure that you only get the least significant n bits -- and this is what you're looking for. Since you're operating on five bits in your example, I chose decimal 31, or '11111'. -- Graham From duke99 at email.ro Sun Aug 31 07:17:52 2003 From: duke99 at email.ro (soso) Date: 31 Aug 2003 04:17:52 -0700 Subject: Embedding help tools Message-ID: Hello everybody, Is there a nice helper tool for easier embedding of python code? Like SWIG helps extending python. Thanks, soso From newsgroups at jhrothjr.com Fri Aug 1 06:44:08 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Fri, 1 Aug 2003 06:44:08 -0400 Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> <23bcqKAykjK$Ewhy@jessikat.fsnet.co.uk> Message-ID: "Robin Becker" wrote in message news:23bcqKAykjK$Ewhy at jessikat.fsnet.co.uk... > In article , Ian > Bicking writes > >And Java's JIT is based on (at least originally) work done on Self, > >which had to do type inference. And actually in many circumstances Java > >requires type inference, because you can substitute in an instance of a > >subclass. > > > >Anyway, JIT is all about runtime analysis -- if you could infer types > >completely before running the program, you would just put in the > >optimizations statically (i.e., compiling optimizations). JIT does > >those optimizations at runtime by definition. > > > > but Java does at least require specifying every type and that must at > least cut down on the amount of work required. > > >And Bicycle Repair Man is inspired by the Refactoring Browser, an IDE > >tool based on another dynamic language (Smalltalk), not on a tool from a > >static language (like Java). > > > > Ian > > I don't have any data here, but I believe Python is just a little too > weakly typed for compiling to float*float type assembler efficiently. The trick with JITs is that they don't depend on absolute type consistency. They depend on the observation that 99.44% of your code is type consistent, and that consistency will turn up at run time. So the code they generate depends on that discovered consistency, and checks in front of each section to discover if the types are what the code expects. If it is, they execute it, if it isn't, they abandon it and go back to the intepreter to discover what happened. John Roth > -- > Robin Becker From peter at engcorp.com Mon Aug 25 14:38:40 2003 From: peter at engcorp.com (Peter Hansen) Date: Mon, 25 Aug 2003 14:38:40 -0400 Subject: Help embedding python References: <3F4A469E.58B94F7C@engcorp.com> Message-ID: <3F4A57B0.E91D89FC@engcorp.com> Zora Honey wrote: > > Peter Hansen wrote: > > Zora Honey wrote: > > > >>My husband and I are writing a program that does a lot of math behind > >>the scenes (c++) with a gui front (python/Tkinter). We've decided that > >>we want the c++ to be the "driver", and so we want to embed the python. > > > > > > It's a little unclear (to me) exactly what you're trying to do, > > but in any case I can't imagine why you'd want to have C++ "drive" > > the Python code (if that's what you meant by "driver", as opposed to > > the more common sense as in "device driver") instead of the other > > way around. > > > > And my inability to imagine why you want this is compounded by your > > choice of Python and Tkinter for the front end. It is much more > > common to have the front end be the "driving" code, and the back end > > be "driven", especially in CPU-intensive applications as it sounds > > like you have here. > > > > -Peter > > Okay. Let's assume that the choice to embed the python was a > well-reasoned decision. Or assume that I want to embed some python for > the pure joy of doing so. Can you help? No, sorry. I have no particular expertise in embedding Python in a C++ application in the way you wish. (If I did, and I had an easy answer, I would offer it. If, on the other hand, I had no easy answer, and it was going to take some effort on my part, I'd be happy to provide that effort if the person I was helping would take a moment of his/her time to convince me that it was a well-reasoned decision. If, on the other hand, the decision was based on ignorance or merely on a frivolous desire to experience the joy of doing so at the cost of another's valuable time, I would probably be less inclined to help...) (If you assume for a moment that the person who actually *can* help you might feel somewhat the same way, you might take a moment to explain the background rather than risk looking like you treat others' time as less valuable than your own. It may not look that way to you, but I was merely trying to help by showing you that at least one person was puzzled by your choice. I'm also always interested in learning, so I'd still be quite interested in your rationale, if you are willing to provide it.) Cheers, -Peter From sjmachin at lexicon.net Mon Aug 4 19:07:57 2003 From: sjmachin at lexicon.net (John Machin) Date: 4 Aug 2003 16:07:57 -0700 Subject: Match beginning of two strings References: Message-ID: Richie Hindle wrote in message news:... > > for C strings. There's another similar optimisation that the C > output leads you to: you can use strlen rather than Python's len: > You can, if you don't care about the possibility that the input may contain NULs. From bsneddon at yahoo.com Mon Aug 25 16:14:45 2003 From: bsneddon at yahoo.com (Bill Sneddon) Date: Mon, 25 Aug 2003 16:14:45 -0400 Subject: Deleting email message using imaplib? Message-ID: Anyone have an example they are willing to share that shows how to use the store command in imaplib? store( message_set, command, flag_list) Alters flag dispositions for messages in mailbox. I have been unable to find one or get the syntax correct through trial and error. I can send the command to the server in the following manor. The only problem is I can not get the response back from the server. I tried the recent() and the responce(code) objects with no success. Not sure what the code should be. I would be open to a different approach to delete a message if one exist. This is example of deleting from PythonWin. >>> m.send('A003 STORE 2:4 +FLAGS (\Deleted)') >>> m.recent() ('OK', ['0']) >>> m.expunge() Traceback (most recent call last): File "", line 1, in ? File "C:\Python23\lib\imaplib.py", line 402, in expunge typ, dat = self._simple_command(name) File "C:\Python23\lib\imaplib.py", line 1000, in _simple_command return self._command_complete(name, self._command(name, *args)) File "C:\Python23\lib\imaplib.py", line 832, in _command_complete raise self.abort('command: %s => %s' % (name, val)) abort: command: EXPUNGE => unexpected response: 'A0032 OK STORE completed' >>> m.expunge() ('OK', ['2', '2', '2']) Thanks for your help. Sorry if this is a FAQ but I looked and could not find the answer. Bill Sneddon From mis6 at pitt.edu Fri Aug 29 05:27:07 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 29 Aug 2003 02:27:07 -0700 Subject: Metaclasses presentation slides available... References: Message-ID: <2259b0e2.0308290127.390598df@posting.google.com> "Mike C. Fletcher" wrote in message news:... > Slides from my PyGTA presentation on Tuesday, focusing mostly on > why/where you would want to use meta-classes, are available in PDF format: > > http://members.rogers.com/mcfletch/programming/metaclasses.pdf I gave a look at your transparancies and they are very good, indeed. Still, there a couple of minor points I think could be improved, for the sake of metaclass newbies (I am in a nitpick mood today ;) 1) On page 26 you say: Note: In Python 2.2.3, the meta-class object's __call__ is not called by the metaclass hook, the interpreter calls __new__, then __init__ directly That's correct (and true in 2.3 too), still there is a way to get the metaclass hook to call __call__: it involves meta-metaclasses ;) class MetaMetaCall(type): def __call__(mcl,name,bases,dic): print "%s.__call__ called!" % mcl class Meta(type): __metaclass__=MetaMetaCall class C: __metaclass__=Meta # invokes Meta.__call__, not Meta.__new__! To understand this, it is enough to remember that metaclasses are just classes and therefore can be modified by using meta-metaclasses. BTW, this is the reason why metamethods do not attach to instances: in this example MetaMeta.__call__ is a meta-metamethod, which is accessible to Meta, but not to its instance C; therefore you can modify the C __call__ (and Meta.__call__ too, if you wish) method independently from MetaMeta.__call__, avoiding name clashes. 2) On page 30 you say that you can modify the dictionary both in __new__ and in __init__. This is true, but not obviously true. In __new__ you can simply change "dic", in __init__ this would not work: class M(type): def __init__(cls,name,bases,dic): dic['spam']='egg' class C: __metaclass__=M print C.__dict__ # does not contain "spam" You can modify the dict only indirectly, with something like cls.spam='egg'. For the rest, excellent presentation! > BTW, for those not on Python-list, be sure to check out David & > Michele's newest developerworks article on the topic: > > http://www.ibm.com/developerworks/library/l-pymeta.html > http://www.ibm.com/developerworks/library/l-pymeta2/?ca=dnt-434 You forgot to mention Alex Martelli's presentation: http://www.strakt.com/dev_talks.html > Have fun, > Mike > > _______________________________________ > Mike C. Fletcher > Designer, VR Plumber, Coder > http://members.rogers.com/mcfletch/ Michele Simionato, Ph. D. MicheleSimionato at libero.it http://www.phyast.pitt.edu/~micheles --- Currently looking for a job --- From postmaster at virgilio.it Fri Aug 22 13:15:32 2003 From: postmaster at virgilio.it (Mail Delivery Service) Date: Fri, 22 Aug 2003 19:15:32 +0200 Subject: Delivery Status Notification Message-ID: <3F401DC2006EE5C4@vsmtp7.tin.it> - These recipients of your message have been processed by the mail server: genteditoscana at virgilio.it; Failed; 5.2.2 (mailbox full) Remote MTA ims2b.cp.tin.it: SMTP diagnostic: 552 RCPT TO: Mailbox disk quota exceeded -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: text/rfc822-headers Size: 656 bytes Desc: not available URL: From dan at osheim.org Fri Aug 8 10:40:33 2003 From: dan at osheim.org (Dan Williams) Date: Fri, 08 Aug 2003 09:40:33 -0500 Subject: Anonymous class question References: Message-ID: <3F33B661.1040100@osheim.org> Bengt Richter wrote: > On Thu, 07 Aug 2003 03:20:24 GMT, Carl Banks wrote: > > >>Dan Williams wrote: >> >>>Python experts, >>> >>>Is there a more pythonic way to do something evquilent to what this line >>>does without creating a dummy class? >>> >>>self.file = type("", (object,), {'close':lambda slf: None})() >>> >> > Does that (object,) do something I'm missing? > > >>> o1 = type('',(object,),{})() > >>> o2 = type('',(),{})() > >>> type(o1).__bases__ > (,) > >>> type(o2).__bases__ > (,) > > Regards, > Bengt Richter I thought it made it a new-style class. I could be wrong about that, though. . . -Dan From altis at semi-retired.com Fri Aug 1 12:48:02 2003 From: altis at semi-retired.com (Kevin Altis) Date: Fri, 1 Aug 2003 09:48:02 -0700 Subject: Potentially important real-time on-line discussion References: Message-ID: URL correction: http://chronicle.com/colloquylive/2003/08/opensource/ ka "Cameron Laird" wrote in message news:vil4sib40kl0c1 at corp.supernews.com... *The Chronicle of Higher Education*, which is more-or-less authoritative for US university administrations, is spon- soring a discussion on the place of open-source in universities ("... are such choices too risky for colleges ...?"), starting in about an hour. Bluntly, I think it's time to rally 'round the flag. http://chronicle.com/colloquylive/2003/08/opensource/chat.php Pass it on. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://phaseit.net/claird/home.html From dtolton at yahoo.com Wed Aug 13 05:34:53 2003 From: dtolton at yahoo.com (Doug Tolton) Date: Wed, 13 Aug 2003 09:34:53 GMT Subject: The importance of using Library Functions References: Message-ID: On Wed, 13 Aug 2003 02:26:18 GMT, Doug Tolton wrote: >At my company we have a program that parses through certain types of >electronic files and stores the information in plain text. E-mail >poses an interesting problem for us, because most of the text tends to >be wrapped and doesn't contain hard returns. The specific web control >we use to display this text will simply show the text of the e-mail as >a single continuous line. > >On friday I was asked to fix the text for these files so it would be >appropriately wrapped at a line width of 80 characters. Yesterday I >began writing the code to deal with this. I was at work until 5:15 am >today trying to solve all the little quirks of that type of parsing. >I finally got most of the kinks worked out, and ran it, however at >great personal cost (ie lost sleep). > >Much to my dismay I was browsing this board and saw the post about >Summer Reading: > >On Tue, 12 Aug 2003 06:57:05 GMT, "Raymond Hettinger" > wrote: > >>Found in a pamphlet at a pre-school: >>--------------------------------------- >>Reading improves vocabulary >>Reading raises cultural literacy through shared knowledge >>Reading develops writing skills >>Reading opens the mind to new ways of understanding >>Reading is fun >> >> >>Accordingly, I suggest the following works of literature: >> >> * heapq.py (255 lines) >> * sets.py (536 lines) >> * textwrap.py (355 lines) >> * csv.py (427 lines) > >With a sinking feeling I opened the textwrap.py module and browsed >through it. After running several tests and playing with some of the >settings, this was *exactly* what I needed. > >I've always enjoyed writing code. I particularly enjoy solving hard >problems, what I don't like is trying to solve them under immense >pressure from a client. Ultimately the problem itself was moderately >hard to solve, but the conditions made it even more difficult. I had >an inordinately large amount of text to deal with, so my test cycle >was ungodly slow. > >Had I spent 30 minutes looking through the documentation, I could've >saved my self one helluva long night. > >As much as I hate to be the example, it really is a wonderful >illustratration of why following the Unix / OSS development model is a >better way to go. > >1. Check to see if someone has already written an app to do what you >want done. >2. Check to see if someone has written something that is close to what >you want done. If you can get the source code, modify it to do what >you need specifically. >3. Write it from scratch. > >Instead of working my way down the list, I jumped straight to number >3. While that can be useful for an academic excercise, or when you >are going for a more rigorous approach, it's seldom useful when you >have a looming deadline. > >Doug Tolton Interestingly TextWrap choked on the text I'm running it against. I'm sure it's more an issue of complete craziness in these files than an actual problem with TextWrap. While it doesn't change the fact that I should have approached the problem differently at the outset, it makes me happy to know that I didn't waste all that time writing my code. Doug Tolton From quiteblack at yahoo.com Fri Aug 8 22:16:24 2003 From: quiteblack at yahoo.com (black) Date: Fri, 8 Aug 2003 19:16:24 -0700 (PDT) Subject: .py into .exe~ Message-ID: <20030809021624.93407.qmail@web21302.mail.yahoo.com> Howdy~ i'd like to package my .py files into .exe but dunno how to, the reason why is i want to show others my mini games but i cant force them to install python in their before sending them my games, any help ? --------------------------------- Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software -------------- next part -------------- An HTML attachment was scrubbed... URL: From thor__00 at yahoo.com Mon Aug 18 18:44:03 2003 From: thor__00 at yahoo.com (Thor) Date: Tue, 19 Aug 2003 00:44:03 +0200 Subject: Functions Message-ID: In this hypothetical case: def f1: f3: def f2: def f3: pass f1: def f4: def f3: pass f1: would the function f1 execute the right f3 depending on from which functions is it called? -- Thor -- Stockholm -- Sverige From peter at engcorp.com Tue Aug 26 13:59:07 2003 From: peter at engcorp.com (Peter Hansen) Date: Tue, 26 Aug 2003 13:59:07 -0400 Subject: Default value for PYTHONPATH References: <8d3e714e.0308260950.40ad4a7b@posting.google.com> Message-ID: <3F4B9FEB.CEF24A2D@engcorp.com> Tony C wrote: > > Is there a default value for PYTHONPATH ? > I've installed Python on both Windows and Linux, and was surprised to see that > this variable is empty. > > IS this normal ? Yes, PYTHONPATH is available for you to *override* or extend the usual settings, which are mostly discovered during site.py processing. Also see a recent post (just yesterday, I believe) that covers the specifics of all this, at least for Windows, in great detail. -Peter From bkc at Murkworks.com Wed Aug 20 14:04:09 2003 From: bkc at Murkworks.com (Brad Clements) Date: Wed, 20 Aug 2003 14:04:09 -0400 Subject: py2exe service doesn't work, can't connect to service controller ? References: <3F41F576.14352.14BE73C2@localhost> Message-ID: I edited the svc_run.exe file and changed PyWinTypes22.dll to PyWinTypes23.dll. py2exe now builds a distribution that does not use any 2.2 Python components. However the service still fails to load after installation with the following error: The description for Event ID ( 240 ) in Source ( MyService ) cannot be found. The local computer may not have the necessary registry information or message DLL files to display messages from a remote computer. The following information is part of the event: 1063, The service process could not connect to the service controller.. Has anyone been able to get py2exe services to work with 2.3? Thanks From aahz at pythoncraft.com Mon Aug 18 14:03:26 2003 From: aahz at pythoncraft.com (Aahz) Date: 18 Aug 2003 14:03:26 -0400 Subject: python threads on multi-CPU machines References: <5a4226f0.0308180945.34f96eca@posting.google.com> Message-ID: In article <5a4226f0.0308180945.34f96eca at posting.google.com>, Kevin Cazabon wrote: >Aahz: >> >> However, C extensions can release the GIL, and almost all I/O code >> in Python does that, so I/O-heavy programs will make good use of the >> SMP. > >FYI, I'm also working on adding that functionality to the PIL library, >seeing as imaging operations can be fairly expensive too. It makes >these processes more "friendly" to other threads (and Tk) even on >single-CPU boxes, and allows taking advantage of multiple CPUs where >available. Cool! When you're done, I'd appreciate it if you could write up a short summary of the problems you ran into and post it here. I'm interested in pushing computational threading in Python, but I haven't written enough C code to have any idea how it differs from other kinds of threading issues. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From gh at ghaering.de Wed Aug 6 07:15:11 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Wed, 06 Aug 2003 13:15:11 +0200 Subject: MSVC 6.0 Unsupported? In-Reply-To: References: <3F302764.8010301@ghaering.de> Message-ID: <3F30E33F.6070402@ghaering.de> Syver Enstad wrote: > "M.-A. Lemburg" writes: > >>The best thing to do is to replace this code in Python's object.h >>file (Python23\Include\object.h; note the comment !): > > That's exactly what I did and it worked fine. Requiring users of my software to patch their Python instalation is not an option for me. -- Gerhard From mfranklin1 at gatwick.westerngeco.slb.com Thu Aug 28 03:42:51 2003 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Thu, 28 Aug 2003 08:42:51 +0100 Subject: homebrew 2.3 install on RedHat9 not playing nice with Tkinter In-Reply-To: <0h83b.953$8v3.90271@twister.austin.rr.com> References: <0h83b.953$8v3.90271@twister.austin.rr.com> Message-ID: <200308280842.51310.mfranklin1@gatwick.westerngeco.slb.com> On Wednesday 27 August 2003 9:12 pm, Rob Andrews wrote: > I'm on a Red Hat 9 system, which has Python 2.2.2 installed, and I > installed 2.3 separately into /home/rob/Python-2.3/ (creating the symbolic > link "py23" to point to my 2.3 installation). Now I'm trying to work out > the kinks in the process. > > Unable to run Idle using 2.3 the way I've got things set up, I created a > super simple Tkinter test program that just pops up a Label widget. I > pasted below an example of how the RH-provided 2.2 runs the script without > incident, but running the script with 2.3 produces a traceback. If someone > can help me see the error of my ways, I'll be most appreciative. > > [Wed Aug 27][03:01 PM] ~/Python-2.3/test $ python -V > Python 2.2.2 > [Wed Aug 27][03:04 PM] ~/Python-2.3/test $ py23 -V > Python 2.3 > [Wed Aug 27][03:01 PM] ~/Python-2.3/test $ py23 test2.py > Traceback (most recent call last): > File "test2.py", line 1, in ? > from Tkinter import Label > File "/home/rob/Python-2.3/Lib/lib-tk/Tkinter.py", line 38, in ? > import _tkinter # If this fails your Python may not be configured for > Tk ImportError: No module named _tkinter > [Wed Aug 27][03:01 PM] ~/Python-2.3/test $ python test2.py > > -Rob > (mediocre with Python, incompetent with linux) Rob, I just finished building python 2.3 on my redhat 9 laptop... the first time I did the make it failed (near the end) because it couldn't find the Tk/Tcl libs. On my system they are in /usr/local/lib (because I built them myself) on your's I guess they would be in /usr/lib. So to fix the build I set LD_RUN_PATH to /usr/local/lib and them ran make again. HTH Martin From ramiak2000 at yahoo.com Tue Aug 19 00:55:32 2003 From: ramiak2000 at yahoo.com (Rami A. Kishek) Date: Tue, 19 Aug 2003 00:55:32 -0400 Subject: Problem installing Python 2.2/2.3 on Windows 98 SE Message-ID: <3F41ADC4.3642D39B@yahoo.com> Please help! Very strange installation problem. First, let me say I successfully installed and use Python 2.2.3 and 2.3 from the EXE binaries on a win ME machine. That machine previously had 1.5.2, and now I have access to all 3 versions. When I tried to do the same on an older machine, however, running Win98 SE (and having had Python 1.5.2 previously installed there), the installation doesn't work: Obvious problems: * IDLE doesn't start at all * Pythonwin starts, but dumps some warning virtually with every line. The long message below is an example of what shows up on startup. * The python win32 ext install differed from that of 2.2 in one respect: it complained about being unable to register the key of some Scripting thing. I compared the registry entries for this python and the pythons on the good (WinME machine), and there's no difference. (However, the MODULES key in Python 2.2 and 2.3 on both machines has no subkeys, whereas 1.5.2 has several). Anyways, I am perplexed, I see no reason why the installation from the same exe binaries should work on one machine but not the other. The Win ME machine suffers from none of the problems above. The only difference I can think of, of remote likelihood, is that the existing Python 1.5.2 on the failed machine was in C:\Program Files\Python, and I tried installing Python 2.x in respective directories on D:\Programs. In the good machine, all are installed on D:\Programs. ----------------- D:\PROGRAMS\PYTHON22\lib\site-packages\Pythonwin\pywin\framework\winout.py:455: DeprecationWarning: strop functions are obsolete; use string methods self.currentView.dowrite(string.join(items,'')) PythonWin 2.2.3 (#42, May 30 2003, 18:12:08) [MSC 32 bit (Intel)] on win32. D:\PROGRAMS\PYTHON22\lib\site-packages\Pythonwin\pywin\framework\winout.py:465: DeprecationWarning: strop functions are obsolete; use string methods pos = string.rfind(message, '\n') Portions Copyright 1994-2001 Mark Hammond (mhammond at skippinet.com.au) - see 'Help/About PythonWin' for further copyright information. >>> D:\PROGRAMS\PYTHON22\lib\site-packages\Pythonwin\pywin\scintilla\IDLEenviro nment.py:207: DeprecationWarning: strop functions are obsolete; use string meth ods if string.find(base,".")>0: D:\PROGRAMS\PYTHON22\lib\site-packages\Pythonwin\pywin\framework\intpyapp.py:27 3: DeprecationWarning: strop functions are obsolete; use string methods modules = string.splitfields(moduleNames,",") From avadmin at cds.unina.it Sun Aug 31 01:07:57 2003 From: avadmin at cds.unina.it (avadmin at cds.unina.it) Date: Sun, 31 Aug 2003 01:07:57 CEST Subject: Inflex scan report [0831010741425] Message-ID: <200308302307.h7UN7wtx038188@cds.unina.it> Administrator Email Reply Address: avadmin Email sent to: zelati at cds.unina.it Inflex ID: 0831010741425 Report Details ----------------------------------------------- AntiVirus Results... SWEEP virus detection utility Version 3.71, July 2003 [Digital Unix/Alpha] Includes detection for 82964 viruses, trojans and worms Copyright (c) 1989,2003 Sophos Plc, www.sophos.com System time 01:07:58, System date 31 August 2003 Command line qualifiers are: -archive -all -rec -sc IDE directory is: /usr/local/sav Using IDE file webber-a.ide Using IDE file gruel-a.ide Using IDE file coconuta.ide Using IDE file cmjspy-b.ide Using IDE file golon-a.ide Using IDE file ataka-e.ide Using IDE file migmaf-a.ide Using IDE file mofei-b.ide Using IDE file viewmova.ide Using IDE file israza.ide Using IDE file graps-a.ide Using IDE file larx-fam.ide Using IDE file zwmvc-b.ide Using IDE file adenu-a.ide Using IDE file mylife-m.ide Using IDE file mumu.ide Using IDE file revas-a.ide Using IDE file klexe-a.ide Using IDE file sage-a.ide Using IDE file sluter-a.ide Using IDE file colevo-a.ide Using IDE file slanpera.ide Using IDE file cailonta.ide Using IDE file sandesa.ide Using IDE file yaha-t.ide Using IDE file sobig-e.ide Using IDE file frtnghte.ide Using IDE file relax-c.ide Using IDE file pcghosta.ide Using IDE file haclineb.ide Using IDE file nofer-c.ide Using IDE file magold-d.ide Using IDE file redist-c.ide Using IDE file nofer-b.ide Using IDE file mumu-b.ide Using IDE file sobig-d.ide Using IDE file frtnghtf.ide Using IDE file mystri-a.ide Using IDE file crock-a.ide Using IDE file suhd-a.ide Using IDE file nofer-a.ide Using IDE file anaco-d.ide File panjang.ide is older than 90 days Using IDE file gruel-c.ide Using IDE file gruel-b.ide Using IDE file mapson-c.ide Using IDE file gruel-d.ide Using IDE file gruel-e.ide Using IDE file dwnld-di.ide Using IDE file gruelfam.ide Using IDE file mofei-c.ide Using IDE file jantic-b.ide Using IDE file frtnghth.ide Using IDE file qqpass-a.ide Using IDE file babybr-a.ide Using IDE file mimail-a.ide Using IDE file randonr.ide Using IDE file cidu-a.ide Using IDE file gruel-m.ide Using IDE file boohoo-a.ide Using IDE file maila.ide Using IDE file autort-a.ide Using IDE file lovgatel.ide Using IDE file sview-a.ide Using IDE file randex-d.ide Using IDE file blastera.ide Using IDE file rpcsdb-a.ide Using IDE file blasterb.ide Using IDE file donkc.ide Using IDE file graybird.ide Using IDE file nachi-a.ide Using IDE file blasterd.ide Using IDE file sobigf.ide Using IDE file dumaru-a.ide Using IDE file bdoorrq.ide Using IDE file pandem-b.ide Using IDE file agobot-q.ide Using IDE file tzet-a.ide Using IDE file blastere.ide Using IDE file nugosh-a.ide Using IDE file raleka.ide Quick Sweeping 00:01 _headers_ 00:01 textfile0 00:01 textfile1 00:01 your_details.pif >>> Virus 'W32/Sobig-F' found in file /usr/local/inflex/tmp/inf_0831010741425/unpacked/your_details.pif 00:01 textfile2 5 files swept in 1 second. 1 virus was discovered. 1 file out of 5 was infected. Please send infected samples to Sophos for analysis. For advice consult www.sophos.com, email support at sophos.com or telephone +44 1235 559933 End of Sweep. File NAME/TYPE Scan Results 0831010741425 from:python-list at python.org to: zelati at cds.unina.itType scanning off. Name scanning off. Text scanning off. END OF MESSAGE. End. . From tyler at scalegen.com Sun Aug 3 00:59:15 2003 From: tyler at scalegen.com (Tyler Eaves) Date: Sun, 03 Aug 2003 00:59:15 -0400 Subject: Dealing with paths (Unix question) References: Message-ID: On Sun, 03 Aug 2003 03:04:13 +0000, paul wrote: > hey there all! > i'm writing some little programs, and i'd like to know about how to deal > with directories on unix. i've read up on this, but the docs don't really > mention much on it. do i use the pickle module, or something? > Look at os.path.walk -- Visit my blog - http://blog.scalegen.com Music, Programming, and More. From adalke at mindspring.com Mon Aug 18 15:06:34 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Mon, 18 Aug 2003 13:06:34 -0600 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: Message-ID: Daniel Dittmar: > What is lacking > is a syntax to be able to create lambdas with multiple statements. And > perhaps a syntax without using the keyword lambda, as some people seem > to have an allergic reaction to it. How about this? def Lambda(x, y): z = x+y return z print Lambda(2,3) ;) In more seriousness, Python makes a strong distinction betweeen statements and expressions. Lambdas can be used in expressions, so if it includes statements then what would would the layout look like which preserves good Pythonic nature? Here's one such example of defining a function for simple numerical integration. def integrate(fctn, start = -1.0, end = 1.0, step = 0.1): return sum(map(fctn, range(start, end, step)))/((end - start)/step) print integrate(fctn = def (x): print "Evaluating at", x, if x > 0: y = math.cos(x) else: y = math.sin(x) print "=", y return y }) I think Python's parser can handle this. It has a certain charm to it as well. But if the code is more than a line or two long then I think it should be a named function. My main complaint is that I can't stick a 'print' in the lambda, as for debugging. Occasionally I'll have code akin to def print_(*args): print " ".join(map(str, arg))) return 1 intergrate(lambda x: print_(x) and x) which is a workaround. But I rarely need it, prefering named functions over unnamed ones. Andrew dalke at dalkescientific.com From davesum99 at yahoo.com Mon Aug 11 21:16:59 2003 From: davesum99 at yahoo.com (smarter_than_you) Date: 11 Aug 2003 18:16:59 -0700 Subject: Slogan: Getting Rich Overnight References: Message-ID: I know this is an old thread already, but my 2c -- If that Brandon idiot hates it, it's a great slogan. Use it and let the doubters be damned. Anyone who doesn't get the irony is not worthy of understanding the sentiment. -ds Christian Tismer wrote in message news:... > Dear friends. > > During a conversation with good friends and newly acquired > Pythonista, we were discussing Python, what it is in essence, > and what it is giving to us. > > The people were Dinu Gherman, Giorgio Giacomazzi, > a promizing newcomer in the Python noosphere, and myself. > > We were discussing how to advertize for Python, and Dinu > spread some of the recent library enhancements, like > > - email package > - XML parsers > - distutils > - add lots of other great stuff, here. > > Then, after a while of silence, Giorgio said something like > """ > Well, right. > But despite of the libraries, I was hit by pure Python, > by the following, simply by using it interactively: > > There are these lists, these tuples, and these dicts. > They are immediately there, at my fingertips. And this is > a feeling that I never had, before. Especially these dicts > are incredible. > > This was a feeling like 'getting rich overnight'. > """ > > I loved this statement very much, and I have to say, this > is essentially my feeling for myself, since many years now. > I could imagine that this might be a candidate for next year's > Python congress' slogan. "Python makes you rich, overnight". > Not by money, in the first place, but by multiplying your > own capabilities, immediately. > > It needed the fresh experience of a newcomer to become aware > of this, again. > > The ambiguity is obvious. On first reading, it will attract > many. On second reading, those who are thinking "ahh, ohh, yes, > not I understand" will remain. But that's ok for a good slogan! > > got rich overnight by Python! > > being rich since 1800 nights now - sincerely -- chris From skip at pobox.com Tue Aug 5 18:01:01 2003 From: skip at pobox.com (Skip Montanaro) Date: Tue, 5 Aug 2003 17:01:01 -0500 Subject: pyc to py?? In-Reply-To: <1034514.1060120302480.JavaMail.nobody@webmail1.brturbo.com> References: <1034514.1060120302480.JavaMail.nobody@webmail1.brturbo.com> Message-ID: <16176.10525.270897.408639@montanaro.dyndns.org> Juliano> is it possible to transform the .pyc file in .py file??? if Juliano> it's possible, how can i get this??? Google for decompyle. Skip From gh at ghaering.de Sun Aug 3 01:25:29 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Sun, 03 Aug 2003 07:25:29 +0200 Subject: pyrex error In-Reply-To: References: <8YPWa.48874$YN5.38312@sccrnsc01> Message-ID: <3F2C9CC9.7040100@ghaering.de> Bryan wrote: > "Gerhard H?ring" wrote: >>In the PySQLite sources, I added this snippet on top: >> >>#ifdef _MSC_VER >>#define staticforward extern >>#endif >> >>to make it compilable under MSVC/Python 2.3. *After* #include-ing >>"Pyhton.h" of course. > > ifdef'ing for _MCS_VER won't solve the problem for compiling under 2.2 and > 2.3. [...] Yes it will. gcc and MSVC, Python 2.2 and Python 2.3. All combinations tested. Btw. I'd appreciate it if you configured your newsreader correctly or switched to one that comes less broken by default, as I despise broken quoting. -- Gerhard From none at none.net Tue Aug 12 08:23:52 2003 From: none at none.net (Sami Viitanen) Date: Tue, 12 Aug 2003 12:23:52 GMT Subject: os.system('cd dir1 ... and executing next os.system command in that directory (dir1) Message-ID: Hello, I'm having problems with os.system. If I execute some 'cd directory' command with it, after that the script is on the same directory level as it was before the command. Any ideas ? Thanks in advance. From jhefferon at smcvt.edu Thu Aug 14 11:09:57 2003 From: jhefferon at smcvt.edu (Jim Hefferon) Date: 14 Aug 2003 08:09:57 -0700 Subject: No doubt I should know this regex point but .. Message-ID: <545cb8c2.0308140709.281fb610@posting.google.com> I am writing a class that walks through a file tree and (among other things) filters out which files it considers. So I want to have __init__( .. ,filterExpression='..') For the default I want to filter nothing. So I need a Python regular expression that never matches. What is (the best) one? Thanks for any help, Jim From R.Brodie at rl.ac.uk Thu Aug 7 08:03:00 2003 From: R.Brodie at rl.ac.uk (Richard Brodie) Date: Thu, 7 Aug 2003 13:03:00 +0100 Subject: Need to convert an arbitrary byte-pair to an int. References: <3f323dc2$0$10775$afc38c87@auth.uk.news.easynet.net> Message-ID: "Graham Nicholls" wrote in message news:3f323dc2$0$10775$afc38c87 at auth.uk.news.easynet.net... > I'm trying to size a jpeg file. The file size is held in a short (2 byte > integer) at a certain offset. Once I've found these two bytes (they're in > MSB,LSB order), I need to convert them to an integer - now I know that in C > I'd just cast a pointer to the offset to a short, and that python doesn't > cast, so how can I extract the value from a stream of bytes. I've looked > at python.org/Doc/current (I'm using 2.3b1), but can't find anything > obvious. For rolling your own direct handling of byte streams, the struct module is often best. You also might want to look at the Python Imaging Library http://www.pythonware.com/products/pil/ From john at rygannon.com Mon Aug 25 17:14:14 2003 From: john at rygannon.com (BadJake) Date: Mon, 25 Aug 2003 21:14:14 GMT Subject: ANN: BlackAdder V1.0.0 References: <3f48a498$3$219$fa0fcedb@lovejoy.zen.co.uk> <1Kj2b.61523$bo1.38258@news-server.bigpond.net.au> Message-ID: <3f4a7ba0$0$250$fa0fcedb@lovejoy.zen.co.uk> UK and European sales are being handled by myself and US and the Rest of the World is handled by theKompany.com There is nothing untoward happening here it is just a resellers agreement. If you go to the CCart menu item and make a purchase via PayPal, the money goes into theKompany.com account. This way I get my resellers commission. If I was to link to theKompany.com BA page I would get nothing Regards John From fawcett at teksavvy.com Mon Aug 18 05:49:53 2003 From: fawcett at teksavvy.com (Graham Fawcett) Date: Mon, 18 Aug 2003 05:49:53 -0400 Subject: What's better about Rattlesnakes than Pythons? In-Reply-To: References: <8e482ba2.0308171939.7de4a288@posting.google.com> Message-ID: <3F40A141.5090408@teksavvy.com> Andrew Dalke wrote: >Brandon J. Van Every: > > >>If >>you want to live in a desert, and you want to hear your pet easily, you're >>better off with a rattlesnake. >> >> > >So I live in a desert. I recently involuntarily acquired some >mouse housemates, which I want to get rid of (and are keeping >me up late tonight because I can hear the occasional rustle.) > >Would Rattlesnake or Python be better at de-mousing my house? >Do either come with an IDE? (Infestation Devouring Engine) >Do either need a lot of support? Are there books on the topic? > > Any snake born in Java will perform better than these two; at least that's what the Javanese snake-sellers tell me. What they don't tell you is that you'll have to spend ten times as long training the darn snake. I hear that sea-snakes are pretty fast too. But be warned: if you point a sea-snake in an invalid direction, it may never come back. Also, be prepared to clean up the mouse carcasses yourself. >Blah. I'm up too late to make even my normal medium quality >quips. Tomorrow it'll be trap shopping day. Again. Caught >two already in glue traps. > > That's a statically-typed trapping solution, isn't it? (Too late for me too, I think) -- Graham From elw at euc.cx Wed Aug 20 21:22:18 2003 From: elw at euc.cx (Jeffrey P Shell) Date: 20 Aug 2003 18:22:18 -0700 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: Message-ID: <240b1020.0308201722.d1b991c@posting.google.com> "Brandon J. Van Every" wrote in message news:... > I'm realizing I didn't frame my question well. > > What's ***TOTALLY COMPELLING*** about Ruby over Python? What makes you jump > up in your chair and scream "Wow! Ruby has *that*? That is SO FRICKIN' > COOL!!! ***MAN*** that would save me a buttload of work and make my life > sooooo much easier!" > > As opposed to minor differences of this feature here, that feature there. > Variations on style are of no interest to me. I'm coming at this from a C++ > background where even C# looks like an improvement. ;-) From 10,000 miles > up, is there anything about Ruby that's a "big deal" compared to Python? > > One person mentioned Japanese documentation. I'm sure that's Totally Kewl > to the Japanese.... Negative points earned by using 'frickin' and 'kewl'. But with an earnest answer to your question - I started evaluating Ruby about two and a half years ago. For me at the time, the "big deals" in comparison to Python were: A unified class hierarchy. ========================== Python 2.2 started addressing this issue. And it's not one that absolutely needs to be solved. But it starts making things more consistent, and we can finally extend core types such as lists and dictionaries, and legally write new code in C that can be subclassed in Python. Ruby has a different concept of modules than Python. In Ruby, a Module is usually a class-like object that is mixed in, allowing for multiple inheritance type functionality in a single inheritance system. What's nice is that Ruby offers some very nice common built in modules that you can reuse in your own classes, such as 'Comparable' (offering overloads for comparison operators), 'Enumerable' (offering a lot of Python built-in functions as methods for collections of objects - equivalents of map(), min(), max(), etc...), and more. A pure pure pure OO system is a nice dream, and this feature makes Ruby closer in it's OO offerings to Smalltalk than to Python. But I have to admit that I actually prefer Python's module/package based system better (I'll address this further down). getter/setter methods for object attribute access ================================================= This is another feature offered by Python 2.2 and later, in new style classes. A problem that plagued Zope for a while was one didn't know if a certain common attribute would be an attribute, or a method - foo.title versus foo.title(). Some objects want to compute their title, or other attributes (ie - you may store a mailbox size attribute as bytes, but present it as megabyte to make it easier to view/edit - so why not compute?). Since Python 2.2 now offers this feature, which is not a critical one (just one that's quite nice), Ruby doesn't score too many points here any more either. But it was something that I liked when first evaluating the language. Static/Class methods ==================== Python 2.2 and later finally allow these as well. In a pure OO system like Ruby and Java, static method are very important when offering what would be module-level functions in Python. Basically, they're methods defined in a class that don't operate on an instance (typically the 'self' in Python). Class Methods operate on a class object instead of an instance. Between static and class methods, for example, you can define new constructors and place them in the class itself (not possible in older Python or old style classes). So what Ruby, Java, Objective-C, and other languages can offer are things like:: MyString.initFromFile(somefile) MyString.initFromURL(someurl) which would generate a new 'MyString' instance based on the contents of a file or URL. Python 2.2 has caught up on this feature as well. As others have stated - it's certainly *prettier* to define these types of methods in Ruby, but I imagine Python will improve in this area as time goes by. It's just nice to have these features available. Generators ========== Another cool feature that Ruby had that fascinated me when I looked at it that Python 2.2 coincidentally picked up. This is the 'yield' keyword, and it produces a lot of opportunities for lazily generating data to be iterated through. Again - Python 2.2 and later have this one, so it's a moot point now. But this was something that really excited me about Ruby when I saw it. 'blocks' ======== blocks...closures...anonymous functions. Whatever you want to call them, Ruby employs them throughout the language. These have been discussed en masse in this thread, I'm sure. It's no longer a deal breaker for me. For the most part, if a lambda or list comprehension expression don't offer me enough, writing a real named Python function is the better route to go, in my opinion. You can do a lot with lamda: expressions, and many parts of the system allow them (including the re module, where you can supply a function that takes a regex match object as its argument and do some calculations on it). >>> import re >>> flan = "I'm some flan & I'm < half off." >>> nonword = re.compile('\W') >>> quoted = nonword.sub(lambda m:'&#%s;' % ord(m.group(0)), flan) >>> quoted 'I'm some flan & I'm < half off.' Of course, for any detailed function, it's still better to write a full one: >>> def quoter(matchobj): ... """ look up values we know names for before using ord() """ ... good_values = { ... ' ': ' ', '<': '<', '>': '>', '"': '"' ... } ... match = matchobj.group(0) ... return good_values.get(match, "&#%s;" % ord(match)) ... >>> nuquoted = nonword.sub(quoter, flan) >>> print nuquoted I'm some flan & I'm < half off. In-Place versus Copy ==================== There's a long running Python situation where one wants a sorted list in the middle of an expression, for the sake of the expression only. Python only lets you do "foo.sort()" as a statement on its own. If you use this in an expression, it evaluates to "None", not a sorted list. Little battles over this show up on occasion in the Python world and have since the beginning of time. In Ruby, there's a difference between "foo.sort" and "foo.sort!" (parenthesis aren't required on method calls in Ruby). Ruby can use some punctuation in its method names, and the exclamation point is often used to indicate that this method will change the current object. "foo.sort!" in Ruby is equivalent to "foo.sort()" in Python (assuming 'foo' is a list). This isn't a huge dealbreaker in favor of Ruby. It's just nice. The use of punctuation to differentiate between inplace operations and i'll-return-a-new-modified-copy operations is a nice one. (Ruby also can have method names end in '?', which is often used for boolean methods. 'foo.isEmpty?' for example.) Ruby Issues and Python Strengths ================================ Ruby has a lot more issues for me now, and Python has some really strong features that differentiate it. Some of these features, in fact, go almost unnoticed because they're so smooth and make so much sense (see coming remarks about modules). Ruby is still more closely related to Perl than it is to Python. Ruby uses all of those shortcut expressions that I find terrible, like $_. Ruby uses other punctuation marks to mark what different variables, with name, $name, @name, and @@name all being different. While it's nice to differentiate between local, global, instance, and class variables, all of these extra punctuation 'shortcuts' get in the way of readability. In fact, it looks like it's quite easy to write unreadable code in Ruby. There are just lots of punctuation marks one has to get used to, and while it's easy to get used to them, I think it moves Ruby away from the "executable pseudocode" that most decent Python code can be. You wind up with statements like ``%w{@names}`` or ``print if ($. == 1)``. dollar-dot? what's that? Fortunately, Python's general "explicit is better than implicit" design means I never have to know. Ruby still has too much shell-script nature inside of it. One built in Ruby expression type is command expansion, or `foo`, where foo is a shell command. (You can also use %x, as in %x{echo "Hello There"}). Putting `uname -v` in your code will execute the Unix 'uname' command. The exit status of the command is in the cheerful global variable $?. As a result, I wonder how well Ruby works as an embedded language. Python and its sibling Jython have been embedded in a variety of systems to allow programmability. Some examples of this include 3D environments (I think 'Caligari Truespace' is one of these), UML tools, and more. In such systems, you don't want shell commands to be run. Yet Ruby has them as first class expressions. Python places operating system interaction into the flexible 'os' and 'os.path' modules, and there are the newer 'popenN' modules as well for running other processes from Python and getting the results back in. But - it's a very key feature of Python that it is not bound strongly to the Unix shell in any way. I don't know how much the `command` feature of Ruby is used, but it's still troubling (to me) that it is a first class expression. Python has modules. I love this fact about it. It got even better when multi-level packages were added as a core feature to the system. I don't know why, but using ``import package.module`` or ``from package.module import Class`` makes me so much happier than the alternatives I see in Ruby, Perl, and PHP. But Python modules and packages just add a nicer element to the language, and I believe that Modula 2 and/or 3 was one of the linguistic influences on Python. Ruby has two statements, and they just bother me. They seem to be nowhere nearly as clean as Python modules (or even Java packages): 'load' and 'require'. And they seem to behave slightly differently. load "filename.rb" "includes the name Ruby source file every time the method is executed". I wonder if that's a full path expression, like if you could do ``load "mypackage/file.rb"``, and if that expression would fail on Windows or the classic Mac OS (or any other operating system that uses a different path separator than Unix). Python Modules are free of that. require "filename" seems not to require the '.rb' extension, and seems closer to Python's imports, but I don't think it puts anything into a special namespace. With Python, you have to explicitly load blindly into your namespace with the "from foo import *" syntax. But it looks like if you do a ``require 'tk'`` command in Ruby, you're doing the equivalent of "from tk import *". Ruby has modules, but in a completely different sense than Python. Modules are namespaces defined within files, which can also be used as mix-ins to classes. While Python makes all subelement traversal use the '.' syntax (package.module.Class, instance.someMethod, etc), Ruby, adds more punctuation to get into modules, using the :: syntax (NameSpace::Example::CONST or NameSpace::Example.new). Man, the more I write, the more I really appreciate the simplicity of Python. We will do funny things with __underscores__, but even that's pretty consistent. Python also has the nice feature of compiling/caching modules, which can speed things up. I don't know if Ruby re-evaluates all code every time you start a Ruby program up, but I haven't really seen an equivalent to Python's '.pyc' and '.pyo' (optimized, generated when running with the -O option in Python) files. Ruby does have some nice things going for it, and I think that people looking for a good object oriented Perl would be happy with it. Personally, I think that Python is more mature, has better design influences (Modula and ABC instead of Perl and Smalltalk). A lot of the extraordinary features of Ruby seem to have found their way into recent Python versions. Python's built in OS abstraction layers (the 'os' module, etc) makes it easier to write multiplatform code (made even easier by universal newline support in Python 2.3, which helps deal with the "'\r', '\n', or '\r\n'?" situation). Python's explicit nature makes following code a lot easier - it's *usually* pretty easy to tell where a name is coming from, for instance. And it does all of this without abusing the sunday comic curse word character set {$@#:!}. Ruby also seems to have some other implicit behaviors, like:: def mult(n, fact) n * fact end the last statement in an expression is what's returned. You *can* use a return statement. But it's nice that Python always requires it (otherwise, you get 'None' as a result): def mult(n, fact): return n * fact it's just a nice touch. It's especially nice when you have to go into systems like Java and you have variables being used that take a while to process - "where's this name coming from? Oh, it's somewhere within the class, not local!". self.doThis() is much more understandable than just doThis(), especially when you start to stack up namespaces. In summary - there's nothing totally compelling about Ruby over Python for me, especially since Python 2.2 and 2.3 have come along and answered my own petty grievances. There are some cool features and aspects of Ruby, to be sure, but I'm pretty happy where I am. And Python always equals = batteries included! 92.7 times out of 103.5, there's a module that shipped with the distribution that will do something that you need to do. Time and again, I hear stories of "I was just about to write a whole blablabla module when it turns out that one was already there!" -- J.Shell From logiplex at qwest.net Thu Aug 7 13:44:46 2003 From: logiplex at qwest.net (Cliff Wells) Date: Thu, 07 Aug 2003 10:44:46 -0700 Subject: newbee : wxPython In-Reply-To: <1060246052.783343@wienet00038.ceu.heidelberg.com> References: <1060246052.783343@wienet00038.ceu.heidelberg.com> Message-ID: <1060278285.2221.2.camel@software1.logiplex.internal> On Thu, 2003-08-07 at 01:47, Bernd Lueth wrote: > Dear Group, > > I've tried to use wxDir / wxFile ( read about them in the wxwindows docs > coming with the wxPython distribution ) but somehow I'm not able to find out > how to import these classe(s). There are a lot of wxWindows classes that aren't mirrored in wxPython. The usual reason is that Python already provides an equivalent (or better) way of doing the same thing. Regards, -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 (800) 735-0555 From ny_r_marquez at yahoo.com Thu Aug 7 09:06:11 2003 From: ny_r_marquez at yahoo.com (R.Marquez) Date: 7 Aug 2003 06:06:11 -0700 Subject: Before I submit a bug report (Pythonwin) References: <8a27e309.0308061019.72656417@posting.google.com> Message-ID: <8a27e309.0308070506.60172bc6@posting.google.com> Oops, I realised this morning that my initial post has an error (that is what I get from writing from memory). I didn't upgrade from Python 2.2.2, but from Python2.3c1. And another significant detail is that I chose a completely different location on the disk for the 2.3 final installation. I wonder if Pythonwin is looking in the old Python2.3 location for something. I added Python2.3 to the path environment variable, and got the same results. I then went trough the registry searching for the old Python2.3 folder. I found an occurrance inthe following key: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32\OpenSaveMRU\exe I changed it to the new Python2.3 location, but Pythonwin still won't start. Any ideas? -Ruben ny_r_marquez at yahoo.com (R.Marquez) wrote in message news:<8a27e309.0308061019.72656417 at posting.google.com>... > I uninstalled my 2.2.2 version of Python and related packages from my > XP Professional station and proceeded to upgrade to the latest and > greatest: Python2.3, win32all-155.exe, etc. > > When I try to start the Pythonwin editor, either through its shortcut > or through right clicking on an existing module, a window pops up with > the message: > traceback>exceptions.ImportError: No module named > pywin.framework.startup > > After, closing the window nothing happens. > > I was able to start the editor by double clicking on: > Python23\Lib\site-packages\Pythonwin\start_pythonwin.pyw > > So, I assume the problem has to do with the installation process. > > This is the first time I have ever had a problem with Pythonwin (the > editor), so I'm a little surprised. Am I the only one having this > problem? > > -Ruben From ktilton at nyc.rr.com Wed Aug 20 19:51:05 2003 From: ktilton at nyc.rr.com (Kenny Tilton) Date: Wed, 20 Aug 2003 23:51:05 GMT Subject: What's better about Ruby than Python? References: <3F41505F.69D18CC8@alcyone.com> <66d7kvonvb2n0nqbqahhd5roak7ur81sob@4ax.com> <3f43ef5d_4@127.0.0.1> Message-ID: <3F440A35.9030602@nyc.rr.com> Chris Reedy wrote: > Doug Tolton wrote: > >> On Tue, 19 Aug 2003 13:43:11 +0200, Alex Martelli >> wrote: >> >>> Doug Tolton wrote: >>> ... >>> >>>> abstractions and better programmer productivity. Why not add Macro's >>>> allowing those of us who know how to use them and like them to use >>>> them. If you hate macros, or you think they are too slow, just don't >>>> use them. >>> .... > I'm curious. Why do you feel such a need for macros? With metaclasses, > etc., etc., what significant advantage would macros buy you? Do you have > any examples where you think you could make a significantly crisper and > easier to read and understand program with macros than without. This macro: (defmacro c? (&body code) `(let ((cache :unbound)) (lambda (self) (declare (ignorable self)) (if (eq cache :unbound) (setf cache (progn , at code)) cache)))) Let's me write this (for some slot of an instance): (c? (+ 10 (left self))) ;; self ala smalltalk Instead of this: (let ((cache :unbound)) (lambda (self) (declare (ignorable self)) (if (eq cache :unbound) (setf cache (+ 10 (left self))) cache))) The above macro is a toy version of the real thing, which expands to this: (make-c-dependent :code '((+ 10 (left self))) :rule (lambda (c &aux (self (c-model c))) (declare (ignorable self c)) (+ 10 (left self)))) Clearly (c? (+ 10 (left self))) is more readable; all the dataflow wiring is hidden. And the application is more maintainable should I decide to change the implementation of my dataflow hack. This kinda thing is when Lispniks use macros, to silently wrap code with infrastructure necessary to satisfy some frequently arising requirement. Especially cool above is that I capture the code in symbolic form in a separate slot for debugging purposes, as well as hand it to the compiler as the body of the lambda function. Took me way too long to think of that when I had no idea what lambda was backtracing. But as soon as I changed the macro, every (c? ) form (and there are hundreds) was debuggable. I think macros are no harder to learn than an API, and most Lispniks won't stray to any language that lacks procedural macros (ie, they are useful), so maybe it comes down to what someone else said in this thread: Python is not trying to be everything. Fair enough. Let Python be Python, let Lisp be Lisp. ie, If someone wants macros, they probably would also like special variables and closures and lexical scope and multi-methods and they may as well get it over with and learn Lisp and stop trying make Python more than it wants to be. -- kenny tilton clinisys, inc http://www.tilton-technology.com/ --------------------------------------------------------------- "Career highlights? I had two. I got an intentional walk from Sandy Koufax and I got out of a rundown against the Mets." -- Bob Uecker From max at alcyone.com Thu Aug 7 23:53:39 2003 From: max at alcyone.com (Erik Max Francis) Date: Thu, 07 Aug 2003 20:53:39 -0700 Subject: ANN: EmPy 3.0.4 -- A powerful and robust templating system for Python Message-ID: <3F331EC3.3F8D72E6@alcyone.com> Summary A powerful and robust templating system for Python. Overview EmPy is a system for embedding Python expressions and statements in template text; it takes an EmPy source file, processes it, and produces output. This is accomplished via expansions, which are special signals to the EmPy system and are set off by a special prefix (by default the at sign, '@'). EmPy can expand arbitrary Python expressions and statements in this way, as well as a variety of special forms. Textual data not explicitly delimited in this way is sent unaffected to the output, allowing Python to be used in effect as a markup language. Also supported are callbacks via hooks, recording and playback via diversions, and dynamic, chainable filters. The system is highly configurable via command line options and embedded commands. Expressions are embedded in text with the '@(...)' notation; variations include conditional expressions with '@(...?...!...)' and the ability to handle thrown exceptions with '@(...$...)'. As a shortcut, simple variables and expressions can be abbreviated as '@variable', '@object.attribute', '@function(arguments)', '@sequence[index]', and combinations. Full-fledged statements are embedded with '@{...}'. Control flow in terms of conditional or repeated expansion is available with '@[...]'. A '@' followed by a whitespace character (including a newline) expands to nothing, allowing string concatenations and line continuations. Comments are indicated with '@#' and consume the rest of the line, up to and including the trailing newline. '@%' indicate "significators," which are special forms of variable assignment intended to specify per-file identification information in a format which is easy to parse externally. Context name and line number changes can be done with '@?' and '@!' respectively. Escape sequences analogous to those in C can be specified with '@\...', and finally a '@@' sequence expands to a single literal at sign. Getting the software The current version of empy is 3.0.4. The latest version of the software is available in a tarball here: http://www.alcyone.com/pyos/empy/empy-latest.tar.gz. The official URL for this Web site is http://www.alcyone.com/pyos/empy/. Requirements EmPy should work with any version of Python from 1.5.2 onward. It has been tested with all major versions of CPython from 1.5 up, and Jython from 2.0 up (using Java runtimes 1.3 and 1.4). The included test script is intended to run on Unix-like systems with a Bourne shell. License This code is released under the GPL. ... Release history [since 3.0.3] - 3.0.4; 2003 Aug 7. Somewhat more robust lvalue parsing for '@[for]' construct (thanks to Beni Cherniavsky for inspiration). From guettler at thomas-guettler.de Fri Aug 22 09:20:42 2003 From: guettler at thomas-guettler.de (Thomas =?ISO-8859-15?Q?G=FCttler?=) Date: Fri, 22 Aug 2003 15:20:42 +0200 Subject: OT: Error Code for Spam-Warnings Message-ID: Hi! Off topic: Aint there a error-code RFC for emails which are created by spam filters? Something like X-Spam-detected: yes X-Spam-scanner: .... If there would be such a RFC, and virus checker implement this, mailman could delete these messages, without sending them to list. By the way, this would be very handy for "Unkown User, "Mailbox full" etc, too. From niemeyer at conectiva.com Thu Aug 21 17:20:20 2003 From: niemeyer at conectiva.com (Gustavo Niemeyer) Date: Thu, 21 Aug 2003 18:20:20 -0300 Subject: tarfile woes In-Reply-To: References: Message-ID: <20030821212020.GA8145@ibook.distro.conectiva> > - bzip2 compressed files cannot be read from a "fake" (StringIO) file > object, only from real files. This is (imho) unbelievably ugly, as > I have the file already in a string. I really do not want to read it > a second time. Or a third time, when the user finally decides that > she wants the archive actually unpacked (second was TOC listing). > > - It does not handle compressed (.Z) archives. Of course there's > noone to blame. The gzip utility (which is used by gnu tar) handles > this ancient algorithm, but apparently, zlib does not. :-( >>> import bz2 >>> print bz2.decompress.__doc__ decompress(data) -> decompressed data Decompress data in one shot. If you want to decompress data sequentially, use an instance of BZ2Decompressor instead. >>> import gzip >>> print gzip.__doc__ Functions that read and write gzipped files. The user of the file doesn't have to worry about the compression, but random access is not allowed. >>> import tarfile >>> print tarfile.open.__doc__ Open a tar archive for reading, writing or appending. Return an appropriate TarFile class. mode: 'r' open for reading with transparent compression 'r:' open for reading exclusively uncompressed 'r:gz' open for reading with gzip compression 'r:bz2' open for reading with bzip2 compression 'a' or 'a:' open for appending 'w' or 'w:' open for writing without compression 'w:gz' open for writing with gzip compression 'w:bz2' open for writing with bzip2 compression 'r|' open an uncompressed stream of tar blocks for reading 'r|gz' open a gzip compressed stream of tar blocks 'r|bz2' open a bzip2 compressed stream of tar blocks 'w|' open an uncompressed stream for writing 'w|gz' open a gzip compressed stream for writing 'w|bz2' open a bzip2 compressed stream for writing -- Gustavo Niemeyer http://niemeyer.net From edob at homemail.com.au Tue Aug 26 05:17:15 2003 From: edob at homemail.com.au (XXX) Date: Tue, 26 Aug 2003 09:17:15 GMT Subject: Comments on my "Python Introduction" slides References: <33803989.0308240000.35b9bf1f@posting.google.com> Message-ID: <3f4b2599@news.comindico.com.au> Miki Comments from an old programmer (but an absolute beginnner in Python) I think it looks good - I picked up a few useful hints. Re: slide 6 on data types - it implies integer only for numeric types - I'd suggest mentioning floating point, arbitrary length numbers (this is implied in slide 5 on Fibonacci) and, of course, complex numbers are very important for some uses. -- Eddie O'Brien Remove XORY from address to reply "Miki Tebeka" wrote in message news:33803989.0308240000.35b9bf1f at posting.google.com... > Hello All, > > I'll be doing a small internal course on Python at my company. > The 1'st session is an introduction that should also sell Python. > > If you have the time I'd appriciate any comments on my slides at > http://www.cs.bgu.ac.il/~tebeka/pyintro.html > > Keep in mind that the "students" are people writing real time and use > scripting mostly for small applications that usually communicate with > hardware, parse binary files, etc. > > TIA. > Miki From dave at pythonapocrypha.com Mon Aug 18 14:30:36 2003 From: dave at pythonapocrypha.com (Dave Brueck) Date: Mon, 18 Aug 2003 12:30:36 -0600 Subject: What's TOTALLY COMPELLING about Ruby over Python? In-Reply-To: References: Message-ID: <200308181230.36167.dave@pythonapocrypha.com> On Monday 18 August 2003 12:07 pm, Brandon J. Van Every wrote: > I'm realizing I didn't frame my question well. > > What's ***TOTALLY COMPELLING*** about Ruby over Python? What makes you > jump up in your chair and scream "Wow! Ruby has *that*? That is SO > FRICKIN' COOL!!! ***MAN*** that would save me a buttload of work and make > my life sooooo much easier!" Nothing. -Dave From mmuller at enduden.spam.filter.com Fri Aug 1 11:30:44 2003 From: mmuller at enduden.spam.filter.com (Michael Muller) Date: Fri, 01 Aug 2003 15:30:44 GMT Subject: Static typing References: <3f218ef1$0$27926$626a54ce@news.free.fr> <3f219c8d$1@nntp0.pdx.net> <3f23ae06$0$21093$626a54ce@news.free.fr> <20030727.141111.1139901474.9957@demon.mindhog.net> <3f244eff$0$21092$626a54ce@news.free.fr> Message-ID: <20030801.113055.213975407.14885@demon.mindhog.net> In article <3f244eff$0$21092$626a54ce at news.free.fr>, "Bruno Desthuilliers" wrote: > It's a management problem, not a programming language issue. Well, I really don't care to argue the issue, but I will say that I personally prefer a technical solution (e.g. static types) to a management solution (e.g. me reading everybody's code and smacking them with a Big Stick(tm) when they don't comply). > Well... Objective C is compiled to machine code, and still has dynamic > binding (not late binding as in C++), so static typing does not seem > mandatory here. For the record, Objective C has the same problem. If you look through the library, method resolution is implemented using a runtime lookup. It's basically C with an embedded interpreter. -- Remove the spam and filter components to get my e-mail address. From hans at zephyrfalcon.org Fri Aug 15 18:47:27 2003 From: hans at zephyrfalcon.org (Hans Nowak) Date: Fri, 15 Aug 2003 18:47:27 -0400 Subject: recursive traversal of file In-Reply-To: References: Message-ID: <3F3D62FF.4050007@zephyrfalcon.org> Xavier Decoret wrote: > I am reading the lines of a file, executing appropriate command if a > pattern is found. One of the pattern can be a input command whose effect > should be to #include the file (possibly recursively) > > The main loop looks like this: > > data=[] > > try: > file = open(fileName) > line = file.readline() > while line: > if matchInputPattern(line,inputFile): > # help me here to parse inputFile > elif matchDataPattern(line): > data.append(1) > line = file.readline() > except IOError, e: > print 'I couldn\'t open file name',fileName > sys.exit(1) > > Can you tell me if there is a simple way to do the part that says #help > me!. Should I do a recursive function? You could wrap all this in a function, let's call it import_file or whatever. Then, upon encountering the #include pattern, you could do, if matchInputPattern(line, inputFile): import_file(some_filename_extracted_from_pattern) This *should* work, although I didn't test it. Also, it assumes that recursive function calls share the same list ('data'). It would be cleaner to have import_file create, fill and return its own list. In pseudocode: def import_file(filename): data = [] ... for line in lines: if (pattern matches): z = import_file(filename_from_pattern) data.extend(z) ... return data HTH, -- Hans (hans at zephyrfalcon.org) http://zephyrfalcon.org/ From tzot at sil-tec.gr Sat Aug 23 09:06:12 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Sat, 23 Aug 2003 16:06:12 +0300 Subject: Compile for IBM Mainframe + performance References: Message-ID: <06pekv881seks75h0p892mvhk0kijjqplb@4ax.com> On Tue, 19 Aug 2003 10:49:04 +0200, rumours say that "Jaco van Tonder" might have written: >Hi There Hi Jaco >We are currently busy with a conversion project on substantial data volumes >using python. >Conversion program currently compiled for AIX, Sun and NT . "Conversion program currently compiled"... seems you are rewriting in Python an already existing program? >There is a direct relation between the size of the processors and the speed >of the program(Hence NT platform outperforming AIX and Sun). By size I presume you mean MHz speed? Obviously not the physical size of the processor (although the latter allows for more electrons running wild inside the CPU :) >Is there any suggestions on how the speed of the program might be improved. Sure: I suggest you make it faster (generic answer for a generic question :) >Is it possible to compile python for a Mainframe(IBM) environment. Yes it is, others have done it for AIX. In case you don't have a C compiler for your (generic) IBM Mainframe, try installing the gcc compiler; there must be some "official" installation offered by IBM or by others. It's possible though that the python executable will be faster if compiled with the IBM compilers (this is the case for SGI Irix, MIPSPro-compiled python is faster than gcc-compiled one). >Are there any special patches or considerations that have to be taken into >account when compiling for the Mainframe environment. You'll have to search google (and groups.google.com) with some relevant keywords. Then, you might come back with more specific questions. -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From wiebke.paetzold at mplusr.de Tue Aug 12 04:11:47 2003 From: wiebke.paetzold at mplusr.de (Wiebke Pätzold) Date: Tue, 12 Aug 2003 10:11:47 +0200 Subject: union in Python Message-ID: import sys Hi all, At the beginning there is a table (database) with different columns. So I create a search operator to look for regular expressions. First I start the search only in one column and the program run. Now I want to expand the search. The search have to take place in 2 columns. In my example it is "Themenbereiche" and "Nachname". I tried something. But the program doesn't run. Can somebody help with the release of the error? import Mk4py import re db = Mk4py.storage("c:\\datafile.mk",1) vw = db.view("people") class PatternFilter: def __init__(self, pattern, feld): self.feld = feld self.pattern = re.compile(pattern) def __call__(self, row): try: exec(self.feld+" = row."+self.feld) except AttributeError: return 0 return self.pattern.search(eval(self.feld))is not None def union1(feld_th, feld_na): result = [] for i in feld_th+feld_na: if i not in result: result.append(i) return result def union2(feld_th, feld_na): result = {} for i in feld_th+feld_na: tmp[i] = 1 return tmp.keys() feld_th = "Themenbereiche" vf = vw.filter(PatternFilter("do.*", feld_th)) feld_na = "Nachname" vf = vw.filter(PatternFilter("im.*", feld_na)) print feld_th, feld_na, union1(feld_th, feld_na) print feld_th, feld_na, union2(feld_th, feld_na) From jjl at pobox.com Sun Aug 24 09:02:50 2003 From: jjl at pobox.com (John J. Lee) Date: 24 Aug 2003 14:02:50 +0100 Subject: macro FAQ References: Message-ID: <878ypjjjid.fsf@pobox.com> Jacek Generowicz writes: > "Andrew Dalke" writes: > > > Here's a proposed Q&A for the FAQ based on a couple recent threads. > > Appropriate comments appreciated > > Such an FAQ item is probably a good idea. > > However, I think that we should distil out much of the opinion > (particularly the opinions about opinions of others :-) and try to > base it on fact: I disagree. People reading a FAQ do want to know the opinion of language users, and more importantly, of Guido, because that's what explains why the language is as it is, and determines what will happen in the future. That's fact too, just fact about people's opinions. > - what are macros (C-like and Lisp-like), > > - what are the technical difficulties with introducing them into > Python Arguably, these are both secondary issues given the fact that both Guido (I presume?) and most Python users don't want macros. Obviously some background should be in there explaining what macros are and how they might apply to Python, but Andrew did just that. [...snip useful technical criticism of Andrew's FAQ...] > Could you please give me a reference to someone "with plenty of > experience using macros in Lisp" arguing this ? Maybe he was referring to Laura Creighton? He posted a quote and a link to another of her posts. [...snip more technical points...] > But then, functions which provide an abstraction are also more > difficult to write and understand than ones which merely "move code > out of the way", and you'd have to think twice whether the abstraction > is really useful, before deciding to pay the price for writing it, and > making readers understand it. I'm amazed that you say this. I think most programmers would disagree with you here (certainly I do). Sure, abstract functions require some work to understand the concept involved, but the important way in which one function is easier or harder to understand than another has to do with how much detail you need to know, not how hard the concepts are. Needing to know details causes bugs. So does needing to know concepts (though less often), but you can't get rid of the concepts, whereas you *can* hide the details. And that's what abstraction is: hiding details. (and there's no need to answer here that you think macros are a good way of hiding detail: we've gathered that ;-) [...] > People in the music software "group" will find it hard to use code > from people writing software for bioinformatics ... with or without > macros. This has nothing to do with macros. But people writing code using one bioinformatics library will not find it hard to read code using another. That might not be the case if macros were built-in. > OK, I promised some examples of macros. Note that I have not shown a > single line of Lisp code in these threads, because I agree that it is > likely to be meaningless to most readers of this group. I'll try > continue without having to resort to Lisp examples. > > ==== Example 1: a debugging aid ================================ > > One litte macro I have for debugging purposes (let's call it "show"), > allows me to print out the source code of a number of expressions, > along with their values. At this point, note that Python's horribly [...] > The "function" version of the show macro invocation: > > show(sin(x), a, a + b + c) [...is equivalent to...] > print "sin(x) =>", sin(x) > print "a =>", a > print "a + b + c =>", a + b + c [...] > Can this be implemented using metaclasses, or any other existing > Python mechanism ? Yes, using Lisp ;-P -- you can do this in Python with an emacs macro. > === Example 2: Alexander Schmolck's updating classes =============== > > Alexander recently expressed the desire to have all existing instances > of a class be updated, when he changes the source of his class, and > re-evaluates the definition. [...] There was a thread recently about how the problem behind this might be solved in Python. I started it (a search for "DOM" or "4DOM" or "hierarchy" and my email address should turn it up). No, wait a minute -- instances, not classes?? Sounds like an abuse of the language to me. What *is* the underlying problem to be solved here? John From martin at v.loewis.de Sat Aug 9 11:39:12 2003 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 09 Aug 2003 17:39:12 +0200 Subject: Python for .NET preview 2 release In-Reply-To: References: <5t_Ya.102789$YN5.72026@sccrnsc01> <87u18rx84u.fsf@pobox.com> Message-ID: Bryan wrote: > but kobra is a way to scripts .NET services from python, and is supposedly very fast and efficient. wasn't there a pycon speech > about this? is this the same Python.NET that was referenced in that speech? Probably, but not in the section you quote. Instead it is this: 1. Use C#/PInvoke to access Python structures at the native level e.g. Python scripting for .NET by Brian Lloyd (http://www.zope.org/Members/Brian/PythonNet/index_html) > sorry, i was under the impression that all the different python .NET solutions > were giving way to Kobra as being the best python solution. Maybe your impression is wrong. Apparently, Brian Lloyd is not "giving way". It isn't clear to me, either, why Kobra would be the best solution when Python for .NET actually runs on Mono, whereas Kobra doesn't... > i thought the python community as a whole was going to rally around it.... I doubt that the Python community as a whole cares very much about .NET This is free software. There is no centrally-controlled grand plan, except for the PSU plans of course, but I can't talk about these. Regards, Martin From tjreedy at udel.edu Tue Aug 26 11:56:41 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 26 Aug 2003 11:56:41 -0400 Subject: Advice to a Junior in High School? References: Message-ID: "Howard Nease" wrote in message news:Ivw2b.1305$Ce2.314 at clmboh1-nws5.columbus.rr.com... > have heard a whole lot about the fact that the market for software engineers > nowadays is *HORRIBLE*, and that I should double major or perhaps go into a > field of study in which I'm not very interested. The demand for software engineers has fluctuated up and down, in various industries and regions, for decades. An article in the current Business 2.0 on the 'coming labor shortage' points out that you are part of the first generation in America to be numerically smaller than your parents generation. In ten years, when boomers have or are retiring, there will probably be a relatively shortage of tech workers. TJR From kern at taliesen.caltech.edu Mon Aug 11 03:36:28 2003 From: kern at taliesen.caltech.edu (Robert Kern) Date: Mon, 11 Aug 2003 07:36:28 +0000 (UTC) Subject: Slogan: Getting Rich Overnight References: Message-ID: In article , Christian Tismer writes: > Ben Finney wrote: > >> On Sun, 10 Aug 2003 23:56:01 +0200, Christian Tismer wrote: >> >>>But is there any way for such a slogan to pass spam at all? >> >> >> The much greater battle is: if it passes electronic/programmatic >> filters, how are you going to get it past the wetware filters -- i.e., >> the fact that it just sounds like spam when you hear it? > > It does not sound like spam when you read it. > Getting you to read it is the trick. Yes, but I think Ben's point is that there are more "filters" that go between the eyeballs ("seeing") and actual comprehension ("reading"). I know that my brain often scans the gross meaning of the words to determine interest before it actually reads for comprehension. Usually, this mode of operation kicks in for activities like scanning subject lines of USENET articles or seeing a T-shirt slogan. Now, the situations where your slogan might be used may not trigger this "mode". On the other hand, it still triggers another "filter" in my head. I simply don't read "get rich {quick,fast,overnight}" and the like as meaningful phrases anymore. Your article is the first time in years that I have seen it used in any context besides a scam. I have to try hard to read "Python makes you rich, overnight" and extract the intending meaning from it. >>>If I remove the ambiguity, the slogan gets lame. >> >> Anything with "get rich {quick,fast,overnight}" already has far too many >> negative connotations to sound un-lame. > > Right. But is this my fault? No, of course not. It is simply an unfortunate coincidence that an incredibly apt way of describing the Python experience has been used by scammers for much, much longer, probably since the beginning of modern English. (I'm working from a US monophone's perspective here. The slogan may work perfectly well in other languages or countries with different scams. I can't address those possbilities.) >> Choose another slogan, forget the "get rich" nonsense. While the >> sentiment is great, and I agree it's a wonderful feeling when you >> realise how much your options have increased with little effort, the >> "get rich overnight" just doesn't jibe with me. > > Yeah, true. The bare fact that "getting rich overnight" has > become something that we regard as spam: > Isn't that telling us a *very very* bad story? > The spammers *have* won, we are playing *their* games. > Can you see it? I don't think it works that way. I'm positive that scammers would much prefer that we give as much attention to their slogans as we do to things that really matter to us. The desensitization that comes from overuse of certain phrases hurts them, too. That's why you now see spam e-mails with conversational subjects like "Hey, listen to this" as if they came from your friend. They really, really, really want you to associate "Get Rich Quick!" with "Great opportunity I should really look into", not "Scam: Ignore". Yes, it has some sad effects in this case, but desensitization is a perfectly natural (and in most cases, beneficial) adaptation to overstimulus. If I gave every spam email or scam flyer the same attention I would like to give "Python makes you rich, overnight", I'd go nuts. It's not just my email (which SpamBayes takes care of quite nicely); "Get Rich Quick!" flyers cover just about every telephone pole I bike past. Since SpamBayes does not (yet!) interface with my eyeballs, my wetware filters are the best I've got. However, their false positive rates are not yet as low as SpamBayes'. I may be idiosyncratic in this, however. I'm particularly intolerant to overuse of certain phrases. "Terror" lost its meaning to me about an hour into 2001-09-11. And perhaps only English-speaking US is really affected this way. I don't know. >> The feeling isn't one of being (financially) rich; it's one of being >> free from restrictions. Another thread recently mentioned the idea >> that, opposed to other languages, Python lets you go home on time. >> That's closer to the mark. > > Fine. And you let spammers dictate to you what they want > you to think? I do think this is going way too far. > We have already allowed them to get too far. > Did I say anything bad? Nothing at all, this was said by > other people. And those are dictating to us, what to say > and what not to say. > SHould we really continue to support this? Come on, there's no need to take this personally. It's a great slogan that succinctly describes the almost-revelatory experience of the Python newbie. Unfortunately, it is surrounded by circumstances beyond your or my control that hamper its potential in certain situations. -- Robert Kern kern at caltech.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter From dedoleo at hotmail.com Fri Aug 1 15:58:16 2003 From: dedoleo at hotmail.com (Dedoleo) Date: 1 Aug 2003 12:58:16 -0700 Subject: Clicking a button on an web page. Message-ID: <28158ea1.0308011158.6cac0091@posting.google.com> I have read through the tutorials for Python and looked at the web related stuff. Unfortunately, the tutorials only mention how to use scripts locally and the web related stuff, well that's local too. How should I go about writing a script that will simply click a button on a web page at an interval? For example, if you're familiar with Neopets, I'd like to click the Collect Interest button around 1am everyday. :) From mjais at web.de Tue Aug 12 02:37:27 2003 From: mjais at web.de (Markus Jais) Date: Tue, 12 Aug 2003 08:37:27 +0200 Subject: Is Python your only programming language? References: Message-ID: Joe Cheng wrote: > I'm curious about something... many Artima.com members who have a Java > background and learned Python have come to the conclusion that Java and > Python are highly complimentary languages. They would never consider > filling the place Java has in their toolbox with Python, but recognize > there are many tasks where it really pays to add Python to the mix. > > I want to ask you hard-core c.l.p Pythonistas: Do you use Python for > everything? (and I'm counting Python + C extensions as just Python) Or > do > you keep another language equally close at hand, and if so, what is it? > And finally, do you foresee a day when Python can be, for all practical > intents and purposes, your only programming language? at work I use mainly java and C. at home when I programm for myself I normally use Python or Ruby. it depends on the libraries available. I like both and use both. I rarely use C or Java at home because with Python or Ruby I am much faster in developing a solution. and I never use C++ at home. and sometimes I play with PHP and Perl. just for fun. Markus From fredrik at pythonware.com Tue Aug 12 05:32:19 2003 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 12 Aug 2003 11:32:19 +0200 Subject: Importerror no module named WIN32API References: <5f5c82ec.0308110740.550d5f43@posting.google.com> <5f5c82ec.0308120038.20c6f70d@posting.google.com> Message-ID: Matt Smith wrote: > > > ImportError: No module named win32api > > > > > > Any clues as to how to rectify this problem would be greatly > > > appreciated > > > > Maybe you need to install the win32all extensions on the Win98 machine? > > http://starship.python.net/crew/mhammond/ > > jf was that supposed to be funny ? > > no i would like a serious answer to this problem, as it is seriously hampering > my current project. have you checked the "Installation Problems" page (available via the funny link)? http://starship.python.net/crew/mhammond/win32/InstallationProblems.html have you checked that win32api is installed, and that python is picking up the right win32api version? have you checked the python path? have you traced the imports (use "python -v" or "python -vv" to run the program)? if win32api exists, what happens if you import it from the python prompt? are all DLLs that win32api depends upon available on your machine (google for DLL dependency checkers, or use "dumpbin /imports" to check what it relies on). etc. From grisha at ispol.com Thu Aug 28 16:26:25 2003 From: grisha at ispol.com (Gregory (Grisha) Trubetskoy) Date: Thu, 28 Aug 2003 16:26:25 -0400 Subject: Bayesian kids content filtering in Python? Message-ID: <20030828161409.V40715@onyx.ispol.com> I've been snooping around the web for open source kids filtering software. Something that runs as an http proxy on my home firewall and blocks certain pages based on content. It occured to me that this might be an interesting project to be done in Python, probably using the same training and scoring mechanism that spambayes uses. Anyway - I wonder if anyone has already tried something like this? Grisha From nhodgson at bigpond.net.au Mon Aug 11 17:37:24 2003 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Mon, 11 Aug 2003 21:37:24 GMT Subject: Rekall docs ready for download References: <3f380ac5$0$239$fa0fcedb@lovejoy.zen.co.uk> Message-ID: Hi John, > The Rekall documentation of available from http://www.totalrekall.co.uk and > http://www.rygannon.com. > You find them in PDF, HTML and Windows HTML Help format The Documentation page now displays: "I don't like you...". Hopefully this is just an oversight ;-) The URL in question is http://www.totalrekall.co.uk/modules.php?name=Downloads&d_op=viewdownload&cid=4" Neil From max at alcyone.com Sat Aug 23 15:27:02 2003 From: max at alcyone.com (Erik Max Francis) Date: Sat, 23 Aug 2003 12:27:02 -0700 Subject: Modifying the {} and [] tokens References: <04cekv0s6ghjtuhl5j2gph7ltobdb5rsam@4ax.com> <2259b0e2.0308230718.53d22c14@posting.google.com> <774fkvg920qibnnp83r17inqmk311tqcsv@4ax.com> Message-ID: <3F47C006.1C730829@alcyone.com> Geoff Howland wrote: > On 23 Aug 2003 08:18:49 -0700, mis6 at pitt.edu (Michele Simionato) > wrote: > > >Subclass dict, define __add__ and __sub__ and it will work, but NOT > >with the brace syntax. You must use something like > > > >mydict(a=1,b=2)+mydict(c=3,d=4) > > Yeah, I got this to work off the bat. So what's the problem? If you got it to do what you wanted, why would you possibly want your personal changes reflected officially in the language? Sit back for a moment and think what would happen if _everybody_ proceeded this way. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ Wars may be fought with weapons, but they are won by men. \__/ Gen. George S. Patton From mark at hahnca.com Fri Aug 29 15:54:21 2003 From: mark at hahnca.com (Mark Hahn) Date: Fri, 29 Aug 2003 12:54:21 -0700 Subject: Binary data handling ? References: Message-ID: What you are trying to do in general won't work. Any combination of 0x0d0a that was in the original data will be corrupted by your code. There is no way to "fix" the data once the web server has corrupted it. "Bill Loren" wrote in message news:mailman.1062079383.31727.python-list at python.org... > Hello ppl, > > I'm having difficulties to accomplish some simple chores with binary data. > I'm having a string (?) which I received via an HTTP transactions which is a > binary file. > Problem is the webserver I'm communicating with injected a \x0D before every > \x0A, > and I need to remove those 0x0D characters from my buffer before saving it > to disk. > > any ideas ? > > I tried the following without any success: > string.replace("%c%c" % (13,10), "%c" % (10)) > string.replace("\x0d\x0a", "\0x0a") > > thx > ~B > > From irmen at -NOSPAM-REMOVETHIS-xs4all.nl Sun Aug 17 18:08:13 2003 From: irmen at -NOSPAM-REMOVETHIS-xs4all.nl (Irmen de Jong) Date: Mon, 18 Aug 2003 00:08:13 +0200 Subject: Path Problem on W2K? In-Reply-To: <96S%a.2489$k_7.1163@newssvr27.news.prodigy.com> References: <93f5c5e9.0308170927.6e0bdc38@posting.google.com> <96S%a.2489$k_7.1163@newssvr27.news.prodigy.com> Message-ID: <3f3ffcca$0$49113$e4fe514c@news.xs4all.nl> Dennis Reinhardt wrote: >>I generally avoid installing in > > c:\ProgramFiles\anything. Related, but off-topic at the same time, I've seen many programs on Windows that barf on the default TEMP directory on Windows 2000 and XP. That is defined as somewhere in c:\documents and settings\username\temporary files or something. Anyway, it contains one or more spaces. Many -broken- tools (mostly installers!) choke on this, that's why I always set TEMP (and TMP) to "C:\temp" as soon as I get my hands on a 'clean' Win2000/Xp box... (yup, get rid of the per-user-tempdir). Bah. ;-) spaces-in-paths-are-evilly-y'rs, Irmen de Jong From tim.one at comcast.net Mon Aug 4 16:05:27 2003 From: tim.one at comcast.net (Tim Peters) Date: Mon, 4 Aug 2003 16:05:27 -0400 Subject: open('.', 'rb') on python 2.3 In-Reply-To: <20030804194657.GA6706@arm.k83.ath.cx> Message-ID: [Arkadiusz Miskiewicz] > [root at maja rdiff-backup]# python > Python 2.3 (#1, Jul 31 2003, 10:41:08) > [GCC 3.3 (PLD Linux)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import os >>>> fp = open('.', 'rb') > Traceback (most recent call last): > File "", line 1, in ? > IOError: [Errno 21] Is a directory > > > but works in 2.2 > [arekm at perfo arekm]$ python > Python 2.2.2 (#1, Dec 28 2002, 23:32:35) > [GCC 2.95.4 20010319 (prerelease)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import os >>>> fp = open('.', 'rb') >>>> > > Is that bug, bugfix, change in python 2.3? (patch of course welcome) > > System is Linux 2.4.21, glibc 2.3.2, filesystem ext3, xfs. Bugfix; see http://www.python.org/sf/487277 From aahz at pythoncraft.com Sat Aug 16 19:38:00 2003 From: aahz at pythoncraft.com (Aahz) Date: 16 Aug 2003 19:38:00 -0400 Subject: CDR Support References: Message-ID: In article , python newbie wrote: > >I'm starting to write a simple backup program using wxPython. But I >figure I might as well support rewritable CDROM that most people use. ( >I still don't have one, that's just wrong). > >Does anyone have knowledge of support for rewriteable CDROM's in >python? Is this for Linux or something else? I'd suggest that you simply write a wrapper around mkisofs and cdrecord. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From amk at amk.ca Tue Aug 19 12:18:34 2003 From: amk at amk.ca (A.M. Kuchling) Date: Tue, 19 Aug 2003 11:18:34 -0500 Subject: Unification of logging in Python's Standard Library References: <3a8e83d2.0308182217.7ccaf883@posting.google.com> Message-ID: On Tue, 19 Aug 2003 10:06:26 -0500, Skip Montanaro wrote: > Matthew> A single, unified logging system across the entire Python > Matthew> Standard Library would be a worthy goal for some future release > Matthew> (Python 3000, or maybe even 2.4/2.5?). > Another alternative is to write a PEP, though I don't think this is > necessarily required for this particular task. It also presents a higher > barrier to action than a bug report. I suspect a PEP is required, because there are more issues here than just changing sys.stderr.write() to logging.info(). For example, what logger should modules use to log messages? If they use the root logger, it will be difficult to discard messages from asyncore while keeping messages from the ZODB. If they use a particular logger, how is this name chosen? Is it dependent on the module name, so asyncore logs to 'asyncore' and so forth? What if my application has a logger named 'network', and I want it to go to 'network.asyncore', 'database.ZODB', etc.? If the user specifies a logger, how is this done? Does every public method have to grow an optional 'log' argument, or is there a module-level global setting, so you'd call asyncore.set_logger(logging.getLogger('network.asyncore'))? None of these options are very difficult to implement, but choosing which one will take some care; otherwise we'll be saddled with an inconvenient implementation that we'll be forever working around. --amk From glauco at sferacarta.com Fri Aug 22 06:14:34 2003 From: glauco at sferacarta.com (Glauco) Date: Fri, 22 Aug 2003 10:14:34 GMT Subject: while (assignment): References: <840592e1.0307291501.42b1156e@posting.google.com> Message-ID: Hannu Kankaanp?? wrote: > Sybren Stuvel wrote in message news:... > >>while info = mydbcursor.fetchone(): >> print "Information: "+str(info) > > > Typically this is done by breaking out of the loop: > > while True: > info = mydbcursor.fetchone() > if not info: > break > print "Information: "+str(info) > > (at least as far as I know) for myidRecord in range(mydbcursor.rowcount): info = mydbcursor.fetchone() print "Information: "+str(info) For a similar problem ( only for eliminate fetchall ) we have created a class iterator on cursor. Glauco From tim.one at comcast.net Mon Aug 11 17:29:37 2003 From: tim.one at comcast.net (Tim Peters) Date: Mon, 11 Aug 2003 17:29:37 -0400 Subject: [PSF-Members] PayPal Donation Page In-Reply-To: Message-ID: [Steve Holden] > Has anyone noticed odd problems with this page, or is it just me? > > Here I am, trying to give money via > https://www.paypal.com/cgi-bin/webscr and whenever I click on the > "Continue" button it stays in "button-down" mode and the window locks > up. > > In fact, dammit, this happens even when I try to just log in at > www.paypal.com - anyone seen this behavior on Windows 2000? Sorry(?), I haven't. To be sure, I just logged into my PayPal acct on a Win2K box, using IE6, without problems. From robin at jessikat.fsnet.co.uk Sat Aug 30 09:04:02 2003 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Sat, 30 Aug 2003 14:04:02 +0100 Subject: Win32 documentation in CHM? References: Message-ID: In article , James Kew writes >"Robin Becker" wrote in message >news:CDURXJA3QHU$EwUz at jessikat.fsnet.co.uk... >> The argument is made that .chm is a better mechanism (more searchable >> indexable etc) for help/documentation than html. Is that really so? > >I've certainly found it so in the ActiveState distribution, which packages >the Python docs, plus selected third-party docs -- win32all, Dive Into >Python -- into a unified HTML Help package. Very, very handy to be able to >quickly look things up in a common index, or search across the whole lot. > >(Still waiting for a 2.3 ActiveState distro, though...) > >James > > the previous poster mentioned decompilers, can one then add other links and then recompile with such beasts? I like being able to down load someone's pdf slides on meta classes into python/doc/xtras and then add a link to them to the main help index. I am also fairly religious about not using IE. -- Robin Becker From ruoruo at 263.sina.com Fri Aug 29 12:09:21 2003 From: ruoruo at 263.sina.com (Sun Wei) Date: Sat, 30 Aug 2003 00:09:21 +0800 Subject: making extension with MinGW on Windows Message-ID: I got this error: undefined reference to `_imp___Py_NoneStruct' But when I used VC++, everything is ok, why??? From alanmk at hotmail.com Mon Aug 18 17:14:46 2003 From: alanmk at hotmail.com (Alan Kennedy) Date: Mon, 18 Aug 2003 22:14:46 +0100 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: <3F41208F.40021A68@engcorp.com> Message-ID: <3F4141C6.5A1FFE71@hotmail.com> [John Roth, among others, wrote] [Snip: Some stuff about good things that Ruby does] As someone who has never seen or written a line of Ruby, I find it most interesting that of all the positive points being made about Ruby, no-one has posted a single line of Ruby code. Whenever people are making points about python, they usually post illustrative snippets of python. Fair enough, it's a python newsgroup, so maybe Ruby code doesn't belong. But I am interested to read others opinions of what Ruby has/does that python hasn't/doesn't. The support for continuations certainly sounds interesting. Some code snippets would really help, for illustrative purposes. but-python-does-almost-everything-that-*i*-need-ly y'rs. -- alan kennedy ----------------------------------------------------- check http headers here: http://xhaus.com/headers email alan: http://xhaus.com/mailto/alan From sjm at sjmsoft.com Sat Aug 2 14:05:37 2003 From: sjm at sjmsoft.com (Steve J. Martin) Date: 2 Aug 2003 11:05:37 -0700 Subject: Problem with Unzipping/Installing Python-2.3.exe References: Message-ID: Timothy Martens wrote in message news:... > Hi John, > > We're in the same boat. I too am having trouble with the win installer. > It's just not working. This is also my first attempt(s) to install > Python. I'm running windows 2K. What version are you on? > > I sent a mesage to the list earlier (subject: 2.3 win installer, "Anyone > having problems with the 2.3 win installer? I'm running win2k pro (sp4) > and the installer is freezing after the initial dialogues, just as the > install starts.") -- but haven't got any feedback. I think maybe most of > the people on the list are running Unix? Can someone help us pathetic > windows users? > > Regards, > > tim. Hi tim, I had no trouble installing Python 2.3 on Win 2000 Pro SP3. I'm also a Python newbie and so can't provide any help, only encouragement that the installer worked fine for me. Cheers, Steve From skip at pobox.com Fri Aug 15 11:46:24 2003 From: skip at pobox.com (Skip Montanaro) Date: Fri, 15 Aug 2003 10:46:24 -0500 Subject: dict->XML->dict? Or, passing small hashes through text? In-Reply-To: <20030815055724.GB19960@incise.org> References: <20030815042536.GA19960@incise.org> <16188.28023.216400.94715@montanaro.dyndns.org> <20030815055724.GB19960@incise.org> Message-ID: <16189.80.590671.642927@montanaro.dyndns.org> mack> Another concern with pickle is that (I think?) I can recall mack> reading about how it is bad to blindly unpickle things that come mack> in from an untrusted source, and that makes sense, as even mack> accessing attributes could run arbitrary code, which mack> seems.. bad. :) That's a problem with any serialization format. If you do something like the equivalent of cmd = raw_input("Enter a Unix command: ") os.system(cmd) you're asking for trouble. Ignoring that extreme case, pickle has the added problem that you can execute an arbitrary amount of Python code instantiating previously pickled objects. If you stick to the usual suspect (int, string, float, long, bool, list, tuple, dict), you're generally going to be okay. Those are, not too surprisingly, the types which interoperate the best anyway. I think you can subclass the pickle.Unpickler class and force a restriction on the types of objects it will unpickle. Skip From adalke at mindspring.com Thu Aug 21 13:25:51 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Thu, 21 Aug 2003 17:25:51 GMT Subject: max length of a python program References: <1ed07caf.0308210513.6556978a@posting.google.com> Message-ID: Ragu: > Is there a limit to the # of lines that can be in a Python program? Many years ago there was a limit of 64K lines, because of how the line number opcode worked in Python. Only machine generated Python code ever ran into that limit. That limit was removed in .. 1.5? Can't find mention of the fix in my cursory search. So no, no effective limit. Andrew dalke at dalkescientific.com From FBatista at uniFON.com.ar Thu Aug 21 16:09:36 2003 From: FBatista at uniFON.com.ar (Batista, Facundo) Date: Thu, 21 Aug 2003 17:09:36 -0300 Subject: tuple to string/list Message-ID: #- for i in range(len(month)): #- output="Hits for",month[i], ":" , teller[i] #- f.write(str(output)) #- f.close() #- #- => this produces a tuple: #- ('Hits for', 'Jan', ':', 0)('Hits for', 'Feb', ':', 2)('Hits for', #- 'Mar', ':', 3) #- #- => whereas I would like the following output: #- Hits for Jan: 0 #- Hits for Feb: 2 #- Hits for Mar: 3 #- #- Any easy way of obtaing this output? Don?t know what?s teller, so I'll assume you need the range(len(month)) situation. for i in range(len(month)): output = "Hits for " + month[i] + ": " + teller[i] f.write(output + "\n") # remember the "\n" f.close() More efficient (not adding strings): for i in range(len(month)): output = "Hits for %s: %s" % (month[i], teller[i]) f.write(output + "\n") # remember the "\n" f.close() My way: output = ["Hits for %s: %s" % (month[i], teller[i]) for i in range(len(month))] f.write("\n".join(output)) f.close() . Facundo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ADVERTENCIA La informaci?n contenida en este mensaje y cualquier archivo anexo al mismo, son para uso exclusivo del destinatario y pueden contener informaci?n confidencial o propietaria, cuya divulgaci?n es sancionada por la ley. Si Ud. No es uno de los destinatarios consignados o la persona responsable de hacer llegar este mensaje a los destinatarios consignados, no est? autorizado a divulgar, copiar, distribuir o retener informaci?n (o parte de ella) contenida en este mensaje. Por favor notif?quenos respondiendo al remitente, borre el mensaje original y borre las copias (impresas o grabadas en cualquier medio magn?tico) que pueda haber realizado del mismo. Todas las opiniones contenidas en este mail son propias del autor del mensaje y no necesariamente coinciden con las de Telef?nica Comunicaciones Personales S.A. o alguna empresa asociada. Los mensajes electr?nicos pueden ser alterados, motivo por el cual Telef?nica Comunicaciones Personales S.A. no aceptar? ninguna obligaci?n cualquiera sea el resultante de este mensaje. Muchas Gracias. -------------- next part -------------- An HTML attachment was scrubbed... URL: From peter at engcorp.com Wed Aug 27 18:49:04 2003 From: peter at engcorp.com (Peter Hansen) Date: Wed, 27 Aug 2003 18:49:04 -0400 Subject: OT: Celebrity advice (was: Advice to a Junior in High School?) References: <3F4D0D8B.5E5F9488@engcorp.com> Message-ID: <3F4D3560.71995AEB@engcorp.com> Gerrit Holl wrote: > > Peter Hansen wrote: > > But if you refuse to go to prison, things get lethal pretty quickly. > > That's what "ultimately" refers to above. > > Well, I don't think they get very lethal, they get painful at most. > > > I think the key word in the above is "ultimately", and > > I can see why ESR would (I think validly) state what he did above. > > Ultimately, the state will use violence. But this violence should not > have lethal consequences. No, you're not taking the word "ultimately" far enough. First the state tries to get painful on your ass, so you resist. Then they get really violent, and still you resist. Picture the nature of this resistance, which usually would have to involve standing up to armed police by this point. Now tell me how, you plan to avoid *ultimately* getting to the lethal stage, without giving in first. -Peter From jimmy at retzlaff.com Tue Aug 12 07:15:50 2003 From: jimmy at retzlaff.com (Jimmy Retzlaff) Date: Tue, 12 Aug 2003 04:15:50 -0700 Subject: Py2.3: Feedback on Sets Message-ID: Raymond Hettinger (vze4rx4y at verizon.net) wrote: >* Are you overjoyed/outraged by the choice of | and & > as set operators (instead of + and *)? I never even thought about it until I saw this question. Either set of operators makes sense to me. >* Is the support for sets of sets necessary for your work > and, if so, then is the implementation sufficiently > powerful? I have not used a set of sets. >* Is there a compelling need for additional set methods like > Set.powerset() and Set.isdisjoint(s) or are the current > offerings sufficient? It's been sufficient for my needs so far. >* Does the performance meet your expectations? My expectations have been met for everything I've thrown at it so far. The biggest set I've dealt with so far was several hundred thousand tuples, each containing 2 floats. For massive data sets (tens of millions) requiring high performance I've used kjBuckets in the past. I haven't had a chance to compare the performance of kjBuckets and sets yet, but kjBuckets will be going away for me if the performance of sets is even close. >* Do you care that sets can only contain hashable elements? Nope, everything I tend to use is either numeric/string types or tuples of those types. >* How about the design constraint that the argument to most > set methods must be another Set (as opposed to any iterable)? This caught me the first time or two, but it immediately seemed reasonable. >* Are the docs clear? Can you suggest improvements? I haven't read them. I sucked sets.py out of CVS a while ago for use with Python 2.2.x and so I used the source as docs. I haven't even looked in the source for quite a while as things seem pretty obvious to me at this point. >* Are sets helpful in your daily work or does the need arise > only rarely? The need for them arises a couple times a week for me. I do a fair amount of data manipulation in SQL databases with Python. There are things that are natural in SQL and other things that are natural in Python. Having an easy to use sets type affords a greater overlap between SQL and Python which gives me more choices when deciding how to manipulate my data. Thanks to everyone involved for the good work. Jimmy From tcronj at ananzi.co.za Wed Aug 6 17:25:49 2003 From: tcronj at ananzi.co.za (Tertius) Date: Wed, 06 Aug 2003 23:25:49 +0200 Subject: MVC in Python In-Reply-To: References: Message-ID: <3f317231$0$227@hades.is.co.za> MK wrote: > In Java, I simply register many listeners with a data model. > Whenever the model changes, all the listeners are notified > and they change their GUI elements accordingly and > automatically. > > How to achieve this feat in Python? Which techniques > do you guys use? > > Say you have one data structure and two tree controls > in wxPython, displaying two perspectives of that same > data structure. How would you proceed, that is, implement > an equivalent, MVC-ish mechanism, in this case? > My first knee-jerk reaction would be: implement two functions, > update_tree_1() and update_tree_2() which "intelligently" > update only the critical parts of tree GUI control and > which are being called by the data structure whenever > it (data structure, that is) changes. > > MK, > coming from a patterns-ridden Java world > > Check out ..\wxPython\lib\pubsub.py From abelikov72 at hotmail.com Mon Aug 25 16:08:24 2003 From: abelikov72 at hotmail.com (Afanasiy) Date: Mon, 25 Aug 2003 20:08:24 GMT Subject: python gripes survey References: Message-ID: On Mon, 25 Aug 2003 13:42:00 -0500, sismex01 at hebmex.com wrote: >[Afanasiy] >> Returning a struct in C is >> easier to deal with than returning a near-mystery tuple in Python. >> > >You *really* *must* *be* *kidding*. Last post on this topic, I knew it would get all retarded. Try to figure out what I am actually saying before reading "C is easier than Python". Since I cannot explain this well enough to satisfy, I am giving up. I will not post again, feel free to post your snide personal attacks now hounds. From bignose-hates-spam at and-benfinney-does-too.id.au Fri Aug 8 20:36:32 2003 From: bignose-hates-spam at and-benfinney-does-too.id.au (Ben Finney) Date: 9 Aug 2003 10:26:32 +0950 Subject: How to print floating point in scientific format? References: <420ced91.0308081115.7060e551@posting.google.com> Message-ID: On 8 Aug 2003 12:15:53 -0700, sdhyok wrote: > I want to change the DEFAULT behavior of python Then you can modify the Python source to do whatever you want. This is a bad idea for your current stated purpose, though. Changing the default behaviour of a native Python type will only be local to machines that have this altered Python; if you write code that depends on that, it will break unexpectedly on other machines. > to print out all floating points in scientific format? > For instance, > >>x=0.01 >>print x > 1.000000E-2 #Like print "%E"%x > > How can I do it? Since changing the way native flot object operate is a bad idea, two ways seem reasonable. One is to always use output formatting, since it will make your code clearer. >>> x = 0.01 >>> print "%E" % x 1.000000E-02 The other way is to subclass the 'float' class to overload its __str__ method. This gives you objects that default to what you want, without breaking Python. >>> class SciFloat( float ): ... """ A floating-point number class ... that defaults to scientific representation ... """ ... def __init__( self, *args, **kwargs ): ... float.__init__( self, args, kwargs ) ... return ... def __str__( self ): ... return "%E" % self ... >>> if( __name__ == '__main__' ): ... x = SciFloat( 0.01 ) ... print x ... 1.000000E-02 >>> -- \ "I filled my humidifier with wax. Now my room is all shiny." | `\ -- Steven Wright | _o__) | Ben Finney From daniel.rawson.take!this!out! at asml.nl Wed Aug 13 13:45:40 2003 From: daniel.rawson.take!this!out! at asml.nl (Dan Rawson) Date: Wed, 13 Aug 2003 13:45:40 -0400 Subject: Testing a class at the interactive prompt? Message-ID: How can I reload a class at the interactive prompt?? >>> from MyClass import MyClass1 >>> x = MyClass1() ..... edit MyClass.py to modify a method in another window . . . >>> reload(MyClass1) (or reload(MyClass), or ...) which fails >>> from MyClass import MyClass1 doesn't give an error, but also doesn't get the newly modified method . . . TIA . . . . Dan From aleax at aleax.it Mon Aug 4 05:30:50 2003 From: aleax at aleax.it (Alex Martelli) Date: Mon, 04 Aug 2003 09:30:50 GMT Subject: Match beginning of two strings References: Message-ID: Jeff Epler wrote: ... > .. unfortunately, it seems to be slower than the first method. On my > machine (800MHz PIII): > $ python timeit.py -s 'import ravi' \ > 'ravi.extract("abcdefghijklmnopqrstuvwxyz","abcdefghijklmnopBHLHT")' > 10000 loops, best of 3: 32.7 usec per loop Here's my proposal...: import sys def extract(a, b): m = min(len(a), len(b)) for i in range(m): if a[i] != b[i]: return a[:i] return a[:m] def extract2(a, b): for i, ai, bi in zip(xrange(sys.maxint), a, b): if ai != bi: return a[:i] return a[:m] def extract3(a, b): for i, ai in enumerate(a): if ai != b[i:i+1]: return a[:i] return a [alex at lancelot python2.3]$ python -O timeit.py -s 'import exa' 'exa.extract("abcdefghijklmnopqrstuvwxyz","abcdefghijklmnopBHLHT")' 100000 loops, best of 3: 13.9 usec per loop [alex at lancelot python2.3]$ python -O timeit.py -s 'import exa' 'exa.extract2("abcdefghijklmnopqrstuvwxyz","abcdefghijklmnopBHLHT")' 10000 loops, best of 3: 19.7 usec per loop [alex at lancelot python2.3]$ python -O timeit.py -s 'import exa' 'exa.extract3("abcdefghijklmnopqrstuvwxyz","abcdefghijklmnopBHLHT")' 100000 loops, best of 3: 15.7 usec per loop Now add after the "import sys" two lines: import psyco psyco.full() and run again: [alex at lancelot python2.3]$ python -O timeit.py -s 'import exa' 'exa.extract("abcdefghijklmnopqrstuvwxyz","abcdefghijklmnopBHLHT")' 1000000 loops, best of 3: 0.771 usec per loop [alex at lancelot python2.3]$ python -O timeit.py -s 'import exa' 'exa.extract3("abcdefghijklmnopqrstuvwxyz","abcdefghijklmnopBHLHT")' 100000 loops, best of 3: 3.37 usec per loop However, extract2 doesn't run correctly with psyco (gets a MemoryError). Still, the 18-times acceleration that psyco is able to effect on the naive extract IS typical of psyco's effect on functions coded in simple, elementary terms. When you really need speed, assuming that your processor is Intel-compatible, consider psyco (of course, you'll generally use psyco.profile, or something more selective still, rather than psyco.full) -- orders-of-magnitude improvements on low-level bottleneck functions are anything but surprising... Alex From jaybromley at hotmail.com Fri Aug 29 02:40:23 2003 From: jaybromley at hotmail.com (Jay Bromley) Date: 28 Aug 2003 23:40:23 -0700 Subject: Update to Python 2.3 on Red Hat Linux 9 Message-ID: <8242f4a7.0308282240.4c87f997@posting.google.com> Hello, I've got a Red Hat Linux 9 system with Python 2.2.2 and I would like to update to Python 2.3. I got the 2.3 source and built and installed it. Python 2.3 itself works but it doesn't have access to a lot of packages that are available to Python 2.2.2. For example, pygtk-1.99.14 and Tkinter work fine with 2.2.2, but in 2.3 I can't do 'import gtk' or 'import _tkinter'. I checked the pygtk site and they say I've got to recompile pygtk for the new Python. I'm hoping there is a better answer. The problem is a lot of RedHat stuff depends on Python and the packages available to 2.2, but I need 2.3 and I don't want to junk the applications based on Python 2.2 and the current packages. So the questions is, can I build Python 2.3 so that it recognizes all the packages that are available to Python 2.2.2? Is this LD_RUN_PATH stuff? Or do I really need to find out all the libraries in use with 2.2.2 and compile these for 2.3? I'd appreciate any pointers or references to documentation. I *really* want 2.3. Thank you, Jay Bromley jaybromley at hotmail.com From peter at engcorp.com Sat Aug 2 10:25:54 2003 From: peter at engcorp.com (Peter Hansen) Date: Sat, 02 Aug 2003 10:25:54 -0400 Subject: SSH and Windows References: <3F2069BD.1FE2EC2@engcorp.com> <7b454334.0308011350.226fd55@posting.google.com> <3F2B306A.A4BBD206@engcorp.com> Message-ID: <3F2BC9F2.F136E678@engcorp.com> Peter Hansen wrote: > > Maybe try this. Tested (mostly) under Python 1.5.2 (as I recall, under > Linux) and Python 2.0 under Windows: > > elif state == 'stalled': > match = child.expect([pexpect.EOF, pexpect.TIMEOUT, 'ETA'], > timeout=self.timeout) > if match == 0: > break > elif match == 1: > import pdb > pdb.set_trace() > raise SshException('stalled for too long, aborted copy') Ugh... remove the "import pdb" and subsequent pdb.set_trace() before attempting to use the above... sorry about that. Must have checked a debugging version in to CVS. :-( -Peter From op73418 at mail.telepac.pt Wed Aug 6 19:54:03 2003 From: op73418 at mail.telepac.pt (Gonçalo Rodrigues) Date: Thu, 07 Aug 2003 00:54:03 +0100 Subject: Bug? If not, how to work around it? References: <060820031458029244%mday@apple.com> <09udnV37oMEUDqyiU-KYgw@comcast.com> Message-ID: On Wed, 6 Aug 2003 19:46:39 -0400, "Terry Reedy" wrote: > >"Gon?alo Rodrigues" wrote in message >news:upv2jv4eeusj7bli30j7a7ikd0cq3njvm4 at 4ax.com... >> >I changed the __iter__ method to the following, and it seems to do >what >> >you want: >> > >> > def __iter__(self): >> > return iter(self.__obj) > >> But this is precisely what I don't want to do. > >If you don't want to do what works, >why ask us to bother answering? > Because it may not work. That is, the use case I have in mind serves as proxy for an object that may or may not have __iter__. IOW if I stick __iter__ I have to code a second class, etc... etc... Oh well... >TJR > With my best regards, G. Rodrigues From martin at v.loewis.de Sun Aug 3 13:46:27 2003 From: martin at v.loewis.de (Martin v. =?iso-8859-15?q?L=F6wis?=) Date: 03 Aug 2003 19:46:27 +0200 Subject: command history broken in Python2.3 ? References: Message-ID: Nicola Mingotti writes: > When i use the Up-Arrow in Python2.3 > started in an xterm i get '^[[A' . > In IDLE under Windows using Alt-p produce nothig . > In IDLE under Linux Alt-p works !! . > > Do you have the same behavior in you > interpreter ? Can you determine whether the readline module was built (import readline)? Regards, Martin From justinjohnson at fastmail.fm Wed Aug 13 15:30:47 2003 From: justinjohnson at fastmail.fm (Justin Johnson) Date: Wed, 13 Aug 2003 13:30:47 -0600 Subject: Changing UNIX primary group In-Reply-To: <20030813191056.GB22290@unpythonic.net> References: <20030813181002.04DAF38434@www.fastmail.fm> <20030813191056.GB22290@unpythonic.net> Message-ID: <20030813193047.820FA380BC@www.fastmail.fm> Okay, I'll have to do some more research. Maybe I *will* have to run the script setuid root. Shucks! Thanks for the grp.getgrnam help. Just what I needed. :-) On Wed, 13 Aug 2003 14:11:01 -0500, "Jeff Epler" said: > On Wed, Aug 13, 2003 at 12:10:02PM -0600, Justin Johnson wrote: > > Thanks. I was hoping for a python solution though. :-( Does anyone > > know of a way to do this in python? > > Unix doesn't let you setgid() to groups in the supplemental group list > without the same permission needed to change to any group. > > But depending what you need to do, you might be able to use set-group-id > directories. For instance, if I am group g1 and have a group list [g1, > g2, g3], then I can read files readable by any of those groups, and > create files in directories writable by any of those groups. But if you > make a directory d2 that is setgid g2 and d3 setgid g3, then when I > create a file in d2 it will belong to group g2. > > Barring that, you could modify the setgid() call in the kernel, to permit > the change if the requested group is in the auxiliary group list. > It looks like something you could do in an afternoon if you have the > source for your kernel (bsd, linux, etc) and can program C. > > "Justin Johnson" wrote in message > news:... > > Also [setgid] only accepts the gid, but I'd rather pass in > > the group name, or somehow lookup the gid based on the name. > > See grp.getgrnam(). Example: > >>> grp.getgrnam("utmp") > ('utmp', 'x', 22, []) > > Jeff From ryanlowe0 at msn.com Thu Aug 28 18:33:35 2003 From: ryanlowe0 at msn.com (Ryan Lowe) Date: Thu, 28 Aug 2003 22:33:35 GMT Subject: crazy programming language thoughts References: Message-ID: <3rv3b.6241$yg.2305230@news4.srv.hcvlny.cv.net> "Christopher Barber" wrote in message news:psowud0miq4.fsf at unicron.curl.com... > Tim Roberts writes: > > > "Ryan Lowe" wrote: > > > > > >one of the things i love about python is its use of the actual words > > >or/and/not/is/in, where other languages would use symbols ||/&&/?!@#$%, what > > >have you. > > > > The "other languages" thing is a little one-sided. C and C++ are really > > the only mainstream languages to use symbols for these constructs. > > and Java and C# and Tcl and Perl and Javascript, all influenced by C of course. > > - C ok, but my main point wasnt about disliking symbols, per se, as long as they are appropriate. for instance, the $ meaning 'scalar' and the @ meaning 'array' in front of perl variables are near arbitrary symbols in my mind, as are the && and || in c++. what i am attempting to figure out, is if there is a way to improve the intuitiveness of the python's syntax, specifically concerning functions. the basic idea i started with was: > > "Ryan Lowe" wrote: >the basic concept would be to use identifying words in front of the >arguments to determine their identity as well as making the function call >read more like an english phrase. for instance, take the simple python >statement: > >>>> vtext.replace('a', 'b') > >wouldnt it be nicer (more english-like at least) to say: > >>> replace 'a' with 'b' in vtext ive been playing around with the notion of part of speech. ive come up with this rule: functions are defined starting with a present-tense single-word verb, followed by a noun target (not necessarily a variable), followed by any other words and/or variables (at least one word must separate each variable). this reads well when the function call is a statement like the example in the quote. however, it reads less well in assignments, conditions, and parameters, where its used as an expression. in such cases, the function calls read better as noun phrases. i noticed that you can convert a function to the noun-form pretty easily, given the function is of the format above, by taking the past-tense of the verb and swaping the first two words, like so: join listv with '' # verb phrase stringv = listv joined with '' # noun phrase get fruit from bowlv # verb phrase apples, oranges = fruit got from bowlv # noun phrase if 'a' replaced with 'b' in textv : # noun phrase replace av with bv in listv joined with gluev # combo a dictionary of english verb suffixes can be used to automatically define the past tense of a verb, even for made-up verbs in many cases, e.g. asparagate (turn something into an asparagas), can still be resolvable from the suffix ate-> ated. so do people think this is an improvement over dot syntax? i think it reads better, but then i thought of it ;-) do you think it would confuse people in terms of which part is a parameter of what when combining 2 functions like the combo example? can anyone think of a scenario where it wouldnt work? it only takes care of methods, i havent figured out how to de-dottify class functions and class attributes. others pointed out that other languages use labels for arguments, but i dont know any that use this rule system. From Russell.Every at MentumGroup.com Wed Aug 20 03:34:45 2003 From: Russell.Every at MentumGroup.com (Russell) Date: 20 Aug 2003 00:34:45 -0700 Subject: SOAP using ZSI talking to .NET Web Service References: <76ab2b2b.0308182053.4b9beea3@posting.google.com> Message-ID: <76ab2b2b.0308192334.5d0e5869@posting.google.com> And the anwer is, as shown in the working code below. Basically it involved setting up a class for the response and parsing the SOAP object. import sys from ZSI.client import Binding from ZSI import * class Request: def __init__(self, i, extra): self.i = i self.extra = extra Request.typecode = TC.Struct(Request, [TC.Integer('i'), TC.String('extra')], 'RJETestItDoc') class Response: def __init__(self, RJETestItDocResult): self.RJETestItDocResult = RJETestItDocResult def __str__(self): return self.RJETestItDocResult Response.typecode = TC.Struct(Response, [TC.String('RJETestItDocResult')], 'RJETestItDocResponse') url1 = 'http://grouse/rjetest/rjetestservice.asmx' url1 = 'http://www.xwebdocs.com/mentum/rjetestwebservice/rjetestservice.asmx' soapaction ='http://RJE.com/RJETestItDoc' namespace = 'http://RJE.com' host = 'XXX' # Set this to your proxy host port = nnn # Set this to the appropriate port on the proxy dict = {} i = 5 extra = 'A lovely day at the office' trace = sys.stdout b = Binding(url=url1, ns=namespace, host=host, port=port, nsdict=dict, soapaction=soapaction, tracefile=trace) b.Send(None, 'RJETestItDoc', Request(i, extra)) obj = b.ReceiveSOAP() answer = obj.Parse(Response) From aahz at pythoncraft.com Mon Aug 18 19:49:57 2003 From: aahz at pythoncraft.com (Aahz) Date: 18 Aug 2003 19:49:57 -0400 Subject: Why "troll"? (was Re: What's better about Ruby than Python?) References: Message-ID: In article , Brandon J. Van Every wrote: > >Well, I'll freely own up to being rude and intellectually violent. >I don't feel like being "PC" about certain basic questions, I'm a >pragmatic programmer and I call a spade a spade. But that doesn't make >me a troll. It's annoying when people can't/won't tell the difference. >The sheer volume of questions I've asked about Python should indicate >to any impartial observer that I actually do care about the answers. >And if that isn't sufficiently convincing, you might try checking the >marketing-python archives. Speaking as someone with a well-deserved reputation for abrasiveness (nothing approaching yours, but established over more than a decade on-line), when someone as obviously intelligent as you persists in writing in ways that piss people off, the only likely answers for "why?" are "troll" or "insane". Since "troll" implies volition, it's actually less pejorative than the alternative. One definition of insanity: performing the same action over and over again, expecting a different result each time. You're the one who has to decide, in the end, how much effort you're willing to put into maintaining the social contract versus continuing to get ostracized. I've made my decision to alienate a fair number of people, but I also got on well enough with others. I actually used to be more abrasive and annoying, but some people were kind enough to whack me with a clue-by-four. Here's your free clue as part of my pay-forward; I don't have the energy to give you more. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From lupe at netvisao.pt Mon Aug 18 15:13:05 2003 From: lupe at netvisao.pt (Lupe) Date: Mon, 18 Aug 2003 20:13:05 +0100 Subject: advice choosing IDE References: Message-ID: Thanks everyone! I've got some material... :) It's not easy to arrive at a different world (Linux) where everything can be customizeable. For a begginner, it's easier to have just 'one solution' in first place and then to evolve, but I'll get there! Lupe From jacek.generowicz at cern.ch Sun Aug 24 17:03:31 2003 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 24 Aug 2003 23:03:31 +0200 Subject: macro FAQ References: <878ypjjjid.fsf@pobox.com> <87fzjq6gfx.fsf@pobox.com> Message-ID: jjl at pobox.com (John J. Lee) writes: > Jacek Generowicz writes: > > > jjl at pobox.com (John J. Lee) writes: > [...] > > Particularly, we should banish the myth that macros fragment > > languages, or make code less unedrstandable. (Quite the reverse is > > true.) > > it seems clear most people here disagree with that. It seems clear to me, that most of the people who disagree with it, disagree with it on the basis of a misunderstanding of what it is that macros actually do. I am keen to avoid a whole FAQ item, or a whole web page to be built around a bogus starting point. From duncan at NOSPAMrcp.co.uk Mon Aug 11 04:58:28 2003 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Mon, 11 Aug 2003 08:58:28 +0000 (UTC) Subject: Python vs. C# References: <3f357a9b@shknews01> Message-ID: "Brandon J. Van Every" wrote in news:3f357a9b at shknews01: > So again my question is, language-wise, what can I get done with > Python that I can't get done with C#? What is easy to express in > Python, that is tedious, difficult, or impossible to express in C#? > C# (or rather the CLR) has collection types that are superficially similar to Python's list and dict types. A lot of C# programming becomes much easier when you start using ArrayList et. al to do things in a Pythonic manner, BUT with C# you cannot manipulate objects without casting them back to a known type. This is a pain. If I have two objects and they are both integers, then in C# I have to cast them to 'int' before adding them. Or if they are strings I have to cast them to string before adding them. In Python I know they are a suitable type, so I just add them without thinking about it. What this means is that you waste a lot of energy in the C# universe defining type-safe subclasses of the collections just to avoid cluttering your code with a lot of superfluous casts. Python has a much more flexible syntax for function arguments. You can have optional arguments, keyword arguments, you can even have functions where you don't know the names of all the keyword arguments in advance. C# just has overloading, so you need to define a new overload for every optional argument and you can't call a function missing out some arguments from the middle of the list. Tuple unpacking. C# just has naff reference arguments. Need I say more? Slicing of sequences. Python lets you write lists and dictionaries inline where you need them, much more convenient than in C#. Functions are first class objects in Python. C# delegates have some neat features (async calls and multicasts), but the effort of using a delegate in most situations is just too much. Don't get me wrong, C# is quite good, but it just has too much syntactic clutter obscuring the code. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From tim.one at comcast.net Sun Aug 17 21:11:00 2003 From: tim.one at comcast.net (Tim Peters) Date: Sun, 17 Aug 2003 21:11:00 -0400 Subject: bitwise not - not what I expected In-Reply-To: Message-ID: [Elaine Jackson] > In case any fellow newbies have been following this thread, here is > the finished Nim script. It doesn't use bit-manipulation as much as I > thought it would. (Still, I got the basics straight. Thanks again to > everyone who helped out!) For a readable account of the optimal > strategy for Nim, see Hardy & Wright's "Introduction to the Theory of > Numbers". Peace. > > ## NIM > from random import random > piles=[0,0,0] > > ... > > def yourMove(): > magicNum=piles[0]^piles[1]^piles[2] > if magicNum==0: > i=indexOfMax() > piles[i]=piles[i]-1 > else: > magicIndex=leftmostBitIndex(magicNum) > targetIndex=(-1) > for i in range(3): > if (piles[i]>>magicIndex)%2==1: > targetNum=piles[i] > targetIndex=i > break > replacement=0 > for i in range(magicIndex): > magicDigit=(magicNum>>i)%2 > targetDigit=(piles[targetIndex]>>i)%2 > if magicDigit==1: > replacementDigit=(magicDigit-targetDigit) > else: > replacementDigit=targetDigit > replacement=replacement+replacementDigit*pow(2,i) > newNum=targetNum-(targetNum%pow(2,magicIndex+1))+replacement > piles[targetIndex]=newNum > print piles OK, what you're trying to do is force the xor of the pile counts to 0. There may be more than one way to do that. For example, if piles is [2, 6, 7] you can force a win by doing any of these: remove 1 from the 2 pile, leaving [1, 6, 7] remove 1 from the 6 pile, leaving [2, 5, 7] remove 3 from the 7 pile, leaving [2, 6, 4] because 1^6^7 == 2^5^7 == 2^6^4 == 0. Now the educational thing is that it's possible to find all these solutions easily *without* picking apart any bits: def myMove(piles): all = 0 for count in piles: all ^= count for i, count in enumerate(piles): # enumerate() new in 2.3 all_without_count = all ^ count if all_without_count < count: print "leave %d in pile #%d" % (all_without_count, i) For example, >>> myMove([2, 6, 7]) leave 1 in pile #0 leave 5 in pile #1 leave 4 in pile #2 >>> Note that the function works for any number of piles, and doesn't care how big each pile may be; for example, >>> myMove([2**50, 3**67, 5**12, 76**30]) leave 92709463147897838211662074651978 in pile #3 >>> 2**50 ^ 3**67 ^ 5**12 ^ 92709463147897838211662074651978 0L >>> I think you'll enjoy figuring out why that function works; proving that it finds all solutions is a bit delicate, but not truly hard. From ryanlowe0 at msn.com Sat Aug 23 11:39:27 2003 From: ryanlowe0 at msn.com (Ryan Lowe) Date: Sat, 23 Aug 2003 15:39:27 GMT Subject: python gripes survey Message-ID: python is a big improvement on most languages that came before it, but no language is perfect. id like to make a list of some of the aspects people find most annoying, regardless of their feasibility of implementation. for instance, i discussed putting if clauses in for loops, and i noticed another thread about allowing {} and [] to be added and subtracted. if its something from another language (especially an obscure one), please explain how it works in case people like myself dont know the language. thanks, ryan From mwilson at the-wire.com Thu Aug 21 18:57:56 2003 From: mwilson at the-wire.com (Mel Wilson) Date: Thu, 21 Aug 2003 18:57:56 -0400 Subject: [OT] Why is it called string? References: <3f44ce77$0$556$b45e6eb0@senator-bedfellow.mit.edu> <3F44DBF2.1010403@draigBrady.com> <3f44fb74$0$571$b45e6eb0@senator-bedfellow.mit.edu> Message-ID: <05UR/ks/KrBD089yn@the-wire.com> In article <3f44fb74$0$571$b45e6eb0 at senator-bedfellow.mit.edu>, Brian Kelley wrote: >A "bit" used to be half a quarter and therefore there are also 8 bits to >a dollar. Coincidence or a play on words? Some of us here are making >our livings using "pieces of eight", so to speak. Synchornicity, IMHO, since early bits were more likely to bunch up into half-dozens than eights. Regards. Mel. From Kyler at news.Lairds.org Fri Aug 1 22:18:49 2003 From: Kyler at news.Lairds.org (Kyler Laird) Date: Sat, 02 Aug 2003 02:18:49 GMT Subject: Potentially important real-time on-line discussion References: Message-ID: bokr at oz.net (Bengt Richter) writes: >Open source is a digital potluck. The dishes available depend on who volunteers to cook, I'm going to do my best to try to get people to stop making such a tight coupling between "open source" and "volunteers." Any ideas on how to do it? I've found that when I say "Red Hat" some people seem to nod as if they understand that there's nothing contradictory about "commercial open source software." --kyler From aahz at pythoncraft.com Sat Aug 2 01:10:16 2003 From: aahz at pythoncraft.com (Aahz) Date: 2 Aug 2003 01:10:16 -0400 Subject: How do I get a reference to a KEY value of a dictionary? References: <645db655.0307311636.71923378@posting.google.com> Message-ID: In article <645db655.0307311636.71923378 at posting.google.com>, Andy C wrote: > >Basically I want to create a graph with an adjacency list >representation, but I don't want any of the adjacency lists to have >duplicate strings when it is avoidable. I have a function createEdge >that adds an edge to the graph. The arguments will be distinct since >they are read from text files. But basically I want to use the >dictionary as a string pool, and if the argument string equals >something in the pool already, don't use the argument string, just a >use a reference to something in the string pool already. That makes some sense, but why use the string object for both key and value? Just do d[key] = True You could optimize your coding style (if not your speed) in Python 2.3 by using sets. I'd recommend against using intern(), because in Python 2.2 and earlier, interned strings *never* get garbage collected. Even in Python 2.3, you may end up with worse memory behavior. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From jepler at unpythonic.net Sat Aug 9 12:51:16 2003 From: jepler at unpythonic.net (Jeff Epler) Date: Sat, 9 Aug 2003 11:51:16 -0500 Subject: Just say "NO" Re: raw string tail escape revisited In-Reply-To: References: Message-ID: <20030809165112.GA5211@unpythonic.net> Well, one problem is that this is incompatible with all existing R-strings, which have been in Python for comparative ages. So we'd be forced to implement then as B'' strings (For Bengt). 16 ways to declare string literals (single and triple, ' and ", standard, r, u, and ur) are bad enough, I don't want to add another 8 (single and triple, ' and ", b and ub) to the mix. $ python -c 'import this' | grep "only one" Secondly, the price in the tokenizer for an R-string vs a regular string is essentially zero, since after the leading r, u or ur is parsed, the regular rule for parsing any string is used. Your rule will require near-duplication of a 60-line segment of Parser/tokenizer.c and a new function similar to PyString_DecodeEscape, probably another 60 lines of C. Finally, I'm not convinced that your description that triple-quotes and quote-stuffing work well together. RIght now, if the parser sees R'''' # dumb way to do "'" it'll still be in the midst of parsing a triple-quoted raw string. How will you be able to write a B''' string that begins with a ' if this rule is followed? So there must be strings that you can't write with B-quoting, just like there are strings you can't write with R-quoting (but this time the problem is with strings that start with quotes instead of ending with backslashes). Jeff From BPettersen at NAREX.com Sun Aug 3 20:09:47 2003 From: BPettersen at NAREX.com (Bjorn Pettersen) Date: Sun, 3 Aug 2003 18:09:47 -0600 Subject: memory leak? Message-ID: <60FB8BB7F0EFC7409B75EEEC13E2019202CE481A@admin56.narex.com> > From: Trevor Perrin [mailto:trevp at trevp.net] > > "Bjorn Pettersen" wrote in message > news:... > > > From: Trevor Perrin [mailto:trevp at trevp.net] > > > > > > Every time I run the below function from the interpreter, > > > python.exe's > > > memory usage increases by 5 Megs and stays at this higher level > > > (python 2.3b2 on WinXP). I tried to isolate this to something > > > simpler, but wasn't successful. > > > > > > Is this a memory leak, or is there another explanation? > > [...] > > Hi Bjorn, > > > Have your tried 2.3 final, > > I just did, same thing. Good -- usually, fixing existing bugs have much higher priority than backporting fixed bugs. > > how are you determining there is a memory > > leak (which tools), > > Windows Task Manager display process memory use. ..and how is that working out for you? *grin*. It's usually easy to determine if something is a leak using TM, by putting the leaking code in a loop: while 1: test() If memory keeps going up without bounds, there is a better probability that it's a leak (however it could also be garbage waiting for the gc collector), if it doesn't you're probably seeing the normal effects of malloc/free rarely returning memory to the OS, global state, etc. This won't give any info about where the leak is, so you'd either have to get a program that can analyze this (e.g. Rational's Purify), or turn on the memory debug aids availabe in debug builds of Python. In any case, you should probably file a bugreport at sourceforge, http://sourceforge.net/tracker/?atid=105470&group_id=5470&func=browse, I forget if you have to register to file a new bug.. > > what steps did you take that weren't successful, > > I tried calling array.array() and random.randrange() the same number > of times in a loop, but the behavior didn't reproduce. > > > did you try without using "import *", how about loading it as a > > module and then deleting the module (i.e. have you inadvertenly > > created an object that is still live)? > > I tried that, and also using xrange(). Below is a transcript from the > interpreter, after running it python.exe had increased memory use from > ~3 MB to ~21 MB. Maybe there's an innocuous explanation, I'm no > python expert, I'm just curious: Thanks. Knowing what you did kept me from repeating it, knowing you'd tried the standard approaches without success made it interesting enough to take it for a spin :-) At first glance it seems suspicious (but I'm not very familiar with array, nor the new implementation of random), so go ahead and file it. E.g.: "The following progam leaks indefinetly": import array import random def test(): randrange = random.randrange range_64 = range(64) for x in xrange(10000): b = array.array("B", [randrange(0,256) for unused in range_64]) while 1: test() -- bjorn From markus_wankus at hotmail.com Thu Aug 7 08:54:33 2003 From: markus_wankus at hotmail.com (Markus Wankus) Date: Thu, 07 Aug 2003 08:54:33 -0400 Subject: win32, COM, and Solidworks (again) - Still Trying References: Message-ID: On Thu, 07 Aug 2003 21:08:21 +1000, Mark Hammond wrote: > Markus Wankus wrote: > >> Hmmm...'Not Implemented'. Because this fails, I can't obtain the CLSID >> of itself, thus it can't use the makepy generated code to bind itself >> properly. I always get back dumb CDispatch objects. I have been trying >> to hack a way of getting the CLSID of the dispatch object, but it just >> isn't there. >> >> Anyway - if anyone reading this knows anything about what I am talking >> about, your help would be greatly appreciated. > > You should use code similar to: > > mod = gencache.EnsureModule("...", ...) > > ob = Dispatch("Whatever.Object") > # ob now "dumb dispatch", but should be object "foo" > # in the gencache module > # Explicitly convert ob to one of these object. > ob = mod.Foo(ob) > > Mark. > > Thanks, Mark. That's what I have been doing in the past (on your advice), but I have been trying to automate that process and found it next to impossible (from what I can figure out anyway). The reason this is an incredible pain is that every single method or attribute of 'ob' that returns an object, returns a dumb object. I need to know what class it is *supposed* to be, and run it through the gencache module class constructor. This is a huge pain. I realize this is nothing to do with win32all - it is Solidworks. Is there a way I can tell them about this problem and possibly get them to fix it? What have they not done in their C++ code that is making their implementation of COM so stupid? If there was a away I could make my own Dispatch class that forced this re- instantiation I would be happy, but I can't see any way to figure out what gencache class I need for a given object at runtime. I wonder if I could somehow generate my own, smarter module from scratch using the gencache module as a starting point. It would be incredibly painful... Anyway - thanks again for your help, Mr. Hammond. Perhaps I should let this drop already and accept the fact that it can't easily be done... -- Mark From jzgoda at gazeta.usun.pl Tue Aug 26 13:16:28 2003 From: jzgoda at gazeta.usun.pl (Jarek Zgoda) Date: Tue, 26 Aug 2003 17:16:28 +0000 (UTC) Subject: wxTreeCtrl event bug only win32? References: Message-ID: Krzysztof Kaczkowski pisze: > Im having problem, wxTreeCtrl generate 3 x EVT_TREE_SEL_CHANGED on click > item right button mouse. This problem only win32. Why? Maybe you should subscribe wxpython-users list and ask this question there? I'm pretty sure, that you will find much broader audience than here. And of course Robin Dunn also subscribes this list... -- Jarek Zgoda Registered Linux User #-1 http://www.zgoda.biz/ JID:jarek at jabberpl.org http://zgoda.jogger.pl/ From pythonguy at Hotpop.com Wed Aug 20 10:54:53 2003 From: pythonguy at Hotpop.com (Anand Pillai) Date: 20 Aug 2003 07:54:53 -0700 Subject: Problem with garbage collection (sort of) References: <246a4e07.0308180608.2b8d685a@posting.google.com> <246a4e07.0308200126.76a3dc78@posting.google.com> Message-ID: <84fc4588.0308200654.18284b50@posting.google.com> Off topic, no doubt, but are you Frank Weiner, IBM consultant? If you are, I can divulge from where I got the information, otherwise pardon me for the inconvenience. -Anand frank at chagford.com (Frank Millman) wrote in message news:<246a4e07.0308200126.76a3dc78 at posting.google.com>... > frank at chagford.com (Frank Millman) wrote: > > > > >y is an instance of class c, which creates an instance of class b, > which creates an instance of class a. When y goes out of scope and is > deleted, I want the instances of class b and class a to be deleted as > well. > > >The problem is that class a keeps a reference to class b (self.b) and > class b keeps a reference to class a (self.p), so the reference counts > do not go down to zero without some additional action. > > Thanks for all the replies - I have learned a lot. It seems that this > whole thing is not a problem at all. In other words, my instances > *are* being deleted by the cyclic garbage collector, and my only > problem was that I could not confirm this positively. > > As Michael says, the very act of creating a __del__ method in my > classes prevents them from being deleted! However, as I only added the > __del__ method to try to confirm the deletion, this is not a problem > in practice. > > I replaced my __del__ methods with the DelWatcher class suggested by > Tim. At first, nothing changed. Then I added 'import gc; gc.collect()' > at the end, and lo and behold, I could see all my instances being > deleted. > > Being a bit of a sceptic, I still did not regard this as positive > confirmation that it will work in practice, as I do not have a > gc.collect() in my live application, so I added the DelWatcher class > there to see if I got the 'deleted' messages. I understand that > gc.collect() runs automatically from time to time, so I waited a > while, and did not get any messages. Then as I did some more work in > the application, the messages started appearing for the older items. > Re-reading the documentation on the gc module confirms that > gc.collect() is only triggered when the number of 'dirty' objects > exceeds a threshold. > > For the record, I tried Tim's suggestion of using weakrefs, and it > worked perfectly. I did some timing tests and it seems to have very > little overhead. However, as Tim says, it is better to stick to the > cyclic garbage collector now that I have confidence that it is working > correctly. > > Many thanks to all. > > Frank Millman From aleax at aleax.it Mon Aug 4 07:22:16 2003 From: aleax at aleax.it (Alex Martelli) Date: Mon, 04 Aug 2003 11:22:16 GMT Subject: Problems decoding and writing mail attachment References: <2afb3281.0308032307.2e0226df@posting.google.com> Message-ID: edwinek wrote: > I've written a script which I use to save attached binary files from > e-mails to disk. The core is simply: > > decodedfile = bas64.decodestring(attachment) > fle = open('image.jpg','wb') > fle.write(decodedfile) > fle.close > > However, the files written to disk are regularly incomplete, i.e. > jpg's having a grey bar at the bottom, gif's don't even display, pdf's > give errors. > What am I doing wrong here? You're not calling fle.close -- you lack parentheses after the method, so you're just mentioning it, NOT calling it. Not sure if that's your problem (seems unlikely), but it most definitely IS something you're doing wrong, so I thought I'd point it out. Alex From mis6 at pitt.edu Mon Aug 4 15:06:39 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 4 Aug 2003 12:06:39 -0700 Subject: Python speed vs csharp References: <1h5f2rzthqgid.8watonaa4cjt.dlg@40tude.net> <3F551D29.1040407@kfunigraz.ac.at> <0MoXa.21930$cl3.850221@news2.tin.it> Message-ID: <2259b0e2.0308041106.7ac111cc@posting.google.com> Alex Martelli wrote in message news:<0MoXa.21930$cl3.850221 at news2.tin.it>... > import math > > def erfc(x): > exp = math.exp > > p = 0.3275911 > a1 = 0.254829592 > a2 = -0.284496736 > a3 = 1.421413741 > a4 = -1.453152027 > a5 = 1.061405429 > > t = 1.0 / (1.0 + p*x) > erfcx = ( (a1 + (a2 + (a3 + > (a4 + a5*t)*t)*t)*t)*t ) * exp(-x*x) > return erfcx > > def main(): > erg = 0.0 > > for i in xrange(1000000): > erg += erfc(0.456) > > print "%f" % erg > > if __name__ == '__main__': > main() > Just for fun, I tested your scripts on my machine and actually my results also substain the (heretic?) argument that Python (with psyco) is *faster* than C for numeric computations: Time Relative to (optimized) C python+psyco 0.41s 0.59 c (-O option) 0.69s 1 c (normal) 0.80s 1.15 pure python 17.8s 26 This means that (in this computation) normal Python is 26 times slower than optimized C; however Psyco gives a 43x speed-up and it ends up to be 70% faster! It took my breath away. Kudos to Armin Rigo and Psyco! Michele P.S. Red Hat Linux 7.2, 500 GHz PIII, time measured with 'time', Python 2.3 and Psyco 1.0, Alex Martelli scripts (with pow(x,2)-> x*x). From newsgroups at jhrothjr.com Sat Aug 23 07:53:44 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Sat, 23 Aug 2003 07:53:44 -0400 Subject: Modifying the {} and [] tokens References: Message-ID: "Geoff Howland" wrote in message news:mtqdkv8sdrmgrn02vugnbpuhtjsgel3ohb at 4ax.com... > I want to modify the {} and [] tokens to contain additional > functionality they do not currently contain, such as being able to add > dicts to dicts, and other things that would be very helpful for me and > my team mates to have. Literals (and those are literals) are hard coded at the parser level, and are not availible to change - unless, of course, you want to change the source. John Roth From dave at nullcube.com Tue Aug 19 00:46:10 2003 From: dave at nullcube.com (Dave Harrison) Date: Tue, 19 Aug 2003 14:46:10 +1000 Subject: Brandon's abrasive style (was Re: What's better about Ruby than Python?) In-Reply-To: References: <38ec68a6.0308172319.431a4fde@posting.google.com> Message-ID: <20030819044610.GA32041@dave@alana.ucc.usyd.edu.au> > I ask tough questions about Python vs. other languages and platforms. Quite frankly most people of your ilk have a tendency to winge and complain about "missing features" or "bad design" but do nothing to contribute to the language. I fail to see why this puts you in any position to ask the "tough questions" as you put it. If you see something you consider to be a weakness, suggest a solution, don't winge about the fact that it exists. > - Python is not a good language for low-level 3D graphics problems. C++ is > better. > - Python isn't a rapid prototyping godsend for every problem out there. > - GUI and tools support can end up being more important than language > niceties. So what ? It is simply impossible to have one language that does it all, essentially why there are so many different ways of combining Python with other languages. > - Microsoft C# and .NET are strategic threats to Python's prosperity and > vitality, if not survival. > - Pythonistas should consider trying to eat Java's lunch, because they > aren't going to eat Microsoft's lunch. > - Ruby has some mindshare among people with knowledge of Python. > - Yet unnamed languages are capable of taking Python's place on the food > chain. > - You have to promote your language, grow its market share, to prevent that > from happening. Who cares ? If you want to go stick up posters for Python go for it. You certainly appear like a troll, so how about a few suggested solutions to these so called problems you raised ? From nhodgson at bigpond.net.au Tue Aug 26 04:21:40 2003 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Tue, 26 Aug 2003 08:21:40 GMT Subject: Indentation question References: Message-ID: JanC: > AFAIK PythonWin uses the Scintilla editor component? Yes. > This should (could?) work with all other Scintilla-based editors too: > SciTE, pyCrust, Eric3, Wing IDE, Boa Constructor, Black Adder, etc. This will work by default in Scintilla based editors. The container may override the key binding which may happen when they emulate another editor such as EMACS. Neil From jwdillworth at yahoo.com Mon Aug 18 13:18:15 2003 From: jwdillworth at yahoo.com (Jeremy Dillworth) Date: Mon, 18 Aug 2003 10:18:15 -0700 (PDT) Subject: Functions Message-ID: <20030818171815.11399.qmail@web41105.mail.yahoo.com> That depends on your view of the "right" f3 :) In a nutshell, f1 is in the global scope. So it's going to search for f3 in the local (f1) scope (which it will never find, since f1 doesn't have its own f3), and then in the global scope. What function you call it from and whether or not that function has a local f3() defined doesn't matter. Here's an interactive session based on your example which demonstrates: Python 2.3 (#1, Aug 12 2003, 15:22:52) [GCC 3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> def f1(): ... f3() ... >>> def f2(): ... def f3(): ... print "f2's f3 called" ... f1() ... >>> def f3(): ... print "global f3 called" ... >>> def f4(): ... def f3(): ... print "f4's f3 called" ... f1() ... >>> f1() global f3 called >>> f2() global f3 called >>> f4() global f3 called >>> --- Thor wrote: > In this hypothetical case: > > def f1: > f3: > def f2: > def f3: > pass > f1: > def f4: > def f3: > pass > f1: > > would the function f1 execute the right f3 depending on from which functions > is it called? > -- > Thor -- Stockholm -- Sverige > -- > http://mail.python.org/mailman/listinfo/python-list From skip at pobox.com Thu Aug 14 00:07:18 2003 From: skip at pobox.com (Skip Montanaro) Date: Wed, 13 Aug 2003 23:07:18 -0500 Subject: Py2.3: Feedback on Sets In-Reply-To: <16187.1433.780458.994728@montanaro.dyndns.org> References: <1rnljv8527o2phdjup4e9uji0kssf93svt@4ax.com> <16187.1433.780458.994728@montanaro.dyndns.org> Message-ID: <16187.2806.1311.521238@montanaro.dyndns.org> Gary> I get what you mean, but let me point out that "iterable" does not Gary> appear in the index of either the Language Reference or Library Gary> Reference, nor do I see it in the introduction. Skip> That's a documentation bug then. See the patch I just submitted at http://python.org/sf/788509 It suggests that a glossary is needed and includes one with a single entry for "iterable". Feel free to attach comments to it. Skip From ulope at gmx.de Thu Aug 21 03:55:42 2003 From: ulope at gmx.de (Ulrich Petri) Date: Thu, 21 Aug 2003 09:55:42 +0200 Subject: Scope of InteractiveInterpreter? References: Message-ID: Kris Caselden" schrieb im Newsbeitrag news:abc3fdd3.0308202339.6a8fed9b at posting.google.com... > I'm using the InteractiveInterpreter to run some source, but the data > generated doesn't seem to be available in the scope of the parent. > > For instance, I tried > > lines = infile.open('data.py','r').readlines() > ii = InteractiveInterpreter({'__name__': '__main__', '__doc__': None}) > for line in lines: > ii.runsource(line) > > but the data objects in data.py don't seem to exist when I try and > manipulate them later in the script. Is what I'm trying to do > possible? Am I on the right track? Try: ------- import data print data.whatever -------- instead Cu Ulrich From riccardo_togli.questo at e.questo_sideralis.net Sat Aug 2 11:59:00 2003 From: riccardo_togli.questo at e.questo_sideralis.net (Riccardo Galli) Date: Sat, 02 Aug 2003 17:59:00 +0200 Subject: [pygtk] textview: how to insert characters? Message-ID: Hello world. I'm trying to insert characters in a textview, in a position different from the one where's the cursor. I'm alwais getting this warning: Gtk-WARNING **: Invalid text buffer iterator: either the iterator is uninitialized, or the characters/pixbufs/widgets in the buffer have been modified since the iterator was created.[...] This a simple example code, of a method called on insert_text event . When 6 characters are typed,it tries to put an 'X' in the second cursor position, and then to put the cursor where it was before. def on_insert_text(self,buffer,textIter,char,*args): buffer.disconnect(self.signal_id) if textIter.get_chars_in_line()==6 : newIter=buffer.get_iter_at_offset(2) buffer.insert(newIter,'X') buffer.place_cursor(buffer.get_end_iter()) self.signal_id=buffer.connect('insert-text',self.on_insert_text) I understand from the warning that I should use marks, but I don't know how. I've posted this msg to pygtk list too. Thanks for help, Riccardo -- -=Riccardo Galli=- _,e. s~ `` ~@. ideralis Programs . ol `**~ http://www.sideralis.net From sross at connectmail.carleton.ca Fri Aug 8 10:33:18 2003 From: sross at connectmail.carleton.ca (Sean Ross) Date: Fri, 8 Aug 2003 10:33:18 -0400 Subject: filter()ing a dict References: <16469f07.0308070559.aed41a@posting.google.com> <16469f07.0308080110.6a9ef7a0@posting.google.com> Message-ID: "Robin Cull" wrote in message news:16469f07.0308080110.6a9ef7a0 at posting.google.com... > robin.cull at pace.co.uk (Robin Cull) wrote in message news:<16469f07.0308070559.aed41a at posting.google.com>... > For my particular script, which is likely to be used by pythonistas > even less experienced than me, I decided to solve the problem this > way: > > def filterDict(testFunction, dictToFilter): > newDict = {} > for k, v in dictToFilter.items(): > if testFunction(v): > newDict[k] = v > return newDict > > Seems to work for what I want it to do and since it's a standalone > defined function which mimics filter() should be nice and easy to > understand for people who have to look at it later. > I actually find the following version atleast as easy to understand as the version above, but I perhaps I lack perspective. def filterdict(predicate, mapping): "predicate() must take one (key,value) tuple as argument and return a boolean" return dict(filter(predicate, mapping.iteritems())) # useage: fd = filterdict(lambda item: len(item[1])==4, d) From python-url at phaseit.net Mon Aug 25 05:45:45 2003 From: python-url at phaseit.net (Raymond Hettinger) Date: Mon, 25 Aug 2003 09:45:45 -0000 Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Aug 25) Message-ID: QOTW: "You're only overlooking the consequences of an infinite amount of information ." -- Tim Peters on why the bitwise-not operator is equivalent to -(n+1). "Perl, Python, Ruby and Tcl are the four dynamic programming languages that get the most publicity as open source projects, and I think they have a lot more in common than they differ." -- Guido van Rossum Discussion ---------- Andrew Dalke makes the case not all language specialties need to be subsumed into Python: Michele Simionato posts an example where Python and Pysco run twice as fast as optimized C: Guido speaks. Steve Holden's interview of him touches on his move to the Left Coast, along with much else. Jimmy Retzlaff: why and when it is possible for Psyco to run faster that optimized C: Erik Lechak proposes a novel mapping class using regular expressions to match keys. Erik Max Francis explains why the % formatting operator must have the same precendence as the % remainder operator. Releases -------- Pmw 1.2, Python megawidgets for Tkinter. cxOracle, a Python extension module for accessing Oracle. BlackAdder V1.0.0, a Windows/Linus application development environment for Python and Qt with a debugger, IDE, and GUI designer. SC-Track Roundup 0.6.0, an issue tracking system. Soprano 0.003, a GUI (wxpython) network scanner written in python for scanning a selected range of ip addresses and retrieving info about the host. SCons 0.92, a build/make tool written in Python. Snakelets 1.3, a simple threaded web application server built to demonstrate how dynamical web pages are built. ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the daily python url http://www.pythonware.com/daily Mygale is a news-gathering webcrawler that specializes in (new) World-Wide Web articles related to Python. http://www.awaretek.com/nowak/mygale.html While cosmetically similar, Mygale and the Daily Python-URL are utterly different in their technologies and generally in their results. comp.lang.python.announce announces new Python software. Be sure to scan this newly-revitalized newsgroup at least weekly. http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce Brett Cannon continues the marvelous tradition established by Andrew Kuchling and Michael Hudson of summarizing action on the python-dev mailing list once every other week. http://www.python.org/dev/summary/ The Python Package Index catalogues packages. http://www.python.org/pypi/ The somewhat older Vaults of Parnassus ambitiously collects references to all sorts of Python resources. http://www.vex.net/~x/parnassus/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ The Python Business Forum "further[s] the interests of companies that base their business on ... Python." http://www.python-in-business.org The Python Software Foundation has replaced the Python Consortium as an independent nexus of activity http://www.python.org/psf/ Cetus does much of the same http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://python.sourceforge.net/peps/pep-0042.html The online Python Journal is posted at pythonjournal.cognizor.com. editor at pythonjournal.com and editor at pythonjournal.cognizor.com welcome submission of material that helps people's understanding of Python use, and offer Web presentation of your work. *Py: the Journal of the Python Language* http://www.pyzine.com Archive probing tricks of the trade: http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python&num=100 http://groups.google.com/groups?meta=site%3Dgroups%26group%3Dcomp.lang.python.* Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://www.ddj.com/topics/pythonurl/ http://purl.org/thecliff/python/url.html (dormant) or http://groups.google.com/groups?oi=djq&as_q=+Python-URL!&as_ugroup=comp.lang.python Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". -- The Python-URL! Team-- Dr. Dobb's Journal (http://www.ddj.com) is pleased to participate in and sponsor the "Python-URL!" project. From tebeka at cs.bgu.ac.il Tue Aug 26 06:30:38 2003 From: tebeka at cs.bgu.ac.il (Miki Tebeka) Date: 26 Aug 2003 03:30:38 -0700 Subject: Comments on my "Python Introduction" slides References: Message-ID: <33803989.0308260230.13e103@posting.google.com> Hello Roman, > In slide 7 why not to use set instead of dictionary? I have to put a dictionary somewhere. I'll mention sets when I talk about it. > In slide 9: to give a list as example may be not a good idea: list has > reverse method OK. I'll use a tuple. Maybe I'll mention list's sort and that's in-place. > In slide 12: Boost.Python I think it is a must to give a reference on > it. 1'st item in google. I don't want too many links... > Nice work. Thanks. Thanks for your time. Miki From FBatista at uniFON.com.ar Thu Aug 28 10:29:42 2003 From: FBatista at uniFON.com.ar (Batista, Facundo) Date: Thu, 28 Aug 2003 11:29:42 -0300 Subject: finding object using IS instead of == Message-ID: #- If I have a large collection (list, tuple, or dict) of #- objects, can I locate #- one quickly that matches a given object using the IS #- equivalence operator #- instead of the value == operator? Could you please send your routine using the == operator? Thanks. . Facundo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ADVERTENCIA La informaci?n contenida en este mensaje y cualquier archivo anexo al mismo, son para uso exclusivo del destinatario y pueden contener informaci?n confidencial o propietaria, cuya divulgaci?n es sancionada por la ley. Si Ud. No es uno de los destinatarios consignados o la persona responsable de hacer llegar este mensaje a los destinatarios consignados, no est? autorizado a divulgar, copiar, distribuir o retener informaci?n (o parte de ella) contenida en este mensaje. Por favor notif?quenos respondiendo al remitente, borre el mensaje original y borre las copias (impresas o grabadas en cualquier medio magn?tico) que pueda haber realizado del mismo. Todas las opiniones contenidas en este mail son propias del autor del mensaje y no necesariamente coinciden con las de Telef?nica Comunicaciones Personales S.A. o alguna empresa asociada. Los mensajes electr?nicos pueden ser alterados, motivo por el cual Telef?nica Comunicaciones Personales S.A. no aceptar? ninguna obligaci?n cualquiera sea el resultante de este mensaje. Muchas Gracias. -------------- next part -------------- An HTML attachment was scrubbed... URL: From csa at csa-net.dk Sun Aug 31 13:07:17 2003 From: csa at csa-net.dk (Claus Alboege) Date: Sun, 31 Aug 2003 19:07:17 +0200 Subject: [OT] Re: confirm unsubscribe from zsh-users@sunsite.dk References: <20030831.095012515090500@csa-net.dk> <9gednbZOl6UBhM-iXTWJiA@comcast.com> Message-ID: <20030831.190717388433500@csa-net.dk> "Terry Reedy" writes: > "Claus Alboege" wrote in message > news:20030831.095012515090500 at csa-net.dk... >> "Terry Reedy" writes: >> >> >> I haven't checked whether your address is currently on the > mailing >> > list. >> > >> > Then you are a pretty dumb program. > > Not checking for the subscriber list is what I thought dumb. Oh, well I'm not sure why it has been implemented that way, but two reasons that comes into mind are, code simplicity and the fact that these bogus unsubscribe requests are really rare - at least until now. >> Ever heard of sublists? > > I would expect sublists to be specially configured, by or with list > owner approval, as you seem to imply below, rather than added thru > public subscribe mechanism. Not nessecarily. Having a bunch of users, behind a slow and expencive link, each one subscribed to more or less the same set of lists, would benefit from sublists. These can easily be setup by the local admin. There is no need to involve the admin of the parent list. >> And about people using different addresses for >> each list they subscribe to, such as user-xxx-list at dom.tld? > > No. I have never had unlimited address availability. I have exactly > 1 from udel and 7 for the family from ISP. But it soulds like a great > idea. Just yesterday I got virus spam sent to names harvested from a > particular list. If I had a special address for that list, I would > resubscribe with a new name. Exactly, yet another way to deal with spam :) > If I ever buy a domain-name service with 'unlimited' email accounts, I > will try this. Thanks. /Claus A From koenig at v-i-t.de Tue Aug 26 14:00:27 2003 From: koenig at v-i-t.de (Mirko Koenig) Date: Tue, 26 Aug 2003 20:00:27 +0200 Subject: wxPython: need return value from wxFrame References: Message-ID: On Fri, 22 Aug 2003 22:56:36 +0200, Cliff Wells wrote: > On Fri, 2003-08-22 at 12:27, Mirko Koenig wrote: >> On Fri, 22 Aug 2003 00:28:23 +0200, Cliff Wells wrote: >> >> > On Thu, 2003-08-21 at 15:17, Mirko Koenig wrote: >> >> I can show() the frame from within the invoice code but show doesn't >> >> return a value. >> > >> > Use a wxDialog instead. >> > >> > >> But how to return a list or tuple. All i can see is that a dialog >> returns a int value > > Try something like this: > .... > > app = wx.PySimpleApp() > dlg = MyDialog(None, -1) > retval = dlg.ShowModal() > if retval == wx.ID_OK: > print dlg.GetValue() > dlg.Destroy() > app.MainLoop() > I tried but couldn't find a solution. As i said before, i have a wxframe derivered class for my addressbook to have a stand-alone addressbook. Stand-alone in my case means that it is a app for itself. Not only a extra windows in the invoice application. It contains wxFrame specific things like status bar etc. Therefore i could not deriver it from wxDialog. I can't place a wxFrame in a sizer of a dialog. That would solve my problem. Are there any other ideas? Mirko Koenig From skip at pobox.com Fri Aug 1 21:29:10 2003 From: skip at pobox.com (Skip Montanaro) Date: Fri, 1 Aug 2003 20:29:10 -0500 Subject: time, calendar, datetime, etc In-Reply-To: References: <153fa67.0307300326.45a29380@posting.google.com> <1sScnW0Sv7DzrrSiRTvUpQ@speakeasy.net> Message-ID: <16171.5094.970999.909168@montanaro.dyndns.org> >>>>> "Andrew" == Andrew Dalke writes: Andrew> So again I say, most people don't care that much about the time. And when they do, it's for at most a few years into the past (taxes, tax audits) and a few years forward (< 100 years, typically the expected remainder of their own lifetime). An astromer's view of time is extremely different and extremely rare. Given that, it's not hard to understand the epoch year chosen by the people who developed the requirements for the datetime module. Maybe Jay Leno should have a "Jay Walking" where he asks people about the adoption of the Gregorian calendar. That would give you some idea about how many people care about dates long ago. ;-) Skip From __peter__ at web.de Sat Aug 23 04:29:30 2003 From: __peter__ at web.de (Peter Otten) Date: Sat, 23 Aug 2003 10:29:30 +0200 Subject: Sort a Dictionary References: Message-ID: Andrew Dalke wrote: > def ksort(d, func = None): > keys = d.keys() > keys.sort(func) > return keys > > for k in ksort(d): > print k, v > > > And no, I haven't tested it. ;) > and no, it doesn't work. Try for k in ksort(d): print k, d[k] or go with items = d.items() items.sort() for key, value in items: print key, "-->", value I reckon that for me the extra function doesn' t pay off, but if you must, use the generic def sorted(seq, func=None): items = list(seq) # create a copy to omit side effects items.sort(func) return items for key, value in sorted(d.items()): print key, "-->", value which would be useful for any iterable. Peter From klastname at nyc.rr.com Fri Aug 22 19:04:32 2003 From: klastname at nyc.rr.com (Kenny Tilton) Date: Fri, 22 Aug 2003 23:04:32 GMT Subject: What's better about Ruby than Python? In-Reply-To: References: <3F41505F.69D18CC8@alcyone.com> <66d7kvonvb2n0nqbqahhd5roak7ur81sob@4ax.com> <3f43ef5d_4@127.0.0.1> <3F440A35.9030602@nyc.rr.com> <4o_0b.1665$Ej6.1182@newsread4.news.pas.earthlink.net> <8D01b.1721$Ej6.702@newsread4.news.pas.earthlink.net> <3F44ED2E.9070308@nyc.rr.com> <0V61b.1900$Ej6.1012@newsread4.news.pas.earthlink.net> <3F4504D7.20008@nyc.rr.com> Message-ID: <4kx1b.39591$Sq.6153905@twister.nyc.rr.com> Terry Reedy wrote: > "Mario S. Mommer" wrote in message > news:fzoeyihycs.fsf at cupid.igpm.rwth-aachen.de... > >>Lisp is simple. >> >>( ...) >> >>Where's the problem? > > > The very uniformity of everything (including operators?) being a > possibly recursive list and the actual practice of relatively deep > (compared to Python and similar languages) nesting. If a lisp > expression ends with 10 to 20 closing parentheses (which I have seen), Not often, I hope. Then again, I for one hate too much code in one function or even too much code in one source file! So I break things up a lot. Funny thing is, I do not end up with a lot of functions for functions' sake, things just tend to be reusable. This one is really personal taste. I think I have a very low tolerance for lotsa code in one place. OTOH, lotsa closing parens means highly functional code. That is very good for code quality. kenny From dtolton at yahoo.com Mon Aug 18 18:37:07 2003 From: dtolton at yahoo.com (Doug Tolton) Date: Mon, 18 Aug 2003 22:37:07 GMT Subject: What's TOTALLY COMPELLING about Ruby over Python? References: <3F41208F.40021A68@engcorp.com> Message-ID: On Mon, 18 Aug 2003 16:22:01 -0400, "John Roth" wrote: >It might be better to simply take the question at face value, rather than >slanging Brandon. I don't find the personalities to add anything of value >to the conversation. Clearly you haven't followed c.l.p for long, otherwise you wouldn't make a statement like this. Brandon is *constantly* trolling this newsgroup with inflammatory and/or contradictory statements. Seriously do a search using google groups for Brandon Van Every in comp.lang.python. Your statement is innappropriate take in full context. Doug Tolton (format t "~a@~a~a.~a" "dtolton" "ya" "hoo" "com") From aleax at aleax.it Fri Aug 29 04:27:27 2003 From: aleax at aleax.it (Alex Martelli) Date: Fri, 29 Aug 2003 08:27:27 GMT Subject: OT: Celebrity advice (was: Advice to a Junior in High School?) References: Message-ID: Gerrit Holl wrote: > Alex Martelli wrote: >> People who don't want ID >> cards to exist, don't want government DB's to be cross-linked, etc, >> plead much the same case -- they prefer inefficient government (whose >> inefficiencies may help terrorists and other criminals) to efficient >> government (whose efficiency might allow more effective oppression). > > This is exactly true. The one extreme is called 'anarchy', the other > is called 'totalitarism' (either Communism or Fascism). It is a political > choice to find a balance. Of course, ID cards don't mean totalitarism, > but extreme government control, or extreme "effective oppression", does. ID cards are a tool that can make government more efficient -- for either good or evil purposes equally well. Similarly, promoting Python use in government-used programming makes government potentially more efficient. Generally, tools are morally neutral -- for an engineer there may be some moral (or, equally, aesthetic -- "beauty is truth, truth, beauty") value in a specific tool, but that's a biased viewpoint;-). > We don't want a state that controls everything. But we Hobbes did (he WAS pretty consistent). But his intellectual heirs (Locke and ff -- and the US's founding fathers were very much part of that continuing tradition) were the ones that best developed the case for limited and hampered government [[IMHO John Stuart Mills is the single best // clearest // most readable thinker and writer in that line... and not coincidentally the last major one -- other later writers in Liberalism, such as Hayek and other Austrians, do not really belong to the same line/tradition, IMHO, though it may of course inspire them]]. > also don't want a state that controls nothing. Some extreme libertarians may indeed believe they want that (but just one look at Somalia and other cases where the state has basically wilted should hopefully be enough to dislike THAT:-). Alex From heikowu at ceosg.de Mon Aug 11 22:00:02 2003 From: heikowu at ceosg.de (Heiko Wundram) Date: 12 Aug 2003 04:00:02 +0200 Subject: Python vs. C# In-Reply-To: References: Message-ID: <1060653602.844.39.camel@d168.stw.stud.uni-saarland.de> On Tue, 2003-08-12 at 03:20, Brandon J. Van Every wrote: > Well, I think mainstream commercial industry sees the writing on the wall > regarding garbage collection. But that's probably the current level of > consensus on "yes, we need a better solution for this." Python advocates > tend to pooh-pooh strong typing, and I'm wondering if in a large-scale > industrial context, if that's really a valid stance to take. I've used Python for most of my university projects so far (at least where I could choose what to use), and I've had professors look at me asking why I chose "an outsider" like Python over languages (considered to be "stronger") such as C++ and SML (whatever...). They only asked until they had a look at the code I had produced. :) Where other people had written huge amounts of C++ code for a renderer, which was incomprehensible even to the original programmer after about a weeks time, my code remained "relatively" short and clean (I had to write it in 72 hours), nicely structured into separate modules, and with a well designed class inheritance scheme (which is pretty important for a renderer, for the user to be able to integrate his/her own objects later on). Metaclass programming aided me a lot here. And, yeah, I love doc-strings! None of my competitors could offer this, whatever language they chose (one chose Perl, all others C++...). None of the professors even spoke about garbage collection, none spoke about dynamic typing, they were all just amazed at the expressive powers Python put in my hands, all with simple syntax and a without a huge STL (such as C++s). I was even asked to give a Python lecture later on (not in an official course, but for the interested). :) I don't think that "static typing" (Python is strongly typed btw., just to correct your statement) is any concern for most people (even for most executives, I guess my professors count as that too), just getting a working solution for a problem quickly, smoothly and readably. And that's what Python excels at. > At any rate, I > expect more years of evolution with languages such as Java and C# before > mainstream industry starts thinking that the more exotic things Python does > are "better solutions" for something that definitely needs fixing. Yeah, I can agree here. But in my experience, if I can show the people what power Python comes with ("batteries included"), after their amazement stops, they'll all start asking which book to buy to start learning. Even with the "power-play" Sun and Microsoft did to boost Java and C#, Python still seems as a valid and interesting alternative to most people I know (except those living in the "Microsoft-Universe", of course, but I guess I'll never save them from that big black hole anyway). Just my 5 eurocents. Heiko. From mirko-lists at zeibig.net Thu Aug 7 05:38:28 2003 From: mirko-lists at zeibig.net (Mirko Zeibig) Date: 7 Aug 2003 09:38:28 GMT Subject: Atomicity of signal handlers References: Message-ID: On Thu, 07 Aug 2003 at 08:29 GMT, Mirko Zeibig wrote: > assuming I have a C++-library implementing tracing, where the tracefile is > implemented as singleton and implements a method rotateLogs. > > Is it safe to have something like: > > def handleSIGUSR2(signal, frame): > tracelib.rotateLogs() > > signal.signal(signal.SIGUSR2, handleSIGUSR2) Pardon, for following up to myself, to clarify this a bit: - given the mechanism above, what would happen if I had: 1: do_sth() 2: tracelib.log("A") 3: do_sth_else() ... where tracelib.log would be a call into the C++-Library. - now, if SIGUSR2 is received by the process, will tracelib.log be interrupted or will the signal be deferred until tracelib.log returns? Regards Mirko From dtolton at yahoo.com Wed Aug 20 14:01:37 2003 From: dtolton at yahoo.com (Doug Tolton) Date: Wed, 20 Aug 2003 18:01:37 GMT Subject: What's better about Ruby than Python? References: <3F41505F.69D18CC8@alcyone.com> Message-ID: <66d7kvonvb2n0nqbqahhd5roak7ur81sob@4ax.com> On Tue, 19 Aug 2003 13:43:11 +0200, Alex Martelli wrote: >Doug Tolton wrote: > ... >> abstractions and better programmer productivity. Why not add Macro's >> allowing those of us who know how to use them and like them to use >> them. If you hate macros, or you think they are too slow, just don't >> use them. > >"No programmer is an island"! It's not sufficient that *I* do not use >macros -- I must also somehow ensure that none of my colleagues does, >none of my clients which I consult for, nobody who posts code asking >for my help to c.l.py or python-help -- how can I possibly ensure all >of this except by ensuring that macros ARE NOT IN PYTHON?! "Slow" has >nothing to do with it: I just don't want to find myself trying to debug >or provide help on a language which I cannot possibly know because it >depends on what macros somebody's defined somewhere out of sight. Not >to mention that I'd have to let somebody else write the second edition >of the Nutshell -- if Python had macros, I would have to cover them in >"Python in a Nutshell". > Sadly, I would say that is something that would sway me. I love my Python in a Nutshell book. I have that baby on my desk and I refer to it *daily*. Although I'd say that's more extortion than a winning argument!! :-p I just don't see Macros as the huge threat you do. As someone mentioned in a previous post, the option would require to do declare explicitly that you are using Macros. Why is that such a *huge* issue? Why is it that the very *existence* of a Macro in a program would offend your sensibilities? > They don't change the underlying language, they just add a >> more useful abstaction capability into the language. > >They may not change the "underlying" language but they sure allow anybody >to change the language that is actually IN USE. That is definitely NOT >what I want in a language for writing production-level applications. I tend to disagree on this point. I like the idea of being able to treat commonly reused idioms as if they are a part of the language. > >I dearly hope that, if and when somebody gives in to the urge of adding >macros to Python, they will have the decency to FORK it, and use an >easily distinguishable name for the forked Python-with-macros language, >say "Monty". This way I can keep editing future editions of "Python in >a Nutshell" and let somebody else write "Monty in a Nutshell" without >any qualms -- and I can keep programming applications in Python, helping >people with Python, consulting about Python, and let somebody else worry >about the "useful abstaction" fragmentation of "Monty". If that "useful >abstaction" enters the Python mainstream instead, I guess the forking >can only be the last-ditch refuge for those of us (often ones who've seen >powerful macros work in practice to fragment language communities and >end up with "every programmer a different language"... do NOT assume that >fear and loathing for powerful macro systems comes from LACK of experience >with them, see also the Laura Creighton posts whose URLs have already >been posted on this thread...) who'd much rather NOT have them. But maybe >moving over to Ruby might be less painful than such a fork (assuming THAT >language can forever stay free of powerful macro systems, of course). That certainly is one way for it to happen. I must say I certainly am suprised at your vehemence. I don't think the natural state of human beings is singular in purpose or design. I think the natural state of humans is to fracture into competing camps / factions. *Every* human system of any size has factions of some sort or another. I think the power of Unix / Linux in general has been in working to allow these factions to Co-exists peacefully. By trying to prevent factioning within the community, I think you will ultimately only be successful in driving people with different viewpoints out of the community. > >I have nothing against macros *IN GENERAL*. I just don't want them *in >my general-purpose language of choice for the purpose of application >programming*: they add NOWHERE NEAR ENOUGH PRODUCTIVITY, in application >programming, to even START making up for the risks of "divergence" of >dialects between individuals, groups, and firms. If I was focused on >some other field than application programming, such as experimental >explorations, tinkering, framework-writing, etc, I might well feel quite >otherwise. But application programming is where the big, gaping hole >of demand in this world is -- it's the need Python is most perfectly >suited to fulfil -- and I think it's the strength it should keep focus >and iinvestments on. Again, I disagree. It appears to me as though you've had some near death experience with Macros that left a sore taste in your mouth. Could you elaborate some on what your experience has been that turned you so definitively sour on Macros? > >Alex Doug Tolton (format t "~a@~a~a.~a" "dtolton" "ya" "hoo" "com") From none at none.net Thu Aug 14 04:13:00 2003 From: none at none.net (Sami Viitanen) Date: Thu, 14 Aug 2003 08:13:00 GMT Subject: Determine file type (binary or text) References: Message-ID: Thanks for the answers. To be more specific I'm making a script that should identify binary files as binary and text files as text. The script is for automating CVS commands and with CVS you have to add the -kb flag to add (or import) binary files. (because it can't itself determine what type the file is). If binary file is not added with -kb the results are awful. Script example usage: -import.py Script makes list of all files under that directory and then determines each files filetype. After that all files are added with Add command and binary files get that additional -kb automatically. "Sami Viitanen" wrote in message news:AFm_a.9725$g4.189983 at news1.nokia.com... > Hello, > > How can I check if a file is binary or text? > > There was some easy way but I forgot it.. > > > Thanks in adv. > > From MK at foo.com Mon Aug 4 16:14:49 2003 From: MK at foo.com (MK) Date: Mon, 4 Aug 2003 22:14:49 +0200 Subject: MVC in Python Message-ID: In Java, I simply register many listeners with a data model. Whenever the model changes, all the listeners are notified and they change their GUI elements accordingly and automatically. How to achieve this feat in Python? Which techniques do you guys use? Say you have one data structure and two tree controls in wxPython, displaying two perspectives of that same data structure. How would you proceed, that is, implement an equivalent, MVC-ish mechanism, in this case? My first knee-jerk reaction would be: implement two functions, update_tree_1() and update_tree_2() which "intelligently" update only the critical parts of tree GUI control and which are being called by the data structure whenever it (data structure, that is) changes. MK, coming from a patterns-ridden Java world From gcash at luncheonmeat.cfl.rr.com Thu Aug 28 00:19:51 2003 From: gcash at luncheonmeat.cfl.rr.com (gcash) Date: Thu, 28 Aug 2003 04:19:51 GMT Subject: win32: "LoadBarState failed" and flaming death Message-ID: I'm doing stuff using COM to automate IE, for some boring repetitive portal tasks I have to do. Anyway, every so often I'll make some sort of error and things will crash, and I'll have to do something like using task manager to kill Python and/or the IE instance. Then I'll reload pythonwin and get "LoadBarState failed due to win32 exception" and once I get this pythonwin will no longer work. It'll get all sorts of errors, the drop down menus won't work, there will be all sorts of exceptions happening, and desktop icons and the start button won't work until I kill pythonwin. This is even before loading anything as it can't even load a file. The only fix is to delete python, then use regedit to remove any python related registry keys. This is in Win2K pro SP4, using either python 2.2.3 and win32all 154 or 156, or python 2.3 and win32all 155 or 157. Any ideas?? -gc -- Windows users [are like] people stuck in abusive relationships. They get beat up over and over again, but they won't leave. -- Steve VanDevender (alt.sysadmin.recovery) From tzot at sil-tec.gr Thu Aug 21 13:42:11 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Thu, 21 Aug 2003 20:42:11 +0300 Subject: tarfile woes References: Message-ID: <031akvog75dgbqoe4v3qq3ketlpiu48lf4@4ax.com> On Thu, 21 Aug 2003 19:29:50 +0200, rumours say that Hans-Joachim Widmaier might have written: > - It does not handle compressed (.Z) archives. Of course there's > noone to blame. The gzip utility (which is used by gnu tar) handles > this ancient algorithm, but apparently, zlib does not. :-( You know there's a gzip module, don't you? -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From mwh at python.net Thu Aug 14 09:41:25 2003 From: mwh at python.net (Michael Hudson) Date: Thu, 14 Aug 2003 13:41:25 GMT Subject: system call in python References: <3F3B2012.9030101@teksavvy.com> <200308140145.51759.skchim0@engr.uky.edu> Message-ID: <7h3d6f84aue.fsf@pc150.maths.bris.ac.uk> Graham Fawcett writes: > On an editorial aside, I'd nominate the "commands" module as a Python > wart. I seem to recall python-dev agrees with you... > It's not that the functions in this module aren't useful, but why > are they divorced from the very-much-related commands in the "os" > module? > > IIWG (If I were Guido) I think I would at least sub-package this > module as os.commands (in the spirit of os.path). While I was at it, > I'd probably do the same for shutil (--> os.shutil). Hmm. In a way, os is already too fat, I'm not sure *more* stuff should end up in there. If it was a real package, then maybe os.commands, os.net, os.shutil would make sense, but it's not. Occasionally people suggest that you should get at the standard library by doing something like from org.python import socket but then Guido shoots them :-) > The Python standard library is full of dark corners bearing wondrous > mysteries, a Library of Alexandria full of useful code... but surely > even Alexandria's librarians put similar scrolls on the same shelf! This is what Alex Martelli is for :-) Cheers, mwh -- If I didn't have my part-time performance art income to help pay the bills, I could never afford to support my programming lifestyle. -- Jeff Bauer, 21 Apr 2000 From aleax at aleax.it Fri Aug 8 08:08:28 2003 From: aleax at aleax.it (Alex Martelli) Date: Fri, 08 Aug 2003 12:08:28 GMT Subject: Bug? If not, how to work around it? References: <2259b0e2.0308070919.2bedce6@posting.google.com> <2259b0e2.0308071454.1f2869aa@posting.google.com> <2259b0e2.0308080323.1a2a8dfa@posting.google.com> Message-ID: <0pMYa.53814$cl3.1681803@news2.tin.it> Michele Simionato wrote: ... > The point is that if you define a fake special method via __getattr__, it > works if it is called as F.__len___(f), but it DOES not work if it is > called as len(f). I suspect Gonzalo's problem is the same with iter. You're right. Special methods are looked up in the 'slots' (tp_iter and the like), for the purpose of Python operations and built-ins (iter() and the like), and __getattr__, being dynamic, doesn't affect those slots. E.g.: def fakeiter(x): return iter('ciao') class witer(type): def __getattr__(cls, name): if name == '__iter__': cls.__iter__ = fakeiter return cls.__iter__ raise AttributeError, name __metaclass__ = witer class X: pass try: for x in iter(X()): print x, print except TypeError: print 'TypeError, as expected' else: print "No TypeError (?!)" try: for x in X().__iter__(): print x, print except AttributeError: print 'AttributeError, as expected' else: print "No AttributeError (?!)" for x in X.__iter__(X()): print x, print try: for x in iter(X()): print x, print except TypeError: print 'TypeError, alas' else: print "No TypeError (good!)" Once X.__iter__ IS finally accessed, it gets installed in the class object, thereby affecting the slots and making iter happy. But until that happens, the class's tp_iter is null, iter() does not cause a __getattr__ call, and X().__iter__, being an access on the instance, doesn't go up to the metaclass either. > Built-in like iter, len, etc. look directly for special methods __iter__, > __len__ etc., *without* checking if they are defined by __getattr__. I > am not saying that this is necessarely a bug, I am saying that this is > not documented and that at least three persons have been beaten by this I agree. The way the Nutshell puts it is "in the new-style object model, implicit use of special methods always relies on the class-level binding of the special method, if any" -- and this is correct and complete, even though probably too terse for anything except perhaps a Language Reference (which IS allowed to be very terse as long as it's correct and complete). __getattr__ is not a BINDING of the special method, though it may be considered a DEFINITION of it, which is why the current phrase in the Language Reference is not 100% correct and complete -- only 99.44%, and I agree that the remaining 0.56% _is_ a delicate defect in the documentation. It would probably be more helpful to most readers if a section on new-style classes, one on old-style classes, and/or one on special methods, expanded on this issue just a wee little bit. Alas, the Language Reference being meant for language-lawyers only, it's hard to argue that it should deign to clarify things, as long as they _are_ expressed in ways that are correct and complete. > issue in the last few months. Not me personally, hence the reason why I > didn't submit a bug report, but this time (if Gonzalo is not going to do > that), I will submit the report, unless Alex is going to prove that this > is already documented ;) It's not _correctly and completely_ documented, I have to agree -- the docs use the potentialy-slightly-ambiguous verb 'define' rather than the more specific one 'bind'. Alex From adalke at mindspring.com Tue Aug 19 19:30:15 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Tue, 19 Aug 2003 23:30:15 GMT Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> Message-ID: Alexander Schmolck: > One thing that makes such an attempt fairly unattractive for anyone with > finite amounts of time is that python isn't that much use without its > supporting C/C++ modules schemes/lisps suck in the FFI department (every > lisp/scheme has its own way of interfacing to C). If Parrot gets enough Python working for the challenge, then someone could write a Lisp-y language targeting Parrot, and take advantage of the work of others. For that matter, there's Lisps on the JVM, no? Could support Jython. > Could you say a little bit more about it? In python I think one could to some > extent use operator overloading and a special expression class, that > simplifies the literal expression the programmer stated, but I guess then one > would then to explicitly request evaluation (and operator overloading isn't > quite powerful enough to easily incorporate 'alien' class-instances, too). > > Is the C++ code something along those lines, or different? Different. The problem with the operator overloading approach is the creation and description of intermediate objects. If you do a = b + c * d then "c*d" makes an intermediary temporary. Template expressions solve it by providing a description of how to do the add, early enough that the compiler can optimize based on the whole express. Eg, for vectors, the compiler could generate code equivalent to for (i=0; i <87lluaeiy9.fsf@pobox.com> Message-ID: <874r0ycvns.fsf@pobox.com> - readline module (or maybe incorrectly picked termlib instead of + readline library (or maybe incorrectly picked termlib instead of John From grante at visi.com Wed Aug 13 15:33:55 2003 From: grante at visi.com (Grant Edwards) Date: 13 Aug 2003 19:33:55 GMT Subject: Determine file type (binary or text) References: <3F3A8275.8B6EE8C4@engcorp.com> Message-ID: <3f3a92a3$0$160$a1866201@newsreader.visi.com> In article <3F3A8275.8B6EE8C4 at engcorp.com>, Peter Hansen wrote: > "Contains only printable characters" is probably a more useful definition > of text in many cases. The definition of "printable" is dependent on the character set, that will have to be specified. -- Grant Edwards grante Yow! World War Three can at be averted by adherence visi.com to a strictly enforced dress code! From adalke at mindspring.com Fri Aug 22 13:00:39 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Fri, 22 Aug 2003 17:00:39 GMT Subject: What's better about Ruby than Python? References: <3F41505F.69D18CC8@alcyone.com> <66d7kvonvb2n0nqbqahhd5roak7ur81sob@4ax.com> <3f43ef5d_4@127.0.0.1> <3F440A35.9030602@nyc.rr.com> <4o_0b.1665$Ej6.1182@newsread4.news.pas.earthlink.net> <8D01b.1721$Ej6.702@newsread4.news.pas.earthlink.net> <3F44ED2E.9070308@nyc.rr.com> <0V61b.1900$Ej6.1012@newsread4.news.pas.earthlink.net> <3F4504D7.20008@nyc.rr.com> Message-ID: Mario S. Mommer: > Lisp is simple. > > ( ...) > > Where's the problem? Quantum mechanics is simple. It's just H | psi> = E | psi> What's H mean? And psi? And bra-ket notation? The reason my original forays into Lisp around 1990 failed was because the documentation I had for learning it didn't talk about anything I found interesting, like doing file I/O and graphics. It went on-and-on about data structures and manipulating them. My later attempts were by trying to customize my Emacs LISP setup, and getting various errors because I didn't know the quoting rules well enough. Since then it's been limited to incidental learning, like seeing examples and trying to figure them out. Eg, consider Gabriel's "Worse is Better" essay. The section "Good Lisp Programming is Hard" http://www.ai.mit.edu/docs/articles/good-news/subsubsection3.2.2.4.html gives this example (defun make-matrix (n m) (let ((matrix ())) (dotimes (i n matrix) (push (make-list m) matrix)))) (defun add-matrix (m1 m2) (let ((l1 (length m1)) (l2 (length m2))) (let ((matrix (make-matrix l1 l2))) (dotimes (i l1 matrix) (dotimes (j l2) (setf (nth i (nth j matrix)) (+ (nth i (nth j m1)) (nth i (nth j m2))))))))) and says the above is both "absolutely beautiful, but it adds matrices slowly. Therefore it is excellent prototype code and lousy production code." I've done a lot of matrix math, but even now cannot simply look at the above code to figure out what it does, much less does wrong. But I can figure them out from, say, Java, in which I have no programming experience at all. I've also looked at Lisp code when evaluating a package written in Lisp. I was able to figure that library better than the above, partially because I had already looked at 15 other packages which did the same task, so knew the structure of the solution. I turned out that the Lisp code was no more powerful or flexible than the ones written in the other languages. I didn't see good reasons to use Lisp for the problems in my domain. > You shouldn't confuse success with quality. For experimental evidence > look at music charts. On the other hand, if people feel more > confortable with python, then so be it. Quips are easy: "You shouldn't confuse power with quality." > > And I assert that it's because Lisp as a language does not encourage > > the sort of code sharing that the languages I mentioned above do. > > This is ridiculous. You don't know Lisp so you do not have an idea > (hint: what you say is wrong), and thus you shouldn't be saying this. Not being able to program in Lisp doesn't mean I don't know anything about it. I've read the histories, the articles like Gabriel's, listened to others as they talk about their experiences with Lisp, and decisions to use an alternate language. I understand the decision to emphasize its parse tree based approach over a more syntax oriented one. And as you say, the semantics in Lisp are for the most part shared with other languages. > > So while it is very expressive for a single person, a single person > > can only do so much. > > People regularly work in teams on lisp projects. Is that just an > illusion of mine? No. My take on things is that the people who do use Lisp these days are self-selected for those who either 1) do things alone, ie, can and will build everything from scratch, or 2) work hard at making sure their code can be used by others. By "work hard" I mean smart people willing to focus on the community and learn about the 7 or so different ways of saying 'equals' and the importants of closures and all the other things needed to become good Lisp programmers. The people I know focus mostly on developing new computational techniques and only want to implement that part of the code, pulling in code from elsewhere if possible. Hence, not #1 nor #2. (There are some #1 projects, and the #2 people are almost invariable from CS, learning Lisp first and biology second.) In other words, the overlap between the types of people who are good at programming in Lisp and those who decide upon a career in computational life sciences is low. Another possibilty I'm considering now is that the additional flexibility that Lisp has, eg, for making frameworks, isn't needed for the programming problems faced in this field, which for the most part are either data munging or compute-bound algorithmics. When then choose a more flexible language of a lesser one is easier to learn and use? But a real Lisper would, I think, argue that it means those tools are available for the few times it is needed. Andrew dalke at dalkescientific.com From faizan at jaredweb.com Mon Aug 4 14:23:50 2003 From: faizan at jaredweb.com (Fazer) Date: 4 Aug 2003 11:23:50 -0700 Subject: Python and cron jobs. Message-ID: <7b454334.0308041023.6e688b4d@posting.google.com> Hello, I am wondering that if it is possible to add cron jobs via a web or shell interface? I can make Python act as a shell script and be called by a PHP script. But my main goal here is to be able to manage cronjobs. Add or remove certain crjob jobs etc... Can any kind soul shed some light on how I would accomplish this? Thanks, Faizan From florian.proff.schulze at gmx.net Fri Aug 29 04:58:02 2003 From: florian.proff.schulze at gmx.net (Florian Schulze) Date: Fri, 29 Aug 2003 10:58:02 +0200 Subject: appoximate string matching library - any interest? References: <4ZGcnR__JutkFdOiXTWJhQ@giganews.com> Message-ID: I was searching myself yesterday and downloaded but didn't look at agrepy yet. I would really be interested, especially as I see your API which seems quite simple. Regards, Florian On Thu, 28 Aug 2003 18:57:59 -0400, Istvan Albert wrote: > Hi all, > > I'm working on a project that needs approximate string matching > such as the String::Aprox module in perl: > > http://search.cpan.org/author/JHI/String-Approx-3.20/Approx.pm > > Unlike exact matches approximate (fuzzy) matches can match > words having small differences in them, typos, errors or > similarly spellings. > > I was unable to find a similar implementation in python right > away so I tried wrapping the perl module's underlying C library > into python calls. I turned out to be fairly easy, man is > SWIG an awesome product or what ... in a just a few hours I > managed to create a quite functional version (see below). > > In the meantime I have also discovered that there is a similar > project Agrepy.py available but I have no idea how well > it works. I'm trying to gauge the interest relative to this > library, right now it serves my needs yet I wouldn't mind > polishing it up and making it public if it appears to be > useful for others too. > > cheers, > > Istvan. > > ------------------------------------------------------- > > import APSE > > title = "Star Wars - Episode Two" > test_word = "Stra Wras - Episode Two" > test_list = ["Stra Wars - Episode Two", > "Stra Wras - Episode Two", "Stra Wras - Episode Tow"] > > # allow at most 4 edits > ap = APSE.Approx(title, edit=4) > > #info on the matching parameres > print "Info", ap.info() > print > > # only prints matching entries > print "Word:", ap.match(test_word) > print "List:", ap.match(test_list) > print > > # verbose matching, the first element of the tuple is > # the edit distance > print "Verbose word:", ap.verbose_match(test_word) > print "Verbose list:", ap.verbose_match(test_list) > > -------------------- output -------------- > > Info ({'edit': 4}, 'Star Wars - Episode Two') > > Word: Stra Wras - Episode Two > List: ['Stra Wars - Episode Two', 'Stra Wras - Episode Two'] > > Verbose word: (4, 'Stra Wras - Episode Two') > Verbose list: [(2, 'Stra Wars - Episode Two'), > (4, 'Stra Wras - Episode Two')] > > -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/ From postmaster at mail.hotmail.com Fri Aug 22 20:15:46 2003 From: postmaster at mail.hotmail.com (postmaster at mail.hotmail.com) Date: Fri, 22 Aug 2003 17:15:46 -0700 Subject: Delivery Status Notification (Delay) Message-ID: This is an automatically generated Delivery Status Notification. THIS IS A WARNING MESSAGE ONLY. YOU DO NOT NEED TO RESEND YOUR MESSAGE. Delivery to the following recipients has been delayed. abuse at hotmail.com -------------- next part -------------- An embedded message was scrubbed... From: Subject: Re: Re: My details Date: Fri, 22 Aug 2003 20:14:03 +0800 Size: 1113 URL: From peter at engcorp.com Sat Aug 2 10:16:16 2003 From: peter at engcorp.com (Peter Hansen) Date: Sat, 02 Aug 2003 10:16:16 -0400 Subject: Announcing issue 2 of The Agile Developer's Life free eZine References: <3F293658.3030609@users.ch> Message-ID: <3F2BC7B0.E9506C91@engcorp.com> Borcis wrote: > > DevCoach wrote: > > I have just published the second issue of The Agile Developer's Life > > (formerly called The Agile Life) > > How much of Rumsfeld's special vocab does it port to computer programming ? Translation, please, anyone? From jordan at krushen.com Mon Aug 25 14:35:39 2003 From: jordan at krushen.com (Jordan Krushen) Date: Mon, 25 Aug 2003 18:35:39 GMT Subject: python gripes survey References: <78kkkvg8ckfio141es2of1p483ohbtbit5@4ax.com> Message-ID: On Mon, 25 Aug 2003 18:32:35 GMT, Jordan Krushen wrote: > def f(x, y, z): > return(z, y, x) > > a, b, c = f() Woops. Make that a, b, c = f(1, 2, 3) > print a, b, c # 3 2 1 J. From dtolton at yahoo.com Mon Aug 18 19:08:04 2003 From: dtolton at yahoo.com (Doug Tolton) Date: Mon, 18 Aug 2003 23:08:04 GMT Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> <3F41505F.69D18CC8@alcyone.com> Message-ID: On Mon, 18 Aug 2003 15:17:03 -0700, Erik Max Francis wrote: >My view of this is that if you really want to do this, you're better off >inventing a separate language -- however similar to Python -- and using >a processor to turn that language into real Python, which can then be >interpreted. In an interpreted language, especially one as dynamic as >Python, translation often strikes me as superior to incorporating >macros. That's IMO the only real issue that would preclude Macro's from being in Python. I wonder how slow they would really be though, the way they are implemented in Lisp makes them pretty dang fast though, even when interpreted. Although if speed were your main issue, you really wouldn't be programming in Python in general at this point. Python is significantly slower than natively compiled Java, C. Clearly the reason people use Python isn't for ultra-high performance. So even though Macros are a performance hit, they probably wouldn't impact performance as much as people think, and even if they did affect performance for some things, they typically wouldn't be speed critical sections of code anyway (ie, don't use them in speed critical sections) Allowing Macros makes it very easy to write an interpreter yes, however I don't think that is the only or even necessarily the primary reason for Macro's. Macro's allow you to embody common high level idioms into a similarly clean statement or expression. Using Python at all we are trading cpu cycles for higher level abstractions and better programmer productivity. Why not add Macro's allowing those of us who know how to use them and like them to use them. If you hate macros, or you think they are too slow, just don't use them. They don't change the underlying language, they just add a more useful abstaction capability into the language. Doug Tolton (format t "~a@~a~a.~a" "dtolton" "ya" "hoo" "com") From hawkfish at trustedmedianetworks.com Thu Aug 28 12:41:43 2003 From: hawkfish at trustedmedianetworks.com (Richard Wesley) Date: 28 Aug 2003 16:41:43 GMT Subject: OT: Americans love their guns References: Message-ID: In article , midnight at warm-summer-night.net (falling star) wrote: > Lulu of the Lotus-Eaters wrote: > LotLE> > LotLE> USA automobile deaths are ^43k/year > LotLE> USA gun-related deaths are ~29k/year > > Where did you get your number? 29k a year??? Don't believe it. I > would guess the number to be somewhere in the 1000 to 2000 range. US murders with firearms were 8,259 in 1999, ranked #4 in the world. Source: The US is a bit better per capita firearms murders at #6 . So while "falling star" appears to be swallowing some well cooked data, the raw data is still pretty bad. Being in the company of South Africa, Columbia, Zimbabwe and Mexico is not something that a progressive nation should be proud of. > Unless you are including people killed by police in your figure? They don't have the data for this, but estimating from where I live (Seattle, population 5e5, ~2/year) gives ~1000/year. I don't believe from looking at the data that this would affect the US ranking significantly. The US is in a big clump at the top of the rankings in both total and per capita measurements. > Or as Mark Twain put it, 'There are lies, damn lies, and statistics'. He actually attributed this quote to Benjamin Disrali. Since neither of them had any mathematical background (indeed they were both famous rhetoricicians), I'm not sure they are qualified to comment on statistics... > The statistic the other poster mentioned about more guns lowering > crime: In states with concealed carry laws, *crime* is lower. Your > statistic about gun _deaths_ being higher in states with relaxed gun laws > is a canard. That is correlating gun deaths with overall crime. There > are issues of population as well. Again, we are talking statistics, and > there can be no agreement as there are so many correlated factors. Speaking of canards, the whole state law comparison arguments used by both sides in this are pretty sketchy (partly for the reasons you present). There are much larger data sets available from other countries and they pretty clearly show that the US is anomalous. What to do about it may be somewhat debatable, but when you have similar firearms murder rates to countries that have de facto civil wars, it is prudent to ask what you have in common with those areas might lead to similar results. One can argue that there is no comparison, but the data is so striking that I believe the burden of proof is on those who make that argument. For the affirmative, we observe that a heavily armed populace is one common factor, as is lack of a common culture or social identity (generally caused by tribal or economic differences). Personally I think it is both: The US populace has very little in common outside of its political institutions and it is heavily armed. This is historically a bad combination, for if you are used to demonizing others and you can kill them, you probably will. Which brings us back to this Handgun Control/NRA meme war. The fact that US politics is havily polarized is partly due to this lack of social cohesion and partly due to there being so much at stake in controlling the largest economy in the world. Once the debate becomes a shouting match and a battle of egos, social cohesion drops even further and you have a positive feedback loop. So in a small way, the argument that you two are having is actually contributing to the problem under discussion. Please note that I am /not/ arguing that the gun violence in the US is being caused by NRA vigilantes hunting down HCI partisans or vice versa. But I do believe that villification of the "other" in the media by large, well-funded organizations intent on maintaining and increasing their own power, leads to feelings of persecution and self-righteousness in /all/ members of society. In the end, those with poor impulse control and easy access to deadly weapons vent these emotions with tragic results. (This includes the police in some cases.) So I think there are actually two policy needs here: handgun control and more civil public discourse. I think that both are required, but I doubt that either will happen. But to the NRA gun nuts, I say that a civil society is a far better guarentee of your safety than being well armed, and to the HCI nuts I say, you are more likely to achieve your goal through a civil society free of fear, for guns are only a symptom of the fear, not its root cause. Anyway, this is waay of topic and I need to get back to work now... -- - rmgw http://www.trustedmedianetworks.com/ ---------------------------------------------------------------------------- Richard Wesley Trusted Media Networks, Inc. "Grownups have the most uninteresting explanations for things." - C. S. Lewis, _The Magician's Nephew_ From jacek.generowicz at cern.ch Sun Aug 24 09:49:32 2003 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 24 Aug 2003 15:49:32 +0200 Subject: What's better about Ruby than Python? References: <8D01b.1721$Ej6.702@newsread4.news.pas.earthlink.net> <3F44ED2E.9070308@nyc.rr.com> <0V61b.1900$Ej6.1012@newsread4.news.pas.earthlink.net> <3F4504D7.20008@nyc.rr.com> <2259b0e2.0308230118.67a676e7@posting.google.com> <2259b0e2.0308230712.3f60cf3c@posting.google.com> <2259b0e2.0308240424.e3d4c60@posting.google.com> Message-ID: mis6 at pitt.edu (Michele Simionato) writes: > This is a tautology. If a Lisp is Common, then it is Common Lisp. I'll assume you forgot a smiley, and let this pass, otherwise we'll be stuck here forever. > I was talking here about Scheme, Emacs Lisp, etc. Now you argue that > these are not dialects of Lisp but entirely different languages. To > be honest, I do think you have reasons for this claim. Nevertheless, > outside of the Lisp community, everybody who says the name Lisp in a > language (ex. Emacs Lisp) would expect that it is a dialect of Lisp. > So, the confusion is unavoidable. Indeed, and therefore it is important (in the current context), to clear up the confusion. So I state once again: Saying that a language is a "dialect of Lisp" is similar to saying that a language is "in the Algol Family"; in both cases it is a statement about the style of syntax on which the language is based, and leaves open the possibility that it has little else in common with other languages in the family. > In Lisp I would agree there is a basic reference, i.e. CL. "In the Algol Family I would agree there is a basic reference, i.e C++." Sorry, no. (As much as I would like the other Lisps to go away :-) it's just factually incorrect.) > In the Python community I don't think macros would necessarely > generate a fragmentation in dialects, since Pythonistas like > to write standardized (even indented !) code. Still, I would > prefer to maintain the status quo and leave things are they > are. If I want macros, I can always use Lisp/Scheme, isn't it? Yes, but what if you don't like Lisp (I'll be generous, and include Scheme under this name :-), but you do like Python ? From mis6 at pitt.edu Sun Aug 3 11:08:31 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 3 Aug 2003 08:08:31 -0700 Subject: I have posted a recipe to draw inheritance diagrams which may be useful to somebody Message-ID: <2259b0e2.0308030708.70da6906@posting.google.com> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/213898 From danbmil99 at yahoo.com Sat Aug 16 12:31:06 2003 From: danbmil99 at yahoo.com (dan) Date: 16 Aug 2003 09:31:06 -0700 Subject: GUI builder for Python References: Message-ID: "Michael Peuser" wrote in message news:... > Have you tried it? It is not a Python tool ;-) And there had been not much > move there for more than a year... What do you mean about it not being a Python tool? It supports wxPython, right? If you mean it wasn't written in Python, why should I care about that? > > There is a well known set of GUI Builders for Pyhon around, most of them > mentioned in this thread. > The most important decision is what GUI-Toolkit to use. This will influence > much of your *programming* tasks that follows the *layout*. Printing? > HTML-Widget? Drag-and-Drop? Agreed. > > There is no silver bullet at the Python market at the moment... Too bad. -dbm From jepler at unpythonic.net Thu Aug 7 07:54:35 2003 From: jepler at unpythonic.net (Jeff Epler) Date: Thu, 7 Aug 2003 06:54:35 -0500 Subject: spawnv( ) or spawnl( ) do not launch a normal running process in Python 2.2.2? In-Reply-To: References: Message-ID: <20030807115430.GA32067@unpythonic.net> I don't see any problem with P_NOWAIT. Take the following for example: $ cat nushin.py import os p = os.spawnvp(os.P_NOWAIT, 'sh', ['sh', '-c', 'sleep 1; echo from spawnv']) print "from program" print "waitpid returns:", os.waitpid(p, 0) $ python -u nushin.py from program waitpid returns:from spawnv (2826, 0) Now, if the program completed very quickly, it's a coin-flip whether its output would appear before "from program". In this case, I made sure the program would take a really long time (1 second) to complete. When running without -u but not on a terminal, you might see $ python nushin.py | cat from spawnv from program waitpid returns: (2832, 0) .. this is because the Python process has printed "from program", but stdio buffering has kept it from actually being written to the output yet. Here's what you see on a terminal without -u: $ python nushin.py from program from spawnv waitpid returns: (2835, 0) This is the same thing you'd see if the program said print "from program"; sys.stdout.flush() Jeff From aleax at aleax.it Wed Aug 6 18:21:20 2003 From: aleax at aleax.it (Alex Martelli) Date: Wed, 06 Aug 2003 22:21:20 GMT Subject: Python's biggest compromises References: Message-ID: Gerrit Holl wrote: >> > Python predates Java. >> Yeah, snakes drink coffee too. > > Both for Python and Java is true that it is unclear when in emerged. > Pythons have existed for a looooooooong time, so has Jawa. But only Not really. What existed (in Ethiopia, only) as a wild plant variant of coffee, before man got to it, has by now a rather thin relation with the widespread coffee plants -- and it didn't grow on the island of Java, nor anywhere else in Indonesia, only in a small corner of Ethiopia. Generally, man has had a huge influence on plants and animals it raises, a much thinner one on those it doesn't; often it makes sense to consider different species for the agriculturally or pastorally "enhanced" (from man's viewpoint) variants, with respect to the preexistent wild "cousins". Thus, I would suggest "Java" didn't exist before (at most) about 1000 years ago -- while phythons most assuredly did. > Pascal is even newer, he lived very recently in this context. "Ada", on the other hand, being the start of "Adam", might claim older genesis. "C sharp" presumably requires musical instruments on a well- tempered scale -- if so, then it seems to me it should be even newer than Pascal. Alex From wrbt at email.com Tue Aug 12 16:24:32 2003 From: wrbt at email.com (Larry) Date: 12 Aug 2003 13:24:32 -0700 Subject: Is Python your only programming language? References: Message-ID: <2ec1bc1c.0308121224.5455f929@posting.google.com> "Joe Cheng" wrote in message news:... > I'm curious about something... At work I'm now at about 90% Python and the rest a mix of Visual Basic and Java. Almost anything new gets done in Python, with Java for applets (blah) and the VB mainly just maintenance on existing VB crap. At home I'm currently about 40% Unreal Tournament 2003 and 60% Civ III. From bokonon at rochester.rr.com Sun Aug 31 16:05:14 2003 From: bokonon at rochester.rr.com (Caleb Land) Date: 31 Aug 2003 13:05:14 -0700 Subject: list as paremeters... References: <3f51ce6e$0$26843$626a54ce@news.free.fr> Message-ID: "shagshag13" wrote in message news:<3f51ce6e$0$26843$626a54ce at news.free.fr>... > hello, > > i have an unexpected behaviour that i didn't understand, can someone explain > this to me ? > > >>> def doit(s, stack = []): > if s == '': > return stack > > stack.append(s[:1]) > return doit(s[1:], stack) > > >>> doit('this') > ['t', 'h', 'i', 's'] > >>> doit('this') > ['t', 'h', 'i', 's', 't', 'h', 'i', 's'] > >>> doit('this') > ['t', 'h', 'i', 's', 't', 'h', 'i', 's', 't', 'h', 'i', 's'] > > and so on ... i would expect it to stuck to > >>> doit('this') > ['t', 'h', 'i', 's'] > > why does this 'stack' remind of previous call ? The problem is your function declaration: def doit(s, stack = []): That empty list is evaluated only once, so each call to doit without a stack argument uses the same list. You should change that to: def doit(s, stack=None): if s == '': return stack if stack is None: stack = [] # A new empty list is created each time stack.append(s[:1]) return doit(s[1:], stack) -Caleb Land From tjreedy at udel.edu Thu Aug 21 21:30:22 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 21 Aug 2003 21:30:22 -0400 Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> <6dj2kv8ugkieehs7guh786cl40o5lj6mcs@4ax.com> Message-ID: "Dave Kuhlman" wrote in message news:bi3ibj$4um7m$1 at ID-139865.news.uni-berlin.de... > See: > > http://www.schemers.org/Documents/Standards/R5RS/HTML/ > > http://www.schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-3.html > > http://www.schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-7.html#%_sec_4.3 > > I have the same worry that some others on this thread have > expressed, that a macro capability in Python would enable others > to write code that I would not be able to read or to figure out. According to the second referenced page ("Background"), not a completely baseless worry, although the Scheme divergence may have had nothing to do with macros: "The first description of Scheme was written in 1975... Three distinct projects began in 1981 and 1982 to use variants of Scheme for courses at MIT, Yale, and Indiana University [21, 17, 10]... As Scheme became more widespread, local dialects began to diverge until students and researchers occasionally found it difficult to understand code written at other sites. Fifteen representatives of the major implementations of Scheme therefore met in October 1984 to work toward a better and more widely accepted standard for Scheme. " Reading the third referenced page on Macros, I notice that the amount of syntax definition for the macro sublanguage is as large as a substantial portion (one-third?) of that for core Python (if condensed to the same density). So, just by definitional bulk, having it in the language would not be a free ride. Terry J. Reedy From dippy at mikka.net.au Fri Aug 15 14:45:13 2003 From: dippy at mikka.net.au (Steven) Date: Fri, 15 Aug 2003 18:45:13 GMT Subject: Module access from inside itself References: Message-ID: On Sat, 16 Aug 2003 04:01:42 +1000, Just wrote: >> How do I get a reference to the module from inside the module? Is this >> the Pythonic way of generating help strings for CL scripts? > > You can just access __doc__ directly. No module prefix neccesary. Ah, I knew I was missing something obvious! Thank you to everyone who answered. -- Steven. From jacek.generowicz at cern.ch Sun Aug 24 05:44:21 2003 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 24 Aug 2003 11:44:21 +0200 Subject: macro FAQ References: <2259b0e2.0308240103.3966476b@posting.google.com> Message-ID: mis6 at pitt.edu (Michele Simionato) writes: > > Can this be implemented using metaclasses, or any other existing > > Python mechanism ? > > Yes. > > http://groups.google.it/groups?hl=it&lr=&ie=UTF-8&threadm=2259b0e2.0306040808.1d737a54%40posting.google.com&rnum=2&prev=/groups%3Fhl%3Dit%26lr%3D%26ie%3DISO-8859-1%26q%3Dsimionato%2Bmacros%26meta%3Dgroup%253Dcomp.lang.python.* Unfortunately I can't easily access this at the moment. I'll try to have a look later. > At the end it uses metaclasses+exec+a simple argument parser based on > tokenize. EXPERIMENTAL code, which I would not trust except as proof > of concept. If it uses exec, then it is faking up macros. Lisp macros are little else besides offering language support for the use of exec for this kind of thing. If people start resorting to this sort of trick themselves, and re-inventing it over and over again, then you might as well design it properly, once and for all, and call it a macro system. I submit that Python already has macros ... they just need a bit of streamlining :-) From Mike at DeleteThis.Geary.com Thu Aug 28 20:52:06 2003 From: Mike at DeleteThis.Geary.com (Michael Geary) Date: Thu, 28 Aug 2003 17:52:06 -0700 Subject: [Zope-dev] Zope 2.7 running with Stackless 3.0 References: <3F4D44EB.5010500@tismer.com> <3F4DF1E7.1010103@zope.com> <3F4E3CE1.5030405@tismer.com> Message-ID: Shane Hathaway wrote: > For the uninitiated: Stackless lets a Python program break out of the > rigid constraints of a simple stack. It lets Python code manipulate its > own execution. It provides new solutions to problems like threading, > debugging, network communication, etc. It's a very interesting shift. > > BTW, here's one avenue you might pursue, Christian: Python IDEs. When I > wrote the debugger for Boa Constructor, I hit a big wall. Since Python > is a dynamic language, one would expect to be able to pause the > execution of a function, change the function, and resume execution with > new code--never skipping a beat. But CPython makes this nearly > impossible. I imagine Stackless would provide an answer for this. If > it does, get in contact with ActiveState, Secret Labs, or the Wing IDE > folks and tell them you can make their debugger twice as good as any > other. Just an idea. Yes! This would be an outstanding benefit. As much as like Python, I *really* miss the Edit and Continue feature from Visual C++. It's truly liberating to be able to change my code right in the midst of debugging it, with all its state preserved. I often write a skeleton for a function, start it up, and then finish coding it while I'm running it. Even short of that, none of the Python debuggers I've tried support a Set Next Statement command like Visual C++ does. That itself is mighty useful. Maybe Stackless would make it possible to support this? -Mike From CousinStanley at hotmail.com Sun Aug 10 16:32:32 2003 From: CousinStanley at hotmail.com (Cousin Stanley) Date: Sun, 10 Aug 2003 13:32:32 -0700 Subject: How to print floating point in scientific format? References: <420ced91.0308081115.7060e551@posting.google.com> <420ced91.0308090642.176b856b@posting.google.com> <420ced91.0308101121.7002ec9@posting.google.com> Message-ID: | Cousin, you are right. | But, do you want to write for loops | whenever you print arrays? | | Maybe not if you are a hard-core scientific programmer. Cousin sdhyok .... I believe that the nature of science and the numerical tools that it employs for problem solving is highly context dependent upon the particular problem at hand and that it might be difficult to find a one-size-fits-all solution for array printing since the nature of the arrays that are employed and their content can vary greatly from context to context .... The dimensonality, homogeniety, and population density of the arrays employed must be considered as design parameters in each problem space and treated accordingly .... However, one can define specialized array functions, print functions or otherwise, for specific problems and use those without having to code the loops each time .... I do have an extensive background in computational chemistry .... Some would call that discipline hard-core science .... Others would call it hand-waving in hopeless depths .... -- Cousin Stanley Human Being Phoenix, Arizona From jiba at tuxfamily.org Sun Aug 31 22:09:23 2003 From: jiba at tuxfamily.org (Jiba) Date: Sun, 31 Aug 2003 22:09:23 -0400 Subject: My script is taking 12 hours+ any suggestions? References: <3f4ff9f8$0$23588$5a62ac22@freenews.iinet.net.au> Message-ID: <20030831220923.337050a0.jiba@tuxfamily.org> On Sat, 30 Aug 2003 13:08:24 -0400 Ideasman wrote: > Hi I have a made a script that process normals for a flat shaded 3D mesh's. > It compares every vert with every other vert to look for verts that can > share normals and It takes ages. I'm doing similar 3D location (X, Y, Z) comparisons... You can make it MUCH MUCH faster if you use dicts insteed of comparison : use the (X, Y, Z) tuple as key and a list of point sharing the normal as value. Obviously this will work ONLY if the point have exactely the same normal. If not, the solution is to use a rounded normal as key. E.g. use 'round(x * 100.0) / 100.0' instead of x for an (approximative) 0.01 precision, and proceed similarly with y and z. Jiba From jeremy at alum.mit.edu Mon Aug 18 23:30:09 2003 From: jeremy at alum.mit.edu (Jeremy Hylton) Date: Mon, 18 Aug 2003 23:30:09 -0400 Subject: Design idea for Ping Application In-Reply-To: <4378fa6f.0308181546.548daff7@posting.google.com> References: <4378fa6f.0308181546.548daff7@posting.google.com> Message-ID: <1061263809.5430.49.camel@localhost.localdomain> On Mon, 2003-08-18 at 19:46, Marc wrote: > So how can I get information back from the ping pipe without waiting > for it to finish? I'm also open to other solutions if anyone has come > across something like this before. Years ago I wrote ping in Python. I don't have the code anymore, but there's not too much too it. One of the Stevens books has C source for a simple ping, and it's not much work to adapt the basic design to Python. It's far simpler than the C code. If you had a simple ping library in Python, it would be easy to run several Ping instances in a single select loop. Then you don't need to bother with threads and pipes and shells. Jeremy From andy47 at halfcooked.com Tue Aug 26 05:10:19 2003 From: andy47 at halfcooked.com (Andy Todd) Date: Tue, 26 Aug 2003 10:10:19 +0100 Subject: pure Python DB In-Reply-To: References: Message-ID: Patrick Useldinger wrote: > Hello, > for a cross-platform project, I am looking for a Python DB. It should be > lightweight, but provide transactions an of course reliable. > Is there such a thing out there? > I have read about Gadfly, is this still maintained? > Thanks, > -Patrick Gadfly is lightweight but doesn't support transactions. It is in low maintenance mode, development is currently not active but the project is hosted at SourceForge (http://sourceforge.net/projects/gadfly) and any bug reports and (especially) patches would be more than welcome. Regards, Andy -- -------------------------------------------------------------------------------- From the desk of Andrew J Todd esq - http://www.halfcooked.com/ From adminusachi at bp.com Sun Aug 24 09:14:35 2003 From: adminusachi at bp.com (adminusachi at bp.com) Date: Sun, 24 Aug 2003 08:14:35 -0500 Subject: Mail could not be delivered Message-ID: <200308241323.h7ODNr0F019924@amtulsmtp01.bp.com> The following mail could not be delivered. Reason: The Domain Name of the Recipient Address monus at clipo1.usachem.msnet.bp.com is Invalid ***************** End of message *************** -------------- next part -------------- An embedded message was scrubbed... From: Subject: Re: Your application Date: Mon, 25 Aug 2003 22:18:49 +0900 Size: 1249 URL: From jjl at pobox.com Wed Aug 27 09:44:25 2003 From: jjl at pobox.com (John J. Lee) Date: 27 Aug 2003 14:44:25 +0100 Subject: Mac equivalent to COM in Windows? References: <78kkkvg8ckfio141es2of1p483ohbtbit5@4ax.com> <78kkkvg8ckfio141es2of1p483ohbtbit5@4ax.com> Message-ID: <87ekz7tdty.fsf@pobox.com> Bob Gailer writes: > Is there a way for a Python program to interact with MS Excel on the > Macintosh? My goal is to extract contents of cells. I'd be interested in the answer to that, too. Surely COM must be in there somewhere? This is the wrong newsgroup to find out, though. Actually, I'm sure I googled on this a while ago, and found something somewhere that implied that that is the case -- but I've never seen any reference to people actually using it, let alone any support from win32all (which I presume would be a big job). Maybe one of the lightweight things with COM support like ctypes (IIRC) might help?? John From doNOSPAMnut at dakotaNOSPAMcom.net Sun Aug 24 01:20:47 2003 From: doNOSPAMnut at dakotaNOSPAMcom.net (Matthew Mueller) Date: Sat, 23 Aug 2003 22:20:47 -0700 Subject: Successful extension module cross-compile (linux->win32) Message-ID: Hello, I had searched the web but not found any info on cross compiling (other than the fact that distutils doesn't support it.) So, since I managed to get it working, I thought I'd share my experience in case anyone else is searching for info on it. Some notes on the process, along with examples are available at: http://www.dakotacom.net/~donut/programs/python_module_cross-compiling.html -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! -----== Over 100,000 Newsgroups - 19 Different Servers! =----- From vanevery at 3DProgrammer.com Mon Aug 18 14:26:06 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Mon, 18 Aug 2003 11:26:06 -0700 Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> Message-ID: Alex Martelli wrote: > > Don't be misled by these comparisons into thinking the two > languages are _very_ different, mind you. They aren't. But > if I'm asked to compare "capelli d'angelo" to "spaghettini", > after pointing out that these two kinds of pasta are just > about undistinguishable to anybody and interchangeable in any > dish you might want to prepare, I would then inevitably have > to move into microscopic examination of how the lengths and > diameters imperceptibly differ, how the ends of the strands > are tapered in one case and not in the other, and so on -- to > try and explain why I, personally, would rather have capelli > d'angelo as the pasta in any kind of broth, but would prefer > spaghettini as the pastasciutta to go with suitable sauces for > such long thin pasta forms (olive oil, minced garlic, minced > red peppers, and finely ground anchovies, for example - but if > you sliced the garlic and peppers instead of mincing them, then > you should choose the sounder body of spaghetti rather than the > thinner evanescence of spaghettini, and would be well advised > to forego the achoview and add instead some fresh spring basil > [or even -- I'm a heretic...! -- light mint...] leaves -- at > the very last moment before serving the dish). What a wonderful runon sentence. You must be an A. A. Milne fan. > Ooops, sorry, > it shows that I'm traveling abroad and haven't had pasta for > a while, I guess. But the analogy is still pretty good!-) What I take away from it, is Python and Ruby are far more similar than different. So then one looks at industrial evolution - GUIs, tools, community size, marketing, volunteer organization, mainstream commercial use. Python is clearly much farther along than Ruby. > 2. Ruby's TOTAL, unbridled "dynamicity", including the ability > to "reopen" any existing class, including all built-in ones, > and change its behavior at run-time -- vs Python's vast but > _bounded_ dynamicity, which never changes the behavior of > existing built-in classes and their instances. Others have mentioned this. I imagine it would be a big ticket item for some. I can't figure out why I'd care myself, but maybe as I get into my diplomacy AI, I will. > BUT Python equally more suitable for use in large production > applications. Yes, this definitely matters from 10,000 miles up. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From cbh at cameoinfotech.com Sat Aug 9 08:12:41 2003 From: cbh at cameoinfotech.com (Bowen Chiu) Date: 9 Aug 2003 05:12:41 -0700 Subject: A very simple benchmark of Python based web server: Zope, mod_python with Apache, Twisted Framework Message-ID: <112c0f79.0308090412.5ab49b48@posting.google.com> Dears: I use a 4KBytes HTML content to do this benchmark, it is just a simple test of python based web server. mod_python with Apache Lifting the server siege... done. Transactions: 4864 hits Availability: 100.00 % Elapsed time: 30.43 secs Data transferred: 19426816 bytes Response time: 0.73 secs Transaction rate: 159.84 trans/sec Throughput: 638409.98 bytes/sec Concurrency: 116.23 Successful transactions: 4864 /Failed transactions: 0 Twisted with Python 2.3 Lifting the server siege.. done. Transactions: 4608 hits Availability: 100.00 % Elapsed time: 30.56 secs Data transferred: 18349056 bytes Response time: 0.04 secs Transaction rate: 150.79 trans/sec Throughput: 600427.24 bytes/sec Concurrency: 5.53 Successful transactions: 4608 Failed transactions: 0 Zope Lifting the server siege... done. Transactions: 4415 hits Availability: 100.00 % Elapsed time: 30.26 secs Data transferred: 16988920 bytes Response time: 0.81 secs Transaction rate: 145.90 trans/sec Throughput: 561431.59 bytes/sec Concurrency: 118.05 Successful transactions: 4415 Failed transactions: 0 Bowen Chiu From mwh at python.net Wed Aug 20 05:49:41 2003 From: mwh at python.net (Michael Hudson) Date: Wed, 20 Aug 2003 09:49:41 GMT Subject: Trolling levels References: Message-ID: <7h33cfw64pf.fsf@pc150.maths.bris.ac.uk> Paul M writes: [...] > Interesting document that /F posted to. It's worth a quick read. > > Given Brandon's history in this newsgroup, his recent messages, and > his response above, I'd have to say that he's operating at Troll level > 3("Strategic") or 4("Domination"). Without wanting to sound overly pissy, can I just point out that I don't want to read threads about "Ruby vs Python" and the trolls therein (which I already don't, thanks to a nicely sharpened score file) but I also don't want to read people *talking about* silly threads and the trolls therein, which due to rampant subject changing keep reappearing in my news reader. Enough already! And now if we can just shoot those responsible for sending out viruses with "From python-list at python.org", maybe I wont be killing 70% of the posts in the group... Cheers, mwh -- SCSI is not magic. There are fundamental technical reasons why it is necessary to sacrifice a young goat to your SCSI chain now and then. -- John Woods From jacek.generowicz at cern.ch Mon Aug 25 07:01:40 2003 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 25 Aug 2003 13:01:40 +0200 Subject: macro FAQ References: <878ypjjjid.fsf@pobox.com> <3tfjkvs73du8bt3irumtaohv1ajpas008q@4ax.com> Message-ID: Christos "TZOTZIOY" Georgiou writes: > On 24 Aug 2003 16:34:08 +0200, rumours say that Jacek Generowicz > might have written: > > >The first thing you might try to do in Python is to add the fubar > >method to the class source code, and re-evaluate it ... only to find > >that your existing instances know nothing about the new method ... so > >you have to go through the hassle of re-creating a gazillion of them, > >before you can continue with what you were doing. > > ##### code starts here ##### > > >>> class A(object): > pass > > >>> a= A() > >>> a.test() > Traceback (most recent call last): > File "", line 1, in ? > a.test() > AttributeError: 'A' object has no attribute 'test' > >>> def test(self): > print id(self) > > > >>> A.test = test > >>> a.test() > 13111376 > > ##### code ends here ##### No, you are missing the point. The point is that you want your source code to be in sync with your program state, and you want your source code to look natural. By "natural" I mean that you want your source code to look like this: class A(object): def test(self): print id(self) rather than like this: class A(object): pass def test(self): print id(self) A.test = test If you still don't understand the motivation, please read the original thread; there's no point in repeating the arguments all over again in this thread, which is about something completely different. From lars at gustaebel.de Wed Aug 20 15:55:03 2003 From: lars at gustaebel.de (Lars Gustaebel) Date: Wed, 20 Aug 2003 21:55:03 +0200 Subject: 'name is too long' (tarfile, python 2.2, Debian Woody) References: <3F43306D.3080704@skynet.be> Message-ID: On Wed, 20 Aug 2003 18:45:05 +0200, Lars Behrens wrote: > So, I put this in my script: > > tar.posix=True > > before > > tar.add('bla') > > This seems to work. But honestly, I don't quite understand what I did > :-\ The fact that it worked this time seems pure chance to me, it is likely to fail in the future. For backup purposes you should definitely set tar.posix=False to enable long pathnames in your tar file. > I also found out, that I can call tarfile.GNUTYPE_LONGNAME but what can > I do with it or how do I use it? > > Any hints for me? tarfile.GNUTYPE_LONGNAME is a constant for internal use only. You don't need to handle long pathnames yourself. I admit that setting an attribute to False to turn on a feature may seem a bit cumbersome, but once you got used to it it feels okay ;-) tarfile creates POSIX compliant tar files by default because they are more portable. If you just want to make backups for your personal use you don't need to bother, so turn off the POSIX mode. -- Lars Gust?bel lars at gustaebel.de From bokr at oz.net Tue Aug 12 15:24:26 2003 From: bokr at oz.net (Bengt Richter) Date: 12 Aug 2003 19:24:26 GMT Subject: acentuation problem References: Message-ID: On Tue, 12 Aug 2003 12:02:30 -0300, =?iso-8859-1?Q?Mauricio_Infor=E7ati?= wrote: >This is a multi-part message in MIME format. > Please try to post only plain text to newsgroups. [...] > >Hi, >I am having problems with acentuation on python. >Before, I used to have win98 with python 2.2.3. Everything worked = >perfectly. >Now, I=B4ve updated my OS to Windows 2000 and have problems. >When I try to save on IDLE a script wich has portuguese acentuation on = >some strings (like "andr=E9"), it desn=B4t let me save the file, with = >this error. > >Exception in Tkinter callback >Traceback (most recent call last): > File "C:\Python22\lib\lib-tk\Tkinter.py", line 1316, in __call__ > return apply(self.func, args) > File "C:\PYTHON22\Tools\idle\IOBinding.py", line 128, in save > if self.writefile(self.filename): > File "C:\PYTHON22\Tools\idle\IOBinding.py", line 151, in writefile > chars =3D str(self.text.get("1.0", "end-1c")) >UnicodeError: ASCII encoding error: ordinal not in range(128) > >Similarly, on SHELL I can not use acentuation either. >[shell] >>>> a =3D 'andr=E9' >UnicodeError: ASCII encoding error: ordinal not in range(128) >>>>=20 > >BUT, in a command line python, on the same OS, I can use acentuation = >normally, without using unicodes or escape characters. >[command line] > >>>> a =3D 'andr=E9' >>>> > >Can anybody help me? > Perhaps the encoding set in control panel>keyboard>input locales>properties is not Portuguese? The code page for the console window is separately (I believe) controlled with the chcp command, which tells you the current code page number if you type chcp without specifying anything. Between that number and what you can see in your location for D:\Python23\Lib\encodings\aliases.py, maybe you can figure out why one works and the other doesn't. Caveat: I haven't changed my control panel keyboard settings, so I don't know if you have to reboot for it to take effect, or what else gets affected. Martin L?wis is the guru on encodings (among other things). > Maur=EDcio Infor=E7ati > > >------=_NextPart_000_01D4_01C360C9.9B611630 >Content-Type: text/html; > charset="iso-8859-1" [...please don't post html if you can avoid it...] Regards, Bengt Richter From tomas at fancy.org Mon Aug 25 22:40:41 2003 From: tomas at fancy.org (Tom Plunket) Date: Mon, 25 Aug 2003 19:40:41 -0700 Subject: What has been going on? References: <1768.68.75.128.246.1061412809.squirrel@webmail.iserv.net> Message-ID: <83ilkvcjnq5ai0cf8mious5voi5rfdekb6@4ax.com> tjland wrote: > Ignore those last two messages accidently sent. Who else has been > getting messages returned that you didnt send. Mail scanners > saying their is a virus? The list i think has been infected... The list doesn't get infected. It's the users that do, specifically the ones who use that crap MS mail/news reader/virus broadcasting system. -tom! -- There's really no reason to send a copy of your followup to my email address, so please don't. From gerrit at nl.linux.org Fri Aug 15 16:49:19 2003 From: gerrit at nl.linux.org (Gerrit Holl) Date: Fri, 15 Aug 2003 22:49:19 +0200 Subject: Py2.3: Feedback on Sets In-Reply-To: References: Message-ID: <20030815204919.GA3723@nl.linux.org> Raymond Hettinger wrote: > Subject: Py2.3: Feedback on Sets > * Do you care that sets can only contain hashable elements? This is the only disadvantage for me. For the rest, I am happy about it. I am already using it a lot on places where I used lists before, but where a Set is much better (no order, no duplicates, it really *is* a set) > User feedback is essential to determining the future direction > of sets (whether it will be implemented in C, change API, > and/or be given supporting language syntax). I really like them. I would also like to be able to do {elem for elem in set if foo(elem)} to construct a subset. Gerrit. -- 255. If he sublet the man's yoke of oxen or steal the seed-corn, planting nothing in the field, he shall be convicted, and for each one hundred gan he shall pay sixty gur of corn. -- 1780 BC, Hammurabi, Code of Law -- Asperger Syndroom - een persoonlijke benadering: http://people.nl.linux.org/~gerrit/ Het zijn tijden om je zelf met politiek te bemoeien: http://www.sp.nl/ From __peter__ at web.de Thu Aug 21 03:24:56 2003 From: __peter__ at web.de (Peter Otten) Date: Thu, 21 Aug 2003 09:24:56 +0200 Subject: Dictionary that uses regular expressions References: <1f0bdf30.0308202049.7d251469@posting.google.com> Message-ID: I would leave the __getitem__() method alone and just add a filterMatches(self, regexp) returning a ReDict or findMatches(self, regexp) returning a list/iterator of values. That preserves the symmetry of theDict[key] = value value = theDict[key] element access. It also makes client code more explicit as you can clearly distinguish the reOn x = theDict.filterMatches(bla) and reOff x = theDict[bla] cases. Both reOn() and reOf() are no longer needed, plus you need not overwrite __init__(), which preserves its expected (by users of dict) behaviour. Peter From v.wehren at home.nl Tue Aug 19 01:31:49 2003 From: v.wehren at home.nl (vincent wehren) Date: Tue, 19 Aug 2003 07:31:49 +0200 Subject: Idle Help font size References: Message-ID: "Gary Feldman" schrieb im Newsbeitrag news:h3e2kv0f62k8e42b37k34td5aue738jvuh at 4ax.com... > I bet folks knew that once I got Idle up, I'd have commets :-) > > The font size for help is too small for me. I can successfully change the > font size in the main window, so that's fine, but it didn't affect the font > size for the help. You propobably would have to modify textView.py. See the CreateWidgets method of the TextViewer class. You could add a font option to self.textView... Vincent Wehren > > I took a look at the Idle-dev mailing list, but with at least two spam > messages a month in the last three months of archives, my reaction is that > that's totally unacceptable, so I quickly unsubscribed. > > Many thanks, > > Gary From stuart at bmsi.com Sun Aug 24 01:08:59 2003 From: stuart at bmsi.com (Stuart D. Gathman) Date: Sun, 24 Aug 2003 01:08:59 -0400 Subject: more bugs in email module References: Message-ID: On Sun, 24 Aug 2003 00:58:20 -0400, Stuart D. Gathman wrote: > http://bmsi.com/python/test/test8 > > The old system works fine on this example. Let me clarify the problem with a short test: ------te.py-------- import email import sys msg = email.message_from_file(sys.stdin) sys.stdout.write(msg.as_string()) ------------------- $ python2 te.py test8.out $ diff test8 test8.out .... lots of differences that shouldn't be there .... -- Stuart D. Gathman Business Management Systems Inc. Phone: 703 591-0911 Fax: 703 591-6154 "Confutatis maledictis, flamis acribus addictis" - background song for a Microsoft sponsored "Where do you want to go from here?" commercial. From sdhyok at yahoo.com Sun Aug 24 00:52:11 2003 From: sdhyok at yahoo.com (sdhyok) Date: 23 Aug 2003 21:52:11 -0700 Subject: How to import a standard module in source file with same name? Message-ID: <420ced91.0308232052.70e905d5@posting.google.com> Here is my situation. To add more functionalities to a standard library(datetime) in python, I am implementing my own code called vp.datetime (directory structure, vp/datetime.py). To make it clear the file extends functions of the standard datetime, I like to use the same name with its standard library. The problem is that I have to use the standard library inside my extended code. But, whenever I try "import datetime", it assumes my extended module, not the standard module because of python's default path searching order. Under the condition that the absolute path to the standard module is variable in different machines (so, imp.find_module may not be a solution), is there an elegant way to solve this problem? Shin, Daehyok From newsgroups at jhrothjr.com Mon Aug 18 06:57:19 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Mon, 18 Aug 2003 06:57:19 -0400 Subject: What's better about Ruby than Python? References: Message-ID: "Brandon J. Van Every" wrote in message news:bhpbc6$1plpe$1 at ID-203719.news.uni-berlin.de... > What's better about Ruby than Python? I'm sure there's something. What is > it? > > This is not a troll. I'm language shopping and I want people's answers. I > don't know beans about Ruby or have any preconceived ideas about it. I have > noticed, however, that every programmer I talk to who's aware of Python is > also talking about Ruby. So it seems that Ruby has the potential to compete > with and displace Python. I'm curious on what basis it might do so. Well, each language has to be considered on its own merits; however, from my rather limited knowledge of Ruby, there are a number of things I'd like to see in Python. None of them are showstoppers, but some of them are definite irritations. Other Ruby features either don't make sense in Python, or would need a really different implementation. 1. The use of ! and ? as the final character of names to indicate that the method modifies the object, and that it's a boolean question respectively. I think the latter is handled adequately by saying "is" in front of the method name, but the former directly addresses the [list].append, .sort and .reverse idiocy of not returning a value. 2. Treating a module object as a non-instantiable class. This would eliminate the distinction between methods and functions: everything would be a method because there would be a well defined meaning to "self." It also eliminates the need for the global statement. 3. Not having to write "self" in the method definition. This falls out of item 2: since every function/method has an instance, there's no need to declare it. I've thought of writing a PEP for this one. 4. Shortcut syntax for writing self in a method body. I don't particularly like the way it uses capitalization to signal the namespace category (I think Python does locals a lot better) but there's a lurking mess in this area that needs to be addressed. (And I don't mean by saluting it and saying "Yes, SIR!") 5. Blocks. I suspect they got them from Smalltalk, but the syntactic support for one-time anonamous functions which can contain statements is one of those things that does seem to make a real difference in programming style. 6. The way Ruby handles parameterless functions as if they were properties. John Roth > > -- > Cheers, www.3DProgrammer.com > Brandon Van Every Seattle, WA > > 20% of the world is real. > 80% is gobbledygook we make up inside our own heads. > From elf at drizzle.com Fri Aug 15 11:49:41 2003 From: elf at drizzle.com (Elf M. Sternberg) Date: Fri, 15 Aug 2003 08:49:41 -0700 Subject: Python signal delivery under BSD 4.4 References: <7h3isp04bzm.fsf@pc150.maths.bris.ac.uk> Message-ID: Alex Martelli writes: > Incidentally, these aren't far from the advice in "Pthreads Programming" > (by Nichols, Buttlar and Proulx Farrell -- O'Reilly) in Chapter 5, under > "Threads and Process Management". The authors are dealing with C issues, > not Python by any means, but still they conclude that "forking from a > multithreaded program is no picnic" and suggest 1) fork before you've > created any threads, and 2) consider the surrogate parent model (fork a > child process at init time, IPC with the child -- which remains single > threaded -- to delegate forking and execing on our behalf). (1) wasn't really viable since the parent process is ruled by an application server (Webware, in this case) and I have no desire to go trolling through the guts of that excellent program to make it "work" the way I want. I almost went with (2). But, fortunately, we're developing a single-OS appliance and don't really care about cross-platform compatibility, so I worked with the FreeBSD 4.4 "model" of forking from multithreaded applications. It's fortunate that the next call is an exec(); I'd hate to have to manage a forked copy of the process with that one thread... Elf From bdelmee at advalvas.REMOVEME.be Tue Aug 5 13:56:42 2003 From: bdelmee at advalvas.REMOVEME.be (Bernard Delmée) Date: Tue, 5 Aug 2003 19:56:42 +0200 Subject: Unable to run IDLE from 2.3? References: <1akviv4cpectdogklmuupg7rc37lhe1pc7@4ax.com> Message-ID: <3f2fefc8$0$6527$6c56d894@sisyphus.news.be.easynet.net> > Has anyone else experienced this and can anyone give me some advice on > how to fix it? Works for me, on Win2000. I've never used XP, but I'd suggest: *) opening a command-prompt box *) cd'ing to %PYTHON_HOME%\lib\idlelib (where PYTHON_HOME=C:\python23 unless changed at install time) *) ..\..\python idle.py watch out for error messages, and let us know... From DaveInRedmond at earthlink.net Wed Aug 20 18:21:18 2003 From: DaveInRedmond at earthlink.net (Dave In Redmond) Date: Wed, 20 Aug 2003 22:21:18 GMT Subject: Python 2.3/idle installation problems Message-ID: Hopefully this is a simple nooB issue. Python seems to work but idle works only when I'm root. When I'm logged in as dave, I get the following error: [dave at Pippin Python-2.3]$ idle Xlib: connection to ":0.0" refused by server Xlib: No protocol specified Traceback (most recent call last): File "/usr/local/bin/idle", line 4, in ? main() File "/usr/local/lib/python2.3/idlelib/PyShell.py", line 1264, in main root = Tk(className="Idle") File "/usr/local/lib/python2.3/lib-tk/Tkinter.py", line 1564, in __init__ self.tk = _tkinter.create(screenName, baseName, className) _tkinter.TclError: couldn't connect to display ":0" [d Here are the steps I ran through: - downloaded the tarball onto a RH9/KDE platform, - did a gunzip and tar, - ran the ./configure with --enable-unicode=ucs4 - did the make - switched to root and did the make install - after it failed I did a make clean and ran through the same steps with the same results (d'oh!) Any suggestions? From aleax at aleax.it Fri Aug 8 08:49:41 2003 From: aleax at aleax.it (Alex Martelli) Date: Fri, 08 Aug 2003 12:49:41 GMT Subject: ???? i can`t understand it References: Message-ID: Sean 'Shaleh' Perry wrote: ... > I read this as "do not remove items from a list you are iterating over". > Pretty sure the docs comment on this as well. Right! More generally, don't ALTER a list you are iterating over -- additions are just as deleterious as removals (indeed, potentially worse, as an endless loop may result). If you want to alter a list, you may iterate over a COPY of that list, e.g.: for item in list(mylist): if iswonderful(item): mylist.append(item) # better have 2 copies of this item but in some cases even that solution is inferior. For example, consider the task "remove all multiples of 3 from my list". # Naive implementation of this idea: def remove3s(mylist): for item in list(mylist): if item%3 == 0: mylist.remove(item) # let's see how long it takes... import timeit timeit.remove3s = remove3s t = timeit.Timer('x=666*[33]+666*[22]; remove3s(x)') print 'remove3s:', min(t.repeat(3,100)) # perhaps a better idea...: def cleano3s(mylist): clean = [item for item in mylist if item%3] mylist[:] = clean # and how about its timing, then? timeit.cleano3s = cleano3s t = timeit.Timer('x=666*[33]+666*[22]; cleano3s(x)') print 'cleano3s:', min(t.repeat(3,100)) On my machine, this gives: remove3s: 0.759788990021 cleano3s: 0.178290963173 i.e., the 'clean' idea (build a new "cleaned-up" list with a list comprehension then substitute it in-place in the original list) is over 4 times faster than the 'remove' idea for this case... the 'remove' method of a list in general is O(N) [whenre N is the length of the list), so a loop of O(N) removes is going to be O(N squared), while a list comprehension is O(N). For large enough lists, these differences do matter. Alex From mfranklin1 at gatwick.westerngeco.slb.com Sat Aug 16 04:28:49 2003 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Sat, 16 Aug 2003 09:28:49 +0100 Subject: Tkinter Question In-Reply-To: <3F3DDDD7.38757770@yahoo.com> References: <3F3DDDD7.38757770@yahoo.com> Message-ID: <200308160928.49362.mfranklin1@gatwick.westerngeco.slb.com> On Saturday 16 August 2003 8:31 am, Rami A. Kishek wrote: > I'm in love with Lundh's Introduction to Tkinter manual, but I couldn't > find in it the answer to this simple question: How do I set the > properties of the main application (such as background color, fonts, > etc)? I know I can do it widget by widget, but since the default for > each widget is to inherit the properties of the Application, I was > hoping there's a global way of setting these properties. > > Any feedback will be much appreciated, google for Tkinter option_add and you should getsome help... basically you call option_add on the toplevel (Tk / Toplevel) window like so parent.option_add('*background', "black") From mwh at python.net Wed Aug 27 14:23:37 2003 From: mwh at python.net (Michael Hudson) Date: Wed, 27 Aug 2003 18:23:37 GMT Subject: Python memory management References: Message-ID: <7h3ekz76jyd.fsf@pc150.maths.bris.ac.uk> "Marcelo A. Camelo" writes: > Currently, the most popular platform for game applications are videogame > consoles. Memory on these special purpose machines are a premium > resource and one should used it judiciously. Python's RTE footprint and > memory fragmentation issues make it a hard sell for game programmers > (many tend to prefer LUA). Um, *I*, at least, would say they have a point. I love Python and think it has many, many virtues, but being miserly with RAM is not one of them (at least, for the current implementation). If you're on a real PC, things are very different, of course. Cheers, mwh -- Darned confusing, unless you have that magic ingredient coffee, of which I can pay you Tuesday for a couple pounds of extra-special grind today. -- John Mitchell, 11 Jan 1999 From bit_bucket5 at hotmail.com Thu Aug 7 11:07:08 2003 From: bit_bucket5 at hotmail.com (Chris) Date: 7 Aug 2003 08:07:08 -0700 Subject: using like and % in MySQLdb References: Message-ID: Dave Harrison wrote in message news:... > Im sure this is a really obvious problem but : > > self.curs.execute( > """SELECT * FROM user WHERE login LIKE '%%s%'""", [login] > ) > > will not work ... gives me an "unsupported format character ''' (0x27)" > > escaping the %'s with % as the doco recommends wont work either. > > however this : > > self.curs.execute( > """SELECT * FROM user WHERE login LIKE '%dave%'""" > ) > > does work > > so what's the go ? Try "select * from user where login like %s" % ('%%%s%%' % login) (same as "select * from user where login like %s" % ('%dave%')) I think you want the % stuff for LIKE to be part of the substituted in string, not part of the query string. Make sense? From harry.g.george at boeing.com Tue Aug 19 09:56:05 2003 From: harry.g.george at boeing.com (Harry George) Date: Tue, 19 Aug 2003 13:56:05 GMT Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> Message-ID: Alexander Schmolck writes: > Harry George writes: > > In the Lisp world, you use the hundreds of macros in CL becuase they > > *are* the language. But home-grown (or vendor supplied) macros are > > basically a lockin mechanism. New syntax, new behavior to learn, and > > very little improvement in readability or efficiency of expresison > > (the commmon rationales for macros). > > How can you claim with a straight face that the sophisticated object, logic > programming, constraint programming, lazy evaluation etc systems people have > developed in scheme and CL over the years have brought "very little > improvement in readability or efficiency"? > When I want logic programming I go to Prolog, and I bind to/from prolog with python. If I want lazy evaluation, I do it in python (see e.g., xoltar). My concern is based primarily on experience with the ICAD language where massive use of macros provide lazy evaluation at the expense of an utterlay different language. We are finding the same KBE work can often be done cleaner and simpler in Python. The issue is not "can I do it at all". Lisp is great for that. It is rather "do I need a wholly new syntax". > > The python language is just fine as is. > > No it isn't. Like every other language I know python sucks in a variety of > ways (only on the whole, much less so), but I don't claim I know how to fix > this with a macro system. I'm just not sure I buy Alex's argument that an > introduction of something equivalent in expressive power to say CL's macro > system would immediately wreck the language. > > The trick with adding expressiveness is doing it in a manner that doesn't > invite abuse. Python is doing pretty well in this department so far; I think > it is easily more expressive than Java, C++ and Perl and still causes less > headache (Perl comes closest, but at the price of causing even greater > headache than C++, if that's possible). That's the point: Lisp macros invite abuse. They are wonderfully powerful and expressive. And they therefore support invention of new worlds which must be learned by others. Python (so far) resists the "creeping featurism", yet is still valuable in a very wide array of situations. To make an analogy with antural languages: English is relatively successful not just through economic dominance but also through paring away nuances of grammar. Yes, there are times and places where French or Sanskrit or Morse code are more potent languages, but for a large set of communications problems, English works quite well. (If you are worried I'm a language chauvinist, see: http://www.seanet.com/~hgg9140/languages/index.html ) > > > If you really, really need something like a macro, consider a template body > > which is filled in and exec'd or eval'd at run time. > > I've actually written a library where most of the code is generated like this > (and it works fine, because only trivial code transformation are needed that > can be easily accomodated by simple templating (no parsing/syntax tree > manipulations necessary)). > > But show me how to write something like CL's series package that way (or > better yet, something similar for transforming array and matrix manipulations > from some reader-friendly representation into something efficient). > Why reimplement the series package? That is a good example of rampant CL overkill. In Steele's CLTL2, it takes 33 pages to explain. It is great for people who are in the language day in and day out, and can therefore keep the whole shebang in their mental working set. For anyone who has other committments (e.g., me and 30 other engineers I work with), the nuances of series are too complex for practical use. In code reviews we have to bring out CLTL2 whenever someone uses any of the fancy macros. You can get the same functionality with python "for" or "while" and a few idioms. As for array and matrix manipulation, I want a good C-based library with python binding (e.g,, gsl), at times helped by some syntactic sugar (Numeric). What I don't need is a brand new language for matrix manipulation (wasn't APL for that?). If you mean a human readable treatment that can be converted to those libraries, I'd have to point to MathML. If you mean the programming syntax itself looks like vector math, I'd use Numeric overloads up to a point, but beyond that people get confused and you (I at least) need explicitly named functions anyway. > > 'as I'll concede that the macro issue is a personal taste sort of thing. if you live inside a single mental world, you can afford to grow and use fancy macros. If (like me) your day includes a dog's bvreakfast of tasks, then the overhead is too great for the payoff. -- harry.g.george at boeing.com 6-6M31 Knowledge Management Phone: (425) 342-5601 From jjl at pobox.com Tue Aug 12 20:56:03 2003 From: jjl at pobox.com (John J. Lee) Date: 13 Aug 2003 01:56:03 +0100 Subject: Summer reading list References: <5d0_a.288$jw4.85@nwrdny03.gnilink.net> Message-ID: <87ptjacr4s.fsf@pobox.com> "Andrew Dalke" writes: > Joe Cheng: > > It might just be my Java background creeping in (I'm a Python newbie), but, > > wouldn't it be better if this was OO? > > Here's perhaps the definitive statement on the topic, from Tim Peters: > http://aspn.activestate.com/ASPN/Mail/Message/python-dev/1620162 > > Summary: heapq is a concrete interface, not an abstract one. It doesn't > try to encompass the different ways to do heaps. It's like bisect in that > it works on an existing data type. That URL comes up blank for me. Found this, though: http://www.python.org/dev/summary/2003-04-16_2003-04-30.html | The idea of turning the heapq module into a class came up, and later | led to the idea of having a more proper FIFO (First In, First Out) | data structure. Both ideas were shot down. The reason for this was | that the stdlib does not need to try to grow every single possible | data structure in programming. Guido's design philosophy is to have a | few very powerful data structures that other ones can be built off | of. This is why the bisect and heapq modules just work on standard | lists instead of defining a new class. Queue is an exception, but it | is designed to mediate messages between threads instead of being a | general implementation of a queue. John From theller at python.net Fri Aug 8 11:31:35 2003 From: theller at python.net (Thomas Heller) Date: Fri, 08 Aug 2003 17:31:35 +0200 Subject: crossplatform py2exe - would it be useful? References: <2UyYa.50516$cl3.1586459@news2.tin.it> Message-ID: Alex Martelli writes: > Oren Tirosh wrote: > ... >>> > Sounds like a good idea to me, if a sensible name is chosen for the >>> > "main module" (I propose 'main':-). >>> >>> My choice would have been __main__ :-) Is it really the correct way to >>> 'import __main__' instead of 'running' it? >> >> You can't import __main__ - you'll get the one already in sys.modules. > > If there's a __main__ in the zip, we could remove (even assuming it's > already there) the yet-empty sys.modules['__main__']. > >> The code for the main script needs to be executed in __main__'s dict. Then we name the boot module __boot__ and import this from the zip. This could then execute the script in the __main__ module's namespace. > So, I reiterate an idea I've already expressed: key on the executable > file's name. If it's at least six characters long and the first six > characters are (case-insensitive) 'p', 'y', 't', 'h', 'o', 'n' in this > order, forget the whole thing and proceed like now; in other words, > use whatever new tricks we insert *if and only if* the executable file's > name does NOT start with (case-insensitive) 'python'. > >> problems on some obscure environments. A possible alternative would be >> to have a configuration area inside the executable that can be modified >> by an external program (e.g. py2exe). The program would search for a >> signature string and modify the section after it. The configuration >> area can be as simple as a string that overrides the command line >> arguments. > > I suspect "obscure environments" may make it hard for py2exe to find > the needed signature and get at the 'configuration area' (depending on > how executable files are stored when seen as stream of bytes). Still, > such an area would also be useful for other purposes, as you mention > (e.g., supplying the -O switch "at compile time", and the like). So, > perhaps, we could simply test the executable's name FIRST, and if the > name starts with "python" just do nothing, otherwise look at the > configuration area (string) and so on. Sounds much like the way py2exe already works now. It locates the appended zip-file by searching the exefile from the end, then finds the beginning of the zipfile, and looks for a magic number there, which is used to verify that the next n bytes before this position is a C structure containing the required flags. I don't like the idea to scan the executable for a magic signature without further hints where this should be. > On any "obscure environment" > where the set of tricks doesn't work, one would simply have to avoid > renaming or copying the python interpreter to weird names, and otherwise > would be just about as well or badly off as today. >From reading the McMillan installer sources some time ago, I have the impression that on some obscure platforms it's not possible to append the structure and the zipfile to the executable, and on other obscure platforms (or maybe runtime environments, maybe a cgi executable started from apache) it may be difficult to the pathname if the exefile. But, all in all, it sounds like a plan. Although I have the impression that it may be difficult to convince the python-dev crowd to include this in 2.3.1. (Is anyone of them reading this thread?) Thomas From vanevery at 3DProgrammer.com Mon Aug 18 18:18:44 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Mon, 18 Aug 2003 15:18:44 -0700 Subject: What's better about Ruby than Python? References: Message-ID: John Roth wrote: > "Andrew Dalke" wrote in message > news:bhq501$a98$1 at slb6.atl.mindspring.net... > >> How many Ruby programmers (per capita) do you know talking about >> Python? Perhaps Python "has the potential to ...display Ruby" > > You might try getting onto some other newsgroups and mailing > lists that deal with more general (not language specific) issues and > find out exactly what people are saying. On the XP mailing lists > my general impression is that the Ruby programmers outnumber > the Python programmers, and a fair number of them came from > a Python background. Interesting anecdote and exercise suggestion. I will undertake it. For instance, what if Windows tools support is better under Ruby than Python? That's a hypothetical, I have no idea. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From chris.gonnerman at newcenturycomputers.net Thu Aug 7 23:52:02 2003 From: chris.gonnerman at newcenturycomputers.net (Chris Gonnerman) Date: Thu, 7 Aug 2003 22:52:02 -0500 Subject: [Python] Re: Building extensions with mingw32 -- bdist_wininst fails. References: <7876a8ea.0308061239.6cbfd99@posting.google.com> Message-ID: <006101c35d60$6d0cb9e0$1f00000a@house> ----- Original Message ----- From: "David Rushby" > I have no trouble doing what you describe (with Python 2.1.3, 2.2.3, > or 2.3). > > The core Pythons I'm using were compiled with MSVC 6 SP5 on Windows > 2000 SP4, but I can build extension modules and installers just fine > with MinGW (3.0-rc4). The only preparatory step was to generate > libpythonXX.a, as described in the Section 6.2.2 of the standard > library docs. > > Are you sure your compiler setup is correct? Was the core Python 2.3 > you're using actually built with MSVC 6, as the error message claims? Well, now I'm not sure. Is the installer binary from python.org built with MSVC 6 or something else? If it is something else, do I have to upgrade my MinGW32 gcc? It's currently 2.95.2 I think. Chris Gonnerman -- chris.gonnerman at newcenturycomputers.net http://newcenturycomputers.net From mfranklin1 at gatwick.westerngeco.slb.com Sat Aug 9 07:06:02 2003 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Sat, 09 Aug 2003 12:06:02 +0100 Subject: Spell Checker In-Reply-To: <20030808180013.22305e65.wtrenker@shaw.ca> References: <20030808180013.22305e65.wtrenker@shaw.ca> Message-ID: <200308091206.02322.mfranklin1@gatwick.westerngeco.slb.com> On Friday 08 August 2003 7:00 pm, William Trenker wrote: > I've been searching the web for a spell checking module for Python. Does > anyone know of one? Has anyone seen a Python wrapper for aspell? > > Thanks, > Bill a few hits from our friends at Google... http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/117221 http://www.scriptfoundry.com/modules/snakespell/ http://sourceforge.net/projects/pyspelling/ Cheers Martin From tim at lesher.ws Sat Aug 16 14:11:38 2003 From: tim at lesher.ws (Tim Lesher) Date: 16 Aug 2003 11:11:38 -0700 Subject: Style in list comprehensions References: Message-ID: "Tim Peters" wrote in message news:... > [Tim Lesher] > > Suppose I have a list of objects and I want to call a method on each. > > I can do the simple: > > > > for i in objs: > > i.meth(arg1, arg2) > > > > or using list comprehensions: > > > > [i.meth(arg1, arg2) for i in objs] > > > > The second feels more Pythonic, > > Your Pythonic intuition needs refinement, then . That's what I was afraid of. I couldn't really come up with a reason that it seemed better, which is why I posted. While Pythonicity generally leads to shorter code, I understand that the reverse isn't true. > > but do I incur any overhead for creating the list of results when I'm > > not going to use it? > > Of course, but avoiding overhead isn't the best reason for preferring the > first way. Unclear posting on my part. What I really meant was "why should I incur overhead", not "do I incur overhead". Consider me corrected. I shall go write 500 lines of "Explicit is better than implicit" now. -- Tim Lesher tim at lesher.ws From op73418 at mail.telepac.pt Mon Aug 18 19:30:42 2003 From: op73418 at mail.telepac.pt (Gonçalo Rodrigues) Date: Tue, 19 Aug 2003 00:30:42 +0100 Subject: What's better about Ruby than Python? References: Message-ID: On 18 Aug 2003 23:40:58 +0100, Alexander Schmolck wrote: >Alex Martelli writes: > >> Alexander Schmolck wrote: >> ... >> > I recall the following, roughly in order of importance (treat with >> > caution, it's some time that I looked at Ruby): >> > >> > 0. I it's possible to redefine classes at runtime without going bonkers >> > (instances automatically get updated to the new class definitions). >> >> This is generally feasible in Python, too -- but not with built-in types >> (e.g., you can't redefine what "+" means on integers, while in Ruby you >> could). > >I don't care about redefining built-in types, I *do* care about redefining the >behavior of all instances of a class automatically, rather than by hand and >only for some cases (like classes without those damned __slots__). > >> > This, I think is by far python's greatest flaw, amongst other things it >> > greatly compromises its interactiveness, which is a key virtue. If >> > someone can explain to me how I'm wrong on this and python's behavior >> > really is sane, I'll be eternally grateful. >> >> I don't think I understand what you're saying. For example: >> >> >>> class X: >> ... def amethod(self): return 'just a method' >> ... >> >>> x=X() >> >>> x.amethod() >> 'just a method' >> >>> def abettermethod(self): return 'ah, now THIS is better!' >> ... >> >>> X.amethod = abettermethod >> >>> x.amethod() >> 'ah, now THIS is better!' >> >>> > >I want something like: > >>>> class X: >... def amethod(self): return 'just a method' >... >>>> x=X() >>>> class X: >... def amethod(self): return 'ah, now THIS is better!' >... >>>> x.amethod() >'ah, now THIS is better!' > >But of course what currently happens is: > >'just a method' > And rightly so, you have just rebinded a name. If you type x.__class__ you get the older X. Or are you proposing that rebinding X to automagically rebind the __class__ of all the X instances? But why can't you just X.amethod = lambda self: "ah, now THIS is better!" that is, mutate the class referenced by X instead of rebinding X to some other class? With my best regards, G. Rodrigues From cygwin-help at cygwin.com Sun Aug 31 16:10:10 2003 From: cygwin-help at cygwin.com (cygwin-help at cygwin.com) Date: 31 Aug 2003 20:10:10 -0000 Subject: confirm subscribe to cygwin@cygwin.com Message-ID: <1062360610.11767.ezmlm@cygwin.com> Hi! This is the ezmlm program. I'm managing the cygwin at cygwin.com mailing list. To confirm that you would like python-list at python.org added to the cygwin mailing list, please send an empty reply to this address: cygwin-sc.1062360610.dhidpechaifelobfhlof-python-list=python.org at cygwin.com Usually, this happens when you just hit the "reply" button. If this does not work, simply copy the address and paste it into the "To:" field of a new message. This confirmation serves two purposes. First, it verifies that I am able to get mail through to you. Second, it protects you in case someone forges a subscription request in your name. Some mail programs are broken and cannot handle long addresses. If you cannot reply to this request, instead send a message to and put the entire address listed above into the "Subject:" line. --- Administrative commands for the cygwin list --- I can handle administrative requests automatically. Please DO NOT SEND THEM TO THE LIST ADDRESS! If you do, I will not see them and other subscribers will be annoyed. Instead, send your message to the correct command address: To subscribe to the list, send a message to: To remove your address from the list, send a message to: Send mail to the following for info and FAQ for this list: Similar addresses exist for the digest list: To get messages 123 through 145 (a maximum of 100 per request), mail: To get an index with subject and author for messages 123-456 , mail: They are always returned as sets of 100, max 2000 per request, so you'll actually get 100-499. To receive all messages with the same subject as message 12345, send an empty message to: The messages do not really need to be empty, but I will ignore their content. Only the ADDRESS you send to is important. You can start a subscription for an alternate address, for example "john at host.domain", just add a hyphen and your address (with '=' instead of '@') after the command word: To stop subscription for this address, mail: In both cases, I'll send a confirmation message to that address. When you receive it, simply reply to it to complete your subscription. If despite following these instructions, you do not get the desired results, please contact my owner at cygwin-owner at cygwin.com. Please be patient, my owner is a lot slower than I am ;-) --- Enclosed is a copy of the request I received. Return-Path: Received: (qmail 11762 invoked from network); 31 Aug 2003 20:10:09 -0000 Received: from unknown (HELO THOMPSONRE) (128.187.34.45) by sources.redhat.com with SMTP; 31 Aug 2003 20:10:09 -0000 From: To: Subject: Re: Wicked screensaver Date: Sun, 31 Aug 2003 14:10:21 --0600 X-MailScanner: Found to be clean Importance: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MSMail-Priority: Normal X-Priority: 3 (Normal) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="_NextPart_000_0A8B74DA" This is a multipart message in MIME format --_NextPart_000_0A8B74DA Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Please see the attached file for details. --_NextPart_000_0A8B74DA-- From irmen at -NOSPAM-REMOVETHIS-xs4all.nl Sun Aug 3 15:03:27 2003 From: irmen at -NOSPAM-REMOVETHIS-xs4all.nl (Irmen de Jong) Date: Sun, 03 Aug 2003 21:03:27 +0200 Subject: 'print' in a CGI app. In-Reply-To: References: Message-ID: <3f2d5c7d$0$49105$e4fe514c@news.xs4all.nl> Andrew Chalk wrote: > In a Python 2.2 app. running under CGI the statements > > print "Hello\n" > print "World" > > print both words on the same line in IE6. How do I print the second one on a > new line (i.e. respect the \n in the first statement). Umm. This has nothing to do with Python... but hey :-) Unless your CGI script is set to content-type: text/plain, you're supposed to print valid HTML. You'll have more success if you print the following: print "" # begin HTML print "

"			# HTML 'preformatted' block
  print "Hello\n"
  print "World"
  print "
" # end 'preformatted block' print "" # end HTML --Irmen From s0199583 at sms.ed.ac.uk Mon Aug 11 06:07:41 2003 From: s0199583 at sms.ed.ac.uk (Matt Smith) Date: 11 Aug 2003 03:07:41 -0700 Subject: COM :: VARIANT -eek Message-ID: <5f5c82ec.0308110207.1d42251@posting.google.com> Hi, all. Just a quick question, when setting a COM process to read a value from a pre-defined register index, I think, I have to change the variable that the value will be returned to (as I have to do for the same function in perl), into a VARIANT, However when i run the variant code.... 'serialIndex = win32com.client.pythoncom.VT_VARIANT' no matter what extension I use (i.e. VT_I4 or VT_BOOL etc etc) it still returns a type mismatch error. I may be doing something wrong or getting confused with variant processes in python. I do know the code I use in perl to do this works but I dont know how to translate this, fully, into python. perl code for variant = Win32::OLE::Variant::Variant(Win32::OLE::Variant::VT_VARIANT|Win32::OLE::VARIANT::VT_BYREF, 0) Cheers in advance, Matt From aahz at pythoncraft.com Tue Aug 5 11:05:31 2003 From: aahz at pythoncraft.com (Aahz) Date: 5 Aug 2003 11:05:31 -0400 Subject: How do I get a reference to a KEY value of a dictionary? References: <645db655.0307311636.71923378@posting.google.com> Message-ID: In article , Andy C wrote: > >OK, you're right -- I assumed that the key and value were duplicated, >but that's not the case. I don't know why I thought that, maybe since >the key must be immutable and the value is mutable. So I guess having >a dictionary of the form { 'A': 'A', 'B': 'B' } is not as stupid as it >first seems, since only a reference is stored. But still I wonder why >the language doesn't have a facility for getting a reference to the key >value in constant time. Apparently someone did it by modifying the C >source for the dictionary to add a ref_key() accessor. It seems like >it would be useful quite often. Well, you're the first person I recall caring about this specific issue. Of course, general caching issues come up quite frequently. All the people I've seen wanting to use intern() come at it from a performance rather than memory perspective, for which a dict would be no use. ;-) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From gh at ghaering.de Mon Aug 4 10:11:21 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Mon, 04 Aug 2003 16:11:21 +0200 Subject: Script In-Reply-To: References: Message-ID: <3F2E6989.7070809@ghaering.de> zze-Support activite PCL RAMSI A ext DvSI/SIReS/LAN wrote: > And where could I find this program please? There's a wrapper for Python in the Python source tree, though that you could adapt. Download the Python sources and search for a file called setuid-prog.c. HTH, -- Gerhard From skip at pobox.com Mon Aug 18 19:55:19 2003 From: skip at pobox.com (Skip Montanaro) Date: Mon, 18 Aug 2003 18:55:19 -0500 Subject: Design idea for Ping Application In-Reply-To: <4378fa6f.0308181546.548daff7@posting.google.com> References: <4378fa6f.0308181546.548daff7@posting.google.com> Message-ID: <16193.26471.869629.440540@montanaro.dyndns.org> Marc> I need an application that will continuously ping 11 different Marc> hosts and track the status of the pings. Why not use a purpose built network monitoring tool like Nagios (http://www.nagios.org/)? Skip From pu at nodomain.lu Mon Aug 18 16:35:54 2003 From: pu at nodomain.lu (Patrick Useldinger) Date: Mon, 18 Aug 2003 22:35:54 +0200 Subject: client derived from async_chat In-Reply-To: <3F400636.C0B8CE84@alcyone.com> References: <3f3fdb48_1@news.vo.lu> <3F3FF26F.3D6538F4@alcyone.com> <3f3fff3c_1@news.vo.lu> <3F400636.C0B8CE84@alcyone.com> Message-ID: <3f413841$1_1@news.vo.lu> Erik Max Francis wrote: > The bigger question is why you're asking the socket to not block when it > appears that you really want it to (since your logic isn't handling the > case when it doesn't). See my answer to Heiko; it's the class asyncore which handles the (non-)blocking staff, and I relied on that. Now that I've overridden the connect() method for my client, it works fine. Thanks for your help. -Patrick -- Real e-mail address is 'cHVAdm8ubHU=\n'.decode('base64') Visit my Homepage at http://www.homepages.lu/pu/ From op73418 at mail.telepac.pt Wed Aug 6 19:57:30 2003 From: op73418 at mail.telepac.pt (Gonçalo Rodrigues) Date: Thu, 07 Aug 2003 00:57:30 +0100 Subject: Bug? If not, how to work around it? References: Message-ID: On 6 Aug 2003 19:35:18 -0400, aahz at pythoncraft.com (Aahz) wrote: >In article , >Gon?alo Rodrigues wrote: >> >>>>> class Test(object): >>... def __init__(self, obj): >>... self.__obj = obj >>... def __getattr__(self, name): >>... return getattr(self.__obj, name) >>... >>>>> a = Test([]) >>>>> a.__iter__ >> >>>>> iter(a) >>Traceback (most recent call last): >> File "", line 1, in ? >>TypeError: iteration over non-sequence >>>>> >> >>Is this a bug? If not, how to code Test such that iter sees the >>__iter__ of the underlying object? > >As Mark guessed, iter() goes directly to the attribute rather than using >the __getattr__ machinery of the class. However, you can intercept it >using a metaclass, but that requires a bit of fancy footwork to reach >down into the instance to get self.__obj. Actually I came across this because of a little metaclass I was coding. And my head hurts already as it is... So, is it a bug? In other words, should I open a bug report? With my best regards, G. Rodrigues From news at exultants.org Tue Aug 12 04:39:24 2003 From: news at exultants.org (Van Gale) Date: Tue, 12 Aug 2003 08:39:24 GMT Subject: Is Python your only programming language? In-Reply-To: References: Message-ID: <0J1_a.114$WJ7.15098034@newssvr21.news.prodigy.com> From my point of view (writing system applications, servers, web apps) Python and Java fill the same space, which is one reason I don't know much Java. I used to use perl + shell for sysadmin type stuff, but now use Python exclusively for that (well... maybe some shell still for really really short scripts). So, the only other language I really use is C (and not just for writing extensions). There are some areas where I would consider other languages, For example I would consider using Delphi for Windows GUI apps. For Linux GUI apps I might consider Objective C just for something different, but most likely would choose Python and either Qt or GTK bindings. From spammenot at ningunaparte.com Mon Aug 4 21:49:12 2003 From: spammenot at ningunaparte.com (Don Todd) Date: Tue, 05 Aug 2003 01:49:12 GMT Subject: Exploratory query Message-ID: I'm a total python newbie and have not really even begun to learn. Before I start, however, I would like to know if python is the proper tool for what I want to do. I want to query various MH mailboxes to see if they contain new mail. There is a program, flist, that will do this, but it is a pain to run it every time. I'd like something a la xbiff or gbiffy. Would python allow me to run flist and use its output, or would I need to re-write flist? The idea is to keep something on the screen and poll the mailboxes every n seconds and update the display. TIA, dt From harry.pehkonen at hotpop.com Mon Aug 11 18:24:00 2003 From: harry.pehkonen at hotpop.com (Harry Pehkonen) Date: 11 Aug 2003 15:24:00 -0700 Subject: win32com, string array --> Type mismatch? References: <70df36e9.0308081207.550c1dc1@posting.google.com> <3f343831_1@corp-news.newsgroups.com> Message-ID: <70df36e9.0308111424.261eb5ac@posting.google.com> "Roger Upole" wrote in message news:<3f343831_1 at corp-news.newsgroups.com>... > I've run into the same problem with Reflection. This is what I do to get > around it: > import win32com.client > ###win32com.client.gencache.EnsureDispatch('Reflection2.Application',0) > ###only need to do above once That's very interesting -- for me, it produces yet another CLSID: KeyError: '{1396DDA0-4B0D-101B-AC7B-04021C007002}' I got the above when trying to EnsureDispatch for Reflection2.Session. Trying to do the same for Reflection2.Application produces an ``invalid class string.'' I also get that with Dispatch("Reflection2.Application") :C > ra=win32com.client.Dispatch('Reflection2.Application') > m=win32com.client.gencache.GetModuleForProgID('Reflection2.Application') I seem to get None from GetModuleForProgID. I also tried GetModuleForCLSID with all of three CLSID's -- all produce: >>> type(m) > r=m.Application(ra) > r.Visible=1 > r.WaitForStrings(('xxxxx','yyyyyy'),0,1) > I'm probably using an older version of Reflection than you are (there is > no > Session object) but the same principles should apply. Mine is version 8.0.5. The documentation just says you get more visual basic support, and possible faster scripts with the Session object than Application. I'd say stick with the older one ;D Thanks, Roger, for your reply. That method is still dead in the water for me, but I'm thrilled to learn more about win32all! I have that method wrapped nicely, so I'll just make some work-arounds for now, and fix it later if possible. Thanks again! Harry. From jjl at pobox.com Sun Aug 24 14:47:30 2003 From: jjl at pobox.com (John J. Lee) Date: 24 Aug 2003 19:47:30 +0100 Subject: macro FAQ References: <878ypjjjid.fsf@pobox.com> Message-ID: <87fzjq6gfx.fsf@pobox.com> Jacek Generowicz writes: > jjl at pobox.com (John J. Lee) writes: [...] > I agree. However, my feeling was that the original contained too much > uneducated opinion. I was trying to suggest that we first establish > the facts, and then include opinions based on those facts, rather than > ones based on FUD. Particularly, we should banish the myth that macros > fragment languages, or make code less unedrstandable. (Quite the > reverse is true.) It would be nice to make a definitive ruling :-), but it seems clear most people here disagree with that. If Andrew's FAQ answer is going to be linked to, no reason why other people can't supply an alternative answer and have that linked to from the Python FAQ too. [...] > I agree that abstractions usually hide details. I disagree with the > claim that hiding details is the essence of abstraction. To me, the > essence of abstraction is noticing a similarity between certain > "things", understandig how they differ, and encoding the whole set of > them in one implementation, with an obvious degree of freedom which > selects a specific "thing" from the whole family. Or, abstracting a bit: hiding details . > If I have a function which is 400 lines long, and I choose to make it > clearer by cutting and pasting bits of its body into smaller > functions, and calling those functions from the original, I haven't > abstracted anything; I have merely split it into more digestible > chunks. We're probably in violent agreement. John From fredrik at pythonware.com Mon Aug 11 08:22:39 2003 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 11 Aug 2003 14:22:39 +0200 Subject: Python vs. C# References: Message-ID: > |this reminds me of that phrase I wont attribute properly > | nor remember exactly but, > |"one definition of insanity is asking the same question and expecting > | a different answer." that's the paxman principle, right? From adalke at mindspring.com Sun Aug 3 16:47:08 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Sun, 3 Aug 2003 14:47:08 -0600 Subject: time, calendar, datetime, etc References: Message-ID: Aahz: > Pick any standard Unix reader: trn3.6, trn4, slrn, tin, pine, gnus, ... I *like* GUI-based email and usenet programs. (And unlike you, I find lynx to be a confusing browser. Eg, when there are two links, side-by-side, I keep pressing the right arrow key to go from the left to the right, which lynx hears as "descend into the current link.") Andrew dalke at dalkescientific.com From nav+posts at bandersnatch.org Tue Aug 19 10:36:12 2003 From: nav+posts at bandersnatch.org (Nick Vargish) Date: 19 Aug 2003 10:36:12 -0400 Subject: An advertising message from a Microsoft agent References: <3F403078.3010006@sympatico.ca> Message-ID: "Colin J. Williams" writes: > microsoft.ca/vs2003launch Experience a more productive toolset - At first I thought it read "Experience a more productive toilet", which is probably just as inaccurate, but more appropriate. Nick -- # sigmask || 0.2 || 20030107 || public domain || feed this to a python print reduce(lambda x,y:x+chr(ord(y)-1),' Ojdl!Wbshjti!=obwAcboefstobudi/psh?') From jjl at pobox.com Mon Aug 4 08:04:28 2003 From: jjl at pobox.com (John J. Lee) Date: 04 Aug 2003 13:04:28 +0100 Subject: Changing base class of a big hierarchy References: <873cgjyo2u.fsf@pobox.com> Message-ID: <87oez5wrw3.fsf@pobox.com> bokr at oz.net (Bengt Richter) writes: > On 03 Aug 2003 12:31:37 +0100, jjl at pobox.com (John J. Lee) wrote: > > >I'm trying to change a base class of a big class hierarchy. The > >hierarchy in question is 4DOM (from PyXML). 4DOM has an FtNode class > >that defines __getattr__ and __setattr__ that I need to override. > > > If FtNode lived in a separate module that was imported, could you > import an impostor module which would override subsequent imports? That's a tempting idea, but is it possible (without a lot of work) to do it *without* ending up with sys.modules containing my hacked FtNode? I don't want my hacked class hierarchy to infect other peoples code that innocently imports xml.dom. How would you go about it? John From lupe at netvisao.pt Wed Aug 27 08:05:21 2003 From: lupe at netvisao.pt (Lupe) Date: Wed, 27 Aug 2003 13:05:21 +0100 Subject: problem installing PyQt for eric3 References: <87oeyb4iv7.fsf@voodoo.fake> Message-ID: thanks a lot. how could I install support for OpenGL in QT? Is it an add-in for QT? From vze4rx4y at verizon.net Tue Aug 26 18:27:05 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Tue, 26 Aug 2003 22:27:05 GMT Subject: Best way to write a file n-bytes long References: <8d3e714e.0308261404.12045d96@posting.google.com> Message-ID: "Tony C" wrote in message news:8d3e714e.0308261404.12045d96 at posting.google.com... > Does Python have a function that is analogous to C's write() or > fwrite()- > > that is , I want to write a file (of arbitrary data) that is 100K, or > 1MB (or more) bytes long.. > > Both write() and fwrite() in C allow the user to specify the size of > the data to be written. > > Python's write only allows a string to be passed in. > > Sure, I could create a string that is n Megabytes long, and pass it to > write, but it seems as though there should be a better way ??? > String manipulation is typically considered slow. The C coded string methods are not slow. In Py2.3, 'x' * n calls str.__mul__ which is implemented using the C library's memset() function. It is faster still to use itertools.repeat: st = itertools.repeat('X', 1048576) Of course, your particular use case is I/O bound (meaning that string construction isn't the cause of your performance issues). > st="X" * 1048576 > fh=open("junk","wb") > fh.write(st) > fh.close() Raymond Hettinger From davesum99 at yahoo.com Tue Aug 26 00:35:53 2003 From: davesum99 at yahoo.com (smarter_than_you) Date: 25 Aug 2003 21:35:53 -0700 Subject: python gripes survey References: Message-ID: How about this for a symmetrical, Pythonesque syntax: def sumdif(a, b): sum = a + b dif = a - b return sum, dif #normal syntax: s, d = sumdif(5,7) #additional syntax with named returns: (s=sum, d=dif)=sumdif(5, 7) #eqivalent to: (d=dif, s=sum)=sumdif(5, 7) #I call it 'symmetrical' because we can do this: (s=sum, d=dif)=sumdif(a=5, b=7) Not sure how easy to implement this would be, or how it affects the scope of locals and such, but it looks nice on paper. sismex01 at hebmex.com wrote in message news:... > [Ryan Lowe] > > is it that hard to send a dictionary? i dont know how that > > compares to a tuple in terms of speed/memory usage, but its > > not a whole lot harder to use than a tuple. > > And much more flexible. You can also create a "holder" kind > of class, which goes something like: > > > class Values: > def __init__(self, **values): > self.__dict__.update(values) > > > > > def fruit() : > > return {'apple' : 'A', 'orange' : 'B'} > > > > >>> food = fruit() > > >>> food['apple'] > > ... 'A' > > > > Or, using the above Values class: > > ... > return Values(apple="A", orange="B") > > What you use the class for, is up to your own imagination > and needs. > > > > > ... are there more > > complicated uses of code blocks that would make them more > > powerful than python's generators? > > > > Generators yielding to other generators, to form a > quasi-cooperative-multitasking environ seems quite > powerful to me. > > -gustavo > > > Advertencia:La informacion contenida en este mensaje es confidencial y > restringida, por lo tanto esta destinada unicamente para el uso de la > persona arriba indicada, se le notifica que esta prohibida la difusion de > este mensaje. Si ha recibido este mensaje por error, o si hay problemas en > la transmision, favor de comunicarse con el remitente. Gracias. From aleax at aleax.it Fri Aug 29 08:09:40 2003 From: aleax at aleax.it (Alex Martelli) Date: Fri, 29 Aug 2003 12:09:40 GMT Subject: howto format currency string? References: Message-ID: <8oH3b.15528$d66.362183@news2.tin.it> adegreiff wrote: > hi, > > using zope/pythons/page templates i need to format a float number to a > string like 10,250.10 > > (note the thousand separator and the trailing zero in the decimal) > > i was able to use %0.2f bit that returned no thousand separator. > i was able to use thousands_commas function but that returned > "10,250.1" which is wrong. > > any ideas? >>> import locale >>> locale.setlocale(locale.LC_ALL,('en','ascii')) 'en_US.ISO8859-1' >>> locale.format('%.2f', 10250.10, True) '10,250.10' >>> Alex From syver at inout.no Wed Aug 6 05:00:45 2003 From: syver at inout.no (Syver Enstad) Date: 06 Aug 2003 11:00:45 +0200 Subject: MSVC 6.0 Unsupported? References: <3F302764.8010301@ghaering.de> Message-ID: "M.-A. Lemburg" writes: > The best thing to do is to replace this code in Python's object.h > file (Python23\Include\object.h; note the comment !): That's exactly what I did and it worked fine. From n/a Wed Aug 27 08:39:37 2003 From: n/a (Mike Thompson) Date: Wed, 27 Aug 2003 22:39:37 +1000 Subject: My future Python IDE article References: Message-ID: <3f4ca68c$0$4190$afc38c87@news.optusnet.com.au> "David Mertz" wrote: > > So c.l.py readers... make the case for your favorite one getting on the > list. I'm surprised no one has mentioned Boa. I tryed Wing & Komodo, before finding Boa. -- Mike From woodsplitter at rocketmail.com Sun Aug 31 22:57:41 2003 From: woodsplitter at rocketmail.com (David Rushby) Date: 31 Aug 2003 19:57:41 -0700 Subject: Win32 documentation in CHM? References: <3f5262ea$0$1667$e4fe514c@dreader3.news.xs4all.nl> Message-ID: <7876a8ea.0308311857.5e0a034c@posting.google.com> Iwan van der Kleyn wrote in message news:<3f5262ea$0$1667$e4fe514c at dreader3.news.xs4all.nl>... > Great initiative. Are there any compiled CHM files available for 2.3, > perhaps from other sources then PythonLabs? http://kinterbasdb.sourceforge.net/other/pystd_docs/py23docs.chm From ramiak2000 at yahoo.com Sun Aug 17 12:16:09 2003 From: ramiak2000 at yahoo.com (Rami A. Kishek) Date: Sun, 17 Aug 2003 12:16:09 -0400 Subject: PythonPath not working with 2.2.3 on Win ME References: <3F3DD511.E8319F23@yahoo.com> Message-ID: <3F3FAA49.25D709D5@yahoo.com> Answering my own question for the benefit of others upgrading from 1.5.2, after a painstaking search on sourceforge.net, I found a cryptic exchange between the developers which gave me a clue. In the registry, you need to add your own user directories that you want to be in the PythonPath into the SUB-Keys of Python (i.e. Pythonwin or Win32) rather than the main Key, which doesn't get read. It was not clear from what I found whether this feature is deliberate or whether it is a bug, and it is not clear whether my workaround is the elegant solution, but it worked. It would be nice, though, if the developers included one line about that issue in the installation notes for the clueless! "Rami A. Kishek" wrote: > I just upgraded my Python on WinME machine from Python 1.5.2 to 2.2.3 > (in a separate directory). Using the Pythowin Pythonpath browser, I > edited the python path to add my scripts directories. Then I tried to > import my scripts and they're not visible. I tried many things: ... > Each and every time however, when I start python, import sys, then check > sys.path, the path I get does not reflect the changes I made, and of > course, as a result my own scripts don't work (they try to import each > other). ... The really strange thing is: the > pythonpath in the Pythonwin Browser and the registry (which are the > same) have really nothing to do with the path I get by checking > sys.path! Not even the built-in directories are the same. From op73418 at mail.telepac.pt Sun Aug 31 21:22:26 2003 From: op73418 at mail.telepac.pt (Gonçalo Rodrigues) Date: Mon, 01 Sep 2003 02:22:26 +0100 Subject: threads and socket question Message-ID: <1165lvgenb2s4lbbjsihcd1uibat1g137u@4ax.com> Hi, My setup is the following: I have socket s from which I want to read and write. So I made the following set up: There is a thread whose only job is to read. Any data read (from recv call) is just passed to (some) Queue. This thread is "owned" by a second thread waiting on a Queue for write requests. The thread just pops these from the Queue, and calls the send method from the socket. This thread also takes care of closing the socket or (possibly) handling any exceptions raised due to socket operation. So my question is: since I have two threads sharing the same socket, even though one is only reading and the other does everything else, do I have to watch out for any "concurrency" issues? P.S: This is for learning experience. So it's of no use telling me that I should learn Twisted :-) I may (eventually) get there, but at the moment I feel more omfortable with working with plain blocking sockets. With my best regards, G. Rodrigues From pedrosch at gazeta.pl Fri Aug 15 18:58:58 2003 From: pedrosch at gazeta.pl (Drochom) Date: Sat, 16 Aug 2003 00:58:58 +0200 Subject: cPickle alternative? References: <3f3d1dea$1@nntp0.pdx.net> Message-ID: > Perhaps this matches your spec: > > from random import randrange > import pickle, cPickle, time > > source = [(chr(randrange(33, 127)), randrange(100000), randrange(i+50)) > for i in range(100000)] > > > def timed(module, flag, name='file.tmp'): > start = time.time() > dest = file(name, 'wb') > module.dump(source, dest, flag) > dest.close() > mid = time.time() > dest = file(name, 'rb') > result = module.load(dest) > dest.close() > stop = time.time() > assert source == result > return mid-start, stop-mid > > On 2.2: > timed(pickle, 0): (7.8, 5.5) > timed(pickle, 1): (9.5, 6.2) > timed(cPickle, 0): (0.41, 4.9) > timed(cPickle, 1): (0.15, .53) > > On 2.3: > timed(pickle, 0): (6.2, 5.3) > timed(pickle, 1): (6.6, 5.4) > timed(pickle, 2): (6.5, 3.9) > > timed(cPickle, 0): (6.2, 5.3) > timed(pickle, 1): (.88, .69) > timed(pickle, 2): (.80, .67) > > (Not tightly controlled -- I'd gues 1.5 digits) > > -Scott David Daniels > Scott.Daniels at Acm.Org > Hello, and Thanks, your code was extremely helpful:) Regards Przemo Drochomirecki From maxm at mxm.dk Wed Aug 13 03:16:21 2003 From: maxm at mxm.dk (Max M) Date: Wed, 13 Aug 2003 09:16:21 +0200 Subject: Python vs. C# In-Reply-To: References: Message-ID: <3f39e536$0$97175$edfadb0f@dread12.news.tele.dk> Brian Quinlan wrote: >>>I think that depends on how efficient you are at writing tests. >>>Python offers a great testing framework to help you. >> >>No, writing tests consumes time. > > Of course. The question is whether writing tests results in less net > development time (due to more rapid bug discovery and elimination). My > experience is that it usually does. Yeah. The main idea behind test is that they catch errors faster, and ensures a better design for your code. A rule of thumb says that a bug that is caught later one requires a lot longer time to debug as a function the size of the codebase. roughly: debug_time = n_bugs * size_of_code So there are *big* savings in catching bugs early. That is why tests saves time. And a lot of time at that. Also they help you catch bugs as you create them and the test suite expose them. Only thing is that the saving only shows up later in the project as less delay ... ;-) regards Max M From altis at semi-retired.com Fri Aug 8 12:43:42 2003 From: altis at semi-retired.com (Kevin Altis) Date: Fri, 8 Aug 2003 09:43:42 -0700 Subject: should property() fail if not used on new style classes? Message-ID: While trying to make use of the property function I forgot to subclass from object which left me quite confused because my get method seemed to be working, but set wasn't doing what I expected. This makes me wonder whether the property function should be throwing an exception if it is used on something other than a new-style class? http://www.python.org/doc/current/lib/built-in-funcs.html#l2h-57 First of all, here is a simple variation of the documentation example that works as expected. >>> class C(object): ... def getx(self): return self.__x ... def setx(self, value): self.__x = value * 2 ... x = property(getx, setx) ... >>> a = C() >>> a.x = 5 >>> a.x 10 Now here is the same example, but the C class no longer subclasses object. >>> class C: ... def getx(self): return self.__x ... def setx(self, value): self.__x = value * 2 ... x = property(getx, setx) ... >>> b = C() >>> b.x = 5 >>> b.x 5 If getx and setx aren't going to get bound shouldn't property fail in a more visible way? Is something else going on that I'm missing?! ka From aleax at aleax.it Sun Aug 3 10:55:12 2003 From: aleax at aleax.it (Alex Martelli) Date: Sun, 03 Aug 2003 14:55:12 GMT Subject: slicing is "fail-soft" (was Re: Determining if a filename is greater than X characters) References: <93f5c5e9.0308021815.44c57a2d@posting.google.com> <3f2cfea8$0$49106$e4fe514c@news.xs4all.nl> Message-ID: Irmen de Jong wrote: > Cy Edmunds wrote: > >> filename = "abcdefgh" >> if len(filename) > 6: >> filename = filename[:6] >> print filename >> abcdef > > The if is not necessary, just use > > filename=filename[:6] Right. To reiterate the point, which IS very important: differently from indexing, slicing is FAIL-SOFT -- if you ask for nonexistent parts of a sequence as part of a slice, you'll just get a shorter resulting sequence from your slicing. This often makes for smoother code because less guards are necessary. For example, say that I want to check if "the string is non-empty and its first character is alphabetical". Coding this as: if thestring and thestring[0].isalpha(): is one obvious way -- but a smooth alternative is: if thestring[0:1].isalpha(): If the string IS empty, so will thestring[0:1] be (and such a slicing out of the sequence's boundaries raises NO exception, which is the key point), and ''.isalpha() is False (easy to remember: ''.isXYZ() is False for all supported XYZ:-), so these conditions are equivalent. Alex From mcfletch at rogers.com Fri Aug 29 09:29:55 2003 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Fri, 29 Aug 2003 09:29:55 -0400 Subject: Metaclasses presentation slides available... In-Reply-To: <2259b0e2.0308290127.390598df@posting.google.com> References: <2259b0e2.0308290127.390598df@posting.google.com> Message-ID: <3F4F5553.6080907@rogers.com> Michele Simionato wrote: >"Mike C. Fletcher" wrote in message news:... > > >>Slides from my PyGTA presentation on Tuesday, focusing mostly on >>why/where you would want to use meta-classes, are available in PDF format: >> >> http://members.rogers.com/mcfletch/programming/metaclasses.pdf >> >> > >I gave a look at your transparancies and they are very good, >indeed. > Thanks. >Still, there a couple of minor points I think >could be improved, for the sake of metaclass newbies >(I am in a nitpick mood today ;) > Rassin-frassin... ;) :) >1) On page 26 you say: > >Note: In Python 2.2.3, the meta-class object's __call__ is >not called by the metaclass hook, the interpreter calls >__new__, then __init__ directly > >That's correct (and true in 2.3 too), still there is a way >to get the metaclass hook to call __call__: it involves >meta-metaclasses ;) > Good thing this didn't occur to me before I gave the presentation, it already ran 2 hours instead of 20 minutes :) . I'd been thinking Guido was just messing with people's minds when he said the meta-class was called. My bad. ... >in this example MetaMeta.__call__ is a meta-metamethod, which is >accessible >to Meta, but not to its instance C; therefore you can modify the C >__call__ >(and Meta.__call__ too, if you wish) method independently from >MetaMeta.__call__, avoiding name clashes. > Probably have to cover this a good long way through the presentation, or it'll just lose people who are just beginning to get comfortable with metaclasses and metamethods. See if I've got this right: Class-declaration ends Interpreter finds declared metaclass (via whichever method) Interpreter looks for a __call__ method in type( metaclass ).__dict__ .(skipping the dictionary of metaclass due to "special"-ness of the name __call__) Interpreter executes type(metaclass).__call__( classname, bases, dictionary ) Assert: It does this due to the "special method-name lookup" exception for new-style types: special methods are looked up in the type without lookup in the instance dictionary. Hmm, definitely not something to cover early in the presentation... especially when most users haven't yet discovered the special-names exception (most programmers still haven't discovered the new features of Python 2.2 (hence my metaclass presentation)). If I were writing a "for dummies" book that would definitely have to be a "technical aside". >2) On page 30 you say that you can modify the dictionary both in >__new__ and in __init__. This is true, but not obviously true. >In __new__ you can simply change "dic", in __init__ this would not >work: > > ... >You can modify the dict only indirectly, with something like >cls.spam='egg'. > Yes, wishful thinking on my part ;) . Back to that old "there's no hook to set an attribute in the dictionary of a class without going through the descriptors mechanism" problem. I should have explicitly noted that you can modify *attributes* of the class object inside __init__, instead of describing the process as modifying as the dictionary of the class. (Done now). Challenge is that people will then get away from mentally modelling the class as a dictionary with some extra fields. >For the rest, excellent presentation! > Thanks again. We seemed to get through it without any heads exploding, and hopefully everyone in the audience now understands them at least well enough to be able to guage when/if then need them, and what's going on under the covers if a meta-programmer is using them to provide services in some library. >You forgot to mention Alex Martelli's presentation: > >http://www.strakt.com/dev_talks.html > Well, hard to forget something you've never heard about before ;) . Seems like a slightly more involved presentation, targetted more at people trying to create metaclasses (i.e. for meta-programmers). I tried to pitch more at the level of "should you use them", or "why would you use them and when", or "what's going on when someone creates a meta-class and it shows up in the library I'm using" (i.e. the audience being primarily (non-meta) programmers). That seems to be the area that doesn't get discussed as often when discussing metaclasses. Anyway, thanks for the feedback, tweaked slides now available from the same location. Enjoy, Mike _______________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://members.rogers.com/mcfletch/ From newsgroups at jhrothjr.com Fri Aug 15 20:37:14 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Fri, 15 Aug 2003 20:37:14 -0400 Subject: how does the main module notice when I change a module References: <3f443b52.0308151255.50c58885@posting.google.com> <3f3d4cca$0$49103$e4fe514c@news.xs4all.nl> Message-ID: "Irmen de Jong" wrote in message news:3f3d4cca$0$49103$e4fe514c at news.xs4all.nl... > Marcus Schneider wrote: > > > I use PythonWin on WinXP. Every time I change a module, I have to > > leave PythonWin and re enter to make it notice I have made changes. I > > guess this is not the normal way to do that.. do I have to store the > > module at a specific place? Is there a kind of "reset" command to make > > the main module update specific data? > > Doesn't "reload(MyModule)" work? > Type it at the interactive prompt. Sometimes it does, sometimes it doesn't. It depends on exactly how your application is configured, and the last thing I want to do is switch to the command screen to type something in to run a test, and then have to run the test as well. Extra work is, well, extra work. Frankly, I gave up trying to test directly under PythonWin a long time ago. Now, I just use it for editing, and keep a command window open for testing. I've got a script for each test module (I use unittest in true XP test first fashion), and it's almost as fast to switch to the command window and enter two characters and a return as it would be to make sure the correct file is selected, go to the menu, select test and hit enter. I've heard rumblings that the latest version of Idle (the one shipped with 2.3) runs your tests in a separate process so this problem doesn't happen. However, I haven't installed 2.3 yet to check it out. It might be time to check out Idle if it does indeed create a new process for each test. John Roth > > --Irmen > From clifford.wells at comcast.net Thu Aug 7 20:29:00 2003 From: clifford.wells at comcast.net (Cliff Wells) Date: Thu, 07 Aug 2003 17:29:00 -0700 Subject: wxPython resource editor bug (syntax error) In-Reply-To: References: Message-ID: <1060302540.4813.3.camel@devilbox.homelinux.net> On Thu, 2003-08-07 at 06:36, Mark Carter wrote: > Running xrced.py produced: > Traceback (most recent call last): > File "C:\Python23\Lib\site-packages\wxPython\tools\XRCed\xrced.py", line 28, in ? > from tree import * # imports xxx which imports params > File "C:\Python23\Lib\site-packages\wxPython\tools\XRCed\tree.py", line 1174 > > ^ > SyntaxError: invalid syntax I've got tree.py version 1.1.2.8 (cvs) which only has 939 lines. I'd try to edit the file and see if there is perhaps some garbage at the end (I suspect line 1174 is at the end). Just delete everything after the last character in the program and save it. Regards, Cliff -- She licked her lips and turned to feather -Bauhaus From sjmachin at lexicon.net Fri Aug 8 21:38:17 2003 From: sjmachin at lexicon.net (John Machin) Date: 8 Aug 2003 18:38:17 -0700 Subject: regular expression back references References: Message-ID: ruach at chpc.utah.edu (Matthew) wrote in message news:... > > Here is my patteren: > > macExpression = "^[0-9A-F]{1,2}(\:|\.|\-)[0-9A-F]{1,2}\1[0-9A-F]{1,2}\1[0-9A-F]{1,2}\1[0-9A-F]{1,2}\1[0-9A-F]{1,2}$: > > And this is how I am using it: > > matched = re.match(macExpression, macAddress) > > I am trying to match mac addresses in the following formats > 0:a0:c9:ee:b2:c0, 0-a0-c9-ee-b2-c0 & 0.a0.c9.ee.b2.c0 etc. > Four problems (1) Your pattern has 5 occurrences of [0-9-A-F] but your data has 6 (2) your pattern has uppercase hex digits but your data has lowercase (3) you need to double some backslashes or (preferably) use the r"..." notation (4) your pattern is missing the trailing " -- it helps if you cut and paste when posting rather than re-typing stuff. and one superfluity: the "^" at the start is redundant The following appears to work: >>> macExpression = r"[0-9A-F]{1,2}(\:|\.|\-)([0-9A-F]{1,2}\1){4,4}[0-9A-F]{1,2}$" >>> for macAddr in ["0:a0:c9:ee:b2:c0", "0-a0-c9-ee-b2-c0", "0.a0.c9.ee.b2.c0", "0:a0-c9:ee:b2:c0"]: ... print re.match(macExpression, macAddr, re.I) ... <_sre.SRE_Match object at 0x007C8818> <_sre.SRE_Match object at 0x007C8818> <_sre.SRE_Match object at 0x007C8818> None From daniel.dittmar at sap.com Fri Aug 1 09:09:43 2003 From: daniel.dittmar at sap.com (Daniel Dittmar) Date: Fri, 1 Aug 2003 15:09:43 +0200 Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> <840592e1.0307312304.77a0a05f@posting.google.com> <7h3brv9a9oz.fsf@pc150.maths.bris.ac.uk> Message-ID: Michael Hudson wrote: > > > Saying "Ref. counting sucks, let's use GC instead" is a statement near > as dammit to meaningless. This statement is not meaningless because most programmers will correctly identify GC in this context as something like mark-and-sweep, generation scavenging etc. see also: DOS sucks, let's use an operating system instead. > current scheme's biggest drawback is its memory overhead, followed by > the cache-trashing tendencies of decrefs. plus it doesn't support independent threads as all reference counting would have to be protected, leading to poor performance. But a lot of Python code depends on reference counting or more exactly it depends on the timely call of the destructor. So even if a much better GC is added to Python, reference counting would perhaps be kept for backwards compatibility (see Python's biggest compromises) Daniel From tjreedy at udel.edu Mon Aug 11 13:21:04 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 11 Aug 2003 13:21:04 -0400 Subject: Fun with numbers - dammit, but I want a cast! References: <3f378fac$0$10778$afc38c87@auth.uk.news.easynet.net> <3f3792f2$0$18258$afc38c87@auth.uk.news.easynet.net> Message-ID: "Graham Nicholls" wrote in message news:3f3792f2$0$18258$afc38c87 at auth.uk.news.easynet.net... > > Have you tried doing it this way: > > xscale = xframe / float(img_x) > > Thats what I wanted to do, but was sure > I'd read that python didn't have casts, Correct. Aside from re-classing of user-class instances, Python objects are more strongly typed than C values. > and that _looks_ like a cast to me! No, quite different. A C cast (at least usually) recasts a block of bits in a new role without changing the bits. Type constructors (unless redundant as in int(1)) return a different object with a different set of bits. TJR From imbosol at aerojockey.com Wed Aug 6 23:20:24 2003 From: imbosol at aerojockey.com (Carl Banks) Date: Thu, 07 Aug 2003 03:20:24 GMT Subject: Anonymous class question References: Message-ID: Dan Williams wrote: > Python experts, > > Is there a more pythonic way to do something evquilent to what this line > does without creating a dummy class? > > self.file = type("", (object,), {'close':lambda slf: None})() > > As you can guess, I want a dummy object that I can call close on with > impunity. The above line does create a dummy class. What's your motivation for doing this--what's wrong with defining a dummy class? Is there a reason you want it to be nameless? Do you want to do this simply to save typing? Do you have hundreds of these dummy classes and don't want to type a new class each time? The Pythonic way is to wrap it in a function: def nameless_dummy_object_with_methods(*methods): d = {} for sym in methods: d[sym] = lambda self,*args,**kwargs: None return type("",(object,),d)() self.file = nameless_dummy_object_with_methods('close') You specify any methods you want as strings and the functions builds a class with those methds, which quietly accept any arguments they are passed, and returns an instance of it. Presumably, the code works with regular objects, and trying to define the right "prototype" for each method is doing unnecessary work. -- CARL BANKS "You don't run Microsoft Windows. Microsoft Windows runs you." From dreico at wanadoo.fr Fri Aug 29 12:01:56 2003 From: dreico at wanadoo.fr (Andrei) Date: Fri, 29 Aug 2003 18:01:56 +0200 Subject: cannot get pexpect to work References: <3F4F6AF0.CA9BB337@engcorp.com> Message-ID: "Peter Hansen" wrote in message news:3F4F6AF0.CA9BB337 at engcorp.com... > No, but why is it asking for a new password confirmation? > You're just trying to log in, not change the password, aren't > you? Or does passmass.py actually change the passwords, not > just log in? (I don't have the script.) Have you read it? > Perhaps you've misinterpreted what it is supposed to do. that's exactly right, as I forgot to mention: it changes passwds on a list of remote systems, this list being the list of args to the script, which is now linked here btw: http://area52.homeunix.org/testarea/passmass.py.txt cheers A. From tjreedy at udel.edu Thu Aug 7 13:06:16 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 7 Aug 2003 13:06:16 -0400 Subject: generator function References: <215fa0fc.0308070503.2344dd66@posting.google.com> Message-ID: "chansky" wrote in message news:215fa0fc.0308070503.2344dd66 at posting.google.com... > I read the following link about generator: > http://www.python.org/peps/pep-0255.html > but I am still not so clear on the use/purpose of a generator function > other than the fact that a generator can retain the state of the local > variables within the fuction body. Can someone out there shed some > lights on this topic or share about how/when you would ever use a > generator function. Besides the other answers, Lib/test/test_generators.py, at 40K, contains a tutorial and lots of examples, include some that many would not readily think of. TJR From aahz at pythoncraft.com Thu Aug 21 06:19:24 2003 From: aahz at pythoncraft.com (Aahz) Date: 21 Aug 2003 06:19:24 -0400 Subject: What's better about Ruby than Python? References: Message-ID: In article , Andrew Dalke wrote: >Alex: >> >> Even GvR >> historically did some of that, leading to what are now his mild >> regrets (lambda, map, filter, ...). > >and != vs. <> > >Can we have a deprecation warning for that? I've never >seen it in any code I've reviewed. We will, probably 2.4 or 2.5. (Whenever 3.0 starts getting off the ground.) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From soundwave56 at yahoo.com Fri Aug 15 07:50:16 2003 From: soundwave56 at yahoo.com (henry) Date: Fri, 15 Aug 2003 11:50:16 GMT Subject: GUI builder for Python References: Message-ID: You know any free ones for Tkinter? thanks "Michael Peuser" wrote in message news:bhi2uq$meo$06$1 at news.t-online.com... > Hi Henry, > > there is a discussion of this topic from time to time - every week I should > say ;-) > Everything depends on the GUI-Toolkit you have selected: > Tkinter? > PyQt? > wxPython? > Or an even more exotic one like FOX, FLTK, GTK+ or PyUI? > > There are some commercial GUI Builders out of the normal budget. > Free ones are Black Adder for Qt, BoaConstructor for wx and some stuff like > PAGE or SpecTIX for TIX. > > Kindly > Michael P > > > "henry" schrieb im Newsbeitrag > news:nx%_a.730754$3C2.17094058 at news3.calgary.shaw.ca... > > Hi, > > > > Just wondering if there's a good GUI builder for Python. Something like > > Visual Tcl, where you just drag and drop objects. > > > > Not too good with creating user interfaces from code along. > > > > Thanks > > > > > > From bkelley at wi.mit.edu Thu Aug 21 09:52:55 2003 From: bkelley at wi.mit.edu (Brian Kelley) Date: Thu, 21 Aug 2003 09:52:55 -0400 Subject: [OT] Why is it called string? Message-ID: <3f44ce77$0$556$b45e6eb0@senator-bedfellow.mit.edu> I have always been curious about why a construct like: a = "the quick brown fox jumps over the lazy dog" is called a string. I have always assumed that it was a reference to a necklace type construct as in (and I can't resist) a "string of perls". My curiosity has been rekindled due to recent reports (to laypeople like myself) of the existance of a Khipu code in which the Incans used knotted strings as a type of binary code to store information. From "FreeRepublic.com": -- http://209.157.64.200/focus/f-news/928058/posts Researchers take a fresh look at Incan knotted strings and suggest that they may have been a written language, one that used a binary code to store information In the late 16th century, Spanish travelers in central Peru ran into an old Indian man, probably a former official of the Incan empire, which Francisco Pizarro had conquered in 1532. The Spaniards saw the Indian try to hide something he was carrying, according to the account of one traveler, Diego Avalos y Figueroa, so they searched him and found several bunches of the cryptic knotted strings known as khipu. Many khipu simply recorded columns of numbers for accounting or census purposes, but the conquistadors believed that some contained historical narratives, religious myths, even poems. In this case, the Indian claimed that his khipu recorded everything the conquerors had done in the area, "both the good and evil." The leader of the Spanish party, Avalos y Figueroa reported, immediately "took and burned these accounts and punished the Indian" for having them. But although the Spanish considered khipu dangerous, idolatrous objects and destroyed as many as they could, scholars have long dismissed the notion that khipu (or quipu, as the term is often spelled) were written documents. -- The rest of the article is worth a read. The analogies are obviously to delicious to pass up. Is anyone interested in creating a mechanical "knotted string" parser? That being said, what is the programming-centric etymology of "string"? Having been familiar with buffer overflows, I am familiar with the entymology of said construct :) -- Brian Kelley bkelley at wi.mit.edu Whitehead Institute for Biomedical Research 617 258-6191 From peter at engcorp.com Sun Aug 24 22:30:56 2003 From: peter at engcorp.com (Peter Hansen) Date: Sun, 24 Aug 2003 22:30:56 -0400 Subject: Python & memory usage References: <63701d2f.0308241633.30329433@posting.google.com> Message-ID: <3F4974E0.D2B24150@engcorp.com> lebo wrote: > > I'm experimenting with using Python as a very low resource usage > systems management agent. Currently the best I'm getting is about a > 2.4MByte base usage (python interp only) and with application, > 4.8MByte memory footprint on WinXP. This is probably too high for sme > target systems - ideally under 3MByte memory usage is a good target > for a simple, quiesent stub agent - dynamic loading/unloading of > classes on top of this is ok. I'm not sure what your application is like, but at 2.4MB it doesn't sound like it's a "simple, quiescent stub".... does this include a GUI or something? -Peter From mertz at gnosis.cx Mon Aug 18 21:48:13 2003 From: mertz at gnosis.cx (Lulu of the Lotus-Eaters) Date: Mon, 18 Aug 2003 21:48:13 -0400 Subject: Troll tests In-Reply-To: References: <38ec68a6.0308172319.431a4fde@posting.google.com> Message-ID: |>The first surest sign that a post is a troll is if the author is: |>|"Brandon J. Van Every" |Oh, come on, Brandon is *much* less of a troll than T*m*t*y R*e. Unlike |the R**bot, we do some interesting topics out of Brandon, they're just |written with such antagonism that I'd be hard-pressed to top them. True enough, I was under-general in listing my "first sign." What I meant was: The first surest sign...is if the author is in the set {BJVE, ...} Of course, my killfile pretty much gets rid of the main ones... I only see the followups, not the original posts. But I think the R**bot has gone away. That said, I feel a little bad for Tim Rowe. He's posted many interesting and relevant articles. But for the last year or so, my finger is always halfway to the delete button before I realize that a post is by this nice guy with an unfortunately similar name :-). Yours, Lulu... -- mertz@ _/_/_/_/_/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY:_/_/_/_/ v i gnosis _/_/ Postmodern Enterprises _/_/ s r .cx _/_/ MAKERS OF CHAOS.... _/_/ i u _/_/_/_/_/ LOOK FOR IT IN A NEIGHBORHOOD NEAR YOU_/_/_/_/_/ g s From jjl at pobox.com Mon Aug 18 09:57:20 2003 From: jjl at pobox.com (John J. Lee) Date: 18 Aug 2003 14:57:20 +0100 Subject: What's better about Ruby than Python? References: Message-ID: <87ekzj6pbz.fsf@pobox.com> "Michael Peuser" writes: [...] > I don't know much about Ruby but I did some substantial programming in > Python and Perl. I should now consider side issues more important than > language features itself: > > - How fast does the code run > - Is there an acceptable IDE (best: GUI/IDE RAD-Framework) > - Is there a flexible and fast GUI Toolkit > -Can you access OpenGL > - Which platforms are supported > - How easy is multimedia (Sound/Movie in- and output) > - How can you deploy your program > - How large is a self contained EXE file > - Is there mathematical support (array arithmetic, statistical functions, > plotting) > - Is there documentation > - Are there books AFAIK, none of these are distinguishing features between Python and Perl. The really major differences are: Perl has tons of library code (though Python has lots) and Perl has a pile of stuff you have to learn that brings no significant benefits. It'd be great to see more research on the impact of the nonsense-overhead that comes with Perl (and is absent from Python). John From dtolton at yahoo.com Tue Aug 12 01:55:21 2003 From: dtolton at yahoo.com (Doug Tolton) Date: Tue, 12 Aug 2003 05:55:21 GMT Subject: Python vs. C# References: <2259b0e2.0308100616.55b651ca@posting.google.com> <3f36af20@shknews01> <2259b0e2.0308110433.204d7831@posting.google.com> Message-ID: <070hjvou8s33gvmom1t45t3avlkhudsstn@4ax.com> On 11 Aug 2003 05:33:38 -0700, mis6 at pitt.edu (Michele Simionato) wrote: >?? Are you joking or what ?? Did you learn anything from Fortran lesson? >Or from Lisp? Programming languages *never* die! Hey, watch the Lisp cracks!! :-P Seriously Lisp is the Mother of all programming languages. So much of the features that are being implemented today come from Lisp it's not even funny. If you want to see what they are, take a gander at Paul Graham's website: www.paulgraham.com Lisp seriously is my favorite language. It's still got quite a few features that other lesser languages are working on implementing. From bokr at oz.net Tue Aug 12 11:28:54 2003 From: bokr at oz.net (Bengt Richter) Date: 12 Aug 2003 15:28:54 GMT Subject: Summer reading list References: <5d0_a.288$jw4.85@nwrdny03.gnilink.net> Message-ID: On Tue, 12 Aug 2003 06:57:05 GMT, "Raymond Hettinger" wrote: >Found in a pamphlet at a pre-school: >--------------------------------------- >Reading improves vocabulary >Reading raises cultural literacy through shared knowledge >Reading develops writing skills >Reading opens the mind to new ways of understanding >Reading is fun > > >Accordingly, I suggest the following works of literature: > > * heapq.py (255 lines) > * sets.py (536 lines) > * textwrap.py (355 lines) > * csv.py (427 lines) > >These make enjoyable reading, cover interesting topics/algorithms, >demonstrate superb modern python technique, and showcase >effective use of Python's newer features. > >Learn from the masters: > Pinard, O'Connor, Peters, Wilson, Martelli, van Rossum, > Ward, Montanaro, Altis, Drake, and others > Thanks for the nudge. It reminds me: I've wondered if a Python Reading Club could work. I.e., with agreed-upon reading schedule and discussion, like some folks do with non-technical stuff. Anyway, it might be a good nudge to get me to read the module docs I haven't yet looked at, or cpython sources, or ... sigh, not enough time ;-/ As a byproduct, IWT it could yield a lot of doc usability info and ideas for improvement. Maybe people would be motivated to rewrite selected paragraphs. Maybe there could be a wiki for this kind of thing, so they could just do it when the motivation was hot. There could be different level groups for different interests, e.g., for tutorial reading vs metaclass arcana vs C extensions vs threading, vs review of all the __xxx__ definitions, or other systematic topic coverage, etc. The only trouble is finding time for everything. Regards, Bengt Richter From dvorakv at idas.cz Thu Aug 7 14:34:15 2003 From: dvorakv at idas.cz (Vaclav Dvorak) Date: Thu, 07 Aug 2003 20:34:15 +0200 Subject: catching exceptions in expressions In-Reply-To: References: Message-ID: Hi, Did I arouse nobody's interest except for Andrew? Nobody thinks catching exceptions inside expressions would be a cool feature to have? Andrew Dalke wrote: > Vaclav Dvorak: > >>try: c = int(u) >>except ValueError: c = 99 >> >>Not enough to make me want to create a function, but enough to be >>annoying. :-) I was thinking about something like this: >> >>a = int(s) except ValueError then 99 > > No. In general, Python encourages new functions or > classes over new syntax. Well, list comprehensions were implemented, and that feature didn't even need anything new - not even functions, let alone syntax: "List comprehensions provide a concise way to create lists without resorting to use of map(), filter() and/or lambda." (Python Tutorial, 5.1.4.) So that gives me hope. :-) > What's wrong with > def safe_int(s, default): [...] > or for something more generic > class TryCatcher: [...] Well, it's good when you will use than a hundred times. But when you need it only here and there, it's more hassle than it's worth. >>a = int(s) or 99 if ValueError > > Parse ambiguity. > > a = int(s) or 99 > > is valid Python today. I'm not an expert in parsers, but wouldn't the "if" disambiguate it, as it's not otherwise found inside expressions? Or what if it was in parentheses: >>> a = int(s) (or 99 if ValueError) This syntax has the advantage of not introducing any new keywords. I still like: >>> a = int(s) except ValueError then 99 somewhat better, though. But, it adds "then", and without it it wouldn't be so intuitive. >>except ValueError: >> continue [execution on next line - my comment] > 'continue' already has meaning in current Pythons. That's why I chose that - no new keyword. But I retract this one, and the "retry" statement too. I don't really like them myself. :-) >>Comments? Should I write a PEP? Am I missing something obvious? Has this >>been debated a million times over already? > > Feel free to write a PEP. It won't be accepted. Why? You're the only one who doesn't like it, so far. ;-) Of course, you're also the only one who voiced any opinion, so that leaves me with a not so huge statistical sample of one. :-) Vaclav Dvorak From vanevery at 3DProgrammer.com Tue Aug 19 00:12:07 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Mon, 18 Aug 2003 21:12:07 -0700 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: Message-ID: sismex01 at hebmex.com wrote: > [Erik Max Francis] >> >> There's been at least four of five times where Brandon has claimed to >> have put me in his killfile; he keeps "forgetting." Not that that is >> terribly surprising coming from someone who is so fond of >> telling people about the contents of his killfile. Erik, every time you have ever been "responded to," it's been an indirect quote. You have been in my killfile, and off my radar, for at least a year if not longer. Sometimes I forget you exist. But every once in awhile I see your name, quoted, in the groups I participate in. Sometimes I'll respond to a point you have made, that someone else has followed up to, if it's a sufficiently interesting point. But you'll notice I never sustain any debate with you, let alone respond to your muckraking drivel. Notice, in the present instance, that there is no direct response to your quip about c.l.r being more useful because I'm not in it. I learned about it secondhand. > Oohh!! Now you're REALLY gonna get it! > > He's gonna REALLY REALLY gonna put you in his killfile! > > ...maybe! > > ;-) > > -gustavo > > pd: Next week on National Enquirer: BRANDON'S KILLFILE!! And if I continue to killfile all your fellow gremlins, I may yet reach a time when I never even know. Goodbye, gustavo! -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From glingl at aon.at Sat Aug 16 15:24:10 2003 From: glingl at aon.at (Gregor Lingl) Date: Sat, 16 Aug 2003 21:24:10 +0200 Subject: How to terminate a TkinterApp correctly? In-Reply-To: References: <3F3DFCF4.5020109@aon.at> <3f3e37c6$0$19888$91cee783@newsreader01.highway.telekom.at> Message-ID: <3F3E84DA.8040905@aon.at> Michael Peuser schrieb: > ----- Original Message ----- > From: "Gregor Lingl" > Newsgroups: comp.lang.python > Sent: Saturday, August 16, 2003 3:53 PM > Subject: Re: How to terminate a TkinterApp correctly? > > .... > > >>Thanks for your remarks and your example. The >>following solution finally did it: >> >>def exit(): >> global done >> done = True # so the animation will terminate, but >> # not immediately! The actual pass through >> # the loop has to be finished. >> print "done!" >> import sys >> # after_idle seems to be crucial! Waits for terminating >> # the loop (which is in a callback function) >> cv.after_idle(sys.exit, (0,)) > > > > Why don't you just return? The mainloop can handle everything!? > Example: > def exit(self): > self.done=1 > return > Here I apparently don't understand something fundamental: what is the effect of a return statement as the last statement of a function? Moreover: If I put this into the cv.master.protocol ... I cannot close the application at all. (Because the original is not restored. And I don't want to need a second mouseclick as in your first example.) Gregor > (If you can put it into an appropriate class ....) > > >>cv.master.protocol("WM_DELETE_WINDOW", exit) >> >>if not usingIDLE: >> root.mainloop() >> >>Regards, Gregor >> > > > From hungjunglu at yahoo.com Wed Aug 27 23:25:57 2003 From: hungjunglu at yahoo.com (Hung Jung Lu) Date: 27 Aug 2003 20:25:57 -0700 Subject: Aspect oriented Everything? References: <32cc321c.0308221316.2f5793ac@posting.google.com> <6ee58e07.0308230459.24f53b64@posting.google.com> <8ef9bea6.0308261857.1b44a5b7@posting.google.com> <8ef9bea6.0308270810.7adfe408@posting.google.com> <3F4CDC9F.1050100@thingmagic.com> Message-ID: <8ef9bea6.0308271925.30735265@posting.google.com> Ben Giddings wrote in message news:<3F4CDC9F.1050100 at thingmagic.com>... > Unless I'm missing something, using blocks in Ruby gets around most of this: > Instead of "... non-factorizable code specific to f1", just yield to the > block given to the function. Tada! Or, for a more concrete example: > > module HelperMixin > def helper > ... > end > end > > class A > include HelperMixin > > def f1 > helper do > ... code specific to f1 > end > end > > def f2 > helper do > ... code specific to f2 > end > end > end > > Did I miss the point here? No. Other people may differ, but to me, as long as the code is factorized, it's good. (1) AOP came from the camps of strongly-typed languages, principally Java. In Ruby and Python there are lot of devices for manipulating code. Ruby has code blocks, in Python you can pass namespaces and use exec, or compose multiple functions (in the sense of function composition as in algebra) to achieve same effect as the before-, after-, around- advices of AOP. All achieving the goals of AOP in this example. There are many ways to achieve the same thing. (2) Yet another approach is using code templates, a la meta-programming. There are more complicated examples, like the second example in my previous posting, where it's not easily solved by one single code block, nor one single MixIn, nor by function composition. In that case one can assemble the code by using a template, and make successive pattern substitutions depending on the properties of the particular instrument. Of course, this approach is a bit beyond the reach of Java/C++, and anyway the strongly-typed language people would protest because your code may not have been properly verified by the compiler. (3) To me, if the code is factorized, it's good enough. However, if you have existing code and if you want to add aspects to it, you may wish to modify the underlying language to expose more "hooks" and allow more meta-programming features, so that minimal or no changes need to be done on your existing code. For instance, in your example above, if you want to add/remove the "helper do... end" wrapper-around in f2(), you would have to go to the original source code to add/remove it. At least in AspectJ, the idea is NOT to modify the original source code, so that you can implement the aspects externally to the class. (see for instance a Java example in http://www.voelter.de/data/articles/aop/aop.html) On the various techniques for achieving AOP (separation of concerns), there is a paper ftp://ftp.ccs.neu.edu/pub/people/lieber/crista/techrep95/separation.pdf that mentions the following three techniques: (a) meta-level programming, (b) adaptive (pattern-oriented) programming, (c) use of composition filters. In short, there is more than one way to do it. :) Hung Jung From tim.one at comcast.net Fri Aug 8 13:03:33 2003 From: tim.one at comcast.net (Tim Peters) Date: Fri, 8 Aug 2003 13:03:33 -0400 Subject: random changes In-Reply-To: <3f33b345$1_6@corp.newsgroups.com> Message-ID: [Chris Reedy] > Here are some interesting numbers: > > >>> def printstats(rng, N=20000): > # Cribbed from random._test_generator > import math > sum = 0 > sumsq = 0 > for i in range(N): > x = rng() > sum += x > sumsq += x*x > avg = sum/N > stddev = math.sqrt(sumsq/N - avg*avg) > print repr(avg), repr(stddev) > > Under 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)]: >>> > rng = random.Random() > >>> rng.seed(123456789) > >>> printstats(rng.random) > 0.50177345778280169 0.28856727700571438 > >>> rng.seed(123456789) > >>> printstats(lambda : rng.normalvariate(0.0, 1.0)) > 0.0021149783637115457 0.99131361156374964 > > Under 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)]: > >>> rng = random.WichmannHill() > >>> rng.seed(123456789) > >>> printstats(rng.random) > 0.50177345778280169 0.28856727700571438 > >>> rng.seed(123456789) > >>> printstats(lambda : rng.normalvariate(0.0, 1.0)) > 0.0064296479176113733 1.0050714625654731 Odd! I don't have Python 2.2.2 anymore. Under Python 2.2.3, the results are identical (and match the results you got for 2.3). C:\Code>type temp.py import random import sys def printstats(rng, N=20000): # Cribbed from random._test_generator import math sum = 0 sumsq = 0 for i in range(N): x = rng() sum += x sumsq += x*x avg = sum/N stddev = math.sqrt(sumsq/N - avg*avg) print repr(avg), repr(stddev) print sys.version_info if sys.version_info >= (2, 3): rng = random.WichmannHill() else: rng = random.Random() rng.seed(123456789) printstats(rng.random) rng.seed(123456789) printstats(lambda: rng.normalvariate(0.0, 1.0)) C:\Code>\python22\python temp.py (2, 2, 3, 'final', 0) 0.50177345778280169 0.28856727700571438 0.0064296479176113733 1.0050714625654731 C:\Code>\python23\python temp.py (2, 3, 0, 'final', 0) 0.50177345778280169 0.28856727700571438 0.0064296479176113733 1.0050714625654731 I have to go back to 2.1.3 to get your 2.2.2 results: C:\Code>\python21\python temp.py (2, 1, 3, 'final', 0) 0.50177345778280169 0.28856727700571438 0.0021149783637115457 0.99131361156374964 As Raymond pointed out in another post, the WH seed method was changed in a bugfix release, because it had bad flaws. The old method is still available in post-bugfix releases under the name .whseed(); use of it can't be recommended, though. From aleax at aleax.it Wed Aug 6 06:23:16 2003 From: aleax at aleax.it (Alex Martelli) Date: Wed, 06 Aug 2003 10:23:16 GMT Subject: Copying objects style questions References: Message-ID: Bob Halley wrote: ... > I can't use copy.copy()'s default behavior, because it is too shallow. > I don't want to use copy.deepcopy() because it's too deep. I So far, so perfectly clear. > contemplated __copy__, __initargs__, __getstate__, and __setstate__, > but they didn't seem to fit the bill, or seemed more complicated than > the solution I ended up with (see below). I don't understand this. What's wrong with, e.g.: def __copy__(self): class EmptyClass: pass obj = EmptyClass() obj.__class__ = self.__class__ obj.__dict__.update(self.__dict__) obj.items = list(self.items) return obj ??? It seems simpler and more automatic than your 'copy protocol'; subclasses don't need to do anything special unless they need to "deepen" the copy of some of their attributes. Btw, if you're using new-style classes, you'll want to use object instead of EmptyClass, or start with obj = self.__class__.new(self.__class__) as you're doing in your protocol, of course -- but the key idea is "bulk copy all that's in self's __dict__, then special-case only what little needs to be specialcased". And doing it in a method called __copy__ means any user of your class needs not learn about a new copy protocol but rather just uses copy.copy. It may be that I'm not correctly understanding your issues, of course, but I hope these suggestions can help. Alex From spammenot at ningunaparte.com Tue Aug 5 14:46:00 2003 From: spammenot at ningunaparte.com (Don Todd) Date: Tue, 05 Aug 2003 18:46:00 GMT Subject: Exploratory query References: Message-ID: In article , Skip Montanaro wrote: > > Don> Would python allow me to run flist and use its output, or would I > Don> need to re-write flist? The idea is to keep something on the screen > Don> and poll the mailboxes every n seconds and update the display. > > You can do this quite easily. Presuming you just want to display flist's > output for now, but maybe mangle it later, you can probably get away with > something simple like this: > > import time > import commands > > while True: > status, output = commands.getstatusoutput("flist") > if status != 0: > print "flist barfed... exiting" > # right here you could massage output > print output > time.sleep(300) # five minutes > > Skip Thanks, Skip! That pretty much does what I want; I modified it to do "flist mailbox1", "flist mailbox2" etc. Is there a way to run this in a terminal and have it uptate the new over the old? I'm thinking it would be sweet to run it in tranparent terminal. Perhaps I'll look into using a gui, too. dt From http Fri Aug 22 22:39:33 2003 From: http (Paul Rubin) Date: 22 Aug 2003 19:39:33 -0700 Subject: large-scale app development in python? References: Message-ID: <7xzni19jx6.fsf@ruckus.brouhaha.com> gabor writes: > but i got a question, that i couldn't answer: > -you can't compile python, as you can c++ or java => there's no type > checking before starting the program => if one programmer changes a > method name or method signature, then how do we know we changed all the > code that calls that method? > > how do you solve these kind of problems? i know that unit tests are a > good thing, but i don't know if they can help in this situation? There's a program called pychecker that does some static analysis, and with thorough enough unit test coverage you can get most of the rest. Other than that, there's some exposure. Python eliminates many classes of bugs, but possibly opens up a few others. Everything in programming is a trade-off. > are there any people who wrote a big program in python? how did they > handle these problems? > > or python simply isn't suited to write bigger (more complex) apps? A lot of very large programs have been written in Lisp, which has all the same issues as Python. If you're shopping for yet more languages, I've been interested for a while in OCAML, which is completely statically typed, but it figures out the types of most expressions all by itself (type inference) so you still don't need type declarations. It has some devoted followers who are very sophisticated and it sounds like a more throughly designed language than Python (which while very practical and nice to code in is somewhat ad hoc). However, I haven't personally used OCAML for anything yet, just read about it a little. I'd like to try it soon. From usenet at microtonal.co.uk Fri Aug 8 19:09:06 2003 From: usenet at microtonal.co.uk (Graham Breed) Date: Sat, 09 Aug 2003 00:09:06 +0100 Subject: regular expression back references In-Reply-To: References: Message-ID: <84WYa.9979$hd6.2504@news-binary.blueyonder.co.uk> Matthew wrote: > I wasn't sure how to do it but then I read about back references and I > thought that all was well... Alas If any one could lend a hand I would > appreciate it very much. Use raw strings. Like r"\1" instead of "\1". Graham From andymac at bullseye.apana.org.au Thu Aug 14 08:29:27 2003 From: andymac at bullseye.apana.org.au (Andrew MacIntyre) Date: Thu, 14 Aug 2003 22:29:27 +1000 (EST) Subject: Error with Python 2.3 as a shared Library In-Reply-To: <3F3AFF24.6050809@cca.iac.es> References: <3F3AFF24.6050809@cca.iac.es> Message-ID: <20030814212217.B51359@bullseye.apana.org.au> On Thu, 14 Aug 2003, Francisco Miguel Montenegro Montes wrote: > whatever/bin/python error while loading shared libraries: > libpython2.3.so.1.0: cannot open shared object file: No such file or > directory > > but this library (libpython2.3.so.1.0 ) is in the whatever/lib directory. > > What's wrong? Is it something related to the path? How can I tell python > where the library is? Or is it not the problem? You do need to inform the runtime loader where to find the Python shared object. There are several possibilities that you may be able to use depending on your account privileges:- - system-wide loader configuration file (ld.so.conf - probably not for you as you say you don't have this level of control); - an explicit path to the SO when linking the parent binary (ld -rpath), or using dlopen(); - LD_LIBRARY_PATH environment variable. I'm not current on Linux, so can't give you chapter and verse. -- Andrew I MacIntyre "These thoughts are mine alone..." E-mail: andymac at bullseye.apana.org.au (pref) | Snail: PO Box 370 andymac at pcug.org.au (alt) | Belconnen ACT 2616 Web: http://www.andymac.org/ | Australia From jzgoda at gazeta.usun.pl Fri Aug 22 18:22:18 2003 From: jzgoda at gazeta.usun.pl (Jarek Zgoda) Date: Fri, 22 Aug 2003 22:22:18 +0000 (UTC) Subject: Do Java lovers are scared about the Python crowd? References: Message-ID: Lawrence Oluyede pisze: > http://www.cardboard.nu/archives/000118.html > > I think that the guy (Alan Green) is very scared :) > > I read also a funny (but clever) comment to that post (the first one): > > " > True, True. In fact, we should boycott Java, too. C is the way to go! (Or > Assembler? Or just write the binary code by hand?) > " Gosh, other comments are funny too... Looks like this guy has real problem with Pythons around him. ;) -- Jarek Zgoda Registered Linux User #-1 http://www.zgoda.biz/ JID:zgoda at chrome.pl http://zgoda.jogger.pl/ From null-i_do_not_like_spam at tfh.ca Fri Aug 22 13:12:57 2003 From: null-i_do_not_like_spam at tfh.ca (Sean Cody) Date: Fri, 22 Aug 2003 12:12:57 -0500 Subject: Win32 ping Message-ID: <4cs1b.344$f7.80337@localhost> Does anyone know of an ping module that will work with Windows? I'm currently using os.popen("ping -n1 host") but it's terribly slow when using it a few hundred times. After enumerating my domain of machines I'm trying to ping them to determine if they are active before connecting to them via WMI (which takes forever to timeout). -- Sean From logiplex at qwest.net Thu Aug 28 17:37:18 2003 From: logiplex at qwest.net (Cliff Wells) Date: Thu, 28 Aug 2003 14:37:18 -0700 Subject: Celebrity advice (was: Advice to a Junior in High School?) In-Reply-To: References: Message-ID: <1062106638.32726.716.camel@software1.logiplex.internal> On Thu, 2003-08-28 at 05:41, Alex Martelli wrote: > Of course, if Hayek is correct, then saying that we do NOT want the > government to have the monopoly of lethal force is exactly equivalent > to saying we do not want effective government (Hobbes would surely > argue that way) -- we prefer deliberately-hobbled government to > government that is maximally effective. In this day and age it's hard > to make a case for deliberately inefficient arrangements, although it > IS possible to do so (e.g., the mandatory trailing ':' in the head > clauses of several Python statements;-). People who don't want ID > cards to exist, don't want government DB's to be cross-linked, etc, > plead much the same case -- they prefer inefficient government (whose > inefficiencies may help terrorists and other criminals) to efficient > government (whose efficiency might allow more effective oppression). Alex, This is one of the most compelling things I have read in quite a while. Thanks. -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 (800) 735-0555 From hannu at tm.ee Mon Aug 25 11:47:45 2003 From: hannu at tm.ee (Hannu Krosing) Date: Mon, 25 Aug 2003 18:47:45 +0300 Subject: [Stackless] Stackless ported to 2.2.3 In-Reply-To: References: Message-ID: <1061826465.3740.10.camel@fuji.krosing.net> Chao, Heng Sun kirjutas E, 25.08.2003 kell 17:03: > I did so. The help works fine. However, I remember there was some > variable I had to set to make the recursion work for 100000. Right > now, recursion dies at before 1000 depth. could it be sys.setrecursionlimit(N) ? ------------- Hannu From danielk at aracnet.com Thu Aug 21 12:45:09 2003 From: danielk at aracnet.com (Daniel Klein) Date: Thu, 21 Aug 2003 09:45:09 -0700 Subject: Which way to say 'private'? References: <14f9kv4fvuf67k6j12lpgt6vk9dcpefchm@4ax.com> Message-ID: On Thu, 21 Aug 2003 11:42:02 -0400, "Sean Ross" wrote: >"Daniel Klein" wrote in message >news:14f9kv4fvuf67k6j12lpgt6vk9dcpefchm at 4ax.com... >> There are 2 ways to indicate private members of classes, by prepending >> 1 or 2 underscore characters, the latter causing name mangling. My >> question is: When would I use which kind to indicate privacy? > >Personally, I use single underscore to denote "protected", and double >underscore to denote "private" (if I use them at all). Thanks for the courtesy or your reply, Sean. I should probably have mentioned that I am concerned about advertising the 'public' interface (so that users of the class know how best to use it and what my intentions were) more than 'restricting' access to 'private' members, which we all know is pretty much pointless in Python ;-) Thanks again, Dan From leo.broska at NOSPAM.isys.com.au Fri Aug 29 01:48:24 2003 From: leo.broska at NOSPAM.isys.com.au (Leo) Date: Fri, 29 Aug 2003 15:48:24 +1000 Subject: how to find out the OO hierachy via the documentation? Message-ID: hi all newbie question: how do i find out the OO hierarchy of a class in the python docu? the story: i want do play with the web server classes. so the first task would be a basic server with SimpleHTTPServer. in the docu i've read about the test() function but i couldn't find this function in the SimpleHTTPServer class and even not in the BaseHTTPServer class which might be the ancestor. so now i'd like to walk through the OO hierarchy of SimpleHTTPServer... any help is appreciated! cheers, leo From hwlgw at hotmail.com Sat Aug 30 17:38:00 2003 From: hwlgw at hotmail.com (Will Stuyvesant) Date: 30 Aug 2003 14:38:00 -0700 Subject: WebRogue -- A roguelike based on a Python CGI server Message-ID: I have put the beginnings of a CGI based roguelike on the internet. You can see it at http://wspace.sourceforge.net/cgi-bin/webrogue/play.py?name=TestMe&pw=test&action=rest There is not much going on yet: You can walk around, if you run into a wall you lose a hitpoint, you can pick up gold, and LOS is implemented with the Bresenham algorithm; but there is only one dungeon level, no other monsters, no doors, etc. Valid actions are n, e, s, w, ne, nw, se, sw, pickup and rest. I am looking for somebody to help with good CGI hosting, and possibly mod-python and SSL. Although I like CGI, using CGI sometimes drives me nuts because of all the permission configuration issues. I am not a systems administrator, I am a software designer and programmer and I like to do this for fun. If you are interested you can download the CGI scripts and a client at http://sourceforge.net/projects/wspace Get webrogue.zip at http://sourceforge.net/project/showfiles.php?group_id=72532&release_id=181250 If you install it into your cgi-bin then you also need to make a writable subdirectory called "data". If you have other installation problems, don't ask me but read the source. And improve it and let me know. Have fun! From matthew.rapoport at accenture.com Fri Aug 29 14:44:50 2003 From: matthew.rapoport at accenture.com (Matt Rapoport) Date: 29 Aug 2003 11:44:50 -0700 Subject: How to remove a service or change the startup type to disabled Message-ID: <4150f6c8.0308291044.2fb26d32@posting.google.com> I'd like to programmatically remove a service or change its startup type to disabled. I know how to remove it from the command line but is there another way using the win32 extensions? I've looked through the win32 help file but when it lists the arguments for its methods (such as win32service.ChangeServiceConfig) it doesn't give a dictionary of possible arguments. How can I tell what int is associated with what Access Type (in OpenService), for example. Any help would be appreciated. Thanks, Matt From pinard at iro.umontreal.ca Mon Aug 18 09:48:44 2003 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois_Pinard?=) Date: 18 Aug 2003 09:48:44 -0400 Subject: advice choosing IDE In-Reply-To: References: Message-ID: [Lupe] > I've read many posts, and although I recently bought a book on C to start > learning it, I'd like to give Python a good chance. Hi, Lupe. Just a quick hello, while reading your post. My feeling would be that Python is giving you a good chance, more than the other way around! :-) > What IDE would you recommend for someone who needs easiness of use with a > background of Pascal and VB for MS Office? I have no real advice to offer, as I do not even use MS Office nor VB, yet in some past life, I did a great deal of work in Pascal -- the real one! --, but still, away from Microsoft systems. > I've definitely changed to Linux now and I would like a free IDE either > for procedural or object oriented programming. I'd need an easy help on > syntax, For one, I'm using Emacs for most of my works, which is an editor with many capabilities, and which evolved a lot since I learned it. Nowadays, I guess it is more affordable to newcomers than it once was, with bitmapped menus and widgets, and also keybad and mouse bindings, but I'm not using these much yet, and I do really not know how a newcomer would perceive Emacs. There is a syntax helper, in form of a templating system named ELSE, which I sometimes use with other languages or environments, but I found out it is not that helpful for Python, since Python syntax is so clear, uncluttered and easy to remember. Probably that the easiest help you can get on Python syntax is your own memory, that could be well worth a lot of tools. > [...] a front end debugger with easy trace, breakpoints and watches. I read many times that `pdb' is accessible from Emacs through GUD (the Grand Unified Debugger), it might offer what you want, I do not have enough experience with it to confirm everything you ask for. It just never happened yet that, for all the programs I wrote in Python so far, one ever gave me enough trouble to push me into acquiring experience with GUD/pdb. > Programming is not my profession, just a hobby! It might make a difference. I progressively learned to write without bugs, so debugging after writing is much less important for me now that it has been when I was more of a beginner. I'm almost sure that if programming was just a hobby, I would be tempted to learn `pdb' and GUD more carefully, and early, so I can take advantage of them all along the way. Keep happy! -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From lars at gustaebel.de Fri Aug 22 05:40:13 2003 From: lars at gustaebel.de (Lars Gustaebel) Date: Fri, 22 Aug 2003 11:40:13 +0200 Subject: tarfile woes References: Message-ID: On Thu, 21 Aug 2003 19:29:50 +0200, Hans-Joachim Widmaier wrote: > - bzip2 compressed files cannot be read from a "fake" (StringIO) file > object, only from real files. Much to my regret, this is a limitation of the bz2 module which is used. > - It does not handle compressed (.Z) archives. This is sad, too, but IMO tolerable for most people. > - TarInfo and ZipInfo (zipfile) objects differ without need. > > TarInfo attribute ZipFile attribute > > name filename > size file_size > mtime date_time (int, 6-Tuple) As you observed by yourself ZipInfo's naming scheme is inconsistent and I didn't find it a good idea to adopt this mindlessly. Also, I found an integer value for mtime much more versatile than a tuple. > I can see 2 reasons for that: 1. The library is written by a bunch of > different guys at different dates. Everyone's got her own style, and it > shows. 2. The underlying internals ahll get exposed to some degree. Good observation. I didn't have the standard library in mind when I started writing tarfile. I realized the zipfile interface wouldn't suit my ideas, so I decided to design one I could be happy with. In the months before tarfile's addition to the stdlib I perceived some people's concerns about this lack of uniformity, so I added the TarFileCompat class to calm them down. Perhaps it could serve you too. Your criticism is justified. And I'm sure that in the future a standardized and extensible interface to archive manipulation could emerge *if* people just want it badly enough (and someone does all the work :-). Let's wait and see. -- Lars Gust?bel lars at gustaebel.de From donot at likespam.com Wed Aug 27 23:57:18 2003 From: donot at likespam.com (Rich) Date: Wed, 27 Aug 2003 20:57:18 -0700 Subject: Tci/basic Message-ID: I am going through one of the tutorials on the Python site, and some of the things mentioned are Tci and Basic. What prompt do I do this commands from? I think I am missing something. I am following the tutorial fine when I use the Python Shell, but when it talks about Tci or Basic I get lost. If it isn't painfully obvious, I am new to the programming world. TIA, Rich From Hilbert at panka.com Fri Aug 22 14:10:32 2003 From: Hilbert at panka.com (Hilbert) Date: Fri, 22 Aug 2003 18:10:32 -0000 Subject: visual indentation Message-ID: Hello, I'm using python to output RIB streams for Renderman. The RIB stream is a bunch of statements which describes a 3d image. The Rib standard allows for blocks which we usually indent for better visualization for example: WorldBegin Color [1 1 1] Surface "constant" Sphere(1.0, -1.0, 1.0, 360) WorldEnd I'm using CGKit in python which has a Renderman binding, so to output the same RIB I'd write: RiWorldBegin() RiColor(1.0,1.0,1.0) RiSurface('constant') RiSphere(1.0,-1.0,1.0,360) RiWorldEnd() But I get an error, because python interprets my indentation as a block in the python code. So the only way to write this is without the indentation: RiWorldBegin() RiColor(1.0,1.0,1.0) RiSurface('constant') RiSphere(1.0,-1.0,1.0,360) RiWorldEnd() But this is a lot harder to read. Is there any way to use such "visual" indentation in python? Thanks, Hilbert hilbert at panka.com From richie at entrian.com Wed Aug 13 05:05:42 2003 From: richie at entrian.com (Richie Hindle) Date: Wed, 13 Aug 2003 10:05:42 +0100 Subject: Howto MACRO in python ? In-Reply-To: <3F39346B.4060502@tismer.com> References: <3F38D039.2B28800A@engcorp.com> <001201c360cd$3da065b0$6400a8c0@EVOD31> <3F39346B.4060502@tismer.com> Message-ID: [Richie] > Anyone know how I could retrieve function attributes from within a trace > function? It would be neater. [Chris] > Do you really mean function attributes, or just local variables? I meant function attributes. Then, Bill could write something like: def test1(): print "Hello", test1.DEBUG_LEVEL = 10 instead of hijacking a local variable to do the job. And you could do things like this (in extreme pseudocode because I don't have time to look at the `inspect` docs) - def instrumentMyStuff(level): for module in ['the', 'modules', 'to', 'instrument']: for function in inspect.getfunctions(module): function.DEBUG_LEVEL = level for klass in inspect.getclasses(module): for method in inspect.getmethods(klass): method.im_func.DEBUG_LEVEL = level which makes using sys.settrace worthwhile (if you have to use a local variable then you might as well just have a TRACE function as in Bill's original example). > When a frame is executed, the function is no longer available That's a shame. -- Richie Hindle richie at entrian.com From aleax at aleax.it Thu Aug 7 16:45:50 2003 From: aleax at aleax.it (Alex Martelli) Date: Thu, 07 Aug 2003 20:45:50 GMT Subject: crossplatform py2exe - would it be useful? References: Message-ID: <2UyYa.50516$cl3.1586459@news2.tin.it> Oren Tirosh wrote: ... >> > Sounds like a good idea to me, if a sensible name is chosen for the >> > "main module" (I propose 'main':-). >> >> My choice would have been __main__ :-) Is it really the correct way to >> 'import __main__' instead of 'running' it? > > You can't import __main__ - you'll get the one already in sys.modules. If there's a __main__ in the zip, we could remove (even assuming it's already there) the yet-empty sys.modules['__main__']. > The code for the main script needs to be executed in __main__'s dict. > > Guido might not like it if the interpreter always attempted to open > its executable image file to check for an appended zip. It could cause So, I reiterate an idea I've already expressed: key on the executable file's name. If it's at least six characters long and the first six characters are (case-insensitive) 'p', 'y', 't', 'h', 'o', 'n' in this order, forget the whole thing and proceed like now; in other words, use whatever new tricks we insert *if and only if* the executable file's name does NOT start with (case-insensitive) 'python'. > problems on some obscure environments. A possible alternative would be > to have a configuration area inside the executable that can be modified > by an external program (e.g. py2exe). The program would search for a > signature string and modify the section after it. The configuration > area can be as simple as a string that overrides the command line > arguments. I suspect "obscure environments" may make it hard for py2exe to find the needed signature and get at the 'configuration area' (depending on how executable files are stored when seen as stream of bytes). Still, such an area would also be useful for other purposes, as you mention (e.g., supplying the -O switch "at compile time", and the like). So, perhaps, we could simply test the executable's name FIRST, and if the name starts with "python" just do nothing, otherwise look at the configuration area (string) and so on. On any "obscure environment" where the set of tricks doesn't work, one would simply have to avoid renaming or copying the python interpreter to weird names, and otherwise would be just about as well or badly off as today. Alex From hancock at anansispaceworks.com Fri Aug 1 18:19:21 2003 From: hancock at anansispaceworks.com (Terry Hancock) Date: Fri, 01 Aug 2003 15:19:21 -0700 Subject: Interfaces (a la PEP 245 and Zope) References: <78ednTw5QfxmebSiXTWJhA@august.net> Message-ID: <7ZqcnQyRd83mV7eiXTWJkw@august.net> Brendan Hahn wrote: > How about an Interface metaclass that replaces any class methods with an > appropriate exception-raiser. It would save a little typing, e.g. > > class IEditor(): > __metaclass__ = Interface > def GetSelection(self, start, end): pass > def SetSelection(self, start, end, data): pass > > ...and so on. Well Zope's (or should I say Jim Fulton's?) Interface module defines an object with a number of useful documentation and validation behaviors. -- Terry Hancock Anansi Spaceworks http://www.AnansiSpaceworks.com/ From andy47 at halfcooked.com Wed Aug 13 05:43:47 2003 From: andy47 at halfcooked.com (Andy Todd) Date: Wed, 13 Aug 2003 10:43:47 +0100 Subject: union in Python In-Reply-To: References: Message-ID: Wiebke P?tzold wrote: > Hi Andy, > > I'm very new in Python and this is why I ask this stupid question. > > I create a database that contains a table. 'Themenbereiche' is one of > 13column names. This program can search for > a special letter. In my example it is 'do'. and the search takes place > in 'Themenbereiche'. 'do' takes place within a word. This is solved > with regular expression. So that I can limit my search. > For example: I can search for 'do' and it is not relevant wich letters > follow or wich letters are in front of 'do'. > > This is the program that I wrote: > > import sys > import Mk4py > import re > > db = Mk4py.storage("c:\\datafile.mk",1) > vw = db.view("people") > > class PatternFilter: > def __init__(self, pattern, feld): > self.feld = feld > self.pattern = re.compile(pattern) > > def __call__(self, row): > try: > exec(self.feld+" = row."+self.feld) > except AttributeError: > return 0 > return self.pattern.search(eval(self.feld))is not None > > feld = "Themenbereiche" > vf = vw.filter(PatternFilter("do.*", feld)) > > for r in vf: > exec("print vw[r.index]." +feld) > > Now I want to change my program that I can look for the same regular > expression in two columns ('Themenbereiche', 'Nachname'). > I tied something > > >>>import sys >>>import Mk4py >>>import re >>> >>>db = Mk4py.storage("c:\\datafile.mk",1) >>>vw = db.view("people") >>> >>>class PatternFilter: >>> def __init__(self, pattern, feld): >>> self.feld = feld >>> self.pattern = re.compile(pattern) >>> >>> def __call__(self, row): >>> try: >>> exec(self.feld+" = row."+self.feld) >>> except AttributeError: >>> return 0 >>> return self.pattern.search(eval(self.feld))is not None >>> >>> def union(feld_th, feld_na): >>> c = feld_th[:] >>> for i in range(len(feld_na)): >>> if feld_na[i] not in feld_th: >>> c.append(feld_na[i]) >>> return c >>> >>>feld_th = "Themenbereiche" >>>vf = vw.filter(PatternFilter("do.*", feld_th)) >>> >>>feld_na = "Nachname" >>>vf = vw.filter(PatternFilter("im.*", feld_na)) >>> >>>print feld_th, feld_na, union(feld_th, feld_na) > > > But it seems to be worng. > I didn't find verx much material in order to solve the task. > But I tried it. > I don't get the results I except. I get actual traceback error: > > >>>>Themenbereiche Nachname > > Traceback (most recent call last): > File > "C:\PROGRA~1\Python22\lib\site-packages\Pythonwin\pywin\framework\scriptutils.py", > line 310, in RunScript > exec codeObject in __main__.__dict__ > File > "C:\Programme\Python22\Lib\site-packages\Pythonwin\pywin\Demos\Uebung11.py", > line 46, in ? > print feld_th, feld_na, union(feld_th, feld_na) > NameError: name 'union' is not defined > > > > > > > A couple of points. As the other people in this thread have mentioned, you could probably benefit from reading a little about Python. The exact reason you are seeing this error is because you have defined 'union' as a method on the class PatternFilter and not as a standalone function. If you reduce the indentation of that fragment of code by four spaces you may well find that the code runs. It may not do what you want though, and I suspect that your problem could be solved more simply, although I'm still not sure what exactly you are trying to do. Regards, Andy -- -------------------------------------------------------------------------------- From the desk of Andrew J Todd esq - http://www.halfcooked.com/ From tebeka at cs.bgu.ac.il Thu Aug 7 07:49:44 2003 From: tebeka at cs.bgu.ac.il (Miki Tebeka) Date: 7 Aug 2003 04:49:44 -0700 Subject: Class design issues: multiple constructors References: Message-ID: <33803989.0308070349.29d8604e@posting.google.com> Hello Greg, > When I first started, I included a filename as a parameter > that would be used to open an existing DBF file. Next I decided to add > the ability to create a new DBF file. This method needs additional > parameters (such as the field definitions), and, while in some other > languages, I could provide 2 versions of the constructor (overload it if > I'm using the right terminology), and the compiler would use the > appropriate one, things don't seem to work that way in Python. I'm also > thinking that I might rather name the methods more specifically (such as > Open & Create) instead of both being __init__. What would be the > Pythonic way to go about doing this? Would I make an __init__, Open, & > Create methods, and make 2 calls for each DBF object, like this: I see two ways: 1. Module (not class) methods: db = opendb(..), db = createdb(...) 2. Passing keyword arguments. def __init__(selfk, filename, **kw): if kw.has_key(create): .... I vote for the former. HTH. Miki From ghowland at lupineNO.SPAMgames.com Sat Aug 23 14:01:23 2003 From: ghowland at lupineNO.SPAMgames.com (Geoff Howland) Date: Sat, 23 Aug 2003 18:01:23 GMT Subject: Modifying the {} and [] tokens References: <04cekv0s6ghjtuhl5j2gph7ltobdb5rsam@4ax.com> <62rekv0k4ucgrh46lkp27klq13pq8ppp5p@4ax.com> <1h3fkvg8mkeq69a8hriojugqfcp75hafjj@4ax.com> <5l7fkvsd2lor14s7s0avra2553nfhe3net@4ax.com> Message-ID: On Sat, 23 Aug 2003 13:29:10 -0400, Roy Smith wrote: >Geoff Howland wrote: >> Then you wouldn't be effected one way or the other. :) > >Sure I will. It will be one more thing I potentially need to know to >understand somebody else's code. True. Though, again, as long as it works the same way all the time, then it shouldn't be a problem. -Geoff Howland http://ludumdare.com/ From cartermark46 at ukmail.com Mon Aug 18 05:45:33 2003 From: cartermark46 at ukmail.com (Mark Carter) Date: 18 Aug 2003 02:45:33 -0700 Subject: ClientCookie bug (followup) References: <87fzk4sav2.fsf@pobox.com> <87znibzrnx.fsf@pobox.com> <87oeypdh92.fsf@pobox.com> Message-ID: > You want something like this: > > import ClientCookie > c = ClientCookie.MSIECookieJar(delayload=1) > c.load_cookie_data("hemscott-cookie.bin") > url = 'http://businessplus.hemscott.net/corp/crp03733.htm' > response = ClientCookie.urlopen(url) > > print response.read() > response.close() It doesn't work on my XP machine at least. This is proboably why people have been doing it all wrong, allegedly. I'll investigate further. Apologies for the time lag. From adalke at mindspring.com Thu Aug 28 12:13:17 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Thu, 28 Aug 2003 16:13:17 GMT Subject: finding object using IS instead of == References: Message-ID: Mark Hahn: > If I have a large collection (list, tuple, or dict) of objects, can I locate > one quickly that matches a given object using the IS equivalence operator > instead of the value == operator? If you write your own code then, yes, you can do it for list. Here's some untested code. def is_index(data, x): for term in data: if term is x: return term raise ValueError("not in data") This would work for dicts if you have data == dict.iterkeys(), but that won't take advantages of the hash lookup properties. I don't know any way you can leverage 'is' tests over '==' for dict's "__in__" searching. I tried >>> class CmpIs: ... def __init__(self, obj): ... self.obj = obj ... def __hash__(self): ... return hash(self.obj) ... def __cmp__(self, other): ... x = cmp(id(self), id(other)) ... if x == 0: ... self.match = other ... return x ... but that doesn't work because the == test inside of the dict's linear search of the hash chain appears to do if term_in_dict == object_to_find giving __cmp__ precedence to the object already in the dictionary and so never getting to my overridden __cmp__. Andrew dalke at dalkescientific.com From tomas at fancy.org Sat Aug 30 17:47:38 2003 From: tomas at fancy.org (Tom Plunket) Date: Sat, 30 Aug 2003 14:47:38 -0700 Subject: OT: Americans love their guns References: Message-ID: <8u32lvsff8k9krssnt1i9jp5plncrusr18@4ax.com> Richard Wesley wrote: > US murders with firearms were 8,259 in 1999, ranked #4 in the world. Indeed, even taking all firearm murders out of the total "number of murders" from that same page would change the US from the sixth most murderous country to the eighth; clearly the US is "just a bunch of violent nuts" in any case. It seems obvious to me that eliminating guns in the US would not eliminate the murders, and I would guess that at least some of the "murders with guns" would occur with some other implement were there no guns to be had. Sure, some murders would not be committed, but zoinks if the US were to still be in eighth place without guns being available?!? What would the reason be then? -tom! -- There's really no reason to send a copy of your followup to my email address, so please don't. From skip at pobox.com Sun Aug 10 21:26:02 2003 From: skip at pobox.com (Skip Montanaro) Date: Sun, 10 Aug 2003 20:26:02 -0500 Subject: python spam filter: random words? In-Reply-To: References: Message-ID: <16182.61610.587354.166572@montanaro.dyndns.org> revyakin> I know fighting spam is like fighting global worming, but revyakin> still.. 50% of spam I get these days contains a random revyakin> combination of letters at the end of the subject line. Has revyakin> anyone tried using that feature in antispam filters? See my .sig. -- Skip Montanaro Got gigs? http://www.musi-cal.com/ Got spam? http://spambayes.sf.net/ From pinard at iro.umontreal.ca Thu Aug 21 07:49:04 2003 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois_Pinard?=) Date: 21 Aug 2003 07:49:04 -0400 Subject: open.read In-Reply-To: References: Message-ID: [Alex Martelli] > David Bear wrote: > > I was in a hurry to do something and I did > > stuff = open("filename", "r").read() > > then I realized, "hey I didn't close the file". > > so python close it automagically? > It's very common use in classic Python, and sometimes handy for > interactive or near-one-liner use, but in any "serious" program explicitly > closing the file just as soon as you're done with it is beter than relying > on the interpreter closing it for you In more recent versions of Python, the `open' built in function has been replaced by the `file' built in constructor, and `open' has been made an alias for `file', so the above may more adequately be written: stuff = file("filename", "r").read() The file object created by the `file' constructor has its own destructor, which closes the file automatically if not done already. Using `file' is Pythonesque. For simple usages like the one above, you can safely rely on Python for destroying the file object, even in extra-serious programs :-). "Better" is a question of opinion, but in the case here, it seems to me that cluttering your code with an assignment, only meant for an explicit close, does not buy you legibility, and moreover, your assignment will get your closed file object uselessly hanging around. Best is exactly what you did. (I would have not used the `, "r"' part in this case.) > it will make your code more usable in Jython, This is likely the only real advantage of cluttering your code, when you know or bet that you are going to use Jython one of these days. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From mhammond at skippinet.com.au Sun Aug 10 19:00:02 2003 From: mhammond at skippinet.com.au (Mark Hammond) Date: Mon, 11 Aug 2003 09:00:02 +1000 Subject: win32, COM, and Solidworks (again) - Still Trying In-Reply-To: References: Message-ID: Markus Wankus wrote: > I realize this is nothing to do with win32all - it is Solidworks. Is > there a way I can tell them about this problem and possibly get them to > fix it? What have they not done in their C++ code that is making their > implementation of COM so stupid? You could ask them to implement the type info interfaces for their objects. > If there was a away I could make my own Dispatch class that forced this > re- instantiation I would be happy, but I can't see any way to figure > out what gencache class I need for a given object at runtime. Yes, this is the rub. Mark. From mis6 at pitt.edu Mon Aug 25 03:37:58 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 25 Aug 2003 00:37:58 -0700 Subject: macro FAQ References: <2259b0e2.0308240103.3966476b@posting.google.com> <87znhzi4k4.fsf@pobox.com> Message-ID: <2259b0e2.0308242337.7a7de63a@posting.google.com> jjl at pobox.com (John J. Lee) wrote in message news:<87znhzi4k4.fsf at pobox.com>... > Jacek Generowicz writes: > Well, as has been repeatedly argued, that's just the point: people > *don't* do that over and over again. Who uses these 'faked-up > macros'? A few people who like messing around with metaclasses for > fun (note Michele's warning about 'EXPERIMENTAL' and 'proof of > concept'). If it's made easier, relatively sane people might do it > too, and then we'll all suffer ;-) I wholeheartly agree. I DO NOT use macros, I wrote that module as a reply to a thread asking about macros. I wanted to see by myself how difficult it was to implement them. The answer is: EXTREMELY difficult, if you want a RELIABLE implementation. My implementation is very poor man with no error checking at all, working only in simple cases, but still it is not trivial. I am not convinced of the advantages of having macros in Python, whereas I am convinced of the disadvantages. So, I am for the status quo. Michele Simionato, Ph. D. MicheleSimionato at libero.it http://www.phyast.pitt.edu/~micheles --- Currently looking for a job --- From bokr at oz.net Wed Aug 6 22:35:44 2003 From: bokr at oz.net (Bengt Richter) Date: 7 Aug 2003 02:35:44 GMT Subject: Match beginning of two strings References: Message-ID: On Mon, 04 Aug 2003 18:53:27 -0400, Ravi wrote: >Ravi wrote: >> Hi, >> >> I have about 200GB of data that I need to go through and extract the >> common first part of a line. Something like this. >> >> >>>a = "abcdefghijklmnopqrstuvwxyz" >> >>>b = "abcdefghijklmnopBHLHT" >> >>>c = extract(a,b) >> >>>print c >> "abcdefghijklmnop" >> >> Here I want to extract the common string "abcdefghijklmnop". Basically I >> need a fast way to do that for any two given strings. For my situation, >> the common string will always be at the beginning of both strings. I can >> use regular expressions to do this, but from what I understand there is >> a lot of overhead. New data is being generated at the rate of about 1GB >> per hour, so this needs to be reasonably fast while leaving CPU time for >> other processes. >> >> Thanks >> Ravi >> > >I really appreciate all your help, Alex, Jim, Jeff, Andrew, John, Richie >and Bengt. However I have this problem taken care of now. Took around 6 >hours to run on a P4 2.8Ghz 1.0GB DDR (I suspect I/O limitations). As >for the data, if you want to know about it just for the sake of an >optimized algorithm, there are no Null (\0) characters in the strings >(actually they're Base64), and I've included a typical pair of strings. >The version I used was Andrew's. > >Someone suggested that this would be better done in larger sets than >just pairs. That's not suitable because of the structure of the data, >two strings might be highly correlated, but are probably quite different >from another pair of strings. Perhaps more significantly, correlation in >sets of greater than two has no physical significance to the experiment. > >I grabbed this from a typical data file. So I would want to be >extracting 'A832nv81a' >" >A832nv81a81nW103v9c24jgpy92T >A832nv81aTyqiep4v9c324jgpy92T >" I still don't understand your use case ;-) 1) Are you periodically batch processing to look for near-pairs in a 200GB unsorted list of strings? Are they just in a huge unsorted ascii file with line feeds delimiting? or 1a) Does someone send you a single string in a message every now and then (how often?) and ask you to find the closest match in the data base? I.e., 200GB at 30 bytes/string would be 6.67 billion strings. Which you say you now crunch in ~6hrs? You don't do that amount of crunching just for one match request, do you? 1b) If you get a lot of "match requests," wouldn't you gain a lot by at least partially ordering the incoming streams into separate buckets? E.g., the simplest thing would be to have 64 files corresponding to the first character, or even 64*64 files for the first two. Then have 64*64 file buffers (not open files) of say 1000 strings each, which would be 64*64*1000*30 or call it 32k/file buffer -> 64*64*32*1024/(1024*1024) ->128 megabytes of buffers and on the average you'd expect 1GB/hr to fill a buffer of 32k about (1e9/3600)/(32*1024) -> 8.477 times/second. It should be reasonable to open a file for append and write 32k and close it that often, IWT. Whateve box writes the 200GB data now could either do the partitioning itself or send it by gigabit ethernet to a dedicated box for that, IWT. Or you could distribute the load by patitioning the ethernet destinations per the leading n bits and let 2**n boxes maybe do even more ordering on the fly. Even without distributing the load, this could give you 200GB/4096 (if evenly distributed!!) or only '%e'%(200e9/4096) ->4.882813e+007 or less than 50MB to read off disk and search to make a probe with a single string. If you sorted when you probed and wrote back the sorted data with an indication that it was sorted, further probes to that same partition could go a lot faster. 2) Why do the string lengths vary if they are samples from some process? Are they effectively just right-stripped from some fixed length, which would be a guaranteed max length? 2a) what are the max and min lengths? 3) what is the distribution of leading characters as they come from the source? 3a) E.g., is the first character uniformly distributed within its possible Base64 codes? 3b) Are they uncorrelated timewise? Or e.g. do they arrive in clumps of <<64 possibilities for a time? 3c) Are the individual strings' characters randomly distributed and uncorrelated within the string? 3d) You say 9000GB compresses to 700GB. That suggests a lot of correlation and/or uneven distributions. Is there a fixed dictionary you could use to repack the strings bit-wise with huffman and/or rle compression? 3d1) What is the significance of the Base64 character boundaries? I.e., would a common prefix of 8-bit bytes representing sequentially compressed string be good enough, even if the first non- matching byte contained some bits that did match and would have been included in base64? 3d2) Note that compressing during partitioned 4096-bucket storage could save a lot of space as well as speed up matching. 4) 1GB/hr translates to about 10k strings like the your example per second. 4a) Are they just logged sequentially to a 200GB data store? (cf. 1b) 4b==2a) Is there a max and/or min length to these strings? (the above are 29 & 30 chars). 4c) You say they are base 64. That means binary would make (6/8)*200gb = 150GB, and the strings (6/8)*30 ~ 22.5 or say 24 for a nice multiple of 8, even without compression. Just some thoughts. Might want to check my arithmetic ;-) > >Thanks for your help everyone, coming from a Perl (It's a four letter >word to me :) world, I'm very impressed by how helpful all of you are. > Some newsgroups are like that. In the past I spent a fair amount of time on the Borland Delphi n.g., and that was mostly very friendly and helpful too. I think that's just the way people are unless some stupidities get in the way. Renaissance yes! Armageddon no! Regards, Bengt Richter From mis6 at pitt.edu Thu Aug 14 08:00:27 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 14 Aug 2003 05:00:27 -0700 Subject: CLI+GUI References: <2259b0e2.0308080948.5a95e383@posting.google.com> <2259b0e2.0308121335.7f1ad18a@posting.google.com> Message-ID: <2259b0e2.0308140400.218370b5@posting.google.com> danbmil99 at yahoo.com (dan) wrote in message news:... > davesum99 at yahoo.com (smarter_than_you) wrote in message > > > Also note that there are at least three ways to get this behavior: > > > > _tkinter.dooneevent(TCL_DONT_WAIT) > > Frame.update() > > Tkinter.dooneevent(0) #this is new to me! You found a third way to > > call it > > > that would be: > > root.tk.dooneevent() > > but anyway -- > > in my experiments, this last way (Michelle's way) has very bad timing, > if you care about that sort of thing. Both the _tkinter call and > update() seem to be more reactive. .update() seems to be working (even of Win98) and the name is self-documenting, so at the moment it is my first candidate. BTW, notice the spelling : Michele with one "l", italian male name, as opposed to Michelle, with two "l", french female name. Thanks, for your help, Michele From jjl at pobox.com Sun Aug 24 08:26:53 2003 From: jjl at pobox.com (John J. Lee) Date: 24 Aug 2003 13:26:53 +0100 Subject: large-scale app development in python? References: <7xlltkxrcv.fsf@ruckus.brouhaha.com> <87smnsx7y6.fsf@pobox.com> <7xznhzgbuy.fsf@ruckus.brouhaha.com> Message-ID: <87d6evjl6a.fsf@pobox.com> Paul Rubin writes: > jjl at pobox.com (John J. Lee) writes: > > I've never checked: how many LOC is Zope? > > I don't remember but the answer has been posted here before. > > > Of course, one has to remember that lower LOC (by a multiple of 5 or > > so, according to some experienced C++, Java and Python developers > > here) is one of the very reasons that people choose Python in the > > first place, so some sort of correction has to be applied, or a more > > sophisticated metric used. > > No, LOC is not perfect but IMO it's about as indicative as most > anything else I can think of. No correction factor should be applied. Well, patently, whether that's true or not ("No correction factor should be applied.") depends ENTIRELY on the question at hand! So, we're in agreement, I'm sure -- we're just asking different questions -- but just to state the obvious: If the question is "what problems does development of a program with x many LOC cause", one should not apply any correction factor, because one suspects the problems are more directly dependent on LOC than on language choice per se. That's to say, to a poor first approximation, choice of language determines the required resources only through the mechanism of determining the LOC required. If the question is "what resources are required to develop a program that solves (a problem whose size, when expressed in Java, is x LOC)" -- which is the question relevant to the OP's question -- and one is using LOC as a measure of cost, then one should apply a correction factor. Hmm, you know you're writing bad English when you have to parenthesize to indicate precedence :-/ The situation is no different, of course, in the case where the project goals may grow or shrink depending on how programmer-efficient the language is. > It could be that a 100 KLOC Python program does more stuff than a > comparably sized Java program, but that doesn't mean the Python > program is bigger. Sure, in terms of the problems it causes. Equally clearly, in terms of the problems it *solves*, the Python program is "bigger" (in that particular sense -- let's not get into an empty debate over definitions). > I think Zope is in the 100 KLOC range within a factor of some small > integer. A large application these days may mean 10 MLOC or more. You're right. But of course, the *reason* we're all worried about large programs is that we want to know "how do I solve problem x with minimum use of resources", or "given these resources, what problems can I solve". We're not trying to write big programs, we're trying to solve big problems. John From vze4rx4y at verizon.net Sun Aug 17 18:39:22 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Sun, 17 Aug 2003 22:39:22 GMT Subject: Py2.3: Feedback on Sets (fwd) References: <2e363c08.0308161306.47a010ae@posting.google.com> Message-ID: [Alex Martelli] > |IMHO, one 'real' issue with this function is that it behaves strangely > |(to me) when iterable has duplicated elements > | data = list(iterable) --> data = Set(iterable) [David Mertz] > Yeah :-). Which points out that I should have actually READ Raymond's > function, rather than just cut-and-paste it. This seems to point out > that even the Python developers are able to make mistakes in > implementing powerset(). Which again suggests a module function > (implemented correctly) is worth having. It wasn't a mistake. I do prefer Alex's improvement because it has a weaker precondition, but the basic code and generation method was dead-on. The real issue with adding a module function or Set method for powerset is the lack of compelling use cases; without those, it is simply a cute example for the docs or an ASPN recipe. Also, if Tim were to chime-in, I think he would abstract the problem and say that the algorithm falls in the domain of combinatorics (for which he has written a module) and that powersets are just a specific case of transforming a collection of items into a collection of all possible sub-collections. Raymond Hettinger From anton at vredegoor.doge.nl Sun Aug 31 18:19:16 2003 From: anton at vredegoor.doge.nl (Anton Vredegoor) Date: Mon, 01 Sep 2003 00:19:16 +0200 Subject: Win32 documentation in CHM? References: Message-ID: "Tim Peters" wrote: >You cannot have used a properly constructed .chm file and seriously question >whether it's more searchable. Of course it is, including seemingly >instantaneous Boolean, proximity, wildcard, and similarity searches, across >the entire doc set with one query. I don't know of any way to search thru >more than a thousand .html files that's even arguably comparable; e.g., grep >is a slow & painful joke in comparison. OTOH this seems like a job for a Python script. It should be possible to do a search that locates all positions for all words in all files (maybe the files can be in a zipped archive) and store the result in a pickle. Probably what's needed is a dictionary and a list of file paths: the file path list( f.e. generated by a recursive path walk): [file1,file2, ....] the dictionary: {"python" : [(1,3),(1,18),(26,5)], "dictionary": [(3,5),...]} Where the first tuple (1,3) means the word "python" appears in the file that's in the file path list at index 1, at position 3 in the file. Next time open the pickle and do not repeat the whole search. Two problems: - what should the -tkinter?- user interface look like? - how to do an ascii-like search in a set of html-files (necessary for displaying the found lines in a tkinter widget) and still return a link for webbrowser.open("filename") with an offset to the found word position after the item is clicked, selected or whatever. One brainstorming idea: - maybe a split window with a tree-like structure in the left (the tree is pruned for the search term) and in the right a list of clickable lines from the selected files in the tree. Anton From tim.one at comcast.net Sun Aug 17 23:01:39 2003 From: tim.one at comcast.net (Tim Peters) Date: Sun, 17 Aug 2003 23:01:39 -0400 Subject: Py2.3: Feedback on Sets In-Reply-To: <001701c3652c$2c621e20$e841fea9@oemcomputer> Message-ID: [Beni Cherniavsky] >> `isdisjoint` sounds like a good idea since it can be implemented >> more effeciently than ``not a & b``. [Raymond Hettinger] > True enough. It is easy to putogether an early-out algorithm using > itertools. So, it can be done a C speed. The question is whether > there are sufficient use cases to warrant expanding an already fat API. Early-out algorithms consume time to determine when the early-out condition obtains, and so can be a net loss (via consuming more time testing for early-out than is saved by getting out early). See the long comment block before _siftup in heapq.py for a classic case where early-out usually loses big. For isdisjoint() it's muddier (depends on whether your data is such that most sets fed to it are or aren't disjoint; if they're usually disjoint, code testing for early-out is a waste of time). ... >>> * Do you care that sets can only contain hashable elements? >> No more than I care for dicts containing only hashable keys. How >> else could you define it? > The hard way. Keep a separate ordered list for elements that > define ordering operations but not a hash value. Insert and Search > using a binary search. > > Keep a third list for elements that only support equality comparision. > Use linear search for that one. > > This complicates the heck out of the code but would expand the range > of things storable in sets. The only real life use case I can think > of is using a third party package that supplied objects without a hash > code. Part of Zope's ZODB (persistent object-oriented database) is an elaborate BTree package, supplying many flavors of containers built on more-or-less (depending on how much you squint ) classical disk-based B+ trees. Sets of C integers and sets of Python objects are some of the container types supported. BTrees require a total ordering among keys, but don't use hash codes. Most operations on B+-tree based sets take time logarithmic in the number of elements; this includes insertion and deletion, where using a straight sorted list instead would take linear time (much worse). There are effective ways to use hashing schemes for disk-based containers too. The strongest reason for using ordered B+ trees in ZODB is that searches in database apps very often want to find everything in a *range* of key values, and traversing a B+ tree in sorted order is trivial (it's just a left-to-right traversal over a linked list of the leaf buckets; a pair of log-time searches is done first to find the range's endpoints). So, e.g., where a Python dict has .iterkeys() a ZODB BTree has .iterkeys(min=None, max=None, excludemin=False, excludemax=False) A prime use case for an ordered implementation of sets is that adaptive strategies such as those used in 2.3's list.sort() can greatly speed union and intersection operations on sets of non-random data. For example, what's the intersection of {1, 2, 3, ..., 1000000} and {2000000, 2000001, 2000002, ..., 3000000} ? If sets are stored in sorted order, a quite general set intersection algorithm can easily deduce that the intersection is empty after just a few comparisons. Indeed, the inspiration for 2.3's sometimes-amazing list.sort() came from reading "Adaptive Set Intersections, Unions, and Differences" (2000) Erik D. Demaine, Alejandro L?pez-Ortiz, J. Ian Munro (easy to find via Google). BTW, there's an extensive discussion of ways to adaptively minimize the cost of early-out gimmicks when they're not paying in Python's Objects/listsort.txt. From sross at connectmail.carleton.ca Fri Aug 29 20:15:05 2003 From: sross at connectmail.carleton.ca (Sean Ross) Date: Fri, 29 Aug 2003 20:15:05 -0400 Subject: crazy programming language thoughts References: <3rv3b.6241$yg.2305230@news4.srv.hcvlny.cv.net> <35y3b.3262$_F1.545316@news20.bellglobal.com> Message-ID: "Ryan Lowe" wrote in message news:ClR3b.22734$yg.8965558 at news4.srv.hcvlny.cv.net... [snip] > im not trying to change python. even a small change is a tough sell with > this crowd ;-) i guess i should have labeled this off-topic. is there a > forum that might be more appropriate? I'm all for this kind of discussion. But, as to a more appropriate forum, I think comp.lang.misc would be the place for this type of thing. [snip] > i see no need to english-ify selecting a range of things from a > list. id do something like: > > get words in paragraphs[2 : 4] > I'd do something like paragraphs[2 to 4].words myself. [snip] > SPARK, huh. never heard of it, ill check it out. thanks Then you missed my earlier post to this thread: http://tinyurl.com/lnts There is code at my site, listed in that posting, that used SPARK to make a toy language based on the Python 1.5.2 grammar. It's not great, but you may find it instructive (atleast insofar as what things not to do :) You can prototype your language, work out the kinks, then consider whether to reimplement in C, or what ever. Good luck, and have fun. Sean From essai1 at mci.local Thu Aug 28 16:49:24 2003 From: essai1 at mci.local (News M Claveau /Hamster-P) Date: Thu, 28 Aug 2003 22:49:24 +0200 Subject: NetServerDiskEnum in win32net References: Message-ID: Hi ! I try, and i have same result. But, i have no read doc... -- Michel Claveau From pedro.werneck at bol.com.br Sat Aug 23 21:14:14 2003 From: pedro.werneck at bol.com.br (Pedro Werneck) Date: Sun, 24 Aug 2003 01:14:14 +0000 Subject: Fw: Re: Python is darn fast (was: How fast is Python) Message-ID: <20030824011414.6f05a4fb.pedro.werneck@bol.com.br> On 23 Aug 2003 08:37:44 -0700 mis6 at pitt.edu (Michele Simionato) wrote: > I posted this few weeks ago (remember the C Sharp thread?) but it went > unnoticed on the large mass of posts, so let me retry. Here I get > Python+ Psyco twice as fast as optimized C, so I would like to now if > something is wrong on my old laptop and if anybody can reproduce my > results. Here are I my numbers for calling the error function a > million times(Python 2.3, Psyco 1.0, Red Hat Linux 7.3, Pentium II 366 > MHz): My timings on a K6-2 500 MHZ (450 overcloked to 500), Slackware 8.1. I increased the loop counter by 10: gcc-2.95.3: $ gcc -O3 -lm erf.c && time ./a.out real 0m6.807s user 0m6.650s sys 0m0.010s Is not much different from gcc-3.3.1: $ gcc-3 -O3 -lm erf.c && time ./a.out real 0m6.677s user 0m6.460s sys 0m0.010s And even with gcc-3.3.1 and cpu flags: $ gcc-3 -O3 -march=k6-2 -lm erf.c && time ./a.out real 0m6.411s user 0m6.400s sys 0m0.000s But with the suggested -ffast-math flag: $ gcc-3 -O3 -march=k6-2 -mcpu=k6-2 -ffast-math -lm erf.c && time ./a.out real 0m2.598s user 0m2.590s sys 0m0.010s And finally, with Python 2.3 + Psyco 1.1.1: $ time python2.3 erf.py real 0m4.900s user 0m4.470s sys 0m0.080s Very surprising :) Pedro Werneck From mpeuser at web.de Sat Aug 16 14:35:19 2003 From: mpeuser at web.de (Michael Peuser) Date: Sat, 16 Aug 2003 20:35:19 +0200 Subject: How to terminate a TkinterApp correctly? References: <3F3DFCF4.5020109@aon.at> <3f3e37c6$0$19888$91cee783@newsreader01.highway.telekom.at> Message-ID: "John Roth" schrieb im Newsbeitrag news:vjsslisoeitsc9 at news.supernews.com... > > "Michael Peuser" wrote in message > news:bhlmgq$dqk$02$1 at news.t-online.com... > > > > ----- Original Message ----- > > From: "Gregor Lingl" > > Newsgroups: comp.lang.python > > Sent: Saturday, August 16, 2003 3:53 PM > > Subject: Re: How to terminate a TkinterApp correctly? > > > > .... > > > > > Thanks for your remarks and your example. The > > > following solution finally did it: > > > > > > def exit(): > > > global done > > > done = True # so the animation will terminate, but > > > # not immediately! The actual pass through > > > # the loop has to be finished. > > > print "done!" > > > import sys > > > # after_idle seems to be crucial! Waits for terminating > > > # the loop (which is in a callback function) > > > cv.after_idle(sys.exit, (0,)) > > > > > > Why don't you just return? The mainloop can handle everything!? > > Unfortunately, the combination of Windows 9x (including Me) > and Python 2.1 can't handle everything. It may also be broken > in 2.2 and later, but I quit trying after reaching my frustration > limit. If you exit with an exception, something doesn't clean up > properly, and you break the DOS box and eventually Windows > itself when you try to shut down. > > This problem doesn't exist in the Windows 2K (including XP) > code base, or other variants. > > I don't know that it's ever been solved, but considering that > Windows 9x is gradually going away, it's also not a real hot > priority. This was not my point I think.... I was not referring to tk/system mainloop but to your own loop you mentioned. This is where you set "done=1" for... The after_idle is confusing and probably not what you want. I have the impression that there is still some misunderstanding. It is absolutly fine to intercept the user click to the close box - there is no magic it and - as to my example - you can do what you want for hours after. Note: the "closing" process is stopped, when you use this WM-.... trick. (Because I was not *quite* sure about the internal states, I also recommende to use WM_SAVE_YOURSELF instead). But I think it is not worth all the work - and still unsafe! - to just call sys.exit() !!! Kindly Michasel P > John Roth > > > From bdelmee at advalvas.REMOVEME.be Sat Aug 30 18:47:36 2003 From: bdelmee at advalvas.REMOVEME.be (=?ISO-8859-1?Q?Bernard_Delm=E9e?=) Date: Sun, 31 Aug 2003 00:47:36 +0200 Subject: Win32 documentation in CHM? In-Reply-To: References: Message-ID: <3f51294a$0$1123$6c56d894@feed0.news.be.easynet.net> > I've certainly found it so in the ActiveState distribution, which packages > the Python docs, plus selected third-party docs -- win32all, Dive Into > Python -- into a unified HTML Help package. Very, very handy to be able to > quickly look things up in a common index, or search across the whole lot. > > (Still waiting for a 2.3 ActiveState distro, though...) The pythlp.py script, available at: http://www.orgmf.com.ar/condor/pytstuff.html still seems to work fine for python 2.3 It'll create an HTM Help project for you, incorporating all std docs, which you then need to compile to CHM using the HTML Help Workshop: http://go.microsoft.com/fwlink/?LinkId=14188 Cheers, Bernard. From shane at zope.com Thu Aug 21 14:32:00 2003 From: shane at zope.com (Shane Hathaway) Date: Thu, 21 Aug 2003 14:32:00 -0400 Subject: What's TOTALLY COMPELLING about Ruby over Python? In-Reply-To: <3F44E347.6789EB86@engcorp.com> References: <240b1020.0308201722.d1b991c@posting.google.com> <3F44E347.6789EB86@engcorp.com> Message-ID: <3F451020.5020303@zope.com> Peter Hansen wrote: > Jeffrey P Shell wrote: > > [an excellent, lengthy article contrasting Python and Ruby] > > Article saved permanently. This is the only good thing to > come out of this thread so far. Thanks Jeffrey! I agree. It would have taken weeks for me to figure out all of that on my own. Get that great article posted in your weblog. I'll note that "foo.sort" vs. "foo.sort!" issue is a very big deal for some people. Being able to reliably distinguish between mutating and non-mutating operations creates opportunities for transparent parallelization. If you have some time, check out Kenton "Temporal" Varda's comment: http://slashdot.org/comments.pl?sid=75478&cid=6749469 and the programming language he's working on: http://www.evlan.org/concepts.php Shane From tzot at sil-tec.gr Fri Aug 29 08:35:58 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Fri, 29 Aug 2003 15:35:58 +0300 Subject: appoximate string matching library - any interest? References: <4ZGcnR__JutkFdOiXTWJhQ@giganews.com> Message-ID: On Thu, 28 Aug 2003 18:57:59 -0400, rumours say that Istvan Albert might have written: >Hi all, > >I'm working on a project that needs approximate string matching >such as the String::Aprox module in perl: [snip] >I was unable to find a similar implementation in python right >away so I tried wrapping the perl module's underlying C library >into python calls. You obviously did not fall upon difflib.py, which is in the standard library. I believe the get_close_matches will be very useful to you. -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From andreas.kuntzagk at mdc-berlin.de Thu Aug 21 10:55:00 2003 From: andreas.kuntzagk at mdc-berlin.de (Andreas Kuntzagk) Date: Thu, 21 Aug 2003 16:55:00 +0200 Subject: Problems with python-list? References: <477762c2.0308201832.327cf5bc@posting.google.com> <7h31xvf43at.fsf@pc150.maths.bris.ac.uk> <7h3r83f2ogv.fsf@pc150.maths.bris.ac.uk> Message-ID: On Thu, 21 Aug 2003 12:21:03 +0000, Michael Hudson wrote: > Michael Hudson writes: > >> dave at pythonapocrypha.com (Dave Brueck) writes: >> > $ telnet mail.python.org 25 > Trying 12.155.117.29... > Connected to mail.python.org. > Escape character is '^]'. > 421 mail.python.org: Too many concurrent SMTP connections; please try > again later. > > I bet this is the fault of the same virus that's currently filling up my > inbox with bounces. Is this the same box which handles the registration for the PyPiPage? Because I was getting an error like this when I tried to register. Andreas From Henrik.Weber at sdm.de Tue Aug 5 08:41:12 2003 From: Henrik.Weber at sdm.de (Henrik Weber) Date: 5 Aug 2003 05:41:12 -0700 Subject: pychecking current source file in pythonwin Message-ID: <44254d3d.0308050441.3ae97677@posting.google.com> Hi. I have tried to add pychecker as an extension to pythonwin. Now I can have pychecker check the source file that is currently open in the editor with a single keypress. If someone is interested, here is how to do it: Create an empty file in your \Lib\site-packages\Pythonwin\pywin directory. Give it a name with .cfg as extension. Into this file put the following lines (replace with the path to your python installation): [General] Based On = Default [Keys:Editor] Shift+Ctrl+v = checksource [Extensions] def checksource(editor_window, event): import pywin.framework.scriptutils import os import re filename = pywin.framework.scriptutils.GetActiveFileName() messages = os.popen(r"\Scripts\pychecker.bat %s" % filename) for message in messages.xreadlines(): print re.sub(r"(.*):(\d+):(.*)", r'File "\1", line \2, \3', message.strip()) messages.close() Start pythonwin. In the View menu select Options. Go to the Editor tab. In the dropdown box select the name of your configuration file. Click OK. Now open a Python source file and press Shift+Ctrl+v. The output of the operation can be found on the interactive screen. The script formats the output so a double click on a pychecker message will jump to the corresponding line in the editor. The script should write something like "pychecker is checking your source" into the status bar, but I haven't found out how to do that yet. Maybe some helpful soul can help out with that. From soerenjohansen171 at hotmail.com Tue Aug 5 08:24:53 2003 From: soerenjohansen171 at hotmail.com (Søren Johansen) Date: Tue, 5 Aug 2003 14:24:53 +0200 Subject: PyRun_SimpleString, PyRun_File Message-ID: <3f2fa1ed$0$5133$edfadb0f@dread11.news.tele.dk> Hi, having had a number of problems with PyRun_File in my application embedding Python, I decided to load scripts into memory myself and execute them with PyRun_(Simple)String. This works fine and dandy except for when scripts reach a certain size. Around the 28000'th byte, it seems to break up the script, resulting in random errors caused by whatever is on that line. Is there some known limitation to PyRun_String buffersize that is not present in PyRun_File - with which it used to work - and a way to overcome it? Thank you, S?ren From mschneider.pad at t-online.de Fri Aug 15 16:51:25 2003 From: mschneider.pad at t-online.de (Marcus Schneider) Date: 15 Aug 2003 13:51:25 -0700 Subject: Modifying TKinter widgets defined in Modules Message-ID: <3f443b52.0308151251.7e6bbaaf@posting.google.com> Sorry if this is an extremely stupid question: I produced some Python modules with TKinter stuff and now I want to use that from my main program. The windows have wuite some user interaction. It's easy to bring them to the screen, but how do I make the communication (i.e. variables) between the main and the modules happen? Currently I call a function from the main and pass all variables in the function call, but with more then 25 variables this looks odd. And now I have to change variables in the main from the module and that doesn work at all, does it? Or can I access widget definitions from the main?? What is the usual, elegant way to handle that? Thanks for any hint ;) From mpeuser at web.de Sun Aug 17 06:59:09 2003 From: mpeuser at web.de (Michael Peuser) Date: Sun, 17 Aug 2003 12:59:09 +0200 Subject: simple text parser? References: Message-ID: "Brandon J. Van Every" schrieb im Newsbeitrag news:bhnml0$1a25t$1 at ID-203719.news.uni-berlin.de... > Michael Peuser wrote: > > This is a little bit confusing. > > (1) Do you want to dump "internal" data? Of course you cannnot expect > > those data to be portabel between Python and C#!!! > > I don't want portability between Python and C#. They are completely > separate projects. Then do: import cPickle # ------ f=open("test","wb") cPickle.dump(whatever,f,1) cPickle.dump(morewhatever,f,1) # ..... f.close() #.... f=open ("test","rb") whatever=cPickle.load(f) morewhatever=cPickle.load(f) # ...... f.close() From jjl at pobox.com Wed Aug 20 17:47:47 2003 From: jjl at pobox.com (John J. Lee) Date: 20 Aug 2003 22:47:47 +0100 Subject: ClientCookie bug (followup) References: <87fzk4sav2.fsf@pobox.com> <87znibzrnx.fsf@pobox.com> <87oeypdh92.fsf@pobox.com> <87k79a25pi.fsf@pobox.com> Message-ID: <87isos0zng.fsf@pobox.com> cartermark46 at ukmail.com (Mark Carter) writes: > > No really, I wasn't joking: you *never* need to use add_cookie_header > > / extract_cookies if you're using urllib2 (at least, I can't think of > > any possible reason to do so). It can only break things. > > I must admit that I don't really know what I am doing. How would you > simplify the following code: [...] It doesn't tend to encourage people to help you if you don't even *try* to apply their advice, and just expect them to do all your work for you. Read that paragraph you quoted (and the rest I posted in that message and previously), try doing what it suggests, then come back here if you need to. John From pinard at iro.umontreal.ca Fri Aug 8 08:41:15 2003 From: pinard at iro.umontreal.ca (Francois Pinard) Date: 08 Aug 2003 08:41:15 -0400 Subject: passing multiple strings to string.find() In-Reply-To: References: <3F331A9B.9020907@vt.edu> Message-ID: [Bengt Richter] > If some search strings have a common prefix, you'll have to put the > longest first in the regex, since re grabs the first match it sees. Hi, gang. I recently wanted to match among a list of keywords, repeatedly, and wanted to help the Python `re' module a bit, speed-wise. I wrote the following helper function (I stole the idea of this from Markku Rossi's `enscript'): def build_regexp(tokens): # Build an optimised regular expression able to recognise all TOKENS. tokens_by_first = {} empty = False for token in tokens: if token == '': empty = True else: sequence = tokens_by_first.get(token[0]) if sequence is None: sequence = tokens_by_first[token[0]] = [] sequence.append(token[1:]) if not tokens_by_first: return '' fragments = [re.escape(letter) + build_regexp(tokens) for letter, tokens in tokens_by_first.iteritems()] if empty: fragments.append('') if len(fragments) == 1: return fragments[0] return '(?:%s)' % '|'.join(fragments) Given the above, build_regexp(['this', 'that', 'the-other']) yields the string 'th(?:is|at|e\\-other)', which one may choose to `re.compile' before use. Here is an real pattern produced using the above device, meant for a LilyPond note in English notation: "((?:a(?:s(?:harp(?:sharp|)|s|)|f(?:lat(?:flat|)|f|)|)|c(?:s(?:harp(?:sharp|)|s|)|f(?:lat(?:flat|)|f|)|)|b(?:s(?:harp(?:sharp|)|s|)|f(?:lat(?:flat|)|f|)|)|e(?:s(?:harp(?:sharp|)|s|)|f(?:lat(?:flat|)|f|)|)|d(?:s(?:harp(?:sharp|)|s|)|f(?:lat(?:flat|)|f|)|)|g(?:s(?:harp(?:sharp|)|s|)|f(?:lat(?:flat|)|f|)|)|f(?:s(?:harp(?:sharp|)|s|)|f(?:lat(?:flat|)|f|)|)))(,+|'*)([!?]?)((?:64|32|16|8|4|2|1|)\\.*)" You agree that this would be fairly tedious to type in with an editor! :-) -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From logiplex at qwest.net Mon Aug 18 19:10:58 2003 From: logiplex at qwest.net (Cliff Wells) Date: Mon, 18 Aug 2003 16:10:58 -0700 Subject: What's better about Ruby than Python? In-Reply-To: References: Message-ID: <1061248257.10907.88.camel@software1.logiplex.internal> On Mon, 2003-08-18 at 14:48, sismex01 at hebmex.com wrote: > [Aahz] > > Oh, come on, Brandon is *much* less of a troll than T*m*t*y > > R*e. Unlike the R**bot, we do some interesting topics out of > > Brandon, they're just written with such antagonism that I'd be > > hard-pressed to top them. > > > > Ahh, yes, Mr. Rue... It's been a while since he's dropped by > for a visit :-) > > I think like you Aahz, that people's dumping way to harsh-like > on Brandon. And it's strange to me, because normally people's > much more polite here than elsewhere; I wonder what's squishing > everyone's balls so tight to make them so. As annoying as Timothy is, his annoying qualities can easily be attributed to a less-than-agile mind. His arrogance rings of madness, which should be pitied, not despised. Brandon, on the other hand, is annoying and arrogant without the saving grace of being either stupid or insane. Regards, -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 (800) 735-0555 From lupe at netvisao.pt Mon Aug 18 07:49:05 2003 From: lupe at netvisao.pt (Lupe) Date: Mon, 18 Aug 2003 12:49:05 +0100 Subject: advice choosing IDE Message-ID: I'm convinced to try Python! I've read many posts, and although I recently bought a book on C to start learning it, I'd like to give Python a good chance. What IDE would you recommend for someone who needs easiness of use with a background of Pascal and VB for MS Office? I've definitely changed to Linux now and I would like a free IDE either for procedural or object oriented programming. I'd need an easy help on syntax, if possible with examples and a front end debugger with easy trace, breakpoints and watches. Programming is not my profession, just a hobby! With all this in mind what would be your recommendation? I've read so many posts on the subject that I'm confused. For a beginner, I just need one solution... Lupe From aleax at aleax.it Wed Aug 20 13:04:13 2003 From: aleax at aleax.it (Alex Martelli) Date: Wed, 20 Aug 2003 17:04:13 GMT Subject: python quickie : retrace function steps? References: <5f5c82ec.0308200820.51c8e33c@posting.google.com> Message-ID: Matt Smith wrote: > hi all, > > If I was to make a function call another function, and from that > function, call another function (so that now I was in a 3rd function) > something like this: > > (function 1) > |________(function 2) > |________(function 3) > > Is there away I can print out the path my Program had taken (i want to > do this as part of my error checking, so a user would always know the > path my program took)? Yes, the _getframe function of module sys exists essentially for this purpose. The leading underscore is meant to indicate you should not use it for "production" purposes, but debugging uses are just fine. > i.e. printted output of error would be: > > error with function 3 > function 3 called from function 2 > function 2 called from function 1 Note, in particular, that the tracebacks that Python normally produces if you raise exceptions have much the same information, just with many more details (lines-within-functions, not just function names). You might prefer to work with the traceback objects rather than (essentially) rebuild them yourself with sys._getframe(N). > In perl there is a function called CALLER, which I have used to the > same effect, i was wondering if python had something similar for this? Yes, you can see sys._getframe(N) as an equivalent to &caller($N). sys._getframe returns a frame object, and the x.f_code.co_name attribute (calling x the object in question) is the one you want. Alex From staschuk at telusplanet.net Wed Aug 27 17:08:16 2003 From: staschuk at telusplanet.net (Steven Taschuk) Date: Wed, 27 Aug 2003 15:08:16 -0600 Subject: how fast is Python? In-Reply-To: ; from adalke@mindspring.com on Wed, Aug 20, 2003 at 10:00:19PM +0000 References: Message-ID: <20030827150816.A470@tibia.amotlpaa.bogus> Quoth Andrew Dalke: > [...] (Though I know of at least one person who sent > in a patch to gcc to optimize poorly written in-house code. > Rather circuitous way to fix things, but it worked.) A bit off-topic perhaps, but I'd be interested in the details of this anecdote. -- Steven Taschuk o- @ staschuk at telusplanet.net 7O ) " ( From pkwan at advsofteng.com Fri Aug 1 12:12:09 2003 From: pkwan at advsofteng.com (Peter Kwan) Date: Sat, 2 Aug 2003 00:12:09 +0800 Subject: 'long int too large to convert to int' in 'garbage collection' ignored References: <00b001c3583b$799c3160$83706698@newlife> <16170.33368.723704.152956@montanaro.dyndns.org> Message-ID: <00e801c35847$a8d66110$83706698@newlife> Hi Skip, Although I know it can be suppressed, it could not very desirable for my case. First, I think if the code is not fixed, it will break in Python 2.4 anyway. In Python 2.4, the 0x80996633 will be considered as Long even if I do not have append an "L". So it will crash with 'long int too large to convert to int' in 'garbage collection' ignored, unless this is fixed. I am a developer for Python libraries. I would like to write some code that works in all common versions of Python and that is easy to use and works in most environments. The warning can only be suppressed using command line switches. It makes my library harder to use if you need to add certain switches in order to use it in some versions of Python. Also, in some environment, the command line switch may be hard to add - for example, when using Python in IIS or using mod_python, etc.. But if there is no better solution, I must live with the warning message for now, and hoping by Python 2.4, someone would have fixed that bug. Regards Peter Kwan ----- Original Message ----- From: "Skip Montanaro" To: "Peter Kwan" Cc: Sent: Friday, August 01, 2003 11:08 PM Subject: Re: 'long int too large to convert to int' in 'garbage collection' ignored > > Peter> FutureWarning: hex/oct constants > sys.maxint will return > Peter> positive values in Python 2.4 and up > > You can suppress this warning. I don't know the implications downstream > though. You should read through the 2.3-related docs. This page looks > particularly useful: > > http://www.python.org/doc/2.3/whatsnew/node22.html > > Skip > From danbmil99 at yahoo.com Wed Aug 13 22:40:11 2003 From: danbmil99 at yahoo.com (dan) Date: 13 Aug 2003 19:40:11 -0700 Subject: CLI+GUI References: <2259b0e2.0308080948.5a95e383@posting.google.com> <2259b0e2.0308121335.7f1ad18a@posting.google.com> Message-ID: davesum99 at yahoo.com (smarter_than_you) wrote in message > Also note that there are at least three ways to get this behavior: > > _tkinter.dooneevent(TCL_DONT_WAIT) > Frame.update() > Tkinter.dooneevent(0) #this is new to me! You found a third way to > call it > that would be: root.tk.dooneevent() but anyway -- in my experiments, this last way (Michelle's way) has very bad timing, if you care about that sort of thing. Both the _tkinter call and update() seem to be more reactive. From jack at performancedrivers.com Mon Aug 18 18:50:02 2003 From: jack at performancedrivers.com (Jack Diederich) Date: Mon, 18 Aug 2003 18:50:02 -0400 Subject: What's better about Ruby than Python? In-Reply-To: ; from vanevery@3DProgrammer.com on Mon, Aug 18, 2003 at 03:14:52PM -0700 References: <38ec68a6.0308172319.431a4fde@posting.google.com> Message-ID: <20030818185002.A2039@localhost.localdomain> On Mon, Aug 18, 2003 at 03:14:52PM -0700, Brandon J. Van Every wrote: > Lulu of the Lotus-Eaters wrote: > > The second surest sign that a post is a troll is if the author > > includes: > > > >>> This is not a troll. > > > > The first surest sign that a post is a troll is if the author is: > > > >> "Brandon J. Van Every" > > Man, it's clear that I've got an entire hate group around here to > exterminate! I wonder how long it's going to take? Maybe this is a > positive sign of Python's growth: it's got enough critical mass to attract > just about anybody, not just people who want to get things done. At any > rate, welcome to my killfile. Never blame on malice what can be explained by stupidity. I don't care if you write troll posts maliciously or not, I do care that you keep sending them. So how big is that RAID that holds your killfile? -jack From donn at u.washington.edu Wed Aug 13 13:13:53 2003 From: donn at u.washington.edu (Donn Cave) Date: Wed, 13 Aug 2003 10:13:53 -0700 Subject: Is Python your only programming language? References: Message-ID: In article , Tim Rowe wrote: [ ... re Python as the only language you need ] > Absolutely not. I don't believe any language could be, because every > task needs different compromises. Sure, within the domain of computer programming problems, no single language can adequately serve for everything. But that's a much broader range than most of us encompass, and I think it's really rather reasonable in principle for a single language to satisfy a single programmer's needs. Where "satisfy" is a function of how well the language works for his or her normal range of problems versus how easily another possibly better language can be brought on board. Excuse me for such an obvious observation, but it seems sort of evasive to turn the question into a matter of principle. For my purposes, there seem to be three programming language roles: a low level system interface language (C, for UNIX), an application language, and a high level system interface language (shell, for UNIX.) In practice, the application language is sometimes Python, more commonly C, and in my dreams it could be Haskell. Donn Cave, donn at u.washington.edu From jdhunter at ace.bsd.uchicago.edu Thu Aug 28 13:38:19 2003 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Thu, 28 Aug 2003 12:38:19 -0500 Subject: yawPyCrypto : encrypt file in blocks Message-ID: I am trying to use to encrypt some potentially large files, so I want to do it in blocks rather than as a single string. Below is the code I am using. When I run dec.finish(), I get the traceback Traceback (most recent call last): File "crblocks.py", line 37, in ? dec.finish() File "/usr/local/lib/python2.3/site-packages/yawPyCrypto/_CipherBase.py", line 239, in finish raise ValueError("Decryption stream ended too early.") ValueError: Decryption stream ended too early. and the source and decrypted differ (the decrypted one is a little smaller), though the apparently differ only at the end, because I can play the decrypted mp3 that I am using for the test file. Apparently, I am not handling the final bytes correctly. The file size are listed below the code. Any advice? Also, is this the best way to encrypt large files? Is there a preferred block size? Thanks, John Hunter from yawPyCrypto.Cipher import DecryptCipher, EncryptCipher from yawPyCrypto.Constants import CIPHER_BLOWFISH, MODE_CBC passwd = 'this is not a great passwd' blocksize = 1024 infile = file('source.mp3') enc = EncryptCipher(passwd, CIPHER_BLOWFISH, MODE_CBC) outfile = file('crypted.mp3.cr', 'w') while 1: data = infile.read(blocksize) if len(data)==0: break enc.feed(data) outfile.write(enc.data) enc.finish() infile.close() outfile.close() # Now try and decrypt dec = DecryptCipher(passwd) infile = file('crypted.mp3.cr') outfile = file('decrypted.mp3', 'w') while 1: data = infile.read(blocksize) if len(data)==0: break dec.feed(data) outfile.write(dec.data) infile.close() outfile.close() ------------------------------------------------------------------ video:~/python/examples/yawpycrypto> ls -l *mp3* -rw-r--r-- 1 jdhunter members 3620957 Aug 28 12:36 crypted.mp3.cr -rw-r--r-- 1 jdhunter members 3609600 Aug 28 12:36 decrypted.mp3 -rw-r--r-- 1 jdhunter members 3610317 Aug 28 12:32 source.mp3 From mis6 at pitt.edu Sat Aug 23 11:18:49 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 23 Aug 2003 08:18:49 -0700 Subject: Modifying the {} and [] tokens References: <04cekv0s6ghjtuhl5j2gph7ltobdb5rsam@4ax.com> Message-ID: <2259b0e2.0308230718.53d22c14@posting.google.com> Geoff Howland wrote in message news:<04cekv0s6ghjtuhl5j2gph7ltobdb5rsam at 4ax.com>... > On 23 Aug 2003 07:02:53 GMT, "OKB (not okblacke)" > wrote: > > >> {} + {}, {} - {}. [] - [], etc > > > > I'm a little puzzled as to why you'd need these, since it seems > >like all they allow you to is hard-code a certain combination of > >statically defined objects. That is, if you're going to do > > > >{ 'a': 1, 'b': 2 } + { 'c': 3, 'd': 4} > > > > . . .why not just write > > > >{ 'a': 1, 'b': 2, 'c': 3, 'd': 4} > > > > in the first place? > > Because I wouldn't just be using {} on a line, I would create a > dictionary with it and then use it around, and then at some point > later I may want to add another dictionary to it, or find the union or > differences between two dictionaries. > > Ruby has this built in, it's useful, it's complete. It's obvious what > is happening, so it's not unclean. It's allowed for other containers. > > > -Geoff Howland > http://ludumdare.com/ Subclass dict, define __add__ and __sub__ and it will work, but NOT with the brace syntax. You must use something like mydict(a=1,b=2)+mydict(c=3,d=4) Python tries hard not to modify its basic syntax, so you must stay with the above. Pythonista would argue that this is a strenght of the language: "explicit is better than implicit". Michele Simionato, Ph. D. MicheleSimionato at libero.it http://www.phyast.pitt.edu/~micheles --- Currently looking for a job --- From duncan at NOSPAMrcp.co.uk Thu Aug 21 08:07:33 2003 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Thu, 21 Aug 2003 12:07:33 +0000 (UTC) Subject: Removing language comparisons References: Message-ID: "A.M. Kuchling" wrote in news:LvmdnSlj7NA_uNmiRTvUqg at speakeasy.net: > python.org has a page of "Python vs. X" language comparisons at >. They're all pretty >outdated, > and often unfair because they're written by a person who knows Python > well but has only a nodding acquaintance with language X. > How about getting some new articles to be written by pairs of people, one Python user who knows a bit of the other language and one person who lives and breathes Perl/Java/Ruby/etc but knows a bit of Python? That way you might end up with some genuinely objective comparisons showing both sides of the fence. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From aleax at aleax.it Sun Aug 3 11:26:30 2003 From: aleax at aleax.it (Alex Martelli) Date: Sun, 03 Aug 2003 15:26:30 GMT Subject: Changing base class of a big hierarchy References: <873cgjyo2u.fsf@pobox.com> Message-ID: John J. Lee wrote: > I'm trying to change a base class of a big class hierarchy. The > hierarchy in question is 4DOM (from PyXML). 4DOM has an FtNode class > that defines __getattr__ and __setattr__ that I need to override. ... > Obviously, I don't want to manually derive from every damned leaf > class. I want to say "give me a new class hierarchy just like this > one, but derived from BrowserFtNode instead of FtNode". I also don't > want to actually mutate the xml.dom module, of course because other > code may be using it. OK, so you want to do two things: -- "deep-copy" a class hierarchy H to H' -- in the copied hierarchy H', change each occurrence in any __bases__ of a class X' to a class Y', and any other class T that is in H to the corresponding class T' in H' > What's the easiest way to do that? I think performing these two steps in order is probably simplest. You do have to identify every class in your starting hierarchy H, of course. > Maybe deep-copying the module or something, then fiddling with > __bases__?? Or a metaclass? Deep copying might not help -- copy.deepcopy(X), when X is a class, still leaves __bases__ unchanged. A custom metaclass that does bases-alteration as you require would be reasonably easy to write, but would be more helpful than just doing the same job in a function if, and only if, you were to re-execute every affected 'class' statement using the new metaclass. I doubt that getting and re-executing those class statements is simplest in this case. > While I'm on the subject, does anybody have code to get a list of all > classes in a package that derive from a particular class? Or > something I could use to do that easily? I'm not sure of how to identify "all classes in a package" in the simplest way. All classes in a module, or other single container, is of course easy (and actually you only want classes that derive from X, so you'd filter that with issubclass); but offhand I can't think of a handy, elegant and robust way to ensure you're walking all over a package (including sub-packages), nor even that all of a package (cum subpackages) is actually LOADED at this time. I suspect that for this purpose you will need to perform file-system checks about what files in a package-directory are python modules, what directories are sub-packages, and so on (I'd love to be wrong on this point... maybe I just haven't given it enough thought... for all submodules within the packages that ARE loaded, looping over sys.modules.keys() and checking for the appropriate prefix would do, but HOW else would one ensure that every single subpackage and module therein is already loaded, save by filesystem ops...?). If you can get all the modules of interest, say by an iterator, then getting all classes of interest is reasonably easy. Altering them as you require is not all that hard, except that the ORDERING in which you're looking at the class objects might be wrong -- it would be simplest if you could be ensured of only looking at a class after you've looked at all of its ancestors. I think we can do that by playing with the (inevitable) dict of class translations. Something like: # seed this with the base class transformation trans_dict = {X: transformed_X} # recursive way to transform a class between hierarchies def transform_class(C): if not issubclass(C, X): return C if C in trans_dict: return trans_dict(C) bases = tuple([transform(B) for B in C.__bases__]) newclass = type(C)('C', bases, C.__dict__) trans_dict[C] = newclass return newclass Of course, if the classes in the hierarchy use each other in more ways than just a base/subclass inheritance [e.g, some classes have other classes as attributes, not just as bases] you may need a bit more work [e.g., on C.__dict__ as well as on C.__bases__]. But I think this is probably the core of what you want, to be applied to a way to loop over all the classes that may interest you, and store the transformed classes somewhere -- that 'somewhere' of course will need to be where some code that uses these classes (and originally written to use classes from the original hierarchy) will look to get the class-objects it uses. You may need to alter the semantics of 'import' statements in that using-code, too, since you did say you do NOT want to alter the actual packages and modules that contain the untransformed [original] classes, and import statements for those modules that you do not want to alter is probably how existing using-code gets its access to those classes... but this is beyond the issue of how to MAKE the new slighty altered hierarchy, and into the separate issue of how to get some existing code to USE the new altered hierarchy once you've made it. Alex From ejeanlouis2001 at yahoo.com Tue Aug 12 13:14:48 2003 From: ejeanlouis2001 at yahoo.com (Emmanuel Jean-Louis) Date: Tue, 12 Aug 2003 10:14:48 -0700 (PDT) Subject: (no subject) Message-ID: <20030812171448.8183.qmail@web13003.mail.yahoo.com> I think it would reduce trafic here if you read an elementary book about how to program with Python. Please, I do not want to be rude! But Python generally has more or less plain vanilla IDEs. You just have to try them out! Most popular is IDLE or course, but there is definitely more. Some of them cost money! SecretLab's PythonWorks Pro, ActiveState's KOMODO, ... Sometimes those IDEs are coupled to GUIs and have GUI Builder Feature.However you have to decide which GUI-Toolkit you want to use (Qt, wx, Tkinter,GTK,......) There is more than one way to do it, as they say at the other place ;-) I was not talking about the GUI drop down. I was talking the feature in IDE that will allow you to see that methods associate with a particular class. Let say I have a class named Foo funk = new Foo() funk., after typing the dot (.), the drop down list will show me all the available methods associate with this class. That is what I meant. So if that was not clear to you guys. Thx. Emmanuel ---------------------------------------------------------------------------------------------------------------------------- Kindly Michael Peuser "Emmanuel Jean-Louis" schrieb im Newsbeitrag news:mailman.1060692918.5794.python-list at python.org... Does python 2.2 has a drop down feature like VB does so that you can list of methods and variables associate with that particular class? If it does, how do I turn it on? Thx. --------------------------------- Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software -------------- next part -------------- An HTML attachment was scrubbed... URL: From dtolton at yahoo.com Tue Aug 12 01:22:56 2003 From: dtolton at yahoo.com (Doug Tolton) Date: Tue, 12 Aug 2003 05:22:56 GMT Subject: Python should try to displace Java References: Message-ID: On Mon, 11 Aug 2003 18:43:08 -0700, "Brandon J. Van Every" wrote: >I'm going to make a number of points which I'm sure many people will object >to. Feel free, but also try not to knee-jerk about them. As someone who >programmed DEC Alpha in 1998, and who sees the sorry state of CPUs nowadays, >I can definitely say that better technology doesn't always win. In fact, it >doesn't *usually* win. Python needs to look to its strategic marketing and >product positioning if it expects to survive in the rough and tumble world >of mainstream industry. Ok, this sounds like a troll to begin with, but I'm bored and irritable so I'll have a go at it. Better technology doesn't always win in the short term, however it almost always wins in the long term. You are looking at something from a very narrow time period. Something that was better 5 years ago, but sucks today wasn't definitively a better technology. > >Points to note: > >- in 5 years, nobody will be doing significant amounts of new application >development in C++. The writing is on the wall: garbage collection is >essential. Any C++ code will be support and legacy libraries. That's a ridiculous blanket statement. People will be doing C++ development for a long time beyond that. There are people still writing Cobol for crying out loud. As you said, it's not always about the best technology, quite frequently it's about what people know, and there are a lot of people that know and are comfortable with C++ > >- Microsoft is already implementing said strategy across all levels of the >company today. Microsoft developers don't do much C++ development anymore. >Various upcoming products are being written entirely in C#. just what we need. More buggy slow products from MS that have Memory Leaks the size of the Mississippi. C# is not a good development platform yet. Heck they are practically still in the standard MS beta period. Everyone knows not to use a MS product on version 1.0 > >- The "higher level language" playing field is crowded: C#, Java, Perl, and >Python. Mainstream industry does not need and will not make room for 4 >higher level languages. Any of these languages has to grow at some other >language's expense. This statement is really vague, and has almost no factual basis. If there were only four programming languages the world would be a very dull place. You forgot to mention Delphi, Visual Basic, Power Builder and a host of others. There is room for a lot more than 4 programming languages. > >- Python will never displace C# on Windows. It's Microsoft's home turf and >you can't fight directly with The Beast. You will see UNIX boxes running >Python, not Windows boxes. That's a bold statement, considering the abysmal adoption rate of C#. C# isn't the dominant windows programming language currently, rather its Visual Basic. Java has far more applications written for Windows than C# does. MS really shot themselves in the foot when they went to dotnet, essentially the adopted the Java platform 8 years after Java. Now they are playing catchup with an inferior product. I doubt they'll ever catch up to Java overall. > >- Sun is about to die. It has done nothing for anyone lately and has no >further tricks up its sleeve. People have been saying this for years. I'll believe it when I see it. > >- Sun has failed to make Java live up to its claims of universality. Java >is for all intents and purposes simply a widespread programming language, >not a portable computing environment. Portable computing environments are, >in general, a pipe dream as long as Microsoft is around. It will always be >Windows vs. open standards. They must give you a good edjumacation at the Redmond campus. Java is by far the best portable computing environment available. These claims are actually laughable. You might want to actually look at a technology before you bash it ignorantly next time. Microsoft is losing ground *big time* to open standards. We'll see how things play out in the next 20 years though. Open Source will be around that long, will Microsoft in it's present incarnation? > >- Java is proprietary. Python is open source. Open Source is the best shot >that anyone has at competing with Windows. Java is only semi-proprietary. It's not the same proprietary you get when using a MS product, because they are the *only* vendor. Still, I agree Open Source is the better way in the long run. > >- Perl is open source and sysadmins won't be giving it up any time soon. >Perl is optimal for their jobs, the capabilities of Python are a non-sell. Perl is a great language for some things, but it really sucks for other things. The Sysadmins I know would love to use Python. It's capabilities are a non-sell? mm...if you think being able to read your code two days after writing it is a non-sell, well ok. > >- Ergo, Java is the weakling of the litter for Python to attack. No factual basis for this statement. Java and Python are really entirely different things. Python is meant as a scripting language, Java is a Systems programming language. It is meant as an alternative to C++, Python isn't. > >- Alternately, if you look at this in real world marketing terms, Python is >the weakling of the litter that must defend itself. I know that will make >various Python idealists upset, but that's the economic reality. Merit >doesn't win in this game. Java is the next weakest langauge so that's whose >lunch Python should try to eat. Who does Python have to defend itself against? Python is Open Source. The only way it's going to die is if everyone stops developing it and it stagnates. If that hapens it will be because something *significantly* better came along. Python doesn't have to defend itself, your Microsoft background is showing through here. C# is by far the weakest language of the four. It is buggy, slow and immature. It has the smallest user base, the least amount of industry backing and a community that is rising up against it's benefactor. I think you dramatically overstate it's chances. Historically Microsoft switches technologies every 3 or 4 years. That only gives C# about 2 years to go before it's dead in the water like every other MS "Innovation". > >- No, this isn't the appraisal of a Microsoftie who wants to set Python and >Java at each others' throats to conquer both. :-) I'm just offering a >realistic picture of what your options are, if you don't want to become a >"gee whiz, wasn't that nice!" technology. Like I said, I've lived through >it already. Don't talk to me about merit carrying the day. Learn from >history, or you are doomed to repeat it. If you subsitute the word propaganda for appraisal, and "highly dogmatic" for realistic you'd be closer to the mark. Historically those with the best technology and the best economic system prevail against inefficient and inferior models. Since there wasn't really a cogent thesis I can't reject it per se, but your arguments are silly at best. Oh well, it was fun going through that ridiculous argument. And it killed some time while my Sql Script was running. Thanks for the diversion. From donn at drizzle.com Sat Aug 16 00:01:44 2003 From: donn at drizzle.com (Donn Cave) Date: Sat, 16 Aug 2003 04:01:44 -0000 Subject: robust clean-up with SIGTERM (was Re: Again, how to write a cleanup function for a module in C ) References: Message-ID: <1061006502.751865@yasure> Quoth "Changjune Kim" : [ ... re why signal handling may not be 100% reliable ] | When signals are generated successively in a very short time, python | interpreter might screw up some of them. Basically, the interpreter checks | every checkinterval(default 100) if it has pending signal handler calls, | and process them. When a signal is generated, it registers the signal and | put its handler on the pending calls. As you can see there are potential | race conditions. | | Check signalmodule.c and ceval.c. | | I don't have a good idea on making signal handling always safe & | guaranteed. Maybe someone else can help? Well, there are ways to defer signal delivery while you process the signals that have already been delivered - /* (untested) */ sigset_t mask, prev_mask; sigfillset(&mask); sigprocmask(SIG_SETMASK, &mask, &prev_mask); /* All signals now blocked. */ ... process state from signal deliveries sigprocmask(SIG_SETMASK, &prev_mask, 0); and you can set a signal handler up such that signals are blocked while it executes - sa.sa_handler = signal_handler; sa.sa_flags = 0; sigfillset(&sa.sa_mask); sigaction(SIGTERM, &sa, 0); This assumes signal handling per POSIX 1003.1, which may be part of the reason if Python isn't trying to do it. Then there are some naturally intrinsic problems with signal handling in Python that make delivery unreliable in a different way - your signal handler may be invoked much later than the signal is delivered. (And of course if you're using threads, there are more problems.) That's only relevant to the present question because, given the unavoidable weaknesses in Python signal handling, it may not be worth even a slight headache from platforms that don't support POSIX signal handling or don't support it correctly. Donn Cave, donn at drizzle.com From root at softnet.tuc.gr Fri Aug 8 17:37:45 2003 From: root at softnet.tuc.gr (grid) Date: Sat, 09 Aug 2003 00:37:45 +0300 Subject: problem updating(run) to python2.2 Message-ID: <3F341829.3050002@softnet.tuc.gr> i have Debian, i have python2.1 and when installing python2.2, i run "$/python ",but pc run's python2.1.How can i overcome this problem? thanks From trader at terray.com Tue Aug 26 02:46:45 2003 From: trader at terray.com (Trader) Date: 25 Aug 2003 23:46:45 -0700 Subject: Extracting Rich Text data formats from win32clipboard Message-ID: Hi, I'm trying to use Mark Hammond's win32clipboard module to extract more complex data than just plain ASCII text from the Windows clipboard. For instance, when you select all the content on web page, you can paste it into an app like Frontpage, or something Rich Text-aware, and it will preserve all the formatting, HTML, etc. I'd like to include that behavior in the application I'm writing. In the interactive session below, before I run the clipboard_grab() function, I've selected all of the www.google.com homepage in IE and hit Control-C. The function cycles through all the formats stored on the clipboard and loads up a data list with each type it finds. Here's where it gets interesting: while data[2] is the textual data that I would expect to see if I pasted the clipboard in a Notepad file, data[0] and data[1] are in a weird, non-ASCII (binary?) format. Are these pointers to (or metadata for) the actual HTML or rich text? How do I use this data? Is there a reference I can use that will help me decipher this information? Any help would be greatly appreciated. Thanks! ---- Python 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import win32clipboard >>> >>> def clipboard_grab(): ... global format, formats, data ... win32clipboard.OpenClipboard() ... format = 1 ... formats = [] ... data = [] ... while 1: ... format = win32clipboard.EnumClipboardFormats(format) ... print "FORMAT:", format ... if not format: ... break ... try: ... datum = win32clipboard.GetClipboardData(format) ... formats.append(format) ... data.append(datum) ... except: ... print format, traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback) ... win32clipboard.EmptyClipboard() ... win32clipboard.CloseClipboard() ... >>> >>> >>> clipboard_grab() FORMAT: 49171 FORMAT: 16 FORMAT: 7 FORMAT: 0 >>> len(data) 3 >>> data[0] '\x00\x00\x00\x00\x18\x01\x00\x00\x01\x00\x00\x00\x06\x00\x00\x00\x00\x00\x00\x0 0\x00\x00\x00\x00\xe3\xc0\xc2w\x00\x00\x00\x00\x01\x00\x00\x00\xff\xff\xff\xff\x 01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xa2\xc0\xe9\x02\x 00\x00\x00\x00\x01\x00\x00\x00\xff\xff\xff\xff\x01\x00\x00\x00\x01\x00\x00\x00\x 00\x00\x00\x00\x00\x00\x00\x00K\xc1\xc2w\x00\x00\x00\x00\x01\x00\x00\x00\xff\xff \xff\xff\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00L\xc1\xc 2w\x00\x00\x00\x00\x01\x00\x00\x00\xff\xff\xff\xff\x01\x00\x00\x00\x01\x00\x00\x 00\x00\x00\x00\x00\x00\x00\x00\x00\r\x00\xc2w\x00\x00\x00\x00\x01\x00\x00\x00\xf f\xff\xff\xff\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0 1\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\xff\xff\xff\xff\x01\x00\x00\x00\x0 1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0 0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0 0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0 0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' >>> data[1] '\t\x04\x00\x00' >>> data[2] '\r\n \tWeb\t \tImages\t \tGroups\t \tDirectory\t \tNews\t \r\n\r\n \t\r\n\t \x0 7 Advanced Search\r\n \x07 Preferences\r\n \x07 Language Tools\r\n\r\n\r\nAdvert ise with Us - Business Solutions - Services & Tools - Jobs, Press, & Help\r\n\r\ nc2003 Google - Searching 3,307,998,701 web pages' >>> From jarausch at skynet.be Mon Aug 4 16:26:19 2003 From: jarausch at skynet.be (Helmut Jarausch) Date: Mon, 04 Aug 2003 22:26:19 +0200 Subject: check if running under IDLE Message-ID: <3f2ec16b$0$285$ba620e4c@reader0.news.skynet.be> Hi, I'd like to check a script which needs sys.argv I haven't seen a method to set this when running the script in IDLE's shell or editor window. The only way I've found is to assign (test values) to sys.argv but only if the script is running under IDLE Is there a mean either to set sys.argv without modifying the script or to check if the script is running under IDLE's control. Thanks for a hint, Helmut Jarausch Lehrstuhl fuer Numerische Mathematik RWTH - Aachen University D 52056 Aachen, Germany From vanevery at 3DProgrammer.com Tue Aug 12 15:04:05 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Tue, 12 Aug 2003 12:04:05 -0700 Subject: Python vs. C# References: Message-ID: Heiko Wundram wrote: > And, is having an interpreted language really such a major concern in > the age of computers operating at 2000+ Mhz? For those of us who are going to continue to increase our triangle counts, yes it is a concern. But if we can find a way to do those parts of the code in C++, and gracefully integrate them, the concern goes away. > And I > don't really want to express game logic, such as computer player AI, > or the like, in C++. Do you? C++ is appropriate for low-level AI, such as pathfinding and terrain analysis. I would not want to do high level AI in C++, and probably game logic would be better done in something else. The question is, what price do you pay for integration? > Isn't a renderer and a game engine a big system architecture? I didn't > just prototype it in Python, I could offer a complete system, which > was > very extensible. I could've never managed this in any other langauge > without the usual headaches. Yes it is, but you didn't write a big system architecture in 72 hours. > And to a sidenote: Unix has always had a .NET Framework. The libraries > .NET tries to standardize have been available on Unix since a long > time. I"m talking about language interoperability because of the Intermediate Language. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From phlip_cpp at yahoo.com Tue Aug 19 10:36:27 2003 From: phlip_cpp at yahoo.com (Phlip) Date: 19 Aug 2003 07:36:27 -0700 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: <3F41208F.40021A68@engcorp.com> <3F413F8C.47AAE514@engcorp.com> Message-ID: <63604d2.0308190636.4c8dd892@posting.google.com> > I don't know either. I do know of several posters on the XP > lists, however, who have switched from Python to Ruby, and > I doubt that it was corporate pressure in any of their cases. > > If you're interested (which most of the posters here are not - > I'm certainly not) you might check with them. I'm sure Phlip, for > one, would be more than happy to say why he switched, and what > made the difference. > > John Roth Hi, JR! I got paid to research in Python, for a while, and started using Ruby as a hobby project on the side - http://flea.sf.net Python blocks, collections, and indentation all suck, but so do C++ equivalents, and I still use the latter as a hobby language, too. If you were to instrument my physical responses and typing rate while coding using Python and Test Driven Development, and compare them to my responses using Ruby, you'd get close to assessing the subjective reason I ain't going back. And I would be interested to see such a comparison between Ruby and Smalltalk. I can't use the latter, but I suspect Ruby exceeds its expressiveness, but without the weird syntax. To reveal objective reasons would lead to tired old threads like this one. I could never write a paragraph expressing why Ruby is better, or why this is not a personal taste thing. The /Programming Ruby/ book says, "Ruby stays out of your way". I know Python tried to be like that too, but it left in so many little irritations. Finally, my TFUI book will use Ruby for its core samples, but generally written as expressively as possible, so that Pythonics and others can read it. I consider this a great improvement over similar books that use that abomination Java. The elegant simplicity of C++ and the blazing speed of Smalltalk! -- Phlip http://www.c2.com/cgi/wiki?TestFirstUserInterfaces From sjmachin at lexicon.net Sat Aug 2 00:47:13 2003 From: sjmachin at lexicon.net (John Machin) Date: Sat, 02 Aug 2003 04:47:13 GMT Subject: Is there the same function in python as atoi() in C References: Message-ID: <3f2b3ba5.27454387@news.lexicon.net> On Sat, 2 Aug 2003 11:51:54 +0800, "Robbie" wrote: >Someone tell me, >if not exist, how to write one with the same function? >I have made a try, but there is no character type in python, >so i failed, someone help me, >thanks very much > > General question: Have you read some of the tutorials? Regarding your specific problem: 1. Think about it. A language without such a function would be utterly useless. 2. There is a built-in function called int() -- look it up in the manual. 3. Don't bother with the atoi() in the string module -- inspection of ..../Lib/string.py will tell you that it just calls int() anyway. 4. No character type? How would you like that, signed or unsigned or implementation-defined? Python avoids that little chamber of horrors and does rather well by using strings of length 1. Here's a rough untested no-negative-allowed no-explicit-overflow-checking base-10-only atoi() ... def demo_atoi(astr): num = 0 for c in astr: if '0' <= c <= '9': num = num * 10 + ord(c) - ord('0') else: raise ValueError('demo_atoi argument (%s) contains non-digit(s)' % astr) return num From fabsk+news at free.fr Wed Aug 13 04:12:19 2003 From: fabsk+news at free.fr (Fabien SK) Date: Wed, 13 Aug 2003 10:12:19 +0200 Subject: Cyclic references et C libraries Message-ID: <3f39f329$0$16171$626a54ce@news.free.fr> Hi, I have a problem with a python module that uses C objects. In this module (not mine, found on the net), I have one parent objet that maintains a list of child objects. The child objects have a reference on the parent object, so there is a cycle. The parent object has a file handle (it is a native C object, not a python "file object") as a member. This handle can be used with functions like "lib_open", "lib_close", "lib_read_section". My problem is that: - I can not release the parent object in a fully automated manner, so there is a leak, and since there is a native object, the handle will not be closed. I can not modify the library to wrap the handle in a class, because if such a class has a "__del__" method the python garbage collector will not clean the cycle I find it not funny to have leaks in Python, and to have to clean objet by hand. One solution would be to wrap the parent objet in a new class (forwarding all the calls to the parent object). In the "__del__" method of this class, I would clean the list of children object, and then remove the reference on the parent objet so its "__del__" method will be called. Am I right ? Last question: why does the python file objects not have a "__del__" method ? How the file can be closed when the last reference is remove ? If I do a simple test, there is not file leak: class Toto: def __init__(self): self.file = open("tata") while 1: a = Toto() b = Toto() a.member = b b.member = a The GC can clean the cycle because the file object doesn't have a "__del__" method. Fabien From rxs141 at cwru.edu Sat Aug 2 19:28:31 2003 From: rxs141 at cwru.edu (Ravi) Date: Sat, 02 Aug 2003 19:28:31 -0400 Subject: Match beginning of two strings In-Reply-To: <3f2c429e@nntp0.pdx.net> References: <3f2c429e@nntp0.pdx.net> Message-ID: >> > While you can be forgiven for not have guessed, os.path is the place to > look: > import os.path > a = "abcdefghijklmnopqrstuvwxyz" > b = "abcdefghijklmnopBHLHT" > print os.path.commonprefix([a,b]) > > -Scott David Daniels > Scott.Daniels at Acm.Org > Certainly not where I was expecting it, Thanks Ravi From schaffer at optonline.net Wed Aug 27 23:18:31 2003 From: schaffer at optonline.net (Les Schaffer) Date: Wed, 27 Aug 2003 23:18:31 -0400 Subject: python version of emailstripper??? References: <3292735.1062016070@dbforums.com> Message-ID: On Wed, 27 Aug 2003 16:27:50 -0400, Andrei wrote: > >I don't know that program, but if it just strips leading ">", it's >pretty easy to do. i thought it does more. but it doesn't wrap long lines properly. anyway, was just looking if someone has implemented a web version of this already, before coding it myself. les schaffer From midnight at warm-summer-night.net Thu Aug 28 10:30:08 2003 From: midnight at warm-summer-night.net (falling star) Date: Thu, 28 Aug 2003 14:30:08 GMT Subject: OT: Americans love their guns References: Message-ID: Lulu of the Lotus-Eaters wrote: LotLE> LotLE> USA automobile deaths are ^43k/year LotLE> USA gun-related deaths are ~29k/year Where did you get your number? 29k a year??? Don't believe it. I would guess the number to be somewhere in the 1000 to 2000 range. Unless you are including people killed by police in your figure? And suicides? LotLE> LotLE> The first number is bigger, yes.... but nothing at all like 100x as LotLE> large. LotLE> LotLE> Pulling facts out of thin air (or equivalently, our of NRA leaflets LotLE> or ESR's writing) is unpersuasive. Absolutely agree with this. Also add, pulling facts out of Handgun Control leaflets is equally unpersuasive. We should probably agree that this is an emotional issue, and leave it at that. Or as Mark Twain put it, 'There are lies, damn lies, and statistics'. However, when the little gangbangers in the neighborhood start popping off, it is far more comforting to know that if they pop at me, I can pop back, than it is to know that I can call the police. And when the home invasion stories run in the newspaper, I don't worry as much as if I had to depend only on calling the police. The statistic the other poster mentioned about more guns lowering crime: In states with concealed carry laws, *crime* is lower. Your statistic about gun _deaths_ being higher in states with relaxed gun laws is a canard. That is correlating gun deaths with overall crime. There are issues of population as well. Again, we are talking statistics, and there can be no agreement as there are so many correlated factors. Once, I too was of faulty mind like you, fearful of my own shadow, thinking that guns were the root of all evil, that they prowled the night and the day, waiting to leap out and harm me. Then I saw the light. :-) Just shows to go you the effectiveness of propaganda. However you want to take that. :-) LotLE> LotLE> Yours, Lulu... LotLE> From a.neudecker at uni-bonn.de Fri Aug 29 13:52:00 2003 From: a.neudecker at uni-bonn.de (Andreas Neudecker) Date: Fri, 29 Aug 2003 19:52:00 +0200 Subject: method (a, b = '', *c, **d): gets a syntax error? In-Reply-To: <0KJ3b.9551$aG6.309676@news1.tin.it> References: <3F4F644D.2060003@uni-bonn.de> <0KJ3b.9551$aG6.309676@news1.tin.it> Message-ID: >>class WhatsUp: >> __call__ ( > You're missing the keyword 'def' here, right before the method name. %&%$ How blind can you get ...! And I have been sitting in front of these lines for, well, ages. THANK YOU! :-) Regards Andreas From ialbert at mailblocks.com Thu Aug 21 12:52:14 2003 From: ialbert at mailblocks.com (Istvan Albert) Date: Thu, 21 Aug 2003 12:52:14 -0400 Subject: [OT] Why is it called string? In-Reply-To: <3F44DBF2.1010403@draigBrady.com> References: <3f44ce77$0$556$b45e6eb0@senator-bedfellow.mit.edu> <3F44DBF2.1010403@draigBrady.com> Message-ID: P at draigBrady.com wrote: > I'm always surprised by the number of people > in computing that don't know this. In all fairness, knowing what bit stands for does not mean much. I would guess that for people that lived through the computing revolution the notion of a binary digit made the concept more accessible. For those born into the whole thing the fact that the word bit is an acronym might feel as an oddity since they are so much accustomed to it that does not need explanations. Istvan. From ghowland at lupineNO.SPAMgames.com Sat Aug 23 21:58:38 2003 From: ghowland at lupineNO.SPAMgames.com (Geoff Howland) Date: Sun, 24 Aug 2003 01:58:38 GMT Subject: python gripes survey References: Message-ID: <7s6gkv031b940dsc522pbh5g30q4nj5vd1@4ax.com> On Sat, 23 Aug 2003 15:39:27 GMT, "Ryan Lowe" wrote: >python is a big improvement on most languages that came before it, but no >language is perfect. id like to make a list of some of the aspects people >find most annoying, regardless of their feasibility of implementation. for >instance, i discussed putting if clauses in for loops, and i noticed another >thread about allowing {} and [] to be added and subtracted. if its something >from another language (especially an obscure one), please explain how it >works in case people like myself dont know the language. Just to point some things out since I started the {} [] thread. I was trying to do something hacky, and while I wanted the [].len() type calls for my team mates, I never had a problem with the current len() and understand the reasoning behind it. [].len() is more uniform, but it also changes the requirements for the language in a duplicated fashion, since the test for __len__() will always exist as well. So while I think they may have been reasonable requests, Im not sure theyre really pitfalls, and Im not sure they would even work out that well on a large scale which is why I wanted to implement it and test it out myself. -Geoff Howland http://ludumdare.com/ From hokiegal99 at hotmail.com Tue Aug 26 23:13:40 2003 From: hokiegal99 at hotmail.com (hokiegal99) Date: Tue, 26 Aug 2003 23:13:40 -0400 Subject: Raw Input Question References: Message-ID: <3F4C21E4.8010108@hotmail.com> Yes, This works nicely... thanks to all for the quick responses!!! Tony Meyer wrote: > y = raw_input("2. Enter the string that you'd like to replace %s with: " % > (XXX,)) > > =Tony Meyer From aahz at pythoncraft.com Thu Aug 7 13:46:35 2003 From: aahz at pythoncraft.com (Aahz) Date: 7 Aug 2003 13:46:35 -0400 Subject: Class design issues: multiple constructors References: <33803989.0308070349.29d8604e@posting.google.com> Message-ID: In article <33803989.0308070349.29d8604e at posting.google.com>, Miki Tebeka wrote: > >1. Module (not class) methods: db = opendb(..), db = createdb(...) Clarification: modules have functions, not methods -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From mike-nospam at skew.org Fri Aug 22 13:47:02 2003 From: mike-nospam at skew.org (Mike Brown) Date: Fri, 22 Aug 2003 17:47:02 GMT Subject: Q: urlopen() and "file:///c:/mypage.html" ?? References: <87n0e1zqzh.fsf@pobox.com> Message-ID: "John J. Lee" wrote in message news:87n0e1zqzh.fsf at pobox.com... > "Michael Geary" writes: > > > MAK wrote: > [...] > > > > If I were to use, say, Netscape to open this file, I'd specify it as > > > > "file:///c:/mypage.html", and it would open it just fine. But > > > > urlopen() won't accept it as a valid URL. I get an OSError > > > > exception with the error message "No such file or directory: > > > > '\\C:\\mypage.html'". > [...] > > f = urllib2.urlopen( 'file:///c|/mypage.html' ) > > Why does Python use a different syntax to the rest of the Windows > world? On Windows, if I open a local file in Netscape 4, the Location bar shows a "file" URL with the "|". If I open a local file in Internet Explorer (or the file Explorer with the Address bar turned on), the Address bar shows a "file" URL with a ":". The resolver used by both Netscape and Explorer will accept either one, if you type it in the address bar. So who is to say what is canon? The 'file' URI scheme is, by definition, OS dependent. If the OS likes the URL, then it's good enough. For 4Suite running on Windows, we were thinking of making a Python wrapper to the Windows resolver for maximum compatibility, but haven't gotten around to it. For now, we avoid the bug-ridden urllib as much as we can, and do some voodoo on 'file' URLs to convert them to OS-specific paths that are safe to pass to open() on the (win32 or posix) OS we're running on. It's not foolproof yet, and won't handle the colon case, but does a round-trip from an OS path to a URI and back pretty well. See the UriToOsPath() and OsPathToUri() work in the Ft.Lib.Uri module here: http://cvs.4suite.org/cgi-bin/viewcvs.cgi/4Suite/Ft/Lib/Uri.py?rev=1.49&content-type=text/vnd.viewcvs-markup From mpeuser at web.de Sun Aug 17 17:47:31 2003 From: mpeuser at web.de (Michael Peuser) Date: Sun, 17 Aug 2003 23:47:31 +0200 Subject: hex(-5) => Futurewarning: ugh, can't we have a better hex than '-'[:n<0]+hex(abs(n)) ?? References: Message-ID: "Bengt Richter" schrieb im Newsbeitrag news:bhomem$jg8$0 at 216.39.172.122... > >>> hex(-5) > __main__:1: FutureWarning: hex()/oct() of negative int will return a signed string in Python 2.4 and up '0xfffffffb' [...] There is a thread from this morning ("bitwise not ...") - this should be an excellent contribution! I have no mercy with someone writing hex(-5) Kindly Michael P From adalke at mindspring.com Fri Aug 1 00:20:36 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Thu, 31 Jul 2003 22:20:36 -0600 Subject: egenix mx package weirdness References: Message-ID: Dave Harrison: > The error is quite simply a coredump. > > Anyone have similar experiences/problems ? any ideas ? Since you have the core dump, can you give us a stack trace? Is it possible to make a small version of the code which reproduces the error? Can you trace which function is causing the core dump, eg, by using a debugger (like pdb, which comes with Python), or by using venerable print statements? Without this information, it's highly unlikely that someone can make any more detailed comment. The best you might get is "yeah, that was a problem in version XYZ, upgrade and it'll go away", which is not a solution for you. Andrew dalke at dalkescientific.com From hanzspam at yahoo.com.au Mon Aug 11 16:36:04 2003 From: hanzspam at yahoo.com.au (=?ISO-8859-1?Q?Hannu_Kankaanp=E4=E4?=) Date: 11 Aug 2003 13:36:04 -0700 Subject: Fun with numbers - dammit, but I want a cast! References: <3f378fac$0$10778$afc38c87@auth.uk.news.easynet.net> Message-ID: <840592e1.0308111236.63bd85c0@posting.google.com> Andrew Koenig wrote in message news:... > 2) At the beginning of your source file, execute: > > from __future__ import division > > Python is going to change its behavior so that division always > returns a floating-point value. This statement causes that new > behavior to occur now. By the way, do you know a reason why after doing from __future__ import division this still happens: >>> 3.0 // 2 1.0 Wouldn't it be more convenient to present the resulting whole number as an integer now, since division operation on integers works correctly? At least IMO the operation >>> 3.0 // 2 1 would be more convenient and natural, and floor division could then be used to get array indices for example: print arr[position // scale] Not that I -really- care either way, since casting division result to int isn't verbose either. Just curious, if you or anyone knows the reason for new floor div working this way. From tcurrey at no.no.no.i.said.no Fri Aug 22 19:21:17 2003 From: tcurrey at no.no.no.i.said.no (Trent Curry) Date: Fri, 22 Aug 2003 16:21:17 -0700 Subject: Aspect oriented Everything? References: <32cc321c.0308221316.2f5793ac@posting.google.com> Message-ID: Wow someone actually uses this group! -- Stan From ayc8NOSPAM at cornell.edu Sat Aug 2 06:16:24 2003 From: ayc8NOSPAM at cornell.edu (Andy C) Date: Sat, 02 Aug 2003 10:16:24 GMT Subject: Python 2.3 IDLE doesn't show on Win2000 References: Message-ID: I have this same problem at work, but at home it works fine. Python 2.2's IDLE works fine on both machines. It's only 2.3 at work. I saw a web page that says that IDLE uses 127.0.0.1 or something now for new processes and that interferes with some firewalls, but the firewall has to be on the machine? I don't remember the details -- it's on the Python website somewhere under "Known Bugs". Oh well, I dunno what to do about it. I'm just sticking with 2.2 at worknow. Miine just doesn't load. You double click, and then you see the cursor turn to the hourglass briefly, and then nothing. IDLE doesn't start, no matter how many times you try to launch it. Andy "Vin Jovanovic" wrote in message news:MMGcndzZzpyG97aiXTWJjw at comcast.com... > Trying to start Python IDLE through Start>Programs>Python 2.3> IDLE doesn't > work > > From DOS ... I get this .... > > C:\>python C:\Python23\Lib\idlelib\idle.py > Traceback (most recent call last): > File "C:\Python23\Lib\idlelib\idle.py", line 23, in ? > idlelib.PyShell.main() > File "C:\Python23\lib\idlelib\PyShell.py", line 1264, in main > root = Tk(className="Idle") > File "C:\Python23\lib\lib-tk\Tkinter.py", line 1564, in __init__ > self.tk = _tkinter.create(screenName, baseName, className) > _tkinter.TclError: Can't find a usable init.tcl in the following directories > {C:\ptc\dataserver\intralink\tools\lib\tcl} {C:\ptc\dataserver\intralink > ls\lib\tcl} C:/ptc/dataserver/intralink/tools/lib/tcl8.4 c:/python23/lib/tcl > c:/lib/tcl8.4 c:/library > > C:/ptc/dataserver/intralink/tools/lib/tcl/init.tcl: version conflict for pac > "Tcl": have 8.4, need 8.2 > version conflict for package "Tcl": have 8.4, need 8.2 > while executing > "package require -exact Tcl 8.2" > (file "C:/ptc/dataserver/intralink/tools/lib/tcl/init.tcl" line 19) > invoked from within > "source C:/ptc/dataserver/intralink/tools/lib/tcl/init.tcl" > ("uplevel" body line 1) > invoked from within > "uplevel #0 [list source $tclfile]" > C:/ptc/dataserver/intralink/tools/lib/tcl/init.tcl: version conflict for pac > "Tcl": have 8.4, need 8.2 > version conflict for package "Tcl": have 8.4, need 8.2 > while executing > "package require -exact Tcl 8.2" > (file "C:/ptc/dataserver/intralink/tools/lib/tcl/init.tcl" line 19) > invoked from within > "source C:/ptc/dataserver/intralink/tools/lib/tcl/init.tcl" > ("uplevel" body line 1) > invoked from within > "uplevel #0 [list source $tclfile]" > > > This probably means that Tcl wasn't installed properly. > > From wickedwickedwicked at hotmail.com Thu Aug 14 09:18:49 2003 From: wickedwickedwicked at hotmail.com (Wicked) Date: Thu, 14 Aug 2003 13:18:49 GMT Subject: ImportError: No module named rpm Message-ID: <3F3B8DC2.7030000@hotmail.com> Hi all, Has anyone got rpm.py? Is this a class/module for Python? I am getting the following error: File "./extra/scripts/update_release.py", line 42, in ? import rpm ImportError: No module named rpm I am using Solaris 9 and the Python package from Sunfreeware.com. The following test code produces a "FAIL" on my system. #!/usr/local/bin/python2.2 from sys import exit def main(): try: import rpm except ImportError: print "FAIL" exit(-1) print "SUCCESS" exit(0) if __name__ == "__main__": main() Thanks for any help in advance. Wicked From simonb at webone.com.au Mon Aug 11 18:47:01 2003 From: simonb at webone.com.au (Simon Burton) Date: Tue, 12 Aug 2003 08:47:01 +1000 Subject: Python and Code Completion References: <3f37d456$0$228@hades.is.co.za> Message-ID: On Mon, 11 Aug 2003 19:39:09 +0200, Madiba wrote: ... > Can anybody please give me some pointers on how to get the available > properties/documentation to a class etc without actually excecuting the > code. Do i have to write my own semi-parser? > I know help('class') displays doc and methods and automatically imports > class, so is there maybe something similar to use? > > any ideas? check out the compiler module. Also, i think pydoc uses it. Simon. From Vincent.Raaijmakers at ge.com Tue Aug 5 14:45:20 2003 From: Vincent.Raaijmakers at ge.com (Raaijmakers, Vincent (IndSys, GE Interlogix)) Date: Tue, 5 Aug 2003 13:45:20 -0500 Subject: site-packages and linux Message-ID: <55939F05720D954E9602518B77F6127F03096E83@FTWMLVEM01.e2k.ad.ge.com> Currently in my linux configuration there seems to be a conflict in my python2.2 and 2.3 install. I installed recently 2.3 but want to go back for some reason to 2.2. All installed packages located in ...\python2.2\site-packages are not recognized anymore. Well, when importing is not possible, no module found error is what I get now. Without re-installing everything, how can I solve this problem? Vincent From achrist at easystreet.com Tue Aug 5 03:04:45 2003 From: achrist at easystreet.com (achrist at easystreet.com) Date: Tue, 05 Aug 2003 00:04:45 -0700 Subject: PyChecker work with Python 2.3? References: <3F2C5300.FA223CBA@easystreet.com> <3F2EB773.4895B5DD@easystreet.com> <3F2EE9C7.A38F7912@easystreet.com> <1MKcnR3fbYoj2LKiXTWJgA@comcast.com> Message-ID: <3F2F570D.A1C3519A@easystreet.com> Terry Reedy wrote: > > It is quite intentional that future imports be simply ignored when > 'obsolete' and not suddenly make program not run. > Don't worry about it. I can find plenty of other ways to have my programs not run. Al From fsc at fuentez.com Fri Aug 29 10:45:39 2003 From: fsc at fuentez.com (fsc at fuentez.com) Date: Fri, 29 Aug 2003 10:45:39 -0400 Subject: EMAIL REJECTED Message-ID: <200308291445.h7TEjaEt011398@wmsc.fuentez.com> Violation found in email message. From: python-list at python.org To: hildjj at fuentez.com From newsgroups at jhrothjr.com Sat Aug 2 18:55:06 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Sat, 2 Aug 2003 18:55:06 -0400 Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> <87el06d2i6.fsf@pobox.com> Message-ID: "Andy C" wrote in message news:mEVWa.279$jw6.24163477 at newssvr21.news.prodigy.com... > > Many tools don't allow you to configure tabs, and of those that do, > > each uses its own incompatible syntax and has its own quirks. In other > > words, tabs may seem like a good thing if you use just one or two tools > > that do what you want, but as soon as your program moves out into > > the wild world, things change. > > What are these quirks? By far the most common I've seen is mixing tabs and > spaces, but this should be relatively easily solved by requiring one or the > other (minus continuation lines, which are still a problem). Using spaces > has some disadvantages too, since not everyone will use the same number of > spaces, and editors don't behave as nicely. I like when you hit the arrow > key at a tab, and it jumps the full tab, rather than having to press an > arrow key 4 times. I'm used to a certain minimum standard from my editors, and smart tabs are one of those things that's part of the price of admission these days, just like syntax highlighting. A programming editor's job is to help where it's useful, and get out of the way when it's not. When you want to indent, you hit the tab button. It's the editor's job to know I want, for example, four spaces, and deliver them. In Python, it's the editor's job to know that when I hit return at the end of a line, there are only one or two legitimate places to put the cursor on the next line, and to put it in the most likely of them. As to the different number of spaces between developers, that's another thing I'd expect from my editors. It's easy enough in Python to figure out what's an indent and infer the number of spaces. I'd expect a decent editor to be able to load a program and tell me what the indentation policy was! I'd also expect to be able to tell it to change it, and have it automatically reindent the program for me. John Roth From donn at u.washington.edu Wed Aug 20 17:11:42 2003 From: donn at u.washington.edu (Donn Cave) Date: Wed, 20 Aug 2003 14:11:42 -0700 Subject: What's better about Ruby than Python? References: <3F41505F.69D18CC8@alcyone.com> <66d7kvonvb2n0nqbqahhd5roak7ur81sob@4ax.com> Message-ID: In article <66d7kvonvb2n0nqbqahhd5roak7ur81sob at 4ax.com>, Doug Tolton wrote: [... re should Python spawn another language that supports macros ] > That certainly is one way for it to happen. I must say I certainly am > suprised at your vehemence. I don't think the natural state of human > beings is singular in purpose or design. I think the natural state of > humans is to fracture into competing camps / factions. *Every* human > system of any size has factions of some sort or another. I think the > power of Unix / Linux in general has been in working to allow these > factions to Co-exists peacefully. By trying to prevent factioning > within the community, I think you will ultimately only be successful > in driving people with different viewpoints out of the community. Fragmentation helps and hurts. The fork that Alex suggests is at least clear, like the choice between regular Python and Stackless. Language change through macros is more insidious because the whole language bears some of the burden, while the benefit if there is any goes to the macro-extended dialect. There's nothing wrong with people with different viewpoints leaving the community. There are all kinds of interesting things happening in computer programming languages, thanks to people with different viewpoints who have followed their vision. I personally don't think Python+macros sounds very interesting, but as long as there's no confusion between that and Python, it's no problem as far as I'm concerned. Donn Cave, donn at u.washington.edu From newsgroups at jhrothjr.com Sun Aug 24 20:31:39 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Sun, 24 Aug 2003 20:31:39 -0400 Subject: python gripes survey References: Message-ID: "Ryan Lowe" wrote in message news:ex42b.177723$_R5.67051940 at news4.srv.hcvlny.cv.net... > "Dave Brueck" wrote in message > news:mailman.1061701097.12913.python-list at python.org... > > Here's a short list of my anti-gripes - features that I like but some > people complain about; > > features that, if removed or changed too much, would make me like Python > > less: > > > > - no assignment in if/while > > - whitespace significant to both programmer and the language > > - {} + {} not allowed ;-) > > - private variables are a language-encouraged convention instead of an > attempt > > to babysit the programmer > > - no macros > > - no end-block tag required > > - list comprehensions > > - a "self" parameter is passed to all class methods, and by convention we > all > > call it "self" > > - tendency to prefer keywords over special characters > > - thread-safe operations on fundamental objects (e.g. two threads doing > > somedict['foo'] = x at the same time won't cause Python to crash or > corrupot > > somdict) > > - list.sort() doesn't return the sorted list > > > > There are more, but this list is just off the top of my head. :) > > -Dave > > > id agree with most of those too. i hadnt really thought about the sort() > function, but that does seem a little inconsistent with other methods which > do return a value. im sure there is a good reason for this (speed?). It's because .sort modifies the list in place. All of the list functions that do this return None instead of the modified list. The reason is to baby-sit the programmer: Guido thought that if these methods returned the list, people would think that the original, unmodified list still existed soemwhere. As far as I'm concerned, it's a wart. Ruby (IMO) deals with this issue better. John Roth > > > > From news at yebu.de Tue Aug 5 04:53:31 2003 From: news at yebu.de (Karl Scalet) Date: Tue, 05 Aug 2003 10:53:31 +0200 Subject: ANN: Snakelets 1.1 (simple-to-use web app server with dynamic pages) In-Reply-To: <3f2ea0a0$0$49110$e4fe514c@news.xs4all.nl> References: <3f2ea0a0$0$49110$e4fe514c@news.xs4all.nl> Message-ID: Irmen de Jong schrieb: > I'm happy to say that Snakelets 1.1 is now available. > > Snakelets is a simple Python web application server, ... Hi Irmen, is there any support for cgi built into? Karl From eric at vanrietpaap.com Wed Aug 6 07:12:21 2003 From: eric at vanrietpaap.com (Eric van Riet Paap) Date: Wed, 06 Aug 2003 13:12:21 +0200 Subject: round(22.47,2) gives 22.469999999999999? Message-ID: <3f30e294$0$125$e4fe514c@dreader5.news.xs4all.nl> Hi, On python2.1.3, python2.2.1 and python2.2.3 round(22.47,2) gives 22.469999999999999 . Does anyone know if this is a bug or some weird, yet unexpected, behaviour? P.S. I haven't tested python2.3, but python1.5.2 doesn't have this problem. From op73418 at mail.telepac.pt Thu Aug 28 10:15:23 2003 From: op73418 at mail.telepac.pt (Gonçalo Rodrigues) Date: Thu, 28 Aug 2003 15:15:23 +0100 Subject: python gripes survey References: <78kkkvg8ckfio141es2of1p483ohbtbit5@4ax.com> Message-ID: On Mon, 25 Aug 2003 18:14:30 GMT, Afanasiy wrote: >On Sat, 23 Aug 2003 15:39:27 GMT, "Ryan Lowe" wrote: > >>python is a big improvement on most languages that came before it, but no >>language is perfect. id like to make a list of some of the aspects people >>find most annoying, regardless of their feasibility of implementation. for >>instance, i discussed putting if clauses in for loops, and i noticed another >>thread about allowing {} and [] to be added and subtracted. if its something >>from another language (especially an obscure one), please explain how it >>works in case people like myself dont know the language. >> >>thanks, >>ryan >> > >I have a bunch, many of them hard to define, but one that I just thought >of I find strange sometimes is the use of tuples as near-mystery return >values. I can't help but thinking a C struct with named fields is easier >to remember than a tuple with fields accessed by integer. > >Sure you can return an associative array, but in my experience the >preference is to return a tuple. I'll probably get flamed for saying so, >but this is how I feel and it is unavoidable. Returning a struct in C is >easier to deal with than returning a near-mystery tuple in Python. Look up my recipe in the ActiveState cookbook: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/218485 With my best regards, G. Rodrigues From pinard at iro.umontreal.ca Thu Aug 21 12:04:25 2003 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois_Pinard?=) Date: 21 Aug 2003 12:04:25 -0400 Subject: open.read In-Reply-To: <200308211438.38899.aleaxit@yahoo.com> References: <200308211438.38899.aleaxit@yahoo.com> Message-ID: [Alex Martelli] > > In more recent versions of Python, the `open' built in function has been > > replaced by the `file' built in constructor, and `open' has been made an > > alias for `file', so the above may more adequately be written: > > > > stuff = file("filename", "r").read() > Except that, since open is an alias (and NOT deprecated), it's exactly > equivalent (IMHO) which name you choose to use. If open ever DOES > get deprecated (perhaps in 3.0, some years from now) that may change. We are not speaking of `open' deprecation. When I write "the above may more adequately be written", one should not read "the above must be written". > In terms of the definition of the Python *language*, the "own destructor" > will run whenever it pleases; thus, it's CONCEIVABLE that (in some > perfectly valid and correct implementations of the Python language) the > file's closing is delayed all the way to the end of the program. Yes. For as far as Python is concerned, this is unlikely, and much more unlikely than conceivable. So, in practice, there is no problem. > you're relying on an IMPLEMENTATION detail [...] This is related to the implementation, yes. But this is more than a detail. The timely finalisation is deeply built in Python, _that_ Python maintained by Guido and team, and which most of us use and will continue to use for years. This implementation feature is a worth one: it allows for compact, clear, legible and _dependable_ writings. Moreover, this is unlikely to change before we all die, at which point the matter is less important for us. I'm fully happy taking advantage of it, in the meantime. And many do! > Or PyPy, or some future implementation of Python for dotNET, or perhaps > some optimizer such as psyco if it uses the semantic freedom the language > definition so explicitly grants it to speed programs up by > delaying/bunching up destructor-calls [...] If this ever happens, there will be a game between developers and users, either developers will acknowledge what users do, or they will loose some of them. I'm not going to live in fear of such games. I favour legibility in the meantime. If I ever have, one of these days, to convert myself to the idea of cluttering my code, I'll do. But there is no reason to suffer now. There is a great probability that I'll never have to undergo conversions. > PROGRAM TO AN INTERFACE, NOT TO AN IMPLEMENTATION is a wonderful, indeed > crucial principle. I consider that timely finalisation in the Python we use is part of its interface. If undocumented, this is a politeness from Guido to Barry. > But it breeds bad habits that may easily trip you when the time comes to > write huge applications that will last a long time and end up using other > implementations of the same language. People using Jython will not preclude themselves from using Java facilities, despite these are not available for Python, and Jython documents some of its own features as "Python made right". There is also a lag between Python development and Jython development, which in general, does not get in the way of people using features from the latest Python releases. People using Python on Windows allow themselves COM interfaces in their big applications. What I mean is that, for any huge application, changing implementations, systems, or about anything, is asking for trouble and careful revision anyway. People know how to make reasonable compromises between purity and practicality, and put limits to their stumbling on the carpet flowers. Python should be regarded as a practical language, and indeed, it is. > Alex You might hardly believe it, but I'm a purist and idealist as well. Python gives me a lot of latitude for exploring my own idealism, so I'm fulfilled by Python in that respect. Yet, Python is also giving me the opportunity to relax somehow, aiming simple and legible code. I choose to do not fear this relaxing pleasure, even for "serious" work. It's a nice world, isn't it? -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From tjreedy at udel.edu Tue Aug 5 16:12:01 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 5 Aug 2003 16:12:01 -0400 Subject: (VERY) New to Python. Need Help! References: Message-ID: "Don Bruder" wrote in message news:beLXa.8574$dk4.365557 at typhoon.sonic.net... > Any indication of whether there's a "getpid" function in the Carbon > version of MacPython? And how would I go about checking to see (aside > from the obvious "fire up the program - if it pukes, the function isn't > there") if an arbitrarily selected function is available in a particular > Python implementation? In the installation directory is a subdirectly Lib (at least for *nix, windows versions, don't know if mac is same). In that directory is a file called os.py which, when imported, becomes the os module. In that file are a number of definitions. Your BT program, by including >>> from os import getpid, path, makedirs is looking for those three particular names. So you could look thru the file to see if they are there. Running the program seems easier ;-), although looking will verify that os.py, path, and makedirs *are* present (and getpid present or not). If so, you could verify the that absence of getpid is exactly the problem by deleting it from import list and adding as the next line print 'got here'; raise SystemExit Terry J. Reedy From aleax at aleax.it Mon Aug 4 09:09:21 2003 From: aleax at aleax.it (Alex Martelli) Date: Mon, 04 Aug 2003 13:09:21 GMT Subject: Python speed vs csharp References: <1h5f2rzthqgid.8watonaa4cjt.dlg@40tude.net> <3F551D29.1040407@kfunigraz.ac.at> <0MoXa.21930$cl3.850221@news2.tin.it> <3F55B1CE.5010607@kfunigraz.ac.at> <3F55D7F1.5020804@kfunigraz.ac.at> Message-ID: <5WsXa.25370$cl3.908732@news2.tin.it> Siegfried Gonzi wrote: ... > Maybe you cannot read. But I wrote in my first post that I blindly "copy > and pasted" the original code and that I didn't check wehter (* x x) is > faster. This was not the point. I can read better than you can write (a criterion that is not hard to meet). You used neither the phrase "copy and paste" NOR the adverb "blindy" in your "first post" (to this thread) -- liar. What you wrote was quite different and "bigloo-specific": """ The Bigloo code could be a bit improved because I do not know wheter using (expn x 2.0) introduces a bottleneck in Bigloo. If there are only """ Apart from your creative innovation in mis-spellings of the poor innocent word "whether", it's clear that you do not know whether raising-to-the- power-of-two is importantly slower than multiplying-by-itself in just about ANY programming language -- what I keep pointing out is that the _C_ code would surely be improved by this tiny change (it speeds up by JUST two times on my machine... trifles, surely...?). This shows you're not an experienced coder of numerically intensive codes, period. > Again, my intention simply was: there is more than just Python. People, Nobody ever denied that. Python's own interpreter is coded in C (though in the pypy project we're trying to do something about that;-), so it's obvious to everybody that "there is more than just Python". Python just happens to be the best overall choice for application-level programming (as opposed to, say, operating system kernels, device drivers, and the like) in most situations. This fact stands in sharp contrast to your previous idiotic assertion that "it's crap" (currently softened to "there is more than just it", I see) -- interestingly accompanied in your own previous posts by the contradictory assertion that "it's okay" (if, that is, one is pragmatic). > if their time budget allows it, should investigate those alternatives. > If they think Scheme is shit oh Lord nobody cares and nobody will impede > them in going/comming back to Python. If they have nothing better to do with their time, investigating a huge variety of programming languages surely does appear a neat idea to me (but then, like many other computer enthusiasts, I do like programming languages for their own sake -- most users consider learning such tools a price to be paid in order to be able to solve their problems, so their evaluation of your suggestion may differ from mine). In the galaxy of programming languages, Scheme is definitely an interesting one (the "stalin" compiler, back when I last tried several extensively, seemed even faster than the "bigloo" one, but the underlying language is still Scheme in both cases), particularly thanks to the excellent book "SICP" (now freely available on the net, and very, very instructive). But if you do want to suggest to people that they explore other alternatives, you'll find out that starting out by describing their current choice as "crap" is definitely not the best way to "make friends and influence people". Your skill at that appears to match that at numerically intensive programming, spelling, and other fields already mentioned. > Sorry, Alex you are one of the idiots and bigots who believe that Python > is the best since sliced bred and butter. Assuming "bred" is meant to stand for "bread" (rather than being the past form of the verb "to breed", which is what one might normally assume;-) -- I don't particularly care for pre-sliced bread, nor for putting butter on my bread (I'm Italian, remember?). I do believe that Python is currently the best alternative for application-level programming, but you have not shown any support for your insults against me on this score (nor for just about any of your assertions). I know Scheme (and many dozens of other languages), and use the most appropriate one for each task -- these days, my opinion (supported by very substantial evidence) is that Python happens to be the most appropriate language for most tasks I tackle (except that C keeps being preferable in several cases, when I work on lower-level code). Since my choices are (obviously -- I'm an engineer!) "pragmatic" ones (i.e., ones oriented to get the best results IN PRACTICE), then by your own previous admission my choice is OK. So how can that choice, by itself, identify me as an idiot and a bigot? Thus, your insults are not just unjustified and unsupported -- they're actually self-contradictory with respect to other recent assertions of yours. In other words, you keep justifying and reinforcing my opinion that you're a sad travesty of a human being. > When I was younger it happend that I was a similar idiot and believed > that "functional programming" in all its glory will salvage this world. Oh, and were you convinced you could spell, too? Functional Programming is a very neat mental toy, and maybe one day I'll come upon a real-world reason to USE it for production code. I'm not holding my breath, though. My opinion that Python is the best currently available language for most tasks isn't based on some kind of preconceived evaluation: it's based on real-world experience over a huge variety of programming tasks, which I have, over the decades, tackled using a similarly huge variety of languages, in some cases by myself, in most cases as a part of a team of programmers. I've seen excellent programmers just fail to GET such (intrinsically excellent) languages as Lisp and Scheme variants of all sorts, Prolog and its ilk, functional programming languages -- try and fail to get any real productivity with them. I've seen excellent programmers dive head-first into complex higher-level languages such as Perl, and come up with huge masses of unmaintainable code. SOME people can no doubt make very effective use of each and every one of these tools, but experience has shown me that they just don't generalize well. For other higher level languages, such as Rexx, Icon, Python, and Ruby, my experience suggests instead that programmers (including both experienced ones and ones with less experience) tend to become very productive with them, very fast, and write good code, suitable for team-work and maintenance. Out of these, Python is currently my choice (and Ruby a close second, but there are aspects of Ruby -- signally its "dynamic-all-the-way" nature -- that suggests to me that, while it may be even better than Python for such purposes as "tinkering", it's intrinsically inferior for the purpose of building very large and complex system which will need to be maintained for many years by a large variety of people) -- in part for pragmatical reasons, and I see nothing shameful in that. > For me Python is crap and not any longer worth to consider. But look, I If so, then hanging out on this newsgroup shows your ability to manage your own time in doing things of interest to you is on a par with the several other intellectual skills we've already mentioned. > even introduced Python at our institution some month ago. A colleague If you DO think it's crap, as you repeatedly said, then such behavior is inexcusable -- you deliberately _damaged_ your "institution" (once a common euphemism for "mental hospital", you know...) by introducing there what you consider "crap". Again, the amount of internal contradiction in your posts is either laughable or very, very sad, depending on one's viewpoint. > asked me and I showed him Scheme. He didn't like the parantheses and I > adviced him to buy some Python books. Indeed he did it. What is > important here: he is happy that I am not any of this idiots who falls > for and believes that his own programming language is the best thing. Python is not "my own" programming language (if anybody's, it's Guido van Rossum's) -- it's simply the one I currently consider as the best available for most production tasks in application development. I, in turn, have repeatedly advised (note the correct spelling) people who came to this newsgroup in order to ask for changes to Python, to take up other languages instead (e.g., Scheme, Dylan, or Common Lisp, if they're *really* keen to have powerful macros in their language). The difference, of course, is that I do not consider such languages to be "crap", as you have stated about Python -- I would not damage another human being by suggesting he use something I consider to be "crap". > I will stop this discussion because I am used to discuss with people who > can demonstrate to have at least a minimal amount of brain. We'll see if you're a liar once again (wouldn't be surprising, considering the amount of lies we've already seen in a few posts of yours) or if for once you keep your word. Your stated reason for "stopping this discussion", of course, doesn't hold water -- you've already repeatedly (if grudgingly) conceded some of my points (indeed, you've explicitly said you thought one of my posts would be useful to others) and therefore you've already, unwittingly to be sure!, demonstrated that you admit I do have "at least a minimal amount of brain". But so what -- lies, obfuscation, muddled thinking, insults, confusion, self-contradition -- I've seen nothing but that in your posts; you appear to think as well as you spell, which IS saying something. So long (hopefully)... Alex From maoy_REMOVE_IF_NOT_SPAM at cis.upenn.edu Thu Aug 14 00:11:31 2003 From: maoy_REMOVE_IF_NOT_SPAM at cis.upenn.edu (Yun Mao) Date: Thu, 14 Aug 2003 00:11:31 -0400 Subject: Non blocking tty I/O References: <1104_1060829342@news-server.optonline.net> Message-ID: You may want to use select to test if the bits are available or not. http://www.python.org/doc/current/lib/module-select.html Yun "Mike solem" wrote in message news:1104_1060829342 at news-server.optonline.net... > I'm reading data from the comport on linux, using 'read(1)'. This blocks until it gets a byte. How can I get it to not block, so that it doesn't hang forever waiting for a byte. > > Mike > > > From skip at pobox.com Wed Aug 20 13:53:35 2003 From: skip at pobox.com (Skip Montanaro) Date: Wed, 20 Aug 2003 12:53:35 -0500 Subject: Newbie Variable Substitution Question In-Reply-To: References: Message-ID: <16195.46495.941374.52324@montanaro.dyndns.org> ckrieg> for c in range(1, 3): ckrieg> print "%(c)s %(1)s" % (locals(), dict01) ckrieg> Results in an error: TypeError: format requires a mapping ckrieg> Why doesn't the second loop work? It seems to be a cleaner way ckrieg> of doing this. Am I missing something? The right-hand argument to the % operator is a tuple of dictionaries, not a dictionary. Try something like this instead: class MultiDict(dict): def __init__(self, *args): self._dicts = args def __getitem__(self, key): for d in self._dicts: try: return d[key] except KeyError: pass raise KeyError, key def has_key(self, key): for d in self._dicts: if key in d: return True return False dict01 = { '1': 'a', '2': 'b' } for c in range(1, 3): print "%(c)s %(1)s" % MultiDict(locals(), dict01) From davidhe at email.com Wed Aug 6 08:36:18 2003 From: davidhe at email.com (Dave) Date: 6 Aug 2003 05:36:18 -0700 Subject: I was blind! Message-ID: To substring in Python: >>> name="Notlob" >>> print name[3:5] lo Cooler than I could imagine... From newsgroups at jhrothjr.com Fri Aug 1 06:55:22 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Fri, 1 Aug 2003 06:55:22 -0400 Subject: time, calendar, datetime, etc References: <153fa67.0307300326.45a29380@posting.google.com> <1sScnW0Sv7DzrrSiRTvUpQ@speakeasy.net> Message-ID: "Andrew Dalke" wrote in message news:bgcr5a$8ac$1 at slb9.atl.mindspring.net... > John Roth: > > I also wonder why anyone made the choice to set the year origin at > > 1AD? That decision, by itself, makes it almost unusable for my hobby > > (astrological software, which is basically astronomical software > > with a different focus.) Astronomical dates are always measured > > in days since 4700 and something BC. > > Well, if you're doing astronomical time, wouldn't you just add 4700 > and something years and 12 hours (as I recall, astronomers have a > 12 hours offset because they observe at night and don't want to have > to change the date (or forget to change the date) part way though.) > How is that unusable? Because I need to be able to deal with BC dates, obviously. Fudging the base date won't handle that. > Why would supporing you be reasonable to the other 99+% of the > users who don't care about doing astronomical measurements, nor > even about the "was there a year 0?" debate. Mostly because I don't see a particular reason for the actual decision tha was reached. > And as for unusable, bah. The nuances of time are very sublte. > Ivan Van Laningham at the Houston conference ('98, I think) gave > a paper on using Python for the Mayan calendar. Even if Python > were to use astronomical time as its basis, that code wouldn't handle > his needs - eg, he wanted to know when the Mayan calendar repeats > itself. Answer? Once every > 2549465048574470321568539870223503965392934390771449170872386445565969718817 > 5919250180245133376000 > years. His paper is at > http://www.foretec.com/python/workshops/1998-11/proceedings/papers/laningham > /laningham.html > and it was a very enjoyable talk. There are a number of "Mayan" calendars; it's a very complicated subject. I had no objection to using the proleptic Gregorian calendar for display: you have to use something, and that's almost universally used. If you do any kind of historical research, you suddenly discover that what you thought you knew about dates doesn't work in practice, even in Western Europe. This is why astronomical dating is important: it provides a single, well understood and accepted dating system that can be tied to the (unfortunatelly rare) comments about astronomical phenomena, and it goes back far enough that all dates of historical interest are positive numbers. > > For another example, to be really precise, a datetime module needs > to support leap seconds, so that "23:59:60" is, at times, valid. But > Python's datetime module doesn't allow that. Usually, that's handled by a separate conversion from UT (Universal Time) to ET (Ephemeris time.) And leap seconds are a modern innovation: for accuracy there are a number of correction formulae that you apply depending on the exact historical era in question. > > And if it did, it would almost certainly break code written by people > who didn't know there could be 61 seconds in a minute. Funny about that: the Unix system specifications that I've seen have always said that there may be 61 seconds in a minute. It's built into the API. > So in summary, almost no one needs the functionality beyond what > the standard library has, supporting each and every specialized niche > makes for more complex code, and more complex code means people > who do "normal" programming are much more likely to run into problems > and make the code more likely to break. Andrew, you've brought in an army of straw men. The **ONLY** thing I was criticising was the decision to limit the module to dates beginning with 1 AD. All the other things you bring up are things that I either don't care about, or that I agree shouldn't complicate the API. John Roth > > Andrew > dalke at dalkescientific.com > > From theller at python.net Wed Aug 6 14:36:20 2003 From: theller at python.net (Thomas Heller) Date: Wed, 06 Aug 2003 20:36:20 +0200 Subject: crossplatform py2exe - would it be useful? Message-ID: I'm currently working on a new version of py2exe, which will require Python 2.3 and later, because it uses the zipimport mechanism. Since py2exe is a distutils extension, and since C compilers are commonly available on most platforms except Windows, it would be fairly easy to let py2exe generate a C source file installing this import hook, and let distutils' C compiler build an executable file from this. Would this be useful, or would I be wasting my time, since McMillan installer, cx_freeze, and tools/freeze already do it? At the end of this post you'll find excerpts from the readme file, which is currently the only documentation available. Thomas The readme file: A new and improved py2exe for Python 2.3 ======================================== Uses the zipimport mechanism, so it requires Python 2.3 or later. The zipimport mechanism is able to handle the early imports of the warnings and also the encodings module which is done by Python. Creates a single directory, which must be deployed completely. (Most of this is based on ideas of Mark Hammond:) Can create any number of console and gui executables in this directory, plus optionally a windows service exe, plus optionally an exe and dll com server. The com servers can expose one or more com object classes. All pure Python files are contained in a single zip archive, which is shared by all the executables. The zip archive may also be used by programs embedding Python. Since extension modules cannot be imported from zipfiles, a simple pure Python loader is included in the zipfile which loads the extension from the file system (without requiring that the directory is in sys.path). It would be nice if the executables could be run with only a single sys.path entry containing the absolute filename of the zipfile, but it seems for dll com servers the executable's directory is also needed. The absolute filenames are constructed at runtime from the directory containing the executable, and the zipfile name specified at build time. The way has changed how build targets are specified in the setup script. py2exe installs it own Distribution subclass, which enables additional keyword arguments to the setup function: console = [...] # list of scripts to convert into console executables windows = [...] # list of scripts to convert into gui executables com_servers = [...] # list of fully qualified class names to build into the exe com server service = [...] # list of fully qualified class names to build into a service executable zipfile = "xxx.zip" # filename of the zipfile containing the pure Python modules All of the above arguments are optional. The zipfile name defaults to 'library.zip'. From hancock at anansispaceworks.com Fri Aug 22 09:47:08 2003 From: hancock at anansispaceworks.com (Terry Hancock) Date: Fri, 22 Aug 2003 08:47:08 -0500 Subject: crazy programming language thoughts References: <-5SdnWETctL179iiU-KYgw@giganews.com> Message-ID: <3PKdnXyDgbmng9uiXTWJiA@august.net> Istvan Albert wrote: > Ryan Lowe wrote: > >>>>v = read lines from 'file.txt'; > join it with '\n'; lower it; split it at '.' > > split line at '\n' is no better than line.split("\n") > after all then you could argue that you should be > able to say "'\n' is the splitting character in line" or > "break into pieces at '\n'" and so on. Yeah, I think this is ultimately the problem with "English-like" syntax. The fact that Python's syntax (one of many examples) is more like mathematical notation is a cue to both the author and the reader that a more exacting attention to syntax is required. Maybe this is what they really meant by "one obvious way to do it" versus "there's more than one way to do it": in English there are many -- maybe infinitely many -- ways to say essentially the same thing. But a parser that could understand them all would pass the Turing Test and want a paycheck. ;-) Of course, it is interesting to note that it is the *author* who primarily needs this cue. The *reader* benefits from using English words instead of abstract symbols. So perhaps this is why Python's mix of syntax works well -- not too hard to write, and not too hard to read. I'm not even going to speculate about whether it is the best such mix. ;-) The main language I use that resembles the "English" style is SQL: SELECT * FROM table_a WHERE field_b LIKE '.*[abc][def]' and while I find SQL very useful in its limited application domain, I wouldn't really want to turn it into a real programming language*! Cheers, Terry *By which I meant "Turing Complete" and nothing else. And no value judgements whatsoever. :lol: -- Terry Hancock Anansi Spaceworks http://www.AnansiSpaceworks.com/ From koenig at v-i-t.de Fri Aug 22 15:27:13 2003 From: koenig at v-i-t.de (Mirko Koenig) Date: Fri, 22 Aug 2003 21:27:13 +0200 Subject: wxPython: need return value from wxFrame References: Message-ID: On Fri, 22 Aug 2003 00:28:23 +0200, Cliff Wells wrote: > On Thu, 2003-08-21 at 15:17, Mirko Koenig wrote: >> I have a frame where you can select/add/delte etc a customer address. >> It is included in an wxApp to have a stand alone customer addressbook. >> >> Now i wrote a invoice application. I added a button to add a address to >> the invoice. I want the customer addressbook to be open by clicking on >> that button. No problem. So far so good. >> >> But i want the addressbook frame to return the selected address as a >> tuple, list or dict. I don't have any idea how to do that. >> >> I can show() the frame from within the invoice code but show doesn't >> return a value. > > Use a wxDialog instead. > But how to return a list or tuple. All i can see is that a dialog returns a int value Mirko Koenig From mpeuser at web.de Thu Aug 14 16:38:28 2003 From: mpeuser at web.de (Michael Peuser) Date: Thu, 14 Aug 2003 22:38:28 +0200 Subject: Iterator - what I am missing References: <3f3bde30$0$297$ba620e4c@reader1.news.skynet.be> Message-ID: Hi Helmut, the information you give is *very* imcomplete ;-) Probably the *next* method is in the wrong class (Node instead of Queue). But one can only help with the full code of both classes... Have you considered using the new generators? They are not as new (from __future__ import generators) if you will not use Python 2.3. They make iterators much more transparent! Kindly Michael P "Helmut Jarausch" schrieb im Newsbeitrag news:3f3bde30$0$297$ba620e4c at reader1.news.skynet.be... > Hi, > > I cannot find out what I miss with my iterator example. > > I have a linked list class Queue which has a 'Head' attribute > and the following > > def __iter__(self): > if self.Head == None: raise StopIteration > return self.Head > > The elements of the list are of class Node > > which has a 'NNd' (next Node) attribute and > a next method > > def next(self): > N= self.NNd > if N == None: raise StopIteration > return N > > Now when I try to iterate over all elements of the > Queue like in (MyQ is an instance of class Queue) > > for N in MyQ: > print "loop->",N > print N.key,N.data > > I get an infinite loop and 'N' always refers to the first > element of the MyQ as initialized by MyQ.__iter__ > > I've checked 'MyQ' and it contains 2 elements and 'NNd' > attribute of the last one is 'None' > > So what's going on here? > > Many thanks for a hint, > > Helmut Jarausch > > Lehrstuhl fuer Numerische Mathematik > RWTH - Aachen University > D 52056 Aachen, Germany > From adalke at mindspring.com Fri Aug 22 00:47:44 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Fri, 22 Aug 2003 04:47:44 GMT Subject: What's better about Ruby than Python? References: <3F41505F.69D18CC8@alcyone.com> <66d7kvonvb2n0nqbqahhd5roak7ur81sob@4ax.com> <3f43ef5d_4@127.0.0.1> <3F440A35.9030602@nyc.rr.com> <4o_0b.1665$Ej6.1182@newsread4.news.pas.earthlink.net> <8D01b.1721$Ej6.702@newsread4.news.pas.earthlink.net> <3F44ED2E.9070308@nyc.rr.com> <0V61b.1900$Ej6.1012@newsread4.news.pas.earthlink.net> <3F4504D7.20008@nyc.rr.com> Message-ID: Kenny Tilton: > Lisp is sick. From the hyperspec on make-hash-table, the test for > lookups can be "eq, eql, equal, or equalp. The default is eql." EQUAL > would work for this case. EQL just looks at object identity. Given the mutability in the structure, how is the hash key generated? > No, to match the power of my code you need to do: > > (let ((b (make-instance 'box > :left 10 > :right (c? (* 2 (left self))))) > (print (list (left b) (right b))) Again, I don't know enough Lisp to follow what you are saying. > Download Paul Graham's On Lisp, he has a macro in there that hides all > the plumbing you used for cacheing. :) Look for "Memoize". As I pointed elsewhere, I tried a couple times to learn Lisp, if only to figure out how to tweak Emacs. I never succeeded. Perhaps for the same reason I never liked HP's stack oriented calculators? And yes, Dylan's another language on my 'should learn more about' because of its in-fix approach to Lisp-style programming. > The bestest I could do without macros would be: > > (make-instance 'box > :left (c? (lambda (self) > (+ 2 (right a))) > .... Which implies Python's object model and Lisps are different, because my code requires but one change per method, just like your macro solution. While macros would be better for this example, for Lisp, it isn't a good example of why a macro system would improve Python's expressability. > The anti-macronistas are better off with the argument, hey, if you want > Lisp, use Lisp. Let's keep it simple here. the question for you all is > how far you want to take Python. But that statement expresses a certain arrogance which grates against at least my ears. The point I've made over and over is that languages which optimize for a single person do not necessarily optimize for a group of people, especially one which is scattered around the world and over years. Given that latter definition, Python is extraordinary advanced, even further than Lisp is. For observational evidence of this, I suggest my own subfields, computational biology and computational chemisty. In the first there are bioperl, biopython, biojava, and bioruby, all with active participants and a yearly confererence organized by open-bio.org. But there is only a rudimentary biolisp project with minimal code available and just about no community involvement. In the latter, Python takes the lead by far over any language other than C/C++/Fortran with commercial support for a couple toolkits and several more free ones beyond that. There's even a workshop in a couple weeks on the representation of biomolecules for Python. There are also some Java and C++ toolkits for chemical informatics. And again, there is no Lisp involvement. I ask you why. And I assert that it's because Lisp as a language does not encourage the sort of code sharing that the languages I mentioned above do. So while it is very expressive for a single person, a single person can only do so much. Andrew dalke at dalkescientific.com From bignose-hates-spam at and-benfinney-does-too.id.au Tue Aug 19 00:58:28 2003 From: bignose-hates-spam at and-benfinney-does-too.id.au (Ben Finney) Date: 19 Aug 2003 14:48:28 +0950 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: <3F41A877.995F9C35@alcyone.com> <3F41B296.BC2CACC0@alcyone.com> Message-ID: On Mon, 18 Aug 2003 22:16:06 -0700, Erik Max Francis wrote: > Ben Finney wrote: >> Seeing second-hand comments (as quoted by others) from people in one's >> killfile is a hazard of Usenet. > > Of course. And it's easily avoided with the tiniest bit of > self-restraint. Uh, no. Seeing them isn't amenable to self-restraint -- you can only exercise that *after* seeing them. -- \ "Consider the daffodil. And while you're doing that, I'll be | `\ over here, looking through your stuff." -- Jack Handey | _o__) | Ben Finney From twomack at chiark.greenend.org.uk Mon Aug 18 01:55:25 2003 From: twomack at chiark.greenend.org.uk (Thomas Womack) Date: 18 Aug 2003 06:55:25 +0100 (BST) Subject: slight csv misbehavior under Windows Message-ID: I'm using the csv module in python 2.3 under Windows XP; it seems that two separate mechanisms try to handle the perverse Windows habit of ending lines with 0d0a, and so writer = csv.writer(file('foo.csv','w')) for i in thing: writer.write(i) produces lines ending 0d0d0a, and when you load this into Excel 97 the data appears double-spaced. Opening the file with 'wb' solves the problem, but it would be lovely were this either fixed or documented; it's rather unintuitive that a file opened with 'wb' still ends lines with 0d0a. Please tell me if this is not the appropriate place to make this kind of bug report. Tom From pedrosch at gazeta.pl Wed Aug 27 10:52:41 2003 From: pedrosch at gazeta.pl (Przemo Drochomirecki) Date: Wed, 27 Aug 2003 16:52:41 +0200 Subject: IDE for Python Message-ID: Hello, does anyone know freeware, nice-looking, easy-to-install with rolling-up-class,def-syntax feature (like in boa, but not boa) Thanks From dakidd at sonic.net Tue Aug 5 03:56:09 2003 From: dakidd at sonic.net (Don Bruder) Date: Tue, 05 Aug 2003 07:56:09 GMT Subject: (VERY) New to Python. Need Help! Message-ID: Greetings, oh scaly ones... :) I'm a Mac user with a fairly high level of computer literacy, including reasonable programming skills in BASIC, C, Pascal, and several flavors of ML, just trying to run a "canned" Python... Uhhh... Program? Script? Module? - Yeesh... I'm such a rookie at Python I'm not even sure of the right terminology to use here... At this point in the game, I'm not actually trying to *DO* anything in Python, I just want to run a program that's written in Python. Specifically, I'm trying to run a P2P package called "BitTorrent". So I've downloaded and installed a package calling itself "MacPython-OS9 2.2.3", which claims to be functional back to MacOS 8.1. (I'm running 8.6) That was fairly painless. Now that I've got it installed, I'm slamming face-first into a brick wall at high velocity - After diddling file types per the docs for MacPython, I double-click the "btdownloadheadless.py" file that the FAQ for BitTorrent says should run for me, and I get a window opening up with this: Python 2.2.3 (#139, Jun 1 2003, 23:11:08) [CW CARBON GUSI2 THREADS GC] on mac Type "copyright", "credits" or "license" for more information. Traceback (most recent call last): File "Megalon City I:Downloads:BitTorrent-3.2.1b:btdownloadheadless.py", line 6, in ? from BitTorrent.download import download File "Megalon City I:Downloads:BitTorrent-3.2.1b:BitTorrent:download.py", line 23, in ? from os import getpid, path, makedirs ImportError: cannot import name getpid and nothing further happens. Looks pretty obvious that something it wants can't be found. At this point in my Python "career", I don't have a freakin' clue what, where to tell it to look for it, or even *HOW* to tell it to look for it! Anybody wanna to throw this newbie a bone? Yes, I realize this is quite vague. Quite frankly, I don't know enough about the language to even properly describe the problem. So can Somebody please lend a hand here? Before you're forced to taunt me a second time! :) (Hey! Quit throwing those tomatoes! The docs said Monty Python references are not only acceptable, but *ENCOURAGED*! :) ) -- Don Bruder - dakidd at sonic.net <--- Preferred Email - unmunged, SpamAssassinated Hate SPAM? See for some seriously great info. I will choose a path that's clear: I will choose Free Will! - N. Peart Fly trap info pages: From clifford.wells at comcast.net Tue Aug 19 01:43:39 2003 From: clifford.wells at comcast.net (Cliff Wells) Date: Mon, 18 Aug 2003 22:43:39 -0700 Subject: Brandon's abrasive style (was Re: What's better about Ruby than Python?) In-Reply-To: References: <38ec68a6.0308172319.431a4fde@posting.google.com> Message-ID: <1061271819.27697.58.camel@devilbox.homelinux.net> On Mon, 2003-08-18 at 21:43, Brandon J. Van Every wrote: > Cliff Wells wrote: > > > > The major problem appears to be your mode of communication. At first > > I took your questions seriously, then I began to think you were > > trolling (and a rather clever troll at that), and finally I've come > > to the conclusion that you're not trolling, rather merely arrogant and > > abrasive. > > Bingo! Guilty as charged. And I get more and more abrasive the more people > call me a troll. As do most people who aren't actually trolling. Quoting the Dalai Lama: Conventional truth, conventional reality is a consensus reality, something that people agree on. Events do not have a reality of their own. All events depend on other events. Nothing (no person) has an independent identity, there is no intrinsic reality. What is called "reality" depends on the context of other factors. While I don't necessarily consider the Dalai Lama an authority on all (or even many) things, I think there is certainly a great amount of truth to this observation. If the majority of people think you are trolling, then, whether you intend to or not, perhaps you are. If you were being truly pragmatic, as you claim, then you must surely realize that offending people with an abrasive approach is counter-productive. Especially when many of those people are central to the Python community. By that I don't mean prolific posting (although that is part of it), but rather the people who have some of the most intimate knowledge of Python and some who actually contribute to its development. You might think that killfiling those people will teach them a lesson (it won't, they could probably care less), but I can guarantee that if you do use Python you will suffer far more than they from missing out on their knowledge of the tool you've chosen. If you post a question regarding actual use of Python (versus rhetorical questions about its utility or future) you have increased your chance of not seeing the answer because you've killfiled the person with the knowledge you are after. > I ask tough questions about Python vs. other languages and platforms. Some > people can't handle it. Maybe they'd handle it if I diplomatically sugar > coated it, but I'm not going to. Things to irritate the "Brandon's a troll" > crowd some more: > > - Python is not a good language for low-level 3D graphics problems. C++ is > better. This is a worthless assertion. I don't think anyone has suggested otherwise, either in any of the threads you've started or at any other time. You did assert it in an earlier thread, but it was apparently in response to nothing. > - Python isn't a rapid prototyping godsend for every problem out there. No, but for many if not most. > - GUI and tools support can end up being more important than language > niceties. Absolutely. This is one of the main reasons languages like Ruby and Haskell aren't in my toolkit. wxRuby appears to be in the pre-alpha stages and wxHaskell doesn't exist at all. And this is just one thing. > - Microsoft C# and .NET are strategic threats to Python's prosperity and > vitality, if not survival. This is certainly arguable. Java certainly hasn't stopped Python's growth. There is little to support this claim other than fear or admiration of Microsoft. > - Pythonistas should consider trying to eat Java's lunch, because they > aren't going to eat Microsoft's lunch. IMHO, Python is set to become the Visual Basic of the open-source world. RedHat uses it for many of its administrative tools and the RH installer. It comes bundled with most open source operating systems. Many open source applications are starting to use Python as an extension and scripting language. Python on Win32 might struggle against MS languages (whatever that means), but as Linux gains mindshare it carries Python with it. It seems MacOSX might also become a "carrier" of Python. > - Ruby has some mindshare among people with knowledge of Python. Certainly. Your questions regarding this were something I had wondered myself but didn't concern myself with due to Ruby's lack of infrastructure (tools and libraries). > - Yet unnamed languages are capable of taking Python's place on the food > chain. As with any other language. Of course languages aren't applications or operating systems. The competition isn't quite the same in this arena. For the most part, it doesn't matter if you write your application in BrandonBasic of which you are the sole user and developer. What matters is how your applications written in this unappreciated language perform. > - You have to promote your language, grow its market share, to prevent that > from happening. Okay, this is where you lose me: why? Why should I care if other people use Python? In my opinion, being in an exclusive group of developers who use what I consider to be superior tools gives me a distinct advantage. Why would I want that to change? I certainly recommend Python to others, but that's just my nice side winning out. If someone irritates me I have no problem recommending Perl or C# to them . > These analyses are called "sanity" in the Windows world. It's Reality On > The Ground. It's really odd to come to a developer community where people > are insular and freak out about these kinds of pronouncements. It makes > Windows people wonder if Python people are capable of industrial relevancy. Probably these same people wondered the same about Linux advocates a few years ago. In a few more years they'll wonder what happened to their beloved behemoth (Windows). > Fortunately, I was pointed to the marketing-python list and I've discovered > that not all Python crowds are the same. Part of the reason people respond to you so violently is because you tend to make unsubstantiated and provocative claims and then accuse people of being "knee-jerk reactionaries" when they dismiss them. > The rest of you: wake up! Smell the Windows! Sorry, I haven't smelled that smell (except incidentally) since 1994 (Slackware 1.0). I expect to be smelling it less and less as time goes on. However, this is a fine example of an unnecessarily inflammatory statement. Regards, Cliff -- I have seen too much, wipe away my eyes -Bauhaus From irmen at -NOSPAM-REMOVETHIS-xs4all.nl Sun Aug 24 17:00:21 2003 From: irmen at -NOSPAM-REMOVETHIS-xs4all.nl (Irmen de Jong) Date: Sun, 24 Aug 2003 23:00:21 +0200 Subject: Comments on my "Python Introduction" slides In-Reply-To: <33803989.0308240644.3090f039@posting.google.com> References: <33803989.0308240000.35b9bf1f@posting.google.com> <33803989.0308240644.3090f039@posting.google.com> Message-ID: <3f492761$0$49117$e4fe514c@news.xs4all.nl> Miki Tebeka wrote: > Should be http://www.cs.bgu.ac.il/~tebeka/pyintro.htm I'm sorry to say this but because the site appears to be made in Powerpoint, and then exported to MSHTML, it sucks in my browser (Mozilla). No cigar. --Irmen From sismex01 at hebmex.com Mon Aug 25 14:42:00 2003 From: sismex01 at hebmex.com (sismex01 at hebmex.com) Date: Mon, 25 Aug 2003 13:42:00 -0500 Subject: python gripes survey Message-ID: [Afanasiy] > Returning a struct in C is > easier to deal with than returning a near-mystery tuple in Python. > You *really* *must* *be* *kidding*. -gustavo Advertencia:La informacion contenida en este mensaje es confidencial y restringida, por lo tanto esta destinada unicamente para el uso de la persona arriba indicada, se le notifica que esta prohibida la difusion de este mensaje. Si ha recibido este mensaje por error, o si hay problemas en la transmision, favor de comunicarse con el remitente. Gracias. From cartermark46 at ukmail.com Thu Aug 14 05:37:46 2003 From: cartermark46 at ukmail.com (Mark Carter) Date: 14 Aug 2003 02:37:46 -0700 Subject: ClientCookie bug Message-ID: I am using Windows 98, python 2.3, ClientCookie 0.4.3a. When I do: import ClientCookie import os c = ClientCookie.MSIECookieJar(delayload=1) c.load_from_registry() I get the response: Traceback (most recent call last): File "C:\My Documents\mycookies.py", line 33, in ? c.load_from_registry() File "C:\PYTHON23\Lib\site-packages\ClientCookie\_MSIECookieJar.py", line 230, in load_from_registry self.load(filename, ignore_discard, ignore_expires) File "C:\PYTHON23\Lib\site-packages\ClientCookie\_MSIECookieJar.py", line 245, in load self._really_load(index, filename, ignore_discard, ignore_expires) File "C:\PYTHON23\Lib\site-packages\ClientCookie\_MSIECookieJar.py", line 258, in _really_load user_name = string.lower(os.environ['USERNAME']) File "C:\PYTHON23\Lib\os.py", line 417, in __getitem__ return self.data[key.upper()] KeyError: 'USERNAME' Basically, it doesn't like USERNAME as an environment variable. From tzot at sil-tec.gr Thu Aug 21 13:39:33 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Thu, 21 Aug 2003 20:39:33 +0300 Subject: Misleading description of [i:j:k] slicing? References: <7h33cfv2az7.fsf@pc150.maths.bris.ac.uk> Message-ID: <8t0akv0ov6k2peg5b92humla84mnhcovu2@4ax.com> On Thu, 21 Aug 2003 17:12:28 GMT, rumours say that Michael Hudson might have written: >> "The slice of s from i to j with step k is defined as the sequence >> of items with index x = i + n*k such that 0 <= n < abs(i-j). [...]" Basically, it's 0 <= n < abs(i-j)//k, right? -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From ofnap at nus.edu.sg Thu Aug 21 03:44:20 2003 From: ofnap at nus.edu.sg (Ajith Prasad) Date: 21 Aug 2003 00:44:20 -0700 Subject: Open MS Excel Spreadsheet with Python References: <221d8dbe.0307160619.2c2943c3@posting.google.com> <221d8dbe.0308150959.b18167c@posting.google.com> Message-ID: <37ee60c8.0308202344.f470d26@posting.google.com> Would it be possible to give a step-by-step guide on how to use the script, ie, what should one do in an interactive Python session to use one or two of the functions in the script? srijit at yahoo.com wrote in message news:<221d8dbe.0308150959.b18167c at posting.google.com>... > Hello Members, > I would like to share the Python-Excel Interface code. > This is based on sample code from Mark Hammond and Andy Robinson's > "Python Programming on Win32" > I use Python 2.3 and Win32all-157 on a Win 98 machine. > I look forward to feedback on how to improve this code. If I get good > response I may think of putting up this code as a Python recipe in > Activestate. > Once again hats off to Mark Hammond for his excellent Win32all > library. > > Regards, > Srijit > > --------------------------------------------------------------------------- > > import win32com.client.dynamic > > class UseExcel(object): > """Python Excel Interface. It provides methods for accessing the > basic functionality of MS Excel 97/2000 from Python. > > This interface uses dynamic dispatch objects. All necessary constants > are embedded in the code. There is no need to run makepy.py. > """ > __slots__ = ("xlapp", "xlbook") > def __init__(self, fileName=None): > """e.g. xlFile = > useExcel("e:\\python23\myfiles\\testExcel1.xls") > """ > self.xlapp = > win32com.client.dynamic.Dispatch("Excel.Application") > if fileName: > self.xlbook = self.xlapp.Workbooks.Open(fileName) > else: > self.xlbook = self.xlapp.Workbooks.Add() > > def save(self, newfileName=None): > if newfilename: > self.xlbook.SaveAs(newfileName) > else: > self.xlbook.Save() > > def close(self): > self.xlbook.Close(SaveChanges=False) > del self.xlapp > > def show(self): > self.xlapp.Visible = True > > def hide(self): > self.xlapp.Visible = False > > def getcell(self, sheet, cellAddress): > """Get value of one cell. > > Description of parameters (self explanatory parameters are not > described): > sheet - name of the excel worksheet > cellAddress - tuple of integers (row, cloumn) or string "ColumnRow" > e.g. (3,4) or "D3" > """ > sht = self.xlbook.Worksheets(sheet) > if (isinstance(cellAddress,str)): > return sht.Range(cellAddress).Value > elif (isinstance(cellAddress,tuple)): > row = cellAddress[0] > col = cellAddress[1] > return sht.Cells(row, col).Value > > def setcell(self, sheet, value, cellAddress, > fontStyle=("Regular",), fontName="Arial", > fontSize=12, fontColor=1): > """Set value of one cell. > > Description of parameters (self explanatory parameters are not > described): > sheet - name of the excel worksheet > value - The cell value. it can be a number, string etc. > cellAddress - tuple of integers (row, cloumn) or string "ColumnRow" > e.g. (3,4) or "D3" > fontStyle - tuple. Combination of Regular, Bold, Italic, Underline > e.g. ("Regular", "Bold", "Italic") > fontColor - ColorIndex. Refer ColorIndex property in Microsoft > Excel Visual Basic Reference > """ > sht = self.xlbook.Worksheets(sheet) > if (isinstance(cellAddress,str)): > sht.Range(cellAddress).Value = value > sht.Range(cellAddress).Font.Size = fontSize > sht.Range(cellAddress).Font.ColorIndex = fontColor > for i, item in enumerate(fontStyle): > if (item.lower() == "bold"): > sht.Range(cellAddress).Font.Bold = True > elif (item.lower() == "italic"): > sht.Range(cellAddress).Font.Italic = True > elif (item.lower() == "underline"): > sht.Range(cellAddress).Font.Underline = True > elif (item.lower() == "regular"): > sht.Range(cellAddress).Font.FontStyle = "Regular" > sht.Range(cellAddress).Font.Name = fontName > elif (isinstance(cellAddress,tuple)): > row = cellAddress[0] > col = cellAddress[1] > sht.Cells(row, col).Value = value > sht.Cells(row, col).Font.FontSize = fontSize > sht.Cells(row, col).Font.ColorIndex = fontColor > for i, item in enumerate(fontStyle): > if (item.lower() == "bold"): > sht.Range(cellAddress).Font.Bold = True > elif (item.lower() == "italic"): > sht.Range(cellAddress).Font.Italic = True > elif (item.lower() == "underline"): > sht.Range(cellAddress).Font.Underline = True > elif (item.lower() == "regular"): > sht.Range(cellAddress).Font.FontStyle = "Regular" > sht.Cells(row, col).Font.Name = fontName > > def getrange(self, sheet, rangeAddress): > """Returns a tuple of tuples from a range of cells. Each tuple > corresponds to a row in excel sheet. > > Description of parameters (self explanatory parameters are not > described): > sheet - name of the excel worksheet > rangeAddress - tuple of integers (row1,col1,row2,col2) or > "cell1Address:cell2Address" > row1,col1 refers to first cell > row2,col2 refers to second cell > e.g. (1,2,5,7) or "B1:G5" > """ > sht = self.xlbook.Worksheets(sheet) > if (isinstance(rangeAddress,str)): > return sht.Range(rangeAddress).Value > elif (isinstance(rangeAddress,tuple)): > row1 = rangeAddress[0] > col1 = rangeAddress[1] > row2 = rangeAddress[2] > col2 = rangeAddress[3] > return sht.Range(sht.Cells(row1, col1), sht.Cells(row2, > col2)).Value > > def setrange(self, sheet, topRow, leftCol, data): > """Sets range of cells with values from data. data is a tuple > of tuples. > Each tuple corresponds to a row in excel sheet. > > Description of parameters (self explanatory parameters are not > described): > sheet - name of the excel worksheet > topRow - row number (integer data type) > leftCol - column number (integer data type) > """ > bottomRow = topRow + len(data) - 1 > rightCol = leftCol + len(data[0]) - 1 > sht = self.xlbook.Worksheets(sheet) > sht.Range(sht.Cells(topRow, leftCol), sht.Cells(bottomRow, > rightCol)).Value = data > return (bottomRow, rightCol) > > def setcellalign(self, sheet, cellAddress, alignment): > """Aligns the contents of the cell. > > Description of parameters (self explanatory parameters are not > described): > sheet - name of the excel worksheet > cellAddress - tuple of integers (row, cloumn) or string "ColumnRow" > e.g. (3,4) or "D3" > alignment - "Left", "Right" or "center" > """ > if (alignment.lower() == "left"): > alignmentValue = 2 > elif ((alignment.lower() == "center") or (alignment.lower() == > "centre")): > alignmentValue = 3 > elif (alignment.lower() == "right"): > alignmentValue = 4 > sht = self.xlbook.Worksheets(sheet) > if (isinstance(cellAddress,str)): > sht.Range(cellAddress).HorizontalAlignment = > alignmentValue > elif (isinstance(cellAddress,tuple)): > row = cellAddress[0] > col = cellAddress[1] > sht.Cells(row, col).HorizontalAlignment = alignmentValue > > def addnewworksheetbefore(self, oldSheet, newSheetName): > """Adds a new excel sheet before the given excel sheet. > > Description of parameters (self explanatory parameters are not > described): > oldSheet - Name of the sheet before which a new sheet should > be inserted > newSheetName - Name of the new sheet > """ > sht = self.xlbook.Worksheets(oldSheet) > self.xlbook.Worksheets.Add(sht).Name = newSheetName > > def addnewworksheetafter(self, oldSheet, newSheetName): > """Adds a new excel sheet after the given excel sheet. > > Description of parameters (self explanatory parameters are not > described): > oldSheet - Name of the sheet after which a new sheet should > be inserted > newSheetName - Name of the new sheet > """ > sht = self.xlbook.Worksheets(oldSheet) > self.xlbook.Worksheets.Add(None,sht).Name = newSheetName > > def insertchart(self, sheet, left, top, width, height): > """Creates a new embedded chart. Returns a ChartObject object. > Refer Add Method(ChartObjects Collection) in Microsoft Excel Visual > Basic Reference. > > Description of parameters (self explanatory parameters are not > described): > sheet - name of the excel worksheet > left, top - The initial coordinates of the new object (in > points), relative to the upper-left corner of cell A1 on a worksheet > or to the upper-left corner of a chart. > width, height - The initial size of the new object, in points. > point - A unit of measurement equal to 1/72 > inch. > """ > sht = self.xlbook.Worksheets(sheet) > return sht.ChartObjects().Add(left, top, width, height) > > def plotdata(self, sheet, dataRanges, chartObject, chartType, > plotBy=None, > categoryLabels=1, seriesLabels=0, > hasLegend=None, title=None, > categoryTitle=None, valueTitle=None, > extraTitle=None): > """Plots data using ChartWizard. For details refer ChartWizard > method in Microsoft Excel Visual Basic Reference. > Before using PlotData method InsertChart method should be used. > > Description of parameters: > sheet - name of the excel worksheet. This name should be same > as that in InsertChart method > dataRanges - tuple of tuples ((topRow, leftCol, bottomRow, > rightCol),). Range of data in excel worksheet to be plotted. > chartObject - Embedded chart object returned by InsertChart method. > chartType - Refer plotType variable for available options. > For remaining parameters refer ChartWizard method in Microsoft Excel > Visual Basic Reference. > """ > sht = self.xlbook.Worksheets(sheet) > if (len(dataRanges) == 1): > topRow, leftCol, bottomRow, rightCol = dataRanges[0] > source = sht.Range(sht.Cells(topRow, leftCol), > sht.Cells(bottomRow, rightCol)) > elif (len(dataRanges) > 1): > topRow, leftCol, bottomRow, rightCol = dataRanges[0] > source = sht.Range(sht.Cells(topRow, leftCol), > sht.Cells(bottomRow, rightCol)) > for count in range(len(dataRanges[1:])): > topRow, leftCol, bottomRow, rightCol = > dataRanges[count+1] > tempSource = sht.Range(sht.Cells(topRow, leftCol), > sht.Cells(bottomRow, rightCol)) > source = self.xlapp.Union(source, tempSource) > plotType = { > "Area" : 1, > "Bar" : 2, > "Column" : 3, > "Line" : 4, > "Pie" : 5, > "Radar" : -4151, > "Scatter" : -4169, > "Combination" : -4111, > "3DArea" : -4098, > "3DBar" : -4099, > "3DColumn" : -4100, > "3DPie" : -4101, > "3DSurface" : -4103, > "Doughnut" : -4120, > "Radar" : -4151, > "Bubble" : 15, > "Surface" : 83, > "Cone" : 3, > "3DAreaStacked" : 78, > "3DColumnStacked" : 55 > } > gallery = plotType[chartType] > format = None > chartObject.Chart.ChartWizard(source, gallery, format, plotBy, > categoryLabels, seriesLabels, hasLegend, title, categoryTitle, > valueTitle, extraTitle) > > def copyrange(self,source, destination): > """Copy range of data from source range in a sheet to > destination range in same sheet or different sheet > > Description of parameters (self explanatory parameters are not > described): > source - tuple (sheet, rangeAddress) > sheet - name of the excel sheet > rangeAddress - "cell1Address:cell2Address" > destination - tuple (sheet, destinationCellAddress) > destinationCellAddress - string "ColumnRow" > """ > sourceSht = self.xlbook.Worksheets(source[0]) > destinationSht = self.xlbook.Worksheets(destination[0]) > sourceSht.Range(source[1]).Copy(destinationSht.Range(destination[1])) > > def copychart(self, sourceChartObject, destination,delete="N"): > """Copy chart from source range in a sheet to destination > range in same sheet or different sheet > > Description of parameters (self explanatory parameters are not > described): > sourceChartObject - Chart object returned by InsertChart method. > destination - tuple (sheet, destinationCellAddress) > sheet - name of the excel > worksheet. > destinationCellAddress - string "ColumnRow" > if sheet is omitted and only > destinationCellAddress is available as string data then same sheet is > assumed. > delete - "Y" or "N". If "Y" the source chart object is > deleted after copy. > So if "Y" copy chart is equivalent to move > chart. > """ > if (isinstance(destination,tuple)): > sourceChartObject.Copy() > sht = self.xlbook.Worksheets(destination[0]) > sht.Paste(sht.Range(destination[1])) > else: > sourceChartObject.Chart.ChartArea.Copy() > destination.Chart.Paste() > if (delete.upper() =="Y"): > sourceChartObject.Delete() > > def hidecolumn(self, sheet, col): > """Hide a column. > > Description of parameters (self explanatory parameters are not > described): > sheet - name of the excel worksheet. > col - column number (integer data) > """ > sht = self.xlbook.Worksheets(sheet) > sht.Columns(col).Hidden = True > > def hiderow(self, sheet, row): > """ Hide a row. > > Description of parameters (self explanatory parameters are not > described): > sheet - name of the excel worksheet. > row - row number (integer data) > """ > sht = self.xlbook.Worksheets(sheet) > sht.Rows(row).Hidden = True > > def excelfunction(self, sheet, range, function): > """Access Microsoft Excel worksheet functions. Refer > WorksheetFunction Object in Microsoft Excel Visual Basic Reference > > Description of parameters (self explanatory parameters are not > described): > sheet - name of the excel worksheet > range - tuple of integers (row1,col1,row2,col2) or > "cell1Address:cell2Address" > row1,col1 refers to first cell > row2,col2 refers to second cell > e.g. (1,2,5,7) or "B1:G5" > For list of functions refer List of Worksheet Functions > Available to Visual Basic in Microsoft Excel Visual Basic Reference > """ > sht = self.xlbook.Worksheets(sheet) > if isinstance(range,str): > xlRange = "(sht.Range(" + "'" + range + "'" + "))" > elif isinstance(range,tuple): > topRow = range[0] > leftColumn = range[1] > bottomRow = range[2] > rightColumn = range[3] > xlRange = "(sht.Range(sht.Cells(topRow, leftColumn), > sht.Cells(bottomRow, rightColumn)))" > xlFunction = "self.xlapp.WorksheetFunction." + function + > xlRange > return eval(xlFunction, globals(), locals()) > > def clearrange(self, sheet, rangeAddress, contents="Y", > format="Y"): > """Clear the contents of a range of cells. > Description of parameters (self explanatory parameters are not > described): > sheet - name of the excel worksheet > rangeAddress - tuple of integers (row1,col1,row2,col2) or > "cell1Address:cell2Address" > row1,col1 refers to first cell > row2,col2 refers to second cell > e.g. (1,2,5,7) or "B1:G5" > contents - "Y" or "N". If "Y" clears the formulas from the > range > format - "Y" or "N". If "Y" clears the formatting of the > object > """ > sht = self.xlbook.Worksheets(sheet) > if (isinstance(rangeAddress,str)): > if (format.upper() == "Y"): > sht.Range(rangeAddress).ClearFormats() > if (contents.upper() == "Y"): > sht.Range(rangeAddress).ClearContents() > elif (isinstance(rangeAddress,tuple)): > row1 = rangeAddress[0] > col1 = rangeAddress[1] > row2 = rangeAddress[2] > col2 = rangeAddress[3] > if (format.upper() == "Y"): > sht.Range(sht.Cells(row1, col1), sht.Cells(row2, > col2)).ClearFormats() > if (contents.upper() == "Y"): > sht.Range(sht.Cells(row1, col1), sht.Cells(row2, > col2)).ClearContents() > > def addcomment(self, sheet, cellAddress, comment=""): > """Add or delete comment to a cell. If parameter comment is > None, delete the comments > > Description of parameters (self explanatory parameters are not > described): > sheet - name of the excel worksheet > cellAddress - tuple of integers (row, cloumn) or string "ColumnRow" > e.g. (3,4) or "D3" > comment - String data. Comment to be added. If None, delete > comments > """ > sht = self.xlbook.Worksheets(sheet) > if (isinstance(cellAddress,str)): > if (comment != None): > sht.Range(cellAddress).AddComment(comment) > else: > sht.Range(cellAddress).ClearComments() > elif (isinstance(cellAddress,tuple)): > row1 = cellAddress[0] > col1 = cellAddress[1] > if (comment != None): > sht.Cells(row1, col1).AddComment(comment) > else: > sht.Cells(row1, col1).ClearComments() > > def excelapp(): > xlFile = UseExcel("e:\\python23\myfiles\\StudentTabulation.xls") > xlFile.show() > xlFile.setcell(sheet="Sheet1", value="Class X Annual > Examination",fontName="Arial", > cellAddress="D1",fontColor=1, > fontStyle=("Bold",), fontSize=16) > xlFile.setcell(sheet="Sheet1", value="Subject : History", > fontName="Arial", > cellAddress="D3",fontColor=1) > data = ( > ("Sl. No." ,"Name of Students", "Roll No.", > "Marks(out of 100)"), > (1 ,"John" ,1020, 52), > (2 ,"Nikhil" ,1021, 75), > (3 ,"Stefen" ,1025, 85), > (4 ,"Thomas" ,1026, 54), > (5 ,"Ali" ,1027, 87), > (6 ,"Sanjay" ,1028, 0) > ) > (bottomRow, rightCol) = xlFile.setrange("Sheet1", 5,2,data) > xlFile.addcomment("sheet1", "C11", "Absent") > chrt1 = xlFile.insertchart("sheet2", 100, 100, 400, 200) > xlFile.plotdata(sheet="sheet1",dataRanges=((6,3,bottomRow,5),), > chartObject=chrt1, > title="Annual Examination : History", plotBy=2, > categoryLabels=1, > seriesLabels=0, chartType="Bar") > #~ xlFile.clearrange("sheet1",(3,2,3,5),"y") > #~ xlFile.addcomment("sheet1", "B4", "Test Comment") > #~ chrt1 = xlFile.insertchart("sheet1", 100, 100, 400, 250) > #~ xlFile.plotdata(sheet="sheet1",dataRange=(4,2,bottomRow, > rightCol), chartObject=chrt1, > #~ title="Test Chart", chartType="Column") > #~ xlFile.copyrange(("sheet1","C3:E3"), ("sheet2", "C3")) > #~ chrt2 = xlFile.insertchart("sheet2", 100, 100, 400, 250) > #~ xlFile.movechart(chrt1,chrt2) > #~ xlFile.copychart(chrt1,("sheet3","D22"), "y") > #~ xlFile.hiderow("sheet1",7) > #~ print xlFile.excelfunction("sheet1", (3,2,3,5), "Min") > #~ print xlFile.getrange("sheet1","A2","C3") > #~ xlFile.setcellfont("sheet1","Regular", "A1") > #~ cellVal1 = xlFile.getcell("sheet1","A1") > #~ xlFile.setcell("sheet1", cellVal1,1,3) > #~ xlFile.setcellfont("sheet1","bold","C1") > #~ xlFile.setcellfont("sheet1","italic",1,3) > #~ xlFile.setcellfont("sheet1","underline",1,3) > #~ xlFile.setcellalign("sheet1","left",1,3) > #~ print xlFile.getrange("sheet1", "D5", "F6") > #~ xlFile.setrange("sheet1", 10,10, > ((45,67),(67,"342"),(88,66.8),(32,77),(3,3))) > #~ xlFile.addnewworksheetafter("sheet1", "Srijit1") > > if (__name__ == "__main__"): > excelapp() > > > --------------------------------------------------------------------------- > > srijit at yahoo.com wrote in message news:<221d8dbe.0307160619.2c2943c3 at posting.google.com>... > > Hi, > > I am working on Python-Excel interface based on the excellent library > > win32com. > > I was planning to put it up as a Python recipe in Activestate. > > Anyway before that I shall personally send you the code after some > > cleanup. It will be good to get an early feedback before I upload it > > in Activestate. > > > > Regards, > > Srijit > > > > "Allison Bailey" wrote in message news:... > > > Hi Folks, > > > > > > I'm a brand new Python programmer, so please point me in the right > > > direction if this is not the best forum for this question.... > > > > > > I would like to open an existing MS Excel spreadsheet and extract > > > information from specific worksheets and cells. > > > > > > I'm not really sure how to get started with this process. > > > I ran the COM Makepy utility from my PythonWin (IDE from ActiveSTate), > > > using Microsoft Excel 10.0 Object Library, then > > > import win32com.client > > > xl = win32com.client.Dispatch("Excel.Application") > > > wb = xl.Workbooks.Open ("c:\\data\\myspreadsheet.xls") > > > > > > Then, I get errors when I try the following: > > > sh = wb.worksheets(1) > > > > > > > > > I think I'm missing something fairly fundamental, but I've googled all > > > over the place and can't seem to find anything very introductory about > > > opening and using data from MS Excel using Python. Any suggestions, > > > including places to get more information are welcome. > > > > > > Also, do I need to run the makepy utility every time I run my script? > > > If so, how would I do it from within my Python program, rather than with > > > the GUI in the IDE? > > > > > > Thanks for your help, > > > > > > Allison > > > > > > > > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > > Allison Bailey > > > TerraLogic GIS, Inc. > > > allisonb at terralogicgis.com > > > 425-673-4495 > > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From urbanlegend at ozemail.com.au Tue Aug 5 12:54:20 2003 From: urbanlegend at ozemail.com.au (M Wells) Date: Wed, 06 Aug 2003 02:54:20 +1000 Subject: Unable to run IDLE from 2.3? Message-ID: <1akviv4cpectdogklmuupg7rc37lhe1pc7@4ax.com> Hi all, I recently downloaded and installed Python 2.3 for Windows (on XP professional) and I don't seem to be able to run IDLE from my start menu? It seems something happens when I click on it (ie I get an hourglass) but no actual application turns up. Has anyone else experienced this and can anyone give me some advice on how to fix it? Much warmth, Murray http://www.planetthoughtful.org Building a thoughtful planet, one snide comment at a time... From zhoney at wildmail.com Mon Aug 25 13:03:17 2003 From: zhoney at wildmail.com (Zora Honey) Date: Mon, 25 Aug 2003 12:03:17 -0500 Subject: Help embedding python Message-ID: My husband and I are writing a program that does a lot of math behind the scenes (c++) with a gui front (python/Tkinter). We've decided that we want the c++ to be the "driver", and so we want to embed the python. We are not stupid people, and we've already searched this newsgroup and the web at large for help, but we're having a heck of a time trying to do this. We're using Python 2.2 and Mark Lutz' "Programming Python" as a guide. Unfortunately, the code in there is a little out of date (loading certain libraries), and we haven't been able to get any examples to work (we even tried downloading the version he uses in the book, but it fails on the build). So I'm wondering if someone out there has, or would be kind enough to create, a very simple ("hello world" type) program with Makefile that works under 2.2. I will be very grateful, as it is my job to do the graphics, so if I can't get python working, I'll have to learn another language... Thanks, Zora From adalke at mindspring.com Sat Aug 23 23:41:28 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Sun, 24 Aug 2003 03:41:28 GMT Subject: Double symlinking breaks module import References: Message-ID: Csaba Henk: > But > if I create another symlink myprog3.py -> myprog2.py, and then I invoke > myprog3.py, I get compliances that mymod is not found. > > Is it a bug or policy? Python uses the normal file open functions, which automatically follow links. It doesn't build in the link following code itself. I suspect your symlink points to the wrong place. Can you cat the file? Andrew dalke at dalkescientific.com From peter at engcorp.com Tue Aug 12 07:34:05 2003 From: peter at engcorp.com (Peter Hansen) Date: Tue, 12 Aug 2003 07:34:05 -0400 Subject: Python vs. C# References: <2259b0e2.0308100616.55b651ca@posting.google.com> <3f36af20@shknews01> <0b0hjv4q40mdf3msnur9q4bcih3tqb8iq3@4ax.com> Message-ID: <3F38D0AD.62CB11BF@engcorp.com> "Brandon J. Van Every" wrote: > > Doug Tolton wrote: > > > > I've used C# full time for over two years. Finally I got disgusted > > with it and swtiched my entire company over to Python. > > > > Python: > > -Internally consistent, cleanly designed, to the point of being > > beautiful > > -Dynamic typing is amazing > > -First class functions (try mimicking that in C# - ha) > > -Tuple unpacking is a god send > > -List types are the cats meow > > -Dictionaries are blazingly fast > > -using metaclasses and the magic methods gives you amazing power and > > flexibility > > (this is just the beginning of a long list) > > In your "Python pros" list, you didn't name any kind of Windows system > interface component at all. What kind of Python development on Windows are > you actually doing? Use either ctypes or the win32all stuff... works nicely. From gerryandsharon at sympatico.ca Mon Aug 25 22:07:04 2003 From: gerryandsharon at sympatico.ca (Gerry Sutton) Date: Mon, 25 Aug 2003 22:07:04 -0400 Subject: Python and Smart Cards Message-ID: Does anyone know of any Smarty Card related modules in Python. I looked within the Python community and could not find any Smart Card related code. Or even the words "Python" and "Smart Card" in the same sentence. Seems to me that Python would be a good fit to provide a front end to one or more of the available Smart Card tool kits. I did find a Pearl module and some RUBY stuff that wraps the PCSC interface From cbuck at lantis.de Sun Aug 10 08:21:19 2003 From: cbuck at lantis.de (Christian Buck) Date: 10 Aug 2003 12:21:19 GMT Subject: matching a sentence, greedy up! Message-ID: Hi, i'm writing a regexp that matches complete sentences in a german text, and correctly ignores abbrevations. Here is a very simplified version of it, as soon as it works i could post the complete regexp if anyone is interested (acually 11 kb): [A-Z](?:[^\.\?\!]+|[^a-zA-Z0-9\-_](?:[a-zA-Z0-9\-_]\.|\d+\.|a\.[\s\-]?A \.)){3,}[\.\?\!]+(?!\s[a-z]) As you see i use [] for charsets because i don't want to depend on locales an speed does'nt matter. (i removed german chars in the above example) I do also allow - and _ within a sentence. Ok, this is what i think i should do: [A-Z] - start with an uppercase char. (?: - don't make a group [^\.\?\!]+ - eat everything that does not look like an end | - OR [^a-zA-Z0-9\-_] - accept a non character (?: - followed by ... [a-zA-Z0-9\-_]\. - a char and a dot like 'i.', '1.' (doesnt work!!!) | - OR \d*\. - a number and a dot | - OR z\.[\s\-]?B\. - some common abbrevations (one one here) )){3,} - some times, at least 3 [\.\?\!]+ - this is the end, and should also match '...' (?!\s[a-z]) - not followed by lowercase chars here i a sample script: - snip - import string, re, pre s = 'My text may i. E. look like this: This is the end.' re_satz = re.compile(r'[A-Z](?:[^\.\?\!]+|' r'[^a-zA-Z0-9\-_](?:[a-zA-Z0-9\-_]\.|' r'\d+\.|a\.[\s\-]?A\.)){3,}[\.\?\!]+(' r'?:(?!\s[a-z]))') mo = re_satz.search(s) if mo: print "found:" sentences = re_satz.findall(s) for s in sentences: print "Sentence: ", s else: print "not found :-(" - snip - Output: found! Sentence: My text may i. Sentence: This is the end. Why isnt the above regexp greedier and matches the whole sentence? thx in advance Christian From borcis at users.ch Mon Aug 18 10:38:43 2003 From: borcis at users.ch (Borcis) Date: Mon, 18 Aug 2003 16:38:43 +0200 Subject: What's better about Rattlesnakes than Pythons? References: <8e482ba2.0308171939.7de4a288@posting.google.com> Message-ID: <3F40E4F3.6010809@users.ch> Graham Fawcett wrote: > > Any snake born in Java will perform better http://www.herpafauna.com/pics/pythons/retic-java.html is in the 9-meters league; no competitors, except the anaconda. From yiyang at wharton.upenn.edu Thu Aug 14 01:21:07 2003 From: yiyang at wharton.upenn.edu (Catherine Yang) Date: Thu, 14 Aug 2003 01:21:07 -0400 Subject: system call in python Message-ID: Hi, A question about how to execute a system command from python program. e.g. in a python script, I need to run another program written in C++, and after that come back to the same python program. Is it the system module, and which function do I use to do this? Thanks a lot Catherine From andrewm at object-craft.com.au Sun Aug 24 21:57:32 2003 From: andrewm at object-craft.com.au (Andrew McNamara) Date: Mon, 25 Aug 2003 11:57:32 +1000 Subject: Python prog needs root -how to do this securely In-Reply-To: Message from "John D." of "Sun, 24 Aug 2003 17:57:57 MST." References: Message-ID: <20030825015733.04CAE3CA4A@coffee.object-craft.com.au> >I have a Python program which runs as user 'www' (it's a CGI). >It needs root privilege to write a particular file. >What's the best way of doing this while remaining secure? > >Right now I do os.system("sudo myutil parms") and pass the parms to it. >I remove : < > & | from the parm string before passing it. >Is there a way to do this without making a system call? What you are talking about is "setuid" - it's best avoided unless you are an expert (and even they get caught out - there are many gotchya - use google if you care). You generally can't make scripts setuid. It's generally considered a good idea to have the minimum amount of code possible running with elevated priviledges - rather than making the entire application priviledged, you might have it ask a priviledged daemon to do the work instead. With security, you always err on the side of caution - in your message above, rather than removing some characters you know to be harmful, you would only allow requests containing characters you know to be safe and necessary in your context (don't guess). Often you find A-Z, a-z, 0-9 are the only characters you *really* need. Your context is a particularly hard problem to solve - if you aren't very very careful, you will allow anyone who compromises your web server (or a script running under the web server) to then compromise root. If you go the "root helper" approach, the helper needs to be completely paranoid about what it accepts (never trust what it's told by a user). -- Andrew McNamara, Senior Developer, Object Craft http://www.object-craft.com.au/ From nws088 at bco.com Thu Aug 21 12:58:27 2003 From: nws088 at bco.com (Joshua S.) Date: 21 Aug 2003 09:58:27 -0700 Subject: configure: WARNING: term.h: present but cannot be compiled Message-ID: <127cc4c7.0308210858.72dc0b04@posting.google.com> I am trying to install python-2.3 on my AIX 5.1.0.0 box. Everytime I try to run the configure script I ge the following error. ./configure --without-cxx --with-gcc --disable-ipv6 ... checking term.h usability... no checking term.h presence... yes configure: WARNING: term.h: present but cannot be compiled configure: WARNING: term.h: check for missing prerequisite headers? configure: WARNING: term.h: proceeding with the preprocessor's result checking for term.h... yes ... When I look in config.log I see a whole bunch of different errors: conftest.c:2: parse error before `me' configure:2405: $? = 1 configure: failed program was: #ifndef __cplusplus choke me #endif configure:2582: gcc -E conftest.c configure:2578: ac_nonexistent.h: No such file or directory configure:2588: $? = 1 configure: failed program was: #line 2577 "configure" #include "confdefs.h" #include configure:2625: result: gcc -E configure:2640: gcc -E conftest.c configure:2646: $? = 0 configure:2673: gcc -E conftest.c configure:2669: ac_nonexistent.h: No such file or directory configure:2679: $? = 1 configure: failed program was: #line 2668 "configure" #include "confdefs.h" #include configure:2898: checking for stdint.h configure:2911: gcc -c -g -O2 conftest.c >&5 configure:2939: stdint.h: No such file or directory configure:2914: $? = 1 configure: failed program was: #line 2903 "configure" #include "confdefs.h" #include #if HAVE_SYS_TYPES_H # include #endif #if HAVE_SYS_STAT_H # include #endif #if STDC_HEADERS # include # include #else # if HAVE_STDLIB_H # include # endif #endif #if HAVE_STRING_H # if !STDC_HEADERS && HAVE_MEMORY_H # include # endif # include #endif #if HAVE_STRINGS_H # include #endif #if HAVE_INTTYPES_H # include #else # if HAVE_STDINT_H # include # endif #endif #if HAVE_UNISTD_H # include #endif #include There are many more all following the same formats, but I am totally at a loss. When I try the make command it fails after a couple of minutes so I am guessing that the term.h file not compiling is causing complications. If anyone could point me in the right direction I would be very greatful! --Josh From jepler at unpythonic.net Wed Aug 13 10:50:38 2003 From: jepler at unpythonic.net (Jeff Epler) Date: Wed, 13 Aug 2003 09:50:38 -0500 Subject: Eight Queens Puzzle by Magnus Lie Hetland In-Reply-To: <215fa0fc.0308130557.7f1c950b@posting.google.com> References: <215fa0fc.0308130557.7f1c950b@posting.google.com> Message-ID: <20030813145034.GB15732@unpythonic.net> View the chessboard as an 8x8 grid. Each square has an x and a y coordinate which is an integer. The vertical distance between (xi, yi) and (xj, yj) is abs(yi-yj). Simularly, the horizontal distance is abs(xi-xj). Two queens conflict if they are on the same row (identical y values), on the same column (identical x values) or on the same diagonals. To be on the same diagonal, the horizontal and vertical distance will be the same. The i'th queen is at the location (state[i], i), and the queen being placed is at (nextX, nextY), and nextY > i. So the 'if abs ... in ...:' test is identical to the description in the paragraph above, but with the parts that are known impossible eliminated (same row) and the calculation of the vertical distance eliminates the abs() call because it is known to give a positive result. Jeff From mis6 at pitt.edu Sat Aug 23 03:33:52 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 23 Aug 2003 00:33:52 -0700 Subject: For Kenny Tilton: Why do I need macros revisited. References: <3f45484f$1_6@corp.newsgroups.com> <3F45A7BF.4060806@nyc.rr.com> Message-ID: <2259b0e2.0308222333.16ad345d@posting.google.com> Kenny Tilton wrote in message news:<3F45A7BF.4060806 at nyc.rr.com>... > You are absolutely right. Metaclasses are killer. I am surprised > Pythonistas afraid of macros let them into the language! Me too. Actually they are quite *scaring*. In my post on "PEP 312 (and thus 308) implemented with a black magic trick" actually I argued that they were much *worse* than macros, since they are able to change the *semantics* of the language, a much more dangerous thing than simply changing the syntax. In a sense, they are deeply unpythonic, the exact opposite of "explicit is better than implicit". Maybe it enters in "practicality beats purity", but this is stretching the principle quite a bit. Same for descriptors and properties, which still are much less dangerous. I think metaclasses were intended not to be used, except from developers and very advanced users. The problem is that once you have a feature in a language, people will use it. I do like metaclasses, but I would be scared in debugging a large program written by others using them and with poor ocumentation. Each time you see a class, you are never sure of what it is doing; when the bug happens, you are not sure if it is in the class or in the metaclass (this happened to me even with my own programs). It is quite worrysome, actually. Fortunately, we are good people, here on c.l.py, and I don't think anybody would mess things up, but it could *easily* be done. Now, I trust the programmer and I do like the power and the freedom; but still it strikes to me as a case of multiple personality to have a language that at the surface is plain, clear, nicely indented, and under the cover ... caveat emptor! Let it be this way, anyway, and let us continue to advertise it as a "clean" language. Let us stop people who want case statement, repeat .. until, ternary operators, braces, and the like, and let us under the cover give people the freedom to program classes and altering at will nearly everything at the semantics level. Let the other worry about syntax ... ;-) > I actually had > a metaclass implementation of Cells until I decided to release the > source. The MOP is not part of the standard, and it shows across > implementations. Hell, MCL does not even expose a MOP. > Quite impressive. You are actually saying that you do prefer Python over Lisp on a problem of ultra-high level programming which should be the rightful Lisp playhouse ... To be fair, the reason is not lack of power by Lisp, but lack of standardization, still it is something that makes me thinking ... Michele Simionato, Ph. D. MicheleSimionato at libero.it http://www.phyast.pitt.edu/~micheles --- Currently looking for a job --- From mertz at gnosis.cx Thu Aug 28 17:36:26 2003 From: mertz at gnosis.cx (Lulu of the Lotus-Eaters) Date: Thu, 28 Aug 2003 17:36:26 -0400 Subject: opposite of dict.items() References: <3f4e708c$0$64719@hades.is.co.za> <3f4e7544$0$64724@hades.is.co.za> Message-ID: |a = {} |for k , v in zip(keys,values): | a[k] = v >>> keys = (1,2,3,4) >>> vals = 'a b c d'.split() >>> dct = dict(zip(keys,vals)) >>> dct {1: 'a', 2: 'b', 3: 'c', 4: 'd'} -- mertz@ | The specter of free information is haunting the `Net! All the gnosis | powers of IP- and crypto-tyranny have entered into an unholy .cx | alliance...ideas have nothing to lose but their chains. Unite | against "intellectual property" and anti-privacy regimes! ------------------------------------------------------------------------- From gh at ghaering.de Wed Aug 20 03:27:25 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Wed, 20 Aug 2003 09:27:25 +0200 Subject: Import error !! In-Reply-To: <200308192221.14129.skchim0@engr.uky.edu> References: <200308192221.14129.skchim0@engr.uky.edu> Message-ID: <3F4322DD.2020107@ghaering.de> satish k.chimakurthi wrote: > Hello all, > > I am trying to import a module which was generated by a PYTHON-C++ interface > generator tool, which failed, and generated the following error : [...] > # /usr/lib/python1.5/exceptions.pyc matches /usr/lib/python1.5/exceptions.py > import exceptions # precompiled from /usr/lib/python1.5/exceptions.pyc > # /usr/lib/python2.2/site.pyc has bad magic > 'import site' failed; traceback: > File "/usr/lib/python2.2/site.py", line 64 > dir = os.path.abspath(os.path.join(*paths)) > ^ > SyntaxError: invalid syntax > Python 1.5.2 (#1, Apr 3 2002, 18:16:26) [GCC 2.96 20000731 (Red Hat Linux > 7.2 2 on linux-i386 > Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam > import readline # dynamically loaded from > /usr/lib/python1.5/lib-dynload/readline.so > > I don't understand much from the above. Can someone suggest what this means ?? For some reason, your Pythons get mixed up (1.5.2 and 2.2). 1.5.2 doesn't understand the argument expansion operator * yet. The first thing I'd check is the Python module search path (sys.path). Maybe you're doing somethnig fancy like setting PYTHONPATH that causes this problem? Also, on your old Redhat system, you'll have to run Python 2.2 with 'python2' instead of 'python'. -- Gerhard From mwh at python.net Tue Aug 26 14:38:50 2003 From: mwh at python.net (Michael Hudson) Date: Tue, 26 Aug 2003 18:38:50 GMT Subject: Default value for PYTHONPATH References: <8d3e714e.0308260950.40ad4a7b@posting.google.com> Message-ID: <7h38ypge06n.fsf@pc150.maths.bris.ac.uk> cappy2112 at yahoo.com (Tony C) writes: > Is there a default value for PYTHONPATH ? > I've installed Python on both Windows and Linux, and was surprised > to see that this variable is empty. > > IS this normal ? Yes. How would it be otherwise, particularly on Linux? I'm quite glad "make install" doesn't try to edit ~/.bashrc. Cheers, mwh -- Q: What are 1000 lawyers at the bottom of the ocean? A: A good start. (A lawyer told me this joke.) -- Michael Str?der, comp.lang.python From adalke at mindspring.com Wed Aug 27 13:01:56 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Wed, 27 Aug 2003 17:01:56 GMT Subject: Aspect oriented Everything? References: <32cc321c.0308221316.2f5793ac@posting.google.com> <6ee58e07.0308230459.24f53b64@posting.google.com> <8ef9bea6.0308261857.1b44a5b7@posting.google.com> <8ef9bea6.0308270810.7adfe408@posting.google.com> Message-ID: <8u53b.6351$Jh2.2854@newsread4.news.pas.earthlink.net> Hung Jung Lu: > The question is: are there code spots that are not factored? If you > have ONE single class that has to implement the before, around, or > after methods, sure, nothing wrong with what you have said. But, if > you have > > class A: > def f1(): > register() > ... > deregister() > class B: > def f2(): > register() > ... > deregister() > class C: > def f3(): > register() > ... > deregister() > > You start to ask your self: how come the register() deregister() parts > are not factor out? How can I factor out these parts of code? What about >>> class RegisterFunc(object): ... def __init__(self, f): ... self.f = f ... def __get__(self, obj, type = None): ... return RegisterCall(self.f, obj) ... >>> class RegisterCall(object): ... def __init__(self, f, obj): ... self.f = f ... self.obj = obj ... def __call__(self, *args, **kwargs): ... register() ... try: ... self.f(self.obj, *args, **kwargs) ... finally: ... deregister() ... >>> def register(): ... print "Register" ... >>> def deregister(): ... print "Deregister" ... >>> class Spam(object): ... def spam(self): ... print "I've been spammed!" ... spam = RegisterFunc(spam) ... >>> Spam.spam() Register I've been spammed! Deregister >>> > If you don't have AOP, you would have to manually modify each class into: ... > Notice that OOP or class > inheritance will not allow you to factor out these types of > "horizontal common code spots". Hmm. Given that, is what I'm doing above not OO programming? You can derive from it, and because the methods are not changed once the class is defined, I event get the proper behaviour that the childrens' behaviour is more restrictive than the parent's. (I point this out because pre-2.3 I would have used __getattr__ hooks to make a wrapper around the whole class, rather than a per-method one like I did here.) > To my, horizontal factorization is what AOP is all about. It goes > beyond the before-, around-, after- hooks. I've written codes where I > have many if statements in a base class method: ... > but in OOP you will find > out that common steps 1,2,4 will not be factored out, and that when > you need to change the code in the common steps, you need to change in > all subclasses, which is tedious and error-prone. For this I would usually use a mixin or just call a function. Or change it so there are functions which can each modify a state, as in class Modifier: def between_1_and_2(self, state): .. def between_2_and_3(self, state): .. class FixedRateModifier(Modifier): ... class GovernmentBondModifier(Modifier): ... def f(arg1, arg2, arg3, ...): modifiers = [FixedRateModifier(), GovernmentBondModifier()] state = State(arg1, arg2, arg3) do_step1_calculations(state) for m in modifiers: m.between_1_and_2(state) self.do_step2_calculations(state) for m in modifiers: m.between_2_and_3(state) ... Is this a hand-written way of doing AOP? (I wouldn't be surprised. I didn't understand OO until I handwrote a system using typedefs and lots of function pointers.) > Clearly inheritance > is not the way to implement properties/features like these ones. OOP > just cannot solve the problem. Agreed about the inheritance part. Disagree that there are non-AOP ways to address it. Andrew dalke at dalkescientific.com From ghowland at lupineNO.SPAMgames.com Sat Aug 23 13:19:51 2003 From: ghowland at lupineNO.SPAMgames.com (Geoff Howland) Date: Sat, 23 Aug 2003 17:19:51 GMT Subject: Modifying the {} and [] tokens References: <04cekv0s6ghjtuhl5j2gph7ltobdb5rsam@4ax.com> <62rekv0k4ucgrh46lkp27klq13pq8ppp5p@4ax.com> <1h3fkvg8mkeq69a8hriojugqfcp75hafjj@4ax.com> <5l7fkvsd2lor14s7s0avra2553nfhe3net@4ax.com> Message-ID: On Sat, 23 Aug 2003 13:16:47 -0400, Roy Smith wrote: >Geoff Howland wrote: >> As it stands now, everyone has to do this every time, > >I suppose that's true. On the other hand, I can't remember the last >time I ever wanted to add two dictionaries. Then you wouldn't be effected one way or the other. :) -Geoff Howland http://ludumdare.com/ From jroznfgre at jngpugbjreXEBCXNbet.cy Thu Aug 21 15:16:49 2003 From: jroznfgre at jngpugbjreXEBCXNbet.cy (JZ) Date: Thu, 21 Aug 2003 21:16:49 +0200 Subject: MySqlDB Question - CompatMySqlDB is all I can find ? References: <282f826a.0308210238.11ef6a97@posting.google.com> Message-ID: On 21 Aug 2003 03:38:37 -0700, richardshea at fastmail.fm (Richard Shea) wrote: >>>> import CompatMysqldb >>>> import Mysqldb >Traceback (most recent call last): > File "", line 1, in ? >ImportError: No module named Mysqldb >>>> Try import MySQLdb Modules name are case sensitive -- JZ From aleax at aleax.it Sat Aug 30 03:52:51 2003 From: aleax at aleax.it (Alex Martelli) Date: Sat, 30 Aug 2003 07:52:51 GMT Subject: Add two dicts References: <86ktkvkd05e88hu14hjudmfvbul7slfgkt@4ax.com> <3F4EDF7A.C9CF6DA3@alcyone.com> <0mrtkv8b1bnnk1v310kf3b8tmjo8d9higo@4ax.com> Message-ID: Greg Brunet wrote: > "Greg Brunet" wrote in message > news:vl0gbotgl3sibf at corp.supernews.com... >> But what about something like this: >> >> >>> class xdict(dict): >> ... def __add__(self,dict2): >> ... result = self.copy() >> ... result = result.update(dict2) ... > Ooops - that should have been: > return result.update(dict2) > > in the last line, but still, shouldn't that have mapped the "+" operator > for xdict objects? You're returning None in both your actual code and the "should have been", but the general approach is workable -- e.g. with Python 2.3: >>> class xdict(dict): ... def __add__(self, other): ... return xdict(self, **other) ... >>> xdict({1:2, 3:4})+{5:6} {1: 2, 3: 4, 5: 6} >>> Alex From adalke at mindspring.com Tue Aug 19 03:20:57 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Tue, 19 Aug 2003 01:20:57 -0600 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: <3F41A877.995F9C35@alcyone.com> Message-ID: Ben Finney: > The "References" header could theoretically allow you get that > information, but it would be expensive to do so for every message, > especially in long-running threads. "expensive"? How? Say 10,000 messages with about 200 messages. A linear scan is fast enough these days, and it's easy enough to merge the message ids into a lookup table. Andrew dalke at dalkescientific.com From jack at performancedrivers.com Mon Aug 18 21:26:35 2003 From: jack at performancedrivers.com (Jack Diederich) Date: Mon, 18 Aug 2003 21:26:35 -0400 Subject: What's better about Ruby than Python? In-Reply-To: ; from a.schmolck@gmx.net on Tue, Aug 19, 2003 at 01:46:20AM +0100 References: Message-ID: <20030818212635.A1008@localhost.localdomain> On Tue, Aug 19, 2003 at 01:46:20AM +0100, Alexander Schmolck wrote: > Gon?alo Rodrigues writes: > > > On 18 Aug 2003 23:40:58 +0100, Alexander Schmolck > > wrote: > > > >But of course what currently happens is: > > > > > >'just a method' > > > > > > > And rightly so, you have just rebinded a name. If you type > > > > x.__class__ > > > > you get the older X. Or are you proposing that rebinding X to > > automagically rebind the __class__ of all the X instances? > > Well, yes, I propose that x.__class__ return the *new* definition of X (like > in ruby, for example). I don't think that necessarily involves rebinding > anything "automagical", depending on how the lookup of x.__class__ works. > > Can you give my any reason why you would *not* want all instances to be > updated on class redefinition? Python names aren't special in any way so making names special when associated with a class as opposed to a function or variable would make it less intuitive for users. Pyhon also doesn't have anonymous classes, so an odd but perfectly OK program could be written class Anon(Exception): pass raise_this_later(Anon) # stores it for later class Anon(Exception): def __str__(self): return "Slightly different exception" raise_this_later(Anon) Explicit is better than implicit requires that the programmer specifically change all old 'Anon' classes into the new classes. Writing a metaclass to do this explicitly for you just for all the classes that might be redefined is also OK. # completely untested, I haven't overidden __new__ in practice so that line # might be a bit off. class NamesMatter(type): all_seen_classes = {} all_seen_instances = [] def __init__(cls, name, bases, dict): """If a class name is reused rebind all the old instances to the new class""" if (name in NamesMatter.all_seen_classes): for (ob) in filter(lambda x:x.__class__ == NamesMatter.all_seen_classes[name]): ob.__class__ = cls NamesMatter.all_seen_classes[name] = cls def remember_obs__new__(cls, **args, **opts): """A custom __new__ that records instances in a central place""" self = object.__new__(cls) NamesMatter.all_seen_instances.append(self) return self setattr(cls, '__new__', classmethod(remember_obs__new__)) return # usage class Anon(object): pass # a class that doesn't upgrade itself class Upgrader(object): __metaclass__ = NameMatter """Instances of this class will be upgraded to a new class if this name is reused""" -jackdied From ryanlowe0 at msn.com Sun Aug 24 11:07:54 2003 From: ryanlowe0 at msn.com (Ryan Lowe) Date: Sun, 24 Aug 2003 15:07:54 GMT Subject: python gripes survey References: Message-ID: "Dave Brueck" wrote in message news:mailman.1061701097.12913.python-list at python.org... > Here's a short list of my anti-gripes - features that I like but some people complain about; > features that, if removed or changed too much, would make me like Python > less: > > - no assignment in if/while > - whitespace significant to both programmer and the language > - {} + {} not allowed ;-) > - private variables are a language-encouraged convention instead of an attempt > to babysit the programmer > - no macros > - no end-block tag required > - list comprehensions > - a "self" parameter is passed to all class methods, and by convention we all > call it "self" > - tendency to prefer keywords over special characters > - thread-safe operations on fundamental objects (e.g. two threads doing > somedict['foo'] = x at the same time won't cause Python to crash or corrupot > somdict) > - list.sort() doesn't return the sorted list > > There are more, but this list is just off the top of my head. :) > -Dave id agree with most of those too. i hadnt really thought about the sort() function, but that does seem a little inconsistent with other methods which do return a value. im sure there is a good reason for this (speed?). From tjreedy at udel.edu Sat Aug 2 17:29:16 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 2 Aug 2003 17:29:16 -0400 Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> <87el06d2i6.fsf@pobox.com> Message-ID: <8Z-cnS25-8ywsLGiXTWJiQ@comcast.com> "Andy C" wrote in message news:y3VWa.261$_p6.23775419 at newssvr21.news.prodigy.com... > What's bad about tabs? Because there is no 'official' meanings, despite claims to the contrary, some software like Outlook Express ignores them on receipt. tjr From ngps at netmemetic.com Thu Aug 28 11:57:41 2003 From: ngps at netmemetic.com (Ng Pheng Siong) Date: 28 Aug 2003 15:57:41 GMT Subject: Windows Remote Log in References: Message-ID: According to Jesse : > What I need is some way for user to enter the proper credentials so > Python could restart the service on the remote machine. If you are able to install one or more Python programs on the servers then you can get your client Python program to talk a private protocol to your server Python program to DTRT. No need to mess around with Windows APIs. -- Ng Pheng Siong http://firewall.rulemaker.net -+- Manage Your Firewall Rulebase Changes http://www.post1.com/home/ngps -+- Open Source Python Crypto & SSL From aahz at pythoncraft.com Wed Aug 6 00:39:46 2003 From: aahz at pythoncraft.com (Aahz) Date: 6 Aug 2003 00:39:46 -0400 Subject: Problem w/ IDLE on Win2000 References: Message-ID: In article , Thomas Rivas wrote: > >Unable to launch IDLE(fork?) from the new Py 2.3. Anybody else have this >problem. Solutions? http://www.python.org/2.3/bugs.html -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From dsylvest at adelphia.net Mon Aug 18 18:00:36 2003 From: dsylvest at adelphia.net (Dennis) Date: 18 Aug 2003 15:00:36 -0700 Subject: GTK import doesn't import first time References: <4a555b17.0308180759.48c99878@posting.google.com> Message-ID: <4a555b17.0308181400.3e3e15b9@posting.google.com> John Hunter wrote in message news:... > >>>>> "Dennis" == Dennis writes: > > Dennis> I've downloaded and installed per the instructions the > Dennis> pyGTK and GTK+ for win32 from the above locations. > Dennis> Folowing the instructions, I import pygtk first, run > Dennis> pygtk.require('2.0') second and then import gtk. I > Dennis> receive an error on the import gtk the first time, but > Dennis> immediately after, if I import again it works. Even if I > Dennis> don't impo0rt pyGTK at all and only import gtk, I get the > Dennis> same results. Any ideas? > > The reason it "works" the second time is that it doesn't try and > import it again after the first. So it did not really work. > > Did you download and install the GTK runtime from > http://www.dropline.net/gtk? If you installed it to to C:\GTK, you'll > need C:\GTK\bin and C:\GTK\lib in your path. Yes, as stated in the post I installed GTK runtime. Also, GTK\2.0 is in my path and verified with: >>> import os >>> print '\n'.join(os.environ['PATH'].split(';')) which provided (amongst other entiries) ... D:\GTK\2.0\lib D:\GTK\2.0\bin ... BUT, searching around google a little more I notice that a LOT of people have had this problem and the response you've provided is pretty much the same. Then I found an answer that worked here: http://www.daa.com.au/pipermail/pygtk/2003-January/004329.html (THANKS Jamey!) Seems that previous versions installed the dll in C:\windows\system32 and python was finding the old dll since the windows directory is earlier in the path. Had I remembered (or known - don't know which) that the directory GTK installs dll's in is now different, I would have caught this. D'oh! Removed the old dll and all is well. Dennis S. > > John Hunter From johnfabel at btinternet.com Thu Aug 7 15:12:02 2003 From: johnfabel at btinternet.com (John Abel) Date: Thu, 07 Aug 2003 20:12:02 +0100 Subject: python-2.3 Checksum Error In-Reply-To: <009301c35d16$1a3ee8e0$4901a8c0@beastjr> References: <009301c35d16$1a3ee8e0$4901a8c0@beastjr> Message-ID: <3F32A482.2090906@btinternet.com> An HTML attachment was scrubbed... URL: From jane.doe at acme.com Mon Aug 4 09:59:21 2003 From: jane.doe at acme.com (Jane Doe) Date: Mon, 04 Aug 2003 15:59:21 +0200 Subject: Can't get dumb webcounter working References: Message-ID: On Sun, 03 Aug 2003 04:08:18 GMT, "J. W. McCall" wrote: >Any advice, specific instructions, pointers to helpful web resources, or >recommendations to better newsgroups, if this is too OT here, would be >greatly appreciated. More infos on calling a Python script through a URL (CGI call) here: http://www.devshed.com/Server_Side/Python/CGI/print_html JD. From pythonguy at Hotpop.com Wed Aug 13 03:09:29 2003 From: pythonguy at Hotpop.com (Anand Pillai) Date: 13 Aug 2003 00:09:29 -0700 Subject: dumb questions! References: <3f38fead$0$49117$e4fe514c@news.xs4all.nl> Message-ID: <84fc4588.0308122309.10491116@posting.google.com> And if you want remoting in your application try out pyro.sourceforge.net :-) Anand Irmen de Jong wrote in message news:<3f38fead$0$49117$e4fe514c at news.xs4all.nl>... > Emmanuel Jean-Louis wrote: > > > Guys please bear with me. I'm new to the hole ball game. I'm an > > electrical engineer who fall in love with programming. I might be the > > dummiest guys in list right now about programming but it's all good. > > Hopefully in a year or so, I will sound just like you guys. You will be > > seeing a lot of none sense questions, please help me out. > > Will do, but it is highly recommended to read the following page > thoroughly: > > http://www.python.org/topics/learn/ > > It points to a lot of invaluable online information, documentation, > FAQs, guides, and more. > > --Irmen From gh at ghaering.de Fri Aug 1 09:02:49 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Fri, 01 Aug 2003 15:02:49 +0200 Subject: Secure FTP in Python? In-Reply-To: References: Message-ID: <3F2A64F9.1070400@ghaering.de> Karl Scalet wrote: > Cameron Laird schrieb: >> Kyler Laird wrote: >>>> Or is there some other >>>> (noncomplicated) way how secure uploading can be implemented in Python? >> >> rsync, in particular, is a good fit for what many people >> mean by "uploading", and rsync is ssh-savvy. > > or, on top of rsync-libs, you can run duplicity. [...] Or just use the plain librsync wrapper for Python. Another option that I use to use SSH tunnels. For some reason the people who contributed the ODBC driver to PostgreSQL found it necessary to reimplement the PostgreSQL wire protocol instead of linking to libpq, which would already be SSL enabled. Instead of buying a commercial SSL-enabled PostgreSQL ODBC driver I decided to just set up a SSH tunnel to my PostgreSQL server for ODBC access. To tunnel FTP over SSH you'll have to use passive FTP. I don't remember if it has been mentioned already, but M2Crypto has a FTP/SSL implementation. -- Gerhard From graham at rockcons.co.uk Thu Aug 7 07:53:34 2003 From: graham at rockcons.co.uk (Graham Nicholls) Date: Thu, 07 Aug 2003 12:53:34 +0100 Subject: Need to convert an arbitrary byte-pair to an int. Message-ID: <3f323dc2$0$10775$afc38c87@auth.uk.news.easynet.net> Hi, I'm trying to size a jpeg file. The file size is held in a short (2 byte integer) at a certain offset. Once I've found these two bytes (they're in MSB,LSB order), I need to convert them to an integer - now I know that in C I'd just cast a pointer to the offset to a short, and that python doesn't cast, so how can I extract the value from a stream of bytes. I've looked at python.org/Doc/current (I'm using 2.3b1), but can't find anything obvious. Thanks -- Graham Nicholls Rock Computer Consultancy From jacek.generowicz at cern.ch Sat Aug 23 05:30:14 2003 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 23 Aug 2003 11:30:14 +0200 Subject: What's better about Ruby than Python? References: <4o_0b.1665$Ej6.1182@newsread4.news.pas.earthlink.net> <8D01b.1721$Ej6.702@newsread4.news.pas.earthlink.net> <3F44ED2E.9070308@nyc.rr.com> <0V61b.1900$Ej6.1012@newsread4.news.pas.earthlink.net> <3F4504D7.20008@nyc.rr.com> <2259b0e2.0308230118.67a676e7@posting.google.com> Message-ID: mis6 at pitt.edu (Michele Simionato) writes: > That said, I do agree that the presence of hundreds of dialects works > against the adoption of Lisp. For instance, this stopped me (together > with other factors). So why did the presence of "hundreds of dialects" of scripting languages not stop you adapting a scripting language ? As I've mentioned elsewhere; objecting to the existence of multiple dialects of Lisp (essentially, languages which represent their source code in a form they can easily manipulate), as as daft as objecting to the existence of multiple dialects of the Algol Language family, or to the existence of multiple languages with significant indentation. From kern at taliesen.caltech.edu Sat Aug 23 21:54:59 2003 From: kern at taliesen.caltech.edu (Robert Kern) Date: Sun, 24 Aug 2003 01:54:59 +0000 (UTC) Subject: Modifying the {} and [] tokens References: Message-ID: In article , Geoff Howland writes: > On Sat, 23 Aug 2003 13:56:13 +0000 (UTC), kern at taliesen.caltech.edu > (Robert Kern) wrote: [snip] >>In the end, it's just not worth the trouble. 99.9% of the time, I think >>you will find that subclassing the builtin types and giving the new >>classes short names will suffice. I mean, how much of a hardship is it >>to do the following: >> >>class d(dict): >> def __add__(self, other): >> # stuff >> >>d({1:2}) + d({3:4}) > > It's not actually the hardship of doing this, there is also the > conversion of everything that doesn't create MyDict by default. I > would have to keep converting them to perform the same manipulations, > or other functions (add is only an important example, others could be > handy as well). > > Now I will need additional lines to do this, or make the lines that > exist more complicated. It's not undue hardship in a lot of ways, but > it would be nice not to have to and be able to keep the characters > used to a minimum. Espcially when trying to write sub-50 line scripts > and such. I understand this feeling. In the NumPy world, we have the same problem with subclassing arrays. The builtin functions still return regular arrays. One particular type of solution is often possible. For example, making an __add__ method for dicts probably doesn't require any other new methods, just the normal dict ones (copy, update). That is, it doesn't require the other object to be MyDict, just a normal dict. So you can write: d({1:2}) + {3:4} Especially for the situations you are considering, where you are only adding functionality, not changing the way other methods work, this will often be a viable way of doing what you want. >>If you're still not convinced, ask yourself these questions: > > I actually feel confident I would be happy with my provided answers as > real functionality. I don't believe Python will be changed to allow > that, and that is fine with me. I just wanted to know if it could be > done the way Python is now. The point of this exercise is to clarify the details what you actually want, try to square them with the current architecture and each other, and finally to show why they aren't there now. >>* How would you apply the new subclass? >> - Only on new literals after the subclass definition (and registry of >> the subclass with some special hook)? >> - On every new object that would normally have been the base type? > > Yes and yes. > > It is possible, if this were possible, to only make this work for > classes that imported it if they so desired I expect. Explicitly > requested only, etc. Not in any clean way. See below. >> - On every previously existing object with the base type? > > No, they're already defined. Unless my understanding of the way types > are done is lacking, and they are referencing the same base object > code, and then maybe yes to this as well, but it would be passive. The question is "do you really want this?" It would interfere with other modules in a very invasive way and according to what you say below is not what you want. >> - In just the one module? or others which import it? or also in >> modules imported after the one with the subclass? > > In the module, and any that import it. It fails to be useful in > making things clean-and-neat if in order to make a clean-and-neat > script you have to first have a bunch of stuff that modifies the > language norms. I think this is impossible without taking a performance hit in the construction of all object with a builtin type. Every internal call to PyDict_New, PyList_New, etc. would have to check the registry and somehow know what module it is being called from. There would have to be a reworking of the internals to give the Py_New functions that kind of information. And you get a performance hit even if you don't subclass builtin types. And if you do subclass in your module, just for internal use, how can you import this module into another without affecting it as well? That is, you only want what the module does, not the redefinition of dicts? >>* How does your choice above work with code compiled on-the-fly with >> eval, exec or execfile? > > It would depend on how Python allowed this change to work. If it did > it the way "I imagine" it would, then the change would effect all of > these circumstances. I don't think it works the way you imagine. I think there would have to be even more reworking of the way these work to pass in the information that the exec'd code should use the redefinitions in the current module. >>* How do you deal with multiple subclasses being defined and registered? > > If they re-wrote the same thing and didn't just augment it (or > overwrote each other), then I would expect them to clobber each other. > Problems could ensue. This is where I say "too much rope." > However, why isn't having {} + {} or [].len() part of the language > anyway? If it was, people wouldnt have to keep writing their own. > > {} + {} doesnt have to solve ALL cases, which is why I'm assuming it > isnt already implemented as [] + [] is. It just has to solve the > basic case and provide the mechanism for determining the difference. > Ex, key clobbering add, and an intersect() function to see what will > be clobbered and do something about it if you care. > > Isn't it better to have some default solution than to have none and > everyone keeps implementing it themselves anew every time? Unless the default solution is the one clear way to do it, no. Since it only takes a few lines to implement in any one way that you might want to do it, there is very little incentive to make the default way one of them. You want clobbering; I'll probably want the values added to each other as in a sparse array. For the same reason, the Python standard library doesn't have a priority queue implementation. There are so many different ways to write a priority queue with different behaviors, tradeoffs, and applications. Since there are all pretty easy to implement in a few number of lines, there is no incentive to include a default one in the standard library. > For the [].len() type things, this is obviously a matter of taste, and > I have always been ok with len([]), but in trying to get team mates to > work with Python I have to concede that [].len() is more consistent > and a good thing. Same for other builtins that apply. Terry explains the historical reasons very well. I would also add that the "len(obj) calls obj.__len__()" rule enforces a consistency among user-defined classes and types. The canonical way to report a length is to define a __len__ method, and the canonical way to get a length is to call len(obj). If this were not the case, objects would be defining .len(), .length(), .getLength(), .number(), .cardinality(), etc. >>* How would you pass in initialization information? >> E.g. say I want to limit the length of lists >> >> class LimitList(list): >> def __init__(self, maxlength, data=[]): >> self.maxlength = maxlength >> list.__init__(self, data) >> def append(self, value): >> if len(self) == self.maxlength: >> raise ValueError, "list at maximum length" >> else: >> list.append(self, value) > > I am actually interested in new features than modifying current ones, > but I suppose you would have this ability as well since you have > access. > > I would say if you break the initialization or any other methods of > accessing the type in a default way, then you have just given yourself > broken code. No one other function will work properly that uses it > and didn't expect to. Again, "too much rope." > You will see it doesn't work, and stop. I didn't say I wanted to > change ALL the behavior of the language, I just wanted to add features > that dont currently exist and I think should. I, for one, rarely ever subclass the builtin types to add something orthogonal to the original methods. I'm usually modifying the behavior of current methods. There's no clean way for an implementation to know this upon registry and raise an error. >>* Can I get a real dict again if wanted to? > > Save it, dont clobber the original out of existance. The coder could > mess this up (more rope). > >>* Given your choices above, how can you implement it in such a way that >> you don't interfere with other people's code by accident? > > There could be module limitations, but when I imagined this it was > globally reaching. I believe that as long as you add features, or any > changes you make dont break things, then you will be safe. If you > mess with features that exist then you will break things and your > programs will not work. > > This seems natural enough to me. You ARE changing a default behavior, > there are risks, but if you dont change things that other functions > use (pre-existing methods), then you are safe. This restriction really limits the usefulness of the feature. Compare the changes that would have to be made at the architecture level to the drawbacks of using MyDict({}). >>Okay, so the last one isn't really fair, but the answers you give on the >>other questions should help define in your mind the kind of behavior you >>want. Reading up on Python internals with the Language Reference, the >>dis module documentation, and some source code should give you an idea >>of how one might go about an implementation and (more importantly) the >>compromises one would have to make. > > It seems the changes would have to be to the Python source, and I dont > want to make a new Python. I dont even want to "change" Python, I > want to augment it. I think these are reasonable additions, and I'm > sure I missed the discussions on why they aren't there now. > > There may be very good reasons, and I could end up retracting my > desired feature set because of them, but I still wanted to see if I > could make it work for my own code. At the Python prompt, "import this". >>Then compare these specific features with the current way. Which is >>safer? Which is more readable by someone unfamiliar with the code? Which >>is more flexible? Which saves the most typing? > > I think my answers above are sound. If it worked the way I hoped it > might, you could change things on a global scale and you still > wouldn't break anything. Well, Python isn't architectured the same way that Ruby is. There are fundamental problems in doing what you want. >>My condolences on having to deal with such a team. It seems a little >>silly to me to equate OO with Everything-Must-Be-a-Method-Call. But if >>they insist, point them at [].__len__(). len([]) just calls [].__len__() >>anyways. After writing code like that for a while, they'll probably get >>over their method fixation. > > I never had a problem with this myself, but people are different. I > have a great team, everyone has their own opinions. No need to > belittle them for differing. > > Some people never get over the whitespacing. It's just the way the > people work. No need to see them as flawed. :) No belittling was intended. I just wanted to express that I just don't see the sense in it, and that if I had to work with such a team, I would be tearing my hair out. I lose enough hair interfacing with FORTRAN, thank you very much. :-) Preferring [].len() to len([]) is one thing, claiming it's intrinsically more OO is another. > -Geoff Howland > http://ludumdare.com/ -- Robert Kern kern at caltech.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter From mpeuser at web.de Thu Aug 7 05:45:59 2003 From: mpeuser at web.de (Michael Peuser) Date: Thu, 7 Aug 2003 11:45:59 +0200 Subject: itertools.ilen? References: Message-ID: Another solution could be to implement custom lenght methods. However I see no graceful way to do it with the quite tricky implementation (yield is the only hint!) of 2.3. It would be definitly easy with 2.2 "by hand" function factories (def iter(), def __next__()), just def len() in addition and find the fastest implementation Kindly Michael "Jeremy Fincher" schrieb im Newsbeitrag news:bgt56e$7no$2 at news.cis.ohio-state.edu... > Michael Peuser wrote: > > There is no way to determined, whether such generartors will come to an > > end - The Halting Problem for Turing Machines ;-) > > Thus there will never be a safe len(iterator). > > But then, there's no way to determine whether any given class' __len__ will > terminate, so you've got the same problem with len. > > Granted, it's more likely to manifest itself with iterators and ilen than > with sequences and len, but if it's really an issue, ilen could take an > optional "max" argument for declaring a counter ilen isn't to exceed. > > Jeremy From skip at pobox.com Wed Aug 20 12:42:07 2003 From: skip at pobox.com (Skip Montanaro) Date: Wed, 20 Aug 2003 11:42:07 -0500 Subject: python quickie : retrace function steps? In-Reply-To: <5f5c82ec.0308200820.51c8e33c@posting.google.com> References: <5f5c82ec.0308200820.51c8e33c@posting.google.com> Message-ID: <16195.42207.258121.20969@montanaro.dyndns.org> Matt> Is there away I can print out the path my Program had taken (i Matt> want to do this as part of my error checking, so a user would Matt> always know the path my program took)? Take a look at the traceback.print_stack() and .format_stack() functions. Skip From skip at pobox.com Mon Aug 25 10:06:15 2003 From: skip at pobox.com (Skip Montanaro) Date: Mon, 25 Aug 2003 09:06:15 -0500 Subject: __all__ as it relates to _foo, _bar, etc. In-Reply-To: References: Message-ID: <16202.6103.395712.221674@montanaro.dyndns.org> carroll> from ModuleName import * carroll> if __all__ is initialized in the module, all of the names carroll> listed in that list are made available; if __all_ is not carroll> initialized, every name not beginning with an underscore is carroll> made available. Correct. carroll> If you code: carroll> import ModuleName carroll> Neither the __all__ or the underscore-prefixed names make any carroll> difference, because the names from the module are not made carroll> available except through an explicit reference to them (e.g., carroll> ModuleName.spam).... carroll> Is my understanding correct? Yes. carroll> If I understand this right, then, if the coder of a module carroll> initializes __all__, he need not worry about the _foo carroll> convention as far as namespaces are concerned, anyway; Yes, though use of a leading underscore is still a signal to people reading your code that you don't intend _foo to be part of the exposed API. Skip From grante at visi.com Tue Aug 5 20:30:13 2003 From: grante at visi.com (Grant Edwards) Date: 06 Aug 2003 00:30:13 GMT Subject: Capture output from stderr References: Message-ID: In article , klappnase wrote: > I am trying to program a Tkinter application for linux, so I want to > run a shell command from the gui and capture its output on the fly > while the process is still running in order to display the progress > messages in a toplevel window so the user may watch what is going on > (the execution of the shell command may take a few minutes). Because > the output is printed to stderr I thought I should use a popen2.Popen4 > instance for that, like: > > self.pp = popen2.Popen4("exec cmd") > > I tried something like > > def getmsg(self): > msg = self.pp.fromchild > newmsg = msg.read(100) > ...(do something)... > self.master.after(1000, self.getmsg) I've always used a read handler for this in the past, and it worked fine. I don't have an example handy... -- Grant Edwards grante Yow! Like I always at say -- nothing can beat visi.com the BRATWURST here in DUSSELDORF!! From tim.golden at viacom-outdoor.co.uk Fri Aug 29 04:52:46 2003 From: tim.golden at viacom-outdoor.co.uk (Tim Golden) Date: 29 Aug 2003 01:52:46 -0700 Subject: NetServerDiskEnum in win32net References: Message-ID: <8360efcd.0308290052.4e0e6f67@posting.google.com> Uwe Becher wrote in message news:... > I try to get all logical drives of a remote machine (WinNT or W2K) and > get a result, that gives me the expected total but not all expected drives. > > Example: > > >>> win32net.NetServerDiskEnum('nor1w020', 0) gives me: > ([u'A:', u'', u'C:', u'', u'D:', u'', u'E:', u''], 8, 0) > > while the machine has the local drives > A: C: D: E: F: G: H: Z: > A: - Floppy > Z: - CDROM > All others are harddisk partitions on two physical drives > > Does anyone have an idea? > > Thanks > Uwe I had the same problem, and to my shame I didn't raise it as a bug, I simply bypassed it (because my DBA needed the info immediately anyway) by using wmi. Have a look at http://tgolden.sc.sabren.com/python/wmi.html and then try something like this: import wmi c = wmi.WMI ("") # or whatever host name for disk in c.Win32_LogicalDisk (DriveType=3): print disk.Caption TJG From aleax at aleax.it Thu Aug 21 06:53:18 2003 From: aleax at aleax.it (Alex Martelli) Date: Thu, 21 Aug 2003 10:53:18 GMT Subject: What's better about Ruby than Python? References: <3F41505F.69D18CC8@alcyone.com> <66d7kvonvb2n0nqbqahhd5roak7ur81sob@4ax.com> <3f43ef5d_4@127.0.0.1> <3F440A35.9030602@nyc.rr.com> <4o_0b.1665$Ej6.1182@newsread4.news.pas.earthlink.net> <8D01b.1721$Ej6.702@newsread4.news.pas.earthlink.net> Message-ID: Andrew Dalke wrote: > Alex Martell: >> ... def __get__(self, obj, cls): >> ... self.obj = obj >> ... return self.cached_call > > That's the part where I still lack understanding. > > class Spam: > def f(self): > pass > f = CachedCall(f) That's an oldstyle class -- use a newstyle one for smoothest and most reliable behavior of descriptors > > obj = Spam() > obj.f() > > Under old-style Python > obj.f is the same as getattr(obj, "f") This equivalence holds today as well -- the getattr builtin has identical semantics to direct member access. > which fails to find 'f' in the instance __dict__ > so looks for 'f' in the class, and finds it > This is not a Python function, so it does not > get bound to self. It's simply returned. > > obj.f() takes that object and calls it. In my original > code (not shown) I tried implementing a __call__ > which did get called, but without the instance self. Sure. > Under new-style Python > obj.f is the same as getattr(obj, "f") Yes. > which fails to find 'f' in the instance __dict__ so > looks for 'f' in the class, and finds the CachedCall. Sure. > Python checks if the object implements __get__, > in which case it's called a descriptor. If so, it's Exactly. > called with the 'obj' as the first parameter. The > return value of this call is used as the value for > the attribute. > > Is that right? Yes! So what is it that you say you don't get? >> should closely mimic your semantics, including ignoring >> what I call obj and you call self in determining whether >> a certain set of argumens is cached. > > Why should obj make a difference? There's only > one CachedCall per method per .... Ahh, because it's > in the class def, not the instance. Adding support for > that using a weak dict is easy. If obj is such that it can be used as a key into a dict (weak or otherwise), sure. Many class instances of some interest can't -- and if they can you may not like the result. COnsider e.g. class Justanyclass: def __init__(self, x): self.x = x def compute(self, y): return self.x + y pretty dangerous to cache THIS compute method -- because, as a good instance method should!, it depends crucially on the STATE of the specific instance you call it on. > Yeah, and my approach won't work with kwargs nor any > other unhashable element. Since I didn't know what the > Lisp code did nor how Lisp handles unhashable elements, > I decided just to implement the essential idea. An automatically cachable method on general objects is quite tricky. I don't think the Lisp code did anything to deal with that trickiness, though, so you're right that your code is equivalent. Anyway, I just wanted to show how the descriptor concept lets you use a class, rather than a function, when you want to -- indeed any function now has a __get__ method, replacing (while keeping the semantics of) the old black magic. Alex From heikki_salo at nobulkmailplease.sci.fi Mon Aug 11 03:53:58 2003 From: heikki_salo at nobulkmailplease.sci.fi (Heikki Salo) Date: Mon, 11 Aug 2003 10:53:58 +0300 Subject: A cgi buffering problem? Message-ID: I have a strange problem with a cgi-script of mine. The script examines some html-pages and then sends their modified content to the browser (into a textbox) so you can easily change and save them. The problem is quite strange: with a 56k modem there is no problem, but when using 10mb/s connection the output to the browser gets messy. Some of the text that was supposed to go into the textbox appears at the end of the page. And that is not all. Some of the pages work well on 10mb/s connection (there are 4 pages currently). The smallest page (=smallest output) works always correctly, the largest never works and the pages between work randomly (yes, randomly! When trying 10 times they usually work 2 times). This looks like some kind of buffering problem to me, but I don't have many ideas left. Python version is 2.3 All help is appreciated. From vanevery at 3DProgrammer.com Mon Aug 18 14:36:53 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Mon, 18 Aug 2003 11:36:53 -0700 Subject: What's better about Ruby than Python? References: <87ekzj6pbz.fsf@pobox.com> Message-ID: John J. Lee wrote: > > The really major differences are: Perl has tons of library code > (though Python has lots) and Perl has a pile of stuff you have to > learn that brings no significant benefits. It'd be great to see more > research on the impact of the nonsense-overhead that comes with Perl > (and is absent from Python). Don't leave out the possibility that cults of expertise can sustain careers and book publishers. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From just at xs4all.nl Fri Aug 15 14:01:42 2003 From: just at xs4all.nl (Just) Date: Fri, 15 Aug 2003 20:01:42 +0200 Subject: Module access from inside itself References: Message-ID: In article , Steven wrote: > I'm writing a Python script which can be called from the command-line, and > I want to use my module doc string as the CL help text, but I don't know > how to access my module object from inside the module. > > I've tried searching for an answer, but haven't found anything. Please > excuse me if I'm missing something simple, I'm a newbie to Python. > > I'm doing something like this: > > > > #!/usr/bin/python > """Module doc string goes here. > """ > > import getopt, sys > > def MyFunction(args): > ? ? pass > > if __name__ == "__main__": > ? ? opts, args = getop.getopt(sys.argv[1:], [], ["help"]) > ? ? for opt in opts: > ? ? ? ? if opt == "--help": > ? ? ? ? ? ? print MY_MODULE.__doc__ ? ?# How do I get this? > ? ? ? ? else: > ? ? ? ? ? ? MyFunction(args) > > > > How do I get a reference to the module from inside the module? Is this > the Pythonic way of generating help strings for CL scripts? You can just access __doc__ directly. No module prefix neccesary. Just From fsc at fuentez.com Tue Aug 26 03:40:54 2003 From: fsc at fuentez.com (fsc at fuentez.com) Date: Tue, 26 Aug 2003 03:40:54 -0400 Subject: EMAIL REJECTED Message-ID: <200308260740.h7Q7erEr024599@wmsc.fuentez.com> Violation found in email message. From: python-list at python.org To: hildjj at fuentez.com From jdhunter at ace.bsd.uchicago.edu Mon Aug 18 14:31:37 2003 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Mon, 18 Aug 2003 13:31:37 -0500 Subject: GTK import doesn't import first time In-Reply-To: <4a555b17.0308180759.48c99878@posting.google.com> (dsylvest@adelphia.net's message of "18 Aug 2003 08:59:55 -0700") References: <4a555b17.0308180759.48c99878@posting.google.com> Message-ID: >>>>> "Dennis" == Dennis writes: Dennis> I've downloaded and installed per the instructions the Dennis> pyGTK and GTK+ for win32 from the above locations. Dennis> Folowing the instructions, I import pygtk first, run Dennis> pygtk.require('2.0') second and then import gtk. I Dennis> receive an error on the import gtk the first time, but Dennis> immediately after, if I import again it works. Even if I Dennis> don't impo0rt pyGTK at all and only import gtk, I get the Dennis> same results. Any ideas? The reason it "works" the second time is that it doesn't try and import it again after the first. So it did not really work. Did you download and install the GTK runtime from http://www.dropline.net/gtk? If you installed it to to C:\GTK, you'll need C:\GTK\bin and C:\GTK\lib in your path. John Hunter From kenfettig at btinet.net Tue Aug 5 21:17:01 2003 From: kenfettig at btinet.net (Ken Fettig) Date: Tue, 5 Aug 2003 20:17:01 -0500 Subject: converting an integer to a string Message-ID: I have a quick simple question. How do you convert an integer to a string in Python? Thanks Ken Fettig mailto:kenfettig at btinet.net From jjl at pobox.com Fri Aug 29 14:16:14 2003 From: jjl at pobox.com (John J. Lee) Date: 29 Aug 2003 19:16:14 +0100 Subject: Bayesian kids content filtering in Python? References: <20030828161409.V40715@onyx.ispol.com> Message-ID: <87n0dsqqhd.fsf@pobox.com> "Paul Paterson" writes: > "Gregory (Grisha) Trubetskoy" wrote in message > news:20030828161409.V40715 at onyx.ispol.com... > > > > I've been snooping around the web for open source kids filtering software. > > Something that runs as an http proxy on my home firewall and blocks > > certain pages based on content. > > > > It occured to me that this might be an interesting project to be done in > > Python, probably using the same training and scoring mechanism that > > spambayes uses. > > > > Anyway - I wonder if anyone has already tried something like this? > > As Rene points out in his response,after some great advice and discussion > from Skip I gave this a try. It works very well. I added a module to a proxy [...] > of concept but I have copied the code I ended up with below. It certainly > seems to work and has application both for parental filtering and other > kinds of content management. [...] Careful: This same idea occurred to me a while ago, but there is one obvious problem: email filters and the category of web filters that you're talking about have rather different problems to solve. Email filters are usually designed to work in the user's interests and act on content that is sent to the user by others; false negatives are not very important. Web filters are often designed to work against the user's interests and act on material that is actively retrieved by the user (and so might change completely from training time to use time); false negatives are important. It will no doubt work well for situations where you want to, for example, block pop-ups, advertising, and other stuff that one tends to bump into whilst going about one's normal surfing business. But if somebody (children, employees, and other people not to be trusted ;-) is actually trying to work around your barriers, there are always likely to be false negatives: sites of a flavour that you've never seen before that you'd wish would trigger your defences, but won't. If the filter has never even seen that *kind* of page before, it can't be expected to work. Unfortunately (or fortunately, depending on the case at hand), there are many kinds of pages that people want to censor, and you're not going to block them all. It may work well most of the time, but is that enough? What's needed here, perhaps, is an open effort to train on categories of things that people would like to block. That might be enough, since I suppose *most* things you're trying to block, in the case of kids, are not actually targetted at them, so arms races are not likely to develop. In no way invalidates the idea, of course -- just limits it. John From peter at engcorp.com Fri Aug 29 09:35:39 2003 From: peter at engcorp.com (Peter Hansen) Date: Fri, 29 Aug 2003 09:35:39 -0400 Subject: python and webcam?? References: Message-ID: <3F4F56AB.19EFE5AB@engcorp.com> Mirco wrote: > > Hi, > I'd like to know if is it possible to make python communicate with a > webcam. Of course, I think it is possible... but I don't know if there > is a specific module for this kind of work. Can anyone give me a council? Depends a lot on the type of webcam, but in any case it's a pretty safe bet that (a) it's possible, and (b) there is no *specific* module for the task. That said, there are things like PIL which could be of use in this area, and at least one specific webcam package (probably using calldll to get to the library for the device) that has been posted in the past. -Peter From bokr at oz.net Sun Aug 31 16:58:49 2003 From: bokr at oz.net (Bengt Richter) Date: 31 Aug 2003 20:58:49 GMT Subject: Update to Python 2.3 on Red Hat Linux 9 References: <8242f4a7.0308282240.4c87f997@posting.google.com> Message-ID: On 31 Aug 2003 04:13:11 +0200, martin at v.loewis.de (Martin v. =?iso-8859-15?q?L=F6wis?=) wrote: >jaybromley at hotmail.com (Jay Bromley) writes: > >> So the questions is, can I build Python 2.3 so that it recognizes all >> the packages that are available to Python 2.2.2? Is this LD_RUN_PATH >> stuff? > >You can't; this is not supported. > >The ABI has changed, so the old modules just wouldn't work anymore if >they were found. > >> Or do I really need to find out all the libraries in use with >> 2.2.2 and compile these for 2.3? > >Yes. > Is this highly automated, or a gross PITA? Regards, Bengt Richter From grante at visi.com Mon Aug 4 16:49:49 2003 From: grante at visi.com (Grant Edwards) Date: 04 Aug 2003 20:49:49 GMT Subject: Tools for reading Dr Dobb's Python-URL References: <3f23bc25$0$49102$e4fe514c@news.xs4all.nl> Message-ID: <3f2ec6ed$0$161$a1866201@newsreader.visi.com> In article , Egbert Bouwman wrote: > On Sun, Jul 27, 2003 at 01:48:55PM +0200, Irmen de Jong wrote: >> >> Open the message in your news reader. >> Click on an URL in the message. >> >> Sorry, couldn't resist. I'm not sure what you want to >> do, really? > > My mail reader is the text-based Mutt, which: > - doesn't react to mouse clicks > - does show url's in a different color > - seems not to do anything useful with them FWIW, my mutt highlights URLs. I double click on one (which copies it to the X11 clipboard), and then I have a root window window menu entry which starts opera using the URL from the clipboard. -- Grant Edwards grante Yow! I want to dress you at up as TALLULAH BANKHEAD and visi.com cover you with VASELINE and WHEAT THINS... From ny_r_marquez at yahoo.com Fri Aug 8 08:58:10 2003 From: ny_r_marquez at yahoo.com (R.Marquez) Date: 8 Aug 2003 05:58:10 -0700 Subject: Before I submit a bug report (Pythonwin) References: <8a27e309.0308061019.72656417@posting.google.com> <8a27e309.0308070506.60172bc6@posting.google.com> Message-ID: <8a27e309.0308080458.63220dd5@posting.google.com> Well, I went ahead and decided to start from scratch. I removed py2exe, wxpython, win32 extensions and Python23. I deleted any remnants of the installation folder. I went to the registry and deleted the Python23 key. I rebooted the machine. I installed Python into D:\Programs\Python23, and it installed correctly. I then installed win32all-155.exe. It all seemed to go well, the Start Menu shortcuts were created, no errors. But when I tried to start the Pythonwin application it failed again with the same error message: exceptions.ImportError: No module named pywin.framework.startup Again, when I launch the following, the app starts fine: D:\Programs\Python23\Lib\site-packages\Pythonwin\start_pythonwin.pyw But, if I launch the following, I get the error: D:\Programs\Python23\pythonwin.exe I guess it is bug report time. :( -Ruben ny_r_marquez at yahoo.com (R.Marquez) wrote in message news:<8a27e309.0308070506.60172bc6 at posting.google.com>... > Oops, I realised this morning that my initial post has an error (that > is what I get from writing from memory). I didn't upgrade from Python > 2.2.2, but from Python2.3c1. And another significant detail is that I > chose a completely different location on the disk for the 2.3 final > installation. I wonder if Pythonwin is looking in the old Python2.3 > location for something. > > I added Python2.3 to the path environment variable, and got the same > results. I then went trough the registry searching for the old > Python2.3 folder. I found an occurrance inthe following key: > HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32\OpenSaveMRU\exe > > I changed it to the new Python2.3 location, but Pythonwin still won't > start. Any ideas? > > -Ruben > > ny_r_marquez at yahoo.com (R.Marquez) wrote in message news:<8a27e309.0308061019.72656417 at posting.google.com>... > > I uninstalled my 2.2.2 version of Python and related packages from my > > XP Professional station and proceeded to upgrade to the latest and > > greatest: Python2.3, win32all-155.exe, etc. > > > > When I try to start the Pythonwin editor, either through its shortcut > > or through right clicking on an existing module, a window pops up with > > the message: > > > traceback>exceptions.ImportError: No module named > > pywin.framework.startup > > > > After, closing the window nothing happens. > > > > I was able to start the editor by double clicking on: > > Python23\Lib\site-packages\Pythonwin\start_pythonwin.pyw > > > > So, I assume the problem has to do with the installation process. > > > > This is the first time I have ever had a problem with Pythonwin (the > > editor), so I'm a little surprised. Am I the only one having this > > problem? > > > > -Ruben From jjl at pobox.com Sat Aug 23 12:10:55 2003 From: jjl at pobox.com (John J. Lee) Date: 23 Aug 2003 17:10:55 +0100 Subject: macro FAQ References: <2259b0e2.0308222250.2e7f51b6@posting.google.com> Message-ID: <877k54bbhs.fsf@pobox.com> mis6 at pitt.edu (Michele Simionato) writes: > "Andrew Dalke" wrote in message news:... > > Here's a proposed Q&A for the FAQ based on a couple recent > > threads. Appropriate comments appreciated > > > > X.Y: Why doesn't Python have macros like in Lisp or Scheme? [...] > I think your document should be made available on the Web somewhere, > but not in the FAQ. Of course the FAQ could and should give a pointer > to it. [...] +1, FWIW John From vze4rx4y at verizon.net Tue Aug 12 02:57:05 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Tue, 12 Aug 2003 06:57:05 GMT Subject: Summer reading list Message-ID: <5d0_a.288$jw4.85@nwrdny03.gnilink.net> Found in a pamphlet at a pre-school: --------------------------------------- Reading improves vocabulary Reading raises cultural literacy through shared knowledge Reading develops writing skills Reading opens the mind to new ways of understanding Reading is fun Accordingly, I suggest the following works of literature: * heapq.py (255 lines) * sets.py (536 lines) * textwrap.py (355 lines) * csv.py (427 lines) These make enjoyable reading, cover interesting topics/algorithms, demonstrate superb modern python technique, and showcase effective use of Python's newer features. Learn from the masters: Pinard, O'Connor, Peters, Wilson, Martelli, van Rossum, Ward, Montanaro, Altis, Drake, and others have-you-read-any-good-code-lately-ly yours, Raymond Hettinger P.S. The unittests for sets.py are *not* as enjoyable reading; however, they are a highly instructive example of Greg's sophisticated use of the testing framework and his unusally thorough approach to deciding what and how to test. Lib/test/test_sets.py (692 lines) Learning from Greg's example enabled me to use similar ideas in developing Lib/test/test_random.py (298 lines). From jjl at pobox.com Wed Aug 27 14:51:47 2003 From: jjl at pobox.com (John J. Lee) Date: 27 Aug 2003 19:51:47 +0100 Subject: Mac equivalent to COM in Windows? References: <78kkkvg8ckfio141es2of1p483ohbtbit5@4ax.com> <78kkkvg8ckfio141es2of1p483ohbtbit5@4ax.com> <87ekz7tdty.fsf@pobox.com> <7h3vfsjcigb.fsf@pc150.maths.bris.ac.uk> Message-ID: <87ad9v9bng.fsf@pobox.com> Michael Hudson writes: > jjl at pobox.com (John J. Lee) writes: > > > Bob Gailer writes: > > > > > Is there a way for a Python program to interact with MS Excel on the > > > Macintosh? My goal is to extract contents of cells. > > > > I'd be interested in the answer to that, too. Surely COM must be in > > there somewhere? This is the wrong newsgroup to find out, though. > > The Mac-ish anser is apple events. I don't know whether Excel's Apple > Event support is useful on the Mac, though. Interesting. I was wondering about COM itself, though. John From oren-py-l at hishome.net Sun Aug 10 02:55:55 2003 From: oren-py-l at hishome.net (Oren Tirosh) Date: Sun, 10 Aug 2003 02:55:55 -0400 Subject: crossplatform py2exe - would it be useful? In-Reply-To: References: <2UyYa.50516$cl3.1586459@news2.tin.it> Message-ID: <20030810065555.GA47359@hishome.net> On Fri, Aug 08, 2003 at 05:31:35PM +0200, Thomas Heller wrote: ... > Sounds much like the way py2exe already works now. It locates the > appended zip-file by searching the exefile from the end, then finds the > beginning of the zipfile, and looks for a magic number there, which is > used to verify that the next n bytes before this position is a C > structure containing the required flags. > > I don't like the idea to scan the executable for a magic signature > without further hints where this should be. I wasn't suggesting scanning the executable at runtime. When py2exe reads the python executablein order to create a copy with an appended zip archive it might as well scan for a signature and modify the customization area that follows it. When this customized interpreter loads the customization values will already be in memory in the form of an initialized variable. If the interpreter detects that the customization area has been modified it will interpret it as command-line arguments instead of argv. This enables complete control of things like compiler flags, optimization flag, ignoring environment, etc. A short "-c" string can be used for bootstrapping the appended zip. The call to PySys_SetArgv would use the real argv, if course. Oren From duncan at NOSPAMrcp.co.uk Mon Aug 18 04:34:31 2003 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Mon, 18 Aug 2003 08:34:31 +0000 (UTC) Subject: python threads on multi-CPU machines References: Message-ID: Thomas Womack wrote in news:vQn*aWb0p at news.chiark.greenend.org.uk: > If I have a dual-processor hyperthreaded machine (so with four CPU > contexts), will a python program distribute threads over all four > logical processors? > > I ask because I'm fairly sure that this *does* happen using the > threading extensions in MFC, and fairly sure that it *doesn't* when > using Java, so I don't see that the result is obvious for python. The C implementation of Python uses a global interpreter lock that only allows one thread to interpret bytecode at a time, so while the threads may be distributed across multiple processors you will get little or no speedup over a single processor. (If your threads spend most of their time in a non-Python extension, they may be able to get some benefit from multiple processors). The only way to take advantage of multiple processors with Python is to run at least one separate process for each processor. For example, I believe Zope will take advantage of multiple processor systems if you run it in ZEO client/server mode with several Zope client processes. I believe that Jython simply does whatever the Java implementation does. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From skip at pobox.com Sun Aug 3 14:46:08 2003 From: skip at pobox.com (Skip Montanaro) Date: Sun, 3 Aug 2003 13:46:08 -0500 Subject: PyChecker work with Python 2.3? In-Reply-To: <3F2D3EF5.DAF09C1C@easystreet.com> References: <3F2C5300.FA223CBA@easystreet.com> <3F2CBCC2.3FC51D57@easystreet.com> <3F2D3EF5.DAF09C1C@easystreet.com> Message-ID: <16173.22640.342735.270688@montanaro.dyndns.org> >> If you think you are so smart, why don't you use your time more >> economically then and just try it out? al> If I upgrade python to 2.3 I also must upgrade: al> ctypes al> py2exe al> pysqlite al> win32all al> wxPython Just to see if pychecker works? Why not just configure Python with a different --prefix=... flag? That's assuming you're on a unix-like system. If you're on Windows (as it appears you are), Python 2.3 installs in c:\Python23 by default which shouldn't disturb your earlier Python installation unless you were tanked the day you installed it and put it in c:\Python23. Skip From mpeuser at web.de Sat Aug 23 16:56:16 2003 From: mpeuser at web.de (Michael Peuser) Date: Sat, 23 Aug 2003 22:56:16 +0200 Subject: Mcmillan Installer without python.dll ? Message-ID: Hi, I am still trying to deploy a python program as a single exe file. There are some possibilities if you want to include tkxx.dll, tclxx.dll and pythonxx.dll. If not it tirens out to be more difficult. I was without luck using py2exe (I posted here some days ago). Using Mcmillan's Installer is a step forward. The tool is straightforward to use and has sufficient documentation (and a lot of options). I manipulated a.binaries as well as used exclude_binaries to get rid of pythonxx.dll and Tcl/Tk in the exe file. This reduced size from 1,4 MB to 900 k when removing tcl/tk and the exe worked still fine. Removing pythonxx.dll reduced it to 300k which was what I intended. However now funny errors occur when starting the exe: Traceback (most recent call last): File "", line 5, in ? File "C:\Python\Downloads\Installer\iu.py", line 277, in importHook mod = _self_doimport(nm, ctx, fqname) File "C:\Python\Downloads\Installer\iu.py", line 347, in doimport mod = director.getmod(nm) File "C:\Python\Downloads\Installer\iu.py", line 184, in getmod mod = owner.getmod(nm) File "C:\Python\Downloads\Installer\archive.py", line 358, in getmod raise ImportError, "PYZ entry '%s' (%s) is not a valid code object" % (nm, r epr(co)) ImportError: PYZ entry 'psyco' (0j) is not a valid code object (psyco was by chance the first imported modul.) Any suggestions? Kindly Michael P From irmen at -NOSPAM-REMOVETHIS-xs4all.nl Sun Aug 17 05:36:49 2003 From: irmen at -NOSPAM-REMOVETHIS-xs4all.nl (Irmen de Jong) Date: Sun, 17 Aug 2003 11:36:49 +0200 Subject: simple text parser? In-Reply-To: References: Message-ID: <3f3f4caf$0$49113$e4fe514c@news.xs4all.nl> Brandon J. Van Every wrote: > Can anyone recommend simple text parsers implemented in Python? You can use Python's own pickle mechanism to serialize almost any Python object(s). But you won't be able to read it back in if you also want to build it in another language such as C# that you mentioned. Perhaps you're better off using a simple .ini file structure, that should be *very* easy to parse in C# (I suspect it has .ini file parsing support built-in) and Python has the ConfigParser module. Or you could use a CSV (Comma Separated Values) file format, that is easily generated and parsed from Python's csv module and should also be easy to do from other languages. Alternatively you can go for something like this: ---------------- item1=value1 item2=value2 item3=value3 ... ---------------- This is perhaps the easiest to create and parse, because in Python, you just execfile() or eval() the file back in. Warning: if somebody puts extra Python code in it, that will be executed. HTH, --Irmen de Jong From tzot at sil-tec.gr Wed Aug 20 09:46:19 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Wed, 20 Aug 2003 16:46:19 +0300 Subject: Py2.3: Feedback on Sets - diffudict.txt (0/1) References: <42n5kv02867rn9skagsdie9ucg11ki30g8@4ax.com> Message-ID: On Wed, 20 Aug 2003 06:10:19 +0300, rumours say that Christos "TZOTZIOY" Georgiou might have written: >A quick thought, in the spirit of C implementation: there are cases >where I would like to get the intersection of dicts (based on the keys), >without having to create sets from the dict keys and then getting the >relevant values. That is, given dicts a and b, I'd like: > >>>> a & b # imaginary > >to mean > >>>> dict([x, a[x] for x in sets.Set(a) & sets.Set(b)]) # real > >You may notice that a&b wouldn't be equivalent to b&a. >Perhaps the speed difference would not be much; I'll grow a function in >dictobject.c, run some benchmarks and come back with results for you. I implemented dict.intersect(), and it is *quite* faster than the equivalent Python code. ********************************************************************** Python 2.4a0 (#3, Aug 20 2003, 16:31:22) [GCC 3.2 (Mandrake Linux 9.0 3.2-1mdk)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> help(dict.intersect) Help on method_descriptor: intersect(...) D.intersect(E) -> a subset of D having common keys with E >>> import sets >>> odds = dict(zip("abcdefghijklmn", range(1, 55, 2))) >>> evens= dict(zip("asdfghj", range(2, 55, 2))) >>> >>> odds {'a': 1, 'c': 5, 'b': 3, 'e': 9, 'd': 7, 'g': 13, 'f': 11, 'i': 17, 'h': 15, 'k': 21, 'j': 19, 'm': 25, 'l': 23, 'n': 27} >>> evens {'a': 2, 'd': 6, 'g': 10, 'f': 8, 'h': 12, 'j': 14, 's': 4} >>> >>> >>> dict([(k, odds[k]) for k in sets.Set(odds) & sets.Set(evens)]) {'a': 1, 'd': 7, 'g': 13, 'f': 11, 'h': 15, 'j': 19} >>> odds.intersect(evens) {'a': 1, 'h': 15, 'j': 19, 'd': 7, 'g': 13, 'f': 11} >>> dict([(k, evens[k]) for k in sets.Set(odds) & sets.Set(evens)]) {'a': 2, 'd': 6, 'g': 10, 'f': 8, 'h': 12, 'j': 14} >>> evens.intersect(odds) {'a': 2, 'h': 12, 'j': 14, 'd': 6, 'g': 10, 'f': 8} >>> >>> >>> my_setup= 'import sets; odds=dict(zip("abcdefghijklmn", range(1, 55, 2))); evens=dict(zip("asdfghj", range(2, 55, 2)))' >>> from timeit import Timer >>> >>> Timer(stmt="odds.intersect(evens)", setup=my_setup).repeat() [1.3545670509338379, 1.3367550373077393, 1.3366960287094116] >>> Timer(stmt="evens.intersect(odds)", setup=my_setup).repeat() [1.321492075920105, 1.2869999408721924, 1.320341944694519] >>> Timer(stmt="dict([(k, odds[k]) for k in sets.Set(odds) & sets.Set(evens)])", setup=my_setup).repeat() [63.413245916366577, 63.526772975921631, 63.503224968910217] >>> Timer(stmt="dict([(k, evens[k]) for k in sets.Set(odds) & sets.Set(evens)])", setup=my_setup).repeat() [63.498296976089478, 63.49311900138855, 63.425426959991455] ********************************************************************** A substantial difference, over 50x on an Athlon XP 1700. Also note the difference in the key order of the results. I believe that dicts should grow such a method, perhaps with another name. Attached is the diff -u for dictobject.c compared to the one in last night's python-latest.tgz -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From jacek.generowicz at cern.ch Sun Aug 24 05:31:54 2003 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 24 Aug 2003 11:31:54 +0200 Subject: macro FAQ References: <1ffd32d9.0308232315.3eadd758@posting.google.com> Message-ID: dtolton at yahoo.com (Doug Tolton) writes: > Also note that the examples presented are purposefully trivial and > could in many instances be accomplished other ways, I hoped that the examples that I presented satisfied the requirements that a) They be simple enough to understand b) not be (at least easily) implementable using existing Python features c) Not be completely useless Did I fail ? :-) > Essentially Macros allow you to pass in some variables that are then > expanded into valid Python syntax which is then executed. Well, not just variables, data in general, some of which might be variables, some of which might be variable names (identifiers) and some of which might be (peudo-) code. > Question: Can't I accomplish this same functionality via string > parsing and eval? > > Answer: Eval will accept any valid Python expression and execute it. > This is however regarded by many as a security hole. Macros allow > this type of expressiveness while limiting many of the security risks. > With a Macro you can more specifically control what types of actions > are permissible. I don't think that this is relevant (or true, for that matter). Lisp macros do not expand arbitrary data that a user passes in, they appear as literals in your source code. The security issues are the same as those surrounding "os.system('rm -rf /')" appearing literally in your source code. What is relevant, is the pain involved in doing it via strings. The (pseudo) code that you pass to a Lisp macro, not only looks exactly like Lisp code, but it is automatically tokenized and parsed for you, and very easily manipulatable. > # Note, Jacek's method of using indentation is an interesting > alternative to calling them as a > # function. It's probably worth pointing out, again, how important Lisp's uniformity of syntax is, for its macro system. Generally speaking, a macro accepts as arguments some mixture of data, identifiers and expressions (let's forget about the existence of Python statements for now, they complicate the situation even more). How do you pass in a mixture of data and code? Data is usually presented in a tuple: foo(datum1, datum2, datum3) Expressions are usually presented on separate lines: def foo(...): expression1 expression2 expression3 Let's try to think of what a Python with-open-file macro call would look like. In CL, with-open-file takes 1) a list containing an identifier (a symbol), a pathname (let's call it a string) with some optional keywords. 2) arbitrary code It then binds the identifer to a stream associated with the file, and expands the source code inside an exception handling environment. So, the expansion of a (simplistic) Python with_open_file might look like this: outfile = file("foo/bar", "w") try: print >> outfile, foo(...) for i in range(10): print >> outfile, bar(...) except: perform the necessary closing and cleaning up But what should the corresponding call to with_open_file look like? We have to pass in the identifier "outfile" (this is where it is very handy to have symbols as a first-class data type, as in Lisp), and the file name "foo/bar" ... but then we also have to pass in the chunk of code print >> outfile, foo(...) for i in range(10): print >> outfile, bar(i) In Lisp it would look something like this: (with-open-file (outfile "foo/bar" :direction :output) (format outfile "~a" (foo ...)) (dotimes (i 10) (format outfile "~&~a" (bar i)))) Now, I refuse to contemplate passing the source code in a string, in the Python version. Maybe we have to accept the distinction between data-like data, and code-like data, having the macro accept both a tuple of arguments, and blocks of code, so the call might look thus: with_open_file("outfile", "foo/bar", "w"): code: print >> outfile, foo(...) for i in range(10): print >> outfile, bar(...) (If you need to pass in more than one code block, each one would go in a seperate "code:" block.) What could the definition look like? defmacro with_open_file(stream, filename, mode)(block1) expand(stream) = file(filename, mode) try: expand(block1) except: perform the necessary closing and clearing up (expand would be a function which gets replaced by its argument, at macro expansion time.) Hmm, just about bearable, I guess, but I doubt that it generalizes very well. Note that we didn't transform the source code argument, just pasted it in directly. If we wanted to manipulate it first, we'd be in for serious suffering. > You could clearly accomplish this functionality using other means, I think it is best to steer clear of such examples, as experience shows that some people will not be able to resist the temptation to conclude (and suggest) that there is no point to macros, and the discussion gets derailed. We've seen enough of "you could do this quite easily without macros, but ...", and not enough of "This would be soooo painful without macros ..." (I won't say "impossible", as there is always Turing completeness.) What was wrong with my original examples? I'd like to know, so that I can replace them with better ones. From and-google at doxdesk.com Sun Aug 3 18:05:07 2003 From: and-google at doxdesk.com (Andrew Clover) Date: 3 Aug 2003 15:05:07 -0700 Subject: 'print' in a CGI app. References: Message-ID: <2c60a528.0308031405.7a47beee@posting.google.com> "Andrew Chalk" wrote: > print "Hello\n" > print "World" > print both words on the same line in IE6. This is because IE is treating the page as HTML by default, where whitespace is not significant. If this is not what you want, set the 'Content-Type' HTTP header to something else, eg.: #!/usr/bin/python print 'Content-Type: text/plain; charset=utf-8' print print 'Hello' print 'World' -- Andrew Clover mailto:and at doxdesk.com http://www.doxdesk.com/ From irmen at -NOSPAM-REMOVETHIS-xs4all.nl Sun Aug 3 16:37:33 2003 From: irmen at -NOSPAM-REMOVETHIS-xs4all.nl (Irmen de Jong) Date: Sun, 03 Aug 2003 22:37:33 +0200 Subject: Passing a string argument by reference In-Reply-To: References: Message-ID: <3f2d728a$0$49117$e4fe514c@news.xs4all.nl> Andrew Chalk wrote: > I am a raw beginner to Python. I just read in "Learning Python" that > assigning to a string argument inside a function does not change the string > in the caller. I want an assignment in the function to alter the passed > string in the caller. Is there any way to do this? No. Strings are immutable. However, there is a better solution to do what you want: just return the new value as a result of the function, and let the caller process this further. Example: def addBarToString(variable): return variable+"bar" called with: variable="foo" variable=addBarToString(variable) print variable results in >>foobar<< to be printed. > For example > > def SafeAdd(self, Variable, Value): > if self.form.has_key( Value ): > Variable = self.form[Value].value > > Called with: > > self.SafeAdd(self.txtCIF, 'txtCIF') > > self.CIF is not changed on return from the function. How do I modify this so > that it is? I understand that you want to assign self.txtCIF (not self.CIF as you wrote) the value of self.form['txtCIF'], but only if that value occurs in self.form? There is a much easier way to do this. I suspect that self.form is a dictionary (or a dict-like object). Just use: self.txtCIF = self.form.get('txtCIF', self.txtCIF) The second argument to the get method is the default value that is returned if the required key is not present in the dict. In this case, it returns the 'old' value of self.txtCIF, so in effect, self.txtCIF will be unchanged if 'txtCIF' does not occur in self.form. Also see http://www.python.org/doc/current/lib/typesmapping.html Hope this helps! --Irmen de Jong From klapotec at chello.at Sat Aug 2 01:37:20 2003 From: klapotec at chello.at (Christopher Koppler) Date: Sat, 02 Aug 2003 05:37:20 GMT Subject: Python Windows 2.3 Installer problems References: Message-ID: On Fri, 01 Aug 2003 12:34:06 -1000, Timothy Martens wrote: >When I run the Python-2.3.exe on my WIN2K box and go through the initial >dialogues, the installer frezes at 1% when it's "Copying File >C:\Python23\UNWISE.exe" > >Any ideas ANYONE? Well, can't really pinpoint anything, as on my Win2K SP4 it works just fine. Others have already pointed out the obvious candidates antivirus and firewall software, as well as re-downloading (have you checked the MD5 checksum? If not, google for md5sum.exe, and try that (the checksum is at the bottom of the download page), it may be that your download was corrupted, and your re-download came from your ISP's cache and so was corrupted too). Apart from that I can only list everything that made problems in my earlier life as a sysadmin/network tech, in increasing order of unlikeliness: Have you tried it on a different computer, if you have access to one? Have you tried to disable everything, and I mean everything that Windows loads at startup time? Have you checked the harddisk? Have you defragmented your harddisk? Have you tried removing unnecessary (for Python) hardware, like TV cards, scanners, etc. As a last resort, have you tried to reinstall Windows, and the SP, and then Python before anything else? --Christopher From pyguy30 at yahoo.com Fri Aug 1 19:56:55 2003 From: pyguy30 at yahoo.com (john) Date: 1 Aug 2003 16:56:55 -0700 Subject: pytunnel 0.2 released Message-ID: <3d46c852.0308011556.71395360@posting.google.com> Pytunnel has been updated. It now has the ability to act as a standalone tunnelling server. It is typically useful for tunneling things like ssl through a proxy. The library is still being worked on but you should find it useful. You can find it at: http://savannah.nongnu.org/download/pytunnel/pytunnel.py Examples: Standalone mode: 1)Setup tunnel w/defaults: ./pytunnel.py --proxy_host phost --host login.yahoo.com 2)It returns a port to standard output that it started on. Use as a Library: 1)define your function, to use pytunnel supplied ip address and port def tunnel_this(ip='',port=0): conn = httplib.HTTPSConnection(ip,port=port) conn.putrequest('GET', '/').endheaders() response = conn.getresponse() 2)Build the tunnel tunnel=pytunnel.build(host=login.yahoo.com,\ proxy_host=phost,proxy_user=u,proxy_pass=p,timeout=0.5) tunnel.run(tunnel_this) From Hengsun.Chao at Cognos.Com Mon Aug 25 10:03:37 2003 From: Hengsun.Chao at Cognos.Com (Chao, Heng Sun) Date: Mon, 25 Aug 2003 10:03:37 -0400 Subject: [Stackless] Stackless ported to 2.2.3 Message-ID: I did so. The help works fine. However, I remember there was some variable I had to set to make the recursion work for 100000. Right now, recursion dies at before 1000 depth. Thanks, Heng Sun Chao System Solution Testing Cognos Inc. 738-1338 x 5051 -----Original Message----- From: Christian Tismer [mailto:tismer at tismer.com] Sent: Friday, August 22, 2003 11:37 PM To: Chao, Heng Sun Cc: Pythonistas; Stackless at tismer.com Subject: Re: [Stackless] Stackless ported to 2.2.3 Chao, Heng Sun wrote: > I have replaced the python22.dll. Unfortunately, the stackless > capability does not appear to be on. Are there any variables I have to set? The only thing you need to do is to import stackless, which is a built-in module. Python should crank up with a boot message that tells you about being Stackless 3.0 somthing. If not, your dll is not in place. Just try help("stackless"). If it works, you are fine. cheers - chris -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 mobile +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ Join us at Cognos' biggest event of the year Enterprise 2003, The Cognos Business Forum. Taking place in over 25 cities around the world, it's an opportunity for Business and IT leaders to learn about strategies for driving performance. Visit http://www.cognos.com/enterprise03 for more details. This message may contain privileged and/or confidential information. If you have received this e-mail in error or are not the intended recipient, you may not use, copy, disseminate or distribute it; do not open any attachments, delete it immediately from your system and notify the sender promptly by e-mail that you have done so. Thank you. -------------- next part -------------- An HTML attachment was scrubbed... URL: From fredrik at pythonware.com Wed Aug 6 07:26:47 2003 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 6 Aug 2003 13:26:47 +0200 Subject: Get the hostname References: <3F30E50B.9090300@semafor.ch> Message-ID: Lukas Schnieper wrote: > How can i get the hostname of my Linux PC? > I tried os.system('hostname') but i cant save the hostname in a variable > like hostname = os.system('hostname') how about import socket hostname = socket.gethostname() From bokr at oz.net Wed Aug 20 14:20:16 2003 From: bokr at oz.net (Bengt Richter) Date: 20 Aug 2003 18:20:16 GMT Subject: Adobe photoshop plug in References: Message-ID: On Wed, 20 Aug 2003 16:49:44 GMT, "Raymond Hettinger" wrote: > >[mustafa umut sarac] >> I am not a programmer. >> But I have a great plug in idea for photoshop. >> I want to complete the entire process bymyself with the help of friends. >> I want to ask that : is python language only or simplest language for to write >this plug in ? >> Do I need to read the entire photoshop code for to write the plug in ? > >In general, writing photoshop plugins is not a project for a beginner >programmer. >However, if your idea can be expressed in terms of existing photoshop actions, >then Python is an excellent choice for a scripting language. For that, you need >to >download win32all (see the link to it at www.python.org/2.3/ ) and then look at >Adobe's scripting guide at http://partners.adobe.com/asn/photoshop/scripting.jsp >. > >If you need a real plugin, then life is more complicated. To write photoshop >plugins in any language, I think you need to have Adobe's plugin SDK which >runs about $200. It was not designed for beginning programmers. I wonder why they charge for that (assuming you're right). ISTM if someone downloaded a copy and did nothing, it would be no loss. If OTOH they put in the hours to produce a desirable plugin, there would be at least a slight gain in PS marketability from the existence of the plugin. IWT selling PS is 'way more important to Adobe's revenues than selling the SDK. So is the SDK revenue worth the loss of the activity that would happen if it were free? I guess they must think so. To me it seems like a video card mfg selling device driver info. Regards, Bengt Richter From oussoren at cistron.nl Wed Aug 20 04:36:26 2003 From: oussoren at cistron.nl (Ronald Oussoren) Date: Wed, 20 Aug 2003 10:36:26 +0200 Subject: python-dev Summary for 2003-08-01 through 2003-08-15 In-Reply-To: <3F42049F.8E967572@engcorp.com> References: <3F42049F.8E967572@engcorp.com> Message-ID: <63823DC8-D2E9-11D7-AFF7-0003931CFE24@cistron.nl> On Tuesday, 19 August, 2003, at 13:06, Peter Hansen wrote: > Andrew Dalke wrote: >> >> I just use distutils and assume the person installing has told >> it where to install. I got confused amoung the options we >> have now, esp. since there's no "site-packages" under MS >> Windows. > > I'm probably way out of the loop on the discussion, but just in > case I'm not: there _is_ a site-packages in the MS Windows > installation of the last couple of major versions of Python. > Not in, I believe, 2.0, but probably those since. > > (Okay, by how much did I miss the point? :-) Not by too much ;-). The reason for my message to python-dev that was mentioned in the summary is that is can be usefull to have more than one site-packages directory. If an administrator has installed a python in a central location, I cannot add new python packages to the site-packages (because I cannot write in that directory). You could use PYTHONPATH for that, but having a standard location for user packages is more usefull. BTW: the actual reason I started to think about this is the Python 2.3 installation that will be in MacOS X. That installation is in the 'OS vendor' part of the file system (e.g. /WINNT on Windows), and if I add packages that install scripts these will also end up in the vendor part of the filesystem. That is not very nice. Most linux distributions have the same problem: the site-packages for the vendor-provided python is somewhere in /usr/lib, and that directory is owned by the vendor and should not contain locally installed software. And w.r.t. the PEP that was mentioned in the summary, I will write one once I find enough time to design and write a useable interface for this. Ronald From raims at dot.com Sat Aug 23 14:27:32 2003 From: raims at dot.com (Lawrence Oluyede) Date: Sat, 23 Aug 2003 20:27:32 +0200 Subject: Python is darn fast (was: How fast is Python) References: <2259b0e2.0308230737.8a9bc1c@posting.google.com> <3F47AA73.7040104@draigBrady.com> Message-ID: P at draigBrady.com wrote: > If you want to try different machines > then http://www.pixelbeat.org/scripts/gcccpuopt will give > you the appropriate machine specific gcc options to use. Very cool script, thanks :) Anyway it didn't change so much with erf.c $ time ./erf real 0m0.190s user 0m0.157s sys 0m0.001s $ time ./erfCPU real 0m0.180s user 0m0.146s sys 0m0.002s erfCPU is compiled with the flags suggested by gcccpuopt script: $ gcccpuopt -march=athlon-xp -mfpmath=sse -msse -mmmx -m3dnow -- Lawrence "Rhymes" Oluyede http://loluyede.blogspot.com rhymes at NOSPAMmyself.com From tomas at fancy.org Fri Aug 29 02:10:34 2003 From: tomas at fancy.org (Tom Plunket) Date: Thu, 28 Aug 2003 23:10:34 -0700 Subject: OT: Celebrity advice References: <3F4D0D8B.5E5F9488@engcorp.com> <3F4D3560.71995AEB@engcorp.com> Message-ID: <0frtkvs8b0opk8ubr6qrce2dntq09e6q2t@4ax.com> Alex Martelli wrote: > > Just as a question of biology, a person can be locked in handcuffs, or > > in a metal cage, and be neither dead nor have the power to kill others. > > This limit comes not out of the compromise and will-power of the > > detained person, but simply out of physics and anatomy. In most > > "ultimate" cases of state-sponsored violence, this is what happens... > > not someone being killed. > > That depends on the determination of said person and his friends to > resist arrest -- with what means and to what extent. If the state's > power to arrest is not to be merely theoretical, it must be backed by > military ability (and will to exercise it) which exceed those of the > people's meant to be arrested. How did Gandhi do it then? Was it just that the British decided that they weren't mean enough to take it to its "ultimate" extent, or was it truly that there was a way to "go to the ultimate" and take back India in a nonviolent way? -tom! -- There's really no reason to send a copy of your followup to my email address, so please don't. From newsgroups at jhrothjr.com Wed Aug 27 11:26:33 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Wed, 27 Aug 2003 11:26:33 -0400 Subject: Proposal: Magic Constants References: Message-ID: "Robert Kern" wrote in message news:biihkv$9m1$1 at naig.caltech.edu... > In article , > "John Roth" writes: > > [snip] > > > Another thing to think about is whether > > this could cause problems with existing > > code. I can't immediately think of a case > > where a literal can be next to a character, > > but I'm also not a real deep authority on all > > of the oddities of Python syntax. > > 10L > 0X > 1e+10 > 10j But these are existing literal syntax. I was thinking more of random code where someone could currently juxtapose a literal and an identifier, say, without an intervening white space character. John Roth > > > John Roth > > -- > Robert Kern > kern at caltech.edu > > "In the fields of hell where the grass grows high > Are the graves of dreams allowed to die." > -- Richard Harter From pkwan at advsofteng.com Fri Aug 1 10:44:55 2003 From: pkwan at advsofteng.com (Peter Kwan) Date: Fri, 1 Aug 2003 22:44:55 +0800 Subject: 'long int too large to convert to int' in 'garbage collection' ignored Message-ID: <00b001c3583b$799c3160$83706698@newlife> Hi, I believe I have discovered a bug in Python 2.3. Could anyone suggest a get around? When I tested my existing Python code with the newly released Python 2.3, I get the following warning: FutureWarning: hex/oct constants > sys.maxint will return positive values in Python 2.4 and up It is because I used some constants such as 0x80ff3366, so I change it to 0x80ff3366L, hoping to get rid of the warning. But then I get the following fatal error: Exception exceptions.OverflowError: 'long int too large to convert to int' in 'garbage collection' ignored Fatal Python error: unexpected exception during garbage collection abnormal program termination I have tried testing the same code in Python 1.5.2 to Python 2.2. In all these versions, there is no error, no matter I use 0x80ff3366 or 0x80ff3366L. But in Python 2.3, I get warning or fatal error in these cases. The details are as follows: The code is running on Windows 2000. Python 2.3. The Python code calls a C library and pass 0x80ff3366 or 0x80ff3366L to the C library. In the C library, it calls //convert the given argument to Long in case it is not already Long PyObject *longObj = PyNumber_Long(argObj); //get the value of the Python Long variable long ret = PyLong_AsLong(longObj); I have done some testing and confirm that the error does not happen if the second line "PyLong_AsLong" is commented out. Also, the erorr does not happen immediately when executing the above statement. It occurs slightly afterwards (during garbage collection?). Could someone suggest a word around without touching the C library, and without making the Python code too ugly? Regards Peter Kwan -------------- next part -------------- An HTML attachment was scrubbed... URL: From abuseonly at sgrail.org Sat Aug 23 20:29:27 2003 From: abuseonly at sgrail.org (derek / nul) Date: Sun, 24 Aug 2003 00:29:27 GMT Subject: Bug with win32 open and utf-16 file References: <27vekvc6evvn3m5jg8n1en2u42skat42qn@4ax.com> Message-ID: <2i1gkv0s7762vcs85rkdq6uvgk6oitje12@4ax.com> On Sat, 23 Aug 2003 17:46:33 +0300, Christos "TZOTZIOY" Georgiou wrote: >On Sat, 23 Aug 2003 14:36:58 GMT, rumours say that derek / nul > might have written: > >[snip opening 'rb' a UTF-16 file] > >>The original file has line terminator characters of 00 0d 00 0a. >>After being read into a variable or a list the line termination characters have >>been changed to 00 0a 00 0a > >You didn't mention any writing back the file. Do you? How exactly do >you write it back? I haven't got to that yet, I suspect the file when written will have twice as many line feeds as the original file which will be a problem. >By the way, what are the unicode name for the characters u"\u000a" and >u"\u000d"? In ASCII (stripping the MSB), they are LF and CR. I don't know about the unicode names, I am concerned about their ascii equivalent. Derek From czoretich at octigabay.com Mon Aug 25 20:12:47 2003 From: czoretich at octigabay.com (Craig Zoretich) Date: 25 Aug 2003 17:12:47 -0700 Subject: modifying method behaviour Message-ID: Hi, I am trying to modify the behaviour of a method so it will automatically log information for me. I have been able to do this with functions by using the code that was kindly submitted to this newsgroup: > class logger: > def __init__(self, func): > self.func = func > def __call__(self, *args): > print "Called: %s with args %s" % (self.func.func_name, args) > return self.func(*args) > > def myfunc(a): return a > > myfunc = logger(myfunc) This code works great for functions, but it doesn't work too well for methods within a class. Here's an example of my code: > class logger: > def __init__(self, func): > self.func = func > def __call__(self, *args): > print "Called: %s with args %s" % (self.func.func_name, args) > return self.func(self, *args) > > class myClass: > def myfunc(self, a): return a > > myfunc = logger(myfunc) What happens is that the "self" argument in myClass.myfunc is being filled with an instance of the logger class, so it doesn't see any of the attributes of "myClass". Is there a simple way of tweeking this code, or do I need to redesign how I am doing this? Thanks in advance, Craig From br801145 at shaw.ca Thu Aug 14 16:31:45 2003 From: br801145 at shaw.ca (BR) Date: Thu, 14 Aug 2003 20:31:45 GMT Subject: [OT] Python and RSA Message-ID: <3F3BF1C2.2010003@shaw.ca> If anyone in the Python community is interested in cryptography and is familiar with the RSA encryption algorithm, I would like to correspond with you offlist to discuss an implementation in Python. Thanks, Barry Roberts From electricity at uymail.com Thu Aug 28 02:23:28 2003 From: electricity at uymail.com (U. N. Owen) Date: Thu, 28 Aug 2003 08:23:28 +0200 Subject: Style question... Message-ID: <20030828062328.19471.qmail@uymail.com> Re: Anthony Roberts wrote: Re: > Re: > If I end indentation levels with "pass" statements, will I piss off people Re: > that have to read my code? eg: Re: > Re: > for i in xrange(0,5): Re: > if i: Re: > print i Re: > pass Re: > print i * -1 Re: > pass Re: > Re: > I ask for two reasons... a) it helps emacs figure it out, and b) I'm more Re: > comfortable ending compound statements with a token. Re: Re: Sorry, but yes, I find that ugly. If you're just starting out with Re: Python, please just give it a shot without that approach for a while Re: and see whether you become much more comfortable *without* the token Re: than you ever were with it. Re: Re: -Peter Re: -- Sorry, but no ;-) Ok it's "one line more", and is not very useful. But... For the moment I work on (a small part of) a project that has hundreds of thousands of lines, almost eveything in Python (and some in C and Fortran), and when you have a loop several pages long, or nested blocks to 8 levels or more, I may say it's *very* convenient to see where the end of a block exactly is. It's convenient to have some long variable names too. -- _______________________________________________ Get your free email from http://www.uymail.com Powered by Outblaze From mis6 at pitt.edu Tue Aug 12 17:35:00 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 12 Aug 2003 14:35:00 -0700 Subject: CLI+GUI References: <2259b0e2.0308080948.5a95e383@posting.google.com> Message-ID: <2259b0e2.0308121335.7f1ad18a@posting.google.com> danbmil99 at yahoo.com (dan) wrote in message news:... > Late to this thread, but -- > > in a similar situation, I just put: > > _tkinter.dooneevent(_tkinter.DONT_WAIT) > > in my main logic loop (cmd interpreter in your case), instead of > calling Frame.mainloop(). I believe Frame.update() does something > similar but for some reason this worked better. > > ISTM this would be cleaner (and safer) than using threads. You can do > all your draw operations from your command line routines, and they > will get displayed as soon as the routine returns to your main loop to > wait for more input. > > Am I missing something? > > -dbm I like quite a lot you suggestion! "dooneevent" was the method I was looking for! Actually, I would rather prefer to avoid threads for such a simple program. Thanks to the power of Python I wrote down a working script in less than five minutes, even if probably I will need more than five minutes to understand what I wrote ;) Here it is: import Tkinter as t import cmd root=t.Tk() s=t.StringVar() s.set('ciao') label=t.Label(root,textvariable=s) label.pack() class Cmd(cmd.Cmd): def do_display(self,arg): s.set(arg) root.tk.dooneevent(0) def do_quit(self,arg): root.quit() return 'quit' # anything != None will do Cmd().cmdloop() I will later try it on Windows 98. Dunno exactly what "dooneevent" is doing, I searched my python directories for "dooneevent" and found only one usage of "doonevent" and copied it ;) Unfortunately "dooneevent" has no docstring, however few experiments show that "dooneevent()" is the same that "dooneevent(0)" whereas "dooneevent(1)" hangs up (it is waiting for what??) Thanks for your help, Michele From guettler at thomas-guettler.de Wed Aug 20 10:55:57 2003 From: guettler at thomas-guettler.de (Thomas =?ISO-8859-15?Q?G=FCttler?=) Date: Wed, 20 Aug 2003 16:55:57 +0200 Subject: Regex Question Message-ID: Hi! I want to parse a file that looks like this: a0001: basbasdb asbddsb asdbasdb abasbd a0002: fffff ffff ffffff ffff a???? should be the key and the following lines should be the value of a dictionary. My solution looks like this: regex=re.compile(r'(?:^|\n)(\w\d\d\d\d):((?:.(?!\n\w\d\d\d\d:))*)', re.DOTALL) matches=regex.findall(content) for match in matches: print match I think there is a better solution than this, don't you? thomas From rganesan at myrealbox.com Mon Aug 18 04:10:50 2003 From: rganesan at myrealbox.com (Ganesan R) Date: Mon, 18 Aug 2003 13:40:50 +0530 Subject: What's better about Rattlesnakes than Pythons? References: <8e482ba2.0308171939.7de4a288@posting.google.com> Message-ID: >>>>> "ForHimself" == ForHimself Every Man writes: > What's better about Rattlesnakes than Python. I'm sure there's > something. What is it? > This is not a troll. I'm a snake shooping and I want people's > answers. I don't know beans about Rattlesnakes or have an > preconceived ideas about them. I noticed, however, that everyone I > talk to who are aware of Pythons are also afraid of Rattlesnakes. So > it seems that Rattlesnakes have the potential to compete with and > displace Pythons. I'm curious how evolution will play this out. ROTFL. Thank you very much. I really needed this :-). -- Ganesan R From tzot at sil-tec.gr Thu Aug 7 11:42:01 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Thu, 07 Aug 2003 18:42:01 +0300 Subject: itertools.ilen? References: Message-ID: <98s4jvkqv94c0gj99epjanq9b3aqvq8i2q@4ax.com> On Thu, 07 Aug 2003 03:10:10 -0400, rumours say that Jeremy Fincher might have written: > objs = gc.get_objects() > classes = len([obj for obj in objs if inspect.isclass(obj)]) > functions = len([obj for obj in objs if inspect.isroutine(obj)]) > modules = len([obj for obj in objs if inspect.ismodule(obj)]) > dicts = len([obj for obj in objs if type(obj) == types.DictType]) > lists = len([obj for obj in objs if type(obj) == types.ListType]) > tuples = len([obj for obj in objs if type(obj) == types.TupleType]) Another way to count objects: # code start import types, gc type2key = { types.ClassType: "classes", types.FunctionType: "functions", types.MethodType: "functions", types.ModuleType: "modules", types.DictType: "dicts", types.ListType: "lists", types.TupleType: "tuples" } sums = { "classes": 0, "functions": 0, "modules": 0, "dicts": 0, "lists": 0, "tuples": 0 } for obj in gc.get_objects(): try: sums[type2key[type(obj)]] += 1 except KeyError: pass # code end This code is intended to be <2.3 compatible. -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From godoy at metalab.unc.edu Fri Aug 8 12:58:35 2003 From: godoy at metalab.unc.edu (Jorge Godoy) Date: Fri, 08 Aug 2003 13:58:35 -0300 Subject: Replacing the crypt module in Windows Message-ID: Hi! What do you use to replace the crypt module in Windows? It's available for POSIX systems only. I need to check some passwords to grant access to a system we're writing and the first choice on unices was crypt. Is there something that can be used on both systems and use a random seed to generate the password? Thanks in advance, -- Godoy. From strehan at asahiindia.com Thu Aug 14 02:30:01 2003 From: strehan at asahiindia.com (Sanjeev Trehan) Date: Thu, 14 Aug 2003 11:30:01 +0500 Subject: Error solution Message-ID: <3.0.32.20030814112813.0068a3f8@mailgw.asahi.com> Dear All, I am a new to Python,just started few days back.I have installed Python23.exe.Also downloaded the totorial of Guido van Rossum Fred L. Drake, Jr., editor Release 2.3 July 29, 2003 When I write in command line the following eoors come: >>> print a File"" Indentation error:Expected an indented block. >>>lambda x:x+n File"" return^ lambda x:x+n Indentation error:Expected an indented block. Please solve my problem and explain from where should I start learning Python. Waiting for reply. Regards Sanjeev From simonb at webone.com.au Wed Aug 20 20:10:25 2003 From: simonb at webone.com.au (Simon Burton) Date: Thu, 21 Aug 2003 10:10:25 +1000 Subject: pyrex.vim ? Message-ID: Looks like the pyrex guy uses emacs... Anyone have any hints/ideas/scripts for getting some vim syntax colors for pyrex ? Simon. From aleax at aleax.it Wed Aug 20 17:37:05 2003 From: aleax at aleax.it (Alex Martelli) Date: Wed, 20 Aug 2003 21:37:05 GMT Subject: class factory References: <8ad2cfb3.0308200015.4f5bd504@posting.google.com> Message-ID: <5SR0b.21604$zN5.668541@news1.tin.it> Nick Keighley wrote: > Hi, > > I'm a Python beginner and I'm would like to write a function that > returns a class (perhaps a tad ambitious...). I've looked through > the FAQ and perused "Python In A Nutshell" (not a good book to > start with?). The only example I found in PiaN used a simple If you're an experienced programmer with other languages then the Nutshell should be helpful -- if you're a newbie to programming, you should start with easier books (but with the kind of tasks you're setting yourself I guess you aren't). I didn't particularly emphasize metaprogramming in the Nutshell -- it's more of a "gee whiz" kind of thing and the Nutshell aims to cover solid, everyday, bread-and-butter usage. > if statement to return one of a selection of pre-existing classes. > I'd like to generate a class on-the-fly from a parameter (a dictionary). How do you want to use that dict -- as the class's dict? Then either: def makeaclass(fromdict): class X: pass X.__dict__ = fromdict return X or def makeaclass(fromdict): class X: pass X.__dict__.update(fromdict) return X might be helpful. > Can Python do this sort of stuff? Does the mean I have to mess with > the dreaded meta-classes? Metaclasses may be easier to use than sufficiently-general class-building functions, actually -- no reason to dread them. But anyway, yes, Python IS pretty good at metaprogramming, too, both with and without metaclasses. Alex From sjmachin at lexicon.net Wed Aug 13 18:32:35 2003 From: sjmachin at lexicon.net (John Machin) Date: 13 Aug 2003 15:32:35 -0700 Subject: Determine file type (binary or text) References: Message-ID: "Michael Peuser" wrote in message news:... > > When I had a similar problem I read 1000 characters, counted the amount of > <32 and >255 characters and classified it "binary when this qota exceeded How many characters > 255 did you get? Did you mean 127? If so, what about accented characters ... like umlauts? On a slightly more serious note, CR, LF, HT and FF would have to be considered "text" but their ordinal values are < 32. What was the problem that you thought you were solving? From Mike at DeleteThis.Geary.com Thu Aug 28 14:01:49 2003 From: Mike at DeleteThis.Geary.com (Michael Geary) Date: Thu, 28 Aug 2003 11:01:49 -0700 Subject: Running a Python script when a page is loaded References: Message-ID: Andrew Chalk wrote: > I am developing a CGI app, When the user loads my page I want to > populate an HTML 'select' box (drop down menu) with items from > a database. What is the best way to get my Python procedure that > does this called when the page is loaded? Normally a CGI app generates the entire page, so you'd already be running Python code and would just call your function at the right place. Or is there more to the question that I missed? If you're running Apache, you can use mod_rewrite to get rid of all the cgi-bin/scriptname?querystring cruft. For example, at my Geary Central site: http://www.geary.com/ All of the pages including the home page are generated by Python scripts (the MoinMoin wiki software), but the URLs look like ordinary static URLs because mod_rewrite translates them. -Mike From ejeanlouis2001 at yahoo.com Tue Aug 12 09:01:27 2003 From: ejeanlouis2001 at yahoo.com (Emmanuel Jean-Louis) Date: Tue, 12 Aug 2003 06:01:27 -0700 (PDT) Subject: dumb questions! Message-ID: <20030812130127.6229.qmail@web13008.mail.yahoo.com> Guys please bear with me. I'm new to the hole ball game. I'm an electrical engineer who fall in love with programming. I might be the dummiest guys in list right now about programming but it's all good. Hopefully in a year or so, I will sound just like you guys. You will be seeing a lot of none sense questions, please help me out. Thx. Emmanuel --------------------------------- Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software -------------- next part -------------- An HTML attachment was scrubbed... URL: From achrist at easystreet.com Mon Aug 4 15:43:47 2003 From: achrist at easystreet.com (achrist at easystreet.com) Date: Mon, 04 Aug 2003 12:43:47 -0700 Subject: PyChecker work with Python 2.3? References: <3F2C5300.FA223CBA@easystreet.com> Message-ID: <3F2EB773.4895B5DD@easystreet.com> Skip Montanaro wrote: > > Al> The pychecker site says that pychecker works with versions > Al> 1.5 through 2.2. Any reason to expect that 2.3 breaks it? > Al> Anyone tried it to see? > > I run Python CVS as my normal Python on my laptop. I've never had a problem > with PyChecker. > Based on this encouraging news, I have upgraded all the packages listed and run pychecker on a program using them all. It looks to work fine. Speed was not noticeably increased or decreased. The only change required in my sources is evidently that the csv module no longer has a parser(); it's a reader(aFile). About the only noticeably slow part of the program is the part that read a gzipped csv file. Unzipping and parsing a 170kb gzip file took about 20 sec with v2.2.3, and takes only about 9 sec with v2.3 (200 MHz machine). So, the speed increase is big where I needed it most. This is great. Al From gafStopSpamData at ziplink.stopallspam.net Thu Aug 21 07:43:59 2003 From: gafStopSpamData at ziplink.stopallspam.net (Gary Feldman) Date: Thu, 21 Aug 2003 11:43:59 GMT Subject: Removing language comparisons References: Message-ID: On Wed, 20 Aug 2003 20:51:30 -0500, "A.M. Kuchling" wrote: >python.org has a page of "Python vs. X" language comparisons at >. ... >I'm planning to drop this page from python.org because it's so outdated and If it weren't for the Python vs. Perl papers, I'd still be using Perl. I suggest simply creating an "Archive" section near the bottom of the page, and moving any links whose contents you know to be wrong to that section. But please, please don't remove the page altogether. Most comparision issues simply aren't going to change, so the articles just get old, not outdated. Gary From aleax at aleax.it Thu Aug 21 11:47:59 2003 From: aleax at aleax.it (Alex Martelli) Date: Thu, 21 Aug 2003 15:47:59 GMT Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> <6dj2kv8ugkieehs7guh786cl40o5lj6mcs@4ax.com> <599a6555.0308202108.397bb1a0@posting.google.com> Message-ID: Jacek Generowicz wrote: ... > For this reason it is rarely a good idea to define a macro for a > single use. However, it becomes an excellent idea if the idea the > macro expresses must be expressed repeatedly. The same is true of > functions, classes, modules ... Not at all. "Defining a function for a sinmgle use" is often a perfectly valid way to make a program MUCH CLEARER. Example: def perimeter_of_right_triangle(leg1, leg2): def hypothenuse(leg1, leg2): return math.sqrt(leg1*leg1 + leg2*leg2) return leg1+leg2+hypothenuse(leg1,leg2) Here, the local function 'hypotenuse' is introduced _purely for readability purposes_ -- as a stylistic alternative to the introduction of a _variable_ of the same name, i.e.: def perimeter_of_right_triangle(leg1, leg2): hypothenuse = math.sqrt(leg1*leg1 + leg2*leg2) return leg1+leg2+hypothenuse Breaking up a complicated expression with well-named intermediate variables or functions is an excellent technique to enhance the expression's readability. The key, of course, is LOCALITY of usage: if the function, or intermediate variable, was defined far away, the purpose would be lost. Being in the immediate vicinity, the var or fun ISOLATES AND NAMES a well-defined part of the expression, If macros were similarly constrained, with their definition immediately available, they wouldn't be anywhere as dangerous (their usefulness, of course, would also be diminished in roughly the same proportion). Alex From javier_ruere at HotPOP.com Thu Aug 28 01:24:09 2003 From: javier_ruere at HotPOP.com (Javier Ruere) Date: Thu, 28 Aug 2003 02:24:09 -0300 Subject: My future Python IDE article In-Reply-To: <6ee58e07.0308271457.7349086f@posting.google.com> References: <6ee58e07.0308271457.7349086f@posting.google.com> Message-ID: <3F4D91F9.10004@HotPOP.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Lothar Scholz wrote: >>You should definitely consider Boa-Constructor (be sure to use at least v. >>0.23, better yet the recent cvs version). >>IMHO its the most "complete" python IDE at the moment. > > But not easy to use and with a lot of bugs. Maybe some less features > and more stability would be nice. After a couple of weeks of learning Python I had already discarded TK and wanted a GUI builder for wxPython. After trying PythonCard I found Boa and loved it. Being Visual Basic the only IDE I had previously used, Boa was very intuitive to me and had little trouble, if any, using it. On the stability front, I'm sure I had at least one problem in this year+ I have been using it but I can't quiet recall what is was... The author labels the IDE as alpha software but he must have the highest standars, for the CVS version is remarkably stable and ready to use IMHO. > And it is not complete if you want to program Web Applications. I have no experience in such things but it does have some Zope stuff (which I know nothing about). Later, Javier -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQE/TZH38XQC840MeeoRAnUgAJ4raTV5gS8EZSy6gQDABF2acZx1YgCffbbe ZdzZNd4cO/UKBqnynxzGu9Y= =c5v/ -----END PGP SIGNATURE----- From bh at intevation.de Thu Aug 7 07:34:47 2003 From: bh at intevation.de (Bernhard Herzog) Date: Thu, 07 Aug 2003 13:34:47 +0200 Subject: round(22.47,2) gives 22.469999999999999? References: <3f30e294$0$125$e4fe514c@dreader5.news.xs4all.nl> Message-ID: <6qn0elr99k.fsf@salmakis.intevation.de> sjmachin at lexicon.net (John Machin) writes: >> Wouldn't >> >> int(22.47 + .5) >> >> get you to where you want to go? > > Sure would, if 22 was where you wanted to go. Even if he would want to round to an int, using int(x + 0.5) would fail for negative values: >>> int(-1.9 + 0.5) -1 but >>> round(-1.9) -2.0 Bernhard -- Intevation GmbH http://intevation.de/ Sketch http://sketch.sourceforge.net/ Thuban http://thuban.intevation.org/ From gerrit at nl.linux.org Wed Aug 27 15:11:43 2003 From: gerrit at nl.linux.org (Gerrit Holl) Date: Wed, 27 Aug 2003 21:11:43 +0200 Subject: Celebrity advice (was: Advice to a Junior in High School?) In-Reply-To: <4e73b.6416$Jh2.2462@newsread4.news.pas.earthlink.net> References: <3F4CD2A2.DE7D05D2@engcorp.com> <4e73b.6416$Jh2.2462@newsread4.news.pas.earthlink.net> Message-ID: <20030827191143.GA4504@nl.linux.org> Andrew Dalke wrote: > Me: > > Given a population of 4 billion (roughly, over the century) and assuming > > the US rate is average for the world, that's > > > > >>> 4000000000 / 100000. * 9.2 > > 368000.0 > > >>> > > > > or roughly 0.5% of the deaths attributed to murders in the cause of > > war. Roughly in line with Terry's claims. > > Oops! That's *per* *year*. Multiply by 100 to get the number > of homicides in a century == 37 million. In a (post-)(civil-)war situation, the difference between homocide and war can be extremely vague, so this number may me much higher (and/or the number of war deaths lower). Not every death is classifyable. Gerrit. -- 215. If a physician make a large incision with an operating knife and cure it, or if he open a tumor (over the eye) with an operating knife, and saves the eye, he shall receive ten shekels in money. -- 1780 BC, Hammurabi, Code of Law -- Asperger Syndroom - een persoonlijke benadering: http://people.nl.linux.org/~gerrit/ Het zijn tijden om je zelf met politiek te bemoeien: http://www.sp.nl/ From leszek at php.net Tue Aug 12 14:43:27 2003 From: leszek at php.net (Leszek =?iso-8859-2?Q?Krupi=F1ski?=) Date: Tue, 12 Aug 2003 18:43:27 +0000 (UTC) Subject: German umlaut in a string. References: Message-ID: Ship log, stardate: [-29]0729.3, Lukas Kasprowicz reports: > Hi Folks, > > I have a string filled with much text converted from a tuple. > > when I try to do someting like this: > > exclusion = re.sub("\\xf6", "%F6", exclusion) # ? > exclusion = re.sub("\\xfc", "%FC", exclusion) # ? > exclusion = re.sub("\\xe4", "%E4", exclusion) # ? > exclusion = re.sub("\\xdf", "%DF", exclusion) # ? > > it takes no effect at the string. > > things like: > > exclusion = re.sub(',', '', exclusion) > exclusion = re.sub('\(', '', exclusion) > exclusion = re.sub('\)', '', exclusion) > exclusion = re.sub("'", "", exclusion) > exclusion = re.sub(" ", "+%2D", exclusion) > work fine. > > when i write the sting in a python console into a variable like: > > >>> test = "some\\xf6thing" > >>> print re.sub("\\xf6", "%F6", test) > some%F6thing > > I get the correct output. It works for you? >>> test = "some\\xf6thing" >>> print re.sub("\\xf6", "%F6", test) some\xf6thing (Python 2.3) >>> exclusion = "some\xf6thing" >>> exclusion = re.sub("\\xf6", "%F6", exclusion) >>> print exclusion some%F6thing I believe that problem is in slashes. Leon -- _________________________Silly is a state of mind, stupid is a way of life / Homepage: http://www.leon.w-wa.pl/ GPG Key @ keyserver.net | JabberID: leafnode at jabberpl.org Real email in headers \_ Curriculum Vitae: http://www.leon.w-wa.pl/cv.pdf _______________________ From adalke at mindspring.com Mon Aug 18 22:16:19 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Mon, 18 Aug 2003 20:16:19 -0600 Subject: What's better about Ruby than Python? References: Message-ID: Pedro Werneck: > Well... I think you're overlooking the fact that you're not exactly > _redefining_ the class. You're creating an entirely new class > object and binding it to the same name, but the old class is still > lying there, I'm pretty sure he knows that and simply disagrees with that design choice, suggesting that a class def should augment a class if it already exists. I wonder ... Alexander? What should this do? from Q import X class X: def amethod(self): return 'ah, now THIS is better!' Should it refine the X in the local namespace or make a new class? I have wondered if def X.amethod(self): return "...." should be allowed, but no longer think it should. OTOH, a proper reload, which updated all instance's __class__ to the newly reloaded class, would be nice. I've stumbled over that many a time. Andrew dalke at dalkescientific.com From fawcett at teksavvy.com Wed Aug 13 21:07:12 2003 From: fawcett at teksavvy.com (Graham Fawcett) Date: Wed, 13 Aug 2003 21:07:12 -0400 Subject: Getting a data structure In-Reply-To: <1103_1060820563@news-server.optonline.net> References: <1103_1060820563@news-server.optonline.net> Message-ID: <3F3AE0C0.9010500@teksavvy.com> Mike solem wrote: >I need to pass a data structures from a C program, to a python program over RS232. >I'm not quite sure how to recreate a data structure from a string of serial data. >In C I would do it like this: > >---------------------- This compiles under gcc ---------- >#include > >typedef struct{ > int a; > char b; >}myStruct; > >int main() >{ > char data[]= {1,2,3,4,5,6,7,8,9}; > myStruct* s1; > > s1 = (myStruct*)&data; > printf("%x %d\n", s1->a, s1->b); > return 0; >} >-------------------------------------------- > >The 'data' array above would be a buffer which receives data from the serial link. >So the questions are, what type of python data stucture to use, and how to >initialize it from the buffer. >The struct I'm using is a lot more complex than the one I used here. It's built up of a couple >of other structs. > >Thanks >Mike > > > Does the standard "struct" module not meet your requirements? "This module performs conversions between Python values and C structs represented as Python strings. It uses /format strings/ (explained below) as compact descriptions of the lay-out of the C structs and the intended conversion to/from Python values. This can be used in handling binary data stored in files or from network connections, among other sources." http://www.python.org/doc/current/lib/module-struct.html -- Graham From Mike at DeleteThis.Geary.com Tue Aug 12 19:38:29 2003 From: Mike at DeleteThis.Geary.com (Michael Geary) Date: Tue, 12 Aug 2003 16:38:29 -0700 Subject: Python should try to displace Java References: Message-ID: > Michael Geary wrote: > > I am being educated here. Is that what trolls do? :-) Cliff Wells wrote: > Only if you're interested in social engineering. After reading more of this thread, I see your point. My educational experience was short-lived. :-) -Mike From davesum99 at yahoo.com Tue Aug 5 17:27:34 2003 From: davesum99 at yahoo.com (smarter_than_you) Date: 5 Aug 2003 14:27:34 -0700 Subject: recompiled midipy.pyd for 2.3 Message-ID: this is a nice windows-based MIDI module with simple interface, it was previously available for <= 2.0 release (See thread on midi for win32). If anyone wants it please post a reply. From altis at semi-retired.com Wed Aug 6 14:15:35 2003 From: altis at semi-retired.com (Kevin Altis) Date: Wed, 6 Aug 2003 11:15:35 -0700 Subject: Is there some Python + IDE/RAD for real speed development??? References: <96fda9ac.0308060611.56dfca7e@posting.google.com> Message-ID: The following wiki page is relevant. http://www.python.org/cgi-bin/moinmoin/GuiProgramming You've already received some comments on Qt and GTK toolkits, so I won't go into those. For wxPython, you should look at Boa, wxGlade, and wxDesigner. Boa is modeled after Delphi, so that might seem the most familiar to you. http://boa-constructor.sourceforge.net/ http://wxglade.sourceforge.net/ http://www.roebling.de/ You can use them just for doing layouts or you can have them generate source code too. In terms of lines of code in your finished script, PythonCard probably wins because it is a wrapper around wxPython designed to hide many of the complexities inherent in setting up frames, controls, and binding events that you normally have to do. The code for doing all the setup is in the framework, not in the code you write. PythonCard uses separate source modules and layout files and auto-binds events, so your source will just be event handlers and program logic. This is similar to what you would be used to seeing if you used Visual Basic. http://www.pythoncard.org/ There is even a tool in progress to convert VB to PythonCard (and later other GUI toolkits) called vb2py http://vb2py.sourceforge.net/ There are a lot of samples and tools for you to look at so you can see if PythonCard is good enough for what you want. http://pythoncard.sourceforge.net/samples/samples.html Between it and one of the wxPython tools above you should get close to what you're looking for. PythonCard is still in flux (which is why it is labeled as alpha) and it doesn't give you all of the capabilities of the other wxPython tools so you might be more comfortable with Boa... Finally, GUI frameworks and environments are a very active area for Python development and the tools are maturing relatively quickly. You can help influence the design and feature set of some of them, but if you don't find exactly what you're looking for today, check back again in six months or so. ka "Edilmar" wrote in message news:96fda9ac.0308060611.56dfca7e at posting.google.com... > Hi, > > First of all, I'm new in Python... > > I have worked with manu langs and IDEs, like Delphi, VB, JBuilder, Eclipse, > Borland C++, Perl, etc... > > Then, today I think IDEs like Delphi have a excelent environment to develop > apps with little time. I saw many people talking about Python like a easy > lang to learn and to develop. But I have look at IDEs for Python, or ways > to develop GUIs with it, and I think it already is limited when comparing > with IDEs like Delphi. Is this afirmation true? > > I look at wxPython and PyGTK, but the samples showed that we have to write > MANY LINES of code to do simple things. Many people have wrote about the > advantage of Python to write little code, but, when talking about GUIs, > I think it's not really true, right? > > Using Delphi, little or none code is need for many things, but wxPython > and PyGTK is the reverse! > > Thanks for any replies, From fredrik at pythonware.com Tue Aug 26 04:01:22 2003 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 26 Aug 2003 10:01:22 +0200 Subject: Tk Canvas text question References: Message-ID: Gary Richardson wrote: > I've been working on a Python version of Andreas Weber's ASCII > schematic drawing program ( http://www.tech-chat.de) ; not that I > thought I could do it better but just as a programming exercise. > I've managed to put together something that more or less works > but I'm puzzled by the way ASCII characters are displayed on a Canvas > window. For example, in the code below (which produces my crude > representation of an OpAmp), why are two leading blanks required in > the text of the second create_text statement to cause the vertical bar to > be aligned with the one above it? And why does the number of trailing > blanks affect the position of the beginning of a line. by default, text is centered around the given coordinate. use anchor=NW to align on the upper left corner, anchor=SW to align on the lower left, etc. From bokr at oz.net Sat Aug 9 13:44:45 2003 From: bokr at oz.net (Bengt Richter) Date: 9 Aug 2003 17:44:45 GMT Subject: raw string tail escape revisited References: Message-ID: On 9 Aug 2003 15:33:39 GMT, bokr at oz.net (Bengt Richter) wrote: >Why wouldn't quote-stuffing solve the problem, and let you treat \ as >an ordinary character? In a raw string, it's no good for preventing >end-of-quoting anyway, unless you want the literal \ in front of the quote >you are escaping. > >Quote-stuffing is a variation on the old quote-doubling, extended to >deal with triple quotes as well (which makes it a little like HDLC bit stuffing). > >IOW, treat \ as an ordinary character, and then if you don't want the >string to end, just stuff one quote character of the starting kind after >the otherwise terminating sequence. You could do this with single quoting >or triple quoting, where of course you'd need it less for triple quotes. >E.g., using uppercase R as a prefix for this kind of raw string syntax, > > R'\' # just fine > R'C:\' # one of the motivations > R'''' # dumb way to do "'" Really dumb ;-/ That makes an un-terminated triple quoted string starting with one quote. D'oh. The logic doesn't start until the beginning delimiter - single or triple - has been passed and established. So if you perversely wanted to use only single quotes to quote one single quote, you couldn't. Is there one you couldn't do at all? I don't think so, since you could always do single-quote doubling and choose the opposite quote of a leading quote in the data. E.g., R'"""''''''' Would be a painful R'"""'+R"'''" Actually, that could be triple quoted as R"""""""'''""", but putting an ending '"' in that data would make a problem. Nope, R'''"""''''"''' would handle that. But what if we add another "'"? Then the data would be ["""'''"'] Still ok, looks like we can always start with a triple quote opposite to the end of the data: R"""""""'''"'""" would do it. Is there an impossible case I'm missing that would have to be split into two adjacent (thus concatenated) string representations? Is there a reasonable use case that is messed up as the price of getting R'\' ? Otherwise I guess it should be ok. Woke up too early and not enough ;-) > R""" ->[""""]<-makes 3 quotes, and we end with \""" > R""" ->[""""""""]<-two stuffing-extended triple quotes make 6 quotes.""" > >The tokenizer would recognize a stuffed quote mark and just discard it if present, >otherwise recognize end of string. > >Just had this idea. Do I need more coffee? What did I forget? > >Regards, >Bengt Richter Regards, Bengt Richter From s0199583 at sms.ed.ac.uk Tue Aug 12 11:27:25 2003 From: s0199583 at sms.ed.ac.uk (Matt Smith) Date: 12 Aug 2003 08:27:25 -0700 Subject: PyIDispatch::GetIDsOfNames + object reg Message-ID: <5f5c82ec.0308120727.51214a6c@posting.google.com> hi again all, last questions for today.... (1) what do i have to import/type to be able to run GetIDsOfNames on a selected function ? I cant seem to find the module PyIDispatch anywhere, and I was assuming that is where I would call that function from? (2) How do I register a type library that can be seen in pythonwins COM brower? cheers, matt From danbmil99 at yahoo.com Sat Aug 2 02:38:31 2003 From: danbmil99 at yahoo.com (dan) Date: 1 Aug 2003 23:38:31 -0700 Subject: looking for win32 (or cross-platform) midi module Message-ID: is there anything like the nice midipy.pyd, but up to date (ie works > 2.0)??? From davbucko at yahoo.com Sat Aug 30 11:50:33 2003 From: davbucko at yahoo.com (Dave) Date: Sat, 30 Aug 2003 19:50:33 +0400 Subject: Reading and manipulating binary data Message-ID: Hi, I am really confused as to how to use binary data with python. I am currently developing a lightweight RADIUS server, which gets UDP datagrams from a client formatted like so: 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Code | Identifier | Length | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | | Request Authenticator | | | | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Attributes ... +-+-+-+-+-+-+-+-+-+-+-+-+- I can read() the data easily enough from the socket. However, when I have read it, it is very difficult to manipulate. I can't convert it to an integer or a string which is driving me crazy... I have seen a lot of posts recommending struct for dealing with binary data, but I can't get it to like mine. I get all sorts of errors, like lengths don't match format etc. Also part of the authentication system involves MD5 hashes. For this I need to be able to take a string, find its MD5 digest, and then xor it with another string. But since the MD5 digest is binary, and I don't know how to change it, I can't xor it... Please, I am sure I am missing something really obvious but I am stumped as to what it is. The basic RADIUS rfc is 2865. Please say if I have seriously misinterpreted it (as you can probably tell, this is my first time trying something more than "Hello World" with sockets). Thanks in advance Dave From davesum99 at yahoo.com Thu Aug 14 12:45:20 2003 From: davesum99 at yahoo.com (smarter_than_you) Date: 14 Aug 2003 09:45:20 -0700 Subject: 3 new slogans Message-ID: Peter Hansen wrote in message > > Get wrapped up in python > > > > nah thats shit too, emmm > > I once tried out "Wrap Python around your problem and crush it!" > how about this -- Python: It's a wrap (maybe you have to have been in the film/TV industry to get it) From carroll at tjc.com Wed Aug 27 21:19:10 2003 From: carroll at tjc.com (carroll at tjc.com) Date: Wed, 27 Aug 2003 18:19:10 -0700 Subject: python gripes survey References: <3F4B4C8E.23554819@engcorp.com> Message-ID: On Tue, 26 Aug 2003 08:03:26 -0400, Peter Hansen wrote: >JanC wrote: >> If it doesn't contain docstrings, you can put that "unwanted" test code >> between triple quotes ("""). > >OR if you're consistent in using only one kind of docstring, say ''' >only, then you can almost always use """ to comment out a block... Thanks; this is actually pretty helpful. From bokr at oz.net Sun Aug 10 17:14:57 2003 From: bokr at oz.net (Bengt Richter) Date: 10 Aug 2003 21:14:57 GMT Subject: How to print floating point in scientific format? References: <420ced91.0308081115.7060e551@posting.google.com> Message-ID: On Sat, 09 Aug 2003 16:58:46 GMT, Alex Martelli wrote: >sdhyok wrote: > >> I want to change the DEFAULT behavior of python >> to print out all floating points in scientific format? >> For instance, >> >>>x=0.01 >>>print x >> 1.000000E-2 #Like print "%E"%x >> >> How can I do it? > >You need to download Python's sources, modify them, and build a modified >Python interpreter and libraries that impose the behavior you want rather >than what the normal Python interpreter and libraries do. > >Specifically, look at function format_float, line 233 of file >Objects/floatobject.c in the current 2.3 maintenance branch for example. >Currently it formats the float with "%.*g" [variable precision passed >in as an argument to format_float]; if you want to use a different C level >format string, that string is the one you need to change. > >Of course, that's likely to break some of the tests in Python's unit-tests >suite, so you'll probably want to modify those, too. And then, you get to >maintain your "slightly divergent" Python yourself forevermore. I do not >think there is much likelihood that a patch in this regard would be >accepted in the Python core, even if you made it flexible enough to keep >the current behavior by default and change it only upon specific request >(e.g., use a variable string for the format, and let the Python coder >modify the letter in it, only, keeping "%.*g" as the default but letting >the 'g' be changed) -- such "big global" settings, which would let one >idiosyncratic library module modify Python behavior enough to break other >innocent modules, are looked at with disfavour, for reasons that should >be obvious (each and every such 'big global' _damages_ Python's suitability >for writing very large, multi-authors applications -- that suitability is >currently very high, and _extremely_ convincing arguments would need to >be brought to bear in order to convince Guido to deliberately lower it). > > OTOH, why not a sys.printhook ? There is a kind of precedent in >>> import sys >>> def dh(obj): ... if isinstance(obj, (int, long, float)): return sys.__displayhook__('%e'%float(obj)) ... else: return sys.__displayhook__(obj) ... >>> sys.displayhook = dh >>> 1 '1.000000e+000' >>> _ '1.000000e+000' >>> 2L '2.000000e+000' >>> 3. '3.000000e+000' >>> 1, 2L, 3. (1, 2L, 3.0) I didn't bother with recursive list and tuple mods. That would be up to the printhook user. ISTM a printhook would be easy to implement and not disruptive overall, whatever silliness it might inspire in particular individuals ;-) Actually, I think there could even be some good use for it, since you could do things with the object stream that you couldn't do by intercepting strings in sys.stdout.write. Regards, Bengt Richter From harry.g.george at boeing.com Wed Aug 13 13:03:55 2003 From: harry.g.george at boeing.com (Harry George) Date: Wed, 13 Aug 2003 17:03:55 GMT Subject: Summer reading list References: <2259b0e2.0308130804.492aa1ac@posting.google.com> Message-ID: mis6 at pitt.edu (Michele Simionato) writes: > "Joe Cheng" wrote in message news:... > > To me it sounds disturbingly like "Procedures are more flexible than > > classes because you can compose classes out of procedures." > > I would subscribe that. Not that I dislike inheritance, but I don't kill > a mosquito with a bazooka. > > Let me give a real life example, happened to me recently. > > I had a class manipulating text, with a "dedent" method. It turns out > that the "textwrap" module included in the Python 2.3 distribution > contains a "dedent" function doing exactly the same. > Then I had the satisfaction of killing my own implementation, > and to add to my class the textwrap.dedent function just with one > line of code, "dedent=staticmethod(textwrapper.dedent)". I am > very happy with that because: > > 1) I shortened my class; > 2) I reused pre-existing code; > 3) I trust the developers of the standard library more than myself; > 4) If the standard library contains bugs, they are much more easily > discovered than my own bugs; > 5) the burden to fix them is up the Python developers, not me ;) > > The fact that "dedent" was a function and not a method in a class > made my life easier. I had not to worry about inheriting from another > class with potential name clashes with my own, and "dedent" was the > only function I needed. > > Fortunately, quite a lot of modules in the standard library are > written without a class interface and I would date say I have never > seen an example of usage of a class when the class is not needed. > > In other words: most of the time a lightweight approach is more than > appropriate, why should I be forced to take a heavy weight approach? > The fact of having "free" functions (i.e. not bounded to classes) is > to me a big strenght of Python and it helps reuse of code quite a lot. > > To reuse classes is good, but typically only works when you know > about the class you want to inherit *before* you start coding your > own class; on the other hand, it is quite easy to add functions > or methods to your class even *after* you wrote it. > > Moreover, this is nothing wrong about using many short modules collecting > utilities functions, you will never clutter your namespace, if you use > a minimum of care (even globals are globals only in their module, > I love that! ;) > > I tend to code in terms of small functions, then I compose them in > small classes, then I compose the classes in modules. When I am > done, I play with metaclasses if I need to modify what I wrote > with a minimum of effort. > > There are quite few languages that can give you such a flexibility, > and no one simpler to use than Python. > > Just my own view, On the other hand, I have a "TabbedWriter" module which uses a class which has a dedent (actually "undent") method. This class has internal memory to track current indentation level (e.g., for indented XML files). Dedenting need to know this information. If I had used a module with dedent as a function and saved level as a global in the module, I would be limited to only 1 tabbed writer per application. I often need several going at once. > > > Michele -- harry.g.george at boeing.com 6-6M31 Knowledge Management Phone: (425) 342-5601 From ryanlowe0 at msn.com Tue Aug 19 20:32:23 2003 From: ryanlowe0 at msn.com (Ryan Lowe) Date: Wed, 20 Aug 2003 00:32:23 GMT Subject: if in for loop Message-ID: i thought id ask here before wirting a PEP, if people thought it would be a good enhancement to allow if clauses in regular for-statements like so: >>> for x in y if x < 10 : is semantically equivalent to >>> for x in [x for x in y if x < 10] : but is shorter and easier to read. basically, the if works as a filter for the values in the iterator. its not a major change, purely syntactic sugar. and clearly backwards-compatible. seem reasonable? ryan From newsgroups at jhrothjr.com Sat Aug 16 19:26:26 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Sat, 16 Aug 2003 19:26:26 -0400 Subject: Python should try to displace Java References: Message-ID: "Brandon J. Van Every" wrote in message news:bh9g66$vst1p$1 at ID-203719.news.uni-berlin.de... > I'm going to make a number of points which I'm sure many people will object > to. Feel free, but also try not to knee-jerk about them. As someone who > programmed DEC Alpha in 1998, and who sees the sorry state of CPUs nowadays, > I can definitely say that better technology doesn't always win. In fact, it > doesn't *usually* win. Python needs to look to its strategic marketing and > product positioning if it expects to survive in the rough and tumble world > of mainstream industry. > > Points to note: > > - in 5 years, nobody will be doing significant amounts of new application > development in C++. The writing is on the wall: garbage collection is > essential. Any C++ code will be support and legacy libraries. Well, I tend to agree that people are slowly oozing that way. I think that 5 years is a bit to enthusiastic a prediction, though. What will happen is that C++ will gradually lose market share to other languages. > - Microsoft is already implementing said strategy across all levels of the > company today. Microsoft developers don't do much C++ development anymore. > Various upcoming products are being written entirely in C#. Again, this is an overstatement. New products are being written in C#, older products are staying in C++, and some core operating system products likewise. I have a huge vision of the Windows kernel being written in C#, for example. > - The "higher level language" playing field is crowded: C#, Java, Perl, and > Python. Mainstream industry does not need and will not make room for 4 > higher level languages. Any of these languages has to grow at some other > language's expense. You missed Ruby and TCL. Granted, TCL is probably only being held up by TK and Expect, though. Ruby is the one that's gaining fastest, and it has a number of interesting features that Guido would do well to think about. Perl, on the other hand, has this Perl 6 effort going on; in a couple of years its going to be a completely new language. > - Python will never displace C# on Windows. It's Microsoft's home turf and > you can't fight directly with The Beast. You will see UNIX boxes running > Python, not Windows boxes. Duh. > - Sun is about to die. It has done nothing for anyone lately and has no > further tricks up its sleeve. Don't count the chickens until the fat lady sings. > - Sun has failed to make Java live up to its claims of universality. Java > is for all intents and purposes simply a widespread programming language, > not a portable computing environment. Portable computing environments are, > in general, a pipe dream as long as Microsoft is around. It will always be > Windows vs. open standards. You're contradicting yourself. Python cannot be portable because Microsoft is around? > - Java is proprietary. Python is open source. Open Source is the best shot > that anyone has at competing with Windows. Duh? Again, the fat lady isn't even gargling in the wings on that one. > - Perl is open source and sysadmins won't be giving it up any time soon. > Perl is optimal for their jobs, the capabilities of Python are a non-sell. > > - Ergo, Java is the weakling of the litter for Python to attack. > > - Alternately, if you look at this in real world marketing terms, Python is > the weakling of the litter that must defend itself. I know that will make > various Python idealists upset, but that's the economic reality. Merit > doesn't win in this game. Java is the next weakest langauge so that's whose > lunch Python should try to eat. You forgot Ruby and TCL again. > - No, this isn't the appraisal of a Microsoftie who wants to set Python and > Java at each others' throats to conquer both. :-) I'm just offering a > realistic picture of what your options are, if you don't want to become a > "gee whiz, wasn't that nice!" technology. Like I said, I've lived through > it already. Don't talk to me about merit carrying the day. Learn from > history, or you are doomed to repeat it. There is a major divide between the statically typed languages and the dynamically typed languages. To sell Python, you need to make two points: 1. Static typing does not do the job that its proponents claim for it well enough to be worth the extra development time it imposes, and 2. Python is better for serious systems development than Perl, Ruby, TCL, etc. There are a number of people saying item 1, some rather vociferously, but there is a noticable lack of hard data on the issue. Regardless of the data, the arguement applies to C++, Java and C# equally: they all have the same fundamental approach to static typing. On number 2, I don't think there's any question about Python's general superiority to Perl and TCL for serious, large scale development work. Ruby, on the other hand, is a completely different question. So the basic conclusion is that Ruby is the enemy to be taken on, not Java. John Roth > -- > Cheers, www.3DProgrammer.com > Brandon Van Every Seattle, WA > > 20% of the world is real. > 80% is gobbledygook we make up inside our own heads. > From postmaster at silabs.com Tue Aug 19 12:09:23 2003 From: postmaster at silabs.com (MIMEDefang) Date: Tue, 19 Aug 2003 11:09:23 -0500 Subject: Important notification from the Silabs mail server Message-ID: <200308191609.h7JG9NCf018852@mailgw.silabs.com> An embedded and charset-unspecified text was scrubbed... Name: not available URL: From mpeuser at web.de Sun Aug 31 09:22:21 2003 From: mpeuser at web.de (Michael Peuser) Date: Sun, 31 Aug 2003 15:22:21 +0200 Subject: list.sort(func) speed References: Message-ID: "Peter Otten" <__peter__ at web.de> schrieb im Newsbeitrag news:bisoke$ql$01$1 at news.t-online.com... > You recommend win32api.FindFiles in the old thread, which is non-portable > but definitely not a "self made scheme". I have to admit the numbers are > striking. Wild guess: time is burnt reading directories rather than > processing file name strings. Anyway, standard Python seems to have room > for improvement in the area :-( > One has to be flexible.... I recall a program change I made some weeks ago, where I changed os.path.splitext(x) into x[:-4] because I knew the extension of the some 2000 filenames I wanted to display on a Tk widget. This improves display time from 1,3 to 0,7 secs. Kindly Michael P From davecook at nowhere.net Mon Aug 25 09:41:29 2003 From: davecook at nowhere.net (David M. Cook) Date: Mon, 25 Aug 2003 13:41:29 GMT Subject: Using the C Source Code from Tcl/Tk References: Message-ID: In article , Bgc wrote: > I had a look at Tcl/Tk. And you know what? I like it better than > Python. I'm sick of "bindings" for everything. Tcl/Tk is just > awesome, so why not use it instead? That's what I'm going to do. > What a relief. Sorry if I offended any Tclers with the original post. > I'm very excited, and relieved about my decision. Heretic! I suppose going through the tcl interpreter is not an ideal situation, but it works, and I've seen some pretty amazing things done with Tkinter. I prefer pygtk, though. Tk is beginning to show its age, though the text and canvas widgets are still strong points. Dave Cook From duanev at io.com Fri Aug 1 11:45:51 2003 From: duanev at io.com (Duane Voth) Date: Fri, 1 Aug 2003 10:45:51 -0500 Subject: No module named _curses (RedHat 7) Message-ID: <20030801104551.A23781@io.com> In January someone had this problem on Windows, but I saw it on a RedHat 7.1 system today. []$ python life.py Traceback (most recent call last): File "life.py", line 21, in ? import curses File "/usr/local/lib/python2.2/curses/__init__.py", line 15, in ? from _curses import * ImportError: No module named _curses []$ Turns out my installtion did not have a symlink for libncurses: # cd /usr/lib # ls -l libncurses* lrwxrwxrwx 1 root root 17 Apr 27 08:33 libncurses.so.5 -> libncurses.so.5.2 -rwxr-xr-x 1 root root 257524 Mar 6 2001 libncurses.so.5.2 # ln -s libncurses.so.5.2 libncurses.so Then, go back to your Python sourse directory and do make and make install. -- Duane Voth duanev at io.com -- djv at djv.net From imbosol at aerojockey.com Fri Aug 15 16:08:11 2003 From: imbosol at aerojockey.com (Carl Banks) Date: Fri, 15 Aug 2003 20:08:11 GMT Subject: Style in list comprehensions References: Message-ID: Tim Lesher wrote: > Suppose I have a list of objects and I want to call a method on each. > I can do the simple: > > for i in objs: > i.meth(arg1, arg2) > > or using list comprehensions: > > [i.meth(arg1, arg2) for i in objs] > > The second feels more Pythonic, I disagree. I suspect most Pythonistas would disagree, too. > but do I incur any overhead for > creating the list of results when I'm not going to use it? Of course you do. You've devoted time and RAM (temporarily) to allocating a list you'll never use. Only you can decide whether the overhead is significant to you. Regardless, just from a stylistic standpoint, I highly discourage using a list comp only for it's side effects. -- CARL BANKS "You don't run Microsoft Windows. Microsoft Windows runs you." From hokiegal99 at vt.edu Wed Aug 6 20:28:12 2003 From: hokiegal99 at vt.edu (hokiegal99) Date: Wed, 06 Aug 2003 20:28:12 -0400 Subject: Adding PC Filename Extensions to Macintosh Filenames References: Message-ID: <3F319D1C.2020701@vt.edu> Roman Suzi wrote: > Second, Linux has 'file' command which tells you file type based on > content and knows tonns of formats. How would I use this from within Python to more accurately identify a file? From sympa at ens.fr Thu Aug 28 06:48:15 2003 From: sympa at ens.fr (SYMPA) Date: Thu, 28 Aug 2003 12:48:15 +0200 (CEST) Subject: Results of your commands Message-ID: <200308281048.h7SAmFCr073562@nef.ens.fr> > Please see the attached file for details. Command not understood: ignoring end of message. No command found in message From aleax at aleax.it Wed Aug 6 18:35:51 2003 From: aleax at aleax.it (Alex Martelli) Date: Wed, 06 Aug 2003 22:35:51 GMT Subject: Copying objects style questions References: Message-ID: Bob Halley wrote: >> To forestall further misunderstandings -- this would not work for >> objects with __slots__ (no __dict__) or inheriting from classes with >> __slots__ (wouldn't copy attributes not in __dict__) -- there is >> always more work needed for such cases. But if one uses __slots__ >> one *deserves* to have to work a bit harder as a result;-). > > I use new-style classes with __slots__ :), because it makes a really > noticeable difference in memory usage if you use dnspython to work > with a good-sized zone (i.e. one with tens of thousands of records). If you have huge numbers of instances of a class, it sure may well make sense to give the class __slots__ in order to save memory -- that's what it was introduced for. But then, giving that class a __copy__, or the like, which knows about its slots (or using the deep dark magic of _reduce_ex, I guess...), if you need to perform fancier copies than ordinary copy.copy or copy.deepcopy would do for you, seems fair enough to me:-). Alex From mis6 at pitt.edu Thu Aug 14 12:05:17 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 14 Aug 2003 09:05:17 -0700 Subject: Python/Tkinter/tk crash [long] References: Message-ID: <2259b0e2.0308140805.680fcfb1@posting.google.com> Eric Brunel wrote in message news:... > Hi all, > > I was creating a Tkinter widget in the style of the reversed tabs below Excel > worksheets and I stepped in a serious problem: the code I made makes python > crash with a seg fault, bus error or X11 BadGC error on both Solaris (2.6 and > 2.7) and Linux (Mandrake 8.0); it doesn't crash on Windows. FWIW: it crashes under Red Hat 7.2+Python 2.2 and under Red Hat 7.3+Python 2.3 too. From max at alcyone.com Fri Aug 1 15:31:34 2003 From: max at alcyone.com (Erik Max Francis) Date: Fri, 01 Aug 2003 12:31:34 -0700 Subject: anti-aliased 2D vector graphics References: Message-ID: <3F2AC016.AF781750@alcyone.com> Andy C wrote: > Where can I get a python package to draw such figures? I googled and > found > PyX, I guess it outputs PostScript. I guess I can get a PostScript to > BMP > converter or something. Is there any other alternative? One obvious solution would be to use GhostView to use PostScript to generate an image, and then sample it down with a good resampling library, like PNM. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ As far as I'm concerned, being any gender is a drag. \__/ Patti Smith From nushin2 at yahoo.com Thu Aug 7 18:45:08 2003 From: nushin2 at yahoo.com (nushin) Date: 7 Aug 2003 15:45:08 -0700 Subject: Bug in os.spawnv with P_NOWAIT References: Message-ID: nushin2 at yahoo.com (nushin) wrote in message > If you do not null out the output of your parent process that launches > a child process by os.spawnv( ) in P_NOWAIT mode, you will see that > your child process is launched *synchronously* instead of > asynchronously. This is a bug! > > Here's a code sample: > > In your parent.py file, call child.py as > > os.spawnv(os.P_NOWAIT,'/usr/bin/python',('python', 'child.py')) > > then, make sure your child.py prints a *hello child* to screen about > 2000000 times, and your parent.py prints a *hello parent* message, > then execute your file in a shell as: > > python parent.py > > then, you would see that whenever your child.py is finished, then > parent.py finishes, i.e., a synchronous call. > > Now, null out the output of your parent process as: > > python parent.py > /dev/null > > then, your parent.py finishes first while child.py is still running, > i.e., an asynchronous call. Please correct me if i am wrong. > > Regards, > Nushin Jeff Epler has shed some light on this issue. Thanks to him. =========================================================== Jeff Epler wrote in message news:... > I don't see any problem with P_NOWAIT. Take the following for example: > > $ cat nushin.py > import os > > p = os.spawnvp(os.P_NOWAIT, 'sh', > ['sh', '-c', 'sleep 1; echo from spawnv']) > print "from program" > print "waitpid returns:", os.waitpid(p, 0) > $ python -u nushin.py > from program > waitpid returns:from spawnv > (2826, 0) > > Now, if the program completed very quickly, it's a coin-flip whether its > output would appear before "from program". In this case, I made sure > the program would take a really long time (1 second) to complete. > > When running without -u but not on a terminal, you might see > $ python nushin.py | cat > from spawnv > from program > waitpid returns: (2832, 0) > .. this is because the Python process has printed "from program", but > stdio buffering has kept it from actually being written to the output > yet. > > Here's what you see on a terminal without -u: > $ python nushin.py > from program > from spawnv > waitpid returns: (2835, 0) > This is the same thing you'd see if the program said > print "from program"; sys.stdout.flush() > > Jeff Thanks Jeff. Yes, i think it's the stdio buffering that causes P_NOWAIT act asif it's a P_WAIT. I wish an additional parameter could be added to spawnv( ) to toggle its stdout on/off. Regards, Nushin From p-abel at t-online.de Tue Aug 5 15:27:26 2003 From: p-abel at t-online.de (Peter Abel) Date: 5 Aug 2003 12:27:26 -0700 Subject: xrange() question References: Message-ID: <13a533e8.0308051127.767111ab@posting.google.com> George Trojan wrote in message news:... > Why do I get an overflow error here: > > > /usr/bin/python > Python 2.2.2 (#1, Feb 24 2003, 19:13:11) > [GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-4)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import sys > >>> for n, x in zip(range(4), xrange(0, sys.maxint, 2)): > ... print n, x > ... > Traceback (most recent call last): > File "", line 1, in ? > OverflowError: integer addition > > but not here: > > >>> for n, x in zip(range(8), xrange(0, sys.maxint)): > ... print n, x > ... > 0 0 > 1 1 > 2 2 > 3 3 > 4 4 > 5 5 > 6 6 > 7 7 > > George I think the problem is that sys.maxint is ?? I guess odd if remember my english lesson well ?? >>> print sys.maxint 2147483647 And if you icrement by 2 you will reach sys.maxint+1 to be tested if the end of xrange(start,end,step) is reached - what is ** an Overflow** . So the solution will be: >>> for n, x in zip(range(4), xrange(0, sys.maxint-1, 2)): ... print n, x ... 0 0 1 2 2 4 3 6 Hope this helps. Regards Peter From find.me at my.homepage.net Thu Aug 21 22:21:16 2003 From: find.me at my.homepage.net (Blake Garretson) Date: Thu, 21 Aug 2003 22:21:16 -0400 Subject: Adding a column in a tab delimited txt file In-Reply-To: References: Message-ID: Garry wrote: > Can I write a while loop to count the number of > tab I hit until the counter is 4 and then add a zero in between and > thru the whole file? Try using the split string method and then the insert list method. Untested code: ### infile = file("in.txt") outfile = file("out.txt") for line in f: columns = line.split("\t") columns.insert(4, "0") outfile.write("\t".join(columns)+"\n") ### The code might not be perfect, but you get the idea. -------------------------------------------------- Blake T. Garretson http://blakeg.freeshell.org From skip at pobox.com Wed Aug 13 12:08:16 2003 From: skip at pobox.com (Skip Montanaro) Date: Wed, 13 Aug 2003 11:08:16 -0500 Subject: Emacs [was: Re: Multi-Line Comment] In-Reply-To: References: <4qofjvg3bh9smlnb1do4f0lhjga7bacnu3@4ax.com> <200308122306.48320.shalehperry@comcast.net> Message-ID: <16186.25200.328781.27600@montanaro.dyndns.org> Francois> At times, I wonder if this should be seen as comforting or Francois> frightening. :-) Adventurous... Skip From mpeuser at web.de Sat Aug 16 08:43:58 2003 From: mpeuser at web.de (Michael Peuser) Date: Sat, 16 Aug 2003 14:43:58 +0200 Subject: How remove Tcl/Tk fom py2exe distribution? References: <7k5dzwo9.fsf@python.net> Message-ID: "Michael Peuser" schrieb im Newsbeitrag news:bhl73o$745$07$1 at news.t-online.com... > Thank you Thomas, for these excellent advice. "verbose" of course just > supports debugging and does not prevent py2exe from beeing quite autistic. > And it does a good job in that: Not only sys.path but sys.prefix as well as > sys.exec_prefix are faked to the local directory. This makes it a little bit > harder to supplement the path info. Well not *as* much. Because I am using win32api anyhow, it was easy to paste CheckPythonPaths from regcheck.py Kindly Michael P From mike at nospam.com Tue Aug 19 18:07:24 2003 From: mike at nospam.com (Mike Rovner) Date: Tue, 19 Aug 2003 15:07:24 -0700 Subject: Python Debugger References: <6ee58e07.0308181134.383a69e7@posting.google.com> <3f412cf3.351547428@news.blueyonder.co.uk> <6ee58e07.0308191220.702baf00@posting.google.com> Message-ID: Lothar Scholz wrote: > alan.gauld at btinternet.com (Alan Gauld) wrote in message > news:<3f412cf3.351547428 at news.blueyonder.co.uk>... >> On 18 Aug 2003 12:34:09 -0700, llothar at web.de (Lothar Scholz) >> wrote: >>> Is there any python debugger that can >>> 1) be used remotely >> >> What do you mean by remotely? Debug a program running on a server >> from a remote PC? > > Yes this is what i mean Successfully done that with WingIDE (server on Solaris, debug from PC) Debugging multi-thread python apps is being discussed in another topic. Mike From writeson at earthlink.net Tue Aug 5 18:08:18 2003 From: writeson at earthlink.net (Doug Farrell) Date: 5 Aug 2003 15:08:18 -0700 Subject: 4Suite and XSLT problems Message-ID: <88bc63c6.0308051408.3674e1d9@posting.google.com> Hi all, I'm trying to use the 4Suite xml/xsl tools to transform some XML data into HTML. I'm using some examples from the O'Reilly book "Python and XML" and things are blowing up. Here is the little piece of code I'm working on: from xml.xslt.Processor import Processor proc = Processor() xsl = """

My CD Collection

Title Artist
""" # here comes the problem proc.appendStylesheetString(xsl) I'm not even getting to the transformation part, just trying to load the xsl stylesheet. I've run the above xsl code, along with my xml data though the command line 4xslt and it works fine. When I run the line of Python code immediately above, I get a tracedump from Python that looks like this: Traceback (most recent call last): File "/var/www/html/python/xslttest.py", line 44, in ? proc.appendStylesheetString(xsl) File "/usr/lib/python2.2/site-packages/_xmlplus/xslt/Processor.py", line 124, in appendStylesheetString sty = self._styReader.fromString(text, baseUri) File "/usr/lib/python2.2/site-packages/_xmlplus/xslt/StylesheetReader.py", line 570, in fromString return pDomletteReader.PyExpatReader.fromString(self,st, refUri='', ownerDoc=None, stripElements=None) File "/usr/lib/python2.2/site-packages/Ft/Lib/ReaderBase.py", line 67, in fromString rt = self.fromStream(stream, refUri, ownerDoc, stripElements) File "/usr/lib/python2.2/site-packages/_xmlplus/xslt/StylesheetReader.py", line 622, in fromStream sheet.setup() File "/usr/lib/python2.2/site-packages/_xmlplus/xslt/Stylesheet.py", line 140, in setup self._setupChildNodes() File "/usr/lib/python2.2/site-packages/_xmlplus/xslt/Stylesheet.py", line 183, in _setupChildNodes curr_node.setup() File "/usr/lib/python2.2/site-packages/_xmlplus/xslt/TemplateElement.py", line 46, in setup namespaces=self._nss File "/usr/lib/python2.2/site-packages/_xmlplus/xpath/Util.py", line 83, in ExpandQName split_name = (nss[prefix], local) KeyError I'm at a loss as to what to do and where to go from here. I'm running Python 2.2.2 on a RedHat 9.0 system and I downloaded and installed 4Suite 1.0.* from www.4suite.org (though I don't think that was necessary). If anyone has some suggestions what I'm doing wrong, I'd very very glad to hear them. Thanks in advance, Doug Farrell From mertz at gnosis.cx Sun Aug 17 15:48:33 2003 From: mertz at gnosis.cx (David Mertz) Date: Sun, 17 Aug 2003 15:48:33 -0400 Subject: Py2.3: Feedback on Sets (fwd) References: <2e363c08.0308161306.47a010ae@posting.google.com> Message-ID: |> Raymond Hettinger: |> |def powerset(iterable): ... |David Mertz wrote: |> Hmmm... I should have checked the docs first. A sample implementation |> obviously helps. That said, this isn't REALLY an implementation of |> powerset. Alex Martelli wrote previously: |def therealpowerset(iterable): | return Set(powerset(iterable)) Sure. But naming the first thing 'subsetsof()' (or 'ipowerset()' to match some of the new itertools functions) and the second just 'powerset()' seems better to me. Or maybe the second should be named: powerset_but_use_at_your_own_risk(). However, my point above is that fewer users will lookup a sample implementation than would use a module function. And somewhere in that difference, some of them will do something wrong. |IMHO, one 'real' issue with this function is that it behaves strangely |(to me) when iterable has duplicated elements | data = list(iterable) --> data = Set(iterable) Yeah :-). Which points out that I should have actually READ Raymond's function, rather than just cut-and-paste it. This seems to point out that even the Python developers are able to make mistakes in implementing powerset(). Which again suggests a module function (implemented correctly) is worth having. Yours, David... -- _/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY: Postmodern Enterprises _/_/_/ _/_/ ~~~~~~~~~~~~~~~~~~~~[mertz at gnosis.cx]~~~~~~~~~~~~~~~~~~~~~ _/_/ _/_/ The opinions expressed here must be those of my employer... _/_/ _/_/_/_/_/_/_/_/_/_/ Surely you don't think that *I* believe them! _/_/ From mark at hahnca.com Wed Aug 27 19:45:17 2003 From: mark at hahnca.com (news.west.cox.net) Date: Wed, 27 Aug 2003 16:45:17 -0700 Subject: timing a function with timeit? (newbie problem) Message-ID: Why do I get the exception "global name 'test' is not defined" in this code (next to last line) and how do I fix it? import timeit def test(): x=2+2 t = timeit.Timer('test()') print t.timeit() From adalke at mindspring.com Mon Aug 18 14:08:59 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Mon, 18 Aug 2003 12:08:59 -0600 Subject: overriding a tuple's __init__ References: Message-ID: Aahz: > class pair(tuple): > def __new__(cls, *args): > return tuple.__new__(cls, args) Right. cls instead of self because it isn't passed the instance. It would help me learn this new part of Python if I had any use for it. :) Though *args likely isn't what the OP wanted - I assume that 'pair' takes only two elements. Andrew dalke at dalkescientific.com From mark at hahnca.com Thu Aug 28 00:35:46 2003 From: mark at hahnca.com (Mark Hahn) Date: Wed, 27 Aug 2003 21:35:46 -0700 Subject: finding object using IS instead of == References: Message-ID: Clarification: Is there a FASTER way that takes advantage of the IS equivalence than using the available == method. I assume the == method does a linear search, except for a dict key lookup, which is not what I'm talking about. Obviously if two references are the same object (IS equivalent) then they are == also so you could find based on == and then check for IS, but I want something faster. "Mark Hahn" wrote in message news:Mkf3b.7167$n94.2649 at fed1read04... > If I have a large collection (list, tuple, or dict) of objects, can I locate > one quickly that matches a given object using the IS equivalence operator > instead of the value == operator? > > From vanevery at 3DProgrammer.com Tue Aug 12 04:54:12 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Tue, 12 Aug 2003 01:54:12 -0700 Subject: Python should try to displace Java References: Message-ID: Doug Tolton wrote: > On Mon, 11 Aug 2003 18:43:08 -0700, "Brandon J. Van Every" >> >> - in 5 years, nobody will be doing significant amounts of new >> application development in C++. The writing is on the wall: garbage >> collection is essential. Any C++ code will be support and legacy >> libraries. > > That's a ridiculous blanket statement. People will be doing C++ > development for a long time beyond that. There are people still > writing Cobol for crying out loud. Do you honestly believe that people are doing a significant amount of new application development in Cobol, as opposed to maintenance work? >> - Microsoft is already implementing said strategy across all levels >> of the company today. Microsoft developers don't do much C++ >> development anymore. Various upcoming products are being written >> entirely in C#. > > just what we need. More buggy slow products from MS that have > Memory Leaks the size of the Mississippi. C# is not a good > development platform yet. Heck they are practically still in the > standard MS beta period. Everyone knows not to use a MS product on > version 1.0 Ignore the trend at your peril. A MS product is one thing. A MS initiative across the entire company is quite another. The last time they did that, Internet Explorer put Netscape in the doghouse. Never, ever, ignore or diminish what Microsoft decides to do as an entire company. >> - The "higher level language" playing field is crowded: C#, Java, >> Perl, and Python. Mainstream industry does not need and will not >> make room for 4 higher level languages. Any of these languages has >> to grow at some other language's expense. > > This statement is really vague, and has almost no factual basis. If > there were only four programming languages the world would be a very > dull place. You forgot to mention Delphi, Visual Basic, Power Builder > and a host of others. There is room for a lot more than 4 programming > languages. Actually, Visual Basic vs. C# would be a good discussion in another newsgroup. Because the books about .NET Framework that I'm reading, show how VB is being modded and borgged to fit the Intermediate Language. Which is essentially C#. I wonder if it would be reasonable to say that in 5 years, nobody will be doing new app development in VB, it'll all be C#? But I'll take that up with the VB crowd. >> - Python will never displace C# on Windows. It's Microsoft's home >> turf and you can't fight directly with The Beast. You will see UNIX >> boxes running Python, not Windows boxes. > > That's a bold statement, considering the abysmal adoption rate of C#. Within Microsoft, the adoption of C# is universal. That tends to have a powerful effect on ISV Windows development over time. > C# isn't the dominant windows programming language currently, rather > its Visual Basic. Java has far more applications written for Windows > than C# does. MS really shot themselves in the foot when they went to > dotnet, essentially the adopted the Java platform 8 years after Java. > Now they are playing catchup with an inferior product. I doubt > they'll ever catch up to Java overall. The problem with your thinking here is there's very clear evidence that Microsoft can and does catch up to and surpass technologies that they have fumblingly cloned. In fact, that's the basic Microsoft corporate philosophy. Version 1.0 sucks, 2.0 is ok... 5.0 actually is a really good product and then the competition can't catch up anymore. Example: DirectX. When it started it was complete garbage. Nowadays it is technically superior to OpenGL in most areas. Why they don't finally implement doubles and put OpenGL out of its misery, I'm not sure. Why can MS catch up? Because Open Source people assume their technological superiority and rest on their laurels. They think they don't have to market because they are technically superior. Also, their ranks are populated with strong engineers who don't *like* marketing, as a matter of basic personality. They never get it in their heads that they have to counter-market to some degree in order to hold the line. If you don't do any marketing, Microsoft completely out-markets you and then you die, technical merit or not. >> - Sun is about to die. It has done nothing for anyone lately and >> has no further tricks up its sleeve. > > People have been saying this for years. I'll believe it when I see it. Read a paper. >> - Sun has failed to make Java live up to its claims of universality. >> Java is for all intents and purposes simply a widespread programming >> language, not a portable computing environment. Portable computing >> environments are, in general, a pipe dream as long as Microsoft is >> around. It will always be Windows vs. open standards. > > They must give you a good edjumacation at the Redmond campus. Java is > by far the best portable computing environment available. Care to name a concrete example? A testimonial? >> - Ergo, Java is the weakling of the litter for Python to attack. > > No factual basis for this statement. Java and Python are really > entirely different things. Python is meant as a scripting language, > Java is a Systems programming language. It is meant as an alternative > to C++, Python isn't. You're saying Python isn't useful as a systems language? Then it is already dead. > Who does Python have to defend itself against? Python is Open Source. > The only way it's going to die is if everyone stops developing it and > it stagnates. You got it! And development stops when a langauge loses all meaningful mindshare. What is the battle of mindshare? A marketing battle. It is not a technological battle, except in the grossest terms of complete incompetence. Time and again, the marketplace has proven that kludgy but well marketed products carry the day. They only fail when they absolutely can't do the job. > If that hapens it will be because something *significantly* better came along. No, it is not an engineering meritocracy. Look at a company like DEC. Wonderful technology company. Couldn't market its way out of a paper bag. That's a warning for this c.l.p crowd. Don't sit around congratulating yourselves on how superior your techology is. Recognize the strategic competition and market against it. > Python doesn't have to defend > itself, your Microsoft background is showing through here. C# is by > far the weakest language of the four. It is buggy, slow and immature. > It has the smallest user base, the least amount of industry backing and is 100% backed by all the resources of Microsoft. It will not go away, and its shortcomings will be fixed at a blistering pace. > and a community that is rising up against it's benefactor. Huh? Care to explain? > I think > you dramatically overstate it's chances. Historically Microsoft > switches technologies every 3 or 4 years. That only gives C# about 2 > years to go before it's dead in the water like every other MS > "Innovation". What part of "100% committment across the company" don't you understand? You really are blind. You don't live in Redmond, you can't conceive of having access to this level of information. And who in c.l.p woudl tell you these things? Well, you've been warned. > Historically > those with the best technology and the best economic system prevail > against inefficient and inferior models. You have *got* to be kidding me. Intel??!? Windows??!? -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From abelikov72 at hotmail.com Mon Aug 25 21:52:40 2003 From: abelikov72 at hotmail.com (Afanasiy) Date: Tue, 26 Aug 2003 01:52:40 GMT Subject: Advice to a Junior in High School? References: Message-ID: On Mon, 25 Aug 2003 22:57:44 GMT, "Howard Nease" wrote: >Hello, everyone. I would appreciate any advice that someone could give me on >my future career path. Here is my situation: > >I am a bright Junior in a very well-respected private high school, taking >almost all AP and accelerated classes. I am HIGHLY interested in technology, >more specifically the field of Computer Science and software engineering. I >have heard a whole lot about the fact that the market for software engineers >nowadays is *HORRIBLE*, and that I should double major or perhaps go into a >field of study in which I'm not very interested. > >I would be devastated were I to find the need to leave computer science. I >love the subject, and I've wanted to be a computer scientist ever since I >was 12 years old. > >Does anyone have any advice for me and my future? What should I study in >college? Will the market for jobs get better? Do I have any hope at all of >finding a decent-paying job in compsci? What languages do you suggest that I >study (I'm already studying Python)? I would make sure to consider a field, in a non-computer science, which allows/requires you to use your interest/skills in computer programming. I believe I chose the right words, so read them carefully. I don't think that leaves any questions of me. Your decision should be your decision. Languages... Whatever appeals to you, but that probably depends on what you want to do. From davecook at nowhere.net Wed Aug 20 04:47:01 2003 From: davecook at nowhere.net (David M. Cook) Date: Wed, 20 Aug 2003 08:47:01 GMT Subject: class factory References: <8ad2cfb3.0308200015.4f5bd504@posting.google.com> Message-ID: <9AG0b.38668$Ij4.14194@news2.central.cox.net> In article <8ad2cfb3.0308200015.4f5bd504 at posting.google.com>, Nick Keighley wrote: > I'm a Python beginner and I'm would like to write a function that > returns a class (perhaps a tad ambitious...). I've looked through > the FAQ and perused "Python In A Nutshell" (not a good book to > start with?). The only example I found in PiaN used a simple > if statement to return one of a selection of pre-existing classes. > I'd like to generate a class on-the-fly from a parameter (a dictionary). > Can Python do this sort of stuff? Does the mean I have to mess with > the dreaded meta-classes? You can create classes on the fly using "type" >>> type('Foo', (object,), {}) The arguments are the class name, a tuple of base classes, and a dictionary of methods. See http://python.org/2.2/descrintro.html#factories Dave Cook From chema-news at chema.homelinux.org Thu Aug 28 09:11:30 2003 From: chema-news at chema.homelinux.org (=?iso-8859-1?Q?Jos=E9_Mar=EDa?= Mateos) Date: Thu, 28 Aug 2003 15:11:30 +0200 Subject: [Off-Topic] slrn scoring (was: Re: Filtering virus-related e-mails?) References: <3f4ce4d6$0$166$a1866201@newsreader.visi.com> <3f4d1580$0$153$a1866201@newsreader.visi.com> Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 In comp.lang.python, Grant (grante at visi.com) wrote: > Setting up scoring in slrn is probably what I ought to do. It > would be useful for other stuff too. Once you start scoring, you can't stop :-). There are also some useful scoring macros at the slrn web page (http://www.slrn.org). Regards, Chema. - -- Esta direcci?n de correo NO se lee. Quita "-news" para contestar This e-mail address is NOT being read. Take out "-news" to reply Web & GPG key: http://chema.homelinux.org/ -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (GNU/Linux) iD8DBQE/Tbil9P6GbSlI+hkRAtPRAKDR4EukJwRnObpVbncSY8rxToMY/QCgneNG jfqAtrR+gVlCIhq6vPhi5b0= =1ski -----END PGP SIGNATURE----- From mcfletch at rogers.com Tue Aug 5 01:02:08 2003 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Tue, 05 Aug 2003 01:02:08 -0400 Subject: MVC in Python In-Reply-To: References: Message-ID: <3F2F3A50.6010703@rogers.com> Troy Melhase wrote: >MK wrote: > > >>How to achieve this feat in Python? Which techniques >>do you guys use? >> >> > >Hi MK: > >If memory serves (and it rarely does), you have two options. The first >would be custom wx events, and the second would be the evtmgr module in the >wxPython.lib package. Both approaches have examples in the wx demo >application. The evtmgr demo is absolutely dazzling in its simplicity, and >I would suggest you start your search there. > > Another option: a number of people also use the multi-consumer-multi-producer "dispatcher" engine. There's a sourceforge project for the latest version here: http://sourceforge.net/projects/pydispatcher/ I've used it in both OpenGLContext and ConflictSolver/wxPython Properties Distribution (and helped a little with putting together the above project). * It's *not* GUI-lib specific, but it works nicely with GUI libraries (and was, IIRC originally created for use with a GUI library), so your model objects don't have dependencies on the GUI code at all, but can readily generate events to which the GUI can subscribe. * There's no requirement that your objects be aware of the event-routing infrastructure. * Registering interest doesn't (generally) affect object lifetimes (that is, dispatcher uses weak references by default (and has special code to allow safe weak references to methods of objects), so that when objects go away their associated routing tables are also cleaned up). The basic pattern is to register interest in certain classes of messages (which are just any hashable value, and may be a special "Any" message to recieve all messages) from a specific sender, any sender, or a special "anonymous" sender. That interest is registered by passing in a callable object (a "receiver"). You then send messages, specifying the sender (which can be "Anonymous") and the message. The system finds all receivers which have registered interest that matches the sender + message combination, figures out what part of the arguments to the message are applicable to the particular receiver, and collects the results of delivering the message to each receiver. All-in-all, it's a good system for normal application event routing, but to be clear, it's not: * an IPC mechanism... this is an in-process mechanism (though IIRC someone has done some experimenting with doing RPC calls with it) * asynchronous (message delivery occurs at the moment you call "send") * protected against event looping (you have to do that in your own code), i.e. it won't detect that method q is sending an event to itself * guaranteed (this isn't an enterprise application routing infrastructure with guaranteed message delivery, input and output queues, logging and the like, it's a lightweight framework for desktop application development) * highly scalable (you don't want to load 100s of thousands of highly dynamic (i.e. disappearing and reappearing rapidly, and/or constantly changing their routing parameters) nodes, (though the version above does include significant improvements beyond the original Python Cookbook version in this regard)). That said, it's right up the MVC for desktop applications alley, so I'd suggest taking a look. Enjoy yourself, Mike _______________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://members.rogers.com/mcfletch/ From bokr at oz.net Sat Aug 9 12:09:29 2003 From: bokr at oz.net (Bengt Richter) Date: 9 Aug 2003 16:09:29 GMT Subject: CLI+GUI References: <2259b0e2.0308080948.5a95e383@posting.google.com> <2259b0e2.0308090530.7519f195@posting.google.com> Message-ID: On 9 Aug 2003 06:30:40 -0700, mis6 at pitt.edu (Michele Simionato) wrote: >mis6 at pitt.edu (Michele Simionato) wrote in message news:<2259b0e2.0308080948.5a95e383 at posting.google.com>... >> I wonder what is the recommended way of using Tkinter >> together with a command line oriented application. > >Replying to myself ... > >I tried to implement what I discussed in my previous mail via the >threading module: > >#cmdriven.py > >import Tkinter as t >import cmd,threading > >root=t.Tk() >s=t.StringVar() >s.set('ciao') >label=t.Label(root,textvariable=s) >label.pack() > >class Cmd(cmd.Cmd): > def do_display(self,arg): > s.set(arg) > def do_quit(self,arg): > root.quit() > return 'quit' # anything <> None will do the job > >def cmdloop(stringvar): > try: Cmd().cmdloop() > finally: pass # gracefully exit if sometimes goes wrong > >thread=threading.Thread(target=cmdloop,args=(s,)) >thread.start() >root.mainloop() > >It works if I do something like > >$ python cmdriven.py >(Cmd) display hello >(Cmd) display It works! >(Cmd) quit > >However, I wonder if this is a robust solution and if I should expect >problems in more complicate situations (some time passes ... I have >just discovered that this script hangs under Windows 98!) > >BTW, I have another question, why the Cmd class does not have a default quit >method? Looking at the source I see that any method returning something >different from None will stop the command loop, and so I have used this >hack, but I don't like it. Maybe I have missed something in the documentation? Thank you for exploring this. I have wanted light weight canvas to paint on from a CLI program, but tk would be nice too. I'm trying to prototype my UFF file idea right now, but this is also interesting. The above looks a little iffy to me off hand, unless there is some built in thread safety magic in cmd loop doing s.set(arg). I.e., isn't s bound in the main thread and the s.set(arg) call in the other thread? I think I'd look at the queue module, or maybe socket. Probably you are already there ;-) Regards, Bengt Richter From sdhyok at yahoo.com Sun Aug 10 23:52:29 2003 From: sdhyok at yahoo.com (sdhyok) Date: 10 Aug 2003 20:52:29 -0700 Subject: How to print floating point in scientific format? References: <420ced91.0308081115.7060e551@posting.google.com> <420ced91.0308101127.644f9813@posting.google.com> <_%zZa.37775$an6.1321077@news1.tin.it> Message-ID: <420ced91.0308101952.73f4fa9b@posting.google.com> Thanks, Alex. snip > If you're doing scientific computations in Python and use arrays but > not Numeric (or its slated-to-be-replacement numarray, of which I > don't know much yet; or the many things layered atop of and onside > of Numeric, such as scipy), switch. You'll be happy you did. I refer all sequences, but, as you say, particularly numpy arrays. > I've never heard a scientific programmer complain too badly about > how Numeric treats arrays, whether they were coming from Fortran > (the typical case), other higher-level languages, or general purpose > languages not really suited for scientific computation (such as C). Right, we can use scientific binary formats, like NetCDF, HDF. But, we often want to read the data in our naked eyes and exchange them with spreadsheet. > > You seem to be focused on readable display of arrays (quite an > unusual focus for scientific programming). So, worst case, it's trivial > to write a general purpose function that takes an array of ANY size > and rank and emits it in the way you prefer -- easier than in any > other language commonly used for scientific programming. > > So, you don't need anything from Python -- just write that blessed > function and scientifically program to your heart's content. Trivial to create my own function. But, surprisingly no common function or command for the work. Maybe, one solution is import Numeric as N N.print(array, format="%.2E") Daehyok Shin From hst at empolis.co.uk Wed Aug 6 09:37:45 2003 From: hst at empolis.co.uk (Harvey Thomas) Date: Wed, 6 Aug 2003 14:37:45 +0100 Subject: Isn't there a substring(start, end)-function???? Message-ID: <8FC4E7C302A6A64AAD5DB1FA0E825DEB53BE2A@hendrix.empolisuk.com> Dave wrote: > Hi all, > > Am I blind, or what? I can't find any quick way to do the following in > Python: > > substring(beginIndex, endIndex) witch returns the substring between > beginIndex and endIndex. > > Like: > text = "If someone attacks you with a banana" > print text.substring(0,3) > Should print "If " > > I've found absolutely everything else that I expect from a modern > programming language, but none of the modules (not even "string"!) > seems to have what I'm looking for. > > Please tell me I'm blind! > > Dave There isn't a substring function, because it's not necessary as slices do the job. The short answer is: text = "If someone attacks you with a banana" print text[0:3] but its explained much more fully in http://www.python.org/doc/current/tut/node5.html#SECTION005120000000000000000 Harvey _____________________________________________________________________ This message has been checked for all known viruses by the MessageLabs Virus Scanning Service. From dpcat at cs.uiuc.edu Fri Aug 22 03:05:39 2003 From: dpcat at cs.uiuc.edu (Design Pattern Catalog) Date: Fri, 22 Aug 2003 02:05:39 -0500 (CDT) Subject: Design Patterns Message-ID: <200308220705.CAA20499@chip.cs.uiuc.edu> Thank you for your interest in "Design Patterns: Elements of Reusable Object-Oriented Design", by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides. This message answers several frequently asked questions. If you thought you were asking for the source code, you must have made a mistake. Please try again! The "pattern home page", with all this information and more, is at http://st-www.cs.uiuc.edu/users/patterns/patterns.html You can get the source code from there, too. There are several mailing lists dealing with patterns. gang-of-4-patterns at cs.uiuc.edu is about the design patterns in our book. If you've got any questions about our patterns, please ask them there. For example, post errata there, or questions about how to implement Singleton. patterns-discussion at cs.uiuc.edu is for discussing patterns in general, i.e. for discussing how to find patterns, how to organize them, or the meaning of patterns, but not necessarily about particular patterns. It is pretty busy. patterns at cs.uiuc.edu is a place for presenting and describing software patterns. This is where you learn about new patterns. They don't have to be object-oriented or design patterns, though most of them are. It is not very busy, so it won't flood your mailbox. To subscribe to these, send e-mail to gang-of-4-patterns-request at cs.uiuc.edu, patterns-request at cs.uiuc.edu, or patterns-discussion-request at cs.uiuc.edu with the subject of "subscribe". Or, go to the patterns home page and see the page on mailing lists, which describes a bunch more and will automatically subscribe you. If you want permission to copy something from the book, you need to talk to Addison-Wesley, not us. Addison-Wesley has a copyright department. They will either just let you do it or charge you a small fee. If you are just copying a few pages for a few people, then it falls under "fair use" and is OK. I don't know what the limit is, though. There is an archive of pattern-related material available by anonymous ftp from st.cs.uiuc.edu in /pub/patterns. In particular, the source code for our book is in /pub/patterns/dpcat. Try that if the mailer isn't returning the source code for you. It acts up a lot. If none of these solves your problem, you can send e-mail to johnson at cs.uiuc.edu. Otherwise, it might be a few months before your message is read. -Ralph From tjland at iserv.net Thu Aug 21 22:19:05 2003 From: tjland at iserv.net (tjland at iserv.net) Date: Thu, 21 Aug 2003 22:19:05 -0400 (EDT) Subject: What had been going on with the list? In-Reply-To: <1768.68.75.128.246.1061412809.squirrel@webmail.iserv.net> References: <1768.68.75.128.246.1061412809.squirrel@webmail.iserv.net> Message-ID: <1318.68.73.70.2.1061518745.squirrel@webmail.iserv.net> Ok now that i ca > > > > When you see the net take the shot > When you miss your shot shoot again > When you make your shot you win! > > Just remember > Offense sells tickets > But defense wins championships! > > -- > http://mail.python.org/mailman/listinfo/python-list > When you see the net take the shot When you miss your shot shoot again When you make your shot you win! Just remember Offense sells tickets But defense wins championships! From mpeuser at web.de Thu Aug 21 00:40:04 2003 From: mpeuser at web.de (Michael Peuser) Date: Thu, 21 Aug 2003 06:40:04 +0200 Subject: how fast is Python? References: <3f43e5cf$0$49115$e4fe514c@news.xs4all.nl> Message-ID: "Irmen de Jong" schrieb im Newsbeitrag news:3f43e5cf$0$49115$e4fe514c at news.xs4all.nl... > Python is fast enough for me, especially 2.3. > > Profile & code slow parts as C extensions. > Include your own assembly there if so desired. > Investigate Psyco. There was one example on this > newsgroup that showed that Python+psyco actually > outperformed the same program in compiled C. > > --Irmen This are my advice as well. Especially use the profiler and change your high level algorithms. You will find a lot with hidden quadratic behavaviour which slow down your program when it comes to high volume. Psyco will generally speed up 2. This is fine (I use it!) but not a break through. There may be cases where it performs better. A bottleneck can be Tkinter. Use something different then (Qt, wx).. Kindly Michael P From cnetzer at sonic.net Wed Aug 27 22:38:31 2003 From: cnetzer at sonic.net (Chad Netzer) Date: Wed, 27 Aug 2003 19:38:31 -0700 Subject: Style question... In-Reply-To: <3F4D63AD.FBBFCCFB@alcyone.com> References: <4cd3b.50331$la.863381@news1.calgary.shaw.ca> <3F4D63AD.FBBFCCFB@alcyone.com> Message-ID: <1062038311.1853.138.camel@adsl-209.204.179.133.sonic.net> On Wed, 2003-08-27 at 19:06, Erik Max Francis wrote: > Anthony Roberts wrote: > > > There is, but it can't tell if I want some stuff indented or not. > > Sure it can. Hit tab or backspace. I think the problem is that people learn to reindent chunks of code by the following technique: . . . This has the unfortunate consequence of breaking your code when you hit multiply indented loops, nested functions, function or loop boundaries, etc. However, by sticking 'pass' at the end of loops, emacs's python-mode will assume a dedent and preserve the indenting at boundaries. But, this technique will STILL fail on multiply nested loops, etc. (emacs does it's best, but it cannot mind read) So it is a terrible habit to get into, because it WILL cause you problems if relied upon blindly. So, it is better to NOT rely on the 'pass' crutch, and instead rely on the python mode operations for reindenting blocks of code (which Eric provided; surely this is becoming a FAQ) So, to Anthony, if you are using the TAB key to indent blocks of code, and relying on 'pass' to make it easier, just be aware that this technique is NOT robust. -- Chad Netzer From skip at pobox.com Mon Aug 11 15:17:38 2003 From: skip at pobox.com (Skip Montanaro) Date: Mon, 11 Aug 2003 14:17:38 -0500 Subject: Multi-Line Comment In-Reply-To: <4qofjvg3bh9smlnb1do4f0lhjga7bacnu3@4ax.com> References: <4qofjvg3bh9smlnb1do4f0lhjga7bacnu3@4ax.com> Message-ID: <16183.60370.315829.561941@montanaro.dyndns.org> Doug> I've been using Python for quite some time now, and I'm a bit Doug> stumped. Does it really not have a multi-line comment? I think I Doug> must just be missing something simple and stupid. Nope, no multi-line comment. The python-mode package which is available for Emacs and XEmacs supports commenting a block of text. You can also use triple-quoted strings: """ This is a multi- line comment (sort of) """ It gets evaluated but immediately popped from the execution stack. Skip From a.schmolck at gmx.net Mon Aug 4 07:08:55 2003 From: a.schmolck at gmx.net (Alexander Schmolck) Date: 04 Aug 2003 12:08:55 +0100 Subject: Classes in Python References: <14dsivkn40c0grotsti39cgsrde7v03hq4@4ax.com> Message-ID: Wiebke P?tzold writes: > Hi all! > > Could somebody help me with a task? I don't know what exactly you're trying to do (I don't know Mk4py), but... > > import sys > import Mk4py > import re > > db = Mk4py.storage("c:\\datafile.mk",1) > vw = db.view("people") > > class PatternFilter: > def _init_(self, pattern): __init__ > self.pattern = re.compile(pattern) > > def _call_(self, row): __call__ > try: > nachname = row.Nachname > except AttributeError: > return 0 > return self.pattern.search(nachname)is not None > > vf = vw.filter(PatternFilter("Ge.*")) Before posting this, you should really have tried something like: class Dummy: Nachname = 'Some name' PatternFilter("Ge.*")(Dummy) > > for r in vf: > print vw[r.index].Nachname > > > > I wrote this program, but it returns nothing. I can't find the error. Well, given the two errors I found, it would seem strange to me that it vw.filter doesn't moan about PatternFilter("Ge.*") being not callable. > Can somebody help me? > Can somebody tell me why the part: "class PatternFilter:" doesn't > return the expressions it should return? 'as From aleaxit at yahoo.com Mon Aug 4 11:13:43 2003 From: aleaxit at yahoo.com (Alex Martelli) Date: Mon, 4 Aug 2003 17:13:43 +0200 Subject: Python speed vs csharp In-Reply-To: <3F2E6D44.4050006@ghaering.de> References: <3F2E6D44.4050006@ghaering.de> Message-ID: <200308041713.43727.aleaxit@yahoo.com> On Monday 04 August 2003 04:27 pm, Gerhard H?ring wrote: > Alex Martelli wrote: > > [nice flame, fun to read] Glad you liked it:-). > I interpreted Mr. Gonzi's statement "Python is crap" to be meant for > numerical programming. Which I can support, unless you use third-party > libraries like Numeric, psyco or others. that's like saying, say, that "C is crap" for multimedia programming... unless you use third-party libraries like SDL. Of _course_ you'll use the appropriate tools for the kind of applications you're writing (what languages, in turn, such tools/libraries are implemented in, is quite secondary -- if and when the pypy project is done, it will not change the nature of Python programming, even though extensions may well at that time have to be similarly reimplemented in Python). Using psyco is as hard as inserting _two_ statements into your code. You may call it "using a library", it that floats your boat, but to me it feels much closer to using 3rd-party optimizer tools for Fortran matrix computations (I still remember the early-90's release of such a tool as totally busting the "specmarks"...), using a jit-enabled JVM rather than a non-jitting one for Java, etc. It doesn't change the way you write your code, as "using a library" normally implies -- it just makes your code faster (if you're lucky;-). How does that differ from, say, using a newer and better optimizer as part of your favourite compiler for any given language? Why is it crucial to you whether such an optimizer is "third-party" or rather sold by the same supplier as your base compiler? If a language "is crap" as long as a needed optimizer is supplied by a third party, then what would the magical process be that would suddenly make it "non-crap" if the base compiler's seller bought out the optimizer-selling company and released the oprimizer itself? How would such a purely commercial operation change the language from "crap" into "non-crap"?-) I'm afraid these observations suggest you may not have thought the issues through. > Perhaps it was a misunderstanding and you two can calm down now. I'm quite calm, thanks (the flames being as fun to write as they are to read:-). And Mr Gonzi has asserted he won't take further part in the discussion, so, unless he wants to show himself up as an outright liar (not for the first time), I guess your recommendations can't affect him now. > Or just continue your flames, they're fun to read :) Glad to hear this! I'll no doubt flame again when the occasion should arise (I _am_ quite prone to doing that, as is well known). Alex From chema-news at chema.homelinux.org Thu Aug 28 04:09:09 2003 From: chema-news at chema.homelinux.org (=?iso-8859-1?Q?Jos=E9_Mar=EDa?= Mateos) Date: Thu, 28 Aug 2003 10:09:09 +0200 Subject: [Off-Topic] slrn scoring (was: Re: Filtering virus-related e-mails?) References: <3f4ce4d6$0$166$a1866201@newsreader.visi.com> <3f4d1580$0$153$a1866201@newsreader.visi.com> Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 In comp.lang.python, Grant (grante at visi.com) wrote: > Setting up scoring in slrn is probably what I ought to do. It > would be useful for other stuff too. Once you start scoring, you can stop. There are also some useful scoring macros at the slrn web page (http://www.slrn.org). Regards, Chema. - -- Esta direcci?n de correo NO se lee. Quita "-news" para contestar This e-mail address is NOT being read. Take out "-news" to reply Web & GPG key: http://chema.homelinux.org/ -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (GNU/Linux) iD8DBQE/Tbil9P6GbSlI+hkRAtPRAKDR4EukJwRnObpVbncSY8rxToMY/QCgneNG jfqAtrR+gVlCIhq6vPhi5b0= =1ski -----END PGP SIGNATURE----- From sismex01 at hebmex.com Thu Aug 14 10:40:07 2003 From: sismex01 at hebmex.com (sismex01 at hebmex.com) Date: Thu, 14 Aug 2003 09:40:07 -0500 Subject: Is Python your only programming language? Message-ID: [Nick Vargish] > > So what programming language actually does bridge the gap between > > "thousands of lives depend on the code working right" and "getting > > this up and running quickly"? [Van Gale] > I think that Ada is one of the few languages capable of being used on > "lives depend on it" systems. It's not anything special about the > language in particular, but rather the immense amount of > man-hours and time spent in writing checking and analysis tools. > That includes tools that can verify an Ada program will meet real-time > requirements. This kind of tool is really sophisticated (obviously) > and would probably be impossible to code for anything but a strong > static typed language. Coincidently, there's a thread like this on comp.lang.forth, and precisely Ada was brought out as an example of a created-for-correctness language; but one of the problems with this is brittleness. As an example, someone mentioned the Arianne accident, a few years back, which was "caused" by a Zero-division error caught by the code, which raised some kind of error condition (I don't do Ada). BUT, it seems that the segment of code being checked wasn't even going to be executed (something about horizontan acceleration), and since the rocket was already in the air, that code shouldn't have mattered; "if it was C, then the operation would have silently failed, and the rocket would have kept flying". It's not really a criticism against Ada, but bad systems design/ implementation; for those cases where lives are at stake, or rocket sciences ;-) , you need code coverage tools, extensive unit tests, etc... so that absolutely NO untested code lines get into the system. anyhow... -gustavo Advertencia:La informacion contenida en este mensaje es confidencial y restringida, por lo tanto esta destinada unicamente para el uso de la persona arriba indicada, se le notifica que esta prohibida la difusion de este mensaje. Si ha recibido este mensaje por error, o si hay problemas en la transmision, favor de comunicarse con el remitente. Gracias. From newsgroups at jhrothjr.com Thu Aug 28 22:11:07 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Thu, 28 Aug 2003 22:11:07 -0400 Subject: Proposal: Magic Constants References: <7h3r837ce12.fsf@pc150.maths.bris.ac.uk> <7h365kj6jp8.fsf@pc150.maths.bris.ac.uk> Message-ID: "Michael Hudson" wrote in message news:7h365kj6jp8.fsf at pc150.maths.bris.ac.uk... > "John Roth" writes: > > > "Michael Hudson" wrote in message > > news:7h3r837ce12.fsf at pc150.maths.bris.ac.uk... > > > "John Roth" writes: > > > > > > > But these are existing literal syntax. I was thinking > > > > more of random code where someone could currently > > > > juxtapose a literal and an identifier, say, without an > > > > intervening white space character. > > > > > > >>> 10and 1 > > > 1 > > > >>> 5or 7 > > > 5 > > > > > > Very much a wart of the tokenizer, though. > > > > Ah, right. I forgot about alphabetic operators. > > > > Why do you call it a wart, though? I would have > > thought that not requiring white space in that context > > was a feature. > > Well, it's just odd. I'm pretty sure it's not intentional, and fairly > sure it's not documented. I don't care enough to check, though :-) The whitespace rule (from the Python Language Reference Manual) is: [begin excerpt LRM 2.1.8 in Python 2.2.3] Except at the beginning of a logical line or in string literals, the whitespace characters space, tab and formfeed can be used interchangeably to separate tokens. Whitespace is needed between two tokens only if their concatenation could otherwise be interpreted as a different token (e.g., ab is one token, but a b is two tokens). [end excerpt] John Roth > > Cheers, > mwh > > -- > In many ways, it's a dull language, borrowing solid old concepts > from many other languages & styles: boring syntax, unsurprising > semantics, few automatic coercions, etc etc. But that's one of > the things I like about it. -- Tim Peters, 16 Sep 93 From mhammond at skippinet.com.au Fri Aug 8 22:08:44 2003 From: mhammond at skippinet.com.au (Mark Hammond) Date: Sat, 09 Aug 2003 12:08:44 +1000 Subject: problems with python: pywintypes.com_error In-Reply-To: <5f5c82ec.0308080304.495fb03b@posting.google.com> References: <5f5c82ec.0308080304.495fb03b@posting.google.com> Message-ID: Matt Smith wrote: > I am calling a program called v2wreg (its a program for interfacing > with the registers/parallel port, used, unfortunatly i think > exclusivly, by the company I work for), I can load the program fine, > but when I come to use any of its advanced featurs i.e. > SetDeviceAddress or ReadRegister I get the same type of error message. > > i.e. > File "", line 2, in MakeConnection > pywintypes.com_error: (-2147352571, 'Type mismatch.', None, 1) These generally mean you are passing the incorrect param types to the object. It is the object complaining, not Python. Some things look a little suspect - eg: serialBusToolv2wReg.SetDeviceAddress = self.deviceAddress It is likely this should be written as: serialBusToolv2wReg.DeviceAddress = self.deviceAddress or serialBusToolv2wReg.SetDeviceAddress(self.deviceAddress) If you still have trouble, you should try reducing it down to no more than 5 lines of Python that demonstrates the problem, and the equivilent VB/Anything code that works. Mark. From pu at nodomain.lu Wed Aug 27 16:36:38 2003 From: pu at nodomain.lu (Patrick Useldinger) Date: Wed, 27 Aug 2003 22:36:38 +0200 Subject: pure Python DB References: <9a6d7d9d.0308261756.5b37cbf4@posting.google.com> Message-ID: On Wed, 27 Aug 2003 08:40:34 +0200, Gerhard H?ring wrote: >> Um.. doesn't support transactions? It depends what you mean, >> I guess. It supports transaction commit and rollback and recovery >> but not transaction concurrency... (yet) In my case, only one process is supposed to acces the DB, but I need to be able to rollback in case it goes wrong, or to commit only all went right. From donn at drizzle.com Thu Aug 14 11:39:48 2003 From: donn at drizzle.com (Donn Cave) Date: Thu, 14 Aug 2003 15:39:48 -0000 Subject: Python signal delivery under BSD 4.4 References: <7h3isp04bzm.fsf@pc150.maths.bris.ac.uk> Message-ID: <1060875587.495888@yasure> Quoth Michael Hudson : | At some point, the threads implementation got changed so that new | threads get their signal mask set to "block everything and it's cat" | (there was a reason for this, but I'm not really sure what it was). | As I see it, you have two options: 1) write a little C to unset the | procmask after fork() but before execve() 2) only launch apps from the | main thread. | | I did write wrappers for sigprocmask & so on for inclusion in Python | 2.3, but the x-platform behaviour was insane (and *some* version of | FreeBSD contains fixes to libc_r that my code provoked, but I'm not | sure which version) so the code got backed out again. Since the present case involves os.spawnv, option 1 is probably feasible. At worst, he could write a C program that zeroes the signal mask and execs its args (i.e., an extra execve before sigprocmask() shouldn't hurt anything.) Of course Python level access would be better. Donn Cave, donn at drizzle.com From neel at mediapulse.com Mon Aug 25 11:58:37 2003 From: neel at mediapulse.com (Michael C. Neel) Date: Mon, 25 Aug 2003 11:58:37 -0400 Subject: Modifying the {} and [] tokens Message-ID: > The problem here is that, when looking at d1 + d2, it is not > obvious what is > going on. If the same key appears in both d1 and d2, what > will the resulting > dict have? The value in d1? The value in d2? Or maybe an > exception will be > raised? Different people will have different notions here > about what is > "obvious" and "natural". > > "Pick one and make that the standard" may work in some other > languages, but > that is usually not how Python's design works. If there is > not "one obvious > way", chances are it won't make it into the language. (Of > course, there are > exceptions... but this seems to be a rule-of-thumb.) > Sadly, I think python is taking this too far, and spends more time debating operators than advancing the language. This has kept out ?: and += from being allowed. And in Geoff's case here, if Python supported traditional C++ like operator overloading, then we could have the best of both worlds - he doesn't "replace" the builting dict, but creates a new dict class and overloads {} and +,- or whatever else he wishes. Coming up with a solution that everyone likes is not going to happen... ever (re: ', '.join([]) ). but we shouldn't rule out something because there is not a uniamous vote (if that were so, we would have no join method). IMHO of cource, Mike From writeson at earthlink.net Tue Aug 12 08:19:50 2003 From: writeson at earthlink.net (Doug Farrell) Date: 12 Aug 2003 05:19:50 -0700 Subject: 4Suite and XSLT problems References: <88bc63c6.0308051408.3674e1d9@posting.google.com> Message-ID: <88bc63c6.0308120419.5774ed23@posting.google.com> uche at ogbuji.net (Uche Ogbuji) wrote in message news:... > > Your answers are here: > > http://uche.ogbuji.net/tech/akara/nodes/2003-01-01/basic-xslt > http://www.xml.com/pub/a/2002/12/11/py-xml.html > > --Uche > http://uche.ogbuji.net Uche, Thank you very much for the response, that is a big help to me and I'll try and implement your suggestions. I'll post back here to let you know of my success. Again, thanks! Doug From news at datatailors.xs4all.nl Fri Aug 8 18:48:59 2003 From: news at datatailors.xs4all.nl (Peter van Kampen) Date: Sat, 9 Aug 2003 00:48:59 +0200 Subject: problem updating(run) to python2.2 References: <3F341829.3050002@softnet.tuc.gr> Message-ID: In article <3F341829.3050002 at softnet.tuc.gr>, grid wrote: > i have Debian, > i have python2.1 and when installing python2.2, i run "$/python ",but pc > run's python2.1.How can i overcome this problem? > > thanks > $python2.2 (on woody) Hth, PterK -- Peter van Kampen pterk -- at -- datatailors.com From code at joecheng.com Tue Aug 12 11:56:11 2003 From: code at joecheng.com (Joe Cheng) Date: Tue, 12 Aug 2003 15:56:11 GMT Subject: Summer reading list References: <5d0_a.288$jw4.85@nwrdny03.gnilink.net> Message-ID: > Accordingly, I suggest the following works of literature: > > * heapq.py (255 lines) > * sets.py (536 lines) > * textwrap.py (355 lines) > * csv.py (427 lines) > > These make enjoyable reading, cover interesting topics/algorithms, > demonstrate superb modern python technique, and showcase > effective use of Python's newer features. I read heapq.py from here: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/python/python/dist/src/Lib/he apq.py Quoting from the comments: """Usage: heap = [] # creates an empty heap heappush(heap, item) # pushes a new item on the heap item = heappop(heap) # pops the smallest item from the heap item = heap[0] # smallest item on the heap without popping it heapify(x) # transforms list into a heap, in-place, in linear time item = heapreplace(heap, item) # pops and returns smallest item, and adds # new item; the heap size is unchanged""" It might just be my Java background creeping in (I'm a Python newbie), but, wouldn't it be better if this was OO? heap = Heap() heap.push(item) item = heap.pop() item = heap[0] heapified = Heap(x) item = heap.replace(item) Otherwise the user could easily break the heap by doing something dumb to the list... From ghowland at lupineNO.SPAMgames.com Sat Aug 23 05:16:13 2003 From: ghowland at lupineNO.SPAMgames.com (Geoff Howland) Date: Sat, 23 Aug 2003 09:16:13 GMT Subject: Modifying the {} and [] tokens References: Message-ID: <04cekv0s6ghjtuhl5j2gph7ltobdb5rsam@4ax.com> On 23 Aug 2003 07:02:53 GMT, "OKB (not okblacke)" wrote: >> {} + {}, {} - {}. [] - [], etc > > I'm a little puzzled as to why you'd need these, since it seems >like all they allow you to is hard-code a certain combination of >statically defined objects. That is, if you're going to do > >{ 'a': 1, 'b': 2 } + { 'c': 3, 'd': 4} > > . . .why not just write > >{ 'a': 1, 'b': 2, 'c': 3, 'd': 4} > > in the first place? Because I wouldn't just be using {} on a line, I would create a dictionary with it and then use it around, and then at some point later I may want to add another dictionary to it, or find the union or differences between two dictionaries. Ruby has this built in, it's useful, it's complete. It's obvious what is happening, so it's not unclean. It's allowed for other containers. -Geoff Howland http://ludumdare.com/ From p-abel at t-online.de Fri Aug 1 15:38:42 2003 From: p-abel at t-online.de (Peter Abel) Date: 1 Aug 2003 12:38:42 -0700 Subject: list indexing References: Message-ID: <13a533e8.0308011138.656ea25e@posting.google.com> "Sean Ross" wrote in message news:... > "Matthew" wrote in message > news:ec1162c7.0307311153.26d1b999 at posting.google.com... > > Hello, I am rather new to python and I have come across a problem that > > I can not find an answer to any where I my books. What I would like to > > know is if there is a way to get the index number of a list element by > > name. Sort of the inverse of the .index() method. > > Perhaps I've misunderstood, but it looks like you want: > >>> words = ['this', 'is', 'a', 'list'] > >>> words.index('list') > 3 > > which is, of course, not the inverse of .index() (but .index() itself). > > In general, if you use this, you'll either need to be certain that the item > is indeed in the list, or nest the call in a try/except like so: > >>> try: > ... index = words.index('list') > ... except ValueError: > ... pass # or whatever you want to do when the look-up fails > ... > >>> index > 3 > > HTH > Sean And if 'list' would appear more than once, the following could help: >>> words = ['this', 'is', 'a', 'list','and','this','is','a','list','too'] >>> for i in range(len(words)): ... if words[i]=='list': ... print i ... 3 8 Regards, Peter From daniel at dittmar.net Fri Aug 1 18:14:51 2003 From: daniel at dittmar.net (Daniel Dittmar) Date: Sat, 02 Aug 2003 00:14:51 +0200 Subject: String Replacement In-Reply-To: <7b454334.0308011400.266438f9@posting.google.com> References: <7b454334.0308011400.266438f9@posting.google.com> Message-ID: Fazer wrote: > import string > string.replace(DataFromDatabase, "\n", "
") > > Unfortunately, it doesn't work. You'll probably want import sys import string sys.out.write (string.replace(DataFromDatabase, "\n", "
")) or for Python 2.x import sys sys.out.write (DataFromDatabase.replace ("\n", "
")) Seeing the result of an expression without print works only at the interactivew prompt: >>> string.replace ("abc\nde", '\n', '
') 'abc
de' >>> print string.replace ("abc\nde", '\n', '
') abc
de Daniel From adalke at mindspring.com Wed Aug 6 21:06:04 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Wed, 6 Aug 2003 19:06:04 -0600 Subject: catching exceptions in expressions References: Message-ID: Vaclav Dvorak: > try: c = int(u) > except ValueError: c = 99 > > Not enough to make me want to create a function, but enough to be > annoying. :-) I was thinking about something like this: > > a = int(s) except ValueError then 99 No. In general, Python encourages new functions or classes over new syntax. What's wrong with def safe_int(s, default): try: return int(s) except ValueError: return default or for something more generic class TryCatcher: def __init__(self, function, default, exceptions = (ValueError,)): self.function = function self.default = default self.exceptions = exceptions def __call__(self, *args, **kwargs): try: return self.function(*args, **kwargs) except self.exceptions: return self.default safe_int = TryCatcher(int, 99) safe_int("a") > a = int(s) or 99 if ValueError Parse ambiguity. a = int(s) or 99 is valid Python today. > a, b, c = 99, 99, 99 > try: > a = int(s) > b = int(t) > c = int(u) > except ValueError: > continue [execution on next line - my comment] 'continue' already has meaning in current Pythons. > Comments? Should I write a PEP? Am I missing something obvious? Has this > been debated a million times over already? Feel free to write a PEP. It won't be accepted. Andrew dalke at dalkescientific.com From afriere at yahoo.co.uk Mon Aug 18 00:50:57 2003 From: afriere at yahoo.co.uk (Asun Friere) Date: 17 Aug 2003 21:50:57 -0700 Subject: ``Type-checking'' with dir() References: <70df36e9.0308161136.3c414a80@posting.google.com> Message-ID: <38ec68a6.0308172050.20f68ea4@posting.google.com> harry.pehkonen at hotpop.com (Harry Pehkonen) wrote in message news:<70df36e9.0308161136.3c414a80 at posting.google.com>... > In order to leave my classes open to receiving objects that are > string-like, list-like, dictionary-like, etc, and not necessarily > _exactly_ the built-in string, list, dictionary, etc types, I have the > desire to just check if the necessary methods exist. Why do you have this desire? If your program is usually going to be passed lists etc, isn't that a lot of expensive LBYL checking to have to go through? Is there some reason that simply handling the Type or Attribute (or Whatever) errors won't suffice? From ckrieg at shaw.ca Wed Aug 20 13:33:16 2003 From: ckrieg at shaw.ca (ckrieg at shaw.ca) Date: Wed, 20 Aug 2003 17:33:16 GMT Subject: Newbie Variable Substitution Question Message-ID: Just a quick question. Consider this: dict01 = { '1': 'a', '2': 'b' } for c in range(1, 3): print "%(c)s" % locals(), "%(1)s" % dict01 Returns: 1 a 2 a But, using this loop instead: for c in range(1, 3): print "%(c)s %(1)s" % (locals(), dict01) Results in an error: TypeError: format requires a mapping Why doesn't the second loop work? It seems to be a cleaner way of doing this. Am I missing something? From duncan at NOSPAMrcp.co.uk Mon Aug 18 09:01:53 2003 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Mon, 18 Aug 2003 13:01:53 +0000 (UTC) Subject: Functions References: Message-ID: Thor wrote in news:bhqhm1$1vcq3$1 at ID-108351.news.uni-berlin.de: > In this hypothetical case: > > def f1: > f3: > def f2: > def f3: > pass > f1: > def f4: > def f3: > pass > f1: > > would the function f1 execute the right f3 depending on from which > functions is it called? Why don't you load up the interactive interpreter and try running it? You'll find a lot of mistakes in the hypothetical code you entered, including the absence of argument lists after the function names, and the spurious colons and lack of parenthese on the function calls. I'll assume you actually meant something like: def f1(): f3() def f2(): def f3(): pass f1() def f4(): def f3(): pass f1() If the code above is indeed what you intended then calling either f2() or f4() will result in a 'NameError' exception because there is no name 'f3' in scope from inside f1(). There are local variables 'f3' inside both f2() and f4(), but local variables are never visible nor accessible from outside the functions in which they are defined. (They are visible from inside nested functions, but that is not the situation here.) To get code something like this to work, you should pass f3 as a parameter to f1: def f1(f3): f3() def f2(): def f3(): pass f1(f3) def f4(): def f3(): pass f1(f3) Remember, Python functions are just objects like any other and may be assigned to variables or passed in and out of other functions. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From exarkun at intarweb.us Fri Aug 15 11:55:21 2003 From: exarkun at intarweb.us (Jp Calderone) Date: Fri, 15 Aug 2003 11:55:21 -0400 Subject: debug python like set -x In-Reply-To: <15fe3ffc.0308150713.10c30841@posting.google.com> References: <15fe3ffc.0308150713.10c30841@posting.google.com> Message-ID: <20030815155521.GA8482@intarweb.us> On Fri, Aug 15, 2003 at 08:13:01AM -0700, Dave wrote: > Hi, > Newbie here. Is there a way to have output from a python program go > to the screen the way it does if I use "set -x" in a shell script? > Python2.3's trace.py (also in Tools/ in 2.2) has some interesting functionality along these lines. Jp -- "Minerals are inexhaustible and will never be depleted. A stream of investment creates additions to proved reserves, a very large in-ground inventory, constantly renewed as it is extracted... How much was in the ground at the start and how much will be left at the end are unknown and irrelevant." -- Morry Adelman, World Renowned Economist From tim.one at comcast.net Sun Aug 3 13:20:03 2003 From: tim.one at comcast.net (Tim Peters) Date: Sun, 3 Aug 2003 13:20:03 -0400 Subject: time, calendar, datetime, etc In-Reply-To: Message-ID: [Tim, explains that the datetime module's date ordinals were deliberately defined to be identical to those used in > Dershowitz and Reingold's highly regarded "Calendrical Calculations": > > http://emr.cs.iit.edu/home/reingold/calendar-book/second-edition/ ] [Dennis Lee Bieber] > Pity the book uses LISP (at least, the first edition did)... > Even BASIC would be more accessible to most folks (though I would > prefer a modern BASIC over G-whiz or older). I'd prefer Python, myself. It would be a fun (for a date weenie ) project to recode these algorithms Pythonically. I hope someone does. From achrist at easystreet.com Sun Aug 31 03:18:47 2003 From: achrist at easystreet.com (achrist at easystreet.com) Date: Sun, 31 Aug 2003 00:18:47 -0700 Subject: Temp File Cleanup for McMillan Installer Pgms Message-ID: <3F51A157.327C006D@easystreet.com> After using the McMillan installer and executables built with it for a while, I've noticed some residual files accumulating on my disk. The installer docs mentions these. Here's code I wrote to clean these up: --------------------Program Fillows---------------------- import fnmatch import os import os.path import stat import tempfile import time currentTime = time.time() def PathIsOld(pathName): accessTime = os.stat(pathName)[stat.ST_ATIME] createTime = os.stat(pathName)[stat.ST_CTIME] modifiedTime = os.stat(pathName)[stat.ST_MTIME] return (((currentTime - accessTime) > 5000) or ( (currentTime - createTime) > 50000)) and ( (currentTime - modifiedTime) > 5000) def GetMEISubdirectories(aDir): for fName in os.listdir(aDir): if fnmatch.fnmatch(fName, "*"): if fName.lower()[:4] == '_mei': fullName = os.path.join(aDir, fName) fMode = os.stat(fullName)[stat.ST_MODE] if stat.S_ISDIR(fMode): yield fullName def GetMEIFiles(aDir): for fName in os.listdir(aDir): if fName.lower()[:4] == '_mei': fullName = os.path.join(aDir, fName) fMode = os.stat(fullName)[stat.ST_MODE] if stat.S_ISREG(fMode): yield fullName def GetTempLocation(): return tempfile.gettempdir() def GetMEIDirectories(): return filter( PathIsOld, GetMEISubdirectories(GetTempLocation()) ) def DeleteMEIDirectory(d): for fileName in os.listdir(d): fullName = os.path.join(d, fileName) try: os.remove(fullName) except: pass try: os.rmdir(d) except: pass for d in GetMEIDirectories(): DeleteMEIDirectory(d) for f in GetMEIFiles(GetTempLocation()): if PathIsOld(f): os.remove(f) -----------------------End of Program ------------------------- What are the top 10 reasons for not including this in every program that I turn into an executable with the McMillan installer? TIA Al From t_therkelsen at hotmail.com Tue Aug 12 04:56:34 2003 From: t_therkelsen at hotmail.com (Troels Therkelsen) Date: 12 Aug 2003 08:56:34 GMT Subject: Py2.3: Feedback on Sets References: Message-ID: In article , Raymond Hettinger wrote: > I've gotten lots of feedback on the itertools module > but have not heard a peep about the new sets module. I would have to say that while I have looked at the sets module and read its documentation, I have not used it much (more below). > * Are you overjoyed/outraged by the choice of | and & > as set operators (instead of + and *)? I actually prefer the | & syntax because it makes more intuitive sense to me, as the operators work identically to how they do when using them as binary number operators. [snip] > * Do you care that sets can only contain hashable elements? No. [snip] > * Are the docs clear? Can you suggest improvements? The docs for the sets module, like most of the Python docs, are very good. The example helps, too. > * Are sets helpful in your daily work or does the need arise > only rarely? I rarely need sets explicitly, but sometimes need the logic that they offer. For example, when wanting to concantenate two lists so that the resulting list only has unique elements, that can be done with set logic. However, as it is another module written in Python, and I only need the logic I usually don't go through with the overhead of creating the Set classes, etc. If it was better integrated (ie., a set() builtin type constructor like int(), str(), etc) then I would feel less of a reservation against using sets. I know this reservation isn't founded in facts, but more in the feeling of trusting builtin types more than custom classes provided by a module. > User feedback is essential to determining the future direction > of sets (whether it will be implemented in C, change API, > and/or be given supporting language syntax). Don't know if my feedback provided above helps, but you asked for it ;-) Regards, Troels Therkelsen From tgerla at outsourcefinancial.com Wed Aug 6 19:07:43 2003 From: tgerla at outsourcefinancial.com (Tim Gerla) Date: 06 Aug 2003 16:07:43 -0700 Subject: Python and Robotics? In-Reply-To: <3f2e0061$0$4189$afc38c87@news.optusnet.com.au> References: <3f2d1e1d$0$4192$afc38c87@news.optusnet.com.au> <3F2D58AF.9000705@norfolkgraphics.com> <3f2e0061$0$4189$afc38c87@news.optusnet.com.au> Message-ID: <1060211263.5029.3.camel@redwall.ofsloans.com> > > > >> Hello All, > >> Hope everyone is well. > >> I am really new to python, so my question maybe some what stupid to > >> some. The question is, can python be used as a programming language > >> for robotics? eg, controling motors and sensors? > >> If so, do you know any website that would contain such information ? > >> > >> Many thanks > >> Darren > >> > > Hi Darren, I built a robotic mixed-drink dispenser using Python and PyGtk, controlling a set of windshield-washer pumps connected to my parallel port. Right now I have pictures but no details: http://math.umcrookston.edu/~gerla/pictures/barbotics/ I used the ioport module available here: http://www.hare.demon.co.uk/ioport/ioport.html If you'd like more information, drop me an email. -Tim -- From max at alcyone.com Wed Aug 13 00:03:47 2003 From: max at alcyone.com (Erik Max Francis) Date: Tue, 12 Aug 2003 21:03:47 -0700 Subject: Python vs. C# References: <2259b0e2.0308100616.55b651ca@posting.google.com> <3f36af20@shknews01> <3f3959e3_1@news.vo.lu> Message-ID: <3F39B8A3.68B9D623@alcyone.com> Tom wrote: > Sorry to be harsh, Mr. Van Avery. Thing is, I doubt that Van Every is consciously trolling. He's just behaving like he always behaves. It shouldn't be any surprise that he has had similar exchanges in practically every newsgroup he's ever visited. Though I don't think he's consciously trolling, it seems that practically no one who encounters him randomly on Usenet doesn't conclude that he's _not_ trolling. That this drama has repeated itself over and over again on Usenet everytime he pokes his head into a new newsgroup should at the very least have raised a red flag in his mind by now. But it hasn't. I wonder why. However, although I don't think that he would honestly considering himself trolling, it hardly matters much. If most people you encounter think that you're trolling, your protests to the contrary won't convince them otherwise, and shouldn't. If it looks like a duck and quacks like a duck, it starts not to matter if it's really a goose. > I have a suggestion, though. I > think you've chosen the wrong group to play in. I think you should > read a book about Lisp (maybe even two) and then share your thoughts > with the comp.lang.lisp folks. Lisp is a really neat language (not > sure but maybe there's a Lisp.NET to explore!!!) and the c.l.l. folks > will be really interested in your insights. I think you and Erik will > hit it off big time. He's probably going to think you're talking about me, rather than Erik Naggum :-). -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ He who conceals his disease cannot expect to be cured. \__/ (an Ethiopian proverb) From pydrew01 at interstice.com Fri Aug 8 15:46:26 2003 From: pydrew01 at interstice.com (Rich Drewes) Date: Fri, 08 Aug 2003 12:46:26 -0700 Subject: execute command in CURRENT shell In-Reply-To: References: Message-ID: <3F33FE12.2010101@interstice.com> Rob Williscroft wrote: >Valentine Kouznetsov wrote in news:ec6d1a16.0308080828.367f6b54 >@posting.google.com: > > > >>Hi, >>simple question, how to execute command in current shell, not in >>subshell? >> execl() will execute a new program in the current process, replacing the current process. It obviously cannot return back to Python. See http://www.python.org/doc/2.2/lib/os-process.html . spawnl() will execute a new program in a new process, but it does not invoke a new *shell*. It allows you to completely specify the environment, so this may also do what you want. Unlike execl() you can return to Python after the subprocess is complete. Rich From bitbucket at safe-mail.net Wed Aug 27 08:05:53 2003 From: bitbucket at safe-mail.net (poiboy) Date: 27 Aug 2003 05:05:53 -0700 Subject: Preferred standalone TAL module? References: <5d855b4b.0308251419.31e894e6@posting.google.com> Message-ID: speakstofish at hotmail.com (Fahd Khan) wrote: > I'm also motivated by the web programming thread's underlying message > of seeking "industrial strength" solutions that work in many domains > using existing tools, so that I spend more time coding and less time > "shopping" for modules. TAL seems a good way to do that (I'm most > certainly not ready to take the plunge into Zope). Any comments there? My TAL-fu seasoning consists of a whopping two websites, the first done in Zope (ZPT) and the second with mod_python (SimpleTAL). But with little reservation, I don't plan on looking much further than TAL in the near future: * Plain HTML is editor highlighting- and indenting-friendly. * Both the logic and presentation code is concise. Ex: Lists are rendered with a single "embedded" tal:repeat='item list' attribute. (I'd like to see how thin I can make code that glues database-enforced values to a TAL page.) * Eliminating HTML<->template translation overhead speeds up everything considerably. * TAL works with Zope & Python (all 31 flavors), PHP, and Java - though this is more for the PHP and Java crowd since I can't imagine a Python slithering backward. Counterpoint? In an attempt to sound objective, here's one: debugging *may be* a pain. However, in practice it seems that the easier a templating system is to debug, the less it looks like a (um,) template. TAL at least encourages an implicit "print" based solution - with a template full of dummy text and images, it's rather obvious where errors in logic are occurring (with the obligatory edit, save, refresh). Meanwhile, finding an error in template processing is as hard as tracking down the missing '}' in any other language. Things I woke up to on this last project: comp.lang.python threads dealing with web programming are often filled with tips like "just do it yourself" or "it's somewhere in Webware or Twisted" - all of which sound(ed) pretty vacuous to a PHP person (moi) looking for session_start() or $_GET equivalents. Turns out that it was easier to dismiss those tips than to put real thought into what "doing it myself" really meant. Looking up from the relatively low-level mod_python, I don't see any difficulty now in quitting PHP cold turkey (excepting webhost variety). And by confining mod_python-specific code to a couple of files, it'll be easy to port the bulk of this or any future website to Webware (when growth warrants the investment in education) or Twisted (when faced with the inevitable transition from website to real-time multiplayer extravaganza). Best to you, the poiboy From dave_at_thuswise_dot_co_dot_uk Wed Aug 27 14:58:45 2003 From: dave_at_thuswise_dot_co_dot_uk (Dave Haynes) Date: Wed, 27 Aug 2003 19:58:45 +0100 Subject: Python PostgreSQL frontend for Win2K with MinGW32 ? Message-ID: <3f4cfee5_2@mk-nntp-1.news.uk.worldonline.com> Hi, This is just as much a PostgreSQL question as a Python one, but here goes... I've been trying to port the psycopg interface to a Win2K client (server runs FreeBSD). I'm using MinGW32 rather than CygWin, and having trouble compiling the libpg library as a DLL. I started off with the following: configure --with-template=win --without-zlib make -C src/interfaces install After complaints that I was missing "Makefile.port" I took a copy from Makefile.win. My Win2K/MSYS/MinGW32 setup doesn't have netinet/in.h, ioctl.h, inet.h, or arpa.h, so I removed the #includes to these header files in pg_config.h. I sort of assumed that none of these would be needed, and I would end up linking to the Windows socket library instead of all the Unix stuff. Massive overoptimism replaced by confusion and gloom. The dlltool can't find a lot of the socket call targets, fe-connect.c and fe-misc.c being the main offenders. Can anyone help, please? I know there are some psycopg enthusiasts about; I'd be very grateful for some pointers. I'd rather use MinGW32 than CygWin; I could swap but my understanding was that MinGW has all that's required. Alternatively, are there any VC++ Studio binaries available? Not that I approve of course ;-) Cheers, Dave From jacek.generowicz at cern.ch Thu Aug 21 10:43:35 2003 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 21 Aug 2003 16:43:35 +0200 Subject: C++-sig problems ? References: Message-ID: Wolfgang writes: > > Has anyone else experienced problems in submitting articles to the > > C++-sig? > > Yes, I subscribed to C++ sig today, but until now received no > confirmation message. > > > I've tried both via Gmane, and directly via mail, without success. > > I read it on Gmame but since 19.08 there are no new messages. > I think the main mailing list server is down or something > is broken. (not with gmame, other mailinglist run without problems) A couple of people have privately replied to me that the likely cause of this is something called "sobig.f", which seems to be heavily disrupting things all over the place. I assume that this is one of the spate of "clients" of Microsoft Virus Gateway, which have become active recently. Being completely detached from the MS world, I have remained, mostly, blissfully unaware of these things. From cben at techunix.technion.ac.il Tue Aug 19 14:41:46 2003 From: cben at techunix.technion.ac.il (Beni Cherniavsky) Date: Tue, 19 Aug 2003 18:41:46 +0000 (UTC) Subject: Why doesn't __call__ lead to infinite recursion? References: <2a82921f.0308151158.b8c9154@posting.google.com> <87ekzldf3d.fsf@pobox.com> Message-ID: In article <87ekzldf3d.fsf at pobox.com>, John J. Lee wrote: >aahz at pythoncraft.com (Aahz) writes: >[...] >> you'll see __call__ there. When you do foo(), Python actually does >> type(foo).__call__(foo). Because type(foo).__call__ is manipulating >> foo, you don't get the circular reference. > >Still seems weird that type(foo).__call__.__call__ (etc.) is defined. > [I'm afraid I sent this 2 or 3 already in private by mistake; resending in public. I apologize, it's late...] The point is that down there, sits the C level which doesn't go through the Python definition. When you call ``foo()``, ``type(foo)`` is asked at the *C* level how to call it (read: the type struct is accessed and the call-behavior slot, if non-NULL, is called by plain C function call - which can't be intercepted in C so there is no futher recursion). It so happens that classes, when asked this, go back into the Python level and look for the `__call__` attribute. They do this for all operations, giving you the dynamism and flexibility we all love. OTOH, functions, when asked this, simply execute their code objects with the given arguments. The attribute `__call__` on function is a "proxy" attribute. It is not used by function objects for the call, it only exposes the C-level call machinery at Python level. The same convention is used for other built-in types and operations, so that from Python you see Python-level and C-level methods in the same way. You only have to be aware of the distinction when working with bizzare extension types that don't respect this convention, or asking questions like this one about how it all works... (Another one: why __getattribute__ is not infinitely recusive? Same explanation.) -- Beni Cherniavsky Look, Mom, no viruses! [Hint: I use GNU/Linux] From adalke at mindspring.com Thu Aug 7 15:58:02 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Thu, 7 Aug 2003 13:58:02 -0600 Subject: random changes References: Message-ID: dan: > next time the core RNG is changed, I think it would be useful to have > an -oldrandom switch. [...] In bumping to 2.3 with the new Mersenne > algorithm, I have no easy way of duplicating my old results. Isn't the random.WichmannHill implement the old code? If so, what about the following untested code? import random random = random.WichmannHill() random.seed(5) print random.random() Failing that, what about copying the old Python code as "oldrandom.py" then doing import oldrandom as random Andrew dalke at dalkescientific.com From shalehperry at comcast.net Sun Aug 10 23:43:10 2003 From: shalehperry at comcast.net (Sean 'Shaleh' Perry) Date: Sun, 10 Aug 2003 20:43:10 -0700 Subject: python spam filter: random words? In-Reply-To: <1ED4ECF91CDED24C8D012BCF2B034F130212AC4D@its-xchg4.massey.ac.nz> References: <1ED4ECF91CDED24C8D012BCF2B034F130212AC4D@its-xchg4.massey.ac.nz> Message-ID: <200308102043.10875.shalehperry@comcast.net> On Sunday 10 August 2003 18:34, Tony Meyer wrote: > > > I am also wondering why spammers add that > > stuff to their subject lines anyway. > > To fool simple checksum type filters, probably. > that is part of it. The other purpose is to add a unique identifier to a batch of spam. "ah, the asjfg batch did well, we will use that list again". From achalk at XXXmagnacartasoftware.com Thu Aug 28 12:14:49 2003 From: achalk at XXXmagnacartasoftware.com (Andrew Chalk) Date: Thu, 28 Aug 2003 16:14:49 GMT Subject: Running a Python script when a page is loaded Message-ID: I am developing a CGI app, When the user loads my page I want to populate an HTML 'select' box (drop down menu) with items from a database. What is the best way to get my Python procedure that does this called when the page is loaded? Many thanks From jorolat at msn.com Fri Aug 1 13:22:04 2003 From: jorolat at msn.com (John Latter) Date: Fri, 01 Aug 2003 18:22:04 +0100 Subject: Problem with Unzipping/Installing Python-2.3.exe References: Message-ID: <7b8liv0dqa45pcj5mdrb2205vqolkvp6b6@4ax.com> Sorry Bob - I must be half asleep! Ordinarily I'm not given the option to unzip a file that isn't zipped, whatever it was I clicked on the exe and its now installed. Thanks for waking me up! -- John Latter Model of an Internal Evolutionary Mechanism (based on an extension to homeostasis) linking Stationary-Phase Mutations to the Baldwin Effect. http://members.aol.com/jorolat/TEM.html 'Where Darwin meets Lamarck?' Discussion Egroup http://groups.yahoo.com/group/evomech From shlomme at gmx.net Mon Aug 11 09:09:17 2003 From: shlomme at gmx.net (Torsten Marek) Date: Mon, 11 Aug 2003 15:09:17 +0200 Subject: Fun with numbers - dammit, but I want a cast! In-Reply-To: <3f378fac$0$10778$afc38c87@auth.uk.news.easynet.net> References: <3f378fac$0$10778$afc38c87@auth.uk.news.easynet.net> Message-ID: Graham Nicholls schrieb: > Hi. > > I'm having some fun with numbers. I've extraced an image sizes from a jpeg > file > > img_x,img_y=image.getsize() > > then I'm trying to use those sizes to scale the image, but because python > has decided that they are integers, I keep getting division by zero errors > > eg > xscale=xframe/img_x > > where xframe will be say 300, and img_x will be 1800 > xscale has the value 0. > > I've tried doing img_x=1.0 to force it to be a float, but I'm getting a bit > frustrated as it seems to make no difference - once image.getsize returns > the (integer) value of the x size, it simply converts back to an int. I've > tried this at the command line, and it seems to confirm that behaviour - > eg: > graham at rocklap:~/work/hsb/pdflive> python > Python 2.3b1 (#3, Jun 17 2003, 23:06:11) > [GCC 3.3 20030226 (prerelease) (SuSE Linux)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>>>x=1.0 >>>>xf=1.0 >>>>scale=1.0 >>>>x=1800 >>>>xf=300 >>>>scale=xf/x >>>>scale > > 0 > > > > > > Heres the relevant code in full: > > img_x=1.0 > img_y=1.0 > img_x,img_y=image.getsize() > except "Not_JPEG": > if warn: > print ("WARNING: Image file %s is not a jpeg file" % fname) > sys.exit(OPEN_ERR) > # How many pixels per mm do we have > # On a4 paper, using pdfrw ? Docs seem to suggest between 60-160 > # which seems a lot. > > xscale=1.0 > yscale=1.0 > scale=1.0 > xscale=1/(xframe/img_x) > yscale=1/(yframe/img_y) > #import pdb > #pdb.set_trace() > print ("xscale=%f,yscale=%f" %(xscale,yscale)) > scale=min(xscale,yscale) * 100 > print ("xframe=%d,yframe=%d, x=%d,y=%d scale=%f\n" %(xframe, yframe, > img_x, img_y, scale)) > > I'd really appreciate some help, thanks! > Graham The type of a variable does not depend on the type it was initialized with. You could do t = 1 t = 1.1 t = "1" t = [1,] and the type changes each time. There is no concept of "int xscale" what you might have in mind. You just should convert the integer into a float with xscale=1/(xframe/float(img_x)). greetings Torsten From davecook at nowhere.net Wed Aug 6 11:17:15 2003 From: davecook at nowhere.net (David M. Cook) Date: Wed, 06 Aug 2003 15:17:15 GMT Subject: Is there some Python + IDE/RAD for real speed development??? References: <96fda9ac.0308060611.56dfca7e@posting.google.com> Message-ID: <%Z8Ya.146152$R92.19892@news2.central.cox.net> In article <96fda9ac.0308060611.56dfca7e at posting.google.com>, Edilmar wrote: > I look at wxPython and PyGTK, but the samples showed that we have to write > MANY LINES of code to do simple things. Many people have wrote about the > advantage of Python to write little code, but, when talking about GUIs, > I think it's not really true, right? The samples are probably showing how to do things "by hand", and aren't taking advantage of the available tools. That's appropriate for an honest sample. Have you tried glade and libglade? Glade does have limitations and annoyances, but I find this a pretty powerful combination. I don't know much about wxpython, but you should probably check out boa-constructor. BTW, PyGTK is essentially just a toolkit, not an application framework, so it is missing some things that people expect from an app framework. gnome-python does have more, but at the cost of considerably more dependencies. There's also PyQT and qtdesigner. Dave Cook From FBatista at uniFON.com.ar Fri Aug 15 17:23:51 2003 From: FBatista at uniFON.com.ar (Batista, Facundo) Date: Fri, 15 Aug 2003 18:23:51 -0300 Subject: Replace every n instances of a string Message-ID: #- this provide better performance? If so, what would be the #- easiest way #- to do that? Check the *very* powerful module re. http://www.python.org/doc/current/lib/module-re.html . Facundo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ADVERTENCIA La informaci?n contenida en este mensaje y cualquier archivo anexo al mismo, son para uso exclusivo del destinatario y pueden contener informaci?n confidencial o propietaria, cuya divulgaci?n es sancionada por la ley. Si Ud. No es uno de los destinatarios consignados o la persona responsable de hacer llegar este mensaje a los destinatarios consignados, no est? autorizado a divulgar, copiar, distribuir o retener informaci?n (o parte de ella) contenida en este mensaje. Por favor notif?quenos respondiendo al remitente, borre el mensaje original y borre las copias (impresas o grabadas en cualquier medio magn?tico) que pueda haber realizado del mismo. Todas las opiniones contenidas en este mail son propias del autor del mensaje y no necesariamente coinciden con las de Telef?nica Comunicaciones Personales S.A. o alguna empresa asociada. Los mensajes electr?nicos pueden ser alterados, motivo por el cual Telef?nica Comunicaciones Personales S.A. no aceptar? ninguna obligaci?n cualquiera sea el resultante de este mensaje. Muchas Gracias. -------------- next part -------------- An HTML attachment was scrubbed... URL: From http Fri Aug 1 22:33:59 2003 From: http (Paul Rubin) Date: 01 Aug 2003 19:33:59 -0700 Subject: OT: Re: Voting Project Needs Python People References: <7x65lv31hf.fsf@ruckus.brouhaha.com> <3jhTa.115229$Io.9825106@newsread2.prod.itd.earthlink.net> Message-ID: <7xllucrdns.fsf@ruckus.brouhaha.com> "Andrew Dalke" writes: > At present there are 50 people who paid the non-refundable fee > for running for the California governship. The article I just read > said the standard ballot used could handle up to 300 entires. Yikes. The weirdest thing about that election is that it's likely to give the governorship to whoever finishes in SECOND place (if you count "no recall" as a vote for the incumbent governor). Btw, Defcon is this weekend (or pretty soon) and I want to float the idea of "black hat voting" (to go with "black box voting"). Black hat voting works like this: 1) Announce that Defcon members will elect this year's Evil Overlord of the Black Hat Universe 2) Further announce that the votes will be counted with Diebold machines. (Of course the organizers would have to get those from somewhere) 3) See what happens. In this election, whoever does the best job of cheating -deserves- to win. It would be interesting to see how the Python-based voting machines do in a situation like that. From bmunroe at tribador.nu Wed Aug 27 19:43:03 2003 From: bmunroe at tribador.nu (Brian Munroe) Date: 27 Aug 2003 16:43:03 -0700 Subject: Class level variables in Python Message-ID: I am just starting to learn the OO side of Python scripting, and I am a little confused on the following. Take the following example class: >>> class rectangle(object): z = 1 def __init__(self): self.x = 2 >>> r = rectangle() >>> print r.z 1 >>> print r.x 2 >>> r.z = 16 >>> print r.z 16 >>> r.x = 17 >>> print r.x 17 >>> I was wondering if someone could explain if there is any difference between initalizing your object attributes up in the __init__ constructor or setting them up as (I am guessing at the name here) object level variables (like z) thanks -- brian From gh at ghaering.de Wed Aug 27 02:40:34 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Wed, 27 Aug 2003 08:40:34 +0200 Subject: pure Python DB In-Reply-To: <9a6d7d9d.0308261756.5b37cbf4@posting.google.com> References: <9a6d7d9d.0308261756.5b37cbf4@posting.google.com> Message-ID: <3F4C5262.4050807@ghaering.de> Aaron Watters wrote: > Andy Todd wrote in message news:... >>Patrick Useldinger wrote:> >>Gadfly is lightweight but doesn't support transactions. It is in low >>maintenance mode, development is currently not active but the project is >>hosted at SourceForge (http://sourceforge.net/projects/gadfly) and any >>bug reports and (especially) patches would be more than welcome. > > Um.. doesn't support transactions? It depends what you mean, > I guess. It supports transaction commit and rollback and recovery > but not transaction concurrency... (yet) Neither does SQLite. Only one transaction can be active at any time. Another transaction will block at BEGIN. If you need that I'd suggest you switch to a client-server database like PostgreSQL. -- Gerhard From tienhuyen at hotmail.com Tue Aug 26 20:22:10 2003 From: tienhuyen at hotmail.com (Tien Nguyen) Date: 26 Aug 2003 17:22:10 -0700 Subject: Problem with mxDateTime on HPUX 11.11 machine ! Message-ID: Hi There, I installed python2.3 (configured with option --with-libs='lpthread -lcl'), and egenix-mx-base-2.0.5 on an HPUX B.11.11 machine. Everything seems to be OK. I can start python and import mx modules successfully. tnguyen at local_host:/users/denver/tnguyen 71 % python Python 2.3 (#1, Aug 26 2003, 16:06:40) [GCC 3.1] on hp-ux11 Type "help", "copyright", "credits" or "license" for more information. >>> from mxDateTime import * >>> from mxDateTime import __version__ >>> from DateTime import * >>> from DateTime import __version__ >>> The problem was that, in my c program, I call the python API: PyObject* call_module = PyImport_ImportModule("module_name"); call_module always NULL and I got the following error on screen: *** You don't have the (right) mxDateTime binaries installed ! I think this message comes from: python_home/lib/python2.3/site-packages/mx/DateTime/mxDateTime/__init__.py ---------------------------------------------------------- """ mxDateTime - Date and time handling routines and types Copyright (c) 2000, Marc-Andre Lemburg; mailto:mal at lemburg.com Copyright (c) 2000-2001, eGenix.com Software GmbH; mailto:info at egenix.com See the documentation for further information on copyrights, or contact the author. All Rights Reserved. """ try: from mxDateTime import * from mxDateTime import __version__ except ImportError, why: print "*** You don't have the (right) mxDateTime binaries installed !" raise ImportError, why #from mxDateTime_Python import * #from mxDateTime_Python import __version__ # Python part of the intialization try: import time setnowapi(time.time) del time except NameError: pass -------------------------------------------- I don't know why it always raise exception like that!? Can any python expert or mxBase expert help me with this? Thank you very much. Tien Nguyen From mack at incise.org Wed Aug 20 12:55:39 2003 From: mack at incise.org (mackstann) Date: Wed, 20 Aug 2003 11:55:39 -0500 Subject: python quickie : retrace function steps? In-Reply-To: <5f5c82ec.0308200820.51c8e33c@posting.google.com> References: <5f5c82ec.0308200820.51c8e33c@posting.google.com> Message-ID: <20030820165539.GD1695@incise.org> On Wed, Aug 20, 2003 at 09:20:29AM -0700, Matt Smith wrote: > If I was to make a function call another function, and from that > function, call another function (so that now I was in a 3rd function) > something like this: > > (function 1) > |________(function 2) > |________(function 3) > > Is there away I can print out the path my Program had taken (i want to > do this as part of my error checking, so a user would always know the > path my program took)? I came up with this a while back and kinda forgot about it until this post: tb = traceback.extract_stack() print ((len(tb)-2)*" " + tb[-2][2]) This indents each function call by two spaces, and when functions call each other, they nest deeper and deeper. E.g.: --------------------------- import traceback def debug(): tb = traceback.extract_stack() print ((len(tb)-2)*" " + tb[-2][2]) def f1(): debug(); f2() def f2(): debug(); print "five plus five is", 5+5 def f3(): debug(); f1() def f4(): debug(); f3() if __name__ == "__main__": f4() --------------------------- % python tmp.py f4 f3 f1 f2 five plus five is 10 --------------------------- > i.e. printted output of error would be: > > error with function 3 > function 3 called from function 2 > function 2 called from function 1 > > In perl there is a function called CALLER, which I have used to the > same effect, i was wondering if python had something similar for this? If I change the comma in the print statement above to a +, I get: File "tmp.py", line 13, in ? f4() File "tmp.py", line 10, in f4 def f4(): debug(); f3() File "tmp.py", line 9, in f3 def f3(): debug(); f1() File "tmp.py", line 7, in f1 def f1(): debug(); f2() File "tmp.py", line 8, in f2 def f2(): debug(); print "five plus five is" + 5+5 TypeError: cannot concatenate 'str' and 'int' objects Do you want something different from that? If so, different in what way? -- m a c k s t a n n mack @ incise.org http://incise.org Absent, adj.: Exposed to the attacks of friends and acquaintances; defamed; slandered. From john at rygannon.com Sun Aug 10 12:34:48 2003 From: john at rygannon.com (john at rygannon.com) Date: Sun, 10 Aug 2003 17:34:48 +0100 Subject: ANNOUNCE: Rekall V2.0.2 References: <5.2.1.1.0.20030810065523.02c3ed10@66.28.54.253> Message-ID: <003201c35f5d$514d8d20$0501a8c0@sun.thekompany.co.uk> Hi ----- Original Message ----- From: "Bob Gailer" To: ; Sent: Sunday, August 10, 2003 1:59 PM Subject: Re: ANNOUNCE: Rekall V2.0.2 > At 11:01 PM 8/9/2003 +0100, john at rygannon.com wrote: > > >Hi > >I would like to take this opportunity to announce the release of Rekall for > >Windows and Linux. > >Rekall is an attempt to produce an application to rival Microsoft Access, > >without the huge price tag. With Rekall you can produce full blown > >applications. Rekall's programmability and power comes through the use of > >Python. There is also a Run Time version of Rekall which allows you ship > >your Rekall application to your customers. Rekall includes a syntax > >highlighting editor and a debugger. You can import and export data and table > >structures to and from all the databases supported by Rekall. Included in > >the standard package are drivers for MySQL, xBase and PostreSQL. You can get > >drivers for DB2, ODBC and Oracles separately from us at a fraction of the > >cost of buying from the big vendors. > >Why not take a Rekall Demo out for a test drive. Our demos are fully > >functional with a 60 minute time limitation (the Windows demo has a 15 day > >time limit), but they will run again. You can find the demos on either of > >two web sites, http://www.rygannon.com > > I just spent more than a reasonable amount of time staring at this page. I > can't make sense of it! I don't see any helpful information that would > entice me to get the product, and no links for demos. > > >and http://www.totalrekall.co.uk > > This page makes a lot more sense. I suggest dropping the first link or > improving the page. I have made a lot of changes many of them as a direct result to everybodies suggests. I hope that I have got it right this time BTW I have add a lot of screen shots to the Contents->About Rekall->Screen Shots page > > Bob Gailer > bgailer at alum.rpi.edu > 303 442 2625 > Regards John ---------------------------------------------------------------------------- ---- > > --- > Outgoing mail is certified Virus Free. > Checked by AVG anti-virus system (http://www.grisoft.com). > Version: 6.0.506 / Virus Database: 303 - Release Date: 8/1/2003 > From a.schmolck at gmx.net Mon Aug 18 12:30:13 2003 From: a.schmolck at gmx.net (Alexander Schmolck) Date: 18 Aug 2003 17:30:13 +0100 Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> Message-ID: Alex Martelli writes: > (I do hope that Python never gets such a powerful macro system, no matter > the allure of "letting people define their own domain-specific little > languages embedded in the language itself" -- it would, IMHO, impair > Python's wonderful usefulness for application programming, by presenting an > "attractive nuisance" to the would-be tinkerer who lurks in every > programmer's heart...). I don't think a powerful but potentially dangerous feature poses much of a problem as long as there is little danger of inadvertently using it and little incentive to inappropriately use it (e.g. you could do all sorts of stupid things in python, like redefining __builtins__.len, but generally there isn't much of an incentive to do so, so many of the reasons why e.g. Java programmers might think python an unsuitable language for larger projects don't really apply in practice. My feeling is this *not* true to the same extent for ruby, where similar things are both encouraged and, if I don't misremember, can happen inadvertently). Would you still have a problem with macros in python if utilizing them required some obvious and explicit mechanism (say a 'use_custom_syntax' statement right at the beginning of a module that wants to use macros), so that their use could easily be controlled by e.g. project managers? 'as From imbosol at aerojockey.com Tue Aug 12 05:09:41 2003 From: imbosol at aerojockey.com (Carl Banks) Date: Tue, 12 Aug 2003 09:09:41 GMT Subject: Is Python your only programming language? References: Message-ID: Joe Cheng wrote: > I'm curious about something... many Artima.com members who have a Java > background and learned Python have come to the conclusion that Java and > Python are highly complimentary languages. They would never consider > filling the place Java has in their toolbox with Python, but recognize there > are many tasks where it really pays to add Python to the mix. > > I want to ask you hard-core c.l.p Pythonistas: Do you use Python for > everything? (and I'm counting Python + C extensions as just Python) Or do > you keep another language equally close at hand, and if so, what is it? And > finally, do you foresee a day when Python can be, for all practical intents > and purposes, your only programming language? For me, it's almost 100% Python + C extensions. Even the C extensions are getting dubious: for my current project, I took the time to write a C code generator in Python. I use a smattering of Bourne Shell and Mathematica for their intended purposes. I often used Fortran in research work and a few other things. I use Java when I want to make an applet (rarely). Any other language I use is either for fun, or to keep my programming skills sharp. -- CARL BANKS "You don't run Microsoft Windows. Microsoft Windows runs you." From sross at connectmail.carleton.ca Thu Aug 21 14:13:58 2003 From: sross at connectmail.carleton.ca (Sean Ross) Date: Thu, 21 Aug 2003 14:13:58 -0400 Subject: ascii2dec References: Message-ID: "Uwe Mayer" wrote in message news:bi0c3p$8qh$1 at news.rz.uni-karlsruhe.de... > Uwe Mayer wrote: > How to convert: > > length = '\x01\x00\x00\x00' > > to an integer As Peter suggested, use struct.unpack with the appropriate endianness, e.g. >>> import struct >>> length = '\x01\x00\x00\x00' >>> # convert 'length' to signed integer (big-endian) >>> unpacked = struct.unpack('>i', length)[0] # unpack returns a tuple >>> unpacked 16777216 >>> # convert 'length' to signed integer (little-endian) >>> unpacked = struct.unpack('i', length)[0] # or, fmt = '>> unpacked 1 HTH Sean From mwh at python.net Wed Aug 27 05:23:19 2003 From: mwh at python.net (Michael Hudson) Date: Wed, 27 Aug 2003 09:23:19 GMT Subject: file object, details of modes and some issues. References: <3f4b800f_3@mk-nntp-1.news.uk.worldonline.com> <7h3d6ese09m.fsf@pc150.maths.bris.ac.uk> Message-ID: <7h34r03e9t1.fsf@pc150.maths.bris.ac.uk> Jeff Epler writes: > On Tue, Aug 26, 2003 at 06:37:03PM +0000, Michael Hudson wrote: > > simon place writes: > > > > > is the code below meant to produce rubbish? > > > > Python uses C's stdio. According to the C standard: > > > > >, i had expected an exception. > > > > > > f=file('readme.txt','w') > > > f.write(' ') > > > f.read() > > > > engages in undefined behaviour (i.e. is perfectly entitled to make > > demons fly out of your nose). You can apparently trigger hair-raising > > crashes on Win98 by playing along these lines. There's not a lot that > > Python can do about this except include it's own implementation of a > > stdio-a-like, and indeed some future version of Python may do just > > this. > > If it's true that stdio doesn't guarantee an error return from fwrite() on > a file opened for reading, then the Python documentation should be > changed (it claims an exception is raised, but this depends on the > return value being different from the number of items written > (presumably 0)) I may be getting confused. The undefined behaviour I was on about was interleaving reads & writes without an intervening seek. > It's my feeling that this is intended to be an error condition, not > undefined behavior. But I can't prove it. Here are some relevant pages > from the SUS spec, which intends to follow ISO C: > http://www.opengroup.org/onlinepubs/007904975/functions/fopen.html > http://www.opengroup.org/onlinepubs/007904975/functions/fwrite.html The EBADF error seems to be marked as an extension to ISO C, but I don't know what that signifies. > Hm, and there's a bug even on Linux: > >>> f = open("/dev/null", "r") > >>> f.write("") # should cause exception (?) > >>> # nope, it doesn't That might well not even call an C library routine at all (I don't know). Cheers, mwh -- 59. In English every word can be verbed. Would that it were so in our programming languages. -- Alan Perlis, http://www.cs.yale.edu/homes/perlis-alan/quotes.html From afriere at yahoo.co.uk Wed Aug 27 20:44:36 2003 From: afriere at yahoo.co.uk (Asun Friere) Date: 27 Aug 2003 17:44:36 -0700 Subject: Celebrity advice (was: Advice to a Junior in High School?) References: <3F4CD2A2.DE7D05D2@engcorp.com> Message-ID: <38ec68a6.0308271644.63430149@posting.google.com> Peter Hansen wrote in message news:<3F4CD2A2.DE7D05D2 at engcorp.com>... > "20th century" (period beginning roughly > January 1, 1900 and ending on or one year before December 31, 2000)? > Actually the 20th Century began on January 1 1901. When it ended is a matter of endless debate, but a debate which is WAY more fun than the gun debate! :P From max at alcyone.com Fri Aug 29 02:40:30 2003 From: max at alcyone.com (Erik Max Francis) Date: Thu, 28 Aug 2003 23:40:30 -0700 Subject: Add two dicts References: <86ktkvkd05e88hu14hjudmfvbul7slfgkt@4ax.com> <3F4EDF7A.C9CF6DA3@alcyone.com> <0mrtkv8b1bnnk1v310kf3b8tmjo8d9higo@4ax.com> Message-ID: <3F4EF55E.8F903BEF@alcyone.com> Afanasiy wrote: > My only guess why that doesn't exist is that no one decided what to do > on > like keys. Use existing, overwrite, or throw exception (my > preference). Yes, it's likely. In fact, this discussion only just came up a few days ago. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ An ounce of hypocrisy is worth a pound of ambition. \__/ Michael Korda From bdesth.nospam at removeme.free.fr Mon Aug 18 18:49:21 2003 From: bdesth.nospam at removeme.free.fr (Bruno Desthuilliers) Date: Tue, 19 Aug 2003 00:49:21 +0200 Subject: What's TOTALLY COMPELLING about Ruby over Python? In-Reply-To: References: Message-ID: <3f4155c4$0$1124$626a54ce@news.free.fr> Brandon J. Van Every wrote: > Michael Sparks wrote: > >>On Mon, 18 Aug 2003, Brandon J. Van Every wrote: >> >>>What's ***TOTALLY COMPELLING*** about Ruby over Python? >> >>You can create lasers using rubies I believe whereas pythons are >>simply cute. > > > Cute. > > >>Michael. >>(Since this is clearly a troll :) > > > I'm tired of repeating the sincerity of my questions to people who can't > imagine what a valid question might look like. Anyone who thinks the > question is "so clearly" a troll, doesn't have the analytical imagination to > be useful to me on Python subjects in general. So, welcome to my killfile. > I too think and cry out loud that you are a troll. I'm I in your killfile, now ? (c'mon, Brandon, make my day). Bruno From ajack at trysybase.com Fri Aug 8 15:11:44 2003 From: ajack at trysybase.com (Adam Jack) Date: Fri, 8 Aug 2003 13:11:44 -0600 Subject: Yet Another ... ImportError: No module named sax Message-ID: <001b01c35de0$e9341d30$4478160a@sybase.com> Hello. I am on W2K w/ ActiveStart Python 2.2.2 build 224. This was working, but seems to have stopped and won't start again... Yesterday I read Python tutorials/manuals and today I am tinkering with my first program & hacking somebody else's program. I was putzing along quite happily and then I created an xml.py. Immediately things starting going wrong, see below, so I renamed it to xmlutils.py but I still get the error. I've cleaned up any *.pyc files I see, but it seems that somehow I've taught my environment about my xml (which no longer exists) in favour of the system one. Is this possible? I've not changed my path or anything. Could this be some sort of registry/optimisation thing? :\data\OSS\jakarta-gump\python>python gump/exec.py raceback (most recent call last): File "gump/exec.py", line 71, in ? from gump.conf import * File "F:\data\OSS\jakarta-gump\python\gump\__init__.py", line 94, in ? from xml.sax import parse ImportError: No module named sax Any thoughts on how I make this work again? regards Adam From adalke at mindspring.com Wed Aug 27 13:02:44 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Wed, 27 Aug 2003 17:02:44 GMT Subject: Aspect oriented Everything? References: <32cc321c.0308221316.2f5793ac@posting.google.com> <6ee58e07.0308230459.24f53b64@posting.google.com> <8ef9bea6.0308261857.1b44a5b7@posting.google.com> Message-ID: Hung Jung Lu: > (If you know > Fourier transform, you know what I mean. A localized wave packet in > time necessarily means a spread-out packet in frequency, and > vice-versa. You can't have encapsulation both ways.) But then there's wavelets. :) Andrew dalke at dalkescientific.com From alloydflanagan at comcast.net Tue Aug 26 15:28:33 2003 From: alloydflanagan at comcast.net (A. Lloyd Flanagan) Date: 26 Aug 2003 12:28:33 -0700 Subject: What has been going on? References: <1768.68.75.128.246.1061412809.squirrel@webmail.iserv.net> Message-ID: tjland at iserv.net wrote in message news:... > Ignore those last two messages accidently sent. Who else has been getting > messages returned that you didnt send. Mail scanners saying their is a > virus? The list i think has been infected with the W32/Sobig.f-MM virus, I've been getting a huge number of these. Basically a virus is in the computer of someone who has you in their address book. It sends out messages from their computer but forges your address in the header fields. So, when that message gets bounced by the recipient's filter, the error message comes to you, not the true sender. I don't know what Microsoft was thinking in their last few software releases. It's not like they didn't have plenty of warning that this was coming. For now, it's going to get worse before it gets better. From bokr at oz.net Mon Aug 4 04:17:30 2003 From: bokr at oz.net (Bengt Richter) Date: 4 Aug 2003 08:17:30 GMT Subject: How do I get a reference to a KEY value of a dictionary? References: <645db655.0307311636.71923378@posting.google.com> <0UXWa.416$_57.26378288@newssvr21.news.prodigy.com> Message-ID: On Sun, 03 Aug 2003 08:51:40 GMT, "Andy C" wrote: >Thanks, looks interesting... but it actually doesn't really address the >question I was asking. It doesn't matter since I think the intern solution I thought it did ;-) >is fine for me. But if I'm not mistaken, your solution still stores the >node names in the values of the dictionary (via the Node objects). So in No, just references, not duplicate strings. >effect you do still have a dictionary of the form { 'node1name': >('node1name', other node1 data), 'node2name': ('node2name', other node2 >data)). It doesn't seem as silly when you have a real node object, though. >In my application the nodes are really just strings; I don't need anything >else. Well, don't you need the adjacency lists you were talking about? I assumed they were all lists of out-edges associated with graph vertices. So I defined a Node class with the two things: a name and an adj_list. You can eliminate the name reference and just let the graph dict keys be the only reference, but then you will not so conveniently have the name available to algorithms that process the nodes. E.g., for some node myNode you might have to search the dict something like for key,value in graph.items(): # untested! if value is myNode: myName=key; break else: myName = "?? can't find name of %r ??'%myNode One caveat though, if your graph has cycles, changing the adjacency lists to direct node references instead of names will create reference cycles that may have to be broken for the gc. I have to look into that. You can comment that fixup loop out if you want to keep adjacency lists as name string references instead of node references. BTW, have you looked at the sets module of 2.3? That would let you have a set of strings with no associated values, and no duplicates (but how do you represent adjacency lists then?) Anyway, unless I goofed, the { 'node1name':('node1name', other node 1 data) } analogy is not using two separate strings. It's more like the result of (untested!): s = 'node1name' graph.update({ s:(s, other node 1 data)}) # pseudo-tuple-element at graph[s][1] ;-) del s To check, I added the assert below, where it scans the node names in the graph.show() method, and it didn't complain: def show(self): node_names = self.keys() 8< snip >8 for node_name in node_names: assert node_name is self[node_name].name prtree(self[node_name]) ret.append('') return '\n'.join(ret) Regards, Bengt Richter From adalke at mindspring.com Wed Aug 13 20:24:44 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Wed, 13 Aug 2003 18:24:44 -0600 Subject: Py2.3: Feedback on Sets References: <3v8ljvo5amvbaq5qdd4e8h9lf47q7afhqk@4ax.com> Message-ID: Gary Feldman: > Also, I'd like to see "iterable must be ", > though this is a general flaw in the Python doc and is perhaps > biased by my C/C++ background where you'd never dream > of doing a reference manual without explicitly indicating the > types of every parameter. Python uses what is sometimes called "duck typing" (meaning, if it quacks like a duck...). Lots of objects are iterable - strings, lists, sets, dict (keys), and user-defined classes. Since you prefer C++, think of Python more akin to templates. Templates expect the objects templated on to have certain properties (can be "+"ed, can be deferenced, has a method named "xyz") and not that they have given types. > Personally, I have hard time imagining where I'd want > [remove]. If I really cared, I could check beforehand, so I think > I'd just always use discard. I'm the other way around. I find it hard to imagine where I would call discard. If I want to remove an element from a set then I want to know right away if that element isn't there. It's been handy for tracking down bugs in my code. > 5.12.2 > engineering_management = engineers & programmers Actually, I don't like that example because there is too much text to read through to see the actual symbols used. > PS I suppose I should mention my strongest pet peeve > with the Python documentation, which is the practice of > putting the member functions on a different page than > the class overview. But that's not your issue, either. And I confess that I like to see everything on one page and not split up between several pages. That way I can use my browser's search facility. Andrew dalke at dalkescientific.com From gh at ghaering.de Thu Aug 7 06:09:38 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Thu, 07 Aug 2003 12:09:38 +0200 Subject: using like and % in MySQLdb In-Reply-To: References: Message-ID: <3F322562.8020907@ghaering.de> Torsten Marek wrote: > Dave Harrison schrieb: > >> Im sure this is a really obvious problem but : >> >> self.curs.execute( >> """SELECT * FROM user WHERE login LIKE '%%s%'""", [login] >> ) >> >> will not work ... gives me an "unsupported format character ''' (0x27)" >> >> escaping the %'s with % as the doco recommends wont work either. >> > Why don't you do > self.curs.execute( > """SELECT * FROM user WHERE login LIKE %s""", ("%"+login+"%", )) > [...] You're right. Please ignore my previous post in this thread. It correctly shows how to escape percent signs, but won't work in the SQL context. -- Gerhard From gh at ghaering.de Tue Aug 26 07:33:30 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Tue, 26 Aug 2003 13:33:30 +0200 Subject: Comments on my "Python Introduction" slides In-Reply-To: <33803989.0308260210.4c1e058@posting.google.com> References: <33803989.0308240000.35b9bf1f@posting.google.com> <33803989.0308240644.3090f039@posting.google.com> <3f492761$0$49117$e4fe514c@news.xs4all.nl> <33803989.0308260210.4c1e058@posting.google.com> Message-ID: <3F4B458A.3090200@ghaering.de> Miki Tebeka wrote: >>frame 10: IMO "Magic methods" has a negative connotation. but maybe it's the correct terminology > > I'll try to find a better alternative. I'd suggest "special methods" - the language specification has a chapter "special method names" (http://www.python.org/doc/current/ref/specialnames.html). -- Gerhard From mhammond at skippinet.com.au Tue Aug 5 22:50:33 2003 From: mhammond at skippinet.com.au (Mark Hammond) Date: Wed, 06 Aug 2003 12:50:33 +1000 Subject: Win32All Crashes Python 2.3? In-Reply-To: <3f30680c_4@corp-news.newsgroups.com> References: <3f30680c_4@corp-news.newsgroups.com> Message-ID: Roger Upole wrote: > I get the same thing on Win2k, Python 2.3 anytime a unicode string is > passed to os.lstat (without invoking any win32all modules) > ... > Looks like the problem is in posixmodule.c > PyUnicodeObject *po; > if (PyArg_ParseTuple(args, wformat, &po)) { > wformat at run time is "u:lstat", which should have > a unicode pointer for the receiving argument, not a PyUnicodeObject. > os.stat (which works for a unicode string) uses uppercase U in the format. Nice spot! I opened http://www.python.org/sf/783882 then fixed it on both the 2.3 maint branch (so it will appear in 2.3.1) and on the trunk (for 2.4) Mark. From tjreedy at udel.edu Sat Aug 16 12:53:41 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 16 Aug 2003 12:53:41 -0400 Subject: IEEE special values References: Message-ID: <5c2dnXDTmskL_KOiXTWJhw@comcast.com> "Norbert Nemec" wrote in message news:bhl7bi$ggg$1 at rznews2.rrze.uni-erlangen.de... > is there any simple reason why IEEE special values are so poorly supported > in python? A. They are poorly, and just as importantly, inconsistently supported in C. B. Python's floating point arithmetic and standard functions are thin wrappers of the C layer. TJR From skip at pobox.com Wed Aug 20 17:39:31 2003 From: skip at pobox.com (Skip Montanaro) Date: Wed, 20 Aug 2003 16:39:31 -0500 Subject: Python Debugger In-Reply-To: References: <6ee58e07.0308181134.383a69e7@posting.google.com> Message-ID: <16195.60051.405938.845875@montanaro.dyndns.org> David> There was some talk about enhancing this in the 2.3 timeframe, David> but I don't think it made it in. I thought I saw one or two checkins by Jeremy Hylton in this regard. I don't recall if it was before or after the 2.3 release, but I'm pretty sure there's more in there now (in CVS at least) than there was in 2.2. Skip From mwh at python.net Thu Aug 14 13:18:41 2003 From: mwh at python.net (Michael Hudson) Date: Thu, 14 Aug 2003 17:18:41 GMT Subject: German umlaut in a string. References: Message-ID: <7h37k5g40sb.fsf@pc150.maths.bris.ac.uk> Lukas Kasprowicz writes: > Hi Leszek, > > When I create a string with > > ="String" > > It works! > > But I have a string that was converted from a tuple to a string. Oh, hang on... when you 'str' a tuple, its contents get 'repr'ed, so you get backslash escapes... Cheers, mwh PS: You want to be using the .replace() string method for things like this -- Some people say that a monkey would bang out the complete works of Shakespeare on a typewriter give an unlimited amount of time. In the meantime, what they would probably produce is a valid sendmail configuration file. -- Nicholas Petreley From claird at lairds.com Sun Aug 24 11:02:07 2003 From: claird at lairds.com (Cameron Laird) Date: Sun, 24 Aug 2003 15:02:07 -0000 Subject: QuickTimeTcl References: Message-ID: In article , Bgc wrote: >Hi All, > >I'm interested in producing educational applications with Python. Of >special interest is the playback of video, something that has as of >yet eluded me. I'm wondering what kind of access Python has to the >Tcl scripting language, because of the following project: > >http://hem.fryistorg.com/matben/qt/ >http://sourceforge.net/projects/quicktimetcl/ >(I hope that URL is correct; google for QuicktimeTcl if not) > >I understand (actually, I'm just beginning to explore) Python's >wrapper access to Tk, but I'm sort of confused about Python's access >to the Tcl scripting language. Is there a similar wrapper for the Tcl >language, and if so, can anyone suggest a reasonable process for >creating a Python wrapper for QuicktimeTcl? . . . Python does all of Tcl. Tk is a superset of Tcl. Tkinter gives access to all of Tk. Conclusion: Tkinter gives access to all of Tcl, in particular. That doesn't mean you automatically get everything you want. There are a couple of difficulties: 1. From a Pythonic viewpoint, programming Tcl through the Tkinter.tk.eval() mechanism isn't pretty. Developers making heavy use of Tcl often *do* write Python wrappers. I know of no such wrapper for QuicktimeTcl. 2. QuicktimeTcl isn't Tcl, strictly; it's an *extension* of Tcl. Sometimes ex- tensions work transparently with Tkinter; sometimes ... not. I have no idea what shape Tkinter-plus-Quicktime- Tcl is in. 'Sounds like a fun project, though. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://phaseit.net/claird/home.html From mpeuser at web.de Sun Aug 17 09:54:19 2003 From: mpeuser at web.de (Michael Peuser) Date: Sun, 17 Aug 2003 15:54:19 +0200 Subject: bitwise not - not what I expected References: Message-ID: "Elaine Jackson" schrieb im Newsbeitrag news:d4L%a.781431$Vi5.17573533 at news1.calgary.shaw.ca... > > "Tim Peters" wrote in message > news:mailman.1061098645.13097.python-list at python.org... > > > | To understand your example above, note that > | binary 10010 actually has an unbounded number of 0 bits "to the left": > | > | ...00000010010 = 13 .. should read 18 BTW > | > | The bitwise inversion of that therefore has an unbounded number of 1 bits > | "to the left": > | > | ...11111101101 = -19 > > ** What you're saying, the way I read it, is that 5+S=(-19), where S is the > (divergent) sum of all the powers 2^k of 2 with k>=5. I'm still at sea, in other > words. I think not. Tim seems to point out that there is no natural final "representation" of negative numbers unless we invent some convention. The interpretation of 1101101 or 11111101101 or ......1111101101 as -19 is a convention and has nothing to do with the more natural interpretaton of 101101 as 18. The main reason is that binary adders used in computers are very simple too be (ab-) used for subtraction in that way.... Kindly Michael P From amk at amk.ca Sun Aug 10 16:51:25 2003 From: amk at amk.ca (A.M. Kuchling) Date: Sun, 10 Aug 2003 15:51:25 -0500 Subject: stop the presses - AMK is licensed to drive! References: <5%wZa.39$DH3.41178@news.uswest.net> Message-ID: On Sun, 10 Aug 2003 12:32:59 -0700, Kevin Altis wrote: > Is this part of the PSU master plan? ;-) Not at all, unless the PSU is trying to ensure that residents of northern Virginia area prefer to avoid the roads from now on. (What am I thinking?!? Residents in the northern Virginia area would prefer to avoid the roads at all times, given the traffic around here.) --amk (www.amk.ca) My biorhythms must be at an all-time low. -- The Doctor, in "The Pirate Planet" From adalke at mindspring.com Thu Aug 21 01:50:23 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Thu, 21 Aug 2003 05:50:23 GMT Subject: Newbie problem with codecs References: Message-ID: derek / nul wrote: > > File "apply_physics.py", line 12, in ? > > codecs.lookup(BOM_UTF16_LE) > > NameError: name 'BOM_UTF16_LE' is not defined Alex > Change the statement to: > codecs.lookup(codecs,BOM_UTF16_LE) Typo? Shouldn't that be a "." instead of a "."? In any case >>> codecs.lookup(codecs.BOM_UTF16_LE) Traceback (most recent call last): File "", line 1, in ? File "C:\PYTHON23\Lib\encodings\__init__.py", line 84, in search_function globals(), locals(), _import_tail) ValueError: Empty module name >>> In any case, the "BOM" means "byte order marker" and the constant is the string prefix used to indicate which UTF16 encoding is used. It isn't the encoding name. Perhaps the following is what the OP wanted? >>> codecs.lookup("utf-16-le") (, , , ) >>> But I am not Martin. ;) Andrew dalke at dalkescientific.com From theller at python.net Fri Aug 8 10:40:19 2003 From: theller at python.net (Thomas Heller) Date: Fri, 08 Aug 2003 16:40:19 +0200 Subject: Accessing c objects in python References: Message-ID: Duncan Booth writes: > Thomas Heller wrote in news:smocwafb.fsf at python.net: > >> Would you care to write a more detailed summary of your findings? This >> would probably make a good page in the main Python wiki... >> > > I did an evaluation of the various ways to link to Python for the ACCU > conference this year, although I must say my conclusion was slightly > different than Alex's: I would use Pyrex in preference to SWIG even if I > didn't want to embed much code in the interface. > > You can find a paper describing my views at: > > http://dales.rmplc.co.uk/Duncan/accu/integratingpython.html > > The slides and source code for the talks are also on the same site. See > http://dales.rmplc.co.uk/Duncan/accu > Interesting. I added these links to the Python wiki. Thomas From sfb at alysseum.com Fri Aug 15 18:50:53 2003 From: sfb at alysseum.com (Simon Bayling) Date: Fri, 15 Aug 2003 22:50:53 +0000 (UTC) Subject: Replace every n instances of a string References: <62de87da.0308151325.41ea4622@posting.google.com> Message-ID: > Any ideas? Do I not want to search for "\\u" but instead just insert > a \n after each 72 characters (equivalent to 12 \uXXXX codes)? If you really mean "after each 72 characters", then something like this; output = [] for i in len(0, s, 72): output.append(s[i:i+72] + '\n') print ''.join(output) > Would this provide better performance? Would what provide better performance than what in what scenario(s)? The difference between the original string and the string with newlines is probably insignificant... - Simon. From jjl at pobox.com Mon Aug 25 08:49:06 2003 From: jjl at pobox.com (John J. Lee) Date: 25 Aug 2003 13:49:06 +0100 Subject: JavaScript web scraping test cases? References: <87ekzg0y6e.fsf@pobox.com> Message-ID: <87fzjpdhrx.fsf@pobox.com> "Cousin Stanley" writes: > I'm not sure what types of applications > you're looking for, The kind that people actually want to use . As I said, there's no problem finding test cases, I just thought that while I was about this, somebody might happen be reading who was actually trying to scrape a JS page. > but I have some JavaScript plots > that might be interesting to test ... > > http://fastq.com/~sckitching/JS/Circle_MH.htm [...] Konqueror 3.1 didn't show anything, Mozilla 1.4 printed some pretty circles, then froze! John From irmen at -NOSPAM-REMOVETHIS-xs4all.nl Tue Aug 12 05:59:22 2003 From: irmen at -NOSPAM-REMOVETHIS-xs4all.nl (Irmen de Jong) Date: Tue, 12 Aug 2003 11:59:22 +0200 Subject: Howto MACRO in python ? In-Reply-To: References: Message-ID: <3f38ba7a$0$49100$e4fe514c@news.xs4all.nl> Bill Loren wrote: > Hi, > > I was looking for a guidance about how to code MACROs in python. > any offer ? > > thx > B http://www.catb.org/~esr/faqs/smart-questions.html --Irmen From bart_vanhaute_ at hotmail.com Sun Aug 17 08:43:21 2003 From: bart_vanhaute_ at hotmail.com (Bart) Date: Sun, 17 Aug 2003 14:43:21 +0200 Subject: resolving relative paths for external entities with xml.sax References: Message-ID: On Fri, 15 Aug 2003 06:24:02 -0700, Uche Ogbuji wrote: >> From what I understand of XML specs, relative paths in external entities >> are relative to the location of the document *in which they are defined*. >> However, using xml.sax (which calls expat, I presume), the paths are >> resolved relative to the current working directory. So the parser can not >> find the test.inc when the current working directory is e.g. dir1. > > I, for one, need to see your Python code to tell, because if you're > using the APIs rightly parsing the first file as a URI rather than, > say, reading it in as a string first), then you should not have the > problem you report. something like: from xml.sax import make_parser from xml.sax.saxutils import XMLGenerator reader = make_parser() reader.setContentHandler(XMLGenerator()) reader.parse('test.xml') this is run in the test1 dir. I also tried using absolute paths, xml.sax.InputSource, 'file:' URLs and combinations of these. The result is either: OSError: [Errno 2] No such file or directory: 'test.inc' or (when using 'file://tmp/xmltest/test1/test.xml'): OSError: [Errno 2] No such file or directory: '/tmp/xmltest/test1/test.inc' or (when using 'file:test.xml'): OSError: [Errno 2] No such file or directory: '/test.inc' In the meantime, I found a discussion in bugzilla for python.xml about the prepare_input_source method in xml.sax.xmlutils (see http://sourceforge.net/tracker/index.php?func=detail&aid=616431&group_id=6473&atid=106473) but i am not sure it is really relevant. From gafStopSpamData at ziplink.stopallspam.net Thu Aug 21 07:29:45 2003 From: gafStopSpamData at ziplink.stopallspam.net (Gary Feldman) Date: Thu, 21 Aug 2003 11:29:45 GMT Subject: if in for loop References: Message-ID: On Wed, 20 Aug 2003 11:16:04 -0400, "Sean Ross" wrote: >... (which would be one >reason people refactor such things using functions). Bingo. The code is complex because the set of conditions is complex, and there's no way that pure syntactic sugar can eliminate the semantic complexity. Refactoring does help, because it adds layers of abstraction, allowing the author and, more importantly, the subsequent maintainers to focus on small chunks at a time. Moving the conditions around within one function, and eliminating or adding punctuation or keywords doesn't have the same effect. Gary From mwh at python.net Mon Aug 4 07:05:21 2003 From: mwh at python.net (Michael Hudson) Date: Mon, 4 Aug 2003 11:05:21 GMT Subject: Python's biggest compromises References: <7xr8456ote.fsf@ruckus.brouhaha.com> <-JecnbRfsp3-lLaiXTWJkQ@comcast.com> <7xel04oond.fsf@ruckus.brouhaha.com> Message-ID: <7h3u18x8z0m.fsf@pc150.maths.bris.ac.uk> Paul Rubin writes: > > As I understand it, Psyco unboxes some types and does away with some > > of the need for any GC. *That* does seem to make a difference. > > I think very large performance improvements can come from changing the > language semantics in ways that would cause some backwards > incompatibility. But I think that should be considered for Python > 3000 which should be implemented with a native-code compiler from the > very outset. I don't see why a good Python system can't have the > performance of a good Lisp system. I can think of a few reasons, actually, with Python as it is today, mostly along the lines of things like "you can't extend at runtime the functionality of #'cl:=". Tangentially, I'm not aware of any work that does Pysco-style dynamic specialization in a Common Lisp environment, which surprises me to the extent that I suspect I just don't know about it. Can anyone provide a pointer? Cheers, mwh -- ... with these conditions cam the realisation that ... nothing turned a perfectly normal healthy individual into a great political or military leader better than irreversible brain damage. -- The Hitch-Hikers Guide to the Galaxy, Episode 11 From vanevery at 3DProgrammer.com Mon Aug 11 18:07:49 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Mon, 11 Aug 2003 15:07:49 -0700 Subject: Python vs. C# References: <3f357a9b@shknews01> Message-ID: Duncan Booth wrote: > > Don't get me wrong, C# is quite good, but it just has too much > syntactic clutter obscuring the code. Ok, so Python is "more flexible" than C#. If I start doing problems that require a lot of flexibility, I'll remember this about Python and consider it. To date I've not been working on such problems, but that could change. And C# might still prove to be "flexible enough." -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From stsolakos at patras.atmel.com Wed Aug 6 06:04:04 2003 From: stsolakos at patras.atmel.com (Stavros Tsolakos) Date: Wed, 06 Aug 2003 13:04:04 +0300 Subject: PyRun_SimpleString, PyRun_File Message-ID: <3F30D294.6050403@patras.atmel.com> >I decided to load scripts into memory myself and execute them with >PyRun_(Simple)String. > I don't know anything about this, but, I use PyRun_SimpleString( "execfile( 'filename' )" ) to execute files. Give it a try. Regards Stavros From uche at ogbuji.net Fri Aug 15 20:43:46 2003 From: uche at ogbuji.net (Uche Ogbuji) Date: Fri, 15 Aug 2003 18:43:46 -0600 Subject: "drop-in" DOM replacement for minidom? In-Reply-To: Message from Geoff Gerrietts of "Fri, 15 Aug 2003 13:28:57 PDT." <20030815202857.GA2349@thoth.homegain.com> Message-ID: <200308160043.h7G0hkZA008058@malatesta.local> I think you may have thought there was animus in my message, but I assure you there was none. > Quoting Uche Ogbuji (uche at ogbuji.net): > > > > My response is usually more like "what are you using XML for a single > > 30MB file for?" > > I don't think you responded when I asked. :) I would have liked to. I'm on so many newsgroups that I pretty mych stagger under the load. My approach to Usenet right now is to do a "python xml" search on Google/Deja every Friday and answer what I can from what comes up. I'd like to be in closer touch, but such is life. > http://groups.google.com/groups?th=bf5c3ace18a4e2b6&seekm=mailman.1053714039.24283.python-list%40python.org > > > I've long maintained that when working with XML, modest document sizes > > is very important, regardless of what tools you're using. > > I think I agree, though some are better suited for large documents > than others. True, though since in my experience it is not a linear curve under *any* processor, you're most likely to find out that one processor can handle a 30MB document, but not a 33MB document. I've eaten all brands of dog food, not just my own, and I haven't found any that have let me be truly cavalier about document sizes. Such is the curse of XML. > > > My friend also had some more challenging problems. He was running on a > > > DEC Alpha, I think under Digital Unix, and as a consequence 4Suite had > > > byte-ordering problems. > > > > 4Suite used to have byte-ordering problems, originally reported under > > Solaris 9, and also affecting some Mac OS X users. Those are fixed > > now. > > As of May this year, 4Suite's cDomlette was having problems for these > users under DEC Alpha running Digital Unix, when dealing with Unicode. > I don't know whether those problems have been fixed since; Nor do I. The "when dealing with Unicode" is a twist I haven't come across, that I remember. > I only know > they existed. I've personally never had a problem with cDomlette. If > you would like, I can put you in touch with the user directly and he > may be able to do some tests for you. Just to follow up, I'll be > asking him if he's checked recently, see if he can reproduce it. That would be helpful. Thanks. > > > However, I believe that if you can get 4Suite to compile, > > > > Which I hardly expect to be a problem. > > Not intended as a slight on 4Suite's stability; I didn't take it that way. Just being matter-of-fact that compiling shouldn't be a problem for folks on most platforms. I would think that the decision point for selection of cDomlette lies on some other branch. > I use it regularly and > find it quite solid. This was more in reference to the current > disclaimer that 4Suite may not always use cDomlette for all platforms; > sometimes it falls back to a pure-python solution. Right. > > Your memories must be from long ago :-) That API is how it's been for > > a while. > > I think I last used cDomlette last fall or late last summer. At the > time, I did not know how to invoke cDomlette directly, but only > stumbled across a newspost, when looking for ways to tighten-up parse > performance. The post -- probably from a mailing list -- referred me > to cDomlette, but I had to go read source code to figure out how to > use it. Yeah. I think my Akara page dates from last Fall and before that cDomlette docs were non-existent. Sorry my effort came late to save you the pain of code speleology ('specially in C). -- Uche Ogbuji Personal: uche at ogbuji.net http://uche.ogbuji.net Work: uche.ogbuji at fourthought.com http://Fourthought.com From jjl at pobox.com Tue Aug 12 08:03:03 2003 From: jjl at pobox.com (John J. Lee) Date: 12 Aug 2003 13:03:03 +0100 Subject: PYTHON AND C++ References: <3f38a42b$0$245$fa0fcedb@lovejoy.zen.co.uk> Message-ID: <87znift760.fsf@pobox.com> Gerhard H?ring writes: > Somebody with the 1337 pseudonym "BadJake" wrote: [...] > You certainly mean SIP :) > > > You can download SLIP from Phil's web site at > > http://www.riverbank.demon.co.uk > > No, I can't. This is how the page looks like: [...] > I'm sure it will be up again soon ;-) Unfortunately, last time I looked, even when you could download the code, you couldn't download any documentation -- it didn't exist. AFAIK, that hasn't changed. John From jjl at pobox.com Mon Aug 25 08:56:10 2003 From: jjl at pobox.com (John J. Lee) Date: 25 Aug 2003 13:56:10 +0100 Subject: ANN: BlackAdder V1.0.0 References: <3f48a498$3$219$fa0fcedb@lovejoy.zen.co.uk> <3f4946b2$0$248$fa0fcedb@lovejoy.zen.co.uk> Message-ID: <87ad9xdhg5.fsf@pobox.com> "BadJake" writes: > The name of the program you are looking for is PyQt [...] I think he was thinking of pyuic, actually. John From redrumjack at hotmail.com Thu Aug 28 09:03:11 2003 From: redrumjack at hotmail.com (Jesse) Date: Thu, 28 Aug 2003 13:03:11 GMT Subject: Windows Remote Log in In-Reply-To: <9d1rkvgv44tl8ncki3oci9lrn0nt9c507h@4ax.com> References: <9d1rkvgv44tl8ncki3oci9lrn0nt9c507h@4ax.com> Message-ID: I guess it is how can I have a user enter their NT Domain Authentication and the script use it to log into NT Domains the computer it is running on it not a member of. derek / nul wrote: > and the question is? > > On Thu, 28 Aug 2003 03:38:03 GMT, Jesse wrote: > > >>I'm new to both programing and python and having a bit of a problem >>finding an answer online. >> >>I've got a script that will be running on a Windows Machine and will >>need to access remote servers not in the same domain. >> >> >>I'll be using this to restart services, copy files. >>This script will be run by the user so they will be available to enter >>their login information and the users all have manager access to the >>remote domains. >> >>Thanks, >> >>Jesse > > From mwh at python.net Mon Aug 18 09:13:22 2003 From: mwh at python.net (Michael Hudson) Date: Mon, 18 Aug 2003 13:13:22 GMT Subject: Why doesn't __call__ lead to infinite recursion? References: <2a82921f.0308151158.b8c9154@posting.google.com> Message-ID: <7h3he4f1571.fsf@pc150.maths.bris.ac.uk> "Andrew Dalke" writes: > Aahz: > > No time to investigate further, but all your examples used classic > > classes instead of new-style classes; I'm pretty sure that new-style > > classes will more closely emulate the way functions work. There's also > > the wrinkle I didn't mention that functions use a dict proxy IIRC. > > Interesting. Very interesting. Yes :-) You have to have something like this when you do things like 'print type(foo)'. This should call the *types* *bound* __str__ method, not try to call the *instances* *unbound* __str__ method... Cheers, mwh -- Its unmanageable complexity has spawned more fear-preventing tools than any other language, but the solution _should_ have been to create and use a language that does not overload the whole goddamn human brain with irrelevant details. -- Erik Naggum, comp.lang.lisp From eric.brunel at pragmadev.com Fri Aug 22 04:15:46 2003 From: eric.brunel at pragmadev.com (Eric Brunel) Date: Fri, 22 Aug 2003 10:15:46 +0200 Subject: Problem with py2exe and installer5b5_5 References: <5b8834c2.0308212317.68acf539@posting.google.com> Message-ID: hellprout wrote: > hi , > i want to use py2exe or installer5b5_5 with my python source > > so no problem when i execute the source , but when i use installer or > py2exe to create an exe file on windows , i have some problems > when my program want to read a xml file i have an error > > 2.2.3 (#42, May 30 2003, 18:12:08) [MSC 32 bit (Intel)] > Traceback (most recent call last): > File "wxFrame1.pyc", line 287, in OnButton1Button > File "EIM_xml.pyc", line 135, in main_xml > File "EIM_xml.pyc", line 44, in construction_liste_xml > File "xml\sax\__init__.pyc", line 33, in parse > File "xml\sax\expatreader.pyc", line 86, in parse > File "xml\sax\saxutils.pyc", line 250, in prepare_input_source > File "ntpath.pyc", line 274, in isfile > LookupError: no codec search functions registered: can't find encoding Apparently, there is some weird code importing the codecs that py2exe or McMillan installer cannot correctly figure out. I had the same problem some time ago, which I solved by simply importing explicitely the codecs module via an: import codecs somewhere in the code. This seems to fix up things for McM's installer (never used py2exe). HTH -- - Eric Brunel - PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com From bgailer at alum.rpi.edu Wed Aug 13 13:04:02 2003 From: bgailer at alum.rpi.edu (Bob Gailer) Date: Wed, 13 Aug 2003 11:04:02 -0600 Subject: How to make tree of dictionaries? In-Reply-To: <87fzk6tuoq.fsf@big.terem> Message-ID: <5.2.1.1.0.20030813110321.02c09e60@66.28.54.253> I thought we made dictionaries out of trees... Are you trying to reverse entropy? Bob Gailer bgailer at alum.rpi.edu 303 442 2625 -------------- next part -------------- --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.506 / Virus Database: 303 - Release Date: 8/1/2003 From adalke at mindspring.com Mon Aug 18 14:45:35 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Mon, 18 Aug 2003 12:45:35 -0600 Subject: What's better about Ruby than Python? References: Message-ID: Brandon J. Van Every: > Why do you assume that I'm asking these questions in order to > understand how to program in either? When you said at the start of this thread: > I'm language shopping and I want people's answers. You didn't say you were language window shopping. > I want to know what people's *perceptions* are. Nothing said in the last few days from either your C# thread or your Ruby thread has raised anything new, and a trivial Google groups search would have given you not only information about perception but the ability to gauge trends in that perception. If you were serious about this, you would *start* by giving the results of your analysis, along with points which you think need further clarification and point out weak points in your thinking. You should not make the assumption that people will do this for you, and given your poor reasoning skills, it's unlikely that even if people did that you would miss the answer. Instead, you make people like me just more and more annoyed about your posts. > Subscribe to marketing-python if you want to puzzle me out more. Or not. Word on the net is that you've raised a whole bunch of bluster there. Andrew dalke at dalkescientific.com From tzot at sil-tec.gr Sat Aug 23 14:56:08 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Sat, 23 Aug 2003 21:56:08 +0300 Subject: Modifying the {} and [] tokens References: <04cekv0s6ghjtuhl5j2gph7ltobdb5rsam@4ax.com> <62rekv0k4ucgrh46lkp27klq13pq8ppp5p@4ax.com> <1h3fkvg8mkeq69a8hriojugqfcp75hafjj@4ax.com> Message-ID: On Sat, 23 Aug 2003 16:04:52 GMT, rumours say that Geoff Howland might have written: >On Sat, 23 Aug 2003 16:40:17 +0300, Christos "TZOTZIOY" Georgiou > wrote: > >>On Sat, 23 Aug 2003 09:16:13 GMT, rumours say that Geoff Howland >> might have written: >> >>[snip of python's by design inability to modify the base C types: dict, >>str, list etc] > >This post begins to read as an insult here, and continues. My >incredible gall at thinking something may be better if it was changed >and wanting to try it! I should be pelted with rocks for speaking the >name Jehova. I am sorry, Geoff, but I can't understand how you perceived my post as insulting. If I did understand a way, I would apologise. I just snipped stuff in order to make my post shorter, according to netiquette. How can the phrase inside the brackets seem insulting to you? Geoff, please justify your clause, and I will gladly apologise. >Is this really the way this group is going to continue? I don't know, I can speak for myself only. How many people have responded to you this "way" to make you wonder about the whole group? >>>Ruby has this built in, it's useful, it's complete. It's obvious what >>>is happening, so it's not unclean. It's allowed for other containers. >> >>It seems that code "terseness" is more important to you than code >>readability. I can sympathise with that, perhaps I'd like that too, but >>I believe I fully understand Guido's decisions over the years to >>disallow that kind of stuff. > >[] + [] is allowed. Right? > >{} + {} is not allowed. > >len([]) is allowed. > >[].len() is not allowed. > >Why? I respect Guidos decsions, Python needs a strong leader to make >them and it got where it is (great language) by having him and the >rest of the community help out in this regard. This is the deal, indeed; for example, I would enjoy very much generator comprehensions in the language, and yet they were rejected. >Is now no one allowed to say "hey, I think this should be done, and >I'd like to make it happen to give it a try"? It's not like if it >becomes a problem it couldn't be reverted and lesson learned right? >Programming is ABOUT experimentation, not dogmatic obedience. My reply came to your specific feature request, ie Python allowing you to modify the base types; your asking if *any* feature request is disallowed is not justified. I consider your question similar to the following dialog: - Can I have cherry pie with my meal? - No, because the cook has decided it does not match with your meal, which is fish. - So no one is allowed to ask for dessert here? I believe that the symbolism is childish, and this indeed you might find it insulting, although it isn't. I am not as fluent in English as I would like, so this is my way to express the general feeling I got from your reply; I call it "black-and-white", or "ping-pong", lacking a better English word, and describes a two-way communication where a disagreement on the one side is perceived magnified as total rejection on the other side. >>I really don't mind subclassing base types and using MyDict() instead of >>{}. I want to be able to make my own APIs (MyDict.update *could* blow >>whistles and roll twice on the floor before resetting the machine), but >>I also want a steady and well-known API for base types (dict.update >>*should* update a dictionary from another one). > >Why should it matter what you mind? It's my code. What should it matter what you mind then? It's Guido's language. Either we both are allowed to say our minds, or not. My opinion is as important as yours. Keep that in mind, please. The fact is, the subject has been brought up in the past, and it has been skipped. I am not sure if has been rejected, so you might have a chance. If you are as warm about this subject as you seem to be, write a PEP; my vote will probably be positive. But Guido is the one to convince, and he listens; my experience so far has shown that he never replies the way you do, and that is good. This URL should be useful: http://www.python.org/peps/pep-0001.html >>You can always roll off a customised Python interpreter, of course, but >>it won't be Python anymore. >>With all due respect, Geoff, if this stuff is really important to you, >>use Ruby. >Yes, throw the heathen into another language. I'm not good enough for >this one. Your last statement is unjustified too, and "black-and-white", assuming hidden meanings in my words. Geoff, I am picking my words very carefully because I don't want to make you jump to the ceiling with rage. Please read, don't assume. My sentence was a practical (and respectful!) suggestion; Ruby already has what you want, and you like it, so why not use it, since the Python community (and Guido most of all) are against such a modification? Did you do a research in older newsgroup threads before posting? >I find this attitude really insulting. I like Python for what it is, >that doesnt mean I dont think there are some things that could be >better and want to try them. I wanted to know if it's possible, so I >asked. I think it's important, so I persisted. Get over it. Stop >making this place an unpleasant place to ask questions in fear of not >asking in a Pythonic enough way. Perhaps you are irritated by earlier discussions, whom I'm not in the mood to look for; this might explain your misinterpretation of my message. Geoff, my attitude was not insulting. It was practical. >Not the first time I've seen this here, I'm sure it wont be the last. >Not sure how many people never picked it up because they were smacked >down before they found their groove in Python. >I'm sorry this sounds heavy and upset, but I would like this place to >not feel so bitter against exploratory questions. Bounds are set in >Python, it's good. It doesn't mean people shouldn't ask and explore >and find out for themselves what is best if it is possible. I could >even go and change all the Python C source to make this work, who is >it going to hurt but myself? It may even bring me valuable insight >that I can then share as an _opinion_ with others who ask later (note, >not telling them to use another language because they want to do >something I dont agree with). Geoff, please. Your last statement inside the parentheses is based on false assumptions, which is bad, because you already had the data. From my previous post I said I'd possibly like what you suggest, and I meant it --and still do. If you don't believe me, if you feel that I am bullying you, lying to you, using sarcasm or irony on you, then I'll have to give up. Don't spend your energy fighting with me (one-side fights: only on USENET :), write a PEP and find good arguments for it. -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From leitao at adtec.com.cn Mon Aug 11 02:47:57 2003 From: leitao at adtec.com.cn (=?gb2312?B?wNfMzg==?=) Date: Mon, 11 Aug 2003 14:47:57 +0800 Subject: Hello Message-ID: <002201c35fd4$7f9284c0$ca110a0a@leitao> I want to user the newgroup of python, but I do not use it! can you give me a hand? -------------- next part -------------- An HTML attachment was scrubbed... URL: From rbroyles at bellsouth.net Sun Aug 24 11:44:44 2003 From: rbroyles at bellsouth.net (Ronnie Broyles) Date: Sun, 24 Aug 2003 11:44:44 -0400 Subject: new to python References: <_%22b.7018$jd.1229@fe02.atl2.webusenet.com> Message-ID: thanks "Rune" wrote in message news:feghkvgq0a0rnjtklprvh3kcg4fobfr7t5 at 4ax.com... > On Sun, 24 Aug 2003 09:38:00 -0400, "Ronnie Broyles" > wrote: > > > > >I am new to python--new to programming period. Will I need a compiler with > >python? I am currently working with the tutorials from the python.org > >website. > > No compiler needed. Python is interpreted. > Good luck! > From tjreedy at udel.edu Thu Aug 28 14:27:09 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 28 Aug 2003 14:27:09 -0400 Subject: Celebrity advice (was: Advice to a Junior in High School?) References: <_M2cnY22TvKT69CiXTWJjA@comcast.com> Message-ID: "Gerrit Holl" wrote in message news:mailman.1062049918.8355.python-list at python.org... > No; reading Newton is also perfectly valid. Cute. For those whoe don't get the joke, Newton, the great mathematical physicist who helped spur the 'Age of Reason', also spent decades 'practicing' and secretly writing about alchemy and related magic, which writings would now (and even then) be considered rubbish to most. (They only became public in the 1930s.) Ironically, his magical beliefs probably helped him conceive of gravity and its 'magical' action at a distance. Terry J. Reedy From usenet_spam at janc.invalid Sat Aug 9 22:17:00 2003 From: usenet_spam at janc.invalid (JanC) Date: Sun, 10 Aug 2003 02:17:00 GMT Subject: ANNOUNCE: Rekall V2.0.2 References: Message-ID: "Neil Hodgson" schreef: >> Why not take a Rekall Demo out for a test drive. Our demos are fully >> functional with a 60 minute time limitation (the Windows demo has a >> 15 day time limit), but they will run again. You can find the demos >> on either of two web sites, http://www.rygannon.com and >> http://www.totalrekall.co.uk > > All links from the top level page require registration, even those > that may explain what the product does. There is some info, including screenshots, that's "reachable" here: -- JanC "Be strict when sending and tolerant when receiving." RFC 1958 - Architectural Principles of the Internet - section 3.9 From bokr at oz.net Mon Aug 4 03:09:30 2003 From: bokr at oz.net (Bengt Richter) Date: 4 Aug 2003 07:09:30 GMT Subject: bug in file.write() ? References: <13a4e2e3.0307311443.299bd59d@posting.google.com> <3f2b5e60.36345431@news.lexicon.net> <3f2b7816_2@news.vo.lu> <3f2cb414_2@news.vo.lu> Message-ID: On Sun, 03 Aug 2003 09:06:04 +0200, Patrick Useldinger wrote: [... more on CDRW mystery ...] By any chance are you doing compression implicitly with the compressor using the destination disk as temp space in some way that requires a complete temp image before copying and before deleting? Maybe if so it can be reconfigured to use space elsewhere or just rename (hm, rename on CDRW isn't implemented as copy, based on renamee not being modifiable, is it?) Still wonder about threads too... Regards, Bengt Richter From missive at frontiernet.net Sat Aug 30 18:51:19 2003 From: missive at frontiernet.net (Lee Harr) Date: Sat, 30 Aug 2003 22:51:19 GMT Subject: variable in regexp References: Message-ID: In article , Peter Enis wrote: > hello, > > does anyone know how to use variables in regular expressions? > > var = '%%bob%%' > > replace = 'bob' > > var = re.sub("%%[^%%]*replace%%', 'peter', var) > > how do i have to mask the replace-variable? > I am not exactly sure what you want to do, but you can make the replace argument to .sub() a function... ie: def repl(matchobj): # do stuff w/ matchobj here return 'foo' var = re.sub(repl, 'peter', var) From r-spirit at sproxy03.hi-ho.ne.jp Fri Aug 22 05:19:18 2003 From: r-spirit at sproxy03.hi-ho.ne.jp (r-spirit at sproxy03.hi-ho.ne.jp) Date: Fri, 22 Aug 2003 18:19:18 +0900 (JST) Subject: Voice Message (105631420722306) Message-ID: <0HK000A4KKK63Z@sproxy03.hi-ho.ne.jp> ------ name ------ Anonymous Friend ------ address ------ Secret ------ message ------ Add expressive voice and music to your websites and emails. Use this new marketing tool in your business or just for fun!. Click the following link to listen to your message: http://voice-email.vze.com/?id=618742659655 Local Time: 2003/8/22/18:19 From irmen at -NOSPAM-REMOVETHIS-xs4all.nl Fri Aug 8 14:35:17 2003 From: irmen at -NOSPAM-REMOVETHIS-xs4all.nl (Irmen de Jong) Date: Fri, 08 Aug 2003 20:35:17 +0200 Subject: ANN: Snakelets 1.2 (simple-to-use web app server with dynamic pages) In-Reply-To: <3f2ea0a0$0$49110$e4fe514c@news.xs4all.nl> References: <3f2ea0a0$0$49110$e4fe514c@news.xs4all.nl> Message-ID: <3f33ed63$0$49102$e4fe514c@news.xs4all.nl> In another announcement, I wrote: > I'm happy to say that Snakelets 1.1 is now available. > > Snakelets is a simple Python web application server, mainly for educational > purposes. This project provides a threaded web server, Ypages (HTML+Python > language, similar to Java's JSPs) and Snakelets: code-centric page > request handlers (similar to Java's Servlets). Small things move fast sometimes-- Snakelets is now at 1.2 :-) New are: - gobble whitespace option now works in Ypages - you can now set the input- and output characater encoding in Ypages; so you can write UTF-8 output for instance. (Python 2.3 required for this) - you can change the content-type for your Ypage so it's possible to write one that outputs text/xml for instance. See http://snakelets.sourceforge.net for more info. --Irmen de Jong From mugginsm at under-the-fridge.com Wed Aug 27 20:13:15 2003 From: mugginsm at under-the-fridge.com (Colin Coghill (SFive)) Date: Thu, 28 Aug 2003 00:13:15 GMT Subject: Replacement for rexec/Bastion? References: Message-ID: In article , Michael Chermside wrote: > > Great! If you are willing to run the untrusted code in a separate > process and fall back on the OS to do the restricting, it _is_ > actually capable of restricting what code can perform, in a way that > Python simply can't match. You can use ulimit and chroot to restrict > what the untrusted code may do. Then there's no particular need to > use ANY special restricted execution support in Python. The reason I haven't just done this is that there are two problems I haven't solved yet, for which I appear to need help from Python itself. Zope's restricted python *does* look like it can solve both of these, I'm still figuring it out though :) A) Network connections You can't afford for the untrusted code to open an uncontrolled network connection, unless you're happy running a spam-repeater. This *could* be solved with a more secure operating system - I'm sure SELinux or OpenBSD could be configured to do this, but that's probably too large a penalty for most uses. I suppose if the chrooted environment provided a cut-down version of Python with all the dangerous stuff stripped, that could do it. But I suspect that'd be more work than reimplementing rexec safely. B) Clean sandbox You can't afford to restart the untrusted process between every piece of code its given unless you're not doing all that much processing. Only restarting it when something goes wrong is the ideal. There needs to be a way to stop one piece of code from messing up the environment for the next one (by creating new versions of __builtins__, for example. Ideas? I currently have three pieces of code: server.py sits in the main application. Provides an API, currently by xmlrpc. provides a "fetchNextSnippet()" which returns the next piece of code to be run. If it has not been called for N seconds, will kill the untrusted process and restart it. linux-safe.py does a chroot(), could probably do more, like setting ulimits, quotas, setuid? unsafe.py fetches a piece of code to run from server using the xmlrpc API. Runs it. That code can call methods in server.py via xmlrpc. Repeat. If I can solve the above two problems, I'm happy to release this code. The interesting thing is that linux-safe.py is the only OS-dependent part. Perhaps equivalents could be made for other systems. There's also no reason unsafe.py needs to be python, this could quite happily be a java, ruby, or whatever environment, if you want to use one of those as your scripting language. Using xmlrpc was only a placeholder because it was easy. This should probably be replaced with something pythonic, over a UNIX Domain socket or the like. - Colin From no at spam.com Tue Aug 5 12:44:57 2003 From: no at spam.com (J. W. McCall) Date: Tue, 05 Aug 2003 16:44:57 GMT Subject: CGI Webcounter not quite working...help, please Message-ID: Sorry again if this is OT; I'm not sure if this is a python problem or just a CGI problem, but I couldn't find a decent CGI NG. Let me know if there's somewhere else I should be posting. I got this webcounter to be called directly (I still can't get it to be called from an HTML file with #exec or #include or anything). Now the problem is that the part of the script that updates the count file doesn't work. It's like it doesn't even execute. Here's the script; don't worry, it's short and simple (I'm a Python beginner) #!/usr/pkg/bin/python print "Content-Type: text/html\n\n" print "\n\n" import os import string print "" print "" filenames = os.listdir(os.curdir) if "count.txt" in filenames: input = open('count.txt', 'r') i = string.atoi(input.read(1)) else: i = 0 print "File doesnt exist
" i = i + 1 print "This page has been accessed " + `i` + " times.
" print "" print "" #it doesn't seem to execute this at all output = open('count.txt', 'w') output.write(`i`) output.close() Do you see any obvious problems with this? It works fine when I call it from the command line. It's on my Freeshell shell account. It's a NetBSD system, I believe. Any advice, ideas? Thanks, J. W. McCall From FBatista at uniFON.com.ar Wed Aug 27 08:31:09 2003 From: FBatista at uniFON.com.ar (Batista, Facundo) Date: Wed, 27 Aug 2003 09:31:09 -0300 Subject: Best way to write a file n-bytes long Message-ID: #- Sure, I could create a string that is n Megabytes long, and #- pass it to #- write, but it seems as though there should be a better way ??? #- String manipulation is typically considered slow. Considering memory & processor speeds versus disk speed, aren't you limited by this latter harwdare? Just write it! . Facundo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ADVERTENCIA La informaci?n contenida en este mensaje y cualquier archivo anexo al mismo, son para uso exclusivo del destinatario y pueden contener informaci?n confidencial o propietaria, cuya divulgaci?n es sancionada por la ley. Si Ud. No es uno de los destinatarios consignados o la persona responsable de hacer llegar este mensaje a los destinatarios consignados, no est? autorizado a divulgar, copiar, distribuir o retener informaci?n (o parte de ella) contenida en este mensaje. Por favor notif?quenos respondiendo al remitente, borre el mensaje original y borre las copias (impresas o grabadas en cualquier medio magn?tico) que pueda haber realizado del mismo. Todas las opiniones contenidas en este mail son propias del autor del mensaje y no necesariamente coinciden con las de Telef?nica Comunicaciones Personales S.A. o alguna empresa asociada. Los mensajes electr?nicos pueden ser alterados, motivo por el cual Telef?nica Comunicaciones Personales S.A. no aceptar? ninguna obligaci?n cualquiera sea el resultante de este mensaje. Muchas Gracias. -------------- next part -------------- An HTML attachment was scrubbed... URL: From electricity at uymail.com Thu Aug 28 03:35:51 2003 From: electricity at uymail.com (U. N. Owen) Date: Thu, 28 Aug 2003 09:35:51 +0200 Subject: Celebrity advice Message-ID: <20030828073551.28804.qmail@uymail.com> I don't see the link with Python, but anyway... Very long ago, some books where burnt in public, for "religious" reasons, later for political reasons. Hopefully these old practice have disappeared and will never come back. And since this crazy guy seems not have read even one line of this book, one can imagine he was bred in an "anti-something", narrow-minded fashion. Actually he is more dangerous than what he denounces... Books are pricey, his advice is not. ----- Original Message ----- From: afriere at yahoo.co.uk (Asun Friere) Date: 28 Aug 2003 00:13:49 -0700 To: python-list at python.org Subject: Re: Celebrity advice Arthur wrote in message > > ""There are some books so bad, but so plausible and influential, that > periodically trashing them in public is almost an obligation. The really > classic stinkeroos of this kind, like Karl Marx's Das Kapital, exert a weird > kind of seduction on otherwise intelligent people long after their factual > basis has been completely exploded.""" > > I gotta go with with Eric on this. > Wow! You've actually managed to read Marx' _Capital_? What all three volumes? I'm impressed! I'm certain no "otherwise intelligent people" would "periodically [thrash]" a book they haven't read, would they? -- _______________________________________________ Get your free email from http://www.uymail.com Powered by Outblaze From fredrik at pythonware.com Wed Aug 20 13:55:26 2003 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 20 Aug 2003 19:55:26 +0200 Subject: ascii2dec References: Message-ID: Uwe Mayer wrote: > this must sound stupid to you, but I'm ages out of Python and I just can't > find a function to convert 4 bytes of binary data to an integer value: > > length=f.read(4) # get length in binary > length=socket.htonl(length) # swap bytes > > #convert 4 bytes to integer > > f.close() > > Thanks for any help import struct result = struct.unpack("!i", f.read(4)) length = result[0] where "!" means network byte order, and "i" means 32-bit integer. see the struct documentation for more options. if the f.read fails to read 4 bytes, this operation raises a struct.error exception note that unpack returns a tuple; you may prefer to unpack a bunch of fields in one step: width, height = struct.unpack("!ii", f.read(8)) From P at draigBrady.com Thu Aug 7 06:45:43 2003 From: P at draigBrady.com (P at draigBrady.com) Date: Thu, 07 Aug 2003 11:45:43 +0100 Subject: Getting output from executed command that is not STDIN In-Reply-To: References: Message-ID: <3F322DD7.3020907@draigBrady.com> Sami Viitanen wrote: > Hello, > > I'm using os.popen and read for reading command input to string but the > string doesn't contain the same output that running the command manually or > with os.system contains. > > with os.system: > cvs server: Diffing //Project1 > File //Project1/testiware.txt is new; current revision 3.13 > File //Project1/what_is_version_control.txt is new; current revision 3.3 > cvs server: Diffing //Project1/Dir1 > File //Project1/Dir1/seltest.c is new; current revision 1.4 > File //Project1/Dir1/testi.c is new; current revision 1.2 > > with os.popen and read: > File //Project1/testiware.txt is new; current revision 3.13 > File //Project1/what_is_version_control.txt is new; current revision 3.3 > File //Project1/Dir1/seltest.c is new; current revision 1.4 > File //Project1/Dir1/testi.c is new; current revision 1.2 > > --- > Script doesn't read those "cvs server: Diffing" lines > --- They go to stderr. The handiest way around this is to put 2>&1 at the end of your command line P?draig, From sybrenUSE at YOURthirdtower.imagination.com Wed Aug 27 13:04:56 2003 From: sybrenUSE at YOURthirdtower.imagination.com (Sybren Stuvel) Date: 27 Aug 2003 17:04:56 GMT Subject: IDE for Python References: Message-ID: Przemo Drochomirecki enlightened us with: > with or without any plugins?? I use it without plugins. Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? From nushin2 at yahoo.com Wed Aug 6 20:14:15 2003 From: nushin2 at yahoo.com (nushin) Date: 6 Aug 2003 17:14:15 -0700 Subject: spawnv( ) or spawnl( ) do not launch a normal running process in Python 2.2.2? References: Message-ID: Thanks Jeff. You do launch a process properly in spawnv if the 3rd parameter of spawnv is argv list, i.e., the following code would launch hello.py in a normal running *R* state in Linux., therefore: os.spawnv(os.P_NOWAIT,'/usr/bin/python',('python', 'hello.py')) would spawn hello.py in state *R*. However, os.P_NOWAIT doesn't work properly, by that i mean, i am expecting *hello.py* to get launched asynchronously, but i see my parent process always gets finished *after* its child process finishes. Is it a bug in spawnv? Please correct me if i am wrong, and thank you for your time. Regards, Nushin Jeff Epler wrote in message news:... > the third argument to os.spawnv is an argument list as in execv, not a > command string as in popen and system. The statement you listed > > os.spawnv(os.P_NOWAIT,'/usr/bin/python',('python hello.py >/dev/null > runs the Python binary with its argv[0] set to 'python hello.py >/dev/null', > which is probably going to drop into trying to read a script from > standard input since there is no script or command on the commandline, > but I'm not really sure what to expect in this crazy case. > > There's no easy way to do command redirections while using spawnv. > Here's a piece of code to do so with fork+exec [tested]: > def F(x): > if not isinstance(x, int): return x.fileno() > > def coroutine(args, child_stdin, child_stdout, child_stderr): > pid = os.fork() > if pid == 0: > os.dup2(F(child_stdin), 0) > os.dup2(F(child_stdout), 1) > os.dup2(F(child_stderr), 2) > os.execvp(args[0], args) > return pid > you could do something similar with os.spawnv [untested]: > def dup2_noerror(a, b): > try: > os.dup2(a, b) > except: > pass > > def coroutine_spawnv(flags, args, child_stdin, child_stdout, child_stderr): > old_stdin = os.dup(0) > old_stdout = os.dup(1) > old_stderr = os.dup(2) > try: > os.dup2(F(child_stdin), 0) > os.dup2(F(child_stdout), 1) > os.dup2(F(child_stderr), 2) > return os.spawnv(flags, args[0], args) > finally: > dup2_noerror(old_stdin, 0) > dup2_noerror(old_stdout, 1) > dup2_noerror(old_stderr, 2) > > Jeff From vze4rx4y at verizon.net Sat Aug 2 00:36:41 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Sat, 02 Aug 2003 04:36:41 GMT Subject: String Replacement References: <7b454334.0308011400.266438f9@posting.google.com> <7b454334.0308011726.15d12be9@posting.google.com> <87lluckewd.fsf@mrbun.watterson> Message-ID: "Tim Heaney" wrote in message news:87lluckewd.fsf at mrbun.watterson... > faizan at jaredweb.com (Fazer) writes: > > > > This works: > > print string.replace(str, "\n", "
") > > > > But I can't assign the result into a variable but only print it like > > the code above. > > The return value is the string you want. So, rather than printing it, > assign it to a variable. You can reuse str, if you like... > > str = string.replace(str, "\n", "
") > > Note that since str is a string, you can invoke its replace method > > str = str.replace("\n", "
") > > rather than the class method. > > I hope this helps, > > Tim "str" is the name of the builtin string type. So, it is inadvisable to re-use "str" as a variable name. Raymond Hettinger From aleaxit at yahoo.com Mon Aug 18 11:26:30 2003 From: aleaxit at yahoo.com (Alex Martelli) Date: Mon, 18 Aug 2003 17:26:30 +0200 Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> Message-ID: Erik Max Francis wrote: > "Brandon J. Van Every" wrote: > >> What's better about Ruby than Python? I'm sure there's something. >> What is it? > > Wouldn't it make much more sense to ask Ruby people this, rather than > Python people? Might, or might not, depending on one's purposes -- for example, if one's purposes include a "sociological study" of the Python community, then putting questions to that community is likely to prove more revealing of informaiton about it, than putting them elsewhere:-). Personally, I gladly took the opportunity to follow Dave Thomas' one-day Ruby tutorial at last OSCON. Below a thin veneer of syntax differences, I find Ruby and Python amazingly similar -- if I was computing the minimum spanning tree among just about any set of languages, I'm pretty sure Python and Ruby would be the first two leaves to coalesce into an intermediate node:-). Sure, I do get weary, in Ruby, of typing the silly "end" at the end of each block (rather than just unindenting) -- but then I do get to avoid typing the equally-silly ':' which Python requires at the _start_ of each block, so that's almost a wash:-). Other syntax differences such as '@foo' versus 'self.foo', or the higher significance of case in Ruby vs Python, are really just about as irrelevant to me. Others no doubt base their choice of programming languages on just such issues, and they generate the hottest debates -- but to me that's just an example of one of Parkinson's Laws in action (the amount on debate on an issue is inversely proportional to the issue's actual importance). One syntax difference that I do find important, and in Python's favour -- but other people will no doubt think just the reverse -- is "how do you call a function which takes no parameters". In Python (like in C), to call a function you always apply the "call operator" -- trailing parentheses just after the object you're calling (inside those trailing parentheses go the args you're passing in the call -- if you're passing no args, then the parentheses are empty). This leaves the mere mention of any object, with no operator involved, as meaning just a reference to the object -- in any context, without special cases, exceptions, ad-hoc rules, and the like. In Ruby (like in Pascal), to call a function WITH arguments you pass the args (normally in parentheses, though that is not invariably the case) -- BUT if the function takes no args then simply mentioning the function implicitly calls it. This may meet the expectations of many people (at least, no doubt, those whose only previous experience of programming was with Pascal, or other languages with similar "implcit calling", such as Visual Basic) -- but to me, it means the mere mention of an object may EITHER mean a reference to the object, OR a call to the object, depending on the object's type -- and in those cases where I can't get a reference to the object by merely mentioning it I will need to use explicit "give me a reference to this, DON'T call it!" operators that aren't needed otherwise. I feel this impacts the "first-classness" of functions (or methods, or other callable objects) and the possibility of interchanging objects smoothly. Therefore, to me, this specific syntax difference is a serious black mark against Ruby -- but I do understand why others would thing otherwise, even though I could hardly disagree more vehemently with them:-). Below the syntax, we get into some important differences in elementary semantics -- for example, strings in Ruby are mutable objects (like in C++), while in Python they are not mutable (like in Java, or I believe C#). Again, people who judge primarily by what they're already familiar with may think this is a plus for Ruby (unless they're familiar with Java or C#, of course:-). Me, I think immutable strings are an excellent idea (and I'm not surprised that Java, independently I think, reinvented that idea which was already in Python), though I wouldn't mind having a "mutable string buffer" type as well (and ideally one with better ease-of-use than Java's own "string buffers"); and I don't give this judgment because of familiarity -- before studying Java, apart from functional programming languages where _all_ data are immutable, all the languages I knew had mutable strings -- yet when I first saw the immutable-string idea in Java (which I learned well before I learned Python), it immediately struck me as excellent, a very good fit for the reference-semantics of a higher level programming language (as opposed to the value-semantics that fit best with languages closer to the machine and farther from applications, such as C) with strings as a first-class, built-in (and pretty crucial) data type. Ruby does have some advantages in elementary semantics -- for example, the removal of Python's "lists vs tuples" exceedingly subtle distinction. But mostly the score (as I keep it, with simplicity a big plus and subtle, clever distinctions a notable minus) is against Ruby (e.g., having both closed and half-open intervals, with the notations a..b and a...b [anybody wants to claim that it's _obvious_ which is which?-)], is silly -- IMHO, of course!). Again, people who consider having a lot of similar but subtly different things at the core of a language a PLUS, rather than a MINUS, will of course count these "the other way around" from how I count them:-). Don't be misled by these comparisons into thinking the two languages are _very_ different, mind you. They aren't. But if I'm asked to compare "capelli d'angelo" to "spaghettini", after pointing out that these two kinds of pasta are just about undistinguishable to anybody and interchangeable in any dish you might want to prepare, I would then inevitably have to move into microscopic examination of how the lengths and diameters imperceptibly differ, how the ends of the strands are tapered in one case and not in the other, and so on -- to try and explain why I, personally, would rather have capelli d'angelo as the pasta in any kind of broth, but would prefer spaghettini as the pastasciutta to go with suitable sauces for such long thin pasta forms (olive oil, minced garlic, minced red peppers, and finely ground anchovies, for example - but if you sliced the garlic and peppers instead of mincing them, then you should choose the sounder body of spaghetti rather than the thinner evanescence of spaghettini, and would be well advised to forego the achoview and add instead some fresh spring basil [or even -- I'm a heretic...! -- light mint...] leaves -- at the very last moment before serving the dish). Ooops, sorry, it shows that I'm traveling abroad and haven't had pasta for a while, I guess. But the analogy is still pretty good!-) So, back to Python and Ruby, we come to the two biggies (in terms of language proper -- leaving the libraries, and other important ancillaries such as tools and environments, how to embed/extend each language, etc, etc, out of it for now -- they wouldn't apply to all IMPLEMENTATIONS of each language anyway, e.g., Jython vs Classic Python being two implementations of the Python language!): 1. Ruby's iterators and codeblocks vs Python's iterators and generators; 2. Ruby's TOTAL, unbridled "dynamicity", including the ability to "reopen" any existing class, including all built-in ones, and change its behavior at run-time -- vs Python's vast but _bounded_ dynamicity, which never changes the behavior of existing built-in classes and their instances. Personally, I consider [1] a wash (the differences are so deep that I could easily see people hating either approach and revering the other, but on MY personal scales the pluses and minuses just about even up); and [2] a crucial issue -- one that makes Ruby much more suitable for "tinkering", BUT Python equally more suitable for use in large production applications. It's funny, in a way, because both languages are so MUCH more dynamic than most others, that in the end the key difference between them from my POV should hinge on that -- that Ruby "goes to eleven" in this regard (the reference here is to "Spinal Tap", of course). In Ruby, there are no limits to my creativity -- if I decide that all string comparisons must become case-insensitive, _I CAN DO THAT_! I.e., I can dynamically alter the built-in string class so that a = "Hello World" b = "hello world" if a == b print "equal!\n" else print "different!\n" end WILL print "equal". In python, there is NO way I can do that. For the purposes of metaprogramming, implementing experimental frameworks, and the like, this amazing dynamic ability of Ruby is _extremely_ appealing. BUT -- if we're talking about large applications, developed by many people and maintained by even more, including all kinds of libraries from diverse sources, and needing to go into production in client sites... well, I don't WANT a language that is QUITE so dynamic, thank you very much. I loathe the very idea of some library unwittingly breaking other unrelated ones that rely on those strings being different -- that's the kind of deep and deeply hidden "channel", between pieces of code that LOOK separate and SHOULD BE separate, that spells d-e-a-t-h in large-scale programming. By letting any module affect the behavior of any other "covertly", the ability to mutate the semantics of built-in types is just a BAD idea for production application programming, just as it's cool for tinkering. If I had to use Ruby for such a large application, I would try to rely on coding-style restrictions, lots of tests (to be rerun whenever ANYTHING changes -- even what should be totally unrelated...), and the like, to prohibit use of this language feature. But NOT having the feature in the first place is even better, in my opinion -- just as Python itself would be an even better language for application programming if a certain number of built-ins could be "nailed down", so I KNEW that, e.g., len("ciao") is 4 (rather than having to worry subliminally about whether somebody's changed the binding of name 'len' in the __builtins__ module...). I do hope that eventually Python does "nail down" its built-ins. But the problem's minor, since rebinding built-ins is quite a deprecated as well as a rare practice in Python. In Ruby, it strikes me as major -- just like the _too powerful_ macro facilities of other languages (such as, say, Dylan) present similar risks in my own opinion (I do hope that Python never gets such a powerful macro system, no matter the allure of "letting people define their own domain-specific little languages embedded in the language itself" -- it would, IMHO, impair Python's wonderful usefulness for application programming, by presenting an "attractive nuisance" to the would-be tinkerer who lurks in every programmer's heart...). Alex From hancock at anansispaceworks.com Fri Aug 1 02:10:13 2003 From: hancock at anansispaceworks.com (Terry Hancock) Date: Thu, 31 Jul 2003 23:10:13 -0700 Subject: Interfaces (a la PEP 245 and Zope) References: <78ednTw5QfxmebSiXTWJhA@august.net> Message-ID: Terry Hancock wrote: > if EditorAPI.isImplementedBy(self): > raise BrokenImplementation( > "Editor plugin '%s' fails implementation test." % > editor_core.title) > else: > self.__implements__ = EditorAPI Whoops. This should of course, be negated: if not EditorAPI.isImplementedBy(self): ... and the code is obviously not tested yet. Cheers, Terry -- Terry Hancock Anansi Spaceworks http://www.AnansiSpaceworks.com/ From tchur at optushome.com.au Thu Aug 14 18:16:34 2003 From: tchur at optushome.com.au (Tim Churches) Date: 15 Aug 2003 08:16:34 +1000 Subject: Python for medicine In-Reply-To: References: Message-ID: <1060899394.3189.141.camel@emilio> On Thu, 2003-08-14 at 23:45, ddoc wrote: > Python, as Zope, underlies some candidate medical record systems. > > Python is also the programming language for at least one system - GNUMed > from Australia. GNUmed is an international effort, with over half the active developers from Australia, and over half the active developers from Germany, and contributions from around the world, although Australians are prominent in teh ranks. You can find lists of other open source health and medical projects here http://www.linuxmednews.com/linuxmednews/LMNProjects/Projects/folder_contents and here http://www.minoru-development.com/en/healthlinks.html (the latter list a bit out-of-date) - Python and Zope do indeed figure prominently, but not dominantly. M (also known as MUMPS) forms the basis of one very large health software system - Vista, used by the US Dept of Veterans Affairs to run their hospitals and clinics. PHP powers a number of Web-based systems, and there is one family physician system written in Tk/TCL. Java also figures prominently. So yes, Python has a significant presence in the open source health and medical software scene, but does not rule the roost by any means. Inthe proprietary health and medical software sector, I've not heard of Python being used anywhere - I'd be interested to learn of any instances. > But the specific slot I see Python as particularly suited to is as a > generic scripting language for use in (many) medical record and decision > assist systems. > > Currently there are a variety of these, and they tend to have individual > scripting languages or lack them altogether, partly because their origins > are in the dawn of time. > > There is a certain amount of work available on the Web on what could be > generic objects, such as the Arden Syntax, a way of defining the steps in > making a decision. > > Rendering such things into Python modules, and leaving it up to the > individual (proprietary or Open) system suppliers to make use of them and > provide the lower level piece that interfaces to the specific system in > question seems like a good way to go, to me. I suggest that you take this discussion to the openhealth mailing list, where a lot of very knowledgeable health and medical informatics people hang out - and some of them are Pythonistas. To join the list, send an e-mail to openhealth-list-request at minoru-development.com with "subscribe" as the subject. An archive of past messages is available at www.mail-archive.com -- Tim C PGP/GnuPG Key 1024D/EAF993D0 available from keyservers everywhere or at http://members.optushome.com.au/tchur/pubkey.asc Key fingerprint = 8C22 BF76 33BA B3B5 1D5B EB37 7891 46A9 EAF9 93D0 -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 196 bytes Desc: This is a digitally signed message part URL: From mertz at gnosis.cx Tue Aug 19 21:41:51 2003 From: mertz at gnosis.cx (David Mertz) Date: Tue, 19 Aug 2003 21:41:51 -0400 Subject: What's better about Ruby than Python? References: Message-ID: Alexander Schmolck wrote previously: |Anyway, I still don't see a compelling reason why class statements |couldn't/shouldn't be mutating, rather than rebinding. Is there one? I don't think there is any reason why the statement 'class' COULD NOT do what you describe. But doing so seems much less Pythonic to me. In Python, there are a bunch of statements or patterns that ALWAYS and ONLY binds names. Having something that sometimes binds names, and other times mutates objects... and you cannot tell the difference without finding something that may be far away in the code.... well, that's not how Pythonistas like to think about code. In the first appendix to my book ( for the free version) I make quite a point of explaining what Python does without the sort of "convenient fiction" that most intros/summaries use. That is, usually the difference between binding a name and assigning a value is sort of brushed over, I guess so previous C, Pascal, Perl, Basic, etc. programmers won't get freaked out. I know Alexander already knows this... but heck, why miss some self-aggrandizement? Yours, David... X-Shameless-Plug: Buy Text Processing in Python: http://tinyurl.com/jskh -- mertz@ _/_/_/_/_/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY:_/_/_/_/ v i gnosis _/_/ Postmodern Enterprises _/_/ s r .cx _/_/ MAKERS OF CHAOS.... _/_/ i u _/_/_/_/_/ LOOK FOR IT IN A NEIGHBORHOOD NEAR YOU_/_/_/_/_/ g s From yiyang at wharton.upenn.edu Thu Aug 14 02:14:16 2003 From: yiyang at wharton.upenn.edu (Catherine Yang) Date: Thu, 14 Aug 2003 02:14:16 -0400 Subject: Thanks a lot! References: Message-ID: Wow, you guys are really fast and very helpful. Thanks !!!!!!! Catherine From altis at semi-retired.com Fri Aug 1 11:49:29 2003 From: altis at semi-retired.com (Kevin Altis) Date: Fri, 1 Aug 2003 08:49:29 -0700 Subject: update eclipse plugin, work in progress? References: Message-ID: Please see the wiki page for the active projects. http://www.python.org/cgi-bin/moinmoin/EclipsePythonIntegration ka "Raaijmakers, Vincent (IndSys, GE Interlogix)" wrote in message news:mailman.1059742743.26743.python-list at python.org... Does anyone know if work is in progress to update the python plugin for eclipse? www.eclipse.org The features of the current plugin is weak compared to the features of for example java. My background from the VA environment for Java and Smalltalk makes me hungry in getting the same strong IDE for Python. Don't mind looking at ways to expand this Python plugin, if possible and if time, but definitely don't have the time to reinvent the wheel. Please feedback. Vincent From danbmil99 at yahoo.com Sat Aug 9 01:05:10 2003 From: danbmil99 at yahoo.com (dan) Date: 8 Aug 2003 22:05:10 -0700 Subject: Slogan: Getting Rich Overnight References: Message-ID: Great post! Yes, I felt the same way when I first saw the language. It's funny because I had a company and we bought a company, and they said they were using Python as their scripting language, but we had to close that division and I never really saw it. Then much later, I had a project that needed something with a clear syntax, more like english than C++. I fiddled with Python and fell in love. I haven't felt this way since I learned Basic in 7th grade (I know Basic sucks now, but then there was nothing else), or when I did my first assembly programming, or fiddled with Lisp and Forth. I never felt that way with C/C++, I have always felt like I was climbing uphill. When I first saw the indentation-critical, bracket-less syntax, it was like "Oh my god, how many years have I wasted trying to see where the braces correspond?" Many years ago I had an idea for a similar syntax, but I never pursued it. Now I don't have to, it is right there for me! This may sound silly, but since using Python, I have felt this wierd sense of liberation -- like my decision to become a programmer finally has meaning. I work for 2 or 3 hours, and I have coded so much I have to stop and think... With the typical strictly-typed langs popular in the last 15 years, I never feel productive. I am at war with the compiler, the linker, the libraries... it's a fight from beginning to end. I have many friends whose brains must be wired differently. They love the feeling of control a tough compiler gives them... they believe the compiler should do all the work for them. I am just different... I have always loved dynamic languages. I just want a thing to be whatever I want, and if I change my mind, I don't want to *necessarily* have to make new prototypes, new header files.. I just want to stick something else in that container, even though I never thought I would, and I never warned anyone. It's just -- well, it's freedom to code your own way. It's the antidote to code rage. Just my thoughts, late at night... Keep up the good work!! Christian Tismer wrote in message news:... > Dear friends. > > During a conversation with good friends and newly acquired > Pythonista, we were discussing Python, what it is in essence, > and what it is giving to us. > > The people were Dinu Gherman, Giorgio Giacomazzi, > a promizing newcomer in the Python noosphere, and myself. > > We were discussing how to advertize for Python, and Dinu > spread some of the recent library enhancements, like > > - email package > - XML parsers > - distutils > - add lots of other great stuff, here. > > Then, after a while of silence, Giorgio said something like > """ > Well, right. > But despite of the libraries, I was hit by pure Python, > by the following, simply by using it interactively: > > There are these lists, these tuples, and these dicts. > They are immediately there, at my fingertips. And this is > a feeling that I never had, before. Especially these dicts > are incredible. > > This was a feeling like 'getting rich overnight'. > """ > > I loved this statement very much, and I have to say, this > is essentially my feeling for myself, since many years now. > I could imagine that this might be a candidate for next year's > Python congress' slogan. "Python makes you rich, overnight". > Not by money, in the first place, but by multiplying your > own capabilities, immediately. > > It needed the fresh experience of a newcomer to become aware > of this, again. > > The ambiguity is obvious. On first reading, it will attract > many. On second reading, those who are thinking "ahh, ohh, yes, > not I understand" will remain. But that's ok for a good slogan! > > got rich overnight by Python! > > being rich since 1800 nights now - sincerely -- chris From mis6 at pitt.edu Sun Aug 3 15:41:03 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 3 Aug 2003 12:41:03 -0700 Subject: Beginner's popups in vanilla Python program References: Message-ID: <2259b0e2.0308031141.176a3322@posting.google.com> Art wrote in message news:... > NEWBIE ALERT! > Does this help? >>> from tkMessageBox import askyesno >>> help(askyesno) Help on function askyesno in module __main__: askyesno(title=None, message=None, **options) Ask a question; return true if the answer is yes This is standard Tkinter, no need to dowload anything and plenty of available documentation. See for instance http://www.pythonware.com/library/tkinter/introduction/index.htm Michele From kwkikrick at freemail.nl Fri Aug 22 11:01:41 2003 From: kwkikrick at freemail.nl (KwikRick) Date: Fri, 22 Aug 2003 15:01:41 GMT Subject: question: reading character for character from stdin Message-ID: <3F46311A.2090707@freemail.nl> Is there a simple way to read from stdin without having to wait for an enter keypress, i.e. like getch() in the curses module. I'd rather not use curses because it isn't supported on all platforms. Rick From nika at kassube.de Fri Aug 22 10:14:12 2003 From: nika at kassube.de (Nils Kassube) Date: Fri, 22 Aug 2003 16:14:12 +0200 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: <240b1020.0308201722.d1b991c@posting.google.com> <81smnteu60.fsf@darwin.lan.kassube.de> Message-ID: <81ada1eq4r.fsf@darwin.lan.kassube.de> Roy Smith writes: > I suppose this is nice, but does it really give you anything you > couldn't get in a slightly different way by just enclosing the whole try > construct in a loop? You are correct. The exception handling in Python is as powerful as in Ruby. However, Ruby's way seems more beautiful to me. Another example: in Python you have to nest multiple try/except statements, in Ruby you can have multiple rescue blocks. It just looks better. (For my eyes.) From vanevery at 3DProgrammer.com Tue Aug 12 05:02:08 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Tue, 12 Aug 2003 02:02:08 -0700 Subject: Python vs. C# References: <3F378923.4080806@mxm.dk> Message-ID: Doug Tolton wrote: > On Mon, 11 Aug 2003 14:16:35 +0200, Max M wrote: > >> Bob Gailer wrote: >> >>> What is "trolling"? > > Ugh...he got me. If "he" means me, I am not a troll. A troll is someone who doesn't believe what he writes, and writes it solely to provoke. I believe what I write, and I'm not writing to provoke, but to discuss and to warn. I have coined the words "trollhunt" and "trollhunter." Compare "witch hunt" and "witch hunter." A trollhunter is a person who, faced with opinions counter to his own, takes the intellectually lazy way out of calling the opponent a troll. A trollhunt is many snivelling trollhunters banding together to shut down dissenting viewpoints. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From rparnes at megalink.net Fri Aug 22 18:31:29 2003 From: rparnes at megalink.net (Bob Parnes) Date: Fri, 22 Aug 2003 22:31:29 -0000 Subject: wxPython: need return value from wxFrame References: Message-ID: On Fri, 22 Aug 2003 21:27:13 +0200, Mirko Koenig wrote: > On Fri, 22 Aug 2003 00:28:23 +0200, Cliff Wells wrote: > >> On Thu, 2003-08-21 at 15:17, Mirko Koenig wrote: >>> I have a frame where you can select/add/delte etc a customer address. >>> It is included in an wxApp to have a stand alone customer addressbook. >>> >>> Now i wrote a invoice application. I added a button to add a address to >>> the invoice. I want the customer addressbook to be open by clicking on >>> that button. No problem. So far so good. >>> >>> But i want the addressbook frame to return the selected address as a >>> tuple, list or dict. I don't have any idea how to do that. >>> >>> I can show() the frame from within the invoice code but show doesn't >>> return a value. >> >> Use a wxDialog instead. >> > > But how to return a list or tuple. All i can see is that a dialog returns > a int value > > Mirko Koenig The dialog returns an integer depending upon which button the user presses to close it. But you can still access the setting in a widget after the dialog closes. -- Bob Parnes rparnes at megalink.net From ramiak2000 at yahoo.com Sat Aug 16 02:54:09 2003 From: ramiak2000 at yahoo.com (Rami A. Kishek) Date: Sat, 16 Aug 2003 02:54:09 -0400 Subject: PythonPath not working with 2.2.3 on Win ME Message-ID: <3F3DD511.E8319F23@yahoo.com> Hi, I would really appreciate help on this from all ye Win-oriented people. I have been using python under Linux for quite a while, know little about windows. I just upgraded my Python on WinME machine from Python 1.5.2 to 2.2.3 (in a separate directory). Using the Pythowin Pythonpath browser, I edited the python path to add my scripts directories. Then I tried to import my scripts and they're not visible. I tried many things: - exiting and restarting pythonwin - rebooting windows - editing Pythonpath from the registry using regedit (under HKEY_LOCAL_MACHINE, software, python2.2) Each and every time however, when I start python, import sys, then check sys.path, the path I get does not reflect the changes I made, and of course, as a result my own scripts don't work (they try to import each other). I also checked sys.path from IDLE and from the command line, and still get the same problem. The really strange thing is: the pythonpath in the Pythonwin Browser and the registry (which are the same) have really nothing to do with the path I get by checking sys.path! Not even the built-in directories are the same. My order of installation was (all using exe binaries) Python 2.2.3 Numpy 22.0 (win32) win32all-154 Py2exe 0.4.1 (win32) Does anyone here have the faintest clue about what's wrong? I checked the FAQs and searched this newsgroup and websites, but there's very little about PYTHONPATH. THanks ... From raims at dot.com Thu Aug 21 10:35:37 2003 From: raims at dot.com (Lawrence Oluyede) Date: Thu, 21 Aug 2003 16:35:37 +0200 Subject: max length of a python program References: <1ed07caf.0308210513.6556978a@posting.google.com> Message-ID: Ragu wrote: > Is there a limit to the # of lines that can be in a Python program? No AFAIK. The only limitation is the common sense, nobody wants to drown into comments :) -- Lawrence "Rhymes" Oluyede http://loluyede.blogspot.com rhymes at NOSPAMmyself.com From vanevery at 3DProgrammer.com Tue Aug 12 15:19:55 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Tue, 12 Aug 2003 12:19:55 -0700 Subject: Python should try to displace Java References: <7pchjvkldv6li5n80p5ra6n33sa6ainut4@4ax.com> Message-ID: Doug Tolton wrote: > On Tue, 12 Aug 2003 01:54:12 -0700, "Brandon J. Van Every" > wrote: > >> Doug Tolton wrote: >>> On Mon, 11 Aug 2003 18:43:08 -0700, "Brandon J. Van Every" >>>> >>>> - in 5 years, nobody will be doing significant amounts of new >>>> application development in C++. The writing is on the wall: >>>> garbage collection is essential. Any C++ code will be support and >>>> legacy libraries. >>> >>> That's a ridiculous blanket statement. People will be doing C++ >>> development for a long time beyond that. There are people still >>> writing Cobol for crying out loud. >> >> Do you honestly believe that people are doing a significant amount >> of new application development in Cobol, as opposed to maintenance >> work? > > Apparently MS does, they were promoting Cobol.net pretty heavily not > too long ago. That's a migration strategy, not new application development. > How are they going to crush Mozilla, Chimera or Khtml? You keep > touting Mindshare. Whose mindshare is growing MS or Open Source? If > you can't answer that honestly then you really are trolling. The only people who care about those are open source hackers. The mainstream doesn't even know what they are. >>> That's a bold statement, considering the abysmal adoption rate of >>> C#. >> >> Within Microsoft, the adoption of C# is universal. That tends to >> have a powerful effect on ISV Windows development over time. > > Really, who cares what MS does? I see. So when confronted with data that contradicts your Python world view, you change from "that's not true" to "who cares?" Contemplate it later, when you've gotten over your first moments of denial. > How does MS using C# affect Python? > You have yet to establish any kind of Causal connection. > > Here it is straight, Python has been around going strong for over 10 > years now, inspite of lack of a corporate pimp. Why is that? Because Python has been a niche. If you are content to stay in a niche, fine. In that sense Python will always survive. Lisp is similarly used by academics, hobbyists, and cranks. If you want to grow out of the niche, achieve mainstream industry relevance, and maintain it, then you're going to have to market yourself against the likes of C# and Java. Engineering merit does *not* win as you attempt to scale up. > I could be wrong but I didn't think OpenGL was open source. If it > isn't, your argument isn't really a good point then. It's an open standard, not open source. That said, I'm pretty sure the OpenGL Sample Implementation is now open source. And the Mesa workalike is definitely open source, although I don't know why anyone cares about SW rendering anymore. >> Why can MS catch up? Because Open Source people assume their >> technological superiority and rest on their laurels. They think >> they don't have to market because they are technically superior. >> Also, their ranks are populated with strong engineers who don't >> *like* marketing, as a matter of basic personality. They never get >> it in their heads that they have to counter-market to some degree in >> order to hold the line. If you don't do any marketing, Microsoft >> completely out-markets you and then you die, technical merit or not. > > Hmm...interesting point. Too bad there is simply no factual basis for > it. If Microsoft completely out markets everyone and they die, why > are there still so many Unix machines around? The only thing that has > made any headway against the Unix establishment is Linux. Linux *is* marketed, unlike Python. Meditate on that, Grasshopper. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From abuseonly at sgrail.org Fri Aug 22 20:53:36 2003 From: abuseonly at sgrail.org (derek / nul) Date: Sat, 23 Aug 2003 00:53:36 GMT Subject: Newbie problem with codecs References: <1R01b.1724$Ej6.454@newsread4.news.pas.earthlink.net> Message-ID: On Fri, 22 Aug 2003 17:10:40 GMT, "Mike Brown" wrote: >"derek / nul" wrote in message >> The print fails (as expected) with a non printing char '\ufeff' which is >of >> course the BOM. >> Is there a nice way to strip off the BOM? > >"derek / nul" wrote: >> I need a pointer to converting utf-16-le to text > >If there is a BOM, then it is not UTF-16LE; it is UTF-16. This paragraph is from http://www.egenix.com/files/python/unicode-proposal.txt It explains the difference between utf-16-le and utf-16-be Standard Codecs: ---------------- Standard codecs should live inside an encodings/ package directory in the Standard Python Code Library. The __init__.py file of that directory should include a Codec Lookup compatible search function implementing a lazy module based codec lookup. Python should provide a few standard codecs for the most relevant encodings, e.g. 'utf-8': 8-bit variable length encoding 'utf-16': 16-bit variable length encoding (little/big endian) 'utf-16-le': utf-16 but explicitly little endian 'utf-16-be': utf-16 but explicitly big endian 'ascii': 7-bit ASCII codepage 'iso-8859-1': ISO 8859-1 (Latin 1) codepage 'unicode-escape': See Unicode Constructors for a definition 'raw-unicode-escape': See Unicode Constructors for a definition 'native': Dump of the Internal Format used by Python Common aliases should also be provided per default, e.g. 'latin-1' for 'iso-8859-1'. Note: 'utf-16' should be implemented by using and requiring byte order marks (BOM) for file input/output. All other encodings such as the CJK ones to support Asian scripts should be implemented in separate packages which do not get included in the core Python distribution and are not a part of this proposal. From siegfried.gonzi at kfunigraz.ac.at Mon Aug 4 07:57:10 2003 From: siegfried.gonzi at kfunigraz.ac.at (Siegfried Gonzi) Date: 4 Aug 2003 11:57:10 GMT Subject: Python speed vs csharp References: <1h5f2rzthqgid.8watonaa4cjt.dlg@40tude.net> <3F551D29.1040407@kfunigraz.ac.at> <0MoXa.21930$cl3.850221@news2.tin.it> <3F55B1CE.5010607@kfunigraz.ac.at> Message-ID: <3F55D7F1.5020804@kfunigraz.ac.at> Alex Martelli wrote: > If true, this suggests unbelievably bad performance in your Celeron's > floating-point hardware -- there's no other explanation as to why > (software-implemented) rational arithmetic could outperform (hardware- > implemented) float arithmetic. Sorry I know that the Celeron is very poor at floating point calculations. My stationary Pentium II 450 Mhz at my university is as fast as my 1000 MHz Celeron. So what and who cares? > Particularly given that the Python-specific "techniques" amount (in all) > to using a good optimizer (aka just-in-time compiler), psyco, I'm quite > confident that many people can indeed use that. The idea of writing > x*x instead of pow(x, 2.0) is just as good in C (as I've shown -- just > that one change speeds up the C program by about two times) or Fortran > (as I mentioned, it was for Fortran, over a quarter of a century ago, > that I first learned of it) as just about any other language, so it's > no doubt going to be even more widely applicable. Maybe you cannot read. But I wrote in my first post that I blindly "copy and pasted" the original code and that I didn't check wehter (* x x) is faster. This was not the point. Again, my intention simply was: there is more than just Python. People, if their time budget allows it, should investigate those alternatives. If they think Scheme is shit oh Lord nobody cares and nobody will impede them in going/comming back to Python. Sorry, Alex you are one of the idiots and bigots who believe that Python is the best since sliced bred and butter. When I was younger it happend that I was a similar idiot and believed that "functional programming" in all its glory will salvage this world. For me Python is crap and not any longer worth to consider. But look, I even introduced Python at our institution some month ago. A colleague asked me and I showed him Scheme. He didn't like the parantheses and I adviced him to buy some Python books. Indeed he did it. What is important here: he is happy that I am not any of this idiots who falls for and believes that his own programming language is the best thing. I will stop this discussion because I am used to discuss with people who can demonstrate to have at least a minimal amount of brain. S. Gonzi From brian at sweetapp.com Tue Aug 12 21:02:02 2003 From: brian at sweetapp.com (Brian Quinlan) Date: Tue, 12 Aug 2003 18:02:02 -0700 Subject: Python vs. C# In-Reply-To: Message-ID: <000d01c36136$8170afc0$21795418@dell1700> > Compiler checking is a kind of test that is done for you all the time, > without you having to reimplement it over and over again. The design of the .NET framework minimizes the utility of static type checking by using the object class all over the place. When you wish to use an instance of class object you must cast it into an appropriate type. The validity of the cast is determined at runtime. Almost all of the collection classes, for example, deal in "object"s. > I agree that people should write tests, but having written many, many > of those for my own project, it is equally true that writing test > cases slows down development. I think that depends on how efficient you are at writing tests. Python offers a great testing framework to help you. > Anything that provides testing "for free" is a boon. It is not free. You are accepting several limitations (e.g. object must conform to a particular interface to be useable, all types must be specified) to get a type of checking that is of questionable value. > Big projects are filled with the bell curve. Not to mention stress under > deadlines, which ruins the code of even good programmers. Cheers, Brian From ramiak2000 at yahoo.com Tue Aug 19 02:34:05 2003 From: ramiak2000 at yahoo.com (Rami A. Kishek) Date: Tue, 19 Aug 2003 02:34:05 -0400 Subject: Serious problem with Shelve References: <3F3FB5B9.5E49B306@yahoo.com> <3F41BC50.91097FAF@yahoo.com> Message-ID: <3F41C4DD.356912A4@yahoo.com> Actually, I take my last message back - it is not so simple. After surfing the anydbm.py and whichdb.py, I ended up commenting out lines 97/98 of the latter: # if magic in (0x00061561, 0x61150600): # return "bsddb185" since I know that I did not install the old bsddb185 with the Python 2.3, and am supposed to have new BSD libraries. Instead, shelve gave me this error when I tried creating new files and reopening them. Something is very funny here and I really hope the python 2.3 developers would pay attention here. If 2.3 was shipped with the bsddb 1.85 disabled, then why is it complaining about the db (created with 2.3) being a bsddb185? File "D:\PROGRAMS\PYTHON23\lib\shelve.py", line 231, in open return DbfilenameShelf(filename, flag, protocol, writeback, binary) File "D:\PROGRAMS\PYTHON23\lib\shelve.py", line 212, in __init__ Shelf.__init__(self, anydbm.open(filename, flag), protocol, writeback, binary) File "D:\PROGRAMS\PYTHON23\lib\anydbm.py", line 80, in open raise error, "db type could not be determined" error: db type could not be determined Incidentally, on the other machine I mentioned (the one on which shelve worked perfectly with 2.2.3) shelve still works perfectly after upgrading to 2.3. Since that is a Linux 2 machine, I figure perhaps it is using a different db like gdbm or something ... "Rami A. Kishek" wrote: > > Well - I installed Python 2.3, but it still doesn't. My program now > crashes on the first pass. After deleting the old databases and > creating new ones, I opened them for read and this is what I get: > > self.revs = shelve.open(os.path.join(tgtdir, dbfn)) > File "D:\PROGRAMS\PYTHON23\lib\shelve.py", line 231, in open > return DbfilenameShelf(filename, flag, protocol, writeback, binary) > File "D:\PROGRAMS\PYTHON23\lib\shelve.py", line 212, in __init__ > Shelf.__init__(self, anydbm.open(filename, flag), protocol, > writeback, binary) > File "D:\PROGRAMS\PYTHON23\lib\anydbm.py", line 82, in open > mod = __import__(result) > ImportError: No module named bsddb185 > > I will try enclosing that import bsddb185 in anydbm.py in try: except:, > though I hate messing around with source files, and there may be many > more such problems. Python developers, be aware of this glitch. > From sanjiv at leopardlogic.com Thu Aug 7 14:59:40 2003 From: sanjiv at leopardlogic.com (Sanjiv Kumar) Date: Thu, 7 Aug 2003 11:59:40 -0700 Subject: python-2.3 Checksum Error Message-ID: <009301c35d16$1a3ee8e0$4901a8c0@beastjr> Hi All, I need to install python-2.3 on solaris machine using gcc version 2.95.2 . I dowloaded the file "Python-2.3.tgz" file from www.python.org . This tar file gives checksum error during untar. Here are the steps I have followed. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ % gunzip Python-2.3.tgz % tar xvf Python-2.3.tar : : x Python-2.3/Mac/OSXResources/app/Resources/English.lproj/Documentation/doc/index.html, 882 bytes, 2 tape blocks x Python-2.3/Mac/OSXResources/app/Resources/English.lproj/Documentation/ide, 0 bytes, 0 tape blocks x Python-2.3/Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/index.html, 9909 bytes, 20 tape blocks x Python-2.3/Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/IDE.gif, 10249 bytes, 21 tape blocks tar: directory checksum error ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ I tried to download same version of python from both ftp and http site. But problem persist. Here are few question. #1 Where can I find the Python-2.3.tgz without above problem? #2 Could i install version 2.3 using my gcc compiler (version 2.95.2) ? I remember that I tired in past to build another version of python and it use to give segmentation fault during "running build_extension". Did anyone try to build python-2.3 with gcc version 2.95.2. I would really appreciate your response as earliest. Best Regards, =Sanjiv= -------------- next part -------------- An HTML attachment was scrubbed... URL: From postmaster.a.reuters.lon at reuters.net Mon Aug 25 21:16:03 2003 From: postmaster.a.reuters.lon at reuters.net (postmaster.a.reuters.lon at reuters.net) Date: Tue, 26 Aug 2003 01:16:03 +0000 (GMT) Subject: Non-Delivery Notification Message-ID: <01KZWE0PPJYM00KWG8@FMG1> Your message could not be delivered. MICHAEL.BATTYE.REUTERS.COM at REUTERS.NET - Invalid user name or user not permissioned Content-type: multipart/mixed; boundary="_NextPart_000_00223216" Date: Tue, 26 Aug 2003 08:28:36 +0800 From: python-list at python.org Importance: Normal Message-id: <200308260026.AAA29750 at relay3.reuters.net> MIME-version: 1.0 Received: from dtc-nsfw41aqfe1 ([196.1.58.18]) by FMG1 (PMDF V5.1-10 #D3161) with SMTP id <01KZWDYQAMM800ODVG at FMG1> for michael.battye.reuters.com at reuters.net; Tue, 26 Aug 2003 01:15:14 GMT Received: from relay.reuters.net by dtc-nsfw41aqfe1 via smtpd (for fmg.reuters.net [172.18.5.5]) with SMTP; Tue, 26 Aug 2003 00:43:41 +0000 (UT) Received: from dtc-nsfw41aqfe2 (localhost [127.0.0.1]) by relay3.reuters.net (8.9.3/8.9.3/ CTG Messaging-$Name: ReutersFMG-Relay-release_2_5k_20000327_matt $/Relay3/ matt) with SMTP id AAA29750 for ; Tue, 26 Aug 2003 00:26:57 +0000 (GMT) Received: from cm58.gamma148.maxonline.com.sg ([202.156.148.58]) by dtc-nsfw41aqfe2 via smtpd (for relay.reuters.net [172.18.5.50]) with SMTP; Tue, 26 Aug 2003 00:42:46 +0000 (UT) Subject: Re: Re: My details To: michael.battye.reuters.com at reuters.net X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MailScanner: Found to be clean X-MSMail-Priority: Normal This is a multipart message in MIME format --_NextPart_000_00223216 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit ****************** InterScan Message (on relay3.reuters.net) Found virus WORM_SOBIG.F in file document_9446.pif The file is deleted. ********************************************************* --_NextPart_000_00223216 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit See the attached file for details --_NextPart_000_00223216 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit ****************** InterScan Message (on relay3.reuters.net) document_9446.pif is removed from here because it contains virus. ********************************************************* --_NextPart_000_00223216-- -- "This message is brought to you by Reuters.net; Any views expressed are those of the sender, except where the sender specifically states them to be the views of Reuters Limited." -- "This message is brought to you by Reuters.net; Any views expressed are those of the sender, except where the sender specifically states them to be the views of Reuters Limited." From jacek.generowicz at cern.ch Fri Aug 22 03:24:12 2003 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 22 Aug 2003 09:24:12 +0200 Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> <6dj2kv8ugkieehs7guh786cl40o5lj6mcs@4ax.com> <3F455BF0.5070700@nyc.rr.com> Message-ID: "Andrew Dalke" writes: > Kenny Tilton: > > as when we go for the > > productivity win of untyped variables and give up on bugs strong static > > typing is supposed to find. > > You do realize that strong typing and static typing are different > things? Note that Kenny said "untyped _variables_" not "untyped objects" or "untyped language". > What does (the lisp equivalent of) 2.5 + "a" do? Common Lisp complains that "a" is not a number. > In Python, a strongly typed language, it raises an exception. Common Lisp is strongly and dynamically typed, just like Python ... although CL does allow type declarations, for optimization purposes. From mal at lemburg.com Mon Aug 11 08:07:24 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon, 11 Aug 2003 14:07:24 +0200 Subject: dist problem on osx In-Reply-To: <644f6688.0308101518.ad9e02a@posting.google.com> References: <644f6688.0308101518.ad9e02a@posting.google.com> Message-ID: <3F3786FC.5020703@lemburg.com> rdack wrote: > osx 10.2.6 python 2.2.1 (built in) > says my architecture is both 386 and ppc. > also has a path with a space in it that won't work. > where can i change these settings? > -------- > gcc -arch i386 -arch ppc -bundle -flat_namespace -undefined suppress > build/temp.darwin-6.6-Power > Macintosh-2.2/mx/DateTime/mxDateTime/mxDateTime/mxDateTime.o > -L/usr/local/lib -L/usr/lib -o build/lib.darwin-6.6-Power > Macintosh-2.2/mx/DateTime/mxDateTime/mxDateTime.so > --------------- This is a bug in distutils. It's fixed in Python 2.2.3. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 11 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From skip at pobox.com Tue Aug 19 17:41:01 2003 From: skip at pobox.com (Skip Montanaro) Date: Tue, 19 Aug 2003 16:41:01 -0500 Subject: Why does this (not) work? In-Reply-To: References: Message-ID: <16194.39277.920636.140954@montanaro.dyndns.org> Michael> But I want to use the * to make life easier to read, so I tried: >>>> ("test",)*3 Michael> ('test', 'test', 'test') >>>> "%s - %s - %s" % ("test",)*3 Michael> Traceback (most recent call last): Michael> File "", line 1, in ? Michael> TypeError: not enough arguments for format string >>>> That's because the % and * operators have the same precendence and group left-to-right. The above expression is equivalent to ("%s - %s - %s" % ("test",))*3 To force the * operation to be evaluated first you need to add some parens: ("%s - %s - %s" % (("test",))*3) which works as expected: >>> "%s - %s - %s" % (("test",)*3) 'test - test - test' If you're worried about readability of large format operations, I suggest you consider using dictionary expansion, e.g.: >>> "%(var)s - %(var)s - %(var)s" % {"var": "test"} 'test - test - test' or more commonly: >>> var = "test" >>> "%(var)s - %(var)s - %(var)s" % locals() 'test - test - test' Skip From dkuhlman at rexx.com Mon Aug 18 15:21:47 2003 From: dkuhlman at rexx.com (Dave Kuhlman) Date: Mon, 18 Aug 2003 12:21:47 -0700 Subject: python & postgresql ? References: Message-ID: GuineaPig wrote: [snip] > I've looked into pyPgSQL too, and this works fine under windows, > but I cannot get this to run on my linux-machine (suse 8.2). What problems are you having. I'm using pyPgSQL-2.3 on Debian GNU/Linux and it seems to work fine, though I'll admit that my usage does not stress it heavily. I found that I had to make the following changes to setup.py: ====================================================== --- setup.py 2002-12-01 10:31:00.000000000 -0800 +++ setup_new.py 2003-06-11 16:13:40.000000000 -0700 @@ -80,7 +80,8 @@ def main(): # Set this to 1 if you need to use your own settings - USE_CUSTOM = 0 + USE_CUSTOM = 1 # Default settings, may be overriden for specific platforms pypgsql_rt_dirs = None @@ -96,8 +97,10 @@ "port/strtok.c"] if USE_CUSTOM: - include_dirs = YOUR_LIST_HERE - library_dirs = YOUR_LIST_HERE + include_dirs = [ "/w2/Postgresql/postgresql-7.3.3/src/include", + "/w2/Postgresql/postgresql-7.3.3/src/interfaces/libpq/" ] + library_dirs = [ "/usr/local/pgsql/lib" ] elif sys.platform == "linux2": include_dirs = ["/usr/include", "/usr/include/postgresql", "/usr/include/pgsql"] @@ -164,6 +167,8 @@ name=modname, sources = sources, include_dirs = include_dirs, + define_macros = [('LONG_LONG', 'PY_LONG_LONG')], library_dirs = library_dirs, runtime_library_dirs = pypgsql_rt_dirs, libraries = optional_libs ====================================================== Dave [snip] -- Dave Kuhlman http://www.rexx.com/~dkuhlman dkuhlman at rexx.com From sross at connectmail.carleton.ca Tue Aug 26 09:54:04 2003 From: sross at connectmail.carleton.ca (Sean Ross) Date: Tue, 26 Aug 2003 09:54:04 -0400 Subject: Advice to a Junior in High School? References: Message-ID: > "Sean Ross" writes: > > > (Lisp, Dylan, Haskell, ocaml, or some other functional programming > > language). > > As an added bonus, studying many langugas reduces the chances of you > misclassifying them, as has been done above :-) Okay. "..., or some other language that supports functional programming style)" (which would include those mentioned, and many more besides). For instance, http://directory.google.com/Top/Computers/Programming/Languages/Functional/?tc=1 Aleph (1) BETA (8) Caml (2) Clean (6) Dylan (19) < Erlang (313) Haskell (48) < Leda (5) Lisp (378) < Logo (46) Lua (18) Mercury (4) Miranda (10) ML (35) Mozart (2) Objective Caml (5) < Pliant (16) POP-11 (6) REBOL (95) Scheme (127) Sisal (12) Whatever. Sean From tjland at iserv.net Thu Aug 21 21:37:59 2003 From: tjland at iserv.net (tjland at iserv.net) Date: Thu, 21 Aug 2003 21:37:59 -0400 (EDT) Subject: (no subject) Message-ID: <1125.68.73.70.2.1061516279.squirrel@webmail.iserv.net> When you see the net take the shot When you miss your shot shoot again When you make your shot you win! Just remember Offense sells tickets But defense wins championships! From tebeka at cs.bgu.ac.il Thu Aug 28 04:28:38 2003 From: tebeka at cs.bgu.ac.il (Miki Tebeka) Date: 28 Aug 2003 01:28:38 -0700 Subject: Comments on my "Python Introduction" slides References: <33803989.0308240000.35b9bf1f@posting.google.com> <33803989.0308240644.3090f039@posting.google.com> <3f492761$0$49117$e4fe514c@news.xs4all.nl> <33803989.0308260210.4c1e058@posting.google.com> Message-ID: <33803989.0308280028.714aa98c@posting.google.com> Hello Bryan, > don't forget None is also a False value. You're right. 10x. > i think this is a very power part of python and used a lot and helps reduce as lot of clutter you might see in other languages when > testing emptyness. all of these can be use in boolean expressions. i might help your "wow" factor to see them all listed. Yap. I'll do the lesswon with IDLE open so they can view this. 10x. Miki From aleax at aleax.it Fri Aug 29 04:40:01 2003 From: aleax at aleax.it (Alex Martelli) Date: Fri, 29 Aug 2003 08:40:01 GMT Subject: Add two dicts References: <86ktkvkd05e88hu14hjudmfvbul7slfgkt@4ax.com> <3F4EDF7A.C9CF6DA3@alcyone.com> <0mrtkv8b1bnnk1v310kf3b8tmjo8d9higo@4ax.com> Message-ID: Afanasiy wrote: > On Thu, 28 Aug 2003 22:07:06 -0700, Erik Max Francis > wrote: > >>Afanasiy wrote: >> >>> Can I add two dicts in a way which is not cumbersome to the above % >>> string >>> operation? Is this another case of writing my own function, or does a >>> builtin (or similar) already exist for this? >> >>combinedDict = aDict.copy() >>combinedDict.update(anotherDict) >> >>If that's cumbersome, don't really know what you'd consider >>non-cumbersome. > > Don't really know if you're asking, but : > > vars(self)+{'x':'123','y':'345'} > > I would consider that non-cumbersome. ;-) So, what about: def dict_add(adict, another): result = adict.copy() result.update(another) return result and then dict_add(vars(self), {'x':'123','y':'345'}) ? But in fact you can do even better...: def dad(_adict, _another={}, **_yetmore): result = _adict.copy() result.update(_another) result.update(_yetmore) return result or in 2.3: def dad(_adict, _another={}, **_yetmore): result = _adict.copy() result.update(dict(_another, **_yetmore)) return result and now, dad(vars(self), x='123', y='345') -- ain't that even LESS cumbersome? You can't do that with the syntax of + (no keyword arguments) Incidentally, in 2.3 you can ALSO spell your desired adict+anotherdict as dict(adict, **anotherdict) > My only guess why that doesn't exist is that no one decided what to do on > like keys. Use existing, overwrite, or throw exception (my preference). The semantics of all the existing ways of spelling dictionary addition and the like (update method, **kwds argument to dict in 2.3) have the second argument 'override' the first. A fast way to check that two dicts don't overlap (or perhaps more generally to get the list of the keys in which they do overlap) might be more generally useful, as well as allowing the diagnostics you want to be produced effectively. Still, as long as you're writing a function for the addition it's easy and fast to check for non-overlap: def dad(_adict, _another={}, **_yetmore): result = _adict.copy() result.update(dict(_another, **_yetmore)) if len(result)!=len(_adict)+len(_another)+len(_yetmore): raise ValueError, "Overlapping keys on dict addition" return result Alex From tim.one at comcast.net Wed Aug 6 14:13:27 2003 From: tim.one at comcast.net (Tim Peters) Date: Wed, 6 Aug 2003 14:13:27 -0400 Subject: FWD: Re: Problem w/ IDLE on Win2000 In-Reply-To: <1060189807.3f31366f342c4@mcherm.com> Message-ID: [Michael Chermside] > ... > I wish we'd caught this before 2.3. Have you confirmed that a problem exists? I haven't tried. If there is, it should have been caught: the release PEP makes clear that the Windows installer should be run with and without admin privs, and using targets with and without embedded spaces. It's my fault that this wasn't done -- there simply wasn't enough "spare time" to run the full course with this release, and I consumed all the time I could make for it intensely testing a single installation. Speaking of which, that doesn't look likely to change anytime soon, so if someone else is willing to take over the PLabs Windows installer, it's yours. Overall, it's in very good shape. Whoever is interested should also consider switching to InnoSetup (and there's a patch on SF moving closer toward that end). > Unfortunately, I usually avoid "Program Files" for exactly this reason, and > I'm guessing other testers did the same. Most people accept the defaults. "Program Files" is fine for an end-user app, but for a tool that's going to get used from scripts and command shells, a path with an embedded space is just begging for needless problems. For that reason, if IDLE does have a problem with embedded spaces, I really don't care. From jan.kesten at web.de Thu Aug 21 03:16:14 2003 From: jan.kesten at web.de (Jan) Date: 21 Aug 2003 00:16:14 -0700 Subject: Pyhthon 2.2 and Informix?! Message-ID: <8ab78660.0308202316.18aa4e61@posting.google.com> Hello, I have following question: is there any (free) possibility to connect to an informix database in pyhton 2.2 (here 2.2.2 on Solaris 2.5 sparc). I found some modules, but they are all written to pyhton 1.5.x - and if possible I would not like to downgrade. Thanks! Jan From adalke at mindspring.com Fri Aug 22 23:28:43 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Sat, 23 Aug 2003 03:28:43 GMT Subject: Sort a Dictionary References: Message-ID: Afanasiy: > Why wouldn't [ksort] be a standard function? Because it isn't needed all that often and can be built (when needed) from the underlying primitives very simply. Because if there are a lot of similar methods then it becomes harder to remember what each one does. The normal practice is keys = d.keys() keys.sort() for k in keys: .... which isn't all that onerous. > How about this one? > > http://www.php.net/manual/en/function.asort.php The normal idiom for sorting by value then printing the key/value pairs is rev_items = [(v, k) for k, v in d.items()] rev_items.sort() for v, k in rev_items: print k, v If you want that as a function return just the keys in value order def asort(d): rev_items = [(v, k) for k, v in d.items()] rev_items.sort() return [k for (v, k) in rev_items] As you can see, there are many ways you might want to sort a dict. Why should all of them be present in the standard dict type when it's really a matter of two extra lines to get what you need. Seeing the code in this case is much easier than memorizing the 7 different sort functions mentioned in the PHP docs. Additionally, Python's keys can be more complex than a string or int. Eg, d = {} d[ (0,0) ] = "home" d[ (1,3) ] = "school" d[ (4,2) ] = "work" y_items = [(y, name) for ((x, y), name) in d.items()] y_items.sort() for y, name in y_items: print y, name sorts by y position, ignoring x position. PHP doesn't have a function for that, but it follows pretty naturally from the idiomatically Python way to do it. Andrew dalke at dalkescientific.com From mark.wondratschek at sap.com Fri Aug 29 09:34:58 2003 From: mark.wondratschek at sap.com (Mark Wondratschek) Date: Fri, 29 Aug 2003 15:34:58 +0200 Subject: Python zipfile: Zip empty directories. References: Message-ID: Thanks Peter, but this must be supported by the zip format ('cause winzip etc. does it this way). The empty-file idea was one of my reflections, too. But I'm sure there must be better ways... From vanevery at 3DProgrammer.com Mon Aug 18 17:52:38 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Mon, 18 Aug 2003 14:52:38 -0700 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: <3f412432$1_1@news.vo.lu> Message-ID: Patrick Useldinger wrote: > Brandon J. Van Every wrote: > >> What's ***TOTALLY COMPELLING*** about Ruby over Python? What makes >> you jump up in your chair and scream "Wow! Ruby has *that*? That >> is SO FRICKIN' COOL!!! ***MAN*** that would save me a buttload of >> work and make my life sooooo much easier!" > > The simple fact that *you* are not active on c.l.ruby? > A time-saver, certainly ;-) I wonder how large my c.l.p killfile is now? -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From dave at boost-consulting.com Sat Aug 23 17:17:30 2003 From: dave at boost-consulting.com (David Abrahams) Date: Sat, 23 Aug 2003 17:17:30 -0400 Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> Message-ID: "Neil Hodgson" writes: > David Abrahams: > >> BTW, the C++ preprocessor is a fairly weak macro system. A higher >> level metaprogramming facility that knows more about the underlying >> language could be a lot cleaner, clearer, safer, and more expressive. > > What do you think of OpenC++? > http://www.csg.is.titech.ac.jp/~chiba/openc++.html I think it's an interesting idea that hasn't been developed much in a long time. The Synopsis (http://synopsis.sf.net) guys have been maintaining their own fork just so they could process Boost code correctly - I like and use Synopsis Personally, I think GCC_XML has more promise than OC++ because the correctness and performance of its front-end is tied to a real compiler which sees a *lot* of use. -- Dave Abrahams Boost Consulting www.boost-consulting.com From aahz at pythoncraft.com Tue Aug 12 23:01:02 2003 From: aahz at pythoncraft.com (Aahz) Date: 12 Aug 2003 23:01:02 -0400 Subject: Python vs. C# References: <070hjvou8s33gvmom1t45t3avlkhudsstn@4ax.com> <934jjvkd3ss4c2lbcovjhnlaqqjjukq8jr@4ax.com> Message-ID: In article <934jjvkd3ss4c2lbcovjhnlaqqjjukq8jr at 4ax.com>, Doug Tolton wrote: >On 12 Aug 2003 10:42:21 -0400, aahz at pythoncraft.com (Aahz) wrote: >> >>Paul Graham was the keynote speak for PyCon DC 2003. > >This statement on Paul Graham's web site is what got me using Python: > > >I like Lisp but my company won't let me use it. What should I do? > >Try to get them to let you use Python. Often when your employer won't >let you use Lisp it's because (whatever the official reason) the guy >in charge of your department is afraid of the way Lisp source code >looks. Python looks like an ordinary dumb language, but semantically >it has a lot in common with Lisp, and has been getting closer to Lisp >over time. > Cool! There's one critical difference in the semantics of Python (lack of macros), but that's precisely to enforce the simplicity and clarity of Python's syntax. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From tchur at optushome.com.au Sat Aug 16 19:51:01 2003 From: tchur at optushome.com.au (Tim Churches) Date: 17 Aug 2003 09:51:01 +1000 Subject: Needs DB-API to connect to SQL Server 2000 In-Reply-To: <20030816.23383100.1745684727@linux.local> References: <20030816.23383100.1745684727@linux.local> Message-ID: <1061077861.1187.69.camel@emilio> On Sun, 2003-08-17 at 09:38, Thomas Chan wrote: > Does anyone know where I can find a DB-API to connect to SQL Server 2000? The MSSQL module by Dave Cole of Object Craft might meet your needs - see http://www.object-craft.com.au/projects/mssql/ -- Tim C PGP/GnuPG Key 1024D/EAF993D0 available from keyservers everywhere or at http://members.optushome.com.au/tchur/pubkey.asc Key fingerprint = 8C22 BF76 33BA B3B5 1D5B EB37 7891 46A9 EAF9 93D0 -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 196 bytes Desc: This is a digitally signed message part URL: From carroll at tjc.com Tue Aug 5 23:30:16 2003 From: carroll at tjc.com (carroll at tjc.com) Date: Tue, 05 Aug 2003 20:30:16 -0700 Subject: wxPython and Chinese characters in Unicode? Message-ID: <3ct0jvgcln2df5dv9g67c7kubah07adopa@4ax.com> Does wxPython handle Unicode strings (specifically, Unihan strings, with Chinese characters) easily? I'm writing an app to help me explore the Chinese character sets, and can do basic displays of the characters in Tkinter, but Tkinter looks daunting as I try to grow the app beyond a simple display. wxPython looks easier to use; but will it handle Chinese characters? From jjl at pobox.com Fri Aug 15 18:14:05 2003 From: jjl at pobox.com (John J. Lee) Date: 15 Aug 2003 23:14:05 +0100 Subject: Porting to Windows References: Message-ID: <878ypush5e.fsf@pobox.com> Zora Honey writes: [...] > difficult. There are some things (such as image manipulation using > ) it's probably pretty impossible to do using Windows system > calls. PIL. [...] > Other functions (such as printing) should be readily available. win32all. > Does anyone know a good resource for learning some of this stuff? The ORA book by Hammond and Robinson. MSDN. > Also, is there any way to compile Python without embedding it in C? OOH: py2exe, McMillan Installer. OTOH: Pyrex, psyco. John From jjl at pobox.com Sat Aug 16 07:05:29 2003 From: jjl at pobox.com (John J. Lee) Date: 16 Aug 2003 12:05:29 +0100 Subject: ClientCookie bug (followup) References: <87fzk4sav2.fsf@pobox.com> <87znibzrnx.fsf@pobox.com> <87oeypdh92.fsf@pobox.com> Message-ID: <87k79ddfra.fsf@pobox.com> jjl at pobox.com (John J. Lee) writes: [...] > > Traceback (most recent call last): > [...] > > whereas running it without delayload=1 causes it to run successfully. [...] I just uploaded a new version with this fixed and a username argument to load / load_from_registry (only needed for win9x). Let me know if it works or not: I don't have a networked Windows machine. John From mwh at python.net Thu Aug 14 08:51:50 2003 From: mwh at python.net (Michael Hudson) Date: Thu, 14 Aug 2003 12:51:50 GMT Subject: Is Python your only programming language? References: <3f38fbf3$0$158$a1866201@newsreader.visi.com> <2259b0e2.0308120912.53b28d6f@posting.google.com> Message-ID: <7h3wudg4d50.fsf@pc150.maths.bris.ac.uk> mis6 at pitt.edu (Michele Simionato) writes: > grante at visi.com (Grant Edwards) wrote in message news:<3f38fbf3$0$158$a1866201 at newsreader.visi.com>... > > > Anybody who thinks there's only one programming > > language for all tasks is seriously deluded. > > Yes, but a programmer does not necessarily need to perform ALL > tasks. It may very well be that Python fullfill 99% of what an > average programmer needs. I quite like the strategy of recommending Python for almost everything, and Common Lisp for what's left. Hmm, guess this doesn't cover the embedded niche... Cheers, mwh -- Also, remember to put the galaxy back when you've finished, or an angry mob of astronomers will come round and kneecap you with a small telescope for littering. -- Simon Tatham, ucam.chat, from Owen Dunn's review of the year From kfettig at state.nd.us Fri Aug 8 15:27:44 2003 From: kfettig at state.nd.us (Ken Fettig) Date: Fri, 8 Aug 2003 14:27:44 -0500 Subject: base64 module Message-ID: Hello, I am trying to make use of the base64 module but am having problems. >>> import base64 >>> decodestring('SVNBKjAwKiAgICAgICAgICAqMDAqICAgICAg') Traceback (most recent call last): File "", line 1, in ? decodestring('SVNBKjAwKiAgICAgICAgICAqMDAqICAgICAg') NameError: name 'decodestring' is not defined >>> What am I doing wrong. I am importing the base64 module, why can't I call the decodestring method? From abulka at netspace.net.au Mon Aug 18 01:02:12 2003 From: abulka at netspace.net.au (Andy Bulka) Date: 17 Aug 2003 22:02:12 -0700 Subject: 3 new slogans References: Message-ID: <13dc97b8.0308172102.5006b620@posting.google.com> I like the The Four Noble Truths of Python website http://www.pauahtun.org/4nobletruthsofpython.html which includes The origin of suffering lies in the use of not-Python. and others. -Andy Bulka http://www.atug.com/andypatterns From sdhyok at yahoo.com Sun Aug 10 15:25:24 2003 From: sdhyok at yahoo.com (sdhyok) Date: 10 Aug 2003 12:25:24 -0700 Subject: How to print floating point in scientific format? References: <420ced91.0308081115.7060e551@posting.google.com> <420ced91.0308090642.176b856b@posting.google.com> Message-ID: <420ced91.0308101125.3dee1bfe@posting.google.com> "Andrew Dalke" wrote in message news:... > Python gives complete control over you can represent numbers. > It just doesn't change the default representation. Users *can* > flexibly modify the printing format. > > I can't see why you would want to change it globally. That > just sounds wrong. Eg, I want my app to print the resolution > in Angstroms in the form "%3.2f" while I want the mass values > in "%3.1f". A global setting is a very clumsy way to change that. Andrew, I take your advice. To change the format of floating point globally may be too aggressive. But, still I think we need more elegant way to print out floating point arrays in python. What is your best way for my example? (I hope it is not for loop.) Daehyok Shin From tzot at sil-tec.gr Fri Aug 29 08:46:00 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Fri, 29 Aug 2003 15:46:00 +0300 Subject: Burn some books (please)... References: <3F4E4698.B8C84943@engcorp.com> Message-ID: <6oiukvg57bu4rhbkkh2b8slq608sq5u34l@4ax.com> On Thu, 28 Aug 2003 14:14:48 -0400, rumours say that Peter Hansen might have written: [David Mertz hilariously suggests that his latest book, along with Alex Martelli's one, are available for purchase and burning for religious and/or political reasons...] [Peter] >As a start, since I'm actually in need of my copies of both the >aforementioned tomes, I've printed out several copies of your >newsgroup posting (above), and some of Alex's, and have built >a small campfire in the pair-programming room to warm the >programmers as they code. Thank you. Well, you wouldn't have to build a campfire if you had reached Pair Programming level 2, AKA Quite Intimate Pair Programming :) -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From twomack at chiark.greenend.org.uk Mon Aug 18 02:17:15 2003 From: twomack at chiark.greenend.org.uk (Thomas Womack) Date: 18 Aug 2003 07:17:15 +0100 (BST) Subject: Loading a file into the interpreter Message-ID: I'd like, from the command line of the python interpreter, to get the effect of having typed in the contents of some text file; the sort of thing I'd expect a "load" command to do. I can do "python prog.py", but that doesn't leave me in the interpreter afterwards, and I'd often like to set some variables, load a program, and poke about to see what the variables look like afterwards. Tom From cnetzer at sonic.net Sat Aug 30 16:20:57 2003 From: cnetzer at sonic.net (Chad Netzer) Date: Sat, 30 Aug 2003 13:20:57 -0700 Subject: Are lists at least as efficient as dictionaries? In-Reply-To: <20030830070303.GA4892@intarweb.us> References: <781faf41.0308281604.51e48f45@posting.google.com> <20030829145423.GA30577@intarweb.us> <1062177877.1855.6.camel@adsl-209.204.179.133.sonic.net> <20030830070303.GA4892@intarweb.us> Message-ID: <1062274856.1875.30.camel@adsl-209.204.179.133.sonic.net> On Sat, 2003-08-30 at 00:03, Jp Calderone wrote: > But as you removed from my original post, list.extend() exists. All one > has to do to retain the existing functionality of __iadd__ is name the > method something else, then call it. All the advantages, none of the > confusing or difficult to track semantics. True, however when working with large Matrices, I much prefer A += B, to A.add(B), and the performance advantages with __iadd__ can be substantial. I prefer the original posters suggestion that self assignment be ignored. But I see your point about the more difficult semantics of __iadd__. -- Chad Netzer From cartermark46 at ukmail.com Fri Aug 15 05:34:23 2003 From: cartermark46 at ukmail.com (Mark Carter) Date: 15 Aug 2003 02:34:23 -0700 Subject: ClientCookie bug References: <87fzk4sav2.fsf@pobox.com> <87znibzrnx.fsf@pobox.com> Message-ID: > trying the getpass fix I suggested? I don't know if getpass.getuser > works on w9x, but it's worth a shot. On a win95 machine, running a fresh installation of python3.2, typing import getpass print getpass.getuser() returns ImportError: No module named pwd. I also tried getuid() - but that didn't work, either (it's in UNIX only). *Sigh* It appears that we are stuck with the workaround that I suggested. I'll try it on a win 98 machine, and report back the results asap. From aahz at pythoncraft.com Tue Aug 12 22:59:03 2003 From: aahz at pythoncraft.com (Aahz) Date: 12 Aug 2003 22:59:03 -0400 Subject: customizing and/or/not References: Message-ID: In article , Simon Burton wrote: > >Just reading about the new Sets... and this came up. >Why can't we customize the and/or/not operators? >I see this as making one's own boolean type. >Is it possible? Not directly, but you can use the arithmetic bit operators, just like sets do: __and__(), __or__(), and __invert__() -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From gregbrunet at NOSPAMsempersoft.com Fri Aug 22 14:16:02 2003 From: gregbrunet at NOSPAMsempersoft.com (Greg Brunet) Date: Fri, 22 Aug 2003 13:16:02 -0500 Subject: __getattr__ weirdness Message-ID: In adding the ability to refer to field values using dbfFile.field notation, I learned how to use __getattr__ and __setattr__ . After some trial and error, I got it working. But as part of my trials, I added some print statements to debug stuff. The ones I added to __setattr__ work as expected, but the one in __getattr__ seems to get called just under 1000 times for every __getattr__ call! Something is obviously not right here - but I'm at a loss to understand what's going on. I've pared down my code to still show it happening & included it below. If you run this program & pipe the output to a file, you'll get just under 14000 debug lines. Any ideas? Thanks! -- Greg # ---------------------------------------------------------------------- ---------- class test: """Introspection test""" #---------------------------------------- def __init__(self,filename): print '** __init__' self._filename=filename self._del=' ' self._dirty=False self._open=False self._rec=[] self._recno = 1 #---------------------------------------- def __getattr__(self, key): """ Return DBF record values by field name """ print "_ga: " + key try: return self._rec[self._fldNames.index(key.upper())] except: raise AttributeError("Unknown Field: %s" % ( key )) #---------------------------------------- def __setattr__(self, key, val): """ Update DBF record values by field name """ print "_sa: %s: %s" % (key, val) try: self._rec[self._fldNames.index(key.upper())] = val print " (DBF field assignment)" except: self.__dict__[key] = val # use the regular variable! #raise AttributeError("Unknown Field: %s" % ( key )) #---------------------------------------- #---------------------------------------- if __name__ == "__main__": f = test('test.dbf') f._del='*' f._recno=123 f._recno=1 f._recno=2 f._recno=3 f._recno=4 f._recno=5 f._recno=6 From tjreedy at udel.edu Sun Aug 3 16:36:03 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 3 Aug 2003 16:36:03 -0400 Subject: Passing a string argument by reference References: Message-ID: <4WWdnT6L9eip77CiXTWJkg@comcast.com> "Andrew Chalk" wrote in message news:PPdXa.1338$uI7.1016630372 at newssvr12.news.prodigy.com... > I am a raw beginner to Python. I just read in "Learning Python" that > assigning to a string argument inside a function does not change the string > in the caller. I want an assignment in the function to alter the passed > string in the caller. Is there any way to do this? As asked, no. Strings are immutable. Period. However, with the proper infor passed in, you may be able to rebind a name or other target to a new (string) object. > For example > > def SafeAdd(self, Variable, Value): > if self.form.has_key( Value ): > Variable = self.form[Value].value > > Called with: > > self.SafeAdd(self.txtCIF, 'txtCIF') ------------ I think you want settattr here. >>> help(setattr) Help on built-in function setattr: setattr(...) setattr(object, name, value) Set a named attribute on an object; setattr(x, 'y', v) is equivalent to ``x.y = v''. ---------- Example: >>> class C: pass ... >>> c=C() >>> setattr(c, 'a', 1) >>> c.a 1 ------------- Perhaps you want something like 'setattr(self, Value, self.form[Value].value)'. The param Variable is useless. Arg self.txtCIF, for instance, is the object currently bound to the name 'txtCIF' and has no info about what name it was bound to. The string arg such as 'txtCIF' appears to be all you need in the case. Terry J. Reedy From ayc8NOSPAM at cornell.edu Fri Aug 1 02:30:53 2003 From: ayc8NOSPAM at cornell.edu (Andy C) Date: Fri, 01 Aug 2003 06:30:53 GMT Subject: How do I get a reference to a KEY value of a dictionary? References: <645db655.0307311636.71923378@posting.google.com> Message-ID: Thanks, I think that is exactly what I'm looking for. I guess if you do a = intern(a), then if a is equivalent but not identical to something in the global string table, it will assign a to reference the object in the global string table, and thus the old "a" value can be garbage collected. Well, for a C/C++ programmer, they ARE references, and I can't imagine thinking otherwise. They are implemented as references/pointers in the interpreter. Thinking in value semantics can simplify things, but there will always be some cases where it doesn't work. I think my example is a good one. If you have a graph in an adjacency list representation, you don't want the nodes to be copies of each other. They should just point to a global list of nodes. This can definitely matter... the worst case is when you have a complete graph, where you would have n(n-1)/2 (or n(n-1) for a complete directed graph) node objects where you only need n. Instead of 100,000 nodes (not an unreasonable size), you could have 10 billion (totally unreasonable). But it is a good question whether the garbage collection will make the difference worth it, in most cases. I could reassign my references, but I don't know when the old objects get deleted. That is, I can do a = intern(a), but the old value of a could hang around in memory for who knows how long. If anyone could shed some light on this, I would appreciate it. "Terry Reedy" wrote in message news:Qf-cnYqDQejEJbSiXTWJjw at comcast.com... > > "Andy C" wrote in message > news:645db655.0307311636.71923378 at posting.google.com... > > I am new to python, so please bear with me if I am making some > > conceptual error. > > > > Basically I want to create a graph with an adjacency list > > representation, but I don't want any of the adjacency lists to have > > duplicate strings when it is avoidable. I have a function > createEdge > > that adds an edge to the graph. The arguments will be distinct > since > > they are read from text files. But basically I want to use the > > dictionary as a string pool, and if the argument string equals > > something in the pool already, don't use the argument string, just a > > use a reference to something in the string pool already. > > Thinking in terms of 'references' can both help and hinder. (There > have been some long recent discussion.) > > Are you familiar with this? > > >>> help('intern') > > Help on built-in function intern: > > intern(...) > intern(string) -> string > > ``Intern'' the given string. This enters the string in the > (global) > table of interned strings whose purpose is to speed up dictionary > lookups. > Return the string itself or the previously interned string object > with the > same value. > > TJR > > From wiiliam.huizinga at smiths-aerospace.com Fri Aug 8 11:30:17 2003 From: wiiliam.huizinga at smiths-aerospace.com (William S. Huizinga) Date: Fri, 08 Aug 2003 11:30:17 -0400 Subject: Need elegant way to cast four bytes into a long Message-ID: <3f33c209$1@news.si.com> I've got an array.array of unsigned char and would like to make a slice of that array (e.g. a[0:4]) become one long like I would in "C" : l = ((unsigned long *) (&a[0]))[0]; I have been getting what I want in this sort of manner : l = 0L l = a[0] l += a[1] << 8 l += a[2] << 16 l += a[3] << 24 but I think that's too wordy. Is there a more intrinsic and elegant way to do this? --- wsh From peter at engcorp.com Wed Aug 6 16:11:18 2003 From: peter at engcorp.com (Peter Hansen) Date: Wed, 06 Aug 2003 16:11:18 -0400 Subject: Stupid string.split question References: <3f314721$0$3936$b45e6eb0@senator-bedfellow.mit.edu> Message-ID: <3F3160E6.BD604930@engcorp.com> Andrew Dalke wrote: > > Brian Kelley: > > "ABCDEF".split("") shouldn't equal ["A", "B", "C", "D", "E", "F"]? > > (which, btw, raises a ValueError.) > > Hmm. Perl does that, right? I see your point about the symmetry, It's only a token kind of symmetry, without much real value. After all, why shouldn't this be symmetrical, too, then? : ''.join(['abc', 'def', 'g', 'h']) --> 'abcdefgh' 'abcdefgh'.split('') --> ['abc', 'def', 'g', 'h'] -avoiding-foolish-consistency-and-hobgoblins-ly y'rs, Peter From aleax at aleax.it Thu Aug 21 02:34:06 2003 From: aleax at aleax.it (Alex Martelli) Date: Thu, 21 Aug 2003 06:34:06 GMT Subject: Newbie problem with codecs References: Message-ID: Andrew Dalke wrote: ... > derek / nul wrote: >> > File "apply_physics.py", line 12, in ? >> > codecs.lookup(BOM_UTF16_LE) >> > NameError: name 'BOM_UTF16_LE' is not defined > > Alex >> Change the statement to: >> codecs.lookup(codecs,BOM_UTF16_LE) > > Typo? Shouldn't that be a "." instead of a "."? A dot, not a comma -- sorry, the font I use makes them hard to tell apart (at least w/my failing eyesight) and they're right next to each other on the keyboard... which I guess is why I think you have dots on both sides of "instead" in your phrase?-). > In any case > >>>> codecs.lookup(codecs.BOM_UTF16_LE) > Traceback (most recent call last): > File "", line 1, in ? > File "C:\PYTHON23\Lib\encodings\__init__.py", line 84, in > search_function > globals(), locals(), _import_tail) > ValueError: Empty module name >>>> > > In any case, the "BOM" means "byte order marker" and > the constant is the string prefix used to indicate which > UTF16 encoding is used. It isn't the encoding name. Perfectly right -- codecs.BOM_UTF16_LE is just a 2-character string which doesn't name a codec (but rather gives the BOM for one). I saw that obvious-cause NameError and didn't look any deeper -- thanks for doing so. > Perhaps the following is what the OP wanted? > >>>> codecs.lookup("utf-16-le") > (, utf_16_le_decode>, , > ) >>>> I won't dare guess, but it's certainly one possibility. Alex From stevena at neosynapse.net Sat Aug 23 13:39:39 2003 From: stevena at neosynapse.net (Steven D. Arnold) Date: Sat, 23 Aug 2003 13:39:39 -0400 Subject: [announce] mix_table module now available Message-ID: Neosynapse (http://www.neosynapse.net) is pleased to offer version 0.8 of the mix_table module, which implements table-like data objects. mix_table offers tables that look superficially like a list of dictionaries, but mix_table supports many advanced features beyond this, including: - Rows may be sorted, alphabetically or numerically, ascending or descending, along one or more columns; - Tables can be compared as sets with other tables; - Tables can be indexed along one or more columns, with each unique combination of the selected columns pointing toward a list of the matching rows; - Tables can be joined, as with SQL; inner, outer, left and right joins are supported; and - A number of utility features are included, such as fetching a list of the items in a column, "normalizing" the rows (i.e. making sure all rows have the same set of columns), etc. This package is offered under the Python license itself (PSF for Python 2.3). The mix_table module *requires* Python 2.3 or higher, and optionally Tim Peters' FixedPoint module (https://sourceforge.net/projects/fixedpoint). The mix_table module may be downloaded at: http://www.neosynapse.net/mix_table.htm Please direct any questions or comments to me personally as well as optionally to the list. -- Steven D. Arnold stevena at neosynapse.net From google at mattwhelan.info Thu Aug 14 14:19:09 2003 From: google at mattwhelan.info (Matt Whelan) Date: 14 Aug 2003 11:19:09 -0700 Subject: SWIG and __int64 Message-ID: Supposedly, recent versions of SWIG can be made to work with MS VC++'s non-standard integer data types. According to a recent SWIG ChangeLog entry: %apply long long { __int64 }; should make Swig happy. But it doesn't. I get Syntax Errors on each line where __int64 appears. Am I missing something? I'm new to SWIG (but not to Python or C++). My searches to date have turned up no examples of successful __int64 and SWIG interaction. If anyone could provide such an example, it would be deeply appreciated. I also need to do similar things for __int8 * and __int32, but I assume once I get __int64 working the solutions for those will become obvious. -- Matt Whelan From srijit at yahoo.com Fri Aug 15 13:59:19 2003 From: srijit at yahoo.com (srijit at yahoo.com) Date: 15 Aug 2003 10:59:19 -0700 Subject: Open MS Excel Spreadsheet with Python References: <221d8dbe.0307160619.2c2943c3@posting.google.com> Message-ID: <221d8dbe.0308150959.b18167c@posting.google.com> Hello Members, I would like to share the Python-Excel Interface code. This is based on sample code from Mark Hammond and Andy Robinson's "Python Programming on Win32" I use Python 2.3 and Win32all-157 on a Win 98 machine. I look forward to feedback on how to improve this code. If I get good response I may think of putting up this code as a Python recipe in Activestate. Once again hats off to Mark Hammond for his excellent Win32all library. Regards, Srijit --------------------------------------------------------------------------- import win32com.client.dynamic class UseExcel(object): """Python Excel Interface. It provides methods for accessing the basic functionality of MS Excel 97/2000 from Python. This interface uses dynamic dispatch objects. All necessary constants are embedded in the code. There is no need to run makepy.py. """ __slots__ = ("xlapp", "xlbook") def __init__(self, fileName=None): """e.g. xlFile = useExcel("e:\\python23\myfiles\\testExcel1.xls") """ self.xlapp = win32com.client.dynamic.Dispatch("Excel.Application") if fileName: self.xlbook = self.xlapp.Workbooks.Open(fileName) else: self.xlbook = self.xlapp.Workbooks.Add() def save(self, newfileName=None): if newfilename: self.xlbook.SaveAs(newfileName) else: self.xlbook.Save() def close(self): self.xlbook.Close(SaveChanges=False) del self.xlapp def show(self): self.xlapp.Visible = True def hide(self): self.xlapp.Visible = False def getcell(self, sheet, cellAddress): """Get value of one cell. Description of parameters (self explanatory parameters are not described): sheet - name of the excel worksheet cellAddress - tuple of integers (row, cloumn) or string "ColumnRow" e.g. (3,4) or "D3" """ sht = self.xlbook.Worksheets(sheet) if (isinstance(cellAddress,str)): return sht.Range(cellAddress).Value elif (isinstance(cellAddress,tuple)): row = cellAddress[0] col = cellAddress[1] return sht.Cells(row, col).Value def setcell(self, sheet, value, cellAddress, fontStyle=("Regular",), fontName="Arial", fontSize=12, fontColor=1): """Set value of one cell. Description of parameters (self explanatory parameters are not described): sheet - name of the excel worksheet value - The cell value. it can be a number, string etc. cellAddress - tuple of integers (row, cloumn) or string "ColumnRow" e.g. (3,4) or "D3" fontStyle - tuple. Combination of Regular, Bold, Italic, Underline e.g. ("Regular", "Bold", "Italic") fontColor - ColorIndex. Refer ColorIndex property in Microsoft Excel Visual Basic Reference """ sht = self.xlbook.Worksheets(sheet) if (isinstance(cellAddress,str)): sht.Range(cellAddress).Value = value sht.Range(cellAddress).Font.Size = fontSize sht.Range(cellAddress).Font.ColorIndex = fontColor for i, item in enumerate(fontStyle): if (item.lower() == "bold"): sht.Range(cellAddress).Font.Bold = True elif (item.lower() == "italic"): sht.Range(cellAddress).Font.Italic = True elif (item.lower() == "underline"): sht.Range(cellAddress).Font.Underline = True elif (item.lower() == "regular"): sht.Range(cellAddress).Font.FontStyle = "Regular" sht.Range(cellAddress).Font.Name = fontName elif (isinstance(cellAddress,tuple)): row = cellAddress[0] col = cellAddress[1] sht.Cells(row, col).Value = value sht.Cells(row, col).Font.FontSize = fontSize sht.Cells(row, col).Font.ColorIndex = fontColor for i, item in enumerate(fontStyle): if (item.lower() == "bold"): sht.Range(cellAddress).Font.Bold = True elif (item.lower() == "italic"): sht.Range(cellAddress).Font.Italic = True elif (item.lower() == "underline"): sht.Range(cellAddress).Font.Underline = True elif (item.lower() == "regular"): sht.Range(cellAddress).Font.FontStyle = "Regular" sht.Cells(row, col).Font.Name = fontName def getrange(self, sheet, rangeAddress): """Returns a tuple of tuples from a range of cells. Each tuple corresponds to a row in excel sheet. Description of parameters (self explanatory parameters are not described): sheet - name of the excel worksheet rangeAddress - tuple of integers (row1,col1,row2,col2) or "cell1Address:cell2Address" row1,col1 refers to first cell row2,col2 refers to second cell e.g. (1,2,5,7) or "B1:G5" """ sht = self.xlbook.Worksheets(sheet) if (isinstance(rangeAddress,str)): return sht.Range(rangeAddress).Value elif (isinstance(rangeAddress,tuple)): row1 = rangeAddress[0] col1 = rangeAddress[1] row2 = rangeAddress[2] col2 = rangeAddress[3] return sht.Range(sht.Cells(row1, col1), sht.Cells(row2, col2)).Value def setrange(self, sheet, topRow, leftCol, data): """Sets range of cells with values from data. data is a tuple of tuples. Each tuple corresponds to a row in excel sheet. Description of parameters (self explanatory parameters are not described): sheet - name of the excel worksheet topRow - row number (integer data type) leftCol - column number (integer data type) """ bottomRow = topRow + len(data) - 1 rightCol = leftCol + len(data[0]) - 1 sht = self.xlbook.Worksheets(sheet) sht.Range(sht.Cells(topRow, leftCol), sht.Cells(bottomRow, rightCol)).Value = data return (bottomRow, rightCol) def setcellalign(self, sheet, cellAddress, alignment): """Aligns the contents of the cell. Description of parameters (self explanatory parameters are not described): sheet - name of the excel worksheet cellAddress - tuple of integers (row, cloumn) or string "ColumnRow" e.g. (3,4) or "D3" alignment - "Left", "Right" or "center" """ if (alignment.lower() == "left"): alignmentValue = 2 elif ((alignment.lower() == "center") or (alignment.lower() == "centre")): alignmentValue = 3 elif (alignment.lower() == "right"): alignmentValue = 4 sht = self.xlbook.Worksheets(sheet) if (isinstance(cellAddress,str)): sht.Range(cellAddress).HorizontalAlignment = alignmentValue elif (isinstance(cellAddress,tuple)): row = cellAddress[0] col = cellAddress[1] sht.Cells(row, col).HorizontalAlignment = alignmentValue def addnewworksheetbefore(self, oldSheet, newSheetName): """Adds a new excel sheet before the given excel sheet. Description of parameters (self explanatory parameters are not described): oldSheet - Name of the sheet before which a new sheet should be inserted newSheetName - Name of the new sheet """ sht = self.xlbook.Worksheets(oldSheet) self.xlbook.Worksheets.Add(sht).Name = newSheetName def addnewworksheetafter(self, oldSheet, newSheetName): """Adds a new excel sheet after the given excel sheet. Description of parameters (self explanatory parameters are not described): oldSheet - Name of the sheet after which a new sheet should be inserted newSheetName - Name of the new sheet """ sht = self.xlbook.Worksheets(oldSheet) self.xlbook.Worksheets.Add(None,sht).Name = newSheetName def insertchart(self, sheet, left, top, width, height): """Creates a new embedded chart. Returns a ChartObject object. Refer Add Method(ChartObjects Collection) in Microsoft Excel Visual Basic Reference. Description of parameters (self explanatory parameters are not described): sheet - name of the excel worksheet left, top - The initial coordinates of the new object (in points), relative to the upper-left corner of cell A1 on a worksheet or to the upper-left corner of a chart. width, height - The initial size of the new object, in points. point - A unit of measurement equal to 1/72 inch. """ sht = self.xlbook.Worksheets(sheet) return sht.ChartObjects().Add(left, top, width, height) def plotdata(self, sheet, dataRanges, chartObject, chartType, plotBy=None, categoryLabels=1, seriesLabels=0, hasLegend=None, title=None, categoryTitle=None, valueTitle=None, extraTitle=None): """Plots data using ChartWizard. For details refer ChartWizard method in Microsoft Excel Visual Basic Reference. Before using PlotData method InsertChart method should be used. Description of parameters: sheet - name of the excel worksheet. This name should be same as that in InsertChart method dataRanges - tuple of tuples ((topRow, leftCol, bottomRow, rightCol),). Range of data in excel worksheet to be plotted. chartObject - Embedded chart object returned by InsertChart method. chartType - Refer plotType variable for available options. For remaining parameters refer ChartWizard method in Microsoft Excel Visual Basic Reference. """ sht = self.xlbook.Worksheets(sheet) if (len(dataRanges) == 1): topRow, leftCol, bottomRow, rightCol = dataRanges[0] source = sht.Range(sht.Cells(topRow, leftCol), sht.Cells(bottomRow, rightCol)) elif (len(dataRanges) > 1): topRow, leftCol, bottomRow, rightCol = dataRanges[0] source = sht.Range(sht.Cells(topRow, leftCol), sht.Cells(bottomRow, rightCol)) for count in range(len(dataRanges[1:])): topRow, leftCol, bottomRow, rightCol = dataRanges[count+1] tempSource = sht.Range(sht.Cells(topRow, leftCol), sht.Cells(bottomRow, rightCol)) source = self.xlapp.Union(source, tempSource) plotType = { "Area" : 1, "Bar" : 2, "Column" : 3, "Line" : 4, "Pie" : 5, "Radar" : -4151, "Scatter" : -4169, "Combination" : -4111, "3DArea" : -4098, "3DBar" : -4099, "3DColumn" : -4100, "3DPie" : -4101, "3DSurface" : -4103, "Doughnut" : -4120, "Radar" : -4151, "Bubble" : 15, "Surface" : 83, "Cone" : 3, "3DAreaStacked" : 78, "3DColumnStacked" : 55 } gallery = plotType[chartType] format = None chartObject.Chart.ChartWizard(source, gallery, format, plotBy, categoryLabels, seriesLabels, hasLegend, title, categoryTitle, valueTitle, extraTitle) def copyrange(self,source, destination): """Copy range of data from source range in a sheet to destination range in same sheet or different sheet Description of parameters (self explanatory parameters are not described): source - tuple (sheet, rangeAddress) sheet - name of the excel sheet rangeAddress - "cell1Address:cell2Address" destination - tuple (sheet, destinationCellAddress) destinationCellAddress - string "ColumnRow" """ sourceSht = self.xlbook.Worksheets(source[0]) destinationSht = self.xlbook.Worksheets(destination[0]) sourceSht.Range(source[1]).Copy(destinationSht.Range(destination[1])) def copychart(self, sourceChartObject, destination,delete="N"): """Copy chart from source range in a sheet to destination range in same sheet or different sheet Description of parameters (self explanatory parameters are not described): sourceChartObject - Chart object returned by InsertChart method. destination - tuple (sheet, destinationCellAddress) sheet - name of the excel worksheet. destinationCellAddress - string "ColumnRow" if sheet is omitted and only destinationCellAddress is available as string data then same sheet is assumed. delete - "Y" or "N". If "Y" the source chart object is deleted after copy. So if "Y" copy chart is equivalent to move chart. """ if (isinstance(destination,tuple)): sourceChartObject.Copy() sht = self.xlbook.Worksheets(destination[0]) sht.Paste(sht.Range(destination[1])) else: sourceChartObject.Chart.ChartArea.Copy() destination.Chart.Paste() if (delete.upper() =="Y"): sourceChartObject.Delete() def hidecolumn(self, sheet, col): """Hide a column. Description of parameters (self explanatory parameters are not described): sheet - name of the excel worksheet. col - column number (integer data) """ sht = self.xlbook.Worksheets(sheet) sht.Columns(col).Hidden = True def hiderow(self, sheet, row): """ Hide a row. Description of parameters (self explanatory parameters are not described): sheet - name of the excel worksheet. row - row number (integer data) """ sht = self.xlbook.Worksheets(sheet) sht.Rows(row).Hidden = True def excelfunction(self, sheet, range, function): """Access Microsoft Excel worksheet functions. Refer WorksheetFunction Object in Microsoft Excel Visual Basic Reference Description of parameters (self explanatory parameters are not described): sheet - name of the excel worksheet range - tuple of integers (row1,col1,row2,col2) or "cell1Address:cell2Address" row1,col1 refers to first cell row2,col2 refers to second cell e.g. (1,2,5,7) or "B1:G5" For list of functions refer List of Worksheet Functions Available to Visual Basic in Microsoft Excel Visual Basic Reference """ sht = self.xlbook.Worksheets(sheet) if isinstance(range,str): xlRange = "(sht.Range(" + "'" + range + "'" + "))" elif isinstance(range,tuple): topRow = range[0] leftColumn = range[1] bottomRow = range[2] rightColumn = range[3] xlRange = "(sht.Range(sht.Cells(topRow, leftColumn), sht.Cells(bottomRow, rightColumn)))" xlFunction = "self.xlapp.WorksheetFunction." + function + xlRange return eval(xlFunction, globals(), locals()) def clearrange(self, sheet, rangeAddress, contents="Y", format="Y"): """Clear the contents of a range of cells. Description of parameters (self explanatory parameters are not described): sheet - name of the excel worksheet rangeAddress - tuple of integers (row1,col1,row2,col2) or "cell1Address:cell2Address" row1,col1 refers to first cell row2,col2 refers to second cell e.g. (1,2,5,7) or "B1:G5" contents - "Y" or "N". If "Y" clears the formulas from the range format - "Y" or "N". If "Y" clears the formatting of the object """ sht = self.xlbook.Worksheets(sheet) if (isinstance(rangeAddress,str)): if (format.upper() == "Y"): sht.Range(rangeAddress).ClearFormats() if (contents.upper() == "Y"): sht.Range(rangeAddress).ClearContents() elif (isinstance(rangeAddress,tuple)): row1 = rangeAddress[0] col1 = rangeAddress[1] row2 = rangeAddress[2] col2 = rangeAddress[3] if (format.upper() == "Y"): sht.Range(sht.Cells(row1, col1), sht.Cells(row2, col2)).ClearFormats() if (contents.upper() == "Y"): sht.Range(sht.Cells(row1, col1), sht.Cells(row2, col2)).ClearContents() def addcomment(self, sheet, cellAddress, comment=""): """Add or delete comment to a cell. If parameter comment is None, delete the comments Description of parameters (self explanatory parameters are not described): sheet - name of the excel worksheet cellAddress - tuple of integers (row, cloumn) or string "ColumnRow" e.g. (3,4) or "D3" comment - String data. Comment to be added. If None, delete comments """ sht = self.xlbook.Worksheets(sheet) if (isinstance(cellAddress,str)): if (comment != None): sht.Range(cellAddress).AddComment(comment) else: sht.Range(cellAddress).ClearComments() elif (isinstance(cellAddress,tuple)): row1 = cellAddress[0] col1 = cellAddress[1] if (comment != None): sht.Cells(row1, col1).AddComment(comment) else: sht.Cells(row1, col1).ClearComments() def excelapp(): xlFile = UseExcel("e:\\python23\myfiles\\StudentTabulation.xls") xlFile.show() xlFile.setcell(sheet="Sheet1", value="Class X Annual Examination",fontName="Arial", cellAddress="D1",fontColor=1, fontStyle=("Bold",), fontSize=16) xlFile.setcell(sheet="Sheet1", value="Subject : History", fontName="Arial", cellAddress="D3",fontColor=1) data = ( ("Sl. No." ,"Name of Students", "Roll No.", "Marks(out of 100)"), (1 ,"John" ,1020, 52), (2 ,"Nikhil" ,1021, 75), (3 ,"Stefen" ,1025, 85), (4 ,"Thomas" ,1026, 54), (5 ,"Ali" ,1027, 87), (6 ,"Sanjay" ,1028, 0) ) (bottomRow, rightCol) = xlFile.setrange("Sheet1", 5,2,data) xlFile.addcomment("sheet1", "C11", "Absent") chrt1 = xlFile.insertchart("sheet2", 100, 100, 400, 200) xlFile.plotdata(sheet="sheet1",dataRanges=((6,3,bottomRow,5),), chartObject=chrt1, title="Annual Examination : History", plotBy=2, categoryLabels=1, seriesLabels=0, chartType="Bar") #~ xlFile.clearrange("sheet1",(3,2,3,5),"y") #~ xlFile.addcomment("sheet1", "B4", "Test Comment") #~ chrt1 = xlFile.insertchart("sheet1", 100, 100, 400, 250) #~ xlFile.plotdata(sheet="sheet1",dataRange=(4,2,bottomRow, rightCol), chartObject=chrt1, #~ title="Test Chart", chartType="Column") #~ xlFile.copyrange(("sheet1","C3:E3"), ("sheet2", "C3")) #~ chrt2 = xlFile.insertchart("sheet2", 100, 100, 400, 250) #~ xlFile.movechart(chrt1,chrt2) #~ xlFile.copychart(chrt1,("sheet3","D22"), "y") #~ xlFile.hiderow("sheet1",7) #~ print xlFile.excelfunction("sheet1", (3,2,3,5), "Min") #~ print xlFile.getrange("sheet1","A2","C3") #~ xlFile.setcellfont("sheet1","Regular", "A1") #~ cellVal1 = xlFile.getcell("sheet1","A1") #~ xlFile.setcell("sheet1", cellVal1,1,3) #~ xlFile.setcellfont("sheet1","bold","C1") #~ xlFile.setcellfont("sheet1","italic",1,3) #~ xlFile.setcellfont("sheet1","underline",1,3) #~ xlFile.setcellalign("sheet1","left",1,3) #~ print xlFile.getrange("sheet1", "D5", "F6") #~ xlFile.setrange("sheet1", 10,10, ((45,67),(67,"342"),(88,66.8),(32,77),(3,3))) #~ xlFile.addnewworksheetafter("sheet1", "Srijit1") if (__name__ == "__main__"): excelapp() --------------------------------------------------------------------------- srijit at yahoo.com wrote in message news:<221d8dbe.0307160619.2c2943c3 at posting.google.com>... > Hi, > I am working on Python-Excel interface based on the excellent library > win32com. > I was planning to put it up as a Python recipe in Activestate. > Anyway before that I shall personally send you the code after some > cleanup. It will be good to get an early feedback before I upload it > in Activestate. > > Regards, > Srijit > > "Allison Bailey" wrote in message news:... > > Hi Folks, > > > > I'm a brand new Python programmer, so please point me in the right > > direction if this is not the best forum for this question.... > > > > I would like to open an existing MS Excel spreadsheet and extract > > information from specific worksheets and cells. > > > > I'm not really sure how to get started with this process. > > I ran the COM Makepy utility from my PythonWin (IDE from ActiveSTate), > > using Microsoft Excel 10.0 Object Library, then > > import win32com.client > > xl = win32com.client.Dispatch("Excel.Application") > > wb = xl.Workbooks.Open ("c:\\data\\myspreadsheet.xls") > > > > Then, I get errors when I try the following: > > sh = wb.worksheets(1) > > > > > > I think I'm missing something fairly fundamental, but I've googled all > > over the place and can't seem to find anything very introductory about > > opening and using data from MS Excel using Python. Any suggestions, > > including places to get more information are welcome. > > > > Also, do I need to run the makepy utility every time I run my script? > > If so, how would I do it from within my Python program, rather than with > > the GUI in the IDE? > > > > Thanks for your help, > > > > Allison > > > > > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > Allison Bailey > > TerraLogic GIS, Inc. > > allisonb at terralogicgis.com > > 425-673-4495 > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From theller at python.net Thu Aug 7 03:04:39 2003 From: theller at python.net (Thomas Heller) Date: Thu, 07 Aug 2003 09:04:39 +0200 Subject: FWD: Re: Problem w/ IDLE on Win2000 References: Message-ID: <8yq67xtk.fsf@python.net> "Tim Peters" writes: > Speaking of which, that doesn't look likely to change anytime soon, so if > someone else is willing to take over the PLabs Windows installer, it's > yours. Overall, it's in very good shape. Whoever is interested should also > consider switching to InnoSetup (and there's a patch on SF moving closer > toward that end). If it helps, I'm willing to take over the windows installer - although I would probably stay with Wise. And I consider IDLE having problems with spaces in its path a problem. Just bought my daughter a copy of 'Python f?r Kids' (although she certainly accepted the default installation options). Thomas From paulpaterson at users.sourceforge.net Wed Aug 27 02:26:49 2003 From: paulpaterson at users.sourceforge.net (Paul Paterson) Date: Wed, 27 Aug 2003 06:26:49 GMT Subject: My future Python IDE article References: Message-ID: "David Mertz" wrote in message news:mailman.1061920192.21278.python-list at python.org... Depending on how you want to define IDE, Leo would be my choice. I use it to develop code, documentation, web pages as well as a arranging thoughts and ideas in a structured way. For me, it is the best IDE because it integrates with the way I think. The ability to represent the same information in mutiple ways is a very powerful feature that I haven't seen matched in other IDE's. As a different spin on IDE's, Leo is definitely worth a look. Paul From mesteve_b at hotmail.com Sat Aug 16 20:24:04 2003 From: mesteve_b at hotmail.com (python newbie) Date: Sun, 17 Aug 2003 00:24:04 GMT Subject: CDR Support References: Message-ID: Actually, it's for Windows. Thanks though "Aahz" wrote in message news:bhmf8o$ia1$1 at panix3.panix.com... > In article , > python newbie wrote: > > > >I'm starting to write a simple backup program using wxPython. But I > >figure I might as well support rewritable CDROM that most people use. ( > >I still don't have one, that's just wrong). > > > >Does anyone have knowledge of support for rewriteable CDROM's in > >python? > > Is this for Linux or something else? I'd suggest that you simply write > a wrapper around mkisofs and cdrecord. > -- > Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ > > This is Python. We don't care much about theory, except where it intersects > with useful practice. --Aahz From missive at frontiernet.net Sun Aug 3 18:26:33 2003 From: missive at frontiernet.net (Lee Harr) Date: Sun, 03 Aug 2003 22:26:33 GMT Subject: Python and XML References: Message-ID: In article , Matthieu M. wrote: > Hi! > > I want to make an application that needs to parse an xml file, but I > always have weird errors, I've got Python 2.3 > > Here's the beginning of my prog: > > from xml.dom import pulldom > > and here's python's answer: > > Traceback (most recent call last): > File "xml.py", line 1, in ? > from xml.dom import pulldom > File "C:\progs\xml.py", line 1, in ? > from xml.dom import pulldom > ImportError: No module named dom > > When I look in my Python folder I see .py files in xml/dom... > > Thanks for any help. > I think the problem is that your program is called xml.py so, when you say: from xml import .... it is trying to import from YOUR PROGRAM instead of the standard lib. Try renaming your program. From gh at ghaering.de Wed Aug 6 18:01:49 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Thu, 07 Aug 2003 00:01:49 +0200 Subject: Python 2.3 Breaks PySQLite a Little In-Reply-To: <3F314D84.E336C01F@easystreet.com> References: <3F314D84.E336C01F@easystreet.com> Message-ID: <3F317ACD.2030805@ghaering.de> achrist at easystreet.com wrote: > Have hit a problem with PySQLite and python 2.3. The new bool > type doesn't want to get written properly to a database. I was > expecting this to break when I started using True and False in > python 2.2, but it didn't. Now there's a little trouble. > I changed the _quote function in pysqlite main.py to look like: > > > def _quote(value): > > if value is None: > return 'NULL' > elif isinstance(value, bool): ### Added > return 0 + value ### Added > [...] > > Is that all it needs? Yeah, except I'd write int(value). [1] You'll also want to convert it back to bools, right? use the 'converters' parameter of the connect call. To check wether your changes worked as expected, you could use something like: #v+ cx = sqlite.connect("db", converters={"bool": bool}) cu.execute("create table test(b bool)") cu.execute("insert into test(b) values (%s)", (True,)) cu.execute("select b from test") res = cu.fetchone() assert type(res.b) is bool #v- All completely untested, I'm too lazy now ;-) -- Gerhard [1] And I intend to drop all this politically correct isinstance stuff in a future version for performance reasons. From mwh at python.net Fri Aug 1 09:47:26 2003 From: mwh at python.net (Michael Hudson) Date: Fri, 1 Aug 2003 13:47:26 GMT Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> <840592e1.0307312304.77a0a05f@posting.google.com> Message-ID: <7h37k5xa3sr.fsf@pc150.maths.bris.ac.uk> "Daniel Dittmar" writes: > John Roth wrote: > > There's a flaw in your reasoning. The various techniques that > > descend from mark and sweep (which is what you're > > calling garbage collection) depend on being able to > > identify all of the objects pointed to. For objects that are > > owned by Python, that's a lengthy (that is, inefficient) > > That's what generation scavenging was developed for. But most generational collectors are copying aren't they? That makes it challenging to meet the "play nice with C" goal I talked about (not impossible, but significantly difficult). > One shouldn't argue by tradition alone, but the fact that the major > implementations of dynamic languages like LISP and Smalltalk don't > use reference counting should carry some weight. True. But the major implementations of these languages are also usually less portable, and something more of a fiddle to write C extensions for (at least, for the implementations I know about, which are mostly CL impls). If you're writing a native code compiler, it doesn't seem that much of a drag to have your code about e.g. the processor's registers. > > It's easy to say that various languages would be improved > > by adding "real" garbage collection, but those techniques > > impose significant design constraints on the implementation > > model. > > True. But one could review these constraints from time to time. Indeed. People have tried using the Boehm GC with Python, but generally found that performance got worse, or at least not strikingly better. I don't think anyone has tried implementing a really good generational-type collector. (And unfortunately, I think one constraint that's not going away is "not breaking every C extension that's ever been written). Cheers, mwh -- US elections For those of you fearing that the rest of the world might be making fun of the US because of this: Rest assured, we are. -- http://www.advogato.org/person/jameson/diary.html?start=12 From guineapig at pi.be Tue Aug 19 06:08:58 2003 From: guineapig at pi.be (Tom Van den Brandt) Date: Tue, 19 Aug 2003 12:08:58 +0200 Subject: python & postgresql ? References: Message-ID: Dave Kuhlman wrote: > GuineaPig wrote: > > [snip] >> I've looked into pyPgSQL too, and this works fine under windows, >> but I cannot get this to run on my linux-machine (suse 8.2). > > What problems are you having. I'm using pyPgSQL-2.3 on Debian > GNU/Linux and it seems to work fine, though I'll admit that my > usage does not stress it heavily. > > I found that I had to make the following changes to setup.py: > > ====================================================== > > --- setup.py 2002-12-01 10:31:00.000000000 -0800 > +++ setup_new.py 2003-06-11 16:13:40.000000000 -0700 > @@ -80,7 +80,8 @@ > > def main(): > # Set this to 1 if you need to use your own settings > - USE_CUSTOM = 0 > + USE_CUSTOM = 1 > > # Default settings, may be overriden for specific platforms > pypgsql_rt_dirs = None > @@ -96,8 +97,10 @@ > "port/strtok.c"] > > if USE_CUSTOM: > - include_dirs = YOUR_LIST_HERE > - library_dirs = YOUR_LIST_HERE > + include_dirs = [ "/w2/Postgresql/postgresql-7.3.3/src/include", > + "/w2/Postgresql/postgresql-7.3.3/src/interfaces/libpq/" ] > + library_dirs = [ "/usr/local/pgsql/lib" ] > elif sys.platform == "linux2": > include_dirs = ["/usr/include", "/usr/include/postgresql", > "/usr/include/pgsql"] > @@ -164,6 +167,8 @@ > name=modname, > sources = sources, > include_dirs = include_dirs, > + define_macros = [('LONG_LONG', 'PY_LONG_LONG')], > library_dirs = library_dirs, > runtime_library_dirs = pypgsql_rt_dirs, > libraries = optional_libs > > ====================================================== > > Dave > > [snip] > Tnx Dave I had some dirs mixed-up... Tnx to your post I went back to have a look at the setup.py file and found the problem -- Tom Van den Brandt I try... From dave at boost-consulting.com Thu Aug 28 03:33:48 2003 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 28 Aug 2003 03:33:48 -0400 Subject: Aspect oriented Everything? References: <32cc321c.0308221316.2f5793ac@posting.google.com> <6ee58e07.0308230459.24f53b64@posting.google.com> <8ef9bea6.0308261857.1b44a5b7@posting.google.com> <8ef9bea6.0308270810.7adfe408@posting.google.com> <3F4CDC9F.1050100@thingmagic.com> <8ef9bea6.0308271925.30735265@posting.google.com> Message-ID: hungjunglu at yahoo.com (Hung Jung Lu) writes: > (2) Yet another approach is using code templates, a la > meta-programming. There are more complicated examples, like the second > example in my previous posting, where it's not easily solved by one > single code block, nor one single MixIn, nor by function composition. > In that case one can assemble the code by using a template, and make > successive pattern substitutions depending on the properties of the > particular instrument. Of course, this approach is a bit beyond the > reach of Java/C++, and anyway the strongly-typed language people would > protest because your code may not have been properly verified by the > compiler. Don't lump Java and C++ together, please! I am currently writing a book about metaprogramming in C++, using (ahem) templates. I realize that you were referring to a more abstract concept when you wrote "template", but it's still amusing that the very C++ feature which implements your "template" is called "template". Well, maybe I need more sleep. It's amusing to me anyway. Anyway, the compile-time computational power of C++ templates goes far beyond simple templated code generation. In fact they have been shown to be Turing-complete (http://osl.iu.edu/~tveldhui/papers/2003/turing.pdf). And, as for proper code verification, template metaprogramming doesn't compromise type-safety. Regards, -- Dave Abrahams Boost Consulting www.boost-consulting.com From danielk at aracnet.com Thu Aug 21 08:38:43 2003 From: danielk at aracnet.com (Daniel Klein) Date: Thu, 21 Aug 2003 05:38:43 -0700 Subject: Which way to say 'private'? Message-ID: <14f9kv4fvuf67k6j12lpgt6vk9dcpefchm@4ax.com> There are 2 ways to indicate private members of classes, by prepending 1 or 2 underscore characters, the latter causing name mangling. My question is: When would I use which kind to indicate privacy? Thanks, Daniel Klein Member of the Dead Parrot Society From tjreedy at udel.edu Sun Aug 24 03:20:52 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 24 Aug 2003 03:20:52 -0400 Subject: Modifying the {} and [] tokens References: <2259b0e2.0308230718.53d22c14@posting.google.com> <774fkvg920qibnnp83r17inqmk311tqcsv@4ax.com> Message-ID: "> If you can conjure up the right Google Groups query, this has been discussed > many times in the past (and by that I mean some good points have been raised > that you might find interesting). In particular, I remember Alex Martelli > making a good argument for len(obj) over obj.len(). One point someone made is summarized by the following contrast: collections = (atuple, alist, adict, someothercollection) flengths = map(len, collections) #actual mlengths = map(lambda obj: gettattr(obj, 'len')(), collections) #hypothetical # or listcomp equivalents Terry J. Reedu From damien.wyart at free.fr Wed Aug 6 07:17:51 2003 From: damien.wyart at free.fr (Damien Wyart) Date: Wed, 06 Aug 2003 13:17:51 +0200 Subject: round(22.47,2) gives 22.469999999999999? References: <3f30e294$0$125$e4fe514c@dreader5.news.xs4all.nl> Message-ID: <3f30e3df$0$15104$626a54ce@news.free.fr> * Eric van Riet Paap in comp.lang.python: > On python2.1.3, python2.2.1 and python2.2.3 round(22.47,2) gives > 22.469999999999999 . This is explained in detail at . -- Damien Wyart From mack at incise.org Sun Aug 31 15:13:45 2003 From: mack at incise.org (mackstann) Date: Sun, 31 Aug 2003 14:13:45 -0500 Subject: SF deploys SA, lauds P & BC [Also: CVS improvements] In-Reply-To: References: Message-ID: <20030831191345.GI9311@incise.org> Also worthy of noting are the improvements to CVS. Anyone that uses SF CVS knows that public CVS has been basically daily (or so) updated snapshots of the real CVS, which has been a pain for fast moving projects, and users who want to use/test bleeding-edge code. This should all be resolved this week, it seems. ----------------- copy/paste --------------------- I wanted to give you a few updates on SF.NET. First, in the last sitewide email I described our CVS performance issues and the solution we are introducing to fix them. The performance increase I spoke of (600%+ increase) is just days away from being deployed. The new systems are now in place, additional electrical power has been added to our colocation cage, and the Linux boxes are in their final stages of configuration. Hang in there. Help is on the way. -------------------------------------------------- -- m a c k s t a n n mack @ incise.org http://incise.org It was one of those perfect summer days -- the sun was shining, a breeze was blowing, the birds were singing, and the lawn mower was broken ... -- James Dent From sales at inode.at Fri Aug 22 08:41:36 2003 From: sales at inode.at (Request Tracker) Date: Fri, 22 Aug 2003 14:41:36 +0200 Subject: [Tkt #603842] (sales) Re: Details Message-ID: Sehr geehrte Damen und Herren, dieses Mail wurde automatisch erstellt, da wir eine Nachricht mit dem Betreff "Re: Details" von Ihnen erhalten haben. Ihre Mail hat die Ticket ID [Tkt #603842] erhalten und wird in kuerze bearbeitet werden. Sie brauchen auf diese Mail nicht zu antworten. [Tkt #603842] Falls Sie mit uns bezueglich dieses Betreffs "Re: Details" wieder korrespondieren, verwenden Sie bitte die Ticket (Tkt) ID . Vielen Dank ! Greetings, This message has been automatically generated in response to your message regarding "Re: Details", the content of which appears below. There is no need to reply to it now. Request Tracker has received your message and it has been assigned a ticket ID of [Tkt #603842]. Please include the string [Tkt #603842] in the subject line of all future correspondence about this problem. To do so, you may reply to this message. Thank you ! -- Inode Telekommunikationsdienstleistungs GmbH - http://www.inode.at/ Tel.: 059999-0 Fax.: 059999 6699 Buero Wien - Millennium Tower Handelskai 94-96/43 - A-1200 Wien Buero Graz - Schmiedlstrasse 1 - A-8042 Graz Buero Linz - Wienerstrasse 131 - A-4020 Linz Buero Sbg - Schillerstrasse 30 - A-5020 Salzburg Buero Ibk - Eduard Bodem Gasse 5-7 - A-6020 Innsbruck Buero Villach - Europastrasse 8/3OG KO6A - A-9524 Villach Please see the attached file for details. >>> application/octet-stream component, message, part 2: http://rt.inode.at/stripmime1/2003/08/1061556093-23366/wicked_scr.scr --- Headers Follow --- Return-path: Received: from smtp-04.inode.at ([62.99.194.6] helo=smtp.inode.at) by rt.inode.at with esmtp (Exim 3.32 #1) id 19qBES-00064l-00 for rt-sales at rt.inode.at; Fri, 22 Aug 2003 14:41:32 +0200 Received: from e-mail.inode.at ([213.229.60.101]:45983) by smtp.inode.at with esmtp (TLSv1:DES-CBC3-SHA:168) (Exim 4.10) id 19qBEQ-0004F4-00 for rt-sales at rt.inode.at; Fri, 22 Aug 2003 14:41:30 +0200 Received: from [212.152.255.254] (helo=INTERNET) by e-mail.inode.at with esmtp (Exim 3.22 #2) id 19qBD0-0007Jm-00 for sales at inode.at; Fri, 22 Aug 2003 14:40:03 +0200 From: To: Subject: Re: Details Date: Fri, 22 Aug 2003 14:52:03 +0200 X-MailScanner: Found to be clean Importance: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MSMail-Priority: Normal X-Priority: 3 (Normal) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="_NextPart_000_09B895B5" Message-Id: -------------------------------------------- Managed by Request Tracker From gfyho at yahoo.com Mon Aug 18 20:49:50 2003 From: gfyho at yahoo.com (G. Feldman) Date: 18 Aug 2003 17:49:50 -0700 Subject: What's better about Ruby than Python? References: Message-ID: <55143354.0308181649.7a25d74@posting.google.com> "Brandon J. Van Every" wrote in message news:... > Well, I'll freely own up to being rude and intellectually violent. > It's annoying when people can't/won't tell the difference. By admitting to being rude, your annoyance becomes irrelevant. Rudeness indicates a disregard for others, hence it's correct and appropriate for others to disregard your feelings about the use of the term troll. If you want people to care about what you say, you need to care enough about them to be polite about it. From duncan at NOSPAMrcp.co.uk Tue Aug 19 04:48:20 2003 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Tue, 19 Aug 2003 08:48:20 +0000 (UTC) Subject: python and symbian? References: <1061222990.25115.0@damia.uk.clara.net> Message-ID: PD wrote in news:1061222990.25115.0 at damia.uk.clara.net: > Yes, thats pretty much the only reference to python on the symbian > platform that I could find. While this is interesting I was hoping for > something for the version 6 OS, or even version 7 (I have a p800 you > see). I think you are out of luck. I did the original port of Python to the Psion 5, so I have some idea of the issues involved. Unfortunately the Epoc/Symbian environment isn't terribly friendly when porting applications from other platforms, your best bet is probably to go with Jython. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From max at alcyone.com Mon Aug 11 23:05:10 2003 From: max at alcyone.com (Erik Max Francis) Date: Mon, 11 Aug 2003 20:05:10 -0700 Subject: Fun with numbers - dammit, but I want a cast! References: <3f378fac$0$10778$afc38c87@auth.uk.news.easynet.net> <3f3792f2$0$18258$afc38c87@auth.uk.news.easynet.net> <3F38367F.9EF03CEE@alcyone.com> <3F38439C.5FC57375@alcyone.com> Message-ID: <3F385966.CAF12DB0@alcyone.com> Bengt Richter wrote: > With (float) 1 it can optimize to one instruction with immediate > operand constant. With the other it needs (at least on x86) to move > via > EAX, for two instructions (e.g., assigning the resp values). This is wholly an implementation detail. The point is, in C and C++, casts have different purposes. Some are compile-time, some are run-time; some are safe and are simply conversion, others are unsafe and result in implementation-defined or undefined behavior. Not all C casts are unsafe; some simply invoke conversions. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ Come not between the dragon and his wrath. \__/ King Lear (Act I, Scene I) From nobbi_at_theorie3.physik.uni-erlangen.de at NOSPAM.COM Sat Aug 16 12:22:41 2003 From: nobbi_at_theorie3.physik.uni-erlangen.de at NOSPAM.COM (Norbert Nemec) Date: Sat, 16 Aug 2003 18:22:41 +0200 Subject: IEEE special values References: Message-ID: John Roth wrote: >> is there any simple reason why IEEE special values are so poorly >> supported in python? > > Like a lot of things, Python's math functions are a rather thin layer > on top of the native C library's math functions. If the C library's > math functions, to use the vernacular, suck, then Python's math > functions will do likewise. That's what I would have expected, BUT: gcc and glibc behave perfectly well (2.95.4) so obviously, the layer in between is rather too thick than too thin. p.e. log(-1.0) gives a plain "nan" in C, while python throws an exception. > One of the essential problems is that every library does certain > things differently, like deciding whether it's going to start up with > silent or signaling NaN's, or what the actual string values are for > NaN, infinity and so forth. I do understand that string representations may be a problem here (that's exactly what PEP 754 would address) but I don't touch strings anywhere so far. And the behaviour for binary representations is perfectly well defined by the IEEE standard. Maybe there are old libraries out there that don't implement this correctly, but why let them spoil the fun to all others? > It takes developer time to clean up that situation. I suspect > that volunteers would be very welcome. Of course - I will not debate about that. :-) Ciao, Nobbi From jjl at pobox.com Wed Aug 20 09:33:34 2003 From: jjl at pobox.com (John J. Lee) Date: 20 Aug 2003 14:33:34 +0100 Subject: Python should try to displace Java References: Message-ID: <87oeykh2s1.fsf@pobox.com> margerum at yahoo.com (Mike Margerum) writes: > C++ is dead? Better not tell that to the embedded/PDA/Phone world. > Seems to be working really well there and thats where the growth is. > Why do you think Sun is putting so much effort into J2ME? Good point. Out of curiosity, much much memory / how fast are these devices? More interestingly, how long will it take for Moore's law to make C++ more expensive overall than Python? Not long, I suspect. John From vanevery at 3DProgrammer.com Mon Aug 18 14:11:44 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Mon, 18 Aug 2003 11:11:44 -0700 Subject: What's better about Ruby than Python? References: Message-ID: dan wrote: > > Dude, what is it with you? > > Download Python, download Ruby, check them out for yourselves. Make > up your own mind instead of depending on others (with whom you rarely > agree anyway). Why do you assume that I'm asking these questions in order to understand how to program in either? I want to know what people's *perceptions* are. Subscribe to marketing-python if you want to puzzle me out more. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From tjreedy at udel.edu Thu Aug 21 01:17:25 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 21 Aug 2003 01:17:25 -0400 Subject: Dictionary that uses regular expressions References: <1f0bdf30.0308202049.7d251469@posting.google.com> Message-ID: "Erik Lechak" wrote in message news:1f0bdf30.0308202049.7d251469 at posting.google.com... > Hello all, > > I wrote the code below. It is simply a dictionary that uses regular > expressions to match keys. A quick look at _test() will give you an > example. > > Is there a module that already does this? Not that I know of > Is there a way and would it > be better to use list comprehension? (using python 2.3) List comp builds a list. Your __getitem__(s,key) code builds an ReDict, not a list. If you extended your initializer to initialize from a list of items (by passing the list of items on to dict.__init__), then you could build such a list with a l.c. and initialize your return ReDict from that. IE (untested, obviously, and it's late...) return ReDict( [item for item in self.items if re.search(key,item[0]) ] ) If you were always (or even almost always) matching by re's, you might as well just use a list of items (key,value). If you really must mix normal and re retrieval, but only after the dict is built and stable, then keeping items() as an attribute rather than re-extracting it for each re access would be faster. Terry J. Reedy From gh at ghaering.de Thu Aug 7 05:21:01 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Thu, 07 Aug 2003 11:21:01 +0200 Subject: using like and % in MySQLdb In-Reply-To: <20030807043808.GA23514@dave@alana.ucc.usyd.edu.au> References: <20030807043808.GA23514@dave@alana.ucc.usyd.edu.au> Message-ID: <3F3219FD.8060300@ghaering.de> Dave Harrison wrote: > Im sure this is a really obvious problem but : > > self.curs.execute( > """SELECT * FROM user WHERE login LIKE '%%s%'""", [login] > ) > > will not work ... gives me an "unsupported format character ''' (0x27)" > > escaping the %'s with % as the doco recommends wont work either. [...] It _will_ work. You'll have to escape the first and the last percent sign with another percent sign and leave the %s in the middle untouched. Thus: "SELECT * FROM user WHERE login LIKE '%%%s%%'" -- Gerhard From clifford.wells at comcast.net Tue Aug 19 03:25:59 2003 From: clifford.wells at comcast.net (Cliff Wells) Date: Tue, 19 Aug 2003 00:25:59 -0700 Subject: Brandon's personal style (was) In-Reply-To: References: <38ec68a6.0308172319.431a4fde@posting.google.com> Message-ID: <1061277959.27697.112.camel@devilbox.homelinux.net> On Mon, 2003-08-18 at 23:17, Brandon J. Van Every wrote: > The problem here is, they aren't troll posts. You just perceive them to be. > Why you do, you'd have to answer for yourself. But I will hazard to guess: > you don't like it when certain questions are asked. You think they are > illegitimate questions, and that nobody, rationally speaking, should ask > them. You think the questions will always cause trouble, that we can count > on this from what we know about newsgroup behaviors, so therefore the > questions should not be asked. In other words, you think you know best > about how discourse should properly proceed. There is a grain of truth to this. Certain questions and conversations almost inevitably lead to flame wars. This is well-known to long-term usenet users. This is why people who ask such questions are usually referred to the archives where such battles have been waged ad nauseum. There is a definite tendency to try to deflect such battles before they begin. To try to force those battles is about as reliable an indicator of trolling as is "URGENT: YOUR IMMEDIATE ASSISTANCE REQUIRED" is a reliable indicator of Nigerian spam. It should come as no surprise to you that people mistake your posts as trolling. They may be incorrect, but it is certainly a reasonable assumption. As such, the burden is on you to demonstrate otherwise. To do otherwise is simply taking advantage of the fact that this ng isn't moderated (in which case you would certainly have been moderated out of existence by this point). You seem to be under the impression that people here are hostile to certain points of view, but I'm aware of at least one time in the past year or so when the topic of forcing someone from the ng came up and most were vehemently opposed to such tactics, even though the person in question had irked everyone to no end. Like most groups of people with an intellectual leaning, people here tend to be fairly skeptical. Making inflammatory assertions with no supporting arguments is bound to gather you the flames you seem to be asking for. > I am starting to wonder, if the high number of kills I've gotten in c.l.p > says something about community cohesion? I mean, I get kills in *every* > group I spend any time in, but the speed and volume of kills I'm getting > here is novel. It's usually much more isolated and sporadic than this. I > hereby pronounce c.l.p, Second Order Magnitude of community cohesion. You > guys aren't all in the same pocket or parrots of each other, but there are > clearly some trends. This is actually quite insightful. I'd agree that as a whole this ng is rather cohesive. Most people who come to this ng comment on its overall friendliness and helpfulness. That is something rather rare on usenet. Those of us who spend a good portion of our days here prefer it that way. And it isn't a "we don't take kindly to strangers" small-town mentality. Python is a pragmatic language and tends to attract pragmatic people. Long-winded dissertations on things not-Python tend to be tolerated to the extent the participants contribute to things Pythonic. Were you known to be a contributor, either with code or knowledge, your forays into time-wasting speculation would most likely be much better received. As it is the only "contribution" you've made is a generous use of other people's time and bandwidth. The fact that you get "kills" in every ng you spend time in probably says more about you than other people. Personally I've never killfiled anyone (not even the ruebot[!]) and to my knowledge, I've yet to be killfiled (although at times I'm a bit surprised at that, today being one of those times). As you've acknowledged in another post (although in somewhat different words), people tend to create the world they live in. You've also claimed to be a pugilist. Why then, are you surprised when people choose to fight with you? Taking your statements together would seem to indicate that a fight is what you want. People who actively seek fights in newsgroups are called trolls. You can take this to its logical conclusion as others already have. To quote another post of yours (see, I'm still reading): "Generally, it is broadening to put yourself in someone else's shoes." If others are (mis)perceiving you as a troll, then perhaps you should try to see it from their point of view for a moment. At the very least you'll have a better insight as to how their accusations should be addressed and might actually prevail in the argument. *plonk* is the sound the white flag makes when it hits the top of the post. Regards, Cliff -- Severance, the birds of leaving call to us Yet here we stand, endowed with the fear of flight -Dead Can Dance From jacek.generowicz at cern.ch Mon Aug 25 03:30:24 2003 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 25 Aug 2003 09:30:24 +0200 Subject: macro FAQ References: <1ffd32d9.0308232315.3eadd758@posting.google.com> <1ffd32d9.0308241136.6e5050c6@posting.google.com> Message-ID: dtolton at yahoo.com (Doug Tolton) writes: > Again, I wanted to focus the discussion for a moment to help alleviate > people's fear of Macro's, as they seem to be based on > mis-understanding what they are about. Please forgive my over > simplification. I was merely pointing out that I think that the security issue is completely orthogonal. > If you hate them that much, we can forget I ever posted them. :-p But Google won't :-) From news.collectivize at scandaroon.com Mon Aug 11 17:22:31 2003 From: news.collectivize at scandaroon.com (John Baxter) Date: Mon, 11 Aug 2003 14:22:31 -0700 Subject: wanted: alternative to LDAP References: <200308110616.h7B6G702021709@localhost.localdomain> Message-ID: In article , Gerhard Haring wrote: > Anthony Baxter wrote: > > I'm looking for something (usable from python) that provides networked > > directory/registry type functionality to a bunch of Linux and Solaris > > servers. > > LDAP's one alternative, but the LDAP servers are heavy heavy beasts, so I > > was > > hoping for something that's actually lightweight, rather than "lighter than > > X.500". > > The term "leightweight" doesn't say much to me. I don't care if a > process takes 1 or 2 MB ;-) What I do care about is ease of > configuration and that's why I use PostgreSQL in places other people use > LDAP: system users, mail accounts, mail forwarding, domain management, > etc. for a virtual hosting solution. > > The reason for going to an RDBMS instead of LDAP were for me: > > a) I know relational databases quite well > b) I know some LDAP, but always found it a pain to work with > c) The open source tools for editing LDAP data are quite weak > > The only advantage LDAP would have over a RDBMS to me is that OpenLDAP > seems to have integrated replication mechanisms. We use LDAP for several "simple" things having to do with user authentication, existence of mail boxes, etc. We use MySQL for many other things where designing LDAP looked too hard to the people doing the work (not me). Both openLDAP and MySQL provide for replication. MySQL's seems to just work...we've installed a monitor system to ensure that the LDAP replication is working (change a comment field in a designated record, wait a few seconds, and verify that the change is on each slave server). We "catch" openLDAP corrupting its database now and then (less frequently in the current version that before), and sometimes catch it refusing to talk until restarted, even though the database isn't corrupt. (slapd refuses to start if the database is corrupt...that's our cue that it's time to rebuild). Suggest you design your client programs so that if the primary server doesn't respond (the bind fails) the program will try other servers until one does...that feature of Exim has proven quite useful. Unfortunately, our POP/IMAP server doesn't do that. > > I reckon you wouldn't call an RDBMS more leightweight than LDAP, but I > don't think there are many alternatives apart from LDAP and RDBMS. Well, > there's NIS if for some reason you didn't know about it, yet :) > I've only used NIS somewhat "passively" on Mac OS X (a one-machine "network"). We don't run it. It looks tempting. --John -- Email to above address discarded by provider's server. Don't bother sending. From skip at pobox.com Fri Aug 15 11:48:16 2003 From: skip at pobox.com (Skip Montanaro) Date: Fri, 15 Aug 2003 10:48:16 -0500 Subject: dict->XML->dict? Or, passing small hashes through text? In-Reply-To: <20030815060420.GC5127@frobozz> References: <20030815042536.GA19960@incise.org> <16188.28023.216400.94715@montanaro.dyndns.org> <20030815055724.GB19960@incise.org> <20030815060420.GC5127@frobozz> Message-ID: <16189.192.938868.884095@montanaro.dyndns.org> >> > Check out xmlrpclib ... >> ... at first I was turned off because it implements its own little >> server, so I'd have to gut mine.... Andrew> It's possible to use xmlrpclib without running its builtin Andrew> server -- e.g. Twisted's XML-RPC support does this, and it's Andrew> not hard. There's also the SimpleXMLRPCServer module and class which makes it, well, simple, to implement such beasts. That might minimize the grief you experience gutting your existing server. Skip From borcis at users.ch Mon Aug 18 11:09:08 2003 From: borcis at users.ch (Borcis) Date: Mon, 18 Aug 2003 17:09:08 +0200 Subject: Py2.3: Feedback on Sets References: <%BX%a.4999$N37.3051@nwrdny02.gnilink.net> <7h3d6f3143s.fsf@pc150.maths.bris.ac.uk> Message-ID: <3F40EC14.4030202@users.ch> Michael Hudson wrote: > + isn't totally silly (strings and lists are > monoids, at least :-). list * int, OTOH, seems a bit smelly to me > (though I'm not sure what a better spelling would be...). But strings/lists form a non-commutative monoid, so list * list would be better imho, ans a corresponding list ** int From nospam at maniacxs.de Tue Aug 12 14:17:10 2003 From: nospam at maniacxs.de (Lukas Kasprowicz) Date: Tue, 12 Aug 2003 20:17:10 +0200 Subject: German umlaut in a string. Message-ID: Hi Folks, I have a string filled with much text converted from a tuple. when I try to do someting like this: exclusion = re.sub("\\xf6", "%F6", exclusion) # ? exclusion = re.sub("\\xfc", "%FC", exclusion) # ? exclusion = re.sub("\\xe4", "%E4", exclusion) # ? exclusion = re.sub("\\xdf", "%DF", exclusion) # ? it takes no effect at the string. things like: exclusion = re.sub(',', '', exclusion) exclusion = re.sub('\(', '', exclusion) exclusion = re.sub('\)', '', exclusion) exclusion = re.sub("'", "", exclusion) exclusion = re.sub(" ", "+%2D", exclusion) work fine. when i write the sting in a python console into a variable like: >>> test = "some\\xf6thing" >>> print re.sub("\\xf6", "%F6", test) some%F6thing I get the correct output. Why do I can not do a substitute on "\\xf6" or simmilar, but on other I can do it (like "\(") I tried with unicode() converting to I think it was from latin-1 to utf-8 and back. with the python console it worked but not with the string that was converted from tuple before. greetz Lukas -- --------------------------------------------------------- Das einzige Mittel gegen Aberglauben ist Wissenschaft. (Henry Thomas Buckle) From h.b.furuseth at usit.uio.no Fri Aug 29 13:04:01 2003 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth (nospam nospam)) Date: 29 Aug 2003 19:04:01 +0200 Subject: imports after function definitions? References: Message-ID: Terry Reedy wrote: >in message news:HBF.20030828usgy at bombur.uio.no... >> Is there any reason not to structure my program like this? >> >> def ... >> def ... >> var = ... >> var = ... >> import ... >> import ... >> main_function() > > It is helpful to human readers to see dependencies at the top and to > know what globals are avaiable when reading defs. What would be > compensating gain of doing such? I'm setting sys.path in a config function which depends on variables near the end of the file. So the config function must be called late, and the imports that depend on it after that. -- Hallvard From logiplex at qwest.net Fri Aug 22 16:56:36 2003 From: logiplex at qwest.net (Cliff Wells) Date: Fri, 22 Aug 2003 13:56:36 -0700 Subject: wxPython: need return value from wxFrame In-Reply-To: References: Message-ID: <1061585796.1506.325.camel@software1.logiplex.internal> On Fri, 2003-08-22 at 12:27, Mirko Koenig wrote: > On Fri, 22 Aug 2003 00:28:23 +0200, Cliff Wells wrote: > > > On Thu, 2003-08-21 at 15:17, Mirko Koenig wrote: > >> I have a frame where you can select/add/delte etc a customer address. > >> It is included in an wxApp to have a stand alone customer addressbook. > >> > >> Now i wrote a invoice application. I added a button to add a address to > >> the invoice. I want the customer addressbook to be open by clicking on > >> that button. No problem. So far so good. > >> > >> But i want the addressbook frame to return the selected address as a > >> tuple, list or dict. I don't have any idea how to do that. > >> > >> I can show() the frame from within the invoice code but show doesn't > >> return a value. > > > > Use a wxDialog instead. > > > > But how to return a list or tuple. All i can see is that a dialog returns > a int value Try something like this: import wx class MyDialog(wx.Dialog): def __init__(self, parent, id, title = "Test"): wx.Dialog.__init__(self, parent, id, title) sizer = wx.BoxSizer(wx.VERTICAL) self.text = {} for t in ['1', '2', '3']: self.text[t] = wx.TextCtrl(self, -1, "") sizer.Add(self.text[t], 1, wx.ALIGN_CENTRE|wx.ALL, 5) btn = wx.Button(self, wx.ID_OK, " OK ") sizer.Add(btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5) btn = wx.Button(self, wx.ID_CANCEL, " Cancel ") sizer.Add(btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5) self.SetSizer(sizer) self.SetAutoLayout(True) sizer.Fit(self) def GetValue(self): retval = {} for t in self.text: retval[t] = self.text[t].GetValue() return retval app = wx.PySimpleApp() dlg = MyDialog(None, -1) retval = dlg.ShowModal() if retval == wx.ID_OK: print dlg.GetValue() dlg.Destroy() app.MainLoop() > > Mirko Koenig -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 (800) 735-0555 From sross at connectmail.carleton.ca Thu Aug 14 09:49:24 2003 From: sross at connectmail.carleton.ca (Sean Ross) Date: Thu, 14 Aug 2003 09:49:24 -0400 Subject: Tuple to string problems References: <3f3b9080@dnews.tpgi.com.au> Message-ID: "Alastair G. Hogge" wrote in message news:3f3b9080 at dnews.tpgi.com.au... > So basicly final_qu would be ('1','two','hello','2003-08-14','23:32:07') > However has stated above type(final_qu) return tuple. If final_qu is already a tuple of strings, and what you need is one string with each string in the tuple concatenated, then you can do this: >>> final_qu = ('1','two','hello','2003-08-14','23:32:07') >>> final_qu_str = ' '.join(final_qu) >>> final_qu_str '1 two hello 2003-08-14 23:32:07' >>> If you can't guarantee that each tuple element is a string, try this: >>> final_qu_str = ' '.join([str(e) for e in final_qu]) >>> final_qu_str '1 two hello 2003-08-14 23:32:07' >>> [str(e) for e in final_qu] creates a list of a strings from the elements in final_qu. HTH Sean From mwh at python.net Fri Aug 29 08:00:35 2003 From: mwh at python.net (Michael Hudson) Date: Fri, 29 Aug 2003 12:00:35 GMT Subject: Garbage Collection Question References: <2ce55ce2.0308281518.4be94efc@posting.google.com> Message-ID: <7h3smnk4qxg.fsf@pc150.maths.bris.ac.uk> csv610 at yahoo.com (Chaman Singh Verma) writes: > I am trying to integrate C++ with Python. I read that Python does > automatic garbage collection. I am creating new objects in C++ and > passing to Python, I don't know now who should control deleting the > objects. Um, I think I need more detail to fully answer this. > If I create objects in C++ do I have to clean them or Python will > use GC to remove unwanted objects. As Aahz noted, Python only GCs objects it knows about, i.e. PyObjects. A common pattern is to have a custom Python object encapsulate one of your C++ objects. So you do something like this: static PyTypeObject Thing_Type; struct ThingObject { PyObject_HEAD Thing* thing; } PyObject* Thing_New() { Thing* thing = PyObject_New(ThingObject, &Thing_Type); thing->thing = new Thing(); return (PyObject*)thing; } void thing_dealloc(PyObject* thing) { delete ((ThingObject*)thing)->thing; thing->ob_type->tp_free(); } and make sure thing_dealloc ends up in the tp_dealloc slot of Thing_Type. HTH, mwh -- if-you-need-your-own-xxx.py-you-know-where-to-shove-it-ly y'rs - tim -- Tim Peters dishes out versioning advice on python-dev From peter at engcorp.com Wed Aug 20 11:32:53 2003 From: peter at engcorp.com (Peter Hansen) Date: Wed, 20 Aug 2003 11:32:53 -0400 Subject: Regex Question References: Message-ID: <3F4394A5.26C751B8@engcorp.com> Thomas G?ttler wrote: > > I want to parse a file that looks like this: > > a0001: basbasdb > asbddsb > asdbasdb > abasbd > a0002: fffff > ffff > ffffff > ffff > > a???? should be the key and the following lines should > be the value of a dictionary. > > My solution looks like this: > > regex=re.compile(r'(?:^|\n)(\w\d\d\d\d):((?:.(?!\n\w\d\d\d\d:))*)', > re.DOTALL) > matches=regex.findall(content) > for match in matches: > print match > > I think there is a better solution than this, don't you? It depends. Does this solution work, and run acceptably quickly? If so, there is no better solution. ;-) (To put it another way: define "better".) -peter From skip at pobox.com Tue Aug 19 11:08:16 2003 From: skip at pobox.com (Skip Montanaro) Date: Tue, 19 Aug 2003 10:08:16 -0500 Subject: Serious problem with Shelve In-Reply-To: <3F41C4DD.356912A4@yahoo.com> References: <3F3FB5B9.5E49B306@yahoo.com> <3F41BC50.91097FAF@yahoo.com> <3F41C4DD.356912A4@yahoo.com> Message-ID: <16194.15712.992084.629516@montanaro.dyndns.org> Rami> Incidentally, on the other machine I mentioned (the one on which Rami> shelve worked perfectly with 2.2.3) shelve still works perfectly Rami> after upgrading to 2.3. Since that is a Linux 2 machine, I figure Rami> perhaps it is using a different db like gdbm or something ... Try this using python 2.2.3 and python 2.3: import whichdb whichdb.whichdb(os.path.join(tgtdir, dbfn)) and see what it prints. That will keep you from guessing about the nature of the file. Skip From adalke at mindspring.com Mon Aug 18 20:19:52 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Mon, 18 Aug 2003 18:19:52 -0600 Subject: What's better about Ruby than Python? References: <38ec68a6.0308172319.431a4fde@posting.google.com> Message-ID: Brandon J. Van Every: > Maybe this is a > positive sign of Python's growth: it's got enough critical mass to attract > just about anybody, not just people who want to get things done. Which includes you, given that you started posting to this group about 7 months ago and still haven't programmed in it. > At any rate, welcome to my killfile. At this rate you won't have anyone left to read. I think you've plonked a good portion of the regulars. Andrew dalke at dalkescientific.com From jlh at cox.net Mon Aug 25 01:17:37 2003 From: jlh at cox.net (Jeff Hinrichs) Date: Mon, 25 Aug 2003 05:17:37 GMT Subject: Win32All - Services and current path Message-ID: I'm having trouble nailing down the path to the script directory when building a service. I am trying to read in a config file via ConfigParser. When I run the service in debug mode all is well. When I start it up normally, via 'myservice.py start' I can't get the directory where my service lives. When starting the service normally the current path when I try to read the file gets set to: G:\Python22\lib\site-packages\win32 probably because that is where pythonservice lives. So I can't use sys.path[0] or parse sys.argv[0] to find directory where my config file lives. I don't want to hardcode the path to the config file but currently that is the only way I can get the ConfigParser object to find my file. What am I missing? -Jeff From jjl at pobox.com Thu Aug 21 18:18:03 2003 From: jjl at pobox.com (John J. Lee) Date: 21 Aug 2003 23:18:03 +0100 Subject: ClientCookie bug (followup) References: <87fzk4sav2.fsf@pobox.com> <87znibzrnx.fsf@pobox.com> <87oeypdh92.fsf@pobox.com> <87k79a25pi.fsf@pobox.com> <84fc4588.0308182207.4c649b93@posting.google.com> <87ada5de3j.fsf@pobox.com> <84fc4588.0308200242.3e74e0a1@posting.google.com> <87smnwh3lp.fsf@pobox.com> Message-ID: <87wud6ejtw.fsf@pobox.com> Robin Munn writes: > John J. Lee wrote: [...] > > lack thereof -- it's just that the convention of using 'we' in source > > code comments is common enough that I've sometimes found myself using > > it even when writing code alone, which is funny.) > > I do that all the time; "we" is the default in my code comments and I > have rarely, I think never, used "I". I usually think of it as myself > reading through the code with another coder, who is tasked with taking > over code maintenance from me. I'm explaining to him what the code is > intended to do: "So here, we want to search through the list for..." That's a good excuse. :-) John From shlomme at gmx.net Thu Aug 7 03:36:10 2003 From: shlomme at gmx.net (Torsten Marek) Date: Thu, 07 Aug 2003 09:36:10 +0200 Subject: Database question..... In-Reply-To: References: Message-ID: John D. schrieb: > I have a small (fewer than a few thousand records) database with the > following properties: > > Each record has four fields: A, B, C, D. > Fields A and B are unique: > there is one B for every A and one A for every B. > Fields C and D are not unique. > Sometimes I need to use A as the key, other times B is the key: > I use A to return B, C, D and also B to return A, C, D. > The items may all be represented as short ASCII strings. > > Currently I am storing this in a 100KB file and converting this to two > dictionaries. I am reading and writing the entire file to update single > records, which is inefficient. I am thinking about using anydbm, but then > how do I do the two-way dictionary lookup? Would I have to store the whole > database twice? What if I had ten items, would I have to store it ten > times? Is this what a relational database allows? > First of all, why do you convert it to two dictionaries? As long as I am not missing something, you only should need one. Let's say you have a tuple of tuples with your values and a dictionary: a = {} b=(("a", "b", "test1", "test2"), ("c", "d", "test3", "test4")) for i in b: a[i[0]] = i a[i[1]] = i del b print a["a"] print a["d"] Ok, now there was a problem if b[1][1] would be "a" instead of "d", so it might be a solution to prefix the dict keys with some other character like "_" and "-" which has to be added for every lookup. Now to the file: If you are going to save an additional value P for position in your dictionary, you could jump to this record's position in the file, but you might need fixed record length. If you use a SQL database, you should would have one table and mark the columns A and B as unique. Lookup would be (given the upper example values from b) > SELECT A,C,D FROM table WHERE b = "d" gives you ("c", "test3", "test4") > SELECT A,C,D FROM table WHERE a = "c" gives you ("d", "test3", "test4") and so on. Further, you would not be able to insert duplicate keys because the database does not allow this. MySQL has some interesting additions to SQL in that case, there is REPLACE INTO... (which should be handled with care because it replaces (!) the values) and INSERT...ON DUPLICATE KEY UPDATE... which is IMHO a lesser killer feature, but only available in 4.1, which is still alpha. greetings Torsten From achrist at easystreet.com Sat Aug 16 17:01:57 2003 From: achrist at easystreet.com (achrist at easystreet.com) Date: Sat, 16 Aug 2003 14:01:57 -0700 Subject: GUI builder for Python References: Message-ID: <3F3E9BC5.D92CFF61@easystreet.com> Kenneth Bergmann wrote: > > I like BoaConstructor myself. > Easy > Quick > Builds a nice interface > > ......And three out of three ain't bad > Just a couple flaws, but nothing minor: Doesn't do sizers. At my settings (800x600 large fonts) displays some things off the screen and impossible to get back on. Al From skip at pobox.com Thu Aug 7 13:09:17 2003 From: skip at pobox.com (Skip Montanaro) Date: Thu, 7 Aug 2003 12:09:17 -0500 Subject: Freeze Question In-Reply-To: References: <16174.45250.408648.333929@montanaro.dyndns.org> Message-ID: <16178.34749.356683.239307@montanaro.dyndns.org> Dave> I'm to the point where two modules are not found by freeze: Dave> Warning: unknown modules remain: pcre strop Dave> There is no mention of these in my Modules/Setup file. Any Dave> suggestions. I think you can probably omit both, though if freeze is figuring things out for you automagically, you may need to tweak Lib/string.py and Lib/re.py to dispense with them. The strop module is an extension module which used to be used to speed up the string module. With string methods it's no longer needed. It's in Modules/stropmodule.c. Pcre is pretty kaput as well. That was the first incarnation of Perl-compatible regular expressions, since replaced by the new sre module. It's in Modules/pcremodule.c. I suspect Modules/pypcre.c is part of the mix as well. Skip From max at ucmg.com.ua Mon Aug 18 04:03:21 2003 From: max at ucmg.com.ua (Max Ischenko) Date: Mon, 18 Aug 2003 11:03:21 +0300 Subject: Needs DB-API to connect to SQL Server 2000 In-Reply-To: References: <20030816.23383100.1745684727@linux.local> Message-ID: >> Does anyone know where I can find a DB-API to connect to SQL Server 2000? >> > > I use mxODBC; > > http://www.egenix.com/files/python/mxODBC.html Another good option could be ADO-based DB-API, http://adodbapi.sf.net -- Max Ischenko, Software Engineer UCMG, IT dept. From aleax at aleax.it Wed Aug 6 07:37:27 2003 From: aleax at aleax.it (Alex Martelli) Date: Wed, 06 Aug 2003 11:37:27 GMT Subject: Checking for an "undefined" variable - newbie question References: Message-ID: Dan Rawson wrote: > How do I check if a variable has been defined?? > > The following don't appear to work: > > if variable: > > if variable is None: > > > I have only one (ugly) solution: > > try: > variable > except NameError: > ... This is the canonical solution. Personally, I find it quite nice that an ugly architecture (such as one based on whether a variable is already defined/initialized rather than initializing it at the start with a unique value and testing for that!) requires an ugly way of expressing it. Unfortunately there are nicer ones such as "if 'variable' not in locals() and 'variable' not in globals():" but at least they're verbose and slow:-). If you can't rule out (e.g.) None as a valid value for your variable, just make a unique placeholder value such as [be sure to use a MUTABLE value, else uniqueness is not guaranteed]: class _uninitialized: pass initialize your variable at the start of your scope with variable = _uninitialized and test at any point within that scope whether the variable is still uninitialized or has been assigned an actual value by if variable is _uninitialized: It seems to me that this is far preferable to any approach based on _not_ binding the name 'variable' at all and later needing to test whether the name is bound or not. Alex From achrist at easystreet.com Sun Aug 3 03:41:54 2003 From: achrist at easystreet.com (achrist at easystreet.com) Date: Sun, 03 Aug 2003 00:41:54 -0700 Subject: PyChecker work with Python 2.3? References: <3F2C5300.FA223CBA@easystreet.com> Message-ID: <3F2CBCC2.3FC51D57@easystreet.com> Gerhard H?ring wrote: > > achrist at easystreet.com wrote: > > The pychecker site says that pychecker works with versions > > 1.5 through 2.2. Any reason to expect that 2.3 breaks it? > > Anyone tried it to see? > > Why don't *you*? > Smart people learn from their mistakes. Very smart people learn from other people's mistakes. Al From __peter__ at web.de Sun Aug 31 08:20:46 2003 From: __peter__ at web.de (Peter Otten) Date: Sun, 31 Aug 2003 14:20:46 +0200 Subject: list.sort(func) speed References: Message-ID: mackstann wrote: > So basename() is not the bottleneck, but accounts for perhaps 1/6th of > the time needed overall. I just wonder if the other 5/6th could be > reduced further by doing something that I'm not thinking of. I've tinkered with your code a bit and could not come up with something faster :-( However, your songs seem to correspond to files, so why not store them in your list as (filename, directory) or (filename, fullpath) tuples in the first place? Personally, I would go with a Song class, where the artist, length etc. could successively be added, but that would rather be trading speed for features... Peter From aleax at aleax.it Thu Aug 21 02:30:07 2003 From: aleax at aleax.it (Alex Martelli) Date: Thu, 21 Aug 2003 06:30:07 GMT Subject: What's better about Ruby than Python? References: <3F41505F.69D18CC8@alcyone.com> <66d7kvonvb2n0nqbqahhd5roak7ur81sob@4ax.com> <3f43ef5d_4@127.0.0.1> <3F440A35.9030602@nyc.rr.com> Message-ID: Andrew Dalke wrote: ... > (Need to use the function instead of a class with __call__ > so that the method gets bound correctly. And I believe You could use a class if its instances where descriptors, i.e. supported __get__ appropriately -- that's basically what functions do nowadays. See Raymond Hettinger's HOWTO on descriptors -- a *wonderful* treatment of the subject. Alex From owner-mutt-dev at mutt.org Wed Aug 20 23:56:46 2003 From: owner-mutt-dev at mutt.org (owner-mutt-dev at mutt.org) Date: 21 Aug 2003 03:56:46 -0000 Subject: mutt-dev@mutt.org: Non-member submission from Message-ID: <20030821035646.20252.qmail@agent57.gbnet.net> Your submission to the list has been forwarded to the list owner for approval because you do not seem to be on that list. If you want to join the list, send email to , with "subscribe mutt-dev" in the message text (not the subject). From imbosol at aerojockey.com Sun Aug 3 14:30:31 2003 From: imbosol at aerojockey.com (Carl Banks) Date: Sun, 03 Aug 2003 18:30:31 GMT Subject: Singleton-like pattern References: <2259b0e2.0308010815.5dcb0b58@posting.google.com> <2259b0e2.0308020746.438d0e6b@posting.google.com> <2259b0e2.0308030616.4b3cf98e@posting.google.com> Message-ID: Michele Simionato wrote: > Steven Taschuk wrote in message news:... >> Quoth Michele Simionato: >> [...] >> > Actually you are right, I remember now that I got problems with >> > (args,kw) and at the end I used args,tuple(kw.items()). But I was >> > ensure if this was a good solution. >> >> I'd worry about the order of kw.items(). > > Yes, indeed. Also, the args tuple can contain nested dictionaries and > become unhashable; in such a case I should recursively flatten all > the dictionaries to tuples, taking in account the ordering. > To much work for me ...I have really to look at the cPickle solution. > How does it solve the ordering issue? Unfortunately, not well. >>> b = { 1: 1, 9: 1 } >>> b {1: 1, 9: 1} >>> c = { 9: 1, 1: 1 } >>> c {9: 1, 1: 1} >>> from cPickle import dumps >>> dumps(b) '(dp1\nI1\nI1\nsI9\nI1\ns.' >>> dumps(c) '(dp1\nI9\nI1\nsI1\nI1\ns.' -- CARL BANKS "You don't run Microsoft Windows. Microsoft Windows runs you." From missive at frontiernet.net Wed Aug 6 12:16:24 2003 From: missive at frontiernet.net (Lee Harr) Date: Wed, 06 Aug 2003 16:16:24 GMT Subject: Interactive Console in embedded Python References: Message-ID: In article , Pablo Yabo wrote: > Hi, > I'm runing some python code from a C++ win32 application. > I need a tool to debug the code in python that I run. > I would like to know if I can run a interactive console to dump objects, > etc. > Is it possible to get the string of the error messages instead of using > PyErr_Print? > Not sure this is what you need, but you might want to look at the code module: http://python.org/doc/current/lib/module-code.html From ekoome at yahoo.com Thu Aug 21 10:53:40 2003 From: ekoome at yahoo.com (Eric) Date: 21 Aug 2003 07:53:40 -0700 Subject: Help Dispatching Events on excel commandbar buttons Message-ID: I have the following function which creates buttons on Excel commandbar. The problem i can't get the buttons to hook up to events. For example, if i create four buttons only the fourth one fires the ButtonEvent, the rest do nothing. What am i doing wrong. Please help Eric --------------begin Function-------------------------- def CreateButton(self,menubar,buttons,images,captions, tooltips): """Create buttons on the Excel bar""" if menubar is not None: if buttons is not None: i=0 for button in buttons: button = menubar.Controls.Add(Type=constants.msoControlButton, Parameter="Greetings") button=self.toolbarButton= DispatchWithEvents(button, ButtonEvent) button.BeginGroup = True button.Width = "34" if captions: button.Caption =captions[i] if tooltips: button.TooltipText = tooltips[i] i+=1 ----------------------end Function------------------------------ From maxx at easynews.com Fri Aug 1 13:31:22 2003 From: maxx at easynews.com (maxx at easynews.com) Date: Fri, 01 Aug 2003 17:31:22 GMT Subject: SQL2000 database vs python, using mssqldb References: Message-ID: >import mssqldb >import MSSQL >db = MSSQL.connect('my_db_server', 'user', 'password', 'my_database') >## so far, so good > >c = db.cursor() >c.execute('select * from my_table') >## boom, error > >c.fetchall() >c.nextset() > >The ms sql enterprise manager shows me that the database and table is there. >Unfortunately, in python the error tells me: Invalid object name 'my_table' A long shot, but you might try prefixing the table name with the owner name. If the table was created by the 'sa' admin user the owner is likely 'dbo'. This can be especially important if the table was given an explicit owner, and the user executing the SQL are not the same. From ruach at chpc.utah.edu Fri Aug 8 18:12:55 2003 From: ruach at chpc.utah.edu (Matthew) Date: 8 Aug 2003 15:12:55 -0700 Subject: regular expression back references Message-ID: Greetings, I am having a problem using back references in my regex and I am having a difficult time figuring out what I am doing wrong. My regex works fine with out the back refs but when I try to use them it won't match my sample. It looks to me that I am using them no differently then my examples and documentation but to no avail. Here is my patteren: macExpression = "^[0-9A-F]{1,2}(\:|\.|\-)[0-9A-F]{1,2}\1[0-9A-F]{1,2}\1[0-9A-F]{1,2}\1[0-9A-F]{1,2}\1[0-9A-F]{1,2}$: And this is how I am using it: matched = re.match(macExpression, macAddress) I am trying to match mac addresses in the following formats 0:a0:c9:ee:b2:c0, 0-a0-c9-ee-b2-c0 & 0.a0.c9.ee.b2.c0 etc. I wasn't sure how to do it but then I read about back references and I thought that all was well... Alas If any one could lend a hand I would appreciate it very much. -matthew From sross at connectmail.carleton.ca Tue Aug 5 22:18:43 2003 From: sross at connectmail.carleton.ca (Sean Ross) Date: Tue, 5 Aug 2003 22:18:43 -0400 Subject: converting an integer to a string References: Message-ID: <2AZXa.2573$_a4.492504@news20.bellglobal.com> "Ken Fettig" wrote in message news:bgpl6401e66 at enews4.newsguy.com... > I have a quick simple question. How do you convert an integer to a string in > Python? >>> 1 1 >>> str(1) '1' >>> HTH, Sean From rxs141 at cwru.edu Sat Aug 2 23:46:26 2003 From: rxs141 at cwru.edu (Ravi) Date: Sat, 02 Aug 2003 23:46:26 -0400 Subject: Match beginning of two strings In-Reply-To: <3f2c7806.20532894@news.lexicon.net> References: <3f2c429e@nntp0.pdx.net> <3f2c7806.20532894@news.lexicon.net> Message-ID: > I don't think that os.path.commonprefix was designed with 200Gb of > data in mind. Inspection of Lib/*path.py gives one the impression that > it spends a lot of time discovering that the first element is a prefix > of itself. > > Ravi, You may need to drop down to C to get the speed you want for > your requirement to find the longest common prefix of two strings. Two > things puzzling me: (1) how you would do this with regular expressions > (2) you have 200Gb now, new data arriving at the rate of 1Gb per hour, > after a year you have almost 9000Gb; where are you putting it all? > BTW, I do hope your algorithm is not O(N**2) ... > > Cheers, > John > Well, I timed os.path.commonprefix with some typical data and it's pulling about 40usec per loop. So I did what I hated and coded a little function in C. Goes something like this. My reasoning is that usually the point where the strings start to differ is in the 30 - 50 character range. Basically the idea is the same as a binary search on a sorted array. Divide and conquer by going halfway each time. Read in both strings. Check to see if the first character matches. If yes: Check halfway through the string and see if that character matches Repeatedly check halfway until the difference point is found. Go back through from the difference point backwards and make sure the characters match from the start to the difference point. I timed it, and it seems to be doing about 3.5usec per loop. Using pipes, I can feed it directly into the processing program. Good enough for me. As for the data, it's data from a radio telescope that's being recorded. We do pattern analysis and reduce it to strings. By examining these strings (more analysis than just the first common bit of course), we can determine what data should be looked at further and what data is garbage. The 9000GB problem isn't all that bad, the stuff compresses extremely well, down to about 700GB for a year's worth. A couple of RAID arrays makes quick work of that. Thanks, Ravi From gafStopSpamData at ziplink.stopallspam.net Mon Aug 18 13:01:05 2003 From: gafStopSpamData at ziplink.stopallspam.net (Gary Feldman) Date: Mon, 18 Aug 2003 17:01:05 GMT Subject: Py2.3: Feedback on Sets References: <1rnljv8527o2phdjup4e9uji0kssf93svt@4ax.com> <16187.1433.780458.994728@montanaro.dyndns.org> Message-ID: <8712kvk6ns9keaos8upo03t06dcga3slqp@4ax.com> On Wed, 13 Aug 2003 23:07:18 -0500, Skip Montanaro wrote: > > Skip> That's a documentation bug then. > >See the patch I just submitted at > > http://python.org/sf/788509 > I appreciate your doing this, and my next step (while I wait for answers to my recently posted question) is to get into the bug system. But in thinking about this, I'm still unconvinced about the original wording. It says "... elements obtained from iteration." Iteration, in this context, is still an abstract concept. It describes the how. But as you've already pointed out, the how is implicit in the name of the argument. Just from a grammatical/semantic point of view, it ought to describe the what, i.e. "... elements obtained from this parameter," though "... updates the set by iterating over this parameter" works, too. In other words, I find it easier to infer that iteration is being used than to infer the source of iteration. Many thanks, especially for the patience being shown, Gary From ulope at gmx.de Wed Aug 27 13:26:52 2003 From: ulope at gmx.de (Ulrich Petri) Date: Wed, 27 Aug 2003 19:26:52 +0200 Subject: My future Python IDE article References: Message-ID: "David Mertz" schrieb im Newsbeitrag news:mailman.1061920192.21278.python-list at python.org... > Pythonistas, > > So c.l.py readers... make the case for your favorite one getting on the > list. I have a while to ponder the opinions advanced, should this > prompt some discussion (it may take a little while to order review > copies of commercial tools and/or get things installed). > You should definitely consider Boa-Constructor (be sure to use at least v. 0.23, better yet the recent cvs version). IMHO its the most "complete" python IDE at the moment. Ciao Ulrich From jo_gleizes at yahoo.fr Wed Aug 20 10:46:21 2003 From: jo_gleizes at yahoo.fr (joelgleizes) Date: 20 Aug 2003 07:46:21 -0700 Subject: debugging with wingIDE Message-ID: I try to debug a python project with WingIDE. I load my main file and launch debug session with Run button. I see a first message: "Listening for back-connection" and then appears this error message :"The debug process never connected back to WingIDE. Aborting debug session" I haven't seen anything in the error-log file What does it mean? Thank you From jjl at pobox.com Fri Aug 22 10:50:10 2003 From: jjl at pobox.com (John J. Lee) Date: 22 Aug 2003 15:50:10 +0100 Subject: Q: urlopen() and "file:///c:/mypage.html" ?? References: Message-ID: <87n0e1zqzh.fsf@pobox.com> "Michael Geary" writes: > > MAK wrote: [...] > > > If I were to use, say, Netscape to open this file, I'd specify it as > > > "file:///c:/mypage.html", and it would open it just fine. But > > > urlopen() won't accept it as a valid URL. I get an OSError > > > exception with the error message "No such file or directory: > > > '\\C:\\mypage.html'". [...] > f = urllib2.urlopen( 'file:///c|/mypage.html' ) Why does Python use a different syntax to the rest of the Windows world? John From vanevery at 3DProgrammer.com Tue Aug 12 22:23:45 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Tue, 12 Aug 2003 19:23:45 -0700 Subject: Python vs. C# References: Message-ID: I'm done with c.l.p for now, I've moved on to the marketing-python list. This has been an interesting proving ground, and I've gotten the information I came for, but productivity demands a move to a different venue. This post was CC:'d to me so I want to address one point: Brian Quinlan wrote: > Brandon wrote: >> >> I agree that people should write tests, but having written many, many >> of those for my own project, it is equally true that writing test >> cases slows down development. > > I think that depends on how efficient you are at writing tests. Python > offers a great testing framework to help you. No, writing tests consumes time. I measure my productivity in units of 4 hours, i.e. a half day. My worst bugs last me 2 days. There is no language written that will obviate the need to design a valid test case. Writing test cases is simply a slow process when you measure functional results over such small periods of time. I am 1 guy and don't have the luxury of armies of coders in an industrial environment to work with. I'm very efficient, and I know what fast and slow is. I do the tests when I know robustness is going to save engineering time. I avoid them for their own sake, it is a waste of time. Better to simply get working code exercised, and keep it all down to 1 code path so that everything continues to be exercised. >> Anything that provides testing "for free" is a boon. > > It is not free. You are accepting several limitations (e.g. object > must conform to a particular interface to be useable, all types must > be specified) to get a type of checking that is of questionable value. C++ style compiler checking helps. I've never met anyone who thinks otherwise. Pythonistas just habitually claim it doesn't have merit and complain about burdens imposed. To us C++ guys, it is no big deal. It is, frankly, the least of our troubles under C++. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From gh at ghaering.de Mon Aug 4 07:06:20 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Mon, 04 Aug 2003 13:06:20 +0200 Subject: how to convert ip address to dot notation In-Reply-To: <3F2E3C6C.2060707@is.lg.ua> References: <3F2E3C6C.2060707@is.lg.ua> Message-ID: <3F2E3E2C.90905@ghaering.de> Ruslan Spivak wrote: > Hello, python users! > > I have ip addresses in my mysql db in int value - 3232261127, for example. > How can i convert that to usual dot notation like 192.168.100.7? > > Thanks in advance. > Your help is very appreciated. If there's nothing in the standard library, something like def numIP2strIP(ip): l = [str((ip >> 8*n) % 256) for n in range(4)] l.reverse() return ".".join(l) should do. Or you could just use PostgreSQL where you you have a datatype for IP addresses :-) -- Gerhard From logiplex at qwest.net Tue Aug 26 17:02:23 2003 From: logiplex at qwest.net (Cliff Wells) Date: Tue, 26 Aug 2003 14:02:23 -0700 Subject: wxPython: need return value from wxFrame In-Reply-To: References: Message-ID: <1061931742.32726.236.camel@software1.logiplex.internal> On Tue, 2003-08-26 at 11:00, Mirko Koenig wrote: > On Fri, 22 Aug 2003 22:56:36 +0200, Cliff Wells wrote: > > > > app = wx.PySimpleApp() > > dlg = MyDialog(None, -1) > > retval = dlg.ShowModal() > > if retval == wx.ID_OK: > > print dlg.GetValue() > > dlg.Destroy() > > app.MainLoop() > > > > I tried but couldn't find a solution. > As i said before, i have a wxframe derivered class for my addressbook to > have a stand-alone addressbook. Stand-alone in my case means that it is a > app for itself. Not only a extra windows in the invoice application. > > It contains wxFrame specific things like status bar etc. > Therefore i could not deriver it from wxDialog. That isn't a problem in and of itself. The code above could be used with a wxFrame instead (with minor modifications). > I can't place a wxFrame in a sizer of a dialog. That would solve my > problem. > > Are there any other ideas? Maybe a better idea of exactly what you want would help. Your app has only a single wxFrame? You want that frame to return something? To what? I would think when the frame "returns" the app would exit if it's the only frame. Regards, -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 (800) 735-0555 From pinard at iro.umontreal.ca Tue Aug 12 15:21:20 2003 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois_Pinard?=) Date: 12 Aug 2003 15:21:20 -0400 Subject: Test to see if variable exists In-Reply-To: References: <2c6431ab.0308120759.26d6e124@posting.google.com> Message-ID: [Graham Breed] > lamar_air wrote: > > I need an if statement to test if a variable exists in a pyton script > locals().has_key('var1') The above could also be written: 'var1' in locals() However, whenever I need to test this (the need is rather unusual), instead of `if', I prefer writing: try: var1 except NameError: pass # `var1' does not exist else: pass # `var1' exists -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From vze4rx4y at verizon.net Thu Aug 7 00:51:25 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Thu, 07 Aug 2003 04:51:25 GMT Subject: Skipping on memory in Python classes References: Message-ID: "the_rev_dharma_roadkill" wrote in message news:fb91dbec.0308061948.2e328980 at posting.google.com... > Hi, > I'm a Python newbie, but I have some experience in other languages. > > I need to create about 100,000 instances of one class. Each instance > has two lists, one usually empty, the other containing exactly 200 > elements which differ widely between the 100,000 instances, but about > half of the elements in these lists will be empty strings: > > instance x (one of 100,000) contains: > list A, 200 elements but half are emptyString > list B, usually empty (None, not []), but can contain a few small > elements > variable X, a fairly short string. > I also set __init__, __cmp__, and an attribute access function. > > Question: How can a reduce the memory used to a minimum? > > I have already set __slots__ = A,B,X > and this shaved about 10% off of the used memory, which is well worth > it. > > Any other proven techniques out there? Is there much point in > creating a new metaclass for my class? How about replacing > emptyStrings with Nones? Is there a fast (runtime) way of translating > between '' and None? If the list of 200 elements doesn't change, it may be better to use a tuple instead of a list. If the list contents are all of the same type, the array module provides a space efficient storage solution. Empty strings are like None in that they all refer to a single object, so there are no savings there. Raymond Hettinger From jepler at unpythonic.net Sun Aug 24 15:54:17 2003 From: jepler at unpythonic.net (Jeff Epler) Date: Sun, 24 Aug 2003 14:54:17 -0500 Subject: suid Python script In-Reply-To: <11vaib.v36.ln@gnocchi.dialup.fu-berlin.de> References: <11vaib.v36.ln@gnocchi.dialup.fu-berlin.de> Message-ID: <20030824195412.GA29366@unpythonic.net> You need to sanitize the environment, there's no question about that. For instance, if you allow the user's value of PYTHONPATH to exist in the setuid script, then the user can load an arbitrary module instead of any of the builtin python modules. Note that the Python source distribution has something called Misc/setuid-prog.c. It seems to deal with the PYTHON* environment variables. Jeff From stefan.behrens.usenet at gmx.net Mon Aug 11 11:33:34 2003 From: stefan.behrens.usenet at gmx.net (Stefan Behrens) Date: Mon, 11 Aug 2003 17:33:34 +0200 Subject: py2exe and wxCalendarCtrl? In-Reply-To: <33803989.0308100833.788c1453@posting.google.com> References: <33803989.0308100833.788c1453@posting.google.com> Message-ID: Indeed it does Thanks! br/Stefan. P.S. Sad thing is only that upgrading to python 2.3 broke boa constructor... Miki Tebeka wrote: > Hello Stefan, > > >>I'm using python 2.2.3, wxPython 2.4.0.7, py2exe 0.4.1 > > On python 2.3, wxPython 2.4.1.2 and py3exe 0.4.1 it works. > > Miki. From habermacher at ia.lip6.fr Mon Aug 4 10:52:33 2003 From: habermacher at ia.lip6.fr (habermacher) Date: 4 Aug 2003 07:52:33 -0700 Subject: =?ISO-8859-1?Q?Linux_&_ex=E9cutable?= Message-ID: Bonjour, Est-ce que quelqu'un sait quel est le logiciel ? utiliser sous linux pour cr?er un ex?cutable correspondant ? du code source en python ? Je vous remercie par avance de vos r?ponses. Emilie. From mpeuser at web.de Thu Aug 7 05:32:36 2003 From: mpeuser at web.de (Michael Peuser) Date: Thu, 7 Aug 2003 11:32:36 +0200 Subject: Is there some Python + IDE/RAD for real speed development??? References: <96fda9ac.0308060611.56dfca7e@posting.google.com> <25a9ea3e.0308061055.1cc2b2dd@posting.google.com> Message-ID: Having looked for some time for Python GUI Toolkits (in contrast to GUI Builders/IDE which was the OP's concern) I found the following quite useful (mostly) C/C++ GUI Toolkits which have a Pythin binding: Tkinter Win32API/MFC Qt GTK wxWindows FOX FLTK Except for Win32API all seem to be portable, most even to Mac-OS X. The quality of the actual Python binding, ease of installation and (Python-) documation varies greatly. Be always aware the differences between fine an stable basis Toolkits and sometimes limited Python bindings! Functionality can as well be a matter. Of cause all provide Labels, Menus, Buttons, some Textedit, and some kind of Canvas. But what about HTML- (or RTF-) Rendering, Printing, "Standard Dialogues", OpenGL, Graphic Primitives,...... You should have a close look for that as well. All of them have some different way of addressing event loops..... I rate Qt very high, but it is VERY commercial as well... Note that wx is a - but what powerful! - layer upon native Base-GUIs: Win32API/MFC on Windows and GTK on Unix. So you can have a lot of layers .... Tkinter is not as bad as you should think, especially with Pmw, TIX and (habe a look at that!) Fredrik Lundh's WCK (aka Tk 3000), which is in some pre-alpha state however..... If printing is a matter, also have a look at ReportLab. Google for all the links... Kindly Michael "Jean Brouwers" schrieb im Newsbeitrag news:25a9ea3e.0308061055.1cc2b2dd at posting.google.com... > Edilmar, > > There are quite a few IDE/RAD tools available for Python, both > commercial and open source. See for example this list > > > > However, before deciding on an IDE/RAD tool for GUI development, > you must consider which underlying toolkit to use, Tkinter, > wxPython, PyQt, etc. That could limit your choice. > > HTH, /Jean > > > > Alex Martelli wrote in message news:... > > > > > > Edilmar wrote: > > > > > Hi, > > > > > > First of all, I'm new in Python... > > > >> > I have worked with manu langs and IDEs, like Delphi, VB, JBuilder, > > > Eclipse, Borland C++, Perl, etc... > > > > > > Then, today I think IDEs like Delphi have a excelent environment to > > > develop apps with little time. I saw many people talking about Python like > > > a easy lang to learn and to develop. But I have look at IDEs for Python, > > > or ways to develop GUIs with it, and I think it already is limited when > > > comparing with IDEs like Delphi. Is this afirmation true? > > > > I don't think you have considered all the available GUIs for Python, > > and, in particular, the commercial ones (like Delphi and its Linux > > version Kylix are commercial). For example, BlackAdder (which uses > > the same commercial Qt libraries which I believe Kylix uses) seems > > to have the "GUI painter" kind of tool that you require. If it's GUI > > painters you're after, I think you can find some, either commercial > > or free (not all in definitive versions, many will still be betas), > > for most toolkits you might want to use (PythonWorks makes a commercial > > one for Tkinter, I think one can use glade + gic [gic.sourceforge.net] > > for Gtk, I see somebody's already mentioned Boa for wx, etc, etc). > > > > > > > I look at wxPython and PyGTK, but the samples showed that we have to write > > > MANY LINES of code to do simple things. Many people have wrote about the > > > advantage of Python to write little code, but, when talking about GUIs, > > > I think it's not really true, right? > > > > If you want a code generator (particularly a tool that generates code > > based on a GUI you paint on-screen) that's not hard to find (particularly > > if, as in Delphi's case, you're willing to pay for one). The amount of > > code to be thus generated for typical GUI's (minus, that is, any logic > > behind them) won't be all that different between e.g. Python and Delphi's > > Object Pascal. If the code that's automatically generated does all that > > your application needs, then it makes no difference to you what language > > that generated code is in, of course. > > > > Python's advantages shine when you have to write code as opposed to being > > 100% satisfied with code automatically generated, and in that respect > > there is no real difference between GUI's (as soon as you need to > > customize the generated code or put custom logic behind it -- via > > inheritance, of course, it would be counterproductive to go and edit > > files produced automatically by a code generator) and other application > > areas. > > > > > > > Using Delphi, little or none code is need for many things, but wxPython > > > and PyGTK is the reverse! > > > > I assume you do not mean what you say, but rather that the GUI painter / > > IDE you use generates just about all code you need ("for many things") in > > Delphi's case, while you're apparently not using any code generator for > > either wxPython or pyGTK and therefore need to write all code yourself. > > So, if you want a code generator / GUI painter, get one... > > > > > > Alex From adalke at mindspring.com Wed Aug 27 13:36:24 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Wed, 27 Aug 2003 17:36:24 GMT Subject: Replacement for rexec/Bastion? References: Message-ID: Michael Chermside: > If you DO wind up going this route, I'm guessing that the code > to launch an untrusted-code-runner in a separate process would be > quite popular if it were released back to the Python community, > judging from the number of times this question gets raised. Maybe we can convince the Twisted folks to do this? ;) Andrew dalke at dalkescientific.com From dtolton at yahoo.com Mon Aug 18 19:13:06 2003 From: dtolton at yahoo.com (Doug Tolton) Date: Mon, 18 Aug 2003 23:13:06 GMT Subject: What's better about Ruby than Python? References: <2qc2kvsti2r6vfpr3tt9468go9qjf0sape@4ax.com> Message-ID: On Mon, 18 Aug 2003 15:09:44 -0700, "Brandon J. Van Every" wrote: >Doug Tolton wrote: >> >> Clearly you are interested in people's philosophical take on why you >> should've posted to the Ruby boards, because you take the time to >> respond to each and every criticism. > >I actually can't remember that I've deliberately done that. I expect I >probably haven't. At any rate, I do always take the time to let people know >that I'm putting them in my killfile. Such as yourself. You haven't said >anything awful, but you also went out of your way to make an otherwise >content-free post at my expense. Of what use is that to me? Eventually, >I'll whittle this group down to people who can take a simple, rational >question at face value, provide the needed info, and be done with it. Yes!! I wonder why he takes the time to continue posting to this group if we are all such idiots? Doug Tolton (format t "~a@~a~a.~a" "dtolton" "ya" "hoo" "com") From adalke at mindspring.com Fri Aug 22 01:18:24 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Fri, 22 Aug 2003 05:18:24 GMT Subject: What's TOTALLY COMPELLING about Ruby over Python? References: <240b1020.0308201722.d1b991c@posting.google.com> Message-ID: David Garamond: > Ah, but this improves readability for me. Some people might also argue > that all those underscores in Python code reduces readability. And how > many threads are lost for people complaining about having to write > 'self.foo' all the time? ;-) What if you had your editor expand '@' into 'self.'? (Not something I would do.) And how many Ruby threads are lost for people complaining about having to write 'end' . > > As a result, I wonder how well Ruby works as an embedded language. > > Not very badly, I think. mod_ruby, eruby, pl-ruby, jruby, ... Though the > last one is nowhere near usable as Jython right now. When I looked at Ruby a few years ago, I had concerns about how its thread system (a platform independent/non-native) system would interact with, say, POSIX threads or with an in-proc COM server. I never found out the answer for that. I also had concerns with its non-ref-count based garbage collection for C extensions, because the C/Fortran libraries I use most often for chemistry only pass opaque integer tokens around, and not raw pointers, so there's no way for Ruby to know when to dealloc things or what the proper deallocation order would be. > And what's not consistent about :: for namespace separator, $ for global > vars, @ for class vars, and so on? Python gets away with doing the :: and @ with just a name and a period. 'x' is local or global 'x.y' is the 'y' thingy in 'x', and 'x' could be a module, a class, or an instance So the inconsistency, from a Python view, is that the "get something from something else" is written in different ways depending on the source of the data. > The current > implementation of Ruby (Ruby 1.x) is admittedly not very fast, but it's > already much faster & efficient than Python for some things (like > creating and destroying objects/classes). How is that tested? I hear that new-style classes for Python are faster than old ones. Still, I decided to test out object creation on a machine which has an older version of Python and of Ruby installed. %python -V Python 2.2.2 %ruby --version ruby 1.6.5 (2001-09-08) [i386-freebsd4.4] % %cat t.py class Qwerty: def __init__(self, name): self.name = name for i in xrange(1000000): Qwerty("shrdlu") %cat t.rb class Qwerty def initialize(name) @name = name end end for i in 0...1000000 Qwerty.new("shrdlu") end %time python t.py 3.303u 0.000s 0:03.42 96.4% 774+1008k 0+0io 0pf+0w %time ruby t.rb 3.466u 0.185s 0:04.25 85.6% 5+889k 0+0io 0pf+0w % I deliberately chose Python code known to be slow. Here's the faster version %cat t.py class Qwerty: def __init__(self, name): self.name = name def main(): for i in xrange(1000000): Qwerty("shrdlu") main() %time python t.py 2.929u 0.000s 0:03.36 86.9% 773+1008k 0+0io 0pf+0w % Faster because 'i' is in local namespace (simple offset lookup in the list of local variables) vs. global namespace (dictionary lookup). Deliberately chosen because I don't know if Ruby has similar differences. Andrew dalke at dalkescientific.com From mis6 at pitt.edu Mon Aug 18 21:39:25 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 18 Aug 2003 18:39:25 -0700 Subject: What's better about Ruby than Python? References: Message-ID: <2259b0e2.0308181739.7b7f4110@posting.google.com> Alexander Schmolck wrote in message news:... > I want something like: > > >>> class X: > ... def amethod(self): return 'just a method' > ... > >>> x=X() > >>> class X: > ... def amethod(self): return 'ah, now THIS is better!' > ... > >>> x.amethod() > 'ah, now THIS is better!' > Yeah, I see what you mean. I have dreamed of redefining a base classes and having all its children automatically updated. This would be a potential source of confusion, however (i.e. I redefine my class at line 1242 of my code and the behavior of all the classes defined in the previous thousand of lines is magically altered, making harder to understand what the program is doing). Currently you can add methods to a base class instead, and it does work under inheritance too: >>> class B(object): ... pass >>> class C(B): ... pass >>> c=C() >>> B.m=lambda self:None >>> c.m() You can also change the class of an instance: >>> c.__class__=B However this does not work always in Python 2.3 (there is an issue with "heap" classes, a limitation to avoid redefining the boolean type). > I guess I must be overlooking > something here, because to me it seems entirely obvious that there should be a > straightforward mechanism for updating all instances of a class when the class > is redefined. > > Since I know of no such mechanism and python's current semantics seem pretty > moronic to me, I'm sure I must be missing something (python has an amazingly > low rate of "obviously stupid" design decisions, that still strike you as > stupid after you understood their rationale). So it's maybe about time > someone put me straight. Regular instances are automatically updated when you modify their class; however if I remember correctly I had problems updating classes which metaclass was modified (don't remember what problem exactly). Michele From klappnase at web.de Wed Aug 6 05:57:51 2003 From: klappnase at web.de (klappnase) Date: 6 Aug 2003 02:57:51 -0700 Subject: Capture output from stderr References: Message-ID: Jeff Epler wrote in message news:... > On Wed, Aug 06, 2003 at 12:30:13AM +0000, Grant Edwards wrote: > > I've always used a read handler for this in the past, and it worked fine. > > I don't have an example handy... > > ... this is found at _tkinter.createfilehandler() or > Tkinter.createfilehandler() [though this didn't work for me!], doesn't > exist on Windows (AFAIK), and seems to be undocumented in pydoc. I think > they're a wrapper on Tcl_CreateFileHandler, which has a manpage. > > Here's a little program I just put together, it shows the > output from a command in a scrolling text area, using popen and > _tkinter.createfilehandler. It doesn't do anything in particular about > stderr, but that's a matter of switching to popen4 or a friend (Another > way, on systems that use /bin/sh as their shell, is to use > 'exec 2>&1; actual command' as the popen argument). Other niceties need > to be observed, like making the Text and refuse keybooard > focus and be non-editable ... > > On my system, a good command that takes some time to execute and only > produces a few hundred lines of output is > $ python tktail.py rpm -qa > ... but that'll only work on systems with rpm. Something that would > work on more systems would be > $ python tktail.py "for i in /*; do echo $i; sleep 1; done" > > # The following code is placed in the public domain > import Tkinter, _tkinter, fcntl, os, sys > > t = Tkinter.Tk() > tx = Tkinter.Text(wrap="char") > tx.pack(side="left", expand=1, fill="both") > s = Tkinter.Scrollbar(orient="v", command=tx.yview) > s.pack(side="left", fill="y") > tx.configure(yscrollcommand=s.set) > > command = " ".join(sys.argv[1:]) > t.wm_title("%s - tktail" % command) > p = os.popen(command, "r") > pf = p.fileno() > > # Make reads from the popen'd command nonblocking > # (so read returns the bytes available without waiting) > fcntl.fcntl(pf, fcntl.F_SETFL, os.O_NONBLOCK) > > > def readfunc(fileobj, event_type): > bytes = p.read() > if bytes == '': > bytes = "***END OF OUTPUT***" > t.wm_title("%s - COMPLETED - tktail" % command) > _tkinter.deletefilehandler(p) > > # bbox is a true value if the specified location is visible > b = tx.bbox('end - 1l') > > tx.insert('end', bytes) > > # If the bottom line was visible before, scroll to the > # new bottom. > if b: tx.see('end') > > _tkinter.createfilehandler(p, Tkinter.READABLE, readfunc) > t.mainloop() > > Jeff Wow, it works! Thank you so much for your help Best regards Michael From lists at gregfortune.com Wed Aug 20 12:04:05 2003 From: lists at gregfortune.com (Greg Fortune) Date: Wed, 20 Aug 2003 09:04:05 -0700 Subject: PyQT installation problems References: Message-ID: First, there's a PyQT (actually called PyKDE) list for discussing these problems and you might get a more insightful answer there. Second, I've had problems exactly like that on machines when I tried to use the version of qt supplied with the distro. I'm not sure if I didn't get all the development headers installed, etc, but I've never had a problem when I compiled a new version of qt on the machine and then compiled/linked all the PyQt stuff against that new version. Just make sure you point all the PyQt related compilations at the new version of qt. Obviously, there's a lot of time/work involved in the solution above and the PyQt mailing list might have a better answer, but this should be a pretty failsafe solution... Greg Fortune Fortune Solutions Stelian Iancu wrote: > Hello all! > > I am trying to install eric3, the Python IDE. I've downloaded and > installed successfully sip-3.8, QScintilla-1.2 and PyQT-3.8. However, when > I try to install eric, I get the following error: > > Sorry, please install PyQt. > > I looked into the install script, then I opened a Python window and there > I tried import qt and I got the following error: > > Traceback (most recent call last): > File "", line 1, in ? > File "/usr/lib/python2.2/site-packages/qt.py", line 25, in ? > import libqtc > ImportError: /usr/lib/python2.2/site-packages/libqtcmodule.so: undefined > symbol: _ZNK9QSGIStyle9classNameEv > > I am using Mandrake 9.1 with the default Python (2.2.3) and Qt. > From aahz at pythoncraft.com Tue Aug 12 01:17:34 2003 From: aahz at pythoncraft.com (Aahz) Date: 12 Aug 2003 01:17:34 -0400 Subject: Slogan: Getting Rich Overnight References: Message-ID: In article , Graham Fawcett wrote: >"Brandon J. Van Every" wrote in message news:... >> Graham Fawcett wrote: >>> >>> "Python: stimulate powerful organisms under your fingertips, without >>> all the GUI mess!" >> >> "Organisms" is easily misread as "orgasms." > >...and GUI is a homonym of "gooey". Was my joke too obscure? > >i-thought-it-was-funny-in-context-ly yours, The problem was with neither messenger nor message. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From tzot at sil-tec.gr Sat Aug 23 09:40:17 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Sat, 23 Aug 2003 16:40:17 +0300 Subject: Modifying the {} and [] tokens References: <04cekv0s6ghjtuhl5j2gph7ltobdb5rsam@4ax.com> Message-ID: <62rekv0k4ucgrh46lkp27klq13pq8ppp5p@4ax.com> On Sat, 23 Aug 2003 09:16:13 GMT, rumours say that Geoff Howland might have written: [snip of python's by design inability to modify the base C types: dict, str, list etc] >Ruby has this built in, it's useful, it's complete. It's obvious what >is happening, so it's not unclean. It's allowed for other containers. It seems that code "terseness" is more important to you than code readability. I can sympathise with that, perhaps I'd like that too, but I believe I fully understand Guido's decisions over the years to disallow that kind of stuff. I really don't mind subclassing base types and using MyDict() instead of {}. I want to be able to make my own APIs (MyDict.update *could* blow whistles and roll twice on the floor before resetting the machine), but I also want a steady and well-known API for base types (dict.update *should* update a dictionary from another one). You can always roll off a customised Python interpreter, of course, but it won't be Python anymore. With all due respect, Geoff, if this stuff is really important to you, use Ruby. -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From kern at taliesen.caltech.edu Sun Aug 24 23:46:13 2003 From: kern at taliesen.caltech.edu (Robert Kern) Date: Mon, 25 Aug 2003 03:46:13 +0000 (UTC) Subject: Simple Dictionary Problem References: Message-ID: In article , google at hanger.snowbird.net (Kris Caselden) writes: > I'm still new to some of Python's finer details, so this problem is > probably an easy fix. I can't seem to loop through a dictionary whose > values are tuples. > > For instance: > > oldlist = {'name':(1,2,3)} > newlist = [] > for x1,x2 in oldlist: ^^^^^ Here's your problem. Iterating over a dictionary yields only keys, not key,value pairs. -- Robert Kern kern at caltech.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter From steinhardt at inpro.de Fri Aug 8 04:48:36 2003 From: steinhardt at inpro.de (x-herbert) Date: 8 Aug 2003 01:48:36 -0700 Subject: py2exe: "ImportError: No module named pywintypes" ...?? :-( References: <39c0c7.0308070301.190dff6a@posting.google.com> Message-ID: <39c0c7.0308080048.7e8f7c0@posting.google.com> Hi Thomas, thank you for the fast replay (I dont forget the "import py2exe") I?ll try your tips... May be have anybody a good solution... CU Ingolf From srijit at yahoo.com Fri Aug 15 22:08:39 2003 From: srijit at yahoo.com (srijit at yahoo.com) Date: 15 Aug 2003 19:08:39 -0700 Subject: Tkinter program crashes References: <221d8dbe.0308140955.658000d0@posting.google.com> Message-ID: <221d8dbe.0308151808.5c449fab@posting.google.com> Hello Members, Here are the details of Python Tkinter applications crash on my machine (Win 98, Python 2.3 and Win32all-157). This has happened whenever I try to run a Tkinter application. The application runs fine. The problem happens whenever I exit from the Tkinter application. This was happening with Python 2.3b1. It continued to happen when I uninstalled Python 2.3b1 and installed python 2.3. The only exception is IDLE. IDLE is also a Tkinter application. Other Python applications are yet to give problems. For example I was successful in running PyGTK applications on my same setup. For example when I ran the Tkinter code (refer below for the actual code) and exited from the application I got the following message. PYTHON caused an invalid page fault in module KERNEL32.DLL at 0167:bff7b9a6. Registers: EAX=00000000 CS=0167 EIP=bff7b9a6 EFLGS=00000246 EBX=011033a0 SS=016f ESP=0062f878 EBP=0062f888 ECX=01103370 DS=016f ESI=01105a98 FS=3c4f EDX=7efeff73 ES=016f EDI=01103370 GS=0000 Bytes at CS:EIP: ff 76 04 e8 13 89 ff ff 5e c2 04 00 56 8b 74 24 Stack dump: 0110484c 010f274f 01105a98 0000002e 0062f8d4 010f0c79 00000009 01103370 0062f98d 010f0c48 0000002e 010ef913 0000002e 00000001 010d9f40 0000002e I am unable to figure out the problem. I guess re-installing Python 2.3 will not help. I hope somebody will help me to run Tkinter applications comfortably on my machine. Otherwise I have to live without Tkinter applications (except IDLE) on my machine. I also know it does not happen on Win 2000 or Win XP. Now I cannot afford Win 2000 or XP. Regards, Srijit The Tkinter code which crashed my Win 98 machine is : import Tkinter class App(Tkinter.Frame): def __init__(self, master): Tkinter.Frame.__init__(self, master) self.button = Tkinter.Button( self, text="QUIT", fg="red", command=self.quit) self.button.pack(side=Tkinter.LEFT) def say_hi(): print "hi there, everyone!" self.hi_there = Tkinter.Button( self, text="Hello", command=say_hi) self.hi_there.pack(side=Tkinter.LEFT) if __name__ == "__main__": root = Tkinter.Tk() app = App(root) app.pack() root.mainloop() From halley at play-bow.org Wed Aug 6 03:56:26 2003 From: halley at play-bow.org (Bob Halley) Date: 06 Aug 2003 00:56:26 -0700 Subject: Copying objects style questions Message-ID: In dnspython I have a set class, SimpleSet. (I don't use Python 2.3's sets.Set class so I can keep supporting Python 2.2, and because the objects in my sets are mutable). The SimpleSet class has a single attribute, "items", which is a list. (I know a list is not going to lead to fast set operations in general, but my typical set has only one or two elements in it, so the potential performance issues don't really matter for my needs.) I then subclass SimpleSet to make other kinds of sets, e.g. RRset subclasses Rdataset which subclasses SimpleSet. RRsets and Rdatasets each add additional attributes. I want to have a copy operation which is an "almost shallow" copy. Specifically, all of the attributes of the object may be shallow copied except for one, the 'items' list of the SimpleSet, for which I want a new list containing references to the same elements, so that the user of the copy may add or remove elements subsequently without affecting the original. I can't use copy.copy()'s default behavior, because it is too shallow. I don't want to use copy.deepcopy() because it's too deep. I contemplated __copy__, __initargs__, __getstate__, and __setstate__, but they didn't seem to fit the bill, or seemed more complicated than the solution I ended up with (see below). I can, of course, write my own copy() method, but I don't want to require each subclass of Set have to make a copy() method which implements the entire copying effort. Rather I'd like cooperating superclasses; I'd like RRset to copy the name, and then let Rdataset copy its attributes, and then let SimpleSet do the copy of the items attribute. My first solution was like clone() in Java: In SimpleSet: def copy(self): """Make a (shallow) copy of the set. There is a 'copy protocol' that subclasses of this class should use. To make a copy, first call your super's copy() method, and use the object returned as the new instance. Then make shallow copies of the attributes defined in the subclass. This protocol allows us to write the set algorithms that return new instances (e.g. union) once, and keep using them in subclasses. """ cls = self.__class__ # I cannot call self.__class__() because the # __init__ method of the subclasses cannot be # called meaningfully with no arguments obj = cls.__new__(cls) obj.items = list(self.items) return obj In Rdataset, which subclasses SimpleSet: def copy(self): obj = super(Rdataset, self).copy() obj.rdclass = self.rdclass obj.rdtype = self.rdtype obj.covers = self.covers obj.ttl = self.ttl return obj I've also noticed that if I just make SimpleSet subclass list instead of having an "items" element, then "the right thing" happens with copy.copy(). I'm a little leery of subclassing the base types, because although I've done it to good effect sometimes, I've also had it cause odd problems because the built-in types behave a little differently than new-style classes in some cases. Also, at least in this case, it fails the is-a test. A set is *not* a list; the fact that I'm using a list is an implementation detail that I might not want to expose. So, what advice do Python experts have for this kind of situation? Should I keep the first solution? Should I subclass list in spite of my misgivings? Is there some other, more elegant solution I've missed? Thanks in advance! /Bob From belred1 at yahoo.com Mon Aug 25 23:38:30 2003 From: belred1 at yahoo.com (Bryan) Date: Tue, 26 Aug 2003 03:38:30 GMT Subject: Comments on my "Python Introduction" slides References: <33803989.0308240000.35b9bf1f@posting.google.com> <33803989.0308240644.3090f039@posting.google.com> <3f492761$0$49117$e4fe514c@news.xs4all.nl> Message-ID: i always seem to prefer using if key in dictionary: rather than if dictionary.has_key(key): i also seem to prefer using for line in file(fname): rather than for line in open(fname).readlines() not sure it's any better, faster, more readable... just my preference. so your frame 7 would be: def unique(fname): '''Prints unique lines in fname''' h = {} for line in file(fname): line = line.strip() if line not in h: h[line] = True print line --- frame 8: you should also list empty tuple, list and dict as having a False value too) frame 9: needs a note that it's for 2.3+ frame 10: IMO "Magic methods" has a negative connotation. but maybe it's the correct terminology frame 12: i know python has a c interface for c extension modules, but can't modules also be written is c++ (ie. boost?) frame 18-19: i would show the exact same example in each. it appears from your slide that wxPython is way more complicated than TK i enjoyed going though it... nice work... bryan From amk at amk.ca Thu Aug 28 09:34:47 2003 From: amk at amk.ca (A.M. Kuchling) Date: Thu, 28 Aug 2003 08:34:47 -0500 Subject: Celebrity advice References: <3F4CD2A2.DE7D05D2@engcorp.com> <23891c90.0308280317.ac68b38@posting.google.com> Message-ID: On 28 Aug 2003 04:17:56 -0700, Paul Boddie wrote: > P.S. And the reason why many people find ESR to be offensive or just > plain inappropriate is that one gets the feeling that he wants you to > buy into his whole agenda, whether or not that involves running around > with a firearm in the woods dressed as Obi-Wan or Yoda. For me the big problem with the recent statement is that it doesn't look very professional, coming from the president of a group. It should have been written more formally and without the invective, and having Star Wars references simply scream "loser in a basement". It's really a pity that open source has no really effective spokesperson at this time. * RMS is unbending in his convictions whether large (such as the value of free software) or small (the whole GNU/Linux naming thing). I admire his resolution, but it hampers his effectiveness as a speaker to mainstream media and businesses. * ESR started out pretty well: "CatB", whatever its flaws might be, is a useful set of observations. Some bits of them might have been anticipated by others, but he was the first to assemble them all together and there are new ideas in there. (I found the idea of project spaces to be new and illuminating.) But... none of the followup essays were as notable, and he hasn't developed anything very impressive (fetchmail is useful, but not tremendously impressive). Worst, now he seems to be rewriting the world to match his views. NTK is reliably snarky about it, but also dead-on: see the second item in "Hard News" at http://www.ntk.net/2003/06/06/. * Linus does a pretty good job as a public speaker, and he doesn't have any of RMS's or ESR's baggage, but he's also not very interested in the job. (The same goes for Guido.) The best candidate is Bruce Perens, IMHO. He has the technical background of working on a non-trivial project (Debian), yet writes and presents in a style that doesn't attract attention and doesn't let irrelevancies intrude. Compare his commentary on SCO (http://www.perens.com/SCO/SCOSlideShow.html) with ESR's counterblast. (To be fair, ESR's analysis of the code is also pretty good; the OSI letter is where it becomes unacceptable.) Here's hoping Perens' group, Global Technology Policy Institute, becomes a success. --amk From jjl at pobox.com Sat Aug 2 09:49:19 2003 From: jjl at pobox.com (John J. Lee) Date: 02 Aug 2003 14:49:19 +0100 Subject: Clicking a button on an web page. References: <28158ea1.0308011158.6cac0091@posting.google.com> Message-ID: <871xw4yxsw.fsf@pobox.com> dedoleo at hotmail.com (Dedoleo) writes: [...] > How should I go about writing a script that will simply click a button > on a web page at an interval? For example, if you're familiar with [...] Until somebody (me :-) writes a web browser-like API, that depends how the button is implemented in the HTML. Probably, just parse out the URL with a regular expression (re module), and do urllib2.urlopen(url). Post some HTML. Alternatively, if you're on Windows, search on Google Groups for IE automation group:comp.lang.python. Or see recent posts about PyKDE, HttpUnit / Jython, etc. John From jjl at pobox.com Fri Aug 15 18:43:30 2003 From: jjl at pobox.com (John J. Lee) Date: 15 Aug 2003 23:43:30 +0100 Subject: Strange re behavior: normal? References: Message-ID: <87smo2r17x.fsf@pobox.com> "Fredrik Lundh" writes: > Mike Rovner wrote: > > > With all due respect to Python and not trying to bend it to any other > > language I believe it trys to do what user expects. > > it does exactly what I expect it to do. > > You don't count. ;-) John From cmuser at hoho.sjc.ebay.com Wed Aug 20 11:02:58 2003 From: cmuser at hoho.sjc.ebay.com (Unexpected reply handler) Date: Wed, 20 Aug 2003 08:02:58 -0700 (PDT) Subject: Thank you! In-Reply-To: <200308201318.h7KDI12A021740@mailhost1.sjc.ebay.com> References: <200308201318.h7KDI12A021740@mailhost1.sjc.ebay.com> Message-ID: <200308201502.h7KF2w413823@hoho.sjc.ebay.com> Subject: This is an AutoResponse from eBay Thank you for your response. As this is an automated email, please do not reply. If you have a question for eBay Customer Support, please visit the following eBay Help page. This page will help you locate the answer to your question, or assist you in contacting eBay Customer Support. http://pages.ebay.com/help/index_popup.html To change your notification preferences, which determine how you would like eBay to communicate with you, please visit our Notification Preferences Change page (please note that it might take a few days to process your request). http://cgi3.ebay.com/aw-cgi/eBayISAPI.dll?OptinLoginShow As always, we appreciate your patronage. Regards, eBay -- From faizan at jaredweb.com Fri Aug 1 18:00:47 2003 From: faizan at jaredweb.com (Fazer) Date: 1 Aug 2003 15:00:47 -0700 Subject: String Replacement Message-ID: <7b454334.0308011400.266438f9@posting.google.com> Hello, As some of you might know, I am new to Python. I was finally successful in using MySQLdb for Python to query the datbase and get a few results from the query. The results will be displayed as HTML and I am sort of confuse din using the string modules and its functions/modules to replace the \n with
. I import the string module and I am not soo sure on how to do the replacing. Here's how my code sort of likes: import string string.replace(DataFromDatabase, "\n", "
") Unfortunately, it doesn't work. Thanks in advance, Fazer From davidb at mcs.st-and.ac.uk Fri Aug 22 16:55:27 2003 From: davidb at mcs.st-and.ac.uk (David Boddie) Date: 22 Aug 2003 13:55:27 -0700 Subject: crazy programming language thoughts References: <3f457487_7@corp.newsgroups.com> Message-ID: <4de76ee2.0308221255.66749ef@posting.google.com> "Paul D. Fernhout" wrote in message news:<3f457487_7 at corp.newsgroups.com>... > Ryan Lowe wrote: [More "natural" language syntax] > > i just want to say that i know i saw a similar idea in another language, a > > few years ago, but damned if i remember where or what language. i guess the > > language didnt make it:( but if anyone knows a language like this, PLEASE > > let me know. > > You may be thinking of Smalltalk. > http://www.smalltalk.org/ > although there are other languages with related phrasing (like in > HyperCard? and even COBOL?). My initial recollection was that Inform had this sort of syntax but a quick re-examination indicates otherwise: http://www.inform-fiction.org/manual/html/index.html http://www.inform-fiction.org/examples/index.html It has an interesting syntax, particularly for class and function definitions. David From shane at zope.com Thu Aug 28 14:20:15 2003 From: shane at zope.com (Shane Hathaway) Date: Thu, 28 Aug 2003 14:20:15 -0400 Subject: [Zope-dev] Zope 2.7 running with Stackless 3.0 In-Reply-To: <3F4E3CE1.5030405@tismer.com> References: <3F4D44EB.5010500@tismer.com> <3F4DF1E7.1010103@zope.com> <3F4E3CE1.5030405@tismer.com> Message-ID: <3F4E47DF.9060800@zope.com> Christian Tismer wrote: > Stackless 3.0 does all of it, whatever is possible. > That means, you can switch whatever, even extension > C code with Python callbacks. But cooperative code > can switch faster. I'm very happy to hear you've forged onward. I was concerned you had given up. >> But Zope has a lot of reentrant code, especially in Acquisition and >> ZODB. Doesn't that prevent Zope from taking advantage of Stackless >> continuations? > > > No continuations, tasklets. :-) Did you switch the terminology? Where can I read about Stackless 3.0? For the uninitiated: Stackless lets a Python program break out of the rigid constraints of a simple stack. It lets Python code manipulate its own execution. It provides new solutions to problems like threading, debugging, network communication, etc. It's a very interesting shift. BTW, here's one avenue you might pursue, Christian: Python IDEs. When I wrote the debugger for Boa Constructor, I hit a big wall. Since Python is a dynamic language, one would expect to be able to pause the execution of a function, change the function, and resume execution with new code--never skipping a beat. But CPython makes this nearly impossible. I imagine Stackless would provide an answer for this. If it does, get in contact with ActiveState, Secret Labs, or the Wing IDE folks and tell them you can make their debugger twice as good as any other. Just an idea. Shane From enoch at gmx.net Wed Aug 6 18:09:02 2003 From: enoch at gmx.net (enoch) Date: 6 Aug 2003 15:09:02 -0700 Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> Message-ID: aahz at pythoncraft.com (Aahz) wrote in message news:... > In article , > enoch wrote: > >anthony_barker at hotmail.com (Anthony_Barker) wrote in message news:<899f842.0307310555.56134f71 at posting.google.com>... > >> > >> What to you think python largest compromises are? > > > >Its non existant SMP scalability. > > Would you care to back up your claim with some actual evidence? > > (Yes, there are issues with Python on SMP machines, but to call Python's > built-in threading "non-existent SMP scalability" is either a lie or > revelatory of near-complete ignorance. Ok, I confess, the term you cited might be little bit exaggerated. But there's no need to get personal. I'm surely not a liar (w.r.t. to this thread, everything else is not a matter of public concern ;) ). The ignorance part, well, we can talk about that ... > That doesn't even count the various IPC mechanisms.) Correct me if I'm wrong, but I don't think any form of IPC is a measurement of scalability of something like the python interpreter. Here are some sources which show that I'm not alone with my assessment that python has deficiencies w.r.t. SMP systems: http://www.python.org/pycon/papers/deferex/ """ It is optimal, however, to avoid requiring threads for any part of a framework. Threading has a significant cost, especially in Python. The global interpreter lock destroys any performance benefit that threading may yield on SMP systems, [...] """ http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=utf-8&safe=off&selm=bekg96%24mi%241%40panix2.panix.com (note the author of that post) """ >My project will be running on an SMP box and requires scalability. >However, my test shows that Python threading has very poor performance >in terms of scaling. In fact it doesn't scale at all. That's true for pure Python code. """ I'm aware that you know quite well about these facts, so I'll leave it at that. But let me just add one more link which maybe you don't know: http://www.zope.org/Members/glpb/solaris/multiproc """ Well, in worst case, it can actually give you performance UNDER 1X. The latency switching the GIL between CPUs comes right off your ability to do work in a quanta. If you have a 1 gigahertz machine capable of doing 12,000 pystones of work, and it takes 50 milliseconds to switch the GIL(I dont know how long it takes, this is an example) you would lose 5% of your peak performance for *EACH* GIL switch. Setting sys.setchechinterval(240) will still yield the GIL 50 times a second. If the GIL actually migrates only 10% of the time its released, that would 50 * .1 * 5% = 25% performance loss. The cost to switch the GIL is going to vary, but will probably range between .1 and .9 time quantas (scheduler time intervals) and a typical time quanta is 5 to 10ms. [...] However, I have directly observed a 30% penalty under MP constraints when the sys.setcheckinterval value was too low (and there was too much GIL thrashing). """ So, although python is capable of taking advantage of SMP systems under certain circumstances (I/O bound systems etc. etc.), there are real world situations where python's performance is _hurt_ by running on a SMP system. Btw. I think even IPC might not help you there, because the different processes might bounce betweeen CPUs, so only processor binding might help. I did quite a bit of googling on this problem - several times - because I'm selling zope solutions. Sometimes, the client wants to run the solution on an existing SMP system, and worse, the system has to fulfill some performance requirements. Then I have the problem of explaining to him that his admins need to undertake some special tasks in order for zope to be able to exploit the multiple procs in his system. Aazh, I'm lurking this newsgroup since approx. 3 years, so I know who you are. You have participated in nearly any discussion about threads, I know your slides, and there's no doubt that you have forgotten more about this subject than I'll never know. From rmunn at pobox.com Tue Aug 12 13:09:25 2003 From: rmunn at pobox.com (Robin Munn) Date: Tue, 12 Aug 2003 17:09:25 GMT Subject: ???? i can`t understand it References: Message-ID: Smille Purusa wrote: > Enrique wrote: > >>>>> a=[1,2,3,4,5] >>>>> for b in a: >> ... a.remove(b) >> ... >>>>> a >> [2, 4] >>>>> > Very interesting result but reasonable. If the underlying interpreter uses > a reference or pointer for the job like this: > > # psudo codes for python > for(ptr = a.first(); ptr.is_valid(); ++ptr) > { > update('b', value(ptr)) > call_method('a', 'remove', get_alue('b')) > } > > ptr may be just an index. So at the first iteration, the first element, '1', > is removed from a. The next time ptr=1, but a has been changed to [2,3,4,5], > so '3' is removed, and so on, This is exactly correct. From the Python reference manual, describing for loops: Warning: There is a subtlety when the sequence is being modified by the loop (this can only occur for mutable sequences, i.e. lists). An internal counter is used to keep track of which item is used next, and this is incremented on each iteration. When this counter has reached the length of the sequence the loop terminates. This means that if the suite deletes the current (or a previous) item from the sequence, the next item will be skipped (since it gets the index of the current item which has already been treated). Likewise, if the suite inserts an item in the sequence before the current item, the current item will be treated again the next time through the loop. This can lead to nasty bugs that can be avoided by making a temporary copy using a slice of the whole sequence, e.g., for x in a[:]: if x < 0: a.remove(x) You can read the whole thing at: http://www.python.org/doc/current/ref/for.html -- Robin Munn | http://www.rmunn.com/ | PGP key 0x6AFB6838 -----------------------------+-----------------------+---------------------- "Remember, when it comes to commercial TV, the program is not the product. YOU are the product, and the advertiser is the customer." - Mark W. Schumann From dtolton at yahoo.com Tue Aug 19 12:18:24 2003 From: dtolton at yahoo.com (Doug Tolton) Date: Tue, 19 Aug 2003 16:18:24 GMT Subject: What's TOTALLY COMPELLING about Ruby over Python? References: <3F41208F.40021A68@engcorp.com> Message-ID: On Mon, 18 Aug 2003 20:18:09 -0400, "John Roth" wrote: >I've been on c.l.py for around two years. Your statement >is rude and assumes things you have not bothered to check >out. > >There is a very simple rule for dealing with trolls, which most >usenet newbies learn sooner or later. If you think someone is >trolling, simply ignore them. Don't answer their posts, don't >comment on them, don't even give them the gratification of >a reply that says: "plonk!" Just killfile them and quit wasteing >bandwidth. You've got better things to do with your time than >maintaining an interaction that you find aggrevating. You're right, I did make an assumption that you were new to the group. A lot of people who are new make posts just like you did. Saying we shouldn't be too harsh on Brandon, after a while they realize maybe he is just a troll. Perhaps my post was a bit rude, I shouldn't have automatically assumed you were new to this NG, although I am a bit baffled at hearing a long time c.l.p reading calling Every anything but a troll. You have to admit, that is atypical. Doug Tolton (format t "~a@~a~a.~a" "dtolton" "ya" "hoo" "com") From staschuk at telusplanet.net Sun Aug 31 16:03:17 2003 From: staschuk at telusplanet.net (Steven Taschuk) Date: Sun, 31 Aug 2003 14:03:17 -0600 Subject: Confusion re "global" statement In-Reply-To: ; from bit_bucket5@hotmail.com on Sun, Aug 31, 2003 at 06:41:48PM +0000 References: Message-ID: <20030831140317.A1893@tibia.amotlpaa.bogus> Quoth Chris Stromberger: [...] > Can someone explain? I guess it has to do with the fact that I'm not > reassigning the name d in the function, but it seems counter-intuitive > that I'm able to modify a global inside the function w/o saying > "global d". Strictly speaking you're not modifying a global -- you're modifying a dict which a global name happens to be bound to. In detail: There's the name 'd' and the dict to which that name is bound. It is the name which is global; the dict just is. For example, d = {} def foo(x): x[3] = 4 foo(d) During the call to foo() here, x is bound to the same object as d; x is a local name, and d a global one. It is not meaningful to ask whether the dict to which they are both bound is local or global; the concept doesn't apply. So, since d[key] = value modifies the dict (adding an element to it) but does not modify the name d (which continues to refer to that dict), strictly speaking this code does not modify a global. The global statement is only needed when you are modifying a global in the strict sense -- as you said, when reassigning d. (Note that it would be practically impossible to require a global statement when merely modifying an object by way of a global variable, since the compiler can't determine whether statements such as d.some_random_method() some_random_function(d) modify the object known as d. The best the compiler could do is to require a global statement for *any* use of a global name; but this would be unbearably unwieldly, since you'd have to use a global statement to refer to other functions defined in the module, to modules imported in module scope, etc..) (Well, a different language might be able to infer mutation statically... anybody know of work in this area?) -- Steven Taschuk staschuk at telusplanet.net "I tried to be pleasant and accommodating, but my head began to hurt from his banality." -- _Seven_ (1996) From electricity at uymail.com Wed Aug 27 13:26:36 2003 From: electricity at uymail.com (U. N. Owen) Date: Wed, 27 Aug 2003 19:26:36 +0200 Subject: sed with python Message-ID: <20030827172636.25931.qmail@uymail.com> David Raleigh Arnold enlightened us with: > How do I use python as a wrapper for sed and/or gawk scripts? You don't. Python can do anything sed and awk can, and much, much more. Sybren That's true, but it may be useful to use existing code (and not bother rewriting in Python). You can use shell scripts, pipes, or if you want to use only python scripts, use os.system to call sed or awk. But if you write new functions, Python is enough, as Sybren says -- _______________________________________________ Get your free email from http://www.uymail.com Powered by Outblaze From nav+posts at bandersnatch.org Tue Aug 19 09:46:22 2003 From: nav+posts at bandersnatch.org (Nick Vargish) Date: 19 Aug 2003 09:46:22 -0400 Subject: 3 new slogans References: <13dc97b8.0308172102.5006b620@posting.google.com> Message-ID: "Brandon J. Van Every" writes: > Is Perl really the enemy? I don't see Microsoft backing Perl. I've got to say that BJVE actually has a point here. If there's one thing about the Python community that I've found perturbing, it's the attitude that "Perl is evil". Perl has many flaws, and I'm very glad I've done a s/Perl/Python/ in my own life, but Perl has been a useful tool and continues to be one of the main drivers of open source acceptance. Antagonism towards Perl just makes us look like cranks. I'm all in favor of Python advocacy, but I much prefer conversion by example rather than sword. The other implication of BJVE's post is that Microsoft is the enemy. I'll save that for a different post... Nick -- # sigmask || 0.2 || 20030107 || public domain || feed this to a python print reduce(lambda x,y:x+chr(ord(y)-1),' Ojdl!Wbshjti!=obwAcboefstobudi/psh?') From patrick at novaroot.com Sun Aug 3 17:30:02 2003 From: patrick at novaroot.com (Patrick Lioi) Date: 3 Aug 2003 14:30:02 -0700 Subject: 'print' in a CGI app. References: Message-ID: <2a82921f.0308031330.76c510fb@posting.google.com> "Andrew Chalk" wrote in message news:... > In a Python 2.2 app. running under CGI the statements > > print "Hello\n" > print "World" > > print both words on the same line in IE6. How do I print the second one on a > new line (i.e. respect the \n in the first statement). > > Many thanks! Run the app, then go to "View"->"Source" in the browser. $10 says they are on separate lines. All browsers are expecting HTML output from CGI scripts. HTML ignores whitespace. The
tag comes in handy for forcing an endline: print "Hello
" print "World" From Gerald.Klix at klix.ch Fri Aug 1 05:40:49 2003 From: Gerald.Klix at klix.ch (Gerald Klix) Date: Fri, 01 Aug 2003 11:40:49 +0200 Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> Message-ID: <3F2A35A1.2040403@klix.ch> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Anthony_Barker wrote: | I have been reading a book about the evolution of the Basic | programming language. The author states that Basic - particularly | Microsoft's version is full of compromises which crept in along the | language's 30+ year evolution. | | What to you think python largest compromises are? | IHMO it is the lambda expression. These "functions" are not real functions. You can not use statements in them. What Python realy needs here is some means to make an expression from a list of statements (called suite in the syntax defintion). That given PEP 308 (If-then-else expression) or PEP 318 (Function/Method Decorator Syntax) are mostly pointless. Let me give an example: Suppose there some special braces like (: :) and a exit operator like a unary ^ one can write a conditional expession like that: (: ~ if f(): ~ ^trueValue ~ else: ~ ^falseValue :) classmethods can be declared as follows: cm = (: ~ def im( arg0, arg1 ): ~ return answer ~ ^classmethod( im ) :) or cm = classmethod( (: ~ def im( arg0, arg1 ): ~ return answer ~ ^im ~ :) ) obvously this demands for some means to write anonymous functions like def ( arg0, arg1 ): ~ return arg0 - arg1 semanticly this should transform to (: ~ def newName( arg0, arg1 ): ~ return arg0 - arg1 ~ ^newName :) giving cm = def ( arg0, arg1 ): ~ return answer Ok, I admit that this is difficult to be integrated in the existing syntax. Perhaps we can not drop the braces around such expression. Is this worth writing a PEP? | |>"No, we use Unit Testing in Zope". I am still missing a simple testing framework. doctest is a good idea, but conflicts with syntax hilighting in most editors. | | | That said, obvious Basic compromised by using things such as "Option | Explicit", thereby allowing both dynamic and more static style | variables. Yahoo groups moved from python to C due to dynamic typing. This is not a problem. They key to speed is using extension written in C for performance. Normaly you will find one that sloves your problem. | | Non-compiled - obviously there are times when performance matters more | than other things. Google I believe uses python to prototype (or used) | and then turns to c++ for heavy lifting. | | What about immutable strings? I'm not sure I understand Guido's | preference for them. In fact the array module provides mutable strings. | | Anthony | http://xminc.com/anthony HTH, Gerald -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (GNU/Linux) Comment: Using GnuPG with Debian - http://enigmail.mozdev.org iD8DBQE/KjWgEDg9cqFA1jQRAovzAJkBygPzdfHsoVXu9H2QHnxTD9sMmACdHvY5 dB1j4kXTzejml7fG0oSwhUg= =WGR+ -----END PGP SIGNATURE----- From jim.easterbrook at rd.bbc.co.uk Fri Aug 22 04:38:19 2003 From: jim.easterbrook at rd.bbc.co.uk (Jim Easterbrook) Date: Fri, 22 Aug 2003 08:38:19 +0000 (UTC) Subject: displaying video in a tkinter GUI References: Message-ID: In article , Mark Hertel wrote: > >Is it possible to embed a video player on a tkinter frame? I'm >looking to create something that displays the video and its >associated controls in the upper right quandrant while the other >screen quandrants are used for user input. > >It would be great if the solution was cross platform (windows/linux) >but the initial target would be winXP/2K. For a Windows only solution, I've used DirectShow via Mark Hammond's win32com extension, and more recently via Thomas Heller's ctypes COM framework. I've been working at a lower level than a complete player (I've been building DirectShow filter graphs and using tkinter buttons for "play", "pause" etc.) but I expect you could embed a full Windows Media Player. -- Jim Easterbrook BBC Research & Development *** All opinions are mine and might not be shared by the BBC *** From __peter__ at web.de Sat Aug 16 04:11:11 2003 From: __peter__ at web.de (Peter Otten) Date: Sat, 16 Aug 2003 10:11:11 +0200 Subject: Iterator - what I am missing References: <3f3bde30$0$297$ba620e4c@reader1.news.skynet.be> <4aSdncbiYfIsgqGiU-KYgw@comcast.com> Message-ID: Terry Reedy wrote: > def __iter__(self): > current = self.Head > while 1: > if current == None: raise StopIteration > yield current > current = current.NNd() > This can be simplified: def __iter__(self): current = self.head # uppercase attributes are ugly while current is not None: yield current current = current.nextNode() # no crptc abrvtns pls, Helmut :-) The StopIteration exception is raised implicitely at the end of the method Peter From staschuk at telusplanet.net Thu Aug 28 01:52:32 2003 From: staschuk at telusplanet.net (Steven Taschuk) Date: Wed, 27 Aug 2003 23:52:32 -0600 Subject: another puzzled newbie In-Reply-To: <68g3b.855589$ro6.16997110@news2.calgary.shaw.ca>; from elainejackson7355@home.com on Thu, Aug 28, 2003 at 05:09:22AM +0000 References: <68g3b.855589$ro6.16997110@news2.calgary.shaw.ca> Message-ID: <20030827235232.A15412@tibia.amotlpaa.bogus> Quoth Elaine Jackson: > The analogous thing works fine in interactive mode, [...] I'm not sure what this means. > [...] but when I put it in a > script, the function singlePass (below) causes a compile-time error. [...] > postshuffled+=[preshuffled[shuffler[0]] There's a ']' missing here, which explains the SyntaxError, in interactive mode or otherwise. (Btw, there's no need for the parentheses in a del statement; del preshuffled[shuffler[0]] # etc. is just as effective, and imho better style.) -- Steven Taschuk staschuk at telusplanet.net "[T]rue greatness is when your name is like ampere, watt, and fourier -- when it's spelled with a lower case letter." -- R.W. Hamming From wolfoxbr at hotmail.com Mon Aug 18 09:14:30 2003 From: wolfoxbr at hotmail.com (Roberto Amorim) Date: Mon, 18 Aug 2003 10:14:30 -0300 Subject: What's better about Ruby than Python? References: Message-ID: > 6. The way Ruby handles parameterless functions as if they were > properties. That's the thing I like most about Ruby. But I couldn't get past its Perl-like syntax and the garbage collector (the latter when mixed with embedding). Anyway, since Ruby 1.8.0 is (finally) out, I'll try it again to see if it can be a viable alternative to Python (at least on some areas), but I doubt it. Python, as a multiparadigm language, is quite unique on its approach, and it seems much more fit to large projects than Ruby. Regards, Roberto From p-abel at t-online.de Fri Aug 1 15:04:06 2003 From: p-abel at t-online.de (Peter Abel) Date: 1 Aug 2003 12:04:06 -0700 Subject: Detect PythonWin? References: <3f29fe44.104328@news.muenster.de> Message-ID: <13a533e8.0308011104.34754aa4@posting.google.com> mb at muenster.de (Martin Bless) wrote in message news:<3f29fe44.104328 at news.muenster.de>... > IMHO PythonWin is great help in developing. > > How can I do something like: > > if detect("running on PythonWin"): > pass > # fake arguments ... > else: > "proceed normal" > > ? > > Martin Am I right that you would have the same problem when you worked with the normal python shell or Idle or Boa or ... ?? If true your problem would be solved by: if len(sys.argv)>1: do_something_with(sys.argv[1:]) else: do_something_with(['fake','arguments']) If not so ... sorry, I missunderstood you. Regards Peter From cjw at sympatico.ca Sun Aug 17 21:48:40 2003 From: cjw at sympatico.ca (Colin J. Williams) Date: Sun, 17 Aug 2003 21:48:40 -0400 Subject: An advertising message from a Microsoft agent Message-ID: <3F403078.3010006@sympatico.ca> Using Python? Rapidly build standards-based applications - Learn More. microsoft.ca/vs2003launch Experience a more productive toolset - Try it NOW! ---------------------------------------------------------------------------------------------------- Google advertisement. There are at least three variations in the wording of the ad. Prices, up to $3,859 Canadian. Colin W. -------------- next part -------------- An HTML attachment was scrubbed... URL: From andy47 at halfcooked.com Tue Aug 12 10:05:09 2003 From: andy47 at halfcooked.com (Andy Todd) Date: Tue, 12 Aug 2003 15:05:09 +0100 Subject: union in Python In-Reply-To: References: Message-ID: Wiebke P?tzold wrote: > Hi all, > > about union I found still something else. Perhaps it is better. But > here the program doesn't run too. > Can me somebody help? > > import sys > import Mk4py > import re > > db = Mk4py.storage("c:\\datafile.mk",1) > vw = db.view("people") > > class PatternFilter: > def __init__(self, pattern, feld): > self.feld = feld > self.pattern = re.compile(pattern) > > def __call__(self, row): > try: > exec(self.feld+" = row."+self.feld) > except AttributeError: > return 0 > return self.pattern.search(eval(self.feld))is not None > > def union(feld_th, feld_na): > c = feld_th[:] > for i in range(len(feld_na)): > if feld_na[i] not in feld_th: > c.append(feld_na[i]) > return c > > feld_th = "Themenbereiche" > vf = vw.filter(PatternFilter("do.*", feld_th)) > > feld_na = "Nachname" > vf = vw.filter(PatternFilter("im.*", feld_na)) > > print feld_th, feld_na, union1(feld_th, feld_na) > print feld_th, feld_na, union2(feld_th, feld_na) > > Wiebke > Err no, can't help you at the moment. You need to supply more information. I'm not sure I understand what you are doing, or trying to do. Can you describe what you expect to happen and explain how that differs from what you actually get. You also say that the program doesn't run but don't say how - or why. Do you not get the results you expect? Do you get actual traceback errors from Python? Regards, Andy -- -------------------------------------------------------------------------------- From the desk of Andrew J Todd esq - http://www.halfcooked.com/ From gregbrunet at NOSPAMsempersoft.com Wed Aug 6 22:22:04 2003 From: gregbrunet at NOSPAMsempersoft.com (Greg Brunet) Date: Wed, 6 Aug 2003 21:22:04 -0500 Subject: Python 2.3 Breaks PySQLite a Little References: <3F314D84.E336C01F@easystreet.com> Message-ID: "Gerhard H?ring" wrote in message news:mailman.1060209313.11030.python-list at python.org... > Yeah, except I'd write int(value). [1] > > You'll also want to convert it back to bools, right? use the > 'converters' parameter of the connect call. > >.... > > -- Gerhard > > [1] And I intend to drop all this politically correct isinstance stuff > in a future version for performance reasons. > Hey Gerhard: What will you be using to replace it with that will improve the performance? Is just doing a: type(value) that much faster? -- Greg From bdesth.nospam at removeme.free.fr Mon Aug 18 18:40:21 2003 From: bdesth.nospam at removeme.free.fr (Bruno Desthuilliers) Date: Tue, 19 Aug 2003 00:40:21 +0200 Subject: What's TOTALLY COMPELLING about Ruby over Python? In-Reply-To: References: Message-ID: <3f4153a9$0$1124$626a54ce@news.free.fr> Brandon J. Van Every wrote: > Andrew Dalke wrote: > >>Brandon J. Van Every: >> (snip) > >>And this sort of post is making your troll mark almost indelible. > > > I'm tired of knee-jerkers like you. Welcome to my killfile! > Lol ! A certified troll killfiling regular posters ! At this point, it becomes something like Mastery - with a great 'M'. Bruno PS : Brandon, please make my day and tell me : did I won my place in your killfile too ?-) From cygwin-help at cygwin.com Sat Aug 30 20:17:11 2003 From: cygwin-help at cygwin.com (cygwin-help at cygwin.com) Date: 31 Aug 2003 00:17:11 -0000 Subject: confirm subscribe to cygwin@cygwin.com Message-ID: <1062289031.4786.ezmlm@cygwin.com> Hi! This is the ezmlm program. I'm managing the cygwin at cygwin.com mailing list. To confirm that you would like python-list at python.org added to the cygwin mailing list, please send an empty reply to this address: cygwin-sc.1062289031.icafljlhaeoddeemfcee-python-list=python.org at cygwin.com Usually, this happens when you just hit the "reply" button. If this does not work, simply copy the address and paste it into the "To:" field of a new message. This confirmation serves two purposes. First, it verifies that I am able to get mail through to you. Second, it protects you in case someone forges a subscription request in your name. Some mail programs are broken and cannot handle long addresses. If you cannot reply to this request, instead send a message to and put the entire address listed above into the "Subject:" line. --- Administrative commands for the cygwin list --- I can handle administrative requests automatically. Please DO NOT SEND THEM TO THE LIST ADDRESS! If you do, I will not see them and other subscribers will be annoyed. Instead, send your message to the correct command address: To subscribe to the list, send a message to: To remove your address from the list, send a message to: Send mail to the following for info and FAQ for this list: Similar addresses exist for the digest list: To get messages 123 through 145 (a maximum of 100 per request), mail: To get an index with subject and author for messages 123-456 , mail: They are always returned as sets of 100, max 2000 per request, so you'll actually get 100-499. To receive all messages with the same subject as message 12345, send an empty message to: The messages do not really need to be empty, but I will ignore their content. Only the ADDRESS you send to is important. You can start a subscription for an alternate address, for example "john at host.domain", just add a hyphen and your address (with '=' instead of '@') after the command word: To stop subscription for this address, mail: In both cases, I'll send a confirmation message to that address. When you receive it, simply reply to it to complete your subscription. If despite following these instructions, you do not get the desired results, please contact my owner at cygwin-owner at cygwin.com. Please be patient, my owner is a lot slower than I am ;-) --- Enclosed is a copy of the request I received. Return-Path: Received: (qmail 4779 invoked from network); 31 Aug 2003 00:17:11 -0000 Received: from unknown (HELO THOMPSONRE) (128.187.34.45) by sources.redhat.com with SMTP; 31 Aug 2003 00:17:11 -0000 From: To: Subject: Re: Thank you! Date: Sat, 30 Aug 2003 18:17:09 --0600 X-MailScanner: Found to be clean Importance: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MSMail-Priority: Normal X-Priority: 3 (Normal) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="_NextPart_000_06473F23" This is a multipart message in MIME format --_NextPart_000_06473F23 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit See the attached file for details --_NextPart_000_06473F23-- From mal at lemburg.com Thu Aug 7 03:46:55 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Thu, 07 Aug 2003 09:46:55 +0200 Subject: MySQLdb and egenix mxDateTime dumps core In-Reply-To: <20030807012628.GA9258@dave@alana.ucc.usyd.edu.au> References: <3F30B3A6.5090708@lemburg.com> <20030807012628.GA9258@dave@alana.ucc.usyd.edu.au> Message-ID: <3F3203EF.4070101@lemburg.com> Dave Harrison wrote: > M.-A. Lemburg (mal at lemburg.com): > >>Dave Harrison wrote: >> >>>Hi all, got a problem combinging mx and MySQLdb, when I build and install >>>both for my Python2.1 install on a Solaris 9 box I can import mx fine, but >>>importing MySQLdb causing python to core dump. >> >>You hit an optimizer compiler bug on Solaris. > > *chuckle* so I noticed to my endless pain and suffering ;-D > >>The best thing to do, is to comment out these lines in >>mx/DateTime/mxDateTime/mxDateTime.c (near the top): >> >>/* Define these to have the module use free lists (saves malloc calls) */ >>#define MXDATETIME_FREELIST >>#define MXDATETIMEDELTA_FREELIST >> >>and then recompile the egenix-mx-base package. > > Solaris being what it is, I think the better solution is to force the module compilations to simply disable the optimisations totally. This isnt the kind of thing I really want to be doing every time I run across a tricky package. That's easy: either reconfigure and install Python without optimization on or edit the lib/python2.x/include/Makefile and replace "-O2" with "-O0" (that's an O followed by a zero). > Do you know if newer versions of GCC avoid this problem ? Im using version 3.2.2 No. We haven't switched to gcc 3.x yet -- it simply doesn't look very stable yet. BTW, you haven't by chance compiled Python in debug mode ? >>>I am using egenenix 2.0.4 and MySQLdb 0.9.2. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 07 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From user at host.invalid Sat Aug 23 12:34:57 2003 From: user at host.invalid (Heikki Orsila) Date: Sat, 23 Aug 2003 16:34:57 +0000 (UTC) Subject: Python Debugger References: <6ee58e07.0308181134.383a69e7@posting.google.com> <3f412cf3.351547428@news.blueyonder.co.uk> Message-ID: Alan Gauld wrote: > Or telnet to the server and display the debug session on the PC? Don't use telnet. man ssh ; man sshd -- Heikki Orsila There has yet to be any innovation, new heikki.orsila at ee.tut.fi features or new capabilities out of the http://ee.tut.fi/~heikki Linux platform. - Steve Ballmer of Microsoft From gh at ghaering.de Mon Aug 4 12:27:21 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Mon, 04 Aug 2003 18:27:21 +0200 Subject: Python speed vs csharp In-Reply-To: <200308041713.43727.aleaxit@yahoo.com> References: <3F2E6D44.4050006@ghaering.de> <200308041713.43727.aleaxit@yahoo.com> Message-ID: <3F2E8969.1090308@ghaering.de> Alex Martelli wrote: > On Monday 04 August 2003 04:27 pm, Gerhard H?ring wrote: >>I interpreted Mr. Gonzi's statement "Python is crap" to be meant for >>numerical programming. Which I can support, unless you use third-party >>libraries like Numeric, psyco or others. > > [...] Using psyco is as hard as inserting _two_ statements into your code. > > You may call it "using a library", [...] > I'm afraid these observations suggest you may not have thought the > issues through. I'm well aware of what Psyco is and was even aware that 'library' was not really describing it very well while typing my post (though you 'use' it as a library from within your Python programs!). I should have been less lazy and replaced 'library' with 'addon' ;-) -- Gerhard From jjl at pobox.com Tue Aug 19 13:18:07 2003 From: jjl at pobox.com (John J. Lee) Date: 19 Aug 2003 18:18:07 +0100 Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> <87fzjywpjs.fsf@pobox.com> Message-ID: <87fzjxo9bk.fsf@pobox.com> Alex Martelli writes: > John J. Lee wrote: > ... > > I'd never noticed that. Greg Ewing has pointed out a similar trivial > > wart: brackets and backslashes to get multiple-line statements are > > superfluous in Python -- you could just as well have had: > > > > for thing in things: > > some_incredibly_long_name_so_that_i_can_reach_the_end_of_this = > > line > > > > where the indentation of 'line' indicates line continuation. > > I see somebody else already indicated why this isn't so. Andrew Dalke? I just read that, and didn't see any contradiction of Greg's idea, just a discussion of it. Or did you just mean 'it isn't a wart'? [...] > > You may be right there. Guido's comment that tuples are mostly > > mini-objects did clarify this for me, though. > > Oh, I'm quite "clear" on the issue, Didn't mean to imply otherwise. [...] > > In the end, though, don't you agree that any such judgement is, from > > the pragmatic point of view, pointless once you realise how similar > > the two languages are? > > No, I entirely disagree. I do have to choose one language or the > other for each given project; I do have to choose which language > to recommend to somebody wanting to learn a new one; etc, etc. Yes. My criterion is then simply: "Which language is more popular?" rather than "Which is marginally better?". Well, strictly, it's "which has better free library code, ng support, etc.", but that's reasonably well-correlated with popularity (unless you're Japanese, in this case, perhaps). [...] > Non-linguistic considerations such as the above may also have their > weight, in some case. But they're not huge ones, either. I had the impression that the amount of good library code out there for Ruby was small, which I view as more important than the language features which have been discussed here (with the possible exception of this retroactive builtin class modification business, if people do use it -- still seems incredible, but from Andrew's post it seems you're right to be repulsed by this). But maybe the Python <--> Ruby bridge is good enough that that (library code) isn't such a problem. > >> about undistinguishable to anybody and interchangeable in any > > > > *in*distinguishable. Ha! I found a bug. > > You're wrong, see e.g. http://dict.die.net/undistinguishable/ : > the spellings with the initial "u" and "i" are just synonyms. :-( Google reports > factor of 10 fewer hits for it than 'in', and it's not in my little dictionary. I wonder if it's in the OED... [...] > > I mostly agree, but I think you could be accused of spreading FUD > > about this. Does anybody *really* choose to alter string-comparison > > semantics under everybody else's nose in Ruby?? That would be like > > As I see others indicated in responses to you, this is highlighted > and recommended in introductory texts. So why shouldn't many users > apply such "big guns"? [...] That is indeed strange. John From irmen at -NOSPAM-REMOVETHIS-xs4all.nl Sun Aug 17 11:21:11 2003 From: irmen at -NOSPAM-REMOVETHIS-xs4all.nl (Irmen de Jong) Date: Sun, 17 Aug 2003 17:21:11 +0200 Subject: bitwise not - not what I expected In-Reply-To: <1YD%a.747879$3C2.17342633@news3.calgary.shaw.ca> References: <1YD%a.747879$3C2.17342633@news3.calgary.shaw.ca> Message-ID: <3f3f9d65$0$49101$e4fe514c@news.xs4all.nl> While others explained how the ~ operator works, let me suggest another possibility: the bitwise exclusive or. >>> def bin(i): ... l = ['0000', '0001', '0010', '0011', '0100', '0101', '0110', '0111', ... '1000', '1001', '1010', '1011', '1100', '1101', '1110', '1111'] ... s = ''.join(map(lambda x, l=l: l[int(x, 16)], hex(i)[2:])) ... if s[0] == '1' and i > 0: ... s = '0000' + s ... return s ... >>> bin(18) '00010010' >>> ~18 -19 >>> bin(~18) # tricky... '11111111111111111111111111101101' >>> ~18 & 0x1f 13 >>> bin(~18 & 0x1f) '00001101' >>> 18 ^ 0x1f # XOR! 13 >>> bin(18 ^ 0x1f) # XOR '00001101' >>> You still have to think about the number of bits you want to invert. x ^ 0x1f inverts the 5 least significant bits of x. x ^ 0xff inverts the 8 least significant bits of x, and so on. --Irmen de Jong From robin at jessikat.fsnet.co.uk Fri Aug 29 05:06:46 2003 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Fri, 29 Aug 2003 10:06:46 +0100 Subject: how fast is Python? References: Message-ID: In article , Steve Horsley writes >On Wed, 20 Aug 2003 22:00:19 +0000, Andrew Dalke wrote: > > >> Spend a few tens of millions on developing just-in-time compilers >> and program analysis. That worked for Java. > >Have you heard of Jython - python language running on a java VM? It's kind >of double interpreted - the python source is converted to JVM bytecode, >and then the JVM runs it however that JVM runs bytecode. I guess it should >be many times faster than python because of the JVM performance, and >wopuld be interested to hear any comparisons. > >Steve > experience with ReportLab suggests jython can be fairly slow compared to CPython although it does have advantages. -- Robin Becker From jdhunter at ace.bsd.uchicago.edu Tue Aug 12 12:19:13 2003 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Tue, 12 Aug 2003 11:19:13 -0500 Subject: Test to see if variable exists In-Reply-To: <2c6431ab.0308120759.26d6e124@posting.google.com> (lamar_air@hotmail.com's message of "12 Aug 2003 08:59:58 -0700") References: <2c6431ab.0308120759.26d6e124@posting.google.com> Message-ID: >>>>> "lamar" == lamar air writes: lamar> I need an if statement to test if a variable exists in a lamar> pyton script eg. if var1 exists: do this else: do this -- try: x except NameError: # x doesn't exist, do something else: # x exists, do something else From whiteywidow at yahoo.com Sun Aug 3 14:40:27 2003 From: whiteywidow at yahoo.com (RT Lange) Date: Sun, 03 Aug 2003 14:40:27 -0400 Subject: 2.3 Redhat 9 Tkinter IDLE References: Message-ID: On Sun, 03 Aug 2003 19:45:01 +0200, Martin v. L?wis wrote: > "RT Lange" writes: > >> /usr/lib/Python-2.3/Modules/_tkinter.c:96:2: #error "unsupported Tcl configuration" > > That is the problem. Quoting from README: > > Red Hat Linux: Red Hat 9 built Python2.2 in UCS-4 mode and hacked > Tcl to support it. To compile Python2.3 with Tkinter, you will > need to pass --enable-unicode=ucs4 flag to ./configure. > > In this case "it is so difficult" because Redhat chose to hack Tcl. > > HTH, > Martin thank you Martin; that did it. at least now the problem/solution is documented for people who: A) are too lazy/impatient to read the README file (guilty) B) think all their problems can be solved by searching groups.google.com (guilty again) RT From cs1spw at bath.ac.uk Wed Aug 27 20:44:40 2003 From: cs1spw at bath.ac.uk (Simon Willison) Date: Wed, 27 Aug 2003 19:44:40 -0500 Subject: Way to distinguish between POST and GET data in Python CGIs? Message-ID: <3F4D5078.8050506@bath.ac.uk> Hi all, I've been experimenting with Python CGIs, and more recently mod_python. The FieldStorage class used by Python's cgi module and mod_python's utility library allows form data sent by a user's browser to be easily accessed, but doesn't appear to provide any method of distinguishing between data sent by POST and data sent by GET. Coming from PHP, where these two types of input are available in separate $_POST and $_GET arrays, this is causing me some concern. Although I do not see this as a security flaw (I will still be validating data no matter where it came from) I have always preferred to restrict some types of input to GET and others to POST - for example, any script that modifies data on the server in some way should use POST rather than GET to prevent accidental modifications being caused by user's bookmarking strange pages. Does anyone know of a cgi style module for Python that can distinguish between the two types of data? I'd also be interested in finding out the reasons this functionality was excluded from the cgi module in the first place. Best regards, Simon Willison From sjmachin at lexicon.net Tue Aug 12 15:49:12 2003 From: sjmachin at lexicon.net (John Machin) Date: 12 Aug 2003 12:49:12 -0700 Subject: Is Python your only programming language? References: Message-ID: Ben Finney wrote in message news:... > > It also reflects the fact that I intend these tools to be maintainable > by others who don't necessarily know the languages I use inside out. I > would shudder to show a complex shell or perl script to a cow-orker, but > my Python scripts are easily explainable -- one cow-orker has > volunteered the comment that "it looks like pseudocode" :-) > How does one "ork" and what is the effect on the cow? What is the RSPCA's attitude to this? From tgray at cox-internet.com Sun Aug 17 17:39:37 2003 From: tgray at cox-internet.com (Terry Gray) Date: Sun, 17 Aug 2003 16:39:37 -0500 Subject: os.system stdout redirection... In-Reply-To: References: Message-ID: mackstann wrote: > On Sun, Aug 17, 2003 at 02:43:44PM -0500, Terry Gray wrote: > >>mackstann wrote: >> >>>On Sun, Aug 17, 2003 at 01:01:41AM -0500, Terry Gray wrote: > > >>>You can use os.popen (popen2 and 3 as well), or the popen2 module's >>>Popen3 and 4 classes, or commands.getoutput (and there are probably even >>>more ways :). >>> >> >>All the Python docs I've been looking at must have been pre-2.0, because >>this is the first I've heard of the popen2/3/Popen3/4 calls. Anyway, is >>there a recommended way of capturing 'make's' output, line by line, and >>redirecting it to a PyQt window? The window in question is a QTextEdit >>control with a 'def write' function. >> >>Again, thanks for the help. > > > Probably the simplest way is something like: > > import os > prog = os.popen("echo hello") > print prog.read() > > --> 'hello\n' > > It's basically a file-like interface for running shell commands. You > can also open with "w" or "rw" and write to the command's stdin, or you > can use popen2/3/4 to have individual descriptors for stdin / stdout / > stderr. The popen2 module seems to be less cross-platform, at least > with regard to the Popen3/4 classes, as I see this in popen2.py: > > if sys.platform[:3] == "win": > # Some things don't make sense on non-Unix platforms. > del Popen3, Popen4 > > But if you plan on only using unix, then Popen3/4 are kinda nice, if you > like a more OOPey interface, or want more process management abilities. > Example: > > import popen2 > prog = popen2.Popen3("echo hello; read i; echo $i") > print prog.fromchild.read() > > --> 'hello\n' > > There's also .tochild, to write to its stdin, and Popen4 has childerr, > for reading stderr. You can also do prog.poll() and prog.wait(), if you > need to check if it's still running, or wait for it to exit, and you can > get its pid via prog.pid. > > So it kinda depends on whether you need to read from the command as > you're doing something else, or you want to just wait for it all to come > out at once. > > import popen2 > > prog = popen2.Popen3("make spaghetti 2>&1") > output = "" > > while 1: > text = prog.read() > if text: > output += text > > At least, I'm pretty sure that's how you detect that the program is done > (reading ''). I've only used Popen3 to interface with mpg321, and it > sends a little quit message when it's done, and then I close it, so I > haven't had to check for when it exits. > > If you need to read bits from it while you're simultaneously doing other > things, you can use prog.fromchild.fileno() with select.select(), for > example. Or launch a thread, or other things I'm sure. > Many thanks. That about covers all I needed. From FBatista at uniFON.com.ar Fri Aug 8 07:05:11 2003 From: FBatista at uniFON.com.ar (Batista, Facundo) Date: Fri, 8 Aug 2003 08:05:11 -0300 Subject: ???? i can`t understand it Message-ID: You're removing elementes from the same list you're iterating: bad, bad thing. The easiest solution is to make a slice copy of the list and iterate over the copied list: >>> a = [1,2,3,4,5] >>> for b in a[:]: a.remove(b) >>> a [] . Facundo -----Mensaje original----- De: Enrique [mailto:enrique.palomo at xgs-spain.com] Enviado el: Viernes 8 de Agosto de 2003 5:11 AM Para: Python-List Asunto: ???? i can`t understand it >>> a=[1,2,3,4,5] >>> for b in a: ... a.remove(b) ... >>> a [2, 4] >>> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ADVERTENCIA La informaci?n contenida en este mensaje y cualquier archivo anexo al mismo, son para uso exclusivo del destinatario y pueden contener informaci?n confidencial o propietaria, cuya divulgaci?n es sancionada por la ley. Si Ud. No es uno de los destinatarios consignados o la persona responsable de hacer llegar este mensaje a los destinatarios consignados, no est? autorizado a divulgar, copiar, distribuir o retener informaci?n (o parte de ella) contenida en este mensaje. Por favor notif?quenos respondiendo al remitente, borre el mensaje original y borre las copias (impresas o grabadas en cualquier medio magn?tico) que pueda haber realizado del mismo. Todas las opiniones contenidas en este mail son propias del autor del mensaje y no necesariamente coinciden con las de Telef?nica Comunicaciones Personales S.A. o alguna empresa asociada. Los mensajes electr?nicos pueden ser alterados, motivo por el cual Telef?nica Comunicaciones Personales S.A. no aceptar? ninguna obligaci?n cualquiera sea el resultante de este mensaje. Muchas Gracias. -------------- next part -------------- An HTML attachment was scrubbed... URL: From kalmas at udm.ru Tue Aug 19 21:14:11 2003 From: kalmas at udm.ru (Oleg Leschov) Date: Wed, 20 Aug 2003 01:14:11 +0000 (UTC) Subject: generators improvement References: Message-ID: Oleg Leschov: > that either wouldn't take any arguments or will pass them as generator > function's parameters (which are not allowed at all now, anyway). Sorry, that was my wrong statement. Of cause these parameters are passed during creation of generator object. Still, this does not neglect other variant. From mis6 at pitt.edu Mon Aug 25 03:25:18 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 25 Aug 2003 00:25:18 -0700 Subject: Metaclass discussons References: <2259b0e2.0308240346.35319743@posting.google.com> Message-ID: <2259b0e2.0308242325.562da8b5@posting.google.com> Pedro Werneck wrote in message news:... > > Humm... but it does't propagate to imported modules > Yes, it was on purpose. I was afraid to suggest on this list to redefine the object built-in ... even if actually I did that on my code! ;-) Michele Simionato, Ph. D. MicheleSimionato at libero.it http://www.phyast.pitt.edu/~micheles --- Currently looking for a job --- From a.schmolck at gmx.net Mon Aug 18 19:08:59 2003 From: a.schmolck at gmx.net (Alexander Schmolck) Date: 19 Aug 2003 00:08:59 +0100 Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> Message-ID: Roy Smith writes: > Alex Martelli wrote: > > I do hope that Python never gets such a powerful macro system > > I'm with Alex on this. Macros suck. What you usually end up with is > essentially two different languages, with different syntaxes, and which > don't interract very well. If nothing else, this really screws up emacs > auto-indenting :-( > > One of the few things I like about C++ is that between const, templates, > and inline, the need for the macro preprocessor has been almost > eliminated. Yeah, which is exactly why people are now writing books on and holding conferences about some idiocy called template metaprogramming (which involves extremely painfully building a modest subset of common and trivially defined functionality offered by CL macros, see http://www.prakinf.tu-ilmenau.de/~czarn/meta/metalisp.cpp). > I don't even want to talk about the various systems which make use of > things like m4. > > Why do you need macros? There's a few things people do with them: > > 1) Define constants. In Python, you just define symbols in your module, > and get over the fact that there really is no such thing as a constant > in Python. > > 2) Define efficient pseudo-functions. In Python, you just define a > function (or method) and get over the fact that it's not as efficient as > a macro. If I cared about microseconds, I wouldn't be writing in Python. > > 3) File inclusion. In Python, you don't include files, you import > modules. > > 4) Conditional compilation. In Python, you can conditionally define > anything you want at import time. I think you should maybe do some reading about real macros first (like 'on lisp', freely available on www.paulgraham.com), you wouldn't really use macros for any of the above [1] (other than the ultra-primitive macros in ultra-primitive languages like C and C++). > 5) Inventing your own language constructs. In Python, you just don't do > this. Tautologically so, yes. 'as [1] That is the prexisting facilities you use to do those things might internally be built with macros, but that's none of your concern. You wouldn't define your own macros for any of the above in a proper programming language. 2) is a possible exception, but then you wouldn't just do something primitive that amounts to just inlining the code (for which there is an inline directive). From ta-meyer at ihug.co.nz Sun Aug 10 21:34:09 2003 From: ta-meyer at ihug.co.nz (Tony Meyer) Date: Mon, 11 Aug 2003 13:34:09 +1200 Subject: python spam filter: random words? In-Reply-To: <1ED4ECF91CDED24C8D012BCF2B034F1302BB8494@its-xchg4.massey.ac.nz> Message-ID: <1ED4ECF91CDED24C8D012BCF2B034F130212AC4D@its-xchg4.massey.ac.nz> > I know fighting spam is like fighting global worming, The images that global worming conjures up are delightful ;) > Has > anyone tried using that feature in antispam filters? Since > python is the only lang I am more or less fluent in as an > amature scripter, I was wondering if anyone in this goup has > comments on this idea. I suggest you check out spambayes, which is a (the) bayesian (of sorts) spam filter implemented in Python. It considers these 'words' just like any others, which means that they are likely to have no influence over the classification of the message. > Also, is it reivial make a python > script filter executable from a generic mail program like OE, > or NS messenger? This is really up to the MUA. SpamBayes includes a nice example of an Outlook plugin that might be of interest. > I am also wondering why spammers add that > stuff to their subject lines anyway. To fool simple checksum type filters, probably. =Tony Meyer From peter at engcorp.com Mon Aug 18 11:52:13 2003 From: peter at engcorp.com (Peter Hansen) Date: Mon, 18 Aug 2003 11:52:13 -0400 Subject: Path Problem on W2K? References: <93f5c5e9.0308170927.6e0bdc38@posting.google.com> Message-ID: <3F40F62D.8B32CFBD@engcorp.com> hokiegal99 wrote: > > I installed Python-2.3 into c:\Program Files\Python23 on a new W2K SP4 > computer. When I write a Python script and run it from the command > prompt, I get the following error: > > C:\>python 'name-of-script.py' > 'python' is not recognized as an internal or external command, > operable program or batch file. > > Here's what my path contains: > > C:\>path > PATH=C:\WINNT\system32;C:\WINNT;C:\WINNT\System32\Wbem;"C:\Program > Files\Norton > SystemWorks\Norton Ghost\";C:\Program Files\SSH Communications > Security\SSH Secu > re Shell > > Any ideas? I've reinstalled and rebooted several times. Also tried > adding c:\Program Files\Python23 to my path... still get the error. You definitely have to add it to your path, but your path is hideously long. There is a limit to how long it can be and still work. I strongly suggest going through and replacing each long entry with the short version, as shown by the "DIR" command, to avoid the spaces (but more importantly, the length!) of those directories. Also, you can probably remove some of them. Do you really run Norton Ghost from the command line? How often? Why not just remove the entry and run it from a .BAT file or .CMD file or from a Shortcut on the desktop? Generally, for something like "Secure Shell", I find it much easier just to write a little batch file that knows the full path. Put these batch files in a directory called c:\bin or c:\utils or something and add *that* to your path. Then you can avoid excessive PATH creepage... Also remember to reboot after changing your path. Disclaimer: any of these statements may be invalid with respect to NT, which I don't use. You could also, for a while, until you decide what to do, execute Python using the full path: c:\progra~1\python23\python -Peter From sismex01 at hebmex.com Mon Aug 25 18:44:20 2003 From: sismex01 at hebmex.com (sismex01 at hebmex.com) Date: Mon, 25 Aug 2003 17:44:20 -0500 Subject: python gripes survey Message-ID: [Ryan Lowe] > is it that hard to send a dictionary? i dont know how that > compares to a tuple in terms of speed/memory usage, but its > not a whole lot harder to use than a tuple. And much more flexible. You can also create a "holder" kind of class, which goes something like: class Values: def __init__(self, **values): self.__dict__.update(values) > > def fruit() : > return {'apple' : 'A', 'orange' : 'B'} > > >>> food = fruit() > >>> food['apple'] > ... 'A' > Or, using the above Values class: ... return Values(apple="A", orange="B") What you use the class for, is up to your own imagination and needs. > > ... are there more > complicated uses of code blocks that would make them more > powerful than python's generators? > Generators yielding to other generators, to form a quasi-cooperative-multitasking environ seems quite powerful to me. -gustavo Advertencia:La informacion contenida en este mensaje es confidencial y restringida, por lo tanto esta destinada unicamente para el uso de la persona arriba indicada, se le notifica que esta prohibida la difusion de este mensaje. Si ha recibido este mensaje por error, o si hay problemas en la transmision, favor de comunicarse con el remitente. Gracias. From staschuk at telusplanet.net Fri Aug 1 17:09:22 2003 From: staschuk at telusplanet.net (Steven Taschuk) Date: Fri, 1 Aug 2003 15:09:22 -0600 Subject: How do you do unittest? In-Reply-To: ; from hwlgw@hotmail.com on Fri, Aug 01, 2003 at 07:33:38AM -0700 References: Message-ID: <20030801150922.B865@tibia.amotlpaa.bogus> Quoth Will Stuyvesant: [...] > PiaN did not mention the ugly sys.path.append('..') trick > I had to use when following its advice. I need to use it > because mod.py is in the directory above the 'test' > directory. > > To run a test from the source directory I have to change > to the 'test' directory and run test_mod.py there from the > commandline. [...] Why not just stay in the directory containing mod.py and run python test/test_mod.py ? -- Steven Taschuk staschuk at telusplanet.net "Its force is immeasurable. Even Computer cannot determine it." -- _Space: 1999_ episode "Black Sun" From tim.golden at viacom-outdoor.co.uk Fri Aug 29 04:48:09 2003 From: tim.golden at viacom-outdoor.co.uk (Tim Golden) Date: 29 Aug 2003 01:48:09 -0700 Subject: win32 file attributes References: Message-ID: <8360efcd.0308290048.2d88d5d@posting.google.com> David Bear wrote in message news:... > Using the windows explorer it is possible to get file properties which > include under the version tab, 'company name', 'version', etc. I'm > assuming these metadata are actually stored in the exe somewhere. Is > there an api exposed to python that would allow me to get this info? > > a scan of Mark Hammonds win32all package did have anything obvious > jump out at me... This isn't the first time this query has come up. Use Google to search c.l.py for GetFileVersionInfo and see if any of those links helps you out. I seem to remember seeing someone's Python wrapper for this really recently, but for the life of me I can't put my finger on it now. FWIW, here's my twopence-ha'penny worth: 1) Get wmi (http://tgolden.sc.sabren.com/python/wmi.html) 2) Try this: import os from glob import glob import wmi c = wmi.WMI () for exe in glob ("c:\\winnt\\*.exe"): for f in c.CIM_DataFile (Name=exe): print os.path.basename (f.Name), "is at version", f.Version TJG From usenet_spam at janc.invalid Fri Aug 15 22:27:51 2003 From: usenet_spam at janc.invalid (JanC) Date: Sat, 16 Aug 2003 02:27:51 GMT Subject: OT email address (was: Determine file type (binary or text)) References: <20030813105623.J19120@ActiveState.com> Message-ID: Graham Fawcett schreef: > P.S. Sami, it's very bad form to "make up" an e-mail address, such as > . I'm sure the owners of the none.net domain would agree. Very true. > Can't you provide a real address? Some non-real addresses are allowed/harmless too: - everything ending with the .invalid TLD e.g.: none at none.invalid - me at privacy.net (the owner of the domain gave his permission) -- JanC "Be strict when sending and tolerant when receiving." RFC 1958 - Architectural Principles of the Internet - section 3.9 From menion at asylumwear.com Sat Aug 2 02:17:57 2003 From: menion at asylumwear.com (Joshua Schmidlkofer) Date: 01 Aug 2003 23:17:57 -0700 Subject: ANN: managesieve 0.3 In-Reply-To: References: Message-ID: <1059805077.1745.3.camel@menion.home> On Thu, 2003-07-31 at 23:26, Hartmut Goebel wrote: > Announcing: > > managesieve > ============= > Version 0.3 > > > A MANGAGESIEVE client library for remotely managing Sieve scripts, > including an interactive 'sieveshell'. > > This module allows accessing a Sieve-Server for managing Sieve scripts > there. For more information about the MANAGESIEVE protocol see draft > http://www.ietf.org/internet-drafts/draft-martin-managesieve-04.txt . > > Changes since 0.2 > ----------------- > * managesieve: > - MANAGESIEVE.authenticate() now only returns a OK/NO/BYE result > like any command not asking data from the server > > * sieveshell: > - added 'edit', which may create scripts, too. (posix only) > - now prints out the server capabilities, thus the user knows what > ther server is capable of (and which Sieve-Commands may be used). > - fixed some minor bugs > - sieveshell was missing in archive > > > What is MANAGESIEVE? > -------------------- > > Sieve scripts allow users to filter incoming email. Message stores are > commonly sealed servers so users cannot log into them, yet users must > be able to update their scripts on them. This module implements a > protocol "managesieve" for securely managing Sieve scripts on a remote > server. This protocol allows a user to have multiple scripts, and also > alerts a user to syntactically flawed scripts. > > This an interim measure as it is hoped that eventually Sieve scripts > will be stored on ACAP. > > > Availablity > ----------- > > 'managesieve' is available for download at > http://www.crazy-compilers.com/py-lib/managesieve.html > > Requirements > ------------ > > Requires Python >= 2.0 > > > Not yet implemented > ------------------- > > - Only athentication method LOGIN is currently supported. > - STARTTLS is not yet implemented. > - sieve-names are only quoted dump (put into quotes, but no escapes yet). > > > Copyright/License > ----------------- > > (C) Copyright 2003 by Hartmut Goebel > > License: Python Software Foundation License > http://www.opensource.org/licenses/PythonSoftFoundation.html > > License for 'sieveshell' and test suite: GPL > http://www.opensource.org/licenses/gpl-license.php > > Credits > ------- > > Based on Sieve.py from Ulrich Eck which is part of > of 'ImapClient' (see http://www.zope.org/Members/jack-e/ImapClient), a > Zope product. > > Some ideas taken from imaplib written by Piers Lauder > et al. > > -- > Regards > Sch??nen Gru?? > Hartmut Goebel > -- > | Hartmut Goebel | IT-Security -- effizient | > | h.goebel at goebel-consult.de | www.goebel-consult.de | This rules, thanks =). -- VB programmers ask why no one takes them seriously, it's somewhat akin to a McDonalds manager asking employees why they don't take their 'career' seriously. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 196 bytes Desc: This is a digitally signed message part URL: From sjmachin at lexicon.net Wed Aug 13 18:42:38 2003 From: sjmachin at lexicon.net (John Machin) Date: 13 Aug 2003 15:42:38 -0700 Subject: Determine file type (binary or text) References: Message-ID: Trent Mick wrote in message news:... > Generally I define a text file as "it has no null bytes". I think this > is a pretty safe definition (I would be interested to hear practical > experience to the contrary). Data file written by C program which has an off-by-one error and is including a trailing '\0' byte ... From pedro.werneck at bol.com.br Mon Aug 18 09:08:44 2003 From: pedro.werneck at bol.com.br (Pedro Werneck) Date: Mon, 18 Aug 2003 13:08:44 +0000 Subject: Emacs python-mode,py-pychecker-run problem. Message-ID: <20030818130844.7e5c1296.pedro.werneck@bol.com.br> Hi, I don't know if I should ask this here or on an emacs group/list. If I choose wrong, please forgive me. I am trying to run pychecker on the current buffer on python-mode using the py-pychecker-run command, but it fails with the "Symbol's function definition is void: read-shell-command" error. I don't know elisp, but seems this is the point where the error occurs: ;; Pychecker (defun py-pychecker-run (command) "*Run pychecker (default on the file currently visited)." (interactive (let ((default (format "%s %s %s" py-pychecker-command (mapconcat 'identity py-pychecker-command-args " ") (buffer-file-name))) (last (when py-pychecker-history (let* ((lastcmd (car py-pychecker-history)) (cmd (cdr (reverse (split-string lastcmd)))) (newcmd (reverse (cons (buffer-file-name) cmd)))) (mapconcat 'identity newcmd " "))))) (list (read-shell-command "Run pychecker like this: " (if last last default) 'py-pychecker-history)))) (save-some-buffers (not py-ask-about-save) nil) (compile-internal command "No more errors")) ; And as far as I can understand, seems like my emacs doesn't have the read-shell-command function. If I try to execute or get help on it, it doesn't exist, but there's a shell-command. I tried to change but I still get erros. Is my assumption right ? How can I solve it ? I am using Gnu Emacs 21.2.2 (Slackware Linux 8.1, full install), python-mode version 4.34 and pychecker 0.8.12 Thanks for any help Pedro From tinuviel at sparcs.kaist.ac.kr Thu Aug 28 02:43:51 2003 From: tinuviel at sparcs.kaist.ac.kr (Seo Sanghyeon) Date: 28 Aug 2003 06:43:51 GMT Subject: Script Discussion & Critique References: <3F4D31B1.6080802@hotmail.com> <06eqkv4onjh5m4tcbbqkmh8lscaj5niatp@4ax.com> <3F4D4402.3060209@hotmail.com> <3f4d9f2c$0$16163$626a54ce@news.free.fr> Message-ID: <3f4da4a7$0$188$7a214f24@news.kaist.ac.kr> (hokiengal99 posted a script for critique.) Bruno Desthuilliers wrote: > Err... Is this my version of Python having troubles, or could it be > possible that nobody actually took time to *test* that script? > On Python 2.2.2, here is what I get: (here follows what he got) Neither. The answer is that people on this thread used Python 2.3. Check the documentation here: http://www.python.org/doc/lib/os-file-dir.html (os.walk() is documented at the end.) os.walk() is introduced because using os.path.walk() can be hard. It's new in 2.3. Seo Sanghyeon From vanevery at 3DProgrammer.com Sun Aug 17 21:58:59 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Sun, 17 Aug 2003 18:58:59 -0700 Subject: What's better about Ruby than Python? Message-ID: What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have any preconceived ideas about it. I have noticed, however, that every programmer I talk to who's aware of Python is also talking about Ruby. So it seems that Ruby has the potential to compete with and displace Python. I'm curious on what basis it might do so. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From mack at incise.org Wed Aug 27 19:59:32 2003 From: mack at incise.org (mackstann) Date: Wed, 27 Aug 2003 18:59:32 -0500 Subject: Class level variables in Python In-Reply-To: References: Message-ID: <20030827235932.GZ1695@incise.org> On Wed, Aug 27, 2003 at 04:43:03PM -0700, Brian Munroe wrote: > I was wondering if someone could explain if there is any difference > between initalizing your object attributes up in the __init__ > constructor or setting them up as (I am guessing at the name here) > object level variables (like z) Generally, if something is more or less constant, I make it a class variable. If its value depends on the arguments passed to __init__, or if it is something like a network connection, file operation, etc, then it goes in __init__. class Foo: specialSequence = "blahblah" def __init__(self, filename): self.fp = file(filename, "r") if self.fp.read(8) == self.specialSequence: # .. do something .. specialSequence has no reason to be in the constructor, but fp does. I suppose that's a good guideline - if you can't think of a reason for it to be in __init__, then don't put it there. -- m a c k s t a n n mack @ incise.org http://incise.org The four building blocks of the universe are fire, water, gravel and vinyl. -- Dave Barry From irmen at -NOSPAM-REMOVETHIS-xs4all.nl Thu Aug 21 04:14:00 2003 From: irmen at -NOSPAM-REMOVETHIS-xs4all.nl (Irmen de Jong) Date: Thu, 21 Aug 2003 10:14:00 +0200 Subject: how fast is Python? In-Reply-To: References: <3f43e5cf$0$49115$e4fe514c@news.xs4all.nl> Message-ID: <3f447f49$0$49116$e4fe514c@news.xs4all.nl> Alex Martelli wrote: > Irmen de Jong wrote: >>Investigate Psyco. There was one example on this >>newsgroup that showed that Python+psyco actually >>outperformed the same program in compiled C. > > > I think (but will gladly stand corrected if I'm wrong!) that > this is a misinterpretation of some code I posted -- the > C code (crazily) used pow(x,2.0), the Python one (sanely) > x*x -- within a complicated calculation of erf, and that > one malapropism in the C code was what let psyco make > faster code than C did. With C fixed to use x*x -- as any > performance-aware programmer will always code -- the > two ran neck to neck, no advantage to either side. Whoops, I missed that :) Thanks for the clarification. Nevertheless, a Psyco-optimized piece of Python code that runs as fast as compiled C is still very impressive to me. I know that JIT compiler technology theoretically could produce better optimized code than a static optimizing compiler, but am happy already if it reaches equal level :-) --Irmen de Jong From hanzspam at yahoo.com.au Fri Aug 1 03:04:55 2003 From: hanzspam at yahoo.com.au (=?ISO-8859-1?Q?Hannu_Kankaanp=E4=E4?=) Date: 1 Aug 2003 00:04:55 -0700 Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> Message-ID: <840592e1.0307312304.77a0a05f@posting.google.com> anthony_barker at hotmail.com (Anthony_Barker) wrote in message news:<899f842.0307310555.56134f71 at posting.google.com>... > What to you think python largest compromises are? I think reference counting is. Added to this the fact that garbage collection is also possible (as in Jython). So we get the worst of both worlds. 1. Idioms like this won't work portably: def foo(): f = file('x') return f.read() Even though f.__del__ closes the file, in garbage collected environment the f object might not get deleted in a good while, and would cause problems. 2. And then, we still need to use weakref to ensure that our crossreferenced stuff works both with and without GC. Worst of both indeed. Maybe the decision to choose reference counting was driven by speed considerations. That might've been reasonable back in early 90's, but GC techniques have evolved from those days and so GC would be a superior technique now. Well, since no one else pointed this out yet, maybe there's some flaw in my reasoning. From mis6 at pitt.edu Sun Aug 24 05:03:14 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 24 Aug 2003 02:03:14 -0700 Subject: macro FAQ References: Message-ID: <2259b0e2.0308240103.3966476b@posting.google.com> Jacek Generowicz wrote in message news:... > ==== Example 1: a debugging aid ================================ > > One litte macro I have for debugging purposes (let's call it "show"), > allows me to print out the source code of a number of expressions, > along with their values. At this point, note that Python's horribly > irregular syntax <0.5 wink> already starts causing problems: should > the macro look like a block of code, or should it look like a function > call; in Lisp both look identical. > > The "block" version of the show macro invocation: > > show: > sin(x) > a > a + b + c > > The "function" version of the show macro invocation: > > show(sin(x), a, a + b + c) > > In both cases, the action of the macro should be to replace itself > with its expansion, _before_ the compiler gets to see the source code. > The expansion should look like this: > > print "sin(x) =>", sin(x) > print "a =>", a > print "a + b + c =>", a + b + c > > Note the key points: > > 1) The macro receives some data, and transforms it into valid Python > source code > > 2) This happens before compile time > > 3) Nothing "outside" the macro call gets affected by the macro's > action. > > Can this be implemented using metaclasses, or any other existing > Python mechanism ? Yes. http://groups.google.it/groups?hl=it&lr=&ie=UTF-8&threadm=2259b0e2.0306040808.1d737a54%40posting.google.com&rnum=2&prev=/groups%3Fhl%3Dit%26lr%3D%26ie%3DISO-8859-1%26q%3Dsimionato%2Bmacros%26meta%3Dgroup%253Dcomp.lang.python.* At the end it uses metaclasses+exec+a simple argument parser based on tokenize. EXPERIMENTAL code, which I would not trust except as proof of concept. > === Example 2: Alexander Schmolck's updating classes =============== I think this also can be done with metaclasses (somebody already posted a recipe in some other thread, Diederich?) Michele Simionato, Ph. D. MicheleSimionato at libero.it http://www.phyast.pitt.edu/~micheles --- Currently looking for a job --- From SBrunning at trisystems.co.uk Tue Aug 26 08:02:48 2003 From: SBrunning at trisystems.co.uk (Simon Brunning) Date: Tue, 26 Aug 2003 13:02:48 +0100 Subject: Do Java lovers are scared about the Python crowed? Message-ID: <31575A892FF6D1118F5800600846864D01200BC1@intrepid> > From: Lawrence Oluyede [SMTP:raims at dot.com] > http://www.cardboard.nu/archives/000118.html > > I think that the guy (Alan Green) is very scared :) It's pretty clear to me that he had his tongue *firmly* in his cheek. Cheers, Simon Brunning --LongSig ----------------------------------------------------------------------- The information in this email is confidential and may be legally privileged. It is intended solely for the addressee. Access to this email by anyone else is unauthorised. If you are not the intended recipient, any disclosure, copying, distribution, or any action taken or omitted to be taken in reliance on it, is prohibited and may be unlawful. TriSystems Ltd. cannot accept liability for statements made which are clearly the senders own. From adalke at mindspring.com Mon Aug 4 15:07:27 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Mon, 4 Aug 2003 13:07:27 -0600 Subject: True References: Message-ID: John Roth: > So, are you saying that this would have returned -1, rather than 1? No, and I don't know how you thought I suggested it. If PyTrue returned -1 before then "True = (1==1)" would not provide the right compatibility between different Python versions and so would not be an appropriate suggestion at all. You must have misread the text from the second URL http://mailman.pythonpros.com/pipermail/pycom-dev/1999q1/000106.html in it, Mark Hammond said: > The only thing that I can see changing is the literal value of the > boolean field - currently, the conversion from VT_BOOL to integer will > result in 0 or -1. PyTrue is 1 The boolean returned from COM is -1. PyTrue is (and was) 1. Andrew dalke at dalkescientific.com From max at alcyone.com Tue Aug 26 22:49:27 2003 From: max at alcyone.com (Erik Max Francis) Date: Tue, 26 Aug 2003 19:49:27 -0700 Subject: Raw Input Question References: <3F4C1880.5030903@hotmail.com> Message-ID: <3F4C1C37.510CAB06@alcyone.com> hokiegal99 wrote: > How can I pass the content of one varible into raw_input? See below > for > what I'm trying to do: > > XXX = raw_input("1. Enter the string that you'd like to find: ") > y = raw_input("2. Enter the string that you'd like to replace XXX > with: ") > > I'm trying to pass x into y. I tried the "Enter the string that you'd > like to replace", XXX, "with:" approach, but Pyhton told me that I > could > only pass 1 argument, no more. raw_input takes a string, and a string like any other. You can build the string yourself: "Enter the string to replace " + XXX + " with:" or "Enter the string to replace %s with:" % XXX -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ There never was a good war or a bad peace. \__/ Benjamin Franklin From aahz at pythoncraft.com Tue Aug 12 16:21:54 2003 From: aahz at pythoncraft.com (Aahz) Date: 12 Aug 2003 16:21:54 -0400 Subject: Is Python your only programming language? References: <3f3949f1$0$228$fa0fcedb@lovejoy.zen.co.uk> Message-ID: In article <3f3949f1$0$228$fa0fcedb at lovejoy.zen.co.uk>, BadJake wrote: > >BTW, if anybody knows of a cheap hosting service which offers Python and >PostgreSQL, please let me know. http://www.python.org/cgi-bin/moinmoin/PythonHosting -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From jepler at unpythonic.net Tue Aug 5 21:47:05 2003 From: jepler at unpythonic.net (Jeff Epler) Date: Tue, 5 Aug 2003 20:47:05 -0500 Subject: Fatal Python error: unknown scope for... In-Reply-To: <1hpgt2ltmkd5a$.dlg@baczek.net.invalid> References: <1hpgt2ltmkd5a$.dlg@baczek.net.invalid> Message-ID: <20030806014701.GC17834@unpythonic.net> Confirmed in a local build (from CVS?), "Python 2.3b1 (#16, May 19 2003, 10:22:28)". I would swear this was discussed at some point, so there's a small chance it was fixed in 2.3. In any case, it's only happening in the presence of another (syntax) error so it's not as bad as it could be (but still bad for eg "restricted execution" environments, which 2.3 tells us don't work anyway) The following program shows a similar error (it's about the simplest program I could devise with the problem): def g(a=None, b, c=lambda: None): g """Fatal Python error: unknown scope for g in g(1) in marek.py""" This program doesn't: def g(a=None, b=None, c=lambda: None): g note the definition of default arg 'b'. This program dies with the syntax error, not the fatal internal error: def g(a=None, b, c=None): g """SyntaxError: non-default argument follows default argument""" Jeff From sjmachin at lexicon.net Sun Aug 10 02:00:04 2003 From: sjmachin at lexicon.net (John Machin) Date: 9 Aug 2003 23:00:04 -0700 Subject: Need elegant way to cast four bytes into a long References: <3f33c209$1@news.si.com> Message-ID: danb_83 at yahoo.com (Dan Bishop) wrote in message news:... > > One correct way of writing the expression without parentheses is > > a[0] | a[1] << 8 | a[2] << 16 | a[3] << 24 Sorry, Dan, I filed the patent application yesterday :-) From mack at incise.org Sat Aug 23 22:15:35 2003 From: mack at incise.org (mackstann) Date: Sat, 23 Aug 2003 21:15:35 -0500 Subject: List and array code? In-Reply-To: References: Message-ID: <20030824021535.GO1695@incise.org> On Sun, Aug 24, 2003 at 01:59:30AM +0000, derek / nul wrote: > Is there any list or array code that can load lines from a file? > > ie what I would like is to open a file and load line by line into a list or > array. > > Any pointers most appreciated. f = file("foobar.txt", "r") myListOfLines = f.readlines() Or if you really don't need to make list, but just want to loop through the lines in a file: f = file("foobar.txt", "r") for line in f: print line -- m a c k s t a n n mack @ incise.org http://incise.org A fool must now and then be right by chance. From jjl at pobox.com Wed Aug 13 06:23:38 2003 From: jjl at pobox.com (John J. Lee) Date: 13 Aug 2003 11:23:38 +0100 Subject: drop down feature References: Message-ID: <87k79hdff9.fsf@pobox.com> "Michael Peuser" writes: > I fully agree with your very comprehensive statements. I personally do not > know VB so much but RealBasic for Macintosh which is absolutely in the line > of useability. It is as well a very friendly GUI Builder with all > drag-n-drop and multimedia stuff AND it compiles AND it makes self contained > exe files!! > > This in fact is my wishlist for a Python IDE ..... > Of course the *language* itself is mess ;-) [...] Never bought the often-tacit assumption that programming environments that happen not to be entirely graphical, and that aren't run by clicking on a single .exe are somehow not integrated (in some ways they tend to be less well integrated, in others more), so: GUI builder: wxPython / BOA constructor OR PyQt / Qt designer OR VB (implement COM servers in Python, write GUI in VB) exe builder: py2exe OR McMillan Installer "drag-n-drop and multimedia stuff" Not sure what that means! John From kncbergmann at earthlink.net Sat Aug 16 12:57:23 2003 From: kncbergmann at earthlink.net (Kenneth Bergmann) Date: Sat, 16 Aug 2003 16:57:23 GMT Subject: GUI builder for Python References: Message-ID: I like BoaConstructor myself. Easy Quick Builds a nice interface ......And three out of three ain't bad "henry" wrote in message news:nx%_a.730754$3C2.17094058 at news3.calgary.shaw.ca... > Hi, > > Just wondering if there's a good GUI builder for Python. Something like > Visual Tcl, where you just drag and drop objects. > > Not too good with creating user interfaces from code along. > > Thanks > > From logiplex at qwest.net Thu Aug 21 18:28:23 2003 From: logiplex at qwest.net (Cliff Wells) Date: Thu, 21 Aug 2003 15:28:23 -0700 Subject: wxPython: need return value from wxFrame In-Reply-To: References: Message-ID: <1061504903.1506.227.camel@software1.logiplex.internal> On Thu, 2003-08-21 at 15:17, Mirko Koenig wrote: > Hi > > I have a frame where you can select/add/delte etc a customer address. > It is included in an wxApp to have a stand alone customer addressbook. > > Now i wrote a invoice application. I added a button to add a address to > the invoice. I want the customer addressbook to be open by clicking > on that button. No problem. So far so good. > > But i want the addressbook frame to return the selected address as a > tuple, list or dict. I don't have any idea how to do that. > > I can show() the frame from within the invoice code but show doesn't > return a value. Use a wxDialog instead. -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 (800) 735-0555 From t.bischoff at tu-bs.de Thu Aug 7 04:34:47 2003 From: t.bischoff at tu-bs.de (Thorsten Bischoff) Date: Thu, 07 Aug 2003 10:34:47 +0200 Subject: Version Problem Message-ID: Hi all! I have created a python extension module written in C. Now when the last release change took place, the module produces import errors under windows and some warnings under linux. As far as I understand the C to Python API has changed and so the module has to be relinked. But there I see a problem: If I have to relink and recompile my module every time there is a new python release, there will be no time left to do the very important things. Which is the recommanded way to deal with different python versions and extension modules? I'm looking for some easy-to-use method, preventing me from maintaining my module for different python versions and which gives the user the most flexibillity. That means I do not want either to enjoin on the user which python version to use nor to maintain many different versions of my module. Besides: Does anybody know a good method for GNU autoconf to check which python version is installed? Yours, Thorsten -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/ From vanevery at 3DProgrammer.com Tue Aug 19 05:03:56 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Tue, 19 Aug 2003 02:03:56 -0700 Subject: Brandon's personal style (was) References: <38ec68a6.0308172319.431a4fde@posting.google.com> Message-ID: Cliff Wells wrote: > To try to force those battles is about as reliable an indicator > of trolling as is "URGENT: YOUR IMMEDIATE ASSISTANCE REQUIRED" is a > reliable indicator of Nigerian spam. It should come as no surprise to > you that people mistake your posts as trolling. They may be > incorrect, but it is certainly a reasonable assumption. I hate to use an Eep-ism, but it's time for people to evolve. "You sound like a troll" is not that reasonable an assumption. Outside of politics newsgroups, I've almost never seen actual trolls. I've seen plenty of people insulting each other, totally unable to see the other person's point of view. I've seen countless instances of Troll Hunting all over Usenet that had nothing to do with me. In fact, it's clearly a popular newsgroup sport! People are intellectually lazy, they don't have an ironclad criterion for what is or isn't a troll. A troll is anything they don't like. They don't use imagination or exercise benefit of the doubt when controversial posts appear. They just enjoy naming things within a familiar pigeonholeing system. It comforts them. They are so focused on controlling group discourse, and not letting "the wrong kind of conversation" happen, that they don't put much thought into what was said in the first place. > Were you known to be a contributor, either with code or > knowledge, your forays into time-wasting speculation would most likely > be much better received. As it is the only "contribution" you've made > is a generous use of other people's time and bandwidth. As I see it, my detractors are enginerds with no appreciation for or skill at marketing. Nor, probably, much awareness of Python marketing efforts. That's how I figure you can (1) blithely ignore my analysis of Reality On The Ground, (2) merrily claim I'm a do-nothing. I've suggested you look at the marketing-python archives several times, it's a comment I've peppered here and there. Have you? > The fact that you get "kills" in every ng you spend time in probably > says more about you than other people. Actually, it says more about where I am in life. There was a time when I never killfiled anybody. If I was rude, and we got into fights, we'd just keep fighting. Often we'd kiss and make up. But sometimes, I'd get an intractable, unforgiving, obsessive compulsive fixated asshole on my ass for years. It drove me out of comp.games.development.* for a time, the hierarchy I created. I got fed up with being told that I was a troll, seeing as how I'd been Newsgroup Proponent. What the hell is that, the ultimate trolling? I've never trolled in my life. Abrasive, argumentative, violent, sure. Trolling, never. Anyways, a few years later I came back. I've been summarily killfiling people ever since. It does wonders for my long-term interaction with people and groups. I don't have to deal with the people I can't work with. > Personally I've never > killfiled anyone (not even the ruebot[!]) and to my knowledge, I've > yet to be > killfiled (although at times I'm a bit surprised at that, today being > one of those times). It's really very simple. Your behavior is not the same as other people's behavior. That's why we're still talking. > Why then, are you surprised when people choose to fight with you? Why do you say I'm surprised? This is all very predictable to me. Seen at this moment in time, you are a static type within this system. You just happen to be a benevolent, workable type. You are the "Well, are you going to killfile *me* too?" type. The kind of person who doesn't behave in a way that I would killfile, and who doesn't quite understand how his behavior is different from the people I do killfile. But, who probably will understand by the time I get done explaining it. Have you seen Enter The Matrix? The scene with The Architect is very profound. The Matrix demands Neo. Someone else observed, this stuff is all about young males. That's no accident, it's a feature of our genetics. Our genetics demand certain confrontations at a certain age. In our lives, we obey certain Grand Strategies, even if we are sapient and exercising choice over the details. > Taking your statements together > would seem to indicate that a fight is what you want. That's sorta true. This is really what I call a "posting binge," to avoid other things I don't want to be doing. I'm an intellectually violent person, I like a good debating scrap. But I've got Rules Of Engagement about what I think is appropriate, intellectually defensible debate. "You're a troll!" instead of hearing someone else's opinion ain't it. Those people, I want to punish. It's irrational, because intellectually I know I can't actually change them. Rationally, I can killfile them. Possibly, I can stimulate cumulative change in the system, but I am uncertain of it. In 10 years maybe I will have let it go. For instance, I'm reasonably sure I can stimulate minor change in your own static type. You understand enough of the dimensions already that you're capable of absorbing more of them. But you'll have probably gotten there on your own soon anyways, so am I really needed as a stimulus? Actually, I suspect I'm not for your benefit, if I am for anyone's benefit. I suspect it is for someone who is lurking. Maybe someone who hasn't formed much of a world view yet. Mine, at any rate, is in my .sig. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From skip at pobox.com Mon Aug 11 12:20:49 2003 From: skip at pobox.com (Skip Montanaro) Date: Mon, 11 Aug 2003 11:20:49 -0500 Subject: proper loop syntax? In-Reply-To: References: Message-ID: <16183.49761.467205.842721@montanaro.dyndns.org> JLowder> The problem is, only the first IF/ELIF are read. None of the JLowder> other elif's are used. In fact, the first elif is used when it JLowder> shouldn't be and I don't know why. This is my code snippet: JLowder> mask = "XXNNxxASSs" JLowder> for t in range(licenses): # licenses = 5 JLowder> for y in mask: JLowder> if y == "x": ... JLowder> elif y == "a" or "S": ... JLowder> elif y == "X" or "s": ... JLowder> license = license + license_char The elif clauses are incorrect. "X or "s" is valid, but doessn't do what you think it is doing (try fiddling with it at an interpreter prompt). You want if y == "x": ... elif y == "a" or y == "S": ... elif y == "X" or y == "s": ... or if y == "x": ... elif y in ["a", "S"]: ... elif y in ["X", "s"]: ... Skip From bokonon at rochester.rr.com Sun Aug 17 16:21:25 2003 From: bokonon at rochester.rr.com (Caleb Land) Date: Sun, 17 Aug 2003 20:21:25 GMT Subject: Python form oriented library Message-ID: Hello, I'm writing a small business accounting type program where the interface is a bunch of forms that represent tables in a database. The interface is usually used completely with the keyboard, but the mouse may also be used. The software does POS, inventory, accounting, etc. The widgets are mostly text entries. Are there any Python libraries that are targetted to this style of interface? If not, does anybody have references to libraries/resources in other languages that might be helpful in designing my own (APIs, design documents, etc)? I've tried googling, but I don't know exactly how to word my request. Sincerely, Caleb Land (bokonon at rochester.rr.com) From al at biolinux.ch Mon Aug 11 09:52:29 2003 From: al at biolinux.ch (Antoine Logean) Date: Mon, 11 Aug 2003 15:52:29 +0200 Subject: Customizing a linux distribuition using Python Message-ID: <3f379f4a@core.inf.ethz.ch> Hi, After having installed Linux (RedHat) on a PC I want to automate all the post-installation tasks. A lot of shell and perl scripts exist to do this. But I want to have something purelly object oriented where I can define the differents tasks in an abstract manner. Is that something in this direction in Python ? So any information concerning Linux (Unix) system administration and Python would interest me. Thanks for your help Antoine From mjackson at alumni.caltech.edu Tue Aug 19 14:50:00 2003 From: mjackson at alumni.caltech.edu (Mark Jackson) Date: 19 Aug 2003 18:50:00 GMT Subject: 3 new slogans References: Message-ID: There's one at the bottom of http://www.python.org/doc/Summary.html: Python - why settle for snake oil when you can have the whole snake? Hey, *I'd* buy the T-shirt! :-) -- Mark Jackson - http://www.alumni.caltech.edu/~mjackson In general, a standard is very useful, whether it's de facto or du jour. - Microsoft's Greg Sullivan as misquoted by News.Com From adalke at mindspring.com Sat Aug 9 02:59:09 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Sat, 9 Aug 2003 00:59:09 -0600 Subject: regular expression back references References: <25373bfe.0308081756.77ac86a8@posting.google.com> <3f3475fe.27768018@news.lexicon.net> Message-ID: John Machin > instead maybe something like > new_list = [] > for sep in '-.:': Yup. Much nicer. Clean, defensive programming is such effort. :) Andrew From fawcett at teksavvy.com Thu Aug 14 02:21:42 2003 From: fawcett at teksavvy.com (Graham Fawcett) Date: Thu, 14 Aug 2003 02:21:42 -0400 Subject: system call in python In-Reply-To: <200308140145.51759.skchim0@engr.uky.edu> References: <3F3B2012.9030101@teksavvy.com> <200308140145.51759.skchim0@engr.uky.edu> Message-ID: <3F3B2A76.7030804@teksavvy.com> satish k.chimakurthi wrote: > On Thursday 14 August 2003 01:37 am, Graham Fawcett wrote: > > >>Catherine Yang wrote: >> >> >>>Hi, >>> >>>A question about how to execute a system command from python program. e.g. >>>in a python script, I need to run another program written in C++, and >>>after that come back to the same python program. >>> >>> >>> >>> >>Probably you are looking for os.system, as in: >> >> >> >I think you can do the following: > >import commands >commands.getstatusoutput("...your command to execture program...") > > You're right of course, and that has the benefit of returning both status and output. On an editorial aside, I'd nominate the "commands" module as a Python wart. It's not that the functions in this module aren't useful, but why are they divorced from the very-much-related commands in the "os" module? IIWG (If I were Guido) I think I would at least sub-package this module as os.commands (in the spirit of os.path). While I was at it, I'd probably do the same for shutil (--> os.shutil). The Python standard library is full of dark corners bearing wondrous mysteries, a Library of Alexandria full of useful code... but surely even Alexandria's librarians put similar scrolls on the same shelf! -- G From mfranklin1 at gatwick.westerngeco.slb.com Thu Aug 28 04:45:29 2003 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Thu, 28 Aug 2003 09:45:29 +0100 Subject: Fwd: Re: homebrew 2.3 install on RedHat9 not playing nice with Tkinter Message-ID: <200308280945.29518.mfranklin1@gatwick.westerngeco.slb.com> ---------- Forwarded Message ---------- Subject: Re: homebrew 2.3 install on RedHat9 not playing nice with Tkinter Date: Thursday 28 August 2003 9:20 am From: "U. N. Owen" To: Martin Franklin I had also some problems with 2.3 on a debian, with an 2.1 initially installed. If I remember well, you must add the path to tk libs to yous LD_LIBRARY_PATH (not LD_RUN_PATH ??? I don't know this variable anyway). Since I am rather paranoid with paths I have lots of environ. variables that point to all libs and progs in my system, and I put all that stuff in PATH, LD_LIBRARY_PATH, C_INCLUDE_PATH and MANPATH... I modify PYTHONPATH too. Then you'll probably have to rerun configure then make, because the configure script looks for installed libs (and tk !). I think it should work on a Redhat 9. I have also installed Python on a Redhat 8 some day, and I had many problems with libraries not installed, but if you have already Python 2.2, you won't have this problem. Good luck ! ----- Original Message ----- From: Martin Franklin Date: Thu, 28 Aug 2003 08:42:51 +0100 To: python-list at python.org Subject: Re: homebrew 2.3 install on RedHat9 not playing nice with Tkinter Re: On Wednesday 27 August 2003 9:12 pm, Rob Andrews wrote: Re: > I'm on a Red Hat 9 system, which has Python 2.2.2 installed, and I Re: > installed 2.3 separately into /home/rob/Python-2.3/ (creating the symbolic Re: > link "py23" to point to my 2.3 installation). Now I'm trying to work out Re: > the kinks in the process. Re: > Re: > Unable to run Idle using 2.3 the way I've got things set up, I created a Re: > super simple Tkinter test program that just pops up a Label widget. I Re: > pasted below an example of how the RH-provided 2.2 runs the script without Re: > incident, but running the script with 2.3 produces a traceback. If someone Re: > can help me see the error of my ways, I'll be most appreciative. Re: > Re: > [Wed Aug 27][03:01 PM] ~/Python-2.3/test $ python -V Re: > Python 2.2.2 Re: > [Wed Aug 27][03:04 PM] ~/Python-2.3/test $ py23 -V Re: > Python 2.3 Re: > [Wed Aug 27][03:01 PM] ~/Python-2.3/test $ py23 test2.py Re: > Traceback (most recent call last): Re: > File "test2.py", line 1, in ? Re: > from Tkinter import Label Re: > File "/home/rob/Python-2.3/Lib/lib-tk/Tkinter.py", line 38, in ? Re: > import _tkinter # If this fails your Python may not be configured for Re: > Tk ImportError: No module named _tkinter Re: > [Wed Aug 27][03:01 PM] ~/Python-2.3/test $ python test2.py Re: > Re: > -Rob Re: > (mediocre with Python, incompetent with linux) Re: Re: Rob, Re: Re: I just finished building python 2.3 on my redhat 9 laptop... the first time I Re: did the make it failed (near the end) because it couldn't find the Tk/Tcl Re: libs. Re: Re: On my system they are in /usr/local/lib (because I built them myself) Re: on your's I guess they would be in /usr/lib. So to fix the build I set Re: LD_RUN_PATH to /usr/local/lib and them ran make again. Re: Re: Re: HTH Re: Martin Re: Re: Re: Re: Re: Re: Re: -- Re: http://mail.python.org/mailman/listinfo/python-list -- _______________________________________________ Get your free email from http://www.uymail.com Powered by Outblaze ------------------------------------------------------- From nav+posts at bandersnatch.org Tue Aug 19 15:55:38 2003 From: nav+posts at bandersnatch.org (Nick Vargish) Date: 19 Aug 2003 15:55:38 -0400 Subject: What's better about Ruby than Python? References: <3F40892D.AEF4AAE@alcyone.com> <87isov6pk4.fsf@pobox.com> <3F412081.5EF7279C@alcyone.com> <874r0ey9bx.fsf@pobox.com> Message-ID: jjl at pobox.com (John J. Lee) writes: > read everything slowly, chew the cud, *then* start writing. I read > the whole of Stroustrup and a couple of other books before writing a I couldn't get past the first chapter of Stroustrup... Maybe because I'd already been working with C++, it read like a pile of justifications for what I consider a bastardization of an elegant foundation. (So, I like C but dislike C++, what can I say?) Nick -- # sigmask || 0.2 || 20030107 || public domain || feed this to a python print reduce(lambda x,y:x+chr(ord(y)-1),' Ojdl!Wbshjti!=obwAcboefstobudi/psh?') From wiebke.paetzold at mplusr.de Mon Aug 4 07:13:18 2003 From: wiebke.paetzold at mplusr.de (Wiebke Pätzold) Date: Mon, 04 Aug 2003 13:13:18 +0200 Subject: Classes in Python References: <14dsivkn40c0grotsti39cgsrde7v03hq4@4ax.com> Message-ID: On Mon, 04 Aug 2003 12:30:11 +0200, Wiebke P?tzold wrote: >Hi all! > >Could somebody help me with a task? > >import sys >import Mk4py >import re > >db = Mk4py.storage("c:\\datafile.mk",1) >vw = db.view("people") > >class PatternFilter: > def _init_(self, pattern): > self.pattern = re.compile(pattern) > > def _call_(self, row): > try: > nachname = row.Nachname > except AttributeError: > return 0 > return self.pattern.search(nachname)is not None > >vf = vw.filter(PatternFilter("Ge.*")) > >for r in vf: > print vw[r.index].Nachname > > > >I wrote this program, but it returns nothing. I can't find the error. >Can somebody help me? >Can somebody tell me why the part: "class PatternFilter:" doesn't >return the expressions it should return? I create a database that contains a table. 'Nachname' and 'Kongressbereich' are special fieldnames. This program can search for a special letter. In my example it is 'G'. and the search takes place in 'Nachname'. Mow I want to use regular expression. So that I can limit my search. For example: I can search for Ge and it is not relevant wich letters follow > >Wiebke From jroznfgre at jngpugbjreQBGbet.cy Wed Aug 13 04:13:02 2003 From: jroznfgre at jngpugbjreQBGbet.cy (JZ) Date: Wed, 13 Aug 2003 10:13:02 +0200 Subject: libmysqld.dll & Python API seeking... Message-ID: Is there any Python module working with embed MySQL 4.x? I found only C++ API with not working example from MySQL manual. :( From mpeuser at web.de Sun Aug 17 03:01:43 2003 From: mpeuser at web.de (Michael Peuser) Date: Sun, 17 Aug 2003 09:01:43 +0200 Subject: bitwise not - not what I expected References: <1YD%a.747879$3C2.17342633@news3.calgary.shaw.ca> Message-ID: "Elaine Jackson" schrieb im Newsbeitrag news:1YD%a.747879$3C2.17342633 at news3.calgary.shaw.ca... ... > I'm writing a script that will > play Nim, just as a way of familiarizing myself with bitwise operators. Good > thing, too: I thought I understood them, but apparently I don't.) > Hi Elaine, You have described a general misconception you seem to be not the only one to live with. The enlightening answers having been posted might sufficwe, but a schuld liek to add some more "enlightenment": Bit complements have a lot to do with set complents and the aritmetic negation (sometimes called two's complement for obvious reasons). Consider the set of of "red" of "blue". Now whats the complement? "green" and "yellow" is obviously the wrong answer. You in fact cannot give any answer befor you define the total set you are dealing with. The same applies to logical bit operations. Generally you take a "processor" word or a part of it to be defined. Some high level languages are more flexible; and even some computers ("vector processors") are. The only rule is, that ~(~x) == x The same situation with numbers: What is the negation of +5. You have to think very hard! This is a trick question and you probably will give a "trick answer": -5. You should be aware that this is just a trick. "-5" contains no other information as that it is some "complement" of 5. (same with complex "imaginary" numbers: 5j (in Python) just says it is some fancy 5.) Now we define a transformation between positive numbers and bit patterns 5 = LoL. Note that 5 == ...000005 or LoL == ....ooooLoL does not help any understanding so you generally skip this part. Now you do some arithmetic "inversion": 5 -> -5 This however can (and should) stay a secret of the processor! By no means should you be interested in how the machine represents "-5". If you are courious then know that there had been times when computers represente -5 as ...LLLoLo. Yes it worked! And you had two diffrent "zeros" then: +0 and -0 !!!! Most computers do not distinguish between the representation of negativ numbers and complemented sets (let alone note a special "total set" the complemt was referring to). Thus the "secret" of modern two's-complement computern arithmetic is always disclosed to you. Note that there is no use in something like "masking" the MSB, i.e. that bits-complements only work on 31 bits. This will lead to ~5 == ~LoL == ~ LL..LLLLoL == 2,147,483,643 Not much improvement, eh!? Kindly Michael P From john at rygannon.com Mon Aug 11 17:31:43 2003 From: john at rygannon.com (BadJake) Date: Mon, 11 Aug 2003 21:31:43 GMT Subject: Rekall docs ready for download Message-ID: <3f380ac5$0$239$fa0fcedb@lovejoy.zen.co.uk> Hi The Rekall documentation of available from http://www.totalrekall.co.uk and http://www.rygannon.com. You find them in PDF, HTML and Windows HTML Help format -- Best Regards John From mcherm at mcherm.com Wed Aug 6 09:04:19 2003 From: mcherm at mcherm.com (Michael Chermside) Date: Wed, 6 Aug 2003 06:04:19 -0700 Subject: Checking for an "undefined" variable - newbie question Message-ID: <1060175059.3f30fcd34c6f7@mcherm.com> > How do I check if a variable has been defined?? > > The following don't appear to work: > > if variable: > > if variable is None: > > > I have only one (ugly) solution: > > try: > variable > except NameError: > ... > > which works, but is a bit clumsy if I just want to know if the thing already > exists. > > If there's a more elegant way to check this, that would be great! Daniel: For a newbie, you're doing GREAT! You have already correctly determined the best way to test if a variable exists. There IS an alternative... you can get ahold of the namespace as a dict, then see if the name is a key. Something like this: >>> g = globals() >>> print g.has_key('x') False >>> x = 7 >>> print g.has_key('x') True >>> ...except that depending on where you write this you might want locals() instead of globals(). However, your solution testing for the exception is just as good. You might ask, "If Python is such a nice language, how come it's so difficult to test whether a variable is defined?" In fact, the reason is that programs written in a pythonic style rarely ever need such a test. In some languages it is idiomatic to leave a variable undefined and use that as a "special value". But in Python, it is more idiomatic to go ahead and assign SOME value to the variable, then use "None" for the "special value" indicating there is no meaningful normal value. There are a couple of reasons for this practice. One is that variables in Python can refer to objects of any type, so even if "x" is NORMALLY an int, it can also be assigned to be None (or any other "special value") without a type mismatch syntax error. Another reason is that it's awefully convenient to test for None... with most object types, all values are considered "True", so just saying: if x: ... will execute the code when x has a value, and skip it if x is None. (Of course, if some other non-true values are allowed, like 0 or "", then you may need "if x is None" instead.) And lastly, its a bit of a pain to test for leaving a variable undefined, so it's easier to use None as the "special value". -- Michael Chermside From jzgoda at gazeta.usun.pl Sat Aug 9 08:59:12 2003 From: jzgoda at gazeta.usun.pl (Jarek Zgoda) Date: Sat, 9 Aug 2003 12:59:12 +0000 (UTC) Subject: Spell Checker References: <20030808180013.22305e65.wtrenker@shaw.ca> Message-ID: Martin Franklin pisze: > http://www.scriptfoundry.com/modules/snakespell/ I tried this one and it works. > http://sourceforge.net/projects/pyspelling/ This one doesn't have too much to offer... According to SF: "this project did not release any files" and its state is "pre-alpha". -- Jarek Zgoda Registered Linux User #-1 http://www.zgoda.biz/ JID:zgoda at chrome.pl http://zgoda.jogger.pl/ From missive at frontiernet.net Sun Aug 31 17:30:32 2003 From: missive at frontiernet.net (Lee Harr) Date: Sun, 31 Aug 2003 21:30:32 GMT Subject: python for dev of CAD type software References: <836a2f21.0308162222.413fefaa@posting.google.com> <836a2f21.0308301741.3bb388a6@posting.google.com> Message-ID: >> >is python suitable for a production level >> >deployment of CAD type of software. >> >> http://www.pythoncad.org/ >> > > PythonCAD appears to be only for Linux > Anything for MS-Windows platforms > What makes you say that? On the screenshots page (http://www.pythoncad.org/screenshots.html) It says specifically: PythonCAD can also work on Windows. Thanks to the amazing efforts of the Python, PyGTK and GTK developers, the code runs without modification. As features such as preference files are added to PythonCAD, Windows users are encouraged to provide suggestions for suitable locations for these type of files. The screenshot below was mailed in and shows PythonCAD running under Windows. It's really pretty nice, and they have been making amazing progress. From tgray at cox-internet.com Mon Aug 18 22:06:42 2003 From: tgray at cox-internet.com (Terry Gray) Date: Mon, 18 Aug 2003 21:06:42 -0500 Subject: os.system stdout redirection... In-Reply-To: <87ptj3kz5y.fsf@andreasen.org> References: <87ptj3kz5y.fsf@andreasen.org> Message-ID: Erwin S. Andreasen wrote: > Terry Gray writes: > > >>Using Python 2.2 in Debian linuxI am trying to change to a different >>directory, execute a 'make all' command, and redirect the output of >>the subshell to a PyQt window... I should be able to execute the >>os.system('cd newdirectory; make all'), but how do I redirect stdout >>of the new subshell created by the os.system call? > > > If you are going to use QT, Use QProcess. You can set it up to fire > off a signal when new output has arrived and then read it and update > your window. > > Thanks, exactly what I was looking for. From tismer at tismer.com Tue Aug 12 14:32:33 2003 From: tismer at tismer.com (Christian Tismer) Date: Tue, 12 Aug 2003 20:32:33 +0200 Subject: Howto MACRO in python ? In-Reply-To: <5.2.1.1.0.20030812121557.02b25d60@66.28.54.253> References: <001201c360cd$3da065b0$6400a8c0@EVOD31> <3F38D039.2B28800A@engcorp.com> <001201c360cd$3da065b0$6400a8c0@EVOD31> <5.2.1.1.0.20030812121557.02b25d60@66.28.54.253> Message-ID: <3F3932C1.8070207@tismer.com> Bob Gailer wrote: > At 10:49 PM 8/12/2003 +1000, Andrew Bennetts wrote: > >> On Tue, Aug 12, 2003 at 02:28:31PM +0200, Bill Loren wrote: >> > Welp, I'm trying to implement some kind of tracing mechanism which will >> > announce every function entrance >> > in Run-Time. >> > I wrote a trace function: >> [...] >> >> You don't need macros for this. Use sys.settracehook. > > > Having just read the docs on sys.settrace I am in the dark. This is a > good example of documentation that is too terse and presumptive to be > useful to those who are unfamiliar with the topic. > > Can you provide or direct us to some better explanation? Yes, just read the reply from Richie Hindle, two hours ago. This post contains demo code which explains how to do it. ciao - chris -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 pager +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From jorgencederberg at hotmail.com Tue Aug 12 09:52:11 2003 From: jorgencederberg at hotmail.com (=?ISO-8859-1?Q?J=F8rgen_Cederberg?=) Date: Tue, 12 Aug 2003 15:52:11 +0200 Subject: union in Python In-Reply-To: References: Message-ID: Wiebke P?tzold wrote: > Hi all, > > about union I found still something else. Perhaps it is better. But > here the program doesn't run too. What are the errors? > Can me somebody help? Somebody probably could, but as you haven't described what is wrong it is very difficult to help you. You could/should copy-paste the error-traceback that was printed when your program failed. > > import sys > import Mk4py > import re > > db = Mk4py.storage("c:\\datafile.mk",1) > vw = db.view("people") > > class PatternFilter: > def __init__(self, pattern, feld): > self.feld = feld > self.pattern = re.compile(pattern) > > def __call__(self, row): > try: > exec(self.feld+" = row."+self.feld) > except AttributeError: > return 0 > return self.pattern.search(eval(self.feld))is not None > > def union(feld_th, feld_na): > c = feld_th[:] > for i in range(len(feld_na)): > if feld_na[i] not in feld_th: > c.append(feld_na[i]) > return c > > feld_th = "Themenbereiche" > vf = vw.filter(PatternFilter("do.*", feld_th)) > > feld_na = "Nachname" > vf = vw.filter(PatternFilter("im.*", feld_na)) > > print feld_th, feld_na, union1(feld_th, feld_na) > print feld_th, feld_na, union2(feld_th, feld_na) Where are the functions union1 and union2 defined and why do you want to find the union between two strings, it doesn't make sense. On the other hand, if feld_th and feld_na where two lists it would make sense. Can you come up with a simpler example, and demonstrate what goes wrong? I don't have mk4py installed, and don't intend installing it. regards Jorgen From JLowder at 360commerce.com Mon Aug 11 12:04:02 2003 From: JLowder at 360commerce.com (JLowder at 360commerce.com) Date: Mon, 11 Aug 2003 11:04:02 -0500 Subject: proper loop syntax? Message-ID: Standard disclaimer here, I'm new to Python/Jython.. I have what should be a really simple for loop with nested if/elif's which doesn't seem to function correctly. The problem is, only the first IF/ELIF are read. None of the other elif's are used. In fact, the first elif is used when it shouldn't be and I don't know why. This is my code snippet: mask = "XXNNxxASSs" for t in range(licenses): # licenses = 5 for y in mask: if y == "x": if t == 0: license_char = "5" elif t == 1: license_char = "P" elif t == 2: license_char = "o" elif t == 3: license_char = " " elif t == 4: license_char = "*" elif y == "a" or "S": if t == 0: license_char = "T" elif t == 1: license_char = " " elif t == 2: license_char = "w" elif t > 2: license_char = "t" elif y == "X" or "s": if t == 0: license_char = "7" elif t == 1: license_char = "G" elif t == 2: license_char = "f" elif t == 3: license_char = "*" elif t > 3: license_char = "u" license = license + license_char The variable license ends up being TTTT55TTTT for the first pass. The 5's are correct, but the T's should only be there for two of the characters (I'm expecting the value to be "772255LTT7"). To save on the length of the email, I'm leaving out two more elif's. If I were to move the elif y == "X" or "s": to be the first elif, the T's would then become 7's. The first elif is the only one being used. What I don't understand is why is the first elif even being looked at if y does not equal a or S? My spacing works, because I endup with indent errors otherwise. The structure looks correct for what I'm used to in other scripting languages... What stupid human trick am I pulling here? Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: From mark at diversiform.com Fri Aug 1 12:38:24 2003 From: mark at diversiform.com (Mark Daley) Date: Fri, 1 Aug 2003 09:38:24 -0700 Subject: Parallel port monitoring Message-ID: I posted this to the python-help list, but didn't receive much of a response, so I'm posting it here, also: I've read many threads regarding parallel port manipulation, but is there anything that can simply monitor what's happening on the parallel port, and perhaps react to certain events on said port? I would much rather do that than simply program a preset wait time. TIA - Mark Daley -------------- next part -------------- An HTML attachment was scrubbed... URL: From alanmk at hotmail.com Fri Aug 15 11:43:27 2003 From: alanmk at hotmail.com (Alan Kennedy) Date: Fri, 15 Aug 2003 16:43:27 +0100 Subject: Test web server References: Message-ID: <3F3CFF9F.31E68A67@hotmail.com> [Axel Grune] > Hi, I'm writing a test script which should act like a simple webserver > but it does'nt work. IE works but Mozilla say the document contains no > data. Does any one no what the problem is? Hmm, works fine for me on IE6 and Netscape 6.2.1. What version of Mozilla are you using? -- alan kennedy ----------------------------------------------------- check http headers here: http://xhaus.com/headers email alan: http://xhaus.com/mailto/alan From pythonguy at Hotpop.com Thu Aug 14 02:10:10 2003 From: pythonguy at Hotpop.com (Anand Pillai) Date: 13 Aug 2003 23:10:10 -0700 Subject: FTP with urllib2 behind a proxy References: <7d6b0b33.0308070304.53588bf0@posting.google.com> <87d6feykl8.fsf@pobox.com> <84fc4588.0308130237.69d480a1@posting.google.com> <87wudhoh5c.fsf@pobox.com> Message-ID: <84fc4588.0308132210.2a35a03@posting.google.com> jjl at pobox.com (John J. Lee) wrote in message news:<87wudhoh5c.fsf at pobox.com>... > pythonguy at Hotpop.com (Anand Pillai) writes: The code obviously caters to the bottom-line, in case the programmer does not want to worry about environment variables, would like to install the handlers himself and his proxy needs authentication. In the last case, the HTTP_PROXY env variable does not help and you need to install the proxy handler yourself. I copied this stuff from my program which needs all these and more ( a USER-AGENT header for example ). -Anand > > You need to install a proxyhandler, authhandler, > > ftphandler and httphandler. Then build yourself > > an opener, that opens the doors for you ... :-) > > > > The following does the trick. > > > > proxy_handler = urllib2.ProxyHandler( {'http': 'myhttpproxy:80', > > 'https' : 'myhttpsproxy:443', > > 'ftp' : 'myftpproxy:21' } ) > > > > opener= urllib2.build_opener(proxy_handler, urllib2.HTTPBasicAuthHandler(), > > urllib2.HTTPHandler, urllib2.HTTPSHandler, > > urllib2.FTPHandler) > > > > # install this opener > > urllib2.install_opener(opener) > > > > # Go ahead, knock knock! > > > > req=urlli2.Request('ftp://ftp.gnu.org') > > data=urllib2.urlopen(req).read() > > A couple of things to add: you don't need to add handlers that already > get added by default by build_opener (FTPHandler and HTTPHandler, for > example). ProxyHandler is one of these default handlers, so if your > environment is set up for it (http_proxy, etc. environment variables), > you don't need to supply a ProxyHandler (of course, if your > environ. *isn't*, then you do need to supply one, to give it the proxy > details). You don't need Request objects (unless you want to add > headers to a Request, or pass Requests around). You don't need to > install a global opener, unless your code expects it -- it's just a > convenience (or an inconvenience, sometimes). > > Actually, did the OP say proxy basic auth. was involved? Don't > recall. I've never needed it for proxies, but there seems to be a > ProxyBasicAuthHandler in urllib2, so I guess that's what you meant to > use, rather than HTTPBasicAuthHandler (which is for website auth., not > proxy auth). > > So, after all that, you end up with: > > opener = urllib2.build_opener(urllib2.ProxyBasicAuthHandler) > data = opener.open('ftp://ftp.gnu.org').read() > > (I like to close the response explicitly, though) > > > John From geoff at gerrietts.net Wed Aug 27 17:19:59 2003 From: geoff at gerrietts.net (Geoff Gerrietts) Date: Wed, 27 Aug 2003 14:19:59 -0700 Subject: OT: Celebrity advice (was: Advice to a Junior in High School?) In-Reply-To: <20030827201213.GA4670@nl.linux.org> References: <3F4D0D8B.5E5F9488@engcorp.com> <20030827201213.GA4670@nl.linux.org> Message-ID: <20030827211959.GD30536@thoth.homegain.com> Quoting Gerrit Holl (gerrit at nl.linux.org): > Peter Hansen wrote: > > But if you refuse to go to prison, things get lethal pretty quickly. > > That's what "ultimately" refers to above. > > Well, I don't think they get very lethal, they get painful at most. It depends on the case. Several times in recent history, the American FBI has deployed lethal force when it was insufficiently provoked (Ruby Ridge, Waco). > > I think the key word in the above is "ultimately", and > > I can see why ESR would (I think validly) state what he did above. > > Ultimately, the state will use violence. But this violence should not > have lethal consequences. > > If 'lethal' would be replaced by 'using violence', this statement is > reasonable for some sorts of government decisions, but only for those > involving law (e.g. not involving building roads (however, roads *can* > be quite lethal ;)). Government derives its power initially from its control over the death of its subjects, from its ability to inflict death upon its subjects. Sometime in the last 500 years -- I want to say the 18th century? -- this evolved. While most governments do still have the authority to kill one of their subjects, governmental authority is more usually asserted in increased measures of control over the subject's lives. This control is based on the underlying principle that the governing body has access to overwhelming physical force. For a fascinating and horrifying read on this topic, I heartily recommend Michel Foucault's _Discipline and Punish_, a discussion of the evolution of police forces and the prison, and the ramifications that has for governmental power. I don't mean to suggest support for either side of the argument here; I'm not sure exactly where I stand. I think an awful lot of things are being assumed, and many more are being oversimplified, all to support positions which are, at base, emotional. --G. -- Geoff Gerrietts "If programming langauges were porn, Java would be bukkake." http://www.gerrietts.net --Dan Dillinger From NineOfSix at gmx.de Fri Aug 15 11:33:01 2003 From: NineOfSix at gmx.de (Axel Grune) Date: Fri, 15 Aug 2003 17:33:01 +0200 Subject: Test web server Message-ID: Hi, I'm writing a test script which should act like a simple webserver but it does'nt work. IE works but Mozilla say the document contains no data. Does any one no what the problem is? TIA, Axel The script: #!/usr/bin/python import socket DATA = """HTTP/1.0 200 OK Connection: Keep-Alive Content-Type: text/html Content-length: 71 Server: Python testHello Python! """ s = socket.socket( socket.AF_INET, socket.SOCK_STREAM) s.bind( ( '', 5333)) s.listen( 1) conn, addr = s.accept() conn.send( DATA) conn.close() From news at exultants.org Sat Aug 23 23:59:51 2003 From: news at exultants.org (Van Gale) Date: Sun, 24 Aug 2003 03:59:51 GMT Subject: Python is darn fast (was: How fast is Python) In-Reply-To: <2259b0e2.0308230737.8a9bc1c@posting.google.com> References: <2259b0e2.0308230737.8a9bc1c@posting.google.com> Message-ID: Michele Simionato wrote: > I posted this few weeks ago (remember the C Sharp thread?) but it went > unnoticed on the large mass of posts, so let me retry. Here I get Python+ > Psyco twice as fast as optimized C, so I would like to now if something > is wrong on my old laptop and if anybody can reproduce my results. > Here are I my numbers for calling the error function a million times > (Python 2.3, Psyco 1.0, Red Hat Linux 7.3, Pentium II 366 MHz): > > $ gcc erf.c -lm -o3 Did you really use "-o3" instead of "-O3"? The lowercase -o3 will produce object code file named "3" instead of doing optimization. Also, code optimization with gcc really seems to be a black art. It's just very application and machine specific as many Gentoo Linux users are discovering. For instance "-Os" can be much faster than "-O[23]" for some applications run on machines that have fast CPU's with low cache. It also seems that -O2 is faster in many cases than -O3 :/ Regardless, if psyco can speed things up to even unoptimized C range that's pretty impressive. Van From adalke at mindspring.com Sat Aug 16 14:04:56 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Sat, 16 Aug 2003 12:04:56 -0600 Subject: Why doesn't __call__ lead to infinite recursion? References: <2a82921f.0308151158.b8c9154@posting.google.com> Message-ID: Aahz: > you'll see __call__ there. When you do foo(), Python actually does > type(foo).__call__(foo). Because type(foo).__call__ is manipulating > foo, you don't get the circular reference. Not quite, but I don't understand how everything works so what I say may also need corrections. The call syntax "foo()" does two things. The first is to get the 'thing' used for the call and the second is to actually call it. The latter is not done recursively - if the returned thing can't be called, the attempt at making the call fails. If 'foo' is an instance, then the implementation code is something like thing_to_call = getattr(foo, "__call__") if thing_to_call is not None: DO_CALL(thing_to_call, args, kwargs) The 'DO_CALL' is not a Python function, it's part of how the implementation works. The getattr implementation for an instance first tries to find "__call__" in foo's instance __dict__. If that fails, it looks in the parent class, and returns a bound method, that is, a new 'thing' with references to the class method and to the instance itself. The DO_CALL does the actual call to this thing with the new arguments. The bound method thing prepends the self parameter and does the actual call to the underlying code. Pretty complicated, and I don't think I was very clear on that. Here's an example though to show that foo() != foo.__class__.__call__(foo) >>> class SPAM: ... def __init__(self): ... def callme(x): ... print "Hello", x ... self.__call__ = callme ... def __call__(self, x): ... print "Hej", x ... >>> spam = SPAM() >>> spam("world") Hello world >>> >>> spam.__class__.__call__(spam, "world") Hej world >>> >>> getattr(spam, "__call__") >>> getattr(spam, "__init__") > >>> getattr(SPAM, "__call__") >>> I'm also missing something because I don't know how functions work. I thought it was always 'use getattr(obj, "__call__") to get the thing to call then do the call machinery on that thing", but it doesn't seem to do that for functions. >>> def f(x): ... print "f(%s)" % x ... >>> def g(x): ... print "g(%s)" % x ... >>> f(5) f(5) >>> f(7) f(7) >>> f.__call__ = g.__call__ >>> f(4) f(4) >>> f.__call__ >>> f.__call__ >>> g.__call__ >>> g.__call__ >>> I expected the 'f(4)' call to return 'g(4)' since I replaced the function's __call__ with g's __call__. What's throwing me off is that g.__call__ returns a new wrapper object each time, while once I assigned f.__call__, it persistently stayed that way. So there's some getattr shenanigans with functions I don't understand. To make it worse, there's also >>> import types >>> types.FunctionType.__call__ >>> I'll leave the clarification to someone else. Andrew dalke at dalkescientific.com From oinkfreddie at oinkshlick.oinknet Mon Aug 4 10:50:58 2003 From: oinkfreddie at oinkshlick.oinknet (Freddie) Date: 5 Aug 2003 00:50:58 +1000 Subject: yEnc implementation in Python, bit slow Message-ID: Hi, I posted a while ago for some help with my word finder program, which is now quite a lot faster than I could manage. Thanks to all who helped :) This time, I've written a basic batch binary usenet poster in Python, but encoding the data into yEnc format is fairly slow. Is it possible to improve the routine any, WITHOUT using non-standard libraries? I don't want to have to rely on something strange ;) yEncode1 tends to be slightly faster here for me on my K6/2 500: $ python2.3 testyenc.py yEncode1 401563 1.82 yEncode1 401563 1.83 yEncode2 401562 1.83 yEncode2 401562 1.83 Any help would be greatly appreciated :) Freddie import struct import time from zlib import crc32 def timing(f, n, a): print f.__name__, r = range(n) t1 = time.clock() for i in r: #f(a); f(a); f(a); f(a); f(a); f(a); f(a); f(a); f(a); f(a) f(a) t2 = time.clock() print round(t2-t1, 3) def yEncSetup(): global YENC YENC = [''] * 256 for I in range(256): O = (I + 42) % 256 if O in (0, 10, 13, 61): # Supposed to modulo 256, but err, why bother? O += 64 YENC[I] = '=%c' % O else: YENC[I] = '%c' % O def yEncode1(data): global YENC yenc = YENC encoded = [] datalen = len(data) n = 0 while n < datalen: chunk = data[n:n+256] n += len(chunk) encoded.extend([yenc[ord(c)] for c in chunk]) encoded.append('\n') print len(''.join(encoded)), def yEncode2(data): global YENC yenc = YENC lines = [] datalen = len(data) n = 0 bits = divmod(datalen, 256) format = '256s' * bits[0] parts = struct.unpack(format, data[:-bits[1]]) for part in parts: lines.append(''.join([yenc[ord(c)] for c in part])) lines.append(''.join([yenc[ord(c)] for c in data[-bits[1]:]])) print len('\n'.join(lines) + '\n'), yEncSetup() teststr1 = 'a' * 400000 teststr2 = 'b' * 400000 for meth in (yEncode1, yEncode2): timing(meth, 1, teststr1) timing(meth, 1, teststr2) -- Remove the oinks! From tzot at sil-tec.gr Fri Aug 29 09:01:27 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Fri, 29 Aug 2003 16:01:27 +0300 Subject: Add two dicts References: <86ktkvkd05e88hu14hjudmfvbul7slfgkt@4ax.com> <2259b0e2.0308290440.670d316f@posting.google.com> Message-ID: On 29 Aug 2003 05:40:15 -0700, rumours say that mis6 at pitt.edu (Michele Simionato) might have written: [snip] > def __add__(self,other): > self.update(other) > return self.__class__(self) hm... I am not sure about this; it's not iadd, so you shouldn't modify self. Perhaps you should (untested): def __add__(self, other): temp = self.copy() temp.update(other) return temp -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From adalke at mindspring.com Thu Aug 21 06:06:53 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Thu, 21 Aug 2003 10:06:53 GMT Subject: Newbie problem with codecs References: Message-ID: <1R01b.1724$Ej6.454@newsread4.news.pas.earthlink.net> derek / nul: > Andrew, this what I was expecting, but my system does not do it. > > codecs.lookup("utf-16-le") > > this is the code cut from my program, but there is NO output from my program. I barely know what I am doing, and given that you don't report what you mean by "does not do it" nor "NO output from my program" makes it hard to track down this problem. Still, this might help. Suppose you wanted to read from a utf-16-le encoded file and write to a utf-8 encoded file. You can do reader_factory = codecs.getreader("utf-16-le") writer_factory = codecs.getwriter("utf-8") reader = reader_factory(open("input.utf16") writer = writer_factory(open("output.utf8", "rb") while 1: s = reader.read(100000) if not s: break writer.write(s) I've not actually tested this, but it seems that that should work given the API and my limited experimentation. I've not worked with this before, so if things fail, please repost (with more details) and hopefully someone with better knowledge can help you out. The other options is to do the conversion through strings instead of through files. # s = "....some set of bytes with your utf-16 in it .." s = open("input.utf16", "rb").read() # the whole file # convert to unicode, given the encoding t = unicode(s, "utf-16-le") # convert to utf-8 encoding s2 = t.encode("utf-8") open("output.utf8", "rb").write(s2) Again, untested. Andrew dalke at dalkescientific.com From davidcfox at post.harvard.edu Mon Aug 25 16:31:29 2003 From: davidcfox at post.harvard.edu (David C. Fox) Date: Mon, 25 Aug 2003 20:31:29 GMT Subject: Problem with lists In-Reply-To: <538fc8e.0308251204.1049e4f9@posting.google.com> References: <538fc8e.0308251204.1049e4f9@posting.google.com> Message-ID: WIWA wrote: > Hi, > > I'm writing an application to analyse my Apache access_log file. In > the below script (which is based on an example I found in 'How to > think as a Programmer'-) I want to measure the amount of hits per > hour. I know it is not the best algorithm but it works for now. > > I see some strange things: on rather small (it must be +/- < 4000 ) > entries in the access_log, my script works fine. Above this limit, I > get the following error. > > Traceback (most recent call last): > File "hits_per_uur.py", line 18, in > lijst.append(int(datum[1])) > IndexError: list index out of range > The error could be in datum[1]. Did you double-check that datum has at least two elements? David From bgailer at alum.rpi.edu Tue Aug 12 14:17:59 2003 From: bgailer at alum.rpi.edu (Bob Gailer) Date: Tue, 12 Aug 2003 12:17:59 -0600 Subject: Howto MACRO in python ? In-Reply-To: <20030812124903.GA5631@frobozz> References: <001201c360cd$3da065b0$6400a8c0@EVOD31> <3F38D039.2B28800A@engcorp.com> <001201c360cd$3da065b0$6400a8c0@EVOD31> Message-ID: <5.2.1.1.0.20030812121557.02b25d60@66.28.54.253> At 10:49 PM 8/12/2003 +1000, Andrew Bennetts wrote: >On Tue, Aug 12, 2003 at 02:28:31PM +0200, Bill Loren wrote: > > Welp, I'm trying to implement some kind of tracing mechanism which will > > announce every function entrance > > in Run-Time. > > I wrote a trace function: >[...] > >You don't need macros for this. Use sys.settracehook. Having just read the docs on sys.settrace I am in the dark. This is a good example of documentation that is too terse and presumptive to be useful to those who are unfamiliar with the topic. Can you provide or direct us to some better explanation? Bob Gailer bgailer at alum.rpi.edu 303 442 2625 -------------- next part -------------- --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.506 / Virus Database: 303 - Release Date: 8/1/2003 From vanevery at 3DProgrammer.com Tue Aug 19 05:06:08 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Tue, 19 Aug 2003 02:06:08 -0700 Subject: Brandon's personal style (was) References: Message-ID: Cliff Wells wrote: > On Mon, 2003-08-18 at 23:30, Brandon J. Van Every wrote: >> Cliff Wells wrote: >>> Brandon, on the other hand, is annoying and arrogant without the >> saving grace of being either stupid or insane. >> >> Well, at least my sanity is vouched for! Would be interesting for >> you to debate with Aahz. > > Threading is almost worthless with Python. Just typing "import > threading" practically guarantees a 40% slowdown in a Python > application. Plus the fact that you can't stop a running thread makes > them useless anyway. > > That should do it. I meant in regards to my sanity. ;-) Aahz has deduced that because I'm not a troll, I'm insane. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From google at hanger.snowbird.net Thu Aug 21 23:55:10 2003 From: google at hanger.snowbird.net (Kris Caselden) Date: 21 Aug 2003 20:55:10 -0700 Subject: Message Passing? Message-ID: What's the best method for communication between Python applications? I'm looking for a simple message-passing routine. I tried looking at pipes, but I haven't found much documentation. Sockets looks most promising, but it seems a little more complicated than what I'm looking for. Any suggestions? From someone at arbitrary.org Fri Aug 22 07:57:19 2003 From: someone at arbitrary.org (Joseph) Date: 22 Aug 2003 04:57:19 -0700 Subject: urllib2/httplib and email mime Message-ID: <4c8dd21a.0308220357.705d0db5@posting.google.com> Hello All, I am using email to create a multipart message that I need to post to a url. I have been doing it semi-manually with httplib: h = httplib.HTTP(self.host) h.putrequest("POST", self.url) h.putheader("Host", self.host) # Lot of other headers here... # Here is where it gets ugly h.putheader("Content-Type", 'multipart/mixed; boundary="===============0814072620=="' # Where I had to figure out what that was from my Message object I created earlier. # Now do ugly stuff to strip off the first 2 lines from my msg.as_string() # (omited due to modesty... It's too ugly) h.putheader("Content-length", str(len(stripped_msg))) h.endheaders() h.send(stripped_msg) Can someone sugest a cleaner way of doing this sort of thing using urllib2? The problem is getting the Content-Type header from my email object to be used by urllib2 as an http header. Thanks, Joseph From Henrik.Weber at sdm.de Thu Aug 7 04:00:57 2003 From: Henrik.Weber at sdm.de (Henrik Weber) Date: 7 Aug 2003 01:00:57 -0700 Subject: pychecking current source file in pythonwin References: <44254d3d.0308050441.3ae97677@posting.google.com> Message-ID: <44254d3d.0308070000.74003c4e@posting.google.com> Mark Hammond wrote in message news:... > Henrik Weber wrote: > > > Hi. > > > > I have tried to add pychecker as an extension to pythonwin. Now I can > > have pychecker check the source file that is currently open in the > > editor with a single keypress. If someone is interested, here is how > > to do it: > > Cool. Would you be interested in sending me a patch file? This makes > it much easier for me to integrate properly. > > > The script should write something like "pychecker is checking your > > source" into the status bar, but I haven't found out how to do that > > yet. Maybe some helpful soul can help out with that. > > win32ui.SetStatusText(message, True) > > Mark. I hope it arrived. Henrik. From jjl at pobox.com Tue Aug 19 08:09:28 2003 From: jjl at pobox.com (John J. Lee) Date: 19 Aug 2003 13:09:28 +0100 Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> <87brumwowx.fsf@pobox.com> Message-ID: <87ekzhdf2f.fsf@pobox.com> "Brandon J. Van Every" writes: > > Well, art is art, isn't it? Still, on the other hand, water is water! > > And east is east and west is west and if you take cranberries and stew > > them like applesauce they taste much more like prunes than rhubarb > > does. > > > > Groucho Marx. > > I almost got it. Not meant to be 'got'. Your mention of 'runon' sentences just reminded me of it, and that was good enough excuse for me :-) John From losnations at comcast.net Mon Aug 18 22:15:21 2003 From: losnations at comcast.net (Marc) Date: Mon, 18 Aug 2003 21:15:21 -0500 Subject: Design idea for Ping Application References: <4378fa6f.0308181546.548daff7@posting.google.com> Message-ID: If my company had wanted to spend money on something they wouldn't have asked me to do it ;) "Skip Montanaro" wrote in message news:mailman.1061250995.28274.python-list at python.org... > > Marc> I need an application that will continuously ping 11 different > Marc> hosts and track the status of the pings. > > Why not use a purpose built network monitoring tool like Nagios > (http://www.nagios.org/)? > > Skip > > From gh at ghaering.de Tue Aug 19 21:30:22 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Wed, 20 Aug 2003 03:30:22 +0200 Subject: distutils In-Reply-To: References: Message-ID: <3F42CF2E.9050106@ghaering.de> Bryan wrote: > what is the correct way to pass custom values to a distutil's setup script? i'd like to pass on the command line the libraries_dir > path. should i just parse it out from sys.argv? What works for me is passing values via environment variables. Examples: LOCALBASE: in the FreeBSD ports system, if set, use it, else default to /usr/local PG_ROOT: the source to the PostgreSQL build tree I use in pyPgSQL (only for win32, default to ../postgresql) Perhaps using environment variables is a simple way to solve your problems as well. -- Gerhard From vanevery at 3DProgrammer.com Tue Aug 19 04:20:52 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Tue, 19 Aug 2003 01:20:52 -0700 Subject: Brandon's abrasive style (was Re: What's better about Ruby than Python?) References: Message-ID: kosh wrote: > > Pointing out there is a problem with python speed for a certain kind > of operation with a code example is fine. > > Pointing out that python is stupid because it does not do what you > want where what you want is never clearly stated and no code is > presented is not. Quote it. No, here, let me help you out. http://groups.google.com/groups?as_q=stupid&safe=images&ie=UTF-8&oe=UTF-8&as_ugroup=comp.lang.python&as_uauthors=vanevery at 3DProgrammer.com&as_drrb=q&as_qdr=y&lr=&num=100&hl=en I've made 7 posts in c.l.p in the past year with the word "stupid" in them. None of them use the word as you suggest. Why don't you try barbequeing me for what I actually say, instead of your impressions and projections upon what I say? As far as I'm concerned, you can take it, and I'm not going to sugar coat it. Because you are proof that you won't read carefully, you'll form your own impressions and blast away anyways. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From logiplex at qwest.net Thu Aug 28 16:05:59 2003 From: logiplex at qwest.net (Cliff Wells) Date: Thu, 28 Aug 2003 13:05:59 -0700 Subject: OT: Americans love their guns In-Reply-To: References: Message-ID: <1062101159.32726.706.camel@software1.logiplex.internal> On Thu, 2003-08-28 at 12:46, maxx at easynews.com wrote: > On Thu, 28 Aug 2003 02:12:34 -0400, Lulu of the Lotus-Eaters > wrote: > > >USA gun-related deaths are ~29k/year > > And my probability of being one of them is pretty low - because I am usually > armed ;) I would think being armed increases your chances of engaging in an armed confrontation. Your position somehow assumes you would win any such conflict, which, until tested, is an unsupportable position. I just watched "Bowling for Columbine" last weekend. Interesting watch if you're interested in the topic. Regards, -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 (800) 735-0555 From fincher.* at osu.edu Thu Aug 7 06:08:12 2003 From: fincher.* at osu.edu (Jeremy Fincher) Date: Thu, 07 Aug 2003 06:08:12 -0400 Subject: itertools.ilen? References: Message-ID: Terry Reedy wrote: > An iterator is a function/method that traverses (or possibly > generates) a seqeuence. The sequence has a length (actual or > potential) but the iterator does not. Even some sequences don't have a length; consider (Lisp terminology) "improper lists," where the cdr points to a cell earlier in the list. Or any class with a somehow non-terminating __len__. > Alternative: initialize six counters to 0. Scan list once and update > appropriate counter. Yes, that works in this particular case, and is probably a superior solution. > If you mean a c-coded counter (which would not be an iterator itself) > equivalent to the above, that could be done. Perhaps len() could be > upgraded/extended to accept an iterator and count when it can't get a > __len__ method to call. The main downside is that iterators are > sometimes destructive (run once only). That's why I don't think such a change should be made to len(); *all* iterators are destructive and len() silently destroying them doesn't seem generally useful enough for the potential for mistake. > In the meanwhile, is this really a bottleneck for you? or merely the > 'pity' of a program running in 1 sec when 0.1 is possible? The whole of itertools really seems to exist because of the "pity" of taking efficient iterators and turning them into lists in order to do any significant manipulation of them. In that case, I would imagine the pity of having to turn an interator into a sequence in order to determine the length of the underlying sequence would be reason enough. Jeremy From mis6 at pitt.edu Mon Aug 4 17:34:44 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 4 Aug 2003 14:34:44 -0700 Subject: doctest -> unittest Message-ID: <2259b0e2.0308041334.3959db01@posting.google.com> Just today I have experimented with the new doctest -> unittest feature of Python 2.3. It works quite well, but I find the output way too much noisy. For instance #doctester.py def example(): """ >>> 1+1 1 """ import doctest,unittest,__main__ suite = doctest.DocTestSuite(__main__) unittest.TextTestRunner().run(suite) gives the following result: E ====================================================================== ERROR: doctest of __main__.example ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/local/lib/python2.3/unittest.py", line 413, in runTest self.__testFunc() File "/usr/local/lib/python2.3/doctest.py", line 1358, in runit _utest(tester, name, doc, filename, lineno) File "/usr/local/lib/python2.3/doctest.py", line 1308, in _utest raise DocTestTestFailure('Failed doctest test for %s\n' DocTestTestFailure: Failed doctest test for __main__.example File "doctester.py", line 2, in example ***************************************************************** Failure in example: 1+1 from line #1 of __main__.example Expected: 1 Got: 2 ---------------------------------------------------------------------- Ran 1 test in 0.013s FAILED (errors=1) It is too long for my taste, is there a way of turning off the traceback which is confusing more than useful? Michele From afriere at yahoo.co.uk Wed Aug 27 20:50:24 2003 From: afriere at yahoo.co.uk (Asun Friere) Date: 27 Aug 2003 17:50:24 -0700 Subject: Celebrity advice (was: Advice to a Junior in High School?) References: Message-ID: <38ec68a6.0308271650.ba2c1e1@posting.google.com> "Terry Reedy" wrote in message news:... > ... I > think it safe to say that during the 20th century, 99% of the 100s of > millions of murders were committed by armed govern-men rather than by > private persons acting alone. For which reason it is absolutely essential to have an armed civilian population so they can even the score up a little bit in this century. From alloydflanagan at comcast.net Tue Aug 26 15:15:09 2003 From: alloydflanagan at comcast.net (A. Lloyd Flanagan) Date: 26 Aug 2003 12:15:09 -0700 Subject: My own 12 points list References: Message-ID: pruebauno at latinmail.com (nnes) wrote in message news:... > I have really no mayor gripes, and the few things I would change would > break backward compatibility, but here is the list anyway: > > 3.) Eliminate open (), use file () instead open() is deprecated, I don't know about plans to eliminate it. > 5.) Eliminate built-in functions buffer(), callable(), delattr(), > dir(), getattr(), hasattr(), hash(), help(), id(), isinstance(), > len(), max(), min(), repr(), setattr(), sum(), str(), type(), Many of these are being superseded by object meathods. I don't know about eliminating them; you'd break nearly every old program. > 6.) Eliminate lambda, use local ?def somename(param):return expr' > instead. There's been a lot of discussion of this, but no consensus on the syntax. Certainly "lambda" is meaningless unless you're used to Lisp. See also PEP 312. > 11.) Add a big decimal type (something like java) in the standard > library. To be able to do bean counter type math easily. Are there so > few python applications that deal with money? I believe this is basically waiting on somebody to make a good implementation to be added to the standard. There are some third-party packages available. From aleax at aleax.it Mon Aug 4 07:19:07 2003 From: aleax at aleax.it (Alex Martelli) Date: Mon, 04 Aug 2003 11:19:07 GMT Subject: Python speed vs csharp References: <1h5f2rzthqgid.8watonaa4cjt.dlg@40tude.net> <3F551D29.1040407@kfunigraz.ac.at> <0MoXa.21930$cl3.850221@news2.tin.it> <3F55B1CE.5010607@kfunigraz.ac.at> Message-ID: Siegfried Gonzi wrote: > Alex Martelli wrote: > >> Still, the performance ratio of psyco-optimized Python vs C on my >> machine is much better than that of bigloo vs C on Mr Gonzi's Celeron, >> and with no need for type declarations either. So much, then, for >> Mr Gonzi's claims about Python being "more or less crap"!-) > > Oh man. I forget to tell if you comment out > > (x (exact->inexact x)) ...presumably avoiding floating-point in favour of rational... > the Bigloo version calculates things in 0.25 seconds (as compared to 0.5 > seconds of the C version). If true, this suggests unbelievably bad performance in your Celeron's floating-point hardware -- there's no other explanation as to why (software-implemented) rational arithmetic could outperform (hardware- implemented) float arithmetic. > Okay, a lot of people have learned a lot from your post. Maybe they can > use some techniques for their own Python programming. Particularly given that the Python-specific "techniques" amount (in all) to using a good optimizer (aka just-in-time compiler), psyco, I'm quite confident that many people can indeed use that. The idea of writing x*x instead of pow(x, 2.0) is just as good in C (as I've shown -- just that one change speeds up the C program by about two times) or Fortran (as I mentioned, it was for Fortran, over a quarter of a century ago, that I first learned of it) as just about any other language, so it's no doubt going to be even more widely applicable. > But still Python is crap. Sorry to tell you the truth. It is not only > speed. Look if I do not use types in Bigloo it is 10 times slower than > C. So performance is not everything; at least for me. Python is demonstrably more productive than lower-level languages (such as C) for application development, and demonstrably more acceptable to most programmers than languages of similar semantic level but with prefix rather than infix syntax. Therefore, your repeated flame-bait assertion that "still Python is crap", now totally unsupported, has sunk to abysmal levels (I don't see what more you could do to further lower your credibility). You've shown how good you are at numerical programming by coding "pow(x,2.0)" where any decently experienced coder would have coded "x*x" and thereby slowing down a whole C program by a factor of two. Now you show that your ability in evaluating programming languages is on a par with your ability in numerical programming -- unsurprising. > But Mr. Martelli your post was very funny. It is always a pleasure for > me to make loosers upset (yes I know your contribution to Python is huge > especially because you are book author). Oh, man I always thought such > individuals are just in the CommonLisp community. Is a "looser" somebody who is more loose (less uptight) than you, or somebody who looses (as in, eases, facilitates) things? Or is your ability at spelling on a par with your ability at numerical programming and language evaluation? In the latter case, you're surely reaching for an interesting "across the board" overall score. My contributions to Python have been pretty minor -- writing books is nice, sure, but of course it can't compare with the real contributions of the "core" Pythonlabs developers and those of many others. Nor did you make me _upset_ -- disgusted, yes, because I'm an optimist and like human beings in general, and it's always sad to see such a sad specimen as you attempt to pass itself off as a human being. As for "such individuals" (such as?) being "just in the Common Lisp community", what would that be describing? Was your working hypothesis that, when you post to a newsgroup about language X a flamebait about X being crap, accompanied by technically faulty examples in non-X languages, somebody will point out your idiocy only if X == "Common Lisp"? If so, then your understanding of Usenet is on a par with your ability at numerical programming, and so on -- truly, truly a sad ersatz-human being there. > If you are pragamatic Python is okay and has a lot to offer. More fodder for the "he spells as well as he programs" theory, I see. Not to mention that "is crap" and "is okay" are compatible only in the field of natural fertilizers (a field I heartily recomment you turn to, given your proven abilities in spewing male bovine exrement). Alex From adalke at mindspring.com Sat Aug 23 23:38:15 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Sun, 24 Aug 2003 03:38:15 GMT Subject: Modifying the {} and [] tokens References: Message-ID: Geoff Howland: > BTW, some of the other comments in my team have been for a desire of > more inclusive OO, such as [].len() instead of len([]), and this sort > of thing. As others have pointed out, you can use obj.__len__() if you really want to use it as a method. I admit this looks ugly. Hoever, there is a benefit to this approach. I am free to define any methods I want and any attributes on want, so long as the names don't both start and end with "__", which is reserved for the language. Compare this to, say, Ruby, where it takes extra knowledge to know that 'initialize', 'id', 'method', 'to_a', 'hash', and others have special meanings. Suppose I had a HashBrown controller, for a machine for making hash browns. I couldn't do the equivalent of possible_methods = ["soft", "crunchy", "southwestern"] class AbstractHashBrownController: def __init__(self, method, interface): assert method in possible_methods self.method = method self.id = interface.acquire_machine_identifier() def initialize(self): """Initialize hash-brown systems (eg, light the gas)""" def hash(self): """chop up the potatoes""" .... While this example is a bit extreme, it worries me that I need to remember all the methods names reserved by the language, and that if the base Object adds new methods then my code might accidentally break in consequence. Most languages don't need that many special variables, so I find it appropriate that when they are needed then I need to do a bit extra work for them. At a different extreme is Perl, where builtins don't have a leading sigil while variables do (or can), so if I have $hash then the language can add 'hash' and not affect anything. I find that too extreme because most things are user-defined code, so it makes the common case more complicated. Python then gets rid of the problem by defining builtins for accessing those __special__ methods, so they are rarely needed except for defining. (Though it then gains the problem that you need to know id uses __id__, bool uses __len__ and __nonzero__, + uses __add__ and __radd__ and __coerce__, etc.) Andrew dalke at dalkescientific.com From jjl at pobox.com Wed Aug 20 14:59:35 2003 From: jjl at pobox.com (John J. Lee) Date: 20 Aug 2003 19:59:35 +0100 Subject: PyQT installation problems References: Message-ID: <87k798b1ew.fsf@pobox.com> Greg Fortune writes: [...] > I've never had a problem > when I compiled a new version of qt on the machine and then compiled/linked [...] > Obviously, there's a lot of time/work involved in the solution above and the [...] And whether you do that or not, remember to compile PyQt using the -c for concatenate (IIRC) switch -- huge reduction in compilation time. John From martin at v.loewis.de Sat Aug 30 22:18:36 2003 From: martin at v.loewis.de (Martin v. =?iso-8859-15?q?L=F6wis?=) Date: 31 Aug 2003 04:18:36 +0200 Subject: Building 2.3 with tkinter on Linux References: Message-ID: Abstractius writes: > Have I missed any shortcuts or other obvious piece of documentation? You are probably missing the Tk header files. Your Linux vendor should have included them in some package on your CD-ROM; you need to install that package. Regards, Martin From Scott.Daniels at Acm.Org Fri Aug 15 18:11:52 2003 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 15 Aug 2003 15:11:52 -0700 Subject: Help from someone with new PKWare zip program In-Reply-To: <3f3d3e70$1@nntp0.pdx.net> References: <3f3d3e70$1@nntp0.pdx.net> Message-ID: <3f3d5aa6$1@nntp0.pdx.net> Scott David Daniels wrote: > PKWare has specified a new compression method (ZIP_BZIP2=12) for .zip > files.... I thought I'd try to teach the zipfile module to read and > write ZIP_BZIP2 compression as well as its current ZIP_DEFLATE format. > > If there is somebody out there with a copy of the PKWare program, > I'd like a small ZIP file compressed with that format, in order to > verify that I correctly produce / consume such files. Once I trust > my code is correct, I'll release it. > > -Scott David Daniels > Scott.Daniels at Acm.Org I forgot to explain: the .zip format (which is what the 'zipfile' module produces and consumes) is an archive file format -- it stores the data for multiple files in a single file. What I'm looking to do is interoperably read and write .zip format files using the stronger 'bz2' compression within the .zip file for compression of individual files within the archive, not for compression of the entire archive as a single unit. -Scott David Daniels Scott.Daniels at Acm.Org From andrew-pythonlist at puzzling.org Fri Aug 29 04:03:10 2003 From: andrew-pythonlist at puzzling.org (Andrew Bennetts) Date: Fri, 29 Aug 2003 18:03:10 +1000 Subject: how to find out the OO hierachy via the documentation? In-Reply-To: References: Message-ID: <20030829080309.GB403@frobozz> On Fri, Aug 29, 2003 at 03:48:24PM +1000, Leo wrote: > hi all > > newbie question: how do i find out the OO hierarchy of a class in the python > docu? > > the story: i want do play with the web server classes. so the first task > would be a basic server with SimpleHTTPServer. in the docu i've read about > the test() function but i couldn't find this function in the > SimpleHTTPServer class and even not in the BaseHTTPServer class which might > be the ancestor. > > so now i'd like to walk through the OO hierarchy of SimpleHTTPServer... The epydoc project (http://epydoc.sf.net/) has generated API docs for the Python 2.2 standard library with this sort of info in it, e.g.: http://epydoc.sourceforge.net/stdlib/public/SimpleHTTPServer.SimpleHTTPRequestHandler-class.html -Andrew. From martin at v.loewis.de Sat Aug 30 22:13:11 2003 From: martin at v.loewis.de (Martin v. =?iso-8859-15?q?L=F6wis?=) Date: 31 Aug 2003 04:13:11 +0200 Subject: Update to Python 2.3 on Red Hat Linux 9 References: <8242f4a7.0308282240.4c87f997@posting.google.com> Message-ID: jaybromley at hotmail.com (Jay Bromley) writes: > So the questions is, can I build Python 2.3 so that it recognizes all > the packages that are available to Python 2.2.2? Is this LD_RUN_PATH > stuff? You can't; this is not supported. The ABI has changed, so the old modules just wouldn't work anymore if they were found. > Or do I really need to find out all the libraries in use with > 2.2.2 and compile these for 2.3? Yes. Regards, Martin From dtolton at yahoo.com Wed Aug 13 03:00:31 2003 From: dtolton at yahoo.com (Doug Tolton) Date: Wed, 13 Aug 2003 07:00:31 GMT Subject: Python vs. C# References: <2259b0e2.0308100616.55b651ca@posting.google.com> <3f36af20@shknews01> <3f3959e3_1@news.vo.lu> Message-ID: On 12 Aug 2003 20:45:52 -0700, nonotreally999 at yahoo.com (Tom) wrote: > I think you should >read a book about Lisp (maybe even two) and then share your thoughts >with the comp.lang.lisp folks. Lisp is a really neat language (not >sure but maybe there's a Lisp.NET to explore!!!) and the c.l.l. folks >will be really interested in your insights. I think you and Erik will >hit it off big time. Ack, we already have one troll on c.l.l. I don't think we need another one. Although I think "Vain" Every is more of a troll than Yaas. c.l.l. seems to be lower volume that c.l.p., but those dudes are hella smart. These are the only two groups I actively watch. I honestly don't think "Vain" Every would ever be able to understand Lisp, even if he read ten books. He can't even grasp the simple truth behind open source. The beauty and power of Lisp are far beyond his reach I suspect. Doug Tolton From max at alcyone.com Mon Aug 18 18:21:07 2003 From: max at alcyone.com (Erik Max Francis) Date: Mon, 18 Aug 2003 15:21:07 -0700 Subject: What's better about Ruby than Python? References: <87ekzj6pbz.fsf@pobox.com> <87zni6ddki.fsf@pobox.com> Message-ID: <3F415153.D0858C0A@alcyone.com> "Brandon J. Van Every" wrote: > You know, people would get along a lot better if they didn't have the > intellectually lazy habit of "troll hunting." When people express > their > opinions about pros and cons, they are not trolling. But don't you find it interesting that an anomalously large percentage of people you encounter on Usenet -- the reaction of comp.lang.python is not at all atypical -- conclude that you're trolling? Since this has happened over and over again, ad infintum and ad nauseum, across all of Usenet, everywhere you go, and doesn't happen with nearly that much frequency to others, wouldn't it be reasonable to conclude there _might_ just possibly be something bad about your approach, particularly if you sincerely don't intend to troll? Aren't you just a little bit curious about why this keeps happening to you? -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ I want a martini that could be declared a disaster area. \__/ Capt. Benjamin "Hawkeye" Pierce From syver-en+usenet at online.no Wed Aug 6 17:43:26 2003 From: syver-en+usenet at online.no (Syver Enstad) Date: 06 Aug 2003 23:43:26 +0200 Subject: Python's biggest compromises References: Message-ID: Gerrit Holl writes: > Are Pearls and Ruby's organic? I don't think so - which must mean > that they are even older. I'll agree with Ruby's but perls are made my shells. Huh, I didn't get that joke before I wrote it. -- Vennlig hilsen Syver Enstad From fgeiger at datec.at Mon Aug 18 13:32:08 2003 From: fgeiger at datec.at (F. GEIGER) Date: Mon, 18 Aug 2003 19:32:08 +0200 Subject: python and symbian? References: Message-ID: <3f410d31@news.swissonline.ch> ...and has its roots in EPOC, a very stable OS for Psion-PDAs (discontinued, alas). Cheers Franz "Lawrence Oluyede" schrieb im Newsbeitrag news:bhqtsp$28jku$1 at ID-128383.news.uni-berlin.de... > Skip Montanaro wrote: > > > What's symbian? > > Symbian OS is the OS of new generation mobile phones made by Nokia, Sony > Ericsson and so on > Symbian itself is a consortium endorsed by Nokia, Siemems, Sony Ericsson > Motorola et. al. > > Some of the mobile phones with Symbian OS are Nokia 3650 and Sony Ericsson > P800 > > The OS ships with C++ SDK, Java and VB AFAIK > > www.symbian.com > > -- > Lawrence "Rhymes" Oluyede > http://loluyede.blogspot.com > rhymes at NOSPAMmyself.com From alanmk at hotmail.com Sat Aug 2 09:53:40 2003 From: alanmk at hotmail.com (Alan Kennedy) Date: Sat, 02 Aug 2003 14:53:40 +0100 Subject: useful tool for c.l.p References: Message-ID: <3F2BC264.55DE0865@hotmail.com> [Behrang Dadsetan wrote] > Would it not be wonderful to have some kind of integrated python > interpreter within the news agent/email program, so one could kinda > select the concerned code (or better, it is automaticly spotted) and > just let it run within the mail? :) That's a nice idea. However, were you to actually go ahead and implement this idea, we would then be exposing ourselves to serious security risks, since people could post malicious code in their posts. Not that that could possibly happen in c.l.py: we're all so nice here ;-) As Terry Reedy pointed out, it's not hard to fire up the interpreter and paste the script into it. Python's conciseness makes that very easy, even if the whitespace issue sometimes results in mangled code. And I always like to cast an eye over code before I run it, as a quick sanity check that its not going to do anything I don't want or like the look of. regards, -- alan kennedy ----------------------------------------------------- check http headers here: http://xhaus.com/headers email alan: http://xhaus.com/mailto/alan From tjreedy at udel.edu Thu Aug 28 11:09:27 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 28 Aug 2003 11:09:27 -0400 Subject: Celebrity advice References: <3F4CD2A2.DE7D05D2@engcorp.com> <23891c90.0308280317.ac68b38@posting.google.com> Message-ID: "A.M. Kuchling" wrote in message news:Kv-cnVDMbb1qmdOiRTvUqg at speakeasy.net... > On 28 Aug 2003 04:17:56 -0700, > It's really a pity that open source has no really effective spokesperson at > this time. > * Linus does a pretty good job as a public speaker, and he doesn't have > any of RMS's or ESR's baggage, but he's also not very interested > in the job. (The same goes for Guido.) He may get drawn into it more anyway. Nothing like being kicked in the pants to stir up a little adrenalin. Here is his take on SCO's dog show: http://www.eweek.com/article2/0,3959,1227128,00.asp (much shorter than the Perens analysis). Key line: "They are smoking crack". > The best candidate is Bruce Perens, IMHO. He has the technical background > of working on a non-trivial project (Debian), yet writes and presents in a > style that doesn't attract attention and doesn't let irrelevancies intrude. > Compare his commentary on SCO (http://www.perens.com/SCO/SCOSlideShow.html) > with ESR's counterblast. (To be fair, ESR's analysis of the code is also > pretty good; the OSI letter is where it becomes unacceptable.) Revolutionary movements need both firebrands and sober analysts. The SCO suit will prompt me to keep better 'audit trails' than I might of overwise. Prediction: If Torvalds and Perens are correct in what they said and the courts (including the 'court of public opinion') agree, Linux and the Open Source Movement will emerge stronger for the SCO challenge. Terry J. Reedy From patrick at novaroot.com Fri Aug 15 15:58:55 2003 From: patrick at novaroot.com (Patrick Lioi) Date: 15 Aug 2003 12:58:55 -0700 Subject: Why doesn't __call__ lead to infinite recursion? Message-ID: <2a82921f.0308151158.b8c9154@posting.google.com> def foo(): pass foo is a function foo is a callable object foo has method __call__ defined foo.__call__ is a function foo.__call__ is a callable object foo.__call__ has method __call__ defined foo.__call__.__call__ is a function... This seems to go on forever. How does calling foo() not lead to an infinite loop while trying to execute? From plaza247 at sbcglobal.net Sat Aug 23 23:03:42 2003 From: plaza247 at sbcglobal.net (Frank & Janny Plaza) Date: Sat, 23 Aug 2003 20:03:42 -0700 (PDT) Subject: How do you sort a name list and list in random order? Message-ID: <20030824030342.6848.qmail@web80407.mail.yahoo.com> I am trying to write a program in which the users will each enter their names and when all names have been entered, I want to randomly sort this list of names several times and then show the order in which they have beeen sorted. I tried using sort(), but this only sorts the names in the order in which they are entered. Any suggestions? Thanks, Cisco -------------- next part -------------- An HTML attachment was scrubbed... URL: From mwh at python.net Thu Aug 21 13:05:58 2003 From: mwh at python.net (Michael Hudson) Date: Thu, 21 Aug 2003 17:05:58 GMT Subject: Backtick Virgins References: Message-ID: <7h37k572ba1.fsf@pc150.maths.bris.ac.uk> Carl Banks writes: > Who else? Huh? Cheers, mwh -- (Of course SML does have its weaknesses, but by comparison, a discussion of C++'s strengths and flaws always sounds like an argument about whether one should face north or east when one is sacrificing one's goat to the rain god.) -- Thant Tessman From mpeuser at web.de Mon Aug 18 10:52:37 2003 From: mpeuser at web.de (Michael Peuser) Date: Mon, 18 Aug 2003 16:52:37 +0200 Subject: What's better about Ruby than Python? References: <87ekzj6pbz.fsf@pobox.com> Message-ID: "John J. Lee" schrieb im Newsbeitrag news:87ekzj6pbz.fsf at pobox.com... > "Michael Peuser" writes: > [...] > > I don't know much about Ruby but I did some substantial programming in > > Python and Perl. I should now consider side issues more important than > > language features itself: > > > > - How fast does the code run > > - Is there an acceptable IDE (best: GUI/IDE RAD-Framework) > > - Is there a flexible and fast GUI Toolkit > > -Can you access OpenGL > > - Which platforms are supported > > - How easy is multimedia (Sound/Movie in- and output) > > - How can you deploy your program > > - How large is a self contained EXE file > > - Is there mathematical support (array arithmetic, statistical functions, > > plotting) > > - Is there documentation > > - Are there books > > AFAIK, none of these are distinguishing features between Python and > Perl. > I absolutly disagree! We are (probably) not talking about the academic merits of the languages, but of what you can do with them with reasonable effort. Those "side issues" I mentioned above (and some more, and some of them not relevant for everyone) have - this is my experience - influenced my productivity more than everything else. Most of the things we do with - especially so called script languages is inetrfacing library packages. Thoug this is not a feature of the languge it is most important how to do it, what pachages have already been bound etc etc. Consider the permanent discussions about what GUI oder IDE to use. The OpenSource situation is, well unclear. I have learning a lot about that durung the last two weeks, and I would say: Well perhaps take eric3 and PyQt. But in fact I have no experience with eric and I very little with Qt. If all those would be in a state as VB with its Active-X support and quitre acceptable application framework or - eben better - as compiled RealBasic on Macintosh with its universal Quicktime interface, then I should say you could discuss fines language matters. (One should mention Delphi as well.) But this is not the case. > The really major differences are: Perl has tons of library code > (though Python has lots) and Perl has a pile of stuff you have to > learn that brings no significant benefits. It'd be great to see more > research on the impact of the nonsense-overhead that comes with Perl > (and is absent from Python). Just amount of "library code" is not what matters. You cannot have found it on my list ;-) Perl is not much better than Python - I think I did not mention that explicitly. Kindly Michael P > > John From syver-en+usenet at online.no Fri Aug 29 17:28:30 2003 From: syver-en+usenet at online.no (Syver Enstad) Date: 29 Aug 2003 23:28:30 +0200 Subject: DDE Hotlinks in Python References: Message-ID: Miguel Hern?ndez Martos writes: > Hello, > > I have seen an old post (http://dbforums.com/t552213.html) refering to > > the support for dde hot links in win32all. With dde module I can build > > a DDE server that notifies clients (VB and Delphi clients) of changes > (using SetData method) and it works great. > > The problem is that I also would like to code a Python dde client that > > can be notified of changes from a server. I browsed the source code of > > dde module and I think it can't be done, but I'm not a win32 guru. Can > > anybody tell me if that can be done with dde module bundled with > win3all? Hi Miguel, you are quite right that it can't be done with the current implementation of dde in win32all. I have made a patch to the dde module that implements dde hotlinks. I sent it to Mark Hammond about a year ago but I don't think it is included in win32all yet. I can see if I can locate the patch and send it to you if you are interested. -- Vennlig hilsen Syver Enstad From glenfant at NOSPAM.bigfoot.com Mon Aug 4 16:07:15 2003 From: glenfant at NOSPAM.bigfoot.com (Gilles Lenfant) Date: Mon, 4 Aug 2003 22:07:15 +0200 Subject: Example code for anydbm wanted... References: Message-ID: >"John D." a ?crit dans le message de news: mailman.1059955807.23968.python-list at python.org... > Does anyone have any good example code that shows how to use the "anydbm" wrapper tp interface with a very simple database. like some examples of how to > use "dumbdbm"? Then perhaps at a later time, I'm going to want to then interface it to a more robust database like PostGreSQL or mySQL. But I want to > external interface to "hide" the specifics and have a really generic interface. > > I already played with Python's interface with PostGreSQL, but they don't follow the generic Python models. At least my prev version didn't. > > John If you want power and object oriented generic interface to classical database engines, you may find some interest playing with modeling www.sf.net/projects/modeling or with dbobj at http://www.xs4all.nl/~bsarempt/python/dbobj.html . --Gilles From Scott.Daniels at Acm.Org Fri Aug 15 16:11:30 2003 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 15 Aug 2003 13:11:30 -0700 Subject: Help from someone with new PKWare zip program Message-ID: <3f3d3e70$1@nntp0.pdx.net> PKWare has specified a new compression method (ZIP_BZIP2=12) for .zip files. This format provides (or can provide) very good compression. Since python now has the bz2 module, I thought I'd try to teach the zipfile module to read and write ZIP_BZIP2 compression as well as its current ZIP_DEFLATE format. If there is somebody out there with a copy of the PKWare program, I'd like a small ZIP file compressed with that format, in order to verify that I correctly produce / consume such files. Once I trust my code is correct, I'll release it. -Scott David Daniels Scott.Daniels at Acm.Org From alan at norfolkgraphics.com Sun Aug 3 14:47:11 2003 From: alan at norfolkgraphics.com (Alan McIntyre) Date: Sun, 03 Aug 2003 14:47:11 -0400 Subject: Python and Robotics? References: <3f2d1e1d$0$4192$afc38c87@news.optusnet.com.au> Message-ID: <3F2D58AF.9000705@norfolkgraphics.com> There's Pyro, which is # 3 on this list: http://www.google.com/search?hl=en&lr=&ie=UTF-8&oe=UTF-8&q=python+robotics Hope this helps, Alan Darren wrote: > Hello All, > Hope everyone is well. > I am really new to python, so my question maybe some what stupid to > some. The question is, can python be used as a programming language for > robotics? eg, controling motors and sensors? > If so, do you know any website that would contain such information ? > > Many thanks > Darren > From gcf78 at hotmail.com Thu Aug 21 20:36:03 2003 From: gcf78 at hotmail.com (Garry) Date: 21 Aug 2003 17:36:03 -0700 Subject: Adding a column in a tab delimited txt file Message-ID: Hi, I am new to python, hope someone can help me here: I have a MS Access exported .txt file which is tab delimited in total 20 columns, now I need to add another column of zero at the 4th column position and a column of zero at the 9th column position. What is the best way to do this? Can I write a while loop to count the number of tab I hit until the counter is 4 and then add a zero in between and thru the whole file? Thanks, Garry From newsgroups at jhrothjr.com Fri Aug 1 08:13:20 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Fri, 1 Aug 2003 08:13:20 -0400 Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> <840592e1.0307312304.77a0a05f@posting.google.com> Message-ID: "Hannu Kankaanp??" wrote in message news:840592e1.0307312304.77a0a05f at posting.google.com... > anthony_barker at hotmail.com (Anthony_Barker) wrote in message news:<899f842.0307310555.56134f71 at posting.google.com>... > > What to you think python largest compromises are? > > I think reference counting is. Added to this the fact that > garbage collection is also possible (as in Jython). So we get > the worst of both worlds. > > 1. Idioms like this won't work portably: > > def foo(): > f = file('x') > return f.read() > > Even though f.__del__ closes the file, in garbage > collected environment the f object might not get deleted > in a good while, and would cause problems. > > 2. And then, we still need to use weakref to ensure > that our crossreferenced stuff works both with and without GC. > > Worst of both indeed. Maybe the decision to choose reference > counting was driven by speed considerations. That might've > been reasonable back in early 90's, but GC techniques have > evolved from those days and so GC would be a superior > technique now. > > Well, since no one else pointed this out yet, maybe there's > some flaw in my reasoning. There's a flaw in your reasoning. The various techniques that descend from mark and sweep (which is what you're calling garbage collection) depend on being able to identify all of the objects pointed to. For objects that are owned by Python, that's a lengthy (that is, inefficient) process, and it's not possible in general for objects that are created by extensions. Reference counting only depends on having the object itself, and control of the creation and removal of references. The latter is a frequent source of bugs and memory leaks in extensions. It's easy to say that various languages would be improved by adding "real" garbage collection, but those techniques impose significant design constraints on the implementation model. John Roth From danbmil99 at yahoo.com Fri Aug 15 23:38:58 2003 From: danbmil99 at yahoo.com (dan) Date: 15 Aug 2003 20:38:58 -0700 Subject: GUI builder for Python References: Message-ID: "henry" wrote in message news:... > Hi, > > Just wondering if there's a good GUI builder for Python. Something like > Visual Tcl, where you just drag and drop objects. > > Not too good with creating user interfaces from code along. > > Thanks Been wondering myself. How is http://sourceforge.net/projects/wxworkshop/? this looks nice and it's free. From jjl at pobox.com Fri Aug 29 20:26:59 2003 From: jjl at pobox.com (John J. Lee) Date: 30 Aug 2003 01:26:59 +0100 Subject: Bayesian kids content filtering in Python? References: <20030828161409.V40715@onyx.ispol.com> <87n0dsqqhd.fsf@pobox.com> Message-ID: <8765kg6ld8.fsf@pobox.com> jjl at pobox.com (John J. Lee) writes: > "Paul Paterson" writes: [...] > censor, and you're not going to block them all. It may work well most > of the time, but is that enough? What's needed here, perhaps, is an > open effort to train on categories of things that people would like to > block. That might be enough, since I suppose *most* things you're [...] Thinking a bit more, that might well fail. It assumes that our high-level categories of things we want to block line up in a simple way with the workings of the algorithm, which is very doubtful when the set of things to filter is no longer highly restricted as in the email case. Though some censorship targets probably *are* spammishly predictable and unimaginative, no doubt lots aren't, too. I'm reminded of the experience of a miltary research project using neural networks to recognise tanks in aerial photographs. They got someone to go and take photos of tanks and other large tank-like objects partially hidden in forested terrain, and trained their network on a fraction of the photos. When they tested the network on the rest of the photographs, they were delighted to discover that it performed fantastically well, despite the great variability in the appearance of the objects and terrain, distinguishing tank from non-tank almost perfectly. Inexplicably, though, when they fed a very similar set of photos to same network, it failed miserably. It turned out that what the network had *really* trained on was not at all what they'd assumed. To take the photos, they'd gone out and scattered the real tanks over the landscape, and taken a set of tank photos. Then they'd moved the tanks out and put the mock-tanks in, and taken a set of mock-tank photos. Of course, that meant all the tank-photos were taken in bright light, and all the mock-tank photos were in dim light of late afternoon. The neural network sensibly picked up that the easy way to tell the two apart was just to look at how bright they were! I made the details of that story up, but who cares ;-) John From borcis at users.ch Thu Aug 21 09:28:24 2003 From: borcis at users.ch (Borcis) Date: Thu, 21 Aug 2003 15:28:24 +0200 Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> <6dj2kv8ugkieehs7guh786cl40o5lj6mcs@4ax.com> <599a6555.0308202108.397bb1a0@posting.google.com> Message-ID: <3F44C8F8.3010307@users.ch> Anton Vredegoor wrote: > > The ability to maintain internal consistency and the tendency of other > people to fill in the gaps so that the final product seems coherent is > IMO the main reason for this strange time-travel-like ability of > making the right decisions even before all the facts are available. Wow :) From creedy at mitretek.org Tue Aug 26 16:38:32 2003 From: creedy at mitretek.org (Chris Reedy) Date: Tue, 26 Aug 2003 16:38:32 -0400 Subject: My future Python IDE article In-Reply-To: References: Message-ID: <3f4bc599_6@corp.newsgroups.com> David Mertz wrote: > > So c.l.py readers... make the case for your favorite one getting on the > list. I have a while to ponder the opinions advanced, should this > prompt some discussion (it may take a little while to order review > copies of commercial tools and/or get things installed). Boy, this is a hard one. I currently use IDLE for all my work, mostly since it comes gratis with Python. For that reason I find myself wanting to argue for its inclusion so I have a baseline for comparison. Beyond that, I think the ones I'd be most interested in hearing about would be eric3 and Komodo, mainly because those are ones where I've gone to the trouble to look at their web pages. Chris -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! -----== Over 100,000 Newsgroups - 19 Different Servers! =----- From davesum99 at yahoo.com Wed Aug 6 10:14:37 2003 From: davesum99 at yahoo.com (smarter_than_you) Date: 6 Aug 2003 07:14:37 -0700 Subject: recompiled midipy.pyd for 2.3 References: Message-ID: FYI -- I just tested downloading the file I just posted. In IE, it saves with an .htm extension but it compares correctly with the file. In NS, it downloads with the right extension but appears to be corrupted (linefeeds I think). I'm no HTML jockey so go figure. From peter at engcorp.com Thu Aug 14 07:31:36 2003 From: peter at engcorp.com (Peter Hansen) Date: Thu, 14 Aug 2003 07:31:36 -0400 Subject: Running Python 2.3 on a Windows 2000 network References: <3F3A8199.B42F1BF5@engcorp.com> Message-ID: <3F3B7318.40C9759B@engcorp.com> Thomas Heller wrote: > > Peter Hansen writes: > > > John Ochiltree wrote: > >> > >> Worked like a dream. I now have a shared python shell > > > > Can you check whether "import pythoncom" and "import pywintypes" > > and (if you've installed the Win32 extensions) "import win32api" > > all work? > > > > If these work without your having to do anything to the registry, > > I'm curious about the installation process you used, since we > > had to do additional steps to get the same result. > > You are aware that recently Mark changed things so the the registry is > no longer used for importing? No! Thank you... my experience comes from setting this up with versions prior to the latest (or "recently" released ones) so likely once we upgrade we can abandon the trickery. Good to know. -Peter From donot at likespam.com Wed Aug 27 11:29:05 2003 From: donot at likespam.com (Rich) Date: Wed, 27 Aug 2003 08:29:05 -0700 Subject: newbie Message-ID: I just downloaded the beginner package from the "Python" site, and would like some advice as to how to begin to learn how to program. Is there exercise to do, or do I need to wade through the site? TIA Rich From mal at lemburg.com Wed Aug 6 03:52:06 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed, 06 Aug 2003 09:52:06 +0200 Subject: MySQLdb and egenix mxDateTime dumps core In-Reply-To: <20030805224935.GA7194@dave@alana.ucc.usyd.edu.au> References: <20030805224935.GA7194@dave@alana.ucc.usyd.edu.au> Message-ID: <3F30B3A6.5090708@lemburg.com> Dave Harrison wrote: > Hi all, got a problem combinging mx and MySQLdb, when I build and install both for my Python2.1 install on a Solaris 9 box I can import mx fine, but importing MySQLdb causing python to core dump. You hit an optimizer compiler bug on Solaris. The best thing to do, is to comment out these lines in mx/DateTime/mxDateTime/mxDateTime.c (near the top): /* Define these to have the module use free lists (saves malloc calls) */ #define MXDATETIME_FREELIST #define MXDATETIMEDELTA_FREELIST and then recompile the egenix-mx-base package. > I am using egenenix 2.0.4 and MySQLdb 0.9.2. > > I have also replaced the -shared flag in the Makefile is /usr/local/lib/Python2.1/config with -G (a recommended solaris change to let the build of the modules work in the first place) -> notably I also made sure I recompiled python from source using this flag in the makefile too. > > I plead guilty to not knowing a heap about debugging linking etc etc, tho I do know a bit of C. > > Any help is REALLY REALLY appreciated ;-) this problem is just sending me right round the bend ;-) > > cheers > Dave > > Here is a transcription of the trace from the core dump : > > #0 mxDateTime_New () at mx/DateTime/mxDateTime/mxDateTime.c:279 > #1 0xff01396c in mxDateTime_FromDateAndTime (year=-5851455, month=-4217812, day=3, hour=680236, > minute=1096156, second=0) at mx/DateTime/mxDateTime/mxDateTime.c:952 > #2 0xff018b1c in mxDateTime_DateTime (self=0x0, args=0xffa6b6c1) at mx/DateTime/mxDateTime/mxDateTime.c:3667 > #3 0x22858 in call_cfunction (func=0xfc568, arg=0x101e6c, kw=0x0) at Python/ceval.c:2854 > #4 0x207a4 in eval_code2 (co=0x115cc0, globals=0x0, locals=0xfc568, args=0x10c164, argcount=0, kws=0xe1050, > kwcount=0, defs=0x0, defcount=0, closure=0xfc568) at Python/ceval.c:1948 > #5 0x1da3c in PyEval_EvalCode (co=0x0, globals=0xc3ddc, locals=0x3) at Python/ceval.c:341 > #6 0x322f4 in PyImport_ExecCodeModuleEx (name=0xffbfb118 "mx.DateTime.DateTime", co=0x115cc0, > pathname=0xffbfa738 "/usr/local/lib/python2.1/site-packages/mx/DateTime/DateTime.pyc") > at Python/import.c:490 > #7 0x328d8 in load_source_module (name=0xffbfb118 "mx.DateTime.DateTime", > pathname=0xffbfa738 "/usr/local/lib/python2.1/site-packages/mx/DateTime/DateTime.pyc", fp=0x115cc0) > at Python/import.c:754 > #8 0x33184 in load_module (name=0xffbfb118 "mx.DateTime.DateTime", fp=0xb4038, > buf=0xffbfac28 "/usr/local/lib/python2.1/site-packages/mx/DateTime/DateTime.py", type=1) > at Python/import.c:1301 > #9 0x33fe8 in import_submodule (mod=0xb54fc, subname=0xffbfb124 "DateTime", > fullname=0xffbfb118 "mx.DateTime.DateTime") at Python/import.c:1829 > #10 0x33b68 in load_next (mod=0xb54fc, altmod=0xa6cd8, p_name=0xffbfb124, > buf=0xffbfb118 "mx.DateTime.DateTime", p_buflen=0xffbfb114) at Python/import.c:1685 > #11 0x33738 in import_module_ex (name=0x0, globals=0xb54fc, locals=0x100664, fromlist=0xffbd4) > at Python/import.c:1536 > #12 0x33910 in PyImport_ImportModuleEx (name=0xfa564 "DateTime", globals=0x100664, locals=0x100664, > fromlist=0xffbd4) at Python/import.c:1577 > #13 0x77254 in builtin___import__ (self=0x0, args=0xfa564) at Python/bltinmodule.c:31 > #14 0x22858 in call_cfunction (func=0xb5ce0, arg=0x1032d4, kw=0x0) at Python/ceval.c:2854 > #15 0x227bc in call_object (func=0xb5ce0, arg=0x1032d4, kw=0x0) at Python/ceval.c:2807 > #16 0x22548 in PyEval_CallObjectWithKeywords (func=0xb5ce0, arg=0x1032d4, kw=0x0) at Python/ceval.c:2740 > #17 0x20124 in eval_code2 (co=0x103df0, globals=0x0, locals=0x100664, args=0xfd749, argcount=0, kws=0x1032d4, > kwcount=0, defs=0x0, defcount=0, closure=0xb5ce0) at Python/ceval.c:1820 > #18 0x1da3c in PyEval_EvalCode (co=0x0, globals=0xffbd4, locals=0xb5ce0) at Python/ceval.c:341 > #19 0x322f4 in PyImport_ExecCodeModuleEx (name=0xffbfc830 "mx.DateTime", co=0x103df0, > pathname=0xffbfb960 "/usr/local/lib/python2.1/site-packages/mx/DateTime/__init__.pyc") > at Python/import.c:490 > #20 0x328d8 in load_source_module (name=0xffbfc830 "mx.DateTime", > pathname=0xffbfb960 "/usr/local/lib/python2.1/site-packages/mx/DateTime/__init__.pyc", fp=0x103df0) > at Python/import.c:754 > #21 0x33184 in load_module (name=0xffbfc830 "mx.DateTime", fp=0xb4028, > buf=0xffbfbe50 "/usr/local/lib/python2.1/site-packages/mx/DateTime/__init__.py", type=1) > at Python/import.c:1301 > #22 0x32ae8 in load_package (name=0xffbfc830 "mx.DateTime", pathname=0xfd500 "") at Python/import.c:811 > #23 0x331f0 in load_module (name=0xffbfc830 "mx.DateTime", fp=0x0, > buf=0xffbfc340 "/usr/local/lib/python2.1/site-packages/mx/DateTime", type=5) at Python/import.c:1324 > #24 0x33fe8 in import_submodule (mod=0xb551c, subname=0xffbfc833 "DateTime", fullname=0xffbfc830 "mx.DateTime") > at Python/import.c:1829 > #25 0x33b68 in load_next (mod=0xb551c, altmod=0xb551c, p_name=0xffbfc833, buf=0xffbfc830 "mx.DateTime", > p_buflen=0xffbfc82c) at Python/import.c:1685 > #26 0x33874 in import_module_ex (name=0x0, globals=0xb551c, locals=0xfe744, fromlist=0xd2764) > at Python/import.c:1543 > #27 0x33910 in PyImport_ImportModuleEx (name=0x10052c "mx.DateTime", globals=0xfe744, locals=0xfe744, > fromlist=0xd2764) at Python/import.c:1577 > #28 0x77254 in builtin___import__ (self=0x0, args=0x10052c) at Python/bltinmodule.c:31 > #29 0x22858 in call_cfunction (func=0xb5ce0, arg=0xfe77c, kw=0x0) at Python/ceval.c:2854 > #30 0x227bc in call_object (func=0xb5ce0, arg=0xfe77c, kw=0x0) at Python/ceval.c:2807 > #31 0x22548 in PyEval_CallObjectWithKeywords (func=0xb5ce0, arg=0xfe77c, kw=0x0) at Python/ceval.c:2740 > #32 0x20124 in eval_code2 (co=0x1006d8, globals=0x0, locals=0xfe744, args=0xfa87b, argcount=0, kws=0xfe77c, > kwcount=0, defs=0x0, defcount=0, closure=0xb5ce0) at Python/ceval.c:1820 > #33 0x1da3c in PyEval_EvalCode (co=0x0, globals=0xd2764, locals=0xb5ce0) at Python/ceval.c:341 > #34 0x322f4 in PyImport_ExecCodeModuleEx (name=0xffbfda58 "MySQLdb.times", co=0x1006d8, > pathname=0xffbfd078 "/usr/local/lib/python2.1/site-packages/MySQLdb/times.pyc") at Python/import.c:490 > #35 0x328d8 in load_source_module (name=0xffbfda58 "MySQLdb.times", > pathname=0xffbfd078 "/usr/local/lib/python2.1/site-packages/MySQLdb/times.pyc", fp=0x1006d8) > at Python/import.c:754 > #36 0x33184 in load_module (name=0xffbfda58 "MySQLdb.times", fp=0xb4018, > buf=0xffbfd568 "/usr/local/lib/python2.1/site-packages/MySQLdb/times.py", type=1) at Python/import.c:1301 > #37 0x33fe8 in import_submodule (mod=0xb52fc, subname=0xffbfda60 "times", fullname=0xffbfda58 "MySQLdb.times") > at Python/import.c:1829 > #38 0x33b68 in load_next (mod=0xb52fc, altmod=0xb52fc, p_name=0xffbfda60, buf=0xffbfda58 "MySQLdb.times", > p_buflen=0xffbfda54) at Python/import.c:1685 > #39 0x33874 in import_module_ex (name=0x0, globals=0xb52fc, locals=0xc10d4, fromlist=0xc6adc) > at Python/import.c:1543 > #40 0x33910 in PyImport_ImportModuleEx (name=0xb9fe4 "MySQLdb.times", globals=0xc10d4, locals=0xc10d4, > fromlist=0xc6adc) at Python/import.c:1577 > #41 0x77254 in builtin___import__ (self=0x0, args=0xb9fe4) at Python/bltinmodule.c:31 > #42 0x22858 in call_cfunction (func=0xb5ce0, arg=0xc85bc, kw=0x0) at Python/ceval.c:2854 > #43 0x227bc in call_object (func=0xb5ce0, arg=0xc85bc, kw=0x0) at Python/ceval.c:2807 > #44 0x22548 in PyEval_CallObjectWithKeywords (func=0xb5ce0, arg=0xc85bc, kw=0x0) at Python/ceval.c:2740 > #45 0x20124 in eval_code2 (co=0xc8130, globals=0x0, locals=0xc10d4, args=0xb96b1, argcount=0, kws=0xc85bc, > kwcount=0, defs=0x0, defcount=0, closure=0xb5ce0) at Python/ceval.c:1820 > #46 0x1da3c in PyEval_EvalCode (co=0x0, globals=0xc6adc, locals=0xb5ce0) at Python/ceval.c:341 > #47 0x322f4 in PyImport_ExecCodeModuleEx (name=0xffbff170 "MySQLdb", co=0xc8130, > pathname=0xffbfe2a0 "/usr/local/lib/python2.1/site-packages/MySQLdb/__init__.pyc") at Python/import.c:490 > #48 0x328d8 in load_source_module (name=0xffbff170 "MySQLdb", > pathname=0xffbfe2a0 "/usr/local/lib/python2.1/site-packages/MySQLdb/__init__.pyc", fp=0xc8130) > at Python/import.c:754 > #49 0x33184 in load_module (name=0xffbff170 "MySQLdb", fp=0xb4008, > buf=0xffbfe790 "/usr/local/lib/python2.1/site-packages/MySQLdb/__init__.py", type=1) > at Python/import.c:1301 > #50 0x32ae8 in load_package (name=0xffbff170 "MySQLdb", pathname=0xc6a68 "") at Python/import.c:811 > #51 0x331f0 in load_module (name=0xffbff170 "MySQLdb", fp=0x0, > buf=0xffbfec80 "/usr/local/lib/python2.1/site-packages/MySQLdb", type=5) at Python/import.c:1324 > #52 0x33fe8 in import_submodule (mod=0xa6cd8, subname=0xffbff170 "MySQLdb", fullname=0xffbff170 "MySQLdb") > at Python/import.c:1829 > #53 0x33b68 in load_next (mod=0xa6cd8, altmod=0xa6cd8, p_name=0xffbff170, buf=0xffbff170 "MySQLdb", > p_buflen=0xffbff16c) at Python/import.c:1685 > #54 0x33738 in import_module_ex (name=0x0, globals=0xa6cd8, locals=0xb6fc4, fromlist=0xa6cd8) > at Python/import.c:1536 > #55 0x33910 in PyImport_ImportModuleEx (name=0xd1f14 "MySQLdb", globals=0xb6fc4, locals=0xb6fc4, > fromlist=0xa6cd8) at Python/import.c:1577 > #56 0x77254 in builtin___import__ (self=0x0, args=0xd1f14) at Python/bltinmodule.c:31 > #57 0x22858 in call_cfunction (func=0xb5ce0, arg=0xba9e4, kw=0x0) at Python/ceval.c:2854 > #58 0x227bc in call_object (func=0xb5ce0, arg=0xba9e4, kw=0x0) at Python/ceval.c:2807 > #59 0x22548 in PyEval_CallObjectWithKeywords (func=0xb5ce0, arg=0xba9e4, kw=0x0) at Python/ceval.c:2740 > #60 0x20124 in eval_code2 (co=0xc0f40, globals=0x0, locals=0xb6fc4, args=0xb9ec0, argcount=0, kws=0xba9e4, > kwcount=0, defs=0x0, defcount=0, closure=0xb5ce0) at Python/ceval.c:1820 > #61 0x1da3c in PyEval_EvalCode (co=0x0, globals=0xa6cd8, locals=0xb5ce0) at Python/ceval.c:341 > #62 0x3ab0c in run_node (n=0xb51f0, filename=0xb6fc4 "", globals=0xb6fc4, locals=0xb6fc4, flags=0xb6fc4) > at Python/pythonrun.c:1045 > #63 0x39908 in PyRun_InteractiveOneFlags (fp=0xffffffff, filename=0x7d4f8 "", flags=0xffbffb3c) > at Python/pythonrun.c:570 > #64 0x39704 in PyRun_InteractiveLoopFlags (fp=0xb3fd8, filename=0x7d4f8 "", flags=0xffbffb3c) > at Python/pythonrun.c:510 > #65 0x3966c in PyRun_AnyFileExFlags (fp=0xb3fd8, filename=0x7d4f8 "", closeit=0, flags=0xffbffb3c) > at Python/pythonrun.c:473 > #66 0x19b90 in Py_Main (argc=1, argv=0xffbffbb4) at Modules/main.c:320 > > -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 06 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From ayc8NOSPAM at cornell.edu Sun Aug 3 04:11:47 2003 From: ayc8NOSPAM at cornell.edu (Andy C) Date: Sun, 03 Aug 2003 08:11:47 GMT Subject: Dealing with paths (Unix question) References: Message-ID: <7t3Xa.87$hD6.7945404@newssvr13.news.prodigy.com> Or os.walk, that might be easier for a beginner. I think that's new though in 2.3. "Tyler Eaves" wrote in message news:pan.2003.08.03.04.59.15.104071 at scalegen.com... > On Sun, 03 Aug 2003 03:04:13 +0000, paul wrote: > > > hey there all! > > i'm writing some little programs, and i'd like to know about how to deal > > with directories on unix. i've read up on this, but the docs don't really > > mention much on it. do i use the pickle module, or something? > > > > Look at os.path.walk > > > -- > Visit my blog - http://blog.scalegen.com > Music, Programming, and More. > From creedy at mitretek.org Fri Aug 8 10:26:35 2003 From: creedy at mitretek.org (Chris Reedy) Date: Fri, 08 Aug 2003 10:26:35 -0400 Subject: random changes In-Reply-To: References: Message-ID: <3f33b345$1_6@corp.newsgroups.com> Tim Peters wrote: > [dan] > >>I did try random.WichmannHill, which gives completely different data >>to either the new or the old version. > > > I expect you're confused about something, then, but there aren't enough > details to guess what. > > Here's a run under 2.1.3: > > >>>>import random >>>>random.seed(123456789) >>>>print repr(random.random()) > > 0.095213622685816457 > > > Here under 2.2.3: > > >>>>import random >>>>random.seed(123456789) >>>>print repr(random.random()) > > 0.095213622685816457 > > > Here under 2.3: > > >>>>import random >>>>random = random.WichmannHill() >>>>random.seed(123456789) >>>>print repr(random.random()) > > 0.095213622685816457 > > > > Same thing -- results should be (and are) bit-for-bit identical. Now show > us what you do that leads to the "completely different data" conclusion. > > Here are some interesting numbers: >>> def printstats(rng, N=20000): # Cribbed from random._test_generator import math sum = 0 sumsq = 0 for i in range(N): x = rng() sum += x sumsq += x*x avg = sum/N stddev = math.sqrt(sumsq/N - avg*avg) print repr(avg), repr(stddev) Under 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)]: >>> rng = random.Random() >>> rng.seed(123456789) >>> printstats(rng.random) 0.50177345778280169 0.28856727700571438 >>> rng.seed(123456789) >>> printstats(lambda : rng.normalvariate(0.0, 1.0)) 0.0021149783637115457 0.99131361156374964 Under 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)]: >>> rng = random.WichmannHill() >>> rng.seed(123456789) >>> printstats(rng.random) 0.50177345778280169 0.28856727700571438 >>> rng.seed(123456789) >>> printstats(lambda : rng.normalvariate(0.0, 1.0)) 0.0064296479176113733 1.0050714625654731 It appears that the numbers for random.random() are identical, however, the numbers for normalvariate (and also lognormvariate, betavariate, weibullvariate, and paretovariate) are different. I have no explanation for why. Chris -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! -----== Over 80,000 Newsgroups - 16 Different Servers! =----- From logiplex at qwest.net Tue Aug 12 18:21:48 2003 From: logiplex at qwest.net (Cliff Wells) Date: Tue, 12 Aug 2003 15:21:48 -0700 Subject: Python vs. C# In-Reply-To: References: <2259b0e2.0308100616.55b651ca@posting.google.com> <3f36af20@shknews01> Message-ID: <1060726907.4769.75.camel@software1.logiplex.internal> On Tue, 2003-08-12 at 11:52, Brandon J. Van Every wrote: > Cliff Wells wrote: > > On Sun, 2003-08-10 at 13:55, Brandon J. Van Every wrote: > > > >> Java and C# are the obvious languages that are not going away. > >> Python? What industrial entity is going to champion Python? > > > > Perhaps people who think for themselves and simply choose the best > > tool > > don't need shiny brochures and a pat on the back from a salesman to > > feel they've made a good choice. > > If I had coffee, I'd be the one choking on it. Would it stop you from typing if you were? > > You're starting to sound like your > > research was done on page 3 of PC Magazine. > > And how many corporate managers do you think do exactly that? What difference does that make to me (or you)? If a corporate manager tells you to develop your 3D renderer in Python, does that make it a good choice? Would you go ahead and do it, knowing that failure is practically guaranteed, or would you instead try to change their mind based upon the actual merits of the respective tools and maybe try to find another job if you couldn't? > > If you think it takes major marketing to push a language, let me ask > > you > > this: what are you doing on this list? No, really. You couldn't > > possibly have discovered Python without a major corporate advertising > > campaign, so how did you find your way here? It seems almost... > > contradictory. > > Python is known in the game industry. There's a steady trickle of > programmers who extol its virtues. Unlike certain advocates in c.l.p, they > give both sides of the story. And this would mean a lot more to me than some corporation telling me their latest product will solve all my programming problems on every platform. I would think the Java hype would have taught everyone a lesson about this. I'm not sure what the other side of the story is, in this case. Obviously Python is not well-suited for all problems. It's probably better suited than C# for most things. If I were going to use C#, I'd use C instead. To me, C# combines all the faults of an interpreted language with all the faults of a compiled language. There is always a balance to be made between sacrificing one feature to gain others. Python sacrifices speed for flexibility, ease of use and true cross-platform functionality. C sacrifices those things for speed and being close to the metal. If Python were weaker in one of those areas, then the tradeoff might not be worth it. C# is the biblical lukewarm spew. It's neither as fast as C nor as flexible as Python. > A GDC 2002 speaker will not irresponsibly > sell you on merits, without commenting on integration issues with C++ and > the debugger environment. Humongous Entertainment, for instance, "solved" > problems of this sort by writing an open source debugger. Why is "solved" in quotes? Isn't this the nature of open source development? If something you need doesn't exist, you write it. What's the problem? > Also, the > companies using Python seem to be writing 2D adventure games (low > performance app) and scripts for Massively Multiplayer Online Games (stuff > is gonna get scripted in something). Not 3D engines. So you would recommend C# or Perl instead? > In my case, I thought I needed a scripting language for user AI extensions > in my game. I had absolutely no interest in inventing a scripting language, > so I surveyed all available scripting languages for their merits and > demerits. Python emerged as the one with the best features, the simplest > syntax, and most importantly the best community support. The downside > appeared to be performance. But overall, it looked like the best fit to the > problem. Then what's the problem? > As it turned out, the problem went away. Looking closer and closer at the > AI problems, I had serious reservations that any casual hobby programmer > could handle low level AI problems without serious brainpower and hard work. Again I'm stunned > There was no point in providing the service if few to no people would use it > in practice. I decided that I should do the low level AI stuff in whatever > langauge was appropriate, probably C++. Once I had a more stable, high > level API for what I was doing, then worry about user AI. So now I had no > immediate reason to use Python. Seems fair. > Looking for reasons why I might still use Python, I examined 2D + 3D GUI > problems. Perhaps this is the crux of the problem. Looking for a problem so you can use a particular tool. Doesn't that seems a bit, um... backwards to you? > Could I get cross-platform widgets that could be skinned for game > development and would run on any platform? Would they integrate well with > my 3D code? I found at least one project along those lines, but as a > sideshow project without a lot of industrial testing, I wasn't willing to > make a big learning curve committment just over that. It didn't look "prime > time" and the whole point of switching to Python is to save work, not create > it. So I put that idea on the backburner. > > More recently I've realized what a chore C++ is, and how it limits my > development. I hate the look of STL, I"ve always avoided it, and I could > really use lists, collections, dictionaries, etc. for some problems. I've > never done much memory management, but even the tiny amount that I have done > tends to be tedious. So recently I started considering the advantages of > higher level languages. As do most people, at one point or another. > Available were: Python, Java, C#. They can all do the "higher level > language" job, but C# currently has slam dunk advantages on the Windows > platform. It's pretty much a no-brainer for a Windows developer who's been > doing lotsa C++ but is tired of it. Sort of like Visual Basic was a few years ago. I'll leave it open to speculation whether C# has "slam-dunk" advantages anywhere, but you've raised another question: Why, two paragraphs ago, were you looking for "cross-platform" tools, and now it's all about Windows? Are you even sure what your goal is? Do you want cross-platform? Then C# probably won't be the answer. Yes, I'm aware of Mono. I'm also aware of how MS strives to create incompatibilities in cross-platform tools. That makes it a probable slam-dunk right in the toilet as far as I'm concerned. > >> But I am not seeing Python's overwhelming utility compared to other > >> languages. > > > > Then perhaps you should spend less time trolling the newsgroups and > > more time programming. > > Perhaps you should spend more time programming on Windows. And perhaps you should procreate with a lawnmower ;) You see, this is probably what differentiates us right here. I enjoy programming and don't see any reason to torture myself with subpar tools. Besides, I don't see what programming on Windows has to do with Python's utility as a programming language. If you're referring to the ability to interact with the Win32 API then there is Mark Hammond's win32all package which seems to do the job quite well. > > Perl isn't a bad language? Perl is a terrific tool but a terrible > > language. I could go on, but I think your own statements sum up your > > abilities to make any sort of qualitative judgement regarding > > programming languages. No wonder you chose C++. > > Please notice my e-mail address as to what kinds of tasks have been > historically most important to me. If you don't see why C++ is a better fit > to low-level 3D graphics problems than Python, well.... Again, I'm stunned. A static compiled language is better than a dynamic interpreted one for CPU-intensive tasks? Anyway, that was more of a poke at your apparent fondness for screwed-up languages. The reason you've raised my ire is that you clearly aren't too familiar with either Python or C# yet seem to want to argue about the merits of both with people who are clearly more knowledgeable about them than you are. That to me is just plain silly. If you want to know which tool is best for the job, it's fine to ask somebody who knows. If you don't believe them, try it yourself. But please don't *argue* with them. You also made some clearly speculative statements yet forwarded them as if they were foregone conclusions (we should all just throw in our hats and do C# on Windows, apparently). People like you were telling me that Linux was a "hacker's OS" in '94 and would never make it in production environments. I obviously should have listened . Regards, -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 (800) 735-0555 From gsmith-mysterymeat at mysterymeat-transmeta.com Wed Aug 13 19:23:34 2003 From: gsmith-mysterymeat at mysterymeat-transmeta.com (Gregory P. Smith) Date: Wed, 13 Aug 2003 16:23:34 -0700 Subject: bsddb.btopen() In-Reply-To: <3f3a1387$0$9624$7a628cd7@news.club-internet.fr> References: <3f3a1387$0$9624$7a628cd7@news.club-internet.fr> Message-ID: <3F3AC876.8040300@mysterymeat-transmeta.com> Anthony McDonald wrote: > PythonWin 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] on > win32. > Portions Copyright 1994-2001 Mark Hammond (mhammond at skippinet.com.au) - see > 'Help/About PythonWin' for further copyright information. > >>>>import os >>>>import bsddb >>>>os.chdir("c:/test") >>>>my_data = bsddb.btopen("testing", 'c') >>>>for i in range(10): > > ... if i == 5: > ... pass > ... else: > ... my_data['%d'%i] = '%d'% (i*i) > ... > >>>>my_data.keys() > > ['0', '1', '2', '3', '4', '6', '7', '8', '9'] > >>>>my_data.sync() > > > Now heres where my problem is. > > The documentation explicitly states that a btopen database when asked to > locate a key that doesn't exist in the dataset, will return the next sorted > key from the dataset. > > So my_data.set_location('5') should return as if I'd called > my_data.set_location('6') > >>>>my_data.set_location('5') > > Traceback (most recent call last): > File "", line 1, in ? > File "C:\Python23\lib\bsddb\__init__.py", line 117, in set_location > return self.dbc.set(key) > DBNotFoundError: (-30991, 'DB_NOTFOUND: No matching key/data pair found') > > Okay maybe it has positioned the cursor, but is just raising the exception > to politely tell me that I'm not pointing at the key I asked for. So > my_data.previous() will return the key/data pair for key "4". > >>>>my_data.previous() > > ('9', '81') > > Okay its pointing at the end of the database. Erm thats not as advertised. > > Okay whats broken? Is the documentation wrong? Is my version of Python > wrong?, or do I need to drink some more coffee? This looks like a break in compatibility between Python <=2.2.x bsddb and the new bsddb (pybsddb/bsddb3) included in Python 2.3. I've filed a bugreport on sourceforge to track fixing this. http://sourceforge.net/tracker/?func=detail&aid=788421&group_id=5470&atid=105470 I don't see an immediately obvious work around while using the old simplistic bsddb interface. -- Gregory P. Smith [remove mystery meat from my address when replying] From owen at nojunk.invalid Wed Aug 13 12:49:08 2003 From: owen at nojunk.invalid (Russell E. Owen) Date: Wed, 13 Aug 2003 09:49:08 -0700 Subject: Py2.3: Feedback on Sets References: Message-ID: In article , garabik-news-2002-02 at kassiopeia.juls.savba.sk (Radovan Garabik) wrote: >Raymond Hettinger wrote: >> * Is the support for sets of sets necessary for your work >> and, if so, then is the implementation sufficiently >> powerful? > >So far my code used dictionaries with values set to None, >I expect that I will use sets soon, it will be more logical >and the code more readable. Same here. I don't rely on sets heavily (I do have a few implemented as dictionaries with value=None) and am not yet ready to make my users upgrade to Python 2.3. I suspect the upgrade issue will significantly slow the incorporation of sets and the other new modules, but that over time they're likely to become quite popular. I am certainly looking forward to using sets and csv. I think it'd speed the adoption of new modules if they were explicitly written to be compatible with one previous generation of Python (and documented as such) so users could manually include them with their code until the current generation of Python had a bit more time to be adopted. I'm not saying this should be a rule, only suggesting it as a useful goal. Presumably it'd be easy with some modules and not worth the work in some cases. -- Russell From newsgroups at jhrothjr.com Fri Aug 29 12:16:08 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Fri, 29 Aug 2003 12:16:08 -0400 Subject: Are lists at least as efficient as dictionaries? References: <781faf41.0308281604.51e48f45@posting.google.com> Message-ID: "Narendra C. Tulpule" wrote in message news:781faf41.0308281604.51e48f45 at posting.google.com... > Hi, > if you know the Python internals, here is a newbie question for you. > If I have a list with 100 elements, each element being a long string, > is it more efficient to maintain it as a dictionary (with a key = a > string from the list and value = None) for the purpose of insertion > and removal? Lists are more efficient for lookup by index, dictionaries are more efficient for insertion (except at the end, where Python maintains extra slots for just this case), removal and lookup by key. Lists are also much more efficient for sequential traversal. John Roth From rganesan at myrealbox.com Mon Aug 18 06:10:22 2003 From: rganesan at myrealbox.com (Ganesan R) Date: Mon, 18 Aug 2003 15:40:22 +0530 Subject: Expirience in using expect (PyExpect) functionality References: Message-ID: >>>>> "Raphael" == Raphael Bossek writes: > Hi, > before starting with PyExpect I would like to know if there is an > alternative because PyExpect seems not to be maintained anymore ? > Is someone using PyExpect successfully here ? I don't know about PyExpect, however I regularly use pexpect (http://pexpect.sourceforge.net). It's a pure python module with a clean interface and works beautifully. Ganesan -- Ganesan R (rganesan at debian dot org) | http://www.debian.org/~rganesan/ 1024D/5D8C12EA, fingerprint F361 84F1 8D82 32E7 1832 6798 15E0 02BA 5D8C 12EA From drlinux at columbus.rr.com Wed Aug 13 17:07:39 2003 From: drlinux at columbus.rr.com (Dave Reed) Date: Wed, 13 Aug 2003 17:07:39 -0400 Subject: Template module problem In-Reply-To: References: Message-ID: <200308131707.39139.drlinux@columbus.rr.com> On Wednesday 13 August 2003 16:04, Gerhard W. Gruber wrote: > Several years ago I wrote a module for python to support templates. I > submitted this to the python resource site and it was accessible through this > link. Unfortunately this points to my old home page which is no longer. Since > I forgot about this I havent updated it and now the webspace has been cleared > out by the provider. If anybody downloaded this could you please send me a > copy? I don't find the file anymore. :( > > Thanks! > > http://py.vaults.ca/apyllo.py/812237977.281773030.7554750.60218011 > > -- > Gerhard Gruber > > F?r jedes menschliche Problem gibt es immer eine einfache L?sung: > Klar, einleuchtend und falsch. (Henry Louis Mencken) > -- > > > Check out web.archive.org, specifically: http://web.archive.org/web/20020209192824/http://members.aon.at/sparhawk/files/template.py Dave From jepler at unpythonic.net Tue Aug 26 18:05:22 2003 From: jepler at unpythonic.net (Jeff Epler) Date: Tue, 26 Aug 2003 17:05:22 -0500 Subject: Generator comprehensions -- patch for compiler module In-Reply-To: References: <20030826213316.GA7285@unpythonic.net> Message-ID: <20030826220522.GA7098@unpythonic.net> The [rejected] PEP is http://python.org/peps/pep-0289.html It was written by Raymond Hettinger, not by me. As a statement, [yield None for x in []] is a pretty dumb one. It will create a generator object and then consume zero of the zero items the generator would produce. It was an example of the simplest generator comprehension I could think of. Some more useful generator comprehensions might be cartesian_prod = [yield (x,y) for x in l1 for y in l2] or replacing some functions from itertools: primes = imap(lambda x: x*x, itertools.ifilter(isprime, zstar())) becomes primes = [yield x*x for x in zstar() if isprime(x)] [zstar() being an iterator returning the natural numbers beginning at 0, after the mathematical notation Z* for the set {0, 1, 2, ...}] If listcomps are better than map() and filter(), then surely a gencomp is better than imap() and ifilter()! The PEP doesn't really list any good use-cases, and I don't have them either. I simply wanted to give a response to one portion of the BDFL's rejection: I expect it will take a lot of work to hack it into the code generator: it has to create a separate code object in order to be a generator. List comprehensions are inlined, so I expect that the generator comprehension code generator can't share much with the list comprehension code generator. My "solution" to the problem does indeed share a fair amount of code with the existing listcomp code (and more can be shared if you don't mind introducing 'if gencomp: else:' a little more). I suspect it took me as little as 4 hours (less than that, except I stared at two fairly stupid bugs for longer than I should have). If the time required for the C implementation is wildly higher than that, it may be a sign that Python should ditch the compiler-in-C as soon as there's a good way to do so. I suppose I'd also like to disagree with Guido on another point: And this for something that's not that common and easily done by writing a 2-line helper function. IOW the ROI isn't high enough. If listcomps are better than map() and filter(), then surely a gencomp is better than imap() and ifilter()! And similarly, you don't *need* a listcomp, because it's equivalent to a 2-line helper loop. Jeff From me at privacy.net Tue Aug 26 00:32:49 2003 From: me at privacy.net (Greg Ewing) Date: Tue, 26 Aug 2003 16:32:49 +1200 Subject: Modifying the {} and [] tokens References: <04cekv0s6ghjtuhl5j2gph7ltobdb5rsam@4ax.com> <62rekv0k4ucgrh46lkp27klq13pq8ppp5p@4ax.com> <1h3fkvg8mkeq69a8hriojugqfcp75hafjj@4ax.com> Message-ID: <3F4AE2F1.5020801@privacy.net> Terry Reedy wrote: > If your particular wish should remain > ungranted a year from now, welcome to the club. Careful, or you'll have him wishing his wish would not be granted, and crashing the universe. :-) Greg From roy at panix.com Sat Aug 23 12:40:05 2003 From: roy at panix.com (Roy Smith) Date: Sat, 23 Aug 2003 12:40:05 -0400 Subject: Modifying the {} and [] tokens References: <04cekv0s6ghjtuhl5j2gph7ltobdb5rsam@4ax.com> <62rekv0k4ucgrh46lkp27klq13pq8ppp5p@4ax.com> <1h3fkvg8mkeq69a8hriojugqfcp75hafjj@4ax.com> Message-ID: Geoff Howland wrote: > {} + {} is not allowed. What would it mean? What would you do if you had two dicts: d1 = {'a':1, 'b':2} d2 = {'a':42} what would the value of (d1+d2)['a'] be? From jdhunter at ace.bsd.uchicago.edu Sun Aug 3 14:45:26 2003 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Sun, 03 Aug 2003 13:45:26 -0500 Subject: String Replacement In-Reply-To: (Tyler Eaves's message of "Fri, 01 Aug 2003 21:42:06 -0400") References: <7b454334.0308011400.266438f9@posting.google.com> <7b454334.0308011726.15d12be9@posting.google.com> Message-ID: >>>>> "Tyler" == Tyler Eaves writes: Tyler> str = str.replace("\n", "
") 'str' is a built in function >>> str(1) '1' And you will be overriding this functionality if you name something 'str'. Perfectly legal, but might lead to some hard to diagnose bugs in the future. John Hunter From dialtone#NOSPAM#.despammed at aruba.it Tue Aug 26 18:30:29 2003 From: dialtone#NOSPAM#.despammed at aruba.it (Dialtone) Date: Wed, 27 Aug 2003 00:30:29 +0200 Subject: Best way to write a file n-bytes long References: <8d3e714e.0308261404.12045d96@posting.google.com> Message-ID: <87d6esxda2.fsf@vercingetorix.caesar.org> cappy2112 at yahoo.com (Tony C) writes: > Sure, I could create a string that is n Megabytes long, and pass it to > write, but it seems as though there should be a better way ??? > String manipulation is typically considered slow. > > st="X" * 1048576 > fh=open("junk","wb") > fh.write(st) > fh.close() For little files (less than 2 or 3 Mb I think) your code is the fastest I can think of. But growing There is a new version which is a lot faster: In [14]: def p3 (a): ....: tmp = time.time() ....: str = 'X'*1024 ....: fh = file('junk','wb') ....: for i in xrange(a): ....: fh.write(str) ....: print time.time()-tmp ....: In [14]: def p4 (a): ....: tmp = time.time() ....: str = 'X'*(1024*a) #Parenthesis are fundamental here ....: fh = file('junk','wb') ....: fh.write(str) ....: fh.close() ....: print time.time()-tmp ....: In [15]: p3(10240) # 10Mb file 0.478311061859 In [16]: p4(10240) 0.625810027122 And this is only slightly faster, If we go up a lil bit more (100Mb) we get to: In [17]: p3(100000) # This is a 100 Mb file, so not really little # and performance is not that bad, 25Mb/s 4.00167894363 In [18]: p4(100000) 8.85632002354 Otherwise if we stay down (1K): In [22]: p3(1) 0.00810098648071 In [23]: p4(1) 0.000607967376709 HTH -- Valentino Volonghi, Regia SpA, Milan Linux User #310274, Debian Sid Proud User From pobrien at orbtech.com Thu Aug 28 17:37:51 2003 From: pobrien at orbtech.com (Patrick K. O'Brien) Date: 28 Aug 2003 16:37:51 -0500 Subject: Object Database (ODBMS) for Python Message-ID: I'm working on an ODBMS written in Python, for Python, and was wondering if anyone was interested. In particular, I'd like to know what features would be useful, and what types of use cases people would have for a simple, but feature-rich object database. The system that I'm developing is PyPerSyst, which began as a simple persistence mechanism, but is now becoming a complete ODBMS. Some details are available here: http://www.orbtech.com/wiki/PyPerSyst The code is available in CVS on SF: http://sourceforge.net/projects/pypersyst/ As you'll see when you look at it, my goal is to provide many of the features you would find in relational databases (declarative alternate keys, referential integrity, etc.) without any of the impedence mismatch associated with mapping between objects and relational tables. And since this is Python, I've got several features I've never seen in any database of any kind (like built-in, automatic, self-maintained, bi-directional associations for all references). So, what else would you like to have in a pure-Python ODBMS? -- Patrick K. O'Brien Orbtech http://www.orbtech.com/web/pobrien ----------------------------------------------- "Your source for Python programming expertise." ----------------------------------------------- From edwin at mindless.com Mon Aug 4 03:07:29 2003 From: edwin at mindless.com (edwinek) Date: 4 Aug 2003 00:07:29 -0700 Subject: Problems decoding and writing mail attachment Message-ID: <2afb3281.0308032307.2e0226df@posting.google.com> I've written a script which I use to save attached binary files from e-mails to disk. The core is simply: decodedfile = bas64.decodestring(attachment) fle = open('image.jpg','wb') fle.write(decodedfile) fle.close However, the files written to disk are regularly incomplete, i.e. jpg's having a grey bar at the bottom, gif's don't even display, pdf's give errors. What am I doing wrong here? Thanks, Edwin From aahz at pythoncraft.com Mon Aug 11 18:46:36 2003 From: aahz at pythoncraft.com (Aahz) Date: 11 Aug 2003 18:46:36 -0400 Subject: IO timeout in threaded application References: Message-ID: In article , Gordon Messmer wrote: > >What's the easiest way to accomplish that? Should I just subclass >smtplib's SMTP class and override the "connect" function with one that >creates a socket with a timeout? If you don't mind having the same timeout for every socket, use either timeoutsocket.py (or the new functionality in Python 2.3) to set a global timeout. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From aleax at aleax.it Mon Aug 4 03:54:28 2003 From: aleax at aleax.it (Alex Martelli) Date: Mon, 04 Aug 2003 07:54:28 GMT Subject: command -- It works , on linux References: Message-ID: Nicola Mingotti wrote: > On Sun, 03 Aug 2003 17:35:31 +0200, Nicola Mingotti wrote: > >> Hello , >> >>> ... John and Martin spoke of termcap and readline ... there it was :) > > ... I hadn't installed two C libraries that were needed : > 'readline' and 'termcap' . After installing them i re-configured/compiled > python and now commands history works fine . > But under windows , where i have only the binary version > at hands , the problem remains ... Have you tried installing Gonnerman's "Alternative Readline", http://newcenturycomputers.net/projects/readline.html ? I have found it extremely useful to gain the gist of readline's functionality on Windows installatons of Python. Alex From jjl at pobox.com Fri Aug 22 10:47:59 2003 From: jjl at pobox.com (John J. Lee) Date: 22 Aug 2003 15:47:59 +0100 Subject: Deficiency in urllib/socket for https? References: <6vaakvorefvifnt3fk59r6tcj16c59rrfi@4ax.com> Message-ID: <87r83dzr34.fsf@pobox.com> Gary Feldman writes: > I think I've found a deficiency in the design of urllib related to https. > > In order to complete an https connection, it appears that URLOpener and > hence FancyURLOpener require the key and cert files. Or at least, it's not > clear from the description of socket.ssl what it does if they're omitted. Nor from urllib -- see below. In fact, it seems that verification is just skipped if they're not there. > However, urlopen has no way to specify such things. Nor should it - for > typical uses, a person simply trying to retrieve data from an ssl site > really doesn't want to know or care about keys and certificate directories. > One just wants to provide an https url and have it work. Ideally, there > should be defaults for the certificate files. Hmm, looking at both urllib and urllib2, I see urllib2 doesn't use any key or certificate files at all. So, two points: this is a deficiency in urllib2 that should be fixed, and, if you're not bothered about key verification, I'd guess just not providing key / cert files will work. Hmm, urllib documentation seems wrong here: Additional keyword parameters, collected in x509, are used for authentication with the https: scheme. The keywords key_file and cert_file are supported; both are needed to actually retrieve a resource at an https: URL. The fact that https works in urllib2 (which does not provide key / cert files) seems to demonstrate that they're *not* required, and that verification is skipped if they're not supplied. If you *are* bothered about verification, use the x509 arg to FancyURLOpener (which is documented, see above). The urlopen function is just a convenience -- just cut-n-paste the trivial code from urllib.py and adapt it to your needs if you need something more complicated. > This implies that somewhere in the function hierarchy, I suspect in > socket.ssl, there needs to be some clever defaults. I don't know if they > folks maintaining the Python distribution really want to be in the business > of maintaining key and certificate directories (probably not), but there at > least ought to be a way to specify default directories (oh, no, another > environment variable?). Thinking idealistically, it would be great if it > could share the default certs on the system (i.e. on UNIX, find a Netscape > or Mozilla install directory and use those, and on MS Windows, do whatever > it takes to use the Windows mechanism). That sounds great if you have the time to write the code. Nobody else is likely to. John From jepler at unpythonic.net Wed Aug 27 11:15:46 2003 From: jepler at unpythonic.net (Jeff Epler) Date: Wed, 27 Aug 2003 10:15:46 -0500 Subject: Proposal: Magic Constants In-Reply-To: <000a01c36c9b$3ef54d20$1f00000a@house> References: <000a01c36c9b$3ef54d20$1f00000a@house> Message-ID: <20030827151545.GU32191@unpythonic.net> 1.05D vs D("1.05") or D(1.05,2) is a 4-character difference. In the case of rationals, 1R/15 vs R(1,15) or R*1/15 is also a tiny difference. And "I have lots of literals in my code" is not an argument I buy. I counted tokens in 1299 python files in /usr/lib/python2.2*, and 59865 out of 1838995 of them are numeric literals. That's only 3% of tokens. By contrast, there are 168520 newlines, 61591 mentions of "self", 31053 comments, 20335 def statements, and 3673 uses of the name "i". (The encodings/ directory is the most numeric-literal-heavy portion of the code, with 11134 numbers in 47423 tokens. But these are clearly not candidates for conversion to magic literals) Even if all these literals were converted to a notation that added 4 characters per literal, the increase would amount to 234k out of 9892k, or 2.4%. In a large system, how do you manage the suffixes? Third-party module A and B may both provide an "R"-suffix rational, implemented incompatibly. Do you want to add functionality to lists/dicts/tuples? ([1,2,3]S for Set(1,2,3)?) If not, why do you think that numeric literals are more important than lists/dicts/tuples? Currently, u'' and U'' are identical, as are 0L and 0l. Will 1R and 1r be equivalent? Type-suffixes are unfortunate where they exist in the language, and they're being eliminated today in the case of 'l', and I think there's a dream to eliminate the 'u' type-prefix for strings as well. I view the 'r' string prefix as a bad idea, too, but unfortunately I don't see it going away. Well, I can dream... Jeff * there are multiple third-party packages installed here From jacek.generowicz at cern.ch Thu Aug 21 08:59:17 2003 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 21 Aug 2003 14:59:17 +0200 Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> <6dj2kv8ugkieehs7guh786cl40o5lj6mcs@4ax.com> Message-ID: "Andrew Dalke" writes: > As a consultant, I don't have the luxury of staying inside a singular > code base. By your logic, I would need to learn each different > high level abstraction done at my clients' sites. The alternative is to understand (and subsequently recognize) the chunks of source code implementing a given patten for which no abstraction was provided (often implemented slightly differently in different parts of the code, sometimes with bugs), each time that it occurs. I'd rather use multimethods that implement the visitor pattern. I'd rather look at multimethods, than at code infested with implementations of the visitor pattern. (The above comments are _not_ about the visitor pattern per se.) > The inference is that programming language abstractions should not > be more attractive than sex. Why ever not? Don't you want to put the joy back into programming :-) > Functions and modules and objects, based on experience, promote > code sharing. Macros, with their implicit encouragement of domain > specific dialect creation, do not. I don't believe you can reasonably draw a rigid and well-defined boundary between functions, modules and objects on one side, and macros on the other. They all offer means of abstraction. All are open to abuse. All can be put to good use. In all four cases, I'd rather have the opportunity to create abstractions, rather than not. I find your suggestion that macros are in some way more "domain specific" than modules, or objects or functions, bogus. > A language which allows very smart people the flexibility to > customize the language, means there will be many different flavors, > which don't all taste well together. > A few years ago I tested out a Lisp library. It didn't work > on the Lisp system I had handy, because the package system > was different. There was a comment in the code which said > "change this if you are using XYZ Lisp", which I did, but that > that's a barrier to use if I ever saw one. You are confusing the issues of - extensibility, - standard non conformance, - not starting from a common base, - languages defined my their (single) implementation. A few days ago I tested out a C++ library. It didn't work on the C++ system I had handy because the STL implementation was different/template support was different. etc. etc. A few days ago I tested out a Python library. It didn't work on the implementation I had handy because it was Jython. > 4) a small change in a language to better fit my needs has > subtle and far-reaching consequences down the line. Instead, > when I do need a language variation, I write a new one > designed for that domain, and not tweak Python. So, what you are saying is that faced with the alternatives of a) Tweaking an existing, feature rich, mature, proven language, to move it "closer" to your domain. b) Implementing a new language from scratch, for use in a single domain you would choose the latter? If so, you are choosing the path which pretty much guarantees that your software will take much longer to write, and that it will be a lot buggier. It's an extreme form of Greenspunning. How do you reconcile > when I do need a language variation, I write a new one designed for > that domain, and not tweak Python. with > Functions and modules and objects, based on experience, promote > code sharing. Macros, with their implicit encouragement of domain > specific dialect creation, do not. ? You criticize macros for not encouraging code sharing (they do, by encouraging you to share the (vast) underlying language while reaching out towards a specific domain), while your preferred solution seems to be the ultimate code non-sharing, by throwing away the underlying language, and re-doing it. From troy at gci.net Mon Aug 4 18:01:20 2003 From: troy at gci.net (Troy Melhase) Date: Mon, 04 Aug 2003 14:01:20 -0800 Subject: MVC in Python References: Message-ID: MK wrote: > How to achieve this feat in Python? Which techniques > do you guys use? Hi MK: If memory serves (and it rarely does), you have two options. The first would be custom wx events, and the second would be the evtmgr module in the wxPython.lib package. Both approaches have examples in the wx demo application. The evtmgr demo is absolutely dazzling in its simplicity, and I would suggest you start your search there. Good luck, troy From cnetzer at sonic.net Wed Aug 13 03:40:41 2003 From: cnetzer at sonic.net (Chad Netzer) Date: Wed, 13 Aug 2003 00:40:41 -0700 Subject: two quick questions In-Reply-To: References: Message-ID: <1060760441.18368.117.camel@adsl-209.204.179.133.sonic.net> On Tue, 2003-08-12 at 23:06, Elaine Jackson wrote: > 1) Does Python have passing-by-reference? Yes. But the references you are passing are references to objects (not memory locations), and objects themselves can be changeable (mutable) or not. When you pass objects, copies are not automatically made (so assignment is very speedy). I prefer to say that these concepts should be put aside when thinking about python. Python has names that refer to objects. Objects are created, and can be assigned one or more names (using assignment). Some objects can mutate (like objects made by user defined classes), some cannot (like strings or integers). When you supply function arguments, copies of the object are not automatically made. If you pass a mutable object, the callee has a name for that (actual) object, and can mutate it. If you pass an immutable object, they cannot. When you use assignment, a copy of the object is not made. It simply gets another name that refers to it. Globals can confuse the issue, since they allow you to change the names used in the global scope (ie. they can allow your function to modify a non-local namespace, rather than just the objects passed in to the local namespace. Examples: 1) Without using globals: a = 1 # Create the immutable 1 integer object and name it 'a' b = [] # Create a mutable list def f( c, d ): c = 3 # Reassign name 'c' to the 3 integer object d.append( "foo" ) # modify the list that is named 'd' f( a, b ) # Copies of 'a', and 'b' are NOT made. # when you call f(), c is a, and d is b. # ie. The names in the function refer to the same # objects as the (different) names outside the function a == 1 b == ['foo'] Discussion: The f() function changed 'b' because the object itself was changeable. The a object is still 1, because the 1 object cannot be changed at all, and f() couldn't reassign a because it gets a name that refers to the object, not access to the namespace itself. 2) similar example using globals to pervert namespace a = 1 def g(): global a # This says that 'a' refers to the global 'a' name a = 2 # Since I have access to the name 'a', I can change # the object that the global 'a' refers to. g() a == 2 # After calling g, the global name 'a' was changed. The point of the globals example, was that it can be used to confuse your understanding. So ignore it for now, and think of objects as free-standing entities that can have multiple names, in multiple scopes, it is easier to understand that you are passing around access to those objects, and you can manipulate them if they are mutable. But, pass-by-value and pass-by-reference, at least as they are typically discussed in the 'C' programming world, are less applicable concepts. As you get more advanced, you will see that Python uses dictionaries to hold namespaces, and you can pass thos dictionaries (and thus the namespaces) around as well. > 2) In ordinary parlance, "deep" implies "shallow" but not conversely. In the > Python "copy" module (if I understand correctly), the implication goes the other > way. Do you find this a nuisance? Not sure what you mean. -- Chad Netzer From harry.pehkonen at hotpop.com Fri Aug 8 16:07:50 2003 From: harry.pehkonen at hotpop.com (Harry Pehkonen) Date: 8 Aug 2003 13:07:50 -0700 Subject: win32com, string array --> Type mismatch? Message-ID: <70df36e9.0308081207.550c1dc1@posting.google.com> I'm running WRQ's Reflection telnet client (win32com.client.Dispatch("Reflection2.Session")). It appears I can only do late binding. There is one method that takes a ``string array,'' and fails with: Traceback (most recent call last): File "", line 1, in ? File "Reflection.py", line 549, in goto_switch result = self.connection.WaitForStrings(waitfor_strngs) File "Reflection.py", line 399, in WaitForStrings options) File "", line 2, in WaitForStrings com_error: (-2147352571, 'Type mismatch.', None, 1) I've tried providing lists and tuples of strings, lists and tuples of unicode strings. makepy -i reports: Warning - could not load registered typelib Without the -i, it creates CLSID 0DE5A6C0-4B0D-101B-AC7B-04021C007002.py, but when I run the telnet client, COM Browser says it's F29799A0-4B0C-101B-AC7B-04021C007002 (off a bit). The 0DE...py module mentions this CLSID F29... I tried renaming and importing the 0DE...py file, but I still get the Type mismatch. In short, is there something specific I need to do in order to pass a ``string array'' from Python to a COM server when I'm (I think) stuck with late binding? Thanks! Harry. PS. Please reply to this group as I get a ton of spam. From pobrien at orbtech.com Fri Aug 29 13:38:39 2003 From: pobrien at orbtech.com (Patrick K. O'Brien) Date: 29 Aug 2003 12:38:39 -0500 Subject: Object Database (ODBMS) for Python References: <1DAECE9E8F34E04AA0E5699AF7D9FF090708D440@stpmsg00.corp.fairisaac.com> <3f4f7af6_3@corp.newsgroups.com> Message-ID: "Paul D. Fernhout" writes: > In Smalltalk, typically persistant objects may get stored and > retrieved as proxies, which is made possible by overriding the basic > storage and retrieval methods which are all exposed etc. Maybe Python > the language could do with more hooks for persistances as a PEP? I > know there are some lower level hooks for access, I'm just wondering > if they are enough for what you may want to do with PyPerSyst to make > an elegant API for persistant objects (perhaps better unique ID > support?), where you could then just go: > > import persistanceSystem import * > foo = MyClass() > PersistanceSystem_Wrap(foo) > # the following defaults to a transaction > foo.x = 10 > # this makes a two change transaction > PersistanceSystem_StartTransaction() > foo.y = 20 > foo.z = 20 > foo.info = "I am a 3D Point" > PersistanceSystem_EndTransaction() > # what happens to foo on garbage collection? It persists! > ... > # Other code in another program > import persistanceSystem import * > foo = PersistanceSystem_Query(x=10, y=20, z=30) > print foo.info # prints --> "I am a 3D Point" > > That MyClass instance called foo and the related variable changes gets > stored in an ODBMS in transactions somewhere... Then I could do the > same for the Pointrel System somehow using the same simple hooks. Adding hooks to Python itself has been discussed (look for the persistence SIG), and not gone anywhere, as far as I know. And I'm not sure it would be so good to add to the language. One reason is that it would either only be able to capture very simple transactions, or would require quite a framework to handle all the requirements for real use cases. This is one area where it would be hard to please everyone, and I think the Python language has to appeal to a broad set of uses. -- Patrick K. O'Brien Orbtech http://www.orbtech.com/web/pobrien ----------------------------------------------- "Your source for Python programming expertise." ----------------------------------------------- From vze4rx4y at verizon.net Sat Aug 16 17:50:18 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Sat, 16 Aug 2003 21:50:18 GMT Subject: Py2.3: Feedback on Sets (fwd) References: Message-ID: [Raymond] > > * Is there a compelling need for additional set methods like > > Set.powerset() and Set.isdisjoint(s) or are the current > > offerings sufficient? [David Mertz] > I confess that I have not used sets for anything beyond testing. I love > the concept, but I just haven't had the need yet (especially in > something where I want to require 2.3). > > The mention of Set.powerset() above is quite interesting to me. It > feels both exciting and dangerous :-). There would need to be compelling use cases before it would be added to the API. How about just adding a cut-and-paste recipe to the docs: from sets import Set def powerset(iterable): data = list(iterable) for i in xrange(2**len(data)): yield Set([e for j,e in enumerate(data) if i&(1<>> list(powerset('abc')) [Set([]), Set(['a']), Set(['b']), Set(['a', 'b']), Set(['c']), Set(['a', 'c']), Set(['c', 'b']), Set(['a', 'c', 'b'])] Raymond Hettinger From clifford.wells at comcast.net Fri Aug 29 05:35:49 2003 From: clifford.wells at comcast.net (Cliff Wells) Date: Fri, 29 Aug 2003 02:35:49 -0700 Subject: [GUI Design] How to achieve short comm paths between controls? In-Reply-To: <3f4d0638@news.swissonline.ch> References: <3f4d0638@news.swissonline.ch> Message-ID: <1062149749.7273.13.camel@devilbox.homelinux.net> On Wed, 2003-08-27 at 12:29, F. GEIGER wrote: [snip nice diagram] > Should I create a dict with control name/object pairs, held by the > MainFrame? This doesn't sound too bad. > Or should the rhs group box a globally accessible singleton or Borg? Trying to get past my prejudice against the word global to see this solution objectively and just can't. > Any other hint? How do you handle such situations? Perhaps by generating a custom event and posting it to the main window? If you're using wxPython, you might take a look at the dispatcher module. I haven't used it yet, but it might be appropriate to this sort of task. Regardless, I'd certainly post to the wxPython user list to see what people there come up with. Regards, Cliff -- She clings to the nearest passerby, she's lost control again -Joy Division From fawcett at teksavvy.com Mon Aug 18 04:24:06 2003 From: fawcett at teksavvy.com (Graham Fawcett) Date: Mon, 18 Aug 2003 04:24:06 -0400 Subject: What's better about Ruby than Python? In-Reply-To: References: Message-ID: <3F408D26.4090607@teksavvy.com> Brandon J. Van Every wrote: >Graham Fawcett wrote: > > >>Brandon J. Van Every wrote: >> >> >>>What's better about Ruby than Python? >>> >>> >>You're never going to get an answer to this question that satisfies >>you. Even if everyone chips in and describes their favourite >>features, those features may be worthless to you personally. So why >>bother asking? >> >> > >You assume too much. My attitudes and criteria aren't yours. I ask because >it's useful to me, not because it's useful to you. > > Fair enough. I can only encourage you, in the spirit of collegiality and goodwill, to emphasise among your attitudes the attitude of personal research. For the sake of brevity (not mine alone, but of this thread), let me add that this point has been previously discussed. A Google Groups search for "ruby vs. python group:comp.lang.python.*" returns over 250 responses. To assist those who don't like to look things up by themselves, here's a link: http://groups.google.ca/groups?q=ruby+vs.+python+group%3Acomp.lang.python.*&ie=UTF-8&oe=UTF-8&hl=en&btnG=Google+Search Notably, see: http://tinyurl.com/kc1u In this particular thread, from December 2002, Lyle Johnson points out "This has been discussed to death in the past and so you should be able to dig up a lot of information with your search engine of choice." History does indeed repeat itself! A more salient discussion on this list -- not just for you, Brandon, but for everyone -- might entail a review and updating of these older threads (what's changed in Python and Ruby since Dec 2002?), rather than a banal rehashing of it. But of course, our criteria vary. ;-) Yours, -- Graham From aahz at pythoncraft.com Wed Aug 6 20:02:21 2003 From: aahz at pythoncraft.com (Aahz) Date: 6 Aug 2003 20:02:21 -0400 Subject: Threading advantages (was Re: Python's biggest compromises) References: <899f842.0307310555.56134f71@posting.google.com> Message-ID: In article , enoch wrote: >aahz at pythoncraft.com (Aahz) wrote in message news:... >> In article , >> enoch wrote: >>>anthony_barker at hotmail.com (Anthony_Barker) wrote in message news:<899f842.0307310555.56134f71 at posting.google.com>... >>>> >>>> What to you think python largest compromises are? >>> >>>Its non existant SMP scalability. >> >> Would you care to back up your claim with some actual evidence? >> >> (Yes, there are issues with Python on SMP machines, but to call Python's >> built-in threading "non-existent SMP scalability" is either a lie or >> revelatory of near-complete ignorance. > >Ok, I confess, the term you cited might be little bit exaggerated. But >there's no need to get personal. I'm surely not a liar (w.r.t. to this >thread, everything else is not a matter of public concern ;) ). The >ignorance part, well, we can talk about that ... Since, as you say, you've done some research, that's why I flamed you. There's just no call for making such an overstated claim -- it is *NOT* "a little bit exaggerated". >> That doesn't even count the various IPC mechanisms.) > >Correct me if I'm wrong, but I don't think any form of IPC is a >measurement of scalability of something like the python interpreter. Depends what your context is. If you're restricting yourself to discussing the Python interpreter, that's correct; if you're discussing ways to boost the performance of a Python application on an SMP box, it's entirely appropriate. >Here are some sources which show that I'm not alone with my assessment >that python has deficiencies w.r.t. SMP systems: That I won't argue. But Python's approach also has some benefits even on SMP systems. And if you choose a multi-process approach, the same advantages that accrue to Python's approach on a single-CPU box apply just as much to an SMP system. >http://www.python.org/pycon/papers/deferex/ >""" >It is optimal, however, to avoid requiring threads for any part of a >framework. Threading has a significant cost, especially in Python. The >global interpreter lock destroys any performance benefit that >threading may yield on SMP systems, [...] >""" Just because it's a published PyCon paper doesn't mean that it's correct. The multi-threaded spider that I use as my example is a toy version of a spider that was used on an SMP box. (That's why I became a threading expert in the first place -- Tim Peters probably remembers me pestering him with questions four years ago. ;-) I guarantee you that SMP made that spider much faster. >So, although python is capable of taking advantage of SMP systems >under certain circumstances (I/O bound systems etc. etc.), there are >real world situations where python's performance is _hurt_ by running >on a SMP system. Absolutely. But that's true of any system with threading that isn't designed and tuned for the needs of a specific application. Python trades performance in some situations for a clean and simple model of threading. >Btw. I think even IPC might not help you there, because the different >processes might bounce betweeen CPUs, so only processor binding might >help. My understanding that most OSes are designed to avoid this; I'd be interested in seeing some information if I'm wrong. In any event, I do know that IPC speeds things up in real-world applications on SMP boxes. >I did quite a bit of googling on this problem - several times - >because I'm selling zope solutions. Sometimes, the client wants to run >the solution on an existing SMP system, and worse, the system has to >fulfill some performance requirements. Then I have the problem of >explaining to him that his admins need to undertake some special tasks >in order for zope to be able to exploit the multiple procs in his >system. Even if Zope is the 800-pound gorilla of the Python world, Python isn't going to change just for Zope. If you want to talk about ways of improving Zope's performance on SMP boxes, I'll be glad to contribute what I can. But spreading false information isn't the way to get me interested. Keep in mind that one reason IPC has gained popularity is because it scales more than threading does, in the end. Blade servers are cheaper than big SMP boxes, and IPC works across multiple computers. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From ialbert at mailblocks.com Mon Aug 18 16:13:10 2003 From: ialbert at mailblocks.com (Istvan Albert) Date: Mon, 18 Aug 2003 16:13:10 -0400 Subject: SWIG typemap leading to a memory leak Message-ID: I'm wrapping a C++ library with SWIG. Everything worked fine and dandy until I let to system run for longer periods of time. At that point I noticed that my scripts use up a whole lot of memory. I tried to locate the problem, and I ended up with an example that is very simple yet exhibits the same behavior. The SWIG wrapper has the following: typemap(out) int { int key; $result = PyDict_New(); for(key=0; key < $1; key++) { PyDict_SetItem($result, PyInt_FromLong(key), PyInt_FromLong(key)); } } this wraps a function that returns an integer and creates and returns a dictionary containing keys and values from 0 to the integer in question. When I call the function as below: for val1 in range(1000): for val2 in range(300): g.test(val2) it uses up all the memory in the system. (The test method belongs to a C++ class and simply returns its argument). The only answer I could come up with is that Python does not garbage collect the dictinary created in the wrapper file, and that fills up the memory. Does anyone know what is going on? Thanks. Istvan. From anton at vredegoor.doge.nl Thu Aug 7 14:04:29 2003 From: anton at vredegoor.doge.nl (Anton Vredegoor) Date: Thu, 07 Aug 2003 20:04:29 +0200 Subject: midi with ctypes Message-ID: Recently there has been a lot of progress concerning the integration of midi into python. A midipy.cpp for Python20 is found and various compiling efforts having been undertaken to compile it for Python23. See the other threads about midipy.cpp for more info. However, seeing that the resulting midipy.pyd is only 48 kilobyte long and seeing that midipy.cpp exports only 14 functions, most of which are inside winmm.dll (for W98 and W2000 at least) I decided to start another effort, which I'm presenting below and for which I hope kind people will add some functions since I doesn't seem to be too hard. first create a winmm.def like this: pexports winmm.dll > winmm.def Now open winmm.def and find the relevant functions, compare them with what's inside midipy.cpp and try to reproduce them using ctypes. The file "mmedia.hlp" from Borland C++ Builder for example, contains detailed info about midi functions, most of which seem to be direct wrappers around the functions inside winmm.dll . Now to get started try this: #ctypesmidipy.py from ctypes import * def getNumMidiInDevices(): return windll.winmm.midiInGetNumDevs() def getNumMidiOutDevices(): return windll.winmm.midiOutGetNumDevs() def test(): print getNumMidiInDevices() print getNumMidiOutDevices() if __name__=='__main__': test() Please note that after importing this file every function should work the same as if midipy.pyd had been imported. Not being very familiar with midi programming I succeeded only to get 2 of the 14 functions working. Getting more functions to work should be harder, but not very hard. Please, anybody reading this, add a function if there's a sudden insight into how it should be done. By and by ctypesmidipy.py will be put together like a little pypy-alike project replacing midipy.cpp :-) Any feasibility studies and remarks about possible legal objections to this are very welcome too. Anton From donot at likespam.com Wed Aug 27 14:03:33 2003 From: donot at likespam.com (Rich) Date: Wed, 27 Aug 2003 11:03:33 -0700 Subject: learning to program References: <3F4CED6E.D04D35D6@engcorp.com> Message-ID: <5bspkv87u1q0v9aupajrrkjuutuh3f5o44@4ax.com> On Wed, 27 Aug 2003 13:42:06 -0400, Peter Hansen wrote: >Rich wrote: >> >> I downloaded the beginner package from the "Python" site, and would >> like to know my next move. >> >> Should I wade through the site, or are there some exorcises I can do >> to get started in the process of learning how to program. > >First thing you can do is stop posting the question and wait for >the answers. Three times is more than enough... This is the only post I am able to see, sorry about re posting. I thought if I changed the subject heading I might be able to see the post. > >Of course, most likely you aren't seeing any of the replies, in which >case you won't get this one either, and since you didn't include your >real mail address, we're stuck! :-) I mugged my e-mail to block spam. Here is my e-mail r.west at comcast.net Rich > >-Peter From grante at visi.com Thu Aug 14 10:28:38 2003 From: grante at visi.com (Grant Edwards) Date: 14 Aug 2003 14:28:38 GMT Subject: Determine file type (binary or text) References: Message-ID: <3f3b9c96$0$175$a1866201@newsreader.visi.com> In article , Sami Viitanen wrote: > To be more specific I'm making a script that should > identify binary files as binary and text files as text. That's "more specific"? ;) -- Grant Edwards grante Yow! I hope I at bought the right visi.com relish... zzzzzzzzz... From achrist at easystreet.com Sat Aug 16 01:55:08 2003 From: achrist at easystreet.com (achrist at easystreet.com) Date: Fri, 15 Aug 2003 22:55:08 -0700 Subject: GUI builder for Python References: Message-ID: <3F3DC73C.3ADD3980@easystreet.com> dan wrote: > > > Been wondering myself. How is http://sourceforge.net/projects/wxworkshop/? > > this looks nice and it's free. I'm wondoering about Visual Wx. This looks like someone put much work into it, but I haven't been able to get it to do anything. This is probablyt because I can't find any documentation in English that tells how to get it to do anything. Al From Juha.Autero at iki.fi Mon Aug 18 00:56:42 2003 From: Juha.Autero at iki.fi (Juha Autero) Date: Mon, 18 Aug 2003 07:56:42 +0300 Subject: hex(-5) => Futurewarning: ugh, can't we have a better hex than '-'[:n<0]+hex(abs(n)) ?? References: Message-ID: <87lltrzhpx.fsf@jautero.no-ip.org> Freddie writes: >> There is a thread from this morning ("bitwise not ...") - this should be an >> excellent contribution! >> I have no mercy with someone writing hex(-5) >> >> Kindly >> Michael P >> >> > > What about crazy people like myself? If you generate a crc32 value with zib, > you occasionally get a negative number returned. If you try to convert that > to hex (to test against a stored CRC32 value), it spits out a FutureWarning > at me. Read the thread about bitwise not. Tell Python how many bits you want. In case of CRC32 that is of course 32 bits: hex(-5&2**32-1) Two questions: What is the best way to generate bitmask of n bits all ones? And would sombody explain why hexadecimal (and octal) literals behave differently from decimal literals? (see: http://www.python.org/doc/current/ref/integers.html ) Why hexadecimal literals from 0x80000000 to 0xffffffff are interpetred as negative numbers instead of converting to long integers? -- Juha Autero http://www.iki.fi/jautero/ Eschew obscurity! From gerrit at nl.linux.org Wed Aug 27 14:28:09 2003 From: gerrit at nl.linux.org (Gerrit Holl) Date: Wed, 27 Aug 2003 20:28:09 +0200 Subject: My own 12 points list In-Reply-To: References: Message-ID: <20030827182809.GB4258@nl.linux.org> A. Lloyd Flanagan wrote: > pruebauno at latinmail.com (nnes) wrote in message news:... > > I have really no mayor gripes, and the few things I would change would > > break backward compatibility, but here is the list anyway: > > > > 3.) Eliminate open (), use file () instead > open() is deprecated, I don't know about plans to eliminate it. Doesn't 'deprecated' mean it will once be elimineted? > > 5.) Eliminate built-in functions buffer(), callable(), delattr(), > > dir(), getattr(), hasattr(), hash(), help(), id(), isinstance(), > > len(), max(), min(), repr(), setattr(), sum(), str(), type(), > Many of these are being superseded by object meathods. I don't know > about eliminating them; you'd break nearly every old program. Python 3.0...? Gerrit. -- 173. If this woman bear sons to her second husband, in the place to which she went, and then die, her earlier and later sons shall divide the dowry between them. -- 1780 BC, Hammurabi, Code of Law -- Asperger Syndroom - een persoonlijke benadering: http://people.nl.linux.org/~gerrit/ Het zijn tijden om je zelf met politiek te bemoeien: http://www.sp.nl/ From http Tue Aug 26 13:10:10 2003 From: http (Paul Rubin) Date: 26 Aug 2003 10:10:10 -0700 Subject: reading hex values elegantly from a datagram References: Message-ID: <7xad9wibv1.fsf@ruckus.brouhaha.com> davbucko at yahoo.com (Dave) writes: > At the moment I am doing crazy things like converting it to a string, > slicing characters off (ie id = packet[0:2]), adding 0x to the front > and exec-ing the whole thing to get an integer. Don't ever exec data from an untrusted source. Use int(packet[0:2], 16). From evan at 4-am.com Fri Aug 22 17:07:09 2003 From: evan at 4-am.com (Evan Simpson) Date: Fri, 22 Aug 2003 16:07:09 -0500 Subject: visual indentation In-Reply-To: References: Message-ID: <3F4685FD.3010406@4-am.com> Hilbert wrote: > RiWorldBegin() > RiColor(1.0,1.0,1.0) > RiSurface('constant') > RiSphere(1.0,-1.0,1.0,360) > RiWorldEnd() > > Is there any way to use such "visual" indentation in python? If all of the lines that you want to indent in this fashion are expressions, not statments, then you could do this: RiWorldBegin() ( RiColor(1.0,1.0,1.0) ) ( RiSurface('constant') ) ( RiSphere(1.0,-1.0,1.0,360) ) RiWorldEnd() If there are statements involved, you could do this: RiWorldBegin() 1; RiColor(1.0,1.0,1.0) 1; RiSurface('constant') 1; RiSphere(1.0,-1.0,1.0,360) RiWorldEnd() Both are ugly, of course. Cheers, Evan @ 4-am From jacek.generowicz at cern.ch Thu Aug 21 09:22:21 2003 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 21 Aug 2003 15:22:21 +0200 Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> <6dj2kv8ugkieehs7guh786cl40o5lj6mcs@4ax.com> <599a6555.0308202108.397bb1a0@posting.google.com> Message-ID: "Andrew Dalke" writes: > Ndiya kulala. -- I am going for the purpose of sleeping. > > And here's an example of Swedish with a translation into > English, which lack some of the geneaological terms > > min mormor -- my maternal grandmother > > I can combine those and say > > Umormor uya kulala -- my maternal grandmother is going > for the purpose of sleeping. > > See how much more precise that is because I can select > words from different Dialects of Speech? You are absolutely right. "Umormor uya kulala" is less readable than "My maternal grandmother is going for the purpose of sleeping", to someone who is familiar with English, but unfamiliar with Xhosa and Swedish. Now explain the Mor/Far concept and the "going for a purpouse" concept" to said English speaker, and present him with text it which combinations of the concepts are user repeatedly. _Now_ ask yourself which is more readable. For this reason it is rarely a good idea to define a macro for a single use. However, it becomes an excellent idea if the idea the macro expresses must be expressed repeatedly. The same is true of functions, classes, modules ... From tebeka at cs.bgu.ac.il Sun Aug 10 12:33:48 2003 From: tebeka at cs.bgu.ac.il (Miki Tebeka) Date: 10 Aug 2003 09:33:48 -0700 Subject: py2exe and wxCalendarCtrl? References: Message-ID: <33803989.0308100833.788c1453@posting.google.com> Hello Stefan, > I'm using python 2.2.3, wxPython 2.4.0.7, py2exe 0.4.1 On python 2.3, wxPython 2.4.1.2 and py3exe 0.4.1 it works. Miki. From hjwidmaier at web.de Mon Aug 11 03:21:39 2003 From: hjwidmaier at web.de (Hans-Joachim Widmaier) Date: 11 Aug 2003 00:21:39 -0700 Subject: Reading external files or internal data Message-ID: <6e990e29.0308102321.53b56117@posting.google.com> Hi, I have a class that reads most common files (text, images, tar archives, zip archives). I just read in the whole thing and decide then what to do with it - create a gtk.TextView, gdk.pixbuf, or tables-of-contents, whatever. Looking at the functions in the appropriate modules shows that most of them want to read from external files. Some take file-like objects, others don't. And tarfile allows it for gzip compressed archives, but not for bzip2 compressed ones. This is not only horribly inconsistent, it's also ugly. I do not want to read an external file over and over again. (If I'd read from standard input, I'd have to create a temporary file - yuck!) I want to deal just *once* with all the errors that can occur while reading the file. What am I missing? Hans-Joachim Widmaier From dkuhlman at rexx.com Thu Aug 21 21:19:31 2003 From: dkuhlman at rexx.com (Dave Kuhlman) Date: Thu, 21 Aug 2003 18:19:31 -0700 Subject: crazy programming language thoughts References: Message-ID: Ryan Lowe wrote: > the basic concept would be to use identifying words in front of > the arguments to determine their identity as well as making the > function call read more like an english phrase. for instance, take > the simple python statement: > >>>> vtext.replace('a', 'b') > > wouldnt it be nicer (more english-like at least) to say: > >>>> replace 'a' with 'b' in vtext Incredibly great idea. Unfortunately, it's been done. It's called COBOL. It was/is hugely successful. And, by the way, whitespace for indentation is significant in COBOL, I believe. Dave -- Dave Kuhlman http://www.rexx.com/~dkuhlman dkuhlman at rexx.com From logiplex at qwest.net Mon Aug 25 16:42:52 2003 From: logiplex at qwest.net (Cliff Wells) Date: Mon, 25 Aug 2003 13:42:52 -0700 Subject: detecting document changes In-Reply-To: References: Message-ID: <1061844172.1506.416.camel@software1.logiplex.internal> On Sun, 2003-08-24 at 02:36, Alessandro Crugnola *sephiroth* wrote: > Hi, > i'm using wxPython and wxTextStyled. > How can I intercept document changes for active documents (for example > modified with others external editors)? If you're on Linux (and perhaps other Unices) you can use FAM (file alteration monitor). There's a Python library for the SGI version of FAM (I don't know if it will work with anything other than XFS): http://python-fam.sourceforge.net/ also check out this link: http://oss.sgi.com/projects/fam/faq.html If you're looking for a more general or cross-platform solution then probably just periodically checking timestamp/size/md5sum for the file is another (albeit somewhat less elegant) option. Regards, -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 (800) 735-0555 From geoff at gerrietts.net Thu Aug 28 15:12:04 2003 From: geoff at gerrietts.net (Geoff Gerrietts) Date: Thu, 28 Aug 2003 12:12:04 -0700 Subject: OT: Celebrity advice (was: Advice to a Junior in High School?) In-Reply-To: <20030828055509.GD2515@nl.linux.org> References: <3F4D0D8B.5E5F9488@engcorp.com> <20030827201213.GA4670@nl.linux.org> <20030827211959.GD30536@thoth.homegain.com> <20030828055509.GD2515@nl.linux.org> Message-ID: <20030828191204.GC18211@thoth.homegain.com> Quoting Gerrit Holl (gerrit at nl.linux.org): > Geoff Gerrietts wrote: > > Quoting Gerrit Holl (gerrit at nl.linux.org): > > > Peter Hansen wrote: > > > > But if you refuse to go to prison, things get lethal pretty quickly. > > > > That's what "ultimately" refers to above. > > > > > > Well, I don't think they get very lethal, they get painful at most. > > > > It depends on the case. Several times in recent history, the American > > FBI has deployed lethal force when it was insufficiently provoked > > (Ruby Ridge, Waco). > > "Several times in (American) history" is, of course, not the same as > "every dicision", "ultimately". And neither is it "they get painful at most", which is the point I was making. ESR overstates his point to make his point; you're doing the same. Whether either point can be made is a different question, as is whether either should be made. --G. -- Geoff Gerrietts "There is no fate that cannot be surmounted by scorn." --Albert Camus From dakidd at sonic.net Tue Aug 5 05:59:35 2003 From: dakidd at sonic.net (Don Bruder) Date: Tue, 05 Aug 2003 09:59:35 GMT Subject: (VERY) New to Python. Need Help! References: Message-ID: In article , "Richard Brodie" wrote: > "Don Bruder" wrote in message > news:tqJXa.8564$dk4.364945 at typhoon.sonic.net... > > > Looks pretty obvious that something it wants can't be found. > > Yes, It can't find the getpid function within the os module. It isn't > available > on the Mac (at least not classic Mac). Reading http://www.dessent.net/btfaq/ > may help. Indeed it does. I can't help but wonder why this URL doesn't seem to appear anywhere in the docs? The only FAQ-type URLs I'm seeing so far in the "on-board" docs appear to be hosting on bitconjurer.org, with no mention of this "www.dessent.net" host anywhere blatantly obvious. Any indication of whether there's a "getpid" function in the Carbon version of MacPython? And how would I go about checking to see (aside from the obvious "fire up the program - if it pukes, the function isn't there") if an arbitrarily selected function is available in a particular Python implementation? Thanks for the help so far! -- Don Bruder - dakidd at sonic.net <--- Preferred Email - unmunged, SpamAssassinated Hate SPAM? See for some seriously great info. I will choose a path that's clear: I will choose Free Will! - N. Peart Fly trap info pages: From irmen at -NOSPAM-REMOVETHIS-xs4all.nl Wed Aug 6 11:20:36 2003 From: irmen at -NOSPAM-REMOVETHIS-xs4all.nl (Irmen de Jong) Date: Wed, 06 Aug 2003 17:20:36 +0200 Subject: recompiled midipy.pyd for 2.3 In-Reply-To: References: Message-ID: <3f311cc4$0$49112$e4fe514c@news.xs4all.nl> smarter_than_you wrote: > FYI -- > > I just tested downloading the file I just posted. In IE, it saves > with an .htm extension but it compares correctly with the file. In > NS, it downloads with the right extension but appears to be corrupted > (linefeeds I think). I'm no HTML jockey so go figure. If you have problems downloading the file, and you can't configure the web server to supply an appropriate content-type such as application/octet-stream, you could always (g)zip the file and put that up for download. Usually the web server gets the content type right in that case, and your browser too. --Irmen From aleax at aleax.it Fri Aug 8 12:32:48 2003 From: aleax at aleax.it (Alex Martelli) Date: Fri, 08 Aug 2003 16:32:48 GMT Subject: crossplatform py2exe - would it be useful? References: <2UyYa.50516$cl3.1586459@news2.tin.it> Message-ID: Thomas Heller wrote: ... > But, all in all, it sounds like a plan. Although I have the impression > that it may be difficult to convince the python-dev crowd to include > this in 2.3.1. (Is anyone of them reading this thread?) Sure -- me, for one;-). Seriously, _let's_ take it to python-dev and see which way the wind blows -- then we may pep &c accordingly... Alex From pdfernhout at kurtz-fernhout.com Mon Aug 25 09:21:04 2003 From: pdfernhout at kurtz-fernhout.com (Paul D. Fernhout) Date: Mon, 25 Aug 2003 09:21:04 -0400 Subject: Comments on my "Python Introduction" slides In-Reply-To: <33803989.0308240000.35b9bf1f@posting.google.com> References: <33803989.0308240000.35b9bf1f@posting.google.com> Message-ID: <3f4a0cea_4@corp.newsgroups.com> I liked your slides a lot, as they also sort of capture a what's new of some of the later python versions (e.g. generators, reverse) which are still somewhat new to me (having done Python for years on and off and having tried to stick with 1.5 backwards compatability for a long time -- until now with 2.3). However, and not knowing your audience, I wonder if the slides are a bit advanced (but obviously they are probably not meant to stand alone from your talk, and your purpose might be to _wow_ your audience). For example, will people really understand how useful and powerful and easy to use dictionaries are [a key feature of Python] by just saying they are like a hash table? You have an example of a dictionary in use in "unique" but in the example doesn't add something into the dictionary in the flow of the text of the program until after the test -- a perfectly good way to implement it, but perhaps harder to follow initially for some people (who may be asking where does the data come from when they get to the test.). Also, since you just set the value to true, it doesn't quite capture how most dictionaries are typically used (to store key value pairs). I'd say another slide on dictionaries might be warranted with a simpler better example, to preceed the "unique" example one you have there. Somethign blah like just putting names and email addresses together. Also, since one a pracical basis some fraction of your audience is going to recoil at the significant white space, you might have a slide on this (maybe in the middle, or after your first example) and how it is not a problem in practice, and in fact promotes maintainability and prevents some bracing style clashes. For me (having used Occam earlier, which also uses significant white space), significant white space for block delimiting is one of Python's best features. You might as well confront the controversy head on somehow (like quotes from this newsgroup from converts to it?) I can also see an argument for not bringing the subject up as that might scare people off, but since you have a chance to bring it out in the open in a controlled way sounding favorable to Python, and you know it will be an issue for people coming from C, it might be best to just deal with it. Obviously, you only have so much time for a talk, so you have to prioritize, and maybe there isn't enough time for two more slides. But, I think if you had to drop two, I'd drop the "generators" and "fibs geenrator" example. You may well lose a lot of your audience there anyway (as while useful, the continuation concept is somewhat abstract and advanced). Also, the "Quick One" items might easily include a word or two on the topic, i.e. "Quick One: Files" or "Quick One: fibs" for reference. Also "Not In Standard Library" might be changed to "Free Third-party Addons" to sound a little nicer (otherwise people might think it is a complaint). You might also rename your "Development Methodology" slide as "Will it be fast enough?" or something like that ("Developing for speed?") and reference programmer time vs. execution time, since I expected that slide otherwise based on the title to reference Extreme Programming vs. Waterfall Development models or some such approaches. Having said all that (and none of those are major problems in the context of a talk where you continually monitor the audience's understanding and adapt your comments), I think the use of complete small program examples (e.g. du, fibs, etc.) in your tutorial was a great choice to help people grasp the language. So, overall, good job! --Paul Fernhout (Who for a while taught programming to biology majors, which turned out to be great experience for talking to senior execs about software. :-) Miki Tebeka wrote: > If you have the time I'd appriciate any comments on my slides at > http://www.cs.bgu.ac.il/~tebeka/pyintro.htm -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! -----== Over 100,000 Newsgroups - 19 Different Servers! =----- From chrisahlers at yahoo.com Wed Aug 27 17:50:57 2003 From: chrisahlers at yahoo.com (Chris) Date: 27 Aug 2003 14:50:57 -0700 Subject: asyncore: handle_accept() question? Message-ID: Here's the idea: I have a listen_server listening to a specific port. A connection object connects to it remotely, and then the communication begins. Once connected, I would like to have the server act no differently than the client (i.e. use the connection class to handle the connection). This way rather than having a typical server and client(producer/consumer) I have two peers. class listen_server(asyncore.dispatcher): def __init__(self, port): ### Basic Server Stuff ### asyncore.dispatcher.__init__(self) self.create_socket(socket.AF_INET, socket.SOCK_STREAM) self.set_reuse_addr() self.bind(('', port)) self.listen(5) def handle_accept(self): conn, addr = self.accept() print conn.fileno() ## this always prints a number print 'connection accepted' ## this always prints newcon = connection(sock=conn) ## error happens here class connection(asyncore.dispatcher): def __init__(self, host = None, port = None, sock = None): asyncore.dispatcher.__init__(self) self.create_socket(socket.AF_INET, socket.SOCK_STREAM) self.set_reuse_addr() # needed? if host and port: self.connect((host, port)) if sock is not None: print 'setting socket' self.set_socket(sock) def handle_read(self): data = self.recv(4096) def handle_write(self): pass def handle_connect(self): print 'connected' def handle_close(self): print 'closed connection' self.close() Here is my output: --------------------------- connection accepted setting socket Traceback (most recent call last): File "test.py", line 66, in ? asyncore.loop() File "/usr/lib/python2.2/asyncore.py", line 206, in loop poll_fun (timeout, map) File "/usr/lib/python2.2/asyncore.py", line 83, in poll r,w,e = select.select (r,w,e, timeout) select.error: (9, 'Bad file descriptor') My basic problem is that I don't know any other way to 'hand off' the incoming connection - if there is a better way to do this please let me know. conn.fileno() appears to work, and I don't understand why this error comes up. Any ideas? Thanks, Chris From fredrik at pythonware.com Wed Aug 20 04:41:06 2003 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 20 Aug 2003 10:41:06 +0200 Subject: what to do when instance of class fails to initialize ? References: Message-ID: Tom Van den Brandt wrote: > If I have an __init__ for a class and the initialisation can't go through > (example: missing or wrong arguments), how do I return an error to the > caller (from main() function)? When I do a return statement in the > __init__ it says __init__ should return None... I can stop the flow with > raise 'BlahBlah'. But then the program exits. > > What is the nice way to do this ? catch the exception: http://www.python.org/doc/current/tut/node10.html: http://www.python.org/doc/current/ref/try.html From tzot at sil-tec.gr Tue Aug 26 15:18:49 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Tue, 26 Aug 2003 22:18:49 +0300 Subject: file object, details of modes and some issues. References: <3f4b800f_3@mk-nntp-1.news.uk.worldonline.com> <7h3d6ese09m.fsf@pc150.maths.bris.ac.uk> Message-ID: <5jcnkvkfbb91ghko4kv661v2h80n9o32k7@4ax.com> On Tue, 26 Aug 2003 18:37:03 GMT, rumours say that Michael Hudson might have written: >>, i had expected an exception. >> >> f=file('readme.txt','w') >> f.write(' ') >> f.read() > >engages in undefined behaviour (i.e. is perfectly entitled to make >demons fly out of your nose). OK, then, let's close the 795550 bug (I saw your reply there after posting the second comment). -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From vze4rx4y at verizon.net Tue Aug 26 12:19:21 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Tue, 26 Aug 2003 16:19:21 GMT Subject: bool and unicode References: Message-ID: [Roman Yakovenko] > But still I expect this code to work. > > assert False == bool( str( bool( False ) ) ) > > The context of previous expression is in serialization. It would be more reasonable to expect: assert False == bool(eval(repr(False))) The code you listed does work for int, complex, long, and float, but does not generalize to other types: >>> int('2') 2 >>> complex('3+4j') (3+4j) >>> long('3L') 3L >>> float('3.14') 3.1400000000000001 >>> list('[1,2]') # this won't work ['[', '1', ',', '2', ']'] >>> tuple('(1,2)') # neither will this ('(', '1', ',', '2', ')') Raymond Hettinger From member35572 at dbforums.com Tue Aug 12 10:33:41 2003 From: member35572 at dbforums.com (sleepinggiant) Date: Tue, 12 Aug 2003 14:33:41 +0000 Subject: pythonwin::python object browser Message-ID: <3229113.1060698821@dbforums.com> anyone know how to add an object to the pythonwin object finder, in the makepy tool (in tools tab) ? cheers, matt -- You ahve nothing to fear except fear itself Posted via http://dbforums.com From max at alcyone.com Tue Aug 19 20:16:32 2003 From: max at alcyone.com (Erik Max Francis) Date: Tue, 19 Aug 2003 17:16:32 -0700 Subject: Why does this (not) work? References: Message-ID: <3F42BDE0.2AACA9DE@alcyone.com> "Michael C. Neel" wrote: > Maybe I should phrase the question a bit differently, more to the real > issue (I guess, it's all academic from here), why is the % operator > used > both for string formatting and remainders? It's got a lot of precedent behind it, so it's too late to change now. At some point, someone decided it made sense, so it was done. > To me: > > >>>"%d" % 2 * 3 > "222" > > Is not what I expected nor wanted. I could however be alone in that > opinion. The real question is: How likely is this issue going to be a real problem? Why not just learn to use parentheses when you're doing something tricky with the right argument to the string formatting operator, and be done with it, problem solved? -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ Human salvation lies in the hands of the creatively maladjusted. \__/ Dr. Martin Luther King, Jr. From mpeuser at web.de Sat Aug 16 08:12:15 2003 From: mpeuser at web.de (Michael Peuser) Date: Sat, 16 Aug 2003 14:12:15 +0200 Subject: How remove Tcl/Tk fom py2exe distribution? References: <7k5dzwo9.fsf@python.net> Message-ID: Thank you Thomas, for these excellent advice. "verbose" of course just supports debugging and does not prevent py2exe from beeing quite autistic. And it does a good job in that: Not only sys.path but sys.prefix as well as sys.exec_prefix are faked to the local directory. This makes it a little bit harder to supplement the path info. Tcl also has the nasty habbit to look arround according to sys.prefix settings and trying this and that.... Nevertheless I think I can do the next step. It could be of help, if py2exe either - could become configurable (i.e. optionally leave the os variables as they are) or - make them somewhere available KIndly Michael P "Thomas Heller" schrieb im Newsbeitrag news:7k5dzwo9.fsf at python.net... > Ok. First you should make sure that Tkinter is not found and copied by > py2exe. The '--exclude' flag could be used, or the above __import__ > trick. > > Then, you should make sure that your executable finds the 'standard' > Tkinter module (and tcl/tk) installation by including the proper > directory into sys.path. Normally py2exe takes some care to *not* find > modules or packages from a Python installation on the system. > > A little experimentation is probably needed, and hacking py2exe could > maybe help. You can change this code (in py2exe\build_exe.py, near line > 926) > header = struct.pack(" self.optimize, # optimize > 0, # verbose > 0x0bad3bad, > ) > into this > header = struct.pack(" self.optimize, # optimize > 1, # verbose > 0x0bad3bad, > ) > and the resulting executable will trace import statements. > > Thomas From adalke at mindspring.com Tue Aug 19 16:26:00 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Tue, 19 Aug 2003 20:26:00 GMT Subject: generators improvement References: Message-ID: Oleg Leschov: > What I think should increase the potential usefulness of a generators, > is bi-directional data passage. This is very easy to implement, IMHO. > > What needs to be done is to allow yield return something - whatever was > passed to the .next() thing from caller.. ... > I understand that this can be achieved by using some > global, for instance, but hey, I used to implement generator's functionality > without using them, too - just make a class and make > algorithm look horrible. The same thing, but much wordier and uglier > looking... and that does not mean that generators are redundant. While somewhat cumbersome, you could do (mind the bad cut&paste - OE Express didn't like the tabs PythonWin sent over) class State: def __init__(self): self.args = None self.kwargs = None class OlegYield: def __init__(self, f): self.f = f def __call__(self, *args, **kwargs): state = State() args = (state,) + args return OlegIter(state, f(*args, **kwargs)) class OlegIter: def __init__(self, state, iter): self.state = state self.iter = iter def __iter__(self): return self def next(self, *args, **kwargs): self.state.args = args self.state.kwargs = kwargs return self.iter.next() >>> def f(state, n): ... for i in range(n): ... yield i ... print state.args, state.kwargs ... >>> g = OlegYield(f) >>> a = g(5) >>> a.next() 0 >>> a.next(6, a=7) (6,) {'a': 7} 1 >>> list(g(4)) () {} () {} () {} () {} [0, 1, 2, 3] >>> Andrew dalke at dalkescientific.com From gregbrunet at NOSPAMsempersoft.com Thu Aug 7 12:20:09 2003 From: gregbrunet at NOSPAMsempersoft.com (Greg Brunet) Date: Thu, 7 Aug 2003 11:20:09 -0500 Subject: Class design issues: multiple constructors References: Message-ID: Hi Alex "Alex Martelli" wrote in message news:SiqYa.27810$an6.980707 at news1.tin.it... > > I'm also > > thinking that I might rather name the methods more specifically (such as > > Open & Create) instead of both being __init__. What would be the > > Right. The Pythonic way is to provide "factory functions" that prepare > and return the object you need. Cosmetically, you may make the factory > functions part of the class itself, using the staticmethod and classmethod > built-in types of Python 2.2 and later -- no real need, but some people > are very keen on this style, so Python now supports it. It sounds like option #1 in Miki's response to my post would be called factory functions. I can see how that would work - pretty straightforward & understandable. > > Pythonic way to go about doing this? Would I make an __init__, Open, & > > Create methods, and make 2 calls for each DBF object, like this: > > > > class dbf: > > __init__(self): > > pass > > Create(self, filename, fieldDefs): > > pass > > Open(self, filename): > > pass > > No, it should rather be something like: > > class dbf(object): > # no need to define __init__ if it's empty! > def Create(filename, fieldDefs): > result = dbf() > # use filename and fieldDefs to populate 'result' appropriately > return result > Create = staticmethod(Create) > def Open(filename): > result = dbf() > # use filename to populate 'result' appropriately > return result > Open = staticmethod(Open) A couple of things. First, I was mostly trying to indicate the structure of the class. I'm thinking that there might in fact be some __init__ code present that would be shared by both the Open & Create functions. In that case, I would expect that the corresponding "result=dbf()" code in the functions would invoke the __init__ code - correct? I'm also confused by the omission of "self" from the function/method definitions. It seems that these functions are 'Class-level' methods (which would explain the term staticmethod I expect ). So at the time they are invoked, an instance/object has not been created (and thus we are returning it: result). > > # open existing file > > f1 = dbf() > > f1 = dbf.Open('customer.dbf') > > No, this wouldn't work with the code you propose; it would with > the variant I suggest, but the first of these statements is useless > so you should remove it. Agreed - I was looking for a way to get rid of the initial "f1=dbf()" statement, and your technique embeds that in the Open call - which is great. The same applies to the Create function call. However, something that's got me more confused is that after getting your response, I read the "Unifying types and classes in Python 2.2" section of the docs, specifically the "Static methods and class methods" section. They give an example of: class C: def foo(x, y): print "staticmethod", x, y foo = staticmethod(foo) C.foo(1, 2) c = C() c.foo(1, 2) What concerns me here is what would happen if someone did indeed perform the "f1=dbf()" before the "dbf.Open" call? The sample from the manual shows that kind of usage. In my situation, it seems that I would be creating an (empty) dbf object, then throwing it away and replacing it with the result of the Create or Open statement. Is there some way to prevent someone from using "f1=dbf()", since doing so would leave them with an unusable object? Thanks for your excellent help! -- Greg From tgray at cox-internet.com Sun Aug 17 15:43:44 2003 From: tgray at cox-internet.com (Terry Gray) Date: Sun, 17 Aug 2003 14:43:44 -0500 Subject: os.system stdout redirection... In-Reply-To: References: Message-ID: mackstann wrote: > On Sun, Aug 17, 2003 at 01:01:41AM -0500, Terry Gray wrote: > >>Using Python 2.2 in Debian linuxI am trying to change to a different >>directory, execute a 'make all' command, and redirect the output of the >>subshell to a PyQt window... I should be able to execute the >>os.system('cd newdirectory; make all'), but how do I redirect stdout of >>the new subshell created by the os.system call? >> >>Any help would be appreciated. > > > You can use os.popen (popen2 and 3 as well), or the popen2 module's > Popen3 and 4 classes, or commands.getoutput (and there are probably even > more ways :). > All the Python docs I've been looking at must have been pre-2.0, because this is the first I've heard of the popen2/3/Popen3/4 calls. Anyway, is there a recommended way of capturing 'make's' output, line by line, and redirecting it to a PyQt window? The window in question is a QTextEdit control with a 'def write' function. Again, thanks for the help. From tismer at tismer.com Sat Aug 16 22:42:40 2003 From: tismer at tismer.com (Christian Tismer) Date: Sun, 17 Aug 2003 04:42:40 +0200 Subject: Loading and executing an arbitrary Python script from within Python In-Reply-To: <20030726094624.15169.00000599@mb-m13.aol.com> References: <20030726094624.15169.00000599@mb-m13.aol.com> Message-ID: <3F3EEBA0.9080805@tismer.com> TheDustbustr wrote: .... > This sucks. Indeed. > How else can I solve this problem? Ideally, I'd use Stackless Python > microthreads, but version 3.0 is not out yet and there is no documentation on > the current way to do microthreads. Stackless is in fact the best way to do this, IMHO. Unfortunately, 5 minutes before getting SLP 3.0 out, most support for Stackless was shut down (no names here). So I have to find a way to continue, which I definately will, but things will slow down, again. Maybe you can help me, and I will help you! cheers - chris -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 mobile +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From andymac at bullseye.apana.org.au Thu Aug 28 07:21:35 2003 From: andymac at bullseye.apana.org.au (Andrew MacIntyre) Date: Thu, 28 Aug 2003 21:21:35 +1000 (EST) Subject: MemoryError: out of memory Python 2.1.3 on Windows 2000 In-Reply-To: References: Message-ID: <20030828210826.J19521@bullseye.apana.org.au> On Thu, 27 Aug 2003, Andy Rechenberg wrote: > Is this issue related to running python 2.1.3 on Windows 2000? Is > there anyway I can fix this problem so that python.exe will use more > than 122MB of RAM (the server has 4GB)? I would hazard a guess that what you are really seeing is a heap fragmentation issue. This was particularly prevalent on Win9x, and I had been under the impression that the situation was much less severe on Win2k and later. There was at least one fix (that I recall anyway) applied to the 2.2.x branch to use aggressive overallocation strategies to reduce the impact of this fragmentation. PyMalloc in 2.3 goes a long way to isolating Python from oddities in the host's malloc() implementation. You might be able to get an indication of whether this is the problem you're seeing by running the longexp regression test - although on a machine with 4GB of RAM you might have to bump the expression length up to 100,000, maybe 150,000. Contact me off-list if you want more detail. Regards, Andrew. -- Andrew I MacIntyre "These thoughts are mine alone..." E-mail: andymac at bullseye.apana.org.au (pref) | Snail: PO Box 370 andymac at pcug.org.au (alt) | Belconnen ACT 2616 Web: http://www.andymac.org/ | Australia From tjreedy at udel.edu Tue Aug 26 21:50:16 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 26 Aug 2003 21:50:16 -0400 Subject: Advice to a Junior in High School? References: <873cfo6tbl.fsf@pobox.com> Message-ID: "John J. Lee" wrote in message news:873cfo6tbl.fsf at pobox.com... > "Terry Reedy" writes: > > The demand for software engineers has fluctuated up and down, in > > various industries and regions, for decades. An article in the > > current Business 2.0 on the 'coming labor shortage' points out that > > you are part of the first generation in America to be numerically > > smaller than your parents generation. In ten years, when boomers have > > or are retiring, there will probably be a relatively shortage of tech > > workers. > > Who knows? There are plenty of clever, hard-working people in India > who speak good English. It would be a good thing if more computing > jobs moved there, IMHO, and that certainly seems to be happening to an > extent already. The same article pointed out that 1) much of the outsourcing is lower level call-center jobs; 2) programmer salaries are already rising in India because most of the good talent is already employed; 3) the shortage anticipated is greater that the anticipated extra supply in India, China, etc. Who know... TJR From geoff at gerrietts.net Fri Aug 15 16:28:57 2003 From: geoff at gerrietts.net (Geoff Gerrietts) Date: Fri, 15 Aug 2003 13:28:57 -0700 Subject: "drop-in" DOM replacement for minidom? In-Reply-To: References: Message-ID: <20030815202857.GA2349@thoth.homegain.com> Quoting Uche Ogbuji (uche at ogbuji.net): > > My response is usually more like "what are you using XML for a single > 30MB file for?" I don't think you responded when I asked. :) http://groups.google.com/groups?th=bf5c3ace18a4e2b6&seekm=mailman.1053714039.24283.python-list%40python.org > I've long maintained that when working with XML, modest document sizes > is very important, regardless of what tools you're using. I think I agree, though some are better suited for large documents than others. > But that having been said, some documents are 30MB, and it makes sense > that they're 30MB, and that's just the way it is. And again. Sometimes unreasonable people with a stronger sense of "good buzzwords" than "good design" are on one end of your project. And sometimes, the "normal" cases may all be appropriate -- optimal, even -- for an XML usage, while the corner cases are 30MB. > > My friend also had some more challenging problems. He was running on a > > DEC Alpha, I think under Digital Unix, and as a consequence 4Suite had > > byte-ordering problems. > > 4Suite used to have byte-ordering problems, originally reported under > Solaris 9, and also affecting some Mac OS X users. Those are fixed > now. As of May this year, 4Suite's cDomlette was having problems for these users under DEC Alpha running Digital Unix, when dealing with Unicode. I don't know whether those problems have been fixed since; I only know they existed. I've personally never had a problem with cDomlette. If you would like, I can put you in touch with the user directly and he may be able to do some tests for you. Just to follow up, I'll be asking him if he's checked recently, see if he can reproduce it. > > However, I believe that if you can get 4Suite to compile, > > Which I hardly expect to be a problem. Not intended as a slight on 4Suite's stability; I use it regularly and find it quite solid. This was more in reference to the current disclaimer that 4Suite may not always use cDomlette for all platforms; sometimes it falls back to a pure-python solution. > Your memories must be from long ago :-) That API is how it's been for > a while. I think I last used cDomlette last fall or late last summer. At the time, I did not know how to invoke cDomlette directly, but only stumbled across a newspost, when looking for ways to tighten-up parse performance. The post -- probably from a mailing list -- referred me to cDomlette, but I had to go read source code to figure out how to use it. I may well have been stuck on a previous version of 4Suite at the time, too, because my production environment is still on Python 1.5.2. So yes, my personal memories are quite old. I would be misrepresenting if I were to say otherwise. --G. -- Geoff Gerrietts "That's it! I've had it with your sassy mouth! I didn't want to do this! (Well, actually, http://www.gerrietts.net/ I did....)" -- Mojo Jojo, "Bubblevicious" From irmen at -NOSPAM-REMOVETHIS-xs4all.nl Thu Aug 14 13:02:19 2003 From: irmen at -NOSPAM-REMOVETHIS-xs4all.nl (Irmen de Jong) Date: Thu, 14 Aug 2003 19:02:19 +0200 Subject: German umlaut in a string. In-Reply-To: References: Message-ID: <3f3bc09b$0$49098$e4fe514c@news.xs4all.nl> Lukas Kasprowicz wrote: > I tried: > > # _*_ coding: latin1 _*_ > > > but this doesn?t work too. Try # -*- coding: latin1 -*- instead --Irmen From tim.one at comcast.net Mon Aug 18 00:10:08 2003 From: tim.one at comcast.net (Tim Peters) Date: Mon, 18 Aug 2003 00:10:08 -0400 Subject: Py2.3: Feedback on Sets (fwd) In-Reply-To: Message-ID: [Raymond Hettinger] > ... > The real issue with adding a module function or Set method for > powerset is the lack of compelling use cases; without those, it is > simply a cute example for the docs or an ASPN recipe. I agree. > Also, if Tim were to chime-in, I think he would abstract the > problem and say that the algorithm falls in the domain of > combinatorics (for which he has written a module) and that > powersets are just a specific case of transforming a collection > of items into a collection of all possible sub-collections. Chiming. It's more that the use cases for generating powersets demand several ways of generating them: + Lexicographic (if the set elements are totally ordered). + Arbitrary Gray code (minimal change from one subset to the next). + App-specific Gray code (e.g., from one subset to the next, add or remove that specific element that makes the largest-- or smallest --change in the value of a function of the subset). + Any order at all (for apps that can't exploit a stronger guarantee, and want peak generation speed). one-size-doesn't-fit-anybody-ly y'rs - tim From edreamleo at charter.net Fri Aug 29 15:45:36 2003 From: edreamleo at charter.net (Edward K. Ream) Date: Fri, 29 Aug 2003 14:45:36 -0500 Subject: after, after_cancel and Python 2.3 References: Message-ID: > Maybe destroy did not trigger Python garbage collection in 8.3 as expected, > so data could have been erroneously accessible. Thanks for your comments. Note that my app does nothing with Tk data after root.destroy(), so this shouldn't matter. The real mystery seems to be why the "after" routine is being called even after after_cancel. I suppose it is time to start digging into the Tk code... Edward P.S. My comments about the "disgusting" hack in the tkinter after method were dim. The tmp list is the default value of the tmp argument of the callit function, so whether tmp is global or not is irrelevant: changes to tmp will affect later calls to callit. EKR -------------------------------------------------------------------- Edward K. Ream email: edreamleo at charter.net Leo: Literate Editor with Outlines Leo: http://webpages.charter.net/edreamleo/front.html -------------------------------------------------------------------- From eric.brunel at pragmadev.com Mon Aug 11 03:58:02 2003 From: eric.brunel at pragmadev.com (Eric Brunel) Date: Mon, 11 Aug 2003 09:58:02 +0200 Subject: CLI+GUI References: <2259b0e2.0308080948.5a95e383@posting.google.com> <2259b0e2.0308090530.7519f195@posting.google.com> Message-ID: Michele Simionato wrote: > mis6 at pitt.edu (Michele Simionato) wrote in message news:<2259b0e2.0308080948.5a95e383 at posting.google.com>... > >>I wonder what is the recommended way of using Tkinter >>together with a command line oriented application. > > > Replying to myself ... > > I tried to implement what I discussed in my previous mail via the > threading module: > > #cmdriven.py > > import Tkinter as t > import cmd,threading > > root=t.Tk() > s=t.StringVar() > s.set('ciao') > label=t.Label(root,textvariable=s) > label.pack() > > class Cmd(cmd.Cmd): > def do_display(self,arg): > s.set(arg) > def do_quit(self,arg): > root.quit() > return 'quit' # anything <> None will do the job > > def cmdloop(stringvar): > try: Cmd().cmdloop() > finally: pass # gracefully exit if sometimes goes wrong > > thread=threading.Thread(target=cmdloop,args=(s,)) > thread.start() > root.mainloop() > > It works if I do something like > > $ python cmdriven.py > (Cmd) display hello > (Cmd) display It works! > (Cmd) quit > > However, I wonder if this is a robust solution and if I should expect > problems in more complicate situations (some time passes ... I have > just discovered that this script hangs under Windows 98!) I don't know if this is the problem, because you didn't say exactly when the script hangs, but Tkinter apparently has problems when calls to it are made from a thread different from the one into which it was initialized. I'd use an Event between Tkinter's thread and Cmd's thread, checking it regularly with Tkinter's after method. HTH -- - Eric Brunel - PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com From peter at engcorp.com Thu Aug 7 11:10:36 2003 From: peter at engcorp.com (Peter Hansen) Date: Thu, 07 Aug 2003 11:10:36 -0400 Subject: True References: <3F312A65.5312B6EA@engcorp.com> Message-ID: <3F326BEC.9CF89FEC@engcorp.com> Daniel Klein wrote: > > Thanks Peter, that will do the trick. Just wondering though why you > chose to code the opposite values [...] As Skip said... but it should have had a comment anyway, since it wasn't clear. You could also consider using "not not boolVal" if you want to make the code _slightly_ (IMHO) more readable, and slightly slower, but I think one still needs a comment explaining it. :-( -Peter From toxicpulse at sbcglobal.net Sun Aug 3 17:10:20 2003 From: toxicpulse at sbcglobal.net (ryan) Date: Sun, 3 Aug 2003 14:10:20 -0700 Subject: ctypes ques Message-ID: <000e01c35a03$a59b83a0$c8e8a540@nbth9wpsmjuio5> the win32 python extentions don't seem to have "SysParametersInfo()" and i need it to set the wallpaper in windows. cyptes has a "SysParametersInfoA()" function but wont let me use the SPI_SETDESKWALLPAPER attribute. anyone have any ideas how i can set the windows wallpaper from a python program? -ryan -------------- next part -------------- An HTML attachment was scrubbed... URL: From vze4rx4y at verizon.net Sun Aug 17 22:03:26 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Mon, 18 Aug 2003 02:03:26 GMT Subject: What's better about Ruby than Python? References: Message-ID: "Brandon J. Van Every" wrote in message news:bhpbc6$1plpe$1 at ID-203719.news.uni-berlin.de... > What's better about Ruby than Python? I'm sure there's something. What is > it? Code blocks, automatic properties, continuations, and excellent Japanese documentation ;-) Raymond Hettinge From bgailer at alum.rpi.edu Tue Aug 5 10:57:35 2003 From: bgailer at alum.rpi.edu (Bob Gailer) Date: Tue, 05 Aug 2003 08:57:35 -0600 Subject: xrange() question In-Reply-To: Message-ID: <5.2.1.1.0.20030805085558.02b5c800@66.28.54.253> At 02:27 PM 8/5/2003 +0000, George Trojan wrote: >Why do I get an overflow error here: > > > /usr/bin/python >Python 2.2.2 (#1, Feb 24 2003, 19:13:11) >[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-4)] on linux2 >Type "help", "copyright", "credits" or "license" for more information. > >>> import sys > >>> for n, x in zip(range(4), xrange(0, sys.maxint, 2)): >... print n, x >... >Traceback (most recent call last): > File "", line 1, in ? >OverflowError: integer addition > >but not here: > > >>> for n, x in zip(range(8), xrange(0, sys.maxint)): >... print n, x [snip] Consider: >>> for x in xrange(sys.maxint-2,sys.maxint,2):x ... 2147483645 for x in xrange(sys.maxint-1,sys.maxint,2):x ... Traceback (most recent call last): File "", line 1, in ? OverflowError: integer addition Does this give you any clues? Bob Gailer bgailer at alum.rpi.edu 303 442 2625 -------------- next part -------------- --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.506 / Virus Database: 303 - Release Date: 8/1/2003 From mpeuser at web.de Sat Aug 30 03:12:06 2003 From: mpeuser at web.de (Michael Peuser) Date: Sat, 30 Aug 2003 09:12:06 +0200 Subject: My script is taking 12 hours+ any suggestions? References: <3f4ff9f8$0$23588$5a62ac22@freenews.iinet.net.au> Message-ID: "Ideasman" schrieb im Newsbeitrag news:3f4ff9f8$0$23588$5a62ac22 at freenews.iinet.net.au... > Hi I have a made a script that process normals for a flat shaded 3D mesh's. > It compares every vert with every other vert to look for verts that can > share normals and It takes ages. > > I'm not asking anyone to rewrite the script- just have a look for any > stupid errors that might be sucking up time. As has been mentioned the source is not indented - there is no safer way to make Python programs unusable ;-) Looking through it you have *a lot* of evals in loops. Remove that! You should convert your data immediately to a binary internal format while reading from the file (first loop). Kindly Michael P From tim.one at comcast.net Sun Aug 17 01:35:47 2003 From: tim.one at comcast.net (Tim Peters) Date: Sun, 17 Aug 2003 01:35:47 -0400 Subject: bitwise not - not what I expected In-Reply-To: <1YD%a.747879$3C2.17342633@news3.calgary.shaw.ca> Message-ID: [Elaine Jackson] > Is there a function that takes a number with binary numeral a1...an > to the number with binary numeral b1...bn, where each bi is 1 if ai > is 0, and vice versa? (For example, the function's value at 18 > [binary 10010] would be 13 [binary 01101].) I thought this was what > the tilde operator (~) did, Surprise: that is what ~ does. > but when I went to try it I found out that wasn't the case. Please give a specific example. To understand your example above, note that binary 10010 actually has an unbounded number of 0 bits "to the left": ...00000010010 = 13 The bitwise inversion of that therefore has an unbounded number of 1 bits "to the left": ...11111101101 = -19 This is why you get -19: >>> n = 18 >>> ~n -19 >>> Any answer other than that is wishing away the 0 bits at the left in the input. Python can't *guess* how many bits you want to keep. If you only want to keep the rightmost 5 bits, then explicitly mask off the rightmost 5 bits: >>> (~18) & 0x1f 13 >>> So that's the 13 "you expected". > I discovered by experiment (and verified by looking at the > documentation) that the tilde operator takes n to -(n+1). I can't > imagine what that has to do with binary numerals. Can anyone > shed some light on that? Python represents negative integers in unbounded 2's-complement form (well, it doesn't really under the covers, but it maintains the illusion of doing so in all arithmetic and logical operators). The 2's-complement of an integer is equal to 1 plus its 1's-complement form, and 1's-complement is identical to bitwise inversion. So -n = 1 + (~n) Then ~n = -(n+1) follows from that via rearrangement. > (In case you're curious, I'm writing a script that will play Nim, > just as a way of familiarizing myself with bitwise operators. Good > thing, too: I thought I understood them, but apparently I don't.) You're only overlooking the consequences of an infinite amount of information . From electricity at uymail.com Mon Aug 25 10:41:09 2003 From: electricity at uymail.com (U. N. Owen) Date: Mon, 25 Aug 2003 16:41:09 +0200 Subject: Coloring print lines Message-ID: <20030825144109.28298.qmail@uymail.com> You can use Ansi escape sequences, look at http://www.termsys.demon.co.uk/vtansi.htm (color attributes at the bottom of the page) and the manuals at http://vt100.net/ You can try "vt100 ansi escape sequences" with google, too... Please note that this should work on any Linux or Unix (including MacOS X), or in MS-DOS if you have ansi.sys installed in config.sys. I don't know if it will work in Windows. And sometimes it depends on the function used to print on screen (I remember that under DOS not both printf and cprintf worked in C). I just tried with print "\033[35m" under linux/debian, and it seems ok. 'hope it helps... -- _______________________________________________ Get your free email from http://www.uymail.com Powered by Outblaze From uche at ogbuji.net Fri Aug 15 09:24:02 2003 From: uche at ogbuji.net (Uche Ogbuji) Date: 15 Aug 2003 06:24:02 -0700 Subject: resolving relative paths for external entities with xml.sax References: Message-ID: Bart wrote in message news:... > Dear python XML'ers, > > I have a set of XML documents that use external entity definitions for > which I am having problems parsing them using python and xml.sax. The > problem is with the resolution of relative paths in these. > An example: > > dir1/test.xml: > > > &ent; > > dir2/test.dtd: > > > > dir2/test.inc: > external entity test > > From what I understand of XML specs, relative paths in external entities > are relative to the location of the document *in which they are defined*. > However, using xml.sax (which calls expat, I presume), the paths are > resolved relative to the current working directory. So the parser can not > find the test.inc when the current working directory is e.g. dir1. > > I do not see how creating an EntityResolver would help here: how do I > know against what base path I have to resolve the entity? > > (the same thing can be read without problems with other xml parser, for > instance in Java). I, for one, need to see your Python code to tell, because if you're using the APIs rightly parsing the first file as a URI rather than, say, reading it in as a string first), then you should not have the problem you report. --Uche http://uche.ogbuji.net From csv610 at yahoo.com Thu Aug 28 19:18:29 2003 From: csv610 at yahoo.com (Chaman Singh Verma) Date: 28 Aug 2003 16:18:29 -0700 Subject: Garbage Collection Question Message-ID: <2ce55ce2.0308281518.4be94efc@posting.google.com> Hello, I am trying to integrate C++ with Python. I read that Python does automatic garbage collection. I am creating new objects in C++ and passing to Python, I don't know now who should control deleting the objects. If I create objects in C++ do I have to clean them or Python will use GC to remove unwanted objects. Bye. csv From hanzspam at yahoo.com.au Tue Aug 26 10:42:10 2003 From: hanzspam at yahoo.com.au (=?ISO-8859-1?Q?Hannu_Kankaanp=E4=E4?=) Date: 26 Aug 2003 07:42:10 -0700 Subject: macro FAQ References: <840592e1.0308251252.74382e29@posting.google.com> Message-ID: <840592e1.0308260642.f8fd566@posting.google.com> Jacek Generowicz wrote in message news:... > hanzspam at yahoo.com.au (Hannu Kankaanp??) writes: > > Obviously this was quite unsatisfactory. I ended up > > putting the axis code in a separate class > > Do you mean "function" rather than "class" ? Actually, I did mean class. Normally I'd have class Widget: def __init__(self): self.x = 0 self.y = 0 self.width = 0 self.height = 0 def getWidth(self): return self.width # normally they wouldn't be this empty! def getHeight(self): return self.height But by wrapping it inside a new class, I could get rid of the duplication (partly, at least): class Widget: def __init__(self): self.x = Widget.Axis(0, 0) self.y = Widget.Axis(0, 0) class Axis: def __init__(self, pos, size) self.pos = pos self.size = size def getSize(self): # this is only once here now return self.size While this tiny example doesn't show decrease in code size, it shows that I have a common definition for all "Axis"-specific code inside the appropriate Axis class. Rest of the Widget methods would be in the widget class. Thus self.x.getSize() instead of self.getWidth(). > > so I could > > use them interchangeably. I.e. If I passed > > func(self.y, self.x) > > and then > > func(self.x, self.y) > > > > I would get the same effect on both axises. But this > > would've been an excellent place for macros IMO > > I don't see what you gain by using a macro, wrt to using a function in > _this_ case. Ok, it was a bad example. I hope the code above shows a bit more clearly what I wanted. Anyway, without the code in the axis-class, I would've had to often say self.x = func(self.x, self.y, self.width, self.height) self.y = func(self.y, self.x, self.height, self.width) Instead of func(self.x, self.y) func(self.y, self.x) Which could modify the axis-specific stuff within the func()tion. (self.x is no longer a non-modifiable number, but a modifiable class) > So you would not only replace whole symbols, but even fragments of > symbols (getSize -> getHeight), and thus macically/implicitly create > new symbols. Many people consider this bad practice. Well, I don't, really. Like any macro that could do something weird, it just needs to be properly understood by anyone who wishes to read the code. > Incidentally, in this case, having a string based code representation > would make your job much easier than the structured representation > which Lisp uses. In a string you'd merely do a search and replace; in > an s-expression you would have to recursively search for all symbols > in all sub-expressions, and then do the search and replace within the > name of each symbol you find. Well, such a recursive search isn't a problem - With help from a macro ;) > > This way, I could've got no duplicated code but > > also a more intuitive interface than I currently have > > (to get width, one needs to type obj.x.getSize() instead > > of obj.getWidth()). And it's obvious this kind of "defBoth" > > wouldn't be added as a language level construct -- Thus > > macros are the only good solution. > > Cue metaclass solution ... :-) How could metaclasses help? I'm quite inexperienced with them. Anyway, if I take the eval route, I might as well do defBoth('''getSize(): return size''') ,retreive appropriate locals() from the stack and modify it to include the new functions. I'd rather not, though :-) From robin at jessikat.fsnet.co.uk Wed Aug 20 04:12:14 2003 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Wed, 20 Aug 2003 09:12:14 +0100 Subject: Unification of logging in Python's Standard Library References: <3a8e83d2.0308182217.7ccaf883@posting.google.com> <3a8e83d2.0308191655.7a82881b@posting.google.com> Message-ID: In article , John Roth writes > >"Matthew Barnes" wrote in message >news:3a8e83d2.0308191655.7a82881b at posting.google.com... > >> I will say that unittest is what motivated me to suggest this in the >> first place, since I'm working on a testing framework that is >> attempting to take advantage of both the unittest *and* logging >> modules. Perhaps a new TestRunner class that uses logging >> (LoggingTestRunner?) might coexist with the default TextTestRunner. > >Perhaps you could tell us a bit more about this? My usage of >unittest is (relatively) pure XP/TDD - I expect all of the tests >to pass except the last one I worked on, and when they don't, >I swat it immediately. Consequently, I don't see any need for >logging anything. > >John Roth > >> >> Matt > > We currently have cgi scripts that implement logging by wrapping a dispatch function. We test everything before going live, nevertheless we still get errors in production and the logging is then invaluable. A typical case is that of inconsistencies accidentally introduced into the back end data base which the end users control; this is not exactly our error, but it causes failures in our code. On a different point we have different logging for testing in our office and on the client's staging, testing and production machines. Typically we use files for simple testing, but on the client production machines we have a single database which collects all the errors from several web facing servers. This requires that our code recognise its location (we use presence of files called LIVE etc) and I wonder how other people handle this terrain recognition problem? -- Robin Becker From oren-py-l at hishome.net Thu Aug 7 15:23:13 2003 From: oren-py-l at hishome.net (Oren Tirosh) Date: Thu, 7 Aug 2003 15:23:13 -0400 Subject: crossplatform py2exe - would it be useful? In-Reply-To: References: Message-ID: <20030807192313.GA82545@hishome.net> On Thu, Aug 07, 2003 at 02:46:24PM +0200, Thomas Heller wrote: > Alex Martelli writes: > > > Oren Tirosh wrote: > > > >> On Wed, Aug 06, 2003 at 08:36:20PM +0200, Thomas Heller wrote: > >>> I'm currently working on a new version of py2exe, which will require > >>> Python 2.3 and later, because it uses the zipimport mechanism. > >> > >> Now that zipimport is part of Python the code required for bootstrapping > >> a py2exe runtime is just: > >> > >> myscript -c "import sys; sys.path.insert(0, sys.executable); import foo" > >> > >> This reduces the difference between the custom interpreter supplied with > >> py2exe and the standard interpreter to just a few lines of C. > >> > >> The obvious question is - why not go all the way and put this little > >> hook into the standard Python distribution? This way py2exe could be a > >> platform-independent pure Python application. In fact, py2exe wouldn't > >> actually be necessary because anyone could create a zip file manually and > >> append it to the executable but it's more convenient to have a tool that > >> automates the process and finds the required dependencies. > > > > Sounds like a good idea to me, if a sensible name is chosen for the > > "main module" (I propose 'main':-). > > My choice would have been __main__ :-) Is it really the correct way to > 'import __main__' instead of 'running' it? You can't import __main__ - you'll get the one already in sys.modules. The code for the main script needs to be executed in __main__'s dict. Guido might not like it if the interpreter always attempted to open its executable image file to check for an appended zip. It could cause problems on some obscure environments. A possible alternative would be to have a configuration area inside the executable that can be modified by an external program (e.g. py2exe). The program would search for a signature string and modify the section after it. The configuration area can be as simple as a string that overrides the command line arguments. Oren From gh at ghaering.de Wed Aug 27 12:11:17 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Wed, 27 Aug 2003 18:11:17 +0200 Subject: Celebrity advice In-Reply-To: <3F4CD2A2.DE7D05D2@engcorp.com> References: <3F4CD2A2.DE7D05D2@engcorp.com> Message-ID: <3F4CD825.6040105@ghaering.de> Peter Hansen wrote: > Terry Reedy wrote: > >>(I think it safe to say that during the 20th century, 99% of the 100s of >>millions of murders were committed by armed govern-men rather than by >>private persons acting alone.) > > It may be safe to say it, but is it true, or merely hyperbole? > > Were there "100s of millions of murders" in the 20th century, assuming > commonplace definitions of "murder" (killing humans), "million" > (10 to the 6th power), and "20th century" (period beginning roughly > January 1, 1900 and ending on or one year before December 31, 2000)? > > That's a lot of people getting themselves killed, whatever the cause... Here's a page with exactly this topic: http://users.erols.com/mwhite28/warstat1.htm I seem to remember that during World War II alone 50 million people died because of the war. Not necessarily with weapons, because for example the Germans invented more efficient ways of mass murder :-( And that number probably includes indirect deaths caused by famine, etc. -- Gerhard From vze4rx4y at verizon.net Sat Aug 2 08:41:19 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Sat, 02 Aug 2003 12:41:19 GMT Subject: Dict to "flat" list of (key,value) References: Message-ID: "Nicolas Girard" wrote in message news:pan.2003.07.30.19.26.18.41642 at removethis.nerim.net... > Hi, > > Forgive me if the answer is trivial, but could you tell me how to achieve > the following: > > {k1:[v1,v2],k2:v3,...} --> [[k1,v1],[k1,v2],[k2,v3],...] > > The subtle point (at least to me) is to "flatten" values that are lists. The other posters answered the question (as asked) by showing a loop that differentiated the two cases of inner lists vs single values. One further thought, is that the original data structure could be improved by building it so that every value is in a list: {k1:[v1,v2],k2:[v3],...} This is typically done by building the values with setdefault: index = {} for pagenum in range(len(pages)): page = pages[pagenum] for word in page: index.setdefault(word, []).append(pagenum) The new structure is much more easily flattened: [(k,v) for k, values in newstruct.iteritems() for v in values] it-all-starts-with-a-good-data-structure-ly yours, Raymond Hettinger From egosum at xs4all.nl Mon Aug 18 17:03:27 2003 From: egosum at xs4all.nl (Henk Burgstra) Date: Mon, 18 Aug 2003 23:03:27 +0200 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: Message-ID: On Mon, 18 Aug 2003 12:20:50 -0600, Andrew Dalke wrote: > > And this sort of post is making your troll mark almost indelible. > Brandon is not a troll. He is very serious in his quest to find a good 'alternative' language. Look him up on Google. Regards, Henk Burgstra From udo.gleich at web.de Fri Aug 1 04:23:51 2003 From: udo.gleich at web.de (Udo Gleich) Date: Fri, 01 Aug 2003 10:23:51 +0200 Subject: anti-aliased 2D vector graphics References: Message-ID: <3F2A2397.CB323180@web.de> Hi, pygame (www.pygame.org) can at least draw antialiased lines. Look for the draw module in the documentation. Udo From vze4rx4y at verizon.net Fri Aug 8 12:35:02 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Fri, 08 Aug 2003 16:35:02 GMT Subject: random changes References: <3f33b345$1_6@corp.newsgroups.com> Message-ID: "Chris Reedy" > It appears that the numbers for random.random() are identical, however, > the numbers for normalvariate (and also lognormvariate, betavariate, > weibullvariate, and paretovariate) are different The underlying random number generator is the same but the formulas for producing the variates were each changed a bit so they could handle the full range of possible inputs (i.e. handling a random() float exactly equal to zero). The OP's original concern was traced back to a change between Py2.0 and Py2.1 where the WichmannHill seed routine was improved (doubling the key space and reducing duplicate states generated from different seeds). The whseed() method was what he needed for backwards compatibility. Raymond Hettinger From mhammond at skippinet.com.au Tue Aug 5 22:53:15 2003 From: mhammond at skippinet.com.au (Mark Hammond) Date: Wed, 06 Aug 2003 12:53:15 +1000 Subject: Fatal Python error: unknown scope for... In-Reply-To: References: <1hpgt2ltmkd5a$.dlg@baczek.net.invalid> Message-ID: Jeff Epler wrote: > Confirmed in a local build (from CVS?), "Python 2.3b1 (#16, May 19 2003, > 10:22:28)". I would swear this was discussed at some point, so there's > a small chance it was fixed in 2.3. In any case, it's only happening in > the presence of another (syntax) error so it's not as bad as it could be > (but still bad for eg "restricted execution" environments, which 2.3 > tells us don't work anyway) > > The following program shows a similar error (it's about the simplest > program I could devise with the problem): > def g(a=None, b, c=lambda: None): g > """Fatal Python error: unknown scope for g in g(1) in marek.py""" Yep, I still get this with current CVS Python. You should open a bug. Mark. From mis6 at pitt.edu Thu Aug 7 18:54:33 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 7 Aug 2003 15:54:33 -0700 Subject: Bug? If not, how to work around it? References: <2259b0e2.0308070919.2bedce6@posting.google.com> Message-ID: <2259b0e2.0308071454.1f2869aa@posting.google.com> Alex Martelli wrote in message news:... > "__getattr__ is skipped" is false (the > __getattr__ a *metaclass* could define would indeed be used as > equivalent to the class defining methods) -- the _class_'s __getattr__ > if any is irrelevant because it's used on class *instances* (as > the language reference also says a few pages later) and thus it's > not the *CLASS* that's defining "methods with special names" here. > Alex, did you look at the thread I mentioned? Here is the problem with __getattr__ in metaclasses for special methods (quoting from that thread). """ defining __len__ on the class does not work: class M(type): def __getattr__(self,name): if name=='__len__': return lambda self:0 class F: __metaclass__=M >>> f=F() >>> F.__len__(f) # okay 0 >>> len(f) # TypeError: len() of unsized object f.__len__() # AttributeError: 'F' object has no attribute '__len__' As you see, the problem is that len(x) is not calling x.__len__(), nor x.__class__.__len__(x); I really would like to know how ``len`` (or ``str``, ``repr``, etc.) work. """ If you remember, Bjorn Pettersen reported this (or something similar) months ago. I am saying that this behaviour is not documented, at least AFAIK. Michele From __peter__ at web.de Mon Aug 25 03:18:28 2003 From: __peter__ at web.de (Peter Otten) Date: Mon, 25 Aug 2003 09:18:28 +0200 Subject: Strange tab problem! References: Message-ID: tjland at iserv.net wrote: > for x in title_author.keys(): > print "Book: ",x," \tAuthor: ",title_author[x]," > \tCopyright:",title_copyright[x] > > it seems that whenever i go over six characters it adds another tab. Is > there a preset field limit to six bytes. What is happening? Thanx in > advance. Note that Python inserts a space between the arguments of a print statement. So you *always* get (replacing space with "S" and tab with "T") "Book:SSxSS(book title):SSTAuthor:SS(author name)TCopyright:S(year)" 123456789a(book title)123 How this is displayed, depends on your editor settings. Assuming 1 tab == 8 spaces: "Tb" -> "SSSSSSSSb" "1Tb" -> "1SSSSSSSb" "12Tb" -> "12SSSSSSb" ... "1234567Tb" -> "1234567Sb" "12345678Tb" -> "12345678SSSSSSSSb" So every time you reach the 8 character limit, another tab appears to be (but is not!) inserted. Solution: (1) do not use tabs, and (2) calculate column widths before printing title_author = {"For whom the bell tolls": "Hemingway", "Zauberberg": "Mann"} title_copyright = {"For whom the bell tolls": 1234, "Zauberberg": 123} titleWidth = max(map(len, title_author.keys())) authorWidth = max(map(len, title_author.values())) copyrightWidth = max(map(lambda y: len(str(y)), title_copyright.values())) for title in title_author.keys(): ptitle = title.ljust(titleWidth) pauthor = title_author[title].ljust(authorWidth) pcopyright = str(title_copyright[title]).rjust(copyrightWidth) print "Book:", ptitle, "Author:", pauthor, "Copyright", pcopyright The generalization for arbitrary tables (and finding out the samples' years of publication) is left as an exercise to the OP :-) Peter From elainejackson7355 at home.com Wed Aug 13 02:06:18 2003 From: elainejackson7355 at home.com (Elaine Jackson) Date: Wed, 13 Aug 2003 06:06:18 GMT Subject: two quick questions Message-ID: Two quick newbie questions: 1) Does Python have passing-by-reference? 2) In ordinary parlance, "deep" implies "shallow" but not conversely. In the Python "copy" module (if I understand correctly), the implication goes the other way. Do you find this a nuisance? Peace, EJ From op73418 at mail.telepac.pt Sun Aug 31 19:23:43 2003 From: op73418 at mail.telepac.pt (Gonçalo Rodrigues) Date: Mon, 01 Sep 2003 00:23:43 +0100 Subject: exception question References: Message-ID: <6p05lvo8b2fkqolt5j7jo2p3ejpvldgcbh@4ax.com> On Mon, 01 Sep 2003 00:14:13 +0200, Peter Otten <__peter__ at web.de> wrote: >Gon?alo Rodrigues wrote: > >> For error processing I found convenient maintaining a dictionary where >> the keys are exception *classes* and the values are callables. Of >> course, for this to work, exception classes have to be hashable which >> I happily found that they were. So my question is, can I count on this >> behaviour? Or is this behaviour I should not count on? (I found >> nothing on the docs about it, thus the question). > >(No answer to your question) > >import sys > >class MyException(Exception): > def __init__(self, msg, handler): > Exception.__init__(self, msg) > self.handler = handler > >try: > raise MyException("yup", lambda: sys.stdout.write("call it sleep\n")) >except MyException, e: > e.handler() > >Would that eliminate the need for a dictionary? Yup, I did though of of a scheme like that before -- It's my fall back solution in case I should not count on the fact that exception classes are hashable. Thanks anyway, G. Rodrigues From newsgroups at jhrothjr.com Wed Aug 6 07:33:09 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Wed, 6 Aug 2003 07:33:09 -0400 Subject: converting an integer to a string References: Message-ID: "Skip Montanaro" wrote in message news:mailman.1060139050.10265.python-list at python.org... > > Ken> I have a quick simple question. How do you convert an integer to a > Ken> string in Python? > > Take your pick: > > str(someint) > repr(someint) > `someint` > '%d' % someint > > Which is most appropriate may well depend on your tastes and your context. > `someint` is just syntactic sugar for repr(someint), and is falling out of > favor with many people. In the case of integers, str(someint) and > repr(someint) are the same, so your choice there is a tossup unless you are > str()'ing or repr()'ing other objects as well (str() generally tries to be > "readable", repr() generally tries to be "parseable"). For most types > repr() and str() generate different output. The experiment is probably > educational enough to perform once, so I won't go into detail. > > The %-format version is appropriate if you want to embed it into a larger > string, e.g.: > > '%s is %d years old' % (person, age) > > Don't forget the dict form as well: > > '%(name)s is %(age)d years old' % locals() The % format also allows you some formatting options that the others don't. John Roth > > Skip > From PieterB+news at gewis.nl Mon Aug 25 12:05:45 2003 From: PieterB+news at gewis.nl (PieterB) Date: Mon, 25 Aug 2003 18:05:45 +0200 Subject: Common tasks in python Message-ID: I noticed the URL http://starship.python.net/~da/commontasks/ gives a 404 ERROR. That page is quite usefull. It's still in Google's Cache BTW, http://www.google.com/search?sourceid=navclient&ie=UTF-8&oe=UTF-8&q=site:starship%2Epython%2Enet+commontasks I something wrong with the starship, or is the page removed? PieterB -- http://zwiki.org/PieterB From graham__fawcett at hotmail.com Mon Aug 11 14:58:24 2003 From: graham__fawcett at hotmail.com (Graham Fawcett) Date: 11 Aug 2003 11:58:24 -0700 Subject: Slogan: Getting Rich Overnight References: Message-ID: "val" wrote in message news:... > A standard GUI is a great concept, but it has a fixed > structure which may become a highly complicated for real-world apps. > A well-designed CL actually splits a potentially huge GUI into > manageable and app-specific "time slices" (CL+GUI) driven by the > current output of the app. [snip] > So, business objects' power under user fingertips seems to be a > powerful concept, indeed. In fact, a living organism' functionality > in an environment is split similarly into stimuli (inputs) and responses > (outputs); an output, in turn, can represent a (pre-specified) > sequence of responses potentially modifiable by the environment > (user inputs). This suggests another slogan for Python... "Python: stimulate powerful organisms under your fingertips, without all the GUI mess!" With apologies to the prudent, -- Graham From mwh at python.net Tue Aug 26 09:49:00 2003 From: mwh at python.net (Michael Hudson) Date: Tue, 26 Aug 2003 13:49:00 GMT Subject: Listening to keyboard input? References: Message-ID: <7h3r838zg4c.fsf@pc150.maths.bris.ac.uk> tjland at iserv.net writes: > Can python monitor keyboard input for lets say i want to have my program > return to the main menu when the user hits escape! Can python do this or > am i going to have to embed some c++ program into it? Thanx Um, probably. Questions like what platform you're on become relavent. If Unix, look at termios, os.read, etc. Or just use curses. On windows, I'm told that the msvcrt module is useful but I don't use windows & wouldn't really know. Punctuation is nice. More please. Cheers, mwh -- how am I expected to quit smoking if I have to deal with NT every day -- Ben Raia From whanlon at cosmic.utah.edu Mon Aug 4 14:34:16 2003 From: whanlon at cosmic.utah.edu (William Hanlon) Date: Mon, 04 Aug 2003 12:34:16 -0600 Subject: member array in c passed to python? Message-ID: Hi, I would like to use the Python C API to use python to access functions originally written in C. The objects that I would like to pass to python have multi-dimensional arrays. How do I include arrays as object member? And how is it declared in the PyMemberDef array? If you can not use C arrays, I thought perhaps then I should use Python tuples or lists, but I don't see how to fill the tuple from the multi-dimensional arrays. Does anyone have an example of this? Thanks, William Hanlon From abuseonly at sgrail.org Fri Aug 22 01:37:38 2003 From: abuseonly at sgrail.org (derek / nul) Date: Fri, 22 Aug 2003 05:37:38 GMT Subject: Newbie problem with codecs References: <1R01b.1724$Ej6.454@newsread4.news.pas.earthlink.net> Message-ID: On Thu, 21 Aug 2003 10:06:53 GMT, "Andrew Dalke" wrote: >Still, this might help. Suppose you wanted to read from a utf-16-le >encoded file and write to a utf-8 encoded file. You can do Very close, I want to read a utf16le into memory, convert to text, change 100 lines in the file, convert back to utf16le and write back to disk. >The other options is to do the conversion through strings >instead of through files. > ># s = "....some set of bytes with your utf-16 in it .." >s = open("input.utf16", "rb").read() # the whole file > ># convert to unicode, given the encoding >t = unicode(s, "utf-16-le") > ># convert to utf-8 encoding >s2 = t.encode("utf-8") > >open("output.utf8", "rb").write(s2) My code so far ------------------------------------------- import codecs codecs.lookup("utf-16-le") eng_file = open("c:/program files/microsoft games/train simulator/trains/trainset/dash9/dash9.eng", "rb").read() # read the whole file t = unicode(eng_file, "utf-16-le") print t ----------------------------------------------------- The print fails (as expected) with a non printing char '\ufeff' which is of course the BOM. Is there a nice way to strip off the BOM? The line where the conversion to utf8 is, I would like to convert to text but I cannot find a built in command. Many thanks so far From bhahn at spam-spam.g0-away.com Fri Aug 1 16:35:19 2003 From: bhahn at spam-spam.g0-away.com (Brendan Hahn) Date: Fri, 01 Aug 2003 20:35:19 GMT Subject: Interfaces (a la PEP 245 and Zope) References: <78ednTw5QfxmebSiXTWJhA@august.net> <7ZqcnQyRd83mV7eiXTWJkw@august.net> Message-ID: Terry Hancock wrote: >Brendan Hahn wrote: >> How about an Interface metaclass that replaces any class methods with an >> appropriate exception-raiser. [...] >Well Zope's (or should I say Jim Fulton's?) Interface module >defines an object with a number of useful documentation and >validation behaviors. I haven't checked out the Zope stuff...that just popped into my head as a slightly easier way to implement Heiko's suggestion. You could use it as a way to generate base classes that enforce the required-implementation aspect of interfaces (maybe call it 'Abstract') and also inherit from other sources to provide validation and such. -- brendan DOT hahn AT hp DOT com From __peter__ at web.de Fri Aug 29 09:38:06 2003 From: __peter__ at web.de (Peter Otten) Date: Fri, 29 Aug 2003 15:38:06 +0200 Subject: howto format currency string? References: <8oH3b.15528$d66.362183@news2.tin.it> Message-ID: Alex Martelli wrote: >>>> import locale >>>> locale.setlocale(locale.LC_ALL,('en','ascii')) > 'en_US.ISO8859-1' Python 2.3 (#1, Jul 30 2003, 11:19:43) [GCC 3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import locale >>> locale.setlocale(locale.LC_ALL, ('de', None)) 'de_DE.ISO8859-1' It works :-) And I always trusted the documentation/error message: >>> locale.setlocale(locale.LC_ALL, 'de') Traceback (most recent call last): File "", line 1, in ? File "locale.py", line 381, in setlocale return _setlocale(category, locale) locale.Error: locale setting not supported >>> The second (not working) variant is taken directly from the documentation. The error message led me to assume that my version of Python didn't support locale setting at all. Maybe I should file a bug report? Peter From bdesth.nospam at removeme.free.fr Tue Aug 19 15:13:31 2003 From: bdesth.nospam at removeme.free.fr (Bruno Desthuilliers) Date: Tue, 19 Aug 2003 21:13:31 +0200 Subject: What's TOTALLY COMPELLING about Ruby over Python? In-Reply-To: References: <3F412484.69867AED@alcyone.com> <3f415560$0$1124$626a54ce@news.free.fr> <3f4216a3$0$16514$626a54ce@news.free.fr> Message-ID: <3f4274ab$0$16554$626a54ce@news.free.fr> Jarek Zgoda wrote: > Bruno Desthuilliers pisze: > > >>>I am not a clp regular (mostly a lurker), but I also wanna play. *please* >>> >>>;-). >>> >> >>Easy : answer to any post from Brandon, singing 'Brandon is a troll, is >>a troll, is a troll' !-) > > > Ugh, I cann't... I cann't see his posts, I accidentally pressed 'k' > while reading some of his writings, than accidentally few times pressed > "Enter" followed by "y" key -- of course by accident... > > Too bad an accident !-) From tzot at sil-tec.gr Mon Aug 25 03:50:08 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Mon, 25 Aug 2003 10:50:08 +0300 Subject: How to import a standard module in source file with same name? References: <420ced91.0308232052.70e905d5@posting.google.com> <420ced91.0308241017.1b5e2a4f@posting.google.com> Message-ID: On 24 Aug 2003 11:17:13 -0700, rumours say that sdhyok at yahoo.com (sdhyok) might have written: >In addition, you can't import the standard datetime with the following >script in vp/datetime.py. > >Daehyok > > >> import datetime >> import vp.datetime >> vp.datetime.datetime = datetime Like I said (including the sentence before the code), >>Or you can do (in the importing module, >>possibly your main program): >> >>import datetime >>import vp.datetime >>vp.datetime.datetime = datetime Obviously I wasn't clear. If module A imports vp.datetime, then the code above should be entered in your A module. For this to work, vp.datetime should just define functions and/or classes (since there would be no vp.datetime.datetime attribute while vp.datetime is imported). This all is theoretical since you agreed with Michael Peuser that having a module with the same name as one of the standard library is not "elegant". -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From news at exultants.org Sun Aug 24 01:40:50 2003 From: news at exultants.org (Van Gale) Date: Sun, 24 Aug 2003 05:40:50 GMT Subject: mpich python? Message-ID: Debian Weekly News lists a new package they call mpichpython, which is described as "MPI enhanced python interpreter". I would have presumed it is an interface to the MPICH API but can't find anything about it on google and "MPI enhanced interpreter" sounds like something different. Anyone know what this is about? Van From ngps at netmemetic.com Fri Aug 1 04:08:45 2003 From: ngps at netmemetic.com (Ng Pheng Siong) Date: 1 Aug 2003 08:08:45 GMT Subject: urllib(2) and https blues? try pytunnel for python tunnelling References: Message-ID: According to john : > The python libraries like urllib and httplib do not support ssl > through a proxy. > Urllib2 supports http through a proxy or https alone, but not https > through a proxy. M2Crypto's contrib/ contains an isaac.httpslib.py, with the following blurb: This is Isaac Salzberg's application of Mihai Ibanescu's patch (available on SF) that allows HTTPS tunneling through an authenticating proxy. This one's a double whammy: it works with IIS through the authenticating proxy, whereas the one on SF, which uses Python's built-in SSL, doesn't. This code is not folded into the main distribution because: 1. Apparently Mihai is still working on it. 2. Mihai uses Python's built-in SSL. Isaac patched it to use M2Crypto.SSL. The stuff is essentially #ifdef'ed code. 3. I don't have an authenticating proxy nor an IIS server to test against, so I can't clean up the code. Volunteers welcome. ;-) Thanks Isaac. -- Ng Pheng Siong http://firewall.rulemaker.net -+- Manage Your Firewall Rulebase Changes http://www.post1.com/home/ngps -+- Open Source Python Crypto & SSL From gh at ghaering.de Fri Aug 22 17:04:21 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Fri, 22 Aug 2003 23:04:21 +0200 Subject: for iteration In-Reply-To: <3F46040E.8000208@gemplus.com> References: <3F46040E.8000208@gemplus.com> Message-ID: <3F468555.3000800@ghaering.de> Franck Bui-Huu wrote: > Hello, > > I'm trying to customize a list by overriding __getitem__ method but > this change seems to not work with for iteration. > When I use my customized list in a for iteration, all changes made > in __getitem__ are not take into account. > How can I modify this behaviour ? To make iteration via "for" possible, the recommended way is to implement the iterator protocol in your object, i. e. the object itself has a method "__iter__(self)" that will return an iterator object. Usually the iterator object is the object itself! The iterator object has one method, called "__next__(self)" that will return the next object or raise StopIteration when there are no further objects. For your particular problem, though, please post code to show it. -- Gerhard From ryanlowe0 at msn.com Sun Aug 24 21:01:52 2003 From: ryanlowe0 at msn.com (Ryan Lowe) Date: Mon, 25 Aug 2003 01:01:52 GMT Subject: python gripes survey References: <2a82921f.0308241641.5bf82d6d@posting.google.com> Message-ID: <4ed2b.184002$_R5.68976096@news4.srv.hcvlny.cv.net> "Patrick Lioi" wrote in message news:2a82921f.0308241641.5bf82d6d at posting.google.com... > I would like to see a shorthand for list.append(), borrowed from PHP: > > foo = [1, 2, 3] > foo[] = 4 # foo now equals [1, 2, 3, 4] well, you can just concatenate a list like this: >>> foo += [4] the meaning of this is even clearer i think. > I would also like to see what would probably end up being called > "generator comprehensions". That is definitely not my own idea, but > for the life of me I can't remember where I first heard about it. > Imagine being able to throw the yield keyword into a list > comprehension syntax in order to take advantage of list > comprehension's in a memory-efficient way, something kinda like this: > > foo = [yield i*i for i in xrange(100)] i like this idea too. someone wrote a PEP for it: http://www.python.org/peps/pep-0289.html but alas it was rejected, like so many good ideas 'round here ;^) From jepler at unpythonic.net Tue Aug 19 17:30:23 2003 From: jepler at unpythonic.net (Jeff Epler) Date: Tue, 19 Aug 2003 16:30:23 -0500 Subject: Why does this (not) work? In-Reply-To: References: Message-ID: <20030819213023.GT16941@unpythonic.net> try this: >>> "%s - %s - %s" % (("test",)*3) why else would >>> 3 % 1 * 2 print 0 instead of 1? Jeff From cookedm+news at physics.mcmaster.ca Sun Aug 10 21:18:13 2003 From: cookedm+news at physics.mcmaster.ca (David M. Cooke) Date: Sun, 10 Aug 2003 21:18:13 -0400 Subject: How to print floating point in scientific format? References: <420ced91.0308081115.7060e551@posting.google.com> <420ced91.0308101127.644f9813@posting.google.com> <_%zZa.37775$an6.1321077@news1.tin.it> Message-ID: At some point, Alex Martelli wrote: > sdhyok wrote: > >> As you recommend, I won't modify the default behavior of python. >> But, still I need a better treatment of python on arrays. > > You seem to be focused on readable display of arrays (quite an > unusual focus for scientific programming). So, worst case, it's trivial > to write a general purpose function that takes an array of ANY size > and rank and emits it in the way you prefer -- easier than in any > other language commonly used for scientific programming. With Numeric at least, you can set globally the functions used for str() and repr() on arrays, giving exactly this, without requiring a separate function for representations. Have a look at Numeric.py, multiarray.set_string_function(), and ArrayPrinter.py from the Numeric distribution. The simple way of controlling output with Numeric is to use the variables sys.output_line_width, sys.float_output_precision and sys.float_output_supress_small (if true, replace in the output numbers that are much smaller than the rest with zero, which is very nice when most of your numbers are 1.0, and you've got some annoying 1.8342e-17 that you want to ignore). These are added by Numeric to the sys module. With numarray, you could subclass the array object, write your own __str__ and __repr__ methods, and use that instead. -- |>|\/|< /--------------------------------------------------------------------------\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca From pobrien at orbtech.com Thu Aug 28 21:26:41 2003 From: pobrien at orbtech.com (Patrick K. O'Brien) Date: 28 Aug 2003 20:26:41 -0500 Subject: Object Database (ODBMS) for Python References: <1DAECE9E8F34E04AA0E5699AF7D9FF090708D440@stpmsg00.corp.fairisaac.com> Message-ID: pobrien at orbtech.com (Patrick K. O'Brien) writes: > pobrien at orbtech.com (Patrick K. O'Brien) writes: > > > I hope that helps demonstrate some of what it can do. > > I forgot to show a cool feature: Here's another: >>> u1.name 'Bob' >>> u1.name = 'Joe' Traceback (most recent call last): File "", line 1, in ? File "/home/pobrien/Code/pypersyst/entity/entity.py", line 94, in __setattr__ raise AttributeError, 'Modifications can only be made by transactions' AttributeError: Modifications can only be made by transactions So, let's use a transaction: >>> t = tx.Update(u1, name='Joe') >>> db.execute(t) >>> u1.name 'Joe' >>> Of course, nobody is perfect. So what happens when we send a bad transaction: >>> t = tx.Update(u1, foo='Joe') >>> db.execute(t) Traceback (most recent call last): File "", line 1, in ? File "/home/pobrien/Code/pypersyst/database.py", line 27, in execute return self._engine.execute(transaction) File "/home/pobrien/Code/pypersyst/engine/engine.py", line 75, in execute return transaction.execute(self._root) File "/home/pobrien/Code/pypersyst/entity/transaction.py", line 76, in execute return root[self.classname]._update(self.instance, **self.attrs) File "/home/pobrien/Code/pypersyst/entity/extent.py", line 312, in _update self._validate(instance, combined) File "/home/pobrien/Code/pypersyst/entity/extent.py", line 324, in _validate instance._validate(attrs) File "/home/pobrien/Code/pypersyst/entity/entity.py", line 157, in _validate raise error.InvalidAttribute, '%r is not an attribute' % name InvalidAttribute: 'foo' is not an attribute >>> Can you tell I've been having some fun with this? ;-) -- Patrick K. O'Brien Orbtech http://www.orbtech.com/web/pobrien ----------------------------------------------- "Your source for Python programming expertise." ----------------------------------------------- From jacek.generowicz at cern.ch Sun Aug 24 05:36:17 2003 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 24 Aug 2003 11:36:17 +0200 Subject: For Kenny Tilton: Why do I need macros revisited. References: <3f45484f$1_6@corp.newsgroups.com> <3F45A7BF.4060806@nyc.rr.com> <2259b0e2.0308222333.16ad345d@posting.google.com> <3F47BDCA.3070001@nyc.rr.com> <2259b0e2.0308240131.8bb4c17@posting.google.com> Message-ID: mis6 at pitt.edu (Michele Simionato) writes: > > The CLOS MOP is a better playground, but Python has > > a clear win in that there is only one Python. If I really need the MOP > > for a project, I just pick a CL which exposes it. If I want to deliver a > > package any lispnik can use, I better not use the MOP. > > Hear, hear, people who say CL is more standard than Python! It is. The MOP did not make it into the standard, which is a pity, but does not detract from the fact that the standard exists. Actulally, the MOP is a particularly thorny issue, in this respect, as it is _almost_ standard. :-) From khoury at physics.ucsb.edu Fri Aug 29 13:09:04 2003 From: khoury at physics.ucsb.edu (George Khoury) Date: Fri, 29 Aug 2003 10:09:04 -0700 Subject: how does python use its .lib files? Message-ID: I am just starting to code some c extensions, and have been experimenting with both the Borland and MSVC compilers. Everything works, but I have a basic question. When using Borland, I have to make an OMF version of Python23.lib. Does this mean I now have two copies of the python interpreter? Or maybe I should ask another question. Suppose I have imported two extension modules compiled with MS and Borland. If they both call a python function (say, PyArg_ParseTuple), they are linking to two different libraries, but the same function, right? How does that work? I realize this is not a python specific question, and really a question about the use of libraries in general. Any explanations or links would be appreciated. Thanks, George Khoury From mpeuser at web.de Thu Aug 14 12:42:35 2003 From: mpeuser at web.de (Michael Peuser) Date: Thu, 14 Aug 2003 18:42:35 +0200 Subject: uiToolkit and some GUI benchmarking References: Message-ID: I got a request for figures with Psyco, so I installed it (which I had not found time for during the last weeks...). It turned out to inmstalled idiotically simple! I extend the benchmarks with Psyco results below.... Kindly Michael P "Michael Peuser" schrieb im Newsbeitrag news:bhg4im$59u$01$1 at news.t-online.com... > Hi, > > is there an official way to acquire SecretLabs uiToolkit? I understand they > no longer sell PythonWorks. > > I recently became a fan of Fredrik Lundh's WCK which gives fresh wind to > Tkinter. It seems that this is the "open source spin off" of uiToolkit. > > WCK can be very fast. I benchmarked some hundered redraws of some thousend > characters: > Addition: value in brackets WITH Psyco: 0.8 (0.5) sec a simple WCK widget 0.9 (0.6) sec Tkinter.Message (a widget which is somewhat underestimated!) 4.3 (4.4) sec Tkinter.Text 5.8 (5.8) sec Tkinter.ListBox > > Most of the time is spend in internal working of update() however; these > figures also change depending on screen depth. > > But there is great potial in WCK in annotating the displayed text. I added > small coloured rectangle to each and every character just for fun. Well, > after that it took 17 sec for 200 updates - this however means less than 0.1 > sec for something Canvas would take 3+ sec (on my laptop at least...) > > Kindly > Michael P > > From staschuk at telusplanet.net Sat Aug 2 18:24:42 2003 From: staschuk at telusplanet.net (Steven Taschuk) Date: Sat, 2 Aug 2003 16:24:42 -0600 Subject: Singleton-like pattern In-Reply-To: <2259b0e2.0308020746.438d0e6b@posting.google.com>; from mis6@pitt.edu on Sat, Aug 02, 2003 at 08:46:32AM -0700 References: <2259b0e2.0308010815.5dcb0b58@posting.google.com> <2259b0e2.0308020746.438d0e6b@posting.google.com> Message-ID: <20030802162442.A1373@tibia.amotlpaa.bogus> Quoth Michele Simionato: [...] > Actually you are right, I remember now that I got problems with > (args,kw) and at the end I used args,tuple(kw.items()). But I was > ensure if this was a good solution. I'd worry about the order of kw.items(). -- Steven Taschuk Aral: "Confusion to the enemy, boy." staschuk at telusplanet.net Mark: "Turn-about is fair play, sir." -- _Mirror Dance_, Lois McMaster Bujold From janssen at parc.com Sat Aug 9 00:56:36 2003 From: janssen at parc.com (Bill Janssen) Date: Fri, 8 Aug 2003 21:56:36 PDT Subject: [Python-Dev] Slogan: Getting Rich Overnight In-Reply-To: Your message of "Fri, 08 Aug 2003 19:59:27 PDT." <3F34638F.9020201@tismer.com> Message-ID: <03Aug8.215641pdt."58611"@synergy1.parc.xerox.com> I think I prefer Get Rich Overnight: Get Python Bill From bokr at oz.net Wed Aug 6 22:45:29 2003 From: bokr at oz.net (Bengt Richter) Date: 7 Aug 2003 02:45:29 GMT Subject: abspell.py helps you say Hotel India -- as well as ticket locator codes ;-) Message-ID: ====< abspell.py >======================================= # abspell.py v.10 20030806 17:20:23 Bengt Richter bokr at oz.net # Use freely, so long as you accept that there is NO WARRANTY OF ANY KIND. # """ Abspell translates alphanumeric strings to corresponding phonetic word codes. (see http://www.wikipedia.org/wiki/NATO_phonetic_alphabet) Usage: abspell.py words and or digits to translate e.g., abspell.py hello abspell v.10 Results in (untranslated letters are square bracketed): hello = Hotel Echo Lima Lima Oscar abspell = Alpha Bravo Sierra Papa Echo Lima Lima v.10 = Victor [.] One Zero """ abLetters = ( 'Alpha Bravo Charlie Delta Echo Foxtrot Golf Hotel India ' 'Juliet Kilo Lima Mike November Oscar Papa Quebec Romeo ' 'Sierra Tango Uniform Victor Whiskey Xray Yankee Zulu' ).split() abDigits = 'Zero One Two Three Four Five Six Seven Eight Niner'.split() def abSpell(s): if ' ' in s: return '\n'.join(map(abSpell, s.split())) return ' '.join(['%10s ='%s]+map( lambda c: c.isdigit() and abDigits[int(c)] or c.isalpha() and abLetters[ord(c.lower())-ord('a')] or '[%s]' %c, s)) if __name__ == '__main__': import sys if sys.argv[1:]: print abSpell(' '.join(sys.argv[1:])) else: print __doc__ ========================================================= Regards, Bengt Richter From lorenb2 at bezeqint.net Sun Aug 17 09:41:37 2003 From: lorenb2 at bezeqint.net (Bill Loren) Date: Sun, 17 Aug 2003 15:41:37 +0200 Subject: RuntimeError: maximum recursion limit exceeded ?? Message-ID: <000501c364c5$483d7cf0$6400a8c0@EVOD31> Hi ppl, Trying to substitute some html tags within a big html file using RE ended up with the "RuntimeError: maximum recursion limit exceeded" message. Any idea why that might happen and how should one cope with it ? thx ~B (btw I'm trying to take off several s, i.e. substiture them with the empty string '') From srijit at yahoo.com Mon Aug 4 03:01:55 2003 From: srijit at yahoo.com (srijit at yahoo.com) Date: 4 Aug 2003 00:01:55 -0700 Subject: Plotting Package for Python 2.3 Message-ID: <221d8dbe.0308032301.2c0e801f@posting.google.com> Hi, I am looking for a good plotting package (preferably with 3D plotting capabilities) based on Python 2.3 (Windows 98). Unfortunately Dislin does not exist for Python 2.3. I look forward to suggestions from members. Regards, Srijit From rdsteph at earthlink.net Fri Aug 29 14:28:57 2003 From: rdsteph at earthlink.net (Ron Stephens) Date: 29 Aug 2003 11:28:57 -0700 Subject: Burn some books (please)... References: Message-ID: <8e6e8e5d.0308291028.79be299b@posting.google.com> I was busy last night burning printed copies of the MetaClass Programming articles I found on IBM DeveloperWorks. These tomes, although short, are packed with more seditious material than I have seen collected in any other single place. Mr. Mertz and another sorcerer (and Italian Simon Magus I believe, or was that a pseudonym for Mr. Martelli?) were twisting logic so pervertedly that they needed to draw numerous magic charts, with horizontal arrows sideswiping into vertical arrows, just in order to make their idle imaginings comprehensible to mere mortals; one could certainly not expect plain folks to understand their intentions by simply reading the code itself. I have heard it said that any object not amenable to introspection is not worth instantiating, so despite my pious misgivings, I labored late into the night wrapping my mind around the sorcerers' baubles; every time I tried to turn off the lights and seek to knit up my raveled sleave of care, I startled myself back to wakefulness wtih foolish mutterings like "the code is its own reward" and "before one can commit an object to memory, one must first grasp the object" or "actual functioning programs are for weenies" when, finally, in one last gasp for the clean, fresh air of practicality, my conscience bade me burn the printed words, for better to burn these scraps than to burn my immortal soul for all eternity. By the flickering firelight I realized that God has granted us perfect freedom; the future is yet unwritten, and all things are possible. I realize now that Italians are all semioticians and Dr. Mertz must have been so seduced. But what is the distinction between these epiphanies and my previous predilection for atheism? If I knew the answer to this, I would be perhaps able to name the particular school of heresy these authors endorse; but, alas, I know not. I do know that I thouroughly enjoyed these articles on metaclass programming, even though I understood only a small portion of their total contents. I want tot thank the authors and, surely if anyone has read this far in my drivelings, they would find it infinitely more profitable to go to IBM Developer Works and study these amazingly well thought-out works. RS From Juha.Autero at iki.fi Thu Aug 28 02:32:36 2003 From: Juha.Autero at iki.fi (Juha Autero) Date: Thu, 28 Aug 2003 09:32:36 +0300 Subject: Dealing with faults matters References: <7ds2g4$cm8$1@Starbase.NeoSoft.COM> <000901be7b41$cdc84f20$f19e2299@tim> <7dt2pv$1mj$1@Starbase.NeoSoft.COM> <3706f449.12085377@news.cybercity.dk> <7e3efa$j7v$1@Starbase.NeoSoft.COM> Message-ID: <8765kinvgb.fsf@jautero.no-ip.org> claird at Starbase.NeoSoft.COM (Cameron Laird) writes: > Exception-handling is even more important to > people. People and organizations that deal > with exceptions intelligently, and don't pre- > tend that everything should be without fault, > are better people and organizations. I think the confusion here was what you mean by exceptions. Do you mean exceptional situations (or faults) or method of handling those situations. Your text got me thinking wouldn't it be great if your organization had exceptions in latter sense. You could raise an exception and it would traverse up the organizational hierarchy until someone handles it. -- Juha Autero http://www.iki.fi/jautero/ Eschew obscurity! From python-url at phaseit.net Tue Aug 12 10:18:06 2003 From: python-url at phaseit.net (Irmen de Jong) Date: Tue, 12 Aug 2003 14:18:06 -0000 Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Aug 12) Message-ID: QOTW: "What can I do with Python that I can't do with C#? You can go home on time at the end of the day." -- Daniel Klein "Python lends itself to playing with it and to discussing the merits of code snippets with other people. It's one of the 'language' languages, in that it's suitable for people to communicate using it, and it can even be used as [a] tool to check ones thoughts." -- Anton Vredegoor Discussion ---------- Last week's QOTW from Gary Herron was about three of Python's "shortcomings", or actually, strengths (according to many). This week, we have a true sore point: Python's supposed lack of proper Symmetric Multiprocessor scalability. Python's random number generator was improved for Pytho 2.3, but this caused problems when you are upgrading from 2.2 and are depending on the sequence of numbers to be reproducible (for simulations, for instance). Raymond Hettinger has the solution. Tim Peters explains why it is relatively safe to take Python 2.3 for a test drive on Windows (it won't leave litter behind when uninstalled, and works side-to-side with other existing versions). Bengt Richter puts forward some interesting ideas for a cross- platform 'py2exe' tool and executable file format. Thomas Heller found a solution for a possible problem with creating an executable with py2exe from python code that requires encodings. (For instance, when you're using pyxml). Announcements ------------- gmpy 1.0 alpha, a wrapper for the well known GNU MP library, to provide multi-precision arithmetic for Python. Confluence 0.6, a functional programming language for digital logic design (FPGA/ASIC) and real-time embedded software development. Confluence source code compiles into Python, amongst others. Effbot's ElementTree 1.2 alpha 2, ElementTidy 1.0 alpha 1. The ElementTree package provides a Python implementation of the 'Element' type, plus code to serialize element trees to and from XML files. ElementTidy is an alternative tree builder that can read arbitrary HTML, and turn it into well-formed XHTML element trees. EmPy 3.0.4, a powerful and robust templating system for Python. Snakelets 1.2, a simple Python web application server, mainly for educational purposes. It includes a web server, HTML+Python pages, and code-centric page request handlers. omniORB version 4.0.2 and omniORBpy 2.2, a robust, high performance CORBA ORB. OmniORBpy is a version for Python. Python for .NET preview 2. This gives you near-seamless integration with the .NET CLR. This package does not implement Python as a first-class CLR language. Rather, it is an integration of the C Python engine with the .NET runtime. Fredrik Lundh continues writing about the new modules in the Python 2.3 standard library. Read about datetime, heapq, new encodings, and others. pxdom 0.6, a stand-alone pure-Python DOM implementation and non-validating parser, supporting Level 3 Core, XML, Load and Save specs. PXTL 0.9, the Python XML Templating Language, a templating solution for producing XML, HTML and other text-based document types. ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the daily python url http://www.pythonware.com/daily Mygale is a news-gathering webcrawler that specializes in (new) World-Wide Web articles related to Python. http://www.awaretek.com/nowak/mygale.html While cosmetically similar, Mygale and the Daily Python-URL are utterly different in their technologies and generally in their results. comp.lang.python.announce announces new Python software. Be sure to scan this newly-revitalized newsgroup at least weekly. http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce Brett Cannon continues the marvelous tradition established by Andrew Kuchling and Michael Hudson of summarizing action on the python-dev mailing list once every other week. http://www.python.org/dev/summary/ The Python Package Index catalogues packages. http://www.python.org/pypi/ The somewhat older Vaults of Parnassus ambitiously collects references to all sorts of Python resources. http://www.vex.net/~x/parnassus/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ The Python Business Forum "further[s] the interests of companies that base their business on ... Python." http://www.python-in-business.org The Python Software Foundation has replaced the Python Consortium as an independent nexus of activity http://www.python.org/psf/ Cetus does much of the same http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://python.sourceforge.net/peps/pep-0042.html The online Python Journal is posted at pythonjournal.cognizor.com. editor at pythonjournal.com and editor at pythonjournal.cognizor.com welcome submission of material that helps people's understanding of Python use, and offer Web presentation of your work. *Py: the Journal of the Python Language* http://www.pyzine.com Archive probing tricks of the trade: http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python&num=100 http://groups.google.com/groups?meta=site%3Dgroups%26group%3Dcomp.lang.python.* Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://www.ddj.com/topics/pythonurl/ http://purl.org/thecliff/python/url.html (dormant) or http://groups.google.com/groups?oi=djq&as_q=+Python-URL!&as_ugroup=comp.lang.python Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". -- The Python-URL! Team-- Dr. Dobb's Journal (http://www.ddj.com) is pleased to participate in and sponsor the "Python-URL!" project. From aleax at aleax.it Thu Aug 21 02:13:26 2003 From: aleax at aleax.it (Alex Martelli) Date: Thu, 21 Aug 2003 06:13:26 GMT Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> <6dj2kv8ugkieehs7guh786cl40o5lj6mcs@4ax.com> Message-ID: Andrew Dalke wrote: ... > be that way. It's the inability to get into another's shoes - > to understand view different than one's own - which annoys > me the most. A deficiency sadly typical of all too many > enthusiastic new language designers. Just as prevalent is the wish to please EVERYone -- that's how one gets, say, PL/I, or perl... by NOT deliberately refusing to "get into other's shoes" and rejecting their "different views" for purposes of inclusion into the new language. Even GvR historically did some of that, leading to what are now his mild regrets (lambda, map, filter, ...). Alex From trentm at ActiveState.com Wed Aug 13 13:56:23 2003 From: trentm at ActiveState.com (Trent Mick) Date: Wed, 13 Aug 2003 10:56:23 -0700 Subject: Determine file type (binary or text) In-Reply-To: ; from none@none.net on Wed, Aug 13, 2003 at 08:29:20AM +0000 References: Message-ID: <20030813105623.J19120@ActiveState.com> [Sami Viitanen wrote] > Hello, > > How can I check if a file is binary or text? > > There was some easy way but I forgot it.. Generally I define a text file as "it has no null bytes". I think this is a pretty safe definition (I would be interested to hear practical experience to the contrary). Assuming that, then: def is_binary(filename): """Return true iff the given filename is binary. Raises an EnvironmentError if the file does not exist or cannot be accessed. """ fin = open(filename, 'rb') try: CHUNKSIZE = 1024 while 1: chunk = fin.read(CHUNKSIZE) if '\0' in chunk: # found null byte return 1 if len(chunk) < CHUNKSIZE: break # done finally: fin.close() return 0 Cheers, Trent -- Trent Mick TrentM at ActiveState.com From fredrik at pythonware.com Thu Aug 7 07:44:35 2003 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 7 Aug 2003 13:44:35 +0200 Subject: How to dectect UCS4 Python at runtime? References: Message-ID: Daniel Dittmar wrote: > I'm trying to detect whether the Python currently running has been compiled > for UCS2 or UCS4. sys.maxunicode From jacek.generowicz at cern.ch Fri Aug 22 05:21:54 2003 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 22 Aug 2003 11:21:54 +0200 Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> <6dj2kv8ugkieehs7guh786cl40o5lj6mcs@4ax.com> Message-ID: Hans Nowak writes: > The problem is that a macro system that is too powerful can be harmful. The problem is that a permissive language can be harmful. > Let's say you write a useful module. Python 3.6 just added a very > powerful macro system, and you use it to, say, write functions with > lazy evaluation, make strings mutable, and write your own flavor of > the for-loop. Now I cannot read your code anymore. A simple function > call, or a loop, does not mean what it used to mean. Let's say you rebind all the attributes of __bulitins__. Now I cannot read your code anymore (well, I can, but it doent'h do what it looks like it will do). If you deliberately want to break things, you don't need macros. os.system("rm -rf *") Just because a stupid or malicious programmer could do "bad things" is not a reason to reduce a language's power. (You end up with Java.) From alexander.dejanovski at laposte.net Mon Aug 4 09:14:54 2003 From: alexander.dejanovski at laposte.net (Alexander DEJANOVSKI) Date: Mon, 04 Aug 2003 15:14:54 +0200 Subject: Developping an EAI server in Python : looking for developpers Message-ID: <5.1.0.14.2.20030804151313.00af61c8@pop.laposte.net> Hi all, I'm starting a new project to develop an Open-Source EAI server in Python and I'm looking for motivated developpers and testers. It is inspired by Open Adaptor (www.openadaptor.org), but aims to be easier to use and more powerful. I've developped yet a first alpha that contains several components: File Source FTP Source HTTP Source FlatToXML Pipe XSLT Pipe File Sink FTP Sink SMTP Sink Upcoming components are : SOAP Source/Sink MQSeries Source/Sink JMS (?) Source/Sink Database Source/Sink and a GUI to create config files. Config files are XML files looking like this : Loggers tags permit to add logging handlers (new logging module of Python 2.3) I've created the project on SourceForge (approval in progress). -------------- next part -------------- An HTML attachment was scrubbed... URL: From Janssen at rz.uni-frankfurt.de Sun Aug 17 13:06:48 2003 From: Janssen at rz.uni-frankfurt.de (Michael Janssen) Date: Sun, 17 Aug 2003 19:06:48 +0200 Subject: Strange re behavior: normal? In-Reply-To: References: Message-ID: Robin Munn wrote: > How is re.split supposed to work? This wasn't at all what I expected: >>>>import re >>>>re.split(r'\b', 'a b c d') > ['a b c d'] the code (INSTALL_DIR/Modul/_sre.c function pattern_split) seems to show this behavior on intention. At least this if-clause has no other purpose to my eyes: if (state.start == state.ptr) { # empty string? mj if (last == state.end) break; /* skip one character */ state.start = (void*) ((char*) state.ptr + state.charsize); continue; } Well, I belive it's good choice, to not split a string by an empty string, but when you really want (version with empty results on start and end omitted): def boundary_split(s): back = [] while 1: try: # r'.\b' and +1 prevents endless loop pos = re.search(r'.\b', s, re.DOTALL).start()+1 except AttributeError: if s: back.append(s) break back.append(s[:pos]) s = s[pos:] return back boundary_split('a b c d') #['a', ' ', 'b', ' ', 'c', ' ', 'd'] What's the good of splitting by boundaries? Someone else wanted this a few days ago on tutor and I can't figure out a reason by now. Michael From ayc8NOSPAM at cornell.edu Fri Aug 1 04:13:35 2003 From: ayc8NOSPAM at cornell.edu (Andy C) Date: Fri, 01 Aug 2003 08:13:35 GMT Subject: anti-aliased 2D vector graphics References: Message-ID: Note that I'm on Windows... if there is some windows-specific solution, that would be fine. I know there is a python win32 interface, and I think GDI supports anti-aliased vector graphics, but I'm not sure. And fonts -- I need to draw text too. Anyone tried that approach? thanks, Andy "Andy C" wrote in message news:J3pWa.420$pS6.37614819 at newssvr21.news.prodigy.com... > Where can I get a python package to draw such figures? I googled and found > PyX, I guess it outputs PostScript. I guess I can get a PostScript to BMP > converter or something. Is there any other alternative? > > I have looked at PIL, but it doesn't seem to support drawing anti-aliased > figures. Thanks for any suggestions. > > Andy > > From achrist at easystreet.com Thu Aug 21 12:30:05 2003 From: achrist at easystreet.com (achrist at easystreet.com) Date: Thu, 21 Aug 2003 09:30:05 -0700 Subject: how fast is Python? References: Message-ID: <3F44F38D.BDDB1DBE@easystreet.com> dan wrote: > > I realize this is a more complex question than one might think. > > Please advise. Consider the percentage of software projects for which the total number of hours of developer time over the life of the project exceeds the total number of hours of CPU run time during productive use of the software produced. This percentage is abysmally high. Python works on improving it on both ends, by both reducing the developer time and increasing the number of hours of productive use. What more could you want? Al From Mike at DeleteThis.Geary.com Fri Aug 22 22:02:59 2003 From: Mike at DeleteThis.Geary.com (Michael Geary) Date: Fri, 22 Aug 2003 19:02:59 -0700 Subject: Keystroke logger for Windows References: Message-ID: > Does anyone know of a keystroke logger that has been written in Python > for Windows machines? I'd like to see such a script and use it as a > point of reference for a real-time backup project that I'm working on. > Basically, I'd like to be able to capture all keystrokes from the > keyboard buffer and write them to a text file so I could reporduce > emails, documents, etc. in the event of file loss that occurs between > nightly backups. For example, my boss comes to me, he has deleted an > email that he was writing... he has been working on the email all day... > and he expects me to wave a magic wand and bring it back. > > Thanks for any advice, code or pointers. Also, if Python isn't suited > for this, let me know and I'll look at doing this in c I don't think Python would be a good choice for the basic keystroke logging utility. A program like this is implemented as a systemwide message hook, which is a DLL that is loaded into the address space of *every* application. This is a simple piece of code that should be written in C/C++ to keep it small. There are a number of commercial products that do keystroke logging, but the ones I've seen are intended for spying on someone else's computer activity--i.e. something your boss might want to put on your computer, not something you would want to put on your boss's computer! I find the spying orientation of those products rather distasteful, but maybe one of them could be used in a more benign way. PC Magazine reviewed several of them last year: http://www.pcmag.com/article2/0,4149,111820,00.asp Some time ago I wrote a similar program for my own use (spying on myself as it were). Maybe it would be worth cleaning it up and releasing it as open source. It's actually pretty handy. For example, if I see a file on my system I don't recognize, I can look back at my log and see what I was doing--what program I was running that created that file. But I'd be worried about the privacy implications--I wouldn't want my program being used as spyware. -Mike From eric.brunel at pragmadev.com Mon Aug 11 10:12:16 2003 From: eric.brunel at pragmadev.com (Eric Brunel) Date: Mon, 11 Aug 2003 16:12:16 +0200 Subject: CLI+GUI References: <2259b0e2.0308080948.5a95e383@posting.google.com> <2259b0e2.0308090530.7519f195@posting.google.com> <2259b0e2.0308110517.7c4fa8c8@posting.google.com> Message-ID: Michele Simionato wrote: > Eric Brunel wrote in message news:... > >>I don't know if this is the problem, because you didn't say exactly when the >>script hangs, but Tkinter apparently has problems when calls to it are made >>from a thread different from the one into which it was initialized. I'd use >>an Event between Tkinter's thread and Cmd's thread, checking it regularly >>with Tkinter's after method. >> >>HTH > > > It hangs immediately when I start the script by clicking on its icon. > What do you mean with "I'd use an Event" ? I thought an Event object > is automatically generated when I click on a widget, or press a key, > or something. I wasn't thinking about this Event class. I thought about the one described here: http://www.python.org/doc/current/lib/event-objects.html It allows very basic communications between threads. > Are you saying can I can programmatically generate an > Event, faking a real mouse/key press? How so? That is something I > always wanted to know ;) Generating a *Tk* event is quite easy: just use the event_generate method that exists on all widgets. I used it to generate simple events, often user-defined one. The syntax is simple: myWidget.event_generate("<>") If you have a binding for "<>" for myWidget, you can trigger it this way. I never tried to pass event detail, though. HTH -- - Eric Brunel - PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com From skip at pobox.com Mon Aug 4 14:39:07 2003 From: skip at pobox.com (Skip Montanaro) Date: Mon, 4 Aug 2003 13:39:07 -0500 Subject: Freeze Question In-Reply-To: References: Message-ID: <16174.43083.667395.719317@montanaro.dyndns.org> David> 'import site' failed; use -v for traceback David> Traceback (most recent call last): David> File "vnmrXserver.py", line 1, in ? David> File "/usr/local/lib/python2.2/SocketServer.py", line 131, in ? David> File "/usr/local/lib/python2.2/socket.py", line 41, in ? David> ImportError: No module named _socket Is this during the freeze operation or while running the frozen app? Can you successfully execute import _socket from the Python interpreter prompt? _socket.so should live in ${prefix}/lib/python2.3/lib-dynload David> So I guess I this means I have to rebuild python with static David> linking (this is a mystery to me) OR is there a way to hack the David> makefile (or perhaps some other file) and have the missing David> modules found and included in the frozen program without a David> rebuild of python? You can fairly easily (though a bit tediously) build a static Python interpreter. You need to edit Modules/Setup to uncomment the various extension modules you need. This is what we all used to do before Greg Ward began attempting world domination through distutils. There should be some documentation somewhere still about how to do this, perhaps in the introductory comments in Modules/Setup itself. Yeah, looks like it's there. I don't know about the second half of your question, as I'm not a freeze user. Two suggestions come to mind: 1. Try Gordon MacMillan's installer instead of freeze. (Dunno if it works on Solaris.) 2. Use Sun's package manager to distribute your application along with Python instead. Having done this recently for a non-Python app, I can tell you this isn't fun, but it should be possible. Skip From aleax at aleax.it Mon Aug 4 07:56:04 2003 From: aleax at aleax.it (Alex Martelli) Date: Mon, 04 Aug 2003 11:56:04 GMT Subject: Match beginning of two strings References: Message-ID: Ravi wrote: > Hi, > > I have about 200GB of data that I need to go through and extract the > common first part of a line. Something like this. > > >>>a = "abcdefghijklmnopqrstuvwxyz" > >>>b = "abcdefghijklmnopBHLHT" > >>>c = extract(a,b) > >>>print c > "abcdefghijklmnop" > > Here I want to extract the common string "abcdefghijklmnop". Basically I > need a fast way to do that for any two given strings. For my situation, > the common string will always be at the beginning of both strings. I can Here's my latest study on this: *** pexa.py: import sys import psyco psyco.full() import cexa import exa def extract(a, b): m = min(len(a), len(b)) for i in range(m): if a[i] != b[i]: return a[:i] return a[:m] def extract2(a, b): for i, ai, bi in zip(xrange(len(a)), a, b): if ai != bi: return a[:i] return a[:m] def extract3(a, b): for i, ai in enumerate(a): if ai != b[i:i+1]: return a[:i] return a extract_pyrex = exa.exa extract_c = cexa.cexa *** exa.pyx: def exa(a, b): cdef int la cdef int lb la = len(a) lb = len(b) cdef int lmin lmin = min(la, lb) cdef int i i = 0 while i < lmin: if a[i] != b[i]: return a[:i] i = i + 1 if lmin == la: return a else: return b *** cexa.c: #include static PyObject* cexa(PyObject* self, PyObject* args) { char *a, *b; int la, lb; int lmin, i; if(!PyArg_ParseTuple(args, "s#s#", &a, &la, &b, &lb)) return 0; lmin = la; if(lmin 'pexa.extract("abcdefghijklmonpKOU", "abcdefghijklmonpZE")' 100000 loops, best of 3: 2.39 usec per loop [alex at lancelot exi]$ python -O timeit.py -s 'import pexa' 'pexa.extract("abcdefghijklmonpKOU", "abcdefghijklmonpZE")' 100000 loops, best of 3: 2.14 usec per loop [alex at lancelot exi]$ python -O timeit.py -s 'import pexa' 'pexa.extract2("abcdefghijklmonpKOU", "abcdefghijklmonpZE")' 10000 loops, best of 3: 30.2 usec per loop [alex at lancelot exi]$ python -O timeit.py -s 'import pexa' 'pexa.extract3("abcdefghijklmonpKOU", "abcdefghijklmonpZE")' 100000 loops, best of 3: 9.59 usec per loop [alex at lancelot exi]$ python -O timeit.py -s 'import pexa' 'pexa.extract_pyrex("abcdefghijklmonpKOU", "abcdefghijklmonpZE")' 10000 loops, best of 3: 21.8 usec per loop [alex at lancelot exi]$ python -O timeit.py -s 'import pexa' 'pexa.extract_c("abcdefghijklmonpKOU", "abcdefghijklmonpZE")' 100000 loops, best of 3: 1.88 usec per loop [alex at lancelot exi]$ So, it seems you can still get a tiny drop of extra speed with a C-coded extension, though it's doubtful whether it's worth the bother wrt the pyro-optimized simple Python code in function 'extract'. I'm not sure where I went wrong in the Pyrex coding (it doesn't seem to be performing anywhere as well as I thought it might) and I'll be happy for real Pyrex expert to show me the way. Of course, as others have pointed out, it's unclear from your problem description that doing such operations pairwise on a lot of pairs of strings is actually what you need. It IS quite possible that what you're doing could often be better modeled, e.g., by repeated "prefix extractions" between ONE fixed string and several other candidate strings; or "prefix extraction" between a set of more than two strings. In each case, it's likely that you can get much better performance by more sophisticated algorithms. However, which algorithms those might be is unclear unless you can provide mode details on what you're doing. Alex From aleax at aleax.it Thu Aug 7 11:12:41 2003 From: aleax at aleax.it (Alex Martelli) Date: Thu, 07 Aug 2003 15:12:41 GMT Subject: Need to convert an arbitrary byte-pair to an int. References: <3f323dc2$0$10775$afc38c87@auth.uk.news.easynet.net> <3f3257ba$0$18274$afc38c87@auth.uk.news.easynet.net> Message-ID: Graham Nicholls wrote: ... >> So, in this >> specific case, would the array module. Both struct and array are part >> of the standard Python library and often come in handy for occasional >> needs of low-level access, such as this. > > Trouble is, you don't know what you don't know, and my python library > reference is at home, and I'm onsite. The python library reference is also online -- see for example http://www.python.org/doc/current/lib/lib.html -- and if one happens to prefer "Python in a Nutshell", why, THAT one is too (on O'Reilly's "safari" service -- however, after some weeks' worth of free trial, if you want to continue accessing "safari" you'd have to subscribe to it). > them, would be useful. Python seems to have more modules, and I do like > lots of things about it, but Ruby _seems_ cleaner, somehow. Its an Interesting. I'm also trying to learn Ruby in my copious spare time and don't really see that "clean-ness" (all of those 'end' terminators of block, how are they "cleaner" than the lack thereof in Python? How is it "cleaner" to have regular expressions deeply mixed in the innards of the language rather than cleanly separated into their own library modules? Etc, etc). I _do_ see that Ruby provides more scope for tinkering, because it lets me play with the way operations on built-in types work -- so if I want e.g. 2+2 to evaluate to 5, I can (or more seriously, I can perform presumably-useful modifications to other special methods of built-in types). But I think the same key difference that makes Ruby better for tinkering -- the total fluidity and dinamicity of just about everything, with no "fixed posts" for the behavior of built-in types -- may make it less suitable for the programming of large, multi-developers, indeed multi-team application programs. Python is highly dynamic but draws the line at modifying behavior of built-in types; Ruby draws no such line, and thus it is even more dynamic. To me, on the basis of my understanding of both languages so far, THAT is the one _crucial_ language difference (the _libraries_ may differ more broadly, but that's secondary and even easily remedied -- the languages' philosophy regarding such dynamic possibilities, however, are far less likely to ever change). Other more specific tradeoffs, such as Ruby's _mutable_ strings (which I mostly dislike, but may sometimes help performance) or the very different style of iterators in the two languages (in Ruby you pass a code block into the iterator, while in Python you get values out of the iterator one by one -- so, for example, stepping over more than one iterator in a controlled way is far easier in Python, while other tasks are easier in Ruby -- I think, overall, the power of the very iterators in the two languages may be very similar, with a tiny edge to Ruby, while the simplicity and syntax cleanliness of coding is IMHO a substantial edge to Python) -- all of these can be discussed point by point, of course. Still, I agree that both languages are quite good. If Python did not exist, I believe I would most probably be using Ruby, myself. Alex From abuseonly at sgrail.org Sun Aug 24 00:51:32 2003 From: abuseonly at sgrail.org (derek / nul) Date: Sun, 24 Aug 2003 04:51:32 GMT Subject: Bug with win32 open and utf-16 file References: <27vekvc6evvn3m5jg8n1en2u42skat42qn@4ax.com> <2i1gkv0s7762vcs85rkdq6uvgk6oitje12@4ax.com> <78egkvg1tu0j1kvedclcefn01hr3vkqh4v@4ax.com> Message-ID: <4vggkv4hebk1j42iaoe5tlojjli6rittu2@4ax.com> On Sun, 24 Aug 2003 07:45:44 +0300, Christos "TZOTZIOY" Georgiou wrote: >On Sun, 24 Aug 2003 04:37:42 GMT, rumours say that derek / nul > might have written: > >>errr, no, just a small p programmer from vb and perl trying to learn an OO >>language. > >Welcome aboard then, fellow Agent user (I have missed some upgrades it >seems...) You'll be fine with Python (what's a small p programmer? I am not a good programmer and I don't program for a living. And I am struggling with OO concepts. >unless you stutter when you type! ;-), especially with the newsgroup, >and keep in mind that should we fail to help you, it's guaranteed you'll >get DOUBLE your money back! Now that's what I wanted to hear :-) :-) >Now, to re-instate seriousness, try again the tutorial and then make >yourself comfortable with the documentation index. We'll be here for >more help. thanks Derek From davecook at nowhere.net Tue Aug 12 03:24:27 2003 From: davecook at nowhere.net (David M. Cook) Date: Tue, 12 Aug 2003 07:24:27 GMT Subject: ANNOUNCE: Rekall V2.0.2 References: <5.2.1.1.0.20030810065523.02c3ed10@66.28.54.253> <3F385CAB.6000705@festina-lente.qc.ca> Message-ID: In article <3F385CAB.6000705 at festina-lente.qc.ca>, Benoit Caron wrote: > I suppose from the reaction to the quirks of the website that this kind > of application would fill a need. Am I wrong? An open source Access type app is sorely needed. > - wxPython as the toolkit : it is more "usable" freely on windows due to > the licensing/etc. on windows I prefer pygtk as a toolkit, but I do agree that wxpython is more usable on windows. > - Use an embedded database : if we want to "attack" Access, we must be > "standalone" and must not need a "real,big" database installation. I > thought about sqlite, but I did'nt dig enough on this to decide yet. > Anyway, the point would be to make it possible to "switch" the model > from a database system to an another. This way, the thing could be used > as a "prototyping" solution. But I digress Why not use SqlObject or one of the other OR mapping layers? http://www.thinkware.se/cgi-bin/thinki.cgi/ObjectRelationalMappersForPython I believe that MiddleKit has some rudimentary support for web forms. (I'm being a bit of a hypocrite here because I eventually ended up rolling my own simple database layer for my app.) > - Make it OpenSource. I looked at rekall and it look not that bad, but I > hardly see how this can take away "mindshare" from Access. I don't see them taking any mindshare from Access, but they are filling an important niche on Linux. > So, anybody think this would have users? Sounds very useful to me. I'd be interested in helping out. Dave Cook daverz at users dot sourceforge dot net From skchim0 at engr.uky.edu Wed Aug 20 13:07:49 2003 From: skchim0 at engr.uky.edu (satish k.chimakurthi) Date: Wed, 20 Aug 2003 13:07:49 -0400 Subject: Import site Message-ID: <200308201307.49778.skchim0@engr.uky.edu> Hello all, I am trying to load a module in python. When I said python at the commandprompt, I got the following and yet I am able to go to the python prompt $ python 'import site' failed; use -v for traceback Python 1.5.2 (#1, Apr 3 2002, 18:16:26) [GCC 2.96 20000731 (Red Hat Linux 7.2 2 on linux-i386 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> Can someone throw light on this ?? Thanks in advance, SATISH SATISH K.CHIMAKURTHI GRADUATE TEACHING ASSISTANT UNIVERSITY OF KENTUCKY LEXINGTON, KY From tjreedy at udel.edu Fri Aug 29 17:34:22 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 29 Aug 2003 17:34:22 -0400 Subject: method (a, b = '', *c, **d): gets a syntax error? References: <3F4F644D.2060003@uni-bonn.de> <3dqcndZe5u2g4NKiXTWJiA@comcast.com> Message-ID: <-6-dnRcax4ZCW9KiXTWJkA@comcast.com> "Michael Peuser" wrote in message news:bio39s$2ai$03$1 at news.t-online.com... > > "Terry Reedy" schrieb im Newsbeitrag > news:3dqcndZe5u2g4NKiXTWJiA at comcast.com... > > [...} > > > > 1. When you make a function call and use **whatever, it must be the > > last item in the argument list, just as in a function definition. A > > following comma is not allowed for either defs or calls. > > This in fact is not true. Funnily you can add *one* comma at the end of any > list-like construct. For 2.2.1 and whatever version Andreas is running, **whatever is an exception and CANNOT be followed by a comma in either def or call, just as I said. I tested before writing. (Did you? Can you test below on 2.3?) >>> def f(**d): ... for i,v in d.items(): print i, v ... >>> b={'one':1, 'two':2} >>> f(**b) two 2 one 1 >>> f(**b,) File "", line 1 f(**b,) ^ SyntaxError: invalid syntax >>> def f2(**d,): pass File "", line 1 def f2(**d,): pass ^ SyntaxError: invalid syntax # On the original fixed-pitch font screen, both arrows point at offending comma. Can someone verify this for 2.3? If so, there is a bug in either doc or interpreter. Terry J. Reedy From aleax at aleax.it Thu Aug 21 03:25:07 2003 From: aleax at aleax.it (Alex Martelli) Date: Thu, 21 Aug 2003 07:25:07 GMT Subject: Brandon's abrasive style (was Re: What's better about Ruby than Python?) References: <38ec68a6.0308172319.431a4fde@posting.google.com> Message-ID: Ramon Leon Fournier wrote: > Brandon J. Van Every wrote: >> - Python is not a good language for low-level 3D graphics problems. C++ >> is better. > > Well, not just for low-level 3D graphics. There are many other things > you would not code in Python unless you are a complete fool. Your > companies mail server, for instance. But you wouldn't do that in C# I deeply disagree: Twisted, coded in Python, lets you do a GREAT job coding such applications as mail servers -- highly scalable, etc etc. And even without Twisted, Python is splendid for such I/O bound jobs. > Granted that my motivation to use Python is different from that of many > others here. I have work to do, and to finish it as quickly as > possible. I figured that Python is a great language for people like me, I think that's the TYPICAL motivation for using Python: it lets you do your job with great productivity. > BTW: What exactly has "Smell the Windows" to do with the current Ruby > vs. Python debate? Are you actually serious about learning any of I dunno: back when I checked carefully, Python was MUCH better integrated with Windows, thanks to win32all etc etc, while Ruby perched precariously on cygwin &c. A Windows-centric view would thus appear to favour Python over Ruby (unless Ruby's Windows implementation has made great strides). Alex From gafStopSpamData at ziplink.stopallspam.net Thu Aug 21 13:51:15 2003 From: gafStopSpamData at ziplink.stopallspam.net (Gary Feldman) Date: Thu, 21 Aug 2003 17:51:15 GMT Subject: Removing language comparisons References: Message-ID: On Thu, 21 Aug 2003 07:16:16 -0500, "A.M. Kuchling" wrote: >But comparison issues do change over time, e.g. the Python/Scheme comparison >at http://www.python.org/doc/pythonVSscheme.html says Python uses only >refcounting GC, and claims the Python and Jython implementations are >explicitly synchronized. Java performance numbers cited are for JDK 1.1.7, >Python performance numbers are for 1.5.2, and so forth. Of course, those aren't language comparisons. They're implementation comparisons. And sure, some language issues do change, but most of the fundamentals don't. Perl will always have funky character prefixes, Java will always have static typing, etc. Gary From danielk at aracnet.com Thu Aug 7 08:39:18 2003 From: danielk at aracnet.com (Daniel Klein) Date: Thu, 07 Aug 2003 05:39:18 -0700 Subject: True References: <3F312A65.5312B6EA@engcorp.com> Message-ID: On Wed, 06 Aug 2003 12:18:45 -0400, Peter Hansen wrote: >> The reason I'm taking a str() value is cuz it is being sent over a >> socket to a non-python server process, where it is converted back to a >> boolean. > >In that case, you'd be better off converting using your own routine >rather than relying on a particular behaviour of str() for this test. >Basically, do something like > >def boolean2String(boolVal): > return { False : '1', True : '0' } [ not boolVal ] > >and save yourself any further future pain... Thanks Peter, that will do the trick. Just wondering though why you chose to code the opposite values and not as def boolean2String(boolVal): return {True:'1', False:'0'}[boolVal] Dan From gh at ghaering.de Wed Aug 27 08:55:42 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Wed, 27 Aug 2003 14:55:42 +0200 Subject: My future Python IDE article In-Reply-To: <3f4ca68c$0$4190$afc38c87@news.optusnet.com.au> References: <3f4ca68c$0$4190$afc38c87@news.optusnet.com.au> Message-ID: <3F4CAA4E.5060603@ghaering.de> Mike Thompson wrote: > "David Mertz" wrote: >>So c.l.py readers... make the case for your favorite one getting on the >>list. > > I'm surprised no one has mentioned Boa. I tryed Wing & Komodo, before finding > Boa. Boa is far from finished. Depending on your wxPython version and how you use the IDE, it could work surprisingly well or annoy you to no end in my experience. I'd recommend to not review alpha software like Boa. -- Gerhard From ktilton at nyc.rr.com Thu Aug 21 10:20:18 2003 From: ktilton at nyc.rr.com (Kenny Tilton) Date: Thu, 21 Aug 2003 14:20:18 GMT Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> <6dj2kv8ugkieehs7guh786cl40o5lj6mcs@4ax.com> <599a6555.0308202108.397bb1a0@posting.google.com> Message-ID: <3F44D5F1.8050006@nyc.rr.com> Andrew Dalke wrote: > Olivier Drolet: > >>Macros don't cause Common Lisp to fork >>anymore than function or class abstractions do. > > > Making new words don't cause Speech to fork any more than > making new sentences does. Hunh? This one doesn't work, and this is the one you have to answer. Forget argument by analogy: How is a macro different than an API or class, which hide details and do wonderful things but still have to be mastered. Here's an analogy : I could learn Java syntax in a week, but does that mean I can keep up with someone who has been using the class libraries for years? Nope. And Java doesn't even have macros. > In short, no one is denying that the ability to create new macros is > a powerful tool, just like no one denies that creating new words is > a powerful tool. But both require extra training and thought for > proper use, and while they are easy to write, it puts more effort > for others to understand you. If I stick to Python/English then > more people can understand me than if I mixed in a bit of Erlang/ > Danish, *even* *if* the latter makes a more precise description > of the solution. One of the guys working under me had no respect for readability, he just got code to work, which was nice. I once had to work on his code. In about half an hour, with the help of a few macros, a great honking mass of text which completely obfuscated the action had been distilled to its essense. One could actually read it. Of course every once in a while you would notice something like "Ndiya", but if you went to the macrolet at the top of the function you would just think "oh, right" and get back to the code. Maybe sometimes these macros could be functions, but then I'd just call the function Ndiya. So what is the difference? btw, I am on your side in one regard: the LOOP macro in Lisp has phenomenally un-Lispy syntax, so I have never used it. I am slowly coming around to it being more useful than irritating, but I did not like having a new /syntax/ invented. (LOOP /can/ be used with conventional syntax, but I have seen such code only once and I think I know why they broke the syntax. ). So I get that point, but normally macros do not deviate from standard Lisp synatx. Ndiya kulala. -- kenny tilton clinisys, inc http://www.tilton-technology.com/ --------------------------------------------------------------- "Career highlights? I had two. I got an intentional walk from Sandy Koufax and I got out of a rundown against the Mets." -- Bob Uecker From lists at webcrunchers.com Sat Aug 9 15:19:47 2003 From: lists at webcrunchers.com (John D.) Date: Sat, 9 Aug 2003 12:19:47 -0700 Subject: [Spambayes] FYI -- dumbdbm is nuked In-Reply-To: <09143027.20030807180829@comcast.net> References: <1ED4ECF91CDED24C8D012BCF2B034F1302BF3128@its-xchg4.massey.ac.nz> <1ED4ECF91CDED24C8D012BCF2B034F1302BF3128@its-xchg4.massey.ac.nz> Message-ID: So, is it my understanding that Python is no longer going to support dumbdbm? I've also been investigating the best dbm modules to use for my specific application, and in the 2.3 release (openBSD), I discovered a "bsddb" directory, and in particular the "dbtables.py" module. This is the first time I heard of this module, and it isn't documented on the Python web site. Why is that? Does this mean that Python is not supporting this module? John From joshway_without_spam at myway.com Mon Aug 25 16:19:25 2003 From: joshway_without_spam at myway.com (Josh) Date: Mon, 25 Aug 2003 20:19:25 +0000 (UTC) Subject: python gripes survey References: Message-ID: sismex01 at hebmex.com wrote: > [Afanasiy] >> Returning a struct in C is >> easier to deal with than returning a near-mystery tuple in Python. >> > You *really* *must* *be* *kidding*. > -gustavo It's really pretty easy: typedef struct { int x; int y; } T; T f() { T t = { 1, 2 }; return t; } int main() { T t = f(); return 0; } And arguably easier to deal with than Python in that the fields are named. I think that's all Afanasiy was getting at. From florian.proff.schulze at gmx.net Fri Aug 22 16:42:46 2003 From: florian.proff.schulze at gmx.net (Florian Schulze) Date: Fri, 22 Aug 2003 22:42:46 +0200 Subject: Cubictemp? References: <3F464B25.A3D791BA@easystreet.com> Message-ID: On Fri, 22 Aug 2003 09:56:05 -0700, wrote: > I've been using the cubictemp template module (from www.nullcube.com) > with some reasonable success for a while. Somehow, I have recently > had these questions about it: > > 1. Anybody else using this? Any problems? I used it quite a bit. The biggest problem is, that when used with HTML the template (not the result) is not valid HTML and thus doesn't look good when viewed in a browser and in a syntax hilighting editor. That's why I switched to SimpleTAL recently. > 2. Does it work with python 2.3? Any changes required to make it > work? Don't know, but I think it should work, the code is quite simple. Regards, Florian From davesum99 at yahoo.com Wed Aug 13 23:50:18 2003 From: davesum99 at yahoo.com (smarter_than_you) Date: 13 Aug 2003 20:50:18 -0700 Subject: 3 new slogans Message-ID: 1) Python made me rich 2) Python saved my life 3) Python changed my mind put them on T-shirts. Collect all three!! From alanmk at hotmail.com Thu Aug 14 06:08:00 2003 From: alanmk at hotmail.com (Alan Kennedy) Date: Thu, 14 Aug 2003 11:08:00 +0100 Subject: 3 new slogans References: Message-ID: <3F3B5F80.3E7DE934@hotmail.com> Graham Fawcett wrote: > or, with apologies to Clarke, > > "Any sufficiently advanced technology is indistinguishable from Python" I *really* like this one. Only problem is, you have to be a sci-fi head to get it: No problem for me: I've been reading Arthur C. Clarke since I was 8 years old. regards, -- alan kennedy ----------------------------------------------------- check http headers here: http://xhaus.com/headers email alan: http://xhaus.com/mailto/alan From tim.hochberg at ieee.org Sun Aug 24 16:40:24 2003 From: tim.hochberg at ieee.org (Tim Hochberg) Date: Sun, 24 Aug 2003 13:40:24 -0700 Subject: Python is darn fast (was: How fast is Python) In-Reply-To: <2259b0e2.0308240638.38350cba@posting.google.com> References: <2259b0e2.0308230737.8a9bc1c@posting.google.com> <2259b0e2.0308240638.38350cba@posting.google.com> Message-ID: Michele Simionato wrote: > I finally came to the conclusion that the exceeding good performance > of Psyco was due to the fact that the function was called a million > times with the *same* argument. Evidently Psyco is smart enough to > notice that. Changing the argument at each call > (erfc(0.456) -> i/1000000.0) slows down Python+Psyco at 1/4 of C speed. > Psyco improves Python performance by an order of magnitude, but still it > is not enough :-( This is not suprising. Last I checked, Psyco does not fully compile floating point expressions. If, I rememeber correctly (though every time try to delve too deeply into Psyco my brains start oozing out my ears), there are three ways a in which a given chunk of code evaluated. At one level, which I'll call #1, Psyco generates the machine code(*) for the expression. At a second level, Psyco calls out to C helper functions, but still works with unboxed values. At the third level, Psyco punts and creates a Python object and hands things off to the interpreter. Most integer functions operate at level #1, so they tend to be quite fast. Most floating point operations operate at level #2, so they have a certain amount of overhead, but are still much faster than unpsyco (sane?) Python. I believe the reason for this is that x86 floating point operations are very messy, so Armin punted... (*) Armin is working on virtual machine implementation of Psyco, so it should be available on non x86 machines soon. FWIW, -tim > I was too optimistic! > > Here I my numbers for Python 2.3, Psyco 1.0, Red Hat Linux 7.3, > Pentium II 366 MHz: > > $ time p23 erf.py > real 0m3.245s > user 0m3.164s > sys 0m0.037s > > This is more than four times slower than optimized C: > > $ gcc erf.c -lm -O3 > $ time ./a.out > real 0m0.742s > user 0m0.725s > sys 0m0.002s > > Here is the situation for pure Python > > $time p23 erf.jy > real 0m27.470s > user 0m27.162s > sys 0m0.023s > > and, just for fun, here is Jython performance: > > $ time jython erf.jy > real 0m44.395s > user 0m42.602s > sys 0m0.389s > > ---------------------------------------------------------------------- > > $ cat erf.py > import math > import psyco > psyco.full() > > def erfc(x): > exp = math.exp > > p = 0.3275911 > a1 = 0.254829592 > a2 = -0.284496736 > a3 = 1.421413741 > a4 = -1.453152027 > a5 = 1.061405429 > > t = 1.0 / (1.0 + p*x) > erfcx = ( (a1 + (a2 + (a3 + > (a4 + a5*t)*t)*t)*t)*t ) * exp(-x*x) > return erfcx > > def main(): > erg = 0.0 > > for i in xrange(1000000): > erg += erfc(i/1000000.0) > > if __name__ == '__main__': > main() > > -------------------------------------------------------------------------- > > # python/jython version = same without "import psyco; psyco.full()" > > -------------------------------------------------------------------------- > > $cat erf.c > #include > #include > > double erfc( double x ) > { > double p, a1, a2, a3, a4, a5; > double t, erfcx; > > p = 0.3275911; > a1 = 0.254829592; > a2 = -0.284496736; > a3 = 1.421413741; > a4 = -1.453152027; > a5 = 1.061405429; > > t = 1.0 / (1.0 + p*x); > erfcx = ( (a1 + (a2 + (a3 + > (a4 + a5*t)*t)*t)*t)*t ) * exp(-x*x); > > return erfcx; > } > > int main() > { > double erg=0.0; > int i; > > for(i=0; i<1000000; i++) > { > erg = erg + erfc(i/1000000.0); > } > > return 0; > } > > Michele Simionato, Ph. D. > MicheleSimionato at libero.it > http://www.phyast.pitt.edu/~micheles/ > ---- Currently looking for a job ---- From bdesth.nospam at removeme.free.fr Sun Aug 31 18:23:35 2003 From: bdesth.nospam at removeme.free.fr (Bruno Desthuilliers) Date: Mon, 01 Sep 2003 00:23:35 +0200 Subject: exception question In-Reply-To: References: Message-ID: <3f527300$0$16153$626a54ce@news.free.fr> Gon?alo Rodrigues wrote: > Hi, > > For error processing I found convenient maintaining a dictionary where > the keys are exception *classes* and the values are callables. Of > course, for this to work, exception classes have to be hashable which > I happily found that they were. So my question is, can I count on this > behaviour? Or is this behaviour I should not count on? (I found > nothing on the docs about it, thus the question). Did you try ? I guess you didn't : Python 2.2.2 (#2, Feb 5 2003, 10:40:08) [GCC 3.2.1 (Mandrake Linux 9.1 3.2.1-5mdk)] on linux-i386 Type "help", "copyright", "credits" or "license" for more information. >>> class TestError(Exception): pass ... >>> d = {TestError: "TestError"} >>> d {: 'TestError'} >>> l = [1,2,3] >>> d = {l : "truc"} Traceback (most recent call last): File "", line 1, in ? TypeError: list objects are unhashable >>> BTW, it seems that classes are hashable !-) Bruno From robin at jessikat.fsnet.co.uk Sat Aug 2 18:45:27 2003 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Sat, 2 Aug 2003 23:45:27 +0100 Subject: boost python & 2.3 In-Reply-To: <200308021720.44862.drlinux@columbus.rr.com> References: <200308021720.44862.drlinux@columbus.rr.com> Message-ID: In message <200308021720.44862.drlinux at columbus.rr.com>, Dave Reed writes >On Saturday 02 August 2003 12:31, Robin Becker wrote: >> I'm having trouble building boost python with Python 2.3 & msvc. I >don't >> remember this with 2.2.3 so I guess it must be related to 2.3. I'm >> seeing lots of this >> >> C:\Python\devel\boost_1_30_0\boost/detail/ob_call_traits.hpp(89) : see >> declaration of 'call_traits_chooser' >> C:\Python\devel\boost_1_30_0\boost/detail/ob_call_traits.hpp(90) : >error >> C2059: syntax error : '{' >> C:\Python\devel\boost_1_30_0\boost/detail/ob_call_traits.hpp(90) : >error >> C2143: syntax error : missing ';' before '{' >> C:\Python\devel\boost_1_30_0\boost/detail/ob_call_traits.hpp(93) : >error >> C2143: syntax error : missing ';' before '{' >> C:\Python\devel\boost_1_30_0\boost/detail/ob_call_traits.hpp(94) : >error >> C2955: 'type' : use of class template requires >> template argument list >> >> Any ideas? >> -- >> Robin Becker > >What version of boost are you using? 1.30.0 won't work with Python >2.3; however, the CVS version of boost does work with Python >2.3. David Abrahams has indicated this on the boost list and I can >confirm that it does work with Python 2.3 (at least on a Solaris 9 >system). > >Dave I'm using boost_1_30_0 so I guess that's the problem. I'll try and get the CVS version. Do I need to get the whole boost tree? -- Robin Becker From kalmas at udm.ru Tue Aug 19 19:55:04 2003 From: kalmas at udm.ru (Oleg Leschov) Date: Tue, 19 Aug 2003 23:55:04 +0000 (UTC) Subject: generators improvement References: Message-ID: Duncan Booth: DB> Oleg Leschov wrote in DB> news:bhtiij$psc$2 at ocasysi.rubbernet.net: >> What needs to be done is to allow yield return something - whatever was >> passed to the .next() thing from caller.. >> Easy and obvious, isn't it? So is there any principal problem with this >> idea that would prevents its implementation? DB> Please read PEP 288, http://www.python.org/peps/pep-0288.html DB> in particular the section: >> Rejected Alternative >> One idea for passing data into a generator was to pass an argument >> through next() and make a assignment using the yield keyword: >> >> datain = yield dataout >> . . . >> dataout = gen.next(datain) >> >> The intractable problem is that the argument to the first next() call >> has to be thrown away, because it doesn't correspond to a yield >> keyword. not quite so... for example, such argument may be passed as the generator function's parameter, if it is defined. Of cause, this would make first .next() and the rest of them distinct. But, the question is - if there is .next(), why there's no .first()? IMHO, current syntax does not truthfully reflect the nature of real generators. These are not those that generate a sequence without the beginning, there is indeed a first element... While any but first .next() works with concrete yield(), the first next() does not - it acts as a thing that starts generator's execution from its entry point; thus, logically, it should be different thing than the next() - perhaps .init() or .first() or .run(), that either wouldn't take any arguments or will pass them as generator function's parameters (which are not allowed at all now, anyway). Of cause, this would not cause any incompatibilities with current behavior, as long as there is no arguments to .next() and no parameters for generator. From mpeuser at web.de Thu Aug 21 15:02:17 2003 From: mpeuser at web.de (Michael Peuser) Date: Thu, 21 Aug 2003 21:02:17 +0200 Subject: how fast is Python? References: <3f43e5cf$0$49115$e4fe514c@news.xs4all.nl> Message-ID: "Neil Padgen" schrieb im Newsbeitrag news:bi2ki9$pai$1 at nntp0.reith.bbc.co.uk... > On Wednesday 20 August 2003 21:19, Irmen de Jong wrote: > > Investigate Psyco. > [...] > > produced the following results on a 1.7GHz P4 running FreeBSD 4.8: > > > python2.2 pi.py > calcPi calculated pi as 3.14159315359 in 3.87623202801 seconds > speedyPi calculated pi as 3.14159315359 in 0.790405035019 seconds > > -- Neil This is certainly correct. My experiance with more general programs running for a few minutes shows that you can expect a speed-up of two. This is still impressiv when you have your results in 5 instead of 10 minutes.. Kindly Michael P From danbmil99 at yahoo.com Fri Aug 8 01:22:04 2003 From: danbmil99 at yahoo.com (dan) Date: 7 Aug 2003 22:22:04 -0700 Subject: random changes References: Message-ID: "Andrew Dalke" wrote in message news:... > Isn't the random.WichmannHill implement the old code? If so, > what about the following untested code? Tried it -- something's different, see my post about this ... > Failing that, what about copying the old Python code as "oldrandom.py" > then doing > > import oldrandom as random Aah, that did it! I love this group!! It never even occured to me that the lib wasn't in C. Duh! thanks - dan From jmiller at stsci.edu Sat Aug 30 10:58:54 2003 From: jmiller at stsci.edu (Todd Miller) Date: 30 Aug 2003 10:58:54 -0400 Subject: ANN: numaray-0.7 Message-ID: <1062255534.3459.209.camel@localhost.localdomain> numarray-0.7 has been released and is now available on Source Forge. Numarray is an array processing package designed to efficiently manipulate large multi-dimensional arrays. Numarray is modelled after Numeric and features c-code generated from python template scripts, the capacity to operate directly on arrays in files, and improved type promotions. I. ENHANCEMENTS 1. Object Arrays numarray now has an object array facility. numarray.objects provides array indexing and ufuncs for fixed length collections of arbitrary Python objects. 2. Merger of NumArray/ComplexArray classes Numarray's NumArray and ComplexArray classes have been unified into a single class. Thus, a single base class can be used to derive array classes which operate on integer, real or complex numbers. Thanks to Colin Williams for this suggestion. 3. Indexing improvements The implementation of numarray's indexing has been simplified and improved. Ad-hoc logic for getting single array elements fast has been replaced by a full conversion to C of the top level of numarray's Python indexing code. The resulting code is simpler, prototyped in Python, and adds an additional kind of indexing which occurs entirely in C for speed: sub-arrays. Slicing and array indexing, however, still involve significant amounts of Python code. 4. IEEE Special Value Constants Standard constants for nan, plus_inf, minus_inf, and inf have been added to numarray.ieeespecial making it easier to assign IEEE special values to arrays in addition to finding or replacing special values. 5. Better Numeric interoperability (wxPyPlot port) numarray-0.7 addresses a couple compatibility and speed issues which hindered numarray's use with wxPyPlot. numarray now works fine with the wxPyPlot demos by changing "import Numeric" to "import numarray as Numeric". II. BUGS FIXED See http://sourceforge.net/tracker/?atid=450446&group_id=1369&func=browse for more details. 793421 PyArray_INCREF / PyArray_XDECREF deprecated 791354 Integer overflow bugs? 785458 Crash subclassing the NumArray class 784866 astype() fails sometimes 779755 Mac OS 10 installation problem 740035 Possible problem with dot III. CAUTIONS 1. numarray extension writers should note that the documented use of PyArray_INCREF and PyArray_XDECREF (in numarray) has been found to be incompatible with Numeric and has therefore been deprecated. numarray wrapper functions using PyArray_INCREF and PyArray_XDECREF should switch to ordinary Py_INCREF and Py_XDECREF. 2. Writers of numarray subclasses should note that the "protected" _getitem/_setitem interface for NDArray has changed. WHERE ----------- Numarray-0.7 windows executable installers, source code, and manual is here: http://sourceforge.net/project/showfiles.php?group_id=1369 Numarray is hosted by Source Forge in the same project which hosts Numeric: http://sourceforge.net/projects/numpy/ The web page for Numarray information is at: http://stsdas.stsci.edu/numarray/index.html Trackers for Numarray Bugs, Feature Requests, Support, and Patches are at the Source Forge project for NumPy at: http://sourceforge.net/tracker/?group_id=1369 REQUIREMENTS ------------------------------ numarray-0.7 requires Python 2.2.2 or greater. AUTHORS, LICENSE ------------------------------ Numarray was written by Perry Greenfield, Rick White, Todd Miller, JC Hsu, Paul Barrett, Phil Hodge at the Space Telescope Science Institute. Thanks go to Jochen Kupper of the University of North Carolina for his work on Numarray and for porting the Numarray manual to TeX format. Thanks also to Edward C. Jones, Francesc Alted, Paul Dubois, Eric Jones, Travis Oliphant, Pearu Peterson, Colin Williams, and everyone who has contributed with comments and feedback. Numarray is made available under a BSD-style License. See LICENSE.txt in the source distribution for details. -- Todd Miller jmiller at stsci.edu From srijit at yahoo.com Fri Aug 22 01:04:47 2003 From: srijit at yahoo.com (srijit at yahoo.com) Date: 21 Aug 2003 22:04:47 -0700 Subject: Embedding a chart in excel References: Message-ID: <221d8dbe.0308212104.c4e45@posting.google.com> Hello, Refer the following link: http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&frame=right&th=6eaef82c8c0d9548&seekm=37ee60c8.0308202344.f470d26%40posting.google.com#link11 Does it help you? If it doesn't, let me know what improvements are required. Regards, Srijit Stephen Boulet wrote in message news:... > I'm having trouble scripting Excel to embed a chart from python. > > Say I have created a sheet object and a workbook object, "xlSheet" and > "xlBook". > > Creating a chart in front of my sheet is as easy as: > > xlSheet.Select() > xlChart = xlBook.Charts.Add() > > Now how do I tell it to go embed itself in my sheet? In VBA, it might be > something like: > > xlChart.Location Where:=xlLocationAsObject, Name:=xlSheet.Name > > Thanks. > > (Is there a newsgroup/list with more of a focus on issues like this than > c.l.py?) > > -- Stephen From op73418 at mail.telepac.pt Thu Aug 7 06:15:41 2003 From: op73418 at mail.telepac.pt (Gonçalo Rodrigues) Date: Thu, 07 Aug 2003 11:15:41 +0100 Subject: Bug? If not, how to work around it? References: <060820031458029244%mday@apple.com> <09udnV37oMEUDqyiU-KYgw@comcast.com> Message-ID: On Thu, 07 Aug 2003 00:54:03 +0100, Gon?alo Rodrigues wrote: >On Wed, 6 Aug 2003 19:46:39 -0400, "Terry Reedy" >wrote: > >> >>"Gon?alo Rodrigues" wrote in message >>news:upv2jv4eeusj7bli30j7a7ikd0cq3njvm4 at 4ax.com... >>> >I changed the __iter__ method to the following, and it seems to do >>what >>> >you want: >>> > >>> > def __iter__(self): >>> > return iter(self.__obj) >> >>> But this is precisely what I don't want to do. >> >>If you don't want to do what works, >>why ask us to bother answering? >> > >Because it may not work. That is, the use case I have in mind serves >as proxy for an object that may or may not have __iter__. IOW if I >stick __iter__ I have to code a second class, etc... etc... Oh well... > Replying to myself: Just to make things clearer, having iter(self.__obj) as in def __iter__(self): return iter(self.__obj) Would mean that my proxy class would become an iterable. And that is not what I want because *other* parts in my code check that an object is in iterable by looking for __iter__. Suffice it to say that fake iterables, although not the worst thing in the world, are not desirable. Maybe this means that I have to approach things in another way. Humpf. With my best regards, G. Rodrigues From andreas.kuntzagk at mdc-berlin.de Tue Aug 19 04:25:02 2003 From: andreas.kuntzagk at mdc-berlin.de (Andreas Kuntzagk) Date: Tue, 19 Aug 2003 10:25:02 +0200 Subject: decode a url References: Message-ID: On Tue, 19 Aug 2003 09:37:20 +0200, Invalid User wrote: > Is there a function/module to decode url's in python? So far, I have come > across "urllib.encode" for encoding, which the opposite of I am looking > for. Quick search on google: http://groups.google.com/groups?q=group%3Acomp.lang.python+urldecode reveals: http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&selm=jjb5-390295.16085712062002%40newsstand.cit.cornell.edu which proposes cgi.parse_qsl test: >>> import cgi >>> import urllib >>> cgi.parse_qsl(urllib.urlencode({"test1":1,"test2":3})) [('test1', '1'), ('test2', '3')] >>> dict(_) {'test1': '1', 'test2': '3'} So seems to work Andreas From gafStopSpamData at ziplink.stopallspam.net Wed Aug 20 18:05:53 2003 From: gafStopSpamData at ziplink.stopallspam.net (Gary Feldman) Date: Wed, 20 Aug 2003 22:05:53 GMT Subject: Idle Help font size References: Message-ID: On Tue, 19 Aug 2003 07:31:49 +0200, "vincent wehren" wrote: >You propobably would have to modify textView.py. See the CreateWidgets >method of the TextViewer class. You could add a font option to >self.textView... Thanks. I had to dig through a ton of stuff on tkinter, and tried all sorts of permutations until I was able to get it to work, and then get it to work for the debugger as well. But it's ok now. I suspect my other gripe isn't nearly as easy, namely I really want it all in one window. It's a rough tradeoff between using emacs to do most of the editing, and then using IDLE for debugging and minor editing. But it's just too darn difficult to find the right text window in IDLE, plus it forces me to change my visual focus. But that's for another time. Gary From halley at dnspython.org Sat Aug 30 17:21:40 2003 From: halley at dnspython.org (Bob Halley) Date: 30 Aug 2003 14:21:40 -0700 Subject: Reading and manipulating binary data In-Reply-To: References: Message-ID: "Dave" writes: > I am really confused as to how to use binary data with python. I am > currently developing a lightweight RADIUS server, which gets UDP datagrams > from a client formatted like so: > > 0 1 2 3 > 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 > +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ > | Code | Identifier | Length | > +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ > | | > | Request Authenticator | > | | > | | > +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ > | Attributes ... > +-+-+-+-+-+-+-+-+-+-+-+-+- > > I can read() the data easily enough from the socket. However, when I have > read it, it is very difficult to manipulate. I can't convert it to an > integer or a string which is driving me crazy... I have seen a lot of posts > recommending struct for dealing with binary data, but I can't get it to like > mine. I get all sorts of errors, like lengths don't match format etc. struct.unpack requires the input string to be the exact length of whatever you're trying to unpack. You need to slice your packet string to get the part you want to unpack. E.g.: import struct code, identifier, length = struct.unpack('!BBH', packet[0:4]) authenticator = packet[4 : 4 + length] /Bob From p-abel at t-online.de Tue Aug 5 17:00:23 2003 From: p-abel at t-online.de (Peter Abel) Date: 5 Aug 2003 14:00:23 -0700 Subject: abstraction of the column names (classes) References: Message-ID: <13a533e8.0308051300.2d463b04@posting.google.com> Wiebke P?tzold wrote in message news:... > Hi all! > > I create a database that contains a table. 'Nachname' is one of 13 > column names. This program can search for > a special letter. In my example it is 'ra'. and the search takes place > in 'Nachname'. 'ra' takes place within a word. This is solved with > regular expression. So that I can limit my search. > For example: I can search for 'ra' and it is not relevant wich letters > follow or wich letters are in front of 'ra'. > Now I want to abstract the column name 'Nachname'. So I search in an > unknown column. Only the user of the program should determine in wich > class the search takes place. This input should happen in the view > lines of testing the class. > My task is it to change the program that a abstraction of the column > names takes place. > Please give me a detailed answer. If it is possible the changed > program because I am very new in Python and I am orientationless. > > This is the program > > import sys > import Mk4py > import re > > db = Mk4py.storage("c:\\datafile.mk",1) > vw = db.view("people") > > class PatternFilter: > def __init__(self, pattern): > self.pattern = re.compile(pattern) > > def __call__(self, row): > try: > nachname = row.Nachname > except AttributeError: > return 0 > return self.pattern.search(nachname)is not None > > vf = vw.filter(PatternFilter("ra.*")) > > for r in vf: > print vw[r.index].Nachname RegEx are really great and there are a lot of problems you can only solve with them. But if I understand you right your problem is to find a string where a substring is to be in, the simple string operation does the work: if String.find(substring) > -1: **find** will give you the position in String where substring will occure the 1rst time and -1 if substring doesn't occur. e.g. >>> nameList=['Meyer', 'Maxon', 'Johnson', 'Mueller'] >>> for name in nameList: ... if name.find('er')>-1: ... print name ... Meyer Mueller >>> So if you can get your columns contents in **ColumnList** and your searchpattern in **SearchPattern** so the following function could do the work: def getPatternMatches(ColumnList,SearchPattern): foundList=[] for n in ColumnList: if n.find(SearchPattern) > -1: foundList.append(n) return foundList Regards Peter From hnease at midsouth.rr.com Mon Aug 25 18:57:44 2003 From: hnease at midsouth.rr.com (Howard Nease) Date: Mon, 25 Aug 2003 22:57:44 GMT Subject: Advice to a Junior in High School? Message-ID: Hello, everyone. I would appreciate any advice that someone could give me on my future career path. Here is my situation: I am a bright Junior in a very well-respected private high school, taking almost all AP and accelerated classes. I am HIGHLY interested in technology, more specifically the field of Computer Science and software engineering. I have heard a whole lot about the fact that the market for software engineers nowadays is *HORRIBLE*, and that I should double major or perhaps go into a field of study in which I'm not very interested. I would be devastated were I to find the need to leave computer science. I love the subject, and I've wanted to be a computer scientist ever since I was 12 years old. Does anyone have any advice for me and my future? What should I study in college? Will the market for jobs get better? Do I have any hope at all of finding a decent-paying job in compsci? What languages do you suggest that I study (I'm already studying Python)? thank you very much for your help! --shn From cookedm+news at physics.mcmaster.ca Thu Aug 28 00:25:45 2003 From: cookedm+news at physics.mcmaster.ca (David M. Cooke) Date: Thu, 28 Aug 2003 00:25:45 -0400 Subject: Way to distinguish between POST and GET data in Python CGIs? References: Message-ID: At some point, Simon Willison wrote: > Hi all, > > I've been experimenting with Python CGIs, and more recently > mod_python. The FieldStorage class used by Python's cgi module and > mod_python's utility library allows form data sent by a user's browser > to be easily accessed, but doesn't appear to provide any method of > distinguishing between data sent by POST and data sent by GET. standard CGI variables: the environment variable REQUEST_METHOD is set to the method (GET or POST). This should do the trick: if os.environ.get('REQUEST_METHOD', 'GET').upper() != 'POST': print 'This script must be accessed using a POST method' else: # do stuff form = cgi.FieldStorage() -- |>|\/|< /--------------------------------------------------------------------------\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca From elainejackson7355 at home.com Sun Aug 17 09:05:13 2003 From: elainejackson7355 at home.com (Elaine Jackson) Date: Sun, 17 Aug 2003 13:05:13 GMT Subject: bitwise not - not what I expected References: Message-ID: "Tim Peters" wrote in message news:mailman.1061098645.13097.python-list at python.org... | To understand your example above, note that | binary 10010 actually has an unbounded number of 0 bits "to the left": | | ...00000010010 = 13 | | The bitwise inversion of that therefore has an unbounded number of 1 bits | "to the left": | | ...11111101101 = -19 ** What you're saying, the way I read it, is that 5+S=(-19), where S is the (divergent) sum of all the powers 2^k of 2 with k>=5. I'm still at sea, in other words. | Python can't *guess* how many bits you want to keep. ** But it could if someone had told it that the leftmost nonzero digit is the place to start. I just assumed somebody had told it that. | Python represents negative integers in unbounded 2's-complement form ** Now we're getting someplace. That was the missing piece in my puzzle. Thanks for the help. Peace, EJ From aahz at pythoncraft.com Wed Aug 20 10:01:23 2003 From: aahz at pythoncraft.com (Aahz) Date: 20 Aug 2003 10:01:23 -0400 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: Message-ID: In article , Doug Tolton wrote: > >Perhaps my post was a bit rude, I shouldn't have automatically assumed >you were new to this NG, although I am a bit baffled at hearing a long >time c.l.p reading calling Every anything but a troll. You have to >admit, that is atypical. I have been very careful to not label Brandon as a troll. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From tismer at tismer.com Wed Aug 6 13:55:47 2003 From: tismer at tismer.com (Christian Tismer) Date: Wed, 06 Aug 2003 19:55:47 +0200 Subject: stackless python: continuation module? In-Reply-To: <20030725163213.09785.00000389@mb-m11.aol.com> References: <20030725152844.18704.00000635@mb-m18.aol.com> <20030725163213.09785.00000389@mb-m11.aol.com> Message-ID: <3F314123.6040401@tismer.com> TheDustbustr wrote: > Nevermind, I found a post to the Stackless mailing list that said that > continuation was a builtin but now is not in the distribution. So uthreads is > no more. I'm supposed to use 'import stackless' instead. Correct. > Anyone have any source code using the stackless module? I found no > documentation about this module. At the moment, there is only help(stackless), and at the moment, this crashes due to something bad I have to fix. The uthread will re-appear pretty soon, not using continuations any longer. cheers - chris -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 pager +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From nicola-mingotti_NOSPAM at libero.it Tue Aug 5 07:57:45 2003 From: nicola-mingotti_NOSPAM at libero.it (Nicola Mingotti) Date: Tue, 05 Aug 2003 13:57:45 +0200 Subject: Linux & =?iso-8859-1?q?ex=E9cutable?= References: Message-ID: On Mon, 04 Aug 2003 16:52:33 +0200, habermacher wrote: > Bonjour, > > Est-ce que quelqu'un sait quel est le logiciel ? utiliser sous linux > pour cr?er un ex?cutable correspondant ? du code source en python ? > > Je vous remercie par avance de vos r?ponses. > > Emilie. If you only want to start you app. as if it was a Linux command follow this : - suppose your source code is 'foo.py' - suppose your python interpreter is in '/usr/bin/python' ( you can see it doing '$> whereis python' ) then : 1) put as first line of your file 'foo.py' the line '#!/usr/bin/python' 2) from you terminal '$> chmod +x foo.py ' try it with '$>./foo.py' bye . Nico From mis6 at pitt.edu Fri Aug 29 15:20:24 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 29 Aug 2003 12:20:24 -0700 Subject: how to find out the OO hierachy via the documentation? References: Message-ID: <2259b0e2.0308291120.998cf54@posting.google.com> "Leo" wrote in message news:... > hi all > > newbie question: how do i find out the OO hierarchy of a class in the python > docu? > > the story: i want do play with the web server classes. so the first task > would be a basic server with SimpleHTTPServer. in the docu i've read about > the test() function but i couldn't find this function in the > SimpleHTTPServer class and even not in the BaseHTTPServer class which might > be the ancestor. > > so now i'd like to walk through the OO hierarchy of SimpleHTTPServer... > > any help is appreciated! > > cheers, leo help(SimpleHTTPServer) Michele Simionato, Ph. D. MicheleSimionato at libero.it http://www.phyast.pitt.edu/~micheles --- Currently looking for a job --- From amk at amk.ca Wed Aug 20 08:23:33 2003 From: amk at amk.ca (A.M. Kuchling) Date: Wed, 20 Aug 2003 07:23:33 -0500 Subject: Problem installing ppgplot References: Message-ID: On 20 Aug 2003 12:07:06 GMT, Enno Middelberg wrote: > I had the suspicion that the "-lcpgplot" was not correct, as the > pgplot distribution does not contain any other files named cpgplot.* > except for cpgplot.h and a cpgplot.c demonstration file. The correct file to look for is libcpgplot.a. --amk From gregbrunet at NOSPAMsempersoft.com Mon Aug 18 00:29:51 2003 From: gregbrunet at NOSPAMsempersoft.com (Greg Brunet) Date: Sun, 17 Aug 2003 23:29:51 -0500 Subject: Python form oriented library References: Message-ID: If I understand what you want, GNUe sounds like a close match: http://www.gnuenterprise.org/project/what.html especially the Forms client. If you're into writing more of your own code, something like PythonCard might be another possibility. I expect though, that you'll end up writing a lot of code compared to doing it in like something like FileMaker Pro. -- Greg "Caleb Land" wrote in message news:pan.2003.08.17.20.21.45.109000 at rochester.rr.com... > Hello, > I'm writing a small business accounting type program where the interface > is a bunch of forms that represent tables in a database. The interface is > usually used completely with the keyboard, but the mouse may also be used. > > The software does POS, inventory, accounting, etc. > > The widgets are mostly text entries. > > Are there any Python libraries that are targetted to this style of > interface? > > If not, does anybody have references to libraries/resources in other > languages that might be helpful in designing my own (APIs, design > documents, etc)? > > I've tried googling, but I don't know exactly how to word my request. > > Sincerely, > Caleb Land > (bokonon at rochester.rr.com) From markus_wankus at hotmail.com Mon Aug 11 21:19:14 2003 From: markus_wankus at hotmail.com (Markus Wankus) Date: Mon, 11 Aug 2003 21:19:14 -0400 Subject: win32, COM, and Solidworks (again) - Still Trying References: <87he4qykqv.fsf@pobox.com> <877k5jwx76.fsf@pobox.com> Message-ID: On 12 Aug 2003 01:12:29 +0100, John J. Lee wrote: > Markus Wankus writes: > >> On 09 Aug 2003 15:21:44 +0100, John J. Lee wrote: >> >> > Markus Wankus writes: >> > >> >> On Thu, 7 Aug 2003 23:06:01 +1000 (EST), Andrew MacIntyre >> >> wrote: >> > [...] >> >> > If you need to go beyond the IDispatch interface, Thomas Heller's >> >> ctypes >> >> > package looks to be your only option, short of creating a full- >> blown >> >> > Pythonwin wrapper (ala Pythonwin's MAPI support) for the >> >> SolidWorks COM >> >> > API. >> >> > >> >> >> >> Yes, I was looking into this but was a little mystified at first. I >> >> generated the python wrapper and had a look inside, but was unsure of >> >> the extent of the Python code I was going to be required to write, as >> >> well as type conversions. >> > >> > He wasn't talking about the automatically-generated makepy Python >> > code, but rather hand-crafted C code wrapper around a particular >> > vtable COM interface (though Mark may have some tools to help with the >> > process of writing such wrappers, I don't think it's automated). >> > >> > ctypes is an easy way of doing it than writing a C wrapper. >> > >> >> Hmmm.. I guess I am not following. I'll go back to the ctypes page >> again and give it another go. > > Ah, maybe it was me who wasn't following. I haven't looked at the > ctypes COM support. I was thinking you were referring to the > win32all-generated Python code, but maybe ctypes does Python code > generation too, and you were referring to that? Dunno. > > > John > Yeah - ctypes generates Python code as well and that is what I was referring to. Anyway - thanks to all who responded. I just wish I knew a little more...ah well. You can't beat experience. Too bad it takes so long. -- Markus From Dick.Zantow at lexisnexis.com Fri Aug 29 11:16:56 2003 From: Dick.Zantow at lexisnexis.com (rzed) Date: Fri, 29 Aug 2003 11:16:56 -0400 Subject: Style question... References: <3F4DFAAC.1356C276@engcorp.com> Message-ID: Steve Lamb wrote: > On 2003-08-28, rzed wrote: >> A better solution might be to physically restrain the posters of >> tab-infested code from doing that, but there are only so many >> hours in the day. And if OE wouldn't do what it does ... but then, >> where would be the fund in that? > > Well, actually, a better solution would be to skip OE for > something sensible, no? :) On my own hook, I'm doing that, but here in the office I don't have the choice. I do have the choice to spell "fun" correctly, though I see I opted not to. -- rzed From llothar at web.de Wed Aug 27 14:35:39 2003 From: llothar at web.de (Lothar Scholz) Date: 27 Aug 2003 11:35:39 -0700 Subject: ANN: BlackAdder V1.0.0 References: <3f48a498$3$219$fa0fcedb@lovejoy.zen.co.uk> <1Kj2b.61523$bo1.38258@news-server.bigpond.net.au> <3f4a7ba0$0$250$fa0fcedb@lovejoy.zen.co.uk> Message-ID: <6ee58e07.0308271035.47219550@posting.google.com> Nick Vargish wrote in message news:... > "BadJake" writes: > > > This way I get my resellers commission. > > Ah, greed. Let me guess you have never ever were responsible for selling something and make a living with it. Most vendors have a reseller program because it is as hard work as writting the software. From tim.one at comcast.net Thu Aug 14 10:22:50 2003 From: tim.one at comcast.net (Tim Peters) Date: Thu, 14 Aug 2003 10:22:50 -0400 Subject: bsddb module bug?: doesn't release locks and seg faults In-Reply-To: Message-ID: [Jane Austine] > There is a test code named test_env_close in bsddb/test, but it > doesn't test the case thoroughly. There seems to be a bug in closing > the db environment first -- the lock is not released, and sometimes > it seg-faults. > ... Please submit bug reports on SourceForge: http://sf.net/tracker/?atid=105470&group_id=5470 The best use for a bug report on comp.lang.python is as an object lesson for your grandchildren: 40 years from now you can search the archives for it, and tell the little darlings "see? if I had only put that on SourceForge instead, the bug would have been fixed by now". From hungjunglu at yahoo.com Tue Aug 26 22:57:53 2003 From: hungjunglu at yahoo.com (Hung Jung Lu) Date: 26 Aug 2003 19:57:53 -0700 Subject: Aspect oriented Everything? References: <32cc321c.0308221316.2f5793ac@posting.google.com> <6ee58e07.0308230459.24f53b64@posting.google.com> Message-ID: <8ef9bea6.0308261857.1b44a5b7@posting.google.com> Steven Ketcham wrote in message > AOP was very difficult to explain, debug and implement. It did not > obviously replace any of our current procedures and at best it was > perceived as very heavy-weight. The conclusion on AOP was that it was a > neat concept but there was no immediate benefit for using it. > > On Sat, 23 Aug 2003 22:00:22 +0900, Lothar Scholz wrote: > > I don't like it because it breaks encapsulation and splitters the code > > over a few files. Maybe that can be solved with new kind of editors > > but it is much more easy to result in a big confusion. AOP is the latest effort in code factorization. Code factorization started with the goto statement, then loops, then functions, then classes and methods. And now, AOP. If you write programs in OOP long enough, you will realize that there are code spots that are not factorized. For example, you register to a event listener at the beginning and de-register at the end of a method. If you find yourself writing very similar codes in various classes or methods all over places, you are not factoring your code efficiently. It's not your fault, it's just that OOP cannot do certain types of code factorization. Before having loops, a repetitive task may look like x = x + 1 x = x + 1 x = x + 1 But when you have loops, you can factor the three lines of code into for i in range(3): x = x + 1 Similarly, before object-oriented programming, you have data structure that are very similar, say, A and B, A has (color, shape) and B has (color, shape, weight), with OOP you can use inheritance, and factor out the common code. If we view OOP and inheritance as a vertical dimension in code factorization, AOP would be a new horizontal dimension in code factorization. Hence, people use terms like "aspect weaving". Some people don't like AOP because it violates encapsulation in the vertical dimension. But this way of thinking is kind of, erh, unidimensional. Because conversely, a program that is built from purely AOP is encapsulated in its own aspect dimension, and the usage of OOP in that case would violate the encapsulation in the horizontal dimension. The fact is, both factorizations are needed in the real world. Aspect-oriented coding and object-oriented coding are like the conjugate variables in quantum mechanics, whether you use one picture or the other, at the end of the day they are equivalent, but in some circumstances it's better to use one than the other. (If you know Fourier transform, you know what I mean. A localized wave packet in time necessarily means a spread-out packet in frequency, and vice-versa. You can't have encapsulation both ways.) regards, Hung Jung From mack at incise.org Fri Aug 29 15:51:34 2003 From: mack at incise.org (mackstann) Date: Fri, 29 Aug 2003 14:51:34 -0500 Subject: Getting class name In-Reply-To: <3f4fa8f2$0$49106$e4fe514c@news.xs4all.nl> References: <3f4fa8f2$0$49106$e4fe514c@news.xs4all.nl> Message-ID: <20030829195134.GC9311@incise.org> On Fri, Aug 29, 2003 at 09:26:47PM +0200, Irmen de Jong wrote: > Or if you're using Python 2.3+ : > > >>> import inspect > >>> def foo(): > ... return inspect.getframeinfo(inspect.currentframe())[2] > ... > >>> foo() > 'foo' > >>> The following works for me in python 2.2: >>> import traceback >>> def foo(): ... return traceback.extract_stack()[-1][2] ... >>> foo() 'foo' Also, doing len() on traceback.extract_stack() can give you an idea of what "depth" you're at (of nested function calls). -- m a c k s t a n n mack @ incise.org http://incise.org Troubled day for virgins over 16 who are beautiful, wealthy, and live in eucalyptus trees. From bokr at oz.net Wed Aug 6 06:13:40 2003 From: bokr at oz.net (Bengt Richter) Date: 6 Aug 2003 10:13:40 GMT Subject: CGI Webcounter not quite working...help, please References: Message-ID: On Wed, 6 Aug 2003 11:01:04 +1000, Dave Harrison wrote: >> I got this webcounter to be called directly (I still can't get it to be >> called from an HTML file with #exec or #include or anything). > >you might want to try embedding the page itself in the code (ugly, but if you're just starting out with python maybe the way to go). > >> #!/usr/pkg/bin/python ^^^^ is this where the ISP has python? When the CGI script runs, does it run as you (i.e., under your uid and permissions) or as user "nobody" or "www" or such? Ask the sysadmin what the policy is. Or they should have a FAQ someplace about their stuff. >> >> print "Content-Type: text/html\n\n" > >> print "\n\n" > >this part is unnecessary, you already have the two \n's from the statement above it. > >> import os >> import string >> >> print "" print 'My CGI-generated Page ??' >> print "" >> filenames = os.listdir(os.curdir) >> >> if "count.txt" in filenames: >> input = open('count.txt', 'r') >> i = string.atoi(input.read(1)) >> else: >> i = 0 >> print "File doesnt exist
" >> >> i = i + 1 >> print "This page has been accessed " + `i` + " times.
" >> print "" >> print "" >> >> #it doesn't seem to execute this at all >> output = open('count.txt', 'w') >> output.write(`i`) >> output.close() >> >> Do you see any obvious problems with this? It works fine when I call it >> from the command line. > >hmmm ... ok well here's how I would do something similar, we dont want to just guess if a file is there, we want it to be there and error else (or so I think, it is a counting script, and a couting script without a file cant really work ;-) > >Now while Im sure this isnt the best way to do it (tho I dont think its all that bad either ;-) .... > A couple of nits and (untested) suggestions: >#!/usr/bin/env python > >import string import sys # for exc_info in case weird exception > >print 'Content-Type: text/html\n\n' print 'Content-Type: text/html\n' # you get one from the print statement >print '' print 'My CGI-generated Page ??' # ?? > >count = '0' > >try: > count = open('count.txt').read() > count = string.strip(count) > num = string.atoi(count) num = count and int(count) or 0 > print "You are the "+str(num+1)+"th visitor to this page" >except IOError: > print "No valid file" >except ValueError: > print "No valid count value" # ugh, just noticed the tabs ... except Exception, e: # print the name and message of any standard exception remaining print '%s: %s' % (e.__class__, e) except: print 'Nonstandard Exception %r: %r' % sys.exc_info()[:2] > >print '' > Or you can let this do the exception stuff: http://www.python.org/doc/current/lib/module-cgitb.html See also http://www.python.org/doc/current/lib/module-cgi.html for good reading. Regards, Bengt Richter From ryanlowe0 at msn.com Fri Aug 29 19:29:38 2003 From: ryanlowe0 at msn.com (Ryan Lowe) Date: Fri, 29 Aug 2003 23:29:38 GMT Subject: crazy programming language thoughts References: <3rv3b.6241$yg.2305230@news4.srv.hcvlny.cv.net> <35y3b.3262$_F1.545316@news20.bellglobal.com> Message-ID: "Sean Ross" wrote in message news:35y3b.3262$_F1.545316 at news20.bellglobal.com... > "Ryan Lowe" wrote in message > news:3rv3b.6241$yg.2305230 at news4.srv.hcvlny.cv.net... > > what i am attempting to figure out, is if there is > > a way to improve the intuitiveness of the python's syntax, specifically > > concerning functions. > > Hi. I'm pretty sure you will not find a lot of support in this forum for > changing > Python in the way that your hoping. You're pretty much proposing a new > language, not just enhancements for an existing one. But, whatever ... im not trying to change python. even a small change is a tough sell with this crowd ;-) i guess i should have labeled this off-topic. is there a forum that might be more appropriate? actually, i would like to make my own language, sort of. what id like to do is compile to regular old python code, instead of directly to executable. that way i wont have to reinvent the wheel for the parts of python i would keep in my new language (which is a lot), as well as all the libraries and such. maybe ill find this will become too difficult, but what the hell, i ought to learn a thing or two in the process. > Personally, I really like the *idea* of an english-like programming > language - > I'd like to make one myself, and I think it'd be a fine toy for simple > scripting. > However, I also think it would become cumbersome as the scale of your > projects grew. Heck, it's cumbersome even when your projects are small. > English is not always the most concise way to say something, nor is it > always the most clear. Take the following Applescript code for example: > > What is the result of each of these statements: > > words from paragraph 2 to paragraph 4 > words of paragraphs 2 thru 4 > text from paragraph 2 to paragraph 4 > text of paragraphs from 2 to 4 > > They're all different. thats interesting. thats pretty much the impression i got from applescript. i think it goes too far trying to be english-like to the point of obfuscation. i see no need to english-ify selecting a range of things from a list. id do something like: get words in paragraphs[2 : 4] where paragraphs is a list of strings each containing a paragraph of text and "get words in _" is a function call and the *only* form it can be written (in verb form, that is; in noun form the only way would be "words got in _"). so i can dodge this bullet, but running into the type of problem in this example is exactly what im concerned with. as it stands, i dont think the difference between my way and python's way is as different as between my way and applescripts.' i use function calls just like python, only they span multiple words with the args interspersed instead of bunched up at the end. part of my motivation for attempting this comes from my ongoing struggle to understand functional programming, which goes to the extreme of putting functions/operators in the wrong place vis a vis the arguments. so i guess my main point in asking here was to see if people with more oo and/or functional lang knowledge can find where/if my model breaks down. because, id like to build much more than a "toy" language. > The answers can be found here: > http://www.applescriptsourcebook.com/tips/gotchas/ranges.html > > > > do you think it would confuse people in terms of which part is a parameter > > of what when combining 2 functions like the combo example? > > > In Applescript, you can (optionally) use parenthesis to (attempt to) > disambiguate. So, for example, in your case, doing something like > > replace av with bv in (listv joined with gluev) > > might make things a bit clearer. sure thats the obvious solution. it would suck (just a little) if every expression-argument needed parens, while the comma and single outer parens work in traditional functions, but thats minor. > > i havent figured out how to de-dottify class functions and class > > attributes. > > Well, you could do something like this (applescript-like, again): > > -- If you have an instance of the class > set the attribute of instance's class to value > > -- or > set the attribute of the class of instance to value > > -- or, maybe even, > get the attribute of instance's class > set it to value > > > -- And, if you don't have an instance, or you just want to get there > directly > set className's attribute to value or just attribute of classInstanceVar = value the 'of' works like the dot only in front. may conceivably cause problems if functions have ofs in them, but since it works on the front while other function words go behind, i think its resolvable. can anyone think of something you couldnt do with this, that you can in python? i know applescript is limited, but does my language suffer from similar challenges? any functions that would translate to a simple verb-noun-args and other words setup? > > Anyway. It's an interesting idea (your language) - not a new idea, but an > interesting one. If you want to play around with something very much like > Applescript, but you don't have a Mac, you can get a trial version of > MetaCard (www.metacard.com). And, if you really want to make your own > language, you could use SPARK, as a start, to whip up a (slow) prototype > to mess around with and see how things should go together. As for getting > Python to _become_ your language ... well, good luck with that. > > Sean SPARK, huh. never heard of it, ill check it out. thanks From mwh at python.net Fri Aug 1 07:04:55 2003 From: mwh at python.net (Michael Hudson) Date: Fri, 1 Aug 2003 11:04:55 GMT Subject: Unfortunate exception on dict item assignment (and why aren't slices hashable?) References: <67fdivk9iu0q1p7nc8smfj1miip3cbvobf@4ax.com> Message-ID: <7h3ptjpabbl.fsf@pc150.maths.bris.ac.uk> "Fredrik Lundh" writes: > Aahz wrote: > > (Despite my regular comments on python-dev, I don't contribute > > code because SF refuses to make changes to allow Lynx to work > > correctly.) > > maybe someone with an SF account could help you out? could it be > worth setting up an aahz-helpers mailing list somewhere, manned by > volunteers with SF access and modern browsers? I've successfully used w3m to drive SF's website, FWIW. Cheers, mwh -- 42. You can measure a programmer's perspective by noting his attitude on the continuing vitality of FORTRAN. -- Alan Perlis, http://www.cs.yale.edu/homes/perlis-alan/quotes.html From reply.in.the.newsgroup at my.address.is.invalid Sun Aug 24 09:43:42 2003 From: reply.in.the.newsgroup at my.address.is.invalid (Rene Pijlman) Date: Sun, 24 Aug 2003 15:43:42 +0200 Subject: new to python References: <_%22b.7018$jd.1229@fe02.atl2.webusenet.com> Message-ID: Ronnie Broyles: >Will I need a compiler with python? You will need the Python interpreter, which is also a compiler of sorts. Grab it from http://www.python.org/download/ -- Ren? Pijlman From schaffer at optonline.net Wed Aug 27 13:52:11 2003 From: schaffer at optonline.net (Les Schaffer) Date: Wed, 27 Aug 2003 13:52:11 -0400 Subject: python version of emailstripper??? Message-ID: Has anyone seen any python code which does something similar to what emailstripper does: http://www.papercut.biz/emailStripper.htm i have a mailing list where this would come in handy. les schaffer From roy at panix.com Mon Aug 18 17:25:55 2003 From: roy at panix.com (Roy Smith) Date: Mon, 18 Aug 2003 17:25:55 -0400 Subject: What's better about Ruby than Python? References: <3F40892D.AEF4AAE@alcyone.com> <87isov6pk4.fsf@pobox.com> <3F412081.5EF7279C@alcyone.com> <874r0ey9bx.fsf@pobox.com> Message-ID: jjl at pobox.com (John J. Lee) wrote: > I read the whole of Stroustrup and a couple of other books > before writing a line of C++ You're a sick puppy :-) From bgailer at alum.rpi.edu Fri Aug 22 11:55:12 2003 From: bgailer at alum.rpi.edu (Bob Gailer) Date: Fri, 22 Aug 2003 09:55:12 -0600 Subject: crazy programming language thoughts In-Reply-To: Message-ID: <5.2.1.1.0.20030822094611.03cfdc18@66.28.54.253> At 12:39 AM 8/22/2003 +0000, Ryan Lowe wrote: >disclaimer: >this is a little out-there, primarily a thought excersise for myself. it >probably belongs in group on programming language theory. but python got me >thinking about this, so here it is. and dont worry, its NOT a change >proposal. > >one of the things i love about python is its use of the actual words >or/and/not/is/in, where other languages would use symbols ||/&&/?!@#$%, what >have you. the symbols dont save you much typing (especially if you count the >shift key), but are merely something extra to learn and remember. Those of us who programmed in APL got great benefit from symbols. Not only did they save a LOT of typing they made it real easy to compose and read expressions. Consider (assuming A is a matrix of numbers): (+/A)%@A (in the APL font the % is a divide symbol (a - overstruck with a :) and the @ is the Greek letter rho. The pythonic equivalent is (Assuming A is a sequence of numbers): reduce(operator.add, A) / len(A) >i also >like how python did away with the unneccesary parentheses in for/if/while >statements. soooo ive been toying with the idea of getting rid of parens in >functions too (ive just been reading the ruby tut and noticed parens are >optional in some cases which is cool, but trust me this is different) > >the basic concept would be to use identifying words in front of the >arguments to determine their identity as well as making the function call >read more like an english phrase. for instance, take the simple python >statement: > > >>> vtext.replace('a', 'b') > >wouldnt it be nicer (more english-like at least) to say: > > >>> replace 'a' with 'b' in vtext > >since the arguments have an identifying word (with, b) (in, vtext), the >order isnt important (other than the first 'anchor' word(s)), so we could >instead have said: > > >>> replace 'a' in vtext with 'b' > >or > > >>> replace in vtext 'a' with 'b' > >ignoring that the last version is a little awkward to say, the advantage is >immediate understandability; each parameter's contribution is explicitly >stated so you dont have to guess or look up what each arg of a many-arg >function does. of course, you could forget what words go in front of the >args (e.g. was it 'in vtext' or 'from vtext'?), but since its english-like i >think less so. plus an editor could give you hints like many do now. > >you may be thinking about keyword inflation. however, the parser would >consider the whole set of words together, so the 'in' in the above wouldnt >be bound to the meaning it has in a for statement. worst case scenario, a >naming convention like the v in front of variable names could be used to aid >parsing, but i think it may be possible to disambiguate without such a >convention. > >i just want to say that i know i saw a similar idea in another language, a >few years ago, but damned if i remember where or what language. i guess the >language didnt make it:( but if anyone knows a language like this, PLEASE >let me know. > >anyway, this is all well and good for this simple example, but lets see how >it scales up. once you get familiar with finctions and dot syntax, you >probably started chaining them together. it saves time and space and after >not so long it becomes pretty easy to write and understand something like >this: > > >>> v = '/n'.join(file('file.txt').readlines()).lower().split('.') > >but think back to when all this stuff was new. you probably would have >written: > > >>> f = file('file.txt') > >>> v = f. readlines() > >>> v = '\n'.join(v) > >>> v = v.lower() > >>> v = v.split('.') > >it may be a little clearer, especially to a beginner, but its not nearly as >convenient. now take a look at this: > > >>> v = read lines from 'file.txt'; join it with '\n'; lower it; split it at >'.' > >i showed this to a couple non-programmers, and they fould it much easier to >interpret than the first way (i didnt show them the second way). Reminds me of showing others programs in languages they did not know. They'd say "I can't read that." Duh. And COBOL was famous for its verbose use of English to make programming easier. >here i do introduce a new keyword 'it' new?? I assume you are unfamiliar with Apple's hypercard. >which you can probably guess contains the >return value of the statement to the left of the semicolon. you could add a >'them' keyword for aggregates (as in the join part) if you are a grammar >stickler. > >ill stop here before i put people completely to sleep. im curious what >people think about this. im not concerned with 'minor' problems like the >speed of a parser that could handle this. id like instead to hear comments, >concerns, reguarding the theory. id especially like any links people might >know about interesting experimental programming languages. > > >-- >http://mail.python.org/mailman/listinfo/python-list > > >--- >Incoming mail is certified Virus Free. >Checked by AVG anti-virus system (http://www.grisoft.com). >Version: 6.0.506 / Virus Database: 303 - Release Date: 8/1/2003 Bob Gailer bgailer at alum.rpi.edu 303 442 2625 -------------- next part -------------- --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.506 / Virus Database: 303 - Release Date: 8/1/2003 From adalke at mindspring.com Wed Aug 20 18:36:27 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Wed, 20 Aug 2003 22:36:27 GMT Subject: What's better about Ruby than Python? References: <3F41505F.69D18CC8@alcyone.com> <66d7kvonvb2n0nqbqahhd5roak7ur81sob@4ax.com> Message-ID: Alex: > Similarly, you do not tend to see in the > Linux community people who are convinced with sufficiently high > intensity that case sensitivity in a filesystem is idiocy (I do believe > that, but not intensely enough to drop Linux's other advantages:-). And fewer who accept, much less understand, Jef Raskin's views against a hierarchical file system at all. LEAP-LEAP! > To put it another way: I _DO_ have a different viewpoint from the > majority of Python users regarding case sensitivity -- I think it's > a wart in the language. While I agree that the file system should be case insensitive but case preserving (making internationalization all that more fun), I confess to being fond of the atom = Atom() idiom. I know it breaks down, eg, for a function which returns a newly created class, but it's too ingrained in me. OTOH, I just thought about it some more. It's rare that I only make a single instance, so atom1 = Atom() atom2 = Atom() new_atom = Atom() are more common than the 'atom =' version. I'll think about it as I write new code. Andrew dalke at dalkescientific.com From blunck at gst.com Wed Aug 13 01:07:09 2003 From: blunck at gst.com (Christopher Blunck) Date: Wed, 13 Aug 2003 01:07:09 -0400 Subject: Multi-Line Comment References: <4qofjvg3bh9smlnb1do4f0lhjga7bacnu3@4ax.com> Message-ID: On Mon, 11 Aug 2003 14:17:38 -0500, Skip Montanaro wrote: > > Doug> I've been using Python for quite some time now, and I'm a bit > Doug> stumped. Does it really not have a multi-line comment? I think I > Doug> must just be missing something simple and stupid. > > Nope, no multi-line comment. The python-mode package which is available for > Emacs and XEmacs supports commenting a block of text. You can also use > triple-quoted strings: That always stumped me as well. Any idea what the justification for this was, Skip? -c From mrroach at okmaybe.com Mon Aug 25 16:31:01 2003 From: mrroach at okmaybe.com (Mark Roach) Date: Mon, 25 Aug 2003 20:31:01 GMT Subject: Deleting email message using imaplib? References: Message-ID: On Mon, 25 Aug 2003 16:14:45 -0400, Bill Sneddon wrote: > Anyone have an example they are willing to share that shows > how to use the store command in imaplib? [...] > >>> m.send('A003 STORE 2:4 +FLAGS (\Deleted)') here's what I use, works just fine. imconn = imaplib.IMAP4(server) imconn.login(username, password) imconn.select(folder) imconn.store(msgid, "+FLAGS", '(\\Deleted)') imconn.expunge() -Mark From pu at nodomain.lu Mon Aug 25 17:08:22 2003 From: pu at nodomain.lu (Patrick Useldinger) Date: Mon, 25 Aug 2003 23:08:22 +0200 Subject: pure Python DB Message-ID: Hello, for a cross-platform project, I am looking for a Python DB. It should be lightweight, but provide transactions an of course reliable. Is there such a thing out there? I have read about Gadfly, is this still maintained? Thanks, -Patrick From hokiegal99 at hotmail.com Fri Aug 22 18:49:30 2003 From: hokiegal99 at hotmail.com (hokieghal99) Date: Fri, 22 Aug 2003 18:49:30 -0400 Subject: Keystroke logger for Windows Message-ID: Does anyone know of a keystroke logger that has been written in Python for Windows machines? I'd like to see such a script and use it as a point of reference for a real-time backup project that I'm working on. Basically, I'd like to be able to capture all keystrokes from the keyboard buffer and write them to a text file so I could reporduce emails, documents, etc. in the event of file loss that occurs between nightly backups. For example, my boss comes to me, he has deleted an email that he was writing... he has been working on the email all day... and he expects me to wave a magic wand and bring it back. Thanks for any advice, code or pointers. Also, if Python isn't suited for this, let me know and I'll look at doing this in c From raims at dot.com Fri Aug 29 10:28:30 2003 From: raims at dot.com (Lawrence Oluyede) Date: Fri, 29 Aug 2003 16:28:30 +0200 Subject: how fast is Python? References: Message-ID: <87isogk06p.fsf@voodoo.fake> Andrew MacIntyre writes: > The advantages being? I think gain access to Java stuff is an advantage in some situations, isn't it? -- Lawrence "Rhymes" Oluyede http://loluyede.blogspot.com rhymes at NOSPAMmyself.com From mpeuser at web.de Sat Aug 16 03:54:37 2003 From: mpeuser at web.de (Michael Peuser) Date: Sat, 16 Aug 2003 09:54:37 +0200 Subject: Modifying TKinter widgets defined in Modules References: <3f443b52.0308151251.7e6bbaaf@posting.google.com> Message-ID: Marcus, I have no clear concept of your problem ("nix verstehen"). Newbie? What is a "main"? What in fact is the overall structure of your software system? You have first di decide where to put your "variables". In Python you will generally use an object. This can be made visible as you like. You however have do decide who instantiates this object ("main" or one of the "moduls")? The best way seems to do this in your "main": class Data: pass myData=Data() Put all your 25 variables into it (myData.varX=None ....), then you pass "myData" as a parameter to your moduls... Is this what helps? Kindly Michael P "Marcus Schneider" schrieb im Newsbeitrag news:3f443b52.0308151251.7e6bbaaf at posting.google.com... > Sorry if this is an extremely stupid question: > > I produced some Python modules with TKinter stuff and now I want to > use that from my main program. The windows have wuite some user > interaction. It's easy to bring them to the screen, but how do I make > the communication (i.e. variables) between the main and the modules > happen? > > Currently I call a function from the main and pass all variables in > the function call, but with more then 25 variables this looks odd. > > And now I have to change variables in the main from the module and > that doesn work at all, does it? > > Or can I access widget definitions from the main?? > > What is the usual, elegant way to handle that? > > Thanks for any hint ;) From nospam at the.net Sun Aug 24 09:47:24 2003 From: nospam at the.net (Rune) Date: Sun, 24 Aug 2003 15:47:24 +0200 Subject: new to python References: <_%22b.7018$jd.1229@fe02.atl2.webusenet.com> Message-ID: On Sun, 24 Aug 2003 09:38:00 -0400, "Ronnie Broyles" wrote: > >I am new to python--new to programming period. Will I need a compiler with >python? I am currently working with the tutorials from the python.org >website. No compiler needed. Python is interpreted. Good luck! From jack at performancedrivers.com Mon Aug 11 17:16:41 2003 From: jack at performancedrivers.com (Jack Diederich) Date: Mon, 11 Aug 2003 17:16:41 -0400 Subject: convert tuple to string In-Reply-To: ; from aleax@aleax.it on Mon, Aug 11, 2003 at 08:40:13PM +0000 References: <84fc4588.0308111221.528e478e@posting.google.com> Message-ID: <20030811171641.A968@bitch.nowhere.blah> On Mon, Aug 11, 2003 at 08:40:13PM +0000, Alex Martelli wrote: > > So, let's look at performance. The complex, lambda-rich > expression with a map and a reduce...: > > python2.3 timeit.py -s't=tuple([ (str(x),) for x in range(30) ])' > 'reduce(lambda x,y:x+","+y, map(lambda x:x[0],t))' > > 10000 loops, best of 3: 59.3 usec per loop > > The simple expression based on a list comprehension: > > python2.3 timeit.py -s't=tuple([ (str(x),) for x in range(30) ])' > '",".join([ x[0] for x in t ])' > > 10000 loops, best of 3: 24.4 usec per loop > > I think this is great fodder for the underground movement aiming > to remove lambda, map and reduce. All that complication just > to slow things down by two times and a half...?-! No, this is a call for lambda/map/filter fans to improve the intepreter. The above reduce has 2*30 more function calls per loop than the equivalent list comprehension. The list comp essentially gets inlined, the lambda gets called and the arguments parsed each time. A truer comparison would also have the top one doing ",".join or the bottom one using reduce. Having one doing 30*3 string concats and the other doing one join() will skew the results. -jackdied From adalke at mindspring.com Mon Aug 18 05:30:40 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Mon, 18 Aug 2003 03:30:40 -0600 Subject: overriding a tuple's __init__ References: Message-ID: Simon Burton: > >>> class pair(tuple): > ... def __init__(self,a,b): > ... tuple.__init__(self, (a,b) ) > What gives? (yes it works with a list, but i need immutable/hashable) The problem is the immutability. This one one of the new changes in 2.3 I still don't fully understand, but I do know the solution is __new__ >>> class pair(tuple): ... def __new__(self, a, b): ... return tuple((a, b)) ... >>> >>> pair(2,3) (2, 3) >>> x=_ >>> type(x) >>> That should give you some pointers for additional searches. Andrew dalke at dalkescientific.com From ghowland at lupineNO.SPAMgames.com Sat Aug 23 12:04:52 2003 From: ghowland at lupineNO.SPAMgames.com (Geoff Howland) Date: Sat, 23 Aug 2003 16:04:52 GMT Subject: Modifying the {} and [] tokens References: <04cekv0s6ghjtuhl5j2gph7ltobdb5rsam@4ax.com> <62rekv0k4ucgrh46lkp27klq13pq8ppp5p@4ax.com> Message-ID: <1h3fkvg8mkeq69a8hriojugqfcp75hafjj@4ax.com> On Sat, 23 Aug 2003 16:40:17 +0300, Christos "TZOTZIOY" Georgiou wrote: >On Sat, 23 Aug 2003 09:16:13 GMT, rumours say that Geoff Howland > might have written: > >[snip of python's by design inability to modify the base C types: dict, >str, list etc] This post begins to read as an insult here, and continues. My incredible gall at thinking something may be better if it was changed and wanting to try it! I should be pelted with rocks for speaking the name Jehova. Is this really the way this group is going to continue? >>Ruby has this built in, it's useful, it's complete. It's obvious what >>is happening, so it's not unclean. It's allowed for other containers. > >It seems that code "terseness" is more important to you than code >readability. I can sympathise with that, perhaps I'd like that too, but >I believe I fully understand Guido's decisions over the years to >disallow that kind of stuff. [] + [] is allowed. Right? {} + {} is not allowed. len([]) is allowed. [].len() is not allowed. Why? I respect Guidos decsions, Python needs a strong leader to make them and it got where it is (great language) by having him and the rest of the community help out in this regard. Is now no one allowed to say "hey, I think this should be done, and I'd like to make it happen to give it a try"? It's not like if it becomes a problem it couldn't be reverted and lesson learned right? Programming is ABOUT experimentation, not dogmatic obedience. >I really don't mind subclassing base types and using MyDict() instead of >{}. I want to be able to make my own APIs (MyDict.update *could* blow >whistles and roll twice on the floor before resetting the machine), but >I also want a steady and well-known API for base types (dict.update >*should* update a dictionary from another one). Why should it matter what you mind? It's my code. >You can always roll off a customised Python interpreter, of course, but >it won't be Python anymore. > >With all due respect, Geoff, if this stuff is really important to you, >use Ruby. Yes, throw the heathen into another language. I'm not good enough for this one. I find this attitude really insulting. I like Python for what it is, that doesnt mean I dont think there are some things that could be better and want to try them. I wanted to know if it's possible, so I asked. I think it's important, so I persisted. Get over it. Stop making this place an unpleasant place to ask questions in fear of not asking in a Pythonic enough way. Not the first time I've seen this here, I'm sure it wont be the last. Not sure how many people never picked it up because they were smacked down before they found their groove in Python. I'm sorry this sounds heavy and upset, but I would like this place to not feel so bitter against exploratory questions. Bounds are set in Python, it's good. It doesn't mean people shouldn't ask and explore and find out for themselves what is best if it is possible. I could even go and change all the Python C source to make this work, who is it going to hurt but myself? It may even bring me valuable insight that I can then share as an _opinion_ with others who ask later (note, not telling them to use another language because they want to do something I dont agree with). -Geoff Howland http://ludumdare.com/ From opendtv at yahoo.com Sun Aug 10 16:23:34 2003 From: opendtv at yahoo.com (Samuel Barber) Date: 10 Aug 2003 13:23:34 -0700 Subject: Python vs. C# References: <3f357a9b@shknews01> Message-ID: <37991aef.0308101223.57beb3c8@posting.google.com> "Brandon J. Van Every" wrote in message news:<3f357a9b at shknews01>... > C# could be glossed as "C++ without the headaches." C# is derived from Java. "Java with pointers (and other stuff)" would be one way of putting it. > Also C#, like Python, has higher level data > types built right in. It does not. Hash tables, expandable arrays, etc. are provided by the standard library. Sam From theller at python.net Thu Aug 7 15:11:02 2003 From: theller at python.net (Thomas Heller) Date: Thu, 07 Aug 2003 21:11:02 +0200 Subject: FWD: Re: Problem w/ IDLE on Win2000 In-Reply-To: (Tim Peters's message of "Thu, 7 Aug 2003 14:25:15 -0400") References: Message-ID: "Tim Peters" writes: > [Thomas Heller] >> If it helps, I'm willing to take over the windows installer > > Great! It's in your capable hands until death . I can't imagine > anyone better for this -- thanks. That's too long for me. ;-) >> - although I would probably stay with Wise. > > Wise has worked very well for us; the only drawbacks are that very few > people are able to help when you want help (because very few people in > PythonLand own a copy of Wise), and that begging Wise for new installer > releases is a PITA. Something like InnoSetup would lower the bar for > contributors. IIRC the past discussions, inno was lacking an important feature. Had this to do with admin/non-admin installs, or is it fixed now? Anyway, I know wise much better than inno, and anyone >> And I consider IDLE having problems with spaces in its path a problem. > > That's permitted . I don't think it's an installer issue, though (see > other email about that -- it's most likely that Python's os.spawn on Windows > has problems with embedded spaces in an argument to the program being > spawned; 2.2 IDLE didn't use spawn so didn't have this vulnerability). > >> Just bought my daughter a copy of 'Python f?r Kids' (although she >> certainly accepted the default installation options). > > German spaces create even more problems . I thought there were *no* spaces in the german word 'Programme', now I hear that's a german space =8) BTW: The only real problem is that I cannot build the HTML pages here on windows, and I have no guy named 'Fred' beneath me. And booting suse in a vmware box isn't really fun. And while we're on it: what's the state of the htmlhelp file for windows? Last time I looked, the build script was in CVS, and it even worked. Thomas From gregbrunet at NOSPAMsempersoft.com Tue Aug 12 16:10:21 2003 From: gregbrunet at NOSPAMsempersoft.com (Greg Brunet) Date: Tue, 12 Aug 2003 15:10:21 -0500 Subject: drop down feature References: Message-ID: Somewhat, depending on the IDE you choose, but not really. Search the newsgroup (or use google) to find a thread titled "'Intellisense' possible for Python?" started (by me) on Dec 18, 2002. It discusses why this isn't really possible with Python (short version: dynamic typing doesn't allow them to do this). Generally, the interactive interepreter windows support this better than the editors. Pat O'Brien did some work on improving this in the PyAlaCarte series of editors, but I've not been able to get it working completely, and he seems to not be doing any additional work on it at this time. As someone who also came from VB, support for intellisense-type capabilities would be the largest practical improvement that could be made to ease-of-use & adoption of Python. I think that it's hard for those folks who haven't benefited from it to understand how nice it really is. Good luck, -- Greg "Emmanuel Jean-Louis" wrote in message news:mailman.1060692918.5794.python-list at python.org... Does python 2.2 has a drop down feature like VB does so that you can list of methods and variables associate with that particular class? If it does, how do I turn it on? Thx. From jbi130 at yahoo.com Tue Aug 26 13:16:28 2003 From: jbi130 at yahoo.com (jbi130 at yahoo.com) Date: Tue, 26 Aug 2003 17:16:28 GMT Subject: resizing curses window Message-ID: <87d6es9vyo.fsf@syn.codemonkey.net> I've built a small curses app with an IRC like interface (not for IRC tho). The last remaining item is to handle resizing the terminal on SIGWINCH. I've tried a few things and everything is failing. I first try to resize my root window using resize() but then my calls to resize other windows usually fail.. Whats the proper or common way to handle a resize? I added on the ncurses extention resizeterm() to _cursesmodule.c and that seems to make things work better, but I'm trying to get away with the stock module. Any pointers to examples would be great as searching google did prove to be very fruitful. Thanks. From justinjohnson at fastmail.fm Tue Aug 12 10:18:50 2003 From: justinjohnson at fastmail.fm (Justin Johnson) Date: Tue, 12 Aug 2003 08:18:50 -0600 Subject: Changing UNIX primary group Message-ID: <20030812141850.331BB380F7@www.fastmail.fm> I have a unix id that has group1 for a primary group, and group2, group3, and group4 for supplementary groups. I'd like to change my primary group before running certain commands. So sometimes I might want group2 to be the primary group, and other times group3 or group4. I saw the posix module's setgid method, but it failed for me unless I was running as root. Also it only accepts the gid, but I'd rather pass in the group name, or somehow lookup the gid based on the name. Does anyone know a way to do all of this? Thanks much. -Justin From jepler at unpythonic.net Sun Aug 31 10:18:23 2003 From: jepler at unpythonic.net (Jeff Epler) Date: Sun, 31 Aug 2003 09:18:23 -0500 Subject: locale.nl_langinfo(RADIXCHAR) vs locale.localeconv()['decimal_point'] In-Reply-To: References: Message-ID: <20030831141818.GA32141@unpythonic.net> Martin, Thanks for the feedback. I've created the bug on SF: http://python.org/sf/798145 Jeff From aleax at aleax.it Fri Aug 29 04:48:30 2003 From: aleax at aleax.it (Alex Martelli) Date: Fri, 29 Aug 2003 08:48:30 GMT Subject: Add two dicts References: <86ktkvkd05e88hu14hjudmfvbul7slfgkt@4ax.com> Message-ID: Afanasiy wrote: > I have some code like this... > > self.write( > ''' > lots of stuff here with %(these)s named expressions > ''' > % vars(self) > ) > > Then I wanted to add an item to the dict vars(self), so I tried : > > vars(self)+{'x':'123','y':'345'} > > This doesn't work, perhaps because no one could decide what should happen > to keys which already exist in the dict? (I'd say throw an exception). > > Can I add two dicts in a way which is not cumbersome to the above % string > operation? Is this another case of writing my own function, or does a > builtin (or similar) already exist for this? In Python 2.3, you can, if you wish, code: self.write( ''' lots of stuff here with %(these)s named expressions ''' % dict(vars(self), x='123', y='345') ) thanks to the new feature of dict of allowing a **kwds argument (with the 'obvious' semantics, however: named keys override keys already present in the first argument -- if you need to diagnose overlap and raise an exception thereupon, you'll have to do that separately). More generally, if you had an existing dict D you wanted to "add" to vars(self), rather than a literal, you could code: self.write( ''' lots of stuff here with %(these)s named expressions ''' % dict(vars(self), **D) ) Alex From tinuviel at sparcs.kaist.ac.kr Thu Aug 28 00:45:46 2003 From: tinuviel at sparcs.kaist.ac.kr (Seo Sanghyeon) Date: 28 Aug 2003 04:45:46 GMT Subject: can generators be nested? References: Message-ID: <3f4d88fa$0$188$7a214f24@news.kaist.ac.kr> news.west.cox.net wrote: > This doesn't work, but is there any elegant way to do something like this? (Someone wants to simplify "for value in generator: yield value".) Currently there is no way around this. There were some dicsussions on this topic, and some syntaxes were proposed, and some said for-yield solution is just fine. * for i in g: yield i * yield every g * yield << g * etc. You may search the archive for details. (ex. "yield every".) I hope this one does not become yet another if-then-else expression. :( Seo Sanghyeon From dtolton at yahoo.com Tue Aug 12 22:26:18 2003 From: dtolton at yahoo.com (Doug Tolton) Date: Wed, 13 Aug 2003 02:26:18 GMT Subject: The importance of using Library Functions Message-ID: At my company we have a program that parses through certain types of electronic files and stores the information in plain text. E-mail poses an interesting problem for us, because most of the text tends to be wrapped and doesn't contain hard returns. The specific web control we use to display this text will simply show the text of the e-mail as a single continuous line. On friday I was asked to fix the text for these files so it would be appropriately wrapped at a line width of 80 characters. Yesterday I began writing the code to deal with this. I was at work until 5:15 am today trying to solve all the little quirks of that type of parsing. I finally got most of the kinks worked out, and ran it, however at great personal cost (ie lost sleep). Much to my dismay I was browsing this board and saw the post about Summer Reading: On Tue, 12 Aug 2003 06:57:05 GMT, "Raymond Hettinger" wrote: >Found in a pamphlet at a pre-school: >--------------------------------------- >Reading improves vocabulary >Reading raises cultural literacy through shared knowledge >Reading develops writing skills >Reading opens the mind to new ways of understanding >Reading is fun > > >Accordingly, I suggest the following works of literature: > > * heapq.py (255 lines) > * sets.py (536 lines) > * textwrap.py (355 lines) > * csv.py (427 lines) With a sinking feeling I opened the textwrap.py module and browsed through it. After running several tests and playing with some of the settings, this was *exactly* what I needed. I've always enjoyed writing code. I particularly enjoy solving hard problems, what I don't like is trying to solve them under immense pressure from a client. Ultimately the problem itself was moderately hard to solve, but the conditions made it even more difficult. I had an inordinately large amount of text to deal with, so my test cycle was ungodly slow. Had I spent 30 minutes looking through the documentation, I could've saved my self one helluva long night. As much as I hate to be the example, it really is a wonderful illustratration of why following the Unix / OSS development model is a better way to go. 1. Check to see if someone has already written an app to do what you want done. 2. Check to see if someone has written something that is close to what you want done. If you can get the source code, modify it to do what you need specifically. 3. Write it from scratch. Instead of working my way down the list, I jumped straight to number 3. While that can be useful for an academic excercise, or when you are going for a more rigorous approach, it's seldom useful when you have a looming deadline. Doug Tolton From news at exultants.org Tue Aug 26 00:31:35 2003 From: news at exultants.org (Van Gale) Date: Tue, 26 Aug 2003 04:31:35 GMT Subject: Preferred standalone TAL module? References: <5d855b4b.0308251419.31e894e6@posting.google.com> Message-ID: On Mon, 25 Aug 2003 15:19:52 -0700, Fahd Khan wrote: > Going through > recent postings on Google it seems SimpleTAL is the standalone TAL > module in most active usage and development just now, would the > community concur or suggest alternatives? Here's another standalone TAL: http://savannah.nongnu.org/projects/opental/ but I'm not sure how active it is, and it doesn't seem to support TALES and METAL. Van From tismer at tismer.com Sun Aug 10 17:56:01 2003 From: tismer at tismer.com (Christian Tismer) Date: Sun, 10 Aug 2003 23:56:01 +0200 Subject: Slogan: Getting Rich Overnight In-Reply-To: References: Message-ID: <3F36BF71.6090204@tismer.com> Robert Kern wrote: ... > While I certainly share that sentiment, I would advise caution in the phrasing > of such a slogan: if I hadn't seen your name, I would have skipped your article > as spam! Absolutely agreed! But is there any way for such a slogan to pass spam at all? If I remove the ambiguity, the slogan gets lame. Any ideas? ciao - chris -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 pager +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From theller at python.net Sat Aug 16 07:09:10 2003 From: theller at python.net (Thomas Heller) Date: Sat, 16 Aug 2003 13:09:10 +0200 Subject: How remove Tcl/Tk fom py2exe distribution? References: Message-ID: <7k5dzwo9.fsf@python.net> "Michael Peuser" writes: >> In case I'm missing something: you could always, as part of your >> build, just delete files from the py2exe-generated build >> directory. For example, at the end of your setup.py script, add some >> lines to delete the tk/tcl files from your build path. I've used >> this "strategy" sometimes when building py2exe apps that use the >> Python Imaging Library. (PIL has tcl/tk import dependencies, but >> doesn't actually need tcl/tk for the majority of its functions.) IMO --exclude Tkinter should also work. > > I tried this! This will not help, because - in this case - Tkinter *is* > used. The importer just does not find it (probably because py2exe modifies > its behaviour.... > > This is why I use > > Tkinter= __import__("Tkinter") > > But this does not wort either... Ok. First you should make sure that Tkinter is not found and copied by py2exe. The '--exclude' flag could be used, or the above __import__ trick. Then, you should make sure that your executable finds the 'standard' Tkinter module (and tcl/tk) installation by including the proper directory into sys.path. Normally py2exe takes some care to *not* find modules or packages from a Python installation on the system. A little experimentation is probably needed, and hacking py2exe could maybe help. You can change this code (in py2exe\build_exe.py, near line 926) header = struct.pack(" <2e363c08.0308161306.47a010ae@posting.google.com> Message-ID: |[David Mertz] |> Yeah :-). Which points out that I should have actually READ Raymond's |> function, rather than just cut-and-paste it. This seems to point out |> that even the Python developers are able to make mistakes in |> implementing powerset(). |It wasn't a mistake. |I do prefer Alex's improvement because it has a weaker precondition, |but the basic code and generation method was dead-on. Well... I'm not sure about dead-on. For example: % cat time_powerset.py from sets import Set from time import clock def rh_powerset(iterable): data = list(iterable) for i in xrange(2**len(data)): yield Set([e for j,e in enumerate(data) if i&(1< References: <78kkkvg8ckfio141es2of1p483ohbtbit5@4ax.com> <78kkkvg8ckfio141es2of1p483ohbtbit5@4ax.com> Message-ID: <5.2.1.1.0.20030825140522.032c5c20@66.28.54.253> Is there a way for a Python program to interact with MS Excel on the Macintosh? My goal is to extract contents of cells. Bob Gailer bgailer at alum.rpi.edu 303 442 2625 -------------- next part -------------- --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.506 / Virus Database: 303 - Release Date: 8/1/2003 From someone at somewhere.com Mon Aug 18 21:50:23 2003 From: someone at somewhere.com (reh) Date: Tue, 19 Aug 2003 01:50:23 GMT Subject: advice choosing IDE References: <2lh711-1s2.ln1@stargate.solsys.priv> Message-ID: Detlev Offenbach wrote: >> >> eric at http://www.die-offenbachs.de/detlev/eric3.html is a full IDE, >> written in PyQt, that integrates with Qt Designer. It does the usual >> editing, debugging, project management, class browsing - plus access >> to source code control systems, syntax checking, unit testing, >> profiling, code coverage. Latest snaphots include refactoring tools. >> Etc, etc, etc. >> >> Phil > > And if there is something missing in the "etc, etc, etc" let me know > and I'll try to implement it. > > Detlev Doing some work in eric between everything else, well done. Have a question on Calltips. Have it Enabled. Thought I would see something like calltips for functions, but what I see is more Autoconfig. Am I missing something. thanks; -- robert redhat 9.0 From max at alcyone.com Sun Aug 24 19:45:54 2003 From: max at alcyone.com (Erik Max Francis) Date: Sun, 24 Aug 2003 16:45:54 -0700 Subject: Alphabetizing? References: Message-ID: <3F494E32.E5A89E72@alcyone.com> Lee Harr wrote: > How about just sort()ing them? > > You can define a custom sort function if you want an > alphabetical rather than lexical sort. ie: ... > def sort_alpha(a, b): > if a.lower() < b.lower(): > return -1 > elif a.lower() > b.lower(): > return 1 > else: > return 0 > > words.sort(sort_alpha) You've got the right approach (sorting based on a signature derived from the string, rather than the string itself), although to be picky this isn't yet an alphabetic sort, since it should be stripping away non-alphabetic characters: >>> sort_alpha("where's", "whereas") -1 Of course this starts to get into questions of what you consider a word or not, but a true alphabetic sort would remove non-alphabetic characters first. You can do this easily enough with string.maketrans and S.translate. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ An undevout astronomer is mad. \__/ Edward Young From irmen at -NOSPAM-REMOVETHIS-xs4all.nl Sat Aug 23 12:40:27 2003 From: irmen at -NOSPAM-REMOVETHIS-xs4all.nl (Irmen de Jong) Date: Sat, 23 Aug 2003 18:40:27 +0200 Subject: ANN: Snakelets 1.3 (simple-to-use web app server with dynamic pages) Message-ID: <3f4798f7$0$49102$e4fe514c@news.xs4all.nl> I'm happy to say that Snakelets 1.3 is now available. Changes since 1.2: - actually compiles Ypages to pyc bytecodes now - ypages can send HTTP error responses, include another url and forward to another url - better script indent handling in Ypages - adds ETag and Last-Modified HTTP headers, - aads nocache HTTP headers for snakelet and Ypage responses - quickreference manual - miscellaneous fixes and improvements Snakelets is a simple Python web application server, mainly for educational purposes. This project provides a threaded web server, Ypages (HTML+Python language, similar to Java's JSPs) and Snakelets: code-centric page request handlers (similar to Java's Servlets). Before you all rightfully scream "not another Python web server and HTML- language" let me say that Snakelet's focus is on understanding the way dynamic web sites are created (the code is very compact and easy to understand), and make this process as easy as possible. The actual server and Ypage-compiler code is less than 2,300 lines. The full download includes a few example web-applications: - mp3 indexer and streamer - shop - server/webapp management tool Snakelets is not meant to be a true platform to develop applications on. It is meant to show how a web application server might work. I certainly learned a lot from creating it. You can download it from http://snakelets.sourceforge.net (go to the SF project site, and then the file section). Snakelets is released under the open-source MIT Software license. --Irmen de Jong From pinard at iro.umontreal.ca Thu Aug 14 16:06:03 2003 From: pinard at iro.umontreal.ca (Francois Pinard) Date: 14 Aug 2003 16:06:03 -0400 Subject: Recommendation of a parser generator In-Reply-To: References: Message-ID: [Fortepianissimo] > I read from Charming Python column that SPARK is *very* slow (it uses > Earley algorithm) (2) We use SPARK in production and are satisfied with it. SPARK can be very slow, indeed, if the grammar is ill conditioned[1], but then, most other parsers will likely not accept such grammars anyway. In our experience so far, for "reasonable" grammars, and source files which may be long, without being huge, SPARK is quite usable in practice. One co-worker told me about a big application which run for hours, and rely on more than thirty parameter files, each being a few pages long. There are a few different syntax for these parameter files, one being particularily recursive and complex. Using SPARK for analysing all these parameter files added 15 seconds to the whole process, nothing worth the slighest complain. -------------------- [1] What is an "ill conditioned" grammar? This is a fuzzy concept, but I might say that it is one that makes SPARK slow! :-). I have some experience with Bison (or YACC) parsing, which accumulated over the years. So, I merely write for SPARK grammars a bit like I would have written them for Bison, but without being overly cautious or concerned about whether Bison would be happy with my grammars, or not. The result is usually workable. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From aleax at aleax.it Fri Aug 8 09:11:46 2003 From: aleax at aleax.it (Alex Martelli) Date: Fri, 08 Aug 2003 13:11:46 GMT Subject: Gmpy References: <8578e2c1.0308070630.5fb70c22@posting.google.com> <%4BYa.85$Ad4.79@nwrdny03.gnilink.net> Message-ID: Carl Banks wrote: ... >>> I couldn't use gmpy because I needed floating point, and mxNumber also >>> wraps the floating point functionality. It seemed to work ok. >> >> gmpy also wraps the floating-point functionality of GMP: >> >>>>> print gmpy.mpf(7,99)/3 >> 2.333333333333333333333333333333333333333 > > > I'm sorry--I was thinking of the mpz module. I remember looking at > gmpy but passed on it for some reason--probably something silly. In > any case, mxNumber worked well enough so I stuck with it. I'm sure mxNumber works just fine, but for some users installing all of mx-base first, then all of mx-experimental, might be a bit much, perhaps, if all they need is the use of GMP (also, I don't think the egenix stuff supports Python 2.3 yet? no doubt just temporarily). So, anyway, I've just updated gmpy with a few outstanding issues (all already solved in CVS, except one case of misdiagnosis when wrong numbers of arguments were passed to some functions, kindly reported by Paul Rubin -- but I hadn't done a "file release" to pick up the CVS enhancements in quite a long while!) and released it as 1.0 alpha. The released Windows binaries, by the way, now require Python 2.3. Alex From sismex01 at hebmex.com Fri Aug 15 18:24:14 2003 From: sismex01 at hebmex.com (sismex01 at hebmex.com) Date: Fri, 15 Aug 2003 17:24:14 -0500 Subject: Replace every n instances of a string Message-ID: [Hans Nowak] > > Something like this: > > # let s be the long string with unicode representation > z = [] > while s: > chunk, s = s[:72], s[72:] > z.append(chunk) > new_string = '\n'.join(z) > > HTH, > And the obligatory single-line list-comp version would be something like: new_string = "\n".join([ S[i:i+12] for i in xrange(0,len(S),12) ]) ...hmmm... something like that anyways. ;-) -gustavo Advertencia:La informacion contenida en este mensaje es confidencial y restringida, por lo tanto esta destinada unicamente para el uso de la persona arriba indicada, se le notifica que esta prohibida la difusion de este mensaje. Si ha recibido este mensaje por error, o si hay problemas en la transmision, favor de comunicarse con el remitente. Gracias. From Ragu_Bharadwaj at vrtx.com Thu Aug 21 09:13:05 2003 From: Ragu_Bharadwaj at vrtx.com (Ragu) Date: 21 Aug 2003 06:13:05 -0700 Subject: max length of a python program Message-ID: <1ed07caf.0308210513.6556978a@posting.google.com> Is there a limit to the # of lines that can be in a Python program? cheers -Ragu From zhoney at wildmail.com Fri Aug 15 17:29:33 2003 From: zhoney at wildmail.com (Zora Honey) Date: Fri, 15 Aug 2003 16:29:33 -0500 Subject: Porting to Windows Message-ID: I've been programming Python on Linux for a while now, and I'm finally ready to start porting some of my stuff to Windows. Problem is I use os.system to perform a lot of tasks, making the porting difficult. There are some things (such as image manipulation using ) it's probably pretty impossible to do using Windows system calls. Other functions (such as printing) should be readily available. Does anyone know a good resource for learning some of this stuff? Also, is there any way to compile Python without embedding it in C? Thanks, Zora From justinjohnson at fastmail.fm Wed Aug 13 14:10:02 2003 From: justinjohnson at fastmail.fm (Justin Johnson) Date: Wed, 13 Aug 2003 12:10:02 -0600 Subject: Changing UNIX primary group In-Reply-To: References: Message-ID: <20030813181002.04DAF38434@www.fastmail.fm> Thanks. I was hoping for a python solution though. :-( Does anyone know of a way to do this in python? On 13 Aug 2003 08:52:40 -0700, "Inyeol Lee" said: > "Justin Johnson" wrote in message > news:... > > I have a unix id that has group1 for a primary group, and group2, group3, > > and group4 for supplementary groups. I'd like to change my primary group > > before running certain commands. So sometimes I might want group2 to be > > the primary group, and other times group3 or group4. > > > > I saw the posix module's setgid method, but it failed for me unless I was > > running as root. Also it only accepts the gid, but I'd rather pass in > > the group name, or somehow lookup the gid based on the name. > > > > Does anyone know a way to do all of this? > > Thanks much. > > -Justin > > These are not python solution; > > 1) make a setgid script and put your commands there, or > 2) use shell commands; > > echo "command1; command2;" | newgrp group2 > > -Inyeol > -- > http://mail.python.org/mailman/listinfo/python-list From jdhunter at ace.bsd.uchicago.edu Wed Aug 6 12:35:38 2003 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Wed, 06 Aug 2003 11:35:38 -0500 Subject: Is there some Python + IDE/RAD for real speed development??? In-Reply-To: <96fda9ac.0308060611.56dfca7e@posting.google.com> (edilmar@intersite.com.br's message of "6 Aug 2003 07:11:16 -0700") References: <96fda9ac.0308060611.56dfca7e@posting.google.com> Message-ID: >>>>> "Edilmar" == Edilmar writes: Edilmar> afirmation true? Edilmar> I look at wxPython and PyGTK, but the samples showed that Edilmar> we have to write MANY LINES of code to do simple Edilmar> things. Many people have wrote about the advantage of Edilmar> Python to write little code, but, when talking about Edilmar> GUIs, I think it's not really true, right? pygtk works with glade, a very nice RAD tool http://glade.gnome.org/ John Hunter From aleaxit at yahoo.com Tue Aug 19 07:25:50 2003 From: aleaxit at yahoo.com (Alex Martelli) Date: Tue, 19 Aug 2003 13:25:50 +0200 Subject: python-dev Summary for 2003-08-01 through 2003-08-15 References: Message-ID: Andrew Dalke wrote: ... > it where to install. I got confused amoung the options we > have now, esp. since there's no "site-packages" under MS > Windows. My Python 2.3 installation on MS Windows *DOES* have c:\Python23\Lib\site-packages\ ...! And if I recall correctly so had the older Python 2.2 installation (under c:\Python22 of course). So, what's different about yours...? Alex From shlomme at gmx.net Thu Aug 7 04:15:55 2003 From: shlomme at gmx.net (Torsten Marek) Date: Thu, 07 Aug 2003 10:15:55 +0200 Subject: using like and % in MySQLdb In-Reply-To: References: Message-ID: Dave Harrison schrieb: > Im sure this is a really obvious problem but : > > self.curs.execute( > """SELECT * FROM user WHERE login LIKE '%%s%'""", [login] > ) > > will not work ... gives me an "unsupported format character ''' (0x27)" > > escaping the %'s with % as the doco recommends wont work either. > Why don't you do self.curs.execute( """SELECT * FROM user WHERE login LIKE %s""", ("%"+login+"%", )) The problem with escaping the % characters is, that MySQLdb converts self.curs.execute("""SELECT * FROM user WHERE login LIKE '%%%s%%'""" , (login,)) to "SELECT * FROM user WHERE login LIKE '%'dave'%'" and I don't know how to prevent this. > however this : > > self.curs.execute( > """SELECT * FROM user WHERE login LIKE '%dave%'""" > ) > > does work > > so what's the go ? > cheers > Dave > From martin at v.loewis.de Fri Aug 8 01:57:57 2003 From: martin at v.loewis.de (Martin v. =?iso-8859-15?q?L=F6wis?=) Date: 08 Aug 2003 07:57:57 +0200 Subject: Phthon2.3 on win2ksp4 problem References: Message-ID: Gu Shaodong writes: > Any help about this ? See http://www.python.org/2.3/bugs.html. Most likely, you have installed Python into "Program Files", which does not work. Regards, Martin From jjl at pobox.com Sat Aug 2 20:52:44 2003 From: jjl at pobox.com (John J. Lee) Date: 03 Aug 2003 01:52:44 +0100 Subject: very newbie question References: Message-ID: <87vftfbm03.fsf@pobox.com> Gerhard H?ring writes: > Agent Mulder wrote: > > Hi group, > > I wonder if I can do Windows programming > > in python. I work with c++ now and do the > > Windows part raw. It's difficult to get my app > > over 150K (need some heavy inlining, that's all). > > Does python support nitty-gritty Windows- > > programming? > > The win32 extensions have support for a lot of the win32 API. Your Lightweight, but 'very alpha' (in the author's words): http://venster.sourceforge.net/ ctypes, py2exe (has some form of COM support, IIRC), McMillan installer are probably also all worth a look. [...] > 2) If you're really concerned about download size I have a project > named "PyhtonRuntime" in planning/proof-of-concept stage. The point of > this is that if you have n apps that depend on Python the Python > runtime will only be downloaded once. It also includes a dead simple > package system and it's win32 only. Cool. John From rdacker at pacbell.net Mon Aug 11 18:20:25 2003 From: rdacker at pacbell.net (rdack) Date: 11 Aug 2003 15:20:25 -0700 Subject: can't connect References: <644f6688.0308101448.526534f2@posting.google.com> Message-ID: <644f6688.0308111420.2fc2be9d@posting.google.com> rdacker at pacbell.net (rdack) wrote in message news:<644f6688.0308101448.526534f2 at posting.google.com>... > mysql 4.0.12 that comes with osx 10.2 > MySQLdb 0.9.2 > Python 2.2 (#1, 10/24/02, 16:10:52) i got build of python 2.3, and installed package for MySQLdb no prob. i can now connect/access ok. From george.trojan at noaa.gov Tue Aug 5 10:27:23 2003 From: george.trojan at noaa.gov (George Trojan) Date: Tue, 05 Aug 2003 14:27:23 +0000 Subject: xrange() question Message-ID: Why do I get an overflow error here: > /usr/bin/python Python 2.2.2 (#1, Feb 24 2003, 19:13:11) [GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-4)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> for n, x in zip(range(4), xrange(0, sys.maxint, 2)): ... print n, x ... Traceback (most recent call last): File "", line 1, in ? OverflowError: integer addition but not here: >>> for n, x in zip(range(8), xrange(0, sys.maxint)): ... print n, x ... 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 George From jacek.generowicz at cern.ch Wed Aug 27 05:09:00 2003 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 27 Aug 2003 11:09:00 +0200 Subject: My future Python IDE article References: Message-ID: mertz at gnosis.cx (David Mertz) writes: > So c.l.py readers... make the case for your favorite one getting on > the list. I'll have to sling in another vote for (X)Emacs. Even if you were to use Emacs exclusively for Python development, it already provides an excellent environment. However, as you approach the limit where Emacs _is_ your opearting system, the level of integration it provides is unsurpassable :-) From grey at despair.dmiyu.org Fri Aug 29 11:25:27 2003 From: grey at despair.dmiyu.org (Steve Lamb) Date: Fri, 29 Aug 2003 15:25:27 -0000 Subject: how fast is Python? References: Message-ID: On 2003-08-20, dan wrote: > However, there are definitely cases where a lot of code would need to > be optimized, and so I ask the question: How fast is Python, compared > to say a typical optimizing C/C++ compiler? Recently on the debian-user list someone asked why C was as popular as it was today with so many other languages around. Many people cited that C runs faster. A bunch of Python people (myself included) pointed out we could develop faster. Finally someone else asked why a large program (in this case Evolution) couldn't be written in Python since it isn't processor intensive. My answer hit it in one: "It wouldn't idle as fast?" Except for some rare instances in most cases any program waiting on user input is going to be sitting idle almost the entire time that it is running. Given that is there anyone who really cares how fast it idles? As others have pointed out for the few cases where the program isn't idling and the user might have something he's waiting on then clearly stepping down to C and wrapping that in Python will help. -- Steve C. Lamb | I'm your priest, I'm your shrink, I'm your PGP Key: 8B6E99C5 | main connection to the switchboard of souls. -------------------------------+--------------------------------------------- From carroll at tjc.com Sun Aug 24 02:31:20 2003 From: carroll at tjc.com (carroll at tjc.com) Date: Sat, 23 Aug 2003 23:31:20 -0700 Subject: __all__ as it relates to _foo, _bar, etc. Message-ID: I'm trying to get straight about the difference and interaction between the __all__ variable and the prefixing a variable name with a single underscore (e.g., _foo, _bar). My understanding is that if you code: from ModuleName import * if __all__ is initialized in the module, all of the names listed in that list are made available; if __all_ is not initialized, every name not beginning with an underscore is made available. If you code: import ModuleName Neither the __all__ or the underscore-prefixed names make any difference, because the names from the module are not made available except through an explicit reference to them (e.g., ModuleName.spam), regardless of whether __all__ was initialized or whether the variable is prefixed with an underscore (i.e., you can reference ModuleName._spam if you wish, but of course do so at your own risk). Is my understanding correct? If I understand this right, then, if the coder of a module initializes __all__, he need not worry about the _foo convention as far as namespaces are concerned, anyway; the __all_ overrides that for the "from ModuleName import *" form of import, and the importing namespace is unaffected if using the "import ModuleName" form. Right? From bromden at gazeta.pl.no.spam Wed Aug 13 07:03:15 2003 From: bromden at gazeta.pl.no.spam (bromden) Date: Wed, 13 Aug 2003 13:03:15 +0200 Subject: Determine file type (binary or text) In-Reply-To: References: Message-ID: > >>> f = os.popen('file -bi test.py', 'r') > >>> f.read().startswith('text') sorry, it's not general, since "file -i" returns "application/x-shellscript" for shell scripts, it's better to go like that: >>> import os >>> f = os.popen('file test.py', 'r') >>> f.read().find('text') != -1 -- bromden[at]gazeta.pl From gh at ghaering.de Wed Aug 27 10:50:06 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Wed, 27 Aug 2003 16:50:06 +0200 Subject: pure Python DB In-Reply-To: <7876a8ea.0308270634.26d02fec@posting.google.com> References: <9a6d7d9d.0308261756.5b37cbf4@posting.google.com> <7876a8ea.0308270634.26d02fec@posting.google.com> Message-ID: <3F4CC51E.6080300@ghaering.de> David Rushby wrote: > Gerhard H?ring wrote: >> If you need [concurrent transactions] I'd suggest you switch to a >> client-server database like PostgreSQL. > > No need to go client/server. Embedded Firebird supports concurrent > transactions with configurable isolation levels, foreign keys, views, > stored procedures, and other features one would expect from a > full-fledged RDBMS. [...] The included README says: """ But you should be aware that you cannot access single database from a number of the embedded servers simultaneously, because they have SuperServer architecture and hence exclusively lock attached databases. """ So it doesn't help in a multi-process environment, either (like in CGI scripts). But then again, CGI sucks :-P Embedded Firebird sounds like a good solution for small *multithreaded* application servers, though. > Plus it's fast--kinterbasdb with embedded Firebird 1.5-rc4 is about > twice as fast as pysqlite 0.4.3 in various trivial speed tests I've > tried. That's interesting. I wonder how much of that is because of the relatively inefficient Python wrapper over SQLite. Time to go on with my prototype for PySQLite 0.5 :-) -- Gerhard From john at rygannon.com Mon Aug 11 05:54:33 2003 From: john at rygannon.com (BadJake) Date: Mon, 11 Aug 2003 09:54:33 GMT Subject: ANNOUNCE: Rekall V2.0.2 References: <5.2.1.1.0.20030810065523.02c3ed10@66.28.54.253> Message-ID: <3f37675d$0$244$fa0fcedb@lovejoy.zen.co.uk> Hi I am using PHP-NUKE to handle Content Management, so I am forced to do things the PHP-NUKE way. I appreciate that it involes a few mouse clicks to to get to the screen shots but the alternative is to build my own web site and that would take far too much time. I have removed the need to register now so with the exception of a few irrelevant sections the whole site is open to all visitors. On a further point. I have had many requests for me to post a lot more information about Rekall than I did in my announment this I will do shortly One thing I have to say and I have said it many times, the beauty of Rekall is Python. Without Python Rekall would just be one of the many mediocre GUI database clients to be found on the web. I like to think of Rekall has being a Python editor with a specific aim of building database client applications Best Regards John From peter at engcorp.com Wed Aug 27 15:49:11 2003 From: peter at engcorp.com (Peter Hansen) Date: Wed, 27 Aug 2003 15:49:11 -0400 Subject: My own 12 points list References: Message-ID: <3F4D0B37.FE0CB101@engcorp.com> Gerrit Holl wrote: > > A. Lloyd Flanagan wrote: > > pruebauno at latinmail.com (nnes) wrote in message news:... > > > I have really no mayor gripes, and the few things I would change would > > > break backward compatibility, but here is the list anyway: > > > > > > 3.) Eliminate open (), use file () instead > > open() is deprecated, I don't know about plans to eliminate it. > > Doesn't 'deprecated' mean it will once be elimineted? It doesn't mean "will be", but usually means "might be". Nobody, except Guido with the time machine of course, can predict the future, so it expresses only intent. And sometimes a thing can be deprecated (as in "don't use this in new code") without anyone actually planning to eliminate it, ever. -Peter From faizan at jaredweb.com Fri Aug 1 13:10:17 2003 From: faizan at jaredweb.com (Fazer) Date: 1 Aug 2003 10:10:17 -0700 Subject: Showing IP address of a user... References: <7b454334.0307291005.53ee8c07@posting.google.com> Message-ID: <7b454334.0308010910.2969b2bc@posting.google.com> Jim Dabell wrote in message news:... > Fazer wrote: > > > I was wondering how I can show an IP address of a person who visits a > > Python web-page? Would I have to use Environment variables to access > > Apache's server variables which hold such values like in PHP or what? > > I see you've already been given answers to this, however bear in mind that > what you are determining is the IP address of the client, not the IP > address of the person visiting the page. In many cases, the two are not > the same, such as when the visitor is using a proxy. > > There's no reliable way of getting the IP address of the person, but you can > make things a little more reliable by examining the X_FORWARDED_FOR header > as well, since many proxies add this header to their requests (also bear in > mind that they may be private addresses, such as 10.0.0.1). Oh, thanks for the reference Jim! I will keep that in mind. From abuseonly at sgrail.org Sun Aug 24 00:13:44 2003 From: abuseonly at sgrail.org (derek / nul) Date: Sun, 24 Aug 2003 04:13:44 GMT Subject: Bug with win32 open and utf-16 file References: <27vekvc6evvn3m5jg8n1en2u42skat42qn@4ax.com> <2i1gkv0s7762vcs85rkdq6uvgk6oitje12@4ax.com> Message-ID: <78egkvg1tu0j1kvedclcefn01hr3vkqh4v@4ax.com> On Sun, 24 Aug 2003 05:40:56 +0300, Christos "TZOTZIOY" Georgiou wrote: >On Sun, 24 Aug 2003 00:29:27 GMT, rumours say that derek / nul > might have written: > >>>[snip opening 'rb' a UTF-16 file] >>> >>>>The original file has line terminator characters of 00 0d 00 0a. >>>>After being read into a variable or a list the line termination characters have >>>>been changed to 00 0a 00 0a > >I believe you don't explain completely your situation, or maybe I am >missing something. The code you posted, which I will quote right here: > >>#!c:/program files/python/python.exe >># win32 python 2.3 >> >>import sys, string, codecs >>#eng_file = list (open("c:/program files/microsoft games/train >>simulator/trains/trainset/dash9/dash9.eng", "rb").read()) # read the whole file >>eng_file = open("c:/program files/microsoft games/train >>simulator/trains/trainset/dash9/dash9.eng", "rb").read() # read the whole file >> >>print hexdump (eng_file) # ok > >opens the file in 'read binary' mode, and without further processing you >pass the data just read to the function hexdump (presumably written by >you). The output of the hex dump shows only \u000a and not any \u000d. >I tried it by downloading your file and ran: hexdump (not mine) import cStringIO def hexdump(data): global printable_chars addr, bytes, ascii = "$00000000", [' '] * 20, [' '] * 20 result = cStringIO.StringIO() print >>result, "Dump of %d Bytes (type %s)" % (len(data), type(data)) for i in range(len(data)): byte = ord(data[i]) bytes[i%20], ascii[i%20] = "%02X" % byte, printable_chars[byte] if i%4 == 3: bytes[i%20] += " " if (i % 20) == 19: print >>result, addr, ''.join(bytes), ''.join(ascii) addr, bytes, ascii = "$%08X" % (i+1), [' '] * 20, [' '] * 20 i = len(data) if i and (i % 20) <> 0: print >>result, addr, "%-45s" % ''.join(bytes).strip(), ''.join(ascii) return result.getvalue() printable_chars = ['.'] * 256 for __c in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"$:;-#+*%&/()=?'": printable_chars[ord(__c)] = __c >>>> data = file("c:/dash9.eng", "rb").read() >>>> data[-10:] >'\r\x00\n\x00)\x00\r\x00\n\x00' Interesting, I have just done the same and it would appear that the hexdump routine is changing 0d to 0a ??? output from my screen >>> data[2:] 'S\x00I\x00M\x00I\x00S\x00A\x00@\x00@\x00@\x00@\x00@\x00@\x00@\x00@\x00@\x00@\x0 0J\x00I\x00N\x00X\x000\x00D\x000\x00t\x00_\x00_\x00_\x00_\x00_\x00_\x00 \r\x00\n\x00 \r\x00\n\x00 W\x00a\x00g\x00o\x00n\x00 \x00(\x00 \x00D\x00a\x00s\x00h\x009\x00 This sequence is correct This will teach me to have faith in code I have not tested!! >which seems correct to me (\r is 0x0d, \n is 0x0a, and the file is >indeed utf-16 le (little endian). Which open command are you using? If >you just enter open in the python prompt, does it show: > >>>> open > > >or what? I am not running in immediate mode, I am running 'python apply_physics.pl' I don't understand what the data[-2:] is doing, could you explain please or point to some notes on this. thanks Derek From aleaxit at yahoo.com Thu Aug 21 08:38:38 2003 From: aleaxit at yahoo.com (Alex Martelli) Date: Thu, 21 Aug 2003 14:38:38 +0200 Subject: open.read In-Reply-To: References: Message-ID: <200308211438.38899.aleaxit@yahoo.com> On Thursday 21 August 2003 01:49 pm, Fran?ois Pinard wrote: ... > In more recent versions of Python, the `open' built in function has been > replaced by the `file' built in constructor, and `open' has been made an > alias for `file', so the above may more adequately be written: > > stuff = file("filename", "r").read() Except that, since open is an alias (and NOT deprecated), it's exactly equivalent (IMHO) which name you choose to use. If open ever DOES get deprecated (perhaps in 3.0, some years from now) that may change. > The file object created by the `file' constructor has its own destructor, > which closes the file automatically if not done already. Using `file' is In terms of the definition of the Python *language*, the "own destructor" will run whenever it pleases; thus, it's CONCEIVABLE that (in some perfectly valid and correct implementations of the Python language) the file's closing is delayed all the way to the end of the program. Keeping files open needlessly is A Bad Thing, and if you're not closing them explicitly you're relying on an IMPLEMENTATION detail (which may vary between otherwise perfectly valid Python implementations) to save you from that Bad Thing. Don't. > Pythonesque. For simple usages like the one above, you can safely rely on > Python for destroying the file object, even in extra-serious programs :-). > "Better" is a question of opinion, but in the case here, it seems to me > that cluttering your code with an assignment, only meant for an explicit > close, does not buy you legibility, and moreover, your assignment will get > your closed file object uselessly hanging around. Best is exactly what you > did. (I would have not used the `, "r"' part in this case.) I agree that the explicit use of the default 'r' option is debatable (explicit is better than implicit, but one does not want extra clutter -- hard to call). I emphatically disagree that relying on an implementation detail to avoid uselessly hogging resources is 'best'! If the few bytes taken by a closed fileobject matter in your case -- that's what the del statement is for. > > it will make your code more usable in Jython, > > This is likely the only real advantage of cluttering your code, when you > know or bet that you are going to use Jython one of these days. Or PyPy, or some future implementation of Python for dotNET, or perhaps some optimizer such as psyco if it uses the semantic freedom the language definition so explicitly grants it to speed programs up by delaying/bunching up destructor-calls -- or, really, *ANY* implementation of the Python language save for those for whom you "KNOW" enough about implementation details and particularities to rely on their "eager" destructors-call semantics. The distinction between a language and its several implementations is very important. A language defines an interface, via its specs; each implementation that is correct implements that interface within the degrees of freedom the language specs give it. PROGRAM TO AN INTERFACE, NOT TO AN IMPLEMENTATION is a wonderful, indeed crucial principle. Relying on "extras" that specific implementations ensure above and beyond what the INTERFACE'S specs guarantee is generally not good programming style. You get away with it in small and/or "intended as throw-away" programs. But it breeds bad habits that may easily trip you when the time comes to write huge applications that will last a long time and end up using other implementations of the same language. The idiom file('blah').read() == just like the perfectly identical one open('blah').read() == relies on implementation details: using it is a violation of the "program to an interface" principle. Now try/finally IS slightly bothersome to use -- you have to put the initialization BEFORE the try, not IN it, for example -- yet its semantics are truly crucial. This is the reason easier-to-use syntax alternatives to try/finally are considered on Python-Dev -- encourage everybody to rely on GUARANTEED finalization rather than implementation accidents that may work on some correct implementations of the Python language but NOT on others. But even now, though the syntactic enhancements are not there yet and nobody can be sure if and how they'll eventuate, the semantics of try/finally are just as important -- and, IMHO, in any "real" program well worth the little bothers that try/finally gives. Alex From aleax at aleax.it Wed Aug 6 11:36:07 2003 From: aleax at aleax.it (Alex Martelli) Date: Wed, 06 Aug 2003 15:36:07 GMT Subject: Copying objects style questions References: Message-ID: Bengt Richter wrote: ... >>def __copy__(self): >> class EmptyClass: pass >> obj = EmptyClass() >> obj.__class__ = self.__class__ >> obj.__dict__.update(self.__dict__) >> obj.items = list(self.items) >> return obj >> >>??? It seems simpler and more automatic than your 'copy protocol'; >>subclasses don't need to do anything special unless they need to >>"deepen" the copy of some of their attributes. Btw, if you're >>using new-style classes, you'll want to use object instead of >>EmptyClass, or start with obj = self.__class__.new(self.__class__) > > > I don't think you meant object() as a direct substitute for EmptyClass() Right -- you couldn't assign __class__ on an object() result, for example. > above, right? And you meant to put tails on that "new," presumably. > Right again. So, for completeness, with a new-style class you could do, e.g. (probably optimal or close to it): def __copy__(self): obj = self.__class__.__new__(self.__class__) obj.__dict__.update(self.__dict__) obj.items = list(self.items) return obj Sorry for the sloppy expression in those hurriedly-written two lines;-). To forestall further misunderstandings -- this would not work for objects with __slots__ (no __dict__) or inheriting from classes with __slots__ (wouldn't copy attributes not in __dict__) -- there is always more work needed for such cases. But if one uses __slots__ one *deserves* to have to work a bit harder as a result;-). Alex From mack at incise.org Fri Aug 15 01:57:24 2003 From: mack at incise.org (mackstann) Date: Fri, 15 Aug 2003 00:57:24 -0500 Subject: dict->XML->dict? Or, passing small hashes through text? In-Reply-To: <16188.28023.216400.94715@montanaro.dyndns.org> References: <20030815042536.GA19960@incise.org> <16188.28023.216400.94715@montanaro.dyndns.org> Message-ID: <20030815055724.GB19960@incise.org> On Fri, Aug 15, 2003 at 12:19:51AM -0500, Skip Montanaro wrote: > mack> I'm basically passing little messages around, which are basically > mack> just hashes, and up until now, I was using a dict that I formatted > mack> to/parsed from a special syntax, but I keep running into growing > mack> pains with that. I'm using SocketServer, and each connection > mack> sends one line of data, and then the connection is closed by the > mack> server. > > Check out xmlrpclib in the Python distribution for quite awhile. It also > interoperates with XML-RPC libraries written in other languages. That was something I've looked at, and honestly I need to look at it further, but at first I was turned off because it implements its own little server, so I'd have to gut mine. But that's not a reason to rule it out completely. > There are > plenty of other choices as well, including Pyro (Irmen de Jong I believe) Pyro looks really cool! This tempts me to forget about non-Python interoperability. :) I'm actually really torn over this. > and an XML-based pickle format from David Mertz (check > http://www.gnosis.cx/), This actually looks like it might be perfect! > not to mention using marshal or pickle then > transporting the strings using SocketServer. This was something I was actually toying with - pickling objects, and then converting them to base64. The downsides are being non-python-unfriendly, and making hand testing (e.g. typing stuff into telnet or netcat) a little more work. Another concern with pickle is that (I think?) I can recall reading about how it is bad to blindly unpickle things that come in from an untrusted source, and that makes sense, as even accessing attributes could run arbitrary code, which seems.. bad. :) -- m a c k s t a n n mack @ incise.org http://incise.org Man usually avoids attributing cleverness to somebody else -- unless it is an enemy. -- Albert Einstein From m_mommer at yahoo.com Fri Aug 22 04:48:19 2003 From: m_mommer at yahoo.com (Mario S. Mommer) Date: 22 Aug 2003 10:48:19 +0200 Subject: What's better about Ruby than Python? References: <3F41505F.69D18CC8@alcyone.com> <66d7kvonvb2n0nqbqahhd5roak7ur81sob@4ax.com> <3f43ef5d_4@127.0.0.1> <3F440A35.9030602@nyc.rr.com> <4o_0b.1665$Ej6.1182@newsread4.news.pas.earthlink.net> <8D01b.1721$Ej6.702@newsread4.news.pas.earthlink.net> <3F44ED2E.9070308@nyc.rr.com> <0V61b.1900$Ej6.1012@newsread4.news.pas.earthlink.net> <3F4504D7.20008@nyc.rr.com> Message-ID: "Andrew Dalke" writes: > As I pointed elsewhere, I tried a couple times to learn Lisp, > if only to figure out how to tweak Emacs. I never succeeded. > Perhaps for the same reason I never liked HP's stack oriented > calculators? Lisp is simple. ( ...) Where's the problem? Granted, you need an editor that helps you to match the parens (which is nothing particularly esoteric), but other than that, it is just a normal programming language. You've got functions, variables, loops, etc. even goto, (and macros, and code generation/manipulation facilities you have not seen nor will see anywhere else, but you do not need to use them for simple stuff). What was it that you couldn't understand? > For observational evidence of this, I suggest my own > subfields, computational biology and computational chemisty. > In the first there are bioperl, biopython, biojava, and bioruby, > all with active participants and a yearly confererence organized > by open-bio.org. But there is only a rudimentary biolisp project > with minimal code available and just about no community > involvement. In the latter, Python takes the lead by far over > any language other than C/C++/Fortran with commercial support > for a couple toolkits and several more free ones beyond that. > There's even a workshop in a couple weeks on the representation > of biomolecules for Python. There are also some Java and C++ > toolkits for chemical informatics. And again, there is no Lisp > involvement. > > I ask you why. You shouldn't confuse success with quality. For experimental evidence look at music charts. On the other hand, if people feel more confortable with python, then so be it. Lisp suffers also from historical problems. It was too big and too slow for mid-80's up to mid-90's PCs, and there where far too many incompatible dialects, which led to it falling in disgrace. But better compilers, moores law, more memory, and an ANSI standard have improved things up to a point where I think there is no reason not to use it. > And I assert that it's because Lisp as a language does not encourage > the sort of code sharing that the languages I mentioned above do. This is ridiculous. You don't know Lisp so you do not have an idea (hint: what you say is wrong), and thus you shouldn't be saying this. > So while it is very expressive for a single person, a single person > can only do so much. People regularly work in teams on lisp projects. Is that just an illusion of mine? From markus_wankus at hotmail.com Thu Aug 7 10:11:11 2003 From: markus_wankus at hotmail.com (Markus Wankus) Date: Thu, 07 Aug 2003 10:11:11 -0400 Subject: win32, COM, and Solidworks (again) - Still Trying References: Message-ID: On Thu, 7 Aug 2003 23:06:01 +1000 (EST), Andrew MacIntyre wrote: > On Wed, 6 Aug 2003, Markus Wankus wrote: > >> For my objects, dispatch.GetTypeInfo() causes the following exception: >> >> Traceback (most recent call last): >> File "F:\_DEV\solidworks\swpycom.py", line 12, in ? >> print sw._oleobj_.GetTypeInfo() >> pywintypes.com_error: (-2147467263, 'Not implemented', None, None) > > If you need to go beyond the IDispatch interface, Thomas Heller's ctypes > package looks to be your only option, short of creating a full-blown > Pythonwin wrapper (ala Pythonwin's MAPI support) for the SolidWorks COM > API. > Yes, I was looking into this but was a little mystified at first. I generated the python wrapper and had a look inside, but was unsure of the extent of the Python code I was going to be required to write, as well as type conversions. I guess I'll have another look at it. Thanks for the info. -- Mark From alanmk at hotmail.com Fri Aug 15 09:57:56 2003 From: alanmk at hotmail.com (Alan Kennedy) Date: Fri, 15 Aug 2003 14:57:56 +0100 Subject: "drop-in" DOM replacement for minidom? References: Message-ID: <3F3CE6E4.FF9BD7FA@hotmail.com> [Bengt Richter] >>Can you assume that you are dealing with valid (error-free) XML as input? [Paul Miller] > Yes, it is assumed to be valid. We don't even use a DTD. A quick nitpick. You need to be careful about terminology. In the strict XML sense, "valid" has a different meaning to what I think you intended. well-formed: an XML document is "well-formed" if it is "error free". valid: an XML document is "valid" if its structure matches the constraints expressed in its Document Type Definition (DTD). So the correct term in your posts would be "well-formed XML". "Valid XML" means something else entirely. in-quality-checking-mode-ly y'rs, -- alan kennedy ----------------------------------------------------- check http headers here: http://xhaus.com/headers email alan: http://xhaus.com/mailto/alan From news.collectivize at scandaroon.com Fri Aug 22 19:33:06 2003 From: news.collectivize at scandaroon.com (John Baxter) Date: Fri, 22 Aug 2003 16:33:06 -0700 Subject: [OT] Why is it called string? References: <3f44ce77$0$556$b45e6eb0@senator-bedfellow.mit.edu> <3F44DBF2.1010403@draigBrady.com> Message-ID: In article <3F44DBF2.1010403 at draigBrady.com>, P at draigBrady.com wrote: > Travis Whitton wrote: > >>"In computing, the word 'bit' is an abbreviation of what two other words?" > > > > Wow, I had no idea it was an abbreviation either. Luckily, dict had the > > answer > > waiting for me: > > > > From Jargon File (4.3.0, 30 APR 2001) [jargon]: > > > > bit n. [from the mainstream meaning and `Binary digIT'] > > > > It's nice to see the occasional thread on computing history rather than the > > endless stream of coding issues. > > I'm always surprised by the number of people > in computing that don't know this. > > bit is a contraction of "Binary digIT" > byte is a pun on the word bit (8 bits) > nibble is a pun on the word byte (4 bits) And for the NCR C-315 (early 1960s), the 12-bit word was called a "slab". This was a (near) abbreviation of "syllable" since someone felt that 12 bits was too small to call a "word". [Compared with IBM's 36-bit words (704, et seq) that made sense.] Data storage and the accumulator were variable in length, up to a few--8, I think--slabs. The accumulator grew and shrank as need to contain what it needed to, with a register named T@ ("tally of the accumulator") keeping track. A slab could be considered to hold 3 digits or two characters. (The machine was decimal, not binary, in the face it presented to the programmer. Including in memory addressing.) And that's my yarn for the day, at least in this thread. --John -- Email to above address discarded by provider's server. Don't bother sending. From adalke at mindspring.com Mon Aug 18 14:30:09 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Mon, 18 Aug 2003 12:30:09 -0600 Subject: What's better about Ruby than Python? References: Message-ID: Brandon J. Van Every: > Thanks for the statistics. It didn't address the subject line, but it was > interesting. Wasn't meant to. It was saying that you you have flawed reasons for your search. Either you do have ulterior motives for asking your question (be it a post-hoc justification for your interest, poor critical thinking skills, self-aggrandizement, or simple troll bait) or, if it really reflects your thoughts on what languages to evalutate then you should be looking at Haskell. Andrew dalke at dalkescientific.com From Simon.Wittber at perth.maptek.com.au Mon Aug 11 22:32:22 2003 From: Simon.Wittber at perth.maptek.com.au (Simon Wittber (Maptek)) Date: Tue, 12 Aug 2003 10:32:22 +0800 Subject: Possible to install from CD using distutils? Message-ID: <20E0F651F8B82F45ABCBACC58A2D995B032BAD@mexper1> Martin v. L?wis wrote: >"Simon Wittber (Maptek)" writes: > >>Try this command. It will let you write to a CD drive. >> >>mount -o rw /dev/cdrom /mnt/cdrom > >Did you try this? You can't mount a cdrom rw - the hardware just does not support writing to a CD-*ROM* (Read-Only Memory). It.. Was.. A.. Joke! From tjreedy at udel.edu Fri Aug 15 11:50:14 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 15 Aug 2003 11:50:14 -0400 Subject: Py2.3: Feedback on Sets References: <3b__a.9694$u%2.7778@nwrdny02.gnilink.net> Message-ID: "Raymond Hettinger" wrote in message news:3b__a.9694$u%2.7778 at nwrdny02.gnilink.net... > "Istvan Albert" > > > Then just by looking at the docs, it feels a little bit confusing to > > have discard() and remove() do essentially the same thing but only one > > of them raising an exception. Which one? I already forgot. I don't know > > which one I would prefer though. I agree that this is confusing -- like having both str.find and str.index. I would prefer one delete function with an optional param 'silent' to switch its 'not there' response from the default (either True or False, according to what seems to be the more common usage) to the other choice. (I know, I should have read draft more carefully and commented last fall -- but this seems like the sort of redundancy that Guido wants to remove in 3.0.) Terry J. Reedy From mike at nospam.com Wed Aug 20 12:48:10 2003 From: mike at nospam.com (Mike Rovner) Date: Wed, 20 Aug 2003 09:48:10 -0700 Subject: debugging with wingIDE References: Message-ID: joelgleizes wrote: > I try to debug a python project with WingIDE. > I load my main file and launch debug session with Run > button. > I see a first message: "Listening for back-connection" > and then appears this error message :"The debug > process never connected back to WingIDE. Aborting > debug session" > I haven't seen anything in the error-log file > > What does it mean? Tha IDE debugger was unable to connect to your program. >From WingDbStub.py: """ wingdbstub.py -- Debug stub for debuggifying Python programs Copyright (c) 1999-2001, Archaeopteryx Software, Inc. All rights reserved. Written by Stephan R.A. Deibel and John P. Ehresman Usage: ----- This is the file that Wing DB users copy into their python project directory if they want to be able to debug programs that are launched outside of the IDE (e.g., CGI scripts, in response to a browser page load). To use this, edit the configuration values below to match your Wing IDE installation and requirements of your project. Then, add the following line to your code: import wingdbstub Debugging will start immediately after this import statements. Next make sure that your IDE is running and that it's configured to do passive listening and accept passive connections from the host the debug program will be running on. Now, invoking your python file should run the code within the debugger. Note, however, that Wing will not stop in the code unless a breakpoint set set. If the debug process is started before the IDE, or is not listening at the time this module is imported then the program will run with debugging until an attach request is seen. Attaching only works if the .wingdebugpw file is present; see the manual for details. One win32, you either need to edit WINGHOME in this script or pass in an environment variable called WINGHOME that points to the Wing IDE installation directory. """ Mike From robin at jessikat.fsnet.co.uk Mon Aug 4 19:37:33 2003 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Tue, 5 Aug 2003 00:37:33 +0100 Subject: boost python & 2.3 References: <4WrXa.16855$an6.616226@news1.tin.it> Message-ID: In article , David Abrahams writes .. .. >ematic). > >I'm pretty sure this is just the "must include Python.h before any >other system header" problem. That translates into "must include a >Boost.Python header before any system header" when using Boost.Python. > >This issue is non-boost/non-python-specific. It's all about Posix. > this may be true, but it only started to cause problems on win32 with 2.3 vs 1.30.0. If its a Posix issuePosix must be really devilish :) -- Robin Becker From achrist at easystreet.com Mon Aug 18 02:57:51 2003 From: achrist at easystreet.com (achrist at easystreet.com) Date: Sun, 17 Aug 2003 23:57:51 -0700 Subject: slight csv misbehavior under Windows References: Message-ID: <3F4078EF.B3D94C6F@easystreet.com> I think that "wb" is obviously the correct format, and this is not a bug. CSV fields that contain an end of line within the field contain a single character end-of-line marker (I can never remember whether this is \r or \n), and this is not kosher for a Windows text file, so it must be a binary file. Al Thomas Womack wrote: > > I'm using the csv module in python 2.3 under Windows XP; it seems that > two separate mechanisms try to handle the perverse Windows habit of > ending lines with 0d0a, and so > > writer = csv.writer(file('foo.csv','w')) > for i in thing: > writer.write(i) > > produces lines ending 0d0d0a, and when you load this into Excel 97 the > data appears double-spaced. > > Opening the file with 'wb' solves the problem, but it would be lovely > were this either fixed or documented; it's rather unintuitive that a > file opened with 'wb' still ends lines with 0d0a. > > Please tell me if this is not the appropriate place to make this kind > of bug report. > > Tom From vanevery at 3DProgrammer.com Tue Aug 19 03:55:27 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Tue, 19 Aug 2003 00:55:27 -0700 Subject: Brandon's abrasive style (was Re: What's better about Ruby than Python?) References: <38ec68a6.0308172319.431a4fde@posting.google.com> Message-ID: Dave Harrison wrote: >> I ask tough questions about Python vs. other languages and platforms. > > Quite frankly most people of your ilk have a tendency to winge and > complain about "missing features" or "bad design" but do nothing to > contribute to the language. I fail to see why this puts you in any > position to ask the "tough questions" as you put it. If you see > something you consider to be a weakness, suggest a solution, don't > winge about the fact that it exists. Well, I can certainly put up or shut up about *that* ! http://pythonology.com/pipermail/marketing-python/ http://www.3dprogrammer.com/Python_Logo_Draft.JPG http://www.3dprogrammer.com/French_Python.JPG Warning, last 2 are 754K and 461K, and you'll probably need to scroll. I get tired of people who lack imagination, who think they know everything about why so-and-so asks such-and-such a question, or speaks in this-and-that a way. Who never exercise their imaginations, who don't try to see from someone else's perspective. What do you really do, yourself, to address the problems? And seeing these photos above, are you going to falsely conclude that I care about Python? I don't. Not yet, at any rate. This is a trial period. >> - You have to promote your language, grow its market share, to >> prevent that from happening. > > Who cares ? If you want to go stick up posters for Python go for it. That's why I spend my time working with the marketing-python crowd and not your ilk. As far as I'm concerned, you are the enemy of progress. Because progress requires relevance. "What language will be relevant 10 years from now?" That is my agenda. > You certainly appear like a troll, so how about a few suggested > solutions to these so called problems you raised ? Your wish is my command, Grasshopper. Now, what should I ask of you in return? I know: nothing. You will either see or you will not see. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From jjl at pobox.com Tue Aug 26 16:59:23 2003 From: jjl at pobox.com (John J. Lee) Date: 26 Aug 2003 21:59:23 +0100 Subject: Python is darn fast (was: How fast is Python) References: <2259b0e2.0308230737.8a9bc1c@posting.google.com> <2259b0e2.0308240638.38350cba@posting.google.com> Message-ID: <87wud05e50.fsf@pobox.com> danbmil99 at yahoo.com (dan) writes: > mis6 at pitt.edu (Michele Simionato) wrote in message > news:<2259b0e2.0308240638.38350cba at posting.google.com>... [...] > This is a far cry from the factor of 10-30 I've been seeing with pure > python. For performance-critical code, this could be the difference > between hand-coding 5% versus 20% of your code. > > Excellent news!! If you care about this a lot, don't forget Pyrex. John From tottinge at indy.rr.com Sat Aug 16 22:54:42 2003 From: tottinge at indy.rr.com (Tim Ottinger) Date: Sun, 17 Aug 2003 02:54:42 GMT Subject: Is Python your only programming language? References: Message-ID: > On Tue, 12 Aug 2003 05:44:45 GMT, "Joe Cheng" > wrote: > >>I want to ask you hard-core c.l.p Pythonistas: Do you use Python for >>everything? (and I'm counting Python + C extensions as just Python) Oh, how I wish. Although I do like my spattering of SQL too. And I don't hate C and C++ (which account for most of my 24yrs of programming). At least not as much as I hate Java. I probably could use python for just about everything I do these days. A different Tim From sybrenUSE at YOURthirdtower.imagination.com Wed Aug 27 13:04:12 2003 From: sybrenUSE at YOURthirdtower.imagination.com (Sybren Stuvel) Date: 27 Aug 2003 17:04:12 GMT Subject: sed with python References: Message-ID: David Raleigh Arnold enlightened us with: > How do I use python as a wrapper for sed and/or gawk scripts? You don't. Python can do anything sed and awk can, and much, much more. Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? From glc at well.com Thu Aug 28 10:12:04 2003 From: glc at well.com (Greg Chapman) Date: Thu, 28 Aug 2003 14:12:04 GMT Subject: Accessing members of Python class from C++ (Embedded Python)???? References: Message-ID: <743skv0054hk2qot12vsjcuo13lmqsbltf@4ax.com> On 27 Aug 2003 10:14:02 -0700, jgerard at fluid-studios.ca (JM) wrote: >If anyone is interested in the solution: > >pDict=PyObject_GetAttrString(PyObject,"__dict__") will get the local >symbol table (a dictionary) for the class. This may not be relevant to your needs, but a class's __dict__ only has references to the attributes actually declared in the class; it doesn't have inherited attributes. If you need access to all the attributes of a class, use PyObject_Dir(aClass), which returns a list of all attribute names declared in the class and it's superclasses (it's the C equivalent of the dir builtin). You can then use PyObject_GetAttr(aClass, attrname) to fetch the attributes themselves. --- Greg Chapman From mack at incise.org Sat Aug 30 21:58:42 2003 From: mack at incise.org (mackstann) Date: Sat, 30 Aug 2003 20:58:42 -0500 Subject: list.sort(func) speed In-Reply-To: References: Message-ID: <20030831015842.GF9311@incise.org> On Sat, Aug 30, 2003 at 08:27:19PM -0400, Terry Reedy wrote: > Google list for decorate sort undecorate pattern Awesome, thanks! I tried it three ways (including original), and timed each one a few times. ------------------- # 1. original way origlist.sort(self._basenameCmp) # 2. decorate sort undecorate w/ list comp. newlist = [ (os.path.basename(i), i) for i in origlist ] newlist.sort() origlist = [ i[1] for i in newlist ] # 3. decorate sort decorate w/ zip and map newlist = zip(map(os.path.basename, origlist), xrange(len(origlist))) newlist.sort() origlist = [ origlist[index] for basename,index in newlist ] ------------------- And here are the times: 1. Around 300ms 2. 75-80ms 3. 70-75ms And after further tweaking, I arrived at what seems to be the simplest and fastest way to go about it (variation on #3): newlist = [ pair[::-1] for pair in enumerate(map(os.path.basename, oldlist)) ] newlist.sort() origlist = [ origlist[index] for basename,index in newlist ] Thanks, -- m a c k s t a n n mack @ incise.org http://incise.org What this world needs is a good five-dollar plasma weapon. From stasz at tux.org Mon Aug 4 14:24:29 2003 From: stasz at tux.org (StasZ) Date: Mon, 04 Aug 2003 20:24:29 +0200 Subject: Passing Global Variables between imported modules References: Message-ID: On Mon, 04 Aug 2003 07:27:41 -0700, Sean wrote: > Is there any way to access global variables defined from within an > imported module? For example, lets say have a file called test2.py > that defines a simple class: > > class MyClass: > def __init__(self): > pass > > def printGlobal(self): > print globalVar > > > Now I have another file that imports test2, sets a global variable > called globalVar, and calles printGlobal() like so: > > from test2 import MyClass > > globalVar = "foo" > > mc = MyClass() > mc.printGlobal() > You can try overloading MyClass. from test2 import MyClass globalVar = "foo" class HisClass(MyClass): def printGlobal(self): print globalVar mc = HisClass() mc.printGlobal() Stas Z From dtolton at yahoo.com Tue Aug 12 03:22:13 2003 From: dtolton at yahoo.com (Doug Tolton) Date: Tue, 12 Aug 2003 07:22:13 GMT Subject: Is Python your only programming language? References: Message-ID: On Tue, 12 Aug 2003 05:44:45 GMT, "Joe Cheng" wrote: >I'm curious about something... many Artima.com members who have a Java >background and learned Python have come to the conclusion that Java and >Python are highly complimentary languages. They would never consider >filling the place Java has in their toolbox with Python, but recognize there >are many tasks where it really pays to add Python to the mix. > >I want to ask you hard-core c.l.p Pythonistas: Do you use Python for >everything? (and I'm counting Python + C extensions as just Python) Or do >you keep another language equally close at hand, and if so, what is it? And >finally, do you foresee a day when Python can be, for all practical intents >and purposes, your only programming language? > I know Java, C, C#, C++, Visual Basic, Python, Asp and now I'm getting into Lisp and Scheme. I'm familiar with quite a few others, but these are the ones I'm most comfortable with. I write 90% of my code in python, maybe even 95%. I used to write everything in C#, but I found that most of the time I was writing a form that had buttons to push and a rich text box for output (at least at my current position). When we have to deploy an app with an ide we'll use either VB or C#, and put the guts in python com classes which are called from the ide. Python has great COM integration (much better than either C# or VB incidentally), so it makes it really easy. I do see a day when all my programming could be done in python (although more likely it will all be done in Lisp). There are a few things that need I need to learn how to do, but ultimately I believe all the major pieces are in place. - I need to learn wxPython or one of the variants on building good cross platform guis better. - I need to learn how to deploy apps to end users better - I need to learn one of the web based python systems. You'll note, these are all centered around technologies I need to learn better, not techonlogies that need to be done still. As for an IDE, I already have one, it's call Emacs. Debugger, I just use pdb (althouh I wish it had, or I knew how to do Edit and Continue) From pwmiller1 at adelphia.net Sat Aug 16 17:06:16 2003 From: pwmiller1 at adelphia.net (Paul Miller) Date: 16 Aug 2003 14:06:16 -0700 Subject: Py2.3: Feedback on Sets (fwd) References: Message-ID: <2e363c08.0308161306.47a010ae@posting.google.com> mertz at gnosis.cx (David Mertz) wrote in message news:... > > * Is there a compelling need for additional set methods like > > Set.powerset() and Set.isdisjoint(s) or are the current > > offerings sufficient? > > As we all know, the size of the powerset of S, for len(S)==N, is 2**N. > Seems like it would be really easy to run into some long runtimes and > memory usage. Then again, power set really is a fundamental operation > on sets. And making users rewrite it each time is error prone. How is it error prone? if P is the power set operation, and S and X are sets, then X in P(S) is equivalent to X is a subset of S. I don't think that's all that error prone. The times when you will want to iterate over the *entire* power set of a set are probably very few, simply because of complexity issues. I can't see iterating over the whole P(S) where S contains more than about 100 elements being time feasible. From CousinStanley at hotmail.com Sat Aug 9 12:07:28 2003 From: CousinStanley at hotmail.com (Cousin Stanley) Date: Sat, 9 Aug 2003 09:07:28 -0700 Subject: How to print floating point in scientific format? References: <420ced91.0308081115.7060e551@posting.google.com> <420ced91.0308090642.176b856b@posting.google.com> Message-ID: The conversion to e format in the print statement seems to work OK if I iterate over the items in the array .... >>> import Numeric as N >>> >>> x = N.arange( 10. ) >>> >>> print x [ 0. 1. 2. 3. 4. 5. 6. 7. 8. 9.] >>> >>> for this_item in x : ... print '%e' % this_item ... 0.000000e+000 1.000000e+000 2.000000e+000 3.000000e+000 4.000000e+000 5.000000e+000 6.000000e+000 7.000000e+000 8.000000e+000 9.000000e+000 >>> -- Cousin Stanley Human Being Phoenix, Arizona From bokr at oz.net Fri Aug 15 18:22:54 2003 From: bokr at oz.net (Bengt Richter) Date: 15 Aug 2003 22:22:54 GMT Subject: cPickle alternative? References: Message-ID: On Fri, 15 Aug 2003 16:27:18 +0200, "Drochom" wrote: >Hello, > I have a huge problem with loading very simple structure into memory > it is a list of tuples, it has 6MB and consists of 100000 elements > If speed is important, you may want to do different things depending on e.g., what is in those tuples, and whether they are all the same length, etc. E.g., if they were all fixed length tuples of integers, you could do hugely better than store the data as a list of tuples. Secondly, you might want to consider being lazy about extracting the data you are actually going to use, depending on use patterns. One way to do that would be to have a compact index to the data, or store it in such a way that you can compute an index, and then write some simple class to define access methods. That's not a bad idea anyway, since it will let you change the way you store and retrieve data later, without changing the code that uses it. You could store the whole thing in a mmap image, with a length-prefixed pickle string in the front representing index info. There's a lot of different things you could do. But Alex's suggestion (upgrade to 2.3 and use protocol 2 pickle) will probably take care of it ;-) >>import cPickle > >>plik = open("mealy","r") >>mealy = cPickle.load(plik) >>plik.close() > > this takes about 30 seconds! > How can I accelerate it? Find a way to avoid doing it? Or doing much of it? What are your access needs once the data is accessible? Regards, Bengt Richter From skip at pobox.com Tue Aug 19 11:06:26 2003 From: skip at pobox.com (Skip Montanaro) Date: Tue, 19 Aug 2003 10:06:26 -0500 Subject: Unification of logging in Python's Standard Library In-Reply-To: <3a8e83d2.0308182217.7ccaf883@posting.google.com> References: <3a8e83d2.0308182217.7ccaf883@posting.google.com> Message-ID: <16194.15602.502118.493642@montanaro.dyndns.org> Matthew> With the inclusion of the new 'logging' module in Python 2.3, Matthew> I'm wondering whether there are plans to update the rest of the Matthew> Standard Library to use this module wherever there is logging Matthew> to be done. ... Matthew> A single, unified logging system across the entire Python Matthew> Standard Library would be a worthy goal for some future release Matthew> (Python 3000, or maybe even 2.4/2.5?). Rather than bring it up on python-dev as Alex suggested (I think it might get lost there as well), I think you should open a bug report on SF which identifies the problem and which modules you think need to be updated. This provides a record of how people think this task should be approached. As time goes on, patches for specific modules can be attached to the report and incorporated into the modules in question. Another alternative is to write a PEP, though I don't think this is necessarily required for this particular task. It also presents a higher barrier to action than a bug report. Skip From abelikov72 at hotmail.com Mon Aug 25 15:45:10 2003 From: abelikov72 at hotmail.com (Afanasiy) Date: Mon, 25 Aug 2003 19:45:10 GMT Subject: python gripes survey References: <78kkkvg8ckfio141es2of1p483ohbtbit5@4ax.com> Message-ID: <3rokkvckckdj6b679164jdnvqlbcfic67j@4ax.com> On Mon, 25 Aug 2003 18:32:35 GMT, Jordan Krushen wrote: >On Mon, 25 Aug 2003 18:14:30 GMT, Afanasiy wrote: > >> Sure you can return an associative array, but in my experience the >> preference is to return a tuple. I'll probably get flamed for saying so, >> but this is how I feel and it is unavoidable. Returning a struct in C is >> easier to deal with than returning a near-mystery tuple in Python. >On one hand, you could always return a dict in your own code. On the >other, I find dealing with returned tuples to be as easy as it gets: Obviously, in my own go I do not use near-mystery tuples. >def f(x, y, z): > return(z, y, x) > >a, b, c = f() >print a, b, c # 3 2 1 Yes, returning multiple values, ie. tuples, is useful, but using them as you would use structs in C is common and the root of my gripe. The problem I explained above has nothing to do with the code you write. The problem is knowing what integer position in the tuple represents what field. In C structs have named fields, but in Python tuple have integer fields. The meaning of tuple integer fields, for tuples used this way, is only known in the documentation, not the code directly. When tuples are used this way, to me, it is akin to using small arrays in C for multiple values, where it is common to define globals in all caps for the integer index supposed to be represented. This is not done in Python because it is very un-python, yet the same type of code which _causes_ this helpful convention *is* used in Python. Curious. Often this is not even done in C, because a struct is used instead. I thought this thread was for gripes, not detailed explanations and solutions. However, for a solution... Perhaps people should use dicts in the libraries more often than near-mystery tuples. It's much more explicit that way. When I have to re-explain and re-gurgitate something like this for benefit of one confused person I leave myself open to more confused attacks, and I don't like that. So if that happens this time, I will make sure not to elaborate so much next time, and will reply abruptly instead. "I have made this letter longer than usual because I lack the time to make it shorter." - Blaise Pascal From adalke at mindspring.com Fri Aug 1 00:51:35 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Thu, 31 Jul 2003 22:51:35 -0600 Subject: Python speed vs csharp References: Message-ID: David M. Cooke: > Here's my best version: > > exp = math.exp > def erfc( x ): Change that to def erfc(x, exp = math.exp) so there's a local namespace lookup instead of a global one. This is considered a hack. Andrew dalke at dalkescientific.com From mis6 at pitt.edu Sun Aug 3 16:45:44 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 3 Aug 2003 13:45:44 -0700 Subject: Dealing with paths (Unix question) References: Message-ID: <2259b0e2.0308031245.38fa1b2a@posting.google.com> paul wrote in message news:... > hey there all! > i'm writing some little programs, and i'd like to know about how to deal > with directories on unix. i've read up on this, but the docs don't really > mention much on it. do i use the pickle module, or something? > > what i'd like to do is read in a path, say > /home/username/images/ > and that path contains a dir called downloads and some png files, > and it also contains another dir called icons, which holds jpg, png and > gif files. > Now, is it posible to go through that top directory and recursively go > through /icons/ and /downloads/ and pick out all files of a certain > extension(only png files, for example)? > > something like: > for each_file in /home/username/images: > if image_extension is png: > add image path to list > but as i said, i need something to work recursively though an arbitrary > number of directories. > > sorry if i wan't too clear here :/ > if anyone can post some clues on the modules/methods i'd use, and maybe > some example code, that'll be *very* much appreciated! > > thanks for reading. > paul. You may also want to look at this recipe: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/212959 M.S. From dtolton at yahoo.com Sun Aug 24 15:36:36 2003 From: dtolton at yahoo.com (Doug Tolton) Date: 24 Aug 2003 12:36:36 -0700 Subject: macro FAQ References: <1ffd32d9.0308232315.3eadd758@posting.google.com> Message-ID: <1ffd32d9.0308241136.6e5050c6@posting.google.com> Jacek Generowicz wrote in message news:... > dtolton at yahoo.com (Doug Tolton) writes: > > > Also note that the examples presented are purposefully trivial and > > could in many instances be accomplished other ways, > > I hoped that the examples that I presented satisfied the requirements > that > > a) They be simple enough to understand > > b) not be (at least easily) implementable using existing Python > features > > c) Not be completely useless > > Did I fail ? :-) No I don't think you failed, I just wanted to nail down that specific point. The reason I purposefully used trivial examples was to illustrate the point the Macros don't somehow magically alter existing source code, rather they operate on source code that is passed into them. I actually liked your examples, I was just hoping to come at them from a slightly different example. > > > Essentially Macros allow you to pass in some variables that are then > > expanded into valid Python syntax which is then executed. > > Well, not just variables, data in general, some of which might be > variables, some of which might be variable names (identifiers) and > some of which might be (peudo-) code. > > > Question: Can't I accomplish this same functionality via string > > parsing and eval? > > > > Answer: Eval will accept any valid Python expression and execute it. > > This is however regarded by many as a security hole. Macros allow > > this type of expressiveness while limiting many of the security risks. > > With a Macro you can more specifically control what types of actions > > are permissible. > > I don't think that this is relevant (or true, for that matter). Lisp > macros do not expand arbitrary data that a user passes in, they appear > as literals in your source code. The security issues are the same as > those surrounding "os.system('rm -rf /')" appearing literally in your > source code. > > What is relevant, is the pain involved in doing it via strings. The > (pseudo) code that you pass to a Lisp macro, not only looks exactly > like Lisp code, but it is automatically tokenized and parsed for you, > and very easily manipulatable. > Again, I wanted to focus the discussion for a moment to help alleviate people's fear of Macro's, as they seem to be based on mis-understanding what they are about. Please forgive my over simplification. > > # Note, Jacek's method of using indentation is an interesting > > alternative to calling them as a > > # function. > > It's probably worth pointing out, again, how important Lisp's > uniformity of syntax is, for its macro system. Generally speaking, a > macro accepts as arguments some mixture of data, identifiers and > expressions (let's forget about the existence of Python statements for > now, they complicate the situation even more). How do you pass in a > mixture of data and code? > > Data is usually presented in a tuple: > > foo(datum1, datum2, datum3) > > Expressions are usually presented on separate lines: > > def foo(...): > expression1 > expression2 > expression3 > > Let's try to think of what a Python with-open-file macro call would > look like. > > In CL, with-open-file takes > > 1) a list containing an identifier (a symbol), a pathname (let's call > it a string) with some optional keywords. > > 2) arbitrary code > > It then binds the identifer to a stream associated with the file, and > expands the source code inside an exception handling environment. > > So, the expansion of a (simplistic) Python with_open_file might look > like this: > > outfile = file("foo/bar", "w") > try: > print >> outfile, foo(...) > for i in range(10): > print >> outfile, bar(...) > except: > perform the necessary closing and cleaning up > > But what should the corresponding call to with_open_file look like? > > We have to pass in the identifier "outfile" (this is where it is very > handy to have symbols as a first-class data type, as in Lisp), and the > file name "foo/bar" ... but then we also have to pass in the chunk of > code > > print >> outfile, foo(...) > for i in range(10): > print >> outfile, bar(i) > > In Lisp it would look something like this: > > (with-open-file (outfile "foo/bar" :direction :output) > (format outfile "~a" (foo ...)) > (dotimes (i 10) > (format outfile "~&~a" (bar i)))) > > Now, I refuse to contemplate passing the source code in a string, in > the Python version. > > Maybe we have to accept the distinction between data-like data, and > code-like data, having the macro accept both a tuple of arguments, and > blocks of code, so the call might look thus: > > with_open_file("outfile", "foo/bar", "w"): > code: > print >> outfile, foo(...) > for i in range(10): > print >> outfile, bar(...) > > (If you need to pass in more than one code block, each one would go in > a seperate "code:" block.) > > What could the definition look like? > > defmacro with_open_file(stream, filename, mode)(block1) > expand(stream) = file(filename, mode) > try: > expand(block1) > except: > perform the necessary closing and clearing up > > (expand would be a function which gets replaced by its argument, at > macro expansion time.) > > Hmm, just about bearable, I guess, but I doubt that it generalizes > very well. > > Note that we didn't transform the source code argument, just pasted it > in directly. If we wanted to manipulate it first, we'd be in for > serious suffering. > > > You could clearly accomplish this functionality using other means, > > I think it is best to steer clear of such examples, as experience > shows that some people will not be able to resist the temptation to > conclude (and suggest) that there is no point to macros, and the > discussion gets derailed. We've seen enough of "you could do this > quite easily without macros, but ...", and not enough of "This would > be soooo painful without macros ..." (I won't say "impossible", as > there is always Turing completeness.) > > What was wrong with my original examples? I'd like to know, so that I > can replace them with better ones. I agree some people have been derailed by that concept, but I'd hoped that making it painfully clear that this wasn't the only way to do it, nor was it necessarily a representative sample of Macros, that maybe some people would see conceptually what Macros are in an extremely simple way. The Hello World of Macros. Again, I thought your examples were fine, I just wanted to simplify them to help the discussion along. If you hate them that much, we can forget I ever posted them. :-p Doug Tolton From romany at actimize.com Tue Aug 26 04:30:55 2003 From: romany at actimize.com (Roman Yakovenko) Date: Tue, 26 Aug 2003 11:30:55 +0300 Subject: bool and unicode Message-ID: <91BFE89EFFA2904E9A4C3ACB4E5F2DF5027B0B@exchange.adrembi.com> Thanks. I am going to sleep a little :-). But still I expect this code to work. assert False == bool( str( bool( False ) ) ) The context of previous expression is in serialization. I save\read my data in\from XML file. So I expected this to work without any additional afford from me. But I was wrong. My mistake was exectly as you explain, thanks. Roman > -----Original Message----- > From: Erik Max Francis [mailto:max at alcyone.com] > Sent: Tuesday, August 26, 2003 9:12 AM > To: python-list at python.org > Subject: Re: bool and unicode > > > Roman Yakovenko wrote: > > > Hi. > > > > >>> bool( u'True' ) > > True > > >>> bool( u'False' ) > > True > > >>> > > > > May somebody explain or give a reference to reason of such > behaviour? > > Does this give you a hint? > > >>> bool('True') > True > >>> bool('False') > True > >>> bool('') > False > > The only string, Unicode or not, considered to be false is the null > string. All other strings are true, even if they spell the word > _false_. > > -- > Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ > __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE > / \ Procrastination is the thief of time. > \__/ Edward Young > -- > http://mail.python.org/mailman/listinfo/python-list > From prochak at netzero.net Thu Aug 21 00:49:51 2003 From: prochak at netzero.net (Erik Lechak) Date: 20 Aug 2003 21:49:51 -0700 Subject: Dictionary that uses regular expressions Message-ID: <1f0bdf30.0308202049.7d251469@posting.google.com> Hello all, I wrote the code below. It is simply a dictionary that uses regular expressions to match keys. A quick look at _test() will give you an example. Is there a module that already does this? Is there a way and would it be better to use list comprehension? (using python 2.3) Just looking for a better or more pythonic way to do it. import re class ReDict(dict): ''' A dictionary that uses regular expressions keys NOTE: if the redict finds more than one key that matches the re it returns a redict of all of the matching keys ''' def __init__(self): dict.__init__(self) self.re=1 def reOn(self): ''' turn regular expression matching on ''' self.re=1 def reOff(self): ''' turn regular expression matching off ''' self.re=0 def __getitem__(self,key): if self.re ==1: temp = ReDict() for item in self.items(): if re.search(key,item[0]): #line match temp[item[0]]=item[1] if len(temp)==1: return temp.values()[0] return temp else: return dict.__getitem__(self,key) def _test(): d=ReDict() d["price"]=7.25 d['call jan 5.0']=1 d['call jan 7.5']=1.5 d['put jan 7.5']=7.2 d['call feb 5.0']=2 d['call feb 7.5']=2.5 d['put feb 7.5']=6.8 d['call mar 5.0']=3 d['call mar 7.5']=3.5 d['put mar 7.5']=4 d['call apr 5.0']=4 d['call apr 7.5']=4.5 d['put apr 7.5']=6.2 d['call may 5.0']=5 d['call may 7.5']=5.5 d['put may 7.5']=4.9 print d['price'] #prints the price print d['call']['may']['7.5'] # prints individual value print d['call'] #returns a redict of all calls print d['put'] #returns a redict of all puts print d['may'] #returns a redict of all options in may _test() Thanks, Erik Lechak From aahz at pythoncraft.com Fri Aug 15 22:31:05 2003 From: aahz at pythoncraft.com (Aahz) Date: 15 Aug 2003 22:31:05 -0400 Subject: Module access from inside itself References: Message-ID: In article , Steven wrote: > >if __name__ == "__main__": >? ? opts, args = getop.getopt(sys.argv[1:], [], ["help"]) >? ? for opt in opts: >? ? ? ? if opt == "--help": >? ? ? ? ? ? print MY_MODULE.__doc__ ? ?# How do I get this? >? ? ? ? else: >? ? ? ? ? ? MyFunction(args) import __main__ print __main__.__doc__ -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From peter at engcorp.com Wed Aug 6 12:18:45 2003 From: peter at engcorp.com (Peter Hansen) Date: Wed, 06 Aug 2003 12:18:45 -0400 Subject: True References: Message-ID: <3F312A65.5312B6EA@engcorp.com> Daniel Klein wrote: > > The reason I'm taking a str() value is cuz it is being sent over a > socket to a non-python server process, where it is converted back to a > boolean. In that case, you'd be better off converting using your own routine rather than relying on a particular behaviour of str() for this test. Basically, do something like def boolean2String(boolVal): return { False : '1', True : '0' } [ not boolVal ] and save yourself any further future pain... From fredrik at pythonware.com Mon Aug 11 12:32:54 2003 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 11 Aug 2003 18:32:54 +0200 Subject: CLI+GUI References: <2259b0e2.0308080948.5a95e383@posting.google.com> <2259b0e2.0308090530.7519f195@posting.google.com> <2259b0e2.0308110517.7c4fa8c8@posting.google.com> Message-ID: Eric Brunel wrote: > Same problem, different solution: it made me give up on Windows 98... ;-) quoting microsoft's lifecycle page: "Mainstream support for Windows 98/98 SE ended on June 30th 2002, and no-charge incident support and extended hotfix support ends on June 30th 2003." > FYI, and just to make this post a bit more useful, it seems to be a problem in > Windows 95/98, since no problem ever occured with the same scripts/distros on > Win2k or WinXP, not to mention Unices... iirc, the problem is that (some versions of the) Tk DLL locks up during the cleanup phase (probably due to a race problem), and Win2k/XP is smart enough to kill the process when that happens. the sourceforge bug tracker has more details. From paulpaterson at users.sourceforge.net Fri Aug 22 00:55:22 2003 From: paulpaterson at users.sourceforge.net (Paul Paterson) Date: Fri, 22 Aug 2003 04:55:22 GMT Subject: Removing language comparisons References: Message-ID: <_mh1b.4405$Xp4.270013@twister.austin.rr.com> "A.M. Kuchling" wrote in message news:R-GdnebThaTFJdmiRTvUqA at speakeasy.net... > On Thu, 21 Aug 2003 12:07:33 +0000 (UTC), > Duncan Booth wrote: > > How about getting some new articles to be written by pairs of people, one > > Python user who knows a bit of the other language and one person who lives > > and breathes Perl/Java/Ruby/etc but knows a bit of Python? That way you > > A good idea, but unless some volunteer steps forward to do the work, it's > not going to happen. A lot of the documentation I am putting together for the vb2Py project is easily reworkable into a comparison of Python and Visual Basic. I don't mind spending some time on that if people think it is of value. Paul From mpeuser at web.de Wed Aug 20 14:47:54 2003 From: mpeuser at web.de (Michael Peuser) Date: Wed, 20 Aug 2003 20:47:54 +0200 Subject: Help with py2exe...com dll References: Message-ID: I was analysing some problems a week ago (see news:bhmbe5$nrq$07$1 at news.t-online.com Some Results from Trying to Cheat py2exe) I think py2exe ignores ANY path when loading out ot the exe. Kindly Michael P "news1.sympatico.ca" schrieb im Newsbeitrag news:Yjw0b.4328$HB4.548424 at news20.bellglobal.com... > > > I am developping a com (dll based) in python. I obviously use py2exe to > create the *.dll file. My program is based on 3 modules (the first one is > calling the two others). If all 3 modules are located inside the same > directory everything goes compiles and the com is created. However if I put > one of the module in a subfolder and try using the -i argument of py2exe > nothing compiles and python tells me that it cannot find the > subfolderX.packageX.py module. I have tried all the above: > > python.exe com_script.py py2exe -i subfoldername.modulename.py --com-dll > > python.exe com_script.py py2exe -i subfoldername.modulename --com-dll > > python.exe com_script.py py2exe -i subfoldername\modulename.py --com-dll > > python.exe com_script.py py2exe -p subfoldername --com-dll > > here is my startup script also: > > import sys > > sys.path.append("d:\\project\\projectX") > > sys.path.append("d:\\projets2\\projectX\\subfolderName") > > from distutils.core import setup > > import py2exe > > setup(name="The Big TEst", > > scripts=["MainModule", "Module2", "Module3"], > > version="1.0") > > > > From jjl at pobox.com Wed Aug 20 09:15:46 2003 From: jjl at pobox.com (John J. Lee) Date: 20 Aug 2003 14:15:46 +0100 Subject: ClientCookie bug (followup) References: <87fzk4sav2.fsf@pobox.com> <87znibzrnx.fsf@pobox.com> <87oeypdh92.fsf@pobox.com> <87k79a25pi.fsf@pobox.com> <84fc4588.0308182207.4c649b93@posting.google.com> <87ada5de3j.fsf@pobox.com> <84fc4588.0308200242.3e74e0a1@posting.google.com> Message-ID: <87smnwh3lp.fsf@pobox.com> pythonguy at Hotpop.com (Anand Pillai) writes: [...] > 'We', nothing royal about it. It is just me and my friend > & co-developer Nirmal Chidambaram. Apparently he has found > a way around some of the bugs in Clientcookie. He has written It'd be great if you made me aware what those bugs are! (BTW, no intent to offend with my comment about your plurality, or lack thereof -- it's just that the convention of using 'we' in source code comments is common enough that I've sometimes found myself using it even when writing code alone, which is funny.) > a new module using the existing Cookie module of python & > urllib2. One of the problems 'we' had with Clientcookie is that > it uses its own 'urlopen' methods which does not fit our > applications needs, so 'we' had to find a way around it. As I said before, if you know how to do that, please comment on the RFE I referenced in my last post. Jeremy Hylton is planning to look at the patch associated with that RFE in detail sometime, and you could save him some time if you know a way to do this without patching urllib2. And I'd like to know how to do it, too :-) > Once the code is ready, I will post it on my webpage, and > of course it is not a module in itself, so I think an > announcement to c.l.py is out of place. [...] Would you mind sending me an email? Thanks John From ta-meyer at ihug.co.nz Thu Aug 21 18:00:18 2003 From: ta-meyer at ihug.co.nz (Tony Meyer) Date: Fri, 22 Aug 2003 10:00:18 +1200 Subject: Reading/Writing Config Files In-Reply-To: <1ED4ECF91CDED24C8D012BCF2B034F1302E95287@its-xchg4.massey.ac.nz> Message-ID: <1ED4ECF91CDED24C8D012BCF2B034F13026F28A5@its-xchg4.massey.ac.nz> > I need to read/write config files that will be updated by > both users as well as programs. All config-file modules > that I have looked at so far aren't completely satisfactory: > > 1. ConfigParser: does not preserve order of entries in the > config file and comments when updating the file. This is > critical since people are going to be reading/updating those > files as well. You might also want to read the python-dev thread about ConfigParser from the start of the year: (I don't know what happened to the ability to make 'surgical' changes that was proposed, since google doesn't seem to have anything further than that thread, and I don't read python-dev. I gather that some improvements were checked in and then backed out, though, so you might even find your solution in the Python cvs history around the start of the year). Or this one from way back in 1999: =Tony Meyer From sjmachin at lexicon.net Mon Aug 4 09:06:09 2003 From: sjmachin at lexicon.net (John Machin) Date: Mon, 04 Aug 2003 13:06:09 GMT Subject: pyrex error References: <8YPWa.48874$YN5.38312@sccrnsc01> Message-ID: <3f2e5966.9631559@news.lexicon.net> On 4 Aug 2003 05:04:20 -0700, sjmachin at lexicon.net (John Machin) wrote: >Gerhard H?ring wrote in message news:... >> Bryan wrote: >> > [PyRex produces code using staticforward that won't work in the combination Python 2.3/MSVC] > >> 2) The other way to temporarily solve this problem is to use MINGW >> instead of MSVC. > >*One* other way, not *the* other way. If the OP wanted to muck about >downloading and becoming familiar with a different compiler, he could >also try the free Borland compiler. > >And here is a third, easier other way: fiddle with your >....\include\object.h so that it defines staticforward as extern. > and here is a fourth easier other way: fiddle with Pyrex itself: change staticforward to extern in line 169 of Nodes.py C:\sw\pyrex\Pyrex-0.8.2\Pyrex\Compiler>grep -n staticforward *.py Nodes.py:169: code.putln('staticforward char *%s[];' % Naming.filetable_cname) Nodes.py:263: code.putln("staticforward PyTypeObject %s;" % name) From vanevery at 3DProgrammer.com Tue Aug 19 03:35:44 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Tue, 19 Aug 2003 00:35:44 -0700 Subject: Brandon's personal style (was) References: <38ec68a6.0308172319.431a4fde@posting.google.com> Message-ID: Michael Geary wrote: > > Personally, I think it's worth taking a little extra effort to try to > compensate for the limitations of the medium. If you know that people > are more likely to misunderstand your intentions, why egg them on? Often, I have a misanthropic idea that I can negatively educate people. If people "get into it," and later it is pointed out how they got themselves into it, they might learn not to "get into it." I don't know if in 10 years' time, I'll find it pointless to educate anybody other than my own (future) children. I already have a theory of static archetypes. Think I posted that in one of these forums, in one of these kinds of interchanges. Basically, people change, but people change so slowly that you can't measure it in weeks or months. It takes years. So if you're dealing with people on a timespan shorter than a year, regard them as a static type. They are part of a system, an ecology of types. They are a certain enzyme. The Troll Hunters are a certain enzyme, so you espouse Buddhist wisdom to them and also killfile them. There is nothing else to do with them right now. Their growth will come later. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From wiebke.paetzold at mplusr.de Wed Aug 6 04:40:43 2003 From: wiebke.paetzold at mplusr.de (Wiebke Pätzold) Date: Wed, 06 Aug 2003 10:40:43 +0200 Subject: abstraction of the column names (classes) References: <13a533e8.0308051300.2d463b04@posting.google.com> Message-ID: On 5 Aug 2003 14:00:23 -0700, p-abel at t-online.de (Peter Abel) wrote: >Wiebke P?tzold wrote in message news:... >> Hi all! >> >> I create a database that contains a table. 'Nachname' is one of 13 >> column names. This program can search for >> a special letter. In my example it is 'ra'. and the search takes place >> in 'Nachname'. 'ra' takes place within a word. This is solved with >> regular expression. So that I can limit my search. >> For example: I can search for 'ra' and it is not relevant wich letters >> follow or wich letters are in front of 'ra'. >> Now I want to abstract the column name 'Nachname'. So I search in an >> unknown column. Only the user of the program should determine in wich >> class the search takes place. This input should happen in the view >> lines of testing the class. >> My task is it to change the program that a abstraction of the column >> names takes place. >> Please give me a detailed answer. If it is possible the changed >> program because I am very new in Python and I am orientationless. >> >> This is the program >> >> import sys >> import Mk4py >> import re >> >> db = Mk4py.storage("c:\\datafile.mk",1) >> vw = db.view("people") >> >> class PatternFilter: >> def __init__(self, pattern): >> self.pattern = re.compile(pattern) >> >> def __call__(self, row): >> try: >> nachname = row.Nachname >> except AttributeError: >> return 0 >> return self.pattern.search(nachname)is not None >> >> vf = vw.filter(PatternFilter("ra.*")) >> >> for r in vf: >> print vw[r.index].Nachname > >RegEx are really great and there are a lot of problems you can >only solve with them. But if I understand you right your problem >is to find a string where a substring is to be in, the simple >string operation does the work: >if String.find(substring) > -1: > >**find** will give you the position in String where substring >will occure the 1rst time and -1 if substring doesn't occur. > >e.g. >>>> nameList=['Meyer', 'Maxon', 'Johnson', 'Mueller'] >>>> for name in nameList: >... if name.find('er')>-1: >... print name >... >Meyer >Mueller >>>> > >So if you can get your columns contents in **ColumnList** >and your searchpattern in **SearchPattern** so the following >function could do the work: > >def getPatternMatches(ColumnList,SearchPattern): > foundList=[] > for n in ColumnList: > if n.find(SearchPattern) > -1: > foundList.append(n) > return foundList > >Regards >Peter there is another problem too. I have NOT a string. Ihave a TABLE. From sjmachin at lexicon.net Mon Aug 4 18:22:07 2003 From: sjmachin at lexicon.net (John Machin) Date: 4 Aug 2003 15:22:07 -0700 Subject: pyrex error References: <8YPWa.48874$YN5.38312@sccrnsc01> <7NtXa.62774$uu5.6090@sccrnsc04> Message-ID: "Bryan" wrote in message news:<7NtXa.62774$uu5.6090 at sccrnsc04>... > "Gerhard H?ring" wrote in message news:mailman.1059853685.20382.python-list at python.org... > > Bryan wrote: > > > [PyRex produces code using staticforward that won't work in the combination Python 2.3/MSVC] > > In the PySQLite sources, I added this snippet on top: > > > > #ifdef _MSC_VER > > #define staticforward extern > > #endif > > > > to make it compilable under MSVC/Python 2.3. *After* #include-ing > > "Pyhton.h" of course. > i've decided to go with gerhard's approach with one minor modification: > > #ifdef _MSC_VER > #undef staticforward > #define staticforward extern > #endif > > this solution is best for me because i want to take the resulting c file and give it to others so they can compile it on other OS's > and compilers. > > why can't this code be placed in the pyrex header? seems like a simple fix. What gave you the impression that it can't be put in? You tell us why *you* can't put it in. I'll tell you why it *shouldn't* be put in: because it's a kludge. The offending C code is a forward declaration of a char [] which is subsequently filled in with the name of the source .pyx file which is known at the time the staticforward is emitted. The principled fix is to declare and define the array in one hit. From cbarber at curl.com Tue Aug 26 13:28:19 2003 From: cbarber at curl.com (Christopher Barber) Date: 26 Aug 2003 13:28:19 -0400 Subject: crazy programming language thoughts References: Message-ID: Tim Roberts writes: > "Ryan Lowe" wrote: > > > >one of the things i love about python is its use of the actual words > >or/and/not/is/in, where other languages would use symbols ||/&&/?!@#$%, what > >have you. > > The "other languages" thing is a little one-sided. C and C++ are really > the only mainstream languages to use symbols for these constructs. and Java and C# and Tcl and Perl and Javascript, all influenced by C of course. - C From bdesth.nospam at removeme.free.fr Thu Aug 28 02:30:28 2003 From: bdesth.nospam at removeme.free.fr (Bruno Desthuilliers) Date: Thu, 28 Aug 2003 08:30:28 +0200 Subject: Script Discussion & Critique In-Reply-To: <3F4D4402.3060209@hotmail.com> References: <3F4D31B1.6080802@hotmail.com> <06eqkv4onjh5m4tcbbqkmh8lscaj5niatp@4ax.com> <3F4D4402.3060209@hotmail.com> Message-ID: <3f4d9f2c$0$16163$626a54ce@news.free.fr> hokiegal99 wrote: > derek / nul wrote: > >> here will do > > > OK, I have a few questions about the script at the end of this message: > > Is this script written well? Is it a good design? How could it be made > better (i.e. write to a file exactly what the scipt did)? I hope to use > it to recursively find a replace strings in all types of files (binary > and text). > > Thanks for any ideas, pointers or critique... most of the ideas behind > the script came from the list. > Err... Is this my version of Python having troubles, or could it be possible that nobody actually took time to *test* that script ? There is a real problem on line 15: > for root, dirs, files in os.walk(setpath): on Python 2.2.2, here is what I get : [laotseu at localhost dev]$ python rfp.py (snip) Traceback (most recent call last): File "rfp.py", line 15, in ? for root, dirs, files in os.walk(setpath): AttributeError: 'module' object has no attribute 'walk' [3]+ Done emacs testrfp [laotseu at localhost dev]$ Of course, 'walk' is in os.path, not in os. Python 2.2.2 (#2, Feb 5 2003, 10:40:08) [GCC 3.2.1 (Mandrake Linux 9.1 3.2.1-5mdk)] on linux-i386 Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> os.walk Traceback (most recent call last): File "", line 1, in ? AttributeError: 'module' object has no attribute 'walk' Now a another problem on the same line : >>> for root, dirs, files in os.path.walk(setpath): ... print root, dirs, files ... Traceback (most recent call last): File "", line 1, in ? TypeError: walk() takes exactly 3 arguments (1 given) Of course, this is not the syntax nor the way to use os.path.walk I checked the os module for a function with similar syntax and usage, and could not find one. os.listdir would have been a candidate, but it does not recurse, and do not return a (root, dirs, files) tuple but a list of filenames. So what ? Bruno From cartermark46 at ukmail.com Thu Aug 14 15:19:35 2003 From: cartermark46 at ukmail.com (Mark Carter) Date: 14 Aug 2003 12:19:35 -0700 Subject: ClientCookie bug References: <87fzk4sav2.fsf@pobox.com> Message-ID: jjl at pobox.com (John J. Lee) wrote in message news:<87fzk4sav2.fsf at pobox.com>... > Syver Enstad writes: > > > cartermark46 at ukmail.com (Mark Carter) writes: > > > > > I am using Windows 98, python 2.3, ClientCookie 0.4.3a. > > > > > > When I do: > > > import ClientCookie > > > import os > > > c = ClientCookie.MSIECookieJar(delayload=1) > > > c.load_from_registry() > > > > > > I get the response: > [...] > > > KeyError: 'USERNAME' > > > > > > Basically, it doesn't like USERNAME as an environment variable. > > > > I suspect this only works on "real" win32 (the NT family) operating > > systems, which define USERNAME, and not hybrid dos/win32 systems like > > the win9x family. > > Anybody know the best way to get the username without win32all > installed? > > Mark: I don't have a win9x box, but try replacing that > os.environ['USERNAME'] with getpass.getuser(). You'll need to stick > an import getpass in there too, of course. Let me know if that works. > > The rest of the code should work OK on win9x. > > > John My apologies - the bug exists in my own brain, not in the code. I had in mind that a fix would be required in ClientCookie - but now I know better. To get it to work, I simply called: os.environ['USERNAME'] = 'mark carter' # or whatever your name is before calling c.load_from_registry() # c is a MSIECookieJar It's an embarassingly simple solution to the problem - but it took me a while to figure it out. Although there is nothing wrong with code, perhaps it would help new users of the library to mention it. Maybe the solution is somewhat obvious in retrospect - but it took me a while before the penny dropped. Another approach - which I actually prefer - is to copy the cookie to the local directory and load it using load_cookie_data(). At first, I was having no end of problems with it - until I discovered that you should use the (binary) cookie, not an ASCII cookie that you obtain from performing a cookie export from MSIE. ... and don't forget to call ClientCookie.MSIECookieJar() WITHOUT the delayload argument. So, sorry for the false alarm - but hope my investigations will prove useful to others. From jjl at pobox.com Mon Aug 18 17:17:12 2003 From: jjl at pobox.com (John J. Lee) Date: 18 Aug 2003 22:17:12 +0100 Subject: What's better about Ruby than Python? References: Message-ID: <87u18ewtrb.fsf@pobox.com> "Roberto Amorim" writes: > > 6. The way Ruby handles parameterless functions as if they were > > properties. > > That's the thing I like most about Ruby. But I couldn't get past its [...] Appeals to me too, but, when it comes right down to it, the only reason I'm using Python and not Perl is that it has a really significant reduction in baggage. There just is no such difference between Python and Ruby, according to everything I've heard people put forward here as 'significant'. Python has more users. Nothing more to be said, as far as I'm concerned. I really wish I could say more for Ruby, as I'd very much like to sound less like a closed-minded programming language-monoglot. In my defence, like lots of people here I'm eager to learn Haskell and O'Caml, not to mention a bunch of others -- if only Python didn't do almost everything so well, there'd be more motivation... John From tim.one at comcast.net Thu Aug 7 21:46:19 2003 From: tim.one at comcast.net (Tim Peters) Date: Thu, 7 Aug 2003 21:46:19 -0400 Subject: random changes In-Reply-To: Message-ID: [dan] > I did try random.WichmannHill, which gives completely different data > to either the new or the old version. I expect you're confused about something, then, but there aren't enough details to guess what. Here's a run under 2.1.3: >>> import random >>> random.seed(123456789) >>> print repr(random.random()) 0.095213622685816457 >>> Here under 2.2.3: >>> import random >>> random.seed(123456789) >>> print repr(random.random()) 0.095213622685816457 >>> Here under 2.3: >>> import random >>> random = random.WichmannHill() >>> random.seed(123456789) >>> print repr(random.random()) 0.095213622685816457 >>> Same thing -- results should be (and are) bit-for-bit identical. Now show us what you do that leads to the "completely different data" conclusion. From vanevery at 3DProgrammer.com Tue Aug 19 00:43:12 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Mon, 18 Aug 2003 21:43:12 -0700 Subject: Brandon's abrasive style (was Re: What's better about Ruby than Python?) References: <38ec68a6.0308172319.431a4fde@posting.google.com> Message-ID: Cliff Wells wrote: > > The major problem appears to be your mode of communication. At first > I took your questions seriously, then I began to think you were > trolling (and a rather clever troll at that), and finally I've come > to the conclusion that you're not trolling, rather merely arrogant and > abrasive. Bingo! Guilty as charged. And I get more and more abrasive the more people call me a troll. As do most people who aren't actually trolling. I ask tough questions about Python vs. other languages and platforms. Some people can't handle it. Maybe they'd handle it if I diplomatically sugar coated it, but I'm not going to. Things to irritate the "Brandon's a troll" crowd some more: - Python is not a good language for low-level 3D graphics problems. C++ is better. - Python isn't a rapid prototyping godsend for every problem out there. - GUI and tools support can end up being more important than language niceties. - Microsoft C# and .NET are strategic threats to Python's prosperity and vitality, if not survival. - Pythonistas should consider trying to eat Java's lunch, because they aren't going to eat Microsoft's lunch. - Ruby has some mindshare among people with knowledge of Python. - Yet unnamed languages are capable of taking Python's place on the food chain. - You have to promote your language, grow its market share, to prevent that from happening. These analyses are called "sanity" in the Windows world. It's Reality On The Ground. It's really odd to come to a developer community where people are insular and freak out about these kinds of pronouncements. It makes Windows people wonder if Python people are capable of industrial relevancy. Fortunately, I was pointed to the marketing-python list and I've discovered that not all Python crowds are the same. The rest of you: wake up! Smell the Windows! -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. > You seem to get a large number of people who perceive you > as > a troll. While I no longer believe this to be true, the sheer number > of people in so many different newsgroups should perhaps indicate to > you > that you need to take a break from your local D&D group and socialize > a bit. You are lacking some fundamental skills in this area. You're > clearly intelligent and have in fact brought up some interesting > topics, but your lack of tact tends to take them off-track rather > quickly. > > For instance, do you really think publicly announcing that someone is > in your killfile hurts their feelings or somehow vindicates you? > That's rather pathetic, but makes sense given the source. I'd > venture that mentality is most common at the pre-teen level of social > interaction. > > > Regards, From kendall at monkeyfist.com Tue Aug 5 15:30:04 2003 From: kendall at monkeyfist.com (Kendall Clark) Date: Tue, 5 Aug 2003 15:30:04 -0400 Subject: Unable to run IDLE from 2.3? In-Reply-To: References: <1akviv4cpectdogklmuupg7rc37lhe1pc7@4ax.com> Message-ID: <20030805193004.GA9243@monkeyfist.com> On Tue, Aug 05, 2003 at 03:14:22PM -0400, Tim Peters wrote: > In addition to the two possible causes Alex spelled out, another common > problem is some *other* program setting up Tcl or Tk environment variables > pointing to an inappropriate version of Tcl/Tk. The installer for Ruby is > the most common culprit for this problem, so if you've installed Ruby that's > probably the cause. I'm battling what seems to be a related issue on RH 9 (accursed Red Hat!). I installed 2.3 from src tarball last week, and it worked fine. The new Idle is very sexy. Yay, idle. Then last night I decided to upgrade from RH 8 to RH 9 (accursed Red Hat!). That was a disaster on many fronts (it's not a good thing to have corrup CD media on the 3rd disc of a KRUD update...argh!), but it also totally trashed my 2.3's _tkinter.so. Now when I try to rebuild 2.3 from src, I can't seem to get a _tkinter.so which points to valid tcl & tk libraries (despite using "--with-libs="" to point to the libtcl & libtk RH 9 installed). (The extent of my dynamic library fu on Linux is to futz around with symlinks from the places where _tkinter.so wants to find tcl/tk libs to the places where they actually are on my RH 9 (accursed Red Hat!) system, then to rerun /sbin/ldconfig. This "trick" didn't work either.) So I decided that RH is completely evil (accursed Red Hat!), and I would just install Tk & Tcl from scratch in /usr/local/lib and rebuild 2.3 using those libs, like this: ./configure --with-libs="/usr/local/lib/libtcl8.4.so \ /usr/local/lib/libtk8.4.so" This works, but goddam what a pain in my ass...In case it's now clear by now: I hate Red Hat (though hitting back at SCO is pretty cool, trying to keep up with Python on a RH box has been way too painful for far too long). I recommend repeated playings, at max volume, of Bob Dylan's "Idiot Wind" if you have to fight this battle -- it seemed to help my mood. Kendall Clark -- Jazz is only what you are. -- Louis Armstrong From dyoo at hkn.eecs.berkeley.edu Tue Aug 12 18:36:49 2003 From: dyoo at hkn.eecs.berkeley.edu (Daniel Yoo) Date: Tue, 12 Aug 2003 22:36:49 +0000 (UTC) Subject: ANN: Baypiggies User Group Meeting August 13th 7:30pm Message-ID: BayPIGgies: Silicon Valley/San Francisco Bay Area Python Users Group When: August 13th, 2003 @ 7:30pm Where: Carnegie Institute of Washington at Stanford University; Palo Alto, CA Agenda: Python 2.3! Speaker: Brett Cannon Brett will be giving a talk on Python 2.3's new features, as well as the Python development process and his involvement with the python-dev summaries. You can find more information (and driving instructions) at: http://www.baypiggies.net Hope to see everyone there! From davesum99 at yahoo.com Wed Aug 13 22:53:12 2003 From: davesum99 at yahoo.com (smarter_than_you) Date: 13 Aug 2003 19:53:12 -0700 Subject: Is Python your only programming language? References: Message-ID: Been programming for 20 years, in (roughly this order): BASIC Assembly (various, starting with 6502) Forth C (a little) Lisp C++ Java and lately, Python I can say without a doubt, Py is so much closer to how my brain works, and I am _so_ much more productive (factor of 2.5 - 3 over C/C++), that I will be using it by default for everything that it can do, and will need to be torn away from it kicking and screaming when absolutely necessary (high-performance stuff mostly). Recently at a job interview my possible boss said he liked C#, and didn't know much about Python. That comment alone made me much less interested in the job. From romany at actimize.com Tue Aug 26 02:16:24 2003 From: romany at actimize.com (Roman Yakovenko) Date: Tue, 26 Aug 2003 09:16:24 +0300 Subject: bool and unicode Message-ID: <91BFE89EFFA2904E9A4C3ACB4E5F2DF502062C@exchange.adrembi.com> Hi. >>> bool( u'True' ) True >>> bool( u'False' ) True >>> May somebody explain or give a reference to reason of such behaviour? Thanks. Roman From writeson at earthlink.net Thu Aug 14 11:58:00 2003 From: writeson at earthlink.net (Doug Farrell) Date: 14 Aug 2003 08:58:00 -0700 Subject: Problem starting running demo.py with new wxPython-2.4.1.2 Message-ID: <88bc63c6.0308140758.6c44abb4@posting.google.com> Hi all, I just installed the wxPython-2.4.1.2 demo RPM on my RedHat Linux 9.0 machine, which has Python 2.2.2 on it, and I'm having a problem running the demo.py program. Here is a trace of the results: python demo.py The font "-*-helvetica-medium-r-normal--12-*-*-*-*-*-iso8859-1, -*-arial-medium-r-normal--12-*-*-*-*-*-iso8859-1, -*-helvetica-medium-r-normal--12-*-*-*-*-*-iso8859-15, -*-arial-medium-r-normal--12-*-*-*-*-*-iso8859-15,*-r-*" does not support all the required character sets for the current locale "en_US.iso885915" (Missing character set "ISO8859-15") (Missing character set "ISO8859-15") Traceback (most recent call last): File "demo.py", line 3, in ? import Main File "Main.py", line 16, in ? import wx # This module uses the new wx namespace File "/usr/lib/python2.2/site-packages/wx/__init__.py", line 45, in ? from wxPython import wx File "/usr/lib/python2.2/site-packages/wxPython/wx.py", line 6, in ? from misc2 import * File "/usr/lib/python2.2/site-packages/wxPython/misc2.py", line 18, in ? from utils import * File "/usr/lib/python2.2/site-packages/wxPython/utils.py", line 982, in ? wxCONFIG_USE_NO_ESCAPE_CHARACTERS = utilsc.wxCONFIG_USE_NO_ESCAPE_CHARACTERS AttributeError: 'module' object has no attribute 'wxCONFIG_USE_NO_ESCAPE_CHARACTERS' Anyone have any ideas/suggestions about what this is or what I can do about it? Thanks in advance for your help, Doug Farrell From jacek.generowicz at cern.ch Tue Aug 26 03:40:20 2003 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 26 Aug 2003 09:40:20 +0200 Subject: Advice to a Junior in High School? References: Message-ID: Howard, I fully agree with the suggestion that you should learn as broad a range of languages as possible. Awareness and appreciation of other styles of programming can make you a better programmer, even in languages which do not provide direct support for the styles you learned in other languages, and whose communities are not familiar the lessons learned in other communities. It seems to be extremely popular in the field of Information Technology (and by association, in the field of Computer Science), to avoid learning the lessons learned by others in the past, an re-invent the wheel repeatedly, usually making many mistakes on the way. Try to study the evolution of different families of languages, and try to observe what lessons were learned in the family's history. That way, you are less likely to be blinded by the hype that accompanies the latest fad language that comes along, but will be able to assess its worth. Remember that popularity and quality are very weakly correlated. I don't wish to suggest that populatrity is not important, but it's not all there is. The popularity of a given idea waxes and wanes; its inherent quality remains constant. "Sean Ross" writes: > (Lisp, Dylan, Haskell, ocaml, or some other functional programming > language). As an added bonus, studying many langugas reduces the chances of you misclassifying them, as has been done above :-) From cnetzer at sonic.net Tue Aug 12 14:11:11 2003 From: cnetzer at sonic.net (Chad Netzer) Date: 12 Aug 2003 11:11:11 -0700 Subject: Summer reading list In-Reply-To: References: <5d0_a.288$jw4.85@nwrdny03.gnilink.net> Message-ID: <1060711870.21962.19.camel@adsl-209.204.179.133.sonic.net> On Tue, 2003-08-12 at 08:56, Joe Cheng wrote: > Quoting from the comments: > > """Usage: > > heap = [] # creates an empty heap > heappush(heap, item) # pushes a new item on the heap > item = heappop(heap) # pops the smallest item from the heap > item = heap[0] # smallest item on the heap without popping it > heapify(x) # transforms list into a heap, in-place, in linear time > item = heapreplace(heap, item) # pops and returns smallest item, and adds > # new item; the heap size is unchanged""" > > It might just be my Java background creeping in (I'm a Python newbie), but, > wouldn't it be better if this was OO? > > heap = Heap() > heap.push(item) > item = heap.pop() > item = heap[0] > heapified = Heap(x) > item = heap.replace(item) > > Otherwise the user could easily break the heap by doing something dumb to > the list... True. But the flexibility of using the builtin is also nice. For example, you can add a bunch of objects to the list, then heapify once, rather than having to call heap.push() a bunch of times (which may be slower, because you need to maintain the heap property after you push each new item.) I think the idea is that, if you want a real Heap class, you can build one very easily (see below). And if you don't need a heap class, you can gain some benefits from this approach because it is exposing and operating on lists directly. This probably comes under "practicality beats purity". (See 'The Zen of Python', or type "import this" into your Python interpreter) Quick heap class (any error corrections are appreciated): --------------------------------------------------------- import heapq class Heap: def __init__( self, heap=[] ): heapq.heapify( heap ) self._heap = heap def __getitem__( self, i ): return self._heap[ i ] def push( self, item ): return heapq.heappush( self._heap, item ) def pop( self ): return heapq.heappop( self._heap ) def replace( self, item ): return heapq.heapreplace( self._heap, item ) if __name__ == '__main__': # Tests heap = Heap() heap.push(3) heap.push(2) heap.push(1) item = heap.pop() assert item == 1 item = heap[0] assert item == 2 item = heap.replace(4) assert item == 2 assert heap[0] == 3 assert heap[1] == 4 -- Chad Netzer From tzot at sil-tec.gr Sat Aug 23 23:22:55 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Sun, 24 Aug 2003 06:22:55 +0300 Subject: Modifying the {} and [] tokens References: <04cekv0s6ghjtuhl5j2gph7ltobdb5rsam@4ax.com> <62rekv0k4ucgrh46lkp27klq13pq8ppp5p@4ax.com> <1h3fkvg8mkeq69a8hriojugqfcp75hafjj@4ax.com> Message-ID: On Sun, 24 Aug 2003 01:50:01 GMT, rumours say that Geoff Howland might have written: >I'm glad that he is limiting things. Perhaps my plan would not have >worked out well anyway, but I was interested in giving it a shot. >Since it's not possible, I'll think up some other less hacky slightly >more verbose way to handle the issues. Geoff, since you invested already some time and energy on this thread, perhaps you should give it a shot, even if it requires some C fiddling. I did a research on google and it seems I got luckier than you: http://groups.google.com.gr/groups?selm=mailman.1056959572.10194.python-list at python.org I also found that the links do not seem to work at this moment in time, so a little more searching produced this: http://www.amk.ca/diary/2003/03/28.html - search for intrinsics in the page and then check this (a very long url): http://tinyurl.com/kzq6 which is the python slide show for Pycon 2003. So you can address JP Calderone and ask for the intrinsics.c code. -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From vkuznet at yahoo.com Fri Aug 8 12:28:18 2003 From: vkuznet at yahoo.com (Valentine Kouznetsov) Date: 8 Aug 2003 09:28:18 -0700 Subject: execute command in CURRENT shell Message-ID: Hi, simple question, how to execute command in current shell, not in subshell? Example. I have environment variable A=aaa and need to invoke shell (sh) script which will do something with A. If I do os.system() then sub-shell will setup A and execute my script there leaving A in parent shell untouched. Thanks, Valentine. From alan.gauld at btinternet.com Sun Aug 31 03:45:23 2003 From: alan.gauld at btinternet.com (Alan Gauld) Date: Sun, 31 Aug 2003 07:45:23 GMT Subject: Polymorphism the Python way References: Message-ID: <3f51a59a.30649281@news.blueyonder.co.uk> On Sat, 30 Aug 2003 20:55:30 -0700, Daniel Klein wrote: > class Dead(object): > def getthing(self): > return self.deadthing > > class Parrot(object): > def getthing(self): > return self.parrotthing > > ...and then somewhere in some script I use... > > self.getthing() I guess you mean object.getthing() since self would be inside a method... > Isn't there a better way to do this in Python? I hate doing these > 'get' type methods. The seem ugly to me. This isn't really a Python issue but one of general OOD. Its bad OOD practice to provide a getXXX method for every attribute just because they exist. But if it is a genuine public feature of the class - ie one of the objects responsibilities - to provide 'thing' information then object.getThing() is a valid way to go. Of course Python by default allows you to access the value directly if you wish, and you can also use the new "property" feature to hide the accessor method. And the name of the method could be changed to use a naming convention: class C: def __init__(s,t): s.myThing = t def thing(s): return s.myThing My old OO mentor used to say: "Methods support responsibilities, attributes support methods" In other words only expose those attributes which are also responsibilities. The rest should be hidden - that's why we call it data hiding! HTH, Alan G. Author of the Learn to Program website http://www.freenetpages.co.uk/hp/alan.gauld From dave at pythonapocrypha.com Sat Aug 23 06:30:07 2003 From: dave at pythonapocrypha.com (Dave Brueck) Date: Sat, 23 Aug 2003 04:30:07 -0600 Subject: Modifying the {} and [] tokens In-Reply-To: <774fkvg920qibnnp83r17inqmk311tqcsv@4ax.com> References: <2259b0e2.0308230718.53d22c14@posting.google.com> <774fkvg920qibnnp83r17inqmk311tqcsv@4ax.com> Message-ID: <200308230430.07033.dave@pythonapocrypha.com> On Saturday 23 August 2003 10:12 am, Geoff Howland wrote: > On 23 Aug 2003 08:18:49 -0700, mis6 at pitt.edu (Michele Simionato) > > >Python tries hard not to modify its basic syntax, so you must stay > >with the above. Pythonista would argue that this is a strenght of the > >language: "explicit is better than implicit". > > I agree with this philosophy too. I'm not sure where the changes I'm > looking to fail to be explicity. > > {} + {} makes sense right? You are adding them together. There will > obviously be a possibility of key clobbering, but then you could run > something like {}.intersect() and get the keys that will be clobbered > (if it existed). Does {'a':4} + {'a':6} equal (a) {'a':10} (b) {'a':[4,6]} (c) {'a':4} (d) {'a':6} ??? I can think of reasonable & realistic use cases where each one is the "obvious" choice. > len([]) > > [].len() If you can conjure up the right Google Groups query, this has been discussed many times in the past (and by that I mean some good points have been raised that you might find interesting). In particular, I remember Alex Martelli making a good argument for len(obj) over obj.len(). For my part, now that I'm used to len(obj), the form obj.len() seems too much like OO-just-for-the-sake-of-OO, which isn't very compelling. -Dave From pwatson at knightsbridge.com Tue Aug 19 19:23:35 2003 From: pwatson at knightsbridge.com (Paul Watson) Date: Tue, 19 Aug 2003 18:23:35 -0500 Subject: codec to parse raw UCS data? References: Message-ID: <3f42b17c$1_1@themost.net> "Fredrik Lundh" wrote in message news:mailman.1061308184.25736.python-list at python.org... > Oleg Leschov wrote: > > > Where can I find a list and documentation for codecs? > > What I want to do is to make a unicode string out of unicode data. > > for example. I am parsing NTFS metadata, that contains filenames as > > UCS-2 code, so I have a binary string that pretends to be a UCS-2. > > the "utf-16-le" codec is probably what you want. > > (utf-16 is basically ucs-2 plus mechanisms to encode characters outside > the 16-bit BMP set; IIRC, Windows 2k and later uses utf-16, not ucs-2). > > UTF-16 DSCS (Double Short Character Set) From simonb at webone.com.au Mon Aug 11 19:29:29 2003 From: simonb at webone.com.au (Simon Burton) Date: Tue, 12 Aug 2003 09:29:29 +1000 Subject: ascii problem References: Message-ID: what about this: >>> a = u'unicode string' Simon. From irmen at -NOSPAM-REMOVETHIS-xs4all.nl Sat Aug 23 12:07:04 2003 From: irmen at -NOSPAM-REMOVETHIS-xs4all.nl (Irmen de Jong) Date: Sat, 23 Aug 2003 18:07:04 +0200 Subject: Python is darn fast (was: How fast is Python) In-Reply-To: <2259b0e2.0308230737.8a9bc1c@posting.google.com> References: <2259b0e2.0308230737.8a9bc1c@posting.google.com> Message-ID: <3f479124$0$49116$e4fe514c@news.xs4all.nl> Michele Simionato wrote: > I posted this few weeks ago (remember the C Sharp thread?) but it went > unnoticed on the large mass of posts, so let me retry. Here I get Python+ > Psyco twice as fast as optimized C, so I would like to now if something > is wrong on my old laptop and if anybody can reproduce my results. I can. :-) I had to increase the loop counter by a factor of 10 because it ran too fast on my machine (celeron 533 mhz), and added a print statement of the accumulated sum (erg). These are my results: [irmen at atlantis]$ gcc -O3 -march=pentium2 -mcpu=pentium2 -lm erf.c [irmen at atlantis]$ time ./a.out 5190039.338694 4.11user 0.00system 0:04.11elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k 0inputs+0outputs (103major+13minor)pagefaults 0swaps [irmen at atlantis]$ time python2.3 erf.py 5190039.33869 2.91user 0.01system 0:02.92elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k 0inputs+0outputs (544major+380minor)pagefaults 0swaps This is with gcc 3.2.2 on Mandrake 9.1. While Python + Psyco is not twice as fast as compiled & optimized C, it's still faster by almost 30% on my system, which is still great!! --Irmen From aleaxit at yahoo.com Tue Aug 19 06:36:02 2003 From: aleaxit at yahoo.com (Alex Martelli) Date: Tue, 19 Aug 2003 12:36:02 +0200 Subject: What's better about Ruby than Python? References: <38ec68a6.0308181659.1aab5c67@posting.google.com> Message-ID: Asun Friere wrote: ... > Ah yes, back to substance. I forgot to mention that Ruby ranges seem > much more intuitive than Python slicing. But I think the confusion, Having both a..b AND a...b -- one indicating a half-open range, another indicating a closed range -- "more intuitive"? You gotta be kidding... > to the extent that confusion does exist, is because Python has one > foot in the C-like 'n-1 indexed array' camp (in relation to ordinary > indexing of elements), and one in the '0 is not an ordinal, but a > point of origin,' camp (in relation to splitting). :ducks. Python's firmly in the "always half-open" field (pioneered in print, to the best of my knowledge, in A. Koenig's "C Traps and Pitfalls", and -- no doubt partly thanks to Koenig's influence -- pervasive in the C++ standard library too). Not sure where _splitting_ enters the picture -- you mean, e.g., 'a few words'.split()? What's THAT gotta do with intervals, or slices? Alex From mpeuser at web.de Sun Aug 17 10:18:22 2003 From: mpeuser at web.de (Michael Peuser) Date: Sun, 17 Aug 2003 16:18:22 +0200 Subject: RuntimeError: maximum recursion limit exceeded ?? References: Message-ID: "Bill Loren" schrieb im Newsbeitrag news:mailman.1061127755.14803.python-list at python.org... > Hi ppl, > > Trying to substitute some html tags within a big html file using RE ended up > with the "RuntimeError: maximum recursion limit exceeded" message. > Any idea why that might happen and how should one cope with it ? > > thx > ~B > > (btw I'm trying to take off several
s, i.e. substiture them with the > empty string '') " sys.getrecursionlimit() Return the current value of the recursion limit, the maximum depth of the Python interpreter stack. This limit prevents infinite recursion from causing an overflow of the C stack and crashing Python. It can be set by setrecursionlimit(). " You probably encountered some situation where one of youre routines went wild. It is not probable that you can reach this limit by something like HTML tag nesting... Kindly Michael P From jjl at pobox.com Thu Aug 14 08:05:21 2003 From: jjl at pobox.com (John J. Lee) Date: 14 Aug 2003 13:05:21 +0100 Subject: ClientCookie bug References: Message-ID: <87fzk4sav2.fsf@pobox.com> Syver Enstad writes: > cartermark46 at ukmail.com (Mark Carter) writes: > > > I am using Windows 98, python 2.3, ClientCookie 0.4.3a. > > > > When I do: > > import ClientCookie > > import os > > c = ClientCookie.MSIECookieJar(delayload=1) > > c.load_from_registry() > > > > I get the response: [...] > > KeyError: 'USERNAME' > > > > Basically, it doesn't like USERNAME as an environment variable. > > I suspect this only works on "real" win32 (the NT family) operating > systems, which define USERNAME, and not hybrid dos/win32 systems like > the win9x family. Anybody know the best way to get the username without win32all installed? Mark: I don't have a win9x box, but try replacing that os.environ['USERNAME'] with getpass.getuser(). You'll need to stick an import getpass in there too, of course. Let me know if that works. The rest of the code should work OK on win9x. John From jgerard at fluid-studios.ca Wed Aug 27 13:14:02 2003 From: jgerard at fluid-studios.ca (JM) Date: 27 Aug 2003 10:14:02 -0700 Subject: Accessing members of Python class from C++ (Embedded Python)???? References: Message-ID: If anyone is interested in the solution: pDict=PyObject_GetAttrString(PyObject,"__dict__") will get the local symbol table (a dictionary) for the class. JG jgerard at fluid-studios.ca (JM) wrote in message news:... > Hello everyone, > > Does anybody know about, have documentation on, or have any code > samples on how to access class members from a python class in C++. > > Say I have a simple python script: > > --------------------------- > class Animal: > NumLegs = 5 > Size = 4.5 > --------------------------- > > How exactly do you access these members from C++. I know how to get > the member if I know its name, ie. > > pkObject = PyDict_GetItemString(pkDict, "Animal"); > int uiNumLegs = PyInt_AsLong(PyObject_GetAttrString(pkObject,"NumLegs")); > > But how do you iterate through all the class members and print their > names and values? This is easy to do for basic variables, but I can't > seem to do it for class variables. > > Any help would be much apprecited. This is driving me nuts. > > JG From fredrik at pythonware.com Thu Aug 7 14:01:00 2003 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 7 Aug 2003 20:01:00 +0200 Subject: Is there some Python + IDE/RAD for real speed development??? References: <96fda9ac.0308060611.56dfca7e@posting.google.com> <25a9ea3e.0308061055.1cc2b2dd@posting.google.com> Message-ID: Michael Peuser wrote: > Fredrik Lundh's WCK (aka Tk 3000), which is in some pre-alpha > state however..... beta 4, actually: http://effbot.org/zone/wck.htm (docs+articles) http://effbot.org/downloads#tkinter3000 (code) From simonb at webone.com.au Mon Aug 18 03:37:45 2003 From: simonb at webone.com.au (Simon Burton) Date: Mon, 18 Aug 2003 17:37:45 +1000 Subject: overriding a tuple's __init__ Message-ID: Python 2.2.2 (#2, Nov 24 2002, 11:41:06) [GCC 3.2 20020903 (Red Hat Linux 8.0 3.2-7)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> class pair(tuple): ... def __init__(self,a,b): ... tuple.__init__(self, (a,b) ) ... >>> a=pair(1,2) Traceback (most recent call last): File "", line 1, in ? TypeError: tuple() takes at most 1 argument (2 given) >>> What gives? (yes it works with a list, but i need immutable/hashable) Simon Burton. From peter at engcorp.com Thu Aug 14 12:18:46 2003 From: peter at engcorp.com (Peter Hansen) Date: Thu, 14 Aug 2003 12:18:46 -0400 Subject: 3 new slogans References: <3f3b9cfe@news.swissonline.ch> Message-ID: <3F3BB666.9B9C78D7@engcorp.com> Sean Ross wrote: > > Python. Fat Free Programming Please use a hyphen in the right place, or we'll all be overweight and unpaid! "Fat-free Programming" -Peter From calfdog at yahoo.com Mon Aug 4 14:18:06 2003 From: calfdog at yahoo.com (calfdog at yahoo.com) Date: 4 Aug 2003 11:18:06 -0700 Subject: HTML DOM parser? References: <7x7k5y5wfh.fsf_-_@ruckus.brouhaha.com> <4de76ee2.0308011420.14f309f8@posting.google.com> <7x4r10oc8l.fsf@ruckus.brouhaha.com> <87el04yyhf.fsf@pobox.com> Message-ID: jjl at pobox.com (John J. Lee) wrote in message news:<87el04yyhf.fsf at pobox.com>... > Paul Rubin writes: > > > calfdog at yahoo.com writes: > > > Here is a quick example of using automation with IE > > > # This is a sample of automating IE using Python. > > > > Thanks, I should have said I'm running under gnu/linux and I was > > hoping for a standalone solution (some of the ones suggested sound > > worth looking into). Even connecting up Python to Mozilla sounds > > awfully heavyweight. > > PyKDE is less hassle, I think. It's certainly heavyweight, though. > Probably more lightweight still is HttpUnit on Jython. I haven't used > either, but I have compiled PyKDE recently, and didn't run into > problems (but if you're unlucky, you may have to compile Qt, KDE, sip > and PyQt first!). > > I seem to have got a basic JavaScript wrapper working now (I'm using > libjs from Mozilla's standalone spidermonkey distribution), bound 4DOM > to it, and extracted & executed the script from a web page. Quite a > lot more to do, though (browser-like interface of some sort, > javascript: scheme URLs, implement window object, wiring up event > attributes to the JS interpreter, getting the DOM actually working > propertly, understanding what document.write does, trying to connect > the DOM to my Python HTML form and HTTP cookies interfaces...). > > Anybody happen to know where JavaScript's document.some_form is > documented? Official W3C DOM has document.forms, but real browser > DOMs apparently have forms directly on the document object. > > > John Try here: http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/dhtml_reference_entry.asp From __peter__ at web.de Sat Aug 23 10:02:45 2003 From: __peter__ at web.de (Peter Otten) Date: Sat, 23 Aug 2003 16:02:45 +0200 Subject: Class Variables (Python 2.2/2.3) References: <221d8dbe.0308230406.6d07cfdd@posting.google.com> Message-ID: srijit at yahoo.com wrote: > Hello Members, > I do not see any direct mention of class variables in new style > classes. Only class methods. Have I missed or is it trivial? If not, > how to define/implement class variables for new style classes? >From my practical point of view, there are no differences between old and new style classes in this respect: def printThem(): for t in t1, t2, t3: print t.name, "=", t.color print #the same goes for class Test(object): ... class Test: color = "blue" def __init__(self, name): self.name = name t1 = Test("t1") t2 = Test("t2") t3 = Test("t3") # class atttribute are accessed like instance attributes printThem() #blue, blue, blue # class attributes are shaded by instance attributes, # which makes them good default values t1.color = "red" printThem() #red, blue blue # class attributes are not copied on instantiation Test.color = "green" printThem() #red, green, green And now let the experts speak up on the subtler aspects :-) Peter From gerrit at nl.linux.org Wed Aug 6 15:27:44 2003 From: gerrit at nl.linux.org (Gerrit Holl) Date: Wed, 6 Aug 2003 21:27:44 +0200 Subject: Python's biggest compromises In-Reply-To: References: Message-ID: <20030806192744.GA4155@nl.linux.org> > > Python predates Java. > Yeah, snakes drink coffee too. Both for Python and Java is true that it is unclear when in emerged. Pythons have existed for a looooooooong time, so has Jawa. But only since Mankind has emerged they are called as such. I think Pythons were known earlier in the west. Do Pythons live on Jawa? I don't know... Are Pearls and Ruby's organic? I don't think so - which must mean that they are even older. C is definetely newer because it requires the alphabet. Pascal is even newer, he lived very recently in this context. Gerrit. -- 190. If a man does not maintain a child that he has adopted as a son and reared with his other children, then his adopted son may return to his father's house. -- 1780 BC, Hammurabi, Code of Law -- Asperger Syndroom - een persoonlijke benadering: http://people.nl.linux.org/~gerrit/ Het zijn tijden om je zelf met politiek te bemoeien: http://www.sp.nl/ From adalke at mindspring.com Mon Aug 18 15:15:12 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Mon, 18 Aug 2003 13:15:12 -0600 Subject: What's better about Ruby than Python? References: Message-ID: William Trenker: > c++ group:comp.lang.python from 1 Jan 2003 to today. 2,630 > > (for what it's worth) Relevant for the OP's thoughts. I also tried C#, but then wondered if google would have problems with non-text characters, and if not, if the search for C++ would be biased by int c = 0; ... c++; I also excluded 'basic' since it's too often used in other contexts. And I totally left out lisp and scheme. Now to confuse searches for the future: snobol, jovial, ada, rebol, smalltalk, dylan, occam, objective c, apl, J, K, and cobol. :) Andrew dalke at dalkescientific.com From max at alcyone.com Sat Aug 9 21:37:51 2003 From: max at alcyone.com (Erik Max Francis) Date: Sat, 09 Aug 2003 18:37:51 -0700 Subject: obj.__dict__ expected behavior or bug? References: Message-ID: <3F35A1EF.75EB169F@alcyone.com> Ed Young wrote: > What happened to c.a, c.b, and c.c when iterating thru > c.__dict__ ? > > It appears that __dict__ members are not instantiated > until they are changed. > > This precludes using __dict__ as the dictionary in > a formatted print statement. e.g. > > print "c.a=%(a)s, c.b=%(b)s, c.c=%(c)s" % c.__dict__ > > Is this a bug or expected behavior? Expected behavior. What you're missing is the general way that Python does attribute lookup. When c is an instance and you say c.x, Python looks in c's __dict__ for an 'x' entry, then it looks in c's class's __dict__ for an 'x' entry, then it looks (in a well-defined way) through c's class's base classes, if any, for an 'x' entry in their __dict__ members. When you defined class C: a = ... b = ... and so on, these are all _class_ attributes. When you instantiate a C and then wrote self.a = ... in its methods, you instantiated _instance_ attributes on that instance. Class attributes are analogous to static members/fields in other languages: >>> class C: # class with two class attributes ... a = 1 ... b = 2 ... >>> c = C() >>> d = C() >>> c.a 1 >>> d.a 1 >>> c.a = 10 # change an instance attribute >>> c.a 10 >>> d.a 1 >>> C.b = 20 # change a class attribute >>> c.b 20 >>> d.b 20 >>> C.__dict__ {'a': 1, '__module__': '__main__', 'b': 20, '__doc__': None} >>> c.__dict__ {'a': 10} >>> d.__dict__ {} -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ Nobody's on nobody's side \__/ Florence, _Chess_ From fredrik at pythonware.com Tue Aug 19 13:26:54 2003 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 19 Aug 2003 19:26:54 +0200 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: <3F41208F.40021A68@engcorp.com> Message-ID: John Roth wrote: > The standard usenet definition of a troll is someone who posts on > a contentious (and usually off-topic) subject with the sole objective > of stiring up reactions. that's a very limited definition. I prefer this one: "An internet troll is someone who fishes for people's confidence and, once found, exploits it" ( from http://www.teamtechnology.co.uk/troll.htm ) From llothar at web.de Thu Aug 28 11:02:03 2003 From: llothar at web.de (Lothar Scholz) Date: 28 Aug 2003 08:02:03 -0700 Subject: My future Python IDE article References: <3f4ca68c$0$4190$afc38c87@news.optusnet.com.au> <3f4d3e12$0$4190$afc38c87@news.optusnet.com.au> Message-ID: <6ee58e07.0308280702.6f2e37a5@posting.google.com> "Mike Thompson" wrote in message news:<3f4d3e12$0$4190$afc38c87 at news.optusnet.com.au>... > > That's not my experience. I've found Boa both stable, functional and well > priced. > One fatal bug is that it doesn't kill applications that you started in the debugger or simply run as a script - at least under Win2000/XP. So after 30 minutes you end up with a maschine full of processes and with the kill only one task at a time MS-Taskmanager it is faster to reboot the maschine. And the complete IDE is not very easy to use, the debugger seems also not very stable. From mis6 at pitt.edu Thu Aug 28 03:31:39 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 28 Aug 2003 00:31:39 -0700 Subject: Celebrity advice (was: Advice to a Junior in High School?) References: Message-ID: <2259b0e2.0308272331.55028ae5@posting.google.com> Jacek Generowicz wrote in message news:... > > One learns so much more from reading opinions opposed to one's own, > than from reading ones with which you agree. I thought it was worth repeating. Michele Simionato, Ph. D. MicheleSimionato at libero.it http://www.phyast.pitt.edu/~micheles --- Currently looking for a job --- From SBrunning at trisystems.co.uk Thu Aug 28 12:32:18 2003 From: SBrunning at trisystems.co.uk (Simon Brunning) Date: Thu, 28 Aug 2003 17:32:18 +0100 Subject: Python quote of the week? Message-ID: <31575A892FF6D1118F5800600846864D01200BE1@intrepid> "All that rigid type safety and data hiding is like wearing army boots on the beach: nothing can bite your toes, but golly don't it feel good to just toss 'em and run barefoot." David Pinn, . Cheers, Simon Brunning --LongSig ----------------------------------------------------------------------- The information in this email is confidential and may be legally privileged. It is intended solely for the addressee. Access to this email by anyone else is unauthorised. If you are not the intended recipient, any disclosure, copying, distribution, or any action taken or omitted to be taken in reliance on it, is prohibited and may be unlawful. TriSystems Ltd. cannot accept liability for statements made which are clearly the senders own. From claird at lairds.com Sun Aug 24 11:09:28 2003 From: claird at lairds.com (Cameron Laird) Date: Sun, 24 Aug 2003 15:09:28 -0000 Subject: how fast is Python? References: <3F44DFEB.60AB6492@engcorp.com> Message-ID: In article <3F44DFEB.60AB6492 at engcorp.com>, Peter Hansen wrote: >dan wrote: >> >> However, there are definitely cases where a lot of code would need to >> be optimized, and so I ask the question: How fast is Python, compared >> to say a typical optimizing C/C++ compiler? > >C is roughly 10 to 100 times faster than Python, though of course it's >easy to find cases outside of this range, on either side. > >I use 30 as a general overall rule of thumb, in the exceptionally >few cases where it seems relevant how much faster C would be. > >And in those very few cases, so far, I have consistently concluded >I'm happy enough with the speed of Python given that the speed of >*development* in Python is easily 5 to 10 times faster than the >speed of development in C. (And again, it's easy to find cases >outside of this range, on either side...) . . . I just think Peter's wise counsel bears repeating. Andrew gave the same quantities, incidentally. Myself, I use ten "as a general over-all rule of thumb", and expect generally to be in the three-to-thirty range. I know other programmers whose Python work consistently runs about one-one-hundredth as fast as the C equivalent. As near as I can tell, that reflects on the kinds of programming we do (how numeric, and so on), rather than the quality of our coding. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://phaseit.net/claird/home.html From carroll at tjc.com Thu Aug 7 00:36:51 2003 From: carroll at tjc.com (carroll at tjc.com) Date: Wed, 06 Aug 2003 21:36:51 -0700 Subject: wxPython and Chinese characters in Unicode? References: <3ct0jvgcln2df5dv9g67c7kubah07adopa@4ax.com> Message-ID: On Wed, 06 Aug 2003 01:22:07 -0700, Cliff Wells wrote: >You will get better responses to wxPython-related questions on the >wxPython mailing list: > >http://www.wxpython.org/maillist.php Thanks! From bgailer at alum.rpi.edu Fri Aug 1 11:58:45 2003 From: bgailer at alum.rpi.edu (Bob Gailer) Date: Fri, 01 Aug 2003 09:58:45 -0600 Subject: Detect PythonWin? In-Reply-To: References: <3f29fe44.104328@news.muenster.de> Message-ID: <5.2.1.1.0.20030801095608.02cb5848@66.28.54.253> >how can my script know it its running from inside PythonWin? I addressed this a few months ago: import sys if len(sys.modules) > 200: # running under PythonWin This is because PythonWin loads a lot of modules beyond what native Python does. (IDLE also loads some, but a lot less that PyrthonWin). Bob Gailer bgailer at alum.rpi.edu 303 442 2625 -------------- next part -------------- --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.500 / Virus Database: 298 - Release Date: 7/10/2003 From deets_noospaam at web.de Fri Aug 1 13:59:47 2003 From: deets_noospaam at web.de (Diez B. Roggisch) Date: Fri, 01 Aug 2003 19:59:47 +0200 Subject: Python vs. Perl vs. PHP? References: <7b454334.0307281002.41dae81b@posting.google.com> <87oezebjh8.fsf@flibuste.net> <87smolomgx.fsf@keyser.soze.com> Message-ID: Hi, > Compared to Apache 2.0 with PHP/Zend & Accelerator? I honestl don't think > so. When PHP is compiled to native code it is as fast as Java or C. There is no such thing like a native compiler for PHP. If you're speaking of the ZEND compiler - AFAIK that one just does some parse tree caching. As I mentioned before, a friend of mine works on a php->C (and then native, of course) compiler. One thing he has to do is to recreate all the library bindings. These are really slow implemented in PHP - has something to do with the parameter-passing. And thats something the ZEND compiler doesn't speed up. Another thing is PHP session mechanism - the simply persist every session to the filesystem. Sure, there are FS-Caches, but neverless thats not as fast as imaginable... And what do you mean by "As fast as Java or C"? There is a huge difference in speed between these two. Not that I think that speed matters much here - usually, the bandwidth, process creation time and database queries are the bottlenecks. Regards, Diez From hemanth_sethuram at yahoo.com Thu Aug 21 05:06:49 2003 From: hemanth_sethuram at yahoo.com (Hemanth P.S.) Date: 21 Aug 2003 02:06:49 -0700 Subject: When is ActivePython 2.3 available? Message-ID: <9be5e130.0308210106.34aaa601@posting.google.com> Any idea when the ActivePython distribution for 2.3 will be available? --Hemanth From timothy.williams at nvl.army.mil Mon Aug 4 15:02:04 2003 From: timothy.williams at nvl.army.mil (Tim Williams) Date: 4 Aug 2003 12:02:04 -0700 Subject: Python2.3 tkFileDialog.askopenfilename returns tuple on Cancel Message-ID: I just installed Python 2.3 on my Redhat system. When I tried to run one of my programs that use tkFileDialog.askopenfilename(), I got an error because it returns a tuple instead of a null string when I select Cancel. Python 2.2: Python 2.2.2 (#3, Jan 21 2003, 08:39:06) [GCC 2.95.3 20010315 (release)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import tkFileDialog >>> f=tkFileDialog.askopenfilename() >>> print f >>> f '' >>> type(f) Python 2.3: Python 2.3 (#1, Aug 4 2003, 10:43:11) [GCC 3.2 20020903 (Red Hat Linux 8.0 3.2-7)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import tkFileDialog >>> f=tkFileDialog.askopenfilename() >>> f () >>> type(f) Both versions return a string when I select an actual file. Sometimes I want to click 'Cancel' when I want to bring up my GUI anyway and select the file later. I got around this by just putting in an if not filename: filename='.' after my call to askopenfilename(). Is this a bug or a feature? Thanks. From gafStopSpamData at ziplink.stopallspam.net Mon Aug 18 15:13:04 2003 From: gafStopSpamData at ziplink.stopallspam.net (Gary Feldman) Date: Mon, 18 Aug 2003 19:13:04 GMT Subject: Idle won't start when Python is installed in Program Files directory References: Message-ID: On 18 Aug 2003 13:19:52 -0400, aahz at pythoncraft.com (Aahz) wrote: >http://www.python.org/2.3/bugs.html Thanks for the pointer. (Interestingly, I got a little confused by following to the SourceForge bug pointers, because there's nothing on the bug report page that clearly indicates the project. I guess they don't expect people to get there by direct links.) Gary From pwatson at knightsbridge.com Thu Aug 21 17:31:10 2003 From: pwatson at knightsbridge.com (Paul Watson) Date: Thu, 21 Aug 2003 16:31:10 -0500 Subject: [OT] Why is it called string? References: <3f44ce77$0$556$b45e6eb0@senator-bedfellow.mit.edu> <3F44DBF2.1010403@draigBrady.com> Message-ID: <3f453a22$1_1@themost.net>

wrote in message news:3F44DBF2.1010403 at draigBrady.com... > Travis Whitton wrote: > >>"In computing, the word 'bit' is an abbreviation of what two other words?" > > > > Wow, I had no idea it was an abbreviation either. Luckily, dict had the answer > > waiting for me: > > > > From Jargon File (4.3.0, 30 APR 2001) [jargon]: > > > > bit n. [from the mainstream meaning and `Binary digIT'] > > > > It's nice to see the occasional thread on computing history rather than the > > endless stream of coding issues. > > I'm always surprised by the number of people > in computing that don't know this. > > bit is a contraction of "Binary digIT" > byte is a pun on the word bit (8 bits) > nibble is a pun on the word byte (4 bits) > > P?draig. My CS professor would insist that a byte is a collection of bits, and not necessarily eight. There are machines which do not have 8-bit addressable bytes. From pedro_rodriguez at club-internet.fr Sat Aug 16 12:26:48 2003 From: pedro_rodriguez at club-internet.fr (Pedro Rodriguez) Date: Sat, 16 Aug 2003 16:26:48 +0000 Subject: Python/Tkinter/tk crash [long] References: Message-ID: On Thu, 14 Aug 2003 09:10:22 +0000, Eric Brunel wrote: > Hi all, > > I was creating a Tkinter widget in the style of the reversed tabs below Excel > worksheets and I stepped in a serious problem: the code I made makes python > crash with a seg fault, bus error or X11 BadGC error on both Solaris (2.6 and > 2.7) and Linux (Mandrake 8.0); it doesn't crash on Windows. I tried to simplify > the script, but I couldn't reproduce the crash with a simpler code. So the code > below is somewhat long; sorry for that. > > To make it crash, just run the script and click on a tab. It usually crashes at > the first click, but you may have to play a bit with the tabs. I tried to run > Python through gdb to see where the crash happens, but it seems to be quite > random. Maybe a memory corruption? > > There's a simple workaround, but with drawbacks: at the beginning of the > __update method, if I do not destroy and re-create the Canvas, but simply empty > its contents, the script works. But it keeps the commands declared created at > the tcl level for the former bindings, so it silently eats up memory. > As far as I understand, the __changeTab method is called when an event occurs on the __tabsCanvas. But one of the first actions of the __update method (which is called by __changeTab) is to destroy the __tabsCanvas object. So DURING the callback call you are destroying the object to which the callback is bound. I wonder if this is the cause of the blow up at the return of the callback (it may depend on how the memory is reallocated on different systems). Just my 0.02 euro guess -- Pedro From fawcett at teksavvy.com Thu Aug 21 00:13:55 2003 From: fawcett at teksavvy.com (Graham Fawcett) Date: Thu, 21 Aug 2003 00:13:55 -0400 Subject: What's TOTALLY COMPELLING about Ruby over Python? In-Reply-To: <240b1020.0308201722.d1b991c@posting.google.com> References: <240b1020.0308201722.d1b991c@posting.google.com> Message-ID: <3F444703.2000801@teksavvy.com> Jeffrey P Shell wrote: >"Brandon J. Van Every" wrote in message news:... > > >>I'm realizing I didn't frame my question well. >> >>What's ***TOTALLY COMPELLING*** about Ruby over Python? What makes you jump >>up in your chair and scream "Wow! Ruby has *that*? That is SO FRICKIN' >>COOL!!! ***MAN*** that would save me a buttload of work and make my life >>sooooo much easier!" >> >>As opposed to minor differences of this feature here, that feature there. >>Variations on style are of no interest to me. I'm coming at this from a C++ >>background where even C# looks like an improvement. ;-) From 10,000 miles >>up, is there anything about Ruby that's a "big deal" compared to Python? >> >>One person mentioned Japanese documentation. I'm sure that's Totally Kewl >>to the Japanese.... >> >> > >Negative points earned by using 'frickin' and 'kewl'. > >But with an earnest answer to your question - I started evaluating >Ruby about two and a half years ago. For me at the time, the "big >deals" in comparison to Python were: > An excellent answer and a great read, Jeffrey. Thanks. -- Graham From cedmunds at spamless.rochester.rr.com Sat Aug 23 19:27:19 2003 From: cedmunds at spamless.rochester.rr.com (Cy Edmunds) Date: Sat, 23 Aug 2003 23:27:19 GMT Subject: python gripes survey References: Message-ID: "Bertrand Geston" wrote in message news:bi8nrd$1fnkl$1 at sinclair.be.wanadoo.com... > "Ryan Lowe" a ?crit dans le message news: > PUL1b.166506$_R5.62801118 at news4.srv.hcvlny.cv.net... > > python is a big improvement on most languages that came before it, but no > > language is perfect. id like to make a list of some of the aspects people > > find most annoying, regardless of their feasibility of implementation. for > > instance, i discussed putting if clauses in for loops, and i noticed > another > > thread about allowing {} and [] to be added and subtracted. if its > something > > from another language (especially an obscure one), please explain how it > > works in case people like myself dont know the language. > > > > thanks, > > ryan > > > > > You could start reading this: > http://zephyrfalcon.org/labs/python_pitfalls.html > http://www.amk.ca/python/writing/warts.html > http://www.ferg.org/projects/python_gotchas.htmlv > > bg Thanks for the links -- nice stuff there! -- Cy http://home.rochester.rr.com/cyhome/ From cartermark46 at ukmail.com Sat Aug 16 05:31:14 2003 From: cartermark46 at ukmail.com (Mark Carter) Date: 16 Aug 2003 02:31:14 -0700 Subject: ClientCookie bug (followup) References: <87fzk4sav2.fsf@pobox.com> <87znibzrnx.fsf@pobox.com> Message-ID: > I'll try it on a win 98 machine, and report back the results asap. --- USERNAME I promised that I would try getuser() on a win 98 machine. Alas, typing: import getpass print getpass.getuser() produces: ImportError: No module named pwd So, it's the same problem as occurs on win95 (unsuprisingly) --- DELAYLOAD John: Why without the delayload argument? My response: The following code: import ClientCookie c = ClientCookie.MSIECookieJar(delayload=1) c.load_cookie_data("hemscott-cookie.bin") import urllib2 url = 'http://businessplus.hemscott.net/corp/crp03733.htm' request = urllib2.Request(url) response = urllib2.urlopen(request) request2 = urllib2.Request(url) c.add_cookie_header(request2) response2 = urllib2.urlopen(request2) print response2.geturl() print response2.info() # headers for line in response2.readlines(): # body print line produces the error: Traceback (most recent call last): File "C:\My Documents\markc\ClientCookie\clp04.py", line 9, in ? c.add_cookie_header(request2) File "C:\PYTHON23\Lib\site-packages\ClientCookie\_ClientCookie.py", line 1170, in add_cookie_header cookies.extend(self._get_cookies_for_domain( File "C:\PYTHON23\Lib\site-packages\ClientCookie\_ClientCookie.py", line 1050, in _get_cookies_for_domain return self._cookies_for_domain(domain, request, unverifiable) File "C:\PYTHON23\lib\site-packages\ClientCookie\_MSIECookieJar.py", line 112, in _cookies_for_domain if self.delayload and cookies["//+delayload"] is not None: KeyError: '//+delayload' whereas running it without delayload=1 causes it to run successfully. From pu Sat Aug 16 19:17:42 2003 From: pu (Patrick Useldinger) Date: Sun, 17 Aug 2003 01:17:42 +0200 Subject: asynchat question In-Reply-To: <3f3ebaa8_2@news.vo.lu> References: <3f3ebaa8_2@news.vo.lu> Message-ID: <3f3ebb39_2@news.vo.lu> Sorry, my mistake. The behaviour is actually that for the client, handle_connect() is never called, so the message is never send. Why? -- Real e-mail address is 'cHVAdm8ubHU=\n'.decode('base64') Visit my Homepage at http://www.homepages.lu/pu/ From tzot at sil-tec.gr Fri Aug 22 02:58:28 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Fri, 22 Aug 2003 09:58:28 +0300 Subject: Misleading description of [i:j:k] slicing? References: <7h33cfv2az7.fsf@pc150.maths.bris.ac.uk> <8t0akv0ov6k2peg5b92humla84mnhcovu2@4ax.com> Message-ID: On Thu, 21 Aug 2003 18:56:38 +0100, rumours say that Raoul Gough might have written: >> Basically, it's 0 <= n < abs(i-j)//k, right? > >I didn't know about // (silly me) but it looks like a good way to >go. Your alternative formulation still doesn't give the right >behaviour for negative values of k. e.g. Yes indeed, I hadn't negative values in mind. -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From duncan at NOSPAMrcp.co.uk Tue Aug 19 04:17:57 2003 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Tue, 19 Aug 2003 08:17:57 +0000 (UTC) Subject: union in Python References: Message-ID: bokr at oz.net (Bengt Richter) wrote in news:bhrsuj$mdv$0 at 216.39.172.122: > But I don't see any reason why the performances couldn't be made to > match. For searching short strings there probably isn't any advantage to using Boyer-Moore, and for short search strings the advantage is probably quite small. I think you would need to spend some time working out just where the breakpoints are that make it worth switching from a plain search to one that skips ahead. The regular expression search may still win, since regular expressions, even if not precompiled, are cached. That means that if you perform the regex search millions of times, the setup cost is only incurred once. String searches don't have this advantage, and it seems unlikely to be worth the effort of caching arguments passed to string.find! -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From clifford.wells at comcast.net Wed Aug 20 00:54:22 2003 From: clifford.wells at comcast.net (Cliff Wells) Date: Tue, 19 Aug 2003 21:54:22 -0700 Subject: Import error !! In-Reply-To: <200308192221.14129.skchim0@engr.uky.edu> References: <200308192221.14129.skchim0@engr.uky.edu> Message-ID: <1061355262.6604.24.camel@devilbox.homelinux.net> On Tue, 2003-08-19 at 19:21, satish k.chimakurthi wrote: > # /usr/lib/python1.5/exceptions.pyc matches /usr/lib/python1.5/exceptions.py > import exceptions # precompiled from /usr/lib/python1.5/exceptions.pyc > # /usr/lib/python2.2/site.pyc has bad magic > 'import site' failed; traceback: > File "/usr/lib/python2.2/site.py", line 64 > dir = os.path.abspath(os.path.join(*paths)) Are you running Python 1.5.2 or 2.2? It sounds as if your Python installation is messed up. Regards, Cliff -- With your cold flesh, my cold love, hissing not kissing -Siouxsie and the Banshees From merkerk at deadspam.com Tue Aug 19 09:36:54 2003 From: merkerk at deadspam.com (Peter van Merkerk) Date: Tue, 19 Aug 2003 15:36:54 +0200 Subject: Brandon's abrasive style (was Re: What's better about Rubythan Python?) References: <38ec68a6.0308172319.431a4fde@posting.google.com> Message-ID: > > - GUI and tools support can end up being more important than language > > niceties. > > Absolutely. This is one of the main reasons languages like Ruby and > Haskell aren't in my toolkit. wxRuby appears to be in the pre-alpha > stages and wxHaskell doesn't exist at all. http://wxhaskell.sourceforge.net From skip at pobox.com Mon Aug 25 10:08:57 2003 From: skip at pobox.com (Skip Montanaro) Date: Mon, 25 Aug 2003 09:08:57 -0500 Subject: Hosting service with Python support In-Reply-To: <3f489493$0$200$fa0fcedb@lovejoy.zen.co.uk> References: <3f489493$0$200$fa0fcedb@lovejoy.zen.co.uk> Message-ID: <16202.6265.816098.163766@montanaro.dyndns.org> john> I have just found out the my hosting service includes Python john> support. Unfortunately, they make no mention of this on their web john> site. There are too few hosting companies that offer Python john> support so I would like to share this one with you. You can share it most effectively by adding a row to the table at http://www.python.org/cgi-bin/moinmoin/PythonHosting if one doesn't already exist. Skip From mpeuser at web.de Fri Aug 15 03:31:14 2003 From: mpeuser at web.de (Michael Peuser) Date: Fri, 15 Aug 2003 09:31:14 +0200 Subject: How remove Tcl/Tk fom py2exe distribution? Message-ID: Hi, I should like to make a distribution (using Tkinter), with standard DLLs removed. pythonXX.dll is no problem. tcl und tk, which make the mass of mega bytes, cannot be removed because _tkinter.pyd seems to expect them in the same directory (Question 1) Is there a configration or path setting in py2exe/distutils I have overlooked? O.k. In fact I do not want to have _tkinter.dll either because it belongs to standard distribution The command line option --exclude Tkinter however leads to an error message when running the exe - this could have been expected however ;-) Now I changed import Tkinter to Tkinter= __import__("Tkinter") This worked fine sofar as --exclude Tkinter was no longer needed to prevent py2exe from copying tcl/tk However "Tkinter" was not found by imputils now... (Question 2) What did I miss?? Kindly Michael P From mwh at python.net Wed Aug 27 05:26:35 2003 From: mwh at python.net (Michael Hudson) Date: Wed, 27 Aug 2003 09:26:35 GMT Subject: Replacement for rexec/Bastion? References: Message-ID: <7h3znhvcv35.fsf@pc150.maths.bris.ac.uk> "Colin Coghill (SFive)" writes: > >> Is Python (preferably CPython 2.3) still able to "sandbox" bits of code > >> under an application provided API safely? > > > > replacement available or even on the horizon. Zope's RestrictedPython > > is the closest thing there is... a quick summary of its approach was > > posted to python-dev today: > > http://mail.python.org/pipermail/python-dev/2003-August/037791.html > > > Thanks, that looks interesting. I had seen mention of it but hadn't > realised it wasn't just rexec behind the scenes. Umm... it's not. Unless I misunterstand you and/or the referenced mail to python-dev. Cheers, mwh -- Problem: Jobs print normally but then burst into flame, plastic surfaces of printer are soft to touch. Solution: Printer is on fire. Turn off flamethrower. -- Internet Oracularity #1306-03 From aahz at pythoncraft.com Wed Aug 6 20:10:20 2003 From: aahz at pythoncraft.com (Aahz) Date: 6 Aug 2003 20:10:20 -0400 Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> Message-ID: In article , Syver Enstad wrote: >aahz at pythoncraft.com (Aahz) writes: >> >> (Yes, there are issues with Python on SMP machines, but to call >> Python's built-in threading "non-existent SMP scalability" is either >> a lie or revelatory of near-complete ignorance. That doesn't even >> count the various IPC mechanisms.) > >It's an interesting subject though. How does python threading on SMP >machines compare with f.ex. Java and C++. I know that at least the >MSVC compiler has a GIL like problem with heap access (new, malloc, >delete, free), which is guarded with a global lock. Sure, but that's not where a C++ application usually spends its time. >Would migrating the global data for a thread to some sort of thread >local storage help Python SMP performance? If Java has better >threading performance than Python how have they solved the interpreter >state problem. Java is interpreted isn't it? Well, that's a good question. *Does* Java have better threading performance than Python? If it does, to what extent is that performance bought at the cost of complexity for the programmer? Keep in mind that the GIL exists not because of issues with thread-local storage but because every Python object is global and can have bindings to it in any -- or every -- thread. Python uses objects *everywhere*; the GC uses Python objects, stack frames are Python objects, modules are Python objects. To create "thread-local" storage as you suggest would require a wholesale revision of Python's object model that would make it something other than what Python is today. Based on recent discussions about restricted execution, I suspect that security would be much more likely to drive such changes; if that happens, perhaps revisiting the way GIL works might happen with it. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From jacek.generowicz at cern.ch Fri Aug 22 10:12:05 2003 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 22 Aug 2003 16:12:05 +0200 Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> <6dj2kv8ugkieehs7guh786cl40o5lj6mcs@4ax.com> Message-ID: Hans Nowak writes: > Jacek Generowicz wrote: > > [re-binding __builtins__ considered harmful] > > I see your point. The obvious answer would be "so don't do that, > then". Of course, the same answer would apply to writing abusive > macros. Exactly. > Python usually strikes a good balance between being permissive and > restrictive. In your opinion. The opinions of others, as to where a "good balance" lies, will be different. And that's just fine. That's why we have different languages. I happen to agree that Python strikes a good balance. I also think that Common Lisp strikes a good balance. The position of "good balance" is a function of the language's audeince. > > Just because a stupid or malicious programmer could do "bad things" is > > not a reason to reduce a language's power. (You end up with Java.) > > You are right, but one could wonder if the drawbacks don't outweight > the benefits. Python is already powerful as it is (compared to > languages other than Lisp ;-). I'm not sure if powerful macros would > do much good. Well, with an interactive language[*] you can easily get two types of programmers: the providers, and the users. A good macro facility allows the provider types to create very useful abstractions for the user types. The user types can use those abstractions without having the faintest clue that they are built using macros, and can happily program in the language without ever writing one of their own. (A bit like metaclasses.) Just because there are macros or metaclasses in a language, does not mean that everyone needs to know about them, while everyone can benefit from them. [*] I guess that this is not exclusive to interactive languages, but I suspect it's more marked. But, wrt macros in Python, I don't really see what Python macros would look like. Lisp code is represented in a fundamental, hierarchical, easily transformable built-in data type. This ain't true for Python. Sometimes I think "if Python had Lisp-like macros, what I am trying to achieve right now would be so much easier". This doesn't mean that I would necessarily advocate the inclusion of macros in Python. What I object to, is the suggestion (which has been made repeatedly around the thread) that macros are evil and should be avoided, and that macros are responsible for the fragmentation/death of Lisp. Macros are great. If a good, Pythonic macro system could be invented, I am sure that it could be put to great use, and that it would not engender the death of Python. I am not sure that such a system can be invented. I do not suggest that such a system _should_ be added to Python. From newsgroups at jhrothjr.com Fri Aug 29 21:58:12 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Fri, 29 Aug 2003 21:58:12 -0400 Subject: My script is taking 12 hours+ any suggestions? References: <3f4ff9f8$0$23588$5a62ac22@freenews.iinet.net.au> Message-ID: Your script isn't indented properly in Outlook Express, making it very difficult to read John Roth "Ideasman" wrote in message news:3f4ff9f8$0$23588$5a62ac22 at freenews.iinet.net.au... > Hi I have a made a script that process normals for a flat shaded 3D mesh's. > It compares every vert with every other vert to look for verts that can > share normals and It takes ages. > > I'm not asking anyone to rewrite the script- just have a look for any > stupid errors that might be sucking up time. > > > > > > > > > #!/usr/bin/python > ############## > # AUTOSMOOTH # > ############## > import sys > import os > import string > import math > > # Used to write floats that dont' contain letters/ > def saneFloat(float): > #return '%(float)b' % vars() # 6 fp as house.hqx > return '%f' % float # 10 fp > > > > #Open file from the command line, turn into a list and close it. > file = open(sys.argv[-1], 'r') > fileLineList = file.readlines() > file.close > > # Remember the number of lines for progress indication. > fileLen = len(fileLineList) > > # Autosmooth value. Higher will autosmooth larger angles. > maxDiff = 1.66 > > # Loop through the lines. > lineIndex = 0 > while lineIndex < len(fileLineList): > > #Find Geom TAG.. > if str(fileLineList[lineIndex])[0:8] == 'Geometry': > lineIndex += 1 > # break if looping beyong the file, > if lineIndex > len(fileLineList): > break > > # Here we remember lines that have been processed. > # it needs to be reset for each geom object. > listOfDoneLines = [] > > # Start a new loop that checks the current vert against all the others > newLoopindex = lineIndex > while len(string.split(fileLineList[newLoopindex])) == 12: > print '\n', fileLen, newLoopindex, > > #vertexnum = newLoopindex - lineIndex > > # Compare the 2 lines > newCompareLoopindex = newLoopindex + 1 # compare the current vert to > this new one. > thisPassDoneLines = [] # act apon this after comparing with each vert > thisPassDoneNormals = [] > while len(string.split(fileLineList[newCompareLoopindex])) == 12: > > # Speed up the process by using 2 if's, splitting the string only if > it has not been evaluated already. > if newCompareLoopindex not in listOfDoneLines: > comp1 = string.split(fileLineList[newLoopindex]) > comp2 = string.split(fileLineList[newCompareLoopindex]) > > if [comp1[0], comp1[1], comp1[2]] == [comp2[0], comp2[1], comp2[2]]: > > if newLoopindex not in listOfDoneLines: # Only needs to be added once > listOfDoneLines.append(newLoopindex) > > if newLoopindex not in thisPassDoneLines: # Only needs to be added > once > thisPassDoneLines.append(newLoopindex) > thisPassDoneNormals.append([eval(comp1[8]), eval(comp1[9]), > eval(comp1[10])]) > > listOfDoneLines.append(newCompareLoopindex) > thisPassDoneLines.append(newCompareLoopindex) > thisPassDoneNormals.append([eval(comp2[8]), eval(comp2[9]), > eval(comp2[10])]) > print '#', > > newCompareLoopindex += 1 > > > > if len(thisPassDoneLines) > 1: # Ok We have some verts to smooth. > > > # This loops through all verts and assigns each a new normal. > for tempLineIndex in thisPassDoneLines: > > tempSplitLine = string.split(fileLineList[tempLineIndex]) > > # We add to these for every vert that is similar, then devide them > to get an average. > NormX = 0 > NormY = 0 > NormZ = 0 > > # A list of vert line indicies that we will create to store verts > that have normals close to ours. > thisVertFrendsCount = 0 > > # This compares the current vert with all the others, if they are > close then add to vertFrends. > for tNorm in thisPassDoneNormals: # tNorm is just used for one of > the normals in the thisPassDoneNormals > > if abs(eval(tempSplitLine[8]) - tNorm[0]) + > abs(eval(tempSplitLine[9]) - tNorm[1]) + abs(eval(tempSplitLine[10]) > -tNorm[2])< maxDiff: > > #maxDiff > NormX += tNorm[0] > NormY += tNorm[1] > NormZ += tNorm[2] > > thisVertFrendsCount += 1 > > > #Now devide the normals by the number of frends. > NormX /= thisVertFrendsCount > NormY /= thisVertFrendsCount > NormZ /= thisVertFrendsCount > > # make unit length vector. > d = NormX*NormX + NormY*NormY + NormZ*NormZ > if d>0: > d = math.sqrt(d) > NormX/=d; NormY/=d; NormZ/=d > > > # Write the normal to the current line > tempSplitLine[8] = str(saneFloat(NormX)) > tempSplitLine[9] = str(saneFloat(NormY)) > tempSplitLine[10] = str(saneFloat(NormZ)) > > fileLineList[tempLineIndex] = string.join(tempSplitLine) + '\n' > > > > newLoopindex += 1 > > lineIndex += 1 > > > # Writing to file > # file to write > file = open(sys.argv[-1], 'w') > file.writelines(fileLineList) > file.close() > From cnetzer at sonic.net Wed Aug 13 03:50:08 2003 From: cnetzer at sonic.net (Chad Netzer) Date: Wed, 13 Aug 2003 00:50:08 -0700 Subject: Python vs. C# In-Reply-To: References: <2259b0e2.0308100616.55b651ca@posting.google.com> <3f36af20@shknews01> <3f3959e3_1@news.vo.lu> Message-ID: <1060761008.18367.126.camel@adsl-209.204.179.133.sonic.net> On Wed, 2003-08-13 at 00:00, Doug Tolton wrote: > I honestly don't think "Vain" Every would ever be able to understand > Lisp, even if he read ten books. Battle not with trolls, lest ye become a troll. -- Chad Netzer From tzot at sil-tec.gr Sat Aug 23 16:22:44 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Sat, 23 Aug 2003 23:22:44 +0300 Subject: Modifying the {} and [] tokens References: <04cekv0s6ghjtuhl5j2gph7ltobdb5rsam@4ax.com> <62rekv0k4ucgrh46lkp27klq13pq8ppp5p@4ax.com> <1h3fkvg8mkeq69a8hriojugqfcp75hafjj@4ax.com> Message-ID: <70jfkvg6seukjah21m4skgvft3rbrahi5a@4ax.com> On Sat, 23 Aug 2003 19:22:02 GMT, rumours say that Geoff Howland might have written: >I dont intend to, I'm glad there was a misunderstanding and sorry I >misunderstood (hope thats parseable). No harm done, thank you for your reply :). I hoped it was only a matter of temporary irritation on your side, and I was thankfully correct; otherwise I wouldn't bother to reply, to be sincere... Cheers! -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From peter at engcorp.com Thu Aug 28 11:10:58 2003 From: peter at engcorp.com (Peter Hansen) Date: Thu, 28 Aug 2003 11:10:58 -0400 Subject: Binary data handling ? References: Message-ID: <3F4E1B82.E4F7AC6D@engcorp.com> Bill Loren wrote: > > Hello ppl, > > I'm having difficulties to accomplish some simple chores with binary data. > I'm having a string (?) which I received via an HTTP transactions which is a > binary file. > Problem is the webserver I'm communicating with injected a \x0D before every > \x0A, > and I need to remove those 0x0D characters from my buffer before saving it > to disk. This sounds wrong. I don't think a properly configured web server should be transmitting unencoded binary files with newline conversion. > any ideas ? > > I tried the following without any success: > string.replace("%c%c" % (13,10), "%c" % (10)) > string.replace("\x0d\x0a", "\0x0a") Strings are immutable. Are you expecting the above to change the string (which doesn't happen) or to return a new string with the changes made? Assign the result of the replace() call to a new variable and it should work. (Except in the latter example you should have \x0a, not \0x0a.) -Peter From achalk at XXXmagnacartasoftware.com Sun Aug 3 15:50:28 2003 From: achalk at XXXmagnacartasoftware.com (Andrew Chalk) Date: Sun, 03 Aug 2003 19:50:28 GMT Subject: 'print' in a CGI app. References: Message-ID: <8IdXa.1333$Vo7.1015369749@newssvr12.news.prodigy.com> Thanks to you, Timo, Dennis and Irmen. The
trick was what I was using but I thought I must be missing something. Regards "Timo Virkkala" wrote in message news:TVcXa.4487$HC4.642 at reader1.news.jippii.net... > Andrew Chalk wrote: > > In a Python 2.2 app. running under CGI the statements > > > > print "Hello\n" > > print "World" > > > > print both words on the same line in IE6. How do I print the second one on a > > new line (i.e. respect the \n in the first statement). > > How about (untested): > > print "Hello
\n" > print "World" > > ...since, AFAIK, it should be HTML that CGI's output...? > > -- > Timo Virkkala | wt at nic.fi > > "In the battle between you and the world, bet on the world." > From nobody at nowhere.com Mon Aug 18 19:32:49 2003 From: nobody at nowhere.com (Grumfish) Date: Mon, 18 Aug 2003 23:32:49 GMT Subject: Writing bitfields with varying field lengths Message-ID: In order to familiarize my self with Flash files and their bytecode I've started to make an assembler. My first problem is writing the bitfields the format uses often. It is a series of fields, each can be a different number of bits, combined into the least amount of bytes possible. Extra bits in the last byte are padded with zeros. I would like to make a function that takes a size and value for each field needed, calculate the amount of needed bytes, place the values, and the nretun a binary string of the resulting bitfield. I am at a complete loss on how to place the values into the field. I've Googled but have found nothing helpful. Can anybody help? From bokr at oz.net Tue Aug 19 06:31:41 2003 From: bokr at oz.net (Bengt Richter) Date: 19 Aug 2003 10:31:41 GMT Subject: Writing bitfields with varying field lengths References: Message-ID: On Mon, 18 Aug 2003 23:32:49 GMT, Grumfish wrote: >In order to familiarize my self with Flash files and their bytecode I've >started to make an assembler. My first problem is writing the bitfields >the format uses often. It is a series of fields, each can be a different >number of bits, combined into the least amount of bytes possible. Extra >bits in the last byte are padded with zeros. I would like to make a >function that takes a size and value for each field needed, calculate >the amount of needed bytes, place the values, and the nretun a binary >string of the resulting bitfield. I am at a complete loss on how to >place the values into the field. I've Googled but have found nothing >helpful. Can anybody help? > Well, a Python integer or long can hold a large number of bits, so your problem is just how to specify a narrow field. The simplest thing is probably just to use tuples to specify bits in an integer, and how many you mean in the other element of the tuple, e.g., (bit_integer, number_of_bits), or (bi,nb) for short. You could then give some opcode and flagbit constants names, e.g., FROOBLE = (0x13, 5) FROZ_ON = (0X1, 1) FROZ_OFF = (0x0, 1) FRAZZLE = (0xff1, 12) Then if you wanted to pack those into a single bit sequence with FROOBLE at the most significant end and FRAZZLE at the least, thus: +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |1 0 0 1 1|1|1 1 1 1 1 1 1 1 0 0 0 1| +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ \frooble/ ^ \______frazzle________/ | +-froz_on you could write a packer, that takes the list and returns a single combined tuple, e.g., ...(later...) actually, why not a Bitfield class that will show interactively and that you can just add to join bitfields? E.g., (hot out of the kitchen, not very tested) ====< bitfield.py >======================================================= class Bitfield(tuple): """Instantiate by Bitfield() for Bitfield(0,0), or Bitfield(bitdata, nbits)""" def __new__(cls, *args): if not args: args = (0,0) #default zero width bitfield return tuple.__new__(cls, args) def __repr__(self): bits, nb = self return ''%(nb,''.join([chr(48+((bits>>(nb-1-i))&1)) for i in xrange(nb)])) def __add__(self, *others): """Add another bitfield or sequence of bitfield objects""" if others and not isinstance(others[0], Bitfield): others = others[0] combo, totb = self for bf, nb in others: combo = (combo<, , ] combined_bitfield: right_padded: left_padded: If we spread the combined bits out so we can compare, we get +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |1 0 0 1 1|1|1 1 1 1 1 1 1 1 0 0 0 1| +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ \frooble/ ^ \______frazzle________/ | +-froz_on You can play with this interactively, e.g., >>> import bitfield >>> BF = bitfield.Bitfield # for short >>> BF() # zero width field >>> BF() + BF(0xa,4) >>> BF() + BF(0xa,4)+ BF(07,3) >>> BF() + BF(0xa,4)+ BF(07,3)+BF(0,1) >>> byte = BF() + BF(0xa,4)+ BF(07,3)+BF(0,1) >>> byte >>> bits, nb = byte >>> hex(bits) '0xAEL' >>> nb 8 >>> byte >>> BF(-1, 5) >>> BF(-1, 0) HTH Regards, Bengt Richter From ngps at netmemetic.com Mon Aug 4 04:30:47 2003 From: ngps at netmemetic.com (Ng Pheng Siong) Date: 4 Aug 2003 08:30:47 GMT Subject: pysqlite last_insert_id References: Message-ID: According to Rick Pasotto : > How do I get the last_insert_id using pysqlite? Where 'conn' is your connection object, invoke conn.db.sqlite_last_insert_rowid(). -- Ng Pheng Siong http://firewall.rulemaker.net -+- Manage Your Firewall Rulebase Changes http://www.post1.com/home/ngps -+- Open Source Python Crypto & SSL From mis6 at pitt.edu Sat Aug 23 02:50:33 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 22 Aug 2003 23:50:33 -0700 Subject: macro FAQ References: Message-ID: <2259b0e2.0308222250.2e7f51b6@posting.google.com> "Andrew Dalke" wrote in message news:... > Here's a proposed Q&A for the FAQ based on a couple recent > threads. Appropriate comments appreciated > > X.Y: Why doesn't Python have macros like in Lisp or Scheme? This is all very interesting and I do agree that there shouuld be a FAQ about macros, nevertheless I don't see your message as suitable for a FAQ. It is ways too verbose. I mean, if one asks for a macro, s/he already knows what a macro is. The FAQ should be much shorter. What you wrote is more useful and interesting for Pythonistas than from Lispers. I think your document should be made available on the Web somewhere, but not in the FAQ. Of course the FAQ could and should give a pointer to it. Maybe lispers would be helped from a page describing how some of the things made in macros in Lisp can be made in Python. This page should be referred in the FAQ too. It is clear, however, that many things involving macros cannot just be done in Python (I mean, unless implementing a custom macro interpreter in Python, which actually I wrote few months ago as a proof of concept (google on c.l.py for simionato macros, first hit) and which I DO NOT use ;). Michele Simionato, Ph. D. MicheleSimionato at libero.it http://www.phyast.pitt.edu/~micheles --- Currently looking for a job --- From dtolton at yahoo.com Tue Aug 12 21:12:24 2003 From: dtolton at yahoo.com (Doug Tolton) Date: Wed, 13 Aug 2003 01:12:24 GMT Subject: Python vs. C# References: <3f36af20@shknews01> <2259b0e2.0308110433.204d7831@posting.google.com> <070hjvou8s33gvmom1t45t3avlkhudsstn@4ax.com> Message-ID: <934jjvkd3ss4c2lbcovjhnlaqqjjukq8jr@4ax.com> On 12 Aug 2003 10:42:21 -0400, aahz at pythoncraft.com (Aahz) wrote: >Paul Graham was the keynote speak for PyCon DC 2003. This statement on Paul Graham's web site is what got me using Python: I like Lisp but my company won't let me use it. What should I do? Try to get them to let you use Python. Often when your employer won't let you use Lisp it's because (whatever the official reason) the guy in charge of your department is afraid of the way Lisp source code looks. Python looks like an ordinary dumb language, but semantically it has a lot in common with Lisp, and has been getting closer to Lisp over time. From martin.vonloewis at hpi.uni-potsdam.de Fri Aug 8 08:42:36 2003 From: martin.vonloewis at hpi.uni-potsdam.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Fri, 08 Aug 2003 14:42:36 +0200 Subject: Why does value of __doc__ not a String type? In-Reply-To: References: <3216865.1060337379@dbforums.com> Message-ID: Alex Martelli wrote: > What string would you like it to be? Clearly, it should be PyCFunction_Type.tp_doc. This is NULL in all Python releases. If it wasn't NULL, I think BuiltinFunctionType.__doc__ would return the string, yet hex.__doc__ would still use the accessor. Regards, Martin From disgracelands at quietblue.co.uk Sun Aug 10 12:18:32 2003 From: disgracelands at quietblue.co.uk (disgracelands) Date: Sun, 10 Aug 2003 17:18:32 +0100 Subject: Trying to embed python into C, help! References: <_usZa.986$rp4.4@news-binary.blueyonder.co.uk> Message-ID: Heh, i had a sneaking suspicion that my question would be hard to understand, forming it around bad grammer really didn't help either, doh. OK thanks, your guess was correct and i was working under the false assumption that the dlls were necessary to create modules for python. To be honest the entire idea of using dlls puzzled me since python isn't platform dependant but thats the way its done in the tutorials. The chances are that i've mis-interpreted something. I've had a quick look and it seems like PyRun_SimpleString() and PyRun_String() should get me up and running pretty quick. Thanks again, you've just saved me a tonne of frustration and a fair ammount of time to boot. Cheers, dis "Alex Martelli" wrote in message news:T6tZa.36779$an6.1289737 at news1.tin.it... > disgracelands wrote: > > > I've been looking at using python and it's been going fairly well so far, > > i can call C from python and python from C fine but now i've hit a snag > > and i'm wondering how you guys have got around it. > > To be honest, I'm having some trouble understanding exactly what > your snag IS. > > > > I have to initialise python inside my C project so that i can make calls > > to python modules whenever i need to but i can't create a dll for the > > project as it's got to produce an exe or at least a lib so that i can > > execute the initialisation code. > > ...but why ever would you WANT to "create a dll" and what does THAT have > to do with "initializing Python"...? > > > > The only way around it would seem to be to create a > > separate dll project containing the python callback code that can then > > import it to python and have my C code load it too. The problem with this > > I'm trying to guess, from this sentence, that you labor under a > mis-apprehension that your C code, which embeds Python, can only > provide "Python extension modules" by supplying them as a separate > DLL. Is that what you mean by "the python callback code that can then > import it to python"...? Sorry if my guess is way off, but really I > find this sentence unparsable and incomprehensible. > > Anyway, if that's your 'snag', rest assured that there is no such > need. Your C program can extend Python, creating modules that > Python code can import, without any DLL whatsoever. For example, > get the source distribution of Python [I don't think the demos > come with e.g. the Windows installer binary] and look at source > file Demo/embed/demo.c -- you'll see it adds to Python, as a > static module, a module 'xyzzy' from which Python code could > import and call, without arguments, a function 'foo'. Unfortunately > the Python code executed in the demo doesn't show that ability > being used, but at least you'll see 'xyzzy' listed among the > "builtin modules"; just add two lines such as: > > PyRun_SimpleString("import xyzzy\n"); > PyRun_SimpleString("print 'the answer is', xyzzy.foo()\n"); > > among the other calls to PyRun_SimpleString, and you'll see it work. > > > Alex > > From aahz at pythoncraft.com Tue Aug 5 21:04:50 2003 From: aahz at pythoncraft.com (Aahz) Date: 5 Aug 2003 21:04:50 -0400 Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> Message-ID: In article , Dang Griffith wrote: >Anthony_Barker wrote: >> >> What about immutable strings? I'm not sure I understand Guido's >> preference for them. > > Strings are also immutable in Java. Maybe Guido likes Java? ;-) Python predates Java. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From jjl at pobox.com Mon Aug 18 09:33:50 2003 From: jjl at pobox.com (John J. Lee) Date: 18 Aug 2003 14:33:50 +0100 Subject: ClientCookie bug (followup) References: <87fzk4sav2.fsf@pobox.com> <87znibzrnx.fsf@pobox.com> <87oeypdh92.fsf@pobox.com> Message-ID: <87smnz6qf5.fsf@pobox.com> cartermark46 at ukmail.com (Mark Carter) writes: > > You want something like this: > > > > import ClientCookie > > c = ClientCookie.MSIECookieJar(delayload=1) > > c.load_cookie_data("hemscott-cookie.bin") > > url = 'http://businessplus.hemscott.net/corp/crp03733.htm' > > response = ClientCookie.urlopen(url) > > > > print response.read() > > response.close() > > > It doesn't work on my XP machine at least. This is proboably why > people have been doing it all wrong, allegedly. I don't see how -- the examples in question (the one everybody seems driven to copy from, and the ones people should copy from) does not include any reference to any CookieJar. > I'll investigate further. Apologies for the time lag. Thanks John From DennisR at dair.com Sun Aug 17 17:05:09 2003 From: DennisR at dair.com (Dennis Reinhardt) Date: Sun, 17 Aug 2003 21:05:09 GMT Subject: Path Problem on W2K? References: <93f5c5e9.0308170927.6e0bdc38@posting.google.com> Message-ID: <96S%a.2489$k_7.1163@newssvr27.news.prodigy.com> > I generally avoid installing in c:\ProgramFiles\anything. c:\progra~1\anything is a non-space way of specifying the same path. -- Dennis Reinhardt DennisR at dair.com http://www.spamai.com?ng_py From hokiegal99 at hotmail.com Tue Aug 26 19:22:06 2003 From: hokiegal99 at hotmail.com (hokieghal99) Date: Tue, 26 Aug 2003 19:22:06 -0400 Subject: String find and replace Message-ID: import os, string print " " setpath = raw_input("Enter the path: ") def find_replace(setpath): for root, dirs, files in os.walk(setpath): fname = files for fname in files: find = string.find(file(os.path.join(root,fname), 'rb').read(), 'THIS') print find if find >=1: replace = string.replace(str, 'THIS', 'THAT') find_replace(setpath) print " " Why doesn't this work? I get this error: Traceback (most recent call last): File "html_find_replace.py", line 12, in ? find_replace(setpath) File "html_find_replace.py", line 11, in find_replace replace = string.replace(str, 'THIS', 'THAT') File "/usr/local/lib/python2.3/string.py", line 370, in replace return s.replace(old, new, maxsplit) TypeError: expected a character buffer object From Kevin.Smith at sas.com Tue Aug 26 08:49:57 2003 From: Kevin.Smith at sas.com (Kevin Smith) Date: 26 Aug 2003 12:49:57 GMT Subject: Preferred standalone TAL module? References: <5d855b4b.0308251419.31e894e6@posting.google.com> Message-ID: <20030826085001862-0400@braeburn.themorgue.org> http://zpt.sf.net uses the actual Zope sources with just a thin wrapper around them to make them work outside the Zope framework. They aren't currently in development simply because they are up to date with the Zope source. In <5d855b4b.0308251419.31e894e6 at posting.google.com> Fahd Khan wrote: > The web-based Python software I've written thus far lacks a consistent > approach to generating output. After reading Graham Fawcett's > endorsement of Zope Template Pages in the recent web programming > thread, I looked up TAL and found it to be quite nice. Going through > recent postings on Google it seems SimpleTAL is the standalone TAL > module in most active usage and development just now, would the > community concur or suggest alternatives? > > Here's the post I'm referencing: > http://groups.google.com/groups?safe=images&ie=UTF-8&oe=UTF-8&as_ > umsgid=e9570f37.0304070923.70612d28 at posting.google.com%20&lr=&hl=en > > I'm also motivated by the web programming thread's underlying message > of seeking "industrial strength" solutions that work in many domains > using existing tools, so that I spend more time coding and less time > "shopping" for modules. TAL seems a good way to do that (I'm most > certainly not ready to take the plunge into Zope). Any comments there? > > Fahd Khan > -- Kevin Smith Kevin.Smith at sas.com From duncan at NOSPAMrcp.co.uk Thu Aug 21 10:29:11 2003 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Thu, 21 Aug 2003 14:29:11 +0000 (UTC) Subject: [OT] Why is it called string? References: <3f44ce77$0$556$b45e6eb0@senator-bedfellow.mit.edu> Message-ID: Brian Kelley wrote in news:3f44ce77$0$556$b45e6eb0 at senator-bedfellow.mit.edu: > I have always been curious about why a construct like: > > a = "the quick brown fox jumps over the lazy dog" > > is called a string. I have always assumed that it was a reference to a > necklace type construct as in (and I can't resist) a "string of perls". I think you have that about right. It's a "string of characters" rather than "pearls". I could be wrong though, we get so used to our terminology that we don't ever need to think where it comes from. I was watching an episode of Mastermind (a UK quiz show) the other day, and one of the questions totally threw me, it was: "In computing, the word 'bit' is an abbreviation of what two other words?", and I was sitting there thinking 'is it really an abbreviation?' long after the contestant had passed on that answer and gone on to other questions. Yes, I worked it out eventually, and I think the contestant had as well by the time he got told the answers to the questions he had passed on. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From bignose-hates-spam at and-zip-does-too.com.au Sun Aug 10 19:13:48 2003 From: bignose-hates-spam at and-zip-does-too.com.au (Ben Finney) Date: Sun, 10 Aug 2003 23:13:48 GMT Subject: Slogan: Getting Rich Overnight References: Message-ID: On Sun, 10 Aug 2003 23:56:01 +0200, Christian Tismer wrote: > But is there any way for such a slogan to pass spam at all? The much greater battle is: if it passes electronic/programmatic filters, how are you going to get it past the wetware filters -- i.e., the fact that it just sounds like spam when you hear it? > If I remove the ambiguity, the slogan gets lame. Anything with "get rich {quick,fast,overnight}" already has far too many negative connotations to sound un-lame. > Any ideas? Choose another slogan, forget the "get rich" nonsense. While the sentiment is great, and I agree it's a wonderful feeling when you realise how much your options have increased with little effort, the "get rich overnight" just doesn't jibe with me. The feeling isn't one of being (financially) rich; it's one of being free from restrictions. Another thread recently mentioned the idea that, opposed to other languages, Python lets you go home on time. That's closer to the mark. -- \ "If life deals you lemons, why not go kill someone with the | `\ lemons (maybe by shoving them down his throat)." -- Jack Handey | _o__) | http://bignose.squidly.org/ 9CFE12B0 791A4267 887F520C B7AC2E51 BD41714B From sjmachin at lexicon.net Wed Aug 13 19:04:55 2003 From: sjmachin at lexicon.net (John Machin) Date: 13 Aug 2003 16:04:55 -0700 Subject: Determine file type (binary or text) References: <20030813105623.J19120@ActiveState.com> Message-ID: Graham Fawcett wrote in message news:... > > It is trivial to create a non-text file that has no NULs. > > f = open('no_zeroes.bin', 'rb') > for x in range(1, 256): > f.write(chr(x)) > f.close() I tried this but it didn't work. It said: IOError: [Errno 2] No such file or directory: 'no_zeroes.bin'. So I thought I had to be persistent but after doing it a few more times it said: SerialIdiotError: What I tell you three times is true. NotLispingError: You need 'wb' as in 'wascally wabbit' This is very strange behaviour -- does my computer have worms? From patrick at novaroot.com Mon Aug 11 12:57:35 2003 From: patrick at novaroot.com (Patrick Lioi) Date: 11 Aug 2003 09:57:35 -0700 Subject: Hello References: Message-ID: <2a82921f.0308110857.cbe537b@posting.google.com> "??" wrote in message news:... > SSB3YW50IHRvIHVzZXIgdGhlIG5ld2dyb3VwIG9mIHB5dGhvbiwgYnV0IEkgZG8gbm90IHVzZSBp > dCEgY2FuIHlvdSBnaXZlIG1lIGEgaGFuZD8= > > -- Translation, although it doesn't exactly help any :P "I want to user the newgroup of python, but I do not use it! can you give me a hand?" I like how Mr ?? was able to user the newgroup well enough to post this, but not his original question. From mark at markroseman.com Mon Aug 25 16:02:55 2003 From: mark at markroseman.com (Mark Roseman) Date: Mon, 25 Aug 2003 16:02:55 -0400 Subject: Revitalizing Tk (was Re: Using the C Source Code from Tcl/Tk) References: Message-ID: "David M. Cook" wrote: > I suppose going through the tcl interpreter is not an ideal situation, but > it works, and I've seen some pretty amazing things done with Tkinter. I > prefer pygtk, though. Tk is beginning to show its age, though the text and > canvas widgets are still strong points. As an earlier poster mentioned, there is an effort underway to update Tk and really brush the dust off of it. People who know Tk can make it look good with a lot of option tweaking and bringing in third-party widgets, but we'd like to see it work a bit better right out of the box. Anyway, as mentioned, more info on this effort is here: http://tcl.projectforum.com/tk/ As one of the people behind this effort (yeah I use Tcl), we'd be very happy to see a lot of Python folks involved. Have a peek at the site, and if you still have questions, post there or please feel free to email me. As an aside, many of us in the Tcl community who are doing professional-level apps have struggled with the choices for a GUI toolkit, and have calculated that improving Tk is not that much work, and doing that would be the best alternative for a fairly large class of development needs. Most of us are pretty pragmatic and not hugely wedded to Tcl (lots of us like Python too), though we do like a lot of what Tcl does offer, including Tk and other goodies. Mark From careers at s2io.com Wed Aug 20 07:28:21 2003 From: careers at s2io.com (Careers at S2IO Technologies) Date: Wed, 20 Aug 2003 07:28:21 -0400 (EDT) Subject: Interest in Employment Opportunities at S2io Message-ID: <200308201128.h7KBSLOu000810@guinness.s2io.com> Thank you for your interest in employment opportunities with S2io Technologies Corp. We regret that we cannot personally respond to all applicants. Your resume will be kept on file for a period of three months and you will be contacted should a position become available that requires your experience and qualifications. Best Regards, S2io Technologies Corp. From hokiegal99 at vt.edu Tue Aug 26 21:10:16 2003 From: hokiegal99 at vt.edu (hokiegal99) Date: Tue, 26 Aug 2003 21:10:16 -0400 Subject: String find and replace References: Message-ID: <3F4C04F8.5070401@vt.edu> Thanks for the explanation, I can make it work this way: import os, string setpath = raw_input("Enter the path: ") for root, dirs, files in os.walk(setpath): fname = files x = 'THIS' y = 'THAT' for fname in files: myfile = file(os.path.join(root,fname), 'r') mystr = myfile.read() myfile.close() search = string.find(mystr, x) if search >=1: string.replace(mystr, x, y) print "Replacing", x, "with", y, "in", fname If only I could actually make the change to the files! It works in theory, but not in practice ;) Anyone recommend how to actual write the change to the file? I'm new to this, so be kind. Thanks Everyone!!! Geoff Gerrietts wrote: > Quoting hokieghal99 (hokiegal99 at hotmail.com): > >>import os, string >>print " " >>setpath = raw_input("Enter the path: ") >>def find_replace(setpath): >> for root, dirs, files in os.walk(setpath): >> fname = files >> for fname in files: >> find = string.find(file(os.path.join(root,fname), 'rb').read(), 'THIS') > > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > this string is never bound to a name > (ie, you never assign str=file(...).read()) > >> print find >> if find >=1: >> replace = string.replace(str, 'THIS', 'THAT') > > ^^^ > this name is currently bound to > the builtin function str() > > >>find_replace(setpath) >>print " " > > > > You might consider the fragment below, instead. It's a couple lines > longer, but safer (your .close() happens exactly when you want it to) > and probably more readable. > > for root, dirs, files in os.walk(setpath): > fname = files > for fname in files: > myfile = file(os.path.join(root,fname), 'rb') > mystr = myfile.read() > myfile.close() > find = string.find(mystr, 'THIS') > print find > if find >=1: > replace = string.replace(mystr, 'THIS', 'THAT') > > > Luck, > --G. > From michael at ninthorder.com Thu Aug 14 16:28:34 2003 From: michael at ninthorder.com (Michael Cornelius) Date: Thu, 14 Aug 2003 15:28:34 -0500 Subject: 3 new slogans In-Reply-To: References: Message-ID: <20030814202833.GC6152@ninthorder.com> "My other programming language is also Python." From FBatista at uniFON.com.ar Fri Aug 15 12:48:01 2003 From: FBatista at uniFON.com.ar (Batista, Facundo) Date: Fri, 15 Aug 2003 13:48:01 -0300 Subject: cPickle alternative? Message-ID: #- > What protocol did you pickle your data with? The default #- (protocol 0, #- > ASCII text) is the slowest. I suggest you upgrade to #- Python 2.3 and #- > save your data with the new protocol 2 -- it's likely to #- be fastest. #- > #- > #- > Alex #- > #- Thanks:) #- i'm using default protocol, i'm not sure if i can upgrade so #- simply, because #- i'm using many modules for Py2.2 Last time I upgraded, was from XLM to bin format (there weren't "protocols"). It was easy: the load() method detects in what format is pickled, so I just modified the dump() method, and that was all! Don't know if this also works with this new methodology. . Facundo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ADVERTENCIA La informaci?n contenida en este mensaje y cualquier archivo anexo al mismo, son para uso exclusivo del destinatario y pueden contener informaci?n confidencial o propietaria, cuya divulgaci?n es sancionada por la ley. Si Ud. No es uno de los destinatarios consignados o la persona responsable de hacer llegar este mensaje a los destinatarios consignados, no est? autorizado a divulgar, copiar, distribuir o retener informaci?n (o parte de ella) contenida en este mensaje. Por favor notif?quenos respondiendo al remitente, borre el mensaje original y borre las copias (impresas o grabadas en cualquier medio magn?tico) que pueda haber realizado del mismo. Todas las opiniones contenidas en este mail son propias del autor del mensaje y no necesariamente coinciden con las de Telef?nica Comunicaciones Personales S.A. o alguna empresa asociada. Los mensajes electr?nicos pueden ser alterados, motivo por el cual Telef?nica Comunicaciones Personales S.A. no aceptar? ninguna obligaci?n cualquiera sea el resultante de este mensaje. Muchas Gracias. -------------- next part -------------- An HTML attachment was scrubbed... URL: From pinard at iro.umontreal.ca Sun Aug 3 10:34:01 2003 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois_Pinard?=) Date: 03 Aug 2003 10:34:01 -0400 Subject: PyChecker work with Python 2.3? In-Reply-To: <3F2D0A11.3090607@ghaering.de> References: <3F2C5300.FA223CBA@easystreet.com> <3F2CBCC2.3FC51D57@easystreet.com> <3F2D0A11.3090607@ghaering.de> Message-ID: [Gerhard H??ring] > achrist at easystreet.com wrote: > > Gerhard H?ring wrote: > >>achrist at easystreet.com wrote: > >> > >>>The pychecker site says that pychecker works with versions > >>>1.5 through 2.2. Any reason to expect that 2.3 breaks it? > >>>Anyone tried it to see? > >> > >>Why don't *you*? > > Smart people learn from their mistakes. Very smart people > > learn from other people's mistakes. > If you think you are so smart, why don't you use your time more economically > then and just try it out? Come on, guys! What's so wrong, asking if someone had success or problems with something? Asserting for oneself that a package `works' may be a bigger undertaking than one might think of. Quickly trying simple cases is one thing. But being solid in all conditions is another game. If unit testing is popular in these days, this is because people feel an urge of being able to answer such questions, however imperfect unit testing may be. It looks like time economical, to me, asking to a crowd of interesting people if someone hit any problem using a package under specified conditions, compared to trying all alone to ascertain the quality. There is of course the danger of abusive laziness, but we should be careful and reserved, before silently assuming that our correspondent is rotten lazy. -- Fran??ois Pinard http://www.iro.umontreal.ca/~pinard From skip at pobox.com Mon Aug 4 15:15:14 2003 From: skip at pobox.com (Skip Montanaro) Date: Mon, 4 Aug 2003 14:15:14 -0500 Subject: Freeze Question In-Reply-To: References: <16174.43083.667395.719317@montanaro.dyndns.org> Message-ID: <16174.45250.408648.333929@montanaro.dyndns.org> David> are there any good places that describe more explicitly how to David> build a static python? I think Modules/Setup is about it. If I had to do this today, here's what I'd do. 1. Starting from a clean source tree, run the 'script' command to get a log of the session in a file named 'typescript'. 2. Exit the script session. 3. Run the usual 'configure ; make' commands. 4. Edit Modules/Setup, uncommenting those modules which you want built statically. Many are simple and require no extra compile or link flags. For others, use the build commands found in the typescript file to identify -I..., -L..., and -l... flags. Obviously, omit or modify any flags that would be used to generate a shared library (-shared, -Bshared, -fPIC, etc). 5. Run 'make clean ; make' 6. Test the resulting executable. 7. Repeat steps 4-6 as necessary. 8. Congratulate yourself on a job well done and buy yourself a beer. If that is an unappealing process for some reason, try this shortcut: 1. Pay a consultant to do it. 2. Get other work done. 3. Congratulate your consultant on a job well done and buy both of you a beer. There is a third, somewhat longer term, alternative: 1. Teach distutils how to build a static Python executable. 2. Submit a patch to SF. 3. Buy yourself two beers. Skip From wiebke.paetzold at mplusr.de Wed Aug 6 03:51:36 2003 From: wiebke.paetzold at mplusr.de (Wiebke Pätzold) Date: Wed, 06 Aug 2003 09:51:36 +0200 Subject: abstraction of the column names (classes) References: <13a533e8.0308051300.2d463b04@posting.google.com> Message-ID: On 5 Aug 2003 14:00:23 -0700, p-abel at t-online.de (Peter Abel) wrote: >Wiebke P?tzold wrote in message news:... >> Hi all! >> >> I create a database that contains a table. 'Nachname' is one of 13 >> column names. This program can search for >> a special letter. In my example it is 'ra'. and the search takes place >> in 'Nachname'. 'ra' takes place within a word. This is solved with >> regular expression. So that I can limit my search. >> For example: I can search for 'ra' and it is not relevant wich letters >> follow or wich letters are in front of 'ra'. >> Now I want to abstract the column name 'Nachname'. So I search in an >> unknown column. Only the user of the program should determine in wich >> class the search takes place. This input should happen in the view >> lines of testing the class. >> My task is it to change the program that a abstraction of the column >> names takes place. >> Please give me a detailed answer. If it is possible the changed >> program because I am very new in Python and I am orientationless. >> >> This is the program >> >> import sys >> import Mk4py >> import re >> >> db = Mk4py.storage("c:\\datafile.mk",1) >> vw = db.view("people") >> >> class PatternFilter: >> def __init__(self, pattern): >> self.pattern = re.compile(pattern) >> >> def __call__(self, row): >> try: >> nachname = row.Nachname >> except AttributeError: >> return 0 >> return self.pattern.search(nachname)is not None >> >> vf = vw.filter(PatternFilter("ra.*")) >> >> for r in vf: >> print vw[r.index].Nachname > >RegEx are really great and there are a lot of problems you can >only solve with them. But if I understand you right your problem >is to find a string where a substring is to be in, the simple >string operation does the work: >if String.find(substring) > -1: > >**find** will give you the position in String where substring >will occure the 1rst time and -1 if substring doesn't occur. > >e.g. >>>> nameList=['Meyer', 'Maxon', 'Johnson', 'Mueller'] >>>> for name in nameList: >... if name.find('er')>-1: >... print name >... >Meyer >Mueller >>>> > >So if you can get your columns contents in **ColumnList** >and your searchpattern in **SearchPattern** so the following >function could do the work: > >def getPatternMatches(ColumnList,SearchPattern): > foundList=[] > for n in ColumnList: > if n.find(SearchPattern) > -1: > foundList.append(n) > return foundList > >Regards >Peter I think you didn't understand me. My task is: I have a database that consists of a tabla with different columns. The program should have two possibilities to search for regular expressions. The firat one possibility is in this program. Here I can look for a certain expression. In my example I can look for 'ra' and it is not relevant wich letters follow or wich letters are in front of 'ra'. But this search can ONLY takes place in the column 'Nachname'. 'Nachname is fixed by the programmer. The second possibility is that the user and NOT the programmer determine the column name in which the user want to look for a regular expression. And so I think there must be anything with a print. Only like that the user can enterin what column the search takes place. From danbmil99 at yahoo.com Thu Aug 7 21:32:40 2003 From: danbmil99 at yahoo.com (dan) Date: 7 Aug 2003 18:32:40 -0700 Subject: midi with ctypes References: Message-ID: Interesting idea, but frankly it seems like alot of extra overhead. Now that midipy is compiling, I'm more inclined to add features in C than using ctypes. What advantages can we expect from doing it this way? anton at vredegoor.doge.nl (Anton Vredegoor) wrote in message news:... > Recently there has been a lot of progress concerning the integration > of midi into python. A midipy.cpp for Python20 is found and various > compiling efforts having been undertaken to compile it for Python23. > See the other threads about midipy.cpp for more info. > > However, seeing that the resulting midipy.pyd is only 48 kilobyte long > and seeing that midipy.cpp exports only 14 functions, most of which > are inside winmm.dll (for W98 and W2000 at least) I decided to start > another effort, which I'm presenting below and for which I hope kind > people will add some functions since I doesn't seem to be too hard. > > first create a winmm.def like this: > > pexports winmm.dll > winmm.def > > Now open winmm.def and find the relevant functions, compare them with > what's inside midipy.cpp and try to reproduce them using ctypes. The > file "mmedia.hlp" from Borland C++ Builder for example, contains > detailed info about midi functions, most of which seem to be direct > wrappers around the functions inside winmm.dll . > > Now to get started try this: > > #ctypesmidipy.py > > from ctypes import * > > def getNumMidiInDevices(): > return windll.winmm.midiInGetNumDevs() > > def getNumMidiOutDevices(): > return windll.winmm.midiOutGetNumDevs() > > def test(): > print getNumMidiInDevices() > print getNumMidiOutDevices() > > if __name__=='__main__': > test() > > Please note that after importing this file every function should work > the same as if midipy.pyd had been imported. Not being very familiar > with midi programming I succeeded only to get 2 of the 14 functions > working. Getting more functions to work should be harder, but not very > hard. Please, anybody reading this, add a function if there's a sudden > insight into how it should be done. By and by ctypesmidipy.py will be > put together like a little pypy-alike project replacing midipy.cpp :-) > Any feasibility studies and remarks about possible legal objections to > this are very welcome too. > > Anton From eppstein at ics.uci.edu Mon Aug 18 12:18:52 2003 From: eppstein at ics.uci.edu (David Eppstein) Date: Mon, 18 Aug 2003 09:18:52 -0700 Subject: Py2.3: Feedback on Sets References: <%BX%a.4999$N37.3051@nwrdny02.gnilink.net> <7h3d6f3143s.fsf@pc150.maths.bris.ac.uk> Message-ID: In article <7h3d6f3143s.fsf at pc150.maths.bris.ac.uk>, Michael Hudson wrote: > Yup! Well, *, anyway. I'd prefer a Haskell-style ++ for > concatenation, but + isn't totally silly (strings and lists are > monoids, at least :-). list * int, OTOH, seems a bit smelly to me > (though I'm not sure what a better spelling would be...). Multiplication by (nonnegative) integers is a pretty standard thing to do in monoids, and means close to what Python's list*int syntax does: add the thing to itself that many times. I'm not sure why multiplying a list by a negative number produces the empty list instead of an exception, though. -- David Eppstein http://www.ics.uci.edu/~eppstein/ Univ. of California, Irvine, School of Information & Computer Science From jcribbs at twmi.rr.com Thu Aug 7 22:07:50 2003 From: jcribbs at twmi.rr.com (Jamey Cribbs) Date: Fri, 08 Aug 2003 02:07:50 GMT Subject: Database question..... In-Reply-To: References: Message-ID: John D. wrote: > I have a small (fewer than a few thousand records) database with the > following properties: > > Each record has four fields: A, B, C, D. > Fields A and B are unique: > there is one B for every A and one A for every B. > Fields C and D are not unique. > Sometimes I need to use A as the key, other times B is the key: > I use A to return B, C, D and also B to return A, C, D. > The items may all be represented as short ASCII strings. > > Currently I am storing this in a 100KB file and converting this to two > dictionaries. I am reading and writing the entire file to update single > records, which is inefficient. I am thinking about using anydbm, but then > how do I do the two-way dictionary lookup? Would I have to store the whole > database twice? What if I had ten items, would I have to store it ten > times? Is this what a relational database allows? > > John > > > John, I wrote a Python module, called KirbyBase, that might be a solution to your problem. KirbyBase is a pure-python, text-file based, database management system. In KirbyBase, you could create a table to hold your records. Then to select a record using field A as the key, you would write: result = db.select('file.tbl',['A'],['key to search for'],['B','C','D']) This line says, "Search the table contained in file 'file.tbl'. Find all records where field 'A' matches the 'key to search for'. When you find a match, return fields 'B','C', and 'D'. To use field 'B' as the key, simply change the line to this: result = db.select('file.tbl',['B'],['key to search for'],['A','C','D']) Now, if you want to add a new record and you want to make sure that fields 'A' and 'B' of the new record are unique, you could do the following: if db.select('file.tbl',['A'],['key for new record']) > 0: print 'Value of A field in new record not unique!' elif db.select('file.tbl',['B'],['key for new record']) > 0: print 'Value of B field in new record not unique!' else: db.insert('file.tbl',['A value','B value','C value','D value'] To update a single record (if you are not changing the value of 'A' or 'B', then you can do: db.update('file.tbl',['A'],['key of record to update'],['C','D'],['new value of C','new value of D']) If this sounds like it might work for you, you can find KirbyBase at: http://www.netpromi.com/kirbybase.html Sorry for the long reply. I got a little carried away. :) Jamey Cribbs From skip at pobox.com Fri Aug 22 14:47:42 2003 From: skip at pobox.com (Skip Montanaro) Date: Fri, 22 Aug 2003 13:47:42 -0500 Subject: visual indentation In-Reply-To: References: Message-ID: <16198.25934.862354.401938@montanaro.dyndns.org> Hilbert> I'm using CGKit in python which has a Renderman binding, so to Hilbert> output the same RIB I'd write: Hilbert> RiWorldBegin() Hilbert> RiColor(1.0,1.0,1.0) Hilbert> RiSurface('constant') Hilbert> RiSphere(1.0,-1.0,1.0,360) Hilbert> RiWorldEnd() Hilbert> But I get an error, because python interprets my indentation as Hilbert> a block in the python code. As it should, because whitespace is significant in Python. Hilbert> So the only way to write this is without the indentation: Hilbert> RiWorldBegin() Hilbert> RiColor(1.0,1.0,1.0) Hilbert> RiSurface('constant') Hilbert> RiSphere(1.0,-1.0,1.0,360) Hilbert> RiWorldEnd() Hilbert> But this is a lot harder to read. Hilbert> Is there any way to use such "visual" indentation in python? In this case, just use "if 1:" RiWorldBegin() if 1: RiColor(1.0,1.0,1.0) RiSurface('constant') RiSphere(1.0,-1.0,1.0,360) RiWorldEnd() Skip From shalehperry at comcast.net Sat Aug 23 01:38:01 2003 From: shalehperry at comcast.net (Sean 'Shaleh' Perry) Date: Fri, 22 Aug 2003 22:38:01 -0700 Subject: crazy programming language thoughts In-Reply-To: References: <3f457487_7@corp.newsgroups.com> Message-ID: <200308222238.01282.shalehperry@comcast.net> On Friday 22 August 2003 16:05, Ryan Lowe wrote: > > i did look into some of the ones mentioned, specifically, COBOL and > Applescript. i was more impressed with applescript, because i think you can > expand the language that the interpreter understands (unlike COBOL) with > some sort of 'dictionary,' though its a little hard to say at first > glance, given the new-programmer-targeted documentation. it seemed a little > wordy, like writing a sentence just to make an assignment when there is a > perfectly good = sign for that :) > ah, but there is the rub. If '=' is good enough for assignment why bother with ANY english text? Why is: a = b better than assign b to a ?? (yes, this is a rhetorical question) From danbmil99 at yahoo.com Sun Aug 3 19:36:56 2003 From: danbmil99 at yahoo.com (dan) Date: 3 Aug 2003 16:36:56 -0700 Subject: 'print' in a CGI app. References: Message-ID: This is a random guess, but try: print "Hello
" print "World" "Andrew Chalk" wrote in message news:... > In a Python 2.2 app. running under CGI the statements > > print "Hello\n" > print "World" > > print both words on the same line in IE6. How do I print the second one on a > new line (i.e. respect the \n in the first statement). > > Many thanks! From bgailer at alum.rpi.edu Fri Aug 1 22:32:49 2003 From: bgailer at alum.rpi.edu (Bob Gailer) Date: Fri, 01 Aug 2003 20:32:49 -0600 Subject: String Replacement In-Reply-To: <7b454334.0308011400.266438f9@posting.google.com> Message-ID: <5.2.1.1.0.20030801202412.02c8de20@66.28.54.253> At 03:00 PM 8/1/2003 -0700, Fazer wrote: >[snip] I am sort of confused in >using the string modules and its functions/modules to replace the \n >with
. I import the string module and I am not soo sure on how to >do the replacing. > >Here's how my code sort of likes: > >import string >string.replace(DataFromDatabase, "\n", "
") > >Unfortunately, it doesn't work. Actually, it does work. Just not in the way you expect. Read the documentation:replace(old, new[, maxsplit]) Return a copy of the string with all occurrences of substring old replaced by new.... string.replace is returning the altered copy; your program is not doing anything with it. What you want is to take the returned value and assign it to DataFromDatabase: DataFromDatabase = string.replace(DataFromDatabase, "\n", "
") BUT also realize that most of the string module functions are now string methods, so it is possible (and simpler) to write: DataFromDatabase = DataFromDatabase.replace("\n", "
") If you develop further needs for substitutions you'd want to consider alternate techniques rather than stacking up a lot of replace calls. OTOH some methods do operate "in-place" such as listobject.sort() and listobject.reverse(). Bob Gailer bgailer at alum.rpi.edu 303 442 2625 -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.500 / Virus Database: 298 - Release Date: 7/10/2003 From vze4rx4y at verizon.net Sun Aug 17 14:03:40 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Sun, 17 Aug 2003 18:03:40 GMT Subject: Py2.3: Feedback on Sets References: Message-ID: <0sP%a.8755$Cd2.3914@nwrdny01.gnilink.net> "John Smith" > Suggestion: How about adding Set.isProperSubset() and > Set.isProperSuperset()? We have them in operator form: ab Spelling them out did not seem to add much value. This is doubly true because some people read it as s.isProperSubsetOf(t) and others read it as s.hasTheProperSubset(t). Raymond Hettinger > Thanks for this wonderful module. I've been working on data mining and > machine > learning area using Python. Set operations are very important to me. Great. You'll love it even more when I implement it in C. Raymond Hettinger From danb_83 at yahoo.com Fri Aug 22 20:40:05 2003 From: danb_83 at yahoo.com (Dan Bishop) Date: 22 Aug 2003 17:40:05 -0700 Subject: visual indentation References: Message-ID: Hilbert wrote in message news:... > Hello, > > I'm using python to output RIB streams for Renderman. > The RIB stream is a bunch of statements which describes > a 3d image. The Rib standard allows for blocks which we > usually indent for better visualization for example: > > WorldBegin > Color [1 1 1] > Surface "constant" > Sphere(1.0, -1.0, 1.0, 360) > WorldEnd ... > Is there any way to use such "visual" indentation in python? If the code consists of nothing but expressions (which yours does), you can write: (RiWorldBegin()) ( RiColor(1.0,1.0,1.0)) ( RiSurface('constant')) ( RiSphere(1.0,-1.0,1.0,360)) (RiWorldEnd()) or ( RiWorldBegin(), RiColor(1.0,1.0,1.0), RiSurface('constant'), RiSphere(1.0,-1.0,1.0,360), RiWorldEnd() ) From kriley1 at hotmail.com Fri Aug 22 11:24:19 2003 From: kriley1 at hotmail.com (Ken R.) Date: 22 Aug 2003 08:24:19 -0700 Subject: problem with custom sort function .... long References: <1e5ab84a.0308211209.eaf3f22@posting.google.com> Message-ID: <1e5ab84a.0308220724.15891182@posting.google.com> > Given that your example data all have 'a' in the first column, these > statements of ill behavior make no sense! > Oh my! One would think that I just dashed off a question to the group without spending any time on the problem (not the case). No excuses for my oversight but thanks for your gentle reply :). From magik1300 at aol.com Thu Aug 7 10:30:34 2003 From: magik1300 at aol.com (Gary) Date: 7 Aug 2003 07:30:34 -0700 Subject: Accessing c objects in python Message-ID: Hi- I've been searching the web for a while and I've been unable to find a way to access c data objects in python without using SWIG. I can do methods just fine but I can't access variables. It seems like PyModule_AddObject should work but it segfaults my program. There's a good chance I'm just using it wrong, or I should be using something else. Could someone give me a simple, complete example pretty please? Thanks! Gary From richardshea at fastmail.fm Thu Aug 21 16:49:50 2003 From: richardshea at fastmail.fm (Richard Shea) Date: 21 Aug 2003 13:49:50 -0700 Subject: MySqlDB Question - CompatMySqlDB is all I can find ? References: <282f826a.0308210238.11ef6a97@posting.google.com> <3f44a6e7@shknews01> Message-ID: <282f826a.0308211249.64fb3029@posting.google.com> Jiri Barton wrote in message news:<3f44a6e7 at shknews01>... > See, I don't know if that's causing it (it is on Linux, actually) but you > may want to use > > import MySQLdb > > next time (mind the case sensitivity) just to stay platform independent. > HTH, Jiri Hi Jiri - OK thanks I'll try that. regards richard. From jepler at unpythonic.net Sat Aug 2 23:23:12 2003 From: jepler at unpythonic.net (Jeff Epler) Date: Sat, 2 Aug 2003 22:23:12 -0500 Subject: Match beginning of two strings In-Reply-To: References: Message-ID: <20030803032308.GA25357@unpythonic.net> This is a naive implementation of the 'extract' function. def extract(a, b): m = min(len(a), len(b)) for i in range(m): if a[i] != b[i]: return a[:i] return a[:m] Here's one that uses the new zip() function: def extract2(a, b): m = min(len(a), len(b)) for i, ai, bi in (range(m), a, b): if ai != bi: return a[:i] return a[:m] .. unfortunately, it seems to be slower than the first method. On my machine (800MHz PIII): $ python timeit.py -s 'import ravi' \ 'ravi.extract("abcdefghijklmnopqrstuvwxyz","abcdefghijklmnopBHLHT")' 10000 loops, best of 3: 32.7 usec per loop If your goal is actually something slightly different---for instance, find the string from a list with the largest shared prefix to a given string---then you probably need to research an efficient algorithm.* Otherwise, you may be stuck with the above. If you have 200GB, and each line is 80 chars, you have about 2.7 billion lines. If you call extract() once per line, and it takes 32 usec, you're looking at 24 hours to run. Writing extract as a C extension may be wise, you're likely to be able to cut those 32 usec down to little more than Python function call overhead, or <2usec per loop. That makes your 2.7x10^9 calls only take 70 minutes. Jeff * The efficient algorithm for this problem might involve arranging the list of strings as a tree, which makes finding the right prefix for a given string against the list take only about lg(len(l)) steps, instead of len(l) steps. This isn't so much a Python problem as a computer science problem, though. From vanevery at 3DProgrammer.com Tue Aug 12 00:45:47 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Mon, 11 Aug 2003 21:45:47 -0700 Subject: Python vs. C# References: Message-ID: Heiko Wundram wrote: >Brandon wrote: >> >> Python advocates tend to pooh-pooh strong typing, and I'm wondering >> if in a large-scale industrial context, if that's really a valid >> stance to take. > > Where other people had written huge amounts of C++ code for a > renderer, which was incomprehensible even to the original programmer > after about a weeks time, my code remained "relatively" short and > clean (I had to > write it in 72 hours), nicely structured into separate modules, and > with > a well designed class inheritance scheme (which is pretty important > for > a renderer, for the user to be able to integrate his/her own objects > later on). Yes your rendering code is nice looking. Is it fast? Were you working on a problem where it needed to be fast? I haven't been using C++ out of love. I've been using it for performance. And I don't think "what I can do in 72 hours" is a valid test for big industrial system architectures. Is your code going to hold up in the face of dozens of programmers banging on it, and hundreds or thousands of programmers using it? And still be fast? > I don't think that "static typing" (Python is strongly typed btw., > just to correct your statement) It is? Then I'm confused, because around here people keep talking about the beauty of avoiding types. > is any concern for most people (even for > most executives, I guess my professors count as that too), just > getting a > working solution for a problem quickly, smoothly and readably. And > that's what Python excels at. What you are saying is Python excels at prototyping, where speed and flexibility are paramount. You are not saying that Python excels as a big system architecture language, where stability and safety are paramount. > Yeah, I can agree here. But in my experience, if I can show the people > what power Python comes with ("batteries included"), after their > amazement stops, they'll all start asking which book to buy to start > learning. Even with the "power-play" Sun and Microsoft did to boost > Java > and C#, Python still seems as a valid and interesting alternative to > most people I know (except those living in the "Microsoft-Universe", > of course, but I guess I'll never save them from that big black hole > anyway). That "except" is, like, 1/2 to 2/3 of industry. I think you Python guys need to wake up that there's a much bigger, scarier, and more threatening world out there than the UNIX world of "engineering done right." That world is also not sitting still, it's on the move. For interoperability of langauges, UNIX has nothing to offer like the .NET Framework. DirectX is now ahead of OpenGL on vertex/pixel shader API capability and stability. The black hole, if not taken seriously, will swallow you. Either that or you're forced into "clone and conquer" in reverse. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From FBatista at uniFON.com.ar Fri Aug 22 10:23:52 2003 From: FBatista at uniFON.com.ar (Batista, Facundo) Date: Fri, 22 Aug 2003 11:23:52 -0300 Subject: Which way to say 'private'? Message-ID: #- (Also, remember that, with properties, you can have things which look #- like direct attributes actulally be set and read with setter and #- getter functions, so it is perfectly OK to make data attributes be #- part of the interface, as you can later install getters and setters #- for them without changing the interface.) One thing about property(): Can't find it's documentation! :( Know it exists and how to use it because of examples found on the net. But where it's formally explained? Thanks! . Facundo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ADVERTENCIA La informaci?n contenida en este mensaje y cualquier archivo anexo al mismo, son para uso exclusivo del destinatario y pueden contener informaci?n confidencial o propietaria, cuya divulgaci?n es sancionada por la ley. Si Ud. No es uno de los destinatarios consignados o la persona responsable de hacer llegar este mensaje a los destinatarios consignados, no est? autorizado a divulgar, copiar, distribuir o retener informaci?n (o parte de ella) contenida en este mensaje. Por favor notif?quenos respondiendo al remitente, borre el mensaje original y borre las copias (impresas o grabadas en cualquier medio magn?tico) que pueda haber realizado del mismo. Todas las opiniones contenidas en este mail son propias del autor del mensaje y no necesariamente coinciden con las de Telef?nica Comunicaciones Personales S.A. o alguna empresa asociada. Los mensajes electr?nicos pueden ser alterados, motivo por el cual Telef?nica Comunicaciones Personales S.A. no aceptar? ninguna obligaci?n cualquiera sea el resultante de este mensaje. Muchas Gracias. -------------- next part -------------- An HTML attachment was scrubbed... URL: From marcstober at yahoo.com Fri Aug 1 16:11:42 2003 From: marcstober at yahoo.com (Marc) Date: 1 Aug 2003 13:11:42 -0700 Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> Message-ID: In general, I suspect BASIC is more defined by compromises than Python. To me there is a compromise in Python's dependence on C. It seems that at some point I will hit a performance or feature issue that will require me to write a C extension. It seems to me VB6 has a similarly awkward relationship with C++. Clearly the creators of Python were expert C programmers; that should not be a requirement to become an expert Python programmer. - Marc From imbosol at aerojockey.com Mon Aug 11 20:57:02 2003 From: imbosol at aerojockey.com (Carl Banks) Date: Tue, 12 Aug 2003 00:57:02 GMT Subject: Fun with numbers - dammit, but I want a cast! References: <3f378fac$0$10778$afc38c87@auth.uk.news.easynet.net> <3f3792f2$0$18258$afc38c87@auth.uk.news.easynet.net> <3F38367F.9EF03CEE@alcyone.com> Message-ID: Erik Max Francis wrote: > Carl Banks wrote: > >> Certainly not. Most type casts actually change bits. > > Some casts do. Some merely invoke conversions. > >> For example, >> supposing floats and longs are both 32 bits, the expression (float)1L >> will *not* return the floating point number with the same bit pattern >> as 1L. It returns 1.0. > > But the C++ equivalent, something like (float) 1, would _not_ return the > floating point number with the same bit pattern as 1L either. It would > simply invoke the conversion from int to float. What you're talking > about would be something like *(float *) &i. It seems you didn't read what I wrote carefully. I was talking about C, not C++. Neither I nor the post I replied to mentioned C++ once. I mentioned the C standard several times, never the C++ standard. Type casts in C are as I described. -- CARL BANKS "You don't run Microsoft Windows. Microsoft Windows runs you." From borcis at users.ch Mon Aug 18 14:38:41 2003 From: borcis at users.ch (Borcis) Date: Mon, 18 Aug 2003 20:38:41 +0200 Subject: What's better about Ruby than Python? References: Message-ID: <3F411D31.4030507@users.ch> John Roth wrote: > > This is why Ruby's solution is superior: "self" is a reserved word, > and so is the special character shortcut. There is no question as > to what is meant. It eliminates essentially futile arguements in the > same way that Python's indentation eliminates arguements about > the proper placement of braces. > This sets a specific target to an obfuscated python context : Illustrate the freedom that python gives you to replace the name of "self" in methods by any identifier you want, with a piece of code designed to put the collision between class variables and the name actually used in the method source as a replacement to "self", into a functional role as a part of the main loop. Or something comparable :) From jjl at pobox.com Wed Aug 27 09:12:34 2003 From: jjl at pobox.com (John J. Lee) Date: 27 Aug 2003 14:12:34 +0100 Subject: problem installing PyQt for eric3 References: <87oeyb4iv7.fsf@voodoo.fake> Message-ID: <87n0dvtfb1.fsf@pobox.com> Lupe writes: > how could I install support for OpenGL in QT? > > Is it an add-in for QT? It's not support for OpenGL in Qt that you're missing, it's OpenGL itself (or its header files, at least). If you don't know what it is, you probably don't need it. John From markus_wankus at hotmail.com Wed Aug 6 21:55:02 2003 From: markus_wankus at hotmail.com (Markus Wankus) Date: Wed, 06 Aug 2003 21:55:02 -0400 Subject: win32, COM, and Solidworks (again) - Still Trying Message-ID: I posted a looong time ago regarding this COM stuff (see the pasted post at the end) and I am still beating my head against the wall on this. I have been trying to debug this further and I think the root of my problem lies in win32com.client.__WrapDispatch(), pasted here: def __WrapDispatch(dispatch, userName = None, resultCLSID = None, typeinfo = None, \ UnicodeToString = NeedUnicodeConversions, clsctx = pythoncom.CLSCTX_SERVER, WrapperClass = None): """ Helper function to return a makepy generated class for a CLSID if it exists, otherwise cope by using CDispatch. """ if resultCLSID is None: try: typeinfo = dispatch.GetTypeInfo() if typeinfo is not None: # Some objects return NULL, some raise exceptions... resultCLSID = str(typeinfo.GetTypeAttr()[0]) except pythoncom.com_error: pass if resultCLSID is not None: import gencache # Attempt to load generated module support # This may load the module, and make it available klass = gencache.GetClassForCLSID(resultCLSID) if klass is not None: return klass(dispatch) # Return a "dynamic" object - best we can do! if WrapperClass is None: WrapperClass = CDispatch return dynamic.Dispatch(dispatch, userName, WrapperClass, typeinfo, UnicodeToString=UnicodeToString,clsctx=clsctx) For my objects, dispatch.GetTypeInfo() causes the following exception: Traceback (most recent call last): File "F:\_DEV\solidworks\swpycom.py", line 12, in ? print sw._oleobj_.GetTypeInfo() pywintypes.com_error: (-2147467263, 'Not implemented', None, None) Hmmm...'Not Implemented'. Because this fails, I can't obtain the CLSID of itself, thus it can't use the makepy generated code to bind itself properly. I always get back dumb CDispatch objects. I have been trying to hack a way of getting the CLSID of the dispatch object, but it just isn't there. Anyway - if anyone reading this knows anything about what I am talking about, your help would be greatly appreciated. Thanks, -- Markus =============8< (old post) =============== Refer to: http://mail.python.org/pipermail/python-list/2003-May/161346.html win32com and early binding: Definitive answer? Markus Wankus markus_wankus at hotmail.com Sat, 03 May 2003 12:24:14 -0400 Hi all, I have been playing with Python and COM - attempting to talk to a 3D CAD package. I have posted on this before, and I have also had a lot of direct hints from Mark Hammond - but I am looking for a definitive answer to my problem here. I have seen other similar threads while Googling for a solution, but all of the answers were the same, with no real explanation as to why (at least nothing that I understand - being a COM newbie). Anyway - the problem is that the particular application (Solidworks) apparently refuses to use early binding. I have gone through the Python Programming on Win32 book with a fine-toothed comb but it just doesn't say anything about this sort of situation. Some code is in order: An example of early binding: import win32com.client sw = win32com.client.Dispatch('SldWorks.Application') print repr(sw) produces the output: '' OK - fine. No problem. Running makepy on the type library generates a module just fine, and it appears in the gen_py folder. So, technically this should force early binding: # Use these commands in Python code to auto generate .py support from win32com.client import gencache gencache.EnsureModule('{83A33D31-27C5-11CE-BFD4-00400513BB57}', 0, 10, 0) import win32com.client sw = win32com.client.Dispatch('SldWorks.Application') print repr(sw) which also produces the output: '' ARRGH! OK - well the file generated by makepy has the following in it: (...a whole bunch of crap...) class ISldWorks(DispatchBaseClass): """Interface for SolidWorks""" CLSID = pythoncom.MakeIID('{83A33D22-27C5-11CE-BFD4-00400513BB57}') (..various methods, etc...) And near the bottom of the file: # This CoClass is known by the name 'SldWorks.Application.10' class SldWorks(CoClassBaseClass): # A CoClass CLSID = pythoncom.MakeIID("{B49E4B36-A1A9-46A4-A738-545948A64113}") coclass_sources = [ DSldWorksEvents, ] default_source = DSldWorksEvents coclass_interfaces = [ ISldWorks, ] default_interface = ISldWorks (NOTE: 'SldWorks.Application.10' is a shortcut to 'SldWorks.Application' in the Registry. This is in case you have different versions instlled at the same time. Dispatching 'SldWorks.Application.10' produces the same results.) Various Google threads, as well as emails to me from Mark Hammond himself (which I very much appreciate - but this was awhile ago and I would like to put this to bed) has eluded to the fact that Solidworks does not implement IDispatch properly, which is the cause of my problems. I CAN get it to work by doing the following: # Use these commands in Python code to auto generate .py support from win32com.client import gencache sldmod = gencache.EnsureModule('{83A33D31-27C5-11CE-BFD4-00400513BB57}', 0, 10, 0) import win32com.client sw = win32com.client.Dispatch('SldWorks.Application') sw = sldmod.ISldWorks(sw) print repr(sw) which produces the following output: The question is this: Is there ANY way to get around this without having to do the extra step of running that object through the interface? I could live with it if it was just the main application object - but I have to do this for every single Solidworks object I want to instantiate. So if a method of the application object returns a document object for instance, I have to look into the API and find out what type of object it is *supposed* to retun, tack an "I" on the front, and run it through its interface with: newObject = sldmod.I(newObject) Which I could automate if I new the object type I was supposed to get back ahead of time - but I can't see a way to figure this out? I guess my only other option is to use something like SWIG to wrap the .dll, or ctypes or something - but that seems like so much more work! Not to mention the fact that I don't know much about them either - so it may take me forever to figure those methods out as well. Anyway, as usual - any help would be greatly appreciated. FWIW - my next step is to get a definitive book on COM (not necessarily anything to do with Python) to learn more background. Perhaps there is a way in raw COM to handle this. Also - the docs for the Solidworks API say the following (if this helps): Programmer's Guide COM vs. Dispatch SolidWorks exposes its API functionality through standard COM objects. For OLE automation, the API is exposed using IDispatch. The Dispatch interface accepts and returns arguments as Variants and IDispatch pointers so they can be handled by languages such as Basic. All Visual Basic, VBA, or VC++ executable (.exe) implementations should use the Dispatch interface. A COM implementation gives your application direct access to the underlying objects or arrays, and subsequently, increased performance. COM implementations will provide slightly more functionality, with operations such as enumeration, and will also return an HRESULT value for each API function call. The COM interface is currently only available to VC++ add-in DLL implementations. The COM interface is recommended for all VC++ add-in DLL projects. If your product will be an .exe implementation, then you are required to use the Dispatch interface since custom marshaling is not provided. Which all sounds good - but it just doesn't work. I can provide .tlb/.idl/gen_py files if anyone is really keen... Thanks ahead of time for any assistance, -- Markus From tdelaney at avaya.com Tue Aug 5 22:57:16 2003 From: tdelaney at avaya.com (Delaney, Timothy C (Timothy)) Date: Wed, 6 Aug 2003 12:57:16 +1000 Subject: converting an integer to a string Message-ID: <338366A6D2E2CA4C9DAEAE652E12A1DE959612@au3010avexu1.global.avaya.com> > From: Ken Fettig [mailto:kenfettig at btinet.net] > > I have a quick simple question. How do you convert an integer > to a string in Python? Same way you convert everything else - str(). You have read the the tutorial haven't you? Tim Delaney From jasongorman at blueyonder.co.uk Sat Aug 9 07:27:24 2003 From: jasongorman at blueyonder.co.uk (jason) Date: 9 Aug 2003 04:27:24 -0700 Subject: Free OO & UML tutorials Message-ID: <5e90cdd2.0308090327.27815766@posting.google.com> There are some great free tutorials on OOA/D, UML, Design Patterns, Test-driven Development, Usability Engineering and heaps of other good stuff at http://www.objectmonkey.com From heiko at asta.uni-saarland.de Sat Aug 16 22:05:37 2003 From: heiko at asta.uni-saarland.de (Heiko Wundram) Date: Sun, 17 Aug 2003 04:05:37 +0200 Subject: ANN: yawPyCrypto 0.1.1 Message-ID: <1061085937.868.17.camel@d168.stw.stud.uni-saarland.de> As announced earlier this week, a maintenance release for yawPyCrypto is now out, which finally adds doc-strings for all classes/methods, and which supports a new module called KeyCipher, which adds support for stream encryption using public key cryptography. The new classes have not been well tested, as I did not have the time to implement a test-suite for them yet, but I would encourage anyone out there using yawPyCrypto to upgrade anyway, and to mail me any errors they might encounter. yawPyCrypto is available at: http://yawpycrypto.sourceforge.net yawPyCrypto =========== yawPyCrypto is a wrapper for a big part of PyCrypto's cryptographic functionality, which provides a much simpler, unified interface on top of the underlying classes. yawPyCrypto aims at exposing as much of the functionality available through PyCrypto as possible, while still making it easy for the programmer to use the functionality. yawPyCrypto offers: An abstract key class which allows you not only to store and reload keys from a string (extensions to e.g. wrap data in ascii-armored format are included), but also to associate key arguments with a key. These key arguments can be any valid Python object, which is serialized and signed by the key (if the key contains a public key). An abstract cipher stream class which allows you to do stream encryption with block ciphers (or stream ciphers), hiding the underlying complexities of only being able to encrypt whole blocks. The output stream format contains information on the encrypted data (such as the encryption algorithm and chaining mode used, this should be safe to distribute), and a hash of the encrypted data (which is checked on load). yawPyCrypto streams are secured in the sense that they work around known problems with several algorithms. A high-level cipher stream class which uses public key functionality to encrypt data with a session key, which is stored in the stream. The stream layout is almost identical to a normal cipher stream. Several other wrapper classes, which are being described in the online documentation (generated by epydoc). yawPyCrypto depends on the serialization library Flatten, also available from there. yawPyCrypto has officially been marked beta as of this release (all earlier releases were marked alpha), and new version information has been introduced in all files (.p). Author: Heiko Wundram URL: http://yawpycrypto.sourceforge.net Depends: PyCrypto 1.9a6 (should run on earlier versions), Python 2.3 Runs on: Should be OS-Independent, only tested on Debian unstable. Release: 2003/08/17 (Version 0.1.1, beta) Available jobs: - Backport yawPyCrypto to earlier Python versions (I will do this, but as I use 2.3 exclusively at the moment, at some much later stage) - Correct all the stupid mistakes I have in my doc-strings - Create a full-blown test-suite for all classes From bkelley at wi.mit.edu Thu Aug 21 10:28:37 2003 From: bkelley at wi.mit.edu (Brian Kelley) Date: Thu, 21 Aug 2003 10:28:37 -0400 Subject: [OT] Why is it called string? In-Reply-To: References: <3f44ce77$0$556$b45e6eb0@senator-bedfellow.mit.edu> Message-ID: <3f44d6d5$0$571$b45e6eb0@senator-bedfellow.mit.edu> Richard Brodie wrote: > "Brian Kelley" wrote in message > news:3f44ce77$0$556$b45e6eb0 at senator-bedfellow.mit.edu... > > >>That being said, what is the programming-centric etymology of "string"? > > > The usage of string as "a sequence of similar objects", appears to be very > old. Dropping the 'character' part is probably much more recent (probably > around the classic Unix/C era: old Pascal documentation tends to say > "character string" explicitly. > Isn't this relatively unique to characters though? I haven't seen "integer string" and some old borland documentation (old memory here) that had some code to convert from a String of Integers into an Array of Byte. This usage of string specifically meant the ASCII equivalent of an integer such as: a = "1234567890" More often I have seen "Array of Integers" or "List of Integers" so the term "string" does appear to mean "human readable" or imply character based... i.e. EBDIC/ASCII or the appropriate encoding. -- Brian Kelley bkelley at wi.mit.edu Whitehead Institute for Biomedical Research 617 258-6191 From manuel at ortega.cl Fri Aug 22 02:51:57 2003 From: manuel at ortega.cl (=?ISO-8859-1?Q?Ma=F1ungo?=) Date: 21 Aug 2003 23:51:57 -0700 Subject: Match beginning of two strings References: <3f2c429e@nntp0.pdx.net> <3f2c7806.20532894@news.lexicon.net> Message-ID: <48d1f86b.0308212251.b9dcf4a@posting.google.com> "Andrew Dalke" wrote in message news:... > Ravi: > > Read in both strings. > > Check to see if the first character matches. > > If yes: > > Check halfway through the string and see if that character matches > > Repeatedly check halfway until the difference point is found. > > Go back through from the difference point backwards and make sure > > the characters match from the start to the difference point. > > > > I timed it, and it seems to be doing about 3.5usec per loop. > > There's a lot of overhead for doing that. Have you tried the simple > > char *s1 = ... the first string .. > char *s2 = ... the second string .. > n = ... the shorter of the two .. > for(i=0; i if (*s1++ != *s2++) { > break; > } > } > return ... the string s1[:n] (or even just the int) > > Easy to understand, and the CPU is spending almost its whole > time doing character tests. > > Andrew > dalke at dalkescientific.com First, I'm not a python programmer... but I think is better test int. Something like that: int *a = (int *) ...first string...; int *b = (int *) ...second string...; for( i = 0; i < n; i += 4 ) if( *a++ != *b++ ) break; char *aa = (char *) a; char *bb = (char *) b; if( *aa++ == *bb++ ) i++; if( *aa++ == *bb++ ) i++; if( *aa == *bb ) i++; and return i. From jacek.generowicz at cern.ch Tue Aug 19 10:20:30 2003 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 19 Aug 2003 16:20:30 +0200 Subject: What's better about Ruby than Python? References: <3F41505F.69D18CC8@alcyone.com> Message-ID: Roy Smith writes: > Here's a real-life example of how macros change the language. Some C++ > code that I'm working with now, has a debug macro that is used like this: > > DEBUG (cout << "I'm a debug statement\n";) > The problem is, emacs doesn't know what to do with the code above. If you think that's a problem ... I have recently seen some code where a DEBUG macro trampled all over an enum containing a DEBUG value. I'm not too worried about Emacs not knowing what to do with the code, but I get rather more upset when the compiler doesn't know what to do with the code :-) But this is all slightly off-topic. I don't think this part of the thread is about C-style macros (which are fundamentally flawed and useless <0.0001 wink>, and very boring), but Lisp-style macros, which are are to C-style macros what Emacs is to cat. From cartermark46 at ukmail.com Thu Aug 21 08:13:36 2003 From: cartermark46 at ukmail.com (Mark Carter) Date: 21 Aug 2003 05:13:36 -0700 Subject: how fast is Python? References: Message-ID: > > However, there are definitely cases where a lot of code would need to > > be optimized, and so I ask the question: How fast is Python, compared > > to say a typical optimizing C/C++ compiler? I did a benchmark some time ago (nothing optimised): PURPOSE: The purpose of this technical report is to gauge the relative speed of the languages: VB, VBA, Python 2.2, C++, and Fortran. SUMMARY RESULTS: It was discovered that uncompiled VB code in VB 6.0 ran at the same speed as VBA code in Excel. It was half the speed of compiled VB code, 5 times the speed of Python, and 1/20th the speed of C++/Fortran. METHOD: The following algorithm was implemented in each of the target languages: X = 0.5 For I = 1 to 108 X = 1 ? X* X Next Timings were made for the execution. The following results were obtained: Language Timing (seconds) VB ? uncompiled 74 VB ? compiled 37 VBA ? Excel 75 Python 401 C++ - debug version 4 C++ - release version 3 Fortran 3 The timings for Fortran are approximate. The execution time had to be timed with a stopwatch because timing functions could not be discovered. From mis6 at pitt.edu Tue Aug 26 02:39:33 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 25 Aug 2003 23:39:33 -0700 Subject: Advice to a Junior in High School? References: <3F4A9DC7.9060509@nyc.rr.com> Message-ID: <2259b0e2.0308252239.35bf1dc9@posting.google.com> Afanasiy wrote in message news:... > I think you > should do a lot of your own exploring. Consider as much as you can, no > matter what someone online says for or against it. Hear, hear: this is good advice! On a more personal note, when I was more or less your age I decided to do Physics, even if I knew very well that the job situation was a disaster. Now, it turns out that the situation is still a disaster and I have just decided to quit the field. I have found some people telling me that I made the bad choice and that I should have chosen a more marketable field. I don't think so. I did what I wanted to do: whereas most of the people do for all their life a job they dislike, I at least avoided that for part of my life. I had the opportunity of doing something and I took it. If you have the chance of having something you like to do, don't throw it away to follow the advice of the others. Your life is your responsability. Michele Simionato, Ph. D. MicheleSimionato at libero.it http://www.phyast.pitt.edu/~micheles --- Currently looking for a job --- From jjl at pobox.com Sun Aug 24 09:11:07 2003 From: jjl at pobox.com (John J. Lee) Date: 24 Aug 2003 14:11:07 +0100 Subject: macro FAQ References: <2259b0e2.0308240103.3966476b@posting.google.com> Message-ID: <87znhzi4k4.fsf@pobox.com> Jacek Generowicz writes: > mis6 at pitt.edu (Michele Simionato) writes: > > > > Can this be implemented using metaclasses, or any other existing > > > Python mechanism ? > > > > Yes. [...] > > At the end it uses metaclasses+exec+a simple argument parser based on > > tokenize. EXPERIMENTAL code, which I would not trust except as proof > > of concept. > > If it uses exec, then it is faking up macros. > > Lisp macros are little else besides offering language support for the > use of exec for this kind of thing. > > If people start resorting to this sort of trick themselves, and > re-inventing it over and over again, then you might as well design it > properly, once and for all, and call it a macro system. [...] Well, as has been repeatedly argued, that's just the point: people *don't* do that over and over again. Who uses these 'faked-up macros'? A few people who like messing around with metaclasses for fun (note Michele's warning about 'EXPERIMENTAL' and 'proof of concept'). If it's made easier, relatively sane people might do it too, and then we'll all suffer ;-) I'm sure you're capable of understanding this position, but the argument has started going round in circles. John From neel at mediapulse.com Thu Aug 21 15:51:06 2003 From: neel at mediapulse.com (Michael C. Neel) Date: Thu, 21 Aug 2003 15:51:06 -0400 Subject: tuple to string/list Message-ID: try this... for i in range(len(month)): output="Hits for %s: %d" % (month[i],teller[i]) f.write(str(output)) f.close() didn't test, may have typos... Mike > -----Original Message----- > From: WIWA [mailto:wim_wauters at skynet.be] > Sent: Thursday, August 21, 2003 3:41 PM > To: python-list at python.org > Subject: tuple to string/list > > > Hi, > > I'm a newbie learning to appreciate the strength of Python. I'm > writing an application to look at the access_log of my apache server: > > When I write: > > for i in range(len(month)): > output="Hits for",month[i], ":" , teller[i] > f.write(str(output)) > f.close() > > => this produces a tuple: > ('Hits for', 'Jan', ':', 0)('Hits for', 'Feb', ':', 2)('Hits for', > 'Mar', ':', 3) > > => whereas I would like the following output: > Hits for Jan: 0 > Hits for Feb: 2 > Hits for Mar: 3 > > Any easy way of obtaing this output? > > Thanks in advance, > > Wim > -- > http://mail.python.org/mailman/listinfo/python-list > From neil.padgen at mon.bbc.co.uk Wed Aug 13 06:51:09 2003 From: neil.padgen at mon.bbc.co.uk (Neil Padgen) Date: Wed, 13 Aug 2003 10:51:09 +0000 Subject: Multi-Line Comment References: <4qofjvg3bh9smlnb1do4f0lhjga7bacnu3@4ax.com> <200308122306.48320.shalehperry@comcast.net> Message-ID: On Wednesday 13 August 2003 07:03, Doug Tolton wrote: > Man, I wonder if I'll even learn 10% of the Emacs keystrokes. >From inside an Emacs python buffer, do M-x py-describe-mode -- Neil From skip at pobox.com Thu Aug 21 17:09:13 2003 From: skip at pobox.com (Skip Montanaro) Date: Thu, 21 Aug 2003 16:09:13 -0500 Subject: Weird Problem In-Reply-To: <84fc4588.0308211018.767fec3f@posting.google.com> References: <0HY0b.24239$Cd2.10527@nwrdny01.gnilink.net> <84fc4588.0308211018.767fec3f@posting.google.com> Message-ID: <16197.13561.490836.511288@montanaro.dyndns.org> Anand> Dont forget that 'input' is a keyword in python. Not quite. It's the name of a builtin function which almost nobody uses. Anand> It is used to accept user inputs as illustrated below. Anand> r=input("Write your name here: ") Anand> print r It is essentially raw_input() wrapped in eval(). Anand> Maybe the interpreter is getting confused with your variable Anand> and the keyword "input". Python never gets confused. It always knows what it is doing. ;-) Skip From avner at skilldesign.com Mon Aug 25 16:45:57 2003 From: avner at skilldesign.com (Avner Ben) Date: Mon, 25 Aug 2003 22:45:57 +0200 Subject: cannot make Python 2.3 work Message-ID: <3f4a67a9@news.012.net.il> I installed Python 2.3 on windows xp (uninstalling the 2.2.3 that used to be there). Python 2.3. keeps looking for "pyhton22.dll" and would not work. Any suggestions? Avner. From pydrew01 at interstice.com Fri Aug 8 12:25:13 2003 From: pydrew01 at interstice.com (Rich Drewes) Date: Fri, 08 Aug 2003 09:25:13 -0700 Subject: difference in popen() or system() in thread vs. top level Message-ID: <3F33CEE9.8050706@interstice.com> Hello, I'm having a strange problem: *certain* subprograms invoked from within python 2.2 via popen/system/spawnv don't seem to return control to python. Others return to python just fine. The invoked subprogram *does* complete, but control does not return to python. Furthermore, and this is the weird part, in python 2.2 I only see the problem when the subprogram is invoked from *within a thread*! If the same subprogram is invoked from the top level of execution, then control returns to python just fine. The problem does not exist in python 1.5.2; everything works fine there under identical conditions, both when the subprogram is invoked from the top level and also from a thread. To summarize: * problem is not seen in python 1.5.2; subprograms always return control to python * problem is not seen ever when subprogram invocation is from top level of program; only when subprogram invocation is from within a thread in python 2.2 * only certain subprograms cause a problem; unfortunately, the only program I have found that causes a problem is called mpirun (part of the MPI package), which you probably don't have, so you may not be able to reproduce the problem. I'd be inclined to say that mpirun is doing something wrong, but why does it only cause a hang when invoked from within a thread? Why does it work OK in python 1.5.2? *What* could mpirun be doing that makes it have this property in combination with being invoked from a python *thread*? (I have examined mpirun. It is a perl script and hence nearly impossible to understand :) However, it is using ssh to invoke programs on multiple nodes in a cluster and then they coordinate via MPI. When I use strace to examine the processes when things hang after being invoked from a python thread, it is waiting for an accept().) * redirection of stdio, stdin, stderr to /dev/null in the subprogram does not solve problem, reducing likelihood that issue is I/O deadlock * wrapping the subprogram in another shell does not solve the problem! Further, the environment (as shown by set) is identical when the invocation is done from the program top level and from within a thread. What else could be different in the thread's invocation of the program vs. when the program is invoked from python's top level of execution!? Could a signal (SIGCHILD?) be sent from the subprogram to the *main* python program and not the thread, and therefore getting lost? Attached below is fairly simple program that shows this problem. Unfortunately, unless you have mpirun on your system you probably won't be able to reproduce this. Thanks in advance for any help you could provide. I know this is a bit obscure. Rich ---- #!/usr/bin/python2 import os, sys, time, popen2 import threading def InvokeThread(cmd): print "invocation in thread, cmd:", cmd os.system(cmd) # the following line is never printed, even though the command we invoke # does complete: print "back from invocation in thread" sys.stdout.flush() # this command will work just fine: #cmd="/usr/bin/find /home/drewes/GArun" # this command will show the problem: cmd="/opt/mpich/myrinet/gcc/bin/mpirun -machinefile /home/drewes/machtest.mpi -np 1 /bin/ls -lat < /dev/null > /dev/null 2> /dev/null" # invoking from the main (top) thread always works: print "invocation from program top level, not in thread, cmd:", cmd os.system(cmd) print "back from normal invocation, not in thread" print "starting invocation from thread" thist=threading.Thread(target=InvokeThread, args=(cmd,)) thist.start() nl=threading.enumerate() while(len(nl) > 1): # note: the master thread (this main one) counts in the threadlist too time.sleep(1) nl=threading.enumerate() print "there are", len(nl), "threads running" # this will always print "2 threads running"; thread never terminates # since system() call in thread never returns From donn at drizzle.com Tue Aug 19 01:34:35 2003 From: donn at drizzle.com (Donn Cave) Date: Tue, 19 Aug 2003 05:34:35 -0000 Subject: Brandon's abrasive style (was Re: What's better about Ruby than Python?) References: <38ec68a6.0308172319.431a4fde@posting.google.com> Message-ID: <1061271273.817674@yasure> "Troll" is really a function of the audience. These guys will exist, there is this way of viewing the world as a dramatic contest between the armies of Python etc.: You will lose, they will eat your lunch, you're already dead and you don't know it, bla bla. But it takes an audience that finds this sort of thing in the least compelling, usually young males it seems. I don't actually see much of that in the responses, just picking a few at random. A discussion of language issues, like why Python has no macros etc., not contentious though a bit boring because it tends to be a rehash. Other than people using the newsgroup to complain about Brandon posts, Brandon's abrasive style doesn't seem to have much effect. If there's anything about c.l.p. that makes any of this disagreeable, it's the implicit awareness that someone might actually add macros, etc., to Python. This means that you can't just let people blabber on about it, stuff like that has to be nipped in the bud and all the usual arguments have to be presented every damned time the subject comes up. Or next thing you know, Guido will conduct a poll: should there be macros. Donn Cave, donn at drizzle.com From BPettersen at NAREX.com Sun Aug 3 06:58:24 2003 From: BPettersen at NAREX.com (Bjorn Pettersen) Date: Sun, 3 Aug 2003 04:58:24 -0600 Subject: memory leak? Message-ID: <60FB8BB7F0EFC7409B75EEEC13E2019202CE4819@admin56.narex.com> > From: Trevor Perrin [mailto:trevp at trevp.net] > > Every time I run the below function from the interpreter, python.exe's > memory usage increases by 5 Megs and stays at this higher level > (python 2.3b2 on WinXP). I tried to isolate this to something > simpler, but wasn't successful. > > Is this a memory leak, or is there another explanation? [...] Have your tried 2.3 final, how are you determining there is a memory leak (which tools), what steps did you take that weren't successful, did you try without using "import *", how about loading it as a module and then deleting the module (i.e. have you inadvertenly created an object that is still live)? tech-support-this-is-Bjorn'ly y'rs From andy47 at halfcooked.com Thu Aug 21 08:30:23 2003 From: andy47 at halfcooked.com (Andy Todd) Date: Thu, 21 Aug 2003 13:30:23 +0100 Subject: MySqlDB Question - CompatMySqlDB is all I can find ? In-Reply-To: <282f826a.0308210238.11ef6a97@posting.google.com> References: <282f826a.0308210238.11ef6a97@posting.google.com> Message-ID: Richard Shea wrote: > Hi - I've just downloaded mysqldb for 3.2. After running the install I > find that I can't import mysqldb. When I looked in the directory > mysqldb was installed into the only modules visible are > _mysql_exceptions.py and CompatMySqlDB.py. So i tried importing > CompatMySqlDB and that works fine ... > > >>>>import CompatMysqldb >>>>import Mysqldb > > Traceback (most recent call last): > File "", line 1, in ? > ImportError: No module named Mysqldb > > > ...trouble is I read in this group that I'm not meant to be using > CompatMysqldb so what am I doing/have done wrong ? > > I got mysqldb as a binary from ... > > http://ghaering.de/python/unsupported/MySQL-python.exe-0.9.2.win32-py2.3.exe > > ... if anyone can throw some light on this I'd be grateful. > > regards > > richard shea. Beware, but it looks like you have a typo. I'd suggest making sure you type the module name with the correct case (Python is case sensitive you know). From an interactive session on my machine; """ PythonWin 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] on win32. Portions Copyright 1994-2001 Mark Hammond (mhammond at skippinet.com.au) - see 'Help/About PythonWin' for further copyright information. >>> import Mysqldb Traceback (most recent call last): File "", line 1, in ? ImportError: No module named Mysqldb >>> import MySQLdb >>> db=MySQLdb.connect() """ Regards, Andy -- -------------------------------------------------------------------------------- From the desk of Andrew J Todd esq - http://www.halfcooked.com/ From elainejackson7355 at home.com Tue Aug 19 00:43:08 2003 From: elainejackson7355 at home.com (Elaine Jackson) Date: Tue, 19 Aug 2003 04:43:08 GMT Subject: bitwise not - not what I expected References: Message-ID: In case anybody is still following this thread, the correctness and completeness of the 'myMove' function (see below) are easy consequences of the following lemmas: 1) xor is commutative and associative 2) zero is the identity element for xor 3) every number is its own inverse wrt xor "Tim Peters" wrote in message news:mailman.1061169151.30094.python-list at python.org... | [Elaine Jackson] | > In case any fellow newbies have been following this thread, here is | > the finished Nim script. It doesn't use bit-manipulation as much as I | > thought it would. (Still, I got the basics straight. Thanks again to | > everyone who helped out!) For a readable account of the optimal | > strategy for Nim, see Hardy & Wright's "Introduction to the Theory of | > Numbers". Peace. | > | > ## NIM | > from random import random | > piles=[0,0,0] | > | > ... | > | > def yourMove(): | > magicNum=piles[0]^piles[1]^piles[2] | > if magicNum==0: | > i=indexOfMax() | > piles[i]=piles[i]-1 | > else: | > magicIndex=leftmostBitIndex(magicNum) | > targetIndex=(-1) | > for i in range(3): | > if (piles[i]>>magicIndex)%2==1: | > targetNum=piles[i] | > targetIndex=i | > break | > replacement=0 | > for i in range(magicIndex): | > magicDigit=(magicNum>>i)%2 | > targetDigit=(piles[targetIndex]>>i)%2 | > if magicDigit==1: | > replacementDigit=(magicDigit-targetDigit) | > else: | > replacementDigit=targetDigit | > replacement=replacement+replacementDigit*pow(2,i) | > newNum=targetNum-(targetNum%pow(2,magicIndex+1))+replacement | > piles[targetIndex]=newNum | > print piles | | OK, what you're trying to do is force the xor of the pile counts to 0. | There may be more than one way to do that. For example, if piles is | | [2, 6, 7] | | you can force a win by doing any of these: | | remove 1 from the 2 pile, leaving [1, 6, 7] | remove 1 from the 6 pile, leaving [2, 5, 7] | remove 3 from the 7 pile, leaving [2, 6, 4] | | because 1^6^7 == 2^5^7 == 2^6^4 == 0. Now the educational thing is | that it's possible to find all these solutions easily *without* picking | apart any bits: | | def myMove(piles): | all = 0 | for count in piles: | all ^= count | for i, count in enumerate(piles): # enumerate() new in 2.3 | all_without_count = all ^ count | if all_without_count < count: | print "leave %d in pile #%d" % (all_without_count, i) | | For example, | | >>> myMove([2, 6, 7]) | leave 1 in pile #0 | leave 5 in pile #1 | leave 4 in pile #2 | >>> | | Note that the function works for any number of piles, and doesn't care how | big each pile may be; for example, | | >>> myMove([2**50, 3**67, 5**12, 76**30]) | leave 92709463147897838211662074651978 in pile #3 | >>> 2**50 ^ 3**67 ^ 5**12 ^ 92709463147897838211662074651978 | 0L | >>> | | I think you'll enjoy figuring out why that function works; proving that it | finds all solutions is a bit delicate, but not truly hard. | | From jzgoda at gazeta.usun.pl Fri Aug 1 17:58:07 2003 From: jzgoda at gazeta.usun.pl (Jarek Zgoda) Date: Fri, 1 Aug 2003 21:58:07 +0000 (UTC) Subject: 2.3 win installer References: <7pAWa.7762$gi.4246099@news2.news.adelphia.net> Message-ID: Bob X pisze: >> Anyone having problems with the 2.3 win installer? I'm running win2k pro >> (sp4) and the installer is freezing after the initial dialogues, just as >> teh install starts. > > If you have any anti-virus going...turn it off. Oh and download it again. Does Python 2.3 have any known viral activity? -- Jarek Zgoda Registered Linux User #-1 http://www.zgoda.biz/ JID:zgoda at chrome.pl http://zgoda.jogger.pl/ From altis at semi-retired.com Tue Aug 5 11:48:24 2003 From: altis at semi-retired.com (Kevin Altis) Date: Tue, 5 Aug 2003 08:48:24 -0700 Subject: boa-constructor bug: import string References: Message-ID: Known bug in 0.2.0 but fixed in later releases. You should upgrade either from cvs or to 0.2.3 http://sourceforge.net/project/showfiles.php?group_id=1909 ka "Mark Carter" wrote in message news:d3c9c04.0308050704.5b8a500 at posting.google.com... In v0.2.0 starting boa.py produces the error message: File "C:\Python23\Lib\site-packages\wxPython\tools\boa\About.py", line 301, in write ss = string.strip(s) NameError: global name 'string' is not defined It appears that string is not imported in many modules, because fixing this gives the further error: File "C:\Python23\Lib\site-packages\wxPython\tools\boa\PropEdit\PropertyEditors.p y", line 1050, in NamePropEdit identifier = string.letters+string.digits+'_' NameError: name 'string' is not defined Can someone confirm that this is a bug? I don't want to post it to their list inadvertantly. From mike at nospam.com Sat Aug 2 15:33:07 2003 From: mike at nospam.com (Mike) Date: Sat, 2 Aug 2003 12:33:07 -0700 Subject: Python speed vs csharp References: Message-ID: <1ivz3gto4e3ty$.18j3vv8ame6w6.dlg@40tude.net> On Wed, 30 Jul 2003 23:09:22 -0700, Mike wrote: Wow. Thanks, everyone, for the suggestions. As noted in another reply, the full simulation calls the erfc function 150 milllion times, not 1.5 billion; the elapsed times are correct. There doesn't appear to be any way to use previous results in the next calculation. I'm calculating the output of a transmission line to a series of input pulses. The input pulse sequence is not repetitive, so the output doesn't asymptotically approach a final state. I had tried the erfc function in the transcendental package (I can't remember where I grabbed it from). I didn't try the scipy package, but since I already had that installed, I should have tried that first. Using psyco, the test case runs in 43 seconds. I was able to reduce that to 25 seconds using some of the improvements that Bengt Richter provided. I was able to reduce the full simulation time down to 647 seconds; I'm sure more improvements are possible, since I haven't implemented all of Bengt's improvements. Part of the problem with the full simulation is that psyco gobbles up all my available memory if I use psyco.full(), so I've been experimenting with psyco.bind(). 647 seconds is my best result so far. Psyco seems to do a good enough job of optimization that replacing lines like a1 = 0.254829542 return ( (a1 + ... with return ( (0.254829542 + ... don't result in any significant change in speed. In addition to the math.exp call, the test case called the function like the full simulation does, with a math.sqrt(c) in the call, which I replaced with sqrt = math.sqrt, then replaced the x**2 with x*x. At first glance, I didn't think there was a way to "vectorize" the simulation, but after looking at it a little more carefully, it's pretty clear that there is. At this point, I'm within a factor of 2 of the c# results, and I'm pretty much prepared to call that good enough to justify sticking with Python instead of learning and converting to c#. Thanks again, -- Mike -- From mack at incise.org Fri Aug 29 00:22:18 2003 From: mack at incise.org (mackstann) Date: Thu, 28 Aug 2003 23:22:18 -0500 Subject: Add two dicts In-Reply-To: <86ktkvkd05e88hu14hjudmfvbul7slfgkt@4ax.com> References: <86ktkvkd05e88hu14hjudmfvbul7slfgkt@4ax.com> Message-ID: <20030829042218.GF1695@incise.org> On Fri, Aug 29, 2003 at 04:11:09AM +0000, Afanasiy wrote: [ ... ] > Then I wanted to add an item to the dict vars(self), so I tried : > > vars(self)+{'x':'123','y':'345'} > > This doesn't work, perhaps because no one could decide what should happen > to keys which already exist in the dict? (I'd say throw an exception). > > Can I add two dicts in a way which is not cumbersome to the above % string > operation? Is this another case of writing my own function, or does a > builtin (or similar) already exist for this? You can use dict.update(), however, this works in place, so you'll have to do it outside of the actual string% statement. d = {"a": 1, "b": 2} d.update({'x':'123','y':'345'}) print "%(..)s %(..)d ..." % d -- m a c k s t a n n mack @ incise.org http://incise.org So, what's with this guy Gideon, anyway? And why can't he ever remember his Bible? From Stephen.Boulet at no.spam.motorola.com Fri Aug 22 10:40:47 2003 From: Stephen.Boulet at no.spam.motorola.com (Stephen Boulet) Date: Fri, 22 Aug 2003 09:40:47 -0500 Subject: Embedding a chart in excel In-Reply-To: <221d8dbe.0308212104.c4e45@posting.google.com> References: <221d8dbe.0308212104.c4e45@posting.google.com> Message-ID: Very nice. I was working on my own excel classes, but I see this does lots. Im my example, I can see from the code that arguments to the Add method aren't optional. Thanks. Maybe this should be in the python cookbook? -- Stephen srijit at yahoo.com wrote: > Hello, > Refer the following link: > http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&frame=right&th=6eaef82c8c0d9548&seekm=37ee60c8.0308202344.f470d26%40posting.google.com#link11 > > Does it help you? If it doesn't, let me know what improvements are > required. > > Regards, > Srijit > > Stephen Boulet wrote in message news:... > >>I'm having trouble scripting Excel to embed a chart from python. >> >>Say I have created a sheet object and a workbook object, "xlSheet" and >>"xlBook". >> >>Creating a chart in front of my sheet is as easy as: >> >>xlSheet.Select() >>xlChart = xlBook.Charts.Add() >> >>Now how do I tell it to go embed itself in my sheet? In VBA, it might be >>something like: >> >>xlChart.Location Where:=xlLocationAsObject, Name:=xlSheet.Name >> >>Thanks. >> >>(Is there a newsgroup/list with more of a focus on issues like this than >>c.l.py?) >> >>-- Stephen From bobo at bobo.bo Sat Aug 16 15:43:52 2003 From: bobo at bobo.bo (Bobo O) Date: Sat, 16 Aug 2003 19:43:52 GMT Subject: GUI builder for Python References: <3F3DC73C.3ADD3980@easystreet.com> Message-ID: > I'm wondoering about Visual Wx. This looks like someone put much > work into it, but I haven't been able to get it to do anything. > This is probablyt because I can't find any documentation in English > that tells how to get it to do anything. my english is bad...sorry You execute these steps in order to add project 1) file\new project select template for python gui 2) store project in the new directory 3) double click on the right panels for open file Add components: 1) Select component on the left panel 2) draw it on the form Change parent components 1) draw panels & components on the form 2) select component for change parent 3) select properties tag on the left panel 4) change parent property Notebook : 1) draw notebook & panels 2) change parent property of the panel (set notebook component like parents) ------------------------ http://visualwx.altervista.org/ nuova release 0.7 [freeware] VisualWx rad per wxwindows,c++ e python From theller at python.net Sat Aug 9 14:59:19 2003 From: theller at python.net (Thomas Heller) Date: Sat, 09 Aug 2003 20:59:19 +0200 Subject: midi with ctypes References: Message-ID: anton at vredegoor.doge.nl (Anton Vredegoor) writes: > danbmil99 at yahoo.com (dan) topposted: > >>Interesting idea, but frankly it seems like alot of extra overhead. >>Now that midipy is compiling, I'm more inclined to add features in C >>than using ctypes. > > The microsoft visual C compiler is about half a gigabyte size, the > soundfont SDK from creative labs is about 20 megabyte size, the OSC > toolkit is about 3 megabyte size, the midipy.cpp is a few kilobyte > size. > > Compare this with the ctypes solution: ctypes itself is about half a > megabyte size and the ctypesmidipy.py is taking a few kilobytes. > > From this comparison one could conclude that the overhead is largely > on the side of the current solution using C. > >>What advantages can we expect from doing it this way? > > The ctypes solution is cheaper, there are less license issues because > there are less parties involved, it's a lot less code so it's easier > to understand and maintain, programming this module in Python gives > extra flexibility, and most importantly this could be a platform > independent solution for MIDI programming. That would earn Python > extra kudos from music programmers. There may even be another advantage (in the future): the ctypes solution may be more portable. Bradley Schatz has started porting ctypes to Java, and so it seems also usable from Jython. Not to speak of pypy... Thomas From aleax at aleax.it Thu Aug 21 02:19:54 2003 From: aleax at aleax.it (Alex Martelli) Date: Thu, 21 Aug 2003 06:19:54 GMT Subject: how fast is Python? References: <3f43e5cf$0$49115$e4fe514c@news.xs4all.nl> Message-ID: Irmen de Jong wrote: > Python is fast enough for me, especially 2.3. > > Profile & code slow parts as C extensions. > Include your own assembly there if so desired. > > Investigate Psyco. There was one example on this > newsgroup that showed that Python+psyco actually > outperformed the same program in compiled C. I think (but will gladly stand corrected if I'm wrong!) that this is a misinterpretation of some code I posted -- the C code (crazily) used pow(x,2.0), the Python one (sanely) x*x -- within a complicated calculation of erf, and that one malapropism in the C code was what let psyco make faster code than C did. With C fixed to use x*x -- as any performance-aware programmer will always code -- the two ran neck to neck, no advantage to either side. Alex From skip at pobox.com Tue Aug 26 14:39:12 2003 From: skip at pobox.com (Skip Montanaro) Date: Tue, 26 Aug 2003 13:39:12 -0500 Subject: My future Python IDE article In-Reply-To: References: Message-ID: <16203.43344.356982.490950@montanaro.dyndns.org> David> So c.l.py readers... make the case for your favorite one getting David> on the list. This doesn't really count as an IDE in the usual sense, but Emacs/XEmacs with python-mode provides a fair amount of leverage to the programmer. It should probably be mentioned, if not tested. There's the pdb-track stuff which is part of python-mode, you can get help on the dotted expression under the cursor with a keystroke (C-c C-h), it colorizes, etc. You can use Emacs TAGS files to help find function/class definitions. Bicycle Repair Man is also available. It's a tool to help you refactor your code. I'm sure there's more I'm forgetting. All in one svelte editor... ;-) Skip From bkc at Murkworks.com Sun Aug 24 14:14:18 2003 From: bkc at Murkworks.com (Brad Clements) Date: Sun, 24 Aug 2003 14:14:18 -0400 Subject: py2exe service doesn't work, can't connect to service controller ? References: <3F41F576.14352.14BE73C2@localhost> Message-ID: "Thomas Heller" wrote in message news:y8xljv9e.fsf at python.net... > There may still be problems with the event log (the descriptions are not > found), but otherwise at least the py2exe sample service works > correctly. > Well, you can install, start, stop, and remove it ;-) Unfortunately, I cannot start the service, it always fails. Here's what I've tried. 1. the latest version of py2exe you just released for 2.3 Build the sample MyService on Windows 2000 SP3 I can install and remove the service ok. If I run the service, I get the same error previously reported: The description for Event ID ( 240 ) in Source ( MyService ) cannot be found. The local computer may not have the necessary registry information or message DLL files to display messages from a remote computer. The following information is part of the event: 1063, The service process could not connect to the service controller.. Also, if using MyService.exe to start the service, it reports error "997" while starting the service. I can, however, use Myservice.exe -debug and that will run the service, it does put an informational message in the event log on startup and shutdown, though as you note, it's missing the descriptor for the event message. 2. Same as above, but try it on a different windows 2000 machine. Same problem. 3. Use py2exe version 0.4.1 with Python22 Same problem as reported in 1 and 2 above. However in all cases, using Python to run MyService works ok. If you can't recreate this error, then I'll need to figure out how to make a debug version of the service, and figure out how to debug a service. How do I do that? From python at grimes.org.uk Tue Aug 12 08:27:49 2003 From: python at grimes.org.uk (Paul Grimes) Date: Tue, 12 Aug 2003 13:27:49 +0100 Subject: PYTHON AND C++ References: <3f38a42b$0$245$fa0fcedb@lovejoy.zen.co.uk> Message-ID: Gerhard H?ring wrote: > Somebody with the 1337 pseudonym "BadJake" wrote: >> Hi >> We use Phil Thompson's exellent interface genentor - SLIP > > You certainly mean SIP :) > >> You can download SLIP from Phil's web site at >> http://www.riverbank.demon.co.uk > > No, I can't. This is how the page looks like: > Phil's web site is at http://www.riverbankcomputing.co.uk/ and appears to be working at the moment. Paul From hjwidmaier at web.de Sat Aug 23 05:10:04 2003 From: hjwidmaier at web.de (Hans-Joachim Widmaier) Date: Sat, 23 Aug 2003 11:10:04 +0200 Subject: MySqlDB Question - CompatMySqlDB is all I can find ? References: <282f826a.0308210238.11ef6a97@posting.google.com> Message-ID: Am Thu, 21 Aug 2003 03:38:37 -0700 schrieb Richard Shea: >>>> import CompatMysqldb >>>> import Mysqldb > Traceback (most recent call last): > File "", line 1, in ? > ImportError: No module named Mysqldb >>>> Did you try "import MySQLdb"? Case is significant, even on Windows. I've never tried it on Windows myself, but I guess its spelled just like under Unix - where it works for me with the above spelling. Hope that helps hjw From mwh at python.net Mon Aug 18 09:36:56 2003 From: mwh at python.net (Michael Hudson) Date: Mon, 18 Aug 2003 13:36:56 GMT Subject: Py2.3: Feedback on Sets References: <%BX%a.4999$N37.3051@nwrdny02.gnilink.net> Message-ID: <7h3d6f3143s.fsf@pc150.maths.bris.ac.uk> Carl Banks writes: > Well, if overloading + and * to represent a non-field or non-ring is > misguided, then + and * for lists and strings is also misguided, > since they don't define a field or ring either. Yup! Well, *, anyway. I'd prefer a Haskell-style ++ for concatenation, but + isn't totally silly (strings and lists are monoids, at least :-). list * int, OTOH, seems a bit smelly to me (though I'm not sure what a better spelling would be...). Cheers, mwh -- ... Windows proponents tell you that it will solve things that your Unix system people keep telling you are hard. The Unix people are right: they are hard, and Windows does not solve them, ... -- Tim Bradshaw, comp.lang.lisp From uce at ftc.gov Sun Aug 24 18:55:43 2003 From: uce at ftc.gov (Gordon Airport) Date: Sun, 24 Aug 2003 18:55:43 -0400 Subject: list re-orderng headache Message-ID: I don't know why, but I am wearing myself out trying to get this to work with reasonable looking code. I need to take a list of even size (probably >= 14, but generality never hurts) and produce a code by looking at the items at odd indexes from the right half and the evens from the left. To make things worse, the left half needs to either be read from the center out or reversed later. For example from [0, 1, 2, 3, 4, 5, 6, 7. 8, 9, 10, 11, 12, 13, 14, 15] I would encode [7, 5, 3, 1] and [8, 10, 12, 14] and [0, 1, 2, 3, 4, 5, 6. 7, 8, 9, 10, 11, 12, 13] gives [5, 3, 1] and [8, 10, 12] My problem has been that with every additional 2 items you swap the odd and even at the middle of the list, so reading out from the center by two only works half the time... Maybe I want to use the extended 2.3 index slicing too much. From missive at frontiernet.net Sun Aug 24 18:47:42 2003 From: missive at frontiernet.net (Lee Harr) Date: Sun, 24 Aug 2003 22:47:42 GMT Subject: Python 2.3 problem References: <51092f25c1b12d2bedc9c63d2dfa14f3@dizum.com> Message-ID: In article <51092f25c1b12d2bedc9c63d2dfa14f3 at dizum.com>, Nomen Nescio wrote: > Hi > > When I does this like hear failre goes: > > def pinhtranh(*args, laoc_te): > phnoi_crek(args, laoc_te) > > I do "laoc_te" last praemetr name always. > This is not allowed. *args and **kwargs must come after the regular arguments. http://python.org/doc/current/tut/node6.html#SECTION006600000000000000000 From Juha.Autero at iki.fi Sat Aug 30 06:38:12 2003 From: Juha.Autero at iki.fi (Juha Autero) Date: Sat, 30 Aug 2003 13:38:12 +0300 Subject: Counsel bears (OT, Re: how fast is Python?) References: <3F44DFEB.60AB6492@engcorp.com> Message-ID: <87smnj5t2j.fsf@jautero.no-ip.org> graham__fawcett at hotmail.com (Graham Fawcett) writes: > If we each had at least /one/ wise counsel bear, then c.l.py would > certainly reap the benefits of our enhanced posts! That reminds me of a story I probably read from The Practice of Programming by Brian W. Kernighan and Rob Pike. In some university (I've forgotten the name) students doing programming exercises had to explain their problem to a teddy bear before they could talk to course staff. This was because often just explaining the problem helped you to understand the problem and then you could fix it. -- Juha Autero http://www.iki.fi/jautero/ Eschew obscurity! From maoy at REMOVE_IF_NOT_SPAM.cis.upenn.edu Thu Aug 14 16:04:20 2003 From: maoy at REMOVE_IF_NOT_SPAM.cis.upenn.edu (Yun Mao) Date: Thu, 14 Aug 2003 16:04:20 -0400 Subject: how to do tags? Message-ID: Hi, I'm using emacs now. How to run etags so that I can search into my own source code as well as those site-packages source? Thanks a million! Yun From cbuck at lantis.de Tue Aug 12 12:44:04 2003 From: cbuck at lantis.de (Christian Buck) Date: 12 Aug 2003 16:44:04 GMT Subject: matching a sentence, greedy up! References: <3F375BFB.7020601@skynet.be> Message-ID: Helmut Jarausch wrote: > Christian Buck wrote: [...] >> s = 'My text may i. E. look like this: This is the end.' >> re_satz = re.compile(r'[A-Z](?:[^\.\?\!]+|' >> r'[^a-zA-Z0-9\-_](?:[a-zA-Z0-9\-_]\.|' >> r'\d+\.|a\.[\s\-]?A\.)){3,}[\.\?\!]+(' >> r'?:(?!\s[a-z]))') >> Sentence: My text may i. >> Sentence: This is the end. >> >> Why isnt the above regexp greedier and matches the whole sentence? >> > First, you don't need to escape any characters within a character > group []. ok. > The very first part r'[A-Z](?:[^\.\?\!]+ cannot be greedier since > you exclude the '.' . So it matches upto but not including the first > dot. Now, as far as I can see, nothing else fits. right. so i could fix it by putting the [^.?!]+ at the end, so first it tries to match the given abrevations including the dot and that doesnt match it eats everything until the sentences end. I thougt A|B would match the same strings as A|B does... > So the output is > just what I expected. How do you think you can differentiate between > the end of a sentence and (the first part of) an abbreviation? I'll provide common abbrevations in the regexp, like 'a.A.' as you see above. thanks! Christian From jjl at pobox.com Sun Aug 3 19:39:59 2003 From: jjl at pobox.com (John J. Lee) Date: 04 Aug 2003 00:39:59 +0100 Subject: Problem dealing with cookies References: <7b454334.0308022035.25482d72@posting.google.com> Message-ID: <87el02ux80.fsf@pobox.com> faizan at jaredweb.com (Fazer) writes: > I have the following code: [...] > C = Cookie.SimpleCookie() > C["moo"] = "f" > C["moo"]["path"] = "/" > C["moo"]["expires"] = 60*60*60*60 > > #Print the headers > print C Here (the print statement), you're setting the client's cookie "moo" to "f", no matter what. What you wanted was to put the form's data in the cookie, if the request contains form data. > print "Content-Type: text/html\n" > > #Print starting html > print "Cookie" > > form = cgi.FieldStorage() > [...] > if C['moo'].value != "f": > print "I remember you %s" % (C["moo"].value) You're expecting C to have magically aquired a new value between the point where you set it above and this point. How is that supposed to happen? > elif form.has_key("name") and C["moo"].value == "f": > print "Thank you %s!" % (form["name"].value) > C["moo"] = form['name'].value [...] More of the same. You're setting C["moo"], but how is the client supposed to find out? SimpleCookie isn't quite that magical. :-) Remember the way all this gets executed: a request comes in, the web server picks the right CGI script based on the request URL, and your script sees the HTTP headers (including Cookie) as environment variables. You use the headers from the environment (with something like C.load(os.environ["HTTP_COOKIE"]) and forms = cgi.FieldStorage() -- both look in os.environ, one explicitly, the other not), then you output some HTTP headers and then some data (usually HTML). Request, response. You're trying to sneak several request-response cycles into one CGI execution. So, you either want a single CGI script and some kind of switch (am I looking at the first request, before the user has seen the form, or the second, with the submitted form data?), or two CGI scripts (one for the first request, one for the second with the form data -- set the form's action HTML-attribute to point to that second CGI script). Probably, you'll quickly find that life is simpler (for anything non-trivial) if you use a web programming framework. Don't be afraid of them! Albatross might be a good choice -- designed to be a small step up from CGI, and pure Python so easy to install on a server -- but there are plenty of others. In all cases, remember that you have to assume you're dealing not with a well-behaved user (no such beast) using a well-behaved browser, but an evil hacker crafting evil HTTP headers and data exactly how he wants them. John From carsten at gnocchi.dialup.fu-berlin.de Sun Aug 24 10:36:05 2003 From: carsten at gnocchi.dialup.fu-berlin.de (Carsten Schultz) Date: Sun, 24 Aug 2003 16:36:05 +0200 Subject: How do you sort a name list and list in random order? References: Message-ID: Frank & Janny Plaza: > I am trying to write a program in which the users will each enter > their names and when all names have been entered, I want to randomly > sort this list of names several times [...] > Thanks, Cisco Hi Frank, Janny or Cisco! My first idea was the following: ============== import random def shuffle(l): randomly_tagged_list = [(random.random(), x) for x in l] randomly_tagged_list.sort() return [x for (r, x) in randomly_tagged_list] t=["Anna", "Berta", "Caesar", "Doris"] print shuffle(t) print shuffle(t) print t ============== You may want to also have a look at random.shuffle, however. Greetings, Carsten -- Carsten Schultz (2:40, 33:47), FB Mathematik, FU Berlin http://carsten.fu-mathe-team.de/ PGP/GPG key on the pgp.net key servers, fingerprint on my home page. From usenet_spam at janc.invalid Sat Aug 9 21:48:27 2003 From: usenet_spam at janc.invalid (JanC) Date: Sun, 10 Aug 2003 01:48:27 GMT Subject: [Python-Dev] Slogan: Getting Rich Overnight References: Message-ID: Bill Janssen schreef: > I think I prefer > Get Rich Overnight: > > Get Python That would be a good "link banner" text too... -- JanC "Be strict when sending and tolerant when receiving." RFC 1958 - Architectural Principles of the Internet - section 3.9 From fredrik at pythonware.com Sun Aug 17 13:15:29 2003 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 17 Aug 2003 19:15:29 +0200 Subject: simple text parser? References: Message-ID: Brandon J. Van Every wrote: > Alternately, doesn't Python have some kind of automagical serialization > pack/unpack functionality? How does that work? if you don't plan to look at the files, use pickle or marshal. for details, see the documentation: http://www.python.org/doc/current/lib/module-pickle.html http://www.python.org/doc/current/lib/module-cPickle.html http://www.python.org/doc/current/lib/module-marshal.html if you prefer INI-file syntax, use the ConfigParser module: http://www.python.org/doc/current/lib/module-ConfigParser.html or relevant modules from the XML subsystem: http://www.python.org/doc/current/lib/markup.html From google at hanger.snowbird.net Sat Aug 23 04:57:33 2003 From: google at hanger.snowbird.net (Kris Caselden) Date: 23 Aug 2003 01:57:33 -0700 Subject: Reference? Message-ID: I've searched all the Python docs I could find, but I haven't seen any mention of referencing function arguments, such as you would with the & in c/c++. Is this possible in Python? From user at domain.invalid Wed Aug 20 08:38:01 2003 From: user at domain.invalid (User At Domain Dot Invalid) Date: Wed, 20 Aug 2003 14:38:01 +0200 Subject: "_pg" (Postgresql) module for win32 Message-ID: Where can I find "_pg" module for postgresql? I would prefer a module not intedend for "cygwin","mingw" or some thing similar to that. From aleax at aleax.it Sun Aug 10 18:51:38 2003 From: aleax at aleax.it (Alex Martelli) Date: Sun, 10 Aug 2003 22:51:38 GMT Subject: How to print floating point in scientific format? References: <420ced91.0308081115.7060e551@posting.google.com> <420ced91.0308101127.644f9813@posting.google.com> Message-ID: <_%zZa.37775$an6.1321077@news1.tin.it> sdhyok wrote: > As you recommend, I won't modify the default behavior of python. > But, still I need a better treatment of python on arrays. Arrays are supplied by extension modules, most popularly Numeric. If you're doing scientific computations in Python and use arrays but not Numeric (or its slated-to-be-replacement numarray, of which I don't know much yet; or the many things layered atop of and onside of Numeric, such as scipy), switch. You'll be happy you did. I've never heard a scientific programmer complain too badly about how Numeric treats arrays, whether they were coming from Fortran (the typical case), other higher-level languages, or general purpose languages not really suited for scientific computation (such as C). You seem to be focused on readable display of arrays (quite an unusual focus for scientific programming). So, worst case, it's trivial to write a general purpose function that takes an array of ANY size and rank and emits it in the way you prefer -- easier than in any other language commonly used for scientific programming. So, you don't need anything from Python -- just write that blessed function and scientifically program to your heart's content. Alex From mpeuser at web.de Thu Aug 14 02:50:39 2003 From: mpeuser at web.de (Michael Peuser) Date: Thu, 14 Aug 2003 08:50:39 +0200 Subject: Getting a data structure References: <1103_1060820563@news-server.optonline.net> Message-ID: "Mike solem" schrieb im Newsbeitrag news:1103_1060820563 at news-server.optonline.net... > > I need to pass a data structures from a C program, to a python program over RS232. > I'm not quite sure how to recreate a data structure from a string of serial data. > In C I would do it like this: (1) What do you mean by "data structure" in Python? (2) Are you fully aware of the binary/marshalled/encoded format of the RS232 string? (3) Don't forget plausibilibility checks! Depending on (2) - you might find hints in the std lib module struct - you will probably have to decode it item by item. This is very straightforward. I am not aware of any trick that could simplify it. Kindly Michael P P.S.: The C-example is no good ;-) > > ---------------------- This compiles under gcc ---------- > #include > > typedef struct{ > int a; > char b; > }myStruct; > > int main() > { > char data[]= {1,2,3,4,5,6,7,8,9}; > myStruct* s1; > > s1 = (myStruct*)&data; > printf("%x %d\n", s1->a, s1->b); > return 0; > } > -------------------------------------------- > > The 'data' array above would be a buffer which receives data from the serial link. > So the questions are, what type of python data stucture to use, and how to > initialize it from the buffer. > The struct I'm using is a lot more complex than the one I used here. It's built up of a couple > of other structs. > > Thanks > Mike > > > > > From andrew-pythonlist at puzzling.org Fri Aug 15 02:04:20 2003 From: andrew-pythonlist at puzzling.org (Andrew Bennetts) Date: Fri, 15 Aug 2003 16:04:20 +1000 Subject: dict->XML->dict? Or, passing small hashes through text? In-Reply-To: <20030815055724.GB19960@incise.org> References: <20030815042536.GA19960@incise.org> <16188.28023.216400.94715@montanaro.dyndns.org> <20030815055724.GB19960@incise.org> Message-ID: <20030815060420.GC5127@frobozz> On Fri, Aug 15, 2003 at 12:57:24AM -0500, mackstann wrote: > On Fri, Aug 15, 2003 at 12:19:51AM -0500, Skip Montanaro wrote: > > mack> I'm basically passing little messages around, which are basically > > mack> just hashes, and up until now, I was using a dict that I formatted > > mack> to/parsed from a special syntax, but I keep running into growing > > mack> pains with that. I'm using SocketServer, and each connection > > mack> sends one line of data, and then the connection is closed by the > > mack> server. > > > > Check out xmlrpclib in the Python distribution for quite awhile. It also > > interoperates with XML-RPC libraries written in other languages. > > That was something I've looked at, and honestly I need to look at it > further, but at first I was turned off because it implements its own > little server, so I'd have to gut mine. But that's not a reason to rule > it out completely. It's possible to use xmlrpclib without running its builtin server -- e.g. Twisted's XML-RPC support does this, and it's not hard. -Andrew. From pedrosch at gazeta.pl Fri Aug 15 18:49:33 2003 From: pedrosch at gazeta.pl (Drochom) Date: Sat, 16 Aug 2003 00:49:33 +0200 Subject: cPickle alternative? References: Message-ID: I forgot to explain you why i use tuples instead of lists i was squeezing a lexicon => minimalization of automaton => using a dictionary => using hashable objects =>using tuples(lists aren't hashable) Regards, Przemo Drochomirecki From avner at skilldesign.com Tue Aug 26 12:56:19 2003 From: avner at skilldesign.com (Avner Ben) Date: Tue, 26 Aug 2003 18:56:19 +0200 Subject: cannot make Python 2.3 work References: <3f4a67a9@news.012.net.il> Message-ID: <3f4b8358@news.012.net.il> "Gerhard H?ring" wrote in message news:mailman.1061883744.31168.python-list at python.org... > If you start Python 2.3 with c:\python23\python.exe (or whereever you > installed Python 2.3), you get an error message that python22.dll is not > found? If you did something different, please describe exactly what you > were doing. The error occurs (a) when I run IDLE, (b) when I run python.exe and import something. Avner. From stevewilliams at wwc.com Sun Aug 17 22:38:22 2003 From: stevewilliams at wwc.com (Steve Williams) Date: Mon, 18 Aug 2003 02:38:22 GMT Subject: Python form oriented library In-Reply-To: References: Message-ID: Caleb Land wrote: > Hello, > I'm writing a small business accounting type program where the interface > is a bunch of forms that represent tables in a database. I've written and am selling an administration system for private post-secondary vocational schools. The language is Python, the Screens are wxPython, the database is Firebird. Attached is the code for the Student ledger card screen. -------------- next part -------------- A non-text attachment was scrubbed... Name: modLedger.py Type: text/x-python Size: 5368 bytes Desc: not available URL: From cedmunds at spamless.rochester.rr.com Sat Aug 2 22:45:31 2003 From: cedmunds at spamless.rochester.rr.com (Cy Edmunds) Date: Sun, 03 Aug 2003 02:45:31 GMT Subject: Determining if a filename is greater than X characters References: <93f5c5e9.0308021815.44c57a2d@posting.google.com> Message-ID: "hokiegal99" wrote in message news:93f5c5e9.0308021815.44c57a2d at posting.google.com... > How would I determine if a filename is greater than a certain number > of characters and then truncate it to that number? For example a file > named XXXXXXXXX.txt would become XXXXXX > > fname = files > if fname[0] > 6 > print fname[0] > > Thanks!!! filename = "abcdefgh" if len(filename) > 6: filename = filename[:6] print filename abcdef -- Cy http://home.rochester.rr.com/cyhome/ From jjl at pobox.com Sat Aug 16 07:19:50 2003 From: jjl at pobox.com (John J. Lee) Date: 16 Aug 2003 12:19:50 +0100 Subject: Why doesn't __call__ lead to infinite recursion? References: <2a82921f.0308151158.b8c9154@posting.google.com> Message-ID: <87ekzldf3d.fsf@pobox.com> aahz at pythoncraft.com (Aahz) writes: [...] > you'll see __call__ there. When you do foo(), Python actually does > type(foo).__call__(foo). Because type(foo).__call__ is manipulating > foo, you don't get the circular reference. Still seems weird that type(foo).__call__.__call__ (etc.) is defined. John From ktilton at nyc.rr.com Thu Aug 21 13:40:25 2003 From: ktilton at nyc.rr.com (Kenny Tilton) Date: Thu, 21 Aug 2003 17:40:25 GMT Subject: What's better about Ruby than Python? References: <3F41505F.69D18CC8@alcyone.com> <66d7kvonvb2n0nqbqahhd5roak7ur81sob@4ax.com> <3f43ef5d_4@127.0.0.1> <3F440A35.9030602@nyc.rr.com> <4o_0b.1665$Ej6.1182@newsread4.news.pas.earthlink.net> <8D01b.1721$Ej6.702@newsread4.news.pas.earthlink.net> <3F44ED2E.9070308@nyc.rr.com> <0V61b.1900$Ej6.1012@newsread4.news.pas.earthlink.net> Message-ID: <3F4504D7.20008@nyc.rr.com> Andrew Dalke wrote: > Kenny Tilton > >>Lisp hashtables can key off any Lisp datum, but... > > > Bear with my non-existant Lisp knowledge > > Suppose the code is modified. How does the hash table > get modified to reflect the change? Written in Python, > if I have > > a = (1, 2, (3, [4, 5])) Lisp is sick. From the hyperspec on make-hash-table, the test for lookups can be "eq, eql, equal, or equalp. The default is eql." EQUAL would work for this case. EQL just looks at object identity. > > I can't hash it because someone could come by later > and do > > a[2][1].append(6) > > so the hash computation and test for equality > will give different results. > > >>The next step would >>have been to determine when the closure had best re-execute the code >>body to see if the world had changed in interesting ways, but that is a >>big step and requires dependency tracking between cells. > > > Ahhh, so the Python code was comparable in power without > using macros? No, it was completely different, as per my earlier post. What you did is what is called MEMOIZE (not part of CL, but I saw some Perl refs pop up when I googled that looking for Paul Graham's memoize code from On Lisp). My code just calculates once ever! That is why it needs me to give another talk in which I add dependency tracking and state change propagation. And even then it does not memoize, tho you have me thinking and I could certainly make that an option for Cells that need it. Kind of rare, but it would be a shiniy new bell/whistle for the package. No, to match the power of my code you need to do: (let ((b (make-instance 'box :left 10 :right (c? (* 2 (left self))))) (print (list (left b) (right b))) and see (10 20). You need to then change the source above to say (c? (* 3 (left self))) and see (10 30). It should be supported by no more than (defmodel box () (left...) (right...)) Macros are not functionality, they are about hiding the wiring/plumbing behind neat new hacks, in a way functions cannot because they jump in at compile time to expand user-supplied code into the necessary implementing constructs. > Could the same code be written in Lisp using an approach > like I did for Python? Download Paul Graham's On Lisp, he has a macro in there that hides all the plumbing you used for cacheing. :) Look for "Memoize". > How would a non-macro solution look > like? (let ((cache :unbound)) (lambda (self) (if (eq cache :unbound) (setf cache (progn (+ 10 (left self)))) cache))) > What's the advantage of the macro one over the non-macro > one? Just performance? Again, arranging it so necessary wiring is not cut and pasted all over, cluttering up the code to no good end, and forcing all the code to be revisited when the implementation changes. ie, They are just like functions, except they operate at compile time on source code. The bestest I could do without macros would be: (make-instance 'box :left (c? (lambda (self) (+ 2 (right a))) .... Where C? becomes a function which returns an instance which has a slot for the cache. But then, without macros, I have to hand-code the setters and getters on every such slot. My defmodel macro writes those accessors silently. You know, with all due respect, the question really is not if macros are useful/powerful. They are, and I think even you conceded that. Forgive me if I am mistaken. At their most powerful they expand into multiple top-level definitions and even stash info globally to assist development, such as being able to inspect the source of a closure at debug-time. They run at compile time and get a look at the source,a nd can do interesting things functions cannot. The anti-macronistas are better off with the argument, hey, if you want Lisp, use Lisp. Let's keep it simple here. the question for you all is how far you want to take Python. Since there already is a Lisp -- stable, compiled, ANSI-standardized, generational GC, etc, etc -- it would be easier to generate FFI bindings for needed C libs than to play catch up against a forty year lead. -- kenny tilton clinisys, inc http://www.tilton-technology.com/ --------------------------------------------------------------- "Career highlights? I had two. I got an intentional walk from Sandy Koufax and I got out of a rundown against the Mets." -- Bob Uecker From logistix at cathoderaymission.net Sun Aug 31 14:35:14 2003 From: logistix at cathoderaymission.net (logistix) Date: Sun, 31 Aug 2003 14:35:14 -0400 Subject: PyXR 0.9.3- Cross-Referenced HTML from Python Source Message-ID: <000001c36fee$9ee6c7d0$20bba8c0@XP> PyXR 0.9.3- Cross-Referenced HTML from Python Source PyXR generates HTML pages from python source files. It also generates cross-referenced hyperlinks and integrates with the Python Library Reference as well, which makes it distinctive from the 8 million other prettyprinters out there. It's been tested on 2.3 for Windows, OpenBSD 3.2 and RedHat 7.3. There's no reason it shouldn't work on other platforms with minor configuration. 0.9.3 is a minor release. It was primarily issued as an "official" 2.3-compatible release, although previous versions should run on 2.3 as well. Other features include: - Per-line-number hyperlinks, to make emailing source code references easier and more accurate. - Upgrade of the PyXR'ed source on my website to 2.3's standard library. A PyXR'ed version of Python 2.3's source can be viewed at: http://www.cathoderaymission.net/~logistix/PyXR/python23/src/ More information about PyXR itself is available at: http://www.cathoderaymission.net/~logistix/python/pyxr.html The package is available at: http://www.cathoderaymission.net/~logistix/python/PyXR.zip Enjoy! From igorr at ifi.uio.no Sat Aug 9 11:33:35 2003 From: igorr at ifi.uio.no (Igor V. Rafienko) Date: 09 Aug 2003 17:33:35 +0200 Subject: Python installation with a custom module search path Message-ID: Hi, I am trying to install python 2.3 and I have trouble understanding how I can make the installation look for its libraries in certain directories. Specifically, we are using epkg, thus having two directory trees -- one where the installation resides (/a/b/c/python-2.3) and one where the symlinks to various installations are (/a/bin, /a/lib, /a/man, etc. E.g. /a/bin/python would be a symlink pointing to /a/b/c/python-2.3/bin/python). I would like python to look under /a/lib/python-2.3/site-packages (which would contain links to many third-party packages), but I cannot understand how I can hardwire this during the compilation stage. I have fiddled a bit with getpath.c (PYTHONPATH macro), but alas, to no avail. I would appreciate any ideas. TIA, ivr --

From ny_r_marquez at yahoo.com Wed Aug 6 14:19:25 2003 From: ny_r_marquez at yahoo.com (R.Marquez) Date: 6 Aug 2003 11:19:25 -0700 Subject: Before I submit a bug report (Pythonwin) Message-ID: <8a27e309.0308061019.72656417@posting.google.com> I uninstalled my 2.2.2 version of Python and related packages from my XP Professional station and proceeded to upgrade to the latest and greatest: Python2.3, win32all-155.exe, etc. When I try to start the Pythonwin editor, either through its shortcut or through right clicking on an existing module, a window pops up with the message: exceptions.ImportError: No module named pywin.framework.startup After, closing the window nothing happens. I was able to start the editor by double clicking on: Python23\Lib\site-packages\Pythonwin\start_pythonwin.pyw So, I assume the problem has to do with the installation process. This is the first time I have ever had a problem with Pythonwin (the editor), so I'm a little surprised. Am I the only one having this problem? -Ruben From cnetzer at sonic.net Fri Aug 29 13:24:37 2003 From: cnetzer at sonic.net (Chad Netzer) Date: Fri, 29 Aug 2003 10:24:37 -0700 Subject: Are lists at least as efficient as dictionaries? In-Reply-To: <20030829145423.GA30577@intarweb.us> References: <781faf41.0308281604.51e48f45@posting.google.com> <20030829145423.GA30577@intarweb.us> Message-ID: <1062177877.1855.6.camel@adsl-209.204.179.133.sonic.net> On Fri, 2003-08-29 at 07:54, Jp Calderone wrote: > += could simply be syntactic sugar for a call to __add__ and then an > assignment. This would work for mutable and immutable objects. But it loses the advantage that some objects would otherwise have of being able to mutate in place, without allocating a new object (ie. very large matrix additions). -- Chad Netzer From danielk at aracnet.com Tue Aug 5 08:56:25 2003 From: danielk at aracnet.com (Daniel Klein) Date: Tue, 05 Aug 2003 05:56:25 -0700 Subject: True References: Message-ID: On Mon, 04 Aug 2003 02:13:57 GMT, Lee Harr wrote: >In article , Daniel Klein wrote: >> In Python 2.2 I use to have >> >> true = (1 == 1) >> false = not true >> >> This was at the recommendation of someone on this list some time ago. >> The reason (if I remember correctly) was that setting >> >> true = 1 >> false = 0 >> >> were not true booleans. >> >> Now the expression (1 == 1) returns 'True', and caused a bug in my > >Actually, it returns True, not 'True' > In this case, it _did_ return a literal string of 'True' cuz I was using str(true) and str(false). That was the nature of the buglet. Before str(true) would return return '1' and str(false) would return '0'. Sorry that I didn't include this bit of information in the original post :-( Dan From john at rygannon.com Thu Aug 14 04:45:21 2003 From: john at rygannon.com (BadJake) Date: Thu, 14 Aug 2003 08:45:21 GMT Subject: To all UK Python Users Message-ID: <3f3b4ba2$0$244$fa0fcedb@lovejoy.zen.co.uk> Hi I have noticed that there does not seem to be a Python User Group anywhere in the UK. Therefore, I would like to put that to rights. I am willing to donate space on one of my web servers if there is sufficient interest. If anybody is interested in joining with me to set up a UK Python User Group please contact me at john at rygannon.com Best Regards John Dean From nicodemus at globalite.com.br Wed Aug 27 17:26:55 2003 From: nicodemus at globalite.com.br (Nicodemus) Date: Wed, 27 Aug 2003 18:26:55 -0300 Subject: modifying method behaviour In-Reply-To: <840592e1.0308270822.27e34fc9@posting.google.com> References: <840592e1.0308270822.27e34fc9@posting.google.com> Message-ID: <3F4D221F.4080508@globalite.com.br> Hannu Kankaanp?? wrote: >Nicodemus wrote in message news:... > > >>Use the new descriptor protocol: >> >>class logmethod(object): >> >> def __init__(self, func): >> self.func = func >> >> def __get__(self, obj, class_): >> def logger(s, *args, **kwargs): >> result = self.func(s, *args, **kwargs) >> params = [repr(x) for x in args] >> params += ['%s=%r' % (name, value) for name, value in >>kwargs.items()] >> print 'LOG: %s(%s)' % (self.func.__name__, ', '.join(params)) >> return result >> return logger.__get__(obj) >> >> > >Actually, since we're accessing functions, not variables, >descriptors aren't useful. This would do also: > >def logmethod(func): > def logger(s, *args, **kwargs): > result = func(s, *args, **kwargs) > params = [repr(x) for x in args] > params += ['%s=%r' % (name, value) for name, value in kwargs.items()] > print 'LOG: %s(%s)' % (func.__name__, ', '.join(params)) > return result > return logger > > Actually, methods are also descriptors, so the use that I indicated is valid. But I agree that your logmethod function works, and actually it's better, since it is simpler... for this case, descriptors are really overkill. Thanks for the remainder. Regards, Nicodemus. From pinard at iro.umontreal.ca Thu Aug 14 21:32:24 2003 From: pinard at iro.umontreal.ca (Francois Pinard) Date: 14 Aug 2003 21:32:24 -0400 Subject: how to do tags? References: Message-ID: [Yun Mao] > Hi, I'm using emacs now. How to run etags so that I can search into my own > source code as well as those site-packages source? Thanks a million! Try `etags --help', and play around with the listed possibilities. Here is a fragment of a top-level Makefile of mine, where the `Echo' directory holds a Python package. This fragment builds separate `TAGS' file in those sub-directories where there are source files, then builds a small top-level `TAGS' file which purpose is to include all others. ----------------------------------------------------------------------> tags: TAGS TAGS: Echo bin html src cd Echo && find -name '*.py' | grep -v '~$$' | etags - cd bin && find -type f | grep -v '~$$' | etags - $(MAKE) -C html $@ $(MAKE) -C src $@ etags -i Echo/TAGS -i bin/TAGS -i html/TAGS -i src/TAGS ----------------------------------------------------------------------< You could use similar principles, maybe, to build separate `TAGS' files for your various site-packages source hierarchies, and for your own personal sources likely kept elsewhere. Then, small master `TAGS' files could then mix those sets you want to operate upon. Of course, once all these `TAGS' files are built and ready, you `M-x visit' at the level which is most appropriate for your needed operations. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From tebeka at cs.bgu.ac.il Mon Aug 25 00:53:43 2003 From: tebeka at cs.bgu.ac.il (Miki Tebeka) Date: 24 Aug 2003 21:53:43 -0700 Subject: Comments on my "Python Introduction" slides References: <33803989.0308240000.35b9bf1f@posting.google.com> <33803989.0308240644.3090f039@posting.google.com> <3f492761$0$49117$e4fe514c@news.xs4all.nl> Message-ID: <33803989.0308242053.a286d1d@posting.google.com> Hello Irmen, > > Should be http://www.cs.bgu.ac.il/~tebeka/pyintro.htm > > I'm sorry to say this but because the site appears to > be made in Powerpoint, and then exported to MSHTML, > it sucks in my browser (Mozilla). No cigar. Sorry. Sadly we work on MS environment... Thanks for your time. Miki From dbrown2 at yahoo.com Thu Aug 14 16:17:57 2003 From: dbrown2 at yahoo.com (dbrown2 at yahoo.com) Date: 14 Aug 2003 13:17:57 -0700 Subject: help for using msvcrt.kbhit() with Python 2.3 editors? References: Message-ID: Mark, Thanks for the repy. In followup I see that msvcrt is a dll and reads as "microsoft visual C++ run time" or something along those lines. I guess msvcrt is assuming a standard console and is somehow generating the keypress events in a stream format then? That's important to know and probably belongs in the python msvcrt module documentation for us less-sophoisticated users. I notice now it says "console I/O" in the module but I didn't distinguish between a console running python and the interactive enviroment inside the editors until now. I'm still confused as to what happens when there is no console present and you call msvcrt.kbit(). Shouldn't it produce a script runtime error? Clearly my code couldn't have worked before in Python 2.2. I can't even imagine how I could have written it originally without noticing the problem. This kind of enviroment-related issue has hit me before unfortunately. So I take it there is no cross-platform or standard way to detect a key press. How do people deal with running a simple script until the user interupts it. That's all I need. I think PythonWin has a right-click feature on its 'process' icon to stop running scripts but it would be nice to have the script be aware of the user input and close down the same way everywhere and a little more gracefully. I suppose I could look for a KeyboardInterrupt error. Is that the error I should see when a running script is aborted by the user? Mark Hammond wrote in message news:... ... > > This will not work for Windows programs. Keystrokes are delivered to > GUI programs via windows messages, not via stream type functions. Thus, > having a GUI program with no existing message loop detecting key presses > is quite difficult. > > Mark. From mauricio.inforcati at cenpra.gov.br Fri Aug 8 13:19:16 2003 From: mauricio.inforcati at cenpra.gov.br (=?iso-8859-1?Q?Maur=EDcio_Caliggiuri_Infor=E7ati?=) Date: Fri, 8 Aug 2003 14:19:16 -0300 Subject: py2exe and numarray Message-ID: <001401c35dd1$323fdce0$417290c8@cenpra.gov.br> Hi, all. I?m trying to freeze a simple python script with py2exe and it does not work. I am using numarray0.6. Can anybody help me? mauricio -------------- next part -------------- An HTML attachment was scrubbed... URL: From jjl at pobox.com Sat Aug 30 18:35:04 2003 From: jjl at pobox.com (John J. Lee) Date: 30 Aug 2003 23:35:04 +0100 Subject: Bayesian kids content filtering in Python? References: <20030828161409.V40715@onyx.ispol.com> <87n0dsqqhd.fsf@pobox.com> <8765kg6ld8.fsf@pobox.com> Message-ID: <8765kelqp3.fsf@pobox.com> Marc Wilson writes: > In comp.lang.python, jjl at pobox.com (John J. Lee) (John J. Lee) wrote in > <8765kg6ld8.fsf at pobox.com>:: [...] > |I made the details of that story up, but who cares ;-) > > If you did, it's escaped into the wild: I read the same story in New > Scientist(?) some years ago. Yeah, but the *details* are certain to be wrong. I didn't make up the *whole thing*! I saw it on some TV program years ago, IIRC. John From jdhunter at ace.bsd.uchicago.edu Sun Aug 3 14:41:41 2003 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Sun, 03 Aug 2003 13:41:41 -0500 Subject: what do people use for 2D coordinates? In-Reply-To: (aayycc88@hotmail.com's message of "1 Aug 2003 16:37:38 -0700") References: Message-ID: >>>>> "Andy" == Andy C writes: Andy> You could use tuples or complex numbers (seems like a bit of Andy> a hack). I saw somewhere it said that tuples are useful for Andy> coordinates. But I haven't found a nice way to add Andy> coordinates, since + does concatenation on tuples. If performance is not a major issue, and you want to be able to generalize to arbitrary dimension, it is rather easy to write a python class to do the work for you, implementing the special methods __add__, __iadd__, __sub__ etc class Coord: def __init__(self, tup): self.tup = tup def __add__(self, other): if len(other.tup) != len(self.tup): raise ValueError return Coord( [ x+y for x,y in zip(self.tup, other.tup)] ) def __sub__(self, other): if len(other.tup) != len(self.tup): raise ValueError return Coord( [ x-y for x,y in zip(self.tup, other.tup)] ) def __repr__(self): return str(self.tup) def __len__(self): return len(self.tup) x = Coord( (1,2) ) y = Coord( (2,3) ) print x+y print x-y x = Coord( (1,2,4,5) ) y = Coord( (2,3,6,7) ) print x+y print x-y Of course, the Numeric module does element-wise array math by default, do you might want to implement this in numeric if performance is an issue. John Hunter From mack at incise.org Thu Aug 28 14:02:31 2003 From: mack at incise.org (mackstann) Date: Thu, 28 Aug 2003 13:02:31 -0500 Subject: OT: Americans love their guns In-Reply-To: References: Message-ID: <20030828180231.GE1695@incise.org> On Thu, Aug 28, 2003 at 01:38:24PM -0400, Lulu of the Lotus-Eaters wrote: > [...] And suicides > attempted by gun succeed at a much higher rate than those done by other > means (and are much more likely to be attempted in the first place > because of the "convenience"). What's so bad about that? We already have a few billion too many humans lying around anyways. Might as well let the volunteers do their thing.. -- m a c k s t a n n mack @ incise.org http://incise.org Real Users are afraid they'll break the machine -- but they're never afraid to break your face. From larry.tami at gte.net Thu Aug 28 13:57:23 2003 From: larry.tami at gte.net (Larry) Date: Thu, 28 Aug 2003 17:57:23 GMT Subject: My future Python IDE article References: Message-ID: <7or3b.16059$Jq1.5225@nwrddc03.gnilink.net> David Mertz wrote: > Pythonistas, > > My loyal fans :-) will remember that I did a Python IDE roundup for > _Charming Python_ a couple years back. Now I have another such roundup > lined up... not the very next article, but it's there on the list. > > In the intervening years, I've hardly touched anything one might call an > IDE. I've looked at screenshots from time to time, and read various > announcements. But really I just use text editors and command lines. > > Here's the thing: I probably have room to look at about four different > tools in one article. In fact, it wouldn't be absurd to only do three. > Past that, I cannot do more than list contact information and platform > in the available words. I'm sure there are more than four IDEs that > -someone- loves to work with out there... but I need to have a cutoff. > > So c.l.py readers... make the case for your favorite one getting on the > list. I have a while to ponder the opinions advanced, should this > prompt some discussion (it may take a little while to order review > copies of commercial tools and/or get things installed). > > Yours, David... There is a brand new version of BlackAdder available from theKompany.com that is quite impressive. http://www.thekompany.com/products/blackadder/ Screenshots here.... http://www.thekompany.com/products/blackadder/screenshots.php3 From usenet at microtonal.co.uk Mon Aug 18 11:19:45 2003 From: usenet at microtonal.co.uk (Graham Breed) Date: Mon, 18 Aug 2003 16:19:45 +0100 Subject: python and symbian? In-Reply-To: References: Message-ID: PD wrote: > Hello, > I was wondering if anyone knew of any efforts to get python working > on the symbian platform? I've done a search and have turned up a > couple of links to projects on the symbian site, but these projects > appear to be long dead. This is what I have installed on my Revo: http://sourceforge.net/projects/epocpython/ and it says the project has moved here where not much is happening http://www.oflebbe.de/oflebbe/python/ Hopefully that'll work for you. There's no GUI, but it's much smaller than Java. Graham From robin at jessikat.fsnet.co.uk Fri Aug 1 05:56:02 2003 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Fri, 1 Aug 2003 10:56:02 +0100 Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> Message-ID: <23bcqKAykjK$Ewhy@jessikat.fsnet.co.uk> In article , Ian Bicking writes >And Java's JIT is based on (at least originally) work done on Self, >which had to do type inference. And actually in many circumstances Java >requires type inference, because you can substitute in an instance of a >subclass. > >Anyway, JIT is all about runtime analysis -- if you could infer types >completely before running the program, you would just put in the >optimizations statically (i.e., compiling optimizations). JIT does >those optimizations at runtime by definition. > but Java does at least require specifying every type and that must at least cut down on the amount of work required. >And Bicycle Repair Man is inspired by the Refactoring Browser, an IDE >tool based on another dynamic language (Smalltalk), not on a tool from a >static language (like Java). > > Ian I don't have any data here, but I believe Python is just a little too weakly typed for compiling to float*float type assembler efficiently. -- Robin Becker From tzot at sil-tec.gr Tue Aug 19 23:15:36 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Wed, 20 Aug 2003 06:15:36 +0300 Subject: Py2.3: Feedback on Sets References: Message-ID: <0sp5kvs37u6nm4mo5vn5ldvifd05mv0hka@4ax.com> On Tue, 12 Aug 2003 12:24:40 -0400, rumours say that Istvan Albert might have written: >Then there is the update method. It feels a little bit redundant >since there is an add() method that seems to be doing the same thing >only that add() adds only one element at a time. >Would it be possible to have add() handle all additions, iterable or >not, then scrap update() altogether. If you have a Set set, then these two are quite different: set.add("hello") set.update("hello") -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From tyler at scalegen.com Sat Aug 2 23:01:38 2003 From: tyler at scalegen.com (Tyler Eaves) Date: Sat, 02 Aug 2003 23:01:38 -0400 Subject: Python-2.3 Installation with Tk on SuSE8.2 fails References: Message-ID: On Sat, 02 Aug 2003 13:14:50 +0200, Frank Grellert wrote: > "Martin v. L?wis" wrote: > >> Could it be that you don't have the Tcl header files installed? > > > Yes, it could be, after installing the Tcl header files it worked fine! > Since Python 2.2.2 was installed by Yast2, I assumed all files necessary to > install PYthon 2.3 with Tcl/Tk where already present. > Thanks for your hint! As I believe you have just discovered the difference between build dependencies and runtime dependencies. -- Visit my blog - http://blog.scalegen.com Music, Programming, and More. From aayycc88 at hotmail.com Fri Aug 1 19:37:38 2003 From: aayycc88 at hotmail.com (Andy C) Date: 1 Aug 2003 16:37:38 -0700 Subject: what do people use for 2D coordinates? Message-ID: You could use tuples or complex numbers (seems like a bit of a hack). I saw somewhere it said that tuples are useful for coordinates. But I haven't found a nice way to add coordinates, since + does concatenation on tuples. Is there a better way than to keep writing (a[0]+b[0], a[1]+b[1]) instead of just a+b? (and 2*a instead of (2*a[0], 2*a[1]) ). I know there is this NumPy library, but that seems like overkill for what I need. I'm just doing some simple 2D drawing. I know it would be trivial to write my own Point class, but I'm just wondering what other people do. It would be nice if there was some built in module that does basic vector math. From jjl at pobox.com Wed Aug 13 06:15:49 2003 From: jjl at pobox.com (John J. Lee) Date: 13 Aug 2003 11:15:49 +0100 Subject: drop down feature References: Message-ID: <87oeytdfsa.fsf@pobox.com> "Greg Brunet" writes: [...] > And this is where, as disparagingly as people talk of VB, it does a good > job. Because it highly encourages (though can disable) static typing & > checking, it is able to know what the properties, methods, etc. are for > a variable. Certainly true. Remember, though: >>> import sets >>> s = sets.Set() >>> dir(s) ['__and__', '__as_immutable__', '__as_temporarily_immutable__', '__class__', '__cmp__', '__contains__', '__copy__', '__deepcopy__', '__delattr__', '__doc__', '__eq__', '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__iand__', '__init__', '__ior__', '__isub__', '__iter__', '__ixor__', '__le__', '__len__', '__lt__', '__module__', '__ne__', '__new__', '__or__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setstate__', '__slots__', '__str__', '__sub__', '__xor__', '_binary_sanity_check', '_compute_hash', '_data', '_repr', '_update', 'add', 'clear', 'copy', 'difference', 'difference_update', 'discard', 'intersection', 'intersection_update', 'issubset', 'issuperset', 'pop', 'remove', 'symmetric_difference', 'symmetric_difference_update', 'union', 'union_update', 'update'] >>> help(zip) etc. > Also agreed. And one other thing that I've never seen matched (even the > 1.0 version of .NET wasn't as good) is the dynamic debugger in VB6. > When I've tried to debug code in IDLE or PythonWin or Boa, I frequently > end up at layers deeper in the class hierarchy than I wish to go (I > usually want to break at my code, but end up in some of the debugger > support code & have to navigate my way up/over to do anything). Also If it doesn't annoy too many people (even if it does, actually), I'm tempted to say 'Don't do that'. Write unit tests (before the code, of course), think harder rather than debug harder, and use print statements instead. Not that I don't fall into the same traps myself, of course (and yes, debuggers can sometimes be useful)... Mind you, maybe this *is* partly sour grapes from me -- I've never really used a debugger / IDE like the one you describe, and as you say, editor (rather than interpreter) auto-completion is at least very hard to implement for Python. John From __peter__ at web.de Tue Aug 5 04:59:56 2003 From: __peter__ at web.de (Peter Otten) Date: Tue, 05 Aug 2003 10:59:56 +0200 Subject: Classes in Python References: <14dsivkn40c0grotsti39cgsrde7v03hq4@4ax.com> Message-ID: Judging from the Getting started section in http://www.equi4.com/metakit/python.html, vw[r.index] seems redundent, so import Mk4py db = Mk4py.storage("c:\\datafile.mk", 1) vw = db.view("people") for r in vw: if r.Nachname.startswith("Ge"): print r.Nachname would be the code to go with. Less code == fewer occasions for errors, and it might even run faster :-) Peter From newsgroups at jhrothjr.com Fri Aug 22 07:05:18 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Fri, 22 Aug 2003 07:05:18 -0400 Subject: Design Patterns References: <3F45F0A3.E33DEC70@hotmail.com> Message-ID: "Alan Kennedy" wrote in message news:3F45F0A3.E33DEC70 at hotmail.com... > Design Pattern Catalog wrote: > [Text of standard email removed] > > Hmm, we seem to getting a lot of "welcome subscriber" type emails to > the list at the moment, on top of all the "virus in your mail" reports > :-( > > Am I the only one who gets the feeling that some mal-adjusted person > is after going to a wide range of sites and subscribing the python > list email address to a lot of different subscription services? You may be the only one. I suspect the rest of us are simply chalking it up to the latest mass mailer worm. John Roth > > -- > alan kennedy > ----------------------------------------------------- > check http headers here: http://xhaus.com/headers > email alan: http://xhaus.com/mailto/alan From pdfernhout at kurtz-fernhout.com Fri Aug 29 12:11:51 2003 From: pdfernhout at kurtz-fernhout.com (Paul D. Fernhout) Date: Fri, 29 Aug 2003 12:11:51 -0400 Subject: Object Database (ODBMS) for Python In-Reply-To: References: <1DAECE9E8F34E04AA0E5699AF7D9FF090708D440@stpmsg00.corp.fairisaac.com> Message-ID: <3f4f7af6_3@corp.newsgroups.com> Patrick K. O'Brien wrote: > Jeremy Bowers writes: >>So why *isn't* it a transaction? Unless you have a good reason not >>to, I'd suggest automatically "coercing" that into a transaction >>instead of throwing an error. > > These are some of my reasons: 1) every transaction gets pickled and > logged before executed, so that the database can recover from a crash, > 2) most of the other cool features depend on mutations passing through > the extent manager for each class, 3) transparent transactions only > seem like a good idea, 4) security is hard to enforce without explicit > boundaries (read the Twisted docs regarding Perspective Broker), 5) > explicit is better than implicit, especially when valuable persistent > data is involved. > > [snip] > >>(I'm only really entering my maturity (IMHO) as a software engineer, >>but one of my rules of thumb for developing software for other >>people to use is that the API can ***never*** be too easy. > > If you can figure out a way to have transparent transactions, without > giving up on any ACID properties considered mandatory for a DBMS, I > would love to hear about it. Have you worked with any other object > databases? To cite: http://databases.about.com/library/weekly/aa120102a.htm "The ACID model is one of the oldest and most important concepts of database theory. It sets forward four goals that every database management system must strive to achieve: atomicity, consistency, isolation and durability. No database that fails to meet any of these four goals can be considered reliable." Well, to chime in here, in a "friendly" competition / cooperation sort of way, the Pointrel Data Repository System, http://sourceforge.net/projects/pointrel/ while not quite an object database (and admittedly its case being easier) has a simple API in the bare minimum use case (it has more complex variants). Here is an example of its use (with fragments inspired in response to an earlier c.l.p poster's use case a few days ago): from pointrel20030812 import * # add a first attendant -- uses built in unique ID function # each change will be implicitely a seperate transaction attendantID = Pointrel_generateUniqueID() Pointrel_add("congress", attendantID, 'object type', 'user') Pointrel_add("congress", attendantID, 'name', 'Sir Galahad') # add a second attendant, this time as an atomic transaction attendantID = Pointrel_generateUniqueID() Pointrel_startTransaction() Pointrel_add("congress", attendantID, 'object type', 'user') Pointrel_add("congress", attendantID, 'name', 'Brian') Pointrel_finishTransaction() In the first case, the changes are automatically made into transactions, in the second, they are lumped under the current transaction. Note that Python objects could be added to the database, as in: Pointrel_add("test", 10, ["hello", "goodbye"], MyClass) This simple API is made possible by two decisions: * to have a version of the API function set which are named as module level globals and use a hidden repository (stored in _repository) which is defaulted in various ways when needed. * to keep a flag in a repository of whether it is in a transaction or not, and if it isn't, to create a transaction on the fly (if an "implicit transactions allowed" option is set, which it is by default). A more general use of the API allowing multiple repositories to be used by one application simultaneously is: repository = PointrelDataRepositorySystem(archiveName) repository.startTransaction() repository.add(context, a, b, c) repository.add(context, d, e, f) repository.finishTransaction() The module level "Pointrel_xyz()" functions use these sorts of more general API calls behind the scenes. Granted, the Pointrel System is essentially a single user single transaction system at the core. It (in theory, subject to bugs) supports atomicity (transactions), isolation (locking) and durability (logging&recovery). It only supports consistency by how applications use transactions as opposed to explicit constraints or rules maintained by the database, so one could argue it fails the ACID test there. (Although would any typical ODBMS pass consistency without extra code support? Does PyPerSyst have this as the database level?) And the Pointrel System doesn't attempt to hook into the Python language syntax, so it's task may be much easier for PyPerSyst's goals? To be clear, I'm not holding this out as "Pointrel System great" and "PyPerSystem not so great", since obviously the two systems do different things, each have its own focus, your task is perhaps harder, I don't fully understand everything that is going on here in your design and requirements, etc. What I am trying to get at is more to challenge you (in a friendly way) to have a very simple API in a default case by throwing down a pseudo-gauntlet of a simpler system API. The Pointrel System has gone through years of permutation on the API (mainly just by me) to get to the conceptual simplicity it has. And of course, now I'm in the process of adding more complexity on top of it (but not in it) where I am running into more object persistance and interface issues (such as the ones PyPerSyst may already solve easily). So feel free to say I don't understand all the issues yet. Maybe I'll learn something. ;-) In Smalltalk, typically persistant objects may get stored and retrieved as proxies, which is made possible by overriding the basic storage and retrieval methods which are all exposed etc. Maybe Python the language could do with more hooks for persistances as a PEP? I know there are some lower level hooks for access, I'm just wondering if they are enough for what you may want to do with PyPerSyst to make an elegant API for persistant objects (perhaps better unique ID support?), where you could then just go: import persistanceSystem import * foo = MyClass() PersistanceSystem_Wrap(foo) # the following defaults to a transaction foo.x = 10 # this makes a two change transaction PersistanceSystem_StartTransaction() foo.y = 20 foo.z = 20 foo.info = "I am a 3D Point" PersistanceSystem_EndTransaction() # what happens to foo on garbage collection? It persists! ... # Other code in another program import persistanceSystem import * foo = PersistanceSystem_Query(x=10, y=20, z=30) print foo.info # prints --> "I am a 3D Point" That MyClass instance called foo and the related variable changes gets stored in an ODBMS in transactions somewhere... Then I could do the same for the Pointrel System somehow using the same simple hooks. I any case, if you can point out why such useage would be impossible using Python and some future version of PyPerSyst, we might be on to something interesting. I know in a typical Smalltalk I could easily do such a thing. But then again, in most Smalltalks, 3/4 yields a fraction (not an int, and not a float), and when 3/4 in Smalltalk is multiplied by 4/3 you get 1 back again (as an int, not a rounded float), and Python still stuggles with some basic things like this (although Python has many other good qualities that more than make up for such weaknesses). >> So, what else would you like to have in a pure-Python ODBMS? I do think PyPerSyst is a really cool concept (in memory use and disk checkpoints and a log). It reminds me a little of Gemstone (an ODBMS) for Smalltalk. By the way, if you add support for the sorts of associative tuples with the Pointrel System is based on, efficiently managed, maybe I'll consider switching to using your system, if the API is simple enough. :-) Or, perhaps there is a way the Pointrel System can be extended to support what you might want to do (in the sense of transparent interaction with Python). In its use of the pickler, the Pointrel System does not keep a list of previously pickled object, so it can't transparently pickle objects that refer to previously pickled object in the repository, so that is one way that the Pointrel system can't do what your system does at all. (I'm not sure how to do that without like PyPerSyst keeping lots of previously pickled objects in memory at once for the Pickler to work with). Also, in the Pointrel System repositories are sort of on the fly made up of an arbitrary collection of archives where archives may be added and removed dynamically, so I don't quite begin to see to handle object persistance across a repository if subobjects are stored in different archives which are dropped out of the repository. My biggest issue with OO databases (including "a Smalltalk image" for that matter) in general is that the definition of objects changes over time, and on a practical basis, it might be needed to support multiple definitions of a class with the same name simultaneously if supporting a broad range of applications and somehwo resolve version issues. The Pointrel System in itself doesn't solve that problem either, but it also doesn't have that problem built in at the core, since its main storage type is just an arbitrary binary string. I mainly added the Python object support just because "pickle" made it easy and fun to do the basics, and I thought that a limited level of transparent support might make it more appealing to Pythonistas and provide some extra easy expanability if people really wanted to easily store typed information as oposed to strings. (ALthough I think it could also bring headaches if people have PyPerSyst level expectations for object storage and retrieval when I support something more like a Newton soup entry..) By the way, I like your overview of various related ODBMS projects here: http://www.orbtech.com/wiki/PythonPersistence (maybe http://munkware.sourceforge.net/ might go there now?) and your article at: http://www-106.ibm.com/developerworks/library/l-pypers.html And I'm just starting to poke around with your PyCrust to see if it can't be used to support more Smalltalk like development of Python apps. As a hint as to what I'd like to do :-) I'm hoping to get a lot of mileage out of code like: newMethodSource = self.editText.GetValue() print newMethodSource self.expr = compile(newMethodSource, '', 'exec') exec self.expr in self.__class__.__dict__ as opposed to reloading a whole file at once -- to support incremental development on live GUIs. I just need a good way to iterate through the fields of a GUI instance to rebind action methods to newer versions. (I discovered typical Python GUI toolkits have sort of same problem as when using Smalltalk blocks for GUI action code, so when you override a boudn method the old version is hung onto by the GUI event system since a method is referenced by pointer not by name, and I don't think Python has a "instance become: otherInstance" equivalent.) If it worked out well, such a system could then leverage the Pointrel System or PyPerSyst to provide version control at a fine grained level for method function definitions. If PyPerSyst was as transparent to use as outlined above, maybe it could then be used to store and retrieve hand built GUI instances with their hand built methods (sort of like in a Squeakish Smalltalk image with Morphic, but maybe better). So anyway, yours in friendly coopetition. :-) --Paul Fernhout http://www.pointrel.org -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! -----== Over 100,000 Newsgroups - 19 Different Servers! =----- From mis6 at pitt.edu Fri Aug 1 12:15:34 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 1 Aug 2003 09:15:34 -0700 Subject: Singleton-like pattern References: Message-ID: <2259b0e2.0308010815.5dcb0b58@posting.google.com> pedro.werneck at bol.com.br (Pedro Werneck) wrote in message news:... > I need to implement an object that behaves just like imutable objects, > like int, str and tuple: if you create two objects with the same value > at the same time, you get the same object, like a singleton, but > instead of storing a unique object, store a set of objects, with no > duplicates. I don't know if this is a common pattern (and if there's a > name for it), but I remember reading something about it some time > ago... the ASPN cookbook has some similar patterns, but none works for > me... > > I know there are several ways to implement this, but I think this > metaclass approach is more elegant than using __new__ and > inheritance... at least it solves my problem (I'm working on a card > game) but I am sure that there are better ways to do it... I could not > find any other value suitable as a key and using str(args) + str(kwds) > is ugly and easy to break... > > > class MultiSingleton(type): > def __call__(cls, *args, **kwds): > cache = cls.__dict__.get('__cache__') > if cache is None: > cls.__cache__ = cache = {} > tag = str(args) + str(kwds) > if tag in cache: > return cache[tag] > obj = object.__new__(cls) > obj.__init__(*args, **kwds) > cache[tag] = obj > return obj > > > Any help will be much appreciated... thanks in advance > > Pedro Werneck "memoize" is a possible name for this. Notice that the metaclass is a bit of overkill, you may well use a simple function for this job. About the issue of finding a suitable key, in the same situation I have used the tuple (args,kw) as key. But me too I would like to ask if this is a good idea. What's the custom solution for getting a good key from a dictionary ? Michele From Kyler at news.Lairds.org Sun Aug 3 10:18:38 2003 From: Kyler at news.Lairds.org (Kyler Laird) Date: Sun, 03 Aug 2003 14:18:38 GMT Subject: Potentially important real-time on-line discussion References: Message-ID: Wojciech Kocjan writes: >Kyler Laird wrote: >> People pay (what I consider to be) lots of money for me to write software >> for them. I insist that it be open source (which makes for interesting >> contract negotiations sometimes). I would be *thrilled* if someone took >> my code and used it. My value is in providing solutions - not shielding >> intellectual property from use. >While I do agree with you, another problem is that you spent your time >and your customer paid you to do the software. No, the customer paid for me to provide a solution. I've done that. The customer is happy. Any further usefulness of the code is gravy. >Would it be fair if at this time, some other programmer took your code, >added (not replaced) him to the copyright notice, changed about 5 things >and charged the same for that? If it's allowed by the license (which we've been terribly loose about), then sure; that'd be dandy. The code is almost incidental to the solution provided. It would make me happy if the same (or slightly modified) code helps someone else solve a problem. >Note that I do not plan to release customer's application as opensource, >only parts of it. I think this is a bit better than releasing all of it, >since my company and my customer spent a lot of time on developing and >facing problems. If some other company wants to solve similar problems, >they can always come to me either writing the software, or consulting them. Even if it's open source that's likely to happen. There's a good chance that using a little of your time is going to be cheaper than hiring someone else to get started. --kyler From peter at engcorp.com Thu Aug 7 13:56:37 2003 From: peter at engcorp.com (Peter Hansen) Date: Thu, 07 Aug 2003 13:56:37 -0400 Subject: serial, parallel and USB port References: <3f284386$0$1922$626a54ce@news.free.fr> Message-ID: <3F3292D5.283374B1@engcorp.com> St?phane Nufer wrote: > > Why are there no module to access serial, parallel or USB port in python. > This could be great to build front end software to control electronic > device or even automaton in industrial process ( or maybe I should ask why > the existing third party modules such as pyserial have not been integrated > in the official release) The third party modules are relatively immature, and I believe may not yet be full-featured enough to consider for inclusion, "batteries included" or not. Nevertheless, downloading and using PySerial is very easy, so it's not really a big problem for anyone doing this to get it working. There is also the cross-platform thing to consider... -Peter From tchur at optushome.com.au Sun Aug 17 16:27:45 2003 From: tchur at optushome.com.au (Tim Churches) Date: 18 Aug 2003 06:27:45 +1000 Subject: Serious problem with Shelve In-Reply-To: <3F3FB5B9.5E49B306@yahoo.com> References: <3F3FB5B9.5E49B306@yahoo.com> Message-ID: <1061152065.1184.22.camel@emilio> On Mon, 2003-08-18 at 03:04, Rami A. Kishek wrote: > Hi - this mysterious behavior with shelve is just about to kill me. I > hope someone here can shed some light. First of all, I have this piece > of code which uses shelve to save instances of some class I define. It > works perfectly on an old machine (PII-400) running Python 2.2.1 under > RedHat Linux 8.0. When I try to run it under Python for windows ME on a > P-4 1.4 GHz, however, it keeps crashing on reading from the shelved file > the second time I try to access it. The Windows machine was originally > running python 1.5.2, so I upgraded to 2.2.3, thinking that would solve > the problem, but it didn't! In Python 2.2 or earlier, by default, shelve uses the Berkeley database 1.8 libraries, which we have found to be seriously broken on all platforms we have tried them on. Upgrading to a later version of the Berkeley libraries and using the pybsddb module fixed the mysterious, inconsistent crashes and segfaults we were seeing with shelve (and which were also driving us crazy). The easiest way to upgrade is to move to Python 2.3, which includes these later versions, but you can also easily install them under earlier version of Python (at least under 2.2). -- Tim C PGP/GnuPG Key 1024D/EAF993D0 available from keyservers everywhere or at http://members.optushome.com.au/tchur/pubkey.asc Key fingerprint = 8C22 BF76 33BA B3B5 1D5B EB37 7891 46A9 EAF9 93D0 -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 196 bytes Desc: This is a digitally signed message part URL: From ggg at zzz.it Wed Aug 6 03:53:15 2003 From: ggg at zzz.it (deelan) Date: Wed, 06 Aug 2003 09:53:15 +0200 Subject: Problem w/ IDLE on Win2000 In-Reply-To: References: Message-ID: David Lees wrote: (...) > I believe the problem is the same one previously discussed with respect > to Windows XP. IDLE can not be in a path where any of the directory > names have a space. Unfortunately, 'program files' has a space in it. some problem on my win2k server sp4. installed py2.3 into "program files", IDLE failed to start. reinstalled 2.3 into "c:\python", problem fixed. bye -- goldicus1970 AT yahoo.it http://www.deelan.com From J.Ferguson at dta.mil.nz Sun Aug 17 17:52:34 2003 From: J.Ferguson at dta.mil.nz (John A Ferguson) Date: Mon, 18 Aug 2003 09:52:34 +1200 Subject: Problem with gui_thread and SciPy ... References: Message-ID: <3f400088$1@news.orcon.net.nz> Try: >>> import gui_thread >>> gui_thread.start() You should get: >>> "jose flanigan" wrote in message news:c6f263dc.0308161315.7dfa79c3 at posting.google.com... > Hi, > > I am running python version 2.2 on a Windows NT machine. I have > installed the latest version of wxPython and SciPy. However, when > running pythonwin and attempting > > >> import gui_thread > > I never get an acknowledgment that this module has been successfully > imported. When I try to plot anything using SciPy's plt function, the > pythonwin session shuts down without warning. > > Any help appreciated. > > Thanks in advance. From roy at panix.com Sat Aug 23 13:16:47 2003 From: roy at panix.com (Roy Smith) Date: Sat, 23 Aug 2003 13:16:47 -0400 Subject: Modifying the {} and [] tokens References: <04cekv0s6ghjtuhl5j2gph7ltobdb5rsam@4ax.com> <62rekv0k4ucgrh46lkp27klq13pq8ppp5p@4ax.com> <1h3fkvg8mkeq69a8hriojugqfcp75hafjj@4ax.com> <5l7fkvsd2lor14s7s0avra2553nfhe3net@4ax.com> Message-ID: Geoff Howland wrote: > As it stands now, everyone has to do this every time, I suppose that's true. On the other hand, I can't remember the last time I ever wanted to add two dictionaries. From grante at visi.com Wed Aug 13 11:16:11 2003 From: grante at visi.com (Grant Edwards) Date: 13 Aug 2003 15:16:11 GMT Subject: Serial port number limitations? References: Message-ID: <3f3a563b$0$160$a1866201@newsreader.visi.com> In article , M.Williams at EU.HNS.COM wrote: > Can anyone tell me if there is a limit on the port number (PC > COM port under windows) that Python recognises? Not that I'm aware of. I've used it with up to 128 serial ports. > I have developed and tested a simple aplication to 'ping' > itself (using a loop-back connector) which works perfectly OK > on normal PC ports, but fails abysmally on 16 port interface. Can you elaborate on "fails abysmally"? > Alternatively, perhaps it expects HEX? Not sure what you're asking. What's "it" and what do you mean by "HEX"? > I have found no clues in Serial.py I've always used the straight Win32 calls, but other's I've talked to have used Serial.py w/o problems. [ditch the HTML stuff, please] > --=_alternative 004D621D80256D81_=-- -- Grant Edwards grante Yow! Join the PLUMBER'S at UNION!! visi.com From mis6 at pitt.edu Mon Aug 11 08:33:38 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 11 Aug 2003 05:33:38 -0700 Subject: Python vs. C# References: <2259b0e2.0308100616.55b651ca@posting.google.com> <3f36af20@shknews01> Message-ID: <2259b0e2.0308110433.204d7831@posting.google.com> "Brandon J. Van Every" wrote in message news:<3f36af20 at shknews01>... > I'm beginning to think that within 5 years, no new applications will be > written in C++. ?? Are you joking or what ?? Did you learn anything from Fortran lesson? Or from Lisp? Programming languages *never* die! > Python? What industrial entity > is going to champion Python? It takes a Sun, a Microsoft, or overwhelming > utility to push a language. You said it well: to "push" a language. Python relies on his own strenght only. No help from anybody. Nevertheless, it is still there after 13 years. You should think about it. And I don't see why it should not have a future longer than C#. It is just a matter of patience: let us wait and see ;) M.S. From max at nospam.com Fri Aug 1 17:15:39 2003 From: max at nospam.com (max) Date: Fri, 01 Aug 2003 21:15:39 GMT Subject: win32serviceutil.ServiceFramework options? Message-ID: <%LAWa.52662$On.7421180@twister.nyc.rr.com> I am building a service based on win32serviceutil.ServiceFramework. By default it comes out as 'manual start' service. How do I get it to start automatically? thanks, max. From maxx at easynews.com Thu Aug 28 15:46:57 2003 From: maxx at easynews.com (maxx at easynews.com) Date: Thu, 28 Aug 2003 19:46:57 GMT Subject: OT: Americans love their guns References: Message-ID: On Thu, 28 Aug 2003 02:12:34 -0400, Lulu of the Lotus-Eaters wrote: >USA gun-related deaths are ~29k/year And my probability of being one of them is pretty low - because I am usually armed ;) From achrist at easystreet.com Mon Aug 4 19:18:31 2003 From: achrist at easystreet.com (achrist at easystreet.com) Date: Mon, 04 Aug 2003 16:18:31 -0700 Subject: PyChecker work with Python 2.3? References: <3F2C5300.FA223CBA@easystreet.com> <3F2EB773.4895B5DD@easystreet.com> Message-ID: <3F2EE9C7.A38F7912@easystreet.com> Skip Montanaro wrote: > > Al> The only change required in my sources is evidently that the csv > Al> module no longer has a parser(); it's a reader(aFile). > > Sounds like you were using a different csv file reader/writer, > perhaps Object Craft's. The csv module which is part of 2.3 is a > new module in the core. It has a different interface than Object > Craft's csv module. I knew that was coming, and I hoped it would be compatible. It isn't, but it's close enough that I just had to change about 5 lines and cut out about ten to switch from one API to the other. I didn't have to change anything else. I guess that I'm still ok importing generators from the future even though they are no longer in the future. This moving from one release to the next is really very nice and easy. With other tools and languages, you have to wait for all the third-party vendors to upgrade their packages, then see what works and what doesn't. All the 3rd party packages for python that I was relying on under 2.2 were available for 2.3 the day that 2.3 went final. Al From graham at rockcons.co.uk Mon Aug 11 08:58:26 2003 From: graham at rockcons.co.uk (Graham Nicholls) Date: Mon, 11 Aug 2003 13:58:26 +0100 Subject: Fun with numbers - dammit, but I want a cast! References: <3f378fac$0$10778$afc38c87@auth.uk.news.easynet.net> Message-ID: <3f3792f2$0$18258$afc38c87@auth.uk.news.easynet.net> Charl P. Botha wrote: > In article <3f378fac$0$10778$afc38c87 at auth.uk.news.easynet.net>, > Graham Nicholls wrote: >> then I'm trying to use those sizes to scale the image, but because >> python has decided that they are integers, I keep getting division by >> zero errors >> >> eg >> xscale=xframe/img_x >> >> where xframe will be say 300, and img_x will be 1800 >> xscale has the value 0. > > Have you tried doing it this way: > xscale = xframe / float(img_x) Thats what I wanted to do, but was sure I'd read that python didn't have casts, and that _looks_ like a cast to me! Thanks Graham > -- Graham Nicholls Rock Computer Consultancy From sjmachin at lexicon.net Thu Aug 7 18:37:58 2003 From: sjmachin at lexicon.net (John Machin) Date: 7 Aug 2003 15:37:58 -0700 Subject: round(22.47,2) gives 22.469999999999999? References: <3f30e294$0$125$e4fe514c@dreader5.news.xs4all.nl> <6qn0elr99k.fsf@salmakis.intevation.de> Message-ID: Bernhard Herzog wrote in message news:<6qn0elr99k.fsf at salmakis.intevation.de>... > sjmachin at lexicon.net (John Machin) writes: > > >> Wouldn't > >> > >> int(22.47 + .5) > >> > >> get you to where you want to go? > > > > Sure would, if 22 was where you wanted to go. > > Even if he would want to round to an int, using int(x + 0.5) would fail > for negative values: > > >>> int(-1.9 + 0.5) > -1 > > but > > >>> round(-1.9) > -2.0 > > > Bernhard "Fail" depends on your/his definition of "round to an int" -- up? down? towards zero? away from zero? closest in either direction [ties broken how?]? From tzot at sil-tec.gr Mon Aug 4 11:42:25 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Mon, 04 Aug 2003 18:42:25 +0300 Subject: anti-aliased 2D vector graphics References: Message-ID: On Sat, 02 Aug 2003 01:43:50 GMT, rumours say that "Andy C" might have written: [SNIP: My suggesting double size images and then resizing] >Thanks for the suggestion, I think this will work fine for what I'm doing. >A little off topic, but is this how it is typically done? Is there a >special case for lines vs. fonts? Font size should be doubled. For lines, you *need* from 2 to 3 lines, but that involves some math.atan2 style pre-calculations... (you can follow the easy way and draw four lines as in the next paragraph. For boxes, lines etc you better draw each 4 times (x+0, y+0), (x+0, y+1), (x+1, y+0), (x+1, y+1) -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From cartermark46 at ukmail.com Mon Aug 25 11:08:15 2003 From: cartermark46 at ukmail.com (Mark Carter) Date: 25 Aug 2003 08:08:15 -0700 Subject: ClientCookie bug (followup) References: <87fzk4sav2.fsf@pobox.com> <87znibzrnx.fsf@pobox.com> <87oeypdh92.fsf@pobox.com> <87k79a25pi.fsf@pobox.com> <87isos0zng.fsf@pobox.com> Message-ID: jjl at pobox.com (John J. Lee) wrote in message news:<87isos0zng.fsf at pobox.com>... > cartermark46 at ukmail.com (Mark Carter) writes: > > > > No really, I wasn't joking: you *never* need to use add_cookie_header > > > / extract_cookies if you're using urllib2 (at least, I can't think of > > > any possible reason to do so). It can only break things. > > > > I must admit that I don't really know what I am doing. How would you > > simplify the following code: > [...] > > It doesn't tend to encourage people to help you if you don't even > *try* to apply their advice, and just expect them to do all your work > for you. Read that paragraph you quoted (and the rest I posted in > that message and previously), try doing what it suggests, then come > back here if you need to. I've looked again, and add_cookie_header() definitely(!) is required for the following code to work: def go10(): #works with win xp import ClientCookie c = ClientCookie.MSIECookieJar(delayload=1) c.load_from_registry(username='mcarter') #only need username for win9x import urllib2 url = 'http://businessplus.hemscott.net/corp/crp03733.htm' request = urllib2.Request(url) response = urllib2.urlopen(request) request2 = urllib2.Request(url) c.add_cookie_header(request2) response2 = urllib2.urlopen(request2) print response2.geturl() print response2.info() # headers for line in response2.readlines(): # body print line If I take out add_cookie_header(), then the wrong page (i.e. the registration page) is returned. I will investigate further and let you know what I find. From nobody at dizum.com Sun Aug 24 16:00:01 2003 From: nobody at dizum.com (Nomen Nescio) Date: Sun, 24 Aug 2003 22:00:01 +0200 (CEST) Subject: Python 2.3 problem Message-ID: <51092f25c1b12d2bedc9c63d2dfa14f3@dizum.com> Hi When I does this like hear failre goes: def pinhtranh(*args, laoc_te): phnoi_crek(args, laoc_te) I do "laoc_te" last praemetr name always. Qinh From skip at pobox.com Mon Aug 18 15:46:10 2003 From: skip at pobox.com (Skip Montanaro) Date: Mon, 18 Aug 2003 14:46:10 -0500 Subject: What's TOTALLY COMPELLING about Ruby over Python? In-Reply-To: References: Message-ID: <16193.11522.6386.14679@montanaro.dyndns.org> Brandon> I'm realizing I didn't frame my question well. What's Brandon> ***TOTALLY COMPELLING*** about Ruby over Python? What makes Brandon> you jump up in your chair and scream "Wow! Ruby has *that*? Brandon> That is SO FRICKIN' COOL!!! ***MAN*** that would save me a Brandon> buttload of work and make my life sooooo much easier!" Apparently, not much in this crowd, otherwise most of us would have switched to Ruby by now. Try asking the Ruby folks. They will probably be able to come up with some answers for you. Skip From max at alcyone.com Tue Aug 12 03:34:31 2003 From: max at alcyone.com (Erik Max Francis) Date: Tue, 12 Aug 2003 00:34:31 -0700 Subject: Is Python your only programming language? References: Message-ID: <3F389887.F7AB871E@alcyone.com> Joe Cheng wrote: > I want to ask you hard-core c.l.p Pythonistas: Do you use Python for > everything? (and I'm counting Python + C extensions as just Python) > Or do > you keep another language equally close at hand, and if so, what is > it? And > finally, do you foresee a day when Python can be, for all practical > intents > and purposes, your only programming language? I get paid to write C++ or C, use Python for recreational projects, and use shell, Python, or (rarely) Perl for administration tasks. For recreation and exploration I play around with a variety of other languages, including Io, APL/J, Logo, Prolog, Scheme, and so on. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ I will always remember / This moment \__/ Sade From pruebauno at latinmail.com Sun Aug 24 18:50:51 2003 From: pruebauno at latinmail.com (nnes) Date: 24 Aug 2003 15:50:51 -0700 Subject: python gripes survey References: <7s6gkv031b940dsc522pbh5g30q4nj5vd1@4ax.com> Message-ID: Geoff Howland wrote in message news:<7s6gkv031b940dsc522pbh5g30q4nj5vd1 at 4ax.com>... > On Sat, 23 Aug 2003 15:39:27 GMT, "Ryan Lowe" > wrote: > > Just to point some things out since I started the {} [] thread. I was > trying to do something hacky, and while I wanted the [].len() type > calls for my team mates, I never had a problem with the current len() > and understand the reasoning behind it. [].len() is more uniform, but > it also changes the requirements for the language in a duplicated > fashion, since the test for __len__() will always exist as well. > > So while I think they may have been reasonable requests, Im not sure > theyre really pitfalls, and Im not sure they would even work out that > well on a large scale which is why I wanted to implement it and test > it out myself. > > > -Geoff Howland > http://ludumdare.com/ Can you post a link to that thread? I have never understood why python has [].count() or "".count() but len([]) and len(""). Why not make len, sum, str, repr, etc just methods of the base object class with specific implementations for different types. Instead of doing len([]) we could do [].len(). This is actually possible already in part. I think you can do [].__len__(). But I never understood the reasoning behind making these special __x__() methods instead of doing a plain x() and using it like obj.x(). The only case I can think of, where it would look kind of odd would be floating points like: niceoutput=2.3.str() Anyway since Pythonistas are smart, it can not be a wart of the language and must be some lack in my understanding :) awaiting-to-be-enlightened-yours Nestor From vze4rx4y at verizon.net Sat Aug 16 17:33:54 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Sat, 16 Aug 2003 21:33:54 GMT Subject: ``Type-checking'' with dir() References: <70df36e9.0308161136.3c414a80@posting.google.com> Message-ID: <6rx%a.547$Ck2.471@nwrdny03.gnilink.net> "Harry Pehkonen" wrote in message news:70df36e9.0308161136.3c414a80 at posting.google.com... > In order to leave my classes open to receiving objects that are > string-like, list-like, dictionary-like, etc, and not necessarily > _exactly_ the built-in string, list, dictionary, etc types, I have the > desire to just check if the necessary methods exist. Instead of: > > if type(a) == type(""): > ... > > . . . I like: > > wanted_methods = ["__getslice__", "__len__"] > if len([ m > for m in dir(a) > if m in wanted_methods ]) == len(wanted_methods): > ... > > In the above example, I might want to get a slice of variable a if > it's length is appropriate. The above code is a simplified in-line > version of, say, has_methods(). Any thoughts? The code becomes especially clean if you use the sets module: if not Set(["__getslice__", "__len__"]) < Set(dir(a)): raise InterfaceError(a) Raymond Hettinger From aleax at aleax.it Mon Aug 4 18:27:43 2003 From: aleax at aleax.it (Alex Martelli) Date: Mon, 04 Aug 2003 22:27:43 GMT Subject: Match beginning of two strings References: Message-ID: Richie Hindle wrote: ... > output leads you to: you can use strlen rather than Python's len: ...IF somebody absolutely ensures you that the Python strings contain no nulls. I do not recall any such guarantee in the original thread, therefore it does not seem to me that this optimization is warranted. > Over ten times quicker than the original, for the sake of a couple of > small tweaks driven by looking at the C output. Although the C still > looks very verbose at first glance, it's now substantially the same as > Alex's cexa.c. Impressive! But IMHO a way must be found to use the actual lengths of the Python strings, as cexa.c did, rather than assuming that the Python strings contain no nulls. Perhaps this can be done by direct use of PyString_AsStringAndSize? Alex From jafo-pythonlist at tummy.com Thu Aug 14 20:13:01 2003 From: jafo-pythonlist at tummy.com (Sean Reifschneider) Date: Thu, 14 Aug 2003 18:13:01 -0600 Subject: 2.3 RPMs Message-ID: <20030815001301.GA30120@tummy.com> I've just uploaded a set of pydotorg RPMs for the 2.3 release. You can find them off the 2.3 RPMs page: http://python.org/2.3/rpms.html Let me know if there are any problems. Sean -- His thoughts tumbled in his head, making and breaking alliances like underpants in a dryer without Cling Free. Sean Reifschneider, Member of Technical Staff tummy.com, ltd. - Linux Consulting since 1995. Qmail, Python, SysAdmin From gregbrunet at NOSPAMsempersoft.com Sat Aug 30 02:36:08 2003 From: gregbrunet at NOSPAMsempersoft.com (Greg Brunet) Date: Sat, 30 Aug 2003 01:36:08 -0500 Subject: Add two dicts References: <86ktkvkd05e88hu14hjudmfvbul7slfgkt@4ax.com> <3F4EDF7A.C9CF6DA3@alcyone.com> <0mrtkv8b1bnnk1v310kf3b8tmjo8d9higo@4ax.com> Message-ID: "Greg Brunet" wrote in message news:vl0gbotgl3sibf at corp.supernews.com... > But what about something like this: > > >>> class xdict(dict): > ... def __add__(self,dict2): > ... result = self.copy() > ... result = result.update(dict2) > ... > > I was hoping that would allow: > >>> a=xdict({'y': 456, 'x': 111}) > >>> b=xdict({'y': 444, 'z': 789}) > >>> a+b > > but instead of the result which I hoped for, I get the following: > > Traceback (most recent call last): > File "", line 1, in ? > TypeError: unsupported operand type(s) for +: 'xdict' and 'xdict' > > So I can't implement '+' operator for dictionaries - why not? Ooops - that should have been: return result.update(dict2) in the last line, but still, shouldn't that have mapped the "+" operator for xdict objects? -- Greg From aahz at pythoncraft.com Tue Aug 12 22:55:45 2003 From: aahz at pythoncraft.com (Aahz) Date: 12 Aug 2003 22:55:45 -0400 Subject: How to make tree of dictionaries? References: <87fzk6tuoq.fsf@big.terem> Message-ID: In article <87fzk6tuoq.fsf at big.terem>, Vlad Sirenko wrote: >I need: >dict = {2002 : {'Jan': {1 : 'num1', 2: 'num2', 3 : 'num3'}, > {'Feb': {1 : 'num4', 2: 'num5', 3 : 'num6'} } } > 2003 : {'Jan': {1 : 'num7', 2: 'num8', 3 : 'num9'} } } > >How to do it programmatically? >In Perl I would do something like: > >while ($line = <>) { > if ($line =~ /^---\s+\w+\s+(\w+)\s+(\d*)\s+(\d+):(\d+):(\d+)\s+(\d+)\s+---$/) { > ($month,$date,$hour,$minute,$sec,$year) = ($1,$2,$3,$4,$5,$6); > $statistics->{$year}->{$month}->{$date} += $sec; > } >} > >But how to do it in Python without catching 'KeyError' exception or >iterating over some nested loops. How to do it elegantly? You don't need nested loops, but you do need multiple statements: tmp_year = stats.setdefault(year, {}) tmp_month = tmp_year.setdefault(month, {}) tmp_month[date] = tmp_month.setdefault(date, 0) + sec -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From sismex01 at hebmex.com Mon Aug 11 12:20:39 2003 From: sismex01 at hebmex.com (sismex01 at hebmex.com) Date: Mon, 11 Aug 2003 11:20:39 -0500 Subject: proper loop syntax? Message-ID: heh heh :-) Congratulations on picking python, you'll have lotsa hours of pure python programming penjoyment (ok, so I dont have impeccable spelling) ;-) Anyway. What we have here, is the need of more data-oriented coding, and not necessarily a lot of chained if-elif-elif... statements. > mask = "XXNNxxASSs" > > for t in range(licenses): ? # licenses = 5 > > ?for y in mask: > ? ? ?if y == "x": > ? ? ? ? ?if t == 0: > ? ? ? ? ? ?license_char = "5" > ? ? ? ? ?elif t == 1: > ? ? ? ? ? ?license_char = "P" .... > ? ? ?elif y == "a" or "S": > ? ? ? ? if t == 0: > ? ? ? ? ? ?license_char = "T" > ? ? ? ? elif t == 1: > ? ? ? ? ? ?license_char = " " .... > ? ? ?elif y == "X" or "s": > ? ? ? ? if t == 0: > ? ? ? ? ? ?license_char = "7" > ? ? ? ? elif t == 1: > ? ? ? ? ? ?license_char = "G" .... > ? ? ?license = license + license_char So, you?re only testing a few variables: "y" and "t", and they have pre-known values in each case, and also, it?s a simple translation. You can create a dictionary-of-lists which will do all of the decision's regarding the selection of license_char without the if?s. Something like: MAIN = {} MAIN["x"] = [ "5", "P", ... ] MAIN["a"] = [ "T", " ", ... ] MAIN["S"] = MAIN["a"] MAIN["X"] = [ "7", "G", ... ] MAIN["s"] = MAIN["X"] So, in this "pseudo-matrix", all decisions are already taken, there?s no need to be iffing around with fixed values and translations; this is data-oriented programming. Now your loop becomes: for t in range(licenses): license = "" for y in mask: license = license + MAIN[y][t] print license As to why if-elif-elif... doesn?t perform as we think it does, I?ve never had to investigate it. So much decisions sometimes means that the algorith must be rethought into a better one. HTH! -gustavo Advertencia:La informacion contenida en este mensaje es confidencial y restringida, por lo tanto esta destinada unicamente para el uso de la persona arriba indicada, se le notifica que esta prohibida la difusion de este mensaje. Si ha recibido este mensaje por error, o si hay problemas en la transmision, favor de comunicarse con el remitente. Gracias. From aahz at pythoncraft.com Sat Aug 16 14:04:01 2003 From: aahz at pythoncraft.com (Aahz) Date: 16 Aug 2003 14:04:01 -0400 Subject: Why doesn't __call__ lead to infinite recursion? References: <2a82921f.0308151158.b8c9154@posting.google.com> Message-ID: In article , Andrew Dalke wrote: > > [...] No time to investigate further, but all your examples used classic classes instead of new-style classes; I'm pretty sure that new-style classes will more closely emulate the way functions work. There's also the wrinkle I didn't mention that functions use a dict proxy IIRC. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From trevp at trevp.net Sun Aug 3 02:37:10 2003 From: trevp at trevp.net (Trevor Perrin) Date: 2 Aug 2003 23:37:10 -0700 Subject: memory leak? Message-ID: <47e891f1.0308022237.5a61f33f@posting.google.com> Every time I run the below function from the interpreter, python.exe's memory usage increases by 5 Megs and stays at this higher level (python 2.3b2 on WinXP). I tried to isolate this to something simpler, but wasn't successful. Is this a memory leak, or is there another explanation? from array import * import random def test(): for x in range(10000): b = array('B', [random.randrange(0,256) for count in range(64)]) Trevor From aahz at pythoncraft.com Sat Aug 2 09:29:25 2003 From: aahz at pythoncraft.com (Aahz) Date: 2 Aug 2003 09:29:25 -0400 Subject: 'long int too large to convert to int' in 'garbage collection' ignored References: Message-ID: In article , John Machin wrote: >"Peter Kwan" wrote in message news:... >> >> I believe I have discovered a bug in Python 2.3. > >This is consistent with most developer's belief systems, which include >code similar to: > >blame_list = ["God", "Bill Gates", "Intel", "software supplier", "team >mate", "self"] > >and need application of the .reverse() method. Possibly. OTOH, I have in the past discovered a real bug in MS SQL Server. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From jjl at pobox.com Sun Aug 3 18:44:52 2003 From: jjl at pobox.com (John J. Lee) Date: 03 Aug 2003 23:44:52 +0100 Subject: Changing base class of a big hierarchy References: <873cgjyo2u.fsf@pobox.com> <2259b0e2.0308031108.3cc1d6db@posting.google.com> Message-ID: <87ispeuzrv.fsf@pobox.com> mis6 at pitt.edu (Michele Simionato) writes: [...] > Here is a hack that does the job (notice the word 'hack'). > Suppose you have a module called x.py: [...] > def modulesub(s,r,module): [...code generation hack snipped...] > import x > Bsource=inspect.getsource(x.B) > Bnewsource=inspect.getsource(B) > > x=modulesub(Bsource,Bnewsource,x) # redefine the module [...] I agree with you that it's a hack ;-). John From nonotreally999 at yahoo.com Wed Aug 13 13:05:42 2003 From: nonotreally999 at yahoo.com (Tom) Date: 13 Aug 2003 10:05:42 -0700 Subject: Python vs. C# References: <2259b0e2.0308100616.55b651ca@posting.google.com> <3f36af20@shknews01> <3f3959e3_1@news.vo.lu> <3F39B8A3.68B9D623@alcyone.com> Message-ID: "A.M. Kuchling" wrote in message news:... > On Wed, 13 Aug 2003 10:26:10 +0200, > Fredrik Lundh wrote: > > is naggum still posting to the net? > > The most recent Google Groups posting for him is Jan. 13 2003. > comp.lang.lisp has since settled down into discussion that are horror> mostly about Lisp, not about newsgroup etiquette, Scheme/Lisp > flamewars, and personal attacks. That's great news. I haven't checked c.l.l. for several months. Didn't think such a complete turnaround was possible. Sounds like this is no longer the best spot for Mr. Van Avery. From see at my.signature.com Wed Aug 27 16:27:50 2003 From: see at my.signature.com (Andrei) Date: Wed, 27 Aug 2003 16:27:50 -0400 Subject: python version of emailstripper??? References: Message-ID: <3292735.1062016070@dbforums.com> I don't know that program, but if it just strips leading ">", it's pretty easy to do. ">> some text".lstrip(">").strip() returns: 'some text' -- Contact info (decode with rot13): cebwrpg5 at bcrenznvy.pbz Fcnzserr! Cyrnfr qb abg hfr va choyvp zrffntrf. V ernq gur yvfg, ab arrq gb PP. Posted via http://dbforums.com From jgerard at fluid-studios.ca Tue Aug 26 19:02:21 2003 From: jgerard at fluid-studios.ca (JM) Date: 26 Aug 2003 16:02:21 -0700 Subject: Accessing members of Python class from C++ (Embedded Python)???? Message-ID: Hello everyone, Does anybody know about, have documentation on, or have any code samples on how to access class members from a python class in C++. Say I have a simple python script: --------------------------- class Animal: NumLegs = 5 Size = 4.5 --------------------------- How exactly do you access these members from C++. I know how to get the member if I know its name, ie. pkObject = PyDict_GetItemString(pkDict, "Animal"); int uiNumLegs = PyInt_AsLong(PyObject_GetAttrString(pkObject,"NumLegs")); But how do you iterate through all the class members and print their names and values? This is easy to do for basic variables, but I can't seem to do it for class variables. Any help would be much apprecited. This is driving me nuts. JG From http Sun Aug 24 21:50:00 2003 From: http (Paul Rubin) Date: 24 Aug 2003 18:50:00 -0700 Subject: large-scale app development in python? References: <7xlltkxrcv.fsf@ruckus.brouhaha.com> <87smnsx7y6.fsf@pobox.com> <7xznhzgbuy.fsf@ruckus.brouhaha.com> <87d6evjl6a.fsf@pobox.com> <7xk793hvub.fsf@ruckus.brouhaha.com> <878ypia7hy.fsf@pobox.com> Message-ID: <7xd6eutsjb.fsf@ruckus.brouhaha.com> jjl at pobox.com (John J. Lee) writes: > I don't think you actually read my post, because you're just repeating > what I said there -- thereby contradicting the post of yours I was > replying to. Enough! -- I give up on this thread. I read your post. I don't see the contradicition. I think the cost per LOC of developing in Python isn't too much different than for other languages. I also think most software metrics including LOC are crap. The stuff that controls the real costs is very hard to objectify. So if you have to use some numerical metric, you may as well use LOC, it's not great but everything else is just as bad. From grante at visi.com Fri Aug 8 13:44:34 2003 From: grante at visi.com (Grant Edwards) Date: 08 Aug 2003 17:44:34 GMT Subject: execute command in CURRENT shell References: Message-ID: <3f33e182$0$151$a1866201@newsreader.visi.com> In article , Valentine Kouznetsov wrote: > simple question, how to execute command in current shell, not > in subshell? Can't be done. > Example. I have environment variable A=aaa and need to invoke > shell (sh) script which will do something with A. If I do > os.system() then sub-shell will setup A and execute my script > there leaving A in parent shell untouched. Under Unix, you can't affect the environment of a parent. You can only write to your own environment and pass it on to your children. -- Grant Edwards grante Yow! It's OKAY --- I'm an at INTELLECTUAL, too. visi.com From ckrieg at shaw.ca Wed Aug 20 18:45:13 2003 From: ckrieg at shaw.ca (Conrad Krieg) Date: Wed, 20 Aug 2003 15:45:13 -0700 Subject: Newbie Variable Substitution Question In-Reply-To: <16195.46495.941374.52324@montanaro.dyndns.org> Message-ID: > ckrieg> for c in range(1, 3): > ckrieg> print "%(c)s %(1)s" % (locals(), dict01) > > ckrieg> Results in an error: TypeError: format requires a mapping > > ckrieg> Why doesn't the second loop work? It seems to be a > cleaner way > ckrieg> of doing this. Am I missing something? > > The right-hand argument to the % operator is a tuple of > dictionaries, not a > dictionary. > > Try something like this instead: > > class MultiDict(dict): > def __init__(self, *args): > self._dicts = args > > def __getitem__(self, key): > for d in self._dicts: > try: > return d[key] > except KeyError: > pass > raise KeyError, key > > def has_key(self, key): > for d in self._dicts: > if key in d: > return True > return False > > dict01 = { '1': 'a', '2': 'b' } > for c in range(1, 3): > print "%(c)s %(1)s" % MultiDict(locals(), dict01) Thanks! This worked great! Conrad From andymac at bullseye.apana.org.au Wed Aug 13 19:42:47 2003 From: andymac at bullseye.apana.org.au (Andrew MacIntyre) Date: Thu, 14 Aug 2003 09:42:47 +1000 (EST) Subject: problems importing "bsddb" In-Reply-To: <16185.22848.524146.916237@montanaro.dyndns.org> References: <16185.22848.524146.916237@montanaro.dyndns.org> Message-ID: <20030814093622.W50245@bullseye.apana.org.au> On Tue, 12 Aug 2003, Skip Montanaro wrote: > John> We are using OpenBSD latest release of Python (2.3), and want to > John> use the "bsddb" module. Our python release has a directory > John> called "bsddb", but when we try and import it, it says > >>> import bsddb > Traceback (most recent call last): > File "", line 1, in ? > File "/usr/local/lib/python2.3/bsddb/__init__.py", line 40, in ? > import _bsddb > ImportError: No module named _bsddb > > You need to install version 3 or 4 of Berkeley DB. It may be available as > part of OpenBSD or as a port, but you can get the source from > > http://www.sleepycat.com/ > > and install it from source easily. Once you've done that, rerun > > python setup.py install > > in the Python source tree. I'm sure that OpenBSD also has BSD DB v1.85 in its libc. If you are wanting to access system DB files (terminal capabilities, master password etc), then you will need to use this instead of Sleepycat's DB3/4 - it should be available as the bsddb185 module. If your code is compatible with the old bsddb module, you could do this as import bsddb185 as bsddb Before Skip goes up in flames, only use the bsddb185 module if you have to. -- Andrew I MacIntyre "These thoughts are mine alone..." E-mail: andymac at bullseye.apana.org.au (pref) | Snail: PO Box 370 andymac at pcug.org.au (alt) | Belconnen ACT 2616 Web: http://www.andymac.org/ | Australia From mcherm at mcherm.com Tue Aug 26 13:07:07 2003 From: mcherm at mcherm.com (Michael Chermside) Date: Tue, 26 Aug 2003 10:07:07 -0700 Subject: Replacement for rexec/Bastion? Message-ID: <1061917627.3f4b93bb2e655@mcherm.com> Colin Coghill (SFive) writes: > Hi, a year or so back some students of mine and I wrote some software > which made use of the rexec module to run untrusted user code relatively > safely. [...] > I noticed that rexec and Bastion have been > withdrawn for (in)security reasons. Yes. Of course, you can still go back and get the old versions of these and run them. It won't be any safer than it was before they were withdrawn, but it will be just as useful (or not useful) as it was when you used it a year back. > Is Python (preferably CPython 2.3) still able to "sandbox" bits of code > under an application provided API safely? No. There are some levels of safety that CAN be achieved, but there's no real way to reliably limit resources. That's why rexec and Bastion were withdrawn rather than being improved... there was no working replacement available or even on the horizon. Zope's RestrictedPython is the closest thing there is... a quick summary of its approach was posted to python-dev today: http://mail.python.org/pipermail/python-dev/2003-August/037791.html > I can trap endless loops and the like, > but I need something to stop them just importing sys and raising havoc. Sorry to be so blunt here, but no, you CAN'T trap endless loops and the like. If you think that you can, then you don't really understand what's involved in securing untrusted code. Consider, for instance, this code: x = 1000000**1000000 I guarantee it'll lock up your python interpreter for a fairly long time. And it executes in C so there's no possible way you can trap it. That's not all, I can do things like this: x = [1] * sys.maxint So I have to question whether you really know what you want here. The truth is, 98.4% of all people who claim to need to sandbox code could get by just fine with no restrictions at all. (Gee, isn't it fun to just make up spuriously-accurate statistics?) If you're one of the remaining 1.6%, you need to decide whether you just need to prevent malicious code from accessing services (eg: reading / writing files), or if you ALSO need to prevent it from bringing down the program that's running it. If just closing off services is good enough, try the old rexec/Bastion or check out RestrictedPython, but realize that neither is perfect (RestrictedPython is better). If you actually need to prevent DOS attacks, then the only approach that could work would be to launch the untrusted code in a separate process, and allow the OS to limit that processes access to services (like the filesystem) and resources (memory and cpu-time constraints). -- Michael Chermside From dave at boost-consulting.com Sat Aug 30 16:51:49 2003 From: dave at boost-consulting.com (David Abrahams) Date: Sat, 30 Aug 2003 16:51:49 -0400 Subject: Help embedding python References: <3F4A469E.58B94F7C@engcorp.com> <3F4A57B0.E91D89FC@engcorp.com> Message-ID: Zora Honey writes: > I'm sorry if I was a bit curt. The reason I didn't include rationale > is because I have none. I have been advocating extending python > instead of embedding it, but since I have no experience with either, > my only argument is that it seems more natural. It seems like either > method is as difficult to learn and implement. It doesn't seem to me > that there are lot of arguments one way or the other. My husband, on > the other hand, is strongly attached to the idea of having a c++ main > program that will coordinate all the data-processing classes and > python widgets. He believes it is easier to have c++ say to python, > "here, I have these plots for you," rather than have python say to > c++, "make these plots for me." I don't believe this is true, but I > don't have any reason *not* to believe it's true, so I aquiesced. > > So, I suppose instead of asking you to assume the rationale are well > reasoned, I should be asking you why you believe extending python is > easier/cheaper/faster/better than embedding it. Here's why you're right and your husband is, well... the opposite : embedding Python almost always includes all the problems of extending it, and a little bit more. In applications where Python is embedded in C++, it's usually insufficient to leave the Python code with access to nothing other than what comes with the Python interpreter: instead you want to give it access to some C++ types and functions. Exposing those to Python is exactly the same job you do when extending, only when extending you don't need to worry about linking Python into your application (on most platforms), handling and reporting Python exceptions from C++ which may emanate from the interpreter, getting ahold of a module context in which to evaluate Python code, etc. Another way to think of it is that when you need to embed, since you also usually need to extend, you need to manage the transition across the C++ <-> Python language boundary in two places instead of one. On the other hand, embedding isn't *much* more difficult, so if it keeps things peaceful at home, I'd just go along with it ;-) Oh, and whichever you choose, I *strongly* recommend you don't do it by hand with Python 'C' API. There are too many ways to mess up reference counting, exception-handling, etc., and way too much boilerplate code repetition for it to be a very productive approach. Besides, since you're using C++ anyway, it gives you all the power you need to embed or extend simply and elegantly. For more info, see http://www.boost.org/libs/python. HTH, -- Dave Abrahams Boost Consulting www.boost-consulting.com From CousinStanley at hotmail.com Mon Aug 25 13:25:43 2003 From: CousinStanley at hotmail.com (Cousin Stanley) Date: Mon, 25 Aug 2003 10:25:43 -0700 Subject: Coloring print lines References: Message-ID: | Is there an easy way to make script print text | with different colors to screen (shell)? | ... Sami ... I have a couple of small examples for printing colorized strings via Ansi escape sequences from Python under Windows ... http://fastq.com/~sckitching/Python/ansi_strings.zip -- Cousin Stanley Human Being Phoenix, Arizona From danb_83 at yahoo.com Sat Aug 2 00:59:00 2003 From: danb_83 at yahoo.com (Dan Bishop) Date: 1 Aug 2003 21:59:00 -0700 Subject: time, calendar, datetime, etc References: Message-ID: "Andrew Dalke" wrote in message news:... > "Intractable?"! What about defining your own class which handles > BC dates, using datetime to do the heavy load? All you need is > your own offset to choose a year which has the same day-of-week > and leapyear behaviour. datetime says 1/1/1 was a Monday, so > you just need a year offset X so that 12/31/X is a Sunday and > where X is a leapyear (or not? Don't know how the leap years > are affected that far in the past.). There were no leap years between 10 BC and AD 4, because after Julius Caesar's death, the priests in charge of the calendar mistakenly added leap days every 3 years instead of 4, and this had to be corrected. I wouldn't expect the datetime module to deal with that, though ;-) > Looks like X=6000 does the job. So does any multiple of 400: The Gregorian leap year cycle is 400 years and this is coincidentally also a whole number of weeks. > >>> datetime.date(1970, 8, 22).weekday() > 5 > >>> datetime.date(6970, 8, 22).weekday() > 5 The output above is my least favorite feature of the datetime module. It took me a while to figure out that those dates are Saturdays. Perhaps we could add a weekday class to 2.3.1? DAY_NAMES = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] class weekday(int): def __repr__(self): return DAY_NAMES[self] for i, name in enumerate(DAY_NAMES): globals()[name] = weekday(i) From adalke at mindspring.com Fri Aug 1 19:23:40 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Fri, 1 Aug 2003 17:23:40 -0600 Subject: time, calendar, datetime, etc References: <153fa67.0307300326.45a29380@posting.google.com> <1sScnW0Sv7DzrrSiRTvUpQ@speakeasy.net> Message-ID: John Roth: > Several turns out to be one revision, and I don't think that they > got it right either. From what I see, the Python datetime library > is actually more complicated than the Java library: it's certainly > got more classes, although they seem to be better designed. Then I was just spreading rumor. I see the following classes in Java: java.util.Date java.sql.Date java.sql.Time java.sql.Timestamp java.util.Calendar java.util.GregorianCalendar java.util.Timezone java.util.SimpleTimeZone java.text.DateFormat java.text.SimpleDateFormat As for Python ones ... datetime.timedelta datetime.date datetime.datetime datetime.tzinfo plus the older ones of time.* calendar (mostly useless, IMHO) > For the most part, the applications that need to be aware of leap > seconds are the ones that communicate with other servers that > are aware of leap seconds, and can report them. As far as I'm > aware, leap seconds are a thing of the past anyway: they proved > to be more trouble than they were worth to anyone. But those tools don't need support for BC-era dates... > I'd also expect to see some sort of reasonably well thought out framework > where those extensions could simply be plugged in and just work. There were some dicussions for that - the idea was that datetime and mxDateTime values should be interoperable. I don't recall the details of those plans though ... (searching) ... Ahh, a thread starts here http://mail.python.org/pipermail/python-dev/2003-January/032100.html but I don't know the conclusion. > Where was it in March? [grin]. Answer. It depends on where is. Sure. Which is why datetime support for then is hard. The statement I made in c.l.py years ago was that it's all dependent on longitude, lattitude, and additude. Software can handle the first two, but not the third, at least not without a lot of work and upkeep. > My objection > is to exactly one implementation decision: to limit the time range > at 1AD. That is, to use the vernacular, a show-stopper. It means > that the core of the library has to be reworked if you want to deal > with dates before 1AD. I gave an idea of a way to work around that, by using an offset of 6000 years. I'll look to there for followup. > programming. My application date package works for what > I need it to do; it just seems that I can't abandon it for the > standard Python library package. [Sigh.] Does that mean if there was no decision to include datetime in Python 2.3 then you wouldn't be able to support your application at all in Python? Or would you have just decided to use mxDateTime? If the latter, what's preventing you from doing so now? Andrew dalke at dalkescientific.com From afriere at yahoo.co.uk Mon Aug 18 03:21:32 2003 From: afriere at yahoo.co.uk (Asun Friere) Date: 18 Aug 2003 00:21:32 -0700 Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> Message-ID: <38ec68a6.0308172321.2e3c03b7@posting.google.com> Erik Max Francis wrote in message news:<3F4040F8.87901505 at alcyone.com>... > "Brandon J. Van Every" wrote: > > > What's better about Ruby than Python? I'm sure there's something. > > What is > > it? > > Wouldn't it make much more sense to ask Ruby people this, rather than > Python people? Maybe he can't speak Japanese? From sross at connectmail.carleton.ca Wed Aug 27 15:30:23 2003 From: sross at connectmail.carleton.ca (Sean Ross) Date: Wed, 27 Aug 2003 15:30:23 -0400 Subject: python gripes survey References: <15dpkvsfatkrlode3rc9h1trihsb3ppcj3@4ax.com> Message-ID: "Gon?alo Rodrigues" wrote in message news:15dpkvsfatkrlode3rc9h1trihsb3ppcj3 at 4ax.com... [snip] > Related with this is the global declaration -- the only > declaration in Python! There should be another way to handle this: > something like scopes becoming objects where the names bound in it are > it's attributes and then you would have two functions global() and > enclosing() returning the global and the enclosing scope. Or something > to this effect :-) > This is probably not what you want, and it's probably worse than just using a global declaration, but it *is* "another way to handle this": >>> # put this at the top of your module, >>> # to grab hold of this module's namespace >>> import __main__ as main >>> g = "global variable" >>> def f(): ... main.g = "re-bound global" ... >>> f() >>> g 're-bound global' >>> If you want a global() function that returns the namespace, you can do this: # # your_utils.py # # I'll use the name 'main' rather than shadow the global keyword def main(): import __main__ return __main__ # other_module.py from your_utils import main foo = "foo" def bar(): print main().foo # output foo I have no idea what issues this raises, but that is not my concern here - I'm just seeing whether there is "another way to handle this". It looks like there is. Usual disclaimers apply: "Don't do that", "Use at your own risk", "Yada, Yada" I can't help you with "names bound in nested scopes are read-only, not rebindable". I tried to implement your enclosing() idea. I made a 'namespace' class to use as follows: def foo(): x = 1 def bar(): # context is the number of frames to go back outer = namespace(context=1) # outer keeps a reference to foo's frame outer.x = 2 # so, I tried to re-bind the x in foo using something like # self.frame.f_locals['x'] = 2, but f_locals is not writable! # I made several attempts to circumvent this, but no success. bar() print x foo() # output 1 Oh well... "just seeing if it can be done-ly yours" Sean From none at none.net Thu Aug 14 04:30:08 2003 From: none at none.net (Sami Viitanen) Date: Thu, 14 Aug 2003 08:30:08 GMT Subject: Determine file type (binary or text) References: Message-ID: I think I've found what I need. The module is called magic.py. It show if the file is data or text. It can be downloaded from http://www.demonseed.net/~jp/code/ "Sami Viitanen" wrote in message news:gwH_a.1649$k4.34358 at news2.nokia.com... > Thanks for the answers. > > To be more specific I'm making a script that should > identify binary files as binary and text files as text. > > The script is for automating CVS commands and > with CVS you have to add the -kb flag to > add (or import) binary files. (because it can't itself > determine what type the file is). If binary file is not > added with -kb the results are awful. > > Script example usage: > -import.py > > Script makes list of all files under that directory > and then determines each files filetype. After that > all files are added with Add command and binary > files get that additional -kb automatically. > > > "Sami Viitanen" wrote in message > news:AFm_a.9725$g4.189983 at news1.nokia.com... > > Hello, > > > > How can I check if a file is binary or text? > > > > There was some easy way but I forgot it.. > > > > > > Thanks in adv. > > > > > > From ejy712 at comcast.net Sat Aug 9 21:01:24 2003 From: ejy712 at comcast.net (Ed Young) Date: Sat, 09 Aug 2003 21:01:24 -0400 Subject: obj.__dict__ expected behavior or bug? Message-ID: Here is an example of the behavior: ------- code start ----------------------------------- #!/usr/bin/python #bugtest - test of class attribute initiation class Config: a = 1 b = 2 c = 3 d = None e = None h = {'d' : 22, 'e' : 33} def __init__(self, factor): for attr in self.h.keys(): self.__dict__[attr] = self.h[attr] * factor def moda(self): self.a *= 5 c = Config(2) print c.a, c.b, c.c, c.d, c.e for attr in c.__dict__: print 'c.%s = %s' % (attr, c.__dict__[attr]) print c.moda() print c.a, c.b, c.c, c.d, c.e for attr in c.__dict__: print 'c.%s = %s' % (attr, c.__dict__[attr]) print ------- code ends ----------------------------------- ------- output starts ------------------------------- $ bugtest 1 2 3 44 66 c.e = 66 c.d = 44 5 2 3 44 66 c.a = 5 c.e = 66 c.d = 44 ------- output ends --------------------------------- What happened to c.a, c.b, and c.c when iterating thru c.__dict__ ? It appears that __dict__ members are not instantiated until they are changed. This precludes using __dict__ as the dictionary in a formatted print statement. e.g. print "c.a=%(a)s, c.b=%(b)s, c.c=%(c)s" % c.__dict__ Is this a bug or expected behavior? From eadorio at yahoo.com Fri Aug 29 05:02:04 2003 From: eadorio at yahoo.com (Ernie) Date: 29 Aug 2003 02:02:04 -0700 Subject: print without intervening space Message-ID: <5b42ae4.0308290102.3f04b90b@posting.google.com> Hi, >>> for x in range(10) ... print x, ... will output 0 1 2 3 4 5 6 7 8 9 >>> What if somebody wants instead 0123456789 Maybe we need a printns (print with no spaces) ? Ernie From plz at solic.it Sun Aug 3 17:20:43 2003 From: plz at solic.it (Jordan Tucker) Date: Sun, 3 Aug 2003 16:20:43 -0500 Subject: FOUND! how to attach to running instances of Internet Explorer References: Message-ID: > Also, I haven't been able to determine if there's a better name of the > form 'InternetExplorer.Application.1' instead of using the horrid > class-id. How do you do that? The makepy output for explorer doesn't > list one. The relevant MSDN page[1] lists the ProgID as 'Shell.Windows' or 'ShellWindows._NewEnum'; however when trying to dispatch with either as the class string fails. Also, searching the registry reveals nothing for the CLSID. [1] http://tinyurl.com/ix1z , i.e. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/programmersguide/shell_basics/shell_basics_programming/objectmap.asp From dave at 3dex.com Tue Aug 19 17:08:41 2003 From: dave at 3dex.com (Dave Benjamin) Date: Tue, 19 Aug 2003 21:08:41 GMT Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> <87fzjywpjs.fsf@pobox.com> Message-ID: "Alex Martelli" wrote in message news:bht3bq02v9p at enews3.newsguy.com... > Thus, the direct Python equivalent might be > > import __builtins__ > __builtins__.len = someotherfunction > > and THAT usage is very specifically warned against e.g. in > "Python in a Nutshell" -- you CAN do it but SHOULDN'T (again, one > can hope to eventually see it "officially" deprecated...!). I agree with your position, more or less, but I am curious - how far do you think this deprecation should go? Just changing a function in __builtins__? Changing a function in any module? Or changing *anything* about a module from the outside? Thanks, Dave From fgeiger at datec.at Sat Aug 9 09:36:41 2003 From: fgeiger at datec.at (F. GEIGER) Date: Sat, 9 Aug 2003 15:36:41 +0200 Subject: Python for .NET preview 2 release References: <5t_Ya.102789$YN5.72026@sccrnsc01> Message-ID: <3f34f876@news.swissonline.ch> >From his readme: "This package does not implement Python as a first-class CLR language - it does not produce managed code (IL) from Python code. Rather, it is an integration of the C Python engine with the .NET runtime. This approach allows you to use use CLR services, continue to use existing Python C extensions, and provides very good execution speeds." Regards Franz GEIGER "Bryan" schrieb im Newsbeitrag news:5t_Ya.102789$YN5.72026 at sccrnsc01... > is this the same visual python .net that at activestate? i didn't know they python .net is still moving forward. i also thought i > read somewhere that there were some limitations about using a typeless language on the clr. is this not true anymore? > > thanks, > > bryan > > > "Brian Lloyd" wrote in message news:mailman.1060400898.32406.python-list at python.org... > > For those interested, I've made a preview-2 release of > > Python for .NET. > > > > Python for .NET is a near-seamless integration of the > > CPython runtime with the .NET Common Language Runtime > > (CLR). It lets you script and build applications in > > Python, using CLR services and components written in any > > language that targets the CLR (C#, Managed C++, VB.NET, > > etc.). > > > > Highlights of this release include array and indexer > > support, better thread handling, the ability to subclass > > managed classes in Python and many bug fixes. > > > > For more info or to download the release: > > > > http://zope.org/Members/Brian/PythonNet/ > > > > - Brian > > > > From sfb at alysseum.com Sat Aug 9 12:43:32 2003 From: sfb at alysseum.com (Simon Bayling) Date: Sat, 9 Aug 2003 16:43:32 +0000 (UTC) Subject: % Documentation Message-ID: Hello, Where is the % operator documented? I was looking for ages yesterday, Python.org, browsing the documentation for modules, the tutorial, searching for it, trying help(%), using Google, and so on. I found that locale.format works like the % operator... how useful ;) if someone could point me towards it, that would be great... (Also, what is the proper name for it? String interpolation? String substitution? Percent-substitution?) Cheers, Simon. From usenet at soraia.com Thu Aug 21 19:53:47 2003 From: usenet at soraia.com (Joe Francia) Date: Thu, 21 Aug 2003 23:53:47 GMT Subject: Q: urlopen() and "file:///c:/mypage.html" ?? In-Reply-To: References: Message-ID: MAK wrote: > I'm stumped. > > I'm trying to use Python 2.3's urllib2.urlopen() to open an HTML file > on the local harddrive of my WinXP box. > > If I were to use, say, Netscape to open this file, I'd specify it as > "file:///c:/mypage.html", and it would open it just fine. But > urlopen() won't accept it as a valid URL. I get an OSError exception > with the error message "No such file or directory: > '\\C:\\mypage.html'". > > I've tried variations on the URL, such as "file://c:/mypage.html", > too, without luck. That one gives me a 'socket.gaierror' exception > with the message "'getaddrinfo failed'". > > Upon diving into the code, I found that, in the first case, the third > '/' is left as part of the filename, and in the second case, it ends > up thinking that 'C:' is the hostname of the machine. > > Can anyone point out the error of my ways? > Thanks. This works: f = urllib2.urlopen(r'file:///c|\mypage.html') But, if you're only opening local files, what's wrong with: f = file(r'c:/mypage.html', 'r') jf From bokr at oz.net Fri Aug 1 18:43:05 2003 From: bokr at oz.net (Bengt Richter) Date: 1 Aug 2003 22:43:05 GMT Subject: Problem with Unzipping/Installing Python-2.3.exe References: Message-ID: On 1 Aug 2003 15:06:20 -0700, sjmachin at lexicon.net (John Machin) wrote: >John Latter wrote in message news:... >> Hi, >> >> I downloaded Python-2.3.exe but when I used winzip it kept asking me >> if I wanted to replace old files with new ones, and in some instances, >> new files with old ones. >> >> I've never downloaded/installed Python before, and as something of a >> computer novice, would like to know what I may be doing wrong! >> >> This is the link I downloaded from: >> >> >Windows users should download the Windows installer, Python-2.3.exe >> >, run it and follow the friendly instructions on the screen to complete >> >the installation. > >Faced with the 4 clues in the above sentence: > >(1) "installer" >(2) ".exe" >(3) "run it" >(4) complete absence of any mention of ".zip", "unzip", "Winzip", ..., > >my expectation would be that one should run the damn thing, not try to >unzip it. > >Do you feel that the instructions were unclear? Do you have any >suggestions on how they might be improved? > I guess for those who are rightfully afraid of any .exe's downloaded from the net, a parenthetic reassuring mention in the same paragraph that the MD5 digests and file sizes are displayed further down the page might be a small improvement. Then all you have to do is trust the folks that created installer and the files and web page ;-) Regards, Bengt Richter From wiebke.paetzold at mplusr.de Wed Aug 6 04:35:59 2003 From: wiebke.paetzold at mplusr.de (Wiebke Pätzold) Date: Wed, 06 Aug 2003 10:35:59 +0200 Subject: abstraction of the column names (classes) References: <13a533e8.0308051300.2d463b04@posting.google.com> Message-ID: On 5 Aug 2003 14:00:23 -0700, p-abel at t-online.de (Peter Abel) wrote: >Wiebke P?tzold wrote in message news:... >> Hi all! >> >> I create a database that contains a table. 'Nachname' is one of 13 >> column names. This program can search for >> a special letter. In my example it is 'ra'. and the search takes place >> in 'Nachname'. 'ra' takes place within a word. This is solved with >> regular expression. So that I can limit my search. >> For example: I can search for 'ra' and it is not relevant wich letters >> follow or wich letters are in front of 'ra'. >> Now I want to abstract the column name 'Nachname'. So I search in an >> unknown column. Only the user of the program should determine in wich >> class the search takes place. This input should happen in the view >> lines of testing the class. >> My task is it to change the program that a abstraction of the column >> names takes place. >> Please give me a detailed answer. If it is possible the changed >> program because I am very new in Python and I am orientationless. >> >> This is the program >> >> import sys >> import Mk4py >> import re >> >> db = Mk4py.storage("c:\\datafile.mk",1) >> vw = db.view("people") >> >> class PatternFilter: >> def __init__(self, pattern): >> self.pattern = re.compile(pattern) >> >> def __call__(self, row): >> try: >> nachname = row.Nachname >> except AttributeError: >> return 0 >> return self.pattern.search(nachname)is not None >> >> vf = vw.filter(PatternFilter("ra.*")) >> >> for r in vf: >> print vw[r.index].Nachname > >RegEx are really great and there are a lot of problems you can >only solve with them. But if I understand you right your problem >is to find a string where a substring is to be in, the simple >string operation does the work: >if String.find(substring) > -1: > >**find** will give you the position in String where substring >will occure the 1rst time and -1 if substring doesn't occur. > >e.g. >>>> nameList=['Meyer', 'Maxon', 'Johnson', 'Mueller'] >>>> for name in nameList: >... if name.find('er')>-1: >... print name >... >Meyer >Mueller >>>> > >So if you can get your columns contents in **ColumnList** >and your searchpattern in **SearchPattern** so the following >function could do the work: > >def getPatternMatches(ColumnList,SearchPattern): > foundList=[] > for n in ColumnList: > if n.find(SearchPattern) > -1: > foundList.append(n) > return foundList > >Regards >Peter I forgot something: The user must have the choice between a special search in a concrete split and a search in all columns. The user have to determine wich search method is used. From ryanlowe0 at msn.com Fri Aug 22 20:12:39 2003 From: ryanlowe0 at msn.com (Ryan Lowe) Date: Sat, 23 Aug 2003 00:12:39 GMT Subject: crazy programming language thoughts References: <-5SdnWETctL179iiU-KYgw@giganews.com> <3PKdnXyDgbmng9uiXTWJiA@august.net> Message-ID: "Terry Hancock" wrote in message news:3PKdnXyDgbmng9uiXTWJiA at august.net... > Istvan Albert wrote: > > Ryan Lowe wrote: > > >>>>v = read lines from 'file.txt'; > > join it with '\n'; lower it; split it at '.' > > > > split line at '\n' is no better than line.split("\n") > > after all then you could argue that you should be > > able to say "'\n' is the splitting character in line" or > > "break into pieces at '\n'" and so on. my intentions are much humbler. im not trying to go for true natural-language capabilities. my split syntax is fixed just as it is in python, except in terms of the order of the parameters in some cases. > Yeah, I think this is ultimately the problem with "English-like" > syntax. The fact that Python's syntax (one of many examples) > is more like mathematical notation is a cue to both the author > and the reader that a more exacting attention to syntax is > required. Maybe this is what they really meant by "one obvious > way to do it" versus "there's more than one way to do it": in > English there are many -- maybe infinitely many -- ways to say > essentially the same thing. > i agree that wordiness is a trend in most if not all of the english-like programming languages ive looked at. human languages are wordy to disambiguate and also to overcome discrepencies in what people know. programming languages, in contrast, are consise and unambiguous. id like to maintain this as much as possible, and at the same time increase the clarity beyond what python has already done. more like super-psudeo-code than true natural language. PERL is exactly what id like to avoid: too flexible and much to cryptic ("there's more than one way to do it" is perl's motto, right?) > and while I find SQL very useful in its limited application > domain, I wouldn't really want to turn it into a real > programming language*! > why does a readable language need to be limited? this is exactly what i want to understand/disprove. i am attempting to build on python, an already powerful language. i only want to make it more english-like if it not only makes things clearer but adds meaning. for example, looking back on the example statement i gave: >>> v = read lines in 'book.txt'; join it with ''; lower it; split it at '' i noticed that the 'it' was unnecessary. i could have said: >>> v = read lines in 'book.txt'; join with ''; lower; split at '' nearly as clear with less writing. in fact its just about as short as the python equivalent. well i need to do some more thinking on this over the weekend... another thing i was playing around with, perhaps stemming from some of the languages ive been looking into, is parts of speech. for example, functions should be verbs and knowing that, some transformations may be possible. a boolean question for an if statement may be derivable from that function automagically: >>> if a was replaced with b in c : could be derived from the replace function by using this rule: >>> if replace a with b in c == a : which has the same meaning but isnt as 'nice.' again the 'was' could be eliminated for brevity. From gh at ghaering.de Thu Aug 21 09:22:30 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Thu, 21 Aug 2003 15:22:30 +0200 Subject: max length of a python program In-Reply-To: <1ed07caf.0308210513.6556978a@posting.google.com> References: <1ed07caf.0308210513.6556978a@posting.google.com> Message-ID: <3F44C796.4010400@ghaering.de> Ragu wrote: > Is there a limit to the # of lines that can be in a Python program? The free version from python.org is limited to 500 lines per module. I'll gladly sell you Python Enterprise 2003, which has no lines of code limits at all and where code size is only limited by available memory. The current price is EUR 250 per seat or EUR 5000 for a site-license. One year of free support via Usenet (comp.lang.python) is included. -- Gerhard From aleax at aleax.it Wed Aug 20 16:11:37 2003 From: aleax at aleax.it (Alex Martelli) Date: Wed, 20 Aug 2003 20:11:37 GMT Subject: Python should try to displace Java References: <3f3e89f3$0$225$626a54ce@news.free.fr> Message-ID: A.M. Kuchling wrote: > On Wed, 20 Aug 2003 17:00:13 GMT, > Alex Martelli wrote: >> "happen" to be excellent for the job. Not just my opinion -- e.g., >> Mitch Kapor and his OSAF chose Python as the application-programming >> language for the Chandler system, and if you look at the specs for >> that ambitious undertaking you'll see it WILL be quite a large-scale >> system when it matures. > > I don't find OSAF's choice of Python to be much of an endorsement. > Given that most of the principals involved didn't seem to actually > know Python at the time of the initial announcement, I can only > conclude that they thought choosing Python would give them some > credibility in the open-source community, and not because they did a > careful comparison of Python with the alternatives. I think you're doing them an injustice. After all, enough open-source work (by far!) is done in (e.g.) C, or Java, or C++, that choosing any of these languages, say, would most obviously not have in any way damaged their "credibility in the open-source community"! Sure, by choosing Python they have gained (e.g.) my personal sympathy, but by the same token by choosing (e.g.) Perl they might have gained the sympathy of the much-vaster hordes of Perl fans, no? It WOULD be interesting to hear from the OSAF guys exactly why they chose Python, what other alternatives they compared it to, and what criteria they weighed by how much. But clearly, one way or another, they DID form the opinion that Python will be suitable to build the ambitious, large-scale system they aspire to -- so, the fact that "Python is excellent for this job" is NOT just my opinion is amply confirmed... whether Kapor & friends made their choice by listening to the opinions of others (Raymond, Berners-Lee, Eckel, whoever) or (as they appear to claim on their pages) by doing their own comparisons of the available alternatives. Alex From rxs141 at cwru.edu Sat Aug 23 20:35:13 2003 From: rxs141 at cwru.edu (Ravi) Date: Sat, 23 Aug 2003 20:35:13 -0400 Subject: Python 2.3 and mod_python Message-ID: Hi, I am considering embarking on a project with mod_python. However I am wondering if the mod_python interpreter is embedded or actually calls the python executable. The documentation says the former, so I am wondering if there is a seperate pythonpath for the interpreter in mod_python. What version of CPython is mod_python analagous to? Not 2.3 I'm guessing. I'm heavily reliant on 2.3 features, it would be difficult for me to go back to 2.2. Also, if mod_python does have a separate pythonpath and interpreter, could someone please point me to a tutorial on how to install modules in mod_python. Thanks, Ravi From imbosol at aerojockey.com Sun Aug 10 16:17:51 2003 From: imbosol at aerojockey.com (Carl Banks) Date: Sun, 10 Aug 2003 20:17:51 GMT Subject: How to print floating point in scientific format? References: <420ced91.0308081115.7060e551@posting.google.com> <420ced91.0308101127.644f9813@posting.google.com> Message-ID: sdhyok wrote: > As you recommend, I won't modify the default behavior of python. > But, still I need a better treatment of python on arrays. Continually repeating your question isn't going to make a better treatment magically appear. Just use the loop method someone suggested. If you don't like writing a for loop every time, put it in a function. -- CARL BANKS "You don't run Microsoft Windows. Microsoft Windows runs you." From vze4rx4y at verizon.net Sat Aug 30 13:15:10 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Sat, 30 Aug 2003 17:15:10 GMT Subject: PyList_New References: Message-ID: [soso] > Hi everybody, Hello! > Does PyList_New() increments the reference count? Yes. > I believe yes but I > want to be sure because I saw some code from a module that has a > function that increments it before returning the list. Quoth the docs: """ PyObject* PyList_New( int len) Return value: New reference. Returns a new list of length len on success, or NULL on failure. """ > Thanks in advance, You're welcome after the fact. > soso Raymond Hettinger From ajr at dynacap.com Mon Aug 18 18:51:09 2003 From: ajr at dynacap.com (Arnaldo Riquelme) Date: Mon, 18 Aug 2003 14:51:09 -0800 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: Message-ID: Bottom line is that people that uses Python have a better sex life than those that use other languages. That is ***TOTALLY COMPELLING*** enough for me to use Python. --ajr > I'm realizing I didn't frame my question well. > > What's ***TOTALLY COMPELLING*** about Ruby over Python? What makes you jump > up in your chair and scream "Wow! Ruby has *that*? That is SO FRICKIN' > COOL!!! ***MAN*** that would save me a buttload of work and make my life > sooooo much easier!" > > As opposed to minor differences of this feature here, that feature there. > Variations on style are of no interest to me. I'm coming at this from a C++ > background where even C# looks like an improvement. ;-) From 10,000 miles > up, is there anything about Ruby that's a "big deal" compared to Python? > > One person mentioned Japanese documentation. I'm sure that's Totally Kewl > to the Japanese.... > > -- > Cheers, www.3DProgrammer.com > Brandon Van Every Seattle, WA > > 20% of the world is real. > 80% is gobbledygook we make up inside our own heads. > From jjl at pobox.com Tue Aug 12 08:29:11 2003 From: jjl at pobox.com (John J. Lee) Date: 12 Aug 2003 13:29:11 +0100 Subject: Python should try to displace Java References: Message-ID: <87ptjbt5yg.fsf@pobox.com> Doug Tolton writes: > On Mon, 11 Aug 2003 18:43:08 -0700, "Brandon J. Van Every" > wrote: [...] > >- in 5 years, nobody will be doing significant amounts of new application > >development in C++. The writing is on the wall: garbage collection is > >essential. Any C++ code will be support and legacy libraries. > > That's a ridiculous blanket statement. People will be doing C++ > development for a long time beyond that. There are people still [...] You (like me) misread what he wrote, I suspect. *Application* development, not development in general. I see no reason to disagree that that would be sane (doesn't mean it's going to happen in five years, of course). > than C# does. MS really shot themselves in the foot when they went to > dotnet, essentially the adopted the Java platform 8 years after Java. > Now they are playing catchup with an inferior product. I doubt > they'll ever catch up to Java overall. Remains to be seen. > >- Ergo, Java is the weakling of the litter for Python to attack. > > No factual basis for this statement. Java and Python are really > entirely different things. Python is meant as a scripting language, > Java is a Systems programming language. It is meant as an alternative > to C++, Python isn't. [...] Well, that's certainly frequently debated. John From ask at me.com Thu Aug 21 12:53:04 2003 From: ask at me.com (Greg Krohn) Date: Thu, 21 Aug 2003 16:53:04 GMT Subject: Subclassing ConfigParser Message-ID: I'm trying to subclass ConfigParser so I can use a custom __read method (the custom format doesn't conform to RFC 822) when needed. Needless to say, it's not working as expected. In the following code, I bind __read_ini to __read and override __read so it can choose between __read_ini and __read_custom. But it seems that __read_custom never gets called when I expect it to aways be called. I have a feeling this has to do with me not entirely understanding magic atributes and name mangling. Anyone have ideas? greg from ConfigParser import ConfigParser class CustomConfigParser(ConfigParser): def __init__(self, defaults=None): ConfigParser.__init__(self, defaults) #Replace the normal __read with my custom __read #while keeping the normal one around if I need it self.__read_ini = ConfigParser._ConfigParser__read ConfigParser._ConfigParser__read = self.__read def __read(self, fp, fpname): #Eventually this will decide between __read_custom #and __read_ini, etc. self.__read_custom(fp, fpname) def __read_custom(self, fp, fpname): print "__read_custom" #This never gets printed. cp = CustomConfigParser() cp.read('config.ini') print cp.sections() From tismer at tismer.com Mon Aug 11 07:57:08 2003 From: tismer at tismer.com (Christian Tismer) Date: Mon, 11 Aug 2003 13:57:08 +0200 Subject: Slogan: Getting Rich Overnight In-Reply-To: <3f373ac6@shknews01> References: <3f373ac6@shknews01> Message-ID: <3F378494.7010104@tismer.com> Brandon J. Van Every wrote: > Christian Tismer wrote: > >>Ben Finney wrote: >> >>>Anything with "get rich {quick,fast,overnight}" already has far too >>>many negative connotations to sound un-lame. >> >>Right. But is this my fault? > > > Yes, it's your fault. The language already exists, and you know it's out > there, so you are guilty of picking the extant lame words. I was not picking them. They were said by another guy, who said in German "Python hat mich ?ber nacht reich gemacht". My problem is not that sentence. In German, it still has a useful meaning. My problem is the impossibility to translate it into English without loosing meaning. ... > Dude, "get rich overnight" was lame way before spammers. Face it, your > slogan only sounds good to the choir. Someone like me, who isn't converted > on Python yet, rightfully asks "How stupid do you think I am?" I don't discuss that in public :-) ciao - chris -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 pager +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From tismer at tismer.com Sun Aug 31 17:38:43 2003 From: tismer at tismer.com (Christian Tismer) Date: Sun, 31 Aug 2003 23:38:43 +0200 Subject: [Zope-dev] Zope 2.7 running with Stackless 3.0 In-Reply-To: <3F4E47DF.9060800@zope.com> References: <3F4D44EB.5010500@tismer.com> <3F4DF1E7.1010103@zope.com> <3F4E3CE1.5030405@tismer.com> <3F4E47DF.9060800@zope.com> Message-ID: <3F526AE3.50608@tismer.com> Hi Shane, > BTW, here's one avenue you might pursue, Christian: Python IDEs. When I > wrote the debugger for Boa Constructor, I hit a big wall. Since Python > is a dynamic language, one would expect to be able to pause the > execution of a function, change the function, and resume execution with > new code--never skipping a beat. But CPython makes this nearly > impossible. I imagine Stackless would provide an answer for this. If > it does, get in contact with ActiveState, Secret Labs, or the Wing IDE > folks and tell them you can make their debugger twice as good as any > other. Just an idea. I think this is a great idea! Btw., Stackless works pretty well with wxPython and Boa. I have a commercial application that uses this. Since you have written the Boa debugger, can you help me what exactly you would need? There has been a request to find the function that created a frame, recently on the main list. Do you think such a feature would make writing edit-and-continue simpler, or is it not needed? There is that call-trace feature which intercepts every code blcok, but you have to guess the function. I'd really like to augment Stackless with everything that makes it into the ideal platform for IDEs. cheers - chris -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 pager +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From danb_83 at yahoo.com Sat Aug 23 11:56:07 2003 From: danb_83 at yahoo.com (Dan Bishop) Date: 23 Aug 2003 08:56:07 -0700 Subject: Modifying the {} and [] tokens References: Message-ID: Geoff Howland wrote in message news:... > I want to modify the {} and [] tokens to contain additional > functionality they do not currently contain, such as being able to add > dicts to dicts, and other things that would be very helpful for me and > my team mates to have. The only way to do that is to modify the C code for the interpreter. Otherwise, you'll have to stick with >>> class NewDict(dict): ... def __add__(self, other): ... result = self.copy() ... result.update(other) ... return result ... >>> NewDict({1:2}) + NewDict({3:4}) {1: 2, 3: 4} From theller at python.net Fri Aug 8 09:23:04 2003 From: theller at python.net (Thomas Heller) Date: Fri, 08 Aug 2003 15:23:04 +0200 Subject: Accessing c objects in python References: Message-ID: Alex Martelli writes: > Dave Kuhlman wrote: > ... > [snipped: C API usage directions] > >> Is there an easier way? I'm not sure, but I'd certainly read the >> following section of the Pyrex documentation. It's about how to >> wrap C structures: >> >> http://ldots.org/pyrex-guide/3-structures.html > ... >> Any Pyrex experts listening in? Am I on the right track here? > > I'm no pyrex expert, but I recently re-evaluated various options > for wrapping large existing C libraries: C API, Boost Python, > Pyste, pyrex, ctypes, and Swig. Somewhat to my surprise (I had > bad memories about it from the past...), Swig came up on top in > terms of simplicity. Pyste might easily be best for _C++_ > libraries, already organized into classes and possibly using > templates &c -- it, in turn, "rests" om Boost Python. Boost > itself -- or pyrex if you'd rather not use C++ for the purpose -- > might likely be best if you want to code some significant amount > of fast logic, not just wrappers. But for "just wrappers", and > C libraries as opposed to C++ ones, Swig rules. > > I'd use the C API directly only if the other tools were ruled > out for some reason (e.g., licensing); it's by far the largest > amount of work -- all other tools rest on top of it and can be > seen as "code generators" for it that save you aggravation. Would you care to write a more detailed summary of your findings? This would probably make a good page in the main Python wiki... Thomas From vincem at en.com Tue Aug 5 15:02:26 2003 From: vincem at en.com (Vincent Marchetti) Date: Tue, 05 Aug 2003 19:02:26 GMT Subject: Python and XML -- Right Thing for path References: <2c60a528.0308031414.4dfe171c@posting.google.com> Message-ID: In article <2c60a528.0308031414.4dfe171c at posting.google.com>, and-google at doxdesk.com (Andrew Clover) wrote: ...> > For some reason, the current working directory is included in Python's > default module search path, before all other directories. If anyone can > explain why this is the Right Thing I'd be interested to know. White the Right Thing to do is probably in the eye of the beholder I find this convention (current working directory at the head of the module search path) very useful for prototyping and tinkering with modules "in a sandbox". I can take a standard module, copy it into a directory not on the search path, and modify it to my hearts content with script in that same folder; only when it works as desired do I "promote" it to my regular search path. Vince Marchetti From p-abel at t-online.de Sat Aug 9 16:17:31 2003 From: p-abel at t-online.de (Peter Abel) Date: 9 Aug 2003 13:17:31 -0700 Subject: regular expression back references References: Message-ID: <13a533e8.0308091217.298429c6@posting.google.com> ruach at chpc.utah.edu (Matthew) wrote in message news:... > Greetings, I am having a problem using back references in my regex and > I am having a difficult time figuring out what I am doing wrong. My > regex works fine with out the back refs but when I try to use them it > won't match my sample. It looks to me that I am using them no > differently then my examples and documentation but to no avail. > > Here is my patteren: > > macExpression = "^[0-9A-F]{1,2}(\:|\.|\-)[0-9A-F]{1,2}\1[0-9A-F]{1,2}\1[0-9A-F]{1,2}\1[0-9A-F]{1,2}\1[0-9A-F]{1,2}$: > > And this is how I am using it: > > matched = re.match(macExpression, macAddress) > > I am trying to match mac addresses in the following formats > 0:a0:c9:ee:b2:c0, 0-a0-c9-ee-b2-c0 & 0.a0.c9.ee.b2.c0 etc. > > I wasn't sure how to do it but then I read about back references and I > thought that all was well... Alas If any one could lend a hand I would > appreciate it very much. > > -matthew Matching even the silliest format of macAdress, the following works for me: >>> silly_adrs=['00-30:65:01.dC:9f', '00:03-93.52.0C-c6', '00-A0:C9.eE:b2.C0'] >>> def mac_adr(any_adr): ... return '.'.join(map(lambda x:str(int(x,16)), re.split('[\:\-\.]',any_adr))) ... >>> for adress in silly_adrs: ... print mac_adr(adress) ... 0.48.101.1.220.159 0.3.147.82.12.198 0.160.201.238.178.192 >>> Regards Peter From FBatista at uniFON.com.ar Wed Aug 6 16:43:07 2003 From: FBatista at uniFON.com.ar (Batista, Facundo) Date: Wed, 6 Aug 2003 17:43:07 -0300 Subject: Stupid string.split question Message-ID: #- Is there any conceptual reason why #- #- "ABCDEF".split("") shouldn't equal ["A", "B", "C", "D", "E", "F"]? #- #- The error says empty seperator, but the result makes sense #- given that #- fact and the fact that: #- #- "".join(["A", "B", "C", "D", "E", "F"]) == "ABCDEF" #- #- It seems that if you can join with an empty seperator, you should be #- able to split with one. Beyond any particular reason, or a better way to do it, seems nice to me to be able to split with empty separator, just to thin of join and split as "complementary" functions (but that's just my opinion). . Facundo From janeaustine50 at hotmail.com Tue Aug 5 23:15:11 2003 From: janeaustine50 at hotmail.com (Jane Austine) Date: 5 Aug 2003 20:15:11 -0700 Subject: FOUND! how to attach to running instances of Internet Explorer References: Message-ID: gcash wrote in message news:... > So I'm running Win2K Pro... and I'm curious about what versions this > works under. I'm pretty sure you have to have IE 5.0 or newer, but > could folks try this code on 95/98 and tell me (gcash-at-cfl.rr.com) > if it works?? > It works perfect with: Win XP Pro Python 2.3 final Thank you. From lorenb2 at bezeqint.net Tue Aug 12 04:42:14 2003 From: lorenb2 at bezeqint.net (Bill Loren) Date: Tue, 12 Aug 2003 10:42:14 +0200 Subject: Howto MACRO in python ? Message-ID: <000b01c360ad$ac3bba30$6400a8c0@EVOD31> Hi, I was looking for a guidance about how to code MACROs in python. any offer ? thx B From jjl at pobox.com Mon Aug 11 20:12:29 2003 From: jjl at pobox.com (John J. Lee) Date: 12 Aug 2003 01:12:29 +0100 Subject: win32, COM, and Solidworks (again) - Still Trying References: <87he4qykqv.fsf@pobox.com> Message-ID: <877k5jwx76.fsf@pobox.com> Markus Wankus writes: > On 09 Aug 2003 15:21:44 +0100, John J. Lee wrote: > > > Markus Wankus writes: > > > >> On Thu, 7 Aug 2003 23:06:01 +1000 (EST), Andrew MacIntyre > >> wrote: > > [...] > >> > If you need to go beyond the IDispatch interface, Thomas Heller's > >> ctypes > >> > package looks to be your only option, short of creating a full-blown > >> > Pythonwin wrapper (ala Pythonwin's MAPI support) for the > >> SolidWorks COM > >> > API. > >> > > >> > >> Yes, I was looking into this but was a little mystified at first. I > >> generated the python wrapper and had a look inside, but was unsure of > >> the extent of the Python code I was going to be required to write, as > >> well as type conversions. > > > > He wasn't talking about the automatically-generated makepy Python > > code, but rather hand-crafted C code wrapper around a particular > > vtable COM interface (though Mark may have some tools to help with the > > process of writing such wrappers, I don't think it's automated). > > > > ctypes is an easy way of doing it than writing a C wrapper. > > > > Hmmm.. I guess I am not following. I'll go back to the ctypes page > again and give it another go. Ah, maybe it was me who wasn't following. I haven't looked at the ctypes COM support. I was thinking you were referring to the win32all-generated Python code, but maybe ctypes does Python code generation too, and you were referring to that? Dunno. John From sdeibel at wingide.com Wed Aug 13 09:59:40 2003 From: sdeibel at wingide.com (Stephan Deibel) Date: 13 Aug 2003 06:59:40 -0700 Subject: Python IDE - "Lite" version available for non commercial use References: <3F395CC7.EFBE63C6@pobox.com> Message-ID: Heiko Wundram wrote in message news:... > On Tue, 2003-08-12 at 23:31, Rick Thomas wrote: > > http://wingide.com/wingide > > The only thing I found so far to get Wing IDE-Lite working was to order > a license file from the people who produce it... This certainly doesn't > mean that it's available for non-commercial use, I guess. > > Anybody else checked this out and cares to enlighten me? Hi, The current deal is that Wing IDE Lite is a feature subset of Wing IDE Standard and it's licensed for non-commercial users only at $35/license (Standard is $149 Linux / $179 other platforms). One-month free trial licenses are also available at http://wingide.com/wingide/demo. However, we do give free permanent licenses to non-commercial open source users that produce open source code from which they don't derive income directly or indirectly (basically, if you get paid we'ld appreciate being paid too!) We've got quite a few such users, including the OSA Foundation (osafoundation.org). Details on the free license: http://wingide.com/wingide/terms#opensource Hope that helps. Questions should go directly to me or sales at wingide.com. Thanks, Stephan Deibel Wing IDE for Python Archaeopteryx Software, Inc. www.wingide.com From peter at engcorp.com Wed Aug 27 14:07:31 2003 From: peter at engcorp.com (Peter Hansen) Date: Wed, 27 Aug 2003 14:07:31 -0400 Subject: learning to program References: <3F4CED6E.D04D35D6@engcorp.com> <5bspkv87u1q0v9aupajrrkjuutuh3f5o44@4ax.com> Message-ID: <3F4CF363.CAF6A14E@engcorp.com> Rich wrote: > > This is the only post I am able to see, sorry about re posting. I > thought if I changed the subject heading I might be able to see the > post. You should be able to see the replies that you missed via Google Groups, as soon as they are indexed and on the web: http://groups.google.com/groups?q=comp.lang.python -Peter From alan.gauld at btinternet.com Mon Aug 18 15:47:36 2003 From: alan.gauld at btinternet.com (Alan Gauld) Date: Mon, 18 Aug 2003 19:47:36 GMT Subject: Python Debugger References: <6ee58e07.0308181134.383a69e7@posting.google.com> Message-ID: <3f412cf3.351547428@news.blueyonder.co.uk> On 18 Aug 2003 12:34:09 -0700, llothar at web.de (Lothar Scholz) wrote: > Is there any python debugger that can > > 1) be used remotely What do you mean by remotely? Debug a program running on a server from a remote PC? Or telnet to the server and display the debug session on the PC? If the latter then the standard pdb module works just fine. > 2) can handle multiple threads Never tried that one, although pdb might work... Alan G. Author of the Learn to Program website http://www.freenetpages.co.uk/hp/alan.gauld From sross at connectmail.carleton.ca Tue Aug 12 10:08:19 2003 From: sross at connectmail.carleton.ca (Sean Ross) Date: Tue, 12 Aug 2003 10:08:19 -0400 Subject: Howto MACRO in python ? References: <3F38D039.2B28800A@engcorp.com> Message-ID: "Bill Loren" wrote in message news:mailman.1060691359.31807.python-list at python.org... > (btw I couldn't find any built-in name which correspands to the current > function name so > I type it myslef every trace call) This recipe will get you the name of the function: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66062 This recipe appears to be able to wrap methods (not functions) as logging methods, which may be useful for you: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/198078 HTH Sean From ask at me.com Sat Aug 23 21:58:42 2003 From: ask at me.com (Greg Krohn) Date: Sun, 24 Aug 2003 01:58:42 GMT Subject: Subclassing ConfigParser References: <3F4621AC.8050002@t-online.de> Message-ID: "Michael Amrhein" wrote in message news:3F4621AC.8050002 at t-online.de... > Hi Greg, > are you sure you have a file 'config.ini' in your current working > directory? ConfigParser is silently ignoring files which cannot be > opened, so that _read is not called! I was getting a ParsingError that showed the line it was choking on, so I know it was finding the file. > > BTW, you did not mention the Python version you are using. In Python 2.3 > the method you overwrite is named '_read', not '__read' (so there is no > name mangling). This is one drawback of overwriting "private" methods, > when the author renames or removes them, your code is broken. I _was_ using ActivePython 2.2 (2.3 isn't out yet). I downloaded the 2.3 regular distro last night because I read ConfigParser was cleaned up, but I haven't had time to mess around with it much. > Anyway, your method of overwriting the method is a bit complicated . You > can do it much easier: just overwrite _read and call the original method > when appropriate: > > class CustomConfigParser(ConfigParser): > def __init__(self, defaults=None): > ConfigParser.__init__(self, defaults) > def _read(self, fp, fpname): > if ... # your criteria for custom ini > then return self._read_custom(fp, fpname) > else return ConfigParser._read(self, fp, fpname) > > def _read_custom(self, fp, fpname): > ... > > Michael Yes, this is great! Everything is working as expected now. Originally I was expecting code like yours to work in 2.2 and when it didn't I tried all sorts of elaborate hacks. What a mess. Thank you very much for your reply. greg From grey at despair.rpglink.com Sat Aug 9 14:03:52 2003 From: grey at despair.rpglink.com (Steve Lamb) Date: Sat, 09 Aug 2003 18:03:52 -0000 Subject: [wxPython] How to tack data onto a node of a tree? Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Ok, this one has me scratching my head. Right now my application is working fine. I have a tree control which contains a 2-level deep tree. The first level is directories while the second level are files in those directories. The user clicks on the file they want to manipulate and it is loaded and parsed into other windows. However I'm doing it in a kludgey fashion and would like to do the proper thing. The kludge is that I could not figure out how to associate data with a particular node within the tree. So for the moment I have set the data to NULL and the node's name is either the directory name or the file name. When the user clicks on the file I then grab the node's name, grab the parent node ID, grab the name of the parent node name and then splice them together. EG: def BuildPath(self, id): ''' Build a path from the node and parent node name''' # This really should be contained in the node data. file = self.FileList.GetItemText(id) parent = self.FileList.GetItemParent(id) path = self.FileList.GetItemText(parent) filepath = path + '/' + file return(filepath) As the comment says, the path to the file should really be contained in the data associated with the node. I've read the documentation for wxTreeItemData and am a little confused. Would something like the following work for assignment? dir = '/dir/to/file' file = 'filename' filepath = wxTreeItemData(dir + '/' + file) self.FileList.Append(dir_node, -1, -1, filepath) I believe that the following would be used to retrieve the data? filepath = self.FileList.GetPyData(id) -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (GNU/Linux) iD8DBQE/NTeIel/srYtumcURAqQ2AJ9HZbdZSSlee+zvRHFVAn4ltNnp+ACdEyf2 XNCzUogZkEAnRtqXQxYX/GU= =phai -----END PGP SIGNATURE----- -- Steve C. Lamb | I'm your priest, I'm your shrink, I'm your PGP Key: 8B6E99C5 | main connection to the switchboard of souls. | -- Lenny Nero - Strange Days -------------------------------+--------------------------------------------- From mpeuser at web.de Sun Aug 17 03:39:38 2003 From: mpeuser at web.de (Michael Peuser) Date: Sun, 17 Aug 2003 09:39:38 +0200 Subject: cPickle alternative? References: <87r83l3jmj.fsf@cassandra.evansnet> Message-ID: So stupid of me :-((( Now here are the benchmarks I got from Drochems dataset. I think it should sufice to use the binary mode of 2.2. (I checked the 2.3 data on a different disk the other day - that made them not comparable!! I now use the same disk for the tests.) Timings (2.2.2): Generation of data: 18 secs Dunping: 3 secs Loading: 18,5 sec Filesize: 5,5 MB Binary dump: 2,4 Binary load: 3 Filesize: 2,8 MB 2.3 Generation of data: 9 secs Dumping: 2,4 Loading: 2,8 Binary dump: 1 Binary load: 1,9 Filesize: 2,8 MB Mode 2 dump: 0,9 Mode 2 load: 1,7 Filesize: 2,6 MB The musch faster time for generating the data in 2.3 could be due to an improved random generator (?) That had alwys been quite slow.. Kindly Michael P "Tim Evans" schrieb im Newsbeitrag news:87r83l3jmj.fsf at cassandra.evansnet... > "Michael Peuser" writes: > > > Hi Drochem, > > > > (1) Your dataset seems to break the binary cPickle mode ;-) (I tried it with > > the "new Pickle" in 2.3 - same result: "EOF error" when loading back...) May > > be there is someone interested in fixing this .... > [snip] > > > f=open ("test","w") > [snip] > > > f=open ("test") > [snip] > > Note that on windows, you must open binary files using binary mode > when reading and writing them, like so: > > f = open('test', 'wb') > f = open('test', 'rb') > ^^^^ > > If you don't do this binary data will be corrupted by the automatic > conversion of '\n' to '\r\n' by win32. This is very likely what is > causing the above error. > > -- > Tim Evans From DaveInRedmond at earthlink.net Fri Aug 22 14:07:06 2003 From: DaveInRedmond at earthlink.net (Dave In Redmond) Date: Fri, 22 Aug 2003 18:07:06 GMT Subject: Idle/Python 2.3 installation problems - 2nd pass Message-ID: Hopefully this is a simple nooB issue. Python seems to work but idle works only when I'm root. When I'm logged in as dave, I get the following error: [dave at Pippin Python-2.3]$ idle Xlib: connection to ":0.0" refused by server Xlib: No protocol specified Traceback (most recent call last): File "/usr/local/bin/idle", line 4, in ? main() File "/usr/local/lib/python2.3/idlelib/PyShell.py", line 1264, in main root = Tk(className="Idle") File "/usr/local/lib/python2.3/lib-tk/Tkinter.py", line 1564, in __init__ self.tk = _tkinter.create(screenName, baseName, className) _tkinter.TclError: couldn't connect to display ":0" [d Here are the steps I ran through: - downloaded the tarball onto a RH9/KDE platform, - did a gunzip and tar, - ran the ./configure with --enable-unicode=ucs4 - did the make - switched to root and did the make install - after it failed I did a make clean and ran through the same steps with the same results (d'oh!) Any suggestions? From ark at gmx.net Thu Aug 21 06:27:53 2003 From: ark at gmx.net (Arne Koewing) Date: Thu, 21 Aug 2003 12:27:53 +0200 Subject: gdbm compatibility between linux and freebsd References: <95f72778.0308210010.5b493c9b@posting.google.com> Message-ID: <877k57paom.fsf@gmx.net> bucket79 at daum.net (bucket79) writes: > here's a problem ... > and the problem is gdbm db file is not compatible between two system > for example ... > anyone know what is the casuse of this problem? Yes and No ;-) I do not think that gdbm-files could be considered 'portable' (gdbm surely is, the files are (sometimes) not) on freebsd systems `off_t` is (sometimes) 8 bytes, while on most others it's just 4 bytes. try changing off_t" to "loff_t" in gdbmdefs.h and recompile libgdmb (breaking existing databases on the system !!!! ) or use some other format for interchanging information. some people say bdb is not that problematic but I don't know... (I'll treat all *db databases non-portable) bdb databases can be be dumped to some interchangeable format. Arne -- From faizan at jaredweb.com Fri Aug 1 21:26:26 2003 From: faizan at jaredweb.com (Fazer) Date: 1 Aug 2003 18:26:26 -0700 Subject: String Replacement References: <7b454334.0308011400.266438f9@posting.google.com> Message-ID: <7b454334.0308011726.15d12be9@posting.google.com> Hmm... This works: print string.replace(str, "\n", "
") But I can't assign the result into a variable but only print it like the code above. What can I do to assign the repalced string to a variable? Because I Have other string replacements to do with that very same string. Thanks, From bignose-hates-spam at and-benfinney-does-too.id.au Wed Aug 13 02:30:35 2003 From: bignose-hates-spam at and-benfinney-does-too.id.au (Ben Finney) Date: 13 Aug 2003 16:20:35 +0950 Subject: unsigned int \ long References: Message-ID: On Wed, 13 Aug 2003 08:40:50 +0300, Roman Yakovenko wrote: > Hi. I need to work with integer as unsigned integer, but I can't find > documentation how can I do it. I'm not aware that Python has such a concept. Perhaps if you explain what you want to do that seems to require an explicit unsigned type, we can come up with a way to do it. -- \ "I like my dental hygenist, I think she's very pretty; so when | `\ I go to have my teeth cleaned, while I'm in the waiting room I | _o__) eat an entire box of cookies." -- Steven Wright | Ben Finney From pinard at iro.umontreal.ca Wed Aug 13 08:00:51 2003 From: pinard at iro.umontreal.ca (Francois Pinard) Date: 13 Aug 2003 08:00:51 -0400 Subject: Emacs [was: Re: Multi-Line Comment] In-Reply-To: References: <4qofjvg3bh9smlnb1do4f0lhjga7bacnu3@4ax.com> <200308122306.48320.shalehperry@comcast.net> Message-ID: [Doug Tolton] > Man, I wonder if I'll even learn 10% of the Emacs keystrokes. And then, you'll realise than pre-made keystrokes are only a small part of all available commands. And then, you'll realise that all available commands are only a small part of all available functions. And, of course, all of the above is only a small drop in the ocean of possibilities given by the capability of extending the editor with new functions. At times, I wonder if this should be seen as comforting or frightening. :-) -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From eric.brunel at pragmadev.com Fri Aug 1 06:01:32 2003 From: eric.brunel at pragmadev.com (Eric Brunel) Date: Fri, 01 Aug 2003 12:01:32 +0200 Subject: Tkinter programming problem References: <2830c89c.0308010048.403a2a19@posting.google.com> Message-ID: Andrew Gregory wrote: > Could someone help me out with these few lines of code: I would like > to know why the Quit button in this application removes the buttons > and causes "Quitting" to be printed, but does not close the outer > frame. > > Andrew. > > > # Demonstration TK interface Windows application > # Runs ok from within IDLE > # > from Tkinter import * > > class CommonStuff: # to get common access to variables and functions > def __init__(cself, frame): > cself.frame = frame It is a Bad Idea to give the first parameter of a method any other name than "self"... Checking tools like PyChecker will complain if you do that, and your programs will be harder to read for anyone else doing Python... > def say_hi(cself): > print "Hello all" > > > class MyWidgets(Frame, CommonStuff): > def __init__(wself, CS): > Frame.__init__(wself, CS.frame) Where have you found this type of Tkinter object initialization? Apparently, there are weird style guides lying around somewhere... You can rewrite all of this: > wself.quitbutton = Button(wself) > wself.quitbutton["text"] = "Quit" > wself.quitbutton["fg"] = "red" > wself.quitbutton["command"] = wself.destroy > > wself.quitbutton.pack({"side": "left"}) like that: wself.quitbutton = Button(wself, text='Quit', fg='red', command=wself.destroy) wself.quitbutton.pack(side=LEFT) This is the most common way to do things. BTW, since you never do anything to the buttons themselves ouside this method, there's no need at all to store them in attributes. So you can just do: quitbutton = Button(wself, text='Quit', fg='red', command=wself.destroy) quitbutton.pack(side=LEFT) or even: Button(wself, text='Quit', fg='red', command=wself.destroy).pack(side=LEFT) > wself.hi_there = Button(wself) > wself.hi_there["text"] = "Hello", > wself.hi_there["command"] = CS.say_hi > > wself.hi_there.pack({"side": "left"}) Same here: wself.hi_there = Button(wself, text="Hello", command=CS.say_hi) wself.hi_there.pack(side=LEFT) or: hi_there = Button(wself, text="Hello", command=CS.say_hi) hi_there.pack(side=LEFT) or even: Button(wself, text="Hello", command=CS.say_hi).pack(side=LEFT) > > class Application: > def __init__(self, master): > self.frame=Frame(master) > CS = CommonStuff(self.frame) > > displayedwidget=MyWidgets(CS) > displayedwidget.grid(row=0, column=0) > self.frame.grid(row=0, column=0) > self.frame.columnconfigure(0) This statement is a no-op: you say you'll configure the column n#0 of self.frame, but you do not give any features for the column. What are you trying to do? > displayedwidget.bind("", self.quit) > self.frame.update() > > def quit(self, event): > print"Quitting..." > self.frame.destroy # Destroy frame and all children Compare this line to the last in the __init__ method just above. To call the update method on self.frame, you did self.frame.update(). So to call the destroy method on self.frame, you must do self.frame.destroy(). self.frame.destroy merely returns the destroy method of the self.frame object, but doesn't do anything with it. > root = Tk() > mainWin = Application(root) > root.wait_window(mainWin.frame) I don't know if this works, but I know it's not the usual way to run a Tkinter application. You'd better replace the last line by: root.mainloop() HTH -- - Eric Brunel - PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com From eric.brunel at pragmadev.com Fri Aug 29 11:58:18 2003 From: eric.brunel at pragmadev.com (Eric Brunel) Date: Fri, 29 Aug 2003 17:58:18 +0200 Subject: Getting class name References: Message-ID: Travis Whitton wrote: > Hello all, > I've googled a bit, and I've failed to find an answer to this question. Is it > possible to get a classes name from inside of a class? I.e., > > class Foo: > def print_classname(self): > # somehow print Foo > > Basically, I'm using WebWare, and I need to pass the current servlet name > to a template. I don't want to have to hardcode the classname inside of > every servlet. print self.__class__.__name__ HTH -- - Eric Brunel - PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com From jjl at pobox.com Wed Aug 20 18:27:34 2003 From: jjl at pobox.com (John J. Lee) Date: 20 Aug 2003 23:27:34 +0100 Subject: Python: executing ping and whois References: <538fc8e.0308201303.46c58c8b@posting.google.com> Message-ID: <8765ks0xt5.fsf@pobox.com> wim_wauters at skynet.be (WIWA) writes: > Anybody that could tell me how to execute some Linux commands using > Python. [...] os.system, os.popen*, popen2 module. Also http://pexpect.sourceforge.net/ John From bdesth.nospam at removeme.free.fr Thu Aug 28 15:27:37 2003 From: bdesth.nospam at removeme.free.fr (Bruno Desthuilliers) Date: Thu, 28 Aug 2003 21:27:37 +0200 Subject: Python quote of the week? In-Reply-To: <3F4E42F2.BA7FB9F9@engcorp.com> References: <3F4E42F2.BA7FB9F9@engcorp.com> Message-ID: <3f4e554e$0$27038$626a54ce@news.free.fr> Peter Hansen wrote: > Simon Brunning wrote: > >>"All that rigid type safety and data hiding is like wearing army boots on >>the beach: nothing can bite your toes, but golly don't it feel good to just >>toss 'em and run barefoot." >> (snip) > Going barefoot is of course also the more agile way to go: > > "Be more agile: program barefoot, with Python." > Beware, some might read it as 'program with your feet with Python' !-) Bruno From lamar_air at hotmail.com Tue Aug 12 11:59:58 2003 From: lamar_air at hotmail.com (lamar_air) Date: 12 Aug 2003 08:59:58 -0700 Subject: Test to see if variable exists Message-ID: <2c6431ab.0308120759.26d6e124@posting.google.com> I need an if statement to test if a variable exists in a pyton script eg. if var1 exists: do this else: do this From kdahlhaus at yahoo.com Mon Aug 4 10:07:57 2003 From: kdahlhaus at yahoo.com (Kevin Dahlhausen) Date: 4 Aug 2003 07:07:57 -0700 Subject: Python and Robotics? References: <3f2d1e1d$0$4192$afc38c87@news.optusnet.com.au> Message-ID: <283adf56.0308040607.3b91aaf1@posting.google.com> I once wrote a utility to exercise the electronics on an embedded steering system in Python. There's a photo at http://members.nccw.net/kdahlhaus/python/hwt.html, but I don't have the code anymore. It worked very well. I don't know the real-time aspects of Python, so you'd certainly want to research that. Darren wrote in message news:<3f2d1e1d$0$4192$afc38c87 at news.optusnet.com.au>... > Hello All, > Hope everyone is well. > I am really new to python, so my question maybe some what stupid to > some. The question is, can python be used as a programming language for > robotics? eg, controling motors and sensors? > If so, do you know any website that would contain such information ? > > Many thanks > Darren From sdhyok at yahoo.com Sun Aug 24 14:17:13 2003 From: sdhyok at yahoo.com (sdhyok) Date: 24 Aug 2003 11:17:13 -0700 Subject: How to import a standard module in source file with same name? References: <420ced91.0308232052.70e905d5@posting.google.com> Message-ID: <420ced91.0308241017.1b5e2a4f@posting.google.com> In addition, you can't import the standard datetime with the following script in vp/datetime.py. Daehyok > import datetime > import vp.datetime > vp.datetime.datetime = datetime From heikowu at ceosg.de Tue Aug 19 01:39:02 2003 From: heikowu at ceosg.de (Heiko Wundram) Date: Tue, 19 Aug 2003 07:39:02 +0200 Subject: What's better about Ruby than Python? In-Reply-To: References: Message-ID: <1061271542.2992.30.camel@d168.stw.stud.uni-saarland.de> On Mon, 2003-08-18 at 19:40, John Roth wrote: > This is why Ruby's solution is superior: "self" is a reserved word, > and so is the special character shortcut. There is no question as > to what is meant. It eliminates essentially futile arguements in the > same way that Python's indentation eliminates arguements about > the proper placement of braces. I think you're not getting the main point in a difference between Ruby and Python here, and why it makes (IMHO) no sense to have a default self in a function: class X: def test(*args): print args X.test() # 1 x = X() x.test() # 2 X.test(x) # 3 Run this, and for the first call you will get an empty tuple, while for the second call, you will get a tuple with the first parameter set to a class instance of X, and for the third call the same as for the second call. Remember about method binding (method/function difference), and the like. I want to have class-functions which can be callable either as a function of the class (doing something on input-data), or work directly on the instance they are associated with. If you have a predeclared self, only calls 2 and 3 would work, if the self parameter is just another parameter for the function, I can miraculously call the function just like it is (see call 1). I find it reasonable enough to have a feature like this to not complain about having to specify self as the first parameter, always. Heiko. From kern at taliesen.caltech.edu Wed Aug 27 06:43:13 2003 From: kern at taliesen.caltech.edu (Robert Kern) Date: Wed, 27 Aug 2003 10:43:13 +0000 (UTC) Subject: ezPyCrypto keys References: Message-ID: In article , John Hunter writes: [snip] > What's going on? Is it abnormal for so many of the characters in the > exported string to be the same? The machine I am running on is a > server that rarely has anyone logged in directly. Is this a problem > with not enough randomness in /dev/random? As Heiko suggests, it's just the serialization protocol that is creating this effect. ezPyCrypto keeps the key as a Python long, pickles it along with other information, then base64-encodes the resulting string. The pickled representation of a long doesn't contain the raw bytes; it contains the string representation, so the pickle contains a lot of decimal digits rather than a full 0-255 range of bytes. Naturally, this representation has redundancy which is made more apparent by the base64-encoding. All 2048 bits of entropy should still be there. > Thanks for any suggestions, > John Hunter -- Robert Kern kern at caltech.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter From dippy at mikka.net.au Fri Aug 15 12:20:43 2003 From: dippy at mikka.net.au (Steven) Date: Fri, 15 Aug 2003 16:20:43 GMT Subject: Module access from inside itself Message-ID: I'm writing a Python script which can be called from the command-line, and I want to use my module doc string as the CL help text, but I don't know how to access my module object from inside the module. I've tried searching for an answer, but haven't found anything. Please excuse me if I'm missing something simple, I'm a newbie to Python. I'm doing something like this: #!/usr/bin/python """Module doc string goes here. """ import getopt, sys def MyFunction(args): ? ? pass if __name__ == "__main__": ? ? opts, args = getop.getopt(sys.argv[1:], [], ["help"]) ? ? for opt in opts: ? ? ? ? if opt == "--help": ? ? ? ? ? ? print MY_MODULE.__doc__ ? ?# How do I get this? ? ? ? ? else: ? ? ? ? ? ? MyFunction(args) How do I get a reference to the module from inside the module? Is this the Pythonic way of generating help strings for CL scripts? Thanks, -- Steven D'Aprano From vanevery at 3DProgrammer.com Tue Aug 19 02:01:33 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Mon, 18 Aug 2003 23:01:33 -0700 Subject: Brandon's personal style (was) References: <55143354.0308181649.7a25d74@posting.google.com> Message-ID: G. Feldman wrote: > "Brandon J. Van Every" wrote in message > news:... > >> Well, I'll freely own up to being rude and intellectually violent. > >> It's annoying when people can't/won't tell the difference. > > By admitting to being rude, your annoyance becomes irrelevant. > Rudeness indicates a disregard for others, hence it's correct and > appropriate for others to disregard your feelings about the use of the > term troll. Sure. And I just killfile them. It makes all our lives easier. Very rational, emotionless, antiseptic solution. I like it! > If you want people to care about what you say, you need to care enough > about them to be polite about it. This really all comes down to one's Rules Of Engagement. Everyone has their own coda and mores, whether implicit or explicit, about what kind of communication they think is acceptable and what isn't. I rarely break my own ROE. However, I know that other people don't share my ROE, and interpret my behavior according to their own ROE. This can lead to troublesome reverberations that neither one of us finds acceptable. I end the bad vibrations by putting people in my killfile, immediately. One of my Meyers-Briggs type components is "Thinker." "Thinkers" and "Feelers" can be big, big trouble for each other. They often have pretty opposite ideas about what's important in a debate. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From michael at stroeder.com Mon Aug 4 14:16:26 2003 From: michael at stroeder.com (=?ISO-8859-1?Q?Michael_Str=F6der?=) Date: Mon, 04 Aug 2003 20:16:26 +0200 Subject: Developping an EAI server in Python : looking for developpers In-Reply-To: References: Message-ID: Alexander DEJANOVSKI wrote: > > I'm starting a new project to develop an Open-Source EAI server in Python > and I'm looking for motivated developpers and testers. > It is inspired by Open Adaptor (_www.openadaptor.org_ > ), but aims to be easier > to use and more powerful. I'd be willing to contribute to the LDAP-related parts. Ciao, Michael. From imbosol at aerojockey.com Wed Aug 6 18:57:26 2003 From: imbosol at aerojockey.com (Carl Banks) Date: Wed, 06 Aug 2003 22:57:26 GMT Subject: Python's biggest compromises References: Message-ID: Alex Martelli wrote: > "Ada", on the other hand, being the start of "Adam", might claim > older genesis. I disagree. Ada refers to a specific person, Ada Lovelace, who lived in the 19th century, and was credited as the world's first programmer. Python, Pascal, Java, and C (which goes back to the Etruscans, at least) all predate Ada. -- CARL BANKS "You don't run Microsoft Windows. Microsoft Windows runs you." From mack at incise.org Sun Aug 31 17:37:33 2003 From: mack at incise.org (mackstann) Date: Sun, 31 Aug 2003 16:37:33 -0500 Subject: list.sort(func) speed In-Reply-To: <1062364123.1852.53.camel@adsl-209.204.179.133.sonic.net> References: <20030831190745.GH9311@incise.org> <1062360910.1852.44.camel@adsl-209.204.179.133.sonic.net> <20030831203354.GK9311@incise.org> <1062364123.1852.53.camel@adsl-209.204.179.133.sonic.net> Message-ID: <20030831213733.GL9311@incise.org> On Sun, Aug 31, 2003 at 02:08:43PM -0700, Chad Netzer wrote: > On Sun, 2003-08-31 at 13:33, mackstann wrote: > > > No, but the thought of inserting things in order did not quite occur to > > me. Can you give me an simple example of exactly how to go about this? > > Don't have time for an example at the moment. But the bisect module > will do it for you. > > help('bisect') > help('bisect.insort') > > The basic way in which it works (I assume, having not looked at the > code), is a binary search algorithm, which is very fast. Cool. >>> from bisect import insort >>> l = [(1,'old'), (2,'old'), (3,'old')] >>> insort(l, (2,'new')) >>> l [(1, 'old'), (2, 'new'), (2, 'old'), (3, 'old')] Thanks, -- m a c k s t a n n mack @ incise.org http://incise.org A long-forgotten loved one will appear soon. Buy the negatives at any price. From pierofoto at tiscali.it Sun Aug 31 08:21:58 2003 From: pierofoto at tiscali.it (Piero) Date: Sun, 31 Aug 2003 14:21:58 +0200 Subject: My emails for you! Message-ID: <_Rl4b.28532$w8.16295@news.edisontel.com> > > > > ginarette at libero.it pierofoto at tiscali.it marianeri1 at tiscali.it lilianaverdis at tiscali.it ginarette at tiscali.it cinziaferretti1 at tiscali.it silviaferro1 at tiscali.it silviogresso at tiscali.it mariocecci at tiscali.it pinoriporto at tiscali.it pierofoto at tiscali.it marianeri1 at infinito.it lilianaverdis at infinito.it ginarette at infinito.it cinziaferretti1 at infinito.it silviaferro1 at infinito.it silviogresso at infinito.it mariocecci at infinito.it pinoriporto at infinito.it fotopiero at infinito.it marianeri1 at libero.it lilianaverdis at libero.it cinziaferretti1 at libero.it silviaferro1 at libero.it silviogresso at libero.it mariocecci at libero.it ginoalberi at libero.it pinoriporto at libero.it piero-foto at libero.it marianeri2 at virgilio.it lilianaverdis at virgilio.it ginarette at virgilio.it cinziaferretti2 at virgilio.it silviaferro2 at virgilio.it silviogresso at virgilio.it mariocecci at virgilio.it ginoalberi at virgilio.it pinoriporto at virgilio.it piero-foto at virgilio.it From mertz at gnosis.cx Thu Aug 14 21:46:21 2003 From: mertz at gnosis.cx (David Mertz) Date: Thu, 14 Aug 2003 21:46:21 -0400 Subject: Recommendation of a parser generator References: Message-ID: fortepianissimo at yahoo.com.tw (Fortepianissimo) wrote previously: |Hi Andrew (and others who replied) - thanks for the extensive tip. |However I ended up in using Simpleparse, cuz (1) I read from Charming |Python column that SPARK is *very* slow (it uses Earley algorithm) (2) |Simpleparse turns out to be not that outdated - the latest one (2.0, |in alpha) was released in 2002. FWIW, in my book, I document and compare mxTextTools, SimpleParse, and PLY in some detail. I decided to look at PLY rather than SPARK for the book; the approaches of SPARK and PLY are similar, but I liked a few things better in the latter (post my CP installment on SPARK). You can read the book for free at: . But if you feel like buying the dead-trees version, use the link below to give me a few extra dollars: X-Shameless-Plug: Buy Text Processing in Python: http://tinyurl.com/jskh -- mertz@ _/_/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY: \_\_\_\_ n o gnosis _/_/ Postmodern Enterprises \_\_ .cx _/_/ \_\_ d o _/_/_/ IN A WORLD W/O WALLS, THERE WOULD BE NO GATES \_\_\_ z e From usenet_spam at janc.invalid Sun Aug 17 00:15:51 2003 From: usenet_spam at janc.invalid (JanC) Date: Sun, 17 Aug 2003 04:15:51 GMT Subject: CDR Support References: Message-ID: [fixed quoting] [python newbie] >>> I'm starting to write a simple backup program using wxPython. But I >>> figure I might as well support rewritable CDROM that most people use. ( >>> I still don't have one, that's just wrong). >>> >>> Does anyone have knowledge of support for rewriteable CDROM's in >>> python? [Aahz] >> Is this for Linux or something else? I'd suggest that you simply write >> a wrapper around mkisofs and cdrecord. [python newbie] > Actually, it's for Windows. The open source tools cdrecord, mkisofs & cdrdao exist for Windows too. cdrecord + mkisofs = cdrtools: cdrdao: -- JanC "Be strict when sending and tolerant when receiving." RFC 1958 - Architectural Principles of the Internet - section 3.9 From irmen at -NOSPAM-REMOVETHIS-xs4all.nl Tue Aug 26 14:02:40 2003 From: irmen at -NOSPAM-REMOVETHIS-xs4all.nl (Irmen de Jong) Date: Tue, 26 Aug 2003 20:02:40 +0200 Subject: Uncatchable socket.error in socket.py (?) In-Reply-To: References: Message-ID: <3f4ba0bb$0$49103$e4fe514c@news.xs4all.nl> Rune wrote: > Now, enough words: What I wonder is: Can I catch that socket.error? By not doing from socket import * but rather import socket (and prefixing your code with "socket." where it's needed). The socket.error you tried to catch is coming from the socket object that you placed in your namespace by doing the "from" import. And the socket class doesn't have an "error" attribute ;) --Irmen From roshweb at softhome.net Thu Aug 7 23:46:02 2003 From: roshweb at softhome.net (Roshan Revankar) Date: Fri, 8 Aug 2003 09:16:02 +0530 Subject: Python-list -- confirmation of subscription -- request 289893 In-Reply-To: <20030803063736.25913.67598.Mailman@mail.python.org> References: <20030803063736.25913.67598.Mailman@mail.python.org> Message-ID: <20030808091602.05d26e51.roshweb@softhome.net> On Sun, 03 Aug 2003 02:37:36 -0400 python-list-request at python.org wrote: > Python-list -- confirmation of subscription -- request 289893 > > We have received a request from 219.65.134.116 for subscription of > your email address, , to the > python-list at python.org mailing list. To confirm the request, please > send a message to python-list-request at python.org, and either: > > - maintain the subject line as is (the reply's additional "Re:" is > ok), > > - or include the following line - and only the following line - in the > message body: > > confirm 289893 > > (Simply sending a 'reply' to this message should work from most email > interfaces, since that usually leaves the subject line in the right > form.) > > If you do not wish to subscribe to this list, please simply disregard > this message. Send questions to python-list-admin at python.org. -- Roshan Revankar http://roshweb.blogspot.com From jimmy at retzlaff.com Tue Aug 12 07:52:55 2003 From: jimmy at retzlaff.com (Jimmy Retzlaff) Date: Tue, 12 Aug 2003 04:52:55 -0700 Subject: Is Python your only programming language? Message-ID: Joe Cheng wrote: > I'm curious about something... many Artima.com members who have a Java > background and learned Python have come to the conclusion that Java and > Python are highly complimentary languages. They would never consider > filling the place Java has in their toolbox with Python, but recognize there > are many tasks where it really pays to add Python to the mix. > > I want to ask you hard-core c.l.p Pythonistas: Do you use Python for > everything? (and I'm counting Python + C extensions as just Python) Or do > you keep another language equally close at hand, and if so, what is it? And > finally, do you foresee a day when Python can be, for all practical intents > and purposes, your only programming language? I'm almost exclusively using Python and SQL these days. Before discovering Python I was mainly using C++ and SQL with a little Java and a little VBScript (in ASP). Within a few months all new code was in Python/SQL and the other languages were only used for maintenance. After a couple years of that, we found that it was often easier to translate subsystems into Python than to add features in the other languages. That was all at my previous job. In my current position we used to occasionally write some C (Python C API) or C++ (Boost) extensions. Since installing psyco and ctypes I don't think we've written a single line of C/C++ and we've even migrated some of those extensions to Python. Our core product is a Python application. You can see a few screenshots at http://www.averdevelopment.com. It contained about 30K lines of Python at last count. Jimmy From ulope at gmx.de Sun Aug 31 07:24:12 2003 From: ulope at gmx.de (Ulrich Petri) Date: Sun, 31 Aug 2003 13:24:12 +0200 Subject: list as paremeters... References: <3f51ce6e$0$26843$626a54ce@news.free.fr> Message-ID: "shagshag13" schrieb im Newsbeitrag news:3f51ce6e$0$26843$626a54ce at news.free.fr... > hello, > > i have an unexpected behaviour that i didn't understand, can someone explain > this to me ? > > >>> def doit(s, stack = []): > if s == '': > return stack > > stack.append(s[:1]) > return doit(s[1:], stack) > > >>> doit('this') > ['t', 'h', 'i', 's'] > >>> doit('this') > ['t', 'h', 'i', 's', 't', 'h', 'i', 's'] > >>> doit('this') > ['t', 'h', 'i', 's', 't', 'h', 'i', 's', 't', 'h', 'i', 's'] > > and so on ... i would expect it to stuck to > >>> doit('this') > ['t', 'h', 'i', 's'] > > why does this 'stack' remind of previous call ? > Try this: >>> def doit(s, stack=None): if stack == None: stack=[] if s == '': return stack stack.append(s[:1]) return doit(s[1:], stack) The problem is the default value auf stack. IIRC Default values are not created each time the function called but rather only the first time (am i correct here?). And since a list is mutable it "rememberes" the previous value. Ciao Ulrich From hjwidmaier at web.de Fri Aug 15 06:15:42 2003 From: hjwidmaier at web.de (Hans-Joachim Widmaier) Date: 15 Aug 2003 03:15:42 -0700 Subject: 2.3: test test_normalization failed References: <7h33cg4403q.fsf@pc150.maths.bris.ac.uk> Message-ID: <6e990e29.0308150215.62730c02@posting.google.com> Michael Hudson wrote in message news:<7h33cg4403q.fsf at pc150.maths.bris.ac.uk>... [test failure with 4.0.0] > This is known: Python from CVS explicitly requests the 3.2 file. Maybe test_normalization.py should look at the file version itself and tell the unsuspicious that it really wants the 3.2 version. > I would imagine it being something like unicode 4 adding more > characters, but Python 2.3 -- being built on 3.2 normalization data -- > doesn't know how these new character compose or decompose. Just a > guess. Sounds reasonable. So the 2.3 normalization is just incomplete regarding the newest standard. Dismissed. Thanks, Hans-Joachim From whiteywidow at yahoo.com Sun Aug 3 02:57:32 2003 From: whiteywidow at yahoo.com (RT Lange) Date: Sun, 03 Aug 2003 02:57:32 -0400 Subject: 2.3 Redhat 9 Tkinter IDLE Message-ID: im trying to get idle to work and its really getting frustrating (and from what ive read on other posts i am not alone) i think i have to edit the Modules/Setup file but im confused as to what to uncoment and what to change. i dont know where my Tcl/Tk libraries are i think my Tcl/Tk headers are in /usr/include/ (not in /usr/local/include) im not sure where my X11 headers are (they werent in /usr/x11r6/include) Tix/BLT - dont know what those are im pretty sure my tcl/tk version is 8.3(rpm -qa tcl/tk reveals 8.3.5-88) and so then i should rebuild and reinstall. and then "Make sure to enable the _tkinter module as well as the TKPATH variable definition."(not sure what they mean by enable or what to do with TKPATH) 2 questions: Why does this have to be so difficult? Can anyone provide step by step inststructions? From robin at jessikat.fsnet.co.uk Wed Aug 6 13:00:25 2003 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Wed, 6 Aug 2003 18:00:25 +0100 Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> Message-ID: In article , Aahz writes .... > >(Yes, there are issues with Python on SMP machines, but to call Python's >built-in threading "non-existent SMP scalability" is either a lie or >revelatory of near-complete ignorance. That doesn't even count the >various IPC mechanisms.) I'm not an expert, but the various grid computation schemes seem to prefer either java or c/c++, I suspect that those schemes aren't really using threads in main, after all they seem to be running between machines in different parts of the world even. I suspect Python would be in better shape if we could migrate threads or tasklets from one processor to another. I believe pyro can almost do that, but I haven't tried it. -- Robin Becker From bokr at oz.net Fri Aug 1 21:50:39 2003 From: bokr at oz.net (Bengt Richter) Date: 2 Aug 2003 01:50:39 GMT Subject: String Replacement References: <7b454334.0308011400.266438f9@posting.google.com> <7b454334.0308011726.15d12be9@posting.google.com> Message-ID: On 1 Aug 2003 18:26:26 -0700, faizan at jaredweb.com (Fazer) wrote: >Hmm... > >This works: >print string.replace(str, "\n", "
") ^^^BZZZT! Don't use builtin names for your stuff!! It will bite you. > >But I can't assign the result into a variable but only print it like >the code above. if print string.replace(str, "\n", "
") worked, xxx = string.replace(str, "\n", "
") print xxx ought to give the same result, with xxx available for further use. > >What can I do to assign the repalced string to a variable? Because I >Have other string replacements to do with that very same string. > If you post copy/pasted logs of interactive experiments showing that e.g., you "can't assign the result," or whatever else is not acting like you think it should, it would be easier to help. Just saying is not like showing ;-) Regards, Bengt Richter From dialtone#NOSPAM#.despammed at aruba.it Tue Aug 26 15:11:30 2003 From: dialtone#NOSPAM#.despammed at aruba.it (Dialtone) Date: Tue, 26 Aug 2003 21:11:30 +0200 Subject: My future Python IDE article References: Message-ID: <87smno1bfh.fsf@vercingetorix.caesar.org> mertz at gnosis.cx (David Mertz) writes: > So c.l.py readers... make the case for your favorite one getting on the > list. I have a while to ponder the opinions advanced, should this > prompt some discussion (it may take a little while to order review > copies of commercial tools and/or get things installed). This one is easy :). My voting goes for: 1) Emacs + python-mode + ipython as interactive shell inside emacs + speedbar as class browser (I use this... actually I use emacs for everything :)) 2) Eric3 3) Eclipse + Trustudio 4) Another one randomly PS: Under windows my favourite is PythonWin -- Valentino Volonghi, Regia SpA, Milan Linux User #310274, Debian Sid Proud User From twomack at chiark.greenend.org.uk Mon Aug 18 02:19:45 2003 From: twomack at chiark.greenend.org.uk (Thomas Womack) Date: 18 Aug 2003 07:19:45 +0100 (BST) Subject: python threads on multi-CPU machines Message-ID: If I have a dual-processor hyperthreaded machine (so with four CPU contexts), will a python program distribute threads over all four logical processors? I ask because I'm fairly sure that this *does* happen using the threading extensions in MFC, and fairly sure that it *doesn't* when using Java, so I don't see that the result is obvious for python. Tom From emiddelb at mpifr-bonn.mpg.de Wed Aug 20 08:38:08 2003 From: emiddelb at mpifr-bonn.mpg.de (Enno Middelberg) Date: 20 Aug 2003 12:38:08 GMT Subject: Problem installing ppgplot References: Message-ID: Hi, thanks for your answer. >The correct file to look for is libcpgplot.a. Ok, I have added libcpgplot.a to $PGPLOT_DIR and the setup.py script now finishes with copying build/lib.linux-i686-2.2/ppgplot.so -> /homes/emiddelb/local2/lib/python2.2/site-packages But still I do have only the ppgplot.so file, and python keeps complaining about "No module named ppgplot". What's missing? Regards, Enno From rupole at hotmail.com Fri Aug 8 23:11:15 2003 From: rupole at hotmail.com (Roger Upole) Date: Fri, 8 Aug 2003 20:11:15 -0700 Subject: win32com, string array --> Type mismatch? References: <70df36e9.0308081207.550c1dc1@posting.google.com> Message-ID: <3f343831_1@corp-news.newsgroups.com> I've run into the same problem with Reflection. This is what I do to get around it: import win32com.client ###win32com.client.gencache.EnsureDispatch('Reflection2.Application',0) ###only need to do above once ra=win32com.client.Dispatch('Reflection2.Application') m=win32com.client.gencache.GetModuleForProgID('Reflection2.Application') r=m.Application(ra) r.Visible=1 r.WaitForStrings(('xxxxx','yyyyyy'),0,1) I'm probably using an older version of Reflection than you are (there is no Session object) but the same principles should apply. hth Roger "Harry Pehkonen" wrote in message news:70df36e9.0308081207.550c1dc1 at posting.google.com... > I'm running WRQ's Reflection telnet client > (win32com.client.Dispatch("Reflection2.Session")). It appears I can > only do late binding. There is one method that takes a ``string > array,'' and fails with: > > Traceback (most recent call last): > File "", line 1, in ? > File "Reflection.py", line 549, in goto_switch > result = self.connection.WaitForStrings(waitfor_strngs) > File "Reflection.py", line 399, in WaitForStrings > options) > File "", line 2, in WaitForStrings > com_error: (-2147352571, 'Type mismatch.', None, 1) > > I've tried providing lists and tuples of strings, lists and tuples of > unicode strings. > > makepy -i reports: > > Warning - could not load registered typelib > > Without the -i, it creates CLSID > 0DE5A6C0-4B0D-101B-AC7B-04021C007002.py, but when I run the telnet > client, COM Browser says it's F29799A0-4B0C-101B-AC7B-04021C007002 > (off a bit). The 0DE...py module mentions this CLSID F29... > > I tried renaming and importing the 0DE...py file, but I still get the > Type mismatch. > > In short, is there something specific I need to do in order to pass a > ``string array'' from Python to a COM server when I'm (I think) stuck > with late binding? > > Thanks! > Harry. > > PS. Please reply to this group as I get a ton of spam. From amk at amk.ca Mon Aug 25 12:24:20 2003 From: amk at amk.ca (A.M. Kuchling) Date: Mon, 25 Aug 2003 11:24:20 -0500 Subject: Python2.3 absolute import error References: Message-ID: On Mon, 25 Aug 2003 17:56:52 +0200, > 'import site' failed; use -v for traceback ^^^^ what's this? I expect the installation is incorrect or sys.path is messed up in some way, and suspect that your import problems are only a side effect, not the root cause of the problem. Run "python -v" to see the traceback from site.py. --amk From jjl at pobox.com Tue Aug 26 16:46:06 2003 From: jjl at pobox.com (John J. Lee) Date: 26 Aug 2003 21:46:06 +0100 Subject: Advice to a Junior in High School? References: Message-ID: <873cfo6tbl.fsf@pobox.com> "Terry Reedy" writes: > "Howard Nease" wrote in message > news:Ivw2b.1305$Ce2.314 at clmboh1-nws5.columbus.rr.com... > > have heard a whole lot about the fact that the market for software > engineers > > nowadays is *HORRIBLE*, and that I should double major or perhaps go > into a > > field of study in which I'm not very interested. > > The demand for software engineers has fluctuated up and down, in > various industries and regions, for decades. An article in the > current Business 2.0 on the 'coming labor shortage' points out that > you are part of the first generation in America to be numerically > smaller than your parents generation. In ten years, when boomers have > or are retiring, there will probably be a relatively shortage of tech > workers. Who knows? There are plenty of clever, hard-working people in India who speak good English. It would be a good thing if more computing jobs moved there, IMHO, and that certainly seems to be happening to an extent already. A lot depends on the location and degree of horror of world events, I fear. Just to cheer you up ;-/ John From dkuhlman at rexx.com Thu Aug 21 18:52:18 2003 From: dkuhlman at rexx.com (Dave Kuhlman) Date: Thu, 21 Aug 2003 15:52:18 -0700 Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> <6dj2kv8ugkieehs7guh786cl40o5lj6mcs@4ax.com> Message-ID: Andrew Dalke wrote: [snip] > > The complaint about macros has been their tendency to > increase a single person's abilities at the cost of overall > loss in group understanding. I've heard references to > projects where that didn't occur, but am not swayed > by it because those seem staffed by people with > extraordinarily good programming skills almost never > found amoung the chemists and biologists I work with. I just took a quick look at the "Revised5 Report on the Algorithmic Language Scheme". Macros in Scheme5 are called "hygienic macros", so apparently there are some dirty macros that we should worry about. My understanding is that macros came to Scheme slowly, with resistence, with a good deal of thought, and with restrictions. "More recently, Scheme became the first programming language to support hygienic macros, which permit the syntax of a block-structured language to be extended in a consistent and reliable manner." See: http://www.schemers.org/Documents/Standards/R5RS/HTML/ http://www.schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-3.html http://www.schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-7.html#%_sec_4.3 I have the same worry that some others on this thread have expressed, that a macro capability in Python would enable others to write code that I would not be able to read or to figure out. [snip] Dave -- Dave Kuhlman http://www.rexx.com/~dkuhlman dkuhlman at rexx.com From jjl at pobox.com Sun Aug 3 07:44:10 2003 From: jjl at pobox.com (John J. Lee) Date: 03 Aug 2003 12:44:10 +0100 Subject: Changing base class of a big hierarchy References: <873cgjyo2u.fsf@pobox.com> Message-ID: <87y8ybx8xh.fsf@pobox.com> jjl at pobox.com (John J. Lee) writes: [...] > Maybe deep-copying the module or something, then fiddling with > __bases__?? Or a metaclass? Actually, I meant deep-copying as an *alternative* to fiddling with __bases__ -- presumably could then replace the base class's methods without affecting other users of xml.dom. Not sure what the best plan is though, so my questions still stand. John From ryanlowe0 at msn.com Thu Aug 28 18:43:20 2003 From: ryanlowe0 at msn.com (Ryan Lowe) Date: Thu, 28 Aug 2003 22:43:20 GMT Subject: python gripes survey References: <15dpkvsfatkrlode3rc9h1trihsb3ppcj3@4ax.com> Message-ID: [smarter_than_you] >How about this for a symmetrical, Pythonesque syntax: > >def sumdif(a, b): > sum = a + b > dif = a - b > return sum, dif > >#normal syntax: >s, d = sumdif(5,7) > >#additional syntax with named returns: > >(s=sum, d=dif)=sumdif(5, 7) > >#eqivalent to: > >(d=dif, s=sum)=sumdif(5, 7) > >#I call it 'symmetrical' because we can do this: > >(s=sum, d=dif)=sumdif(a=5, b=7) > >Not sure how easy to implement this would be, or how it affects the >scope of locals and such, but it looks nice on paper. not bad. heres an alternative: s, d = (sum, dif) from sumdif(5, 7) d, s = (dif, sum) from sumdif(5, 7) uses the from keyword. makes it look like a parallel assignment. From logiplex at qwest.net Fri Aug 22 13:47:16 2003 From: logiplex at qwest.net (Cliff Wells) Date: Fri, 22 Aug 2003 10:47:16 -0700 Subject: Do Java lovers are scared about the Python crowd? In-Reply-To: References: Message-ID: <1061574435.1506.241.camel@software1.logiplex.internal> On Fri, 2003-08-22 at 01:45, Lawrence Oluyede wrote: > http://www.cardboard.nu/archives/000118.html > > I think that the guy (Alan Green) is very scared :) Or very ironic. -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 (800) 735-0555 From lvirden at yahoo.com Fri Aug 1 13:03:17 2003 From: lvirden at yahoo.com (lvirden at yahoo.com) Date: 1 Aug 2003 17:03:17 GMT Subject: Potentially important real-time on-line discussion References: Message-ID: According to Cameron Laird : :*The Chronicle of Higher Education*, which is more-or-less :authoritative for US university administrations, is spon- :soring a discussion on the place of open-source in :universities ("... are such choices too risky for colleges :...?"), starting in about an hour. : :http://chronicle.com/colloquylive/2003/08/opensource/chat.php To me, this appears to be the correct URL: http://chronicle.com/colloquylive/2003/08/opensource/chat.php3 -- Tenth Tcl/Tk Conference is this week! Even if explicitly stated to the contrary, nothing in this posting should be construed as representing my employer's opinions. From dloolb at sinatown.com Fri Aug 8 06:09:39 2003 From: dloolb at sinatown.com (dlo_olb) Date: Fri, 08 Aug 2003 10:09:39 +0000 Subject: Why does value of __doc__ not a String type? Message-ID: <3216865.1060337379@dbforums.com> Hi, >>> import types >>> type(types.BuiltinFunctionType.__doc__) >>> TIA -- dlo_olb Posted via http://dbforums.com From dsylvest at adelphia.net Mon Aug 18 11:59:55 2003 From: dsylvest at adelphia.net (Dennis) Date: 18 Aug 2003 08:59:55 -0700 Subject: GTK import doesn't import first time Message-ID: <4a555b17.0308180759.48c99878@posting.google.com> The setup: Windows XP Pro Python 2.3 GTK+ 2.2.1.2 and pyGTK 1.99.17 for Python 2.3 from http://www.pcpm.ucl.ac.be/~gustin/win32_ports/ I've downloaded and installed per the instructions the pyGTK and GTK+ for win32 from the above locations. Folowing the instructions, I import pygtk first, run pygtk.require('2.0') second and then import gtk. I receive an error on the import gtk the first time, but immediately after, if I import again it works. Even if I don't impo0rt pyGTK at all and only import gtk, I get the same results. Any ideas? PythonWin 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] on win32. Portions Copyright 1994-2001 Mark Hammond (mhammond at skippinet.com.au) - see 'Help/About PythonWin' for further copyright information. >>> import pygtk >>> pygtk.require('2.0') >>> import gtk Traceback (most recent call last): File "", line 1, in ? File "D:\Python\Python23\lib\site-packages\gtk-2.0\gtk\__init__.py", line 43, in ? from _gtk import * ImportError: DLL load failed: The specified procedure could not be found. >>> import gtk >>> Thanks, Dennis From nick.keighley at marconi.com Fri Aug 22 08:07:50 2003 From: nick.keighley at marconi.com (Nick Keighley) Date: 22 Aug 2003 05:07:50 -0700 Subject: class factory References: <8ad2cfb3.0308200015.4f5bd504@posting.google.com> <5SR0b.21604$zN5.668541@news1.tin.it> Message-ID: <8ad2cfb3.0308220407.7f596d14@posting.google.com> Alex Martelli wrote in message news:<5SR0b.21604$zN5.668541 at news1.tin.it>... > Nick Keighley wrote: thamks all for help and suggestions. > > I'm a Python beginner and I'm would like to write a function that > > returns a class (perhaps a tad ambitious...). I've looked through > > the FAQ and perused "Python In A Nutshell" (not a good book to > > start with?). The only example I found in PiaN used a simple > > If you're an experienced programmer with other languages then > the Nutshell should be helpful -- if you're a newbie to programming, > you should start with easier books (but with the kind of tasks > you're setting yourself I guess you aren't). no, not a programming beginner. A Python beginner. I was specifically trying to do something that was hard (impossible) to do in "normal" language (eg. C). The idea was try and generate types (ie. classes) that had a limited set of values. I'd found the C enum emulators in http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/67107 but they didn't quite do what I wanted. > [...] I didn't particularly > emphasize metaprogramming in the Nutshell -- it's more of a "gee > whiz" kind of thing and the Nutshell aims to cover solid, everyday, > bread-and-butter usage. > > > if statement to return one of a selection of pre-existing classes. > > I'd like to generate a class on-the-fly from a parameter (a dictionary). > > How do you want to use that dict -- as the class's dict? Then either: > > def makeaclass(fromdict): > class X: pass > X.__dict__ = fromdict > return X > > or > > def makeaclass(fromdict): > class X: pass > X.__dict__.update(fromdict) > return X > > might be helpful. > > > > Can Python do this sort of stuff? Does the mean I have to mess with > > the dreaded meta-classes? > > Metaclasses may be easier to use than sufficiently-general class-building > functions, actually -- no reason to dread them. But anyway, yes, Python > IS pretty good at metaprogramming, too, both with and without metaclasses. -- Nick Keighley From aleax at aleax.it Wed Aug 6 12:13:57 2003 From: aleax at aleax.it (Alex Martelli) Date: Wed, 06 Aug 2003 16:13:57 GMT Subject: Problem with blocking portably on sockets and Queue? References: Message-ID: <9P9Ya.42349$cl3.1347211@news2.tin.it> Tero Saarni wrote: > Hi, > > I have several threads communicating with each other using events > stored in Queues. Threads block on Queue.get() until somebody > publishes an event in thread's event queue. So far so wonderful -- excellent architecture. > I need to add support for sockets to the system. Thread needs to > unblock when: > > - there is socket ready to be read, or > - there is event waiting in the queue > > My first tought was to replace blocking on Queue.get() with blocking > on poll or select and dedicating file descriptors (created with os.pipe()) > as an semaphore. Event publisher would write something to the write > end of the pipe when it puts an event to the queue, effectively > unblocking the receiver. > > BUT I noticed that select.poll() is not available on Windows and > secondly Windows version of select.select() will accept only socket > descriptors. > > What options do I have that are still portable also to Windows > platform? I think you could devote a thread specifically to the task of handling sockets, only. That special thread would not block on any queue but just on select; when its select shows that a socket is ready, you can have the thread itself do the reading and post the appropriate special message including the data read to the appropriate thread, or you could pass the ready-for-reading socket object to the appropriate thread, or the like. This needs a bit more care if the set of sockets to be select'ed on changes with time; in this case, I think the socket-handler thread would have to use a timeout on its select so the set of sockets can be updated once in a while (either by another thread, in which case you need a lock to protect the "set of sockets" shared data, or by the socket-handling thread (SHT) itself in response to a queued message -- the SHT would read non-blockingly from that queue periodically when the select times out) -- or you could perhaps use a special identifiable socket for the SHT to receive from other threads requests to change the set of ('true') sockets to be selected on. Alex From bac at OCF.Berkeley.EDU Sun Aug 10 17:23:57 2003 From: bac at OCF.Berkeley.EDU (Brett C.) Date: Sun, 10 Aug 2003 14:23:57 -0700 Subject: python-dev Summary for 2003-07-01 through 2003-07-31 Message-ID: <3F36B7ED.3060702@ocf.berkeley.edu> python-dev Summary for 2003-07-01 through 2003-07-31 ++++++++++++++++++++++++++++++++++++++++++++++++++++ This is a summary of traffic on the `python-dev mailing list`_ from July 1, 2003 through July 31, 2003. It is intended to inform the wider Python community of on-going developments on the list. To comment on anything mentioned here, just post to python-list at python.org or `comp.lang.python`_ with a subject line mentioning what you are discussing. All python-dev members are interested in seeing ideas discussed by the community, so don't hesitate to take a stance on something. And if all of this really interests you then get involved and join `python-dev`_! This is the twenty-first/twenty-second summary written by Brett Cannon (who is still learning how to count; gave the wrong summary count last month). All summaries are archived at http://www.python.org/dev/summary/ . Please note that this summary is written using reStructuredText_ which can be found at http://docutils.sf.net/rst.html . Any unfamiliar punctuation is probably markup for reST_ (otherwise it is probably regular expression syntax or a typo =); you can safely ignore it, although I suggest learning reST; its simple and is accepted for `PEP markup`_ and gives some perks for the HTML output. Also, because of the wonders of programs that like to reformat text, I cannot guarantee you will be able to run the text version of this summary through Docutils_ as-is unless it is from the original text file. .. _PEP Markup: http://www.python.org/peps/pep-0012.html The in-development version of the documentation for Python can be found at http://www.python.org/dev/doc/devel/ and should be used when looking up any documentation on something mentioned here. Python PEPs (Python Enhancement Proposals) are located at http://www.python.org/peps/ . To view files in the Python CVS online, go to http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/python/ . .. _python-dev: http://www.python.org/dev/ .. _python-dev mailing list: http://mail.python.org/mailman/listinfo/python-dev .. _comp.lang.python: http://groups.google.com/groups?q=comp.lang.python .. _Docutils: http://docutils.sf.net/ .. _reST: .. _reStructuredText: http://docutils.sf.net/rst.html .. contents:: .. _last summary: http://www.python.org/dev/summary/2003-06-01_2003-06-30.html ===================== Summary Announcements ===================== It's experimentation time again! In preparation for having to cut down on the breadth of the summary thanks to my return to school I am starting this summary off as the inaugural release of the new format. Pretty much everything is going to change somewhat. First, though, I think I should explain my new viewpoint towards the summaries that I am taking. In order to continue to provide a certain level of quality and coverage while retaining my personal sanity and to not feel like the Summaries are a job instead of something I do for fun and to help others, I am going to start viewing the Summaries more from a journalistic perspective than a historical one. Before I felt more like a historian that was summarizing *everything* that happened on python-dev. Now, though, I am be more like a journalist, covering only the pertinent ideas. This also allows me to inject more of my personality into my writing. But what ramifications does this new perspective cause? Well, it will dictate what I do and do not summarize. I plan on several types of discussions to be covered in the Summaries. One is new features of the language. This is so people can know about them ASAP and thus comment on them. Since practically any feature mentioned here is experimental there is a chance to remove it if a community movement mounts. I will also cover any major thinking on the future of Python. I have always wished there was an easy way to see what pie-in-the-sky ideas python-dev was thinking of in the back of our collective mind; the summaries might as well fill this desire. And of course any random discussion that is large, important, and/or complex will continue to be covered. In terms of formatting and layout, that will also change along with the new viewpoint. I am planning to follow something more along the lines of the Perl's `This Week... `__; yes, I am taking a cue from Perl but AM Kuchling and Michael Hudson originally used this format as well. This means titles of summary sections will more reflect the topic being summarized rather than the specific thread(s). I will continue to list all of the threads that contributed to the summary, though, for reference purposes. I feel this will be beneficial since I know I have personally looked back into the Summary archives and had a hard time finding something specific since the subject of a thread does not always match the topic of discussion; if I can't find something and I know about what month it happened I can only imagine what everyone else has had to go through to find something! I am removing the Quickies section from the Summaries. This section was nice to have, but it just ate away at my time. This also goes along with the new viewpoint. I am sure not everyone will be happy with this change, that's fine. But if someone out there *truly* hates the direction I am going then they can step forward and take the reigns from me. But as I have stated before, the fine print on me giving up this post is that the person who takes over must be as thorough as I *used* to be; I can do the summaries in a half-assed fashion as well as anyone else. Enough of that topic. One thing I would like to mention is that the `Python Software Foundation`_ can now accept donations through PayPal. Specifics can be found at http://www.python.org/psf/donations.html . It would be great if people could donate since the PSF is more than just a non-profit to hold the Python intellectual property. One of the goals of the group is to get enough money to do something like the Perl Foundation does and sponsor someone to hack on Python for a living for a set amount of time. Right now we are a ways off from having that kind of revenue, but there is no reason why we can't. Heck, if we can just get enough to sponsor one person to do full-time Python hacking for a week it would be beneficial. Or better yet, the PSF could sponsor one of their own members to write a summary of the python-dev mailing list for the betterment of the community. =) .. _PSF: .. _Python Software Foundation: http://www.python.org/psf/ .. _PayPal: http://www.paypal.com/ ========= Summaries ========= -------------------------- Python 2.3 final released! -------------------------- In case for some odd reason you didn't know, Python 2.3 final has gone out the door. The team managed to meet the goal of getting it out by the end of the month so that Apple_ can use a final release instead of a release candidate in OS X 10.3 (a.k.a. Panther). The goal of this release was to continue to improve Python without adding any new keywords. This was met while speeding things up, fixing bugs, adding to the standard library, and adding some new built-ins. To find out what is new or has changed look at the changelog at http://www.python.org/2.3/highlights.html or `What's New in Python 2.3`_. As with all software, there are bound to be bugs. What bugs that are known are listed at http://www.python.org/2.3/bugs.html . If you find bugs not listed there, please report them on the SourceForge bug tracker at http://sourceforge.net/tracker/?group_id=5470&atid=105470 . Running the regression test suite (details on how to do this is covered in the documentation for the 'test' package as found at http://www.python.org/doc/current/lib/module-test.html) is always appreciated. Contributing threads: - `Problem with 2.3b2 tarfile?`__ - `MacPython 2.3b2 binary installer for MacOSX`__ - `Running tests on freebsd5`__ - `Python 2.3 release schedule update`__ - `Vacation and possibly a new bug`__ - `Doc/ tree closes at noon, US/Eastern`__ - `I've tagged the tree`__ - `cygwin errors`__ - `test_strptime; test_logging; test_time failure`__ - `2.3rc1 delayed`__ - `Python 2.3 release candidate 1`__ - `post-release festivities`__ - `New branch for r23c2 work`__ - `Serious CallTip Bug in IDLE`__ - `MacPython-OS9 test failures`__ - `Doc/ tree on trunk closed`__ - `Cutting the 2.3c2 tonight 8pm EDT`__ - `Re: [Python-checkins] python/dist/src/Misc NEWS,1.826,1.827`__ - `RELEASED Python 2.3c2`__ - `2.3rc2 IDLE problems on a Win2000sp3 box`__ - `Draft: 2.3 download page`__ - `Last priority >= 7 bug for Python 2.3`__ - `CVS Freeze`__ - `RELEASED Python 2.3 (final)`__ __ http://mail.python.org/pipermail/python-dev/2003-July/036669.html __ http://mail.python.org/pipermail/python-dev/2003-July/036732.html __ http://mail.python.org/pipermail/python-dev/2003-July/036762.html __ http://mail.python.org/pipermail/python-dev/2003-July/036783.html __ http://mail.python.org/pipermail/python-dev/2003-July/036845.html __ http://mail.python.org/pipermail/python-dev/2003-July/036892.html __ http://mail.python.org/pipermail/python-dev/2003-July/036899.html __ http://mail.python.org/pipermail/python-dev/2003-July/036900.html __ http://mail.python.org/pipermail/python-dev/2003-July/037117.html __ http://mail.python.org/pipermail/python-dev/2003-July/036921.html __ http://mail.python.org/pipermail/python-dev/2003-July/036940.html __ http://mail.python.org/pipermail/python-dev/2003-July/036941.html __ http://mail.python.org/pipermail/python-dev/2003-July/037024.html __ http://mail.python.org/pipermail/python-dev/2003-July/037134.html __ http://mail.python.org/pipermail/python-dev/2003-July/037144.html __ http://mail.python.org/pipermail/python-dev/2003-July/037193.html __ http://mail.python.org/pipermail/python-dev/2003-July/037200.html __ http://mail.python.org/pipermail/python-dev/2003-July/037207.html __ http://mail.python.org/pipermail/python-dev/2003-July/037208.html __ http://mail.python.org/pipermail/python-dev/2003-July/037237.html __ http://mail.python.org/pipermail/python-dev/2003-July/037284.html __ http://mail.python.org/pipermail/python-dev/2003-July/037311.html __ http://mail.python.org/pipermail/python-dev/2003-July/037315.html __ http://mail.python.org/pipermail/python-dev/2003-July/037319.html .. _Apple: http://www.apple.com/ .. _What's New in Python 2.3: http://www.python.org/doc/2.3/whatsnew/ ------------------------------------------- String Exceptions Going Extinct, Eventually ------------------------------------------- It has been brought up several times before, but things are now moving along to eventually deprecate string exceptions (e.g., ``raise "this string exception"``). they have now been removed from the tutorial to prevent people new to the language from picking up habits that will eventually be impossible to perform. As for when the impending deprecation will occur only Guido knows. The chances of it coming before Python 3, though, is most likely small. Contributing threads: - `String exceptions in the Tutorial`__ __ http://mail.python.org/pipermail/python-dev/2003-July/036665.html -------------------------------------------------------- Someday, My CVS updates Will Succeed on the First Try... -------------------------------------------------------- We all know that SourceForge_ does not have the snappiest or most reliable CVS_ servers in the world; Python 2.3 final's release was targeted a few days earlier than needed for Apple_ in case SF's CVS went down. Solutions to how to deal with this problem have come up. One specific problem that people are trying to solve is the poor anonymous pserver access. SF has their CVS servers set up so that authorized CVS commands take priority over anonymous ones and thus when there is heavy traffic anonymous CVS basically shuts down. Martin v. L?wis put up a link to a nightly tarball at http://www.dcl.hpi.uni-potsdam.de/home/loewis/python.tgz of the CVS HEAD. perl.org has provided a nightly tarball as well at http://cvs.perl.org/snapshots/python/ for quite some time now. The suggestion of having a read-only version of the CVS tree on python.org was came up, but how to properly do it and who would set it up was not settled. And of course there is always the option of moving CVS off of SF entirely. There is one offer on the table with the caveat that we need to know what kind of bandwidth demands we would have. Another offer sprung up this month from Michal Wallace to host our CVS at http://www.versionhost.com/ with the hitch that it requires an external Python script for secure connections (as specified at http://www.sabren.net/code/cvssh/ ). Contributing threads: - `alternate pserver access for python CVS?`__ - `[fwd] SourceForge status`__ - `Volunteering to help with pserver cvs on python.org`__ __ http://mail.python.org/pipermail/python-dev/2003-July/036699.html __ http://mail.python.org/pipermail/python-dev/2003-July/036708.html __ http://mail.python.org/pipermail/python-dev/2003-July/036860.html .. _SourceForge: http://www.sf.net/ .. _CVS: http://www.cvshome.org/ --------------------- Which License to Use? --------------------- Domenico Andreoli wanted to donate `python-crack`_ to the PSF_ and wondered what steps would be necessary to do so. He was first told that the module would not be included in Python since it is too specific. Secondly, it was suggested he not choose the PSF license. Instead, he was told that he should use the BSD or MIT license (both of which can be found at http://www.opensource.org/licenses/index.php); clean, simple licenses that are not viral like the GPL but are GPL-compatible. This is so that it can be included in any software that uses Python. Contributing threads: - `donating python-crack module`__ __ http://mail.python.org/pipermail/python-dev/2003-July/036712.html .. _python-crack: http://savannah.nongnu.org/projects/python-crack ---------------- Not Quite ANSI C ---------------- Every so often someone runs Python against a C code checker and notices failures that get reported to us. Often, though, we have to tell the person that we already know of the failures and that there is nothing to worry about. This time it was failures under Purify. We have also received reports of failures under Valgrind_ which are spurious. The language isn't even fully ANSI C compliant, but as Tim Peters said, "it's not possible to write a useful and portable memory allocator in 100% standard ANSI C" among other reasons why strict ANSI C conformity is broken. The only major violations in the code are casting a pointer to a unsigned integer type and assuming "that whatever memory protection gimmicks an OS implements are at page granularity" which is a minor sin at best. There is also some cases of accessing memory without proper casting. Contributing threads: - `Invalid memory read in PyObject_Free`__ - `strict aliasing and Python`__ __ http://mail.python.org/pipermail/python-dev/2003-July/036717.html __ http://mail.python.org/pipermail/python-dev/2003-July/036898.html .. _Valgrind: http://developer.kde.org/~sewardj/ --------------------------------------- Shadowing Built-ins is Becoming a No-No --------------------------------------- Before the code was removed, Python 2.3 raised a DeprectionWarning when you overshadowed a built-in in a module from outside the module's actual code. What this means is that doing something like:: import mod mod.reload = 42 would raise the warning. Now doing ``reload = 42`` in the module itself would still be allowed. The idea was (and still is) that the compiler can know when a built-in is shadowed in a module when it compiles the module's code. But allowing someone to overwrite a built-in externally means that the compiler cannot make any assumptions that built-ins will forever reference the actual built-in code. This is unfortunate since if shadowing externally was made illegal the compiler can reference the built-in code directly and skip some steps for a nice speed-up. This is why there was code to warn against this initially. But it didn't work well enough to be left in Python 2.3 so it has been removed. But this restriction will most likely be enforced at some point so it is something to keep in mind. Contributing threads: - `Deprecation warning 'assignment shadows builtin'`__... - `DeprecationWarning: assignment shadows builtin`__ __ http://mail.python.org/pipermail/python-dev/2003-July/036767.html __ http://mail.python.org/pipermail/python-dev/2003-July/036879.html ------------------------ Must...Start...Faster... ------------------------ While Python 2.3 sees up to a 30% speed increase over 2.2, it still starts up slower. Originally it was believed that it was because of the importation of the re module. Marc-Andr? Lemburg applied a patch that tried to minimize its possible importation at startup but it was still slow. Jeremy Hylton pointed out that 2.2.3 imported re so that probably was not the problem. One thing that is different, though, is the automatic inclusion of warnings, codecs, and the ability to do zip imports. These three things pull more modules and all of this leads to a longer startup time. There is also the importation of distutils thanks to the site.py module, but that only occurs if you execute in a build directory. Including zip imports also got attacked for the number of failed checks for files it can incur. But it is believed this is not as bad as all of the extra imports being done now and Just van Rossum said he would try to cut down the unneeded checks in the future. Contributing threads: - `2.3 startup speed?`__ __ http://mail.python.org/pipermail/python-dev/2003-July/036815.html --------------------- The World and Numbers --------------------- People might not be aware of it, but locale.setlocale never changes the LC_NUMERIC locale value. This is so that 'str' and 'float' can return and receive numbers in a consistent way in source code. This causes a problem, though, for people in locales that do not use a period for a decimal point. If you had your locale set to Brazilian and tried to pass the string "3,14" to 'float' it would fail even though that is a legitimate number representation for your locale. The suggestion became to have a locale-agnostic version of 'str' and 'float' in the locale module for people to use when they needed such functionality. It has now reached the stage of a rough draft PEP as found at http://mail.python.org/pipermail/python-dev/2003-July/036996.html . Contributing threads: - `LC_NUMERIC and C libraries`__ - `Be Honest about LC_NUMERIC`__ - `RE: [Spambayes] Question (or possibly a bug report)`__ __ http://mail.python.org/pipermail/python-dev/2003-July/036869.html __ http://mail.python.org/pipermail/python-dev/2003-July/036996.html __ http://mail.python.org/pipermail/python-dev/2003-July/037178.html --------------- Zippin' Nothin' --------------- The built-in 'zip' function in Python 2.3 raises TypeError when given no arguments. This causes problem when you do ``zip(*args)`` and args is empty. So for Python 2.4 'zip' with no arguments will return an empty list. Contributing threads: - `zip() in Py2.4`__ __ http://mail.python.org/pipermail/python-dev/2003-July/037332.html -------------------------------- A Syntax For Function Attributes -------------------------------- An old debate (or at least old in terms of it having popped up multiple times during the tenure of your author) has been ways of enhancing function definitions. Previously it has been over ways to make defining classmethod and its ilk in a cleaner fashion along with properties (past summaries on this can be found at http://www.python.org/dev/summary/2003-01-16_2003-01-31.html#extended-function-syntax and http://www.python.org/dev/summary/2003-02-01_2003-02-15.html#extended-function-syntax ). What made the discussion slightly different this time, though, was the focus was on function attributes specifically. One idea was to tweak Michael Hudson's bracket syntax for method annnotations to allow for function attributes; ``def foo() [bar=42]: pass``. Another suggestion was to take the dictionary-like connection even farther; ``def foo() {bar=42}: pass``. There was no clear winner in either case partially because this discussion flared up towards the end of the month. It was also pointed out that using Michael Hudson's method descriptors you could come up with a wrapping function that handled the situation:: def attrs(**kw): def _(func): for k in kw: setattr(func, k, kw[k]) return func return _ def foo() [attrs(bar=42)]: pass Perk of this is it does not lead to any special syntax just for function attributes. One drawback, though, as pointed out by Paul Moore is that this makes the method annotation idea a little to liberal and open to hackish solutions like this that will lead to abuse. This was not a huge worry, though, since almost anything can be abused and this is all already doable now, just without a nice, clean syntax. Contributing threads: - `A syntax for function attributes?`__ __ http://mail.python.org/pipermail/python-dev/2003-July/037338.html From pieroul_nospam_ at attglobal.net Thu Aug 14 01:46:18 2003 From: pieroul_nospam_ at attglobal.net (Pierre Rouleau) Date: Thu, 14 Aug 2003 01:46:18 -0400 Subject: system call in python In-Reply-To: References: Message-ID: Catherine Yang wrote: > Hi, > > A question about how to execute a system command from python program. e.g. > in a python script, I need to run another program written in C++, and after > that come back to the same python program. > > Is it the system module, and which function do I use to do this? > You can use the os.system() to execute a program accessible from your path or specified explicitly: >>> import os >>> os.system('ls') For more info on process control, take a look at: http://www.python.org/doc/current/lib/os-process.html From trevp at trevp.net Mon Aug 4 14:30:56 2003 From: trevp at trevp.net (Trevor Perrin) Date: 4 Aug 2003 11:30:56 -0700 Subject: memory leak? References: <60FB8BB7F0EFC7409B75EEEC13E2019202CE481A@admin56.narex.com> Message-ID: <47e891f1.0308041030.68ec0a63@posting.google.com> Skip Montanaro wrote in message news:... > Bjorn> In any case, you should probably file a bugreport at sourceforge, > Bjorn> http://sourceforge.net/tracker/?atid=105470&group_id=5470&func=browse, > > Not necessary in this case as Tim Peters already did. Neal Norwitz > confirmed the bug and suggested a simple fix. I expect it will be closed > Monday. Looks like it was. Thanks everyone, for the speedy response! Trevor From danbmil99 at yahoo.com Sun Aug 24 22:52:18 2003 From: danbmil99 at yahoo.com (dan) Date: 24 Aug 2003 19:52:18 -0700 Subject: Python is darn fast (was: How fast is Python) References: <2259b0e2.0308230737.8a9bc1c@posting.google.com> <2259b0e2.0308240638.38350cba@posting.google.com> Message-ID: mis6 at pitt.edu (Michele Simionato) wrote in message news:<2259b0e2.0308240638.38350cba at posting.google.com>... > I finally came to the conclusion that the exceeding good performance > of Psyco was due to the fact that the function was called a million > times with the *same* argument. Evidently Psyco is smart enough to > notice that. Changing the argument at each call > (erfc(0.456) -> i/1000000.0) slows down Python+Psyco at 1/4 of C speed. > Psyco improves Python performance by an order of magnitude, but still it > is not enough :-( > It's plenty! A factor of 4 from optimized C, considering the newness and limited resources behind psyco, is very encouraging, and good enough for most tasks. Java JIT compilers are still around a factor of 2 slower than C, and they've had at least 2 orders of magnitude more whumpage. This is a far cry from the factor of 10-30 I've been seeing with pure python. For performance-critical code, this could be the difference between hand-coding 5% versus 20% of your code. Excellent news!! From Gerald.Klix at klix.ch Sat Aug 2 05:38:38 2003 From: Gerald.Klix at klix.ch (Gerald Klix) Date: Sat, 02 Aug 2003 11:38:38 +0200 Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> <3F2A35A1.2040403@klix.ch> Message-ID: <3F2B869E.1030005@klix.ch> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 This is not a function. This just the same as blocks in Algol 68, because both do not defer execution until the fuction is called. Of course you can define the semantics of such a block in terms of a function defintion and an immedirate call to the fuction. This is done in the Scheme languges let syntax. HTH, Gerald OKB (not okblacke) wrote: | Gerald Klix wrote: | | |>What Python realy needs here is some means to make an expression |>from a list of statements (called suite in the syntax defintion). | | | I believe this is called a "function". | -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (GNU/Linux) Comment: Using GnuPG with Debian - http://enigmail.mozdev.org iD8DBQE/K4adEDg9cqFA1jQRAnLkAJ0WXxqAwdzyqrKfOy2O1ycod1aCmQCfeKRH doeQdEuwBJ8LS+gy6IOYzZQ= =KB0f -----END PGP SIGNATURE----- From mwilson at the-wire.com Fri Aug 1 11:15:44 2003 From: mwilson at the-wire.com (Mel Wilson) Date: Fri, 01 Aug 2003 11:15:44 -0400 Subject: OT Remark on Re: time, calendar, datetime, etc References: <153fa67.0307300326.45a29380@posting.google.com> <1sScnW0Sv7DzrrSiRTvUpQ@speakeasy.net> Message-ID: In article , "Andrew Dalke" wrote: >Well, if you're doing astronomical time, wouldn't you just add 4700 >and something years and 12 hours (as I recall, astronomers have a >12 hours offset because they observe at night and don't want to have >to change the date (or forget to change the date) part way though.) (Also the Royal Navy, in the era of Patrick O'Brians novels. Apparently because you can determine local noon exactly with a sun sight, but there's damn all you can do to determine midnight without a lot of work.) Regards. Mel. From tjreedy at udel.edu Fri Aug 1 21:14:46 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 1 Aug 2003 21:14:46 -0400 Subject: How do I combine instance+string for variable References: <4378fa6f.0308011305.183c291a@posting.google.com> Message-ID: > > conns = [conn2, conn3, conn4, conn5, conn6, conn7, conn8] > ... > for int in range(2,9): > qput(key.command, conns[int-2], act_user("user-ID" + str(int), "CTAG", > "t*sting" + str(int) ) ) > And what happens if you follow 'snippett' with anything like type(var)==int # or var=int(num/3) # or num = int(somestring) or preceed it with something like for str in stringlist: ..... ? Please don't use type names (or other builtins) as variables in posted code. Experts may survive it, but it's a bad example for beginners. ;-) Terry J. Reedy From mal at lemburg.com Fri Aug 1 03:27:54 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Fri, 01 Aug 2003 09:27:54 +0200 Subject: time, calendar, datetime, etc In-Reply-To: References: <153fa67.0307300326.45a29380@posting.google.com> <1sScnW0Sv7DzrrSiRTvUpQ@speakeasy.net> Message-ID: <3F2A167A.5000506@lemburg.com> John Roth wrote: > The datetime module is a great piece of work, but I wonder why it > wasn't made more compatible with the time module? It would seem to > be simple enough to provide a sequence interface so the object > supports the 9-tuple directly (for either naive or tz-aware, pick one,) > and also supports the same attributes as the objects in the time package. > > I also wonder why anyone made the choice to set the year origin at > 1AD? That decision, by itself, makes it almost unusable for my hobby > (astrological software, which is basically astronomical software > with a different focus.) Astronomical dates are always measured > in days since 4700 and something BC. History did not begin, after > all, six years after JC was born. (And astronomical years, btw, > do include a year zero, which historical years do not.) FWIW, mxDateTime has all needed features for these things (and has had them for years). -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 01 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From NOSPAM__nabugoon__ at __moor.pe.krNOSPAM Tue Aug 26 05:41:26 2003 From: NOSPAM__nabugoon__ at __moor.pe.krNOSPAM (Charlie Kim) Date: Tue, 26 Aug 2003 18:41:26 +0900 Subject: gnome.applet programming question. Message-ID: Here is gnome applet source of mine. -------------------------------------------------- #!/usr/bin/env python import pydic import gtk import gnome.applet class PyDicApplet(gtk.HBox): def __init__(self, applet): gtk.HBox.__init__(self, spacing=3) entry = gtk.Entry() entry.connect("key_press_event", self.entry_cb) self.add(entry) button = gtk.Button(unicode("??", "euc-kr")) #butoon.connect("button-press-event", self.button_press_cb, applet) #button.connect("clicked", self.button_cb, entry) self.pack_end(button, gtk.FALSE) self.win = pydic.MainWindow() def entry_cb(self, widget, event): key = event.keyval if key == 65293: self.win.Show(True) self.win.search(entry.get_text()) def button_press_cb(self, widget, event, applet): if event.button == 3: applet.emit("button_press_event", event) return gtk.FALSE def buttob_cb(self, widget, entry): pass def destroy_cb(applet, widget): pass def sleeper(): gtk.timeout_add(33, sleeper) time.sleep(0.001) def dic_factory(applet, iid): gtk.timeout_add(33, sleeper) d = PyDicApplet(applet) applet.connect("destroy", destroy_cb, d) applet.add(d) applet.show_all() return gtk.TRUE gnome.applet.bonobo_factory("OAFIID:GNOME_PyDic_Factory", gnome.applet.Applet.__gtype__, "pydic", "0", dic_factory) ----------------------------------------------------- It works fine. but, when I uncomment 15, 16 line, applet run without error but not appear in panel. any idea? TIA. From janek.n at gmx.de Thu Aug 28 11:49:13 2003 From: janek.n at gmx.de (Janek Neubert) Date: Thu, 28 Aug 2003 17:49:13 +0200 Subject: PAM and Python2.2 Message-ID: Hi, I'm using pyPAM (0.4.2) to authenticate users via PAM. With Debian sarge all works fine. Unfortunally, I've problems with the same tool on Redhat 7.3. pyPAM is unable to execute a conversation function and reports: PAM.error: ('Conversation error', 19) In /var/log/messages you read: Aug 27 18:53:51 minipc3 wwwproject(pam_unix)[21675]: auth could not identify password for [janek] On my debian, all forks fine. Very strange. Is this a redhat problem or a problem with pyPAM? cu & thx janek The test script: import sys import PAM from getpass import getpass def pam_conv(auth, query_list, userData): resp = [] for i in range(len(query_list)): query, type = query_list[i] if type == PAM.PAM_PROMPT_ECHO_ON: val = raw_input(query) resp.append((val, 0)) elif type == PAM.PAM_PROMPT_ECHO_OFF: val = getpass(query) resp.append((val, 0)) elif type == PAM.PAM_PROMPT_ERROR_MSG or type == PAM.PAM_PROMPT_TEXT_INFO: print query resp.append(('', 0)) else: return None return resp service = 'wwwproject' if len(sys.argv) == 2: user = sys.argv[1] else: user = None auth = PAM.pam() auth.start(service) if user != None: auth.set_item(PAM.PAM_USER, user) auth.set_item(PAM.PAM_CONV, pam_conv) print auth.authenticate() #print auth.acct_mgmt() sys.exit(0) -- "Macht korrumpiert. Absolute Macht korrumpiert absolut." - Stefan Heym - From theller at python.net Fri Aug 22 16:24:29 2003 From: theller at python.net (Thomas Heller) Date: Fri, 22 Aug 2003 22:24:29 +0200 Subject: py2exe service doesn't work, can't connect to service controller ? References: <3F41F576.14352.14BE73C2@localhost> Message-ID: "Brad Clements" writes: > I edited the svc_run.exe file and changed PyWinTypes22.dll to > PyWinTypes23.dll. py2exe now builds a distribution that does not use any 2.2 > Python components. > > However the service still fails to load after installation with the > following error: > > > The description for Event ID ( 240 ) in Source ( MyService ) cannot be > found. The local computer may not have the necessary registry information or > message DLL files to display messages from a remote computer. The following > information is part of the event: 1063, The service process could not > connect to the service controller.. > > Has anyone been able to get py2exe services to work with 2.3? > Brad, I've uploaded a new py2exe binary installer for Python 2.3. There may still be problems with the event log (the descriptions are not found), but otherwise at least the py2exe sample service works correctly. Well, you can install, start, stop, and remove it ;-) Thomas From adalke at mindspring.com Sun Aug 10 20:00:38 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Sun, 10 Aug 2003 18:00:38 -0600 Subject: How to print floating point in scientific format? References: <420ced91.0308081115.7060e551@posting.google.com> <420ced91.0308090642.176b856b@posting.google.com> <420ced91.0308101125.3dee1bfe@posting.google.com> Message-ID: sdhyok: > What is your best way for my example? > (I hope it is not for loop.) It's a for loop. I disagree with your assessment that it's a problem, so I'll understand if you disagree with my solution. Andrew dalke at dalkescientific.com From gregbrunet at NOSPAMsempersoft.com Wed Aug 6 22:17:40 2003 From: gregbrunet at NOSPAMsempersoft.com (Greg Brunet) Date: Wed, 6 Aug 2003 21:17:40 -0500 Subject: Class design issues: multiple constructors Message-ID: I'm trying to write a package to handle working with DBase files. There's enough different stuff in handling them (unfortunately) that I'm not going to try to the interface DB-API 2.0 compliant - it'll be a lower level wrapper around reading & writing the DBF files. In trying to design a good framework, however, I'm unsure of how to progress. I intend to have a class to represent the actual DBF files, and I would expect to have an __init__ method to be called when creating a new instance. When I first started, I included a filename as a parameter that would be used to open an existing DBF file. Next I decided to add the ability to create a new DBF file. This method needs additional parameters (such as the field definitions), and, while in some other languages, I could provide 2 versions of the constructor (overload it if I'm using the right terminology), and the compiler would use the appropriate one, things don't seem to work that way in Python. I'm also thinking that I might rather name the methods more specifically (such as Open & Create) instead of both being __init__. What would be the Pythonic way to go about doing this? Would I make an __init__, Open, & Create methods, and make 2 calls for each DBF object, like this: class dbf: __init__(self): pass Create(self, filename, fieldDefs): pass Open(self, filename): pass # open existing file f1 = dbf() f1 = dbf.Open('customer.dbf') # create a new file f2 = dbf() f2 = dbf.Create('states.dbf', [('StateCode', 'C', 2), \ ('StateName','C',20)] Or maybe there's a clean way to be able to 'bundle' the initialization/construction into the Create & Open method calls. Thanks for the help, -- Greg From gerald.hein at epost.de Tue Aug 19 00:30:12 2003 From: gerald.hein at epost.de (Gerald Hein) Date: Tue, 19 Aug 2003 06:30:12 +0200 Subject: usage of python 2.3 and Tk on freebsd ? Message-ID: <3F41A7D4.7020002@epost.de> Hi, I'm using FreeBSD 4.8 and upgraded to python 2.3. I tried import Tk and got an error message telling me that python is not configured for Tk. I never tried importing Tk before, so I don't know what t I've to do to fix this. Python seems to have a problem with _tkinter. What could be done in order to get python configured for Tk ? Thanks, Gerald From maxm at mxm.dk Sun Aug 10 14:26:36 2003 From: maxm at mxm.dk (Max M) Date: Sun, 10 Aug 2003 20:26:36 +0200 Subject: Need elegant way to cast four bytes into a long In-Reply-To: <3f33c209$1@news.si.com> References: <3f33c209$1@news.si.com> Message-ID: <3F368E5C.7020105@mxm.dk> William S. Huizinga wrote: > I've got an array.array of unsigned char and would like to make a slice > of that array (e.g. a[0:4]) become one long like I would in "C" : > > l = ((unsigned long *) (&a[0]))[0]; > > I have been getting what I want in this sort of manner : > > l = 0L > l = a[0] > l += a[1] << 8 > l += a[2] << 16 > l += a[3] << 24 > > but I think that's too wordy. Is there a more intrinsic and elegant way > to do this? def readBew(value): "Reads string as big endian word, (asserts len(string) in [1,2,4])" return unpack('>%s' % {1:'b', 2:'H', 4:'l'}[len(value)], value)[0] def writeBew(value, length): """ Write int as big endian formatted string, (asserts length in [1,2,4]) """ return pack('>%s' % {1:'b', 2:'H', 4:'l'}[length], value) Any of those usefull? regards Max M From dtolton at yahoo.com Wed Aug 20 13:28:41 2003 From: dtolton at yahoo.com (Doug Tolton) Date: Wed, 20 Aug 2003 17:28:41 GMT Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> <6dj2kv8ugkieehs7guh786cl40o5lj6mcs@4ax.com> Message-ID: On Mon, 18 Aug 2003 18:16:07 -0600, "Andrew Dalke" wrote: >Doug Tolton >> I don't agree at all. Yes when you are defining a macro you are in >> essence defining a new mini-language. This is perhaps one of the most >> powerful features of Lisp. Programming closer to the application >> domain, *greatly* enhances both the readability and the reusability of >> code. > >For that domain. And rarely does the author of a package, >much less a macro, understand "the domain as understood by other >people" vs. personal understanding. It depends what you are talking about. If you are talking about making some large cross industry library I might be inclined to agree, but when it comes to building good high level abstractions within a company, this argument doesn't make sense. Any feature has to be used in the proper context for it to be useful, Macros are also this way. > >This topic has come up before. Laura Creighton made several >comments on macros, the most notable of which is: > >lac: >] Writing your own Lisp Macro System is better than sex. I >] _know_ -- 18 year old me turned down _lots_ of opportunities >] for sex to go hack on her macro system. Thus if we introduce >] this to the language, I think that it is _inevitable_ that we will >] fragment the Python community into a plethora of mutually >] unintelligble dialects. I don't want this. Thus I don't want a >] macro facility in the language _because_ it would be so cool. > I just don't find that argument compelling. By that logic we should write the most restrictive language possible on the most restrictive platform possible (ie VB on Windows) because allowing choice is clearly a bad thing. Don't introduce a feature because it would be so cool that everyone would use it? That's just plain weird. The Python Core language would still always be controlled by Guido, but I don't see the problem with a community of people writing cool macro's for python. Linux is based on this concept of allowing people to extend the system, it doesn't seem to have suffered from it. >> That doesn't mean it *shouldn't* be available [in Python]. >> Python is Open Source, how would someone writing a >> Macro lock you in? Just don't use the macro. > >Another writing from Laura seems relevant: >http://mail.python.org/pipermail/python-list/2001-May/042102.html > >My interepretation - I don't customize my apps, nor even >my .cshrc (except for one alias (alias ls 'ls -l \!* | grep ^d') >an 'unset noclobber', 'set ignoreeof', and the PATH and >LD_LIBRARY_PATH - and I wish I didn't need those) >I don't, because I don't like to think. At least not spend my >time puzzling out slight changes. I like my changes either >none or a lot, that is, use Python as-is or write a converter >(or use another language). > Same argument as above, I don't agree with this logic. Python is a great language, that doesn't mean it couldn't be better though. If that were the case development would be cease. Why do we allow people to write functions even, I mean you have to learn the syntax for calling them, what the variables are and what they do. Bah, we should make everyone use only built in functions, if they want a different one, use a different language. What? It makes no sense to me. >> Just like anything else, Macro's can be over used and abused. However >> I maintain that if you don't see the usefulness of macros, you don't >> really understand them. > >That's not the argument against them. It's that they are too useful, >each person makes their own dialect, the community breaks down >as the different branches do their own thing, and one person's so- >called "Python" code looks different than another's. > So don't allow people to customize the system huh? They why is Python Open Source? That's the *entire* point of Open Source, so that people can tweak and customize to their own environment. Do you have any specific examples that are comparable where customization broke a community down? This sounds like baseless hypothetical speculation to me. >I know I am nowhere near as good a language designer as Guido, >Larry Wall, Matz, and the others, though I think I'm pretty decent. >I don't have the essential hubris to say that I know better how >to tweak Python-the-language to fit my own domain. > You are saying you don't know how to tweak a language to fit it your specific domain better than a general puprose language? And you are saying you are a pretty good language designer? If you don't know your specific domain well enough to adapt a general purpose language to it better than it is already written there are several possibilities: 1) You don't know your domain that well 2) You work in a very general purpose domain 3) You aren't a very good language designer Designing a good language is all about designing the right high level abstractions. Even a medium skilled designer should be able to design a language that maps better to their specific domain than a general purpose domain (actually implementing is of course a vastly different story). The whole point of Macro's though is to allow you to leverage the facilities the language provides while at the same time abstacting the common idioms. >> Essentially using Python over Machine >> language is just using one big ass macro language. > >You confuse two meanings of the word 'macro' here. >Any assembly language worth its salt has "macros", which >are pre-assembled sets of code. Use the macro and it >generates the code. But you can't use those macros to >rewrite the actual language like you can with hygenic >macros. It doesn't have the proper tail-biting recursive nature. I am not talking about Assembly Macros. I was comparing hygenic macros to the ability to make useful high level abstractions. Python is an abstraction of Machine Language whereas Macros would allow you to abstract Python. You are in essence saying that Python is perfect, that no one could make a more useful abstraction than it already has, and that saying that one could do so is hubristic. I reject your argument and your logic as specious. I think what makes Python so useful is the high level abstractions it offers. The fact that it let's me do things that *I* know are right for my domain. That it doesn't make the assumption that Guido knows best for my domain (because I guarantee you I know my domain better than Guido does). Python doesn't treat me like the idiot programmer who can't be given a powerful tool because it might hurt me. Ultimately this is the basis of Java / C# / Visual Basic. Don't give the programmer room, he might hurt himself, or abuse something. That paradigm is filled, there are many languages that restrict programmers because they might misuse a feature, or they are just too dumb to get it right. I say fine, leave the languages like Java / C# / VB to those people, but let's make Python a language that allows people the room to do it the way it needs to be done, not so much the way Guido or whoever thinks it should be done. Just my 2p Doug Tolton (format t "~a@~a~a.~a" "dtolton" "ya" "hoo" "com") From google at hanger.snowbird.net Fri Aug 22 03:27:39 2003 From: google at hanger.snowbird.net (Kris Caselden) Date: 22 Aug 2003 00:27:39 -0700 Subject: Weird Problem References: <3F44E0E4.779D6409@engcorp.com> Message-ID: Actually, the problem turned out to be a combination of previously having used "from os import *" along with not having reloaded the code in Pythonwin. Thanks for everyone's help. Peter Hansen wrote in message news:<3F44E0E4.779D6409 at engcorp.com>... > Kris Caselden wrote: > > > > I'm sure this is a simple newbie problem, but I can't figure it out > > for the life of me. > > > > The code: > > import sys, os > > input = open("example.py","r") > > > > Gives me the error: > > TypeError: an integer is required > > Always post the actual code, and the *full* traceback, and > don't just retype it: cut and paste. From tcronj at ananzi.co.za Thu Aug 28 17:56:08 2003 From: tcronj at ananzi.co.za (Tertius) Date: Thu, 28 Aug 2003 23:56:08 +0200 Subject: opposite of dict.items() In-Reply-To: References: <3f4e708c$0$64719@hades.is.co.za> Message-ID: <3f4e7a3c$0$64726@hades.is.co.za> Peter Otten wrote: > Tertius wrote: > > >>Is there a method to create a dict from a list of keys and a list of >>values ? > > >>>>dict(zip(range(3), "abc")) > > {0: 'a', 1: 'b', 2: 'c'} > > Not a method() but a method. > > Peter > > much better than a for loop :) thnx From agh at tpg.com.au Sat Aug 16 22:37:19 2003 From: agh at tpg.com.au (Alastair G. Hogge) Date: Sun, 17 Aug 2003 12:37:19 +1000 Subject: Tuple to string problems References: <3f3b9080@dnews.tpgi.com.au> Message-ID: <3f3eea56@dnews.tpgi.com.au> Sean Ross wrote: > > "Alastair G. Hogge" wrote in message > news:3f3b9080 at dnews.tpgi.com.au... >> So basicly final_qu would be ('1','two','hello','2003-08-14','23:32:07') >> However has stated above type(final_qu) return tuple. > > If final_qu is already a tuple of strings, and what you need is one string > with each string in the tuple concatenated, then you can do this: > >>>> final_qu = ('1','two','hello','2003-08-14','23:32:07') >>>> final_qu_str = ' '.join(final_qu) >>>> final_qu_str > '1 two hello 2003-08-14 23:32:07' >>>> > > If you can't guarantee that each tuple element is a string, try this: >>>> final_qu_str = ' '.join([str(e) for e in final_qu]) >>>> final_qu_str > '1 two hello 2003-08-14 23:32:07' >>>> > > [str(e) for e in final_qu] creates a list of a strings from the elements > [in > final_qu. > > HTH > Sean OK. Sorry I didn't quite make myslef clear. final_qu is a string for pydb. The string should be something link: INSERT INTO foo VALUES "('1','two','hello','2003-08-14','23:32:07')" I need the () and each value must be inclosed in '' for the database interface. From val at vtek.com Fri Aug 22 17:51:56 2003 From: val at vtek.com (val) Date: Fri, 22 Aug 2003 17:51:56 -0400 Subject: error compiling Python 2.3 Message-ID: Hi the Gurus, i'm trying to compile Python 2.3 remotely (telnet access). It is Cobalt. Linux 2. mips. gcc 2.7.2. This is a piece of output when doing ./configure ... ## ---------------------- ## ## Running config.status. ## ## ---------------------- ## This file was extended by python config.status 2.3, which was generated by GNU Autoconf 2.53. Invocation command line was CONFIG_FILES = CONFIG_HEADERS = CONFIG_LINKS = CONFIG_COMMANDS = $ ./config.status on ns2.spiderwebhost.net config.status:695: creating Makefile.pre config.status:695: creating Modules/Setup.config config.status:25: error: cannot find input file: Modules/Setup.config.in When i'm looking into Modules, there is no Setup.config up there. Naively doing make I get: make: *** No targets specified and no makefile found. Stop Any advice? Or, maybe a pointer to the binary please? Thanks, Val From mis6 at pitt.edu Sun Aug 24 07:29:15 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 24 Aug 2003 04:29:15 -0700 Subject: Python is darn fast (was: How fast is Python) References: <2259b0e2.0308230737.8a9bc1c@posting.google.com> Message-ID: <2259b0e2.0308240329.43331023@posting.google.com> Your remark made me check which a.out I was timing (I had two versions, an optimized one and a standard one). Since I had compiled them one month ago, I made some mistake and the numbers I posted refer to the non-optimized version, actually :-( Sorry about that, it seemed too good to be true ! (a factor of 2 in favor of Python!). With the respect to the -O3 optimized version the gain of Python over C is only of 15-20% (Irmen de Iong reported 30% on his machine). I am sure that with a newer compiler and smart switches one can revert the ratio. But the message is still the same: on this numerical computation, taken from a real life case, C does not have any significant advantage over Python. Maybe the reason is the slow C implementation of exp or some other accident, but still this is a quite impressive result. Michele From belred1 at yahoo.com Sat Aug 2 19:52:50 2003 From: belred1 at yahoo.com (Bryan) Date: Sat, 02 Aug 2003 23:52:50 GMT Subject: pyrex error References: <8YPWa.48874$YN5.38312@sccrnsc01> Message-ID: "Gerhard H?ring" wrote in message news:mailman.1059853685.20382.python-list at python.org... > Bryan wrote: > > [PyRex produces code using staticforward that won't work in the combination Python 2.3/MSVC] > > 1) Please don't top-post. > > 2) The other way to temporarily solve this problem is to use MINGW > instead of MSVC. > > In the PySQLite sources, I added this snippet on top: > > #ifdef _MSC_VER > #define staticforward extern > #endif > > to make it compilable under MSVC/Python 2.3. *After* #include-ing > "Pyhton.h" of course. > > -- Gerhard > ifdef'ing for _MCS_VER won't solve the problem for compiling under 2.2 and 2.3. is there a way to ifdef this for 2.2 and 2.3 under windows as well as gcc? bryan From Ingmar.Blum at zumtobelstaff.co.at Thu Aug 21 10:47:28 2003 From: Ingmar.Blum at zumtobelstaff.co.at (Blum Ingmar) Date: Thu, 21 Aug 2003 16:47:28 +0200 Subject: Out of Office AutoReply: Your details Message-ID: <0E98032F74AEBC42AB09E5AD1E1C589F027A718A@dop106.zumtobel.co.at> Danke f?r Ihre E-Mail. Ich bin bis 25.08.2003 nicht im B?ro. Diese E-Mail wird nicht weitergeleitet. Nach meiner R?ckkehr werde ich sie baldm?glichst bearbeiten. In dringenden F?llen wenden Sie sich bitte an AGNES ZEINER - eMail: agnes.zeiner at zumtobelstaff.co.at - Telefon:+43 (5572) 390-1303 Mit freundlichen Gr??en Ingmar Blum Head of eBusiness, Zumtobel Staff GmbH Thank you for your e-mail. I shall be out of office until 25.08.2003. This e-mail will not be forwarded. I will contact you as soon as possible when I am back. In urgent cases, please contact AGNES.ZEINER - eMail: agnes.zeiner at zumtobelstaff.co.at - Telefon:+43 (5572) 390-1303 Yours sincerely, Ingmar Blum Head of eBusiness, Zumtobel Staff GmbH From hq1998 at 263.net Sat Aug 30 07:41:23 2003 From: hq1998 at 263.net (He Qiang) Date: Sat, 30 Aug 2003 19:41:23 +0800 Subject: How to transform decimal to base64 Message-ID: base64 module only provide interface for string to base64, I want to know how to transform decimal digit to base64. For example, 1 -> base64, not "1". Thanks. Regards He Qiang hq1998 at 263.net From donn at u.washington.edu Mon Aug 25 13:25:42 2003 From: donn at u.washington.edu (Donn Cave) Date: Mon, 25 Aug 2003 10:25:42 -0700 Subject: OT: Ocaml? References: <7xk795xde6.fsf_-_@ruckus.brouhaha.com> Message-ID: In article <7xk795xde6.fsf_-_ at ruckus.brouhaha.com>, Paul Rubin wrote: > Anyone here use OCAML? How do you like it? Is it a language a > Pythonista can learn to love? From what little I've seen, it looks > interesting, but I haven't actually tried installing or using it yet. I think typically, people who like Python tend to say they like Haskell more often than Objective CAML. Haskell is more similar in one very superficial respect - its layout notation is like Python's indented notation - but it's basically much farther from Python in terms of fundamental notions about programming. So it's different in interesting ways. Haskell is pretty, on a couple of different levels. Ocaml is by comparison efficient, portable, fast, predictable, but I have to say Objective CAML is one of the ugliest languages I ever saw - regrettable syntax, baroque core language, awkward support for basic data types like strings and numbers. (So for me it's worth making a distinction between ocaml, which I think is brilliant, and Objective CAML the sorry language it implements.) Incidentally, a few years back someone got fairly far along on implementing Python (or something like it) from scratch in Objective CAML. Donn Cave, donn at u.washington.edu (What about that syntax complaint - just my inflexible esthetic taste, maybe? Consider this, you decide: let jump d v = begin match d with UP -> begin output_string stdout "Jump up\n"; match v with 0 -> nonjump () | _ -> jumpup v end | DOWN -> begin output_string stdout "Jump down\n"; match v with 0 -> nonjump () | _ -> jumpdown v end; output_string stdout "done jumping\n" end ;; jump UP 3 Would you expect "done jumping"? Objective CAML's syntax for a procedural block is expressions separated by ";", optionally enclosed in "begin"/"end" or parentheses. The DOWN branch starts with a begin/end block, but it's utterly ambiguous whether the semicolon that follows that block starts a new expression in the DOWN branch, or in the function block. The compiler actually does the former. Because begin/end is optional for blocks, in practice you have to put it around single expressions like match UP/DOWN here, and that's annoying and counter-intuitive.) From CousinStanley at hotmail.com Wed Aug 6 19:47:18 2003 From: CousinStanley at hotmail.com (Cousin Stanley) Date: Wed, 6 Aug 2003 16:47:18 -0700 Subject: MVC in Python References: Message-ID: I've also been looking for Python MVC examples and ran across a simple example for WebWare ... http://webware.colorstudy.com/twiki/bin/view/Webware/ModelViewController The model and controller are plain-vanilla Python and the view module contains the WebWare interface ... Since I have NO clue about WebWare, I haven't tried to convert it to anything else ... Perhaps someone that is more familar with WebWare programming could provide a conversion to something like Tkinter ... -- Cousin Stanley Human Being Phoenix, Arizona From mark at diversiform.com Wed Aug 6 13:27:48 2003 From: mark at diversiform.com (Mark Daley) Date: Wed, 6 Aug 2003 10:27:48 -0700 Subject: Tkinter programming problem In-Reply-To: Message-ID: I have problems with sys.exit() when I'm running under IDLE, since it seems to cause ALL mainloops to exit, killing IDLE. I can't really give a whole lot of detail on this, since I tend to use the command line to launch my GUIs, anyway. - Mark -----Original Message----- From: python-list-admin at python.org [mailto:python-list-admin at python.org]On Behalf Of Eric Brunel Sent: Wednesday, August 06, 2003 7:35 AM To: python-list at python.org Subject: Re: Tkinter programming problem Kevin Burrows wrote: > If I follow this thread correctly we are discussing how the exit from > Python/Tkinter programs. As it happens I have beed experimenting with > these environments and have struck the same problem.Examples from > "Python and Tkinter Programming" by John E Grayson. These examples > fire up OK but when the Quit button is hit the window freezes. If the > X in the window corner is hit first the application exits correctly. > > Several suggestions have been suggested. I have experimented with the > following program: > > #!/usr/local/bin/python > from Tkinter import * # Interface to Tk widgets > > class Application(Frame): > def __init__(self, master=None): > Frame.__init__(self, master) > self.grid() > self.createWidgets() > > def createWidgets(self): > self.quitButton = Button ( self, text="Quit", > command=self.quit ) > self.quitButton.grid() > > def quit(self): > print sys.platform > print "Quitting" > self.quit #--DOES NOT QET RID OF WINDOW > # sys.exit(0) #--DOES NOT GET RID OF WINDOW > # self.master.destroy() #--GETS RID OF WINDOW This can't be the code you tested, since, again, there are no () after self.quit. Moreover, even if you had written self.quit(), it wouldn't have worked since this would call again the quit method on Application recursively, ending up in an exception. What you should have written is: Frame.quit(self) > app = Application() # Instantiate the application class > app.master.title("Sample application") > app.mainloop() # Wait for events > > I changed commented out 2 of the 3 methods in the "quit" function > under PythonWinIDE, IDLE and Windows using a .pyw extension. > > The results of the quit methods were: > > PythonWinIDE IDLE Windows using > a .pyw extension > > quit No No No > > sys.exit No No Yes > > destroy No No Yes > > Interstingly the application does not freeze under IDLE and can still > be closed with the windows X. > > I am using Windows 98 and Python 2.2 There always have been issues with Tkinter on Windows 98: Tkinter applications often freeze on exit, but not always. This is likely to be a Windows issue, since it works everywhere else, even on more recent version of Windows with the same tcl/tk version. > So it looks like "destroy" is the method that works. It is > interesting that the example and test in the Tkinter.py module use the > "destroy" method but Grayson uses "quit" in his examples. Perhapse > the problem with "quit" is a MS Windows thing. You definetely should use quit: quitting Tkinter's main loop is its intended use; see http://www.pythonware.com/library/tkinter/introduction/x9374-event-processin g.htm > I would be interested to here if the same thing happens under Unix et. > al. I never had any problem with the quit method on Unix (Linux or Solaris) or on recent version of Windows (2k, XP). I'm however always running the Python scripts from the command line, never from an IDE. So that may be an issue too... -- - Eric Brunel - PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com -- http://mail.python.org/mailman/listinfo/python-list From sjmachin at lexicon.net Sat Aug 2 23:18:27 2003 From: sjmachin at lexicon.net (John Machin) Date: Sun, 03 Aug 2003 03:18:27 GMT Subject: Match beginning of two strings References: <3f2c429e@nntp0.pdx.net> Message-ID: <3f2c7806.20532894@news.lexicon.net> On Sat, 02 Aug 2003 21:18:32 -0700, Scott David Daniels wrote: >Ravi wrote: >> Hi, >> >> I have about 200GB of data that I need to go through and extract the >> common first part of a line. Something like this. >> >> >>>a = "abcdefghijklmnopqrstuvwxyz" >> >>>b = "abcdefghijklmnopBHLHT" >> >>>c = extract(a,b) >> >>>print c >> "abcdefghijklmnop" >> >> Here I want to extract the common string "abcdefghijklmnop". Basically I >> need a fast way to do that for any two given strings. For my situation, >> the common string will always be at the beginning of both strings. I can >> use regular expressions to do this, but from what I understand there is >> a lot of overhead. New data is being generated at the rate of about 1GB >> per hour, so this needs to be reasonably fast while leaving CPU time for >> other processes. >> >> Thanks >> Ravi >> >While you can be forgiven for not have guessed, os.path is the place to >look: > import os.path > a = "abcdefghijklmnopqrstuvwxyz" > b = "abcdefghijklmnopBHLHT" > print os.path.commonprefix([a,b]) > I don't think that os.path.commonprefix was designed with 200Gb of data in mind. Inspection of Lib/*path.py gives one the impression that it spends a lot of time discovering that the first element is a prefix of itself. Ravi, You may need to drop down to C to get the speed you want for your requirement to find the longest common prefix of two strings. Two things puzzling me: (1) how you would do this with regular expressions (2) you have 200Gb now, new data arriving at the rate of 1Gb per hour, after a year you have almost 9000Gb; where are you putting it all? BTW, I do hope your algorithm is not O(N**2) ... Cheers, John From rmunn at pobox.com Mon Aug 18 12:40:51 2003 From: rmunn at pobox.com (Robin Munn) Date: Mon, 18 Aug 2003 16:40:51 GMT Subject: Strange re behavior: normal? References: Message-ID: Michael Janssen wrote: > > What's the good of splitting by boundaries? Someone else wanted this a > few days ago on tutor and I can't figure out a reason by now. Heh. I bet I know the name of the person who was asking about this on the tutor list. He's a friend of mine, and I've been helping him learn Python. He E-mailed me about trying to split on word boundaries with re.split(r'\b', 'some text'), and it was his E-mail that caused me to discover that splitting by boundaries didn't do what I expected. What's the good of it? As someone else pointed out, it allows you to fetch the words and the separating text, yielding: ['See', ' ', 'Spot', '. ', 'See', ' ', 'Spot', ' ', 'run', '.'] which may be useful in certain English-language-parsing situations, since it would allow you to look "ahead" or "back" from a word to see what punctuation precedes or follows it. Anyway, the re.split behavior I described isn't particularly bothering me, but I do think it should be better documented. Time to submit a doc patch, methinks... -- Robin Munn | http://www.rmunn.com/ | PGP key 0x6AFB6838 -----------------------------+-----------------------+---------------------- "Remember, when it comes to commercial TV, the program is not the product. YOU are the product, and the advertiser is the customer." - Mark W. Schumann From pobrien at orbtech.com Fri Aug 29 20:32:42 2003 From: pobrien at orbtech.com (Patrick K. O'Brien) Date: 29 Aug 2003 19:32:42 -0500 Subject: Object Database (ODBMS) for Python References: <1DAECE9E8F34E04AA0E5699AF7D9FF090708D440@stpmsg00.corp.fairisaac.com> <3f4f7af6_3@corp.newsgroups.com> Message-ID: Jeremy Jones writes: > On Fri, 29 Aug 2003 12:11:51 -0400 > "Paul D. Fernhout" wrote: > > > By the way, I like your overview of various related ODBMS projects > > here: http://www.orbtech.com/wiki/PythonPersistence (maybe > > http://munkware.sourceforge.net/ might go there now?) > > I wouldn't be offended if Munkware found its way to the > PythonPersistence page ;-) Me either. It's a wiki, so please feel free to add anything you like. -- Patrick K. O'Brien Orbtech http://www.orbtech.com/web/pobrien ----------------------------------------------- "Your source for Python programming expertise." ----------------------------------------------- From martin at v.loewis.de Tue Aug 5 15:21:46 2003 From: martin at v.loewis.de (Martin v. =?iso-8859-15?q?L=F6wis?=) Date: 05 Aug 2003 21:21:46 +0200 Subject: Win32All Crashes Python 2.3? References: <1tkngb.2h1.ln@boundary.tundraware.com> Message-ID: Tim Daneliuk writes: > OK, after some highly-technical debugging procedures (print statements! ;), > I have determined that os.lstat() is blowing up when Win32All is being > used. What is strange is that this only happens sometimes. For the life > of me, I cannot see anything in my code that is causing the problem. > It sure looks to me like an errant pointer or something in Win32All. > > FWIW, Dr. Watson is reporting an Access Violation... Please verify that there is only a single copy of the CRT in your process. Regards, Martin From cartermark46 at ukmail.com Thu Aug 14 10:09:33 2003 From: cartermark46 at ukmail.com (Mark Carter) Date: 14 Aug 2003 07:09:33 -0700 Subject: ClientCookie bug (fix offered) References: Message-ID: > > I am using Windows 98, python 2.3, ClientCookie 0.4.3a. > > > > When I do: > > c.load_from_registry() > > > > I get the response: > > KeyError: 'USERNAME' > I suspect this only works on "real" win32 (the NT family) operating I have a fix/workaround for this - and would like it included in ClientCookie. It my problems out real nice! Interested? BTW, I can't seem to locate the project on Sourceforge. From vze4rx4y at verizon.net Sun Aug 24 22:48:26 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Mon, 25 Aug 2003 02:48:26 GMT Subject: Suggestion/recommendation for dictionary formatting References: Message-ID: <_Ne2b.4519$t57.3756@nwrdny01.gnilink.net> "John D." wrote in message news:mailman.1061773823.16870.python-list at python.org... > I've experimented with this and concluded: > > {1:2, 3:4, 5:6, 7:8} > > is more readable than the current output: > > {1: 2, 3: 4, 5: 6, 7: 8} > > Removing the space after the colon more clearly > shows the key:value pairings. The effect is less striking > with longer and more complex items, but it is never detrimental. > > Summary of proposed change: > --------------------------- > Synopsis: Remove space after the colon in formatted dictionary dumps > Purpose: Legibility improvement > Effect on existant programs: Minimal -this is mostly cosmetic > Difficulty of implementation: Trivial for one familiar with core code > Security issues: None > > Comments anyone? Here is one data point ------------------------- An indicator of what is natural is to see the writing style used when creating dictionaries in production code. Grepping for { in python/lib/*.py, I see that with only one exception (rfc822.py), all of the hardcoded dictionaries use a space after the colon. Raymond Hettinger From fincher.* at osu.edu Thu Aug 7 06:11:10 2003 From: fincher.* at osu.edu (Jeremy Fincher) Date: Thu, 07 Aug 2003 06:11:10 -0400 Subject: itertools.ilen? References: Message-ID: Michael Peuser wrote: > There is no way to determined, whether such generartors will come to an > end - The Halting Problem for Turing Machines ;-) > Thus there will never be a safe len(iterator). But then, there's no way to determine whether any given class' __len__ will terminate, so you've got the same problem with len. Granted, it's more likely to manifest itself with iterators and ilen than with sequences and len, but if it's really an issue, ilen could take an optional "max" argument for declaring a counter ilen isn't to exceed. Jeremy From vanevery at 3DProgrammer.com Mon Aug 18 17:55:21 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Mon, 18 Aug 2003 14:55:21 -0700 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: <3F412484.69867AED@alcyone.com> Message-ID: Istvan Albert wrote: > Erik Max Francis wrote: > >>> What's ***TOTALLY COMPELLING*** about Ruby over Python? >> >> comp.lang.ruby doesn't have Brandon Van Every. Erik has been in my killfile forever, from other newsgroups. I even had to put him back in after letting him out. I thought a year would have been enough, but apparently not. > LOL > > Istvan. So, you're guilty by association. Goodbye! -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From Dick.Zantow at lexisnexis.com Thu Aug 28 09:03:30 2003 From: Dick.Zantow at lexisnexis.com (rzed) Date: Thu, 28 Aug 2003 09:03:30 -0400 Subject: Style question... References: <3F4DFAAC.1356C276@engcorp.com> Message-ID: Peter Hansen wrote: > "U. N. Owen" wrote: >> >> For the moment I work on (a small part of) a project >> that has hundreds of thousands of lines, almost >> eveything in Python (and some in C and Fortran), >> and when you have a loop several pages long, or >> nested blocks to 8 levels or more, I may say >> it's *very* convenient to see where the end >> of a block exactly is. It's convenient to >> have some long variable names too. > > I use Scite, which provides a graphical means of representation > the indentation, with vertical lines that extend down at every > indent level. (It would have to be later in the day for me to > be coherent enough to describe it better.) Suffice to say that > it provides more than adequate (for me) visual indication of the > end of a block that stretches too far. > > A better point I'd make however is that if you have a loop several > pages long, or a nested block 8 levels deep, the code needs > refactoring! Saying this occurs in a large project does nothing > to excuse it: the more code you have, the greater the need for > structuring it well. > The only times I've seen the lack of a block delimiter as a problem is when somebody plops some sample code in a usenet message and uses tabs for indenting. OE strips out the leading tabs for some reason, so everything winds up flush to the left margin. Once in awhile it is not possible to recreate the proper indention, and for that reason I try to include comment delimiters in code I send. When I don't forget, at least. A better solution might be to physically restrain the posters of tab-infested code from doing that, but there are only so many hours in the day. And if OE wouldn't do what it does ... but then, where would be the fund in that? -- rzed From mwh at python.net Thu Aug 7 09:46:42 2003 From: mwh at python.net (Michael Hudson) Date: Thu, 7 Aug 2003 13:46:42 GMT Subject: where are docutils tools installed? References: <6f03c4a5.0308060631.7409f7b1@posting.google.com> Message-ID: <7h3d6fh7f9i.fsf@pc150.maths.bris.ac.uk> rimbalaya at yahoo.com (Rim) writes: > Hi, > > I've installed the latest docutils, but I can't find where the > tools have been installed. I can see them when I expand the > tarball, but I can't find them under site-packages. I don't think they do get installed by distutils at all. Cheers, mwh -- Q: Isn't it okay to just read Slashdot for the links? A: No. Reading Slashdot for the links is like having "just one hit" off the crack pipe. -- http://www.cs.washington.edu/homes/klee/misc/slashdot.html#faq From srijit at yahoo.com Sat Aug 23 07:03:56 2003 From: srijit at yahoo.com (srijit at yahoo.com) Date: 23 Aug 2003 04:03:56 -0700 Subject: Embedding a chart in excel References: <221d8dbe.0308212104.c4e45@posting.google.com> Message-ID: <221d8dbe.0308230303.72850884@posting.google.com> Hello, Can you send me the code? In the mean time I shall check setcell. Regards, Srijit Stephen Boulet wrote in message news:... > There seems to be a problem with UseExcel.setcell: > > >>> a.setcell(sht1.Name,1,(1,1)) > Traceback (most recent call last): > File "", line 1, in ? > File "excel_from_google.py", line 139, in setcell > sht.Cells(row, col).Font.FontSize = fontSize > File "C:\Python23\lib\site-packages\win32com\client\dynamic.py", line > 504, in __setattr__ > raise AttributeError, "Property '%s.%s' can not be set." % > (self._username_, attr) > AttributeError: Property '.FontSize' can not be set. > From abuseonly at sgrail.org Sat Aug 23 10:36:58 2003 From: abuseonly at sgrail.org (derek / nul) Date: Sat, 23 Aug 2003 14:36:58 GMT Subject: Bug with win32 open and utf-16 file Message-ID: HI all, I appear to have found a bug with win32 open and utf-16 files. utf-16 file available at www.sgrail.org/files/dash9.eng the program ----------------------------------------------------------------------------------- #!c:/program files/python/python.exe # win32 python 2.3 import sys, string, codecs #eng_file = list (open("c:/program files/microsoft games/train simulator/trains/trainset/dash9/dash9.eng", "rb").read()) # read the whole file eng_file = open("c:/program files/microsoft games/train simulator/trains/trainset/dash9/dash9.eng", "rb").read() # read the whole file print hexdump (eng_file) # ok ------------------------------------------------------------------------------------------- The original file has line terminator characters of 00 0d 00 0a. After being read into a variable or a list the line termination characters have been changed to 00 0a 00 0a hex dump after open $00000000 FFFE5300 49004D00 49005300 41004000 40004000 ..S.I.M.I.S.A....... $00000014 40004000 40004000 40004000 40004A00 49004E00 ..............J.I.N. $00000028 58003000 44003000 74005F00 5F005F00 5F005F00 X.0.D.0.t........... $0000003C 5F000A00 0A000A00 0A00 Any comments? Derek From adalke at mindspring.com Sun Aug 24 01:15:13 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Sun, 24 Aug 2003 05:15:13 GMT Subject: email bug? References: Message-ID: Stuart D. Gathman: > Here is my quick (and probably incorrect) fix: There's a test suite in email.tests. It includes tests for getparams, and I see some commented out code which lists a test known to fail. You could use that to check the validity of your code. Andrew dalke at dalkescientific.com From tismer at tismer.com Wed Aug 13 13:34:09 2003 From: tismer at tismer.com (Christian Tismer) Date: Wed, 13 Aug 2003 19:34:09 +0200 Subject: Howto MACRO in python ? In-Reply-To: References: <3F38D039.2B28800A@engcorp.com> <001201c360cd$3da065b0$6400a8c0@EVOD31> Message-ID: <3F3A7691.4030903@tismer.com> Bengt Richter wrote: ... > maybe there ought to be a magic __self__ in the local namespace of a function? > > Or better yet (?;-) if a user-defined function were a subclass of type function > instead of an instance, and a frame were an activation-instance of this function subclass, > then frame.__class__.__dict__ would be the function __dict__, where you could find attributes. I have similar thoughts, here, maybe simpler: A frame is something like an instance of a function, the function is somehow instantiated to be executed. Unfortunately, on creation of a frame, the function is "unpacked", in the sense that certain information is used to parameterize the frame, but then the frame has only the code object left. This is probably so, because frames are created in different context, like in the executable part of a class, or when the code of a script is run. There is no function, but there is a frame with a code object. Maybe it makes sense to just add the function/method to the code object as a new slot, which is either filled or set to None? I guess that not to do this was a decision from the pre-GC time, where this would have been a really bad circular reference? Then we could grow a frame attribute like __callable__ which grabs the callable from the code object. Maybe we should ask python-dev what they think. ciao - chris -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 mobile +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From sparhawk at gmx.at Wed Aug 13 16:04:36 2003 From: sparhawk at gmx.at (Gerhard W. Gruber) Date: Wed, 13 Aug 2003 22:04:36 +0200 Subject: Template module problem Message-ID: Several years ago I wrote a module for python to support templates. I submitted this to the python resource site and it was accessible through this link. Unfortunately this points to my old home page which is no longer. Since I forgot about this I havent updated it and now the webspace has been cleared out by the provider. If anybody downloaded this could you please send me a copy? I don't find the file anymore. :( Thanks! http://py.vaults.ca/apyllo.py/812237977.281773030.7554750.60218011 -- Gerhard Gruber F?r jedes menschliche Problem gibt es immer eine einfache L?sung: Klar, einleuchtend und falsch. (Henry Louis Mencken) From jepler at unpythonic.net Sun Aug 3 21:46:46 2003 From: jepler at unpythonic.net (Jeff Epler) Date: Sun, 3 Aug 2003 20:46:46 -0500 Subject: uTidyLib --I'm lost In-Reply-To: References: Message-ID: <20030804014642.GB10412@unpythonic.net> "yield" is a new keyword, related to support for generator functions. It is supported in Python 2.2 with "from __future__ import generators" and in 2.3 by default. Python 2.1 doesn't support the "yield" keyword. In short, you need to upgrade your Python to use this module. Jeff From anonymous at remailer.net Sat Aug 2 12:24:14 2003 From: anonymous at remailer.net (Wedrowiec) Date: Sat, 02 Aug 2003 18:24:14 +0200 Subject: ODBC & DbiData problem Message-ID: <5oonivsud5jrt522bldbevo6nvdf8ktqdp@4ax.com> I have a problem for experienced programmers. The following code should copy data between two different databases: import dbi,odbc conn1=odbc.odbc('mysql'); conn2=odbc.odbc('sqlite') c1 = conn1.cursor(); c2 = conn2.cursor() c1.execute("SELECT field1, field2 FROM table1") rows = c1.fetchall() c2.executemany('INSERT INTO table1 (field1=%s,field2=%s)', rows) c1.close();c1=None; c2.close();c1=None; conn1.close();conn1=None; conn2.close();conn2=None The problem is: field 'field2' is DATE type and after fetchmany() method I got DbiDate object instead of string 'YYYY-MM-DD HH:MM:SS'. So my code breaks because Python cannot insert such object to another database. I know how to convert this object to the correct string (http://www.python.org/windows/OdbcHints.html) but it must be done for every field in every row. :( So my question is: Is it possible to make odbc module to *automatically convert* this field from DbiDate object to string? Maybe is there any special parameter to set up? I do not want to write special code to convert all such fields. It suppose, it can be done more automatically by odbc module, bu I do not know how.... From mwilson at the-wire.com Fri Aug 1 10:38:17 2003 From: mwilson at the-wire.com (Mel Wilson) Date: Fri, 01 Aug 2003 10:38:17 -0400 Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> <73bpv-4f3.ln1@beastie.ix.netcom.com> Message-ID: In article , "Andrew Dalke" wrote: >Dennis Lee Bieber: >> Whereas BASIC started life as an interpreted language wherein >every >> statement had a line number, conditionals (IF) did jumps to line >> numbers, and all variables were global (even across subroutine calls). > >Not interpreted. >See http://wombat.doc.ic.ac.uk/foldoc/foldoc.cgi?Dartmouth+BASIC >] Dartmouth BASIC >] The original BASIC language [...] Unlike most later >] BASIC dialects, Dartmouth BASIC was compiled > >or a more detailed description at http://www.kbasic.org/1/history.php3 >which says the first interpreted BASIC was the Micro-Soft one for >the Altair. Hmm, OK. Let's say then that Darmouth BASIC was designed as a very lighweight compiler, for quick response. 'Designed for interaction' might cover it. Lightweightness would encoourage things like the 'LET' statment, single-character (+ optional type-suffix) variable names. My catch-phrase lately is "Python is to C++ as BASIC was to FORTRAN". I should be careful who I use it around, maybe. Regards. Mel. From pdfernhout at kurtz-fernhout.com Thu Aug 21 21:41:51 2003 From: pdfernhout at kurtz-fernhout.com (Paul D. Fernhout) Date: Thu, 21 Aug 2003 21:41:51 -0400 Subject: crazy programming language thoughts In-Reply-To: References: Message-ID: <3f457487_7@corp.newsgroups.com> Ryan Lowe wrote: > the basic concept would be to use identifying words in front of the > arguments to determine their identity as well as making the function call > read more like an english phrase. for instance, take the simple python > statement: >>>>vtext.replace('a', 'b') > wouldnt it be nicer (more english-like at least) to say: >>>>replace 'a' with 'b' in vtext > i just want to say that i know i saw a similar idea in another language, a > few years ago, but damned if i remember where or what language. i guess the > language didnt make it:( but if anyone knows a language like this, PLEASE > let me know. You may be thinking of Smalltalk. http://www.smalltalk.org/ although there are other languages with related phrasing (like in HyperCard? and even COBOL?). The Python code: x = sin(10) + 50 * 20 * self.myfunctionXY(cos(30), 40) would be in Smalltalk something like: x := 10 sin + (50 * 20 * self myfunctionX: 30 cos y: 40). where the order of precedence is unary (sin, cos), binary (+, *) and then keyword (myfunctionX:y:). Evaluation is otherwise left to right. Note the extra parentheses needed to ensure "*" is done before "+" as there is no other order of precedence. Note, Smalltalk has very few reserved words --- even things like "if" and "while" are typically done in Smalltalk as overrideable keywords of True and False classes (and the compiler may optimize these inline in some cases). I prefer Smalltalk's keyword type method function calls over Python's nameless parameters (yes they can be named but it is inelegant) because I think keywords are more self documenting of parameter expectations than function calls which do not indicate the possible number of paraeters or hint at their uses. However, I do prefer Python's use of significant white space over Smalltalk's use of braces to mark off blocks. (Although Smalltalk blocks are very powerful idea Python doesn't quite have except maybe as nameless functions.) I tend to use Python over Smalltalk these days because it is elegant enough, has lots of third party modules, has a good user community, has a fairly stable core, has books on it, appeals to C coders, is reasonably well licensed, and seems reasonably free of worries over copyright infringement etc (made easier because the language is different from most commercial languages, so there is little temptation or possibility to cut and paste library functions from commercial implementations). But I do miss keywords and Smalltalk's level of integration and transparency related to development tools and debugging GUIs down to the VM. I also miss changing the program while it runs for a complex GUI app; although I have recently learned how to do this some in Python from someone elses' usenet post a while back (although reloading a module still klunkier than Smalltalk but maybe this can be fixed by a better development environment which works more like a Smalltalk image by modifying live code). Incidentally, I'm not sure if Python really semantically needs the "." operator as opposed to a space, in which case it would look a little more Smalltalk like. For example: self.list.InsertColumn(0, "S") would seem to me could still be meaningful as: self list InsertColumn(0, "S") This of course might freak out some C programmers. But I don't think it would be ambiguous (I haven't thought this through completely though). But then I might also make ":' optional (despite the argument it is for clarity), and I might enforce indentation at two spaces (like Occam) and I might enforce variable declarations before use to avoid bugs from typos in assignments (like Smalltalk), and I might get rid of the need for "self" in object method function declarations (like Smalltalk) by making it implicit and enforcing the "self" name for any such reference. That last might not be a great idea as one of the nice things about Python is that functions and methods don't need to be compiled in different ways, unlike Smalltalk where there is a difference in compilation structure between blocks and methods, but maybe something could be worked through by a smart compiler seeing that a function with a reference to self in it was treated specially, and functions assigned to method slots could be somehow be upgraded to accept another argument if they didn't reference self (or perhaps all functions could take an implicit self?). I have tried to come up with a way to combine significant white space with Smalltalk syntax, but run up against difficulties with indenting keyword arguments when nesting keywords. I do think one can mix keyword function calls and significant white space easily and usefully, but perhaps only if one uses reserved words for block structuring (if, else, for, etc.) as opposed to Smalltalk's dynamic blocks. For example, the python method declaration def addOrFindStringRecord(self, string, readOnlyFlag = 0): if not readOnlyFlag: self.refreshLockFileIfNeeded() self.checkOpen() if Options.caching: try: if self.stringCache.has_key(string): location = self.stringCache[string] return self.readStringIndexRecord(location) except TypeError, e: # may generate type error if object not hashable pass ... becomes in this hybrid language (Pytalk?): def addOrFindStringRecord: string readOnlyFlag: readOnlyFlag = 0 if not readOnlyFlag self refreshLockFileIfNeeded self checkOpen if Options caching try if self stringCache has_key: string location = self stringCache[string] return self readStringIndexRecord: location except TypeError, e # may generate type error if object not hashable pass ... (Not sure what to do about brackets, so I left them...) I think that combination might be easier to maintain, but alas, Python is good enough that I don't see such a more perfect (IMHO) variant taking off anytime soon. Also, people would complain about the loss of variable length argument lists, and they would say it is good enough for IDE's to intelligently display parameter hints when hovering over a fucntion name. In any case, while Python is, like just about all things in this beautiful and mysterious world, not quite perfect, (and also open to argument over what perfection is), Python is elegant and fun and practical. And thanks be to Guido (and others) for making it happen. --Paul Fernhout -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! -----== Over 100,000 Newsgroups - 19 Different Servers! =----- From andrew-pythonlist at puzzling.org Thu Aug 28 00:48:52 2003 From: andrew-pythonlist at puzzling.org (Andrew Bennetts) Date: Thu, 28 Aug 2003 14:48:52 +1000 Subject: finding object using IS instead of == In-Reply-To: References: Message-ID: <20030828044852.GC7025@frobozz> On Wed, Aug 27, 2003 at 09:35:46PM -0700, Mark Hahn wrote: > Clarification: Is there a FASTER way that takes advantage of the IS > equivalence than using the available == method. I assume the == method does > a linear search, except for a dict key lookup, which is not what I'm talking > about. > > Obviously if two references are the same object (IS equivalent) then they > are == also so you could find based on == and then check for IS, but I want > something faster. Actually, (x != y) doesn't necessarily imply that (x is not y): >>> class NeverEqual: ... def __eq__(self, other): ... return False ... >>> ne = NeverEqual() >>> ne == ne False >>> ne is ne True I'm not sure how much this matters to you, though :) -Andrew. From grante at visi.com Wed Aug 27 15:22:36 2003 From: grante at visi.com (Grant Edwards) Date: 27 Aug 2003 19:22:36 GMT Subject: Filtering virus-related e-mails? References: <3f4ce4d6$0$166$a1866201@newsreader.visi.com> <7h3ad9v6jqu.fsf@pc150.maths.bris.ac.uk> Message-ID: <3f4d04fc$0$157$a1866201@newsreader.visi.com> In article <7h3ad9v6jqu.fsf at pc150.maths.bris.ac.uk>, Michael Hudson wrote: > grante at visi.com (Grant Edwards) writes: > >> Would it be possible for the python mailing list to filter out >> the "virus-warning" emails rather than posting them to the >> newsgroup? > > Possibly, but I think the admins are busier trying to stop the network > cables and the server melting due to the load... maybe now they've > done that they can turn to secondary effects. I gather virus warning > emails are quite hard to filter due to each virus program having a > different format. That's too bad. It makes them part of the problem as well. > (Earlier on today, Greg Ward brought up exim on the new version > of the starship; within ten minutes, the number of SMTP > connections had maxed out. Ten minutes after instituting the > clever hack that saved mail.python.org, about 250 hosts were > being rejected at the firewall level). Ouch. -- Grant Edwards grante Yow! Wait... is this a FUN at THING or the END of LIFE in visi.com Petticoat Junction?? From caw at cs.mu.oz.au Thu Aug 7 21:05:34 2003 From: caw at cs.mu.oz.au (Chris Wright) Date: 7 Aug 2003 18:05:34 -0700 Subject: generating byte code from compiler.parse output Message-ID: Is there a way to go from the AST output of compiler.paser to byte code i.e. in the example below, is there a way to compile m and get a code object that could then be called? cheers and thanks for the help chris wright >>> s = """ ... def test(x): ... y = x + 1 ... print x, y ... """ >>> m = compiler.parse(s) >>> m Module(None, Stmt([Function('test', ['x'], [], 0, None, Stmt([Assign([AssName('y', 'OP_ASSIGN')], Add((Name('x'), Const(1)))), Printnl([Name('x'), Name('y')], None)]))])) >>> From essai1 at mci.local Sat Aug 23 02:31:22 2003 From: essai1 at mci.local (News M Claveau /Hamster-P) Date: Sat, 23 Aug 2003 08:31:22 +0200 Subject: Keystroke logger for Windows References: Message-ID: But this, run only with de TK'window, not for all windows. -- Michel Claveau From mpeuser at web.de Thu Aug 14 12:54:30 2003 From: mpeuser at web.de (Michael Peuser) Date: Thu, 14 Aug 2003 18:54:30 +0200 Subject: Converting foreign numeric conventions to US References: Message-ID: schrieb im Newsbeitrag news:mailman.1060868487.25555.python-list at python.org... > I have a number of text fields with different ways of exressing currency. > .....but I was hoping for a cleaner more pythonic (read: > more readable) solution. > > Thanks in advance, > > Loren There certainly is none! And it's not a matter of programming language - it's a matter of AI and maybe neural networks ;-) I think any regex will be fine. You can try doing some more analysis when you have multiple consistent data (i.e. look through a file and try to find out what their "system" could be). This will break however when the data is not generated by a programm but input by a human (with changing attitudes and typos now and than...) Kindly Michael P From gafStopSpamData at ziplink.stopallspam.net Mon Aug 18 16:41:15 2003 From: gafStopSpamData at ziplink.stopallspam.net (Gary Feldman) Date: Mon, 18 Aug 2003 20:41:15 GMT Subject: Idle Help font size Message-ID: I bet folks knew that once I got Idle up, I'd have commets :-) The font size for help is too small for me. I can successfully change the font size in the main window, so that's fine, but it didn't affect the font size for the help. I took a look at the Idle-dev mailing list, but with at least two spam messages a month in the last three months of archives, my reaction is that that's totally unacceptable, so I quickly unsubscribed. Many thanks, Gary From jjl at pobox.com Mon Aug 18 16:47:51 2003 From: jjl at pobox.com (John J. Lee) Date: 18 Aug 2003 21:47:51 +0100 Subject: ClientCookie bug (followup) References: <87fzk4sav2.fsf@pobox.com> <87znibzrnx.fsf@pobox.com> <87oeypdh92.fsf@pobox.com> <87oeyn6pzp.fsf@pobox.com> Message-ID: <878ypqy9oo.fsf@pobox.com> Gary Feldman writes: > On 18 Aug 2003 14:43:06 +0100, jjl at pobox.com (John J. Lee) wrote: > > >Hmm, good idea, but I really don't want to split the documentation up > >-- one page is simpler -- and the example is instructive for people > > Then definitely blockquote it (or indent it some other way), and consider > putting it into a smaller font, or using a grey background, or something > else to indicate that it's a digression. Again, that would be a good idea if it *were* a digression, but it's necessary for understanding what the module gets up to. Without that understanding in the reader's mind, it's hard to explain the code that one uses in practice if it's any more complicated than urlopen. And the very top of the page says: | import ClientCookie | response = ClientCookie.urlopen("http://foo.bar.com/") | |This function behaves identically to urllib2.urlopen, except that it |deals with cookies automatically. That's probably all you need to |know. So you don't even have to read further than that for most purposes. I can't see how to improve on that, but I'm happy to learn how! > Orange would draw attention to > it; you want the opposite. Only the comment is in emacs-orange (well, my copy of python-mode uses that kind of rust-orange for Python comments), so it doesn't particularly draw attention to that block of code more than the rest. And I *do* want to draw attention to the comment, so people read the comment before the code. Admittedly, it doesn't seem to work ;-) (on a sample of one misinterpreter, Mark, so far -- I only just added that comment recently, though there are several other warnings that cover the same ground elsewhere). John From __peter__ at web.de Fri Aug 29 04:26:59 2003 From: __peter__ at web.de (Peter Otten) Date: Fri, 29 Aug 2003 10:26:59 +0200 Subject: how to find out the OO hierachy via the documentation? References: Message-ID: Leo wrote: > newbie question: how do i find out the OO hierarchy of a class in the > python docu? You can use pydoc -p 9999 or on Windows perhaps python c:\path\to\python\pydoc.py -p 9999 on the command line and then access documentation generated on the fly with your preferred browser: http://localhost:9999/SimpleHTTPServer.html Peter From sjmachin at lexicon.net Wed Aug 6 18:29:44 2003 From: sjmachin at lexicon.net (John Machin) Date: 6 Aug 2003 15:29:44 -0700 Subject: round(22.47,2) gives 22.469999999999999? References: <3f30e294$0$125$e4fe514c@dreader5.news.xs4all.nl> Message-ID: Daniel Klein wrote in message news:... > On Wed, 06 Aug 2003 13:12:21 +0200, Eric van Riet Paap > wrote: > >On python2.1.3, python2.2.1 and python2.2.3 round(22.47,2) gives > >22.469999999999999 . Does anyone know if this is a bug or some weird, yet > >unexpected, behaviour? > > Wouldn't > > int(22.47 + .5) > > get you to where you want to go? Sure would, if 22 was where you wanted to go. One trusts that you would be lonely on arrival, though. Perhaps you might then notice a bunch of folks over at 22.47 ... From hwlgw at hotmail.com Mon Aug 25 03:07:19 2003 From: hwlgw at hotmail.com (Will Stuyvesant) Date: 25 Aug 2003 00:07:19 -0700 Subject: ANN: BlackAdder V1.0.0 References: <3f48a498$3$219$fa0fcedb@lovejoy.zen.co.uk> Message-ID: > [BadJake] You usenet posting did look bad to me. It looked like a mess: amateuristic. If you want to sell things, you should make even ascii-based postings look professionally. And don't mention prices in this newsgroup, give a URI. -- A bachelor is an unaltared male. From oinkfreddie at oinkshlick.oinknet Tue Aug 5 00:37:55 2003 From: oinkfreddie at oinkshlick.oinknet (Freddie) Date: 5 Aug 2003 14:37:55 +1000 Subject: yEnc implementation in Python, bit slow References: Message-ID: Freddie wrote in news:Xns93CE8D81747C5freddiethescaryeleph at 218.100.3.9: Arr. There's an error here, the [n+i+256+1] shouldn't have a 1. I always get that wrong :) The posted files actually decode now, and the yEncode() overhead is a lot lower. > encoded = [] > n = 0 > for i in range(0, len(translated), 256): > chunk = translated[n+i:n+i+256] > if chunk[-1] == '=': > chunk += translated[n+i+256] <<< this line > n += 1 > encoded.append(chunk) > encoded.append('\n') -- Remove the oinks! From ramiak2000 at yahoo.com Tue Aug 19 01:57:36 2003 From: ramiak2000 at yahoo.com (Rami A. Kishek) Date: Tue, 19 Aug 2003 01:57:36 -0400 Subject: Serious problem with Shelve References: <3F3FB5B9.5E49B306@yahoo.com> Message-ID: <3F41BC50.91097FAF@yahoo.com> Well - I installed Python 2.3, but it still doesn't. My program now crashes on the first pass. After deleting the old databases and creating new ones, I opened them for read and this is what I get: self.revs = shelve.open(os.path.join(tgtdir, dbfn)) File "D:\PROGRAMS\PYTHON23\lib\shelve.py", line 231, in open return DbfilenameShelf(filename, flag, protocol, writeback, binary) File "D:\PROGRAMS\PYTHON23\lib\shelve.py", line 212, in __init__ Shelf.__init__(self, anydbm.open(filename, flag), protocol, writeback, binary) File "D:\PROGRAMS\PYTHON23\lib\anydbm.py", line 82, in open mod = __import__(result) ImportError: No module named bsddb185 I will try enclosing that import bsddb185 in anydbm.py in try: except:, though I hate messing around with source files, and there may be many more such problems. Python developers, be aware of this glitch. Tim Churches wrote: > > > of code which uses shelve to save instances of some class I define. > > it keeps crashing on reading from the shelved file > > the second time I try to access it. > > In Python 2.2 or earlier, by default, shelve uses the Berkeley database > 1.8 libraries, which we have found to be seriously broken on all > platforms we have tried them on. Upgrading to a later version of the > Berkeley libraries and using the pybsddb module fixed the mysterious, > inconsistent crashes and segfaults we were seeing with shelve (and which > were also driving us crazy). The easiest way to upgrade is to move to > Python 2.3, which includes these later versions, but you can also > easily install them under earlier version of Python (at least under > 2.2). > -- From ma at Bell.com Tue Aug 19 01:15:43 2003 From: ma at Bell.com (xam) Date: Tue, 19 Aug 2003 05:15:43 GMT Subject: a twisted question References: Message-ID: <3oi0b.15187$ev.2983733@twister.nyc.rr.com> ok, 1) thanks 2) status update: I successfully installed 2.2.3 as a parallel install. it is mapped to python2 on my system. How do I induce Twisted to work off of that copy? thanks, max. From usenet_spam at janc.invalid Wed Aug 20 23:39:48 2003 From: usenet_spam at janc.invalid (JanC) Date: Thu, 21 Aug 2003 03:39:48 GMT Subject: What's better about Ruby than Python? References: <3F40892D.AEF4AAE@alcyone.com> <87isov6pk4.fsf@pobox.com> <3F412081.5EF7279C@alcyone.com> <874r0ey9bx.fsf@pobox.com> Message-ID: jjl at pobox.com (John J. Lee) schreef: > Mind you, I am the type who, when faced with a new language, tends to > read everything slowly, chew the cud, *then* start writing. Sounds familiar, you're not the only "sick puppy"... ;-) -- JanC "Be strict when sending and tolerant when receiving." RFC 1958 - Architectural Principles of the Internet - section 3.9 From s0199583 at sms.ed.ac.uk Mon Aug 11 11:40:46 2003 From: s0199583 at sms.ed.ac.uk (Matt Smith) Date: 11 Aug 2003 08:40:46 -0700 Subject: Importerror no module named WIN32API Message-ID: <5f5c82ec.0308110740.550d5f43@posting.google.com> hi all, again.... having another problem with python COMs, I run a python script on a win2000 machine, that uses win32com.client and it runs perfectly, whereas when I come to run it on a win98 machine (the machine that the code, when completed, will be running from in the future) it returns the error: Traceback (most recent call last): File "firsttry.py", line 1, in ? import helloworld File "G:\msmith\python\helloworld.py", line 2, in ? import win32com File "C:\PYTHON23\lib\site-packages\win32com\__init__.py", line 5, in ? import win32api, sys ImportError: No module named win32api Any clues as to how to rectify this problem would be greatly appreciated cheers, matt. From daniel at dittmar.net Mon Aug 18 14:31:28 2003 From: daniel at dittmar.net (Daniel Dittmar) Date: Mon, 18 Aug 2003 20:31:28 +0200 Subject: python threads on multi-CPU machines In-Reply-To: References: <5a4226f0.0308180945.34f96eca@posting.google.com> Message-ID: Aahz wrote: > Cool! When you're done, I'd appreciate it if you could write up a short > summary of the problems you ran into and post it here. I'm interested > in pushing computational threading in Python, but I haven't written > enough C code to have any idea how it differs from other kinds of > threading issues. I've written a C extension to access a database and I came upon the following: A multithreaded application on a 4 CPU machine would keep the database server less busy than the same application written in Java. The behaviour on the Python side got somewhat better when - I kept the GIL while sending the request to the database and - released it only while waiting for the reply. I guess this had something to do with the fact that releasing the GIL triggers a thread switch (at least on Windows) and this introduced a lag until the thread got control again and could actually send the requrest to the database. I wasn't able to test this behaviour with other operating systems, as I hadn't them on multi-CPU machines. Daniel From http Sat Aug 30 12:55:35 2003 From: http (Paul Rubin) Date: 30 Aug 2003 09:55:35 -0700 Subject: Reading and manipulating binary data References: Message-ID: <7xsmnjaxvc.fsf@ruckus.brouhaha.com> "Dave" writes: > Also part of the authentication system involves MD5 hashes. For this I need > to be able to take a string, find its MD5 digest, and then xor it with > another string. But since the MD5 digest is binary, and I don't know how to > change it, I can't xor it... Please, I am sure I am missing something > really obvious but I am stumped as to what it is. Look at the docs for the array module. It may solve a lot of your problems. From gh at ghaering.de Thu Aug 28 03:05:05 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Thu, 28 Aug 2003 09:05:05 +0200 Subject: Tci/basic In-Reply-To: References: Message-ID: <3F4DA9A1.4000306@ghaering.de> Rich wrote: > I am going through one of the tutorials on the Python site, and some > of the things mentioned are Tci and Basic. [...] Which tutorial is this, can you give a link? I suppose it's comparing Python to TCL and BASIC, which are other programming languages and doing this for the benefit of those who already know one of these languages. As you're interested in Python, you can safely ignore these languages :-) -- Gerhard From jordan at krushen.com Mon Aug 25 14:32:35 2003 From: jordan at krushen.com (Jordan Krushen) Date: Mon, 25 Aug 2003 18:32:35 GMT Subject: python gripes survey References: <78kkkvg8ckfio141es2of1p483ohbtbit5@4ax.com> Message-ID: On Mon, 25 Aug 2003 18:14:30 GMT, Afanasiy wrote: > Sure you can return an associative array, but in my experience the > preference is to return a tuple. I'll probably get flamed for saying so, > but this is how I feel and it is unavoidable. Returning a struct in C is > easier to deal with than returning a near-mystery tuple in Python. On one hand, you could always return a dict in your own code. On the other, I find dealing with returned tuples to be as easy as it gets: def f(x, y, z): return(z, y, x) a, b, c = f() print a, b, c # 3 2 1 J. From paddy3118 at netscape.netNOTthisBIT Sun Aug 10 02:25:09 2003 From: paddy3118 at netscape.netNOTthisBIT (Donald 'Paddy' McCarthy) Date: Sun, 10 Aug 2003 07:25:09 +0100 Subject: ANNOUNCE: Rekall V2.0.2 In-Reply-To: References: Message-ID: Neil Hodgson wrote: > John: > >>Why not take a Rekall Demo out for a test drive. Our demos are fully >>functional with a 60 minute time limitation (the Windows demo has a 15 day >>time limit), but they will run again. You can find the demos on either of >>two web sites, http://www.rygannon.com and http://www.totalrekall.co.uk > > > All links from the top level page require registration, even those that > may explain what the product does. > > Neil > > I'll second that. They need to state on the Menu just what is available for the casual browser, or only show what is available to the casual browser until they have registered. From danielk at aracnet.com Thu Aug 14 09:03:17 2003 From: danielk at aracnet.com (Daniel Klein) Date: Thu, 14 Aug 2003 06:03:17 -0700 Subject: unsigned int \ long References: Message-ID: On Wed, 13 Aug 2003 08:40:50 +0300, "Roman Yakovenko" wrote: >Hi. I need to work with integer as unsigned integer, but >I can't find documentation how can I do it. > >Some reference on this will be appreciated. > >For example (unsigned int)(-1) == 0xFFFFFFFF. '%lu' % abs(-1) http://www.python.org/doc/current/lib/typesseq-strings.html Dan From vze4rx4y at verizon.net Fri Aug 15 20:48:31 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Sat, 16 Aug 2003 00:48:31 GMT Subject: Py2.3: Feedback on Sets References: <3v8ljvo5amvbaq5qdd4e8h9lf47q7afhqk@4ax.com> Message-ID: "Gary Feldman" > >* Are the docs clear? Can you suggest improvements? > > I haven't used them yet, but since I'm working my way through > the docs in general, I thought I'd check them out and comment. All of the issues you found have been fixed (except for the discussion of what an iterable parameter means -- that will be addressed elsewhere). Raymond Hettinger From mis6 at pitt.edu Sat Aug 23 03:40:48 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 23 Aug 2003 00:40:48 -0700 Subject: For Kenny Tilton: Why do I need macros revisited. References: <3f45484f$1_6@corp.newsgroups.com> <3F45A7BF.4060806@nyc.rr.com> <8dk1b.2825$Ej6.1159@newsread4.news.pas.earthlink.net> Message-ID: <2259b0e2.0308222340.27e58005@posting.google.com> mertz at gnosis.cx (David Mertz) wrote in message news:... > "Andrew Dalke" wrote previously: > |I've seen David Mertz' xml_pickle code which makes good use of > |[metaclasses], but don't yet follow how it works. > > I'm afraid I must insist here that the use of metaclasses in > gnosis.xml.pickle is utterly trivial, and just for show. You'll > have to look elsewhere for "good use" of them :-). > > Yours, David... For instance Psyco was using metaclasses to wrap the methods to "speed-up", at least when I looked at version 0.4. This was a quite clean usage, simple and effective. When you need to wrap many methods in a class (for instance for logging purposes or other reasons) a metaclass is most probably the best solution you have at your disposal. Michele Simionato, Ph. D. MicheleSimionato at libero.it http://www.phyast.pitt.edu/~micheles --- Currently looking for a job --- From davidcfox at post.harvard.edu Fri Aug 8 08:44:24 2003 From: davidcfox at post.harvard.edu (David C. Fox) Date: Fri, 08 Aug 2003 12:44:24 GMT Subject: ???? i can`t understand it In-Reply-To: References: Message-ID: Enrique wrote: > >>> a=[1,2,3,4,5] > >>> for b in a: > ... a.remove(b) > ... > >>> a > [2, 4] > >>> As others have noted, modifying a sequence can have strange effects on iterators. Presumably, the example above is simplified (since if you really wanted to remove all elements in a, you would just say a = []). If you want to selectively remove elements in a, you should have a look at the built-in function filter. For example, to remove elements < 0: a = [1,5,7, -4, 2, -10] a = filter(lambda x: x >= 0, a) David From bkc at Murkworks.com Tue Aug 19 14:05:42 2003 From: bkc at Murkworks.com (Brad Clements) Date: Tue, 19 Aug 2003 14:05:42 -0400 Subject: Py2exe for 2.3 also copies python22.dll References: Message-ID: Great, I expect that answers my other post about 'can't connect to service controller' as well. are the win32 sources still required to rebuild run_svc? -- Novell DeveloperNet Sysop #5 _ "Thomas Heller" wrote in message news:oeymloja.fsf at python.net... > "Brad Clements" writes: > > > Here's a "screen shot" I'm running > > > > python setup.py -d c:\temp\rose s UMXService > > > > I have python 2.2 installed, and 2.3. 2.3 is the 'default' for .py > > files but it seems that py2exe's setup copies pythonxx.dll from > > system32, rather than picking the specific version that's needed > > > > Due to a bug, the run_svc.exe distributed with py2exe for Python 2.3 > is linked with pywintypes22.dll instead of pywintypes23.dll. > > Rebuilding py2exe from source should help (currently I have no time to > do it myself). > > Thanks, > > Thomas > -- > http://mail.python.org/mailman/listinfo/python-list > From mertz at gnosis.cx Wed Aug 27 13:44:46 2003 From: mertz at gnosis.cx (Lulu of the Lotus-Eaters) Date: Wed, 27 Aug 2003 13:44:46 -0400 Subject: Celebrity advice References: <3F4CD2A2.DE7D05D2@engcorp.com> Message-ID: Terry Reedy wrote: > (I think it safe to say that during the 20th century, 99% of the 100s of > millions of murders were committed by armed govern-men rather than by > private persons acting alone.) Peter Hansen wrote previously: |It may be safe to say it, but is it true, or merely hyperbole? |Were there "100s of millions of murders" in the 20th century The 99% seems like an overstatement. But the 100s of millions does not. "State sponsored" murder was awfully prevalent in the 20th C (and before, and since). A good resource is: http://users.erols.com/mwhite28/warstats.htm It's unlikely that a single one of those listed occurrences would have been substantially different because of local ESR-style gun-nuts in the various places. In fact, in many or most of the places, the murdered populations -were- armed in the way ESR advocates. ESR's "arguments" boil down to: (1) Wow, isn't it fun hearing guns make a loud bang; (2) Oh yeah, be careful not to point them at people by accident; (3) This bunch of invented history kinda-sorta supports my nutsiness, if you squint and don't think about it too hard; (4) Did I mention that I like to hear loud bangs? Yours, Lulu... -- mertz@ _/_/_/_/_/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY:_/_/_/_/ v i gnosis _/_/ Postmodern Enterprises _/_/ s r .cx _/_/ MAKERS OF CHAOS.... _/_/ i u _/_/_/_/_/ LOOK FOR IT IN A NEIGHBORHOOD NEAR YOU_/_/_/_/_/ g s From gerrit at nl.linux.org Thu Aug 28 17:04:54 2003 From: gerrit at nl.linux.org (Gerrit Holl) Date: Thu, 28 Aug 2003 23:04:54 +0200 Subject: OT: Americans love their guns In-Reply-To: References: Message-ID: <20030828210454.GA3736@nl.linux.org> Richard Wesley wrote: > In article , > midnight at warm-summer-night.net (falling star) wrote: > > Lulu of the Lotus-Eaters wrote: > > LotLE> > > LotLE> USA automobile deaths are ^43k/year > > LotLE> USA gun-related deaths are ~29k/year > > > > Where did you get your number? 29k a year??? Don't believe it. I > > would guess the number to be somewhere in the 1000 to 2000 range. > > US murders with firearms were 8,259 in 1999, ranked #4 in the world. There is a difference between 'murders with firearms' and 'gun-related deaths'. Gerrit. -- 112. If any one be on a journey and entrust silver, gold, precious stones, or any movable property to another, and wish to recover it from him; if the latter do not bring all of the property to the appointed place, but appropriate it to his own use, then shall this man, who did not bring the property to hand it over, be convicted, and he shall pay fivefold for all that had been entrusted to him. -- 1780 BC, Hammurabi, Code of Law -- Asperger Syndroom - een persoonlijke benadering: http://people.nl.linux.org/~gerrit/ Het zijn tijden om je zelf met politiek te bemoeien: http://www.sp.nl/ From tjland at iserv.net Thu Aug 21 22:21:44 2003 From: tjland at iserv.net (tjland at iserv.net) Date: Thu, 21 Aug 2003 22:21:44 -0400 (EDT) Subject: What has been going on? In-Reply-To: <1768.68.75.128.246.1061412809.squirrel@webmail.iserv.net> References: <1768.68.75.128.246.1061412809.squirrel@webmail.iserv.net> Message-ID: <1322.68.73.70.2.1061518904.squirrel@webmail.iserv.net> Ignore those last two messages accidently sent. Who else has been getting messages returned that you didnt send. Mail scanners saying their is a virus? The list i think has been infected with the W32/Sobig.f-MM virus, anyone else experiencing problems? Also i havent been able to post to the list its been saying post returned after four hours, or something like that. Thanx for help! > > > > When you see the net take the shot > When you miss your shot shoot again > When you make your shot you win! > > Just remember > Offense sells tickets > But defense wins championships! > > -- > http://mail.python.org/mailman/listinfo/python-list > When you see the net take the shot When you miss your shot shoot again When you make your shot you win! Just remember Offense sells tickets But defense wins championships! From bokr at oz.net Fri Aug 8 14:27:06 2003 From: bokr at oz.net (Bengt Richter) Date: 8 Aug 2003 18:27:06 GMT Subject: crossplatform py2exe - would it be useful? References: <2UyYa.50516$cl3.1586459@news2.tin.it> Message-ID: On Fri, 08 Aug 2003 17:31:35 +0200, Thomas Heller wrote: >Alex Martelli writes: > >> Oren Tirosh wrote: >> ... >>>> > Sounds like a good idea to me, if a sensible name is chosen for the >>>> > "main module" (I propose 'main':-). >>>> >>>> My choice would have been __main__ :-) Is it really the correct way to >>>> 'import __main__' instead of 'running' it? >>> >>> You can't import __main__ - you'll get the one already in sys.modules. >> >> If there's a __main__ in the zip, we could remove (even assuming it's >> already there) the yet-empty sys.modules['__main__']. >> >>> The code for the main script needs to be executed in __main__'s dict. > >Then we name the boot module __boot__ and import this from the zip. >This could then execute the script in the __main__ module's namespace. > >> So, I reiterate an idea I've already expressed: key on the executable >> file's name. If it's at least six characters long and the first six >> characters are (case-insensitive) 'p', 'y', 't', 'h', 'o', 'n' in this >> order, forget the whole thing and proceed like now; in other words, >> use whatever new tricks we insert *if and only if* the executable file's >> name does NOT start with (case-insensitive) 'python'. >> >>> problems on some obscure environments. A possible alternative would be >>> to have a configuration area inside the executable that can be modified >>> by an external program (e.g. py2exe). The program would search for a >>> signature string and modify the section after it. The configuration >>> area can be as simple as a string that overrides the command line >>> arguments. >> >> I suspect "obscure environments" may make it hard for py2exe to find >> the needed signature and get at the 'configuration area' (depending on >> how executable files are stored when seen as stream of bytes). Still, >> such an area would also be useful for other purposes, as you mention >> (e.g., supplying the -O switch "at compile time", and the like). So, >> perhaps, we could simply test the executable's name FIRST, and if the >> name starts with "python" just do nothing, otherwise look at the >> configuration area (string) and so on. > >Sounds much like the way py2exe already works now. It locates the >appended zip-file by searching the exefile from the end, then finds the >beginning of the zipfile, and looks for a magic number there, which is >used to verify that the next n bytes before this position is a C >structure containing the required flags. > >I don't like the idea to scan the executable for a magic signature >without further hints where this should be. > >> On any "obscure environment" >> where the set of tricks doesn't work, one would simply have to avoid >> renaming or copying the python interpreter to weird names, and otherwise >> would be just about as well or badly off as today. > >From reading the McMillan installer sources some time ago, I have the >impression that on some obscure platforms it's not possible to append >the structure and the zipfile to the executable, and on other obscure >platforms (or maybe runtime environments, maybe a cgi executable started >from apache) it may be difficult to the pathname if the exefile. > >But, all in all, it sounds like a plan. Although I have the impression >that it may be difficult to convince the python-dev crowd to include >this in 2.3.1. (Is anyone of them reading this thread?) > PMJI, since I haven't read all the prior thread, but if the point is just to have an executable that self-unpacks and starts, IWT the safest (for platform independence -- not security, see my conclusion later below) approach would be to have a tool that makes a light-weight self-unpacking "exe" wrapper for any/each platform. I think it would be relatively trivial on win32. I think you could do it all in Python once you have a little C boilerplate exe template compiled and a few special locations and segments defined (i.e., .exe's have provision for simple embedded resource entities. In the auto-executing python use, I guess the resources would be the interpreter exe file, zip file(s), and some simple startup-control/config file. For easiest cross platform use, I think I would use the win32 resource space as a single binary resource string of bytes, and define a simple sequential platform-independent packing *within* that, so that we don't get involved with complex structure in the exe template or the corresponding unix or mac etc solutions. I have previously used a binary packing that pre- and -post-fixed 4-byte lengths for each internal packet, with zero length being legal and 0xffffffxx being reserved for special marks. The length *pre*-fix was optional (absence signalled by special mark) so it was easy to write the whole packed segment sequentially without first knowing the sizes. (BTW I used this to append segments stack-like to a file, so I could pop/top the file segment with one physical read for small segments (just read the last 4k of a file and look back in memory to the beginning per the last 4 bytes) (BTW2, ever wonder why a stack file is not used to communicate between programs like pipe files?). Anyway, even though you might not always need 2-way walking, I think it's not much space to allow for it, or better, specify it in the overall header. It can make the file effectively into a doubly linked list of segments with pointers in the form of relative offsets. With this model of a multi-segment container of packets, we just need a header for the whole thing. The first or any packet can be used by application convention for whatever, but there needs to be a header for the whole thing before you can read packets. I.e., that says what the byte ordering and total length is, at a minimum. For that purpose, I've been thinking a unicode utf-8 representation of an rfc2822 header might be cool. The unpacking wrapper exe could understand a simple command line switch to dump that, and we'd have a file-name-independent way of identifying content to any desired detail. And the output could easily be piped to a unicode app that could display chinese or japanese or russian or greek parts of the header, though I think default should be English unless otherwise marked. This could easily be used to specify what python interpreter was contained, and what apps or data. Note that this kind of wrapper could be used just to install simple data files as well. The only thing I don't like about this, and I REALLY REALLY don't like it, is having people be used to executing stuff they might not check the sizes and signatures of. It is really going down the slippery path of MS-ian uber-convenience, and ignoring security IMO. I was getting fairly enthused about the exe, but I think it's really not a good idea. Why not just let the wrapper part I described be a very light weight standalone installer/launcher/header-viewer and keep the packed info resource as a separate file. Note that this separate file would now start with a utf-8 rfc2822 header!! (and if we put Ctrl-z and Ctrl-D at the end of the header, many editors would be able to open the file and just see the header). I have been thinking this kind of header would do a heck of a lot more than magic numbers, but for magic compatibility, maybe some utf-8 character could be found that would make a clean magic prefix and identifier for utf-8 rfc2822. The header could also specify whether the following was as single packet without length-links or had them pre- or post- or both. A prototype (un)wrapper for utf-8-rfc-2822-headed packet files as outlined above would be short work in Python, and UFHwrap.py (UniversalFileHeader wrap/unwrap) could be part of the batteries. A standalone C version of the unwrapper (you wouldn't need a wrapper, since you could unwrap a python version, though I don't think it would be very hard) would also be short work, especially after a python prototype was working. Since the UFH file (extension hint .ufh ;-) is so simple and platform-independent in structure, it should be easy to write uhfunwrap.c for most platforms, and let people download a 50k exe they can trust for repeated use, rather than worry each time that some big exe is going to zap them unless they fuss about signatures etc. Is this PEP-able? Regards, Bengt Richter From nhodgson at bigpond.net.au Fri Aug 1 07:33:01 2003 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Fri, 01 Aug 2003 11:33:01 GMT Subject: Detect PythonWin? References: <3f29fe44.104328@news.muenster.de> Message-ID: Martin Bless > but how can my script know it its running from inside PythonWin? I don't know if it is all that robust but performing 'dir()' from a PythonWin Interactive Window shows an interesting 'pywin' symbol, so: if 'pywin' in dir(): print 'PythonWin' Seems to work. Neil From Scott.Daniels at Acm.Org Fri Aug 15 13:52:44 2003 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 15 Aug 2003 10:52:44 -0700 Subject: cPickle alternative? In-Reply-To: References: Message-ID: <3f3d1dea$1@nntp0.pdx.net> Drochom wrote: > Thanks for help:) > Here is simple example: > frankly speaking it's a graph with 100000 nodes: > STRUCTURE: > [(('k', 5, 0),), (('*', 0, 0),), (('t', 1, 1),), (('o', 2, 0),), (('t', 3, > 0),), (('a', 4, 0), ('o', 2, 0))] Perhaps this matches your spec: from random import randrange import pickle, cPickle, time source = [(chr(randrange(33, 127)), randrange(100000), randrange(i+50)) for i in range(100000)] def timed(module, flag, name='file.tmp'): start = time.time() dest = file(name, 'wb') module.dump(source, dest, flag) dest.close() mid = time.time() dest = file(name, 'rb') result = module.load(dest) dest.close() stop = time.time() assert source == result return mid-start, stop-mid On 2.2: timed(pickle, 0): (7.8, 5.5) timed(pickle, 1): (9.5, 6.2) timed(cPickle, 0): (0.41, 4.9) timed(cPickle, 1): (0.15, .53) On 2.3: timed(pickle, 0): (6.2, 5.3) timed(pickle, 1): (6.6, 5.4) timed(pickle, 2): (6.5, 3.9) timed(cPickle, 0): (6.2, 5.3) timed(pickle, 1): (.88, .69) timed(pickle, 2): (.80, .67) (Not tightly controlled -- I'd gues 1.5 digits) -Scott David Daniels Scott.Daniels at Acm.Org From john_taylor_1973 at yahoo.com Sun Aug 17 21:59:26 2003 From: john_taylor_1973 at yahoo.com (John Taylor) Date: 17 Aug 2003 18:59:26 -0700 Subject: ANN: PyQt v3.8 Released References: Message-ID: Phil, Does PyQT support the ability to minimize an app to the lower right tray, next to the clock? If so, could you please post some example code? Thanks, John Phil Thompson wrote in message news:... > PyQt v3.8 has been released and can be downloaded from > http://www.riverbankcomputing.co.uk/pyqt/ > > Highlights of this release include the addition of many operators to existing > classes and full support for Qt v3.2.0. > > PyQt is a comprehensive set of Python bindings for Trolltech's Qt GUI toolkit. > It includes approximately 300 classes and 5,750 methods including OpenGL, SQL > and XML support as well as a rich set of GUI widgets. It also includes a > utility to generate Python code from Qt Designer, Qt's GUI builder. > > PyQt runs on UNIX/Linux, Windows and the Sharp Zaurus. > > PyQt is licensed under the GPL, commercial, educational and non-commercial > licenses. > > Phil From decoret at graphics.lcs.mit.edu Fri Aug 15 15:32:26 2003 From: decoret at graphics.lcs.mit.edu (Xavier Decoret) Date: Fri, 15 Aug 2003 15:32:26 -0400 Subject: recursive traversal of file Message-ID: I am reading the lines of a file, executing appropriate command if a pattern is found. One of the pattern can be a input command whose effect should be to #include the file (possibly recursively) The main loop looks like this: data=[] try: file = open(fileName) line = file.readline() while line: if matchInputPattern(line,inputFile): # help me here to parse inputFile elif matchDataPattern(line): data.append(1) line = file.readline() except IOError, e: print 'I couldn\'t open file name',fileName sys.exit(1) Can you tell me if there is a simple way to do the part that says #help me!. Should I do a recursive function? -- +-------------------------------------------------+ | Xavier D?coret - Post Doct | | Graphics Lab (LCS) - MIT | | mailto: decoret at graphics.lcs.mit.edu | | home : http://www.graphics.lcs.mit.edu/~decoret| +-------------------------------------------------+ From __peter__ at web.de Thu Aug 28 02:41:45 2003 From: __peter__ at web.de (Peter Otten) Date: Thu, 28 Aug 2003 08:41:45 +0200 Subject: Script Discussion & Critique References: <3F4D31B1.6080802@hotmail.com> <06eqkv4onjh5m4tcbbqkmh8lscaj5niatp@4ax.com> <3F4D4402.3060209@hotmail.com> <3f4d9f2c$0$16163$626a54ce@news.free.fr> Message-ID: Bruno Desthuilliers wrote: > Err... Is this my version of Python having troubles, or could it be > possible that nobody actually took time to *test* that script ? Python 2.3 (#1, Jul 30 2003, 11:19:43) [GCC 3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> dir(os.walk) ['__call__', '__class__', '__delattr__', '__dict__', '__doc__', '__get__', '__getattribute__', '__hash__', '__init__', '__module__', '__name__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', 'func_closure', 'func_code', 'func_defaults', 'func_dict', 'func_doc', 'func_globals', 'func_name'] >>> It's time to upgrade :-) Peter From thomasacross at hotmail.com Fri Aug 15 17:25:57 2003 From: thomasacross at hotmail.com (Tom Cross) Date: 15 Aug 2003 14:25:57 -0700 Subject: Replace every n instances of a string Message-ID: <62de87da.0308151325.41ea4622@posting.google.com> Hello- I have a function that returns to me a text representation of Unicode data, which looks like this: \u0013\u0021\u003c\u003f\u0044\u001f\u006a\u005a\u0050\u0015\u0018\u001d\u007e\u006b\u004e\u007d\u006a\u006e\u0068\u0042\u0026\u003c\u004f\u0059\u0056\u002b\u001a\u0077\u0065\u006a\u000a\u0021\u005f\u0025\u003f\u0025\u0024\u007e\u0020\u0011\u0060\u002c\u0037\u0067\u007a\u0074\u0074\u0003\u0003\u000f\u0039\u0018\u0059\u0038\u0029\u0001\u0073\u0034\u0009\u0069\u005e\u0003\u006e\u000d\u004c\u001d\u00 f\u006e\u001b\u006e\u0063\u000b\u0014\u0071\u007c\u004e\u006a\u0011\u004a\u001f\u0063\u0016\u003d\u0020\u0065\u003e\u0043\u0012\u0047\u0026\u0062\u0004\u0025\u003b\u0005\u004c\u002e\u005a\u0070\u0048 I would like to add carriage returns to this for usability. But I don't want to add a return after each "\u" I encounter in the text (regexp comes to mind if I did). I want to add a return after each 12 "\\u"s I encounter in the string. Any ideas? Do I not want to search for "\\u" but instead just insert a \n after each 72 characters (equivalent to 12 \uXXXX codes)? Would this provide better performance? If so, what would be the easiest way to do that? Thanks much! From jimmy at retzlaff.com Tue Aug 12 23:34:17 2003 From: jimmy at retzlaff.com (Jimmy Retzlaff) Date: Tue, 12 Aug 2003 20:34:17 -0700 Subject: The importance of using Library Functions Message-ID: Doug Tolton (dtolton at yahoo.com) wrote: [a painful sounding story about writing the equivalent of textwrap.py under the pressure of a deadline only to discover someone else had already done it. He offered one remedy:] >As much as I hate to be the example, it really is a wonderful >illustratration of why following the Unix / OSS development model is a >better way to go. > >1. Check to see if someone has already written an app to do what you >want done. >2. Check to see if someone has written something that is close to what >you want done. If you can get the source code, modify it to do what >you need specifically. >3. Write it from scratch. Something that serves me well is to occasionally (maybe once or twice a year) take 30 minutes or so to browse the entire library documentation just to rebuild the index in my head. I also thoroughly read AMK's "What's New" document (e.g., http://www.python.org/doc/2.3/whatsnew/) whenever a new version of Python is released. Keeping up with the next version can also point out interesting things in development that are often easy to back-port for use before the next version is released (http://www.python.org/dev/doc/devel/whatsnew/ - it's a little sparse right now seeing as 2.3 was just released). Jimmy From elainejackson7355 at home.com Thu Aug 28 21:52:55 2003 From: elainejackson7355 at home.com (Elaine Jackson) Date: Fri, 29 Aug 2003 01:52:55 GMT Subject: another puzzled newbie References: <68g3b.855589$ro6.16997110@news2.calgary.shaw.ca> Message-ID: "Chad Netzer" wrote in message news:mailman.1062051053.30902.python-list at python.org... | > def singlePass(shuffler,preshuffled,postshuffled): | > postshuffled+=[preshuffled[shuffler[0]] | ^ | You forgot a ']' at the end of the line Right. How embarassing. Thank you. | You don't need the '(' and ')' here. del is a keyword, not a function. Can't it be both? Could you explain why it fails to be a function? | > for i in range(len(shuffler)): | > shuffler[i]+=(-1) | ^^^^ | If you want a tuple here, it should be (-1,). It needs the comma. | But, since shuffler is a list, you probably really want [-1]. No, I want (-1) the integer. My problem is that I really dislike the appearance of a statement like X-=Y. (Even right now I can barely stand writing it.) So I wrote X+=(-Y) instead. Maybe it would look better as shuffler=map(lambda n: n-1, shuffler)? Thanks again, and muchas gracias to the other respondents as well. Peace, EJ From bgailer at alum.rpi.edu Thu Aug 14 14:28:59 2003 From: bgailer at alum.rpi.edu (Bob Gailer) Date: Thu, 14 Aug 2003 12:28:59 -0600 Subject: PythonWin hangs when Shift-F5 (stop debug) In-Reply-To: Message-ID: <5.2.1.1.0.20030814122814.02717270@66.28.54.253> At 10:49 AM 8/14/2003 -0700, ywsat wrote: >Has anyone experienced the problem where PythonWin debugger hangs you >stop the debug session? > >I'm running Windows 2000. Python 2.3. > >I have to kill it through the task manager each time. I've had other conditions that required an End Task, but not what you're describing. Bob Gailer bgailer at alum.rpi.edu 303 442 2625 -------------- next part -------------- --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.506 / Virus Database: 303 - Release Date: 8/1/2003 From dyoo at hkn.eecs.berkeley.edu Sun Aug 24 18:57:39 2003 From: dyoo at hkn.eecs.berkeley.edu (Daniel Yoo) Date: Sun, 24 Aug 2003 22:57:39 +0000 (UTC) Subject: OT: Ocaml? References: <7xk795xde6.fsf_-_@ruckus.brouhaha.com> <87lltkuluy.fsf@gmx.net> <7xwud41322.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: : Arne Koewing writes: :> > Anyone here use OCAML? How do you like it? Is it a language a :> > Pythonista can learn to love? From what little I've seen, it looks :> > interesting, but I haven't actually tried installing or using it yet. :> Yes and I think it's a great language, but it's a little bit harder :> to start learning it. (you must learn how to read the types). :> But you get a very 'save' language with a very efficient compiler. : Do you find that the strict type system gets in your way like it does : in Java? Actually, not at all! Mark Jason Dominus has written a very nice page talking about type systems, and in particular, gushes about the ML/Ocaml approach. He shows how the ML type system just gets out of the way: http://perl.plover.com/yak/typing/ Very good reading. *grin* Hope this helps! From mis6 at pitt.edu Sat Aug 23 05:18:10 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 23 Aug 2003 02:18:10 -0700 Subject: What's better about Ruby than Python? References: <4o_0b.1665$Ej6.1182@newsread4.news.pas.earthlink.net> <8D01b.1721$Ej6.702@newsread4.news.pas.earthlink.net> <3F44ED2E.9070308@nyc.rr.com> <0V61b.1900$Ej6.1012@newsread4.news.pas.earthlink.net> <3F4504D7.20008@nyc.rr.com> Message-ID: <2259b0e2.0308230118.67a676e7@posting.google.com> "Andrew Dalke" wrote in message news:... > For observational evidence of this, I suggest my own > subfields, computational biology and computational chemisty. > In the first there are bioperl, biopython, biojava, and bioruby, > all with active participants and a yearly confererence organized > by open-bio.org. But there is only a rudimentary biolisp project > with minimal code available and just about no community > involvement. In the latter, Python takes the lead by far over > any language other than C/C++/Fortran with commercial support > for a couple toolkits and several more free ones beyond that. > There's even a workshop in a couple weeks on the representation > of biomolecules for Python. There are also some Java and C++ > toolkits for chemical informatics. And again, there is no Lisp > involvement. > > I ask you why. And I assert that it's because Lisp as a > language does not encourage the sort of code sharing that > the languages I mentioned above do. So while it is very > expressive for a single person, a single person can only > do so much. > > Andrew > dalke at dalkescientific.com I would say simply that Lisp has a much steeper curve than Python & comparable languages. Scientists want to do science, not CS. Moreover, they typically don't have very hard programming problems (I mean conceptually, not numerically). So, a scripting language is much better for somebody who is simply a CS amateur, with a different field of research. On the other hand, a CS academics would probably prefer Lisp/Scheme over a scripting language, at least I think. That said, I do agree that the presence of hundreds of dialects works against the adoption of Lisp. For instance, this stopped me (together with other factors). Michele Simionato, Ph. D. MicheleSimionato at libero.it http://www.phyast.pitt.edu/~micheles --- Currently looking for a job --- From Inyeol_lee at yahoo.com Wed Aug 13 11:52:40 2003 From: Inyeol_lee at yahoo.com (Inyeol Lee) Date: 13 Aug 2003 08:52:40 -0700 Subject: Changing UNIX primary group References: Message-ID: "Justin Johnson" wrote in message news:... > I have a unix id that has group1 for a primary group, and group2, group3, > and group4 for supplementary groups. I'd like to change my primary group > before running certain commands. So sometimes I might want group2 to be > the primary group, and other times group3 or group4. > > I saw the posix module's setgid method, but it failed for me unless I was > running as root. Also it only accepts the gid, but I'd rather pass in > the group name, or somehow lookup the gid based on the name. > > Does anyone know a way to do all of this? > Thanks much. > -Justin These are not python solution; 1) make a setgid script and put your commands there, or 2) use shell commands; echo "command1; command2;" | newgrp group2 -Inyeol From mal at lemburg.com Wed Aug 6 03:49:08 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Wed, 06 Aug 2003 09:49:08 +0200 Subject: MSVC 6.0 Unsupported? In-Reply-To: <3F302764.8010301@ghaering.de> References: <3F302764.8010301@ghaering.de> Message-ID: <3F30B2F4.9060409@lemburg.com> Gerhard H?ring wrote: > Syver Enstad wrote: > >> I've downloaded both source distro, and binary installer. Installed >> python with the binary installer, when I attempted to compile >> mxDateTime (mxBase) for 2.3 with MSVC 6.0 I got an error that seemed >> related to forward declarations. >> >> It seems that the #defines that makes staticforward into extern when >> using the MSVC 6 compiler has been removed from object.h. So I guess >> this means I should use VC++ 7.0 to compile python with? > > Huh? You couldn't be more wrong. > > 1) Python 2.3 binaries *are* built with MSVC6 > > 2) staticforward was defined from exten to empty on win32 for Python 2.3 ... and that's the problem: MS VC6 doesn't work with static forwards. Previous Python versions therefore defined a macro called BAD_STATIC_FORWARD which triggered a work-around in Python. That work-around was removed in Python 2.3 for some reason I don't understand (and I just stumbled over it when I tried to compile egenix-mx-base against Python 2.3 on Windows -- we do regular builds against the Python 2.3 on Linux and gcc does not botch the static forwards, so we didn't see the problem before the Python 2.3 release). > 3) The quick hack I used is to insert something like: > > #ifdef _MSC_VER > #define staticforward extern > #endif > > in the relevant source files *after* they include Python.h. The best thing to do is to replace this code in Python's object.h file (Python23\Include\object.h; note the comment !): /* Define staticforward and statichere for source compatibility with old C extensions. The staticforward define was needed to support certain broken C compilers (notably SCO ODT 3.0, perhaps early AIX as well) botched the static keyword when it was used with a forward declaration of a static initialized structure. Standard C allows the forward declaration with static, and we've decided to stop catering to broken C compilers. (In fact, we expect that the compilers are all fixed eight years later.) */ #define staticforward static #define statichere static with this snippet (the previously used one): /* A common programming style in Python requires the forward declaration of static, initialized structures, e.g. for a type object that is used by the functions whose address must be used in the initializer. Some compilers (notably SCO ODT 3.0, I seem to remember early AIX as well) botch this if you use the static keyword for both declarations (they allocate two objects, and use the first, uninitialized one until the second declaration is encountered). Therefore, the forward declaration should use the 'forwardstatic' keyword. This expands to static on most systems, but to extern on a few. The actual storage and name will still be static because the second declaration is static, so no linker visible symbols will be generated. (Standard C compilers take offense to the extern forward declaration of a static object, so I can't just put extern in all cases. :-( ) */ #ifdef BAD_STATIC_FORWARD #define staticforward extern #define statichere static #else /* !BAD_STATIC_FORWARD */ #define staticforward static #define statichere static #endif /* !BAD_STATIC_FORWARD */ > Anyway you can't compile the eGenix extensions with Python 2.3. I hoped > this gets fixed soon. The compile fails somewhere in the mxTextTools > stuff. All I needed was mxDateTime and I got that to compile. > > If you need Windoze binaries, I've uploaded some for the pyPgSQL project > at http://sourceforge.net/project/showfiles.php?group_id=16528 > > pypgsql-experimental > > Python 2.3b2 2003-07-17 11:22 > egenix-mx-base-2.0.4.win32-py2.3.exe 471273 6 i386 > .exe (32-bit Windows) FYI, we'll release fixed versions later this week. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 06 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From max at alcyone.com Mon Aug 11 14:43:58 2003 From: max at alcyone.com (Erik Max Francis) Date: Mon, 11 Aug 2003 11:43:58 -0700 Subject: Fun with numbers - dammit, but I want a cast! References: <3f378fac$0$10778$afc38c87@auth.uk.news.easynet.net> <3f3792f2$0$18258$afc38c87@auth.uk.news.easynet.net> <3F37DC90.B9FA25BF@alcyone.com> Message-ID: <3F37E3EE.822A68C3@alcyone.com> Erik Max Francis wrote: > It's a function call, not a conversion. Oops, that was supposed to be, "It's a functional call, not a cast." -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ Nobody can reach me, nobody can touch me; it's a wonderful feeling. \__/ Aaliyah From mertz at gnosis.cx Sun Aug 3 02:38:27 2003 From: mertz at gnosis.cx (Lulu of the Lotus-Eaters) Date: Sun, 03 Aug 2003 02:38:27 -0400 Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> <840592e1.0307312304.77a0a05f@posting.google.com> <7h3brv9a9oz.fsf@pc150.maths.bris.ac.uk> Message-ID: "Daniel Dittmar" wrote previously: |But a lot of Python code depends on reference counting or more exactly it |depends on the timely call of the destructor. So even if a much better GC is |added to Python, reference counting would perhaps be kept for backwards |compatibility (see Python's biggest compromises) Did this thread get caught in a time warp, and posts from two years ago get posted again. Exactly this all happened years ago. -- mertz@ | The specter of free information is haunting the `Net! All the gnosis | powers of IP- and crypto-tyranny have entered into an unholy .cx | alliance...ideas have nothing to lose but their chains. Unite | against "intellectual property" and anti-privacy regimes! ------------------------------------------------------------------------- From ivomirb at hotmail.com Sun Aug 10 14:58:33 2003 From: ivomirb at hotmail.com (Ivo) Date: Sun, 10 Aug 2003 18:58:33 GMT Subject: override I/O and memory management Message-ID: Hi. I'm trying to embed Python as a scripting language for my Win32 application. What I need is to provide my own text console and my own memory manager. Is it possible to do that without replacing all printfs and mallocs in the Python source? Even if I do that, how is that going to work for third-party modules I import? Thanks Ivo From hanzspam at yahoo.com.au Sun Aug 17 11:39:13 2003 From: hanzspam at yahoo.com.au (=?ISO-8859-1?Q?Hannu_Kankaanp=E4=E4?=) Date: 17 Aug 2003 08:39:13 -0700 Subject: Jython and J2ME References: <25373bfe.0308161733.2fd5bb64@posting.google.com> Message-ID: <840592e1.0308170739.1de04d6d@posting.google.com> clay at shirky.com (Clay Shirky) wrote in message news:<25373bfe.0308161733.2fd5bb64 at posting.google.com>... > Can Jython be used to write applications to run in J2ME environments? > I ask because Python seems an ideal language for teaching students to > write applications for the phone or other mobile devices. > > If this is possible, I would be grateful for any pointers to a > Jython/J2ME reference. Short answer: No. Size is an issue, because the current mobile devices can only handle very small applications, like 32 kB or 64 kB JAR size. You couldn't even fit the Jython interpreter in that space, since it's over 900 kB. I don't know about Jython's memory usage, but I'm certain it would also become an issue. Jython's speed is also a problem. Mobile devices are very slow, so adding another layer of abstraction with Jython would make the J2ME applications way too slow to be useful in practice. Java is not that hard a language to teach or understand. It's just cumbersome to write :P From john at rygannon.com Sun Aug 24 06:36:08 2003 From: john at rygannon.com (BadJake) Date: Sun, 24 Aug 2003 10:36:08 GMT Subject: Hosting service with Python support Message-ID: <3f489493$0$200$fa0fcedb@lovejoy.zen.co.uk> Hi I have just found out the my hosting service includes Python support. Unfortunately, they make no mention of this on their web site. There are too few hosting companies that offer Python support so I would like to share this one with you. You can find out by pointing your brower at http://www.krellen.com For $14.95 per month you get the following:- 1. 1 Gb Disk Space 2. 10Gb monthly transfer 3. 10 domains 4. Unlimited number of e-mail accounts 5. Unlimited number of FTP accounts 6. Unlimited number of Domain Pointers 7. Unlimited number of sub-domains 8. Private cgi-bin 9. Web Mail 10. Unlimited number of MySQL databases There are cheaper options available starting at $4.95 per month go up to $50 per month for resellers plans EMail support is excellent and you can even get to speak to a human by phone. The only time they went off-line was when they up graded their servers to Red Hat V9.0 and then we were notified Regards BadJake From mnations at airmail.net Wed Aug 27 19:19:28 2003 From: mnations at airmail.net (Marc) Date: 27 Aug 2003 16:19:28 -0700 Subject: How to force a Pmw ComboBox to update list Message-ID: <4378fa6f.0308271519.41095800@posting.google.com> Hi all, I have an application that uses a Pmw ComboBox to display a list that is dynamic. The user has the ability to add and delete items from the list at different points in the program. However, once the list is updated it needs to automatically refresh the ComboBox to reflect the updated list. The only way I have been able to solve the problem so far is to redraw the window (by withdrawing the window and calling the function that creates the window again). I tried to do a 'configure' on the ComboBox, but couldn't get it to work because the list itself was an initialization even. However, I could have been doing that wrong. Is there any way to force the ComboBox to update the list or redraw itself with the new list? Thanks ahead of time, Marc From danbmil99 at yahoo.com Sun Aug 10 02:17:42 2003 From: danbmil99 at yahoo.com (dan) Date: 9 Aug 2003 23:17:42 -0700 Subject: random changes References: Message-ID: "Raymond Hettinger" wrote in message news:... > So, to get your old results with Py2.3, try something like: > > import random > rng = random.WichmannHill() > rng.whseed(12345) > for i in range(6): > print rng.randint(1, 10) > that worked, thanks From vanevery at 3DProgrammer.com Sun Aug 17 06:59:22 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Sun, 17 Aug 2003 03:59:22 -0700 Subject: simple text parser? References: Message-ID: Michael Peuser wrote: > This is a little bit confusing. > (1) Do you want to dump "internal" data? Of course you cannnot expect > those data to be portabel between Python and C#!!! I don't want portability between Python and C#. They are completely separate projects. > (2) Do you have your data already converted to some standard ASCII > format? Then just write it into a textfile! No it is not already converted. I have to decide on formatting for my own custom data. > (3) Do you have a very special structure in mind to be serialized > (i.e. list of string - integer tuples; an "array of structs of a row > of char and an int" as you would say in C ;-))? Then you probably > should store it in XML. Lots of tools with Python, probably as many > in C# XML looks like peanut butter in the mouth. Too much complexity, inappropriate. The game data is fairly simple but not completely trivial. I asked about XML in another newsgroup. People said that might be wise if *others* need to *read* my data, but they don't. I just need a save file format. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From ayc8NOSPAM at cornell.edu Fri Aug 1 03:57:29 2003 From: ayc8NOSPAM at cornell.edu (Andy C) Date: Fri, 01 Aug 2003 07:57:29 GMT Subject: anti-aliased 2D vector graphics Message-ID: Where can I get a python package to draw such figures? I googled and found PyX, I guess it outputs PostScript. I guess I can get a PostScript to BMP converter or something. Is there any other alternative? I have looked at PIL, but it doesn't seem to support drawing anti-aliased figures. Thanks for any suggestions. Andy From s.dewar at wakcoll.ac.uk Wed Aug 6 03:58:34 2003 From: s.dewar at wakcoll.ac.uk (Scott Dewar) Date: Wed, 6 Aug 2003 08:58:34 +0100 Subject: unsubscribe Message-ID: <3BB1EA54E4DD7B49AC9A96E2996A7A166CC00F@SRV501.wakecoll.net> Could you please remove my name from the mail list? Thank you Scott A. Dewar Lecturer ICT Wakefield College Margaret Street Wakefield WF1 2DH -------------- next part -------------- An HTML attachment was scrubbed... URL: From jepler at unpythonic.net Wed Aug 20 12:39:36 2003 From: jepler at unpythonic.net (Jeff Epler) Date: Wed, 20 Aug 2003 11:39:36 -0500 Subject: python quickie : retrace function steps? In-Reply-To: <5f5c82ec.0308200820.51c8e33c@posting.google.com> References: <5f5c82ec.0308200820.51c8e33c@posting.google.com> Message-ID: <20030820163935.GB19351@unpythonic.net> On Wed, Aug 20, 2003 at 09:20:29AM -0700, Matt Smith wrote: > In perl there is a function called CALLER, which I have used to the > same effect, i was wondering if python had something similar for this? Python has sys._getframe, and various frame-oriented functions in the inspect module that build on sys._getframe. $ cat /tmp/smith.py from __future__ import generators import inspect try: enumerate except NameError: def enumerate(l): idx = 0 for item in l: yield idx, item idx += 1 def f(): g() def g(): h() def h(): print_callers() def print_callers(): for record in inspect.getouterframes(inspect.currentframe(1), 2): print "%s() at %s:%d" % (record[3], record[1], record[2]) for idx, line in enumerate(record[4]): print "%03d: %s" % ( idx + record[2] - 1, line.strip("\n")) print # Let's show something interesting f() $ python /tmp/smith.py h() at /tmp/smith.py:18 017: def h(): 018: print_callers() g() at /tmp/smith.py:15 014: 015: def g(): h() f() at /tmp/smith.py:13 012: 013: def f(): g() ?() at /tmp/smith.py:28 027: # Let's show something interesting 028: f() Jeff From brian at sweetapp.com Sat Aug 9 22:30:45 2003 From: brian at sweetapp.com (Brian Quinlan) Date: Sat, 09 Aug 2003 19:30:45 -0700 Subject: Python vs. C# In-Reply-To: <3f357a9b@shknews01> Message-ID: <000001c35ee7$679a5610$21795418@dell1700> > So again my question is, language-wise, what can I get done with Python > that I can't get done with C#? Nothing, as both are Turing complete. > What is easy to express in Python, that is tedious, difficult, or > impossible to express in C#? 1. the .NET class library is fairly robust but a lot of powerful types aren't available as literals in C# (or there literals have usage restrictions e.g. array literals are only available during variable initialization) 2. the entire reflection API in .NET is painful to use and mainly provides features that are automatic in Python 3. C# forces you to do a lot of type casting (for some reason it doesn't even allow covariant return types) 4. forcing everything into a class is stupid e.g. does anyone really like writing Math.sin(x) over sin(x)? Sorry, no time for more; dinner time. Cheers, Brian From wiebke.paetzold at mplusr.de Mon Aug 4 06:30:11 2003 From: wiebke.paetzold at mplusr.de (Wiebke Pätzold) Date: Mon, 04 Aug 2003 12:30:11 +0200 Subject: Classes in Python Message-ID: <14dsivkn40c0grotsti39cgsrde7v03hq4@4ax.com> Hi all! Could somebody help me with a task? import sys import Mk4py import re db = Mk4py.storage("c:\\datafile.mk",1) vw = db.view("people") class PatternFilter: def _init_(self, pattern): self.pattern = re.compile(pattern) def _call_(self, row): try: nachname = row.Nachname except AttributeError: return 0 return self.pattern.search(nachname)is not None vf = vw.filter(PatternFilter("Ge.*")) for r in vf: print vw[r.index].Nachname I wrote this program, but it returns nothing. I can't find the error. Can somebody help me? Can somebody tell me why the part: "class PatternFilter:" doesn't return the expressions it should return? Wiebke From aleax at aleax.it Tue Aug 5 14:47:44 2003 From: aleax at aleax.it (Alex Martelli) Date: Tue, 05 Aug 2003 18:47:44 GMT Subject: Needs programming tip using date References: Message-ID: Raaijmakers, Vincent (IndSys, GE Interlogix) wrote: > I think this is a bit of a newbie question in the dates area. > > So before I end up in very ugly coding, > What is THE/recommended way in checking if a date formatted as > "08/05/2003", so "month/day/year" is the date of today or a date of the > current week? If you don't want to install 3rd party extensions, such as the excellent mxDateTime that's already been suggested to you, you can also do it with tools from Python's own standard libraries (in the current release, Python 2.3). Considering a week as going from a Sunday (included) to the following Saturday (included), i.e., with Sunday as the first day of the week: import time, datetime def dateof(datestring): daytuple = time.strptime(datestring, '%m/%d/%y')[:3] return datetime.date(*daytuple) offset = 0 def weekof(date): return (offset+date.toordinal()) // 7 this_week = weekof(date.today()) and now you can just test if this_week==weekof(whatever). If you want to account for weeks differently (e.g. starting from Monday) just set offset appropriately (e.g to -1). Alex From aleaxit at yahoo.com Tue Aug 19 07:23:10 2003 From: aleaxit at yahoo.com (Alex Martelli) Date: Tue, 19 Aug 2003 13:23:10 +0200 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: <3F41208F.40021A68@engcorp.com> Message-ID: Andrew Dalke wrote: ... > than many consider. Though I know I can't recall needed a > singleton for my code. Maybe I have a different code style? > I've noticed a tendency of mine towards functional programming... Good program designers rarely NEED singletons -- even when they tend towards object-oriented rather than functional programming. Kent Beck's superb "Test-Driven Development by example" book (Addison-Wesley, highly recommended to everybody!) has this to say on the subject, as part of an excellent though brief survey of useful design patterns: """ Singleton How do you provide global variables in languages without global variables? Don't. Your program will thank you for taking the time to think about design instead. """ This is ALL that Kent's book says on the subject -- and, really, it SHOULD be all that NEEDS to be said. The concept of a language that ENCOURAGES you to disregard Kent Beck's advice, and use Singleton instead of "taking the time to think about design", is truly appalling. Alex From tzot at sil-tec.gr Tue Aug 26 14:13:55 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Tue, 26 Aug 2003 21:13:55 +0300 Subject: Boa Constructor project of the month on SF [nt] Message-ID: From mpeuser at web.de Sat Aug 16 01:39:02 2003 From: mpeuser at web.de (Michael Peuser) Date: Sat, 16 Aug 2003 07:39:02 +0200 Subject: how does the main module notice when I change a module References: <3f443b52.0308151255.50c58885@posting.google.com> <3f3d4cca$0$49103$e4fe514c@news.xs4all.nl> Message-ID: "John Roth" schrieb im Newsbeitrag news:vjqv5v78ptob98 at news.supernews.com... [..]> > I've heard rumblings that the latest version of Idle (the one shipped > with 2.3) runs your tests in a separate process so this problem doesn't > happen. However, I haven't installed 2.3 yet to check it out. It might > be time to check out Idle if it does indeed create a new process for > each test. > > John Roth > There is generally no need to install Python 2.3 for another IDLE. I could use the IDLE 1.0 coming with with 2.3 under 2.3 - though I am not quite content with it.... There is a IDLEfork Project http://idlefork.sourceforge.net/ where all the new IDLEs come from... My favourit is IDLE 0.81 which is shipped with VPYTHON, but you probably can find it the archives. Under Windows 2000 it (0.81) does not come up the first time when opening it from Windows (Edit with....), Newer versions 0.9, 1.0 do, but they as well open a command line window every time. This not only pollutes the desktop but sometimes hangs up the communication. After a while you will find youself with 10 or more interpreters in the background and you have to kill them with the task manager..... The mechanism they use is internal TCP/IP communication. This as I mentioned can hang up. You than need not restart WIndows but just clean up all the Pythons lurking in the background... Kindly Michael P From adalke at mindspring.com Sun Aug 3 14:44:59 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Sun, 3 Aug 2003 12:44:59 -0600 Subject: Match beginning of two strings References: <3f2c429e@nntp0.pdx.net> <3f2c7806.20532894@news.lexicon.net> <6qpuv-q4m.ln1@grendel.myth> Message-ID: Jim Richardson: > Why bother finding out which one is the shorter? if you try the compare, > and you run out of the other to compare to, then by default, it's not > the same :) Because I wasn't sure if the strings had embedded NULs in them. Python strings allow those. Otherwise something like this would work char *s1, *s2 = ... the strings from Python char *s = s1; while ( *s1 && (*s1++ == *s2++)) ; return the string from s->s1, or just the size s1-s. Andrew dalke at dalkescientific.com From tzot at sil-tec.gr Sat Aug 30 08:27:08 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Sat, 30 Aug 2003 15:27:08 +0300 Subject: How to transform decimal to base64 References: Message-ID: On Sat, 30 Aug 2003 19:41:23 +0800, rumours say that "He Qiang" might have written: >base64 module only provide interface for string to base64, I want to know >how to transform decimal digit to base64. >For example, 1 -> base64, not "1". chr(1).encode("base64") If you have many bytes to convert, you can use an array.array('B') and, when you have built the array, then use its .tostring() method. -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From max at alcyone.com Fri Aug 1 19:56:17 2003 From: max at alcyone.com (Erik Max Francis) Date: Fri, 01 Aug 2003 16:56:17 -0700 Subject: How do I combine instance+string for variable References: <4378fa6f.0308011305.183c291a@posting.google.com> Message-ID: <3F2AFE21.A558CC6C@alcyone.com> Marc wrote: > I have several instances of telnet connections that I label > conn2,conn3, etc. Later when I want to scroll through all of these I > wanted to do something like this: > > for int in range(2, 9): > use... conn+str(int) {I'm passing it into another > function} > > I can't get it to work. I've tried using setattr and eval, but nothing > seems to work. Can I get a little help. You probably meant connection = eval('conn' + str(connectionNumber)) although in something like this, it seems like a dictionary, with the keys being integers, would be a far better solution. Then you'd simply write: connections[connectionNumber] -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ To understand is to forgive, even oneself. \__/ Alexander Chase From knight at baldmt.com Thu Aug 14 16:51:32 2003 From: knight at baldmt.com (Steven Knight) Date: Thu, 14 Aug 2003 15:51:32 -0500 (CDT) Subject: ANNOUNCE: SCons beta 0.91 adds Qt and SWIG support Message-ID: SCons is a software construction tool (build tool, or make tool) written in Python. It is based on the design which won the Software Carpentry build tool competition in August 2000. Beta version 0.91 of SCons has been released and is available for download from the SCons web site: http://www.scons.org/ Or through the download link at the SCons project page at SourceForge: http://sourceforge.net/projects/scons/ RPM and Debian packages and a Win32 installer are all available, in addition to the traditional .tar.gz and .zip files. WHAT'S NEW IN THIS RELEASE? IMPORTANT: Release 0.91 contains the following interface changes: - The spelling of the "validater" Builder option has been corrected to "validator". The old spelling still works, but generates a warning. - The SConscript() function no longer automatically splits its argument on white space into a list of SConscript file names. You must now explicitly enclose the argument in the Split() function (or do something similar) if you want that behavior. See the release notes for more information about these changes. This release adds the following features: - SWIG support has been added. - Qt support for processing .ui files into .c files has been added. - You may now specify a list of tools when calling Environment.Copy(). - A new "sconsign" script can be used to dump the contents of .sconsign files. - A new $MAXLINELENGTH construction variables allows control of when a temporary file is used for long link lines on Win32. - A Builder emitter can now be a dictionary that maps different source file types (suffixes) to separate emitter functions. - Builder "prefix" and "suffix" arguments can now be callables that return generated strings, or dictionaries that map different source file types (suffixes) to separate prefix or suffix values. - When executing a Win32 long link line in a temporary file, SCons now also prints the long line being executed through the file. - A new $CPPDEFINES variables supports defining platform-independent C preprocessor command-line arguments. - SCons now uses the C++ compiler only if there are any object files from C++ sources being linked, and otherwise invokes the C compiler. The following fixes have been added: - Python Value Nodes now work when using timestamps for signatures. - SCons now creates a .hpp file when the yacc file ends in .yy and the -d YACC flag is used. - SCons now correctly deduces target prefixes from source files in subdirectories in all tested cases. - When CVS checkout errors occur, SCons no longer creates zero-length files by mistake. - All Actions now print correctly when using the --cache-show option. - The Command() Builder can now take a directory as a source. - SConscript file or path names with white space now work. - The Microsoft Visual C++ /TP argument has been added to the default $CXXFLAGS value, so it can compile all the different C++ suffixes. - A problem with checking whether certain Node types are up-to-date has been fixed. - The LIB construction variable is now initialized for the Intel compiler (icl). - The g++ and gcc Tool specifications now actually use g++ and gcc in preference to c++ and cc. - SCons configuration tests no longer hang if a piped command generates more output than can be read in single buffer. Error handling has been improved as follows: - Handling Python errors in SConscript files is now more informative. - SCons now reports the target being built in various error conditions that prevent the build Action from being executed. - Incorrect arguments to the Install() function generates a better error message. - A stack trace is now generated if the internal task controller catches an exception. Performance has been improved as follows: - A default environment is created when needed, not every invocation. - Internal maintenance of various lists of dependencies has been sped up by using a dictionary to search for duplication. - The list of dependent children is now calculated once and cached. - The -debug=pdb option now invokes the Python debugger directly, not by recursively invoking Python+SCons. The following changes have been made to the SCons packaging: - An incorrect distutils warning message when using --prefix= option has been removed. - Building the SCons .rpm package should no longer depend on the installation location of the local distutils. The documentation has been improved: - The help output generated by "scons -H" has been tightened. - An explanation about SCons not propagating the external environment has been added to the introduction. - The AlwaysBuild() function is now better explained. - The SConscript function's "dirs" and "name" keywords are now documented. - Typos have been fixed. ABOUT SCONS Distinctive features of SCons include: - a global view of all dependencies; no multiple passes to get everything built properly - configuration files are Python scripts, allowing the full use of a real scripting language to solve difficult build problems - a modular architecture allows the SCons Build Engine to be embedded in other Python software - the ability to scan files for implicit dependencies (#include files); - improved parallel build (-j) support that provides consistent build speedup regardless of source tree layout - use of MD5 signatures to decide if a file has really changed; no need to "touch" files to fool make that something is up-to-date - easily extensible through user-defined Builder and Scanner objects - build actions can be Python code, as well as external commands An scons-users mailing list is available for those interested in getting started using SCons. You can subscribe at: http://lists.sourceforge.net/lists/listinfo/scons-users Alternatively, we invite you to subscribe to the low-volume scons-announce mailing list to receive notification when new versions of SCons become available: http://lists.sourceforge.net/lists/listinfo/scons-announce ACKNOWLEDGEMENTS Special thanks to Chad Austin, Bram Moolenaar, Gary Oberbrunner, Laurent Pelecq, Ben Scott and Christoph Wiedemann for their contributions to this release. On behalf of the SCons team, --SK From mis6 at pitt.edu Sat Aug 23 11:12:15 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 23 Aug 2003 08:12:15 -0700 Subject: What's better about Ruby than Python? References: <4o_0b.1665$Ej6.1182@newsread4.news.pas.earthlink.net> <8D01b.1721$Ej6.702@newsread4.news.pas.earthlink.net> <3F44ED2E.9070308@nyc.rr.com> <0V61b.1900$Ej6.1012@newsread4.news.pas.earthlink.net> <3F4504D7.20008@nyc.rr.com> <2259b0e2.0308230118.67a676e7@posting.google.com> Message-ID: <2259b0e2.0308230712.3f60cf3c@posting.google.com> Jacek Generowicz wrote in message news:... > mis6 at pitt.edu (Michele Simionato) writes: > > > That said, I do agree that the presence of hundreds of dialects works > > against the adoption of Lisp. For instance, this stopped me (together > > with other factors). > > So why did the presence of "hundreds of dialects" of scripting > languages not stop you adapting a scripting language ? > > As I've mentioned elsewhere; objecting to the existence of multiple > dialects of Lisp (essentially, languages which represent their source > code in a form they can easily manipulate), as as daft as objecting to > the existence of multiple dialects of the Algol Language family, or to > the existence of multiple languages with significant indentation. I disagree. Perl is NOT a dialect of Python. Ruby is NOT a dialect of Python. Tcl is NOT a dialect of Python. They are entirely different languages, at least at the syntactical level (which DOES matter when you learn a language, since you must memorize the syntax too) and on the conceptual level too. I would concede than in many ways Python, Perl and Ruby are similar and more or less with the same power, bust still the way of programming in one or the other is completely different. I would concede that Lisp is different from Scheme, more at the conceptual level that at the syntactical level. But still the reality is that the different implementations of Lisp and Scheme are different, especially in what concern the interface with the operating system and scripting facilities, which is what one does all the time (at least in this mailing list ;). So once I know an implementation, I am never sure my program will run on another implementation, if you prefer the term implementation to the term dialect. On top of that, how am I supposed to choose my implementation? Too much choice (meaning a too much fragmented community) can scare potential lisp newcomers. At least it scared me. There is only one dominant implementation of Python, CPython. All the others try to match it as soon as possible. I expect Jython 2.2 (now in alpha) will catch up with CPython, at some moment. The goal of PyPy or Stackless is to enhance CPython, but taking CPython as base reference. In Scheme there is no such a basic reference, I am correct? Lisp has CL, but learning CL will not help me very much with Emacs Lisp which is what I would need the most ;) I am joking a bit here; BTW, we are going as bit off topic, so let me stop here. Michele Simionato, Ph. D. MicheleSimionato at libero.it http://www.phyast.pitt.edu/~micheles --- Currently looking for a job --- From bokr at oz.net Sat Aug 9 14:17:12 2003 From: bokr at oz.net (Bengt Richter) Date: 9 Aug 2003 18:17:12 GMT Subject: Just say "NO" Re: raw string tail escape revisited References: Message-ID: On Sat, 9 Aug 2003 11:51:16 -0500, Jeff Epler wrote: >Well, one problem is that this is incompatible with all existing >R-strings, which have been in Python for comparative ages. So we'd be >forced to implement then as B'' strings (For Bengt). 16 ways to declare >string literals (single and triple, ' and ", standard, r, u, and ur) >are bad enough, I don't want to add another 8 (single and triple, ' and >", b and ub) to the mix. > $ python -c 'import this' | grep "only one" > >Secondly, the price in the tokenizer for an R-string vs a regular string is >essentially zero, since after the leading r, u or ur is parsed, the >regular rule for parsing any string is used. Your rule will require >near-duplication of a 60-line segment of Parser/tokenizer.c and a new >function similar to PyString_DecodeEscape, probably another 60 lines of >C. > >Finally, I'm not convinced that your description that triple-quotes and >quote-stuffing work well together. RIght now, if the parser sees > R'''' # dumb way to do "'" >it'll still be in the midst of parsing a triple-quoted raw string. How Right. That was a goof. See prev post (I didn't see this one, or I would have made it a reply to this). >will you be able to write a B''' string that begins with a ' if this >rule is followed? So there must be strings that you can't write with >B-quoting, just like there are strings you can't write with R-quoting >(but this time the problem is with strings that start with quotes >instead of ending with backslashes). No, I think you can quote anything. The question is if there are any reasonable use cases that become obnoxious. The fall-back can always be if the data starts with a quote, use a single quote of the opposite kind and double the quoting quote if it appears in the data. With a triple quote, I think you look at the data's last character. If it's a quote, you use the opposite triple quote and then if a triple quote of the now quoting kind occurs in the data, add an extra quote (like doubling, only 33% increase instead of 100%). Can you think of a case that can't be done as a single string? Anyhow, it was just the thought that there didn't have to be any impossible cases that I liked. The current raw string makes lots of impossible cases ending in quotes that you don't want a literal \ in front of. They would become possible, I think. Not that there aren't work-arounds ;-) Regards, Bengt Richter From robin at jessikat.fsnet.co.uk Mon Aug 11 06:40:39 2003 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Mon, 11 Aug 2003 11:40:39 +0100 Subject: Python vs. C# References: <3f357a9b@shknews01> Message-ID: In article , Duncan Booth writes >"Brandon J. Van Every" wrote in >news:3f357a9b at shknews01: > >> So again my question is, language-wise, what can I get done with >> Python that I can't get done with C#? What is easy to express in >> Python, that is tedious, difficult, or impossible to express in C#? >> Eiffel.Net is alleged to have multiple inheritance, but I must admit I wasn't entirely convinced by one of the explanations I saw. In fact at the end of the piece it was stated that multiple inheritance was allowed only for Eiffel classes. On the other hand there are a bunch of features that will apparently arrive with later revisions of the CLR and multiple inheritance is one of them. I suspect it will be a long time before serious meta classes arrive. -- Robin Becker From google at hanger.snowbird.net Sun Aug 24 23:06:56 2003 From: google at hanger.snowbird.net (Kris Caselden) Date: 24 Aug 2003 20:06:56 -0700 Subject: Simple Dictionary Problem Message-ID: I'm still new to some of Python's finer details, so this problem is probably an easy fix. I can't seem to loop through a dictionary whose values are tuples. For instance: oldlist = {'name':(1,2,3)} newlist = [] for x1,x2 in oldlist: for y1 in x2: newlist.append(str(x1)+str(y1)) print newlist Gives me: line 3, in ? for x1,x2 in oldlist: ValueError: too many values to unpack The docs I've read mention problems where the key is immutable, but don't say anything about what data-types are acceptable for the value. What am I missing? From klapotec at chello.at Mon Aug 4 12:14:54 2003 From: klapotec at chello.at (Christopher Koppler) Date: Mon, 04 Aug 2003 16:14:54 GMT Subject: Passing Global Variables between imported modules References: Message-ID: On 4 Aug 2003 07:27:41 -0700, sean at activeprime.com (Sean) wrote: >Is there any way to access global variables defined from within an >imported module? For example, lets say have a file called test2.py >that defines a simple class: > >class MyClass: > def __init__(self): > pass > > def printGlobal(self): > print globalVar > > >Now I have another file that imports test2, sets a global variable >called globalVar, and calles printGlobal() like so: > >from test2 import MyClass > >globalVar = "foo" > >mc = MyClass() >mc.printGlobal() > > >When I run it, I get a NameError that "global name 'globalVar' is not >defined". I've tried explicitly calling 'global globalVar' and even >stepping through the __builtins__ but to no avail. Is accessing >globalVar from within test2.py possible? Global variables are global at *module* level, which means that every class and function defined in that module can access that variable. Variables (and all other names) from *other* modules need to be imported in order to be used, thus the 'not defined'. In your case, however, you'd need to import the 'another file that imports test2' (I'll call it globalTest from here on) into test2, so you could access globalVar inside of test2; that would lead to a nasty case of circular import, and an ImportError exception will be thrown: Traceback (most recent call last): File "globalTest.py", line 1, in ? from test2 import MyClass File "C:\Python23\test2.py", line 1, in ? from globalTest import globalVar File "C:\Python23\globalTest.py", line 1, in ? from test2 import MyClass ImportError: cannot import name MyClass There might be a hack around that, but if there was, I wouldn't use it. To pass any value from globalTest to test2.MyClass, pass it at class instantiation - it becomes a variable local to the class instance. Directly adapting your example: #test2.py class MyClass: def __init__(self, val): self.value = val def printGlobal(self): print self.value #globalTest.py from test2 import MyClass globalVar = "foo" mc = MyClass(globalVar) mc.printGlobal() So far so good, this runs as it should. Now if you tell us what you really wanted to do, maybe we could give you a more helpful answer... --Christopher From nhodgson at bigpond.net.au Fri Aug 22 21:52:49 2003 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Sat, 23 Aug 2003 01:52:49 GMT Subject: Script to remove SoBig/F virus from POP3 mailbox References: Message-ID: Skip: > I wrote something similar today for scrubbing Mailman 2.1 pending > administrative requests. I have created a similar script. It requires ClientCookie and ClientForm (URLs in the script) and blindly discards all moderation requests. http://www.scintilla.org/DiscardModeration.py Modify the script to point to your host, lists and password and then run. If your admin URL looks like "http://mailman.XXX/mailman/admindb/YYY" then YYY is the mailing list name and "http://mailman.XXX/mailman/admindb/" the host. Tested with Mailman 2.1.2 and client side Python 2.3. Neil From m.doering at bgbm.org Tue Aug 26 03:41:13 2003 From: m.doering at bgbm.org (Markus Doering) Date: Tue, 26 Aug 2003 09:41:13 +0200 Subject: Python2.3 absolute import error References: Message-ID: Oh man. After diving into the site.py traceback I noticed that I had a module named "types" in my package and site.py tried to import the standard types module but ended up importing my custom module instead (the scripts directory is the first in sys.path). I renamed it and everything seems to work fine. Thanks, Markus "A.M. Kuchling" wrote in message news:g8KcnaISvKGppdeiRTvUqg at speakeasy.net... > On Mon, 25 Aug 2003 17:56:52 +0200, > > 'import site' failed; use -v for traceback > ^^^^ what's this? > > I expect the installation is incorrect or sys.path is messed up in some way, > and suspect that your import problems are only a side effect, not the root > cause of the problem. Run "python -v" to see the traceback from site.py. > > --amk From vvainio at tp.spt.fi Mon Aug 18 02:25:16 2003 From: vvainio at tp.spt.fi (Ville Vainio) Date: 17 Aug 2003 23:25:16 -0700 Subject: What's better about Ruby than Python? References: Message-ID: "Brandon J. Van Every" wrote in message news:... > This is not a troll. I'm language shopping and I want people's answers. I .. > also talking about Ruby. So it seems that Ruby has the potential to compete > with and displace Python. I'm curious on what basis it might do so. :-) From mwh at python.net Thu Aug 28 07:45:52 2003 From: mwh at python.net (Michael Hudson) Date: Thu, 28 Aug 2003 11:45:52 GMT Subject: Style question... References: <3F4D637B.7ADB0BC4@alcyone.com> Message-ID: <7h3oeya57pe.fsf@pc150.maths.bris.ac.uk> "Anthony Roberts" writes: > > C-c < and C-c >. > > Thanks. :) It's worth doing "C-h m" and "C-c ?" and reading the results, too. Cheers, mwh -- In case you're not a computer person, I should probably point out that "Real Soon Now" is a technical term meaning "sometime before the heat-death of the universe, maybe". -- Scott Fahlman From raims at dot.com Tue Aug 26 16:09:23 2003 From: raims at dot.com (Lawrence Oluyede) Date: Tue, 26 Aug 2003 22:09:23 +0200 Subject: My future Python IDE article References: <87smno1bfh.fsf@vercingetorix.caesar.org> Message-ID: <87wud02nbg.fsf@voodoo.fake> Dialtone writes: > 3) Eclipse + Trustudio Mmm i don't think so. IDLE is better :-) And i think that's not a great idea to use an IDE that needs a JVM to run only to have syntax highlighting and a not-so-smart indentation feature. For Trustudio you need a JVM (~20 Mb) , Eclipse (~60Mb), Trustudio plugins (~1.5 Mb) For IDLE you need nothing :) When Trustudio will become really useful, i think that'll be the time to look at it, since Eclipse itself is awesome for refactoring and Java coding -- Lawrence "Rhymes" Oluyede http://loluyede.blogspot.com rhymes at NOSPAMmyself.com From cjw at sympatico.ca Mon Aug 25 10:22:56 2003 From: cjw at sympatico.ca (Colin J. Williams) Date: Mon, 25 Aug 2003 10:22:56 -0400 Subject: python gripes survey In-Reply-To: References: <7s6gkv031b940dsc522pbh5g30q4nj5vd1@4ax.com> Message-ID: <_Yo2b.365$nw3.90129@news20.bellglobal.com> nnes wrote: > Geoff Howland wrote in message news:<7s6gkv031b940dsc522pbh5g30q4nj5vd1 at 4ax.com>... > >>On Sat, 23 Aug 2003 15:39:27 GMT, "Ryan Lowe" >>wrote: >> >>Just to point some things out since I started the {} [] thread. I was >>trying to do something hacky, and while I wanted the [].len() type >>calls for my team mates, I never had a problem with the current len() >>and understand the reasoning behind it. [].len() is more uniform, but >>it also changes the requirements for the language in a duplicated >>fashion, since the test for __len__() will always exist as well. >> >>So while I think they may have been reasonable requests, Im not sure >>theyre really pitfalls, and Im not sure they would even work out that >>well on a large scale which is why I wanted to implement it and test >>it out myself. >> >> >>-Geoff Howland >>http://ludumdare.com/ > > > Can you post a link to that thread? > > I have never understood why python has [].count() or "".count() but > len([]) and len(""). > > Why not make len, sum, str, repr, etc just methods of the base object > class with specific implementations for different types. Instead of > doing len([]) we could do [].len(). > > This is actually possible already in part. I think you can do > [].__len__(). But I never understood the reasoning behind making these > special __x__() methods instead of doing a plain x() and using it like > obj.x(). Or why not make it plainer still, so that len, str etc become properties or attributes, without the need to add the redundant parentheses? > > The only case I can think of, where it would look kind of odd would be > floating points like: > > niceoutput=2.3.str() > > Anyway since Pythonistas are smart, it can not be a wart of the > language and must be some lack in my understanding :) > > awaiting-to-be-enlightened-yours > > Nestor Colin W. From matthew at barnes.net Tue Aug 19 20:55:44 2003 From: matthew at barnes.net (Matthew Barnes) Date: 19 Aug 2003 17:55:44 -0700 Subject: Unification of logging in Python's Standard Library References: <3a8e83d2.0308182217.7ccaf883@posting.google.com> Message-ID: <3a8e83d2.0308191655.7a82881b@posting.google.com> "A.M. Kuchling" wrote>: > I suspect a PEP is required, because there are more issues here than just > changing sys.stderr.write() to logging.info(). For example, what logger > should modules use to log messages? If they use the root logger, it will be > difficult to discard messages from asyncore while keeping messages from the > ZODB. If they use a particular logger, how is this name chosen? Is it > dependent on the module name, so asyncore logs to 'asyncore' and so forth? > What if my application has a logger named 'network', and I want it to go to > 'network.asyncore', 'database.ZODB', etc.? > > If the user specifies a logger, how is this done? Does every public method > have to grow an optional 'log' argument, or is there a module-level global > setting, so you'd call > asyncore.set_logger(logging.getLogger('network.asyncore'))? > > None of these options are very difficult to implement, but choosing which > one will take some care; otherwise we'll be saddled with an inconvenient > implementation that we'll be forever working around. "John Roth" wrote: > I'm going to agree with Andrew: write a PEP. > > Unittest, as far as I know, doesn't have a logging system, and > I, for one, don't want to see it burdened with a completely unnecessary > logging system. I can't comment on the other examples in your > list because I've never used them, but unittest is part of my standard > project life, and I like it the way it is, thanks. Kent Beck and the > other people involved in the xUnit development put a lot of thought > into how it works, and AFKC, lack of logging isn't one of the problems. Andrew raised some very good points, and a PEP probably is necessary. I did have some half baked ideas on how to go about this. Generally speaking, the default logging output of each module that uses 'logging' should be identical or as identical as possible to what the module currently produces. This would (hopefully) make the transition nearly transparent to end-users. Then we provide some 'hook' at either a module-level or (preferably) class-level for replacing the default logger with a customized one. Here's a few more module-specific thoughts: asyncore.py ----------- Add a 'logger' attribute to the 'dispatcher' class, which defaults to a logger named 'asyncore' (i.e. the module's __name__) configured to use a StreamHandler. This would allow each instance of asyncore.dispatcher to potentially have a unique logger. BaseHTTPServer.py ----------------- Add a 'logger' attribute to the 'BaseHTTPRequestHandler' class, which defaults to a logger named 'BaseHTTPServer' (i.e. the module's __name__) configured to use a StreamHandler and a Formatter that produces the RFC931-style messages that are currently produced (note: haven't looked into whether a logging.Formatter can do that). This would allow each instance of BaseHTTPServer.BaseHTTPRequestHandler to potentially have a unique logger. cgi.py ------ Not quite sure about what to do with this one; Andrew's questions pop up here. Perhaps provide a logger named 'cgi' (i.e. the module's __name__) configured to use a StreamHandler. The functions should use a module-level 'logger' variable (initialized to the 'cgi' logger) rather than hard-coding the logger name into the function bodies. The 'logger' variable could then be assigned a different logger instance and the functions would pick up on it. I need to kill some more brain cells on the other modules in my list. I will say that unittest is what motivated me to suggest this in the first place, since I'm working on a testing framework that is attempting to take advantage of both the unittest *and* logging modules. Perhaps a new TestRunner class that uses logging (LoggingTestRunner?) might coexist with the default TextTestRunner. Matt From max at alcyone.com Tue Aug 12 23:55:16 2003 From: max at alcyone.com (Erik Max Francis) Date: Tue, 12 Aug 2003 20:55:16 -0700 Subject: customizing and/or/not References: Message-ID: <3F39B6A4.E48450BE@alcyone.com> Simon Burton wrote: > I guess i'm wondering why we cant use and/or with lists/sets etc. > It's perhaps too funky. It's not possible because there is something substantively different about the and/or operators as opposed to say, the &/| operator: The and/or operators support short-circuiting. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ He who conceals his disease cannot expect to be cured. \__/ (an Ethiopian proverb) From Spam.Buster at web.de Sun Aug 24 07:45:58 2003 From: Spam.Buster at web.de (Lars Behrens) Date: Sun, 24 Aug 2003 13:45:58 +0200 Subject: How to store data? In-Reply-To: <3f482037_5@corp.newsgroups.com> References: <3f482037_5@corp.newsgroups.com> Message-ID: Thx for your help and hints and examples. But as you assume, my application *is* mission critical. And as I read Pointres is only tested under GNU/Linux but the server I have to use runs under Solaris, so I have to find another solution. Anyways, what I've read so far about Pointres sounds quite interesting to me (especially because I'm a real database hater). So I will certainly take a look at Pointres sometime... Cheerz Lars From thanks200 at hotmail.com Fri Aug 15 03:11:29 2003 From: thanks200 at hotmail.com (Tom Hanks) Date: 15 Aug 2003 00:11:29 -0700 Subject: Is Python your only programming language? References: Message-ID: <6152d0a0.0308142311.679c6f01@posting.google.com> "Richard Brodie" wrote in message [snip] > It was in a background task, that was unnecessary. However the > exception handling was specified to be: write results to EEPROM > and halt. It's true that in C one would likely have garbage values > in the integer, and the error would have gone unnoticed. I'm not > sure I find that a comforting thought though. Yeah, I hate "fail-silently" - it's much simpler to find errors if you simply explode the rocket to draw attention to your typo. :) TTFN, Tom. From bokr at oz.net Thu Aug 7 20:33:07 2003 From: bokr at oz.net (Bengt Richter) Date: 8 Aug 2003 00:33:07 GMT Subject: Bug? If not, how to work around it? References: Message-ID: On Thu, 07 Aug 2003 00:57:30 +0100, Gon?alo Rodrigues wrote: >On 6 Aug 2003 19:35:18 -0400, aahz at pythoncraft.com (Aahz) wrote: > >>In article , >>Gon?alo Rodrigues wrote: >>> >>>>>> class Test(object): >>>... def __init__(self, obj): >>>... self.__obj = obj >>>... def __getattr__(self, name): >>>... return getattr(self.__obj, name) >>>... >>>>>> a = Test([]) >>>>>> a.__iter__ >>> >>>>>> iter(a) >>>Traceback (most recent call last): >>> File "", line 1, in ? >>>TypeError: iteration over non-sequence >>>>>> >>> >>>Is this a bug? If not, how to code Test such that iter sees the >>>__iter__ of the underlying object? >> >>As Mark guessed, iter() goes directly to the attribute rather than using >>the __getattr__ machinery of the class. However, you can intercept it >>using a metaclass, but that requires a bit of fancy footwork to reach >>down into the instance to get self.__obj. > >Actually I came across this because of a little metaclass I was >coding. And my head hurts already as it is... > >So, is it a bug? In other words, should I open a bug report? > I don't think it's a bug, but there's a lot to explore ;-) Here is something I've been hacking at to do some exploring. Maybe you will find it interesting: ====< for_grodrigues.py >============================================= class Test(object): def __init__(self, *args, **kw): pass def __new__(cls, obj): # helper to capture method in closure for method delegator def mk_meth_deleg(obj, meth, name): def meth_deleg(arg0, *args, **kw): if isinstance(arg0, type): return meth(arg0, *args, **kw) else: return meth(obj, *args, **kw) return meth_deleg # get the objects's class dict to build a new class proxy_cdict = obj.__class__.__dict__.copy() for name, meth in proxy_cdict.items(): if( name.startswith('__') and callable(meth) and #not name.startswith('__getattr') and not name == '__init__' ): m = mk_meth_deleg(obj, meth, name) proxy_cdict[name] = m # customize proxy class as desired here def __getitem__(self, i): if i==2: return '[Test-modified %r]'%obj[i] else: return obj[i] proxy_cdict['__getitem__'] = __getitem__ #derive from object's class if possible for stuff we haven't caught?? try: type('',(obj.__class__,), {}) except TypeError: proxy_base = object else: proxy_base = obj.__class__ proxy_class = type( obj.__class__.__name__+'_proxy', (proxy_base,), proxy_cdict) proxy_obj = proxy_class() proxy_obj.instattr = 'proxy_obj instance attribute set by Test' return proxy_obj ====================================================================== Sample interaction: >>> from for_grodrigues import Test >>> a = Test([1,2,3]) >>> a [1, 2, 3] >>> type(a) >>> a.__iter__ >>> iter(a) >>> a.__iter__() >>> ait = iter(a) >>> ait.next() 1 >>> for i in a: print i, ... 1 2 3 Note that the __iter__ bypassed the doctored __getitem__ of our proxy object, vs: >>> for i in range(3): print a[i], ... 1 2 [Test-modified 3] >>> b = Test(None) >>> type(b) >>> b None >>> b[2] Traceback (most recent call last): File "", line 1, in ? File "for_grodrigues.py", line 26, in __getitem__ if i==2: return '[Test-modified %r]'%obj[i] TypeError: unsubscriptable object Now we try to iterate over the string, but it doesn't provide __iter__ apparently, since we can see that it wound up using __getitem__: >>> c = Test('abcd') >>> for x in c: print x, ... a b [Test-modified 'c'] d vs, again the list: >>> a [1, 2, 3] >>> type(a) >>> for i in a: print i, ... 1 2 3 >>> c 'abcd' >>> c[::-1] 'dcba' That doesn't use __getitem__ either. By inheriting from the object's class, we pick up base class methods: >>> class A(object): ... def afoo(self): return 'afoo()' ... >>> class B(A): ... def bfoo(self): return 'bfoo()' ... >>> b = B() >>> pb = Test(b) >>> pb.bfoo() 'bfoo()' >>> pb.afoo() 'afoo()' >>> type(pb) There are interesting issues of proxy object attribute space vs the real object vs the proxy class methods vs the real object's methods, vs inheritance for it, etc. and you could alter the priorities. You can mess with it yourself, and maybe eliminate some hacking cruft ;-) Regards, Bengt Richter From Simon.Wittber at perth.maptek.com.au Sun Aug 10 21:38:57 2003 From: Simon.Wittber at perth.maptek.com.au (Simon Wittber (Maptek)) Date: Mon, 11 Aug 2003 09:38:57 +0800 Subject: Python vs. C# Message-ID: <20E0F651F8B82F45ABCBACC58A2D995B0518B8@mexper1> >I'm starting to think that you are trolling. Are you? Hi Brian, You should never insinuate that Brandon is a troll, unless you are prepared to have your address appended to the end of his 100MB killfile. Indeed, I believe you have guessed correctly, Brandon is a very subtle and clever troll. For a full history, try google. http://groups.google.com/groups?q=brandon+every From aahz at pythoncraft.com Tue Aug 12 10:44:40 2003 From: aahz at pythoncraft.com (Aahz) Date: 12 Aug 2003 10:44:40 -0400 Subject: What's a troll? (was Re: Python vs. C#) References: <54nm01-tqj.ln1@newsgate.kjn.lan> Message-ID: In article <54nm01-tqj.ln1 at newsgate.kjn.lan>, Theodor Rash wrote: > > -------------------------- > /| /| | | > ||__|| | Please don't | > / O O\__ feed | > / \ the trolls | > / \ \ | > / _ \ \ ---------------------- > / |\____\ \ || > / | | | |\____/ || > / \|_|_|/ | __|| > / / \ |____| || > / | | /| | --| > | | |// |____ --| > * _ | |_|_|_| | \-/ > *-- _--\ _ \ // | > / _ \\ _ // | / > * / \_ /- | - | | > * ___ c_c_c_C/ \C_c_c_c____________ ROTFL! Now, if you wanna make one *really* funny, make it with a panda. ;-) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Let's see who gets this reference From interscaneManager at fr.ch Thu Aug 21 06:49:44 2003 From: interscaneManager at fr.ch (interscaneManager at fr.ch) Date: Thu, 21 Aug 2003 12:49:44 +0200 Subject: message eradique par une regle emise par SPE Message-ID: ************* eManager Notification ************** Sender, Content filter has detected a sensitive e-mail. Source mailbox: "python-list at python.org" Destination mailbox(es): SPE at fr.ch Action: Delete ******************* End of message ******************* -------------- next part -------------- Received: from [212.152.255.254] by sangbad09.etatfr.ch via smtpd (for [172.20.1.7]) with SMTP; Thu, 21 Aug 2003 12:48:10 +0200 From: To: Subject: Re: Details Date: Thu, 21 Aug 2003 13:00:17 +0200 X-MailScanner: Found to be clean Importance: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MSMail-Priority: Normal X-Priority: 3 (Normal) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="_NextPart_000_042BE67A" From staschuk at telusplanet.net Wed Aug 27 01:19:27 2003 From: staschuk at telusplanet.net (Steven Taschuk) Date: Tue, 26 Aug 2003 23:19:27 -0600 Subject: getopt issues In-Reply-To: ; from david.bear@asu.edu on Tue, Aug 26, 2003 at 09:13:35PM -0700 References: Message-ID: <20030826231927.A3216@tibia.amotlpaa.bogus> Quoth David Bear: > >>> args > '-Middwb at mainex1.asu.edu -AKHAAM at prlinux+898 [...] [...] > >>> a, b = getopt.getopt(args, 'APQn') getopt wants its arguments as a list of strings (like sys.argv), not one big string. Here, for example, >>> a, b = getopt.getopt(args.split(), 'APQn') Traceback (most recent call last): ... getopt.GetoptError: option -M not recognized as expected. -- Steven Taschuk o- @ staschuk at telusplanet.net 7O ) " ( From abelikov72 at hotmail.com Mon Aug 25 16:06:13 2003 From: abelikov72 at hotmail.com (Afanasiy) Date: Mon, 25 Aug 2003 20:06:13 GMT Subject: python gripes survey References: Message-ID: On Mon, 25 Aug 2003 13:42:00 -0500, sismex01 at hebmex.com wrote: >[Afanasiy] >> Returning a struct in C is >> easier to deal with than returning a near-mystery tuple in Python. >> > >You *really* *must* *be* *kidding*. On the very specific level I was referring to, I really am not kidding. From google at mattwhelan.info Fri Aug 15 16:40:45 2003 From: google at mattwhelan.info (Matt Whelan) Date: 15 Aug 2003 13:40:45 -0700 Subject: SWIG and __int64 References: <3F3BE519.3060802@users.sourceforge.net> Message-ID: Lyle Johnson wrote in message news:<3F3BE519.3060802 at users.sourceforge.net>... > Just to clarify: are you getting errors when running SWIG (i.e. to > generate the wrapper code) or when compiling the code that SWIG > generated for you? Yes, it's in the SWIG generation step. I think I've figured out the problem, but I still don't know what to do about it. All the __int?? types are specified as unsigned in my code. SWIG works great on default-signedness types, but it throws syntax errors on "unsigned __int64" and friends. So here's what I've got: ----Begin Code---- test.i: %module test_wrap %{ #include "test.h" %} %apply long long { __int64 } %include test.h test.h: #ifndef TEST_H #define TEST_H unsigned __int64 foo(); //body is {return 42;} in test.cpp #endif ----End Code---- If I remove the unsigned qualifier, it works fine, but as it is I get a syntax error on line 4 of test.h. I've tried adding the unsigned qualifier to the %apply statment in all possible ways; none of them help. I'm beginning to suspect this is a bug in SWIG. If someone can give me a work around (or educate me on what I'm doing wrong), I would appreciate it. From jjl at pobox.com Sun Aug 24 09:04:01 2003 From: jjl at pobox.com (John J. Lee) Date: 24 Aug 2003 14:04:01 +0100 Subject: macro FAQ References: <1ffd32d9.0308232315.3eadd758@posting.google.com> Message-ID: <874r07jjge.fsf@pobox.com> Jacek Generowicz writes: > dtolton at yahoo.com (Doug Tolton) writes: [...] > I hoped that the examples that I presented satisfied the requirements > that > > a) They be simple enough to understand > > b) not be (at least easily) implementable using existing Python > features > > c) Not be completely useless > > Did I fail ? :-) Yes. :-) John From warlock at eskimo.com Sun Aug 3 03:22:14 2003 From: warlock at eskimo.com (Jim Richardson) Date: Sun, 3 Aug 2003 00:22:14 -0700 Subject: Match beginning of two strings References: <3f2c429e@nntp0.pdx.net> <3f2c7806.20532894@news.lexicon.net> Message-ID: <6qpuv-q4m.ln1@grendel.myth> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Sun, 3 Aug 2003 00:22:46 -0600, Andrew Dalke wrote: > Ravi: >> Read in both strings. >> Check to see if the first character matches. >> If yes: >> Check halfway through the string and see if that character matches >> Repeatedly check halfway until the difference point is found. >> Go back through from the difference point backwards and make sure >> the characters match from the start to the difference point. >> >> I timed it, and it seems to be doing about 3.5usec per loop. > > There's a lot of overhead for doing that. Have you tried the simple > > char *s1 = ... the first string .. > char *s2 = ... the second string .. > n = ... the shorter of the two .. > for(i=0; i if (*s1++ != *s2++) { > break; > } > } > return ... the string s1[:n] (or even just the int) > > Easy to understand, and the CPU is spending almost its whole > time doing character tests. > > Why bother finding out which one is the shorter? if you try the compare, and you run out of the other to compare to, then by default, it's not the same :) -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (GNU/Linux) iD8DBQE/LLgmd90bcYOAWPYRAoWbAJ9dgt4IMuu07FgyuUAtdJlVf5AWygCg1Rek 7Qd4Z6xgK1NwhysngVlLQY0= =ZWGw -----END PGP SIGNATURE----- -- Jim Richardson http://www.eskimo.com/~warlock Linux, because eventually, you grow up enough to be trusted with a fork() From stevecanfield at yahoo.com Wed Aug 13 09:46:39 2003 From: stevecanfield at yahoo.com (Steve Canfield) Date: 13 Aug 2003 06:46:39 -0700 Subject: Plone book recommendation Message-ID: <63081650.0308130546.1e884bab@posting.google.com> I've just downloaded Plone and have started to experiment with it. Are there any Plone books available? I'm interested in books on working with and customizing plone. A quick search on Amazon didn't turn up anything. Is there a Zope book with a significant Plone section? Thanks, Steve From tzot at sil-tec.gr Tue Aug 19 23:10:15 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Wed, 20 Aug 2003 06:10:15 +0300 Subject: Recommendation of a parser generator References: Message-ID: On 9 Aug 2003 03:57:38 GMT, rumours say that bokr at oz.net (Bengt Richter) might have written: >BTW, I wonder if there is a Python parser generator that will take >a flex-format grammar as input. Then a transition would be easier. Don't know of one; but have you heard of ply? google('python lex yacc') -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From raims at dot.com Wed Aug 27 04:14:52 2003 From: raims at dot.com (Lawrence Oluyede) Date: Wed, 27 Aug 2003 10:14:52 +0200 Subject: problem installing PyQt for eric3 References: Message-ID: <87oeyb4iv7.fsf@voodoo.fake> Lupe writes: > In file included from qttest.cpp:1: /usr/lib/qt3/include/qgl.h:78:21: > GL/glu.h: No such file or directory It doesn't find GL utility library's header file. > make: ** [qttest.o] Erro 1 > ************************************************************** > The qtgl > module will not be built. > ************************************************************** It means that you won't have support for OpenGL in QT > > can anyone translate this to english. Is qtgl important? No, if you don't need OpenGL in PyQT. Eric3 doesn't use that modules > I have a file named qgl.h in the /include directory, so what was wrong? qgl.h is there. the compiler doesn't find the glu.h header. -- Lawrence "Rhymes" Oluyede http://loluyede.blogspot.com rhymes at NOSPAMmyself.com From ny_r_marquez at yahoo.com Wed Aug 27 12:48:58 2003 From: ny_r_marquez at yahoo.com (R.Marquez) Date: 27 Aug 2003 09:48:58 -0700 Subject: My future Python IDE article References: Message-ID: <8a27e309.0308270848.6ca4f8c2@posting.google.com> > So c.l.py readers... make the case for your favorite one getting on the > list. I have a while to ponder the opinions advanced, should this > prompt some discussion (it may take a little while to order review > copies of commercial tools and/or get things installed). I work on Windows mostly, and Pythonwin has been great for a few years, although it doesn't have any GUI building facilities. Lately, due to a bug in the last release (which I have already submitted), I have taken the opportunity to give others a try. I am not currently interested in paying for an IDE. I tried BOA a little while ago. My first impression was "wow, someone has done a lot of work here". However, I didn't like the fact that I had to mold my code to the way the application wants it. For example, I have to always have a "main" function. Maybe that is a good practice, but being forced to it didn't give me a good feeling. The code it generated for the GUI was a bit verbose and it... I don't know. It just didn't seem to simplify things for me too much. I probably should go back and give it another try one of these days. Idle is nice enough, although like Pythonwin, it doesn't have any GUI building facilities. Surprisingly for me, I couldn't find some basic features for simple code editing that I really like. For example, I couldn't find a way to have white space visible. It also doesn't seem to have an indentation guide feature, which I find very useful in Pythonwin (this feature seems to me to be a must for a Python code editor since indentation is so crucial in it). Also, I could not see how to display line numbers (although it does have a "Go to line" feature). I was surprised to find all of these features as well as most other features that I expected for basic code editing on the PythonCard prototype Code Editor. And, PythonCard is an actual Application builder, with outstanding GUI building facilities and all. I think that PythonCard has the potential to be the best IDE/App Builder for Python. It uses wxPython as its foundation, which I think is most GUI developers favorite *free* toolkit. Unfortunately, a lot of the wxPython widgets have yet to be integrated. However, it is already usable for simple GUI applications. So, if you haven't given a try I would encourage you to do so. You may just see what I mean. I still like Pythonwin as my favorite Code Editor in Windows. But, until my little bug is fixed I think I am sticking with PythonCard's Code Editor. -Ruben From Robert at AbilitySys.com Thu Aug 21 11:08:58 2003 From: Robert at AbilitySys.com (Robert D. Young) Date: Thu, 21 Aug 2003 08:08:58 -0700 Subject: How does one get "maintenance copies" (resend) Message-ID: <0FC17BE316F9BB47A704AF96308E09CD12263D@ability-nt.AbilityNT.AbilitySys.com> (I sent this last night, but never saw it on the list) Pardon my stupidity, I've only used the Windows version of Python and only via the standard installer at that. However, I've been having a bear of a time w/2.3 - I even went back to 2.2 to stay productive. I researched the "bug list" to see if the problems I was experiencing were known and sure enough, they are (such as the "install to a directory name with a space" issue that IDLE has). The bug tracker mentions these are fixed in some form of "maintenance" package. How can I get the latest fixes and put them into my Windows version? TIA, - Robert From vanevery at 3DProgrammer.com Sun Aug 17 06:56:27 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Sun, 17 Aug 2003 03:56:27 -0700 Subject: simple text parser? References: <3f3f4caf$0$49113$e4fe514c@news.xs4all.nl> Message-ID: Irmen de Jong wrote: > Brandon J. Van Every wrote: > >> Can anyone recommend simple text parsers implemented in Python? > > You can use Python's own pickle mechanism to serialize almost > any Python object(s). But you won't be able to read it back > in if you also want to build it in another language such as C# > that you mentioned. I don't care about C# interoperability. The Python and C# projects will be completely separate. > Or you could use a CSV (Comma Separated Values) file format, > that is easily generated and parsed from Python's csv module > and should also be easy to do from other languages. Will look into it. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From ktilton at nyc.rr.com Thu Aug 21 17:58:46 2003 From: ktilton at nyc.rr.com (Kenny Tilton) Date: Thu, 21 Aug 2003 21:58:46 GMT Subject: What's better about Ruby than Python? References: <3F41505F.69D18CC8@alcyone.com> <66d7kvonvb2n0nqbqahhd5roak7ur81sob@4ax.com> <3f43ef5d_4@127.0.0.1> <3F440A35.9030602@nyc.rr.com> <3F44CF06.4080003@nyc.rr.com> <3F4528FD.7040404@nyc.rr.com> Message-ID: <3F454166.8010409@nyc.rr.com> Andrew Dalke wrote: > Maybe. But look for previous posts of mine on c.l.py to see that > my previous attempts at learning Lisp have met dead ends. I know > how it's supposed to work, but haven't been able to convert what > I see on a page into something in my head. It's funny you say that. Someone is dropping by shortly to help me get up to speed on Linux, and I am helping him with Lisp. But the last email from him said he had been reading Winston&Horn since my talk on Sunday (which apparently got him off the same "don't-get-it" square you're on) and he now says he has no idea why he did not get it before. I wonder if the (funny (syntax)) makes people think there is more there than there is. Even in C I code functionally: this( that( x), then (y)) so I do not think it is the functional thang. > BTW, I'm afraid I'm about at the end of my limits for this thread. > I'll only be able to do small followups. OK. I might be tossing off a fun demo of my C? jobbies for my talk at the upcoming Lisp conference in New York: http://www.international-lisp-conference.org/ Maybe I'll preview it here. That might help us understand each other better it. -- kenny tilton clinisys, inc http://www.tilton-technology.com/ --------------------------------------------------------------- "Career highlights? I had two. I got an intentional walk from Sandy Koufax and I got out of a rundown against the Mets." -- Bob Uecker From elf at drizzle.com Wed Aug 13 17:40:54 2003 From: elf at drizzle.com (Elf M. Sternberg) Date: Wed, 13 Aug 2003 14:40:54 -0700 Subject: Python signal delivery under BSD 4.4 References: Message-ID: Donn Cave writes: > In article , > "Elf M. Sternberg" wrote: >> This worked well under Python 2.1, where I used os.fork() instead >> of os.spawnvp(). >> We have upgraded to Python 2.2.3 and it has mysteriously stopped >> working. Processes launched off the appserver, whether using os.fork() >> or os.spawnvp(), are now completely deaf to signals. Nothing gets its >> attention except, of course, SIGKILL. Not when sent from the appserver, >> and not when sent from the shell, not even by root. I'm sorry about the confusion. FreeBSD 4.4 is what we're running where I work. > Can you duplicate it in a simpler environment? > I'd like to run the following C program from spawnv, from a > Python program like > import os > import time > import signal > p = os.spawnv(os.P_NOWAIT, 'prsig', ['prsig']) > time.sleep(1.0) > os.kill(p, signal.SIGTERM) > print 'process exit', os.waitpid(p, 0) I'm going to assume you meant 'SIGUSR1' here since that's what you're catching in the C code you included. In any event, your code worked as expected. However, this variant worked as I've reported: import os import sys import time import signal import thread def do_it(): p = os.spawnv(os.P_NOWAIT, 'prsig', ['prsig']) print >>sys.stderr, "Sleeping" time.sleep(1.0) os.kill(p, signal.SIGUSR1) print 'process exit', os.waitpid(p, 0) sys.exit() thread.start_new_thread(do_it, ()) time.sleep(4.0) Not only did it behave as I reported, but it slept the full four seconds even though the sys.exit() call was made. This leads me to the conclusion that something rather unusual is going on within Python's threading module and the libc_r.a within FreeBSD4.4. Right now, I just want a way to make signal delivery work. Thanks for your help so far, though. Elf From jacek.generowicz at cern.ch Thu Aug 21 10:27:01 2003 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 21 Aug 2003 16:27:01 +0200 Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> <6dj2kv8ugkieehs7guh786cl40o5lj6mcs@4ax.com> <3F44CF86.3060203@users.ch> Message-ID: Borcis writes: > Jacek Generowicz wrote: > > > You criticize macros for not encouraging code sharing (they do, by > > encouraging you to share the (vast) underlying language while reaching > > out towards a specific domain), while your preferred solution seems to > > be the ultimate code non-sharing, by throwing away the underlying > > language, and re-doing it. > > This criticism can't help looking frivolous, Only in so far as the original thesis is frivolous. > You appear to be confusing "language" with "speech". I'm not sure what you mean by this. Are you saying that macros are "language" because you've heard the buzz-phrase that "macros allow you to modify the language", while functions, classes and modules are "speech", because no such buzz-phrases about them abound ? If so, then you are erecting artificial boundaries between different abstraction mechanisms. (All IMHO, of course.) From zhoney at wildmail.com Mon Aug 25 15:14:11 2003 From: zhoney at wildmail.com (Zora Honey) Date: Mon, 25 Aug 2003 14:14:11 -0500 Subject: Help embedding python References: <3F4A469E.58B94F7C@engcorp.com> <3F4A57B0.E91D89FC@engcorp.com> Message-ID: Peter Hansen wrote: > Zora Honey wrote: > >>Peter Hansen wrote: >> >>>Zora Honey wrote: >>> >>> >>>>My husband and I are writing a program that does a lot of math behind >>>>the scenes (c++) with a gui front (python/Tkinter). We've decided that >>>>we want the c++ to be the "driver", and so we want to embed the python. >>> >>> >>>It's a little unclear (to me) exactly what you're trying to do, >>>but in any case I can't imagine why you'd want to have C++ "drive" >>>the Python code (if that's what you meant by "driver", as opposed to >>>the more common sense as in "device driver") instead of the other >>>way around. >>> >>>And my inability to imagine why you want this is compounded by your >>>choice of Python and Tkinter for the front end. It is much more >>>common to have the front end be the "driving" code, and the back end >>>be "driven", especially in CPU-intensive applications as it sounds >>>like you have here. >>> >>>-Peter >> >>Okay. Let's assume that the choice to embed the python was a >>well-reasoned decision. Or assume that I want to embed some python for >>the pure joy of doing so. Can you help? > > > No, sorry. I have no particular expertise in embedding Python in a > C++ application in the way you wish. > > (If I did, and I had an easy answer, I would offer it. If, on the other hand, > I had no easy answer, and it was going to take some effort on my part, > I'd be happy to provide that effort if the person I was helping would > take a moment of his/her time to convince me that it was a well-reasoned > decision. If, on the other hand, the decision was based on ignorance > or merely on a frivolous desire to experience the joy of doing so at the > cost of another's valuable time, I would probably be less inclined to help...) > > (If you assume for a moment that the person who actually *can* help you > might feel somewhat the same way, you might take a moment to explain > the background rather than risk looking like you treat others' time as > less valuable than your own. It may not look that way to you, but I > was merely trying to help by showing you that at least one person was > puzzled by your choice. I'm also always interested in learning, so > I'd still be quite interested in your rationale, if you are willing to > provide it.) > > Cheers, > -Peter I'm sorry if I was a bit curt. The reason I didn't include rationale is because I have none. I have been advocating extending python instead of embedding it, but since I have no experience with either, my only argument is that it seems more natural. It seems like either method is as difficult to learn and implement. It doesn't seem to me that there are lot of arguments one way or the other. My husband, on the other hand, is strongly attached to the idea of having a c++ main program that will coordinate all the data-processing classes and python widgets. He believes it is easier to have c++ say to python, "here, I have these plots for you," rather than have python say to c++, "make these plots for me." I don't believe this is true, but I don't have any reason *not* to believe it's true, so I aquiesced. So, I suppose instead of asking you to assume the rationale are well reasoned, I should be asking you why you believe extending python is easier/cheaper/faster/better than embedding it. Thank you, Zora (who's hoping hubby isn't reading this newsgroup today) From cnetzer at sonic.net Thu Aug 28 16:36:09 2003 From: cnetzer at sonic.net (Chad Netzer) Date: Thu, 28 Aug 2003 13:36:09 -0700 Subject: OT: Americans love their guns In-Reply-To: References: Message-ID: <1062102969.1849.9.camel@adsl-209.204.179.133.sonic.net> On Thu, 2003-08-28 at 12:46, maxx at easynews.com wrote: > On Thu, 28 Aug 2003 02:12:34 -0400, Lulu of the Lotus-Eaters > wrote: > > >USA gun-related deaths are ~29k/year > > And my probability of being one of them is pretty low - because I am usually > armed ;) Yes, because firearm owners ALWAYS get the drop on the bad duys, and NEVER take one in the gut themselves. Also, they NEVER turn them on themselves, either accidentally or intentionally, or have their kids discover and accidentally discharge them, or have them stolen from them, or shoot or get shot by the wrong person, or the police, or their neighbor, etc. I looked up a bunch of statistics yesterday, and don't have time today. Suffice to say that the idea that owning a gun will give you a "low" probability of being killed by one, even discounting suicides, is far from obvious. -- Chad Netzer From llothar at web.de Wed Aug 27 18:57:30 2003 From: llothar at web.de (Lothar Scholz) Date: 27 Aug 2003 15:57:30 -0700 Subject: My future Python IDE article References: Message-ID: <6ee58e07.0308271457.7349086f@posting.google.com> "Ulrich Petri" wrote in message news:... > "David Mertz" schrieb im Newsbeitrag > news:mailman.1061920192.21278.python-list at python.org... > > Pythonistas, > > > > So c.l.py readers... make the case for your favorite one getting on the > > list. I have a while to ponder the opinions advanced, should this > > prompt some discussion (it may take a little while to order review > > copies of commercial tools and/or get things installed). > > > > You should definitely consider Boa-Constructor (be sure to use at least v. > 0.23, better yet the recent cvs version). > IMHO its the most "complete" python IDE at the moment. But not easy to use and with a lot of bugs. Maybe some less features and more stability would be nice. And it is not complete if you want to program Web Applications. From paddy3118 at netscape.netNOTthisBIT Sun Aug 24 21:20:40 2003 From: paddy3118 at netscape.netNOTthisBIT (Donald 'Paddy' McCarthy) Date: Mon, 25 Aug 2003 02:20:40 +0100 Subject: What needs to be in a macro capability! Message-ID: So, for those that don't actively not-want a Python macro facility. If we are to have it what should it do? 1) Macro definitions should allow Doc strings. 2) There should be a separate statement to import Macro definitions from another file. 3) Existing import of a module file containing module definitions should NOT cause the module files macros to be 'active' in the file that is importing. A new macro import command would be needed (or an extension of the existing import command to say that macro(s) are also imported and active. 4) An (annotated) dump of macro expanded source should be made available (by command line option). 5) It should not be the Lisp macro facility. 6) It should not be the C/C++ macro facility. 7) Macro definitions should be a distinctive new statement. 7) The scope of a macro definition should follow that of existing names I don't have an implementation though ;-) Pad. From peter at engcorp.com Thu Aug 7 11:51:42 2003 From: peter at engcorp.com (Peter Hansen) Date: Thu, 07 Aug 2003 11:51:42 -0400 Subject: Extracting a short using struct - won't print. References: <3f3273f7$0$10777$afc38c87@auth.uk.news.easynet.net> Message-ID: <3F32758E.5734C64F@engcorp.com> Graham Nicholls wrote: > > Thanks to Richard and Alex, I'm doing this: > > seg_stru=">BHH" > seg_data=self.fhand.read(struct.calcsize(seg_stru)) > data=struct.unpack(seg_stru,seg_data) > x=seg_data[1] > y=seg_data[2] Why are you unpacking the struct if you aren't going to use the unpacked data? > if debug: > print ("DEBUG: Image [%s] is [%d] by [%d] pixels" % (self.fname,x,y)) Best way to troubleshoot this kind of thing, in my experience, is to insert "import pdb; pdb.set_trace()" into the code just above the failing line, then use the debugger to inspect the values directly just before they are used. (You need to execute the "r" or "return" command immediately after the debugger is entered... the rest is pretty straightforward to learn.) -Peter From theller at python.net Thu Aug 14 13:17:14 2003 From: theller at python.net (Thomas Heller) Date: Thu, 14 Aug 2003 19:17:14 +0200 Subject: py2exe service and tool-tray app combined? In-Reply-To: <3F3A8371.840.20CD3615@localhost> (Brad Clements's message of "Wed, 13 Aug 2003 18:29:40 -0400") References: <3F3A8371.840.20CD3615@localhost> Message-ID: <1xvop3ad.fsf@python.net> "Brad Clements" writes: > Once again I apologize for posting this py2exe question in the ctypes list. ;-) In the long run, this will be the wrong forum. I suggest comp.lang.python (or should a py2exe mailing list be created?). And I'm cc'ing to python-list. > > I need to ship a Windows service in py2exe, but I also want a > tool-tray control application (I'll make with venster or win32gui) > > Naturally I want to save space. Can I do this with one .exe? > > It's not clear from the project page what gets executed when the > service .exe is run without -debug or -register. Well, you can try it out. But IIRC, nothing useful will happen. The service tries to start, but cannot because it cannot connect to the service manager (or something like that). > Can I have a single .py file that has win32serviceutil.ServiceFramework subclass and the usual > > if __name__ == "__main__": > > And if I do this, how do I handle -register and -unregister? I don't think so. But look into the C code run_svc.c to be sure. > Also, if anyone knows, I assume services don't run on 9x, so I want to 'simulate' a > service there by having the same .exe do all the work (and appear as a tooltray app), > so here's another reason for having one .exe > > Can it be done? > Not sure. Best would be to change the win32all serviceutil framework. But I'm not sure it makes sense nowadays - win98 is history. > -- > > And while I'm bugging the list, one thing I'd like to be able to do is > to split my application files into their own .zip distinct from 'the > python library .zip bolted onto the .exe'. Well, I have something for you. As time permits, I'm working on a new py2exe using the zipimport of Python 2.3. Still very much work in progress, and services are not yet supported, but it's already in CVS in a sandbox subdirectory. > That is, be able to define a group of .py files or packages that > should go into their own zip file outside the .exe, with that .zip > being inserted into sys.path before the .zip that's built into the > .exe This py2exe (optionally) allows to create a number of console, gui exe files, together with exe files implementing localserver and inproc COM servers. The exe (or dll) files only contain the main script, or a 'boot' script for the com and service. The remaining code is loaded from a shared zipfile. > > This way, when I want to ship an 'upgrade' I most likely only need to > send a small .zip file instead of a gigantic .exe > > So while declaring which packages or .py files are 'seperate' would be > a pain, I think this would be very handy for making easy-to-web-update > applications. > > Comments? This reminds me of how applications for Visual Smalltalk were distributed. We had a small exe of only a could of kilobytes, this was renamed into something like 'myapp.exe'. The classes neede were packed into .sll files - smalltalk link libraries. And you had to provide a 'myapp.bnd' file which listed all the .sll files needed by 'myapp.exe'. If you discovered a bug in an .sll file, you could either buid and distribute a new version of it, or you could create an additional, new .sll file containing the fixed methods. And you would make sure to list this new .sll in the myapp.bnd file, before the buggy one. This way the size of the upgrade could be kept as small as possible. Now, isn't this '.bnd' file mechanism also a nice idea for py2exe? Thomas From DLNXPEGFQVEB at spammotel.com Mon Aug 25 09:40:03 2003 From: DLNXPEGFQVEB at spammotel.com (Christos TZOTZIOY Georgiou) Date: 25 Aug 2003 06:40:03 -0700 Subject: Python preinstalled on Windows - looking for details References: Message-ID: <6f9e154b.0308250540.7781f2f5@posting.google.com> Skip Montanaro wrote in message news:... > Folks, > > It appears that HP and perhaps some other computer manufacturers who deliver > Windows systems have begun delivering systems with Python pre-installed. I found this on Google: http://wingide.com/pipermail/marketing-python/2003-February/001050.html but I couldn't find others (or another message by Kevin Altis) mentioning this. -- TZOTZIOY From tl_news at nexgo.de Mon Aug 4 09:56:48 2003 From: tl_news at nexgo.de (Tino Lange) Date: Mon, 04 Aug 2003 15:56:48 +0200 Subject: how to convert ip address to dot notation References: Message-ID: Ruslan Spivak wrote: > I have ip addresses in my mysql db in int value - 3232261127, for example. > How can i convert that to usual dot notation like 192.168.100.7? Hi Ruslan! The socket Module conatins some magic for that: >>> import socket, struct >>> socket.inet_ntoa(struct.pack('!L',3232261127L)) '192.168.100.7' Cheers Tino From p-abel at t-online.de Fri Aug 8 11:31:38 2003 From: p-abel at t-online.de (Peter Abel) Date: 8 Aug 2003 08:31:38 -0700 Subject: ???? i can`t understand it References: Message-ID: <13a533e8.0308080731.479966b2@posting.google.com> Sean 'Shaleh' Perry wrote in message news:... > On Friday 08 August 2003 01:11, Enrique wrote: > > >>> a=[1,2,3,4,5] > > >>> for b in a: > > > > ... a.remove(b) > > ... > > > > >>> a > > > > [2, 4] > > does this help?? > > >>> a = range(1,6) > >>> for b in a: > ... print b > ... a.remove(b) > ... > 1 > 3 > 5 > >>> a > [2, 4] > > I read this as "do not remove items from a list you are iterating over". > Pretty sure the docs comment on this as well. > > What seems to happen is b = 1, 1 is removed from a. b should then be 2. But > the internal counter skips it and goes to 3. So what i see happening is: > > next = 0 > for b = a(next): > a.remove(b) > next += 1 > > so a[1] is 3 when we expect it to be 2 because 2 is now at index a[0]. Or start removing from the end: >>> a=[1,2,3,4,5] >>> for i in range(len(a)-1,-1,-1): ... a.remove(a[i]) ... print a ... [1, 2, 3, 4] [1, 2, 3] [1, 2] [1] [] Regards Peter From heikowu at ceosg.de Mon Aug 4 13:07:00 2003 From: heikowu at ceosg.de (Heiko Wundram) Date: 04 Aug 2003 19:07:00 +0200 Subject: Classes in Python In-Reply-To: <14dsivkn40c0grotsti39cgsrde7v03hq4@4ax.com> References: <14dsivkn40c0grotsti39cgsrde7v03hq4@4ax.com> Message-ID: <1060016820.792.11.camel@d168.stw.stud.uni-saarland.de> On Mon, 2003-08-04 at 12:30, Wiebke P??tzold wrote: > class PatternFilter: > def _init_(self, pattern): > self.pattern = re.compile(pattern) Python special functions are always prefixed/postfixed by two underscores, so let this read __init__ > [snip] > vf = vw.filter(PatternFilter("Ge.*")) Moans here with a "__init__ takes only one argument, got two instead", when I try to run it. Next time you post code, read the error message, and this should've pointed you at the fact that _init_ isn't called, but __init__ is. When this was corrected, Metakit would've moaned that the filter wasn't callable, this would've made you look up the syntax for callable in the Python documentation http://www.python.org/doc/current/, which would've led you to the documentation on callable instances having a __call__ method. And so on. Next time you post something, please include the correct error message (this program doesn't run at all, of course this means it doesn't return anything, but the exception traceback would've been helpful), and having a look at the Python documentation before posting can't harm too... Heiko. From mis6 at pitt.edu Thu Aug 14 08:01:50 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 14 Aug 2003 05:01:50 -0700 Subject: 3 new slogans References: Message-ID: <2259b0e2.0308140401.3b268276@posting.google.com> Graham Fawcett wrote in message news:... > or, with apologies to Clarke, > > Any sufficiently advanced technology is indistinguishable from Python > This one is great! ;) M. From daniel.rawson.take!this!out! at asml.nl Wed Aug 6 08:00:39 2003 From: daniel.rawson.take!this!out! at asml.nl (Dan Rawson) Date: Wed, 06 Aug 2003 08:00:39 -0400 Subject: Checking for an "undefined" variable - newbie question In-Reply-To: References: Message-ID: Duncan Booth wrote: > Dan Rawson wrote in > news:bgqmce$qk3d1$1 at ID-122008.news.uni-berlin.de: > > >>I have only one (ugly) solution: >> >>try: >> variable >>except NameError: >> ... >> >>which works, but is a bit clumsy if I just want to know if the thing >>already exists. > > > You could check whether the name of the variable is present in 'locals', > 'globals', or 'vars' as appropriate: > > >>>>'variable' in vars() > > 0 > Ahhhh . . . . thanks! 'locals' and 'globals' I think I understand, but what's the scope for 'vars' ?? In the specific case in question, these are global variables, so it's relatively easy . . . . TIA . . . Dan From davesum99 at yahoo.com Tue Aug 12 11:53:17 2003 From: davesum99 at yahoo.com (dan) Date: 12 Aug 2003 08:53:17 -0700 Subject: Slogan: Getting Rich Overnight References: Message-ID: "Brandon J. Van Every" wrote in message news: At any rate, welcome to > my killfile. If knee-jerkism is the extent of your marketing analysis, I > surely don't need to hear about it. If everyone who disagrees with you is on your killfile, how will you have any fun arguing? I don't give a shit about you or your killfile, this is about what's good for Python. I'm not knee-jerk. I've run a public company worth $1B. I know marketing. I think you're wrong, period. You think you know more than you do. It's a great slogan for its target audience. I'm going to put it on a T-shirt for myself and see what kinds of reactions I get. -smy From furliz at libero.it Thu Aug 7 04:11:57 2003 From: furliz at libero.it (furliz) Date: Thu, 07 Aug 2003 10:11:57 +0200 Subject: Tkinter programming problem In-Reply-To: <2830c89c.0308040201.7c70695d@posting.google.com> References: <2830c89c.0308010048.403a2a19@posting.google.com> <2830c89c.0308040201.7c70695d@posting.google.com> Message-ID: <3F3209CD.5040701@libero.it> > I did try self.frame.destroy as the function > self.frame.destroy(), but the Quit button still didn't work. The > application can be closed via the window corner X, but I'm still > puzzled as to why it does not respond to Quit. > > Any more suggestions? why don't use 'sys.exit(0)' as command? Ex: quitButton = Button(root,text="Quit",command=sys.exit(0)) From __peter__ at web.de Thu Aug 21 06:21:37 2003 From: __peter__ at web.de (Peter Otten) Date: Thu, 21 Aug 2003 12:21:37 +0200 Subject: csv documentation error? (was Re: csv - howto specify fmtparam parameters) References: <3F44955C.3020206@igpm.rwth-aachen.de> Message-ID: Helmut Jarausch wrote: > still I am curious: is the documentation in error? Taken directly from csv.py: class DictReader: def __init__(self, f, fieldnames, restkey=None, restval=None, dialect="excel", *args): self.fieldnames = fieldnames # list of keys for the dict self.restkey = restkey # key to catch long rows self.restval = restval # default value for short rows self.reader = reader(f, dialect, *args) As there is no provision for keyword arguments in DictReader.__init__() as opposed to reader, it seems to be a bug that can be easily fixed: class DictReader: def __init__(self, f, fieldnames, restkey=None, restval=None, dialect="excel", *args, **kwd): self.fieldnames = fieldnames # list of keys for the dict self.restkey = restkey # key to catch long rows self.restval = restval # default value for short rows self.reader = reader(f, dialect, *args, **kwd) Peter From info at nyc-search.com Tue Aug 12 16:43:26 2003 From: info at nyc-search.com (NYC-SEARCH) Date: 12 Aug 2003 13:43:26 -0700 Subject: JOB: Python Technical Lead & Head of Data Quality Assurance, NYC Message-ID: If you are interested in a position, please review the requirements and reply with your salary requirement. My clients main concern with these positions is Python. Elaborating on your knowledge of Python when replying to me will greatly increase your chances of landing an interview. JOB #1: Python Technical Lead, New York, NY DETAILS: http://www.nyc-search.com/jobs/python.html JOB #2: Head of Data Quality Assurance, New York, NY DETAILS: http://www.nyc-search.com/jobs/headQA.html Thank you, Beau J. Gould Kandidates.com Python Jobs Yahoo Group >> http://groups.yahoo.com/group/pythonjobs From tyler at scalegen.com Sun Aug 3 00:25:57 2003 From: tyler at scalegen.com (Tyler Eaves) Date: Sun, 03 Aug 2003 00:25:57 -0400 Subject: Can't get dumb webcounter working References: Message-ID: On Sun, 03 Aug 2003 04:08:18 +0000, J. W. McCall wrote: > Sorry if this is OT, but here's my question: > > I wrote a simple python script to increment a counter in a text file, > and I wanted this script to be accessed whenever an HTML file is > accessed. The HTML files and python script are on a shell account on > UNIX a machine that has support for CGI, Python, etc. I unfortunately > don't know much about CGI, since I assume this is what I need to get > this to work. All I want to do is to get script to be called when the > web site is accessed and hopefully insert some output (a number) into > the HTML. > > Any advice, specific instructions, pointers to helpful web resources, or > recommendations to better newsgroups, if this is too OT here, would be > greatly appreciated. > > Thanks, > > J. W. McCall Server side includes? -- Visit my blog - http://blog.scalegen.com Music, Programming, and More. From edreamleo at charter.net Fri Aug 29 11:03:13 2003 From: edreamleo at charter.net (Edward K. Ream) Date: Fri, 29 Aug 2003 10:03:13 -0500 Subject: after, after_cancel and Python 2.3 Message-ID: Previous to Python 2.3 my app has destroyed the root Tk window using root.destroy rather than the more usual root.quit. In Python 2.3 this does not work so well. In some situations (i.e., for some data), Tk (not Tkinter) complains that an "after" routine does not exist that has been registered with the Tkinter after routine. Moreover, in Python 2.3, the tkinter after_cancel routine does not appear to work at all, regardless of whether root.destroy() or root.quit() follows after_cancel. When using root.quit(), the after routine is called properly, so no real harm is done. When using root.destroy(), it appears that Tkinter (or is it Tk) attempts to call the "after" routine after the "after" routine has already been destroyed. For example, the following code appears in my app's shutdown code: self.killed = true # Disable after events. # New for Python 2.3: attempt to cancel the after handler. if self.afterHandler != None: print "finishQuit: canceling",self.afterHandler self.root.after_cancel(self.afterHandler) self.afterHandler = None if 1: # Works in Python 2.1 and 2.2. Leaves Python window open. self.root.destroy() else: # Works in Python 2.3. Closes Python window. self.root.quit() In versions before Python 2.3 there was never any need for a call to root.after_cancel and the call to root.destroy never complained. In Python 2.3, the call to root.destroy() sometimes gives an error message like this: finishQuit: canceling after#18 >>> invalid command name "14189192callit" while executing "14189192callit" ("after" script) If my code calls self.root.quit() what happens is that the "after" routine is called, sees self.killed == true and returns. In other words, the self.killed hack allows the after routine to work around the fact that after_cancel has had no apparent effect. Can anyone see any obvious problem in my code? Here are the definitions of after and after_cancel in tkinter.py. This code has not changed between Python 2.2 and Python 2.3. def after(self, ms, func=None, *args): """Call function once after given time. MS specifies the time in milliseconds. FUNC gives the function which shall be called. Additional parameters are given as parameters to the function call. Return identifier to cancel scheduling with after_cancel.""" if not func: # I'd rather use time.sleep(ms*0.001) self.tk.call('after', ms) else: # XXX Disgusting hack to clean up after calling func tmp = [] def callit(func=func, args=args, self=self, tmp=tmp): try: func(*args) finally: try: self.deletecommand(tmp[0]) except TclError: pass name = self._register(callit) tmp.append(name) return self.tk.call('after', ms, name) def after_cancel(self, id): """Cancel scheduling of function identified with ID. Identifier returned by after or after_idle must be given as first parameter.""" try: data = self.tk.call('after', 'info', id) # In Tk 8.3, splitlist returns: (script, type) # In Tk 8.4, splitlist may return (script, type) or (script,) script = self.tk.splitlist(data)[0] self.deletecommand(script) except TclError: # print "ekr: tcl error" pass # print "ekr: calling cancel",id self.tk.call('after', 'cancel', id) The "disgusting" tmp hack does not appear in after_cancel. I'm not sure what this does, especially since tmp.append(name) would appear to have no effect because tmp is not a global. My guess is that if the hack is needed in one place it might be needed in another. Summary: For now I can just call root.quit and rely on the killed flag to keep the after routine out of trouble, but it does appear that something isn't quite right. Does anyone have a clue what is going on? Thanks. Edward P.S. My "after" routine is initially created with after_idle, and thereafter reposts itself with after. Like this: # An internal routine used to dispatch the "idle" hook. def idleTimeHookHandler(*args): a = app() if a.killed: # New for Python 2.3... print "idleTimeHookHandler: killed" return # ...Do stuff # Requeue this routine after 100 msec. if a.idleTimeHook: a.afterHandler = a.root.after(a.idleTimeDelay,idleTimeHookHandler) else: a.afterHandler = None EKR -------------------------------------------------------------------- Edward K. Ream email: edreamleo at charter.net Leo: Literate Editor with Outlines Leo: http://webpages.charter.net/edreamleo/front.html -------------------------------------------------------------------- From ialbert at mailblocks.com Mon Aug 18 21:10:57 2003 From: ialbert at mailblocks.com (Istvan Albert) Date: Mon, 18 Aug 2003 21:10:57 -0400 Subject: What's better about Rattlesnakes than Pythons? In-Reply-To: <8e482ba2.0308171939.7de4a288@posting.google.com> References: <8e482ba2.0308171939.7de4a288@posting.google.com> Message-ID: ForHimself Every Man wrote: > it seems that Rattlesnakes have the potential to compete with and > displace Pythons. I'm curious how evolution will play this out. I predict that in five years Rattlesnakes with a huge marketing muscle will totally completely squeeze out Pythons. Istvan. From ryanlowe0 at msn.com Wed Aug 20 18:07:23 2003 From: ryanlowe0 at msn.com (Ryan Lowe) Date: Wed, 20 Aug 2003 22:07:23 GMT Subject: if in for loop References: Message-ID: "Sean Ross" wrote in message news:sgM0b.2022$c_.87471 at news20.bellglobal.com... > "Ryan Lowe" wrote in message > news:vXB0b.126774$_R5.47942299 at news4.srv.hcvlny.cv.net... > > your complaint is this? > [snip code example] > > i agree its not as clear whats going on here as in the if example, but its > > no less readable than the list-comprehension version, i.e. msgs = ["%s > > %s"%(x,y) for x in words for y in otherwords] > > whats the argument? should they do away with double for's in list-comp? > > > Actually, I hadn't really formulated an argument. I'm indifferent to the > proposal, with some slight leaning towards non-acceptance (as my "-0" vote > suggests). I don't think I can justify why I don't care for the proposal. It > does seem reasonable. If your goal is to maintain consistency within the > language, then this proposal would seem to aid that goal. I also prefer that > a language provide consistency. The problem, I suppose, should you choose to > be consistent, is deciding in which direction to focus that consistency. > While I very much enjoy list comprehensions, and would prefer that they not > be removed from the language (read, "Never remove them from the language, > please!" and "Could we please have generator comprehensions, as well?"), I > also see that they are somewhat of an anomaly and that they can hinder > readability when they are allowed to grow without bound. Of course, the same > can be said for deeply nested for-loops - at some point, as you add more and > more for-loops, the meaning becomes less and less clear (which would be one > reason people refactor such things using functions). Anyway. I suppose the > question I was addressing in the earlier post was this: Does consistency, in > this instance, aid or hinder, and what does it aid or hinder. If we argue > that filtering should be added to the for-loop syntax because that syntax > should be more consistent with the list comprehension syntax, then it seems > reasonable to also argue for the inclusion of multiple for-expressions, on > the same basis (Is this argument fallacious? I'm not sure...looks like a > slippery-slope) . So, anticipating that others might make this argument once > one part of list comprehension syntax had been retro-fitted into the > existing for-loop syntax, it seemed reasonable to ask - do you also think > multiple for-expressions in a for-loop would be of benefit? Do you want only > the one and not the other? (False dichotomy?) If so, why? If not, why not? > These are topics you may wish to address, were you to write a PEP. As I've > said, I'm pretty much neutral towards the whole thing, with some tendency > towards caution. > > [snipped quote from John Roth posting] > > **harder** to read!? cmon now. i will buy its certainly not a necessary > > change, but harder to read... > > for x in X if condx(x) for y in Y if condy(y) for z in Z if condz(z) for w > in W if condw(w): > suite > > for x in X: > if condx(x): > for y in Y: > if condy(y): > for z in Z: > if condz(z): > for w in W: > if condw(w): > suite > > Neither strikes me as being particularly easier to read than the other. > > for x in X if condx(x): > suite > > for x in X: > if condx(x): > suite > > > Same thing here. > > > thanks for the reply. well put. i guess the tradeoff comes down to, on the one hand, added consistency and reduction of nesting layers, and on the other, going through the bother of implementing it. i can clearly see from the replies that programmer laziness and resistance to change has won :) so consider the issue dropped. From stefan.behrens.usenet at gmx.net Tue Aug 12 04:27:01 2003 From: stefan.behrens.usenet at gmx.net (Stefan Behrens) Date: Tue, 12 Aug 2003 10:27:01 +0200 Subject: BOA constructor and Python2.3/wxPython 2.4.1.2 Message-ID: Hi all, after upgrading to Python 2.3 and wxPython 2.4.1.2 the Traceback TAB in boa constructor seems to be broken. Did anyone else encounter the same problem? Any suggestion/workaround/fixes? br/Stefan. From mwh at python.net Tue Aug 5 11:51:03 2003 From: mwh at python.net (Michael Hudson) Date: Tue, 5 Aug 2003 15:51:03 GMT Subject: Capture PID of child process References: Message-ID: <7h365lc85p2.fsf@pc150.maths.bris.ac.uk> klappnase at web.de (klappnase) writes: > Hello, everyone, > > I am running python2.2.2 on a linux box. > I want to call a shell command and get the PID of this child process > so I have the possibility to abort the child process while it is still > running. > > I tried the popen2 module for that: > > self.pp = popen2.Popen3(cmd) > cmdpid = self.pp.pid > > However I found that the PID returned by self.pp.pid is not the PID of > the process of interest, but the PID of a subshell in which this child > process is running. > So if I do > > os.kill(cmdpid, 9) > > the subshell is killed, but the process I actually wanted to stop is > happily running on. > > Does anyone have a clue what to do about that? Any help would be very > appreciated. If you don't actually want to let a shell near your cmd string, you can pass a list of strings to popen2.Popen3's constructor, and then pp.pid will be the PID of the child process you're interested in. This doesn't seem to be documented anywhere! But you can read the source, I hope. Cheers, mwh -- 58. Fools ignore complexity. Pragmatists suffer it. Some can avoid it. Geniuses remove it. -- Alan Perlis, http://www.cs.yale.edu/homes/perlis-alan/quotes.html From spahievi at vega.bg Sun Aug 17 07:08:48 2003 From: spahievi at vega.bg (Niki Spahiev) Date: Sun, 17 Aug 2003 14:08:48 +0300 Subject: python for dev of CAD type software In-Reply-To: <836a2f21.0308162222.413fefaa@posting.google.com> References: <836a2f21.0308162222.413fefaa@posting.google.com> Message-ID: <8710461943.20030817140848@vega.bg> 8/17/2003, 9:22:04, Sanjay Minni wrote: SM> is python suitable for a production level SM> deployment of CAD type of software. For CAD/CAM look at www.vintech.bg -- Best regards, Niki Spahiev From stephen at hostwiththemost.net Mon Aug 18 15:26:14 2003 From: stephen at hostwiththemost.net (s) Date: 18 Aug 2003 12:26:14 -0700 Subject: Python newbie help Message-ID: <87fa5cfa.0308181126.c61bfa2@posting.google.com> Hi all, I've recently been very interested in learning Python but I seem to lack direction while reading the tutorials. I understand the syntax and everything concerning the language itself but the tutorials I have seen are merely displaying features of the language rather than teaching you to code while reaching an end goal of a program and I think that's been my problem with learning the language so slowly. Is anyone aware of an online tutorial with examples that actually end up creating a semi-useful program and not just snippets of code displaying how the code functions? Thanks From gh at ghaering.de Sun Aug 31 13:32:23 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Sun, 31 Aug 2003 19:32:23 +0200 Subject: SF deploys SA, lauds P & BC In-Reply-To: References: Message-ID: <3F523127.4020700@ghaering.de> Terry Reedy wrote: > In Friday's occasional newsletter to registerees, SourceForge > announced that it has deployed SpamAssassin (written in Python) [...] Is that rewrite of SpamAssassin from Perl in Python available somewhere? ;-) -- Gerhard From tim.one at comcast.net Mon Aug 11 16:24:23 2003 From: tim.one at comcast.net (Tim Peters) Date: Mon, 11 Aug 2003 16:24:23 -0400 Subject: Multi-Line Comment In-Reply-To: <16183.60370.315829.561941@montanaro.dyndns.org> Message-ID: [Skip Montanaro] > Nope, no multi-line comment. The python-mode package which is > available for Emacs and XEmacs supports commenting a block of text. > You can also use triple-quoted strings: > > """ > This is a multi- > line > comment > (sort of) > """ > > It gets evaluated but immediately popped from the execution stack. One of the previous times this came up, Guido suggested that the compiler could be changed to optimize away string expressions that aren't docstrings. It was then my task to fire up the time machine so that I could report that the compiler already did. It still does . That is, it doesn't get evaluated or popped -- it's not in the compiled code at all, so is exactly like a comment in that respect. From jjl at pobox.com Mon Aug 4 14:03:22 2003 From: jjl at pobox.com (John J. Lee) Date: 04 Aug 2003 19:03:22 +0100 Subject: Python and SSL References: Message-ID: <877k5ts3kl.fsf@pobox.com> Illo de' Illis writes: > While I was coding a software which needs to set up a SSL transaction > with a client using an underlying proprietary protocol, I found > that the _ssl module works only in SSL client mode. Moreover it is [...] Don't know if it does what you want, but have you found m2crypto? John From Juha.Autero at iki.fi Thu Aug 21 04:22:07 2003 From: Juha.Autero at iki.fi (Juha Autero) Date: Thu, 21 Aug 2003 11:22:07 +0300 Subject: What's better about Ruby than Python? References: Message-ID: <87k797ifo0.fsf@jautero.no-ip.org> Alex Martelli writes: > The counter-arguments you present in the following do not affect Mertz's > argument in the least, and thus cannot indicate why you don't find it > completely compelling. To rephrase David's argument: simplicity suggests > that a 'class' statement should always have the same fundamental semantics. > Since it SOMETIMES needs to bind a name, therefore, letting it ALWAYS > bind a name -- rather than sometimes yes, sometimes no, depending on > context -- is the only Pythonic approach. I think the problem here is same as with understanding Python variables and assignment. People think names as objects themself rather than bindings to an object. (Maybe I should have said "things" to avoid confusin. Though in Python, everything you can bind a name to is a Python object.) They think that after class foo: pass you get +-----+ | foo | +-----+ but in Python in reality you get +-----+ foo --> | | +-----+ So, in Python all objects are basically anonymous. They just have names bound to them. And since everything is an object, this goes for classes and functions, too. I'm not sure about modules though. -- Juha Autero http://www.iki.fi/jautero/ Eschew obscurity! From frank at chagford.com Mon Aug 18 10:08:39 2003 From: frank at chagford.com (Frank Millman) Date: 18 Aug 2003 07:08:39 -0700 Subject: Problem with garbage collection (sort of) Message-ID: <246a4e07.0308180608.2b8d685a@posting.google.com> Hi all I am writing a general accounting application. A user can log in to the application and stay there for a long time, maybe all day, moving around the menu system, selecting an item to perform a task, then returning to the menu and selecting another item. I want to ensure that each item selected cleans itself up correctly when it is completed. My worry is that if I do not do this, the number of 'dirty' items will accumulate in memory and will cause performance to suffer. I have come across a situation where a number of instances created by an item are not deleted when the item has completed. It took me a long time to identify what was actually happening, but now that I have identified it, the 'fix' that I have come up with is rather ugly. Below is a very artificial example to explain the scenario. Should I worry about this, or is the performance hit negligible? Assuming that I should worry about it, can anyone suggest a better solution? It may be that the problem is caused by bad design, in which case I may follow this up with more details, to see if anyone can come up with a better approach. #------------------------------------------------------ class a: def __init__(self,b): self.b = b print 'a created' def __del__(self): print 'a deleted' class b: def __init__(self): self.p = [] e = a(self) self.p.append(e) print 'b created' def __del__(self): print 'b deleted' class c: def __init__(self): self.f = b() print 'c created' def __del__(self): # del self.f.p print 'c deleted' y = c() #del y.f.p #-------------------------------------------- y is an instance of class c, which creates an instance of class b, which creates an instance of class a. When y goes out of scope and is deleted, I want the instances of class b and class a to be deleted as well. The problem is that class a keeps a reference to class b (self.b) and class b keeps a reference to class a (self.p), so the reference counts do not go down to zero without some additional action. I have 2 possible solutions - the two commented-out lines. If either of these lines are uncommented, all instances are deleted. The ugliness is that p is internal to class b - neither class c nor the main application requires any knowledge of it. However, my solution requires one or the other to explicitly delete it. Any advice will be much appreciated. Many thanks Frank Millman From srijit at yahoo.com Thu Aug 14 13:55:37 2003 From: srijit at yahoo.com (srijit at yahoo.com) Date: 14 Aug 2003 10:55:37 -0700 Subject: Tkinter program crashes Message-ID: <221d8dbe.0308140955.658000d0@posting.google.com> Hello, Any idea - why the following code crashes on my Win 98 machine with Python 2.3? Everytime I run this code, I have to reboot my machine. I also have Win32all-157 installed. from Tkinter import * class App: def __init__(self, master): frame = Frame(master) frame.pack() self.button = Button( frame, text="QUIT", fg="red", command=frame.quit ) self.button.pack(side=LEFT) self.hi_there = Button(frame, text="Hello", command=self.say_hi) self.hi_there.pack(side=LEFT) def say_hi(self): print "hi there, everyone!" root = Tk() app = App(root) root.mainloop() Regards, Srijit From timfm at hawaii.rr.com Fri Aug 1 15:31:45 2003 From: timfm at hawaii.rr.com (Timothy Martens) Date: Fri, 01 Aug 2003 09:31:45 -1000 Subject: Problem with Unzipping/Installing Python-2.3.exe Message-ID: <3F2AC021.3060402@hawaii.rr.com> Hi John, We're in the same boat. I too am having trouble with the win installer. It's just not working. This is also my first attempt(s) to install Python. I'm running windows 2K. What version are you on? I sent a mesage to the list earlier (subject: 2.3 win installer, "Anyone having problems with the 2.3 win installer? I'm running win2k pro (sp4) and the installer is freezing after the initial dialogues, just as the install starts.") -- but haven't got any feedback. I think maybe most of the people on the list are running Unix? Can someone help us pathetic windows users? Regards, tim. From bokr at oz.net Fri Aug 15 16:32:05 2003 From: bokr at oz.net (Bengt Richter) Date: 15 Aug 2003 20:32:05 GMT Subject: Eight Queens Puzzle by Magnus Lie Hetland References: <215fa0fc.0308130557.7f1c950b@posting.google.com> <3f3c1007$0$177$a1866201@newsreader.visi.com> <3F3CC067.5010102@users.ch> Message-ID: On Fri, 15 Aug 2003 13:13:43 +0200, Borcis wrote: >Grant Edwards wrote: > >>>BTW, my version got all 92 solutions in < 155ms on a 300mhz P2 without >>>attempting to optimize ;-) (just the call to doqueens that is, not including >>>import time). >> >> >> Someday I want to modify it to keep a list of solutions and eliminating all >> the ones that are mirror images or rotations. > >This will give you 12 solutions, one of which possesses an internal >2-fold symmetry, so 92 = 11*8 + 1*8/2. > This version discovers the 12 unique ones: (not too tested, and probably has some redundancies ;-) This one does use generators ;-) ====< queens.py >======================================================== """ bitmap of board 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 """ threatfrom = {} queenat = {} for row in xrange(8): for col in xrange(8): queenat[row,col] = 1L<<(8*row+col) threat = 0L for r in xrange(8): for c in xrange(8): if r==row or c==col or abs(r-row)==abs(c-col): threat |= 1L<<(8*r+c) threatfrom[row,col] = threat def printsol(sol): for row in range(8): for col in range(8): print '+Q'[(sol>>(row*8+col))&1], print def solok(sol): """check that each queen doesn't threaten the rest""" for row in range(8): for col in range(8): if (sol>>(row*8+col))&1: q = 1L<<(row*8+col) if (sol^q) & threatfrom[row,col]: return False return True def doqueens(): solutions = [] def tryplace(board, row, cols): for col in cols: if (board&threatfrom[row,col]): continue qboard = board|queenat[row,col] if row<7: xcols = cols[:] xcols.remove(col) tryplace(qboard, row+1, xcols) else: solutions.append(qboard) tryplace(0L, 0, range(8)) return solutions rotates = ( ((lambda r,c:(c, 7-r )), 'R+90'), # old->ccw->new ((lambda r,c:(7-c, r )), 'R-90'), # old->cw->new ((lambda r,c:(7-r, 7-c )), 'R+-180'), ) flips = ( ((lambda r,c:(r, 7-c )), 'E-W'), ((lambda r,c:(c, r )), 'NE-SW'), ) def combo(): for flip in flips: yield flip for rot in rotates: yield rot for flip in flips: for rot in rotates: label = '%s, %s'%(flip[1],rot[1]) def f(r,c,flip=flip[0], rot=rot[0]): return rot(*flip(r,c)) yield f, label def transforms(sol): for fliprot, label in combo(): board =0L for r in range(8): for c in range(8): if sol&queenat[r,c]: board |= queenat[fliprot(r,c)] yield board, label if __name__ == '__main__': solutions = doqueens() unique = {}; transformed = {} iunique=0 for sol in solutions: if sol in unique or sol in transformed: continue iunique+=1 unique[sol]=iunique for tsol, label in transforms(sol): if tsol in transformed: continue transformed[tsol] = sol,label loop = '' iunique = 0 for iorig, sol in enumerate(solutions): assert solok(sol) # just for warm fuzzies if loop in ['', 'a']: if sol in unique: iunique+=1 print '\n====[ Unique Solution %s (orig %s/92) ]====[ bitmap %X ]====\n'%( unique[sol], iorig+1, sol) printsol(sol) else: usol, label = transformed[sol] print '\n====[ Orig solution %s/92 is unique solution %s transformed %s ]====\n'%( iorig+1, unique[usol], label) if loop=='': loop ='x' while loop not in ['','a','q','t']: loop = raw_input('\nPress Enter for another, a for all, t for transform, q to quit: ') if loop=='t': print '\n Original solution # %s/92:\n'%(iorig+1) printsol(sol) print '\n ... is the following unique solution %s transformed by %s:\n'%( unique[usol], label) printsol(usol) loop = '' if loop =='q': break ========================================================================= Regards, Bengt Richter From grante at visi.com Mon Aug 25 16:20:57 2003 From: grante at visi.com (Grant Edwards) Date: 25 Aug 2003 20:20:57 GMT Subject: python gripes survey References: <78kkkvg8ckfio141es2of1p483ohbtbit5@4ax.com> <3rokkvckckdj6b679164jdnvqlbcfic67j@4ax.com> Message-ID: <3f4a6fa9$0$167$a1866201@newsreader.visi.com> In article , Jordan Krushen wrote: > On Mon, 25 Aug 2003 19:45:10 GMT, Afanasiy wrote: > >> Yes, returning multiple values, ie. tuples, is useful, but using them as >> you would use structs in C is common and the root of my gripe. The >> problem >> I explained above has nothing to do with the code you write. The problem >> is knowing what integer position in the tuple represents what field. In C >> structs have named fields, but in Python tuple have integer fields. The >> meaning of tuple integer fields, for tuples used this way, is only known >> in the documentation, not the code directly. > > I agree here. Returning tuples is only useful when very few > arguments are being returned. In my experience, two is the maximum useful value. I don't have t0o much trouble remembering the order of a pair of returned values, but with three or more, I often get it wrong. -- Grant Edwards grante Yow! I'd like MY data-base at JULIENNED and stir-fried! visi.com From eric.brunel at pragmadev.com Thu Aug 14 11:13:05 2003 From: eric.brunel at pragmadev.com (Eric Brunel) Date: Thu, 14 Aug 2003 17:13:05 +0200 Subject: Python/Tkinter/tk crash [long] References: Message-ID: Martin Franklin wrote: > On Thursday 14 August 2003 10:10 am, Eric Brunel wrote: > >>Hi all, >> >>I was creating a Tkinter widget in the style of the reversed tabs below >>Excel worksheets and I stepped in a serious problem: the code I made makes >>python crash with a seg fault, bus error or X11 BadGC error on both Solaris >>(2.6 and 2.7) and Linux (Mandrake 8.0); it doesn't crash on Windows. I >>tried to simplify the script, but I couldn't reproduce the crash with a >>simpler code. So the code below is somewhat long; sorry for that. > > > > Eric, > > Have you looked at Pmw (Python Mega Widgets) they have a NoteBook (tabbed > pane) widget that looks like what you want... I do know and use extensively this package. The behaviour I'd like to implement is somewhat different than the one in Pmw.NoteBook. Please also note that despite its length, the code I posted is only an extract of the actual code. Thanks anyway. -- - Eric Brunel - PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com From jjl at pobox.com Wed Aug 20 19:00:30 2003 From: jjl at pobox.com (John J. Lee) Date: 21 Aug 2003 00:00:30 +0100 Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> <6dj2kv8ugkieehs7guh786cl40o5lj6mcs@4ax.com> Message-ID: <87zni4ylwx.fsf@pobox.com> Doug Tolton writes: [...] > Don't introduce a feature because it would be so cool that everyone > would use it? That's just plain weird. [...] Sounds like you'd like Perl. Seriously. John From aahz at pythoncraft.com Sat Aug 30 15:54:42 2003 From: aahz at pythoncraft.com (Aahz) Date: 30 Aug 2003 15:54:42 -0400 Subject: Open Source leader? (was Re: Celebrity advice) References: <23891c90.0308280317.ac68b38@posting.google.com> Message-ID: In article , A.M. Kuchling wrote: > >The best candidate is Bruce Perens, IMHO. He has the technical >background of working on a non-trivial project (Debian), yet >writes and presents in a style that doesn't attract attention and >doesn't let irrelevancies intrude. Compare his commentary on SCO >(http://www.perens.com/SCO/SCOSlideShow.html) with ESR's counterblast. >(To be fair, ESR's analysis of the code is also pretty good; the OSI >letter is where it becomes unacceptable.) OTOH, Perens is also (like me ;-) a self-described asshole. When I saw him at the Waterside Conference earlier this year, he basically claimed that only assholes could make significant progress in the Open Source community. Linus and Guido are obvious counter-examples in some respects, but as you point out, they're not really interested in a spokesmodel position. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From gerrit at nl.linux.org Thu Aug 28 02:14:15 2003 From: gerrit at nl.linux.org (Gerrit Holl) Date: Thu, 28 Aug 2003 08:14:15 +0200 Subject: learning to program In-Reply-To: References: <3F4CED6E.D04D35D6@engcorp.com> <5bspkv87u1q0v9aupajrrkjuutuh3f5o44@4ax.com> <3F4CF363.CAF6A14E@engcorp.com> <6b2qkv4nf549o8clg3bagphd02f92dadub@4ax.com> <3F4D0AD6.1CE798D2@engcorp.com> Message-ID: <20030828061415.GA2694@nl.linux.org> Rich wrote: > I am going through one of the tutorials on the Python site and have > ran into a problem. > > During the tutorial it talked about TCI, and gave some commands to do. > I went to the site and downloaded TCI. but was unable to do any of > the tasks. > > I think my question is, when the tutorial say the Dos prompt, do I use > my Dos prompt in windows, or the Dos prompt in the Python program? The dos prompt in Windows (or Dos). Please note that there is also a tutor mailing list, designed to help new programmers. You may get a quicked answer there. Gerrit. -- 202. If any one strike the body of a man higher in rank than he, he shall receive sixty blows with an ox-whip in public. -- 1780 BC, Hammurabi, Code of Law -- Asperger Syndroom - een persoonlijke benadering: http://people.nl.linux.org/~gerrit/ Het zijn tijden om je zelf met politiek te bemoeien: http://www.sp.nl/ From jjl at pobox.com Sun Aug 3 07:13:50 2003 From: jjl at pobox.com (John J. Lee) Date: 03 Aug 2003 12:13:50 +0100 Subject: looking for design pattern name References: <87adaud0he.fsf@pobox.com> Message-ID: <877k5vyowh.fsf@pobox.com> "Andrew Dalke" writes: [...] > Quoting from the docs, > exception TypeError > Raised when a built-in operation or function is applied to an object of > inappropriate type. The associated value is a string giving details about > the type mismatch. > > In addition to your comments, this is not a built-in operation, so it's > the wrong exception. [...] Hmm, I don't think that's what the docs meant to communicate -- you're allowed to use it in your non-builtin code. At least, that's what I've always assumed: def isstringlike(x): try: x+"" except: return False else: return True class Foo: def __init__(self, stringy): if not isstringlike(stringy): raise TypeError("stringy must be string-like") I don't see anything in that documentation that says that's bad. John From robin at jessikat.fsnet.co.uk Sat Aug 2 12:31:00 2003 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Sat, 2 Aug 2003 17:31:00 +0100 Subject: boost python & 2.3 Message-ID: I'm having trouble building boost python with Python 2.3 & msvc. I don't remember this with 2.2.3 so I guess it must be related to 2.3. I'm seeing lots of this C:\Python\devel\boost_1_30_0\boost/detail/ob_call_traits.hpp(89) : see declaration of 'call_traits_chooser' C:\Python\devel\boost_1_30_0\boost/detail/ob_call_traits.hpp(90) : error C2059: syntax error : '{' C:\Python\devel\boost_1_30_0\boost/detail/ob_call_traits.hpp(90) : error C2143: syntax error : missing ';' before '{' C:\Python\devel\boost_1_30_0\boost/detail/ob_call_traits.hpp(93) : error C2143: syntax error : missing ';' before '{' C:\Python\devel\boost_1_30_0\boost/detail/ob_call_traits.hpp(94) : error C2955: 'type' : use of class template requires template argument list Any ideas? -- Robin Becker From staschuk at telusplanet.net Sun Aug 10 02:50:35 2003 From: staschuk at telusplanet.net (Steven Taschuk) Date: Sun, 10 Aug 2003 00:50:35 -0600 Subject: exec(), execfile() and local-variable binding? In-Reply-To: ; from jonaomi@excite.com on Sat, Aug 09, 2003 at 04:19:27PM -0700 References: Message-ID: <20030810005035.A436@tibia.amotlpaa.bogus> Quoth Jonathan: [...] > Well, that's understandable. But what I find strange is that exec() > *doesn't* work in this way. Consider this version: > > # main_exec.py > def f() : > exec("x = 1") > print "x:", x Note that exec is a keyword, not a function; you might as well write exec 'x = 1' I'm not just picking a nit here -- it is important for your question that exec is a keyword, since this means it is possible to determine at compile-time whether exec is used in the body of a function. This is quite unlike calls to built-in functions such as execfile(), which cannot in general be identified as such at compile-time. As you noted, in the presence of exec statements, the compiler abandons the optimization by which LOAD_NAMEs are replaced with LOAD_GLOBALs. This optimization normally speeds up variable access by skipping a futile name lookup in the locals; abandoning this optimization when there are exec statements makes your example above work in the obvious and desired way. -- Steven Taschuk staschuk at telusplanet.net "I tried to be pleasant and accommodating, but my head began to hurt from his banality." -- _Seven_ (1996) From irmen at -NOSPAM-REMOVETHIS-xs4all.nl Sun Aug 10 18:16:29 2003 From: irmen at -NOSPAM-REMOVETHIS-xs4all.nl (Irmen de Jong) Date: Mon, 11 Aug 2003 00:16:29 +0200 Subject: Python's biggest compromises In-Reply-To: References: <899f842.0307310555.56134f71@posting.google.com> Message-ID: <3f36c43a$0$49105$e4fe514c@news.xs4all.nl> Robin Becker wrote: > I'm not an expert, but the various grid computation schemes seem to > prefer either java or c/c++, I suspect that those schemes aren't really > using threads in main, after all they seem to be running between > machines in different parts of the world even. I suspect Python would be > in better shape if we could migrate threads or tasklets from one > processor to another. > > I believe pyro can almost do that, but I haven't tried it. Could you please elaborate on this a bit? What exactly did you have in mind when talking about "migrating threads or tasklets" ? Does this involve transporting code across nodes, or only the 'execution' (and data)? Pyro supports transporting code, but with a few important limitations, such as "once loaded, not reloaded". --Irmen de Jong From eric.brunel at pragmadev.com Mon Aug 11 11:46:14 2003 From: eric.brunel at pragmadev.com (Eric Brunel) Date: Mon, 11 Aug 2003 17:46:14 +0200 Subject: CLI+GUI References: <2259b0e2.0308080948.5a95e383@posting.google.com> <2259b0e2.0308090530.7519f195@posting.google.com> <2259b0e2.0308110517.7c4fa8c8@posting.google.com> Message-ID: Cousin Stanley wrote: > Michele .... > > I experience hangs with SIMPLE Python/Tk scripts > regularly using Windows 98 and this has been > a source of much frustration, almost to the point > of giving up on Tk .... Same problem, different solution: it made me give up on Windows 98... ;-) FYI, and just to make this post a bit more useful, it seems to be a problem in Windows 95/98, since no problem ever occured with the same scripts/distros on Win2k or WinXP, not to mention Unices... -- - Eric Brunel - PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com From mwh at python.net Thu Aug 21 13:12:28 2003 From: mwh at python.net (Michael Hudson) Date: Thu, 21 Aug 2003 17:12:28 GMT Subject: Misleading description of [i:j:k] slicing? References: Message-ID: <7h33cfv2az7.fsf@pc150.maths.bris.ac.uk> Raoul Gough writes: > As of Python 2.3, Section 2.2.6 (Sequence Types) describes slices > which have a specified step (to omit some indexes in beteween), using > the notation s[i:j:k]. The note about how this works says: > > "The slice of s from i to j with step k is defined as the sequence > of items with index x = i + n*k such that 0 <= n < abs(i-j). [...]" > > Seems to me that "0 <= n < abs(i-j)" is wrong, since the range of n > gets multiplied by k. How about "0 <= n < abs(k*(i-j))"? But you're right, what's there is a bit wrong. It's surprisingly hard to get this written down well. The idea's not that hard, but a terse explanation is surprisingly hard (when you start omitting values it gets even more fun!). Please submit a patch (assign it to me if you like -- the above passage is my fault). Cheers, mwh -- This same programmer had worked for the military, and therefore had access to weapons-grade cursing technology. -- Matt Roberds, asr From mpeuser at web.de Sat Aug 16 03:05:45 2003 From: mpeuser at web.de (Michael Peuser) Date: Sat, 16 Aug 2003 09:05:45 +0200 Subject: cPickle alternative? References: Message-ID: Hi Drochem, (1) Your dataset seems to break the binary cPickle mode ;-) (I tried it with the "new Pickle" in 2.3 - same result: "EOF error" when loading back...) May be there is someone interested in fixing this .... (2) I run your code and - as you noticed - it takes some time to *generate* the datastructure. To be fair pickle has to do the same so it cannot be *significantly* faster!!! The size of the file was 5,5 MB (3) Timings (2.2): Generation of data: 18 secs Dunping: 3,2 secs Loading: 19,4 sec (4) I couldn't refrain from running it under 2.3 Generation of data: 8,5 secs !!!! Dumping: 6,4 secs !!!! Loading: 5,7 secs So your programming might really improve when changing to 2.3 - and if anyone can fix the cPickle bug, protocol mode 2 will be even more efficient. Kindly Michael "Drochom" schrieb im Newsbeitrag news:bhjn6v$pi8$1 at nemesis.news.tpi.pl... > [....] > TRY THIS: > > import cPickle as Pickle > from time import clock > from random import randrange > > > x=[] > > for i in xrange(20000): > c = [] > for j in xrange(randrange(2,25)): > c.append((chr(randrange(33,120)),randrange(1,100000),randrange(1,3))) > c = tuple(c) > x.append(c) > if i%1000==0: print i #it will help you to survive waiting... > print len(x), "records" > > t0=clock() > f=open ("test","w") > Pickle.dump(x,f,0) > f.close() > print "out=", clock()-t0 > > > t0=clock() > f=open ("test") > x=Pickle.load(f) > f.close() > print "in=", clock()-t0 > > Thanks once again:) > > > From bhv1 at psu.edu Fri Aug 1 12:31:28 2003 From: bhv1 at psu.edu (Brian Victor) Date: Fri, 01 Aug 2003 16:31:28 GMT Subject: curses and use_default_colors() References: <7652139e.0307291843.2ade58c6@posting.google.com> Message-ID: A.M. Kuchling wrote: > On Wed, 30 Jul 2003 17:34:29 GMT, > Brian Victor wrote: >> {"use_default_colors", pyuse_default_colors, METH_VARARGS, > Use METH_NOARGS instead of METH_VARARGS; as written, this code will accept [snip] OK, I made this change on my local copy. > I'll add this function to the curses module, so at least it'll be in 2.4; Great, thanks! Note that this is an ncurses extension, so it won't link with plain old curses. I don't know if that's really an issue nowadays or not. Also, if you're looking for things to be complete, adding assume_default_colors would be a good idea. But that might require changing init_pair to allow -1 for foreground/packground parameters. > thanks for writing it. Anyone know if it's possible to test it on MacOS X? > Does the Terminal support transparency? Interestingly, both Terminal and iTerm seem to make everything transparent, so use_default_colors has no significant effect. That is, a black background is indistinguishable from a transparent/default background. -- Brian From hokiegal99 at hotmail.com Wed Aug 27 20:54:06 2003 From: hokiegal99 at hotmail.com (hokiegal99) Date: Wed, 27 Aug 2003 20:54:06 -0400 Subject: Script Discussion & Critique References: <3F4D31B1.6080802@hotmail.com> <06eqkv4onjh5m4tcbbqkmh8lscaj5niatp@4ax.com> <3F4D4402.3060209@hotmail.com> Message-ID: <3F4D52AE.8000203@hotmail.com> Something odd that I've discovered about this script is that it won't replace strings at the far left side of a text file *unless* the string has one or more spaces before it. For example: THIS (won't be replace with THAT) THIS (will be replaced with THAT) THIS (will be replaced with THAT) THIS (will be replaced with THAT) > #Thanks to comp.lang.python > import os, string > print " " > print "******************************************************" > print " Three Easy Steps to a Recursive find and Replace " > print "******************************************************" > print " " > x = raw_input("1. Enter the string that you'd like to find: ") > print " " > y = raw_input("2. What would you like to replace %s with: " %x) > print " " > setpath = raw_input("3. Enter the path where the prgroam should run: ") > print " " > for root, dirs, files in os.walk(setpath): > fname = files > for fname in files: > inputFile = file(os.path.join(root,fname), 'r') > data = inputFile.read() > inputFile.close() > search = string.find(data, x) > if search >=1: > data = data.replace(x, y) > outputFile = file(os.path.join(root,fname), 'w') > outputFile.write(data) > outputFile.close() > print "Replacing", x, "with", y, "in", fname > print " " > print "**********" > print " Done " > print "**********" > print " " > From davecook at nowhere.net Wed Aug 27 16:36:19 2003 From: davecook at nowhere.net (David M. Cook) Date: Wed, 27 Aug 2003 20:36:19 GMT Subject: Python PostgreSQL frontend for Win2K with MinGW32 ? References: <3f4cfee5_2@mk-nntp-1.news.uk.worldonline.com> Message-ID: <7D83b.45228$0u4.40952@news1.central.cox.net> In article <3f4cfee5_2 at mk-nntp-1.news.uk.worldonline.com>, Dave Haynes wrote: > I've been trying to port the psycopg interface to a Win2K client > (server runs FreeBSD). I'm using MinGW32 rather than CygWin, and having > trouble compiling the libpg library as a DLL. Have you tried any of these? http://www.stickpeople.com/projects/python/psycopg/ There are also pyPgSQL win32 binaries at http://pypgsql.sf.net Dave Cook From simon_place at whsmithnet.co.uk Sat Aug 30 08:27:26 2003 From: simon_place at whsmithnet.co.uk (simon place) Date: Sat, 30 Aug 2003 13:27:26 +0100 Subject: file object, details of modes and some issues. In-Reply-To: <3F4B9FB4.6AB14581@engcorp.com> References: <3f4b800f_3@mk-nntp-1.news.uk.worldonline.com> <3F4B9FB4.6AB14581@engcorp.com> Message-ID: <3f509832_2@mk-nntp-1.news.uk.worldonline.com> Peter Hansen wrote: > simon place wrote: > >> 'b', all modes can have a 'b' appended to indicate binary mode, i think this >>is something of a throw-back to serial comms ( serial comms being bundled into >>the same handlers as files because when these things were developed, 20+ years >>ago, nothing better was around. ) > > > It has nothing to do with serial communications, AFAIK. > > perhaps too big a leap in one go, how about text file -> ascii file -> control codes -> teletype -> serial comms ( never noticed how ascii characters below 32 have serial comms references.) >>Binary mode turns off the 'clever' handling >>of line ends and ( depending on use and os ) other functional characters ( >>tabs expanded to spaces etc ), the normal mode is already binary on windows so >>binary makes no difference on win32 files. > > > I think this is mostly wrong. The normal mode on windows is *text*, not > binary, so it very much makes a difference. Also, I've never heard > of binary mode having *any* effect on tabs, spaces, etc., other than > the newline character(s), so could you please provide a reference. Or > was this supposition on your part? > > No, what i said was that binary mode does NOT do things. on windows, and msdos, files seem to be handled more separately to serial comms than on some other systems and so files bypass any control code processing , that's why i said its effectively already binary mode for files. But generally using binary mode is more compatible, although i understand the reasoning which makes someone think that text mode was more x-platform. >>But since in may do on other >>o.s.'s, ( or when actually using the file object for serial comms.) i think >>you should actually ALWAYS use the binary version of the mode, and handle the >>line ends etc. yourself. > > > Your program will not be portable if you do this. Use text mode on text > files and binary mode on binary files. Understand the difference, so you > know when to use which. > > i don't think i'm the one with a shallow grasp of these things. but, to be helpful, how about you come up with an example of when 'text' mode as opposed to 'binary and handle the line end', is helpful for portability. >>suffice to say, i wasn't entirely impressed with the python file object > > > Where is your programming background from? I've never used a language where > the "file object" or equivalent did anything more than, let alone even as much as, > the Python file object. (Not intended as an insult, just pure curiosity.) > never heard of VB., open 'file' for random access lock write #1 python,ind.comms,web,databases,java,vb,windows,fortran,pascal,msdos,8086,z80,6502 I've seen all sorts of changes made to sequential data because of control codes. Although most file systems have lost virtually all the processing effects, for compatibility and flexibility, use binary, and handle the line ends. >>i remembered the cross platform problems its dealing with and all >>the code that works ok with it, and though i'd knock up this post of my >>findings to try to elicit some discussion / get it improved / stop others >>making mistakes. > > > A laudable goal. Let the discussion ensue! :-) > > -Peter From gh at ghaering.de Sun Aug 3 09:11:45 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Sun, 03 Aug 2003 15:11:45 +0200 Subject: PyChecker work with Python 2.3? In-Reply-To: <3F2CBCC2.3FC51D57@easystreet.com> References: <3F2C5300.FA223CBA@easystreet.com> <3F2CBCC2.3FC51D57@easystreet.com> Message-ID: <3F2D0A11.3090607@ghaering.de> achrist at easystreet.com wrote: > Gerhard H?ring wrote: >>achrist at easystreet.com wrote: >> >>>The pychecker site says that pychecker works with versions >>>1.5 through 2.2. Any reason to expect that 2.3 breaks it? >>>Anyone tried it to see? >> >>Why don't *you*? > > Smart people learn from their mistakes. Very smart people > learn from other people's mistakes. If you think you are so smart, why don't you use your time more economically then and just try it out? -- Gerhard From osuchw at ecn.ab.ca Wed Aug 27 11:59:18 2003 From: osuchw at ecn.ab.ca (Waldemar Osuch) Date: 27 Aug 2003 08:59:18 -0700 Subject: My future Python IDE article References: Message-ID: mertz at gnosis.cx (David Mertz) wrote in message news:... > > > So c.l.py readers... make the case for your favorite one getting on the > list. I have a while to ponder the opinions advanced, should this > prompt some discussion (it may take a little while to order review > copies of commercial tools and/or get things installed). One should not forget about Boa Constructor (http://boa-constructor.sourceforge.net/). It is very feature rich. - it is not only editor/debugger but also GUI builder. - integrates with exisiting Python tools like PyChecker, Bicycle Repair Man, cyclops etc. - automatically generated documentation and UML view. - Zope debugger. It is also crossplatform Waldemar Osuch From Dick.Zantow at lexisnexis.com Wed Aug 27 12:33:00 2003 From: Dick.Zantow at lexisnexis.com (rzed) Date: Wed, 27 Aug 2003 12:33:00 -0400 Subject: Celebrity advice (was: Advice to a Junior in High School?) References: <3F4CD2A2.DE7D05D2@engcorp.com> Message-ID: Peter Hansen wrote: > Terry Reedy wrote: >> >> (I think it safe to say that during the 20th century, 99% of the >> 100s of millions of murders were committed by armed govern-men >> rather than by private persons acting alone.) > > It may be safe to say it, but is it true, or merely hyperbole? > > Were there "100s of millions of murders" in the 20th century, > assuming commonplace definitions of "murder" (killing humans), > "million" (10 to the 6th power), and "20th century" (period > beginning roughly January 1, 1900 and ending on or one year before > December 31, 2000)? > > That's a lot of people getting themselves killed, whatever the > cause... > A little overstated, maybe. One site estimates about 147 million, and its estimates run a little higher than some others. If war casualties includes deaths by starvation and the like, and if war casualties are murder victimes, then it runs reasonably close. On the other hand, claims that more Americans have been killed by domestic gun violence between 1979 and 1997 than in battle in all the wars in which America was involved. Their estimates for the civil war seem low to me, but of course that preceded the 20th century anyway. -- rzed From jepler at unpythonic.net Thu Aug 14 09:49:25 2003 From: jepler at unpythonic.net (Jeff Epler) Date: Thu, 14 Aug 2003 08:49:25 -0500 Subject: Python/Tkinter/tk crash [long] In-Reply-To: References: Message-ID: <20030814134924.GB16941@unpythonic.net> I can duplicate the signal 11 on RedHat Linux 9 and the following relevant packages installed: python-2.2.2-26 tcl-8.3.5-88 tk-8.3.5-88 My traceback looks like the following. I believe that the lines listed as "Tk_GetItemTypes" actually correspond to static functions defined in tkCanvas.c. #0 0x4011b1a7 in Tk_GetItemTypes () from /usr/lib/libtk8.3.so #1 0x4011aec1 in Tk_GetItemTypes () from /usr/lib/libtk8.3.so #2 0x4011ac25 in Tk_GetItemTypes () from /usr/lib/libtk8.3.so #3 0x400d1a7c in Tk_HandleEvent () from /usr/lib/libtk8.3.so #4 0x400d1e7c in TkQueueEventForAllChildren () from /usr/lib/libtk8.3.so #5 0x401c300d in Tcl_ServiceEvent () from /usr/lib/libtcl8.3.so #6 0x401c326d in Tcl_DoOneEvent () from /usr/lib/libtcl8.3.so #7 0x40062115 in Tkapp_MainLoop (self=0x815dfb0, args=0x8269358) at Modules/_tkinter.c:1696 #8 0x080d0df4 in PyCFunction_Call () #9 0x0807a65e in PyEval_EvalCode () #10 0x0807b0ce in PyEval_EvalCodeEx () #11 0x0807c62b in PyEval_GetFuncDesc () #12 0x0807a5a3 in PyEval_EvalCode () #13 0x0807b0ce in PyEval_EvalCodeEx () #14 0x08077fc5 in PyEval_EvalCode () #15 0x08097e29 in PyRun_FileExFlags () #16 0x08096d90 in PyRun_SimpleFileExFlags () #17 0x080966da in PyRun_AnyFileExFlags () #18 0x08053a19 in Py_Main () #19 0x08053469 in main () #20 0x42015574 in __libc_start_main () from /lib/tls/libc.so.6 This leads me to two things: first, reproduce this using a libtk compiled with debugging information. second, this is likely to be a Tk bug and not a Python bug given where it happens. It should be possible to write a test-case that is purely tcl code.. In fact, the following tcl code crashed on me once (not in gdb, so I can't compare stack traces), and when I run it under valgrind the *first* click I make sprays "invalid read" and "invalid write" errors such as ==23796== Invalid write of size 4 ==23796== at 0x4026ACEB: (within /usr/lib/libtk8.3.so) ==23796== by 0x4026AC24: (within /usr/lib/libtk8.3.so) ==23796== by 0x40221A7B: Tk_HandleEvent (in /usr/lib/libtk8.3.so) ==23796== by 0x40221E7B: (within /usr/lib/libtk8.3.so) ==23796== Address 0x41493D98 is 188 bytes inside a block of size 460 free'd ==23796== at 0x40161048: free (in /usr/lib/valgrind/valgrind.so) ==23796== by 0x402D8368: TclpFree (in /usr/lib/libtcl8.3.so) ==23796== by 0x402DD4F4: Tcl_Free (in /usr/lib/libtcl8.3.so) ==23796== by 0x402685C5: (within /usr/lib/libtk8.3.so) Now, in the python and wish cases, the shared libraries are loaded at different addresses. but note that the number of bytes between TK_HandleEvent and the next stack frame inwards (called Tk_GetItemTypes by gdb) is the same distance on my system. Jeff # --- tk program kinda like original python program proc p {} { puts p destroy .c canvas .c grid .c set tabIndex 0 set pos 0 foreach p { a b c } { set tags [list TAB_$tabIndex] if {$tabIndex == 1} { lappend tags CURRENT_TAB } set textId [.c create text $pos 10 -text $p -anchor w -tags $tags] .c bind TAB_$tabIndex p incr tabIndex 1 incr pos 20 } } p # --- From pythonguy at Hotpop.com Wed Aug 13 06:21:59 2003 From: pythonguy at Hotpop.com (Anand Pillai) Date: 13 Aug 2003 03:21:59 -0700 Subject: convert tuple to string References: <84fc4588.0308111221.528e478e@posting.google.com> Message-ID: <84fc4588.0308130221.5994658@posting.google.com> Jack Diederich wrote in message news:... > On Mon, Aug 11, 2003 at 08:40:13PM +0000, Alex Martelli wrote: > > > > So, let's look at performance. The complex, lambda-rich > > expression with a map and a reduce...: > > > > python2.3 timeit.py -s't=tuple([ (str(x),) for x in range(30) ])' > > 'reduce(lambda x,y:x+","+y, map(lambda x:x[0],t))' > > > > 10000 loops, best of 3: 59.3 usec per loop > > > > The simple expression based on a list comprehension: > > > > python2.3 timeit.py -s't=tuple([ (str(x),) for x in range(30) ])' > > '",".join([ x[0] for x in t ])' > > > > 10000 loops, best of 3: 24.4 usec per loop > > > > I think this is great fodder for the underground movement aiming > > to remove lambda, map and reduce. All that complication just > > to slow things down by two times and a half...?-! > I agree. Somehow the solutions which involve lambda + functional tools (map, filter, reduce, apply) have an innate appeal. Invariablye one finds that he has to use one of (map, filter, apply, reduce) in his lambda expressions. I did not check the performance part when I posted it. Maybe the interpreter should decide to inline them lambda calls also :-) Anand > No, t his is a call for lambda/map/filter fans to improve the > intepreter. The above reduce has 2*30 more function calls > per loop than the equivalent list comprehension. The list comp > essentially gets inlined, the lambda gets called and the > arguments parsed each time. > > A truer comparison would also have the top one doing ",".join or > the bottom one using reduce. Having one doing 30*3 string concats > and the other doing one join() will skew the results. > > -jackdied From syver-en+usenet at online.no Tue Aug 5 15:18:33 2003 From: syver-en+usenet at online.no (Syver Enstad) Date: 05 Aug 2003 21:18:33 +0200 Subject: MSVC 6.0 Unsupported? Message-ID: I've downloaded both source distro, and binary installer. Installed python with the binary installer, when I attempted to compile mxDateTime (mxBase) for 2.3 with MSVC 6.0 I got an error that seemed related to forward declarations. It seems that the #defines that makes staticforward into extern when using the MSVC 6 compiler has been removed from object.h. So I guess this means I should use VC++ 7.0 to compile python with? -- Vennlig hilsen Syver Enstad From jjl at pobox.com Mon Aug 18 09:52:27 2003 From: jjl at pobox.com (John J. Lee) Date: 18 Aug 2003 14:52:27 +0100 Subject: What's better about Ruby than Python? References: <3F40892D.AEF4AAE@alcyone.com> Message-ID: <87isov6pk4.fsf@pobox.com> Erik Max Francis writes: > "Brandon J. Van Every" wrote: > > > I frankly don't have the time, and am not afraid to leverage other > > people's > > experiences to some degree. > > But surely in the time you've been considering the use of Python -- > particularly now, since you claim to have to decided to use it as one of > your main development languages -- you could have taken a few hours or > so it would require to read and really absorb the tutorial Fair comment, but it *is* reasonable to ask about Pythonistas' view of Ruby -- I don't know why other posters have complained about that. > (much less, > of course, if you're already a competent programmer, as you claim to > be)? [...] Much less than a few hours? You're obviously much faster on the uptake than me... John From adalke at mindspring.com Fri Aug 1 18:33:16 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Fri, 1 Aug 2003 16:33:16 -0600 Subject: time, calendar, datetime, etc References: Message-ID: John Roth: > See my response to Andrew Dalke. The basic issue is that the starting > date is too late to be useful. And my reponse is you should have said "... to be useful for you." It's plenty useful for me and others. Though if I were to do long baseline interferometry, using a couple of masers to keep things in synch, then I expect that datetime would also not be useful for me because I would need better than microsecond resolution. When should datetime functionality stop growing to support smaller and smaller niches? > I wouldn't have any problem with wrapping it to get what I want, but > the base date issue is intractible in any significant sense. The remainder > of Andrew's straw men are clearly in extension territory. "Intractable?"! What about defining your own class which handles BC dates, using datetime to do the heavy load? All you need is your own offset to choose a year which has the same day-of-week and leapyear behaviour. datetime says 1/1/1 was a Monday, so you just need a year offset X so that 12/31/X is a Sunday and where X is a leapyear (or not? Don't know how the leap years are affected that far in the past.). Looks like X=6000 does the job. >>> datetime.date(1970, 8, 22).weekday() 5 >>> datetime.date(6970, 8, 22).weekday() 5 >>> So what about an offset of 6000 years? Implement your own class which uses datetime for storage, and just subtract 6000 years from its result to get the real result? class RothDate(object): def __init__(self, year, month, day): self._date = datetime.date(year + 6000, month, day) year = property(lambda self: self._date.year - 6000) month = property(lambda self: self._date.month) day = property(lambda self: self._date.day) def weekday(self): self._date.weekday ... d = RothDate(-200, 2, 10) print d.year, d.month. d.day print d.weekday() Doesn't seem that intractable to me, excepting leapyear behaviours. And is there consensus on that? Andrew dalke at dalkescientific.com From bkelley at wi.mit.edu Thu Aug 7 10:27:50 2003 From: bkelley at wi.mit.edu (Brian Kelley) Date: Thu, 07 Aug 2003 10:27:50 -0400 Subject: Stupid string.split question In-Reply-To: References: <3f314721$0$3936$b45e6eb0@senator-bedfellow.mit.edu> <3F3160E6.BD604930@engcorp.com> Message-ID: <3f326199$0$3951$b45e6eb0@senator-bedfellow.mit.edu> Andrew Dalke wrote: > Instead, he is bothered because the following doesn't work > when sep == "" > > def split_join(s, sep): > return s == sep.join(s.split(sep)): > That's pretty much it. Note that I'm not bothered so much to actually do anything about it :) I understand the infinite number of empty seperators though, and while it might give pause I wonder (as an academic excercise) if you asked 100 people what "ABCDEF".split('') should return (if it returned anything at all) what you would get. Again, don't bother answering this question, list("ABCDEF") works just fine for me :) Now, as for old chesnuts and long hot summers, if one could just do: "".join(list("ABCDEF").reverse()) *ducks* From creedy at mitretek.org Wed Aug 20 18:05:15 2003 From: creedy at mitretek.org (Chris Reedy) Date: Wed, 20 Aug 2003 18:05:15 -0400 Subject: What's better about Ruby than Python? In-Reply-To: <66d7kvonvb2n0nqbqahhd5roak7ur81sob@4ax.com> References: <3F41505F.69D18CC8@alcyone.com> <66d7kvonvb2n0nqbqahhd5roak7ur81sob@4ax.com> Message-ID: <3f43ef5d_4@127.0.0.1> Doug Tolton wrote: > On Tue, 19 Aug 2003 13:43:11 +0200, Alex Martelli > wrote: > >>Doug Tolton wrote: >> ... >> >>>abstractions and better programmer productivity. Why not add Macro's >>>allowing those of us who know how to use them and like them to use >>>them. If you hate macros, or you think they are too slow, just don't >>>use them. >> >>"No programmer is an island"! It's not sufficient that *I* do not use >>macros -- I must also somehow ensure that none of my colleagues does, >>none of my clients which I consult for, nobody who posts code asking >>for my help to c.l.py or python-help -- how can I possibly ensure all >>of this except by ensuring that macros ARE NOT IN PYTHON?! "Slow" has >>nothing to do with it: I just don't want to find myself trying to debug >>or provide help on a language which I cannot possibly know because it >>depends on what macros somebody's defined somewhere out of sight. Not >>to mention that I'd have to let somebody else write the second edition >>of the Nutshell -- if Python had macros, I would have to cover them in >>"Python in a Nutshell". > > Sadly, I would say that is something that would sway me. I love my > Python in a Nutshell book. I have that baby on my desk and I refer to > it *daily*. Although I'd say that's more extortion than a winning > argument!! :-p > > I just don't see Macros as the huge threat you do. As someone > mentioned in a previous post, the option would require to do declare > explicitly that you are using Macros. Why is that such a *huge* > issue? Why is it that the very *existence* of a Macro in a program > would offend your sensibilities? > I'm curious. Why do you feel such a need for macros? With metaclasses, etc., etc., what significant advantage would macros buy you? Do you have any examples where you think you could make a significantly crisper and easier to read and understand program with macros than without. Chris ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =--- From hokiegal99 at hotmail.com Thu Aug 28 09:23:42 2003 From: hokiegal99 at hotmail.com (hokieghal99) Date: Thu, 28 Aug 2003 09:23:42 -0400 Subject: Script Discussion & Critique In-Reply-To: References: <3F4D31B1.6080802@hotmail.com> <06eqkv4onjh5m4tcbbqkmh8lscaj5niatp@4ax.com> <3F4D4402.3060209@hotmail.com> Message-ID: Peter Otten wrote: > Factor out reusable code, e.g: > > def replaceTokenInTree(rootFolder, searchToken, replaceToken, > filterFunc=None) > def replaceTokenInFile(filename, searchToken, replaceToken, backupFile=None) > > This will pay off as your scripts grow (or your script grows:-), so make it > a habit as soon as possible. I don't fully understand how functions work yet. This is something that I'm studying in my spare time. I dislike using something when I don't fully understand how it works, thus my scripts are really very simple right now. That's one reason I like Python so well, it has milk for babies like me and meat for adults like you. It's useful and productive for both of us at different stages in our knowledge. > Some observations that are not directly code-related: > > You can change - and possibly corrupt - *many* files in one run of you > script. So you might add a confirmation prompt repeating searchToken, > replaceToken and the root directory (resolved to an absolute path) and - > somewhat more ambitious - a means to generate backups. This is very good. I will add the confirmation check soon. Thank you for the suggestion. The backup idea is good too, not 100% necessary, but highly desirable. > Last but most important: > > Take time to build a test file tree, and include all special cases you can > think of (including those you consider irrelevant) e. g. files > starting/ending with search token, zerolength file, file with readonly > access. Yes, I do this a lot, but it's just me and I'm limited to my world view of things. This is why I like this forum, you guys point things out that I miss entirely. Thanks!!! From RaoulGough at yahoo.co.uk Thu Aug 21 13:56:38 2003 From: RaoulGough at yahoo.co.uk (Raoul Gough) Date: Thu, 21 Aug 2003 18:56:38 +0100 Subject: Misleading description of [i:j:k] slicing? References: <7h33cfv2az7.fsf@pc150.maths.bris.ac.uk> <8t0akv0ov6k2peg5b92humla84mnhcovu2@4ax.com> Message-ID: Christos "TZOTZIOY" Georgiou writes: > On Thu, 21 Aug 2003 17:12:28 GMT, rumours say that Michael Hudson > might have written: > >>> "The slice of s from i to j with step k is defined as the sequence >>> of items with index x = i + n*k such that 0 <= n < abs(i-j). [...]" > > Basically, it's 0 <= n < abs(i-j)//k, right? I didn't know about // (silly me) but it looks like a good way to go. Your alternative formulation still doesn't give the right behaviour for negative values of k. e.g. s[4:0:-1]. i.e. i=4, j=0, k=-1 so 0 <= n < -4 ?? or, indeed, for positive k and j <87znibzrnx.fsf@pobox.com> <87oeypdh92.fsf@pobox.com> <87k79a25pi.fsf@pobox.com> <87isos0zng.fsf@pobox.com> <87ptis39kp.fsf@pobox.com> Message-ID: > Oh, sorry, I missed something: you're using urllib.urlopen. You need > to call ClientCookie.urlopen instead (this is still using urllib2 -- > ClientCookie uses urllib2 to do most of the work). > > You seem to be opening the same URL twice for no obvious reason, so I > removed that below: > > > def go10(): > #works with win xp > import ClientCookie > c = ClientCookie.MSIECookieJar(delayload=1) > c.load_from_registry(username='mcarter') #only need username for win9x > > url = 'http://businessplus.hemscott.net/corp/crp03733.htm' > response = ClientCookie.urlopen(url) > > print response.info() # headers > print response.read() # body At the risk of sounding thick ... this doesn't work either! I couldn't get load_cookie_data() to work using the above template, either. What seems odd for starters is the line response = ClientCookie.urlopen(url) What makes it odd is that to an offhand observer, there is nothing visibly connecting the urlopen() command to c. Sure, some fancy stuff may be going on under the hood; but like I say, ClientCookie.urlopen() doesn't seem connected with the MSIECookieJar instance just by looking at it. It looks like I really want to be saying something like response = c.urlopen(url) but that just gives me AttributeError: MSIECookieJar instance has no attribute 'urlopen' From mwilson at the-wire.com Mon Aug 4 13:23:55 2003 From: mwilson at the-wire.com (Mel Wilson) Date: Mon, 04 Aug 2003 13:23:55 -0400 Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> <87el06d2i6.fsf@pobox.com> Message-ID: In article , "Andy C" wrote: >What's bad about tabs? I'm new to Python. Tabs are good because then you >can view the source however you want. I can't write in 4 space tabs and >someone else can change it to 2 if they prefer. But I can see the problem >with continuation lines. Also it must be ALL tabs or ALL spaces. This >shouldn't be too hard -- most editors have the "tabify" option. Nothing essentially. But if a program combines the two forms, say somebody pastes space-using code into a tab-using program, then strange things can happen for no obvious reason. There's no standard exchange rate between tabs and spaces in the Python syntax. (Idea for obfuscated Python: a program that mixes spaces and tabs in the indenting so as to perform two or more distinct useful functions depending on the space-to-tab rate. Bonus points for a program that undoes itself at different settings.) My own preference is for tabs, because my favourite editor works well with them (i.e. Tab serves as indent and Backspace as undent), and convert to spaces for people on the outside, per convention. Regards. Mel. From p-abel at t-online.de Thu Aug 28 12:50:16 2003 From: p-abel at t-online.de (Peter Abel) Date: 28 Aug 2003 09:50:16 -0700 Subject: Binary data handling ? References: Message-ID: <13a533e8.0308280850.1d7d913d@posting.google.com> "Bill Loren" wrote in message news:... > Hello ppl, > > I'm having difficulties to accomplish some simple chores with binary data. > I'm having a string (?) which I received via an HTTP transactions which is a > binary file. > Problem is the webserver I'm communicating with injected a \x0D before every > \x0A, > and I need to remove those 0x0D characters from my buffer before saving it > to disk. > > any ideas ? > > I tried the following without any success: > string.replace("%c%c" % (13,10), "%c" % (10)) > string.replace("\x0d\x0a", "\0x0a") > > thx > ~B >>> # A short function to generate a string with 0x0D's >>> def make_bin(): ... bytes=[] ... for i in range(20): ... bytes.append(chr(i)) ... # every 5th char is a 0x0D ... if not i%5: ... bytes.append(chr(0x0D)) ... return ''.join(bytes) ... >>> binary=make_bin() >>> binary '\x00\r\x01\x02\x03\x04\x05\r\x06\x07\x08\t\n\r\x0b\x0c\r\x0e\x0f\r\x10\x11\x12\x13' >>> # split the string at the 0x0D's and join it again >>> binary_without_x0D=''.join(binary.split(chr(0x0D))) >>> #et voila >>> binary_without_x0D '\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\x0e\x0f\x10\x11\x12\x13' >>> Regards Peter From vze4rx4y at verizon.net Wed Aug 27 11:02:41 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Wed, 27 Aug 2003 15:02:41 GMT Subject: Help improve Python -- Call for reviewers Message-ID: Sourceforge is used to track bug reports, feature requests, and patches: https://sourceforge.net/projects/python/ Each of those submissions needs to be reviewed and discussed. A good way to participate in python development is to spend some time adding useful comments to each report. Bug reports ------------ * Sometimes the OP thinks a bug is present when, in fact, Python is behaving as intended. It is useful to gently steer them in the right direction, correct their understanding, and have them close the bug report. * Sometimes the bug is unique to OP's own environment and it is helpful to have another person confirm the bug on another machine. * Often, a bug report is inadequately specific -- "My 200 line script doesn't work". Help is needed to refine the report to the simplest possible demonstration of the error: bool("False")!=False. * It is even more helpful to specifically identify where the error is occurring in the source: line 200 in textwrap.py has an and/or problem. * In many cases, discussion is necessary to ascertain whether the behavior is truly a bug, a documentation issue, or a natural byproduct of other important invariants. * It is also helpful to suggest alternative solutions and discuss the implications of each. Patches -------- * The simplest checks are: - does it work - does it have unittests - does it have a doc patch * More advanced considerations: - are there subtle code breakages (one man's bug is another's feature) - is the change desirable - would a refactoring have simplified the problem - are there unintended consequences - is there a better alternative solution Feature Requests ------------------- The basic idea here is to see whether life would truly be better if the idea were adopted. Considerations include the minimizing the rate of language growth, ease of implementation, how it fits in with the rest of the language, and the existence of practice use cases. Readers of comp.lang.python are also in a good position to make comments on the idea and how it fits in with stated Python design goals. For example, IDLE could easily grow macros, RCS buttons, templates and such, but it's design goal is to be a relatively simple yet complete, portable editor/ide written in pure python -- this means that grandiose ideas to transform it into emacs will likely not be accepted. The presence of a feature in another language is neither cause for acceptance or rejection. Just because Perl, PHP, VB, or Ruby does something, it is not necessarily good or necessarily bad. It does at least provide a proof-of-concept and real world experience with the feature so that we can learn from its successes or failures. The itertools module was designed to capture some of the successes in Haskell and ML. Raymond Hettinger From kevin at cazabon.com Wed Aug 6 17:26:14 2003 From: kevin at cazabon.com (Kevin Cazabon) Date: 6 Aug 2003 14:26:14 -0700 Subject: crossplatform py2exe - would it be useful? References: Message-ID: <5a4226f0.0308061326.31cedc03@posting.google.com> Hi Thomas; I've tried Freeze before, but I'm hooked on py2exe because it's so SIMPLE and flexible, and handles all the weird cases automatically... For those of us that aren't C gurus, anything that makes the process easier is welcome. To clarify your proposal, would you simply build the executable using the same setup.py script on other platforms too, or would you have to do more manual steps? Thanks for the great work so far... py2exe ROCKS! q:] Kevin. Thomas Heller wrote in message news:... > I'm currently working on a new version of py2exe, which will require > Python 2.3 and later, because it uses the zipimport mechanism. > > Since py2exe is a distutils extension, and since C compilers are > commonly available on most platforms except Windows, it would be fairly > easy to let py2exe generate a C source file installing this import hook, > and let distutils' C compiler build an executable file from this. > > Would this be useful, or would I be wasting my time, since McMillan > installer, cx_freeze, and tools/freeze already do it? > > At the end of this post you'll find excerpts from the readme file, which > is currently the only documentation available. > > Thomas > > The readme file: > > A new and improved py2exe for Python 2.3 > ======================================== > > Uses the zipimport mechanism, so it requires Python 2.3 or later. The > zipimport mechanism is able to handle the early imports of the > warnings and also the encodings module which is done by Python. > > Creates a single directory, which must be deployed completely. > > (Most of this is based on ideas of Mark Hammond:) Can create any > number of console and gui executables in this directory, plus > optionally a windows service exe, plus optionally an exe and dll com > server. The com servers can expose one or more com object classes. > > All pure Python files are contained in a single zip archive, which is > shared by all the executables. The zip archive may also be used by > programs embedding Python. Since extension modules cannot be imported > from zipfiles, a simple pure Python loader is included in the zipfile > which loads the extension from the file system (without requiring that > the directory is in sys.path). > > It would be nice if the executables could be run with only a single > sys.path entry containing the absolute filename of the zipfile, but it > seems for dll com servers the executable's directory is also > needed. The absolute filenames are constructed at runtime from the > directory containing the executable, and the zipfile name specified at > build time. > > The way has changed how build targets are specified in the setup > script. py2exe installs it own Distribution subclass, which enables > additional keyword arguments to the setup function: > > console = [...] # list of scripts to convert into console executables > windows = [...] # list of scripts to convert into gui executables > com_servers = [...] # list of fully qualified class names to build into the exe com server > service = [...] # list of fully qualified class names to build into a service executable > zipfile = "xxx.zip" # filename of the zipfile containing the pure Python modules > > All of the above arguments are optional. The zipfile name defaults to > 'library.zip'. From shlomme at gmx.net Fri Aug 8 15:26:41 2003 From: shlomme at gmx.net (Torsten Marek) Date: Fri, 08 Aug 2003 21:26:41 +0200 Subject: no universal newlines in os.popen Message-ID: Is it a bug that os.popen("some_nifty_command some_arg", "rU") gives OSError: [Errno 22] Invalid argument in Python 2.3? greetings Torsten From aahz at pythoncraft.com Mon Aug 11 18:44:56 2003 From: aahz at pythoncraft.com (Aahz) Date: 11 Aug 2003 18:44:56 -0400 Subject: Reference count References: <002a01c3603b$73442a90$417290c8@paraopeba> <16183.60555.59705.762835@montanaro.dyndns.org> Message-ID: In article , Pablo Yabo wrote: > >I need to keep a object alive even if its reference count if zero. >Is there any way to increment its reference count using Python code, not >Py_INCREF or there is any way to avoid deletion of the object? To expand on Skip and Gary, there is no way to keep alive an object if its refcount goes to zero. One way or another, you need to bind *some* target (most likely a dict or list element) to the object to increase its refcount. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From max at alcyone.com Mon Aug 18 04:07:09 2003 From: max at alcyone.com (Erik Max Francis) Date: Mon, 18 Aug 2003 01:07:09 -0700 Subject: What's better about Ruby than Python? References: Message-ID: <3F40892D.AEF4AAE@alcyone.com> "Brandon J. Van Every" wrote: > I frankly don't have the time, and am not afraid to leverage other > people's > experiences to some degree. But surely in the time you've been considering the use of Python -- particularly now, since you claim to have to decided to use it as one of your main development languages -- you could have taken a few hours or so it would require to read and really absorb the tutorial (much less, of course, if you're already a competent programmer, as you claim to be)? You've certainly spent a great deal more than a few hours since you first started posting your questions here, which was more than two years ago (first coherent Python-related questions appeared in 2001 April, according to Google Groups). -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ 'Tis man's to fight, but Heaven's to give success. \__/ Homer From cookedm+news at physics.mcmaster.ca Fri Aug 1 16:14:47 2003 From: cookedm+news at physics.mcmaster.ca (David M. Cooke) Date: Fri, 01 Aug 2003 16:14:47 -0400 Subject: Python speed vs csharp References: Message-ID: At some point, Mike wrote: [...] > # Rational approximation for erfc(x) (Abramowitz & Stegun, Sec. 7.1.26) > # Fifth order approximation. |error| <= 1.5e-7 for all x > # > def erfc( x ): > p = 0.3275911 > a1 = 0.254829592 > a2 = -0.284496736 > a3 = 1.421413741 > a4 = -1.453152027 > a5 = 1.061405429 > > t = 1.0 / (1.0 + p*float(x)) > erfcx = ( (a1 + (a2 + (a3 + > (a4 + a5*t)*t)*t)*t)*t ) * math.exp(-(x**2)) > return erfcx Since no else has mentioned this, and it's not in the comments: the above code is no good for x < 0 (erfc(-3)=84337, for instance). You'll need a check for x < 0, and if so, use the identity erfc(x) = 2 - erfc(-x). That'll slow you down a tad again :) -- |>|\/|< /--------------------------------------------------------------------------\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca From scottholmes at sbcglobal.net Sat Aug 16 14:40:05 2003 From: scottholmes at sbcglobal.net (Scott Holmes) Date: Sat, 16 Aug 2003 11:40:05 -0700 Subject: event binding and component.config Message-ID: <3F3E7A85.8040202@sbcglobal.net> I'm experiencing what seems to be strange behaviour. I don't know if it's Pmw, Tkinter on Python. I have a button, defined in a Pmw.buttonbox, that I would like to configure to "sunken" after it has been clicked/released. Using the example style coding: self.buttonBox1.add('Add', command = self.addCalendar) the button remains "sunken". If I bind the event: self.buttonBox1.add('Add') self.buttonBox1.component('Add').bind('', self.addCalendarBind) self.buttonBox1.component('Add').bind('', self.addCalendarBind) the button reverts to "raised". The addCalendar and addCalendarBind are still essentially stub functions: def addCalendarBind(self,event): self.addCalendar() def addCalendar(self): global prog_mode self.clearCalendar() prog_mode = 'add' self.buttonBox1.component('Add').config(relief='sunken') self.buttonBox1.component('Commit').config(relief='raised') self.buttonBox1.component('Update').config(relief='flat') self.buttonBox1.component('Delete').config(relief='flat') self.buttonBox1.component('Query').config(relief='flat') -- --------------------------------------------------------------------- Scott Holmes http://sholmes.ws http://pages.sbcglobal.net/scottholmes scottholmes at sbcglobal.net Independent Programmer/Analyst Passport 4GL PHP HTML Composer PostgreSQL Informix 4GL, SQL --------------------------------------------------------------------- There are more things in heaven and earth, Horatio, than are dreamt of in your philosophy --------------------------------------------------------------------- From sismex01 at hebmex.com Thu Aug 14 12:55:50 2003 From: sismex01 at hebmex.com (sismex01 at hebmex.com) Date: Thu, 14 Aug 2003 11:55:50 -0500 Subject: Is Python your only programming language? Message-ID: [Terry Reedy] > http://www.mssl.ucl.ac.uk/www_plasma/missions/cluster/about_cluster/cluster1 /ariane5rep.html > Having just read this, I second the suggestion. What the report hints > at is that the 'root' cause of the failure was pride leading to > complacency -- a trap most anyone can fall into -- and one which one > language can completely protect against. Which language is that? :-) -gustavo pd: Yeah, I know you meant "...no language can..." ;-) Advertencia:La informacion contenida en este mensaje es confidencial y restringida, por lo tanto esta destinada unicamente para el uso de la persona arriba indicada, se le notifica que esta prohibida la difusion de este mensaje. Si ha recibido este mensaje por error, o si hay problemas en la transmision, favor de comunicarse con el remitente. Gracias. From sjmachin at lexicon.net Mon Aug 4 18:33:27 2003 From: sjmachin at lexicon.net (John Machin) Date: 4 Aug 2003 15:33:27 -0700 Subject: Test installs of Python on Windows References: Message-ID: "Tim Peters" wrote in message news:... > Python installs are pretty benign, and on Windows 2.2.x and 2.3.y even name > the base DLL differently (python22.dll vs python23.dll). For a minimally > intrusive 2.3 test drive: > > + Install to the suggested \Python23 directory. It won't touch anything > in your 2.2.x installation then. > > + Leave the "Yes, make backups" default selected. > > + In the "Select Components" dialog, click on "Advanced Options ...". > In the "Advanced Options" dialog that pops up, > > - Select "Non-Admin install". Then all files (even the base Python > DLL) will be unpacked under \Python23 (by default, we try to unpack > the base DLL into a Windows system directory). > > - Uncheck "Register file extensions". Then .py (etc) files will > continue to be associated with whatever Python you had before > the 2.3 test drive. > > Because I build the PLabs Windows installer, I install broken pre-release > Pythons all the time. The steps above are the ones I use then to ensure > that they don't interfere with any of the released Pythons on my box. The > Wise uninstaller does a thorough job of removing all traces of a Python > installed in this way, and because we avoid changing file associations, > can't be fooled by an unfortunate sequence of installs and uninstalls. Tim, can this excellent advice be made to appear on the python.org website, in close proximity to the bit that says "download python*.exe and run it"? Cheers, John From danbmil99 at yahoo.com Tue Aug 12 12:14:49 2003 From: danbmil99 at yahoo.com (dan) Date: 12 Aug 2003 09:14:49 -0700 Subject: CLI+GUI References: <2259b0e2.0308080948.5a95e383@posting.google.com> Message-ID: Late to this thread, but -- in a similar situation, I just put: _tkinter.dooneevent(_tkinter.DONT_WAIT) in my main logic loop (cmd interpreter in your case), instead of calling Frame.mainloop(). I believe Frame.update() does something similar but for some reason this worked better. ISTM this would be cleaner (and safer) than using threads. You can do all your draw operations from your command line routines, and they will get displayed as soon as the routine returns to your main loop to wait for more input. Am I missing something? -dbm mis6 at pitt.edu (Michele Simionato) wrote in message news:<2259b0e2.0308080948.5a95e383 at posting.google.com>... > I wonder what is the recommended way of using Tkinter > together with a command line oriented application. > I have in mind something like that: > > import cmd,sys > > class CMD(cmd.Cmd): > def do_this(self,*args): > draw_a_diagram() > def do_that(self,*args): > draw_another_diagram() > def do_exit(self,*args): > sys.exit(0) > > c=CMD() > c.cmdloop() > > Here the methods ``draw_a_diagram`` and ``draw_another_diagram`` > should do what you expect. Notice that I don't want to use > different windows, the graphs should be displayed on the same > window one over the other. BTW, I am not really displaying > diagrams, this is only the simplest example I can figure out > of graphics program driven by a command line interpreter. > I want to stay with the CLI interface, which I like a lot > thanks to the readline and completion support, the easy > of use and the easy of implementation. > > I have no idea of how to do that, except via contorsions > such as saving (a representation of) the diagrams in a file > and having a separated Tkinter process that periodically look at the > file, changing the display if the file has been updated. I > guess there is a better way, since this is a quite common issue. > Any suggestion? > > TIA, > > Michele From pedro.werneck at bol.com.br Mon Aug 18 17:28:16 2003 From: pedro.werneck at bol.com.br (Pedro Werneck) Date: Mon, 18 Aug 2003 21:28:16 +0000 Subject: What's better about Ruby than Python? In-Reply-To: References: Message-ID: <20030818212816.25da1b86.pedro.werneck@bol.com.br> On 18 Aug 2003 23:40:58 +0100 Alexander Schmolck wrote: > Does it make sense now? I say "something like" because I could also live with > something like ``sys.update_all_instances_of(X)``. What I can't live with is > the (according to my current understanding) entirely brain-dead ``x.__class__ > = X`` for every `x` I can lay my hands on, with quite a bit of labour (and > which furthermore tends to break pickling etc). I guess I must be overlooking > something here, because to me it seems entirely obvious that there should be a > straightforward mechanism for updating all instances of a class when the class > is redefined. Well... I think you're overlooking the fact that you're not exactly _redefining_ the class. You're creating an entirely new class object and binding it to the same name, but the old class is still lying there, and all instances have their __class__ references pointing to it. class X: def amethod(self): return "just a method" # and import types def amethod(self): return "just a method" X = types.ClassType('X', (), {'amethod':amethod}) # So, I may be completely wrong, but I think that redefining the entire class rather than methods on the former class, is not possible in Python, unless you keep references of instances and iterate over them updating their __class__ to point to the new class object. From urbanlegend at ozemail.com.au Tue Aug 5 23:20:12 2003 From: urbanlegend at ozemail.com.au (M Wells) Date: Wed, 06 Aug 2003 13:20:12 +1000 Subject: Unable to run IDLE from 2.3? References: <1akviv4cpectdogklmuupg7rc37lhe1pc7@4ax.com> <3f2fefc8$0$6527$6c56d894@sisyphus.news.be.easynet.net> <9j20jv0v49gmud6kvtadl63l313biv6ctd@4ax.com> <3f300e8f$0$6526$6c56d894@sisyphus.news.be.easynet.net> Message-ID: <9vs0jv4lha3balukqpgikisbalgbf7cvpa@4ax.com> On Tue, 5 Aug 2003 22:08:02 +0200, "Bernard Delm?e" wrote: >I seem to recall ruby defines tcl/tk related environment variables >which may interfere with python. If you are not using ruby-tk, >I don't think you need to de-install but merely un-defining those >variables should correct the situation. I think that's what I did >long ago so I don't see those variable names myself, and can't >be more specific.... Hi Bernard, Worked perfectly! Removed the ruby variables and now IDLE is running! Thank you to you (and also to the others that replied) for your help! Much warmth, Murray http://www.planetthoughtful.org Building a thoughtful planet, one snide comment at a time... From davidb at mcs.st-and.ac.uk Fri Aug 1 18:20:05 2003 From: davidb at mcs.st-and.ac.uk (David Boddie) Date: 1 Aug 2003 15:20:05 -0700 Subject: HTML DOM parser? References: <7x7k5y5wfh.fsf_-_@ruckus.brouhaha.com> Message-ID: <4de76ee2.0308011420.14f309f8@posting.google.com> Paul Rubin wrote in message news:<7x7k5y5wfh.fsf_-_ at ruckus.brouhaha.com>... > Is there an HTML DOM parser available for Python? Preferably one that > does a reasonable job with the crappy HTML out there on real web > pages, that doesn't get upset about unterminated tables and stuff like > that. Many extra points if it understands Javascript. Application is > a screen scraping web robot. Thanks. As John J. Lee points out in another message in this thread, the KHTML bindings in PyKDE might be useful. Particularly for cutting through Javascript to get to those extra points. However, what's wrong with the following? >>> from xml.dom.ext.reader import HtmlLib >>> reader = HtmlLib.Reader() >>> document = reader.fromUri("http://www.python.org/index.html") The help for xml.dom.ext.reader.HtmlLib says: DESCRIPTION Components for reading HTML files using htmllib.py. WWW: http://4suite.com/4DOM e-mail: support at 4suite.com Copyright (c) 2000 Fourthought Inc, USA. All Rights Reserved. See http://4suite.com/COPYRIGHT for license and copyright information I've no idea how it performs on badly written pages. David -- http://www.boddie.org.uk/david/Projects/ From max at alcyone.com Tue Aug 26 15:26:45 2003 From: max at alcyone.com (Erik Max Francis) Date: Tue, 26 Aug 2003 12:26:45 -0700 Subject: Uncatchable socket.error in socket.py (?) References: <3f4ba0bb$0$49103$e4fe514c@news.xs4all.nl> Message-ID: <3F4BB475.DCECCAA4@alcyone.com> Rune wrote: > Thanks Irmen, but the problem seems to be that the server is actually > crashed before I can catch the exception. There is no connection to > send output to. I have no idea how to avoid this. If you catch the error, then the server won't have "crashed," and you'll be able to recover however you like. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ The most exhausting thing in life is being insincere. \__/ Anne Morrow Lindbergh From martin at v.loewis.de Fri Aug 8 01:56:57 2003 From: martin at v.loewis.de (Martin v. =?iso-8859-15?q?L=F6wis?=) Date: 08 Aug 2003 07:56:57 +0200 Subject: generating byte code from compiler.parse output References: Message-ID: caw at cs.mu.oz.au (Chris Wright) writes: > Is there a way to go from the AST output of compiler.paser to byte > code Yes. Use the source, Luke. > i.e. in the example below, is there a way to compile m and get a code > object that could then be called? You have to find out what compiler.compile is doing in addition to what you are doing. Then, you find, that you need misc.set_filename, syntax.check, ModuleCodeGenerator, and .getCode, in that order. HTH, Martin From tocapicha at hotmail.com Sat Aug 30 21:27:44 2003 From: tocapicha at hotmail.com (Inspector Chan) Date: 30 Aug 2003 18:27:44 -0700 Subject: Escaping shell commands Message-ID: <5ce25061.0308301727.4c7b478a@posting.google.com> Hi, I'm using some external data on shell commands which are to be executed with os.system (other functions doesn't provide enough flexibility for executing these shell lines). So I have decided to user re.escape() for escaping these data before using it on the created command lines. Quick example: malicious external data in var 'data': data= '; touch /home/user/I0wnzu' shell command to be executed is 'command': command= 'echo I am so happy' + re.escape(data) This way the generated shell lines is: echo I am so happy\;\ touch\ \/home\/user\/I0wnzu With this example it looks safe... But I'm not quite sure about this method of escaping input. ?Is this breakable? If so... ?how? ?Does anyone knows a better way to get this done? From nicola-mingotti_NOSPAM at libero.it Tue Aug 5 07:27:07 2003 From: nicola-mingotti_NOSPAM at libero.it (Nicola Mingotti) Date: Tue, 05 Aug 2003 13:27:07 +0200 Subject: command -- It works , on linux References: Message-ID: On Mon, 04 Aug 2003 09:54:28 +0200, Alex Martelli wrote: > Have you tried installing Gonnerman's "Alternative Readline", > http://newcenturycomputers.net/projects/readline.html ? I have found it > extremely useful to gain the gist of readline's functionality on Windows > installatons of Python. > -- Alex yes , only now , and it works . thank you . bye. From usenet at soraia.com Mon Aug 11 15:37:48 2003 From: usenet at soraia.com (Joe Francia) Date: Mon, 11 Aug 2003 19:37:48 GMT Subject: Importerror no module named WIN32API In-Reply-To: <5f5c82ec.0308110740.550d5f43@posting.google.com> References: <5f5c82ec.0308110740.550d5f43@posting.google.com> Message-ID: Matt Smith wrote: > hi all, again.... > > having another problem with python COMs, I run a python script on a > win2000 machine, that uses win32com.client and it runs perfectly, > whereas when I come to run it on a win98 machine (the machine that the > code, when completed, will be running from in the future) it returns > the error: > > Traceback (most recent call last): > File "firsttry.py", line 1, in ? > import helloworld > File "G:\msmith\python\helloworld.py", line 2, in ? > import win32com > File "C:\PYTHON23\lib\site-packages\win32com\__init__.py", line 5, > in ? > import win32api, sys > ImportError: No module named win32api > > Any clues as to how to rectify this problem would be greatly > appreciated > > cheers, > matt. Maybe you need to install the win32all extensions on the Win98 machine? http://starship.python.net/crew/mhammond/ jf From fawcett at teksavvy.com Sun Aug 17 01:22:34 2003 From: fawcett at teksavvy.com (Graham Fawcett) Date: Sun, 17 Aug 2003 01:22:34 -0400 Subject: How to shortcut a package path? In-Reply-To: <420ced91.0308161605.acf6c5a@posting.google.com> References: <420ced91.0308161605.acf6c5a@posting.google.com> Message-ID: <3F3F111A.8060103@teksavvy.com> sdhyok wrote: >Is there any way to create a shortcut for a package path? >For instance, if I have the following path structure, > >dir1/dir2/program.py > >what should I do if I want to import program with > >from dir1 import program > >, not with > >from dir1.dir2 import program > > > If it were me, I would lay it out as such: #---------------------------------------------------------- # myapp.py from dir1 import program #---------------------------------------------------------- # dir1/__init__.py from dir1.dir2 import program # or, from dir2 import program, see note below. #---------------------------------------------------------- # dir1/dir2/__init__.py """Required, of course""" #---------------------------------------------------------- # dir1/dir2/program.py """Your code""" Side note: In dir1/__init__.py, I used "from dir1.dir2 import program" instead of "from dir2 import program". Either one would work, but sometimes you have to be careful not to mix the two (the absolute and the relative) approaches. Mixing them can lead to the a module being initialized twice, which can sometimes lead to some strange and hard-to-debug behaviour. Given the Python zen-ism of "explicit is better than implicit", my vote is for the side-effect-free, "full path" approach. Here's one of many c.l.py threads that refers to this double-initialization behaviour (maybe not the best, but the first I found): http://tinyurl.com/k98r Pedro asked why you want to do this... Personally, I might use this technique would be if I wanted "dir1" to act as a Facade, or API, to a set of subpackages. Import all of the "public" classes and functions into the dir1.__init__ module, and then your users are less inclined to access your "private" subpackages. This isn't a security technique, of course, it's just clean API design. -- Graham From nospam at the.net Tue Aug 26 13:47:43 2003 From: nospam at the.net (Rune) Date: Tue, 26 Aug 2003 19:47:43 +0200 Subject: Uncatchable socket.error in socket.py (?) Message-ID: Hi, I've written a very simple 'kill-server' to help me shut down processes through Telnet or HTTP. The kill-server is a function and is launched as a thread. I use the module socket.py on Python v2.3 (Windows) I can use telnet host:port and enter the secret killword or use a broser with http://host:port/secret_killword The 'kill-server' validates the secret_killword and writes a file to /tmp. The main process regularly checks for the existence of that file, and ends the loop if it does exist. It works well. But most for the fun (because this will probably never be exposed to the net, i think), I started to implement som basic security. For instance: I don't want ther server to be easily crashable. So I've written some try/except blocks to handle irregularities, but when trying to overflow the receive buffer, I get an exception in the socket module itself It says: |----------------------> Unhandled exception in thread started by Traceback (most recent call last): File "X:\tmp\webcam.py", line 68, in spawn_killserver connection.send("Nice try mister.") File "G:\dev\python\lib\socket.py", line 143, in _dummy raise error(EBADF, 'Bad file descriptor') socket.error: (9, 'Bad file descriptor') <----------------------| Relevant code: #init SOCKET sock = socket(AF_INET, SOCK_STREAM) sock.bind((host, killserver_port)) sock.listen(5) (blah blah) connection, address = sock.accept() try: buffer = connection.recv(16) except: connection.send("Nice try mister.") connection.close() So if I use a browser with this in the address field: http://host:port/500_chars_long_string I get the execption 'socket.error:' But if I try to catch it with 'except socket.error:', I generate a new exception: AttributeError - _socketobject' has no attribute 'error' I know I can make the receive buffer bigger, but the point is to lock that door once and for all. It seems to me that what happens is that the server crashes, and that connection.send() no longer have any place to send to. Now, enough words: What I wonder is: Can I catch that socket.error? --rune From raphael.bossek at gmx.de Mon Aug 18 05:30:28 2003 From: raphael.bossek at gmx.de (Raphael Bossek) Date: Mon, 18 Aug 2003 11:30:28 +0200 Subject: Expirience in using expect (PyExpect) functionality Message-ID: Hi, before starting with PyExpect I would like to know if there is an alternative because PyExpect seems not to be maintained anymore ? Is someone using PyExpect successfully here ? -- Raphael From vze4rx4y at verizon.net Wed Aug 20 17:17:45 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Wed, 20 Aug 2003 21:17:45 GMT Subject: Adobe photoshop plug in References: Message-ID: [Raymond] > >If you need a real plugin, then life is more complicated. To write photoshop > >plugins in any language, I think you need to have Adobe's plugin SDK which > >runs about $200. It was not designed for beginning programmers. [Bengt Richter] > I wonder why they charge for that (assuming you're right). ISTM if someone downloaded > a copy and did nothing, it would be no loss. If OTOH they put in the hours to produce > a desirable plugin, there would be at least a slight gain in PS marketability from the > existence of the plugin. IWT selling PS is 'way more important to Adobe's revenues > than selling the SDK. So is the SDK revenue worth the loss of the activity that would > happen if it were free? I guess they must think so. Not at all. The real reason has little to do with making a buck from developers. It is more insidious than that -- it's more along the lines of controlling their intellectual property; using price as a quality control mechanism; and a mircosoft style desire to know who you are, what you're up to, and having a say in whether you can do it. Even if you come up with the money, they can still deny your request for an SDK: http://partners.adobe.com/asn/photoshop/index.jsp Raymond Hettinger From mpeuser at web.de Wed Aug 13 07:25:35 2003 From: mpeuser at web.de (Michael Peuser) Date: Wed, 13 Aug 2003 13:25:35 +0200 Subject: drop down feature References: <87k79hdff9.fsf@pobox.com> Message-ID: "John J. Lee" schrieb im Newsbeitrag news:87k79hdff9.fsf at pobox.com... > "Michael Peuser" writes: > > > I fully agree with your very comprehensive statements. I personally do not > > know VB so much but RealBasic for Macintosh which is absolutely in the line > > of useability. It is as well a very friendly GUI Builder with all > > drag-n-drop and multimedia stuff AND it compiles AND it makes self contained > > exe files!! > > > > This in fact is my wishlist for a Python IDE ..... > > Of course the *language* itself is a mess ;-) Well it might not have been clear *which* language I was refering to ;-) ........ > Never bought the often-tacit assumption that programming environments > that happen not to be entirely graphical, and that aren't run by > clicking on a single .exe are somehow not integrated (in some ways > they tend to be less well integrated, in others more), so: > > GUI builder: > wxPython / BOA constructor > OR PyQt / Qt designer > OR VB (implement COM servers in Python, write GUI in VB) > > exe builder: > py2exe > OR McMillan Installer Yes, yes, yes! But when you are new to a language like Python, it is VERY DIFFICULT for you to find out, WHICH tool to use and WHICH library to download. Especially if they are not free as some of the better products you mention above. The choice between Tkinter, Qt and wx (and there is still FOX and something like FLTK and a lot of experimental projects like WCK, DynWin and PyUI...) There is a real great advantage of a comfortable - icluded! - IDE. This is the main reason I stay to IDLE and Tkinter, though they have none of the features I should like to have. > > "drag-n-drop and multimedia stuff" > Not sure what that means! A modern GUI is expected to support OS wide Drag and Drop. E.g. an IDE should be able to accept a source file dropped to it. Alas there is nothing like the integrated Quicktime-Technology on other platforms. For the simple programmer Quicktime has made most of any thougths about image audio or CD formats obsolete. Strictly both features have nothing to do with the discussion. They came to my mind when thinking back to all the good things of RealBasic.... > > > John Kindly Michael From alanmk at hotmail.com Mon Aug 18 11:14:42 2003 From: alanmk at hotmail.com (Alan Kennedy) Date: Mon, 18 Aug 2003 16:14:42 +0100 Subject: Exiting python to the DOS shell in 2.3 References: Message-ID: <3F40ED62.A81B6221@hotmail.com> [Stephen Boulet] > Control-C doesn't get me back to the DOS prompt anymore in python 2.3. > Aside from typing "import sys" and "sys.exit()", is there a key > combination to quit python? The EOF character should do the job on any platform. On Windows/DOS, the EOF character is ctrl-Z, on *nix it's ctrl-D. Here is a transcript of a (brief) python session on win2K: C:\>python Python 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] Type "help", "copyright", "credits" or "license" for more information. >>> ^Z C:\> > BTW, the "enumerate" function is the best thing since sliced bread. IMHO, generators, i.e. resumable functions, are the best thing since sliced bread ;-) but enumerate is pretty useful too. regards, -- alan kennedy ----------------------------------------------------- check http headers here: http://xhaus.com/headers email alan: http://xhaus.com/mailto/alan From bgailer at alum.rpi.edu Tue Aug 19 12:01:45 2003 From: bgailer at alum.rpi.edu (Bob Gailer) Date: Tue, 19 Aug 2003 10:01:45 -0600 Subject: wxPython launches DOS shell In-Reply-To: <4150f6c8.0308190748.7633e5c9@posting.google.com> Message-ID: <5.2.1.1.0.20030819100127.02cc2318@66.28.54.253> At 08:48 AM 8/19/2003 -0700, Matt Rapoport wrote: >Does anyone know how to avoid getting a DOS shell launched everytime >you run a wxPython script? The shell is used to run Python.exe but it >doesn't look very professional when a black window pops up along with >your GUI. use pythonw.exe Bob Gailer bgailer at alum.rpi.edu 303 442 2625 -------------- next part -------------- --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.506 / Virus Database: 303 - Release Date: 8/1/2003 From schnieper at semafor.ch Wed Aug 6 07:22:51 2003 From: schnieper at semafor.ch (Lukas Schnieper) Date: Wed, 06 Aug 2003 13:22:51 +0200 Subject: Get the hostname Message-ID: <3F30E50B.9090300@semafor.ch> Hi How can i get the hostname of my Linux PC? I tried os.system('hostname') but i cant save the hostname in a variable like hostname = os.system('hostname') thanks Lukas Schnieper From hancock at anansispaceworks.com Mon Aug 18 12:52:57 2003 From: hancock at anansispaceworks.com (Terry Hancock) Date: Mon, 18 Aug 2003 09:52:57 -0700 Subject: Watchdog technique Message-ID: Hi all, I have a program in a webserver environment that needs to run a fairly intensive calculation, which involves C extension calls (image processing with PIL). Most of the time, this works fine, but every once in awhile the calculation will hang, and I can't afford to wait for it (it's better to ditch it and get no result). This is a classic "heartbeat" or "watchdog" problem. I'm currently trying this with code like this: regen_thread = threading.Thread(...) regen_thread.start() regen_thread.join(REGEN_TIMEOUT) Which, on the surface, seems like the obvious way. But I'm concerned that there's no mention in the library reference of whether the regen_thread still exists after the join (if it times out). And, searching the archives, I see that Will Stuyvesant apparently had this same problem in late 2002. His posts seem to indicate that the regen_thread will be left running -- in my case this could eat up system resources, and eventually cause essentially a DOS situation on the server -- especially as I do not know in advance what might've gone wrong in the regeneration (e.g. it might be stuck in an infinite loop inside an extension call). Obviously, that would be bad. So, my question is: is there a better way? Thanks for any advice, Terry -- Terry Hancock Anansi Spaceworks http://www.AnansiSpaceworks.com/ From duncan at NOSPAMrcp.co.uk Tue Aug 12 04:38:56 2003 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Tue, 12 Aug 2003 08:38:56 +0000 (UTC) Subject: Python vs. C# References: Message-ID: "Joe Cheng" wrote in news:Jq%Za.8237$M6.632214 at newsread1.prod.itd.earthlink.net: > Java and C# have static strong typing. > > Python has dynamic strong typing. So, if you can keep the types of > your objects straight without the help of the compiler, you get the > benefits of a concise syntax while enjoying type safety at runtime. > > Someone correct me if I've gotten it wrong... > You have it about right. C# lets you define functions that take arguments of any type by boxing them as objects. However, to perform almost any operation on these values you have to cast them back to their original type. So a function that takes two objects and adds them together can't work unless you know the type you expected the objects to be. You cannot just add two objects, even if they are of the same type, you have to cast (unbox) them from object back to their real type (and you have to get that type *exactly* right, you can't for example unbox a short as an int) and then operate on them. [A couple of operations work directly on objects, you can convert any object to a string, and compare objects for equality directly]. Python on the other hand will let you do something like adding two objects together, it will perform some permitted conversions automatically, e.g. extending int to float, but it won't attempt to do weird things like parse a string into a number, or for that matter automatically convert a number to a string. Both languages are strongly typed. The drawback with C# is mainly that you have to keep telling the language things that both you and the compiler already know. If I have an ArrayList filled with strings, and I want to pass one of them to a function taking a string argument, I have to explicitly cast the element of the ArrayList back to string. If the cast fails at runtime I get an exception. Why can the compiler not put that cast in silently and give me the same exception at runtime? -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From furliz at libero.it Fri Aug 29 10:19:34 2003 From: furliz at libero.it (Mirco) Date: Fri, 29 Aug 2003 16:19:34 +0200 Subject: python and webcam?? In-Reply-To: References: <3F4F56AB.19EFE5AB@engcorp.com> Message-ID: > > Try this... > http://videocapture.sourceforge.net/ Thanks all, I think this is enought for now :) From skip at pobox.com Mon Aug 11 15:44:33 2003 From: skip at pobox.com (Skip Montanaro) Date: Mon, 11 Aug 2003 14:44:33 -0500 Subject: Reference count In-Reply-To: <007601c3603e$f6bd5d30$0601a8c0@hq.novamens.com> References: <002a01c3603b$73442a90$417290c8@paraopeba> <16183.60555.59705.762835@montanaro.dyndns.org> <007601c3603e$f6bd5d30$0601a8c0@hq.novamens.com> Message-ID: <16183.61985.886580.261961@montanaro.dyndns.org> Pablo> I need to keep a object alive even if its reference count if Pablo> zero. Is there any way to increment its reference count using Pablo> Python code, not Py_INCREF or there is any way to avoid deletion Pablo> of the object? Sure, maintain an extra reference to it: >>> a = 1000 >>> id(a) 6864248 >>> b = a >>> id(b) 6864248 >>> sys.getrefcount(a) 3 >>> sys.getrefcount(b) 3 >>> del a >>> sys.getrefcount(b) 2 Skip From __peter__ at web.de Wed Aug 20 04:53:08 2003 From: __peter__ at web.de (Peter Otten) Date: Wed, 20 Aug 2003 10:53:08 +0200 Subject: what to do when instance of class fails to initialize ? References: Message-ID: Tom Van den Brandt wrote: > If I have an __init__ for a class and the initialisation can't go through > (example: missing or wrong arguments), how do I return an error to the > caller (from main() function)? When I do a return statement in the > __init__ it says __init__ should return None... I can stop the flow with > raise 'BlahBlah'. But then the program exits. Missing arguments raise an exception, for wrong arguments you can use assertions: def __init__(self, color): assert color in ["red", "green", "blue"], "Unknown color" These errors should all be ironed out during the design/debugging phase. It's a good idea to fix them as soon as possible, so for small apps it would be OK to terminate the program immediately. For larger apps, where you do not want programming errors in less important parts or currently unavailable resources to terminate the whole app, you can do somethng like this CONDITION = False WENT_WRONG = None #Make up your own Exception class ConstructionFailed(Exception): pass class Test: def __init__(self, data, condition): if not condition: raise ConstructionFailed self.data = data def useIt(self): print "using", self.data #You can now catch it in your client code: try: test = Test("bla", CONDITION) # how would you access a result from __init__() here? except ConstructionFailed: test = None if test is not WENT_WRONG: test.useIt() However, I don't like exceptions from inside __init__(): The constructor would typically fail if some resources cannot be acquired and you would then end up writing destruction/release code in the constructor. class Test2: def __init__(self, data): self.data = data def useIt(self): print "using", self.data def makeTest2(data, condition): if condition: return Test2(data) else: return None test2 = makeTest2("bla2", CONDITION) if test2 is not WENT_WRONG: test2.useIt() For newstyle classes I think you can also modify the __new__() method to return the WENT_WRONG value, but I haven't done that yet. Peter From pahan at gmx.net Mon Aug 18 18:32:51 2003 From: pahan at gmx.net (PenguinOfDoom) Date: 18 Aug 2003 15:32:51 -0700 Subject: iptables bindings Message-ID: <76590c5.0308181432.64b504cf@posting.google.com> I started writing bindings for libiptc/iptables using Pyrex, but iptables' semantics are more complex than my motivation for this project. I put the code written so far at http://www.people.cornell.edu/pages/pp64/ipytables-0.1-WONTWORK.tar.gz This compiles, and all chain operations work, however libiptc is a horrible mildly documented mess (http://www.opalsoft.net/qos/libiptc/qlibiptc.html). People ask for this sort of thing once in a while, so perhaps somebody would bother to complete this into a usable library. The code is in public domain. From gh at ghaering.de Mon Aug 11 05:24:04 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Mon, 11 Aug 2003 11:24:04 +0200 Subject: wanted: alternative to LDAP In-Reply-To: <200308110616.h7B6G702021709@localhost.localdomain> References: <200308110616.h7B6G702021709@localhost.localdomain> Message-ID: <3F3760B4.9000300@ghaering.de> Anthony Baxter wrote: > I'm looking for something (usable from python) that provides networked > directory/registry type functionality to a bunch of Linux and Solaris servers. > LDAP's one alternative, but the LDAP servers are heavy heavy beasts, so I was > hoping for something that's actually lightweight, rather than "lighter than > X.500". The term "leightweight" doesn't say much to me. I don't care if a process takes 1 or 2 MB ;-) What I do care about is ease of configuration and that's why I use PostgreSQL in places other people use LDAP: system users, mail accounts, mail forwarding, domain management, etc. for a virtual hosting solution. The reason for going to an RDBMS instead of LDAP were for me: a) I know relational databases quite well b) I know some LDAP, but always found it a pain to work with c) The open source tools for editing LDAP data are quite weak The only advantage LDAP would have over a RDBMS to me is that OpenLDAP seems to have integrated replication mechanisms. I reckon you wouldn't call an RDBMS more leightweight than LDAP, but I don't think there are many alternatives apart from LDAP and RDBMS. Well, there's NIS if for some reason you didn't know about it, yet :) -- Gerhard From paulpaterson at users.sourceforge.net Fri Aug 29 19:52:57 2003 From: paulpaterson at users.sourceforge.net (Paul Paterson) Date: Fri, 29 Aug 2003 23:52:57 GMT Subject: Bayesian kids content filtering in Python? References: <20030828161409.V40715@onyx.ispol.com> <87n0dsqqhd.fsf@pobox.com> Message-ID: "John J. Lee" wrote in message news:<87n0dsqqhd.fsf at pobox.com>... > if somebody (children, employees, and other people not to be trusted ;-) > is actually trying to work around your barriers, there are always > likely to be false negatives: sites of a flavour that you've never > seen before that you'd wish would trigger your defences, but won't. I agree - this kind of technology would work best as a filter rather, than a barrier, where you are trying to reduce the number of negative experiences rather than try to block delibrate attempts to circumvent it. > If the filter has never even seen that *kind* of page before, it can't be > expected to work. Unfortunately (or fortunately, depending on the > case at hand), there are many kinds of pages that people want to > censor, and you're not going to block them all. It may work well most > of the time, but is that enough? What's needed here, perhaps, is an > open effort to train on categories of things that people would like to > block. But who would volunteer to visit all those kinds of sites ;) > That might be enough, since I suppose *most* things you're > trying to block, in the case of kids, are not actually targetted at > them, so arms races are not likely to develop. Agreed. In fact, there may be an alternative use where you have it watch your daily surfing habits and then combine it with a web spider to go out and find other site/articles which you might like to read. For this kind of application, false positives and negatives would not be as serious. Too many interesting things to try, not enough time! Paul From tjreedy at udel.edu Mon Aug 11 23:15:32 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 11 Aug 2003 23:15:32 -0400 Subject: Python vs. C# References: Message-ID: "Brandon J. Van Every" wrote in message news:bh9eri$vhr5i$1 at ID-203719.news.uni-berlin.de... > Python advocates tend to pooh-pooh strong typing, Disinformation nonsense. Python objects are more strongly typed than C variables. Does C# have casts? TJR From jjl at pobox.com Sat Aug 9 09:54:42 2003 From: jjl at pobox.com (John J. Lee) Date: 09 Aug 2003 14:54:42 +0100 Subject: problem updating(run) to python2.2 References: <3F341829.3050002@softnet.tuc.gr> Message-ID: <87llu3x7fh.fsf@pobox.com> Peter van Kampen writes: > In article <3F341829.3050002 at softnet.tuc.gr>, grid wrote: > > i have Debian, > > i have python2.1 and when installing python2.2, i run "$/python ",but pc > > run's python2.1.How can i overcome this problem? > > > > thanks > > > > $python2.2 > > (on woody) /usr/bin/python on Debian is a link to the latest version of Python installed from a .deb. IIRC, the .debs makes a soft link from /usr/bin/python, and the Python source tarball makes a hard link /usr/local/bin/python. So if you want 'python' to mean something different, you could just rm /usr/bin/python, then re-link to whichever version you want to run. Watch out -- /usr/local/bin may be ahead of /usr/bin in your PATH, and if you installed your 2.2 from the Python source tarball rather than a .deb, you may have a /usr/local/bin/python too. ls -i is useful to tell if two files are really hard links to the same underlying file. ls -l on my system shows the target of soft links. John From tphhec01 at degas.ceu.hu Sun Aug 24 05:16:27 2003 From: tphhec01 at degas.ceu.hu (Csaba Henk) Date: Sun, 24 Aug 2003 09:16:27 +0000 (UTC) Subject: Double symlinking breaks module import References: Message-ID: In article , Andrew Dalke wrote: > Csaba Henk: >> But >> if I create another symlink myprog3.py -> myprog2.py, and then I invoke >> myprog3.py, I get compliances that mymod is not found. >> >> Is it a bug or policy? > > Python uses the normal file open functions, which automatically > follow links. It doesn't build in the link following code itself. > I suspect your symlink points to the wrong place. Can you > cat the file? The symlink can't be wrong because the python program itself (to which the symlinks refer) starts up; it just doesn't find the module. This question is related to importing modules, and the list of dirs in which the module seeked is a Python internal, so it does not depend only on file functions. How symlinking affect the module search path? As I now, modules seeked in the current dir and standard places. If I invoke the prog via a symlink, the current dir is not the same as for the program (where the module resides also), still the module is found somehow. But not if two symlinks used. Btw, the program with which I have this program, is sketch. Sketch has sketch.py and the module Sketch in /lib/sketch-0.6.15/. It's usually invoked via the symlink /bin/sketch -> ../lib/sketch-0.6.15/sketch.py. My problem occured when I wanted to started sketch via another symlink pointing to /bin/sketch. You can test my report by installing sketch. sketch.py is the following code: import sys if sys.version < '1.5.1': sys.stderr.write("Sorry, Sketch requires at least Python 1.5.1\n") sys.exit(1) import Sketch Sketch.config.sketch_command = sys.argv[0] Sketch.main.main() -- Csaba Set theory is the LSD of mathematics From vanevery at 3DProgrammer.com Tue Aug 12 05:28:30 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Tue, 12 Aug 2003 02:28:30 -0700 Subject: Slogan: Getting Rich Overnight References: Message-ID: Aahz wrote: > In article , > Graham Fawcett wrote: >> "Brandon J. Van Every" wrote in message >> news:... >>> Graham Fawcett wrote: >>>> >>>> "Python: stimulate powerful organisms under your fingertips, >>>> without all the GUI mess!" >>> >>> "Organisms" is easily misread as "orgasms." >> >> ...and GUI is a homonym of "gooey". Was my joke too obscure? >> >> i-thought-it-was-funny-in-context-ly yours, > > The problem was with neither messenger nor message. Was there a problem? -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From syver-en+usenet at online.no Sun Aug 3 19:16:25 2003 From: syver-en+usenet at online.no (Syver Enstad) Date: 04 Aug 2003 01:16:25 +0200 Subject: Python debugger References: <2259b0e2.0308030706.5fd6b86a@posting.google.com> Message-ID: mis6 at pitt.edu (Michele Simionato) writes: > Syver Enstad wrote in message > news:... > > > Dave Kuhlman writes: > > > > > Andrew Chalk wrote: > > > > > > > I am sure that it has been asked before but could someone tell a > > > > > newbie whether there is a Python debugger out there? > > > > > > > > > > See: > > > > > > http://www.python.org/doc/current/lib/module-pdb.html > > > > And in case you don't like using a commandline debugger, you can use > > > pythonwin's debugger or Emacs together with pdb. > > How do I use pdb with emacs? Do you have any reference? Yes, in my head ;-) You basically just do Meta-x and write pdb in the mini-buffer. Emacs queries you for a commandline and off you go. The pdb support is an integrated part of Grand Unified Debugger so that the same menus, shortcut keys applies across all suported debuggers. If you are running windows there are two different problems you will have to solve before pdb will work. 1: The regexp that pdb uses to match the filenames (so that it can popup the file that the instruction pointer is in) is wrong for paths under windows. I am not sure if this is fixed in the latest emacs release (don't think so). 2: NT Emacs has problems with python buffering stdin and stdout, this causes the GUD-PDB statemachine to get into a bad state. I have made some miscelleanous extension to GUD-PDB, like visual breakpoints, enabling more items in the GUD menu and more. -- Vennlig hilsen Syver Enstad From llothar at web.de Mon Aug 25 15:37:03 2003 From: llothar at web.de (Lothar Scholz) Date: 25 Aug 2003 12:37:03 -0700 Subject: ANN: BlackAdder V1.0.0 References: <3f48a498$3$219$fa0fcedb@lovejoy.zen.co.uk> Message-ID: <6ee58e07.0308251137.b0cdd4b@posting.google.com> "BadJake" wrote in message news:<3f48a498$3$219$fa0fcedb at lovejoy.zen.co.uk>... > A limited functionality, freely available demonstration version can be > downloaded from http://www.totalrekall.co.uk or http://www.rygannon.com > Detailed Features I found the previous demo releases to complicated to install (lots of libs that i must get from somewhere els) and to restricted. Hope you (theKompany) learned from this. From adalke at mindspring.com Sun Aug 3 02:09:39 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Sun, 3 Aug 2003 00:09:39 -0600 Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> <73bpv-4f3.ln1@beastie.ix.netcom.com> Message-ID: Dennis Lee Bieber: > I'd swear that the BASIC I learned on -- via a timeshare > Honeywell-Bull using a dial-up from an ASR-33 -- back in 1972 was > interpreted... Well, my background is all microcomputer basics in the 80s, including some (very little) HP BASIC for lab equipment, so I'm not a good judge. Were I to implement a compiled BASIC I would have done the "compile on " you suggested. One of the links described the Dartmouth BASIC commands and they would be easy to implement that way. > Python's compatibility doesn't /feel/ like a different language; > through all the changes in Python, a Python 1.3 program /looks/ like a > Python 2.2+ program. In playing around with some of the new Python 2.3 features, I noticed myself using a more functional style, like d = {"A": 1, "B": 9", ...} # all uppercase keys d.update(dict([(k.lower(), v) for k, v in d.items()])) instead of the more readable and faster for k, v in d.items(): d[k.lower] = v It's easier in Python 2.2+ to make Python code which doesn't look like Python 1.3. Which I think is the version I started with. ;) When I got QuickBasic in 1988 or so, it would run just about all of my old GW-BASIC programs, which was distributed some 5 years previous. But it's true, the GW-BASIC program wouldn't look like a QB program. Thinking some more ... the 1.3 code would have string exceptions, so that's one age indicator. It would use the "while 1 / readline / if not line / break" idiom instead of the more modern 'for line in file'. It didn't have module support, IIRC, and only the regex module for regular expressions. Ahh, and no string methods. That's very noticible when I look at pre-2.0 code. Okay, so the two main things that would make a 1.3-style code stick out is using string.* and raising string exceptions. In other words, I mostly agree with you, but couldn't let you get a complete bye :) > But between early 70s BASIC and what passes for BASIC today looks like > totally different languages. I stopped about 10 years ago. I do recall reading an article by a VB book author saying VB_(N+1) was too different from VB(N) and the differences were driven by marketing and not for good programming reasons. There's also the TrueBASIC folks. I believe they started in the mid-80s and argue their BASIC is essentially the same. > quick glance... Let a non-programmer look at source files from K&K > type BASIC, Visual BASIC, F-IV, F77, and F90... and he likely will be > able to identify the three Fortrans as being related -- but would not > consider K&K to be a relation of VB. Interesting test. Nasty idea: get that same person to judge if Lisp and Scheme are closely related then post the results on c.l.lisp. Andrew dalke at dalkescientific.com From bgailer at alum.rpi.edu Tue Aug 12 13:13:59 2003 From: bgailer at alum.rpi.edu (Bob Gailer) Date: Tue, 12 Aug 2003 11:13:59 -0600 Subject: Howto MACRO in python ? In-Reply-To: <000b01c360ad$ac3bba30$6400a8c0@EVOD31> Message-ID: <5.2.1.1.0.20030812104157.02becd40@66.28.54.253> At 10:42 AM 8/12/2003 +0200, Bill Loren wrote: >I was looking for a guidance about how to code MACROs in python. We do need to know what you mean by MACRO and what you want to accomplish: Macro has MANY meanings: http://frontier.userland.com/stories/storyReader$3281 http://www.macros.com/ http://www.bradchoate.com/past/mtmacros.php In Visual FoxPro there is macro substitution: you assign a character string to a variable (e.g. asdf = 'Joe') the reference it &asdf which substitutes 'Joe". Neat in that it can be used for commands, command parameters, within literal strings, ... Then there are macro assemblers, macro biotics, macro lenses In MS Office macros were the predecessor of VBA There are tools for recording macros (recording user interaction via keyboard and mouse). Bob Gailer bgailer at alum.rpi.edu 303 442 2625 -------------- next part -------------- --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.506 / Virus Database: 303 - Release Date: 8/1/2003 From bokr at oz.net Fri Aug 1 18:23:43 2003 From: bokr at oz.net (Bengt Richter) Date: 1 Aug 2003 22:23:43 GMT Subject: String Replacement References: <7b454334.0308011400.266438f9@posting.google.com> Message-ID: On 1 Aug 2003 15:00:47 -0700, faizan at jaredweb.com (Fazer) wrote: >Hello, > >As some of you might know, I am new to Python. I was finally >successful in using MySQLdb for Python to query the datbase and get a >few results from the query. > >The results will be displayed as HTML and I am sort of confuse din >using the string modules and its functions/modules to replace the \n >with
. I import the string module and I am not soo sure on how to >do the replacing. > >Here's how my code sort of likes: > >import string print repr(DataFromDatabase) # do this to check what you are operating on >string.replace(DataFromDatabase, "\n", "
") print repr(string.replace(DataFromDatabase, "\n", "
")) # to see result >>> import string >>> help(string.replace) Help on function replace in module string: replace(s, old, new, maxsplit=-1) replace (str, old, new[, maxsplit]) -> string Return a copy of string str with all occurrences of substring old replaced by new. If the optional argument maxsplit is given, only the first maxsplit occurrences are replaced. >>Unfortunately, it doesn't work. You are throwing away the result ;-) Regards, Bengt Richter From afriere at yahoo.co.uk Thu Aug 28 03:13:49 2003 From: afriere at yahoo.co.uk (Asun Friere) Date: 28 Aug 2003 00:13:49 -0700 Subject: Celebrity advice References: Message-ID: <38ec68a6.0308272313.3cc72758@posting.google.com> Arthur wrote in message > > ""There are some books so bad, but so plausible and influential, that > periodically trashing them in public is almost an obligation. The really > classic stinkeroos of this kind, like Karl Marx's Das Kapital, exert a weird > kind of seduction on otherwise intelligent people long after their factual > basis has been completely exploded.""" > > I gotta go with with Eric on this. > Wow! You've actually managed to read Marx' _Capital_? What all three volumes? I'm impressed! I'm certain no "otherwise intelligent people" would "periodically [thrash]" a book they haven't read, would they? From hans at zephyrfalcon.org Fri Aug 22 14:25:24 2003 From: hans at zephyrfalcon.org (Hans Nowak) Date: Fri, 22 Aug 2003 14:25:24 -0400 Subject: How does one get "maintenance copies" In-Reply-To: <0FC17BE316F9BB47A704AF96308E09CD12263C@ability-nt.AbilityNT.AbilitySys.com> References: <0FC17BE316F9BB47A704AF96308E09CD12263C@ability-nt.AbilityNT.AbilitySys.com> Message-ID: <3F466014.2080905@zephyrfalcon.org> Robert D. Young wrote: > Pardon my stupidity, I've only used the Windows version of Python and > only via the standard installer at that. However, I've been having a > bear of a time w/2.3 - I even went back to 2.2 to stay productive. I > researched the "bug list" to see if the problems I was experiencing were > known and sure enough, they are (such as the "install to a directory > name with a space" issue that IDLE has). The bug tracker mentions these > are fixed in some form of "maintenance" package. How can I get the > latest fixes and put them into my Windows version? The bugfix releases (2.2.1, 2.2.2, etc) are usually announced on c.l.py.announce and on the Python website. The latest versions can be downloaded there also, for example: http://www.python.org/2.2.3/. 2.3.1 isn't out yet though. Cheers, -- Hans (hans at zephyrfalcon.org) http://zephyrfalcon.org/ From c-b-o-o-m-e-r at tiscali.co.uk Mon Aug 18 11:53:11 2003 From: c-b-o-o-m-e-r at tiscali.co.uk (Christopher Boomer (don't dash!)) Date: Mon, 18 Aug 2003 16:53:11 +0100 Subject: Dictionary assignment References: Message-ID: <3f40fa35$2_2@mk-nntp-2.news.uk.tiscali.com> "Mark Daley" wrote in message news:mailman.1060979551.16837.python-list at python.org... Start by making your code a bit more robust. for key in current.keys(): lookup=self.formats.get() if not format.has_key(lookup): format[lookup]={} print "No such lookup:",lookup # a debugging warning format[self.formats.get()][key] = current[key] You can work from there, depending on what outcome you want in the event of an error... You also have to be sure that the result of get() is a valid key (string, tuple) not, say, a list, which is why you should avoid statements like mylist=tuple(temp). There's a list() like the tuple() you use, so to save more headahes, avoid list= altogether And don't mind him. We don't solve problems, but we do tell you how to. ;-) Christopher Boomer. From harry.pehkonen at hotpop.com Fri Aug 29 16:20:29 2003 From: harry.pehkonen at hotpop.com (Harry Pehkonen) Date: 29 Aug 2003 13:20:29 -0700 Subject: bsddb read-only requires rw access to close? Message-ID: <70df36e9.0308291220.527fcdfc@posting.google.com> Stats: Python2.3 windows2000 professional If I have ``Full Control'' of a bsddb file, no problem: >>> import bsddb >>> a = bsddb.btopen("c:/sharedrw/db/npanxx2pseudo.db", "r") >>> a.close() >>> ... but if I change to read-only access (as in permissions on file): >>> a = bsddb.btopen("c:/sharedrw/db/npanxx2pseudo.db", "r") >>> a.close() Traceback (most recent call last): File "", line 1, in -toplevel- a.close() File "C:\Python23\lib\bsddb\__init__.py", line 101, in close v = self.db.close() DBPermissionsError: (1, 'Operation not permitted') Performing a close() with read/write access with file opened "r" does not change the last-modified time/date. Is this a bug? Thanks! Harry. From newsgroups at jhrothjr.com Fri Aug 1 15:35:52 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Fri, 1 Aug 2003 15:35:52 -0400 Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> <23bcqKAykjK$Ewhy@jessikat.fsnet.co.uk> Message-ID: "Robin Becker" wrote in message news:MM7ikWAxZoK$Ew0N at jessikat.fsnet.co.uk... > In article , John Roth > writes > >> > >> I don't have any data here, but I believe Python is just a little too > >> weakly typed for compiling to float*float type assembler efficiently. > > > >The trick with JITs is that they don't depend on absolute type > >consistency. They depend on the observation that 99.44% of your > >code is type consistent, and that consistency will turn up at run time. So > >the code they generate depends on that discovered consistency, and > >checks in front of each section to discover if the types are what the > >code expects. > > > >If it is, they execute it, if it isn't, they abandon it and go back to > >the intepreter to discover what happened. > > > >John Roth > Yes I suspected they have to do that, but that implies that a discovered > 'float' object must carry along a whole lot of baggage (I guess I mean > be a more generic object) to allow for the testing. Loops without method > or function calls would be good candidates for JIT as methods and > functions could alter attribute types. > > Is the JIT object literally just a union of > > type,values > > or would it be an actual Python object? For example would an > innerproduct be over a pair of lists or would the magic convert these > into actual double arrays. As far as I'm aware, the JIT code doesn't fiddle with the data; it just does the equivalent of assert tests at the beginning of the blocks to verify that it's got the type of object it expects. In other words, it does a very large amount of run-time type checking. This only pays off if it can save even more expense by compiling the code. Now, this is going to be difficult for short segments of code, but it can be quite a time saver if the JIT generated code can make intermediate objects vanish so they don't have to be created just to be discarded a short time later. John Roth > -- > Robin Becker From evan at 4-am.com Tue Aug 12 17:43:05 2003 From: evan at 4-am.com (Evan Simpson) Date: Tue, 12 Aug 2003 16:43:05 -0500 Subject: Python + Zope compared to J2EE and .Net In-Reply-To: <74bd3bc.0308100707.577f2930@posting.google.com> References: <74bd3bc.0308100707.577f2930@posting.google.com> Message-ID: <3F395F69.4070304@4-am.com> Sig wrote: > I would like to promote Zope as good alternative to examine. But I > don't know how I should position Zope as a serious challenger > solution. Is there a hope for Zope in big corporations ? See http://www.zope.com/ZopeClientList for a list of some of the big organizations (such as the Navy, AARP, Bank of America, etc.) that use Zope. I'd say the answer is "YES!" I run a very small corporation, and it works quite well for me, also. Cheers, Evan @ 4-am From pedrosch at gazeta.pl Fri Aug 15 18:33:51 2003 From: pedrosch at gazeta.pl (Drochom) Date: Sat, 16 Aug 2003 00:33:51 +0200 Subject: cPickle alternative? References: Message-ID: "Michael Peuser" wrote in message news:bhj56t$1d8$03$1 at news.t-online.com... > o.k - I modified my testprogram - let it run at your machine. > It took 1.5 seconds - I made it 11 Million records to get to 2 Mbyte. > Kindly > Michael > ------------------ > import cPickle as Pickle > from time import clock > > # generate 1.000.000 records > r=[(('k', 5, 0),), (('*', 0, 0),), (('t', 1, 1),), (('o', 2, 0),), (('t', 3, > 0),), (('a', 4, 0), ('o', 2, 0))] > > x=[] > > for i in xrange(1000000): > x.append(r) > > print len(x), "records" > > t0=clock() > f=open ("test","w") > Pickle.dump(x,f,1) > f.close() > print "out=", clock()-t0 > > t0=clock() > f=open ("test") > x=Pickle.load(f) > f.close() > print "in=", clock()-t0 > --------------------- Hi, i'm really grateful for your help, i've modyfied your code a bit, check your times and tell me what are they TRY THIS: import cPickle as Pickle from time import clock from random import randrange x=[] for i in xrange(20000): c = [] for j in xrange(randrange(2,25)): c.append((chr(randrange(33,120)),randrange(1,100000),randrange(1,3))) c = tuple(c) x.append(c) if i%1000==0: print i #it will help you to survive waiting... print len(x), "records" t0=clock() f=open ("test","w") Pickle.dump(x,f,0) f.close() print "out=", clock()-t0 t0=clock() f=open ("test") x=Pickle.load(f) f.close() print "in=", clock()-t0 Thanks once again:) From mis6 at pitt.edu Sun Aug 10 10:16:26 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 10 Aug 2003 07:16:26 -0700 Subject: Python vs. C# References: Message-ID: <2259b0e2.0308100616.55b651ca@posting.google.com> Brian Quinlan wrote in message news:... > 4. forcing everything into a class is stupid e.g. does anyone really > like > writing Math.sin(x) over sin(x)? I always have thought that putting everything in classes was stupid from a boilerplate point of view; however, it is stupid even from an OOP point of view. Having the possibility of defining functions outside classes is quite useful, for instance in the implementation of multi-methods. Thinking that OOP means "everything is in a class" is a pretty naive point of view, IMHO. Also, I feel OOP in Java to be pretty weak as compared to Python (I am referring to multiple inheritance, metaclasses, etc). Dunno about C#, but I am assuming here that it is on the same foot as Java. Anyway, even if C# was better than Python (which I strongly doubt; if speed is a concern, notice that Python has Psyco, Pyrex, SWIG, Boost, etc. etc.) I would not waste my time in learning something which could disappear in few years (Microsoft's policy in supporting programming languages is well know). Just my $0.02, Michel From ivomirb at hotmail.com Thu Aug 7 01:04:26 2003 From: ivomirb at hotmail.com (Ivo) Date: Thu, 07 Aug 2003 05:04:26 GMT Subject: embedding Python Message-ID: Hi. I want to embed Python 2.3 as a scripting language in my Win32 application. I have few questions: 1) Is it possible to link Python as a static lib? 2) Can I link statically all the modules I want and disable the loading of any additional DLLs? Thanks Ivo From raims at dot.com Wed Aug 27 12:08:25 2003 From: raims at dot.com (Lawrence Oluyede) Date: Wed, 27 Aug 2003 18:08:25 +0200 Subject: newbie References: Message-ID: <87znhvozgm.fsf@voodoo.fake> Rich writes: > I just downloaded the beginner package from the "Python" site, and > would like some advice as to how to begin to learn how to program. I suggest you to take a look at this page if you are a non-programmer: http://python.org/topics/learn/non-prog.html, otherwise look at this: http://python.org/topics/learn/prog.html Have fun! -- Lawrence "Rhymes" Oluyede http://loluyede.blogspot.com rhymes at NOSPAMmyself.com From jjl at pobox.com Tue Aug 12 11:44:45 2003 From: jjl at pobox.com (John J. Lee) Date: 12 Aug 2003 16:44:45 +0100 Subject: Python should try to displace Java References: <3f38fc40$0$13195$edfadb0f@dread15.news.tele.dk> Message-ID: <87y8xyhocy.fsf@pobox.com> Kim Petersen writes: > Brandon J. Van Every wrote: [...] > As far as i've read up on .NET/C# - the language doesn't matter - > whats to stop ppl continuing the programming language they've always > used? [...] The design of the CLR. Implementing Python on the CLR isn't feasible. John From ktilton at nyc.rr.com Fri Aug 22 08:34:58 2003 From: ktilton at nyc.rr.com (Kenny Tilton) Date: Fri, 22 Aug 2003 12:34:58 GMT Subject: What's better about Ruby than Python? References: <3F41505F.69D18CC8@alcyone.com> <66d7kvonvb2n0nqbqahhd5roak7ur81sob@4ax.com> <3f43ef5d_4@127.0.0.1> <3F440A35.9030602@nyc.rr.com> <4o_0b.1665$Ej6.1182@newsread4.news.pas.earthlink.net> <8D01b.1721$Ej6.702@newsread4.news.pas.earthlink.net> <3F44ED2E.9070308@nyc.rr.com> <0V61b.1900$Ej6.1012@newsread4.news.pas.earthlink.net> <3F4504D7.20008@nyc.rr.com> Message-ID: <3F460EC1.1050207@nyc.rr.com> Andrew Dalke wrote: > Kenny Tilton: >>The anti-macronistas are better off with the argument, hey, if you want >>Lisp, use Lisp. Let's keep it simple here. the question for you all is >>how far you want to take Python. > > > But that statement expresses a certain arrogance which grates > against at least my ears. Really? I thought that was non-controversial or I would not have said it. Earlier in this thread I thought I read a Pythonista saying, without contradiction, that Python does not try to be everything. Lisp macros try to be everything. ie, If Lisp does not have something I want, such as C-style enums because I am literally translating a C RoboCup client to Lisp, noproblemo, I just cobble one together, and I can arrange it so the final syntax: (enum CMD_KICK CMD_DASH (CMD_TEAR_OFF_SHIRT 42)...) is close enough to C syntax that the C can be edited into Lisp by changing/moving braces to parens, deleteing all the commas, and hand-hacking the rare symbol=number usage. The point I've made over and over is > that languages which optimize for a single person do not > necessarily optimize for a group of people, especially one > which is scattered around the world and over years. Given > that latter definition, Python is extraordinary advanced, even > further than Lisp is. > > For observational evidence of this, I suggest my own > subfields, computational biology and computational chemisty. > In the first there are bioperl, biopython, biojava, and bioruby, > all with active participants and a yearly confererence organized > by open-bio.org. You do not like? http://www.biolisp.org/ Give it time. It's a chicken-egg thing. In fact, my RoboCup project is a conscious attempt to be the egg for a renaissance in RoboLisp. The RoboCup server was originally a Lisp project, but teams are now almost universally developed in Java or C++. The funny (and great for me!) thing is that all those clients have to parse: "(see 457 ((f l t 10) 12.3 23 2.3 5)..." with parsers, where I just say: (read-from-string ). And I have already heard from one C or Java (they did not say) team that is interested in my code base simply because it is Lisp. We lispniks do look forward to the day when there is a larger Lisp community, and we take great consolation from Python's success (and Perl's and to a lesser degree Ruby's). That tells us there is great unhappiness with Java and C++. It also shows that popularity and dominance in computer languages may not be the advantage it seems to be for OSes. Lisp has been dead for twenty years, but some of us won't use anything else (no macros!) and we even see a trickle of newbies on c.l.l., maybe one a day. That is mighty small number compared to Python or Ruby, but we used to see one a year. I got so curious I started a survey on cliki (turns out Paul Graham gets a lot of credit): http://www.cliki.net/The%20RtLS%20by%20Road I was trying to find out how people ended up trying Lisp in spite of its tiny community and death. > I ask you why. Historical, for one. Lisp has always needed a meg or two of RAM. Even when PCs had 8k, 64k, 128k... so C and Pascal became the languages of the masses. Remember Pascal? C++ was C trying to hop on the OO bandwagon (don't get me wrong, I like OO) and Java hopped on the internet bandwagon (and stayed close to C syntax to win those folks over. Python wins because of its interactive qualty and seamless access to C, and by adopting many cool ideas from more advanced languages--kind of a best of both worlds. Peter Norvig, a lisp biggy, has famously found Python to be equivalent to Lisp (except for runtime speed, IIRC). Think of Lisp as compiled Python. With macros and multi-methods etc etc. But you still have to roll FFI binidngs to access C. I did that for my OPenGL project, using macros which took slightly edited C headers and transformed them into the FFI declarations. The other thing Lisp did not have was cheap graphical workstations with syntax-aware editors and optimizing compilers. So that got it off on the wrong foot. But I look at it this way. Lisp already was a fad language (when folks were all excited about AI) and has already died. But it is still the language of choice for some very talented programmers who know all about the other languages out there, andit is picking up a trickle of interest. And when I look at languages like Perl and Python, I see them adopting new features highly reminiscent of Lisp. I ask you why? :) -- kenny tilton clinisys, inc http://www.tilton-technology.com/ --------------------------------------------------------------- "Career highlights? I had two. I got an intentional walk from Sandy Koufax and I got out of a rundown against the Mets." -- Bob Uecker From zathras at thwackety.com Thu Aug 28 07:38:27 2003 From: zathras at thwackety.com (Michael Sparks) Date: Thu, 28 Aug 2003 12:38:27 +0100 (BST) Subject: can generators be nested? In-Reply-To: Message-ID: Hi, Unfortunately there isn't a way of doing this - the reason is that the act of including the yield keyword in a function/method definition turns the function/method definition into a generator definition. The way you're doing it now: > for i in gen2(): yield i Is the only way of doing it. I asked essentially the same question almost a year ago - I was concerned about the fragility of nesting yields. The fact you can't do this influenced certain aspects on the design of a system I'm working on for work - largely to shield users of my classes from the problem. The original thread where I asked the question is here: * http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&threadm=alqehl%249qv%241%40nntp0.reith.bbc.co.uk&rnum=9&prev=/&frame=on Best Regards, Michael On Wed, 27 Aug 2003, news.west.cox.net wrote: > This doesn't work, but is there any elegant way to do something like this? > > def gen2(): > yield "hello" > > def gen1(): > gen2() > yield "world" > > for i in gen1(): print i > > ---- output ---- > hello > world > > I'm doing it this way now: > > def gen2(): > yield "hello" > > def gen1(): > for i in gen2(): yield i > yield "world" > > > -- > http://mail.python.org/mailman/listinfo/python-list > From gh at ghaering.de Fri Aug 29 12:44:12 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Fri, 29 Aug 2003 18:44:12 +0200 Subject: making extension with MinGW on Windows In-Reply-To: References: Message-ID: <3F4F82DC.5090806@ghaering.de> Sun Wei wrote: > I got this error: > undefined reference to `_imp___Py_NoneStruct' > > But when I used VC++, everything is ok, why??? You're using distutils to compile, right? It not, please try again using distutils. If it still fails, can you post a minimal example source code that fails for you? -- Gerhard From glingl at aon.at Sat Aug 16 09:53:47 2003 From: glingl at aon.at (Gregor Lingl) Date: Sat, 16 Aug 2003 15:53:47 +0200 Subject: How to terminate a TkinterApp correctly? In-Reply-To: References: <3F3DFCF4.5020109@aon.at> Message-ID: <3f3e37c6$0$19888$91cee783@newsreader01.highway.telekom.at> Michael Peuser schrieb: > "Gregor Lingl" schrieb im Newsbeitrag > news:3F3DFCF4.5020109 at aon.at... > >>I'm working on a windows machine >> >>I've written a Tkinter-app ... > Thanks for your remarks and your example. The following solution finally did it: def exit(): global done done = True # so the animation will terminate, but # not immediately! The actual pass through # the loop has to be finished. print "done!" import sys # after_idle seems to be crucial! Waits for terminating # the loop (which is in a callback function) cv.after_idle(sys.exit, (0,)) cv.master.protocol("WM_DELETE_WINDOW", exit) if not usingIDLE: root.mainloop() Regards, Gregor From ark at acm.org Mon Aug 11 16:16:43 2003 From: ark at acm.org (Andrew Koenig) Date: Mon, 11 Aug 2003 20:16:43 GMT Subject: Fun with numbers - dammit, but I want a cast! References: <3f378fac$0$10778$afc38c87@auth.uk.news.easynet.net> Message-ID: Istvan> Will there be a keyword/function for integer division after that? Yes -- a//b is the integer part of a/b. -- Andrew Koenig, ark at acm.org From gh at ghaering.de Mon Aug 25 19:40:07 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Tue, 26 Aug 2003 01:40:07 +0200 Subject: Decoding MIME email. In-Reply-To: <20030825175038.48958.qmail@web13503.mail.yahoo.com> References: <20030825175038.48958.qmail@web13503.mail.yahoo.com> Message-ID: <3F4A9E57.80904@ghaering.de> Thomas Williams wrote: > Hello everyone, my name is Tom W. And, I am new to the > list, and have been using Python for about a year now. > > Anyway, I got a question! I am trying to decode MIME > (base64) email from a POP3 server, but all I get is a > corrupt file. [...] You should be using the email module for this. Here are a few interactive commands that could get you started: >>> from email.Parser import Parser >>> f = file("/tmp/mail.txt") >>> parser = Parser() >>> msg = parser.parse(f) >>> f.close() >>> msg You probably can figure out the rest with the documentation for the email module, otherwise just ask here. Oh, and if your Python doesn't have an email module, it's really time to upgrade :) -- Gerhard From max at alcyone.com Sun Aug 10 04:16:53 2003 From: max at alcyone.com (Erik Max Francis) Date: Sun, 10 Aug 2003 01:16:53 -0700 Subject: PMW 0.8.5 vs Python 2.3 References: Message-ID: <3F35FF75.C01C5591@alcyone.com> Robin Becker wrote: > I'm getting the following error when I attempt to run an app with > Python 2.3. I suppose this was silently ignored under 2.2. With > debugging I see that s==0 in Something else is going on, you get the same error in 2.2: Python 2.2.3 (#1, May 31 2003, 21:31:33) [GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> int(0, 16) Traceback (most recent call last): File "", line 1, in ? TypeError: int() can't convert non-string with explicit base -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ Men and women, women and men. It will never work. \__/ Erica Jong From tjreedy at udel.edu Thu Aug 28 14:58:49 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 28 Aug 2003 14:58:49 -0400 Subject: Celebrity advice (was: Advice to a Junior in High School?) References: Message-ID: "Colin J. Williams" wrote in message news:jKl3b.9017$nw3.311231 at news20.bellglobal.com... > We seem to be straying from Python and/or advice to a you[ng] person, but > the third paragraph [of me] is clearly nonsense. > > To give an example. In Canada, over the next year or more, the Members > of Parliament and the Senators will have to make a choice as to whether > gay marriage is to continue in this country. No threat of force exists. > A decision will be made and the populace will accept it as being more or > less democratic. If the decision is a 'resolution', like the US Congress declaring some week to be 'National Python Week' or whatever*, then your are right. However, the whole purpose of the US movement to enact gay marriage 'laws' is precisely to *enforce* what will be for some new, different, and possibly morally repugnant (to the people 'enforced') behaviors. Alex M. gave just one example (hospitals)**. Terry J. Reedy * I sometimes wonder about the relative cost of getting a Day versus a Week, Month, or Year resolution ;-) ** Further off-topic opinions: keeping intimates apart when sick is cruel; there are nonviolent ways to change old practices; gays are short-sighted to ignore the costs of bringing government violence threats into their relationships. From theller at python.net Thu Aug 7 15:03:40 2003 From: theller at python.net (Thomas Heller) Date: Thu, 07 Aug 2003 21:03:40 +0200 Subject: crossplatform py2exe - would it be useful? References: <3cgdfnzo.fsf@python.net> Message-ID: Alex Martelli writes: > Thomas Heller wrote: > >> Alex Martelli writes: >> >>> Thomas Heller wrote: >>> ... >>>>>> myscript -c "import sys; sys.path.insert(0, sys.executable); import >>>>>> foo" >>> ... >>>>> Sounds like a good idea to me, if a sensible name is chosen for the >>>>> "main module" (I propose 'main':-). >>>> >>>> My choice would have been __main__ :-) Is it really the correct way to >>>> 'import __main__' instead of 'running' it? >>> >>> Well, most main scripts ARE coded with the "if __name__=='__main__':" >>> convention, after all, so an "import __main__" can be seen as a way >>> to just piggyback on that existing convention rather than inventing a >>> new one in addition. So, I concede it's better than "import main". >>> >> >> How would the hook be triggered? The zipimporter code would probably add >> argv[0] to sys.path, and then try to 'import __main__' or something like >> this. The problem is that a standalone executable python would have to >> disable the standard Python command line flags and environment >> variables, but they are parse *before* Py_Initialize() is called. > > Ah, yes, good point. So, the executable needs to know whether to do > the usual commandline and environment processing, or not, _before_ > calling Py_Inizialize. Exactly. And it may even be useful to do specail command line processing, an PY2EXEVERBOSE flag might be useful. > One approach might be to trigger this based > on the executable's own *name* -- do the full commandline and environment > processing if and only if the executable's name starts with (case- > insensitive, probably, to be safe...) the six letters 'python', but > not otherwise. There are, no doubt, other alternative ways, too, but > this one seems dirt-simple and practically sufficient. On windows, where the interpreter is in a dll, providing a custom equivalent to python.exe (as py2exe currently does) is pretty simple. On systems where the interpreter is staically linked, there's no other choice than to recompile and relink the whole pythonm if I understand correctly. >> And I hope that the options set by the command line flags and env vars >> should now come from the __main__ script itself. > > I'm not sure I understand what you mean. Anyway, I do see that if > my 'foobar.exe' is a python.exe + appended zipfile, then running > 'foobar -i' should just put '-i' in sys.argv[1], and NOT gobble it up > to mean "enter interactive mode", for example. You understood. Yes, the command line flags must be passed into sys.argv. But I still want to set the optimize flag and the unbuffered flag at *build* time. I'm quite sure all this cannot be encoded into the filename. Right now, py2exe embeds a struct containing a magic value plus these flags into the exe, just before the zip-archive, but all this unpacking has to be done from C code (because these flags are not writable from Python code), so all this has to be part of the hook. Thomas PS: Since py2exe, even on Linux, doesn't really create a single file executable, there are always some shared libs needed, maybe the first step would be to create a directory containing the interpreter executable with an appended ziparchive, the shared libs needed (zlib.so, maybe more), and a bash script containing something like this (you'll probably see how rusty my *nix skills are nowadays): #!/bin/sh exec python_with_zip -c "< Hi, does anyone know how to change the foreground color of the command prompt through python? For example if i was printing out an error message, I would like it to be red where the normal text color is white. Thanks From gh at ghaering.de Wed Aug 6 07:45:13 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Wed, 06 Aug 2003 13:45:13 +0200 Subject: unsubscribe In-Reply-To: <3BB1EA54E4DD7B49AC9A96E2996A7A166CC00F@SRV501.wakecoll.net> References: <3BB1EA54E4DD7B49AC9A96E2996A7A166CC00F@SRV501.wakecoll.net> Message-ID: <3F30EA49.4020300@ghaering.de> Scott Dewar wrote: > Could you please remove my name from the mail list? Please go here http://mail.python.org/mailman/listinfo/python-list and remove yourself. -- Gerhard From aleax at aleax.it Mon Aug 4 18:17:30 2003 From: aleax at aleax.it (Alex Martelli) Date: Mon, 04 Aug 2003 22:17:30 GMT Subject: member array in c passed to python? References: Message-ID: <_XAXa.28632$cl3.1020849@news2.tin.it> William Hanlon wrote: > Hi, > > I would like to use the Python C API to use python to access functions > originally written in C. The objects that I would like to pass to python > have multi-dimensional arrays. > > How do I include arrays as object member? And how is it declared in the > PyMemberDef array? You can, if you wish, construct and expose a new "array" type from within your extension -- or reuse those already constructed for you by the Numeric package. > If you can not use C arrays, I thought perhaps then I should use Python > tuples or lists, but I don't see how to fill the tuple from the > multi-dimensional arrays. Does anyone have an example of this? You have to know the number of dimensions and proceed accordingly, For example, for a 2-dimensional array of integers you could do something like: PyObject* array_to_list_2d(int **array, int N, int M) { PyObject * temp; PyObject * result = PyList_New(N); for(i = 0; i < N; i++) { PyList_SET_ITEM(result, i, temp = PyList_NEW(M)); for(j = 0; j < M; j++) PyList_SET_ITEM(temp, j, PyInt_FromLong(array[i][j])); } return result; } However, this does need a lot of data copying and object allocation, which you might obviate if you were to use your own data type (or reuse Numeric's) to wrap your existing arrays. Alex From logistix at cathoderaymission.net Thu Aug 28 15:56:16 2003 From: logistix at cathoderaymission.net (logistix at cathoderaymission.net) Date: 28 Aug 2003 12:56:16 -0700 Subject: Windows Remote Log in References: Message-ID: <3c91a864.0308281156.3c895d8d@posting.google.com> Jesse wrote in message news:... > Thanks I'll check this out and also try to further clarify myself. > > > This is a mixture of NT 4 and Win2K Servers. WMI may not be installed > on all the remote systems. > > > We have quite a few NT domains that our servers are spread out over and > sometimes the machine I would execute the script from would not be in > the same Domain and need different Logon Credentials to access the > remote machine. We don't have control over this our primary > responsibility is for the applications that reside on these servers. We > have Administrator Access to the servers but not complete control on how > they are setup. Ahhh the wonderful Politics of Big Business. > > Often certian services for the applications we maintain will need to be > restarted on these remote machines. I've found a way to this this with > a Python Module called WService. In the App I'm making that will reside > on the clients machine they will enter a server name or ip address and > click a button that will restart the req'd service. As long as we are > in the same NT Domain no big deal, but not all servers are in the same > domain and we use different accounts to access them. > > What I need is some way for user to enter the proper credentials so > Python could restart the service on the remote machine. > > If this isn't making sense please disregard and I'll move on to > something a bit easier. > You probably need to logon to the IPC Share to get proper authentication. From the commandline it's "net use \\servername\ipc$ password /USER:domain\username". You could also probably use win32net.netUseAdd() to do this natively in Python, but I've never tried this. From cben at techunix.technion.ac.il Sun Aug 17 15:37:09 2003 From: cben at techunix.technion.ac.il (Beni Cherniavsky) Date: Sun, 17 Aug 2003 22:37:09 +0300 (IDT) Subject: Py2.3: Feedback on Sets In-Reply-To: Message-ID: <20030817193709.460B22210E@techunix.technion.ac.il> In comp.lang.python, you wrote: >I've gotten lots of feedback on the itertools module >but have not heard a peep about the new sets module. > >* Are you overjoyed/outraged by the choice of | and & > as set operators (instead of + and *)? > ``&`` and ``|`` are good. In math too, the union/intersection operators are very similar to the or/and opearators. The later are overloaded as addition/mulitplication in boolead algebra only because the or/and operators are so similar and inconvenient. This overloading is quite misguided because these operators don't define a field or even a ring (xor/and would do that). >* Is the support for sets of sets necessary for your work > and, if so, then is the implementation sufficiently > powerful? > I used sets very heavily in my last project, including nested sets. The implementation is powerful enough. The concept of sets themselves became too weak at some moment (I needed to associate data with each element) but I got so used to the powerful union/intersection/etc. operations that I implemented__ them over dicts... __ http://www.technion.ac.il/~cben/python/dsets.py I suspect that the set/dict boundary will be crossed quite frequently by people; it's hard to know beforehand that you'll never want to asssociate values with the keys. Besides, set operators are a very powerful and high-level way to manipulate dicts. So perhaps it'd be a good idea to integrate sets with dicts more along the lines of my dsets module. So that dicts grow in power as well. The biggest lesson from my dsets module is that for set operations on dicts, you really want to choose how to handle collisions (both sets have the same key so two values contend for the result). And you want to choose it per-operation. It's OK if you can only do it on named methods but not on overloaded operators (there is no good syntax for that). My dsets module treats iterables (including sets) as dsets whose values are `None`. This direction also suggests that sets could be true dicts: when you omit the value in a dict initializer, it defaults to `None`. But after some thinking I think it would be suboptimal. One reason: it means you should to choose a collision function even when working with sets whose value are meaningless, which makes little sense. I now think it'd be better to separate them (by presence of the __getitem__ method) and only give meaning to collision functions if both arguments have values. So: - `` & `` means what it means now. - `` & `` means subset of dict. - ``.intersection(, ) means what it means in dsets. But there are more complications: - `` | `` must mean union of sets because for keys not in you have no value. - Should `` | ``, `` & ``, etc. raise exception on collisions (as now) or simply return sets? I'll try to release a working design soon. Feedback most welcome. >* Is there a compelling need for additional set methods like > Set.powerset() and Set.isdisjoint(s) or are the current > offerings sufficient? > Generating the full powerset seems pretty useless. `isdisjoint` sounds like a good idea since it can be implemented more effeciently than ``not a & b``. >* Does the performance meet your expectations? > I think so. Almost half of my program's time is spent in set.py according to the profiler but when I optimized the sets module (and my dsets) with psyco, things got several percent slower. Is this a good sign ?-) >* Do you care that sets can only contain hashable elements? > No more than I care for dicts containing only hashable keys. How else could you define it? What I do like is the auto-copying of mutable sets when used a set items; I wouldn't mind something like this to be extended into other Python types (primarily dicts). >* How about the design constraint that the argument to most > set methods must be another Set (as opposed to any iterable)? > I'd go for any iterable where it's enough and require __contains__ where that's needed. I think together this should cover all method's needs. I think it's better not to add artificail checks, so that other set-alike types can be used with sets (primarily mapping or set-alike types). >* Are the docs clear? Can you suggest improvements? > It's been a lot of time since I had to read them which is probably a good sign. >* Are sets helpful in your daily work or does the need arise > only rarely? > Helpful. Since they were released on 2.2, I feel free to import sets whenever it reflects my meaning clearer than dicts, even when I don't use any fancy operations. I find the code more readable this way. And sets of sets (or ImmutableSets as dict keys) are very helpful when you need them. -- Beni Cherniavsky From peter at engcorp.com Sat Aug 23 03:57:48 2003 From: peter at engcorp.com (Peter Hansen) Date: Sat, 23 Aug 2003 03:57:48 -0400 Subject: Testing References: <1061613394.311279@www.vif.com> Message-ID: <3F471E7C.226765E9@engcorp.com> planeglenn wrote: > > Hello, I am trying a test to se if this works. > > Thank you. Unless you are testing something specific to the c.l.p newsgroup, please use the misc.test newsgroup instead. That's what it's there for. Thank you. From CousinStanley at hotmail.com Sat Aug 2 15:02:48 2003 From: CousinStanley at hotmail.com (Cousin Stanley) Date: Sat, 2 Aug 2003 12:02:48 -0700 Subject: FOUND! how to attach to running instances of Internet Explorer References: Message-ID: gcash .... Your win32 script for connecting to open IE instances works fine for me using .... Win98_SE Python 2.2.1 Displays info for open IE instances for both local and remote pages .... -- Cousin Stanley Human Being Phoenix, Arizona From cben at techunix.technion.ac.il Wed Aug 20 04:10:58 2003 From: cben at techunix.technion.ac.il (Beni Cherniavsky) Date: Wed, 20 Aug 2003 11:10:58 +0300 (IDT) Subject: Py2.3: Feedback on Sets In-Reply-To: <001701c3652c$2c621e20$e841fea9@oemcomputer> References: <20030817193709.460B22210E@techunix.technion.ac.il> <001701c3652c$2c621e20$e841fea9@oemcomputer> Message-ID: Raymond Hettinger wrote on 2003-08-17: > [Beni Cherniavsky] > > > And sets of sets (or ImmutableSets as dict keys) are very helpful when you > > need them. > > Good. I've gotten almost no replies from people using sets of sets. > For the record, here is the central data-type of my program (recognition of lines from a bitmap): pixel ::= (x, y) tuple node ::= set of pixels graph.nodes = {node: set of neighbour nodes} dict graph.edges = {set of 2 nodes: set of pixels} dict So I have two dicts, one mapping sets to sets of sets and the other mapping sets of sets to sets ;-). The the fact that sets can be dictionary keys is perhaps even more useful than sets being set elements. P.S. I wonder what happens if I do:: s = Set([1, 2]) s.add(s) how badly will operations on it break then? Perhaps the docs should mention that circular set structures are a bad idea (see the quote in my signature ;). -- Beni Cherniavsky A word of warning about matrices - *each column must have the same number of elements in it*. The world will end if you get this wrong. -- EQN user manual, Brian W. Kernighan & Lorinda L. Cherry From achrist at easystreet.com Sun Aug 3 12:57:25 2003 From: achrist at easystreet.com (achrist at easystreet.com) Date: Sun, 03 Aug 2003 09:57:25 -0700 Subject: PyChecker work with Python 2.3? References: <3F2C5300.FA223CBA@easystreet.com> <3F2CBCC2.3FC51D57@easystreet.com> Message-ID: <3F2D3EF5.DAF09C1C@easystreet.com> Gerhard H?ring wrote: > > > If you think you are so smart, why don't you use your time more > economically then and just try it out? > If I upgrade python to 2.3 I also must upgrade: ctypes py2exe pysqlite win32all wxPython With a dial-up connection that's quite a bit of download time. Then, if there is a problem, I must roll back: python ctypes py2exe pysqlite win32all wxPython And hope that everything rolls back ok. Meanwhile, I've got a reasonably busy application-level to-do list going. Better to ask a question than worry about all that, no? Al From irmen at -NOSPAM-REMOVETHIS-xs4all.nl Sun Aug 3 08:23:06 2003 From: irmen at -NOSPAM-REMOVETHIS-xs4all.nl (Irmen de Jong) Date: Sun, 03 Aug 2003 14:23:06 +0200 Subject: Determining if a filename is greater than X characters In-Reply-To: References: <93f5c5e9.0308021815.44c57a2d@posting.google.com> Message-ID: <3f2cfea8$0$49106$e4fe514c@news.xs4all.nl> Cy Edmunds wrote: > filename = "abcdefgh" > if len(filename) > 6: > filename = filename[:6] > print filename > abcdef The if is not necessary, just use filename=filename[:6] --Irmen From jimmy at retzlaff.com Mon Aug 11 19:47:23 2003 From: jimmy at retzlaff.com (Jimmy Retzlaff) Date: Mon, 11 Aug 2003 16:47:23 -0700 Subject: stretching list comprehensions Message-ID: Simon Burton (simonb at webone.com.au): ... > >>> nums = [ x+y for x in range(y) for y in range(10) ] > Traceback (most recent call last): > File "", line 1, in ? > NameError: name 'y' is not defined > > Well.. Is there an inherent reason why this could/should not be made to > work? Yes - y has not yet been defined when you try to start iterating over range(y). Turn it around and it works fine: >>> nums = [ x+y for x in range(10) for y in range(x) ] >>> nums [1, 2, 3, 3, 4, 5, 4, 5, 6, 7, 5, 6, 7, 8, 9, 6, 7, 8, 9, 10, 11, 7, 8, 9, 10, 11, 12, 13, 8, 9, 10, 11, 12, 13, 14, 15, 9, 10, 11, 12, 13, 14, 15, 16, 17] Jimmy From essai1 at mci.local Fri Aug 1 05:57:24 2003 From: essai1 at mci.local (News M Claveau /Hamster-P) Date: Fri, 1 Aug 2003 11:57:24 +0200 Subject: .zip files sample manip Message-ID: Bonjour ! J'ai publi? dans "announce", mais, comme cela n'appara?t pas (???), je donne l'adresse ici : http://mclaveau.com/ress/python/zipmci.htm Dans ce gros exemple, il y a, notamment, la suppression des fichiers, la r?affectation des date-time des fichiers extraits, etc. @-salutations -- Michel Claveau From janeaustine50 at hotmail.com Wed Aug 13 14:51:31 2003 From: janeaustine50 at hotmail.com (Jane Austine) Date: 13 Aug 2003 11:51:31 -0700 Subject: robust clean-up with SIGTERM (was Re: Again, how to write a cleanup function for a module in C ) Message-ID: I'm writing a cgi script. The user can push the stop button at any moment while the page is loading, and the apache will raise SIGTERM and then SIGKILL in 3 secs. And the garbage is not collected automatically when the signals are raised. It's an abnormal termination. I need to clean up a few things(like closing the db connection) before the interpreter terminates. How do I? And according to Alex's suggestions... (see my questions below) "Alex Martelli" wrote: [snip] > > Are you implying that atexit doesn't? Run the following script: > > import atexit > def f(*args): > print 'f',args > atexit.register(f,'goo','bar','baz') > 1/0 > > The output I see for it is as follows: > > [alex at lancelot src]$ python2.2 a.py > Traceback (most recent call last): > File "a.py", line 5, in ? > 1/0 > ZeroDivisionError: integer division or modulo by zero > f ('goo', 'bar', 'baz') > [alex at lancelot src]$ > > > Signals are nastier -- by default they terminate the process > WITHOUT cleanup. For example, if instead of the 1/0 you have > at the end of the script: > > import os, signal > os.kill(os.getpid(), signal.SIGIO) > > then f won't get run. Easy solution (won't work all of the > time, but, pretty often): handle the signal to turn it into > an exception! e.g. change the above two lines to: > > import os, signal > def sig2exc(sig, frm): raise SystemError(sig) > signal.signal(signal.SIGIO, sig2exc) > os.kill(os.getpid(), signal.SIGIO) > > and f will again execute. > > [snip] > > So, handle the signal, and make the program die "cleanly" with the > exception of your choice -- THEN, cleanup code DOES run. > [snip] This "signal to exception translation" looks nice. But Alex said "won't work all of the time, but, pretty often". I am afraid to use this method if its safety is not guaranteed. I wonder in what cases it does not work, and how I can make it work always. From aleax at aleax.it Thu Aug 28 12:23:04 2003 From: aleax at aleax.it (Alex Martelli) Date: Thu, 28 Aug 2003 16:23:04 GMT Subject: celebrity advice References: Message-ID: Arthur wrote: > Owen write - [didn't get Owen's original so I'm hijacking Arthur's reply...] >>I don't see the link with Python, but anyway... >>Very long ago, some books where burnt in public, >>for "religious" reasons, later for political Very long as in, Winter 2001/2002, for example? That's when a book burning (of Harry Potter books) was held by the "Christ Community Church", for example. As Kenneth Paulson points out in http://www.freedomforum.org/templates/document.asp?documentID=15610 , as long of course as the books you burn belong to you, that's a form of political speech which is just as acceptable as burning a flag. (If you burn a book you have not legally purchased, just as if you buy a flag which belongs to somebody else, the issue is obviously totally different). Thus: >>reasons. Hopefully these old practice have >>disappeared and will never come back. Wanna bet? Very little has changed over the last couple of years to suggest the "Christ Community Church" and similar organizations now believe that book-burning is not warranted any more. Just like flag-burning, I'm quite confident it WILL happen again (and be roughly as ineffective as in all past cases, except perhaps where armed force underpins it, normally through government sponsorship). Alex From urbanlegend at ozemail.com.au Tue Aug 5 15:51:53 2003 From: urbanlegend at ozemail.com.au (M Wells) Date: Wed, 06 Aug 2003 05:51:53 +1000 Subject: Unable to run IDLE from 2.3? References: <1akviv4cpectdogklmuupg7rc37lhe1pc7@4ax.com> <3f2fefc8$0$6527$6c56d894@sisyphus.news.be.easynet.net> Message-ID: <9j20jv0v49gmud6kvtadl63l313biv6ctd@4ax.com> On Tue, 5 Aug 2003 19:56:42 +0200, "Bernard Delm?e" wrote: >> Has anyone else experienced this and can anyone give me some advice on >> how to fix it? > >Works for me, on Win2000. I've never used XP, but I'd suggest: > >*) opening a command-prompt box >*) cd'ing to %PYTHON_HOME%\lib\idlelib > (where PYTHON_HOME=C:\python23 unless changed at install time) >*) ..\..\python idle.py > >watch out for error messages, and let us know... Hi Bernard, Well, yes, it seems there is a problem. Having followed your instructions, I get the following error(s): C:\Python23\Lib\idlelib>..\..\python idle.py Traceback (most recent call last): File "idle.py", line 23, in ? idlelib.PyShell.main() File "C:\Python23\lib\idlelib\PyShell.py", line 1264, in main root = Tk(className="Idle") File "C:\Python23\lib\lib-tk\Tkinter.py", line 1564, in __init__ self.tk = _tkinter.create(screenName, baseName, className) _tkinter.TclError: Can't find a usable init.tcl in the following directories: {c:\program files\ruby\tcl\lib\tcl8.3} {c:\program files\ruby\tcl\lib\tcl8.3} {c:/program files/ruby/tcl/lib/tcl8.4} C:/Pytho n23/lib/tcl8.4 C:/lib/tcl8.4 C:/library c:/program files/ruby/tcl/lib/tcl8.3/init.tcl: version conflict for package "Tcl": have 8.4, need 8.3 version conflict for package "Tcl": have 8.4, need 8.3 while executing "package require -exact Tcl 8.3" (file "c:/program files/ruby/tcl/lib/tcl8.3/init.tcl" line 19) invoked from within "source {c:/program files/ruby/tcl/lib/tcl8.3/init.tcl}" ("uplevel" body line 1) invoked from within "uplevel #0 [list source $tclfile]" c:/program files/ruby/tcl/lib/tcl8.3/init.tcl: version conflict for package "Tcl": have 8.4, need 8.3 version conflict for package "Tcl": have 8.4, need 8.3 while executing "package require -exact Tcl 8.3" (file "c:/program files/ruby/tcl/lib/tcl8.3/init.tcl" line 19) invoked from within "source {c:/program files/ruby/tcl/lib/tcl8.3/init.tcl}" ("uplevel" body line 1) invoked from within "uplevel #0 [list source $tclfile]" This probably means that Tcl wasn't installed properly. It appears the fact that I also have ruby installed is causing the problem? Should I uninstall ruby, do you think, and try re-installing python? I'd prefer to have access to both of them, but Python is the language I want to concentrate on at present. Thank you for your help! Much warmth, Murray http://www.planetthoughtful.org Building a thoughtful planet, one snide comment at a time... From peter at engcorp.com Thu Aug 14 09:28:30 2003 From: peter at engcorp.com (Peter Hansen) Date: Thu, 14 Aug 2003 09:28:30 -0400 Subject: 3 new slogans References: <3F3B5F80.3E7DE934@hotmail.com> <5f5c82ec.0308140502.36af5ce6@posting.google.com> Message-ID: <3F3B8E7E.F6713CEB@engcorp.com> Matt Smith wrote: > > Alan Kennedy wrote in message news:<3F3B5F80.3E7DE934 at hotmail.com>... > > Graham Fawcett wrote: > > > > > or, with apologies to Clarke, > > > > > > "Any sufficiently advanced technology is indistinguishable from Python" > > > > I *really* like this one. > > > > Only problem is, you have to be a sci-fi head to get it: No problem > > for me: I've been reading Arthur C. Clarke since I was 8 years old. > > > > regards, > > those all suck, > > how about..... > > Get wrapped up in python > > nah thats shit too, emmm I once tried out "Wrap Python around your problem and crush it!" Yours is shorter though. (Not that length matters! ;-) -Peter From appleseed-cast~NOSPAM~ at breathe.com Sat Aug 2 23:04:13 2003 From: appleseed-cast~NOSPAM~ at breathe.com (paul) Date: Sun, 3 Aug 2003 03:04:13 +0000 (UTC) Subject: Dealing with paths (Unix question) Message-ID: hey there all! i'm writing some little programs, and i'd like to know about how to deal with directories on unix. i've read up on this, but the docs don't really mention much on it. do i use the pickle module, or something? what i'd like to do is read in a path, say /home/username/images/ and that path contains a dir called downloads and some png files, and it also contains another dir called icons, which holds jpg, png and gif files. Now, is it posible to go through that top directory and recursively go through /icons/ and /downloads/ and pick out all files of a certain extension(only png files, for example)? something like: for each_file in /home/username/images: if image_extension is png: add image path to list but as i said, i need something to work recursively though an arbitrary number of directories. sorry if i wan't too clear here :/ if anyone can post some clues on the modules/methods i'd use, and maybe some example code, that'll be *very* much appreciated! thanks for reading. paul. From swenggsri at yahoo.com Mon Aug 18 16:47:47 2003 From: swenggsri at yahoo.com (Sriram Chadalavada) Date: 18 Aug 2003 13:47:47 -0700 Subject: Pmw BLT problems - addendum Message-ID: Oops. Should have mentioned in my post.. I am using a Redhat 9 machine with python2.2, PMW1.2 and BLT2.4z. Thanks, Sriram From borcis at users.ch Mon Aug 4 13:42:23 2003 From: borcis at users.ch (Borcis) Date: Mon, 04 Aug 2003 19:42:23 +0200 Subject: Bewildered graphs References: <3F06BF7C.8DC6A978@noaa.gov> <87k7awk8ft.fsf@pobox.com> Message-ID: <3F2E9AFF.4070605@users.ch> John J. Lee wrote: > hwlgw at hotmail.com (Will Stuyvesant) writes: > [...] > >>You are thinking about generating a .PNG or .JPG or .GIF or something >>like that? >> >>I have an idea: if your app is running on a web server cluster >>already, how about generating dynamic web pages displaying the graph. >>You could for example display this whole picture with SVG > > [...] > >>this. Note the BIG advantage of such a web application: everybody can >>use it with their browser; no installations, compilations, > > > I just tried Mozilla Firebird 0.6 and Konqueror 3.1, and neither has > built-in SVG support. Indeed, only a few experimental browsers have (partial) built-in SVG support. Most usually, support is acquired with the adobe SVG plugin - but beware that it doesn't fit all and requires an installation. Otoh Batik can be used server-side to render the SVG to a pixel format if the browser doesn't support it, iirc. If pdf is an option I believe it deserves mention that the reportlab package is very much designed to help produce similar on-the-fly web graphics in pdf. From bokr at oz.net Fri Aug 15 23:46:54 2003 From: bokr at oz.net (Bengt Richter) Date: 16 Aug 2003 03:46:54 GMT Subject: Eight Queens Puzzle by Magnus Lie Hetland References: <215fa0fc.0308130557.7f1c950b@posting.google.com> <3f3c1007$0$177$a1866201@newsreader.visi.com> <3F3CC067.5010102@users.ch> Message-ID: On 15 Aug 2003 20:32:05 GMT, bokr at oz.net (Bengt Richter) wrote: >On Fri, 15 Aug 2003 13:13:43 +0200, Borcis wrote: > >>Grant Edwards wrote: >> >>>>BTW, my version got all 92 solutions in < 155ms on a 300mhz P2 without >>>>attempting to optimize ;-) (just the call to doqueens that is, not including >>>>import time). >>> >>> >>> Someday I want to modify it to keep a list of solutions and eliminating all >>> the ones that are mirror images or rotations. >> >>This will give you 12 solutions, one of which possesses an internal >>2-fold symmetry, so 92 = 11*8 + 1*8/2. >> >This version discovers the 12 unique ones: (not too tested, and probably has some redundancies ;-) >This one does use generators ;-) > I decided to see how it would go if I did the same thing using a set of position tuples to represent a board. I found that the strict ordering of the bitmap in a long was doing stuff I wanted (i.e., allowing me to use it as a unique dict key), so I wound up representing solutions as tuples of the set tuples, sorted. I changed the printout to print any of the 92 showing a selected unique solution along with the transformation(s) to transform the unique to the other. I guess I might think that a set of small integers might map nicely to bits in an int or long and back, and might be useful as a hidden optimization. Another useful thing might be to make a set hashable by sorting the element list and hashing that as a tuple, the way I did manually. Of course it wouldn't always work, but if e.g., the underlying representation was a bit vector, it could work fast. You'd want a coercion method to accept a long or int as a bit vector integer set representation, or maybe an as_bitvec property that you could operate through, e.g., mySet = sets.Set() mySet.as_bitvec |= 0xff could mean the same as msSet = sets.Set() mySet |= sets.Set(range(256)) ====< queenset.py >======================================================== # board now represented by set of (r,c) tuples # signifying queen placement with rows and columns # in range(8) -- i.e., [0..7) # # map of board positions: # 0,0 0,1 0,2 0,3 0,4 0,5 0,6 0,7 # 1,0 1,1 1,2 1,3 1,4 1,5 1,6 1,7 # 2,0 2,1 2,2 2,3 2,4 2,5 2,6 2,7 # 3,0 3,1 3,2 3,3 3,4 3,5 3,6 3,7 # 4,0 4,1 4,2 4,3 4,4 4,5 4,6 4,7 # 5,0 5,1 5,2 5,3 5,4 5,5 5,6 5,7 # 6,0 6,1 6,2 6,3 6,4 6,5 6,6 6,7 # 7,0 7,1 7,2 7,3 7,4 7,5 7,6 7,7 # import sets class Board(sets.Set): def excluding(self, q): ret = self.copy() ret.discard(q) return ret threatfrom = {} # still a dict, now of sets queenat = {} # also a dict of sets, just to get the & and | operations for row in xrange(8): for col in xrange(8): queenat[row,col] = Board([(row,col)]) threat = Board() for r in xrange(8): for c in xrange(8): if r==row or c==col or abs(r-row)==abs(c-col): threat.add((r,c)) threatfrom[row,col] = threat def sollines(sol): ret = ['+---'*8+'+'] for r in range(8): ret.append('| %s |' % ' | '.join(['%s'%(' Q'[(r,c) in sol]) for c in range(8)])) ret.append(ret[0]) return ret def printsol(sol): print '\n'.join(sollines(sol)+['']) def printpair(sola, solb, sep=' '): for lina, linb in zip(sollines(sola), sollines(solb)): print '%s%s%s'%(lina,sep,linb) def solok(sol): """check that each queen doesn't threaten the rest""" for row in range(8): for col in range(8): q = (row, col) if q in sol: if Board(sol).excluding(q) & threatfrom[row,col]: return False return True def doqueens(): solutions = [] # list of sorted queen position tuples (overall list not sorted here) def tryplace(board, row, cols): for col in cols: if (board&threatfrom[row,col]): continue qboard = board|queenat[row,col] if row<7: xcols = cols[:] xcols.remove(col) tryplace(qboard, row+1, xcols) else: rclist = list(qboard) rclist.sort() solutions.append(tuple(rclist)) tryplace(Board(), 0, range(8)) return solutions rotates = ( ((lambda r,c:(c, 7-r )), 'R+90'), # old->ccw->new ((lambda r,c:(7-c, r )), 'R-90'), # old->cw->new ((lambda r,c:(7-r, 7-c )), 'R+-180'), ) flips = ( ((lambda r,c:(r, 7-c )), 'E-W'), ((lambda r,c:(c, r )), 'NE-SW'), ) def combo(): for flip in flips: yield flip for rot in rotates: yield rot for flip in flips: for rot in rotates: label = '%s, %s'%(flip[1],rot[1]) def f(r,c,flip=flip[0], rot=rot[0]): return rot(*flip(r,c)) yield f, label def transforms(sol): for fliprot, label in combo(): board = Board() for r in range(8): for c in range(8): if (r,c) in sol: board |= queenat[fliprot(r,c)] rclist = list(board) rclist.sort() yield tuple(rclist), label if __name__ == '__main__': solutions = doqueens() solutions.sort() # for some kind of consistency unique = {}; transformed = {} ucount=0 for sol in solutions: if sol in unique or sol in transformed: continue ucount+=1 unique[sol]=ucount for tsol, label in transforms(sol): if tsol in transformed: continue transformed[tsol] = sol, label loop = '' printmode = '-u' for i92, sol in enumerate(solutions): assert solok(sol) # just for warm fuzzies if printmode=='u' and sol not in unique: continue if loop in ['']: while 1: loop = raw_input('\nEnter => next, a => all, u => unique only (-u off), q to quit: ') if loop in ('u', '-u'): printmode = loop if loop in ['','a','q']: break if loop =='q': break if sol in unique: print '\n====[ Unique Solution %s (orig %s/92) ]\n====[ %r ]====\n'%( unique[sol], i92+1, sol) printsol(sol) else: usol, label = transformed[sol] print ( '\n Original solution # %s/92' ' <== transform %s of unique solution # %s:\n'%( (i92+1), label, unique[usol]) ) printpair(sol, usol) ========================================================================= It has prettier output: [20:38] C:\pywk\clp>queenset.py Enter => next, a => all, u => unique only (-u off), q to quit: ====[ Unique Solution 1 (orig 1/92) ] ====[ ((0, 0), (1, 4), (2, 7), (3, 5), (4, 2), (5, 6), (6, 1), (7, 3)) ]==== +---+---+---+---+---+---+---+---+ | Q | | | | | | | | +---+---+---+---+---+---+---+---+ | | | | | Q | | | | +---+---+---+---+---+---+---+---+ | | | | | | | | Q | +---+---+---+---+---+---+---+---+ | | | | | | Q | | | +---+---+---+---+---+---+---+---+ | | | Q | | | | | | +---+---+---+---+---+---+---+---+ | | | | | | | Q | | +---+---+---+---+---+---+---+---+ | | Q | | | | | | | +---+---+---+---+---+---+---+---+ | | | | Q | | | | | +---+---+---+---+---+---+---+---+ Enter => next, a => all, u => unique only (-u off), q to quit: ====[ Unique Solution 2 (orig 2/92) ] ====[ ((0, 0), (1, 5), (2, 7), (3, 2), (4, 6), (5, 3), (6, 1), (7, 4)) ]==== +---+---+---+---+---+---+---+---+ | Q | | | | | | | | +---+---+---+---+---+---+---+---+ | | | | | | Q | | | +---+---+---+---+---+---+---+---+ | | | | | | | | Q | +---+---+---+---+---+---+---+---+ | | | Q | | | | | | +---+---+---+---+---+---+---+---+ | | | | | | | Q | | +---+---+---+---+---+---+---+---+ | | | | Q | | | | | +---+---+---+---+---+---+---+---+ | | Q | | | | | | | +---+---+---+---+---+---+---+---+ | | | | | Q | | | | +---+---+---+---+---+---+---+---+ Enter => next, a => all, u => unique only (-u off), q to quit: Original solution # 3/92 <== transform NE-SW of unique solution # 2: +---+---+---+---+---+---+---+---+ +---+---+---+---+---+---+---+---+ | Q | | | | | | | | | Q | | | | | | | | +---+---+---+---+---+---+---+---+ +---+---+---+---+---+---+---+---+ | | | | | | | Q | | | | | | | | Q | | | +---+---+---+---+---+---+---+---+ +---+---+---+---+---+---+---+---+ | | | | Q | | | | | | | | | | | | | Q | +---+---+---+---+---+---+---+---+ +---+---+---+---+---+---+---+---+ | | | | | | Q | | | | | | Q | | | | | | +---+---+---+---+---+---+---+---+ +---+---+---+---+---+---+---+---+ | | | | | | | | Q | | | | | | | | Q | | +---+---+---+---+---+---+---+---+ +---+---+---+---+---+---+---+---+ | | Q | | | | | | | | | | | Q | | | | | +---+---+---+---+---+---+---+---+ +---+---+---+---+---+---+---+---+ | | | | | Q | | | | | | Q | | | | | | | +---+---+---+---+---+---+---+---+ +---+---+---+---+---+---+---+---+ | | | Q | | | | | | | | | | | Q | | | | +---+---+---+---+---+---+---+---+ +---+---+---+---+---+---+---+---+ Regards, Bengt Richter From sscherer at rocketmail.com Wed Aug 20 19:55:36 2003 From: sscherer at rocketmail.com (Bgc) Date: 20 Aug 2003 16:55:36 -0700 Subject: QuickTimeTcl Message-ID: Hi All, I'm interested in producing educational applications with Python. Of special interest is the playback of video, something that has as of yet eluded me. I'm wondering what kind of access Python has to the Tcl scripting language, because of the following project: http://hem.fryistorg.com/matben/qt/ http://sourceforge.net/projects/quicktimetcl/ (I hope that URL is correct; google for QuicktimeTcl if not) I understand (actually, I'm just beginning to explore) Python's wrapper access to Tk, but I'm sort of confused about Python's access to the Tcl scripting language. Is there a similar wrapper for the Tcl language, and if so, can anyone suggest a reasonable process for creating a Python wrapper for QuicktimeTcl? Thanks, Steve From pythonguy at Hotpop.com Wed Aug 13 02:56:43 2003 From: pythonguy at Hotpop.com (Anand Pillai) Date: 12 Aug 2003 23:56:43 -0700 Subject: Python should try to displace Java References: Message-ID: <84fc4588.0308122256.419af04f@posting.google.com> Sounds like being pragmatic to you means being paranoid also. Anand "Brandon J. Van Every" wrote in message news:... > Doug Tolton wrote: > > On Mon, 11 Aug 2003 18:43:08 -0700, "Brandon J. Van Every" > >> > >> - in 5 years, nobody will be doing significant amounts of new > >> application development in C++. The writing is on the wall: garbage > >> collection is essential. Any C++ code will be support and legacy > >> libraries. > > > > That's a ridiculous blanket statement. People will be doing C++ > > development for a long time beyond that. There are people still > > writing Cobol for crying out loud. > > Do you honestly believe that people are doing a significant amount of new > application development in Cobol, as opposed to maintenance work? > > >> - Microsoft is already implementing said strategy across all levels > >> of the company today. Microsoft developers don't do much C++ > >> development anymore. Various upcoming products are being written > >> entirely in C#. > > > > just what we need. More buggy slow products from MS that have > > Memory Leaks the size of the Mississippi. C# is not a good > > development platform yet. Heck they are practically still in the > > standard MS beta period. Everyone knows not to use a MS product on > > version 1.0 > > Ignore the trend at your peril. A MS product is one thing. A MS initiative > across the entire company is quite another. The last time they did that, > Internet Explorer put Netscape in the doghouse. Never, ever, ignore or > diminish what Microsoft decides to do as an entire company. > > >> - The "higher level language" playing field is crowded: C#, Java, > >> Perl, and Python. Mainstream industry does not need and will not > >> make room for 4 higher level languages. Any of these languages has > >> to grow at some other language's expense. > > > > This statement is really vague, and has almost no factual basis. If > > there were only four programming languages the world would be a very > > dull place. You forgot to mention Delphi, Visual Basic, Power Builder > > and a host of others. There is room for a lot more than 4 programming > > languages. > > Actually, Visual Basic vs. C# would be a good discussion in another > newsgroup. Because the books about .NET Framework that I'm reading, show > how VB is being modded and borgged to fit the Intermediate Language. Which > is essentially C#. I wonder if it would be reasonable to say that in 5 > years, nobody will be doing new app development in VB, it'll all be C#? But > I'll take that up with the VB crowd. > > >> - Python will never displace C# on Windows. It's Microsoft's home > >> turf and you can't fight directly with The Beast. You will see UNIX > >> boxes running Python, not Windows boxes. > > > > That's a bold statement, considering the abysmal adoption rate of C#. > > Within Microsoft, the adoption of C# is universal. That tends to have a > powerful effect on ISV Windows development over time. > > > C# isn't the dominant windows programming language currently, rather > > its Visual Basic. Java has far more applications written for Windows > > than C# does. MS really shot themselves in the foot when they went to > > dotnet, essentially the adopted the Java platform 8 years after Java. > > Now they are playing catchup with an inferior product. I doubt > > they'll ever catch up to Java overall. > > The problem with your thinking here is there's very clear evidence that > Microsoft can and does catch up to and surpass technologies that they have > fumblingly cloned. In fact, that's the basic Microsoft corporate > philosophy. Version 1.0 sucks, 2.0 is ok... 5.0 actually is a really good > product and then the competition can't catch up anymore. Example: DirectX. > When it started it was complete garbage. Nowadays it is technically > superior to OpenGL in most areas. Why they don't finally implement doubles > and put OpenGL out of its misery, I'm not sure. > > Why can MS catch up? Because Open Source people assume their technological > superiority and rest on their laurels. They think they don't have to market > because they are technically superior. Also, their ranks are populated with > strong engineers who don't *like* marketing, as a matter of basic > personality. They never get it in their heads that they have to > counter-market to some degree in order to hold the line. If you don't do > any marketing, Microsoft completely out-markets you and then you die, > technical merit or not. > > >> - Sun is about to die. It has done nothing for anyone lately and > >> has no further tricks up its sleeve. > > > > People have been saying this for years. I'll believe it when I see it. > > Read a paper. > > >> - Sun has failed to make Java live up to its claims of universality. > >> Java is for all intents and purposes simply a widespread programming > >> language, not a portable computing environment. Portable computing > >> environments are, in general, a pipe dream as long as Microsoft is > >> around. It will always be Windows vs. open standards. > > > > They must give you a good edjumacation at the Redmond campus. Java is > > by far the best portable computing environment available. > > Care to name a concrete example? A testimonial? > > >> - Ergo, Java is the weakling of the litter for Python to attack. > > > > No factual basis for this statement. Java and Python are really > > entirely different things. Python is meant as a scripting language, > > Java is a Systems programming language. It is meant as an alternative > > to C++, Python isn't. > > You're saying Python isn't useful as a systems language? Then it is already > dead. > > > Who does Python have to defend itself against? Python is Open Source. > > The only way it's going to die is if everyone stops developing it and > > it stagnates. > > You got it! And development stops when a langauge loses all meaningful > mindshare. What is the battle of mindshare? A marketing battle. It is not > a technological battle, except in the grossest terms of complete > incompetence. Time and again, the marketplace has proven that kludgy but > well marketed products carry the day. They only fail when they absolutely > can't do the job. > > > If that hapens it will be because something *significantly* better came > along. > > No, it is not an engineering meritocracy. Look at a company like DEC. > Wonderful technology company. Couldn't market its way out of a paper bag. > That's a warning for this c.l.p crowd. Don't sit around congratulating > yourselves on how superior your techology is. Recognize the strategic > competition and market against it. > > > Python doesn't have to defend > > itself, your Microsoft background is showing through here. C# is by > > far the weakest language of the four. It is buggy, slow and immature. > > It has the smallest user base, the least amount of industry backing > > and is 100% backed by all the resources of Microsoft. It will not go away, > and its shortcomings will be fixed at a blistering pace. > > > and a community that is rising up against it's benefactor. > > Huh? Care to explain? > > > I think > > you dramatically overstate it's chances. Historically Microsoft > > switches technologies every 3 or 4 years. That only gives C# about 2 > > years to go before it's dead in the water like every other MS > > "Innovation". > > What part of "100% committment across the company" don't you understand? > You really are blind. You don't live in Redmond, you can't conceive of > having access to this level of information. And who in c.l.p woudl tell you > these things? > > Well, you've been warned. > > > Historically > > those with the best technology and the best economic system prevail > > against inefficient and inferior models. > > You have *got* to be kidding me. Intel??!? Windows??!? From anthony at interlink.com.au Mon Aug 11 02:16:07 2003 From: anthony at interlink.com.au (Anthony Baxter) Date: Mon, 11 Aug 2003 16:16:07 +1000 Subject: wanted: alternative to LDAP Message-ID: <200308110616.h7B6G702021709@localhost.localdomain> I'm looking for something (usable from python) that provides networked directory/registry type functionality to a bunch of Linux and Solaris servers. LDAP's one alternative, but the LDAP servers are heavy heavy beasts, so I was hoping for something that's actually lightweight, rather than "lighter than X.500". Thanks, Anthony From niemeyer at conectiva.com Thu Aug 14 16:53:09 2003 From: niemeyer at conectiva.com (Gustavo Niemeyer) Date: Thu, 14 Aug 2003 17:53:09 -0300 Subject: No doubt I should know this regex point but .. In-Reply-To: <545cb8c2.0308140709.281fb610@posting.google.com> References: <545cb8c2.0308140709.281fb610@posting.google.com> Message-ID: <20030814205309.GA10113@ibook.distro.conectiva> > I am writing a class that walks through a file tree and (among other > things) filters out which files it considers. So I want to have > __init__( .. ,filterExpression='..') For the default I want to filter > nothing. So I need a Python regular expression that never matches. > What is (the best) one? There are many.. "(?=a)b" is just one of them. OTOH, this is awful. :-) Do as Aahz suggested and use None as default. -- Gustavo Niemeyer http://niemeyer.net From wdunn82 at comcast.net Sat Aug 30 21:08:08 2003 From: wdunn82 at comcast.net (winston) Date: Sun, 31 Aug 2003 01:08:08 GMT Subject: printer friendly python tutorial In-Reply-To: References: Message-ID: winston wrote: > does anyone know where i can find a printer friendly version of the > python tutorial release 2.3? > never mind i found it? From sanjiv at leopardlogic.com Fri Aug 8 17:43:10 2003 From: sanjiv at leopardlogic.com (Sanjiv Kumar) Date: Fri, 8 Aug 2003 14:43:10 -0700 Subject: Imortning histogram References: <009301c35d16$1a3ee8e0$4901a8c0@beastjr> Message-ID: <00cd01c35df6$13401290$4901a8c0@beastjr> Hi All, I have a python script which is using histogram (import Histogram )package. Can please some one tell me what all packages I need to install for this and where (website??) I can get it. I am new user of python so sorry for these basic questions. Thanks in advance!!! Best Regards, =Sanjiv= -------------- next part -------------- An HTML attachment was scrubbed... URL: From s011362 at bohr.gbar.dtu.dk Fri Aug 29 09:21:41 2003 From: s011362 at bohr.gbar.dtu.dk (Halfdan Holger Knudsen) Date: Fri, 29 Aug 2003 15:21:41 +0200 (MEST) Subject: string.count issue (simple) Message-ID: ok first off: Has the string.count function been replaced in python 2.2 (as compared to 1.5)?m And second: I need this in relation to a stringsearch program assuming a text file has been loaded into allLines and word contains the string you're searching for I want to count all occurences of the search string the following should do it (but doesn't - please disregard any missing colons or such this has not been copy/pasted): count = 0 for eachLine in allLines: if eachLine.find(word) > -1: count = count + eachLine.count(word, beg=0, end=len(eachLine) print eachLine print count what am I missing - it only outputs the nubmer of lines (as if the count statement had been count = count + 1) thanks H From andy47 at halfcooked.com Sun Aug 17 07:06:22 2003 From: andy47 at halfcooked.com (Andy Todd) Date: Sun, 17 Aug 2003 12:06:22 +0100 Subject: Needs DB-API to connect to SQL Server 2000 In-Reply-To: <20030816.23383100.1745684727@linux.local> References: <20030816.23383100.1745684727@linux.local> Message-ID: Thomas Chan wrote: > Does anyone know where I can find a DB-API to connect to SQL Server 2000? > I use mxODBC; http://www.egenix.com/files/python/mxODBC.html Regards, Andy -- -------------------------------------------------------------------------------- From the desk of Andrew J Todd esq - http://www.halfcooked.com/ From tismer at tismer.com Sun Aug 10 17:59:17 2003 From: tismer at tismer.com (Christian Tismer) Date: Sun, 10 Aug 2003 23:59:17 +0200 Subject: Slogan: Getting Rich Overnight In-Reply-To: References: Message-ID: <3F36C035.9000801@tismer.com> Timo Virkkala wrote: > Robert Kern wrote: ... >> While I certainly share that sentiment, I would advise caution in the >> phrasing >> of such a slogan: if I hadn't seen your name, I would have skipped >> your article >> as spam! > > I _did_, the first time around. Sure. I think, this cannot work in emails subject lines. If at all, then such a thing must be printed on T-Shirts. While sounding similar, but with a completely different meaning, "Getting rich comparisons overnight" might not be caught by SPAM filters :-)) -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 pager +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From rtw at freenet.REMOVE.co.uk Fri Aug 8 14:46:25 2003 From: rtw at freenet.REMOVE.co.uk (Rob Williscroft) Date: 08 Aug 2003 18:46:25 GMT Subject: execute command in CURRENT shell References: Message-ID: Valentine Kouznetsov wrote in news:ec6d1a16.0308080828.367f6b54 @posting.google.com: > Hi, > simple question, how to execute command in current shell, not in > subshell? > > Example. I have environment variable A=aaa and need to invoke shell > (sh) script which will do something with A. If I do os.system() then > sub-shell will setup A > and execute my script there leaving A in parent shell untouched. > A hack for you: Create a new sh script. say new.sh: #!/bin/sh source $* echo Result=$A # ---------------- #!/bin/python import os command="original.sh arg1, arg2" # you get the idea #Sorry don't know how you need to invoke sh w = os.popen( "sh ./new.sh " + command ) while ( True ): s = w.readline() if not s: break if s.startswith( "Result=" ): os.environ[ "A" ] = s[ s.find( "=" ) + 1 : ] ) break # Or maybe read all lines - so you get the last "Result="! w.close() HTH Rob. -- http://www.victim-prime.dsl.pipex.com/ From ejeanlouis2001 at yahoo.com Thu Aug 14 09:22:38 2003 From: ejeanlouis2001 at yahoo.com (Emmanuel Jean-Louis) Date: Thu, 14 Aug 2003 06:22:38 -0700 (PDT) Subject: help Message-ID: <20030814132238.58054.qmail@web13004.mail.yahoo.com> Is there a way that I can get/read these streams of every minute python email instead of poping up my screen? It bugs me to have these email coming like that. Thx. Emmanuel --------------------------------- Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Sat Aug 9 20:50:23 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 9 Aug 2003 20:50:23 -0400 Subject: Python vs. C# References: <3f357a9b@shknews01> Message-ID: "Brandon J. Van Every" wrote in message news:3f357a9b at shknews01... > What can I do with Python that I can't do with C#? Given that all Turing complete languages are theoretically equivalent, nothing, either way. But... > So again my question is, language-wise, what can I get done with Python that > I can't get done with C#? Same question, same answer. but... > What is easy to express in Python, that is > tedious, difficult, [or impossible] to express in C#? Different question, more realistic answer... I don't believe there are many C# experts who post here, so I'll share the teeny bit I know from other postings. The smart people who investigated integrating Python as a full-fledged .NET CLR language gave up because they found the [common intermediate language] to be unsuitable for Python. I believe it had to do with dynamic typing vs. C#, etc, static typing. So I speculate that generic programming (writing functions that work with any behaviorally compatible objects) is much easier in Python than C#. Maybe someone more knowledgable will chime in. Terry J. Reedy From adalke at mindspring.com Mon Aug 18 19:37:14 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Mon, 18 Aug 2003 17:37:14 -0600 Subject: Py2.3: Feedback on Sets References: <%BX%a.4999$N37.3051@nwrdny02.gnilink.net> <7h3d6f3143s.fsf@pc150.maths.bris.ac.uk> Message-ID: Bob Gailer: > You just have to avoid specifying a negative # too large in magnitude, > or you will get a memory underflow. Actually, there's a limit in how much negative memory you can get >>> d*(-sys.maxint-1) [] >>> d*(-sys.maxint-2) Traceback (most recent call last): File "", line 1, in ? OverflowError: long int too large to convert to int >>> Andrew dalke at dalkescientific.com From klappnase at web.de Tue Aug 5 20:26:49 2003 From: klappnase at web.de (klappnase) Date: 5 Aug 2003 17:26:49 -0700 Subject: Capture output from stderr Message-ID: Hello, I am trying to program a Tkinter application for linux, so I want to run a shell command from the gui and capture its output on the fly while the process is still running in order to display the progress messages in a toplevel window so the user may watch what is going on (the execution of the shell command may take a few minutes). Because the output is printed to stderr I thought I should use a popen2.Popen4 instance for that, like: self.pp = popen2.Popen4("exec cmd") I tried something like def getmsg(self): msg = self.pp.fromchild newmsg = msg.read(100) ...(do something)... self.master.after(1000, self.getmsg) to get the output, but this way the process gets horribly slowed down and even if it worked it would be hard to check the whole output for the information that I want to be displayed. I think I would need something like self.pp.readlines() but this only returns after the process has finished. Does anyone know how to handle this? I would be very thankful for any help. Michael From none at none.net Mon Aug 25 09:22:40 2003 From: none at none.net (Sami Viitanen) Date: Mon, 25 Aug 2003 13:22:40 GMT Subject: Coloring print lines Message-ID: Hello, Is there an easy way to make script print text with differents colors to screen (shell)? I mean a script that can for example print lines in red if some error occurs in executing some information.. --SV ----Thanks in advance. From ryanlowe0 at msn.com Sat Aug 23 18:43:02 2003 From: ryanlowe0 at msn.com (Ryan Lowe) Date: Sat, 23 Aug 2003 22:43:02 GMT Subject: python gripes survey References: Message-ID: much thanks "Bertrand Geston" wrote in message news:bi8nrd$1fnkl$1 at sinclair.be.wanadoo.com... > "Ryan Lowe" a ?crit dans le message news: > PUL1b.166506$_R5.62801118 at news4.srv.hcvlny.cv.net... > > python is a big improvement on most languages that came before it, but no > > language is perfect. id like to make a list of some of the aspects people > > find most annoying, regardless of their feasibility of implementation. for > > instance, i discussed putting if clauses in for loops, and i noticed > another > > thread about allowing {} and [] to be added and subtracted. if its > something > > from another language (especially an obscure one), please explain how it > > works in case people like myself dont know the language. > > > > thanks, > > ryan > > > > > You could start reading this: > http://zephyrfalcon.org/labs/python_pitfalls.html > http://www.amk.ca/python/writing/warts.html > http://www.ferg.org/projects/python_gotchas.htmlv > > bg > > > > From mfranklin1 at gatwick.westerngeco.slb.com Thu Aug 14 09:51:38 2003 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Thu, 14 Aug 2003 14:51:38 +0100 Subject: Python/Tkinter/tk crash [long] In-Reply-To: References: Message-ID: <200308141451.39582.mfranklin1@gatwick.westerngeco.slb.com> On Thursday 14 August 2003 10:10 am, Eric Brunel wrote: > Hi all, > > I was creating a Tkinter widget in the style of the reversed tabs below > Excel worksheets and I stepped in a serious problem: the code I made makes > python crash with a seg fault, bus error or X11 BadGC error on both Solaris > (2.6 and 2.7) and Linux (Mandrake 8.0); it doesn't crash on Windows. I > tried to simplify the script, but I couldn't reproduce the crash with a > simpler code. So the code below is somewhat long; sorry for that. Eric, Have you looked at Pmw (Python Mega Widgets) they have a NoteBook (tabbed pane) widget that looks like what you want... Regards Martin From mike at nospam.com Thu Aug 7 22:28:31 2003 From: mike at nospam.com (Mike Rovner) Date: Thu, 7 Aug 2003 19:28:31 -0700 Subject: streams (was: Re: Itertools) References: Message-ID: Beni Cherniavsky wrote: > Mike Rovner wrote on 2003-07-30: I'm sorry for taking so long to answer (I had a project deadline to meet ;) - done). >> Beni Cherniavsky wrote: > Point taken. But what do you call it then? Lazy linked lists has > only one single-word name that I'm aware of and that is "streams"; > there is no name for it in Tcl and Unix becauit is almost never used > in them, as far as I know. I made an intensive search on internet and convinced now that term 'streams' is globaly associated with i/o. I still think using this term for universal data structure will be misleading. However I can't come with a good word (my best is LazyList). >>> - `Cons` still requires lisp background but I don't know any >>> name that would be recognizable to non-lispers anyway. And >>> it's not a bad name. >> >> Construct, Glue, Merge? >> Taken readability any whole word is better. >> > `Construct` is too long. Compare with `str`, `int`, `dict` rather > than `string`, `integer` and `dictionary`. But they all are (long-lived) built-ins. AFAIK now there is a tendency to make language more readable (isinstance, enumerate to name a few hmm recent additions) > How would `Glue` and `Merge` be meaningful here? The only > associasions of "glue" are what TeX puts between boxes and "glue > layers" between different languages or libraries. "Merge" sounds like > the process of taking several sequences of values and interlevaing > them in some way (like in merge sort; BTW, it needs a lookahead of 1 > for each stream, so it should be convenient to implement with > streams). But this has nothing to do with what `Cons` does: creating > a new stream by prepending given head to given tail. `Cons` is the > only term I know of that unabigously refers to this operation, again > coming from functional languages . > > There is another possibility: rename `Cons` to `Stream` and `Stream` > to `LazyStream`; `Stream` would then be a factory function creating > either depending on whether it got 1 or two arguments. Would this be > better? No. In discussion about list.insert() and/or range() difference in behaivor dependent on args was prononced A Bad Thing (IIRC). >>> - Anything else anybody needs? >> >> If I got the intend of Stream correctly, I wish use them as Tcl >> streams, so I'd need combining and filtering and i/o. >> > You can use a `Stream` or `StreamIter` over a file object to get > lookahead and mulitple passes over it, without requiring the file to > be seekable! That's one of the main uses. It also gives you ability > to "unread" any amount of data. Note that if you simply apply it to a > file the stream operates on a line at a time; you will need to wrap > the file with a custom generator if you wish to operate at character > level; working at token level might be the best compromise. > > I'm not familiar with Tcl streams, so I don't understand the > "combining and filtering" reference - can you elaborate? I didn't touch tcl for several years ;) But the idea is pretty simple: to pass file object throw 'filter' to get 'another' file(-like) object. import compress as Z for line in tarfile.open('-','r',Z.open(filename)).extractiter() instead of stream = tarfile.open('-','r',Z.open(filename)) for elem in tarfile.open('-','r',Z.open(filename)).getmembers(): for line in stream.extract(elem): ... or something like that. I admit that later example based on new 2.3 syntax fulfill my (long being) expectations quite well. Thanks, Mike From losnations at comcast.net Fri Aug 1 19:51:56 2003 From: losnations at comcast.net (Marc) Date: Fri, 1 Aug 2003 18:51:56 -0500 Subject: How do I combine instance+string for variable References: <4378fa6f.0308011305.183c291a@posting.google.com> Message-ID: > >I have several instances of telnet connections that I label > How do you "label" them? By assigning, like conn2 = someSourceOfConn(...)? Exactly. They are each separate instances of a telnet connection: conn2 = telnetlib... ... conn8 = telnetlib... > Do you want to pass a name in the form of a string, like 'conn2' or do you > want the conn2 that you assigned before? Actually right now I'm using the list method: conns = [conn2, conn3, conn4, conn5, conn6, conn7, conn8] ... for int in range(2,9): qput(key.command, conns[int-2], act_user("user-ID" + str(int), "CTAG", "t*sting" + str(int) ) ) I didn't include the code originally because it goes off in a lot of directions. I'm putting it into a queue with function qput that later gets executed with a function in file key. The list method works for me with a small number of connections, but if I ever need a lot of connections it will be a little klunky. Therefore I was trying to find a fix similar to using setattr if I was using classes. So basically I want to be able to use the conn2 that I assigned before, but referencing it using a string. I think the method you mentioned: for i in range(2, 9): name = 'conn%s' % i aConn = vars()[name] # or use globals() in place of vars() if not in local namespace usingFunc(aConn) is what I'm looking for as it appears to concatenate "conn" with a number to create the instance name. I hadn't come across the built-in function "vars" yet, but I was trying to accomplish the same thing using "eval". Thanks for the tip, Marc From s at 3ntra.donotfreakingspamme.net Tue Aug 19 08:42:11 2003 From: s at 3ntra.donotfreakingspamme.net (s) Date: Tue, 19 Aug 2003 12:42:11 GMT Subject: Python newbie help References: <87fa5cfa.0308181126.c61bfa2@posting.google.com> Message-ID: On Tue, 19 Aug 2003 08:28:06 +0000 (UTC), Duncan Booth wrote: >stephen at hostwiththemost.net (s) wrote in >news:87fa5cfa.0308181126.c61bfa2 at posting.google.com: > >> I've recently been very interested in learning Python but I seem to >> lack direction while reading the tutorials. I understand the syntax >> and everything concerning the language itself but the tutorials I have >> seen are merely displaying features of the language rather than Thanks for the help. I will definitely look into these links very hard but I must point out that I'm not a teenager or a beginner programmer, just someone who has lost motivation to learn but would like to get it back. I just get bored with examples that don't really contribute to a program or the like. Thanks for the link. From bgailer at alum.rpi.edu Wed Aug 13 18:59:35 2003 From: bgailer at alum.rpi.edu (Bob Gailer) Date: Wed, 13 Aug 2003 16:59:35 -0600 Subject: Py2.3: Feedback on Sets In-Reply-To: Message-ID: <5.2.1.1.0.20030813165644.02bfc1d0@66.28.54.253> At 06:02 AM 8/12/2003 +0000, Raymond Hettinger wrote: >* Are you overjoyed/outraged by the choice of | and & > as set operators (instead of + and *)? Its OK. >* Is the support for sets of sets necessary for your work > and, if so, then is the implementation sufficiently powerful? Necessary? No. Desirable? Yes Powerful? Yes >* Is there a compelling need for additional set methods like > Set.powerset() and Set.isdisjoint(s) or are the current offerings > sufficient? Its OK >* Does the performance meet your expectations? Not tested >* Do you care that sets can only contain hashable elements? No >* How about the design constraint that the argument to most > set methods must be another Set (as opposed to any iterable)? Be nice to support iterable also. >* Are the docs clear? Can you suggest improvements? VERY. A model of how I'd like to see the rest of Python docs. >* Are sets helpful in your daily work or does the need arise only rarely? Hard to say, Bob Gailer bgailer at alum.rpi.edu 303 442 2625 -------------- next part -------------- --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.506 / Virus Database: 303 - Release Date: 8/1/2003 From aleax at aleax.it Fri Aug 29 10:27:23 2003 From: aleax at aleax.it (Alex Martelli) Date: Fri, 29 Aug 2003 14:27:23 GMT Subject: Metaclasses presentation slides available... References: <2259b0e2.0308290127.390598df@posting.google.com> Message-ID: Mike C. Fletcher wrote: ... > metaclasses and metamethods. See if I've got this right: > > Class-declaration ends > Interpreter finds declared metaclass (via whichever method) > Interpreter looks for a __call__ method in type( metaclass > ).__dict__ .(skipping the dictionary of metaclass due to "special"-ness > of the name __call__) > Interpreter executes type(metaclass).__call__( classname, bases, > dictionary ) Almost, but what gets executed is: type(metaclass).__call__(metaclass, classname, bases, dictionary) i.e., the unbound-method type(metaclass).__call__ *DOES* get the mandatory first argument 'metaclass', of course. > Assert: It does this due to the "special method-name lookup" exception > for new-style types: special methods are looked up in the type without > lookup in the instance dictionary. Yep. Exactly like *ANY* situation of foo(args) turns into: type(foo).__call__(foo, args) (except when foo is an instance of a classic-class, where for reasons of backwards compatibility foo.__call__(args) happens instead). > Hmm, definitely not something to cover early in the presentation... > especially when most users haven't yet discovered the special-names > exception (most programmers still haven't discovered the new features of > Python 2.2 (hence my metaclass presentation)). If I were writing a "for > dummies" book that would definitely have to be a "technical aside". I think that understanding what "foo(args)" means is VASTLY more important than grasping metaclasses, for (by far) most practical programming tasks. The so-called "special-names exception" (which is not an exception at all but a perfectly general rule -- on the contrary, the exception is the behavior of classic-class instances:-) should be clear to the listeners, otherwise they'll get their knickers in a serious twist trying to make any real use of what they learn about metaclasses. E.g., that metaclass.__call__ is what determines what it means to call the CLASS, etc, etc. >>You forgot to mention Alex Martelli's presentation: >> >>http://www.strakt.com/dev_talks.html >> > Well, hard to forget something you've never heard about before ;) . > Seems like a slightly more involved presentation, targetted more at > people trying to create metaclasses (i.e. for meta-programmers). It's more of a _presentation_ -- just the slides with the highlights -- while yours is more like an _article_ -- much more useful as standalone material, because you've got so much text on each slide (but by the same token, not ideal for projection;-). > I tried to pitch more at the level of "should you use them", or "why > would you use them and when", or "what's going on when someone creates a > meta-class and it shows up in the library I'm using" (i.e. the audience > being primarily (non-meta) programmers). That seems to be the area that > doesn't get discussed as often when discussing metaclasses. Actually, I do target "why would you use them and when", though you do that much more widely (mine was a 45-minutes presentation, yours a 2-hours one, I believe, just from amount of material you have on your slides), trying to distinguish between canonical uses (quite good) and non-canonical ones (tempting but IMHO best avoided -- it did seem to me that Guido, who was in the audience as I presented this at Europython, broadly agreed, and he did even explicitly bless the convention of using 'mcl' for a first-method-argument that is a metaclass, just as 'cls' is used for one that is a class and 'self' for one that is an instance). Alex From peter at engcorp.com Thu Aug 28 08:50:52 2003 From: peter at engcorp.com (Peter Hansen) Date: Thu, 28 Aug 2003 08:50:52 -0400 Subject: Style question... References: Message-ID: <3F4DFAAC.1356C276@engcorp.com> "U. N. Owen" wrote: > > For the moment I work on (a small part of) a project > that has hundreds of thousands of lines, almost > eveything in Python (and some in C and Fortran), > and when you have a loop several pages long, or > nested blocks to 8 levels or more, I may say > it's *very* convenient to see where the end > of a block exactly is. It's convenient to > have some long variable names too. I use Scite, which provides a graphical means of representation the indentation, with vertical lines that extend down at every indent level. (It would have to be later in the day for me to be coherent enough to describe it better.) Suffice to say that it provides more than adequate (for me) visual indication of the end of a block that stretches too far. A better point I'd make however is that if you have a loop several pages long, or a nested block 8 levels deep, the code needs refactoring! Saying this occurs in a large project does nothing to excuse it: the more code you have, the greater the need for structuring it well. -Peter From __peter__ at web.de Fri Aug 29 09:12:24 2003 From: __peter__ at web.de (Peter Otten) Date: Fri, 29 Aug 2003 15:12:24 +0200 Subject: Python zipfile: Zip empty directories. References: Message-ID: Mark Wondratschek wrote: > How can I pack empty directories? I want to mirror a whole directory > structure in an archive. So I want to zip non-empty AND empty directories. > Any ideas? As far as I remember, the zip format does not support storing empty directories. But you could put a file with an easily recognizable name in all empty directories, e.g. __empty__. Peter From adalke at mindspring.com Wed Aug 27 18:40:30 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Wed, 27 Aug 2003 22:40:30 GMT Subject: Celebrity advice References: <3F4CD2A2.DE7D05D2@engcorp.com> Message-ID: Lulu of the Lotus-Eaters: > Of course, in reality, the homicide rate is much lower outside of the > USA, so the base rate isn't good for extrapolation. I thought of that when I looked up that number. But the comparison stats I know of are for Europe. I remember in 'Guns, Germs, and Steel', in the foreword the author points out that the homicide rate in New Guinea was quite high, pointing out he knew a woman whose first husband was killed by the man who became her second husband. He goes on to state that when two people first met, one of the things they did was to figure out how they were related, because if they weren't then the odds of murder was higher. (Can't find my borrowed copy of the book, so regard the above as a rough summary.) And I didn't want to do the legwork to find more precise numbers. Andrew dalke at dalkescientific.com From krummbeersupp at web.de Thu Aug 7 10:01:21 2003 From: krummbeersupp at web.de (Oliver Emrich) Date: Thu, 7 Aug 2003 16:01:21 +0200 Subject: win32com error Message-ID: <200308071401.h77E1LQ20377@mailgate5.cinetic.de> An HTML attachment was scrubbed... URL: From theller at python.net Fri Aug 8 04:31:39 2003 From: theller at python.net (Thomas Heller) Date: Fri, 08 Aug 2003 10:31:39 +0200 Subject: Building extensions with mingw32 -- bdist_wininst fails. References: Message-ID: [posted and mailed] "Chris Gonnerman" writes: > From: "Thomas Heller" > >> > I checked the archives regarding that error message and >> > found a conversation wherein Jeremy Hylton claimed he >> > might have added the code to detect this, and Paul Moore >> > asked to have it removed/disabled at least for mingw32 >> > (which makes binaries 100% compatible with MSVC6). In >> > the case given then, the extension wouldn't build at >> > all; now it builds but I can't make a Windows installer >> > from it. >> >> Can you point me to this discussion, please? Then I'll >> try to look after this. >> >> Thomas > > Thanks! First, here's where I found the messages I refer > to above: > > http://mail.python.org/pipermail/distutils-sig/2003-July/003339.html > > OK, here's the problem. The distutils bdist_wininst > script calls build (illustrated below) but does not > accept --compiler=mingw32. This is obviously wrong, > but I'm unsure how to fix it (I'm still trying to wrap > my fuzzy and tired mind around the entire distutils > thing). There's an easy workaround. python setup.py bdist_wininst --compiler=mingw32 does *not* work. But this one does: python setup.py build --compiler=mingw32 bdist_wininst Maybe this should be documented somewhere? I've tried it with one of my simple extension modules at least, and after hacking msvccompiler so that this one isn't found any longer. Thomas From irmen at -NOSPAM-REMOVETHIS-xs4all.nl Fri Aug 15 13:23:36 2003 From: irmen at -NOSPAM-REMOVETHIS-xs4all.nl (Irmen de Jong) Date: Fri, 15 Aug 2003 19:23:36 +0200 Subject: cPickle alternative? In-Reply-To: References: Message-ID: <3f3d1716$0$49113$e4fe514c@news.xs4all.nl> Drochom wrote: >>What protocol did you pickle your data with? The default (protocol 0, >>ASCII text) is the slowest. I suggest you upgrade to Python 2.3 and >>save your data with the new protocol 2 -- it's likely to be fastest. >> >> >>Alex >> > > Thanks:) > i'm using default protocol, i'm not sure if i can upgrade so simply, because > i'm using many modules for Py2.2 Then use protocol 1 instead -- that has been the binary pickle protocol for a long time, and works perfectly on Python 2.2.x :-) (and it's much faster than protocol 0 -- the text protocol) --Irmen From tebeka at cs.bgu.ac.il Tue Aug 26 06:18:21 2003 From: tebeka at cs.bgu.ac.il (Miki Tebeka) Date: 26 Aug 2003 03:18:21 -0700 Subject: Comments on my "Python Introduction" slides References: <33803989.0308240000.35b9bf1f@posting.google.com> <3f4a0cea_4@corp.newsgroups.com> Message-ID: <33803989.0308260218.72ba5780@posting.google.com> Hell Paul, > However, and not knowing your audience, I wonder if the slides are a bit > advanced (but obviously they are probably not meant to stand alone from > your talk, and your purpose might be to _wow_ your audience). Yap. I'll bee it up while I talk. > For example, will people really understand how useful and powerful and > easy to use dictionaries are [a key feature of Python] by just saying > they are like a hash table? You have an example of a dictionary in use > in "unique" but in the example doesn't add something into the dictionary > in the flow of the text of the program until after the test -- a > perfectly good way to implement it, but perhaps harder to follow > initially for some people (who may be asking where does the data come > from when they get to the test.). Also, since you just set the value to > true, it doesn't quite capture how most dictionaries are typically used > (to store key value pairs). I'd say another slide on dictionaries might > be warranted with a simpler better example, to preceed the "unique" > example one you have there. Somethign blah like just putting names and > email addresses together. A good point. I'll try adding one. > Also, since one a pracical basis some fraction of your audience is going > to recoil at the significant white space, you might have a slide on this > (maybe in the middle, or after your first example) and how it is not a > problem in practice, and in fact promotes maintainability and prevents > some bracing style clashes. For me (having used Occam earlier, which > also uses significant white space), significant white space for block > delimiting is one of Python's best features. You might as well confront > the controversy head on somehow (like quotes from this newsgroup from > converts to it?) I can also see an argument for not bringing the subject > up as that might scare people off, but since you have a chance to bring > it out in the open in a controlled way sounding favorable to Python, and > you know it will be an issue for people coming from C, it might be best > to just deal with it. You're right. I think I'll talk about it without a slide. But I need to get prepared. I think ESR's article has some stuff in it. > Obviously, you only have so much time for a talk, so you have to > prioritize, and maybe there isn't enough time for two more slides. But, > I think if you had to drop two, I'd drop the "generators" and "fibs > geenrator" example. You may well lose a lot of your audience there > anyway (as while useful, the continuation concept is somewhat abstract > and advanced). I think Python's generators are easyer to understand than Scheme continuations (which I don't fully grasp yet :-). It's a very powerfull idiom which is used a lot in 2.3 (see itertools module) > Also, the "Quick One" items might easily include a word or two on the > topic, i.e. "Quick One: Files" or "Quick One: fibs" for reference. OK. > Also "Not In Standard Library" might be changed to "Free Third-party > Addons" to sound a little nicer (otherwise people might think it is a > complaint). OK. > You might also rename your "Development Methodology" slide as "Will it > be fast enough?" or something like that ("Developing for speed?") and > reference programmer time vs. execution time, since I expected that > slide otherwise based on the title to reference Extreme Programming vs. > Waterfall Development models or some such approaches. OK. > Having said all that (and none of those are major problems in the > context of a talk where you continually monitor the audience's > understanding and adapt your comments), I think the use of complete > small program examples (e.g. du, fibs, etc.) in your tutorial was a > great choice to help people grasp the language. > > So, overall, good job! Thanks. Thanks for you help. Miki From aleax at aleax.it Fri Aug 29 08:05:09 2003 From: aleax at aleax.it (Alex Martelli) Date: Fri, 29 Aug 2003 12:05:09 GMT Subject: print without intervening space References: <5b42ae4.0308290102.3f04b90b@posting.google.com> Message-ID: Ernie wrote: > Hi, > >>>> for x in range(10) > ... print x, > ... > > will output > > 0 1 2 3 4 5 6 7 8 9 >>>> > > What if somebody wants instead > > 0123456789 > > Maybe we need a printns (print with no spaces) ? Hopefully not, since you already have several ways to achieve this purpose ('print' itself is quite redundant, just a convenience): >>> for x in range(10): ... print x, ... sys.stdout.softspace = False ... else: ... print ... 0123456789 >>> or, more simply, eschewing print: >>> for x in range(10): ... sys.stdout.write(str(x)) ... else: ... sys.stdout.write('\n') ... 0123456789 >>> sys.stdout.writelines([str(x) for x in range(10)]+['\n']) 0123456789 >>> sys.stdout.write(''.join([str(x) for x in range(10)]+['\n'])) 0123456789 >>> Note that the effort in each of these cases to include a trailing '\n' is just to avoid the interactive interpreter's prompt overwriting the line we've just printed. Alex From tim at remove_if_not_spam.digitig.co.uk Wed Aug 13 09:37:27 2003 From: tim at remove_if_not_spam.digitig.co.uk (Tim Rowe) Date: Wed, 13 Aug 2003 14:37:27 +0100 Subject: Is Python your only programming language? References: Message-ID: On Tue, 12 Aug 2003 05:44:45 GMT, "Joe Cheng" wrote: >I want to ask you hard-core c.l.p Pythonistas: Do you use Python for >everything? (and I'm counting Python + C extensions as just Python) No. I'm a firm believer in using the right language for the task, and I don't believe it to b possible for a single language to be the best for every application. > Or do >you keep another language equally close at hand, and if so, what is it? C++ close to hand, Eiffel and Ada available. > And >finally, do you foresee a day when Python can be, for all practical intents >and purposes, your only programming language? Absolutely not. I don't believe any language could be, because every task needs different compromises. From jdhunter at ace.bsd.uchicago.edu Fri Aug 29 09:37:39 2003 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Fri, 29 Aug 2003 08:37:39 -0500 Subject: yawPyCrypto : encrypt file in blocks In-Reply-To: (John Hunter's message of "Thu, 28 Aug 2003 12:38:19 -0500") References: Message-ID: >>>>> "John" == John Hunter writes: John> Apparently, I am not handling the final bytes correctly. John> The file size are listed below the code. John> Any advice? Also, is this the best way to encrypt large John> files? Is there a preferred block size? Hmmm, I thought I had posted a follow up to this yesterday but it didn't appear to come through. Apologies if you get a duplicate. I discovered the source of this problem. I needed to write the encrypted/decrypted stream one more time after the call to finish. The following works from yawPyCrypto.Cipher import DecryptCipher, EncryptCipher from yawPyCrypto.Cipher import ZipDecryptCipher, ZipEncryptCipher from yawPyCrypto.Constants import CIPHER_BLOWFISH, MODE_CBC def encrypt(passwd, infile, outfile, blocksize=1024, enc=None): """ Encrypt the data in the file handle infile to the file handle outfile in blocks of length blocksize enc is a EncryptCipher instace. If None, default to EncryptCipher(passwd, CIPHER_BLOWFISH, MODE_CBC) """ if enc is None: enc = EncryptCipher(passwd, CIPHER_BLOWFISH, MODE_CBC) while 1: data = infile.read(blocksize) if len(data)==0: break enc.feed(data) outfile.write(enc.data) enc.finish() outfile.write(enc.data) infile.close() outfile.close() def decrypt(passwd, infile, outfile, blocksize=1024, dec=None): """ Decrypt the data in the file handle infile to the file handle outfile in blocks of length blocksize dec is a DecryptCipher instace. If None, default to DecryptCipher(passwd) """ if dec is None: dec = DecryptCipher(passwd) while 1: data = infile.read(blocksize) if len(data)==0: break dec.feed(data) outfile.write(dec.data) dec.finish() outfile.write(dec.data) infile.close() outfile.close() passwd = 'a really bad passwd' infile = file('source.mp3', 'rb') outfile = file('crypted.mp3.cr', 'wb') encrypt(passwd, infile, outfile) infile = file('crypted.mp3.cr', 'rb') outfile = file('decrypted.mp3', 'wb') decrypt(passwd, infile, outfile) From tottinge at indy.rr.com Tue Aug 19 00:32:19 2003 From: tottinge at indy.rr.com (Tim Ottinger) Date: Tue, 19 Aug 2003 04:32:19 GMT Subject: threads and timeout -> running a shell command / want to guard against infinite loops References: Message-ID: On Tue, 19 Aug 2003 14:21:14 +1200, Marcus Liddle wrote: > > > Hi > > I'm trying to get a really simple python program to > run a bash testing script and kill itself if its > been running to long (ie infinite loop) > > create the thread object - test = TestThread() > run the command - test.do_command("infloop.bash") > if t.isAlive(): ...stop it > > any good ideas? Have you considered pexpect? From paul at boddie.net Tue Aug 12 11:40:41 2003 From: paul at boddie.net (Paul Boddie) Date: 12 Aug 2003 08:40:41 -0700 Subject: Python should try to displace Java References: Message-ID: <23891c90.0308120740.3a771ff6@posting.google.com> "Brandon J. Van Every" wrote in message news:... > I'm going to make a number of points which I'm sure many people will object > to. I'll resist the temptation to refer to your other threads, then. (Or other postings in this thread, in fact.) [...] > - in 5 years, nobody will be doing significant amounts of new application > development in C++. The writing is on the wall: garbage collection is > essential. Any C++ code will be support and legacy libraries. Well, it should be a surprise that in the "business systems" area people are still writing huge quantities of C++ code, especially since a lot of the innovation is now done in other languages. Apart from your favourite Seattle-based company, who else is seriously bothering with C++ for Web services, for example? Or at least, who else worth speaking of? As far as I'm concerned, it was a surprise five years ago that people didn't automatically consider other languages before C++ for systems of this kind. It's clear that C and C++ do, however, fit the bill as the languages most likely to be used to implement systems where high performance is crucial. In many areas where those languages are used, developers seem to be fairly conservative, and whilst other languages could offer noticeable benefits during development and even offer comparable performance, bandwagon chasing isn't a priority for these people. The Solaris kernel isn't now implemented in Java as far as I'm aware, for example. Of course, you could be referring to the promising situation of Python running directly on the metal. ;-) > - Microsoft is already implementing said strategy across all levels of the > company today. Microsoft developers don't do much C++ development anymore. > Various upcoming products are being written entirely in C#. This doesn't interest me, and if it did, I could easily find out for myself whether this is really true or just speculation. :-) > - The "higher level language" playing field is crowded: C#, Java, Perl, and > Python. Mainstream industry does not need and will not make room for 4 > higher level languages. Any of these languages has to grow at some other > language's expense. Mainstream industry, whoever that is, already entertains more than four higher level languages. Note also that Python and Perl are both at an even higher level than C# and Java, so that observation has potentially been debunked if you consider those languages' areas of operation to be complementary. > - Python will never displace C# on Windows. It's Microsoft's home turf and > you can't fight directly with The Beast. You will see UNIX boxes running > Python, not Windows boxes. This depends on whether Microsoft remove all their "legacy" APIs and insist that everything runs on the common language runtime (CLR, or whatever it's called). I doubt that this will happen soon, and you ignore the possibility that one of these days someone will get Python running natively and efficiently on the CLR. > - Sun is about to die. It has done nothing for anyone lately and has no > further tricks up its sleeve. About to? They made a pile of cash in the dot-com years and could presumably sit and burn that off if it weren't for those shareholders. Personally, I believe that they will either be marginalised or adapt like IBM and HP have done. > - Sun has failed to make Java live up to its claims of universality. Java > is for all intents and purposes simply a widespread programming language, > not a portable computing environment. Portable computing environments are, > in general, a pipe dream as long as Microsoft is around. It will always be > Windows vs. open standards. This is where your signature comes in, I think. In your 20% of "real-world" experience, presumably around graphics stuff, Java hasn't really been as successful as hyped, although the latest mobile 'phone craze for Java gaming might at least change that slightly. Meanwhile, in various parts of the 80% that you don't have experience of, Java has been pretty successful precisely because it offers a portable environment, albeit one that can be pretty infuriating at times. Hint: Python complements Java when Java gets too infuriating. > - Java is proprietary. Python is open source. Open Source is the best shot > that anyone has at competing with Windows. This will be demonstrated over time, yes. > - Perl is open source and sysadmins won't be giving it up any time soon. > Perl is optimal for their jobs, the capabilities of Python are a non-sell. I don't agree. People do use tools which they know about and can be hostile to those that they don't have time to learn. Education is the principal issue here, and that education won't be readily accepted as white papers written by suits. > - Ergo, Java is the weakling of the litter for Python to attack. Again, Python and Java can operate in different areas, interoperate, and coexist in the same area as tools which offer certain advantages at certain points in time. > - Alternately, if you look at this in real world marketing terms, Python is > the weakling of the litter that must defend itself. I know that will make > various Python idealists upset, but that's the economic reality. Merit > doesn't win in this game. Java is the next weakest langauge so that's whose > lunch Python should try to eat. I think you should stop trying to think of all this as an intellectually lightweight corporate strategy meeting where we have to agree on some kind of marketing campaign that actually does nothing more than prop up the advertising profession whilst making complete fools out of everyone involved. What does stop Python from being recognised and adopted is the lack of awareness that people have, and it is true that part of this lack of awareness is down to a lack of brochures arriving on the desks of salespeople and strategists. Nevertheless, demonstrated successful systems have a more powerful impact on those whose money is ultimately being spent on new software - the customers. Because as their competitors demonstrate working systems that give them productivity benefits, they can turn to vendors and say, "Stop trying to sell us buzzword X - just give us something like our competitors are using!" The more I think about it, the more I realise that many customers probably don't care whether you've used the latest stuff from Microsoft or not (although they might be a bit concerned about the licensing schemes), and the more I realise that it must be the various bandwagons that "inform" certain parts of the "decision chain" that create this downward pressure on people to write all their stuff in C# or . As the balance of power shifts away from the vendor to the customer, however, I think you'll start to see the smart vendors adapt and start to discover what actually works, both from their customers and the people on the ground actually doing the work, and they'll cut out the brochure trail as they realise that it doesn't really help them to make money and satisfy customers at the same time. Paul P.S. If you're really interested, there's a marketing/promotion interest group for Python. The details are out there on the Web, so if it's important to you, I'm sure you can dig them out. From peter at engcorp.com Fri Aug 29 13:40:49 2003 From: peter at engcorp.com (Peter Hansen) Date: Fri, 29 Aug 2003 13:40:49 -0400 Subject: imports after function definitions? References: Message-ID: <3F4F9021.354CDD2D@engcorp.com> Hallvard B Furuseth wrote: > > Terry Reedy wrote: > >in message news:HBF.20030828usgy at bombur.uio.no... > >> Is there any reason not to structure my program like this? > >> > >> def ... > >> def ... > >> var = ... > >> var = ... > >> import ... > >> import ... > >> main_function() > > > > It is helpful to human readers to see dependencies at the top and to > > know what globals are avaiable when reading defs. What would be > > compensating gain of doing such? > > I'm setting sys.path in a config function which depends on variables > near the end of the file. So the config function must be called late, > and the imports that depend on it after that. Sounds like the structure ought to be changed (IMHO). This is an unusual arrangement, but not a highly unusual thing to need to do. Why not just put the sys.path-setting stuff, including the variables on which it seems to depend (I'd ask why that's need, too), in a separate module, possibly the __main__ one, and have the rest of the code including the stuff that needs the imports be called from there. In other words, why do you need all those defines and all those variables to come before the imports? Are they really all required for the sys.path-setting code? If so, shouldn't they just be in a separate module? -Peter From jjl at pobox.com Sat Aug 23 19:59:28 2003 From: jjl at pobox.com (John J. Lee) Date: 24 Aug 2003 00:59:28 +0100 Subject: What's better about Ruby than Python? References: <3F41505F.69D18CC8@alcyone.com> <66d7kvonvb2n0nqbqahhd5roak7ur81sob@4ax.com> <3f43ef5d_4@127.0.0.1> <3F440A35.9030602@nyc.rr.com> <4o_0b.1665$Ej6.1182@newsread4.news.pas.earthlink.net> <8D01b.1721$Ej6.702@newsread4.news.pas.earthlink.net> <3F44ED2E.9070308@nyc.rr.com> <0V61b.1900$Ej6.1012@newsread4.news.pas.earthlink.net> <3F4504D7.20008@nyc.rr.com> Message-ID: <87oeygx6vz.fsf@pobox.com> "Andrew Dalke" writes: > Mario S. Mommer: > > Lisp is simple. > > > > ( ...) > > > > Where's the problem? > > Quantum mechanics is simple. It's just H | psi> = E | psi> [...] > Since then it's been limited to incidental learning, like seeing examples > and trying to figure them out. Eg, consider Gabriel's "Worse is [...] Amusing interactive scheme tutorial: http://www.ifarchive.org/if-archive/games/competition96/lists/lists.z5 To be run on one of the bazillion Zcode interpreters out there (Z code is the bytecode used by Infocom for their old text adventures): http://www.ifarchive.org/indexes/if-archiveXinfocomXinterpreters.html John From fredrik at pythonware.com Tue Aug 12 04:00:21 2003 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 12 Aug 2003 10:00:21 +0200 Subject: Is Python your only programming language? References: Message-ID: Joe Cheng wrote: > I want to ask you hard-core c.l.p Pythonistas: Do you use Python for > everything? (and I'm counting Python + C extensions as just Python) yes. > And finally, do you foresee a day when Python can be, for all practical > intents and purposes, your only programming language? has been, since 1995. From tomas at fancy.org Fri Aug 1 13:56:59 2003 From: tomas at fancy.org (Tom Plunket) Date: Fri, 01 Aug 2003 10:56:59 -0700 Subject: How do you do unittest? References: Message-ID: Will Stuyvesant wrote: > ----------------------- test.bat ------------------------ > cd test > test_mod.py > cd .. > --------------------------------------------------------- Could you do simply "test/test_mod.py" ? Then the current directory would still be the "main" directory. Not sure how Python handles the paths in a case like this though. > I guess the author of PiaN does not use a 'test' subdirectory > himself, as it is now the example 17-2 does only work in the > source directory. I just have all of my test_*.py files and my main test.py in the main source folder. My test.py automatically runs all of the tests that exist, I have to thank this group for getting me down the right path. (The 'Directory' stuff is because my unittests create lots of files. It's a work-in-progress. RunTests() is the function most relevant to this discussion.) ---- test.py ---- import unittest import os, sys def SetupDirectory(name): testDir = os.environ['TESTING_DIRECTORY'] testDir = os.path.join(testDir, name) if not os.path.exists(testDir): os.mkdir(testDir) os.chdir(testDir) def PruneDirectory(dir): files = os.listdir(dir) for f in files: fullpath = os.path.join(dir, f) if os.path.isfile(fullpath): os.remove(fullpath) elif os.path.isdir(fullpath): PruneDirectory(fullpath) os.rmdir(dir) def CreateTempDirectory(): # testDir = os.environ['TEMP'] # testDir = os.path.join(testDir, 'filefiend_test') testDir = os.path.join(os.getcwd(), 'testdata') if os.path.exists(testDir): PruneDirectory(testDir) os.mkdir(testDir) os.environ['TESTING_DIRECTORY'] = testDir def RemoveTempDirectory(): testDir = os.environ['TESTING_DIRECTORY'] os.chdir(os.path.join(testDir, os.pardir)) PruneDirectory(testDir) def RunTests(): files = os.listdir(os.curdir) names = [] for file in files: if file[:5] == "test_" and file[-3:] == os.extsep+"py": names.append(file[:-3]) CreateTempDirectory() suite = unittest.defaultTestLoader.loadTestsFromNames(names) runner = unittest.TextTestRunner(verbosity=1) result = runner.run(suite) RemoveTempDirectory() # raw_input("\n to continue.\n") sys.exit(not result.wasSuccessful()) if __name__ == "__main__": RunTests() -tom! -- There's really no reason to send a copy of your followup to my email address, so please don't. From sdhyok at yahoo.com Sun Aug 24 21:11:59 2003 From: sdhyok at yahoo.com (sdhyok) Date: 24 Aug 2003 18:11:59 -0700 Subject: A strange behavior of list.extend() References: <420ced91.0308241311.734cbc9c@posting.google.com> Message-ID: <420ced91.0308241711.79e5ab6b@posting.google.com> Thanks. I got it. Deahyok From jacek.generowicz at cern.ch Fri Aug 22 07:47:24 2003 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 22 Aug 2003 13:47:24 +0200 Subject: Which way to say 'private'? References: Message-ID: "Batista, Facundo" writes: > As a I read don't remember where, :p, to put 1 underscore is the > same to hang a "Do not disturb" sign in the door, to put 2 > underscores is the same to lock the door. ... and to put the key under the mat in front of the door. (On the outside :-) Any fool who cares to look, can figure out and circumvent the name mangling scheme. It offers no protection against intruders. It does offer protection against name clashes, and that is its purpose. From bergeston at yahoo.fr Sat Aug 23 17:49:17 2003 From: bergeston at yahoo.fr (Bertrand Geston) Date: Sat, 23 Aug 2003 23:49:17 +0200 Subject: python gripes survey References: Message-ID: "Ryan Lowe" a ?crit dans le message news: PUL1b.166506$_R5.62801118 at news4.srv.hcvlny.cv.net... > python is a big improvement on most languages that came before it, but no > language is perfect. id like to make a list of some of the aspects people > find most annoying, regardless of their feasibility of implementation. for > instance, i discussed putting if clauses in for loops, and i noticed another > thread about allowing {} and [] to be added and subtracted. if its something > from another language (especially an obscure one), please explain how it > works in case people like myself dont know the language. > > thanks, > ryan > > You could start reading this: http://zephyrfalcon.org/labs/python_pitfalls.html http://www.amk.ca/python/writing/warts.html http://www.ferg.org/projects/python_gotchas.htmlv bg From mertz at gnosis.cx Thu Aug 28 16:27:15 2003 From: mertz at gnosis.cx (Lulu of the Lotus-Eaters) Date: Thu, 28 Aug 2003 16:27:15 -0400 Subject: OT: Americans love their guns In-Reply-To: References: Message-ID: |>USA gun-related deaths are ~29k/year |And my probability of being one of them is pretty low - because I am |usually armed ;) Obviously, your probability is MUCH, MUCH higher of being one of them, because you are armed. Most of them are suicides. My chance of being a gun-inflicted suicide is 0.00%... yours is more (maybe you don't suffer from depression now, and maybe no temporary personal tragedy has made you despondent... but if such things do happen [of course, I do not wish them on you]...) Moreover, some of the rest are accidents. Again, my odds... well, more than 0%, since my neighbors could misfire their guns in my direction. But still much less than yours. As for homicide, well, you're far more likely to be either a victim or a killer. If you are armed, it is quite possible that an angry loved one would have access to that gun.... and no doubt regret shooting you after his/her anger cooled. And should you be mugged on the street by a stranger, your chance of walking away dead (rather than just with less money), are MANY times higher if you pull a gun on your assailant. Yours, Lulu... P.S. But wow! Isn't it fun to hear a big bang on the target range :-(. -- mertz@ _/_/_/_/_/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY:_/_/_/_/ v i gnosis _/_/ Postmodern Enterprises _/_/ s r .cx _/_/ MAKERS OF CHAOS.... _/_/ i u _/_/_/_/_/ LOOK FOR IT IN A NEIGHBORHOOD NEAR YOU_/_/_/_/_/ g s From tjreedy at udel.edu Sat Aug 30 20:27:19 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 30 Aug 2003 20:27:19 -0400 Subject: list.sort(func) speed References: Message-ID: "mackstann" wrote in message news:mailman.1062286079.6474.python-list at python.org... > I have the following function that compares two filenames based on their > basename only: > > _basenameCmp = lambda self, *pair: cmp(*map(os.path.basename, pair)) > This is so that I can sort a list of files, and the sorting will be done > by filename, ignoring path. There is a minor issue which is not so much > a problem (yet) per se, but just made me curious if there was a better > way to go about this. When calling .sort() on my list, it takes 16ms to > complete. Calling .sort(_basenameCmp) on the same list takes 244ms. > This list could very well be 5 or 10 times the size, in use. Now, I > believe that my _basenameCmp() needs to be called a lot of times (er.. > can't figure out exactly how many, (len(mylist)/2)^2 ?) and doing a > string operation that many times is obviously going to slow it down. > > So my question is: Is there anything I could do differently or better > to speed this up? Google list for decorate sort undecorate pattern TJR From gafStopSpamData at ziplink.stopallspam.net Sun Aug 17 12:45:37 2003 From: gafStopSpamData at ziplink.stopallspam.net (Gary Feldman) Date: Sun, 17 Aug 2003 16:45:37 GMT Subject: ClientCookie bug (followup) References: <87fzk4sav2.fsf@pobox.com> <87znibzrnx.fsf@pobox.com> <87oeypdh92.fsf@pobox.com> Message-ID: On 16 Aug 2003 11:33:13 +0100, jjl at pobox.com (John J. Lee) wrote: > >Take note of this comment from the web page: > >| # Don't copy this blindly! You probably want to follow the examples >| # above, not this one. Since the purpose of that example seems to be to show how things work under the hood, may I suggest putting it on a separate page, and replacing it here with something like "Here is a
lower level example that shows how this works, though you would rarely want to implement things at this low level." Gary From ryanlowe0 at msn.com Tue Aug 19 20:31:28 2003 From: ryanlowe0 at msn.com (Ryan Lowe) Date: Wed, 20 Aug 2003 00:31:28 GMT Subject: if statement in for loop Message-ID: i thought id ask here before wirting a PEP, if people thought it would be a good enhancement to allow if clauses in regular for-statements like so: >>> for x in y if x < 10 : is semantically equivalent to >>> for x in [x for x in y if x < 10] : but is shorter and easier to read. basically, the if works as a filter for the values in the iterator. its not a major change, purely syntactic sugar. and clearly backwards-compatible. seem reasonable? ryan From tpeters at imaging.robarts.ca Fri Aug 29 11:32:07 2003 From: tpeters at imaging.robarts.ca (Terry M Peters) Date: Fri, 29 Aug 2003 11:32:07 -0400 (EDT) Subject: Away from my office Message-ID: <200308291532.h7TFW7Qx025704@theremin.irus.robarts.ca> I will be away from my office until September 3rd. If you have any questions relating to MICCAI 2003, please contact Dr Randy Ellis ellis at cs.queensu.ca (scientific) or Ms Janet Wallace jwallace at imaging.robarts.ca (administrative). Terry Peters From amk at amk.ca Wed Aug 20 13:54:34 2003 From: amk at amk.ca (A.M. Kuchling) Date: Wed, 20 Aug 2003 12:54:34 -0500 Subject: Python should try to displace Java References: <3f3e89f3$0$225$626a54ce@news.free.fr> Message-ID: On Wed, 20 Aug 2003 17:00:13 GMT, Alex Martelli wrote: > "happen" to be excellent for the job. Not just my opinion -- e.g., > Mitch Kapor and his OSAF chose Python as the application-programming > language for the Chandler system, and if you look at the specs for > that ambitious undertaking you'll see it WILL be quite a large-scale > system when it matures. I don't find OSAF's choice of Python to be much of an endorsement. Given that most of the principals involved didn't seem to actually know Python at the time of the initial announcement, I can only conclude that they thought choosing Python would give them some credibility in the open-source community, and not because they did a careful comparison of Python with the alternatives. --amk From nonotreally999 at yahoo.com Mon Aug 18 13:34:11 2003 From: nonotreally999 at yahoo.com (Tom) Date: 18 Aug 2003 10:34:11 -0700 Subject: What's better about Ruby than Python? References: Message-ID: "Brandon J. Van Every" wrote in message news:... > This is not a troll. "I am not a crook." R.Nixon Don't waste yr time feeding the trolls. (unless it amuses you) If you feel I'm being hard on the prolific Mr. Avery, do a search on his posts and decide for yourself. My personal opinion is that he, like any troll, wastes valuable c.l.p. cycles. If I remember correctly, a recent Avery post said he was finished with the c.l.p. group (oh, darn) and was moving on the the marketing-python mailing list. Guess he's back. Tom From op73418 at mail.telepac.pt Mon Aug 18 22:03:04 2003 From: op73418 at mail.telepac.pt (Gonçalo Rodrigues) Date: Tue, 19 Aug 2003 03:03:04 +0100 Subject: What's better about Ruby than Python? References: Message-ID: <0i03kvod921okq1p12kkurm0i37ufc78ln@4ax.com> On 19 Aug 2003 01:46:20 +0100, Alexander Schmolck wrote: >Gon?alo Rodrigues writes: > >> On 18 Aug 2003 23:40:58 +0100, Alexander Schmolck >> wrote: > >> >But of course what currently happens is: >> > >> >'just a method' >> > >> >> And rightly so, you have just rebinded a name. If you type >> >> x.__class__ >> >> you get the older X. Or are you proposing that rebinding X to >> automagically rebind the __class__ of all the X instances? > >Well, yes, I propose that x.__class__ return the *new* definition of X (like >in ruby, for example). I don't think that necessarily involves rebinding >anything "automagical", depending on how the lookup of x.__class__ works. > >Can you give my any reason why you would *not* want all instances to be >updated on class redefinition? > But in the example you gave you were not *redefining* the class referenced by X! You are *rebinding* the name X to a different class, two completely different things. So no, I do not want rebinding the name X => Automagically change instances of X.__class__ to the new class This strikes me as a very insane thing to do. That, or else I'm not understanding a thing of what you are saying -- which given that it's 3am and I am tired, it's not that farfetched. > >> >> But why can't you just >> >> X.amethod = lambda self: "ah, now THIS is better!" >> >> that is, mutate the class referenced by X instead of rebinding X to >> some other class? > >Um, didn't you read what I wrote or was I just unclear? > >To recap: usually, if I change a class I'd like all pre-existing instances to >become updated (Let's say you develop your program with a running python >session; you notice a mistake in a method-definition but don't want to start >over from scratch; you just want to update the class definition and have this >update percolate to all the currently existing instances. This is an *very* >reasonable wish if it doesn't just take seconds to get to the current state by >rerunning everything, but possibly hours or days). AFAIK doing this in a >general and painfree fashion is pretty much impossible in python (you have to >first track down all instances -- not an easy task, as far as I can see and >then updating their .__class__ might not quite work as expected either as I've >already mentioned). > >I think this sucks big time, because it greatly devalues the interactive >programming experience for certain tasks, IMHO, but maybe I'm just missing >something since typically nobody complains. > Um, you were unclear. I still can't understand why the following does not work for you: >>> class X(object): ... def amethod(self): ... return "I am %r." % self ... >>> x = X() >>> x.amethod() 'I am <__main__.X object at 0x010D4C10>.' >>> X.amethod = lambda self: "I am not who I am." >>> x.amethod() 'I am not who I am.' >>> It seems to cover the use case you describe above. There are other, more "violent" means of mucking with a class hierarchy, such as rebinding __class__ or __bases__ directly but that does not always work and is fraught with dangers. With my best regards, G. Rodrigues From robin at jessikat.fsnet.co.uk Wed Aug 20 12:17:22 2003 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Wed, 20 Aug 2003 17:17:22 +0100 Subject: It is possible to pass a Python callback to C-extensions? References: Message-ID: In article , Pierre Rouleau writes >I have a GUI application written in Python (with WxPython) which uses >some low level classes also written in Python. These low level Python >classes are given a pointer to some GUI Python object. The low level >Python classes callback some of the methods of the GUI object. All >works fine. > >Now I want to convert the low level Python classes to C++. I will be >using SWIG to create the marshaling so the top level GUI, written in >Python stays that way. > >The problem: is it possible to continue using call backs? The C++ code >would need to call the Python methods back. Is there an easy way to do >this? > certainly you can call back into python, I have some typical code that looks like PyObject *callback; ....... PyObject *arglist; PyObject *result; arglist = Py_BuildValue("(s)",buf); result = PyEval_CallObject(callback, arglist); Py_DECREF(arglist); if(result){ Py_DECREF(result); /*success*/ } else { /*handle error*/ } Of course you need to get the definition of callback somehow. But that is easy via argument passing or obtaining a global function. >This is a little different from extending or embedding. I have a Python >program that uses Python extensions written in C++. This C++ code would >need to pass some information back to the Python code (and currently, >the all-round Python code uses call backs). > > ..... >Thanks in advance for any help. > >/Pierre > -- Robin Becker From losnations at comcast.net Mon Aug 18 22:20:50 2003 From: losnations at comcast.net (Marc) Date: Mon, 18 Aug 2003 21:20:50 -0500 Subject: Design idea for Ping Application References: <4378fa6f.0308181546.548daff7@posting.google.com> Message-ID: Thanks Andrew, But alas I am working under a Windows environment. Actually I already have my threads running and can use them to ping using a direct call under the os module. But my problem was being able to have them running continuously. I guess technically using a threaded application they won't run continuously anyway since each thread will only get a piece of the clock. But it takes time to start the ping process going, and if I could simply find a way to read the data back to me from a running os process as opposed to having to stop it to read it. I guess the main question is are there any file functions, like readlines, that will only look at the available data and not look for EOF? Thanks again, Marc "Andrew Dalke" wrote in message news:bhrs4h$o5n$1 at slb5.atl.mindspring.net... > Marc: > > I've been searching old posts for ideas, and can't quite come up with > > anything. In short I need an application that will continuously ping > > 11 different hosts and track the status of the pings. > > That was a flashback. I posted a "sndping" module on this > list many years ago. It made a ping sound for every ping. > > > This works, but presents me with a problem. In order to continuously > > ping using the "-t" option for ping, I am unable to perform a > > readlines() command because it hangs. I've tried other variations of > > read commands, but they all hang my system. I guess it keeps looking > > for EOF and never finds it because the thing is still running. Is > > there a type of read command that just takes what is currently in the > > buffer and stores it? > > The normal way is to use the select module, at least for unixy > systems. > > %cat t.py > import os, select > > class Ping: > def __init__(self, hostname): > self.hostname = hostname > timeout = len(hostname) % 5 + 3 # for some variation > self.infile = os.popen("ping -i %d %s" % (timeout, hostname)) > def fileno(self): > return self.infile.fileno() > def readline(self): > return self.infile.readline() > > def report(hostnames): > pings = [Ping(name) for name in hostnames] > while 1: > print "Waiting for another ping ...." > r, w, e = select.select(pings, [], [], 1) > for p in r: > print "Ping", p.hostname, p.readline()[:-1] > > if __name__ == "__main__": > import sys > if len(sys.argv) == 1: > raise SystemExit("missing list of machines to ping") > else: > report(sys.argv[1:]) > > %python t.py biopython.org dalkescientific.com python.org > Waiting for another ping .... > Ping dalkescientific.com PING dalkescientific.com (66.39.47.217): 56 data > bytes > Waiting for another ping .... > Ping biopython.org PING biopython.org (155.94.54.81): 56 data bytes > Waiting for another ping .... > Ping python.org PING python.org (194.109.137.226): 56 data bytes > Waiting for another ping .... > Waiting for another ping .... > Waiting for another ping .... > Ping python.org 64 bytes from 194.109.137.226: icmp_seq=0 ttl=238 > time=96.553 ms > Waiting for another ping .... > Ping python.org 64 bytes from 194.109.137.226: icmp_seq=1 ttl=238 > time=94.554 ms > Waiting for another ping .... > Waiting for another ping .... > Waiting for another ping .... > Ping biopython.org 64 bytes from 155.94.54.81: icmp_seq=0 ttl=55 time=17.084 > ms > > You could also spawn off a thread for each one, but the select > approach is pretty simple. (See Aahz's thread tutorial for an example > of how to use threads for a similar task.) > > Andrew > dalke at dalkescientific.com > > From peter at engcorp.com Fri Aug 1 23:30:50 2003 From: peter at engcorp.com (Peter Hansen) Date: Fri, 01 Aug 2003 23:30:50 -0400 Subject: SSH and Windows References: <3F2069BD.1FE2EC2@engcorp.com> <7b454334.0308011350.226fd55@posting.google.com> Message-ID: <3F2B306A.A4BBD206@engcorp.com> Fazer wrote: > > Peter Hansen wrote in message news:<3F2069BD.1FE2EC2 at engcorp.com>... > > Isaac Raway wrote: > > > > > > Hello. I'm writing a Python program that connects to servers through > > > telnetlib to execute a few commands. I've discovered that some of the > > > servers that I have to connect to with this program run only SSH, so I > > > need to add support for SSH to the program. I'm looking for a library > > > that behaves similarly to telnetlib for SSH connections. Does anyone > > > know of one? I was going to try using pexpect to control the Windows > > > telnet command, but pexpect only works on Unix. > > > > If it's just to execute a few commands, consider downloading PLink > > (from the PuTTY site) and use it via os.system(). It works well. > > > > -Peter > > Hmm...is there a *nix version for PLink? I checked PuTTY's site and > it's all for Windows. Or maybe an alternative for PLink for *nix? Maybe try this. Tested (mostly) under Python 1.5.2 (as I recall, under Linux) and Python 2.0 under Windows: import sys import os import time True, False = 1, 0 class SshException(Exception): pass class LinuxSshSession: PAT_PASSWORD = '[pP]assword:' def __init__(self, host, user, password, timeout=30): self.host = host self.user = user self.password = password self.timeout = timeout self.verbose = True def scp(self, src, dest): import pexpect user = self.user host = self.host if self.verbose: sys.stdout.write('scp %(src)s %(user)s@%(host)s:%(dest)s ...' % locals()) sys.stdout.flush() began = time.time() try: # use compression (not that that would help with a .tgz file # and make sure we don't get messed up by the known_hosts file child = pexpect.spawn('scp -C' ' -o UserKnownHostsFile=/dev/null' ' -o StrictHostKeyChecking=no' ' %(src)s %(user)s@%(host)s:%(dest)s' % locals()) state = 'authorizing' while 1: #~ print '%s: %r///%r' % (state, child.before, child.after) if state == 'authorizing': match = child.expect([pexpect.EOF, pexpect.TIMEOUT, self.PAT_PASSWORD], timeout=self.timeout) if match == 0: raise SshException('failed to authenticate') elif match == 1: raise SshException('timeout waiting to authenticate') elif match == 2: child.sendline(self.password) state = 'copying' elif state == 'copying': match = child.expect([pexpect.EOF, pexpect.TIMEOUT, 'stalled', 'ETA'], timeout=self.timeout) if match == 0: break elif match == 1: raise SshException('timeout waiting for response') elif match == 2: state = 'stalled' elif state == 'stalled': match = child.expect([pexpect.EOF, pexpect.TIMEOUT, 'ETA'], timeout=self.timeout) if match == 0: break elif match == 1: import pdb pdb.set_trace() raise SshException('stalled for too long, aborted copy') elif match == 2: state = 'copying' finally: if self.verbose: elapsed = time.time() - began try: size = os.stat(src)[os.path.stat.ST_SIZE] rate = size / elapsed sys.stdout.write(' %.1fs (%d cps)\n' % (elapsed, rate)) except: sys.stdout.write(' %.1fs\n' % (elapsed)) def ssh(self, cmd): import pexpect user = self.user host = self.host if self.verbose: sys.stdout.write('ssh -l %(user)s %(host)s \"%(cmd)s\"\n' % locals()) sys.stdout.flush() # use compression # -o options make sure we don't get messed up by the known_hosts file child = pexpect.spawn('ssh -C' ' -o UserKnownHostsFile=/dev/null' ' -o StrictHostKeyChecking=no' ' -l %(user)s %(host)s ' '\"%(cmd)s\"' % locals()) state = 'authorizing' while 1: if state == 'authorizing': match = child.expect([pexpect.EOF, pexpect.TIMEOUT, self.PAT_PASSWORD], timeout=self.timeout) if match == 0: raise SshException('failed to authenticate') elif match == 1: raise SshException('timeout waiting to authenticate') elif match == 2: child.sendline(self.password) state = 'running' elif state == 'running': match = child.expect([pexpect.EOF, pexpect.TIMEOUT], timeout=self.timeout) if match == 0: break elif match == 1: raise SshException('timeout waiting to finish') return child.before class WindowsSshSession: def __init__(self, host, user, password, timeout=30): self.host = host self.user = user self.password = password def scp(self, src, dest): user = self.user host = self.host password = self.password return os.system('pscp -pw %(password)s %(src)s %(user)s@%(host)s:%(dest)s' % locals()) def ssh(self, cmd): user = self.user host = self.host password = self.password os.system('plink -pw %(password)s -ssh %(user)s@%(host)s "%(cmd)s"' % locals()) def SshSession(host, user, password, timeout=30): if sys.platform == 'win32': sessionClass = WindowsSshSession else: # assume we're on linux if platform is not windows sessionClass = LinuxSshSession return sessionClass(host, user, password, timeout) -Peter From p-abel at t-online.de Fri Aug 8 12:05:05 2003 From: p-abel at t-online.de (Peter Abel) Date: 8 Aug 2003 09:05:05 -0700 Subject: passing multiple strings to string.find() References: <3F331A9B.9020907@vt.edu> Message-ID: <13a533e8.0308080805.e23ca20@posting.google.com> hokiegal99 wrote in message news:<3F331A9B.9020907 at vt.edu>... > How do I say: > > x = string.find(files, 'this', 'that', 'the-other') > > currently I have to write it like this to make it work: > > x = string.find(files, 'this') > y = string.find(files, 'that') > z = string.find(files, 'the-other') If your problem is to know, if files in flist and if yes to get the index of the first occurence then the following could help: >>> files='that' >>> flist=['this', 'that', 'the-other'] >>> (files in flist and [flist.index(files)] or [None])[0] 1 Regards Peter From tismer at tismer.com Fri Aug 8 09:52:23 2003 From: tismer at tismer.com (Christian Tismer) Date: Fri, 08 Aug 2003 15:52:23 +0200 Subject: Game Company looking for Employiees In-Reply-To: References: Message-ID: <3F33AB17.1000905@tismer.com> BlackHawke wrote: ... > 1: We need python scripters. Much of the programming used for the servers > must necessarily be in python. The bulk of our code will be in Python, and > we have no access to Python programmers at the moment. > > 2: We need people capable of programming vast worlds in the CrystalSpace 3d > engine. While we do have excellent graphic artists on hand, we have no-one > capable of developing the lands and cities in this game. We have chosen > CrystalSpace because of our financial concerns. > 3. Since this is an MMORPG, you probably need Stackless Python. This has been most successfully used in the EVE online game. will contact you by privat mail -- chris -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 pager +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From klapotec at chello.at Mon Aug 4 12:19:21 2003 From: klapotec at chello.at (Christopher Koppler) Date: Mon, 04 Aug 2003 16:19:21 GMT Subject: python 2.3 final References: <3F2E81FC.4040903@vt.edu> Message-ID: On Mon, 04 Aug 2003 11:55:40 -0400, hokiegal99 wrote: >I'm new to Python. I have been using 2.3b2 for several months now with >good results. I assumed that once the beta was good enough that Python >2.4 would be released, but today I noticed that there is a 2.3 final >release. I'm used to odd point releases being beta or testing, but it >seems that that isn't true in Python. Spot on! Linux does the 'odd version is experimental' bit, and other open source projects have followed that kind of versioning, but every release in Python that's not marked alpha, beta, or release candidate is a 'real', stable release. --Christopher From timow at nwn.de Thu Aug 7 06:25:46 2003 From: timow at nwn.de (Timo Warns) Date: 7 Aug 2003 10:25:46 GMT Subject: Auto persistency References: Message-ID: Timo Warns wrote: > Batista, Facundo wrote: > > > > [Example of class with get- and set-methods] > > > > [...] > > This is some kind of a design pattern often called "data access > objects". Java has this already built-in with its JDOs. Actually "built-in" is a little misleading ;-) There is an optional package from Sun available. Strictly it is not part of the language. Sorry for that. Timo From adalke at mindspring.com Fri Aug 1 22:08:16 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Fri, 1 Aug 2003 20:08:16 -0600 Subject: OT: Re: Voting Project Needs Python People References: <7x65lv31hf.fsf@ruckus.brouhaha.com> <3jhTa.115229$Io.9825106@newsread2.prod.itd.earthlink.net> Message-ID: At present there are 50 people who paid the non-refundable fee for running for the California governship. The article I just read said the standard ballot used could handle up to 300 entires. That brings to mind one of the things I don't like about the touchscreen solution -- I like to see my whole ballot at once. In this case, could you even fit 50 names for this one category on the screen at once and be readable enough? Then again, I would also like a desk sized display with 200+ dpi. Just gotta wait 10 years, right? Andrew dalke at dalkescientific.com From ryanlowe0 at msn.com Tue Aug 19 23:30:35 2003 From: ryanlowe0 at msn.com (Ryan Lowe) Date: Wed, 20 Aug 2003 03:30:35 GMT Subject: if in for loop References: Message-ID: "Sean Ross" wrote in message news:igA0b.4602$HB4.657643 at news20.bellglobal.com... > "Ryan Lowe" wrote in message > news:rkz0b.126472$_R5.47133670 at news4.srv.hcvlny.cv.net... > > i thought id ask here before wirting a PEP, if people thought it would be > a > > good enhancement to allow if clauses in regular for-statements like so: > > Hi. > This was brought up in July: > http://groups.google.ca/groups?hl=en&lr=&ie=UTF-8&selm=840592e1.0307021036.5 08d7d7d%40posting.google.com > > Here's the link for the entire thread: > http://groups.google.ca/groups?hl=en&lr=&ie=UTF-8&threadm=840592e1.030702103 6.508d7d7d%40posting.google.com&rnum=1&prev=/groups%3Fhl%3Den%26lr%3D%26ie%3 DUTF-8%26selm%3D840592e1.0307021036.508d7d7d%2540posting.google.com > > This was my response then (and now): > http://groups.google.ca/groups?hl=en&lr=&ie=UTF-8&selm=LUYMa.5841%24eF3.7215 51%40news20.bellglobal.com > > Other opinions will differ. (For instance, Michele Simionato was +1 on the > idea) > > > -0 > > Sean Ross >> >>> for x in y if x < 10 : >> >> is semantically equivalent to >> >> >>> for x in [x for x in y if x < 10] : >> well ok, so it wasnt a unique idea. but hey, if multiple people think the same thing up independently, maybe theres something there... i like list-comprehensions, they add a lot to the language, but they do seem sort of thrown in. fixing the symmetry, as the july poster put it, is a good way to think about it. your complaint is this? >(being symmetrical) we should also be able to write: > >>>> msgs = [] >>>> for x in words: >... for y in otherwords: >... msgs.append("%s %s"%(x,y)) >... >>>> msgs >['hello foo', 'hello bar', 'bonjour foo', 'bonjour bar'] > > >as follows: > >msgs = [] >for x in words for y in otherwords: > msgs.append("%s %s"%(x,y)) i agree its not as clear whats going on here as in the if example, but its no less readable than the list-comprehension version, i.e. msgs = ["%s %s"%(x,y) for x in words for y in otherwords] whats the argument? should they do away with double for's in list-comp? >It doesn't do anything for me. I actually find it harder to >read: the brackets at least guide my eyes to the various parts >of the line, which the form you propose doesn't do. >Also, its most definitely >not backwards compatible, and I wish you wouldn't >send three duplicate messages to the newsgroup with >different headers but the same body. **harder** to read!? cmon now. i will buy its certainly not a necessary change, but harder to read... all i meant by it being backwards compatible is that for statements without the clause would work as they did before. sorry about the triple post. i got error messages when i posted so i didnt think they went through. ryan From cnetzer at sonic.net Wed Aug 13 02:21:16 2003 From: cnetzer at sonic.net (Chad Netzer) Date: Tue, 12 Aug 2003 23:21:16 -0700 Subject: Multi-Line Comment In-Reply-To: <200308122306.48320.shalehperry@comcast.net> References: <4qofjvg3bh9smlnb1do4f0lhjga7bacnu3@4ax.com> <200308122306.48320.shalehperry@comcast.net> Message-ID: <1060755676.18368.76.camel@adsl-209.204.179.133.sonic.net> On Tue, 2003-08-12 at 23:06, Sean 'Shaleh' Perry wrote: > On Tuesday 12 August 2003 22:07, Christopher Blunck wrote: > > > > > > Nope, no multi-line comment. > > That always stumped me as well. Any idea what the justification for this > > was, Skip? > none of the other shell/script languages have one either. I rarely miss it. Multiline comments can be easily made with triplle quoted strings, or with Emacs (it folds long single line comments into multiple line comments). And for commenting out blocks of code, my good pal "if 0:" works great (along with block indent/dedent with a decent editor) -- Chad Netzer From belred1 at yahoo.com Tue Aug 19 21:23:33 2003 From: belred1 at yahoo.com (Bryan) Date: Wed, 20 Aug 2003 01:23:33 GMT Subject: distutils Message-ID: what is the correct way to pass custom values to a distutil's setup script? i'd like to pass on the command line the libraries_dir path. should i just parse it out from sys.argv? thanks, bryan From theller at python.net Tue Aug 12 16:00:22 2003 From: theller at python.net (Thomas Heller) Date: Tue, 12 Aug 2003 22:00:22 +0200 Subject: Possible to install from CD using distutils? References: Message-ID: sjmachin at lexicon.net (John Machin) writes: > Martin v. L wis wrote: >> "Simon Wittber (Maptek)" writes: >> >> >Try this command. It will let you write to a CD drive. >> > >> >mount -o rw /dev/cdrom /mnt/cdrom >> >> Did you try this? You can't mount a cdrom rw - the hardware just does >> not support writing to a CD-*ROM* (Read-Only Memory). > > I tried it but the computer typed this back at me: > > 'mount' is not recognized as an internal or external command, > operable program or batch file. > > What is this "mount"? Where can I get it from? Install Linux. Thomas (sorry, couldn't resist) From jjl at pobox.com Mon Aug 25 08:38:19 2003 From: jjl at pobox.com (John J. Lee) Date: 25 Aug 2003 13:38:19 +0100 Subject: macro FAQ References: <2259b0e2.0308240103.3966476b@posting.google.com> <87znhzi4k4.fsf@pobox.com> Message-ID: <87k791di9w.fsf@pobox.com> Jacek Generowicz writes: > jjl at pobox.com (John J. Lee) writes: > > > I'm sure you're capable of understanding this position, but the > > argument has started going round in circles. > > As I've said repeatedly: > > - I do _not_ necessarily advocate the inclusion of macros in Python. But you do advocate them in other languages, right? And that was a significant part of the argument. > - I merely wish to dispel the myth that macros make code less > readable[*]: they _ease_ understanding of the code. > > > [*] And they don't fragment languages either. John From bignose-hates-spam at and-benfinney-does-too.id.au Sun Aug 3 22:59:44 2003 From: bignose-hates-spam at and-benfinney-does-too.id.au (Ben Finney) Date: 4 Aug 2003 12:49:44 +0950 Subject: [OT] Google URLs (was Re: popen eating quotes?) References: <20030803202417.GA10412@unpythonic.net> Message-ID: On Sun, 3 Aug 2003 17:45:00 -0600, Steven Taschuk wrote: > Not memorable, but at least shorter, is > > In general all you need is the threadm or selm parameter, which > gives the message-id of the post in question; if memory serves, > threadm and selm differ in whether the resulting page shows the > rest of the thread. Fortunately, the Message-Id: is available in the message itself (it's part of every NNTP posting), so even without Google you theoretically have complete information to give the Google Groups URL for any post: for threaded, or for the message alone. > All discovered empirically. Use at your own risk. Likewise. -- \ Eccles: "I just saw the Earth through the clouds!" Lew: "Did | `\ it look round?" Eccles: "Yes, but I don't think it saw me." | _o__) -- The Goon Show, _Wings Over Dagenham_ | Ben Finney From dave at psys.org Wed Aug 20 10:01:25 2003 From: dave at psys.org (d.w. harks) Date: Wed, 20 Aug 2003 09:01:25 -0500 Subject: PyQT installation problems In-Reply-To: References: Message-ID: <200308200901.25939.dave@psys.org> On Wednesday 20 August 2003 04:54 am, Stelian Iancu wrote: > Hello all! > > I am trying to install eric3, the Python IDE. I've downloaded and installed > successfully sip-3.8, QScintilla-1.2 and PyQT-3.8. However, when I try to > install eric, I get the following error: > > Sorry, please install PyQt. > > I looked into the install script, then I opened a Python window and there I > tried import qt and I got the following error: > > Traceback (most recent call last): > File "", line 1, in ? > File "/usr/lib/python2.2/site-packages/qt.py", line 25, in ? > import libqtc > ImportError: /usr/lib/python2.2/site-packages/libqtcmodule.so: undefined > symbol: _ZNK9QSGIStyle9classNameEv > > I am using Mandrake 9.1 with the default Python (2.2.3) and Qt. > I just got PyQt going on Mandrake, and it's a trick. Best way I found was to go to http://www.rpmfind.net and grab the .src.rpm's of PyQt and SIP, edit the .spec files to ensure that you're using the correct Python version, and build from source (rpm -bb ). Another way is to use the packages from pykde.sf.net, which are a bit older, but seem to work fine. dave -- d.w. harks http://dwblog.psys.org From nick.keighley at marconi.com Wed Aug 20 04:15:44 2003 From: nick.keighley at marconi.com (Nick Keighley) Date: 20 Aug 2003 01:15:44 -0700 Subject: class factory Message-ID: <8ad2cfb3.0308200015.4f5bd504@posting.google.com> Hi, I'm a Python beginner and I'm would like to write a function that returns a class (perhaps a tad ambitious...). I've looked through the FAQ and perused "Python In A Nutshell" (not a good book to start with?). The only example I found in PiaN used a simple if statement to return one of a selection of pre-existing classes. I'd like to generate a class on-the-fly from a parameter (a dictionary). Can Python do this sort of stuff? Does the mean I have to mess with the dreaded meta-classes? thanks for any help anyone can give. -- Nick Keighley It's always September. But sometimes it is _more_ September. From cjw at sympatico.ca Sat Aug 16 12:56:22 2003 From: cjw at sympatico.ca (Colin J. Williams) Date: Sat, 16 Aug 2003 12:56:22 -0400 Subject: how does the main module notice when I change a module In-Reply-To: References: Message-ID: Bob Gailer wrote: > At 01:55 PM 8/15/2003 -0700, Marcus Schneider wrote: > >> I use PythonWin on WinXP. Every time I change a module, I have to >> leave PythonWin and re enter to make it notice I have made changes. I >> guess this is not the normal way to do that.. do I have to store the >> module at a specific place? Is there a kind of "reset" command to make >> the main module update specific data? > > > Notice File -> Import (ctrl+I) and its toolbar icon. I don't find (ctrl I) in the PythonWin Keyboard Bindings. My practice is to delete the .pyc file when this problem arises. Colin W > > Bob Gailer > bgailer at alum.rpi.edu > 303 442 2625 > > > ------------------------------------------------------------------------ > > > --- > Outgoing mail is certified Virus Free. > Checked by AVG anti-virus system (http://www.grisoft.com). > Version: 6.0.506 / Virus Database: 303 - Release Date: 8/1/2003 From fredrik at pythonware.com Fri Aug 15 15:23:32 2003 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 15 Aug 2003 21:23:32 +0200 Subject: Strange re behavior: normal? References: Message-ID: Mike Rovner wrote: > With all due respect to Python and not trying to bend it to any other > language I believe it trys to do what user expects. it does exactly what I expect it to do. From mpeuser at web.de Tue Aug 12 08:12:32 2003 From: mpeuser at web.de (Michael Peuser) Date: Tue, 12 Aug 2003 14:12:32 +0200 Subject: Scanning through Directory Message-ID: There is a portable way of reading directories os.listdir in conjunction with os.stat and a little help from os.path.split and os.path.join Though using os.stat gives programs a somewhat clumbsy look, I had not been too annoyed with it until I tried to scan a whole disk. Reworking the join and split operations already gave a considerable speed-up As I need it for Windows I then with very little effort changed to: win32api.FindFiles (I already had used win32api.GetDiskFreeSpace) This was a breakthrough: 5 secs instead of 50+ ! os.listdir seems to do little more than win32api FindFiles How can it be so slow??? Why is there no portable way of getting "DiskFreeSpace" info Questions and Questions.... I strongly recommend the win32api calls it you have similar applications. The interface is extremely simple and the only penalty is non-compatibility ;-) I also recommend to use the Python profiler from time to time for programms running more than one second. It might give you interesting insights... Kindly Michael Peuser From cookedm+news at physics.mcmaster.ca Wed Aug 6 16:36:54 2003 From: cookedm+news at physics.mcmaster.ca (David M. Cooke) Date: Wed, 06 Aug 2003 16:36:54 -0400 Subject: mailbox.py examples (Maildir) References: Message-ID: At some point, Matej Cepl wrote: > Hi, > > is there any example of use of mailbox.py. I would be especially > interested if anybody made a objects which would be able to .delete() > .append() etc. individual messages. > > Thanks, mailbox.py unfortunately only reads mailboxes (although it does handle most formats, including Maildir, which is nice). offlineimap (gopher://gopher.quux.org/1/devel/offlineimap) [1] uses Maildir for storing messages, so you may want to look at it. [1] I was pretty sure gopher was dead. There's a web interface at http://gopher.quux.org:70/devel/offlineimap/ for those of us living in the 21st century ;) -- |>|\/|< /--------------------------------------------------------------------------\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca From maxm at mxm.dk Tue Aug 12 04:36:52 2003 From: maxm at mxm.dk (Max M) Date: Tue, 12 Aug 2003 10:36:52 +0200 Subject: ANNOUNCE: Rekall V2.0.2 In-Reply-To: <3F385CAB.6000705@festina-lente.qc.ca> References: <5.2.1.1.0.20030810065523.02c3ed10@66.28.54.253> <3F385CAB.6000705@festina-lente.qc.ca> Message-ID: <3f38a68d$0$97261$edfadb0f@dread12.news.tele.dk> Benoit Caron wrote: > The goal being to build an application that make somebody able to build > a small database-using application with no fuss, with the option of > building "semi-automatically" a web interface to it's database. > > So, anybody think this would have users? Yes. But wouldn't it be smarter to just make an access-like graphical interface to the multiple databases that Python supports? Like when Access is used to connect to other databases through ado/odbc? regards Max M From tzot at sil-tec.gr Thu Aug 7 06:22:28 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Thu, 07 Aug 2003 13:22:28 +0300 Subject: check if running under IDLE References: <3f2ec16b$0$285$ba620e4c@reader0.news.skynet.be> Message-ID: On Mon, 04 Aug 2003 22:26:19 +0200, rumours say that Helmut Jarausch might have written: >Is there a mean either to set sys.argv without modifying >the script or to check if the script is running under IDLE's >control. Try checking what is the sys.stdin.__class__ . -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From dave at pythonapocrypha.com Thu Aug 28 12:43:37 2003 From: dave at pythonapocrypha.com (Dave Brueck) Date: Thu, 28 Aug 2003 10:43:37 -0600 Subject: OT: Americans love their guns In-Reply-To: <3F4E7ED9.924AEAF2@engcorp.com> References: <3F4E7ED9.924AEAF2@engcorp.com> Message-ID: <200308281043.37484.dave@pythonapocrypha.com> On Thursday 28 August 2003 04:14 pm, Peter Hansen wrote: > Dave Brueck wrote: > > On Thursday 28 August 2003 12:40 pm, Lulu of the Lotus-Eaters wrote: > > > |The odds of getting killed that way are roughly the same as the odds > > > |that you'll die from aspirin or similar drugs > > > > > > No... this one is just way off. According to above URL form: > > > > > > 2000, United States > > > Adverse effects - Drugs Deaths and Rates per 100,000 > > > All Races, Both Sexes, All Ages > > > ICD-10 Codes: Y40-Y59,Y88.0 > > > > > > Number of Deaths Population Crude Rate Age-Adjusted Rate** > > > 255 275,264,999 0.09 0.09 > > > > Aren't statistics fun? :) > > > > Think about it: even intuitively, 255 is *way* too low for a population > > of 275 million (that's essentially zero - in a population that size 255 > > people probably die in sneezing-releated incidents every year) - I don't > > think that statistic represents what you think it represents. > > Dave, I think you missed the "rates per 100,000" part, above. That > means roughly 700,000 deaths for the population given, not 255. That's what I thought too initially, but the actual web page itself suggests otherwise. OTOH, if it *is* 255 per 100k, then that just makes my previous comment *more* true, and I don't think Lulu was attempting to do that! ;-) -Dave From raims at dot.com Mon Aug 18 12:12:09 2003 From: raims at dot.com (Lawrence Oluyede) Date: Mon, 18 Aug 2003 18:12:09 +0200 Subject: python and symbian? References: Message-ID: Skip Montanaro wrote: > What's symbian? Symbian OS is the OS of new generation mobile phones made by Nokia, Sony Ericsson and so on Symbian itself is a consortium endorsed by Nokia, Siemems, Sony Ericsson Motorola et. al. Some of the mobile phones with Symbian OS are Nokia 3650 and Sony Ericsson P800 The OS ships with C++ SDK, Java and VB AFAIK www.symbian.com -- Lawrence "Rhymes" Oluyede http://loluyede.blogspot.com rhymes at NOSPAMmyself.com From abelikov72 at hotmail.com Mon Aug 25 16:05:18 2003 From: abelikov72 at hotmail.com (Afanasiy) Date: Mon, 25 Aug 2003 20:05:18 GMT Subject: python gripes survey References: <78kkkvg8ckfio141es2of1p483ohbtbit5@4ax.com> Message-ID: <0rqkkv481p8ob48ppbdikh95kn96jb9fe1@4ax.com> On Mon, 25 Aug 2003 06:44:03 -0600, Dave Brueck wrote: >On Monday 25 August 2003 12:14 pm, Afanasiy wrote: > >> I have a bunch, many of them hard to define, but one that I just thought >> of I find strange sometimes is the use of tuples as near-mystery return >> values. I can't help but thinking a C struct with named fields is easier >> to remember than a tuple with fields accessed by integer. >> >> Sure you can return an associative array, but in my experience the >> preference is to return a tuple. I'll probably get flamed for saying so, >> but this is how I feel and it is unavoidable. Returning a struct in C is >> easier to deal with than returning a near-mystery tuple in Python. > >A bit of an apples-to-oranges comparison, isn't it? If you prefer to return a >named structure in C, the Python equivalent certainly wouldn't be a tuple. That's exactly my point. The Python equivalent certainly isn't a tuple. The comparison with C is to explain, AND also happens to point to WHY code like this exists in libraries which come with Python. From gmessmer at real.com Mon Aug 11 15:15:58 2003 From: gmessmer at real.com (Gordon Messmer) Date: Mon, 11 Aug 2003 12:15:58 -0700 Subject: IO timeout in threaded application Message-ID: <3F37EB6E.4080306@real.com> According to the "signal" documentation, threads spawned as part of a multi-threaded application can not receive signals. I have a daemon which I want to validate email addresses by connecting to the MX for the domain and sending the EHLO/MAIL/RCPT commands. I would like to place an upper limit on the amount of time spent doing the validation. I had expected to be able to schedule an alarm() in a thread, and use that to interrupt the otherwise blocking read/writes. What's the easiest way to accomplish that? Should I just subclass smtplib's SMTP class and override the "connect" function with one that creates a socket with a timeout? From martin at v.loewis.de Sun Aug 3 13:48:22 2003 From: martin at v.loewis.de (Martin v. =?iso-8859-15?q?L=F6wis?=) Date: 03 Aug 2003 19:48:22 +0200 Subject: Python and XML References: Message-ID: "Matthieu M." writes: > from xml.dom import pulldom [...] > ImportError: No module named dom > > When I look in my Python folder I see .py files in xml/dom... Please report 1. the output of import xml print xml.__file__ 2. The contents of the directory printed above 3. The contents of the dom directory inside. Regards, Martin From benny at coca-kohler.de Thu Aug 7 04:20:05 2003 From: benny at coca-kohler.de (bk) Date: Thu, 7 Aug 2003 10:20:05 +0200 Subject: makepy must be run after restart of pythonwin Message-ID: <001501c35cbc$b74d2840$0d00a8c0@maitai> hi, thank you for the hint, but i solved the problem myself. i didnt knew that that the following two lines in py-script must be added: from win32com.client import gencache gencache.EnsureModule('{00062FFF-0000-0000-C000-000000000046}',0,8,0) now it works fine. my skills in python in python are not really advanced, so the python-mailinglists are good help for me. so long ben >hi, > >i'm using pythonwin 2.2.3 >my programm reads and write the outlook-adress book using COM. for this i >have to use the makepy utility. after i have run the utiltity everything is >fine and i can run my py-file without any errors. >but if i close the pythonwin and restart and then try to run my py-script i >get the following error: > >File "C:\Program Files\Python22\contacts_ausgabe.py", line 45, in >DumpDefaultAddressBook > folder = >mapi.GetDefaultFolder(win32com.client.constants.olFolderContacts) > File "C:\PROGRA~1\Python22\lib\site-packages\win32com\client\__init__.py", >line 168, in __getattr__ > raise AttributeError, a >AttributeError: olFolderContacts I suggest you examine the attributes of win32com.client.constants. Perhaps there is a case sensitivity issue. makepy can cause attributes that were previously case insensitive to become case sensitive. I also recall somewhere a discussion about win32com.client.constants not being populated immediately. Consider waiting a moment after dispaching. Bob Gailer bgailer at alum.rpi.edu 303 442 2625 From syver-en+usenet at online.no Fri Aug 29 18:41:45 2003 From: syver-en+usenet at online.no (Syver Enstad) Date: 30 Aug 2003 00:41:45 +0200 Subject: how does python use its .lib files? References: Message-ID: "George Khoury" writes: > I am just starting to code some c extensions, and have been > experimenting with both the Borland and MSVC compilers. Everything > works, but I have a basic question. When using Borland, I have to > make an OMF version of Python23.lib. Does this mean I now have two > copies of the python interpreter? No, Python23.lib is not a traditional .lib file, it is a so called import library, which just makes your C linker happy, and actually links in the code via the Python23.dll at runtime. > Or maybe I should ask another question. Suppose I have imported two > extension modules compiled with MS and Borland. If they both call a > python function (say, PyArg_ParseTuple), they are linking to two > different libraries, but the same function, right? They are linked to two different import libraries, but they actually link dynamically to the same dynamic link library Python23.dll. The reason you have to use two different .lib files is that MSVC and Borland uses two different .lib file formats. The .dll format is defined by the operating system so that format is fixed. -- Vennlig hilsen Syver Enstad From ryanlowe0 at msn.com Mon Aug 25 17:52:06 2003 From: ryanlowe0 at msn.com (Ryan Lowe) Date: Mon, 25 Aug 2003 21:52:06 GMT Subject: python gripes survey References: <78kkkvg8ckfio141es2of1p483ohbtbit5@4ax.com> <0rqkkv481p8ob48ppbdikh95kn96jb9fe1@4ax.com> Message-ID: "Afanasiy" wrote in message news:0rqkkv481p8ob48ppbdikh95kn96jb9fe1 at 4ax.com... > On Mon, 25 Aug 2003 06:44:03 -0600, Dave Brueck > wrote: > > >On Monday 25 August 2003 12:14 pm, Afanasiy wrote: > > > >> I have a bunch, many of them hard to define, but one that I just thought id like to hear them if you get the chance. > >> of I find strange sometimes is the use of tuples as near-mystery return > >> values. I can't help but thinking a C struct with named fields is easier > >> to remember than a tuple with fields accessed by integer. dont access the return values by their index; just unpack 'em. def getFruit() : return 'apples', 'oranges' apples, oranges = getFruit() > >> Sure you can return an associative array, but in my experience the > >> preference is to return a tuple. I'll probably get flamed for saying so, > >> but this is how I feel and it is unavoidable. Returning a struct in C is > >> easier to deal with than returning a near-mystery tuple in Python. > > > >A bit of an apples-to-oranges comparison, isn't it? If you prefer to return a > >named structure in C, the Python equivalent certainly wouldn't be a tuple. > > That's exactly my point. The Python equivalent certainly isn't a tuple. > The comparison with C is to explain, AND also happens to point to WHY code > like this exists in libraries which come with Python. From trentm at ActiveState.com Mon Aug 25 13:52:19 2003 From: trentm at ActiveState.com (Trent Mick) Date: Mon, 25 Aug 2003 10:52:19 -0700 Subject: Common tasks in python In-Reply-To: ; from PieterB+news@gewis.nl on Mon, Aug 25, 2003 at 06:05:45PM +0200 References: Message-ID: <20030825105219.C7530@ActiveState.com> [PieterB wrote] > I noticed the URL http://starship.python.net/~da/commontasks/ > gives a 404 ERROR. That page is quite usefull. It's still in Google's > Cache BTW, > http://www.google.com/search?sourceid=navclient&ie=UTF-8&oe=UTF-8&q=site:starship%2Epython%2Enet+commontasks > > I something wrong with the starship, or is the page removed? If you go up one-level: http://starship.python.net/~da/ You get: I got rid of this web site because I could never keep it up to date. I'm too busy at ActiveState. If you need something that you think I have, find me and ask me nicely. My email address is made up of my first name and my first initial, at my employer's domain name. David Ascher Trent -- Trent Mick TrentM at ActiveState.com From andrew-pythonlist at puzzling.org Tue Aug 12 05:41:56 2003 From: andrew-pythonlist at puzzling.org (Andrew Bennetts) Date: Tue, 12 Aug 2003 19:41:56 +1000 Subject: Python vs. C# In-Reply-To: References: <3f357a9b@shknews01> Message-ID: <20030812094156.GC4576@frobozz> On Tue, Aug 12, 2003 at 02:27:26AM -0700, Brandon J. Van Every wrote: > > Good to hear that some people understand what it means when Microsoft puts > 100% of the company behind something. Remember, last time around we got IE > and Netscape vanished. When was that? I'm happily running Mozilla as my web browser, and have been for well over a year now. I'm hardly alone in this. Sure, Netscape-the-company might be effectively dead, but I don't care about that. Their software, on the other hand, is still alive, improving, and gaining market-share (according to some reports, at least). And it's software we're talking about here -- we're discussing programming languages, after all. To point out that Microsoft effectively killed a particular company while that company's software is thriving seems like a misleading misdirection of the discussion, to me... After all, if MS collapsed tomorrow, but C# looked to have a vibrant community and industry support behind it keeping it developing, would ditch it just because MS was dead? -Andrew. From pinard at iro.umontreal.ca Wed Aug 27 16:21:34 2003 From: pinard at iro.umontreal.ca (Francois Pinard) Date: 27 Aug 2003 16:21:34 -0400 Subject: Filtering virus-related e-mails? In-Reply-To: <7h3ad9v6jqu.fsf@pc150.maths.bris.ac.uk> References: <3f4ce4d6$0$166$a1866201@newsreader.visi.com> <7h3ad9v6jqu.fsf@pc150.maths.bris.ac.uk> Message-ID: [Michael Hudson] > I gather virus warning emails are quite hard to filter due to each virus > program having a different format. As my own name has been much (ab)used in `From' lines for such virus, I've been receiving a great deal of such rejects for many days. It peeked at around 5000 per day, but this is now decreasing. Despite I use a few filtering devices already (spambayes is one of them!), a lot was going through, and I had to spend the last two days for teaching my -- unpublished -- filters how to do a better job for that overwhelming mass of meta-email about viruses that was (incorrectly) sent back to me. The thing now seem efficient enough, yet still, a few are slipping through. I've nothing against sharing my code. On the other hand, I might not be available enough to promise support: this has been written to solve personal needs and might use configuration choices that would not please others. Some anti-spam tools have a lot, lot more knowledge than my own filters. Moreover, for the above processing, I did the work in a rush, not seeking the ideal parameterisation. Also, the overall thing might be a bit tersely documented. But if it could give ideas to the Python list maintainers (or anyone else), I'm quite willing to make it available on request. > Ten minutes after instituting the clever hack that saved mail.python.org, > about 250 hosts were being rejected at the firewall level. What is that clever hack? I'm mostly curious, but maybe interested too! :-) -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From fawcett at teksavvy.com Wed Aug 13 21:03:06 2003 From: fawcett at teksavvy.com (Graham Fawcett) Date: Wed, 13 Aug 2003 21:03:06 -0400 Subject: Determine file type (binary or text) In-Reply-To: References: <20030813105623.J19120@ActiveState.com> Message-ID: <3F3ADFCA.1080100@teksavvy.com> John Machin wrote: >Graham Fawcett wrote in message news:... > > >>It is trivial to create a non-text file that has no NULs. >> >> f = open('no_zeroes.bin', 'rb') >> for x in range(1, 256): >> f.write(chr(x)) >> f.close() >> >> > >I tried this but it didn't work. It said: > >IOError: [Errno 2] No such file or directory: 'no_zeroes.bin'. > >So I thought I had to be persistent but after doing it a few more times it said: > >SerialIdiotError: What I tell you three times is true. >NotLispingError: You need 'wb' as in 'wascally wabbit' > >This is very strange behaviour -- does my computer have worms? > > No, but my brain does. Glad you caught my typo. However, it looks like your computer definitely has an AttitudeError! -- Graham From marc.poinot at dlr.de Tue Aug 12 07:12:07 2003 From: marc.poinot at dlr.de (Marc Poinot (Onera)) Date: Tue, 12 Aug 2003 13:12:07 +0200 Subject: TarFile using binary strings Message-ID: <3F38CB87.5831C2EE@dlr.de> Hi all, I have a DBMS with Blobs, I want to export them into a tar.gz file using the TarFile module. So far, I'm using a temporary file for the tar file creation, each blob is exported into a file and then added to the tar file. Is it possible to avoid the temporary files, and read the stream from the binary string coming from DBMS ? The TarInfo object uses a fileobj Python type, is there any trick (or module) to make TarInfo happy with a 'possible' fileobj-like on a memory zone ? marcvs [alias Hmmm... but you have 2Gb memory and 800Gb disk, so ?] From sismex01 at hebmex.com Fri Aug 29 11:52:57 2003 From: sismex01 at hebmex.com (sismex01 at hebmex.com) Date: Fri, 29 Aug 2003 10:52:57 -0500 Subject: Getting class name Message-ID: [Travis Whitton] > Is it > possible to get a classes name from inside of a class? Shure! class XXX: ... method YYY(self, ...): ... print self.__class__.__name__ HTH! -gustavo Advertencia:La informacion contenida en este mensaje es confidencial y restringida, por lo tanto esta destinada unicamente para el uso de la persona arriba indicada, se le notifica que esta prohibida la difusion de este mensaje. Si ha recibido este mensaje por error, o si hay problemas en la transmision, favor de comunicarse con el remitente. Gracias. From tebeka at cs.bgu.ac.il Tue Aug 12 01:20:37 2003 From: tebeka at cs.bgu.ac.il (Miki Tebeka) Date: 11 Aug 2003 22:20:37 -0700 Subject: CLI+GUI References: <2259b0e2.0308080948.5a95e383@posting.google.com> Message-ID: <33803989.0308112120.504e3c65@posting.google.com> Hello Michele, > I wonder what is the recommended way of using Tkinter > together with a command line oriented application. I know it's not Tkinter but what about wxPython with wxCrust? HTH. Miki From vanevery at 3DProgrammer.com Mon Aug 11 01:24:39 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Sun, 10 Aug 2003 22:24:39 -0700 Subject: Python vs. C# References: <3f357a9b@shknews01> <37991aef.0308101223.57beb3c8@posting.google.com> Message-ID: <3f37267f@shknews01> Samuel Barber wrote: > "Brandon J. Van Every" wrote in message > >> Also C#, like Python, has higher level data types built right in. > > It does not. Hash tables, expandable arrays, etc. are provided by the > standard library. Ok... does this make a big difference, or any difference, in practice? Is there something ugly or bad about the C# standard library? I've avoided C++ STL for years.... -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From mpeuser at web.de Mon Aug 18 03:05:41 2003 From: mpeuser at web.de (Michael Peuser) Date: Mon, 18 Aug 2003 09:05:41 +0200 Subject: Python form oriented library References: Message-ID: Hallo Celeb, Tkinter looks easy at the first glance, it becomes confusing when you use more advanced features, and it becomes very easy again when you mastered it and can use Pmw, Tix and maybe even Fredrik Lundh's WCK in addition to it. The disadvantages are: - no convincing GUI-Builder running under Windows (PAGE or Spectix); ActiveState's KOMODO might be an alternative, but you need the 300 $ commercial version. It is surely not worth that much money. - output to a printer is virtually impossible (yes I know there something called PostScript) - no multi column lists or grid-like widgets. Don't understand this wrong. You can do *anything* with Tkinter, but it needs a lot of experience. Two years ago I started with generating a 10x10 array made of Labels and updated them. It was not fast. Then I changed it to 20x20...... You shall not do it this way. On the other hand there are real work horses which make life easy: Text, Canvas, and most of all the TIX HList. Especially HList ist something you can do a lot of things with! But - like nearly all of Tkinter/TIX widgets - they become slow when containing more than some thousend items (depending of your CPU and RAM or course) .... But even HList does not let you easyly click to the header for sorting actions or whatever... In this thread Pedro mentioned Kiwi, which was new to me, although I think I have a quite good overview over the scene. This might be interesting but I encountered a lot of Problems with GTK on Windows. It runs fine on Linux machines but I never got Glade running on Windows e.g. I rate Qt very high, though I have limited experience. It is well documented and there are tutorials. This is because it is the only commercial product since PythonWorks is no longer available. (Which is a pity BTW). It will do everything you want! But read the license! vwWindows (=wxPython) is nearly as good. It is free and a lot of people working with it. There is newsgroup know-how. Both Qt and vw can print , have some drag-n-drop and a lot of useful widgets, especially a HTML-renderer. Someone mentioned PyCard which is a good product, but there is only a limited number of widgets available. You should give it a try because it supports (no, that is wrong: it can live with) a lot of basis GUIs.; Generate a 6 column list, fill it with 1000 entries, sort it, and then try to print some of it. BTW printing: There is a phantastic product called ReportLab! Sorry I answered by mistake to the private address yesterday. Kindly Michael P "Caleb Land" schrieb im Newsbeitrag news:pan.2003.08.17.20.21.45.109000 at rochester.rr.com... > Hello, > I'm writing a small business accounting type program where the interface > is a bunch of forms that represent tables in a database. The interface is > usually used completely with the keyboard, but the mouse may also be used. > > The software does POS, inventory, accounting, etc. > > The widgets are mostly text entries. > > Are there any Python libraries that are targetted to this style of > interface? > > If not, does anybody have references to libraries/resources in other > languages that might be helpful in designing my own (APIs, design > documents, etc)? > > I've tried googling, but I don't know exactly how to word my request. > > Sincerely, > Caleb Land > (bokonon at rochester.rr.com) From wojciech at n0spam-kocjan.org Sun Aug 3 08:10:23 2003 From: wojciech at n0spam-kocjan.org (Wojciech Kocjan) Date: Sun, 03 Aug 2003 14:10:23 +0200 Subject: Potentially important real-time on-line discussion In-Reply-To: References: Message-ID: Kyler Laird wrote: > People pay (what I consider to be) lots of money for me to write software > for them. I insist that it be open source (which makes for interesting > contract negotiations sometimes). I would be *thrilled* if someone took > my code and used it. My value is in providing solutions - not shielding > intellectual property from use. While I do agree with you, another problem is that you spent your time and your customer paid you to do the software. Would it be fair if at this time, some other programmer took your code, added (not replaced) him to the copyright notice, changed about 5 things and charged the same for that? I do not know the "right" answer to that. My previous software is closed-source, mainly because it is too tightly bound. That is why I try to split my new programs into reusable components and components related with the customer or with a specific problem. Then I can release the reusable parts (for example a lot of code to handle DB, DB gui, richtext editing :-). The benefit is that if someone else will use the code, he/she will probably find some errors that I and my customers haven't found yet, and probably correct them and send me back a patch - then my development time on the code will get a bit shorter, and I'll use that to solve another customer's problems. However, this is just theory for now, mostly based on experience with other opensource code I used. Note that I do not plan to release customer's application as opensource, only parts of it. I think this is a bit better than releasing all of it, since my company and my customer spent a lot of time on developing and facing problems. If some other company wants to solve similar problems, they can always come to me either writing the software, or consulting them. -- WK From jzgoda at gazeta.usun.pl Fri Aug 1 15:11:01 2003 From: jzgoda at gazeta.usun.pl (Jarek Zgoda) Date: Fri, 1 Aug 2003 19:11:01 +0000 (UTC) Subject: 2.3 win installer References: Message-ID: Timothy Martens pisze: > Anyone having problems with the 2.3 win installer? I'm running win2k pro > (sp4) and the installer is freezing after the initial dialogues, just as > teh install starts. Nothing of such weird behavior. -- Jarek Zgoda Registered Linux User #-1 http://www.zgoda.biz/ JID:zgoda at chrome.pl http://zgoda.jogger.pl/ From dmbkiwi at yahoo.com Tue Aug 26 03:51:31 2003 From: dmbkiwi at yahoo.com (dmbkiwi) Date: Tue, 26 Aug 2003 19:51:31 +1200 Subject: Help with regular expressions Message-ID: I have a problem. I have written a python based theme for a linux app called superkaramba, which is effectively an engine for desktop applets that utilises python as its theming language. The script basically parses weather websites, and displays the info in a visually appealing way. A couple of other people have contributed code to this project, particularly relating to the parsing of the websites. Unfortunately, it is not parsing one particular part of the website properly. This is because it is expecting the data to be in a certain form, and occasionally it is in a different form. Unfortunately this causes the entire script to fail to run. Unfortunately, I know very little about regular expressions and can't get hold of the person who wrote this part of the script. The other issue I am struggling with is that there are no error messages as to what's going wrong, which makes it more difficult to code round the issue. The issue comes down to a couple of lines in the html for the web page. The following lines parse correctly: Wind: From the Northeast at 6 mph these don't: Wind: calm  the relevant portion of the python script is as follows: print '===================================================' p_current = r'''(?isx) # Ignore case, Dot matches all, Verbose wxicons/52/(?P\d*?)\.gif # Icon .*?obsTempTextA>(?P\d*?)° # Temp .*?obsTextA>(?P.*?) # Sky .*?Feels\sLike
(?P.*?)° # Heat .*?UV\sIndex:.*?Info2>(?P.*?)  .*?Dew\sPoint:.*?Info2>(?P.*?)° .*?Humidity:.*?Info2>(?P\d+) .*?Visibility:.+?Info2>(?P.*?) .*?Pressure:.+?Info2>(?P.*?)\sinches\sand\s(?P.*?) .*?Wind:.+?Info2>(?P.*?)\sat\s(?P\d*?)  ''' match = re.search(p_current, data1) if match: now.icon(match.group('icon')) now.temperature(match.group('temp'), 'F') now.relative_heat(match.group('heat'), 'F') now.sky(match.group('sky')) now.uv(match.group('uv')) now.dewpoint(match.group('dew'), 'F') now.humidity(match.group('dew')) now.visibility(match.group('vis')) now.pressure(match.group('baro'), 'inHg') now.pressure_change(match.group('change')) mywind = match.group('wind') now.wind(mywind.replace('From the ', '')) now.wind_speed(match.group('speed'), 'mph') Obviously the issue is that the regular expression expects "at", and in the second line of the html that doesn't parse, there is no at. The question I have, is how do I go about fixing this. What I want is to test to see if the line does or doesn't contain an "at", and if not, change it to contain an "at". I'm just not sure how to code the RE in python to do this. Any help would be appreciated. Matt From gherron at islandtraining.com Fri Aug 22 16:06:46 2003 From: gherron at islandtraining.com (Gary Herron) Date: Fri, 22 Aug 2003 13:06:46 -0700 Subject: visual indentation In-Reply-To: <3F4660CB.FF72D945@easystreet.com> References: <3F4660CB.FF72D945@easystreet.com> Message-ID: <200308221306.46685.gherron@islandtraining.com> On Friday 22 August 2003 11:28 am, achrist at easystreet.com wrote: > Hilbert wrote: > > Hello, > > > > I'm using python to output RIB streams for Renderman. > > The RIB stream is a bunch of statements which describes > > a 3d image. The Rib standard allows for blocks which we > > usually indent for better visualization for example: > > > > WorldBegin > > Color [1 1 1] > > Surface "constant" > > Sphere(1.0, -1.0, 1.0, 360) > > WorldEnd > > > > I'm using CGKit in python which has a Renderman binding, > > so to output the same RIB I'd write: > > > > RiWorldBegin() > > RiColor(1.0,1.0,1.0) > > RiSurface('constant') > > RiSphere(1.0,-1.0,1.0,360) > > RiWorldEnd() > > > > But I get an error, because python interprets my indentation > > as a block in the python code. So the only way to write this > > is without the indentation: > > > > RiWorldBegin() > > RiColor(1.0,1.0,1.0) > > RiSurface('constant') > > RiSphere(1.0,-1.0,1.0,360) > > RiWorldEnd() > > > > But this is a lot harder to read. > > > > Is there any way to use such "visual" indentation in python? > > If the code is purely sequential, how about something like this: > > import string > def RunTheseStatements(s): > stmts = map(string.strip, s.split("\n")) > for stmt in stmts: > eval(stmt) > > RunTheseStatements(""" > > > RiWorldBegin() > RiColor(1.0,1.0,1.0) > RiSurface('constant') > RiSphere(1.0,-1.0,1.0,360) > RiWorldEnd() > > > """) Here's another way -- inside a [..] or (...) construct [ RiWorldBegin(), RiColor(1.0,1.0,1.0), RiSurface('constant'), RiSphere(1.0,-1.0,1.0,360), RiWorldEnd(), ] Or try this (this might be too ugly) RiWorldBegin() if 1: RiColor(1.0,1.0,1.0) RiSurface('constant') RiSphere(1.0,-1.0,1.0,360) RiWorldEnd() or make these all member functions of a class and try c. RiWorldBegin(), c. RiColor(1.0,1.0,1.0), c. RiSurface('constant'), c. RiSphere(1.0,-1.0,1.0,360), c. RiWorldEnd(), or Hmmmm -- I'll bet there's more possibilities. Gary Herron From shalehperry at comcast.net Sun Aug 3 02:40:15 2003 From: shalehperry at comcast.net (Sean 'Shaleh' Perry) Date: Sat, 2 Aug 2003 23:40:15 -0700 Subject: Determining if a filename is greater than X characters In-Reply-To: <93f5c5e9.0308021815.44c57a2d@posting.google.com> References: <93f5c5e9.0308021815.44c57a2d@posting.google.com> Message-ID: <200308022340.15500.shalehperry@comcast.net> On Saturday 02 August 2003 19:15, hokiegal99 wrote: > How would I determine if a filename is greater than a certain number > of characters and then truncate it to that number? For example a file > named XXXXXXXXX.txt would become XXXXXX > > fname = files > if fname[0] > 6 > print fname[0] > > Thanks!!! look at the os.path module and also the len() builtin. The two of those should give you everything you need. From rdickins at usaor.net Fri Aug 29 14:46:28 2003 From: rdickins at usaor.net (Robert Dickinson) Date: Fri, 29 Aug 2003 14:46:28 -0400 Subject: imports after function definitions? References: Message-ID: The only restriction is that if you want to reference some imported thing at the module level, then the import has to precede the use: import x class cls(x.cls1): pass Other than that I don't know of any reasons (other than readability, which can be interpreted to advantage either way). -- Rob -- "Hallvard B Furuseth" wrote in message news:HBF.20030828usgy at bombur.uio.no... > Is there any reason not to structure my program like this? > > def ... > def ... > var = ... > var = ... > import ... > import ... > main_function() > > E.g. does it compile to slower code, or does it confuse PyChecker or > something, if I put the imports after the functions that use them? > > -- > Hallvard From BrenBarn at aol.com Fri Aug 1 13:39:30 2003 From: BrenBarn at aol.com (OKB (not okblacke)) Date: 1 Aug 2003 17:39:30 GMT Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> <3F2A35A1.2040403@klix.ch> Message-ID: Gerald Klix wrote: > What Python realy needs here is some means to make an expression > from a list of statements (called suite in the syntax defintion). I believe this is called a "function". -- --OKB (not okblacke) "Do not follow where the path may lead. Go, instead, where there is no path, and leave a trail." --author unknown From jjl at pobox.com Mon Aug 11 20:30:26 2003 From: jjl at pobox.com (John J. Lee) Date: 12 Aug 2003 01:30:26 +0100 Subject: Multi-Line Comment References: <4qofjvg3bh9smlnb1do4f0lhjga7bacnu3@4ax.com> Message-ID: <87y8xzvhst.fsf@pobox.com> Doug Tolton writes: [...] > How do you comment the block of text with Emacs? That is what I'm > using for my code editor. C-c # I use C-x r k to uncomment (kill-rectangle), but I'm sure there must be an uncomment-region in there somewhere... > I was wondering if a triple-quoted string not assigned would work, but > I hadn't got arround to trying it yet. The only trouble with TCSs is that emacs gets confused more easily than with '## ' multiline-comments. And recent CVS python-modes have had broken docstring fill (still broken, actually, whitespace gets collapsed sometimes... must file a bug). John From scottholmes at sbcglobal.net Wed Aug 6 18:09:29 2003 From: scottholmes at sbcglobal.net (Scott Holmes) Date: Wed, 06 Aug 2003 15:09:29 -0700 Subject: Calendar date and Time of Day pick lists or screens Message-ID: <3F317C99.40900@sbcglobal.net> I'm at a point in developing a user interface where I need to provide functionality for picking a date and for picking start and stop times for events. I've only done a brief google and found nothing in particular, so I thought I'd ask the community. Are there any calendar pick lists or screens available? I would like the user to be able to click a button that opens a display of a range of dates. The user would then select one which would then close the pick screen and provide the picked value for entry in a field. I need the same sort of thing for times of day. -- --------------------------------------------------------------------- Scott Holmes http://sholmes.ws http://pages.sbcglobal.net/scottholmes scottholmes at sbcglobal.net Independent Programmer/Analyst Passport 4GL PHP HTML Composer PostgreSQL Informix 4GL, SQL --------------------------------------------------------------------- There are more things in heaven and earth, Horatio, than are dreamt of in your philosophy --------------------------------------------------------------------- From dmbkiwi at yahoo.com Tue Aug 26 05:00:48 2003 From: dmbkiwi at yahoo.com (dmbkiwi) Date: Tue, 26 Aug 2003 21:00:48 +1200 Subject: Help with regular expressions References: Message-ID: On Tue, 26 Aug 2003 08:47:33 +0000, Sybren Stuvel wrote: > dmbkiwi enlightened us with: >> A couple of other people have contributed code to this project, >> particularly relating to the parsing of the websites. >> Unfortunately, it is not parsing one particular part of the website >> properly. This is because it is expecting the data to be in a >> certain form, and occasionally it is in a different form. >> Unfortunately this causes the entire script to fail to run. > > You seem to expect old HTML. Why not use XHTML only ('tidy' can > convert between them) and use a regular XML parser? Much, much, much > easier! And you won't have to be afraid of messing up your regular > expressions ;-) > > Sybren XML would be nice, but unfortunately I have no choice as to the markup language used by the site. It's a website on the world wide web, not a site overwhich I have any control. My regular expressions are at the mercy of the developers of that site. Any other suggestions? Matt From faizan at jaredweb.com Tue Aug 5 01:07:25 2003 From: faizan at jaredweb.com (Fazer) Date: 4 Aug 2003 22:07:25 -0700 Subject: Python and cron jobs. References: <7b454334.0308041023.6e688b4d@posting.google.com> Message-ID: <7b454334.0308042107.2548af6d@posting.google.com> Lee Harr wrote in message news:... > In article <7b454334.0308041023.6e688b4d at posting.google.com>, Fazer wrote: > > Hello, > > > > I am wondering that if it is possible to add cron jobs via a web or > > shell interface? I can make Python act as a shell script and be > > called by a PHP script. But my main goal here is to be able to manage > > cronjobs. Add or remove certain crjob jobs etc... > > > > Can any kind soul shed some light on how I would accomplish this? > > > > > I think adding them from the shell is probably the "normal" way. > For adding cron jobs from the web, you might look at webmin. > > Basically, the crontab is just a file, so if you can edit the file > from your program and then force cron to reload the crontab you > are all set. Hmm...nevermind. I just found out that it is a file. How would I reload the crontab? From bitbucket at safe-mail.net Thu Aug 28 05:32:38 2003 From: bitbucket at safe-mail.net (poiboy) Date: 28 Aug 2003 02:32:38 -0700 Subject: Way to distinguish between POST and GET data in Python CGIs? References: Message-ID: Hi Simon, Regarding mod_python: * Check req.method in ('GET', 'POST'). * GET variable strings are accessible via req.args, req.parsed_uri[apache.URI_QUERY], or req.subprocess_env['QUERY_STRING'] after calling req.add_common_vars(). * POST variable strings are in the client's request body, accessible via req.read() * The variable list strings can be parsed using functions in the cgi and urllib modules. Viewing mod_python as an Apache interface which accomodates web-scripting instead of (just) a web-scripting tool helps considerably. Think "light on the context, heavy on the construct." Example: 4.5.3: "The request object is a Python mapping to the Apache request_rec structure. When a handler is invoked, it is always passed a single argument - the request object." See http://httpd.apache.org/dev/apidoc/apidoc_request_rec.html for the structure's nitty grit. Wearing my Clueless CGI Apologist cap, I believe that it is the server's duty to set environment variables (like REQUEST_METHOD) and call an appropriate script with a query string (close enough). In other words, the script's only *required input* is the query string itself. Since environment (or "meta") variable accessibility is "system defined," a frugal cgi module was a safe bet. Just guessing. Aloha, the poiboy From ptmcg at austin.rr.com Tue Aug 19 08:08:29 2003 From: ptmcg at austin.rr.com (Paul McGuire) Date: Tue, 19 Aug 2003 12:08:29 GMT Subject: recursive traversal of file References: Message-ID: <1ro0b.200417$xg5.74450@twister.austin.rr.com> To prevent a recursive infinite loop, keep a list of the current chain of filenames being imported. Before importing filename_from_pattern, make sure it is not in the list (else you will eventually loop through the same files until your stack blows up or similar dire consequence). If the file is in the list, you can skip it, or raise an exception. -- Paul McGuire Austin, TX > > This *should* work, although I didn't test it. Also, it assumes that recursive > function calls share the same list ('data'). It would be cleaner to have > import_file create, fill and return its own list. In pseudocode: > > def import_file(filename): > data = [] > ... > for line in lines: > if (pattern matches): > z = import_file(filename_from_pattern) > data.extend(z) > ... > > return data > > From simonb at webone.com.au Mon Aug 4 20:18:32 2003 From: simonb at webone.com.au (Simon Burton) Date: Tue, 05 Aug 2003 10:18:32 +1000 Subject: SCALAPACK and PBLAS in Python References: Message-ID: On Mon, 04 Aug 2003 12:23:13 +0200, Vicente Galiano wrote: > > Hi everybody, > > > I'm searching differents tools for Python programming using parallelism > tools...., I've seen PyPar, PyMPI an d Scientific Python, but I'm > lookingo for implementations in python of SCALAPACK, on the other > hand,.... How can I implement PBLAS and SCALAPACK callings in python?? Have a look at SWIG. It's not too hard to use, unless the library calls use function pointers; then it can get tricky. Simon Burton. From george.trojan at noaa.gov Tue Aug 5 15:50:05 2003 From: george.trojan at noaa.gov (George Trojan) Date: Tue, 05 Aug 2003 19:50:05 +0000 Subject: xrange() question In-Reply-To: References: Message-ID: Bob Gailer wrote: > At 02:27 PM 8/5/2003 +0000, George Trojan wrote: > >> Why do I get an overflow error here: >> >> > /usr/bin/python >> Python 2.2.2 (#1, Feb 24 2003, 19:13:11) >> [GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-4)] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >> >>> import sys >> >>> for n, x in zip(range(4), xrange(0, sys.maxint, 2)): >> ... print n, x >> ... >> Traceback (most recent call last): >> File "", line 1, in ? >> OverflowError: integer addition >> >> but not here: >> >> >>> for n, x in zip(range(8), xrange(0, sys.maxint)): >> ... print n, x > > [snip] > Consider: > > >>> for x in xrange(sys.maxint-2,sys.maxint,2):x > ... > 2147483645 > > for x in xrange(sys.maxint-1,sys.maxint,2):x > ... > Traceback (most recent call last): > File "", line 1, in ? > OverflowError: integer addition > > Does this give you any clues? > > Bob Gailer > bgailer at alum.rpi.edu > 303 442 2625 > >------------------------------------------------------------------------ > > >--- >Outgoing mail is certified Virus Free. >Checked by AVG anti-virus system (http://www.grisoft.com). >Version: 6.0.506 / Virus Database: 303 - Release Date: 8/1/2003 > > It does. The reason I asked the question is that in the original example zip() needs only 4 elements from xrange(), so I was puzzled why the overflow was reached. But the following: >>> xrange(0, 3, 2) xrange(0, 4, 2) explains it (I think). Thanks to all for the answers. George From chrismoll at chrismoll.homelinux.org Fri Aug 15 21:17:02 2003 From: chrismoll at chrismoll.homelinux.org (Christian Kaenzig) Date: Sat, 16 Aug 2003 03:17:02 +0200 Subject: Test web server In-Reply-To: References: Message-ID: <200308160317.02212.chrismoll@chrismoll.homelinux.org> On Friday 15 August 2003 17:33, Axel Grune wrote: > Hi, I'm writing a test script which should act like a simple webserver > but it does'nt work. IE works but Mozilla say the document contains no > data. Does any one no what the problem is? > > TIA, > Axel What seems strange here is that you send data right after accepting the connection. On a normal http transfer, the client first sends this request and the awaits an answer from the server. Maybe is this confusing your Mozilla ? I don't have much experience with this kind of stuff so I may as well be completely wrong. > /snip/ Chris From cjh_nospam at managesoft.com Sun Aug 31 23:21:32 2003 From: cjh_nospam at managesoft.com (Clifford Heath) Date: Mon, 01 Sep 2003 13:21:32 +1000 Subject: Aspect oriented Everything? In-Reply-To: <32cc321c.0308221316.2f5793ac@posting.google.com> References: <32cc321c.0308221316.2f5793ac@posting.google.com> Message-ID: <3F52BB3C.70406@managesoft.com> New_aspect wrote: > What I want to know is,if anybody on a > commercial scale is using AOSD to develop commercial products? I have been using aspect oriented design techniques since 1992, when I invented a name "contextual extension" for a feature that occurred naturally in a data definition language I had designed in 1983. Needless to say, the term "aspect oriented" wasn't then current :-). I introduced hierarchical aspect-oriented design to ManageSoft last year, and we are finding my hierarchical approach (which extends and generalises most of the current AOSD state-of-the-art) helps considerably in the design and requirements phases - because it gives a better framework for SOC. So yes, it's fair to say that AO design *is* being used in a >1MLOC commercial product, which spans C++, Java, C# and Perl as well as a number of proprietry domain-specific languages (for errors, tracing, configuration variables, etc). I should say that our aspect orientation goes far beyond its traditional application to "infrastructure" aspects like logging etc (though we have identified and use over 80 different infrastructure aspects). For example, the ManageSoft product distributes software packages down a distribution hierarchy. Each distribution server has a basic object type which is extended with several facets. The Packages facet details which packages are or should be on each server. The Hierarchy facet details where this server lives in the hierarchy, and the Configuration facet details the configuration state of each server. These facets are *independent* of each other, yet belong to the same object - each reflects where the object cuts across a particular aspect. It's a kind of polymorphism, so not really that new. I think that the use of Aspect Oriented techniques beyond the infrastructure layers is the main area for adding value. As has been noted, infrastructure requirements should be built into the basic language, or added through low-impact libraries - Ruby allows (though by manual construction) the best of both worlds in this regard. We are using Ruby for a multiple tier generator based on an XML database schema language. This generator makes use of Ruby's mixins and the "extend" method to implement "facet realisation" - dynamic extension of base classes to allow them to serve in a particular context. This is primitive aspect oriented programming, and works well. The generator produces data tiers in C# and C++, web services definitions and implementations, web-service client proxy stubs that implement location- and version-transparency, as well as high-quality printed documentation, SQL DDL and stored procedures, and will be extended to cover test cases, schema migration and perhaps user interfaces (in C#). Despite our database only containing 58 tables, the 3KLOC generator reads a 1.2KLOC schema file and generates over 50KL of high-quality, formatted, readable, commented code. If I was a contractor it would be a license to print money. Of all langages I've learnt or created, implementing this generator in Ruby using aspect-oriented techniques is the only way to have kept it down to its current 3KLOC - and most of that code is templates! > Is it the fact that AOP is new and, for most, confusing Maybe. Although it is somewhat difficult to grapple with, the intrinsic concepts are much simpler than current implementations indicate. AspectJ had to integrate with Java, so had to multiply the basic concepts, and had to live within the traditional source-file idiom. AOD tools *must* support dynamic view synthesis, allowing visualisation of the system in both composed and partly-composed form. I'm not aware of a tool that does that. Aspect oriented design requires a visual language for presenting designs. Some work has been done on adding AOD features to UML, but basically it's difficult because AOD is used to implement multi-dimensional designs - which can't easily be flattened to any 2-D language. I think that the only hope there is for a 1-D (traditional text-based) language which is supported by powerful graphical tools which allow filtering the aspects exposed in dynamic views. A true AOD language (as opposed to a hack preprocessor added to an existing language) would also support dynamic extension (which I term facet realisation). We do that in Ruby with mixins and extend(), but it's a bit too "manual". > Is an Open Source development ever going to gain the trust of industry? What on earth has that got to do with AOP? > What are the main features that may lead to AOSD adoption? Proper filtering aspect browsers in an IDE for a naturally aspect-oriented language. None of which currently exist, as far as I'm aware. > Is AOP the next step on from OOP? Perhaps, if the tool support is provided. > Is it another chance for some of the lesser > utilised languages to step up to Java and C++? No. I don't believe that AOD can be adequately justified when implemented as an extension to either C++ or Java. AFAIK, there is no viable candidate for the title of the first viable aspect-oriented language. I meant to publish a bunch of writings and tools at my nascent domain www.aspectdesign.org, but my employer is not forthcoming with an IP disclaimer to publish tools so the domain lies dormant and the tools unwritten. Sigh. I honestly believe these tools must be open source. I've previously tried to found a business based on simple, general powerful software tools and languages, and have become convinced that commercial survival is only possible with limited-purpose tools. Proprietry standards for basic technologies are doomed. Clifford Heath, cjh at spam-me-rotten.managesoft.com - you work it out. From John.Marshall at ec.gc.ca Wed Aug 6 12:27:58 2003 From: John.Marshall at ec.gc.ca (John Marshall) Date: 06 Aug 2003 16:27:58 +0000 Subject: PyXML and 4Suite Message-ID: <1060187279.15899.8.camel@mango.cmc.ec.gc.ca> Hi, Some questions about PyXML and 4Suite I hope someone can answer: 1) What is the relationship between PyXML and what 4Suite is offering (Ft.* modules)? 2) Which package is recommended? It seems that the 4Suite package has stuff that is much more performant vis-a-vis PyXML. 3) Is 4Suite better performing only if the light-weight DOM is used? 4) Are there many differences between the two besides a few import statements and document creation calls (e.g., setup for using specific readers)? I am currently using PyXML, but am looking for more performance. The document load/DOM-build is quite slow under PyXML (though I certainly appreciate the work that has gone into it). Thanks, John From mcfletch at rogers.com Mon Aug 18 21:16:02 2003 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Mon, 18 Aug 2003 21:16:02 -0400 Subject: Writing bitfields with varying field lengths In-Reply-To: References: Message-ID: <3F417A52.4030003@rogers.com> Grumfish wrote: > In order to familiarize my self with Flash files and their bytecode > I've started to make an assembler. My first problem is writing the > bitfields the format uses often. It is a series of fields, each can be > a different number of bits, combined into the least amount of bytes > possible. Extra bits in the last byte are padded with zeros. I would > like to make a function that takes a size and value for each field > needed, calculate the amount of needed bytes, place the values, and > the nretun a binary string of the resulting bitfield. I am at a > complete loss on how to place the values into the field. I've Googled > but have found nothing helpful. Can anybody help? This should help you get started. There are more efficient ways to do the work, but this is easily followed (hopefully): def packBitField( * items ): """Pack any size set of boolean values into binary string""" result = [] items = list(items) while len(items)>=8: result.append( pack8( items[:8] ) ) del items[:8] if items: result.append( pack8( items+([0]*(8-len(items)) ) )) return "".join( result ) def pack8( items ): """Pack 8 booleans into a byte""" value = 0 for x in range(len(items)): value += (not not items[x])< Message-ID: > >>> macExpression = r"[0-9A-F]{1,2}(\:|\.|\-)([0-9A-F]{1,2}\1){4,4}[0-9A-F]{1,2}$" Thanks very much that will work a lot better. I am going to save the other code you (and the others) offered for later. It may be useful later on in the program. Thanks -matthew From p-abel at t-online.de Wed Aug 6 09:01:02 2003 From: p-abel at t-online.de (Peter Abel) Date: 6 Aug 2003 06:01:02 -0700 Subject: xrange() question References: Message-ID: <13a533e8.0308060501.31d0bac0@posting.google.com> Bob Gailer wrote in message news:... > At 02:27 PM 8/5/2003 +0000, George Trojan wrote: > > >Why do I get an overflow error here: > > > > > /usr/bin/python > >Python 2.2.2 (#1, Feb 24 2003, 19:13:11) > >[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-4)] on linux2 > >Type "help", "copyright", "credits" or "license" for more information. > > >>> import sys > > >>> for n, x in zip(range(4), xrange(0, sys.maxint, 2)): > >... print n, x > >... > >Traceback (most recent call last): > > File "", line 1, in ? > >OverflowError: integer addition > > > >but not here: > > > > >>> for n, x in zip(range(8), xrange(0, sys.maxint)): > >... print n, x > [snip] > Consider: > > >>> for x in xrange(sys.maxint-2,sys.maxint,2):x > ... > 2147483645 > > for x in xrange(sys.maxint-1,sys.maxint,2):x > ... > Traceback (most recent call last): > File "", line 1, in ? > OverflowError: integer addition > > Does this give you any clues? > YES, it does. At my opinion it's completely in accordance with my above said. You start with sys.maxint - 1 = 2147483646 and then get this as first element. Next - I guess - Python will check if 2147483646 + 2 is bigger or equal than the ending criteria, what is sys.maxint. But this check will fail because 2147483646 + 2 causes an overflow. So for me the global rule is: If you have a therm like **range(start,end,step)**, it is higly recommmended, that "start" + "N" * "step" is equal to "end" for a certain "N", where "N" is an integer. This is necessary when "end" is sys.maxint. Regards Peter > Bob Gailer > bgailer at alum.rpi.edu > 303 442 2625 > > -- From google at hanger.snowbird.net Sat Aug 23 04:31:46 2003 From: google at hanger.snowbird.net (Kris Caselden) Date: 23 Aug 2003 01:31:46 -0700 Subject: Scope of InteractiveInterpreter? References: <7h3vfsr2oj4.fsf@pc150.maths.bris.ac.uk> Message-ID: What I'm trying to do is dynamically add code to a running program. Essentially, file1.py could execute file2.py, then the code in both files could execute and read each others data both ways. It seems like execfile almost works, but the communication only happens one way, from file1 to file2. Is there any way to get around this? Michael Hudson wrote in message news:<7h3vfsr2oj4.fsf at pc150.maths.bris.ac.uk>... > google at hanger.snowbird.net (Kris Caselden) writes: > > > I'm using the InteractiveInterpreter to run some source, but the data > > generated doesn't seem to be available in the scope of the parent. > > > > For instance, I tried > > > > lines = infile.open('data.py','r').readlines() > > ii = InteractiveInterpreter({'__name__': '__main__', '__doc__': None}) > > for line in lines: > > ii.runsource(line) > > > > but the data objects in data.py don't seem to exist when I try and > > manipulate them later in the script. Is what I'm trying to do > > possible? Am I on the right track? > > I don't know what you're trying to acheive. It *sounds* like you're > hunting for a complicated version of execfile. > > Try this: > > d = {} > execfile('data.py', d, d) > > then the objects you're looking for are in the dictionary d. If you > really want a module you can then do > > data = new.module('data', d) > > or maybe just use the standard (but obscure) imp module to do it all > in one step. > > HTH, > mwh From max at alcyone.com Sat Aug 16 19:29:08 2003 From: max at alcyone.com (Erik Max Francis) Date: Sat, 16 Aug 2003 16:29:08 -0700 Subject: asynchat question References: <3f3ebaa8_2@news.vo.lu> Message-ID: <3F3EBE44.FA29DC66@alcyone.com> Patrick Useldinger wrote: > The client connects and send his question. The server answers, but the > client never receives an answer. On the server side, I receive the > following message: > > error: uncaptured python exception, closing channel > __main__.SecondaryServer connected 127.0.0.1:3432 at 0x7fc968> > (socket.error:(10053, 'Software caused connection abort') > C:\Python23\lib\asynchat.py|handle_read|88] [C:\Python23\lib\asyn > core.py|recv|353]) > > Can anyone explain why? There are several problems here. For starters, your server class isn't really a server, since it doesn't derive from asyncore.dispatcher, and doesn't bind to a port, so connections never come in. (And you wanted to override handle_accept, not handle_connect.) Try something like this for your server: class Server(asyncore.dispatcher): def __init__(self, port, isQuiet=False): asyncore.dispatcher.__init__(self) self.create_socket(socket.AF_INET, socket.SOCK_STREAM) self.set_reuse_addr() self.addr = '', port self.bind(self.addr) self.listen(5) def handle_accept(self): Connection(self, self.accept()) where Connection is a class that derives from asynchat.async_chat. I'm sure a dozen people will tell you to use Twisted, now. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ Who's not sat tense before his own heart's curtain? \__/ Rainer Maria Rilke From dtolton at yahoo.com Tue Aug 12 02:08:51 2003 From: dtolton at yahoo.com (Doug Tolton) Date: Tue, 12 Aug 2003 06:08:51 GMT Subject: Python vs. C# References: <2259b0e2.0308100616.55b651ca@posting.google.com> <3f36af20@shknews01> Message-ID: <0b0hjv4q40mdf3msnur9q4bcih3tqb8iq3@4ax.com> On Mon, 11 Aug 2003 14:57:55 -0700, "Brandon J. Van Every" wrote: >I am not convinced. As the books tell it, C# was created to take the best >features of Java and some other languages. And as a dyed in the wool C++ >programmer, most of what I've learned about C# so far certainly looks like >sanity. I am currently thinking of it as "C++ without the pain." It's amazing that you pass yourself off as an expert in C# when you are just reading the propaganda still. Come back and have this discussion when you have actual experience in C#. I've used C# full time for over two years. Finally I got disgusted with it and swtiched my entire company over to Python. >From my experience I have found the following: -C# is buggy and inconsistent. -C# debugger is a piece of crap, the immediate window is worthless -C# Garbage Collection algorithm is worthless, essentially it never collects until it's way to late. By that time you are screwed. -C# static typing is a major pain in the ass, it causes far more bugs and errors than having loose types like C ever did. -The .net widgets are slow and *really* buggy. Events get lost, they choke are large volumes of text, and the drawing.dll just pukes on load randomly. -The lack of a multi-line string drives me bananas. Try building up a big HTML form using a string builder sometime. (this is just the beginning of a long list) Python: -Internally consistent, cleanly designed, to the point of being beautiful -Dynamic typing is amazing -First class functions (try mimicking that in C# - ha) -Tuple unpacking is a god send -List types are the cats meow -Dictionaries are blazingly fast -using metaclasses and the magic methods gives you amazing power and flexibility (this is just the beginning of a long list) Overall Python is a language written by programmers for programmers. You can feel it when you use it. When you need a function, and you go looking for it, it's already been written and it works just like you'd think it would. It's blazingly fast, and is a joy to program in. Overal C# is a buggy, slow, half implementation of Java. It's written by committe for people dumber than themselves. If you need to perform some function that pushes the limits of the language, it will either choke, or throw an error saying it was explicitly disallowed. It's painful attempting to write real world apps in C#. When you can come back with some real world experience using some of these languages you are bashing then your opinion might mean something. Right now you are just spewing Microsoft hyperbole and propaganda. Doug Tolton From maxm at mxm.dk Tue Aug 12 04:32:46 2003 From: maxm at mxm.dk (Max M) Date: Tue, 12 Aug 2003 10:32:46 +0200 Subject: Is Python your only programming language? In-Reply-To: References: Message-ID: <3F38A62E.50207@mxm.dk> Joe Cheng wrote: > I want to ask you hard-core c.l.p Pythonistas: Do you use Python for > everything? (and I'm counting Python + C extensions as just Python) Or do > you keep another language equally close at hand, and if so, what is it? And > finally, do you foresee a day when Python can be, for all practical intents > and purposes, your only programming language? I used to learn a new language a year. But i'm afraid that python has made me lazy. It sort of killed the natural itch to learn new languages by removing the little anoyances I used to have when programming. So now I start up my editor in Python mode like a mindless zombie. It has even gotten to the point that I use it for calculations instead of a spreadsheet and pocket calculator. But to keep up to date language wise I will look into other languages again someday soon. I swear. hmm! regards Max M From robin at jessikat.fsnet.co.uk Fri Aug 29 11:47:11 2003 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Fri, 29 Aug 2003 16:47:11 +0100 Subject: how fast is Python? References: Message-ID: In article , Andrew MacIntyre writes >On Fri, 29 Aug 2003, Robin Becker wrote: > >> experience with ReportLab suggests jython can be fairly slow compared to >> CPython although it does have advantages. > >The advantages being? > >Regards, >Andrew. well I guess you can package it up into a single jar file and then ship it to those big blue iron jvm environments ie it's another market. -- Robin Becker From alan.gauld at btinternet.com Sun Aug 24 12:33:24 2003 From: alan.gauld at btinternet.com (Alan Gauld) Date: Sun, 24 Aug 2003 16:33:24 GMT Subject: Python is darn fast (was: How fast is Python) References: <2259b0e2.0308230737.8a9bc1c@posting.google.com> <2259b0e2.0308240638.38350cba@posting.google.com> Message-ID: <3f48e825.858271679@news.blueyonder.co.uk> On 24 Aug 2003 07:38:49 -0700, mis6 at pitt.edu (Michele Simionato) wrote: > I finally came to the conclusion that the exceeding good performance > of Psyco was due to the fact that the function was called a million > times with the *same* argument. Still an interesting thread. > Here is the situation for pure Python > user 0m27.162s > sys 0m0.023s > > and, just for fun, here is Jython performance: > user 0m42.602s > sys 0m0.389s Just as a matter of interest what happens if Jython code is compiled to Java and run under the JVM rather than the Jython interpreter? Does that increase or decrease the speed. I've been toying with the idea of moving to Jython but the speed hit is one factor (of several) that stops me. Alan G. Author of the Learn to Program website http://www.freenetpages.co.uk/hp/alan.gauld From llothar at web.de Tue Aug 19 16:20:12 2003 From: llothar at web.de (Lothar Scholz) Date: 19 Aug 2003 13:20:12 -0700 Subject: Python Debugger References: <6ee58e07.0308181134.383a69e7@posting.google.com> <3f412cf3.351547428@news.blueyonder.co.uk> Message-ID: <6ee58e07.0308191220.702baf00@posting.google.com> alan.gauld at btinternet.com (Alan Gauld) wrote in message news:<3f412cf3.351547428 at news.blueyonder.co.uk>... > On 18 Aug 2003 12:34:09 -0700, llothar at web.de (Lothar Scholz) > wrote: > > Is there any python debugger that can > > > > 1) be used remotely > > What do you mean by remotely? Debug a program running on a server > from a remote PC? Yes this is what i mean > > 2) can handle multiple threads > > Never tried that one, although pdb might work... No it does not. From someone at somewhere.com Tue Aug 19 19:07:22 2003 From: someone at somewhere.com (reh) Date: Tue, 19 Aug 2003 23:07:22 GMT Subject: advice choosing IDE References: <2lh711-1s2.ln1@stargate.solsys.priv> <6f2a11-633.ln1@stargate.solsys.priv> Message-ID: Detlev Offenbach wrote: > > You have to install some api files somewhere and configure their usage > using the Preferences Dialog. Calltips and Autocompletion both use the > API files. > > Detlev thanks... -- robert redhat 9.0 From zephyr01 at alltel.net Fri Aug 15 18:24:59 2003 From: zephyr01 at alltel.net (Hans Nowak) Date: Fri, 15 Aug 2003 18:24:59 -0400 Subject: Replace every n instances of a string In-Reply-To: <62de87da.0308151325.41ea4622@posting.google.com> References: <62de87da.0308151325.41ea4622@posting.google.com> Message-ID: <3F3D5DBB.30503@alltel.net> Tom Cross wrote: > Hello- > > I have a function that returns to me a text representation of Unicode > data, which looks like this: > > \u0013\u0021\u003c\u003f\u0044\u001f\u006a\u005a\u0050\u0015\u0018\u001d\u007e\u006b\u004e\u007d\u006a\u006e\u0068\u0042\u0026\u003c\u004f\u0059\u0056\u002b\u001a\u0077\u0065\u006a\u000a\u0021\u005f\u0025\u003f\u0025\u0024\u007e\u0020\u0011\u0060\u002c\u0037\u0067\u007a\u0074\u0074\u0003\u0003\u000f\u0039\u0018\u0059\u0038\u0029\u0001\u0073\u0034\u0009\u0069\u005e\u0003\u006e\u000d\u004c\u001d\u00 > f\u006e\u001b\u006e\u0063\u000b\u0014\u0071\u007c\u004e\u006a\u0011\u004a\u001f\u0063\u0016\u003d\u0020\u0065\u003e\u0043\u0012\u0047\u0026\u0062\u0004\u0025\u003b\u0005\u004c\u002e\u005a\u0070\u0048 > > I would like to add carriage returns to this for usability. But I > don't want to add a return after each "\u" I encounter in the text > (regexp comes to mind if I did). I want to add a return after each 12 > "\\u"s I encounter in the string. > > Any ideas? Do I not want to search for "\\u" but instead just insert > a \n after each 72 characters (equivalent to 12 \uXXXX codes)? Would > this provide better performance? If so, what would be the easiest way > to do that? Something like this: # let s be the long string with unicode representation z = [] while s: chunk, s = s[:72], s[72:] z.append(chunk) new_string = '\n'.join(z) HTH, From jonaomi at excite.com Sat Aug 9 19:19:27 2003 From: jonaomi at excite.com (Jonathan) Date: 9 Aug 2003 16:19:27 -0700 Subject: exec(), execfile() and local-variable binding? Message-ID: I'm puzzled by Python's behavior when binding local variables which are introduced within exec() or execfile() statements. First, consider this simple Python program: # main.py def f() : x = 1 print "x:", x f() This just prints "x: 1" when run. Now, what happens if we move the assignment into a separate file "assign.py", and attempt to read it in with execfile()? # assign.py x = 1 print "x in assign.py:", x # main_execfile.py def f () : execfile("assign.py") print "x in main_execfile.py:", x f() So, you might assume that if execfile() worked like a C-style #include, this would work fine. But it doesn't. Instead, when "main_execfile.py" is compiled, the "x = 1" assignment in "assign.py" is never seen, so the 'x' in the print statement is assumed to be a global variable. Then at run-time, we get an error about 'x' being an undefined global variable: x in assign.py: 1 x in main_execfile.py: Traceback (most recent call last): File "main_execfile.py", line 4, in ? f() File "main_execfile.py", line 3, in f print "x in main_execfile.py:", x NameError: global name 'x' is not defined Well, that's understandable. But what I find strange is that exec() *doesn't* work in this way. Consider this version: # main_exec.py def f() : exec("x = 1") print "x:", x f() I would have thought that, just like the execfile() version, the "x = 1" string would not be interpreted at parse-time, so that the 'x' in the "print" statement would again be taken to be a global variable. But no, this version runs fine, producing the output "x: 1". And this fancier version also runs: # main_exec2.py def f(v) : exec(v + " = 1") print "x:", x print "Type 'x':" f(input()) Here, if the user enters 'x', the assignment string "x = 1" is made up, and the program runs as before. So, why do these exec() versions work, when the execfile() one didn't? Specifically, why aren't the 'x' variables in the "print" statements taken as global variables? AFAIK, this should be a compile-time decision, but the "x = 1" assignment strings can't have been interpreted at that time. Thanks for any help, -- Jonathan From sismex01 at hebmex.com Thu Aug 14 13:19:52 2003 From: sismex01 at hebmex.com (sismex01 at hebmex.com) Date: Thu, 14 Aug 2003 12:19:52 -0500 Subject: py2exe service and tool-tray app combined? Message-ID: [Thomas Heller] > (description of *.bnd files clipped) > Now, isn't this '.bnd' file mechanism also a nice idea for py2exe? DEFINITELY! Please! :-) -gustavo Advertencia:La informacion contenida en este mensaje es confidencial y restringida, por lo tanto esta destinada unicamente para el uso de la persona arriba indicada, se le notifica que esta prohibida la difusion de este mensaje. Si ha recibido este mensaje por error, o si hay problemas en la transmision, favor de comunicarse con el remitente. Gracias. From heikowu at ceosg.de Wed Aug 27 05:18:02 2003 From: heikowu at ceosg.de (Heiko Wundram) Date: Wed, 27 Aug 2003 11:18:02 +0200 Subject: ezPyCrypto keys In-Reply-To: References: Message-ID: <1061975882.799.5.camel@d168.stw.stud.uni-saarland.de> On Wed, 2003-08-27 at 04:37, John Hunter wrote: > What's going on? Is it abnormal for so many of the characters in the > exported string to be the same? The machine I am running on is a > server that rarely has anyone logged in directly. Is this a problem > with not enough randomness in /dev/random? It's sure got nothing to do with too little randomness, I'd rather say this is just a serialization issue. The Ms and Ns are probably control characters in the underlying cPickle key output. I guess it'd be hard for the key output to be random, except when you compress it using zlib/bzip2 on output, this should randomize the data sufficiently. I haven't done any tries for this on my machine, so I might just as well be plain wrong, and you have too little randomness available. But, as PyCrypto uses /dev/random, this can't really be the case, as this would mean that your kernel is buggy, and I don't recall any problems with 2.4.9. If you want more control over the output format of keys, have a look at yawPyCrypto, "yet another wrapper for PyCrypto", which defines a much more flexible interface for wrapping stringified key data (and btw. is written and maintained by me ;)). You could easily write a plugin which zips all key output. HTH! Heiko. From ta-meyer at ihug.co.nz Tue Aug 26 05:17:56 2003 From: ta-meyer at ihug.co.nz (Tony Meyer) Date: Tue, 26 Aug 2003 21:17:56 +1200 Subject: Help with regular expressions In-Reply-To: <1ED4ECF91CDED24C8D012BCF2B034F1303063FBC@its-xchg4.massey.ac.nz> Message-ID: <1ED4ECF91CDED24C8D012BCF2B034F13026F28C3@its-xchg4.massey.ac.nz> > Any other suggestions? If you're going to be maintaining it (and if you can't find someone to fix it, I presume you are), then you might as well bite the bullet and learn the basics of regular expressions. I put this off for ages, but it didn't take all that long once I finally did, and I really regret that I didn't earlier. This page is great as a tutorial and reference: > The question I have, is how do I go about fixing this. What I want is to > test to see if the line does or doesn't contain an "at", and if not, > change it to contain an "at". I'm just not sure how to code the RE in > python to do this. For this particular case, you can just change the '\sat\s' (in the last line) to '(?:\sat\s)?'. This makes the at a group (the parentheses), which isn't captured (the ?:) and which is optional (the ? at the end) - the \s means that there is whitespace around the 'at'. There are no doubt other (probably better!) ways, but this should do what you ask. =Tony Meyer From roy at panix.com Sat Aug 16 20:22:09 2003 From: roy at panix.com (Roy Smith) Date: Sat, 16 Aug 2003 20:22:09 -0400 Subject: Python should try to displace Java References: Message-ID: "John Roth" wrote: > You missed Ruby and TCL. Granted, TCL is probably only being held up > by TK and Expect, though. Don't kid yourself. I work on a commercial application which includes almost 20,000 lines of TCL, and not a single line of it is Tk or Expect. As an embedded scripting language, it fills a very nice niche. This particular collection of TCL code is the 3rd generation of scripting code for this application. The first generation was a huge shell script, which was quickly outgrown. The second generation was a home-brew language which was a complete failure. The third generation was embedding TCL, which was a roaring success. I've been known to mutter "TCL is a stupid language" more than a few times (typically during code reviews), but it does have a few things going for it. It's dead simple to learn, reasonably powerful, and it's trivial to imbed (simplier than Python). Still, for all that, I suspect it's a bit of an evolutionary dead end. From tim.one at comcast.net Sun Aug 3 18:56:52 2003 From: tim.one at comcast.net (Tim Peters) Date: Sun, 3 Aug 2003 18:56:52 -0400 Subject: PyChecker work with Python 2.3? In-Reply-To: <3F2D762C.1B5A0143@easystreet.com> Message-ID: [achrist at easystreet.com] > ... > If I'm on a Windows system, and I am, I am very suspicious of any > claims that it is possible to install and uninstall anything easily > and come out exactly where I was before. If you feel that way often , search google for GoBack. That's a commercial product (i.e, you pay for it), which performs deep magic to track all changes to your hard drive, storing recovery information to a permanently reserved part of your hard drive. It doesn't care (or know) why anything on disk is changing, it simply captures *all* changes. It's very effective at restoring the disk to a previous state. For example, defragment your hard drive, and (provided you reserved enough disk space to store all the change info), it can restore your disk to its fragmented state again (! not useful, but an impressive demo; maybe more impressive is deleting your Windows system directory -- the box won't be able to boot then until you tell GoBack to revert the drive to a time before the deletion). > About a month ago I noticed that my jaz drive was working not too > well, so I upgraded Iomega's tools. That broke NT, it wouldn't > uninstall, and I spent 3.5 days trying to fix NT. With the tool above, you would simply tell it to restore your disk to its state at a time preceding your Iomega upgrade. End of problem! It doesn't matter whether an upgrade fiddled with the registry, replaced device drivers, deleted files completely, whatever -- in the end, they're all just bits on your hard drive, and your drive will get changed back to exactly what it was before you installed the upgrade (or before you even downloaded the updgrade installer, if you choose a restoration time before you did the download). > ... > If you work with Windows much, you learn the downside of promiscuous > installing. There's always a risk. Better to ask twice and install > once. Python installs are pretty benign, and on Windows 2.2.x and 2.3.y even name the base DLL differently (python22.dll vs python23.dll). For a minimally intrusive 2.3 test drive: + Install to the suggested \Python23 directory. It won't touch anything in your 2.2.x installation then. + Leave the "Yes, make backups" default selected. + In the "Select Components" dialog, click on "Advanced Options ...". In the "Advanced Options" dialog that pops up, - Select "Non-Admin install". Then all files (even the base Python DLL) will be unpacked under \Python23 (by default, we try to unpack the base DLL into a Windows system directory). - Uncheck "Register file extensions". Then .py (etc) files will continue to be associated with whatever Python you had before the 2.3 test drive. Because I build the PLabs Windows installer, I install broken pre-release Pythons all the time. The steps above are the ones I use then to ensure that they don't interfere with any of the released Pythons on my box. The Wise uninstaller does a thorough job of removing all traces of a Python installed in this way, and because we avoid changing file associations, can't be fooled by an unfortunate sequence of installs and uninstalls. From mpeuser at web.de Mon Aug 18 11:22:21 2003 From: mpeuser at web.de (Michael Peuser) Date: Mon, 18 Aug 2003 17:22:21 +0200 Subject: advice choosing IDE References: Message-ID: "Michael Peuser" schrieb im Newsbeitrag news:bhqo8a$ggs$06$1 at news.t-online.com... > My apologies! I was of course refering to the Trolltech QT Builder which is > a fine product but no integrated Python tool. I have heard of "eric" but > never used it.... I certainly will! Nevertheless it is no simple task to install it on a Windows machine: There seems to be just a source code version of QScintilla (what you need in addition to Qt and PyQt). This seems nothing for a newbie to start, looking for his first IDE...... Similar problems (on Windows) happen with GTK related products. This a total mess. We poor and simple minded WIndows usesr expect something working just out of the box ;-) Kindly Michael P From imbosol at aerojockey.com Thu Aug 7 18:07:07 2003 From: imbosol at aerojockey.com (Carl Banks) Date: Thu, 07 Aug 2003 22:07:07 GMT Subject: Gmpy References: <8578e2c1.0308070630.5fb70c22@posting.google.com> Message-ID: Jean-Pierre Andreaux wrote: > Gmpy module was a wrapper of the GNU MP library. It seems that no > evolution is done on this module since 2001. Indeed, Gmpy is not > supported in Python 2.2 nor 2.3. > > My question is the following: what is the better replacement solution > for manipulating long numbers. I want to do long numbers > exponentiations. Thanks in advance for your answers. An alternative is egenix mxNumber package, still in beta stage. http://www.egenix.com/files/python/mxNumber.html I couldn't use gmpy because I needed floating point, and mxNumber also wraps the floating point functionality. It seemed to work ok. -- CARL BANKS "You don't run Microsoft Windows. Microsoft Windows runs you." From alanmk at hotmail.com Fri Aug 22 06:29:55 2003 From: alanmk at hotmail.com (Alan Kennedy) Date: Fri, 22 Aug 2003 11:29:55 +0100 Subject: Design Patterns References: Message-ID: <3F45F0A3.E33DEC70@hotmail.com> Design Pattern Catalog wrote: [Text of standard email removed] Hmm, we seem to getting a lot of "welcome subscriber" type emails to the list at the moment, on top of all the "virus in your mail" reports :-( Am I the only one who gets the feeling that some mal-adjusted person is after going to a wide range of sites and subscribing the python list email address to a lot of different subscription services? -- alan kennedy ----------------------------------------------------- check http headers here: http://xhaus.com/headers email alan: http://xhaus.com/mailto/alan From halley at play-bow.org Wed Aug 6 15:08:34 2003 From: halley at play-bow.org (Bob Halley) Date: 06 Aug 2003 12:08:34 -0700 Subject: Copying objects style questions In-Reply-To: References: Message-ID: > To forestall further misunderstandings -- this would not work for > objects with __slots__ (no __dict__) or inheriting from classes with > __slots__ (wouldn't copy attributes not in __dict__) -- there is > always more work needed for such cases. But if one uses __slots__ > one *deserves* to have to work a bit harder as a result;-). I use new-style classes with __slots__ :), because it makes a really noticeable difference in memory usage if you use dnspython to work with a good-sized zone (i.e. one with tens of thousands of records). From p-abel at t-online.de Fri Aug 29 07:31:31 2003 From: p-abel at t-online.de (Peter Abel) Date: 29 Aug 2003 04:31:31 -0700 Subject: opposite of dict.items() References: <3f4e708c$0$64719@hades.is.co.za> Message-ID: <13a533e8.0308290331.68fb07bf@posting.google.com> "Raymond Hettinger" wrote in message news:... > [Tertius wrote] > > > Is there a method to create a dict from a list of keys and a list of > > > values ? > > [Peter Otten] > > >>> dict(zip(range(3), "abc")) > > {0: 'a', 1: 'b', 2: 'c'} > > > If you're using Py2.3, then the itertools way is a bit nicer: > > >>> dict(itertools.izip(range(3), "abc")) > {0: 'a', 1: 'b', 2: 'c'} > > > Raymond Hettinger I guess Py2.2 is nice too :-) >>> dict(zip(range(3), "abc")) {0: 'a', 1: 'b', 2: 'c'} Regards Peter From vanevery at 3DProgrammer.com Mon Aug 18 14:00:03 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Mon, 18 Aug 2003 11:00:03 -0700 Subject: What's better about Ruby than Python? References: Message-ID: Andrew Dalke wrote: > > How many Ruby programmers (per capita) do you know talking about > Python? Perhaps Python "has the potential to ...display Ruby" I don't know many. Anecdotally, though, it's clear that Ruby has mindshare. It's on the radar of everyone I've talked to who knows about Python. Thanks for the statistics. It didn't address the subject line, but it was interesting. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From adalke at mindspring.com Fri Aug 1 00:47:27 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Thu, 31 Jul 2003 22:47:27 -0600 Subject: time, calendar, datetime, etc References: <153fa67.0307300326.45a29380@posting.google.com> <1sScnW0Sv7DzrrSiRTvUpQ@speakeasy.net> Message-ID: John Roth: > I also wonder why anyone made the choice to set the year origin at > 1AD? That decision, by itself, makes it almost unusable for my hobby > (astrological software, which is basically astronomical software > with a different focus.) Astronomical dates are always measured > in days since 4700 and something BC. Well, if you're doing astronomical time, wouldn't you just add 4700 and something years and 12 hours (as I recall, astronomers have a 12 hours offset because they observe at night and don't want to have to change the date (or forget to change the date) part way though.) How is that unusable? Why would supporing you be reasonable to the other 99+% of the users who don't care about doing astronomical measurements, nor even about the "was there a year 0?" debate. And as for unusable, bah. The nuances of time are very sublte. Ivan Van Laningham at the Houston conference ('98, I think) gave a paper on using Python for the Mayan calendar. Even if Python were to use astronomical time as its basis, that code wouldn't handle his needs - eg, he wanted to know when the Mayan calendar repeats itself. Answer? Once every 2549465048574470321568539870223503965392934390771449170872386445565969718817 5919250180245133376000 years. His paper is at http://www.foretec.com/python/workshops/1998-11/proceedings/papers/laningham /laningham.html and it was a very enjoyable talk. For another example, to be really precise, a datetime module needs to support leap seconds, so that "23:59:60" is, at times, valid. But Python's datetime module doesn't allow that. And if it did, it would almost certainly break code written by people who didn't know there could be 61 seconds in a minute. So in summary, almost no one needs the functionality beyond what the standard library has, supporting each and every specialized niche makes for more complex code, and more complex code means people who do "normal" programming are much more likely to run into problems and make the code more likely to break. Andrew dalke at dalkescientific.com From danbmil99 at yahoo.com Thu Aug 21 21:27:52 2003 From: danbmil99 at yahoo.com (dan) Date: 21 Aug 2003 18:27:52 -0700 Subject: how fast is Python? References: <3F44DFEB.60AB6492@engcorp.com> Message-ID: Peter Hansen wrote in message news:<3F44DFEB.60AB6492 at engcorp.com>... ... > And in those very few cases, so far, I have consistently concluded > I'm happy enough with the speed of Python given that the speed of > *development* in Python is easily 5 to 10 times faster than the > speed of development in C. (And again, it's easy to find cases > outside of this range, on either side...) > I pretty much agree. The point of my question was not to knock Python -- I'm simply curious how fast, _in_principle_, a language like Python could be made to run. I've looked at Psyco and Pyrex, I think both are interesting projects but I doubt anything in the Py world has had nearly the kind of man-hours devoted to optimization that Java, C++, and probably C# have had. From vanevery at 3DProgrammer.com Mon Aug 18 17:48:06 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Mon, 18 Aug 2003 14:48:06 -0700 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: Message-ID: Jeff Epler wrote: > Of course, without Python users, he wouldn't have much fun, > would he, with nobody stupid enough to stand up to defend Python and > "get trolled". So even the troll should be glad that there's nothing > "totally compelling" about Ruby over Python. I don't want to get sucked into an issue that I have little to no interest in. So I will observe rhetorically: some of you people waste a *lot* of energy on games of "who's a troll." Mabye it's time for you to establish a c.l.p.advocacy newsgroup, to siphon those energies in a particular direction? But hey, it's your newsgroup. > Jeff > PS I'd just like to state for the record that neither Python nor Ruby > have a totally compelling advantage compared to the following > > K&R C Even as one who hasn't converted to Python yet, that statement is clearly insane. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From mpeuser at web.de Mon Aug 18 10:58:11 2003 From: mpeuser at web.de (Michael Peuser) Date: Mon, 18 Aug 2003 16:58:11 +0200 Subject: bitwise not - not what I expected References: <1YD%a.747879$3C2.17342633@news3.calgary.shaw.ca> <3f40d077$0$164$a1866201@newsreader.visi.com> Message-ID: "Grant Edwards" schrieb im Newsbeitrag news:3f40d077$0$164$a1866201 at newsreader.visi.com... > In article , Michael Peuser wrote: > > > A very good point! I might add that this is my no means an exotic feature. > > Mathematically speaking there is great charme in computing just inside the > > invervall (-1,+1). And if you have no FPU you can do *a lot* of pseudo real > > operations. You have get track of the scale of course - it is a little bit > > like working with sliding rules if anyone can remember those tools ;-) > > Sure. I've got two sitting at home. :) > > FWIW, it used to be fairly common for process-control systems > to define operations only over the interval (-1,+1). This made > implimentation easy, and the input and output devices > (temp/pressure sensors, valves, whatnot) all had pre-defined > ranges that mapped logically to the (-1,+1) interval. > > -- Yes it simplifies a lot of matters, even when using full floating point numbers. Take OpenGL e.g. The colour space is a 1x1x1 cube. Very fine! No magic numbers near 256 ;-) Kindly Michael P From pdfernhout at kurtz-fernhout.com Sat Aug 23 22:33:13 2003 From: pdfernhout at kurtz-fernhout.com (Paul D. Fernhout) Date: Sat, 23 Aug 2003 22:33:13 -0400 Subject: crazy programming language thoughts In-Reply-To: References: <3f457487_7@corp.newsgroups.com> Message-ID: <3f482391_5@corp.newsgroups.com> Roberto Amorim wrote: >>The Python code: >> >> x = sin(10) + 50 * 20 * self.myfunctionXY(cos(30), 40) >> >>would be in Smalltalk something like: >> >> x := 10 sin + (50 * 20 * self myfunctionX: 30 cos y: 40). > > > In fact, that would be > > x := 10 sin + (50 * 20 * (self myfunctionX: 30 cos y: 40)). > > unless you want to call myfunctionX:y: over the result of (50*20*self). :-) My bad. Thanks for pointing this out. It somehow did feel wrong. Guess I've been doing too much Python these days. ;-) --Paul Fernhout -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! -----== Over 100,000 Newsgroups - 19 Different Servers! =----- From newsgroups at jhrothjr.com Sun Aug 17 07:59:17 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Sun, 17 Aug 2003 07:59:17 -0400 Subject: Python should try to displace Java References: Message-ID: "Roy Smith" wrote in message news:roy-E4E108.20220916082003 at reader1.panix.com... > "John Roth" wrote: > > You missed Ruby and TCL. Granted, TCL is probably only being held up > > by TK and Expect, though. > > Don't kid yourself. I work on a commercial application which includes > almost 20,000 lines of TCL, and not a single line of it is Tk or Expect. > As an embedded scripting language, it fills a very nice niche. > > This particular collection of TCL code is the 3rd generation of > scripting code for this application. The first generation was a huge > shell script, which was quickly outgrown. The second generation was a > home-brew language which was a complete failure. The third generation > was embedding TCL, which was a roaring success. > > I've been known to mutter "TCL is a stupid language" more than a few > times (typically during code reviews), but it does have a few things > going for it. It's dead simple to learn, reasonably powerful, and it's > trivial to imbed (simplier than Python). > > Still, for all that, I suspect it's a bit of an evolutionary dead end. I agree. There's a huge amount of intertia since, for many applications, there isn't a whole lot of difference between the four major scripting languages. John Roth From kalmas at udm.ru Tue Aug 19 20:12:03 2003 From: kalmas at udm.ru (Oleg Leschov) Date: Wed, 20 Aug 2003 00:12:03 +0000 (UTC) Subject: codec to parse raw UCS data? Message-ID: Where can I find a list and documentation for codecs? What I want to do is to make a unicode string out of unicode data. for example. I am parsing NTFS metadata, that contains filenames as UCS-2 code, so I have a binary string that pretends to be a UCS-2. Currently I am using hand-written module, a wrapper to iconv library, to make translation of this data (that is, I used it for that task). However, I am aware of python's codecs that are supposed to do the same thing in much prettier way.. So, as long as I can do things like st = u'\uxxxx' and such, I could construct and exec it, but this is ugly... Shouldn't there be a simple thing like .decode("UCS-2") that would return a python's unicode string? Or perhaps I've missed something in the documentation... From vanevery at 3DProgrammer.com Tue Aug 19 04:02:27 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Tue, 19 Aug 2003 01:02:27 -0700 Subject: Brandon's abrasive style (was Re: What's better about Ruby than Python?) References: <38ec68a6.0308172319.431a4fde@posting.google.com> <1061271273.817674@yasure> Message-ID: Donn Cave wrote: > "Troll" is really a function of the audience. Agreed. > These guys will > exist, there is this way of viewing the world as a dramatic > contest between the armies of Python etc.: You will lose, they > will eat your lunch, you're already dead and you don't know it, > bla bla. But it takes an audience that finds this sort of thing > in the least compelling, usually young males it seems. I'm after something much bigger than Python. I'm after Permanent Computing. I want any game I make to be archived for hundreds of years to posterity. Championing an open source language, or figuring out how to surf Microsoft indefinitely, is only the opening gambit. It would not shock me if most people could care less about this agenda. Most programmers are not also artists. They accept their ephemerality, their complete wastes of time. In fact, they usually think it's kewl. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From jwdillworth at yahoo.com Thu Aug 14 11:30:57 2003 From: jwdillworth at yahoo.com (Jeremy Dillworth) Date: Thu, 14 Aug 2003 08:30:57 -0700 (PDT) Subject: No doubt I should know this regex point but .. In-Reply-To: <545cb8c2.0308140709.281fb610@posting.google.com> Message-ID: <20030814153057.34842.qmail@web41113.mail.yahoo.com> I would suggest: "^$" Which matches only empty strings. --- Jim Hefferon wrote: > I am writing a class that walks through a file tree and (among other things) > filters out which files it considers. So I want to have > __init__( .. ,filterExpression='..') > For the default I want to filter nothing. So I need a Python regular expression > that never matches. What is (the best) one? > > Thanks for any help, > Jim > -- > http://mail.python.org/mailman/listinfo/python-list From tjreedy at udel.edu Fri Aug 8 11:49:01 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 8 Aug 2003 11:49:01 -0400 Subject: Need elegant way to cast four bytes into a long References: <3f33c209$1@news.si.com> Message-ID: "William S. Huizinga" wrote in message news:3f33c209$1 at news.si.com... > I've got an array.array of unsigned char and would like to make a slice > of that array (e.g. a[0:4]) become one long like I would in "C" : > > l = ((unsigned long *) (&a[0]))[0]; > > I have been getting what I want in this sort of manner : > > l = 0L > l = a[0] > l += a[1] << 8 > l += a[2] << 16 > l += a[3] << 24 > > but I think that's too wordy. Is there a more intrinsic and elegant way > to do this? el = 0L+ a[0] + (a[1]<< 8) + (a[2]<<16) + (a[3] << 24) is more compact and must be slightly faster (but parens are needed) TJR From adalke at mindspring.com Mon Aug 18 20:50:16 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Mon, 18 Aug 2003 18:50:16 -0600 Subject: Design idea for Ping Application References: <4378fa6f.0308181546.548daff7@posting.google.com> Message-ID: Marc: > I've been searching old posts for ideas, and can't quite come up with > anything. In short I need an application that will continuously ping > 11 different hosts and track the status of the pings. That was a flashback. I posted a "sndping" module on this list many years ago. It made a ping sound for every ping. > This works, but presents me with a problem. In order to continuously > ping using the "-t" option for ping, I am unable to perform a > readlines() command because it hangs. I've tried other variations of > read commands, but they all hang my system. I guess it keeps looking > for EOF and never finds it because the thing is still running. Is > there a type of read command that just takes what is currently in the > buffer and stores it? The normal way is to use the select module, at least for unixy systems. %cat t.py import os, select class Ping: def __init__(self, hostname): self.hostname = hostname timeout = len(hostname) % 5 + 3 # for some variation self.infile = os.popen("ping -i %d %s" % (timeout, hostname)) def fileno(self): return self.infile.fileno() def readline(self): return self.infile.readline() def report(hostnames): pings = [Ping(name) for name in hostnames] while 1: print "Waiting for another ping ...." r, w, e = select.select(pings, [], [], 1) for p in r: print "Ping", p.hostname, p.readline()[:-1] if __name__ == "__main__": import sys if len(sys.argv) == 1: raise SystemExit("missing list of machines to ping") else: report(sys.argv[1:]) %python t.py biopython.org dalkescientific.com python.org Waiting for another ping .... Ping dalkescientific.com PING dalkescientific.com (66.39.47.217): 56 data bytes Waiting for another ping .... Ping biopython.org PING biopython.org (155.94.54.81): 56 data bytes Waiting for another ping .... Ping python.org PING python.org (194.109.137.226): 56 data bytes Waiting for another ping .... Waiting for another ping .... Waiting for another ping .... Ping python.org 64 bytes from 194.109.137.226: icmp_seq=0 ttl=238 time=96.553 ms Waiting for another ping .... Ping python.org 64 bytes from 194.109.137.226: icmp_seq=1 ttl=238 time=94.554 ms Waiting for another ping .... Waiting for another ping .... Waiting for another ping .... Ping biopython.org 64 bytes from 155.94.54.81: icmp_seq=0 ttl=55 time=17.084 ms You could also spawn off a thread for each one, but the select approach is pretty simple. (See Aahz's thread tutorial for an example of how to use threads for a similar task.) Andrew dalke at dalkescientific.com From skip at pobox.com Sun Aug 3 14:09:56 2003 From: skip at pobox.com (Skip Montanaro) Date: Sun, 3 Aug 2003 13:09:56 -0500 Subject: _socket / SocketServer / Mandrake Linux problem / Python 2.3 In-Reply-To: References: Message-ID: <16173.20468.422158.81586@montanaro.dyndns.org> Barry> I've rebuilt, and reinstalled, but cannot find a _socket.py, Barry> _socket.pyo, or _socket.pyc in the lib directory. ( I suspect Barry> that's what socket.py is looking for? ) Nope, it's looking for _socket.so, which you should find in ${prefix}/lib/python2.3/lib-dynload/_socket.so. Skip From abelikov72 at hotmail.com Fri Aug 29 00:11:09 2003 From: abelikov72 at hotmail.com (Afanasiy) Date: Fri, 29 Aug 2003 04:11:09 GMT Subject: Add two dicts Message-ID: <86ktkvkd05e88hu14hjudmfvbul7slfgkt@4ax.com> I have some code like this... self.write( ''' lots of stuff here with %(these)s named expressions ''' % vars(self) ) Then I wanted to add an item to the dict vars(self), so I tried : vars(self)+{'x':'123','y':'345'} This doesn't work, perhaps because no one could decide what should happen to keys which already exist in the dict? (I'd say throw an exception). Can I add two dicts in a way which is not cumbersome to the above % string operation? Is this another case of writing my own function, or does a builtin (or similar) already exist for this? From s at 3ntra.donotfreakingspamme.net Tue Aug 19 08:38:41 2003 From: s at 3ntra.donotfreakingspamme.net (s) Date: Tue, 19 Aug 2003 12:38:41 GMT Subject: Python newbie help References: <87fa5cfa.0308181126.c61bfa2@posting.google.com> <3f412b85.351181492@news.blueyonder.co.uk> <0ct2kvch8346h8pgtk529v7pjlkpai42vo@4ax.com> Message-ID: On Tue, 19 Aug 2003 01:00:06 GMT, Gary Feldman wrote: >On Mon, 18 Aug 2003 21:49:37 GMT, none >wrote: > >>Your examples follow along with the same thing that I'm describing. >>You have code that works and thorough descriptions that explain what's >>going on but there is no end goal. I'm not learning how to write a >>program, I'm learning how to write snippets of code. > >Just out of curiousity, what other programming languages do you know? I >ask because the approach currently taken in the tutorial seems appropriate >for people who already know how to program (and that's made obvious by the >opening paragraph in the introduction). However, if you have no >programming experience, or all you know is JavaScript or perhaps Visual >Basic, then I can see how you might need more. > >Gary Well, I know VB from years ago, C/C++ and a little PHP. It's not so much of a tutorial thing is a motivational thing for me. I want to have an end goal when I'm learning to program with something. With python, I have not been presented an end goal so I get bored quickly looking at code and not putting it to use with anything more than an example. > >PS: Your posting doesn't seem to match the base note with respect to the >various author fields. It's ok to hide real email addresses, etc., but it >would be useful if there were some consistent indicator that the two posts >were written by the same person, assuming that's the case. It could just >be a signature line, even if the sig is just "A Python Novice". Sorry about that. My NG program wasn't cooperating so I had to use Google then I got it to cooperate and I realized that I had some of the preferences screwed up. From iddwb at asu.edu Wed Aug 27 16:25:21 2003 From: iddwb at asu.edu (David Bear) Date: Wed, 27 Aug 2003 13:25:21 -0700 Subject: getopt issues In-Reply-To: References: Message-ID: On Tue, 26 Aug 2003, Steven Taschuk wrote: > > >>> args > > '-Middwb at mainex1.asu.edu -AKHAAM at prlinux+898 [...] > [...] > > >>> a, b = getopt.getopt(args, 'APQn') > > getopt wants its arguments as a list of strings (like sys.argv), > not one big string. Here, for example, many thanks. I didn't think the 'list' of args that getopt wanted was a python list. now that I've read a little more of the getopt documentation, it says that getopt stops processing when a 'nonoption' is encounted. Is there a way to have it process the whole argument list, then only return the options specified in options, rather than have it through an exception and return nothing? > > >>> a, b = getopt.getopt(args.split(), 'APQn') > Traceback (most recent call last): > ... > getopt.GetoptError: option -M not recognized > > as expected. > > From jacek.generowicz at cern.ch Wed Aug 27 09:22:59 2003 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 27 Aug 2003 15:22:59 +0200 Subject: Celebrity advice (was: Advice to a Junior in High School?) References: Message-ID: "Tim Churches" writes: > Cameron Laird wrote: > > > I ask in part because, as near as I can tell, you were the > > first to mention him in this thread. It appears that you > > regard his output as particularly hazardous. > > See the first few paragraphs of > http://www.catb.org/~esr/guns/gun-ethics.html If you wish to strengthen a prejudice you might have about ESR's writings being dangerous, then, yes, read the first few paragraphs of http://www.catb.org/~esr/guns/gun-ethics.html and stop there. You will pass on with that warm fuzzy feeling that smug satisfaction gives you. Whatever you do, don't read on. If you do read on, certainly don't stop to think about what is actually written there. If you do think about it, then don't drop the guard of your prejudice. It is particularly important to protect yourself behind your prejudice if you reach the highlighted phrases: - it all comes down to you - never count on being able to undo your choices - the universe doesn't care about motives for if you do, then you are in danger of realizing that (in spite of the frequent references to triggers, bullets, death etc.) what you are reading is _not_ an article about firearms.[1] And then that warm fuzzy feeling will be replaced by a hollow pit in your stomach, and we wouldn't want that, would we now ! I thank you (Tim) for pointing out this article. I thank myself for ignoring your instructions and reading beyond the first few paragraphs. [FWIW, I am opposed to the "bearing of firearms". However, given that I have only lived in courtries in which firearms are not borne by everyone, I have not had sufficient motivation to base my opinion on any careful consideration.] One learns so much more from reading opinions opposed to one's own, than from reading ones with which you agree. If one suppresses one's prejudices, at least. [1] Don't stop reading at this point either, because then you will fail to realize that it is actually _trying_ very hard to be an article about firearms, after all. But that only serves to strengthen my point. From nika at kassube.de Sat Aug 16 13:19:03 2003 From: nika at kassube.de (Nils Kassube) Date: Sat, 16 Aug 2003 19:19:03 +0200 Subject: Porting to Windows References: Message-ID: <814r0hfrlk.fsf@darwin.lan.kassube.de> Ramon Leon Fournier writes: > Porting software to Windows won't help anyone except Microsoft, not It helps to put food on the table. Case closed. Welcome to reality. It's nice here, isn't it? From gafStopSpamData at ziplink.stopallspam.net Mon Aug 18 15:15:38 2003 From: gafStopSpamData at ziplink.stopallspam.net (Gary Feldman) Date: Mon, 18 Aug 2003 19:15:38 GMT Subject: ClientCookie bug (followup) References: <87fzk4sav2.fsf@pobox.com> <87znibzrnx.fsf@pobox.com> <87oeypdh92.fsf@pobox.com> <87oeyn6pzp.fsf@pobox.com> Message-ID: On 18 Aug 2003 14:43:06 +0100, jjl at pobox.com (John J. Lee) wrote: >Hmm, good idea, but I really don't want to split the documentation up >-- one page is simpler -- and the example is instructive for people Then definitely blockquote it (or indent it some other way), and consider putting it into a smaller font, or using a grey background, or something else to indicate that it's a digression. Orange would draw attention to it; you want the opposite. Gary From jacek.generowicz at cern.ch Thu Aug 28 04:51:26 2003 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 28 Aug 2003 10:51:26 +0200 Subject: OT: Celebrity advice (was: Advice to a Junior in High School?) References: Message-ID: Gerrit Holl writes: > (I don't know how "eigen rechter spelen" is called in English). "Taking the law into your own hands." From jjl at pobox.com Wed Aug 20 18:19:37 2003 From: jjl at pobox.com (John J. Lee) Date: 20 Aug 2003 23:19:37 +0100 Subject: JavaScript web scraping test cases? Message-ID: <87ekzg0y6e.fsf@pobox.com> I've put together a Python package for scraping / testing pages that depend on embedded JavaScript code (without depending on IE, Mozilla or Konqueror, and with the DOM etc. all implemented in pure Python -- mostly a hacked 4DOM, with some bits from pxdom; the JavaScript interpreter I'm using ATM is spidermonkey). It's still missing a lot and is pre-alpha, but it works, just barely. Anyway, the point of this post is that I'm looking for pages to test it on, so if you have a page that you'd like scraped (one that uses JavaScript in some non-trivial way, of course! -- for dynamically modifying forms, setting cookies, or whatever), mail me the details: better that than some randomly-selected site from the Internet. Obviously, it should be something that doesn't violate any terms & conditions of use or otherwise cause people trouble, and preferably that doesn't require any signup. [In fact, TBH, my completely ad-hoc methodology with this is to write some web scraping code, discover that the JavaScript breaks things, often by depending on some nonstandard DOM feature, hack the DOM a bit, etc. Hopefully I'll reach a point in understanding where I can rewrite the DOM from scratch ('scratch' here being 4DOM), properly, to match some approximation of 'HTML DOM as deployed'...] John From erwin at andreasen.com Mon Aug 18 07:01:13 2003 From: erwin at andreasen.com (Erwin S. Andreasen) Date: 18 Aug 2003 13:01:13 +0200 Subject: os.system stdout redirection... References: Message-ID: <87ptj3kz5y.fsf@andreasen.org> Terry Gray writes: > Using Python 2.2 in Debian linuxI am trying to change to a different > directory, execute a 'make all' command, and redirect the output of > the subshell to a PyQt window... I should be able to execute the > os.system('cd newdirectory; make all'), but how do I redirect stdout > of the new subshell created by the os.system call? If you are going to use QT, Use QProcess. You can set it up to fire off a signal when new output has arrived and then read it and update your window. -- =============================================================== Herlev, Denmark <*> =============================================================== From newsgroups at jhrothjr.com Sun Aug 3 19:18:37 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Sun, 3 Aug 2003 19:18:37 -0400 Subject: time, calendar, datetime, etc References: Message-ID: "Tim Peters" wrote in message news:mailman.1059931279.4524.python-list at python.org... > [Tim, explains that the datetime module's date ordinals were > deliberately defined to be identical to those used in > > > Dershowitz and Reingold's highly regarded "Calendrical Calculations": > > > > http://emr.cs.iit.edu/home/reingold/calendar-book/second-edition/ > ] > > [Dennis Lee Bieber] > > Pity the book uses LISP (at least, the first edition did)... > > Even BASIC would be more accessible to most folks (though I would > > prefer a modern BASIC over G-whiz or older). > > I'd prefer Python, myself. It would be a fun (for a date weenie ) > project to recode these algorithms Pythonically. I hope someone does. Well, where's the hook in the module for someone to add additonal calendar classes? John Roth > > From jjl at pobox.com Fri Aug 15 18:46:54 2003 From: jjl at pobox.com (John J. Lee) Date: 15 Aug 2003 23:46:54 +0100 Subject: how to do tags? References: Message-ID: <87oeyqr129.fsf@pobox.com> "Yun Mao" writes: > Hi, I'm using emacs now. How to run etags so that I can search into my own > source code as well as those site-packages source? Thanks a million! Same way you'd do anything else with etags. You just feed it the files you want. C-h i m emacs RET m tags RET m create RET ...and page down a bit, for an example. John From aahz at pythoncraft.com Thu Aug 7 10:57:28 2003 From: aahz at pythoncraft.com (Aahz) Date: 7 Aug 2003 10:57:28 -0400 Subject: Bug? If not, how to work around it? References: Message-ID: In article , Gon?alo Rodrigues wrote: > >So, is it a bug? In other words, should I open a bug report? I'd say it's not a bug. It's a natural consequence of the way new-style classes are intended to work. OTOH, opening a bug report may result in improvement of the documentation -- if you do choose a bug report, I'd suggest taking that tack. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From poire.williams at nomore.org Fri Aug 22 13:38:23 2003 From: poire.williams at nomore.org (Poire Williams) Date: Fri, 22 Aug 2003 19:38:23 +0200 Subject: Python/C API - PyArg_ParseTuple problem ? Message-ID: Hi, everybody. I'm writing a Python binding for a C++ library and I just found something that puzzles me. In some initializing function for a new type, I parse arguments using PyArg_ParseTuple as usual. One of the optional arguments is a string, so it looks like this if (!PyArg_ParseTuple(args, "ii|s", &a, &b, &s)) return NULL // go on... Whenever I instantiate the new type with a value for the optional string argument, and try to quit the Python interpreter, it seems to enter an infinite loop (top(1) shows it consumes all CPU resource), with the following traceback according to gdb: #0 0x400d2797 in chunk_free (ar_ptr=0x4017d6a0, p=0x8129ea8) at malloc.c:3251 #1 0x400d2513 in __libc_free (mem=0x8129f60) at malloc.c:3153 #2 0x08057d32 in _PyObject_Del () #3 0x0805d2ec in string_dealloc () #4 0x080c9740 in PyDict_DelItem () #5 0x0805cc8e in PyString_Fini () #6 0x080955e7 in Py_Finalize () #7 0x080535bb in Py_Main () #8 0x08052df6 in main () #9 0x4007b17d in __libc_start_main (main=0x8052de0
, argc=1, ubp_av=0xbffff654, init=0x80521d0 <_init>, fini=0x80d0b10 <_fini>, What is really strange is that is only happens if I instantiate the new type like this: >> t = NewType(0, 42, 'hi') If I do this: >> s = 'hi' >> t = NewType(0, 42, s) everything is well... Moreover, if I change my C code to something like this: if (!PyArg_ParseTuple(args, "ii|O", &a, &b, &o) return NULL; s = PyString_AsString(o); everything's fine again, in both cases... I guess it's some kind of twisted reference count thing, and I'm still trying to get some minimal C code to reproduce this. Meanwhile, does anybody have a clue ? Thanks in advance. Precisions: I'm running Python 2.2.3 on Linux, and I don't free() the buffer retrieved via PyArg_ParseTuple or PyString_AsString :) -- J?r?me Laheurte If you didn't get caught, did you really do it? From aleax at aleax.it Wed Aug 6 10:39:24 2003 From: aleax at aleax.it (Alex Martelli) Date: Wed, 06 Aug 2003 14:39:24 GMT Subject: Checking for an "undefined" variable - newbie question References: <3f30f372$0$27815$626a54ce@news.free.fr> Message-ID: Damien Wyart wrote: > * Alex Martelli in comp.lang.python: >> If you can't rule out (e.g.) None as a valid value for your variable, >> just make a unique placeholder value such as [be sure to use a MUTABLE >> value, else uniqueness is not guaranteed]: > > Could you expand on this "uniqueness" point ? I don't see very well what > you mean. if you used, e.g.: variable = 'astringthatwontactuallyoccur' then you couldn't later test with if variable is 'astringthatwontactuallyoccur': because the two literals might be or not be unique so the 'is' test is not guaranteed to work -- you'd have to use == which is slower -- AND again because of non-uniqueness you might be in trouble is some code did want to assign to variable such a string, e.g. because it can get read from a file, or interactively from the user, or otherwise constructed. The 'is' test checks for object identity, not value, so it's faster -- and using a unique mutable object (e.g. a class) made just for the purpose also guarantees no clashes with any actual value you might want to assign to your variable. I started that classname with an underscore to signify it's meant for internal use in the module, not for export to other modules, by the way. Alex From ghowland at lupineNO.SPAMgames.com Sat Aug 23 01:50:25 2003 From: ghowland at lupineNO.SPAMgames.com (Geoff Howland) Date: Sat, 23 Aug 2003 05:50:25 GMT Subject: Indentation question References: Message-ID: On Sat, 23 Aug 2003 04:55:53 GMT, David Lees wrote: >I have a real basic how-to question. When I decide to reuse a piece of >python code at a different indentation level than the original, is there >a common trick (or set of tricks) for moving the indentation correctly >for the whole block? Probably this is editor dependent, so if some has >a FAQ or pointer to a page please feel free to post. Typical I use >PythonWin as my editor, though sometimes I use EditPadLite (an ascii >editor). A lot of editors use the method of: 1. Select lines of text 2. Press TAB or SHIFT+TAB to change indentation out or in respectively. I dont know about those editors though. -Geoff Howland http://ludumdare.com/ From tismer at tismer.com Mon Aug 11 07:46:54 2003 From: tismer at tismer.com (Christian Tismer) Date: Mon, 11 Aug 2003 13:46:54 +0200 Subject: Slogan: Getting Rich Overnight In-Reply-To: References: Message-ID: <3F37822E.6040104@tismer.com> Robert Kern wrote: ... [Me, in a bad mood] >>Did I say anything bad? Nothing at all, this was said by >>other people. And those are dictating to us, what to say >>and what not to say. >>SHould we really continue to support this? [Robert] > Come on, there's no need to take this personally. It's a great slogan that > succinctly describes the almost-revelatory experience of the Python newbie. > Unfortunately, it is surrounded by circumstances beyond your or my control that > hamper its potential in certain situations. You're right. Once again, I abused emails as a valve for personal anger, which is never good. Sorry. ciao - chris -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 pager +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From cnetzer at sonic.net Thu Aug 28 02:09:34 2003 From: cnetzer at sonic.net (Chad Netzer) Date: Wed, 27 Aug 2003 23:09:34 -0700 Subject: another puzzled newbie In-Reply-To: <68g3b.855589$ro6.16997110@news2.calgary.shaw.ca> References: <68g3b.855589$ro6.16997110@news2.calgary.shaw.ca> Message-ID: <1062050974.1852.174.camel@adsl-209.204.179.133.sonic.net> On Wed, 2003-08-27 at 22:09, Elaine Jackson wrote: > The analogous thing works fine in interactive mode, but when I put it in a > script, the function singlePass (below) causes a compile-time error. A SyntaxError perhaps? > def singlePass(shuffler,preshuffled,postshuffled): > postshuffled+=[preshuffled[shuffler[0]] ^ You forgot a ']' at the end of the line > del(preshuffled[shuffler[0]]) ^ You don't need the '(' and ')' here. del is a keyword, not a function. > del(shuffler[0]) > for i in range(len(shuffler)): > shuffler[i]+=(-1) ^^^^ If you want a tuple here, it should be (-1,). It needs the comma. But, since shuffler is a list, you probably really want [-1]. -- Chad Netzer From paddy3118 at netscape.netNOTthisBIT Sun Aug 24 20:16:24 2003 From: paddy3118 at netscape.netNOTthisBIT (Donald 'Paddy' McCarthy) Date: Mon, 25 Aug 2003 01:16:24 +0100 Subject: For Kenny Tilton: Why do I need macros revisited. In-Reply-To: References: <3f45484f$1_6@corp.newsgroups.com> <3F45A7BF.4060806@nyc.rr.com> <8dk1b.2825$Ej6.1159@newsread4.news.pas.earthlink.net> <40udnfEuVojnr9uiXTWJjg@comcast.com> Message-ID: <3F495558.7000805@netscape.netNOTthisBIT> Jacek Generowicz wrote: > "Terry Reedy" writes: > > >>Until some advocate of a Python macro facility adds more detail to the >>proposal beyound 'Lisp/Scheme-like maco facility', it is really hard >>for someone like me, who has used neither, to have much of any >>concrete idea of what is being proposed. > > > Until some advocate of a Python macro facility adds more detail to the > proposal ... it is really hard for me to have much of any concrete > idea what is being proposed ... because Lisp-style macros rely on the > fact that Lisp code is expressed in a fundamental Lisp data structure, > in the form of its parse tree. This ain't the case in Python, so the > whole macro business suddenly gets more complicated by an order of > magnitude or two. > > I just can't imagine what such a macro system would look like. Maybe > someone with deep knowledge of Dylan can enlighten us. You might take a look at: http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&selm=3ED52BAE.5050704%40blueyonder.co.ukNOTthisBIT&rnum=12 This was my attempt at putting down some of the things that I'd like to see in Python Macros/ Cheers, Pad. From vanevery at 3DProgrammer.com Sun Aug 10 16:55:30 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Sun, 10 Aug 2003 13:55:30 -0700 Subject: Python vs. C# References: <2259b0e2.0308100616.55b651ca@posting.google.com> Message-ID: <3f36af20@shknews01> Michele Simionato wrote: > I would not waste my time in learning something which could > disappear in few years (Microsoft's policy in supporting programming > languages is well know). Microsoft does almost all of its internal development in C# now. It is not going away. C# is, essentially, the .NET Framework. The advantages of C# as an enterprise language over C++ are quite obvious, and of course Microsoft is going to use its homegrown, not Java. I think what C# has got going for it, is it's much better than C++ to work with, it's got mature tools support, and performance is claimed to be good as long as you don't create garbage collection hell. Comparing C++ to Python, Python has obvious higher level advantages. But comparing C# to Python, Python isn't much higher level than C#. They've got "similar stuff," with Python adding some exotic features. Python gets style points, but tools maturity, ubiquity, and future count for more than style points. I'm beginning to think that within 5 years, no new applications will be written in C++. People will still be using legacy C++ libraries, but all new development will be in higher level langauges. Java and C# are the obvious languages that are not going away. Python? What industrial entity is going to champion Python? It takes a Sun, a Microsoft, or overwhelming utility to push a language. For instance, Perl has become popular because it's overwhelmingly useful for sysadmin and web admin. But I am not seeing Python's overwhelming utility compared to other languages. You can do apps, you can do web admin, but most people are doing Java, C#, or Perl. And unlike C++ they aren't bad languages, so Python is not offering an obvious "slam dunk" remedy. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From uche at ogbuji.net Fri Aug 22 12:07:00 2003 From: uche at ogbuji.net (Uche Ogbuji) Date: 22 Aug 2003 09:07:00 -0700 Subject: resolving relative paths for external entities with xml.sax References: Message-ID: Bart wrote in message news:... > On Fri, 15 Aug 2003 06:24:02 -0700, Uche Ogbuji wrote: > > >> From what I understand of XML specs, relative paths in external entities > >> are relative to the location of the document *in which they are defined*. > >> However, using xml.sax (which calls expat, I presume), the paths are > >> resolved relative to the current working directory. So the parser can not > >> find the test.inc when the current working directory is e.g. dir1. > > > > I, for one, need to see your Python code to tell, because if you're > > using the APIs rightly parsing the first file as a URI rather than, > > say, reading it in as a string first), then you should not have the > > problem you report. > > something like: > from xml.sax import make_parser > from xml.sax.saxutils import XMLGenerator > reader = make_parser() > reader.setContentHandler(XMLGenerator()) > reader.parse('test.xml') > > this is run in the test1 dir. > > I also tried using absolute paths, xml.sax.InputSource, 'file:' URLs and > combinations of these. > > The result is either: > OSError: [Errno 2] No such file or directory: 'test.inc' > or (when using 'file://tmp/xmltest/test1/test.xml'): > OSError: [Errno 2] No such file or directory: '/tmp/xmltest/test1/test.inc' > or (when using 'file:test.xml'): > OSError: [Errno 2] No such file or directory: '/test.inc' Ignore my last posting. Silly me: I threw out all the context. This is a bug. I'll try to make time to look into it (I don't get to pitch into PyXML enough these days). > In the meantime, I found a discussion in bugzilla for python.xml about the > prepare_input_source method in xml.sax.xmlutils (see > http://sourceforge.net/tracker/index.php?func=detail&aid=616431&group_id=6473&atid=106473) > but i am not sure it is really relevant. It's certainly relevant, and I plan to make that a starting point. Thanks. --Uche http://uche.ogbuji.net From peter at engcorp.com Mon Aug 18 11:59:22 2003 From: peter at engcorp.com (Peter Hansen) Date: Mon, 18 Aug 2003 11:59:22 -0400 Subject: What's better about Ruby than Python? References: Message-ID: <3F40F7DA.D27A8C58@engcorp.com> "Brandon J. Van Every" wrote: > > What's better about Ruby than Python? I'm sure there's something. What is > it? > > This is not a troll. An observation: Brandon seems particularly incapable of posting anything that is *not* a troll. On the plus side, he didn't cross-post it... Please, someone, teach the guy about Google. -Peter "already in his killfile" Hansen From jar at mminternet.com Thu Aug 7 22:06:56 2003 From: jar at mminternet.com (james roush) Date: Thu, 7 Aug 2003 19:06:56 -0700 Subject: uTidyLib --I'm lost References: Message-ID: In article , cookedm+news at physics.mcmaster.ca says... > At some point, james roush wrote: > > > I'm tryinh to switch from mx.tidy to uTidyLin and it isn't going well. > > So far I can't even import TidyLib. Below is what I get when trying to > > import into Idle. I'm using Python 2.1. > > > >>>> from tidylib.lib import parse, parseString > > Traceback (most recent call last): > > File "", line 1, in ? > > from tidylib.lib import parse, parseString > > File "K:\Python21\tidylib\lib.py", line 47 > > yield n > > ^ > > because yield (and generators) weren't added until python 2.2. (you'll need > to upgrade.) > > So I've been told. i'm beginning to think I'm the only one that didn't know this. I upgraded to 2.3 and things are much better now. -- ----------------------- James A Roush jar @ mminternet.com ----------------------- From wtrenker at shaw.ca Sun Aug 17 10:17:19 2003 From: wtrenker at shaw.ca (William Trenker) Date: Sun, 17 Aug 2003 14:17:19 +0000 Subject: WebDAV Message-ID: <20030817141719.62c726b7.wtrenker@shaw.ca> I've been goolging for a WebDAV client written in Python. I've found http://www.webdav.org/projects/ which includes http://www.lyra.org/greg/python/davlib.py but not much else for the client side. Zope's WebDAV package also includes http://cvs.zope.org/Packages/webdav/client.py Does anyone know of any other WebDAV client software written in Python? I'm trying to programmatically access my Zope site via DAV so I guess Zope's own client.py would be the way to go. But I'd be interested to know of other DAV clients written in Python. Thanks, Bill From jjl at pobox.com Fri Aug 22 11:15:55 2003 From: jjl at pobox.com (John J. Lee) Date: 22 Aug 2003 16:15:55 +0100 Subject: Which way to say 'private'? References: Message-ID: <87he49zpsk.fsf@pobox.com> Jacek Generowicz writes: > "Batista, Facundo" writes: > > > As a I read don't remember where, :p, to put 1 underscore is the > > same to hang a "Do not disturb" sign in the door, to put 2 > > underscores is the same to lock the door. > > ... and to put the key under the mat in front of the door. (On the > outside :-) > > Any fool who cares to look, can figure out and circumvent the name > mangling scheme. It offers no protection against intruders. It does > offer protection against name clashes, and that is its purpose. And, just to reiterate, both _ and __ offer protection against accidental intruders (not the same as accidental name-clashes). And __ does offer some protection against thoughtless abuse of implementation where there's an interface to do the job. So, to sum up, contrary to popular belief, all of this is roughly the same in any language -- one can always get around the restrictions (though maybe not feasibly in some cases with Java?) -- they're there only to prevent accidents and casual abuse. Hence the argument often put forward here that making access restrictions *too* awkward to work around is actually a real mistake -- interface designers *have* been known to make mistakes . John From a.schmolck at gmx.net Tue Aug 19 18:28:00 2003 From: a.schmolck at gmx.net (Alexander Schmolck) Date: 19 Aug 2003 23:28:00 +0100 Subject: What's better about Ruby than Python? References: Message-ID: "Andrew Dalke" writes: > Pedro Werneck: > > Well... I think you're overlooking the fact that you're not exactly > > _redefining_ the class. You're creating an entirely new class > > object and binding it to the same name, but the old class is still > > lying there, > > I'm pretty sure he knows that and simply disagrees with that > design choice, suggesting that a class def should augment a > class if it already exists. Indeed. Or rather what I find *really* important is that there exist proper support for interactive development (so that changes to source code can be easily reflected in a running session). I currently sometimes find myself driven to develop procedural, rather than OO code (because changes to functions in the source code can be trivially updated in the interactive shell), and sometimes I even skip the procedural bit, too, and just throw code into the global level (because if something goes wrong I get to keep the variables I've accumulated so far). [I'd like to stress that I obviously only do this in extreme cases (when the code both takes long to run and is highly experimental -- so that its final form might also well depend on intermediate results obtained during interactive development) and I presuambly just have to think harder about how to do this properly in python. Does anyone know a way to fake restartable exceptions in python BTW?]. > > I wonder ... Alexander? What should this do? > > from Q import X > > class X: > def amethod(self): return 'ah, now THIS is better!' > > Should it refine the X in the local namespace or make a new > class? I'd say redefine X in the local namespace. Have you spotted a problem with it? > > I have wondered if > > def X.amethod(self): return "...." > > should be allowed, but no longer think it should. No I don't think so either. > > OTOH, a proper reload, which updated all instance's __class__ > to the newly reloaded class, would be nice. I've stumbled > over that many a time. Indeed. I'd summarize my opinion on python as follows: python's biggest strength it is a practical language that supports interactive development, languages which don't support interactive development are worthless (but all too common). Python's biggest weakness is that it doesn't support interactive development properly and out-of-the-box (I think its generally often difficult to have the changes you made to your source code adequately reflected in your interactive session and the debugging facilities are pretty poor (and yet already *extremely* useful if used properly; ``@pdb on`` emacs/ipython sure speeds fixing things up). Bizarrely, of all the languages I've ever come across, the only one which seems to have a vaguely sensible development model is smalltalk. 'as From p3d at yahoo.co.uk Mon Aug 18 09:54:47 2003 From: p3d at yahoo.co.uk (PD) Date: 18 Aug 2003 06:54:47 -0700 Subject: python and symbian? Message-ID: Hello, I was wondering if anyone knew of any efforts to get python working on the symbian platform? I've done a search and have turned up a couple of links to projects on the symbian site, but these projects appear to be long dead. I personally prefer python to java and would love to find a python alternative to j2me. Just wondering. thanks PD From bokr at oz.net Sat Aug 2 03:35:40 2003 From: bokr at oz.net (Bengt Richter) Date: 2 Aug 2003 07:35:40 GMT Subject: bug in file.write() ? References: <13a4e2e3.0307311443.299bd59d@posting.google.com> <3f2b5e60.36345431@news.lexicon.net> Message-ID: On Sat, 02 Aug 2003 07:08:20 GMT, sjmachin at lexicon.net (John Machin) wrote: >On 31 Jul 2003 15:43:34 -0700, pu at vo.lu (Patrick Useldinger) wrote: > >>Hi, >> >>I think I found a bug in the write method of file objects. It seems as >>if before writing each block, a check was done in order to verifiy >>that there is enough space left for the *whole* file, not for the >>*remaining* data to be written. > >This is very unlikely --- it is difficult to determine reliably the >available space on a disk or tape volume; if one were really >interested, one would do it once before trying to write the file, not >before writing each block. No, the expected implementation, which you >can check against reality by inspecting the source (fileobject.c), is >just to attempt to write, and throw an informative-as-possible >exception if the write fails. > >Despite the appearance that you have about 6KB margin of safety, you >will probably find that you don't have any --- the quoted size of the >source file doesn't include the unused space in the last cluster or >block or whatever. It's a while since I've had to concern myself with >this sort of detail, but it's a good bet that the "chunk" size on your >disk is 8Kb or more and you're out of luck. > Besides chunks of data, directories and allocation info also take up nonzero space, and unless you have a file system with a fixed reserve for that stuff (maybe some unusual custom floppy format?) it's going to take its byte out of the total. How much will depend on how that nondata stuff is implemented. A thick tree of directories max deep and all single-cluster data files will surely be different from a single large file. >> >>It happens both under 2.3 and 2.2.3. >>Any ideas? > >[snip] > >> File "C:\Python23\lib\shutil.py", line 39, in copyfile >> copyfileobj(fsrc, fdst) >> File "C:\Python23\lib\shutil.py", line 24, in copyfileobj >> fdst.write(buf) >>IOError: [Errno 28] No space left on device >> >>I:\My Programs\dfc>dir f: >> Volume in drive F is Backup 01 >> Volume Serial Number is E2CB-1650 >> >> Directory of F:\ >> >>18/05/2002 15:39 . >>18/05/2002 15:39 .. >>01/08/2003 00:25 299.630.592 dfcArchive cheetah >>20030731-234648 F.zip >> 1 File(s) 299.630.592 bytes >> 2 Dir(s) 299.636.736 bytes free >> >[snip] Regards, Bengt Richter From unendliche at hanmail.net Mon Aug 4 07:07:33 2003 From: unendliche at hanmail.net (Seo Sanghyeon) Date: 4 Aug 2003 04:07:33 -0700 Subject: IDLE function 'tooltips' References: <38ec68a6.0308032215.2db836c0@posting.google.com> Message-ID: <45e6545c.0308040307.49eb580c@posting.google.com> Asun Friere wrote: > I'm just trying out Python 2.3's IDLE and was wondering how you turn > off the 'tooltipping' that comes up whenever you write out a function > and open the first parenth. I can't seem to find the option for it in > 'Configure IDLE'. You can turn it off by editing IDLE's extension config file. In case of Python 2.3 on Windows XP, make a file named "config-extensions.cfg" under .idlerc directory, which would be under your home directory. And write: [CallTips] enable = 0 It would be nice to make this configurable in the configuration dialog. Perhaps you must submit this one as a feature request? Seo Sanghyeon From klappnase at web.de Tue Aug 5 20:02:58 2003 From: klappnase at web.de (klappnase) Date: 5 Aug 2003 17:02:58 -0700 Subject: Capture PID of child process References: <6qr8403xh2.fsf@salmakis.intevation.de> Message-ID: Bernhard Herzog wrote in message news:<6qr8403xh2.fsf at salmakis.intevation.de>... > > If cmd is a string popen will start a sub-shell so that'd the pid you > get. You could try to prefix your command with exec so that your > command's process replaces the shell process (see the shell > documentation). Thank you so much for that hint! > Alternatively you could use a list of strings as the command so that no > shell is used in the first place, i.e. "prog param" would become > ["prog", "param"]. This approach has the advantage that you don't have > to worry about shell quoting but it's less portable because it's not > even documented (I'll file a bug report for that). > This really seems to work, too if I use: self.pp = popen2.Popen3(cmd.split()) I am just not sure if this is an additional feature or a bug? Does anyone know this? Michael From elw at euc.cx Thu Aug 21 15:24:06 2003 From: elw at euc.cx (Jeffrey P Shell) Date: 21 Aug 2003 12:24:06 -0700 Subject: What's better about Ruby than Python? References: Message-ID: <240b1020.0308211124.69d25418@posting.google.com> Alex Martelli wrote in message news:... > As for me, I have no special issue with "having to specify self" for > functions I intend to use as bound or unbound methods; otherwise I > would no doubt have to specify what functions are meant as methods > in other ways, such as e.g. > > def [method] test(what, ever): > ... > > and since that is actually more verbose than the current: > > def test(self, what, ever): > ... > > I see absolutely no good reason to have special ad hoc rules, make > "self" a reserved word, etc, etc. Python's choices are very simple > and work well together (for the common case of defining methods > that DO have a 'self' -- classmethod and staticmethod are currently > a bit unwieldy syntactically, but I do hope that some variation on > the often-proposed "def with modifiers" syntax, such as It's especially nice that if you don't want to use 'self', you don't have to. Comfortable with 'this' from Java and friends? def test(this, what, ever): this.goKaboom(what*ever-what) will work just fine. 'self' is just a ferociously common idiom. But it's only an idiom. I like that. So even if we used [method] as a function decorator, I'd still prefer to see 'self' as part of the signature. I just like knowing where my names come from. I do like the concept of function/method decorators though. I'll have to revisit that PEP. -- J.Shell; http://toulouse.amber.org/ From daniel.dittmar at sap.com Thu Aug 7 06:00:53 2003 From: daniel.dittmar at sap.com (Daniel Dittmar) Date: Thu, 7 Aug 2003 12:00:53 +0200 Subject: How to dectect UCS4 Python at runtime? Message-ID: I'm trying to detect whether the Python currently running has been compiled for UCS2 or UCS4. I need this because I'm distributing a C extension. I've choosen to pack the binaries for all the Python versions into one download and then decide at runtime which one to load. And with RedHat compiling Python for UCS4, I'll have to do the same for the unicode variants. Daniel -- Daniel Dittmar SAP DB, SAP Labs Berlin http://www.sapdb.org From br_y at yahoo.de Fri Aug 22 09:09:25 2003 From: br_y at yahoo.de (Birgit Rahm) Date: Fri, 22 Aug 2003 15:09:25 +0200 Subject: catching a from CORBA.UserException inherited exception Message-ID: Hallo newsgroup, I have the following problem: (programming in Python with omniORB and omniORBpy) 1. I got an IDL file and translate it with omniidl and got a python file 2. I wrote a executable python file, which correct connects (till I have the starting object in the expected class) and disconnects to the ORB 3. then I want to invoke a method within a try - except statement, where the except statement has to catch an exception defined in the file created in 1. - without the try - exception statement the call is correct with the correct parameter and throws an exception (that ends the debugging) with an incorrect parameter now I wanted to catch the correct exception, but I can only catch CORBA.UserException in the right way What have I to do, to catch the derived exception? I hope, someone can help me. TIA, Birgit From detlefsend at enovatia.com Thu Aug 7 16:40:06 2003 From: detlefsend at enovatia.com (David Detlefsen) Date: Thu, 07 Aug 2003 16:40:06 -0400 Subject: Freeze Question In-Reply-To: <16178.34749.356683.239307@montanaro.dyndns.org> Message-ID: On 8/7/03 1:09 PM, "Skip Montanaro" wrote: > > Dave> I'm to the point where two modules are not found by freeze: > > Dave> Warning: unknown modules remain: pcre strop > > Dave> There is no mention of these in my Modules/Setup file. Any > Dave> suggestions. > > I think you can probably omit both, though if freeze is figuring things out > for you automagically, you may need to tweak Lib/string.py and Lib/re.py to > dispense with them. The strop module is an extension module which used to > be used to speed up the string module. With string methods it's no longer > needed. It's in Modules/stropmodule.c. Pcre is pretty kaput as well. That > was the first incarnation of Perl-compatible regular expressions, since > replaced by the new sre module. It's in Modules/pcremodule.c. I suspect > Modules/pypcre.c is part of the mix as well. > > Skip I think I'm all set with Freeze with a static python build. Just to summarize and close the loop on this, here's what I did: 1. Modified Modules/Setup uncommenting as many modules I could find that freeze was complaining about (this took care of all but strop and pcre) 2. Commented out references to strop in all Lib/*.py it existed in which included only string.py and stringold.py (python 2.2.1) 3. Removed (actually renamed) Modules/pre.py...not sure why this was getting included in my build since re.py had an if/else that should have caused sre to be imported (and presumably eliminating the dependency on pcre) instead of pre...not sure if that makes sense. 4. Did a 'make clean' and a 'make' to a static python 5. Freeze my python program without any Warning: unknown modules error Dave From donn at drizzle.com Sat Aug 30 22:54:38 2003 From: donn at drizzle.com (Donn Cave) Date: Sun, 31 Aug 2003 02:54:38 -0000 Subject: Escaping shell commands References: <5ce25061.0308301727.4c7b478a@posting.google.com> Message-ID: <1062298477.438124@yasure> Quoth tocapicha at hotmail.com (Inspector Chan): | I'm using some external data on shell commands which are to be | executed with os.system (other functions doesn't provide enough | flexibility for executing these shell lines). | | So I have decided to user re.escape() for escaping these data before | using it on the created command lines. | | Quick example: | | malicious external data in var 'data': | | data= '; touch /home/user/I0wnzu' | | shell command to be executed is 'command': | | command= 'echo I am so happy' + re.escape(data) | | This way the generated shell lines is: | | echo I am so happy\;\ touch\ \/home\/user\/I0wnzu | | With this example it looks safe... But I'm not quite sure about this | method of escaping input. | | Is this breakable? I can't think of any way right off hand. Well, if the immediate command actually goes on to invoke another shell that will interpret this string again, you lose, but you can't win that one anyway. | Does anyone knows a better way to get this done? I prefer to avoid the shell, with os.spawnv(). Suppose you're invoking something a little more fussy about its parameters than echo, like 'ls' - os.spawnv(os.P_WAIT, '/bin/ls', ['ls', '-l', data]) Note that element 0 of the parameter list is the name of the command - this list is the sys.argv for ls. Donn Cave, donn at drizzle.com From darnold4 at cox.net Thu Aug 28 07:30:22 2003 From: darnold4 at cox.net (David Raleigh Arnold) Date: Thu, 28 Aug 2003 07:30:22 -0400 Subject: sed with python References: Message-ID: On Wed, 27 Aug 2003 19:26:36 +0200, U. N. Owen wrote: > > David Raleigh Arnold enlightened us with: >> How do I use python as a wrapper for sed and/or gawk scripts? > > You don't. Python can do anything sed and awk can, and much, much more. > > Sybren > > > > That's true, but it may be useful to use existing code (and not bother > rewriting in Python). You can use shell scripts, pipes, or if you want to > use only python scripts, use > os.system to call sed or awk. > But if you write new functions, Python is enough, as Sybren says Thanks. I didn't realize at first that Sybren had not read the question before replying. I am using shell scripts, both very simple ones that call sed and more elaborate ones that extract fields from a database and do something with them. Obviously, os.system does me no good at all. If windows users had bash I would have no reason to use python to call it. Is there an equivalent to "tac" already written as a function in python? Is there a matrix transposition function that automagically adds fields to records so that all records have the same number of fields, to guard against data loss? Where are these found? DaveA -- "We have learned the lessons of Viet Nam." --anon Spokesman "Failure is not an option." --anon Spokesman Can both be true? n Are both false? y Right answers get my vote. D. Raleigh Arnold dra@ http://www.openguitar.com darnold4 at cox.net From pythonhda at yahoo.com.replacepythonwithlinux Tue Aug 26 09:38:31 2003 From: pythonhda at yahoo.com.replacepythonwithlinux (pythonhda) Date: Tue, 26 Aug 2003 09:38:31 -0400 Subject: need code-snippet for a simple dialog window in wxPython References: Message-ID: <20030826093832.73e105b8.pythonhda@yahoo.com.replacepythonwithlinux> Download the wxpython demo from their website. Also check out the wiki for additional help: http://wiki.wxpython.org/index.cgi/MessageBoxes On Tue, 26 Aug 2003 12:53:12 +0200 Christoph Lehmann wrote: > Hi > > I am a newbie and have a very simple python code, doing some calculations. > > maybe there is one already having a code snippet in wxPython for what I need: > > (i) simple dialog box, where the user can enter an integer. after > closing the dialog I get this integer. nothing more > > (ii) similar for getting a file-name (with a file-dialog) > > thanks a lot > > > christoph > > > -- > Christoph Lehmann > > From anton at vredegoor.doge.nl Sat Aug 16 06:12:47 2003 From: anton at vredegoor.doge.nl (Anton Vredegoor) Date: Sat, 16 Aug 2003 12:12:47 +0200 Subject: Eight Queens Puzzle by Magnus Lie Hetland References: <215fa0fc.0308130557.7f1c950b@posting.google.com> <3f3c1007$0$177$a1866201@newsreader.visi.com> <3F3CC067.5010102@users.ch> Message-ID: bokr at oz.net (Bengt Richter) wrote: >I decided to see how it would go if I did the same thing using a set of position tuples >to represent a board. I found that the strict ordering of the bitmap in a long was doing >stuff I wanted (i.e., allowing me to use it as a unique dict key), so I wound up representing >solutions as tuples of the set tuples, sorted. I changed the printout to print any of the 92 >showing a selected unique solution along with the transformation(s) to transform the unique >to the other. First of all, I explicitly disclaim to be able to follow precisely what you have been programming. This reply is just because some of the things you are talking about seem to be vaguely reminiscent of the things I'm doing. IMO it would be best to find a unique representative for a solution, for example by hashing all its mirror images and always choosing the mirror image with the smallest hash value as a canonical representative for a solution. >I guess I might think that a set of small integers might map nicely to bits in an int or long >and back, and might be useful as a hidden optimization. > >Another useful thing might be to make a set hashable by sorting the element list and >hashing that as a tuple, the way I did manually. Of course it wouldn't always work, but >if e.g., the underlying representation was a bit vector, it could work fast. You'd >want a coercion method to accept a long or int as a bit vector integer set representation, >or maybe an as_bitvec property that you could operate through, e.g., > > mySet = sets.Set() > mySet.as_bitvec |= 0xff > >could mean the same as > > msSet = sets.Set() > mySet |= sets.Set(range(256)) The comment I made above is still valid here, so please take my remarks with a grain of salt. I *think* you are advocating that sets could (and should) sometimes be represented with long integers, which I heartily agree with. Dictionaries are close competitors for set programming and have the advantage of being faster. In order for sets to have a niche in the programmers mind they should be blazingly fast and this can be done nicely by representing them by long integer *bitfields*. This has been discussed before, see for example: http://home.hccnet.nl/a.vredegoor/universe (the link above points to a broken set implementation, I'm just using it as an example of a possible alternative way of programming sets, I still think that it is possible to program sets this way, but progress in this area has been halted for quite some time now, and the project is lingering in limbo) Specific for the queen solving problem however is the need to reduce the search space (I'm just assuming people generalize the problem to n-sized boards) and this can be done by using symmetry to find solutions which represent whole categories of solutions. I'm interested in the problem because finding representative solutions is used in a lot of other areas too. For example -in my case- programming go -baduk- can use it effectively and also it can be used for programming solutions to rubiks cubes of size 5x5x5 and up. What I like to do is to find the canonical representatives first and to generate the list of solutions later, by applying the different transforms to them. I think neither my code below nor your code -which is much appreciated- do that. A completely different problem is the need to write readable code, which I have not solved yet. When the subject of the code is getting more and more abstract -as is the case with mirror transforms of abstractions from solution spaces- the advantages of Python as a readable programming language dwindle fast. The same kind of problems can be observed when trying to read numerical Python code or code about three -or more- dimensional computations or when reading difficult combinatorics code. While the code is readable for the coder, anyone else has a hard time to reproduce the *history* of code creation which IMO is an important cue for why the code has become as it is instead of having been done in a different way. Since you're posting different developmental versions the readers get a view in your kitchen and can have a look at your coding recipes and follow the creative process, which is much appreciated. As a counterexample I'm giving a piece of code of mine -also meant to slow you down a bit to give me time to follow :-) - which does more or less the same as your code (no competition however, your code is a lot better) and is a bit easier to follow for *me only* [1] because I programmed it. I wouldn't be surprised if even seasoned coders would have a hard time following it, while it's only very simple code. If true, the audience can give the verdict about what kind of code is easier to read and which guidelines should be followed to make it easier to mentally reproduce the *flow* of the program. Anton [1] A friend of mine when asked for solutions to difficult mathematical problems, sometimes replies by sending me the solution in the form of an -incomprehensible- excel spreadsheet :-) I'm still trying to get even the idea of using Python for communicating solutions across, in order to not replace one problem with a solution inside another problem. < snip much appreciated yet hard to follow code > >====< queenset.py >======================================================== < and returning the favor (maybe it's a lot easier to read? I don't think so :-) > def uniqueQueens(size): """n-Queens solver without solutions that are rotations or mirror images of previous solutions""" n = size board = [divmod(i,n) for i in range(n*n)] d = {} for solution in queens(n,board): c = hashmirror(n,solution) if c not in d: d[c] = solution yield solution def queens(n,F,Q=[]): """recursive n-Queens solver""" if n==0: yield Q for i,q in enumerate(F): for gen in queens(n-1,prune(q,F[i+1:]),Q+[q]): yield gen def hashmirror(sz,sol): """turn the solution into a matrix representation and find the mirror image of this matrix with the smallest hash value, and return the hash value""" mat = [[0]*sz for i in range(sz)] for i,j in sol: mat[i][j] = 1 def hm(mat): #horizontal mirror image m = mat[:] for i in range(sz/2): m[i],m[sz-i-1]=m[sz-i-1],m[i] return m def d1(mat): return zip(*mat) def r1(mat): return zip(*hm(mat)) def r2(mat): return r1(r1(mat)) def r3(mat): return hm(zip(*mat)) def vm(mat): return d1(r3(mat)) def d2(mat): return d1(r2(mat)) def I(mat): return mat[:] mh =1L<<100 for T in [hm,vm,d1,d2,r1,r2,r3,I]: h = hash(tuple(map(tuple,T(mat)))) if h < mh: mh = h return mh def prune((i,j),F): """removes positions that are covered by Queen(i,j)""" def keep((x,y)): return i!=x and j!=y and abs(x-i)!=abs(y-j) return filter(keep,F) def test(): size = 8 for i,solution in enumerate(uniqueQueens(size)): print i,solution if __name__=='__main__': test() From dave at pythonapocrypha.com Mon Aug 25 08:44:03 2003 From: dave at pythonapocrypha.com (Dave Brueck) Date: Mon, 25 Aug 2003 06:44:03 -0600 Subject: python gripes survey In-Reply-To: <78kkkvg8ckfio141es2of1p483ohbtbit5@4ax.com> References: <78kkkvg8ckfio141es2of1p483ohbtbit5@4ax.com> Message-ID: <200308250644.03273.dave@pythonapocrypha.com> On Monday 25 August 2003 12:14 pm, Afanasiy wrote: > I have a bunch, many of them hard to define, but one that I just thought > of I find strange sometimes is the use of tuples as near-mystery return > values. I can't help but thinking a C struct with named fields is easier > to remember than a tuple with fields accessed by integer. > > Sure you can return an associative array, but in my experience the > preference is to return a tuple. I'll probably get flamed for saying so, > but this is how I feel and it is unavoidable. Returning a struct in C is > easier to deal with than returning a near-mystery tuple in Python. A bit of an apples-to-oranges comparison, isn't it? If you prefer to return a named structure in C, the Python equivalent certainly wouldn't be a tuple. -Dave From pythonguy at Hotpop.com Wed Aug 13 03:16:33 2003 From: pythonguy at Hotpop.com (Anand Pillai) Date: 13 Aug 2003 00:16:33 -0700 Subject: Finding the path to a file References: Message-ID: <84fc4588.0308122316.af9ffc4@posting.google.com> One way to do this is to specify an environment variable similar to PYTHONPATH for your application. It will be the place where the program should search for the config file. On unix, one user would use it as follows. Egs: % export MYCONFIGPATH="/etc:/usr/local/etc:/home/someuser/: /home/soomeuser/program" In your program, look for the config file first in cwd . If you cannot find it look up this env variable from the shell using os.environ.get() and walk through the paths using os.path.walk() to look for your cfg file. I suggest os.path.walk() as it can recurse the sub-paths too. It reminds me, I have to add similar functionality for harvestman. Anand Todd Johnson wrote in message news:... > Hey, > > I have been working on a program that stores > information for each user in a subdirectory of the > directory in which the script is run. So if my script > is in /home/someuser/myprogram, the config files and > such are in /home/someuser/myprogram/config. Now if I > invoke the interpreter from the same directory as the > script is in I can load and save the files because cwd > points to that directory(I used cwd to get the path > and then add /config to it to get to the proper > directory) > > My problem is that if I invoke it with a command like > python /home/someuser/myprogram but I am in > /home/someuser, cwd does not point to the scripts > directory but to the directory the interpreter was > invoked from. This means I don't know how to find the > config files other than making them hard coded to a > certain directory. I don't want to hard code them > however so that the program can be contained in one > directory and easily removed and I also don't want to > have to specify where a user installs the program. > > So basically, I want to know how to find the directory > my script is in, even when it is invoked from another > directory. Any help would be greatly appreciated. > > Thanks in advance, > Todd A. Johnson > > ===== > The grace of the Lord Jesus Christ, and the love of God, and the communion of the Holy Ghost, be with you all. Amen. II Corinthians 13:14 > > __________________________________ > Do you Yahoo!? > Yahoo! SiteBuilder - Free, easy-to-use web site design software > http://sitebuilder.yahoo.com From hokiegal99 at hotmail.com Thu Aug 28 09:30:55 2003 From: hokiegal99 at hotmail.com (hokieghal99) Date: Thu, 28 Aug 2003 09:30:55 -0400 Subject: Script Discussion & Critique In-Reply-To: References: <3F4D31B1.6080802@hotmail.com> <06eqkv4onjh5m4tcbbqkmh8lscaj5niatp@4ax.com> <3F4D4402.3060209@hotmail.com> Message-ID: Ganesan R wrote: > Others have done an excellent job of telling you the problems of critiquing > your code. I'll try to address one point that others haven't covered > already. > > What you've done is not wrong. But it's simpler to replace all that with > > import sys > x = sys.argv[1] > y = sys.argv[2] > setpath = sys.argv[3] > > so that you can run it as "python myscript.py ". > This way you can easily call your script from another program and > makes it much more useful. You can do something like > > if len(sys.argv) >= 1: > x = sys.argv[1] > y = sys.argv[2] > setpath = sys.argv[3] > else: > raw_input(...) > ... I don't understand this approach to developing a script. I think this is more of a true program than a script... it's much more complex. My background is shell scripting so I'm limited to what I've learned from that. Python is much deeper than that, but I'm learning. Thank you for the advice. From rimbalaya at yahoo.com Thu Aug 21 10:40:46 2003 From: rimbalaya at yahoo.com (Rim) Date: 21 Aug 2003 07:40:46 -0700 Subject: docutils: ImportError: No module named roman Message-ID: <6f03c4a5.0308210640.46504655@posting.google.com> Hi, ImportError: No module named roman What provides the roman module? I can't run docutils/tools since I upgraded to python2.3. Thanks, -Rim From gregadelliot at hotmail.com Mon Aug 4 05:17:11 2003 From: gregadelliot at hotmail.com (jeff) Date: 4 Aug 2003 02:17:11 -0700 Subject: Python and Robotics? References: <3f2d1e1d$0$4192$afc38c87@news.optusnet.com.au> <3F2D58AF.9000705@norfolkgraphics.com> <3f2e0061$0$4189$afc38c87@news.optusnet.com.au> Message-ID: Also try pyserial, i think thats how its spelt, i know there are only really 2 lines (tx/rx) that can be used, but if you chuck in a max232 and a pic to recieve binary codes, then you could use the pic's I/O ports and then use the serial port to send out binary codes, that tell the pic what to execute hope that help, if you need any help email me if been playing with interfacing hardware to the computer using python for a little while now HTH greg From duncan at NOSPAMrcp.co.uk Mon Aug 18 04:24:21 2003 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Mon, 18 Aug 2003 08:24:21 +0000 (UTC) Subject: overriding a tuple's __init__ References: Message-ID: Simon Burton wrote in news:pan.2003.08.18.07.37.44.108933 at webone.com.au: >>>> class pair(tuple): > ... def __init__(self,a,b): > ... tuple.__init__(self, (a,b) ) > ... >>>> a=pair(1,2) > Traceback (most recent call last): > File "", line 1, in ? > TypeError: tuple() takes at most 1 argument (2 given) >>>> > > What gives? (yes it works with a list, but i need immutable/hashable) You need to override __new__ instead of __init__: >>> class pair(tuple): def __new__(cls, a, b): return tuple.__new__(cls, (a,b)) Tuples really are immutable, so their value has to be set by the constructor __new__ rather than the initialiser __init__. The same applies if you wanted to subclass numbers. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From phil at riverbankcomputing.co.uk Mon Aug 18 04:53:26 2003 From: phil at riverbankcomputing.co.uk (Phil Thompson) Date: Mon, 18 Aug 2003 09:53:26 +0100 Subject: ANN: PyQt v3.8 Released In-Reply-To: References: Message-ID: <200308180953.26774.phil@riverbankcomputing.co.uk> On Monday 18 August 2003 2:59 am, John Taylor wrote: > Phil, > > Does PyQT support the ability to minimize an app to the lower right > tray, next to the clock? If so, could you please post some example > code? What platform? If you mean Windows then QApplication.winEventFilter() and QWidget.winEvent() were added to PyQt v3.4 at the specific request of somebody who wanted to do this. Sorry, but I don't have example code. Phil From kevin at cazabon.com Mon Aug 18 13:45:29 2003 From: kevin at cazabon.com (Kevin Cazabon) Date: 18 Aug 2003 10:45:29 -0700 Subject: python threads on multi-CPU machines References: Message-ID: <5a4226f0.0308180945.34f96eca@posting.google.com> > However, C extensions can release the > GIL, and almost all I/O code in Python does that, so I/O-heavy programs > will make good use of the SMP. FYI, I'm also working on adding that functionality to the PIL library, seeing as imaging operations can be fairly expensive too. It makes these processes more "friendly" to other threads (and Tk) even on single-CPU boxes, and allows taking advantage of multiple CPUs where available. I'll be posting links on the PIL mailing list when it's complete (just needs exhaustive testing now... it'll be a while), and Fred has agreed to merge it into the core distribution afterwards. Kevin. From Franck.BUI-HUU at gemplus.com Mon Aug 25 04:26:46 2003 From: Franck.BUI-HUU at gemplus.com (Franck Bui-Huu) Date: Mon, 25 Aug 2003 10:26:46 +0200 Subject: for iteration References: Message-ID: <3F49C846.7020301@gemplus.com> Thanks for your example but I haven't found __iter__ method in list type: >>> dir(list) ['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__delsli ce__', '__doc__', '__eq__', '__ge__', '__getattribute__', '__getitem__', '__gets lice__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__le__', '__ len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__repr__', '__r mul__', '__setattr__', '__setitem__', '__setslice__', '__str__', 'append', 'coun t', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort'] >>> Do you know why ? Peter Otten a ?crit: >Franck Bui-Huu wrote: > > > >>Hello, >> >>I'm trying to customize a list by overriding __getitem__ method but >>this change seems to not work with for iteration. >>When I use my customized list in a for iteration, all changes made >>in __getitem__ are not take into account. >>How can I modify this behaviour ? >> >>Thanks >> >> > >For the for loop to work properly, you have to overide the __iter__() >method, e.g.: > >class MyList(list): > def __getitem__(self, index): > """ for the sake of this example convert item to uppercase """ > return list.__getitem__(self, index).upper() > def __iter__(self): > """ implemented using a generator """ > for i in range(len(self)): > yield self[i] # calls the customized __getitem__() > >myList = MyList(["alpha", "beta", "gamma"]) > ># works with __getitem__() >for index in range(len(myList)): > print myList[index] > >print > ># works with __iter__() >for item in myList: > print item > >Peter > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Wed Aug 27 11:05:13 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 27 Aug 2003 11:05:13 -0400 Subject: Celebrity advice (was: Advice to a Junior in High School?) References: Message-ID: "Tim Churches" writes: > Cameron Laird wrote: > > > I ask in part because, as near as I can tell, you were the > > first to mention him in this thread. It appears that you > > regard his output as particularly hazardous. > > See the first few paragraphs of > http://www.catb.org/~esr/guns/gun-ethics.html I did. 'Few' means at least three. The second and last sentence of the third paragraph reads " Every political choice ultimately reduces to a choice about when and how to use lethal force, because the threat of lethal force is what makes politics and law more than a game out of which anyone could opt at any time." Do you disagree (with what seems to me like an obviously true statement)? Or are you one who doesn't the 'people' to notice the elitist hypocrisy of being 'anti-gun' while supporting the bearing *and use* of guns by 'govern-men' the elitists hope to control? (I think it safe to say that during the 20th century, 99% of the 100s of millions of murders were committed by armed govern-men rather than by private persons acting alone.) Well back to Python. Terry J. Reedy From newsgroups at jhrothjr.com Tue Aug 19 12:50:10 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Tue, 19 Aug 2003 12:50:10 -0400 Subject: generators improvement References: Message-ID: "Duncan Booth" wrote in message news:Xns93DC5C1AFAB9Eduncanrcpcouk at 127.0.0.1... > Oleg Leschov wrote in > news:bhtiij$psc$2 at ocasysi.rubbernet.net: > > > What needs to be done is to allow yield return something - whatever was > > passed to the .next() thing from caller.. > > Easy and obvious, isn't it? So is there any principal problem with this > > idea that would prevents its implementation? > > Please read PEP 288, http://www.python.org/peps/pep-0288.html > in particular the section: > > > Rejected Alternative > > One idea for passing data into a generator was to pass an argument > > through next() and make a assignment using the yield keyword: > > > > datain = yield dataout > > . . . > > dataout = gen.next(datain) > > > > The intractable problem is that the argument to the first next() call > > has to be thrown away, because it doesn't correspond to a yield > > keyword. "I can't figure out how to do it so that it satisfies my sense of esthetics" is not the same as "this problem doesn't need to be solved." John Roth > > > > > -- > Duncan Booth duncan at rcp.co.uk > int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" > "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From bignose-hates-spam at and-benfinney-does-too.id.au Tue Aug 19 20:04:19 2003 From: bignose-hates-spam at and-benfinney-does-too.id.au (Ben Finney) Date: 20 Aug 2003 09:54:19 +0950 Subject: Why does this (not) work? References: Message-ID: On Tue, 19 Aug 2003 19:16:27 -0400, Michael C. Neel wrote: > why is the % operator used both for string formatting and remainders? Historical. Neither operation has an obvious character on the keyboard, and the '%' did not already have an obvious application as an operator for either strings nor numbers. For numbers, I believe the '%' for modulus has been around at least as early as C, probably in much earlier languages. Its visual similarity to the division operator, which is strongly related to modulus, probably helped the decision. For strings, the C printf formatting codes use '%' as a format marker within the string, so when Python adopted the same convention, it was a good choice when Python needed to choose a character for the operator. > >>>"%d" % 2 * 3 > "222" > > Is not what I expected nor wanted. I could however be alone in that > opinion. No, you're not alone in that -- I'd certainly expect the "2 * 3" to have a tighter binding than, and to be evaluated before, the string formatting. I think it's even potentially a bug that the "2 * 3" is interpreted as a string operation, since its arguments are clearly numeric. However, this does reinforce a principle I learned from somewhere (maybe Scott Meyers, maybe Steve McConnell, maybe someone else) with regard to remembering operator precedence in different languages: Addition and subtraction are equal precedence. Multiplication and division are equal precedence. Use parentheses to make explicit any other precedence assumptions. Using that rule, your example becomes: >>> "%d" % ( 2 * 3 ) '6' No problem. > It's probably not hard to guess I don't like ', '.join(list) either > ;-) Nor I. But I am finding the reminder of the immutability of the list to be useful. -- \ "What if the Hokey Pokey IS what it's all about?" -- Anonymous | `\ | _o__) | Ben Finney From tjreedy at udel.edu Fri Aug 22 14:29:50 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 22 Aug 2003 14:29:50 -0400 Subject: What's better about Ruby than Python? References: <3F41505F.69D18CC8@alcyone.com> <66d7kvonvb2n0nqbqahhd5roak7ur81sob@4ax.com> <3f43ef5d_4@127.0.0.1> <3F440A35.9030602@nyc.rr.com> <4o_0b.1665$Ej6.1182@newsread4.news.pas.earthlink.net> <8D01b.1721$Ej6.702@newsread4.news.pas.earthlink.net> <3F44ED2E.9070308@nyc.rr.com> <0V61b.1900$Ej6.1012@newsread4.news.pas.earthlink.net> <3F4504D7.20008@nyc.rr.com> Message-ID: "Mario S. Mommer" wrote in message news:fzoeyihycs.fsf at cupid.igpm.rwth-aachen.de... > Lisp is simple. > > ( ...) > > Where's the problem? The very uniformity of everything (including operators?) being a possibly recursive list and the actual practice of relatively deep (compared to Python and similar languages) nesting. If a lisp expression ends with 10 to 20 closing parentheses (which I have seen), then there were at least 10 to 20 pending operations waiting to be closed. This many layers is a bit much for many or most people. There is also the 'problem' of having to read inside out and backwards. Ok for a line or two, less ok for multiple lines. Consider the opposite extreme for an accumlator-based machine: Assembly is simple. Where's the problem? The very uniformity of doing everything in sequential baby steps. Once people learn and understand the baby steps, bigger chunks like discrim = sqrt(b*b-4*a*c) are easier to grasp than the assembler equivalent. Empirically, it seems that most people prefer the mix of steps with expressions to either extreme of all steps or all expression, even though both syntaxes express function composition. > Granted, you need an editor that helps you to match the parens This may make deep nesting more manageable, but does not make it shallower. Yes, one could also write a 10-line, 10-layer expression in Python, but I doubt I would. Terry J. Reedy From FBatista at uniFON.com.ar Wed Aug 20 17:18:48 2003 From: FBatista at uniFON.com.ar (Batista, Facundo) Date: Wed, 20 Aug 2003 18:18:48 -0300 Subject: Python: executing ping and whois Message-ID: #- Anybody that could tell me how to execute some Linux commands using #- Python. os.system() >From the web documentation: """ system(command) Execute the command (a string) in a subshell. This is implemented by calling the Standard C function system(), and has the same limitations. Changes to posix.environ, sys.stdin, etc. are not reflected in the environment of the executed command. On Unix, the return value is the exit status of the process encoded in the format specified for wait(). Note that POSIX does not specify the meaning of the return value of the C system() function, so the return value of the Python function is system-dependent. On Windows, the return value is that returned by the system shell after running command, given by the Windows environment variable COMSPEC: on command.com systems (Windows 95, 98 and ME) this is always 0; on cmd.exe systems (Windows NT, 2000 and XP) this is the exit status of the command run; on systems using a non-native shell, consult your shell documentation. Availability: Unix, Windows. """ . Facundo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ADVERTENCIA La informaci?n contenida en este mensaje y cualquier archivo anexo al mismo, son para uso exclusivo del destinatario y pueden contener informaci?n confidencial o propietaria, cuya divulgaci?n es sancionada por la ley. Si Ud. No es uno de los destinatarios consignados o la persona responsable de hacer llegar este mensaje a los destinatarios consignados, no est? autorizado a divulgar, copiar, distribuir o retener informaci?n (o parte de ella) contenida en este mensaje. Por favor notif?quenos respondiendo al remitente, borre el mensaje original y borre las copias (impresas o grabadas en cualquier medio magn?tico) que pueda haber realizado del mismo. Todas las opiniones contenidas en este mail son propias del autor del mensaje y no necesariamente coinciden con las de Telef?nica Comunicaciones Personales S.A. o alguna empresa asociada. Los mensajes electr?nicos pueden ser alterados, motivo por el cual Telef?nica Comunicaciones Personales S.A. no aceptar? ninguna obligaci?n cualquiera sea el resultante de este mensaje. Muchas Gracias. -------------- next part -------------- An HTML attachment was scrubbed... URL: From john at rygannon.com Sat Aug 16 03:22:45 2003 From: john at rygannon.com (BadJake) Date: Sat, 16 Aug 2003 07:22:45 GMT Subject: ANN: Rekall V2.1 beta0 Message-ID: <3f3ddb46$0$226$fa0fcedb@lovejoy.zen.co.uk> Hi We are please to announce that we have just started beta testing Rekall V2.1 beta0. This release is considered unstable, therefore it should not be used in a production environment. If you would like to help us beta test Rekall V2.1 beta0, please me an email and I will send you the details of my private anonymous FTP server. Please email your request to john at totalrekall.co.uk or john at rygannon.com for the Windows version and mike at quaking.demon.co.uk for the Linux version. New for this release are: Macros and Wizards Best Regards John Dean From fperez528 at yahoo.com Wed Aug 27 17:13:08 2003 From: fperez528 at yahoo.com (Fernando Perez) Date: Wed, 27 Aug 2003 15:13:08 -0600 Subject: changing color on the command prompt References: <731fc603.0308271213.4d91ab29@posting.google.com> Message-ID: Hank wrote: > does anyone know how to change the foreground color of the command > prompt through python? > > For example if i was printing out an error message, I would like it to > be red where the normal text color is white. You may want to look at ipython (http://ipython.scipy.org), which does that (and much more). best, f From postmaster at comeconnect.com Fri Aug 22 04:51:18 2003 From: postmaster at comeconnect.com (postmaster at comeconnect.com) Date: Fri, 22 Aug 2003 13:51:18 +0500 (GMT+0500) Subject: Wicked screensaver In-Reply-To: <200308220851.NAA0000002086@mohali1-ee0.comeconnect.com> References: <200308220851.NAA0000002086@mohali1-ee0.comeconnect.com> Message-ID: <200308220851.NAA0000002138@mohali1-ee0.comeconnect.com> Mail not delivered to @comeconnect.com. The mailbox of the user has exceeded the allotted limit.Try sending later. From heikowu at ceosg.de Sun Aug 17 19:26:33 2003 From: heikowu at ceosg.de (Heiko Wundram) Date: Mon, 18 Aug 2003 01:26:33 +0200 Subject: client derived from async_chat In-Reply-To: <3f4001bb_2@news.vo.lu> References: <3f3fdb48_1@news.vo.lu> <3F3FF26F.3D6538F4@alcyone.com> <3f3fff3c_1@news.vo.lu> <3f4001bb_2@news.vo.lu> Message-ID: <1061162793.1230.17.camel@d168.stw.stud.uni-saarland.de> On Mon, 2003-08-18 at 00:30, Patrick Useldinger wrote: > > socket.error: (10035, 'The socket operation could not complete without > > blocking') >From what I read, this is obvious: Windows is telling you, that the (still-connecting) socket you created is set to non-blocking, but still you try to receive data from it, so this means that the operation would have to block until the socket is finally connected (or fails to connect). Remember: connecting is also a non-blocking operation, if the socket is set to non-blocking mode. I even think that exactly this error is telling you (IIRC from reading the UNIX socket docs) that the connection is still in progress; when the socket later returns some other exception, this means that the socket could not be established, when read() returns something for the first time, the socket has been established. I dunno why async_chat doesn't work with this on Windows (on *nix, this is exactly what it does), but I guess it has something to do with decoding the error codes, as a *nix-socket would return EWOULDBLOCK in this case, for which it checks, I am certain of that. HTH! If you need more info on this, feel free to mail me privately. Heiko. From peter at engcorp.com Thu Aug 28 13:59:14 2003 From: peter at engcorp.com (Peter Hansen) Date: Thu, 28 Aug 2003 13:59:14 -0400 Subject: Python quote of the week? References: Message-ID: <3F4E42F2.BA7FB9F9@engcorp.com> Simon Brunning wrote: > > "All that rigid type safety and data hiding is like wearing army boots on > the beach: nothing can bite your toes, but golly don't it feel good to just > toss 'em and run barefoot." > > David Pinn, . Hmm.... nothing can bite your toes, but you can still trip. And those who "toss 'em and run barefoot" a lot will have learned from the experience that going barefoot actually provides one with a better feel for the terrain, and thus a more sure-footed way of travelling. It needs a little more care (watch out for glass, pointy rocks, and scorpions) but is arguably safer in many cases. Going barefoot is of course also the more agile way to go: "Be more agile: program barefoot, with Python." -Peter From bobx at linuxmail.org Fri Aug 1 21:50:04 2003 From: bobx at linuxmail.org (Bob X) Date: Sat, 02 Aug 2003 01:50:04 GMT Subject: 2.3 win installer References: <7pAWa.7762$gi.4246099@news2.news.adelphia.net> Message-ID: "Jarek Zgoda" wrote in message news:bgenpf$p89$4 at atlantis.news.tpi.pl... > Bob X pisze: > > >> Anyone having problems with the 2.3 win installer? I'm running win2k pro > >> (sp4) and the installer is freezing after the initial dialogues, just as > >> teh install starts. > > > > If you have any anti-virus going...turn it off. Oh and download it again. > > Does Python 2.3 have any known viral activity? > No but sometimes AV programs cause problems... From irmen at -NOSPAM-REMOVETHIS-xs4all.nl Wed Aug 6 08:23:58 2003 From: irmen at -NOSPAM-REMOVETHIS-xs4all.nl (Irmen de Jong) Date: Wed, 06 Aug 2003 14:23:58 +0200 Subject: Isn't there a substring(start, end)-function???? In-Reply-To: References: Message-ID: <3f30f35f$0$49113$e4fe514c@news.xs4all.nl> Dave wrote: > Am I blind, or what? I can't find any quick way to do the following in > Python: > > substring(beginIndex, endIndex) witch returns the substring between > beginIndex and endIndex. > > Like: > text = "If someone attacks you with a banana" > print text.substring(0,3) > Should print "If " You're not blind but you've overlooked string slicing: C:\> python Python 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> text = "If someone attacks you with a banana" >>> print text[0:3] If >>> print text[3:10] someone >>> print text[-6:] banana >>> print text[::-1] ananab a htiw uoy skcatta enoemos fI more info here: http://www.python.org/doc/current/ref/slicings.html --Irmen From paul at boddie.net Thu Aug 28 07:17:56 2003 From: paul at boddie.net (Paul Boddie) Date: 28 Aug 2003 04:17:56 -0700 Subject: Celebrity advice References: <3F4CD2A2.DE7D05D2@engcorp.com> Message-ID: <23891c90.0308280317.ac68b38@posting.google.com> "Andrew Dalke" wrote in message news:... > Lulu of the Lotus-Eaters: > > Of course, in reality, the homicide rate is much lower outside of the > > USA, so the base rate isn't good for extrapolation. > > I thought of that when I looked up that number. But the > comparison stats I know of are for Europe. I remember in 'Guns, > Germs, and Steel', in the foreword the author points out that > the homicide rate in New Guinea was quite high, pointing out > he knew a woman whose first husband was killed by the man > who became her second husband. A great book, that one, with some very interesting discussions on dynamics within and between societies, and the relative importance of technology in all of these things. Interestingly, if I recall correctly, the author mentions the introduction of firearms in New Zealand and the subsequent "musket wars", contrasting this with the disapproval of firearms over a long period in Japan. Again, I'd recommend that people spend their time doing a bit of background reading (and viewing - the homicide rate discrepancy is also covered in "Bowling for Columbine") rather than pushing their agenda on a programming language newsgroup because they probably couldn't cut it on a newsgroup actually dedicated to such discussions. Paul P.S. And the reason why many people find ESR to be offensive or just plain inappropriate is that one gets the feeling that he wants you to buy into his whole agenda, whether or not that involves running around with a firearm in the woods dressed as Obi-Wan or Yoda. From duncan at NOSPAMrcp.co.uk Thu Aug 7 10:43:52 2003 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Thu, 7 Aug 2003 14:43:52 +0000 (UTC) Subject: Stupid string.split question References: <3f314721$0$3936$b45e6eb0@senator-bedfellow.mit.edu> <3F3160E6.BD604930@engcorp.com> <3f326199$0$3951$b45e6eb0@senator-bedfellow.mit.edu> Message-ID: Brian Kelley wrote in news:3f326199$0$3951$b45e6eb0 at senator-bedfellow.mit.edu: > Now, as for old chesnuts and long hot summers, if one could just do: > > "".join(list("ABCDEF").reverse()) > > *ducks* > In what way would that be an improvement on writing "ABCDEF"[::-1] ? *ducks and runs* -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From mwh at python.net Fri Aug 1 07:14:37 2003 From: mwh at python.net (Michael Hudson) Date: Fri, 1 Aug 2003 11:14:37 GMT Subject: Wow: list of immediate subclasses? References: Message-ID: <7h3k79xaavf.fsf@pc150.maths.bris.ac.uk> "Andrew Dalke" writes: > Carl Banks, responding to Roman Suzi: > > __subclasses__ is a list of weak references, so the class can be > > collected even though it's listed in __subclasses__. For whatever > > reason, class A isn't deleted by reference counts, but cyclic garbage > > collection gets it. > > But I want to know that reason. Why are there any cycles? After > all, don't weak-references help break cycles? And in my code > before, why do I need to do the gc a few times to force the cycle > to be broken? > > >>> float.__subclasses__() > [] > >>> class Spam(float): pass > ... > >>> float.__subclasses__() > [] > >>> del Spam > >>> _ = None # just in case ... This doesn't do what you think it does. The reference to Spam is in __builtin__._; this only assigns to __main__._. I don't know where the cycle is, off-hand. I suspect I did once... [...] > It's a bit too mysterious for my liking. I can manage not to care :-) Cheers, mwh -- It's actually a corruption of "starling". They used to be carried. Since they weighed a full pound (hence the name), they had to be carried by two starlings in tandem, with a line between them. -- Alan J Rosenthal explains "Pounds Sterling" on asr From peter at engcorp.com Wed Aug 13 14:24:53 2003 From: peter at engcorp.com (Peter Hansen) Date: Wed, 13 Aug 2003 14:24:53 -0400 Subject: Determine file type (binary or text) References: Message-ID: <3F3A8275.8B6EE8C4@engcorp.com> Trent Mick wrote: > > [Sami Viitanen wrote] > > Hello, > > > > How can I check if a file is binary or text? > > > > There was some easy way but I forgot it.. > > Generally I define a text file as "it has no null bytes". I think this > is a pretty safe definition (I would be interested to hear practical > experience to the contrary). "Contains only printable characters" is probably a more useful definition of text in many cases. I can't say off the top of my head exactly when either definition might be a problem.... wait, how about this one: in CVS, if you don't have a file that is effectively line-oriented, human readable information, you probably don't want to let it be treated as "text" and stored as diffs. In that situation, "contains primarily printable characters organized in lines" is probably a more thorough, though less deterministic, definition. -Peter From FBatista at uniFON.com.ar Tue Aug 5 07:24:00 2003 From: FBatista at uniFON.com.ar (Batista, Facundo) Date: Tue, 5 Aug 2003 08:24:00 -0300 Subject: Auto persistency Message-ID: Example of class. Just an object between all of them in my program: class Example: def __init__(self, value): self.value = value return def getValue(self): return self.value def setValue(self, value): self.value = value return I want to implement persistency. I think it's a good idea to each object be the responsible of it's own persistence in a file, in a sql server, anywhere (opinions?). Adding persistence: class Example: def __init__(self, value): self.value = value # create in sql server return def getValue(self): return self.value def setValue(self, value): self.value = value # modify in sql server return Now I have two questions: 1) How do I implement the dead of the object. I need it to erase itself from the sql server. Should I define the __del__ method? 2) When the program starts, how do I retrieve all the objects from the sql server to memory? (considering that only the object knows how it's persisted). Thanks for all. . Facundo From aleaxit at yahoo.com Mon Aug 18 09:44:53 2003 From: aleaxit at yahoo.com (Alex Martelli) Date: Mon, 18 Aug 2003 15:44:53 +0200 Subject: Functions References: Message-ID: Thor wrote: > In this hypothetical case: > > def f1: I assume you mean def f1(): here and in similar cases (the parentheses are syntactically mandatory). > f3: I assume you mean f3() here and in similar cases (the colon would be a syntax error, the parentheses indicate a call is being performed). > def f2: > def f3: > pass > f1: > def f4: > def f3: > pass > f1: > > would the function f1 execute the right f3 depending on from which > functions is it called? No. There is no "dynamic scoping" of names (and the rules are exactly the same whether you're thinking of names of functions or names of any other type of object). f1 would look up name f3 in its LEXICAL scope, not find it, and therefore produce an error. If you added global f3 as the first statement of both f2 and f4, right before the "def f3():" in each of them, then -- as it happens -- you would get the behavior you're after, in this particular simple case (both f2 and f4 would, with the 'global', clobber global name f3 with their own version of function f3 on each execution -- and global names of this module which all functions share ARE parts of the lexical scope searched for name resolution within function f1). Alex From tjreedy at udel.edu Thu Aug 7 14:03:05 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 7 Aug 2003 14:03:05 -0400 Subject: Static class properties (read-only) References: Message-ID: "Greg Brunet" wrote in message news:vj4v20o2qfi7c9 at corp.supernews.com... > In puzzling over classes, I'm wondering if classes can have read-only > static properties? I certainly seem to be able to do create static > properties like this: > > class C(object): > count = 0 > > def __init__(self,s): > C.count += 1 > self.Name = sCC > > def __del__(self): > C.count -= 1 > > and C.count should have a count of the number of its instances that have > been created. However, someone could set the value directly. Prefixing count with a single underscore will tell others that is is private-- they should not write it and should not depend on being able to read it in future versions. Prefixing with 2 underscores will invoke name-mangling, which you need to read about before using. TJR From avadmin at cds.unina.it Thu Aug 28 03:29:57 2003 From: avadmin at cds.unina.it (avadmin at cds.unina.it) Date: Thu, 28 Aug 2003 03:29:57 CEST Subject: Inflex scan report [08280329268745] Message-ID: <200308280129.h7S1TwoE270668@cds.unina.it> Administrator Email Reply Address: avadmin Email sent to: zelati at cds.unina.it Inflex ID: 08280329268745 Report Details ----------------------------------------------- AntiVirus Results... SWEEP virus detection utility Version 3.71, July 2003 [Digital Unix/Alpha] Includes detection for 82960 viruses, trojans and worms Copyright (c) 1989,2003 Sophos Plc, www.sophos.com System time 03:29:58, System date 28 August 2003 Command line qualifiers are: -archive -all -rec -sc IDE directory is: /usr/local/sav Using IDE file webber-a.ide Using IDE file gruel-a.ide Using IDE file coconuta.ide Using IDE file cmjspy-b.ide Using IDE file golon-a.ide Using IDE file ataka-e.ide Using IDE file migmaf-a.ide Using IDE file mofei-b.ide Using IDE file viewmova.ide Using IDE file israza.ide Using IDE file graps-a.ide Using IDE file larx-fam.ide Using IDE file zwmvc-b.ide Using IDE file adenu-a.ide Using IDE file mylife-m.ide Using IDE file mumu.ide Using IDE file revas-a.ide Using IDE file klexe-a.ide Using IDE file sage-a.ide Using IDE file sluter-a.ide Using IDE file colevo-a.ide Using IDE file slanpera.ide Using IDE file cailonta.ide Using IDE file sandesa.ide Using IDE file yaha-t.ide Using IDE file sobig-e.ide Using IDE file frtnghte.ide Using IDE file relax-c.ide Using IDE file pcghosta.ide Using IDE file haclineb.ide Using IDE file nofer-c.ide Using IDE file magold-d.ide Using IDE file redist-c.ide Using IDE file nofer-b.ide Using IDE file mumu-b.ide Using IDE file sobig-d.ide Using IDE file frtnghtf.ide Using IDE file mystri-a.ide Using IDE file crock-a.ide Using IDE file suhd-a.ide Using IDE file nofer-a.ide Using IDE file anaco-d.ide File panjang.ide is older than 90 days Using IDE file gruel-c.ide Using IDE file gruel-b.ide Using IDE file mapson-c.ide Using IDE file gruel-d.ide Using IDE file gruel-e.ide Using IDE file dwnld-di.ide Using IDE file gruelfam.ide Using IDE file mofei-c.ide Using IDE file jantic-b.ide Using IDE file frtnghth.ide Using IDE file qqpass-a.ide Using IDE file babybr-a.ide Using IDE file mimail-a.ide Using IDE file randonr.ide Using IDE file cidu-a.ide Using IDE file gruel-m.ide Using IDE file boohoo-a.ide Using IDE file maila.ide Using IDE file autort-a.ide Using IDE file lovgatel.ide Using IDE file sview-a.ide Using IDE file randex-d.ide Using IDE file blastera.ide Using IDE file rpcsdb-a.ide Using IDE file blasterb.ide Using IDE file donkc.ide Using IDE file graybird.ide Using IDE file nachi-a.ide Using IDE file blasterd.ide Using IDE file sobigf.ide Using IDE file dumaru-a.ide Using IDE file bdoorrq.ide Using IDE file pandem-b.ide Using IDE file agobot-q.ide Using IDE file tzet-a.ide Quick Sweeping 00:01 _headers_ 00:01 textfile0 00:01 textfile1 00:01 document_9446.pif >>> Virus 'W32/Sobig-F' found in file /usr/local/inflex/tmp/inf_08280329268745/unpacked/document_9446.pif 00:01 textfile2 5 files swept in 1 second. 1 virus was discovered. 1 file out of 5 was infected. Please send infected samples to Sophos for analysis. For advice consult www.sophos.com, email support at sophos.com or telephone +44 1235 559933 End of Sweep. File NAME/TYPE Scan Results 08280329268745 from:python-list at python.org to: zelati at cds.unina.itType scanning off. Name scanning off. Text scanning off. END OF MESSAGE. End. . From tjreedy at udel.edu Mon Aug 18 11:51:45 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 18 Aug 2003 11:51:45 -0400 Subject: What's better about Ruby than Python? References: Message-ID: "John Roth" wrote in message news:vk1c89jvdjepa4 at news.supernews.com... > 4. Shortcut syntax for writing self in a method body. If you declare the first param as 's', for instance, then your shortcut is 's.', which is pretty minimal, and hardly enough, it seems to me, to make much fuss over. I like having a clean visual separation between local variables and instance attributes. TJR From scottholmes at sbcglobal.net Tue Aug 5 13:45:26 2003 From: scottholmes at sbcglobal.net (Scott Holmes) Date: Tue, 05 Aug 2003 10:45:26 -0700 Subject: How to determine row position in a list box References: Message-ID: <3F2FED36.8000005@sbcglobal.net> Daniel P. Engel wrote: > > Wouldn't that be sels[0]? > The value in sels[0] is the string I wish to display in a label, not the row number. Actually I've abandoned the attempt to find the row number. I'm now creating a dictionary at the same time the listbox is being populated: while 1: lRec = curs.fetchone() if not lRec: break itm = str(lRec[3]) + ", " + str(lRec[1]) + " " + str(lRec[2]) self.box.insert('end', itm) self.pnmbrs[itm] = str(lRec[0]) The select statement fetches the unique people_nmbr and the person's first middle and last name. The listbox displays the name value, thusly: last_name, first_name middle_name. When a row is selected from the listbox, the selected value is used as a key: def selectionCommand(self): sels = self.box.getcurselection() if len(sels) == 0: print 'No selection' else: print 'Selection:', sels[0] print 'People Number:', self.pnmbrs[sels[0]] If there is a prefered or more efficient way of doing this, I would be grateful to hear of it. -- --------------------------------------------------------------------- Scott Holmes http://sholmes.ws http://pages.sbcglobal.net/scottholmes scottholmes at sbcglobal.net Independent Programmer/Analyst Passport 4GL PHP HTML Composer PostgreSQL Informix 4GL, SQL --------------------------------------------------------------------- There are more things in heaven and earth, Horatio, than are dreamt of in your philosophy --------------------------------------------------------------------- From staschuk at telusplanet.net Thu Aug 21 17:43:29 2003 From: staschuk at telusplanet.net (Steven Taschuk) Date: Thu, 21 Aug 2003 15:43:29 -0600 Subject: ClientCookie bug (followup) In-Reply-To: ; from rmunn@pobox.com on Thu, Aug 21, 2003 at 06:55:52PM +0000 References: <87oeypdh92.fsf@pobox.com> <87k79a25pi.fsf@pobox.com> <84fc4588.0308182207.4c649b93@posting.google.com> <87ada5de3j.fsf@pobox.com> <84fc4588.0308200242.3e74e0a1@posting.google.com> <87smnwh3lp.fsf@pobox.com> Message-ID: <20030821154329.D327@tibia.amotlpaa.bogus> Quoth Robin Munn: [use of "we" in code comments] > [...] I usually think of it as myself > reading through the code with another coder, who is tasked with taking > over code maintenance from me. I'm explaining to him what the code is > intended to do: "So here, we want to search through the list for..." This convention is also typical in mathematical writing. I interpret it much as you do. -- Steven Taschuk "If you've learned anything from what I've said staschuk at telusplanet.net today, you haven't been paying attention." -- "The Power of Ignorance", Chris Gibbs From staschuk at telusplanet.net Tue Aug 5 18:27:22 2003 From: staschuk at telusplanet.net (Steven Taschuk) Date: Tue, 5 Aug 2003 16:27:22 -0600 Subject: Python and cron jobs. In-Reply-To: <7b454334.0308050947.3d1d51fb@posting.google.com>; from faizan@jaredweb.com on Tue, Aug 05, 2003 at 10:47:28AM -0700 References: <7b454334.0308041023.6e688b4d@posting.google.com> <7b454334.0308050947.3d1d51fb@posting.google.com> Message-ID: <20030805162722.A1020@tibia.amotlpaa.bogus> Quoth Fazer: [...] > Actually, I think I will open the crontab file as a file and do the > changes that way because this would also involve in the deletion of > some cronjobs. [...] Note that you can invoke the crontab so as to print out a given user's crontab: crontab -u username -l Using the os.popen family, you can then read the output as a file, modify it, then write it back as the stdin for an invocation of crontab -u username This is perhaps slightly more work than simply manipulating the file in /var/cron/tabs directly; certainly it is less efficient, though I doubt that's much of a concern for this task. The advantage is that it allows for the possibility that the local system has some strange way of storing crontabs, a way which crontab(1) understands but your program should not need to. > [...] I just wish to know how to get the cron deamon to > reload the crontab. Are you certain that it checks for changes or > reloads every minute? No. There's lots of cron implementations, and I certainly haven't used all of them; perhaps some need a SIGHUP to reload, for example. Check your local documentation to be sure, 'man 8 cron' or what have you, and/or just try it as Michael suggested. -- Steven Taschuk staschuk at telusplanet.net "I tried to be pleasant and accommodating, but my head began to hurt from his banality." -- _Seven_ (1996) From usenet at microtonal.co.uk Sun Aug 24 07:18:36 2003 From: usenet at microtonal.co.uk (Graham Breed) Date: Sun, 24 Aug 2003 12:18:36 +0100 Subject: Hosting service with Python support In-Reply-To: <3f489493$0$200$fa0fcedb@lovejoy.zen.co.uk> References: <3f489493$0$200$fa0fcedb@lovejoy.zen.co.uk> Message-ID: BadJake wrote: > Hi > I have just found out the my hosting service includes Python support. > Unfortunately, they make no mention of this on their web site. There are too > few hosting companies that offer Python support so I would like to share > this one with you. You can find out by pointing your brower at > http://www.krellen.com Here's where they mention Python: http://www.krellen.com/hosting/faq.php#cat0_0 Being Red Hat, that really does mean "latest version" does it? Graham From sdhyok at yahoo.com Sat Aug 16 20:05:46 2003 From: sdhyok at yahoo.com (sdhyok) Date: 16 Aug 2003 17:05:46 -0700 Subject: How to shortcut a package path? Message-ID: <420ced91.0308161605.acf6c5a@posting.google.com> Is there any way to create a shortcut for a package path? For instance, if I have the following path structure, dir1/dir2/program.py what should I do if I want to import program with from dir1 import program , not with from dir1.dir2 import program Thanks in advance. Daehyok Shin From __peter__ at web.de Thu Aug 28 05:03:04 2003 From: __peter__ at web.de (Peter Otten) Date: Thu, 28 Aug 2003 11:03:04 +0200 Subject: Script Discussion & Critique References: <3F4D31B1.6080802@hotmail.com> <06eqkv4onjh5m4tcbbqkmh8lscaj5niatp@4ax.com> <3F4D4402.3060209@hotmail.com> Message-ID: hokiegal99 wrote: > Thanks for any ideas, pointers or critique... most of the ideas behind > the script came from the list. Choose variable names that make their intended purpose clear, e.g. searchToken/replaceToken instead of x/y. > search = string.find(data, x) > if search >=1: This is wrong as others have already explained. I recommend: if searchToken in data: # perform replacement (I did it with .find() till yesterday, but no more! I like that Python minimizes the need of artificial indices:-) Factor out reusable code, e.g: def replaceTokenInTree(rootFolder, searchToken, replaceToken, filterFunc=None) def replaceTokenInFile(filename, searchToken, replaceToken, backupFile=None) This will pay off as your scripts grow (or your script grows:-), so make it a habit as soon as possible. Some observations that are not directly code-related: You can change - and possibly corrupt - *many* files in one run of you script. So you might add a confirmation prompt repeating searchToken, replaceToken and the root directory (resolved to an absolute path) and - somewhat more ambitious - a means to generate backups. When replacement fails on one file, e. g. due to access rights, you could catch the exception and prompt the user, if he wants to continue or abort the script. Chances are that there are some files in the tree that you do not want to process, so you should add some basic filtering. The fnmatch module might be helpful. Last but most important: Take time to build a test file tree, and include all special cases you can think of (including those you consider irrelevant) e. g. files starting/ending with search token, zerolength file, file with readonly access. Peter From swenggsri at yahoo.com Mon Aug 18 16:41:53 2003 From: swenggsri at yahoo.com (Sriram Chadalavada) Date: 18 Aug 2003 13:41:53 -0700 Subject: Pmw BLT problems Message-ID: Hello fellow python users, I am trying to use Python Mega widgets and the BLT extension to Tk for my project. Pmw scripts seem to work fine. However, I could not run the BLT examples since BLT was not installed. BLT installation was interesting since while the INSTALL file in the tar ball indicated that the default install directory is /usr/local, even after specifying the prefix directory during 'configure', the files were installed w.r.t /usr directory. Running a HELLO program that makes use of blt graph gave the following error message: Traceback (most recent call last): File "./HelloGraph.py", line 33, in ? g = Pmw.Blt.Graph(master) File "/usr/lib/python2.2/site-packages/Pmw/Pmw_1_2/lib/PmwBlt.py", line 260, in __init__ Tkinter.Widget.__init__(self, master, _graphCommand, cnf, kw) File "/usr/lib/python2.2/lib-tk/Tkinter.py", line 1764, in __init__ self.tk.call( TclError: invalid command name "::blt::graph" A quick search on the group archive suggested that this might be because BLT has not been installed. In my case, that might be 'not properly installed'. Any suggestions on how to get the installation right? Did anyone deal with this kind of problem before? Thanks in advance, Sriram From martin at v.loewis.de Fri Aug 8 17:14:34 2003 From: martin at v.loewis.de (Martin v. =?iso-8859-15?q?L=F6wis?=) Date: 08 Aug 2003 23:14:34 +0200 Subject: Socket Memory Leak References: Message-ID: William Trenker writes: > When I look at the Python patches on Sourceforge I can't see the > patch that fixes problem 783312. This is probably because I don't > understand the process of what happens between the time a fix is > implemented in CVS and the time it shows up as a patch on the patch > list. Can someone enlighten me on this process? The process is the other way 'round. Patches contributed to the SF patch list may, after some consideration, be integrated into the CVS. Changes integrated into the CVS need to be posted to the patches tracker, unless either a) the patch author has no write access to the CVS, or b) the patch author is uncertain as to whether the patch is correct. > Also, when a significant bug like this is identified and fixed, is > this announced on a list somewhere so we can incorporate critical > fixes like this? There is no procedure to do that. Instead, the CVS revisions of the files being changed are recorded in the SF bug report, and the bug report number is recorded in the CVS commit message, and in the CVS version of the Misc/NEWS file. That is the place where you should get a list of all significant changes. > Of course this might all be documented on the Python site and I've > overlooked it. A link to such documentation would be greatly > appreciated. I recommend you take a close look at the CVS. It is all inside. Regards, Martin From aaron at reportlab.com Tue Aug 26 21:56:13 2003 From: aaron at reportlab.com (Aaron Watters) Date: 26 Aug 2003 18:56:13 -0700 Subject: pure Python DB References: Message-ID: <9a6d7d9d.0308261756.5b37cbf4@posting.google.com> Andy Todd wrote in message news:... > Patrick Useldinger wrote:> > Gadfly is lightweight but doesn't support transactions. It is in low > maintenance mode, development is currently not active but the project is > hosted at SourceForge (http://sourceforge.net/projects/gadfly) and any > bug reports and (especially) patches would be more than welcome. Um.. doesn't support transactions? It depends what you mean, I guess. It supports transaction commit and rollback and recovery but not transaction concurrency... (yet) -- Aaron Watters === She's wondering what he'll make for breakfast... He's wondering how long he has to cuddle before he can go home... From staschuk at telusplanet.net Thu Aug 14 17:51:35 2003 From: staschuk at telusplanet.net (Steven Taschuk) Date: Thu, 14 Aug 2003 15:51:35 -0600 Subject: Iterator - what I am missing In-Reply-To: <3f3bde30$0$297$ba620e4c@reader1.news.skynet.be>; from jarausch@skynet.be on Thu, Aug 14, 2003 at 09:08:32PM +0200 References: <3f3bde30$0$297$ba620e4c@reader1.news.skynet.be> Message-ID: <20030814155135.B246@tibia.amotlpaa.bogus> Quoth Helmut Jarausch: > I cannot find out what I miss with my iterator example. > > I have a linked list class Queue which has a 'Head' attribute > and the following > > def __iter__(self): > if self.Head == None: raise StopIteration > return self.Head This method should return an iterator, not a node. A for loop calls .next() on the same object -- the iterator object -- at each iteration; that method is supposed to return successive values on each call. It's as if for x in iterable: mung(x) were iterator = iter(iterable) # get iterator object try: while True: x = iterator.next() # call its .next() method repeatedly mung(x) except StopIteration: pass If you walk through this blurb using an instance of your Queue class for the 'iterable' variable, you'll quickly see how the infinite loop occurs. If you walk through it using class Queue(object): # ... def __iter__(self): return QueueIterator(self.Head) class QueueIterator(object): def __init__(self, firstnode): self.nextnode = firstnode def __iter__(self): return self def next(self): if self.nextnode is None: raise StopIteration() node = self.nextnode self.nextnode = self.nextnode.NNd return node instead, you'll see how what's supposed to happen. In your actual code you'll probably not want to use an explicit QueueIterator class; a generator function, with its implicit iterator object, is simpler here: from __future__ import generators # needed in Python 2.2 class Queue(object): # ... def __iter__(self): node = self.Head while node is not None: yield node node = node.NNd -- Steven Taschuk o- @ staschuk at telusplanet.net 7O ) " ( From ansnum at laposte.net Wed Aug 27 08:19:18 2003 From: ansnum at laposte.net (AnsNum) Date: Wed, 27 Aug 2003 14:19:18 +0200 Subject: mpeg problem with pygame Message-ID: hello, when I start this program, the movie doesn't play smoothly, anybody has an idea ? (I use windowsXP) import pygame from pygame.display import flip from pygame.locals import * pygame.init() screen = pygame.display.set_mode((640,480)) pygame.mixer.quit() movie = pygame.movie.Movie("d://pygame//video3.mpeg") movie.set_display(screen, (0,0)) movie.play() movie.set_volume(1) flip() while 1: if not movie.get_busy(): break -- Henri From jtk at yahoo.com Fri Aug 1 13:13:57 2003 From: jtk at yahoo.com (Jeff Kowalczyk) Date: Fri, 01 Aug 2003 13:13:57 -0400 Subject: list indexing References: Message-ID: > It's just index: >>>> list = ['this', 'is', 'a', 'list'] >>>> for item in list: > print list.index(item), item > 0 this > 1 is > 2 a > 3 list But this only works for single instances, since it finds the first: >>> li = 'this is a list with a repeated word in this list'.split() >>> for item in li: print li.index(item), item ... 0 this 1 is 2 a 3 list 4 with 2 a 6 repeated 7 word 8 in 0 this 3 list I wondered at first if there was a way to do it directly, but I usually ended up making a companion range of indexes to zip(), and now will use enumerate(). Was there a direct method that I never found? From imbosol at aerojockey.com Tue Aug 12 05:09:42 2003 From: imbosol at aerojockey.com (Carl Banks) Date: Tue, 12 Aug 2003 09:09:42 GMT Subject: Py2.3: Feedback on Sets References: Message-ID: Raymond Hettinger wrote: > I've gotten lots of feedback on the itertools module > but have not heard a peep about the new sets module. > > * Are you overjoyed/outraged by the choice of | and & > as set operators (instead of + and *)? I slightly favor | and &. > * Is the support for sets of sets necessary for your work > and, if so, then is the implementation sufficiently > powerful? > > * Is there a compelling need for additional set methods like > Set.powerset() and Set.isdisjoint(s) or are the current > offerings sufficient? I imagine isdisjoint would be useful, although it's easy enough to use bool(s&t). > * Does the performance meet your expectations? > > * Do you care that sets can only contain hashable elements? > > * How about the design constraint that the argument to most > set methods must be another Set (as opposed to any iterable)? > > * Are the docs clear? Can you suggest improvements? Yeah: in the library reference, the table entry for s.union(t) should say "synonym of s|t" instead of repeating the description. This is especially true because it's not clear from a simple glance whether "s.union(t)" goes with "s|t" or "s&t", because it sits right between the two. Better yet, I would change it to a three-column table (operation, synonym, result). > * Are sets helpful in your daily work or does the need arise > only rarely? I haven't used sets yet (or Python 2.3), but I expect to use them a lot. However, I imagine my typical use would be efficient testing for membership. I have maybe half a dozen places where I use a dictionary for that now. -- CARL BANKS "You don't run Microsoft Windows. Microsoft Windows runs you." From logiplex at qwest.net Fri Aug 15 17:09:50 2003 From: logiplex at qwest.net (Cliff Wells) Date: Fri, 15 Aug 2003 14:09:50 -0700 Subject: [wxPython] Updating the status bar? In-Reply-To: References: Message-ID: <1060981790.10907.7.camel@software1.logiplex.internal> On Fri, 2003-08-15 at 13:06, Steve Lamb wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On 11 Aug 2003 05:32:10 GMT, Rob Williscroft wrote: > > So I would guess at: > > > self.MainStatus.Refresh() > > self.MainStatus.Update() > > Finally got around to trying this and no dice. Still does not > update the status bar at all. :/ Try adding a wxYield() after the Update(). The Refresh() probably isn't necessary. Regards, -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 (800) 735-0555 From tim.one at comcast.net Sun Aug 3 20:24:25 2003 From: tim.one at comcast.net (Tim Peters) Date: Sun, 3 Aug 2003 20:24:25 -0400 Subject: Wow: list of immediate subclasses? In-Reply-To: Message-ID: [Roman Suzi] > I wonder why to have __subclasses__() at all... I recall somebody > (Tim Peters?) tolds us that classes are essentially just > dictionaries - everything else is an imagination by OO-brains > and fluffy operations like computing MRO. __subclasses__ aren't > needed for OO to work. What for they really are? Just to have nice way > to know subclasses? Why not to use some external framework for that > task, hooking object manipulation to some routine if necessary? > > I can't find any reference to __subclasses__ in standard library! > (I was looking for __subclasses__ string) Looking for __subclasses__ won't answer it -- that's just Python exposing an internal mechanism for the morbidly curious . Look for uses of update_subclasses() instead, in typeobject.c. At the C level, Python doesn't want to do long-winded MRO searches for every attribute reference for every type implemented in C, so "percolates down" type object slot definitions from parent classes to their children at the time child classes are first created. Then the child class just has to look at its own definitions. This doesn't work, though, when a base class definition inherited by a child class changes in the base class later, or when a new definition appears by magic in the MRO (from the child's POV) before the base class originally inherited from. Since Python allows changing class characteristics at runtime, this happens (albeit not in most peoples' code). In such cases, the freshly-mutated type object's tp_subclasses slot (that's the C spelling of the Python-level __subclasses__) is used to figure out which derived classes need to get their type object slots updated too. In short, __subclasses__ exists to support efficient runtime class mutation at the C level. I view it much more as an accidental detail of the current implementation than as a property of the language (Python would still be Python if tp_subclasses/__subclasses__ didn't exist; CPython would simply be slower (and possibly much slower) for some kinds of code then -- at heart, it's to support an MRO-lookup caching/memoization gimmick). From mpeuser at web.de Wed Aug 13 07:07:19 2003 From: mpeuser at web.de (Michael Peuser) Date: Wed, 13 Aug 2003 13:07:19 +0200 Subject: unsigned int \ long References: Message-ID: Hi Roman, > "Roman Yakovenko" schrieb im Newsbeitrag news:mailman.1060766064.21827.pythonlist at python.org... > 1. Bitwise operations > ~210 | 118 == -129 > I'd like to get 127 ( of course if I work within byte or smth like this ). I think this is a misconception! It makes no sense to use ~X without being aware of something like a "wordlength". You should use (255^X) instead > Today in order to get it I have to write ( ~210 | 118 ) & 0xFF Well..... > 2. Example > def print_selection( some_list, range=(0,-1) ): > lower = max( 0, range[0] ) > upper = min( len( some_list ), unsigned_int( range[1] ) ) > print some_list[lower:upper] I should not consider it good style to interpret -1 as plus infinite... Kindly Michael P. From peter at engcorp.com Wed Aug 27 15:47:14 2003 From: peter at engcorp.com (Peter Hansen) Date: Wed, 27 Aug 2003 15:47:14 -0400 Subject: learning to program References: <3F4CED6E.D04D35D6@engcorp.com> <5bspkv87u1q0v9aupajrrkjuutuh3f5o44@4ax.com> <3F4CF363.CAF6A14E@engcorp.com> <6b2qkv4nf549o8clg3bagphd02f92dadub@4ax.com> Message-ID: <3F4D0AC2.EE79D7E4@engcorp.com> Rich wrote: > > On Wed, 27 Aug 2003 14:07:31 -0400, Peter Hansen > wrote: > > >Rich wrote: > >> > >> This is the only post I am able to see, sorry about re posting. I > >> thought if I changed the subject heading I might be able to see the > >> post. > > > >You should be able to see the replies that you missed via Google Groups, > >as soon as they are indexed and on the web: > How long does it usually take to post on Google? In my experience, usually quite a few hours (maybe four or more?). Right now I can see posts there which I read only a short time before seeing yours, so that estimate feels about right. (By the way, it would be helpful if, when you quote material in a post to which you're replying, if you used whitespace to separate your own text from the quoted material. I almost didn't see your message at all, thinking you'd accidentally posted an empty reply. Thanks. :-) -Peter From mike at nospam.com Sun Aug 3 11:09:23 2003 From: mike at nospam.com (Mike) Date: Sun, 3 Aug 2003 08:09:23 -0700 Subject: Python speed vs csharp References: <1ivz3gto4e3ty$.18j3vv8ame6w6.dlg@40tude.net> <3F2C2617.B36BCA2F@jandecaluwe.com> Message-ID: <1usgd54h46n5y$.13cpypr9dtdg9.dlg@40tude.net> On Sat, 02 Aug 2003 22:59:03 +0200, Jan Decaluwe wrote: > Mike wrote: >> > >> improvements. Part of the problem with the full simulation is that psyco >> gobbles up all my available memory if I use psyco.full(), so I've been >> experimenting with psyco.bind(). > > What about psyco.profile() ? I understood from Armin Rigo that's > the preferred interface. Since the slow portion of code is well known, I didn't bother to try profile(). However... Since you mentioned it, I gave it a try, and there's no difference in the results between using psyco.bind() on the slow routines and psyco.profile() on the entire simulation. However, the difference in effort, and corresponding reduction in liklihood of programmer error, is enough to justify using the single psyco.profile() line vs multiple psyco.bind() lines. Thanks, -- Mike -- From junk at realityx.net Thu Aug 21 07:22:59 2003 From: junk at realityx.net (junk spam) Date: Thu, 21 Aug 2003 13:22:59 +0200 Subject: automated response Message-ID: <10308211322.AA00358@realityx.net> Please stop spamming.. This is an automated reply.. From aleaxit at yahoo.com Wed Aug 6 05:05:00 2003 From: aleaxit at yahoo.com (Alex Martelli) Date: Wed, 6 Aug 2003 11:05:00 +0200 Subject: Question about import In-Reply-To: References: Message-ID: <200308061105.00701.aleaxit@yahoo.com> On Wednesday 06 August 2003 02:18 am, Mark Daley wrote: > The only exception I would consider to this would be Tkinter. It seems > like every last book on this always has the user import from Tkinter, not > just import Tkinter itself. Is this just by convention, or is there a > perfectly good explanation for this? I think it's mostly a convention. In my Tkinter programs I use import Tkinter as Tk or the like, and thus avoid e.g. accidents with the huge number of constants such as DISABLED and the like which Tkinter exports. But even in the Nutshell Tkinter examples I did use a few "from" (as well as mostly "import") statements, admittedly. Alex From tzot at sil-tec.gr Wed Aug 6 15:06:09 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Wed, 06 Aug 2003 22:06:09 +0300 Subject: Script References: Message-ID: On Mon, 04 Aug 2003 16:11:21 +0200, rumours say that Gerhard H?ring might have written: >zze-Support activite PCL RAMSI A ext DvSI/SIReS/LAN wrote: >> And where could I find this program please? > >There's a wrapper for Python in the Python source tree, though that you >could adapt. Download the Python sources and search for a file called >setuid-prog.c. This is indeed a thought-out setuid program (the one in dist/src/Misc). Just to add my two eurocents, though, here's the smallest, most-insecure and dirtiest setuid C program I have used for quite a few years: /* user.c */ int main(int argc, char *argv[]) { return execvp (argv[1], argv+1); } (Hint: it returns only if execvp fails) Compile it, strip it, chown root, chmod u+s, use it as user ... -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From llothar at web.de Mon Aug 18 15:34:09 2003 From: llothar at web.de (Lothar Scholz) Date: 18 Aug 2003 12:34:09 -0700 Subject: Python Debugger Message-ID: <6ee58e07.0308181134.383a69e7@posting.google.com> Is there any python debugger that can 1) be used remotely 2) can handle multiple threads I checked Eric, IDLE and Wing-IDE. None of them can do this. Any other recommendations? From ta-meyer at ihug.co.nz Tue Aug 26 22:45:55 2003 From: ta-meyer at ihug.co.nz (Tony Meyer) Date: Wed, 27 Aug 2003 14:45:55 +1200 Subject: Raw Input Question In-Reply-To: <1ED4ECF91CDED24C8D012BCF2B034F130306422B@its-xchg4.massey.ac.nz> Message-ID: <1ED4ECF91CDED24C8D012BCF2B034F130212AD78@its-xchg4.massey.ac.nz> > XXX = raw_input("1. Enter the string that you'd like to find: ") > y = raw_input("2. Enter the string that you'd like to replace > XXX with: ") y = raw_input("2. Enter the string that you'd like to replace %s with: " % (XXX,)) =Tony Meyer From donn at drizzle.com Fri Aug 15 23:29:49 2003 From: donn at drizzle.com (Donn Cave) Date: Sat, 16 Aug 2003 03:29:49 -0000 Subject: Python signal delivery under BSD 4.4 References: <7h3isp04bzm.fsf@pc150.maths.bris.ac.uk> Message-ID: <1061004588.144247@yasure> Quoth "Elf M. Sternberg" : | ... But, fortunately, we're | developing a single-OS appliance and don't really care about | cross-platform compatibility, so I worked with the FreeBSD 4.4 "model" | of forking from multithreaded applications. It's fortunate that the | next call is an exec(); I'd hate to have to manage a forked copy of the | process with that one thread... So, you resolved the problem and the spawnv child process can now receive signals? Did you use sigprocmask() to clear the signal mask? What is the FreeBSD 4.4 model of forking from multithreaded applications? (And is it the same as the FreeBSD 4.7 model, 5.1, etc.?) Donn Cave, donn at drizzle.com From falted at openlc.org Fri Aug 29 14:33:45 2003 From: falted at openlc.org (Francesc Alted) Date: Fri, 29 Aug 2003 18:33:45 +0000 (UTC) Subject: Hunting a memory leak References: <7h3oey84qho.fsf@pc150.maths.bris.ac.uk> Message-ID: [Ooops. Something went wrong with my newsreader config ;-)] Thanks for the responses!. I started by fetching the TrackRefs() class from http://cvs.zope.org/Zope3/test.py and pasted it in my local copy of unittest.py. Then, I've modified the TestCase.__call__ try: block from the original: try: testMethod() ok = 1 to read: try: rc1 = rc2 = None #Pre-heating for i in xrange(10): testMethod() gc.collect() rc1 = sys.gettotalrefcount() track = TrackRefs() # Second (first "valid") loop for i in xrange(10): testMethod() gc.collect() rc2 = sys.gettotalrefcount() print "First output of TrackRefs:" track.update() print >>sys.stderr, "%5d %s.%s.%s()" % (rc2-rc1, testMethod.__module__, testMethod.im_class.__name__, testMethod.im_func.__name__) # Third loop for i in xrange(10): testMethod() gc.collect() rc3 = sys.gettotalrefcount() print "Second output of TrackRefs:" track.update() print >>sys.stderr, "%5d %s.%s.%s()" % (rc3-rc2, testMethod.__module__, testMethod.im_class.__name__, testMethod.im_func.__name__) ok = 1 However, I'm not sure if I have made a good implementation. My understanding is that the first loop is for pre-heating (to avoid false count-refs due to cache issues and so). The second loop should already give good count references and, thereby, I've made a call to track.update(). Finally, I wanted to re-check the results of the second loop with a third one. Therefore, I expected more or less the same results in second and third loops. But... the results are different!. Following are the results of this run: $ python2.3 widetree3.py First output of TrackRefs: 13032 85335 8969 38402 1761 11931 1215 4871 1180 5189 841 4897 516 2781 331 3597 295 1180 236 944 145 1092 107 734 94 440 86 1967 84 336 75 306 73 312 70 280 52 364 42 435 41 164 25 187 24 173 9 44 7 28 6 25 4 20 3 31 3 23 3 12 2 41 2 30 2 9 2 8 2 8 1 2371 1 16 1 12 1 11 1 10 1 9 1 8 1 7 1 6 1 6 1 6 1 5 1 5 1 5 1 4 1 4 1 4 1 4 7 __main__.WideTreeTestCase.test00_Leafs() Second output of TrackRefs: 37 218 0 74 212 __main__.WideTreeTestCase.test00_Leafs() . ---------------------------------------------------------------------- Ran 1 test in 0.689s OK [21397 refs] $ As you can see, for the second loop (first output of TrackRefs), a lot of objects appear, but after the third loop (second output of TrackRefs), much less appear (only objects of type "int" and "type"). Besides, the increment of the total references for the second loop is only 7 while for the third loop is 212. Finally, to add even more confusion, these numbers are *totally* independent of the number of iterations I put in the loops. You see 10 in the code, but you can try with 100 (in one or all the loops) and you get exactly the same figures. I definitely think that I have made a bad implementation of the try: code block, but I can't figure out what's going wrong. I would appreciate some ideas. Francesc Alted From tzot at sil-tec.gr Fri Aug 22 21:04:37 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Sat, 23 Aug 2003 04:04:37 +0300 Subject: error compiling Python 2.3 References: Message-ID: On Fri, 22 Aug 2003 17:51:56 -0400, rumours say that "val" might have written: >Hi the Gurus, > i'm trying to compile Python 2.3 remotely >(telnet access). It is Cobalt. Linux 2. mips. gcc 2.7.2. Cobalt? Cobalt?? Whatever... Try reporting things from a little earlier; you might know better than what I (or anybody else) might assume, but we can't be sure. Specify URL of the .tgz file you downloaded. Copy-paste the commands you entered (skip obviously dumb output, if for example you use the v flag when extracting files) and their output. The "This file was extended by..." does not sound very familiar, but it's possible I never noticed it in configure's output. -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From vanevery at 3DProgrammer.com Tue Aug 19 02:25:13 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Mon, 18 Aug 2003 23:25:13 -0700 Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> Message-ID: Alexander Schmolck wrote: > "Brandon J. Van Every" writes: > >> Alexander Schmolck wrote: >>> >>> Would you still have a problem with macros in python if utilizing >>> them required some obvious and explicit mechanism (say a >>> 'use_custom_syntax' statement right at the beginning of a module >>> that wants to use macros), so that their use could easily be >>> controlled by e.g. project managers? >> >> Yes you would. In open source communities, you'd get different >> philosophical camps, and people in one camp would embed >> 'use_custom_syntax' in some *.h file (yeah yeah I'm a C++ >> programmer) that all the other *.h files use. > > In the proposed scheme every module that wants to use custom syntax > has to say so, period. So there is no silent infestation (these > syntaxes can't be stealthily exported). I wsan't talking about stealth, I was talking about developmental inertia. The least common denominator is functionality turned ON in some root *.h file, and everyone else inherits the functionality. Are you saying that modules in Python don't inherit? If you don't want the functionality to end up being "always ON" by faits accompli, then you must ensure that functionality is irrevocably, "always OFF." In other words, don't provide the functionality. > It would be > easy (from a technical perspective) for project managers (open source > or otherwise) to only allow certain, particularly trusted programers > to create such modules or ban them outright. >From a technical perspective. From a productivity, political, or business perspective, you are asking the moon. People are going to do what works. What works, is functionality turned ON at the least common denominator. Nobody wants to chase the ON/OFF test issues. Nobody's going to change code that was designed monolithically ON to something compartmentalized ON/OFF. > Just like you wouldn't allow every second rate programmer to write the > system-critical libraries everything is built upon, you wouldn't > allow just about anybody to create their own mini-languages without a > need. Man, this isn't very real world as far as how sprawling projects evolve! -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From gherron at islandtraining.com Wed Aug 20 02:09:15 2003 From: gherron at islandtraining.com (Gary Herron) Date: Tue, 19 Aug 2003 23:09:15 -0700 Subject: Float + min/max? In-Reply-To: <005d01c366be$22a146c0$9200a8c0@PowerLoom> References: <005d01c366be$22a146c0$9200a8c0@PowerLoom> Message-ID: <200308192309.15222.gherron@islandtraining.com> On Tuesday 19 August 2003 06:55 pm, Shu-Hsien Sheu wrote: > Hi, > > I am new to Python, and just wrote a small program to generate the maximum > number of the cartisian coordinates among all atoms in a given molecule. > However, I found the float function, if combined with max function, to be > kind of confusing. It would give a number with uneccessary decimals from > nowhere. > > Not converting to float: > > x = [] > for i in (0, length-2): > slines[i] = lines[i].split() > if slines[i][0] == "ATOM": > x.append(slines[i][6]) > > print "xmax = " + max(x) + " " + "xmin = " + min(x) > > Output: > xmax = 90.179 xmin = 64.112 > > > Converting to float numbers: > > x = [] > for i in (0, length-2): > slines[i] = lines[i].split() > if slines[i][0] == "ATOM": > x.append( float(slines[i][6]) ) > > print "xmax = " + max(x) + " " + "xmin = " + min(x) > > Output: > xmax = 90.179000000000002 xmin = 64.111999999999995 > > > The original data file apparantly does not have those decimals. May I ask > how does it happend? Thank! > > -shuhsien This is a *feature* of all floating point numbers in any language on any computer. See the following URL's for more information. >From the FAQ: http://www.python.org/cgi-bin/faqw.py?req=all#4.98 and a manual page: http://www.python.org/doc/current/tut/node14.html The solutions: Learn to life with floating point numbers and their approximate representation on any computer, or explicitly control the output format like this: >>> t = 1.0/3.0 >>> print t 0.333333333333 >>> print '%6.2f' % t 0.33 >>> Gary Herron From mhammond at skippinet.com.au Wed Aug 13 19:01:00 2003 From: mhammond at skippinet.com.au (Mark Hammond) Date: Thu, 14 Aug 2003 09:01:00 +1000 Subject: COM :: VARIANT -eek In-Reply-To: <5f5c82ec.0308130542.6857fe74@posting.google.com> References: <5f5c82ec.0308110207.1d42251@posting.google.com> <5f5c82ec.0308130542.6857fe74@posting.google.com> Message-ID: Matt Smith wrote: > Mark Hammond wrote in message news:... > My problem is now this, when i go to makepy tool in pythonwin, it does > not see/recognise the type library file I want it to convert. Is there > anyway to add the file to the list of .tlb files it does does? These type libraries are in the registry. You may be able to pass the filename on the commandline to makepy. > p.s. How do I include the generated makepy file into my code ? In generaly, you just need to generate the file and do nothing else. At runtime, Python will see these generated files and automatically use them. I don't know how that will go with your type library though. Mark From skip at pobox.com Fri Aug 22 11:46:34 2003 From: skip at pobox.com (Skip Montanaro) Date: Fri, 22 Aug 2003 10:46:34 -0500 Subject: What has been going on? In-Reply-To: <1322.68.73.70.2.1061518904.squirrel@webmail.iserv.net> References: <1768.68.75.128.246.1061412809.squirrel@webmail.iserv.net> <1322.68.73.70.2.1061518904.squirrel@webmail.iserv.net> Message-ID: <16198.15066.34252.742758@montanaro.dyndns.org> >> Who else has been getting messages returned that you didnt send. Who hasn't? The "virus alert" messages are worse than the viruses themselves. Skip From falted at openlc.org Fri Aug 29 14:06:30 2003 From: falted at openlc.org (Francesc Alted) Date: Fri, 29 Aug 2003 18:06:30 +0000 (UTC) Subject: Hunting a memory leak References: <7h3oey84qho.fsf@pc150.maths.bris.ac.uk> Message-ID: On 2003-08-29, Michael Hudson wrote: > Debian User writes: > >> I'm trying to discover a memory leak on a program of mine. I've taken >> several approaches, but the leak still resists to appear. >> >> First of all, I've tried to use the garbage collector to look for >> uncollectable objects. > > [snip] > >> Then I've taken an approach that I've seen in python developers list >> contributed by Walter D?rwald, that basically consists in creating a >> debug version of python, create a unitest with the leaking code, and >> modify the unittest.py to extract the increment of total reference >> counting in that code (see >> http://aspn.activestate.com/ASPN/Mail/Message/python-dev/1770868). > > Well, somewhere in that same thread are various references to a > TrackRefs class. Have you tried using that? It should tell you what > type of object is leaking, which is a good start. > >> With that, I see that my reference count grows by one each time the >> test execute. But the problem is: is there some way to look at the >> object (or make a memory dump) that is leaking?. > > See above :-) > >> I've used valgrind (http://developer.kde.org/~sewardj/) to see if it >> could detect the leak. In fact, it detects a bunch of them, but I am >> afraid that they are not related with the leak I'm looking for. I am >> saying that because, when I loop over my leaky code, valgrind always >> report the same amount of leaky memory, independently of the number of >> iterations (while top is telling me that memory use is growing!). > > There are various things (interned strings, f'ex) that always tend to > be alive at the end of a Python program: these are only leaks in a > very warped sense. > > I don't know if there's a way to get vaglrind to tell you what's > allocated but not deallocated between two arbitrary points of program > execution. > >> My code uses extension modules in C, so I am afraid this does not >> contribute to alleviate the problem. > > Well, in all likelyhood, the bug is IN the C extension module. Have > you tried stepping through the code in a debugger? Sometime's that's > a good way of spotting a logic error. > >> I am sorry, but I cannot be more explicit about the code because it >> is quite complex (it is the PyTables package, http://pytables.sf.net), >> and I was unable to make a simple example to be published >> here. However, if anyone is tempted to have a look at the code, you >> can download it from >> (http://sourceforge.net/project/showfiles.php?group_id=63486). I am >> attaching a unittest that exposes the leak. >> >> I am a bit desperate. Any hint? > > Not really. Try using TrackRefs. > > Cheers, > mwh > From PoulsenL at capanalysis.com Thu Aug 14 09:39:30 2003 From: PoulsenL at capanalysis.com (PoulsenL at capanalysis.com) Date: Thu, 14 Aug 2003 09:39:30 -0400 Subject: Converting foreign numeric conventions to US Message-ID: <72F73B808A78D511A73600034771D9FF718663@dc_exchange2.howrey.com> I have a number of text fields with different ways of exressing currency. Examples: 1 512,3 M 0.214,0 m 1 123 k 1,234,567 1.235.458,90 1,234,324 m (Where in this case m is to be conveyed as k. My only check is to look at the final number and adjust by /1000 if greater than say 1 billion) 12,456 M [Tab] 67,897 k (where these numbers represent two different scenarios) 1) [Tab] 0.456,9 M [CR] 2) [Tab] 45.879,0 M (where these numbers represent two different scenarios) plus a few other creative ways to express currency. I have written a re that covers each case and, using matched groups, puts things back together using the US convention but I was hoping for a cleaner more pythonic (read: more readable) solution. Thanks in advance, Loren -------------------------------------------------------------------------------------------------------------------- This email and any attachments contain information from CapAnalysis, LLC, which may be confidential and/or privileged. The information is intended to be for the use of the individual or entity named on this email. If you are not the intended recipient, be aware that any disclosure, copying, distribution or use of the contents of this email is prohibited. If you receive this email in error, please notify us by reply email immediately so that we can arrange for the retrieval of the original documents at no cost to you. From mertz at gnosis.cx Mon Aug 18 14:57:30 2003 From: mertz at gnosis.cx (Lulu of the Lotus-Eaters) Date: Mon, 18 Aug 2003 14:57:30 -0400 Subject: What's better about Ruby than Python? References: <38ec68a6.0308172319.431a4fde@posting.google.com> Message-ID: The second surest sign that a post is a troll is if the author includes: |> This is not a troll. The first surest sign that a post is a troll is if the author is: |"Brandon J. Van Every" From aleaxit at yahoo.com Tue Aug 19 07:57:45 2003 From: aleaxit at yahoo.com (Alex Martelli) Date: Tue, 19 Aug 2003 13:57:45 +0200 Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> <87fzjywpjs.fsf@pobox.com> Message-ID: John J. Lee wrote: ... > I'd never noticed that. Greg Ewing has pointed out a similar trivial > wart: brackets and backslashes to get multiple-line statements are > superfluous in Python -- you could just as well have had: > > for thing in things: > some_incredibly_long_name_so_that_i_can_reach_the_end_of_this = > line > > where the indentation of 'line' indicates line continuation. I see somebody else already indicated why this isn't so. > The differences between Ruby and Python are, in the end, about as far > from significant as it's possible to be (near as I can tell from Yes, they're extremely similar languages. >> Ruby does have some advantages in elementary semantics -- for >> example, the removal of Python's "lists vs tuples" exceedingly >> subtle distinction. > > You may be right there. Guido's comment that tuples are mostly > mini-objects did clarify this for me, though. Oh, I'm quite "clear" on the issue, I just think it's a design error to have tuples in Python, that's all (rather than just an immutable version of lists for hashing purposes, for example). >> But mostly the score (as I keep it, with >> simplicity a big plus and subtle, clever distinctions a notable >> minus) is against Ruby (e.g., having both closed and half-open > > In the end, though, don't you agree that any such judgement is, from > the pragmatic point of view, pointless once you realise how similar > the two languages are? No, I entirely disagree. I do have to choose one language or the other for each given project; I do have to choose which language to recommend to somebody wanting to learn a new one; etc, etc. > If somebody sneakily switched Python and Ruby > in the middle of the night (so that suddenly many more people use > Ruby, and much more code was written in Ruby than in Python), you'd > stick with Ruby, wouldn't you? Non-linguistic considerations such as the above may also have their weight, in some case. But they're not huge ones, either. >> about undistinguishable to anybody and interchangeable in any > > *in*distinguishable. Ha! I found a bug. You're wrong, see e.g. http://dict.die.net/undistinguishable/ : the spellings with the initial "u" and "i" are just synonyms. >> If I had to use Ruby for such a large application, I would >> try to rely on coding-style restrictions, lots of tests (to >> be rerun whenever ANYTHING changes -- even what should be >> totally unrelated...), and the like, to prohibit use of this >> language feature. But NOT having the feature in the first >> place is even better, in my opinion -- just as Python itself > [...] > > I mostly agree, but I think you could be accused of spreading FUD > about this. Does anybody *really* choose to alter string-comparison > semantics under everybody else's nose in Ruby?? That would be like As I see others indicated in responses to you, this is highlighted and recommended in introductory texts. So why shouldn't many users apply such "big guns"? > doing > > import some_module > > def evil_replacement_function(): return blah() > > some_module.important_function = evil_replacement_function > > > in Python, wouldn't it? And hopefully this WILL be deprecated in 2.4 (pity that there just was not enough time and consensus to do it in 2.3, but the BDFL really liked the concept). Still, the Python usage you mention is LESS problematic, in that the influence on some_module is very explicit -- while altering Object (or whatever) in Ruby is a way to IMPLICITLY AND HIDDENLY influence EVERY other module. It's a *covert* channel -- a disaster, in large applications. Thus, the direct Python equivalent might be import __builtins__ __builtins__.len = someotherfunction and THAT usage is very specifically warned against e.g. in "Python in a Nutshell" -- you CAN do it but SHOULDN'T (again, one can hope to eventually see it "officially" deprecated...!). Alex From bobx at linuxmail.org Fri Aug 1 12:55:33 2003 From: bobx at linuxmail.org (Bob) Date: 1 Aug 2003 09:55:33 -0700 Subject: Problem with Unzipping/Installing Python-2.3.exe References: Message-ID: <1001ff04.0308010855.7b97c959@posting.google.com> You just double-click on the EXE file to start the installation. From gh at ghaering.de Sat Aug 2 15:51:34 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Sat, 02 Aug 2003 21:51:34 +0200 Subject: very newbie question In-Reply-To: References: Message-ID: <3F2C1646.7090701@ghaering.de> Agent Mulder wrote: > Hi group, > > I wonder if I can do Windows programming > in python. I work with c++ now and do the > Windows part raw. It's difficult to get my app > over 150K (need some heavy inlining, that's all). > Does python support nitty-gritty Windows- > programming? The win32 extensions have support for a lot of the win32 API. Your app's download size will be considerably larger, however, if you always distribute the full Python interpreter and win32 extensions with your app. But 1) Download size is not very important 2) If you're really concerned about download size I have a project named "PyhtonRuntime" in planning/proof-of-concept stage. The point of this is that if you have n apps that depend on Python the Python runtime will only be downloaded once. It also includes a dead simple package system and it's win32 only. -- Gerhard From adalke at mindspring.com Fri Aug 8 04:36:42 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Fri, 8 Aug 2003 02:36:42 -0600 Subject: random changes References: Message-ID: dan: > Tried it -- something's different, see my post about this As others pointed out, it should work. Could you repeat the test and show us what "different" means? Glad to hear that 'from oldrandom import random' worked at least for the interim. Andrew dalke at dalkescientific.com From fawcett at teksavvy.com Sat Aug 16 02:04:51 2003 From: fawcett at teksavvy.com (Graham Fawcett) Date: Sat, 16 Aug 2003 02:04:51 -0400 Subject: How remove Tcl/Tk fom py2exe distribution? In-Reply-To: References: Message-ID: <3F3DC983.8010504@teksavvy.com> Michael Peuser wrote: >Hi, >I should like to make a distribution (using Tkinter), with standard DLLs >removed. > >pythonXX.dll is no problem. > >tcl und tk, which make the mass of mega bytes, cannot be removed because >_tkinter.pyd seems to expect them in the same directory > >(Question 1) Is there a configration or path setting in py2exe/distutils I >have overlooked? > >O.k. In fact I do not want to have _tkinter.dll either because it belongs to >standard distribution >The command line option --exclude Tkinter however leads to an error message >when running the exe - this could have been expected however ;-) > > It's a bit unclear, Michael, what you're trying to accomplish. On the one hand, you're using py2exe to deploy your application, which suggests that you don't expect your users to have a Python distribution on their computers. On the other hand, you're looking to deploy a Tkinter app, but without any tcl/tk files, because they "belong to the standard distribution", suggesting that you *do* expect your users to have a Python distribution. If you can assume that your clients have a standard distribution on their machines, don't use py2exe. It's the wrong tool for the job. In case I'm missing something: you could always, as part of your build, just delete files from the py2exe-generated build directory. For example, at the end of your setup.py script, add some lines to delete the tk/tcl files from your build path. I've used this "strategy" sometimes when building py2exe apps that use the Python Imaging Library. (PIL has tcl/tk import dependencies, but doesn't actually need tcl/tk for the majority of its functions.) -- Graham From pwatson at knightsbridge.com Thu Aug 21 17:34:16 2003 From: pwatson at knightsbridge.com (Paul Watson) Date: Thu, 21 Aug 2003 16:34:16 -0500 Subject: max length of a python program References: <1ed07caf.0308210513.6556978a@posting.google.com> Message-ID: <3f453ad6$1_1@themost.net> "Lawrence Oluyede" wrote in message news:bi2lbm$3v6fr$1 at ID-128383.news.uni-berlin.de... > Ragu wrote: > > > Is there a limit to the # of lines that can be in a Python program? > > No AFAIK. > The only limitation is the common sense, nobody wants to drown into comments > :) > > -- > Lawrence "Rhymes" Oluyede > http://loluyede.blogspot.com > rhymes at NOSPAMmyself.com Probably no fear of drowning in comments. It seems that many peole who write seemingly excesslively long source code files do not want to waste disk space or processing time on something so useless as comments. From irmen at -NOSPAM-REMOVETHIS-xs4all.nl Mon Aug 4 14:11:03 2003 From: irmen at -NOSPAM-REMOVETHIS-xs4all.nl (Irmen de Jong) Date: Mon, 04 Aug 2003 20:11:03 +0200 Subject: Passing a string argument by reference In-Reply-To: References: <3f2d728a$0$49117$e4fe514c@news.xs4all.nl> Message-ID: <3f2ea1b5$0$49117$e4fe514c@news.xs4all.nl> Andrew Chalk wrote: > Thanks. You guessed correctly about what I am trying to do although I think > the syntax is: > > self.txtCIF = self.form.getvalue('txtCIF', self.txtCIF) Please don't top-post. Anyway it looks like form is actually a FieldStorage object from the cgi module, am I right? It would have helped (a bit) if you pointed that out earlier. But, never mind, it works now! Glad to be able to help you out. --Irmen From max at alcyone.com Mon Aug 18 15:04:03 2003 From: max at alcyone.com (Erik Max Francis) Date: Mon, 18 Aug 2003 12:04:03 -0700 Subject: What's better about Ruby than Python? References: Message-ID: <3F412323.F2938E1B@alcyone.com> "Brandon J. Van Every" wrote: > Why do you assume that I'm asking these questions in order to > understand how > to program in either? I want to know what people's *perceptions* are. > Subscribe to marketing-python if you want to puzzle me out more. Why do you need to understand _other_ peoples' perceptions, general marketing trends, and Python marketshare in order to learn it? You've already evidently (from your post here and in other groups recently) decided that you're going to go with Python -- at least that's what you claim, I'm not entirely convinced -- so why aren't you learning the language instead of all these other irrelevant things? If you've truly decided that you're going to use Python, why aren't you learning the _language_ now -- something you've been putting off for years -- instead of hunting down all these red herrings? -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ Principles have no real force except when one is well fed. \__/ Mark Twain From irmen at -NOSPAM-REMOVETHIS-xs4all.nl Mon Aug 4 14:06:26 2003 From: irmen at -NOSPAM-REMOVETHIS-xs4all.nl (Irmen de Jong) Date: Mon, 04 Aug 2003 20:06:26 +0200 Subject: ANN: Snakelets 1.1 (simple-to-use web app server with dynamic pages) Message-ID: <3f2ea0a0$0$49110$e4fe514c@news.xs4all.nl> I'm happy to say that Snakelets 1.1 is now available. Snakelets is a simple Python web application server, mainly for educational purposes. This project provides a threaded web server, Ypages (HTML+Python language, similar to Java's JSPs) and Snakelets: code-centric page request handlers (similar to Java's Servlets). Before you all rightfully scream "not another Python web server and HTML- language" let me say that Snakelet's focus is on understanding the way dynamic web sites are created (the code is very compact and easy to understand), and make this process as easy as possible. The actual server and Ypage-compiler code is less than 2,000 lines. The full download includes a few example web-applications: - mp3 indexer and streamer - shop - server/webapp management tool Snakelets is not meant to be a true platform to develop applications on. It is meant to show how a web application server might work. I certainly learned a lot from creating it. You can download it from http://snakelets.sourceforge.net (go to the SF project site, and then the file section). Snakelets is released under the open-source MIT Software license. --Irmen de Jong From usenet at dwall.fastmail.fm Tue Aug 19 10:14:34 2003 From: usenet at dwall.fastmail.fm (David K. Wall) Date: Tue, 19 Aug 2003 14:14:34 -0000 Subject: python for non-programmers tutorial? References: Message-ID: Anthony Baxter wrote: > I'm writing a half-day tutorial at work for the non-programmer > techies (network engineers, database admins, sysadmins, that sort > of thing) and was wondering if anyone else has already done this > and made their materials available? I plan to put my slides up on > the web after they're done... Here are a couple of tutorials I've bookmarked. http://www.ibiblio.org/obp/thinkCSpy/ http://www.freenetpages.co.uk/hp/alan.gauld/ I can't judge the quality, because I don't really program with Python. I'm tinkering with Python in my spare time just to be able to use another language, and see how things are done differently with Python. -- David Wall From P.Schnizer at nospam.gsi.de Tue Aug 5 03:36:57 2003 From: P.Schnizer at nospam.gsi.de (Pierre Schnizer) Date: 05 Aug 2003 09:36:57 +0200 Subject: SCALAPACK and PBLAS in Python References: Message-ID: <87smog4kti.fsf@smtp.gsi.de> "Vicente Galiano" writes: > Hi everybody, > > > I'm searching differents tools for Python programming using parallelism > tools...., I've seen PyPar, PyMPI an d Scientific Python, but I'm > lookingo for implementations in python of SCALAPACK, on the other > hand,.... How can I implement PBLAS and SCALAPACK callings in python?? > ,if I make a library in C, it's posibble run scalapack and the MPI > proccess that=92s runs under it... > As these routines as written in Fortran, try f2py. It will also write the C interface and array size checkers for you. It is available at: http://cens.ioc.ee/projects/f2py2e/ The scipy project (http://www.scipy.org) uses f2py to generate its wrappers for blas and lapack. Have a look in their tree e.g: scipy/Lib/linalg/flapack.pyf scipy/Lib/linalg/generic_fblas1.pyf Best Regards Pierre -- Remove the nospam for direct reply From adalke at mindspring.com Thu Aug 21 14:51:32 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Thu, 21 Aug 2003 18:51:32 GMT Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> <6dj2kv8ugkieehs7guh786cl40o5lj6mcs@4ax.com> <599a6555.0308202108.397bb1a0@posting.google.com> <599a6555.0308210631.441f76cd@posting.google.com> Message-ID: Olivier Drolet: > Really cute intuition pump you've got there, Alex! :-) Err, it was me, no? > Macros don't require that you change variable names, just the syntax. > Macros in Python would then not be equivalent to new words, but new > constructs. And yes, you need to know their meaning, but is this > effort greater than managing without them? Have you or any opponents > of macros on this news group never seen a context in which the > advantages of macros outweigh their overhead? Sure. Having macros would have let people experiment with generators without tweaking the core language. Would have let people implement their own metaclass mechanisms instead of waiting until they were added to the C code. The complaint has never been that there is no context for which macros cannot provide the better solution. I think this track of the discussion will go no further. Let's assume that I am convinced that not only are macros the best thing since chocolate but that it should be added to Python. Following Aahz's suggestion -- what would a Python-with-macros look like? Andrew dalke at dalkescientific.com From robin at jessikat.fsnet.co.uk Sun Aug 10 04:40:14 2003 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Sun, 10 Aug 2003 09:40:14 +0100 Subject: PMW 0.8.5 vs Python 2.3 References: <3F35FF75.C01C5591@alcyone.com> Message-ID: In article <3F35FF75.C01C5591 at alcyone.com>, Erik Max Francis writes >Robin Becker wrote: > >> I'm getting the following error when I attempt to run an app with >> Python 2.3. I suppose this was silently ignored under 2.2. With >> debugging I see that s==0 in never min people, I upgraded to Pmw 1.2 and things are now fine. -- Robin Becker From max at alcyone.com Tue Aug 12 03:26:56 2003 From: max at alcyone.com (Erik Max Francis) Date: Tue, 12 Aug 2003 00:26:56 -0700 Subject: Python vs. C# References: <2259b0e2.0308100616.55b651ca@posting.google.com> <3f36af20@shknews01> <0b0hjv4q40mdf3msnur9q4bcih3tqb8iq3@4ax.com> Message-ID: <3F3896C0.C0A9FA10@alcyone.com> Doug Tolton wrote: > It's amazing that you pass yourself off as an expert in C# when you > are just reading the propaganda still. Come back and have this > discussion when you have actual experience in C#. By the way, in case it wasn't obvious, there's no evidence he knows anything about Python, either. And with his continuing admissions that he doesn't know Standard C++ -- and seems staunchly unwilling to learn anything about it -- we arrive at the trifecta. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ I will always remember / This moment \__/ Sade From wsdng at onlinehome.de Wed Aug 27 16:00:25 2003 From: wsdng at onlinehome.de (=?ISO-8859-1?Q?Sascha_D=F6rdelmann?=) Date: 27 Aug 2003 13:00:25 -0700 Subject: Aspect oriented Everything? References: <32cc321c.0308221316.2f5793ac@posting.google.com> Message-ID: letterbox1001 at hotmail.com (New_aspect) wrote: > What I want to know is,if anybody on a > commercial scale is using AOSD to develop commercial products? I know about AOP for quite a while now but I've actually never used it in a commercial product. One reason I can offer you is, that it was always easy to get around using it. You know most of the "vertical" and "horizontal" needs from the beginning of the project and are free to include them in your UML model. One strategy to get around AOP at design time ist multiple inheritance (MI). Even if the language doesn't support MI directly there are many ways to implement an UML model which includes MI. Other strategies include the visitor pattern or some other form of delegation to specialized objects. There are some things which could make AOP more attractive: - discussions like this one - integration in some language would of course make some people use it (but who would use this brand new language?) - find a "killer app" (e. g. show that it's better to use AOP to profile than to use the standard profiling tools) - make it either as simple as possible or very difficult but with enormous power - build a refactoring browser which refactors aspects to where they belong ;-) Generic programming is gaining more and more attention in the world of statically typed languages. AOP could be part of that. On the other hand it's a lot easier to implement AOP in a dynamic language like Ruby. And as people like the nature of their favorite language, they might like the dynamic aspect of AOP, too. Cheers Sascha From bkelley at wi.mit.edu Thu Aug 21 13:04:52 2003 From: bkelley at wi.mit.edu (Brian Kelley) Date: Thu, 21 Aug 2003 13:04:52 -0400 Subject: [OT] Why is it called string? In-Reply-To: References: <3f44ce77$0$556$b45e6eb0@senator-bedfellow.mit.edu> <3F44DBF2.1010403@draigBrady.com> Message-ID: <3f44fb74$0$571$b45e6eb0@senator-bedfellow.mit.edu> Istvan Albert wrote: > P at draigBrady.com wrote: > >> I'm always surprised by the number of people >> in computing that don't know this. Coloquially (in american-english): A "bit" used to be half a quarter and therefore there are also 8 bits to a dollar. Coincidence or a play on words? Some of us here are making our livings using "pieces of eight", so to speak. Anyway, this brings up this reather mildly amusing chart for pricing memory (from http://www.thehumanitarian.org/faq.php) 1 Megabyte 1024 Kilobytes 1 Kilobyte 1024 Bytes 1 Byte 8 Bits 1 Shave and a Haircut 2 Bits 1 Bit $0.125 $1 8 Bits 1 Byte $1 1 Kilobyte $1024 1 Megabyte $1048576 -- Brian Kelley bkelley at wi.mit.edu Whitehead Institute for Biomedical Research 617 258-6191 From mwh at python.net Fri Aug 29 05:59:20 2003 From: mwh at python.net (Michael Hudson) Date: Fri, 29 Aug 2003 09:59:20 GMT Subject: [Zope-dev] Zope 2.7 running with Stackless 3.0 References: <3F4D44EB.5010500@tismer.com> <3F4DF1E7.1010103@zope.com> <3F4E3CE1.5030405@tismer.com> Message-ID: <7h3y8xc4wjj.fsf@pc150.maths.bris.ac.uk> "Michael Geary" writes: > Even short of that, none of the Python debuggers I've tried support a Set > Next Statement command like Visual C++ does. That itself is mighty useful. > Maybe Stackless would make it possible to support this? pdb in Python 2.3 has this feature. It has some limitations, but it's there. Cheers, mwh -- If you're talking "useful", I'm not your bot. -- Tim Peters, 08 Nov 2001 From jacek.generowicz at cern.ch Sun Aug 24 16:52:43 2003 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 24 Aug 2003 22:52:43 +0200 Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> <3F41505F.69D18CC8@alcyone.com> <%h92b.247100$Ho3.31983@sccrnsc03> Message-ID: "Bryan" writes: > but, if someone on my team adds macros to our project, does that > mean i'm now forced to learn a macro language? But, if someone on my team adds classes to our project, does that mean I'm now forced to learn a class langugage? But, if someone on my team adds functions to our project, does that mean I'm now forced to learn a function langugage? > also, can someone please post a fictituos example of what a macro > language might look like and do for me in python? i don't > understand what he benefit would be. I have posted some examples of what _macros_ might do, and how they do it, in the "macro FAQ" thread. From peter at engcorp.com Fri Aug 29 17:37:42 2003 From: peter at engcorp.com (Peter Hansen) Date: Fri, 29 Aug 2003 17:37:42 -0400 Subject: cannot get pexpect to work References: <3F4F6AF0.CA9BB337@engcorp.com> <3F4F9152.ABC73E49@engcorp.com> Message-ID: <3F4FC7A6.37CF2C3@engcorp.com> Andrei wrote: > > > Unfortunately at this moment (13:45 EDT) I get no response to > > connection requests on port 80. (That is, server is answering > > pings, but no web server on standard port.) > > sorry, I had to bring the homeserver down because of a bad thunderstorm ... > after which someone else must have taken the ip address=) > > here it is on another server which is altogether more impervious to > meteorogical changes ... > > http://tufish.org/misc/passmass.py.txt I note that pexpect.py appears to be using a default timeout of 30 seconds. It's quite possible your hosts are taking longer than that to respond with the password prompt. I've seen that happen, among other reasons, because of reverse name resolution delays. Near as I can tell ssh is broken and always does a reverse mapping attempt, even if told explicitly not to (and the default is supposed to be not to, also!). Temporarily removing /etc/resolv.conf on the host you're connecting to can help troubleshoot this... If you modify the code to catch the exception and print child.before you might see how much, if anything, was received from the host. Best solution: this is Python (!), so just start up an interactive session and type the relevant commands yourself, based on what you see in pexpect.py. Not only will you solve the problem, but you'll end up with a much better understanding of pexpect.py and the passmass.py script as well. -Peter From robin at jessikat.fsnet.co.uk Sun Aug 3 05:44:57 2003 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Sun, 3 Aug 2003 10:44:57 +0100 Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> <23bcqKAykjK$Ewhy@jessikat.fsnet.co.uk> Message-ID: In article , Lulu of the Lotus-Eaters writes >Robin Becker wrote previously: >|I don't have any data here, but I believe Python is just a little too >|weakly typed for compiling to float*float type assembler efficiently. > >Repeat this every morning: > > PYTHON IS A STRONGLY TYPED LANGUAGE WITH LATE BINDING! > >(objects are typed in Python, names are not) > strictly true, but I program with the names not the objects. I thought that objects are always typed, if they weren't it would be hard to do things with them :) >-- > mertz@ _/_/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY: \_\_\_\_ n o >gnosis _/_/ Postmodern Enterprises \_\_ >.cx _/_/ \_\_ d o > _/_/_/ IN A WORLD W/O WALLS, THERE WOULD BE NO GATES \_\_\_ z e > > -- Robin Becker From aleax at aleax.it Thu Aug 7 10:57:32 2003 From: aleax at aleax.it (Alex Martelli) Date: Thu, 07 Aug 2003 14:57:32 GMT Subject: filter()ing a dict References: <16469f07.0308070559.aed41a@posting.google.com> Message-ID: Robin Cull wrote: > Imagine I have a dict looking something like this: > > myDict = {"key 1": ["value 1", "value 2", "value 3", "value 4"], "key > 2": ["value 1", "value 2"], "key 3": ["value2", "value 3", "value 4"], > "key 4": ["value 1", "value 2", "value 3", "value 4"]} > > That is, a set of keys which have a variable length list of associated > values after them. What I want to do is filter out a subset of this > dict to produce another dict that satisfies a set of criteria (in this > case whether it contains all four values) to end up with something > like this: > > {"key 1": ["value 1", "value 2", "value 3", "value 4"], "key 4": > ["value 1", "value 2", "value 3", "value 4"]} > > I've tried using the filter() function so I wrote a small function > that returned True or False depending on whether the length of the > list was what I wanted e.g. > > def f(item): > if len(item) == 4: > return True > else: > return False This function expects to be passed the value (not the item). > I then called filter(f, myDict). While this passes the keys (not the items, but not the values either). > I was expecting to be returned a dict which was the subset of myDict > that satisfied f. > > This did not happen; the item passed to f was each key of the dict, > not each value list. The call to filter returned an empty list (as > obviously none of the keys satisfied the criteria). If anything I > would have expected an empty dict back as according to the docs: > > ""filter(function, sequence)" returns a sequence (of the same > type, if possible) consisting of those items from the sequence for > which function(item) is true." > > The important bit here is "of the same type, if possible" which I > understood to mean if passed a dict it would return a dict. Please check the current docs at http://www.python.org/doc/current/lib/built-in-funcs.html and let us know if you consider them clearer now. Specifically, the sentence: """ If list is a string or a tuple, the result also has that type; otherwise it is always a list. """ should help (despite the unfortunate name chosen for the argument). > I've tried calling filter(f, myDict.values()) which works and I get a > list like this returned: > > [["value 1", "value 2", "value 3", "value 4"], ["value 1", "value 2", > "value 3", "value 4"]] > > Sort of what I want but I've lost the associativity with the key which > was kind of the point in using a dict in the first place. Exactly. It's impossible to reconstruct the right dict from this one. > I'm guessing that filter() does not work on a dict in the way I think > it should. Doesn't and never will. > I can write something to get around the behaviour in this particular > case (although suggestions would be welcome). You need to filter on items, which are key-value pairs; therefore: def f(item): return len(item[1]) == 4 the value is the 1-th element of the 'item' pair (tuple) while the key is the 0-th element. I've also simplified the logical structure, since the == already returns True or False just as you wish, there is no reason to keep an if/else (though it's just redundant, not directly harmful). Then, you need to provide to filter the items, explicitly: filter(f, myDict.items()) this gives you a list of items (pairs of key-value). Finally you can pass that to dict to obtain what you want: dict(filter(f, myDict.items())) You could equivalently use myDict.iteritems() [may be faster, but I doubt that matters for a reasonably small dictionary anyway]. Note that filter, these days, is often shunned in favour of a list-comprehension, which saves the need to write a function as the predicate for the filtering; with a list comprehension you might write it all on one line as dict([ (key,myDict[key]) for key in myDict if len(myDict[key])==4 ]) or, if you prefer: dict([ (key,value) for key,value in myDict.items() if len(value)==4 ]) and other equivalent ways yet. > My question is, does anybody else think that when calling filter(f, > dict), it should return a dict of the keys and values of the former > dict where the values satisfy the conditions defined by f()? According to "Ugol's Law", on Usenet, if you ever ask whether you are the only one who "X" (where "X" is "thinks this", "does that", "likes the other", etc, etc), the answer is invariably "no". However, the Ugolian certainty that there must be another person who shares your opinion in this matter isn't all that relevant. More interesting is the next question you ask: > Are there reasons for it not to work this way? I must admit I've not > looked into this carefully, just in the context of my script it'd be > useful to. 'filter' unfortunately carries around the complication (for backwards compatibility) of returning a string when passed a string, a tuple when passed a tuple, a list in all other cases. It would obviously be much simpler if it always returned a list. You, on the other hand, would want to make it even _more_ complicated -- and for reasons that escape me, but perhaps connected at looking just at the context of this one script, would want the filtering function to be passed just the values, rather than (as happens now if you pass filter a dict) just the keys. Since you CAN recover the value from the key (if you have access to the dictionary, e.g. as a global variable) but not vice-versa, I think it's undisputable that such a hypothetical change (hypothetical because it would break backwards compatibility, and thus it's mathematically certain that it will not happen) would be worse than the current situation. Passing a (key,value) pair, i.e a whole item, would on the other hand not be just as unambiguously bad -- it would "just" be a complication whose cost (complicating things) needs to be weighed against its advantage (making it a tad handier to perform dictionary-filtering in certain cases) - again hypothetically speaking, of course. > What are the side effects of making filter() work this way? Presumably that filter then would need to know about one more special case (besides the two unfortunate, historical ones of strings and tuples) rather than just being able to iterate on its second argument. The incompatibility of the filtering function needing to be passed the whole item [ (key,value) pair ] is the definite reason this will never happen; whether it should have been so in the first place is therefore moot (I opine filter's very existence is unjustified in today's Python, except for backwards compatibility, but others do differ, of course). Python 3.0's main thrust (when it finally happens) will be to *SIMPLIFY* Python by removing a lot of currently existing basically redundant ways to do things -- the BDFL has said so at this year's Python conferences. Thus, I expect the filter function to go away, rather than gaining bells and whistles. If you can make substantial use cases for the "filtering a dictionary" functionality, for very large dictionaries where dict([ (k,d[k]) for k in d if len(d[k])==4 ]) has intolerable overhead, then one addition that _might_ have some (small) chance of making it into future releases might be to add to the dict class a filter method (taking just the predicate as its argument). I'm still rather dubious that this would actually stand any real chance, but can't be certain of that. Alex From dieter at handshake.de Wed Aug 20 14:19:41 2003 From: dieter at handshake.de (Dieter Maurer) Date: 20 Aug 2003 20:19:41 +0200 Subject: Python Debugger References: <6ee58e07.0308181134.383a69e7@posting.google.com> <3f412cf3.351547428@news.blueyonder.co.uk> <6ee58e07.0308191220.702baf00@posting.google.com> Message-ID: llothar at web.de (Lothar Scholz) writes on 19 Aug 2003 13:20:12 -0700: > alan.gauld at btinternet.com (Alan Gauld) wrote in message news:<3f412cf3.351547428 at news.blueyonder.co.uk>... > > On 18 Aug 2003 12:34:09 -0700, llothar at web.de (Lothar Scholz) > > wrote: > > > Is there any python debugger that can > > > > > > 1) be used remotely > > > > What do you mean by remotely? Debug a program running on a server > > from a remote PC? > > Yes this is what i mean For this, we use WingIDE, a commercial IDE for Python. > > > 2) can handle multiple threads When you mean a debugger that can set breakpoints in any thread, analyse the state of any thread etc, then this is unlikely. Python maintains the debugging hook in a thread specific data structure. The available API functions can only access the debugging hook in the own thread but not in a foreign thread. This implies that unless the start of a thread is customized (such that the debugging hook is immediately set on thread start) it is very difficult to debug a foreign thread (without a specialized C extension using internal implementation details of Pythons thread implementation). Dieter From vanevery at 3DProgrammer.com Tue Aug 19 00:12:49 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Mon, 18 Aug 2003 21:12:49 -0700 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: <3f4153a9$0$1124$626a54ce@news.free.fr> Message-ID: Bruno Desthuilliers wrote: > > PS : Brandon, please make my day and tell me : did I won my place in > your killfile too ?-) Yes you did. Goodbye! -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From P at draigBrady.com Wed Aug 6 07:43:19 2003 From: P at draigBrady.com (P at draigBrady.com) Date: Wed, 06 Aug 2003 12:43:19 +0100 Subject: Capture PID of child process In-Reply-To: References: Message-ID: <3F30E9D7.1070003@draigBrady.com> klappnase wrote: > Hello, everyone, > > I am running python2.2.2 on a linux box. > I want to call a shell command and get the PID of this child process > so I have the possibility to abort the child process while it is still > running. > > I tried the popen2 module for that: > > self.pp = popen2.Popen3(cmd) I modified this a bit to create my own class, which allows me to kill the whole process group and wait for completion. See the fslint_backend class in http://www.pixelbeat.org/fslint/FSlint-2.02.tar.gz P?draig. From dave at solussoftware.com Thu Aug 28 07:38:21 2003 From: dave at solussoftware.com (Dave Brueck) Date: Thu, 28 Aug 2003 05:38:21 -0600 Subject: OT: Americans love their guns In-Reply-To: References: Message-ID: <200308280538.21593.dave@solussoftware.com> On Thursday 28 August 2003 10:41 am, Richard Wesley wrote: > In article , > > midnight at warm-summer-night.net (falling star) wrote: > > Lulu of the Lotus-Eaters wrote: > > LotLE> > > LotLE> USA automobile deaths are ^43k/year > > LotLE> USA gun-related deaths are ~29k/year > > > > Where did you get your number? 29k a year??? Don't believe it. I > > would guess the number to be somewhere in the 1000 to 2000 range. > > US murders with firearms were 8,259 in 1999, ranked #4 in the world. > Source: That's it!?!? Wow... I'm amazed that number is so low! That means that, in the U.S., you are twice as likely to die from an accident involving drunk drivers (http://www.madd.org/stats/0,1056,3726,00.html), four times as likely to die from influenza (http://www.cdc.gov/od/oc/media/pressrel/r030107.htm), and 67 times as likely to die from cancer (http://www.millennium.com/rd/oncology/treatment/index.asp) than to be murdered with a firearm. The odds of getting killed that way are roughly the same as the odds that you'll die from aspirin or similar drugs (http://www.drugwarfacts.org/causes.htm). From cnetzer at sonic.net Fri Aug 29 13:21:26 2003 From: cnetzer at sonic.net (Chad Netzer) Date: Fri, 29 Aug 2003 10:21:26 -0700 Subject: another puzzled newbie In-Reply-To: <20030829194017.A24765@bullseye.apana.org.au> References: <68g3b.855589$ro6.16997110@news2.calgary.shaw.ca> <20030829194017.A24765@bullseye.apana.org.au> Message-ID: <1062177686.1865.3.camel@adsl-209.204.179.133.sonic.net> On Fri, 2003-08-29 at 02:44, Andrew MacIntyre wrote: > On Fri, 29 Aug 2003, Elaine Jackson wrote: > > > | > for i in range(len(shuffler)): > > | > shuffler[i]+=(-1) > > | ^^^^ > > | If you want a tuple here, it should be (-1,). > > No, I want (-1) the integer. > I find a little white space makes things more attractive and easier to > read, ie: > > shuffler[i] += -1 Right. In my case, the first version led me to believe that the poster may have wanted to append a tuple (well, construct a new one with '+'...). The second one, with spaces, makes the intent much less ambiguous at first glance. -- Chad Netzer From aleax at aleax.it Sun Aug 3 17:09:56 2003 From: aleax at aleax.it (Alex Martelli) Date: Sun, 03 Aug 2003 21:09:56 GMT Subject: Determining if a filename is greater than X characters References: <93f5c5e9.0308021815.44c57a2d@posting.google.com> <3f2cfea8$0$49106$e4fe514c@news.xs4all.nl> <3F2D6A90.1040203@vt.edu> Message-ID: hokiegal99 wrote: > Thanks for the tips. I got it to work using this: > > for root, dirs, files in os.walk(setpath): > old_fname = files > new_fname = old_fname[0][:27] > print old_fname > print new_fname [note the lack of indentation due to your usage of tabs -- please use spaces, not tabs, for Python code in messages you post to the net or send by mail - many popular user-agents for news and mail, such as Microsoft Outlook Express and KDE's KNode, won't display or process tabs in the way you might expect them to]. > The problem with this approach is that it only gets the first filename > in the directory. I tried doing "old_fname[:][:27]", but that doesn't do > it. I need to learn more about lists. Since files is a LIST of strings, you may loop (directly or with a list-comprehension) to process all of its items, i.e., your loop above becomes: for root, dirs, files in os.walk(setpath): for old_fname in files: new_fname = old_fname[:27] print old_fname print new_fname Alex From mcfletch at rogers.com Mon Aug 11 18:50:13 2003 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Mon, 11 Aug 2003 18:50:13 -0400 Subject: mysql fieldnames In-Reply-To: <644f6688.0308111422.2f2c4a05@posting.google.com> References: <644f6688.0308111422.2f2c4a05@posting.google.com> Message-ID: <3F381DA5.8000704@rogers.com> Here's the code I use for it: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/pytable/table/pytable/mysql/tableactions.py?rev=HEAD&content-type=text/vnd.viewcvs-markup (You can scroll down to the bottom to see the low-level queries). Basically MySQL has a "show" SQL query for the database types. You can use regular DB-API calls to get the results of running those queries. HTH, Mike rdack wrote: >how can i retrieve database names and fieldnames from mysql 4 using >MySQLdb 0.9.2 from python 2.3? >(on mac osx 10.2.6) > > _______________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://members.rogers.com/mcfletch/ From uche at ogbuji.net Fri Aug 8 16:23:26 2003 From: uche at ogbuji.net (Uche Ogbuji) Date: 8 Aug 2003 13:23:26 -0700 Subject: 4Suite and XSLT problems References: <88bc63c6.0308051408.3674e1d9@posting.google.com> Message-ID: writeson at earthlink.net (Doug Farrell) wrote in message news:<88bc63c6.0308051408.3674e1d9 at posting.google.com>... > Hi all, > > I'm trying to use the 4Suite xml/xsl tools to transform some XML data > into HTML. I'm using some examples from the O'Reilly book "Python and > XML" and things are blowing up. Here is the little piece of code I'm > working on: Your answers are here: http://uche.ogbuji.net/tech/akara/nodes/2003-01-01/basic-xslt http://www.xml.com/pub/a/2002/12/11/py-xml.html --Uche http://uche.ogbuji.net From lists at webcrunchers.com Sun Aug 24 20:59:06 2003 From: lists at webcrunchers.com (John D.) Date: Sun, 24 Aug 2003 17:59:06 -0700 Subject: Suggestion/recommendation for dictionary formatting Message-ID: I've experimented with this and concluded: {1:2, 3:4, 5:6, 7:8} is more readable than the current output: {1: 2, 3: 4, 5: 6, 7: 8} Removing the space after the colon more clearly shows the key:value pairings. The effect is less striking with longer and more complex items, but it is never detrimental. Summary of proposed change: --------------------------- Synopsis: Remove space after the colon in formatted dictionary dumps Purpose: Legibility improvement Effect on existant programs: Minimal -this is mostly cosmetic Difficulty of implementation: Trivial for one familiar with core code Security issues: None Comments anyone? John From mauricio.inforcati at cenpra.gov.br Tue Aug 12 11:02:30 2003 From: mauricio.inforcati at cenpra.gov.br (=?iso-8859-1?Q?Mauricio_Infor=E7ati?=) Date: Tue, 12 Aug 2003 12:02:30 -0300 Subject: acentuation problem Message-ID: <01d701c360e2$c0df2230$417290c8@paraopeba> Hi, I am having problems with acentuation on python. Before, I used to have win98 with python 2.2.3. Everything worked perfectly. Now, I?ve updated my OS to Windows 2000 and have problems. When I try to save on IDLE a script wich has portuguese acentuation on some strings (like "andr?"), it desn?t let me save the file, with this error. Exception in Tkinter callback Traceback (most recent call last): File "C:\Python22\lib\lib-tk\Tkinter.py", line 1316, in __call__ return apply(self.func, args) File "C:\PYTHON22\Tools\idle\IOBinding.py", line 128, in save if self.writefile(self.filename): File "C:\PYTHON22\Tools\idle\IOBinding.py", line 151, in writefile chars = str(self.text.get("1.0", "end-1c")) UnicodeError: ASCII encoding error: ordinal not in range(128) Similarly, on SHELL I can not use acentuation either. [shell] >>> a = 'andr?' UnicodeError: ASCII encoding error: ordinal not in range(128) >>> BUT, in a command line python, on the same OS, I can use acentuation normally, without using unicodes or escape characters. [command line] >>> a = 'andr?' >>> Can anybody help me? Maur?cio Infor?ati -------------- next part -------------- An HTML attachment was scrubbed... URL: From Robert at AbilitySys.com Thu Aug 21 00:27:51 2003 From: Robert at AbilitySys.com (Robert D. Young) Date: Wed, 20 Aug 2003 21:27:51 -0700 Subject: How does one get "maintenance copies" Message-ID: <0FC17BE316F9BB47A704AF96308E09CD12263C@ability-nt.AbilityNT.AbilitySys.com> Pardon my stupidity, I've only used the Windows version of Python and only via the standard installer at that. However, I've been having a bear of a time w/2.3 - I even went back to 2.2 to stay productive. I researched the "bug list" to see if the problems I was experiencing were known and sure enough, they are (such as the "install to a directory name with a space" issue that IDLE has). The bug tracker mentions these are fixed in some form of "maintenance" package. How can I get the latest fixes and put them into my Windows version? TIA, - Robert From kmj9907 at cs.rit.edu Mon Aug 4 23:06:21 2003 From: kmj9907 at cs.rit.edu (Keith Jones) Date: Tue, 05 Aug 2003 03:06:21 GMT Subject: TKinter, PyQT and wxPython (BOA) References: Message-ID: On Tue, 05 Aug 2003 02:02:11 +0000, Dennis Sylvester wrote: > Interested in any opinions, studies, etc., concerning the GUI tool(s) to > use for Python. Specifically, which would you recommend (and why) for > building GUI apps in Python: > > TKinter > BOA > PyQT > > Thanks, > Dennis I've used Tkinter and PyQt. The nice thing about Tkinter is that it comes with the standard python package. It's relatively simple, but I don't like it for more significant GUI applications.. I had trouble finding good documenation for it. Perhaps if you already know Tk, it's not so bad. I've used PyQt on linux, and I love it, but beware, Trolltech only provides noncommercial Qt 2.3 for windows, which means you might find it a pain if you're writing for linux and want to port to windows. (But then, it's probably not that big of a pain unless you use Qt3-specific stuff.) I think the trolltech people have done a great job providing a first class toolkit. I've found the PyQt programming book more handy than the Tkinter programming book (I bought them both), and Trolltech's Qt docs are (for the vast majority, but not always) applicable to PyQt. With PyQt you can use qt-designer if you like that sort of thing; you'll need to get pyuic, too. Personally, I've found the layout managers to be useful enough so far. You didn't mention PyGTK, which you can use with glade; just thought I'd mention that. Good luck, Keith From Scott.Daniels at Acm.Org Mon Aug 11 11:28:55 2003 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 11 Aug 2003 08:28:55 -0700 Subject: Slogan: Getting Rich Overnight In-Reply-To: References: <3f373ac6@shknews01> Message-ID: <3f37b637$1@nntp0.pdx.net> Christian Tismer wrote (in response to Brandon J. Van Every): > ... I was not picking them. > They were said by another guy, who > said in German > "Python hat mich ?ber nacht reich gemacht". > > My problem is not that sentence. In German, > it still has a useful meaning. > My problem is the impossibility > to translate it into English without loosing meaning. Though Idon't know German, I'll propose another formulation: "Python can enrich you overnight." Enrich is less inevitably used in a monetary sense. -Scott David Daniels Scott.Daniels at Acm.Org From peter at engcorp.com Sun Aug 24 09:32:43 2003 From: peter at engcorp.com (Peter Hansen) Date: Sun, 24 Aug 2003 09:32:43 -0400 Subject: Python preinstalled on Windows - looking for details References: Message-ID: <3F48BE7B.961CFBA0@engcorp.com> Skip Montanaro wrote: > > It appears that HP and perhaps some other computer manufacturers who deliver > Windows systems have begun delivering systems with Python pre-installed. > We've begun to get frequent questions about this at the webmaster at python.org > email address. I contacted HP about this, but have so far received no firm > details about why Python is installed or what applications on their boxes > use it. It's not clear how to respond to people who ask, "What's this > Python thing? Can I delete it?", other than to say, "No, you probably > shouldn't delete it.". > > If you have any details about who in the Windows world preinstalls Python > and what they use it for, please let me know. I'd like to add a question to > the Python FAQ, but would like some details. Maybe get someone who has purchased such a machine to contact HP tech-support and ask some similar questions. Something like "I found this Python stuff on my machine and thought maybe my kid put it there. Can I safely delete it to free up hard drive space? Will that break anything and, if so, what?" -Peter From heikowu at ceosg.de Sun Aug 10 19:54:29 2003 From: heikowu at ceosg.de (Heiko Wundram) Date: 11 Aug 2003 01:54:29 +0200 Subject: ANN: yawPyCrypto 0.1 and Flatten 0.2 Message-ID: <1060559669.822.13.camel@d168.stw.stud.uni-saarland.de> yawPyCrypto ----------- yawPyCrypto is "yet another wrapper" for the PyCrypto library written by Andrew M. Kuchling and others. It aims at more complete support for the whole range of cryptographic functionality available in PyCrypto, while still offering an easy to use interface. There has been quite a jump from version 0.0alpha4, which was the last version I posted, to version 0.1. There have been major code cleanups, factorizations, and other important changes. The strong points of yawPyCrypto at the moment are: 1. Full support for the public key ciphers of PyCrypto in a single class. 2. Full support for all cipher algorithms of PyCrypto in a single class, which allow for stream encryption using block ciphers. 3. Fully and easily extensible with user functionality through a plugin interface (which isn't documented yet). What's still missing from the functionality that was present in 0.0alpha4 but isn't cleaned up yet: 1. Full support for GPG-like stream encryption using block ciphers with session keys (session key support is present in the crypto cipher classes, but the stream format of a GPG-like stream needs cleaning up). The last point will be cleaned up in a maintenance release in about three days. yawPyCrypto now depends on Flatten ------- A Python serialization library which aims at offering a secure pickling algorithm, especially well suited for network transport of data. This library offers a few other gimmicks which I found no other serializer could offer me, such as a unique way of reconstructing stored instances with type-checking of operands implemented directly in the serialization code. Flatten 0.2 is basically a maintenance release which supersedes Flatten 0.1, which was released about a month ago. The functionality has not been changed, except that a little bug concerning the handling of None in pickles was fixed, and finally the package comes with a distutils script. URL: http://www.sourceforge.net/projects/yawpycrypto Version: yawPyCrypto 0.1 and Flatten 0.2 Author: Heiko Wundram From adalke at mindspring.com Mon Aug 4 14:56:32 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Mon, 4 Aug 2003 12:56:32 -0600 Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> <87el06d2i6.fsf@pobox.com> Message-ID: Mel Wilson: > (Idea for obfuscated Python: a program that mixes spaces > and tabs in the indenting so as to perform two or more > distinct useful functions depending on the space-to-tab > rate. Bonus points for a program that undoes itself at > different settings.) That's just not possible because Python only has one setting for a tag - 8 spaces. At most there would appear to be a difference if your editor was configured to display tabs as, say, 4 spaces. But Python's understanding of it would not change. Andrew dalke at dalkescientific.com From tjreedy at udel.edu Tue Aug 19 21:35:41 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 19 Aug 2003 21:35:41 -0400 Subject: 2 funny Py2.3 Issues: 'datetime', string.join() References: <3F42AB3D.F9B456F4@yahoo.com> Message-ID: "Rami A. Kishek" wrote in message news:3F42AB3D.F9B456F4 at yahoo.com... > 1) I particular like how the Python 2 syntax has all the string > functions as methods of the object (so we don't have to import > string. However, wouldn't it make more sense if the "join" mehtod > actually belonged to the List object, since it primarily operates on > lists? Go to http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&group=comp.lang.python and enter .join for at least 2 threads on this topic in last year. Terry J. Reedy From mcherm at mcherm.com Thu Aug 7 07:50:00 2003 From: mcherm at mcherm.com (Michael Chermside) Date: Thu, 7 Aug 2003 04:50:00 -0700 Subject: Anonymous class question Message-ID: <1060257000.3f323ce842aa7@mcherm.com> Dan Williams writes: > Is there a more pythonic way to do something evquilent to what this line > does without creating a dummy class? > > self.file = type("", (object,), {'close':lambda slf: None})() Dan, NO solution other than this one: class CanBeFreelyClosed(object): def close(self): pass [...] self.file = CanBeFreelyClosed can be said to be "pythonic". In this case, there is one (obvious) way to do it. Why on earth would you be afraid to create a class? -- Michael Chermside From fortepianissimo at yahoo.com.tw Fri Aug 8 18:06:33 2003 From: fortepianissimo at yahoo.com.tw (Fortepianissimo) Date: 8 Aug 2003 15:06:33 -0700 Subject: Recommendation of a parser generator Message-ID: I'm about to start a new project which will be mostly written in Python. The first task is to parse some formula-like expressions into an internal data structure so they can be evaluated. This parser would be run extensively in the future, so speed is a consideration, although at this point to get something up and running is more important. Also there's a strong possibility of changing the formula grammar in the future (although the change probably would be some minor addition/changes). I took a look at http://www.python.org/sigs/parser-sig/towards-standard.html, and went to check BisonGen and found out it's 2-year old now (this is the fastest one reported in the survey). I checked YAPPS but accordint to the author it's not designed for efficiency and the parsing technique has limitations compared to others. Also checked Simpleparse and found it has to be installed with another toolkit, etc. I'd appreciate very much some expert suggestions from the group, like on the speed, flexibility, portability, and the future prospect (like to be adopted as the standard etc.). Thanks a lot! From sross at connectmail.carleton.ca Tue Aug 12 22:39:22 2003 From: sross at connectmail.carleton.ca (Sean Ross) Date: Tue, 12 Aug 2003 22:39:22 -0400 Subject: how to let compiler do a check before I run References: Message-ID: Hi. Try this: http://pychecker.sourceforge.net/ HTH Sean From pythonguy at Hotpop.com Tue Aug 19 02:26:22 2003 From: pythonguy at Hotpop.com (Anand Pillai) Date: 18 Aug 2003 23:26:22 -0700 Subject: XML parser and py2exe References: <84fc4588.0307200721.970b9d9@posting.google.com> <4r1dkuho.fsf@python.net> Message-ID: <84fc4588.0308182226.58063c8a@posting.google.com> I am sure it would be a lot of fun :-) Could you tell me how to get a start on it? Thanks -Anand Thomas Heller wrote in message news:<4r1dkuho.fsf at python.net>... > pythonguy at Hotpop.com (Anand Pillai) writes: > > > I am using the expat parser in the 'xml.parsers.expat' module in > > my code. The code works well as source, but the py2exe executable created > > using it does not. I get the following traceback. > > > > Traceback (most recent call last): > > File "", line 146, in ? > > File "imputil.pyo", line 103, in _import_hook > > File "", line 52, in _import_top_module > > File "imputil.pyo", line 216, in import_top > > File "imputil.pyo", line 271, in _import_one > > File "", line 128, in _process_result > > File "HarvestManConfig.pyo", line 110, in ? > > File "imputil.pyo", line 103, in _import_hook > > File "", line 52, in _import_top_module > > File "imputil.pyo", line 216, in import_top > > File "imputil.pyo", line 271, in _import_one > > File "", line 128, in _process_result > > File "HarvestManXMLParser.pyo", line 12, in ? > > File "imputil.pyo", line 132, in _import_hook > > File "", line 70, in _finish_import > > File "imputil.pyo", line 318, in _load_tail > > ImportError: No module named _xmlplus.parsers > > The released version of py2exe isn't able to handle PyXML correctly. > Although the current CVS version can do it. If you can build it > yourself, you should try it. > > I'm hesitating to make a new release at the moment because I hope to > solve the Python 2.3 problems, and also I have got a patch from Mark > Hammond for inproc com servers, which I would like to integrate. > > Thomas From mfranklin1 at gatwick.westerngeco.slb.com Thu Aug 28 04:44:37 2003 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Thu, 28 Aug 2003 09:44:37 +0100 Subject: homebrew 2.3 install on RedHat9 not playing nice with Tkinter In-Reply-To: <200308280842.51310.mfranklin1@gatwick.westerngeco.slb.com> References: <0h83b.953$8v3.90271@twister.austin.rr.com> <200308280842.51310.mfranklin1@gatwick.westerngeco.slb.com> Message-ID: <200308280944.37519.mfranklin1@gatwick.westerngeco.slb.com> On Thursday 28 August 2003 8:42 am, Martin Franklin wrote: > On Wednesday 27 August 2003 9:12 pm, Rob Andrews wrote: > > I'm on a Red Hat 9 system, which has Python 2.2.2 installed, and I > > installed 2.3 separately into /home/rob/Python-2.3/ (creating the > > symbolic link "py23" to point to my 2.3 installation). Now I'm trying to > > work out the kinks in the process. > > > > Unable to run Idle using 2.3 the way I've got things set up, I created a > > super simple Tkinter test program that just pops up a Label widget. I > > pasted below an example of how the RH-provided 2.2 runs the script > > without incident, but running the script with 2.3 produces a traceback. > > If someone can help me see the error of my ways, I'll be most > > appreciative. > > > > [Wed Aug 27][03:01 PM] ~/Python-2.3/test $ python -V > > Python 2.2.2 > > [Wed Aug 27][03:04 PM] ~/Python-2.3/test $ py23 -V > > Python 2.3 > > [Wed Aug 27][03:01 PM] ~/Python-2.3/test $ py23 test2.py > > Traceback (most recent call last): > > File "test2.py", line 1, in ? > > from Tkinter import Label > > File "/home/rob/Python-2.3/Lib/lib-tk/Tkinter.py", line 38, in ? > > import _tkinter # If this fails your Python may not be configured for > > Tk ImportError: No module named _tkinter > > [Wed Aug 27][03:01 PM] ~/Python-2.3/test $ python test2.py > > > > -Rob > > (mediocre with Python, incompetent with linux) > > Rob, > > I just finished building python 2.3 on my redhat 9 laptop... the first > time I did the make it failed (near the end) because it couldn't find the > Tk/Tcl libs. > > On my system they are in /usr/local/lib (because I built them myself) > on your's I guess they would be in /usr/lib. So to fix the build I set > LD_RUN_PATH to /usr/local/lib and them ran make again. > > > HTH > Martin OK so just to check what I did I did it again...: The error I got when I did make for the first time was:- gcc -pthread -shared build/temp.linux-i686-2.3/_tkinter.o build/temp.linux-i686-2.3/tkappinit.o -L/usr/X11R6/lib -L/usr/local/lib -ltk8.4 -ltcl8.4 -lX11 -o build/lib.linux-i686-2.3/_tkinter.so *** WARNING: renaming "_tkinter" since importing it failed: libtk8.4.so: cannot open shared object file: No such file or directory So it looks like _tkinter got compiled OK but when it was imported (as a test I presume) it failed to find the tk library.. so:- [mfranklin1 at m-franklin Python-2.3]$ export LD_RUN_PATH=/usr/local/lib [mfranklin1 at m-franklin Python-2.3]$ make gcc -pthread -shared build/temp.linux-i686-2.3/_tkinter.o build/temp.linux-i686-2.3/tkappinit.o -L/usr/X11R6/lib -L/usr/local/lib -ltk8.4 -ltcl8.4 -lX11 -o build/lib.linux-i686-2.3/_tkinter.so running build_scripts This time it continues. without error/warning... What is LD_RUN_PATH??? man ld -rpath dir Add a directory to the runtime library search path. This is used when linking an ELF executable with shared objects. All -rpath arguments are concatenated and passed to the runtime linker, which uses them to locate shared objects at runtime. The -rpath option is also used when locating shared objects which are needed by shared objects explicitly included in the link; see the description of the -rpath-link option. If -rpath is not used when linking an ELF executable, the contents of the environment variable "LD_RUN_PATH" will be used if it is defined. The -rpath option may also be used on SunOS. By default, on SunOS, the linker will form a runtime search patch out of all the -L options it is given. If a -rpath option is used, the runtime search path will be formed exclusively using the -rpath options, ignoring the -L options. This can be useful when using gcc, which adds many -L options which may be on NFS mounted filesystems. For compatibility with other ELF linkers, if the -R option is fol- lowed by a directory name, rather than a file name, it is treated Cheers Martin From baas at ira.uka.de Sun Aug 3 04:55:14 2003 From: baas at ira.uka.de (Matthias Baas) Date: Sun, 03 Aug 2003 10:55:14 +0200 Subject: what do people use for 2D coordinates? References: Message-ID: On 1 Aug 2003 16:37:38 -0700, aayycc88 at hotmail.com (Andy C) wrote: >You could use tuples or complex numbers (seems like a bit of a hack). >I saw somewhere it said that tuples are useful for coordinates. But I >haven't found a nice way to add coordinates, since + does >concatenation on tuples. I have written a package that includes 3D vectors. You can also use those for 2D stuff (just ignore the 3rd component). The package can be found here: http://cgkit.sourceforge.net And to see if it suits your needs you can have a look at the documentation here: http://cgkit.sourceforge.net/doc/index.html - Matthias - From news at 92tr.freeserve.co.uk Tue Aug 26 20:08:24 2003 From: news at 92tr.freeserve.co.uk (ddoc) Date: Wed, 27 Aug 2003 00:08:24 +0000 Subject: Python and Smart Cards References: Message-ID: Gerry Sutton wrote: > Does anyone know of any Smarty Card related modules in Python. http://homepage.mac.com/jlgiraud/pycsc/Pycsc.html Pycsc is a python module which defines a new type of object to access smart cards using the PCSC API. Python 2.2 or higher is required to use pycsc. RPMs for what it wraps here http://www.linuxnet.com/middle.html on a site which is part of the MUSCLE project I know little of these things, but let us know if this helps, and what one migh do with them, please. -- A From mcfletch at rogers.com Wed Aug 20 22:24:33 2003 From: mcfletch at rogers.com (Mike Fletcher) Date: Wed, 20 Aug 2003 22:24:33 -0400 Subject: Toronto-area Pythonistas meeting Tuesday the 26th of August... Message-ID: <3F442D61.9090107@rogers.com> Since no-one seems to have announced this yet... PyGTA meeting this upcoming Tuesday at the regular time (8pm) and place (519 Comm. Centre (on Church St., in downtown Toronto)) See: http://web.engcorp.com/pygta/wiki/NextMeeting for details. Feel free to bring questions or problems to ask other Pythonistas about. We've been having good turnouts for the last few meetings, almost enough to overflow the rooms, so you don't have to just listen to Peter and I blathering on ;) . If you'd like to do a short presentation on your Python work please propose it on the pygta-general mailing list. Enjoy all, Mike _______________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://members.rogers.com/mcfletch/ From SquatLittleElvis_spammenot at netscape.net Mon Aug 25 15:32:55 2003 From: SquatLittleElvis_spammenot at netscape.net (John Paquin) Date: Mon, 25 Aug 2003 19:32:55 GMT Subject: Help embedding python In-Reply-To: References: Message-ID: Zora, Questions: 1) the docs that come with the python23 runtime have some simple examples that may help you. They go through the process fairly thoroughly 2) What os are you using? 3) what kind of build errors are you getting? I've always just built dynamic libraries built from the source distribution, then linked with the python23.lib or python23_d.lib and it's mostly worked. Here are some things that I've found useful: if you are defining a new class, it seems that tp_methods (from the PyTypeObject class) is not used in the way indicated in the docs. Instead, I've had to do the following inside my getattr handler: static PyObject *script_CModel_getattr(PyObject*self,char *attr) { return Py_FindMethod(PyMethodDef *pmethods, (PyObject *)self, attr); } where pmethods is the same method table you would ordinarily attach to tp_methods. Since the new-style classes have been implemented, it may be necessary to subclass new classes from "object" instead of NULL as the docs say. Finally, to just create a module in C, call: Py_InitModule("modulename", PyMethodDef *methods); as the docs indicate. also, get python to load a .py module, you have to do 2 things: make sure the path to the module is in the sys.path list, then call import_module. here's how I do it: PyObject* pSysPath; PyObject* pmodule; PyObject* pSysModule = PyImport_AddModule("sys"); if (pSysModule) { pSysPath = PyObject_GetAttrString(pSysModule,"path"); // note: newpath is a char* PyObject *result = PyObject_CallMethod( pSysPath, "insert", "is",0,newpath); if (result) { Py_DECREF(result); pmodule = PyImport_ImportModule(module_name); result = PyObject_CallMethod(pSysPath,"pop","i",0); Py_XDECREF(result); } } pmodule is now the PyObject version of the module you just loaded. Sorry if this isn't enough help. Zora Honey wrote: > My husband and I are writing a program that does a lot of math behind > the scenes (c++) with a gui front (python/Tkinter). We've decided that > we want the c++ to be the "driver", and so we want to embed the python. > We are not stupid people, and we've already searched this newsgroup and > the web at large for help, but we're having a heck of a time trying to > do this. > > We're using Python 2.2 and Mark Lutz' "Programming Python" as a guide. > Unfortunately, the code in there is a little out of date (loading > certain libraries), and we haven't been able to get any examples to work > (we even tried downloading the version he uses in the book, but it fails > on the build). > > So I'm wondering if someone out there has, or would be kind enough to > create, a very simple ("hello world" type) program with Makefile that > works under 2.2. > > I will be very grateful, as it is my job to do the graphics, so if I > can't get python working, I'll have to learn another language... > > Thanks, > Zora > From lists at webcrunchers.com Sun Aug 24 20:57:57 2003 From: lists at webcrunchers.com (John D.) Date: Sun, 24 Aug 2003 17:57:57 -0700 Subject: Python prog needs root -how to do this securely Message-ID: I have a Python program which runs as user 'www' (it's a CGI). It needs root privilege to write a particular file. What's the best way of doing this while remaining secure? Right now I do os.system("sudo myutil parms") and pass the parms to it. I remove : < > & | from the parm string before passing it. Is there a way to do this without making a system call? i.e. gimme_root() my code... drop_root() From tjreedy at udel.edu Wed Aug 6 20:12:26 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 6 Aug 2003 20:12:26 -0400 Subject: modifying def behaviour References: Message-ID: "Craig Zoretich" wrote in message news:e7d0b08f.0308061508.5b5228c7 at posting.google.com... > Is it possible to change how the "def" builtin command works? Sure, if you are willing to change the interpreter. But no, there is not an exposed 'metafunction' facility analogous to metaclasses. > Specifically I want to modify def to write to a log file when a > function executes (for instance the name of the function, when it was > executed - that sort of thing). I want to avoid having to put some > code in each and every function I write to do this logging for me. However, the def code has nothing to do with what happens when a function is called. All it could do is what you don't want (put code in eash function). So you would need to hook into the function call mechanism. To do this in Python (rather than in C and recompile the interpreter) wrap the functions you want logged as instances of a logger class. Others have previously posted examples like this: class logger: def __init__(self, func): self.func = func def __call__(self, *args): print "Called: %s with args %s" % (self.func.func_name, args) return self.func(*args) def myfunc(a): return a myfunc = logger(myfunc) >>> myfunc(3) Called: myfunc with args (3,) 3 Terry J. Reedy From mpeuser at web.de Fri Aug 29 15:07:38 2003 From: mpeuser at web.de (Michael Peuser) Date: Fri, 29 Aug 2003 21:07:38 +0200 Subject: after, after_cancel and Python 2.3 References: Message-ID: "Edward K. Ream" schrieb im Newsbeitrag news:vkur12pg3gj5ac at corp.supernews.com... > > Previous to Python 2.3 my app has destroyed the root Tk window using > > root.destroy rather than the more usual root.quit. In Python 2.3 this does > > not work so well... Your example is somewhat complicated to say the least. As I am not using 2.3/8.4 at the moment I have not encountered like problems. But note that there are fundamental differences between Tk.quit and Tk.destroy. Tk.quit just leaves the event loop and touches no widget. See this example: from Tkinter import * m=Tk() Button(m,text="quit",command=m.quit).pack() mainloop() print "this is not The End" mainloop() Maybe destroy did not trigger Python garbage collection in 8.3 as expected, so data could have been erronously accessable. The memory leak would not have been to obvious because destroy is a rare instruction... May also be there is some bug with destroy in Tk 8,4 ;-) Kindly Michael P > From vanevery at 3DProgrammer.com Mon Aug 18 17:40:41 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Mon, 18 Aug 2003 14:40:41 -0700 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: Message-ID: Andrew Dalke wrote: > Brandon J. Van Every: >> What's ***TOTALLY COMPELLING*** about Ruby over Python? > > Nothing. > > I think several people have been very explicit in saying > that Ruby has some advantages over Python, and vice versa, > that in most cases it's a wash, but that there's nothing 'TOTALLY > COMPELLING" about Ruby. That's the answer I was expecting to hear. > You need to acquire critical reading skills. No I do not. I was seeking clear verification, and I got what I was looking for. I suggest that you need to acquire imagination skills. You can't seem to wrap your head around legitimate reasons for asking a question. > And this sort of post is making your troll mark almost indelible. I'm tired of knee-jerkers like you. Welcome to my killfile! -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From Olivier.POYEN at clf-dexia.com Tue Aug 19 09:53:42 2003 From: Olivier.POYEN at clf-dexia.com (POYEN OP Olivier (DCL)) Date: Tue, 19 Aug 2003 15:53:42 +0200 Subject: What's better about Ruby than Python? Message-ID: <8963D6370B323E4AA3241200F0EAF731035FC1AA@FCEXVEXM002.dcl.int.dexwired.net> > -----Message d'origine----- > De : Alex Martelli [mailto:aleaxit at yahoo.com] > Envoy? : mardi 19 ao?t 2003 13:58 > ? : python-list at python.org > Objet : Re: What's better about Ruby than Python? > > > Thus, the direct Python equivalent might be > > import __builtins__ > __builtins__.len = someotherfunction > > and THAT usage is very specifically warned against e.g. in > "Python in a Nutshell" -- you CAN do it but SHOULDN'T (again, one > can hope to eventually see it "officially" deprecated...!). > Would that mean the end of import sys sys.stdout=myLogger() ... print 'it works' ... sys.stdout=sys.__stdout__ ? Sad, sad, sad. Quite useful in some way. But I assume it could be replace by the new print >>>loggerInstace, "it works also, but is longer" ---OPQ, the man with unvolontary big signature..... -------------- next part -------------- ----------------------------------------------------------------- Ce message est confidentiel ; son contenu ne represente en aucun cas un engagement de la part de Dexia Credit Local ou de Dexia CLF Banque. Toute publication, utilisation ou diffusion, meme partielle, doit etre autorisee prealablement par l'emetteur. Si vous n'etes pas destinataire de ce message, merci d'en avertir immediatement l'expediteur. This message is confidential ; its contents do not constitute a commitment by Dexia Credit Local or Dexia CLF Banque. Any unauthorised disclosure, use or dissemination, either whole or partial, is prohibited. If you are not the intended recipient of the message, please notify the sender immediately. ----------------------------------------------------------------- Consultez notre site internet www.dexia-clf.fr La cle d'une gestion optimisee du secteur public local ----------------------------------------------------------------- From tjreedy at udel.edu Mon Aug 11 20:45:17 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 11 Aug 2003 20:45:17 -0400 Subject: Python vs. C# References: <3f357a9b@shknews01> Message-ID: "Christopher Barber" wrote in message news:pso8yq0b1d3.fsf at bandit.curl.com... > "Terry Reedy" writes: > > > "Brandon J. Van Every" wrote in message > > news:3f357a9b at shknews01... > > > What can I do with Python that I can't do with C#? > > > > Given that all Turing complete languages are theoretically equivalent, > > nothing, either way. > > Turing equivalence is probably the least interesting property of any > programming language and says absolutely nothing about its suitability for > real programming tasks. Huh??? This is a paraphrase of what I said. So why did you silently clip the remainder of my post where I went on to discuss practical suitability? Terry J. Reedy From grante at visi.com Fri Aug 8 11:53:41 2003 From: grante at visi.com (Grant Edwards) Date: 08 Aug 2003 15:53:41 GMT Subject: Need elegant way to cast four bytes into a long References: <3f33c209$1@news.si.com> Message-ID: <3f33c785$0$172$a1866201@newsreader.visi.com> In article <3f33c209$1 at news.si.com>, William S. Huizinga wrote: > I've got an array.array of unsigned char and would like to make a slice > of that array (e.g. a[0:4]) become one long like I would in "C" : > > l = ((unsigned long *) (&a[0]))[0]; Bad C programming. Your program isn't portable. > I have been getting what I want in this sort of manner : > > l = 0L > l = a[0] > l += a[1] << 8 > l += a[2] << 16 > l += a[3] << 24 > > but I think that's too wordy. Is there a more intrinsic and elegant way > to do this? How about this: l = a[0] + (a[1]<<8) + (a[2]<<16) + (a[3]<<24) Or you can use struct: l = struct.unpack(" hi , i want to use mcmillan installer 5_5b5 with python 2.3 so , no problem when i compil this prog but when i'm using installer i have an error D:\Python23\lib\fcntl.py:7: DeprecationWarning: the FCNTL module is deprecated; please use fcntl DeprecationWarning) i have an exe file , so double click doesn't do something .... wait and nothing if somebody have some idees thanks a lot hellprout From fredrik at pythonware.com Thu Aug 7 07:48:46 2003 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 7 Aug 2003 13:48:46 +0200 Subject: Sick problem with Python properties References: <2147483647.1060261376@[192.168.0.100]> Message-ID: webmaster at t-dose.de wrote: > See the following code. I wonder why in this case neither > setp() nor getp() is called !? > > yetix@/home/ajung(1)% cat test.py > class A: > > def __init__(self): > self._p=None > > def setp(self, p): > print 'set' > self._p = p*p > > def getp(self): > print 'get' > return self._p > > pp = property(getp, setp) > > > inst=A() > inst.p = 9 > print inst.p > > yetix@/home/ajung(2)% python2.3 test.py > 9 you need to 1) inherit from the "object" base class, and 2) change "inst.p" to "inst.pp" in the example. From martin at v.loewis.de Thu Aug 7 01:47:21 2003 From: martin at v.loewis.de (Martin v. =?iso-8859-15?q?L=F6wis?=) Date: 07 Aug 2003 07:47:21 +0200 Subject: Sources for Python 2.3? References: Message-ID: "Ivo" writes: > Where can I find the sources for the official stable 2.3 release? http://www.python.org/ftp/python/2.3/Python-2.3.tgz Regards, Martin From florian.proff.schulze at gmx.net Mon Aug 25 13:27:07 2003 From: florian.proff.schulze at gmx.net (Florian Schulze) Date: Mon, 25 Aug 2003 19:27:07 +0200 Subject: Python & memory usage References: <63701d2f.0308241633.30329433@posting.google.com> Message-ID: On 24 Aug 2003 17:33:45 -0700, lebo wrote: > I'm experimenting with using Python as a very low resource usage > systems management agent. Currently the best I'm getting is about a > 2.4MByte base usage (python interp only) and with application, > 4.8MByte memory footprint on WinXP. This is probably too high for sme > target systems - ideally under 3MByte memory usage is a good target > for a simple, quiesent stub agent - dynamic loading/unloading of > classes on top of this is ok. > Some general questions.... > 1) Are there ways to reduce the memory footprint of Python to make it > really lean? > 2) Compile options? > 3) Other options? > > Any thoughts appreciated. > L > You should measure the memory footprint on the target, not on WinXP. You can leave out builtin modules if you don't need them, this might give you some more memory, but most modules aren't that big. Florian From borcis at users.ch Mon Aug 4 13:15:54 2003 From: borcis at users.ch (Borcis) Date: Mon, 04 Aug 2003 19:15:54 +0200 Subject: anti-aliased 2D vector graphics References: Message-ID: <3F2E94CA.3060109@users.ch> Dave Brown wrote: > > Sounds like a job for...SVG! I was going to say the same thing. > > Here, have a look at this: http://www2.sfk.nl/svg I'd say before a python wrapper, the first things to look for are the open spec/doc at w3c, and a working renderer. Given that svg is an xml language, I find a wrapper like the one pointed at by your link, a bit paradoxical in the sense that it's first selling point appears to be the convenience of not seeing the xml representation while its intrinsic documentation isn't sufficient for that purpose. From peter at engcorp.com Fri Aug 22 14:31:16 2003 From: peter at engcorp.com (Peter Hansen) Date: Fri, 22 Aug 2003 14:31:16 -0400 Subject: Running one single test... References: Message-ID: <3F466174.CD790471@engcorp.com> Timothy Grant wrote: > > At work we use Perl and a home rolled unittesting mechanism. One of the things > I love about That testing mechanism is that I can run one single test. In > fact, I've configured Vim to run the current test and either tell me if it > passes or tell me the error when it doesn't. > > I'd love to do something similar with PyUnit, but I have yet to figure out how > to run one single test. > > Any help would be greatly appreciated. >From the command line, assuming your tests are functions named testNN() in a class called MyTestCase in a file called tests.py: python tests.py MyTestCase.test01 -Peter From pobrien at orbtech.com Fri Aug 29 10:50:12 2003 From: pobrien at orbtech.com (Patrick K. O'Brien) Date: 29 Aug 2003 09:50:12 -0500 Subject: Need good example database schema Message-ID: I'm looking for a good schema to use as an example for an object database system. Something like a books/authors/publishers or teachers/students/courses kind of thing. There are plenty of examples of such to be found, especially in the academic literature involving object databases, but most of them are pathetic. It's hard to take a schema seriously when it shows MarriedTeacher inheriting from Teacher, etc. I want something that makes proper use of inheritance, has classes with reasonable attributes, and does a decent job reflecting reality (ie, books can have more than one author, a teacher of one course could be a student of another, etc.). Any suggestions? -- Patrick K. O'Brien Orbtech http://www.orbtech.com/web/pobrien ----------------------------------------------- "Your source for Python programming expertise." ----------------------------------------------- From ark at gmx.net Fri Aug 29 05:14:31 2003 From: ark at gmx.net (Arne Koewing) Date: Fri, 29 Aug 2003 11:14:31 +0200 Subject: print without intervening space References: <5b42ae4.0308290102.3f04b90b@posting.google.com> Message-ID: <87ekz4zuyw.fsf@gmx.net> eadorio at yahoo.com (Ernie) writes: > Hi, > >>>> for x in range(10) > ... print x, > ... > > will output > > 0 1 2 3 4 5 6 7 8 9 >>>> > > What if somebody wants instead > > 0123456789 > > Maybe we need a printns (print with no spaces) ? just use: import sys for x in range(10): sys.stdout.write(x) From sjmachin at lexicon.net Fri Aug 1 19:37:57 2003 From: sjmachin at lexicon.net (John Machin) Date: 1 Aug 2003 16:37:57 -0700 Subject: 'long int too large to convert to int' in 'garbage collection' ignored References: Message-ID: "Peter Kwan" wrote in message news:... > Hi, > > I believe I have discovered a bug in Python 2.3. This is consistent with most developer's belief systems, which include code similar to: blame_list = ["God", "Bill Gates", "Intel", "software supplier", "team mate", "self"] and need application of the .reverse() method. > Could anyone suggest a > get around? > > When I tested my existing Python code with the newly released Python > 2.3, I get the following warning: > > FutureWarning: hex/oct constants > sys.maxint will return positive > values in Python 2.4 and up > > It is because I used some constants such as 0x80ff3366, so I change it > to 0x80ff3366L, hoping to get rid of the warning. > > But then I get the following fatal error: > > Exception exceptions.OverflowError: 'long int too large to convert to > int' in 'garbage collection' ignored > Fatal Python error: unexpected exception during garbage collection > > abnormal program termination > > I have tried testing the same code in Python 1.5.2 to Python 2.2. In all > these versions, there is no error, no matter I use 0x80ff3366 or > 0x80ff3366L. But in Python 2.3, I get warning or fatal error in these > cases. > > The details are as follows: > > The code is running on Windows 2000. Python 2.3. > > The Python code calls a C library and pass 0x80ff3366 or 0x80ff3366L to > the C library. In the C library, it calls > > //convert the given argument to Long in case it is not already Long > PyObject *longObj = PyNumber Long(argObj); Danger; you are not testing for an error here. Some clueless caller could supply an argument that can't be converted to Python Long. You should do something like this: PyObject *longObj; longObj = PyNumber Long(argObj); if (longObj == NULL) something_nasty_happened(....); > > //get the value of the Python Long variable > long ret = PyLong AsLong(longObj); > > I have done some testing and confirm that the error does not happen if > the second line "PyLong AsLong" is commented out. Also, the erorr does > not happen immediately when executing the above statement. It occurs > slightly afterwards (during garbage collection?). You need to distinguish between the happening of the error and the reporting of it. The error *happens* when you try to convert a long int value to int type and it won't fit. You are not testing for the error and clearing it, so it is *reported* later. Any behavioural difference between versions is probably due to (a) extra checking in the garbage collection phase in Python 2.3 (b) you do a one-shot test and immediately exit Python or somehow trigger a garbage collection before executing some other code -- if you do more Python execution I would expect the delayed exception to be triggered whatever the version of Python. Here's what the doco says: """For C programmers, however, error checking always has to be explicit. All functions in the Python/C API can raise exceptions, unless an explicit claim is made otherwise in a function's documentation. In general, when a function encounters an error, it sets an exception, discards any object references that it owns, and returns an error indicator -- usually NULL or -1. A few functions return a Boolean true/false result, with false indicating an error. Very few functions return no explicit error indicator or have an ambiguous return value, and require explicit testing for errors with PyErr_Occurred()""" The last sentence applies to PyLong_AsLong(). It is of course very remotely possible that the behaviour of PyLong_AsLong() changed in 2.3 but your posting is very remote from evidence of that. > > Could someone suggest a word around without touching the C library, and > without making the Python code too ugly? > Your C library needs (IMHO) touching so that, with any Python version, it (a) permits either int or long int arguments (b) detects and reports bad argument types (c) detects argument values that are not in your permissible range (d) checks all API function calls for errors. By the way, what is your permissible range for this argument? Is it a 32-bit vector, or is it whatever what (used to) fit in a Python int? What should happen on a 64-bit machine? As a design principle, you are the expert who is providing the library to non-experts, so the Python code that has to be written to call a function in your library should be no more ugly than having to have "L" at the end of constants, if necessary. The work-around should be done in your C code. Have you considered using Pyrex? Even if you don't use it to develop whole modules, looking at the C code that's generated can be very useful if you need help on how to do reference counting or error handling (including how to clean up before you return from your function, both in normal circumstances and when an error has been detected). Hope this helps, John From stefan.behrens.usenet at gmx.net Sat Aug 9 16:09:00 2003 From: stefan.behrens.usenet at gmx.net (Stefan Behrens) Date: Sat, 09 Aug 2003 22:09:00 +0200 Subject: py2exe and wxCalendarCtrl? Message-ID: Hi, does anybody know how I can get py2exe to work with wxPython's wxCalendarCtrl? Currently, I have just a "standard" setup.py, and py2exe gives me a syntax error. Do I need to include any special extension and how? Below is the output I get as well as a small demo app to reproduce the problem. I'm using python 2.2.3, wxPython 2.4.0.7, py2exe 0.4.1 TIA /Stefan. P.S. Things work fine without the calendar control (but I need it ;) ---error message--- E:\python\test1>f:\win1_expand\python\python.exe setup.py py2exe running py2exe running build running build_scripts not copying wxApp1.py (up-to-date) running install_scripts not copying build\scripts-2.2\wxApp1.py (output up-to-date) +---------------------------------------------------- | Processing script wxApp1.py with py2exe-0.4.1 +---------------------------------------------------- Searching modules needed to run 'wxApp1.py' on path: ['E:\\python\\test1\\build\\bdist.win32\\winexe\\lib\\win1_expand\\python\\Lib\\ site-packages', '', 'E:\\python\\test1', 'f:\\win1_expand\\python\\DLLs', 'f:\\w in1_expand\\python\\lib', 'f:\\win1_expand\\python\\lib\\lib-tk', 'f:\\win1_expa nd\\python', 'f:\\win1_expand\\python\\lib\\site-packages'] Traceback (most recent call last): File "setup.py", line 7, in ? scripts = ["wxApp1.py"], File "f:\win1_expand\python\lib\distutils\core.py", line 138, in setup dist.run_commands() File "f:\win1_expand\python\lib\distutils\dist.py", line 902, in run_commands self.run_command(cmd) File "f:\win1_expand\python\lib\distutils\dist.py", line 922, in run_command cmd_obj.run() File "F:\WIN1_E~1\python\Lib\site-packages\py2exe\build_exe.py", line 590, in run mf.run_script(script) File "F:\WIN1_E~1\python\Lib\site-packages\py2exe\tools\modulefinder.py", line 114, in run_script self.load_module('__main__', fp, pathname, stuff) File "F:\WIN1_E~1\python\Lib\site-packages\py2exe\tools\modulefinder.py", line 282, in load_module self.scan_code(co, m) File "F:\WIN1_E~1\python\Lib\site-packages\py2exe\tools\modulefinder.py", line 339, in scan_code self._safe_import_hook(name, m, fromlist) File "F:\WIN1_E~1\python\Lib\site-packages\py2exe\tools\modulefinder.py", line 297, in _safe_import_hook self.import_hook(name, caller) File "F:\WIN1_E~1\python\Lib\site-packages\py2exe\tools\modulefinder.py", line 126, in import_hook q, tail = self.find_head_package(parent, name) File "F:\WIN1_E~1\python\Lib\site-packages\py2exe\tools\modulefinder.py", line 168, in find_head_package q = self.import_module(head, qname, parent) File "F:\WIN1_E~1\python\Lib\site-packages\py2exe\tools\modulefinder.py", line 252, in import_module m = self.load_module(fqname, fp, pathname, stuff) File "F:\WIN1_E~1\python\Lib\site-packages\py2exe\tools\modulefinder.py", line 267, in load_module co = compile(fp.read()+'\n', pathname, 'exec') File "", line 27 self.calend = wxCalendarCtrl(self, -1, pos = (20,25)) ^ SyntaxError: invalid syntax ---code-- #Boa:Frame:wxFrame1 from wxPython.wx import * from wxPython.gizmos import * from wxPython.calendar import wxCalendarCtrl def create(parent): return wxFrame1(parent) [wxID_WXFRAME1] = map(lambda _init_ctrls: wxNewId(), range(1)) class wxFrame1(wxFrame): def _init_utils(self): # generated method, don't edit pass def _init_ctrls(self, prnt): # generated method, don't edit wxFrame.__init__(self, id=wxID_WXFRAME1, name='', parent=prnt, pos=wxPoint(285, 318), size=wxSize(721, 394), style=wxDEFAULT_FRAME_STYLE, title='wxFrame1') self._init_utils() self.SetClientSize(wxSize(713, 367)) def __init__(self, parent): self._init_ctrls(parent) self.calend = wxCalendarCtrl(self, -1, pos = (20,25)) ---setup.py--- from distutils.core import setup import py2exe setup(name = 'test1', version = '0.1', scripts = ["wxApp1.py"], ) From lists at webcrunchers.com Sun Aug 3 20:09:11 2003 From: lists at webcrunchers.com (John D.) Date: Sun, 3 Aug 2003 17:09:11 -0700 Subject: Example code for anydbm wanted... Message-ID: Does anyone have any good example code that shows how to use the "anydbm" wrapper tp interface with a very simple database. like some examples of how to use "dumbdbm"? Then perhaps at a later time, I'm going to want to then interface it to a more robust database like PostGreSQL or mySQL. But I want to external interface to "hide" the specifics and have a really generic interface. I already played with Python's interface with PostGreSQL, but they don't follow the generic Python models. At least my prev version didn't. John From mrroach at okmaybe.com Thu Aug 28 11:24:45 2003 From: mrroach at okmaybe.com (Mark Roach) Date: Thu, 28 Aug 2003 15:24:45 GMT Subject: pure Python DB References: <9a6d7d9d.0308261756.5b37cbf4@posting.google.com> <7876a8ea.0308270634.26d02fec@posting.google.com> Message-ID: On Wed, 27 Aug 2003 07:34:01 -0700, David Rushby wrote: [...] > No need to go client/server. Embedded Firebird supports concurrent > transactions with configurable isolation levels, foreign keys, views, > stored procedures, and other features one would expect from a > full-fledged RDBMS. Plus it's fast--kinterbasdb with embedded > Firebird 1.5-rc4 is about twice as fast as pysqlite 0.4.3 in various > trivial speed tests I've tried. I thought Firebird was a web browser?! couldn't help myself :-) -Mark From oliphant.travis at ieee.org Tue Aug 5 18:16:02 2003 From: oliphant.travis at ieee.org (Travis Oliphant) Date: Tue, 05 Aug 2003 16:16:02 -0600 Subject: Making a def file from python23.lib for mingw32 Message-ID: Has anyone succeeded in making a usable def file from python23.lib so that which can be used to compile extensions with mingw32? I have tried pexports (0.43 and 0.42h) and impdef which have both failed stating that the file is the wrong type. I have generated a manual .def file using nm and sed but then I still get unresolved symbols (of the _imp__XXXXXX variety) when I try to compile an extension. Any ideas are appreciated. -Travis Oliphant From tjreedy at udel.edu Thu Aug 7 12:39:06 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 7 Aug 2003 12:39:06 -0400 Subject: Bug? If not, how to work around it? References: <060820031458029244%mday@apple.com> <09udnV37oMEUDqyiU-KYgw@comcast.com> Message-ID: "Gon?alo Rodrigues" wrote in message news:md94jvccu02b9dv5890k34629rkot79roj at 4ax.com... > On Thu, 07 Aug 2003 00:54:03 +0100, Gon?alo Rodrigues > wrote: > > >On Wed, 6 Aug 2003 19:46:39 -0400, "Terry Reedy" > >>If you don't want to do what works, > >>why ask us to bother answering? > >Because it may not work. That is, the use case I have in mind serves > >as proxy for an object that may or may not have __iter__. IOW if I > >stick __iter__ I have to code a second class, etc... etc... Oh well... > Just to make things clearer, having iter(self.__obj) as in > > def __iter__(self): > return iter(self.__obj) > > Would mean that my proxy class would become an iterable. And that is > not what I want because *other* parts in my code check that an object > is in iterable by looking for __iter__. As I understand your clarification, you want the proxy to actually be iterable (via delegation) when given as an arg to iter(), but to not look iterable to other code (call it test_iterable()). And your test_iterable() *currently* looks only for the presence/absence of the very thing needed to make iter() work. It is definitely not a Python bug that this does not work. But I am still not sure of your spec for test_iterable(). If you want it to always return false for the proxies, it needs another indicator that iter() doesn't use (which is what you were trying to do with your __getattr__). So add the following line to your proxy class: not_iterable = True # or 1 if pre2.2 and have test_iterable check this next if it does find __iter__. def test_iterable(obj): #untested return hasattr(obj, '__iter__') and not hasattr(obj, 'not_iterable') If you want it to return true or false (for proxies) according to the wrapped object, then it must directly or indirectly test the wrapped object. Terry J. Reedy From adalke at mindspring.com Wed Aug 13 14:54:17 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Wed, 13 Aug 2003 12:54:17 -0600 Subject: Namespaces, classes, and using standard modules References: Message-ID: Dan Rawson > Hmm . . . I'm still a bit confused . . . The naming doc says that > > from MyClass import MyClass > > will only import the stuff that is part of the class scope (if I read it correctly). But it > appears to also read and use the 'import os' at the module level for the MyClass.py file. > > The second question is why "import os" doesn't work at the interactive prompt; once > I say that, isn't that a 'global' ?? Every module has its own namespace. The interactive prompt has its own namespace, called "__main__". This is not the global namespace. (There is a 'global' namespace called "__builtin__", but you should almost never put anything into it because doing so most often indicates 'bad', or at least non-standard/non-Pythonic programming style.) All code in a module looks for so-called globals only in the module's namespace and, failing that, in the __builtin__ namespace. So your MyClass.MyClass.show method looks for 'os' first in the MyClass module and then in the __builtin__, finding it in neither. This is what's often called "static scoping," as compared to "dynamic scoping," which is what you are looking for. That wouldn't lead to easy to use code because then when you import a class or function you would need to also import all the modules it uses. I sure don't want to remember all those. Andrew dalke at dalkescientific.com From adalke at mindspring.com Sat Aug 30 01:54:47 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Sat, 30 Aug 2003 05:54:47 GMT Subject: OT: Celebrity advice (was: Advice to a Junior in High School?) References: Message-ID: Alex Martelli: > ID cards are a tool that can make government more efficient -- for either > good or evil purposes equally well. Personally, I don't think it's uses for good are all that clear for making government more efficient. It costs money to develop and maintain an ID card system; estimates for the UK "entitlement card" sytem were on the order of 39 pounds (http://www.theregister.co.uk/content/6/31581.html ) per person per renewal. Small compared to the average household income of about 23k GBP, but non-trivial. Add to that the hassles when you don't have an ID card: if you forget it / have it stolen / lose it, does that prevent you from getting medical card? get you arrested (as in Belgium where an ID card is required)? prevent you from voting? Can you get out of jury duty (in countries which have citizen jurors) by claiming you lost your id? Are you arrested if it isn't replaced in time? Top it off with improper assumptions people have about the validity of said card and likelihood of misuse, and you get such modern problems as identity theft, or credit records messed up because of simple transcription errors. There is better efficiency in tracking down someone known, although again it's not unknown for that information to be wrong. (I recently read a case where a man was almost sent to Miami on a 30 year old warrant even though the name on the warrant wasn't quite his - the middle name was different - and spent several days in jail before his figureprints were checked. Would an id card have helped there? http://www.sptimes.com/2003/08/21/Tampabay/Here_s_one_guy_who_re.shtml ) But you still need to know the person (and be correct). Consider another possibility - what about hiring more police officers instead? That would help track down the person who commited the crime. Figure renewal of every seven years means ~6GBP/yr., If a police officer is paid average wages, then with a factor of 2 for overhead means that 8,000 cards is about the same as another police officer. Minors might not have cards, so that's about, say, 15,000 people. (Wild guess.) http://www.llcc.cc.il.us/gtruitt/SCJ290spring2002/France%20CJS1.pdf claims there is about 1 officer per 300 people, so ID cards correspond to about 2% increase in the police force. So I am not convinced that ID cards can make a government more efficient, or at least not all that much more efficient. (A rhetorical question: Belgium requires ID cards. Does that make the Belgium government more efficient than, say, the Dutch one?) > Similarly, promoting Python use in government-used programming makes > government potentially more efficient. Generally, tools are morally > neutral -- for an engineer there may be some moral (or, equally, > aesthetic -- "beauty is truth, truth, beauty") value in a specific > tool, but that's a biased viewpoint;-). "potentially more efficient" is different. I can say "potentially SNOBOL use in government-used ...." and be equally correct. Attempting to verify that shows otherwise. And potentially ID cards could make a government more efficient, but there may be other ways which make the government even more efficient, for less cost, and without the human rights concerns. Chaining everyone to a stake on a limited line may make government potentially more efficient. (Easy to track people down - don't need the change-of-address system for the postal service! - very hard to commit any crimes). Doesn't mean it's a good idea. Andrew dalke at dalkescientific.com From logiplex at qwest.net Mon Aug 18 18:38:27 2003 From: logiplex at qwest.net (Cliff Wells) Date: Mon, 18 Aug 2003 15:38:27 -0700 Subject: What's better about Ruby than Python? In-Reply-To: References: <38ec68a6.0308172319.431a4fde@posting.google.com> Message-ID: <1061246306.10907.56.camel@software1.logiplex.internal> On Mon, 2003-08-18 at 15:14, Brandon J. Van Every wrote: > Lulu of the Lotus-Eaters wrote: > > The second surest sign that a post is a troll is if the author > > includes: > > > >>> This is not a troll. > > > > The first surest sign that a post is a troll is if the author is: > > > >> "Brandon J. Van Every" > > Man, it's clear that I've got an entire hate group around here to > exterminate! I wonder how long it's going to take? Maybe this is a > positive sign of Python's growth: it's got enough critical mass to attract > just about anybody, not just people who want to get things done. At any > rate, welcome to my killfile. The major problem appears to be your mode of communication. At first I took your questions seriously, then I began to think you were trolling (and a rather clever troll at that), and finally I've come to the conclusion that you're not trolling, rather merely arrogant and abrasive. You seem to get a large number of people who perceive you as a troll. While I no longer believe this to be true, the sheer number of people in so many different newsgroups should perhaps indicate to you that you need to take a break from your local D&D group and socialize a bit. You are lacking some fundamental skills in this area. You're clearly intelligent and have in fact brought up some interesting topics, but your lack of tact tends to take them off-track rather quickly. For instance, do you really think publicly announcing that someone is in your killfile hurts their feelings or somehow vindicates you? That's rather pathetic, but makes sense given the source. I'd venture that mentality is most common at the pre-teen level of social interaction. Regards, -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 (800) 735-0555 From ktilton at nyc.rr.com Fri Aug 22 15:12:07 2003 From: ktilton at nyc.rr.com (Kenny Tilton) Date: Fri, 22 Aug 2003 19:12:07 GMT Subject: For Kenny Tilton: Why do I need macros revisited. References: <3f45484f$1_6@corp.newsgroups.com> <3F45A7BF.4060806@nyc.rr.com> <8dk1b.2825$Ej6.1159@newsread4.news.pas.earthlink.net> Message-ID: <3F466BD9.1080704@nyc.rr.com> Andrew Dalke wrote: > Kenny Tilton: > >>We have pointed out again and again >>that macros are no harder to understand than functions or classes, but >>no one addresses that point. > > > What about Terry's comment, based on the above URL: > ) Reading the third referenced page on Macros, I notice that the amount > ) of syntax definition for the macro sublanguage is as large as a > ) substantial portion (one-third?) of that for core Python (if condensed > ) to the same density). So, just by definitional bulk, having it in the > ) language would not be a free ride. Oy. This comment is about understanding how to write macros. We are talking about whether: (with-open-file (f "my.data" <...options...>) (do-fun-things-with f)) ...is harder to understand than: (open-file-and-do "my.data" <...options...> :do-this (lambda (f) (do-fun-things-with f))) btw, /writing/ macros takes a while to learn, or it did for me anyway, because one has moved to a different space than a programmer normally occupies, somewhere inside the compiler you might say. So some of the time you are typing in code for run-time and some of the time you are typing in code that runs at compile time to produce the code that runs at runtime. And there's some weird syntax, with backquotes and coomas and ampersands. Great fun, once it is second nature, but till then...the neat thing is realizing you can put in debug statements that execute while the macro is being expanded, not at run time. And you can have a bug in the expanding code such that evaluating the form dies before it begins being evaluated! > > >>Strangely, quite a few of you have also conceded macros can leverage a >>language. > > > Leverage a language ... for what? And for whom? The keystone macro of the RoboCup client I plan to share with soccer hooligans everywhere is DEFTASK: (deftask &key achieved subtasks wait-on-subtasks? attempt retry-when) achieved is a rule for deciding when the task has been achieved. subtasks are subtasks to be completed (achieved) before the task at hand is attempted, unless... wait-on-subtasks? is nil, in which case the task can decide on its won when to check if it has alreadt been achieved (you'll need an example). attempt is code which generates a command to the soccer server, hopefully leading to task achievement retry-when tells the engine when to try again if not yet achieved. eg, don't turn again to look for the ball until we have gotten a new "see" message. Now that's pretty slim doc, but there will be more and examples galore (and an on-line help desk ), but some points: No, no one looking at my code has ever seen deftask before. But if they have done any lisp at all, they will know I have built a little task solving engine for them. They will know because I used standard Lisp terminology, the "def" prefix. They will understand all the keywords, but immediately scream for documentation because keywords do not a user's guide make. They will also see that the style is declarative, which is meant to be helpful (and is) but they will sweat bullets until they have a solid feel for how the engine works inside ("why did a completed subtask start getting solved again"). I'll have to come clean on the guts of the engine. Or, as some of the folks on our team have done, they can macroexpand any deftask form. They can look at the source of deftask as well, but that can be harder because the final output is kinda disguised by all the code which builds the final output. Once they see the astonishing output, they will likely decide just to have me provide a functional spec so they do not have to worry about the engine internals. Like I do. They just write: (deftask head-for-ball () ;; literally set body heading for ball () :achieved (bwhen (ball (^ball)) (< (+ .neck. (seen-dir ball)) 10)) :subtasks (list (mktask find-ball)) :attempt (bwhen (ball (^ball)) (let ((correction (+ .neck. (seen-dir ball)))) (ptrc nil "correcting" correction) ;;debug macro! `(turn ,correction)))) The unadvertised synatx above (the two () forms near the beginning, are a giveaway that deftask expands into the familiar (to lispniks) defclass form. ie, deftask is implemented as defclass. Again, I make an effort to keep the syntax lispy and recognizable and familiar and all that good stuff. They can add slots to their task, have supertasks, etc etc. So the defclass power is /leveraged/ to make deftask even better than i could make it. Generic functions automatically can be dispatched by soccer task, without me lifting a finger. In the end, a bunch of people with just an interest in machine learning and genetic algorithms and soccer can have some fun concnetrating just on the ML and GA and football. Because I am providing a task-executing "language" which deals with the soccer server for them. As for what the above would look like without macros: (defmodel head-for-ball (task) () (:default-initargs :wait-on-subtasks-p t :kids (c? (let ((task self) (self (player self))) (mapcar (lambda (subtask) (if (symbolp subtask) (make-instance subtask :player self) subtask)) (thekids (list (mktask find-ball)))))) :achieved-body (lambda (cells::c &aux (task (cells::c-model cells::c)) (self (player task))) (declare (ignorable self task)) (bwhen (ball (^ball)) (< (+ .neck. (seen-dir ball)) 10))) :retry-when-body (lambda (cells::c &aux (task (cells::c-model cells::c)) (self (player task))) (declare (ignorable cells::c self task)) nil) :attempt-body (lambda (cells::c &aux (task (cells::c-model cells::c)) (self (player task))) (declare (ignorable self task)) (bwhen (ball (^ball)) (let ((correction (+ .neck. (seen-dir ball)))) (ptrc nil "head-for-ball correcting" correction) `(turn ,correction)))))) Not too bad, but then you have to expand defmodel. :) -- kenny tilton clinisys, inc http://www.tilton-technology.com/ --------------------------------------------------------------- "Career highlights? I had two. I got an intentional walk from Sandy Koufax and I got out of a rundown against the Mets." -- Bob Uecker From ecartis at unicode.org Fri Aug 22 21:24:40 2003 From: ecartis at unicode.org (Ecartis) Date: Fri, 22 Aug 2003 21:24:40 -0400 (EDT) Subject: Ecartis command results: No commands found Message-ID: Request received for list 'unicode' via request address. >> Please see the attached file for details. Unknown command. No commands detected in message. ** Ecartis Help File ** By Rachel Blackman, JT Traub and Ryan T. Dean TO GET A LIST OF LISTS: Send a message to the ecartis account on the server with a subject of "lists". A list of lists hosted by the server will be returned to you. TO SUBSCRIBE TO A LIST: Send a message to the ecartis account on the server (you can just reply to this message). In the subject field, enter "subscribe [listname]". Or, you can send a message to "[listname]-request" with a subject of "subscribe". TO UNSUBSCRIBE FROM A LIST: Send a message to the ecartis account on the server (you can just reply to this message). Enter "unsubscribe [listname]" in the subject field. You can also send a message to "[listname]-request" with a subject of "unsubscribe". While you should NOT send your unsubscribe command to the list itself, Ecartis will attempt to trap such erroneous postings and forward them to the list administrators for proper handling. TO GET A DIGEST EVERY DAY: Send a message to the ecartis account on the server with a subject of "set [listname] digest". This will turn on digests, and you will receive a digest however often the server is configured to send them. TO STOP GETTING A DIGEST: Send a message to the ecartis account on the server with a subject of "unset [listname] digest". This will turn off digest mode, and instead you will receive an eMail every time something is posted to the list. TO GET A DIGEST AND NORMAL POSTS: Send a message to the ecartis account on the server with a subject of "set [listname] digest2". This will activate digest mode with normal posting. As each message is posted to the list it will be sent to you, and you will receive a digest as well. This flag should be used INSTEAD of digest, NOT IN ADDITION TO. To stop receiving digests in addition to normal posts, send a message to the ecartis account with a subject of "unset [listname] digest2". You will go back to receiving normal posts. TO FIND OUT WHO IS ON A LIST: Send a message to the ecartis account on the server with a subject of "who [listname]". You will receive a list of people subscribed to the list who are not hidden. Admins will be able to see everbody, including those hidden. TO HIDE ON A LIST: Send a message to the ecartis account on the server with a subject of "set [listname] hidden". You will no longer appear on WHO queries to the listserver. No one (except Admins) will know you are subscribed to the list unless you post to it (in which case those people on the list will know you posted if nothing else). TO STOP HIDING ON A LIST: Send a message to the ecartis account on the server with a subject of "unset [listname] hidden". You will then show up on WHO queries to the listserver. TO GO ON VACATION: Send a message to the ecartis account on the server with a subject of "set [listname] vacation". You will remain subscribed to the list but will not receive any eMail as long as this flag is set. To come back from vacation, eMail the ecartis account with a subject of "unset [listname] vacation". TO CHECK ON YOUR OWN STATUS: Send a message to the ecartis account on the server with a subject of "stats [listname]". You will get a list of all the flags currently set on your account. TO GET A LIST OF FLAGS AVAILABLE: Send a message to the ecartis account on the server with a subject of "flags". An eMail will be sent to you with the available flags that you can set on your account. TO GET A LIST OF COMMANDS AVAILABLE: Send a message to the ecartis account on the server with a subject of "commands". An eMail will be sent to you with all the commands that the server and any installed modules offer. --- Ecartis v1.0.0 - job execution complete. From fredrik at pythonware.com Fri Aug 15 03:24:10 2003 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 15 Aug 2003 09:24:10 +0200 Subject: dict->XML->dict? Or, passing small hashes through text? References: <20030815042536.GA19960@incise.org> Message-ID: "mackstann" wrote: > I'm thinking that the ideal way that it would happen with XML in the mix > would be something like: > > msg = {} > msg["foo"] = 1 > msg["bar"] = "hello" > msg["abc"] = "text" > > xmsg = xmlMessage(msg) > > xmsg would now be a string such as: > '1hellotext' (that's not valid XML: there can be only one toplevel element in an XML document. that's easy to fix, of course) > I could then send that over the wire, and on the other end, do something > like: > > msg = xmlMessage2dict(xmsg) > > And I'd have my dict back. I don't think I'll be using values other > than strings and ints. Dealing with variable types is something I'm > unsure of, e.g. making sure that I get back msg["foo"]==1, not > msg["foo"]=="1". here's a minimal implementation, based on my ElementTree module: from elementtree import ElementTree def xmlMessage(dict): elem = ElementTree.Element("message") for key, value in dict.items(): if isinstance(value, type(0)): ElementTree.SubElement(elem, key, type="int").text = str(value) else: ElementTree.SubElement(elem, key).text = value return ElementTree.tostring(elem) def xmlMessage2dict(message): elem = ElementTree.XML(message) assert elem.tag == "message" dict = {} for elem in elem: if elem.get("type") == "int": dict[elem.tag] = int(elem.text) else: dict[elem.tag] = elem.text return dict msg = {} msg["foo"] = 1 msg["bar"] = "hello" msg["abc"] = "text" xmsg = xmlMessage(msg) print xmsg -> hellotext1 print xmlMessage2dict(xmsg) -> {'foo': 1, 'bar': 'hello', 'abc': 'text'} you can get the elementtree source code via this page: http://effbot.org/zone/element-index.htm note that this approach places some limitations on your data; the keys must all be valid XML names, you must use Unicode strings if keys or values contain non-ASCII data, you can only use integers and strings, etc. tweak as necessary. if the XML format doesn't really matter, you can use Python's standard xmlrpclib module: import xmlrpclib def xmlMessage(dict): # dumps requires a tuple return xmlrpclib.dumps((dict,)) def xmlMessage2dict(message): result, method = xmlrpclib.loads(message) return result[0] # unwrap From adalke at mindspring.com Sat Aug 23 00:41:20 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Sat, 23 Aug 2003 04:41:20 GMT Subject: Modifying the {} and [] tokens References: Message-ID: Geoff Howland: > I want to modify the {} and [] tokens to contain additional > functionality they do not currently contain, such as being able to add > dicts to dicts, and other things that would be very helpful for me and > my team mates to have. You can't. Not without changing the underlying implementation. > So I can obviously override dict and it works when I specifically call > dict(), but it does not work with the syntax sugar {}. That's because you created a new dict. You didn't modify the actual type {} uses in the intepreter. {} is not simple syntactic sugar for dict() in the local namespace. BTW, if it were, then dict = 8 a = {3: 4} would fail. > How can I make this work? Can this also work to overload strings with > the "" and '' tokens? You can't. What's wrong with using your derived dict? Why must you use {}? You can't modify the fundamental type used by strings either. Andrew dalke at dalkscientific.com From mwilson at the-wire.com Wed Aug 20 10:40:27 2003 From: mwilson at the-wire.com (Mel Wilson) Date: Wed, 20 Aug 2003 10:40:27 -0400 Subject: Python newbie help References: <87fa5cfa.0308181126.c61bfa2@posting.google.com> Message-ID: In article , Dennis Lee Bieber wrote: > Whereas I'd find a text that basically follows your desired scheme to >be the boring, non-motivational one. Anything that basically says: > > We are going to produce a program to do XYZ. > > Here's the code for step one... > > Here's the code for step two... > > Here's the modifications to the code in step one to use the code in >step two... > > This may be sufficient to learn the syntax of the language, but it is >not teaching me how to /think/. The deadly " ... By Example" books. I think these are even a crummy way to learn syntax, because I don't believe syntax can effectively be split away from thinking. I think book editors like them for their strong story lines. I think beginners like them because, seeing all that code, they think they're getting the Real Thing. But finally such books have everything to do with the author's programs, and nothing to do with my programs. As soon as I try to do something the author didn't I find the book has left me stranded. I'm stuck with imagining some possible syntax consistent with what I've seen, and fiddling with random changes until something seems to work. My hat's off to Daniel D. McCracken. Regards. Mel. From abuseonly at sgrail.org Mon Aug 25 01:00:20 2003 From: abuseonly at sgrail.org (derek / nul) Date: Mon, 25 Aug 2003 05:00:20 GMT Subject: Comments on my "Python Introduction" slides References: <33803989.0308240000.35b9bf1f@posting.google.com> <33803989.0308240644.3090f039@posting.google.com> <3f492761$0$49117$e4fe514c@news.xs4all.nl> <33803989.0308242053.a286d1d@posting.google.com> Message-ID: On 24 Aug 2003 21:53:43 -0700, tebeka at cs.bgu.ac.il (Miki Tebeka) wrote: >Hello Irmen, > >> > Should be http://www.cs.bgu.ac.il/~tebeka/pyintro.htm >> >> I'm sorry to say this but because the site appears to >> be made in Powerpoint, and then exported to MSHTML, >> it sucks in my browser (Mozilla). No cigar. >Sorry. Sadly we work on MS environment... I run python in an MS environment!! From nospam at maniacxs.de Mon Aug 11 08:55:31 2003 From: nospam at maniacxs.de (Lukas Kasprowicz) Date: Mon, 11 Aug 2003 14:55:31 +0200 Subject: convert tuple to string Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi Folks, My Proglem is, I get after a query on a mysql database with module MySQLdb a tuple but I need this output from database as a string. can anybody help? - -------------- database --------- import MySQLdb def select(fields, tables, where): db=MySQLdb.connect(host=db_host,user=db_user,passwd=db_passwd,db=db_db) c = db.cursor() c.execute("SELECT %s FROM %s WHERE %s" %(fields,tables,where)) return c.fetchall() db.close() OUTPUT: - -------------- (('6610 at 8210',), ('akku',), ('cover',), ('ladekabel',), ('kfz',), ('tischladestation',), ('dummy',), ('Hansytasche',), ('poster',), ('o2',), ('Vodafone',), ('T-Mobile',), ('D1',), ('D2',), ('E+',), ('Eplus',), ('tasche',), ('zubeh\xf6r',), ('Quertasche',), ('Ledertasche',), ('Boom',), ('BELEUCHTUNG',), ('Tastaturmatte',), ('Dummys',), ('Zubeh\xf6rset',), ('TASTATUR',), ('Tastatur',), ('Mittelgeh\xe4use',), ('fast',), ('Displayschutzfolie',), ('Radio',), ('Tischlader',), ('Geh\xe4use\xf6ffner',), ('Oberschale',), ('1 Woche',), ('Alubox',), ('Echtledertasche',), ('E Plus',), ('E+',), ('Eplus',)) greetz Lukas - -- - --------------------------------------------------------- Das einzige Mittel gegen Aberglauben ist Wissenschaft. (Henry Thomas Buckle) -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2-rc1-SuSE (GNU/Linux) iD8DBQE/N5JKHNh65/SR0v0RAmDIAKCUUcd4FuXI9t7g8aU7Mt5nDQaTyQCgoeoN 3yqqMGuLMvWLNgUNDjJk6lY= =LRtn -----END PGP SIGNATURE----- From oren-py-l at hishome.net Thu Aug 7 07:39:02 2003 From: oren-py-l at hishome.net (Oren Tirosh) Date: Thu, 7 Aug 2003 07:39:02 -0400 Subject: email client written with python + wxWindows In-Reply-To: <409a56e2.0308062211.456575df@posting.google.com> References: <409a56e2.0308062211.456575df@posting.google.com> Message-ID: <20030807113902.GA92985@hishome.net> On Wed, Aug 06, 2003 at 11:11:52PM -0700, Shagshag wrote: > hello, > > does anyone know of a full python + wxWindows email client ? The Chandler project from the Open Source Applications Foundation contains a mail client, calendar and other collaboration tools. It's written in Python and wxWindows. http://osafoundation.org/our_product_desc.htm It's just at version 0.1, though. Oren From imbosol at aerojockey.com Thu Aug 7 19:16:11 2003 From: imbosol at aerojockey.com (Carl Banks) Date: Thu, 07 Aug 2003 23:16:11 GMT Subject: Gmpy References: <8578e2c1.0308070630.5fb70c22@posting.google.com> Message-ID: <%4BYa.85$Ad4.79@nwrdny03.gnilink.net> Alex Martelli wrote: > Carl Banks wrote: > >> Jean-Pierre Andreaux wrote: >>> Gmpy module was a wrapper of the GNU MP library. It seems that no >>> evolution is done on this module since 2001. Indeed, Gmpy is not >>> supported in Python 2.2 nor 2.3. >>> >>> My question is the following: what is the better replacement solution >>> for manipulating long numbers. I want to do long numbers >>> exponentiations. Thanks in advance for your answers. >> >> >> An alternative is egenix mxNumber package, still in beta stage. >> >> http://www.egenix.com/files/python/mxNumber.html >> >> I couldn't use gmpy because I needed floating point, and mxNumber also >> wraps the floating point functionality. It seemed to work ok. > > gmpy also wraps the floating-point functionality of GMP: > >>>> print gmpy.mpf(7,99)/3 > 2.333333333333333333333333333333333333333 I'm sorry--I was thinking of the mpz module. I remember looking at gmpy but passed on it for some reason--probably something silly. In any case, mxNumber worked well enough so I stuck with it. -- CARL BANKS "You don't run Microsoft Windows. Microsoft Windows runs you." From missive at frontiernet.net Sun Aug 3 22:13:57 2003 From: missive at frontiernet.net (Lee Harr) Date: Mon, 04 Aug 2003 02:13:57 GMT Subject: True References: Message-ID: In article , Daniel Klein wrote: > In Python 2.2 I use to have > > true = (1 == 1) > false = not true > > This was at the recommendation of someone on this list some time ago. > The reason (if I remember correctly) was that setting > > true = 1 > false = 0 > > were not true booleans. > > Now the expression (1 == 1) returns 'True', and caused a bug in my Actually, it returns True, not 'True' > code. So my question is what is the proper method for setting booleans > in 2.3? > > Really confused, > True and False are now built in to 2.3 >python Python 2.3 (#1, Aug 1 2003, 15:18:54) [GCC 2.95.4 20020320 [FreeBSD]] on freebsd4 Type "help", "copyright", "credits" or "license" for more information. >>> dir(__builtins__) ['ArithmeticError', 'AssertionError', 'AttributeError', 'DeprecationWarning', 'EOFError', 'Ellipsis', 'EnvironmentError', 'Exception', 'False', .snip. 'True', .snip. 'type', 'unichr', 'unicode', 'vars', 'xrange', 'zip'] but I think if you had an up-to-date 2.2 they should have been there too... >python2.2 Python 2.2.3 (#1, Jun 9 2003, 18:01:50) [GCC 2.95.4 20020320 [FreeBSD]] on freebsd4 Type "help", "copyright", "credits" or "license" for more information. >>> dir(__builtins__) ['ArithmeticError', 'AssertionError', 'AttributeError', 'DeprecationWarning', 'EOFError', 'Ellipsis', 'EnvironmentError', 'Exception', 'False', .snip. 'True', .snip. 'super', 'tuple', 'type', 'unichr', 'unicode', 'vars', 'xrange', 'zip'] What error are you getting? How are you using true and false? I know the developers were very careful to not cause any compatibilty problems with the addition of booleans. From op73418 at mail.telepac.pt Wed Aug 27 09:56:19 2003 From: op73418 at mail.telepac.pt (Gonçalo Rodrigues) Date: Wed, 27 Aug 2003 14:56:19 +0100 Subject: python gripes survey References: Message-ID: <15dpkvsfatkrlode3rc9h1trihsb3ppcj3@4ax.com> On Sat, 23 Aug 2003 15:39:27 GMT, "Ryan Lowe" wrote: >python is a big improvement on most languages that came before it, but no >language is perfect. id like to make a list of some of the aspects people >find most annoying, regardless of their feasibility of implementation. for >instance, i discussed putting if clauses in for loops, and i noticed another >thread about allowing {} and [] to be added and subtracted. if its something >from another language (especially an obscure one), please explain how it >works in case people like myself dont know the language. > Major gripes: names bound in nested scopes are read-only, not rebindable. Related with this is the global declaration -- the only declaration in Python! There should be another way to handle this: something like scopes becoming objects where the names bound in it are it's attributes and then you would have two functions global() and enclosing() returning the global and the enclosing scope. Or something to this effect :-) Minor gripes: - trimming down the builtins, e.g. move enumerate to itertools, get rid of map and filter, etc. - Get rid of lambda or find a way for lambda to accept statements. - Some of the more advanced Python stuff (super, metaclasses) has some dark corners (check the bugs tracker). Bring on the light. Things that I still haven't decided if they are gripes or not: - __slots__. Dangerous hack, makes generic code much more difficult. - names in for loops/list comprehensions leak out. With my best regards, G. Rodrigues From sdhyok at yahoo.com Sat Aug 9 10:42:57 2003 From: sdhyok at yahoo.com (sdhyok) Date: 9 Aug 2003 07:42:57 -0700 Subject: How to print floating point in scientific format? References: <420ced91.0308081115.7060e551@posting.google.com> Message-ID: <420ced91.0308090642.176b856b@posting.google.com> I am disappointed that there is no elegant solution for this problem in python. As you may notice, my primary usage of python is for scientific programming. For the purpose, it is critical for users to flexibly modify the printing format of floating points depending on their ranges and precisions. Think about this case. >import Numeric as N >x = N.arange(10.) >print x [ 0. 1. 2. 3. 4. 5. 6. 7. 8. 9.] >print "%E"%x TypeError: float argument required Even the format string option in print command doesn't work for numpy array. This limitation can be a serious handicap in the application of python for scientific programming. I like to listen to all of you who are interested in this issue. Shin, Daehyok From peter at engcorp.com Wed Aug 13 22:17:24 2003 From: peter at engcorp.com (Peter Hansen) Date: Wed, 13 Aug 2003 22:17:24 -0400 Subject: Python vs. C# References: Message-ID: <3F3AF134.C020F82D@engcorp.com> Christopher Barber wrote: > > Andrew Bennetts writes: > > In both cases, you need tests, preferably comprehensive, automated tests, to > > verify that your code actually works correctly. > > I like the sentiment, but in practice there is no such thing as comprehensive > tests. Without an agreed-upon definition of "comprehensive", this is arguable. "1. Including much; comprising many things; having a wide scope or a full view." Surely you'd agree that comprehensive tests are possible in this case. "2: including all or everything" In this case, although I'm unclear on the distinction between "all" and "everything", you're certainly correct, but it's an uninteresting point as it's too obvious. Certainly Andrew doesn't think anyone has tests which cover *everything*... And is your objection based on personal experience only, or do you consider others' situations. I would say that at my workplace we certainly have *comprehensive* and fully automated tests for some of our code. And those tests do verify quite well that the code works. -Peter From jussij at zeusedit.com Mon Aug 25 23:19:24 2003 From: jussij at zeusedit.com (Jussi Jumppanen) Date: Tue, 26 Aug 2003 13:19:24 +1000 Subject: ANN: Zeus Programmers Editor V3.90 Message-ID: <3F4AD1BC.12C9@zeusedit.com> The latest release of the Zeus for Windows programmer's editor is now available. To see what is new vist: http://www.zeusedit.com/whatsnew.html to read what other's have to say about the power of Zeus goto: http://www.zeusedit.com/awards.html or to see Zeus in action goto: http://www.zeusedit.com/lookcomp.html or to test drive Zeus for yourself download the fully functional shareware version from this link: http://www.zeusedit.com/download.html (3.3 Mega Byte) Jussi Jumppanen http://www.zeusedit.com From no at spam.com Sat Aug 9 00:44:35 2003 From: no at spam.com (J. W. McCall) Date: Sat, 09 Aug 2003 04:44:35 GMT Subject: Python and Web Hosting In-Reply-To: References: Message-ID: Ken Fettig wrote: > Hello, I am begining to learn the Python language and I am enjoying its > flexibility. I do have a question. I am considering using Python for web > development. I have found that a huge number of web hosts offer support for > PHP. How hard is it to find a Web Host that will allow you to you to run > your own Python scripts, web or app server, template engine (Zope or > Cheetah)? If it is not, is it comparable in cost? > > Thanks > Ken > kenfettig at btinet.net I have an account with www.freeshell.org. It has support for Python, C/C++, PHP, Perl, and quite a few other languages. You have to make a one-time donation of $30 or so (it's a nonprofit public shell account provider) to get web hosting and all that. You also get a full Unix shell account. You might want to check it out. I'm not sure about Zope or Cheetah, whatever those are (I'm new to Python), but it definately supports Python. I just wrote some scripts for my web site on there. J. W. McCall From andrew-pythonlist at puzzling.org Tue Aug 12 21:14:03 2003 From: andrew-pythonlist at puzzling.org (Andrew Bennetts) Date: Wed, 13 Aug 2003 11:14:03 +1000 Subject: Python vs. C# In-Reply-To: References: <3f357a9b@shknews01> Message-ID: <20030813011403.GB7207@frobozz> On Tue, Aug 12, 2003 at 12:06:20PM -0700, Brandon J. Van Every wrote: > Andrew Bennetts wrote: > > On Tue, Aug 12, 2003 at 02:27:26AM -0700, Brandon J. Van Every wrote: > >> > >> Good to hear that some people understand what it means when > >> Microsoft puts 100% of the company behind something. Remember, last > >> time around we got IE and Netscape vanished. > > > > When was that? > > > > I'm happily running Mozilla as my web browser, and have been for well > > over a year now. I'm hardly alone in this. > > > > Sure, Netscape-the-company might be effectively dead, > > Why do you bother to contradict me, if you're only going to make my point > for me? I forgot to trim the "When was that?" from my original draft of my reply. The spirit of it remains correct, though -- Netscape Corp. might be dead (I honestly don't know), but that's irrelevant to me. > > but I don't care about that. > > I bet you don't care about the market share of that software either. > Basically, most c.l.p people would be happy if they held onto a 1% market > share as the rest of the world changes. I do care, but not in "percentage of overall market share" terms. I care that the open source software I'm using still has a sufficiently active community supporting it and developing it that I know I can continue to use it indefinitely, without needing to shop around for an alternative while it stagnates. Mozilla (and Python, to drag this back on topic) both look extremely healthy to me. I don't particularly care much if other people use IE or C# (except to laugh at them ). I'm a happy Mozilla user, and I'm being paid to write Python, which is my preferred programming language. The corporations that are or aren't backing these choices really don't factor into it. -Andrew. From bokr at oz.net Fri Aug 1 10:05:36 2003 From: bokr at oz.net (Bengt Richter) Date: 1 Aug 2003 14:05:36 GMT Subject: Python speed vs csharp References: Message-ID: On 1 Aug 2003 03:11:35 GMT, bokr at oz.net (Bengt Richter) wrote: [...] > # inlining code from old version: > # constant assignments hoisted out of loop, of course > p = 0.3275911 > a1 = 0.254829592 > a2 = -0.284496736 > a3 = 1.421413741 > a4 = -1.453152027 > a5 = 1.061405429 > x = 1.2345 > for i in xrange(100000): > t = 1.0 / (1.0 + p*float(x)) > erfcx = ( (a1 + (a2 + (a3 + > (a4 + a5*t)*t)*t)*t)*t ) * math.exp(-(x**2)) > t4 = clock() > for i in xrange(100000): erfc_in_c(1.2345) > t5=clock() > print 'old: %f, new: %f, inline: %f, in_c %f' %(t2-t1, t3-t2, t4-t3, t5-t4) D'oh ... # inlining the new version code p = 0.3275911 a1 = 0.254829592 a2 = -0.284496736 a3 = 1.421413741 a4 = -1.453152027 a5 = 1.061405429 exp = math.exp for i in xrange(100000): t = 1.0 / (1.0 + p*x) #XXX# don't need float(), since p is float erfcx = ( (a1 + (a2 + (a3 + (a4 + a5*t)*t)*t)*t)*t ) * exp(-x**2) #XXX# elim attr lookup on global math.exp t6=clock() print 'old: %f, new: %f, inline: %f, in_c %f, inline new %f' %( t2-t1, t3-t2, t4-t3, t5-t4, t6-t5) >======================================================================= > >Result is: > > >[19:48] C:\pywk\cstuff>erfcopt.py >old: 4.490975, new: 3.123005, inline: 3.051674, in_c 0.806907 > >I was surprised that the inline gain was not more, but I guess there was enough computation >to obscure that cost. Anyway, moving some of the work to def-time paid off about 30%. But >going to C cut 82%. > [ 6:48] C:\pywk\cstuff>erfcopt.py old: 4.448979, new: 3.112778, inline: 3.073672, in_c 0.806066, inline new 2.193491 Ok, that last number is a bit more like it. Of course the C version is still the fastest. Forgot to include the source ;-/ If you have MSVC++6 and python sources you can compile and link the following with your version of this .cmd file: ====< mkpydll.cmd >=========================================== @cl -LD -nologo -Id:\python22\include %1.c -link -LIBPATH:D:\python22\libs -export:init%1 ============================================================== Invoked thus: [ 7:03] C:\pywk\cstuff>mkpydll erfc erfc.c Creating library erfc.lib and object erfc.exp (Tested only as far as you've seen in recent posts!) ====< erfc.c >================================================ /* ** erfc.c taken with slight mod from Mike @ nospam.com's c# posted version of ** Rational approximation for erfc(x) (Abramowitz & Stegun, Sec. 7.1.26) ** Fifth order approximation. |error| <= 1.5e-7 for all x ** Version 0.01 20030731 Bengt Richter bokr at oz.net */ #include static double erfc( double x ) { double p, a1, a2, a3, a4, a5; double t, erfcx; p = 0.3275911; a1 = 0.254829592; a2 = -0.284496736; a3 = 1.421413741; a4 = -1.453152027; a5 = 1.061405429; t = 1.0 / (1.0 + p*x); erfcx = ( (a1 + (a2 + (a3 + (a4 + a5*t)*t)*t)*t)*t ) * exp(-pow(x,2.0)); return erfcx; } #include "Python.h" #include static char doc_erfc[] = "erfc(x) -> approximation\n"; static PyObject * erfc_erfc(PyObject *self, PyObject *args) { PyObject *rv; double farg; if (!PyArg_ParseTuple(args, "d:erfc", &farg)) /* Single floatingpoint arg */ return NULL; rv = Py_BuildValue("d", erfc(farg)); return rv; } /* List of functions defined in the module */ static struct PyMethodDef erfc_module_methods[] = { {"erfc", erfc_erfc, METH_VARARGS, doc_erfc}, {NULL, NULL} /* sentinel */ }; /* Initialization function for the module (*must* be called initerfc) */ static char doc_erfc_module[] = "# Rational approximation for erfc(x) (Abramowitz & Stegun, Sec. 7.1.26)\n" "# Fifth order approximation. |error| <= 1.5e-7 for all x\n"; DL_EXPORT(void) initerfc(void) { PyObject *m, *d, *x; /* Create the module and add the functions */ m = Py_InitModule("erfc", erfc_module_methods); d = PyModule_GetDict(m); x = PyString_FromString(doc_erfc_module); PyDict_SetItemString(d, "__doc__", x); Py_XDECREF(x); } ============================================================== >>> help('erfc') Help on module erfc: NAME erfc FILE c:\pywk\cstuff\erfc.dll DESCRIPTION # Rational approximation for erfc(x) (Abramowitz & Stegun, Sec. 7.1.26) # Fifth order approximation. |error| <= 1.5e-7 for all x FUNCTIONS erfc(...) erfc(x) -> approximation DATA __file__ = 'erfc.dll' __name__ = 'erfc' >>> from erfc import erfc >>> for x in range(10): print '%s => %g'%(x,erfc(x)) ... 0 => 1 1 => 0.157299 2 => 0.00467786 3 => 2.21051e-005 4 => 1.54603e-008 5 => 1.54782e-012 6 => 2.17852e-017 7 => 4.26424e-023 8 => 1.15275e-029 9 => 4.28336e-037 Regards, Bengt Richter From duduca007 at yahoo.com Wed Aug 27 11:11:14 2003 From: duduca007 at yahoo.com (Carlos Moreira) Date: Wed, 27 Aug 2003 08:11:14 -0700 (PDT) Subject: IDE for Python In-Reply-To: Message-ID: <20030827151114.80449.qmail@web11401.mail.yahoo.com> --- Przemo Drochomirecki wrote: > Hello, > does anyone know freeware, nice-looking, > easy-to-install > with rolling-up-class,def-syntax feature (like in > boa, but not boa) IDLE -> http://die-offenbachs.de/detlev/eric3.html Eric3 -> http://die-offenbachs.de/detlev/eric3.html but I use vim :-) -> http://www.vim.org/index_real.php []?s Cadu Moreira KaduSoft President -------------------------- [...to sleep is for the weak ones...] __________________________________ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com From bokr at oz.net Fri Aug 8 18:02:27 2003 From: bokr at oz.net (Bengt Richter) Date: 8 Aug 2003 22:02:27 GMT Subject: crossplatform py2exe - would it be useful? References: <2UyYa.50516$cl3.1586459@news2.tin.it> Message-ID: On Fri, 08 Aug 2003 21:52:45 +0200, Thomas Heller wrote: >bokr at oz.net (Bengt Richter) writes: > >> PMJI, since I haven't read all the prior thread, but if the point is >> just to have an executable that self-unpacks and starts, IWT the safest >> (for platform independence -- not security, see my conclusion later below) >> approach would be to have a tool that makes a light-weight self-unpacking >> "exe" wrapper for any/each platform. > >No, that's not the goal (at least not for me). I don't want to unpack >something at runtime, I want exactly that what py2exe currently does: >One executable, plus maybe a handful of files (.dll/.pyd/.so). > That "plus" makes for a little ambiguity ;-) Is there a big difference for you between e.g., wget /py2exefiedapp.exe py2exefiedapp and wget /py2exefiedapp.uff uffunwrap --launch exefiedapp.uff ?? I don't think you'd see much difference in speed between a single exe with tacked-on baggage or a single .uff file launched with uffunwrap --launch. (BTW, changed my mind to .uff for Universal File Format -- it's easier to type ;-) (you could make a .uff automatic association on windows, and if you wanted a single-file launch on unix, you could prefix a line like #!/usr/bin/uffunwrap --launch) Especially if you can type ufhunwrap --header exefiedapp.uff and see something like Date: Fri, 08 Aug 2003 21:52:45 +0700 Author: B. Richter Status: Preliminary. Could use ideas for conventions in this header. Description: This package will if launched will unpack in the current directory and run. It does all kinds of neat things, trust me .... ;-) License: PSF X-Launch: ./py2exefiedapp.exe -cfg ./myConfig.txt X-UFF-Packing: endian=little pktframes=none align=8 # take lengths from this hdr, expect pad to %8=0 1: b 3456780 ./py2exefiedapp.exe 2003-08-08 22:00:00 +0700 md5=0123456789abcdef... 2: b 123458 ./dlls/mySpecialGizmo.dll ... 3: t 456 ./myConfig.txt ... ... the idea is a simple flat list of contents with sizes and binary/text indications and where-to-put-them paths with a numbered list of segments in the .uff file (zero is the header itself). You can see how easy it would be to unpack such a file. I'm tempted to write it before posting this ;-) You can see also that the X-Launch: line can permit doing just about anything. It would not be hard to package up a special version of python.exe and some dll's and with X-Launch: python -OO whatever, then uffunwrap --launch (I think I'd soon alias that to uff -x ;-) would simply start whatever is in the X-Launch line. you could also type uffunwrap --check exefiedapp.uff to get all the available checksums checked and others reported You could have an option to use existing files or overwrite them, etc. I think I will write one of these in any case. Maybe you will like the result better as a reality ;-) >> I think it would be relatively trivial on win32. I think you could do it all >> in Python once you have a little C boilerplate exe template compiled and a >> few special locations and segments defined (i.e., .exe's have provision >> for simple embedded resource entities. > >Well, for PE files on win32, the special locations can easily be stored >as resources, but IIUC that's not possible under Linux, for example. >But appending random stuff at the end of a valid executable is possible there. > >> For that purpose, I've been thinking a unicode utf-8 representation of >> an rfc2822 header might be cool. > >Ok, once you can execute Python code, you can do very fancy stuff. But >the problem is to 'boot' the Python interpreter into existance, the >first setp of this must be done from C code, and so it must be as simple >as possible. I am confident (FLW ;-) that I can write a small fast unwrapper/launcher in C along the lines of the above for win32. I think it will port well, except for the actual executable-launch part. If you insist, I can write the win32 version to allow tack-on resources ;-) Regards, Bengt Richter From pu Sun Aug 17 18:30:57 2003 From: pu (Patrick Useldinger) Date: Mon, 18 Aug 2003 00:30:57 +0200 Subject: client derived from async_chat In-Reply-To: <3f3fff3c_1@news.vo.lu> References: <3f3fdb48_1@news.vo.lu> <3F3FF26F.3D6538F4@alcyone.com> <3f3fff3c_1@news.vo.lu> Message-ID: <3f4001bb_2@news.vo.lu> Patrick Useldinger wrote: > File "I:\My Programs\sas\sasLA0.py", line 18, in ? > response=sock.recv(BUFFSIZE) > socket.error: (10035, 'The socket operation could not complete without > blocking') To be even more precise, the 10035 (EWOULDBLOCK) already happens when I do a connect(): 20030818-001054 connecting to EB on 127.0.0.1:16385 connect rc= 10035 <============================== File "I:\My Programs\sas\sasLA0.py", line 18, in ? response=sock.recv(BUFFSIZE) socket.error: (10035, 'The socket operation could not complete without blocking') This is exactly what happens in my previous code: class Server(SingleServer): def __init__(self,message,*args): self.log_info('Server:__init__') SingleServer.__init__(self,*args) self.create_socket(socket.AF_INET,socket.SOCK_STREAM) print now(),'connecting to EM on %s:%s' % (EBHost,EBPort) self.connect((EBHost,EBPort)) def handle_connect(self): self.log_info('Server:handle_connect') print now(),'sending %s' % repr(message) self.push(message+BLOCKEND) def processData(self,data): self.log_info('Server:processData') print now(),'received "%s"' % repr(response) self.close() I.e. issuing a connect() right after the socket creation in non-blocking mode yields this error message, so my questions are: 1- what does it mean? 2- using async_chat, *where* should I place my connect() if not immediately after the socket creation? I didn't have the problem in my server class as the bind() method seems to work independently whether the socket is blocking or non-blocking. -- Real e-mail address is 'cHVAdm8ubHU=\n'.decode('base64') Visit my Homepage at http://www.homepages.lu/pu/ From mwh at python.net Wed Aug 27 11:35:04 2003 From: mwh at python.net (Michael Hudson) Date: Wed, 27 Aug 2003 15:35:04 GMT Subject: Proposal: Magic Constants References: Message-ID: <7h3r837ce12.fsf@pc150.maths.bris.ac.uk> "John Roth" writes: > But these are existing literal syntax. I was thinking > more of random code where someone could currently > juxtapose a literal and an identifier, say, without an > intervening white space character. >>> 10and 1 1 >>> 5or 7 5 Very much a wart of the tokenizer, though. Cheers, mwh -- "Well, the old ones go Mmmmmbbbbzzzzttteeeeeep as they start up and the new ones go whupwhupwhupwhooopwhooooopwhooooooommmmmmmmmm." -- Graham Reed explains subway engines on asr From jzgoda at gazeta.usun.pl Fri Aug 22 18:27:28 2003 From: jzgoda at gazeta.usun.pl (Jarek Zgoda) Date: Fri, 22 Aug 2003 22:27:28 +0000 (UTC) Subject: crazy programming language thoughts References: Message-ID: Ryan Lowe pisze: >>>> v = read lines from 'file.txt'; join it with '\n'; lower it; split it at > '.' Nice. Didn't COBOL come from similar assumptions? That a computer language should be as similar as possible to natural English? -- Jarek Zgoda Registered Linux User #-1 http://www.zgoda.biz/ JID:zgoda at chrome.pl http://zgoda.jogger.pl/ From duncan at NOSPAMrcp.co.uk Tue Aug 19 09:20:52 2003 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Tue, 19 Aug 2003 13:20:52 +0000 (UTC) Subject: Path Problem on W2K? References: <93f5c5e9.0308170927.6e0bdc38@posting.google.com> <3F40F62D.8B32CFBD@engcorp.com> <3F41FECA.6743B6BD@engcorp.com> Message-ID: Peter Hansen wrote in news:3F41FECA.6743B6BD at engcorp.com: >> Alternatively create doskey macros for commands like that then you just >> need one file with a load of macro definitions. > > Does that let you execute them from other batch files? I > have a few dozen utilities which run Python scripts by executing > "call python scriptname.py" somewhere, relying on a .bat file > in the PATH. Does the DOSKEY approach work similarly? No, DOSKEY just affects what you type, you would have to write the commands out in full in a batch file. If you are running a lot of Python scripts from the command prompt or batch files, consider adding .py to the PATHEXT environment variable, that will let you run scripts directly, e.g. "scriptname" instead of "python scriptname.py", and will search PATH for the scripts. (However be aware that redirecting doesn't work on most versions of windows for scripts invoked this way!) -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From tzot at sil-tec.gr Thu Aug 7 11:13:27 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Thu, 07 Aug 2003 18:13:27 +0300 Subject: Adding PC Filename Extensions to Macintosh Filenames References: <3F306BC5.7000608@vt.edu> Message-ID: <83r4jv01ar9q89aveiijhefk73co2bge2b@4ax.com> On Tue, 05 Aug 2003 22:45:25 -0400, rumours say that hokiegal99 might have written: [snip] >and more >efficent and ways in which I might ID file types more accurately. You might want to give this a shot (single line URL): http://groups.google.com/groups?selm=1bea6vgknk099sknspp0p4fcaqhp60d0qh%404ax.com -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From max at alcyone.com Mon Aug 25 16:38:40 2003 From: max at alcyone.com (Erik Max Francis) Date: Mon, 25 Aug 2003 13:38:40 -0700 Subject: Problem with lists References: <538fc8e.0308251204.1049e4f9@posting.google.com> Message-ID: <3F4A73D0.8B003B1A@alcyone.com> WIWA wrote: > I see some strange things: on rather small (it must be +/- < 4000 ) > entries in the access_log, my script works fine. Above this limit, I > get the following error. It probably means that there's an entry in the log that isn't what you expect. The error is being generated by the input data; print the contents of `datum' before you run that code, or check it out in a debugger, to see what it contains. > Question: do lists have a limit? Anyone know how I can change this > simple script so that it works for more entries as well. No, lists do not have any such limitation. The code that's generation the exception isn't dealing with a large list, anyway. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ It's just a day that brings it all about \__/ Sade From nospam at the.net Tue Aug 26 15:15:41 2003 From: nospam at the.net (Rune) Date: Tue, 26 Aug 2003 21:15:41 +0200 Subject: My future Python IDE article References: Message-ID: On Tue, 26 Aug 2003 13:39:17 -0400, mertz at gnosis.cx (David Mertz) wrote: >Here's the thing: I probably have room to look at about four different >tools in one article. In fact, it wouldn't be absurd to only do three. >Past that, I cannot do more than list contact information and platform >in the available words. I'm sure there are more than four IDEs that >-someone- loves to work with out there... but I need to have a cutoff. At least you will have to comment the Komodo from ActiveState. Rune From jepler at unpythonic.net Sun Aug 24 09:49:36 2003 From: jepler at unpythonic.net (Jeff Epler) Date: Sun, 24 Aug 2003 08:49:36 -0500 Subject: Threading Oddity? In-Reply-To: References: Message-ID: <20030824134931.GA27488@unpythonic.net> On Fri, Aug 22, 2003 at 09:33:18PM -0700, Kris Caselden wrote: > I noticed a strange yet easily fixed problem in Python's thread > module. > > Consider the following code: > > #------------------------------- > > import thread > > data='this is data' > data_mutex = thread.allocate_lock() > > def thread1(): > while data_mutex.locked(): > data_mutex.aquire() > print 'thread1:',data > if data_mutex.locked(): > data_mutex.release() > > def thread2(): > while data_mutex.locked(): > data_mutex.aquire() > print 'thread2:',data > if data_mutex.locked(): > data_mutex.release() > > thread.start_new_thread(thread1,()) > thread.start_new_thread(thread2,()) This code didn't run for me (no lines were printed) because the program exits when the main thread is done. I added import time time.sleep(1) after the start_new_thread calls as a remedy. Then, it printed two lines and waited about a second before I got the prompt back. I tried removing the 'while's and dedenting the lines "data_mutex.aquire". Then I got an attribute error! But with the "while", there's no error. Why not? Because the mutex was never locked! If the mutex is not locked, the body of the while statement is not executed. On the other hand, if the statement inside the loop was executed and did successfully claim the mutex, the 'while' condition would evaluate to 'true' the next time through, the statement to claim the lock would execute again, and block forever. (but this isn't likely to happen on any particular run, because it would require that the mutex be released at just the right moment.. properly testing threaded code is hard) I think this comes down to being a typo (as pointed out by another poster, acquire vs aquire) and the addition of the 'while' loop just adds confusion and is a completely wrong thing to do. Jeff From tim.one at comcast.net Sun Aug 17 20:18:27 2003 From: tim.one at comcast.net (Tim Peters) Date: Sun, 17 Aug 2003 20:18:27 -0400 Subject: bitwise not - not what I expected In-Reply-To: Message-ID: [Michael Peuser] >> I have the impression (may be wrong) that you are working under the >> misconception that there can be a "natural" binary represensation of >> negative numbers!? Three conventions have commonly been used so far: >> 1- Complement >> 2-Complement >> Sign tag plus absolut binary values [Elaine Jackson] > The last alternative sounds like what I was assuming. If it is, I > would argue that it's pretty darn natural. Here's a little function to > illustrate what I mean: > > def matilda(n): ## "my tilde" > if 0<=n for i in range(1,31): > iOnes=pow(2,i)-1 > if n<=iOnes: > return iOnes-n > else: > raise As Carl Banks pointed out, under this meaning the fundamental identity ~~x == x almost never holds. For example, matilda(18) is 13, but matilda(13) is 2. ~ is its own inverse under Python's meaning. You can see that formally by algrebraic manipulation: ~~n = ~(-(n+1)) = -(-(n+1)+1) == n or more easily by noting that ~x in Python acts the same as xor'ing x with an infinite string of 1 bits. From mpeuser at web.de Wed Aug 13 03:12:47 2003 From: mpeuser at web.de (Michael Peuser) Date: Wed, 13 Aug 2003 09:12:47 +0200 Subject: two quick questions References: <3F39D89B.A7160172@alcyone.com> Message-ID: The following examples might clear the more rheoretical elaborations ..... def noUse(a): a=(4,5,6) def tricky(a): a[0]=(7,8,9) # case 1 x=[1,2,3] print x tricky(x) x=(1,2,3) # case 2 noUse ([x]) print x # case 3 tricky([x]) print x # case 4 y=[x] tricky (y) print x print y[0] # case 5 tricky(x) print x Kindly Michael Peuser "Erik Max Francis" schrieb im Newsbeitrag news:3F39D89B.A7160172 at alcyone.com... > Elaine Jackson wrote: > > > 1) Does Python have passing-by-reference? > > It depends on exactly what you mean by that. In a sense all Python > objects are passed by reference, but only in the sense that the > reference is passed by value. (Say that three times fast.) > > If you want to get the equivalent of a C++ reference on an immutable > object, you can do it with containment. Pass the function a mutable > container containing your object, and then manipulate/change the > contained object. In the caller's scope, the container will have > mutated. > > > 2) In ordinary parlance, "deep" implies "shallow" but not conversely. > > In the > > Python "copy" module (if I understand correctly), the implication goes > > the other > > way. Do you find this a nuisance? > > I'm not sure what about the copy's modules semantics you're thinking are > reversed, but the terminology used in the copy module is common in > computer science. A shallow copy means that the object is copied, but > it will retain the same references to contained objects; a deep copy > means that the object is copied, as well as the objects it contains (and > so on, recursively). A deep copy always does the same thing as a > shallow copy, and more. > > -- > Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ > __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE > / \ I always entertain great hopes. > \__/ Robert Frost From fredrik at pythonware.com Fri Aug 8 09:35:44 2003 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 8 Aug 2003 15:35:44 +0200 Subject: passing multiple strings to string.find() References: <3F331A9B.9020907@vt.edu> Message-ID: Francois Pinard wrote: > Given the above, > > > build_regexp(['this', 'that', 'the-other']) > > > yields the string 'th(?:is|at|e\\-other)', which one may choose to > `re.compile' before use. footnote: the SRE compiler looks for common prefixes, so "th(?:is|at|e\\-other)" is no different from "this|that|the-other" on the engine level. From calderano at sgaspa.it Tue Aug 5 12:43:44 2003 From: calderano at sgaspa.it (Luca Calderano) Date: Tue, 5 Aug 2003 18:43:44 +0200 Subject: handle
tags Message-ID: <000001c35b70$bce53ab0$410100a4@utente65> I got it using SGMLParser! ... def unknown_starttag(self, tag, attrs): if tag == 'br': self.data.append('\n') ... Thanks all! S.G.A S.p.A. Nucleo Sistemi Informativi Luca Calderano -----Messaggio originale----- Da: python-list-admin at python.org [mailto:python-list-admin at python.org]Per conto di Luca Calderano Inviato: gioved? 31 luglio 2003 15.11 A: Python Mailing List (E-mail) Oggetto: handle
tags Hi guys... I've done a subclass of SGMLParser to handle the contents of a web page, but i'm not able to handle the
tag can someone help me??? S.G.A S.p.A. Nucleo Sistemi Informativi Luca Calderano -- http://mail.python.org/mailman/listinfo/python-list From dakidd at sonic.net Tue Aug 5 16:23:01 2003 From: dakidd at sonic.net (Don Bruder) Date: Tue, 05 Aug 2003 20:23:01 GMT Subject: (VERY) New to Python. Need Help! References: Message-ID: In article , "Terry Reedy" wrote: > "Don Bruder" wrote in message > news:beLXa.8574$dk4.365557 at typhoon.sonic.net... > > Any indication of whether there's a "getpid" function in the Carbon > > version of MacPython? And how would I go about checking to see > (aside > > from the obvious "fire up the program - if it pukes, the function > isn't > > there") if an arbitrarily selected function is available in a > particular > > Python implementation? > > In the installation directory is a subdirectly Lib (at least for *nix, > windows versions, don't know if mac is same). In that directory is a > file called os.py which, when imported, becomes the os module. In > that file are a number of definitions. Your BT program, by including > > >>> from os import getpid, path, makedirs > > is looking for those three particular names. So you could look thru > the file to see if they are there. Running the program seems easier > ;-), although looking will verify that os.py, path, and makedirs *are* > present (and getpid present or not). > > If so, you could verify the that absence of getpid is exactly the > problem by deleting it from import list and adding as the next line > print 'got here'; raise SystemExit Actually, the FAQ that Richard pointed me at included a "cookbook" fix - specifically, ripping out the import of "getpid", and further along, teraing out the reference to it that happens while (if I've got *ANY* understanding at all of programming) building what appears to be a unique string. And as Richard said (and you imply), there is no such thing as "getpid" on pre-X Macs. Thanks for the advice, though! God knows I need every bit of it I can get when I'm this "green" in a language! -- Don Bruder - dakidd at sonic.net <--- Preferred Email - unmunged, SpamAssassinated Hate SPAM? See for some seriously great info. I will choose a path that's clear: I will choose Free Will! - N. Peart Fly trap info pages: From andrew at indranet.co.nz Thu Aug 14 17:14:21 2003 From: andrew at indranet.co.nz (Andrew McGregor) Date: Fri, 15 Aug 2003 09:14:21 +1200 Subject: Multi-Line Comment In-Reply-To: <1060760753.18367.122.camel@adsl-209.204.179.133.sonic.net> References: <4qofjvg3bh9smlnb1do4f0lhjga7bacnu3@4ax.com> <200308122306.48320.shalehperry@comcast.net> <1060760753.18367.122.camel@adsl-209.204.179.133.sonic.net> Message-ID: <3353161.1060938861@[192.168.1.249]> --On Wednesday, 13 August 2003 12:45 a.m. -0700 Chad Netzer wrote: > On Wed, 2003-08-13 at 00:03, Doug Tolton wrote: > >> > (along with block indent/dedent with a decent editor) >> >> In emacs what are the key strocks for block indent and dedent? > > In python-mode: > > C-c > > C-c < > > >> Man, I wonder if I'll even learn 10% of the Emacs keystrokes. > > I don't even know 1%, but I know the 1% that counts. :) > > -- > Chad Netzer Try C-h ? ? which will give you the "help for help", which is how to learn the 5% or so that you need of the active keys in the modes you use (yes, emacs really does have that many keybindings! There are only 38 two-key sequences guaranteed available for user bindings...) Andrew --------- Andrew McGregor Director, Scientific Advisor IndraNet Technologies Ltd http://www.indranet-technologies.com/ From mertz at gnosis.cx Thu Aug 28 02:12:34 2003 From: mertz at gnosis.cx (Lulu of the Lotus-Eaters) Date: Thu, 28 Aug 2003 02:12:34 -0400 Subject: OT: Americans love their guns References: Message-ID: Tom Plunket wrote previously: |Ironically the states with the loosest gun laws also have the |least crime. Almost exactly opposite to the truth. Check the FBI uniform crime statistics. Although the pattern is not 100% reliable, there is a strong correlation between lax gun laws and gun-related deaths. |Remember that automobiles kill something like 100x the number of |people in the US every year over guns. USA automobile deaths are ^43k/year USA gun-related deaths are ~29k/year The first number is bigger, yes.... but nothing at all like 100x as large. Pulling facts out of thin air (or equivalently, our of NRA leaflets or ESR's writing) is unpersuasive. Yours, Lulu... -- mertz@ _/_/_/_/_/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY:_/_/_/_/ v i gnosis _/_/ Postmodern Enterprises _/_/ s r .cx _/_/ MAKERS OF CHAOS.... _/_/ i u _/_/_/_/_/ LOOK FOR IT IN A NEIGHBORHOOD NEAR YOU_/_/_/_/_/ g s From jjl at pobox.com Mon Aug 18 19:01:50 2003 From: jjl at pobox.com (John J. Lee) Date: 19 Aug 2003 00:01:50 +0100 Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> Message-ID: <87brumwowx.fsf@pobox.com> "Brandon J. Van Every" writes: > Alex Martelli wrote: > > > > Don't be misled by these comparisons into thinking the two [...] > > spaghettini as the pastasciutta to go with suitable sauces for > > such long thin pasta forms (olive oil, minced garlic, minced [...] > > [or even -- I'm a heretic...! -- light mint...] leaves -- at > > the very last moment before serving the dish). > > What a wonderful runon sentence. You must be an A. A. Milne fan. [...] Well, art is art, isn't it? Still, on the other hand, water is water! And east is east and west is west and if you take cranberries and stew them like applesauce they taste much more like prunes than rhubarb does. Groucho Marx. John From dougfort at dougfort.net Tue Aug 26 16:31:27 2003 From: dougfort at dougfort.net (Doug Fort) Date: Tue, 26 Aug 2003 20:31:27 GMT Subject: My future Python IDE article References: Message-ID: Up until six months ago, I was a solid EMACS guy. The a friend urged me to try Komodo. There's a good 21 day free trial, but I bought the personal version because I've gotten so much good stuff from ActiveState. Now I'm hooked. If you haven't checked it out recently, I recommend taking a look at Komodo. http://www.activestate.com On Tue, 26 Aug 2003 13:39:17 -0400, David Mertz wrote: > Pythonistas, > > My loyal fans :-) will remember that I did a Python IDE roundup for > _Charming Python_ a couple years back. Now I have another such roundup > lined up... not the very next article, but it's there on the list. > > In the intervening years, I've hardly touched anything one might call an > IDE. I've looked at screenshots from time to time, and read various > announcements. But really I just use text editors and command lines. > > Here's the thing: I probably have room to look at about four different > tools in one article. In fact, it wouldn't be absurd to only do three. > Past that, I cannot do more than list contact information and platform > in the available words. I'm sure there are more than four IDEs that > -someone- loves to work with out there... but I need to have a cutoff. > > So c.l.py readers... make the case for your favorite one getting on the > list. I have a while to ponder the opinions advanced, should this > prompt some discussion (it may take a little while to order review > copies of commercial tools and/or get things installed). > > Yours, David... > > -- > _/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY: Postmodern Enterprises _/_/_/ > _/_/ ~~~~~~~~~~~~~~~~~~~~[mertz at gnosis.cx]~~~~~~~~~~~~~~~~~~~~~ _/_/ > _/_/ The opinions expressed here must be those of my employer... _/_/ > _/_/_/_/_/_/_/_/_/_/ Surely you don't think that *I* believe them! _/_/ From Vincent.Raaijmakers at ge.com Tue Aug 5 15:04:23 2003 From: Vincent.Raaijmakers at ge.com (Raaijmakers, Vincent (IndSys, GE Interlogix)) Date: Tue, 5 Aug 2003 14:04:23 -0500 Subject: site-packages and linux Message-ID: <55939F05720D954E9602518B77F6127F03096F46@FTWMLVEM01.e2k.ad.ge.com> No, what I mean is... the packages in 2.2 are not recognized anymore if I run python2.2. However, I never moved them out, to be sure that I could go back from 2.3 to 2.2. Too late I guess. Vincent -----Original Message----- From: Batista, Facundo [mailto:FBatista at uniFON.com.ar] Sent: Tuesday, August 05, 2003 2:43 PM To: Python-List (E-mail) Subject: RE: site-packages and linux #- Currently in my linux configuration there seems to be a #- conflict in my python2.2 and 2.3 install. #- I installed recently 2.3 but want to go back for some reason to 2.2. #- All installed packages located in #- ...\python2.2\site-packages are not recognized anymore. #- Well, when importing is not possible, no module found #- error is what I get now. #- #- Without re-installing everything, how can I solve this problem? Tried to copy the modules from ...\python2.2\site-packages to ...\python2.3\site-packages? . Facundo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ADVERTENCIA La informaci?n contenida en este mensaje y cualquier archivo anexo al mismo, son para uso exclusivo del destinatario y pueden contener informaci?n confidencial o propietaria, cuya divulgaci?n es sancionada por la ley. Si Ud. No es uno de los destinatarios consignados o la persona responsable de hacer llegar este mensaje a los destinatarios consignados, no est? autorizado a divulgar, copiar, distribuir o retener informaci?n (o parte de ella) contenida en este mensaje. Por favor notif?quenos respondiendo al remitente, borre el mensaje original y borre las copias (impresas o grabadas en cualquier medio magn?tico) que pueda haber realizado del mismo. Todas las opiniones contenidas en este mail son propias del autor del mensaje y no necesariamente coinciden con las de Telef?nica Comunicaciones Personales S.A. o alguna empresa asociada. Los mensajes electr?nicos pueden ser alterados, motivo por el cual Telef?nica Comunicaciones Personales S.A. no aceptar? ninguna obligaci?n cualquiera sea el resultante de este mensaje. Muchas Gracias. -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Fri Aug 15 19:05:36 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 15 Aug 2003 19:05:36 -0400 Subject: Replace every n instances of a string References: <62de87da.0308151325.41ea4622@posting.google.com> Message-ID: "Tom Cross" wrote in message news:62de87da.0308151325.41ea4622 at posting.google.com... > I have a function that returns to me a text representation of Unicode > data, which looks like this: ... > I would like to add carriage returns...after each 12 > "\\u"s I encounter in the string. > > Any ideas? Do I not want to search for "\\u" but instead just insert > a \n after each 72 characters (equivalent to 12 \uXXXX codes)? Would > this provide better performance? If so, what would be the easiest way > to do that? Split string into list of 6*n (72) char chunks and join with \n: #unirep = textrep(unidata) #ie, call your func and store result. for illustration... unirep = r'\u0013\u0021\u003c\u003f\u0044\u001f\u006a\u005a\u0050\u0015\u0018' blocklen = 6*4 #instead of 6*12 to get multiple lines with short unirep unilist = [] for i in range(0, len(unirep), blocklen): unilist.append(unirep[i:i+blocklen]) unilines = '\n'.join(unilist) >>> print unilines \u0013\u0021\u003c\u003f \u0044\u001f\u006a\u005a \u0050\u0015\u0018 Consider whether you want to change r'\n' to something else like spaces for easier viewing. If so, do so on unirep before chop into blocks and adjust blocklen if replacement is not two chars. Terry J. Reedy Terry J. Reedy From hwlgw at hotmail.com Sat Aug 2 03:18:58 2003 From: hwlgw at hotmail.com (Will Stuyvesant) Date: 2 Aug 2003 00:18:58 -0700 Subject: How do you do unittest? References: Message-ID: > [Raymond Hettinger] > You can avoid that sort of mambo jambo by avoiding > unittest.main() and running the tests directly. I added > a simple example to the Py2.3 docs: > > http://www.python.org/doc/current/lib/minimal-example.html Thanks, I now use unittest.TextTestRunner (what a name!) in test_mod.py in a test_mod.test function. Together with a general test.py in the 'test' directory that does the sys.path.append('..') I can now run tests in the test directory so I don't have all the clutter in the source directory, and I don't have to do sys.path.append('..') in every test_xxx.py, only in the test.py that looks like: # To be executed in the 'test' directory import sys sys.path.append('..') import test_mod test_mod.test() import test_mod2 test_mod2.test() ... From rac at orion.he.net Thu Aug 21 10:18:02 2003 From: rac at orion.he.net (rac) Date: Thu, 21 Aug 2003 07:18:02 -0700 Subject: Approved In-Reply-To: <200308211417.HAA27147@orion.he.net> References: <200308211417.HAA27147@orion.he.net> Message-ID: <200308211418.HAA27169@orion.he.net> == This Is An Automated Response from the Anime Corner == Hi! Thank you for writing! Your inquiry has been received, and will be addressed by one of our customer care representatives as soon as possible, usually by the next business day. Don't worry, we are here to serve you, so rest assured, we'll get back to you as soon as possible! In the mean time: *Answers to most general questions can be found on one of our information pages here: http://www.animecornerstore.com/info.html *Complete shipping and ordering information can be found here: http://www.animecornerstore.com/shipping.html *Daily new item, shopping, and store update information can be found here: http://www.animecornerstore.com/storeupdates.html *Join our 'e'-mailing list for news, updates, and special offers: http://lb.bcentral.com/ex/manage/subscriberprefs.aspx?customerid=8578 Thank you very much for choosing the Anime Corner Store!! Best regards, The Anime Corner Store Customer Care Team! Bob, Jamie, Jenn, Mitch, & Denise -- See what other customers say about us! http://www.animecornerstore.com/comments.html -- ------------------------------------------------------------ http://www.animecornerstore.com The Anime Corner Store Anime Items by the thousands in Stock and Ready to Ship at Everyday Low prices! DVD, CD, Cels, Manga, Toys, More! ----------------------------------------------------------- From mwh at python.net Fri Aug 29 11:50:47 2003 From: mwh at python.net (Michael Hudson) Date: Fri, 29 Aug 2003 15:50:47 GMT Subject: Getting class name References: Message-ID: <7h3fzjk4g9s.fsf@pc150.maths.bris.ac.uk> Travis Whitton writes: > Hello all, > I've googled a bit, and I've failed to find an answer to this question. Is it > possible to get a classes name from inside of a class? I.e., > > class Foo: > def print_classname(self): > # somehow print Foo print self.__class__.__name__ ? Cheers, mwh -- MARVIN: Do you want me to sit in a corner and rust, or just fall apart where I'm standing? -- The Hitch-Hikers Guide to the Galaxy, Episode 2 From tzot at sil-tec.gr Fri Aug 22 20:38:43 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Sat, 23 Aug 2003 03:38:43 +0300 Subject: how fast is Python? References: Message-ID: On 20 Aug 2003 13:08:20 -0700, rumours say that danbmil99 at yahoo.com (dan) might have written: >How fast is Python, compared >to say a typical optimizing C/C++ compiler? The most important time for me is the time *I* invest in a program, since when it's run-time, I can always do other stuff while some slave computer follows my orders. So, I'll reply only about development time and I'll quote the Smiths: "How Soon Is Now?" :) -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From postmaster at darbynet.com Fri Aug 22 10:18:08 2003 From: postmaster at darbynet.com (postmaster at darbynet.com) Date: Fri, 22 Aug 2003 10:18:08 -0400 Subject: Delivery Status Notification (Failure) Message-ID: This is an automatically generated Delivery Status Notification. Delivery to the following recipients failed. LPOLLARD at Darbylaw.com -------------- next part -------------- An embedded message was scrubbed... From: Subject: Re: Re: My details Date: Fri, 22 Aug 2003 9:12:08 --0500 Size: 1543 URL: From aahz at pythoncraft.com Wed Aug 27 10:50:27 2003 From: aahz at pythoncraft.com (Aahz) Date: 27 Aug 2003 10:50:27 -0400 Subject: My future Python IDE article References: Message-ID: In article , David Mertz wrote: > >So c.l.py readers... make the case for your favorite one getting on the >list. I have a while to ponder the opinions advanced, should this >prompt some discussion (it may take a little while to order review >copies of commercial tools and/or get things installed). I use vi, so take my advice with a grain of salt, but I think you should include IDLE because there have been so many improvements with Python 2.3 (running code in a separate process, if nothing else), and it is the standard IDE that comes with Python. That would make three + IDLE for your article, and you can get started on IDLE now. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From paul at boddie.net Wed Aug 27 08:01:01 2003 From: paul at boddie.net (Paul Boddie) Date: 27 Aug 2003 05:01:01 -0700 Subject: Celebrity advice (was: Advice to a Junior in High School?) References: <38ec68a6.0308261856.3c5f85d@posting.google.com> Message-ID: <23891c90.0308270401.73084c61@posting.google.com> afriere at yahoo.co.uk (Asun Friere) wrote in message news:<38ec68a6.0308261856.3c5f85d at posting.google.com>... > "Tim Churches" wrote in message > news:... > > > Except when it comes to guns > > You should know better than getting into a discussion with Americans about > guns. Before we get into a long and pointless debate, it should be said that the film "Bowling for Columbine" does have a more sophisticated point about the relationship between gun availability and criminal acts than is typically made out or assumed (usually by people who haven't seen it, I might add). And with that, I'd advise anyone interested in pursuing such a debate to take it to the appropriate forums (and to see the film, too). Meanwhile, given ESR's latest "Star Wars trip" (as published by NewsForge and a whole load of other places by now, I'm sure) there's a strong argument for the issue of T-shirts which read "STFU ESR". Because like all of us, there are times when saying nothing is substantially better than saying something, especially when repeated references to "Obi-Wan", "The Emperor" and "Rebel Command" are made. Paul From gerrit at nl.linux.org Thu Aug 28 05:58:38 2003 From: gerrit at nl.linux.org (Gerrit Holl) Date: Thu, 28 Aug 2003 11:58:38 +0200 Subject: Class level variables in Python In-Reply-To: References: Message-ID: <20030828095838.GB3020@nl.linux.org> Brian Munroe wrote: > >>> class rectangle(object): > z = 1 > def __init__(self): > self.x = 2 Class attributes are for each object, instance attributes only for one object. E.g.: class Rectangle(object): angle_size = 90 def __init__(self, x, y): self.horizontal = x self.vertical = y (Note that classes are Capitalized). Now, each Rectangle han an attribute angle_size (which can even be made read-only, but that's something different), and 'horizontal' and 'vertical'. This would be the correct approach; initializing attributes on startup should only be done if they depend on the call or other "environmental" factors, or should be different for each instance. Hope this helps. Hope it's correct ;) Gerrit. -- 178. If a "devoted woman" or a prostitute to whom her father has given a dowry and a deed therefor, but if in this deed it is not stated that she may bequeath it as she pleases, and has not explicitly stated that she has the right of disposal; if then her father die, then her brothers shall hold her field and garden, and give her corn, oil, and milk according to her portion, and satisfy her. If her brothers do not give her corn, oil, and milk according to her share, then her field and garden shall support her. She shall have the usufruct of field and garden and all that her father gave her so long as she lives, but she can not sell or assign it to others. Her position of inheritance belongs to her brothers. -- 1780 BC, Hammurabi, Code of Law -- Asperger Syndroom - een persoonlijke benadering: http://people.nl.linux.org/~gerrit/ Het zijn tijden om je zelf met politiek te bemoeien: http://www.sp.nl/ From bokr at oz.net Tue Aug 12 16:15:18 2003 From: bokr at oz.net (Bengt Richter) Date: 12 Aug 2003 20:15:18 GMT Subject: Howto MACRO in python ? References: <3F38D039.2B28800A@engcorp.com> <001201c360cd$3da065b0$6400a8c0@EVOD31> Message-ID: On Tue, 12 Aug 2003 20:39:39 +0200, Christian Tismer wrote: >Richie Hindle wrote: > >... > >> Anyone know how I could retrieve function attributes from within a trace >> function? It would be neater. > >Do you really mean function attributes, or just >local variables? The latter are easily obtainable >through the frame's f_locals. > >If you are just after the locals, you don't need to read on. > >When a frame is executed, the function is no longer >available, just the source filename (from the code >object), the name of the function and the frame's f_lineno. > >Guessing the function object from this info is not >guaranteed to work, but will probably work if your >code is static (not created dynamically, compiled >and thrown away after starting it). >With some luck, you can use the filename and the >function name, import the according module and >get the function object by the name. >Then you can use function attributes. > maybe there ought to be a magic __self__ in the local namespace of a function? Or better yet (?;-) if a user-defined function were a subclass of type function instead of an instance, and a frame were an activation-instance of this function subclass, then frame.__class__.__dict__ would be the function __dict__, where you could find attributes. Binding of locals to passed args would be an __init__ function of the activation-instance, automatically followed by running the code (or maybe not, in the case of generators), and presumably a function (being a frame-instance-making class) could be customized more flexibly than we can now do with functions, including metaclass stuff, so you could e.g. define pre-bound local slot variables (just handwaving ;-). def would be syntactic sugar. ;-) Regards, Bengt Richter From bgailer at alum.rpi.edu Mon Aug 11 07:30:28 2003 From: bgailer at alum.rpi.edu (Bob Gailer) Date: Mon, 11 Aug 2003 05:30:28 -0600 Subject: Python vs. C# In-Reply-To: <20E0F651F8B82F45ABCBACC58A2D995B0518B8@mexper1> Message-ID: <5.2.1.1.0.20030811052947.02bf7ea8@66.28.54.253> What is "trolling"? Bob Gailer bgailer at alum.rpi.edu 303 442 2625 -------------- next part -------------- --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.506 / Virus Database: 303 - Release Date: 8/1/2003 From __peter__ at web.de Fri Aug 29 15:42:04 2003 From: __peter__ at web.de (Peter Otten) Date: Fri, 29 Aug 2003 21:42:04 +0200 Subject: opposite of dict.items() References: <3f4e708c$0$64719@hades.is.co.za> Message-ID: Chad Netzer wrote: >> If I could use the above in Py2.4, it would be even nicer, namely: >> >> - convert itertools to builtins > > The push is to have LESS builtins. You can always import them in to the > current namespace: > > from itertools import izip More than 20% (counted manually, so maybe wrong) of the builtins have been added in the 2.x versions. So the question is rather what than if to include. I use zip() more often than property(). I happen to see *both* as core language features (can't remember having zipped anything in C or Basic). But I could live with # do not mistake that as a proposal from classfeatures import property, staticmethod >> - add irange(), perhaps as an alias for xrange() like file/open > > BTW. In the example you used, you COULD use xrange(). The only problem > is that range has been extended, in 2.3, to accept longs, and xrange() > only works with ints, and Guido wants it that way (he doesn't want to > extend xrange()'s features, since it is a pain.) irange(), if it ever > appears, would presumably be fully range() compatible. I did not want irange() as an *addition* but as an *alias* for xrange(). For new users, it would be easier to have a common prefix for all lazy sequence operations. In my example I took two steps at once (using xrange() instead of range() and introducing the alias), which confused the issue. Think of the "perhaps" as bloat and remove it :-) (As to the implementation details of xrange(), these have completely escaped me until now) > I suggested an irange to Raymond, and even coded one up, a while ago. > He sees it as bloat, and rightfully so, since there is a push to allow > optimizations of range that would achieve the same effect. (ie. rather > than remembering when to use range(), xrange(), or irange(), we could > just always use range() and the language would do lazy evaluation > whenever possible.) Unless that avenue turns out to be a complete dead > end, don't expect an irange(). Now *that* sounds interesting, but if it is feasible I would expect other functions like ifilter() and imap() to be unified with their (at least for the moment) builtin analogs. Peter From pruebauno at latinmail.com Mon Aug 25 20:00:47 2003 From: pruebauno at latinmail.com (nnes) Date: 25 Aug 2003 17:00:47 -0700 Subject: My own 12 points list Message-ID: I have really no mayor gripes, and the few things I would change would break backward compatibility, but here is the list anyway: 1.) Eliminate the whole long stuff. E.g. built-in long () function, "L", etc. It is a Python language implementation detail and I do not care about how it is done as long as it is fast and correct. Make python int adapt according to size of the integer and underlying architecture. 8088-80286=16 bit integers, 386-586=32 bit, x86-64=64bit. If number overflows the CPU architecture auto-magically use internal (long) representation. 2.) Eliminate map (), filter (), reduce (). It can be replaced with list comprehensions and for loops, which are easier to read. 3.) Eliminate open (), use file () instead 4.) Eliminate xrange(), replace range() with xrange() implementation 5.) Eliminate built-in functions buffer(), callable(), delattr(), dir(), getattr(), hasattr(), hash(), help(), id(), isinstance(), len(), max(), min(), repr(), setattr(), sum(), str(), type(), unichr() and make them methods of the root or base object. Transform them into object.func(parameters). Most of them have as the first parameter an object anyway. Some of them can be moved to sys. Various other functions can be deprecated so that I do no have to scan over a dozen of functions each time I am looking something up. Especially if few people use them anyway and they can be replaced 1:1 with another simple construct. 6.) Eliminate lambda, use local ?def somename(param):return expr' instead. 7.) Eliminate locals(), globals() and replace with a vars() that defaults to locals, and accept a parameter to get globals(). 8.) Eliminate `x` for repr() 9.) Eliminate raw_input() and replace input() with raw_input() implementation. Input can be done using eval(input()). Do NOT simply eliminate input, print and put it in sys. Although it IS ugly, reading and writing to standard input and output is the bread and butter of admin scripts, CGI and all kinds of glue programs (python's core usage) and should be readily available. It also makes for a quick and dirty user input and output for debugging. sys.stdin.readline() is too verbose IMHO. 10.) Eliminate the recursion limit on functions or better yet, include an option to change from the default to infinite. No need to change anything in the language. A lot of work in the implementation though. Could use regular method up to a number of calls and then switch to a less performant method. 11.) Add a big decimal type (something like java) in the standard library. To be able to do bean counter type math easily. Are there so few python applications that deal with money? 12.) Int division: return float (for engineers) or big decimal (for bean counters) Some of them are blatantly copied from Guidos regrets slides btw. I just happen to agree with most of the points on them. Nestor From romain at zzict.com Thu Aug 28 04:13:44 2003 From: romain at zzict.com (Romain Slootmaekers) Date: Thu, 28 Aug 2003 10:13:44 +0200 Subject: [Zope-dev] Zope 2.7 running with Stackless 3.0 In-Reply-To: <3F4D44EB.5010500@tismer.com> References: <3F4D44EB.5010500@tismer.com> Message-ID: <3F4DB9B8.7080408@zzict.nl> Christian Tismer wrote: > Dear friends, > > just by chance, I got into the position to try out > Zope 2.7.0 beta 1/2, and since it needs Python 2.2.3 > at least, and Stackless 3.0 was just ported to that, I tried > to build Zope with Stackless 3.0. > > It works very very well! After a few patches to get the includes > right, here the installation instructions. > > Get the current Stakless 3.0 beta. > > CVSROOT=:pserver:anonymous at centera.de:/home/cvs > export CVSROOT > > cvs co stackless > > cd stackless/src > ./configure > make > # su if your weren't root > make install > > Then, install the Zope source, and make the same dance as usual. > This is very, very cool. I've been waiting for this quite a while... Romain. From adalke at mindspring.com Sun Aug 3 02:22:46 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Sun, 3 Aug 2003 00:22:46 -0600 Subject: Match beginning of two strings References: <3f2c429e@nntp0.pdx.net> <3f2c7806.20532894@news.lexicon.net> Message-ID: Ravi: > Read in both strings. > Check to see if the first character matches. > If yes: > Check halfway through the string and see if that character matches > Repeatedly check halfway until the difference point is found. > Go back through from the difference point backwards and make sure > the characters match from the start to the difference point. > > I timed it, and it seems to be doing about 3.5usec per loop. There's a lot of overhead for doing that. Have you tried the simple char *s1 = ... the first string .. char *s2 = ... the second string .. n = ... the shorter of the two .. for(i=0; i Message-ID: WIWA wrote: > for i in range(len(month)): > output="Hits for",month[i], ":" , teller[i] > f.write(str(output)) > f.close() > Slightly off topic, here's a way to avoid the range(len(sequence)) idiom: for m, t in zip(month, teller): f.write("Hits for %s: %s\n" % (m, t)) Peter From newsgroups at jhrothjr.com Fri Aug 1 18:24:11 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Fri, 1 Aug 2003 18:24:11 -0400 Subject: How do you do unittest? References: Message-ID: "Will Stuyvesant" wrote in message news:cb035744.0308010633.3fd4e805 at posting.google.com... > I have a unittest testfile like this: > > ----------------------- test_mod.py --------------------- > import sys > sys.path.append('..') > import unittest > import mod > > class Test_rmlutils(unittest.TestCase): > > def testNormalCase(self): > self.assertEqual(.... > > > if __name__ == '__main__': > unittest.main() > --------------------------------------------------------- > > It is exactly the same as example 17-2 in "Python in a > Nutshell" (PiaN), except for the first two lines. To > quote PiaN: > "...name the test module...with a prefix such as 'test_', > and put it in a subdirectory named 'test' of the directory > where you keep the sources." > > PiaN did not mention the ugly sys.path.append('..') trick > I had to use when following its advice. I need to use it > because mod.py is in the directory above the 'test' > directory. > > To run a test from the source directory I have to change > to the 'test' directory and run test_mod.py there from the > commandline. Okay, I can do that from a batchfile: > > ----------------------- test.bat ------------------------ > cd test > test_mod.py > cd .. > --------------------------------------------------------- > > But: I would like to get rid of the need for > sys.append('..') and I don't see a nice way to do that, do > you? Maybe something from a Python script instead of a > DOS script...I am thinking about importing sys there and > then doing some advanced unittest function like > 'runsuite(blah, foo)' but I am still reading the unittest > docs and there must be somebody who did this before? > > I guess the author of PiaN does not use a 'test' subdirectory > himself, as it is now the example 17-2 does only work in the > source directory. I'm not sure what the author of Python in a Nutshell was thinking of. I have never had any problem with running unit tests, but my setup has the unit test modules in the same directory as the source modules, and I also have a script file (well, a Windows batch or command file) for each test module, as well as a test module that creates a suite with all of the other test modules. It works wonderfully well; never a problem. What's happening is that Python always puts the directory with the module you invoked into the path as the first directory, so I would suspect that your project directory isn't in the path. If you only execute out of that one directory, everything just works. If you try to import one of those modules from somewhere else, it doesn't work. If you want to keep your tests in a separate library (and there are good arguements for that - I just ignore them for myself) your actual program directory has to be on the Python path. The ".." workaround you've mentioned is one way of doing that. The way I work, I just set the Python path to what I want in the invocation scripts, or in the script that invokes the command prompt I use, and then simply use it. No muss, no fuss. John Roth From mpeuser at web.de Sun Aug 24 01:51:06 2003 From: mpeuser at web.de (Michael Peuser) Date: Sun, 24 Aug 2003 07:51:06 +0200 Subject: How to import a standard module in source file with same name? References: <420ced91.0308232052.70e905d5@posting.google.com> Message-ID: "Christos TZOTZIOY Georgiou" schrieb im Newsbeitrag news:gbigkvcgl5upje1qe14r8mqe2unsec6vmh at 4ax.com... > On 23 Aug 2003 21:52:11 -0700, rumours say that sdhyok at yahoo.com > (sdhyok) might have written: > > [snip of problem description as per the subject] > > >Under the condition that the absolute path to the standard module > >is variable in different machines > >(so, imp.find_module may not be a solution), > >is there an elegant way to solve this problem? > > You might try changing the case... call it DateTime for example; there > must be some magic in the C code (if you work on Windows) that matches > in a case-sensitive way. Or you can do (in the importing module, > possibly your main program): > > import datetime > import vp.datetime > vp.datetime.datetime = datetime > -- It i sgeneraqlly not a good idea to call a package _exactly_ as an already existing one, even if you want to superseed it. Because of Windows' case insensitivity for files for folders such a distinction should also be considered bad style. So the solution could be: User of package: import newPackage as Package or from newPackage import * Implementation of package: import Package as oldPackage and qulifying in case of use of oldPackage accordingly. Kindly Michael P From fa507874 at skynet.be Thu Aug 7 16:37:18 2003 From: fa507874 at skynet.be (conatic) Date: Thu, 07 Aug 2003 22:37:18 +0200 Subject: Hints about a script that read ftp contents .... References: <3f318f5d_3@mk-nntp-1.news.uk.worldonline.com> Message-ID: On Thu, 07 Aug 2003 00:29:21 +0100, simon place wrote: > > On the ftp holding my web space (ftp server: ProFTPD 1.2.0pre10 ) a 'stat > *.pdf' command will list all pdf files in all sub directories recursively, ( > and this is meant to be fairly standard,) unfortunately using ftp commands > directly shows up the server os dependent format that directories are listed > in ( usually UNIX ) but the functions to interpret this are in the ftp lib and > there's a more general interpretation module out there somewhere ( handles > more server os's ) With 'stat *.pdf' and classic ftplib I have this. Have you got same ? WHere is the mistake ? from ftplib import FTP ftp = FTP('ftp.python.org') # connect to host, default port ftp.login() ftp.retrlines('stat *.pdf') # list directory contents ftp.quit() ----------------------------------------------------------------------- >python -u ftp.py Traceback (most recent call last): File "ftp.py", line 4, in ? ftp.retrlines('stat *.pdf') # list directory contents File "/usr/lib/python2.2/ftplib.py", line 402, in retrlines conn = self.transfercmd(cmd) File "/usr/lib/python2.2/ftplib.py", line 346, in transfercmd return self.ntransfercmd(cmd, rest)[0] File "/usr/lib/python2.2/ftplib.py", line 330, in ntransfercmd raise error_reply, resp ftplib.error_reply: 211-status of *.pdf: 211 End of Status >Exit code: 1 From daniel.rawson.take!this!out! at asml.nl Tue Aug 12 08:14:06 2003 From: daniel.rawson.take!this!out! at asml.nl (Dan Rawson) Date: Tue, 12 Aug 2003 08:14:06 -0400 Subject: Returning a string from a boolean Message-ID: I need to return "True" or "False" strings for a boolean value (mostly for display purposes). It's obviously trivial to write the function: def bStr (bVar): if bVar: return 'True' else: return 'False' In Perl I can do this with the ternary 'if' (bVar) ? 'True' : 'False' Is there a simpler way in Python?? If it makes a difference, I'm using 2.2.2 (on Solaris) with no chance of going to 2.3 in the near future ; I know that some of this has changed in 2.3. TIA . . . Dan From danielk at aracnet.com Sun Aug 3 21:20:18 2003 From: danielk at aracnet.com (Daniel Klein) Date: Sun, 03 Aug 2003 18:20:18 -0700 Subject: True Message-ID: In Python 2.2 I use to have true = (1 == 1) false = not true This was at the recommendation of someone on this list some time ago. The reason (if I remember correctly) was that setting true = 1 false = 0 were not true booleans. Now the expression (1 == 1) returns 'True', and caused a bug in my code. So my question is what is the proper method for setting booleans in 2.3? Really confused, Daniel Klein From tjland at iserv.net Mon Aug 25 14:20:50 2003 From: tjland at iserv.net (tjland at iserv.net) Date: Mon, 25 Aug 2003 14:20:50 -0400 (EDT) Subject: Listening to keyboard input? Message-ID: <1212.65.42.184.126.1061835650.squirrel@webmail.iserv.net> Can python monitor keyboard input for lets say i want to have my program return to the main menu when the user hits escape! Can python do this or am i going to have to embed some c++ program into it? Thanx When you see the net take the shot When you miss your shot shoot again When you make your shot you win! Just remember Offense sells tickets But defense wins championships! From dave at nullcube.com Thu Aug 7 00:38:08 2003 From: dave at nullcube.com (Dave Harrison) Date: Thu, 7 Aug 2003 14:38:08 +1000 Subject: using like and % in MySQLdb Message-ID: <20030807043808.GA23514@dave@alana.ucc.usyd.edu.au> Im sure this is a really obvious problem but : self.curs.execute( """SELECT * FROM user WHERE login LIKE '%%s%'""", [login] ) will not work ... gives me an "unsupported format character ''' (0x27)" escaping the %'s with % as the doco recommends wont work either. however this : self.curs.execute( """SELECT * FROM user WHERE login LIKE '%dave%'""" ) does work so what's the go ? cheers Dave From altis at semi-retired.com Mon Aug 25 13:55:12 2003 From: altis at semi-retired.com (Kevin Altis) Date: Mon, 25 Aug 2003 10:55:12 -0700 Subject: Script to remove SoBig/F virus from POP3 mailbox References: Message-ID: <_Yr2b.1485$y1.29567@news.uswest.net> Like Alex I wrote a script last week to auto-delete potential virus attachments from my POP account. The code uses the poplib module and email package and downloads the full message to completely parse the attachments before deciding whether to delete the message or not. The latest version is sitting in cvs. No warranties implied, but I've been using it without problems since Friday. http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/pythoncard/PythonCardPrototyp e/samples/fpop/emailfilter.py ka "Alex" wrote in message news:PqacnRTDw7cVltqiXTWc-g at speakeasy.net... > Skip Montanaro wrote: > > Alex> Under the gun, I've written a Python script to delete emails > > Alex> containing this latest virus/worm (Sobig-F) from a POP3 mailbox. > > > > ... > > > > I wrote something similar today for scrubbing Mailman 2.1 pending > > administrative requests. I've killed over a thousand messages for the > > python-help mailing list so far. It's crude, but saves a huge amount of > > pointing and clicking. If you'd like a copy, drop me a note. If enough > > people are interested and it seems like there's no other easy way to > > accomplish this with the usual Mailman means, I'll place a copy on my > > website. > > > > Skip > > > > Heck, why not post? "When in doubt, ship it out." :) > > Actually, my script was small enough to simply include in the newsgroup posting. > But, it's usually handier for people to get things from the web site than trying > to sort through old news messages. > > As indicated in the private email, I solved two particular problems we had: > > 1) Used TOP to read just the start of the emails so that our bandwidth wasn't > saturated by full, virus emails. > > 2) Deleted virus scanner bounces that contained the whole, danged virus file > attachment. > > Alex > From mwilson at the-wire.com Sun Aug 31 11:28:40 2003 From: mwilson at the-wire.com (Mel Wilson) Date: Sun, 31 Aug 2003 11:28:40 -0400 Subject: Modifying the {} and [] tokens References: Message-ID: In article , Geoff Howland wrote: >On Sat, 23 Aug 2003 13:39:15 -0400, "Terry Reedy" >wrote: >>With respect to {}+{}. An in-place version of this is currently >>spelled {}.update({}). Yes, more chars to type, but also more >>'honest' in not implying symmetry between the two dicts. As the name >>suggests, duplicate key with new value overrides previous value. > >What's really the problem with a + sugar though? Currently there is >no sugar, and update() really all there is to it. There's no single clear idea on how that sugar should taste, particularly when the operands have keys in common. Personally, the applications I've written so far would like dictionary addition d+u to work like for k in u.keys(): d[k] = d.get (k, additive_identity) + u[k] where additive_identity is a magical value that's 0 working with numbers, [] with lists, () with tuples and '' with strings. In real life I'd catch the key errors instead. But those are yesterdays programs. If you asked me to guarantee that tomorrows program would use this, I'd refuse. Regards. Mel. From sheila at spamcop.net Sun Aug 31 19:57:07 2003 From: sheila at spamcop.net (Sheila King) Date: Sun, 31 Aug 2003 23:57:07 GMT Subject: MySQLdb: execute query results... Message-ID: I have searched for an answer to this question on the comp.lang.python archives at Google Groups, and also looked through the (sparse) MySQLdb documentation, and cannot confirm for a FACT what I think I know. Looking for affirmation before I go "assuming" something and getting myself into trouble somewhere along the line... Here is what I *think* I know...let me know if I'm wrong, for crying out loud!!! If I do something like: >>> db = MySQLdb.connect(passwd="mypass", host="localhost", ... db="mydb", user="myusername") >>> c = db.cursor() and then later do: >>> result = c.execute("""""") doesn't result always return the number of affected rows? As a more concrete example: I made the following table: mysql> CREATE TABLE example( -> name VARCHAR(14), -> AGE INT, -> COUNTRY VARCHAR(15)); Query OK, 0 rows affected (0.03 sec) And then in Python did the following INSERTS and UPDATE: >>> c.execute("""INSERT INTO example (name, AGE, COUNTRY) VALUES ("sheila", 29, "US");""") 1L >>> c.execute("""INSERT INTO example (name, AGE, COUNTRY) VALUES ("arthur", 23, "NL");""") 1L >>> c.execute("""INSERT INTO example (name, AGE, COUNTRY) VALUES ("bob", 29, "US");""") 1L >>> result = c.execute("""UPDATE example SET AGE=30 WHERE AGE=29;""") >>> result 2L Can I *RELY* on that "2L" result of the UPDATE statement under the cursor's "execute" method representing the number of rows updated? Or am I assuming too much? Like I say, I looked through several sources, including my O'Reilly MySQL book and cannot verify this for a fact from docs. I did find this, however: http://www.mysql.com/doc/en/UPDATE.html "UPDATE returns the number of rows that were actually changed. In MySQL Version 3.22 or later, the C API function mysql_info() returns the number of rows that were matched and updated and the number of warnings that occurred during the UPDATE. " Which seems to corroborate, although they are not referring to the Python DB-API specifically. Thanks for any clarification on this matter, -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From stephan.diehl at gmx.net Wed Aug 13 03:00:00 2003 From: stephan.diehl at gmx.net (Stephan Diehl) Date: Wed, 13 Aug 2003 09:00:00 +0200 Subject: MySQLdb and Python2.3 References: Message-ID: Torsten Marek wrote: > Stephan Diehl schrieb: >> Since using Python2.3, MySQLdb doesn't work anymore correctly. >> Inserting data fails with "IndexError: list index out of range". >> Since the MySQLdb website states, that it runs up to version 2.2, I >> definatelly shouldn't complain :-) >> Is there somebody whose MySQLdb is running with 2.3? >> >> MySQLdb 0.9.2 >> Python 2.3 >> Linux >> >> Thanks a lot for your help >> >> Stephan > I run MySQLdb 0.9.2 with Python 2.3 and MySQL 4.0.13 without > encountering any problems. > BTW: What OS do you use? Did you recompile the package? I did recompile. I'm using MySQL 3.23 though. Thanks for your info Stephan > > Torsten From adalke at mindspring.com Sun Aug 3 14:32:29 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Sun, 3 Aug 2003 12:32:29 -0600 Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> Message-ID: Dennis Lee Bieber: > Unless I'm mistaken, the folks behind TrueBASIC /were/ Kemeny and > Kurtz (spellings)... IE, the creators of the original BASIC. Yup. From truebasic.com ] John G. Kemeny and Thomas E. Kurtz invented BASIC in 1964 ] for use at Dartmouth College. They made it freely available to ] everyone who wanted to learn how to program computers. It ] soon became a world standard. ] ] In 1983 they created True BASIC to incorporate and showcase ] all the advanced developments they had added to their language, ] and offered it as a commercial product. But that doesn't implement the original BASIC language. OTOH, it does say it can convert older BASIC to TrueBASIC, so there is still backwards compatibility. That's gotta warm someone's heart knowing code written back in the 1960s on a teletype machine will still run today.. and even on a handheld. Andrew dalke at dalkescientific.com From jflanigan at netzero.net Sat Aug 16 17:15:08 2003 From: jflanigan at netzero.net (jose flanigan) Date: 16 Aug 2003 14:15:08 -0700 Subject: Problem with gui_thread and SciPy ... Message-ID: Hi, I am running python version 2.2 on a Windows NT machine. I have installed the latest version of wxPython and SciPy. However, when running pythonwin and attempting >> import gui_thread I never get an acknowledgment that this module has been successfully imported. When I try to plot anything using SciPy's plt function, the pythonwin session shuts down without warning. Any help appreciated. Thanks in advance. From christoph at mmc-startup.com Wed Aug 13 17:09:29 2003 From: christoph at mmc-startup.com (Christoph Becker-Freyseng) Date: Wed, 13 Aug 2003 23:09:29 +0200 Subject: Pssible Bug in Python Profiler Message-ID: <3F3AA909.4010303@mmc-startup.com> Hello, I started some profiling with '2.1.3 (#1, Sep 7 2002, 15:29:56) \n[GCC 2.95.4 20011002 (Debian prerelease)]' and got the following output: 6067913 function calls in -3311.947 CPU seconds Also the cumulative times are affected (at least of some calls) It took some time to run my program and so I guess there's a overflow in the seconds counter. Ideas? Suggestions? Thank You, Christoph Becker-Freyseng From wim_wauters at skynet.be Thu Aug 21 11:32:16 2003 From: wim_wauters at skynet.be (WIWA) Date: 21 Aug 2003 08:32:16 -0700 Subject: pySNMP: SNMP walk Message-ID: <538fc8e.0308210732.7ede4fd6@posting.google.com> Hi, I have installed pySNMP. I want to make an application where I read out all the OIDs of a MIB of a particular device. In other words, I want to do an SNMPwalk for a certain MIB. I can do an SNMPget using pySNMP, because that's one of the examples on the pySNMP website. There is a lot of information, but to be honnest - I cannot find my way in these docs. It doesn't give me a good view on what I have to program. Therefore, can someone point me to a kinds of pySNMP tutorial with examples. Especially the examples are welcome, because I cannot make anything out of that documentation. Thanks in advance, Wim From heikowu at ceosg.de Fri Aug 1 06:53:16 2003 From: heikowu at ceosg.de (Heiko Wundram) Date: 01 Aug 2003 12:53:16 +0200 Subject: Interfaces (a la PEP 245 and Zope) In-Reply-To: References: <78ednTw5QfxmebSiXTWJhA@august.net> Message-ID: <1059735195.2020.12.camel@d168.stw.stud.uni-saarland.de> Hey Terry! Simplest way I use to implement "interfaces": class IEditor(object): def getSelection(self,start,end): raise NotImplementedError("Implement this for IEditor") # Other mandatory functions. # ... class Editor(IEditor): # Implementation of getSelection overrides "virtual" base. # ... Checking whether a class "implements" an interface can be done with issubclass(Editor,IEditor) or isinstance(editinst,IEditor). This doesn't do rigid checking of an interface, but seems to suit most of my needs. If you devise a test-suite for your program, you'll catch the NotImplementedError inevitably when you run the code. I don't really know what __implements__ does aditionally in Zope, as I've never programmed for/with it, but I'd consider the above paradigm, it's much simpler and "just works", without extra modules. HTH! Heiko W. From mertz at gnosis.cx Sat Aug 16 12:26:22 2003 From: mertz at gnosis.cx (David Mertz) Date: Sat, 16 Aug 2003 12:26:22 -0400 Subject: Py2.3: Feedback on Sets (fwd) Message-ID: > * Is there a compelling need for additional set methods like > Set.powerset() and Set.isdisjoint(s) or are the current > offerings sufficient? I confess that I have not used sets for anything beyond testing. I love the concept, but I just haven't had the need yet (especially in something where I want to require 2.3). The mention of Set.powerset() above is quite interesting to me. It feels both exciting and dangerous :-). As we all know, the size of the powerset of S, for len(S)==N, is 2**N. Seems like it would be really easy to run into some long runtimes and memory usage. Then again, power set really is a fundamental operation on sets. And making users rewrite it each time is error prone. So I think I would advocate it, but with a fairly harsh warning in the documentation about complexity issues. Yours, David... -- mertz@ | The specter of free information is haunting the `Net! All the gnosis | powers of IP- and crypto-tyranny have entered into an unholy .cx | alliance...ideas have nothing to lose but their chains. Unite | against "intellectual property" and anti-privacy regimes! ------------------------------------------------------------------------- X-Shameless-Plug: Buy Text Processing in Python: http://tinyurl.com/jskh From piet at cs.uu.nl Mon Aug 25 14:49:28 2003 From: piet at cs.uu.nl (Piet van Oostrum) Date: 25 Aug 2003 20:49:28 +0200 Subject: [OT] Why is it called string? References: <3f44ce77$0$556$b45e6eb0@senator-bedfellow.mit.edu> <3F44DBF2.1010403@draigBrady.com> <3f453a22$1_1@themost.net> Message-ID: >>>>> Jarek Zgoda (JZ) wrote: JZ> Paul Watson pisze: >> My CS professor would insist that a byte is a collection of bits, and not >> necessarily eight. There are machines which do not have 8-bit addressable >> bytes. JZ> I remember that "byte" in French is expressed as "octet", even if it has JZ> only 7 bits... Are you sure. Several international organisations use the word 'octet' in their official specifications, to make sure that an 8-bit byte is meant. -- Piet van Oostrum URL: http://www.cs.uu.nl/~piet [PGP] Private email: P.van.Oostrum at hccnet.nl From duncan at NOSPAMrcp.co.uk Tue Aug 12 08:26:07 2003 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Tue, 12 Aug 2003 12:26:07 +0000 (UTC) Subject: Returning a string from a boolean References: Message-ID: Dan Rawson wrote in news:bhalml$1012pe$1 at ID-122008.news.uni-berlin.de: > In Perl I can do this with the ternary 'if' > > (bVar) ? 'True' : 'False' > > > Is there a simpler way in Python?? > > If it makes a difference, I'm using 2.2.2 (on Solaris) with no chance > of going to 2.3 in the near future ; I know that some of this has > changed in 2.3. > Python 2.2 and earlier, the shortest way is: return bVar and 'True' or 'False' or return ('True','False')[not bVar] Both of the above will test the truth value of bVar, so for example an empty string or empty list will return False. Personally, I would go for your original function as combining clarity with reasonable but not excessive brevity. In Python 2.3, str(bVar) will give you 'True' or 'False' as appropriate, but only if bVar is a bool. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From newsgroups at jhrothjr.com Mon Aug 18 13:40:36 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Mon, 18 Aug 2003 13:40:36 -0400 Subject: What's better about Ruby than Python? References: Message-ID: "Terry Reedy" wrote in message news:b8GdnQTH7KaPa92iXTWJkg at comcast.com... > > "John Roth" wrote in message > news:vk1c89jvdjepa4 at news.supernews.com... > > 4. Shortcut syntax for writing self in a method body. > > If you declare the first param as 's', for instance, then your > shortcut is 's.', which is pretty minimal, and hardly enough, it seems > to me, to make much fuss over. I like having a clean visual > separation between local variables and instance attributes. This particular issue has been debated a number of times, and one of the answers that always comes up is the one you trot out. Just about everyone uses "self" for good reason: everyone else uses "self", so it communicates its meaning clearly. If everyone suddenly decided to use their own terms, program readability would go down across the board; unless, of course, the only programs you read are your own. This is why Ruby's solution is superior: "self" is a reserved word, and so is the special character shortcut. There is no question as to what is meant. It eliminates essentially futile arguements in the same way that Python's indentation eliminates arguements about the proper placement of braces. John Roth > > TJR > > From jzgoda at gazeta.usun.pl Tue Aug 12 14:45:04 2003 From: jzgoda at gazeta.usun.pl (Jarek Zgoda) Date: Tue, 12 Aug 2003 18:45:04 +0000 (UTC) Subject: Is Python your only programming language? References: Message-ID: Joe Cheng pisze: > I want to ask you hard-core c.l.p Pythonistas: Do you use Python for > everything? (and I'm counting Python + C extensions as just Python) Or do > you keep another language equally close at hand, and if so, what is it? And > finally, do you foresee a day when Python can be, for all practical intents > and purposes, your only programming language? I learn new programming language each year. During last 10 years I learned 10 languages -- only in few of them I wrote more than exercises, these are Python, RPG and REXX, sorted descending. Python is most amusing and fun part of my work, I use it whenever it is possible and has any sign of advantage over any other languages but I will never try to use Python to write interactive application on OS/400. There is RPG/400 for this and other platforms have other tasks that are better accomplished in other ways than Python. But I'll continue to love Python until somebody invents something more amazing. Which looks impossible now, but remember, 10 years ago mr Gates said, that 640KB seems to be enough for everybody. ;) -- Jarek Zgoda Registered Linux User #-1 http://www.zgoda.biz/ JID:zgoda at chrome.pl http://zgoda.jogger.pl/ From mf at mrinfo.de Wed Aug 13 08:22:33 2003 From: mf at mrinfo.de (Marko Faldix) Date: Wed, 13 Aug 2003 14:22:33 +0200 Subject: list groups and users of NT domain Message-ID: Hello, I am looking for a language to achieve lists of all NT users and groups of a given NT domain on a Windows 2000 Server. It has to run within a webscript, so vbscript with windows scripting host is considered first. But before I dive into this, isn't it possible to do it with win32all? An ideal result would be something like the listings one get while changing file permissions on a file on a NT machine. I think, this extends too far, because you browse all accessible domains (isn't it?), but maybe it is sufficient enough to concentrate on one given known NT domain. Must I really use WSH and this combined with vbscript? Thanks for suggestions, -- Marko Faldix M+R Infosysteme Hubert-Wienen-Str. 24 52070 Aachen Tel.: 0241-93878-16 Fax.:0241-875095 E-Mail: marko.faldix at mplusr.de From whitton at atlantic.net Fri Aug 29 11:44:57 2003 From: whitton at atlantic.net (Travis Whitton) Date: Fri, 29 Aug 2003 15:44:57 GMT Subject: Getting class name Message-ID: Hello all, I've googled a bit, and I've failed to find an answer to this question. Is it possible to get a classes name from inside of a class? I.e., class Foo: def print_classname(self): # somehow print Foo Basically, I'm using WebWare, and I need to pass the current servlet name to a template. I don't want to have to hardcode the classname inside of every servlet. TIA, Travis Whitton From pedro.werneck at bol.com.br Sun Aug 24 08:57:21 2003 From: pedro.werneck at bol.com.br (Pedro Werneck) Date: Sun, 24 Aug 2003 12:57:21 +0000 Subject: Metaclass discussons In-Reply-To: <20030822193039.GA20830@ibook.distro.conectiva> References: <20030822193039.GA20830@ibook.distro.conectiva> Message-ID: <20030824125721.5cf376e6.pedro.werneck@bol.com.br> Hi, On Fri, 22 Aug 2003 16:30:39 -0300 Gustavo Niemeyer wrote: > Without yet considering interpreter hacks, that's what I had as a > first solution (a very limited one, I must admit): > > class M(type): pass > __metaclass__ = M > class object: > __metaclass__ = M > execfile("somemodule.py", globals(), locals()) There are some problems with this approach. It's tricky to work with packages using execfile and it doesn't work with byte-compiled files. Yet with the same idea (executing it on a hacked context) I tried something like this... --- class MetaKlass(type): pass __builtin__.object = MetaKlass("object", (), {"__slots__":[]}) somemodule = types.ModuleType("somemodule") somemodule.__file__ = "somemodule.py" data = open("somemodule.py").read() code = compile(data, "somemodule.py", "exec") somemodule.__dict__["__metaclass__"] = MetaKLass exec code in somemodule.__dict__ -- Which is essentially the same, but more "low-level". As the discussion was about new import hooks to impose metaclass on existing modules, I wrote a simple module for it, available in http://alpha.linuxmag.com.br:8080/python/Members/werneck/mop.tar.bz2 Any ideas ??? Pedro From mwh at python.net Wed Aug 27 09:59:31 2003 From: mwh at python.net (Michael Hudson) Date: Wed, 27 Aug 2003 13:59:31 GMT Subject: Mac equivalent to COM in Windows? References: <78kkkvg8ckfio141es2of1p483ohbtbit5@4ax.com> <78kkkvg8ckfio141es2of1p483ohbtbit5@4ax.com> <87ekz7tdty.fsf@pobox.com> Message-ID: <7h3vfsjcigb.fsf@pc150.maths.bris.ac.uk> jjl at pobox.com (John J. Lee) writes: > Bob Gailer writes: > > > Is there a way for a Python program to interact with MS Excel on the > > Macintosh? My goal is to extract contents of cells. > > I'd be interested in the answer to that, too. Surely COM must be in > there somewhere? This is the wrong newsgroup to find out, though. The Mac-ish anser is apple events. I don't know whether Excel's Apple Event support is useful on the Mac, though. Cheers, mwh -- For every complex problem, there is a solution that is simple, neat, and wrong. -- H. L. Mencken From sabu at pure-elite.org Wed Aug 6 18:26:43 2003 From: sabu at pure-elite.org (Xavier) Date: Wed, 6 Aug 2003 12:26:43 -1000 (HST) Subject: dl + getenv (without arguments) = segfault (python2.p2, python2.3) Message-ID: <39281.24.199.120.198.1060208803.squirrel@mail.darkscape.net> Greetings, While messing around with the "dl" module I ran into a segfault. *DO NOTE THAT THE FOLLOWING OCCURED ON 2 OF MY LINUX WORKSTATIONS* ------ # python -c 'import dl; a=dl.open("libc.so.6"); print a.call("getenv")' or while in the interpreter: import dl a=dl.open("libc.so.6") print a.call("getenv") ------ After discussing the issue with a counterpart, and thinking logically in the case of getenv(const char *name) -- the call segfaults because of the missing *name, variable. Now, my problem is not with the obvious.. but with the fact that Python segfaulted instead of raising an exception or returning 0 (in the case of my netbsd box with: Python 2.3 (#1, Aug 6 2003, 00:29:47)//[GCC 2.95.3 20010315 (release) (NetBSD nb3)] on netbsd1). Thanks, and sorry if this issue has been brought up already. Here is the full log from all 3 machines I tested it on: #1 --> python Python 2.3 (#1, Aug 6 2003, 00:29:47) [GCC 2.95.3 20010315 (release) (NetBSD nb3)] on netbsd1 Type "help", "copyright", "credits" or "license" for more information. >>> import dl >>> a=dl.open('libc.so.12.83.1') >>> print a.call('getenv') 0 #2 sabu at culprit:/root$ python Python 2.2.3+ (#1, Jul 5 2003, 11:04:18) [GCC 3.3.1 20030626 (Debian prerelease)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import dl >>> a=dl.open('libc.so.6') >>> print a.call('getenv') Segmentation fault sabu at culprit:/root$ #3 root at tixdev:~# python2.2 Python 2.2.3+ (#1, Jul 5 2003, 11:04:18) [GCC 3.3.1 20030626 (Debian prerelease)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import dl >>> a=dl.open('libc.so.6') >>> print a.call('getenv') Segmentation fault root at tixdev:~# --Xavier. From pedrosch at gazeta.pl Mon Aug 25 18:29:04 2003 From: pedrosch at gazeta.pl (Przemo Drochomirecki) Date: Tue, 26 Aug 2003 00:29:04 +0200 Subject: Determinig position of a element in a list Message-ID: Hello, i'm wondering if there is any tricky way for doing following thing: A - list of distinct integers (e.x. A = [1,3,7,11,14,15]) very fast function determinig position of number x in list A or -1 if x doesnt belong to A Operator IN returns only false/true values i can implement function index (e.x. index(5,A) = -1, index(7,A) = 2), but maybe there's is simpler(builtin?) solution Thanks From max at alcyone.com Mon Aug 18 14:52:49 2003 From: max at alcyone.com (Erik Max Francis) Date: Mon, 18 Aug 2003 11:52:49 -0700 Subject: What's better about Ruby than Python? References: <3F40892D.AEF4AAE@alcyone.com> <87isov6pk4.fsf@pobox.com> Message-ID: <3F412081.5EF7279C@alcyone.com> "John J. Lee" wrote: > Much less than a few hours? You're obviously much faster on the > uptake than me... To read and usefully absorb the tutorial in only an hour? That seems quite feasible for an experienced programmer. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ Principles have no real force except when one is well fed. \__/ Mark Twain From fredrik at pythonware.com Fri Aug 15 02:32:50 2003 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 15 Aug 2003 08:32:50 +0200 Subject: Strange re behavior: normal? References: Message-ID: Mike Rovner wrote: > IMHO that split behavior is a bug although technicaly it is not. > (From re manual: > "This module provides regular expression matching operations similar to > those found in Perl.") is "split" really a matching operation? fact is, all methods have Python-specific behaviour. it's just the RE language itself that's based on Perl. From vze4rx4y at verizon.net Thu Aug 7 09:19:40 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Thu, 07 Aug 2003 13:19:40 GMT Subject: itertools.ilen? References: Message-ID: "Jeremy Fincher" > Sometimes I find myself simply wanting the length of an iterator. For > example, to collect some (somewhat useless ;)) statistics about a program > of mine, I've got code like this: > > objs = gc.get_objects() > classes = len([obj for obj in objs if inspect.isclass(obj)]) > functions = len([obj for obj in objs if inspect.isroutine(obj)]) > modules = len([obj for obj in objs if inspect.ismodule(obj)]) > dicts = len([obj for obj in objs if type(obj) == types.DictType]) > lists = len([obj for obj in objs if type(obj) == types.ListType]) > tuples = len([obj for obj in objs if type(obj) == types.TupleType]) > > Now, obviously I can (and will, now that 2.3 is officially released :)) > replace the list comprehensions with itertools.ifilter, but I need an > itertools.ilen to find the length of such iterators. > > I can imagine such a need arises in more useful situations than this, but > this is the particular case that brought the need to mind. > > The Python code is simple, obviously: > > def ilen(iterator): > i = 0 > for _ in iterator: > i += 1 > return i > > But it's a pity to use itertools' super-fast iterators and have to use slow, > raw Python to determine their length :) For your application, it is not hard to build a itertools version: >>> import itertools >>> def countif(predicate, seqn): ... return sum(itertools.imap(predicate, seqn)) >>> def isEven(x): ... return x&1 == 0 >>> countif(isEven, xrange(1000000)) 500000 >>> def isTuple(x): ... return type(x) == types.TupleType >>> tuples = countif(isTuple, objs) Raymond Hettinger From tgray at cox-internet.com Sun Aug 17 14:47:11 2003 From: tgray at cox-internet.com (Terry Gray) Date: Sun, 17 Aug 2003 13:47:11 -0500 Subject: os.system stdout redirection [to PyQt window] In-Reply-To: <1061139086.812238@yasure> References: <1061139086.812238@yasure> Message-ID: Donn Cave wrote: > Quoth mackstann : > | On Sun, Aug 17, 2003 at 01:01:41AM -0500, Terry Gray wrote: > |> Using Python 2.2 in Debian linuxI am trying to change to a different > |> directory, execute a 'make all' command, and redirect the output of the > |> subshell to a PyQt window... I should be able to execute the > |> os.system('cd newdirectory; make all'), but how do I redirect stdout of > |> the new subshell created by the os.system call? > > | You can use os.popen (popen2 and 3 as well), or the popen2 module's > | Popen3 and 4 classes, or commands.getoutput (and there are probably even > | more ways :). > > Yes, very good, there are many ways to redirect output, but you > need to know how to make PyQt monitor a file and copy it to a window > before it matters much either way. > > I don't know, so I've changed the subject line, replacing the elipsis > ("..." - what was that for?) with [to PyQt window] to attract the > attention of someone who might have a clue. > > Do you need to write this output line by line as it comes out of make? > Or would it be fine to run make, and then wait to present all the output > after it's finished? The latter is likely to be significantly easier. > > # make output goes to both units 1 and 2 (output and error/diagnostic) > os.system('cd newdirectory; make all > make.log 2>&1') > displayfile('newdirectory/make.log') > > Donn Cave, donn at drizzle.com I need to display make's output line by line, since it a very long compile cycle (kernel compile). Thanks for the help. From fgeiger at datec.at Wed Aug 27 15:29:34 2003 From: fgeiger at datec.at (F. GEIGER) Date: Wed, 27 Aug 2003 21:29:34 +0200 Subject: [GUI Design] How to achieve short comm paths between controls? Message-ID: <3f4d0638@news.swissonline.ch> +--------------------------------------------------------------+ | | +--------------------------------------------------------------+ | +--------+ | | | Page 1 | | |-+ +---------------------------------------------------| | | +- Group ------------------------+| | # | || | lhs pane | | || rhs pane | | | || | | | || | +----------------------+ | | || | |A control, | | | Editor object || | |which properties | | | || | |have to be edited | | | || | |with the editor in the| | | || | |rhs pane | | | || | +----------------------+ | | || | | +--------------------------------+| +--------------------------------------------------------------+ When I click on the control within the lhs pane, I want to display the appropriate editor, which displays the control's properties. To do so I need the group box in the rhs pane as the editor's parent. Therefore the text control tells the MainFrame (module variable as a singleton) to display the right editor. So this path is short. But now, down the path, I get into troubles: The MainFrame does not know about the group box in the rhs pane of the active page of the notebook within the MainFrame. See? So the path is: MainFrame ---displayEditor()--> NoteBook ---displayEditor()--> Currently selected page. The nesting down stops here, because the page knows about the group box within the pane, because it created them. I'm in doubt that this is a design pattern issue. I guess it's about organizing all the controls of a GUI. Should I create a dict with control name/object pairs, held by the MainFrame? Or should the rhs group box a globally accessible singleton or Borg? Any other hint? How do you handle such situations? I sketched the app both with wxPython and PMW/Tkinter. Is this what PyQt's slots are for? Can I connect the lhs control with the rhs group box? It'S hard for me to see how this would solve the problem, because the distance between the controls remains. Well, I guess the dict mentioned above is not the worst here, is it? Any hint welcome. Regards Franz GEIGER From mpeuser at web.de Sat Aug 30 15:50:02 2003 From: mpeuser at web.de (Michael Peuser) Date: Sat, 30 Aug 2003 21:50:02 +0200 Subject: Reading and manipulating binary data References: Message-ID: "Dave" schrieb im Newsbeitrag news:biqh54$7sa$1 at balder.stud.idb.hist.no... > Hi, > > I am really confused as to how to use binary data with python. I am > currently developing a lightweight RADIUS server, which gets UDP datagrams > from a client formatted like so: > > 0 1 2 3 > 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 > +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ > | Code | Identifier | Length | > +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ > | | > | Request Authenticator | > | | > | | > +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ > | Attributes ... > +-+-+-+-+-+-+-+-+-+-+-+-+- > > I can read() the data easily enough from the socket. However, when I have > read it, it is very difficult to manipulate. I can't convert it to an > integer or a string which is driving me crazy... I have seen a lot of posts > recommending struct for dealing with binary data, but I can't get it to like > mine. I get all sorts of errors, like lengths don't match format etc. I do not see the problem at the moment. You have got a string of binary data (I think at least); the first 32 bit word consists of 2 bytes and a short. Have a look at the following snippet: from struct import * x='\x01\x02\x00\xFF' print unpack(">BBH",x) This unpacks it quite easily. Note the '>'. I assume the length is big-endian, if otherwise use '<' instead. Kindly Michael P From davecook at nowhere.net Mon Aug 18 18:35:25 2003 From: davecook at nowhere.net (David M. Cook) Date: Mon, 18 Aug 2003 22:35:25 GMT Subject: python & postgresql ? References: Message-ID: In article , GuineaPig wrote: > I'm trying to develop a cross-platform python-gui for a postgresql db. > Of course, I need some postgresql-module for python... Pygresql seems > the obvious choice, but I'm developing on windows xp. To get pygresql > to work I need to compile pygresql with a visual c++ compiler (wich I > don't have). They have a win32 installer that works fine on XP: http://sourceforge.net/project/showfiles.php?group_id=16528 > I've looked into pyPgSQL too, and this works fine under windows, but I > cannot get this to run on my linux-machine (suse 8.2). What errors are you getting? It works fine on my RH 9 box. The application I'm currently working on works with pygresql, psycopg or pypgsql: http://classicollect.sf.net Dave Cook From office at inode.at Thu Aug 21 14:15:15 2003 From: office at inode.at (Request Tracker) Date: Thu, 21 Aug 2003 20:15:15 +0200 Subject: [Tkt #601284] (office-wien) Re: Wicked screensaver Message-ID: Sehr geehrte Damen und Herren, dieses Mail wurde automatisch erstellt, da wir eine Nachricht mit dem Betreff "Re: Wicked screensaver" von Ihnen erhalten haben. Ihre Mail hat die Ticket ID [Tkt #601284] erhalten und wird in kuerze bearbeitet werden. Sie brauchen auf diese Mail nicht zu antworten. [Tkt #601284] Falls Sie mit uns bezueglich dieses Betreffs "Re: Wicked screensaver" wieder korrespondieren, verwenden Sie bitte die Ticket (Tkt) ID . Vielen Dank ! Greetings, This message has been automatically generated in response to your message regarding "Re: Wicked screensaver", the content of which appears below. There is no need to reply to it now. Request Tracker has received your message and it has been assigned a ticket ID of [Tkt #601284]. Please include the string [Tkt #601284] in the subject line of all future correspondence about this problem. To do so, you may reply to this message. Thank you ! -- Inode Telekommunikationsdienstleistungs GmbH - http://www.inode.at/ Tel.: 059999-0 Fax.: 059999 6699 Buero Wien - Millennium Tower Handelskai 94-96/43 - A-1200 Wien Buero Graz - Schmiedlstrasse 1 - A-8042 Graz Buero Linz - Wienerstrasse 131 - A-4020 Linz Buero Sbg - Schillerstrasse 30 - A-5020 Salzburg Buero Ibk - Eduard Bodem Gasse 5-7 - A-6020 Innsbruck Buero Villach - Europastrasse 8/3OG KO6A - A-9524 Villach Please see the attached file for details. >>> application/octet-stream component, message, part 2: http://rt.inode.at/stripmime1/2003/08/1061489714-9093/document_9446.pif --- Headers Follow --- Return-path: Received: from smtp-05.inode.at ([62.99.194.7] helo=smtp.inode.at) by rt.inode.at with esmtp (Exim 3.32 #1) id 19ptxq-0002Mc-00 for rt-office-wien at rt.inode.at; Thu, 21 Aug 2003 20:15:14 +0200 Received: from e-mail.inode.at ([213.229.60.101]:53470) by smtp.inode.at with esmtp (TLSv1:DES-CBC3-SHA:168) (Exim 4.10) id 19ptxl-0005Jg-00 for rt-office-wien at rt.inode.at; Thu, 21 Aug 2003 20:15:09 +0200 Received: from [212.152.255.254] (helo=INTERNET) by e-mail.inode.at with esmtp (Exim 3.22 #2) id 19ptxG-0001gZ-00 for office at inode.at; Thu, 21 Aug 2003 20:14:39 +0200 From: To: Subject: Re: Wicked screensaver Date: Thu, 21 Aug 2003 20:26:39 +0200 X-MailScanner: Found to be clean Importance: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MSMail-Priority: Normal X-Priority: 3 (Normal) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="_NextPart_000_05C49AF9" Message-Id: -------------------------------------------- Managed by Request Tracker From bokr at oz.net Sun Aug 3 01:49:44 2003 From: bokr at oz.net (Bengt Richter) Date: 3 Aug 2003 05:49:44 GMT Subject: re or html parser module, for wildcard search within html document? References: <4cec047f.0308011806.68d8d056@posting.google.com> Message-ID: On 1 Aug 2003 19:06:53 -0700, mm2ps at yahoo.co.uk (Douglas) wrote: >I want to search and replace some expressions within an html document. >Specifically, I want to replace any tag containing the word "font" >with a new tag. As I want to use some form of wild card for the >search, eg. <*font*>, should I use a regular expression module (re) or >one of the specific html parsers? If this should be done with an html >parser module then which one and where is some easy going introductory >documentation, please? > Do you want to change to another font? If you want to eliminate it altogether, you will have to eliminate the end tag also. This seems unlikely to bomb with a regex, unless someone has deleted something to make them unmatched, and then commented the trash out. But then they deserve more trash ;-) Assuming you want just to change the opening font tag to another font tag, a regex like Read starting info (I saved python page to disk) >>> html = file('www_python_org.html').read() Make regex >>> import re >>> rxo = re.compile(r'<[Ff][Oo][Nn][Tt] [^>]*>') Check original >>> rxo.findall(html) ['', '', '', '', '', '', ''] Make an new by substitution >>> html2 = rxo.sub('', html) Write it out >>> file('www_python_red.html','w').write(html2) Check what we did to the data (look at the two with the browser and see effect to left) >>> rxo.findall(html2) ['', '', '', '', '', '', ''] >>> HTH Regards, Bengt Richter From bignose-hates-spam at and-zip-does-too.com.au Sun Aug 10 21:28:38 2003 From: bignose-hates-spam at and-zip-does-too.com.au (Ben Finney) Date: Mon, 11 Aug 2003 01:28:38 GMT Subject: python spam filter: random words? References: Message-ID: On 10 Aug 2003 18:13:53 -0700, revyakin wrote: > I know fighting spam is like fighting global worming, but still.. ^^^^^^^^^^^^^^ Given that some spam contains e-mail worms, the typo is appropriate :-) > 50% of spam I get these days contains a random combination of letters > at the end of the subject line. Has anyone tried using that feature in > antispam filters? My experience has been that this practice is dropping off, since Bayesian statistical-analysis filters will glide right by random words as "not statistically significant. What I'm seeing now is spam with words taken straight from the "likely good" word lists of Bayesian filters :-) > I am also wondering why spammers add that stuff to their subject lines > anyway. To defeat spam filters that check for the occurrence of a known spam message they've seen before. As noted above, though, these are being superseded by Bayesian word metric analysis. -- Ben Finney From mis6 at pitt.edu Fri Aug 29 15:17:18 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 29 Aug 2003 12:17:18 -0700 Subject: Add two dicts References: <86ktkvkd05e88hu14hjudmfvbul7slfgkt@4ax.com> <2259b0e2.0308290440.670d316f@posting.google.com> Message-ID: <2259b0e2.0308291117.415d0e43@posting.google.com> Christos "TZOTZIOY" Georgiou wrote in message news:... > On 29 Aug 2003 05:40:15 -0700, rumours say that mis6 at pitt.edu (Michele > Simionato) might have written: > > [snip] > > > def __add__(self,other): > > self.update(other) > > return self.__class__(self) > > hm... I am not sure about this; it's not iadd, so you shouldn't modify > self. > > Perhaps you should (untested): > def __add__(self, other): > temp = self.copy() > temp.update(other) > return temp As you wish ;) Michele Simionato, Ph. D. MicheleSimionato at libero.it http://www.phyast.pitt.edu/~micheles --- Currently looking for a job --- From __peter__ at web.de Sat Aug 23 05:34:02 2003 From: __peter__ at web.de (Peter Otten) Date: Sat, 23 Aug 2003 11:34:02 +0200 Subject: Reference? References: Message-ID: Kris Caselden wrote: > I've searched all the Python docs I could find, but I haven't seen any > mention of referencing function arguments, such as you would with the > & in c/c++. Is this possible in Python? The analog of the Python way of handling args among the C-style languages is Java. So, no, you are on mission impossible :-) class Mutable: pass v1 = Mutable() v1.name = "v1" v2 = "v2" #strings are immutable def fun(a1, a2): a1.name = "a1" a2 = "a2" fun(v1, v2) print v1.name # prints a1 print v2 # prints v2 As a workaround, you can do: def fun2(): a1 = Mutable() a1.name = "A1" return a1, "A2" v1, v2 = fun2() print v1.name # prints A1 print v2 # prints A2 See the tutorial (http://www.python.org/doc/current/tut/node6.html) for the tricks you *can* do with function arguments Peter From news at fairford.co.uk Thu Aug 7 03:38:00 2003 From: news at fairford.co.uk (jim) Date: Thu, 7 Aug 2003 07:38:00 +0000 (UTC) Subject: WaitCommEvent problem on windows XP Message-ID: Hi, All I am using python (activestate 2.2.2-224) on XP home and have suddenly got the following error from a file which works fine under millenium. File "E:\code\Python\PyModbus\FEModbusV101.py", line 162, in ComPortWrite rc,mask =win32file.WaitCommEvent(self.hComm,self.Overlapped) api_error: (87, 'WaitCommError', 'The parameter is incorrect.') self..hComm is a proper handle to the comm port self.Overlapped is a proper overlapped object I think the api call requires 3 parameters but only 2 are used in python I have checked through old messages and found quite a few about this but saw no solution ? is it me ? any help gratefully received. regards Jim From irmen at -NOSPAM-REMOVETHIS-xs4all.nl Tue Aug 5 09:04:35 2003 From: irmen at -NOSPAM-REMOVETHIS-xs4all.nl (Irmen de Jong) Date: Tue, 05 Aug 2003 15:04:35 +0200 Subject: ANN: Snakelets 1.1 (simple-to-use web app server with dynamic pages) In-Reply-To: References: <3f2ea0a0$0$49110$e4fe514c@news.xs4all.nl> <3f2f7bf4$0$49103$e4fe514c@news.xs4all.nl> Message-ID: <3f2fab63$0$49103$e4fe514c@news.xs4all.nl> Karl Scalet wrote: > the reason why I asked for CGI was that I potentially > will hold a course about python/webprogramming (very > newbie level) and was thinking about an easy way to set > up an environment of such. Well, setting up Snakelets is as simple as untarring the tarball and starting serv.py. Presto, a running web server with several demo applications ready to go. Adding your own app is as simple as creating a directory and stuffing some .html files (or .y files) into it. But it depends on what you want to *achieve* with the web app in your course. If it is a few simple pages, CGI is good enough. But if you want to do stuff with sessions, or more complex pages or page interactions, IMHO CGI is quickly becoming too cumbersome. > Previously I was thinking > about twisted, but did not yet investigate about the > CGI capabilities there. Why CGI at all: Simple because > if I introduce some simple web-applications in the course > the attendees could take them and most easily transport > them to a common web-hoster. I know about CGIHTTPServer > and might end up with it. FWIW, it is trivial to create a Ypage in Snakelets or a true Snakelet that 'calls' your designated "cgi" script with the current request environment. But one thing is certain: the web app you're creating won't easily be transported to a common web-hoster, while plain old CGI scripts would. It seems that going with CGIHTTPServer (or even a pre-configured apache server that can run your python cgi scripts) is your best option. --Irmen From mwh at python.net Thu Aug 14 13:33:25 2003 From: mwh at python.net (Michael Hudson) Date: Thu, 14 Aug 2003 17:33:25 GMT Subject: 2.3: test test_normalization failed References: Message-ID: <7h33cg4403q.fsf@pc150.maths.bris.ac.uk> Hans-Joachim Widmaier writes: > When I compiled Python 2.3 at home, everything went well. make test > reported no problems. At work, though, I got: > > test test_normalization failed -- 03F9;03F9;03F9;03A3;03A3; > > At first I thought it might be a problem with a somewhat inconsistently > upgraded system, but a few looks showed me the real difference. > At home I had updated Python quite frequently and downloaded > NormalizationTest.txt some months ago. At work, I downloaded it last week. > With revision 3.2.0 of said file the test passes, with revision 4.0.0 it > fails. This is known: Python from CVS explicitly requests the 3.2 file. > I have almost zip knowledge of the whole unicode business 'til now, so > I'm not overly concerned. Was 3.2.0 buggy? Is 4.0.0 buggy? Are there > different, incompatible specs? (Now _that_ I can't think of!) I would imagine it being something like unicode 4 adding more characters, but Python 2.3 -- being built on 3.2 normalization data -- doesn't know how these new character compose or decompose. Just a guess. Cheers, mwh -- Enlightenment is probably antithetical to impatience. -- Erik Naggum, comp.lang.lisp From jjl at pobox.com Sat Aug 23 19:31:15 2003 From: jjl at pobox.com (John J. Lee) Date: 24 Aug 2003 00:31:15 +0100 Subject: Python is darn fast (was: How fast is Python) References: <2259b0e2.0308230737.8a9bc1c@posting.google.com> <3F47AA73.7040104@draigBrady.com> <3f47bbc3$0$49114$e4fe514c@news.xs4all.nl> Message-ID: <87wud4x870.fsf@pobox.com> Irmen de Jong writes: > P at draigBrady.com wrote: > > > try a 3.x series gcc with the appropriate -march=pentium3 > > You'll be pleasently surprised. > > In my other reply I mentioned that I still get a Python+Psyco > advantage of 30% over a gcc 3.2.2 compiled version. > My gcc is doing a lot better than Michele's reported 50% difference, > but Python+Psyco still wins :-) So, the interesting part is: why? John From c-b-o-o-m-e-r at tiscali.co.uk Wed Aug 6 09:26:32 2003 From: c-b-o-o-m-e-r at tiscali.co.uk (Christopher Boomer (don't dash!)) Date: Wed, 6 Aug 2003 14:26:32 +0100 Subject: Isn't there a substring(start, end)-function???? References: Message-ID: <3f310239_2@mk-nntp-2.news.uk.tiscali.com> > You are ;-) You couldn't find it in the documentation for the modules because > it's a base operator on the string itself: Surely a lesson to be learned there? I am still a relative newcomer and regularly find myself stumbling round the tutorial to find the answers that are too easy for the library reference. Christopher Boomer. From tjreedy at udel.edu Wed Aug 27 08:58:43 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 27 Aug 2003 08:58:43 -0400 Subject: mpeg problem with pygame References: Message-ID: "AnsNum" wrote in message news:bii76h$a1n$1 at news-reader2.wanadoo.fr... > hello, > when I start this program, the movie doesn't play smoothly, anybody has an > idea ? > (I use windowsXP) If you do not get a satisfactory answer here, try the pygame mailing list. In general, questions about third-party packages are best asked on package-specific forums. Idea: perhaps your system is underpowered for running both XP and a movie. Terry J. Reedy From tzot at sil-tec.gr Fri Aug 22 03:19:01 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Fri, 22 Aug 2003 10:19:01 +0300 Subject: Py2.3: Feedback on Sets References: <20030817193709.460B22210E@techunix.technion.ac.il> <001701c3652c$2c621e20$e841fea9@oemcomputer> Message-ID: On Wed, 20 Aug 2003 11:10:58 +0300 (IDT), rumours say that Beni Cherniavsky might have written: >P.S. I wonder what happens if I do:: > > s = Set([1, 2]) > s.add(s) > >how badly will operations on it break then? They won't. Sets are mutable, so adding a Set to itself actually adds an ImmutableSet copy constructed on the fly. -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From jjl at pobox.com Sat Aug 23 12:33:43 2003 From: jjl at pobox.com (John J. Lee) Date: 23 Aug 2003 17:33:43 +0100 Subject: large-scale app development in python? References: Message-ID: <87y8xk9vvc.fsf@pobox.com> gabor writes: [...] > are there any people who wrote a big program in python? how did they > handle these problems? [...] There have been threads on this in the past: google groups with something like 'group:comp.lang.python "large-scale"' brings up a lot of stuff. Once you've read a bit, adding search terms naming some of the examples of big Python codes you find (eg. zope) will no doubt make it easier to find lists people have posted. Googling for "python success stories" also brings up some more diverse stuff (not all large-scale, but no doubt interesting to you). John From borcis at users.ch Sun Aug 3 12:53:44 2003 From: borcis at users.ch (Borcis) Date: Sun, 03 Aug 2003 18:53:44 +0200 Subject: Announcing issue 2 of The Agile Developer's Life free eZine References: <3F293658.3030609@users.ch> <3F2BC7B0.E9506C91@engcorp.com> Message-ID: <3F2D3E18.2020500@users.ch> Peter Hansen wrote: > Borcis wrote: > >>DevCoach wrote: >> >>>I have just published the second issue of The Agile Developer's Life >>>(formerly called The Agile Life) >> >>How much of Rumsfeld's special vocab does it port to computer programming ? > > > Translation, please, anyone? "Agile" as a buzzword in the current sense, I first heard applied by Rumsfeld to the military, so that I naturally concieve of it as an interface component to Rumsfeld's mind. Hence "porting". From usenet_spam at janc.invalid Sun Aug 31 22:48:05 2003 From: usenet_spam at janc.invalid (JanC) Date: Mon, 01 Sep 2003 02:48:05 GMT Subject: Win32 documentation in CHM? References: <87r832u1jv.fsf@voodoo.fake> Message-ID: Lawrence Oluyede schreef: > Yeah, you're right, I recently switched from Win to Linux (cause I > have to use Linux for job stuff) and the only thing that I really miss > is something like chm compiled documentation. The wxWindows/wxPython helpviewer utility uses a subset of the MS HTML Workshop format: For wxPython-version look in: site-packages/wxPython/tools -- JanC "Be strict when sending and tolerant when receiving." RFC 1958 - Architectural Principles of the Internet - section 3.9 From bh at intevation.de Tue Aug 5 12:01:13 2003 From: bh at intevation.de (Bernhard Herzog) Date: Tue, 05 Aug 2003 18:01:13 +0200 Subject: Capture PID of child process References: Message-ID: <6qr8403xh2.fsf@salmakis.intevation.de> klappnase at web.de (klappnase) writes: > self.pp = popen2.Popen3(cmd) > cmdpid = self.pp.pid > > However I found that the PID returned by self.pp.pid is not the PID of > the process of interest, but the PID of a subshell in which this child > process is running. If cmd is a string popen will start a sub-shell so that'd the pid you get. You could try to prefix your command with exec so that your command's process replaces the shell process (see the shell documentation). Alternatively you could use a list of strings as the command so that no shell is used in the first place, i.e. "prog param" would become ["prog", "param"]. This approach has the advantage that you don't have to worry about shell quoting but it's less portable because it's not even documented (I'll file a bug report for that). Bernhard -- Intevation GmbH http://intevation.de/ Sketch http://sketch.sourceforge.net/ Thuban http://thuban.intevation.org/ From bgailer at alum.rpi.edu Wed Aug 27 17:49:14 2003 From: bgailer at alum.rpi.edu (Bob Gailer) Date: Wed, 27 Aug 2003 15:49:14 -0600 Subject: OT: Celebrity advice (was: Advice to a Junior in High School?) In-Reply-To: <20030827201213.GA4670@nl.linux.org> References: <3F4D0D8B.5E5F9488@engcorp.com> <3F4D0D8B.5E5F9488@engcorp.com> Message-ID: <5.2.1.1.0.20030827154824.044e9dc0@66.28.54.253> At 10:12 PM 8/27/2003 +0200, Gerrit Holl wrote: >[snip] OK; I'll bite. Why do you quote from Hammurabi, Code of Law? >156. If a man betroth a girl to his son, but his son has not known her, >and if then he defile her, he shall pay her half a gold mina, and >compensate her for all that she brought out of her father's house. She may >marry the man of her heart. > -- 1780 BC, Hammurabi, Code of Law Bob Gailer bgailer at alum.rpi.edu 303 442 2625 -------------- next part -------------- --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.506 / Virus Database: 303 - Release Date: 8/1/2003 From tismer at tismer.com Thu Aug 14 13:38:34 2003 From: tismer at tismer.com (Christian Tismer) Date: Thu, 14 Aug 2003 19:38:34 +0200 Subject: 3 new slogans In-Reply-To: <3f3b9cfe@news.swissonline.ch> References: <3f3b9cfe@news.swissonline.ch> Message-ID: <3F3BC91A.5030907@tismer.com> F. GEIGER wrote: > Years ago I read in Usenet "Less code, more results". Was it in a VB group? > I forgot. Anyway, it really applies to Python. > > "Python - less code, more results". Reminds me of some sentence of mine if a different context (long thread about some work which didn't happen) "less words, more code" -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 mobile +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From tzot at sil-tec.gr Fri Aug 22 11:54:56 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Fri, 22 Aug 2003 18:54:56 +0300 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: <3F41208F.40021A68@engcorp.com> Message-ID: <8oeckvgqejo8kniupsm09ccbhhq8rk1ja0@4ax.com> On Mon, 18 Aug 2003 16:22:01 -0400, rumours say that "John Roth" might have written: >All of the Ruby collections implement a .each method, which is essentially >a version of the Visitor pattern. If I want to do something to every element >in a list or a dict (or any kind of collection,) all I have to do is say >something >like (using Python syntax): > >collectObj.each() You can do similar things in Python, just wrap your collection in a class. Check this module: http://www.sil-tec.gr/~tzot/python/predicates.py See the test cases after the line if __name__ == "main": Does this work for you? Esp. the do method. PS I don't believe that the my final test labeled "Tricky" works, but RSN I'm going to work on it :) -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From mpeuser at web.de Wed Aug 13 06:55:23 2003 From: mpeuser at web.de (Michael Peuser) Date: Wed, 13 Aug 2003 12:55:23 +0200 Subject: two quick questions References: <3F39D89B.A7160172@alcyone.com> Message-ID: Sorry! Correction in case #2 (see below) Michael ----- Original Message ----- From: "Michael Peuser" Newsgroups: comp.lang.python Sent: Wednesday, August 13, 2003 9:12 AM Subject: Re: two quick questions > The following examples might clear the more rheoretical elaborations ..... > > > def noUse(a): > a=(4,5,6) > > def tricky(a): > a[0]=(7,8,9) > > # case 1 > x=[1,2,3] > print x > tricky(x) > > x=(1,2,3) > # case 2 > noUse(x) # of course! not: noUse ([x]) > print x > > # case 3 > tricky([x]) > print x > > # case 4 > y=[x] > tricky (y) > print x > print y[0] > > # case 5 > tricky(x) > print x > > > Kindly > Michael Peuser > > "Erik Max Francis" schrieb im Newsbeitrag > news:3F39D89B.A7160172 at alcyone.com... > > Elaine Jackson wrote: > > > > > 1) Does Python have passing-by-reference? > > > > It depends on exactly what you mean by that. In a sense all Python > > objects are passed by reference, but only in the sense that the > > reference is passed by value. (Say that three times fast.) > > > > If you want to get the equivalent of a C++ reference on an immutable > > object, you can do it with containment. Pass the function a mutable > > container containing your object, and then manipulate/change the > > contained object. In the caller's scope, the container will have > > mutated. > > > > > 2) In ordinary parlance, "deep" implies "shallow" but not conversely. > > > In the > > > Python "copy" module (if I understand correctly), the implication goes > > > the other > > > way. Do you find this a nuisance? > > > > I'm not sure what about the copy's modules semantics you're thinking are > > reversed, but the terminology used in the copy module is common in > > computer science. A shallow copy means that the object is copied, but > > it will retain the same references to contained objects; a deep copy > > means that the object is copied, as well as the objects it contains (and > > so on, recursively). A deep copy always does the same thing as a > > shallow copy, and more. > > > > -- > > Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ > > __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE > > / \ I always entertain great hopes. > > \__/ Robert Frost > > From eltronic at juno.com Sun Aug 24 15:12:35 2003 From: eltronic at juno.com (eltronic at juno.com) Date: Sun, 24 Aug 2003 15:12:35 -0400 Subject: macro FAQ Message-ID: <20030824.152231.-216293.0.eltronic@juno.com> On 24 Aug 2003 16:43:42 +0200 Jacek Generowicz writes: > As I've said repeatedly: true > - I do _not_ necessarily advocate the inclusion of macros in > Python. grain of salt? > - I merely wish to dispel the myth that macros make code less > readable[*]: they _ease_ understanding of the code. maybe with 'a few' simple macros. the fear, if any, is that imported files depending on more macros will eventually be too great to fit your brain. its a decision many agree with and has been amply fleshed out with all sides represented. we would all use them, debug them, curse them often. macros containing macros will be possible. with latent bugs and security holes now multiplied. they can solve nothing useful speedwise since they wont replace code inline. with lazy evaluation of code this is less of a concern. > > [*] And they don't fragment languages either. I'm betting you usually get the last word. macros [will/might/beyond all doubt can] fragment the language into harder to read pieces. not the origional argument, but a concern. if everyone shoots for 100% of their personal truth the FAQ will be unreadable. keep it to at most few short paragraphs please. e please forward all spam to "not my real email" ________________________________________________________________ The best thing to hit the internet in years - Juno SpeedBand! Surf the web up to FIVE TIMES FASTER! Only $14.95/ month - visit www.juno.com to sign up today! From ganamide at msn.com Sat Aug 23 22:59:22 2003 From: ganamide at msn.com (Chris Matuszewski) Date: 23 Aug 2003 19:59:22 -0700 Subject: Fatal Python error: Interpreter not initialized (version mismatch?) - Solution Message-ID: Potential Solution! I had this problem when I built an extension module using a debug version of python.lib. The problem occured when attempting to import the extended module with the release version of the python executable. This solution will probably work vice versa. So if you link to pythonxx_d.lib, then use python_d.exe (on windows) If you link using pythonxx.lib, then use python.exe From clay at shirky.com Fri Aug 8 21:56:30 2003 From: clay at shirky.com (Clay Shirky) Date: 8 Aug 2003 18:56:30 -0700 Subject: regular expression back references References: Message-ID: <25373bfe.0308081756.77ac86a8@posting.google.com> ruach at chpc.utah.edu (Matthew) wrote in message news:... > Here is my patteren: > > macExpression = "^[0-9A-F]{1,2}(\:|\.|\-)[0-9A-F]{1,2}\1[0-9A-F]{1,2}\1[0-9A-F]{1,2}\1[0-9A-F]{1,2}\1[0-9A-F]{1,2}$: good lord, that looks like perl. that sort of thing is miserable to write and miserable to maintain. it makes more sense to treat MAC addresses as numbers than strings (and saves you the horror of upper/lower case and "is it 0 or 00?" issues as well) use the re moduel to figure out what to split on, then convert everything to numeric comparisons. here's an example, more readable than the macExpression above: import re orig_list = [ 0, 160, 201, 238, 178, 192 ] # test MAC as numbers new_addresses = [ "00:30:65:01:dc:9f", # various formats... "00-03-93-52-0c-c6", "00.A0.C9.EE.B2.C0" ] for new_address in new_addresses: test_list = [] # use regexes to see what to split on if re.search(":", new_address): new_list = new_address.split(":") elif re.search("-", new_address): new_list = new_address.split("-") elif re.search(".", new_address): new_list = new_address.split(".") # convert alphanumeric hex strings to numbers # via a long() cast, in base 16 for two_byte in new_list: test_list.append(long(two_byte, 16)) # make a test list if test_list == orig_list: # check for numeric matches print new_address, "matches..." else: print new_address, "doesn't match..." From jfmoxley at MIT.EDU Sun Aug 24 13:31:58 2003 From: jfmoxley at MIT.EDU (Joel Forrest Moxley) Date: Sun, 24 Aug 2003 13:31:58 -0400 (EDT) Subject: nested data structures in classes Message-ID: Greetings python-list! The good news is that I've been having a blast with Python since early Spring. I've had great success in both learning the language from online / usegroup resources and implementing it in one of my projects. However, I can't pretend to be an expert, and I do not have a strong comp sci background. This is a question that I've had for a while. Usually, I'll stumble across the answer with repeated attempts and re-searching the groups, but I didn't have luck with this one, even in a Dietel book I picked up at the library. I'm assuming there's an obvious answer, so maybe ya'll can save me some time. My Python use involves organizing nested list information. In a simplified example, you could imagine a list of reactants and products in a chemical reaction. Thus, len(nested_list_of_reactants) = len(nested_list_of_products) => "number of reactions" where: nested_list_of_reactants[i] => "list of reactants for reaction i" where: nested_list_of_reactants[i][j] => "reactant j of reaction i" And so forth. Obviously, there are many attributes associated with a specific reaction. Currently, I just pass these attribute lists (nested and non-nested) into and out of functions. However, I'd like to be able to create a class that would streamline this. E.g., (this is a MATLAB structure whose qualities I'd like to emulate): reaction(27).name = 'fawlty towers' reaction(27).reactant(2).name = 'john cleese' Currently, I'd have a list and a nested list to take care of this... reaction_name[27] = 'fawlty towers' and reactants[27][2] = 'john cleese' if this makes sense. Any thoughts or suggestions on this type of data structuring would be greatly appreciated. Python love, Joel From Gerald.Klix at klix.ch Mon Aug 18 08:00:42 2003 From: Gerald.Klix at klix.ch (Gerald Klix) Date: Mon, 18 Aug 2003 14:00:42 +0200 Subject: advice choosing IDE References: Message-ID: <3F40BFEA.1080501@klix.ch> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 You may give idle a try. It comes with the python standard distribution and should have no installation hassels. Under Debian linix it is installed as "idle-python", "idle-python2.3" or "idle-python2.x", depending on the python version installed. If you don't mind installing some additional software and an extended startup time you may try Boa Constructor. It has - besides many other features - a builtin GUI builder and claims to be sort of "Delphi for Python". Boa Constructors Home Page can be found at: http://boa-constructor.sourceforge.net/ HTH, Gerald Lupe wrote: | I'm convinced to try Python! | | I've read many posts, and although I recently bought a book on C to start | learning it, I'd like to give Python a good chance. | | What IDE would you recommend for someone who needs easiness of use with a | background of Pascal and VB for MS Office? I've definitely changed to | Linux now and I would like a free IDE either for procedural or object | oriented programming. | | I'd need an easy help on syntax, if possible with examples and a front end | debugger with easy trace, breakpoints and watches. | | Programming is not my profession, just a hobby! | | With all this in mind what would be your recommendation? I've read so many | posts on the subject that I'm confused. For a beginner, I just need one | solution... | | Lupe -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (GNU/Linux) Comment: Using GnuPG with Debian - http://enigmail.mozdev.org iD8DBQE/QL/pEDg9cqFA1jQRAkSYAJ9Csppn0pGfZKAFn2qIckxbCVYDqACfQsT7 cLWSeAXW5vPnLg26Ynt3YeI= =q8jG -----END PGP SIGNATURE----- From hokiegal99 at hotmail.com Tue Aug 26 23:32:37 2003 From: hokiegal99 at hotmail.com (hokiegal99) Date: Tue, 26 Aug 2003 23:32:37 -0400 Subject: String find and replace References: <3F4C04F8.5070401@vt.edu> <3F4C1046.1030704@hotmail.com> <3F4C1BF8.6A19CA06@alcyone.com> Message-ID: <3F4C2655.9000306@hotmail.com> Easy for you maybe ;) That works great. I learn something each time I post to the list. With a community like this, Python will be around forever!!! Thanks for the help. Erik Max Francis wrote: > hokiegal99 wrote: > > >>I hate to answer my own post, but I think I understand what I'm doing >>wrong. I'm finding and replacing 'this' with 'that' in the varible >>named >>mystr, not the actual files. So, how would I go about making the >>change >>to the actual files instead of a variable that contains their content? > > > Easy: > > inputFile = file(filename, 'r') > data = inputFile.read() > inputFile.close() > data = data.replace(this, that) > outputFile = file(filename, 'w') > outputFile.write(data) > outputFile.close() From faizan at jaredweb.com Fri Aug 1 17:50:30 2003 From: faizan at jaredweb.com (Fazer) Date: 1 Aug 2003 14:50:30 -0700 Subject: SSH and Windows References: <3F2069BD.1FE2EC2@engcorp.com> Message-ID: <7b454334.0308011350.226fd55@posting.google.com> Peter Hansen wrote in message news:<3F2069BD.1FE2EC2 at engcorp.com>... > Isaac Raway wrote: > > > > Hello. I'm writing a Python program that connects to servers through > > telnetlib to execute a few commands. I've discovered that some of the > > servers that I have to connect to with this program run only SSH, so I > > need to add support for SSH to the program. I'm looking for a library > > that behaves similarly to telnetlib for SSH connections. Does anyone > > know of one? I was going to try using pexpect to control the Windows > > telnet command, but pexpect only works on Unix. > > If it's just to execute a few commands, consider downloading PLink > (from the PuTTY site) and use it via os.system(). It works well. > > -Peter Hmm...is there a *nix version for PLink? I checked PuTTY's site and it's all for Windows. Or maybe an alternative for PLink for *nix? From peter at engcorp.com Thu Aug 28 18:13:04 2003 From: peter at engcorp.com (Peter Hansen) Date: Thu, 28 Aug 2003 18:13:04 -0400 Subject: changing color on the command prompt References: <731fc603.0308271213.4d91ab29@posting.google.com> <3F4D34C5.150FD96E@engcorp.com> <731fc603.0308281044.7e545096@posting.google.com> Message-ID: <3F4E7E70.B9DC7546@engcorp.com> Hank wrote: > > I meant the prompt for Windows operating system C:>. And by error > messages i just mean printouts like > print "Error in Process" > > If its just an environment variable, i should be able to change it, > print it out and change it back to the original color right? > > Anyone know which variable i have to modify? It's not a variable, and now that you've clarified what you mean (as near as I can tell it has nothing to do with the prompt itself, which is the text that is displayed in the console *after* your program has terminated, in the case of Windows the C:\> thing) I can safely say you need to follow this advice: > Peter Hansen wrote in message news:<3F4D34C5.150FD96E at engcorp.com>... > > If you mean the console text color, check the archives for the last couple > > of days for responses to a similar question (search for "ansi.sys" perhaps). The key is having the ANSI.SYS driver installed, so if you want this to work for anyone using your program, you may be out of luck since most don't have it running. (I think... others are more expert in this area.) -Peter From adamv at nwlink.com Sun Aug 3 18:41:53 2003 From: adamv at nwlink.com (Adam Vandenberg) Date: Sun, 3 Aug 2003 15:41:53 -0700 Subject: HOME Directory in posix and nt References: Message-ID: >>Subject: HOME Directory in posix and nt On POSIX there are various standard ways that people have mentioned. Under NT, the concept of a home directory is a little iffier. If you want this directory so you can store some app configuration data (ie, ~/.myappsettings), what you want to do under NT is to get the application data folder: >>> import os >>> print os.getenv('APPDATA') C:\Documents and Settings\Adam Vandenberg\Application Data Make a subfolder in there for your app and stick your configuration in the subfolder. Unfortunately it isn't very symetric with the POSIX way, so you have to sniff platforms to figure out which form to use. Hope this helps. -Adam From jjl at pobox.com Fri Aug 22 20:04:24 2003 From: jjl at pobox.com (John J. Lee) Date: 23 Aug 2003 01:04:24 +0100 Subject: Deficiency in urllib/socket for https? References: <6vaakvorefvifnt3fk59r6tcj16c59rrfi@4ax.com> <87r83dzr34.fsf@pobox.com> <1hlckvot3mr78up9o52uiutse4ofh1d2vq@4ax.com> <87fzjtpefg.fsf@pobox.com> <87bruhpdkm.fsf@pobox.com> Message-ID: <87isopi6if.fsf@pobox.com> jjl at pobox.com (John J. Lee) writes: > jjl at pobox.com (John J. Lee) writes: > [...] > > Would you mind submitting a doc patch (both urllib and urllib2 docs > > appear to need fixing -- urllib2 to say that it never verifies, urllib > > to say that it skips verification if an appropriate x509 mapping isn't > > supplied)? > > Hmm, maybe I've got this wrong: the fact that key/cert args are passed > to httplib.HTTPS by urllib doesn't mean authentication happens, and > the fact that they're not passed by urllib2 doesn't mean > authentication doesn't happen. I'll investigate. Bah! *After* reading the source, I found this in the ssl module docs: | Warning: This does not do any certificate verification! (which the _ssl.c source confirms: it uses SSL_VERIFY_NONE, but doesn't call SSL_get_verify_result). So the urllib docs are wrong: | Additional keyword parameters, collected in x509, are used for | authentication with the https: scheme. The keywords key_file and | cert_file are supported; both are needed to actually retrieve a | resource at an https: URL. They're not needed, and they're never used for authentication (if you don't count just checking the key without verifying it against the certificate). Given this, the fact that urllib2 doesn't have arguments for this starts to look like a feature, not a bug! Actually (dredging up very hazy memories here) aren't you supposed to check a revocation list, too? Is that given in a URL in the certificate? No idea how this SSL stuff is supposed to work, really... I'll upload a doc patch in a minute. So, in summary, none of httplib, urllib and urllib2 in standard Python do proper authentication (because the socket module doesn't). There are third-party SSL libraries for Python: m2crypto is one. If you need it, and assuming m2crypto has an ssl function with the same interface that *does* do better auth, I suppose you could probably do import socket from m2crypto import ssl # or whatever socket.ssl = ssl And have urllib magically start working, with any luck. John From hokiegal99 at hotmail.com Wed Aug 27 12:41:24 2003 From: hokiegal99 at hotmail.com (hokiegal99) Date: Wed, 27 Aug 2003 12:41:24 -0400 Subject: String find and replace References: <3F4C04F8.5070401@vt.edu> Message-ID: <3F4CDF34.1030705@hotmail.com> Thomas G?ttler wrote: > I once wrote a replace recursive script. Maybe it helps you: > http://www.thomas-guettler.de/scripts/replace-recursive.py.txt > > thomas Yes that's very helpful, but a bit too complex for me at this point in time. Here is the script that I put together from all of the responses I recieved from the list: #Thanks to comp.lang.python import os, string print " " print "******************************************************" print " Three Easy Steps to a Recursive find and Replace " print "******************************************************" print " " x = raw_input("1. Enter the string that you'd like to find: ") print " " y = raw_input("2. What would you like to replace %s with: " %x) print " " setpath = raw_input("3. Enter the path where the prgroam should run: ") print " " for root, dirs, files in os.walk(setpath): fname = files for fname in files: inputFile = file(os.path.join(root,fname), 'r') data = inputFile.read() inputFile.close() search = string.find(data, x) if search >=1: data = data.replace(x, y) outputFile = file(os.path.join(root,fname), 'w') outputFile.write(data) outputFile.close() print "Replacing", x, "with", y, "in", fname print " " print "**********" print " Done " print "**********" print " " From a.schmolck at gmx.net Thu Aug 14 04:44:56 2003 From: a.schmolck at gmx.net (Alexander Schmolck) Date: 14 Aug 2003 09:44:56 +0100 Subject: Testing a class at the interactive prompt? References: Message-ID: Dan Rawson writes: > How can I reload a class at the interactive prompt?? > > >>> from MyClass import MyClass1 > >>> x = MyClass1() > ..... edit MyClass.py to modify a method in another window . . . > >>> reload(MyClass1) (or reload(MyClass), or ...) >>> reload(MyClass) >>> from MyClass import MyClass1 or >>> MyClass1 = MyClass.MyClass1 'as From mkur at poczta.gazeta.pl Thu Aug 21 16:23:43 2003 From: mkur at poczta.gazeta.pl (=?ISO-8859-2?Q?Micha=B3?= Kurowski) Date: Thu, 21 Aug 2003 20:23:43 +0000 (UTC) Subject: FieldStorage and standard files Message-ID: Hi, That's probably an easy one: I need to make a FiledStorage instances form usual unix filesystem files. When I do: fp = open('a file', 'r') fs = cgi.Filed.Storage(fp=fp) ... the "fs" does not know it has a file and I cannot pass it further, etc. What's the trick ? -- Michal Kurowski From chris.gonnerman at newcenturycomputers.net Thu Aug 7 23:04:03 2003 From: chris.gonnerman at newcenturycomputers.net (Chris Gonnerman) Date: Thu, 7 Aug 2003 22:04:03 -0500 Subject: Building extensions with mingw32 -- bdist_wininst fails. References: Message-ID: <001d01c35d59$b95788e0$1f00000a@house> ----- Original Message ----- From: "Thomas Heller" > > I checked the archives regarding that error message and > > found a conversation wherein Jeremy Hylton claimed he > > might have added the code to detect this, and Paul Moore > > asked to have it removed/disabled at least for mingw32 > > (which makes binaries 100% compatible with MSVC6). In > > the case given then, the extension wouldn't build at > > all; now it builds but I can't make a Windows installer > > from it. > > Can you point me to this discussion, please? Then I'll > try to look after this. > > Thomas Thanks! First, here's where I found the messages I refer to above: http://mail.python.org/pipermail/distutils-sig/2003-July/003339.html OK, here's the problem. The distutils bdist_wininst script calls build (illustrated below) but does not accept --compiler=mingw32. This is obviously wrong, but I'm unsure how to fix it (I'm still trying to wrap my fuzzy and tired mind around the entire distutils thing). Here it is with Python 2.2.2 and Python 2.3. I never realized this before, but the --compiler option doesn't work with bdist_wininst in that version either. I've been doing the build first, then bdist_wininst as a separate command, and that works... evidently because the MSVC compiler version check isn't there, the MSVCCompiler class accepts the binaries built by a previous pass of the mingw32 compiler. Adding the compiler version check simply makes the error in the bdist_wininst script obvious. With PYTHON 2.2.2 (downloaded from python.org) ---------------------------------------------------------- C:\usr\WConio-1.5>python setup.py bdist_wininst --compiler=mingw32 usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...] or: setup.py --help [cmd1 cmd2 ...] or: setup.py --help-commands or: setup.py cmd --help error: option --compiler not recognized C:\usr\WConio-1.5>python setup.py build --compiler=mingw32 running build running build_py creating build creating build\lib.win32-2.2 copying WConio.py -> build\lib.win32-2.2 running build_ext building '_WConio' extension creating build\temp.win32-2.2 creating build\temp.win32-2.2\Release C:\MINGW32\BIN\gcc.exe -mno-cygwin -mdll -O -Wall -IC:\PYTHON\include -c WConiom odule.c -o build\temp.win32-2.2\Release\wconiomodule.o WConiomodule.c:139: warning: `ConPuts' defined but not used writing build\temp.win32-2.2\Release\_WConio.def C:\MINGW32\BIN\dllwrap.exe -mno-cygwin -mdll -static --output-lib build\temp.win 32-2.2\Release\lib_WConio.a --def build\temp.win32-2.2\Release\_WConio.def -s build\temp.win32-2.2\Release\wconiomodule.o -LC:\PYTHON\libs -lpython22 -o build\lib.win32-2.2\_WConio.pyd With PYTHON 2.3 (also downloaded from python.org) ---------------------------------------------------------- C:\usr\WConio-1.5>python setup.py build --compiler=mingw32 running build running build_py creating build creating build\lib.win32-2.3 copying WConio.py -> build\lib.win32-2.3 running build_ext building '_WConio' extension creating build\temp.win32-2.3 creating build\temp.win32-2.3\Release C:\MINGW32\BIN\gcc.exe -mno-cygwin -mdll -O -Wall -IC:\PYTHON\include -IC:\P YTHO N\PC -c WConiomodule.c -o build\temp.win32-2.3\Release\wconiomodule.o WConiomodule.c:139: warning: `ConPuts' defined but not used writing build\temp.win32-2.3\Release\_WConio.def C:\MINGW32\BIN\dllwrap.exe -mno-cygwin -mdll -static --output-lib build\temp.win 32-2.3\Release\lib_WConio.a --def build\temp.win32-2.3\Release\_WConio.def -s build\temp.win32-2.3\Release\wconiomodule.o -LC:\PYTHON\libs -LC:\PYTHON\PCB uild -lpython23 -o build\lib.win32-2.3\_WConio.pyd C:\usr\WConio-1.5>python setup.py bdist_wininst running bdist_wininst running build running build_py running build_ext error: Python was built with version 6 of Visual Studio, and extensions need to be built with the same version of the compiler, but it isn't installed. ------------------------------------------------------------ Note that the error message for adding --compiler=mingw32 to bdist_wininst is the same for both versions, so I've omitted it here. Chris Gonnerman -- chris.gonnerman at newcenturycomputers.net http://newcenturycomputers.net From skip at pobox.com Mon Aug 25 10:45:16 2003 From: skip at pobox.com (Skip Montanaro) Date: Mon, 25 Aug 2003 09:45:16 -0500 Subject: Suggestion/recommendation for dictionary formatting In-Reply-To: References: Message-ID: <16202.8444.639956.834417@montanaro.dyndns.org> John> I've experimented with this and concluded: John> {1:2, 3:4, 5:6, 7:8} John> is more readable than the current output: John> {1: 2, 3: 4, 5: 6, 7: 8} ... John> Comments anyone? Have you tried the pprint module? For small dictionaries it prints the normal way, but for large dictionaries it prints one element per row. Skip From jpb at ApesSeekingKnowledge.net Wed Aug 20 22:39:25 2003 From: jpb at ApesSeekingKnowledge.net (Joe Block) Date: Thu, 21 Aug 2003 02:39:25 GMT Subject: What's better about Ruby than Python? References: <3F41505F.69D18CC8@alcyone.com> <66d7kvonvb2n0nqbqahhd5roak7ur81sob@4ax.com> Message-ID: In article , "Andrew Dalke" wrote: > Alex: > > Similarly, you do not tend to see in the > > Linux community people who are convinced with sufficiently high > > intensity that case sensitivity in a filesystem is idiocy (I do believe > > that, but not intensely enough to drop Linux's other advantages:-). > > And fewer who accept, much less understand, Jef Raskin's views > against a hierarchical file system at all. LEAP-LEAP! > > > To put it another way: I _DO_ have a different viewpoint from the > > majority of Python users regarding case sensitivity -- I think it's > > a wart in the language. > > While I agree that the file system should be case insensitive but > case preserving (making internationalization all that more fun), > I confess to being fond of the > > atom = Atom() > > idiom. I know it breaks down, eg, for a function which returns > a newly created class, but it's too ingrained in me. I happen to like for a in A: foo when processing lists of objects as well as your above example. jpb From achalk at XXXmagnacartasoftware.com Sun Aug 3 15:58:39 2003 From: achalk at XXXmagnacartasoftware.com (Andrew Chalk) Date: Sun, 03 Aug 2003 19:58:39 GMT Subject: Passing a string argument by reference Message-ID: I am a raw beginner to Python. I just read in "Learning Python" that assigning to a string argument inside a function does not change the string in the caller. I want an assignment in the function to alter the passed string in the caller. Is there any way to do this? For example def SafeAdd(self, Variable, Value): if self.form.has_key( Value ): Variable = self.form[Value].value Called with: self.SafeAdd(self.txtCIF, 'txtCIF') self.CIF is not changed on return from the function. How do I modify this so that it is? Many thanks From vze4rx4y at verizon.net Thu Aug 21 08:18:15 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Thu, 21 Aug 2003 12:18:15 GMT Subject: csv documentation error? (was Re: csv - howto specify fmtparam parameters) References: <3F44955C.3020206@igpm.rwth-aachen.de> Message-ID: "Peter Otten" <__peter__ at web.de> wrote in message news:bi26pd$dug$07$1 at news.t-online.com... > Helmut Jarausch wrote: > > > still I am curious: is the documentation in error? > > Taken directly from csv.py: > > class DictReader: > def __init__(self, f, fieldnames, restkey=None, restval=None, > dialect="excel", *args): > self.fieldnames = fieldnames # list of keys for the dict > self.restkey = restkey # key to catch long rows > self.restval = restval # default value for short rows > self.reader = reader(f, dialect, *args) > > As there is no provision for keyword arguments in DictReader.__init__() as > opposed to reader, it seems to be a bug that can be easily fixed: > > class DictReader: > def __init__(self, f, fieldnames, restkey=None, restval=None, > dialect="excel", *args, **kwd): > self.fieldnames = fieldnames # list of keys for the dict > self.restkey = restkey # key to catch long rows > self.restval = restval # default value for short rows > self.reader = reader(f, dialect, *args, **kwd) Please file a bug report so this doesn't get lost. Raymond Hettinger From peter at engcorp.com Wed Aug 27 15:47:34 2003 From: peter at engcorp.com (Peter Hansen) Date: Wed, 27 Aug 2003 15:47:34 -0400 Subject: learning to program References: <3F4CED6E.D04D35D6@engcorp.com> <5bspkv87u1q0v9aupajrrkjuutuh3f5o44@4ax.com> <3F4CF363.CAF6A14E@engcorp.com> <6b2qkv4nf549o8clg3bagphd02f92dadub@4ax.com> Message-ID: <3F4D0AD6.1CE798D2@engcorp.com> Rich wrote: > > On Wed, 27 Aug 2003 14:07:31 -0400, Peter Hansen > wrote: > > >Rich wrote: > >> > >> This is the only post I am able to see, sorry about re posting. I > >> thought if I changed the subject heading I might be able to see the > >> post. > > > >You should be able to see the replies that you missed via Google Groups, > >as soon as they are indexed and on the web: > How long does it usually take to post on Google? In my experience, usually quite a few hours (maybe four or more?). Right now I can see posts there which I read only a short time before seeing yours, so that estimate feels about right. (By the way, it would be helpful if, when you quote material in a post to which you're replying, if you used whitespace to separate your own text from the quoted material. I almost didn't see your message at all, thinking you'd accidentally posted an empty reply. Thanks. :- c ) -Peter From max at alcyone.com Thu Aug 14 02:00:39 2003 From: max at alcyone.com (Erik Max Francis) Date: Wed, 13 Aug 2003 23:00:39 -0700 Subject: system call in python References: Message-ID: <3F3B2587.59FEF5A8@alcyone.com> Catherine Yang wrote: > A question about how to execute a system command from python program. > e.g. > in a python script, I need to run another program written in C++, and > after > that come back to the same python program. > > Is it the system module, and which function do I use to do this? os.system, or os.popen, or one of the popen.popen... functions if you want to collect the output or feed it input. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ Laughter is the only genuine form of applause. \__/ Camden Benares From mhammond at skippinet.com.au Tue Aug 5 19:18:13 2003 From: mhammond at skippinet.com.au (Mark Hammond) Date: Wed, 06 Aug 2003 09:18:13 +1000 Subject: True In-Reply-To: References: Message-ID: Daniel Klein wrote: > Thanks Fran?ois. I don't need to support multiple versions. I simply > changed the code from: > > true = (1 == 1) > > to > > true = 1 > > and presto, no more bug :-) For the sake of being pedantic, I believe your code still does have a bug. You bug is that you rely on the "str()" of a boolean value returning a specific string. Your code should probably check the bool and create your own string rather than relying on this behaviour remaining unchanged forever. In fact, in Python 2.4, I heard you will get this behaviour: Python 2.4a0 (#46, Jul 31 2003, 10:15:54) [MSC v.1200 32 bit (Intel)] on win32 >>> True 'Does a bear shit in the woods?' ly, Mark. From v451v at yahoo.com Mon Aug 4 20:15:09 2003 From: v451v at yahoo.com (Jorl Shefner) Date: Mon, 04 Aug 2003 20:15:09 -0400 Subject: chaco setup References: Message-ID: In article , Robin Becker wrote: > I'm having trouble building chaco from source with Python- > 2.2.3/Win2kSP4. I have Numeric 23.0 installed so assumed that it might > not work using the win32 installer so am trying to build from chaco- > 0.1.0_alpha_37.776.zip. I get a setup.py error ImportError: No module > named build_agg. Do I need to install some extra software prior to > building chaco? I recently tried to get Chaco (same version) running as well (on Mac Os X, however) and got exactly the same 'ImportError: No module named build_agg" error. It seemed to derive from 'kiva/agg/setup_agg.py'. I've seen other reports of this error in various postings, but no solutions suggested. I installed all the packages that were recommended at: http://www.scipy.org/site_content/chaco/intro Chaco has always looked promising to me, but I've never had luck getting it to work. J.S. From vze4rx4y at verizon.net Fri Aug 22 13:31:10 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Fri, 22 Aug 2003 17:31:10 GMT Subject: itertools expansion time has arrived? References: Message-ID: [Christos TZOTZIOY Georgiou] > Hi all, although more like "hi Raymond" :) Hello! > Since 2.3 is out, now, perhaps it's time to add the itertools.window, > itertools.weave (and maybe others I did not happen to read about). I > don't know if Raymond needs any help, I'd be glad to. See the patch at www.python.org/sf/756253 . Jack developed implementations for window() and roundrobin(). Upon review, I rejected window() on the basis that the C version offered no compelling advantage over the pure python version. So, we included the pure python version in the docs. Jack is still refining itertools.roundrobin(). IIRC, weave() was a merge iterator and an implementation was proposed along with a stream class: www.python.org/sf/774414 The merge iterator was rejected on the basis on not being sufficiently general purpose -- meaning that it doesn't seem to be a basic building block for iterator algebra. Also, that specific implementation did not allow for a custom sort order. The stream class is the start of a good idea. Over time, I expect that it will evolve into a general purpose lazy list object that is directly substitutable for real lists but has an underlying iterator that supplies data on a just in time basis. Much experimentation is needed because there are thorny issues: * is it safe to implement a len() method knowing that users may have potentially infinite underlying iterators? * likewise, how would you handle: s[:-3] * does the implementation respond correctly to a series of appends, inserts, and deletes? to do that, it must be able to keep a running tab of all of the changes or will have to run the underlying iterator and throw away the advantages of just-in-time data production. * will memory utilization be surprising when the stream object usually consumes no memory and then a seemingly innocuous query causes much of the data to be loaded into an internal list? * does it new class play nicely with the other itertools? more specifically, is it easy to compose new functions by combining the new class with the existing tools? my early experiments indicate that they don't combine well. * the promise (holy grail?) of the new class is to provide a basis for creating new generators using Haskell like self-reference to the stream being created. Unfortunately, the ideas presented to date are not sufficiently powerful to express something like this: fib = 1 : 1 : [ a+b | (a,b) <- zip fib (tail fib) ] Such a construct would have been especially nice for expressing the proposed window() function. One other itertools proposal was a function that consumes the underlying iterator and returns nothing. Functional folks will hate this because it is all about programming with side-effects: itertools.consume(mydict.__setitem__, keygen(), valuegen()) --> None Speed freaks will like it because it is a for-loop that doesn't need to loop through the byte code evaluation cycle on each pass. I'm keeping an open mind on all these ideas. From the feedback so far, users are excited about and like the toolset. However, combining the tools requires some mental effort and that effort gets much has when even a single additional tool is added. So, I'm trying to keep it small. Also, python's generators have excellent performance and make it trivially easy to make your own custom new itertools if the need arises. As a result, I feel very little pressure to add new tools. Whenever someone proposes a new, general purpose combination of the tools, I have added it to the examples in the docs. Reading those examples will rapidly increase one's sophistication in using the toolset. Raymond Hettinger From duncan at NOSPAMrcp.co.uk Tue Aug 19 04:38:14 2003 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Tue, 19 Aug 2003 08:38:14 +0000 (UTC) Subject: Path Problem on W2K? References: <93f5c5e9.0308170927.6e0bdc38@posting.google.com> <3F40F62D.8B32CFBD@engcorp.com> Message-ID: Peter Hansen wrote in news:3F40F62D.8B32CFBD at engcorp.com: > Generally, for something like "Secure Shell", I find it much > easier just to write a little batch file that knows the full > path. Put these batch files in a directory called c:\bin > or c:\utils or something and add *that* to your path. Then > you can avoid excessive PATH creepage... > Alternatively create doskey macros for commands like that then you just need one file with a load of macro definitions. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From faizan at jaredweb.com Tue Aug 5 13:47:28 2003 From: faizan at jaredweb.com (Fazer) Date: 5 Aug 2003 10:47:28 -0700 Subject: Python and cron jobs. References: <7b454334.0308041023.6e688b4d@posting.google.com> Message-ID: <7b454334.0308050947.3d1d51fb@posting.google.com> Steven Taschuk wrote in message news:... > Quoth Fazer: > > I am wondering that if it is possible to add cron jobs via a web or > > shell interface? I can make Python act as a shell script and be > > called by a PHP script. But my main goal here is to be able to manage > > cronjobs. Add or remove certain crjob jobs etc... > > > > Can any kind soul shed some light on how I would accomplish this? > > The question is a bit vague, I'm afraid. > > If you just want to know how to invoke crontab(1) from a Python > script, look up os.popen() and friends in the standard library > documentation. As for getting the cron daemon to reload the > changed crontab, that's a nop in the crons I've seen; they check > for changes every minute anyway. > > If you want to know something else, please specify. Hello and thanks for your reply! Actually, I think I will open the crontab file as a file and do the changes that way because this would also involve in the deletion of some cronjobs. I just wish to know how to get the cron deamon to reload the crontab. Are you certain that it checks for changes or reloads every minute? From jepler at unpythonic.net Tue Aug 5 19:46:56 2003 From: jepler at unpythonic.net (Jeff Epler) Date: Tue, 5 Aug 2003 18:46:56 -0500 Subject: managing stdout and stderr neatly while doing parallel processing In-Reply-To: References: Message-ID: <20030805234654.GB17834@unpythonic.net> Well, the problem is that stderr messages are still going the same place as before (eg the terminal) instead of being redirected by the popen(). You could use "exec 2>&1;" (if my shell-fu doesn't fail me, anyway) at the beginning of your popen command to merge them and read both from the file returned by popen. However, even when you use the 2>&1 trick, stdio buffering can reverse the order between stdout and stderr messages: $ (exec 2>&1; python -c 'import sys; sys.stdout.write("hi there\n"); sys.stderr.write("this is the error, written second\n");') | cat this is the error, written second hi there I'm not sure what tricks to use to fix this problem, and my knowledge of how Unix works gets iffy. Getting output to be char- or line-buffered by stdio in the subprocess would seem to be the ticket, but I don't how to do this for programs that don't support it (python has 'python -u' to do it). If you set things up to run in a pty, that should get you terminal-like behavior, including the "expected" ordering of messages from a single process, but here both my Unix and Python knowledge fail me. good luck, Jeff From martin at v.loewis.de Sat Aug 2 05:28:26 2003 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 02 Aug 2003 11:28:26 +0200 Subject: Python-2.3 Installation with Tk on SuSE8.2 fails In-Reply-To: References: Message-ID: Frank Grellert wrote: > Did anyone succeed in configuring Python-2.3 with Tk on SuSe 8.2? It works fine for me. Can you please report the full set of error messages, beginning with the "gcc" invocation? Could it be that you don't have the Tcl header files installed? Regards, Martin From vanevery at 3DProgrammer.com Tue Aug 12 15:07:44 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Tue, 12 Aug 2003 12:07:44 -0700 Subject: Python vs. C# References: <3f357a9b@shknews01> Message-ID: Y2KYZFR1 wrote: > "Brandon J. Van Every" wrote in message > >> Some open source projects are trying to clone .NET and provide a C# >> compiler. > > again with the misconseptions, not a compiler but a runtime > interpreter. Sounds like a pedantry battle to me. JIT compiler. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From code at joecheng.com Tue Aug 12 01:44:45 2003 From: code at joecheng.com (Joe Cheng) Date: Tue, 12 Aug 2003 05:44:45 GMT Subject: Is Python your only programming language? Message-ID: I'm curious about something... many Artima.com members who have a Java background and learned Python have come to the conclusion that Java and Python are highly complimentary languages. They would never consider filling the place Java has in their toolbox with Python, but recognize there are many tasks where it really pays to add Python to the mix. I want to ask you hard-core c.l.p Pythonistas: Do you use Python for everything? (and I'm counting Python + C extensions as just Python) Or do you keep another language equally close at hand, and if so, what is it? And finally, do you foresee a day when Python can be, for all practical intents and purposes, your only programming language? From jjl at pobox.com Sat Aug 2 09:38:06 2003 From: jjl at pobox.com (John J. Lee) Date: 02 Aug 2003 14:38:06 +0100 Subject: Python 2.3 IDLE doesn't show on Win2000 References: Message-ID: <87adasyybl.fsf@pobox.com> "Andy C" writes: > I have this same problem at work, but at home it works fine. Python 2.2's > IDLE works fine on both machines. It's only 2.3 at work. I saw a web page > that says that IDLE uses 127.0.0.1 or something now for new processes and > that interferes with some firewalls, but the firewall has to be on the > machine? Yes. Since 127.0.0.1 never reaches the internet (or *anywhere* but your local machine), the firewall clearly has to be on the local machine to cause trouble. > I don't remember the details -- it's on the Python website > somewhere under "Known Bugs". Oh well, I dunno what to do about it. I'm [...] Configure your firewall correctly, or wait for 2.3.1. John From electricity at uymail.com Wed Aug 27 12:48:20 2003 From: electricity at uymail.com (U. N. Owen) Date: Wed, 27 Aug 2003 18:48:20 +0200 Subject: newbie Message-ID: <20030827164820.28326.qmail@uymail.com> First of all, install Python ;-) Let's rewrite some parts of the doc... Launch the interpreter, and try to load some modules: >>> import math >>> import time You may have some problems in Windows if you installed Python in a folder with spaces (like "Program Files"). >>> a=1 >>> b=1.0e-1 >>> math.sin(b) >>> str(a) >>> int('10') >>> print a The preceeding are very useful ;-) Next, you will need to write whole functions, so you need a folder to put your files (not inside the Python library !). You must add this folder to the PYTHONPATH variable. On linux, it's just another "setenv" or "export". On Mac, you need to run something like "ConfigurePythonPref" in the main Python folder, and on Windows, I can't remember; maybe you add PYTHONPATH in autoexec.bat or (another place in NT and XP). Then open your preferred text editor. A python file is similar to what is typed in the interpreter, but it's much simpler to type. To define a function : def fibonacci(n): if n<2: return n a,b=0,1 for i in range(n): a,b=b,a+b return a First note indentation is *very* important. It's the only way to distinguish "block", like in the for loop. The colon is also important. You should use space for indentation, and no tabs. You can save this new file as fib.py, in the folder you add to PYTHONPATH. Then >>> import fib >>> fib.fibonacci(10) or >>> from fib import fibonacci >>> fibonacci(10) It certainly isn't enough, but I tried to explain some points where I had some problems when I learnt... You should definitively read the documentation. I hope this helps. If you have any question, you can use jeanclaude.arbaut at free.fr. -- _______________________________________________ Get your free email from http://www.uymail.com Powered by Outblaze From kern at taliesen.caltech.edu Sun Aug 24 22:52:54 2003 From: kern at taliesen.caltech.edu (Robert Kern) Date: Mon, 25 Aug 2003 02:52:54 +0000 (UTC) Subject: python gripes survey References: <7s6gkv031b940dsc522pbh5g30q4nj5vd1@4ax.com> Message-ID: In article , pruebauno at latinmail.com (nnes) writes: [snip] > I have never understood why python has [].count() or "".count() but > len([]) and len(""). > > Why not make len, sum, str, repr, etc just methods of the base object > class with specific implementations for different types. Instead of > doing len([]) we could do [].len(). Like John said, "mostly history." This is in the General FAQ, question 4.6, in fact. http://tinyurl.com/l2gw """4.6 Why does Python use methods for some functionality (e.g. list.index()) but functions for other (e.g. len(list))? The major reason is history. Functions were used for those operations that were generic for a group of types and which were intended to work even for objects that didn't have methods at all (e.g. tuples). It is also convenient to have a function that can readily be applied to an amorphous collection of objects when you use the functional features of Python (map(), apply() et al). In fact, implementing len(), max(), min() as a built-in function is actually less code than implementing them as methods for each type. One can quibble about individual cases but it's a part of Python, and it's too late to make such fundamental changes now. The functions have to remain to avoid massive code breakage. Note that for string operations Python has moved from external functions (the string module) to methods. However, len() is still a function. """ > This is actually possible already in part. I think you can do > [].__len__(). But I never understood the reasoning behind making these > special __x__() methods instead of doing a plain x() and using it like > obj.x(). I think one of the benefits is that it promotes generic programming. If I'm designing a class which acts like a sequence or collection, the canonical way for me to expose the length or size of the object is to define a __len__ method. If I'm using someone else's class which acts like a collection, I know that I can almost certainly call len(obj) and get the length. I don't have to remember if they called it .len(), .length(), .getLength(), .size(), .cardinality(), .length (as an attribute or property), .numKeys(), etc. And each one of those would be used somewhere (exclusively) even if all of the builtins used only .len(). > The only case I can think of, where it would look kind of odd would be > floating points like: > > niceoutput=2.3.str() Actually it works fine for floats. Try it in the interpreter (using __str__ or one of the other magic method, though). Plain ints, on the other hand, are problematic. > Anyway since Pythonistas are smart, it can not be a wart of the > language and must be some lack in my understanding :) > > awaiting-to-be-enlightened-yours In fine Zen koan tradition, consider yourself whacked on the head with a large stick. :-) > Nestor -- Robert Kern kern at caltech.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter From mcherm at mcherm.com Thu Aug 7 07:45:30 2003 From: mcherm at mcherm.com (Michael Chermside) Date: Thu, 7 Aug 2003 04:45:30 -0700 Subject: Sick problem with Python properties Message-ID: <1060256730.3f323bda5b077@mcherm.com> aj writes: > See the following code. I wonder why in this case neither > setp() nor getp() is called !? [... code ...] > pp = property(getp, setp) [... more code ...] > inst.p = 9 > print inst.p Because you named it "pp", but then tried using "p" instead. -- Michael Chermside From m.bless at gmx.de Fri Aug 1 06:32:06 2003 From: m.bless at gmx.de (Martin Bless) Date: Fri, 01 Aug 2003 12:32:06 +0200 Subject: Detect PythonWin? References: <3f29fe44.104328@news.muenster.de> Message-ID: [Andrew Dalke]: >To see if you're on Windows, [...] >To see if the win32 extensions are installed Ok, but how can my script know it its running from inside PythonWin? I often have the situation that while developing with PythonWin I have to insert code like if 1 and "developing in PythonWin": sys.argv[1:] = ['fake', 'arguments'] Later on or when running the same script from the commandline I need to disable this if statement. Nasty. I'm looking for a predicate functions that will let my script know if it's running from inside PythonWin. And the function shouldn't use much time or resources if we are not in PythonWin. Anybody knows? Martin From skip at pobox.com Mon Aug 25 09:41:06 2003 From: skip at pobox.com (Skip Montanaro) Date: Mon, 25 Aug 2003 08:41:06 -0500 Subject: Script to remove SoBig/F virus from POP3 mailbox In-Reply-To: References: Message-ID: <16202.4594.543022.826837@montanaro.dyndns.org> Alex> Under the gun, I've written a Python script to delete emails Alex> containing this latest virus/worm (Sobig-F) from a POP3 mailbox. >> I wrote something similar today for scrubbing Mailman 2.1 pending >> administrative requests. Alex> Heck, why not post? "When in doubt, ship it out." :) It's available as http://manatee.mojam.com/~skip/python/mmdiscard.py Alex> Actually, my script was small enough to simply include in the Alex> newsgroup posting. Mine too. I just wasn't sure if that was the right way to do things in a Mailman environment. Clearly, if you have direct access to the machine there are going to be faster ways to clear the backlog. Skip From ta-meyer at ihug.co.nz Mon Aug 25 22:16:50 2003 From: ta-meyer at ihug.co.nz (Tony Meyer) Date: Tue, 26 Aug 2003 14:16:50 +1200 Subject: Advice to a Junior in High School? In-Reply-To: <1ED4ECF91CDED24C8D012BCF2B034F1303063EF2@its-xchg4.massey.ac.nz> Message-ID: <1ED4ECF91CDED24C8D012BCF2B034F130212AD44@its-xchg4.massey.ac.nz> [Sean Ross] > But, most importantly, take what interests you! This is the only rule to follow, whatever you want to end up doing at the end (plus the corollaries "take the prerequisites for what interests you", and "take whatever you are forced to by the administration"), computer science, business, arts, whatever. If you don't do that, then you end up either with poor marks (no matter how smart you are) or hating studying. The corresponding rule, of course, is to only apply for jobs that interest you. This should mean that if you've followed the above, you have all the qualifications you need (as well as some others, hopefully). Just my opinion, but based on many years of study as well as observing my students. =Tony Meyer From adalke at mindspring.com Wed Aug 20 14:59:30 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Wed, 20 Aug 2003 18:59:30 GMT Subject: Python should try to displace Java References: <3f3e89f3$0$225$626a54ce@news.free.fr> Message-ID: Alex Martelli and Doug Tolton, on 'scripting' vs. 'systems' languages: Doug > > I'm using System in the generic sense rather than the specific sense > > of Operating System. Alex: > Yep, same here. Although in the expression "system programming" > it IS more often than not an _Operating_ system that is meant. The original article I know of which tried to pin down the differences between the two approaches, at least in the context of modern languages, is Ousterhout's essay at http://home.pacbell.net/ouster/scripting.html By its definitions, Python is a system language: Scripting languages aren't intended for writing applications from scratch; they are intended primarily for plugging together components. scripting languages tend to be typeless: all things look and behave the same so that they are interchangeable. Scripting languages are often string-oriented, since this provides a uniform representation for many different things. Another key difference between scripting languages and system programming languages is that scripting languages are usually interpreted whereas system programming languages are usually compiled. (Python is byte compiled on the fly, but so is Tcl. And most Java implementations.) Scripting languages represent a different set of tradeoffs than system programming languages. They give up execution speed and strength of typing relative to system programming languages but provide significantly higher programmer productivity and software reuse. I no longer see his essay as interesting. I bring it up to point out the scripting vs. system language debate is based on nebulous grounds because there are many, many divergent interpretations of what those two terms mean. Alex: > as well as a source of income;-). But note that the firm does NOT > advertise the role of Python in their systems: "all rock-solid C++" > is the message marketing wants to keep sending What's wrong with that? It's just using a C library. ;) Andrew dalke at dalkescientific.com From graham at rockcons.co.uk Thu Aug 7 08:15:08 2003 From: graham at rockcons.co.uk (Graham Nicholls) Date: Thu, 07 Aug 2003 13:15:08 +0100 Subject: Need to convert an arbitrary byte-pair to an int. References: <3f323dc2$0$10775$afc38c87@auth.uk.news.easynet.net> Message-ID: <3f3242cc$0$18275$afc38c87@auth.uk.news.easynet.net> Richard Brodie wrote: > > "Graham Nicholls" wrote in message > news:3f323dc2$0$10775$afc38c87 at auth.uk.news.easynet.net... > >> I'm trying to size a jpeg file. The file size is held in a short (2 byte >> integer) at a certain offset. Once I've found these two bytes (they're >> in MSB,LSB order), I need to convert them to an integer - now I know that >> in C I'd just cast a pointer to the offset to a short, and that python >> doesn't >> cast, so how can I extract the value from a stream of bytes. I've looked >> at python.org/Doc/current (I'm using 2.3b1), but can't find anything >> obvious. > > For rolling your own direct handling of byte streams, the struct module is > often best. You also might want to look at the Python Imaging Library > http://www.pythonware.com/products/pil/ Thanks - that looks to be exactly what I need. -- Graham Nicholls Rock Computer Consultancy From joshway_without_spam at myway.com Tue Aug 26 15:13:42 2003 From: joshway_without_spam at myway.com (Josh) Date: Tue, 26 Aug 2003 19:13:42 +0000 (UTC) Subject: Advice to a Junior in High School? References: Message-ID: Howard Nease wrote: ... > Does anyone have any advice for me and my future? What should I study in > college? Will the market for jobs get better? Do I have any hope at all of > finding a decent-paying job in compsci? What languages do you suggest that I > study (I'm already studying Python)? I'd suggest C++, because it's complex and hideous, and you'll probably be dealing with complex hideous things in the software industry--so it's best to start early. From phil at riverbankcomputing.co.uk Sun Aug 17 15:05:02 2003 From: phil at riverbankcomputing.co.uk (Phil Thompson) Date: Sun, 17 Aug 2003 20:05:02 +0100 Subject: ANN: PyQt v3.8 Released Message-ID: <200308172005.02987.phil@riverbankcomputing.co.uk> PyQt v3.8 has been released and can be downloaded from http://www.riverbankcomputing.co.uk/pyqt/ Highlights of this release include the addition of many operators to existing classes and full support for Qt v3.2.0. PyQt is a comprehensive set of Python bindings for Trolltech's Qt GUI toolkit. It includes approximately 300 classes and 5,750 methods including OpenGL, SQL and XML support as well as a rich set of GUI widgets. It also includes a utility to generate Python code from Qt Designer, Qt's GUI builder. PyQt runs on UNIX/Linux, Windows and the Sharp Zaurus. PyQt is licensed under the GPL, commercial, educational and non-commercial licenses. Phil From eltronic at juno.com Sun Aug 10 15:38:46 2003 From: eltronic at juno.com (eltronic at juno.com) Date: Sun, 10 Aug 2003 15:38:46 -0400 Subject: Python vs. C# Message-ID: <20030810.153849.-295053.0.eltronic@juno.com> On Sat, 9 Aug 2003 21:08:16 -0700 "Brandon J. Van Every" writes: > > Can't respond to any of your other points, I haven't a clue, this reminds me of that phrase I wont attribute properly nor remember exactly but, "one definition of insanity is asking the same question and expecting a different answer." another definition is responding to the same poster and expecting them to suddenly see the light, in spite of the relative ease and speed improvements since v2.2 when we first entered this void. bug fixes aside, the arguments then were convincing to use as much python as humanly possible and reap the benefits in time saved. even if you would then take the prototype and convert into (c,c++,c#,lisp,*), which you will almost never have to do. unless you first optimize then design then reject before profile. normally one designs and tests, maybe profile to reveal slow parts. easily calling a wrapped 3rd party lib or optomizing. the google and ASPN c.l.p archive is a valuable resource for posters and responders alike. if only they could be automatically consulted and a summary appended to each email. we would not be disappointed in this case to notice past attempts by some of the c.l.p luminaries who are now avoiding this subject or have killfiled early on the quite brite dare I say the word, '3D troll'. C hasn't changed that much and python is only getting tighter. admit it, you now love python, psyco, pyrex & indentation. and you lurk in the hope of convincing yourself of the facts. apology to anyone truly wanting C# or .NET integration. is it any surprize that it will be difficult or impossible? huge gratitude to those working on the corner cases in antique languages and environments to make python less constricting. ________________________________________________________________ The best thing to hit the internet in years - Juno SpeedBand! Surf the web up to FIVE TIMES FASTER! Only $14.95/ month - visit www.juno.com to sign up today! From bsprajc at pacbell.net Sun Aug 3 01:19:43 2003 From: bsprajc at pacbell.net (Barry Sprajc) Date: Sun, 03 Aug 2003 05:19:43 GMT Subject: Can't get dumb webcounter working References: Message-ID: Tyler's correct. You'll want to check with those hosting your web site, they usually have particular directories in your home directory where you'll put your scripts, etc... Then, you just need to put the correct HTML code in your document. /barry sprajc "J. W. McCall" wrote in message news:SU%Wa.148398$xg5.51882 at twister.austin.rr.com... > Sorry if this is OT, but here's my question: > > I wrote a simple python script to increment a counter in a text file, > and I wanted this script to be accessed whenever an HTML file is > accessed. The HTML files and python script are on a shell account on > UNIX a machine that has support for CGI, Python, etc. I unfortunately > don't know much about CGI, since I assume this is what I need to get > this to work. All I want to do is to get script to be called when the > web site is accessed and hopefully insert some output (a number) into > the HTML. > > Any advice, specific instructions, pointers to helpful web resources, or > recommendations to better newsgroups, if this is too OT here, would be > greatly appreciated. > > Thanks, > > J. W. McCall > From logiplex at qwest.net Wed Aug 20 18:57:09 2003 From: logiplex at qwest.net (Cliff Wells) Date: Wed, 20 Aug 2003 15:57:09 -0700 Subject: What's better about Ruby than Python? In-Reply-To: References: <3F4040F8.87901505@alcyone.com> <6dj2kv8ugkieehs7guh786cl40o5lj6mcs@4ax.com> Message-ID: <1061420228.1506.140.camel@software1.logiplex.internal> On Wed, 2003-08-20 at 14:15, Alex Martelli wrote: > > Designing a good language is all about designing the right high level > > abstractions. Even a medium skilled designer should be able to design > > a language that maps better to their specific domain than a general > > I entirely, utterly, totally and completely disagree with this point. > > This is like saying that even a medium skilled musician should be > able to write music that plays better to their specific audience than > great music written by a genius who's never personally met any of > the people in the audience: it's just completely false. I want to > use a language designed by a genius, and I want to listen to music > written by Bach, Haendel, Mozart, and the like. I was with you until this point. Your preference for music written by geniuses only says that you are part of that audience for that type of music; it says nothing about whether Mozart would play well to the audience in a mosh pit. I don't think it invalidates your point about programming languages, it's just a bad (in fact, incorrect) example. Regards, -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 (800) 735-0555 From fredrik at pythonware.com Tue Aug 26 04:10:14 2003 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 26 Aug 2003 10:10:14 +0200 Subject: Copying a PIL image to windows clipboard? References: <10ebb92.0308211823.6fe428f7@posting.google.com> Message-ID: Gey-Hong Gweon wrote: > Is there a way to copy a PIL image to windows clipboard (as a dib > image or a bitmap, I suppose)? > > What I would like to accomplish is to do a fast copy and paste of > images from my python application to a windows application such as > powerpoint. A slower way is to use files, which is what I am doing at > the moment. as of PIL 1.1.4, you can only copy images *from* the clipboard (see the ImageGrab module). adding support for the other direction would be straightforward, but involves some C (or win32all) programming, and more round tuits than I have available right now (contributions are welcome!) From markus_wankus at hotmail.com Mon Aug 11 09:13:29 2003 From: markus_wankus at hotmail.com (Markus Wankus) Date: Mon, 11 Aug 2003 09:13:29 -0400 Subject: win32, COM, and Solidworks (again) - Still Trying References: <87he4qykqv.fsf@pobox.com> Message-ID: On 09 Aug 2003 15:21:44 +0100, John J. Lee wrote: > Markus Wankus writes: > >> On Thu, 7 Aug 2003 23:06:01 +1000 (EST), Andrew MacIntyre >> wrote: > [...] >> > If you need to go beyond the IDispatch interface, Thomas Heller's >> ctypes >> > package looks to be your only option, short of creating a full-blown >> > Pythonwin wrapper (ala Pythonwin's MAPI support) for the SolidWorks >> COM >> > API. >> > >> >> Yes, I was looking into this but was a little mystified at first. I >> generated the python wrapper and had a look inside, but was unsure of >> the extent of the Python code I was going to be required to write, as >> well as type conversions. > > He wasn't talking about the automatically-generated makepy Python > code, but rather hand-crafted C code wrapper around a particular > vtable COM interface (though Mark may have some tools to help with the > process of writing such wrappers, I don't think it's automated). > > ctypes is an easy way of doing it than writing a C wrapper. > Hmmm.. I guess I am not following. I'll go back to the ctypes page again and give it another go. Thanks, -- Markus From sybrenUSE at YOURthirdtower.imagination.com Mon Aug 25 10:04:29 2003 From: sybrenUSE at YOURthirdtower.imagination.com (Sybren Stuvel) Date: 25 Aug 2003 14:04:29 GMT Subject: Coloring print lines References: Message-ID: Sami Viitanen enlightened us with: > Is there an easy way to make script print text with differents colors to > screen (shell)? Sure, just use ANSI codes. > I mean a script that can for example print lines in red if some > error occurs in executing some information.. Example: print "\033[31;1mError:\033[0m some message" Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? From abuseonly at sgrail.org Tue Aug 26 05:44:14 2003 From: abuseonly at sgrail.org (derek / nul) Date: Tue, 26 Aug 2003 09:44:14 GMT Subject: Bug with win32 open and utf-16 file References: <27vekvc6evvn3m5jg8n1en2u42skat42qn@4ax.com> <2i1gkv0s7762vcs85rkdq6uvgk6oitje12@4ax.com> <78egkvg1tu0j1kvedclcefn01hr3vkqh4v@4ax.com> Message-ID: On Mon, 25 Aug 2003 23:06:53 -0700, Tim Roberts wrote: >derek / nul wrote: >> >>>>>> data = file("c:/dash9.eng", "rb").read() >>>>>> data[-10:] >>>'\r\x00\n\x00)\x00\r\x00\n\x00' >> >>Interesting, I have just done the same and it would appear that the hexdump >>routine is changing 0d to 0a ??? > >I cut-and-pasted your version of hexdump onto my machine, fetched your >dash9.eng file, and ran this: > > from hexdump import hexdump > f = open('dash9.eng','rb').read() > print hexdump(f) > >The output seems to be exactly correct: > >C:\tmp\x>python xxx.py|head >Dump of 32884 Bytes (type ) >$00000000 FFFE5300 49004D00 49005300 41004000 40004000 ..S.I.M.I.S.A....... >$00000014 40004000 40004000 40004000 40004A00 49004E00 ..............J.I.N. >$00000028 58003000 44003000 74005F00 5F005F00 5F005F00 X.0.D.0.t........... >$0000003C 5F000D00 0A000D00 0A005700 61006700 6F006E00 ..........W.a.g.o.n. >$00000050 20002800 20004400 61007300 68003900 0D000A00 ..(...D.a.s.h.9..... >$00000064 09006300 6F006D00 6D006500 6E007400 28004400 ..c.o.m.m.e.n.t.(.D. >$00000078 61007300 68002000 39002D00 34003400 43005700 a.s.h...9.-.4.4.C.W. >$0000008C 29000D00 0A000900 54007900 70006500 20002800 ).......T.y.p.e...(. >$000000A0 20004500 6E006700 69006E00 65002000 29000D00 ..E.n.g.i.n.e...)... > >I get the same result if I cast the string to a list. > >What version of Python are you using? #!c:/program files/python/python.exe # win32 python 2.3 Derek From mack at incise.org Sat Aug 23 05:11:48 2003 From: mack at incise.org (mackstann) Date: Sat, 23 Aug 2003 04:11:48 -0500 Subject: Reference? In-Reply-To: References: Message-ID: <20030823091148.GL1695@incise.org> On Sat, Aug 23, 2003 at 01:57:33AM -0700, Kris Caselden wrote: > I've searched all the Python docs I could find, but I haven't seen any > mention of referencing function arguments, such as you would with the > & in c/c++. Is this possible in Python? Python is pass-by-reference by default. >>> f = [] >>> def foo(n): ... n.append("hi") ... >>> foo(f) >>> print f ['hi'] -- m a c k s t a n n mack @ incise.org http://incise.org A bore is someone who persists in holding his own views after we have enlightened him with ours. From Hilbert at panka.com Sun Aug 24 14:10:31 2003 From: Hilbert at panka.com (Hilbert) Date: Sun, 24 Aug 2003 18:10:31 -0000 Subject: visual indentation References: <3F4660CB.FF72D945@easystreet.com> Message-ID: You're right, this reduces readability in python, but reflects the RIB stream better which is what I want to do. In article , Ben Finney wrote: > On Fri, 22 Aug 2003 13:06:46 -0700, Gary Herron wrote: >> Hmmmm -- I'll bet there's more possibilities. > > All of which, like all possibilities for forcing different indentation > on Python, presented so far, *reduce* readability instead of enhancing > it. > From jarausch at skynet.be Thu Aug 14 15:08:32 2003 From: jarausch at skynet.be (Helmut Jarausch) Date: Thu, 14 Aug 2003 21:08:32 +0200 Subject: Iterator - what I am missing Message-ID: <3f3bde30$0$297$ba620e4c@reader1.news.skynet.be> Hi, I cannot find out what I miss with my iterator example. I have a linked list class Queue which has a 'Head' attribute and the following def __iter__(self): if self.Head == None: raise StopIteration return self.Head The elements of the list are of class Node which has a 'NNd' (next Node) attribute and a next method def next(self): N= self.NNd if N == None: raise StopIteration return N Now when I try to iterate over all elements of the Queue like in (MyQ is an instance of class Queue) for N in MyQ: print "loop->",N print N.key,N.data I get an infinite loop and 'N' always refers to the first element of the MyQ as initialized by MyQ.__iter__ I've checked 'MyQ' and it contains 2 elements and 'NNd' attribute of the last one is 'None' So what's going on here? Many thanks for a hint, Helmut Jarausch Lehrstuhl fuer Numerische Mathematik RWTH - Aachen University D 52056 Aachen, Germany From john at rygannon.com Sun Aug 24 19:16:07 2003 From: john at rygannon.com (BadJake) Date: Sun, 24 Aug 2003 23:16:07 GMT Subject: ANN: BlackAdder V1.0.0 References: <3f48a498$3$219$fa0fcedb@lovejoy.zen.co.uk> Message-ID: <3f4946b2$0$248$fa0fcedb@lovejoy.zen.co.uk> Hi The name of the program you are looking for is PyQt And yes, using BlackAdder + PyQt you can design full applications. Qt Designer only produces a code skelton, so you have to add the feature and functionality you need. Why not download the demo and run through the tutorials Best Regards John From sross at connectmail.carleton.ca Thu Aug 7 10:45:07 2003 From: sross at connectmail.carleton.ca (Sean Ross) Date: Thu, 7 Aug 2003 10:45:07 -0400 Subject: filter()ing a dict References: <16469f07.0308070559.aed41a@posting.google.com> Message-ID: d = {"key 1": ["value 1", "value 2", "value 3", "value 4"], "key 2": ["value 1", "value 2"], "key 3": ["value2", "value 3", "value 4"], "key 4": ["value 1", "value 2", "value 3", "value 4"]} # using list comprehension fd = dict([(k,v) for k,v in d.items() if len(v)==4]) print fd # using filter value = 1 fd = dict(filter(lambda item:len(item[value])==4, d.items())) print fd From magick-users-bounces at imagemagick.org Sun Aug 31 12:36:45 2003 From: magick-users-bounces at imagemagick.org (magick-users-bounces at imagemagick.org) Date: Sun, 31 Aug 2003 09:36:45 -0700 Subject: Request to mailing list Magick-users rejected Message-ID: Your request to the Magick-users mailing list Posting of your message titled "Re: Wicked screensaver" has been rejected by the list moderator. The moderator gave the following reason for rejecting your request: "No reason given" Any questions or comments should be directed to the list administrator at: magick-users-owner at imagemagick.org From aleaxit at yahoo.com Mon Aug 18 11:43:23 2003 From: aleaxit at yahoo.com (Alex Martelli) Date: Mon, 18 Aug 2003 17:43:23 +0200 Subject: Py2.3: Feedback on Sets (fwd) References: Message-ID: Raymond Hettinger wrote: ... >> resulting iterator also has duplications. Changing the single >> statement that is currently: >> data = list(iterable) >> into >> data = Set(iterable) >> would make duplications in 'iterable' irrelevant instead. > > Good call. > Do you guys want the revised version added to the docs > or perhaps saved as an ASPN recipe? IMHO, the revised version would make most sense as a simple example in the docs -- I don't think it would be equally accessible to users if it went on the ASPN Cookbook, and it's short enough that it doesn't seem to give problems in the docs. Alex From simon_place at lineone.net Tue Aug 26 11:43:08 2003 From: simon_place at lineone.net (simon place) Date: Tue, 26 Aug 2003 16:43:08 +0100 Subject: file object, details of modes and some issues. Message-ID: <3f4b800f_3@mk-nntp-1.news.uk.worldonline.com> is the code below meant to produce rubbish?, i had expected an exception. f=file('readme.txt','w') f.write(' ') f.read() ( PythonWin 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] on win32. ) I got this while experimenting, trying to figure out the file objects modes, which on very careful reading of the documentation left me completely in the dark. Below is a summary of that experimentation, some is for reference and some is more of a warning. 'r' is (r)ead mode so you can't write to the file, you get 'IOError:(0,'Error')' if you try, which isn't a particularly helpful error description. read() reads the whole file and read(x) x-bytes, unless there are less than x bytes left, then it reads as much as possible. so a test for less than the required number of bytes indicates the end of the file, i think maybe an exception when a read at the end of the file is attempted would be better, like iterators. if you try to open a non-existent file in 'r' mode you get 'IOError: [Errno 2] No such file or directory: "filename"' which makes sense 'w' is (w)rite mode so you can't read from the file, ( any existing file is erased or a new file created, and bear in mind that anything you write to the file can't be read back directly on this object.), you get 'IOError: [Errno 9] Bad file descriptor' if you try reading, which is an awful error description. BUT this only happens at the beginning of the file? when at the end of the file, as is the case when you have just written something ( without a backward seek, see below), you don't get an exception, but lots of rubbish data ( see example at beginning.) This mode allows you to seek backward and rewrite data, but if you try a read somewhere between the first character and the end, you get a different exception 'IOError: (0, 'Error')' 'a' is (a)ppend mode, you can only add to the file, so basically write mode (with the same problems ) plus a seek to the end, obviously append doesn't erase an existing file and it also ignores file seeks, so all writes pile up at the end. tell() gives the correct location in the file after a write ( so actually always gives the length of the file.) but if you seek() you don't get an exception and tell() returns the new value but writes actually go to the end of the file, so if you use tell() to find out where writes are going, in this mode it might not always be right. 'r+' is (r)ead (+) update, which means read and write access, but don't read, without backward seeking, after a write because it will then read a lot of garbage.( the rest of the disk fragment/buffer i guess? ) 'w+' is (w)rite (+) update mode, which means read and write access, (like 'r+' but on a new or erased file). 'a+' is (a)ppend (+) update mode, which also means read and write, but file seeks are ignored, so any reads seems a bit pointless since they always read past the end of the file! returning garbage, but it does extend the file, so this garbage becomes incorporated in the file!! ( yes really ) 'b', all modes can have a 'b' appended to indicate binary mode, i think this is something of a throw-back to serial comms ( serial comms being bundled into the same handlers as files because when these things were developed, 20+ years ago, nothing better was around. ) Binary mode turns off the 'clever' handling of line ends and ( depending on use and os ) other functional characters ( tabs expanded to spaces etc ), the normal mode is already binary on windows so binary makes no difference on win32 files. But since in may do on other o.s.'s, ( or when actually using the file object for serial comms.) i think you should actually ALWAYS use the binary version of the mode, and handle the line ends etc. yourself. ( then of course you'll have to deal with the different line end types!) Bit surprised that the file object doesn't do ANY access control, multiple file objects on the same actual file can ALL write to it!! and other software can edit files opened for writing by the file object. However a write lock on a file made by other software cause a 'IOError: [Errno 13] Permission denied' when opened by python with write access. i guess you need os.access to test file locks and os.chmode to change the file locks, but i haven't gone into this, shame that there doesn't appear to be a nice simple file object subclass that does all this! Writes to the file object actually get done when flush() ( or seek() ) is called. suffice to say, i wasn't entirely impressed with the python file object, then i remembered the cross platform problems its dealing with and all the code that works ok with it, and though i'd knock up this post of my findings to try to elicit some discussion / get it improved / stop others making mistakes. From wl at flexis.de Thu Aug 21 10:16:31 2003 From: wl at flexis.de (Wolfgang) Date: Thu, 21 Aug 2003 16:16:31 +0200 Subject: C++-sig problems ? In-Reply-To: References: Message-ID: Hello, Jacek Generowicz wrote: > Has anyone else experienced problems in submitting articles to the > C++-sig? Yes, I subscribed to C++ sig today, but until now received no confirmation message. > I've tried both via Gmane, and directly via mail, without success. I read it on Gmame but since 19.08 there are no new messages. I think the main mailing list server is down or something is broken. (not with gmame, other mailinglist run without problems) I hope the problem will be solved next time. I have a problem and want to mail it to the c++ sig. bye by Wolfgang From oren-py-l at hishome.net Mon Aug 4 17:47:10 2003 From: oren-py-l at hishome.net (Oren Tirosh) Date: Mon, 4 Aug 2003 17:47:10 -0400 Subject: yEnc implementation in Python, bit slow In-Reply-To: References: Message-ID: <20030804214710.GA142@hishome.net> On Tue, Aug 05, 2003 at 12:50:58AM +1000, Freddie wrote: > Hi, > > I posted a while ago for some help with my word finder program, which is now > quite a lot faster than I could manage. Thanks to all who helped :) > > This time, I've written a basic batch binary usenet poster in Python, but > encoding the data into yEnc format is fairly slow. Is it possible to improve > the routine any, WITHOUT using non-standard libraries? I don't want to have > to rely on something strange ;) Python is pretty quick as long as you avoid loops that operate character by character. Try to use functions that operate on longer strings. Suggestions: For the (x+42)%256 build a translation table and use str.translate. To encode characters as escape sequences use str.replace or re.sub. Oren From t.evans at paradise.net.nz Sat Aug 16 07:52:04 2003 From: t.evans at paradise.net.nz (Tim Evans) Date: Sat, 16 Aug 2003 11:52:04 GMT Subject: cPickle alternative? References: Message-ID: <87r83l3jmj.fsf@cassandra.evansnet> "Michael Peuser" writes: > Hi Drochem, > > (1) Your dataset seems to break the binary cPickle mode ;-) (I tried it with > the "new Pickle" in 2.3 - same result: "EOF error" when loading back...) May > be there is someone interested in fixing this .... [snip] > > f=open ("test","w") [snip] > > f=open ("test") [snip] Note that on windows, you must open binary files using binary mode when reading and writing them, like so: f = open('test', 'wb') f = open('test', 'rb') ^^^^ If you don't do this binary data will be corrupted by the automatic conversion of '\n' to '\r\n' by win32. This is very likely what is causing the above error. -- Tim Evans From pedro.werneck at bol.com.br Sun Aug 24 09:12:10 2003 From: pedro.werneck at bol.com.br (Pedro Werneck) Date: Sun, 24 Aug 2003 13:12:10 +0000 Subject: Metaclass discussons In-Reply-To: <2259b0e2.0308240346.35319743@posting.google.com> References: <2259b0e2.0308240346.35319743@posting.google.com> Message-ID: <20030824131210.67c48e4d.pedro.werneck@bol.com.br> On 24 Aug 2003 04:46:26 -0700 mis6 at pitt.edu (Michele Simionato) wrote: > Much less hackish, but a bit non-trivial. Your idea is perfect for > easy hacks in the debugging phase (i.e. add a metaclass generating > logging capabilities or other more general debugging utilities). You > can spell it even as > > class object(object): > class __metaclass__(type): > pass > > # rest of the code Humm... but it does't propagate to imported modules # mod.py class Klass(object): pass # end --- >>> class object(object): ... class __metaclass__(type): pass ... >>> import mod >>> mod.Klass.__bases__ (,) >>> class A(object): pass ... >>> A.__bases__ (,) -- But assigning it to __builtin__.object do: >>> class metaclass(type): pass ... >>> import __builtin__ >>> __builtin__.object = metaclass("object", (), {}) >>> import mod >>> mod.Klass.__bases__ (,) >>> class A(object): pass ... >>> A.__bases__ (,) >>> Rgds Pedro From wiebke.paetzold at mplusr.de Wed Aug 13 03:51:12 2003 From: wiebke.paetzold at mplusr.de (Wiebke Pätzold) Date: Wed, 13 Aug 2003 09:51:12 +0200 Subject: union in Python References: Message-ID: Hi Andy, I'm very new in Python and this is why I ask this stupid question. I create a database that contains a table. 'Themenbereiche' is one of 13column names. This program can search for a special letter. In my example it is 'do'. and the search takes place in 'Themenbereiche'. 'do' takes place within a word. This is solved with regular expression. So that I can limit my search. For example: I can search for 'do' and it is not relevant wich letters follow or wich letters are in front of 'do'. This is the program that I wrote: import sys import Mk4py import re db = Mk4py.storage("c:\\datafile.mk",1) vw = db.view("people") class PatternFilter: def __init__(self, pattern, feld): self.feld = feld self.pattern = re.compile(pattern) def __call__(self, row): try: exec(self.feld+" = row."+self.feld) except AttributeError: return 0 return self.pattern.search(eval(self.feld))is not None feld = "Themenbereiche" vf = vw.filter(PatternFilter("do.*", feld)) for r in vf: exec("print vw[r.index]." +feld) Now I want to change my program that I can look for the same regular expression in two columns ('Themenbereiche', 'Nachname'). I tied something >> import sys >> import Mk4py >> import re >> >> db = Mk4py.storage("c:\\datafile.mk",1) >> vw = db.view("people") >> >> class PatternFilter: >> def __init__(self, pattern, feld): >> self.feld = feld >> self.pattern = re.compile(pattern) >> >> def __call__(self, row): >> try: >> exec(self.feld+" = row."+self.feld) >> except AttributeError: >> return 0 >> return self.pattern.search(eval(self.feld))is not None >> >> def union(feld_th, feld_na): >> c = feld_th[:] >> for i in range(len(feld_na)): >> if feld_na[i] not in feld_th: >> c.append(feld_na[i]) >> return c >> >> feld_th = "Themenbereiche" >> vf = vw.filter(PatternFilter("do.*", feld_th)) >> >> feld_na = "Nachname" >> vf = vw.filter(PatternFilter("im.*", feld_na)) >> >> print feld_th, feld_na, union(feld_th, feld_na) But it seems to be worng. I didn't find verx much material in order to solve the task. But I tried it. I don't get the results I except. I get actual traceback error: >>> Themenbereiche Nachname Traceback (most recent call last): File "C:\PROGRA~1\Python22\lib\site-packages\Pythonwin\pywin\framework\scriptutils.py", line 310, in RunScript exec codeObject in __main__.__dict__ File "C:\Programme\Python22\Lib\site-packages\Pythonwin\pywin\Demos\Uebung11.py", line 46, in ? print feld_th, feld_na, union(feld_th, feld_na) NameError: name 'union' is not defined >>> From clifford.wells at comcast.net Wed Aug 6 04:22:07 2003 From: clifford.wells at comcast.net (Cliff Wells) Date: Wed, 06 Aug 2003 01:22:07 -0700 Subject: wxPython and Chinese characters in Unicode? In-Reply-To: <3ct0jvgcln2df5dv9g67c7kubah07adopa@4ax.com> References: <3ct0jvgcln2df5dv9g67c7kubah07adopa@4ax.com> Message-ID: <1060158127.2581.35.camel@devilbox.homelinux.net> On Tue, 2003-08-05 at 20:30, carroll at tjc.com wrote: > Does wxPython handle Unicode strings (specifically, Unihan strings, > with Chinese characters) easily? > > I'm writing an app to help me explore the Chinese character sets, and > can do basic displays of the characters in Tkinter, but Tkinter looks > daunting as I try to grow the app beyond a simple display. wxPython > looks easier to use; but will it handle Chinese characters? You will get better responses to wxPython-related questions on the wxPython mailing list: http://www.wxpython.org/maillist.php Regards, -- Pushing the stone up the hill of failure -Swans From aleaxit at yahoo.com Mon Aug 18 08:26:05 2003 From: aleaxit at yahoo.com (Alex Martelli) Date: Mon, 18 Aug 2003 14:26:05 +0200 Subject: python based tools for developing web-based apps References: <3f40b630$0$49105$e4fe514c@news.xs4all.nl> Message-ID: Joost van Rooij wrote: > Hello, > > For business purposes I would like to develop several web based > application, > all based on the the same foundation. I looked at several options like > zope, mod_py, webware, skunkweb. > > Based on the information I found, I now basically considder two options > 1. writing a xml-rpc server in Python which provides all the logic. And a > seperate frontend in php which reads the data from the Python xml-rpc > server and presents it in nice html. (Won't this be a performance hog?) > 2. write it on top of a application server like webware or skunkweb. (Are > these projects mature enough?) I would consider Webware for Python very mature and stable, quite suitable for any kind of production-level deployment. Personally, I'm trying out CherryPy these days, and I love what I see -- but I have as yet no idea about the stability, scalability, and so on. With Webware, you're going for the most solid and proven solution. I don't see any advantage with doing the presentation in PHP -- Webware supports excellent templating (Cheetah), servlets, AND if you insist "embed Python in HTML" too, and you can mix-and-match if you need to. > 3. any other good idea, I haven't thought of.... :) Twisted -- a great solution if you have the option of deploying a self-sufficient server rather than having to run on top of Apache or the like. I think Webware is easier to program at the application level, and it gives you many more deployment options, but Twisted's performance and scalability are nothing short of amazing -- and if you need to add more and more protocols, not just HTTP, Twisted's flexibility is gonna pay for itself. Alex From mwh at python.net Tue Aug 19 06:30:10 2003 From: mwh at python.net (Michael Hudson) Date: Tue, 19 Aug 2003 10:30:10 GMT Subject: python and symbian? References: <87r83idcp7.fsf@pobox.com> Message-ID: <7h3r83iymaa.fsf@pc150.maths.bris.ac.uk> jjl at pobox.com (John J. Lee) writes: > Lawrence Oluyede writes: > > > Skip Montanaro wrote: > > > > > What's symbian? > > > > Symbian OS is the OS of new generation mobile phones made by Nokia, Sony > > Ericsson and so on > > Symbian itself is a consortium endorsed by Nokia, Siemems, Sony Ericsson > > Motorola et. al. > > > > Some of the mobile phones with Symbian OS are Nokia 3650 and Sony Ericsson > > P800 > > > > The OS ships with C++ SDK, Java and VB AFAIK > > Not Erlang? I guess they (Ericsson) only use that for the exchanges, > then. Yup, at least AIUI. Cheers, mwh -- This makes it possible to pass complex object hierarchies to a C coder who thinks computer science has made no worthwhile advancements since the invention of the pointer. -- Gordon McMillan, 30 Jul 1998 From tebeka at cs.bgu.ac.il Tue Aug 26 06:03:00 2003 From: tebeka at cs.bgu.ac.il (Miki Tebeka) Date: 26 Aug 2003 03:03:00 -0700 Subject: Comments on my "Python Introduction" slides References: <33803989.0308240000.35b9bf1f@posting.google.com> <3F49CD52.1070609@netscape.netNOTthisBIT> Message-ID: <33803989.0308260203.4c31cf18@posting.google.com> Hello Paddy, > Slide 9: The tripple quoted string has got the quotes mangled by the > editor. You might try cut & paste execution of all your examples from > the slides. OK. > General: Frames: the frames are not movable in Mozilla, (I wanted to > make the slide frame larger). This is a convertion from M$ PowerPoint. The real lecture don't have these problems. I'm considering moving to OpenOffice ... > General: Slide title 'Quick One': Could be more informative. It's a common one for all code samples. Thanks for you comments. Miki From fredrik at pythonware.com Tue Aug 19 12:15:46 2003 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 19 Aug 2003 18:15:46 +0200 Subject: What's better about Ruby than Python? References: <38ec68a6.0308181659.1aab5c67@posting.google.com> Message-ID: Jacek Generowicz wrote: > > Python's firmly in the "always half-open" field (pioneered in print, > > to the best of my knowledge, in A. Koenig's "C Traps and Pitfalls", > > I seem to recall seeing a scanned-in copy of a hand-written talk by > Dijkstra, on this. this one? "Why numbering should start at zero" http://www.cs.utexas.edu/users/EWD/ewd08xx/EWD831.PDF From zcoder at bigmir.net Tue Aug 12 17:47:17 2003 From: zcoder at bigmir.net (Vlad Sirenko) Date: 13 Aug 2003 00:47:17 +0300 Subject: How to make tree of dictionaries? Message-ID: <87fzk6tuoq.fsf@big.terem> I need: dict = {2002 : {'Jan': {1 : 'num1', 2: 'num2', 3 : 'num3'}, {'Feb': {1 : 'num4', 2: 'num5', 3 : 'num6'} } } 2003 : {'Jan': {1 : 'num7', 2: 'num8', 3 : 'num9'} } } How to do it programmatically? In Perl I would do something like: while ($line = <>) { if ($line =~ /^---\s+\w+\s+(\w+)\s+(\d*)\s+(\d+):(\d+):(\d+)\s+(\d+)\s+---$/) { ($month,$date,$hour,$minute,$sec,$year) = ($1,$2,$3,$4,$5,$6); $statistics->{$year}->{$month}->{$date} += $sec; } } But how to do it in Python without catching 'KeyError' exception or iterating over some nested loops. How to do it elegantly? -- WBR, VS From raims at dot.com Sat Aug 30 20:13:24 2003 From: raims at dot.com (Lawrence Oluyede) Date: Sun, 31 Aug 2003 02:13:24 +0200 Subject: Win32 documentation in CHM? References: Message-ID: <87r832u1jv.fsf@voodoo.fake> "Tim Peters" writes: > You cannot have used a properly constructed .chm file and seriously question > whether it's more searchable. Of course it is, including seemingly > instantaneous Boolean, proximity, wildcard, and similarity searches, across > the entire doc set with one query. I don't know of any way to search thru > more than a thousand .html files that's even arguably comparable; e.g., grep > is a slow & painful joke in comparison. Yeah, you're right, I recently switched from Win to Linux (cause I have to use Linux for job stuff) and the only thing that I really miss is something like chm compiled documentation. Now i have to use odd things like xCHM or the nicely-formatted arCHMage :(( Mmm if I don't find something more useful i try to code a serious reader by my self :) -- Lawrence "Rhymes" Oluyede http://loluyede.blogspot.com rhymes at NOSPAMmyself.com From achrist at easystreet.com Sat Aug 30 05:07:19 2003 From: achrist at easystreet.com (achrist at easystreet.com) Date: Sat, 30 Aug 2003 02:07:19 -0700 Subject: Pyhton 2.3 does not work References: <3f504a34$1@news.012.net.il> <3f505f0a@news.012.net.il> Message-ID: <3F506947.6519AEE5@easystreet.com> Avner Ben wrote: > > The culprit was SET PYTHONPATH command in the autoexec.bat file. Since I > prefer not to put my (bulky) development stuff in the Python distribution > directory, I have used this DOS command - based a long time ago upon the > then current Python documentation - to direct Python to look for import > modules in my development directories as well. This has worked fine for all > Python versions up to and including 2.2.3. But then, with Python 2.3, it > turns out to destroy the contents of sys.path, apparently leading the dll > loader astray. > If a target machine happens to have such a PYTHONPATH setting, will this disrupt the operation of *.exe files built with py2exe or the McMillan installer? Al From peterm at resmed.com.au Wed Aug 27 16:42:22 2003 From: peterm at resmed.com.au (Peter Milliken) Date: Thu, 28 Aug 2003 06:42:22 +1000 Subject: My future Python IDE article References: <87smno1bfh.fsf@vercingetorix.caesar.org> <%yP2b.284$rC1.12766@nnrp1.ozemail.com.au> <87oeycrtvz.fsf@voodoo.fake> Message-ID: Hi Lawrence, I am the author of ELSE (one of the reasons I like using it with Emacs :-)). You can find it at http://www.zipworld.com.au/~peterm (along with templates for other languages). There is an extensive users guide at the site (but since most people don't like documentation I would suggest that you browse the section on Installation, the section on "Default Keybindings" and have a look at the Tutorial section on using ELSE - these three sections that should get you up an going) If you need any assistance just drop me an email, I am more than happy to provide support etc. Peter "Lawrence Oluyede" wrote in message news:87oeycrtvz.fsf at voodoo.fake... > "Peter Milliken" writes: > > > I use the same Emacs configuration with the addition of ELSE (with the > > python code templates for easy code input) and PyMacs (for extending Emacs > > using Python). > > Cool! How does ELSE works? How could i setup Emacs to use it easily? > > PyMacs? Wow :) I'll check it out tomorrow > > -- > Lawrence "Rhymes" Oluyede > http://loluyede.blogspot.com > rhymes at NOSPAMmyself.com From bkc at murkworks.com Thu Aug 14 14:10:09 2003 From: bkc at murkworks.com (Brad Clements) Date: Thu, 14 Aug 2003 14:10:09 -0400 Subject: py2exe service and tool-tray app combined? In-Reply-To: <1xvop3ad.fsf@python.net> References: <3F3A8371.840.20CD3615@localhost> (Brad Clements's message of "Wed, 13 Aug 2003 18:29:40 -0400") Message-ID: <3F3B981A.21451.2505FB7F@localhost> On 14 Aug 2003 at 19:17, Thomas Heller wrote: > In the long run, this will be the wrong forum. I suggest > comp.lang.python (or should a py2exe mailing list be created?). > And I'm cc'ing to python-list. I think a py2exe specific mailing list would be best. You could probably just use one on SF like venster does. > > It's not clear from the project page what gets executed when the > > service .exe is run without -debug or -register. > > Well, you can try it out. But IIRC, nothing useful will happen. The > service tries to start, but cannot because it cannot connect to the > service manager (or something like that). I hvaen't looked at the source yet, but perhaps it would be enough to 'emulate' win32serviceutil.HandleCommandLine like pythonservice.exe does. This way, a person could create a service using pythonservice.exe, and then package with py2exe without changing the code at all. And, in my case I could parse the command line before calling win32serviceutil.HandleCommandLine and do something different, like showing a tooltray app or something instead. > But I'm not sure it makes sense nowadays - win98 is history. ha ha, tell the customer! > Well, I have something for you. As time permits, I'm working on a new > py2exe using the zipimport of Python 2.3. Still very much work in > progress, and services are not yet supported, but it's already in CVS in a > sandbox subdirectory. That sounds good. So then all we'd need is changes to the packaging mechanism to group 'specified packages' into their own zip file external to the .exe, specify the order in which these .zip files get placed into sys.path, and have the .exe do this path munging when it starts. > Now, isn't this '.bnd' file mechanism also a nice idea for py2exe? Sure, its all nice, but maybe a bit overkill. Supports we just had 0 or more 'external' import zips stuck into sys.path in an order we desired. I'm assuming that packages have to completely fit into a single .zip. So upgrading would require putting the entire contents of the 'updated' package into a new .zip file that goes into the path before the old .zip In my use cases, I only need one (maybe 2) external .zips and I'd just upgrade the entire .zip in one shot. These will always be much smaller than python23.zip anyway. -- Brad Clements, bkc at murkworks.com (315)268-1000 http://www.murkworks.com (315)268-9812 Fax http://www.wecanstopspam.org/ AOL-IM: BKClements From clifford.wells at comcast.net Mon Aug 4 02:24:58 2003 From: clifford.wells at comcast.net (Cliff Wells) Date: 03 Aug 2003 23:24:58 -0700 Subject: wxPython: Default Frame button? In-Reply-To: <33803989.0308030211.10b31e97@posting.google.com> References: <33803989.0308030211.10b31e97@posting.google.com> Message-ID: <1059978298.13637.21.camel@devilbox.homelinux.net> On Sun, 2003-08-03 at 03:11, Miki Tebeka wrote: > Hello All, > > I have a frame that contains a panel and several buttons. > I'd like to make one of the button the default button but > self.SetDefaultItem(btn) or btn.SetFocus() don't work. The item in > focus is a text control inside the panel. > > Any Ideas? (see short example below) In general, the only child of a frame should be a panel or some other container (like a splitter). Frames should generally only have one child. Make the button a child of the panel rather than a sibling. Here's your code, hacked up a bit: import wx class P(wx.Panel): def __init__(self, parent, id = -1): wx.Panel.__init__(self, parent, id) sizer = wx.BoxSizer(wx.VERTICAL) b = wx.Button(self, -1, "Quit") wx.EVT_BUTTON(self, b.GetId(), parent.on_quit) sizer.AddMany([ (wx.TextCtrl(self, -1, size = (250, -1), value = "XXX")), (b, 0, wx.EXPAND), ]) self.SetDefaultItem(b) b.SetFocus() self.SetAutoLayout(True) self.SetSizer(sizer) sizer.Fit(self) class F(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, -1, "Test Frame") panel = P(self) self.Fit() def on_quit(self, e): self.Close(True) def main(): app = wx.PySimpleApp() f = F() f.Show(True) app.MainLoop() if __name__ == "__main__": main() Regards, Cliff -- With your cold flesh, my cold love, hissing not kissing -Siouxsie and the Banshees From gherron at islandtraining.com Fri Aug 22 15:44:03 2003 From: gherron at islandtraining.com (Gary Herron) Date: Fri, 22 Aug 2003 12:44:03 -0700 Subject: visual indentation In-Reply-To: <3F4660CB.FF72D945@easystreet.com> References: <3F4660CB.FF72D945@easystreet.com> Message-ID: <200308221244.03792.gherron@islandtraining.com> On Friday 22 August 2003 11:28 am, achrist at easystreet.com wrote: > Hilbert wrote: > > Hello, > > > > I'm using python to output RIB streams for Renderman. > > The RIB stream is a bunch of statements which describes > > a 3d image. The Rib standard allows for blocks which we > > usually indent for better visualization for example: > > > > WorldBegin > > Color [1 1 1] > > Surface "constant" > > Sphere(1.0, -1.0, 1.0, 360) > > WorldEnd > > > > I'm using CGKit in python which has a Renderman binding, > > so to output the same RIB I'd write: > > > > RiWorldBegin() > > RiColor(1.0,1.0,1.0) > > RiSurface('constant') > > RiSphere(1.0,-1.0,1.0,360) > > RiWorldEnd() > > > > But I get an error, because python interprets my indentation > > as a block in the python code. So the only way to write this > > is without the indentation: > > > > RiWorldBegin() > > RiColor(1.0,1.0,1.0) > > RiSurface('constant') > > RiSphere(1.0,-1.0,1.0,360) > > RiWorldEnd() > > > > But this is a lot harder to read. > > > > Is there any way to use such "visual" indentation in python? > > If the code is purely sequential, how about something like this: > > import string > def RunTheseStatements(s): > stmts = map(string.strip, s.split("\n")) > for stmt in stmts: > eval(stmt) > > RunTheseStatements(""" > > > RiWorldBegin() > RiColor(1.0,1.0,1.0) > RiSurface('constant') > RiSphere(1.0,-1.0,1.0,360) > RiWorldEnd() > > > """) Here's another way -- inside a [..] or (...) construct [ RiWorldBegin(), RiColor(1.0,1.0,1.0), RiSurface('constant'), RiSphere(1.0,-1.0,1.0,360), RiWorldEnd(), ] Or try this (this might be too ugly) RiWorldBegin() if 1: RiColor(1.0,1.0,1.0) RiSurface('constant') RiSphere(1.0,-1.0,1.0,360) RiWorldEnd() or make these all member functions of a class and try c. RiWorldBegin(), c. RiColor(1.0,1.0,1.0), c. RiSurface('constant'), c. RiSphere(1.0,-1.0,1.0,360), c. RiWorldEnd(), or Hmmmm -- I'll bet there's more possibilities. Gary Herron From vanevery at 3DProgrammer.com Mon Aug 18 18:09:44 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Mon, 18 Aug 2003 15:09:44 -0700 Subject: What's better about Ruby than Python? References: <2qc2kvsti2r6vfpr3tt9468go9qjf0sape@4ax.com> Message-ID: Doug Tolton wrote: > > Clearly you are interested in people's philosophical take on why you > should've posted to the Ruby boards, because you take the time to > respond to each and every criticism. I actually can't remember that I've deliberately done that. I expect I probably haven't. At any rate, I do always take the time to let people know that I'm putting them in my killfile. Such as yourself. You haven't said anything awful, but you also went out of your way to make an otherwise content-free post at my expense. Of what use is that to me? Eventually, I'll whittle this group down to people who can take a simple, rational question at face value, provide the needed info, and be done with it. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From aleax at aleax.it Mon Aug 4 05:06:40 2003 From: aleax at aleax.it (Alex Martelli) Date: Mon, 04 Aug 2003 09:06:40 GMT Subject: Determining if a filename is greater than X characters References: <93f5c5e9.0308021815.44c57a2d@posting.google.com> <3f2cfea8$0$49106$e4fe514c@news.xs4all.nl> <3F2D6A90.1040203@vt.edu> <3F2D81A9.70404@vt.edu> Message-ID: hokiegal99 wrote: > OK, I'll use spaces... I thought tabs akward, but they take less time in > my editor than spaces do. Thanks for the for loop idea. It works > perfectly. Below is the script with spaces instead of tabs. Thanks > again!!! You're welcome! Note that good editors can be configured so as to let you hit the Tab keys for indentation (and shift-Tab to go back, if you wish) while using spaces in the file as saved. If your current editor does not support that I would suggest you consider changing -- there are SO many good editors out there, after all. For example, IDLE, the integrated GUI development environment that comes with Python, is quite nice now in its release 1.0 (comes with Python 2.3). The Options menu opens a multi-tab dialog open at the first tab, "Fonts/Tabs", and you'll see a simple choice between "Tab key inserts spaces" (default) and an alternative of "Tab key inserts tabs". Even though I normally use VIM myself (a highly configurable & programmable descendant of good old vi) and occasionally SciTE (a useful lightweight editor/environment), I'm seriously tempted by the new IDLE 1.0 to switch for much of my work... Alex From jjl at pobox.com Mon Aug 18 14:14:49 2003 From: jjl at pobox.com (John J. Lee) Date: 18 Aug 2003 19:14:49 +0100 Subject: ClientCookie bug (followup) References: <87fzk4sav2.fsf@pobox.com> <87znibzrnx.fsf@pobox.com> <87oeypdh92.fsf@pobox.com> Message-ID: <87k79a25pi.fsf@pobox.com> cartermark46 at ukmail.com (Mark Carter) writes: > > I'll investigate further. > > Here are the results from running tests in ClientCookie 0.4.4.a: [...] > The upshot of this is that load_cookie_data() now works in win 98 and > xp. > load_from_registry() works from win xp; it works from win 98 if and > only if you set the USERNAME environment variable. You missed the username argument. cookiejar.load_from_registry(username="mark") (should only be required for win9x family) > I appreciate that all the stuff about request2 and response2 may not > be to your liking - but at the moment I'm just trying to figure out > what works, and what doesn't. We can also worry about the delayload > business later. No really, I wasn't joking: you *never* need to use add_cookie_header / extract_cookies if you're using urllib2 (at least, I can't think of any possible reason to do so). It can only break things. > What do you think about the idea of actually setting up an Aapache web > page to test these things 'for real'? I've done limited testing on Windows with 'fake' cookies from a local Apache server, and on wine on linux. As I said, though, I don't have a networked Windows OS, so it's inconvenient to test these things in a 'real' situation. And my machine currently doesn't boot into Windows without physically switching cables around (security & obscure hardware issues, not software ones), which means I currently can't be bothered to test it on Windows :-P. So, your feedback is appreciated. John From rowen at cesmail.net Tue Aug 26 16:43:24 2003 From: rowen at cesmail.net (Russell E. Owen) Date: Tue, 26 Aug 2003 13:43:24 -0700 Subject: ftp get from a Tkinter gui: advice wanted References: <87zniar1iw.fsf@pobox.com> Message-ID: In article <87zniar1iw.fsf at pobox.com>, jjl at pobox.com (John J. Lee) wrote: >"Russell E. Owen" writes: > >> I'm writing a Tkinter app (telescope remote controller). The application >> presently runs on unix and MacOS X and I think some users will want to >> use Windows. It's going just fine, but I'm trying to add the ability to >> automatically get images via binary ftp (i.e. as each image is recorded) >> and am realizing it's harder than I though. >> >> Ideally, I'd like image download to work like a typical web browser >> download: a status window that shows each transfer, how far along it is, >> allows the user to cancel it, etc. >[...] > >Not sure what "as each image is recorded" refers to,... My application causes astronomical images to be written to disk on a remote host. My app will then initiate an ftp transfer to retrieve the "image" file on the remote host. >but if you want >to grab files via ftp, is there anything wrong with (in a separate >thread, I suppose): > >import urllib2 >urllib2.urlopen("ftp://ftp.example.com/pub/rhubarb.txt") I suspect you're right. I was hoping not to have to write the log window from scratch (especially as Tkinter has no good mult-list widget) but am plowing ahead. I'm using urllib.urlopen (urllib supports ftp with password, which I need) and have got the basics done, though am about to post a query about nonblocking read of the returned file object. Tkinter file events seem to work on the returned file and this avoids the need to use threads, so really the only significant work will be a decent GUI for viewing status and allowing transfers to be aborted. >If you don't mind pulling in more code, no doubt Twisted could do this >just as simply too, and, I imagine, wouldn't need to use a separate >thread (never used it, but I know it has support for various common >GUI event loops). Yes, the integration with various event loops is a big attraction. I may end up there, but so far have been rolling my own code to avoid relying on a 3rd party library. Thank you for your reply! -- Russell From bgailer at alum.rpi.edu Wed Aug 6 12:31:27 2003 From: bgailer at alum.rpi.edu (Bob Gailer) Date: Wed, 06 Aug 2003 10:31:27 -0600 Subject: check if running under IDLE In-Reply-To: <3F30CED2.7070609@igpm.rwth-aachen.de> References: <13a533e8.0308051237.6bfa05d3@posting.google.com> <3f2ec16b$0$285$ba620e4c@reader0.news.skynet.be> <13a533e8.0308051237.6bfa05d3@posting.google.com> Message-ID: <5.2.1.1.0.20030806103016.02b85db0@66.28.54.253> At 11:48 AM 8/6/2003 +0200, Helmut Jarausch wrote: [snip][ To check a script accessing sys.argv I have to set it. >Unfortunately the 'Run' pulldown menu of IDLE doesn't have an item >to set sys.argv as it's common with debuggers for C. > >Now in Python I can set sys.argv within the script, >but forgetting to comment this out afterwards makes the >script wrong outside of IDLE > >So I'd like to say > >if __IDLE_IS_RUNNUNG__: > sys.argv=['test','-a','/home/jarausch/BackUp'] > >but I haven't work how to check if the script is running under IDLE's >supervision. import sys __IDLE_IS_RUNNUNG__ = len(sys.modules) > 20 Bob Gailer bgailer at alum.rpi.edu 303 442 2625 -------------- next part -------------- --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.506 / Virus Database: 303 - Release Date: 8/1/2003 From aleax at aleax.it Sat Aug 30 03:46:49 2003 From: aleax at aleax.it (Alex Martelli) Date: Sat, 30 Aug 2003 07:46:49 GMT Subject: My script is taking 12 hours+ any suggestions? References: <3f4ff9f8$0$23588$5a62ac22@freenews.iinet.net.au> <3f500589$0$23595$5a62ac22@freenews.iinet.net.au> Message-ID: Ideasman wrote: > Its indenting for me- Netscape/Mozilla > > John Roth wrote: >> Your script isn't indented properly in Outlook Express, >> making it very difficult to read It's apparently using tabs and therefore does not get displayed as indented by many newsreaders, including Outlook Express and KNode. Therefore, it's nearly unreadable and it's unlikely you'll get any help from users of such newsreaders, including me. *ALWAYS* use spaces, NOT tabs, in any code you post. This is assuming that you care for the code you post to be read, as is likely the case when you're asking for help about it. Alex From raims at dot.com Fri Aug 22 04:45:18 2003 From: raims at dot.com (Lawrence Oluyede) Date: Fri, 22 Aug 2003 10:45:18 +0200 Subject: Do Java lovers are scared about the Python crowd? Message-ID: http://www.cardboard.nu/archives/000118.html I think that the guy (Alan Green) is very scared :) I read also a funny (but clever) comment to that post (the first one): " True, True. In fact, we should boycott Java, too. C is the way to go! (Or Assembler? Or just write the binary code by hand?) " -- Lawrence "Rhymes" Oluyede http://loluyede.blogspot.com rhymes at NOSPAMmyself.com From vanevery at 3DProgrammer.com Mon Aug 18 03:44:21 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Mon, 18 Aug 2003 00:44:21 -0700 Subject: 3 new slogans References: <13dc97b8.0308172102.5006b620@posting.google.com> Message-ID: Andy Bulka wrote: > I like the The Four Noble Truths of Python website > http://www.pauahtun.org/4nobletruthsofpython.html Is Perl really the enemy? I don't see Microsoft backing Perl. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From fredrik at pythonware.com Wed Aug 13 04:03:30 2003 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 13 Aug 2003 10:03:30 +0200 Subject: Summer reading list References: <5d0_a.288$jw4.85@nwrdny03.gnilink.net> Message-ID: Andrew Dalke wrote: > Summary: heapq is a concrete interface, not an abstract one. It doesn't > try to encompass the different ways to do heaps. It's like bisect in that > it works on an existing data type. more importantly, it works on *any* existing data type, as long as the type behaves like a mutable sequence. From gregbrunet at NOSPAMsempersoft.com Tue Aug 12 19:28:36 2003 From: gregbrunet at NOSPAMsempersoft.com (Greg Brunet) Date: Tue, 12 Aug 2003 18:28:36 -0500 Subject: drop down feature References: Message-ID: Hi Michael: "Michael Peuser" wrote in message news:bhbp0k$epd$07$1 at news.t-online.com... > IDLE can help with its Class Browser feature. Although this not "automatic", > it will help a lot > when using site-packages or even your own old code ;-) IDLE and many other GUI's do provide that & it is a definite help. Any class library, whether Python's or some other language, simply has to be learned. Hopefully, the designers were consistent and 'standard' in their name choices to make things easier, and certainly once you begin using a tool frequently it becomes easier. Even as good as a class browser is, I've found that the Intellisense stuff is perhaps an order of magnitude more helpful to me than the browser. Without having to manually jump to another window/pane & lookup the class I'm interested in, I have all of the properties & methods available as I finish typing the variable, AND a link to the full help on the item by pressing F1 as soon as I've selected it. > For the beginner, of course even properties (attributes and methods) of > standard types are not > obvious. I must say, that Python can really be a little bit cryptical > (consider *get* oder *has_key* for > directories ). I generally have to look it up, when *haskey* or *has* does > not work ;-) > > But you can very well organize yourself with man pages.... > > The main problem seems to be that Python has no static typing. So it > *generally* is not possible > for an editor to know what type will dynamically be used. And this is where, as disparagingly as people talk of VB, it does a good job. Because it highly encourages (though can disable) static typing & checking, it is able to know what the properties, methods, etc. are for a variable. In reading a description of the WingIDE for Python, their standard package tries to accomplish this by: "Infers class structure and variable types based on real time analysis of Python source code." I understand that Python for now & likely evermore will be dynamically typed - hopefully the editors can get smarter about performing this analysis to support the intellisense type operation. > Problems increase especially with GUIs - I would be lost even in Tkinter > without a paper reference ;-) Also agreed. And one other thing that I've never seen matched (even the 1.0 version of .NET wasn't as good) is the dynamic debugger in VB6. When I've tried to debug code in IDLE or PythonWin or Boa, I frequently end up at layers deeper in the class hierarchy than I wish to go (I usually want to break at my code, but end up in some of the debugger support code & have to navigate my way up/over to do anything). Also the VB debugger would provide mouse-over information of any variables (their value, etc.) displayed in the editor at the time the breakpoint fires, along with an unbelievable ability to edit and continue running the program. If someone could come up with an editor for Python with the capabilities of the VB6 IDE, I'd certainly pay for that one. For now, it seems that Boa is the closest thing to the mark in the open source field. I've not evaluated the commercial editors sufficiently, but from what I've read, there isn't anything out there yet that meets that criteria. > Kindly > Michael Peuser Take care, -- Greg From Smille at mail.com Mon Aug 11 19:18:55 2003 From: Smille at mail.com (Smille Purusa) Date: Mon, 11 Aug 2003 23:18:55 +0000 Subject: ???? i can`t understand it References: Message-ID: Enrique wrote: >>>> a=[1,2,3,4,5] >>>> for b in a: > ... a.remove(b) > ... >>>> a > [2, 4] >>>> Very interesting result but reasonable. If the underlying interpreter uses a reference or pointer for the job like this: # psudo codes for python for(ptr = a.first(); ptr.is_valid(); ++ptr) { update('b', value(ptr)) call_method('a', 'remove', get_alue('b')) } ptr may be just an index. So at the first iteration, the first element, '1', is removed from a. The next time ptr=1, but a has been changed to [2,3,4,5], so '3' is removed, and so on, Smille From creedy at mitretek.org Wed Aug 13 13:34:22 2003 From: creedy at mitretek.org (Chris Reedy) Date: Wed, 13 Aug 2003 13:34:22 -0400 Subject: Py2.3: Feedback on Sets In-Reply-To: References: Message-ID: <3f3a76d1$1_6@corp.newsgroups.com> Raymond - Well now that you ask ... Raymond Hettinger wrote: > I've gotten lots of feedback on the itertools module > but have not heard a peep about the new sets module. > > * Are you overjoyed/outraged by the choice of | and & > as set operators (instead of + and *)? I think that choice appeals to me more than + and * (which are already more overloaded than I would like). I haven't seen any suggestions that I liked better. > * Is the support for sets of sets necessary for your work > and, if so, then is the implementation sufficiently > powerful? Yes I need it (desperately). Generally works as I need. However, see more comments below. > * Is there a compelling need for additional set methods like > Set.powerset() and Set.isdisjoint(s) or are the current > offerings sufficient? I haven't felt the need yet. So far I've been satisfied with: if x & y: as opposed to if x.isdisjoint(y) > * Does the performance meet your expectations? So far. However, so far, I haven't been trying meet any demanding performance requirements. > * Do you care that sets can only contain hashable elements? This is an interesting question. In particular, I have found myself on more than one occasion doing the following: for x in interesting_objects: x.foo = Set() while something_to_do: somex.foo |= something_I_just_computed for x in interesting_objects: x.foo = ImmutableSet(x.foo) build_some_more_sets(somex.foo) I'm not sure whether I like having to go back and change all my sets to Immutable ones after I've finished the computation. (Or whether I just ought to make x.foo immutable all the time.) I did appreciate the ImmutableSet type, since it allows me to flag to myself that I don't expect a set to change further. > * How about the design constraint that the argument to most > set methods must be another Set (as opposed to any iterable)? In some cases I've run into that. Since I can create a set with any iterable I've been able to do: set op Set(iterable) I think I might be interested in using a general iterable if that would get me some advantage (maybe significantly faster). > * Are the docs clear? Can you suggest improvements? No problems here. However, my background is math, and I've never had problems with documentation (I started my career learning IBM mainframe assembly language programming from the reference manuals) so I don't think I'm a good test case. > * Are sets helpful in your daily work or does the need arise > only rarely? I'm working on a project where they are critical. If it hadn't been supplied I would have implemented one myself. I was using the backported version of the set module with 2.2 before 2.3 came out. > User feedback is essential to determining the future direction > of sets (whether it will be implemented in C, change API, > and/or be given supporting language syntax). > > > Raymond Hettinger Chris -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! -----== Over 80,000 Newsgroups - 16 Different Servers! =----- From M.Williams at EU.HNS.COM Wed Aug 13 10:05:34 2003 From: M.Williams at EU.HNS.COM (M.Williams at EU.HNS.COM) Date: Wed, 13 Aug 2003 15:05:34 +0100 Subject: Serial port number limitations? Message-ID: Can anyone tell me if there is a limit on the port number (PC COM port under windows) that Python recognises? I have developed and tested a simple aplication to 'ping' itself (using a loop-back connector) which works perfectly OK on normal PC ports, but fails abysmally on 16 port interface. Alternatively, perhaps it expects HEX? I have found no clues in Serial.py Any thoughts gratefully accepted. Martin Williams #********************************************************************** This message is intended solely for the use of the individual or organisation to whom it is addressed. It may contain privileged or confidential information. If you have received this message in error, please notify the originator immediately. If you are not the intended recipient, you should not use, copy, alter, or disclose the contents of this message. All information or opinions expressed in this message and/or any attachments are those of the author and are not necessarily those of Hughes Network Systems Limited, including its European subsidiaries and affiliates. Hughes Network Systems Limited, including its European subsidiaries and affiliates accepts no responsibility for loss or damage arising from its use, including damage from virus. #********************************************************************** -------------- next part -------------- An HTML attachment was scrubbed... URL: From aleax at aleax.it Thu Aug 28 10:19:27 2003 From: aleax at aleax.it (Alex Martelli) Date: Thu, 28 Aug 2003 14:19:27 GMT Subject: OT: Celebrity advice References: <3F4D0D8B.5E5F9488@engcorp.com> <3F4D3560.71995AEB@engcorp.com> Message-ID: Lulu of the Lotus-Eaters wrote: > Peter Hansen wrote previously: > |No, you're not taking the word "ultimately" far enough. First the > |state tries to get painful on your ass, so you resist. Then they get > |really violent, and still you resist. > > Just as a question of biology, a person can be locked in handcuffs, or > in a metal cage, and be neither dead nor have the power to kill others. > This limit comes not out of the compromise and will-power of the > detained person, but simply out of physics and anatomy. In most > "ultimate" cases of state-sponsored violence, this is what happens... > not someone being killed. That depends on the determination of said person and his friends to resist arrest -- with what means and to what extent. If the state's power to arrest is not to be merely theoretical, it must be backed by military ability (and will to exercise it) which exceed those of the people's meant to be arrested. People who do not understand this may not have lived their lives in the land of the Mafia, I suspect -- when the prospect of a group of organized criminals commanding armed power [[which is admittedly a mere fraction of the state's, a limitation which however is partly compensated by far higher readiness to use it in lethal ways]] is not a theoretical conumdrum, but a living and vivid reality. And as a consequence the corps of Carabinieri, midway between the normal Police (also armed and quite ready to kill, but not a full-fledged military organization) and other corps such as the Army, Navy etc. Alex From theller at python.net Mon Aug 4 12:33:54 2003 From: theller at python.net (Thomas Heller) Date: Mon, 04 Aug 2003 18:33:54 +0200 Subject: packaging windows services? References: Message-ID: max writes: >> I have a patch sitting on the SF py2exe page which does this and more, >> I hope I can work on this during this week. >> OTOH, you can change the startup options of the service (and the user >> account it uses) with the control panel services applet. >> Thomas > > Hi Tom, > I was looking in the CVS on sf for this one, could you tell me where > it's sitting? > And yes, I know about the applet, just my users don't :) > max. I know that the (commercial) WISE installer can also install a service with the options you need. I do not know if inno or nsis can also do this. Thomas From donot at likespam.com Wed Aug 27 15:42:09 2003 From: donot at likespam.com (Rich) Date: Wed, 27 Aug 2003 12:42:09 -0700 Subject: learning to program References: <3F4CED6E.D04D35D6@engcorp.com> <5bspkv87u1q0v9aupajrrkjuutuh3f5o44@4ax.com> <3F4CF363.CAF6A14E@engcorp.com> Message-ID: <6b2qkv4nf549o8clg3bagphd02f92dadub@4ax.com> On Wed, 27 Aug 2003 14:07:31 -0400, Peter Hansen wrote: >Rich wrote: >> >> This is the only post I am able to see, sorry about re posting. I >> thought if I changed the subject heading I might be able to see the >> post. > >You should be able to see the replies that you missed via Google Groups, >as soon as they are indexed and on the web: How long does it usually take to post on Google? > > http://groups.google.com/groups?q=comp.lang.python > >-Peter From alessandro at sephiroth.it Wed Aug 27 10:18:39 2003 From: alessandro at sephiroth.it (Alessandro Crugnola *sephiroth*) Date: Wed, 27 Aug 2003 14:18:39 GMT Subject: detecting document changes References: <8360efcd.0308270012.5e74e157@posting.google.com> Message-ID: <3533b.2884$d66.38856@news2.tin.it> > and this one with Win32: > > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/156178 thanks but that one check only new/deleted/renamed files (also useful indeed). I should check also for modified files.. but I think i can add the functionallity to that script.. ..but is not too stressing for the cpu to check for file changes in a (forever) while loop? -- Alessandro Crugnola [sephiroth] Flash | PHP Developer http://www.sephiroth.it From mertz at gnosis.cx Wed Aug 27 15:54:25 2003 From: mertz at gnosis.cx (Lulu of the Lotus-Eaters) Date: Wed, 27 Aug 2003 15:54:25 -0400 Subject: Celebrity advice References: <3F4CD2A2.DE7D05D2@engcorp.com> Message-ID: "Andrew Dalke" wrote previously: |US homicide rates are 9.2 +/- 1.0 per 100,000 claims |Given a population of 4 billion (roughly, over the century) and assuming |the US rate is average for the world, that's |>>> 4000000000 / 100000. * 9.2 That homicide rate is a yearly rate. If you want to find out how many murders in a century, you'd need to multiply by 100. Of course, in reality, the homicide rate is much lower outside of the USA, so the base rate isn't good for extrapolation. Of course, the dominant reason the homicide rate is lower outside the USA is because most places don't have so damn many handguns. Yours, Lulu... -- ---[ to our friends at TLAs (spread the word) ]-------------------------- Echelon North Korea Nazi cracking spy smuggle Columbia fissionable Stego White Water strategic Clinton Delta Force militia TEMPEST Libya Mossad ---[ Postmodern Enterprises ]-------------------------- From __peter__ at web.de Fri Aug 22 10:37:00 2003 From: __peter__ at web.de (Peter Otten) Date: Fri, 22 Aug 2003 16:37:00 +0200 Subject: catching a from CORBA.UserException inherited exception References: Message-ID: Birgit Rahm wrote: > 3. then I want to invoke a method within a try - except statement, where > the except statement has to catch an exception defined in the file created > in 1. - without the try - exception statement the call is correct with the > correct parameter and throws an exception (that ends the debugging) with > an incorrect parameter > now I wanted to catch the correct exception, but I can only catch > CORBA.UserException in the right way > > What have I to do, to catch the derived exception? Asuming the userdefined exception MyException is defined in myfile: import myfile obj = # your initialization code try: obj.methodThatFails() except myfile.MyException: print "something went wrong in an organized manner" I am doubting if that is what you want, though. Maybe you could post some code and the traceback? From trevp at trevp.net Sun Aug 3 14:35:18 2003 From: trevp at trevp.net (Trevor Perrin) Date: 3 Aug 2003 11:35:18 -0700 Subject: memory leak? References: Message-ID: <47e891f1.0308031035.50684a31@posting.google.com> "Bjorn Pettersen" wrote in message news:... > > From: Trevor Perrin [mailto:trevp at trevp.net] > > > > Every time I run the below function from the interpreter, python.exe's > > memory usage increases by 5 Megs and stays at this higher level > > (python 2.3b2 on WinXP). I tried to isolate this to something > > simpler, but wasn't successful. > > > > Is this a memory leak, or is there another explanation? > [...] Hi Bjorn, > > Have your tried 2.3 final, I just did, same thing. > how are you determining there is a memory > leak (which tools), Windows Task Manager display process memory use. > what steps did you take that weren't successful, I tried calling array.array() and random.randrange() the same number of times in a loop, but the behavior didn't reproduce. > did > you try without using "import *", how about loading it as a module and > then deleting the module (i.e. have you inadvertenly created an object > that is still live)? I tried that, and also using xrange(). Below is a transcript from the interpreter, after running it python.exe had increased memory use from ~3 MB to ~21 MB. Maybe there's an innocuous explanation, I'm no python expert, I'm just curious: >>> import array >>> import random >>> def test(): ... for x in xrange(10000): ... b = array.array("B", [random.randrange(0,256) for count in range(64)]) >>> test() >>> test() >>> test() >>> test() >>> del(array) >>> del(random) Trevor From fa507874 at skynet.be Mon Aug 11 11:57:06 2003 From: fa507874 at skynet.be (conatic) Date: Mon, 11 Aug 2003 17:57:06 +0200 Subject: Hints about a script that read ftp contents .... References: <3f328d06_1@mk-nntp-1.news.uk.worldonline.com> Message-ID: Is there a way to check if it is a directory or a file ? I 'd like to build a function to make a walk-into in the directories but I need a way to know if it is a directory or a file. Could you give me any hints ? Conatic On Thu, 07 Aug 2003 18:31:47 +0100, simon place wrote: > another idea > > the distribution included module 'ftputil' has a walk function to move through > a ftp directory structure and apply a function to the directory/file name. From gh at ghaering.de Sat Aug 2 23:21:19 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Sun, 03 Aug 2003 05:21:19 +0200 Subject: PyChecker work with Python 2.3? In-Reply-To: <3F2C5300.FA223CBA@easystreet.com> References: <3F2C5300.FA223CBA@easystreet.com> Message-ID: <3F2C7FAF.2020801@ghaering.de> achrist at easystreet.com wrote: > The pychecker site says that pychecker works with versions > 1.5 through 2.2. Any reason to expect that 2.3 breaks it? > Anyone tried it to see? Why don't *you*? -- Gerhard From mirko-lists at zeibig.net Thu Aug 7 04:29:58 2003 From: mirko-lists at zeibig.net (Mirko Zeibig) Date: 7 Aug 2003 08:29:58 GMT Subject: Atomicity of signal handlers Message-ID: Hello, assuming I have a C++-library implementing tracing, where the tracefile is implemented as singleton and implements a method rotateLogs. Is it safe to have something like: def handleSIGUSR2(signal, frame): tracelib.rotateLogs() signal.signal(signal.SIGUSR2, handleSIGUSR2) Regards Mirko From aleax at aleax.it Thu Aug 21 05:20:27 2003 From: aleax at aleax.it (Alex Martelli) Date: Thu, 21 Aug 2003 09:20:27 GMT Subject: What's better about Ruby than Python? References: <3F41505F.69D18CC8@alcyone.com> <66d7kvonvb2n0nqbqahhd5roak7ur81sob@4ax.com> <3f43ef5d_4@127.0.0.1> <3F440A35.9030602@nyc.rr.com> <4o_0b.1665$Ej6.1182@newsread4.news.pas.earthlink.net> Message-ID: Andrew Dalke wrote: > Alex: >> You could use a class if its instances where descriptors, i.e. >> supported __get__ appropriately ... See Raymond Hettinger's >> HOWTO on descriptors -- a *wonderful* treatment of the subject. > > I'm slowing easing my way into this new stuff. I read it through > once, but it didn't all sink in. Could you post an example of how > to use it for my cache example? You posted...: >>> import time >>> def CachedCall(f): ... cache = {} ... def cached_call(self, *args): ... if args in cache: ... return cache[args] ... x = f(self, *args) ... cache[args] = x ... return x ... return cached_call ... >>> class LongWait: ... def compute(self, i): ... time.sleep(i) ... return i*2 ... compute = CachedCall(compute) To use descriptors, you should first of all change LongWait to be new-style, i.e. change its header to "class LongWait(object):". Not strictly necessary, but might avoid some minor issues. Thenm, something like...: >>> class CachedCall(object): ... def __init__(self, f): ... self.f = f ... self.cache = {} ... def cached_call(self, *args): ... if args in self.cache: return self.cache[args] ... x = self.f(self.obj, *args) ... self.cache[args] = x ... return x ... def __get__(self, obj, cls): ... self.obj = obj ... return self.cached_call ... should closely mimic your semantics, including ignoring what I call obj and you call self in determining whether a certain set of argumens is cached. Haven't tested it, mind you, but this is the general concept. Having obj (or self) be relevant may be obtained by keeping the cache right on obj (or self) [unless __slots__ should interfere, in which case you might try workarounds...]. Alex From aleaxit at yahoo.com Fri Aug 15 04:12:25 2003 From: aleaxit at yahoo.com (Alex Martelli) Date: Fri, 15 Aug 2003 10:12:25 +0200 Subject: GUI builder for Python References: Message-ID: Michael Peuser wrote: ... > There are some commercial GUI Builders out of the normal budget. By the way, I hear that PythonWorks is "out of development" but they're still selling licenses to existing customers only. I wonder if there is any chance the Tkinter GUI builder that came with it may be freed... > Free ones are Black Adder for Qt, BoaConstructor for wx and some stuff > like PAGE or SpecTIX for TIX. BlackAdder isn't free -- it's cheap but still commercial. If and only if you're under the conditions for using the GPL license for Qt &c -- basically if you're developing GPL for free operating systems, I think that's a fair summary -- you can use Trolltech's own QtDesigner and then pyuic to generate Python from the resulting XML file (that's more or less what BlackAdder does nowadays, though in a more integrated way: it uses an external QtDesigner rather than trying to "embed" it as it once did in earlier versions). Alex From grante at visi.com Sun Aug 17 23:12:36 2003 From: grante at visi.com (Grant Edwards) Date: 18 Aug 2003 03:12:36 GMT Subject: bitwise not - not what I expected References: <1YD%a.747879$3C2.17342633@news3.calgary.shaw.ca> Message-ID: <3f404424$0$157$a1866201@newsreader.visi.com> In article , Michael Peuser wrote: > I have the impression (may be wrong) that you are working under the > misconception that there can be a "natural" binary represensation of > negative numbers!? > Three conventions have commonly been used so far: > 1- Complement > 2- Complement > Sign tag plus absolut binary values > > All of them have their pros and cons. For a mixture of very technical > reasons (you mentioned the +0/-0 conflict, I might add the use of binary > adders for subtraction) The latter is _far_ more important than the former. Being able to use a simple binary adder to do operations on either signed or unsigned values is a huge savings in CPU and ISA design. I doubt that anybody really cares about the +0 vs. -0 issue very much (IEEE FP has zeros of both signs, and nobody seems to care). > most modern computers use 2-complement, and this now leads to > those funny speculations in this thread. ;-) -- Grant Edwards grante Yow! An Italian is COMBING at his hair in suburban DES visi.com MOINES! From theller at python.net Fri Aug 8 15:41:13 2003 From: theller at python.net (Thomas Heller) Date: Fri, 08 Aug 2003 21:41:13 +0200 Subject: py2exe and numarray References: Message-ID: <3cgcuecm.fsf@python.net> Maur?cio Caliggiuri Infor?ati writes: > > class Teste: > > > > def __init__(self): > > > > a = array("1","1") > > print a > > > > > > if __name__ == '__main__' : > > Teste() > Sorry, Thomas > I forgot on line: > "from numarray import array" > > The entire code is exactly this above! > I use python22 and numarray0.6 (for py22) > > The exe is generated but I cant run it! > This is the output error: > > Fatal Python error: Can't import module 'numarray.libnumarray' > abnormal program termination > > Mauricio This gives a clue, at least. So the next step would be to run python setup.py py2exe -i numarray.libnumarray Having done this, you get this when running the exe: Traceback (most recent call last): File "", line 1, in ? [... several lines deleted] File "imputil.pyc", line 93, in _import_hook File "imputil.pyc", line 347, in _do_import File "imputil.pyc", line 271, in _import_one File "", line 128, in _process_result File "numarray\_ufuncall.pyc", line 13, in ? File "", line 1, in ? File "imputil.pyc", line 106, in _import_hook ImportError: No module named _ufuncBool Not quite there, but we're making progress. So: python setup.py py2exe -i "numarray.libnumarray,numarray._ufuncBool" Then, we get something similar like the above traceback. This time, the last line of the traceback is: File "imputil.pyc", line 106, in _import_hook ImportError: No module named _ufuncInt8 We continue the above a few times, then we discover that abviously py2exe (or modulefinder, to be precise) has problems finding the .pyd files in the numarray package. Unfortunately, '--packages numarray' also doesn't find them - seems like a bug in py2exe. But the mechanisms to work around this are there. Instead of constructing a giant command line listing all the stuff, write a setup.cfg file and place it in the directory where setup.py resides. This is the contents, it lists all the numarray extension modules: [py2exe] includes=numarray.libnumarray, numarray.memory, numarray._bytes, numarray._chararray, numarray._conv, numarray._converter, numarray._ndarray, numarray._numarray, numarray._operator, numarray._sort, numarray._ufunc, numarray._ufuncBool, numarray._ufuncComplex32, numarray._ufuncComplex64, numarray._ufuncFloat32, numarray._ufuncFloat64, numarray._ufuncInt16, numarray._ufuncInt32, numarray._ufuncInt64, numarray._ufuncInt8, numarray._ufuncUInt16, numarray._ufuncUInt32, numarray._ufuncUInt8 Running 'python setup.py py2exe', and running the resulting executable: C:\test>dist\test\test.exe [49] C:\test> Bingo, it works! Thomas From bleah at pacific.net.sg Wed Aug 20 07:47:27 2003 From: bleah at pacific.net.sg (Mervyn Yeo) Date: Wed, 20 Aug 2003 19:47:27 +0800 Subject: Printing to a printer under WinXP Message-ID: <3f435f26$1@news.starhub.net.sg> I've tried p = open('LPT1:','wb') p.write('test') and it doesn't work. I've also tried win32print's WritePrinter and it doesn't work either. Does anyone know of an easy way to print strings and such from within a python script to windows' printers? From klappnase at web.de Sat Aug 9 04:19:24 2003 From: klappnase at web.de (klappnase) Date: 9 Aug 2003 01:19:24 -0700 Subject: TAB and Enter key in Tkinter References: Message-ID: Scott Holmes wrote in message news:... > I've noticed that widgets in a Pmw toplevel are navigated by tab key. I > find I can tab between the entry fields and the buttons but hitting the > enter key after moving to a button does not activate the button. If > possible, how do I configure buttons to accept and enter key event? > -- > --------------------------------------------------------------------- Hi, I suppose you probably bound the callback to your button with the "command=" option, like: button1 = Button(parent, text="Hello", command=some_function) In this case you will get the default Tk behavior that the callback is invoked with a (mouse-) Button-1 or a Space-Key press. If you do not want this, use the bind method instead like: button1 = Button(parent, text="Hello") button1.bind("", some_function) button1.bind("", some_function) This way you will get the behavior I think you want. Of course you can bind any other event to your callback this way. Please note that the "bind" method unlike the "command" option passes the event as (the first) argument to the callback function, so you will have to change the definition line like this: #callback for use with "command" option def some_function(): do_something #callback for use with "bind" method def some_function(event): do_something I hope this helped. Best regards Michael From ramiak2000 at yahoo.com Sun Aug 17 13:04:57 2003 From: ramiak2000 at yahoo.com (Rami A. Kishek) Date: Sun, 17 Aug 2003 13:04:57 -0400 Subject: Serious problem with Shelve Message-ID: <3F3FB5B9.5E49B306@yahoo.com> Hi - this mysterious behavior with shelve is just about to kill me. I hope someone here can shed some light. First of all, I have this piece of code which uses shelve to save instances of some class I define. It works perfectly on an old machine (PII-400) running Python 2.2.1 under RedHat Linux 8.0. When I try to run it under Python for windows ME on a P-4 1.4 GHz, however, it keeps crashing on reading from the shelved file the second time I try to access it. The Windows machine was originally running python 1.5.2, so I upgraded to 2.2.3, thinking that would solve the problem, but it didn't! This is what the error looks like: tmprec = myrecs[key] File "D:\PROGRAMS\PYTHON22\lib\shelve.py", line 70, in __getitem__ f = StringIO(self.dict[key]) KeyError: A_G_08631616188 ^ Notes: Here's what my program does (it is too much code to include here). I have 4 related modules: one containing the class definitions (in all other modules I use from classfile import ___); the second module builds the shelve file by parsing a large text file containing the data, building classes; the third re-opens the file later to do reading and writing operations; and the 4th module is a GUI controller that simple calls the appropriate functions from the other 2 modules. The main breakdown occurs in module 3. Significantly, I initially had this module set up as a script in which everything was done on the module level, and it was working fine (apparently). The problems started appearing when I wrapped code inside functions (I need to do that since I want to call it from other modules, and I have about 4000 lines of code altogether!). I spent painstaking hours trying to isolate the problem - I pass the open shelve file as a parameter to all the functions that need it, and I close it properly using try: finally statements after every use. I also make sure all the keys that go in there are unique. What module 3 does is a series of short reads and writes to the shelve file. First I test if a particular key is in there - if it is not, I add an item, if it is, I read the existing item, update it, then write it back like this: tmprec = myrecs[key] # I read a particular instance from the shelve file tmprec.field = 1 # I update one field #del myrevs[key] # Commented lines are things I tried while debugging #myrecs.sync() # myrecs[key] = tmprec # Then I write it back to the shelve file #myrecs.sync() This one function apppears to be the guilty party. When I comment it out the crash stops. However it is a vital function for my program and I need to do it. Note that deleting the original item before reqwriting it helped reduce the frequency of crashes, but didn't eliminate it completely. The other possibility (which is why I unsuccessfully tried the .sync() lines) is that it has to do with the timing of writing to disk. The library reference is vague about this, saying that shelve is incapable of simultanteous reads and writes, so the file shouldn't be opened twice for write. However it does not say whether this implies we cannot read and write like this in quick succession. More details: * The first run of module 3 after creating the shelve file doesn't crash, although I suspect it is doing something funny. * The second time I get that error above, keeping in mind I am supposed to have a key in there called "A_G_0863161618" (without the extra '8' at the end), so the database is already corrupted. So the key 'A_G_08631616188' is in myshelvefile.keys(), the original is no more, yet NEITHER can be accesed using myshelvefile[key]! * After creation, the shelve file size is only 71 kB. After running module 3 - which is supposed to mostly read and not really change the file much - the size jumps to 110 kB! * If I open the file in a text editor, I notice all sorts of things that are not supposed to be there (like directory paths, etc), indicating it is corrupted. I do not see those things when I open the file on the good (Linux) machine. * I did a scandisk to ensure the disk is OK and it is. From uche at ogbuji.net Fri Aug 15 09:05:45 2003 From: uche at ogbuji.net (Uche Ogbuji) Date: 15 Aug 2003 06:05:45 -0700 Subject: "drop-in" DOM replacement for minidom? References: Message-ID: Geoff Gerrietts wrote in message news:... > Quoting Paul Miller (paul at fxtech.com): > > We've run into minidom's inabilty to handle large (20+MB) XML files, and > > need a replacement that can handle it. Unfortunately, we're pretty > > dependent on a DOM, so a pulldom or SAX replacement is likely out of the > > question for now. > > > > Has someone done a more efficient minidom replacement module that we can > > just drop in? Preferrably written in C? > > I've posted on a related topic in the past, when a friend of mine was > blowing thru 8GB of memory parsing a 30MB file in minidom. Pretty much > every response I got was of the general form "well what the hell are > you using DOM for? are you defective?" Some were more diplomatic than > others. My response is usually more like "what are you using XML for a single 30MB file for?" I've long maintained that when working with XML, modest document sizes is very important, regardless of what tools you're using. But that having been said, some documents are 30MB, and it makes sense that they're 30MB, and that's just the way it is. > My friend also had some more challenging problems. He was running on a > DEC Alpha, I think under Digital Unix, and as a consequence 4Suite had > byte-ordering problems. 4Suite used to have byte-ordering problems, originally reported under Solaris 9, and also affecting some Mac OS X users. Those are fixed now. > PyRXP wouldn't compile for him, if I recall > correctly -- or maybe there were licensing problems? Anyway, he > ultimately settled on using pulldom; that gave him simplicity, speed, > and a small enough memory profile that it satisfied his needs. > > Obviously it won't help in your case. pulldom is always worth considering. http://www-106.ibm.com/developerworks/xml/library/x-tipulldom.html > I don't think you'll find something that precisely mimics the minidom > module's interface, so you're going to hafta do some retooling. > However, I believe that if you can get 4Suite to compile, Which I hardly expect to be a problem. > you might > find some love in there. There's a cDomlette component (labelled at > the time of my last reading as "experimental") cDomlette hasn't been experimental for nearly a year now. We use it heavily in production. > that builds the parse > tree in C, with a minimal memory consumption. And fast parse and mutation time. > Here's a link to something that should tell you how to make it work > (though when I personally used cDomlette, I seem to remember it being > harder than this....) > > http://uche.ogbuji.net/tech/akara/nodes/2003-01-01/domlettes Your memories must be from long ago :-) That API is how it's been for a while. > Also, you may be interested in looking at the comparisons done by the > PyRXP folks on their page: > > http://www.reportlab.com/xml/pyrxp.html > > Best of luck! Ditto. --Uche http://uche.ogbuji.net From goodger at python.org Thu Aug 7 15:34:03 2003 From: goodger at python.org (David Goodger) Date: Thu, 07 Aug 2003 15:34:03 -0400 Subject: where are docutils tools installed? In-Reply-To: <6f03c4a5.0308060631.7409f7b1@posting.google.com> References: <6f03c4a5.0308060631.7409f7b1@posting.google.com> Message-ID: <3F32A9AB.8030605@python.org> Rim wrote: > I've installed the latest docutils, but I can't find where the > tools have been installed. I can see them when I expand the > tarball, but I can't find them under site-packages. Michael is correct, they aren't installed. They can be used from the "tools" directory of the expanded tarball. Installing them properly is on the to-do list, however they also need wholesale renaming, and I haven't gotten around to it yet. Help is welcome! Please feel free to join the docutils-develop and/or docutils-users lists (I missed your original article here, and only noticed Michael's follow-up; posting to one of the dedicated lists is guaranteed to get better results). David Goodger http://starship.python.net/~goodger For hire: http://starship.python.net/~goodger/cv Docutils: http://docutils.sourceforge.net/ (includes reStructuredText: http://docutils.sf.net/rst.html) From mwh at python.net Thu Aug 21 10:47:45 2003 From: mwh at python.net (Michael Hudson) Date: Thu, 21 Aug 2003 14:47:45 GMT Subject: max length of a python program References: <1ed07caf.0308210513.6556978a@posting.google.com> Message-ID: <7h3bruj2hoe.fsf@pc150.maths.bris.ac.uk> Ragu_Bharadwaj at vrtx.com (Ragu) writes: > Is there a limit to the # of lines that can be in a Python program? I can't seem to find one, although trying to run a million line file got the OOM killer into action... Cheers, mwh -- ZAPHOD: OK, so ten out of ten for style, but minus several million for good thinking, eh? -- The Hitch-Hikers Guide to the Galaxy, Episode 2 From pdfernhout at kurtz-fernhout.com Sat Aug 23 22:18:53 2003 From: pdfernhout at kurtz-fernhout.com (Paul D. Fernhout) Date: Sat, 23 Aug 2003 22:18:53 -0400 Subject: How to store data? In-Reply-To: References: Message-ID: <3f482037_5@corp.newsgroups.com> Lars- I don't want to see you cut on bleeding edge software, but, I just released an updated version of the Pointrel Data Repository System http://sourceforge.net/projects/pointrel/ which could in theory handle such a task (subject to bugs etc.), and I could not resist responding to your post. The Pointrel System can handle simple locking and simple transactions (although this has only be tested recently under GNU/Linux and Python2.3). As a caveat, this Pointrel System database bunny may have long pointy, nasty teeth, etc., and so if your application is mission critical you should most likely go with a more proven solution -- like a convetional relational database (and using SQL to access one is a good skill to learn). And possibly if your needs are minimal, pickling your dictionaries or using the 'shelve' module might just be good enough for a simple application. Mainly just for fun, and also as another example for people who are interested in playing with the related concepts, rather than to try to persuade you specifically to try the Pointrel System (since if you are not an experienced programmer you would have no way to judge what you were getting into, and so my best advice to you specifically would be to go with something proven like pickle, shelve, SQL etc.), here is how you might solve the storage issue you outline using the Pointrel System: ================================================== File: "congress.py" ================================================== from pointrel20030812 import * Pointrel_initialize("archive_congress") # add a first attendant -- uses built in unique ID function # but could be any unique ID string # each change will be implicitely a seperate transaction attendantID = Pointrel_generateUniqueID() Pointrel_add("congress", attendantID, 'object type', 'user') Pointrel_add("congress", attendantID, 'name', 'Sir Galahad') Pointrel_add("congress", attendantID, 'address', 'Camelot') Pointrel_add("congress", attendantID, 'mail', 'Carrierpigeon at england.com') # add a second attendant, this time as an atomic transaction attendantID = Pointrel_generateUniqueID() Pointrel_startTransaction() Pointrel_add("congress", attendantID, 'object type', 'user') Pointrel_add("congress", attendantID, 'name', 'Brian') Pointrel_add("congress", attendantID, 'address', 'Palestine') Pointrel_add("congress", attendantID, 'mail', 'fastridingmessenger at rome.com') Pointrel_finishTransaction() # add a third attendant, again as a single transaction attendantID = Pointrel_generateUniqueID() Pointrel_startTransaction() Pointrel_add("congress", attendantID, 'object type', 'user') Pointrel_add("congress", attendantID, 'name', 'Lars') Pointrel_add("congress", attendantID, 'address', 'Pythonland') Pointrel_add("congress", attendantID, 'mail', 'lars at example.com') Pointrel_finishTransaction() # update a value, as an implicit transaction attendantID = Pointrel_lastMatch("congress", WILD, 'name', 'Sir Galahad') Pointrel_add("congress", attendantID, 'address', "Zoot's castle") # delete an attendant attendantID = Pointrel_lastMatch("congress", WILD, 'name', 'Brian') Pointrel_add("congress", attendantID, 'deleted', 'true') # get a list of all attendants (deleted or not) attendants = Pointrel_allMatches("congress", WILD, 'object type', 'user') print '\nAll attendant IDs (including deleted ones):', attendants # filter out deleted attendants currentAttendants = filter(lambda user: Pointrel_lastMatch('congress', user, 'deleted', WILD) <> 'true', attendants) print '\nCurrent attendants:', currentAttendants print "\nAttendant names:" for attendant in currentAttendants: print Pointrel_lastMatch('congress', attendant, 'name', WILD) print "\nAttendant csv info" for attendant in currentAttendants: name = Pointrel_lastMatch('congress', attendant, 'name', WILD) address = Pointrel_lastMatch('congress', attendant, 'address', WILD) email = Pointrel_lastMatch('congress', attendant, 'mail', WILD) print '"%s","%s","%s"' %(name, address, email) # note proper csv output would require escaping embedded quotes etc. ================================================== Sample output: ================================================== creating archive file archive_congress.pointrel_database.poi archive with only header All attendant IDs (including deleted ones): ['unique://freevolution:23:43207645167115827', 'unique://freevolution:25:37062969616920138', 'unique://freevolution:26:11213192987278475'] Current attendants: ['unique://freevolution:23:43207645167115827', 'unique://freevolution:26:11213192987278475'] Attendant names: Sir Galahad Lars Attendant csv info "Sir Galahad","Zoot's castle","Carrierpigeon at england.com" "Lars","Pythonland","lars at example.com" ================================================== Database file created: 'archive_congress.pointrel_database.xml' (There is also a binary file which is maintained for efficiency). ================================================== [And, as an example of bleeding edge, from testing this, I found a bug from a last minute change I made to the unique ID system which had been working well for a long time; it turns out that because of an error in how I open a support file when it does not exists, the file "a_pointrel_uniqueIDCounter.txt" now needs to exist in the local directory with a number (e.g. '10') in it to get sequence numbers in addition to a random ID component in unique IDs. The system still works without this file though -- the unique IDs just aren't as collision resistant. Something for an incremental release ASAP though.] The one plug I'd put for the Pointrel System is that the simple (yet, I hope, elegant) data storage approach is designed to be expandable with changing needs over time, and usually data storage needs do change, and in unexpected ways. Whether the Pointrel System can really deliver on that promise remains to be seen. Again, MySql etc. have a proven track record handling the sorts of issues you have outlined so far, and are probably your best choice. Anyway, if all this sounds like gibberish, feel free to ignore it! :-) Best of luck with your project. --Paul Fernhout Lars Behrens wrote: > Hi there! > > For a web project I need a little expert help. I don't have written much > code yet, just been fiddling around a bit, testing and planning. > > The web site will have a submission page for attendants of a congress. > In a form the user will submit name, mailadress etc. and I plan to store > the data in a list of dictionaries: > > People = [{'name' : 'Sir Galahad', 'address' : 'Camelot', 'mail' : > 'Carrierpigeon at england.com'}] > > #new attendant: > People.append({'name' : 'Brian', 'address' : 'Palestine', 'mail' : > 'fastridingmessenger at rome.com'}) > > The 'lines' can be accessed by their index. > > Now my question: Where do you suggest to store the data? I know that > something sql-like would be quite useful but I don't have any knowledge > of sql. So I thought about putting the data either into a comma > separated file or pickling it. > > I should mention that some other people on different operation systems > should be able to import the file (Excel, Open Office) so I tend towards > the csv file. > > What would be better? > > And another problem: How to lock the file when several users try to > write to it? > > As I'm no very experienced programmer I would appreciate your help, > thanks in advance > > Cheerz Lars -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! -----== Over 100,000 Newsgroups - 19 Different Servers! =----- From edreamleo at charter.net Fri Aug 29 11:07:11 2003 From: edreamleo at charter.net (Edward K. Ream) Date: Fri, 29 Aug 2003 10:07:11 -0500 Subject: after, after_cancel and Python 2.3 References: Message-ID: > Previous to Python 2.3 my app has destroyed the root Tk window using > root.destroy rather than the more usual root.quit. In Python 2.3 this does > not work so well... Oops. I forgot to mention that I am using Python 2.3.0 on Windows XP. It was installed using the standard Windows installer and so is running Tk 8.4.3. Edward -------------------------------------------------------------------- Edward K. Ream email: edreamleo at charter.net Leo: Literate Editor with Outlines Leo: http://webpages.charter.net/edreamleo/front.html -------------------------------------------------------------------- From geoff at gerrietts.net Wed Aug 13 17:25:02 2003 From: geoff at gerrietts.net (Geoff Gerrietts) Date: Wed, 13 Aug 2003 14:25:02 -0700 Subject: "drop-in" DOM replacement for minidom? In-Reply-To: References: Message-ID: <20030813212502.GF24355@thoth.homegain.com> Quoting Paul Miller (paul at fxtech.com): > We've run into minidom's inabilty to handle large (20+MB) XML files, and > need a replacement that can handle it. Unfortunately, we're pretty > dependent on a DOM, so a pulldom or SAX replacement is likely out of the > question for now. > > Has someone done a more efficient minidom replacement module that we can > just drop in? Preferrably written in C? I've posted on a related topic in the past, when a friend of mine was blowing thru 8GB of memory parsing a 30MB file in minidom. Pretty much every response I got was of the general form "well what the hell are you using DOM for? are you defective?" Some were more diplomatic than others. My friend also had some more challenging problems. He was running on a DEC Alpha, I think under Digital Unix, and as a consequence 4Suite had byte-ordering problems. PyRXP wouldn't compile for him, if I recall correctly -- or maybe there were licensing problems? Anyway, he ultimately settled on using pulldom; that gave him simplicity, speed, and a small enough memory profile that it satisfied his needs. Obviously it won't help in your case. I don't think you'll find something that precisely mimics the minidom module's interface, so you're going to hafta do some retooling. However, I believe that if you can get 4Suite to compile, you might find some love in there. There's a cDomlette component (labelled at the time of my last reading as "experimental") that builds the parse tree in C, with a minimal memory consumption. Here's a link to something that should tell you how to make it work (though when I personally used cDomlette, I seem to remember it being harder than this....) http://uche.ogbuji.net/tech/akara/nodes/2003-01-01/domlettes Also, you may be interested in looking at the comparisons done by the PyRXP folks on their page: http://www.reportlab.com/xml/pyrxp.html Best of luck! --G. -- Geoff Gerrietts "Whenever people agree with me I always feel I must be wrong." --Oscar Wilde From newsgroups at jhrothjr.com Wed Aug 27 13:08:46 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Wed, 27 Aug 2003 13:08:46 -0400 Subject: Proposal: Magic Constants References: <7h3r837ce12.fsf@pc150.maths.bris.ac.uk> Message-ID: "Michael Hudson" wrote in message news:7h3r837ce12.fsf at pc150.maths.bris.ac.uk... > "John Roth" writes: > > > But these are existing literal syntax. I was thinking > > more of random code where someone could currently > > juxtapose a literal and an identifier, say, without an > > intervening white space character. > > >>> 10and 1 > 1 > >>> 5or 7 > 5 > > Very much a wart of the tokenizer, though. Ah, right. I forgot about alphabetic operators. Why do you call it a wart, though? I would have thought that not requiring white space in that context was a feature. John Roth > > Cheers, > mwh > > -- > "Well, the old ones go Mmmmmbbbbzzzzttteeeeeep as they start up and > the new ones go whupwhupwhupwhooopwhooooopwhooooooommmmmmmmmm." > -- Graham Reed explains subway engines on asr From mpeuser at web.de Wed Aug 13 03:52:45 2003 From: mpeuser at web.de (Michael Peuser) Date: Wed, 13 Aug 2003 09:52:45 +0200 Subject: How to make tree of dictionaries? References: <87fzk6tuoq.fsf@big.terem> Message-ID: "Aahz" schrieb im Newsbeitrag news:bhc9bh$lp9$1 at panix1.panix.com... > In article <87fzk6tuoq.fsf at big.terem>, Vlad Sirenko wrote: > >I need: > >dict = {2002 : {'Jan': {1 : 'num1', 2: 'num2', 3 : 'num3'}, > > {'Feb': {1 : 'num4', 2: 'num5', 3 : 'num6'} } } > > 2003 : {'Jan': {1 : 'num7', 2: 'num8', 3 : 'num9'} } } > > > >How to do it programmatically? > >In Perl I would do something like: > > > >while ($line = <>) { > > if ($line =~ /^---\s+\w+\s+(\w+)\s+(\d*)\s+(\d+):(\d+):(\d+)\s+(\d+)\s+---$/) { > > ($month,$date,$hour,$minute,$sec,$year) = ($1,$2,$3,$4,$5,$6); > > $statistics->{$year}->{$month}->{$date} += $sec; > > } > >} This is what I love Perl for! BTW: Do you really mean += ? This does nor match yourt example, neither seems to make much sense. Perhaps a misconception? > > > >But how to do it in Python without catching 'KeyError' exception or > >iterating over some nested loops. How to do it elegantly? > > You don't need nested loops, but you do need multiple statements: > > tmp_year = stats.setdefault(year, {}) > tmp_month = tmp_year.setdefault(month, {}) > tmp_month[date] = tmp_month.setdefault(date, 0) + sec *I* think this is less readable than the Python expression! Note that *get* and *setdefault* are most powerful operations on mapping types once you get used to them, that is... ;) Kindly Michael P > -- > Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ > > This is Python. We don't care much about theory, except where it intersects > with useful practice. --Aahz From jjl at pobox.com Mon Aug 18 14:29:33 2003 From: jjl at pobox.com (John J. Lee) Date: 18 Aug 2003 19:29:33 +0100 Subject: What's better about Ruby than Python? References: <87ekzj6pbz.fsf@pobox.com> Message-ID: <87zni6ddki.fsf@pobox.com> "Michael Peuser" writes: > "John J. Lee" schrieb im Newsbeitrag > news:87ekzj6pbz.fsf at pobox.com... > > "Michael Peuser" writes: > > [...] > > > I don't know much about Ruby but I did some substantial programming in > > > Python and Perl. I should now consider side issues more important than > > > language features itself: > > > > > > - How fast does the code run > > > - Is there an acceptable IDE (best: GUI/IDE RAD-Framework) > > > - Is there a flexible and fast GUI Toolkit > > > -Can you access OpenGL > > > - Which platforms are supported > > > - How easy is multimedia (Sound/Movie in- and output) > > > - How can you deploy your program > > > - How large is a self contained EXE file > > > - Is there mathematical support (array arithmetic, statistical > functions, > > > plotting) > > > - Is there documentation > > > - Are there books > > > > AFAIK, none of these are distinguishing features between Python and > > Perl. > > > I absolutly disagree! We are (probably) not talking about the academic > merits of the languages, but of what you can do with them with reasonable > effort. Yes. > Those "side issues" I mentioned above (and some more, and some of them not > relevant for everyone) have - this is my experience - influenced my > productivity more than everything else. Sure. What does that have to do with the *comparison* between Perl and Python, though? My claim was that these things are pretty much the same on both. > Most of the things we do with - especially so called script languages is > inetrfacing library packages. Thoug this is not a feature of the languge it > is most important how to do it, what pachages have already been bound etc > etc. Consider the permanent discussions about what GUI oder IDE to use. The > OpenSource situation is, well unclear. I have learning a lot about that > durung the last two weeks, and I would say: Well perhaps take eric3 and > PyQt. But in fact I have no experience with eric and I very little with Qt. Where's your point here? You seem to have slipped into a comparison of Windows and Open Source. My post was a reply to your Perl / Python comparison. > If all those would be in a state as VB with its Active-X support and quitre > acceptable application framework or - eben better - as compiled RealBasic on > Macintosh with its universal Quicktime interface, then I should say you > could discuss fines language matters. (One should mention Delphi as well.) This comes over as a troll, so I shan't bother to answer. > But this is not the case. > > > The really major differences are: Perl has tons of library code > > (though Python has lots) and Perl has a pile of stuff you have to > > learn that brings no significant benefits. It'd be great to see more > > research on the impact of the nonsense-overhead that comes with Perl > > (and is absent from Python). > > > Just amount of "library code" is not what matters. Where did I say that? Not sure why library code requires scare quotes, either... > You cannot have found it > on my list ;-) I still don't, if we're talking about *differences*. (With the possible exception of 'how easy is multimedia' -- I don't know enough about that to say). John From wolfoxbr at hotmail.com Mon Aug 11 14:09:01 2003 From: wolfoxbr at hotmail.com (Roberto Amorim) Date: Mon, 11 Aug 2003 15:09:01 -0300 Subject: Problems py22 -> py23 References: <000e01c3600c$39b62be0$237290c8@ITABIRITO> Message-ID: Change the line below: menuBar1.addmenuitem('Ajuda', 'command' , 'Creditos' , label = 'Threshold 2D ')#, command = lambda e = self , x ='copyrightVTK.html' : e.showbrowser(x)) to: menuBar1.addmenuitem('Ajuda', 'command' , 'Creditos' , label = 'Threshold_2D ')#, command = lambda e = self , x ='copyrightVTK.html' : e.showbrowser(x)) See if it works. I can't try it now, but I hope it works for you. If possible, show us a little more of the code, as the error doesn't bring enough information to know what's going on. All the above is little more than a wild guess. :-) Boa sorte! From roy at panix.com Thu Aug 21 22:14:53 2003 From: roy at panix.com (Roy Smith) Date: Thu, 21 Aug 2003 22:14:53 -0400 Subject: What's better about Ruby than Python? References: Message-ID: Juha Autero wrote: > Alex Martelli writes: > > > The counter-arguments you present in the following do not affect Mertz's > > argument in the least, and thus cannot indicate why you don't find it > > completely compelling. To rephrase David's argument: simplicity suggests > > that a 'class' statement should always have the same fundamental semantics. > > Since it SOMETIMES needs to bind a name, therefore, letting it ALWAYS > > bind a name -- rather than sometimes yes, sometimes no, depending on > > context -- is the only Pythonic approach. > > I think the problem here is same as with understanding Python > variables and assignment. People think names as objects themself > rather than bindings to an object. (Maybe I should have said "things" > to avoid confusin. Though in Python, everything you can bind a name to > is a Python object.) They think that after > > class foo: pass > > you get > > +-----+ > | foo | > +-----+ > > but in Python in reality you get > +-----+ > foo --> | | > +-----+ > > So, in Python all objects are basically anonymous. They just have > names bound to them. And since everything is an object, this goes for > classes and functions, too. I'm not sure about modules though. Well, classes (and modules) are not really anonymous. A class knows it's name (as does a module). >>> class foo: pass ... >>> print foo __main__.foo >>> bar = foo >>> print bar __main__.foo >>> so, a more accurate picture would be +-----+ foo --> | foo | +-----+ From jjl at pobox.com Sat Aug 23 19:36:33 2003 From: jjl at pobox.com (John J. Lee) Date: 24 Aug 2003 00:36:33 +0100 Subject: large-scale app development in python? References: <7xlltkxrcv.fsf@ruckus.brouhaha.com> Message-ID: <87smnsx7y6.fsf@pobox.com> Paul Rubin writes: > "John Roth" writes: > > There are quite a few large programs in Python. Zope comes to mind > > immediately. > > I think by the standards of "large programs", Zope would be considered > medium sized. I've never checked: how many LOC is Zope? Of course, one has to remember that lower LOC (by a multiple of 5 or so, according to some experienced C++, Java and Python developers here) is one of the very reasons that people choose Python in the first place, so some sort of correction has to be applied, or a more sophisticated metric used. John From dpengel at sbcglobal.net Tue Aug 5 12:10:00 2003 From: dpengel at sbcglobal.net (Daniel P. Engel) Date: Tue, 05 Aug 2003 16:10:00 GMT Subject: How to determine row position in a list box In-Reply-To: References: Message-ID: > Where do I obtain the value y used in nearest(y)? Wouldn't that be sels[0]? Scott Holmes wrote: > I've been trying to understand nearest(y) but I'm not getting it. I > have a ScrolledListBox with a list of people's names. I also have a > parallel list of the unique people numbers used in the PostgreSQL > database. When a name is selected from the scrolled list, I need to > determine the index value and then find the corresponding people number. > > > def selectionCommand(self): > sels = self.box.getcurselection() > if len(sels) == 0: > print 'No selection' > else: > print 'Selection:', sels[0] > print self.nmbr_list[self.box[0].nearest(y)] > self.lkupTopLevel.withdraw() > > Where do I obtain the value y used in nearest(y)? > From jar at mminternet.com Sun Aug 3 19:01:08 2003 From: jar at mminternet.com (james roush) Date: Sun, 3 Aug 2003 16:01:08 -0700 Subject: uTidyLib --I'm lost Message-ID: I'm tryinh to switch from mx.tidy to uTidyLin and it isn't going well. So far I can't even import TidyLib. Below is what I get when trying to import into Idle. I'm using Python 2.1. >>> from tidylib.lib import parse, parseString Traceback (most recent call last): File "", line 1, in ? from tidylib.lib import parse, parseString File "K:\Python21\tidylib\lib.py", line 47 yield n ^ Can someone please clue me in. ----------------------- James A Roush jar @ mminternet.com ----------------------- From postmaster at earthlink.net Sun Aug 31 21:34:32 2003 From: postmaster at earthlink.net (Daniel T.) Date: Mon, 01 Sep 2003 01:34:32 GMT Subject: threads and socket question References: <1165lvgenb2s4lbbjsihcd1uibat1g137u@4ax.com> Message-ID: Gon?alo Rodrigues wrote: > My setup is the following: I have socket s from which I want to read > and write. So I made the following set up: > > There is a thread whose only job is to read. Any data read (from recv > call) is just passed to (some) Queue. This thread is "owned" by a > second thread waiting on a Queue for write requests. The thread just > pops these from the Queue, and calls the send method from the socket. > This thread also takes care of closing the socket or (possibly) > handling any exceptions raised due to socket operation. > > So my question is: since I have two threads sharing the same socket, > even though one is only reading and the other does everything else, do > I have to watch out for any "concurrency" issues? > > P.S: This is for learning experience. So it's of no use telling me > that I should learn Twisted :-) I may (eventually) get there, but at > the moment I feel more omfortable with working with plain blocking > sockets. The first problem I can think of is the one that stopped me. Note the code below... You can't close a blocked socket in python even from a separate thread. import unittest import socket import threading import time class SocketAcceptor ( threading.Thread ): def __init__( self, socket ): threading.Thread.__init__( self ) self.socket = socket self.done = 0 def run( self ): self.socket.bind( ( "", 3424 ) ) self.socket.listen( 5 ) try: child, ip = self.socket.accept() except: pass self.done = 1 class SocketTester ( unittest.TestCase ): def testClose( self ): ss = socket.socket() acceptor_thread = SocketAcceptor( ss ) acceptor_thread.start() time.sleep( 1 ) ss.close() time.sleep( 1 ) self.assertEquals( acceptor_thread.done, 1 ) if __name__ == '__main__': unittest.main() From m.doering at bgbm.org Mon Aug 25 11:56:52 2003 From: m.doering at bgbm.org (Markus Doering) Date: Mon, 25 Aug 2003 17:56:52 +0200 Subject: Python2.3 absolute import error Message-ID: Hello, I just switched from 2.2 to Python 2.3. I am developing an XML/CGI interface to databases as a python package called "unitWrapper" containing several modules which ran fine under v2.2. Running Python2.3 under windows2000 I get import errors when a module imports another module of the same package with absolute package-names like this: main script: "unitWrapper.wrapper" : > ># import error messages and error logging mechanism >from unitWrapper.errorclasses import * > 'import site' failed; use -v for traceback Traceback (most recent call last): File "wrapper.py", line 67, in ? from unitWrapper.errorclasses import * ImportError: No module named unitWrapper.errorclasses The module exists and curiosly the import above works fine when executed from outside the package directory. But as soon as there is an import statement in the imported module unitWrapper.errorclasses, trying to import other modules in an absolute way, I get the same error again. I checked the sys.path environment and suprisingly I found that the site-packages directory is not included when scripts are executed from a subfolder of site-packages: sys.path when executing unitWrapper.wrapper.py from site-packages directoy: ['C:\\Python23\\Lib\\site-packages\\unitWrapper', 'C:\\WINNT\\System32\\python23.zip', '', 'C:\\Python23\\DLLs', 'C:\\Python23\\lib', 'C:\\Python23\\lib\\plat-win', 'C:\\Python23\\lib\\lib-tk', 'C:\\Python23'] sys.path when executing unitWrapper.wrapper.py from outside site-packages directoy: ['C:\\Documents and Settings\\m.doering\\Desktop', 'C:\\WINNT\\System32\\python23.zip', 'C:\\Documents and Settings\\m.doering\\Desktop', 'C:\\Python23\\DLLs', 'C:\\Python23\\lib', 'C:\\Python23\\lib\\plat-win', 'C:\\Python23\\lib\\lib-tk', 'C:\\Python23', 'C:\\Python23\\lib\\site-packages'] Is this intended ? Has there changed anything according to relative / absolute adressing of modules ? How should modules import other modules of the same package? Are only relative package-names allowed? And how do I adress a "parental" module from a subpackage in a relative way? Any help greatly appreciated, Markus Doering -- Markus D?ring Botanic Garden and Botanical Museum Berlin Dahlem, Dept. of Biodiversit y Informatics K?nigin-Luise-Str. 6-8, D-14191 Berlin Email: m.doering at bgbm.org http://www.bgbm.org/BioDivInf/ From vanevery at 3DProgrammer.com Sat Aug 9 18:59:05 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Sat, 9 Aug 2003 15:59:05 -0700 Subject: Python vs. C# Message-ID: <3f357a9b@shknews01> What can I do with Python that I can't do with C#? I'm currently going up a learning curve about C# and .NET. I've avoided "Microsoft stuff" for a rather long time, but there's this reality that I currently live in Seattle. I need gigs, so swallowing C# and .NET is currently the way to go. While swallowing, I've been surprised to find out that on paper, C# and .NET look like well implemented systems. C# could be glossed as "C++ without the headaches." I certainly don't care for the headaches of C++, I've just spent most of the last 11 years avoiding them, that's how I've gotten by. Also C#, like Python, has higher level data types built right in. No more memory management, no more implementing linked lists over and over again .NET Framework could be glossed as "an interoperability environment for programming languages." So long as your language looks a lot like C#. ;-) Some open source projects are trying to clone .NET and provide a C# compiler. So, C# may not remain a "Windows thing," although it will remain driven by Microsoft. We'll have the age-old question, can open source keep up with Microsoft, enough to be usable and of interest to people? Don't really know at this point. But I do know, from reading the Linux newsgroups, that Linux people have failed to provide "an interoperability enviornment for programming languages." That's why some people are looking to clone .NET. Microsoft is leading in this area. So again my question is, language-wise, what can I get done with Python that I can't get done with C#? What is easy to express in Python, that is tedious, difficult, or impossible to express in C#? -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From clifford.wells at comcast.net Fri Aug 22 21:58:41 2003 From: clifford.wells at comcast.net (Cliff Wells) Date: Fri, 22 Aug 2003 18:58:41 -0700 Subject: visual indentation In-Reply-To: References: Message-ID: <1061603915.17746.3.camel@devilbox.homelinux.net> On Fri, 2003-08-22 at 11:10, Hilbert wrote: > Hello, > > I'm using python to output RIB streams for Renderman. > The RIB stream is a bunch of statements which describes > a 3d image. The Rib standard allows for blocks which we > usually indent for better visualization for example: > > WorldBegin > Color [1 1 1] > Surface "constant" > Sphere(1.0, -1.0, 1.0, 360) > WorldEnd > > I'm using CGKit in python which has a Renderman binding, > so to output the same RIB I'd write: > > RiWorldBegin() > RiColor(1.0,1.0,1.0) > RiSurface('constant') > RiSphere(1.0,-1.0,1.0,360) > RiWorldEnd() > > But I get an error, because python interprets my indentation > as a block in the python code. So the only way to write this > is without the indentation: > > RiWorldBegin() > RiColor(1.0,1.0,1.0) > RiSurface('constant') > RiSphere(1.0,-1.0,1.0,360) > RiWorldEnd() > > But this is a lot harder to read. > > Is there any way to use such "visual" indentation in python? I'm sending this again as the message I sent earlier apparently never made it. RiWorldBegin() ( RiColor(1.0,1.0,1.0), RiSurface('constant'), RiSphere(1.0,-1.0,1.0,360), ) RiWorldEnd() There's a bit of added overhead (superfluous tuple creation) but it does what you ask. Regards, Cliff -- Should I stand midst the breakers, Should I lie with Death my bride? -This Mortal Coil From http Sun Aug 3 21:23:13 2003 From: http (Paul Rubin) Date: 03 Aug 2003 18:23:13 -0700 Subject: Example code for anydbm wanted... References: Message-ID: <7x8yqa8bcu.fsf@ruckus.brouhaha.com> "John D." writes: > Does anyone have any good example code that shows how to use the > "anydbm" wrapper tp interface with a very simple database. like > some examples of how to use "dumbdbm"? Then perhaps at a later > time, I'm going to want to then interface it to a more robust > database like PostGreSQL or mySQL. But I want to external interface > to "hide" the specifics and have a really generic interface. I think using anydbm isn't wise because it makes a completely indeterminate choice of what underlying database library to call. I used it in a Python 1.5.2 script and later the machine it ran on had an OS upgrade. The result was that anydbm switched to using an incompatible dbm library and my script broke and I had to do contorted things to get it working again. If you don't want to use particular features of a specific dbm library (and deal with the headaches of handling upgrades to that library), it's probably better to just use dumbdbm. If dumbdbm's performance is really awful, then dumbdbm should be fixed. From aleax at aleax.it Fri Aug 29 10:49:32 2003 From: aleax at aleax.it (Alex Martelli) Date: Fri, 29 Aug 2003 14:49:32 GMT Subject: method (a, b = '', *c, **d): gets a syntax error? References: <3F4F644D.2060003@uni-bonn.de> Message-ID: <0KJ3b.9551$aG6.309676@news1.tin.it> Andreas Neudecker wrote: > Hello. > > I am relatively new to Python and I have a strange problem with some > code. In a class the __call__ method gets parameters like this: > > > class WhatsUp: > __call__ ( You're missing the keyword 'def' here, right before the method name. Alex From harry.g.george at boeing.com Mon Aug 25 15:01:28 2003 From: harry.g.george at boeing.com (Harry George) Date: Mon, 25 Aug 2003 19:01:28 GMT Subject: Help embedding python References: Message-ID: Zora Honey writes: > My husband and I are writing a program that does a lot of math behind > the scenes (c++) with a gui front (python/Tkinter). We've decided > that we want the c++ to be the "driver", and so we want to embed the > python. We are not stupid people, and we've already searched this > newsgroup and the web at large for help, but we're having a heck of a > time trying to do this. > > We're using Python 2.2 and Mark Lutz' "Programming Python" as a > guide. Unfortunately, the code in there is a little out of date > (loading certain libraries), and we haven't been able to get any > examples to work (we even tried downloading the version he uses in the > book, but it fails on the build). > > So I'm wondering if someone out there has, or would be kind enough to > create, a very simple ("hello world" type) program with Makefile that > works under 2.2. > > I will be very grateful, as it is my job to do the graphics, so if I > can't get python working, I'll have to learn another language... > > Thanks, > Zora > I'm no expert but we do have such code working here. We took these steps: 1. Make a normal "extension" wrapper for at least some of your C++ code. That way the python can call C++ functions and objects. See Boost, SIP, SWIG, or handcoding for this. (Otherwise python is blind, deaf, and dumb to the rest of your app.) 2. Embed the python interpreter in your C++ code where it can be accessed. First, in the startup code (e.g., before calling the main C++ loop), initialize the interpreter. Second, from wherever you want to initial a specific python action, hook in the code to call that interpreter with the needed triggers (e.g., the name of the python module or function to be called). 3. Because the C++ owns the main loop, and because python interpreter really ought to own it, we had to do threads and locks to get it all to work. It was a debugging nightmare for a while. In other words, this can be done, but it is wrong headed. If we were to do it again, all of us on the project agree we'd do python as the main loop (with PyQT in our case), and call C++ extensions as needed for performance. -- harry.g.george at boeing.com 6-6M31 Knowledge Management Phone: (425) 342-5601 From aleax at aleax.it Wed Aug 6 18:08:35 2003 From: aleax at aleax.it (Alex Martelli) Date: Wed, 06 Aug 2003 22:08:35 GMT Subject: crossplatform py2exe - would it be useful? References: Message-ID: Thomas Heller wrote: > I'm currently working on a new version of py2exe, which will require > Python 2.3 and later, because it uses the zipimport mechanism. > > Since py2exe is a distutils extension, and since C compilers are > commonly available on most platforms except Windows, it would be fairly > easy to let py2exe generate a C source file installing this import hook, > and let distutils' C compiler build an executable file from this. > > Would this be useful, or would I be wasting my time, since McMillan > installer, cx_freeze, and tools/freeze already do it? I think it would be a WONDERFUL idea: py2exe is the simplest to use of all the tools you mention, and it would save a lot of ink^H^H^H pixels, each time I point people to it, to be able to omit the blurb about "if you're interested in deploying to Windows platform only, then"...:-). Alex From jacek.generowicz at cern.ch Fri Aug 22 17:07:21 2003 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 22 Aug 2003 23:07:21 +0200 Subject: For Kenny Tilton: Why do I need macros revisited. References: <3f45484f$1_6@corp.newsgroups.com> <3F45A7BF.4060806@nyc.rr.com> <8dk1b.2825$Ej6.1159@newsread4.news.pas.earthlink.net> <40udnfEuVojnr9uiXTWJjg@comcast.com> Message-ID: "Terry Reedy" writes: > Until some advocate of a Python macro facility adds more detail to the > proposal beyound 'Lisp/Scheme-like maco facility', it is really hard > for someone like me, who has used neither, to have much of any > concrete idea of what is being proposed. Until some advocate of a Python macro facility adds more detail to the proposal ... it is really hard for me to have much of any concrete idea what is being proposed ... because Lisp-style macros rely on the fact that Lisp code is expressed in a fundamental Lisp data structure, in the form of its parse tree. This ain't the case in Python, so the whole macro business suddenly gets more complicated by an order of magnitude or two. I just can't imagine what such a macro system would look like. Maybe someone with deep knowledge of Dylan can enlighten us. From mpeuser at web.de Tue Aug 19 12:42:19 2003 From: mpeuser at web.de (Michael Peuser) Date: Tue, 19 Aug 2003 18:42:19 +0200 Subject: python for non-programmers tutorial? References: Message-ID: "Anthony Baxter" schrieb im Newsbeitrag news:mailman.1061266650.12641.python-list at python.org... > > I'm writing a half-day tutorial at work for the non-programmer techies > (network engineers, database admins, sysadmins, that sort of thing) > and was wondering if anyone else has already done this and made their > materials available? Have a look at: www.pauahtun.org/TYPython/ Ivan Van Laningham: Teach Yourself Python in 24 Hours "....This book's primary aim is to teach you how to program. Only secondarily does it aim to teach you Python, perhaps the coolest programming language on the planet. You don't need to know any programming before you begin; all you need is the desire to learn. ..." Everything online. Kindly Michael P From glenfant at NOSPAM.bigfoot.com Fri Aug 1 06:29:18 2003 From: glenfant at NOSPAM.bigfoot.com (Gilles Lenfant) Date: Fri, 1 Aug 2003 12:29:18 +0200 Subject: HTML DOM parser? References: <7x7k5y5wfh.fsf_-_@ruckus.brouhaha.com> Message-ID: mailto:gilles at pilotsystems.net "Paul Rubin" a ?crit dans le message de news: 7x7k5y5wfh.fsf_-_ at ruckus.brouhaha.com... > Is there an HTML DOM parser available for Python? Preferably one that > does a reasonable job with the crappy HTML out there on real web > pages, that doesn't get upset about unterminated tables and stuff like > that. Many extra points if it understands Javascript. Application is > a screen scraping web robot. Thanks. Windoze IE5(+) + Win32All python package only : Use IE as COM object, browse the file or URL, then, get it's DOM root. But any javascript found in that page is executed at page load and may fool your app. --Gilles From tim at lesher.ws Sun Aug 17 16:00:48 2003 From: tim at lesher.ws (Tim Lesher) Date: 17 Aug 2003 13:00:48 -0700 Subject: bitwise not - not what I expected References: Message-ID: Graham Fawcett wrote in message news:... > Tim Peters wrote: > >You're only overlooking the consequences of an infinite amount of > >information . > > > > > Excellent line! [...] > It may need to be accompanied by a smoldering, wide-eyed > Rasputin-ish stare, however, or it might lack the necessary mystique to > supress any further questions. Somehow, I associated it with a smoldering, wide-eyed Tom Baker-ish stare. To each his own. -- Tim Lesher tim at lesher.ws From dave at nullcube.com Tue Aug 5 18:49:35 2003 From: dave at nullcube.com (Dave Harrison) Date: Wed, 6 Aug 2003 08:49:35 +1000 Subject: MySQLdb and egenix mxDateTime dumps core Message-ID: <20030805224935.GA7194@dave@alana.ucc.usyd.edu.au> Hi all, got a problem combinging mx and MySQLdb, when I build and install both for my Python2.1 install on a Solaris 9 box I can import mx fine, but importing MySQLdb causing python to core dump. I am using egenenix 2.0.4 and MySQLdb 0.9.2. I have also replaced the -shared flag in the Makefile is /usr/local/lib/Python2.1/config with -G (a recommended solaris change to let the build of the modules work in the first place) -> notably I also made sure I recompiled python from source using this flag in the makefile too. I plead guilty to not knowing a heap about debugging linking etc etc, tho I do know a bit of C. Any help is REALLY REALLY appreciated ;-) this problem is just sending me right round the bend ;-) cheers Dave Here is a transcription of the trace from the core dump : #0 mxDateTime_New () at mx/DateTime/mxDateTime/mxDateTime.c:279 #1 0xff01396c in mxDateTime_FromDateAndTime (year=-5851455, month=-4217812, day=3, hour=680236, minute=1096156, second=0) at mx/DateTime/mxDateTime/mxDateTime.c:952 #2 0xff018b1c in mxDateTime_DateTime (self=0x0, args=0xffa6b6c1) at mx/DateTime/mxDateTime/mxDateTime.c:3667 #3 0x22858 in call_cfunction (func=0xfc568, arg=0x101e6c, kw=0x0) at Python/ceval.c:2854 #4 0x207a4 in eval_code2 (co=0x115cc0, globals=0x0, locals=0xfc568, args=0x10c164, argcount=0, kws=0xe1050, kwcount=0, defs=0x0, defcount=0, closure=0xfc568) at Python/ceval.c:1948 #5 0x1da3c in PyEval_EvalCode (co=0x0, globals=0xc3ddc, locals=0x3) at Python/ceval.c:341 #6 0x322f4 in PyImport_ExecCodeModuleEx (name=0xffbfb118 "mx.DateTime.DateTime", co=0x115cc0, pathname=0xffbfa738 "/usr/local/lib/python2.1/site-packages/mx/DateTime/DateTime.pyc") at Python/import.c:490 #7 0x328d8 in load_source_module (name=0xffbfb118 "mx.DateTime.DateTime", pathname=0xffbfa738 "/usr/local/lib/python2.1/site-packages/mx/DateTime/DateTime.pyc", fp=0x115cc0) at Python/import.c:754 #8 0x33184 in load_module (name=0xffbfb118 "mx.DateTime.DateTime", fp=0xb4038, buf=0xffbfac28 "/usr/local/lib/python2.1/site-packages/mx/DateTime/DateTime.py", type=1) at Python/import.c:1301 #9 0x33fe8 in import_submodule (mod=0xb54fc, subname=0xffbfb124 "DateTime", fullname=0xffbfb118 "mx.DateTime.DateTime") at Python/import.c:1829 #10 0x33b68 in load_next (mod=0xb54fc, altmod=0xa6cd8, p_name=0xffbfb124, buf=0xffbfb118 "mx.DateTime.DateTime", p_buflen=0xffbfb114) at Python/import.c:1685 #11 0x33738 in import_module_ex (name=0x0, globals=0xb54fc, locals=0x100664, fromlist=0xffbd4) at Python/import.c:1536 #12 0x33910 in PyImport_ImportModuleEx (name=0xfa564 "DateTime", globals=0x100664, locals=0x100664, fromlist=0xffbd4) at Python/import.c:1577 #13 0x77254 in builtin___import__ (self=0x0, args=0xfa564) at Python/bltinmodule.c:31 #14 0x22858 in call_cfunction (func=0xb5ce0, arg=0x1032d4, kw=0x0) at Python/ceval.c:2854 #15 0x227bc in call_object (func=0xb5ce0, arg=0x1032d4, kw=0x0) at Python/ceval.c:2807 #16 0x22548 in PyEval_CallObjectWithKeywords (func=0xb5ce0, arg=0x1032d4, kw=0x0) at Python/ceval.c:2740 #17 0x20124 in eval_code2 (co=0x103df0, globals=0x0, locals=0x100664, args=0xfd749, argcount=0, kws=0x1032d4, kwcount=0, defs=0x0, defcount=0, closure=0xb5ce0) at Python/ceval.c:1820 #18 0x1da3c in PyEval_EvalCode (co=0x0, globals=0xffbd4, locals=0xb5ce0) at Python/ceval.c:341 #19 0x322f4 in PyImport_ExecCodeModuleEx (name=0xffbfc830 "mx.DateTime", co=0x103df0, pathname=0xffbfb960 "/usr/local/lib/python2.1/site-packages/mx/DateTime/__init__.pyc") at Python/import.c:490 #20 0x328d8 in load_source_module (name=0xffbfc830 "mx.DateTime", pathname=0xffbfb960 "/usr/local/lib/python2.1/site-packages/mx/DateTime/__init__.pyc", fp=0x103df0) at Python/import.c:754 #21 0x33184 in load_module (name=0xffbfc830 "mx.DateTime", fp=0xb4028, buf=0xffbfbe50 "/usr/local/lib/python2.1/site-packages/mx/DateTime/__init__.py", type=1) at Python/import.c:1301 #22 0x32ae8 in load_package (name=0xffbfc830 "mx.DateTime", pathname=0xfd500 "") at Python/import.c:811 #23 0x331f0 in load_module (name=0xffbfc830 "mx.DateTime", fp=0x0, buf=0xffbfc340 "/usr/local/lib/python2.1/site-packages/mx/DateTime", type=5) at Python/import.c:1324 #24 0x33fe8 in import_submodule (mod=0xb551c, subname=0xffbfc833 "DateTime", fullname=0xffbfc830 "mx.DateTime") at Python/import.c:1829 #25 0x33b68 in load_next (mod=0xb551c, altmod=0xb551c, p_name=0xffbfc833, buf=0xffbfc830 "mx.DateTime", p_buflen=0xffbfc82c) at Python/import.c:1685 #26 0x33874 in import_module_ex (name=0x0, globals=0xb551c, locals=0xfe744, fromlist=0xd2764) at Python/import.c:1543 #27 0x33910 in PyImport_ImportModuleEx (name=0x10052c "mx.DateTime", globals=0xfe744, locals=0xfe744, fromlist=0xd2764) at Python/import.c:1577 #28 0x77254 in builtin___import__ (self=0x0, args=0x10052c) at Python/bltinmodule.c:31 #29 0x22858 in call_cfunction (func=0xb5ce0, arg=0xfe77c, kw=0x0) at Python/ceval.c:2854 #30 0x227bc in call_object (func=0xb5ce0, arg=0xfe77c, kw=0x0) at Python/ceval.c:2807 #31 0x22548 in PyEval_CallObjectWithKeywords (func=0xb5ce0, arg=0xfe77c, kw=0x0) at Python/ceval.c:2740 #32 0x20124 in eval_code2 (co=0x1006d8, globals=0x0, locals=0xfe744, args=0xfa87b, argcount=0, kws=0xfe77c, kwcount=0, defs=0x0, defcount=0, closure=0xb5ce0) at Python/ceval.c:1820 #33 0x1da3c in PyEval_EvalCode (co=0x0, globals=0xd2764, locals=0xb5ce0) at Python/ceval.c:341 #34 0x322f4 in PyImport_ExecCodeModuleEx (name=0xffbfda58 "MySQLdb.times", co=0x1006d8, pathname=0xffbfd078 "/usr/local/lib/python2.1/site-packages/MySQLdb/times.pyc") at Python/import.c:490 #35 0x328d8 in load_source_module (name=0xffbfda58 "MySQLdb.times", pathname=0xffbfd078 "/usr/local/lib/python2.1/site-packages/MySQLdb/times.pyc", fp=0x1006d8) at Python/import.c:754 #36 0x33184 in load_module (name=0xffbfda58 "MySQLdb.times", fp=0xb4018, buf=0xffbfd568 "/usr/local/lib/python2.1/site-packages/MySQLdb/times.py", type=1) at Python/import.c:1301 #37 0x33fe8 in import_submodule (mod=0xb52fc, subname=0xffbfda60 "times", fullname=0xffbfda58 "MySQLdb.times") at Python/import.c:1829 #38 0x33b68 in load_next (mod=0xb52fc, altmod=0xb52fc, p_name=0xffbfda60, buf=0xffbfda58 "MySQLdb.times", p_buflen=0xffbfda54) at Python/import.c:1685 #39 0x33874 in import_module_ex (name=0x0, globals=0xb52fc, locals=0xc10d4, fromlist=0xc6adc) at Python/import.c:1543 #40 0x33910 in PyImport_ImportModuleEx (name=0xb9fe4 "MySQLdb.times", globals=0xc10d4, locals=0xc10d4, fromlist=0xc6adc) at Python/import.c:1577 #41 0x77254 in builtin___import__ (self=0x0, args=0xb9fe4) at Python/bltinmodule.c:31 #42 0x22858 in call_cfunction (func=0xb5ce0, arg=0xc85bc, kw=0x0) at Python/ceval.c:2854 #43 0x227bc in call_object (func=0xb5ce0, arg=0xc85bc, kw=0x0) at Python/ceval.c:2807 #44 0x22548 in PyEval_CallObjectWithKeywords (func=0xb5ce0, arg=0xc85bc, kw=0x0) at Python/ceval.c:2740 #45 0x20124 in eval_code2 (co=0xc8130, globals=0x0, locals=0xc10d4, args=0xb96b1, argcount=0, kws=0xc85bc, kwcount=0, defs=0x0, defcount=0, closure=0xb5ce0) at Python/ceval.c:1820 #46 0x1da3c in PyEval_EvalCode (co=0x0, globals=0xc6adc, locals=0xb5ce0) at Python/ceval.c:341 #47 0x322f4 in PyImport_ExecCodeModuleEx (name=0xffbff170 "MySQLdb", co=0xc8130, pathname=0xffbfe2a0 "/usr/local/lib/python2.1/site-packages/MySQLdb/__init__.pyc") at Python/import.c:490 #48 0x328d8 in load_source_module (name=0xffbff170 "MySQLdb", pathname=0xffbfe2a0 "/usr/local/lib/python2.1/site-packages/MySQLdb/__init__.pyc", fp=0xc8130) at Python/import.c:754 #49 0x33184 in load_module (name=0xffbff170 "MySQLdb", fp=0xb4008, buf=0xffbfe790 "/usr/local/lib/python2.1/site-packages/MySQLdb/__init__.py", type=1) at Python/import.c:1301 #50 0x32ae8 in load_package (name=0xffbff170 "MySQLdb", pathname=0xc6a68 "") at Python/import.c:811 #51 0x331f0 in load_module (name=0xffbff170 "MySQLdb", fp=0x0, buf=0xffbfec80 "/usr/local/lib/python2.1/site-packages/MySQLdb", type=5) at Python/import.c:1324 #52 0x33fe8 in import_submodule (mod=0xa6cd8, subname=0xffbff170 "MySQLdb", fullname=0xffbff170 "MySQLdb") at Python/import.c:1829 #53 0x33b68 in load_next (mod=0xa6cd8, altmod=0xa6cd8, p_name=0xffbff170, buf=0xffbff170 "MySQLdb", p_buflen=0xffbff16c) at Python/import.c:1685 #54 0x33738 in import_module_ex (name=0x0, globals=0xa6cd8, locals=0xb6fc4, fromlist=0xa6cd8) at Python/import.c:1536 #55 0x33910 in PyImport_ImportModuleEx (name=0xd1f14 "MySQLdb", globals=0xb6fc4, locals=0xb6fc4, fromlist=0xa6cd8) at Python/import.c:1577 #56 0x77254 in builtin___import__ (self=0x0, args=0xd1f14) at Python/bltinmodule.c:31 #57 0x22858 in call_cfunction (func=0xb5ce0, arg=0xba9e4, kw=0x0) at Python/ceval.c:2854 #58 0x227bc in call_object (func=0xb5ce0, arg=0xba9e4, kw=0x0) at Python/ceval.c:2807 #59 0x22548 in PyEval_CallObjectWithKeywords (func=0xb5ce0, arg=0xba9e4, kw=0x0) at Python/ceval.c:2740 #60 0x20124 in eval_code2 (co=0xc0f40, globals=0x0, locals=0xb6fc4, args=0xb9ec0, argcount=0, kws=0xba9e4, kwcount=0, defs=0x0, defcount=0, closure=0xb5ce0) at Python/ceval.c:1820 #61 0x1da3c in PyEval_EvalCode (co=0x0, globals=0xa6cd8, locals=0xb5ce0) at Python/ceval.c:341 #62 0x3ab0c in run_node (n=0xb51f0, filename=0xb6fc4 "", globals=0xb6fc4, locals=0xb6fc4, flags=0xb6fc4) at Python/pythonrun.c:1045 #63 0x39908 in PyRun_InteractiveOneFlags (fp=0xffffffff, filename=0x7d4f8 "", flags=0xffbffb3c) at Python/pythonrun.c:570 #64 0x39704 in PyRun_InteractiveLoopFlags (fp=0xb3fd8, filename=0x7d4f8 "", flags=0xffbffb3c) at Python/pythonrun.c:510 #65 0x3966c in PyRun_AnyFileExFlags (fp=0xb3fd8, filename=0x7d4f8 "", closeit=0, flags=0xffbffb3c) at Python/pythonrun.c:473 #66 0x19b90 in Py_Main (argc=1, argv=0xffbffbb4) at Modules/main.c:320 From jjl at pobox.com Tue Aug 12 08:01:26 2003 From: jjl at pobox.com (John J. Lee) Date: 12 Aug 2003 13:01:26 +0100 Subject: Multi-Line Comment References: <4qofjvg3bh9smlnb1do4f0lhjga7bacnu3@4ax.com> <87y8xzvhst.fsf@pobox.com> <7iekzr2m3q.fsf@enark.csis.hku.hk> Message-ID: <874r0nult5.fsf@pobox.com> Isaac To writes: > >>>>> "John" == John J Lee writes: [...] > John> I use C-x r k to uncomment (kill-rectangle), but I'm sure there > John> must be an uncomment-region in there somewhere... > > Just do C-u C-c # D'oh! John From guettler at thomas-guettler.de Tue Aug 19 07:08:36 2003 From: guettler at thomas-guettler.de (Thomas =?ISO-8859-15?Q?G=FCttler?=) Date: Tue, 19 Aug 2003 13:08:36 +0200 Subject: httplib usage for images References: Message-ID: berklee just berklee wrote: > I have an ASP page which is returning a chart image that's being > dynamically generated (by writing to the response object). > > When I try and access that page with httplib (to download said image), I > keep encountering an HTTP1.1 server error. However, I've tried the same > URL in Internet Explorer and Mozilla with no problems at all. > > Is there a possibility that it could be the httplib module causing the > error? If so, anyone have a suggested workaround? Maybe you need to add a slash to your url. Example: Your browser redirects you from http://www.python.org/doc to http://www.python.org/doc/ If this does not help, please send the error message of httplib thomas From tim.one at comcast.net Sun Aug 3 13:14:05 2003 From: tim.one at comcast.net (Tim Peters) Date: Sun, 3 Aug 2003 13:14:05 -0400 Subject: time, calendar, datetime, etc In-Reply-To: Message-ID: [Dan Bishop] > There were no leap years between 10 BC and AD 4, because after Julius > Caesar's death, the priests in charge of the calendar mistakenly added > leap days every 3 years instead of 4, and this had to be corrected. > > I wouldn't expect the datetime module to deal with that, though ;-) Thank you -- some people did . > ... > >>> datetime.date(1970, 8, 22).weekday() > 5 > >>> datetime.date(6970, 8, 22).weekday() > 5 > > The output above is my least favorite feature of the datetime module. > It took me a while to figure out that those dates are Saturdays. That's very peculiar! Because they're not both Saturdays: >>> datetime.date(1970, 8, 22).weekday() 5 >>> datetime.date(6970, 8, 22).weekday() 2 >>> Or if you want names instead: >>> datetime.date(1970, 8, 22).ctime()[:3] 'Sat' >>> datetime.date(6970, 8, 22).ctime()[:3] 'Wed' >>> Did you actually run the example you pasted, or just assume that the second line would display 5 too, or didn't paste the actual example you ran and made a typo? The earlier claim: > The Gregorian leap year cycle is 400 years and this is coincidentally > also a whole number of weeks. was correct, but the 5000 years between 1970 and 6970 isn't a multiple of 400, so the example as given wasn't relevant to that claim. > Perhaps we could add a weekday class to 2.3.1? > > DAY_NAMES = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', > 'Saturday', 'Sunday'] > class weekday(int): > def __repr__(self): > return DAY_NAMES[self] > for i, name in enumerate(DAY_NAMES): > globals()[name] = weekday(i) I doubt anything like this will get added, in part because we have the unfortunate fact that .weekday() and .isoweekday() map day names into little integers differently. As shown above, you can easily get English day names (well, abbreviations) from the .ctime() result. A .strftime() format works too, except .strftime() has irritating year-range limitations inherited from C. I have a little dateutil.py module I use for my own stuff, containing MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY = range(7) (JANUARY, FEBRUARY, MARCH, APRIL, MAY, JUNE, JULY, AUGUST, SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER) = range(1, 13) at the start. That's easy, and caters to that (1) I'm unlikely ever to use .isoweekday(); and, (2) after decades of practice, I'm comfortable with the English names for these things. It's much easier to do something similar for yourself than to try to define a gimmick that covers the union of all peoples' crazy ideas . From margerum at yahoo.com Tue Aug 19 12:12:50 2003 From: margerum at yahoo.com (Mike Margerum) Date: 19 Aug 2003 09:12:50 -0700 Subject: win32com and com Record types Message-ID: Hi I am trying to using a COM server I built in C++. I ran GenPy on my type library and I am able to instantiate objects from the server. What I can't figure out is how to create/use Record types from my COM server. I see them defined in my generated py file as a map RecordMap = { 'FormRecord': '{F6EBBC2A-E2D5-4921-A498-EA80AE851012}', 'ICD9Record': '{FA83723F-55F6-4D17-8309-A9D323A4FD01}', 'BrandRecord': '{AD4B5647-E78A-447B-A041-EEC59E89D3F6}', } How Do i instantiate one so I can use it in one of my methods that takes a BrandRecord by reference? This is a snippet of VB code that works Dim db As New BrandDb db.Open ("c:\temp\irx2_brand.pdb") Dim brandRec As BrandRecord While i < db.RecordCount db.GetBrand i, brandRec, 1 'use 0 instead of 1 to not load form data List1.AddItem brandRec.MasterIndex & " " & brandRec.Id & " " & brandRec.Description This is my python code that is working minus the GetBrand call from win32com.client import * from PDBUtils import * db = BrandDb() print db.Version db.Open(r"c:\temp\irx2_brand.pdb") for i in range(0,db.RecordCount): print i Thanks a lot for the help. From avner at skilldesign.com Sat Aug 30 05:21:15 2003 From: avner at skilldesign.com (Avner Ben) Date: Sat, 30 Aug 2003 11:21:15 +0200 Subject: Pyhton 2.3 does not work References: <3f504a34$1@news.012.net.il> Message-ID: <3f505f0a@news.012.net.il> "Avner Ben" wrote in message news:3f504a34$1 at news.012.net.il... > I need help with Python 2.3 installation in Windows. > > I installed Python 2.3 on both my computers (one running Windows XP and the > other running Windows 98), after first uninstalling Python 2.2.3. In both > computers, Python 2.3. keeps looking for "python22.dll" and would not work. > This happens when running IDLE and when running python.exe and trying to > import anything. > > I removed all mentions of pyhton22.dll from the registry and repaired it > (with Registry Mechanic) - no help. > I looked at PYTHONPATH and it has no mention of python22. > > Obviously, there is something left in my configurations that uninstalling > 2.2.3 would not amend. > > The only extensions to Python installed earlier were py2exe and wxPython. I > took care to uninstall them first. > > Any suggestions what to look for? > Ok, I've found the problem, and it may be of interest to some. The culprit was SET PYTHONPATH command in the autoexec.bat file. Since I prefer not to put my (bulky) development stuff in the Python distribution directory, I have used this DOS command - based a long time ago upon the then current Python documentation - to direct Python to look for import modules in my development directories as well. This has worked fine for all Python versions up to and including 2.2.3. But then, with Python 2.3, it turns out to destroy the contents of sys.path, apparently leading the dll loader astray. I guess the current autoexec could be fixed somehow, but, instead, I followed the current Python documentation's advice to put the additional module directories in a .pth file in the site-packages directory - and it works fine. It also looks better! I would recommend that the Python 23 Windows installer look for the presence of "SET PYTHONPATH" in the autoexec.bat and, at least, issue a warning! Avner. From jjl at pobox.com Wed Aug 13 08:34:16 2003 From: jjl at pobox.com (John J. Lee) Date: 13 Aug 2003 13:34:16 +0100 Subject: drop down feature References: <87k79hdff9.fsf@pobox.com> Message-ID: <871xvppwhj.fsf@pobox.com> "Michael Peuser" writes: > "John J. Lee" schrieb im Newsbeitrag > news:87k79hdff9.fsf at pobox.com... [...] > > "Michael Peuser" writes: > > GUI builder: > > wxPython / BOA constructor > > OR PyQt / Qt designer > > OR VB (implement COM servers in Python, write GUI in VB) > > > > exe builder: > > py2exe > > OR McMillan Installer > > > Yes, yes, yes! But when you are new to a language like Python, it is VERY > DIFFICULT for you to find out, WHICH tool to use and WHICH library to > download. Especially if they are not free as some of the better products you [...] Such is life. I'd rather have a choice between Qt, wx and VB than between VB, VB and VB. > > "drag-n-drop and multimedia stuff" > > Not sure what that means! > > A modern GUI is expected to support OS wide Drag and Drop. E.g. an IDE [...] > Strictly both features have nothing to do with the discussion. They came to [...] Nothing to do with Python, either. John From rmichael at NOfields.SPAMutoronto.ca Mon Aug 18 22:25:12 2003 From: rmichael at NOfields.SPAMutoronto.ca (Richard Michael) Date: Tue, 19 Aug 2003 02:25:12 GMT Subject: Newbie: explanation of PrivoxyWindowOpen; website docs outdated? In-Reply-To: References: Message-ID: Joe Francia wrote: > Richard Michael wrote: > > I've been reading the Python docs, and the 6.1.3 File Objects section of > >> the Library Reference indicates that instead of "open()", I should use >> the builtin function "PrivoxyWindowOpen()" instead. > > > As you suspected, this has nothing to do with Python or the Python.org > website - it is Privoxy replacing all instances of open() with > PrivoxyWindowOpen() to squash pop-up advertisements and such. Just add > .python.org to your whitelist and you'll be OK. (browse to > http://config.privoxy.org/ to bring up the configuration page). > > jf > Oh my dear. Now this is an embarassing situation. Well, I guess I've gotta laugh. :) I didn't realize Privoxy would do this. I guess context handling by Privoxy would be lots of work. It also why explains why 'PrivoxyWindowOpen()' didn't turn up in any newsgroups or in the local documentation! (I don't think I was ever viewing the copies of identical document both locally and online for comparison.) A bit sad that I didn't think this could have actually been realtime interference by Privoxy! :( Thanks Joe. Richard From simonb at webone.com.au Mon Aug 11 20:04:30 2003 From: simonb at webone.com.au (Simon Burton) Date: Tue, 12 Aug 2003 10:04:30 +1000 Subject: stretching list comprehensions References: Message-ID: On Mon, 11 Aug 2003 16:44:52 -0700, David Eppstein wrote: > In article , > Simon Burton wrote: > >> >>> del y >> >>> nums = [ x+y for x in range(y) for y in range(10) ] >> Traceback (most recent call last): >> File "", line 1, in ? >> NameError: name 'y' is not defined >> >>> >> >> Well.. Is there an inherent reason why this could/should not be made to work? >> > > It does work with the loops in the opposite order: > Aha! It seems the wrong order to my "innermost first" mind. Guess i'm changing that now. Thanks, Simon. From mpeuser at web.de Fri Aug 29 13:33:49 2003 From: mpeuser at web.de (Michael Peuser) Date: Fri, 29 Aug 2003 19:33:49 +0200 Subject: python and webcam?? References: <3F4F56AB.19EFE5AB@engcorp.com> <3F4F6A31.1598071A@engcorp.com> Message-ID: "Peter Hansen" schrieb im Newsbeitrag news:3F4F6A31.1598071A at engcorp.com... > Mike Kier wrote: > > > > Try this... > > http://videocapture.sourceforge.net/ > > Ah, that's the one. Uses it's own .pyd actually, not calldll as I > thought. > > Doesn't work with my webcam though. Might help if the OP could specify > what he has. > Works fine with my lowcost cam (AIPTEK 3M). USB Driver from AIPTEK installed - no problems with VideoCapture. Have you tried the AMCAP.EXE in folder AMCAP? This is not Pytthon but checks the same interface... Kindly Michael From jzgoda at gazeta.usun.pl Fri Aug 22 18:31:13 2003 From: jzgoda at gazeta.usun.pl (Jarek Zgoda) Date: Fri, 22 Aug 2003 22:31:13 +0000 (UTC) Subject: [OT] Why is it called string? References: <3f44ce77$0$556$b45e6eb0@senator-bedfellow.mit.edu> <3F44DBF2.1010403@draigBrady.com> <3f453a22$1_1@themost.net> Message-ID: Paul Watson pisze: > My CS professor would insist that a byte is a collection of bits, and not > necessarily eight. There are machines which do not have 8-bit addressable > bytes. I remember that "byte" in French is expressed as "octet", even if it has only 7 bits... -- Jarek Zgoda Registered Linux User #-1 http://www.zgoda.biz/ JID:zgoda at chrome.pl http://zgoda.jogger.pl/ From michael.kier at hp.com Thu Aug 14 13:32:10 2003 From: michael.kier at hp.com (Mike Kier) Date: Thu, 14 Aug 2003 17:32:10 GMT Subject: 3 new slogans References: Message-ID: "My code doesn't run... ...It slithers! - Python" -- Mike Kier HP Consulting & Integration Services Cincinnati, OH, USA mike.kier at hp.com From achalk at XXXmagnacartasoftware.com Sun Aug 3 14:52:20 2003 From: achalk at XXXmagnacartasoftware.com (Andrew Chalk) Date: Sun, 03 Aug 2003 18:52:20 GMT Subject: 'print' in a CGI app. Message-ID: In a Python 2.2 app. running under CGI the statements print "Hello\n" print "World" print both words on the same line in IE6. How do I print the second one on a new line (i.e. respect the \n in the first statement). Many thanks! From newsgroups at jhrothjr.com Tue Aug 26 19:42:40 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Tue, 26 Aug 2003 19:42:40 -0400 Subject: String find and replace References: Message-ID: "hokieghal99" wrote in message news:bigq2u$p23$1 at solaris.cc.vt.edu... > import os, string > print " " > setpath = raw_input("Enter the path: ") > def find_replace(setpath): > for root, dirs, files in os.walk(setpath): > fname = files > for fname in files: > find = string.find(file(os.path.join(root,fname), > 'rb').read(), 'THIS') > print find > if find >=1: > replace = string.replace(str, 'THIS', 'THAT') > find_replace(setpath) > print " " > > Why doesn't this work? I get this error: > > Traceback (most recent call last): > File "html_find_replace.py", line 12, in ? > find_replace(setpath) > File "html_find_replace.py", line 11, in find_replace > replace = string.replace(str, 'THIS', 'THAT') > File "/usr/local/lib/python2.3/string.py", line 370, in replace > return s.replace(old, new, maxsplit) > TypeError: expected a character buffer object what's "str" in line 11? John Roth > From dkuhlman at rexx.com Fri Aug 15 16:58:03 2003 From: dkuhlman at rexx.com (Dave Kuhlman) Date: Fri, 15 Aug 2003 13:58:03 -0700 Subject: Style in list comprehensions References: Message-ID: Tim Lesher wrote: > Suppose I have a list of objects and I want to call a method on > each. I can do the simple: > > for i in objs: > i.meth(arg1, arg2) > > or using list comprehensions: > > [i.meth(arg1, arg2) for i in objs] > > The second feels more Pythonic, but do I incur any overhead for > creating the list of results when I'm not going to use it? > Play fair. Your two scripts do not do the same thing. The script using list comprehension forms a list containing each of the results of applying meth to the items in the original list. If you do not need the resulting list, then use the for-loop. If you do need that list, then to make the two lists equivalent, you might modify the for-loop as follows: result = [] for i in objs: result.append(i.meth(arg1, arg2)) Now ask which is preferred. The script using list comprehension has the advantage of of possibly mystifying Perl programmers. They do enough of that to us Pythonista's, so it serves them right, don't you agree. Come to think about it, if you think it might mystify anyone, then it is un-Pythonic to write it that way. As to speed, my eyeballs could detect no difference with the following: def func1(x): return x*3 def t1(lst): return [func1(x) for x in lst] def t2(lst): result = [] for x in lst: result.append(func1(x)) return result a = t1(range(100000)) a = t2(range(100000)) Dave -- Dave Kuhlman http://www.rexx.com/~dkuhlman dkuhlman at rexx.com From peter at engcorp.com Tue Aug 12 07:30:59 2003 From: peter at engcorp.com (Peter Hansen) Date: Tue, 12 Aug 2003 07:30:59 -0400 Subject: Running Python 2.3 on a Windows 2000 network References: Message-ID: <3F38CFF3.DCD942F6@engcorp.com> Gerhard H?ring wrote: > > Python itself doesn't need any registry entries. If you use the COM > stuff of the win32 extensions, though, this might be different. One can get by without registry entries even there, with a little trickery. I've posted an example of such trickery a few weeks ago in the newsgroup... untested on 2K however, but working on networked Win98 machines and likely to work on 2K/XP as well. -Peter From gh at ghaering.de Tue Aug 5 20:44:29 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Wed, 06 Aug 2003 02:44:29 +0200 Subject: Making a def file from python23.lib for mingw32 In-Reply-To: References: Message-ID: <3F304F6D.9040205@ghaering.de> Travis Oliphant wrote: > Has anyone succeeded in making a usable def file from python23.lib so > that which can be used to compile extensions with mingw32? [...] The instructions in the Python distutils documentation (well, where is it, all I always do is %google python non-ms compiler ;-) worked fine for me for Python 2.3. Just be sure to copy python{major}{minor}.dll in the working directory before executing the commands there. -- Grhard From gerrit at nl.linux.org Fri Aug 29 03:45:34 2003 From: gerrit at nl.linux.org (Gerrit Holl) Date: Fri, 29 Aug 2003 09:45:34 +0200 Subject: OT: Celebrity advice (was: Advice to a Junior in High School?) In-Reply-To: References: Message-ID: <20030829074534.GA2567@nl.linux.org> Alex Martelli wrote: > People who don't want ID > cards to exist, don't want government DB's to be cross-linked, etc, > plead much the same case -- they prefer inefficient government (whose > inefficiencies may help terrorists and other criminals) to efficient > government (whose efficiency might allow more effective oppression). This is exactly true. The one extreme is called 'anarchy', the other is called 'totalitarism' (either Communism or Fascism). It is a political choice to find a balance. Of course, ID cards don't mean totalitarism, but extreme government control, or extreme "effective oppression", does. We don't want a state that controls everything. But we also don't want a state that controls nothing. Do I deserve a prize for the best 'open door' statement ;)? Gerrit. -- 4. If he satisfy the elders to impose a fine of grain or money, he shall receive the fine that the action produces. -- 1780 BC, Hammurabi, Code of Law -- Asperger Syndroom - een persoonlijke benadering: http://people.nl.linux.org/~gerrit/ Het zijn tijden om je zelf met politiek te bemoeien: http://www.sp.nl/ From me at privacy.net Fri Aug 1 23:14:32 2003 From: me at privacy.net (Luciano ES) Date: 2 Aug 2003 03:14:32 GMT Subject: Potentially important real-time on-line discussion References: Message-ID: Kyler Laird wrote on 01/08/03: > I'm going to do my best to try to get people to stop making such a > tight coupling between "open source" and "volunteers." Any ideas on > how to do it? I've found that when I say "Red Hat" some people seem > to nod as if they understand that there's nothing contradictory about > "commercial open source software." I think that another big question that strikes many companies is: "if I make the source available, what will stop anyone from compiling the source themselves and using it for free (illegally)?", or "if I make the source available, what will stop anyone from using some of my best ideas and becoming my competitor?" That kind of fear tends to result in rejection of the OS model or a further crave for protection, i.e. patents. I prefer living with closed source to living with more patents. And no patent would make any difference against illegitimate use of software (piracy). The protection provided by passwords and serial numbers is feeble, but most companies seem to be happy enough with it. I think Open Source is great, but it also seems to prefer to pretend that we live in an ideal world. We do not. Reality is brutal. Besides, RedHat is not the average case. They are like Yahoo and Microsoft in that they can afford to enforce certain ideas that most of the players cannot. -- Luciano ES WARNING: fake address on reply! (domain is obfuscated) Santos, SP - Brasil From eric.brunel at pragmadev.com Thu Aug 14 12:47:59 2003 From: eric.brunel at pragmadev.com (Eric Brunel) Date: Thu, 14 Aug 2003 18:47:59 +0200 Subject: Python/Tkinter/tk crash [long] References: Message-ID: Martin Franklin wrote: > On Thursday 14 August 2003 10:10 am, Eric Brunel wrote: >>There's a simple workaround, but with drawbacks: at the beginning of the >>__update method, if I do not destroy and re-create the Canvas, but simply >>empty its contents, the script works. But it keeps the commands declared >>created at the tcl level for the former bindings, so it silently eats up >>memory. >> > > > > does it still eat up memory if you, for example, change the top of the > __update method to: > > def __update(self): > if not self.__tabsCanvas: > self.__tabsCanvas = Canvas(self, bg=self.cget('background'), > height=self.__canvasHeight) > self.__tabsCanvas.grid(row=0, column=0, sticky='nswe') > self.__tabsCanvas.delete("all") Yes it does: the call to delete('all') on the canvas doesn't delete the callbacks registered at the tcl level for all the bindings done in the canvas. These commands are only deleted when the canvas itself is deleted. Consider the following script: --eatmem.py--------------------------- from Tkinter import * root = Tk() cnv = Canvas(root) cnv.pack() def spam(*w): print spam def eat(): cnv.delete(ALL) l = cnv.create_line(10, 10, 10, 30) cnv.tag_bind(l, '<1>', spam) root.after(100, eat) eat() root.mainloop() -------------------------------------- If you run it and monitor the size of the running process either with the task manager on Windows or a "ps -A -o vsz -o args | grep eatmem' on Linux, you'll notice the memory occupied by the program slowly but steadily grows (you'll have to wait a little before it starts growing). Remove the bind, and it doesn't happen anymore. The same happens for commands in menus: they're only deleted when the whole menu goes away, not when the entry having the command is deleted. If you know something that can be done about that, I'm interested! -- - Eric Brunel - PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com From abelikov72 at hotmail.com Fri Aug 29 02:17:04 2003 From: abelikov72 at hotmail.com (Afanasiy) Date: Fri, 29 Aug 2003 06:17:04 GMT Subject: Add two dicts References: <86ktkvkd05e88hu14hjudmfvbul7slfgkt@4ax.com> <3F4EDF7A.C9CF6DA3@alcyone.com> Message-ID: <0mrtkv8b1bnnk1v310kf3b8tmjo8d9higo@4ax.com> On Thu, 28 Aug 2003 22:07:06 -0700, Erik Max Francis wrote: >Afanasiy wrote: > >> Can I add two dicts in a way which is not cumbersome to the above % >> string >> operation? Is this another case of writing my own function, or does a >> builtin (or similar) already exist for this? > > combinedDict = aDict.copy() > combinedDict.update(anotherDict) > >If that's cumbersome, don't really know what you'd consider >non-cumbersome. Don't really know if you're asking, but : vars(self)+{'x':'123','y':'345'} I would consider that non-cumbersome. ;-) My only guess why that doesn't exist is that no one decided what to do on like keys. Use existing, overwrite, or throw exception (my preference). From ryanlowe0 at msn.com Fri Aug 22 19:05:52 2003 From: ryanlowe0 at msn.com (Ryan Lowe) Date: Fri, 22 Aug 2003 23:05:52 GMT Subject: crazy programming language thoughts References: <3f457487_7@corp.newsgroups.com> Message-ID: thanks for all the replies. i think the language i was thinking is lost amongst the hundreds of languages almost nobody has ever heard of. it doesnt really matter though, its the ideas that interest me. ive looked into so many languages recently, one thing is clear, ive only scratched the surface of different languages... i did look into some of the ones mentioned, specifically, COBOL and Applescript. i was more impressed with applescript, because i think you can expand the language that the interpreter understands (unlike COBOL) with some sort of 'dictionary,' though its a little hard to say at first glance, given the new-programmer-targeted documentation. it seemed a little wordy, like writing a sentence just to make an assignment when there is a perfectly good = sign for that :) "Paul D. Fernhout" wrote in message news:3f457487_7 at corp.newsgroups.com... > You may be thinking of Smalltalk. > http://www.smalltalk.org/ > although there are other languages with related phrasing (like in > HyperCard? and even COBOL?). > > The Python code: > > x = sin(10) + 50 * 20 * self.myfunctionXY(cos(30), 40) > > would be in Smalltalk something like: > > x := 10 sin + (50 * 20 * self myfunctionX: 30 cos y: 40). > i didnt look at smalltalk. stuff like this example turns me off a bit. why put the sin and cos AFTER the operand? ill try to look into it at some point, though. i have heard good things about it. From nushin2 at yahoo.com Thu Aug 7 18:39:34 2003 From: nushin2 at yahoo.com (nushin) Date: 7 Aug 2003 15:39:34 -0700 Subject: spawnv( ) or spawnl( ) do not launch a normal running process in Python 2.2.2? References: Message-ID: Thanks Jeff. Yes, i think it's the stdio buffering that causes P_NOWAIT act asif it's a P_WAIT. I wish an additional parameter could be added to spawnv( ) to toggle its stdout on/off. Regards, Nushin Jeff Epler wrote in message news:... > I don't see any problem with P_NOWAIT. Take the following for example: > > $ cat nushin.py > import os > > p = os.spawnvp(os.P_NOWAIT, 'sh', > ['sh', '-c', 'sleep 1; echo from spawnv']) > print "from program" > print "waitpid returns:", os.waitpid(p, 0) > $ python -u nushin.py > from program > waitpid returns:from spawnv > (2826, 0) > > Now, if the program completed very quickly, it's a coin-flip whether its > output would appear before "from program". In this case, I made sure > the program would take a really long time (1 second) to complete. > > When running without -u but not on a terminal, you might see > $ python nushin.py | cat > from spawnv > from program > waitpid returns: (2832, 0) > .. this is because the Python process has printed "from program", but > stdio buffering has kept it from actually being written to the output > yet. > > Here's what you see on a terminal without -u: > $ python nushin.py > from program > from spawnv > waitpid returns: (2835, 0) > This is the same thing you'd see if the program said > print "from program"; sys.stdout.flush() > > Jeff From cnetzer at sonic.net Mon Aug 25 01:39:58 2003 From: cnetzer at sonic.net (Chad Netzer) Date: Sun, 24 Aug 2003 22:39:58 -0700 Subject: visual indentation In-Reply-To: <3F466B56.7010101@zephyrfalcon.org> References: <3F466B56.7010101@zephyrfalcon.org> Message-ID: <1061789998.6148.8.camel@adsl-209.204.179.133.sonic.net> On Fri, 2003-08-22 at 12:13, Hans Nowak wrote: > Hilbert wrote: > But maybe somebody else has a better solution...? Another kinda ugly one: RiWorldBegin() ;\ RiColor(1.0,1.0,1.0) ;\ RiSurface('constant') ;\ RiSphere(1.0,-1.0,1.0,360) ;\ RiWorldEnd() -- Chad Netzer From mis6 at pitt.edu Sun Aug 3 11:03:01 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 3 Aug 2003 08:03:01 -0700 Subject: PyChecker work with Python 2.3? References: <3F2C5300.FA223CBA@easystreet.com> <3F2CBCC2.3FC51D57@easystreet.com> Message-ID: <2259b0e2.0308030703.7d834fe7@posting.google.com> achrist at easystreet.com wrote in message news:<3F2CBCC2.3FC51D57 at easystreet.com>... > Gerhard H?ring wrote: > > > > achrist at easystreet.com wrote: > > > The pychecker site says that pychecker works with versions > > > 1.5 through 2.2. Any reason to expect that 2.3 breaks it? > > > Anyone tried it to see? > > > > Why don't *you*? > > > > Smart people learn from their mistakes. Very smart people > learn from other people's mistakes. > > > Al I context one can learn anything from second hand mistakes. There is much more satisfaction in making your own ;) Michele From stuart at bmsi.com Sat Aug 23 16:02:48 2003 From: stuart at bmsi.com (Stuart D. Gathman) Date: Sat, 23 Aug 2003 16:02:48 -0400 Subject: email bug? Message-ID: Running the following with Python 2.2.2: from email.Parser import Parser txt = """Subject: IE is Evil Content-Type: image/pjpeg; name="Jim&&Jill" """ msg = email.message_from_string(txt) print msg.get_params() I get: [('image/pjpeg', ''), ('name', '"Jim&'), ('&', ''), ('Jill"', '')] What IE apparently gets is: [('image/pjpeg', ''), ('name', '"Jim&&Jill"')] Is this a bug (in the email package, I mean - obviously IE is buggy)? Do I have to write my own custom param parsing routines to handle this? -- Stuart D. Gathman Business Management Systems Inc. Phone: 703 591-0911 Fax: 703 591-6154 "Confutatis maledictis, flamis acribus addictis" - background song for a Microsoft sponsored "Where do you want to go from here?" commercial. From bignose-hates-spam at and-benfinney-does-too.id.au Tue Aug 12 01:37:00 2003 From: bignose-hates-spam at and-benfinney-does-too.id.au (Ben Finney) Date: 12 Aug 2003 15:27:00 +0950 Subject: Is Python your only programming language? References: Message-ID: On Tue, 12 Aug 2003 05:44:45 GMT, Joe Cheng wrote: > many [...] have come to the conclusion that Java and Python are highly > complimentary languages. I think you mean "complementary"; I've never had a programming language compliment me on anything, though it'd make a nice change from all those error messages :-) > I want to ask you hard-core c.l.p Pythonistas: Do you use Python for > everything? (and I'm counting Python + C extensions as just Python) > Or do you keep another language equally close at hand, and if so, what > is it? My professional programming these days is mostly sysadmin tool writing. Where I used to use 70% shell with 30% perl, these days I do 80% python with 20% shell. That probably reflects the ad-hoc, small-scope nature of the tools I write though. It also reflects the fact that I intend these tools to be maintainable by others who don't necessarily know the languages I use inside out. I would shudder to show a complex shell or perl script to a cow-orker, but my Python scripts are easily explainable -- one cow-orker has volunteered the comment that "it looks like pseudocode" :-) > And finally, do you foresee a day when Python can be, for all > practical intents and purposes, your only programming language? I do have several larger-scale programming projects in the back wings, and those will be written entirely in Python. (Waiting has gained me the incremental nice features of Python 2.3 :-) -- \ "I know when I'm going to die, because my birth certificate has | `\ an expiration date." -- Steven Wright | _o__) | Ben Finney From zanesdad at bellsouth.net Fri Aug 29 19:55:35 2003 From: zanesdad at bellsouth.net (Jeremy Jones) Date: Fri, 29 Aug 2003 19:55:35 -0400 Subject: Object Database (ODBMS) for Python In-Reply-To: <3f4f7af6_3@corp.newsgroups.com> References: <1DAECE9E8F34E04AA0E5699AF7D9FF090708D440@stpmsg00.corp.fairisaac.com> <3f4f7af6_3@corp.newsgroups.com> Message-ID: <20030829195535.2df54a97.zanesdad@bellsouth.net> On Fri, 29 Aug 2003 12:11:51 -0400 "Paul D. Fernhout" wrote: > By the way, I like your overview of various related ODBMS projects here: > http://www.orbtech.com/wiki/PythonPersistence > (maybe http://munkware.sourceforge.net/ might go there now?) I wouldn't be offended if Munkware found its way to the PythonPersistence page ;-) Jeremy Jones From vanevery at 3DProgrammer.com Tue Aug 12 14:52:09 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Tue, 12 Aug 2003 11:52:09 -0700 Subject: Python vs. C# References: <2259b0e2.0308100616.55b651ca@posting.google.com> <3f36af20@shknews01> Message-ID: Cliff Wells wrote: > On Sun, 2003-08-10 at 13:55, Brandon J. Van Every wrote: > >> Java and C# are the obvious languages that are not going away. >> Python? What industrial entity is going to champion Python? > > Perhaps people who think for themselves and simply choose the best > tool > don't need shiny brochures and a pat on the back from a salesman to > feel they've made a good choice. If I had coffee, I'd be the one choking on it. > You're starting to sound like your > research was done on page 3 of PC Magazine. And how many corporate managers do you think do exactly that? > If you think it takes major marketing to push a language, let me ask > you > this: what are you doing on this list? No, really. You couldn't > possibly have discovered Python without a major corporate advertising > campaign, so how did you find your way here? It seems almost... > contradictory. Python is known in the game industry. There's a steady trickle of programmers who extol its virtues. Unlike certain advocates in c.l.p, they give both sides of the story. A GDC 2002 speaker will not irresponsibly sell you on merits, without commenting on integration issues with C++ and the debugger environment. Humongous Entertainment, for instance, "solved" problems of this sort by writing an open source debugger. Also, the companies using Python seem to be writing 2D adventure games (low performance app) and scripts for Massively Multiplayer Online Games (stuff is gonna get scripted in something). Not 3D engines. In my case, I thought I needed a scripting language for user AI extensions in my game. I had absolutely no interest in inventing a scripting language, so I surveyed all available scripting languages for their merits and demerits. Python emerged as the one with the best features, the simplest syntax, and most importantly the best community support. The downside appeared to be performance. But overall, it looked like the best fit to the problem. As it turned out, the problem went away. Looking closer and closer at the AI problems, I had serious reservations that any casual hobby programmer could handle low level AI problems without serious brainpower and hard work. There was no point in providing the service if few to no people would use it in practice. I decided that I should do the low level AI stuff in whatever langauge was appropriate, probably C++. Once I had a more stable, high level API for what I was doing, then worry about user AI. So now I had no immediate reason to use Python. Looking for reasons why I might still use Python, I examined 2D + 3D GUI problems. Could I get cross-platform widgets that could be skinned for game development and would run on any platform? Would they integrate well with my 3D code? I found at least one project along those lines, but as a sideshow project without a lot of industrial testing, I wasn't willing to make a big learning curve committment just over that. It didn't look "prime time" and the whole point of switching to Python is to save work, not create it. So I put that idea on the backburner. More recently I've realized what a chore C++ is, and how it limits my development. I hate the look of STL, I"ve always avoided it, and I could really use lists, collections, dictionaries, etc. for some problems. I've never done much memory management, but even the tiny amount that I have done tends to be tedious. So recently I started considering the advantages of higher level languages. Available were: Python, Java, C#. They can all do the "higher level language" job, but C# currently has slam dunk advantages on the Windows platform. It's pretty much a no-brainer for a Windows developer who's been doing lotsa C++ but is tired of it. >> But I am not seeing Python's overwhelming utility compared to other >> languages. > > Then perhaps you should spend less time trolling the newsgroups and > more time programming. Perhaps you should spend more time programming on Windows. > Perl isn't a bad language? Perl is a terrific tool but a terrible > language. I could go on, but I think your own statements sum up your > abilities to make any sort of qualitative judgement regarding > programming languages. No wonder you chose C++. Please notice my e-mail address as to what kinds of tasks have been historically most important to me. If you don't see why C++ is a better fit to low-level 3D graphics problems than Python, well.... -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From adalke at mindspring.com Thu Aug 21 02:18:00 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Thu, 21 Aug 2003 06:18:00 GMT Subject: What's better about Ruby than Python? References: <3F41505F.69D18CC8@alcyone.com> <66d7kvonvb2n0nqbqahhd5roak7ur81sob@4ax.com> <3f43ef5d_4@127.0.0.1> <3F440A35.9030602@nyc.rr.com> Message-ID: Kenny Tilton: > This macro: > > (defmacro c? (&body code) > `(let ((cache :unbound)) > (lambda (self) > (declare (ignorable self)) > (if (eq cache :unbound) > (setf cache (progn , at code)) > cache)))) I have about no idea of what that means. Could you explain without using syntax? My guess is that it caches function calls, based only on the variable names. Why is a macro needed for that? >>> import time >>> def CachedCall(f): ... cache = {} ... def cached_call(self, *args): ... if args in cache: ... return cache[args] ... x = f(self, *args) ... cache[args] = x ... return x ... return cached_call ... >>> class LongWait: ... def compute(self, i): ... time.sleep(i) ... return i*2 ... compute = CachedCall(compute) ... >>> t1=time.time();LongWait().compute(3);print time.time()-t1 6 3.01400005817 >>> t1=time.time();LongWait().compute(3);print time.time()-t1 6 0.00999999046326 >>> (Need to use the function instead of a class with __call__ so that the method gets bound correctly. And I believe this won't work if the class is derived from object. Nope! I'm wrong. It does work.) Andrew dalke at dalkescientific.com From belred1 at yahoo.com Tue Aug 26 10:13:01 2003 From: belred1 at yahoo.com (Bryan) Date: Tue, 26 Aug 2003 14:13:01 GMT Subject: Comments on my "Python Introduction" slides References: <33803989.0308240000.35b9bf1f@posting.google.com> <33803989.0308240644.3090f039@posting.google.com> <3f492761$0$49117$e4fe514c@news.xs4all.nl> <33803989.0308260210.4c1e058@posting.google.com> Message-ID: > > frame 8: you should also list empty tuple, list and dict as having a False value too) > Don't they fall under "empty collection"? > don't forget None is also a False value. i think this is a very power part of python and used a lot and helps reduce as lot of clutter you might see in other languages when testing emptyness. all of these can be use in boolean expressions. i might help your "wow" factor to see them all listed. bryan From tomas at fancy.org Sat Aug 30 17:51:39 2003 From: tomas at fancy.org (Tom Plunket) Date: Sat, 30 Aug 2003 14:51:39 -0700 Subject: OT: Americans love their guns References: <5627c6fa.0308281905.152eb4e4@posting.google.com> Message-ID: Tayss wrote: > The irony though is that [Bowling for Columbine] raised > suspicions on the media, but of course this documentary is really > part of the media. It steered the audience very strongly at > times, and I wish he released the unedited footage of scenes like > the surprise interview at the end. It seems just mean to me to take a guy with Alzhimer's and rake him over the coals to me, but maybe it was shot before the announcement that he had it... -tom! -- There's really no reason to send a copy of your followup to my email address, so please don't. From timow at nwn.de Wed Aug 6 03:07:43 2003 From: timow at nwn.de (Timo Warns) Date: 6 Aug 2003 07:07:43 GMT Subject: Auto persistency References: Message-ID: Batista, Facundo wrote: > > [Example of class with get- and set-methods] > > I want to implement persistency. I think it's a good idea to each object be > the responsible of it's own persistence in a file, in a sql server, anywhere > (opinions?). This is some kind of a design pattern often called "data access objects". Java has this already built-in with its JDOs. Hava a look at this design pattern and how it is implemented in other languages or python packages. Do you need any kind of capabilities like transactions? > [...] > > Now I have two questions: > > 1) How do I implement the dead of the object. I need it to erase > itself from the sql server. Should I define the __del__ method? You probably should create another method like "drop". If you implement the __del__ method, you will not have any persistency, because any time your object is deleted, the data will be deleted in your data source. > > 2) When the program starts, how do I retrieve all the objects from > the sql server to memory? (considering that only the object knows how it's > persisted). You could implement a factory, that generates the objects and loads the data by a given primary key. HTH, Timo From gh at ghaering.de Mon Aug 4 10:27:16 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Mon, 04 Aug 2003 16:27:16 +0200 Subject: Python speed vs csharp In-Reply-To: References: <1h5f2rzthqgid.8watonaa4cjt.dlg@40tude.net> <3F551D29.1040407@kfunigraz.ac.at> <0MoXa.21930$cl3.850221@news2.tin.it> <3F55B1CE.5010607@kfunigraz.ac.at> Message-ID: <3F2E6D44.4050006@ghaering.de> Alex Martelli wrote: > [nice flame, fun to read] I interpreted Mr. Gonzi's statement "Python is crap" to be meant for numerical programming. Which I can support, unless you use third-party libraries like Numeric, psyco or others. Perhaps it was a misunderstanding and you two can calm down now. Or just continue your flames, they're fun to read :) -- Gerhard From sross at connectmail.carleton.ca Thu Aug 21 13:29:40 2003 From: sross at connectmail.carleton.ca (Sean Ross) Date: Thu, 21 Aug 2003 13:29:40 -0400 Subject: [OT] Why is it called string? References: <3f44ce77$0$556$b45e6eb0@senator-bedfellow.mit.edu> <3F44DBF2.1010403@draigBrady.com> Message-ID: "Greg Krohn" wrote in message news:q_61b.1904$Ej6.268 at newsread4.news.pas.earthlink.net... > >

wrote in message news:3F44DBF2.1010403 at draigBrady.com... > ... > > bit is a contraction of "Binary digIT" > > byte is a pun on the word bit (8 bits) > > nibble is a pun on the word byte (4 bits) > > I could swear there where more of these. Isn't there one for 2 bits and > 32bits, etc? This lists several, but there are others: for instance, I seem to recall seeing trio, quartet, quintet, etc. used somewhere... 2 bits: crumb, quad, quarter, tayste, tydbit, morsel 4 bits: nybble, nibble 5 bits: nickle 10 bits: deckle 16 bits: playte, chawmp (on a 32-bit machine), word (on a 16-bit machine), half-word (on a 32-bit machine). 18 bits: chawmp (on a 36-bit machine), half-word (on a 36-bit machine) 32 bits: dynner, gawble (on a 32-bit machine), word (on a 32-bit machine), longword (on a 16-bit machine). 36 bits: word (on a 36-bit machine) 48 bits: gawble (under circumstances that remain obscure) 64 bits: double word (on a 32-bit machine) quad (on a 16-bit machine) 128 bits: quad (on a 32-bit machine) from: http://developer.syndetic.org/query_jargon.pl?term=nybble Sean From http Sat Aug 2 01:32:58 2003 From: http (Paul Rubin) Date: 01 Aug 2003 22:32:58 -0700 Subject: HTML DOM parser? References: <7x7k5y5wfh.fsf_-_@ruckus.brouhaha.com> <4de76ee2.0308011420.14f309f8@posting.google.com> Message-ID: <7x4r10oc8l.fsf@ruckus.brouhaha.com> calfdog at yahoo.com writes: > Here is a quick example of using automation with IE > # This is a sample of automating IE using Python. Thanks, I should have said I'm running under gnu/linux and I was hoping for a standalone solution (some of the ones suggested sound worth looking into). Even connecting up Python to Mozilla sounds awfully heavyweight. From sdhyok at yahoo.com Sun Aug 24 14:20:24 2003 From: sdhyok at yahoo.com (sdhyok) Date: 24 Aug 2003 11:20:24 -0700 Subject: How to import a standard module in source file with same name? References: <420ced91.0308232052.70e905d5@posting.google.com> Message-ID: <420ced91.0308241020.241cc00f@posting.google.com> Thanks, Michael. If I insist the same name, is there any technical solution for it? Daehyok "Michael Peuser" wrote in message news:... > "Christos TZOTZIOY Georgiou" schrieb im Newsbeitrag > news:gbigkvcgl5upje1qe14r8mqe2unsec6vmh at 4ax.com... > > On 23 Aug 2003 21:52:11 -0700, rumours say that sdhyok at yahoo.com > > (sdhyok) might have written: > > > > [snip of problem description as per the subject] > > > > >Under the condition that the absolute path to the standard module > > >is variable in different machines > > >(so, imp.find_module may not be a solution), > > >is there an elegant way to solve this problem? > > > > You might try changing the case... call it DateTime for example; there > > must be some magic in the C code (if you work on Windows) that matches > > in a case-sensitive way. Or you can do (in the importing module, > > possibly your main program): > > > > import datetime > > import vp.datetime > > vp.datetime.datetime = datetime > > -- > > It i sgeneraqlly not a good idea to call a package _exactly_ as an already > existing one, even if you want to superseed it. Because of Windows' case > insensitivity for files for folders such a distinction should also be > considered bad style. So the solution could be: > > User of package: > > import newPackage as Package > or > from newPackage import * > > > Implementation of package: > > import Package as oldPackage > > and qulifying in case of use of oldPackage accordingly. > > > Kindly > Michael P From dtolton at yahoo.com Mon Aug 11 16:36:25 2003 From: dtolton at yahoo.com (Doug Tolton) Date: Mon, 11 Aug 2003 20:36:25 GMT Subject: Multi-Line Comment References: <4qofjvg3bh9smlnb1do4f0lhjga7bacnu3@4ax.com> Message-ID: On Mon, 11 Aug 2003 14:17:38 -0500, Skip Montanaro wrote: >Nope, no multi-line comment. The python-mode package which is available for >Emacs and XEmacs supports commenting a block of text. You can also use >triple-quoted strings: > How do you comment the block of text with Emacs? That is what I'm using for my code editor. I was wondering if a triple-quoted string not assigned would work, but I hadn't got arround to trying it yet. Doug Tolton From max at alcyone.com Tue Aug 19 01:29:04 2003 From: max at alcyone.com (Erik Max Francis) Date: Mon, 18 Aug 2003 22:29:04 -0700 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: <3F41A877.995F9C35@alcyone.com> <3F41B296.BC2CACC0@alcyone.com> Message-ID: <3F41B5A0.9FFFE102@alcyone.com> Ben Finney wrote: > Uh, no. Seeing them isn't amenable to self-restraint -- you can only > exercise that *after* seeing them. It's not hard to not read messages from an individual person, with or without a killfile. Even when the messages are sitting right in front of you. If you truly don't want to read someone's posts, it's easy to not read them. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ No man is more cheated than the selfish man. \__/ Henry Ward Beecher From logiplex at qwest.net Tue Aug 19 13:24:23 2003 From: logiplex at qwest.net (Cliff Wells) Date: Tue, 19 Aug 2003 10:24:23 -0700 Subject: An advertising message from a Microsoft agent In-Reply-To: <16194.16259.915249.366277@montanaro.dyndns.org> References: <3F403078.3010006@sympatico.ca> <16194.16259.915249.366277@montanaro.dyndns.org> Message-ID: <1061313863.10907.1189.camel@software1.logiplex.internal> On Tue, 2003-08-19 at 08:17, Skip Montanaro wrote: > Nick> "Colin J. Williams" writes: > >> microsoft.ca/vs2003launch Experience a more productive toolset - > > Nick> At first I thought it read "Experience a more productive toilet", > Nick> which is probably just as inaccurate, but more appropriate. > > I don't know. I've never experienced a toilet that produced anything under > normal circumstances. Where I live, toilets are generally consumers. But wouldn't a productive toilet be the Microsoft way? Where do you want to go today? For the mop. Regards, -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 (800) 735-0555 From tnienstedt at telesyn.com Mon Aug 18 06:39:28 2003 From: tnienstedt at telesyn.com (Ted Nienstedt) Date: Mon, 18 Aug 2003 06:39:28 -0400 Subject: Expirience in using expect (PyExpect) functionality In-Reply-To: Message-ID: <005701c36575$009af480$6401a8c0@telesyn.corp> Have you seen http://pexpect.sourceforge.net/, a pure python expect implementation. I'm making much successful use of pexpect. Ted -----Original Message----- From: python-list-admin at python.org [mailto:python-list-admin at python.org] On Behalf Of Raphael Bossek Sent: Monday, August 18, 2003 5:30 AM To: python-list at python.org Subject: Expirience in using expect (PyExpect) functionality Hi, before starting with PyExpect I would like to know if there is an alternative because PyExpect seems not to be maintained anymore ? Is someone using PyExpect successfully here ? -- Raphael From bdelmee at advalvas.REMOVEME.be Tue Aug 5 14:39:05 2003 From: bdelmee at advalvas.REMOVEME.be (Bernard Delmée) Date: Tue, 5 Aug 2003 20:39:05 +0200 Subject: Needs programming tip using date References: Message-ID: <3f2ff9b6$0$6531$6c56d894@sisyphus.news.be.easynet.net> > What is THE/recommended way in checking if a date formatted as > "08/05/2003", so "month/day/year" > is the date of today or a date of the current week? Gotta love 2.3: import datetime sdate = '08/08/2003' (d,m,y) = map(int,sdate.split('/')) # assumming dd/mm/yyyy mask ddate = datetime.date( y,m,d ) sweek = ddate.isocalendar()[1] refwk = ddate.today().isocalendar()[1] same_week = sweek == refwk Cheers, Bernard. From bgailer at alum.rpi.edu Wed Aug 13 12:06:41 2003 From: bgailer at alum.rpi.edu (Bob Gailer) Date: Wed, 13 Aug 2003 10:06:41 -0600 Subject: Is Python your only programming language? In-Reply-To: References: Message-ID: <5.2.1.1.0.20030813095929.02b355b8@66.28.54.253> At 12:49 PM 8/12/2003 -0700, John Machin wrote: >How does one "ork" Quite well, thank you. >and what is the effect on the cow? ' Most of the cows around whom I've orked have given more and richer milk. >What is the RSPCA's attitude to this? Probably better than the ASCPA's. Also consider: http://www.geocities.com/SunsetStrip/5662/Bands/ork.html http://www.geocities.com/Area51/Station/1835/sr.html http://www.openravenscar.org/ http://www.rewth.com/amtgard/ Tracing dictionary references ork -> orc -> grampus "Called also cowfish." Now the circle is complete. Bob Gailer bgailer at alum.rpi.edu 303 442 2625 -------------- next part -------------- --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.506 / Virus Database: 303 - Release Date: 8/1/2003 From tundra at tundraware.com Tue Aug 5 03:10:06 2003 From: tundra at tundraware.com (Tim Daneliuk) Date: 05 Aug 2003 07:10:06 GMT Subject: Win32All Crashes Python 2.3? In-Reply-To: References: Message-ID: <1tkngb.2h1.ln@boundary.tundraware.com> Tim Daneliuk wrote: > Some time ago I wrote a portable file system browser, twander, that, > While it is certainly possible that this is a bug in my code, I > cannot imagine what it might be. The program has worked flawlessly > on a wide variety of Unix/FreeBSD/Win32 systems with no reports > of this sort of thing. > > Anyone have any ideas what could cause this? Is this a reported > Win32All bug? OK, after some highly-technical debugging procedures (print statements! ;), I have determined that os.lstat() is blowing up when Win32All is being used. What is strange is that this only happens sometimes. For the life of me, I cannot see anything in my code that is causing the problem. It sure looks to me like an errant pointer or something in Win32All. FWIW, Dr. Watson is reporting an Access Violation... -- ---------------------------------------------------------------------------- Tim Daneliuk tundra at tundraware.com PGP Key: http://www.tundraware.com/PGP/ From ktilton at nyc.rr.com Thu Aug 21 16:14:38 2003 From: ktilton at nyc.rr.com (Kenny Tilton) Date: Thu, 21 Aug 2003 20:14:38 GMT Subject: What's better about Ruby than Python? References: <3F41505F.69D18CC8@alcyone.com> <66d7kvonvb2n0nqbqahhd5roak7ur81sob@4ax.com> <3f43ef5d_4@127.0.0.1> <3F440A35.9030602@nyc.rr.com> <3F44CF06.4080003@nyc.rr.com> Message-ID: <3F4528FD.7040404@nyc.rr.com> Andrew Dalke wrote: > Kenny Tilton > >>C? does something similar to what you think, but at with an order of >>magnitude more power. Estimated. :) Here is how C? can be used: >> >>[.. some lisp example ...] > > > You have got to stop assuming that a description in Lisp is > intuitive to me. I don't know anywhere near enough of that > language to know what's normal vs. what's novel. Don't feel bad, lispniks are scared by (c? ...). It does Something Completely Different. Well, Garnet and COSI and other constraint programming ttols also do it, but a lot of people don't know about those. I'd translate to Python if I remembered it from my brief exploration a while back. > > >>So I do not have to drop out of the work at hand to put /somewhere else/ >>a top-level function which also caches, > > > Didn't you have to "drop out of the work at hand" to make the macro? C? is like your cacheCall, it works for anything. But I just toss it in in-line, around any arbitrary lisp expression. I think you had to set up a class with a method and a cache slot before even doing the cacheCall call. Too messy. Can a Python first-class function close over a lexical variable and use that as a cache across multiple calls? That is another Lisp feature I am pressing into action. > > I tried to understand the lisp but got lost with all the 'defun' vs > 'function' vs 'funcall' vs 'defmodel' vs 'defclass' vs 'destructuring-bind' > I know Lisp is a very nuanced language. I just don't understand > all the subtleties. (And since Python works for what I do, I > don't really see the need to understand those nuances.) Build it and they will come. Maybe if you used a macro-powered language and saw where macros improved code and they became second nature... > > >>Cool. But call cachedCall "memoize". :) Maybe the difference is that you >>are cacheing a specific computation of 3, while my macro in a sense >>caches the computation of arbitrary code by writing the necessary >>plumbing at compile time, so I do not have to drop my train of thought >>(and scatter my code all over the place). > > > Sure, I'll call it memoize, but I don't see what that's to be prefered. I think it's just industry practice (since I saw it today in a Perl conext ) > The code caches the result of calling a given function, which could > compute 3 or could compute bessel functions or could compute > anything else. I don't see how that's any different than what your > code does. Because I do not have to set anything up like you did with the class and the cache and the slot and the call to cacheCall. And if I did, a single form such as: (defmemoized count (n) (* 2 n)) ...would suffice. In my case I can even inline, since I am immediately dumping the outcome into an instance's slot where cooperating code (written by the defmodel macro) makes it work. > > And I still don't see how your macro solution affects the train > of thought any less than my class-based one. Memoization does not come up that much, tho Graham still saw fit to create a macro for it. But my hack gets used hundreds of times throughout a sizeable app. I dash them off inline without missing a beat, and when I change C? they all keep working. > > >>That is where Lisp macros step up--they are just one way code is treated >>as data, albeit at compile time instead of the usual runtime > > consideration. > > The distinction between run-time and compile time use of code is > rarely important to me. Suppose the hardware was 'infinitely' fast > (that is, fast enough that whatever you coded could be done in > within your deadline). On that machine, there's little need for > the extra efficiencies of code transformation at compile time. But > there still is a need for human readablity, maintainability, and code > sharing. This has nothing to do with shifting computation from runtime to compile time, though I have seen people cite that as one advantage. I agree with you that that is negligible. The key thing about being there at compile time is that my code can write code for me, driven by the very small amount of code that varies from case to case. That makes my code more readable than yours, because you are cutting and pasting all that implementing cruft over and over again and the varying essence does not stand out so well. -- kenny tilton clinisys, inc http://www.tilton-technology.com/ --------------------------------------------------------------- "Career highlights? I had two. I got an intentional walk from Sandy Koufax and I got out of a rundown against the Mets." -- Bob Uecker From dietmar at schwertberger.de Mon Aug 4 14:46:25 2003 From: dietmar at schwertberger.de (Dietmar Schwertberger) Date: Mon, 4 Aug 2003 20:46:25 +0200 Subject: ctypes ques References: Message-ID: In article , ryan wrote: > the win32 python extentions don't seem to have "SysParametersInfo()" and i need it to > set the wallpaper in windows. > > cyptes has a "SysParametersInfoA()" function but wont let me use the SPI_SETDESKWALLPA > PER attribute. > > anyone have any ideas how i can set the windows wallpaper from a python program? This is what I've been using with windll: def set_wallpaper(wallpaper): # refresh wallpaper try: import windll g = windll.module("user32") buf = windll.cstring(wallpaper) g.SystemParametersInfo(20, 0, buf, 3) except: pass Regards, Dietmar From ktilton at nyc.rr.com Mon Aug 25 19:34:06 2003 From: ktilton at nyc.rr.com (Kenny Tilton) Date: Mon, 25 Aug 2003 23:34:06 GMT Subject: Advice to a Junior in High School? References: Message-ID: <3F4A9DC7.9060509@nyc.rr.com> Howard Nease wrote: > H What languages do you suggest that I > study (I'm already studying Python)? PS. Common Lisp -- kenny tilton clinisys, inc http://www.tilton-technology.com/ --------------------------------------------------------------- "Career highlights? I had two. I got an intentional walk from Sandy Koufax and I got out of a rundown against the Mets." -- Bob Uecker From belred1 at yahoo.com Sat Aug 9 00:08:33 2003 From: belred1 at yahoo.com (Bryan) Date: Sat, 09 Aug 2003 04:08:33 GMT Subject: Python for .NET preview 2 release References: Message-ID: <5t_Ya.102789$YN5.72026@sccrnsc01> is this the same visual python .net that at activestate? i didn't know they python .net is still moving forward. i also thought i read somewhere that there were some limitations about using a typeless language on the clr. is this not true anymore? thanks, bryan "Brian Lloyd" wrote in message news:mailman.1060400898.32406.python-list at python.org... > For those interested, I've made a preview-2 release of > Python for .NET. > > Python for .NET is a near-seamless integration of the > CPython runtime with the .NET Common Language Runtime > (CLR). It lets you script and build applications in > Python, using CLR services and components written in any > language that targets the CLR (C#, Managed C++, VB.NET, > etc.). > > Highlights of this release include array and indexer > support, better thread handling, the ability to subclass > managed classes in Python and many bug fixes. > > For more info or to download the release: > > http://zope.org/Members/Brian/PythonNet/ > > - Brian > From anton at vredegoor.doge.nl Sat Aug 30 07:32:35 2003 From: anton at vredegoor.doge.nl (Anton Vredegoor) Date: Sat, 30 Aug 2003 13:32:35 +0200 Subject: OT: Celebrity advice (was: Advice to a Junior in High School?) References: Message-ID: "Andrew Dalke" wrote: >So I am not convinced that ID cards can make a government >more efficient, or at least not all that much more efficient. The problem is with how to measure efficiency. For example a factory may produce goods with high efficiency, while neglecting costs resulting from ecological damage to the environment. Not including these and other factors into the efficiency measurement is highly questionable. >Chaining everyone to a stake on a limited line may make >government potentially more efficient. (Easy to track people >down - don't need the change-of-address system for the postal >service! - very hard to commit any crimes). Doesn't mean >it's a good idea. Ask Michael Moore about this issue :-) (there was a documentary about this on Dutch television some time ago, maybe it was shown on other networks too at some other time?) Anton p.s. to make this thread more efficient I'm providing some code using a mIDi-file interface that was posted here some time ago: http://www.mxm.dk/technologies/pythonmidi/ -great work max- perhaps someone can improve my code that uses it, changing the notes is one obvious way to do it :-P import os from MidiOutFile import MidiOutFile from operator import add class Track: def __init__(self,channel,instrument,volume): self.instrument = instrument self.channel = channel self.volume = volume self.notes = {} def addnote(self,start,note,duration=10): self.notes[start] = (note,start+duration) def playtracks(tracks,out_file='midiout/my.mid'): midi_events = [] for t in tracks: for start in t.notes: note,end = t.notes[start] midi_events.append((start,True, t.channel,t.instrument,note,t.volume)) midi_events.append((end,False,t.channel, t.instrument,note,0)) midi_events.sort() midi = MidiOutFile(out_file) midi.header() midi.start_of_track() t=0 for event in midi_events: time,switch,channel,instrument,note,volume = event midi.update_time(time-t) t=time midi.patch_change(channel,instrument) midi.note_on(channel,note,volume) midi.update_time(0) midi.end_of_track() midi.eof() os.startfile(out_file) def simpletrack(channel,instrument,timedelta,notes,volume): T = Track(channel,instrument,volume) for time,note in enumerate(notes): T.addnote(time*timedelta,note,100) return T def test(): f,n = 30,5 L=[[55,67,70], [70,69],[64,60,62],[65,67],[64],[65,67,70], [69,74,64,65],[57,58,62],[57,58,53]]*2 solonotes = reduce(add,L,[]) basenotes = reduce(add,L[1:]+L[:1],[]) drumnotes = [48,64,42,47,42,65]*3+[35,64,60,62]*3+\ [48,64,42,47,42,65]*3+[35,64,54]*2 solo = simpletrack(0,34,f,solonotes*n,127) drum = simpletrack(9,0,f,drumnotes*n,127) base = simpletrack(1,67,f,basenotes*n,127) playtracks([drum,base,solo]) if __name__=='__main__': test() From adalke at mindspring.com Mon Aug 18 20:26:10 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Mon, 18 Aug 2003 18:26:10 -0600 Subject: What's better about Ruby than Python? References: <87zni6wu79.fsf@pobox.com> Message-ID: John J. Lee: > Would be fun to write a Google API script, keep records, and put up a > page to plot graphs of some simple metrics... No doubt somebody has > done it already. Even if not, the basic tools exist, like the Google/SOAP interface, some COM code to talk to Excel, a couple mouse clicks, and poof. But I'm not interested in the results nor the process, other than to say it's easy. > Somewhere, I came across somebody who had graphed nr. of Amazon books > over the years, by programming language, with a neat web interface > (maybe that was pointed to by Alex's post, can't remember). There's also the sucks/rules index. See http://www.lehigh.edu/~sol0/rules.html Looks like Python rules ... but Ruby isn't on that list. Andrew dalke at dalkescientific.com From adalke at mindspring.com Wed Aug 20 15:41:31 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Wed, 20 Aug 2003 19:41:31 GMT Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> <6dj2kv8ugkieehs7guh786cl40o5lj6mcs@4ax.com> Message-ID: Doug Tolton: > It depends what you are talking about. If you are talking about > making some large cross industry library I might be inclined to agree, > but when it comes to building good high level abstractions within a > company, this argument doesn't make sense. Any feature has to be used > in the proper context for it to be useful, Macros are also this way. As a consultant, I don't have the luxury of staying inside a singular code base. By your logic, I would need to learn each different high level abstraction done at my clients' sites. And given the usual software engineering experience a chemist or biologist has, those are unlikely to be good. > I just don't find that argument compelling. By that logic we should > write the most restrictive language possible on the most restrictive > platform possible (ie VB on Windows) because allowing choice is > clearly a bad thing. The inference is that programming language abstractions should not be more attractive than sex. Classes, functions, and modules are not. Arguing as you do is an all-or-nothing approach which overly polarizes the discussion. > Linux is based on this concept of allowing people to extend the > system, it doesn't seem to have suffered from it. I don't use Linus's kernel. The machine I have with Linux on it runs a modified version distributed by a company and with all the other parts needed to make a useful environment for my work. And I loath the times I need to recompile the kernel, even though I actually have done kernel mods on Minix in OS class back in school. In a similar vein, the different distributions once upon a time were very divergent on where files were placed, how startup scripts worked, which libraries were included, and how things were configured in general (eg, which libc to use?). If I wanted to distributed precompiled binaries, I was in a bind because I would need to ship all the variations, even though it's just for "Linux". There's more consensus now on, but it took a lot of time. In short, my comment is that Linux does allow the diversity, it did cause problems, and people now decide that that diversity isn't worth it, at least for most uses. For me as an applications developer, that diversity just makes my life more complicated. > Same argument as above, I don't agree with this logic. Python is a > great language, that doesn't mean it couldn't be better though. If > that were the case development would be cease. What if Python had a marker so people could tell the intepreter that the next few lines are Lisp code, or Perl, or Tcl, or any other language. Would the result be more flexible? Yes? More powerful? Yes. Better? I think not. > Why do we allow people to write functions even, I mean you have to > learn the syntax for calling them, what the variables are and what > they do. Bah, we should make everyone use only built in functions, if > they want a different one, use a different language. What? It makes > no sense to me. Your argument of an extreme has no weight because it's different than what I'm saying. Extra power and flexibility can have bad effects, not just on the language but on the community built around the language. Software development is rarely a singleton affair, so a good language should also optimize the ability for different people to use each others' libraries. Functions and modules and objects, based on experience, promote code sharing. Macros, with their implicit encouragement of domain specific dialect creation, do not. > So don't allow people to customize the system huh? They why is Python > Open Source? That's the *entire* point of Open Source, so that people > can tweak and customize to their own environment. Err, no. I use open source because it's cheap, because the tools are of good quality, because if something breaks I can track down the problem, and as a risk management bonus, if the project ever dies, I can still maintain things on my own. I never, ever, ever, want to get into the case where I'm maintaining my own private, modified version of Python. > Do you have any > specific examples that are comparable where customization broke a > community down? This sounds like baseless hypothetical speculation to > me. Lisp. A language which allows very smart people the flexibility to customize the language, means there will be many different flavors, which don't all taste well together. A few years ago I tested out a Lisp library. It didn't work on the Lisp system I had handy, because the package system was different. There was a comment in the code which said "change this if you are using XYZ Lisp", which I did, but that that's a barrier to use if I ever saw one. > You are saying you don't know how to tweak a language to fit it your > specific domain better than a general puprose language? And you are > saying you are a pretty good language designer? If you don't know > your specific domain well enough to adapt a general purpose language > to it better than it is already written there are several > possibilities: > 1) You don't know your domain that well > 2) You work in a very general purpose domain > 3) You aren't a very good language designer 4) a small change in a language to better fit my needs has subtle and far-reaching consequences down the line. Instead, when I do need a language variation, I write a new one designed for that domain, and not tweak Python. > Designing a good language is all about designing the right high level > abstractions. Even a medium skilled designer should be able to design > a language that maps better to their specific domain than a general > purpose domain (actually implementing is of course a vastly different > story). But if Python is HERE ............................... and my domain is HERE I'm not going to try to force them together. > You are in essence saying that Python is perfect, that no one could > make a more useful abstraction than it already has, and that saying > that one could do so is hubristic. I looked up 'hubris' just now. It's the wrong word for me to use. http://dictionary.reference.com/search?q=hubris hubris: Overbearing pride or presumption; arrogance I don't mean 'overbearing', I mean perhaps 'confidence'. 'arrogance' is also the wrong word. Something without the negative overtones. Andrew dalke at dalkescientific.com From tjreedy at udel.edu Sun Aug 31 12:01:15 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 31 Aug 2003 12:01:15 -0400 Subject: artificial intelligence? References: Message-ID: "Arthur" wrote in message news:mailman.1062333596.9491.python-list at python.org... > > """ > Dear Amazon.com Customer, > > We've noticed that customers who have purchased books by Mark Lutz often > enjoy the books of Sedi 200. So you might like to know that Sedi 200's > newest book, Earth's Core and Lower Mantle (Fluid Mechanics of Astrophysics > and Geophysics, V.11), > > """ > > Sure read my mind, didn't they? > > Any theories on how the Amazon.com AI machine got this far off track? Is there another Mark Lutz who writes geophysics books? TJR From bit_bucket5 at hotmail.com Sun Aug 31 11:43:27 2003 From: bit_bucket5 at hotmail.com (Chris Stromberger) Date: Sun, 31 Aug 2003 15:43:27 GMT Subject: MySQLdb -- any way to get "rows matched"? Message-ID: When issuing updates in mysql (in the console window), mysql will tell you if any rows matched and how many rows were updated (see below). I know how to get number of rows udpated using MySQLdb, but is there any way to get the number of rows matched? I want to find out, when rows updated = 0, if there were no updates because the row wasn't found (rows matched will = 0) or because the update would not have changed any data (rows matched = 1). mysql> select * from test; +------+------+ | rver | s | +------+------+ | 1 | new | +------+------+ 1 row in set (0.00 sec) mysql> update test set rver = 1, s = 'new' where rver = 1; Query OK, 0 rows affected (0.00 sec) Rows matched: 1 Changed: 0 Warnings: 0 mysql> update test set rver = 1, s = 'new' where rver = 17; Query OK, 0 rows affected (0.00 sec) Rows matched: 0 Changed: 0 Warnings: 0 mysql> update test set rver = 1, s = 'neww' where rver = 1; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 Thanks, Chris From Vincent.Raaijmakers at ge.com Tue Aug 5 13:17:13 2003 From: Vincent.Raaijmakers at ge.com (Raaijmakers, Vincent (IndSys, GE Interlogix)) Date: Tue, 5 Aug 2003 12:17:13 -0500 Subject: Needs programming tip using date Message-ID: <55939F05720D954E9602518B77F6127F03096A83@FTWMLVEM01.e2k.ad.ge.com> Wow, thanks!! Fast service. Thank you for not letting me invent the wheel again. Vincent -----Original Message----- From: Gerhard H?ring [mailto:gh at ghaering.de] Sent: Tuesday, August 05, 2003 12:27 PM To: python-list at python.org Subject: Re: Needs programming tip using date Raaijmakers, Vincent (IndSys, GE Interlogix) wrote: > I think this is a bit of a newbie question in the dates area. Ok, the first thing you should do is download and install the eGenix BASE package [1]. If you have a half-way decent operating system, you can also install it via the package manager or ports system ;-) > So before I end up in very ugly coding, > What is THE/recommended way in checking if a date formatted as "08/05/2003", so "month/day/year" > is the date of today or a date of the current week? from mx.DateTime import DateTimeFrom, now dt = DateTimeFrom("08/05/2003") if dt.iso_week[1] == now().iso_week[1]: print "date is in current week" You'll want to check if the definition of iso_week matches your definition of 'week'. [2] -- Gerhard [1] http://www.egenix.com/files/python/eGenix-mx-Extensions.html [2] http://www.egenix.com/files/python/mxDateTime.html -- http://mail.python.org/mailman/listinfo/python-list From writeson at earthlink.net Tue Aug 12 08:21:46 2003 From: writeson at earthlink.net (Doug Farrell) Date: 12 Aug 2003 05:21:46 -0700 Subject: Problem with mod_python and 4Suite References: <88bc63c6.0308080449.3e6fdf7a@posting.google.com> Message-ID: <88bc63c6.0308120421.3763f79e@posting.google.com> Alexandre Fayolle wrote in message news:... > Doug Farrell a ?crit : > > Hi all, > > > > I'm trying to build a demonstration website using mod_python and > > 4Suite to show how we could transform XML documents into HTML with > > XSLT. Here is a piece of code that causes it to blow up: > > > > # import the xml/xslt stuff here > > from xml.xslt.Processor import Processor > > This actually imports the broken xslt engine in pyxml, and not 4suite's. > This engine is known not to work. > > You want to import Ft.Xml.Xslt to use 4suite xslt engine in the 1.0 > branch. You will also have to adapt your code to the new apis introduced > since 4suite 0.12, please see the documentation. > > Try asking on the 4Suite mailing list (links to the list available from > http://4suite.org/) Alexandre, Thanks for your help and suggestions, I will implement them and see how that works for me. I'll also post back to this thread to let you know of my success (or failure ). Again, thanks for for your feedback, Doug Farrell Scholastic, Inc. From mpeuser at web.de Sat Aug 30 15:58:55 2003 From: mpeuser at web.de (Michael Peuser) Date: Sat, 30 Aug 2003 21:58:55 +0200 Subject: Newbie Tkinter problem... References: <3306631.1062265710@dbforums.com> Message-ID: "Baltor" schrieb im Newsbeitrag news:3306631.1062265710 at dbforums.com... > > I am trying to attach a scollbar to a text field. This is the code > I am using: ... > self.scrollbar.pack(side=RIGHT, fill=Y) .... > self.text.grid(row=2, column=1, rowspan=2) > NEVER mix two different geometry managers in the same frame!!!!! Strange things will happen ;-) Kindly Michael P From max at alcyone.com Sun Aug 17 17:23:59 2003 From: max at alcyone.com (Erik Max Francis) Date: Sun, 17 Aug 2003 14:23:59 -0700 Subject: client derived from async_chat References: <3f3fdb48_1@news.vo.lu> Message-ID: <3F3FF26F.3D6538F4@alcyone.com> Patrick Useldinger wrote: > Has anybody got such an example? My server works fine, but my client > does not :-( I tried to run your sample but you didn't include enough material for me to run it as a standalone application. When I tried to stub out the additional material you didn't include, I got connection refused errors, presumably because the server wasn't running at the point your clients tried to connect. Furthermore, the error code that you got appeared to be Windows-specific, so if that's where your problem lies, I can't help you. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ Sometimes a cigar is just a cigar. \__/ Sigmund Freud From mpeuser at web.de Sat Aug 23 18:20:55 2003 From: mpeuser at web.de (Michael Peuser) Date: Sun, 24 Aug 2003 00:20:55 +0200 Subject: OpenGL with Mcmillan Installer? Message-ID: I encountered two problems with Mcmillan's Installer when trying to make a distribution from an OpenGL/Tk program. (1) This part of the Tk interface seems to be to hard: The exe does not find Togl (I copied the .dll manually, but that did not help any...) (Lines 71 - 82 from __init__ ) ...... # add this file's directory to Tcl's search path # on Linux Togl is installed in ./linux2-tk8.0 # on Windows (Python2.0) in ./win32-tk8.3 _default_root.tk.call('lappend', 'auto_path', os.path.join( \ os.path.dirname(__file__), \ sys.platform + "-tk" + _default_root.getvar("tk_version"))) try: _default_root.tk.eval('load {} Togl') except TclError: pass _default_root.tk.call('package', 'require', 'Togl') ........ Any idea? (2) The dist-directory is full of FOX, wx and Pygame/SDL garbage. I can remove that of course, but maybe someone already has a coustumized Installer.spec template for this ??? Thank you for your help Michael P From benny at coca-kohler.de Wed Aug 6 11:02:01 2003 From: benny at coca-kohler.de (bk) Date: Wed, 6 Aug 2003 17:02:01 +0200 Subject: makepy must be run after restart of pythonwin Message-ID: <006901c35c2b$b47e6fc0$0d00a8c0@maitai> hi, i'm using pythonwin 2.2.3 my programm reads and write the outlook-adress book using COM. for this i have to use the makepy utility. after i have run the utiltity everything is fine and i can run my py-file without any errors. but if i close the pythonwin and restart and then try to run my py-script i get the following error: File "C:\Program Files\Python22\contacts_ausgabe.py", line 45, in DumpDefaultAddressBook folder = mapi.GetDefaultFolder(win32com.client.constants.olFolderContacts) File "C:\PROGRA~1\Python22\lib\site-packages\win32com\client\__init__.py", line 168, in __getattr__ raise AttributeError, a AttributeError: olFolderContacts When i run the makepy again, then everything is fine again. i cant understand what is the problem. is there anyone who can help me??? After the Restart of pythonwin the files generated by makepy still exist. so why do i have to regenerate them again by use makepy??? From Mike at DeleteThis.Geary.com Tue Aug 12 02:31:00 2003 From: Mike at DeleteThis.Geary.com (Michael Geary) Date: Mon, 11 Aug 2003 23:31:00 -0700 Subject: Python should try to displace Java References: Message-ID: > still trolling eh, > > but you try too hard and it shows, I'm new to Python and new to this group, so I'm not familiar with any previous discussions that have taken place. All I know about Brandon is what he posted in this particular message. As someone who has made the wrong bet on strategic directions more than a few times in the 35 years that I've been developing software, I found his comments, along with Doug's reply, to be interesting and thought-provoking. I am being educated here. Is that what trolls do? :-) -Mike From irmen at -NOSPAM-REMOVETHIS-xs4all.nl Sun Aug 17 16:19:33 2003 From: irmen at -NOSPAM-REMOVETHIS-xs4all.nl (Irmen de Jong) Date: Sun, 17 Aug 2003 22:19:33 +0200 Subject: Path Problem on W2K? In-Reply-To: References: <93f5c5e9.0308170927.6e0bdc38@posting.google.com> <3f3fd1c8$0$1122$6c56d894@feed0.news.be.easynet.net> Message-ID: <3f3fe353$0$49112$e4fe514c@news.xs4all.nl> Bertrand Geston wrote: > "Bernard Delm?e" a ?crit dans le message > news: 3f3fd1c8$0$1122$6c56d894 at feed0.news.be.easynet.net... > >>>Also tried adding c:\Program Files\Python23 to my path... >> >>This should work, though! Still it's advisable to install to >>a path without space(s), otherwise the "idle" IDE won't work. >> > > Try with "C\Program Files\Python23" in your path (with the quotes). Could > help you (or not :-( ) That should have read "C:\Program Files\Python23". If it doesn't work, try C:\Progra~1\Python23 This squiggle-path is the 8.3 notation. --Irmen From moncho.leon at gmx.net Fri Aug 15 19:21:33 2003 From: moncho.leon at gmx.net (Ramon Leon Fournier) Date: Sat, 16 Aug 2003 01:21:33 +0200 Subject: Porting to Windows References: Message-ID: Zora Honey wrote: > I've been programming Python on Linux for a while now, and I'm finally > ready to start porting some of my stuff to Windows. Why would you want to port your work to Windows? As a free citizen you have chosen to develop your programs using a free programming language on a free operating system. Thus I postulate that you are aware of the great advantages of such a quality environment. Why then are you planning to port the fruit of your labour to an operating system whose developers do everything they can to undermine your freedoms? Do you not care about it? Porting software to Windows won't help anyone except Microsoft, not even the Windows users themselves. Why? Because instead of trying out a free operating system, people will continue to use Windows. At the same time they will not encourage others to move away from Windows, which they would do if they had made that move already. Cheers, Ram?n -- Horum omnium fortissimi sunt Costarricenses From scottholmes at sbcglobal.net Mon Aug 18 19:17:38 2003 From: scottholmes at sbcglobal.net (Scott Holmes) Date: Mon, 18 Aug 2003 16:17:38 -0700 Subject: event binding and component.config References: <3F3E7A85.8040202@sbcglobal.net> <20030818181308.GN16941@unpythonic.net> Message-ID: <3F415E92.2090008@sbcglobal.net> Jeff Epler wrote: ..... > > Finally, you don't explain exactly why you want this behavior, > and I'm not familiar with any common programs that do this (though the > behavior you're describing sounds a little bit like a Tk checkbutton > with indicatoron=0). You should always ask yourself if departing from > standard behavior of the OS and other applications is worth it, given > that the results are likely to confuse users. > > Jeff > Actually, my motivation for this is purely cosmetic. Also, I'm am still trying to determine "best practices" for python coding. My GUI has, among other buttons, Add and Update and Commit. This is following long practice going back to the Informix 4GL code my project is based on. I would like it to be apparent to the user what "mode" they are in be it Add or Update. It's possible that I will abandon button relief in favor of a screen label. An example: activating the Add button sets a flag and clears the input screen. After inputing field values, the user will activate the Commit button. This will commit values to the database. Your explanation is very helpful, indeed. I rather expected something like that. I have had little time, so far, to explore the internals as I am in a desperate race to port this project to a useable interface. If this project proves feasible I would eventually like to release it to the community at large. -- --------------------------------------------------------------------- Scott Holmes http://sholmes.ws http://pages.sbcglobal.net/scottholmes scottholmes at sbcglobal.net Independent Programmer/Analyst Passport 4GL PHP HTML Composer PostgreSQL Informix 4GL, SQL --------------------------------------------------------------------- There are more things in heaven and earth, Horatio, than are dreamt of in your philosophy --------------------------------------------------------------------- From wt at nic.fi Wed Aug 6 07:55:57 2003 From: wt at nic.fi (Timo Virkkala) Date: Wed, 06 Aug 2003 14:55:57 +0300 Subject: Isn't there a substring(start, end)-function???? In-Reply-To: References: Message-ID: <4Z5Ya.5298$HC4.59@reader1.news.jippii.net> Dave wrote: > substring(beginIndex, endIndex) witch returns the substring between > beginIndex and endIndex. > > Like: > text = "If someone attacks you with a banana" > print text.substring(0,3) > Should print "If " text = "If someone attacks you with a banana" print text[0:3] -- Timo Virkkala | wt at nic.fi "In the battle between you and the world, bet on the world." From mertz at gnosis.cx Sun Aug 17 02:55:29 2003 From: mertz at gnosis.cx (David Mertz) Date: Sun, 17 Aug 2003 02:55:29 -0400 Subject: Py2.3: Feedback on Sets (fwd) References: <2e363c08.0308161306.47a010ae@posting.google.com> Message-ID: |mertz at gnosis.cx (David Mertz) wrote |> Then again, power set really is a fundamental operation |> on sets. And making users rewrite it each time is error prone. pwmiller1 at adelphia.net (Paul Miller) wrote previously: |How is it error prone? if P is the power set operation, and S and X |are sets, then X in P(S) is equivalent to X is a subset of S. I don't |think that's all that error prone. This looks more like a definition of a method Set.ispowerset(), not one of Set.powerset(). The actual generation of P(S) is the part I think programmers could do wrong. I'm not saying that they might not usually do it right... but mistakes happen. Raymond Hettinger also wrote: |from sets import Set |def powerset(iterable): | data = list(iterable) | for i in xrange(2**len(data)): | yield Set([e for j,e in enumerate(data) if i&(1< Hi Why this statement will generate errors shutil.copy2("c:\hamido.sql", "c:\ali1.ali") shutil.copy2('c:\hamido.sql', 'c:\ali1.ali') ------------------- Error Traceback (most recent call last): File "", line 1, in ? shutil.copy2("c:\hamido.sql", "c:\ali1.ali") File "C:\PYTHON23\lib\shutil.py", line 82, in copy2 copyfile(src, dst) File "C:\PYTHON23\lib\shutil.py", line 38, in copyfile fdst = open(dst, 'wb') IOError: [Errno 2] No such file or directory: 'c:\x07li1.ali' ------------------------------------------- TQ From cnetzer at sonic.net Fri Aug 29 13:34:00 2003 From: cnetzer at sonic.net (Chad Netzer) Date: Fri, 29 Aug 2003 10:34:00 -0700 Subject: opposite of dict.items() In-Reply-To: References: <3f4e708c$0$64719@hades.is.co.za> Message-ID: <1062178440.1855.16.camel@adsl-209.204.179.133.sonic.net> On Fri, 2003-08-29 at 04:53, Peter Otten wrote: > >>> dict(izip(irange(3), "abc")) > {0: 'a', 1: 'b', 2: 'c'} > > If I could use the above in Py2.4, it would be even nicer, namely: > > - convert itertools to builtins The push is to have LESS builtins. You can always import them in to the current namespace: from itertools import izip > - add irange(), perhaps as an alias for xrange() like file/open I suggested an irange to Raymond, and even coded one up, a while ago. He sees it as bloat, and rightfully so, since there is a push to allow optimizations of range that would achieve the same effect. (ie. rather than remembering when to use range(), xrange(), or irange(), we could just always use range() and the language would do lazy evaluation whenever possible.) Unless that avenue turns out to be a complete dead end, don't expect an irange(). BTW. In the example you used, you COULD use xrange(). The only problem is that range has been extended, in 2.3, to accept longs, and xrange() only works with ints, and Guido wants it that way (he doesn't want to extend xrange()'s features, since it is a pain.) irange(), if it ever appears, would presumably be fully range() compatible. -- Chad Netzer From dfinner at Kollsman.com Thu Aug 28 14:30:19 2003 From: dfinner at Kollsman.com (dfinner at Kollsman.com) Date: Thu, 28 Aug 2003 14:30:19 -0400 Subject: IBM Goes Python Message-ID: <85256D90.0065A7A9.00@Notes.kollsman.com> Part 1: http://www-106.ibm.com/developerworks/linux/library/l-pymeta.html ::: Metaclass programming in Python, Part 2 ::: Metaclasses can be downright metaphysical. If you thought inheritance was messy before, wait until you see what happens when Python experts Michele Simoniato and David Mertz introduce metaclasses, superclasses, subclasses, metatypes, magic methods, and more into the equation. But fear not: they assure us that, despite the pitfalls (and worse) of mixing metas into your Python work, the benefits make the effort more than worth while. http://www.ibm.com/developerworks/library/l-pymeta2/?ca=dnt-434 IBM's Developerworks posts quite a bit of Python/Perl/OpenSource information in their weekly newsletter. If you weren't aware, I thought you might find this interesting. Doug From mertz at gnosis.cx Fri Aug 22 18:14:54 2003 From: mertz at gnosis.cx (David Mertz) Date: Fri, 22 Aug 2003 18:14:54 -0400 Subject: For Kenny Tilton: Why do I need macros revisited. References: <3f45484f$1_6@corp.newsgroups.com> <3F45A7BF.4060806@nyc.rr.com> <8dk1b.2825$Ej6.1159@newsread4.news.pas.earthlink.net> Message-ID: "Andrew Dalke" wrote previously: |I've seen David Mertz' xml_pickle code which makes good use of |[metaclasses], but don't yet follow how it works. I'm afraid I must insist here that the use of metaclasses in gnosis.xml.pickle is utterly trivial, and just for show. You'll have to look elsewhere for "good use" of them :-). Yours, David... -- mertz@ _/_/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY: \_\_\_\_ n o gnosis _/_/ Postmodern Enterprises \_\_ .cx _/_/ \_\_ d o _/_/_/ IN A WORLD W/O WALLS, THERE WOULD BE NO GATES \_\_\_ z e From ask at me.com Mon Aug 25 22:39:28 2003 From: ask at me.com (Greg Krohn) Date: Tue, 26 Aug 2003 02:39:28 GMT Subject: modifying method behaviour References: Message-ID: "Craig Zoretich" wrote in message news:e7d0b08f.0308251612.cf5c9bd at posting.google.com... > > class logger: > > def __init__(self, func): > > self.func = func > > def __call__(self, *args): > > print "Called: %s with args %s" % (self.func.func_name, args) > > return self.func(self, *args) > > > > class myClass: > > def myfunc(self, a): return a > > > > myfunc = logger(myfunc) I changed a couple of things, so this seems to work: class Logger: def __init__(self, func): self.func = func def __call__(self, *args): print "Called: %s with args %s" % (self.func.func_name, args) #Got rid of that 'self' all together return self.func(*args) class MyClass: def __init__(self): #Created the logged method in the class's __init__ self.myFunc = Logger(self.myFunc) def myFunc(self, a): return a if __name__ == "__main__": m = MyClass() print m.myFunc('Testing...') HTH, greg From adalke at mindspring.com Fri Aug 1 16:55:09 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Fri, 1 Aug 2003 14:55:09 -0600 Subject: time, calendar, datetime, etc References: <153fa67.0307300326.45a29380@posting.google.com> <1sScnW0Sv7DzrrSiRTvUpQ@speakeasy.net> Message-ID: Ben Finney: > It is astronomy (and, before it, astrology) that has driven the > standardisation of time for many centuries; anyone wanting to use a > standardised time system is using one based on astronomical imperatives. And here I thought it was the railroads which drove the standarization. Before then, each city had its own noon, and the only standarization between places was for dates. (Except also depending on your faith.) Granted, "noon" is an astronomical measurement, just that the actual time changed from place to place. Kinda depends on what you call "standard". And before trains, ships wanted to know the time to know the location, and monks wanted to know when to pray, and .. So again I say, most people don't care that much about the time. A useful library doesn't need to incorporate all the details needed by astronomers, historians, etc. > Anyone who wants to deal with dates BC (in the Gregorian calendar) cares > about the "was there a year 0?" question (answer: not in the Gregorian > calendar, there wasn't). > > So it seems you're dismissing a large sector of users: those who deal > with dates before 1AD, and those who want to use worldwide date/time > standards. That's not in disagreement with what I said. I said (though more loosely) 99+% of the people who are affected by the restrictions of datetime won't notice a problem. The remaining <1% might still be "a large sector of users". For them I say, develop a library which deals with all that complexity (or use the mx package). Python doesn't try to support all numerical systems - that's why Numeric exists. Would those users like Numeric support in core Python? Probably. Are there more Numeric users than people who need a detailed datetime library? Almost certainly yes. So I aks again, what makes datetime with B.C. support, leap seconds, etc. important enough to justify inclusion in Python's standard library. By comparison, a friend of mine mentioned that the Java time library, which does try to include all these complexities, has gone through several iterations to get where it is now and is complicated to use because it tries to get all the details right. > Such people would run into trouble when leap seconds occurred anyway; Ha! None of my code ever used leap seconds, and in my 15 years or so of software development, no one ever filed a bug report on it. And on the plus side, I don't have to distribute an update when there is an new leap second. That's because for just about everyone in the world, a difference of a few seconds doesn't make a difference. C'mon - the clocks in my house are +/- a few minutes! It's only the very small number of people who care about the differences between UTC, UT1, GPS, TAI, and all those other highly specialized time systems that care about these sorts of details ("care" == "affects them in any meaningful way"), so what's wrong with those people developing a specialized library to handle those issues? > keeping the datetime module ignorant of it just means the problems will > not be dealt with when the program is designed (when it is easy to > correct) but rather be thrust in their face when a leap second occurs > (presumably when the program has been long forgotten about and the > original programmer possibly departed). Easy to correct? Okay, the last leap second was added 1/1/99. Did you upgrade some data file then to include that change? Or did your software fix itself automatically? Or did you just synch your machine to network time and figure it was part of normal clock skew? > Quite the reverse. If the standard library supported things like leap > seconds, absence-of-year-zero, and Julian dates, it would be wrapped up > in one place where programmers could use it without having to know about > the implementation complexities. Implement that library, get people to use it, implement the functionality of the datetime module using it, make sure it's maintainable and maintained, petition for its inclusion in Python. Then again, you could just use mxDateTime. Here's another view of the issue. The datetime module implements what I'll call "vernacular" time. That is, time as is understood by most people. 24 hours in a day, 60 minutes in an hour, 60 seconds in a day, 365 days in a year except every 4th year (and hazy idea about something strange at the century mark, but that's not a problem now). And then there's timezones and daylight savings time. (And no thoughts of "double daylight savings like the British had during WWII.") datetime implements vernacular time. There's a lot of code which implements vernacular time, because they aren't written by experts. To them, 1) datetime makes sense and 2) won't ever cause problems in real life. I am one of those people. I would like to replace my hand-written code with a standard library. I want that library to implement *my* time system, not the so-called real one developed by experts who worry about variations in the Earth's rotation nor about scholars who say the first day of the year back in 1000AD was in March. So a robust datetime library almost certainly must implement this vernacular time system, if only for completeness. Consider 'datetime' as the first module for that hypothetical library. It definitely is useful as-is. Now we just have to wait for the rest of it to be implemented. Ahhh, I shoulda been a philosopher. :) Andrew dalke at dalkescientific.com From jorolat at msn.com Sat Aug 2 04:15:34 2003 From: jorolat at msn.com (John Latter) Date: Sat, 02 Aug 2003 09:15:34 +0100 Subject: Problem with Unzipping/Installing Python-2.3.exe References: Message-ID: On 1 Aug 2003 18:54:16 -0700, sjmachin at lexicon.net (John Machin) wrote: >bokr at oz.net (Bengt Richter) wrote in message news:... >> On 1 Aug 2003 15:06:20 -0700, sjmachin at lexicon.net (John Machin) wrote: >> >> >John Latter wrote in message news:... >> >> Hi, >> >> >> >> I downloaded Python-2.3.exe but when I used winzip it kept asking me >> >> if I wanted to replace old files with new ones, and in some instances, >> >> new files with old ones. >> >> >> >> I've never downloaded/installed Python before, and as something of a >> >> computer novice, would like to know what I may be doing wrong! >> >> >> >> This is the link I downloaded from: >> >> >> >> >Windows users should download the Windows installer, Python-2.3.exe >> >> >, run it and follow the friendly instructions on the screen to complete >> >> >the installation. >> > >> >Faced with the 4 clues in the above sentence: >> > >> >(1) "installer" >> >(2) ".exe" >> >(3) "run it" >> >(4) complete absence of any mention of ".zip", "unzip", "Winzip", ..., >> > >> >my expectation would be that one should run the damn thing, not try to >> >unzip it. >> > >> >Do you feel that the instructions were unclear? Do you have any >> >suggestions on how they might be improved? >> > >> I guess for those who are rightfully afraid of any .exe's downloaded from the net, > >Except that the OP's remarks didn't strike me as being those of one >who "fears to tread" :-) > >> a parenthetic reassuring mention in the same paragraph that the MD5 digests and file >> sizes are displayed further down the page might be a small improvement. Then all you >> have to do is trust the folks that created installer and the files and web page ;-) >> > >Indeed. > >In-Timbot-we-trust-ly-yours, > >John I was having a bad day And besides I like unzipping things :) -- John Latter Model of an Internal Evolutionary Mechanism (based on an extension to homeostasis) linking Stationary-Phase Mutations to the Baldwin Effect. http://members.aol.com/jorolat/TEM.html 'Where Darwin meets Lamarck?' Discussion Egroup http://groups.yahoo.com/group/evomech From anthonyr-at-hotmail-dot-com at nospam.com Thu Aug 28 01:00:02 2003 From: anthonyr-at-hotmail-dot-com at nospam.com (Anthony Roberts) Date: Thu, 28 Aug 2003 05:00:02 GMT Subject: Style question... References: <4cd3b.50331$la.863381@news1.calgary.shaw.ca> <3F4D63AD.FBBFCCFB@alcyone.com> <3F4D785A.7A76F620@alcyone.com> Message-ID: > Agreed. If you're going to write code in a particular language, you > should fully embrace the language and its style, or move on to something > that you feel more comfortable with. These kind of crutches will only > serve to bite you later -- they aren't panaceas, and you may forget to > use them or be hobbled when interacting with someone else's code (where > you're not going to convince others to use your crutches). There's also > an indirect effect; if I'm reading someone else's Python code, and, say, > see someone using semicolons as statement delimiters on every line, I'm > not exactly going to be struck with a great deal of confidence. It sits better with me if I have a good idea why I'm doing it. From cappy2112 at yahoo.com Tue Aug 26 18:04:12 2003 From: cappy2112 at yahoo.com (Tony C) Date: 26 Aug 2003 15:04:12 -0700 Subject: Best way to write a file n-bytes long Message-ID: <8d3e714e.0308261404.12045d96@posting.google.com> Does Python have a function that is analogous to C's write() or fwrite()- that is , I want to write a file (of arbitrary data) that is 100K, or 1MB (or more) bytes long.. Both write() and fwrite() in C allow the user to specify the size of the data to be written. Python's write only allows a string to be passed in. Sure, I could create a string that is n Megabytes long, and pass it to write, but it seems as though there should be a better way ??? String manipulation is typically considered slow. st="X" * 1048576 fh=open("junk","wb") fh.write(st) fh.close() thanks From hokiegal99 at hotmail.com Wed Aug 27 19:51:30 2003 From: hokiegal99 at hotmail.com (hokiegal99) Date: Wed, 27 Aug 2003 19:51:30 -0400 Subject: Script Discussion & Critique References: <3F4D31B1.6080802@hotmail.com> <06eqkv4onjh5m4tcbbqkmh8lscaj5niatp@4ax.com> Message-ID: <3F4D4402.3060209@hotmail.com> derek / nul wrote: > here will do OK, I have a few questions about the script at the end of this message: Is this script written well? Is it a good design? How could it be made better (i.e. write to a file exactly what the scipt did)? I hope to use it to recursively find a replace strings in all types of files (binary and text). Thanks for any ideas, pointers or critique... most of the ideas behind the script came from the list. #Thanks to comp.lang.python import os, string print " " print "******************************************************" print " Three Easy Steps to a Recursive find and Replace " print "******************************************************" print " " x = raw_input("1. Enter the string that you'd like to find: ") print " " y = raw_input("2. What would you like to replace %s with: " %x) print " " setpath = raw_input("3. Enter the path where the prgroam should run: ") print " " for root, dirs, files in os.walk(setpath): fname = files for fname in files: inputFile = file(os.path.join(root,fname), 'r') data = inputFile.read() inputFile.close() search = string.find(data, x) if search >=1: data = data.replace(x, y) outputFile = file(os.path.join(root,fname), 'w') outputFile.write(data) outputFile.close() print "Replacing", x, "with", y, "in", fname print " " print "**********" print " Done " print "**********" print " " From fawcett at teksavvy.com Thu Aug 14 10:53:40 2003 From: fawcett at teksavvy.com (Graham Fawcett) Date: Thu, 14 Aug 2003 10:53:40 -0400 Subject: 3 new slogans In-Reply-To: References: Message-ID: <3F3BA274.5080701@teksavvy.com> Nick Vargish wrote: >Graham Fawcett writes: > > > >>or, with apologies to Clarke, >> >> Any sufficiently advanced technology is indistinguishable from Python >> >> > >I'd wear that on a T-shirt. Or, with apologies to Sturgeon: > > 90% of code is crud > The rest is Python > > Brilliant. I'd wear that one on a T-shirt, too. Actually, I'd probably get a big tattoo with both of 'em, and stop wearing T-shirts... -- G From adalke at mindspring.com Fri Aug 1 04:56:01 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Fri, 1 Aug 2003 02:56:01 -0600 Subject: Wow: list of immediate subclasses? References: Message-ID: Carl Banks, responding to Roman Suzi: > __subclasses__ is a list of weak references, so the class can be > collected even though it's listed in __subclasses__. For whatever > reason, class A isn't deleted by reference counts, but cyclic garbage > collection gets it. But I want to know that reason. Why are there any cycles? After all, don't weak-references help break cycles? And in my code before, why do I need to do the gc a few times to force the cycle to be broken? >>> float.__subclasses__() [] >>> class Spam(float): pass ... >>> float.__subclasses__() [] >>> del Spam >>> _ = None # just in case ... >>> float.__subclasses__() [] >>> gc.collect() 0 >>> float.__subclasses__() [] >>> gc.collect() 0 >>> float.__subclasses__() [] >>> gc.collect() 0 >>> gc.collect() 6 >>> gc.collect() 0 >>> float.__subclasses__() [] >>> It's a bit too mysterious for my liking. Andrew dalke at dalkescientific.com From oinkfreddie at oinkshlick.oinknet Sun Aug 17 22:17:16 2003 From: oinkfreddie at oinkshlick.oinknet (Freddie) Date: 18 Aug 2003 12:17:16 +1000 Subject: Python form oriented library References: Message-ID: Caleb Land wrote in news:pan.2003.08.17.20.21.45.109000 at rochester.rr.com: > Hello, > I'm writing a small business accounting type program where the interface > is a bunch of forms that represent tables in a database. The interface is > usually used completely with the keyboard, but the mouse may also be used. > > The software does POS, inventory, accounting, etc. > > The widgets are mostly text entries. > > Are there any Python libraries that are targetted to this style of > interface? > > If not, does anybody have references to libraries/resources in other > languages that might be helpful in designing my own (APIs, design > documents, etc)? > > I've tried googling, but I don't know exactly how to word my request. > > Sincerely, > Caleb Land > (bokonon at rochester.rr.com) > What about crazy people like myself? If you generate a crc32 value with zlib, you occasionally get a negative number returned. If you try to convert that to hex (to test against a stored CRC32 value), it spits out a FutureWarning at me. How rude :) So you end up with stupid things like this in your code: # Disable FutureWarning, since it whinges about us making bad hex values :( import warnings try: warnings.filterwarnings(action='ignore', category=FutureWarning) except NameError: del warnings -- Remove the oinks! From amk at amk.ca Wed Aug 20 12:33:30 2003 From: amk at amk.ca (A.M. Kuchling) Date: Wed, 20 Aug 2003 11:33:30 -0500 Subject: Problem installing ppgplot References: Message-ID: On 20 Aug 2003 12:38:08 GMT, > copying build/lib.linux-i686-2.2/ppgplot.so -> > /homes/emiddelb/local2/lib/python2.2/site-packages Hm. Is the /homes/emiddelb/... directory in Python's path? You can check by doing "import sys ; print sys.path". If the directory isn't in sys.path, you can add it by either setting the PYTHONPATH environment variable before running Python, or by modifying sys.path; it's just a list of strings, so you can do sys.path.append('/homes/....'). If it *is* on the path, then I'm puzzled. Running 'python -v' will cause Python to print out each filename it tries; maybe the file has strange permissions or something. --amk From __peter__ at web.de Fri Aug 22 16:55:12 2003 From: __peter__ at web.de (Peter Otten) Date: Fri, 22 Aug 2003 22:55:12 +0200 Subject: for iteration References: Message-ID: Franck Bui-Huu wrote: > Hello, > > I'm trying to customize a list by overriding __getitem__ method but > this change seems to not work with for iteration. > When I use my customized list in a for iteration, all changes made > in __getitem__ are not take into account. > How can I modify this behaviour ? > > Thanks For the for loop to work properly, you have to overide the __iter__() method, e.g.: class MyList(list): def __getitem__(self, index): """ for the sake of this example convert item to uppercase """ return list.__getitem__(self, index).upper() def __iter__(self): """ implemented using a generator """ for i in range(len(self)): yield self[i] # calls the customized __getitem__() myList = MyList(["alpha", "beta", "gamma"]) # works with __getitem__() for index in range(len(myList)): print myList[index] print # works with __iter__() for item in myList: print item Peter From wtrenker at shaw.ca Fri Aug 8 14:00:13 2003 From: wtrenker at shaw.ca (William Trenker) Date: Fri, 08 Aug 2003 18:00:13 +0000 Subject: Spell Checker Message-ID: <20030808180013.22305e65.wtrenker@shaw.ca> I've been searching the web for a spell checking module for Python. Does anyone know of one? Has anyone seen a Python wrapper for aspell? Thanks, Bill From Adrien.DiMascio at logilab.fr Wed Aug 13 02:13:35 2003 From: Adrien.DiMascio at logilab.fr (Adrien Di Mascio) Date: Wed, 13 Aug 2003 08:13:35 +0200 Subject: how to let compiler do a check before I run In-Reply-To: References: Message-ID: <20030813061335.GA878@logilab.fr> Hi, > Hi. > Try this: http://pychecker.sourceforge.net/ > HTH > Sean You might also want to try this : http://www.logilab.org/pylint/ Cheers, Adrien. -- Adrien Di Mascio LOGILAB, Paris (France). http://www.logilab.com http://www.logilab.fr http://www.logilab.org From aahz at pythoncraft.com Mon Aug 18 16:38:42 2003 From: aahz at pythoncraft.com (Aahz) Date: 18 Aug 2003 16:38:42 -0400 Subject: What's better about Ruby than Python? References: <38ec68a6.0308172319.431a4fde@posting.google.com> Message-ID: In article , Lulu of the Lotus-Eaters wrote: > >The second surest sign that a post is a troll is if the author includes: > >|> This is not a troll. > >The first surest sign that a post is a troll is if the author is: > >|"Brandon J. Van Every" Oh, come on, Brandon is *much* less of a troll than T*m*t*y R*e. Unlike the R**bot, we do some interesting topics out of Brandon, they're just written with such antagonism that I'd be hard-pressed to top them. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From tzot at sil-tec.gr Tue Aug 26 14:11:52 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Tue, 26 Aug 2003 21:11:52 +0300 Subject: file object, details of modes and some issues. References: <3f4b800f_3@mk-nntp-1.news.uk.worldonline.com> Message-ID: <6q6nkv88qb708bc0d6g5vtcg20r4dob3r6@4ax.com> On Tue, 26 Aug 2003 16:43:08 +0100, rumours say that simon place might have written: >is the code below meant to produce rubbish?, i had expected an exception. > >f=file('readme.txt','w') >f.write(' ') >f.read() > >( PythonWin 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] on >win32. ) [snip] > 'w' is (w)rite mode so you can't read from the file, ( any existing file is >erased or a new file created, and bear in mind that anything you write to the >file can't be read back directly on this object.), you get 'IOError: [Errno 9] >Bad file descriptor' if you try reading, which is an awful error description. >BUT this only happens at the beginning of the file? when at the end of the >file, as is the case when you have just written something ( without a backward >seek, see below), you don't get an exception, but lots of rubbish data ( see >example at beginning.) This mode allows you to seek backward and rewrite >data, but if you try a read somewhere between the first character and the end, >you get a different exception 'IOError: (0, 'Error')' This is a bug (reading after writing on 'w' files returns garbage), although I don't know if it is a Python bug or stdio's. It seems to happen only on Windows (Linux and Irix work correctly throwing IOError with errno = 9, "bad file descriptor"), and I don't have a VS6 available now. Anyone out there willing to try? > 'a' is (a)ppend mode, you can only add to the file, so basically write mode >(with the same problems ) plus a seek to the end, obviously append doesn't >erase an existing file and it also ignores file seeks, so all writes pile up >at the end. tell() gives the correct location in the file after a write ( so >actually always gives the length of the file.) but if you seek() you don't get >an exception and tell() returns the new value but writes actually go to the >end of the file, so if you use tell() to find out where writes are going, in >this mode it might not always be right. This is stdio behaviour. Perhaps Python should try to provide a more stable environment than the underlying library as it does in other places. > 'r+' is (r)ead (+) update, which means read and write access, but >don't read, without backward seeking, after a write because it will then read >a lot of garbage.( the rest of the disk fragment/buffer i guess? ) stdio behaviour again. > 'a+' is (a)ppend (+) update mode, which also means read and write, but >file seeks are ignored, No, they're not (on Linux at least). I do use this mode in a script, where I want to append to a file without duplicating data, so I first do a .seek(0), read the existing data, and then do my .write(data). Works fine. >so any reads seems a bit pointless since they always >read past the end of the file! I did try that on Windows (2k SP4) and you are absolutely correct; either opening the file as text or binary, a .seek(0) followed by .read() fetches garbage. I will open a bug report if none other does, but first I would like to know if it's the Windows stdio to blame or not. >returning garbage, but it does extend >the file, so this garbage becomes incorporated in the file!! ( yes really ) Ouch! I replicated that behaviour too... > 'b', all modes can have a 'b' appended to indicate binary mode, i think this >is something of a throw-back to serial comms ( serial comms being bundled into >the same handlers as files because when these things were developed, 20+ years >ago, nothing better was around. ) Treating everything as a file (common API to open, read and write) seemed ingenious to me when I first met Unix 15 years ago; extra calls to accomodate extra features a la ioctl seems fine too. 'nothing better was around' seems strange, sounds as a compromise... what would be / is better? >Binary mode turns off the 'clever' handling >of line ends and ( depending on use and os ) other functional characters ( >tabs expanded to spaces etc ), the normal mode is already binary on windows so Normal mode on windows is text, not binary. AFAIK text mode == binary mode only on *nix (VMS was CR+LF I believe, MAC is CR, MS "Doors" :) and MS Windows is CR+LF, but I haven't used all OS'es since the beginning of time). >binary makes no difference on win32 files. But since in may do on other >o.s.'s, ( or when actually using the file object for serial comms.) i think What would be so different for serial comms? Talking about *nix, by the time that data arrive to the file layer, any 'stty tab?' etc have already been implemented... if your tabs have been converted to spaces because of the line settings, opening the tty in binary mode won't change a thing. And LF's are LF's. >you should actually ALWAYS use the binary version of the mode, and handle the >line ends etc. yourself. ( then of course you'll have to deal with the >different line end types!) > Bit surprised that the file object doesn't do ANY access control, multiple >file objects on the same actual file can ALL write to it!! and other software >can edit files opened for writing by the file object. However a write lock on >a file made by other software cause a 'IOError: [Errno 13] Permission denied' >when opened by python with write access. i guess you need >os.access to test file locks and os.chmode to change the file locks, but i >haven't gone into this, shame that there doesn't appear to be a nice simple >file object subclass that does all this! Writes to the file object actually >get done when flush() ( or seek() ) is called. A File object class with unified locking has been and still is a good idea; I believe you just volunteered to do it? :) > suffice to say, i wasn't entirely impressed with the python file object, then >i remembered the cross platform problems its dealing with and all >the code that works ok with it, and though i'd knock up this post of my >findings to try to elicit some discussion / get it improved / stop others >making mistakes. Indeed, "cross-platformability" is not a trivial task... -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From timr at probo.com Tue Aug 26 02:06:53 2003 From: timr at probo.com (Tim Roberts) Date: Mon, 25 Aug 2003 23:06:53 -0700 Subject: Bug with win32 open and utf-16 file References: <27vekvc6evvn3m5jg8n1en2u42skat42qn@4ax.com> <2i1gkv0s7762vcs85rkdq6uvgk6oitje12@4ax.com> <78egkvg1tu0j1kvedclcefn01hr3vkqh4v@4ax.com> Message-ID: derek / nul wrote: > >>>>> data = file("c:/dash9.eng", "rb").read() >>>>> data[-10:] >>'\r\x00\n\x00)\x00\r\x00\n\x00' > >Interesting, I have just done the same and it would appear that the hexdump >routine is changing 0d to 0a ??? I cut-and-pasted your version of hexdump onto my machine, fetched your dash9.eng file, and ran this: from hexdump import hexdump f = open('dash9.eng','rb').read() print hexdump(f) The output seems to be exactly correct: C:\tmp\x>python xxx.py|head Dump of 32884 Bytes (type ) $00000000 FFFE5300 49004D00 49005300 41004000 40004000 ..S.I.M.I.S.A....... $00000014 40004000 40004000 40004000 40004A00 49004E00 ..............J.I.N. $00000028 58003000 44003000 74005F00 5F005F00 5F005F00 X.0.D.0.t........... $0000003C 5F000D00 0A000D00 0A005700 61006700 6F006E00 ..........W.a.g.o.n. $00000050 20002800 20004400 61007300 68003900 0D000A00 ..(...D.a.s.h.9..... $00000064 09006300 6F006D00 6D006500 6E007400 28004400 ..c.o.m.m.e.n.t.(.D. $00000078 61007300 68002000 39002D00 34003400 43005700 a.s.h...9.-.4.4.C.W. $0000008C 29000D00 0A000900 54007900 70006500 20002800 ).......T.y.p.e...(. $000000A0 20004500 6E006700 69006E00 65002000 29000D00 ..E.n.g.i.n.e...)... I get the same result if I cast the string to a list. What version of Python are you using? -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From ktilton at nyc.rr.com Thu Aug 21 19:57:02 2003 From: ktilton at nyc.rr.com (Kenny Tilton) Date: Thu, 21 Aug 2003 23:57:02 GMT Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> <6dj2kv8ugkieehs7guh786cl40o5lj6mcs@4ax.com> Message-ID: <3F455BF0.5070700@nyc.rr.com> Dave Kuhlman wrote: > Andrew Dalke wrote: > > [snip] > >>The complaint about macros has been their tendency to >>increase a single person's abilities at the cost of overall >>loss in group understanding. I've heard references to >>projects where that didn't occur, but am not swayed >>by it because those seem staffed by people with >>extraordinarily good programming skills almost never >>found amoung the chemists and biologists I work with. > > > I just took a quick look at the "Revised5 Report on the > Algorithmic Language Scheme". Macros in Scheme5 are called > "hygienic macros", so apparently there are some dirty macros that > we should worry about. (defmacro whoops (place &body code) `(let ((x (random 3))) (setf ,place (progn , at code)))) ...wreaks havoc if the code refers to an X it had bound to something else and expected it to be used. otoh: (defmacro c? (&body code) `(lambda (self) , at code)) ...is cool because I can do the anaphoric thing and provide the user with a uniform referent to the instance owning the slot, ala SmallTalk or C++ with "this". > My understanding is that macros came to > Scheme slowly, with resistence, with a good deal of thought, and > with restrictions. > > "More recently, Scheme became the first programming language > to support hygienic macros, which permit the syntax of a > block-structured language to be extended in a consistent and > reliable manner." > > See: > > http://www.schemers.org/Documents/Standards/R5RS/HTML/ > > http://www.schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-3.html > > http://www.schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-7.html#%_sec_4.3 > > I have the same worry that some others on this thread have > expressed, that a macro capability in Python would enable others > to write code that I would not be able to read or to figure out. > Do what I do. Don't look at anyone else's code (if you have to work on it, rewrite it anyway) and never show your code to anyone. Naw, c'mon, everyone seems to be conceding macros are powerful. But you are going to be held back by fear and worry? Well, I am a lispnik, we always opt for power and damn the torpedos, as when we go for the productivity win of untyped variables and give up on bugs strong static typing is supposed to find. -- kenny tilton clinisys, inc http://www.tilton-technology.com/ --------------------------------------------------------------- "Career highlights? I had two. I got an intentional walk from Sandy Koufax and I got out of a rundown against the Mets." -- Bob Uecker From guineapig at pi.be Wed Aug 20 03:43:17 2003 From: guineapig at pi.be (Tom Van den Brandt) Date: Wed, 20 Aug 2003 09:43:17 +0200 Subject: what to do when instance of class fails to initialize ? Message-ID: Hello ! As you might have guessed, I'm one of those newbie-types, comming here, asking questions and stuff... Very specific question, it's probably a bit basic so forgive me if it's stupid to ask... If I have an __init__ for a class and the initialisation can't go through (example: missing or wrong arguments), how do I return an error to the caller (from main() function)? When I do a return statement in the __init__ it says __init__ should return None... I can stop the flow with raise 'BlahBlah'. But then the program exits. What is the nice way to do this ? Tnx, -- Tom Van den Brandt I try... From roy at panix.com Thu Aug 28 08:59:16 2003 From: roy at panix.com (Roy Smith) Date: Thu, 28 Aug 2003 08:59:16 -0400 Subject: Advice to a Junior in High School? References: Message-ID: Tom Plunket wrote: > Learn Python, learn C++, learn Lisp. Understand what you like > and don't like about each of these languages. The most imporant thing you can learn in school is how to learn. Especially in a fast-moving technology field, most of the cutting-edge stuff you learn in school is going to be routine in 5 years and obsolete in 10. Languages come and go. Operating systems come and go. Programming methodologies come and go (flowcharts and coding grids were the range when I got into programming). The constant is knowing how to think and how to learn. In school, people decide what you need to know and spoon-feed it to you. In the real world, you'll need to be able to look around, figure out for yourself what's important, and teach it to yourself. From yaipa at yahoo.com Thu Aug 28 22:41:24 2003 From: yaipa at yahoo.com (yaipa h.) Date: 28 Aug 2003 19:41:24 -0700 Subject: Burn some books (please)... References: Message-ID: <6e07b825.0308281841.321bda3@posting.google.com> David, As a way of saying thanks, I purchased two copies of your fine book. One for myself and one for our local library. Cheers, --Alan mertz at gnosis.cx (David Mertz, Ph.D.) wrote in message news:... > Alex Martelli wrote previously: > |>>Very long ago, some books where burnt in public, > > |Very long as in, Winter 2001/2002, for example? > |...as long of course as the books you burn belong to you, that's a form of > |political speech which is just as acceptable as burning a flag. > > I just want to point out to the readership that many copies of _Text > Processing in Python_ are available at your local bookstore for public > burning. There's heresy in that book! (apparently I trend a bit to far > in an FP direction :-)). > > I think I can speak for Alex in pointing out that _Python in a Nutshell_ > also makes for excellent kindling. > > Yours, David... From raims at dot.com Wed Aug 27 12:10:26 2003 From: raims at dot.com (Lawrence Oluyede) Date: Wed, 27 Aug 2003 18:10:26 +0200 Subject: Tkinter? References: Message-ID: <87vfsjozd9.fsf@voodoo.fake> tjland at iserv.net writes: > Does anyone know a really good tutorial into Tkinter because i want to > learn it. One that is more user friendly would be nice. Thanx in advance. "An Introduction to Tkinter": http://www.pythonware.com/library/tkinter/introduction/index.htm The Python.org page about Tkinter: http://python.org/topics/tkinter/ -- Lawrence "Rhymes" Oluyede http://loluyede.blogspot.com rhymes at NOSPAMmyself.com From adalke at mindspring.com Mon Aug 18 20:30:09 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Mon, 18 Aug 2003 18:30:09 -0600 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: Message-ID: Brandon J. Van Every: > in. So I will observe rhetorically: some of you people waste a *lot* of > energy on games of "who's a troll." Mabye it's time for you to establish a > c.l.p.advocacy newsgroup, to siphon those energies in a particular > direction? But hey, it's your newsgroup. Search all c.l.py for my posts. The first was 1995/09/11, and Google says I made 1,160 posts in the last 8 years. Only two ever use the word troll. And I never said you were a troll. I said that you were labeled a troll ("your troll mark"), and you ain't done nothing to wash it off. > Even as one who hasn't converted to Python yet, that statement is clearly > insane. Why the demand that we raise coils^H^H^H^H^Harms against the incursion of C# / Ruby/ etc. when you youself, in the months since you first posted here, can't make a firm decision for yourself? Me: > > You need to acquire critical reading skills. > No I do not. I was seeking clear verification, and I got what I was looking > for. I suggest that you need to acquire imagination skills. You can't seem > to wrap your head around legitimate reasons for asking a question. As I pointed out in your previous thread, the reasons you stated were not legitimate. You have not corrected my misconceptions in your follow-ups it so I remain unconvinced otherwise. Andrew dalke at dalkescientific.com From fredrik at pythonware.com Wed Aug 13 09:54:49 2003 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 13 Aug 2003 15:54:49 +0200 Subject: Namespaces, classes, and using standard modules References: Message-ID: Dan Rawson wrote: > I would have expected that importing os from the interactive prompt > would have worked, and that the 'import os' statement in MyClass.py > would have been ignored. every module has its own namespace. > Any comments or clues about how this SHOULD work would be appreciated! the manual is a good place to start: http://www.python.org/doc/current/tut/node8.html#SECTION008100000000000000000 http://www.python.org/doc/current/ref/naming.html From scottholmes at sbcglobal.net Fri Aug 8 21:08:30 2003 From: scottholmes at sbcglobal.net (Scott Holmes) Date: Fri, 08 Aug 2003 18:08:30 -0700 Subject: TAB and Enter key in Tkinter Message-ID: <3F34498E.80301@sbcglobal.net> I've noticed that widgets in a Pmw toplevel are navigated by tab key. I find I can tab between the entry fields and the buttons but hitting the enter key after moving to a button does not activate the button. If possible, how do I configure buttons to accept and enter key event? -- --------------------------------------------------------------------- Scott Holmes http://sholmes.ws http://pages.sbcglobal.net/scottholmes scottholmes at sbcglobal.net Independent Programmer/Analyst Passport 4GL PHP HTML Composer PostgreSQL Informix 4GL, SQL --------------------------------------------------------------------- There are more things in heaven and earth, Horatio, than are dreamt of in your philosophy --------------------------------------------------------------------- From andrew-pythonlist at puzzling.org Mon Aug 18 20:49:53 2003 From: andrew-pythonlist at puzzling.org (Andrew Bennetts) Date: Tue, 19 Aug 2003 10:49:53 +1000 Subject: a twisted question In-Reply-To: References: Message-ID: <20030819004953.GA472@frobozz> On Mon, Aug 18, 2003 at 10:23:38PM +0000, xam wrote: > Hi All, > I have got a bit of a complicated situation here: > I need to get buildBot (and hence twisted) running on RH 7.1, which > currently has python 1.5 installed. From browsing newsgroups it appears that > I cannot overwritte 1.5 due to some RH scripts relying on that version. So: > 1) can twisted run on 1.5? I could not find this info in the docs. Current Twisted requires Python 2.2 (it also works with 2.3). > 2) if not, can it run on parallel-installed later version? Sure, although I don't know the details of doing this under Red Hat 7.1. > 3) if so, could someone give me a hint on installing a parallel version? Failing all else, you could download the latest 2.2 (or 2.3) source tarball from python.org, and compile and install it to /usr/local, but then you don't get the benefit of RH's package managment... -Andrew. From jjl at pobox.com Mon Aug 18 18:03:12 2003 From: jjl at pobox.com (John J. Lee) Date: 18 Aug 2003 23:03:12 +0100 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: <3F41208F.40021A68@engcorp.com> Message-ID: <87oeymwrmn.fsf@pobox.com> "John Roth" writes: [...] > It's not so much code blocks. It's that Ruby's syntax gives you one > code block for free in every method call. I don't know what that means. Care to explain a bit more? [...] > All of the Ruby collections implement a .each method, which is essentially [...] > like (using Python syntax): > > collectObj.each() [...] > You can also say: we can do that with for. Well, duh. For is a > statement, not a method call. I don't understand. Why does this matter? I guess you could implement this in Python if you had a burning desire, using __metaclass__ (caveat: never having had such a desire, I've never used metaclasses, so I may be wrong). > To continue on this vein, Ruby directly implements Visitor, Observer, > Delegate and Singleton. I don't particularly like the way it does some > of them, but Python can't claim any one of the four! [...] And so...? John From nav+posts at bandersnatch.org Thu Aug 14 10:04:22 2003 From: nav+posts at bandersnatch.org (Nick Vargish) Date: 14 Aug 2003 10:04:22 -0400 Subject: Is Python your only programming language? References: Message-ID: Tim Rowe writes: > If I want to get something up and running quickly then I go straight > to Python. If thousands of lives depend on the code working right I > would not be allowed to use Python, and, IMHO, quite rightly too. It > just doesn't have what it needs for proving correctness, and adding > those things would scupper the getting things up and running > quickly. So what programming language actually does bridge the gap between "thousands of lives depend on the code working right" and "getting this up and running quickly"? Whenever someone implies that compile-time type checking provides some "proof of correctness", I think about (void *) and am not very convinced. Nick -- # sigmask || 0.2 || 20030107 || public domain || feed this to a python print reduce(lambda x,y:x+chr(ord(y)-1),' Ojdl!Wbshjti!=obwAcboefstobudi/psh?') From tzot at sil-tec.gr Fri Aug 22 21:32:15 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Sat, 23 Aug 2003 04:32:15 +0300 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: <3F41A877.995F9C35@alcyone.com> Message-ID: <7egdkvg5o91v4vso9to985p4oo7k81cptk@4ax.com> On 20 Aug 2003 19:16:01 -0700, davesum99 at yahoo.com (smarter_than_you) topposted: >The real question here is, why haven't we all but Brandon in OUR killfiles? c.l.py and killfiles don't match. Thankfully, the worst killfiling group I have frequented was comp.databases.ms-access, a more-or-less friendly but more aloof group than c.l.py. -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From theller at python.net Thu Aug 7 08:32:36 2003 From: theller at python.net (Thomas Heller) Date: Thu, 07 Aug 2003 14:32:36 +0200 Subject: py2exe: "ImportError: No module named pywintypes" ...?? :-( References: <39c0c7.0308070301.190dff6a@posting.google.com> Message-ID: [posted and mailed] steinhardt at inpro.de (x-herbert) writes: (Herbert, athough you have also sent mail privately to me I prefer to answer on the newsgroup, just for the archives) > Hi, > > I have a small test to "compile" al litle script as a WMI-Tester. The > script include a wmi-wrapper and "insert" the Win32-modeles. > > here the code: > > my "WMI-Tester.py" > ----- > import wmi > computer = wmi.WMI () > for item in computer.Win32_Process (): > print item > ----- Ok. After installing wmi.py and rebooting my machine, this works for me when run from Python. > the py2exe-setup.py > ----- > from distutils.core import setup > setup(name="WMI_tester", scripts=["WMI_tester.py"],) > ----- This script is not complete (but certainly a cut and paste error), you have to add 'import py2exe'. > and the error at > "setup.py py2exe": ... > Traceback (most recent call last): > File "C:\Programme\ActivePython22\Lib\site-packages\Pythonwin\pywin\framework\scriptutils.py", > line 301, in RunScript > exec codeObject in __main__.__dict__ > File "C:\Dokumente und Einstellungen\steinha\Eigene > Dateien\WinProcess\PythonProc\setup-py2exe.py", line 7, in ? > setup(name="WMI_tester", scripts=["WMI_tester.py"],) > File "C:\Programme\ActivePython22\lib\distutils\core.py", line 138, > in setup > dist.run_commands() > File "C:\Programme\ActivePython22\lib\distutils\dist.py", line 893, > in run_commands > self.run_command(cmd) > File "C:\Programme\ActivePython22\lib\distutils\dist.py", line 913, > in run_command > cmd_obj.run() > File "C:\Programme\ActivePython22\Lib\site-packages\py2exe\build_exe.py", > line 604, in run > mf.import_hook(f) > File "C:\Programme\ActivePython22\Lib\site-packages\py2exe\tools\modulefinder.py", > line 126, in import_hook > q, tail = self.find_head_package(parent, name) > File "C:\Programme\ActivePython22\Lib\site-packages\py2exe\tools\modulefinder.py", > line 180, in find_head_package > raise ImportError, "No module named " + qname > ImportError: No module named pywintypes It seems that either your installation is corrupted or py2exe doesn't work with ActiveState Python any longer, py2exe 0.4.1 requires a fairly new build of the win32 extensions (154 or later, IIRC). Mark changed the way the special pywintypes and pythoncom extensions are imported. For me (Python 2.2.2, and a recent win32all) the py2exe build process runs successfully. The deeper problem occurs when the executable is run: c:\wmi\dist\wmi-tester>wmi-tester.exe Traceback (most recent call last): File "", line 1, in ? File "imputil.pyc", line 103, in _import_hook File "", line 52, in _import_top_module File "imputil.pyc", line 216, in import_top File "imputil.pyc", line 271, in _import_one File "", line 128, in _process_result File "wmi.pyc", line 117, in ? File "win32com\client\gencache.pyc", line 435, in EnsureDispatch File "win32com\client\gencache.pyc", line 419, in EnsureModule File "win32com\client\gencache.pyc", line 236, in MakeModuleForTypelib File "win32com\client\makepy.pyc", line 273, in GenerateFromTypeLibSpec File "win32com\client\gencache.pyc", line 449, in AddModuleToCache File "win32com\client\gencache.pyc", line 473, in _GetModule File "imputil.pyc", line 132, in _import_hook File "", line 70, in _finish_import File "imputil.pyc", line 318, in _load_tail ImportError: No module named win32com.gen_py That is because the wmi module uses early binding to get some COM constants described in a type library. For this, one would need to use the --progids option to py2exe, so that the win32com.gen_py directory which contains the makepy output is included into the exe. Unfortunately this only works for *modules* in this directory, and not (yet?) for packages, but wmi requires/creates a package named 565783C6-CB41-11D1-8B02-00600806D9B6x0x1x2 here, and I cannot come up with a quick hack right now, neither do I know how to guess this name. And I don't even find docs for win32com.client.GetObject("winmgmts:"). How can I, from this call, find out the typelib guid and version? Also, I'm not sure if it is a good idea to include the makepy generated modules into the executable. Maybe it would be better to create them at runtime in a subdirectory (and include the makepy module into the exe). Can anyone help? Thomas From blunck at gst.com Mon Aug 18 23:25:07 2003 From: blunck at gst.com (Christopher Blunck) Date: Mon, 18 Aug 2003 23:25:07 -0400 Subject: Pmw.Group font Message-ID: Is it possible to set the font of the tag_text within a Pmw.Group? I have set the font on my Labels within the interior of the Group, and the label font of the Group looks pretty lame. -c From bokr at oz.net Sat Aug 2 12:34:58 2003 From: bokr at oz.net (Bengt Richter) Date: 2 Aug 2003 16:34:58 GMT Subject: bug in file.write() ? References: <13a4e2e3.0307311443.299bd59d@posting.google.com> <3f2b5e60.36345431@news.lexicon.net> <3f2b7816_2@news.vo.lu> Message-ID: On Sat, 02 Aug 2003 10:37:48 +0200, Patrick Useldinger wrote: >Bengt Richter wrote: [Actually this is not the part I (Bengt) wrote, though I agree that a file.write bug per se is unlikely ;-)] >>>This is very unlikely --- it is difficult to determine reliably the >>>available space on a disk or tape volume; if one were really >>>interested, one would do it once before trying to write the file, not >>>before writing each block. No, the expected implementation, which you >>>can check against reality by inspecting the source (fileobject.c), is >>>just to attempt to write, and throw an informative-as-possible >>>exception if the write fails. > >This is actually a CD-RW, and it has no files on it. I have used that >very same CD earlier, and was able to fill it to its max. > >>>Despite the appearance that you have about 6KB margin of safety, you > >The margin is 50%, or 299 000 000 bytes, as you can see below. If I copy >the file via the NT Explorer, it works ok, so the CD-RW is not the problem. > Sorry, I didn't really read your traceback. I went with the "6kb" ;-) I wonder if 1) the error message is for real or is another error condition improperly reported, 2) whether you are in a threaded situation where some kind of race condition could be involved, or 3) whether you could be getting buffer underrun as the real cause for (1), and (4) can you reformat (as opposed to deleting files) the CDRW or use a fresh blank and get the same problem? Perhaps there could be a fragmentation problem? Is the CD-RW set up to look like an ordinary disk to applications? If so, you could try (note file extension ;-) f=file('f:\dfcArchive cheetah 20030731-234648 F.zip_fake', 'wb') million = '-'*(1000*1000) rest = '+'*630592 for m in range(299): f.write(million) f.write(rest) f.close() And see if that gets there. Those are big chunks with no disk read delays, vs shutil's 16k read-source/write-dest loop. This might give a clue for chasing underrun or other timing problems. If there is contention for the the CDRW between threads or processes somehow, maybe you have to arrange for a single writer fed by a queue or such? Hope this gives you a useful idea. Regards, Bengt Richter From grante at visi.com Mon Aug 25 16:26:14 2003 From: grante at visi.com (Grant Edwards) Date: 25 Aug 2003 20:26:14 GMT Subject: python gripes survey References: Message-ID: <3f4a70e6$0$167$a1866201@newsreader.visi.com> In article , Afanasiy wrote: > On Mon, 25 Aug 2003 13:42:00 -0500, sismex01 at hebmex.com wrote: > >>[Afanasiy] >>> Returning a struct in C is >>> easier to deal with than returning a near-mystery tuple in Python. >>> >> >>You *really* *must* *be* *kidding*. > > Last post on this topic, I knew it would get all retarded. Not "all retarded" -- just one post. > Try to figure out what I am actually saying before reading "C > is easier than Python". Since I cannot explain this well enough > to satisfy, I am giving up. Relax. Everybody else understood what you wrote. c.l.p is better than most groups, but this is Usenet. No matter what you write, somebody is going to interpret it as a proposal to cook and eat babies. > I will not post again, feel free to post your snide personal > attacks now hounds. -- Grant Edwards grante Yow! I'm continually at AMAZED at th'breathtaking visi.com effects of WIND EROSION!! From niemeyer at conectiva.com Fri Aug 22 15:30:39 2003 From: niemeyer at conectiva.com (Gustavo Niemeyer) Date: Fri, 22 Aug 2003 16:30:39 -0300 Subject: Metaclass discussons Message-ID: <20030822193039.GA20830@ibook.distro.conectiva> Hi everyone! I was just part of a small discussion concerning metaclass features on Python, and one limitation that was appointed was the inability to redefine metaclasses on existent code. Than I thought it was a good way to explore some more the metaclass concepts.. Basically, people were arguing that there are some uses for that, based on plugging new knowledge on existent classes and instances. Without complaining too much about usage issues, I started looking for ways to dismiss that limitation. Without yet considering interpreter hacks, that's what I had as a first solution (a very limited one, I must admit): class M(type): pass __metaclass__ = M class object: __metaclass__ = M execfile("somemodule.py", globals(), locals()) Can you imagine any alternative which is not based on the same concept (executing the module code on a hacked context)? -- Gustavo Niemeyer http://niemeyer.net From max at alcyone.com Mon Aug 11 14:15:30 2003 From: max at alcyone.com (Erik Max Francis) Date: Mon, 11 Aug 2003 11:15:30 -0700 Subject: Fun with numbers - dammit, but I want a cast! References: <3f378fac$0$10778$afc38c87@auth.uk.news.easynet.net> <3f3792f2$0$18258$afc38c87@auth.uk.news.easynet.net> Message-ID: <3F37DD42.309D383A@alcyone.com> Terry Reedy wrote: > No, quite different. A C cast (at least usually) recasts a block of > bits in a new role without changing the bits. Type constructors > (unless redundant as in int(1)) return a different object with a > different set of bits. Well, the issue is that, in C, a cast can mean a lot of different things. That's why, in C++, casts are separated into template like syntaxes depending on their purpose. The unsafe form of C cast is a reinterpret_cast in C++, and sometimes a const_cast (if you actually cast away constness of a truly const object and then attempt to mutate it). The other two -- static_cast and dynamic_cast -- are "safe" in the sense of being well-defined when the compiler accepts them, and merely invoke a well-defined conversion and do a runtime type cast, respectively. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ Nobody can reach me, nobody can touch me; it's a wonderful feeling. \__/ Aaliyah From alan.gauld at btinternet.com Thu Aug 28 16:46:01 2003 From: alan.gauld at btinternet.com (Alan Gauld) Date: Thu, 28 Aug 2003 20:46:01 GMT Subject: learning to program References: <3F4CED6E.D04D35D6@engcorp.com> <5bspkv87u1q0v9aupajrrkjuutuh3f5o44@4ax.com> <3F4CF363.CAF6A14E@engcorp.com> <6b2qkv4nf549o8clg3bagphd02f92dadub@4ax.com> <3F4D0AC2.EE79D7E4@engcorp.com> Message-ID: <3f4e68f3.1219166518@news.blueyonder.co.uk> On Wed, 27 Aug 2003 18:20:51 -0700, Rich wrote: > During the tutorial it talked about TCI, and gave some commands to do. > I went to the site and downloaded TCI. but was unable to do any of > the tasks. That tutor is now 5 years old so my recommendation is skip over the Tcl bits. I am in the process of rewriting it using Javascript and VBScript instead of Tcl and QBASIC. > I think my question is, when the tutorial say the Dos prompt, do I use > my Dos prompt in windows, or the Dos prompt in the Python program? The Windows DOS prompt, that is the one that looks like C:\WINDOWS> > I am using the Tutorial by Alan Gauld, and I am at the bottom of > simple sequences (left side of page). OK, If you have any specific things about the tutorial (eg something seems broken) send them to me via the mailto link at the bottom opf each web page. Any general quesries about Python send here or to the Python tutor mailing list where more eyes ensure a faster response. Finally, you can still read the Tcl and BASIC sections if you like, they are really there to make the point that the basic concepts of programming apply equally to anyt language, once you learn one (Python say) you can learn most others very quickly. Alan g Author of the Learn to Program website http://www.freenetpages.co.uk/hp/alan.gauld From sdhyok at yahoo.com Sun Aug 24 14:13:32 2003 From: sdhyok at yahoo.com (sdhyok) Date: 24 Aug 2003 11:13:32 -0700 Subject: How to import a standard module in source file with same name? References: <420ced91.0308232052.70e905d5@posting.google.com> Message-ID: <420ced91.0308241013.3023de54@posting.google.com> As Michael indicates, the usage of different case is not a good solution. Daehyok Christos "TZOTZIOY" Georgiou wrote in message news:... > On 23 Aug 2003 21:52:11 -0700, rumours say that sdhyok at yahoo.com > (sdhyok) might have written: > > [snip of problem description as per the subject] > > >Under the condition that the absolute path to the standard module > >is variable in different machines > >(so, imp.find_module may not be a solution), > >is there an elegant way to solve this problem? > > You might try changing the case... call it DateTime for example; there > must be some magic in the C code (if you work on Windows) that matches > in a case-sensitive way. Or you can do (in the importing module, > possibly your main program): > > import datetime > import vp.datetime > vp.datetime.datetime = datetime From irmen at -NOSPAM-REMOVETHIS-xs4all.nl Tue Aug 12 08:23:19 2003 From: irmen at -NOSPAM-REMOVETHIS-xs4all.nl (Irmen de Jong) Date: Tue, 12 Aug 2003 14:23:19 +0200 Subject: os.system('cd dir1 ... and executing next os.system command in that directory (dir1) In-Reply-To: References: Message-ID: <3f38dc37$0$49098$e4fe514c@news.xs4all.nl> Sami Viitanen wrote: > I'm having problems with os.system. > > If I execute some 'cd directory' command with it, after that the script is > on the > same directory level as it was before the command. > > Any ideas ? os.system creates a new process that executes your command. Python's own process is not affected. You'll want to use os.chdir instead :-) --Irmen From duncan at NOSPAMrcp.co.uk Fri Aug 8 09:45:49 2003 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Fri, 8 Aug 2003 13:45:49 +0000 (UTC) Subject: Accessing c objects in python References: Message-ID: Thomas Heller wrote in news:smocwafb.fsf at python.net: > Would you care to write a more detailed summary of your findings? This > would probably make a good page in the main Python wiki... > I did an evaluation of the various ways to link to Python for the ACCU conference this year, although I must say my conclusion was slightly different than Alex's: I would use Pyrex in preference to SWIG even if I didn't want to embed much code in the interface. You can find a paper describing my views at: http://dales.rmplc.co.uk/Duncan/accu/integratingpython.html The slides and source code for the talks are also on the same site. See http://dales.rmplc.co.uk/Duncan/accu -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From theller at python.net Thu Aug 7 09:33:48 2003 From: theller at python.net (Thomas Heller) Date: Thu, 07 Aug 2003 15:33:48 +0200 Subject: py2exe problems References: Message-ID: "Alessandro Crugnola *sephiroth*" writes: > Hi, > i'm trying to compile a .py script using py2exe into a win .exe file. > In that script i'm using xml.dom.minidom to parse an xml file (with the iso8859-1 encoding) > > i've included in the setup command line the --packages encodings > but once i launch the exe file i receive this error in the console window: > > Traceback (most recent call last): > File "", line 51, in Notify > File "", line 105, in __init__ > File "WindowsSnippets.pyc", line 27, in __init__ > File "WindowsSnippets.pyc", line 135, in loadXML > File "xml\dom\minidom.pyc", line 1915, in parse > File "xml\dom\expatbuilder.pyc", line 924, in parse > File "xml\dom\expatbuilder.pyc", line 207, in parseFile > LookupError: no codec search functions registered: can't find encoding > > how can i solve the issue? Which Python version are you using? 2.3 doesn't yet work correctly, but 2.2 should be ok. Thomas From vanevery at 3DProgrammer.com Tue Aug 19 05:12:27 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Tue, 19 Aug 2003 02:12:27 -0700 Subject: Brandon's priorities, to your relief Message-ID: Ok, I've played the posting game until 2 am. It was a good run instead of playing something mindless like Diablo II again. Thats said, I could have finished "Childhood's End" instead. Tangible today was 1 more Python type-treatment. To those of you who took my Ruby questions at face value, and answered them perfunctorily, thanks! I got the information I wanted and the conclusions haven't surprised me. To those who might still be game for a little Troll Hunting, well, smooches, I missed you this time but my killfile will still be there for you later. Unsubscribing for now, to concentrate on marketing-python. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From postmaster at 127.0.0.1 Thu Aug 21 05:07:20 2003 From: postmaster at 127.0.0.1 (David McNab) Date: Thu, 21 Aug 2003 21:07:20 +1200 Subject: how fast is Python? References: <3f43e5cf$0$49115$e4fe514c@news.xs4all.nl> Message-ID: On Thu, 21 Aug 2003 06:40:04 +0200, Michael Peuser paused, took a deep breath, then came out with: > A bottleneck can be Tkinter. Use something different then (Qt, wx).. Wow! I've found wx to be way slower than Tkinter. On a P133 running Win98, a McMillan-compiled prog using wx took twice as long to start up as a similar prog implemented in Tkinter. From jorolat at msn.com Sat Aug 2 04:24:05 2003 From: jorolat at msn.com (John Latter) Date: Sat, 02 Aug 2003 09:24:05 +0100 Subject: Problem with Unzipping/Installing Python-2.3.exe References: Message-ID: > On 1 Aug 2003 15:06:20 -0700, sjmachin at lexicon.net (John Machin) wrote: > > >John Latter wrote in message news:... > >> Hi, > >> > >> I downloaded Python-2.3.exe but when I used winzip it kept asking me > >> if I wanted to replace old files with new ones, and in some instances, > >> new files with old ones. > >> > >> I've never downloaded/installed Python before, and as something of a > >> computer novice, would like to know what I may be doing wrong! > >> > >> This is the link I downloaded from: > >> > >> >Windows users should download the Windows installer, Python-2.3.exe > >> >, run it and follow the friendly instructions on the screen to complete > >> >the installation. > > > >Faced with the 4 clues in the above sentence: > > > >(1) "installer" > >(2) ".exe" > >(3) "run it" > >(4) complete absence of any mention of ".zip", "unzip", "Winzip", ..., > > > >my expectation would be that one should run the damn thing, not try to > >unzip it. > > > >Do you feel that the instructions were unclear? Do you have any > >suggestions on how they might be improved? > > > I guess for those who are rightfully afraid of any .exe's downloaded from the net, > a parenthetic reassuring mention in the same paragraph that the MD5 digests and file > sizes are displayed further down the page might be a small improvement. Then all you > have to do is trust the folks that created installer and the files and web page You're trying to make me look stupid. The instructions would have been far clearer if they had said: >Windows users should download the Windows installer, Python-2.3.exe >, run it, but Whatever You Do DON'T UNZIP THE FREAKIN' THING - This Means YOU John Latter!, and follow the friendly instructions on the screen to complete >the installation. To make the instructions even friendlier it would also help if "but Whatever You Do DON'T UNZIP THE FREAKIN' THING - This Means YOU John Latter!" were in large, bold, and underlined type. And preferably a different colour. I've reread what I've typed above and as far as I'm concerned its close to being a literary masterpiece. I rest my case -- John Latter Model of an Internal Evolutionary Mechanism (based on an extension to homeostasis) linking Stationary-Phase Mutations to the Baldwin Effect. http://members.aol.com/jorolat/TEM.html 'Where Darwin meets Lamarck?' Discussion Egroup http://groups.yahoo.com/group/evomech From mhammond at skippinet.com.au Tue Aug 19 18:08:12 2003 From: mhammond at skippinet.com.au (Mark Hammond) Date: Wed, 20 Aug 2003 08:08:12 +1000 Subject: win32com and com Record types In-Reply-To: References: Message-ID: Mike Margerum wrote: > Hi I am trying to using a COM server I built in C++. I ran GenPy on > my type library and I am able to instantiate objects from the server. > What I can't figure out is how to create/use Record types from my COM > server. I see them defined in my generated py file as a map > > RecordMap = { > 'FormRecord': '{F6EBBC2A-E2D5-4921-A498-EA80AE851012}', > 'ICD9Record': '{FA83723F-55F6-4D17-8309-A9D323A4FD01}', > 'BrandRecord': '{AD4B5647-E78A-447B-A041-EEC59E89D3F6}', > } > > How Do i instantiate one so I can use it in one of my methods that > takes a BrandRecord by reference? > > This is a snippet of VB code that works > > Dim db As New BrandDb > db.Open ("c:\temp\irx2_brand.pdb") > Dim brandRec As BrandRecord > While i < db.RecordCount > db.GetBrand i, brandRec, 1 'use 0 instead of 1 to not load > form data > List1.AddItem brandRec.MasterIndex & " " & brandRec.Id & " " & > brandRec.Description You can create a record object by using: r = win32com.client.Record("RecordName", object) where "RecordName" is the name of the record, and 'object' is &any* COM object defined in the same type library. See win32com\test\testvb for some real examples. Mark. From tzot at sil-tec.gr Sat Aug 23 08:52:58 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Sat, 23 Aug 2003 15:52:58 +0300 Subject: installing Tix References: <731fc603.0308191124.18bd3f8e@posting.google.com> Message-ID: <7toekv0d6mbfi99qldkmhbaod0f0i2rpsp@4ax.com> On 19 Aug 2003 12:24:20 -0700, rumours say that soundwave56 at yahoo.ca (Hank) might have written: >Hi, > >I'm trying to install Tix and I thought the best way to do that is >thru IDEStudio. Check this post: http://groups.google.com/groups?selm=m3smrqc8sd.fsf at mira.informatik.hu-berlin.de This one worked for me (on Windows). I believe I just put the tix8184.dll in the DLLs folder and the tix8.1 subfolder inside the tcl subfolder. -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From sjmachin at lexicon.net Sat Aug 2 19:16:16 2003 From: sjmachin at lexicon.net (John Machin) Date: 2 Aug 2003 16:16:16 -0700 Subject: How do I get a reference to a KEY value of a dictionary? References: <645db655.0307311636.71923378@posting.google.com> Message-ID: "Andy C" wrote in message news:... > I don't see how I can do this and let me eliminate duplicates. I need to > assign the old duplicate string to the unique string that already exists. > Hence the question, how do I get a reference to the KEY value? I know I can > use keys() and do a linear search, but that is much more inefficient. I > would like to get a reference to the key value in the same time that it > takes to do a hash lookup (constant time). > > Basically I would want to rewrite this section of the code I posted: > > nodes = self.nodes > if nodes.has_key( node2 ): > node2 = nodes[ node2 ] > else: > nodes[ node2 ] = node2 > > This dictionary seems stupid, I agree. The keys and values are the same. > But in the first part of the if, I want to reassign node2 to an equivalent > string that already exists. How can I do that? > > The intern solution seems reasonable, and it appears that it was designed > specifically for this problem. I wasn't aware of the implementation > problems. But I'm still curious about different ways to do it. > Google("intern-like memory saver"). From gregnans at yahoo.PAS.DE.SPAM.fr Tue Aug 19 10:27:44 2003 From: gregnans at yahoo.PAS.DE.SPAM.fr (Gregory Nans) Date: Tue, 19 Aug 2003 16:27:44 +0200 Subject: (newbie) Zope... Message-ID: hello, i'm looking for a gentle introduction to zope, dealing with database connections and sessions handling. Is there any case study out there ? (or some kind of phpbuilder articles ?) or does someone have code that could fit as a zope self introduction for someone coming from php ? thanks. From pedro.werneck at bol.com.br Sun Aug 17 16:25:13 2003 From: pedro.werneck at bol.com.br (Pedro Werneck) Date: Sun, 17 Aug 2003 20:25:13 +0000 Subject: Python form oriented library In-Reply-To: References: Message-ID: <20030817202513.05600eb3.pedro.werneck@bol.com.br> Try Kiwi, http://www.async.com.br/kiwi. It was developed for this sort of problem... On Sun, 17 Aug 2003 20:21:25 GMT Caleb Land wrote: > Hello, > I'm writing a small business accounting type program where the interface > is a bunch of forms that represent tables in a database. The interface is > usually used completely with the keyboard, but the mouse may also be used. > > The software does POS, inventory, accounting, etc. > > The widgets are mostly text entries. > > Are there any Python libraries that are targetted to this style of > interface? > > If not, does anybody have references to libraries/resources in other > languages that might be helpful in designing my own (APIs, design > documents, etc)? > > I've tried googling, but I don't know exactly how to word my request. > > Sincerely, > Caleb Land > (bokonon at rochester.rr.com) > -- > http://mail.python.org/mailman/listinfo/python-list From pjoshi at bandbprintshop.net Wed Aug 20 10:33:59 2003 From: pjoshi at bandbprintshop.net (Your Name) Date: Wed, 20 Aug 2003 09:33:59 -0500 Subject: On Creating Codecs Message-ID: Hi, I have been trying to generate codecs for my language in Python using gencodec.py. The problem is the codec created does not work. Here is the process that I followed. I created a directory inside [python_installation]/tools/scripts and put in a text file containing the mapping. Here is a sample from it. 0x63 0x0915 # acsii letter c 0x64 0x0916 0x65 0x0917 # ascii letter e 0x66 0x0918 0x67 0x0919 As my Language was not standardized before Unicode, I have to use fonts that have been developed using the ascii character set. Now in the table I map ascii representative values to the char encoding in Unicode. Now using gencodec.py I generate the codecs. It gives me a py script file, which I placed in the [python_installation]/lib/encodings directory. Now I try to use the codec from the shell and below is my session on it. >>> string = 'cde' >>> string.encode('nepali') Traceback (most recent call last): File "", line 1, in ? string.encode('nepali') File "C:\Python22\lib\encodings\nepali.py", line 18, in encode return codecs.charmap_encode(input,errors,encoding_map) UnicodeError: charmap encoding error: character maps to >>> I may be doing something wrong. Can you please tell me how to go about it. I am using Python 2.2 on Windows XP. Thank you. PRJoshi From mat at frheaven.com Sun Aug 3 13:34:00 2003 From: mat at frheaven.com (Matthieu M.) Date: Sun, 03 Aug 2003 19:34:00 +0200 Subject: Python and XML Message-ID: Hi! I want to make an application that needs to parse an xml file, but I always have weird errors, I've got Python 2.3 Here's the beginning of my prog: from xml.dom import pulldom and here's python's answer: Traceback (most recent call last): File "xml.py", line 1, in ? from xml.dom import pulldom File "C:\progs\xml.py", line 1, in ? from xml.dom import pulldom ImportError: No module named dom When I look in my Python folder I see .py files in xml/dom... Thanks for any help. -- Matthieu M. http://www.frheaven.com From crayfish at comcast.net Tue Aug 12 18:19:21 2003 From: crayfish at comcast.net (Rich) Date: Tue, 12 Aug 2003 15:19:21 -0700 Subject: Is Python your only programming language? References: Message-ID: "John Machin" wrote in message news:c76ff6fc.0308121149.67b320fa at posting.google.com... > > How does one "ork" and what is the effect on the cow? What is the > RSPCA's attitude to this? There is a page on orking here: http://www.monkeon.co.uk/orking/ The RSPCA is fine with it.... see ya, Rich. (formerly of JMI in Carlton, way back when Colonial had it. :-) From skip at pobox.com Fri Aug 22 16:47:39 2003 From: skip at pobox.com (Skip Montanaro) Date: Fri, 22 Aug 2003 15:47:39 -0500 Subject: Script to remove SoBig/F virus from POP3 mailbox In-Reply-To: References: Message-ID: <16198.33131.159715.770879@montanaro.dyndns.org> Alex> Under the gun, I've written a Python script to delete emails Alex> containing this latest virus/worm (Sobig-F) from a POP3 mailbox. ... I wrote something similar today for scrubbing Mailman 2.1 pending administrative requests. I've killed over a thousand messages for the python-help mailing list so far. It's crude, but saves a huge amount of pointing and clicking. If you'd like a copy, drop me a note. If enough people are interested and it seems like there's no other easy way to accomplish this with the usual Mailman means, I'll place a copy on my website. Skip From ayc8NOSPAM at cornell.edu Sat Aug 2 06:05:17 2003 From: ayc8NOSPAM at cornell.edu (Andy C) Date: Sat, 02 Aug 2003 10:05:17 GMT Subject: How do I get a reference to a KEY value of a dictionary? References: <645db655.0307311636.71923378@posting.google.com> Message-ID: I don't see how I can do this and let me eliminate duplicates. I need to assign the old duplicate string to the unique string that already exists. Hence the question, how do I get a reference to the KEY value? I know I can use keys() and do a linear search, but that is much more inefficient. I would like to get a reference to the key value in the same time that it takes to do a hash lookup (constant time). Basically I would want to rewrite this section of the code I posted: nodes = self.nodes if nodes.has_key( node2 ): node2 = nodes[ node2 ] else: nodes[ node2 ] = node2 This dictionary seems stupid, I agree. The keys and values are the same. But in the first part of the if, I want to reassign node2 to an equivalent string that already exists. How can I do that? The intern solution seems reasonable, and it appears that it was designed specifically for this problem. I wasn't aware of the implementation problems. But I'm still curious about different ways to do it. > That makes some sense, but why use the string object for both key and > value? Just do > > d[key] = True > > You could optimize your coding style (if not your speed) in Python 2.3 > by using sets. I'd recommend against using intern(), because in Python > 2.2 and earlier, interned strings *never* get garbage collected. Even > in Python 2.3, you may end up with worse memory behavior. > -- > Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ > > This is Python. We don't care much about theory, except where it intersects > with useful practice. --Aahz From bokr at oz.net Fri Aug 1 15:27:01 2003 From: bokr at oz.net (Bengt Richter) Date: 1 Aug 2003 19:27:01 GMT Subject: Singleton-like pattern References: <2259b0e2.0308010815.5dcb0b58@posting.google.com> Message-ID: On 1 Aug 2003 09:15:34 -0700, mis6 at pitt.edu (Michele Simionato) wrote: >pedro.werneck at bol.com.br (Pedro Werneck) wrote in message news:... >> I need to implement an object that behaves just like imutable objects, >> like int, str and tuple: if you create two objects with the same value >> at the same time, you get the same object, like a singleton, but >> instead of storing a unique object, store a set of objects, with no >> duplicates. I don't know if this is a common pattern (and if there's a >> name for it), but I remember reading something about it some time >> ago... the ASPN cookbook has some similar patterns, but none works for >> me... >> >> I know there are several ways to implement this, but I think this >> metaclass approach is more elegant than using __new__ and >> inheritance... at least it solves my problem (I'm working on a card >> game) but I am sure that there are better ways to do it... I could not >> find any other value suitable as a key and using str(args) + str(kwds) >> is ugly and easy to break... >> >> >> class MultiSingleton(type): class MultiSingleton(object): >> def __call__(cls, *args, **kwds): def __new__(cls, *args, **kwds): >> cache = cls.__dict__.get('__cache__') >> if cache is None: >> cls.__cache__ = cache = {} >> tag = str(args) + str(kwds) tag = '%r%r'% (args, kwds) # might be an alternative >> if tag in cache: >> return cache[tag] >> obj = object.__new__(cls) >> obj.__init__(*args, **kwds) >> cache[tag] = obj >> return obj >> >> >> Any help will be much appreciated... thanks in advance >> >> Pedro Werneck > >"memoize" is a possible name for this. Notice that the metaclass is a >bit of overkill, you may well use a simple function for this job. Why not just change as above, and sublass to inherit the behavior (and create subclass-specific caches) ? >About the issue of finding a suitable key, in the same situation I have >used the tuple (args,kw) as key. But me too I would like to ask if this is a >good idea. What's the custom solution for getting a good key from >a dictionary ? Does (args,kw) work in general? IWT you could easily get something unhashable? IWT using a tuple of actual args may also be a bad idea since it would prevent callers' temp args from being garbage collected. I use repr to avoid that, maybe mistakenly? Regards, Bengt Richter From logistix at cathoderaymission.net Sun Aug 31 14:44:07 2003 From: logistix at cathoderaymission.net (logistix at cathoderaymission.net) Date: 31 Aug 2003 11:44:07 -0700 Subject: Update to Python 2.3 on Red Hat Linux 9 References: <8242f4a7.0308282240.4c87f997@posting.google.com> Message-ID: <3c91a864.0308311044.c931940@posting.google.com> jaybromley at hotmail.com (Jay Bromley) wrote in message news:<8242f4a7.0308282240.4c87f997 at posting.google.com>... > Hello, > > I've got a Red Hat Linux 9 system with Python 2.2.2 and I would like > to update to Python 2.3. I got the 2.3 source and built and installed > it. Python 2.3 itself works but it doesn't have access to a lot of > packages that are available to Python 2.2.2. For example, > pygtk-1.99.14 and Tkinter work fine with 2.2.2, but in 2.3 I can't do > 'import gtk' or 'import _tkinter'. I checked the pygtk site and they > say I've got to recompile pygtk for the new Python. I'm hoping there > is a better answer. The problem is a lot of RedHat stuff depends on > Python and the packages available to 2.2, but I need 2.3 and I don't > want to junk the applications based on Python 2.2 and the current > packages. > > So the questions is, can I build Python 2.3 so that it recognizes all > the packages that are available to Python 2.2.2? Is this LD_RUN_PATH > stuff? Or do I really need to find out all the libraries in use with > 2.2.2 and compile these for 2.3? > > I'd appreciate any pointers or references to documentation. I *really* > want 2.3. > > Thank you, > Jay Bromley > jaybromley at hotmail.com You can use 'make altinstall'. This only creates a 'python2.3' executable and leaves 'python' linked to the one redhat expects. You can then explicitly force python2.3 where required with "#!/usr/local/bin/python2.3" in your personal scripts. From gherron at islandtraining.com Mon Aug 25 11:08:03 2003 From: gherron at islandtraining.com (Gary Herron) Date: Mon, 25 Aug 2003 08:08:03 -0700 Subject: Python 2.3 problem In-Reply-To: <51092f25c1b12d2bedc9c63d2dfa14f3@dizum.com> References: <51092f25c1b12d2bedc9c63d2dfa14f3@dizum.com> Message-ID: <200308250808.03439.gherron@islandtraining.com> On Sunday 24 August 2003 01:00 pm, Nomen Nescio wrote: > Hi > > When I does this like hear failre goes: > > def pinhtranh(*args, laoc_te): > phnoi_crek(args, laoc_te) > > I do "laoc_te" last praemetr name always. > > > Qinh The syntax of Python does not allow this, but perhaps the following will do what you want. The two lines in pinhtranh will set "laoc_te" to the last argument, and "args" to a tuple of all except for the last argument. def pinhtranh(*allArgs): args = allArgs[:-1] laoc_te = allArgs[-1] ... I hope that's what you wanted. Gary Herron From Russell.Every at MentumGroup.com Tue Aug 19 00:53:17 2003 From: Russell.Every at MentumGroup.com (Russell) Date: 18 Aug 2003 21:53:17 -0700 Subject: SOAP using ZSI talking to .NET Web Service Message-ID: <76ab2b2b.0308182053.4b9beea3@posting.google.com> Using Python 2.3 and ZSI 1.2 I am having problems getting information back from a test web service running on a PC on our LAN. The SOAP request details (from the .asmxfile) are as follows: POST /rjetest/rjetestservice.asmx HTTP/1.1 Host: grouse Content-Type: text/xml; charset=utf-8 Content-Length: length SOAPAction: "http://RJE.com/RJETestItDoc" int string and the response details (from the .asmx) are: HTTP/1.1 200 OK Content-Type: text/xml; charset=utf-8 Content-Length: length string The Python program is: import sys from ZSI.client import Binding, TC class fooRequest: def __init__(self, i, extra): self.i = i self.extra = extra fooRequest.typecode = TC.Struct(fooRequest, [TC.Integer('i'), TC.String('extra')], 'RJETestItDoc') url1 = 'http://grouse/rjetest/rjetestservice.asmx' soapaction ='http://RJE.com/RJETestItDoc' namespace = 'http://RJE.com' host = 'grouse' port = 80 dict = { 'soap' : 'http://schemas.xmlsoap.org/wsdl/soap/', 's' : 'http://www.w3.org/2001/XMLSchema', 's0' : 'http://RJE.com', 'http' : 'http://schemas.xmlsoap.org/wsdl/http/', 'tm' : 'http://microsoft.com/wsdl/mime/textMatching/', 'mime' : 'http://schemas.xmlsoap.org/wsdl/mime/', 'soapenc' : 'http://schemas.xmlsoap.org/soap/encoding/' } i = 10 extra = 'A lovely day at the office' b = Binding(url=url1, ns=namespace, host=host, port=port, nsdict=dict, soapaction=soapaction, tracefile=sys.stdout) b.Send(url1, 'RJETestItDoc', fooRequest(i, extra)) x = b.ReceiveSOAP() The SOAP response via the Python program is: ********** A lovely day at the office ********** and looks fine (to me anyway). However... I can't figure out how to get the text from response. Any advice would be very much appreciated. The input values are being correctly received by the web service. From jacek.generowicz at cern.ch Wed Aug 20 03:01:06 2003 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 20 Aug 2003 09:01:06 +0200 Subject: What's better about Ruby than Python? References: <38ec68a6.0308181659.1aab5c67@posting.google.com> Message-ID: "Fredrik Lundh" writes: > Jacek Generowicz wrote: > > > > Python's firmly in the "always half-open" field (pioneered in print, > > > to the best of my knowledge, in A. Koenig's "C Traps and Pitfalls", > > > > I seem to recall seeing a scanned-in copy of a hand-written talk by > > Dijkstra, on this. > > this one? > > "Why numbering should start at zero" > http://www.cs.utexas.edu/users/EWD/ewd08xx/EWD831.PDF Bingo ! Thanks. From abuseonly at sgrail.org Wed Aug 20 21:47:44 2003 From: abuseonly at sgrail.org (derek / nul) Date: Thu, 21 Aug 2003 01:47:44 GMT Subject: Newbie problem with codecs Message-ID: Good people I am writing my first python program, so be gentle :-) This program needs to r/w UTF16LE files. When I run the program I get the following error Traceback (most recent call last): File "apply_physics.py", line 12, in ? codecs.lookup(BOM_UTF16_LE) NameError: name 'BOM_UTF16_LE' is not defined Could someone point to my mistake please? Derek ============================== #!c:/program files/python/python.exe # # win32 python 2.3 import sys, string import codecs codecs.lookup(BOM_UTF16_LE) From mpeuser at web.de Wed Aug 13 03:20:09 2003 From: mpeuser at web.de (Michael Peuser) Date: Wed, 13 Aug 2003 09:20:09 +0200 Subject: unsigned int \ long References: Message-ID: Have a look at Library Reference 4.3: struct But you should explain a litle bit more what your problem is.... Kindly Michael P "Roman Yakovenko" schrieb im Newsbeitrag news:mailman.1060753100.20465.python-list at python.org... Hi. I need to work with integer as unsigned integer, but I can't find documentation how can I do it. Some reference on this will be appreciated. For example (unsigned int)(-1) == 0xFFFFFFFF. Thanks. Roman. From peter at engcorp.com Thu Aug 21 11:09:16 2003 From: peter at engcorp.com (Peter Hansen) Date: Thu, 21 Aug 2003 11:09:16 -0400 Subject: Backtick Virgins References: Message-ID: <3F44E09C.D97D43F0@engcorp.com> Carl Banks wrote: > > Who else? Five? From logiplex at qwest.net Tue Aug 12 18:24:21 2003 From: logiplex at qwest.net (Cliff Wells) Date: Tue, 12 Aug 2003 15:24:21 -0700 Subject: Python vs. C# In-Reply-To: <3f3959e3_1@news.vo.lu> References: <2259b0e2.0308100616.55b651ca@posting.google.com> <3f36af20@shknews01> <3f3959e3_1@news.vo.lu> Message-ID: <1060727060.4769.79.camel@software1.logiplex.internal> On Tue, 2003-08-12 at 14:21, Patrick Useldinger wrote: > Brandon J. Van Every wrote: > > > [...] > > Some time ago, you started a similar discussion on C++ vs. Python. You > pretended to be just as objective, and you turned out to be just as > decided as you are now (funny, isn't it ?). > > So what the heck is the purpose? I cannot help but think that you are > just bored. Maybe 3D-programming isn't that interesting after all ... Apparently, it's just a way to establish some platform of credibility with which to launch ridiculous tirades from. Ooh. That might be an idea for a new 3D shooter -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 (800) 735-0555 From aahz at pythoncraft.com Wed Aug 6 12:08:49 2003 From: aahz at pythoncraft.com (Aahz) Date: 6 Aug 2003 12:08:49 -0400 Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> Message-ID: In article , enoch wrote: >anthony_barker at hotmail.com (Anthony_Barker) wrote in message news:<899f842.0307310555.56134f71 at posting.google.com>... >> >> What to you think python largest compromises are? > >Its non existant SMP scalability. Would you care to back up your claim with some actual evidence? (Yes, there are issues with Python on SMP machines, but to call Python's built-in threading "non-existent SMP scalability" is either a lie or revelatory of near-complete ignorance. That doesn't even count the various IPC mechanisms.) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From larry_Goodman at yahoo.com Wed Aug 20 10:56:07 2003 From: larry_Goodman at yahoo.com (Chuck Spears) Date: Wed, 20 Aug 2003 14:56:07 GMT Subject: win32com and com Record types References: Message-ID: <3f438bce.63332637@news.pa.comcast.giganews.com> When I run this code, it fails on the line where i try to create a record. Thanks again for the help. import win32com.client db=win32com.client.Dispatch("PDBUtils.BrandDb") db.Open (r"c:\temp\irx2_brand.pdb") for i in range(0,db.RecordCount): print i rec = win32com.client.Record("BrandRecord", db) 0 Traceback (most recent call last): File "c:\temp\test\comTest.py", line 18, in ? rec = win32com.client.Record("BrandRecord", db) File "C:\PYTHON22\lib\site-packages\win32com\client\__init__.py", line 392, in Record object = gencache.EnsureDispatch(object) File "C:\PYTHON22\lib\site-packages\win32com\client\gencache.py", line 442, in EnsureDispatch raise TypeError, "This COM object can not automate the makepy process - please run makepy manually for this object" TypeError: This COM object can not automate the makepy process - please run makepy manually for this object From pf_moore at yahoo.co.uk Tue Aug 19 15:38:44 2003 From: pf_moore at yahoo.co.uk (Paul Moore) Date: Tue, 19 Aug 2003 20:38:44 +0100 Subject: Unification of logging in Python's Standard Library References: <3a8e83d2.0308182217.7ccaf883@posting.google.com> Message-ID: Skip Montanaro writes: > Matthew> With the inclusion of the new 'logging' module in Python 2.3, > Matthew> I'm wondering whether there are plans to update the rest of the > Matthew> Standard Library to use this module wherever there is logging > Matthew> to be done. > ... > Matthew> A single, unified logging system across the entire Python > Matthew> Standard Library would be a worthy goal for some future release > Matthew> (Python 3000, or maybe even 2.4/2.5?). > > Rather than bring it up on python-dev as Alex suggested (I think it might > get lost there as well), I think you should open a bug report on SF which > identifies the problem and which modules you think need to be updated. This > provides a record of how people think this task should be approached. As > time goes on, patches for specific modules can be attached to the report and > incorporated into the modules in question. > > Another alternative is to write a PEP, though I don't think this is > necessarily required for this particular task. It also presents a higher > barrier to action than a bug report. One other point, which is worth mentioning (although don't let it put you off reporting a bug or writing a PEP), is that something like this is *far* more likely to happen if you contribute code rather than just ideas. If you haven't the expertise or time to contribute code, please still raise the idea - but don't be too disappointed if it's hard to get anyone to do anything about it. If you *can* contribute code, then you'll be welcomed with open arms of course. And your code will be ripped to shreds, but that's just to show we all care :-) Paul. -- This signature intentionally left blank From jjl at pobox.com Sat Aug 9 10:21:44 2003 From: jjl at pobox.com (John J. Lee) Date: 09 Aug 2003 15:21:44 +0100 Subject: win32, COM, and Solidworks (again) - Still Trying References: Message-ID: <87he4qykqv.fsf@pobox.com> Markus Wankus writes: > On Thu, 7 Aug 2003 23:06:01 +1000 (EST), Andrew MacIntyre > wrote: [...] > > If you need to go beyond the IDispatch interface, Thomas Heller's ctypes > > package looks to be your only option, short of creating a full-blown > > Pythonwin wrapper (ala Pythonwin's MAPI support) for the SolidWorks COM > > API. > > > > Yes, I was looking into this but was a little mystified at first. I > generated the python wrapper and had a look inside, but was unsure of > the extent of the Python code I was going to be required to write, as > well as type conversions. He wasn't talking about the automatically-generated makepy Python code, but rather hand-crafted C code wrapper around a particular vtable COM interface (though Mark may have some tools to help with the process of writing such wrappers, I don't think it's automated). ctypes is an easy way of doing it than writing a C wrapper. John From and-google at doxdesk.com Tue Aug 12 06:26:18 2003 From: and-google at doxdesk.com (Andrew Clover) Date: 12 Aug 2003 03:26:18 -0700 Subject: A cgi buffering problem? References: Message-ID: <2c60a528.0308120226.34dc54ac@posting.google.com> Heikki Salo wrote: > Some of the text that was supposed to go into the textbox appears > at the end of the page. Without being able to access it, it's difficult to say, so I'm not sure if this applies to your problem, but: a common reason for text not appearing in a textbox is that it has not been escaped. eg. this: is invalid and should be: If you've got an or inside the textarea it is, I guess, conceivable that a browser *might* do something different depending on whether further information has been buffered. Perhaps. -- Andrew Clover mailto:and at doxdesk.com http://www.doxdesk.com/ From Mike at DeleteThis.Geary.com Fri Aug 22 23:57:52 2003 From: Mike at DeleteThis.Geary.com (Michael Geary) Date: Fri, 22 Aug 2003 20:57:52 -0700 Subject: Keystroke logger for Windows References: Message-ID: > I don't think Python would be a good choice for the basic keystroke logging > utility. A program like this is implemented as a systemwide message hook, > which is a DLL that is loaded into the address space of *every* application. > This is a simple piece of code that should be written in C/C++ to keep it > small. Just adding one (fairly obvious) thought... Even though I wouldn't use Python for the low-level systemwide message hook, it would be an excellent choice for code that processes the resulting log. -Mike From jdhunter at ace.bsd.uchicago.edu Tue Aug 26 11:26:21 2003 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Tue, 26 Aug 2003 10:26:21 -0500 Subject: ANN: matplotlib 0.21 -- matlab compatible plotting in python Message-ID: Announcing matplotlib 0.21 -- http://matplotlib.sourceforge.net/ Matplotlib is a pure python plotting library designed to bring publication quality plotting to python with a syntax familiar to matlab users. Matplotlib uses pygtk for plotting, and has been tested on linux, UNIX and Microsoft Windows. Features include multiple figures and subplots, anti-aliased fonts, multiple style and color line plots, histograms, scatter plots, interactive control of plots, and more. matplotlib uses Numeric, with extensive use of data clipping, and so is suitable for use with interactive plotting of large data sets. What's new in matplotlib 0.21 Deprecation warnings fixed -- Several users reported deprecation warnings with python2.3 and pygtk 1.99.18. These were all related to passing floats rather than ints to gtk drawing commands. These have been cleaned up and none of the examples generate wanings. Let me know if you get some! Improved interactive shell -- Jon Anderson posted an improved GTK shell to the pygtk mailing list. Using this no longer requires that pygtk have threading built in. See interactive2.py. Use this if you want to make plots interactively from the python shell. Specifying colors -- You can now specify colors with color format strings, RGB tuples, or hex strings as in html. See color_demo.py Figure text -- All text in matplotlib has previously been in axis (data) coordinates. Sometimes it's helpful to be able to specify text in figure (relative) coordinates. Now figures also have text. When you scroll interactively, axis text moves with the data, figure text is fixed. This is also useful for making a figure title when you have multiple columns of subplots. See figtext.py Flicker free updates -- All drawing is done to a pixmap and then updated. This allows flicker free updates of the figure. You can use this, for example, to build a system monitor, which continuously shows system resources such as RAM, CPU, etc... See system_monitor.py for a demo. From tim.one at comcast.net Thu Aug 7 14:25:15 2003 From: tim.one at comcast.net (Tim Peters) Date: Thu, 7 Aug 2003 14:25:15 -0400 Subject: FWD: Re: Problem w/ IDLE on Win2000 In-Reply-To: <8yq67xtk.fsf@python.net> Message-ID: [Thomas Heller] > If it helps, I'm willing to take over the windows installer Great! It's in your capable hands until death . I can't imagine anyone better for this -- thanks. > - although I would probably stay with Wise. Wise has worked very well for us; the only drawbacks are that very few people are able to help when you want help (because very few people in PythonLand own a copy of Wise), and that begging Wise for new installer releases is a PITA. Something like InnoSetup would lower the bar for contributors. > And I consider IDLE having problems with spaces in its path a problem. That's permitted . I don't think it's an installer issue, though (see other email about that -- it's most likely that Python's os.spawn on Windows has problems with embedded spaces in an argument to the program being spawned; 2.2 IDLE didn't use spawn so didn't have this vulnerability). > Just bought my daughter a copy of 'Python f?r Kids' (although she certainly > accepted the default installation options). German spaces create even more problems . From amk at amk.ca Sun Aug 24 10:45:31 2003 From: amk at amk.ca (A.M. Kuchling) Date: Sun, 24 Aug 2003 09:45:31 -0500 Subject: Python preinstalled on Windows - looking for details References: <3F48BE7B.961CFBA0@engcorp.com> Message-ID: On Sun, 24 Aug 2003 09:32:43 -0400, Peter Hansen quoted: > Skip Montanaro wrote: >> It appears that HP and perhaps some other computer manufacturers who deliver >> Windows systems have begun delivering systems with Python pre-installed. My parents have a Compaq Windows box, and the last time I visited, I discovered a Python 1.5 installation in a system directory. I assume that portions of their installation or administrative tools use Python for something. --amk From grante at visi.com Mon Aug 25 16:23:25 2003 From: grante at visi.com (Grant Edwards) Date: 25 Aug 2003 20:23:25 GMT Subject: python gripes survey References: <78kkkvg8ckfio141es2of1p483ohbtbit5@4ax.com> Message-ID: <3f4a703d$0$167$a1866201@newsreader.visi.com> In article , Dave Brueck wrote: > On Monday 25 August 2003 12:14 pm, Afanasiy wrote: >> I have a bunch, many of them hard to define, but one that I just thought >> of I find strange sometimes is the use of tuples as near-mystery return >> values. I can't help but thinking a C struct with named fields is easier >> to remember than a tuple with fields accessed by integer. [...] > A bit of an apples-to-oranges comparison, isn't it? If you prefer to return a > named structure in C, the Python equivalent certainly wouldn't be a tuple. If you look at the library, it is. In instances where the "return" value to an ioctl or system call is a C struct, the Python return value is often a tuple. stat() leaps to mind as a good example. In that case, symbolic indexes into the tuple are provided -- this mitigates the situation somewhat. -- Grant Edwards grante Yow! SHHHH!! I hear SIX at TATTOOED TRUCK-DRIVERS visi.com tossing ENGINE BLOCKS into empty OIL DRUMS... From eric.brunel at pragmadev.com Wed Aug 6 10:35:10 2003 From: eric.brunel at pragmadev.com (Eric Brunel) Date: Wed, 06 Aug 2003 16:35:10 +0200 Subject: Tkinter programming problem References: <2830c89c.0308010048.403a2a19@posting.google.com> <2830c89c.0308040201.7c70695d@posting.google.com> <3f305c09.4980094@news.senet.com.au> Message-ID: Kevin Burrows wrote: > If I follow this thread correctly we are discussing how the exit from > Python/Tkinter programs. As it happens I have beed experimenting with > these environments and have struck the same problem.Examples from > "Python and Tkinter Programming" by John E Grayson. These examples > fire up OK but when the Quit button is hit the window freezes. If the > X in the window corner is hit first the application exits correctly. > > Several suggestions have been suggested. I have experimented with the > following program: > > #!/usr/local/bin/python > from Tkinter import * # Interface to Tk widgets > > class Application(Frame): > def __init__(self, master=None): > Frame.__init__(self, master) > self.grid() > self.createWidgets() > > def createWidgets(self): > self.quitButton = Button ( self, text="Quit", > command=self.quit ) > self.quitButton.grid() > > def quit(self): > print sys.platform > print "Quitting" > self.quit #--DOES NOT QET RID OF WINDOW > # sys.exit(0) #--DOES NOT GET RID OF WINDOW > # self.master.destroy() #--GETS RID OF WINDOW This can't be the code you tested, since, again, there are no () after self.quit. Moreover, even if you had written self.quit(), it wouldn't have worked since this would call again the quit method on Application recursively, ending up in an exception. What you should have written is: Frame.quit(self) > app = Application() # Instantiate the application class > app.master.title("Sample application") > app.mainloop() # Wait for events > > I changed commented out 2 of the 3 methods in the "quit" function > under PythonWinIDE, IDLE and Windows using a .pyw extension. > > The results of the quit methods were: > > PythonWinIDE IDLE Windows using > a .pyw extension > > quit No No No > > sys.exit No No Yes > > destroy No No Yes > > Interstingly the application does not freeze under IDLE and can still > be closed with the windows X. > > I am using Windows 98 and Python 2.2 There always have been issues with Tkinter on Windows 98: Tkinter applications often freeze on exit, but not always. This is likely to be a Windows issue, since it works everywhere else, even on more recent version of Windows with the same tcl/tk version. > So it looks like "destroy" is the method that works. It is > interesting that the example and test in the Tkinter.py module use the > "destroy" method but Grayson uses "quit" in his examples. Perhapse > the problem with "quit" is a MS Windows thing. You definetely should use quit: quitting Tkinter's main loop is its intended use; see http://www.pythonware.com/library/tkinter/introduction/x9374-event-processing.htm > I would be interested to here if the same thing happens under Unix et. > al. I never had any problem with the quit method on Unix (Linux or Solaris) or on recent version of Windows (2k, XP). I'm however always running the Python scripts from the command line, never from an IDE. So that may be an issue too... -- - Eric Brunel - PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com From jdhunter at ace.bsd.uchicago.edu Thu Aug 21 22:41:19 2003 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Thu, 21 Aug 2003 21:41:19 -0500 Subject: Adding a column in a tab delimited txt file In-Reply-To: (gcf78@hotmail.com's message of "21 Aug 2003 17:36:03 -0700") References: Message-ID: >>>>> "Garry" == Garry writes: Garry> Hi, I am new to python, hope someone can help me here: I Garry> have a MS Access exported .txt file which is tab delimited Garry> in total 20 columns, now I need to add another column of Garry> zero at the 4th column position and a column of zero at the Garry> 9th column position. What is the best way to do this? Can I Garry> write a while loop to count the number of tab I hit until Garry> the counter is 4 and then add a zero in between and thru Garry> the whole file? Unless the file is terribly large, it will be easier to slurp the whole thing into memory, manipulate some list structures, and then dump back to the file. There are a couple of nifty things to speed you along. You can use string split methods to split the file on tabs and read the file into a list of rows, each row split on the tabs. rows = [line.split('\t') for line in file('tabdelim.dat')] The next fun trick is to use the zip(*rows) to tranpose this into a list of columns. You can then use the list insert method to insert your column. Here I'm adding a last name column to the third column. cols = zip(*rows) # transposes 2Dlist cols.insert(2, ['Hunter', 'Sierig', 'Hunter', 'Hunter']) Now all that is left is to transpose back to rows and write the new file using the string method join to rejoin the columns with tabs rows = zip(*cols) # transpose back file('newfile.dat', 'w').writelines(['\t'.join(row) for row in rows]) This script takes an input file like 1 John 35 M 2 Miriam 31 F 3 Rahel 5 F 4 Ava 2 F and generates an outfile 1 John Hunter 35 M 2 Miriam Sierig 31 F 3 Rahel Hunter 5 F 4 Ava Hunter 2 F Damn cool! Here is the whole script: rows = [line.split('\t') for line in file('tabdelim.dat')] cols = zip(*rows) cols.insert(2, ['Hunter', 'Sierig', 'Hunter', 'Hunter']) rows = zip(*cols) file('newfile.dat', 'w').writelines(['\t'.join(row) for row in rows]) Cheers, John Hunter From peter at engcorp.com Mon Aug 18 14:53:03 2003 From: peter at engcorp.com (Peter Hansen) Date: Mon, 18 Aug 2003 14:53:03 -0400 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: Message-ID: <3F41208F.40021A68@engcorp.com> Daniel Dittmar wrote: > > Brandon J. Van Every wrote: > > What's ***TOTALLY COMPELLING*** about Ruby over Python? What makes you jump > > up in your chair and scream "Wow! Ruby has *that*? That is SO FRICKIN' > > COOL!!! ***MAN*** that would save me a buttload of work and make my life > > sooooo much easier!" > > Code blocks, although I'd rather go to the source and steal them from > Smalltalk. What is it about code blocks that would let "save *me* a buttload of work and make *my* life sooooo much easier"? If one can't answer that, one shouldn't expect to be able to answer whatever the heck it is Brandon has in mind (which is clearly not much), since only he has any idea what it is he wants, and we're not even sure about that... -Peter From mis6 at pitt.edu Wed Aug 6 10:08:06 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 6 Aug 2003 07:08:06 -0700 Subject: Checking for an "undefined" variable - newbie question References: Message-ID: <2259b0e2.0308060608.3020f2be@posting.google.com> Dan Rawson wrote in message news:... > How do I check if a variable has been defined?? > > The following don't appear to work: > > if variable: > > if variable is None: > > > I have only one (ugly) solution: > > try: > variable > except NameError: > ... > > which works, but is a bit clumsy if I just want to know if the thing already exists. > > If there's a more elegant way to check this, that would be great! > > Thanks . . . . > > Dan IMHO, the try .. except trick is the easiest, efficient and Pythonic solution. I would recommend it. If you don't like it, you may try if variable in dict where dict can be globals(), locals() or vars(). But still I would prefer the explicit try ... except. Michele From mertz at gnosis.cx Sun Aug 3 02:44:17 2003 From: mertz at gnosis.cx (Lulu of the Lotus-Eaters) Date: Sun, 03 Aug 2003 02:44:17 -0400 Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> <840592e1.0307312304.77a0a05f@posting.google.com> <7h3brv9a9oz.fsf@pc150.maths.bris.ac.uk> Message-ID: "Daniel Dittmar" wrote previously: |But a lot of Python code depends on reference counting or more exactly it |depends on the timely call of the destructor. So even if a much better GC is |added to Python, reference counting would perhaps be kept for backwards |compatibility (see Python's biggest compromises) Did this thread get caught in a time warp, and posts from two years ago get posted again. Exactly this all happened years ago. -- mertz@ | The specter of free information is haunting the `Net! All the gnosis | powers of IP- and crypto-tyranny have entered into an unholy .cx | alliance...ideas have nothing to lose but their chains. Unite | against "intellectual property" and anti-privacy regimes! ------------------------------------------------------------------------- From cpbotha at i_triple_e.org Mon Aug 11 08:47:38 2003 From: cpbotha at i_triple_e.org (Charl P. Botha) Date: Mon, 11 Aug 2003 12:47:38 +0000 (UTC) Subject: Fun with numbers - dammit, but I want a cast! References: <3f378fac$0$10778$afc38c87@auth.uk.news.easynet.net> Message-ID: In article <3f378fac$0$10778$afc38c87 at auth.uk.news.easynet.net>, Graham Nicholls wrote: > then I'm trying to use those sizes to scale the image, but because python > has decided that they are integers, I keep getting division by zero errors > > eg > xscale=xframe/img_x > > where xframe will be say 300, and img_x will be 1800 > xscale has the value 0. Have you tried doing it this way: xscale = xframe / float(img_x) -- charl p. botha http://cpbotha.net/ http://visualisation.tudelft.nl/ From mcherm at mcherm.com Tue Aug 5 14:52:26 2003 From: mcherm at mcherm.com (Michael Chermside) Date: Tue, 5 Aug 2003 11:52:26 -0700 Subject: (no subject) Message-ID: <1060109546.3f2ffcea737cb@mcherm.com> Fazer writes: [...] > I just wish to know how to get the cron deamon to > reload the crontab. Are you certain that it checks for changes or > reloads every minute? Rather than asking someone here who probably uses a different operating system than what you have, why not test it? Seems like it'd take only about 2 minutes to test, and then you'd be REALLY sure. Just use cron to run this python program: out = open("/mydir/test.txt", "w") out.write("this is a test\n") out.close() and see whether it happens. -- Michael Chermside From aleax at aleax.it Thu Aug 21 02:23:20 2003 From: aleax at aleax.it (Alex Martelli) Date: Thu, 21 Aug 2003 06:23:20 GMT Subject: open.read References: Message-ID: David Bear wrote: > I was in a hurry to do something and I did > > stuff = open("filename", "r").read() > > then I realized, "hey I didn't close the file". > > so python close it automagically? Since I was doing python > interactively I expect the interpreter closed the file for me but my > guess is the above syntax is probably poor. any comments? It's very common use in classic Python, and sometimes handy for interactive or near-one-liner use, but in any "serious" program explicitly closing the file just as soon as you're done with it is beter than relying on the interpreter closing it for you -- it will make your code more usable in Jython, and taken as a habit it will prevent some cases (not -- directly -- the above one) where even in CPython you might hang on to resources longer than necessary. try/final is the way to GUARANTEE that some key finalization code gets executed, by the way, in case you need that. Alex From appleseed-cast~NOSPAM~ at breathe.com Sun Aug 3 10:30:36 2003 From: appleseed-cast~NOSPAM~ at breathe.com (paul) Date: Sun, 3 Aug 2003 14:30:36 +0000 (UTC) Subject: Dealing with paths (Unix question) References: Message-ID: On Sun, 03 Aug 2003 03:04:13 +0000, paul wrote: > hey there all! cheers for the replies Tyler, Bjorn and Andy. I'll be checking out os.path, etc... fun fun fun... paul. From s0199583 at sms.ed.ac.uk Thu Aug 14 04:47:31 2003 From: s0199583 at sms.ed.ac.uk (Matt Smith) Date: 14 Aug 2003 01:47:31 -0700 Subject: COM :: VARIANT -eek References: <5f5c82ec.0308110207.1d42251@posting.google.com> <5f5c82ec.0308130542.6857fe74@posting.google.com> Message-ID: <5f5c82ec.0308140047.773a248c@posting.google.com> Mark Hammond wrote in message news:... > Matt Smith wrote: > > Mark Hammond wrote in message news:... > > > My problem is now this, when i go to makepy tool in pythonwin, it does > > not see/recognise the type library file I want it to convert. Is there > > anyway to add the file to the list of .tlb files it does does? > > These type libraries are in the registry. You may be able to pass the > filename on the commandline to makepy. > > > p.s. How do I include the generated makepy file into my code ? > > In generaly, you just need to generate the file and do nothing else. At > runtime, Python will see these generated files and automatically use them. > > I don't know how that will go with your type library though. > > Mark Hi again, I had to register the .tlb file (as it didnt do it automatically at installation [don't know why]) using a vb .tlb registration script, which worked fine and now I have a lovily makepy.py generated file for my .tlb file. My problem is now this, When I try to run the file (in pythonwins interactive window) using the code: from win32com.client include gencache gencache.EnsureModule('{AF684923-D245-11D3-8DE8-00A024ACAB85x0x1x0}', 0, 1, 0) pythonwin returns the error: ImportError: No module named gen_py.AF684923-D245-11D3-8DE8-00A024ACAB85x0x1x0 I have tested it with other makepy.py generated files and they all return the same error. Do I need to tell python where to find these makepy files? or is there some other reason as to why it does not want to use ANY makepy.py files thanks for all the help, matt. From mwh at python.net Tue Aug 26 14:37:03 2003 From: mwh at python.net (Michael Hudson) Date: Tue, 26 Aug 2003 18:37:03 GMT Subject: file object, details of modes and some issues. References: <3f4b800f_3@mk-nntp-1.news.uk.worldonline.com> Message-ID: <7h3d6ese09m.fsf@pc150.maths.bris.ac.uk> simon place writes: > is the code below meant to produce rubbish? Python uses C's stdio. According to the C standard: >, i had expected an exception. > > f=file('readme.txt','w') > f.write(' ') > f.read() engages in undefined behaviour (i.e. is perfectly entitled to make demons fly out of your nose). You can apparently trigger hair-raising crashes on Win98 by playing along these lines. There's not a lot that Python can do about this except include it's own implementation of a stdio-a-like, and indeed some future version of Python may do just this. Cheers, mwh -- something happens, what I'm not exactly sure. -- PyPy debugging fun From p3d at NOSPAMTAyahoo.co.uk Mon Aug 18 12:09:54 2003 From: p3d at NOSPAMTAyahoo.co.uk (PD) Date: Mon, 18 Aug 2003 17:09:54 +0100 Subject: python and symbian? In-Reply-To: References: Message-ID: <1061222990.25115.0@damia.uk.clara.net> Hi, Yes, thats pretty much the only reference to python on the symbian platform that I could find. While this is interesting I was hoping for something for the version 6 OS, or even version 7 (I have a p800 you see). Thanks Paul. Graham Breed wrote: > PD wrote: > >> Hello, >> I was wondering if anyone knew of any efforts to get python working >> on the symbian platform? I've done a search and have turned up a >> couple of links to projects on the symbian site, but these projects >> appear to be long dead. > > > This is what I have installed on my Revo: > > http://sourceforge.net/projects/epocpython/ > > and it says the project has moved here where not much is happening > > http://www.oflebbe.de/oflebbe/python/ > > Hopefully that'll work for you. There's no GUI, but it's much smaller > than Java. > > > Graham > From staschuk at telusplanet.net Wed Aug 6 08:59:03 2003 From: staschuk at telusplanet.net (Steven Taschuk) Date: Wed, 6 Aug 2003 06:59:03 -0600 Subject: Checking for an "undefined" variable - newbie question In-Reply-To: ; from daniel.rawson.take!this!out!@asml.nl on Wed, Aug 06, 2003 at 06:47:34AM -0400 References: Message-ID: <20030806065903.A2783@tibia.amotlpaa.bogus> Quoth Dan Rawson: > How do I check if a variable has been defined?? [...] > try: > variable > except NameError: > ... This is the answer to your question. > If there's a more elegant way to check this, that would be great! Why do you want to check it in the first place? In particular, why not initialize your variable to some out-of-band value (such as None) and test that? E.g., myvar = None # ... code which might set myvar to something else ... if myvar is None: # ... -- Steven Taschuk staschuk at telusplanet.net Every public frenzy produces legislation purporting to address it. (Kinsley's Law) From vanevery at 3DProgrammer.com Mon Aug 18 14:35:02 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Mon, 18 Aug 2003 11:35:02 -0700 Subject: What's better about Rattlesnakes than Pythons? References: <8e482ba2.0308171939.7de4a288@posting.google.com> Message-ID: Graham Fawcett wrote: > > Any snake born in Java will perform better than these two; at least > that's what the Javanese snake-sellers tell me. What they don't tell > you > is that you'll have to spend ten times as long training the darn > snake. What, Java doesn't have mice? > I hear that sea-snakes are pretty fast too. But be warned: if you > point > a sea-snake in an invalid direction, it may never come back. Also, be > prepared to clean up the mouse carcasses yourself. Nonsense. The carcasses fall to the bottom of the ocean. If your ocean is big enough, it doesn't matter. If your ocean is an inflatable kiddie pool.... -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From bvdeenen at access-four-all.nl.invalid Tue Aug 12 03:17:38 2003 From: bvdeenen at access-four-all.nl.invalid (Bart) Date: Tue, 12 Aug 2003 09:17:38 +0200 Subject: proper loop syntax? References: Message-ID: <3f389493$0$1688$e4fe514c@dreader3.news.xs4all.nl> Hi I tried to run your code snippet, and it didn't work right away. One of the problems might be that license() is actually a builtin function! Furthermore, how about making all the ifs into if y=='x': license_char = "5Po *"[t] elif y=="a" or y=="S" license_char = "7Gf*u"[t] GOT it. you typed y=='a' or 'S' and it should be as shown above Best regards Bart van Deenen From donn at u.washington.edu Mon Aug 25 18:27:39 2003 From: donn at u.washington.edu (Donn Cave) Date: Mon, 25 Aug 2003 15:27:39 -0700 Subject: python gripes survey References: <78kkkvg8ckfio141es2of1p483ohbtbit5@4ax.com> <0rqkkv481p8ob48ppbdikh95kn96jb9fe1@4ax.com> Message-ID: In article , "Ryan Lowe" wrote: > dont access the return values by their index; just unpack 'em. > > def getFruit() : > return 'apples', 'oranges' > > apples, oranges = getFruit() Not a solution, as he has already pointed out in another followup. Why not oranges, apples = getFruit() ? Well, obviously because that's wrong, but the problem is that you may not realize it's wrong. Able to remember the order of items in the return from posix.stat()? I am not, and I've been using Python on UNIX for about a decade. Here it is, in case you're wondering what I mean - (mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime) = os.stat('.') So this particular case is actually resolved in 2.2 - the return isn't really a tuple. >>> st = os.stat('.') >>> print st.st_uid 501 >>> type(a) which is probably the best that can be done for Python. If you were starting over from scratch, I think you'd want to have and use a record type. Donn Cave, donn at u.washington.edu From max at alcyone.com Sun Aug 17 18:48:22 2003 From: max at alcyone.com (Erik Max Francis) Date: Sun, 17 Aug 2003 15:48:22 -0700 Subject: client derived from async_chat References: <3f3fdb48_1@news.vo.lu> <3F3FF26F.3D6538F4@alcyone.com> <3f3fff3c_1@news.vo.lu> Message-ID: <3F400636.C0B8CE84@alcyone.com> Patrick Useldinger wrote: > This is exactly what seems to happen with the async_chat class, as in > dispatcher.create_socket the same setblocking(0) is done. > > If you just could shed some light on what this error means, I haven't > found any explanation up to now. It'd doing what you asked it to do. Functions that would block return an error of EWOULDBLOCK (which is translated into a socket.error exception in Python) if they would have blocked but you have set the socket not to block. The error is not an error, it's just the system telling you, "I would have blocked here, but you told me not to, so I'm telling you that." The bigger question is why you're asking the socket to not block when it appears that you really want it to (since your logic isn't handling the case when it doesn't). -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ Defeat is a school in which truth always grows strong. \__/ Henry Ward Beecher From avner at skilldesign.com Sat Aug 30 03:53:50 2003 From: avner at skilldesign.com (Avner Ben) Date: Sat, 30 Aug 2003 09:53:50 +0200 Subject: Pyhton 2.3 does not work Message-ID: <3f504a34$1@news.012.net.il> I need help with Python 2.3 installation in Windows. I installed Python 2.3 on both my computers (one running Windows XP and the other running Windows 98), after first uninstalling Python 2.2.3. In both computers, Python 2.3. keeps looking for "python22.dll" and would not work. This happens when running IDLE and when running python.exe and trying to import anything. I removed all mentions of pyhton22.dll from the registry and repaired it (with Registry Mechanic) - no help. I looked at PYTHONPATH and it has no mention of python22. Obviously, there is something left in my configurations that uninstalling 2.2.3 would not amend. The only extensions to Python installed earlier were py2exe and wxPython. I took care to uninstall them first. Any suggestions what to look for? Avner. From pradix at gmx.de Fri Aug 29 07:54:43 2003 From: pradix at gmx.de (=?iso-8859-1?q?Lorenz_K=F6hl?=) Date: Fri, 29 Aug 2003 13:54:43 +0200 Subject: modpython compilation error Message-ID: hi, I've python 2.3 and apache 2.0.47 installed on my SuSE8.2. when trying to compile modpython into apache, make stops with the error ---- In file included from /usr/local/include/python2.3/Python.h:8, from /home/software/network/apache/mod_python-3.0.3/src/include/mod_python.h:92, from requestobject.c:64: /usr/local/include/python2.3/pyconfig.h:844:1: warning: "_POSIX_C_SOURCE" redefined In file included from /usr/include/sys/types.h:27, from /usr/local/apache2/include/apr.h:149, from /usr/local/apache2/include/ap_config.h:58, from /usr/local/apache2/include/httpd.h:72, from /home/software/network/apache/mod_python-3.0.3/src/include/mod_python.h:71, from requestobject.c:64: /usr/include/features.h:131:1: warning: this is the location of the previous definition requestobject.c: In function `getreq_recmbr_off': requestobject.c:1055: error: `LONG_LONG' undeclared (first use in this function) requestobject.c:1055: error: (Each undeclared identifier is reported only once requestobject.c:1055: error: for each function it appears in.) requestobject.c:1056: error: parse error before "l" requestobject.c:1057: error: `l' undeclared (first use in this function) requestobject.c: At top level: requestobject.c:1270: warning: initialization from incompatible pointer type apxs:Error: Command failed with rc=65536 . make[1]: *** [mod_python.so] Error 1 make[1]: Leaving directory `/home/software/network/apache/mod_python-3.0.3/src' make: *** [do_dso] Error 2 ---- Hmm, apache is (probably) correctly installed. dso is of course activated and I also installed apr from apr.apache.org any ideas? From peter at engcorp.com Wed Aug 27 13:44:14 2003 From: peter at engcorp.com (Peter Hansen) Date: Wed, 27 Aug 2003 13:44:14 -0400 Subject: Celebrity advice (was: Advice to a Junior in High School?) References: <3F4CD2A2.DE7D05D2@engcorp.com> Message-ID: <3F4CEDEE.C2DC4576@engcorp.com> Andrew Dalke wrote: > > Peter Hansen > > Were there "100s of millions of murders" in the 20th century, assuming > > commonplace definitions of "murder" (killing humans), "million" > > (10 to the 6th power), and "20th century" (period beginning roughly > > January 1, 1900 and ending on or one year before December 31, 2000)? > > > > That's a lot of people getting themselves killed, whatever the cause... > > I think Terry means deaths related to war, genocide, and various > internal purges. Here's one source > http://users.erols.com/mwhite28/atrox.htm > which totals 155 million. > > Not all were deaths from arms. Bombs, knives, disease, famine all > played a role. I figured it was that. I wasn't questioning the type of killing that should be called "murder", but the "100s of millions" thing, which evokes an image of something like a billion people (a mere 10 "100s of millions"). 155 million total, while perhaps mind-numbingly high still, is not really in the "100s of millions" according to the usual interpretation of such a phrase. Just wondering... thanks for the links, everyone. -Peter From cookedm+news at physics.mcmaster.ca Fri Aug 22 15:58:21 2003 From: cookedm+news at physics.mcmaster.ca (David M. Cooke) Date: Fri, 22 Aug 2003 15:58:21 -0400 Subject: Design idea for Ping Application References: <4378fa6f.0308181546.548daff7@posting.google.com> <1061263809.5430.49.camel@localhost.localdomain> Message-ID: At some point, "Mike C. Fletcher" wrote: > David M. Cooke wrote: >>At some point, "Mike C. Fletcher" wrote: >> > ... > >>>however, I've not yet been >>>able to get the code to run under Unix (where creating raw sockets is >>>a no-no). >>> >> >>Only root can create raw sockets. You'll notice the system ping >>command is setuid root so that ordinary users can use it. Running this >>code as root works. >> > ... > Oh well, bite the bullet and make it a setuid-safe program and > figure out how to get that installed on client machines. Or just > scrap the whole direct approach on Unix and spawn 100 "ping" > processes simultaneously. Problem there is there are different versions of ping. There are three versions available for Debian, for instance. With Redhat 7.x, the times are returned as microseconds, whereas others return milliseconds. The ping on Solaris, IIRC, by default just checks if a system is up. So you end up trying to figure out what version of ping you have, and how to call it correctly. -- |>|\/|< /--------------------------------------------------------------------------\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca From jjl at pobox.com Mon Aug 18 14:01:01 2003 From: jjl at pobox.com (John J. Lee) Date: 18 Aug 2003 19:01:01 +0100 Subject: ClientCookie bug (followup) References: <87fzk4sav2.fsf@pobox.com> <87znibzrnx.fsf@pobox.com> <87oeypdh92.fsf@pobox.com> <87smnz6qf5.fsf@pobox.com> Message-ID: <87oeym26ci.fsf@pobox.com> jjl at pobox.com (John J. Lee) writes: > cartermark46 at ukmail.com (Mark Carter) writes: [...] > > It doesn't work on my XP machine at least. This is proboably why > > people have been doing it all wrong, allegedly. > > I don't see how -- the examples in question (the one everybody seems > driven to copy from, and the ones people should copy from) does not > include any reference to any CookieJar. OK, it does, now I come to actually look at it... John From maxx at easynews.com Fri Aug 29 13:51:33 2003 From: maxx at easynews.com (maxx at easynews.com) Date: Fri, 29 Aug 2003 17:51:33 GMT Subject: OT: Americans love their guns References: Message-ID: On Thu, 28 Aug 2003 19:46:57 GMT, maxx at easynews.com wrote: >And my probability of being one of them is pretty low - because I am usually >armed ;) Lots of replies. Rather than create a large list of individual responses, I will summarize in this one post. >I would think being armed increases your chances of engaging in an armed >confrontation. I have never quite agreed with that concept. Being armed should not make one "seek out" conflict, or otherwise engage in unsafe situations. Armed self defense (IMO) is only for when an aggressor forces the issue, and presents no other options (to escape for example). In other words, a last resort where the only choices are to fight or die. >Your position somehow assumes you would win any such >conflict, which, until tested, is an unsupportable position. Three words: Training, training, training. Now I will readily admit that no amount of training will prepare someone for all situations, but I will also state that if one straps on a gun, and does not seek out expert instruction and regular training, then they _are_ a threat to their own safety. >Obviously, your probability is MUCH, MUCH higher of being one of them, >because you are armed. Why? Maybe it is because of my education, but I can look at any home, and spot several ways to inflict great bodily harm to myself, without looking too hard. Many of these methods do not require traditional weapons. In other words, if I want to end my chapter, I do not need a gun. >My chance of being a >gun-inflicted suicide is 0.00%... yours is more (maybe you don't suffer >from depression now, and maybe no temporary personal tragedy has made >you despondent... but if such things do happen [of course, I do not wish >them on you]...) Suicide by gun is a messy affair. I know it is a method used by many, but the chance of failing to complete the task exists, and I would prefer more certain methods. HOWEVER, I do not worry that my death will come at my own purposeful hand. I enjoy life too much, and I do not worry too much about my personal future turning out to change that negatively. >Moreover, some of the rest are accidents. Cannot refute that one. Natural Selection anyone? >As for homicide, well, you're far more likely to be either a victim or a >killer. If you are armed, it is quite possible that an angry loved one >would have access to that gun.... and no doubt regret shooting you after >his/her anger cooled. I think she would prefer a kitchen knife. YMMV. ;) >And should you be mugged on the street by a >stranger, your chance of walking away dead (rather than just with less >money), are MANY times higher if you pull a gun on your assailant. I will refer to my comments above, and again restate, that as a civilian, I believe firearms are a last ditch effort, kind of like nuclear weapons. Only "push the button" if you are screwed if you do not. Deployment of a weapon (any weapon) must be considered with extreme prudence. Now I will agree that this is not often the case, and that is what causes many of the negative statistics. I will also agree that persons who cannot or will not exercise the required discretion should not carry weapons. >Yes, because firearm owners ALWAYS get the drop on the bad duys, and >NEVER take one in the gut themselves. NEVER say NEVER. Life is not scripted. I do not believe in fate. >I think (though I don't know), from self-defense courses run by police >a long, long time ago at a university far, far away, that your >statement alone actually /elevates/ the probability that you will be >one of them. Times are a changin'. Different studies, and different ways of thought, result in different conclusions. Again, based on the individuals training and discipline, this concept can be either true or false. They used to preach passiveness in rape-survival, acquiesce and live another day. Often the current advice is opposite. >To /lower/ the probability, you'll need to talk about the >time you've spent on a tactical course or in police training. Many, many, many hours (hint, hint). More than the average (citizen) bear. And that friends, IMO, is the real problem. What the heck does all this have to do with Python? Perhaps a different, but topically improper Python: http://www.colt.com/CMCI/Python.asp Off to the range. From jjl at pobox.com Fri Aug 22 17:31:31 2003 From: jjl at pobox.com (John J. Lee) Date: 22 Aug 2003 22:31:31 +0100 Subject: Deficiency in urllib/socket for https? References: <6vaakvorefvifnt3fk59r6tcj16c59rrfi@4ax.com> <87r83dzr34.fsf@pobox.com> <1hlckvot3mr78up9o52uiutse4ofh1d2vq@4ax.com> Message-ID: <87fzjtpefg.fsf@pobox.com> Gary Feldman writes: > On 22 Aug 2003 15:47:59 +0100, jjl at pobox.com (John J. Lee) wrote: > > Thanks for your extensive reply. All I can say is that any environment > that silently does https interactions without verifying the certificate, > and without loudly warning the user, is a security catastrophe waiting to > happen. While I don't claim to be a web security expert, I've spent enough [...] > Even if it's just a clearly labelled warning in urlopen saying that it > ignores https certification errors, which by definition defeats a primary > purpose of https (it gets you encryption but no authentication). [...] You're right -- with the caveat that it is useful to have https even without authentication (essentially all https traffic on the internet proves that ;-). Would you mind submitting a doc patch (both urllib and urllib2 docs appear to need fixing -- urllib2 to say that it never verifies, urllib to say that it skips verification if an appropriate x509 mapping isn't supplied)? John From jjl at pobox.com Sat Aug 2 09:42:41 2003 From: jjl at pobox.com (John J. Lee) Date: 02 Aug 2003 14:42:41 +0100 Subject: Python Windows 2.3 Installer problems References: Message-ID: <8765lgyy3y.fsf@pobox.com> Timothy Martens writes: > When I run the Python-2.3.exe on my WIN2K box and go through the > initial dialogues, the installer frezes at 1% when it's "Copying File > C:\Python23\UNWISE.exe" > > Any ideas ANYONE? Report it as a bug on sourceforge (after searching for duplicate reports first, of course). John From tebeka at cs.bgu.ac.il Thu Aug 28 04:26:58 2003 From: tebeka at cs.bgu.ac.il (Miki Tebeka) Date: 28 Aug 2003 01:26:58 -0700 Subject: Comments on my "Python Introduction" slides References: <33803989.0308240000.35b9bf1f@posting.google.com> <33803989.0308240644.3090f039@posting.google.com> <3f492761$0$49117$e4fe514c@news.xs4all.nl> <33803989.0308260210.4c1e058@posting.google.com> Message-ID: <33803989.0308280026.596559f0@posting.google.com> Hello Gerhard, > >>frame 10: IMO "Magic methods" has a negative connotation. but maybe it's the correct terminology > > > > I'll try to find a better alternative. > > I'd suggest "special methods" - the language specification has a chapter > "special method names" > (http://www.python.org/doc/current/ref/specialnames.html). Taken. 10x. Miki From kz3206s02 at sneakemail.com Thu Aug 28 16:00:52 2003 From: kz3206s02 at sneakemail.com (Ben Liblit) Date: Thu, 28 Aug 2003 13:00:52 -0700 Subject: extra_ivars assersion failure Message-ID: I'm having trouble subclassing a class from an extension module. When Python processes my subclass definition, and before any instances are created, it aborts with: python: Objects/typeobject.c:872: extra_ivars: Assertion `t_size >= b_size' failed. The extension module is trying to coordinate no less than three different object systems (GObject, CORBA, Python). Let me back up and explain what's going on in there. In the world of the GTK+ GObject system, I've got a GObject subclass. (It's actually a subclass of BonoboObject, which in turn derives from GObject.) I can write C code that instantiates this GObject-derived class and all is well. I'm wrapping these GObject instances inside Python objects using h2def.py and pygtk-codegen-2.0. The ".defs" file looks good: there's a define-object construct with the right class name and parent class name. The constructor is detected and wrapped correctly. In the ".override" file I "import bonobo.Object as PyBonoboObject_Type", and everything builds smoothly. I can write Python code that instantiates this wrapper class and all is well. What I cannot do is subclass this wrapper class in Python code. When I try to, I get the diagnostic message reported earlier: python: Objects/typeobject.c:872: extra_ivars: Assertion `t_size >= b_size' failed. Does anyone know what deeper problem this message is symptomatic of? What am I doing wrong in my extension module that would allow it to work correctly when the wrapper class is instantiated directly, but which would cause this error when a subclass of the wrapper class is defined? [I originally posted this message to the pygtk mailing list, as it involves a number of their supporting tools. Folks on that list suggested that I try asking in this forum instead.] Thanks! From mpeuser at web.de Sat Aug 30 04:01:49 2003 From: mpeuser at web.de (Michael Peuser) Date: Sat, 30 Aug 2003 10:01:49 +0200 Subject: How do I prevent master window from being accessed with childwindow present? References: <4378fa6f.0308291012.f660cdf@posting.google.com> <7YadnTLIALoMddKiXTWJiw@comcast.com> Message-ID: "Marc" schrieb im Newsbeitrag news:7YadnTLIALoMddKiXTWJiw at comcast.com... > I guess knowing which kit would help. I am using Tkinter. > Of course you were usind Tkinter... (1) You can use the modal approach (have a look how Pmw are doing this. (2) Disable all your controls in the main widget when you show the child window. (3) "withdraw" the main window (this is not iconify!) Example: from Tkinter import * m=Tk() m.title("Parent") c=Toplevel(m) c.title("Child") Button(c,text="Hello",command=c.destroy).pack() c.bind("",lambda x:m.deiconify()) # note we need lambda to get rid of the Destroy argument #we should "bind", because there are many ways a window can be killed m.withdraw() mainloop() From peter at engcorp.com Wed Aug 27 18:51:00 2003 From: peter at engcorp.com (Peter Hansen) Date: Wed, 27 Aug 2003 18:51:00 -0400 Subject: Style question... References: Message-ID: <3F4D35D4.1F7E0373@engcorp.com> Anthony Roberts wrote: > > If I end indentation levels with "pass" statements, will I piss off people > that have to read my code? eg: > > for i in xrange(0,5): > if i: > print i > pass > print i * -1 > pass > > I ask for two reasons... a) it helps emacs figure it out, and b) I'm more > comfortable ending compound statements with a token. Sorry, but yes, I find that ugly. If you're just starting out with Python, please just give it a shot without that approach for a while and see whether you become much more comfortable *without* the token than you ever were with it. -Peter From mis6 at pitt.edu Sun Aug 3 15:08:01 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 3 Aug 2003 12:08:01 -0700 Subject: Changing base class of a big hierarchy References: <873cgjyo2u.fsf@pobox.com> Message-ID: <2259b0e2.0308031108.3cc1d6db@posting.google.com> jjl at pobox.com (John J. Lee) wrote in message news:<873cgjyo2u.fsf at pobox.com>... > I'm trying to change a base class of a big class hierarchy. > What's the easiest way to do that? > > Maybe deep-copying the module or something, then fiddling with > __bases__?? Or a metaclass? > > While I'm on the subject, does anybody have code to get a list of all > classes in a package that derive from a particular class? Or > something I could use to do that easily? > > > John Here is a hack that does the job (notice the word 'hack'). Suppose you have a module called x.py: #x.py module class B(object): a='B' # in principle this is a very large class class C(B): pass You want to change the base class B (and therefore C) without touching the original source code. You can go along the following lines: import inspect from types import ModuleType def MRO(cls): count=0; out=["MRO of %s:" % cls.__name__] for c in cls.__mro__: name=c.__name__ bases=','.join([b.__name__ for b in c.__bases__]) s=" %s - %s(%s)" % (count,name,bases) if type(c) is not type: s+="[%s]" % type(c).__name__ out.append(s); count+=1 return '\n'.join(out) def modulesub(s,r,module): name=module.__name__ source=inspect.getsource(module).replace(s,r) dic={name: module}; exec source in dic # exec the modified module module2=ModuleType(name+'2') # creates an an empty module; requires 2.3 for k,v in dic.iteritems(): setattr(module2,k,v) # populates it with dic return module2 class B(object): # redefinition of the original class B a='NewB' import x Bsource=inspect.getsource(x.B) Bnewsource=inspect.getsource(B) x=modulesub(Bsource,Bnewsource,x) # redefine the module print MRO(x.C) print x.C.a # will print NewB The MRO function is here only for convenience, it is quite useful in large hierarchies. .__subclasses__() is useful too. HTH, Michele From graham__fawcett at hotmail.com Mon Aug 11 22:49:21 2003 From: graham__fawcett at hotmail.com (Graham Fawcett) Date: 11 Aug 2003 19:49:21 -0700 Subject: Slogan: Getting Rich Overnight References: Message-ID: "Brandon J. Van Every" wrote in message news:... > Graham Fawcett wrote: > > > > "Python: stimulate powerful organisms under your fingertips, without > > all the GUI mess!" > > "Organisms" is easily misread as "orgasms." ...and GUI is a homonym of "gooey". Was my joke too obscure? i-thought-it-was-funny-in-context-ly yours, -- G From danbmil99 at yahoo.com Thu Aug 7 18:44:53 2003 From: danbmil99 at yahoo.com (dan) Date: 7 Aug 2003 15:44:53 -0700 Subject: random changes References: Message-ID: I did try random.WichmannHill, which gives completely different data to either the new or the old version. danbmil99 at yahoo.com (dan) wrote in message news:... > just a suggestion -- > > next time the core RNG is changed, I think it would be useful to have > an > -oldrandom switch. It is common practice in simulation projects to > depend > on the fact that your random numbers will come out the same if you use > the same seed. In bumping to 2.3 with the new Mersenne algorithm, I > have no easy way of duplicating my old results. From p-abel at t-online.de Tue Aug 5 15:58:49 2003 From: p-abel at t-online.de (Peter Abel) Date: 5 Aug 2003 12:58:49 -0700 Subject: Passing Global Variables between imported modules References: Message-ID: <13a533e8.0308051158.43ee3bef@posting.google.com> sean at activeprime.com (Sean) wrote in message news:... > Thanks for the help guys. Passing the variable as a class parameter > (or even function parameter) is not really a possibility due to the > structure of the actual program code. The real world problem is that > I'm defining a global variable for a base application path for my > program, which changes depending on whether the program is being run > as a script, an compiled exe, and if there are preconfigured settings > in the windows registry and/or a config file. This was previously > being done in the global space of the "main" application script. The > class that needed this info was about 5 or six steps down the import > tree. > > I think my solution is going to involve taking all the logic for > finding the base path out of the main app script and putting it in > it's own module. That way anything that needs to see that variable > can just import that module and not have to worry about strange import > loops. > > -Sean Levatino At my knowledge **global** is always global in the module's namespace. That means your **MyClass.printGlobal()** methode is searching for **globalVar** in the namespace of the module **test2**. When you say **from test2 import MyClass** then MyClass is an attribute in the actual namespace where you're working. But it's searching **globalVar** in the namespace of **test2**. So the following works for me: >>> import test2 >>> mc = test2.MyClass() >>> test2.globalVar='foo' >>> mc.printGlobal() foo >>> To proove the above said even the following works: >>> from test2 import MyClass >>> import test2 >>> test2.globalVar='foo' ## !!ATTENTION!! The following is NOT **mc=test2.MyClass()** >>> mc=MyClass() >>> mc.printGlobal() foo >>> test2.globalVar='Something else' >>> mc.printGlobal() Something else >>> Regards Peter From newsgroups at jhrothjr.com Sun Aug 3 06:39:30 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Sun, 3 Aug 2003 06:39:30 -0400 Subject: PB with Python ActiveX Scripting Engine registration (Python 2.2.3/2.3) References: Message-ID: Long trace snipped... RExec was removed in Release 2.2.3 and 2.3. It's caused a number of other problems: for example, the Python port of FIT no longer works, either. (That's a three line fix, though.) You need to get a new verion of whatever it is from the person who wrote it. John Roth "GE" wrote in message news:bgik5l$6lj$1 at news-reader5.wanadoo.fr... > File "C:\Python22\lib\rexec.py", line 183, in __init__ > raise RuntimeError, "This code is not secure in Python 2.2 and 2.3" > exceptions.RuntimeError: This code is not secure in Python 2.2 and 2.3 > > > > > > "Mark Hammond" wrote in message > news:bgf4qa$2k95$1 at arachne.labyrinth.net.au... > > GE wrote: > > > > > I execute the Python program win32com\axscript\client\pyscript_rexec.py > and > > > the engine is successfully registered But the python engine isn't > active in > > > IE (tested with demo.htm, even after a reboot) > > > I did not have probleme with Python 2.1 and win32all-151 > > > > > > The path of win32com have changed ( now in python 2.2 we have the > directory > > > "site-packages" in more) is-it a way??? > > > > > > > Try resistering with "--debug", then open the "Trace Collector Debugging > > Tool" from Pythonwin. > > > > Mark. > > > > From newsgroups at jhrothjr.com Sat Aug 23 17:36:53 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Sat, 23 Aug 2003 17:36:53 -0400 Subject: How to store data? References: Message-ID: "Lars Behrens" wrote in message news:bi8lqg$6qoh4$1 at ID-95936.news.uni-berlin.de... > Hi there! > > For a web project I need a little expert help. I don't have written much > code yet, just been fiddling around a bit, testing and planning. > > The web site will have a submission page for attendants of a congress. > In a form the user will submit name, mailadress etc. and I plan to store > the data in a list of dictionaries: > > People = [{'name' : 'Sir Galahad', 'address' : 'Camelot', 'mail' : > 'Carrierpigeon at england.com'}] > > #new attendant: > People.append({'name' : 'Brian', 'address' : 'Palestine', 'mail' : > 'fastridingmessenger at rome.com'}) > > The 'lines' can be accessed by their index. > > Now my question: Where do you suggest to store the data? I know that > something sql-like would be quite useful but I don't have any knowledge > of sql. So I thought about putting the data either into a comma > separated file or pickling it. > > I should mention that some other people on different operation systems > should be able to import the file (Excel, Open Office) so I tend towards > the csv file. > > What would be better? Python 2.3 has an excellent CSV module. > And another problem: How to lock the file when several users try to > write to it? > > As I'm no very experienced programmer I would appreciate your help, > thanks in advance John Roth > > Cheerz Lars > > > > > > > > > > From vze4rx4y at verizon.net Fri Aug 8 00:27:11 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Fri, 08 Aug 2003 04:27:11 GMT Subject: passing multiple strings to string.find() References: <3F331A9B.9020907@vt.edu> Message-ID: "hokiegal99" wrote in message news:3F331A9B.9020907 at vt.edu... > How do I say: > > x = string.find(files, 'this', 'that', 'the-other') > > currently I have to write it like this to make it work: > > x = string.find(files, 'this') > y = string.find(files, 'that') > z = string.find(files, 'the-other') Try this: x, y, z = map(files.find, ['this', 'that', 'the-other']) or, if you're just trying to find the first match: re.search('this|that|the-other', files).start() OTOH, you've hinted at an application that may not appropriate for multiple string searches. Instead, look at building a dictionary or list of files -- they are most easily searched and better suited for associating other data such as file sizes, etc. Raymond Hettinger From chrisahlers at yahoo.com Sun Aug 24 20:37:26 2003 From: chrisahlers at yahoo.com (Chris) Date: 24 Aug 2003 17:37:26 -0700 Subject: Threading and Sockets Problem Message-ID: For some reason, I can only connect to my server once. After that, I keep getting 'connection refused 111' messages). import socket import threading class listen_server(threading.Thread): def __init__(self, port): threading.Thread.__init__(self) self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.socket.bind(("", port)) self.setDaemon(True) self.start() def run(self): self.socket.listen(5) while 1: clientsocket, address = self.socket.accept() print 'connection accepted' class connection(threading.Thread): def __init__(self, host = None, port = None): threading.Thread.__init__(self) self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.lock = threading.Lock() self.alive = True self.connect(host,port) self.start() def connect(self, host, port): self.socket.connect((host,port)) def disconnect(self): self.lock.acquire() self.alive = False self.lock.release() def run(self): while 1: self.lock.acquire() if not self.alive: self.lock.release() break self.lock.release() self.socket.close() print 'socket closed' #main program: x = listen_server(11090) y = connection('localhost', 11090) y.disconnect() Any ideas? From news at yebu.de Tue Aug 5 07:44:41 2003 From: news at yebu.de (Karl Scalet) Date: Tue, 05 Aug 2003 13:44:41 +0200 Subject: ANN: Snakelets 1.1 (simple-to-use web app server with dynamic pages) In-Reply-To: <3f2f7bf4$0$49103$e4fe514c@news.xs4all.nl> References: <3f2ea0a0$0$49110$e4fe514c@news.xs4all.nl> <3f2f7bf4$0$49103$e4fe514c@news.xs4all.nl> Message-ID: Irmen de Jong schrieb: > Karl Scalet wrote: > >> is there any support for cgi built into? > > > No, I especially designed Snakelets away from CGI: > it is inspired by Java's model of code-based request > handlers or HTML-based page templates (with Python > code embedded). No such thing as CGI scripts. > > Perhaps you could be a bit more specific what you > want to do? If you want to use Ypages (for instance) > as CGI scripts, please don't...: there are much better > things out there (Spyce springs to mind) that *do* > have CGI support. the reason why I asked for CGI was that I potentially will hold a course about python/webprogramming (very newbie level) and was thinking about an easy way to set up an environment of such. Previously I was thinking about twisted, but did not yet investigate about the CGI capabilities there. Why CGI at all: Simple because if I introduce some simple web-applications in the course the attendees could take them and most easily transport them to a common web-hoster. I know about CGIHTTPServer and might end up with it. Karl From vanevery at 3DProgrammer.com Mon Aug 18 13:43:05 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Mon, 18 Aug 2003 10:43:05 -0700 Subject: simple text parser? References: Message-ID: Alex Martelli wrote: > > I still don't understand why you need parsing for your expressed > purpose (saving data to disk and restoring them, with no effort) -- > surely C# has its own object-serialization modules already implemented > for your use, just like Python has cPickle and Java its own > serialization library modules. At this point I agree with you. I don't know about C#'s features, I'll be finding out. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From fredrik at pythonware.com Tue Aug 19 17:36:17 2003 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 19 Aug 2003 23:36:17 +0200 Subject: Why does this (not) work? References: Message-ID: Michael C. Neel wrote: > But I want to use the * to make life easier to read, so I tried: > > >>> ("test",)*3 > ('test', 'test', 'test') > >>> "%s - %s - %s" % ("test",)*3 > Traceback (most recent call last): > File "", line 1, in ? > TypeError: not enough arguments for format string > >>> >>> "%s - %s - %s" % ("test",)*3 is the same thing as >>> ( "%s - %s - %s" % ("test",) ) * 3 but you really want >>> "%s - %s - %s" % ( ("test",)*3 ) (your eval/str construct is just a really inefficient way to add parentheses to an expression...) From john at rygannon.com Tue Aug 12 04:28:55 2003 From: john at rygannon.com (BadJake) Date: Tue, 12 Aug 2003 08:28:55 GMT Subject: mysql fieldnames References: <644f6688.0308111422.2f2c4a05@posting.google.com> Message-ID: <3f38a4cb$0$229$fa0fcedb@lovejoy.zen.co.uk> You can execute the queries SHOW DATABASES; or SHOW COLUMNS FROM your_table_name Regards John From bkc at Murkworks.com Mon Aug 18 14:06:28 2003 From: bkc at Murkworks.com (Brad Clements) Date: Mon, 18 Aug 2003 14:06:28 -0400 Subject: py2exe service and tool-tray app combined? References: <3F3A8371.840.20CD3615@localhost> Message-ID: (moved from ctypes list) I've taken a look at the py2exe source. What I'd like to do is combine the functionality of run_svc.c with that of run_w.c So for example, could I simply change run_svc.c int main (int argc, char **argv) { int result; result = init(); if (result) return result; if(1 < argc && !stricmp(argv[1], "-x")) return start(argc, argv) else return PythonService_main(argc, argv); } Then link in start.c in addition to PythonService.cpp ? This way, the generated exe could work as both a service, and a regular application just by passing -x as the first command line option, or some other well-defined sentinel. I don't have the win32 source, so it's not easy for me to try. Anyone know off-hand if start.c exports items that will collide with PythonService.cpp? From gafStopSpamData at ziplink.stopallspam.net Mon Aug 18 21:00:06 2003 From: gafStopSpamData at ziplink.stopallspam.net (Gary Feldman) Date: Tue, 19 Aug 2003 01:00:06 GMT Subject: Python newbie help References: <87fa5cfa.0308181126.c61bfa2@posting.google.com> <3f412b85.351181492@news.blueyonder.co.uk> Message-ID: <0ct2kvch8346h8pgtk529v7pjlkpai42vo@4ax.com> On Mon, 18 Aug 2003 21:49:37 GMT, none wrote: >Your examples follow along with the same thing that I'm describing. >You have code that works and thorough descriptions that explain what's >going on but there is no end goal. I'm not learning how to write a >program, I'm learning how to write snippets of code. Just out of curiousity, what other programming languages do you know? I ask because the approach currently taken in the tutorial seems appropriate for people who already know how to program (and that's made obvious by the opening paragraph in the introduction). However, if you have no programming experience, or all you know is JavaScript or perhaps Visual Basic, then I can see how you might need more. Gary PS: Your posting doesn't seem to match the base note with respect to the various author fields. It's ok to hide real email addresses, etc., but it would be useful if there were some consistent indicator that the two posts were written by the same person, assuming that's the case. It could just be a signature line, even if the sig is just "A Python Novice". From bart_vanhaute_ at hotmail.com Thu Aug 7 18:10:34 2003 From: bart_vanhaute_ at hotmail.com (Bart) Date: Fri, 08 Aug 2003 00:10:34 +0200 Subject: resolving relative paths for external entities with xml.sax Message-ID: Dear python XML'ers, I have a set of XML documents that use external entity definitions for which I am having problems parsing them using python and xml.sax. The problem is with the resolution of relative paths in these. An example: dir1/test.xml: &ent; dir2/test.dtd: dir2/test.inc: external entity test >From what I understand of XML specs, relative paths in external entities are relative to the location of the document *in which they are defined*. However, using xml.sax (which calls expat, I presume), the paths are resolved relative to the current working directory. So the parser can not find the test.inc when the current working directory is e.g. dir1. I do not see how creating an EntityResolver would help here: how do I know against what base path I have to resolve the entity? (the same thing can be read without problems with other xml parser, for instance in Java). Bart. From mpeuser at web.de Fri Aug 15 05:08:38 2003 From: mpeuser at web.de (Michael Peuser) Date: Fri, 15 Aug 2003 11:08:38 +0200 Subject: GUI builder for Python References: Message-ID: Hi Alex, "Alex Martelli" schrieb im Newsbeitrag news:bhi4l901ijn at enews4.newsguy.com... > Michael Peuser wrote: > ... > > There are some commercial GUI Builders out of the normal budget. > > By the way, I hear that PythonWorks is "out of development" but they're > still selling licenses to existing customers only. This is what they say on their pages - I ask in this group some days ago about the state (especially of the uiToolkit) but there were no replies so far.... > ..... I wonder if there is > any chance the Tkinter GUI builder that came with it may be freed... This would be great because it would give us a very profesional IDE. I am even willing - let's have a look in my purse - yes, about 25 $/Euro for it ;-) > > Free ones are Black Adder for Qt, BoaConstructor for wx and some stuff > > like PAGE or SpecTIX for TIX. > > BlackAdder isn't free -- it's cheap but still commercial. If and only > if you're under the conditions for using the GPL license for Qt &c -- > basically if you're developing GPL for free operating systems, I think > that's a fair summary -- you can use Trolltech's own QtDesigner and > then pyuic to generate Python from the resulting XML file (that's more > or less what BlackAdder does nowadays, though in a more integrated way: > it uses an external QtDesigner rather than trying to "embed" it as it > once did in earlier versions). Quite true. Although I like Qt very much and rate it highes among the existing GUI-Toolkits - the quite license situation is somwhat annoying. There is not only Trolltech involved but another company (Riverbank, I think) for the Python bindings. BTW the scientitific plot package PyQwt is great. > > Alex > From mertz at gnosis.cx Thu Aug 28 13:38:24 2003 From: mertz at gnosis.cx (Lulu of the Lotus-Eaters) Date: Thu, 28 Aug 2003 13:38:24 -0400 Subject: OT: Americans love their guns References: Message-ID: |> LotLE> USA automobile deaths are ^43k/year |> LotLE> USA gun-related deaths are ~29k/year |> |> Where did you get your number? 29k a year??? Don't believe it. I |> would guess the number to be somewhere in the 1000 to 2000 range. Take a look at the US National Center for Injury Prevention and Control (part of the Centers for Disease Control and Prevention): http://webapp.cdc.gov/sasweb/ncipc/mortrate10.html I do not seem to be able to create a direct URL, but on the form select "Firearm" as the "cause or mechanism" of injury. This produces 28,663 deaths for Y2000. Incidentally, you can slice-and-dice the numbers using this same form. It is true, of course, that no all those deaths are homicides. Most of them are suicides, and many are accidents. In other words EXACTLY what I wrote in my original post. FWIW, gun accidents don't happen to people without guns (or at least w/o nearby people having them). And suicides attempted by gun succeed at a much higher rate than those done by other means (and are much more likely to be attempted in the first place because of the "convenience"). Yours, Lulu... -- mertz@ _/_/_/_/_/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY:_/_/_/_/ v i gnosis _/_/ Postmodern Enterprises _/_/ s r .cx _/_/ MAKERS OF CHAOS.... _/_/ i u _/_/_/_/_/ LOOK FOR IT IN A NEIGHBORHOOD NEAR YOU_/_/_/_/_/ g s From usenet_spam at janc.invalid Tue Aug 26 00:14:00 2003 From: usenet_spam at janc.invalid (JanC) Date: Tue, 26 Aug 2003 04:14:00 GMT Subject: python gripes survey References: Message-ID: carroll at tjc.com schreef: > No kidding: I'd really like a GOTO. I know, that's heresy, but I like > it during development. Sometimes I have a whole bunch of tests, and > change something that will only affect a test near the end. I'd love > to GOTO around the early stuff. > > If Python used {} to delimit blocks, I could just make the skipped > code a block and add a condition to skip it, but with the indentation > as the way of showing block scope (which I *love*), I have to indent a > big chunk of code to use that method. If it doesn't contain docstrings, you can put that "unwanted" test code between triple quotes ("""). -- JanC "Be strict when sending and tolerant when receiving." RFC 1958 - Architectural Principles of the Internet - section 3.9 From daniel at dittmar.net Mon Aug 18 14:41:38 2003 From: daniel at dittmar.net (Daniel Dittmar) Date: Mon, 18 Aug 2003 20:41:38 +0200 Subject: What's TOTALLY COMPELLING about Ruby over Python? In-Reply-To: References: Message-ID: Brandon J. Van Every wrote: > What's ***TOTALLY COMPELLING*** about Ruby over Python? What makes you jump > up in your chair and scream "Wow! Ruby has *that*? That is SO FRICKIN' > COOL!!! ***MAN*** that would save me a buttload of work and make my life > sooooo much easier!" Code blocks, although I'd rather go to the source and steal them from Smalltalk. Python now has most of the parts to implement code blocks, perhaps not exactly like Smalltalk, but enough to make them useful. What is lacking is a syntax to be able to create lambdas with multiple statements. And perhaps a syntax without using the keyword lambda, as some people seem to have an allergic reaction to it. Daniel From adalke at mindspring.com Sat Aug 2 20:16:06 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Sat, 2 Aug 2003 18:16:06 -0600 Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> <87el06d2i6.fsf@pobox.com> <8Z-cnS25-8ywsLGiXTWJiQ@comcast.com> Message-ID: Terry Reedy: > Because there is no 'official' meanings, despite claims to the > contrary, some software like Outlook Express ignores them on receipt. I sent email to a friend of mine. It contained a copy&paste from the interactive prompt. Something like >>> class Spam: ... pass >>> Something on his side (either Exchange or OE, dropped the "... pass" part of what I sent. Andrew dalke at dalkescientific.com From dkuhlman at rexx.com Thu Aug 14 13:29:47 2003 From: dkuhlman at rexx.com (Dave Kuhlman) Date: Thu, 14 Aug 2003 10:29:47 -0700 Subject: 3 new slogans References: Message-ID: Graham Fawcett wrote: [snip] >> 90% of code is crud >> The rest is Python >> >> I'd like to suggest that someone make a collection of these slogans and put them in the Python Wiki or the Python Web site. Wasn't there a slogan contest at Python 10? What happened to that list of slogans? By the way, at one time I found a set of Python icons that could be freely used, for example on Web sites. Is that still available? I couldn't find it. If it still exists, perhaps the list of Python slogans could be placed next to that (for some meaning of "next to" that makes sense on the Web). Dave -- Dave Kuhlman http://www.rexx.com/~dkuhlman dkuhlman at rexx.com From pyabo at novamens.com Mon Aug 11 14:24:34 2003 From: pyabo at novamens.com (Pablo Yabo) Date: Mon, 11 Aug 2003 15:24:34 -0300 Subject: Reference count Message-ID: <004c01c36035$d06b1e00$0601a8c0@hq.novamens.com> Hi, I'm embedding Python as script language of a application. I need to create objects in Python an keep them alive as they are GUI objects. How can I increment the reference count of the objects in order to prevent garbage collector destroy them? Pablo Yabo From RaoulGough at yahoo.co.uk Thu Aug 21 14:07:33 2003 From: RaoulGough at yahoo.co.uk (Raoul Gough) Date: Thu, 21 Aug 2003 19:07:33 +0100 Subject: Misleading description of [i:j:k] slicing? References: <7h33cfv2az7.fsf@pc150.maths.bris.ac.uk> Message-ID: Michael Hudson writes: > Raoul Gough writes: >> Seems to me that "0 <= n < abs(i-j)" is wrong, since the range of n >> gets multiplied by k. > > How about "0 <= n < abs(k*(i-j))"? But you're right, what's there is > a bit wrong. It's surprisingly hard to get this written down well. > The idea's not that hard, but a terse explanation is surprisingly > hard (when you start omitting values it gets even more fun!). > > Please submit a patch (assign it to me if you like -- the above > passage is my fault). I've submitted a bug to the sourceforge tracker for Python, but couldn't see how to assign it to anyone. Bug number is 792656, hope this is what you meant. -- Raoul Gough "Let there be one measure for wine throughout our kingdom, and one measure for ale, and one measure for corn" - Magna Carta From skip at pobox.com Wed Aug 13 12:06:59 2003 From: skip at pobox.com (Skip Montanaro) Date: Wed, 13 Aug 2003 11:06:59 -0500 Subject: Multi-Line Comment In-Reply-To: <1060760753.18367.122.camel@adsl-209.204.179.133.sonic.net> References: <4qofjvg3bh9smlnb1do4f0lhjga7bacnu3@4ax.com> <200308122306.48320.shalehperry@comcast.net> <1060760753.18367.122.camel@adsl-209.204.179.133.sonic.net> Message-ID: <16186.25123.416984.576099@montanaro.dyndns.org> >> Man, I wonder if I'll even learn 10% of the Emacs keystrokes. Chad> I don't even know 1%, but I know the 1% that counts. :) Your best friend when using various (X)?Emacs editing modes is C-h m You will sometimes stumble upon useful bits from the other 99%... Skip From duncan at NOSPAMrcp.co.uk Mon Aug 11 08:56:44 2003 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Mon, 11 Aug 2003 12:56:44 +0000 (UTC) Subject: Fun with numbers - dammit, but I want a cast! References: <3f378fac$0$10778$afc38c87@auth.uk.news.easynet.net> Message-ID: Graham Nicholls wrote in news:3f378fac$0$10778$afc38c87 at auth.uk.news.easynet.net: > eg > xscale=xframe/img_x > > where xframe will be say 300, and img_x will be 1800 > xscale has the value 0. > > I've tried doing img_x=1.0 to force it to be a float, but I'm getting > a bit frustrated as it seems to make no difference - once > image.getsize returns the (integer) value of the x size, it simply > converts back to an int. Variables don't have types in Python, objects have types. Assigning a float object to a variable doesn't have any effect on the type of the next object assigned to the same variable. To get the behaviour you want either convert at least one of your values to a float: xscale = float(xframe)/img_x or add the following 'magic' line to the top of your sourcefile: from __future__ import division If your file has that line at the top, division will behave more the way you expect: casting to float automatically whenever you divide integers. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From paddy3118 at netscape.netNOTthisBIT Mon Aug 25 04:48:18 2003 From: paddy3118 at netscape.netNOTthisBIT (Donald 'Paddy' McCarthy) Date: Mon, 25 Aug 2003 09:48:18 +0100 Subject: Comments on my "Python Introduction" slides In-Reply-To: <33803989.0308240000.35b9bf1f@posting.google.com> References: <33803989.0308240000.35b9bf1f@posting.google.com> Message-ID: <3F49CD52.1070609@netscape.netNOTthisBIT> Miki Tebeka wrote: > Hello All, > > I'll be doing a small internal course on Python at my company. > The 1'st session is an introduction that should also sell Python. > > If you have the time I'd appriciate any comments on my slides at > http://www.cs.bgu.ac.il/~tebeka/pyintro.html > > Keep in mind that the "students" are people writing real time and use > scripting mostly for small applications that usually communicate with > hardware, parse binary files, etc. > > TIA. > Miki Hi, Slide 9: The tripple quoted string has got the quotes mangled by the editor. You might try cut & paste execution of all your examples from the slides. General: Frames: the frames are not movable in Mozilla, (I wanted to make the slide frame larger). General: Slide title 'Quick One': Could be more informative. Paddy. From peter at engcorp.com Thu Aug 28 08:51:38 2003 From: peter at engcorp.com (Peter Hansen) Date: Thu, 28 Aug 2003 08:51:38 -0400 Subject: Celebrity advice (was: Advice to a Junior in High School?) References: <3F4CD2A2.DE7D05D2@engcorp.com> <38ec68a6.0308271644.63430149@posting.google.com> Message-ID: <3F4DFADA.4246344D@engcorp.com> Asun Friere wrote: > > Peter Hansen wrote in message news:<3F4CD2A2.DE7D05D2 at engcorp.com>... > > "20th century" (period beginning roughly > > January 1, 1900 and ending on or one year before December 31, 2000)? > > > Actually the 20th Century began on January 1 1901. When it ended is a > matter of endless debate, but a debate which is WAY more fun than the > gun debate! :P I knew you were out there, which is why I said "roughly". ;-) -Peter From vze4rx4y at verizon.net Thu Aug 14 01:45:00 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Thu, 14 Aug 2003 05:45:00 GMT Subject: Py2.3: Feedback on Sets References: Message-ID: "Skip Montanaro" wrote in message news:mailman.1060798102.26105.python-list at python.org... > > Russell> I suspect the upgrade issue will significantly slow the > Russell> incorporation of sets and the other new modules, but that over > Russell> time they're likely to become quite popular. I am certainly > Russell> looking forward to using sets and csv. > > The csv module (and the _csv module which underpins it) should work with > 2.2.3. If they don't, please file a bug report. > > Russell> I think it'd speed the adoption of new modules if they were > Russell> explicitly written to be compatible with one previous > Russell> generation of Python (and documented as such) so users could > Russell> manually include them with their code until the current > Russell> generation of Python had a bit more time to be adopted. > > That was the intention with the csv module. I wonder if some limitations to > use of sets with 2.2.x could be gotten around by adding a __future__ import? > Maybe itertools is also needed. In the documentation for the itertools module, I intensionally included pure python versions of each tool that make backporting easy. You can cut and paste the documentation into a module with from __future__ import generators and have a Py2.2 version of itertools that would enable the sets module to run just fine. Still, why not upgrade to Py2.3? The bug fixes were all ported to 2.2.3 and into Py2.3 so that the essential differences are the new modules and some minor language improvements. Raymond Hettinger From mwh at python.net Fri Aug 29 10:43:24 2003 From: mwh at python.net (Michael Hudson) Date: Fri, 29 Aug 2003 14:43:24 GMT Subject: method (a, b = '', *c, **d): gets a syntax error? References: <3F4F644D.2060003@uni-bonn.de> Message-ID: <7h3k78w4je4.fsf@pc150.maths.bris.ac.uk> Andreas Neudecker writes: > Hello. > > I am relatively new to Python and I have a strange problem with some > code. In a class the __call__ method gets parameters like this: > > > class WhatsUp: > __call__ ( > self, > var1, > var2 = '', > *moreVars, > **moreNamedVars, > ): > pass > > > I always get an error for the **moreNamedVars, line where the '^' > points at the comma at the end (or, if I remove the comma, it points > at the colon). I also tried commenting-out the other variables passed > to the method. Same result. > I assumed the order of variables and variable lists of variables had > to be like this? What is wrong? Missing a def? Cheers, mwh -- Any form of evilness that can be detected without *too* much effort is worth it... I have no idea what kind of evil we're looking for here or how to detect is, so I can't answer yes or no. -- Guido Van Rossum, python-dev From duncan at NOSPAMrcp.co.uk Wed Aug 20 04:17:30 2003 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Wed, 20 Aug 2003 08:17:30 +0000 (UTC) Subject: Why does this (not) work? References: Message-ID: Skip Montanaro wrote in news:mailman.1061329351.3443.python-list at python.org: > If you're worried about readability of large format operations, I suggest > you consider using dictionary expansion, e.g.: > > >>> "%(var)s - %(var)s - %(var)s" % {"var": "test"} > 'test - test - test' > > or more commonly: > > >>> var = "test" > >>> "%(var)s - %(var)s - %(var)s" % locals() > 'test - test - test' > I'm not sure about that last one being more common. I don't think I have ever had a desire to pass more variables to the string format than the ones I know I really want there. If you've upgraded to Python 2.3, then another way to write this would be: >>> "%(var)s - %(var)s - %(var)s" % dict(var="test") -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From paul.m at speakeasy.net Tue Aug 26 20:52:45 2003 From: paul.m at speakeasy.net (Paul M) Date: Tue, 26 Aug 2003 20:52:45 -0400 Subject: My future Python IDE article In-Reply-To: References: Message-ID: David Mertz wrote: > > So c.l.py readers... make the case for your favorite one getting on the > list. I have a while to ponder the opinions advanced, should this > prompt some discussion (it may take a little while to order review > copies of commercial tools and/or get things installed). > > Yours, David... I think it would be great to focus on truly cross platform IDEs. I regularly use Python on Win32, Linux, and Mac OS X, and I tend to prefer editors that work on at least those platforms (more would be great!). I imagine other people platform-hop a lot as well. And cross platform-ness is definitely keeping with the spirit of python. --Paul M. From http Sat Aug 23 17:23:17 2003 From: http (Paul Rubin) Date: 23 Aug 2003 14:23:17 -0700 Subject: OT: Ocaml? References: <7xk795xde6.fsf_-_@ruckus.brouhaha.com> <87lltkuluy.fsf@gmx.net> Message-ID: <7xwud41322.fsf@ruckus.brouhaha.com> Arne Koewing writes: > > Anyone here use OCAML? How do you like it? Is it a language a > > Pythonista can learn to love? From what little I've seen, it looks > > interesting, but I haven't actually tried installing or using it yet. > Yes and I think it's a great language, but it's a little bit harder > to start learning it. (you must learn how to read the types). > But you get a very 'save' language with a very efficient compiler. Do you find that the strict type system gets in your way like it does in Java? From clifford.wells at comcast.net Tue Aug 19 06:58:16 2003 From: clifford.wells at comcast.net (Cliff Wells) Date: Tue, 19 Aug 2003 03:58:16 -0700 Subject: Brandon's personal style (was) In-Reply-To: References: <38ec68a6.0308172319.431a4fde@posting.google.com> Message-ID: <1061290696.3203.57.camel@devilbox.homelinux.net> On Tue, 2003-08-19 at 02:03, Brandon J. Van Every wrote: > Cliff Wells wrote: > > To try to force those battles is about as reliable an indicator > > of trolling as is "URGENT: YOUR IMMEDIATE ASSISTANCE REQUIRED" is a > > reliable indicator of Nigerian spam. It should come as no surprise to > > you that people mistake your posts as trolling. They may be > > incorrect, but it is certainly a reasonable assumption. > > I hate to use an Eep-ism, but it's time for people to evolve. "You sound > like a troll" is not that reasonable an assumption. Outside of politics > newsgroups, I've almost never seen actual trolls. I've seen several, mostly on the Linux lists, but c.l.py hasn't been immune (lumberjack, you there?). > I've seen plenty of > people insulting each other, totally unable to see the other person's point > of view. I've seen countless instances of Troll Hunting all over Usenet > that had nothing to do with me. In fact, it's clearly a popular newsgroup > sport! People are intellectually lazy, they don't have an ironclad > criterion for what is or isn't a troll. A troll is anything they don't > like. They don't use imagination or exercise benefit of the doubt when > controversial posts appear. They just enjoy naming things within a familiar > pigeonholeing system. It comforts them. They are so focused on controlling > group discourse, and not letting "the wrong kind of conversation" happen, > that they don't put much thought into what was said in the first place. Have you ever considered that perhaps it is your own expectation of a "Troll Hunt" that makes you see such a thing when there is at least a remote chance you're looking for something that isn't there? In my two years on c.l.py I've never seen any such thing nor heard anyone else complain of such until now. If you give up the fantasy that people are out to get you then perhaps you might see how your own actions precipitated today's events. It's certainly true that people were quick to label your thread on Python vs. Ruby as a troll. However I also expect much of that was due the lingering effects of your prior thread on Python vs C#. > > Were you known to be a contributor, either with code or > > knowledge, your forays into time-wasting speculation would most likely > > be much better received. As it is the only "contribution" you've made > > is a generous use of other people's time and bandwidth. > > As I see it, my detractors are enginerds with no appreciation for or skill > at marketing. Quite probably true. Also most of them are probably proud of it. This isn't a marketing group, it's a programming language discussion group. I'd venture that with few exceptions most people here probably despise marketing or at best find it irrelevant. That is why there is a separate ng for discussion of such things. Most people here don't want to hear about it, even in the sense that it relates to Python. > Nor, probably, much awareness of Python marketing efforts. But the ones that do have hopefully found the appropriate forum. > That's how I figure you can (1) blithely ignore my analysis of Reality On > The Ground, (2) merrily claim I'm a do-nothing. I've suggested you look at > the marketing-python archives several times, it's a comment I've peppered > here and there. Have you? I browsed it and in fact considered responding to some of your claims there, which I found to be baseless (or at least misguided), but as I am one of the people who find marketing boring I didn't bother. > > The fact that you get "kills" in every ng you spend time in probably > > says more about you than other people. > > Actually, it says more about where I am in life. There was a time when I > never killfiled anybody. If I was rude, and we got into fights, we'd just > keep fighting. Often we'd kiss and make up. But sometimes, I'd get an > intractable, unforgiving, obsessive compulsive fixated asshole on my ass for > years. It drove me out of comp.games.development.* for a time, the > hierarchy I created. I got fed up with being told that I was a troll, > seeing as how I'd been Newsgroup Proponent. What the hell is that, the > ultimate trolling? I've never trolled in my life. Abrasive, argumentative, > violent, sure. Trolling, never. Fair enough. But would you find it odd if you were to slip on over to alt.culture.black and mention that you think affirmative action was a mistake and people got riled up? That some of them would label you racist? Of course not. In fact, if that were your position, you would expect such a response and preemptively address that response before the flamewar began. You should try the same thing with less volatile topics. Instead of assuming that your point of view is obvious (it isn't) or that people have read your posts in other groups (they haven't), simply provide a supporting argument for such remarks. Trust me, it goes a long way. > Anyways, a few years later I came back. I've been summarily killfiling > people ever since. It does wonders for my long-term interaction with people > and groups. I don't have to deal with the people I can't work with. That actually doesn't sound confrontational. In fact, IIWAP, I'd probably label it passive aggressive. > > Personally I've never > > killfiled anyone (not even the ruebot[!]) and to my knowledge, I've > > yet to be > > killfiled (although at times I'm a bit surprised at that, today being > > one of those times). > > It's really very simple. Your behavior is not the same as other people's > behavior. That's why we're still talking. > > > Why then, are you surprised when people choose to fight with you? > > Why do you say I'm surprised? This is all very predictable to me. Seen at > this moment in time, you are a static type within this system. You just > happen to be a benevolent, workable type. You are the "Well, are you going > to killfile *me* too?" type. I'm just the type who finds the entire process rather boring. I enjoy a good argument (heated or otherwise) a bit more than the next guy. However, I find irrational behavior a big yawn. I see no point in investing a lot of work trying to make someone look foolish who is going to do the job on his own anyway. I respect people who make their knowledge and work available to others without belittling them. I respect people who are able to articulate their arguments whether I agree with them or not. In general, I'm willing to give people the benefit of doubt which is why I've never killfiled anyone. > The kind of person who doesn't behave in a way > that I would killfile, and who doesn't quite understand how his behavior is > different from the people I do killfile. But, who probably will understand > by the time I get done explaining it. Actually, what surprises me is that several of the people you killfiled are some of the more reasonable people on the list. I'm a little concerned that I wasn't among them > Have you seen Enter The Matrix? The scene with The Architect is very > profound. The Matrix demands Neo. Someone else observed, this stuff is all > about young males. That's no accident, it's a feature of our genetics. Our > genetics demand certain confrontations at a certain age. In our lives, we > obey certain Grand Strategies, even if we are sapient and exercising choice > over the details. > > > Taking your statements together > > would seem to indicate that a fight is what you want. > > That's sorta true. This is really what I call a "posting binge," to avoid > other things I don't want to be doing. So for entertainment value you stir up groups where people are trying to help others get their jobs done? That might be a bit of a cheap shot, as I doubt you consciously intended to initiate a wild flamewar, but seriously, your binge took valuable time from people who others depend on. When I post a question to c.l.py, it's usually because I've got something I need done now and don't have a ton of time to tinker around or RTFM. > I'm an intellectually violent > person, I like a good debating scrap. But I've got Rules Of Engagement > about what I think is appropriate, intellectually defensible debate. > "You're a troll!" instead of hearing someone else's opinion ain't it. Ah, you've done the same, albeit in a different fashion. "You're a troll" certainly doesn't constitute a grand argument. But your approach is to selectively respond to arguments and sprinkle in the odd flamebait (or, as you would label them: things people don't want to hear). This is why I had you pegged (momentarily) as a clever troll. It appeared as if you were using just enough reasonable debate to disguise the unreasonable assertion. > Those > people, I want to punish. It's irrational, because intellectually I know I > can't actually change them. Rationally, I can killfile them. Possibly, I > can stimulate cumulative change in the system, but I am uncertain of it. In > 10 years maybe I will have let it go. This sounds good on the surface, and I can certainly understand phases in one's life. Nevertheless, acknowledging a shortcoming doesn't excuse it (please don't repeat that to my girlfriend, I don't want it used against me later ). Besides, you are still assuming that it is others who need to change. I can assure you that even were that so, it is an exercise in futility. Until you can cease to react to others, it is somewhat hypocritical to explain that they shouldn't react to you. > For instance, I'm reasonably sure I can stimulate minor change in your own > static type. You understand enough of the dimensions already that you're > capable of absorbing more of them. But you'll have probably gotten there on > your own soon anyways, so am I really needed as a stimulus? That would assume that 1) I desire such change, and 2) that such change would be desirable. > Actually, I suspect I'm not for your benefit, if I am for anyone's benefit. > I suspect it is for someone who is lurking. Maybe someone who hasn't formed > much of a world view yet. Mine, at any rate, is in my .sig. Well, certainly there is some benefit for someone, but I'm less than certain that the lesson is necessarily what you would expect. Regards, -- When I die, don't bury me alone -These Immortal Souls From alan_salmoni at yahoo.com Thu Aug 28 07:15:57 2003 From: alan_salmoni at yahoo.com (Alan James Salmoni) Date: 28 Aug 2003 04:15:57 -0700 Subject: My future Python IDE article References: Message-ID: Gerhard, Do'h! Sincerest apologies. I'll report to the torture chamber for immediate privation. I won't be allowed to use Python for a whole week... :) Alan. Gerhard H?ring wrote in message news:... > Alan James Salmoni wrote: > > Personally, I would include: > > > > 1) SciTE [...] > > 2) Leo [...] > > Neither one is an IDE (they lack a debugger). They're only editors. > > -- Gerhard From ialbert at mailblocks.com Mon Aug 18 21:03:10 2003 From: ialbert at mailblocks.com (Istvan Albert) Date: Mon, 18 Aug 2003 21:03:10 -0400 Subject: What's better about Ruby than Python? In-Reply-To: References: Message-ID: Brandon J. Van Every wrote: > You certainly are a waste of my time, Tom. Welcome to my killfile. I'd > like to think that if I'm a waste of your time, it's for different reasons > and not ones of my own designing. For what is worth Brandon is a hard working troll. I can respect that. Look at all of his responses, and all the effort to reward those that do respond to his questions. And all that killfiling, it is a gimmick but it works, is funny to see whether you make it or not. It makes you read what he says next. Posting on the usenet is a sort of jungle, getting read is surviving. And no matter how, mocked or not, laughed at or ridiculed Brandon's parasitic postings live on. It is not that easy and it takes an appreciable mental exercise to attempt to juggle or manipulate people. Istvan. From gh at ghaering.de Wed Aug 6 07:44:20 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Wed, 06 Aug 2003 13:44:20 +0200 Subject: Get the hostname In-Reply-To: <3F30E50B.9090300@semafor.ch> References: <3F30E50B.9090300@semafor.ch> Message-ID: <3F30EA14.9090202@ghaering.de> Lukas Schnieper wrote: > Hi > How can i get the hostname of my Linux PC? > I tried os.system('hostname') but i cant save the hostname in a variable > like hostname = os.system('hostname') Check out the functions gethostname() and getfqdn() in the socket module. To read the output of an external system command, you can use the commands module. -- Gerhard From tim at remove_if_not_spam.digitig.co.uk Tue Aug 19 17:22:33 2003 From: tim at remove_if_not_spam.digitig.co.uk (Tim Rowe) Date: Tue, 19 Aug 2003 22:22:33 +0100 Subject: What's better about Ruby than Python? References: <38ec68a6.0308172319.431a4fde@posting.google.com> Message-ID: <9755kv4bku839cpsqrvch13504qagg7gev@4ax.com> On 18 Aug 2003 16:38:42 -0400, aahz at pythoncraft.com (Aahz) wrote: >Oh, come on, Brandon is *much* less of a troll than T*m*t*y R*e. Dangerously close to my name -- I hope it's not a typo and meant to /be/ my name! From aleax at aleax.it Mon Aug 4 03:18:50 2003 From: aleax at aleax.it (Alex Martelli) Date: Mon, 04 Aug 2003 07:18:50 GMT Subject: Example code for anydbm wanted... References: Message-ID: John D. wrote: > Does anyone have any good example code that shows how to use the "anydbm" > wrapper tp interface with a very simple database. like some examples of > how to use "dumbdbm"? Then perhaps at a later time, I'm going to want > to then interface it to a more robust database like PostGreSQL or mySQL. > But I want to external interface to "hide" the specifics and have a really > generic interface. > > I already played with Python's interface with PostGreSQL, but they don't > follow the generic Python models. At least my prev version didn't. I know of no Python interface to any SQL-based RDBMS that mimics the simplistic interface of anydbm and its underlying modules -- rather, Python's interfaces to SQL databases normally follow the "DB API" specs. If you will eventually want to migrate to PostGreSQL, SAP/DB, or the like, you're therefore better off starting right now with an SQL based interface rather than anydbm. Luckily, you have at least two choices for lightweight SQL based interfaces -- gadfly (which has a pure Python implementation, though you may speed it up by using some C-coded extension modules) and PySQlite, which directly interfaces to the lightweight, C-coded SQlite library for embedding SQL databases in any program. I suspect PySQlite is likely to be more suitable for your purposes (gadfly can have slow startup times, unless you keep it running in the background as another server process). Even if you do choose to use DB API compliant modules exclusively, starting, say, with PySQlite, you're most likely still better off encapsulating database access within a "database independence layer" module rather than strewing it around your program. SQL dialects accepted by different database engines have small but annoying quirks (I recommend O'Reilly's "SQL in a Nutshell" for a concise and useful review of some such issues) and DB API modules may add a few more points of divergence (such as the choice of %, ?, or others yet, for value-placeholders in SQL query strings). By encapsulating all of your DB accesses into one module, you keep such divergence under far better control than by strewing them around. Of course, like in any portability situation, it's unlikely that your code will actually BE portable unless you keep trying it out during development on at least two different platforms -- otherwise, it's all too easy to fall into some dependence on a specific plaftorm without realizing the fact. If you DO develop your code so that it runs against two or more separate DB API implementations, then if and when you need to add even more such implementations in the future your task will be manageable and with any luck actually pretty easy. Alex From rnd at onego.ru Wed Aug 6 00:32:00 2003 From: rnd at onego.ru (Roman Suzi) Date: Wed, 6 Aug 2003 08:32:00 +0400 (MSD) Subject: Adding PC Filename Extensions to Macintosh Filenames In-Reply-To: <3F306BC5.7000608@vt.edu> Message-ID: I must correct myself. Metainformation of file type on Mac is not in resource fork but in some small addition which usually appears at the beginning of file on foreign filesystems. Of course, FTP could drop it, but then again if Mac users were able to use FTP - this info must be present somewhere! Usually one cannot just download file ABC to Mac and use it: one must set it's type and creator, two four letter strings. (Disclaimer: I used 10 year old Macs 4 years ago, so probably it all changed) Sincerely yours, Roman Suzi -- rnd at onego.ru =\= My AI powered by GNU/Linux RedHat 7.3 From oren-py-l at hishome.net Thu Aug 28 02:55:14 2003 From: oren-py-l at hishome.net (Oren Tirosh) Date: Thu, 28 Aug 2003 02:55:14 -0400 Subject: Proposal: Magic Constants In-Reply-To: <000a01c36c9b$3ef54d20$1f00000a@house> References: <000a01c36c9b$3ef54d20$1f00000a@house> Message-ID: <20030828065514.GA87742@hishome.net> If these values are to be treated as literals rather than funky function calls they should be evaluated at module load time not when encountered during execution. Each literal should be evaluated only once regardless of the number of places it is referenced or how many times the code is executed. Any bad literals inside a function should be detected even if the function is never called. Here's how it might work: The compiler finds all custom literals in the module, merging identical ones and puts them somewhere in the marshalled code object for the module. At the top nesting level of the module, before any reference to the custom literals (but possibly after some imports and assignments) the compiler places a call to the literal initialization code. This call will evaluate all custom literals and put them into a tuple of literals in the module namespace. The module code object and all its nested code objects (functions, class definitions, etc) index into this tuple when referring to custom literals. Alternatively, these literals can actually be loaded into the co_consts of the code objects and referenced with the LOAD_CONST opcode like any other literal. The effect is NOT global across all modules. Namespace conflicts must be resolved locally and explicitly (using Bernhard Herzog's idea of __literals__ = {...} or something similar). All modules get an initial literals list that contains 'i'. The code for complex numbers can then be removed from the interpreter and placed in an extension module that is imported on demand. The default literals list might be changed globally in site.py but that would be at your own peril. Oren From afriere at yahoo.co.uk Mon Aug 25 22:43:15 2003 From: afriere at yahoo.co.uk (Asun Friere) Date: 25 Aug 2003 19:43:15 -0700 Subject: Determinig position of a element in a list References: <3F4A955B.B1659F4A@alcyone.com> Message-ID: <38ec68a6.0308251843.7069b764@posting.google.com> Erik Max Francis wrote in message news:<3F4A955B.B1659F4A at alcyone.com>... > Przemo Drochomirecki wrote: > > > i'm wondering if there is any tricky way for doing following thing: > > ... > > i can implement function index (e.x. index(5,A) = -1, index(7,A) = 2), > > but > > maybe there's is simpler(builtin?) solution > > Yep, the -- wait for it -- .index method on the list object: :) But do note that, despite its name, 'list.index' does NOT return the "position of an element in a list," but rather the position of the _first equivalent_ element in a list. Although for the example you gave that amounts to the same thing. Whether you regard this as a wart or the only logical choice probably depends on the use to which you want to put '.index' eg. >>> class MyInt(int) : pass >>> a=MyInt(1);b=MyInt(2);c=MyInt(3);d=MyInt(2) >>> l = [a,b,c,d] >>> l[l.index(d)] == d True >>> l[l.index(d)] is d False >>> From vanevery at 3DProgrammer.com Tue Aug 12 15:06:20 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Tue, 12 Aug 2003 12:06:20 -0700 Subject: Python vs. C# References: <3f357a9b@shknews01> Message-ID: Andrew Bennetts wrote: > On Tue, Aug 12, 2003 at 02:27:26AM -0700, Brandon J. Van Every wrote: >> >> Good to hear that some people understand what it means when >> Microsoft puts 100% of the company behind something. Remember, last >> time around we got IE and Netscape vanished. > > When was that? > > I'm happily running Mozilla as my web browser, and have been for well > over a year now. I'm hardly alone in this. > > Sure, Netscape-the-company might be effectively dead, Why do you bother to contradict me, if you're only going to make my point for me? > but I don't care about that. I bet you don't care about the market share of that software either. Basically, most c.l.p people would be happy if they held onto a 1% market share as the rest of the world changes. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From dsylvest at adelphia.net Mon Aug 4 22:02:11 2003 From: dsylvest at adelphia.net (Dennis Sylvester) Date: Tue, 05 Aug 2003 02:02:11 GMT Subject: TKinter, PyQT and wxPython (BOA) Message-ID: Interested in any opinions, studies, etc., concerning the GUI tool(s) to use for Python. Specifically, which would you recommend (and why) for building GUI apps in Python: TKinter BOA PyQT Thanks, Dennis From bkc at murkworks.com Tue Aug 19 09:56:45 2003 From: bkc at murkworks.com (Brad Clements) Date: Tue, 19 Aug 2003 09:56:45 -0400 Subject: py2exe service doesn't work, can't connect to service controller ? Message-ID: <3F41F576.14352.14BE73C2@localhost> I'm trying to get a simple service to work with py2exe and python 2.3 I get this error when I start it (after registering it) The description for Event ID ( 240 ) in Source ( UMXWIN32SVC ) cannot be found. The local computer may not have the necessary registry information or message DLL files to display messages from a remote computer. The following information is part of the event: 1063, The service process could not connect to the service controller.. I then tried the sample MyService and I get the same problem. After building it, I then register it then try to start it, but it fails. The description for Event ID ( 240 ) in Source ( MyService ) cannot be found. The local computer may not have the necessary registry information or message DLL files to display messages from a remote computer. The following information is part of the event: 1063, The service process could not connect to the service controller.. The contents of the dist directory for the sample MyService is Directory of C:\temp\py2exe\MyService 08/19/2003 09:55a

. 08/19/2003 09:55a .. 08/19/2003 09:55a 324,416 MyService.exe 05/30/2003 06:12p 847,920 python22.dll 07/29/2003 06:54p 974,900 python23.dll 01/18/2002 04:44p 65,536 PyWinTypes22.dll 07/27/2003 10:23p 86,084 PyWinTypes23.dll 07/27/2003 10:23p 61,497 win32api.pyd 07/27/2003 10:23p 28,731 win32event.pyd 07/27/2003 10:23p 28,732 win32evtlog.pyd 07/27/2003 10:23p 28,733 win32service.pyd 07/29/2003 06:55p 57,392 _sre.pyd (Note the double copying of pythonxx.dll's) The registry entry looks ok. Any ideas? -- Brad Clements, bkc at murkworks.com (315)268-1000 http://www.murkworks.com (315)268-9812 Fax http://www.wecanstopspam.org/ AOL-IM: BKClements From vanevery at 3DProgrammer.com Mon Aug 18 18:02:45 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Mon, 18 Aug 2003 15:02:45 -0700 Subject: What's better about Ruby than Python? References: Message-ID: Tom wrote: > "Brandon J. Van Every" wrote in message > news:... > >> This is not a troll. > > "I am not a crook." R.Nixon You certainly are a waste of my time, Tom. Welcome to my killfile. I'd like to think that if I'm a waste of your time, it's for different reasons and not ones of my own designing. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From mpeuser at web.de Sat Aug 16 06:24:00 2003 From: mpeuser at web.de (Michael Peuser) Date: Sat, 16 Aug 2003 12:24:00 +0200 Subject: How to terminate a TkinterApp correctly? References: <3F3DFCF4.5020109@aon.at> Message-ID: "Gregor Lingl" schrieb im Newsbeitrag news:3F3DFCF4.5020109 at aon.at... > I'm working on a windows machine > > I've written a Tkinter-app (sort of game) which > consists mainly of an animation which is driven > by a while True: ... loop. > [....] > Only if this loop is terminated by some other means > - e.g. game over - before closing the window no > error message is displayed. > Correct > How, i.e. by what sort of event handler or error handler > can I avoid this annoying behaviour of my program? > You can bind and act accordimngly, or intercept the action altogether. Example: ----------------------------- from Tkinter import * def killingAction(ev): print "Destroyed" def kidding(): print "not killing" l.config(text="just kidding") l.master.protocol("WM_DELETE_WINDOW",original) l=Label(text="Kill me!") l.pack() l.bind("",killingAction) original= l.master.protocol("WM_DELETE_WINDOW",None) l.master.protocol("WM_DELETE_WINDOW",kidding) l.master.destroy=lambda: 0 mainloop() -------------------------------------------- Kindly Michael P > Regards, Gregor > From andresv at hot.ee Wed Aug 13 03:48:31 2003 From: andresv at hot.ee (Andres Viikmaa) Date: Wed, 13 Aug 2003 10:48:31 +0300 Subject: unsigned int \ long References: Message-ID: <3f39ece8$0$158$bb624dac@diablo.uninet.ee> look module struct -- Interpret strings as packed binary data Andres "Roman Yakovenko" wrote in message news:mailman.1060753100.20465.python-list at python.org... Hi. I need to work with integer as unsigned integer, but I can't find documentation how can I do it. Some reference on this will be appreciated. For example (unsigned int)(-1) == 0xFFFFFFFF. Thanks. Roman. From tjreedy at udel.edu Fri Aug 22 11:10:49 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 22 Aug 2003 11:10:49 -0400 Subject: For Kenny Tilton: Why do I need macros revisited. References: <3f45484f$1_6@corp.newsgroups.com> <3F45A7BF.4060806@nyc.rr.com> <8dk1b.2825$Ej6.1159@newsread4.news.pas.earthlink.net> Message-ID: <40udnfEuVojnr9uiXTWJjg@comcast.com> "Paul Foley" wrote in message news:m24r09vqbr.fsf at mycroft.actrix.gen.nz... > Scheme, as such, is barely a language. It's pretty useless on its own. > Most of the functionality of an actual Scheme /implementation/ is > extra-standard stuff (i.e., not Scheme), which, naturally enough, > every implementor does differently. Core Python, while useful on it own, is also pretty sparse. So I gather it would be something like having multiple Python implementations (of comparable popularity) with different sets of builtins and overlapping but incompatible 'standard' libraries. The Python community is fortunate to have avoided that. ... > Scheme macros are not the same as Lisp macros. Scheme macros are a > lot more complicated (and less useful; but most Scheme implementations > also offer Lisp-style macros...) Please excuse my confusing of Scheme with Lisp. I am pleased to find that my difficulty in reading the Scheme macro stuff wasn't just me. But note that there have been proposals that if Python were to have a macro facility, it should be 'hygenic', which I presume means like Scheme macros. Until some advocate of a Python macro facility adds more detail to the proposal beyound 'Lisp/Scheme-like maco facility', it is really hard for someone like me, who has used neither, to have much of any concrete idea of what is being proposed. Terry J. Reedy From jjl at pobox.com Tue Aug 5 11:45:51 2003 From: jjl at pobox.com (John J. Lee) Date: 05 Aug 2003 16:45:51 +0100 Subject: ANN: Snakelets 1.1 (simple-to-use web app server with dynamic pages) References: <3f2ea0a0$0$49110$e4fe514c@news.xs4all.nl> <3f2f7bf4$0$49103$e4fe514c@news.xs4all.nl> Message-ID: <87n0eods5s.fsf@pobox.com> Karl Scalet writes: [...] > the reason why I asked for CGI was that I potentially > will hold a course about python/webprogramming (very [...] > CGI capabilities there. Why CGI at all: Simple because > if I introduce some simple web-applications in the course > the attendees could take them and most easily transport > them to a common web-hoster. I know about CGIHTTPServer [...] Albatross might be worth a look too (also simple, pure-Python hence easy install, small step up from plain CGI). John From clifford.wells at comcast.net Sun Aug 10 19:12:45 2003 From: clifford.wells at comcast.net (Cliff Wells) Date: Sun, 10 Aug 2003 16:12:45 -0700 Subject: Slogan: Getting Rich Overnight In-Reply-To: <3F36BF71.6090204@tismer.com> References: <3F36BF71.6090204@tismer.com> Message-ID: <1060557165.9832.8.camel@devilbox.homelinux.net> On Sun, 2003-08-10 at 14:56, Christian Tismer wrote: > But is there any way for such a slogan to pass spam at all? > If I remove the ambiguity, the slogan gets lame. > Any ideas? jkadf Getting Rich Overnight zxklaf -- She licked her lips and turned to feather -Bauhaus From donot at likespam.com Wed Aug 27 14:53:53 2003 From: donot at likespam.com (Rich) Date: Wed, 27 Aug 2003 11:53:53 -0700 Subject: learning to program References: <3F4CED6E.D04D35D6@engcorp.com> <5bspkv87u1q0v9aupajrrkjuutuh3f5o44@4ax.com> <3F4CF363.CAF6A14E@engcorp.com> Message-ID: Thanks On Wed, 27 Aug 2003 14:07:31 -0400, Peter Hansen wrote: >Rich wrote: >> >> This is the only post I am able to see, sorry about re posting. I >> thought if I changed the subject heading I might be able to see the >> post. > >You should be able to see the replies that you missed via Google Groups, >as soon as they are indexed and on the web: > > http://groups.google.com/groups?q=comp.lang.python > >-Peter From wolfoxbr at hotmail.com Fri Aug 22 09:03:14 2003 From: wolfoxbr at hotmail.com (Roberto Amorim) Date: Fri, 22 Aug 2003 10:03:14 -0300 Subject: crazy programming language thoughts References: <3f457487_7@corp.newsgroups.com> Message-ID: > The Python code: > > x = sin(10) + 50 * 20 * self.myfunctionXY(cos(30), 40) > > would be in Smalltalk something like: > > x := 10 sin + (50 * 20 * self myfunctionX: 30 cos y: 40). In fact, that would be x := 10 sin + (50 * 20 * (self myfunctionX: 30 cos y: 40)). unless you want to call myfunctionX:y: over the result of (50*20*self). :-) I love Python, and by far it's the language I use the most. However, when it comes to languages, Smalltalk is still my favorite. :-) From bokr at oz.net Fri Aug 8 00:27:31 2003 From: bokr at oz.net (Bengt Richter) Date: 8 Aug 2003 04:27:31 GMT Subject: passing multiple strings to string.find() References: <3F331A9B.9020907@vt.edu> Message-ID: On Thu, 07 Aug 2003 23:35:55 -0400, hokiegal99 wrote: >How do I say: > >x = string.find(files, 'this', 'that', 'the-other') > >currently I have to write it like this to make it work: > >x = string.find(files, 'this') >y = string.find(files, 'that') >z = string.find(files, 'the-other') > You might try the re module, e.g., >>> import re >>> rxo = re.compile(r'this|that|the-other') >>> pos = 0 >>> while 1: ... m = rxo.search(' Find this or the-other or that and this.', pos) ... if not m: break ... print '%4s: %s' % (m.start(), m.group()) ... pos = m.end() ... 6: this 14: the-other 27: that 36: this If some search strings have a common prefix, you'll have to put the longest first in the regex, since re grabs the first match it sees. Regards, Bengt Richter From nbm at mithrandr.moria.org Tue Aug 19 06:01:25 2003 From: nbm at mithrandr.moria.org (Neil Blakey-Milner) Date: Tue, 19 Aug 2003 12:01:25 +0200 Subject: usage of python 2.3 and Tk on freebsd ? In-Reply-To: <3F41A7D4.7020002@epost.de> References: <3F41A7D4.7020002@epost.de> Message-ID: <20030819100124.GA43252@mithrandr.moria.org> On Tue 2003-08-19 (06:30), Gerald Hein wrote: > I'm using FreeBSD 4.8 and upgraded to python 2.3. > I tried import Tk and got an error message telling me that python is not > configured for Tk. I never tried importing Tk before, so I don't know > what t I've to do to fix this. Python seems to have a problem with _tkinter. > What could be done in order to get python configured for Tk ? Hi Gerald, I'm guessing you're using FreeBSD's port system or a package built from it. It was decided to split off the tkinter module into a separate port - x11-toolkits/py-tkinter. Install that port, and your program using Tk should work. Good luck, Neil -- Neil Blakey-Milner nbm at mithrandr.moria.org From ma at Bell.com Sun Aug 3 10:17:32 2003 From: ma at Bell.com (xam) Date: Sun, 03 Aug 2003 14:17:32 GMT Subject: Interview with Guido in the Wall Street Journal References: <3f2cf93b$0$49106$e4fe514c@news.xs4all.nl> Message-ID: <0Q8Xa.16879$gU6.2518935@twister.nyc.rr.com> I believe the subscription is free, BTW. From ghowland at lupineNO.SPAMgames.com Sat Aug 23 15:22:02 2003 From: ghowland at lupineNO.SPAMgames.com (Geoff Howland) Date: Sat, 23 Aug 2003 19:22:02 GMT Subject: Modifying the {} and [] tokens References: <04cekv0s6ghjtuhl5j2gph7ltobdb5rsam@4ax.com> <62rekv0k4ucgrh46lkp27klq13pq8ppp5p@4ax.com> <1h3fkvg8mkeq69a8hriojugqfcp75hafjj@4ax.com> Message-ID: On Sat, 23 Aug 2003 21:56:08 +0300, Christos "TZOTZIOY" Georgiou wrote: >>>[snip of python's by design inability to modify the base C types: dict, >>>str, list etc] >> >>This post begins to read as an insult here, and continues. My >>incredible gall at thinking something may be better if it was changed >>and wanting to try it! I should be pelted with rocks for speaking the >>name Jehova. > >I am sorry, Geoff, but I can't understand how you perceived my post as >insulting. If I did understand a way, I would apologise. I just >snipped stuff in order to make my post shorter, according to netiquette. >How can the phrase inside the brackets seem insulting to you? Geoff, >please justify your clause, and I will gladly apologise. If you didn't mean it as insulting, than I am very sorry for taking it so and responding in the way I did. I saw it as I was being told that I am ignoring the good design philosophies of Python, and as such I should move on to another language. I have been told exactly this thing before (without being mistaking) so I suppose I am more sensitive to it than I would have been had I not had it said before. Sorry for misunderstanding you and becoming upset about it. :) >>Is this really the way this group is going to continue? > >I don't know, I can speak for myself only. How many people have >responded to you this "way" to make you wonder about the whole group? Maybe 2 here, to more or lesser degrees. Probably about 5 times on python IRC channels. >>Why? I respect Guidos decsions, Python needs a strong leader to make >>them and it got where it is (great language) by having him and the >>rest of the community help out in this regard. > >This is the deal, indeed; for example, I would enjoy very much generator >comprehensions in the language, and yet they were rejected. Exactly, and as long as it's ok to bring them up, then all is well. I was just feeling like I was being rebuked for doing so. In retrospect, I probably should have just not responded at all to the thread portion that I felt that way about, as other people were giving me answers I thought were completely even. I do appreciate Python's design decisions. It's what keeps it from becomming the things I dont like about Perl, where that does not seem to be the case. However, I still like having the rope to shoot myself in the foot if I so desire, but if it doesnt exist I'll get by without it. :) >>Is now no one allowed to say "hey, I think this should be done, and >>I'd like to make it happen to give it a try"? It's not like if it >>becomes a problem it couldn't be reverted and lesson learned right? >>Programming is ABOUT experimentation, not dogmatic obedience. > >My reply came to your specific feature request, ie Python allowing you >to modify the base types; your asking if *any* feature request is >disallowed is not justified. I consider your question similar to the >following dialog: > >- Can I have cherry pie with my meal? >- No, because the cook has decided it does not match with your meal, >which is fish. >- So no one is allowed to ask for dessert here? Well, this was because I took your post as hostility. I'm not sure I was out there in interpretting this way, as usually telling someone to "go somewhere else" when they inquire about things is meant that way. >I believe that the symbolism is childish, and this indeed you might find >it insulting, although it isn't. I am not as fluent in English as I >would like, so this is my way to express the general feeling I got from >your reply; I call it "black-and-white", or "ping-pong", lacking a >better English word, and describes a two-way communication where a >disagreement on the one side is perceived magnified as total rejection >on the other side. Im fine with the things being one way or another, no problems at all with it. I understand why base types arent allowed to be modified, cause while you could do it without damaing things, it would be a lot more likely that things would be damaged over time and you might never know you're including a module that changes behavior. It makes sense. That doesn't mean it wouldnt be useful, which is why I was inquiring. If it was possible, I'd probably do it because of it's usefulness. If it became a problem later, I could correct that. I am flexible that way, it is probably a good thing Guido and the Python community that helps design Python is not. Checks and balances. As long as it's still ok to inquire. I think the last thing that was really brought up in this "how dare you" type style was someone inquiring about protecting their code from people reading it. Some people near-flamed the guy for asking how to do this, and I think it is ridiculous. Everyone has their own purposes for tools, so my ire was up. :) >>>I really don't mind subclassing base types and using MyDict() instead of >>>{}. I want to be able to make my own APIs (MyDict.update *could* blow >>>whistles and roll twice on the floor before resetting the machine), but >>>I also want a steady and well-known API for base types (dict.update >>>*should* update a dictionary from another one). >> >>Why should it matter what you mind? It's my code. > >What should it matter what you mind then? It's Guido's language. >Either we both are allowed to say our minds, or not. My opinion is as >important as yours. Keep that in mind, please. Sure, but you were answering a question and saying "no" based on your opinions. That's tangential to the question, which is that I want to do something. That it's not possible is topical. That Guido/PythonLabs doesnt approve is topical, in the sense of a style guide. That you don't approve is topical on an advice level, but not on a "how do I do this" level. Thats my view of it, and since I was thinking you were saying I should "move on to another language for not liking everything exactly as it is now", then I took it as a judgement placement, rather than advise. Again, my misunderstanding and my appology. >The fact is, the subject has been brought up in the past, and it has >been skipped. I am not sure if has been rejected, so you might have a >chance. If you are as warm about this subject as you seem to be, write >a PEP; my vote will probably be positive. But Guido is the one to >convince, and he listens; my experience so far has shown that he never >replies the way you do, and that is good. > >This URL should be useful: >http://www.python.org/peps/pep-0001.html I actually wanted to do a proof of concept and try it before writing a PEP. Cause if it turns out to suck in practice, why bother with the PEP? I think now I would have to change the Python C code in order to try it, and that isnt acceptable to me as I wouldnt be able to really put it into effect in the real world and see if it works. I'm all for putting in the time to write and push a PEP if I think something is really worth it and I have proof in my own eyes. I'm also accepting if it gets rejected because it doesn't fit with the language. So far I haven't gotten to a point where I am confident enough about something I think should work a different way to do this. Maybe someday it will happen, maybe it wont. I'd like to help, but dont want to make suggestions that aren't really helpful until I'm convinced myself that they are. >>>With all due respect, Geoff, if this stuff is really important to you, >>>use Ruby. > >>Yes, throw the heathen into another language. I'm not good enough for >>this one. > >Your last statement is unjustified too, and "black-and-white", assuming >hidden meanings in my words. Geoff, I am picking my words very >carefully because I don't want to make you jump to the ceiling with >rage. Please read, don't assume. The difficulties of reading text. I showed this message to 2 other people, and they also thought it was telling me off instead of just explaining something to me. However, I still appologize for misreading your intentions and my response. >My sentence was a practical (and respectful!) suggestion; Ruby already >has what you want, and you like it, so why not use it, since the Python >community (and Guido most of all) are against such a modification? Did >you do a research in older newsgroup threads before posting? Yeah, I searched around for about 6 hours before posting this, also poking around in different books and the python interpretter. I didn't find this topic covered, but sometimes it's very hard to find things with common words like: python, dict, modification/override, etc. Ruby is a great language, but there are a couple reasons it wont be used in this circumstance. If it was possible and practical, then I would use it. >Don't spend your energy fighting with me (one-side fights: only on >USENET :), write a PEP and find good arguments for it. I dont intend to, I'm glad there was a misunderstanding and sorry I misunderstood (hope thats parseable). Maybe there will be a PEP on this someday, but it'll be harder to do without evidence that it works well in the real world first. -Geoff Howland http://ludumdare.com/ From graham at rockcons.co.uk Thu Aug 7 12:11:57 2003 From: graham at rockcons.co.uk (Graham Nicholls) Date: Thu, 07 Aug 2003 17:11:57 +0100 Subject: Extracting a short using struct - won't print. References: <3f3273f7$0$10777$afc38c87@auth.uk.news.easynet.net> <3F32758E.5734C64F@engcorp.com> <3f32779d$0$10780$afc38c87@auth.uk.news.easynet.net> Message-ID: <3f327a56$0$10770$afc38c87@auth.uk.news.easynet.net> Graham Nicholls wrote: > Peter Hansen wrote: > >> Graham Nicholls wrote: >>> >>> Thanks to Richard and Alex, I'm doing this: >>> >>> seg_stru=">BHH" >>> seg_data=self.fhand.read(struct.calcsize(seg_stru)) >>> data=struct.unpack(seg_stru,seg_data) >>> x=seg_data[1] >>> y=seg_data[2] >> >> Why are you unpacking the struct if you aren't going to use the >> unpacked data? > > Err, I'm trying to extract two shorts - the x and y size in pixels of an > image, which I'll use to scale it to fit another pair of parameters. What > makes you think I'm not using the data? Am I not - I thought I was! > > I realise that ">BHH" above ouhjt really to be "xHH" but aside from that, > I don't understand your point - theres more code after the debug in the > rel app - returning x and y. > >> >>> if debug: >>> print ("DEBUG: Image [%s] is [%d] by [%d] pixels" % >>> (self.fname,x,y)) >> >> Best way to troubleshoot this kind of thing, in my experience, >> is to insert "import pdb; pdb.set_trace()" into the code just >> above the failing line, then use the debugger to inspect the >> values directly just before they are used. (You need to execute >> the "r" or "return" command immediately after the debugger is >> entered... the rest is pretty straightforward to learn.) >> > I'll give that a go, thanks >> -Peter > OK, the code now looks like this: seg_stru=">xHH" seg_data=self.fhand.read(struct.calcsize(seg_stru)) data=struct.unpack(seg_stru,seg_data) x=seg_data[1] y=seg_data[2] import pdb ; pdb.set_trace() if debug: print ("DEBUG: Image [%s] is [%d] by [%d] pixels" % (self.fname,x,y)) return(x,y) When I run it, I get this: EBUG: Scaling image file hb.jpg to fit 100 100 DEBUG: Searching hb.jpg for dimensions DEBUG: found header type e0 DEBUG: found header type db DEBUG: found header type db DEBUG: found header type c0 --Return-- > /usr/local/lib/python2.3/pdb.py(972)set_trace()->None -> Pdb().set_trace() (Pdb) (Pdb) r > /home/graham/work/hsb/pdflive/pdf_merge(427)getsize() -> if debug: (Pdb) print x (Pdb) print y m (Pdb) Which _seems_ to indicate that unpack is not unpacking the shorts as shorts, but as chars. Is this right? Thanks Graham -- Graham Nicholls Rock Computer Consultancy From =?iso-8859-1?b?IkrpcvRtZQ==?= Fri Aug 22 17:15:55 2003 From: =?iso-8859-1?b?IkrpcvRtZQ==?= (=?iso-8859-1?b?IkrpcvRtZQ==?=) Date: Fri, 22 Aug 2003 23:15:55 +0200 Subject: Python/C API - PyArg_ParseTuple problem ? References: <7h3fzjt1rlh.fsf@pc150.maths.bris.ac.uk> Message-ID: Just remembered I forgot to mention, in order to import the module from Python you'll have to ln -s the library to flpython.so :) And the function where all the stuff happens is Widget_init, in Widget.cpp... -- J?r?me Laheurte Everyone is a genius. It's just that some people are too stupid to realize it. From sjmachin at lexicon.net Wed Aug 6 08:12:18 2003 From: sjmachin at lexicon.net (John Machin) Date: 6 Aug 2003 05:12:18 -0700 Subject: How do I get a reference to a KEY value of a dictionary? References: <645db655.0307311636.71923378@posting.google.com> Message-ID: "Andy C" wrote in message news:... > > These days I have an extension which merely subclasses dict to add on > > a key reference method and an increment method which does something > > like: > > You did this in C or python? If in python, how did you do it? (without > keys()?) If in C, why don't you submit it to the source tree? C. There were two people interested in having it in the core, me and Pat Malone. From merkosh at hadiko.de Wed Aug 20 13:48:27 2003 From: merkosh at hadiko.de (Uwe Mayer) Date: Wed, 20 Aug 2003 19:48:27 +0200 Subject: ascii2dec References: Message-ID: Uwe Mayer wrote: > this must sound stupid to you, but I'm ages out of Python and I just can't > find a function to convert 4 bytes of binary data to an integer value: > > length=f.read(4) # get length in binary > length=socket.htonl(length) # swap bytes > > #convert 4 bytes to integer Sorry, socket.htonl(...) already expects a number, so its: > #convert 4 bytes to integer > length=socket.htonl(length) # swap bytes i.e. How to convert: length = '\x01\x00\x00\x00' to an integer Uwe -- From richie at entrian.com Tue Aug 12 11:36:11 2003 From: richie at entrian.com (Richie Hindle) Date: Tue, 12 Aug 2003 16:36:11 +0100 Subject: mouse control with python In-Reply-To: References: Message-ID: Hi Ken, > Very nice. Very helpful! Thank you!! No problem! > I ran around looking at ctypes and the User32 dll looking for mouse click > control and couldn't find anything. Is there a way for me to send a mouse > click too? SendInput is the API you're looking for - documentation is at http://tinyurl.com/jrxm You'll have to figure out the details yourself I'm afraid, but it should be pretty similar to my GetGUIThreadInfo stuff. -- Richie Hindle richie at entrian.com From carsten at gnocchi.dialup.fu-berlin.de Sun Aug 24 14:09:37 2003 From: carsten at gnocchi.dialup.fu-berlin.de (Carsten Schultz) Date: Sun, 24 Aug 2003 20:09:37 +0200 Subject: suid Python script Message-ID: <11vaib.v36.ln@gnocchi.dialup.fu-berlin.de> Hi, I want to run a python script suid root. I will use a C wrapper for that, because Linux does not respect the suid bit on scripts. But, is it safe? Do I have to take special precautions? Do I have to wipe the environment? Will a user be able to use some kind of user configuration to execute arbitrary python code as root? Thanks, Carsten -- Carsten Schultz (2:40, 33:47), FB Mathematik, FU Berlin http://carsten.fu-mathe-team.de/ PGP/GPG key on the pgp.net key servers, fingerprint on my home page. From tjreedy at udel.edu Mon Aug 11 12:32:13 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 11 Aug 2003 12:32:13 -0400 Subject: Slogan: Getting Rich Overnight References: <3f373ac6@shknews01> Message-ID: "Christian Tismer" wrote in message news:mailman.1060602978.32477.python-list at python.org... > I was not picking them. > They were said by another guy, who > said in German > "Python hat mich ?ber nacht reich gemacht". > > My problem is not that sentence. In German, > it still has a useful meaning. > My problem is the impossibility > to translate it into English without loosing meaning. "Python Makes You Glow' covers the main point. TJR From adalke at mindspring.com Thu Aug 7 16:01:06 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Thu, 7 Aug 2003 14:01:06 -0600 Subject: python-2.3 Checksum Error References: Message-ID: Sanjiv Kumar: > I need to install python-2.3 on solaris machine using gcc version 2.95.2 . I > dowloaded the file "Python-2.3.tgz" file from www.python.org . This tar file > gives checksum error during untar. Here are the steps I have followed. http://www.python.org/2.3/bugs.html ] It has been reported that untarring the source tarball using Solaris tar ] can fail. This is caused by some pathnames being too long for Solaris ] tar to handle. Using GNU tar should allow for untarring on Solaris. Andrew dalke at dalkescientific.com From mwh at python.net Fri Aug 22 08:53:22 2003 From: mwh at python.net (Michael Hudson) Date: Fri, 22 Aug 2003 12:53:22 GMT Subject: Misleading description of [i:j:k] slicing? References: <7h33cfv2az7.fsf@pc150.maths.bris.ac.uk> Message-ID: <7h3u18926vm.fsf@pc150.maths.bris.ac.uk> Raoul Gough writes: > Michael Hudson writes: > > > Raoul Gough writes: > >> Seems to me that "0 <= n < abs(i-j)" is wrong, since the range of n > >> gets multiplied by k. > > > > How about "0 <= n < abs(k*(i-j))"? But you're right, what's there is > > a bit wrong. It's surprisingly hard to get this written down well. > > The idea's not that hard, but a terse explanation is surprisingly > > hard (when you start omitting values it gets even more fun!). > > > > Please submit a patch (assign it to me if you like -- the above > > passage is my fault). > > I've submitted a bug to the sourceforge tracker for Python, but > couldn't see how to assign it to anyone. Bug number is 792656, hope > this is what you meant. I've assigned it to myself now, cheers. Cheers, mwh -- I'd certainly be shocked to discover a consensus. ;-) -- Aahz Maruch, comp.lang.python From mcherm at mcherm.com Wed Aug 6 13:10:07 2003 From: mcherm at mcherm.com (Michael Chermside) Date: Wed, 6 Aug 2003 10:10:07 -0700 Subject: FWD: Re: Problem w/ IDLE on Win2000 Message-ID: <1060189807.3f31366f342c4@mcherm.com> Aahz writes: > Is there an SF bug for this? Should I add it to bugs.html? I couldn't find one (may have missed it), so I entered one this morning, figuring a duplicate was better than a dropped issue. I can't give a link to the one I entered... source forge is too slow to be used right now. Yes, adding to bugs.html is good. I wish we'd caught this before 2.3. Unfortunately, I usually avoid "Program Files" for exactly this reason, and I'm guessing other testers did the same. -- Michael Chermside From mertz at gnosis.cx Sun Aug 3 02:43:43 2003 From: mertz at gnosis.cx (Lulu of the Lotus-Eaters) Date: Sun, 03 Aug 2003 02:43:43 -0400 Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> <23bcqKAykjK$Ewhy@jessikat.fsnet.co.uk> Message-ID: Robin Becker wrote previously: |I don't have any data here, but I believe Python is just a little too |weakly typed for compiling to float*float type assembler efficiently. Repeat this every morning: PYTHON IS A STRONGLY TYPED LANGUAGE WITH LATE BINDING! (objects are typed in Python, names are not) -- mertz@ _/_/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY: \_\_\_\_ n o gnosis _/_/ Postmodern Enterprises \_\_ .cx _/_/ \_\_ d o _/_/_/ IN A WORLD W/O WALLS, THERE WOULD BE NO GATES \_\_\_ z e From letterbox1001 at hotmail.com Fri Aug 22 17:16:12 2003 From: letterbox1001 at hotmail.com (New_aspect) Date: 22 Aug 2003 14:16:12 -0700 Subject: Aspect oriented Everything? Message-ID: <32cc321c.0308221316.2f5793ac@posting.google.com> Hello, Aspect oriented Software development seems to be expanding in the popular vision of developers, with more and more IDE 'add-ons' and even more specialized tools,Jboss etc. I've seen more and more languages integrate AOP,AspectJ (Java), AspectR(Ruby)etc.Aspect oriented does seem to be the place to go from a developer standpoint.What I want to know is,if anybody on a commercial scale is using AOSD to develop commercial products? Is an Open Source development ever going to gain the trust of industry? It may be ok for personal projects and other Open Source material but will your bank ever accept it? Is it the fact that AOP is new and, for most,confusing or is it the fact that AOP has developed in the environment it has.i.e Open Source,that may dissuade commercial development shops from accepting AOP. What are the main features that may lead to AOSD adoption? Is AOP the next step on from OOP? Is it another chance for some of the lesser utilised languages to step up to Java and C++? Your opinions on the subject would be appreciated? Design features are one thing but widespread adoption is another, or is it? Anything you care to add on the subject would be appreciated on this short questionnaire. http://www.geocities.com/aspect505 Thank you for your participation. Shane Hassan. http://www.geocities.com/aspect505 From aleaxit at yahoo.com Tue Aug 19 07:43:11 2003 From: aleaxit at yahoo.com (Alex Martelli) Date: Tue, 19 Aug 2003 13:43:11 +0200 Subject: What's better about Ruby than Python? References: <3F41505F.69D18CC8@alcyone.com> Message-ID: Doug Tolton wrote: ... > abstractions and better programmer productivity. Why not add Macro's > allowing those of us who know how to use them and like them to use > them. If you hate macros, or you think they are too slow, just don't > use them. "No programmer is an island"! It's not sufficient that *I* do not use macros -- I must also somehow ensure that none of my colleagues does, none of my clients which I consult for, nobody who posts code asking for my help to c.l.py or python-help -- how can I possibly ensure all of this except by ensuring that macros ARE NOT IN PYTHON?! "Slow" has nothing to do with it: I just don't want to find myself trying to debug or provide help on a language which I cannot possibly know because it depends on what macros somebody's defined somewhere out of sight. Not to mention that I'd have to let somebody else write the second edition of the Nutshell -- if Python had macros, I would have to cover them in "Python in a Nutshell". They don't change the underlying language, they just add a > more useful abstaction capability into the language. They may not change the "underlying" language but they sure allow anybody to change the language that is actually IN USE. That is definitely NOT what I want in a language for writing production-level applications. I dearly hope that, if and when somebody gives in to the urge of adding macros to Python, they will have the decency to FORK it, and use an easily distinguishable name for the forked Python-with-macros language, say "Monty". This way I can keep editing future editions of "Python in a Nutshell" and let somebody else write "Monty in a Nutshell" without any qualms -- and I can keep programming applications in Python, helping people with Python, consulting about Python, and let somebody else worry about the "useful abstaction" fragmentation of "Monty". If that "useful abstaction" enters the Python mainstream instead, I guess the forking can only be the last-ditch refuge for those of us (often ones who've seen powerful macros work in practice to fragment language communities and end up with "every programmer a different language"... do NOT assume that fear and loathing for powerful macro systems comes from LACK of experience with them, see also the Laura Creighton posts whose URLs have already been posted on this thread...) who'd much rather NOT have them. But maybe moving over to Ruby might be less painful than such a fork (assuming THAT language can forever stay free of powerful macro systems, of course). I have nothing against macros *IN GENERAL*. I just don't want them *in my general-purpose language of choice for the purpose of application programming*: they add NOWHERE NEAR ENOUGH PRODUCTIVITY, in application programming, to even START making up for the risks of "divergence" of dialects between individuals, groups, and firms. If I was focused on some other field than application programming, such as experimental explorations, tinkering, framework-writing, etc, I might well feel quite otherwise. But application programming is where the big, gaping hole of demand in this world is -- it's the need Python is most perfectly suited to fulfil -- and I think it's the strength it should keep focus and iinvestments on. Alex From CousinStanley at hotmail.com Mon Aug 11 13:05:18 2003 From: CousinStanley at hotmail.com (Cousin Stanley) Date: Mon, 11 Aug 2003 10:05:18 -0700 Subject: CLI+GUI References: <2259b0e2.0308080948.5a95e383@posting.google.com> <2259b0e2.0308090530.7519f195@posting.google.com> <2259b0e2.0308110517.7c4fa8c8@posting.google.com> Message-ID: | Same problem, different solution: | it made me give up on Windows 98 ... Eric ... I do plan on eventually moving to a Linux distribution in the near future, but have to deal with what I have at the moment ... The limited experimentation that I've done using Knoppix, proved to me that Tk under Win98 was the problem as the same scripts that hang intermittently under Win98 ran under Knoppix without any problems ... It's also good to hear that the Tk problems under later versions of Windows are alleviated ... Thanks for the info ... -- Cousin Stanley Human Being Phoenix, Arizona From davecook at nowhere.net Tue Aug 19 05:45:34 2003 From: davecook at nowhere.net (David M. Cook) Date: Tue, 19 Aug 2003 09:45:34 GMT Subject: Brandon's abrasive style (was Re: What's better about Ruby than Python?) References: <38ec68a6.0308172319.431a4fde@posting.google.com> Message-ID: <2lm0b.34671$Ij4.16947@news2.central.cox.net> In article , Brandon J. Van Every wrote: > I ask tough questions about Python vs. other languages and platforms. Why don't you work on some tough solutions? > Some > people can't handle it. Maybe they'd handle it if I diplomatically sugar > coated it, but I'm not going to. Things to irritate the "Brandon's a troll" > crowd some more: > - Python is not a good language for low-level 3D graphics problems. C++ is > better. Not many programmers are going to write their own low-level 3D code. Python has bindings to 3D libraries. For some specialized applications this will not be adequate, but I don't think that is something worth worrying too much about. > - Python isn't a rapid prototyping godsend for every problem out there. Someone said that it was? BTW, in your experience, for which problems is Python not good for rapid prototyping? > - GUI and tools support can end up being more important than language > niceties. Luckily Python has both excellent GUI and tool support *and* language niceties. > - Microsoft C# and .NET are strategic threats to Python's prosperity and > vitality, if not survival. Sounds like a good opportunity for someone who sees such a threat to work out and implement a response. > - Pythonistas should consider trying to eat Java's lunch, because they > aren't going to eat Microsoft's lunch. Sounds like a good opportunity for someone interested in eating Java's lunch to work out and implement a plan for doing so. > - Ruby has some mindshare among people with knowledge of Python. OK. > - Yet unnamed languages are capable of taking Python's place on the food > chain. I'll worry about it when they get names. I like learning new languages. Maybe unnamed language will be more fun than Python. > - You have to promote your language, grow its market share, to prevent that > from happening. Sounds like a good opportunity for someone interested in marketing. Dave Cook From robert.hayes at havok.com Fri Aug 15 10:10:49 2003 From: robert.hayes at havok.com (Robert Hayes) Date: Fri, 15 Aug 2003 15:10:49 +0100 Subject: thread debugging Message-ID: Hi, This may well be a very stupid question, but I'll ask it anyway: I have a script that uses Thread classes. All it does (when called as a __main__ script) is initialise the classes and start() them. Then it exits. The problem is that I can't debug those threads with a standard debugger (I'm using PythonWin 157 btw), because the script has already exited! (even though the threads are still running). So any breakpoints I set are ignored... My question is thus: is impossible to debug this threaded code, or is there some way that I can? (preferable using pythonwin; sorry, my *nix friends, but I am confined to windows for this one ;)) thanks, ~Rob From skip at pobox.com Thu Aug 21 10:34:36 2003 From: skip at pobox.com (Skip Montanaro) Date: Thu, 21 Aug 2003 09:34:36 -0500 Subject: gdbm compatibility between linux and freebsd In-Reply-To: <877k57paom.fsf@gmx.net> References: <95f72778.0308210010.5b493c9b@posting.google.com> <877k57paom.fsf@gmx.net> Message-ID: <16196.55420.687044.447886@montanaro.dyndns.org> Arne> some people say bdb is not that problematic but I don't know... I copy my 20MB+ SpamBayes database (a bsddb-based shelve file) from my Powerbook to my Linux mail server all the time with no problem. Arne> bdb databases can be be dumped to some interchangeable format. In the Python distribution you will find Tools/scripts/{db2pickle.py, pickle2db.py} which were written to help people migrate between Berkeley DB 1.85 and 4.1.25 files, but they should also work to transfer db files between systems. Skip From glingl at aon.at Sat Aug 16 05:44:20 2003 From: glingl at aon.at (Gregor Lingl) Date: Sat, 16 Aug 2003 11:44:20 +0200 Subject: How to terminate a TkinterApp correctly? Message-ID: <3F3DFCF4.5020109@aon.at> I'm working on a windows machine I've written a Tkinter-app (sort of game) which consists mainly of an animation which is driven by a while True: ... loop. If I close the App's window by clicking the right upper standard-X-Button, the program doesn't terminate cleanly. Instead a somewhat cryptic error message is displayed, e.g.: .... TclError: invalid command name ".12880040.12880944" which - I suppose - stems from the interpreter trying to execute some statement in the infinite loop. Only if this loop is terminated by some other means - e.g. game over - before closing the window no error message is displayed. How, i.e. by what sort of event handler or error handler can I avoid this annoying behaviour of my program? Regards, Gregor From dtolton at yahoo.com Mon Aug 11 14:48:51 2003 From: dtolton at yahoo.com (Doug Tolton) Date: Mon, 11 Aug 2003 18:48:51 GMT Subject: Multi-Line Comment Message-ID: <4qofjvg3bh9smlnb1do4f0lhjga7bacnu3@4ax.com> I've been using Python for quite some time now, and I'm a bit stumped. Does it really not have a multi-line comment? I think I must just be missing something simple and stupid. Thanks in advance. Doug Tolton From ryanlowe0 at msn.com Mon Aug 25 18:37:48 2003 From: ryanlowe0 at msn.com (Ryan Lowe) Date: Mon, 25 Aug 2003 22:37:48 GMT Subject: python gripes survey References: Message-ID: <0dw2b.194888$_R5.73038469@news4.srv.hcvlny.cv.net> "Josh" wrote in message news:bidr0d$p9g$1 at fred.mathworks.com... > sismex01 at hebmex.com wrote: > > [Afanasiy] > >> Returning a struct in C is > >> easier to deal with than returning a near-mystery tuple in Python. > >> > > > You *really* *must* *be* *kidding*. > > > -gustavo > > It's really pretty easy: > > typedef struct { > int x; > int y; > } T; > > T f() { > T t = { 1, 2 }; > return t; > } > > int main() { > T t = f(); > return 0; > } > > And arguably easier to deal with than Python in that the fields are > named. I think that's all Afanasiy was getting at. is it that hard to send a dictionary? i dont know how that compares to a tuple in terms of speed/memory usage, but its not a whole lot harder to use than a tuple. def fruit() : return {'apple' : 'A', 'orange' : 'B'} >>> food = fruit() >>> food['apple'] ... 'A' anyone have any more things they dont like or, better yet, feel are missing from python? ive got a pretty big list going. ill post a link when i get it uploaded. "Andrew Dalke" wrote in message news:P372b.1862$Jh2.521 at newsread4.news.pas.earthlink.net [...] > > > code blocks (like Smalltalk) > > > > is this what it sounds like? do you name a block of code and call it like > an > > inline function with no parameters? > > Consider the following Ruby code > > [ 1, 3, 5 ].each { |i| puts i } > > The > |i| puts i > is an *unnamed* code block which does take parameters. > The [] is a container, and [].each sends the code block to > each of the elements in the container. See > http://www.rubycentral.com/book/tut_containers.html > i looked into code blocks. they still seem a bit confusing, but from what i learned i dont see any advantage over python's generators. for example take these two versions of code that produces the fibonacci series: RUBY def fibUpTo(max) a, b = 1, 1 # parallel assignment while a <= max yield i1 a, b = b, a+b end end fibUpTo(1000) { |f| print f, " " } PYTHON def fibUpTo(max) : a, b = 1, 1 while a <= max : yield a a, b = b, a+b >>> for f in fibUpTo(1000) : print f, i think the python version is much more intuitive. are there more complicated uses of code blocks that would make them more powerful than python's generators? i think i read a PEP or something about adding the ability to pass info into a generator. if this doesnt exist yet or ever, that would probably be a good difference, but i cant think of a good example to illustrate this... From zephyr01 at alltel.net Tue Aug 12 23:31:46 2003 From: zephyr01 at alltel.net (Hans Nowak) Date: Tue, 12 Aug 2003 23:31:46 -0400 Subject: customizing and/or/not In-Reply-To: References: Message-ID: <3F39B122.3080306@alltel.net> Simon Burton wrote: > Just reading about the new Sets... and this came up. > Why can't we customize the and/or/not operators? > I see this as making one's own boolean type. > Is it possible? Probably not. The 'and' and 'or' operators are special, in that they do short-circuit evaluation (as opposed to the binary operators & and |). Even if it would be possible to define a magic method __land__ or __lor__, they are not guaranteed to be called. Consider a and b ...if a is true, then b is never evaluated. A hypothetical call a.__land__(b) would be impossible without evaluating b first. Ditto for 'or'. 'not' is a different bowl of soup, it *can* be customized using the __nonzero__ magic method: >>> class Foo: def __init__(self, value): self.value = value def __nonzero__(self): return not self.value >>> f = Foo(42) >>> not f, not not f (1, 0) >>> f = Foo([]) >>> not f, not not f (0, 1) HTH, From wt at nic.fi Sun Aug 10 01:34:03 2003 From: wt at nic.fi (Timo Virkkala) Date: Sun, 10 Aug 2003 08:34:03 +0300 Subject: Slogan: Getting Rich Overnight In-Reply-To: References: Message-ID: Robert Kern wrote: > In article , > Christian Tismer writes: > [snip] > >>I loved this statement very much, and I have to say, this >>is essentially my feeling for myself, since many years now. >>I could imagine that this might be a candidate for next year's >>Python congress' slogan. "Python makes you rich, overnight". >>Not by money, in the first place, but by multiplying your >>own capabilities, immediately. > > While I certainly share that sentiment, I would advise caution in the phrasing > of such a slogan: if I hadn't seen your name, I would have skipped your article > as spam! I _did_, the first time around. -- Timo Virkkala | wt at nic.fi "In the battle between you and the world, bet on the world." From sminni_news at minisoftindia.com Sat Aug 30 21:45:20 2003 From: sminni_news at minisoftindia.com (Sanjay Minni) Date: 30 Aug 2003 18:45:20 -0700 Subject: python for dev of CAD type software References: <836a2f21.0308162222.413fefaa@posting.google.com> Message-ID: <836a2f21.0308301745.33b2483e@posting.google.com> Niki Spahiev wrote in message news:... > 8/17/2003, 9:22:04, Sanjay Minni wrote: > > SM> is python suitable for a production level > SM> deployment of CAD type of software. > > For CAD/CAM look at www.vintech.bg Is there an english version of this site ? also the site opens with difficulty Sanjay Minni From ryanlowe0 at msn.com Sat Aug 23 23:52:24 2003 From: ryanlowe0 at msn.com (Ryan Lowe) Date: Sun, 24 Aug 2003 03:52:24 GMT Subject: python gripes survey References: <7s6gkv031b940dsc522pbh5g30q4nj5vd1@4ax.com> Message-ID: "Geoff Howland" wrote in message news:7s6gkv031b940dsc522pbh5g30q4nj5vd1 at 4ax.com... > On Sat, 23 Aug 2003 15:39:27 GMT, "Ryan Lowe" > wrote: > > Just to point some things out since I started the {} [] thread. I was > trying to do something hacky, and while I wanted the [].len() type > calls for my team mates, I never had a problem with the current len() > and understand the reasoning behind it. [].len() is more uniform, but > it also changes the requirements for the language in a duplicated > fashion, since the test for __len__() will always exist as well. i was actually more impressed with the union/intersection of lists and dictionaries. why the hell cant you join two dictionaries like you can two list? the len thing is a pretty minor issue in my mind. > So while I think they may have been reasonable requests, Im not sure > theyre really pitfalls, and Im not sure they would even work out that > well on a large scale which is why I wanted to implement it and test > it out myself. i guess my request was a little vague. im actually more interested in missing funtionality of the python language, as opposed to pitfalls, warts, minor syntax issues. to put it another way, why should anyone want to use a general language other than python (ignoring speed and not including languages designed for a specific/limited domain)? what types of things are just plain easier to achieve in smalltalk, perl, icon, lisp, ruby, etc? there must be plenty of ideas that people have had, but havent bothered to write a PEP for or couldnt even begin to find a way to integrate them into python. From rbthomas55 at pobox.com Tue Aug 12 17:31:51 2003 From: rbthomas55 at pobox.com (Rick Thomas) Date: Tue, 12 Aug 2003 21:31:51 GMT Subject: Python IDE - "Lite" version available for non commercial use Message-ID: <3F395CC7.EFBE63C6@pobox.com> http://wingide.com/wingide From timfm at hawaii.rr.com Fri Aug 1 06:09:44 2003 From: timfm at hawaii.rr.com (Timothy Martens) Date: Fri, 01 Aug 2003 00:09:44 -1000 Subject: 2.3 win installer Message-ID: <3F2A3C68.3050104@hawaii.rr.com> Anyone having problems with the 2.3 win installer? I'm running win2k pro (sp4) and the installer is freezing after the initial dialogues, just as teh install starts. From Stephen.Boulet at no.spam.motorola.com Thu Aug 21 18:17:24 2003 From: Stephen.Boulet at no.spam.motorola.com (Stephen Boulet) Date: Thu, 21 Aug 2003 17:17:24 -0500 Subject: Embedding a chart in excel Message-ID: I'm having trouble scripting Excel to embed a chart from python. Say I have created a sheet object and a workbook object, "xlSheet" and "xlBook". Creating a chart in front of my sheet is as easy as: xlSheet.Select() xlChart = xlBook.Charts.Add() Now how do I tell it to go embed itself in my sheet? In VBA, it might be something like: xlChart.Location Where:=xlLocationAsObject, Name:=xlSheet.Name Thanks. (Is there a newsgroup/list with more of a focus on issues like this than c.l.py?) -- Stephen From jepler at unpythonic.net Thu Aug 7 21:55:15 2003 From: jepler at unpythonic.net (Jeff Epler) Date: Thu, 7 Aug 2003 20:55:15 -0500 Subject: spawnv( ) or spawnl( ) do not launch a normal running process in Python 2.2.2? In-Reply-To: References: Message-ID: <20030808015515.GC955@unpythonic.net> On Thu, Aug 07, 2003 at 03:39:34PM -0700, nushin wrote: > Thanks Jeff. Yes, i think it's the stdio buffering that causes > P_NOWAIT act asif it's a P_WAIT. I wish an additional parameter could > be added to spawnv( ) to toggle its stdout on/off. I'm not sure what you're asking for. An earlier message I sent to you used dup2 + spwanv to redirect a child's standard input, output, and error. Using /dev/null here should be a way to turn the child's stdout off. You can even beef it up a little bit by flushing the main program's standard files before spawning, and letting an argument of 'None' open /dev/null Of course, all this is still untested... F_devnull = None def F(x): """Return the file number corresponding to the given object F(x) -> fd corresponding to /dev/null if x is None F(x) -> x if isinstance(x, int) F(x) -> x.fileno() otherwise """ if f is None: global F_devnull if F_devnull is None: F_devnull = os.open("/dev/null", os.O_RDWR) return F_devnull if not isinstance(x, int): return x.fileno() def dup2_noerror(a, b): "a dup2 that suppresses all errors. For use in cleanup" try: os.dup2(a, b) except: pass def coroutine_spawnv(flags, args, child_stdin, child_stdout, child_stderr): "Call spawnv with a different set of files for stdin/stdio/stderr" sys.stdout.flush(); sys.stderr.flush() old_stdin = os.dup(0) old_stdout = os.dup(1) old_stderr = os.dup(2) try: os.dup2(F(child_stdin), 0) os.dup2(F(child_stdout), 1) os.dup2(F(child_stderr), 2) return os.spawnv(flags, args[0], args) finally: dup2_noerror(old_stdin, 0) dup2_noerror(old_stdout, 1) dup2_noerror(old_stderr, 2) > > Regards, > Nushin > > Jeff Epler wrote in message news:... > > I don't see any problem with P_NOWAIT. Take the following for example: > > > > $ cat nushin.py > > import os > > > > p = os.spawnvp(os.P_NOWAIT, 'sh', > > ['sh', '-c', 'sleep 1; echo from spawnv']) > > print "from program" > > print "waitpid returns:", os.waitpid(p, 0) > > $ python -u nushin.py > > from program > > waitpid returns:from spawnv > > (2826, 0) > > > > Now, if the program completed very quickly, it's a coin-flip whether its > > output would appear before "from program". In this case, I made sure > > the program would take a really long time (1 second) to complete. > > > > When running without -u but not on a terminal, you might see > > $ python nushin.py | cat > > from spawnv > > from program > > waitpid returns: (2832, 0) > > .. this is because the Python process has printed "from program", but > > stdio buffering has kept it from actually being written to the output > > yet. > > > > Here's what you see on a terminal without -u: > > $ python nushin.py > > from program > > from spawnv > > waitpid returns: (2835, 0) > > This is the same thing you'd see if the program said > > print "from program"; sys.stdout.flush() > > > > Jeff > -- > http://mail.python.org/mailman/listinfo/python-list > From bhv1 at psu.edu Sun Aug 3 08:30:48 2003 From: bhv1 at psu.edu (Brian Victor) Date: Sun, 03 Aug 2003 12:30:48 GMT Subject: Can't get dumb webcounter working References: Message-ID: J. W. McCall wrote: > As far as the correct HTML code...sorry if this is a dumb question, but > what exactly would that HTML code be? I saw something about "" but that didn't seem to work. I've never called > a script from an HTML document. I guess that's what I'm trying to > figure out. You're close, but you're missing a few characters: http://httpd.apache.org/docs-2.0/mod/mod_include.html#element.exec Or similarly the "include virtual" alternative mentioned at the link above. -- Brian From cnetzer at sonic.net Sat Aug 30 16:30:15 2003 From: cnetzer at sonic.net (Chad Netzer) Date: Sat, 30 Aug 2003 13:30:15 -0700 Subject: OT: Americans love their guns In-Reply-To: References: Message-ID: <1062275414.1875.35.camel@adsl-209.204.179.133.sonic.net> On Fri, 2003-08-29 at 10:51, maxx at easynews.com wrote: > On Thu, 28 Aug 2003 19:46:57 GMT, maxx at easynews.com wrote: > > >And my probability of being one of them is pretty low - because I am usually > >armed ;) > > Lots of replies. Rather than create a large list of individual responses, I will > summarize in this one post. Don't have any responses (well, I do, but this is all far afield...) I just wanted to point out that this was quite a civil discussion about what can be a highly charged issue. Just wanted to thank everyone involved for their cool heads. -- Chad Netzer From sross at connectmail.carleton.ca Sat Aug 30 11:21:28 2003 From: sross at connectmail.carleton.ca (Sean Ross) Date: Sat, 30 Aug 2003 11:21:28 -0400 Subject: My script is taking 12 hours+ any suggestions? References: <3f4ff9f8$0$23588$5a62ac22@freenews.iinet.net.au> <0uW3b.4392$_F1.665478@news20.bellglobal.com> Message-ID: "Sean Ross" wrote in message news:0uW3b.4392$_F1.665478 at news20.bellglobal.com... [re: dictionary record of shared normals] > > But, this takes up more space than the jagged list version. And the look-up > is slower. Actually, that's wrong. Because of the way I built the dictionary SHARED = {0: [0,1,3], # v0 shares normals with itself, v1 and v3 1: [0,1,3], 2: [2] 3: [0,1,3]} is actually more like this SHARED = {0: , 1: , 3: , 2: } where is [0,1,3] and is [2] So, we're only using space for two lists, not four (plus space for the dictionary, it's keys, yada, yada). As an added benefit, the look-up for shared normals is quick and easy as well: # v0.share_normal(v3) SHARED[0] is SHARED[3] where we only have to check the identity of the lists being referenced. Another benefit of this is, if you add a new vert to the dictionary after you've processed the file, if the new vert shares normals with any of the verts in the dictionary, you just add it to the list of the first one that you come across, and all of the other verts that this new vert would share normals with will also have that new verts index in their share list. Not bad. So, it looks to me like this may be the best of the three methods I've presented: It calls share_normal() at most as many times as the jagged list method (and probably far fewer times). It updates easily and the effects are distributed. And the subsequent share normal checks by identity are quick and efficient. But, hey, I could be wrong. For one thing, I don't even know if you need to do this type of thing... OK, then. Have fun, Sean From usenet_spam at janc.invalid Sun Aug 3 00:58:48 2003 From: usenet_spam at janc.invalid (JanC) Date: Sun, 03 Aug 2003 04:58:48 GMT Subject: Secure FTP in Python? References: Message-ID: "d z e k y l" schreef: > I'd like to write a small backup utility in Python, which would take > advantage of Secure FTP to upload backup archives. Is there a library > implementing SFTP in Python (something like ftplib)? Or is there some > other (noncomplicated) way how secure uploading can be implemented in > Python? You can do that using pycurl. -- JanC "Be strict when sending and tolerant when receiving." RFC 1958 - Architectural Principles of the Internet - section 3.9 From logiplex at qwest.net Tue Aug 5 15:40:20 2003 From: logiplex at qwest.net (Cliff Wells) Date: Tue, 05 Aug 2003 12:40:20 -0700 Subject: site-packages and linux In-Reply-To: <55939F05720D954E9602518B77F6127F03096E83@FTWMLVEM01.e2k.ad.ge.com> References: <55939F05720D954E9602518B77F6127F03096E83@FTWMLVEM01.e2k.ad.ge.com> Message-ID: <1060112419.13056.8.camel@software1.logiplex.internal> On Tue, 2003-08-05 at 11:45, Raaijmakers, Vincent (IndSys, GE Interlogix) wrote: > Currently in my linux configuration there seems to be a conflict in my python2.2 and 2.3 install. > I installed recently 2.3 but want to go back for some reason to 2.2. > All installed packages located in ...\python2.2\site-packages are not recognized anymore. > Well, when importing is not possible, no module found error is what I get now. > > Without re-installing everything, how can I solve this problem? The problem most likely is that when you run 'python' it's running 2.3. If you still have a python 2.2 binary around (possibly 'python2.2'?) it should pick up the old site-packages. Regards, -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 (800) 735-0555 From bokr at oz.net Mon Aug 11 22:41:19 2003 From: bokr at oz.net (Bengt Richter) Date: 12 Aug 2003 02:41:19 GMT Subject: Fun with numbers - dammit, but I want a cast! References: <3f378fac$0$10778$afc38c87@auth.uk.news.easynet.net> <3f3792f2$0$18258$afc38c87@auth.uk.news.easynet.net> <3F38367F.9EF03CEE@alcyone.com> <3F38439C.5FC57375@alcyone.com> Message-ID: On Mon, 11 Aug 2003 18:32:12 -0700, Erik Max Francis wrote: >Carl Banks wrote: > >> It seems you didn't read what I wrote carefully. I was talking about >> C, not C++. Neither I nor the post I replied to mentioned C++ once. >> I mentioned the C standard several times, never the C++ standard. >> >> Type casts in C are as I described. > >C++ was mentioned by the original poster; either way, C and C++ casts >act precisely the same in this context. (float) 1 and *(float *) &i >have precisely the same meanings both in C and C++. > With (float) 1 it can optimize to one instruction with immediate operand constant. With the other it needs (at least on x86) to move via EAX, for two instructions (e.g., assigning the resp values). Where x&y are extern floats, to make sure unused vars don't get optimized away: ; 3 : int i = 1; 00004 c7 45 fc 01 00 00 00 mov DWORD PTR _i$[ebp], 1 ; 4 : x = (float) 1; 0000b c7 05 00 00 00 00 00 00 80 3f mov DWORD PTR _x, 1065353216 ; 3f800000H ; 5 : y = *(float *) &i; 00015 8b 45 fc mov eax, DWORD PTR _i$[ebp] 00018 a3 00 00 00 00 mov DWORD PTR _y, eax I agree the bits are just being moved in either case for assignment. But then if you multiply by 5.0, the compiler will fold one constant expression, but not the other (even with max optimizimg and declaring const stuff not shown here) ; 3 : int i = 1; 00004 c7 45 fc 01 00 00 00 mov DWORD PTR _i$[ebp], 1 ; 4 : x = 5.0*((float) 1); 0000b c7 05 00 00 00 00 00 00 a0 40 mov DWORD PTR _x, 1084227584 ; 40a00000H ; 5 : y = 5.0*(*(float *) &i); 00015 d9 45 fc fld DWORD PTR _i$[ebp] 00018 dc 0d 00 00 00 00 fmul QWORD PTR __real at 8@4001a000000000000000 0001e d9 1d 00 00 00 00 fstp DWORD PTR _y So what a source spelling "really means" depends on what aspect you are concentrating, I think you might agree? Sometimes the context does not result in code that will "act precisely the same." Depending ;-) Regards, Bengt Richter From mwh at python.net Fri Aug 1 07:29:11 2003 From: mwh at python.net (Michael Hudson) Date: Fri, 1 Aug 2003 11:29:11 GMT Subject: Wow: list of immediate subclasses? References: <7h3k79xaavf.fsf@pc150.maths.bris.ac.uk> Message-ID: <7h3fzklaa75.fsf@pc150.maths.bris.ac.uk> Michael Hudson writes: > "Andrew Dalke" writes: > > > Carl Banks, responding to Roman Suzi: > > > __subclasses__ is a list of weak references, so the class can be > > > collected even though it's listed in __subclasses__. For whatever > > > reason, class A isn't deleted by reference counts, but cyclic garbage > > > collection gets it. > > > > But I want to know that reason. Why are there any cycles? [...] > > I don't know where the cycle is, off-hand. I suspect I did once... Found it (them): >>> class A(object): pass ... >>> A.__dict__['__weakref__'].__objclass__ is A True praise-be-to-neils-ly y'rs mwh -- I never disputed the Perl hacking skill of the Slashdot creators. My objections are to the editors' taste, the site's ugly visual design, and the Slashdot community's raging stupidity. -- http://www.cs.washington.edu/homes/klee/misc/slashdot.html#faq From jepler at unpythonic.net Sun Aug 3 11:49:23 2003 From: jepler at unpythonic.net (Jeff Epler) Date: Sun, 3 Aug 2003 10:49:23 -0500 Subject: HOME Directory in posix and nt In-Reply-To: References: Message-ID: <20030803154918.GA7105@unpythonic.net> os.environ holds the system environment, so home = os.environ['HOME'] on unix, and home = os.environ['HOMEPATH'] on windows might be what you want. You could also try home = os.path.expanduser("~") which looks at HOME and pwd.getpwuid on unix, and at HOME, HOMEPATH, and HOMEDRIVE on NT. Jeff From syver-en+usenet at online.no Wed Aug 6 16:17:06 2003 From: syver-en+usenet at online.no (Syver Enstad) Date: 06 Aug 2003 22:17:06 +0200 Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> Message-ID: aahz at pythoncraft.com (Aahz) writes: > (Yes, there are issues with Python on SMP machines, but to call > Python's built-in threading "non-existent SMP scalability" is either > a lie or revelatory of near-complete ignorance. That doesn't even > count the various IPC mechanisms.) It's an interesting subject though. How does python threading on SMP machines compare with f.ex. Java and C++. I know that at least the MSVC compiler has a GIL like problem with heap access (new, malloc, delete, free), which is guarded with a global lock. Would migrating the global data for a thread to some sort of thread local storage help Python SMP performance? If Java has better threading performance than Python how have they solved the interpreter state problem. Java is interpreted isn't it? -- Vennlig hilsen Syver Enstad From max at alcyone.com Tue Aug 26 22:48:24 2003 From: max at alcyone.com (Erik Max Francis) Date: Tue, 26 Aug 2003 19:48:24 -0700 Subject: String find and replace References: <3F4C04F8.5070401@vt.edu> <3F4C1046.1030704@hotmail.com> Message-ID: <3F4C1BF8.6A19CA06@alcyone.com> hokiegal99 wrote: > I hate to answer my own post, but I think I understand what I'm doing > wrong. I'm finding and replacing 'this' with 'that' in the varible > named > mystr, not the actual files. So, how would I go about making the > change > to the actual files instead of a variable that contains their content? Easy: inputFile = file(filename, 'r') data = inputFile.read() inputFile.close() data = data.replace(this, that) outputFile = file(filename, 'w') outputFile.write(data) outputFile.close() -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ There never was a good war or a bad peace. \__/ Benjamin Franklin From mertz at gnosis.cx Thu Aug 28 02:20:21 2003 From: mertz at gnosis.cx (Lulu of the Lotus-Eaters) Date: Thu, 28 Aug 2003 02:20:21 -0400 Subject: Celebrity advice References: Message-ID: |Eric Raymeond at http://armedndangerous.blogspot.com/ |""There are some books so bad, but so plausible and influential, that |periodically trashing them in public is almost an obligation. The really |classic stinkeroos of this kind, like Karl Marx's Das Kapital |Lulu can correct me if I am wrong, but links from Lulu's site has led |me to understand him to be an avowed "otherwise intelligent person". I make no such avowal. I just post missives from the land of the lotus-eaters. And I sometimes find my ideas in everyones' heads[*] That said, I'm probably one of fairly few list contributors who owns the complete standard edition of Marx and Engels' writings (except an unfortunate gap at 1857, and in some of the letters)... and who has read a substantial chunk of it.[**] I imagine ESR has not so read. |advice to a new programmer to eschew Raymond... I would certainly never urge anyone to eschew reading ESRs essays. I would urge them to find the essays a little bit silly--this applies as much, actually, to the "Homesteading" and "Cathedral" essays as to the gun-nut stuff. But then, Raymond is a bit of an amateur in the areas I studied as a profession (political philosophy, economics, sociology, etc). I'd certainly give him high marks in one of my erstwhile classes. Nonetheless, I sure wouldn't want his job as "Official ideologue of Open Source"... it's way too much work. And he writes mostly true things, even if for the wrong reasons. Yours, Lulu... [*] Who the heck put the 'post' in post-Situ?! OK, I protest too much, since I know it was a delightful writer named Hakim Bey, whom I saw speak a couple weeks back (after reading his books some years earlier). [**] Although I confess I never quite made it through Volume Three, I know some certain persons who have.... and discovered that my own little village (literally) in Western Massachusetts, called Turners Falls (after a local mass murderer of the prior locals), appeared by name in a nice turn of phrase about cutlery. -- _/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY: Postmodern Enterprises _/_/_/ _/_/ ~~~~~~~~~~~~~~~~~~~~[mertz at gnosis.cx]~~~~~~~~~~~~~~~~~~~~~ _/_/ _/_/ The opinions expressed here must be those of my employer... _/_/ _/_/_/_/_/_/_/_/_/_/ Surely you don't think that *I* believe them! _/_/ From elainejackson7355 at home.com Mon Aug 18 12:50:10 2003 From: elainejackson7355 at home.com (Elaine Jackson) Date: Mon, 18 Aug 2003 16:50:10 GMT Subject: bitwise not - not what I expected References: Message-ID: <6t70b.797745$Vi5.17799551@news1.calgary.shaw.ca> Cool. Thanks a bunch. I find the documentation about 'enumerate' a little sketchy, but it seems like, as a first approximation, I can think of enumerate(piles) as the list of all pairs [ i, piles[i] ] with 0 <= i < len(piles). Is that right? "Tim Peters" wrote in message news:mailman.1061169151.30094.python-list at python.org... | [Elaine Jackson] | > In case any fellow newbies have been following this thread, here is | > the finished Nim script. It doesn't use bit-manipulation as much as I | > thought it would. (Still, I got the basics straight. Thanks again to | > everyone who helped out!) For a readable account of the optimal | > strategy for Nim, see Hardy & Wright's "Introduction to the Theory of | > Numbers". Peace. | > | > ## NIM | > from random import random | > piles=[0,0,0] | > | > ... | > | > def yourMove(): | > magicNum=piles[0]^piles[1]^piles[2] | > if magicNum==0: | > i=indexOfMax() | > piles[i]=piles[i]-1 | > else: | > magicIndex=leftmostBitIndex(magicNum) | > targetIndex=(-1) | > for i in range(3): | > if (piles[i]>>magicIndex)%2==1: | > targetNum=piles[i] | > targetIndex=i | > break | > replacement=0 | > for i in range(magicIndex): | > magicDigit=(magicNum>>i)%2 | > targetDigit=(piles[targetIndex]>>i)%2 | > if magicDigit==1: | > replacementDigit=(magicDigit-targetDigit) | > else: | > replacementDigit=targetDigit | > replacement=replacement+replacementDigit*pow(2,i) | > newNum=targetNum-(targetNum%pow(2,magicIndex+1))+replacement | > piles[targetIndex]=newNum | > print piles | | OK, what you're trying to do is force the xor of the pile counts to 0. | There may be more than one way to do that. For example, if piles is | | [2, 6, 7] | | you can force a win by doing any of these: | | remove 1 from the 2 pile, leaving [1, 6, 7] | remove 1 from the 6 pile, leaving [2, 5, 7] | remove 3 from the 7 pile, leaving [2, 6, 4] | | because 1^6^7 == 2^5^7 == 2^6^4 == 0. Now the educational thing is | that it's possible to find all these solutions easily *without* picking | apart any bits: | | def myMove(piles): | all = 0 | for count in piles: | all ^= count | for i, count in enumerate(piles): # enumerate() new in 2.3 | all_without_count = all ^ count | if all_without_count < count: | print "leave %d in pile #%d" % (all_without_count, i) | | For example, | | >>> myMove([2, 6, 7]) | leave 1 in pile #0 | leave 5 in pile #1 | leave 4 in pile #2 | >>> | | Note that the function works for any number of piles, and doesn't care how | big each pile may be; for example, | | >>> myMove([2**50, 3**67, 5**12, 76**30]) | leave 92709463147897838211662074651978 in pile #3 | >>> 2**50 ^ 3**67 ^ 5**12 ^ 92709463147897838211662074651978 | 0L | >>> | | I think you'll enjoy figuring out why that function works; proving that it | finds all solutions is a bit delicate, but not truly hard. | | From BrenBarn at aol.com Sun Aug 17 01:28:17 2003 From: BrenBarn at aol.com (OKB (not okblacke)) Date: 17 Aug 2003 05:28:17 GMT Subject: bitwise not - not what I expected References: <1YD%a.747879$3C2.17342633@news3.calgary.shaw.ca> Message-ID: Elaine Jackson wrote: > Is there a function that takes a number with binary numeral a1...an > to the number with binary numeral b1...bn, where each bi is 1 if ai > is 0, and vice versa? (For example, the function's value at 18 > [binary 10010] would be 13 [binary 01101].) I thought this was what > the tilde operator (~) did, but when I went to try it I found out > that wasn't the case. I discovered by experiment (and verified by > looking at the documentation) that the tilde operator takes n to > -(n+1). I can't imagine what that has to do with binary numerals. > Can anyone shed some light on that? (In case you're curious, I'm > writing a script that will play Nim, just as a way of familiarizing > myself with bitwise operators. Good thing, too: I thought I > understood them, but apparently I don't.) > I think this is because it's also inverting the leading zero bits. That is, 18 isn't really 10010, it's 000...0010010 with a bunch of 0s at the front. (I'm not sure, but I think the number of bits in the integer type can change with different implementations.) So when you bitwise-not it, you get 111...1101101, which is interpreted as -19. -- --OKB (not okblacke) "Do not follow where the path may lead. Go, instead, where there is no path, and leave a trail." --author unknown From news at exultants.org Thu Aug 28 12:02:39 2003 From: news at exultants.org (Van Gale) Date: Thu, 28 Aug 2003 16:02:39 GMT Subject: Zope from Interwoven References: <3cf2990f.0308280620.3dec0c39@posting.google.com> Message-ID: On Thu, 28 Aug 2003 07:20:47 -0700, mxlplx wrote: > I'm currently working on a project to convert an Interwoven-based site > to use Zope instead. Has anyone attempted this before and if so, were > you able to do it with Zope? Could you use the XML files produced by > Interwoven? Any ideas would be appreciated. I can't think of a single thing the 2 systems have in common really, so it won't be an easy task. The conversion to Zope should mostly be possible, and is probably worth it considering the cost of the conversion will probably be less than licensing costs... but you'll have to develop custom tools to convert any data that can be converted and the rest will have to be developed from scratch. Some bits, such as workflow XML/perl templates probably cannot be converted at all and you'll need to redesign workflows in the Zope way. If your pages are ASP or PHP you'll have to convert them to Zope's DTML or TAL. If you use metadata you'll need to design objects with attributes to match. The XML from Teamsite templates would also be replaced by python objects, which means processing the teamsite XML to create a new object, merging the metadata, and then getting that object into Zope's object storage. You might get a better answer on the Zope mailing list, but I bet it'll be the same general "Ugh!" :) Van From oktaysafak at ixir.com Fri Aug 1 19:01:23 2003 From: oktaysafak at ixir.com (Oktay Safak) Date: 1 Aug 2003 16:01:23 -0700 Subject: a question on the new dict() keyword argument syntax Message-ID: <722261f9.0308011501.48263391@posting.google.com> Hi, Is there an equivalent keyword argument syntax for these cases: d1 = {1:"one"} d2 = {"1":"one"} these don't work, of course: >>> a = dict(1 = "one") SyntaxError: keyword can't be an expression >>> a = dict("1" = "one") SyntaxError: keyword can't be an expression Just curious... From raims at dot.com Fri Aug 22 04:38:23 2003 From: raims at dot.com (Lawrence Oluyede) Date: Fri, 22 Aug 2003 10:38:23 +0200 Subject: Do Java lovers are scared about the Python crowed? Message-ID: http://www.cardboard.nu/archives/000118.html I think that the guy (Alan Green) is very scared :) I read also a funny (but clever) comment to that post (the first one): " True, True. In fact, we should boycott Java, too. C is the way to go! (Or Assembler? Or just write the binary code by hand?) " -- Lawrence "Rhymes" Oluyede http://loluyede.blogspot.com rhymes at NOSPAMmyself.com From pythonguy at Hotpop.com Wed Aug 20 06:42:35 2003 From: pythonguy at Hotpop.com (Anand Pillai) Date: 20 Aug 2003 03:42:35 -0700 Subject: ClientCookie bug (followup) References: <87fzk4sav2.fsf@pobox.com> <87znibzrnx.fsf@pobox.com> <87oeypdh92.fsf@pobox.com> <87k79a25pi.fsf@pobox.com> <84fc4588.0308182207.4c649b93@posting.google.com> <87ada5de3j.fsf@pobox.com> Message-ID: <84fc4588.0308200242.3e74e0a1@posting.google.com> Hi John I wanted to add cookies support to harvestman, your module looked ideal for it. 'We', nothing royal about it. It is just me and my friend & co-developer Nirmal Chidambaram. Apparently he has found a way around some of the bugs in Clientcookie. He has written a new module using the existing Cookie module of python & urllib2. One of the problems 'we' had with Clientcookie is that it uses its own 'urlopen' methods which does not fit our applications needs, so 'we' had to find a way around it. Once the code is ready, I will post it on my webpage, and of course it is not a module in itself, so I think an announcement to c.l.py is out of place. Regards -Anand jjl at pobox.com (John J. Lee) wrote in message news:<87ada5de3j.fsf at pobox.com>... > pythonguy at Hotpop.com (Anand Pillai) writes: > > > I am working on a Cookie module which works *with* urllib2 rather > > than on top of it like the existing ClientCookie module. It uses > > the Cookie module which comes with python standard library. > > Interesting, though I don't know quite what you mean. > > First, if there's a way to work more closely with urllib2 than I've > figured out (which is quite possible), this patch needs to know about > it, so please post a comment: > > http://www.python.org/sf/759792 > > If I understand what you mean, ClientCookie only works 'on top of' > rather than 'with' urllib2 to the extent that it currently has to > cut-n-paste code to add cookie handling to urllib2. That patch is > designed to remove the need to cut-n-paste, which would mean you'd do > urllib2.urlopen (after building an OpenerDirector that has an > HTTPCookieProcessor from ClientCookie) instead of ClientCookie.urlopen > as is required at present. > > Seco nd: is your module intended to do what ClientCookie does > (ie. figure out what cookies should be set and returned, and do so), > or is it just a more OO way of getting and returning Cookie headers? > I guess the latter? > > > > This module is written as an extension of my Harvestman webcrawler. > > The alpha code is ready. We are doing testing right now. > > Is this the Royal We? ;-) > > > > Details will be posted to my website at > > http://members.lycos.co.uk/anandpillai within say 2 weeks or so. > [...] > > Please do post an announcement to c.l.py.announce, or I'll forget. > > > John From jordan at krushen.com Mon Aug 25 16:11:35 2003 From: jordan at krushen.com (Jordan Krushen) Date: Mon, 25 Aug 2003 20:11:35 GMT Subject: python gripes survey References: <78kkkvg8ckfio141es2of1p483ohbtbit5@4ax.com> <3rokkvckckdj6b679164jdnvqlbcfic67j@4ax.com> Message-ID: On Mon, 25 Aug 2003 19:45:10 GMT, Afanasiy wrote: > Yes, returning multiple values, ie. tuples, is useful, but using them as > you would use structs in C is common and the root of my gripe. The > problem > I explained above has nothing to do with the code you write. The problem > is knowing what integer position in the tuple represents what field. In C > structs have named fields, but in Python tuple have integer fields. The > meaning of tuple integer fields, for tuples used this way, is only known > in the documentation, not the code directly. I agree here. Returning tuples is only useful when very few arguments are being returned. I must admit, I haven't seen many cases where they're used as [larger] C structs are -- in most of those cases, some kind of methodless container object is usually returned. For trivial cases, it's much less work for the developer to simply return a tuple than to create a class just for the result. Therein lies much of the problem, I believe. Developers tend to code to whatever method makes life easier for them. This is fine for closed application development, but developers working on libraries often forget that a little extra work up front will save time for many other coders as they continue to use the library. > Often this is not even done in C, because a struct is used instead. Indeed. In Python, I prefer to simply toss a methodless object back, instead. Obviously, this incurs some overhead though (both finger-and run- time). I wonder if occurences of tuples being returned in the standard library are there for performance reasons (select.select, etc). > I thought this thread was for gripes, not detailed explanations and > solutions. However, for a solution... Perhaps people should use dicts in > the libraries more often than near-mystery tuples. It's much more > explicit that way. I'm just trying to determine where you have most of an issue with this -- in the standard library, in other libraries, or what is being recommended as Pythonic. If it's an inconsistency/readability issue in the standard library, we can fix it! Isn't that the point of this thread? Simply detailing gripes without any attempt to fix them is quite unproductive, IMO. If the complaint is more specifically what you deem or perceive others to deem as Pythonic, then I can't say I have seen many cases of mystery-tuples being returned, except for the low-layer library wrappers (win32all comes to mind), but those seem to often be written as shims, with the expectation that another, more OO and developer-friendly API will be exposed afterward. I can't say I've seen many cases where people *recommend* returning tuples, as readability does tend to suffer. > When I have to re-explain and re-gurgitate something like this for > benefit of one confused person I leave myself open to more confused > attacks, and I don't like that. So if that happens this time, I > will make sure not to elaborate so much next time, and will reply > abruptly instead. I'm neither confused or attacking. This is a concern of mine that lines up with your own, but I'm looking at a potential fix for the problem, and trying to clarify where you perceive the issue to exist. J. From Olivier.POYEN at clf-dexia.com Tue Aug 12 05:02:09 2003 From: Olivier.POYEN at clf-dexia.com (POYEN OP Olivier (DCL)) Date: Tue, 12 Aug 2003 11:02:09 +0200 Subject: ANNOUNCE: Rekall V2.0.2 Message-ID: <8963D6370B323E4AA3241200F0EAF7318C103A@FCEXVEXM002.dcl.int.dexwired.net> > -----Message d'origine----- > De : Max M [mailto:maxm at mxm.dk] > Envoy? : mardi 12 ao?t 2003 10:37 > ? : python-list at python.org > Objet : Re: ANNOUNCE: Rekall V2.0.2 > > > Benoit Caron wrote: > > > > The goal being to build an application that make somebody > able to build > > a small database-using application with no fuss, with the option of > > building "semi-automatically" a web interface to it's database. > > > > So, anybody think this would have users? > > Sure. But I think it's one of the point from the gnuE (gnu Enterprise) which use python as a scripting langage. You have designer & forms tools. Maybe a little big, but worth a look. (www.gnuenterprise.org) ---OPQ -------------- next part -------------- ----------------------------------------------------------------- Ce message est confidentiel ; son contenu ne represente en aucun cas un engagement de la part de Dexia Credit Local ou de Dexia CLF Banque. Toute publication, utilisation ou diffusion, meme partielle, doit etre autorisee prealablement par l'emetteur. Si vous n'etes pas destinataire de ce message, merci d'en avertir immediatement l'expediteur. This message is confidential ; its contents do not constitute a commitment by Dexia Credit Local or Dexia CLF Banque. Any unauthorised disclosure, use or dissemination, either whole or partial, is prohibited. If you are not the intended recipient of the message, please notify the sender immediately. ----------------------------------------------------------------- Consultez notre site internet www.dexia-clf.fr La cle d'une gestion optimisee du secteur public local ----------------------------------------------------------------- From davidcfox at post.harvard.edu Thu Aug 21 16:02:48 2003 From: davidcfox at post.harvard.edu (David C. Fox) Date: Thu, 21 Aug 2003 20:02:48 GMT Subject: tuple to string/list In-Reply-To: <538fc8e.0308211141.4bca8a8d@posting.google.com> References: <538fc8e.0308211141.4bca8a8d@posting.google.com> Message-ID: WIWA wrote: > Hi, > > I'm a newbie learning to appreciate the strength of Python. I'm > writing an application to look at the access_log of my apache server: > > When I write: > > for i in range(len(month)): > output="Hits for",month[i], ":" , teller[i] > f.write(str(output)) > f.close() > > => this produces a tuple: > ('Hits for', 'Jan', ':', 0)('Hits for', 'Feb', ':', 2)('Hits for', > 'Mar', ':', 3) > > => whereas I would like the following output: > Hits for Jan: 0 > Hits for Feb: 2 > Hits for Mar: 3 > > Any easy way of obtaing this output? output = "Hits for %s: %d\n" % (month[i], teller[i]) or output = "Hits for " + month[i] + ": " + str(teller[i]) + "\n" and then f.write(output) See 7.1 in the Tutorial David From db3l at fitlinxx.com Wed Aug 20 17:23:48 2003 From: db3l at fitlinxx.com (David Bolen) Date: 20 Aug 2003 17:23:48 -0400 Subject: Python Debugger References: <6ee58e07.0308181134.383a69e7@posting.google.com> Message-ID: llothar at web.de (Lothar Scholz) writes: > Is there any python debugger that can > > 1) be used remotely > 2) can handle multiple threads > > I checked Eric, IDLE and Wing-IDE. None of them can do this. > Any other recommendations? Well, Wing-IDE can definitely do 1. Just import wingdbstub in your remote application and it will connect back to the debugger whereever else it may be - IP communications path required. Works even if the application being debugged is internal to something else (a web app, or just a library for some other system, etc...) (2) is going to be tough currently because of some limitations of the internals of the Python debugger support. I'm not up on all the specifics but the debugger isn't told about thread changes and there is some state information that is not maintained on a per-thread basis. There was some talk about enhancing this in the 2.3 timeframe, but I don't think it made it in. However, with Wing at least, it has partial thread support in that while it can't monitor multiple threads, by controlling which thread imports wingdbstub you can set the single thread being monitored and has full debugging support. So it's not as good as arbitrary thread support, but in many cases is much better than no thread support at all, and it's probably about as good a debugger support as you'll see for Python at the moment. -- David From gh at ghaering.de Wed Aug 6 19:42:51 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Thu, 07 Aug 2003 01:42:51 +0200 Subject: MSVC 6.0 Unsupported? In-Reply-To: References: <3F302764.8010301@ghaering.de> Message-ID: <3F31927B.8040506@ghaering.de> Syver Enstad wrote: > Gerhard H?ring writes: >>Syver Enstad wrote: >>>"M.-A. Lemburg" writes: >>> >>> >>>>The best thing to do is to replace this code in Python's object.h >>>>file (Python23\Include\object.h; note the comment !): >>> >>>That's exactly what I did and it worked fine. >> >>Requiring users of my software to patch their Python instalation is >>not an option for me. > > But Gerhard, what can I do? Every python extension that I will try to > compile will fail if it depends on a working staticforward. The most > rational thing to me is to patch object.h instead of patching every > .cpp/.c file that needs this define. Yeah sure. That's the best option for *you* if you want existing (noncompatible) Python extensions :) I was playing the side of an author of Open Source Software that should be buildable with Python 2.3 and MSVC6. That's where my different view on this issue comes from :-) -- Gerhard From bignose-hates-spam at and-benfinney-does-too.id.au Wed Aug 13 01:15:58 2003 From: bignose-hates-spam at and-benfinney-does-too.id.au (Ben Finney) Date: 13 Aug 2003 15:05:58 +0950 Subject: Python should try to displace Java References: Message-ID: On Wed, 13 Aug 2003 01:05:37 -0400, Christopher Blunck wrote: > Best of luck Brandon - good post!!! :) Seconded. Though others argue the motivation behind Brandon making the post, I found it to be quite thought-provoking and worth discussing on its merits. (As it happens, I didn't, because others already have done better in this thread.) -- \ "The man who is denied the opportunity of taking decisions of | `\ importance begins to regard as important the decisions he is | _o__) allowed to take." -- C. Northcote Parkinson | Ben Finney From none at none.net Sun Aug 31 17:04:45 2003 From: none at none.net (Iwan van der Kleyn) Date: Sun, 31 Aug 2003 23:04:45 +0200 Subject: Win32 documentation in CHM? In-Reply-To: References: Message-ID: <3f5262ea$0$1667$e4fe514c@dreader3.news.xs4all.nl> Tim Peters wrote: > The volunteers who have, and will, build the PythonLabs Windows installers > (Mark Hammond, me, and now Thomas Heller) unanimously agreed that including > a .chm file in the 2.3.1 PythonLabs Windows installer would be more useful > to more people than continuing to ship 8.4MB of HTML docs spread over 1,200+ > files. Great initiative. Are there any compiled CHM files available for 2.3, perhaps from other sources then PythonLabs? Regards, Iwan From cdstarrett at yahoo.com Mon Aug 4 23:24:46 2003 From: cdstarrett at yahoo.com (Charles Starrett) Date: 4 Aug 2003 20:24:46 -0700 Subject: Subject: MacPython-OS9 2.2.3 & Tkinter Message-ID: I am a just a dabbler in programming, but I'd like to make some simple cross-platform tools for generating webpages, as well as for text munging. One thing I need is a Mac OS 9/Windows GUI solution. I thought that Tkinter could provide this, but I'm having trouble getting the simple test script from Learning Python p.22 to work under Mac OS 9 (9.2.2, on a 400 MHz PowerBook firewire/2000, 192 MB ram). Starting with a clean install of MacPython 2.2.3, I run ConfigurePythonClassic, and then launch PythonInterpreter. This is how far I get: Python 2.2.3 (#139, Jun 1 2003, 21:54:44) [CW PPC GUSI2 THREADS GC] on mac Type "copyright", "credits" or "license" for more information. >>> from Tkinter import * >>> w = Button(text="Hello", command='exit') Then I get just a blinking cursor on the following line and nothing else happens. The OS hasn't frozen at that point, but the interpreter doesn't return any prompt (neither >>> nor ...). I can't quit out of PythonInterpreter except to "force quit." The menus respond visually but produce no result. doesn't terminate the interpreter either. If I don't force it to quit, the interpreter eventually (after 5-10 minutes) "quits unexpectedly" on its own. ONCE I was able to work all the way through the script to w.mainloop() but neither the button ("Hello") nor the window widgets responded to mouse clicks, and again I had to force quit the interpreter. I've also tried increasing the memory Preferred Size for PythonInterpreter but that didn't appear to help. My question is, does Tkinter actually work on OS 9? Is there a problem with this test script, or do I need to look elsewhere for my cross-platform needs? (The only other solution I have found is PLT Scheme, which I like, but I'd like to give Python a try...) Thanks for any help... ~~Charles From gfyho at yahoo.com Wed Aug 13 08:47:08 2003 From: gfyho at yahoo.com (G. Feldman) Date: 13 Aug 2003 05:47:08 -0700 Subject: Using urrlib for https Message-ID: <55143354.0308130447.7e66e4b@posting.google.com> I'm running Python 2.2 on MSWin XP. I can successfully download an http page using urllib.urlopen. At first trying to download an https page failed, so I downloaded and installed the SSL socket kit at http://pypgsql.sourceforge.net/misc/python-ssl.html . This seems to work for getting me the headers (at least it no longer fails at the urlopen), but it now gives me AttributeError: addinfourl instance has no attribute 'readlines' Either I'm doing something dumb, or there's an inconsistency in that the object returned by urlopen isn't the same type for http and https. Thanks for any help, Gary From ark at gmx.net Sat Aug 23 17:04:21 2003 From: ark at gmx.net (Arne Koewing) Date: Sat, 23 Aug 2003 23:04:21 +0200 Subject: OT: Ocaml? References: <7xk795xde6.fsf_-_@ruckus.brouhaha.com> Message-ID: <87lltkuluy.fsf@gmx.net> Paul Rubin writes: > Anyone here use OCAML? How do you like it? Is it a language a > Pythonista can learn to love? From what little I've seen, it looks > interesting, but I haven't actually tried installing or using it yet. Yes and I think it's a great language, but it's a little bit harder to start learning it. (you must learn how to read the types). But you get a very 'save' language with a very efficient compiler. I use OCAML whenever I need to write something that needs to be fast (it replaced C++ for me) From gafStopSpamData at ziplink.stopallspam.net Thu Aug 28 14:24:18 2003 From: gafStopSpamData at ziplink.stopallspam.net (Gary Feldman) Date: Thu, 28 Aug 2003 18:24:18 GMT Subject: learning to program References: <3F4CED6E.D04D35D6@engcorp.com> <5bspkv87u1q0v9aupajrrkjuutuh3f5o44@4ax.com> <3F4CF363.CAF6A14E@engcorp.com> <6b2qkv4nf549o8clg3bagphd02f92dadub@4ax.com> <3F4D0AC2.EE79D7E4@engcorp.com> Message-ID: On Wed, 27 Aug 2003 15:47:14 -0400, Peter Hansen wrote: >Rich wrote: >> >> On Wed, 27 Aug 2003 14:07:31 -0400, Peter Hansen >> wrote: ... >> How long does it usually take to post on Google? > >In my experience, usually quite a few hours (maybe four or more?). My experience has been longer, often overnight. Gary From falted at inspiron.openlc.org Fri Aug 29 06:59:07 2003 From: falted at inspiron.openlc.org (Debian User) Date: Fri, 29 Aug 2003 10:59:07 +0000 (UTC) Subject: Hunting a memory leak Message-ID: Hi, I'm trying to discover a memory leak on a program of mine. I've taken several approaches, but the leak still resists to appear. First of all, I've tried to use the garbage collector to look for uncollectable objects. I've used the next: # at the beginning of code gc.enable() gc.set_debug(gc.DEBUG_LEAK) # at the end of code: print "\nGARBAGE:" gc.collect() print "\nGARBAGE OBJECTS:" for x in gc.garbage: s = str(x) print type(x),"\n ", s With that, I get no garbage objects. Then I've taken an approach that I've seen in python developers list contributed by Walter D?rwald, that basically consists in creating a debug version of python, create a unitest with the leaking code, and modify the unittest.py to extract the increment of total reference counting in that code (see http://aspn.activestate.com/ASPN/Mail/Message/python-dev/1770868). With that, I see that my reference count grows by one each time the test execute. But the problem is: is there some way to look at the object (or make a memory dump) that is leaking?. I've used valgrind (http://developer.kde.org/~sewardj/) to see if it could detect the leak. In fact, it detects a bunch of them, but I am afraid that they are not related with the leak I'm looking for. I am saying that because, when I loop over my leaky code, valgrind always report the same amount of leaky memory, independently of the number of iterations (while top is telling me that memory use is growing!). My code uses extension modules in C, so I am afraid this does not contribute to alleviate the problem. I think all the malloc are correctly freed, but I can't be sure (however, valgrind does not detect nothing wrong in the extension). I am sorry, but I cannot be more explicit about the code because it is quite complex (it is the PyTables package, http://pytables.sf.net), and I was unable to make a simple example to be published here. However, if anyone is tempted to have a look at the code, you can download it from (http://sourceforge.net/project/showfiles.php?group_id=63486). I am attaching a unittest that exposes the leak. I am a bit desperate. Any hint? Francesc Alted -- # Unittest to expose the memory leak import sys import unittest import os import tempfile from tables import * # Next imports are only necessary for this test suite #from tables import Group, Leaf, Table, Array verbose = 0 class WideTreeTestCase(unittest.TestCase): def test00_Leafs(self): import time maxchilds = 2 if verbose: print '\n', '-=' * 30 print "Running %s.test00_wideTree..." % \ self.__class__.__name__ print "Maximum number of childs tested :", maxchilds # Open a new empty HDF5 file file = tempfile.mktemp(".h5") #file = "test_widetree.h5" fileh = openFile(file, mode = "w") if verbose: print "Children writing progress: ", for child in range(maxchilds): if verbose: print "%3d," % (child), a = [1, 1] fileh.createGroup(fileh.root, 'group' + str(child), "child: %d" % child) # Comment the createArray call to see the leak disapear fileh.createArray("/group" + str(child), 'array' + str(child), a, "child: %d" % child) if verbose: print # Close the file fileh.close() #---------------------------------------------------------------------- def suite(): theSuite = unittest.TestSuite() theSuite.addTest(unittest.makeSuite(WideTreeTestCase)) return theSuite if __name__ == '__main__': unittest.main(defaultTest='suite') From mertz at gnosis.cx Thu Aug 28 02:17:36 2003 From: mertz at gnosis.cx (Lulu of the Lotus-Eaters) Date: Thu, 28 Aug 2003 02:17:36 -0400 Subject: OT: Celebrity advice References: <3F4D0D8B.5E5F9488@engcorp.com> <3F4D3560.71995AEB@engcorp.com> Message-ID: Peter Hansen wrote previously: |No, you're not taking the word "ultimately" far enough. First the |state tries to get painful on your ass, so you resist. Then they get |really violent, and still you resist. Just as a question of biology, a person can be locked in handcuffs, or in a metal cage, and be neither dead nor have the power to kill others. This limit comes not out of the compromise and will-power of the detained person, but simply out of physics and anatomy. In most "ultimate" cases of state-sponsored violence, this is what happens... not someone being killed. Someone upthread recommended Foucault... I strongly second reading his looks at "technologies of control." Yours, Lulu... -- mertz@ | The specter of free information is haunting the `Net! All the gnosis | powers of IP- and crypto-tyranny have entered into an unholy .cx | alliance...ideas have nothing to lose but their chains. Unite | against "intellectual property" and anti-privacy regimes! ------------------------------------------------------------------------- From donn at u.washington.edu Wed Aug 13 14:04:12 2003 From: donn at u.washington.edu (Donn Cave) Date: Wed, 13 Aug 2003 11:04:12 -0700 Subject: Python signal delivery under BSD 4.4 References: Message-ID: In article , "Elf M. Sternberg" wrote: > I'm having a devil of a time with signal handling under BSD 4.4 with > Python and I was hoping that this might ring a bell with someone. Using > the Webware Application Server (a multi-threaded Python application), I > fork off a process to run independently and do some heavy-duty multi- > threaded I/O churning. The process is launched with os.spawnvp(). > > The user may, at any time, elect to terminate this process > before it reaches its end. I do that by having the Application Server > send a SIGUSR1 signal to the process ID returned by os.spawnvp(), which > so far has been reliably returned and stored in the appserver's session > mananger. So far, so good. > > This worked well under Python 2.1, where I used os.fork() instead > of os.spawnvp(). > > We have upgraded to Python 2.2.3 and it has mysteriously stopped > working. Processes launched off the appserver, whether using os.fork() > or os.spawnvp(), are now completely deaf to signals. Nothing gets its > attention except, of course, SIGKILL. Not when sent from the appserver, > and not when sent from the shell, not even by root. > > If the process is launched from the command line, however, it > is well-behaved and responds to signal reliably. > > What gives? Don't know. Can you duplicate it in a simpler environment? I'd like to run the following C program from spawnv, from a Python program like import os import time import signal p = os.spawnv(os.P_NOWAIT, 'prsig', ['prsig']) time.sleep(1.0) os.kill(p, signal.SIGTERM) print 'process exit', os.waitpid(p, 0) if you think that represents what you're doing. This seems to work as expected with Python 2.2 on a BSD platform (if your "BSD 4.4" is actually NetBSD 1.6 or FreeBSD 5.1, I could try that.) The reasons I can think of in principle are 1. handler set to SIG_IGN (if the child process is supposed to exit due to the default signal handler.) 2. blocked via signal mask 3. wrong process Donn Cave, donn at u.washington.edu/donn at drizzle.com include #include #include static void handler(int sig) { switch (sig) { case SIGALRM: fprintf(stderr, "caught SIGALRM\n"); break; case SIGUSR1: fprintf(stderr, "caught SIGUSR1\n"); break; default: fprintf(stderr, "caught %d\n", sig); } exit(0); } static void prsig(int sig) { struct sigaction sa; int status; memset(&sa, 0, sizeof(sa)); status = sigaction(sig, 0, &sa); if (status == 0) { printf("sigaction {\n"); printf(" sa_handler 0x%08x,\n", sa.sa_handler); printf(" sa_flags 0x%08x\n", sa.sa_flags); /* printf(" sa_mask 0x%08x\n", sa.sa_mask); */ printf("}\n"); } else { perror("sigaction query"); exit(2); } } static void prmask() { sigset_t mask; int status; status = sigprocmask(SIG_SETMASK, 0, &mask); if (status == 0) fprintf(stdout, "mask 0x%lx\n", mask); else { perror("sigprocmask"); exit(2); } } static void sethandler(int sig, void (*hf)(int)) { struct sigaction sa; int status; memset(&sa, 0, sizeof(sa)); sa.sa_handler = hf; status = sigaction(sig, &sa, 0); if (status == 0) { } else { perror("sigaction"); exit(2); } } static void pause() { char buffer[4]; read(0, buffer, 4); } int main(int argc, char **argv) { prsig(SIGUSR1); prmask(); sethandler(SIGUSR1, handler); sethandler(SIGALRM, handler); alarm(3); pause(); return 0; } From t.evans at paradise.net.nz Tue Aug 19 04:23:45 2003 From: t.evans at paradise.net.nz (Tim Evans) Date: Tue, 19 Aug 2003 08:23:45 GMT Subject: Problem with garbage collection (sort of) References: <246a4e07.0308180608.2b8d685a@posting.google.com> Message-ID: <87ekzi12em.fsf@cassandra.evansnet> frank at chagford.com (Frank Millman) writes: >snip< > class a: > def __init__(self,b): > self.b = b > print 'a created' > def __del__(self): > print 'a deleted' > > class b: > def __init__(self): > self.p = [] > e = a(self) > self.p.append(e) > print 'b created' > def __del__(self): > print 'b deleted' > > class c: > def __init__(self): > self.f = b() > print 'c created' > def __del__(self): > # del self.f.p > print 'c deleted' > > y = c() > #del y.f.p > > #-------------------------------------------- > > y is an instance of class c, which creates an instance of class b, > which creates an instance of class a. When y goes out of scope and is > deleted, I want the instances of class b and class a to be deleted as > well. > > The problem is that class a keeps a reference to class b (self.b) and > class b keeps a reference to class a (self.p), so the reference counts > do not go down to zero without some additional action. > > I have 2 possible solutions - the two commented-out lines. If either > of these lines are uncommented, all instances are deleted. > > The ugliness is that p is internal to class b - neither class c nor > the main application requires any knowledge of it. However, my > solution requires one or the other to explicitly delete it. > > Any advice will be much appreciated. > > Many thanks > > Frank Millman Others have discussed the cyclic garbage collector... Another possible solution is to use the weakref module. See the docs for the details, but this here is how you could use it: --------------------------------------- import weakref class a: def __init__(self,b): self.b = weakref.ref(b) print 'a created' def __del__(self): print 'a deleted' --------------------------------------- The only difference is that when you access 'self.b' you need to use 'self.b()' to follow the weakref and get the real object. Note that 'self.b()' will return None if the real object has been destroyed already (i.e. when nothing references it with a real reference). Weak refs are quite useful in the situation that you appear to have, where a node in a tree needs to access it's parent but where the node won't outlive it's parent. You're still probably better off trusting the cyclic garbage collector, but weakrefs are another option. Note that if you want to watch things being collected by the gc, you can do this: --------------------------------------- class DelWatcher: def __init__(self, obj): self.objrepr = repr(obj) def __del__(self): print '%s deleted' % self.objrepr class a: def __init__(self,b): self._delwatcher = DelWatcher(self) self.b = weakref.ref(b) print 'a created' --------------------------------------- You may need to do 'import gc; gc.collect()' to actually collect all the objects right away. 'gc.collect()' gets run periodically by the interpreter so you don't need to do it in your application. -- Tim Evans From jarausch at skynet.be Thu Aug 7 03:07:35 2003 From: jarausch at skynet.be (Helmut Jarausch) Date: Thu, 07 Aug 2003 09:07:35 +0200 Subject: check if running under IDLE In-Reply-To: References: <13a533e8.0308051237.6bfa05d3@posting.google.com> <3f2ec16b$0$285$ba620e4c@reader0.news.skynet.be> <13a533e8.0308051237.6bfa05d3@posting.google.com> Message-ID: <3F31FAB7.8020607@skynet.be> Bob Gailer wrote: > At 11:48 AM 8/6/2003 +0200, Helmut Jarausch wrote: > [snip][ > To check a script accessing sys.argv I have to set it. > >> Unfortunately the 'Run' pulldown menu of IDLE doesn't have an item >> to set sys.argv as it's common with debuggers for C. >> >> Now in Python I can set sys.argv within the script, >> but forgetting to comment this out afterwards makes the >> script wrong outside of IDLE >> >> So I'd like to say >> >> if __IDLE_IS_RUNNUNG__: >> sys.argv=['test','-a','/home/jarausch/BackUp'] >> >> but I haven't work how to check if the script is running under IDLE's >> supervision. > > > import sys > __IDLE_IS_RUNNUNG__ = len(sys.modules) > 20 > Thanks for this idea. Just to report a simple script #!/usr/local/bin/python import sys print len(sys.modules) prints 26 here (Python 2.3) while under idle I get 117 so __IDLE_IS_RUNNUNG__ = len(sys.modules) > 100 seems to be safe. Helmut. -- Helmut Jarausch Lehrstuhl fuer Numerische Mathematik RWTH - Aachen University D 52056 Aachen, Germany From roy at panix.com Sat Aug 23 13:29:10 2003 From: roy at panix.com (Roy Smith) Date: Sat, 23 Aug 2003 13:29:10 -0400 Subject: Modifying the {} and [] tokens References: <04cekv0s6ghjtuhl5j2gph7ltobdb5rsam@4ax.com> <62rekv0k4ucgrh46lkp27klq13pq8ppp5p@4ax.com> <1h3fkvg8mkeq69a8hriojugqfcp75hafjj@4ax.com> <5l7fkvsd2lor14s7s0avra2553nfhe3net@4ax.com> Message-ID: Geoff Howland wrote: > Then you wouldn't be effected one way or the other. :) Sure I will. It will be one more thing I potentially need to know to understand somebody else's code. From dtolton at yahoo.com Mon Aug 18 16:16:21 2003 From: dtolton at yahoo.com (Doug Tolton) Date: Mon, 18 Aug 2003 20:16:21 GMT Subject: What's better about Ruby than Python? References: Message-ID: <2qc2kvsti2r6vfpr3tt9468go9qjf0sape@4ax.com> On Mon, 18 Aug 2003 10:52:09 -0700, "Brandon J. Van Every" wrote: >Let me make myself as clear as I can. I am not the slightest bit interested >in yours or anyone else's philosophy of whether I should have asked the >question, or what manner I should have asked it. I asked a very simple >question, and in some cases was rewarded with very simple, helpful answers. >Whereas this meta-debate is a complete waste of time. Clearly you are interested in people's philosophical take on why you should've posted to the Ruby boards, because you take the time to respond to each and every criticism. It's interesting to note that you could've pre-empted the question by saying either "I've also posted this to the Ruby group, but I wanted your take" or "The Ruby group is a bunch of dunder heads and I only like Python programmers" etc. However your ranting and whining about people not answering the question to your satisfaction is amusing. Beggars can't be choosers my friend. You posted an antagonistic question to the Python board, expect to get antagonistic responses. Clearly people don't care if they are answering your question in a way that is suitable and appealing to you. Doug Tolton (format t "~a@~a~a.~a" "dtolton" "ya" "hoo" "com") From daniel.rawson.take!this!out! at asml.nl Wed Aug 6 06:47:34 2003 From: daniel.rawson.take!this!out! at asml.nl (Dan Rawson) Date: Wed, 06 Aug 2003 06:47:34 -0400 Subject: Checking for an "undefined" variable - newbie question Message-ID: How do I check if a variable has been defined?? The following don't appear to work: if variable: if variable is None: I have only one (ugly) solution: try: variable except NameError: ... which works, but is a bit clumsy if I just want to know if the thing already exists. If there's a more elegant way to check this, that would be great! Thanks . . . . Dan From basile at starynkevitch.net Sat Aug 30 21:45:55 2003 From: basile at starynkevitch.net (Basile STARYNKEVITCH) Date: 31 Aug 2003 03:45:55 +0200 Subject: ANN: guis-1.1 - a (Python) programmable GTK2 widget "server" Message-ID: Dear All, It is my pleasure to announce the availability of Guis, which is a programmable graphical user interface widget "server". Guis communicate with a (one) client application thru textual communication channels; input requests (from application to guis) are Python instructions (using the PyGTK binding to GTK2) and output replies (or events) are arbitrary textual lines from Guis to application (sent by Python code). There is a possibility to trace the exchanges between application & guis (in a graphical window) Guis is therefore a programmable (in Python) GTK2 widget server. The GTK related code of Guis can easily be ported to any embeddable scripting language offering a GTK2 binding. Guis is opensource, under GNU General Public License, developped under Linux. See http://www.starynkevitch.net/Basile/guisdoc.html for documentation on Guis, and also http://freshmeat.net/propjects/guis/ and download source code (with demo) from http://www.starynkevitch.net/Basile/guis-1.1.tar.gz (a 946707 GNU gzipped tar file of md5sum 8bc2ece3e669ae4a5738168489d6acc6) Comments, suggestions and patches are welcome! (PS a previous incompatible version 0.3 of guis was scriptable in lua) Regards -- Basile STARYNKEVITCH http://starynkevitch.net/Basile/ email: basilestarynkevitchnet aliases: basiletunesorg = bstarynknerimnet 8, rue de la Fa?encerie, 92340 Bourg La Reine, France From ayc8NOSPAM at cornell.edu Sat Aug 2 16:21:50 2003 From: ayc8NOSPAM at cornell.edu (Andy C) Date: Sat, 02 Aug 2003 20:21:50 GMT Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> <87el06d2i6.fsf@pobox.com> Message-ID: > > it isn't to a compiler). OTOH, *Python's* scheme is inferior to a > > pure-space-character indentation scheme because off the tab-vs.-space > > issue :-( > > Well, that's been recognized as a problem for a long time. I believe > that the intention is to mandate spaces only in Python 3.0. On the > other hand, I'm not holding my breath waiting for Guido to decide What's bad about tabs? I'm new to Python. Tabs are good because then you can view the source however you want. I can't write in 4 space tabs and someone else can change it to 2 if they prefer. But I can see the problem with continuation lines. Also it must be ALL tabs or ALL spaces. This shouldn't be too hard -- most editors have the "tabify" option. Andy From mpeuser at web.de Fri Aug 29 10:28:11 2003 From: mpeuser at web.de (Michael Peuser) Date: Fri, 29 Aug 2003 16:28:11 +0200 Subject: string.count issue (simple) References: Message-ID: Hello Halfdan, it is a pity that you did not copy&paste the code in question. What you posted cannot work - count has no keyword parameters! On the other hand the use of find AND count is quite redundant... This snippet works fine: count = 0 for eachLine in allLines: count += eachLine.count(word) Kindly Michael P "Halfdan Holger Knudsen" schrieb im Newsbeitrag news:mailman.1062163536.18292.python-list at python.org... > ok first off: Has the string.count function been replaced in python 2.2 > (as compared to 1.5)?m And second: > > I need this in relation to a stringsearch program > assuming a text file has been loaded into allLines and word contains the > string you're searching for I want to count all occurences of the search > string the following should do it (but doesn't - please disregard any > missing colons or such this has not been copy/pasted): > > count = 0 > > for eachLine in allLines: > if eachLine.find(word) > -1: > count = count + eachLine.count(word, beg=0, end=len(eachLine) > print eachLine > print count > > what am I missing - it only outputs the nubmer of lines (as if the count > statement had been count = count + 1) > > thanks > H > From dave at pythonapocrypha.com Thu Aug 28 03:07:02 2003 From: dave at pythonapocrypha.com (Dave Brueck) Date: Thu, 28 Aug 2003 01:07:02 -0600 Subject: Style question... In-Reply-To: <20030828062328.19471.qmail@uymail.com> References: <20030828062328.19471.qmail@uymail.com> Message-ID: <200308280107.02349.dave@pythonapocrypha.com> On Thursday 28 August 2003 12:23 am, U. N. Owen wrote: > Re: Anthony Roberts wrote: > Re: > > Re: > If I end indentation levels with "pass" statements, will I piss off > people Re: > that have to read my code? eg: > Re: > > Re: > for i in xrange(0,5): > Re: > if i: > Re: > print i > Re: > pass > Re: > print i * -1 > Re: > pass > Re: > > Re: > I ask for two reasons... a) it helps emacs figure it out, and b) I'm > more Re: > comfortable ending compound statements with a token. > Re: > Re: Sorry, but yes, I find that ugly. If you're just starting out with > Re: Python, please just give it a shot without that approach for a while > Re: and see whether you become much more comfortable *without* the token > Re: than you ever were with it. > Re: > Re: -Peter > Re: -- > > > Sorry, but no ;-) Ok it's "one line more", and > is not very useful. But... > For the moment I work on (a small part of) a project > that has hundreds of thousands of lines, almost > eveything in Python (and some in C and Fortran), > and when you have a loop several pages long, or > nested blocks to 8 levels or more, I may say > it's *very* convenient to see where the end > of a block exactly is. It's convenient to > have some long variable names too. Sorry, but yes * 2. ;-) Please just don't tolerate loops several pages long and/or nested blocks that deep - such things should occur very, very rarely (essentially never). Putting an end-block delimiter after such beasts is like putting a band-aid on top of a compound fracture. -Dave From a.schmolck at gmx.net Mon Aug 18 11:21:26 2003 From: a.schmolck at gmx.net (Alexander Schmolck) Date: 18 Aug 2003 16:21:26 +0100 Subject: What's better about Ruby than Python? References: Message-ID: "Brandon J. Van Every" writes: > What's better about Ruby than Python? I'm sure there's something. What is > it? > Since I think this is a reasonable question and I haven't seen to many direct answer I'll give it a shot. I recall the following, roughly in order of importance (treat with caution, it's some time that I looked at Ruby): 0. I it's possible to redefine classes at runtime without going bonkers (instances automatically get updated to the new class definitions). This, I think is by far python's greatest flaw, amongst other things it greatly compromises its interactiveness, which is a key virtue. If someone can explain to me how I'm wrong on this and python's behavior really is sane, I'll be eternally grateful. 1. syntactic distinction between destructive and nondestructive methods (list.sort! vs list.sort) 2. lightweight lambdas (blocks) 3. Generally more OOation (in the style of Smalltalk), if you think that's good (doesn't make functional programming easier, for example). The class hierachies are certainly cleaner and, thanks to 'modules' (viz. mixins), have less duplication. In python, for example there is no reasonable way to find out whether something is a Mapping, or a number and classes that should be taxonmically connected aren't and thus reduplicate code (or just miss random features; e.g. both `str` and `list` have methods that the other one could do with; in ruby this is handled by the Enumeration module) 5. continuations, should you so desire. 6. An interesting attempt at an OO case statement. I should add that 1. and 2. are however inexcusably flawed, especially since they are really just (badly) adapted from scheme and smalltalk, respectively: irb(main):001:0> [1,2].sort [1, 2] irb(main):002:0> [1,2].sort! [1, 2] irb(main):003:0> [1].sort [1] irb(main):004:0> [1].sort! nil ^^^ !!! irb(main):017:0> x = 10 10 irb(main):018:0> [1,2,3].reject {|x| x < 2} [2, 3] irb(main):019:0> x 3 This together with some other symptoms (what the hell is the point of having Array.assoc?) gives me the overall impression that Ruby is an uglified smalltalk, hideously disguised as Perl for mainstream appeal with some random scheme features on top crafted by someone who doesn't seem to have quite understood either smalltalk or scheme. OTOH, smalltalk and scheme at least aren't such bad languages to steal from (even badly) and Ruby has one worthwhile feature over (standard) smalltalk, mixins (there is BTW, some interesting work in the squeak community on 'traits'). 'as From hokiegal99 at hotmail.com Tue Aug 26 22:33:36 2003 From: hokiegal99 at hotmail.com (hokiegal99) Date: Tue, 26 Aug 2003 22:33:36 -0400 Subject: Raw Input Question Message-ID: <3F4C1880.5030903@hotmail.com> How can I pass the content of one varible into raw_input? See below for what I'm trying to do: XXX = raw_input("1. Enter the string that you'd like to find: ") y = raw_input("2. Enter the string that you'd like to replace XXX with: ") I'm trying to pass x into y. I tried the "Enter the string that you'd like to replace", XXX, "with:" approach, but Pyhton told me that I could only pass 1 argument, no more. Thanks!!! From mwh at python.net Thu Aug 28 13:29:15 2003 From: mwh at python.net (Michael Hudson) Date: Thu, 28 Aug 2003 17:29:15 GMT Subject: finding object using IS instead of == References: Message-ID: <7h3bru966dk.fsf@pc150.maths.bris.ac.uk> "Mark Hahn" writes: > If I have a large collection (list, tuple, or dict) of objects, can > I locate one quickly that matches a given object using the IS > equivalence operator instead of the value == operator? I don't think so. You'll have to roll your own code. Cheers, mwh -- One of the great skills in using any language is knowing what not to use, what not to say. ... There's that simplicity thing again. -- Ron Jeffries From vze4rx4y at verizon.net Thu Aug 21 01:15:56 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Thu, 21 Aug 2003 05:15:56 GMT Subject: how fast is Python? References: Message-ID: "dan" > However, there are definitely cases where a lot of code would need to > be optimized, and so I ask the question: How fast is Python, compared > to say a typical optimizing C/C++ compiler? The extension modules run at optimized C speed because they *are* optimized C. For pure python applications, Psyco can provide just-in-time native compilation. Tim once said that anything written using Python's dictionaries are zillions of times faster that anything else. There is a grain of truth in that because Python makes it so easy to create efficient data structures that their performance can surpass less data structures written in assembly or C. All that being said, Python is designed for those who value programmer time more than they value clock cycles. Raymond Hettinger From jepler at unpythonic.net Sat Aug 30 10:02:26 2003 From: jepler at unpythonic.net (Jeff Epler) Date: Sat, 30 Aug 2003 09:02:26 -0500 Subject: My script is taking 12 hours+ any suggestions? In-Reply-To: <3f4ff9f8$0$23588$5a62ac22@freenews.iinet.net.au> References: <3f4ff9f8$0$23588$5a62ac22@freenews.iinet.net.au> Message-ID: <20030830140221.GC18871@unpythonic.net> As one poster mentioned, you should convert to Python floats once, not many times. Second, you achieve some speed increase by putting everything inside a function. For instance, this program: for i in range(1000): j = sin(i) will run just a bit faster if you write it as def f(): for i in range(1000): j = math.sin(i) f() because access to "i" and "j" will be a C array indexing operation instead of a Python hash table lookup. You can get a little bit more speed if you make 'math.sin' into a local variable, for instance with def f(): sin = math.sin for i in range(1000): j = sin(i) f() As to the smoothing algorithm itself: I haven't decoded exactly what you're doing, but I once wrote a polygon smoothing algorithm modeled after http://www.xmission.com/~nate/smooth.html -- Here is his summary of his method: * First builds a list of all the triangles each vertex is in. * Then loops through each vertex in the the list averaging * all the facet normals of the triangles each vertex is in. * Finally, sets the normal index in the triangle for the vertex * to the generated smooth normal. If the dot product of a facet * normal and the facet normal associated with the first triangle * in the list of triangles the current vertex is in is greater * than the cosine of the angle parameter to the function, that * facet normal is not added into the average normal calculation * and the corresponding vertex is given the facet normal. * This tends to preserve hard edges. The angle to use depends * on the model, but 90 degrees is usually a good start. In my application, I had a flag available which said whether a particular face should participate in smooth normal generation or not, so I ignored that part of the algorithm. The step which takes some time is the grouping of the vertices. My models were small, so an N^2 approach in vertex count was not a problem even though I had to do the smoothing "online". The naive way, which involves comparing each vertex to all the other vertices, is N^2. You can get better-than-N^2 in a couple of ways. For instance, you could use a tree structure to partition space, just like octrees are used for color reduction. (this probably gives O(NlgN) behavior) You could just use a Python dict to place points into bins of a carefully chosen size so that points the other algorithms would consider identical almost always end up in the same bin, and points that the other algorithms would consider different almost always end up in different bins. I think this would give nearly O(N) behavior. Jeff From tismer at tismer.com Sun Aug 10 17:54:30 2003 From: tismer at tismer.com (Christian Tismer) Date: Sun, 10 Aug 2003 23:54:30 +0200 Subject: [Python-Dev] Slogan: Getting Rich Overnight In-Reply-To: <03Aug8.215641pdt."58611"@synergy1.parc.xerox.com> References: <03Aug8.215641pdt."58611"@synergy1.parc.xerox.com> Message-ID: <3F36BF16.4000406@tismer.com> Bill Janssen wrote: > Get Rich Overnight: > > Get Python Not bad, but no better concerning SPAM filters. -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 pager +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From vze4rx4y at verizon.net Fri Aug 8 12:13:38 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Fri, 08 Aug 2003 16:13:38 GMT Subject: random changes References: Message-ID: "dan" wrote in message news:fbf8d8f2.0308071030.1f174d34 at posting.google.com... > just a suggestion -- > > next time the core RNG is changed, I think it would be useful to have > an > -oldrandom switch. It is common practice in simulation projects to > depend > on the fact that your random numbers will come out the same if you use > the same seed. In bumping to 2.3 with the new Mersenne algorithm, I > have no easy way of duplicating my old results. It would have been helpful to included a sample call, the results, and the version of Python you were using. It looks like you were using Py2.0 and upgraded to Py2.3. This difference you are seeing came version Py2.1 when WichmannHill's seed method was improved (the upgrade to the Mersenne Twister has nothing to do with it): """ random.py's seed() function is new. For bit-for-bit compatibility with prior releases, use the whseed function instead. The new seed function addresses two problems: (1) The old function couldn't produce more than about 2**24 distinct internal states; the new one about 2**45 (the best that can be done in the Wichmann-Hill generator). (2) The old function sometimes produced identical internal states when passed distinct integers, and there was no simple way to predict when that would happen; the new one guarantees to produce distinct internal states for all arguments in [0, 27814431486576L). """ So, to get your old results with Py2.3, try something like: import random rng = random.WichmannHill() rng.whseed(12345) for i in range(6): print rng.randint(1, 10) Raymond Hettinger From vanevery at 3DProgrammer.com Tue Aug 12 05:27:26 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Tue, 12 Aug 2003 02:27:26 -0700 Subject: Python vs. C# References: <3f357a9b@shknews01> Message-ID: Joe Cheng wrote: > > From a purely language point of view, I think the comparison can be > boiled down to two main points. > > * Python is dynamic, C# is static. You've got a C++ background, so it > doesn't sound like you would consider C#'s static typing a liability, > nor would you likely fall in love with metaclasses and the like. So, > most of the arguments along the lines of "C# is too inflexible" will > probably not be relevant to you. Yep, true of my thinking. > * C#/.NET has to be one of the most mature "version 1.1" programming > systems in history. (I'm too young to be making definitive > statements about programming history, though...) You can tell by > reading Chris Brumme's blog the amount of sophistication they have > already achieved. Frankly, it's a little frightening how much MS can > accomplish in just a couple of years--when they want it bad enough. Good to hear that some people understand what it means when Microsoft puts 100% of the company behind something. Remember, last time around we got IE and Netscape vanished. > * Math.sin(x) versus sin(x)? Really, who cares?? Well, I care, but I'll be surprised if there's no way around it. And if there isn't, it's not a dominant issue, just an annoyance. > * The .NET community does not seem as clever and innovative, nor as > passionate, as the Python community. You sorta get the sense that > everyone who works with .NET is getting paid to do so, while Python > hackers bang away on their keyboards with glee. And it feels like > 90% of the innovation in the .NET realm comes from Microsoft itself > (or perhaps, 60% from MS and 30% from the Java open-source > community--NAnt, NUnit, NLucene, etc.). Yes, and that's both a weakness and a strength. The strength of uncreative bangers is they don't get idealistic about what market forces are going to carry the day. In contrast, idealistic Python hackers are so busy enjoying themselves that they don't feel they have to market in order to keep their platform alive. They have bad self-defense instincts. The DEC Alpha CPU was a joy to program for, it was the best and fastest CPU of 1998, and it's dead. Let that be a warning to you. > In contrast, I like Python very much (well, actually, Ruby is the one > that I really like--but close enough). Indeed, there are other wannabe langauges that would happily take Python's place on the food chain. Python merely has a mature community and a track record behind it. If other languages gain those things, and are even "more interesting than Python" in various people's minds, then what will keep Python on anyone's radar? > However, when it comes down to building the big, hairy, slightly > nasty (just admit it) software that brings home the bacon, sometimes > it's just gotta be C#. And if you live in Seattle, I'd say it's > gotta be C# all the way. Yep. I started this trek out of necessity, not love. I was surprised to discover the various positives of C# and .NET because I've been deliberately avoiding them. I have all the traditional anti-Microsoft prejudices, and frankly I'm opposed to them as a company. I'll never be their employee, but I'm willing to contract for them. It might be interesting to some that I cut teeth as a Linux hacker in 1993. By 1996 I had given it up, as at the time, 3D graphics on Linux was going nowhere. Today it is... ok, but behind Microsoft. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From gh at ghaering.de Tue Aug 12 04:50:51 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Tue, 12 Aug 2003 10:50:51 +0200 Subject: PYTHON AND C++ In-Reply-To: <3f38a42b$0$245$fa0fcedb@lovejoy.zen.co.uk> References: <3f38a42b$0$245$fa0fcedb@lovejoy.zen.co.uk> Message-ID: <3F38AA6B.4000705@ghaering.de> Somebody with the 1337 pseudonym "BadJake" wrote: > Hi > We use Phil Thompson's exellent interface genentor - SLIP You certainly mean SIP :) > You can download SLIP from Phil's web site at > http://www.riverbank.demon.co.uk No, I can't. This is how the page looks like: """ Index of / mode links bytes last-changed name dr-x 2 4096 Apr 15 2000 ./ dr-x 50 4096 Jul 25 22:01 ../ """ :-P I'm sure it will be up again soon ;-) -- Gerhard From duncan at NOSPAMrcp.co.uk Wed Aug 6 10:19:48 2003 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Wed, 6 Aug 2003 14:19:48 +0000 (UTC) Subject: Checking for an "undefined" variable - newbie question References: Message-ID: Alex Martelli wrote in news:XL5Ya.40525$cl3.1301474 at news2.tin.it: > This is the canonical solution. Personally, I find it quite nice > that an ugly architecture (such as one based on whether a variable > is already defined/initialized rather than initializing it at the > start with a unique value and testing for that!) requires an ugly > way of expressing it. Unfortunately there are nicer ones such as > "if 'variable' not in locals() and 'variable' not in globals():" but > at least they're verbose and slow:-). How slow the nicer forms are kind of depends whether or not you expect the variable to exist. The canonical solution is very fast if the variable exists and the exception isn't thrown, but if the exception is thrown it sucks: >timeit.py "try:" " variable" "except NameError: pass" 100000 loops, best of 3: 11.3 usec per loop >timeit.py -s "global variable" -s "variable=0" "try:" " variable" "except NameError: pass" 1000000 loops, best of 3: 0.374 usec per loop Testing for membership of globals() is pretty fast whether or not the variable exists: >lib\timeit.py "if 'variable' not in globals(): pass" 1000000 loops, best of 3: 0.576 usec per loop >lib\timeit.py -s "global variable" -s "variable=0" "if 'variable' not in globals(): pass" 1000000 loops, best of 3: 0.636 usec per loop Testing for membership of locals() or vars() is slower than globals() (as you would expect), but if the variable doesn't exist it still beats the exception block by a long way: >lib\timeit.py "if 'variable' not in vars(): pass" 1000000 loops, best of 3: 1.44 usec per loop >lib\timeit.py -s "variable=0" "if 'variable' not in vars(): pass" 1000000 loops, best of 3: 1.75 usec per loop However, I must say that I agree fully with the point that Alex was really making (albeit somewhat obliquely). You shouldn't normally have to do this kind of thing at all. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From Stephen.Boulet at no.spam.motorola.com Mon Aug 18 10:28:54 2003 From: Stephen.Boulet at no.spam.motorola.com (Stephen Boulet) Date: Mon, 18 Aug 2003 09:28:54 -0500 Subject: Exiting python to the DOS shell in 2.3 Message-ID: Control-C doesn't get me back to the DOS prompt anymore in python 2.3. Aside from typing "import sys" and "sys.exit()", is there a key combination to quit python? BTW, the "enumerate" function is the best thing since sliced bread. -- Stephen From sjmachin at lexicon.net Thu Aug 7 08:43:13 2003 From: sjmachin at lexicon.net (John Machin) Date: 7 Aug 2003 05:43:13 -0700 Subject: Stupid string.split question References: Message-ID: "Batista, Facundo" wrote in message news:... > #- Is there any conceptual reason why > #- > #- "ABCDEF".split("") shouldn't equal ["A", "B", "C", "D", "E", "F"]? > #- > #- The error says empty seperator, but the result makes sense > #- given that > #- fact and the fact that: > #- > #- "".join(["A", "B", "C", "D", "E", "F"]) == "ABCDEF" > #- > #- It seems that if you can join with an empty seperator, you should be > #- able to split with one. > > Beyond any particular reason, or a better way to do it, seems nice to me to > be able to split with empty separator, just to thin of join and split as > "complementary" functions (but that's just my opinion). > All the old chestnuts are being dragged out ... looks like it's going to be a long hot summer :-) From sholden at holdenweb.com Mon Aug 11 17:19:52 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 11 Aug 2003 17:19:52 -0400 Subject: PayPal Donation Page Message-ID: Has anyone noticed odd problems with this page, or is it just me? Here I am, trying to give money via https://www.paypal.com/cgi-bin/webscr and whenever I click on the "Continue" button it stays in "button-down" mode and the window locks up. In fact, dammit, this happens even when I try to just log in at www.paypal.com - anyone seen this behavior on Windows 2000? regards -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ From bokr at oz.net Mon Aug 18 16:57:50 2003 From: bokr at oz.net (Bengt Richter) Date: 18 Aug 2003 20:57:50 GMT Subject: hex(-5) => Futurewarning: ugh, can't we have a better hex than '-'[:n<0]+hex(abs(n)) ?? References: Message-ID: On Mon, 18 Aug 2003 09:16:48 +0200, "Michael Peuser" wrote: > >"Juha Autero" schrieb im Newsbeitrag >news:mailman.1061182647.31076.python-list at python.org... >> Freddie writes: >> >> >> There is a thread from this morning ("bitwise not ...") - this should >be an >> >> excellent contribution! >> >> I have no mercy with someone writing hex(-5) >> >> >> >> Kindly >> >> Michael P >> >> >> >> >> > >> > What about crazy people like myself? If you generate a crc32 value with >zib, >> > you occasionally get a negative number returned. If you try to convert >that >> > to hex (to test against a stored CRC32 value), it spits out a >FutureWarning >> > at me. >> >> Read the thread about bitwise not. Tell Python how many bits you >> want. In case of CRC32 that is of course 32 bits: >> hex(-5&2**32-1) >> >> Two questions: What is the best way to generate bitmask of n bits all >> ones? > >Why do you object to 2**n-1? This is just fine I think. > >> And would sombody explain why hexadecimal (and octal) literals >> behave differently from decimal literals? (see: >> http://www.python.org/doc/current/ref/integers.html ) Why hexadecimal >> literals from 0x80000000 to 0xffffffff are interpetred as negative >> numbers instead of converting to long integers? > >Most of all this has practical reasons because of the use most programmers >have for stating hexadecimal literals. > >Of couse some hex literals are not interpreted as negative numbers but the >memory contents, because it has become undistinguishable what the origin had >been. > >One will not expect > print int(0xffffffff ) >do something different from > x=0xffffffff > print int(x) > Unfortunately, the path to unification of integers to hardware-width independence has backwards compatibility problems. I guess they are worse than for true division, but has anyone really attempted to get a measure of them? The options for hex representation seem to be (in terms of regexes) 1) signed standard: [+-]?0x[0-9a-fA-F]+ 2) unprefixed standard: [0-9a-fA-F]+ which are produced by hex() and '%x' and '%X' and interpreted by int(x, 16) There is a need for a round trip hex representation/interpretation for signed integers of arbitrary size, but IMO a prefixed '-' does violence to the usual expectation for hex representation (i.e., a sensible view of the bits involved in a conventional "two's complement" representation of the number to whatever width required). I hope it can be avoided as a default, but that at a minimum, that an alternative will be provided. For hex literals, the [01]x[0-9a-fA-F]+ variation seems clean (I forgot again who came up with that as the best emerging alternative in an old thread, but credit is due). Tim liked it too, I believe ;-) Since hex() will change anyway, how much more breakage will hex(-1) => 1xf create vs => -0x1 ? Not to harp, but obviously the -0x1 gives no sense of the conventional underlying bit pattern of ...fffff. (I am talking about an abstract bit pattern that extends infinitely to the left, not a concrete implementation. Of course it is often useful to know how the abstraction gets implemented on a particular platform, but that is not the only use for hex. It is also handy as a human-readable representatation of an abstract bit sequence). The other question is what to do with '%x'. The current 2.3 version doesn't seem to pay much attention to field widths other than as a minimum, so that may offer an opportunity to control the output. It does not generate an '0x' prefix ( easy for the positive case to specify as 0x%x) yet negatives presumably will prefix a '-'. (Will 0x-abcd be legal??) What are some other possibilities? Looking forward to using widths, what would one hope to get from '%2.2x'%-1 ? I would hope for 'ff', personally ;-) And ' 1' for '%2.2x'%1 and '01' for %02.2x'%1. Coming at it from this end, what happens if we drop the max width? What should we get for '%02x'%1 ? That's easy: '01' as now. But '%02x'%-1 => 'ffffffff' currently, and that has to change. Apparently to '-1' if things go as they're going? (Again, hexness is lost). A possibility for unrestricted output width would be to print enough hex characters for an unambiguous interpretation of sign. I.e., so that there are enough bits to include the sign and an optional number of copies to pad to a full 4-bit hex character as necessary. This would mean '%02x'%-1 => ff since that gives the first hex character the right sign. That has the wrong interpretation (if you want to recover the signed value) for int(('%02x'%-1),16) so that would need a fix for easy use. Although I usually dislike passing flag info to functions by negating nonzero parameters, it would have mnemonic value in this case. E.g., int(('%02x'%-1), -16) or the equivalent int('ff', -16) could mean use the leading bit as sign. This convention would translate nicely to octal and binary string representations as well. Of course int(('%02x'%255) could not return 'ff' as an unconstrained-width representation. It would have to be '0ff' to provide the proper sign. Note that constraining this to a max width of 2 would give 'ff'. This works for octal and binary too. IMO this way of avoiding '-' in hex, octal, and binary string formats would make the strings represent the data more clearly. These formats are mainly to communicate bit patterns IMO, not just alternative ways to spell integer values. If we have 1xf as a literal for spelling -0x1, I guess we don't need a literal format for the leading-bit-as-sign convention. But the latter would be a way of reading and writing signed arbitrary-width hex without losing the hexness of n the way you would with '%c%x'%('-'[:n<0],abs(n)) #yech, gak ;-/ Regards, Bengt Richter From tjreedy at udel.edu Fri Aug 29 12:34:45 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 29 Aug 2003 12:34:45 -0400 Subject: string.count issue (simple) References: Message-ID: "Halfdan Holger Knudsen" wrote in message news:mailman.1062163536.18292.python-list at python.org... > string the following should do it (but doesn't - please disregard any > missing colons or such this has not been copy/pasted): In the future, please help your asked-for helpers by including the actual code that failed to run. TJR From theller at python.net Thu Aug 7 15:52:06 2003 From: theller at python.net (Thomas Heller) Date: Thu, 07 Aug 2003 21:52:06 +0200 Subject: py2exe problems References: <8utYa.48785$cl3.1524137@news2.tin.it> Message-ID: Thomas Heller writes: > "Alessandro Crugnola *sephiroth*" writes: > >>> The canonical test I use is to run the test_c14n.py test from the >>> PyXML source distribution through py2exe. It works for me, on Windows XP >>> Pro, SP 1, py2exe-0.4.1, Python 2.2.2, PyXML-0.8.3, with the command line >>> 'python setup.py py2exe -p encodings' >>> and this script: >>> >>> from distutils.core import setup >>> import py2exe >>> >>> setup(name='test_c14n', scripts=['test_c14n.py'], version='0') >> >> Sorry, i get always the same error: >> >> File "", line 170, in ? >> File "imputil.pyc", line 132, in _import_hook >> File "", line 70, in _finish_import >> File "imputil.pyc", line 316, in _load_tail >> File "imputil.pyc", line 271, in _import_one >> File "", line 128, in _process_result >> File "xml\dom\ext\reader\__init__.pyc", line 20, in ? >> LookupError: no codec search functions registered: can't find encoding >> >> >> python 2.2.3 >> pyxml 0.8.3 > > Then I have no idea. Installing 2.2.3 instead of 2.2.2 is something I > cannot currently do (and I doubt it would help). Ok, I've installed 2.2.3 and verified the behaviour you observed. And I have a workaround: run the setup script with these options, and the test_c14n.py script works as executable: python py2exe --packages encodings --force-imports encodings (I had nearly forgotten the force-imports option, and I still don't remember exactly what it does :-) Thomas From tjreedy at udel.edu Wed Aug 6 19:46:39 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 6 Aug 2003 19:46:39 -0400 Subject: Bug? If not, how to work around it? References: <060820031458029244%mday@apple.com> Message-ID: <09udnV37oMEUDqyiU-KYgw@comcast.com> "Gon?alo Rodrigues" wrote in message news:upv2jv4eeusj7bli30j7a7ikd0cq3njvm4 at 4ax.com... > >I changed the __iter__ method to the following, and it seems to do what > >you want: > > > > def __iter__(self): > > return iter(self.__obj) > But this is precisely what I don't want to do. If you don't want to do what works, why ask us to bother answering? TJR From jepler at unpythonic.net Tue Aug 5 22:15:57 2003 From: jepler at unpythonic.net (Jeff Epler) Date: Tue, 5 Aug 2003 21:15:57 -0500 Subject: Capture output from stderr In-Reply-To: References: Message-ID: <20030806021557.GD17834@unpythonic.net> On Wed, Aug 06, 2003 at 12:30:13AM +0000, Grant Edwards wrote: > I've always used a read handler for this in the past, and it worked fine. > I don't have an example handy... ... this is found at _tkinter.createfilehandler() or Tkinter.createfilehandler() [though this didn't work for me!], doesn't exist on Windows (AFAIK), and seems to be undocumented in pydoc. I think they're a wrapper on Tcl_CreateFileHandler, which has a manpage. Here's a little program I just put together, it shows the output from a command in a scrolling text area, using popen and _tkinter.createfilehandler. It doesn't do anything in particular about stderr, but that's a matter of switching to popen4 or a friend (Another way, on systems that use /bin/sh as their shell, is to use 'exec 2>&1; actual command' as the popen argument). Other niceties need to be observed, like making the Text and refuse keybooard focus and be non-editable ... On my system, a good command that takes some time to execute and only produces a few hundred lines of output is $ python tktail.py rpm -qa ... but that'll only work on systems with rpm. Something that would work on more systems would be $ python tktail.py "for i in /*; do echo $i; sleep 1; done" # The following code is placed in the public domain import Tkinter, _tkinter, fcntl, os, sys t = Tkinter.Tk() tx = Tkinter.Text(wrap="char") tx.pack(side="left", expand=1, fill="both") s = Tkinter.Scrollbar(orient="v", command=tx.yview) s.pack(side="left", fill="y") tx.configure(yscrollcommand=s.set) command = " ".join(sys.argv[1:]) t.wm_title("%s - tktail" % command) p = os.popen(command, "r") pf = p.fileno() # Make reads from the popen'd command nonblocking # (so read returns the bytes available without waiting) fcntl.fcntl(pf, fcntl.F_SETFL, os.O_NONBLOCK) def readfunc(fileobj, event_type): bytes = p.read() if bytes == '': bytes = "***END OF OUTPUT***" t.wm_title("%s - COMPLETED - tktail" % command) _tkinter.deletefilehandler(p) # bbox is a true value if the specified location is visible b = tx.bbox('end - 1l') tx.insert('end', bytes) # If the bottom line was visible before, scroll to the # new bottom. if b: tx.see('end') _tkinter.createfilehandler(p, Tkinter.READABLE, readfunc) t.mainloop() Jeff From jepler at unpythonic.net Sun Aug 3 16:24:18 2003 From: jepler at unpythonic.net (Jeff Epler) Date: Sun, 3 Aug 2003 15:24:18 -0500 Subject: popen eating quotes? In-Reply-To: References: Message-ID: <20030803202417.GA10412@unpythonic.net> This has been discussed before. One such thread that I participated in was http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&threadm=0000161b%40bossar.com.pl&rnum=1&prev=/groups%3Fq%3Dshell%2Bquoting%2Bnt%2Bgroup:comp.lang.python%26hl%3Den%26lr%3D%26ie%3DUTF-8%26selm%3D0000161b%2540bossar.com.pl%26rnum%3D1%26filter%3D0 [apologies for the long URL, I don't know how to get a good memorable URL for a google groups search] This really is a cesspool on Windows, and the fault isn't Python's. Python is just calling the Windows functions, which insist on behaving badly compared to the Unix behavior. unix bigot'ly yours, jeff From redrumjack at hotmail.com Wed Aug 27 23:38:03 2003 From: redrumjack at hotmail.com (Jesse) Date: Thu, 28 Aug 2003 03:38:03 GMT Subject: Windows Remote Log in Message-ID: I'm new to both programing and python and having a bit of a problem finding an answer online. I've got a script that will be running on a Windows Machine and will need to access remote servers not in the same domain. I'll be using this to restart services, copy files. This script will be run by the user so they will be available to enter their login information and the users all have manager access to the remote domains. Thanks, Jesse From skip at pobox.com Fri Aug 8 11:54:38 2003 From: skip at pobox.com (Skip Montanaro) Date: Fri, 8 Aug 2003 10:54:38 -0500 Subject: Need elegant way to cast four bytes into a long In-Reply-To: <3f33c209$1@news.si.com> References: <3f33c209$1@news.si.com> Message-ID: <16179.51134.403044.521554@montanaro.dyndns.org> wsh> I have been getting what I want in this sort of manner : wsh> l = 0L wsh> l = a[0] wsh> l += a[1] << 8 wsh> l += a[2] << 16 wsh> l += a[3] << 24 wsh> but I think that's too wordy. Is there a more intrinsic and wsh> elegant way to do this? You mean like this: l = long(a[0] + a[1] << 8 + a[2] << 16 + a[3] << 24) You can use struct.unpack as well, though I'd be hard-pressed to get the details correct. You'd be better off with "pydoc struct". Skip From adalke at mindspring.com Wed Aug 6 20:56:11 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Wed, 6 Aug 2003 18:56:11 -0600 Subject: Stupid string.split question References: <3f314721$0$3936$b45e6eb0@senator-bedfellow.mit.edu> <3F3160E6.BD604930@engcorp.com> Message-ID: Peter Hansen: > It's only a token kind of symmetry, without much real value. After > all, why shouldn't this be symmetrical, too, then? : > > ''.join(['abc', 'def', 'g', 'h']) --> 'abcdefgh' > > 'abcdefgh'.split('') --> ['abc', 'def', 'g', 'h'] That's a different symmetry than what Brian is arguing. He doesn't expect "a".join(["abc", "def", "cab"]) --> "abcadefacab" "abcadefacab".split() --> ["abc", "def", "cab"] Instead, he is bothered because the following doesn't work when sep == "" def split_join(s, sep): return s == sep.join(s.split(sep)): Andrew dalke at dalkescientific.com From newsgroups at jhrothjr.com Sat Aug 23 08:00:01 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Sat, 23 Aug 2003 08:00:01 -0400 Subject: large-scale app development in python? References: Message-ID: "gabor" wrote in message news:mailman.1061597346.828.python-list at python.org... > hi, > > at the company where i'm working we have to rewrite a part of our > java-based application in a different language. > > there were many options, at the end python and c++ remained. > > our program is quite big, so c++ was an obvious choice. > > python remained because we have to finish the rewrite in a reasonable > time, and python has all the necessary libraries or bindings that we > need. > > but i got a question, that i couldn't answer: > -you can't compile python, as you can c++ or java => there's no type > checking before starting the program => if one programmer changes a > method name or method signature, then how do we know we changed all the > code that calls that method? > > how do you solve these kind of problems? i know that unit tests are a > good thing, but i don't know if they can help in this situation? Generally, if you follow the TDD methodology, that is, your test suite has complete coverage and you test with every small change, you'll find out during coding that you forgot to change something. The trick is to have complete statement coverage, which is something that TDD does as a matter of course. If you've got sloppy programmers, and you don't have an automated test suite with close to complete coverage, or you don't run those tests after every change, you're going to have problems. > are there any people who wrote a big program in python? how did they > handle these problems? There are quite a few large programs in Python. Zope comes to mind immediately. > > or python simply isn't suited to write bigger (more complex) apps? > > thanks, > gabor John Roth From mis6 at pitt.edu Sun Aug 3 11:06:49 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 3 Aug 2003 08:06:49 -0700 Subject: Python debugger References: Message-ID: <2259b0e2.0308030706.5fd6b86a@posting.google.com> Syver Enstad wrote in message news:... > Dave Kuhlman writes: > > > Andrew Chalk wrote: > > > > > I am sure that it has been asked before but could someone tell a > > > newbie whether there is a Python debugger out there? > > > > > > > See: > > > > http://www.python.org/doc/current/lib/module-pdb.html > > And in case you don't like using a commandline debugger, you can use > pythonwin's debugger or Emacs together with pdb. How do I use pdb with emacs? Do you have any reference? Michele From h.b.furuseth at usit.uio.no Thu Aug 28 14:25:11 2003 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth (nospam nospam)) Date: 28 Aug 2003 20:25:11 +0200 Subject: imports after function definitions? Message-ID: Is there any reason not to structure my program like this? def ... def ... var = ... var = ... import ... import ... main_function() E.g. does it compile to slower code, or does it confuse PyChecker or something, if I put the imports after the functions that use them? -- Hallvard From mertz at gnosis.cx Thu Aug 28 21:18:46 2003 From: mertz at gnosis.cx (Lulu of the Lotus-Eaters) Date: Thu, 28 Aug 2003 21:18:46 -0400 Subject: OT: Dying Americans References: <3F4E7ED9.924AEAF2@engcorp.com> Message-ID: <2nqT/kKkXcma092yn@gnosis.cx> Dave Brueck wrote previously: |> > Think about it: even intuitively, 255 is *way* too low for a population |> > of 275 million (that's essentially zero - in a population that size 255 |> > people probably die in sneezing-releated incidents every year) The page at: http://webapp.cdc.gov/sasweb/ncipc/mortrate10.html Let's you slice-and-dice injury mortality rates in quite a few ways. You can check by age, by state, race, sex, and others. You can try different time periods and normalizations. In a morbid way, it's a fascinating URL. This doesn't include other causes of mortality like disease, but some other CDC pages have useful info there. The number I posted was adverse effects -excluding- medical care--i.e. accidental over-ingestion of aspirin, which seemed closest to the category Dave initially suggested. However, the CDC lists 2804 deaths from adverse effects in medical care, or about 1 per 100k. However, poisonings are at 20,230 in Y2000, which is 7.35/100k. I'm not sure how the CDC split out adverse effects from poisonings (obviously, -no- amount of insecticide is desirable to digest, but a lot of things have dosage transitions between useful and dangerous). Anyway, I find the CDC to be pretty darn definitive in these reports. Maybe not flawless, but a lot better than particular political advocacy groups (whether pro- or anti-gun, or MAAD, or environmental [pro- or con-], etc). Yours, Lulu... -- ---[ to our friends at TLAs (spread the word) ]-------------------------- Echelon North Korea Nazi cracking spy smuggle Columbia fissionable Stego White Water strategic Clinton Delta Force militia TEMPEST Libya Mossad ---[ Postmodern Enterprises ]-------------------------- From cbarber at curl.com Mon Aug 11 12:33:28 2003 From: cbarber at curl.com (Christopher Barber) Date: 11 Aug 2003 12:33:28 -0400 Subject: Python vs. C# References: <3f357a9b@shknews01> Message-ID: "Terry Reedy" writes: > "Brandon J. Van Every" wrote in message > news:3f357a9b at shknews01... > > What can I do with Python that I can't do with C#? > > Given that all Turing complete languages are theoretically equivalent, > nothing, either way. Turing equivalence is probably the least interesting property of any programming language and says absolutely nothing about its suitability for real programming tasks. From tismer at tismer.com Wed Aug 27 19:55:23 2003 From: tismer at tismer.com (Christian Tismer) Date: Thu, 28 Aug 2003 01:55:23 +0200 Subject: Zope 2.7 running with Stackless 3.0 Message-ID: <3F4D44EB.5010500@tismer.com> Dear friends, just by chance, I got into the position to try out Zope 2.7.0 beta 1/2, and since it needs Python 2.2.3 at least, and Stackless 3.0 was just ported to that, I tried to build Zope with Stackless 3.0. It works very very well! After a few patches to get the includes right, here the installation instructions. Get the current Stakless 3.0 beta. CVSROOT=:pserver:anonymous at centera.de:/home/cvs export CVSROOT cvs co stackless cd stackless/src ./configure make # su if your weren't root make install Then, install the Zope source, and make the same dance as usual. Just a note: Zope doesn't (yet) use any of the Stackless features. It just builds and works with it. But of course, *you* can use the stackless features, of course. I also expect, that Zope will create a branch in some future and implement a new Medusa which doesn't need real threads. cheers and let me know of your experience -- chris -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 mobile +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From ryanlowe0 at msn.com Mon Aug 25 22:27:33 2003 From: ryanlowe0 at msn.com (Ryan Lowe) Date: Tue, 26 Aug 2003 02:27:33 GMT Subject: python gripes survey References: Message-ID: wrote in message news:mailman.1061851794.28843.python-list at python.org... > > ... are there more > > complicated uses of code blocks that would make them more > > powerful than python's generators? > > > > Generators yielding to other generators, to form a > quasi-cooperative-multitasking environ seems quite > powerful to me. > not that i have any clue what you just said, but is this possible in python? or only in code-block languages? From mis6 at pitt.edu Sun Aug 24 05:31:32 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 24 Aug 2003 02:31:32 -0700 Subject: For Kenny Tilton: Why do I need macros revisited. References: <3f45484f$1_6@corp.newsgroups.com> <3F45A7BF.4060806@nyc.rr.com> <2259b0e2.0308222333.16ad345d@posting.google.com> <3F47BDCA.3070001@nyc.rr.com> Message-ID: <2259b0e2.0308240131.8bb4c17@posting.google.com> Kenny Tilton wrote in message news:<3F47BDCA.3070001 at nyc.rr.com>... > A few months back I started on a PyCells project, and of course was > having great fun down at the metaclass level. It was a little daunting > compared to the Lisp MOP, which just takes the same concepts of calls > and instance and does a conceptual-shift-up (new machine language > instruction?) so a class is now an instance (of a metaclass, which is > just another class really--the "meta" is only to keep one's head > straight). Python might be viewed as easier because it jumps over to > using internals such as that __dict__ thing (sorry if that is wrong, it > has been a while and I only played for a few weeks), so it there is none > of that class-being-an-instance confusion. Fun stuff, either way. I don't follow you. In Python it is just the same, a class is just an instance of a metaclass, a metaclass is just an instance of a meta-meta class, etc. Metaclasses are classes, their simply have a different type.__new__ method than object.__new__ so the instantiation syntax looks a bit different. > The CLOS MOP is a better playground, but Python has > a clear win in that there is only one Python. If I really need the MOP > for a project, I just pick a CL which exposes it. If I want to deliver a > package any lispnik can use, I better not use the MOP. Hear, hear, people who say CL is more standard than Python! > (How do you like that? > Multiple inheritance of metaclasses! ) I need more multiple inheritance for metaclasses than for classes. You maybe interested in this recipe of mine: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/204197 > Even if CLOS metaclasses were standard, kind of in the spirit of some of > this thread, I think I would like to avoid doing Cells by tinkering with > the object model. A hack that kinda disappears at run time (the macros > expand into vanilla CL) is probably going to play better with other > hacks, including not breaking optimizations. ANd it may be a Message > From God(tm) that Cells internals got simpler when I ripped out the > metaclass thing. > As always, the most abstract solution is not necessarely the best solution. Michele Simionato, Ph. D. MicheleSimionato at libero.it http://www.phyast.pitt.edu/~micheles --- Currently looking for a job --- From vgaliano at umh.es Mon Aug 4 06:23:13 2003 From: vgaliano at umh.es (Vicente Galiano) Date: Mon, 4 Aug 2003 12:23:13 +0200 Subject: SCALAPACK and PBLAS in Python Message-ID: <000601c35a72$690c4810$388893c1@umhxxxxxx> Hi everybody, I'm searching differents tools for Python programming using parallelism tools...., I've seen PyPar, PyMPI an d Scientific Python, but I'm lookingo for implementations in python of SCALAPACK, on the other hand,.... How can I implement PBLAS and SCALAPACK callings in python?? ,if I make a library in C, it's posibble run scalapack and the MPI proccess that?s runs under it... ... I'm very lost in that item, and I will gratefull with any idea and comment you can give,.... Thanks,.... ====================================================================== Vicente Galiano Ibarra | Universidad Miguel Hernandez | Dpto.Fisica y Arquitectura de Computadores ===================================================================== From tebeka at cs.bgu.ac.il Sun Aug 24 04:58:00 2003 From: tebeka at cs.bgu.ac.il (Miki Tebeka) Date: 24 Aug 2003 01:58:00 -0700 Subject: macro FAQ References: Message-ID: <33803989.0308240058.2878a349@posting.google.com> Hello Andrew, Great work! For a good reading about macros and why/how to use them you can point to Paul Graham's "On Lisp" which is freely available online at http://www.paulgraham.com/onlisptext.html He has great examples over there. My personal favorites are the anaphoric macros (aif ...) HTH. Miki From detlefsend at enovatia.com Mon Aug 4 14:59:14 2003 From: detlefsend at enovatia.com (David Detlefsen) Date: Mon, 04 Aug 2003 14:59:14 -0400 Subject: Freeze Question In-Reply-To: <16174.43083.667395.719317@montanaro.dyndns.org> Message-ID: On 8/4/03 2:39 PM, "Skip Montanaro" wrote: > > David> 'import site' failed; use -v for traceback > David> Traceback (most recent call last): > David> File "vnmrXserver.py", line 1, in ? > David> File "/usr/local/lib/python2.2/SocketServer.py", line 131, in ? > David> File "/usr/local/lib/python2.2/socket.py", line 41, in ? > David> ImportError: No module named _socket > > Is this during the freeze operation or while running the frozen app? This happens when I try to run the frozen application on a computer that doesn't have python. > Can you successfully execute > > import _socket I can indeed run it where I freeze it (both the .py script and the frozen application) and import _socket (of course) works fine. > > from the Python interpreter prompt? _socket.so should live in > > ${prefix}/lib/python2.3/lib-dynload > > David> So I guess I this means I have to rebuild python with static > David> linking (this is a mystery to me) OR is there a way to hack the > David> makefile (or perhaps some other file) and have the missing > David> modules found and included in the frozen program without a > David> rebuild of python? > > You can fairly easily (though a bit tediously) build a static Python > interpreter. You need to edit Modules/Setup to uncomment the various > extension modules you need. This is what we all used to do before Greg Ward > began attempting world domination through distutils. There should be some > documentation somewhere still about how to do this, perhaps in the > introductory comments in Modules/Setup itself. Yeah, looks like it's there. Wait...I thought it was my turn to dominate the world! And it's been a while since I've installed python on a SparcStation and indeed, I may have found the binaries somewhere...are there any good places that describe more explicitly how to build a static python? From mertz at gnosis.cx Thu Aug 21 21:10:12 2003 From: mertz at gnosis.cx (David Mertz, Ph.D.) Date: Thu, 21 Aug 2003 21:10:12 -0400 Subject: Reviewers for _Text Processing in Python_ Message-ID: <01WR/kKkXgsG092yn@gnosis.cx> In the couple months since it was printed, my book seems to have been selling fairly well. Not that I actually know concrete numbers, but I have looked at Amazon's "sales rank" -way- too often. However, I've been a bit disappointed not to see more reviews of the book appear. While it's possible I've missed something, all I've really seen is Ron Stephens very kind notice that appeared on slashdot, as well as other places. So I would be extremely pleased to get a free reviewer's copy into the hands of anyone likely to publish a review. By "publish", btw., I have a very liberal sense--obviously print is good, but anywhere on topical websites, mailing lists, etc. is good too. Anyone interested, please email me, and I'll let Addison Wesley know your shipping info--they seem quite happy to send out more free copies (btw. this need not be USA; since I don't need to ship them directly, I presume AW will send from local distributors). Of course, you won't get an inscribed/signed version, as the buyers of my (sold-out) author's copies did :-). Yours, David... -- X-Shameless-Plug: Buy Text Processing in Python: http://tinyurl.com/jskh From adalke at mindspring.com Fri Aug 1 19:00:05 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Fri, 1 Aug 2003 17:00:05 -0600 Subject: Wow: list of immediate subclasses? References: <7h3k79xaavf.fsf@pc150.maths.bris.ac.uk> <7h3fzklaa75.fsf@pc150.maths.bris.ac.uk> Message-ID: Michael Hudson: > >>> A.__dict__['__weakref__'].__objclass__ is A Ahhh... Andrew dalke at dalkescientific.com From rshaw2 at midsouth.rr.com Mon Aug 4 16:40:33 2003 From: rshaw2 at midsouth.rr.com (Richard) Date: 4 Aug 2003 13:40:33 -0700 Subject: Python2.3 tkFileDialog.askopenfilename returns tuple on Cancel References: Message-ID: <84e0f331.0308041240.6acfff8@posting.google.com> timothy.williams at nvl.army.mil (Tim Williams) wrote in message news:... > I just installed Python 2.3 on my Redhat system. When I tried to run > one of my programs that use tkFileDialog.askopenfilename(), I got an > error because it returns a tuple instead of a null string when I > select Cancel. > > Python 2.2: > > Python 2.2.2 (#3, Jan 21 2003, 08:39:06) > [GCC 2.95.3 20010315 (release)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import tkFileDialog > >>> f=tkFileDialog.askopenfilename() > >>> print f > > >>> f > '' > >>> type(f) > > > > Python 2.3: > > Python 2.3 (#1, Aug 4 2003, 10:43:11) > [GCC 3.2 20020903 (Red Hat Linux 8.0 3.2-7)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import tkFileDialog > >>> f=tkFileDialog.askopenfilename() > >>> f > () > >>> type(f) > > > Both versions return a string when I select an actual file. Sometimes > I want to click 'Cancel' when I want to bring up my GUI anyway and > select the file later. > > I got around this by just putting in an > > if not filename: filename='.' > > after my call to askopenfilename(). > > Is this a bug or a feature? > > Thanks. I tried this under Windows 2000 and got a 'str' either way. Richard From scottholmes at sbcglobal.net Mon Aug 4 20:13:40 2003 From: scottholmes at sbcglobal.net (Scott Holmes) Date: Mon, 04 Aug 2003 17:13:40 -0700 Subject: How to determine row position in a list box Message-ID: <3F2EF6B4.3010102@sbcglobal.net> I've been trying to understand nearest(y) but I'm not getting it. I have a ScrolledListBox with a list of people's names. I also have a parallel list of the unique people numbers used in the PostgreSQL database. When a name is selected from the scrolled list, I need to determine the index value and then find the corresponding people number. def selectionCommand(self): sels = self.box.getcurselection() if len(sels) == 0: print 'No selection' else: print 'Selection:', sels[0] print self.nmbr_list[self.box[0].nearest(y)] self.lkupTopLevel.withdraw() Where do I obtain the value y used in nearest(y)? -- --------------------------------------------------------------------- Scott Holmes http://sholmes.ws http://pages.sbcglobal.net/scottholmes scottholmes at sbcglobal.net Independent Programmer/Analyst Passport 4GL PHP HTML Composer PostgreSQL Informix 4GL, SQL --------------------------------------------------------------------- There are more things in heaven and earth, Horatio, than are dreamt of in your philosophy --------------------------------------------------------------------- From Spam.Buster at web.de Wed Aug 20 12:45:05 2003 From: Spam.Buster at web.de (Lars Behrens) Date: Wed, 20 Aug 2003 18:45:05 +0200 Subject: 'name is too long' (tarfile, python 2.2, Debian Woody) In-Reply-To: <3F43306D.3080704@skynet.be> References: <3F43306D.3080704@skynet.be> Message-ID: Helmut Jarausch wrote: > The standard tar format allows only names (i.e. complete path) of 100 > characters. So in your '/home/lars' are names (fully expanded) which are > longer. > Please have a look at the documentation of tarfile, there is an option > to store extended path names. Most other tar programs (like gnu-tar) > support these, as well. Thanks! I found this in the tarfile doc: -- snip -- posix=True If True, create a POSIX 1003.1-1990 compliant archive. GNU extensions are not used, because they are not part of the POSIX standard. This limits the length of filenames to at most 256 and linknames to 100 characters. A ValueError is raised, if a pathname exceeds this limit. If False, create a GNU tar compatible archive. It will not be POSIX compliant, but can store pathnames of unlimited length. -- snap -- So, I put this in my script: tar.posix=True before tar.add('bla') This seems to work. But honestly, I don't quite understand what I did :-\ I also found out, that I can call tarfile.GNUTYPE_LONGNAME but what can I do with it or how do I use it? Any hints for me? TIA Lars From siegfried.gonzi at kfunigraz.ac.at Sun Aug 3 18:40:11 2003 From: siegfried.gonzi at kfunigraz.ac.at (Siegfried Gonzi) Date: 3 Aug 2003 22:40:11 GMT Subject: Python speed vs csharp References: <1h5f2rzthqgid.8watonaa4cjt.dlg@40tude.net> Message-ID: <3F551D29.1040407@kfunigraz.ac.at> Mike wrote: > Ugh. Because I can't be trusted with a calculator, that's why. 1.5 billion > should be 150 million. The elapsed times are correct: 210 seconds and 3500 > seconds. I cannot see your original message except on google: Hi: I am sure you know what you are after, but Python for numerical computations is more or less crap. Not only has Python a crippled syntax it is most of the time dog slow and unpredictable. Python is more or less a fraud. But I must admit it is sometimes immensly useful due to its big pool of add-on libraries. But I would rather like to see that all the manpower gets concentrated in languages which deserve to be called a programming language (for example Scheme, CommonLisp, Ada, C++,..). I am not sure what exactly are your simulation problems and requirements but the Bigloo (Scheme) compiler is very robust and I use it every day for numerical computations. I once used Python but quickly stopped using it and I have never looked back. For example Bigloo lets you specify types. It is easy to specify types in Bigloo and the code is transportable even, provided you write a small macro where the compiler decides wheter it is Bigloo or not. Normally, giving types in Bigloo puts you in the range of "only 2 times slower than C"; also for heavy numerical computations. The following small Scheme program sums up your error function 10^6 times. Also included a C program. The timings on a simple Celeron laptop are as follows: g++ -O3 erf.c : 0.5 seconds bigloo -Obench erf.scm: 1.1 seconds The Bigloo code could be a bit improved because I do not know wheter using (expn x 2.0) introduces a bottleneck in Bigloo. If there are only floating point calculations involved Bigloo is as fast as C (see comp.lang.scheme and my code for the Coyote Gulch benchmark; see also slashdot). If you have big arrays Bigloo's gap to C is shifted towards a factor of 2 or in hard cases 3. This is still fairly good. Not to cheerlead Bigloo or Scheme here. If you are pragmatic stay with Python it has really tons of add-on libraries and huge community. S. Gonzi ;;;;;;;;;;;;;;;;; BIGLOO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (module erfc2 (option (set! *genericity* #f))) (define (erfc x ) (let* ((x (exact->inexact x)) (p 0.3275911) (a1 0.254829592) (a2 -0.284496736) (a3 1.421413741) (a4 -1.453152027) (a5 1.061405429) (t (/fl 1.0 (+fl 1.0 (*fl p x)))) (erfcx (*fl (*fl t (+fl a1 (*fl t (+fl a2 (*fl t (+fl a3 (*fl t (+fl a4 (*fl t a5))))))))) (exp (- (expt x 2.0)))))) erfcx)) (define (do-it) (let ((erg 0.0)) (do ((i 0 (+fx i 1))) ((=fx i 1000000)) (set! erg (+fl erg (erfc 0.456)))) erg)) (print (do-it)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; C ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; #include #include double erfc( double x ) { double p, a1, a2, a3, a4, a5; double t, erfcx; p = 0.3275911; a1 = 0.254829592; a2 = -0.284496736; a3 = 1.421413741; a4 = -1.453152027; a5 = 1.061405429; t = 1.0 / (1.0 + p*x); erfcx = ( (a1 + (a2 + (a3 + (a4 + a5*t)*t)*t)*t)*t ) * exp(-pow(x,2.0)); return erfcx; } int main() { double erg=0.0; int i; for(i=0; i<1000000; i++) { erg += erfc(0.456); } printf("%f",erg); return 1; } ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; From vze4rx4y at verizon.net Sun Aug 31 18:12:59 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Sun, 31 Aug 2003 22:12:59 GMT Subject: can generators be nested? References: Message-ID: "Michael Sparks" wrote in message news:mailman.1062072254.6205.python-list at python.org... > Hi, > > > Unfortunately there isn't a way of doing this - the reason is that the act > of including the yield keyword in a function/method definition turns the > function/method definition into a generator definition. > > The way you're doing it now: > > for i in gen2(): yield i > > Is the only way of doing it. > > I asked essentially the same question almost a year ago - I was concerned > about the fragility of nesting yields. > > The fact you can't do this influenced certain aspects on the design of a > system I'm working on for work - largely to shield users of my classes > from the problem. > > The original thread where I asked the question is here: > * http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&threadm=alqehl%249qv%241%40nntp0.reith.bbc.co.uk&rnum=9&prev=/&frame=on If you would like to have a 'yield every', a good first step is to file a feature request at sourceforge. For the truly determined, writing a PEP is the surest path to complete issue discussion followed by a BDFL pronouncement. Raymond Hettinger From neil.padgen at mon.bbc.co.uk Thu Aug 21 10:22:01 2003 From: neil.padgen at mon.bbc.co.uk (Neil Padgen) Date: Thu, 21 Aug 2003 14:22:01 +0000 Subject: how fast is Python? References: <3f43e5cf$0$49115$e4fe514c@news.xs4all.nl> Message-ID: On Wednesday 20 August 2003 21:19, Irmen de Jong wrote: > Investigate Psyco. On the strength of this thread, I investigated Psyco. Results of a very quick investigation with the following program: ----------------------------------------- def calcPi(iterations): pi4 = 1.0 for i in xrange(1, iterations): denominator = (4*i)-1 pi4 = pi4 - 1.0/denominator + 1.0/(denominator+2) return pi4 * 4.0 def timethis(func, funcName): import sys try: i = int(sys.argv[1]) except: i = 1000000 import time start = time.time() pi = func(i) end = time.time() print "%s calculated pi as %s in %s seconds" % (funcName, pi, end - start) def main(): timethis(calcPi, 'calcPi') timethis(speedyPi, 'speedyPi') import psyco speedyPi = psyco.proxy(calcPi) if __name__ == '__main__': main() ----------------------------------------- produced the following results on a 1.7GHz P4 running FreeBSD 4.8: > python2.2 pi.py calcPi calculated pi as 3.14159315359 in 3.87623202801 seconds speedyPi calculated pi as 3.14159315359 in 0.790405035019 seconds -- Neil From nav+posts at bandersnatch.org Tue Aug 19 15:04:36 2003 From: nav+posts at bandersnatch.org (Nick Vargish) Date: 19 Aug 2003 15:04:36 -0400 Subject: An advertising message from a Microsoft agent References: <3F403078.3010006@sympatico.ca> Message-ID: Skip Montanaro writes: > I don't know. I've never experienced a toilet that produced anything under > normal circumstances. Where I live, toilets are generally consumers. Generally, indeed. That sort of depends on your plumbing infrastructure, which in the case of Visual Studio would be win32... Which leads me to conclude that VS may be the productive sort of lavatory. Nick -- # sigmask || 0.2 || 20030107 || public domain || feed this to a python print reduce(lambda x,y:x+chr(ord(y)-1),' Ojdl!Wbshjti!=obwAcboefstobudi/psh?') From nospam at maniacxs.de Wed Aug 13 17:07:28 2003 From: nospam at maniacxs.de (Lukas Kasprowicz) Date: Wed, 13 Aug 2003 23:07:28 +0200 Subject: German umlaut in a string. References: Message-ID: I tried: # _*_ coding: latin1 _*_ but this doesn?t work too. From alessandro at sephiroth.it Thu Aug 7 09:25:47 2003 From: alessandro at sephiroth.it (Alessandro Crugnola *sephiroth*) Date: Thu, 07 Aug 2003 13:25:47 GMT Subject: py2exe problems Message-ID: Hi, i'm trying to compile a .py script using py2exe into a win .exe file. In that script i'm using xml.dom.minidom to parse an xml file (with the iso8859-1 encoding) i've included in the setup command line the --packages encodings but once i launch the exe file i receive this error in the console window: Traceback (most recent call last): File "", line 51, in Notify File "", line 105, in __init__ File "WindowsSnippets.pyc", line 27, in __init__ File "WindowsSnippets.pyc", line 135, in loadXML File "xml\dom\minidom.pyc", line 1915, in parse File "xml\dom\expatbuilder.pyc", line 924, in parse File "xml\dom\expatbuilder.pyc", line 207, in parseFile LookupError: no codec search functions registered: can't find encoding how can i solve the issue? Mayn thanks -- Alessandro Crugnola From abcdebl2nonspammy at verizon.net Sat Aug 23 22:12:13 2003 From: abcdebl2nonspammy at verizon.net (David Lees) Date: Sun, 24 Aug 2003 02:12:13 GMT Subject: Indentation question In-Reply-To: References: Message-ID: <1aV1b.9190$vy5.3133@nwrddc01.gnilink.net> Christos TZOTZIOY Georgiou wrote: > On Sat, 23 Aug 2003 05:50:25 GMT, rumours say that Geoff Howland > might have written: > > [David Lees asks how to indent and unindent a group of lines in his > code, referring to PythonWin and EditPadLight] > > >>A lot of editors use the method of: >> >>1. Select lines of text >>2. Press TAB or SHIFT+TAB to change indentation out or in >>respectively. > > >>I dont know about those editors though. > > > This works for PythonWin, I don't know for EditPadLite. In IDLE (in > windows at least), the keypresses are ^[ and ^] for unindenting and > indenting, respectively; check the Edit menu for the actual shortcuts. I just tried it in EditPad and PythonWin. It works in both. Thanks guys, this is real handy to know. David Lees From pinard at iro.umontreal.ca Sat Aug 9 11:55:03 2003 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois_Pinard?=) Date: 09 Aug 2003 11:55:03 -0400 Subject: passing multiple strings to string.find() In-Reply-To: References: <3F331A9B.9020907@vt.edu> Message-ID: [Fredrik Lundh] > Francois Pinard wrote: > > Given the above, > > > > build_regexp(['this', 'that', 'the-other']) > > > > yields the string 'th(?:is|at|e\\-other)', which one may choose to > > `re.compile' before use. > the SRE compiler looks for common prefixes, so "th(?:is|at|e\\-other)" is > no different from "this|that|the-other" on the engine level. Thanks for the note. So the `build_regexp' function is not useful after all. It was indirectly written around a speed problem in the GNU regexp engine, but seemingly, the Python regexp engine knows better already. As I wrote earlier, I first saw Emacs Lisp `regexp-opt' used within `enscript'. A speed comparison between both methods shows that they are fairly equivalent. A small difference is that `build_regexp', given that one of the word is a prefix of another, automatically recognises the longest one, while a naive regexp of '|'.join(words) recognises whatever happens to be listed first. Of course, this is easily solved by sorting, then reversing the word list before producing the naive regexp. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From pobrien at orbtech.com Thu Aug 28 20:38:50 2003 From: pobrien at orbtech.com (Patrick K. O'Brien) Date: 28 Aug 2003 19:38:50 -0500 Subject: Object Database (ODBMS) for Python In-Reply-To: <1DAECE9E8F34E04AA0E5699AF7D9FF090708D440@stpmsg00.corp.fairisaac.com> References: <1DAECE9E8F34E04AA0E5699AF7D9FF090708D440@stpmsg00.corp.fairisaac.com> Message-ID: "Pettersen, Bjorn S" writes: > > From: Patrick K. O'Brien [mailto:pobrien at orbtech.com] > > > > I'm working on an ODBMS written in Python, for Python, and was > > wondering if anyone was interested. In particular, I'd like to know > > what features would be useful, and what types of use cases people > > would have for a simple, but feature-rich object database. > > > > The system that I'm developing is PyPerSyst, which began as a simple > > persistence mechanism, but is now becoming a complete ODBMS. Some > > details are available here: > > > > http://www.orbtech.com/wiki/PyPerSyst > > > > The code is available in CVS on SF: > > > > http://sourceforge.net/projects/pypersyst/ > > I'd be interested, but can't seem to find docs, demos or tests through > sf's web interface.. any pointers? First of all, let me just make a caveat that this is still in the early stages of development. By that I mean that many features are coded, and there are a good many unit tests, but I haven't got much in the way of docs and demos. PyPerSyst is being used in a commercial application, so it does work quite well. But in no way am I advertising it as a finished product. I'm just looking for feedback from early adopters and developers with an interest. The main pypersyst package is here: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/pypersyst/pypersyst/pypersyst/ The unit tests are here: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/pypersyst/pypersyst/pypersyst/test/ I'm working on a simple demo (twistedcred), but haven't committed it to cvs yet. In the mean time, here is what the database portion of an application looks like: import os from pypersyst.database import Database from pypersyst.engine.engine import Engine from pypersyst.storage.storage import Storage from twistedcred import data from twistedcred.schema import cred def database(): """Return a PyPerSyst database.""" dir = os.path.dirname(data.__file__) app = '.twistedcred' storage = Storage(dir, app, binary=False, python=True) engine = Engine(storage, cred.Root) database = Database(engine) return database --- And here is the schema for the twistedcred database: from pypersyst import root from pypersyst.entity.entity import Entity class Avatar(Entity): """Avatar class.""" _attrSpec = [ 'realm', 'user', 'name', ] _altkeySpec = [ ('user', 'realm', 'name',), ] def __init__(self, user, realm, name='Avatar'): """Create Avatar instance.""" self._prep(locals()) Entity.__init__(self) class Realm(Entity): """Realm class.""" _attrSpec = [ 'name', ] _altkeySpec = [ ('name',), ] def __init__(self, name): """Create Realm instance.""" self._prep(locals()) Entity.__init__(self) class User(Entity): """User class.""" _attrSpec = [ 'name', 'hashedPassword', ] _altkeySpec = [ ('name',), ] def __init__(self, name, hashedPassword=None): """Create User instance.""" self._prep(locals()) Entity.__init__(self) class Root(root.Root): """Root class.""" _EntityClasses = [ Avatar, Realm, User, ] You can create the database using PyCrust, for example, and interact with it like this: >>> from twistedcred.database import database >>> db = database.database() >>> from pypersyst.entity import transaction as tx >>> t = tx.Create('User', name='Bob') >>> u1 = db.execute(t) >>> u1.name 'Bob' >>> t = tx.Create('Realm', name='Whatever') >>> r1 = db.execute(t) >>> t = tx.Create('Avatar', name='MyAvatar', user=u1, realm=r1) >>> a1 = db.execute(t) >>> a1.user.name 'Bob' >>> t = tx.Create('User', name='Bob') >>> u = db.execute(t) Traceback (most recent call last): File "", line 1, in ? File "/home/pobrien/Code/pypersyst/database.py", line 27, in execute return self._engine.execute(transaction) File "/home/pobrien/Code/pypersyst/engine/engine.py", line 75, in execute return transaction.execute(self._root) File "/home/pobrien/Code/pypersyst/entity/transaction.py", line 31, in execute return self.EntityClass(**self.attrs) File "/home/pobrien/Code/twistedcred/schema/cred.py", line 65, in __init__ Entity.__init__(self) File "/home/pobrien/Code/pypersyst/entity/entity.py", line 81, in __init__ self.extent._insert(self) File "/home/pobrien/Code/pypersyst/entity/extent.py", line 213, in _insert self._validate(instance, instance._attrs()) File "/home/pobrien/Code/pypersyst/entity/extent.py", line 325, in _validate self._validatekeys(instance, attrs) File "/home/pobrien/Code/pypersyst/entity/extent.py", line 335, in _validatekeys raise KeyError, msg KeyError: duplicate value ('Bob',) for altkey ('name',) >>> u1.links {('Avatar', 'user'): []} >>> r1.links {('Avatar', 'realm'): []} >>> db.root['Avatar'].match(name='Ava') [] >>> db.root['Avatar'].search(name='Ava') [] >>> I hope that helps demonstrate some of what it can do. -- Patrick K. O'Brien Orbtech http://www.orbtech.com/web/pobrien ----------------------------------------------- "Your source for Python programming expertise." ----------------------------------------------- From hokiegal99 at hotmail.com Sun Aug 17 16:35:23 2003 From: hokiegal99 at hotmail.com (hokiegal99) Date: 17 Aug 2003 13:35:23 -0700 Subject: Path Problem on W2K? References: <93f5c5e9.0308170927.6e0bdc38@posting.google.com> Message-ID: <93f5c5e9.0308171235.61079bb6@posting.google.com> "Dennis Reinhardt" wrote in message news:... > > C:\>python 'name-of-script.py' > > 'python' is not recognized as an internal or external command, > > operable program or batch file. > > Try python.exe instead of python as the command. same result: C:\>python.exe property.py 'python.exe' is not recognized as an internal or external command, operable program or batch file. From panbru at comcast.net Thu Aug 28 20:40:41 2003 From: panbru at comcast.net (N.E. Daynow) Date: Thu, 28 Aug 2003 18:40:41 -0600 Subject: Garbage Collection Question In-Reply-To: References: <2ce55ce2.0308281518.4be94efc@posting.google.com> Message-ID: <3F4EA109.2040103@comcast.net> Aahz wrote: > In article <2ce55ce2.0308281518.4be94efc at posting.google.com>, > Chaman Singh Verma wrote: > >>I am trying to integrate C++ with Python. I read that Python does >>automatic garbage collection. I am creating new objects in C++ and >>passing to Python, I don't know now who should control deleting the >>objects. If I create objects in C++ do I have to clean them or Python >>will use GC to remove unwanted objects. > > > Depends whether it's a Python object created with a Python API call. If > not, your objects will never be touched by Python. If your C++ object is represented in Python land by a Python opaque pointer (a/k/a a CObject), you can designate a destructor that will be called when your CObject's reference count reaches zero. You'll need to create a destructor function of the proper form to pass to the CObject creation function: PyObject* PyCObject_FromVoidPtr(void* cobj, void (*destr)(void *)) Note that "cobj" is a pointer to your C++ object and "destr" is your destructor function which will simply delete the C++ object. You can get a void pointer to your C++ object back from Python land with: void* PyCObject_AsVoidPtr(PyObject* self) Good luck, Tim From vanevery at 3DProgrammer.com Sun Aug 17 12:52:08 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Sun, 17 Aug 2003 09:52:08 -0700 Subject: simple text parser? References: Message-ID: Alex Martelli wrote: > > Developing a program under each of two platforms you previously didn't > know is no doubt a good way to compare several characteristics of > those platforms. Out of curiosity -- are you relying on Usenet help, > rather than a manual, for the C# version, too? Not exactly. I have 2 books on C#, but they don't talk about parsing except via XML. At some point I will ask about C# parsers, but probably not until I get stuck on the Python way of doing things. Cheers, Brandon From bokr at oz.net Sun Aug 10 20:09:42 2003 From: bokr at oz.net (Bengt Richter) Date: 11 Aug 2003 00:09:42 GMT Subject: unescaping xml escape codes References: <3F367C1E.FAE188C1@yahoo.com> Message-ID: On Sun, 10 Aug 2003 10:08:46 -0700, Daniel wrote: >I'm working with strings that contain xml escape codes, such as '0' >and need a way in python to unescape these back to their ascii >representation, such as '&' but can't seem to find a python method for >this. I tried xml.sax.saxutils.unescape(s), but while it works with >'&', it doesn't work with '0' and other numeric codes. Any >suggestions on how to decode the numeric xml escape codes such as this? >Thanks. > Maybe just a regex sub function would do it for you? Do you just need the decimal forms like above or also the hex? If your coded entities are � to ÿ or &x00; to &xff; this might work. Other entities are converted to '?'. If you want to do this properly, I think you have to parse the html a little and see what the encoding is, and convert to unicode, and then do the conversions. Very little tested!! ====< cvthtmlent.py >====================================== import re rxo =re.compile(r'\&\#(x?[0-9a-fA-F]+);') def ent2chr(m): code = m.group(1) if code.isdigit(): code = int(code) else: code = int(code[1:], 16) if code<256: return chr(code) else: return '?' #XXX unichr(code).encode('utf-16le') ?? def cvthtmlent(s): return rxo.sub(ent2chr, s) if __name__ == '__main__': import sys; args = sys.argv[1:] if args: arg = args.pop(0) if arg == '-test': print cvthtmlent( 'blah [0] blah [ö] blah [123] ω') else: if arg == '-': fi = sys.stdin else: fi = file(arg) for line in fi: sys.stdout.write(cvthtmlent(line)) =========================================================== If you run this in idle, you can see the umlaut, but not the omega, which becomes a '?' Martin can tell you the real scoop ;-) >>> from cvthtmlent import cvthtmlent as cvt >>> print cvt('blah [0] blah [ö] blah [123] ω') blah [0] blah [?] blah [123] ? Regards, Bengt Richter From peter at engcorp.com Mon Aug 25 13:25:50 2003 From: peter at engcorp.com (Peter Hansen) Date: Mon, 25 Aug 2003 13:25:50 -0400 Subject: Help embedding python References: Message-ID: <3F4A469E.58B94F7C@engcorp.com> Zora Honey wrote: > > My husband and I are writing a program that does a lot of math behind > the scenes (c++) with a gui front (python/Tkinter). We've decided that > we want the c++ to be the "driver", and so we want to embed the python. It's a little unclear (to me) exactly what you're trying to do, but in any case I can't imagine why you'd want to have C++ "drive" the Python code (if that's what you meant by "driver", as opposed to the more common sense as in "device driver") instead of the other way around. And my inability to imagine why you want this is compounded by your choice of Python and Tkinter for the front end. It is much more common to have the front end be the "driving" code, and the back end be "driven", especially in CPU-intensive applications as it sounds like you have here. -Peter From wim_wauters at skynet.be Mon Aug 25 16:04:10 2003 From: wim_wauters at skynet.be (WIWA) Date: 25 Aug 2003 13:04:10 -0700 Subject: Problem with lists Message-ID: <538fc8e.0308251204.1049e4f9@posting.google.com> Hi, I'm writing an application to analyse my Apache access_log file. In the below script (which is based on an example I found in 'How to think as a Programmer'-) I want to measure the amount of hits per hour. I know it is not the best algorithm but it works for now. I see some strange things: on rather small (it must be +/- < 4000 ) entries in the access_log, my script works fine. Above this limit, I get the following error. Traceback (most recent call last): File "hits_per_uur.py", line 18, in lijst.append(int(datum[1])) IndexError: list index out of range Question: do lists have a limit? Anyone know how I can change this simple script so that it works for more entries as well. ------------------------------------------------------------------------------ import sys,string def inbucket(lijst, low, high): count=0 for num in lijst: if low<=num Message-ID: On 11 Aug 2003 00:09:42 GMT, bokr at oz.net (Bengt Richter) wrote: [...] >> >Maybe just a regex sub function would do it for you? Do you just need the decimal >forms like above or also the hex? If your coded entities are � to ÿ or >&x00; to &xff; this might work. Other entities are converted to '?'. That should be � and ÿ respectively. I did implement hex entites after all. Botched reediting this commentary however ;-P Regards, Bengt Richter From bokr at oz.net Sat Aug 2 19:32:44 2003 From: bokr at oz.net (Bengt Richter) Date: 2 Aug 2003 23:32:44 GMT Subject: How do I get a reference to a KEY value of a dictionary? References: <645db655.0307311636.71923378@posting.google.com> Message-ID: On 2 Aug 2003 10:16:13 -0400, aahz at pythoncraft.com (Aahz) wrote: >In article , >Andy C wrote: >> >>I don't see how I can do this and let me eliminate duplicates. I need >>to assign the old duplicate string to the unique string that already >>exists. Hence the question, how do I get a reference to the KEY value? >>I know I can use keys() and do a linear search, but that is much more >>inefficient. I would like to get a reference to the key value in the >>same time that it takes to do a hash lookup (constant time). > >Ahhhh.... Right. Hmmmmm.... You're correct, you do >need to set the value to the key. I think using a dict is better than >using intern(). Here's an optimization: > > node2 = node_cache.setdefault(node2, node2) I would sure be more comfortable with a change in nomenclature, e.g., node2name = node_name_cache.setdefault(node2name, node2name) so that it is clear that you are dealing with name strings, not typical graph vertex/node objects. BTW, reading from a file, you can probably not in general avoid forward references, (i.e., names of adjacent nodes yet to be defined), but they should be resolvable at the end, so you could make nodes that refer to adjacent nodes directly instead of by name. Nodes would carry a ref to their own (string) name, and go by that same name string in a graph dict, so there should be no duplication of strings, just references to them. E.g., (I started to just sketch something, and ... well, it's hard to stop programming Python before something is running at least preliminarily ;-) I subclassed dict to keep nodes in by name. ====< graph.py >========================================================= def boxit(s): lines = s.splitlines() wid = max(map(len,lines)) ret = ['+-%s-+' % ('-'*wid)] fmt = '| %%-%ds |'%wid for line in lines: ret.append(fmt%line) ret.append(ret[0]) return '\n'.join(ret) def errep(Ex, *rest): if __debug__: print boxit('%s: %s'%(Ex.__name__, rest and rest[0])) # and blunder on else: raise Ex(*rest) class Node(object): __slots__ = 'name', 'adj_list' def __init__(self, name): self.name = name self.adj_list = None # signify undefined, vs [] for no adjacent nodes class Graph(dict): def load(self, infile, print_lines=False): for line in infile: if print_lines: print line.rstrip() sline = line.strip() if not sline or sline.startswith('#'): continue node_def_names = line.split() # assume line like 'nodename adj_node1_name adj_node2_name ...' node_name = node_def_names[0] if node_name in self: # don't allow re-definition errep(ValueError, 'Node %r being re-defined:\n new adj: %r\n old adj: %r' %( node_name, node_def_names[1:], self[node_name].adj_list)) else: self[node_name] = Node(node_name) # set adj list, making making this a defined node self[node_name].adj_list = node_def_names[1:] # change adj lists to direct references to adjacent nodes for node in self.values(): adj_list = node.adj_list assert adj_list is not None for i in xrange(len(adj_list)): adj_name = adj_list[i] try: adj_list[i] = self[adj_name] except KeyError: errep( ValueError, 'node %r refers to undefined adj node %r' % (node.name, adj_name)) # continuing if debugging adj_list[i] = Node(adj_name) # adj_list None (vs []) signifies undefined def show(self): node_names = self.keys() node_names.sort() visited = {} ret = [] def prtree(node, indent=0): if node.name in visited: if indent: ret.append('%s%s (see previous)'%(indent*' ',node.name)) else: visited[node.name]=True if node.adj_list is None: ret.append('%s%s (undefined) '%(indent*' ',node.name)) return ret.append('%s%s'%(indent*' ',node.name)) for adj in node.adj_list: prtree(adj, indent+1) for node_name in node_names: prtree(self[node_name]) ret.append('') return '\n'.join(ret) def test(filepath=''): graph = Graph() # name-string -> Node instance if not filepath: import StringIO f_graph = StringIO.StringIO(""" A B C D B E F C G H G A D B E F H D E F X E Y """) else: f_graph = file(filepath) print 'Loading graph from %s ...\n--' % (filepath or '(test)') graph.load(f_graph, True) # print the lines read print '--' f_graph.close() print graph.show() if __name__ == '__main__': import sys args = sys.argv[1:] test(args and args[0] or '') ========================================================================= Result: [16:33] C:\pywk\clp\pp>graph.py Loading graph from (test) ... -- A B C D B E F C G H G A D B E F H D E F +----------------------------------------+ | ValueError: Node 'D' being re-defined: | | new adj: ['E', 'F'] | | old adj: ['B'] | +----------------------------------------+ X E Y +-------------------------------------------------------+ | ValueError: node 'X' refers to undefined adj node 'Y' | +-------------------------------------------------------+ -- A B E F C G A (see previous) H D B (see previous) X E (see previous) Y (undefined) (Not tested beyond what you see. NTBWYS? ;-) Regards, Bengt Richter From a.schmolck at gmx.net Mon Aug 18 18:40:58 2003 From: a.schmolck at gmx.net (Alexander Schmolck) Date: 18 Aug 2003 23:40:58 +0100 Subject: What's better about Ruby than Python? References: Message-ID: Alex Martelli writes: > Alexander Schmolck wrote: > ... > > I recall the following, roughly in order of importance (treat with > > caution, it's some time that I looked at Ruby): > > > > 0. I it's possible to redefine classes at runtime without going bonkers > > (instances automatically get updated to the new class definitions). > > This is generally feasible in Python, too -- but not with built-in types > (e.g., you can't redefine what "+" means on integers, while in Ruby you > could). I don't care about redefining built-in types, I *do* care about redefining the behavior of all instances of a class automatically, rather than by hand and only for some cases (like classes without those damned __slots__). > > This, I think is by far python's greatest flaw, amongst other things it > > greatly compromises its interactiveness, which is a key virtue. If > > someone can explain to me how I'm wrong on this and python's behavior > > really is sane, I'll be eternally grateful. > > I don't think I understand what you're saying. For example: > > >>> class X: > ... def amethod(self): return 'just a method' > ... > >>> x=X() > >>> x.amethod() > 'just a method' > >>> def abettermethod(self): return 'ah, now THIS is better!' > ... > >>> X.amethod = abettermethod > >>> x.amethod() > 'ah, now THIS is better!' > >>> I want something like: >>> class X: ... def amethod(self): return 'just a method' ... >>> x=X() >>> class X: ... def amethod(self): return 'ah, now THIS is better!' ... >>> x.amethod() 'ah, now THIS is better!' But of course what currently happens is: 'just a method' cf.: irb(main):001:0> class X irb(main):002:1> def amethod irb(main):003:2> puts "just a method" irb(main):004:2> end irb(main):005:1> end nil irb(main):006:0> x = new X irb(main):021:0> class X irb(main):022:1> def amethod irb(main):023:2> puts "Ah, this is better." irb(main):024:2> end irb(main):025:1> end nil irb(main):026:0> x.amethod Ah, this is better. nil Does it make sense now? I say "something like" because I could also live with something like ``sys.update_all_instances_of(X)``. What I can't live with is the (according to my current understanding) entirely brain-dead ``x.__class__ = X`` for every `x` I can lay my hands on, with quite a bit of labour (and which furthermore tends to break pickling etc). I guess I must be overlooking something here, because to me it seems entirely obvious that there should be a straightforward mechanism for updating all instances of a class when the class is redefined. Since I know of no such mechanism and python's current semantics seem pretty moronic to me, I'm sure I must be missing something (python has an amazingly low rate of "obviously stupid" design decisions, that still strike you as stupid after you understood their rationale). So it's maybe about time someone put me straight. The fact that you can't easily update your instances (after all first you gotta find then and secondly, as mentioned above even if you do you might run into trouble) isn't that much of a problem if your progam takes about 5 seconds to run. If it takes 48 hours and you notice that you need to change a method definition after you've got almost all the results in, you're in for quite a bit of fun (or at least I have been, possibly due to ignorance). I think this sucks pretty badly, even more so than the fact that I don't know of a decent way to fix things if an exception occurs somehwere (again imagine in the second to last line, after 48h of computations; this is not hypothetical, as I'm sure you as an ex-Fortran (and hence I'd guess numerics) programmer will appreciate). Maybe you can pickle some things if you are careful and do an immedidate postmortem with pdb, without making a silly typo first that will raise another exception and cost you all the previous exception state you desperately needed, but this is really far from ideal. > Isn't this "redefining classes at runtime // instances automatically > get updated", too? If you want to redefine a bunch of entries in X, > rather than just a few, X.__dict__.update(someotherdict) -- or even, > shudder, reassigning X.__dict__ altogether... -- may perhaps be > preferable, but I personally like the explicitness of assignments > for most cases of such (rare) tasks. This isn't a rare task at all. At least it wouldn't be if python had these instance updating semantics and people used python in a vaguely intelligent fashion (viz. interactively), because then it would happen countless times a working day (and the reason I put that in the conditional is that I suspect many might be hampered by bad habits formed with brain-dead run-compile-debug-edit languages a la Java, C and C++). 'as From tjreedy at udel.edu Wed Aug 13 02:42:35 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 13 Aug 2003 02:42:35 -0400 Subject: unsigned int \ long References: Message-ID: "Roman Yakovenko" wrote in message news:mailman.1060753100.20465.python-list at python.org... >Hi. I need to work with integer as unsigned integer, but >I can't find documentation how can I do it. >Some reference on this will be appreciated. >For example (unsigned int)(-1) == 0xFFFFFFFF. Python does not have a separate count type. Just use 0 and positive ints and longs. TJR From terosaarni at hotmail.com Thu Aug 7 00:44:31 2003 From: terosaarni at hotmail.com (Tero Saarni) Date: Thu, 7 Aug 2003 07:44:31 +0300 Subject: Problem with blocking portably on sockets and Queue? References: <9P9Ya.42349$cl3.1347211@news2.tin.it> Message-ID: "Alex Martelli" wrote in message news:9P9Ya.42349$cl3.1347211 at news2.tin.it... > > > Tero Saarni wrote: > > > Hi, > > > > I have several threads communicating with each other using events > > stored in Queues. Threads block on Queue.get() until somebody > > publishes an event in thread's event queue. > > So far so wonderful -- excellent architecture. > > > > I need to add support for sockets to the system. Thread needs to > > unblock when: > > > > - there is socket ready to be read, or > > - there is event waiting in the queue > > > > My first tought was to replace blocking on Queue.get() with blocking > > on poll or select and dedicating file descriptors (created with os.pipe()) > > as an semaphore. Event publisher would write something to the write > > end of the pipe when it puts an event to the queue, effectively > > unblocking the receiver. > > > > BUT I noticed that select.poll() is not available on Windows and > > secondly Windows version of select.select() will accept only socket > > descriptors. > > > > What options do I have that are still portable also to Windows > > platform? > > I think you could devote a thread specifically to the task of handling > sockets, only. That special thread would not block on any queue but > just on select; when its select shows that a socket is ready, you can > have the thread itself do the reading and post the appropriate special > message including the data read to the appropriate thread, or you could > pass the ready-for-reading socket object to the appropriate thread, or > the like. This needs a bit more care if the set of sockets to be > select'ed on changes with time; in this case, I think the socket-handler > thread would have to use a timeout on its select so the set of sockets > can be updated once in a while (either by another thread, in which > case you need a lock to protect the "set of sockets" shared data, or > by the socket-handling thread (SHT) itself in response to a queued > message -- the SHT would read non-blockingly from that queue periodically > when the select times out) -- or you could perhaps use a special > identifiable socket for the SHT to receive from other threads requests > to change the set of ('true') sockets to be selected on. > > > Alex > Good idea, thanks! I will try dedicating a special thread for socket handling, although breaking out of select() for modifying the set of sockets gets a little tricky as you pointed out. Momentarily I was even thinking that I could break out of select() by sending a signal when I want to modify the set of sockets, but as I was almost expecting, it appeared that also signal support is quite limited on Windows platform. I guess that fallback solution would be to learn Windows sychronization primitives (wait functions etc) and write two separate implementations of relevant parts of the system. With some work that could probably be hidden behind matching interfaces and a factory method choosing the implementation on the fly. --- Tero From claird at lairds.com Tue Aug 26 05:03:28 2003 From: claird at lairds.com (Cameron Laird) Date: Tue, 26 Aug 2003 09:03:28 -0000 Subject: Celebrity advice (was: Advice to a Junior in High School?) References: <3F4A9DC7.9060509@nyc.rr.com> Message-ID: In article , Afanasiy wrote: . . . >I would also recommend not giving much weight to anything from ESR. . . . What's going on *there*? Eric makes plenty of mistakes, and he's apparently stubborn and biased in many cases; on the other hand, while I disagree with him profoundly on some technical choices, and I've been told of all sorts of personal failings he exhibits, in my experience he's always been willing to correct errors when presented with evidence. So: are you saying that he simply says too much and too early, and consequently is unreliable because he's outside his domain of expertise, or do you perceive a deeper problem with his advice? I ask in part because, as near as I can tell, you were the first to mention him in this thread. It appears that you regard his output as particularly hazardous. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://phaseit.net/claird/home.html From mikael at isy.liu.se Fri Aug 22 02:24:55 2003 From: mikael at isy.liu.se (Mikael Olofsson) Date: Fri, 22 Aug 2003 08:24:55 +0200 Subject: [OT] Why is it called string? In-Reply-To: References: <3f44ce77$0$556$b45e6eb0@senator-bedfellow.mit.edu> <3F44DBF2.1010403@draigBrady.com> Message-ID: <20030822082455.0ba24c68.mikael@isy.liu.se> On Thu, 21 Aug 2003 17:06:30 GMT "Greg Krohn" wrote: > I could swear there where more of these. Isn't there one for 2 bits and > 32bits, etc? I call 2 bits a dibit. /Mikael Olofsson Universitetslektor (Associate professor) Link?pings universitet ----------------------------------------------------------------------- E-Mail: mikael at isy.liu.se WWW: http://www.dtr.isy.liu.se/en/staff/mikael Phone: +46 - (0)13 - 28 1343 Telefax: +46 - (0)13 - 28 1339 ----------------------------------------------------------------------- Link?pings kammark?r: www.kammarkoren.com From nav+posts at bandersnatch.org Thu Aug 21 00:00:43 2003 From: nav+posts at bandersnatch.org (Nick Vargish) Date: 21 Aug 2003 00:00:43 -0400 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: <3F41A877.995F9C35@alcyone.com> Message-ID: davesum99 at yahoo.com (smarter_than_you) writes: > The real question here is, why haven't we all but Brandon in OUR killfiles? When there's a stinging insect flying around the room, I like to be able to see it. Also, his perspective is so different from mine, I find it useful to be reminded that there are people like him out there. It's fascinating the way he seems to think everything needs to be a zero-sum interaction... I mean, _why_ does anyone in the open source world have to eat anyone else's lunch? Why is market dominance supposed to be important to pythonistas? It's just good to be reminded that some people really think like this -- as weird as it might seem to me. Nick -- # sigmask || 0.2 || 20030107 || public domain || feed this to a python print reduce(lambda x,y:x+chr(ord(y)-1),' Ojdl!Wbshjti!=obwAcboefstobudi/psh?') From tgray at cox-internet.com Sun Aug 17 02:01:41 2003 From: tgray at cox-internet.com (Terry Gray) Date: Sun, 17 Aug 2003 01:01:41 -0500 Subject: os.system stdout redirection... Message-ID: Using Python 2.2 in Debian linuxI am trying to change to a different directory, execute a 'make all' command, and redirect the output of the subshell to a PyQt window... I should be able to execute the os.system('cd newdirectory; make all'), but how do I redirect stdout of the new subshell created by the os.system call? Any help would be appreciated. twgray From nicholas_wieland at yahoo.it Thu Aug 21 06:56:32 2003 From: nicholas_wieland at yahoo.it (Nicholas Wieland) Date: Thu, 21 Aug 2003 12:56:32 +0200 Subject: Search for dialog based question/answer module for installation/configuration procedures References: Message-ID: <04le11-3m.ln1@lorien.ilweran.home> -Raphael Bossek: > Hi, > > I search for a module where programming of installation and configuration > procedures based on question and answer/list selection/single line edit > ect. steps can be done easy. I know only Debconf as something similar. > But are there other project to, especially for Python ? I'm sure there's an a module for using Python with 'dialog' out there, probably 'PyDialog' or something similar. Try 'python dialog' or 'PyDialog' with Google. nicholas From mpeuser at web.de Sun Aug 31 04:11:26 2003 From: mpeuser at web.de (Michael Peuser) Date: Sun, 31 Aug 2003 10:11:26 +0200 Subject: list.sort(func) speed References: Message-ID: "mackstann" schrieb im Newsbeitrag news:mailman.1062286079.6474.python-list at python.org... > I have the following function that compares two filenames based on their > basename only: > > _basenameCmp = lambda self, *pair: cmp(*map(os.path.basename, pair)) Please note that all os.path functions are *awfully* slow! If ever possible use a nonportable self made scheme. It drove me nearly crazy when I detected that os.path split and join operations took even longer than raw disk access in a directory scan program.... (The other issue (decorated sorting) is more relevent of course.) Kindly Michael P From jjl at pobox.com Thu Aug 21 18:11:35 2003 From: jjl at pobox.com (John J. Lee) Date: 21 Aug 2003 23:11:35 +0100 Subject: What's better about Ruby than Python? References: <3F40892D.AEF4AAE@alcyone.com> <87isov6pk4.fsf@pobox.com> <3F412081.5EF7279C@alcyone.com> <874r0ey9bx.fsf@pobox.com> <87brulnui2.fsf@pobox.com> Message-ID: <871xvefyp4.fsf@pobox.com> alloydflanagan at comcast.net (A. Lloyd Flanagan) writes: [...] > Don't get me wrong: you can do great things with C++ if you're an > expert. Problem is, if you're not, you can do tremendous damage. While I take Alex's point about the practicalities of getting people to use a language (independent of it's actual appropriateness for the job at hand), I just suspect there must be a better language out there in the multiverse, which did the job of integrating nicely with C, allowing incremental improvement of C code *without* actually trying to *be* C (+more stuff on top). Of course, it's far too late now. John From max at alcyone.com Mon Aug 18 02:47:12 2003 From: max at alcyone.com (Erik Max Francis) Date: Sun, 17 Aug 2003 23:47:12 -0700 Subject: Loading a file into the interpreter References: Message-ID: <3F407670.7F9E6DB@alcyone.com> Thomas Womack wrote: > I'd like, from the command line of the python interpreter, to get the > effect of having typed in the contents of some text file; the sort of > thing I'd expect a "load" command to do. > > I can do "python prog.py", but that doesn't leave me in the > interpreter afterwards, and I'd often like to set some variables, load > a program, and poke about to see what the variables look like > afterwards. Try python -i prog.py -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ Well I have been puppetized / Oh how I have compromised \__/ Lamya From vanevery at 3DProgrammer.com Mon Aug 11 17:59:15 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Mon, 11 Aug 2003 14:59:15 -0700 Subject: Python vs. C# References: <2259b0e2.0308100616.55b651ca@posting.google.com> <3f36af20@shknews01> <2259b0e2.0308110433.204d7831@posting.google.com> Message-ID: Michele Simionato wrote: > "Brandon J. Van Every" wrote in message > news:<3f36af20 at shknews01>... >> I'm beginning to think that within 5 years, no new applications will >> be >> written in C++. > > ?? Are you joking or what ?? Did you learn anything from Fortran > lesson? Or from Lisp? Programming languages *never* die! Ok, "no" new applications may be a bit strong. There will always be hobbyists and cranks. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From mschneider.pad at t-online.de Sat Aug 16 05:54:55 2003 From: mschneider.pad at t-online.de (Marcus Schneider) Date: 16 Aug 2003 02:54:55 -0700 Subject: GUI builder for Python References: Message-ID: <3f443b52.0308160154.3db55613@posting.google.com> "henry" wrote in message news:... > You know any free ones for Tkinter? > > thanks I'm using PAGE. It's Tcl/Tix for Python and works pretty fine and as far as I can see, it's for free;) Though installation was a little rough. And I'm not sure if any developers are still working on it. > > "Michael Peuser" wrote in message > news:bhi2uq$meo$06$1 at news.t-online.com... > > Hi Henry, > > > > there is a discussion of this topic from time to time - every week I > should > > say ;-) > > Everything depends on the GUI-Toolkit you have selected: > > Tkinter? > > PyQt? > > wxPython? > > Or an even more exotic one like FOX, FLTK, GTK+ or PyUI? > > > > There are some commercial GUI Builders out of the normal budget. > > Free ones are Black Adder for Qt, BoaConstructor for wx and some stuff > like > > PAGE or SpecTIX for TIX. > > > > Kindly > > Michael P > > > > > > "henry" schrieb im Newsbeitrag > > news:nx%_a.730754$3C2.17094058 at news3.calgary.shaw.ca... > > > Hi, > > > > > > Just wondering if there's a good GUI builder for Python. Something like > > > Visual Tcl, where you just drag and drop objects. > > > > > > Not too good with creating user interfaces from code along. > > > > > > Thanks > > > > > > > > > > > From ruach at chpc.utah.edu Fri Aug 1 16:50:12 2003 From: ruach at chpc.utah.edu (Matthew) Date: 1 Aug 2003 13:50:12 -0700 Subject: list indexing References: Message-ID: "Sean Ross" wrote in message news:... > Perhaps I've misunderstood, but it looks like you want: > >>> words = ['this', 'is', 'a', 'list'] > >>> words.index('list') > 3 > > which is, of course, not the inverse of .index() (but .index() itself). > > In general, if you use this, you'll either need to be certain that the item > is indeed in the list, or nest the call in a try/except like so: > >>> try: > ... index = words.index('list') > ... except ValueError: > ... pass # or whatever you want to do when the look-up fails > ... > >>> index > 3 > > HTH > Sean Christopher Koppler wrote in message news:<76uiivkl7vlr98ggp1p7i4h8m8h2s0sbs0 at 4ax.com>... > Using a recent Python you can use enumerate (built-in): > > list = ['this', 'is', 'a', 'list'] > for cnt, item in enumerate(list): > if item == 'list': > print cnt > > > > --Christopher Mark Day wrote in message news:<310720031327225125%mday at apple.com>... > > If you're using Python 2.3, you can use enumerate() like this: > > for index,item in enumerate(list): > if item == 'list': > print index > > BTW: I'd suggest not using the name of a built-in class for your > variable "list". Perhaps "mylist" or "words"? > > -Mark Thanks Sean (& Mark and Christopher) You were right I misunderstoof the use of index(). It does do exactly what I want. However Mark and Christophers replies better suit this particular problem. Thanks very much All -matthew From bokr at oz.net Sun Aug 3 15:44:31 2003 From: bokr at oz.net (Bengt Richter) Date: 3 Aug 2003 19:44:31 GMT Subject: Match beginning of two strings References: Message-ID: On Sat, 2 Aug 2003 22:23:12 -0500, Jeff Epler wrote: >This is a naive implementation of the 'extract' function. > def extract(a, b): > m = min(len(a), len(b)) > for i in range(m): > if a[i] != b[i]: > return a[:i] > return a[:m] > >Here's one that uses the new zip() function: I don't see "zip" ;-) > def extract2(a, b): > m = min(len(a), len(b)) > for i, ai, bi in (range(m), a, b): > if ai != bi: return a[:i] > return a[:m] >.. unfortunately, it seems to be slower than the first method. On my >machine (800MHz PIII): >$ python timeit.py -s 'import ravi' \ > 'ravi.extract("abcdefghijklmnopqrstuvwxyz","abcdefghijklmnopBHLHT")' >10000 loops, best of 3: 32.7 usec per loop > My timing harness (I seem to need a new getopt for timeit.py under 2.3) shows a slight (15-22% less time) improvement for this 2.3 alternative: def commonprefix(s1, s2): # very little tested! try: for i, c in enumerate(s1): if c != s2[i]: return s1[:i] except IndexError: return s1[:i] return s1 [12:39] C:\pywk\clp>timefuns ravi -c extract -s 'abcdefghijklmnopqrstuvwxyz' -s 'abcdefghijklmno pBHLHT' -c commonprefix -s 'abcdefghijklmnopqrstuvwxyz' -s 'abcdefghijklmnopBHLHT' timing oh: 0.000007 ratio extract: 0.000088 1.00 commonprefix: 0.000074 0.85 [12:39] C:\pywk\clp>timefuns ravi -c extract -s 'abcdefghijklmnopqrstuvwxyz' -s 'abcdefghijklmno pBHLHT' -c commonprefix -s 'abcdefghijklmnopqrstuvwxyz' -s 'abcdefghijklmnopBHLHT' timing oh: 0.000007 ratio extract: 0.000091 1.00 commonprefix: 0.000071 0.78 [12:40] C:\pywk\clp>timefuns ravi -c extract -s 'abcdefghijklmnopqrstuvwxyz' -s 'abcdefghijklmno pBHLHT' -c commonprefix -s 'abcdefghijklmnopqrstuvwxyz' -s 'abcdefghijklmnopBHLHT' timing oh: 0.000007 ratio extract: 0.000091 1.00 commonprefix: 0.000071 0.78 [12:40] C:\pywk\clp>timefuns ravi -c extract -s 'abcdefghijklmnopqrstuvwxyz' -s 'abcdefghijklmno pBHLHT' -c commonprefix -s 'abcdefghijklmnopqrstuvwxyz' -s 'abcdefghijklmnopBHLHT' timing oh: 0.000007 ratio extract: 0.000088 1.00 commonprefix: 0.000071 0.81 Regards, Bengt Richter From prouleau001 at sympatico.ca Sun Aug 24 12:25:00 2003 From: prouleau001 at sympatico.ca (Pierre Rouleau) Date: Sun, 24 Aug 2003 12:25:00 -0400 Subject: Where is sys.path set? In-Reply-To: References: Message-ID: Greg Chapman wrote: > On Sat, 23 Aug 2003 17:00:02 -0400, Pierre Rouleau > wrote: > > >>I can't remember where/how sys.path is set (aside from the automatically >>loaded site.py) and i get a strange entry in it. Can anyone remind me >>where/how to control sys.path on a Win32 machine (i'm running XP on the >>one where the issue arises). >> >>I can't figure out why the 'C:\WINDOWS\System32\python23.zip' entry is >>inside sys.path. That file/dir does not exist on the disk. Could a >>failing (crashing) Pythonwin installation caused that? >> > > > The python23.zip entry has to do with the support for loading modules from zip > files. See http://www.python.org/peps/pep-0273.html (esp. the section headed > "Booting"). > > Otherwise, I think the best description of how sys.path is set on windows comes > from a long comment at the top of PC/getpathp.c from the source code: > > /* ---------------------------------------------------------------- > PATH RULES FOR WINDOWS: > This describes how sys.path is formed on Windows. It describes the > functionality, not the implementation (ie, the order in which these > are actually fetched is different) > > * Python always adds an empty entry at the start, which corresponds > to the current directory. > > * If the PYTHONPATH env. var. exists, it's entries are added next. > > * We look in the registry for "application paths" - that is, sub-keys > under the main PythonPath registry key. These are added next (the > order of sub-key processing is undefined). > HKEY_CURRENT_USER is searched and added first. > HKEY_LOCAL_MACHINE is searched and added next. > (Note that all known installers only use HKLM, so HKCU is typically > empty) > > * We attempt to locate the "Python Home" - if the PYTHONHOME env var > is set, we believe it. Otherwise, we use the path of our host .EXE's > to try and locate our "landmark" (lib\\os.py) and deduce our home. > - If we DO have a Python Home: The relevant sub-directories (Lib, > plat-win, lib-tk, etc) are based on the Python Home > - If we DO NOT have a Python Home, the core Python Path is > loaded from the registry. This is the main PythonPath key, > and both HKLM and HKCU are combined to form the path) > > * Iff - we can not locate the Python Home, have not had a PYTHONPATH > specified, and can't locate any Registry entries (ie, we have _nothing_ > we can assume is a good path), a default path with relative entries is > used (eg. .\Lib;.\plat-win, etc) > > > The end result of all this is: > * When running python.exe, or any other .exe in the main Python directory > (either an installed version, or directly from the PCbuild directory), > the core path is deduced, and the core paths in the registry are > ignored. Other "application paths" in the registry are always read. > > * When Python is hosted in another exe (different directory, embedded via > COM, etc), the Python Home will not be deduced, so the core path from > the registry is used. Other "application paths" in the registry are > always read. > > * If Python can't find its home and there is no registry (eg, frozen > exe, some very strange installation setup) you get a path with > some default, but relative, paths. > > ---------------------------------------------------------------- */ > > --- > Greg Chapman > Thanks a lot Greg, this explains it all! --- Pierre Rouleau From hans at zephyrfalcon.org Wed Aug 20 22:35:57 2003 From: hans at zephyrfalcon.org (Hans Nowak) Date: Wed, 20 Aug 2003 22:35:57 -0400 Subject: What's better about Ruby than Python? In-Reply-To: References: <3F4040F8.87901505@alcyone.com> <6dj2kv8ugkieehs7guh786cl40o5lj6mcs@4ax.com> Message-ID: <3F44300D.4040008@zephyrfalcon.org> Doug Tolton wrote: > I just don't find that argument compelling. By that logic we should > write the most restrictive language possible on the most restrictive > platform possible (ie VB on Windows) because allowing choice is > clearly a bad thing. > > Don't introduce a feature because it would be so cool that everyone > would use it? That's just plain weird. The problem is that a macro system that is too powerful can be harmful. Let's say you write a useful module. Python 3.6 just added a very powerful macro system, and you use it to, say, write functions with lazy evaluation, make strings mutable, and write your own flavor of the for-loop. Now I cannot read your code anymore. A simple function call, or a loop, does not mean what it used to mean. One of Python's strengths is that you can create powerful abstractions with functions and classes. But no matter what you do with these, they will always be functions and classes that adhere to some common language rules. There is no way to go "over the top" and change the language proper. Right now I can read everybody's Python code (unless deliberately obfuscated); this would change if there were macros that were so powerful that they would change language constructs, or allow new ones. Maybe they would make your problesm easier to solve, but Python itself would lose in the long run. My $0.02, -- Hans (hans at zephyrfalcon.org) http://zephyrfalcon.org/ From logistix at cathoderaymission.net Sun Aug 10 17:23:45 2003 From: logistix at cathoderaymission.net (logistix at cathoderaymission.net) Date: 10 Aug 2003 14:23:45 -0700 Subject: COM server usage question References: Message-ID: <3c91a864.0308101323.5461437b@posting.google.com> nenad.propadovic at partner.bmw.de (Propad) wrote in message news:... > Dear Mr. Hammond, > thank you for your answer, and even more for making Python on win32 > possible at all. I do realise my question resembles some previous > postings, and the answer you gave me was allready given. > However, I'll try to restate my question in other words: could anybody > give me a pointer to any kind of literature enabling me to produce my > own type library? Some easy to understand beginners guide to COM, > explaining also the typical registry entries? Well if there are no > tlb-s in win32com, I just might manage to get them in there :-) > Thanks, all you kind people. > Nenad Propadovic > P.S. Starting a contract work at BMW, I just realised the penetration > of Python in the german automotive industry seems to be quite descent. > This is due to a tool-suite by a company named DSpace, which uses > Python as its scripting language... > "Inside COM+ Base Services" From MS Press is the first book you should read. It should probably be read by anyone trying to do serious COM work. There is at least one chapter on Type Libraries in the book. Once you get through that the library reference at http://msdn.microsoft.com should fill in the blanks. However, both of these references will assume you know C/C++ reasonably well (and maybe some VB on msdn). From joerg.maier at rz.uni-mannheim.de Tue Aug 5 14:42:12 2003 From: joerg.maier at rz.uni-mannheim.de (=?ISO-8859-15?Q?J=F6rg?= Maier) Date: Tue, 05 Aug 2003 20:42:12 +0200 Subject: python gui and ssh References: Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 J?rg Maier wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Hey, > i have a problem with ssh and popen2: Sorry, i got it already, will use the pexpect module, thanks joerg > #sshstdin, sshstdout = os.popen2(SSH_PATH + ' ' + self.user + '@' + > self.server + ' ' + 'ls -al') > > ssh does not take paswords from sshstdin and it does not write > user at server's password: > to sshstdout but it writes to the terminal due to security issues. is > there a possibility to pass passwords to ssh and to get terminal outputs > to a pipe in a gui program? > > thanks for every help, > i would like to write a gui based program giving the possibility to rsync > with ssh as remote shell. this tool should run under cygwin, linux and > macosx. > > - -- > Hi > I am a signature virus. > Please copy me to your .signature file to help me spread. > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.2.2-rc1-SuSE (GNU/Linux) > > iD8DBQE/L/RYTYj8eXbs1acRAjpOAKCHLZFryhzcFQIVADRS6Az5UDAecgCdHLec > 36sfcK7CB3Cg1t9l055BXAs= > =MG0v > -----END PGP SIGNATURE----- - -- Hi I am a signature virus. Please copy me to your .signature file to help me spread. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2-rc1-SuSE (GNU/Linux) iD8DBQE/L/qETYj8eXbs1acRAtmWAKDGx67GbgDkhTmThqfMkJPqclasPwCgiyd0 zzXVeuzX49F3HyXPJ4Rnw7s= =r/50 -----END PGP SIGNATURE----- From mpeuser at web.de Sun Aug 17 17:41:51 2003 From: mpeuser at web.de (Michael Peuser) Date: Sun, 17 Aug 2003 23:41:51 +0200 Subject: bitwise not - not what I expected References: <1YD%a.747879$3C2.17342633@news3.calgary.shaw.ca> Message-ID: "Dennis Lee Bieber" schrieb im Newsbeitrag news:c84511-ol3.ln1 at beastie.ix.netcom.com... > Elaine Jackson fed this fish to the penguins on Saturday 16 August 2003 > 09:58 pm: > > > > > > > Is there a function that takes a number with binary numeral a1...an to > > the number with binary numeral b1...bn, where each bi is 1 if ai is 0, > > and vice versa? (For example, the function's value at 18 [binary > > 10010] would be 13 > > [binary 01101].) I thought this was what the tilde operator (~) did, > > [but when I > > went to try it I found out that wasn't the case. I discovered by > > experiment (and verified by looking at the documentation) that the > > tilde operator takes n to -(n+1). I can't imagine what that has to do > > with binary numerals. [..] > You've had lots of answers at the moment though I haven't seen anyone > explain away the "+1" part... > > Most computers use twos-complement arithmetic to avoid the problem of > having two valid values for integer 0, which is what appears in ones > complement arithmetic. > > For argument, assume an 8-bit integer. The value of "5" would be > represented as 00000101. The one's complement negative would be > 11111010. So far there isn't any problem... But consider the value of > 0, represented as 00000000. A one's complement negative would become > 11111111 -- But mathematically, +0 = -0; in one's complement math, this > does not hold true. > > So a little trick is played, to create twos complement... To negate a > number, we take the ones complement, and then add 1 to the result. The > "5" then goes through: 00000101 -> 11111010 + 1 -> 11111011... Looks > strange, doesn't it... But watch what happens to that 8-bit 0: 00000000 > -> 11111111 + 1 -> (overflows) 00000000.... Negative 0 is the same as > positive 0. [..] I have the impression (may be wrong) that you are working under the misconception that there can be a "natural" binary represensation of negative numbers!? Three conventions have commonly been used so far: 1- Complement 2-Complement Sign tag plus absolut binary values All of them have their pros and cons. For a mixture of very technical reasons (you mentioned the +0/-0 conflict, I might add the use of binary adders for subtraction) most modern computers use 2-complement, and this now leads to those funny speculations in this thread. ;-) Kindly Michael P From aleaxit at yahoo.com Fri Aug 15 05:06:43 2003 From: aleaxit at yahoo.com (Alex Martelli) Date: Fri, 15 Aug 2003 11:06:43 +0200 Subject: Python signal delivery under BSD 4.4 References: <7h3isp04bzm.fsf@pc150.maths.bris.ac.uk> Message-ID: Michael Hudson wrote: > "Elf M. Sternberg" writes: > >> Right now, I just want a way to make signal delivery work. > > At some point, the threads implementation got changed so that new > threads get their signal mask set to "block everything and it's cat" > (there was a reason for this, but I'm not really sure what it was). > As I see it, you have two options: 1) write a little C to unset the > procmask after fork() but before execve() 2) only launch apps from the > main thread. Incidentally, these aren't far from the advice in "Pthreads Programming" (by Nichols, Buttlar and Proulx Farrell -- O'Reilly) in Chapter 5, under "Threads and Process Management". The authors are dealing with C issues, not Python by any means, but still they conclude that "forking from a multithreaded program is no picnic" and suggest 1) fork before you've created any threads, and 2) consider the surrogate parent model (fork a child process at init time, IPC with the child -- which remains single threaded -- to delegate forking and execing on our behalf). Alex From shagshag13 at yahoo.fr Thu Aug 7 02:11:52 2003 From: shagshag13 at yahoo.fr (Shagshag) Date: 6 Aug 2003 23:11:52 -0700 Subject: email client written with python + wxWindows Message-ID: <409a56e2.0308062211.456575df@posting.google.com> hello, does anyone know of a full python + wxWindows email client ? google didn't help me... thanks, From tech-support at ams.org Thu Aug 21 09:55:59 2003 From: tech-support at ams.org (tech-support at ams.org) Date: Thu, 21 Aug 2003 09:55:59 -0400 (EDT) Subject: Automatic Acknowledgement In-Reply-To: <200308211353.h7LDrsGY001784@smtp.ams.org> References: <200308211353.h7LDrsGY001784@smtp.ams.org> Message-ID: <200308211355.h7LDtxZS020554@ams.org> This message has been generated automatically. (To prevent mail loops, please do not reply to it.) This is to acknowledge receipt of your mail by the American Mathematical Society Technical Support group. A full reply will follow as soon as possible. The response time can vary considerably depending on the number of incoming questions, the amount of investigation required, and other demands on the time of the AMS Technical Support personnel. If you do not hear from us within two weeks after that date, or if your question is extremely urgent, you may wish to leave a voice-mail message at 401-455-4080; we will check all messages as soon as we return. Technical Support Staff American Mathematical Society tech-support at ams.org From aahz at pythoncraft.com Sat Aug 16 01:16:26 2003 From: aahz at pythoncraft.com (Aahz) Date: 16 Aug 2003 01:16:26 -0400 Subject: Why doesn't __call__ lead to infinite recursion? References: <2a82921f.0308151158.b8c9154@posting.google.com> Message-ID: In article <2a82921f.0308151158.b8c9154 at posting.google.com>, Patrick Lioi wrote: > >def foo(): pass > >foo is a function >foo is a callable object >foo has method __call__ defined > >foo.__call__ is a function >foo.__call__ is a callable object >foo.__call__ has method __call__ defined You're mixing up the distinction between objects and types. If you do print foo.__dict__ you'll see that __call__ isn't there. However, if you try print type(foo).__dict__ you'll see __call__ there. When you do foo(), Python actually does type(foo).__call__(foo). Because type(foo).__call__ is manipulating foo, you don't get the circular reference. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From max at alcyone.com Mon Aug 11 14:55:37 2003 From: max at alcyone.com (Erik Max Francis) Date: Mon, 11 Aug 2003 11:55:37 -0700 Subject: Fun with numbers - dammit, but I want a cast! References: <3f378fac$0$10778$afc38c87@auth.uk.news.easynet.net> Message-ID: <3F37E6A9.10358C87@alcyone.com> Istvan Albert wrote: > Will there be a keyword/function for integer division after that? Yes, the // operator. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ Nobody can reach me, nobody can touch me; it's a wonderful feeling. \__/ Aaliyah From grey at despair.rpglink.com Fri Aug 15 16:06:47 2003 From: grey at despair.rpglink.com (Steve Lamb) Date: Fri, 15 Aug 2003 20:06:47 -0000 Subject: [wxPython] Updating the status bar? References: Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 11 Aug 2003 05:32:10 GMT, Rob Williscroft wrote: > So I would guess at: > self.MainStatus.Refresh() > self.MainStatus.Update() Finally got around to trying this and no dice. Still does not update the status bar at all. :/ > HTH Thanks, though. I'll keep plugging at it. :) -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (GNU/Linux) iD8DBQE/PT1Xel/srYtumcURAkajAKCuBrfp8x3azM6Ex58tb70X6/R1HgCfYzJA SxizcQkao9WiUlWJAW/hT8s= =a+IZ -----END PGP SIGNATURE----- -- Steve C. Lamb | I'm your priest, I'm your shrink, I'm your PGP Key: 8B6E99C5 | main connection to the switchboard of souls. | -- Lenny Nero - Strange Days -------------------------------+--------------------------------------------- From blackhawke at legacygames.net Thu Aug 7 21:14:57 2003 From: blackhawke at legacygames.net (BlackHawke) Date: Thu, 7 Aug 2003 18:14:57 -0700 Subject: Game Company looking for Employiees Message-ID: Hello! My name is Nick Soutter, I am the owner of a small game company in San Diego, CA called Aepox Games (www.aepoxgames.net). Our first product, Andromeda Online (www.andromedaonline.net), goes commercial in a few months. We are in pre-production of our second project, codenamed "Avalon". It is a MMORPG. We have started a working relationship with a hosting company which can host our game, to our specifications, with up to 1 millions simultaneous players online with no lag (butterfly.net, partnered with IBM, using an ingenious method of data management to offer stability, reliability, and ultra fast reaction time with no lag). Because we are a small company, cost is an extremely limiting factor. We don 't have a lot of funds to throw at this, though we hope the success of Andromeda Online will help. Our arrangement with butterfly.net will allow us to pay on demand- as we gain more subscribers, we pay them proportionately, drastically reducing our upfront costs. There are two areas we are now lacking: 1: We need python scripters. Much of the programming used for the servers must necessarily be in python. The bulk of our code will be in Python, and we have no access to Python programmers at the moment. 2: We need people capable of programming vast worlds in the CrystalSpace 3d engine. While we do have excellent graphic artists on hand, we have no-one capable of developing the lands and cities in this game. We have chosen CrystalSpace because of our financial concerns. We are looking for Python programmers, and CrystalSpace developers. We are hopefully going to be able to pay a decent wage, but probably not a fully commensurate salary. Our company is strapped for cash. In addition to pay, however, we have a lot to offer. We are offering the potential for a long term job (if Avalon does well, we'll need continued support for years to come). We are offering the chance to get in on the ground floor of a budding game company. We also believe fully in giving credit to those who work for us. For you budding programmers, this is the chance for a big project, where you are needed, appreciated, and your work will be public and commercial. We are in pre-development. We have not begun production. Production is not slated to begin for another 6 months. We would like people in the San Diego area, it makes things mildly easier. HOWEVER, it is not a requirement. Andromeda was done with most of us never physically meeting the programmer. We have strong internet management and development resources. At present, we are simply trying to get some names, get a feel for who might be interested, the kind of experience they may have, and what our resources may be before we begin. Anybody interested, please send me an email, with your resume, at nsoutter at aepoxgames.com. Please only send us your resume if you are interested. Sending us your resume is not a promise you will take the project, nor is accepting your resume a promise of getting a job. We are simply trying to see who is interested, and what they can do. Thank you for your time, and I hope you consider us. Nick Soutter Aepox Games From washu at 127.0.0.1 Fri Aug 1 23:55:42 2003 From: washu at 127.0.0.1 (washu) Date: Fri, 01 Aug 2003 20:55:42 -0700 Subject: Is there the same function in python as atoi() in C References: Message-ID: On Sat, 02 Aug 2003 11:51:54 +0800, Robbie wrote: > Someone tell me, > if not exist, how to write one with the same function? > I have made a try, but there is no character type in python, > so i failed, someone help me, > thanks very much I may be totally wrong but I believe there is a atoi in the strings modules. From tzot at sil-tec.gr Fri Aug 22 22:47:23 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Sat, 23 Aug 2003 05:47:23 +0300 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: Message-ID: On Mon, 18 Aug 2003 14:51:09 -0800, rumours say that "Arnaldo Riquelme" might have written: >Bottom line is that people that uses Python have a better sex life than >those that use other languages. OK, who added viagra.py in the standard library? :) -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From mnations at airmail.net Fri Aug 29 14:12:20 2003 From: mnations at airmail.net (Marc) Date: 29 Aug 2003 11:12:20 -0700 Subject: How do I prevent master window from being accessed with child window present? Message-ID: <4378fa6f.0308291012.f660cdf@posting.google.com> Hi, I am doing a gui application where child windows pop up with options after the user selects particular buttons from the master window. However, the master window is still active underneath the child window. If they accidentally press the same button again they can get the same copy of two child windows, and that screws up a bunch of the database stuff that I am trying to collect. I have tried using the 'transient' method, and that prevents the master window from being highlighted. But the user can still push buttons on the master window if the child window is moved aside. How do I disable the master window until the child window is closed? Thanks, Marc From db3l at fitlinxx.com Mon Aug 11 17:54:50 2003 From: db3l at fitlinxx.com (David Bolen) Date: 11 Aug 2003 17:54:50 -0400 Subject: Multi-Line Comment References: <4qofjvg3bh9smlnb1do4f0lhjga7bacnu3@4ax.com> Message-ID: Doug Tolton writes: > How do you comment the block of text with Emacs? That is what I'm > using for my code editor. In Python mode, use C-c # to comment the selected region and C-u C-c # to uncomment a region. The commenting is done with "##" at the front of every line in the region, so it normally stands out from actual comments due to the #-doubling. -- David From bokr at oz.net Fri Aug 1 16:09:46 2003 From: bokr at oz.net (Bengt Richter) Date: 1 Aug 2003 20:09:46 GMT Subject: Potentially important real-time on-line discussion References: Message-ID: On Fri, 01 Aug 2003 16:21:38 -0000, claird at lairds.com (Cameron Laird) wrote: >*The Chronicle of Higher Education*, which is more-or-less >authoritative for US university administrations, is spon- >soring a discussion on the place of open-source in >universities ("... are such choices too risky for colleges >...?"), starting in about an hour. Bluntly, I think it's >time to rally 'round the flag. > >http://chronicle.com/colloquylive/2003/08/opensource/chat.php > >Pass it on. That link didn't work for me, but chopping its tail did: http://chronicle.com/colloquylive/2003/08/opensource/ But it's over ;-) The guest -- Bernard W. Gleason -- was a proponent of open software, and answered questions reasonably, I thought. But I think open source needs a simple metaphor for politicians and non-geeks to understand. Open source is a digital potluck. The dishes available depend on who volunteers to cook, but digital dishes don't get used up when they're served, so there's plenty of the best to go around ;-) Regards, Bengt Richter From rmichael at NOfields.SPAMutoronto.ca Sun Aug 17 17:58:00 2003 From: rmichael at NOfields.SPAMutoronto.ca (Richard Michael) Date: Sun, 17 Aug 2003 21:58:00 GMT Subject: Newbie: explanation of PrivoxyWindowOpen; website docs outdated? Message-ID: Hello, First up, the website documentation is out of date. For example, http://www.python.org/doc/current/lib/os-fd-ops.html purports to be the most recent (July 29, 2003) documentation. (At least, that's how I'm reading the footer.) However, the downloadable package contains different content in Section 6.1.3. Related to this issue, it doesn't refer to PrivoxyWindowOpen! Moving on, [Python 2.2.2] I've been reading the Python docs, and the 6.1.3 File Objects section of the Library Reference indicates that instead of "open()", I should use the builtin function "PrivoxyWindowOpen()" instead. However, it isn't defined. I'm using IDLEfork, but have also tried this from the plain interpreter as well. Do I need to import a module? (I've tried 'from sys,os import *'.) I've rgrepped through /usr/lib/python2.2 and see no usage or definition of "PrivoxyWindowOpen". If it's the recommended file object function, why don't any of the modules contain calls to it? Of course, I've also searched python-list at MARC, and also on Usenet, and there are very few references to it! In short, for being recommended in the documentation, it seems remarkably mysterious. Can someone take a minute to explain the situation to me? (For example, why is it named "...Window...", when it's function for handling file objects? Is it related to the Privoxy HTTP proxy?) I'm using the current RedHat (9) build of python (2.2.2), but have encountered this with the python build that came with RH 7.2 as well. I'm sure I've missed an obvious comment somwhere because "reading" the documentation really means "skimming for relevant functions"). Thanks and apologies for the newbie noise. Regards, Richard From staschuk at telusplanet.net Wed Aug 27 17:18:33 2003 From: staschuk at telusplanet.net (Steven Taschuk) Date: Wed, 27 Aug 2003 15:18:33 -0600 Subject: getopt issues In-Reply-To: ; from iddwb@asu.edu on Wed, Aug 27, 2003 at 01:25:21PM -0700 References: Message-ID: <20030827151833.B470@tibia.amotlpaa.bogus> Quoth David Bear: [...] > now that I've read a little more of the getopt documentation, it says that > getopt stops processing when a 'nonoption' is encounted. Is there a way > to have it process the whole argument list, then only return the options > specified in options, rather than have it through an exception and return > nothing? I don't think so. This is an unusual request -- normally it is desirable for a program to insist on correct usage, rather than trying to guess what the user meant. (Imagine, for example, that a user types 'rm -I *', intending 'rm -i *', and rm just ignores the unknown option '-I'. This would be bad.) It might, however, be possible to subclass optparse.OptionParser to get the behaviour you want. (The optparse module is new in the 2.3 stdlib.) -- Steven Taschuk staschuk at telusplanet.net "Telekinesis would be worth patenting." -- James Gleick From cjw at sympatico.ca Thu Aug 28 07:31:35 2003 From: cjw at sympatico.ca (Colin J. Williams) Date: Thu, 28 Aug 2003 07:31:35 -0400 Subject: Celebrity advice (was: Advice to a Junior in High School?) In-Reply-To: References: Message-ID: Terry Reedy wrote: > "Tim Churches" writes: > > >>Cameron Laird wrote: >> >> >>>I ask in part because, as near as I can tell, you were the >>>first to mention him in this thread. It appears that you >>>regard his output as particularly hazardous. >> >>See the first few paragraphs of >>http://www.catb.org/~esr/guns/gun-ethics.html > > > I did. 'Few' means at least three. The second and last sentence of > the third paragraph reads > > " Every political choice ultimately reduces to a choice about when and > how to use lethal force, because the threat of lethal force is what > makes politics and law more than a game out of which anyone could opt > at any time." > > Do you disagree (with what seems to me like an obviously true > statement)? Or are you one who doesn't the 'people' to notice the > elitist hypocrisy of being 'anti-gun' while supporting the bearing > *and use* of guns by 'govern-men' the elitists hope to control? (I > think it safe to say that during the 20th century, 99% of the 100s of > millions of murders were committed by armed govern-men rather than by > private persons acting alone.) > > Well back to Python. > > Terry J. Reedy We seem to be straying from Python and/or advice to a your person, but the third paragraph is clearly nonsense. To give an example. In Canada, over the next year or more, the Members of Parliament and the Senators will have to make a choice as to whether gay marriage is to continue in this country. No threat of force exists. A decision will be made and the populace will accept it as being more or less democratic. Colin W. From zathras at thwackety.com Tue Aug 12 06:32:39 2003 From: zathras at thwackety.com (Michael Sparks) Date: Tue, 12 Aug 2003 11:32:39 +0100 (BST) Subject: Python should try to displace Java In-Reply-To: Message-ID: On Tue, 12 Aug 2003, Daniel Dittmar wrote: > So what do you propose? To transfer the copyright of Python to SCO so > that they sue SUN? No, no, no. Transfer the copyrights of the Tim-bot & Martelli-bot to Microsoft, the BFDL moves to OSDL which becomes aquired by Microsoft in as swift turn about of face as their U-turn on the Internet. Python labs is aquired by Lindows who acquire SCO once they've destroyed themselves, they get infected by SCO Unix's viral Unix license (*) transmogrify into SCO-TNG who then attack Microsoft who trounce them right royally in court, but in a shock countermove are forced to buy everyone on the planet a pint of their favourite beverage. Meanwhile the people working on open source projects turn around and go "oh that's nice dear", and carry on working on their pet projects. Or something like that. Michael. (*) SCO described it this way somewhere. Probably from a website, so it must be true. Definitely. Oh yes. From avner at skilldesign.com Thu Aug 28 15:20:51 2003 From: avner at skilldesign.com (Avner Ben) Date: Thu, 28 Aug 2003 21:20:51 +0200 Subject: cannot make Python 2.3 work References: <3f4a67a9@news.012.net.il> Message-ID: <3f4e4838$1@news.012.net.il> "Gerhard H?ring" wrote in message news:mailman.1061883744.31168.python-list at python.org... > If you start Python 2.3 with c:\python23\python.exe (or whereever you > installed Python 2.3), you get an error message that python22.dll is not > found? If you did something different, please describe exactly what you > were doing. The crash happens when I run IDLE and when I run python.exe and try to import anything. Avner. From jacek.generowicz at cern.ch Fri Aug 22 08:17:14 2003 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 22 Aug 2003 14:17:14 +0200 Subject: For Kenny Tilton: Why do I need macros revisited. References: <3f45484f$1_6@corp.newsgroups.com> <3F45A7BF.4060806@nyc.rr.com> <8dk1b.2825$Ej6.1159@newsread4.news.pas.earthlink.net> Message-ID: "Andrew Dalke" writes: > http://www.schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-3.html#%_sec_ > Temp_4 > ] As Scheme became more widespread, local dialects began to > ] diverge until students and researchers occasionally found it difficult > ] to understand code written at other sites. That has probably more to do with the fact that Scheme is minimalistic. And if you have a minimalistic langugage, you end up having to implement a lot of utilities before you can get on with what you are actulally trying to achieve (or have your language implementation provide them as extensions). Schemers criticize Common Lisp for being too big. The consequence of having a big language (a la CL, not a la C++) is that most things that "everybody" needs are already in the language. In Scheme "everybody" ends up re-inventing the things that "everybody" needs, separately, leading to fragmentation. In CL, everybody agrees on how to implement the things that "everybody" needs: you use the ones defined by the standard. In this way, any macro-magic is restricted to the domain specific corners of your application. In summary, I reckon that any inter-Scheme incomprehensibility or Scheme fragmentation results from starting with a language that doesn't offer enough out of the box. From logiplex at qwest.net Fri Aug 22 15:26:20 2003 From: logiplex at qwest.net (Cliff Wells) Date: Fri, 22 Aug 2003 12:26:20 -0700 Subject: visual indentation In-Reply-To: References: Message-ID: <1061580380.1506.309.camel@software1.logiplex.internal> On Fri, 2003-08-22 at 11:10, Hilbert wrote: > Hello, > > I'm using python to output RIB streams for Renderman. > The RIB stream is a bunch of statements which describes > a 3d image. The Rib standard allows for blocks which we > usually indent for better visualization for example: > > WorldBegin > Color [1 1 1] > Surface "constant" > Sphere(1.0, -1.0, 1.0, 360) > WorldEnd > > I'm using CGKit in python which has a Renderman binding, > so to output the same RIB I'd write: > > RiWorldBegin() > RiColor(1.0,1.0,1.0) > RiSurface('constant') > RiSphere(1.0,-1.0,1.0,360) > RiWorldEnd() > > But I get an error, because python interprets my indentation > as a block in the python code. So the only way to write this > is without the indentation: > > RiWorldBegin() > RiColor(1.0,1.0,1.0) > RiSurface('constant') > RiSphere(1.0,-1.0,1.0,360) > RiWorldEnd() > > But this is a lot harder to read. > > Is there any way to use such "visual" indentation in python? How about this? It creates a bit of unnecessary overhead (a single tuple creation), but looks okay visually (and Emacs correctly indents it): RiWorldBegin() ( RiColor(1.0,1.0,1.0), RiSurface('constant'), RiSphere(1.0,-1.0,1.0,360), ) RiWorldEnd() Regards, -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 (800) 735-0555 From ekoome at yahoo.com Thu Aug 14 07:36:15 2003 From: ekoome at yahoo.com (Eric) Date: 14 Aug 2003 04:36:15 -0700 Subject: Excel COM Addin Message-ID: I would like to Write an Excel Addin like the Outlook Addin in the COM samples but i am stuck since after examining the windows registry, there is no Excel addin Key. The application would utilise interface IDTExtensibility2 to create buttons and menus on excel which will be hooked up to perform certain functions. How can i go about doing this? Please help. Koome From harry.g.george at boeing.com Mon Aug 11 15:07:56 2003 From: harry.g.george at boeing.com (Harry George) Date: Mon, 11 Aug 2003 19:07:56 GMT Subject: Python vs. C# References: <3f357a9b@shknews01> Message-ID: Christopher Barber writes: > "Terry Reedy" writes: > > > "Brandon J. Van Every" wrote in message > > news:3f357a9b at shknews01... > > > What can I do with Python that I can't do with C#? > > > > Given that all Turing complete languages are theoretically equivalent, > > nothing, either way. > > Turing equivalence is probably the least interesting property of any > programming language and says absolutely nothing about its suitability for > real programming tasks. > True, and that was probably why it was mentioned. Personally I make the same point by saying "Sure we could do it in XYZ language, but then we could also do it assembler. On the other hand, if you want it done on time, with the available resources, and a hope of maintaining it later, then look at Python." > -- harry.g.george at boeing.com 6-6M31 Knowledge Management Phone: (425) 342-5601 From peter at engcorp.com Thu Aug 21 11:20:39 2003 From: peter at engcorp.com (Peter Hansen) Date: Thu, 21 Aug 2003 11:20:39 -0400 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: <240b1020.0308201722.d1b991c@posting.google.com> Message-ID: <3F44E347.6789EB86@engcorp.com> Jeffrey P Shell wrote: [an excellent, lengthy article contrasting Python and Ruby] Article saved permanently. This is the only good thing to come out of this thread so far. Thanks Jeffrey! -Peter From john at rygannon.com Tue Aug 12 04:26:15 2003 From: john at rygannon.com (BadJake) Date: Tue, 12 Aug 2003 08:26:15 GMT Subject: PYTHON AND C++ References: Message-ID: <3f38a42b$0$245$fa0fcedb@lovejoy.zen.co.uk> Hi We use Phil Thompson's exellent interface genentor - SLIP You can download SLIP from Phil's web site at http://www.riverbank.demon.co.uk Regards John From newsgroups at jhrothjr.com Sat Aug 30 07:36:41 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Sat, 30 Aug 2003 07:36:41 -0400 Subject: Add two dicts References: <86ktkvkd05e88hu14hjudmfvbul7slfgkt@4ax.com> <3F4EDF7A.C9CF6DA3@alcyone.com> <0mrtkv8b1bnnk1v310kf3b8tmjo8d9higo@4ax.com> Message-ID: "Greg Brunet" wrote in message news:vl0gbotgl3sibf at corp.supernews.com... > "Alex Martelli" wrote in message > news:BjE3b.7850$aG6.251286 at news1.tin.it... > > Afanasiy wrote: > > > > > On Thu, 28 Aug 2003 22:07:06 -0700, Erik Max Francis > > > > wrote: > > > > > >>Afanasiy wrote: > > >> > > >>> Can I add two dicts in a way which is not cumbersome to the above > % > > >>> string > > >>> operation? Is this another case of writing my own function, or > does a > > >>> builtin (or similar) already exist for this? > > >> > > >>combinedDict = aDict.copy() > > >>combinedDict.update(anotherDict) > > >> > > >>If that's cumbersome, don't really know what you'd consider > > >>non-cumbersome. > > > > > > Don't really know if you're asking, but : > > > > > > vars(self)+{'x':'123','y':'345'} > > > > > > I would consider that non-cumbersome. ;-) > > > > So, what about: > > > > def dict_add(adict, another): > > result = adict.copy() > > result.update(another) > > return result > > > > and then dict_add(vars(self), {'x':'123','y':'345'}) ? But in fact > > you can do even better...: > > > ... lots of other good ideas... > > But what about something like this: > > >>> class xdict(dict): > ... def __add__(self,dict2): > ... result = self.copy() > ... result = result.update(dict2) > ... > > I was hoping that would allow: > >>> a=xdict({'y': 456, 'x': 111}) > >>> b=xdict({'y': 444, 'z': 789}) > >>> a+b > > but instead of the result which I hoped for, I get the following: > > Traceback (most recent call last): > File "", line 1, in ? > TypeError: unsupported operand type(s) for +: 'xdict' and 'xdict' > > So I can't implement '+' operator for dictionaries - why not? The special functions can only be defined in the class definition. They cannot be added afterwards. This is a compiler optimization to avoid having to do dictionary lookups on every operator. If you want to do this, subclass dict. John Roth > > -- > Greg > > > From belred1 at yahoo.com Sun Aug 3 21:32:50 2003 From: belred1 at yahoo.com (Bryan) Date: Mon, 04 Aug 2003 01:32:50 GMT Subject: popen eating quotes? References: Message-ID: <6JiXa.57926$Ho3.8715@sccrnsc03> "Rob Williscroft" wrote in message news:Xns93CDD4975617ukcoREMOVEfreenetrtw at 195.129.110.201... > Bryan wrote in news:LOgXa.57808$o%2.28737 at sccrnsc02: > > >>>> import os > >>>> def run_args(arg): > > ... i, o = os.popen4('"c:/program files/test/args.bat" -vv %s' % arg) > > ... print o.read() > > ... > >>>> run_args('"this is a very long path with spaces"') > > 'c:/program' is not recognized as an internal or external command, > > operable program or batch file. > > > > > > I just got the following working where os.getcwd() is returning: > 'C:\\Documents and Settings\\Rob\\Desktop' > > > >>> def f(): > ... i, o = os.popen4( "\"" + os.getcwd() + "\\aaa.bat\"" ) > ... print o.read() > ... i.close() > ... o.close() > ... > > > If this dosen't help, then (sound of large hammer being removed > from a tool box) maybe this will: > > def g(arg): > x = os.getcwd() > os.chdir( "c:/program files/test/" ) > i, o = os.popen4( 'args.bat -vv %s' % arg ) > os.chdir( x ) > print o.read() > > > Rob. > -- > http://www.victim-prime.dsl.pipex.com/ rob, thanks... this is exactly the solution i came up with too. it does remove the path, but not the spaces in the file name. i _might_ be able to live with this hack though. the code i'm porting to python is from perl, and the perl code doesn't have the popen issue. @xxxoutput=`xxx -vv "$file"`; now i won't be able show how cool python is :( bryan From Franck.BUI-HUU at gemplus.com Fri Aug 22 07:52:46 2003 From: Franck.BUI-HUU at gemplus.com (Franck Bui-Huu) Date: Fri, 22 Aug 2003 13:52:46 +0200 Subject: for iteration Message-ID: <3F46040E.8000208@gemplus.com> Hello, I'm trying to customize a list by overriding __getitem__ method but this change seems to not work with for iteration. When I use my customized list in a for iteration, all changes made in __getitem__ are not take into account. How can I modify this behaviour ? Thanks From tebeka at cs.bgu.ac.il Sun Aug 24 04:00:42 2003 From: tebeka at cs.bgu.ac.il (Miki Tebeka) Date: 24 Aug 2003 01:00:42 -0700 Subject: Comments on my "Python Introduction" slides Message-ID: <33803989.0308240000.35b9bf1f@posting.google.com> Hello All, I'll be doing a small internal course on Python at my company. The 1'st session is an introduction that should also sell Python. If you have the time I'd appriciate any comments on my slides at http://www.cs.bgu.ac.il/~tebeka/pyintro.html Keep in mind that the "students" are people writing real time and use scripting mostly for small applications that usually communicate with hardware, parse binary files, etc. TIA. Miki From amk at amk.ca Wed Aug 13 08:24:11 2003 From: amk at amk.ca (A.M. Kuchling) Date: Wed, 13 Aug 2003 07:24:11 -0500 Subject: Python vs. C# References: <2259b0e2.0308100616.55b651ca@posting.google.com> <3f36af20@shknews01> <3f3959e3_1@news.vo.lu> <3F39B8A3.68B9D623@alcyone.com> Message-ID: On Wed, 13 Aug 2003 10:26:10 +0200, Fredrik Lundh wrote: > is naggum still posting to the net? The most recent Google Groups posting for him is Jan. 13 2003. comp.lang.lisp has since settled down into discussion that are mostly about Lisp, not about newsgroup etiquette, Scheme/Lisp flamewars, and personal attacks. --amk (www.amk.ca) It serves the purpose of not serving a purpose, surely quite a valid one. -- Peter Greenaway, in an interview in _Artforum_, Nov. 83 From aleax at aleax.it Thu Aug 21 04:19:41 2003 From: aleax at aleax.it (Alex Martelli) Date: Thu, 21 Aug 2003 08:19:41 GMT Subject: What's better about Ruby than Python? References: <3F40892D.AEF4AAE@alcyone.com> <87isov6pk4.fsf@pobox.com> <3F412081.5EF7279C@alcyone.com> <874r0ey9bx.fsf@pobox.com> Message-ID: Roy Smith wrote: > jjl at pobox.com (John J. Lee) wrote: >> I read the whole of Stroustrup and a couple of other books >> before writing a line of C++ > > You're a sick puppy :-) I'm very much made out of the same cloth, though age has slowly and gradually moved me a little bit towards mainstream. When I was 9 -- and every relative and friend kidded me about it for YEARS -- I decided I wanted to make paper planes. So I did the obvious thing -- walked into my favourite bookshop and got their best-appearing two books on paper-plane making. Surely I should not start cutting and folding paper until I had read a couple of books about it?! [[my parents HAD opened an account for me at the bookshop, so I could get any book and they'd pay for them all at the end of the month -- libraries not being very good in Italy, at least at the time, that was an excellent though a bit costly way to encourage my fierce passion for reading...!!!]] Alex From adalke at mindspring.com Thu Aug 21 05:52:04 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Thu, 21 Aug 2003 09:52:04 GMT Subject: What's better about Ruby than Python? References: <3F41505F.69D18CC8@alcyone.com> <66d7kvonvb2n0nqbqahhd5roak7ur81sob@4ax.com> <3f43ef5d_4@127.0.0.1> <3F440A35.9030602@nyc.rr.com> <4o_0b.1665$Ej6.1182@newsread4.news.pas.earthlink.net> Message-ID: <8D01b.1721$Ej6.702@newsread4.news.pas.earthlink.net> Alex Martell: > ... def __get__(self, obj, cls): > ... self.obj = obj > ... return self.cached_call That's the part where I still lack understanding. class Spam: def f(self): pass f = CachedCall(f) obj = Spam() obj.f() Under old-style Python obj.f is the same as getattr(obj, "f") which fails to find 'f' in the instance __dict__ so looks for 'f' in the class, and finds it This is not a Python function, so it does not get bound to self. It's simply returned. obj.f() takes that object and calls it. In my original code (not shown) I tried implementing a __call__ which did get called, but without the instance self. Under new-style Python obj.f is the same as getattr(obj, "f") which fails to find 'f' in the instance __dict__ so looks for 'f' in the class, and finds the CachedCall. Python checks if the object implements __get__, in which case it's called a descriptor. If so, it's called with the 'obj' as the first parameter. The return value of this call is used as the value for the attribute. Is that right? > should closely mimic your semantics, including ignoring > what I call obj and you call self in determining whether > a certain set of argumens is cached. Why should obj make a difference? There's only one CachedCall per method per .... Ahh, because it's in the class def, not the instance. Adding support for that using a weak dict is easy. Yeah, and my approach won't work with kwargs nor any other unhashable element. Since I didn't know what the Lisp code did nor how Lisp handles unhashable elements, I decided just to implement the essential idea. Andrew dalke at dalkescientific.com From jarausch at skynet.be Wed Aug 20 04:25:17 2003 From: jarausch at skynet.be (Helmut Jarausch) Date: Wed, 20 Aug 2003 10:25:17 +0200 Subject: 'name is too long' (tarfile, python 2.2, Debian Woody) In-Reply-To: References: Message-ID: <3F43306D.3080704@skynet.be> Lars Behrens wrote: > Hi, Pythonistas! > > I'm quite new to Python and have a problem with a simple backup script. > > This code: > > tar = tarfile.open('/home/lars/test.tar.gz', 'w:gz') > tar.addfile('/home/lars') > > brings up the following error message: > > ********************************************************************** > /usr/lib/python2.2/site-packages/tarfile.py in addfile(self, tarinfo, > fileobj) > 1289 > 1290 if not prefix or len(name) > LENGTH_NAME: > -> 1291 raise ValueError, "name is too long (>%d)" \ > 1292 % (LENGTH_NAME) > 1293 > > ValueError: name is too long (>100) > ********************************************************************** > The standard tar format allows only names (i.e. complete path) of 100 characters. So in your '/home/lars' are names (fully expanded) which are longer. Please have a look at the documentation of tarfile, there is an option to store extended path names. Most other tar programs (like gnu-tar) support these, as well. -- Helmut Jarausch Lehrstuhl fuer Numerische Mathematik RWTH - Aachen University D 52056 Aachen, Germany From tom_chansky at rocketmail.com Sat Aug 16 19:38:31 2003 From: tom_chansky at rocketmail.com (Thomas Chan) Date: Sat, 16 Aug 2003 23:38:31 GMT Subject: Needs DB-API to connect to SQL Server 2000 Message-ID: <20030816.23383100.1745684727@linux.local> Does anyone know where I can find a DB-API to connect to SQL Server 2000? From mcherm at mcherm.com Thu Aug 28 13:56:31 2003 From: mcherm at mcherm.com (Michael Chermside) Date: Thu, 28 Aug 2003 10:56:31 -0700 Subject: Modifying the {} and [] tokens Message-ID: <1062093391.3f4e424f119bd@mcherm.com> Geoff Howland writes: > This post begins to read as an insult here, and continues. My > incredible gall at thinking something may be better if it was changed > and wanting to try it! I should be pelted with rocks for speaking the > name Jehova. Step back a sec... I didn't find Christos's comments "insulting", and I'm sure they weren't intended that way. You've asked a legitimate question: "Can I change the behavior of the objects created by literal {}, [], "", and ''?". The answer to that question was, "Only if you modify the Python interpreter (written in C)." Now there are a few places you could go from here. One is that you could take the advice of a few folks here and check out Ruby. It's another language which is a lot like Python in many ways, but it's most significant difference is that it DOES allow programmers to do EXACTLY the kind of thing that you are asking for. Another thing you could do would be to explain what it is that you are trying to achieve, and ask people on this list to suggest alternative approaches that WILL work in Python. Perhaps they'll say you need to write "Q({...})" in place of "{...}" everywhere and that will fix your problem. Or maybe there's some clever metaclass trick that will help out. If you want to go this route you should try to describe what problem you are trying to solve (eg: "My developers all come from a Pascal background, and they keep trying to use + and - with dicts as if they were sets."). And then keep an open mind about the responses you receive: some will be off-the-mark and won't fix your problem, but others will be out-of-the-box and WILL fix your problem, just not in the way you had expected. The third approach would be for you to ask questions about WHY the things you wanted don't work in Python. It's NOT an accident, or just that we haven't gotten around to it yet, these were deliberate design decisions. Perhaps once you hear the reasoning you'll find it doesn't apply to what you're doing, or perhaps you will decide that Python as-designed makes sense after all. Since you've already started asking some approach-three style questions, I will see if I can answer them: > [] + [] is allowed. Right? > > {} + {} is not allowed. That's because it's not clear what to do with {1:'a'} + {1:'b'}. Should it result in {1:'a'}? {1:'b'}? {1:['a','b']}? An exception? All of these make sense for different applications, and so Guido decided to prohibit the whole thing and provide specific methods like {}.update() as needed. > len([]) is allowed. > > [].len() is not allowed. Yes it is. It's just spelled a little funny. Try "[].__len__()" instead. > Why? I respect Guidos decsions, Python needs a strong leader to make > them and it got where it is (great language) by having him and the > rest of the community help out in this regard. Well, I don't think so. If Guido wants to do it one way but the community consensus is that another way is better, then I think that Guido should shut up and go with the community. Guido's personal strength is that his approaches very often turn out to make great sense, but sometimes only after you've been trying it for a while, and NOTHING ever makes sense to ALL users. > Is now no one allowed to say "hey, I think this should be done, and > I'd like to make it happen to give it a try"? It's not only allowed, it's encouraged! Python is open source, so you can just grab a copy and try out your ideas. You can even try talking someone else into helping you try them out. Submit a patch, and it might get accepted. Write a PEP (no coding skill required) and you might recruit others to write it for you. An extreme example is Stackless Python. YEARS ago, Christian Tismer wanted to try a very different approach to managing the call stack in Python. His changes never got accepted into the core, but now Stackless exists as a separate distribution. And although it took a while, I'd say that now Christian probably favors that approach (sorry Christian if I'm mis-channeling you here): cPython's approach has some advantages (eg: portability), and Stackless has others (eg: microthreads). > >With all due respect, Geoff, if this stuff is really important to you, > >use Ruby. > > Yes, throw the heathen into another language. I'm not good enough for > this one. > > I find this attitude really insulting. It wasn't intended that way. Seriously... Python *INTENTIONALLY* prohibits you from doing what you are asking for. Ruby is a similar language that allows, even encourages it. That's worth pointing out -- and maybe worth checking out. But as Christos said "with all due respect" -- he's presuming that you ARE serious here and DO want these features, and he's suggesting one way of getting them. -- Michael Chermside From dtolton at yahoo.com Sun Aug 24 03:15:31 2003 From: dtolton at yahoo.com (Doug Tolton) Date: 24 Aug 2003 00:15:31 -0700 Subject: macro FAQ References: Message-ID: <1ffd32d9.0308232315.3eadd758@posting.google.com> Jacek Generowicz wrote in message news:... > > Macros can modify other code to make it fit the problem better, > > What do you mean by "other" code? Macros modify the code that is > passed to them as an argument, transforming it before the compiler > gets to see it. I get the impression that you believe that macros can > somehow modify code from other parts of the program. They can't. > > Ultimately, macros just save you a lot of typing of source code. (And > thereby save you a lot of bugs.) If you can't type it as soure code, > then a macro can't do it. > > > while functions only use other code but make no modifications. > > This only strengthens the above suspicion, but I'm not really sure > what you mean, here. > > > This makes them very powerful but means that understanding a section > > of code requires also knowing about any macros which might use the > > code. > > What do you mean by "macros using code" ? > > The macros are part of the code, just like functions are. To > understand the code, you must understand what the macros and functions > do. > > > In an extreme case which wouldn't be used in real projects, every * > > could be replaced with a +. > > This almost completely convinces me that you are very confused about > what macros can achieve. > > Either, you are suggesting that one might write a macro which replaces > every * operator with a + operator, and then pass _the entire source > code_ of a project to it (possible, but patently absurd); or you are > suggesting that it is possible to write a macro "over here" which, > somehow, surreptitiously modifies existing source code "over there". > > a) Macros cannot do the latter. > > b) You can achieve something very similar in Python, by re-binding > attributes of __builtins__. > > Think of the point of macros in another way. The point is _not_ to > take existing source code, and to change it. The point is to take > something that is not (necessarily) valid source code, and turn it > into valid source code, before the compiler gets to see it. Why? > Because this allows you to create a shorthand notation, and use macros > to expand it to real code. Think in terms of encoding design patterns. > I think Jacek has made an extremely good point here, and I want to follow up on it to determine if everyone has a clear understanding of what macros are and are not. Following I have outlined a series of questions an answers to attempt to illuminate the issue. Please suggest any clarifications or distinctions that need to be made. Also note that the examples presented are purposefully trivial and could in many instances be accomplished other ways, however I am presenting these examples in order to provide a meaningful context to proceed from. Question: What are Macros? Answer: Macros are an advanced templating system that allow dynamic evaluation of code during run time. Essentially Macros allow you to pass in some variables that are then expanded into valid Python syntax which is then executed. Question: Can't I accomplish this same functionality via string parsing and eval? Answer: Eval will accept any valid Python expression and execute it. This is however regarded by many as a security hole. Macros allow this type of expressiveness while limiting many of the security risks. With a Macro you can more specifically control what types of actions are permissible. Question: I have some existing modules, if I import a macro from someone else, could the macro make my existing code perform in unexpected ways? Answer: No. A macro doesn't modify existing code, in order to invoke a macro it must be called just like a function call. So a Macro couldn't alter the functionality of existing code any more than a function could. The only way to accomplish such a feat would be to manually open each file and parse through them and re-evaluate them. This type of functionality is not what macros are about any more than a function call would be. Question: How would Macros work in practice? Answer: Here is a trivial example macro to start with: def HelloFunc(message): print "%s\n" % (message) defmacro uselessmacro(message): macroexpansion = "HelloFunc(%s)" % (message) defmacro callfunc(funcname, message): macroexpansion = """ calllog = open("/var/log/functions.log", "a") calllog.write("%(funcname)s was called.\n") calllog.flush() calllog.close() %(funcname)s(%(message)s) """ % locals() if __name__ == "__main__": uselessmacro("Hello World") callfunc("HelloFunc", "Hello World") # Note, Jacek's method of using indentation is an interesting alternative to calling them as a # function. # Second note, this textarea box does not have a compiler, so please forgive any syntax errors :) uselessmacro simply passes it's arguments through to HelloFunc undisturbed callfunc logs all calls to a function before evaluating the function You could clearly accomplish this functionality using other means, however I have used such a trivial example in order to illustrate several points: 1) Macros once they are defined would most likely be invoked the same way any other function call would be or represented as a block of code. 2) Macros taken in isolation would not allow any strange changes to the language to be made (eg changing all *'s to +'s, or changing the behavior of existing classes - metaclasses, builtins and magic methods are required for this) 3) Understanding a macro's behavior is typically easy for someone familiar with Python's syntax and constructs. In otherwords a Macro allows you to encapsulate commonly used idioms into a cleaner syntax, but would not allow you to alter the behavior of the language itself. My examples are barely touching the surface of what is possible with macros, but I wanted to start with some simple examples in order to give everyone some solid examples of what Macros are, and what Macros are not. From bignose-hates-spam at and-benfinney-does-too.id.au Fri Aug 22 18:43:48 2003 From: bignose-hates-spam at and-benfinney-does-too.id.au (Ben Finney) Date: 23 Aug 2003 08:33:48 +0950 Subject: visual indentation References: <3F4660CB.FF72D945@easystreet.com> Message-ID: On Fri, 22 Aug 2003 13:06:46 -0700, Gary Herron wrote: > Hmmmm -- I'll bet there's more possibilities. All of which, like all possibilities for forcing different indentation on Python, presented so far, *reduce* readability instead of enhancing it. -- \ "One time a cop pulled me over for running a stop sign. He | `\ said, 'Didn't you see the stop sign?' I said, 'Yeah, but I | _o__) don't believe everything I read.'" -- Steven Wright | Ben Finney From shalehperry at comcast.net Fri Aug 8 04:39:11 2003 From: shalehperry at comcast.net (Sean 'Shaleh' Perry) Date: Fri, 8 Aug 2003 01:39:11 -0700 Subject: ???? i can`t understand it In-Reply-To: References: Message-ID: <200308080139.11771.shalehperry@comcast.net> On Friday 08 August 2003 01:11, Enrique wrote: > >>> a=[1,2,3,4,5] > >>> for b in a: > > ... a.remove(b) > ... > > >>> a > > [2, 4] does this help?? >>> a = range(1,6) >>> for b in a: ... print b ... a.remove(b) ... 1 3 5 >>> a [2, 4] I read this as "do not remove items from a list you are iterating over". Pretty sure the docs comment on this as well. What seems to happen is b = 1, 1 is removed from a. b should then be 2. But the internal counter skips it and goes to 3. So what i see happening is: next = 0 for b = a(next): a.remove(b) next += 1 so a[1] is 3 when we expect it to be 2 because 2 is now at index a[0]. From jbar at lf1.cuni.cz Tue Aug 12 09:58:53 2003 From: jbar at lf1.cuni.cz (Jiri Barton) Date: Tue, 12 Aug 2003 15:58:53 +0200 Subject: MySQLdb and Python2.3 References: Message-ID: <3f38f31b@shknews01> I run MySQLdb 0.9.2-0.3 Python 2.3-1 Debian GNU/Linux unstable without a problem. Can you post the piece of code that causes this, and the schema of the table? Jiri Barton From fatherbob70 at yahoo.com Sat Aug 30 00:25:39 2003 From: fatherbob70 at yahoo.com (Rob Andrews) Date: Sat, 30 Aug 2003 04:25:39 GMT Subject: Update to Python 2.3 on Red Hat Linux 9 References: <8242f4a7.0308282240.4c87f997@posting.google.com> <8242f4a7.0308291913.63bcc19b@posting.google.com> Message-ID: <7HV3b.2450$sl.138883@twister.austin.rr.com> Aside from the fact that I haven't been using pygtk, your situation sounds similar to one I've been trying to resolve in the occasional free moment lately. I posted to c.l.p on 8-27 with the subject "homebrew 2.3 install on RedHat9 not playing nice with Tkinter" and have not yet satisfactorily resolved it. So if you have amazing success, by all means feel free to share the details. regards, Rob Jay Bromley wrote: > I've done some playing and if I can get the sys.path the same for both > versions most of the libraries seem to be ok, so that's the next shot, > doing some more reading to see how I can config 2.3 to have the same > sys.path as 2.2.2. From sross at connectmail.carleton.ca Thu Aug 28 21:35:34 2003 From: sross at connectmail.carleton.ca (Sean Ross) Date: Thu, 28 Aug 2003 21:35:34 -0400 Subject: crazy programming language thoughts References: <3rv3b.6241$yg.2305230@news4.srv.hcvlny.cv.net> Message-ID: <35y3b.3262$_F1.545316@news20.bellglobal.com> "Ryan Lowe" wrote in message news:3rv3b.6241$yg.2305230 at news4.srv.hcvlny.cv.net... > what i am attempting to figure out, is if there is > a way to improve the intuitiveness of the python's syntax, specifically > concerning functions. Hi. I'm pretty sure you will not find a lot of support in this forum for changing Python in the way that your hoping. You're pretty much proposing a new language, not just enhancements for an existing one. But, whatever ... Personally, I really like the *idea* of an english-like programming language - I'd like to make one myself, and I think it'd be a fine toy for simple scripting. However, I also think it would become cumbersome as the scale of your projects grew. Heck, it's cumbersome even when your projects are small. English is not always the most concise way to say something, nor is it always the most clear. Take the following Applescript code for example: What is the result of each of these statements: words from paragraph 2 to paragraph 4 words of paragraphs 2 thru 4 text from paragraph 2 to paragraph 4 text of paragraphs from 2 to 4 They're all different. The answers can be found here: http://www.applescriptsourcebook.com/tips/gotchas/ranges.html > do you think it would confuse people in terms of which part is a parameter > of what when combining 2 functions like the combo example? In Applescript, you can (optionally) use parenthesis to (attempt to) disambiguate. So, for example, in your case, doing something like replace av with bv in (listv joined with gluev) might make things a bit clearer. > i havent figured out how to de-dottify class functions and class > attributes. Well, you could do something like this (applescript-like, again): -- If you have an instance of the class set the attribute of instance's class to value -- or set the attribute of the class of instance to value -- or, maybe even, get the attribute of instance's class set it to value -- And, if you don't have an instance, or you just want to get there directly set className's attribute to value Anyway. It's an interesting idea (your language) - not a new idea, but an interesting one. If you want to play around with something very much like Applescript, but you don't have a Mac, you can get a trial version of MetaCard (www.metacard.com). And, if you really want to make your own language, you could use SPARK, as a start, to whip up a (slow) prototype to mess around with and see how things should go together. As for getting Python to _become_ your language ... well, good luck with that. Sean From vattekkat.babu at verizon.net Tue Aug 19 22:19:14 2003 From: vattekkat.babu at verizon.net (Vattekkat Satheesh Babu) Date: Wed, 20 Aug 2003 02:19:14 GMT Subject: How to save web pages for offline reading? References: <84fc4588.0308182224.6186a988@posting.google.com> Message-ID: In case you need to automate IE's File-SaveAs; http://vsbabu.org/mt/archives/2003/06/13/ie_automation.html I had to do this once because a closed source web app was generating different pages for IE and everything else... - Babu http://vsbabu.org/ From geoff at gerrietts.net Thu Aug 28 00:54:46 2003 From: geoff at gerrietts.net (Geoff Gerrietts) Date: Wed, 27 Aug 2003 21:54:46 -0700 Subject: finding object using IS instead of == In-Reply-To: References: Message-ID: <20030828045446.GB19170@isis.gerrietts.net> Quoting Mark Hahn (mark at hahnca.com): > > If I have a large collection (list, tuple, or dict) of objects, > > can I locate one quickly that matches a given object using the IS > > equivalence operator instead of the value == operator? > > Clarification: Is there a FASTER way that takes advantage of the IS > equivalence than using the available == method. I assume the == > method does a linear search, except for a dict key lookup, which is > not what I'm talking about. > > Obviously if two references are the same object (IS equivalent) then > they are == also so you could find based on == and then check for > IS, but I want something faster. I'm not exactly sure how to answer your question. The short answer might be "yes" but I can't produce a long answer because I'm not even sure the short answer is right, for the question you're asking. An example might help? Let's say you have a large list of O objects L1: class O: def __init__(self, oid): self.oid = oid L1 = [O(oid) for oid in range(50000)] And somehow, you have a handle to one of those O objects: handle = L1[random.randint(0,49999)] You can do a search to retrieve it (them) using 'is': matches = [o for o in L1 if o is handle] But is this useful to your specific problem domain? That's harder to answer. Thanks, --G. -- Geoff Gerrietts "That's it! I've had it with your sassy mouth! I didn't want to do this! (Well, actually, http://www.gerrietts.net/ I did....)" -- Mojo Jojo, "Bubblevicious" From peter at engcorp.com Thu Aug 28 18:14:49 2003 From: peter at engcorp.com (Peter Hansen) Date: Thu, 28 Aug 2003 18:14:49 -0400 Subject: OT: Americans love their guns References: Message-ID: <3F4E7ED9.924AEAF2@engcorp.com> Dave Brueck wrote: > > On Thursday 28 August 2003 12:40 pm, Lulu of the Lotus-Eaters wrote: > > |The odds of getting killed that way are roughly the same as the odds > > |that you'll die from aspirin or similar drugs > > > > No... this one is just way off. According to above URL form: > > > > 2000, United States > > Adverse effects - Drugs Deaths and Rates per 100,000 > > All Races, Both Sexes, All Ages > > ICD-10 Codes: Y40-Y59,Y88.0 > > > > Number of Deaths Population Crude Rate Age-Adjusted Rate** > > 255 275,264,999 0.09 0.09 > > Aren't statistics fun? :) > > Think about it: even intuitively, 255 is *way* too low for a population of 275 > million (that's essentially zero - in a population that size 255 people > probably die in sneezing-releated incidents every year) - I don't think that > statistic represents what you think it represents. Dave, I think you missed the "rates per 100,000" part, above. That means roughly 700,000 deaths for the population given, not 255. -Peter From bokr at oz.net Mon Aug 4 15:27:25 2003 From: bokr at oz.net (Bengt Richter) Date: 4 Aug 2003 19:27:25 GMT Subject: Match beginning of two strings References: Message-ID: On Mon, 04 Aug 2003 11:56:04 GMT, Alex Martelli wrote: >Ravi wrote: > >> Hi, >> >> I have about 200GB of data that I need to go through and extract the >> common first part of a line. Something like this. >> >> >>>a = "abcdefghijklmnopqrstuvwxyz" >> >>>b = "abcdefghijklmnopBHLHT" >> >>>c = extract(a,b) >> >>>print c >> "abcdefghijklmnop" >> >> Here I want to extract the common string "abcdefghijklmnop". Basically I >> need a fast way to do that for any two given strings. For my situation, >> the common string will always be at the beginning of both strings. I can > >Here's my latest study on this: > >*** pexa.py: > [...] JFTHOI, if you have the inclination, I'm curious how this slightly different 2.3-dependent version would fare in your harness on your system with the rest: def commonprefix(s1, s2): # very little tested! try: for i, c in enumerate(s1): if c != s2[i]: return s1[:i] except IndexError: return s1[:i] return s1 [...] > >and my measurements give me: > >[alex at lancelot exi]$ python -O timeit.py -s 'import pexa' \ >> 'pexa.extract("abcdefghijklmonpKOU", "abcdefghijklmonpZE")' >100000 loops, best of 3: 2.39 usec per loop >[alex at lancelot exi]$ python -O timeit.py -s 'import pexa' >'pexa.extract("abcdefghijklmonpKOU", "abcdefghijklmonpZE")' >100000 loops, best of 3: 2.14 usec per loop >[alex at lancelot exi]$ python -O timeit.py -s 'import pexa' >'pexa.extract2("abcdefghijklmonpKOU", "abcdefghijklmonpZE")' >10000 loops, best of 3: 30.2 usec per loop >[alex at lancelot exi]$ python -O timeit.py -s 'import pexa' >'pexa.extract3("abcdefghijklmonpKOU", "abcdefghijklmonpZE")' >100000 loops, best of 3: 9.59 usec per loop >[alex at lancelot exi]$ python -O timeit.py -s 'import pexa' >'pexa.extract_pyrex("abcdefghijklmonpKOU", "abcdefghijklmonpZE")' >10000 loops, best of 3: 21.8 usec per loop >[alex at lancelot exi]$ python -O timeit.py -s 'import pexa' >'pexa.extract_c("abcdefghijklmonpKOU", "abcdefghijklmonpZE")' >100000 loops, best of 3: 1.88 usec per loop >[alex at lancelot exi]$ > Interesting, but I think I will have to write a filter so I can see a little more easily what your timeit.py outputs say ;-) Regards, Bengt Richter From bokr at oz.net Fri Aug 15 23:03:05 2003 From: bokr at oz.net (Bengt Richter) Date: 16 Aug 2003 03:03:05 GMT Subject: cPickle alternative? References: Message-ID: On Sat, 16 Aug 2003 00:41:42 +0200, "Drochom" wrote: >Hello, > >> If speed is important, you may want to do different things depending on >e.g., >> what is in those tuples, and whether they are all the same length, etc. >E.g., >> if they were all fixed length tuples of integers, you could do hugely >better >> than store the data as a list of tuples. >Those tuples have different length indeed. > >> You could store the whole thing in a mmap image, with a length-prefixed >pickle >> string in the front representing index info. >If i only knew how do to it...:-) > >> Find a way to avoid doing it? Or doing much of it? >> What are your access needs once the data is accessible? >My structure stores a finite state automaton with polish dictionary (lexicon >to be more precise) and it should be loaded >once but fast! > I wonder how much space it would take to store the Polish complete language word list with one entry each in a Python dictionary. 300k words of 6-7 characters avg? Say 2MB plus the dict hash stuff. I bet it would be fast. Is that in effect what you are doing, except sort of like a regex state machine to match words character by character? Regards, Bengt Richter From __peter__ at web.de Thu Aug 28 02:08:48 2003 From: __peter__ at web.de (Peter Otten) Date: Thu, 28 Aug 2003 08:08:48 +0200 Subject: another puzzled newbie References: <68g3b.855589$ro6.16997110@news2.calgary.shaw.ca> Message-ID: Elaine, it is always a good idea to post the exact error message (cut and paste), (even if it is not particulary helpful in this case) and a short abstract of what your posted piece of code is supposed to do. What I could find out so far: You have forgotten the last ] in the first line of singlePass(): postshuffled += [preshuffled[shuffler[0]]] By the way, open (, [ or { lead Python to assume that the following lines are also part of the list, tuple, dictionary or function call, which often causes misleading error messages. Hope that helps, Peter From belred1 at yahoo.com Mon Aug 4 20:16:12 2003 From: belred1 at yahoo.com (Bryan) Date: Tue, 05 Aug 2003 00:16:12 GMT Subject: pyrex error References: <8YPWa.48874$YN5.38312@sccrnsc01> <7NtXa.62774$uu5.6090@sccrnsc04> Message-ID: "John Machin" wrote in message news:c76ff6fc.0308041422.3d819d78 at posting.google.com... > "Bryan" wrote in message news:<7NtXa.62774$uu5.6090 at sccrnsc04>... > > "Gerhard H?ring" wrote in message news:mailman.1059853685.20382.python-list at python.org... > > > Bryan wrote: > > > > [PyRex produces code using staticforward that won't work in the combination Python 2.3/MSVC] > > > > In the PySQLite sources, I added this snippet on top: > > > > > > #ifdef _MSC_VER > > > #define staticforward extern > > > #endif > > > > > > to make it compilable under MSVC/Python 2.3. *After* #include-ing > > > "Pyhton.h" of course. > > > i've decided to go with gerhard's approach with one minor modification: > > > > #ifdef _MSC_VER > > #undef staticforward > > #define staticforward extern > > #endif > > > > this solution is best for me because i want to take the resulting c file and give it to others so they can compile it on other OS's > > and compilers. > > > > why can't this code be placed in the pyrex header? seems like a simple fix. > > What gave you the impression that it can't be put in? You tell us why > *you* can't put it in. > because i don't have the experience to do so. the fact you think the above #ifdef is a kludge proves it and i'm not even the one who came up with those 4 lines. > I'll tell you why it *shouldn't* be put in: because it's a kludge. The > offending C code is a forward declaration of a char [] which is > subsequently filled in with the name of the source .pyx file which is > known at the time the staticforward is emitted. The principled fix is > to declare and define the array in one hit. From mpeuser at web.de Sat Aug 30 06:14:42 2003 From: mpeuser at web.de (Michael Peuser) Date: Sat, 30 Aug 2003 12:14:42 +0200 Subject: Win32 documentation in CHM? References: Message-ID: "Robin Becker" schrieb im Newsbeitrag news:CDURXJA3QHU$EwUz at jessikat.fsnet.co.uk... > It seems the Gods are proposing to distribute the documentation and help > for Python-2.3.1 in .chm form. I particularly detest .chm and much > prefer .html as it works across all platforms. Additionally by having a > single index.html for all of the various bits of Python help I can link > in things like Pmw, PIL and Quick Guide etc with a simple text editor. > > The argument is made that .chm is a better mechanism (more searchable > indexable etc) for help/documentation than html. Is that really so? HTML > is at least an open standard. chm is more compact and nicely packaged. It in fact is basically nothing but html and you can unpack it if you want. There are lots of tools - look for arCHMage e.g. which is a Unix chm viewer and decompiler... Kindly Michael P From __peter__ at web.de Fri Aug 29 07:53:47 2003 From: __peter__ at web.de (Peter Otten) Date: Fri, 29 Aug 2003 13:53:47 +0200 Subject: opposite of dict.items() References: <3f4e708c$0$64719@hades.is.co.za> Message-ID: Raymond Hettinger wrote: > If you're using Py2.3, then the itertools way is a bit nicer: > >>>> dict(itertools.izip(range(3), "abc")) > {0: 'a', 1: 'b', 2: 'c'} >>> dict(izip(irange(3), "abc")) {0: 'a', 1: 'b', 2: 'c'} If I could use the above in Py2.4, it would be even nicer, namely: - convert itertools to builtins - add irange(), perhaps as an alias for xrange() like file/open That would remove the slant towards the list prcessing functions and encourage lazy people like me to always choose the best solution :-) Peter From raims at dot.com Sun Aug 24 03:09:03 2003 From: raims at dot.com (Lawrence Oluyede) Date: Sun, 24 Aug 2003 09:09:03 +0200 Subject: Python is darn fast (was: How fast is Python) References: <2259b0e2.0308230737.8a9bc1c@posting.google.com> Message-ID: Van Gale wrote: > It also seems that -O2 is faster in many cases than -O3 :/ Yeah, you're right. I ran ccbench on my machine and it told me that the best is gcc -O2 -march=athlon-mp (I have a Duron not an MP :) I tried but it's slower than the one compiled with the gcccpuopt suggested flags. It's funny :) -- Lawrence "Rhymes" Oluyede http://loluyede.blogspot.com rhymes at NOSPAMmyself.com From vze4rx4y at verizon.net Thu Aug 7 20:22:02 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Fri, 08 Aug 2003 00:22:02 GMT Subject: random changes References: Message-ID: "dan" > I did try random.WichmannHill, which gives completely different data > to either the new or the old version. It works for me: Python 2.2.3 (#42, May 30 2003, 18:12:08) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information. IDLE 0.8 -- press F1 for help >>> import random >>> rng = random.Random(1492) >>> rng.random() 0.44575247281897029 Python 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. **************************************************************** Personal firewall software may warn about the connection IDLE makes to its subprocess using this computer's internal loopback interface. This connection is not visible on any external interface and no data is sent to or received from the Internet. **************************************************************** IDLE 1.0 >>> import random >>> rng = random.WichmannHill(1492) >>> rng.random() 0.44575247281897029 Raymond Hettinger From david.bear at asu.edu Thu Aug 28 18:27:25 2003 From: david.bear at asu.edu (David Bear) Date: 28 Aug 2003 15:27:25 -0700 Subject: win32 file attributes Message-ID: Using the windows explorer it is possible to get file properties which include under the version tab, 'company name', 'version', etc. I'm assuming these metadata are actually stored in the exe somewhere. Is there an api exposed to python that would allow me to get this info? a scan of Mark Hammonds win32all package did have anything obvious jump out at me... -- David Bear phone: 480-965-8257 fax: 480-965-9189 College of Public Programs/ASU Wilson Hall 232 Tempe, AZ 85287-0803 "Beware the IP portfolio, everyone will be suspect of trespassing" From logistix at cathoderaymission.net Mon Aug 18 22:56:58 2003 From: logistix at cathoderaymission.net (logistix at cathoderaymission.net) Date: 18 Aug 2003 19:56:58 -0700 Subject: Path Problem on W2K? References: <93f5c5e9.0308170927.6e0bdc38@posting.google.com> <96S%a.2489$k_7.1163@newssvr27.news.prodigy.com> Message-ID: <3c91a864.0308181856.2d9d39a3@posting.google.com> "Dennis Reinhardt" wrote in message news:<96S%a.2489$k_7.1163 at newssvr27.news.prodigy.com>... > > I generally avoid installing in > c:\ProgramFiles\anything. > > c:\progra~1\anything > > is a non-space way of specifying the same path. I hope I don't come off as a know-it-all jerk, but 8.3 filenames are considered legacy in NT/2000/XP. There is a registry hack that will disable them and is commonly recommended in security lockdown and performance tuning documents for Windows. That being said, it's fine to use progr~1 on your personal computer, I just wouldn't count on it working for all Windows installs if you're writing something that you intend to distribute. From aleax at aleax.it Fri Aug 8 11:28:21 2003 From: aleax at aleax.it (Alex Martelli) Date: Fri, 08 Aug 2003 15:28:21 GMT Subject: Anonymous class question References: <3F33B661.1040100@osheim.org> Message-ID: Dan Williams wrote: ... >>>>self.file = type("", (object,), {'close':lambda slf: None})() >>> >> Does that (object,) do something I'm missing? >> >> >>> o1 = type('',(object,),{})() >> >>> o2 = type('',(),{})() >> >>> type(o1).__bases__ >> (,) >> >>> type(o2).__bases__ >> (,) >> >> Regards, >> Bengt Richter > > I thought it made it a new-style class. I could be wrong about that, > though. . . Class whose metaclass is type (and it surely will be, if you instantiate type directly by calling it as you did) ARE "new style" by definition. Don't be confused with the class statement: _then_ you may need to explicitly specify object as a base class [or otherwise set the __metaclass__] in order to have a class be new-style rather than the default 'classic'. But when you explicitly call type, specifiying object as the only base is not necessary (although, it _is_ innocuous). Alex From sdhyok at yahoo.com Sun Aug 10 23:41:35 2003 From: sdhyok at yahoo.com (sdhyok) Date: 10 Aug 2003 20:41:35 -0700 Subject: How to print floating point in scientific format? References: <420ced91.0308081115.7060e551@posting.google.com> Message-ID: <420ced91.0308101941.64361991@posting.google.com> Writing my own function is definitely one choice. But, my point is that if some of us are really serious about scientific/engineering programming, we must have a common function or command to print out whole array elements easily with any format we want. It can be in Numeric (or numarray) package like, import Numeric as N N.print(array, format="%.2E") Daehyok Shin bokr at oz.net (Bengt Richter) wrote in message news:... > On 8 Aug 2003 12:15:53 -0700, sdhyok at yahoo.com (sdhyok) wrote: > > >I want to change the DEFAULT behavior of python > >to print out all floating points in scientific format? > >For instance, > > > >>x=0.01 > >>print x > >1.000000E-2 #Like print "%E"%x > > > >How can I do it? > > > Do you have to use the print statement per se for output? > I.e., why couldn't you write > > sciPrint( x, whatever, etc ) > > instead of > > print x, whatever, etc > > Then you could customize sciPrint as you please. > Or do you have to change the behaviour of existing modules without > changing their source? > > Regards, > Bengt Richter From dan at osheim.org Wed Aug 6 21:42:28 2003 From: dan at osheim.org (Dan Williams) Date: Wed, 06 Aug 2003 20:42:28 -0500 Subject: Anonymous class question Message-ID: Python experts, Is there a more pythonic way to do something evquilent to what this line does without creating a dummy class? self.file = type("", (object,), {'close':lambda slf: None})() As you can guess, I want a dummy object that I can call close on with impunity. I've been reading _Python in a Nutshell_ (Thanks, Alex!), which defines a Bunch class that I think could also work, but if I'm only going to use it to define a class with a dummy close() method, I might as well just create the dummy class with the dummy method. . . Unless there is something equvilent to Bunch in one of the standard modules that I don't know about . . .? From abcdebl2nonspammy at verizon.net Wed Aug 6 01:17:19 2003 From: abcdebl2nonspammy at verizon.net (David Lees) Date: Wed, 06 Aug 2003 05:17:19 GMT Subject: Problem w/ IDLE on Win2000 In-Reply-To: References: Message-ID: Thomas Rivas wrote: > Unable to launch IDLE(fork?) from the new Py 2.3. Anybody else have this > problem. Solutions? > > Thanks. > > Tom Rivas > > > I think I have the same problem. When the Win2000 Start menu, 'IDLE' icon is clicked, the hourglass-wait icon goes on for a second and then disappears. I can see a new process startup 'pythonw.exe', but nothing appears on the screen. I believe the problem is the same one previously discussed with respect to Windows XP. IDLE can not be in a path where any of the directory names have a space. Unfortunately, 'program files' has a space in it. I found that I can start idle up by going directly to the idle executable which on my pc is under: 'program files\python23\lib\idlelib\idle.exe Creating a shortcut to IDLE and then placing it on my desktop seems to work just fine for starting it up. David Lees From peter at engcorp.com Fri Aug 22 11:37:02 2003 From: peter at engcorp.com (Peter Hansen) Date: Fri, 22 Aug 2003 11:37:02 -0400 Subject: how fast is Python? References: <3F44DFEB.60AB6492@engcorp.com> Message-ID: <3F46389E.EED13B35@engcorp.com> dan wrote: > > Peter Hansen wrote in message news:<3F44DFEB.60AB6492 at engcorp.com>... > ... > > And in those very few cases, so far, I have consistently concluded > > I'm happy enough with the speed of Python given that the speed of > > *development* in Python is easily 5 to 10 times faster than the > > speed of development in C. (And again, it's easy to find cases > > outside of this range, on either side...) > > > I pretty much agree. The point of my question was not to knock Python > -- I'm simply curious how fast, _in_principle_, a language like Python > could be made to run. > > I've looked at Psyco and Pyrex, I think both are interesting projects > but I doubt anything in the Py world has had nearly the kind of > man-hours devoted to optimization that Java, C++, and probably C# have > had. Oh, I completely misinterpreted the question then. I thought you wanted practical information. _In principle_, (which I'll interpret as "in theory"), Python can be made to run even faster than C or C++. In practice, nobody has been able to prove or disprove that theory yet... ;-) -Peter From mis6 at pitt.edu Tue Aug 12 13:12:37 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 12 Aug 2003 10:12:37 -0700 Subject: Is Python your only programming language? References: <3f38fbf3$0$158$a1866201@newsreader.visi.com> Message-ID: <2259b0e2.0308120912.53b28d6f@posting.google.com> grante at visi.com (Grant Edwards) wrote in message news:<3f38fbf3$0$158$a1866201 at newsreader.visi.com>... > Anybody who thinks there's only one programming > language for all tasks is seriously deluded. Yes, but a programmer does not necessarily need to perform ALL tasks. It may very well be that Python fullfill 99% of what an average programmer needs. I personally know various languages, but at the end I only use Python since it fullfills all my needs and it is faster to develop in it that in any other language. Michele From yinyang at eburg.com Thu Aug 14 12:37:19 2003 From: yinyang at eburg.com (Gordon Messmer) Date: Thu, 14 Aug 2003 09:37:19 -0700 Subject: IO timeout in threaded application In-Reply-To: <3F397C27.9030003@eburg.com> References: <3F37EB6E.4080306@real.com> <16183.61048.228691.131382@montanaro.dyndns.org> <3F3923EC.9000703@eburg.com> <3F397C27.9030003@eburg.com> Message-ID: <3F3BBABF.7070201@eburg.com> Gordon Messmer wrote: > Gordon Messmer wrote: > >> The other approach I'd thought about would be to open a pipe and fork >> a process to do the check. The external process could handle signals >> properly. > > This almost works right, except that the new pid ends up as a zombie... > Why doesn't the main thread reap the status of this process? For the archives, in case anyone follows this thread: POSIX systems seem to deliver the SIGCHLD from the forked process to the thread that spawned it, and not to the parent process. Threads block all signals, so there's nothing to reap the status of the process. In order to collect the status of the forked process, the thread that created it must call os.waitpid() with the result of os.fork() as the first argument. Manually collecting the status of the forked process will avoid zombies. From jepler at unpythonic.net Wed Aug 27 08:50:26 2003 From: jepler at unpythonic.net (Jeff Epler) Date: Wed, 27 Aug 2003 07:50:26 -0500 Subject: Generator comprehensions -- patch for compiler module In-Reply-To: References: Message-ID: <20030827125025.GR32191@unpythonic.net> On Tue, Aug 26, 2003 at 10:31:15PM +0000, Raymond Hettinger wrote: > If you put your patch on SourceForge, I'll add a link to it > from the PEP. That way, everyone who is interested in the > subject can experiment with it. http://python.org/sf/795947 > only-a-revolutionary-implements-a-rejected-pep-ly yours, Well, it's only half-implemented, since I didn't touch the written-in-C compiler. It's also half-implemented in terms of lacking tests. Jeff From davecook at nowhere.net Mon Aug 11 04:18:07 2003 From: davecook at nowhere.net (David M. Cook) Date: Mon, 11 Aug 2003 08:18:07 GMT Subject: Python vs. C# References: <2259b0e2.0308100616.55b651ca@posting.google.com> <3f36af20@shknews01> Message-ID: <3jIZa.241585$R92.17560@news2.central.cox.net> In article <3f36af20 at shknews01>, Brandon J. Van Every wrote: > I'm beginning to think that within 5 years, no new applications will be > written in C++. People will still be using legacy C++ libraries, but all > new development will be in higher level langauges. Java and C# are the > obvious languages that are not going away. Python? What industrial entity > is going to champion Python? It takes a Sun, a Microsoft, or overwhelming I read all the way to this point in the thread before wrinkling my nose and looking at the From: line, and then chuckled when I saw the name. Van Every does it again! What an obnoxious know-nothing twit! But the jokes on me for wasting my time with his self-important blather. Dave Cook From harry.pehkonen at hotpop.com Sat Aug 16 15:36:43 2003 From: harry.pehkonen at hotpop.com (Harry Pehkonen) Date: 16 Aug 2003 12:36:43 -0700 Subject: ``Type-checking'' with dir() Message-ID: <70df36e9.0308161136.3c414a80@posting.google.com> In order to leave my classes open to receiving objects that are string-like, list-like, dictionary-like, etc, and not necessarily _exactly_ the built-in string, list, dictionary, etc types, I have the desire to just check if the necessary methods exist. Instead of: if type(a) == type(""): ... . . . I like: wanted_methods = ["__getslice__", "__len__"] if len([ m for m in dir(a) if m in wanted_methods ]) == len(wanted_methods): ... In the above example, I might want to get a slice of variable a if it's length is appropriate. The above code is a simplified in-line version of, say, has_methods(). Any thoughts? Thanks! Harry. From tjreedy at udel.edu Wed Aug 13 02:51:34 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 13 Aug 2003 02:51:34 -0400 Subject: two quick questions References: Message-ID: "Elaine Jackson" wrote in message news:uzk_a.740726$Vi5.16966327 at news1.calgary.shaw.ca... > Two quick newbie questions: > > 1) Does Python have passing-by-reference? Python no. Arg passing is by object binding. CPython uses *PyObject passing to implement this. Human readers do what they do. For more, try to find long thread on function calls/arg passing earlier this year (via Google). You should ask yourself why you ask this, and you might get answer more directly relevant to you. > 2) In ordinary parlance, "deep" implies "shallow" but not conversely. In the > Python "copy" module (if I understand correctly), the implication goes the other > way. Do you find this a nuisance? I believe deep copy does shallow copy + more copy so that 'deep' *does* imply 'shallow'. For this sort of question, start interpreter in interactive mode (or use IDE that simulates this mode), make up simple example, import copy module, and interactively experiment. This is best way to learn actual behavior. Ability to do so is great feature of Python. Terry J. Reedy From claird at lairds.com Mon Aug 25 14:00:49 2003 From: claird at lairds.com (Cameron Laird) Date: Mon, 25 Aug 2003 18:00:49 -0000 Subject: Using the C Source Code from Tcl/Tk References: Message-ID: In article , David M. Cook wrote: . . . >prefer pygtk, though. Tk is beginning to show its age, though the text and >canvas widgets are still strong points. > >Dave Cook text and canvas are indeed remarkable. An interesting experiment to rejuvenate Tk is underway . 'Most everyone in- volved has explicitly mentioned the intent to help with Tkinter, Perl/Tk, ... at the same time. If you'd like Tk or Tkinter to be better than they are now, this is a great op- portunity to volunteer to good effect. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://phaseit.net/claird/home.html From mwh at python.net Fri Aug 22 09:03:26 2003 From: mwh at python.net (Michael Hudson) Date: Fri, 22 Aug 2003 13:03:26 GMT Subject: Problems with python-list? References: <477762c2.0308201832.327cf5bc@posting.google.com> <7h31xvf43at.fsf@pc150.maths.bris.ac.uk> <7h3r83f2ogv.fsf@pc150.maths.bris.ac.uk> Message-ID: <7h3k79526eu.fsf@pc150.maths.bris.ac.uk> Gerhard H?ring writes: > Andreas Kuntzagk wrote: > > Is this [python.org] the same box which handles the registration for the PyPiPage? [...] > > Yes, it is the same box. Well, that depends what you mean :-). mail.python.org is in a Baymountain colo facility somewhere in Virginia and is the machine that has been being clattered by sobig.f. PyPI runs on www.python.org which is in xs4all's data centre in Amsterdam and is doing just fine. *However* registering for PyPI appears to send mail via m.p.o, which currently isn't happening. Cheers, mwh -- In that case I suggest that to get the correct image you look at the screen from inside the monitor whilst standing on your head. -- James Bonfield, http://www.ioccc.org/2000/rince.hint From vanevery at 3DProgrammer.com Sun Aug 17 05:09:45 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Sun, 17 Aug 2003 02:09:45 -0700 Subject: simple text parser? Message-ID: I'm making a 2D game with a simple "adjacent freeform territories" map. I need to make save files for this. I figure I could store the data in either binary or text. The amount of data to be stored should be small enough that efficiency and size do not matter. What does matter, is I don't want to spend any time at all on this. I want something off-the-shelf. Can anyone recommend simple text parsers implemented in Python? Alternately, doesn't Python have some kind of automagical serialization pack/unpack functionality? How does that work? I remember reading something about that in the Python docs awhile ago. Before you scream RTFM, bear in mind that my current plan is to write versions of this game in C# / .NET and Python / WhateverWidgets simultaneously. I'm ignorant of both platforms, this is an excuse to do a comparo. And, the whole point of moving to higher level language development is to minimize pain. Asking questions here rather than reinventing the wheel is part of that agenda. I want to handle this problem off-the-shelf. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From sross at connectmail.carleton.ca Mon Aug 25 19:00:54 2003 From: sross at connectmail.carleton.ca (Sean Ross) Date: Mon, 25 Aug 2003 19:00:54 -0400 Subject: Determinig position of a element in a list References: Message-ID: <8yw2b.1762$_F1.179720@news20.bellglobal.com> "Przemo Drochomirecki" wrote in message news:bie2kk$7av$1 at atlantis.news.tpi.pl... > Hello, > i'm wondering if there is any tricky way for doing following thing: > A - list of distinct integers (e.x. A = [1,3,7,11,14,15]) > very fast function determinig position of number x in list A > or -1 if x doesnt belong to A > Operator IN returns only false/true values > i can implement function index (e.x. index(5,A) = -1, index(7,A) = 2), but > maybe there's is simpler(builtin?) solution > > Thanks > > You can use list_object.index(value): >>> A = [1,3,7,11,14,15] >>> A.index(5) # this will raise an exception, use try/except Traceback (most recent call last): File "", line 1, in ? ValueError: list.index(x): x not in list >>> A.index(7) 2 >>> HTH Sean From tebeka at cs.bgu.ac.il Tue Aug 12 02:29:49 2003 From: tebeka at cs.bgu.ac.il (Miki Tebeka) Date: 11 Aug 2003 23:29:49 -0700 Subject: Python and Code Completion References: <3f37d456$0$228@hades.is.co.za> Message-ID: <33803989.0308112229.4e2e590a@posting.google.com> Hello Madiba, > Can anybody please give me some pointers on how to get the available > properties/documentation to a class etc without actually excecuting the > code. Do i have to write my own semi-parser? > I know help('class') displays doc and methods and automatically imports > class, so is there maybe something similar to use? > > any ideas? Have a look at introspect.py that comes with wxPython. PyCrust uses it. HTH. Miki From pythonguy at Hotpop.com Wed Aug 13 05:57:07 2003 From: pythonguy at Hotpop.com (Anand Pillai) Date: 13 Aug 2003 02:57:07 -0700 Subject: ???? i can`t understand it References: Message-ID: <84fc4588.0308130157.89ba8b4@posting.google.com> I would rather use slices. Here are two ways of doing it. >>>a=[1,2,3,4,5] >>>for b in a[0:] # Small typo here in prev post ... a.remove(b) >>>print a [] Or I think a better way is (dont ask me why!) >>>a=[1,2,3,4,5] >>>for b in a[:]: ... a.remove(b) >>>print a [] -Anand bokr at oz.net (Bengt Richter) wrote in message news:... > On Fri, 8 Aug 2003 08:05:11 -0300, "Batista, Facundo" wrote: > > >This message is in MIME format. Since your mail reader does not understand > >this format, some or all of this message may not be legible. > > If you could eliminate the HTML, it would improve reception on this end ;-) > > Regards, > Bengt Richter From __peter__ at web.de Sun Aug 31 18:14:13 2003 From: __peter__ at web.de (Peter Otten) Date: Mon, 01 Sep 2003 00:14:13 +0200 Subject: exception question References: Message-ID: Gon?alo Rodrigues wrote: > For error processing I found convenient maintaining a dictionary where > the keys are exception *classes* and the values are callables. Of > course, for this to work, exception classes have to be hashable which > I happily found that they were. So my question is, can I count on this > behaviour? Or is this behaviour I should not count on? (I found > nothing on the docs about it, thus the question). (No answer to your question) import sys class MyException(Exception): def __init__(self, msg, handler): Exception.__init__(self, msg) self.handler = handler try: raise MyException("yup", lambda: sys.stdout.write("call it sleep\n")) except MyException, e: e.handler() Would that eliminate the need for a dictionary? Peter From juneaftn at REMOVETHIShanmail.net Fri Aug 15 18:21:29 2003 From: juneaftn at REMOVETHIShanmail.net (Changjune Kim) Date: Sat, 16 Aug 2003 07:21:29 +0900 Subject: robust clean-up with SIGTERM (was Re: Again, how to write a cleanup function for a module in C ) References: Message-ID: Though I'm not Alex Martelli, hope this helps: (look at the end of this post) "Jane Austine" wrote in message news:ba1e306f.0308131051.3b6bcbd3 at posting.google.com... > I'm writing a cgi script. The user can push the stop button at any > moment while the page is loading, and the apache will raise SIGTERM > and then SIGKILL in 3 secs. And the garbage is not collected > automatically when the signals are raised. It's an abnormal > termination. > > I need to clean up a few things(like closing the db connection) before > the interpreter terminates. > > How do I? > > And according to Alex's suggestions... (see my questions below) > > "Alex Martelli" wrote: > > [snip] > > > > Are you implying that atexit doesn't? Run the following script: > > > > import atexit > > def f(*args): > > print 'f',args > > atexit.register(f,'goo','bar','baz') > > 1/0 > > > > The output I see for it is as follows: > > > > [alex at lancelot src]$ python2.2 a.py > > Traceback (most recent call last): > > File "a.py", line 5, in ? > > 1/0 > > ZeroDivisionError: integer division or modulo by zero > > f ('goo', 'bar', 'baz') > > [alex at lancelot src]$ > > > > > > Signals are nastier -- by default they terminate the process > > WITHOUT cleanup. For example, if instead of the 1/0 you have > > at the end of the script: > > > > import os, signal > > os.kill(os.getpid(), signal.SIGIO) > > > > then f won't get run. Easy solution (won't work all of the > > time, but, pretty often): handle the signal to turn it into > > an exception! e.g. change the above two lines to: > > > > import os, signal > > def sig2exc(sig, frm): raise SystemError(sig) > > signal.signal(signal.SIGIO, sig2exc) > > os.kill(os.getpid(), signal.SIGIO) > > > > and f will again execute. > > > > > [snip] > > > > So, handle the signal, and make the program die "cleanly" with the > > exception of your choice -- THEN, cleanup code DOES run. > > > [snip] > > This "signal to exception translation" looks nice. But Alex said > "won't work all of the time, but, pretty often". I am afraid to use > this method if its safety is not guaranteed. I wonder in what cases it > does not work, and how I can make it work always. When signals are generated successively in a very short time, python interpreter might screw up some of them. Basically, the interpreter checks every checkinterval(default 100) if it has pending signal handler calls, and process them. When a signal is generated, it registers the signal and put its handler on the pending calls. As you can see there are potential race conditions. Check signalmodule.c and ceval.c. I don't have a good idea on making signal handling always safe & guaranteed. Maybe someone else can help? From jjl at pobox.com Sat Aug 16 18:47:11 2003 From: jjl at pobox.com (John J. Lee) Date: 16 Aug 2003 23:47:11 +0100 Subject: Summer reading list References: <2259b0e2.0308130804.492aa1ac@posting.google.com> <87ekzmsi5c.fsf@pobox.com> <2259b0e2.0308160430.47b01040@posting.google.com> Message-ID: <873cg1jk40.fsf@pobox.com> mis6 at pitt.edu (Michele Simionato) writes: > jjl at pobox.com (John J. Lee) wrote in message news:<87ekzmsi5c.fsf at pobox.com>... > > mis6 at pitt.edu (Michele Simionato) writes: > > > To reuse classes is good, but typically only works when you know > > > about the class you want to inherit *before* you start coding your > > > own class; on the other hand, it is quite easy to add functions > > > or methods to your class even *after* you wrote it. > > [...] > > > > But I don't think that makes any sense. As I'm certain you know, > > there would be nothing to stop you using a class in exactly the same > > way you used the function, because reuse != inheritance. Functions > > can be implemented in terms of classes, and classes can be implemented > > in terms of functions. > > Let me see if I understand what you mean. You are saying "I could invoke > an instance method just as I invoke a function, without using inheritance, > and reuse the method in another class". True, but this is clumsy: the point I don't think composition is clumsy. > of using a class is making use of inheritance for code reuse, otherwise I > could just use a function, isn't it? Composition doesn't preclude inheritance in the class hierarchy you're reusing by composition. In fact, that's usually what happens. And extension of interfaces (which is what you were talking about, presumably with implementation inheritance of the old methods) isn't the only useful thing about classes -- associating functions with data is useful on its own, as is plain old interface inheritance without extension. > Besides, typically an instance > method is doing something to the 'self' argument and may have unwanted > side effects on the object; a function is safer in this respect. I don't understand. class foo: def ni(self): print "ni" class bar: def __init__(self): self.foo = foo() def NININI(self): for i in range(3): self.foo.ni() > In my experience, it takes a certain effort to code a reusable class; > it takes a much lesser effort to code a reusable function. s/reusable class/inheritable class/, and add the proviso that it's just as easy to reuse classes by composition as it is functions, and I'd agree. But you knew that! > > The only reason it's good that Python library uses functions sometimes > > instead of classes is as you say: KISS. If it only needs a function, > > use a function. > > > > John > > Yep. > > Michele John From rupole at hotmail.com Thu Aug 28 22:13:14 2003 From: rupole at hotmail.com (Roger Upole) Date: Thu, 28 Aug 2003 19:13:14 -0700 Subject: NetServerDiskEnum in win32net References: Message-ID: <3f4e8896_1@127.0.0.1> There's a bug in this function. (also a related memory leak) I've been meaning to submit a patch for it, but I hadn't heard anybody else complain about it yet. Roger "Uwe Becher" wrote in message news:bilh88$rs3$03$1 at news.t-online.com... > I try to get all logical drives of a remote machine (WinNT or W2K) and > get a result, that gives me the expected total but not all expected drives. > > Example: > > >>> win32net.NetServerDiskEnum('nor1w020', 0) gives me: > ([u'A:', u'', u'C:', u'', u'D:', u'', u'E:', u''], 8, 0) > > while the machine has the local drives > A: C: D: E: F: G: H: Z: > A: - Floppy > Z: - CDROM > All others are harddisk partitions on two physical drives > > Does anyone have an idea? > > Thanks > Uwe > From bgailer at alum.rpi.edu Mon Aug 25 18:58:34 2003 From: bgailer at alum.rpi.edu (Bob Gailer) Date: Mon, 25 Aug 2003 16:58:34 -0600 Subject: Determinig position of a element in a list In-Reply-To: Message-ID: <5.2.1.1.0.20030825165532.032eb620@66.28.54.253> At 12:29 AM 8/26/2003 +0200, Przemo Drochomirecki wrote: >Hello, >i'm wondering if there is any tricky way for doing following thing: > A - list of distinct integers (e.x. A = [1,3,7,11,14,15]) > very fast function determinig position of number x in list A > or -1 if x doesnt belong to A >Operator IN returns only false/true values >i can implement function index (e.x. index(5,A) = -1, index(7,A) = 2), but >maybe there's is simpler(builtin?) solution try: pos = A.index(5) # or whatever number you want except ValueError: pos = -1 Bob Gailer bgailer at alum.rpi.edu 303 442 2625 -------------- next part -------------- --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.506 / Virus Database: 303 - Release Date: 8/1/2003 From tchur at optushome.com.au Thu Aug 28 09:27:39 2003 From: tchur at optushome.com.au (Tim Churches) Date: Thu, 28 Aug 2003 23:27:39 +1000 Subject: appoximate string matching library - any interest? In-Reply-To: <4ZGcnR__JutkFdOiXTWJhQ@giganews.com> Message-ID: <001001c36d68$2b4b08f0$a300a8c0@emilio> Istvan Albert writes: > I'm working on a project that needs approximate string > matching such as the String::Aprox module in perl: > > http://search.cpan.org/author/JHI/String-Approx-3.20/Approx.pm > > Unlike exact matches approximate (fuzzy) matches can match > words having small differences in them, typos, errors or > similarly spellings. > > I was unable to find a similar implementation in python right > away so I tried wrapping the perl module's underlying C > library into python calls. I turned out to be fairly easy, > man is SWIG an awesome product or what ... in a just a few > hours I managed to create a quite functional version (see below). > > In the meantime I have also discovered that there is a > similar project Agrepy.py available but I have no idea how > well it works. I'm trying to gauge the interest relative to > this library, right now it serves my needs yet I wouldn't > mind polishing it up and making it public if it appears to be > useful for others too. There are a number of approximate string matching functions, implemented in pure Python, included in the Febrl project (Febrl=Freely-extensible biomedical record linkage). See under "Prototype software" at http://datamining.anu.edu.au/projects/linkage.html or for details of the approximate string comparators implemented, see http://cs.anu.edu.au/~Peter.Christen/febrl-0.2/febrldoc-0.2.1/node37.htm l Note that approximate string comparator functions are different from (although related to) phonetic encoders, such as Soundex (see http://cs.anu.edu.au/~Peter.Christen/febrl-0.2/febrldoc-0.2.1/node38.htm l for some examples of the latter). Wrapped C implementations of any or all of these comparators would be welcome, although in practice we haven't found them to be a major bottleneck (although calculating the Levenshtein distance on long strings can be rather expensive). Oh, there are also a number of interesting vector-space comparison techniques which can be applied to strings, but we haven't implemented any of these yet in Febrl. Then there are various language- or culture-specific comparators. And then there is the whole issue of name comparison in pictographic and ideographic languages... And I didn't mention guns once... Tim C From clifford.wells at comcast.net Fri Aug 29 05:50:27 2003 From: clifford.wells at comcast.net (Cliff Wells) Date: Fri, 29 Aug 2003 02:50:27 -0700 Subject: Celebrity advice In-Reply-To: <000701c36ce7$a6ff24d0$0c02a8c0@Arts> References: <000701c36ce7$a6ff24d0$0c02a8c0@Arts> Message-ID: <1062150627.7273.26.camel@devilbox.homelinux.net> On Wed, 2003-08-27 at 15:07, Arthur wrote: > We all knew this kind of discussion would lead to no good. Even to my own > eventual involvment. But the rule I had set to myself, would be to comment > only upon Lulu's comment, and only if that comment was something other than > to the effect that one's politics might be irrelevent here, and that the > advice to a new programmer to eschew Raymond because of his was .. bad > advice. I'd have to agree with Art on this. ESR's thoughts on guns have little to do with programming, and unless he likes to use "nra" or "bullet" as metavariables, his politics would best be omitted from the discussion. Had Hitler (note end of thread) rather than Einstein written _Relativity_ would we expect physicists to ignore it because of his politics? I certainly hope not. The fact that I think Charlton Heston is a buffoon shouldn't be the reason I think his movies suck. Regards, Cliff -- Pushing the stone up the hill of failure -Swans From tim.one at comcast.net Sat Aug 16 12:39:58 2003 From: tim.one at comcast.net (Tim Peters) Date: Sat, 16 Aug 2003 12:39:58 -0400 Subject: IEEE special values In-Reply-To: Message-ID: [Norbert Nemec] > is there any simple reason why IEEE special values are so poorly > supported in python? They're not supported at all, except by accident. This is because C89 doesn't support them at all, except by accident, and Python is coded in C. > Are there any serious efforts to change that? No. A little less than once a year someone claims very earnestly that they're going to try, but nothing has come of that. Don't underestimate the difficulty of writing portable C that delivers consistent cross-platform results in the presence of 754 gimmicks! Virtually everyone does underestimate it, so eventually gives up when the problems overwhelm their initial enthusiasm and wishful hopes for quick victory. > NaN and Inf are an extremely useful concept for numerical > calculations and they would mix perfectly with the concepts in NumPy, > anyhow, the support seems to be absolutely minimal. Again, there's no support in core Python, except by accident. Python more-or-less reflects whatever accidental support the platform C compiler provides. For example, on most (but not all) Unix platforms, if x is an infinity then eval(str(x)) == x. On other Unix platforms, and on Windows, eval(str(x)) raises an exception. > (The ideas in PEP 754 do not really change much: There is little > use in easy access to those values, if the math functions don't accept > them as input but break down.) And fixing that requires that Python supply its own math functions. Fine by me, but that's too big a project for my spare time, and nobody so far wants this enough to pay for it. From newsgroups at jhrothjr.com Tue Aug 19 09:52:42 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Tue, 19 Aug 2003 09:52:42 -0400 Subject: What's better about Ruby than Python? References: Message-ID: "Heiko Wundram" wrote in message news:mailman.1061271511.20407.python-list at python.org... > On Mon, 2003-08-18 at 19:40, John Roth wrote: > > This is why Ruby's solution is superior: "self" is a reserved word, > > and so is the special character shortcut. There is no question as > > to what is meant. It eliminates essentially futile arguements in the > > same way that Python's indentation eliminates arguements about > > the proper placement of braces. > > I think you're not getting the main point in a difference between Ruby > and Python here, and why it makes (IMHO) no sense to have a default self > in a function: > > class X: > def test(*args): > print args > > X.test() # 1 > x = X() > x.test() # 2 > X.test(x) # 3 > > Run this, and for the first call you will get an empty tuple, while for > the second call, you will get a tuple with the first parameter set to a > class instance of X, and for the third call the same as for the second > call. Remember about method binding (method/function difference), and > the like. > > I want to have class-functions which can be callable either as a > function of the class (doing something on input-data), or work directly > on the instance they are associated with. If you have a predeclared > self, only calls 2 and 3 would work, if the self parameter is just > another parameter for the function, I can miraculously call the function > just like it is (see call 1). > > I find it reasonable enough to have a feature like this to not complain > about having to specify self as the first parameter, always. If every function/method has access to an instance/class whatever, then there is clearly no reason to waste keystrokes specifying it on the function/method header. I would think this would be obvious. John Roth > > Heiko. > > From cjw at sympatico.ca Fri Aug 15 06:54:50 2003 From: cjw at sympatico.ca (Colin J. Williams) Date: Fri, 15 Aug 2003 06:54:50 -0400 Subject: PythonWin hangs when Shift-F5 (stop debug) In-Reply-To: References: Message-ID: Bob Gailer wrote: > At 10:49 AM 8/14/2003 -0700, ywsat wrote: > >> Has anyone experienced the problem where PythonWin debugger hangs you >> stop the debug session? >> >> I'm running Windows 2000. Python 2.3. >> >> I have to kill it through the task manager each time. > > > I've had other conditions that required an End Task, but not what you're > describing. > > Bob Gailer > bgailer at alum.rpi.edu > 303 442 2625 > > > ------------------------------------------------------------------------ > > > --- > Outgoing mail is certified Virus Free. > Checked by AVG anti-virus system (http://www.grisoft.com). > Version: 6.0.506 / Virus Database: 303 - Release Date: 8/1/2003 I've found it better not to end debug session, by using Shift F5 or by using the "Close" icon on the debug task bar. I avoid the End Task, by letting a job run to completion - typically an exception during testing. Now, if the job is of long duration, a judiciously placed "assert 0" can ensure temination at an exception. Colin W. From aramsi.ext at rd.francetelecom.com Mon Aug 4 09:26:01 2003 From: aramsi.ext at rd.francetelecom.com (zze-Support activite PCL RAMSI A ext DvSI/SIReS/LAN) Date: Mon, 4 Aug 2003 15:26:01 +0200 Subject: Script Message-ID: Hello everybody, I try to execute an ifconfig command in my python code using: stat, wdsout = commands.getstatusoutput("./script.sh " + interface + " " + ipadrr) The script.sh executes the ifconfig command as: Ifconfig $1 plumb && ifconfig $1 $2 netmawk 255.255.255.0 up this script is created by the root, and have 4755 as chmod. When the script is executed by th root, it works normaly but when it's launched from the python file it doesn't work: and i have a Permission denied message. Is something wrong in what I do? Thanks in advance. -------------- next part -------------- An HTML attachment was scrubbed... URL: From theller at python.net Mon Aug 18 16:05:29 2003 From: theller at python.net (Thomas Heller) Date: Mon, 18 Aug 2003 22:05:29 +0200 Subject: Py2exe for 2.3 also copies python22.dll References: Message-ID: "Brad Clements" writes: > Here's a "screen shot" I'm running > > python setup.py -d c:\temp\rose s UMXService > > I have python 2.2 installed, and 2.3. 2.3 is the 'default' for .py > files but it seems that py2exe's setup copies pythonxx.dll from > system32, rather than picking the specific version that's needed > Due to a bug, the run_svc.exe distributed with py2exe for Python 2.3 is linked with pywintypes22.dll instead of pywintypes23.dll. Rebuilding py2exe from source should help (currently I have no time to do it myself). Thanks, Thomas From gstein at lyra.org Sat Aug 30 08:26:45 2003 From: gstein at lyra.org (gstein at lyra.org) Date: Sat, 30 Aug 2003 05:26:45 -0700 Subject: received your email Message-ID: <200308301226.h7UCQjTq031588@nebula.lyra.org> Hi, [ Re: Re: That movie ] I have received your email, but it may take a while to respond. I'm really sorry to have to hook up this auto-responder, as it is so impersonal. However, I get a lot of email every day and find it very difficult to keep up with it. Please be patient while I try to get to your message. Please feel free to resend your message if you think I've missed it. I'll always respond to personal email first. If your email is regarding some of the software that I work on (if you have questions, comments, suggestions, etc), then please resend it to the appropriate mailing list: mod_dav WebDAV ViewCVS Subversion edna Thank you! Cheers, -g -- Greg Stein, http://www.lyra.org/ From darnold4 at cox.net Wed Aug 27 14:16:36 2003 From: darnold4 at cox.net (David Raleigh Arnold) Date: Wed, 27 Aug 2003 14:16:36 -0400 Subject: sed with python References: Message-ID: On Wed, 27 Aug 2003 19:26:36 +0200, U. N. Owen wrote: > > David Raleigh Arnold enlightened us with: >> How do I use python as a wrapper for sed and/or gawk scripts? > > You don't. Python can do anything sed and awk can, and much, much more. > > Sybren > > > > That's true, but it may be useful to use existing code (and not bother > rewriting in Python). You can use shell scripts, pipes, or if you want to > use only python scripts, use > os.system to call sed or awk. > But if you write new functions, Python is enough, as Sybren says os.system it is. Thanks! Some of my stuff is simple substitution filters, and rewriting that makes no sense to me. DaveA -- "We have learned the lessons of Viet Nam." --anon Spokesman "Failure is not an option." --anon Spokesman Can both be true? n Are both false? y Right answers get my vote. D. Raleigh Arnold dra@ http://www.openguitar.com darnold4 at cox.net From R.Brodie at rl.ac.uk Thu Aug 21 10:11:19 2003 From: R.Brodie at rl.ac.uk (Richard Brodie) Date: Thu, 21 Aug 2003 15:11:19 +0100 Subject: [OT] Why is it called string? References: <3f44ce77$0$556$b45e6eb0@senator-bedfellow.mit.edu> Message-ID: "Brian Kelley" wrote in message news:3f44ce77$0$556$b45e6eb0 at senator-bedfellow.mit.edu... > That being said, what is the programming-centric etymology of "string"? The usage of string as "a sequence of similar objects", appears to be very old. Dropping the 'character' part is probably much more recent (probably around the classic Unix/C era: old Pascal documentation tends to say "character string" explicitly. From aahz at pythoncraft.com Mon Aug 18 04:31:57 2003 From: aahz at pythoncraft.com (Aahz) Date: 18 Aug 2003 04:31:57 -0400 Subject: overriding a tuple's __init__ References: Message-ID: In article , Simon Burton wrote: > >Python 2.2.2 (#2, Nov 24 2002, 11:41:06) >[GCC 3.2 20020903 (Red Hat Linux 8.0 3.2-7)] on linux2 >Type "help", "copyright", "credits" or "license" for more information. > >>>> class pair(tuple): >... def __init__(self,a,b): >... tuple.__init__(self, (a,b) ) >... >>>> a=pair(1,2) >Traceback (most recent call last): > File "", line 1, in ? >TypeError: tuple() takes at most 1 argument (2 given) >>>> > >What gives? (yes it works with a list, but i need immutable/hashable) You need to define __new__(); __init__() gets called *after* object creation, when it's already immutable. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From aahz at pythoncraft.com Wed Aug 20 10:14:19 2003 From: aahz at pythoncraft.com (Aahz) Date: 20 Aug 2003 10:14:19 -0400 Subject: python for non-programmers tutorial? References: Message-ID: In article , Michael Peuser wrote: > >Have a look at: > > www.pauahtun.org/TYPython/ > >Ivan Van Laningham: Teach Yourself Python in 24 Hours Unfortunately, speaking as the tech editor of that book, I can't recommend it. Besides, it's out of print. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From brjohan at email.com Thu Aug 14 16:15:00 2003 From: brjohan at email.com (Bror Johansson) Date: Thu, 14 Aug 2003 22:15:00 +0200 Subject: py2exe problem References: Message-ID: Thomas Heller wrote: > "Bror Johansson" writes: > >> When using py2exe to convert a Python program into an executable: >> >> Everything works fine when my.py-files reside in a directory on a >> local disk >> >> but >> >> after having copied the .py-files to a ClearCase dynamic view >> located on a server machine and having checked them in, I get this >> error when executing the file built by py2exe (trace output from >> execution of py2exe is the same in both cases): >> >> KeyError: Scripts.py2exe\support.py >> >> Python 2.2, py2exe-0.3.4, Win"K >> >> Any idea, anyone? > > I cannot really understand what you're asking, and I don't know what a > ClearCase dynamic view is. > > Hm, maybe an idea: distutils (and thus py2exe) doesn't really work > if you use absolute pathnames. The script should be in the same > directory (or a subdirectory, maybe) as the setup.py file, and the > 'python setup.py py2exe' command should be executed in this directory. > > Thomas ClearCase is a configuration/version management tool A dynamic view is a mountable view of a specified version of files/directories. This view is associated with a real directory - on a server (in my case). It is mounted to drive 'Y:' (in my case) I did develop my Python-application with the files located in a directory on a local disk. After execution of 'python setup.py py2exe' in that directory everything works fine. (Neither in the setup.py nor in the other .py files are any pathnames present) Then I copied all .py files (including the setup.py) from this directory into a view-directory. In this directory my application works fine when invoked as 'python myapp.py'. Execution of 'python setup.py py2exe' gives no warnings or errors (trace output is exactly the same as that from the local disk execution). When I - after 'cd dist\myapp' executes '.\myapp' I almost immediately get this message: 'KeyError: Scripts.py2exe\support.py' Is there a good way to debug the execution of a 'py2exe'-produced executable? /BJ From jjl at pobox.com Sat Aug 9 09:46:19 2003 From: jjl at pobox.com (John J. Lee) Date: 09 Aug 2003 14:46:19 +0100 Subject: Recommendation of a parser generator References: Message-ID: <87ptjfx7tg.fsf@pobox.com> bokr at oz.net (Bengt Richter) writes: [...] > BTW, I wonder if there is a Python parser generator that will take > a flex-format grammar as input. Then a transition would be easier. I agree, but flex isn't a parser generator, is it -- it's a lexical scanner generator? John From pythonguy at Hotpop.com Wed Aug 13 06:17:25 2003 From: pythonguy at Hotpop.com (Anand Pillai) Date: 13 Aug 2003 03:17:25 -0700 Subject: Scanning through Directory References: Message-ID: <84fc4588.0308130217.4e64c3a@posting.google.com> Did you try os.path.walk() in your experiments? If you did, you could post the profile data for it too. I find it one of the most useful functions defined in the os.path module. Thanks! Anand "Michael Peuser" wrote in message news:... > There is a portable way of reading directories > os.listdir > in conjunction with > os.stat and a little help from os.path.split and os.path.join > Though using os.stat gives programs a somewhat clumbsy look, > I had not been too annoyed with it until I tried to scan a whole disk. > Reworking the join and split operations already gave a considerable > speed-up > > As I need it for Windows I then with very little effort changed to: > win32api.FindFiles > (I already had used win32api.GetDiskFreeSpace) > > This was a breakthrough: 5 secs instead of 50+ ! > > os.listdir seems to do little more than win32api FindFiles > How can it be so slow??? > Why is there no portable way of getting "DiskFreeSpace" info > Questions and Questions.... > > I strongly recommend the win32api calls it you have similar applications. > The interface is extremely simple and the only penalty is non-compatibility > ;-) > > I also recommend to use the Python profiler from time to time for programms > running more than one second. It might give you interesting insights... > > Kindly > Michael Peuser From no at spam.com Sun Aug 3 01:41:56 2003 From: no at spam.com (J. W. McCall) Date: Sun, 03 Aug 2003 05:41:56 GMT Subject: Can't get dumb webcounter working In-Reply-To: References: Message-ID: Barry Sprajc wrote: > Tyler's correct. > > You'll want to check with those hosting your web site, they usually have > particular directories in your home directory where you'll put your scripts, > etc... > > Then, you just need to put the correct HTML code in your document. From the FAQs and help at my shell account (freeshell.org) it says I don't need a "cgi-bin" directory or anything like that; I can run scripts from anywhere. As far as the correct HTML code...sorry if this is a dumb question, but what exactly would that HTML code be? I saw something about "" but that didn't seem to work. I've never called a script from an HTML document. I guess that's what I'm trying to figure out. Thanks, J. W. McCall From cnetzer at sonic.net Wed Aug 27 19:20:39 2003 From: cnetzer at sonic.net (Chad Netzer) Date: Wed, 27 Aug 2003 16:20:39 -0700 Subject: Style question... In-Reply-To: References: Message-ID: <1062026439.1853.22.camel@adsl-209.204.179.133.sonic.net> On Wed, 2003-08-27 at 15:45, Anthony Roberts wrote: > If I end indentation levels with "pass" statements, will I piss off people > that have to read my code? eg: > > for i in xrange(0,5): > if i: > print i > pass > print i * -1 > pass I do this myself at times, to help emacs. But I'd suggest you not overdo it. It is more "pythonic" to simply leave the line blank (ie. vertical whitespace), than have "pass" everywhere. Pressing backspace once (to undo the auto-indent that emacs gives inside loops) is less typing than 'pass'. And if you need to reindent large chunks of code, you are better off using emacs block indent/dedent feature than relying on "pass" as defacto block delimiter (this has been my experience) Also, look into the pindent.py script (included in Python's "Tools" directory with the distribution), for another way of producing block closing tokens. -- Chad Netzer From heikowu at ceosg.de Mon Aug 4 12:58:47 2003 From: heikowu at ceosg.de (Heiko Wundram) Date: 04 Aug 2003 18:58:47 +0200 Subject: Script In-Reply-To: References: Message-ID: <1060016327.792.3.camel@d168.stw.stud.uni-saarland.de> On Mon, 2003-08-04 at 15:26, zze-Support activite PCL RAMSI A ext DvSI/SIReS/LAN wrote: > this script is created by the root, and have 4755 as chmod. The 4 is +s (set UID), but this isn't allowed on scripts, because there's some kind of race condition associated with having setuid scripts on Unix. Don't remember what the problem was, but just look for the term setuid script, and you'l soon find out. Workaround: Write a compiled (a C program), which is setuid, and calls ifconfig for you. This works, and this is what programs like mailman, etc. do to get around this limitation of each and every Unix kernel. HTH! Heiko. From logiplex at qwest.net Tue Aug 19 13:21:01 2003 From: logiplex at qwest.net (Cliff Wells) Date: Tue, 19 Aug 2003 10:21:01 -0700 Subject: Brandon's abrasive style (was Re: What's better about Rubythan Python?) In-Reply-To: References: <38ec68a6.0308172319.431a4fde@posting.google.com> Message-ID: <1061313661.10907.1183.camel@software1.logiplex.internal> On Tue, 2003-08-19 at 06:36, Peter van Merkerk wrote: > > > - GUI and tools support can end up being more important than > language > > > niceties. > > > > Absolutely. This is one of the main reasons languages like Ruby and > > Haskell aren't in my toolkit. wxRuby appears to be in the pre-alpha > > stages and wxHaskell doesn't exist at all. > > http://wxhaskell.sourceforge.net Feh. I should have known =) It seems nearly every language is gathering a wx interface. What's next, wxC#? Regards, -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 (800) 735-0555 From davidcfox at post.harvard.edu Thu Aug 14 10:04:36 2003 From: davidcfox at post.harvard.edu (David C. Fox) Date: Thu, 14 Aug 2003 14:04:36 GMT Subject: Determine file type (binary or text) In-Reply-To: References: Message-ID: Sami Viitanen wrote: > Thanks for the answers. > > To be more specific I'm making a script that should > identify binary files as binary and text files as text. > > The script is for automating CVS commands and > with CVS you have to add the -kb flag to > add (or import) binary files. (because it can't itself > determine what type the file is). If binary file is not > added with -kb the results are awful. > You should note that the question of when to use -kb is not simply based on the contents of the file, but on whether you want CVS/RCS to try to merge conflicting versions. For example, I recently added some files containing pickled objects (used as test data sets for a regression test) to the CVS repository for my project. Although the pickle files are in fact all printable text, a CVS/RCS merge of two valid pickle files won't yield a valid pickle file. Therefore, I used -kb to ensure that the developer would always be forced to choose a version in the event of a version conflict. David From usenet_poster_a at tranzoa.com Sat Aug 23 02:36:14 2003 From: usenet_poster_a at tranzoa.com (Alex) Date: Fri, 22 Aug 2003 23:36:14 -0700 Subject: Script to remove SoBig/F virus from POP3 mailbox In-Reply-To: References: Message-ID: Skip Montanaro wrote: > Alex> Under the gun, I've written a Python script to delete emails > Alex> containing this latest virus/worm (Sobig-F) from a POP3 mailbox. > > ... > > I wrote something similar today for scrubbing Mailman 2.1 pending > administrative requests. I've killed over a thousand messages for the > python-help mailing list so far. It's crude, but saves a huge amount of > pointing and clicking. If you'd like a copy, drop me a note. If enough > people are interested and it seems like there's no other easy way to > accomplish this with the usual Mailman means, I'll place a copy on my > website. > > Skip > Heck, why not post? "When in doubt, ship it out." :) Actually, my script was small enough to simply include in the newsgroup posting. But, it's usually handier for people to get things from the web site than trying to sort through old news messages. As indicated in the private email, I solved two particular problems we had: 1) Used TOP to read just the start of the emails so that our bandwidth wasn't saturated by full, virus emails. 2) Deleted virus scanner bounces that contained the whole, danged virus file attachment. Alex From jacek.generowicz at cern.ch Tue Aug 19 08:33:02 2003 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 19 Aug 2003 14:33:02 +0200 Subject: What's better about Ruby than Python? References: Message-ID: Alexander Schmolck writes: > Well, yes, I propose that x.__class__ return the *new* definition of > X Except that this would then create an exceptional case, and it is central to the Python philosophy to avoid exceptional cases. class : etc. (re)binds just like def (): etc. (re)binds just like = etc. (re)binds . I would find it disturbing, and anomalous, if one of those did some other stuff behind my back. Python's *-by-value-but-all-values-are-references binding model is consistent in not allowing you to alter other references to any given object, merely by rebinding one of the references to that object. If you _really_ want a change to be reflected in all references, then you are free to mutate the object in question (if it is a mutable one). > Can you give my any reason why you would *not* want all instances to > be updated on class redefinition? Your familiarity with, and appreciation of CLOS is showing :-) Remember that Python has just the one namespace (in the Lisp-1 vs Lisp-2 sense of "namespace"), so while CLOS understands symbols referring to classes in CL's "class namespace", and therefore can treat their re-binding differently than it would in the "variable namespace", Python does not have this luxury. The identifiers referring to Python classes are just plain old variables, like those referring to plain old data. > > But why can't you just > > > > X.amethod = lambda self: "ah, now THIS is better!" > > > > that is, mutate the class referenced by X instead of rebinding X to > > some other class? > > Um, didn't you read what I wrote or was I just unclear? > > To recap: usually, if I change a class I'd like all pre-existing instances to > become updated Well, actually, that's exactly what _does_ happen. If you change (mutate) the _class_, then all existing instances immediately pick that up. However, if you change the reference which initially referred to the original class, clearly the existing instances of the original and still existing-in-unmodified-form class, will not change. > (Let's say you develop your program with a running python session; > you notice a mistake in a method-definition but don't want to start > over from scratch; you just want to update the class definition and > have this update percolate to all the currently existing > instances. This is an *very* reasonable wish if it doesn't just take > seconds to get to the current state by rerunning everything, but > possibly hours or days). AFAIK doing this in a general and painfree > fashion is pretty much impossible in python (you have to first track > down all instances Nope, just _mutate_ the original class. A scheme based on the following might be close to what you want: 1) Create a temporary second reference to the original class. 2) Go to your class source code and make whatever modification you deem fit; higlight it and thwack C-c | (or your IDE's equivalent). 3) Replace the dictionary of the the original class (via the temporary reference from step 1), with that of the newly created class. 4) Rebind the class identifier to refer to the original class. I suspect that a utility function or two (or even a metaclass) could make this almost automatic ... but I haven't the time to think about the details and pitfalls, right now. From tjreedy at udel.edu Wed Aug 27 20:52:14 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 27 Aug 2003 20:52:14 -0400 Subject: Class level variables in Python References: Message-ID: "Brian Munroe" wrote in message news:c16d085c.0308271543.3dfc581e at posting.google.com... > I am just starting to learn the OO side of Python scripting, and I am > a little confused on the following. Take the following example class: > > >>> class rectangle(object): > z = 1 > def __init__(self): > self.x = 2 > > >>> r = rectangle() > >>> print r.z > 1 > >>> print r.x > 2 > >>> r.z = 16 > >>> print r.z > 16 > >>> r.x = 17 > >>> print r.x > 17 > >>> > > I was wondering if someone could explain if there is any difference > between initalizing your object attributes up in the __init__ > constructor or setting them up as (I am guessing at the name here) > object level variables (like z) Everything set at 'top' level under the class statement is a class attribute. Ditto for anything set outside the class statement as someclass.attribute. This include instance methods, which are common to all instances and therefore *attributes* of the class. Everything set within instance methods as self.attribute or outside as someinstance.attribute are instance attributes private to that instance. Just as a function can have a private local variable with the same name as a 'public' global variable, an instance can have an attribute of the same name as an attribute of its class. Just as function locals 'mask' the global of the same name, instance 'locals' usually* mask the class attribute of the same name. In your example above, you start with class attribute z and later add an r instance attribute of same name (but different value). First you see one, then the other. (* I believe the masking exception alluded to above has something to do with special methods, descriptors, and classes derived from builtins, but I do not know the current rule will enough to even quote it. But beginners usually need not worry about it.) Terry J. Reedy From adalke at mindspring.com Thu Aug 28 16:55:03 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Thu, 28 Aug 2003 20:55:03 GMT Subject: OT: Celebrity advice (was: Advice to a Junior in High School?) References: <3F4D0D8B.5E5F9488@engcorp.com> <3F4D3560.71995AEB@engcorp.com> <3F4DFC18.4B309330@engcorp.com> Message-ID: Alex Martelli > Again, I suspect these are very theoretical possibilities for most > discussants. People who were in Bologna in 1976, on the other hand, > have witnessed these issues first-hand: with the "mob" of protesters > having nearly taken over the city, the government acted rapidly and > decisively by sending in the armed forces, with abundant tanks to > occupy and hold the city's key strategic points. Another datum for the discussion is Iraq. In Slate at http://slate.msn.com/id/2080201/ and with reader responses at http://slate.msn.com/id/2081185 In the March 11 New York Times, Neil MacFarquhar notes in passing, "Most Iraqi households own at least one gun." This comes as a shock to those of us who've been hearing for years from the gun lobby that widespread firearms ownership is necessary to prevent the United States from becoming a police state. Note also that the US allows Iraqis even now to own AK-47s, which isn't legal in the US. The US tried an amnesty program, for people to turn their weapons in, but only a few hundred of the estimated 5 million were turned in. http://www.smh.com.au/articles/2003/08/15/1060936052309.html Andrew dalke at dalkescientific.com From google at hanger.snowbird.net Sat Aug 23 17:26:28 2003 From: google at hanger.snowbird.net (Kris Caselden) Date: 23 Aug 2003 14:26:28 -0700 Subject: Threading Oddity? References: Message-ID: Christos "TZOTZIOY" Georgiou wrote in message news:... > Kris, please copy-paste *real* code. This is not code you ran, this was > written for the sake of the post. thread.lock object has no attribute > "aquire". You lost me for a second, until I realized that "aquire" and "acquire" are two different words ;) Sigh. However, my code does indeed run, without error, which begs the question; how is this working? Anyways, thanks for the fix. From DennisR at dair.com Sun Aug 3 15:02:07 2003 From: DennisR at dair.com (Dennis Reinhardt) Date: Sun, 03 Aug 2003 19:02:07 GMT Subject: 'print' in a CGI app. References: Message-ID: > print "Hello\n" > print "World" Try print "Hello
\n" print "World" or try print "
"
    print "Hello\n"
    print "World"
    print "
" -- Dennis Reinhardt DennisR at dair.com http://www.spamai.com?ng_py From ark at acm.org Mon Aug 11 09:51:20 2003 From: ark at acm.org (Andrew Koenig) Date: Mon, 11 Aug 2003 13:51:20 GMT Subject: Fun with numbers - dammit, but I want a cast! References: <3f378fac$0$10778$afc38c87@auth.uk.news.easynet.net> Message-ID: Graham> I'm having some fun with numbers. I've extraced an image Graham> sizes from a jpeg file Graham> img_x,img_y=image.getsize() Graham> then I'm trying to use those sizes to scale the image, but Graham> because python has decided that they are integers, I keep Graham> getting division by zero errors Graham> eg Graham> xscale=xframe/img_x Graham> where xframe will be say 300, and img_x will be 1800 Graham> xscale has the value 0. Graham> I've tried doing img_x=1.0 to force it to be a float, but I'm Graham> getting a bit frustrated as it seems to make no difference - Graham> once image.getsize returns the (integer) value of the x size, Graham> it simply converts back to an int. Two possibilities: 1) Create a floating-point value from the dividend or divisor, which will cause the other one to be converted to float: xscale = float(xframe) / img_x or xscale = xframe / float(img_x) 2) At the beginning of your source file, execute: from __future__ import division Python is going to change its behavior so that division always returns a floating-point value. This statement causes that new behavior to occur now. -- Andrew Koenig, ark at acm.org From vanevery at 3DProgrammer.com Tue Aug 19 03:29:52 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Tue, 19 Aug 2003 00:29:52 -0700 Subject: Brandon's personal style (was) References: <3F41A877.995F9C35@alcyone.com> Message-ID: David Eppstein wrote: > > Googling for that, it seems that the only other stuff you would lose > by killfiling references containing that hostname would be his six-way > crossposts to alt.atheism, alt.politics.bush, alt.fan.noam-chomsky, > soc.culture.iraq, soc.culture.jewish, soc.culture.russian, and > soc.history.war.misc... Some people are still saying he isn't a troll? What are you talking about? I've never initiated any such crosspost. I simply hit (R)eply Group because I, like most people, am too lazy to massage newsgroup headers all day long. Do I respond to trolls in political forums? You bet your ass I do. As far as I'm concerned, you've already accepted the nature of the beast subscribing to such a forum. Your job is to entertain yourself, and spread something that's truth rather than complete bullshit. I also don't spend a lot of time in such forums, it's an occasional dalliance of mine. If you're thorough and fair-minded in your analysis of my posting habits, you'll discover that fact. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From mwh at python.net Tue Aug 26 08:53:22 2003 From: mwh at python.net (Michael Hudson) Date: Tue, 26 Aug 2003 12:53:22 GMT Subject: Python/C API - PyArg_ParseTuple problem ? References: <7h3fzjt1rlh.fsf@pc150.maths.bris.ac.uk> Message-ID: <7h31xv81t2d.fsf@pc150.maths.bris.ac.uk> "J?r?me Laheurte" writes: > I still haven't been able to reproduce it with a minimal source code, but > if you want to try it the source should be available at > > http://fraca7.homeunix.net/pyfltk2-0.0.0.tar.gz > > at least if I didn't screw up with the whole NAT thingies. That URL 404s for me (as did a few others I guessed). > As you can see, the string buffer is passed to > WidgetWrapper::WidgetWrapper, which copies it by using > fltk::Widget::copy_label. I've checked the fltk code to ensure the buffer > was copied via strdup(). > > What really puzzles me is that difference between the "ii|s" and > "ii|O"/PyString_AsString stuff. Wouldn't one expect to have the same > result, right or wrong, from both techniques ? Um, probably :-) Cheers, mwh -- how am I expected to quit smoking if I have to deal with NT every day -- Ben Raia From mertz at gnosis.cx Thu Aug 21 12:24:31 2003 From: mertz at gnosis.cx (David Mertz) Date: Thu, 21 Aug 2003 12:24:31 -0400 Subject: Reviewers _Text Processing in Python_ Message-ID: In the couple months since it was printed, my book seems to have been selling fairly well. Not that I actually know concrete numbers, but I have looked at Amazon's "sales rank" -way- too often. However, I've been a bit disappointed not to see more reviews of the book appear. While it's possible I've missed something, all I've really seen is Ron Stephens very kind notice that appeared on slashdot, as well as other places. So I would be extremely pleased to get a free reviewer's copy into the hands of anyone likely to publish a review. By "publish", btw., I have a very liberal sense--obviously print is good, but anywhere on topical websites, mailing lists, etc. is good too. Anyone interested, please email me, and I'll let Addison Wesley know your shipping info--they seem quite happy to send out more free copies (btw. this need not be USA; since I don't need to ship them directly, I presume AW will send from local distributors). Of course, you won't get an inscribed/signed version, as the buyers of my (sold-out) author's copies did :-). Yours, David... -- X-Shameless-Plug: Buy Text Processing in Python: http://tinyurl.com/jskh From sfb at alysseum.com Sun Aug 10 13:28:01 2003 From: sfb at alysseum.com (Simon Bayling) Date: Sun, 10 Aug 2003 17:28:01 +0000 (UTC) Subject: Python vs. C# References: <3f357a9b@shknews01> Message-ID: The interactive interpreter. >>> for i in range(10): print i, i**i Allows for some very quick testing and exploring, even moreso when combined with dir(object). Tuples. >>> def minmax(L): return min(L), max(L) >>> >>> a, b = test([4,3,1,2]) >>> a, b (1, 4) >>> test("bca") ('a', 'c') A quick way to return multiple values from a function without needing to use 'out' or explicitly put everything into an arraylist and take it out again. Lowered finger-typing - minmax() works on lists, tuples, and strings without needing to make: minmax(string s) minmax(list l) minmax(tuple t) overloads. Mixed type collections. >>> L = [] # make an empty list >>> L.append("1") >>> L.append(1) >>> for item in L: print type(item) In C#, (I think), everything that goes into a collection is cast to object, and when it comes out you have to know what type you are expecting and cast it back. Nothing amazing to beat C# with, just some nice points, like C# has very good database interfacing and (x ? a:b) support... Cheers, Simon. "Brandon J. Van Every" wrote in news:3f357a9b at shknews01: > So again my question is, language-wise, what can I get done with > Python that I can't get done with C#? What is easy to express in > Python, that is tedious, difficult, or impossible to express in C#? From nushin2 at yahoo.com Wed Aug 6 21:38:11 2003 From: nushin2 at yahoo.com (nushin) Date: 6 Aug 2003 18:38:11 -0700 Subject: Bug in os.spawnv with P_NOWAIT Message-ID: If you do not null out the output of your parent process that launches a child process by os.spawnv( ) in P_NOWAIT mode, you will see that your child process is launched *synchronously* instead of asynchronously. This is a bug! Here's a code sample: In your parent.py file, call child.py as os.spawnv(os.P_NOWAIT,'/usr/bin/python',('python', 'child.py')) then, make sure your child.py prints a *hello child* to screen about 2000000 times, and your parent.py prints a *hello parent* message, then execute your file in a shell as: python parent.py then, you would see that whenever your child.py is finished, then parent.py finishes, i.e., a synchronous call. Now, null out the output of your parent process as: python parent.py > /dev/null then, your parent.py finishes first while child.py is still running, i.e., an asynchronous call. Please correct me if i am wrong. Regards, Nushin From ajsiegel at optonline.net Thu Aug 28 09:08:36 2003 From: ajsiegel at optonline.net (Arthur) Date: Thu, 28 Aug 2003 09:08:36 -0400 Subject: celebrity advice Message-ID: <002801c36d65$7ea56980$0c02a8c0@Arts> Owen write - >I don't see the link with Python, but anyway... >Very long ago, some books where burnt in public, >for "religious" reasons, later for political >reasons. Hopefully these old practice have >disappeared and will never come back. >And since this crazy guy seems not have read >even one line of this book, one can imagine >he was bred in an "anti-something", narrow-minded >fashion. Actually he is more dangerous than what >he denounces... Books are pricey, his advice >is not. Though it is not clear to whom or what you are referring. But it is true I did mean to be more explicit in my advocacy of book burning. thanks for filling in the wholes. And how does one arrange for a receipt when one finishes a line? Art From Scott.Daniels at Acm.Org Sat Aug 2 23:42:32 2003 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sat, 02 Aug 2003 20:42:32 -0700 Subject: Dict to "flat" list of (key,value) In-Reply-To: <3f2c54f6.11554794@news.lexicon.net> References: <3f2c54f6.11554794@news.lexicon.net> Message-ID: <3f2c84a9$1@nntp0.pdx.net> John Machin wrote: > On Sat, 02 Aug 2003 12:41:19 GMT, "Raymond Hettinger" > wrote: >> [a perfectly fine chunk of code] >>it-all-starts-with-a-good-data-structure-ly yours, > > I liked the elegant code example for building a book index. However in > practice the user requirement would be not to have duplicated page > numbers when a word occurs more than once on the same page. If you can > achieve that elegantly, please post it! OK, I'll bite: def genindex(pages): index = {} for pagenum in range(len(pages)): page = pages[pagenum] for word in page: index.setdefault(word, {})[pagenum] = None or with 2.3: def genindex(pages): index = {} for pagenum, page in enumerate(pages): for word in page: index.setdefault(word, {})[pagenum] = None return index With either one, flattening looks like: def flatten(index): flattened = [(word, list(pages)) for word, pages in index.items()] for word, pages in flattened: pages.sort() flattened.sort() return flatten For fun, try: book = ['this is a test'.split(), 'this is only a test'.split(), 'had this been a real function, you care a bit'.split()] for word, pages in flatten(index(book)): print word, pages -Scott David Daniels Scott.Daniels at Acm.Org From sross at connectmail.carleton.ca Wed Aug 20 11:16:04 2003 From: sross at connectmail.carleton.ca (Sean Ross) Date: Wed, 20 Aug 2003 11:16:04 -0400 Subject: if in for loop References: Message-ID: "Ryan Lowe" wrote in message news:vXB0b.126774$_R5.47942299 at news4.srv.hcvlny.cv.net... > your complaint is this? [snip code example] > i agree its not as clear whats going on here as in the if example, but its > no less readable than the list-comprehension version, i.e. msgs = ["%s > %s"%(x,y) for x in words for y in otherwords] > whats the argument? should they do away with double for's in list-comp? Actually, I hadn't really formulated an argument. I'm indifferent to the proposal, with some slight leaning towards non-acceptance (as my "-0" vote suggests). I don't think I can justify why I don't care for the proposal. It does seem reasonable. If your goal is to maintain consistency within the language, then this proposal would seem to aid that goal. I also prefer that a language provide consistency. The problem, I suppose, should you choose to be consistent, is deciding in which direction to focus that consistency. While I very much enjoy list comprehensions, and would prefer that they not be removed from the language (read, "Never remove them from the language, please!" and "Could we please have generator comprehensions, as well?"), I also see that they are somewhat of an anomaly and that they can hinder readability when they are allowed to grow without bound. Of course, the same can be said for deeply nested for-loops - at some point, as you add more and more for-loops, the meaning becomes less and less clear (which would be one reason people refactor such things using functions). Anyway. I suppose the question I was addressing in the earlier post was this: Does consistency, in this instance, aid or hinder, and what does it aid or hinder. If we argue that filtering should be added to the for-loop syntax because that syntax should be more consistent with the list comprehension syntax, then it seems reasonable to also argue for the inclusion of multiple for-expressions, on the same basis (Is this argument fallacious? I'm not sure...looks like a slippery-slope) . So, anticipating that others might make this argument once one part of list comprehension syntax had been retro-fitted into the existing for-loop syntax, it seemed reasonable to ask - do you also think multiple for-expressions in a for-loop would be of benefit? Do you want only the one and not the other? (False dichotomy?) If so, why? If not, why not? These are topics you may wish to address, were you to write a PEP. As I've said, I'm pretty much neutral towards the whole thing, with some tendency towards caution. [snipped quote from John Roth posting] > **harder** to read!? cmon now. i will buy its certainly not a necessary > change, but harder to read... for x in X if condx(x) for y in Y if condy(y) for z in Z if condz(z) for w in W if condw(w): suite for x in X: if condx(x): for y in Y: if condy(y): for z in Z: if condz(z): for w in W: if condw(w): suite Neither strikes me as being particularly easier to read than the other. for x in X if condx(x): suite for x in X: if condx(x): suite Same thing here. From mwilson13 at cox.net Mon Aug 25 16:10:31 2003 From: mwilson13 at cox.net (Mark Wilson) Date: Mon, 25 Aug 2003 16:10:31 -0400 Subject: Coloring print lines In-Reply-To: Message-ID: <2DF5B68A-D738-11D7-B166-000393876156@cox.net> On Monday, August 25, 2003, at 09:22 AM, Sami Viitanen wrote: > Hello, > > Is there an easy way to make script print text with differents colors > to > screen (shell)? > > I mean a script that can for example print lines in red if some error > occurs > in executing > some information.. > > --SV > > ----Thanks in advance. You might try porting Ian Macdonald's GPL licensed program "Arbitrary Command Output Colourer" from Ruby to Python. The program is described here: http://www.caliban.org/ruby/acoc.shtml Regards, Mark From dave at nullcube.com Thu Aug 7 06:39:33 2003 From: dave at nullcube.com (Dave Harrison) Date: Thu, 7 Aug 2003 20:39:33 +1000 Subject: using like and % in MySQLdb In-Reply-To: References: Message-ID: <20030807103933.GB23527@dave@alana.ucc.usyd.edu.au> > >Im sure this is a really obvious problem but : > > > >self.curs.execute( > > """SELECT * FROM user WHERE login LIKE '%%s%'""", [login] > > ) > > > >will not work ... gives me an "unsupported format character ''' (0x27)" > > > >escaping the %'s with % as the doco recommends wont work either. > > > Why don't you do > self.curs.execute( > """SELECT * FROM user WHERE login LIKE %s""", ("%"+login+"%", )) > > The problem with escaping the % characters is, that MySQLdb converts > self.curs.execute("""SELECT * FROM user WHERE login LIKE '%%%s%%'""" , > (login,)) > to > "SELECT * FROM user WHERE login LIKE '%'dave'%'" > and I don't know how to prevent this. hehe yeah Id been testing what I was doing against my mysql client and couldnt work out why the module kept adding the '', you're solution works a treat, thanks torsten > >however this : > > > >self.curs.execute( > > """SELECT * FROM user WHERE login LIKE '%dave%'""" > > ) > > > >does work > > > >so what's the go ? > >cheers > >Dave > > > > -- > http://mail.python.org/mailman/listinfo/python-list From achrist at easystreet.com Tue Aug 5 18:56:22 2003 From: achrist at easystreet.com (achrist at easystreet.com) Date: Tue, 05 Aug 2003 15:56:22 -0700 Subject: recompiled midipy.pyd for 2.3 References: Message-ID: <3F303616.BF4CC936@easystreet.com> smarter_than_you wrote: > > this is a nice windows-based MIDI module with simple interface, it was > previously available for <= 2.0 release (See thread on midi for > win32). > > If anyone wants it please post a reply. Oh yes, I am interested. Al From exarkun at intarweb.us Sat Aug 30 03:03:03 2003 From: exarkun at intarweb.us (Jp Calderone) Date: Sat, 30 Aug 2003 03:03:03 -0400 Subject: Are lists at least as efficient as dictionaries? In-Reply-To: <1062177877.1855.6.camel@adsl-209.204.179.133.sonic.net> References: <781faf41.0308281604.51e48f45@posting.google.com> <20030829145423.GA30577@intarweb.us> <1062177877.1855.6.camel@adsl-209.204.179.133.sonic.net> Message-ID: <20030830070303.GA4892@intarweb.us> On Fri, Aug 29, 2003 at 10:24:37AM -0700, Chad Netzer wrote: > On Fri, 2003-08-29 at 07:54, Jp Calderone wrote: > > > += could simply be syntactic sugar for a call to __add__ and then an > > assignment. This would work for mutable and immutable objects. > > But it loses the advantage that some objects would otherwise have of > being able to mutate in place, without allocating a new object (ie. very > large matrix additions). > But as you removed from my original post, list.extend() exists. All one has to do to retain the existing functionality of __iadd__ is name the method something else, then call it. All the advantages, none of the confusing or difficult to track semantics. Jp From chema-news at chema.homelinux.org Wed Aug 27 16:12:44 2003 From: chema-news at chema.homelinux.org (=?iso-8859-1?Q?Jos=E9_Mar=EDa?= Mateos) Date: Wed, 27 Aug 2003 22:12:44 +0200 Subject: Filtering virus-related e-mails? References: <3f4ce4d6$0$166$a1866201@newsreader.visi.com> Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 In comp.lang.python, Grant (grante at visi.com) wrote: > Would it be possible for the python mailing list to filter out > the "virus-warning" emails rather than posting them to the > newsgroup? Filtering out all the posts with the word "virus" in the subject line helps a log. Regards, Chema. - -- Esta direcci?n de correo NO se lee. Quita "-news" para contestar This e-mail address is NOT being read. Take out "-news" to reply Web & GPG key: http://chema.homelinux.org/ -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (GNU/Linux) iD8DBQE/TRC89P6GbSlI+hkRAmdYAKDOR2+4ZgI/h/0BTeprD+1mHIEyywCeNlPk U0JP3Zai4mBsW/xsCBxqv9Q= =stWi -----END PGP SIGNATURE----- From a.schmolck at gmx.net Wed Aug 20 13:38:39 2003 From: a.schmolck at gmx.net (Alexander Schmolck) Date: 20 Aug 2003 18:38:39 +0100 Subject: What's better about Ruby than Python? References: Message-ID: mertz at gnosis.cx (David Mertz) writes: > Alexander Schmolck wrote previously: > |Anyway, I still don't see a compelling reason why class statements > |couldn't/shouldn't be mutating, rather than rebinding. Is there one? > > I don't think there is any reason why the statement 'class' COULD NOT do > what you describe. But doing so seems much less Pythonic to me. > > In Python, there are a bunch of statements or patterns that ALWAYS and > ONLY binds names. Having something that sometimes binds names, and > other times mutates objects... and you cannot tell the difference > without finding something that may be far away in the code.... well, > that's not how Pythonistas like to think about code. I agree this argument has merrit but I'm not sure I find it completely compelling. What's worse, looking at the top of a file and thinking "Ah so that's what class Foo does" and a) overlooking that somewhere below a 2nd class Foo gets created (and one assumes both with instances that insidously claim to be 'Foos'). b) overlooking that somewhere below a 2nd class Foo gets mutated (and thus all prexisting instances of it) ? I think we'd agree that both options are generally undesirable (so one could conceivably even make class statments with the same name in module scope raise an exception and have the user jump through some hoops if he *really* wants something along those lines, like having to define Foo #2 in a function and have it returned). But at least for b) I can think of one use-case I find rather compelling, namely interactive development. I'd also think that the nasty surprise in a) might well be worse than in b), because at least all instances that claim to be Foos will behave the same. As I said, I'm not hung up on this since admittedly b) isn't necessary for convinient interactive development, which is what I'm really keen on. It just means that one could paste/send code directly to the shell to achieve the desired effect, but as long as there is *one general way* to mutate classes, the IDE/editor etc. could just be made to do the extra work of silently inserting the required python code for class mutation before sending to the shell. 'as From cartermark46 at ukmail.com Mon Aug 18 12:57:10 2003 From: cartermark46 at ukmail.com (Mark Carter) Date: 18 Aug 2003 09:57:10 -0700 Subject: Exiting python to the DOS shell in 2.3 References: Message-ID: Stephen Boulet wrote in message news:... > Control-C doesn't get me back to the DOS prompt anymore in python 2.3. > Aside from typing "import sys" and "sys.exit()", is there a key > combination to quit python? Control-Z From sjmachin at lexicon.net Fri Aug 1 21:54:16 2003 From: sjmachin at lexicon.net (John Machin) Date: 1 Aug 2003 18:54:16 -0700 Subject: Problem with Unzipping/Installing Python-2.3.exe References: Message-ID: bokr at oz.net (Bengt Richter) wrote in message news:... > On 1 Aug 2003 15:06:20 -0700, sjmachin at lexicon.net (John Machin) wrote: > > >John Latter wrote in message news:... > >> Hi, > >> > >> I downloaded Python-2.3.exe but when I used winzip it kept asking me > >> if I wanted to replace old files with new ones, and in some instances, > >> new files with old ones. > >> > >> I've never downloaded/installed Python before, and as something of a > >> computer novice, would like to know what I may be doing wrong! > >> > >> This is the link I downloaded from: > >> > >> >Windows users should download the Windows installer, Python-2.3.exe > >> >, run it and follow the friendly instructions on the screen to complete > >> >the installation. > > > >Faced with the 4 clues in the above sentence: > > > >(1) "installer" > >(2) ".exe" > >(3) "run it" > >(4) complete absence of any mention of ".zip", "unzip", "Winzip", ..., > > > >my expectation would be that one should run the damn thing, not try to > >unzip it. > > > >Do you feel that the instructions were unclear? Do you have any > >suggestions on how they might be improved? > > > I guess for those who are rightfully afraid of any .exe's downloaded from the net, Except that the OP's remarks didn't strike me as being those of one who "fears to tread" :-) > a parenthetic reassuring mention in the same paragraph that the MD5 digests and file > sizes are displayed further down the page might be a small improvement. Then all you > have to do is trust the folks that created installer and the files and web page ;-) > Indeed. In-Timbot-we-trust-ly-yours, John From achalk at XXXmagnacartasoftware.com Mon Aug 4 14:03:30 2003 From: achalk at XXXmagnacartasoftware.com (Andrew Chalk) Date: Mon, 04 Aug 2003 18:03:30 GMT Subject: Passing a string argument by reference References: <3f2d728a$0$49117$e4fe514c@news.xs4all.nl> Message-ID: Thanks. You guessed correctly about what I am trying to do although I think the syntax is: self.txtCIF = self.form.getvalue('txtCIF', self.txtCIF) Regards "Irmen de Jong" wrote in message news:3f2d728a$0$49117$e4fe514c at news.xs4all.nl... > Andrew Chalk wrote: > > I am a raw beginner to Python. I just read in "Learning Python" that > > assigning to a string argument inside a function does not change the string > > in the caller. I want an assignment in the function to alter the passed > > string in the caller. Is there any way to do this? > > No. Strings are immutable. However, there is a better solution to do what > you want: just return the new value as a result of the function, and > let the caller process this further. > > Example: > > def addBarToString(variable): > return variable+"bar" > > called with: > > variable="foo" > variable=addBarToString(variable) > print variable > > results in >>foobar<< to be printed. > > > > For example > > > > def SafeAdd(self, Variable, Value): > > if self.form.has_key( Value ): > > Variable = self.form[Value].value > > > > Called with: > > > > self.SafeAdd(self.txtCIF, 'txtCIF') > > > > self.CIF is not changed on return from the function. How do I modify this so > > that it is? > > I understand that you want to assign self.txtCIF (not self.CIF as you > wrote) the value of self.form['txtCIF'], but only if that value > occurs in self.form? > > There is a much easier way to do this. I suspect that self.form is > a dictionary (or a dict-like object). > > Just use: > > self.txtCIF = self.form.get('txtCIF', self.txtCIF) > > The second argument to the get method is the default value that is > returned if the required key is not present in the dict. > In this case, it returns the 'old' value of self.txtCIF, so in effect, > self.txtCIF will be unchanged if 'txtCIF' does not occur in self.form. > Also see http://www.python.org/doc/current/lib/typesmapping.html > > Hope this helps! > --Irmen de Jong > From mpeuser at web.de Sat Aug 16 14:57:10 2003 From: mpeuser at web.de (Michael Peuser) Date: Sat, 16 Aug 2003 20:57:10 +0200 Subject: GUI builder for Python References: <3F3DC73C.3ADD3980@easystreet.com> <3F3E64B0.2E691EF9@easystreet.com> Message-ID: Well, of course you are absolutly right, but we are real programmers aren't we. And all interface is english (with even less typos than in my postings ;-)). Given, that Visual Wx is meant for C++ as a lot of other GUI Builders. Python and Perl is a side issue, but it seems to work. For a preview you can only use: Build - Run which starts the Python interpreter with the Python code. But where is the code? - Make a new Project - Select a template that sounds good: Menu_Toolbar_Python e.g. - Store it somewhere. Now it is a little disappointing that nothing breathtaking pops up. But you already can "RUN" it. Looks great. Use the tree at the right hand side to open the design of MyFrame or look at the source code (Python). In seems there is something missing (MyApp, MyFrame), but you can open the sources using the L-Icon. The problem now is, that the file types is set to Python and - hey presto - there are the files. Well, all over a little immature but that's the situation with most of the tools, which were meant for C++ und got a Perl/Python outlet... Kindly Michael Peuser schrieb im Newsbeitrag news:3F3E64B0.2E691EF9 at easystreet.com... > Michael Peuser wrote: > > > > > > Well try it out then - a little bit English is in it ;-) > > http://visualwx.altervista.org/indexen.htm > > Sorry. I don't see any information on that page on how to use Visual > Wx. It tells how to download and install, and I succeeded at that. > The program runs, showing me a nice UI with thee panels. The left > panel looks to be a list of wx classes that I can add to my project. > The central panel can display source code. The right panel is a > tree control showing an outline of the project. > > There is no explanation of how to use these panels to create any > specific results. The word 'visual' in the name of the program > vaguely suggests that I get to see what my UI looks like as I > design it, but I haven't found any way to get visual wx to show > me anything that looks like a display of the ui of the project > being worked on. I'm pretty well lost at that point. > > There is a forum link from the web page, but last I looked, the > postings are all in Italian. I'm certainly not criticizing > someone who speaks and writes Italian for not writing English. > I'm not saying that the program isn't very good. It looks like > it might be very good even if I have drawn an unjustified > inference about what 'visual' means. I'm just suggesting that > if anyone who knows English uses Visual Wx to some advantage, > and if they could post somewhere just a few paragraphs about how > to use it, Visual Wx could have a place on the list of answers > to the GUI-builder question. > > > Al From staschuk at telusplanet.net Fri Aug 1 17:07:46 2003 From: staschuk at telusplanet.net (Steven Taschuk) Date: Fri, 1 Aug 2003 15:07:46 -0600 Subject: Retrieve source filename In-Reply-To: <6qk79xh6me.fsf@salmakis.intevation.de>; from bh@intevation.de on Fri, Aug 01, 2003 at 03:03:53PM +0200 References: <3f29207d$0$24768$626a54ce@news.free.fr> <6qk79xh6me.fsf@salmakis.intevation.de> Message-ID: <20030801150746.A865@tibia.amotlpaa.bogus> Quoth Bernhard Herzog: > Steven Taschuk writes: [...] > > sys.modules[__name__].__file__ > > Why so complicated? Just as __name__, __file__ is simply a global > variable in the module, so you can use it directly. Heh. Good catch. -- Steven Taschuk staschuk at telusplanet.net "What I find most baffling about that song is that it was not a hit." -- Tony Dylan Davis (CKUA) From ramiak2000 at yahoo.com Fri Aug 22 19:36:46 2003 From: ramiak2000 at yahoo.com (Rami A. Kishek) Date: Fri, 22 Aug 2003 19:36:46 -0400 Subject: 2 funny Py2.3 Issues: 'datetime', string.join() References: <3F42AB3D.F9B456F4@yahoo.com> Message-ID: <3F46A90E.6070503@yahoo.com> Thanks - that answers both my questions The argument for join is pretty convincing, though it wouldn't hurt to write add a list method which aliases the string method and does the same thing. Just a thought ... Andrew Dalke wrote: > http://www.python.org/cgi-bin/faqw.py?req=show&file=faq04.096.htp > You'll need to use __new__ for any immutable object. From vze4rx4y at verizon.net Sun Aug 17 12:28:38 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Sun, 17 Aug 2003 16:28:38 GMT Subject: Py2.3: Feedback on Sets (fwd) References: <2e363c08.0308161306.47a010ae@posting.google.com> Message-ID: "Alex Martelli" wrote in message news:bhntvc01enr at enews1.newsguy.com... > David Mertz wrote: > ... > > Raymond Hettinger also wrote: > > |from sets import Set > > |def powerset(iterable): > > | data = list(iterable) > > | for i in xrange(2**len(data)): > > | yield Set([e for j,e in enumerate(data) if i&(1< > > > Hmmm... I should have checked the docs first. A sample implementation > > obviously helps. That said, this isn't REALLY an implementation of > > powerset. It returns an iterator, not a set. Now, sure... an iterator > > is a BETTER thing to get, for lots of reasons. But I'm not sure it > > lives up to the function name. > > Surely writing > > def therealpowerset(iterable): > return Set(powerset(iterable)) > > (or just inlining the Set call) isn't beyond the abilities of most > prospective users. Just like one calls list(x) on any iterable x > if one needs specifically a list, so does one call Set(x) if one > needs specifically a set. Sure, the name is debatable, and maybe > 'subsetsof' would be neater. But I think this is quibbling. > > IMHO, one 'real' issue with this function is that it behaves strangely > (to me) when iterable has duplicated elements -- namely, the > resulting iterator also has duplications. Changing the single > statement that is currently: > data = list(iterable) > into > data = Set(iterable) > would make duplications in 'iterable' irrelevant instead. Good call. Do you guys want the revised version added to the docs or perhaps saved as an ASPN recipe? >>> from sets import Set >>> def powersetiterator(iterable): ... data = Set(iterable) ... for i in xrange(2**len(data)): ... yield Set([e for j,e in enumerate(data) if i&(1<>> Set(powersetiterator('abc')) Set([ImmutableSet([]), ImmutableSet(['a']), ImmutableSet(['c']), ImmutableSet(['b']), ImmutableSet(['c', 'b']), ImmutableSet(['a', 'c']), ImmutableSet(['a', 'b']), ImmutableSet(['a', 'c', 'b'])]) Raymond Hettinger From sjmachin at lexicon.net Fri Aug 8 19:19:48 2003 From: sjmachin at lexicon.net (John Machin) Date: 8 Aug 2003 16:19:48 -0700 Subject: extension mixes MSVC & mingw32 stdio (was: Re: Building extensions with mingw32 -- bdist_wininst fails.) References: <87adak1vez.fsf@smtp.gsi.de> Message-ID: Pierre Schnizer wrote in message news:<87adak1vez.fsf at smtp.gsi.de>... > "Chris Gonnerman" writes: > > > ----- Original Message ----- > > From: "Thomas Heller" > > > > > > I checked the archives regarding that error message and > > > > found a conversation wherein Jeremy Hylton claimed he > > > > might have added the code to detect this, and Paul Moore > > > > asked to have it removed/disabled at least for mingw32 > > > > (which makes binaries 100% compatible with MSVC6). In > > > > the case given then, the extension wouldn't build at > > > > all; now it builds but I can't make a Windows installer > > > > from it. > > Please excuse, if it is a bit out topic. You're excused. > When I tried to build an extension module for Python2.2 with MingW3.0 I had > problems with the conversion of files. So > > myfile = PyFile_AsFile(object); > > would crash python2.2 when a standard Python2.2 was invoking an extension > module compiled with MinGW. > If Python is compiled with compiler X, and an extension is compiled with compiler Y, there is a very high chance that the runtime support for files is quite different. What X's FILE* points to will be different to what Y's FILE* points to. Although MinGW uses the MSVC runtime msvcrt.dll, it's not the sort of thing you should bet your last dollar on. For portability, always assume that X != Y. So, either (1) get a filename from the Python caller, and fopen it yourself, and use stdio functions on the FILE* or (2) get a PyFileObject* from the Python caller, and use the high-level API functions on that e.g. PyFile_GetLine, PyFile_WriteString [not useful if you have embedded '\0' in your string], PyFile_WriteObject. IMHO, PyFile_AsFile() and PyFile_FromFile() should have severe warnings in the documentation. Hope this helps, John From raims at dot.com Tue Aug 26 17:28:16 2003 From: raims at dot.com (Lawrence Oluyede) Date: Tue, 26 Aug 2003 23:28:16 +0200 Subject: My future Python IDE article References: <87smno1bfh.fsf@vercingetorix.caesar.org> <%yP2b.284$rC1.12766@nnrp1.ozemail.com.au> Message-ID: <87oeycrtvz.fsf@voodoo.fake> "Peter Milliken" writes: > I use the same Emacs configuration with the addition of ELSE (with the > python code templates for easy code input) and PyMacs (for extending Emacs > using Python). Cool! How does ELSE works? How could i setup Emacs to use it easily? PyMacs? Wow :) I'll check it out tomorrow -- Lawrence "Rhymes" Oluyede http://loluyede.blogspot.com rhymes at NOSPAMmyself.com From daniel.rawson.take!this!out! at asml.nl Wed Aug 6 10:13:30 2003 From: daniel.rawson.take!this!out! at asml.nl (Dan Rawson) Date: Wed, 06 Aug 2003 10:13:30 -0400 Subject: Checking for an "undefined" variable - newbie question In-Reply-To: References: Message-ID: Steven Taschuk wrote: > Quoth Dan Rawson: > >>How do I check if a variable has been defined?? > > [...] > >>try: >> variable >>except NameError: >> ... > > > This is the answer to your question. > > >>If there's a more elegant way to check this, that would be great! > > > Why do you want to check it in the first place? > > In particular, why not initialize your variable to some > out-of-band value (such as None) and test that? E.g., > > myvar = None > # ... code which might set myvar to something else ... > if myvar is None: > # ... > So I guess it's as much a philosophy issue as a technical one . Thanks to everyone for their suggestions; I now have the script up and running! Dan From graham at rockcons.co.uk Mon Aug 11 08:44:27 2003 From: graham at rockcons.co.uk (Graham Nicholls) Date: Mon, 11 Aug 2003 13:44:27 +0100 Subject: Fun with numbers - dammit, but I want a cast! Message-ID: <3f378fac$0$10778$afc38c87@auth.uk.news.easynet.net> Hi. I'm having some fun with numbers. I've extraced an image sizes from a jpeg file img_x,img_y=image.getsize() then I'm trying to use those sizes to scale the image, but because python has decided that they are integers, I keep getting division by zero errors eg xscale=xframe/img_x where xframe will be say 300, and img_x will be 1800 xscale has the value 0. I've tried doing img_x=1.0 to force it to be a float, but I'm getting a bit frustrated as it seems to make no difference - once image.getsize returns the (integer) value of the x size, it simply converts back to an int. I've tried this at the command line, and it seems to confirm that behaviour - eg: graham at rocklap:~/work/hsb/pdflive> python Python 2.3b1 (#3, Jun 17 2003, 23:06:11) [GCC 3.3 20030226 (prerelease) (SuSE Linux)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> x=1.0 >>> xf=1.0 >>> scale=1.0 >>> x=1800 >>> xf=300 >>> scale=xf/x >>> scale 0 >>> Heres the relevant code in full: img_x=1.0 img_y=1.0 img_x,img_y=image.getsize() except "Not_JPEG": if warn: print ("WARNING: Image file %s is not a jpeg file" % fname) sys.exit(OPEN_ERR) # How many pixels per mm do we have # On a4 paper, using pdfrw ? Docs seem to suggest between 60-160 # which seems a lot. xscale=1.0 yscale=1.0 scale=1.0 xscale=1/(xframe/img_x) yscale=1/(yframe/img_y) #import pdb #pdb.set_trace() print ("xscale=%f,yscale=%f" %(xscale,yscale)) scale=min(xscale,yscale) * 100 print ("xframe=%d,yframe=%d, x=%d,y=%d scale=%f\n" %(xframe, yframe, img_x, img_y, scale)) I'd really appreciate some help, thanks! Graham -- Graham Nicholls Rock Computer Consultancy From skip at pobox.com Fri Aug 1 11:08:08 2003 From: skip at pobox.com (Skip Montanaro) Date: Fri, 1 Aug 2003 10:08:08 -0500 Subject: 'long int too large to convert to int' in 'garbage collection' ignored In-Reply-To: <00b001c3583b$799c3160$83706698@newlife> References: <00b001c3583b$799c3160$83706698@newlife> Message-ID: <16170.33368.723704.152956@montanaro.dyndns.org> Peter> FutureWarning: hex/oct constants > sys.maxint will return Peter> positive values in Python 2.4 and up You can suppress this warning. I don't know the implications downstream though. You should read through the 2.3-related docs. This page looks particularly useful: http://www.python.org/doc/2.3/whatsnew/node22.html Skip From mis6 at pitt.edu Mon Aug 18 17:43:06 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 18 Aug 2003 14:43:06 -0700 Subject: overriding a tuple's __init__ References: Message-ID: <2259b0e2.0308181343.3ad9ad77@posting.google.com> "Andrew Dalke" wrote in message news:... > Simon Burton: > > >>> class pair(tuple): > > ... def __init__(self,a,b): > > ... tuple.__init__(self, (a,b) ) > > > What gives? (yes it works with a list, but i need immutable/hashable) > > The problem is the immutability. This one one of the > new changes in 2.3 Actually this was a change in 2.2 __new__ is needed to acts on the creation of immutable objects and this is the right way to use it; unfortunaly it gives room to plenty of abuses: class YouThinkIamAString(str): def __new__(cls,arg): return 42 print YouThinkIamAString("What's the answer?") Yes, in Python you cannot modify the builtins, but still you have plenty of rope to shoot in your foot ;) Michele From alf at fayauffre.org Fri Aug 8 09:05:14 2003 From: alf at fayauffre.org (Alexandre Fayolle) Date: Fri, 8 Aug 2003 13:05:14 +0000 (UTC) Subject: Problem with mod_python and 4Suite References: <88bc63c6.0308080449.3e6fdf7a@posting.google.com> Message-ID: Doug Farrell a ?crit : > Hi all, > > I'm trying to build a demonstration website using mod_python and > 4Suite to show how we could transform XML documents into HTML with > XSLT. Here is a piece of code that causes it to blow up: > > # import the xml/xslt stuff here > from xml.xslt.Processor import Processor This actually imports the broken xslt engine in pyxml, and not 4suite's. This engine is known not to work. You want to import Ft.Xml.Xslt to use 4suite xslt engine in the 1.0 branch. You will also have to adapt your code to the new apis introduced since 4suite 0.12, please see the documentation. Try asking on the 4Suite mailing list (links to the list available from http://4suite.org/) -- Alexandre Fayolle LOGILAB, Paris (France). http://www.logilab.com http://www.logilab.fr http://www.logilab.org D?veloppement logiciel avanc? - Intelligence Artificielle - Formations From tzot at sil-tec.gr Sun Aug 24 00:29:46 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Sun, 24 Aug 2003 07:29:46 +0300 Subject: Bug with win32 open and utf-16 file References: <27vekvc6evvn3m5jg8n1en2u42skat42qn@4ax.com> <2i1gkv0s7762vcs85rkdq6uvgk6oitje12@4ax.com> <78egkvg1tu0j1kvedclcefn01hr3vkqh4v@4ax.com> Message-ID: On Sun, 24 Aug 2003 04:13:44 GMT, rumours say that derek / nul might have written: >Interesting, I have just done the same and it would appear that the hexdump >routine is changing 0d to 0a ??? A quick glance at the code seems not, but this is not authoritative. >I don't understand what the data[-2:] is doing, could you explain please or >point to some notes on this. This is a slicing operation, prints the last two bytes of the string -- you mean you haven't read the tutorial? Check strings (and slicing) at: http://www.python.org/doc/current/tut/node5.html#SECTION005120000000000000000 but you better read the tutorial at: http://www.python.org/doc/current/tut/tut.html (you might have it on your computer already). Say... :) you don't happen to be an HP owner that found python preinstalled on your PC, are you? -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From mack at incise.org Wed Aug 20 22:53:11 2003 From: mack at incise.org (mackstann) Date: Wed, 20 Aug 2003 21:53:11 -0500 Subject: Problems with python-list? In-Reply-To: <477762c2.0308201832.327cf5bc@posting.google.com> References: <477762c2.0308201832.327cf5bc@posting.google.com> Message-ID: <20030821025311.GE1695@incise.org> On Wed, Aug 20, 2003 at 07:32:52PM -0700, Dave Brueck wrote: > Is anybody else having problems sending email to > python-list at python.org? About 48 hours ago or so my posts stopped > making it to the list (I usually post via the mailing list rather than > to the Usenet group). Yeah, I replied to the thread about tracing the hierarchy of function calls, but it either didn't get to python.org, or it didn't get back to me, because I never saw the reply come up. (Err, wait, I see you're posting via google, hmm, let's see if this gets to the list or not) -- m a c k s t a n n mack @ incise.org http://incise.org If you had any brains, you'd be dangerous. From duncan at NOSPAMrcp.co.uk Tue Aug 19 04:28:06 2003 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Tue, 19 Aug 2003 08:28:06 +0000 (UTC) Subject: Python newbie help References: <87fa5cfa.0308181126.c61bfa2@posting.google.com> Message-ID: stephen at hostwiththemost.net (s) wrote in news:87fa5cfa.0308181126.c61bfa2 at posting.google.com: > I've recently been very interested in learning Python but I seem to > lack direction while reading the tutorials. I understand the syntax > and everything concerning the language itself but the tutorials I have > seen are merely displaying features of the language rather than > teaching you to code while reaching an end goal of a program and I > think that's been my problem with learning the language so slowly. Is > anyone aware of an online tutorial with examples that actually end up > creating a semi-useful program and not just snippets of code > displaying how the code functions? I think that many people coming to Python already know how to program, and they are the ones that the tutorial is aimed at. Teaching a new language to someone who already programs is a very different thing from teaching Python to people who know nothing about programming (the latter have far less to unlearn!) It depend what you mean by 'semi-useful', but you might want to have a look at the Livewires Python Course, http://www.livewires.org.uk/python/ which is intended for teaching programming to teenagers who have never programmed before. > The course consists of a collection of worksheets. The Beginners' > course consists of 5 numbered worksheets (numbered Sheet 1 to Sheet > 5), which are intended to be worked through in numerical order, and a > whole load of lettered worksheets (lettered A to Z, with some gaps) > which provide background or go deeper into a particular topic. As well > as this, there are some games worksheets which are intended for people > who have been through the numbered sheets. Each sheet takes the reader > through the process of writing a simple graphical game (such as Space > War, or Pacman). -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From imbaczek at poczta.onet.pl Tue Aug 5 16:54:22 2003 From: imbaczek at poczta.onet.pl (=?iso-8859-2?Q?Marek_=22Baczek=22_Baczy=F1ski?=) Date: Tue, 5 Aug 2003 22:54:22 +0200 Subject: Fatal Python error: unknown scope for... Message-ID: <1hpgt2ltmkd5a$.dlg@baczek.net.invalid> :map ,p :!python % ,p #v+ C:\COMMAND.COM /c python items.py Fatal Python error: unknown scope for super in __init__(14) in items.py symbols: {'multirandrange': 264} locals: {} globals: {'multirandrange': True} abnormal program termination Hit any key to close this window... #v- (also have mp for PyChecker, which failed miserably with the same message) I must have done something *really* bad, I said to myself. Yet IMHO I didn't (just paste'n'run): class Weapon(Item): def __init__(self, name, category, rarity=COMMON, weight, damdie = (1,6), tdamdie=(1,4), material=None, effects = (), todam_f = lambda: multirandrange(-1,2,3)): super(Weapon, self).__init__(name, weight, damdie, tdamdie, rarity, material, effects, todam_f=todam_f) self.category = category Apparently, removing todam_f fixes the FPE, as well as making the code syntactically correct (moving rarity after weight.) Seems like something got overlooked in the parser? Almost forgot: Python 2.3/win98 Pozdrawiam, Baczek From stefan.arentz at soze.com Fri Aug 1 03:39:42 2003 From: stefan.arentz at soze.com (Stefan Arentz) Date: 01 Aug 2003 09:39:42 +0200 Subject: Python vs. Perl vs. PHP? References: <7b454334.0307281002.41dae81b@posting.google.com> <87oezebjh8.fsf@flibuste.net> Message-ID: <87smolomgx.fsf@keyser.soze.com> Wilk writes: > faizan at jaredweb.com (Fazer) writes: > > > Hello, > > > > I am an avid user of PHP and I am just fooling around with Python for > > now. I originally wanted to know which one is faster. As in, works > > faster. So far, I think PHP is the fastest for dynamic web-content. > > Am I wrong? > > yes for two reasons, one relative, one more objective : > > - you'll write cleaner and shorter programs with python, so more easy to > optimize A bad programmer will write shitty code in both PHP and Python. > - when you'll really need speed, you'll write standalone web-server with > python, and so a lot more eficient and fast in high trafic. Compared to Apache 2.0 with PHP/Zend & Accelerator? I honestl don't think so. When PHP is compiled to native code it is as fast as Java or C. S. From exarkun at intarweb.us Wed Aug 13 14:08:58 2003 From: exarkun at intarweb.us (Jp Calderone) Date: Wed, 13 Aug 2003 14:08:58 -0400 Subject: Testing a class at the interactive prompt? In-Reply-To: References: Message-ID: <20030813180858.GA3148@intarweb.us> On Wed, Aug 13, 2003 at 01:45:40PM -0400, Dan Rawson wrote: > How can I reload a class at the interactive prompt?? > > [snip] > > >>> from MyClass import MyClass1 > > doesn't give an error, but also doesn't get the newly modified method . . . > Don't use "from" imports here, and things will work as you desire. Jp From eric.brunel at pragmadev.com Thu Aug 14 11:21:43 2003 From: eric.brunel at pragmadev.com (Eric Brunel) Date: Thu, 14 Aug 2003 17:21:43 +0200 Subject: Python/Tkinter/tk crash [long] References: Message-ID: <3F3BA907.9000807@pragmadev.com> Jeff Epler wrote: > I can duplicate the signal 11 on RedHat Linux 9 and the following > relevant packages installed: > python-2.2.2-26 > tcl-8.3.5-88 > tk-8.3.5-88 > > My traceback looks like the following. I believe that the lines listed > as "Tk_GetItemTypes" actually correspond to static functions defined in > tkCanvas.c. > #0 0x4011b1a7 in Tk_GetItemTypes () from /usr/lib/libtk8.3.so > #1 0x4011aec1 in Tk_GetItemTypes () from /usr/lib/libtk8.3.so > #2 0x4011ac25 in Tk_GetItemTypes () from /usr/lib/libtk8.3.so > #3 0x400d1a7c in Tk_HandleEvent () from /usr/lib/libtk8.3.so > #4 0x400d1e7c in TkQueueEventForAllChildren () from /usr/lib/libtk8.3.so > #5 0x401c300d in Tcl_ServiceEvent () from /usr/lib/libtcl8.3.so > #6 0x401c326d in Tcl_DoOneEvent () from /usr/lib/libtcl8.3.so > #7 0x40062115 in Tkapp_MainLoop (self=0x815dfb0, args=0x8269358) at Modules/_tkinter.c:1696 > #8 0x080d0df4 in PyCFunction_Call () > #9 0x0807a65e in PyEval_EvalCode () > #10 0x0807b0ce in PyEval_EvalCodeEx () > #11 0x0807c62b in PyEval_GetFuncDesc () > #12 0x0807a5a3 in PyEval_EvalCode () > #13 0x0807b0ce in PyEval_EvalCodeEx () > #14 0x08077fc5 in PyEval_EvalCode () > #15 0x08097e29 in PyRun_FileExFlags () > #16 0x08096d90 in PyRun_SimpleFileExFlags () > #17 0x080966da in PyRun_AnyFileExFlags () > #18 0x08053a19 in Py_Main () > #19 0x08053469 in main () > #20 0x42015574 in __libc_start_main () from /lib/tls/libc.so.6 > > This leads me to two things: first, reproduce this using a libtk > compiled with debugging information. second, this is likely to be a Tk > bug and not a Python bug given where it happens. It should be possible > to write a test-case that is purely tcl code.. Thanks a lot: you're absolutely right. The tcl code you wrote behaves exactly the same than the Python script I sent: when I run it, the first click on any text ends in a seg fault or a bus error. I should have tried to reproduce the bug in pure tcl, but I'm not really fluent in it... I'll try to figure out exactly what happens and submit the problem to the c.l.tcl newsgroup. Thanks! -- - Eric Brunel - PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com From mertz at gnosis.cx Tue Aug 26 13:39:17 2003 From: mertz at gnosis.cx (David Mertz) Date: Tue, 26 Aug 2003 13:39:17 -0400 Subject: My future Python IDE article Message-ID: Pythonistas, My loyal fans :-) will remember that I did a Python IDE roundup for _Charming Python_ a couple years back. Now I have another such roundup lined up... not the very next article, but it's there on the list. In the intervening years, I've hardly touched anything one might call an IDE. I've looked at screenshots from time to time, and read various announcements. But really I just use text editors and command lines. Here's the thing: I probably have room to look at about four different tools in one article. In fact, it wouldn't be absurd to only do three. Past that, I cannot do more than list contact information and platform in the available words. I'm sure there are more than four IDEs that -someone- loves to work with out there... but I need to have a cutoff. So c.l.py readers... make the case for your favorite one getting on the list. I have a while to ponder the opinions advanced, should this prompt some discussion (it may take a little while to order review copies of commercial tools and/or get things installed). Yours, David... -- _/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY: Postmodern Enterprises _/_/_/ _/_/ ~~~~~~~~~~~~~~~~~~~~[mertz at gnosis.cx]~~~~~~~~~~~~~~~~~~~~~ _/_/ _/_/ The opinions expressed here must be those of my employer... _/_/ _/_/_/_/_/_/_/_/_/_/ Surely you don't think that *I* believe them! _/_/ From peter at engcorp.com Wed Aug 20 12:43:36 2003 From: peter at engcorp.com (Peter Hansen) Date: Wed, 20 Aug 2003 12:43:36 -0400 Subject: python quickie : retrace function steps? References: <5f5c82ec.0308200820.51c8e33c@posting.google.com> Message-ID: <3F43A538.F56D59A8@engcorp.com> Matt Smith wrote: > > If I was to make a function call another function, and from that > function, call another function (so that now I was in a 3rd function) > something like this: > > (function 1) > |________(function 2) > |________(function 3) > > Is there away I can print out the path my Program had taken (i want to > do this as part of my error checking, so a user would always know the > path my program took)? > > i.e. printted output of error would be: > > error with function 3 > function 3 called from function 2 > function 2 called from function 1 This is called a traceback, and Python handles them naturally whenever an Exception is raised. In this case, if your own code detects an error, you would raise a custom exception (subclassed from Exception). You should be able to find dozens of examples pretty easily. Also read about the "traceback" module, as it has handy information about and functions for this stuff. Also the sys._getframe() function could be of use. Try this inside your function3 to see the effect: raise Exception('too much spam!) If you hit that line, your program should exit and Python will print the full traceback at the console (assuming the program was launched from the console). -Peter From mpeuser at web.de Mon Aug 18 03:42:16 2003 From: mpeuser at web.de (Michael Peuser) Date: Mon, 18 Aug 2003 09:42:16 +0200 Subject: bitwise not - not what I expected References: <1YD%a.747879$3C2.17342633@news3.calgary.shaw.ca> Message-ID: "Bengt Richter" schrieb im Newsbeitrag news:bhpjm1$g01$0 at 216.39.172.122... > On Sun, 17 Aug 2003 22:18:39 GMT, Dennis Lee Bieber wrote: > > >Michael Peuser fed this fish to the penguins on Sunday 17 August 2003 > >02:41 pm: > > > >> I have the impression (may be wrong) that you are working under the > >> misconception that there can be a "natural" binary represensation of > >> negative numbers!? > > > > Apologies if I gave that impression... the +/- 0 technical affair is > >the main reason I went into the whole thing... > > > >> Three conventions have commonly been used so far: > >> 1- Complement > >> 2-Complement > >> Sign tag plus absolut binary values > >> > >> All of them have their pros and cons. For a mixture of very technical > >> reasons (you mentioned the +0/-0 conflict, I might add the use of > >> binary adders for subtraction) most modern computers use 2-complement, > >> and this now leads to those funny speculations in this thread. ;-) > >> > > From a human readable standpoint, your third option is probably the > >most "natural"; after all, what is -19 in human terms but a "pure" 19 > >prefaced with a negation tag marker... (I believe my college > >mainframe's BCD hardware unit actually put the sign marker in the > >nibble representing the decimal point location -- but it has been 25 > >years since I had to know what a Xerox Sigma did for COBOL packed > >decimal ). > > > > ie, 00010011 vs -00010011 > > > > 1s complement is electrically easy; just "not" each bit. > > > > 2s complement is mathematically cleaner as 0 is 0, but requires an > >adder to the 1s complement circuit... Though both complement styles > >lead to the ambiguity of signed vs unsigned values > > > Everyone says "two's complement" and then usually starts talking about numbers > that are bigger than two. I'll add another interpretation, which is what I thought > when I first heard of it w.r.t. a cpu that was designed on the basis that all its > "integer" numbers were fixed point fractions up to 0.9999.. to whatever precision > the binary fractional bits provided. There was no units bit. And if you took one > of these fractional values 0.xxxx and subtracted it from 2.0, you would have a > complementary number with respect to two. Well, for addition and subtraction, that turns > out to work just like the "two's complement" integers we are used to. But since the > value of fractional bits were all in negative powers of two, squaring e.g., .5 had > to result in a consistent representation of 0.25 -- i.e. in binary squaring 0.1 > resulted in 0.01 -- which is shifted one bit from what you get looking at the numbers > as integers with the lsb at the bottom of the registers and the result. > > I.e., a 32-bit positive integer n in the fractional world was n*2**-31. If you square > that for 64 bits, you get n**2, but in the fractional world that looks like (n**2)*2**-63, > where it's supposed to be (n*2**-31)**2 => (n**2)*2**-62 with respect to the binary point. > The fractional model preserved an extra bit of precision in multiplies. > > So on that machine we used to count bits from the left instead of the right, and place imaginary > binary points in the representations, so a binary 0.101 could be read as "5 at 3" or "2.5 at 2" > or "10 at 4" etc. And the multiplying rule was x at xbit times y at ybit => x*y at xbit+ybit. > > You can do the same counting the bit positions leftwards from lsb at 0, as we usually do now, > of course, to play with fixed point fractions. A 5 at 0 is then 1.25 at 2 ;-) > > Anyway, my point is that there was a "two's complement" implementation that really meant > a numeric value complement with respect to the value two ;-) > > Regards, > Bengt Richter A very good point! I might add that this is my no means an exotic feature. Mathematically speaking there is great charme in computing just inside the invervall (-1,+1). And if you have no FPU you can do *a lot* of pseudo real operations. You have get track of the scale of course - it is a little bit like working with sliding rules if anyone can remember those tools ;-) Even modern chips have support for this format, e.g. there is the 5$ Atmel Mega AVR which has two kinds of multiplication instructions: one for the integer multiplication and one which automatically adds a left shift after the multiplication! I leave it as an exercise to find out why this is necessary when multiplying fractional numbers ;-) Negative numbers are formed according to the same rule for fractionals and integers: Take the maximum positive number: 2**32-1 or 0.999999 Extend your scope Add one bit: 2*32 or 1 Double it: 2*33 or 2 Subtract the number in question Reduce your scope again Kindly Michael P From whiteywidow at yahoo.com Sun Aug 3 11:57:05 2003 From: whiteywidow at yahoo.com (RT Lange) Date: Sun, 03 Aug 2003 11:57:05 -0400 Subject: 2.3 Redhat 9 Tkinter IDLE References: Message-ID: On Sun, 03 Aug 2003 09:50:26 +0200, Martin v. L?wis wrote: > No, you don't have to edit Modules/Setup. _tkinter is built > automatically if you have the header files installed. i have the header files: /usr/include/tcl.h;/usr/include/tk.h > Sorry, I don't have Redhat 9, so I don't know what the name of the > package is that contains the Tk header files. It probably has the > strings "tcl" and "dev" in their name. the package is buried under "Kernel Development" > It would be better if you reported the steps you have been doing, and > the problems you see. [root@/usr/lib/Python-2.3]# make case $MAKEFLAGS in \ *-s*) CC='gcc -pthread' LDSHARED='gcc -pthread -shared' OPT='-DNDEBUG -g -O3 -Wall -Wstrict-prototypes' ./python -E ./setup.py -q build;; \ *) CC='gcc -pthread' LDSHARED='gcc -pthread -shared' OPT='-DNDEBUG -g -O3 -Wall -Wstrict-prototypes' ./python -E ./setup.py build;; \ esac running build running build_ext building '_tkinter' extension gcc -pthread -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC -fno-strict-aliasing -DWITH_APPINIT=1 -I/usr/X11R6/include -I. -I/usr/lib/Python-2.3/./Include -I/usr/local/include -I/usr/lib/Python-2.3/Include -I/usr/lib/Python-2.3 -c /usr/lib/Python-2.3/Modules/_tkinter.c -o build/temp.linux-i686-2.3/_tkinter.o /usr/lib/Python-2.3/Modules/_tkinter.c:96:2: #error "unsupported Tcl configuration" /usr/lib/Python-2.3/Modules/_tkinter.c: In function `AsObj': /usr/lib/Python-2.3/Modules/_tkinter.c:947: warning: passing arg 1 of `Tcl_NewUnicodeObj' from incompatible pointer type /usr/lib/Python-2.3/Modules/_tkinter.c: In function `FromObj': /usr/lib/Python-2.3/Modules/_tkinter.c:1073: warning: passing arg 1 of `PyUnicodeUCS2_FromUnicode' from incompatible pointer type running build_scripts From afriere at yahoo.co.uk Mon Aug 18 20:59:12 2003 From: afriere at yahoo.co.uk (Asun Friere) Date: 18 Aug 2003 17:59:12 -0700 Subject: What's better about Ruby than Python? References: <38ec68a6.0308172319.431a4fde@posting.google.com> Message-ID: <38ec68a6.0308181659.1aab5c67@posting.google.com> "Brandon J. Van Every" wrote in message news:... > Lulu of the Lotus-Eaters wrote: > > The second surest sign that a post is a troll is if the author > > includes: > > > >>> This is not a troll. > > > > The first surest sign that a post is a troll is if the author is: > > > >> "Brandon J. Van Every" > > Man, it's clear that I've got an entire hate group around here to > exterminate! Doesn't that just mean a lot of people will be able to talk about you behind your back without your ever realising? I was wondering why all those people were making allegations about small children, and you didn't defend yourself. I thought it was all true! > At any rate, welcome to my killfile. Like he cares? Congratulations, you've just managed to deprive yourself of the often insightful contributions of a regular poster to this newsgroup. I wonder if you wouldn't be better off simply not participating in Usenet groups at all. You'll save significant amounts of diskspace without that killfile of yours, not to mention keystrokes. But please feel free to add me to your much vaunted killfile as well, that way you don't have to listen one of the few people who, in this thread, actually took your question seriously and gave a substantive answer. Ah yes, back to substance. I forgot to mention that Ruby ranges seem much more intuitive than Python slicing. But I think the confusion, to the extent that confusion does exist, is because Python has one foot in the C-like 'n-1 indexed array' camp (in relation to ordinary indexing of elements), and one in the '0 is not an ordinal, but a point of origin,' camp (in relation to splitting). :ducks. From frank at pc-nett.no Mon Aug 4 05:43:21 2003 From: frank at pc-nett.no (frank) Date: Mon, 4 Aug 2003 11:43:21 +0200 Subject: ANN: soprano 0.002 Message-ID: Soprano is a GUI app that scans a selected range of ip addresses and try to get info about the hosts such as users, localgroups, shares, operating system. This program only runs under windows enviorment(tested under win2000, should work under xp to, unsure about win98) changes 0.001 > 0.002: added toolbar and menubar. auto features are now in menubar under options. added log window. users can now set "ping timeout". works with python 2.3. eliminated some bugs. Source code and windows binary at http://sourceforge.net/projects/soprano/ From andrew.gregory at npl.co.uk Thu Aug 7 05:18:53 2003 From: andrew.gregory at npl.co.uk (Andrew Gregory) Date: 7 Aug 2003 02:18:53 -0700 Subject: Tkinter programming problem References: Message-ID: <2830c89c.0308070118.73bf2211@posting.google.com> "Mark Daley" wrote in message news:... > I have problems with sys.exit() when I'm running under IDLE, since it seems > to cause ALL mainloops to exit, killing IDLE. I can't really give a whole > lot of detail on this, since I tend to use the command line to launch my > GUIs, anyway. > Using tkinter seems to require a bit of lateral thinking at times (and I think I must have failed the test!!!). I suppose the difficulty lies in getting the right structure (generally true of OOP). Anyway, I did fix the problem and working code is given below. In effect, root does have to be destroyed. Andrew. # Demonstration TK interface Windows application # Runs ok from within IDLE # # A. Gregory, 4th August 2003 # from Tkinter import * class CommonStuff: # to get common access to variables and functions def __init__(self, master): self.master=master self.frame = Frame(master) self.frame.bind("",self.CleanUp) def say_hi(self): print "Hello all" def myquit(self): self.master.destroy() def CleanUp(self, event): print "Cleaning up after Tk windows closed" class MyWidgets(Frame, CommonStuff): def __init__(self, CS): Frame.__init__(self, CS.frame) quitbutton = Button(self, text='Quit', fg='red', command=CS.myquit) quitbutton.pack(side=LEFT) self.hi_there = Button(self, text="Hello", command=CS.say_hi) self.hi_there.pack(side=LEFT) class Application: def __init__(self, CS): displayedwidget=MyWidgets(CS) displayedwidget.grid(row=0, column=0) CS.frame.grid(row=0, column=0) CS.frame.columnconfigure(0) CS.frame.update() root = Tk() CS = CommonStuff(root) mainWin = Application(CS) # If running from IDLE in Python 2.2 or earlier must use root.wait_window(CS.frame) # Otherwise can use # root.mainloop() From pu at nodomain.lu Mon Aug 18 16:34:06 2003 From: pu at nodomain.lu (Patrick Useldinger) Date: Mon, 18 Aug 2003 22:34:06 +0200 Subject: client derived from async_chat In-Reply-To: References: <3f3fdb48_1@news.vo.lu> <3F3FF26F.3D6538F4@alcyone.com> <3f3fff3c_1@news.vo.lu> <3f4001bb_2@news.vo.lu> Message-ID: <3f4137d5$1_1@news.vo.lu> Heiko Wundram wrote: > Remember: connecting is also a non-blocking operation, if the socket is > set to non-blocking mode. I should have read some more about sockets before trying to use async_chat; I thought I would get by 'just adding a few methods'. Shame on me ;-) Anyway, what happened is that 'create_socket()' and 'connect()' were called to quickly one after the other; as async_chat (asnycore, actually) sets the socket on creation to non-blocking, my connect failed. I solved the problem by adding a method 'connect()' in my derived class which looks like this: def connect(self,*args): timeOut=self.gettimeout() self.settimeout(None) SingleServer.connect(self,*args) self.settimeout(timeOut) This did the trick for my chat client. > I dunno why async_chat doesn't work with this on Windows (on *nix, this > is exactly what it does), but I guess it has something to do with > decoding the error codes, as a *nix-socket would return EWOULDBLOCK in > this case, for which it checks, I am certain of that. I think it works as designed, but it was not designed to open sockets for clients, only for servers. I could have opened the socket outside the method, probably, but I really wanted the class to handle all of the network stuff. Anyway, it works fine now. Thanks for your explanation. -Patrick -- Real e-mail address is 'cHVAdm8ubHU=\n'.decode('base64') Visit my Homepage at http://www.homepages.lu/pu/ From electricity at uymail.com Wed Aug 27 03:42:49 2003 From: electricity at uymail.com (U. N. Owen) Date: Wed, 27 Aug 2003 09:42:49 +0200 Subject: [OT] Why is it called string? Message-ID: <20030827074249.18654.qmail@uymail.com> I don't know if this helps very much, but... In french we *almost always* use "octet" for 8bit bytes. Sometimes for 7bit. And for 4bit, we use "quartet", which is mostly seen in HP48 world. It concerns only software, since I don't know very well "hardware words". -- _______________________________________________ Get your free email from http://www.uymail.com Powered by Outblaze From max at alcyone.com Mon Aug 11 14:12:32 2003 From: max at alcyone.com (Erik Max Francis) Date: Mon, 11 Aug 2003 11:12:32 -0700 Subject: Fun with numbers - dammit, but I want a cast! References: <3f378fac$0$10778$afc38c87@auth.uk.news.easynet.net> <3f3792f2$0$18258$afc38c87@auth.uk.news.easynet.net> Message-ID: <3F37DC90.B9FA25BF@alcyone.com> Graham Nicholls wrote: > Thats what I wanted to do, but was sure I'd read that python didn't > have > casts, and that _looks_ like a cast to me! It's a function call, not a conversion. Even in C++, conversion by constructor is not considered a cast. A cast would be: xframe/static_cast(image_x) and there is no analogous structure to this in Python. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ Nobody can reach me, nobody can touch me; it's a wonderful feeling. \__/ Aaliyah From raw at raw.com Sat Aug 23 00:28:46 2003 From: raw at raw.com (Richard A. Wells) Date: Sat, 23 Aug 2003 00:28:46 -0400 (EDT) Subject: (no subject) Message-ID: <20030823042846.5A2BC1C4D24B@mail.raw.com> I'm on vacation until Tuesday, 2 September, 2003. I'll answer your message as soon after my return as I can. Cheers, Richard *** Richard A. Wells, raw at raw.com *** Reality And Wonder, http://www.raw.com/ From grante at visi.com Wed Aug 27 12:55:26 2003 From: grante at visi.com (Grant Edwards) Date: 27 Aug 2003 16:55:26 GMT Subject: Tkinter? References: Message-ID: <3f4ce27e$0$158$a1866201@newsreader.visi.com> In article , tjland at iserv.net wrote: > Does anyone know a really good tutorial into Tkinter because i > want to learn it. One that is more user friendly would be nice. If you want a book, I thought John Grayson's book was quite good. It also covers PMW (a set of higher-level widgets built on Tk). http://www.amazon.com/exec/obidos/tg/detail/-/1884777813?v=glance -- Grant Edwards grante Yow! QUIET!! I'm being at CREATIVE!! Is it GREAT visi.com yet? It's s'posed to SMOKEY THE BEAR... From bokr at oz.net Thu Aug 14 11:51:52 2003 From: bokr at oz.net (Bengt Richter) Date: 14 Aug 2003 15:51:52 GMT Subject: random value generation References: Message-ID: On Tue, 12 Aug 2003 11:57:28 -0700 (PDT), Brandon Michael Moore wrote: >I'm trying to test a web application using a tool written in python. I >would like to be able to generate random values to put in fields. I would >like to be able to generate random dates (in a specified range), random >strings (specifying allowed characters and a distribution of lengths), or >choose randomly between several generators (for better control of the >distribution of values). > >Is there any library for this sort of thing in Python? I've started a >library heavily based off the generators of Haskell's QuickCheck library, >that represents generators as objects with a generate() method, with >constructor parameters (maybe other generators) the control the resulting >distribution. > >I've got Choose that takes a list of generators and chooses between them >(with random.choice), GMap that maps a function over the output of another >generator, Choice that chooses an element from a list, Expo that wraps >random's expovariate, and List that takes a number generator and an >element generator and generates lists with lengths drawn from the first >generator and elements drawn from the second, and String that's like List >but joins the resulting list with ''. > >I can use these classes like Choice(['red','blue','green']), or >String(Expo(1.0/3),Choice(string.lower)). > >Are there any existing libraries for this sort of thing? Or at least, can >anyone suggest a cleaner way of doing this? (I don't like creating classes >for things that should really be functions, but I need to call the random >number generator each time I use the generator, not once when I define it) > >Brandon > Have you looked at the time and random modules? E.g., >>> import time, random >>> time.localtime() (2003, 8, 14, 8, 45, 13, 3, 226, 1) >>> midday = time.mktime((2003,8,14,12,0,0,0,0,1)) >>> time.ctime(midday) 'Thu Aug 14 12:00:00 2003' >>> time.strftime >>> time.strftime.__doc__ 'strftime(format[, tuple]) -> string\n\nConvert a time tuple to a string according to a format s pecification.\nSee the library reference manual for formatting codes. When the time tuple\nis no t present, current time as returned by localtime() is used.' >>> time.strftime('%Y%m%d %H%M%S',time.localtime(midday)) '20030814 120000' >>> time.strftime('%y%m%d %H%M%S',time.localtime(midday)) '030814 120000' Set some seed to have a way to restart the same sequence if desired >>> random.seed(1234) Vary times uniformly forawrd 24 hours from midday >>> for i in xrange(10): print time.strftime('<%Y-%m-%d %H%M%S>', time.localtime(midday+random.r andom()*3600*24)) ... <2003-08-15 111141> <2003-08-14 223439> <2003-08-14 121047> <2003-08-15 095148> <2003-08-15 103232> <2003-08-15 015824> <2003-08-15 040703> <2003-08-14 140052> <2003-08-15 062343> <2003-08-14 174100> or vary uniformly forward one hour from midday: >>> for i in xrange(10): print time.strftime('<%Y-%m-%d %H%M%S>', time.localtime(midday+random.r andom()*3600)) ... <2003-08-14 120150> <2003-08-14 124719> <2003-08-14 122045> <2003-08-14 123723> <2003-08-14 123656> <2003-08-14 120854> <2003-08-14 121059> <2003-08-14 120651> <2003-08-14 120052> <2003-08-14 122912> of course you can use other distributions and time formats too. This was just a quick demo. Generating and/or selecting random strings seems not too challenging, unless you have some tricky requirements. Regards, Bengt Richter From garabik-news-2002-02 at kassiopeia.juls.savba.sk Wed Aug 13 03:24:42 2003 From: garabik-news-2002-02 at kassiopeia.juls.savba.sk (Radovan Garabik) Date: 13 Aug 2003 07:24:42 GMT Subject: Py2.3: Feedback on Sets References: Message-ID: Raymond Hettinger wrote: > I've gotten lots of feedback on the itertools module > but have not heard a peep about the new sets module. > > * Are you overjoyed/outraged by the choice of | and & > as set operators (instead of + and *)? I would prefer to have + in addition to |. I do not care about *, but IMHO + is so intuitive and natural that it is a pity not to have it (you can add lists, tuples, strings with +, but not sets???) > > * Is the support for sets of sets necessary for your work > and, if so, then is the implementation sufficiently > powerful? So far my code used dictionaries with values set to None, I expect that I will use sets soon, it will be more logical and the code more readable. > > * Are sets helpful in your daily work or does the need arise > only rarely? daily work, production code, but so far I used lists or dictionaries instead. I am somewhat afraid of performance, until setrs are implemented in C, though -- ----------------------------------------------------------- | Radovan Garab?k http://melkor.dnp.fmph.uniba.sk/~garabik/ | | __..--^^^--..__ garabik @ kassiopeia.juls.savba.sk | ----------------------------------------------------------- Antivirus alert: file .signature infected by signature virus. Hi! I'm a signature virus! Copy me into your signature file to help me spread! From belred1 at yahoo.com Sun Aug 24 16:32:59 2003 From: belred1 at yahoo.com (Bryan) Date: Sun, 24 Aug 2003 20:32:59 GMT Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> <3F41505F.69D18CC8@alcyone.com> Message-ID: <%h92b.247100$Ho3.31983@sccrnsc03> > Using Python at all we are trading cpu cycles for higher level > abstractions and better programmer productivity. Why not add Macro's > allowing those of us who know how to use them and like them to use > them. If you hate macros, or you think they are too slow, just don't > use them. They don't change the underlying language, they just add a > more useful abstaction capability into the language. > > > Doug Tolton > (format t "~a@~a~a.~a" "dtolton" "ya" "hoo" "com") but, if someone on my team adds macros to our project, does that mean i'm now forced to learn a macro language? also, can someone please post a fictituos example of what a macro language might look like and do for me in python? i don't understand what he benefit would be. thanks, bryan From antaie_m at libero.it Thu Aug 14 20:37:30 2003 From: antaie_m at libero.it (Antonio Aiello) Date: 15 Aug 2003 02:37:30 +0200 Subject: Contents of python-list digest Message-ID: <1060907850.1895.1.camel@localhost> From logiplex at qwest.net Tue Aug 12 13:58:07 2003 From: logiplex at qwest.net (Cliff Wells) Date: Tue, 12 Aug 2003 10:58:07 -0700 Subject: Python vs. C# In-Reply-To: References: <2259b0e2.0308100616.55b651ca@posting.google.com> <3f36af20@shknews01> <2259b0e2.0308110433.204d7831@posting.google.com> Message-ID: <1060711087.2221.4196.camel@software1.logiplex.internal> On Mon, 2003-08-11 at 14:59, Brandon J. Van Every wrote: > Michele Simionato wrote: > > "Brandon J. Van Every" wrote in message > > news:<3f36af20 at shknews01>... > >> I'm beginning to think that within 5 years, no new applications will > >> be > >> written in C++. > > > > ?? Are you joking or what ?? Did you learn anything from Fortran > > lesson? Or from Lisp? Programming languages *never* die! > > Ok, "no" new applications may be a bit strong. There will always be > hobbyists and cranks. And which group do you fall under? > 20% of the world is real. > 80% is gobbledygook we make up inside our own heads. Living up to your sig'ly yrs, -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 (800) 735-0555 From usenet_spam at janc.invalid Sat Aug 30 21:26:52 2003 From: usenet_spam at janc.invalid (JanC) Date: Sun, 31 Aug 2003 01:26:52 GMT Subject: Celebrity advice (was: Advice to a Junior in High School?) References: <2259b0e2.0308272331.55028ae5@posting.google.com> Message-ID: Gerrit Holl schreef: > Of course, this is only true if the other oppinions are based on > points (can't find the English word for "gefundeerd"... founded?) Yes, "founded" or "well-founded" (vs. "ill-founded") > In the Dutch politics newsgroup nl.politiek, a lot of opinions are > available which aren't mine, but less than 5% of them has any points. Sounds like be.politics then, but IIRC 95% of the messages in those two groups are cross-posts anyway... ;-) -- JanC "Be strict when sending and tolerant when receiving." RFC 1958 - Architectural Principles of the Internet - section 3.9 From mhammond at skippinet.com.au Fri Aug 1 21:40:31 2003 From: mhammond at skippinet.com.au (Mark Hammond) Date: Sat, 02 Aug 2003 11:40:31 +1000 Subject: PB with Python ActiveX Scripting Engine registration (Python 2.2.3/2.3) In-Reply-To: References: Message-ID: GE wrote: > I execute the Python program win32com\axscript\client\pyscript_rexec.py and > the engine is successfully registered But the python engine isn't active in > IE (tested with demo.htm, even after a reboot) > I did not have probleme with Python 2.1 and win32all-151 > > The path of win32com have changed ( now in python 2.2 we have the directory > "site-packages" in more) is-it a way??? > Try resistering with "--debug", then open the "Trace Collector Debugging Tool" from Pythonwin. Mark. From timr at probo.com Fri Aug 8 00:06:18 2003 From: timr at probo.com (Tim Roberts) Date: Thu, 07 Aug 2003 21:06:18 -0700 Subject: round(22.47,2) gives 22.469999999999999? References: <3f30e294$0$125$e4fe514c@dreader5.news.xs4all.nl> Message-ID: Daniel Klein wrote: >Eric van Riet Paap wrote: > >>On python2.1.3, python2.2.1 and python2.2.3 round(22.47,2) gives >>22.469999999999999 . Does anyone know if this is a bug or some weird, yet >>unexpected, behaviour? > >Wouldn't > >int(22.47 + .5) > >get you to where you want to go? No, you didn't read the assignment. :) round(22.47,2) gives roughly 22.47. int(22.47+.5) gives 22. VERY different numbers. -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From bignose-hates-spam at and-benfinney-does-too.id.au Tue Aug 19 00:45:54 2003 From: bignose-hates-spam at and-benfinney-does-too.id.au (Ben Finney) Date: 19 Aug 2003 14:35:54 +0950 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: <3F41A877.995F9C35@alcyone.com> Message-ID: On Mon, 18 Aug 2003 21:32:55 -0700, Erik Max Francis wrote: > "Brandon J. Van Every" wrote: >> Erik, every time you have ever been "responded to," it's been an >> indirect quote. > > Brandon (gotta love that; direct address to someone he's "killfiled"), In this instance, as in all others, Brandon responded to your comment as seen in someone else's post. > adults use killfiles so that they don't have to see posts they've > decided, for whatever reason, that they wish not to read anymore. If > you really wanted to killfile me to avoid reading my posts, you'd > adjust your killfile to toss emails that were in response to me, or at > least show the self-restraint not to read -- and respond! -- to them. Brandon accesses comp.lang.python via Usenet, not email. His X-Newsreader header shows he is using Outlook Express. I don't know of any newsreaders that can allow you to filter on the person(s) to whom the current post is responding -- nor any email clients with the facility, for that matter. The "References" header could theoretically allow you get that information, but it would be expensive to do so for every message, especially in long-running threads. Seeing second-hand comments (as quoted by others) from people in one's killfile is a hazard of Usenet. -- \ "Truth: Something somehow discreditable to someone." -- Henry | `\ L. Mencken | _o__) | Ben Finney From aahz at pythoncraft.com Thu Aug 7 13:47:23 2003 From: aahz at pythoncraft.com (Aahz) Date: 7 Aug 2003 13:47:23 -0400 Subject: Static class properties (read-only) References: Message-ID: In article , Greg Brunet wrote: > >In puzzling over classes, I'm wondering if classes can have read-only >static properties? I certainly seem to be able to do create static >properties like this: > >class C(object): > count = 0 > > def __init__(self,s): > C.count += 1 > self.Name = s > > def __del__(self): > C.count -= 1 > >and C.count should have a count of the number of its instances that have >been created. However, someone could set the value directly. I know >that using get/set methods, I can make a read-only property at the >object/instance level. Can this be done at the class level? Thanks, Nope. Gotta do a metaclass. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From ialbert at mailblocks.com Fri Aug 29 18:58:47 2003 From: ialbert at mailblocks.com (Istvan Albert) Date: Fri, 29 Aug 2003 18:58:47 -0400 Subject: Need good example database schema In-Reply-To: References: Message-ID: Mark Carter wrote: > I found a link: > http://www.geocities.com/tablizer/oopbad.htm > (and there are others) who suggest that object-oriented databases > aren't a good idea. Tabular databases (and in fact a tabular design Actually what the link above suggests is that OOP is evil in general. The brief discourse on OOP not being appropriate for data modeling is just a tiny part of it. To sum it up for those that do not want to read it: OOP = Communism Istvan. From richard.mertens at wolfi.org Tue Aug 12 08:34:58 2003 From: richard.mertens at wolfi.org (Richard Mertens) Date: 12 Aug 2003 12:34:58 GMT Subject: get line number Message-ID: How do get the actual line number from the actual running sourcecode. I need it for debugging purpose From newsgroups at jhrothjr.com Sat Aug 2 18:56:25 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Sat, 2 Aug 2003 18:56:25 -0400 Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> <87el06d2i6.fsf@pobox.com> <8Z-cnS25-8ywsLGiXTWJiQ@comcast.com> Message-ID: "Terry Reedy" wrote in message news:8Z-cnS25-8ywsLGiXTWJiQ at comcast.com... > > "Andy C" wrote in message > news:y3VWa.261$_p6.23775419 at newssvr21.news.prodigy.com... > > What's bad about tabs? > > Because there is no 'official' meanings, despite claims to the > contrary, some software like Outlook Express ignores them on receipt. > > tjr You can always blame that on Micro$haft. However, it does make e-mailing a program indented with tabs something of an adventure. John Roth > > > From vanevery at 3DProgrammer.com Mon Aug 11 21:43:08 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Mon, 11 Aug 2003 18:43:08 -0700 Subject: Python should try to displace Java Message-ID: I'm going to make a number of points which I'm sure many people will object to. Feel free, but also try not to knee-jerk about them. As someone who programmed DEC Alpha in 1998, and who sees the sorry state of CPUs nowadays, I can definitely say that better technology doesn't always win. In fact, it doesn't *usually* win. Python needs to look to its strategic marketing and product positioning if it expects to survive in the rough and tumble world of mainstream industry. Points to note: - in 5 years, nobody will be doing significant amounts of new application development in C++. The writing is on the wall: garbage collection is essential. Any C++ code will be support and legacy libraries. - Microsoft is already implementing said strategy across all levels of the company today. Microsoft developers don't do much C++ development anymore. Various upcoming products are being written entirely in C#. - The "higher level language" playing field is crowded: C#, Java, Perl, and Python. Mainstream industry does not need and will not make room for 4 higher level languages. Any of these languages has to grow at some other language's expense. - Python will never displace C# on Windows. It's Microsoft's home turf and you can't fight directly with The Beast. You will see UNIX boxes running Python, not Windows boxes. - Sun is about to die. It has done nothing for anyone lately and has no further tricks up its sleeve. - Sun has failed to make Java live up to its claims of universality. Java is for all intents and purposes simply a widespread programming language, not a portable computing environment. Portable computing environments are, in general, a pipe dream as long as Microsoft is around. It will always be Windows vs. open standards. - Java is proprietary. Python is open source. Open Source is the best shot that anyone has at competing with Windows. - Perl is open source and sysadmins won't be giving it up any time soon. Perl is optimal for their jobs, the capabilities of Python are a non-sell. - Ergo, Java is the weakling of the litter for Python to attack. - Alternately, if you look at this in real world marketing terms, Python is the weakling of the litter that must defend itself. I know that will make various Python idealists upset, but that's the economic reality. Merit doesn't win in this game. Java is the next weakest langauge so that's whose lunch Python should try to eat. - No, this isn't the appraisal of a Microsoftie who wants to set Python and Java at each others' throats to conquer both. :-) I'm just offering a realistic picture of what your options are, if you don't want to become a "gee whiz, wasn't that nice!" technology. Like I said, I've lived through it already. Don't talk to me about merit carrying the day. Learn from history, or you are doomed to repeat it. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From news at exultants.org Sun Aug 24 10:14:06 2003 From: news at exultants.org (Van Gale) Date: Sun, 24 Aug 2003 14:14:06 GMT Subject: ANN: BlackAdder V1.0.0 References: <3f48a498$3$219$fa0fcedb@lovejoy.zen.co.uk> Message-ID: On Sun, 24 Aug 2003 11:44:31 +0000, BadJake wrote: > Key Features > ... > A GUI designer with all the features of Qt Designer and generates Python > code. Does this mean the BlackAdder GUI designer can now design other types interfaces than dialog boxes? Or is Qt Designer + pygui (err.. I forget the program name exactly) are still required for that? Van Gale From vanevery at 3DProgrammer.com Tue Aug 12 00:51:29 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Mon, 11 Aug 2003 21:51:29 -0700 Subject: Python should try to displace Java References: Message-ID: Istvan Albert wrote: > still trolling eh, > > but you try too hard and it shows, I asked you not to knee-jerk on what I wrote, but you couldn't do it. So welcome to my killfile. I didn't expect emotional idealists to handle it, that's why they're emotional idealists. Pragmatic engineers can get on with whether the strategic analysis has merit or not. I don't know what your corporate culture is, sitting in newsgroups plotting the future of a nice open source langauge. Maybe you think the whole world runs on volunteerism and good vibes. But in the big iron corporate background I come from, people sit down and have powwows about what the strategic threats are. You can deny the existence of strategic threats all you like, and stay in a comfortable universe of engineering merit. That will last until... commercial reality washes over you and your career like a tidal wave. Do you want to be earning good money on your Python knowledge 10 years from now? Then pay attention. I guarantee you that Microsoft has powwows about C#, Java, and Python. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From google at hanger.snowbird.net Thu Aug 21 01:09:21 2003 From: google at hanger.snowbird.net (Kris Caselden) Date: 20 Aug 2003 22:09:21 -0700 Subject: Weird Problem Message-ID: I'm sure this is a simple newbie problem, but I can't figure it out for the life of me. The code: import sys, os input = open("example.py","r") Gives me the error: TypeError: an integer is required Am I missing something? This is straight out of documentation and tutorials. What could be wrong? I'm using Python 2.3. I'm still new to Python, and even though it's a simple language, I encounter seemingly nonsensical problems like these almost every time I try to do something. Is this kind of behavior normal for Python or is there some process I'm not following? -Chris- From cartermark46 at ukmail.com Thu Aug 7 07:41:26 2003 From: cartermark46 at ukmail.com (Mark Carter) Date: 7 Aug 2003 04:41:26 -0700 Subject: Python/Excel VBComponents crash Message-ID: I use Office 2000, and I have recently upgraded to python 2.3 and win32all-155.exe The following code worked in python 2.2: xlApp = Dispatch("Excel.Application") xlApp.Visible = 1 xlApp.Workbooks.Add() xlApp.ActiveWorkbook.SaveAs(sys.path[0] + '\\temp.xls') wb = xlApp.Workbooks("temp.xls") wbc = wb.VBProject.VBComponents # <---- CAUSES CRASH IN 2.3 xlApp.Quit() del xlApp but I get a GPE in 2.3, when the code finishes execution: EXCEL caused an invalid page fault in module OLE32.DLL at 0167:65f18ae3. If you comment out the line wbc = ... then I get no GPE. Any ideas? From sismex01 at hebmex.com Tue Aug 26 09:42:50 2003 From: sismex01 at hebmex.com (sismex01 at hebmex.com) Date: Tue, 26 Aug 2003 08:42:50 -0500 Subject: python gripes survey Message-ID: [Gustavo Cordova] > > Generators yielding to other generators, to form a > > quasi-cooperative-multitasking environ seems quite > > powerful to me. [Ryan Lowe] > not that i have any clue what you just said, but is this > possible in python? > or only in code-block languages? Nope, it's quite possible, and not too complicated to do (but comprehend) in Python. You just need a bunch of routines which need to run in an "interleaved" fashion. You put "yield" statements where you intend to pause execution of each routine, the secret is in which value you yield. One approach is to put all obtained generators into a list, and simply iterate through it repeatedly, taking each one and calling it's .next() You can use a sentinel value to signal that you should take this generator off the list. The loop would look something like: while 1: for I in GeneratorsList: I.next() The next approach is to yield in each iterator the reference to the next subroutine to be called. This is especially neat in state machines, because each state *knows* which other state follows given a certain condition. So, you replace the generator-list-iteration loop given above for something like below: state = InitialStateGenerator while state: state = state.next() and this will loop until a certain state returns a false value. Neat. The final approach is for a generator to yield TO the final state; in this case you don't yield a reference to the next generator, but you directly call it's .next() method, which directly continues it's execution, etc. So, the loop actually disappears and becomes state = InitialStateGenerator state.next() and by the time it returns, it's done. :-) NEAT. -gustavo Advertencia:La informacion contenida en este mensaje es confidencial y restringida, por lo tanto esta destinada unicamente para el uso de la persona arriba indicada, se le notifica que esta prohibida la difusion de este mensaje. Si ha recibido este mensaje por error, o si hay problemas en la transmision, favor de comunicarse con el remitente. Gracias. From mis6 at pitt.edu Mon Aug 11 09:17:35 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 11 Aug 2003 06:17:35 -0700 Subject: CLI+GUI References: <2259b0e2.0308080948.5a95e383@posting.google.com> <2259b0e2.0308090530.7519f195@posting.google.com> Message-ID: <2259b0e2.0308110517.7c4fa8c8@posting.google.com> Eric Brunel wrote in message news:... > I don't know if this is the problem, because you didn't say exactly when the > script hangs, but Tkinter apparently has problems when calls to it are made > from a thread different from the one into which it was initialized. I'd use > an Event between Tkinter's thread and Cmd's thread, checking it regularly > with Tkinter's after method. > > HTH It hangs immediately when I start the script by clicking on its icon. What do you mean with "I'd use an Event" ? I thought an Event object is automatically generated when I click on a widget, or press a key, or something. Are you saying can I can programmatically generate an Event, faking a real mouse/key press? How so? That is something I always wanted to know ;) Michele From andrew.gregory at npl.co.uk Fri Aug 1 04:48:58 2003 From: andrew.gregory at npl.co.uk (Andrew Gregory) Date: 1 Aug 2003 01:48:58 -0700 Subject: Tkinter programming problem Message-ID: <2830c89c.0308010048.403a2a19@posting.google.com> Could someone help me out with these few lines of code: I would like to know why the Quit button in this application removes the buttons and causes "Quitting" to be printed, but does not close the outer frame. Andrew. # Demonstration TK interface Windows application # Runs ok from within IDLE # from Tkinter import * class CommonStuff: # to get common access to variables and functions def __init__(cself, frame): cself.frame = frame def say_hi(cself): print "Hello all" class MyWidgets(Frame, CommonStuff): def __init__(wself, CS): Frame.__init__(wself, CS.frame) wself.quitbutton = Button(wself) wself.quitbutton["text"] = "Quit" wself.quitbutton["fg"] = "red" wself.quitbutton["command"] = wself.destroy wself.quitbutton.pack({"side": "left"}) wself.hi_there = Button(wself) wself.hi_there["text"] = "Hello", wself.hi_there["command"] = CS.say_hi wself.hi_there.pack({"side": "left"}) class Application: def __init__(self, master): self.frame=Frame(master) CS = CommonStuff(self.frame) displayedwidget=MyWidgets(CS) displayedwidget.grid(row=0, column=0) self.frame.grid(row=0, column=0) self.frame.columnconfigure(0) displayedwidget.bind("", self.quit) self.frame.update() def quit(self, event): print"Quitting..." self.frame.destroy # Destroy frame and all children root = Tk() mainWin = Application(root) root.wait_window(mainWin.frame) From andrew_ellem at hotmail.com Sun Aug 24 23:38:49 2003 From: andrew_ellem at hotmail.com (Andrew Ellem) Date: Sun, 24 Aug 2003 23:38:49 -0400 Subject: Fatal Python error with Py_InitModule (Python 2.3) Message-ID: I'm using Python embedded in my app, and I've run into problems creating my own modules. I'm using Python version 2.3 compiled with MSVC .NET (not 2003). When I call Py_InitModule I get the message: "Fatal Python error: Interpreter not initialized (version mismatch?)" However, Python does seem to be initialized. Py_IsInitialized() returns 1, and I can PyImport_Import() and I can run scripts successfully from my program. I'm not sure what I could be doing wrong, all the information I've found online indicates that the above message comes from incompatible version (not using a debug version, etc), but I don't see how that would be the problem in my case, since I can run normal scripts. Does anyone have an idea what might be the problem? Thanks. _________________________________________________________________ Protect your PC - get McAfee.com VirusScan Online http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963 From irmen at -NOSPAM-REMOVETHIS-xs4all.nl Tue Aug 5 05:42:12 2003 From: irmen at -NOSPAM-REMOVETHIS-xs4all.nl (Irmen de Jong) Date: Tue, 05 Aug 2003 11:42:12 +0200 Subject: ANN: Snakelets 1.1 (simple-to-use web app server with dynamic pages) In-Reply-To: References: <3f2ea0a0$0$49110$e4fe514c@news.xs4all.nl> Message-ID: <3f2f7bf4$0$49103$e4fe514c@news.xs4all.nl> Karl Scalet wrote: > is there any support for cgi built into? No, I especially designed Snakelets away from CGI: it is inspired by Java's model of code-based request handlers or HTML-based page templates (with Python code embedded). No such thing as CGI scripts. Perhaps you could be a bit more specific what you want to do? If you want to use Ypages (for instance) as CGI scripts, please don't...: there are much better things out there (Spyce springs to mind) that *do* have CGI support. --Irmen PS then again, the HTTP form POSTs are parsed by Python's standard cgi module :-) From jarrodhroberson at yahoo.com Tue Aug 12 14:06:58 2003 From: jarrodhroberson at yahoo.com (Y2KYZFR1) Date: 12 Aug 2003 11:06:58 -0700 Subject: Python vs. C# References: <3f357a9b@shknews01> Message-ID: "Brandon J. Van Every" wrote in message news:<3f357a9b at shknews01>... snip >... C# could be glossed as "C++ without the headaches." Actually nothing could be farther from the truth, if you really think this you don't understand anything about C++! Just because the SYNTAX is SIMILAR does not make the IMPLEMENTATION simlar! > I've just spent most of the last 11 years avoiding them, > that's how I've gotten by. well guess that qualifies why you have the above misconception! > Also C#, like Python, has higher level data > types built right in. No more memory management, no more implementing > linked lists over and over again .NET Framework could be glossed as "an > interoperability environment for programming languages." So long as your > language looks a lot like C#. ;-) Actually this is completely wrong also, C# works much like VB "objects" are COM objects. Nothing fancy at the langauge level there. .Net Framework is Windows specific runtime environment that is very similar to the Java standard libraries, nothing more nothing less. > Some open source projects are trying to clone .NET and provide a C# > compiler. again with the misconseptions, not a compiler but a runtime interpreter. From pythonguy at Hotpop.com Fri Aug 22 02:50:27 2003 From: pythonguy at Hotpop.com (Anand Pillai) Date: 21 Aug 2003 23:50:27 -0700 Subject: ClientCookie bug (followup) References: <87oeypdh92.fsf@pobox.com> <87k79a25pi.fsf@pobox.com> <84fc4588.0308182207.4c649b93@posting.google.com> <87ada5de3j.fsf@pobox.com> <84fc4588.0308200242.3e74e0a1@posting.google.com> <87smnwh3lp.fsf@pobox.com> <87wud6ejtw.fsf@pobox.com> Message-ID: <84fc4588.0308212250.52085da1@posting.google.com> Does it mean that all coders have split personalities? ;-) -Anand jjl at pobox.com (John J. Lee) wrote in message news:<87wud6ejtw.fsf at pobox.com>... > Robin Munn writes: > > > John J. Lee wrote: > [...] > > > lack thereof -- it's just that the convention of using 'we' in source > > > code comments is common enough that I've sometimes found myself using > > > it even when writing code alone, which is funny.) > > > > I do that all the time; "we" is the default in my code comments and I > > have rarely, I think never, used "I". I usually think of it as myself > > reading through the code with another coder, who is tasked with taking > > over code maintenance from me. I'm explaining to him what the code is > > intended to do: "So here, we want to search through the list for..." > > That's a good excuse. :-) > > > John From caw at cs.mu.oz.au Fri Aug 8 07:05:55 2003 From: caw at cs.mu.oz.au (Chris Wright) Date: 8 Aug 2003 04:05:55 -0700 Subject: generating byte code from compiler.parse output References: Message-ID: After Martin's gentle prodding, I came up with the code below (without error checking etc....) I am very grateful ! cheers Chris ------------------ from compiler import parse, syntax from misc import set_filename from pycodegen import ModuleCodeGenerator class Test: def __init__(self): pass def munge_code_string(s): m = parse(s) set_filename("", m) syntax.check(m) print m gen = ModuleCodeGenerator(m) c = gen.getCode() return c code_string = """ def f(x): print x """ if __name__ == '__main__': t = Test() code = munge_code_string(code_string) exec code in globals(), t.__dict__ print dir(t) t.f(4) martin at v.loewis.de (Martin v. L?wis) wrote in message news:... > caw at cs.mu.oz.au (Chris Wright) writes: > > > Is there a way to go from the AST output of compiler.paser to byte > > code > > Yes. Use the source, Luke. > > > i.e. in the example below, is there a way to compile m and get a code > > object that could then be called? > > You have to find out what compiler.compile is doing in addition to > what you are doing. Then, you find, that you need misc.set_filename, > syntax.check, ModuleCodeGenerator, and .getCode, in that order. > > HTH, > Martin From skip at pobox.com Sun Aug 3 22:08:38 2003 From: skip at pobox.com (Skip Montanaro) Date: Sun, 3 Aug 2003 21:08:38 -0500 Subject: memory leak? In-Reply-To: <60FB8BB7F0EFC7409B75EEEC13E2019202CE481A@admin56.narex.com> References: <60FB8BB7F0EFC7409B75EEEC13E2019202CE481A@admin56.narex.com> Message-ID: <16173.49190.116602.289119@montanaro.dyndns.org> Bjorn> In any case, you should probably file a bugreport at sourceforge, Bjorn> http://sourceforge.net/tracker/?atid=105470&group_id=5470&func=browse, Not necessary in this case as Tim Peters already did. Neal Norwitz confirmed the bug and suggested a simple fix. I expect it will be closed Monday. Backporting isn't necessary, since it was introduced during some code reorganization since 2.2 was released. Bjorn> I forget if you have to register to file a new bug.. Anonymous reporting is not allowed. Too often submitters could not be reached to provide more information about incomplete bug reports. Skip From max at alcyone.com Wed Aug 27 22:06:37 2003 From: max at alcyone.com (Erik Max Francis) Date: Wed, 27 Aug 2003 19:06:37 -0700 Subject: Style question... References: <4cd3b.50331$la.863381@news1.calgary.shaw.ca> Message-ID: <3F4D63AD.FBBFCCFB@alcyone.com> Anthony Roberts wrote: > There is, but it can't tell if I want some stuff indented or not. Sure it can. Hit tab or backspace. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ Nobody's on nobody's side \__/ Florence, _Chess_ From kp at kyborg.dk Tue Aug 12 10:39:55 2003 From: kp at kyborg.dk (Kim Petersen) Date: Tue, 12 Aug 2003 16:39:55 +0200 Subject: Python should try to displace Java In-Reply-To: References: Message-ID: <3f38fc40$0$13195$edfadb0f@dread15.news.tele.dk> Brandon J. Van Every wrote: > Doug Tolton wrote: > >>On Mon, 11 Aug 2003 18:43:08 -0700, "Brandon J. Van Every" >> >>>- in 5 years, nobody will be doing significant amounts of new >>>application development in C++. The writing is on the wall: garbage >>>collection is essential. Any C++ code will be support and legacy >>>libraries. >> >>That's a ridiculous blanket statement. People will be doing C++ >>development for a long time beyond that. There are people still >>writing Cobol for crying out loud. > > > Do you honestly believe that people are doing a significant amount of new > application development in Cobol, as opposed to maintenance work? You can bet your life on it. When you have a *very* large portfolio of Cobol programs (and a lot of companies have) - then you know that you cannot change to another programming language - without setting back the development years - you might try and run a seperate developing line (we do here) to catch up with the Cobol line (in several years). > > >>>- Microsoft is already implementing said strategy across all levels >>>of the company today. Microsoft developers don't do much C++ >>>development anymore. Various upcoming products are being written >>>entirely in C#. >> >> just what we need. More buggy slow products from MS that have >>Memory Leaks the size of the Mississippi. C# is not a good >>development platform yet. Heck they are practically still in the >>standard MS beta period. Everyone knows not to use a MS product on >>version 1.0 > > > Ignore the trend at your peril. A MS product is one thing. A MS initiative > across the entire company is quite another. The last time they did that, > Internet Explorer put Netscape in the doghouse. Never, ever, ignore or > diminish what Microsoft decides to do as an entire company. There is a large difference between a product (IE) and a programming language. All this reminds me of the hype first C++ and then Java got - none of those are today all pervasive. (if your line of thought is correct - then we *all* would be programming either VC++ or VB). >>>- Python will never displace C# on Windows. It's Microsoft's home >>>turf and you can't fight directly with The Beast. You will see UNIX >>>boxes running Python, not Windows boxes. >> >>That's a bold statement, considering the abysmal adoption rate of C#. > > > Within Microsoft, the adoption of C# is universal. That tends to have a > powerful effect on ISV Windows development over time. As far as i've read up on .NET/C# - the language doesn't matter - whats to stop ppl continuing the programming language they've always used? (eg. Cobol (which exists in several versions in .NET). > > >>C# isn't the dominant windows programming language currently, rather >>its Visual Basic. Java has far more applications written for Windows >>than C# does. MS really shot themselves in the foot when they went to >>dotnet, essentially the adopted the Java platform 8 years after Java. >>Now they are playing catchup with an inferior product. I doubt >>they'll ever catch up to Java overall. > > > The problem with your thinking here is there's very clear evidence that > Microsoft can and does catch up to and surpass technologies that they have > fumblingly cloned. In fact, that's the basic Microsoft corporate > philosophy. Version 1.0 sucks, 2.0 is ok... 5.0 actually is a really good > product and then the competition can't catch up anymore. Example: DirectX. > When it started it was complete garbage. Nowadays it is technically > superior to OpenGL in most areas. Why they don't finally implement doubles > and put OpenGL out of its misery, I'm not sure. sorry - won't comment on above - its so damned platformcentric that it entirely misses whatever point you may have been trying to put over. > > Why can MS catch up? Because Open Source people assume their technological > superiority and rest on their laurels. They think they don't have to market > because they are technically superior. Also, their ranks are populated with > strong engineers who don't *like* marketing, as a matter of basic > personality. They never get it in their heads that they have to > counter-market to some degree in order to hold the line. If you don't do > any marketing, Microsoft completely out-markets you and then you die, > technical merit or not. > Assume for a moment that Linux takes off on the desktop (as indications could be read) - where is your argument? > >>>- Sun is about to die. It has done nothing for anyone lately and >>>has no further tricks up its sleeve. >> >>People have been saying this for years. I'll believe it when I see it. > > > Read a paper. Which ones ? Sun-pro, Sun-Neutral or Sun-contra's? As another example - Unix has been pronounced dead since the late-80's - as far as i can see, it seems to live better than ever (in Linux/BSD etc.) - and that was in all the papers as well... All the papers have also been stating that MS is dominant on the server platform (all during the 90's) - slowly the picture is revealed, that they _never_ had any dominance in this marked - and that they are at the moment even failing to hold on to the marked they have.... > You got it! And development stops when a langauge loses all meaningful > mindshare. What is the battle of mindshare? A marketing battle. It is not > a technological battle, except in the grossest terms of complete > incompetence. Time and again, the marketplace has proven that kludgy but > well marketed products carry the day. They only fail when they absolutely > can't do the job. Again Fortran is very much alive - Cobol, Lisp and loads others are also very much alive - and when is the last time you've seen marketing for those? > >>If that hapens it will be because something *significantly* better came > > along. > > No, it is not an engineering meritocracy. Look at a company like DEC. > Wonderful technology company. Couldn't market its way out of a paper bag. > That's a warning for this c.l.p crowd. Don't sit around congratulating > yourselves on how superior your techology is. Recognize the strategic > competition and market against it You seem to have failed in the understanding of the OpenSource movement ... Read up on the *why's* of its success - and you will find that it has naught to do with marketing. > >>Historically >>those with the best technology and the best economic system prevail >>against inefficient and inferior models. > > > You have *got* to be kidding me. Intel??!? Windows??!? > intel => economics made it win windows => intel economics made it win (in the 90's) -- Med Venlig Hilsen / Regards Kim Petersen - Kyborg A/S (Udvikling) IT - Innovationshuset Havneparken 2 7100 Vejle Tlf. +4576408183 || Fax. +4576408188 From detlev at die-offenbachs.de Tue Aug 19 13:07:26 2003 From: detlev at die-offenbachs.de (Detlev Offenbach) Date: Tue, 19 Aug 2003 19:07:26 +0200 Subject: GUI IDE for Macintosh? References: Message-ID: <632a11-ks2.ln1@stargate.solsys.priv> Leo wrote: > hi there > > i'm looking for a GUI Building IDE for Python Development running on a > mac under OS X. > > i know about eric (http://www.die-offenbachs.de/detlev/eric3.html) and > boa (http://boa-constructor.sourceforge.net/). in > > their install readme's si only linux and windows listed. does anybody > has experience with a GUI Building Tool on OS X? > > thanks for any advice, > > leo I think in the meantime Trolltech has released Qt for Mac OS X. This means that you should be able to compile sip, PyQt and QScintilla (???). If this works ok, eric is no problem anymore because it is pure Python and PyQt. Detlev -- Detlev Offenbach detlev at die-offenbachs.de From oinkfreddie at oinkshlick.oinknet Sun Aug 17 23:06:16 2003 From: oinkfreddie at oinkshlick.oinknet (Freddie) Date: 18 Aug 2003 13:06:16 +1000 Subject: hex(-5) => Futurewarning: ugh, can't we have a better hex than '-'[:n<0]+hex(abs(n)) ?? References: Message-ID: "Michael Peuser" wrote in news:bhot6f$65j$07$1 at news.t- online.com: > > "Bengt Richter" schrieb im Newsbeitrag > news:bhomem$jg8$0 at 216.39.172.122... >> >>> hex(-5) >> __main__:1: FutureWarning: hex()/oct() of negative int will return a > signed string in Python 2.4 and up '0xfffffffb' > > [...] > > There is a thread from this morning ("bitwise not ...") - this should be an > excellent contribution! > I have no mercy with someone writing hex(-5) > > Kindly > Michael P > > What about crazy people like myself? If you generate a crc32 value with zib, you occasionally get a negative number returned. If you try to convert that to hex (to test against a stored CRC32 value), it spits out a FutureWarning at me. So you end up with silly things like this in your code: # Disable FutureWarning, since it whinges about us making bad hex values :( import warnings try: warnings.filterwarnings(action='ignore', category=FutureWarning) except NameError: del warnings -- Remove the oinks! From jepler at unpythonic.net Wed Aug 13 15:11:01 2003 From: jepler at unpythonic.net (Jeff Epler) Date: Wed, 13 Aug 2003 14:11:01 -0500 Subject: Changing UNIX primary group In-Reply-To: <20030813181002.04DAF38434@www.fastmail.fm> References: <20030813181002.04DAF38434@www.fastmail.fm> Message-ID: <20030813191056.GB22290@unpythonic.net> On Wed, Aug 13, 2003 at 12:10:02PM -0600, Justin Johnson wrote: > Thanks. I was hoping for a python solution though. :-( Does anyone > know of a way to do this in python? Unix doesn't let you setgid() to groups in the supplemental group list without the same permission needed to change to any group. But depending what you need to do, you might be able to use set-group-id directories. For instance, if I am group g1 and have a group list [g1, g2, g3], then I can read files readable by any of those groups, and create files in directories writable by any of those groups. But if you make a directory d2 that is setgid g2 and d3 setgid g3, then when I create a file in d2 it will belong to group g2. Barring that, you could modify the setgid() call in the kernel, to permit the change if the requested group is in the auxiliary group list. It looks like something you could do in an afternoon if you have the source for your kernel (bsd, linux, etc) and can program C. "Justin Johnson" wrote in message news:... > Also [setgid] only accepts the gid, but I'd rather pass in > the group name, or somehow lookup the gid based on the name. See grp.getgrnam(). Example: >>> grp.getgrnam("utmp") ('utmp', 'x', 22, []) Jeff From achalk at XXXmagnacartasoftware.com Fri Aug 1 12:01:04 2003 From: achalk at XXXmagnacartasoftware.com (Andrew Chalk) Date: Fri, 01 Aug 2003 16:01:04 GMT Subject: Debugging a Python program from a browser Message-ID: <49wWa.1561$3J6.718038155@newssvr30.news.prodigy.com> My python 2.2 program runs from a browser. I want to set breakpoints that are activated when the program runs. In the current case I am running on W2K with IE v6.0. Any idea how to do this? Regards From gh at ghaering.de Thu Aug 7 05:31:45 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Thu, 07 Aug 2003 11:31:45 +0200 Subject: email client written with python + wxWindows In-Reply-To: <409a56e2.0308062211.456575df@posting.google.com> References: <409a56e2.0308062211.456575df@posting.google.com> Message-ID: <3F321C81.5090300@ghaering.de> Shagshag wrote: > hello, > > does anyone know of a full python + wxWindows email client ? There is one, but if you ask about my personal opinion, it's n ybnq bs penc. > google didn't help me... http://www.google.de/search?q=wxpython+email+client First hit. rzMail. Mahogany has support for Python scripting in the sourcecode, but AFAIR it hasn't been updated for years. It's written in C++ using wxWindows, but contrary to rzMail it's actually useful :-> -- Gerhard From usenet at microtonal.co.uk Sat Aug 23 06:19:59 2003 From: usenet at microtonal.co.uk (Graham Breed) Date: Sat, 23 Aug 2003 11:19:59 +0100 Subject: OT: Ocaml? In-Reply-To: <7xk795xde6.fsf_-_@ruckus.brouhaha.com> References: <7xk795xde6.fsf_-_@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Anyone here use OCAML? How do you like it? Is it a language a > Pythonista can learn to love? From what little I've seen, it looks > interesting, but I haven't actually tried installing or using it yet. Yes, I've been playing with it. It's a good complement to Python in that it's statically typed with an efficient compiler. It has an interactive interpreter, but there are some cases where it feels lower level. Like you can't do introspection to the same extent, and it doesn't have the magic string formatting (or rather, it must for the interpreter, but I don't know how to get at it). Graham From arekm at pld-linux.org Mon Aug 4 15:46:57 2003 From: arekm at pld-linux.org (Arkadiusz Miskiewicz) Date: Mon, 4 Aug 2003 21:46:57 +0200 Subject: open('.', 'rb') on python 2.3 Message-ID: <20030804194657.GA6706@arm.k83.ath.cx> Hi, Simple code fails in python 2.3: [root at maja rdiff-backup]# python Python 2.3 (#1, Jul 31 2003, 10:41:08) [GCC 3.3 (PLD Linux)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> fp = open('.', 'rb') Traceback (most recent call last): File "", line 1, in ? IOError: [Errno 21] Is a directory but works in 2.2 [arekm at perfo arekm]$ python Python 2.2.2 (#1, Dec 28 2002, 23:32:35) [GCC 2.95.4 20010319 (prerelease)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> fp = open('.', 'rb') >>> Is that bug, bugfix, change in python 2.3? (patch of course welcome) System is Linux 2.4.21, glibc 2.3.2, filesystem ext3, xfs. -- Arkadiusz Mi?kiewicz CS at FoE, Wroclaw University of Technology arekmatssedotpl AM2-6BONE, 1024/3DB19BBD, arekm(at)ircnet, PLD/Linux From alanmk at hotmail.com Fri Aug 15 06:58:49 2003 From: alanmk at hotmail.com (Alan Kennedy) Date: Fri, 15 Aug 2003 11:58:49 +0100 Subject: Python or Perl with C# or Java References: Message-ID: <3F3CBCE9.995FC68D@hotmail.com> bezeee wrote: > At my work we are in the process of building a tool to test an XML based > API. Basically, XML in and XML out over http. Presumably you mean WebServices/WSDL/etc when you say "an XML based API .. over HTTP"? If yes, you should check out TestMaker, an open source web-services testing framework. This might have solved all your problems already. http://www.pushtotest.com/ Look under "Free Tools". > Currently, there are two > engines that do all of the schema validations, xml diffs, > sending/receiving, > etc. One of these engines in implemented in C# and the other in Java. I think you'll find oodles of support for all things XML in both Java and C#. Probably more support than you need for any givan task. > Now the choice comes down to which scripting language we choose (Perl, > Python or Jython) to tie into one of these engines. The scripting language > is where we will actually write the tests which consists of manipulating > xml, checking values, etc. The C# and Java engines are simply tools to > report, schema validate, etc. > > It's a snap to use the C# modules with the Win32 libraries in Python and > Perl, Jython could handle the Java > I've seen JPE > (http://www.arakne.com/jpe/faq.htm) if we want to use Python and Java. Hmm, my understanding is that JPE is a dead project: no release of code for quite a while, no new features (Check out the date of copyright, August 2000). And being honest, I always thought it is a bad idea and a waste of effort anyway. If you want to glue python and jython together, far better to use some remote-object-call facility like Pyro, or CORBA. http://pyro.sourceforge.net/ http://omniorb.sourceforge.net/ > Personally, I like Python and C#. Unfortunately, my company leans towards > Perl and Java. I think you'll find that all of Python/COM, Python/C# and Jython/Java are excellent choices. My personal opinion is that Java can't be beaten for choice for third-party libraries, particularly for XML, which is fantastically well supported in the Java world. I make that assertion based on the fact that there are oodles of free Java + XML software available from third parties. Although I'm fairly sure that C# will get there eventually in terms of being well supported by the free software community, I don't believe that support is there right now: at least in comparison to Java. > Given, I'm posting on comp.lang.python but I'd love to hear anyone's > thoughts on Perl/Python/Jython interfacing with C# or Java. Summarising my knowledge 1. I know nothing about perl+java+c# 2. CPython supports MS platforms (COM, C#) extremely well. Pretty much guaranteed to support all facilities that you need. 3. Jython integration with Java is so good that it is completely seamless. Coding in jython and then dropping down to Java when you need more speed is a dream combination, IMHO. Given that Java and C# are essentially different flavours of the same language (Alan dons asbestos suit ;-), it seems to me that your real choice is based on how quickly you can write your apps in Perl vs. Python, and how correct and maintainable will the final result be. Assuming that Perl integrates with Java or C# as well as (C|J)Python does. HTH, -- alan kennedy ----------------------------------------------------- check http headers here: http://xhaus.com/headers email alan: http://xhaus.com/mailto/alan From fawcett at teksavvy.com Wed Aug 13 14:28:43 2003 From: fawcett at teksavvy.com (Graham Fawcett) Date: Wed, 13 Aug 2003 14:28:43 -0400 Subject: Determine file type (binary or text) In-Reply-To: <20030813105623.J19120@ActiveState.com> References: <20030813105623.J19120@ActiveState.com> Message-ID: <3F3A835B.3020900@teksavvy.com> Trent Mick wrote: >[Sami Viitanen wrote] > > >>Hello, >> >>How can I check if a file is binary or text? >> >>There was some easy way but I forgot it.. >> >> > >Generally I define a text file as "it has no null bytes". I think this >is a pretty safe definition (I would be interested to hear practical >experience to the contrary). > Dangerous assumption. Even if many or most binary files contain NULs, it doesn't mean that they all do. It is trivial to create a non-text file that has no NULs. f = open('no_zeroes.bin', 'rb') for x in range(1, 256): f.write(chr(x)) f.close() Sami, I would suggest that you need to stop thinking in terms of tools, and instead think in terms of the problem you're trying to solve. Why do you need to (or think you need to) determine whether a file is "binary" or "text"? Why would your application fail if it received a (binary/text) file when it expected a (text/binary) one? My guess is that the trait you are trying to identify will prove not to be "binary or text", but something more application-specific. -- Graham P.S. Sami, it's very bad form to "make up" an e-mail address, such as . I'm sure the owners of the none.net domain would agree. Can't you provide a real address? From skip at pobox.com Tue Aug 5 23:02:53 2003 From: skip at pobox.com (Skip Montanaro) Date: Tue, 5 Aug 2003 22:02:53 -0500 Subject: converting an integer to a string In-Reply-To: References: Message-ID: <16176.28637.956876.60332@montanaro.dyndns.org> Ken> I have a quick simple question. How do you convert an integer to a Ken> string in Python? Take your pick: str(someint) repr(someint) `someint` '%d' % someint Which is most appropriate may well depend on your tastes and your context. `someint` is just syntactic sugar for repr(someint), and is falling out of favor with many people. In the case of integers, str(someint) and repr(someint) are the same, so your choice there is a tossup unless you are str()'ing or repr()'ing other objects as well (str() generally tries to be "readable", repr() generally tries to be "parseable"). For most types repr() and str() generate different output. The experiment is probably educational enough to perform once, so I won't go into detail. The %-format version is appropriate if you want to embed it into a larger string, e.g.: '%s is %d years old' % (person, age) Don't forget the dict form as well: '%(name)s is %(age)d years old' % locals() Skip From mpeuser at web.de Mon Aug 18 03:16:48 2003 From: mpeuser at web.de (Michael Peuser) Date: Mon, 18 Aug 2003 09:16:48 +0200 Subject: hex(-5) => Futurewarning: ugh, can't we have a better hex than '-'[:n<0]+hex(abs(n)) ?? References: Message-ID: "Juha Autero" schrieb im Newsbeitrag news:mailman.1061182647.31076.python-list at python.org... > Freddie writes: > > >> There is a thread from this morning ("bitwise not ...") - this should be an > >> excellent contribution! > >> I have no mercy with someone writing hex(-5) > >> > >> Kindly > >> Michael P > >> > >> > > > > What about crazy people like myself? If you generate a crc32 value with zib, > > you occasionally get a negative number returned. If you try to convert that > > to hex (to test against a stored CRC32 value), it spits out a FutureWarning > > at me. > > Read the thread about bitwise not. Tell Python how many bits you > want. In case of CRC32 that is of course 32 bits: > hex(-5&2**32-1) > > Two questions: What is the best way to generate bitmask of n bits all > ones? Why do you object to 2**n-1? This is just fine I think. > And would sombody explain why hexadecimal (and octal) literals > behave differently from decimal literals? (see: > http://www.python.org/doc/current/ref/integers.html ) Why hexadecimal > literals from 0x80000000 to 0xffffffff are interpetred as negative > numbers instead of converting to long integers? Most of all this has practical reasons because of the use most programmers have for stating hexadecimal literals. Of couse some hex literals are not interpreted as negative numbers but the memory contents, because it has become undistinguishable what the origin had been. One will not expect print int(0xffffffff ) do something different from x=0xffffffff print int(x) Kindly Michael P > > -- > Juha Autero > http://www.iki.fi/jautero/ > Eschew obscurity! > > From adalke at mindspring.com Thu Aug 21 12:49:12 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Thu, 21 Aug 2003 16:49:12 GMT Subject: What's better about Ruby than Python? References: <3F41505F.69D18CC8@alcyone.com> <66d7kvonvb2n0nqbqahhd5roak7ur81sob@4ax.com> <3f43ef5d_4@127.0.0.1> <3F440A35.9030602@nyc.rr.com> <4o_0b.1665$Ej6.1182@newsread4.news.pas.earthlink.net> <8D01b.1721$Ej6.702@newsread4.news.pas.earthlink.net> Message-ID: Alex Martelli: > That's an oldstyle class -- use a newstyle one for smoothest > and most reliable behavior of descriptors Oops! Yeah, forgot that too. I do consider it a (necessary) wart that different classes have different behaviours. > > Is that right? > > Yes! So what is it that you say you don't get? Before this I didn't realize the process of __getattr__ had changed to allow the __get__ to work. I thought properties were done at assignment time rather than lookup time, and that the hooks were located in something done with __getattribute__ After stepping through it, with Raymond's descriptor next to me, I think I now understand it. > If obj is such that it can be used as a key into a dict > (weak or otherwise), sure. Many class instances of some > interest can't -- and if they can you may not like the > result. COnsider e.g. > > class Justanyclass: > def __init__(self, x): self.x = x > def compute(self, y): return self.x + y > > pretty dangerous to cache THIS compute method -- because, > as a good instance method should!, it depends crucially > on the STATE of the specific instance you call it on. But if someone were to use a method call cache on it then I would have expected that person to know if its use was relevant. > Anyway, I just wanted to > show how the descriptor concept lets you use a class, > rather than a function, when you want to -- indeed any > function now has a __get__ method, replacing (while > keeping the semantics of) the old black magic. Yep. Using a class is to be prefered over my def-with-nested-scope trick. Andrew dalke at dalkescientific.com From tebeka at cs.bgu.ac.il Mon Aug 4 09:22:32 2003 From: tebeka at cs.bgu.ac.il (Miki Tebeka) Date: 4 Aug 2003 06:22:32 -0700 Subject: wxPython: Default Frame button? References: <33803989.0308030211.10b31e97@posting.google.com> Message-ID: <33803989.0308040522.2edbd0ec@posting.google.com> Hello Cliff, > In general, the only child of a frame should be a panel or some other > container (like a splitter). Frames should generally only have one > child. Make the button a child of the panel rather than a sibling. 10x. Works like a charm. >class F(wx.Frame): > def __init__(self): > wx.Frame.__init__(self, None, -1, "Test Frame") > panel = P(self) > self.Fit() Is there a default frame that does the above? Miki. From skip at pobox.com Mon Aug 11 20:12:48 2003 From: skip at pobox.com (Skip Montanaro) Date: Mon, 11 Aug 2003 19:12:48 -0500 Subject: Multi-Line Comment In-Reply-To: References: <4qofjvg3bh9smlnb1do4f0lhjga7bacnu3@4ax.com> Message-ID: <16184.12544.119281.520186@montanaro.dyndns.org> Doug> How do you comment the block of text with Emacs? That is what I'm Doug> using for my code editor. "C-c #". Here's the doc: C-c # runs `py-comment-region' `py-comment-region' is an interactive compiled Lisp function -- loaded from "/Users/skip/emacs/python-mode.elc" (py-comment-region BEG END &optional ARG) Documentation: Like `comment-region' but uses double hash (`#') comment starter. Skip From ktilton at nyc.rr.com Thu Aug 21 11:45:37 2003 From: ktilton at nyc.rr.com (Kenny Tilton) Date: Thu, 21 Aug 2003 15:45:37 GMT Subject: What's better about Ruby than Python? References: <3F41505F.69D18CC8@alcyone.com> <66d7kvonvb2n0nqbqahhd5roak7ur81sob@4ax.com> <3f43ef5d_4@127.0.0.1> <3F440A35.9030602@nyc.rr.com> Message-ID: <3F44E9F0.3080902@nyc.rr.com> Alex Martelli wrote: > Kenny Tilton wrote: > ... > >>thread: Python is not trying to be everything. Fair enough. Let Python >>be Python, let Lisp be Lisp. >> >>ie, If someone wants macros, they probably would also like special >>variables and closures and lexical scope and multi-methods and they may >>as well get it over with and learn Lisp and stop trying make Python more >>than it wants to be. > > > Hear, hear! Or one you just can't stand the nested-parentheses idea, > then that's what Dylan was designed for: much the same semantics > and power as Lisp, including all of the features you mention!, but with > infix syntax. But walk a mile in parentheses before ducking them. I hope never to edit another syntax again. The editor uses them to /show me/ the structure of the code, mine or anyone else's. No more manually prettying up my code; control-shift-p does an entire file. And when I am slicing and dicing, I tend to work in the chunks defined by parens. Under ACL's Emacs-like editor a double-click selects a whole chunk, or right click duplicates a whole chunk. Throw in drag and drop along with cut-copy-paste, and I am safely refactoring (or coding or bugfixing) at a very high level while the editor takes care of the details. hellasweet. -- kenny tilton clinisys, inc http://www.tilton-technology.com/ --------------------------------------------------------------- "Career highlights? I had two. I got an intentional walk from Sandy Koufax and I got out of a rundown against the Mets." -- Bob Uecker From __peter__ at web.de Thu Aug 28 17:33:27 2003 From: __peter__ at web.de (Peter Otten) Date: Thu, 28 Aug 2003 23:33:27 +0200 Subject: opposite of dict.items() References: <3f4e708c$0$64719@hades.is.co.za> Message-ID: Tertius wrote: > Is there a method to create a dict from a list of keys and a list of > values ? >>> dict(zip(range(3), "abc")) {0: 'a', 1: 'b', 2: 'c'} Not a method() but a method. Peter From mwh at python.net Tue Aug 26 10:02:12 2003 From: mwh at python.net (Michael Hudson) Date: Tue, 26 Aug 2003 14:02:12 GMT Subject: Replacement for rexec/Bastion? References: <862bb9d6ecb44848b676dc4a7dd9ffd5@news.teranews.com> Message-ID: <7h3isokzfic.fsf@pc150.maths.bris.ac.uk> "Colin Coghill (SFive)" writes: [snippety] > I'd like to be able to have (possibly malicious) users of my software able > to script behavior using small snippets of python code. Anything from a line > to maybe a few pages in length each. I can trap endless loops and the like, > but I need something to stop them just importing sys and raising havoc. Zope's RestrictedPython might be an option. Cheers, mwh -- how am I expected to quit smoking if I have to deal with NT every day -- Ben Raia From BjornPettersen at fairisaac.com Thu Aug 28 19:07:01 2003 From: BjornPettersen at fairisaac.com (Pettersen, Bjorn S) Date: Thu, 28 Aug 2003 18:07:01 -0500 Subject: Object Database (ODBMS) for Python Message-ID: <1DAECE9E8F34E04AA0E5699AF7D9FF090708D440@stpmsg00.corp.fairisaac.com> > From: Patrick K. O'Brien [mailto:pobrien at orbtech.com] > > I'm working on an ODBMS written in Python, for Python, and was > wondering if anyone was interested. In particular, I'd like to know > what features would be useful, and what types of use cases people > would have for a simple, but feature-rich object database. > > The system that I'm developing is PyPerSyst, which began as a simple > persistence mechanism, but is now becoming a complete ODBMS. Some > details are available here: > > http://www.orbtech.com/wiki/PyPerSyst > > The code is available in CVS on SF: > > http://sourceforge.net/projects/pypersyst/ I'd be interested, but can't seem to find docs, demos or tests through sf's web interface.. any pointers? - bjorn From sross at connectmail.carleton.ca Sat Aug 23 22:16:54 2003 From: sross at connectmail.carleton.ca (Sean Ross) Date: Sat, 23 Aug 2003 22:16:54 -0400 Subject: List and array code? References: Message-ID: "derek / nul" wrote in message news:ss6gkvo87qn5eu279gsct60c1id8fmb6hb at 4ax.com... > Is there any list or array code that can load lines from a file? > > ie what I would like is to open a file and load line by line into a list or > array. > Hi. There are several ways to do this: # list comprehension lines = [line for line in file("your/file/name/here")] # file_object.readlines() lines = file("your/file/name/here").readlines() # build list from iterator lines = list(file("your/file/name/here")) # for loop lines = [] for line in file("your/file/name/here"): lines.append(line) HTH Sean From tzot at sil-tec.gr Mon Aug 25 03:50:06 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Mon, 25 Aug 2003 10:50:06 +0300 Subject: macro FAQ References: <878ypjjjid.fsf@pobox.com> Message-ID: <3tfjkvs73du8bt3irumtaohv1ajpas008q@4ax.com> On 24 Aug 2003 16:34:08 +0200, rumours say that Jacek Generowicz might have written: [See at the end for an interactive session transcript -- a simple copy - paste] >> No, wait a minute -- instances, not classes?? Sounds like an abuse of >> the language to me. What *is* the underlying problem to be solved >> here? > >It started in the Ruby thread: in Ruby classes are "open". > >Say you're developing a class (foo), make a gazillion instances of it, >and play around with them as you are continuing to develop your >program. Suddenly you realize "Darn, I really need a fubar method!" > >In Ruby you do something like: > >class foo > def fubar ... > > end >end > >All your existing gazillion instances of foo have just acquired a >fubar method, and you can happily continue your exploration with all >the state you built up still intact. > >The first thing you might try to do in Python is to add the fubar >method to the class source code, and re-evaluate it ... only to find >that your existing instances know nothing about the new method ... so >you have to go through the hassle of re-creating a gazillion of them, >before you can continue with what you were doing. ##### code starts here ##### >>> class A(object): pass >>> a= A() >>> a.test() Traceback (most recent call last): File "", line 1, in ? a.test() AttributeError: 'A' object has no attribute 'test' >>> def test(self): print id(self) >>> A.test = test >>> a.test() 13111376 ##### code ends here ##### -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From gh at ghaering.de Mon Aug 25 03:32:01 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Mon, 25 Aug 2003 09:32:01 +0200 Subject: ANN: BlackAdder V1.0.0 In-Reply-To: References: <3f48a498$3$219$fa0fcedb@lovejoy.zen.co.uk> Message-ID: <3F49BB71.2070604@ghaering.de> Will Stuyvesant wrote: >>[BadJake] > > You usenet posting did look bad to me. It looked like a mess: > amateuristic. Looked like a copy-and-paste from some web page into an ASCII editor to me. Which of course doesn't make it any better. > If you want to sell things, you should make even ascii-based postings > look professionally. And don't mention prices in this newsgroup, > give a URI. Furthermore, I'd excpect an email address with a connection to the company that offers the product, something like blackadder at thekompany.com, sales at thekompany.com or something like that. Not some random BadJake with a completely different email address ;-) -- Gerhard From tim.golden at viacom-outdoor.co.uk Wed Aug 27 10:32:44 2003 From: tim.golden at viacom-outdoor.co.uk (Tim Golden) Date: Wed, 27 Aug 2003 15:32:44 +0100 Subject: detecting document changes Message-ID: From: Alessandro Crugnola *sephiroth* [mailto:alessandro at sephiroth.it] >> Tim Golden: >> and this one with Win32: >> >> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/156178 > thanks but that one check only new/deleted/renamed files Indeed, but as I noted in the original response, you only need to add a flag or two to the API call to get modification notifications as well. (He says, without checking it out for himself). > ..but is not too stressing for the cpu > to check for file changes in a (forever) while loop? In short, no. Somewhere in the depths of the operating system is a signal / wait mechanism which sits there quite quietly until something happens. Anything on Windows which uses the WaitForSingleObject family of API calls is fairly safe. Obviously, there is an overhead (try running it against a big directory of constantly-changing files) but by and large it's fine. There is another, deeper, API call which Mark Hammond introduced into the later versions of win32all. I can't remember the name of the function, but if you Google back through c.l.py looking for FindFirstChangeNotification and/or my name, you might come across an earlier discussion on the matter. I haven't tried it myself. As a final note, you could -- theoretically -- use WMI to do this same job: it can see directories as objects and has a notification system, but I tried it once and soon had to reboot my machine. Don't Do It! TJG ________________________________________________________________________ This e-mail has been scanned for all viruses by Star Internet. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________ From theller at python.net Fri Aug 22 12:53:44 2003 From: theller at python.net (Thomas Heller) Date: Fri, 22 Aug 2003 18:53:44 +0200 Subject: py2exe service doesn't work, can't connect to service controller ? References: <3F41F576.14352.14BE73C2@localhost> Message-ID: "Brad Clements" writes: > I edited the svc_run.exe file and changed PyWinTypes22.dll to > PyWinTypes23.dll. py2exe now builds a distribution that does not use any 2.2 > Python components. > > However the service still fails to load after installation with the > following error: > > > The description for Event ID ( 240 ) in Source ( MyService ) cannot be > found. The local computer may not have the necessary registry information or > message DLL files to display messages from a remote computer. The following > information is part of the event: 1063, The service process could not > connect to the service controller.. > > Has anyone been able to get py2exe services to work with 2.3? Brad, I want to lookm after this tonight. Do you have any further information for me? Does the service run with 2.2? Thomas From sjmachin at lexicon.net Fri Aug 1 18:06:20 2003 From: sjmachin at lexicon.net (John Machin) Date: 1 Aug 2003 15:06:20 -0700 Subject: Problem with Unzipping/Installing Python-2.3.exe References: Message-ID: John Latter wrote in message news:... > Hi, > > I downloaded Python-2.3.exe but when I used winzip it kept asking me > if I wanted to replace old files with new ones, and in some instances, > new files with old ones. > > I've never downloaded/installed Python before, and as something of a > computer novice, would like to know what I may be doing wrong! > > This is the link I downloaded from: > > >Windows users should download the Windows installer, Python-2.3.exe > >, run it and follow the friendly instructions on the screen to complete > >the installation. Faced with the 4 clues in the above sentence: (1) "installer" (2) ".exe" (3) "run it" (4) complete absence of any mention of ".zip", "unzip", "Winzip", ..., my expectation would be that one should run the damn thing, not try to unzip it. Do you feel that the instructions were unclear? Do you have any suggestions on how they might be improved? > 'Where Darwin meets Lamarck?' Discussion Egroup > http://groups.yahoo.com/group/evomech Is this anything to do with the Darwin Awards? From ajsiegel at optonline.net Fri Aug 1 20:11:25 2003 From: ajsiegel at optonline.net (Arthur) Date: Fri, 01 Aug 2003 20:11:25 -0400 Subject: Numeric and VPython for Python2.3 Windows available Message-ID: <010501c3588a$9d3d0960$0c02a8c0@Arts> Anxious to begin using 2.3 and dependent on Numeric and VPython, I did VC6 compilation of these modules for Windows. Disutils created self-installing executables are available for anyone who might find them useful at http://home.netcom.com/~ajs/download.html Art From bgailer at alum.rpi.edu Mon Aug 11 08:29:34 2003 From: bgailer at alum.rpi.edu (Bob Gailer) Date: Mon, 11 Aug 2003 06:29:34 -0600 Subject: convert tuple to string In-Reply-To: Message-ID: <5.2.1.1.0.20030811062856.02bef008@66.28.54.253> At 02:55 PM 8/11/2003 +0200, Lukas Kasprowicz wrote: >-----BEGIN PGP SIGNED MESSAGE----- >Hash: SHA1 > >Hi Folks, > >My Proglem is, I get after a query on a mysql database with module MySQLdb a >tuple but I need this output from database as a string. >can anybody help? > >- -------------- database --------- >import MySQLdb >def select(fields, tables, where): > db=MySQLdb.connect(host=db_host,user=db_user,passwd=db_passwd,db=db_db) > c = db.cursor() > c.execute("SELECT %s FROM %s WHERE %s" %(fields,tables,where)) > return c.fetchall() > db.close() > > >OUTPUT: >- -------------- >(('6610 at 8210',), ('akku',), ('cover',), ('ladekabel',), ('kfz',), >('tischladestation',), ('dummy',), ('Hansytasche',), ('poster',), ('o2',), >('Vodafone',), ('T-Mobile',), ('D1',), ('D2',), ('E+',), ('Eplus',), >('tasche',), ('zubeh\xf6r',), ('Quertasche',), ('Ledertasche',), ('Boom',), >('BELEUCHTUNG',), ('Tastaturmatte',), ('Dummys',), ('Zubeh\xf6rset',), >('TASTATUR',), ('Tastatur',), ('Mittelgeh\xe4use',), ('fast',), >('Displayschutzfolie',), ('Radio',), ('Tischlader',), >('Geh\xe4use\xf6ffner',), ('Oberschale',), ('1 Woche',), ('Alubox',), >('Echtledertasche',), ('E Plus',), ('E+',), ('Eplus',)) There are numerous ways to create strings. It'd help if you'd tell us what this string should look like. Either give us an example or a specification. Bob Gailer bgailer at alum.rpi.edu 303 442 2625 -------------- next part -------------- --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.506 / Virus Database: 303 - Release Date: 8/1/2003 From irmen at -NOSPAM-REMOVETHIS-xs4all.nl Sun Aug 3 07:59:56 2003 From: irmen at -NOSPAM-REMOVETHIS-xs4all.nl (Irmen de Jong) Date: Sun, 03 Aug 2003 13:59:56 +0200 Subject: Interview with Guido in the Wall Street Journal In-Reply-To: References: Message-ID: <3f2cf93b$0$49106$e4fe514c@news.xs4all.nl> Will Stuyvesant wrote: > Daily Python mentions: > > "Lee Gomes: Two men, two ways to speak computerese [The Wall Street > Journal reports on Python and Perl, and interviews their respective > authors.] " > > If you click on the link then you will find TWSJ works with > subscription, "2 weeks for free!". Hurray! Forcing people to > subscribe and then (later) asking money for it is against my > principles of free information exchange so I didn't read it. > > Anybody has the interview? Any good? Afraid to post it here because > of legal issues? I posted a link to the article in the weekly Python-URL! and was just about to copy-paste it here, when I found out that it is indeed saying "only available to subscribers now". It was accessible (without subscribing) a few days ago... Bah. I didn't save it, sorry. --Irmen From tzot at sil-tec.gr Tue Aug 26 14:36:09 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Tue, 26 Aug 2003 21:36:09 +0300 Subject: file object, details of modes and some issues. References: <3f4b800f_3@mk-nntp-1.news.uk.worldonline.com> <6q6nkv88qb708bc0d6g5vtcg20r4dob3r6@4ax.com> Message-ID: On Tue, 26 Aug 2003 21:11:52 +0300, rumours say that Christos "TZOTZIOY" Georgiou might have written: >I will open a bug report if none other does, >but first I would like to know if it's the Windows stdio to blame or >not. I didn't wait that long, it's bug 795550 in SF. -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From xy at nikolaidis.com Sat Aug 30 11:46:08 2003 From: xy at nikolaidis.com (Peter Nikolaidis) Date: Sat, 30 Aug 2003 11:46:08 -0400 Subject: Can't get MySQLdb to connect Message-ID: <12C23450-DB01-11D7-8162-00039393C622@nikolaidis.com> Greetings, I am attempting to get MySQLdb 0.9.2 installed on Mac OS 10.2 with a Fink distribution of Python 2.2.2. I have seen only a few posts on the subject, some of them relate to "conflicting header files," but I don't know what to do about conflicting header files, or where I would find them, and once I found them, which ones to remove. I have compiled MySQL 4.1 and installed into /usr/local/mysql, but since have moved to a Fink package installation or 4.0.13. Although MySQLdb appears to install successfully (I think), I am unable to connect when I try, as shown below: >>> import sys >>> import MySQLdb >>> conn = MySQLdb.connect (db = 'mydb', host = 'localhost', user = 'myuser', passwd = 'mypassword') Traceback (most recent call last): File "", line 1, in ? File "/sw/lib/python2.2/site-packages/MySQLdb/__init__.py", line 63, in Connect return apply(Connection, args, kwargs) File "/sw/lib/python2.2/site-packages/MySQLdb/connections.py", line 116, in __init__ self.converter[types.StringType] = self.string_literal TypeError: object does not support item assignment >>> My setup.py file contains the following (although I've tried many variations, commenting and uncommenting stuff with no real success): # include files and library locations should cover most platforms include_dirs = [ # '/usr/include/mysql', # '/usr/local/include/mysql', # '/usr/local/mysql/include/mysql', '/sw/include/mysql' ] library_dirs = [ # '/usr/lib/mysql', # '/usr/local/lib/mysql', # '/usr/local/mysql/lib/mysql', '/sw/lib/mysql', '/sw/lib' ] This is what happens when I build: running build running build_py not copying CompatMysqldb.py (output up-to-date) not copying _mysql_exceptions.py (output up-to-date) not copying MySQLdb/__init__.py (output up-to-date) not copying MySQLdb/converters.py (output up-to-date) not copying MySQLdb/connections.py (output up-to-date) not copying MySQLdb/cursors.py (output up-to-date) not copying MySQLdb/sets.py (output up-to-date) not copying MySQLdb/times.py (output up-to-date) not copying MySQLdb/constants/__init__.py (output up-to-date) not copying MySQLdb/constants/CR.py (output up-to-date) not copying MySQLdb/constants/FIELD_TYPE.py (output up-to-date) not copying MySQLdb/constants/ER.py (output up-to-date) not copying MySQLdb/constants/FLAG.py (output up-to-date) not copying MySQLdb/constants/REFRESH.py (output up-to-date) not copying MySQLdb/constants/CLIENT.py (output up-to-date) running build_ext skipping '_mysql' extension (up-to-date) And when I run setup.py install: running install running build running build_py not copying CompatMysqldb.py (output up-to-date) not copying _mysql_exceptions.py (output up-to-date) not copying MySQLdb/__init__.py (output up-to-date) not copying MySQLdb/converters.py (output up-to-date) not copying MySQLdb/connections.py (output up-to-date) not copying MySQLdb/cursors.py (output up-to-date) not copying MySQLdb/sets.py (output up-to-date) not copying MySQLdb/times.py (output up-to-date) not copying MySQLdb/constants/__init__.py (output up-to-date) not copying MySQLdb/constants/CR.py (output up-to-date) not copying MySQLdb/constants/FIELD_TYPE.py (output up-to-date) not copying MySQLdb/constants/ER.py (output up-to-date) not copying MySQLdb/constants/FLAG.py (output up-to-date) not copying MySQLdb/constants/REFRESH.py (output up-to-date) not copying MySQLdb/constants/CLIENT.py (output up-to-date) running build_ext skipping '_mysql' extension (up-to-date) running install_lib not copying build/lib.darwin-6.6-PowerMacintosh-2.2/_mysql.so (output up-to-date) not copying build/lib.darwin-6.6-PowerMacintosh-2.2/_mysql_exceptions.py (output up-to-date) not copying build/lib.darwin-6.6-PowerMacintosh-2.2/CompatMysqldb.py (output up-to-date) not copying build/lib.darwin-6.6-PowerMacintosh-2.2/MySQLdb/__init__.py (output up-to-date) not copying build/lib.darwin-6.6-PowerMacintosh-2.2/MySQLdb/connections.py (output up-to-date) not copying build/lib.darwin-6.6-PowerMacintosh-2.2/MySQLdb/constants/__init__.py (output up-to-date) not copying build/lib.darwin-6.6-PowerMacintosh-2.2/MySQLdb/constants/CLIENT.py (output up-to-date) not copying build/lib.darwin-6.6-PowerMacintosh-2.2/MySQLdb/constants/CR.py (output up-to-date) not copying build/lib.darwin-6.6-PowerMacintosh-2.2/MySQLdb/constants/ER.py (output up-to-date) not copying build/lib.darwin-6.6-PowerMacintosh-2.2/MySQLdb/constants/FIELD_TYPE.py (output up-to-date) not copying build/lib.darwin-6.6-PowerMacintosh-2.2/MySQLdb/constants/FLAG.py (output up-to-date) not copying build/lib.darwin-6.6-PowerMacintosh-2.2/MySQLdb/constants/REFRESH.py (output up-to-date) not copying build/lib.darwin-6.6-PowerMacintosh-2.2/MySQLdb/converters.py (output up-to-date) not copying build/lib.darwin-6.6-PowerMacintosh-2.2/MySQLdb/cursors.py (output up-to-date) not copying build/lib.darwin-6.6-PowerMacintosh-2.2/MySQLdb/sets.py (output up-to-date) not copying build/lib.darwin-6.6-PowerMacintosh-2.2/MySQLdb/times.py (output up-to-date) skipping byte-compilation of /sw/lib/python2.2/site-packages/_mysql_exceptions.py to _mysql_exceptions.pyc skipping byte-compilation of /sw/lib/python2.2/site-packages/CompatMysqldb.py to CompatMysqldb.pyc skipping byte-compilation of /sw/lib/python2.2/site-packages/MySQLdb/__init__.py to __init__.pyc skipping byte-compilation of /sw/lib/python2.2/site-packages/MySQLdb/connections.py to connections.pyc skipping byte-compilation of /sw/lib/python2.2/site-packages/MySQLdb/constants/__init__.py to __init__.pyc skipping byte-compilation of /sw/lib/python2.2/site-packages/MySQLdb/constants/CLIENT.py to CLIENT.pyc skipping byte-compilation of /sw/lib/python2.2/site-packages/MySQLdb/constants/CR.py to CR.pyc skipping byte-compilation of /sw/lib/python2.2/site-packages/MySQLdb/constants/ER.py to ER.pyc skipping byte-compilation of /sw/lib/python2.2/site-packages/MySQLdb/constants/FIELD_TYPE.py to FIELD_TYPE.pyc skipping byte-compilation of /sw/lib/python2.2/site-packages/MySQLdb/constants/FLAG.py to FLAG.pyc skipping byte-compilation of /sw/lib/python2.2/site-packages/MySQLdb/constants/REFRESH.py to REFRESH.pyc skipping byte-compilation of /sw/lib/python2.2/site-packages/MySQLdb/converters.py to converters.pyc skipping byte-compilation of /sw/lib/python2.2/site-packages/MySQLdb/cursors.py to cursors.pyc skipping byte-compilation of /sw/lib/python2.2/site-packages/MySQLdb/sets.py to sets.pyc skipping byte-compilation of /sw/lib/python2.2/site-packages/MySQLdb/times.py to times.pyc Any help would be greatly appreciated. Thanks, Peter From alan.gauld at btinternet.com Thu Aug 28 16:58:24 2003 From: alan.gauld at btinternet.com (Alan Gauld) Date: Thu, 28 Aug 2003 20:58:24 GMT Subject: Tci/basic References: Message-ID: <3f4e6b8d.1219831995@news.blueyonder.co.uk> On Wed, 27 Aug 2003 20:57:18 -0700, Rich wrote: > I am going through one of the tutorials on the Python site, and some > of the things mentioned are Tci and Basic. THey are just there for comparison, don;t worry about typing them in. Just look at them long enough to notice the similarity. > What prompt do I do this commands from? If you really really feel you must you should find QBASIC on your Windows CD. You just copy the exe file to your hard drive and run it. It brings up a text menu based mouse driven programming environment. The Tcl stuff you can download as per a previous post, but again I don't really recommend this nowadays. (Tcl used to come with Python, now you only get a DLL) > I think I am missing something. I am following the tutorial fine when I use the Python > Shell, but when it talks about Tci or Basic I get lost. Just ignore those bits and skip to the Python stuff. > If it isn't painfully obvious, I am new to the programming world. That's OK, it's what the tutor is aimed at. Its just that I personally believe that learning to program is more important than learning a single language (even Python) so I try to show how similar they all are by using three... Some may argue that this is just overly confusing, personally I think the extra effort is worth it (or at least it was when Tcl and QBASIC were readily available!) Alan G. Author of the Learn to Program website http://www.freenetpages.co.uk/hp/alan.gauld From gh at ghaering.de Wed Aug 13 07:50:48 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Wed, 13 Aug 2003 13:50:48 +0200 Subject: libmysqld.dll & Python API seeking... In-Reply-To: References: Message-ID: <3F3A2618.6070502@ghaering.de> JZ wrote: > Is there any Python module working with embed MySQL 4.x? I found only > C++ API with not working example from MySQL manual. :( MySQLdb can be built against MySQL 4.x. It should be certainly possible to make it work against the embedded version of MySQL. Last time I tried the result was that at .connect time it crashed. But if you invest more time than me (more than 2 minutes), you can probably get it working ;-) -- Gerhard From Mike at DeleteThis.Geary.com Fri Aug 22 04:55:56 2003 From: Mike at DeleteThis.Geary.com (Michael Geary) Date: Fri, 22 Aug 2003 01:55:56 -0700 Subject: Q: urlopen() and "file:///c:/mypage.html" ?? References: Message-ID: > MAK wrote: > > I'm trying to use Python 2.3's urllib2.urlopen() to open an HTML > > file on the local harddrive of my WinXP box. > > > > If I were to use, say, Netscape to open this file, I'd specify it as > > "file:///c:/mypage.html", and it would open it just fine. But > > urlopen() won't accept it as a valid URL. I get an OSError > > exception with the error message "No such file or directory: > > '\\C:\\mypage.html'". Joe Francia wrote: > This works: > > f = urllib2.urlopen(r'file:///c|\mypage.html') > > But, if you're only opening local files, what's wrong with: > > f = file(r'c:/mypage.html', 'r') Just to add to that, the significant thing in the working example isn't that it uses backslash instead of forward slash, but that it uses vertical bar instead of colon. This works just as well: f = urllib2.urlopen( 'file:///c|/mypage.html' ) -Mike From dbentley at stanford.edu Wed Aug 27 02:38:06 2003 From: dbentley at stanford.edu (Daniel Timothy Bentley) Date: Tue, 26 Aug 2003 23:38:06 -0700 Subject: sending a byte on a socket Message-ID: Slamming my head against what should be an easy problem: How do I send a byte across an open, connected socket? Do I have to implement my own type that implements some method a string normally does? Or is there some hidden encoding that will let me turn a byte into a string? This is surely a simple question for anyone who remembers the answer. Thanks so much, Dan From phil.hornby at accutest.co.uk Thu Aug 14 07:59:37 2003 From: phil.hornby at accutest.co.uk (Phil Hornby) Date: Thu, 14 Aug 2003 12:59:37 +0100 Subject: To all UK Python Users In-Reply-To: Message-ID: Ooops wrong mailing list.... -----Original Message----- From: python-list-admin at python.org [mailto:python-list-admin at python.org]On Behalf Of Phil Hornby Sent: 14 August 2003 12:54 To: python-list at python.org Subject: FW: To all UK Python Users Not sure how many of you subscribe to the main python list...i know I am starting to get sick of being so swamped.... But here is something you might be interested in....thought it might be worth posting to here too...as someone else suggested it might be better to continue the thread in here... -----Original Message----- From: python-list-admin at python.org [mailto:python-list-admin at python.org]On Behalf Of BadJake Sent: 14 August 2003 09:45 To: python-list at python.org Subject: To all UK Python Users Hi I have noticed that there does not seem to be a Python User Group anywhere in the UK. Therefore, I would like to put that to rights. I am willing to donate space on one of my web servers if there is sufficient interest. If anybody is interested in joining with me to set up a UK Python User Group please contact me at john at rygannon.com Best Regards John Dean -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list From aahz at pythoncraft.com Tue Aug 19 01:07:01 2003 From: aahz at pythoncraft.com (Aahz) Date: 19 Aug 2003 01:07:01 -0400 Subject: python for non-programmers tutorial? References: Message-ID: In article , Anthony Baxter wrote: > >I'm writing a half-day tutorial at work for the non-programmer techies >(network engineers, database admins, sysadmins, that sort of thing) >and was wondering if anyone else has already done this and made their >materials available? I plan to put my slides up on the web after they're >done... Dunno about slides, but the first link on www.python.org's sidebar is "Beginner's Guide"... You should be able to find something useful there. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From raims at dot.com Thu Aug 28 15:51:15 2003 From: raims at dot.com (Lawrence Oluyede) Date: Thu, 28 Aug 2003 21:51:15 +0200 Subject: how fast is Python? References: Message-ID: <8765khzhl8.fsf@voodoo.fake> "Steve Horsley" writes: > Have you heard of Jython - python language running on a java VM? It's kind > of double interpreted - the python source is converted to JVM bytecode, > and then the JVM runs it however that JVM runs bytecode. I guess it should > be many times faster than python because of the JVM performance, and > wopuld be interested to hear any comparisons. Jython faster than Python? We did little test and it doesn't seem, look: http://tinyurl.com/liix -- Lawrence "Rhymes" Oluyede http://loluyede.blogspot.com rhymes at NOSPAMmyself.com From ta-meyer at ihug.co.nz Thu Aug 21 17:44:49 2003 From: ta-meyer at ihug.co.nz (Tony Meyer) Date: Fri, 22 Aug 2003 09:44:49 +1200 Subject: Reading/Writing Config Files In-Reply-To: <1ED4ECF91CDED24C8D012BCF2B034F1302E95287@its-xchg4.massey.ac.nz> Message-ID: <1ED4ECF91CDED24C8D012BCF2B034F13026F28A4@its-xchg4.massey.ac.nz> > 1. ConfigParser: does not preserve order of entries in the > config file and comments when updating the file. This is > critical since people are going to be reading/updating those > files as well. [...] > Are there other libraries I should look at? Should I just > write one myself (or clean up [2] or [3]) ? I can't believe > there isn't something better available for such a common task... I ran into this when making some changes to the SpamBayes options code, too. I was also surprised that there didn't seem to be anything around, and ended up making a enhanced version of [1]. I was meant to submit this as a patch in case the Python people were interested, but haven't yet got around to it (for one reason, the use by SpamBayes changed a couple of times). Note that it's a much more difficult task to enhance [1] in Python 2.2 because all the attributes that you need to override are private. This is fixed in Python 2.3. If you want it, you can find it in the source for SpamBayes (in case you don't know, the PSF holds the copyright to SpamBayes and it's released under the PSF license, just like Python itself). There's a module in the spambayes/spambayes attic called UpdatableConfigParser.py, which is a standalone module that does what you're after. There's also the file spambayes/spambayes/Options.py, which contains a version of this, but isn't standalone. FWIW and HTH. =Tony Meyer From Juha.Autero at iki.fi Tue Aug 19 03:33:05 2003 From: Juha.Autero at iki.fi (Juha Autero) Date: Tue, 19 Aug 2003 10:33:05 +0300 Subject: hex(-5) => Futurewarning: ugh, can't we have a better hex than '-'[:n<0]+hex(abs(n)) ?? References: Message-ID: <87oeymf6fi.fsf@jautero.no-ip.org> "Michael Peuser" writes: >> Two questions: What is the best way to generate bitmask of n bits all >> ones? > > Why do you object to 2**n-1? This is just fine I think. Maybe I should have said "What other ways there are to generate a bitmask of n bits all ones?" 2**n-1 seemed like a hack since it relies on certain properties of binary numbers, but on the other hand all bitmask processing relies on certain properties of binary numbers. -- Juha Autero http://www.iki.fi/jautero/ Eschew obscurity! From aleax at aleax.it Tue Aug 5 07:45:47 2003 From: aleax at aleax.it (Alex Martelli) Date: Tue, 05 Aug 2003 11:45:47 GMT Subject: Exploratory query References: Message-ID: Don Todd wrote: > I'm a total python newbie and have not really even begun to learn. > Before I start, however, I would like to know if python is the proper > tool for what I want to do. > > I want to query various MH mailboxes to see if they contain new mail. > There is a program, flist, that will do this, but it is a pain to run it > every time. I'd like something a la xbiff or gbiffy. > > Would python allow me to run flist and use its output, or would I need > to re-write flist? The idea is to keep something on the screen and poll > the mailboxes every n seconds and update the display. Yes, it should be pretty easy to write a Python script (with e.g. a Tkinter GUI) to do just this -- run another arbitrary program X every Y seconds and keep a window display with the latest stdout of said program X. (Of course, you can then make a more refined version that knows the format of stdout for given programs and parses it in order to provide prettier or more useful output, and add more features). Such a script could be something like: import Tkinter as Tk import optparse, sys, os # acquire arguments parser = optparse.OptionParser() parser.add_option('-c', '--command', dest='command', help='Command to be executed periodically', metavar='PIPELINE', default='date') parser.add_option('-p', '--period', dest='period', help='How many seconds to wait between executions', metavar='SECONDS', default=5) options, args = parser.parse_args() if args: print >> sys.stderr, "Unknown args %r ignored" % args # run command, update output if needed last_output = '' def run_command(): global last_output new_output = os.popen(options.command).read() if new_output != last_output: last_output = new_output text.config(state=Tk.NORMAL) text.delete(1.0, Tk.END) text.insert(Tk.END, new_output) text.config(state=Tk.DISABLED) text.after(options.period, run_command) # prepare and display a GUI text = Tk.Text() text.config(state=Tk.DISABLED) text.pack() run_command() Tk.mainloop() Running this with -cflist should already give you a first rough prototype of what you might want. Many improvements are of course possible, but I hope this shows it's worth studying some Python (and Tkinter, or other GUI toolkit if you prefer) in order to be able to implement such improvements. Alex From sross at connectmail.carleton.ca Wed Aug 27 20:28:58 2003 From: sross at connectmail.carleton.ca (Sean Ross) Date: Wed, 27 Aug 2003 20:28:58 -0400 Subject: Script Discussion & Critique References: <3F4D31B1.6080802@hotmail.com> <06eqkv4onjh5m4tcbbqkmh8lscaj5niatp@4ax.com> <3F4D4402.3060209@hotmail.com> Message-ID: "hokiegal99" wrote in message news:3F4D4402.3060209 at hotmail.com... Here's a some trivial (mostly cosmetic) changes: # multi-line string print """ ****************************************************** Three Easy Steps to a Recursive Find and Replace ****************************************************** """ text = raw_input("1. Enter the string that you'd like to find: ") replacement = raw_input("\n2. What would you like to replace '%s' with: "%text) path = raw_input("\n3. Enter the path where the program should run: ") print # " " is not required. for root, dirs, files in os.walk(path): for fname in files: filename = os.path.join(root,fname) fd = file(filename, 'r') data = fd.read() fd.close() if string.find(data, text) >=1: data = data.replace(text, replacement) fd = file(filename, 'w') fd.write(data) fd.close() print "Replacing '%s' with '%s' in '%s'" % (text, replacement, fname) print """ ********** Done ********** """ # Note: I haven't tested the changes. Hope that's useful, Sean From skip at pobox.com Mon Aug 18 16:44:18 2003 From: skip at pobox.com (Skip Montanaro) Date: Mon, 18 Aug 2003 15:44:18 -0500 Subject: SWIG typemap leading to a memory leak In-Reply-To: References: Message-ID: <16193.15010.34326.558983@montanaro.dyndns.org> You need to DECREF the result of PyInt_FromLong(key): typemap(out) int { int key; PyObject *obj; $result = PyDict_New(); for(key=0; key < $1; key++) { obj = PyInt_FromLong(key); /* obj has a refcount of 1 */ PyDict_SetItem($result, obj, obj); /* obj has a refcount of 3 */ Py_DECREF(obj); /* obj has a refcount of 2 because of its use in the dictionary */ } } PyDict_SetItem will bump the reference counts of the objects you pass into it. When the dictionary goes away, it does its DECREFs, but all those integers still have non-zero reference counts as a result of their initial creation by PyInt_FromLong. You have to take care of that. Skip From pyguy30 at yahoo.com Fri Aug 8 16:30:15 2003 From: pyguy30 at yahoo.com (john) Date: 8 Aug 2003 13:30:15 -0700 Subject: pytunnel 0.21 and urllib3.py Message-ID: <3d46c852.0308081230.16d60834@posting.google.com> pytunnel has been further updated with .netrc support and a automatic shutdown of the standalone process after it's been idle. As an example, I've also just started a wrapper for urllib2.py, for lack of a better name, I've called it urllib3.py. It ultimately calls urllib2.py to do the heavy lifting but first sets up up a tunnel (via by pytunnel). You would use it like: import urllib3 print urllib3.urlopen('https://login.yahoo.com/',ssl='proxy_server').read() The ssl option tells urllib3 to setup a tunnel with proxy_server. Both programs are at: http://savannah.nongnu.org/download/pytunnel/urllib3.py http://savannah.nongnu.org/download/pytunnel/pytunnel.py What is pytunnel? Pytunnel is a program that tunnels TCP/IP through another server like a proxy. A typical use would be to tunnel through an http proxy. Pytunnel supports basic http proxy authentication. Pytunnel allows your software to connect to the local tunnel rather than connecting to the remote server directly. For example, if doing SSL, instead connecting to the webhost on port 443 you connect to localhost using the locally determined port. Pytunnel makes use of several technologies asyncore, threads, and non-blocking sockets w\a custom recv_all to take advantage of that. The tunnel has no knowledge of the protocol being tunneled through it, instead, it keeps the tunnel alive as long as any bit of data, now matter how tiny, comes across it. Once the data stops after a user defined timeout, tunnel shuts down. This program can be either used as a library or standalone tunnel. john From altis at semi-retired.com Thu Aug 28 02:15:09 2003 From: altis at semi-retired.com (Kevin Altis) Date: Wed, 27 Aug 2003 23:15:09 -0700 Subject: My future Python IDE article References: Message-ID: "David Mertz" wrote in message news:mailman.1061920192.21278.python-list at python.org... > Pythonistas, > > My loyal fans :-) will remember that I did a Python IDE roundup for > _Charming Python_ a couple years back. Now I have another such roundup > lined up... not the very next article, but it's there on the list. > > In the intervening years, I've hardly touched anything one might call an > IDE. I've looked at screenshots from time to time, and read various > announcements. But really I just use text editors and command lines. > > Here's the thing: I probably have room to look at about four different > tools in one article. In fact, it wouldn't be absurd to only do three. > Past that, I cannot do more than list contact information and platform > in the available words. I'm sure there are more than four IDEs that > -someone- loves to work with out there... but I need to have a cutoff. > > So c.l.py readers... make the case for your favorite one getting on the > list. I have a while to ponder the opinions advanced, should this > prompt some discussion (it may take a little while to order review > copies of commercial tools and/or get things installed). > > Yours, David... So, I guess the key question is what features are required to be considered an IDE? If you're simply talking about an editor with an integrated debugger then there is a lot to choose from and certainly IDLE (formerly IDLEfork should be included) just for completeness. Based on the responses to c.l.py a lot of people seem to think vim and Emacs qualify as IDEs, but those would probably be best covered in their own articles. Just out of curiosity, I checked the "definition" of an IDE. http://dictionary.reference.com/search?q=interactive%20development%20environ ment One thing I've found quite interesting about Python is that when I started using it I was disappointed in the debugger support, since I was used to more elaborate systems from my compiled language days. There is also the pro blem that many Python editors/IDEs including the old IDLE couldn't debug GUI code if the IDE used a different toolkit than your app (tkinter, win32, wxPython, Qt, etc.) Then I realized that at least for the kind of GUI work I do the debugger fell into the YAGNI category and I end up doing most of my exploration in the shell at runtime or using print or log statements for other bits. It will be interesting to see whether the ability to set breakpoints and do other debugger sorts of things becomes more important to me in the future. Some people seem to think an IDE means integrated layout capabilities. That would narrow the field considerably. Boa should be considered in your selections regardless of whether its wxPython GUI capabilities are needed. PythonCard, at least in its current form doesn't really qualify as an IDE since the codeEditor is just a source editor, it doesn't have a debugger and it is not integrated with the resourceEditor which handles layouts. A future version will have a more integrated environment. ka From tjland at iserv.net Wed Aug 27 11:27:19 2003 From: tjland at iserv.net (tjland at iserv.net) Date: Wed, 27 Aug 2003 11:27:19 -0400 (EDT) Subject: Tkinter? Message-ID: <35320.216.120.186.2.1061998039.squirrel@webmail.iserv.net> Does anyone know a really good tutorial into Tkinter because i want to learn it. One that is more user friendly would be nice. Thanx in advance. When you see the net take the shot When you miss your shot shoot again When you make your shot you win! Just remember Offense sells tickets But defense wins championships! From rdacker at pacbell.net Mon Aug 11 12:39:44 2003 From: rdacker at pacbell.net (rdack) Date: 11 Aug 2003 09:39:44 -0700 Subject: dist problem on osx References: <644f6688.0308101518.ad9e02a@posting.google.com> Message-ID: <644f6688.0308110839.606ed7c9@posting.google.com> rdacker at pacbell.net (rdack) wrote in message news:<644f6688.0308101518.ad9e02a at posting.google.com>... > osx 10.2.6 python 2.2.1 (built in) > says my architecture is both 386 and ppc. > also has a path with a space in it that won't work. > where can i change these settings? > -------- i have been informed that this is a bug in dist-utils that is fixed in python 2.3 From newsgroups at jhrothjr.com Tue Aug 19 20:46:15 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Tue, 19 Aug 2003 20:46:15 -0400 Subject: for statement list comprehension-like extention proposal References: Message-ID: "Ryan Lowe" wrote in message news:zjz0b.126468$_R5.47127053 at news4.srv.hcvlny.cv.net... > i thought id ask here before wirting a PEP, if people thought it would be a > good enhancement to allow if clauses in regular for-statements like so: > > >>> for x in y if x < 10 : > > is semantically equivalent to > > >>> for x in [x for x in y if x < 10] : > > but is shorter and easier to read. basically, the if works as a filter for > the values in the iterator. its not a major change, purely syntactic sugar. > and clearly backwards-compatible. > > seem reasonable? It doesn't do anything for me. I actually find it harder to read: the brackets at least guide my eyes to the various parts of the line, which the form you propose doesn't do. Also, its most definitely not backwards compatible, and I wish you wouldn't send three duplicate messages to the newsgroup with different headers but the same body. John Roth > > ryan > > From tzot at sil-tec.gr Fri Aug 1 10:21:06 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Fri, 01 Aug 2003 17:21:06 +0300 Subject: anti-aliased 2D vector graphics References: Message-ID: On Fri, 01 Aug 2003 07:57:29 GMT, rumours say that "Andy C" might have written: >Where can I get a python package to draw such figures? I googled and found >PyX, I guess it outputs PostScript. I guess I can get a PostScript to BMP >converter or something. Is there any other alternative? > >I have looked at PIL, but it doesn't seem to support drawing anti-aliased >figures. Thanks for any suggestions. Use PIL, and draw on an image twice the size (2*width, 2*height) as the one you want. When you're done, resize the image --BILINEAR works fine in this case. You will need to draw thicker lines & arcs (I don't remember ATM if you can use a parameter with drawing methods)... create a custom class to manage drawing double lines and arcs / circles when needed. -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From jjl at pobox.com Wed Aug 20 19:08:00 2003 From: jjl at pobox.com (John J. Lee) Date: 21 Aug 2003 00:08:00 +0100 Subject: What's better about Ruby than Python? References: <9755kv4bku839cpsqrvch13504qagg7gev@4ax.com> <87oeykb22l.fsf@pobox.com> Message-ID: <87vfssylkf.fsf@pobox.com> aahz at pythoncraft.com (Aahz) writes: > In article <87oeykb22l.fsf at pobox.com>, John J. Lee wrote: > > > >Rest assured, *definitely* no relation. :-) > > No relation to what? T*m*t*y R*e. Did I miss something? John From nplejic.remove at programiranje.nospam.net Thu Aug 14 09:21:23 2003 From: nplejic.remove at programiranje.nospam.net (Nikola Plejic) Date: Thu, 14 Aug 2003 15:21:23 +0200 Subject: Error solution References: Message-ID: In news:mailman.1060852019.2478.python-list at python.org, Sanjeev Trehan wrote: > Dear All, > I am a new to Python,just started few days back.I have installed > Python23.exe.Also downloaded the totorial of Guido van Rossum > Fred L. Drake, Jr., editor Release 2.3 > July 29, 2003 > > When I write in command line the following eoors come: >>>> print a I think you are trying to print a content of the variable "a" but you haven't declared the variable... Try this: >>> a = 2 >>> print a 2 Altough the error message doesn't really point to this error, it is a possible cause for your test not to work. -- Greets, Nikola ( http://zweistein.cjb.net ) From kburrows at senet.com.au Wed Aug 6 08:53:07 2003 From: kburrows at senet.com.au (Kevin Burrows) Date: Wed, 06 Aug 2003 12:53:07 GMT Subject: Tkinter programming problem References: <2830c89c.0308010048.403a2a19@posting.google.com> <2830c89c.0308040201.7c70695d@posting.google.com> Message-ID: <3f305c09.4980094@news.senet.com.au> If I follow this thread correctly we are discussing how the exit from Python/Tkinter programs. As it happens I have beed experimenting with these environments and have struck the same problem.Examples from "Python and Tkinter Programming" by John E Grayson. These examples fire up OK but when the Quit button is hit the window freezes. If the X in the window corner is hit first the application exits correctly. Several suggestions have been suggested. I have experimented with the following program: #!/usr/local/bin/python from Tkinter import * # Interface to Tk widgets class Application(Frame): def __init__(self, master=None): Frame.__init__(self, master) self.grid() self.createWidgets() def createWidgets(self): self.quitButton = Button ( self, text="Quit", command=self.quit ) self.quitButton.grid() def quit(self): print sys.platform print "Quitting" self.quit #--DOES NOT QET RID OF WINDOW # sys.exit(0) #--DOES NOT GET RID OF WINDOW # self.master.destroy() #--GETS RID OF WINDOW app = Application() # Instantiate the application class app.master.title("Sample application") app.mainloop() # Wait for events I changed commented out 2 of the 3 methods in the "quit" function under PythonWinIDE, IDLE and Windows using a .pyw extension. The results of the quit methods were: PythonWinIDE IDLE Windows using a .pyw extension quit No No No sys.exit No No Yes destroy No No Yes Interstingly the application does not freeze under IDLE and can still be closed with the windows X. I am using Windows 98 and Python 2.2 So it looks like "destroy" is the method that works. It is interesting that the example and test in the Tkinter.py module use the "destroy" method but Grayson uses "quit" in his examples. Perhapse the problem with "quit" is a MS Windows thing. I would be interested to here if the same thing happens under Unix et. al. Kevin On Tue, 05 Aug 2003 09:40:55 +0200, Eric Brunel wrote: Most deleted >> def quit(self, event): >> print"Quitting..." >> self.master.destroy() # Destroy root window > >This may also work, but the most common way is the one I describe above. If you >want to do it here, you can do: > >def quit(self, event): > print "Quitting..." > self.master.quit() > >AFAIK, all Tkinter widgets have a quit method that will quit the Tk mainloop. > >HTH >-- >- Eric Brunel - >PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com > From mwh at python.net Wed Aug 27 14:20:46 2003 From: mwh at python.net (Michael Hudson) Date: Wed, 27 Aug 2003 18:20:46 GMT Subject: newbie References: Message-ID: <7h3k78z6k34.fsf@pc150.maths.bris.ac.uk> Rich writes: > I have just downloaded the software from the "Python" site, so I can > learn how to program,or at least start to learn. > > What should be my next move? should I wade through the site, or are > there some exercise I might get into? If http://www.python.org/topics/learn doesn't suit, those who maintain it would like to know why not! Cheers, mwh -- 3. Syntactic sugar causes cancer of the semicolon. -- Alan Perlis, http://www.cs.yale.edu/homes/perlis-alan/quotes.html From detlefsend at enovatia.com Thu Aug 7 11:50:10 2003 From: detlefsend at enovatia.com (David Detlefsen) Date: Thu, 07 Aug 2003 11:50:10 -0400 Subject: Freeze Question In-Reply-To: <16174.45250.408648.333929@montanaro.dyndns.org> Message-ID: On 8/4/03 3:15 PM, "Skip Montanaro" wrote: Thanks Skip for the following.... > I think Modules/Setup is about it. If I had to do this today, here's what > I'd do. > > 1. Starting from a clean source tree, run the 'script' command to get > a log of the session in a file named 'typescript'. > > 2. Exit the script session. > > 3. Run the usual 'configure ; make' commands. > > 4. Edit Modules/Setup, uncommenting those modules which you want built > statically. Many are simple and require no extra compile or link > flags. For others, use the build commands found in the typescript > file to identify -I..., -L..., and -l... flags. Obviously, omit or > modify any flags that would be used to generate a shared library > (-shared, -Bshared, -fPIC, etc). > > 5. Run 'make clean ; make' > > 6. Test the resulting executable. > > 7. Repeat steps 4-6 as necessary. > > 8. Congratulate yourself on a job well done and buy yourself a beer. I'm to the point where two modules are not found by freeze: Warning: unknown modules remain: pcre strop There is no mention of these in my Modules/Setup file. Any suggestions. Dave From dtolton at yahoo.com Tue Aug 12 02:23:08 2003 From: dtolton at yahoo.com (Doug Tolton) Date: Tue, 12 Aug 2003 06:23:08 GMT Subject: Python vs. C# References: <3F378923.4080806@mxm.dk> Message-ID: On Mon, 11 Aug 2003 14:16:35 +0200, Max M wrote: >Bob Gailer wrote: > >> What is "trolling"? >> > > >http://www.urban75.com/Mag/troll.html > > >regards Max M Ugh...he got me. Crap. Doug Tolton From grey at despair.rpglink.com Mon Aug 11 00:31:53 2003 From: grey at despair.rpglink.com (Steve Lamb) Date: Mon, 11 Aug 2003 04:31:53 -0000 Subject: [wxPython] Updating the status bar? Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Ok, this one I did try before coming here... :) I am trying to report the status of what is going on to the status bar of the main window of my wxPython app. I know I'm on the right track with SetStatusText() but it doesn't always alter the text. What the program is doing is taking a filename and passing it through two different external programs. One of them is taking a little bit of time to process the file (sa-learn) so the user needs to know what is going on. Right now I have the call to update the status bar preceding the external call like so: self.MainStatus.SetStatusText('Reporting message as spam.',0) code = os.system("%s '%s'" % (vars.razor_spam, filepath)) The status bar is not being updated. I know it works because other calls I have to the same method work fine. Is there some call I need to make to refresh the window or at least the status bar? -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (GNU/Linux) iD8DBQE/Nxw5el/srYtumcURAkUaAKCsZep0u8rjIalqXYJ4+8BbeqmdVgCfRbYx 3vIlOU4xsEXlLQI5+3Q74Dc= =4EQS -----END PGP SIGNATURE----- -- Steve C. Lamb | I'm your priest, I'm your shrink, I'm your PGP Key: 8B6E99C5 | main connection to the switchboard of souls. | -- Lenny Nero - Strange Days -------------------------------+--------------------------------------------- From revyakin at yahoo.com Sun Aug 10 21:13:53 2003 From: revyakin at yahoo.com (revyakin) Date: 10 Aug 2003 18:13:53 -0700 Subject: python spam filter: random words? Message-ID: I know fighting spam is like fighting global worming, but still.. 50% of spam I get these days contains a random combination of letters at the end of the subject line. Has anyone tried using that feature in antispam filters? Since python is the only lang I am more or less fluent in as an amature scripter, I was wondering if anyone in this goup has comments on this idea. Also, is it reivial make a python script filter executable from a generic mail program like OE, or NS messenger? I am also wondering why spammers add that stuff to their subject lines anyway. From msolem at firstlinux.net Wed Aug 13 20:23:14 2003 From: msolem at firstlinux.net (Mike solem) Date: Thu, 14 Aug 2003 00:23:14 GMT Subject: Getting a data structure Message-ID: <1103_1060820563@news-server.optonline.net> I need to pass a data structures from a C program, to a python program over RS232. I'm not quite sure how to recreate a data structure from a string of serial data. In C I would do it like this: ---------------------- This compiles under gcc ---------- #include typedef struct{ int a; char b; }myStruct; int main() { char data[]= {1,2,3,4,5,6,7,8,9}; myStruct* s1; s1 = (myStruct*)&data; printf("%x %d\n", s1->a, s1->b); return 0; } -------------------------------------------- The 'data' array above would be a buffer which receives data from the serial link. So the questions are, what type of python data stucture to use, and how to initialize it from the buffer. The struct I'm using is a lot more complex than the one I used here. It's built up of a couple of other structs. Thanks Mike From grey at despair.rpglink.com Sat Aug 9 13:51:49 2003 From: grey at despair.rpglink.com (Steve Lamb) Date: Sat, 09 Aug 2003 17:51:49 -0000 Subject: TKinter, PyQT and wxPython (BOA) References: Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Tue, 05 Aug 2003 03:06:21 GMT, Keith Jones wrote: > You didn't mention PyGTK, which you can use with glade; just thought > I'd mention that. Well, technically, he did. BOA = Boa-Constructor = wxWindows = PyGTK on Linux. Personally I just built my very first GUI app in any language using Boa-Constructor. It was also my very first wxPython app. The total time to get the shell up and running to my satisfaction with all the elements in place was about 6-7 hours. That's learning Boa, wxPython and the basics of how to put together a GUI as well as the actual deed of doing it. Boa is beautiful even though at v0.2.3 it is still listed as Alpha. The Linux version has some problems (typical GTK font bug) but is usable and builds the shell of the application nicely. wxPython gives a great interface and while the documentation is geared for the C++ implementation of the same toolkit (wxWindows) I've had very little problems getting any documented feature I need working. I can't imagine any other combination being as easy as this has been. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (GNU/Linux) iD8DBQE/NTS1el/srYtumcURAnLbAJ9yRc1ot6RMrKx6n/MgKAgfnasgMwCfbK3d WxH4M4FT2ngSClUklXnXYsM= =H2cn -----END PGP SIGNATURE----- -- Steve C. Lamb | I'm your priest, I'm your shrink, I'm your PGP Key: 8B6E99C5 | main connection to the switchboard of souls. | -- Lenny Nero - Strange Days -------------------------------+--------------------------------------------- From ma at Bell.com Mon Aug 18 18:23:38 2003 From: ma at Bell.com (xam) Date: Mon, 18 Aug 2003 22:23:38 GMT Subject: a twisted question Message-ID: Hi All, I have got a bit of a complicated situation here: I need to get buildBot (and hence twisted) running on RH 7.1, which currently has python 1.5 installed. From browsing newsgroups it appears that I cannot overwritte 1.5 due to some RH scripts relying on that version. So: 1) can twisted run on 1.5? I could not find this info in the docs. 2) if not, can it run on parallel-installed later version? 3) if so, could someone give me a hint on installing a parallel version? thanks, max. From vanevery at 3DProgrammer.com Tue Aug 12 15:43:28 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Tue, 12 Aug 2003 12:43:28 -0700 Subject: Why Python needs to market itself References: <23891c90.0308120740.3a771ff6@posting.google.com> Message-ID: Paul Boddie wrote: > > I think you should stop trying to think of all this as an > intellectually lightweight corporate strategy meeting where we have to > agree on some kind of marketing campaign that actually does nothing > more than prop up the advertising profession whilst making complete > fools out of everyone involved. It's actually not my thinking. I really think all the technocrats around here are the marketing lightweights. I have a very clear picture of what makes it down the corporate value chain, which is why I'm highlighting your post: > What does stop Python from being recognised and adopted is the lack of > awareness that people have, and it is true that part of this lack of > awareness is down to a lack of brochures arriving on the desks of > salespeople and strategists. Nevertheless, demonstrated successful > systems have a more powerful impact on those whose money is ultimately > being spent on new software - the customers. Because as their > competitors demonstrate working systems that give them productivity > benefits, they can turn to vendors and say, "Stop trying to sell us > buzzword X - just give us something like our competitors are using!" > > The more I think about it, the more I realise that many customers > probably don't care whether you've used the latest stuff from > Microsoft or not (although they might be a bit concerned about the > licensing schemes), and the more I realise that it must be the various > bandwagons that "inform" certain parts of the "decision chain" that > create this downward pressure on people to write all their stuff in C# > or . With you so far. > As the balance of power shifts away > from the vendor to the customer, however, I think you'll start to see > the smart vendors adapt and start to discover what actually works, > both from their customers and the people on the ground actually doing > the work, and they'll cut out the brochure trail as they realise that > it doesn't really help them to make money and satisfy customers at the > same time. Not in the absence of marketing. Keep in mind, Linux is marketed. > P.S. If you're really interested, there's a marketing/promotion > interest group for Python. The details are out there on the Web, so if > it's important to you, I'm sure you can dig them out. Actually, I would be interested in their opinions of the Python community, if they're willing to give them. And maybe they'd be interested in an outsider's perception of the Python community. It is, after all, people like me that have to be sold in order to grow the market. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From fredrik at pythonware.com Wed Aug 27 10:50:12 2003 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 27 Aug 2003 16:50:12 +0200 Subject: mpeg problem with pygame References: Message-ID: "AnsNum" wrote: > when I start this program, the movie doesn't play smoothly, anybody has an > idea ? > (I use windowsXP) > > import pygame > from pygame.display import flip > from pygame.locals import * > > pygame.init() > screen = pygame.display.set_mode((640,480)) > pygame.mixer.quit() > movie = pygame.movie.Movie("d://pygame//video3.mpeg") > movie.set_display(screen, (0,0)) > movie.play() > movie.set_volume(1) > flip() > while 1: > if not movie.get_busy(): > break just guessing, but that busy loop might suck up more spare cycles than you have. try inserting a short sleep: while 1: if not movie.get_busy(): break time.sleep(0.1) From zathras at thwackety.com Mon Aug 18 16:13:38 2003 From: zathras at thwackety.com (Michael Sparks) Date: Mon, 18 Aug 2003 21:13:38 +0100 (BST) Subject: What's TOTALLY COMPELLING about Ruby over Python? In-Reply-To: Message-ID: On Mon, 18 Aug 2003, Brandon J. Van Every wrote: > What's ***TOTALLY COMPELLING*** about Ruby over Python? You can create lasers using rubies I believe whereas pythons are simply cute. Michael. (Since this is clearly a troll :) From rganesan at myrealbox.com Thu Aug 28 05:18:35 2003 From: rganesan at myrealbox.com (Ganesan R) Date: Thu, 28 Aug 2003 14:48:35 +0530 Subject: Script Discussion & Critique References: <3F4D31B1.6080802@hotmail.com> <06eqkv4onjh5m4tcbbqkmh8lscaj5niatp@4ax.com> <3F4D4402.3060209@hotmail.com> Message-ID: >>>>> "hokiegal99" == hokiegal99 writes: > Is this script written well? Is it a good design? How could it be made > better (i.e. write to a file exactly what the scipt did)? I hope to > use it to recursively find a replace strings in all types of files > (binary and text). > Thanks for any ideas, pointers or critique... most of the ideas behind > the script came from the list. Others have done an excellent job of telling you the problems of critiquing your code. I'll try to address one point that others haven't covered already. > print " " > print "******************************************************" > print " Three Easy Steps to a Recursive find and Replace " > print "******************************************************" > print " " > x = raw_input("1. Enter the string that you'd like to find: ") > print " " > y = raw_input("2. What would you like to replace %s with: " %x) > print " " > setpath = raw_input("3. Enter the path where the prgroam should run: ") What you've done is not wrong. But it's simpler to replace all that with import sys x = sys.argv[1] y = sys.argv[2] setpath = sys.argv[3] so that you can run it as "python myscript.py ". This way you can easily call your script from another program and makes it much more useful. You can do something like if len(sys.argv) >= 1: x = sys.argv[1] y = sys.argv[2] setpath = sys.argv[3] else: raw_input(...) ... and get the best of both worlds. Ganesan -- Ganesan R From thor__00 at yahoo.com Tue Aug 19 09:48:08 2003 From: thor__00 at yahoo.com (Thor) Date: Tue, 19 Aug 2003 15:48:08 +0200 Subject: Functions References: Message-ID: Thanks to both. Of ourse the parentheses thin was worng, I was just trying to make the most symplified code. I tt was just one possibility that arose from the code I was doing. -- Thor -- Stockholm -- Sverige From klapotec at chello.at Mon Aug 4 04:28:25 2003 From: klapotec at chello.at (Christopher Koppler) Date: Mon, 04 Aug 2003 08:28:25 GMT Subject: [OT] Google URLs (was Re: popen eating quotes?) References: <20030803202417.GA10412@unpythonic.net> Message-ID: On Sun, 3 Aug 2003 17:45:00 -0600, Steven Taschuk wrote: >Quoth Jeff Epler: >> http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&threadm=0000161b%40bossar.com.pl&rnum=1&prev=/groups%3Fq%3Dshell%2Bquoting%2Bnt%2Bgroup:comp.lang.python%26hl%3Den%26lr%3D%26ie%3DUTF-8%26selm%3D0000161b%2540bossar.com.pl%26rnum%3D1%26filter%3D0 >> [apologies for the long URL, I don't know how to get a good memorable >> URL for a google groups search] > >Not memorable, but at least shorter, is > >In general all you need is the threadm or selm parameter, which >gives the message-id of the post in question; if memory serves, >threadm and selm differ in whether the resulting page shows the >rest of the thread. > >(Ignore the selm in your URL above; it's inside the prev >parameter, which stores information about where you were before >arriving at the page the URL is actually for.) > >It seems that Google also assigns an id to each thread; with >suitable poking around (see, e.g., the source for the page at the >above URL) you can locate a 'th' parameter which can be used in >place of the threadm/selm parameter if you wish to refer to the >thread as a whole. In your case that's > >(As this illustrates, the resulting URL is often shorter than one >using the message-id.) The first ten messages in the thread >appear on the page obtained thus, with anchors, so you can refer >to them individually by appending '#link1', '#link2', etc. This >makes nice short URLs too (though I'm not certain that *which* >messages such anchors refer to is constant over time as the thread >grows). > >All discovered empirically. Use at your own risk. If all you want is a short URL for posting, have a look at http://tinyurl.com/ Jeff's *long* URL would then be: http://tinyurl.com/iy1q --Christopher From mis6 at pitt.edu Sat Aug 23 05:06:37 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 23 Aug 2003 02:06:37 -0700 Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> <6dj2kv8ugkieehs7guh786cl40o5lj6mcs@4ax.com> Message-ID: <2259b0e2.0308230106.7eeec174@posting.google.com> Hans Nowak wrote in message news:... > One of Python's strengths is that you can create powerful abstractions with > functions and classes. But no matter what you do with these, they will always > be functions and classes that adhere to some common language rules. There is > no way to go "over the top" and change the language proper. This is a mere illusion. There are metaclasses and descriptors now. > Right now I can > read everybody's Python code (unless deliberately obfuscated); this would > change if there were macros that were so powerful that they would change > language constructs, or allow new ones. Maybe they would make your problesm > easier to solve, but Python itself would lose in the long run. > > My $0.02, We already have things worse than macros. Still I am not suggesting we should add them, because of KISS. But the idea of Python being well behaved is a mere illusion, however well kept. See my other posts on "macros revisited" for more on this. Michele Simionato, Ph. D. MicheleSimionato at libero.it http://www.phyast.pitt.edu/~micheles --- Currently looking for a job --- From vanevery at 3DProgrammer.com Mon Aug 18 03:34:11 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Mon, 18 Aug 2003 00:34:11 -0700 Subject: What's better about Ruby than Python? References: Message-ID: Graham Fawcett wrote: > Brandon J. Van Every wrote: > >> What's better about Ruby than Python? > > You're never going to get an answer to this question that satisfies > you. Even if everyone chips in and describes their favourite > features, those features may be worthless to you personally. So why > bother asking? You assume too much. My attitudes and criteria aren't yours. I ask because it's useful to me, not because it's useful to you. > Try the languages out yourself, both of them; program a non-trivial > application in both languages. I frankly don't have the time, and am not afraid to leverage other people's experiences to some degree. > Exactly: so don't ask for others' ideas. You have a profound difference of philosophy that I don't share. You seem to think other people's opinions are all or nothing. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From R.Brodie at rl.ac.uk Mon Aug 11 09:01:20 2003 From: R.Brodie at rl.ac.uk (Richard Brodie) Date: Mon, 11 Aug 2003 14:01:20 +0100 Subject: Fun with numbers - dammit, but I want a cast! References: <3f378fac$0$10778$afc38c87@auth.uk.news.easynet.net> Message-ID: "Graham Nicholls" wrote in message news:3f378fac$0$10778$afc38c87 at auth.uk.news.easynet.net... > I've tried doing img_x=1.0 to force it to be a float, but I'm getting a bit > frustrated as it seems to make no difference - once image.getsize returns > the (integer) value of the x size, it simply converts back to an int. Yes. Types are properties of values, not names. There is no implied declaration: you can assign a float to img_x then later an int, string, function or whatever. To get floating point division you can use a cast like syntax, by using the builtin float() function. >>> 1 / 2 0 >>> float (1) / float(2) 0.5 In future versions of Python, / will become a floating point division operator. // will be used for truncating division. For compatibility, you need to explicitly enable the new behaviour at present, either with a from __future__ or a -Q option. These activate Guido's famous time machine, which add new features to Python before you ask for them. >>> from __future__ import division >>> 1 / 2 0.5 >>> 1 // 2 0 U:\>python -Qwarn ActivePython 2.2.2 Build 224 (ActiveState Corp.) based on Python 2.2.2 (#37, Nov 26 2002, 10:24:37) [MSC 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> 1/2 __main__:1: DeprecationWarning: classic int division 0 From mis6 at pitt.edu Sat Aug 23 03:59:46 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 23 Aug 2003 00:59:46 -0700 Subject: For Kenny Tilton: Why do I need macros revisited. References: <3f45484f$1_6@corp.newsgroups.com> <3F45A7BF.4060806@nyc.rr.com> <8dk1b.2825$Ej6.1159@newsread4.news.pas.earthlink.net> Message-ID: <2259b0e2.0308222359.4a2edacf@posting.google.com> "Andrew Dalke" wrote in message news:<8dk1b.2825$Ej6.1159 at newsread4.news.pas.earthlink.net>... > Kenny Tilton: > > You are absolutely right. Metaclasses are killer. I am surprised > > Pythonistas afraid of macros let them into the language! > > Speaking personally, I still haven't wrapped my head around > them, and despite seeing Alex's talk about them, don't fully > understand when to use them. I've seen David Mertz' xml_pickle > code which makes good use of them, but don't yet follow > how it works. I was in your situation some time ago and actually I was sceptical about the usefulness of metaclasses. Then, I got the metaclass book. It made the click. Notice that it is a C++ book, of little use to a Pythonista, nevertheless it provides lots of use case and compelling (at least for me) motivations for metaclasses. It is easier to study something if you understand what is for ;) BTW, I got it used from Amazon.com, $10. It is cited in the references of http://www-106.ibm.com/developerworks/library/l-pymeta.html so you should be able to find it. Alex Martelli has a very advanced set of slides on metaclass, but I haven't the URL here (Alex, do you here me ?) Michele Simionato, Ph. D. MicheleSimionato at libero.it http://www.phyast.pitt.edu/~micheles --- Currently looking for a job --- From trimtab at mac.com Thu Aug 21 10:31:08 2003 From: trimtab at mac.com (Olivier Drolet) Date: 21 Aug 2003 07:31:08 -0700 Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> <6dj2kv8ugkieehs7guh786cl40o5lj6mcs@4ax.com> <599a6555.0308202108.397bb1a0@posting.google.com> Message-ID: <599a6555.0308210631.441f76cd@posting.google.com> Really cute intuition pump you've got there, Alex! :-) Obviously, no programmer of Python, Lisp, Java, etc., would ever want to deal with code in their preferred computer language where every token and glyph belonged to a foreign language (i.e., of which they are not a competent locutor). That goes without saying, but your point is noted nonetheless. Macros don't require that you change variable names, just the syntax. Macros in Python would then not be equivalent to new words, but new constructs. And yes, you need to know their meaning, but is this effort greater than managing without them? Have you or any opponents of macros on this news group never seen a context in which the advantages of macros outweigh their overhead? "Andrew Dalke" wrote in message news:... > Olivier Drolet: > > Macros, as found in Common Lisp, do not change (...) > words from different Dialects of Speech? > > Andrew > dalke at dalkescientific.com From python-url at phaseit.net Mon Aug 18 00:38:58 2003 From: python-url at phaseit.net (Irmen de Jong) Date: Mon, 18 Aug 2003 04:38:58 -0000 Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Aug 17) Message-ID: QOTW: "The best use for a bug report on comp.lang.python is as an object lesson for your grandchildren: 40 years from now you can search the archives for it, and tell the little darlings 'see? if I had only put that on SourceForge instead, the bug would have been fixed by now'." -- Tim Peters [on the subject of a tree datastructure that consisting of dicts] "I thought we made dictionaries out of trees... Are you trying to reverse entropy? " -- Bob Gailer Discussion ---------- It was an entertaining week on comp.lang.python. Have a look at these links: Graham Fawcett is one of the people proposing nice new Python slogans. Michael Sparks has ideas about what we should do to 'displace java', which somehow also involves SCO ;-) Theodor Rash has a warning for us in a discussion about Python vs. C#. Some people may agree that it is appropriate, others may find that a few interesting points are actually being discussed... Thankfully, serious discussion took place as well ;-) Is the tilde operator ~ acting weird as a bitwise not operation? Tim Peters explains that it doesn't. Related to this, an old (but handy) function to print numbers in binary: The age-old 8-queen-problem sticks up its head again. Bengt Richter is on the loose with several interesting variatons. For those that have some free time left this summer, Raymond Hettinger suggests some interesting reading material, somewhere in Python's standard library source code. Alex Martelli provides the 'real' powerset function. Interesting thread about the new sets module by the way. Gerhard Haering shows that it is very easy to run Python off a Windows network share, instead of a local directory on your own harddisk. Andrew Dalke and Aahz take __call__ apart. Calling stuff in Python is rather complicated under the hood, it seems... or isn't it? Releases -------- Pyro 3.3, an advanced and powerful Distributed Object Technology system written entirely in Python, and designed to be very easy to use. ClientCookie 0.4.4a and ClientForm 0.1.7b, modules for handling cookies and HTML forms on the client side (useful for simulating a browser). dnspython 1.1.0, a DNS toolkit. eGenix mx packages: mx BASE 2.0.5 (various utilities including mxDateTime), mx Experimental 0.8.0 (experimental tools), mxODBC 2.0.6 (ODBC connectivity). yawPyCrypto 0.1.1, a facade for the PyCrypto library. Flatten 0.2, a serialization library with a secure pickling algorithm, especially well suited for network transport of data. KirbyBase 1.3, a simple, pure-python, flat-file database mgmt system. SCons 0.91 beta, a software construction tool (build tool, or make tool) written in Python. PyTables 0.7.1, a hierarchical database package to organize and manipulate scientific data tables as well as Numeric and numarray data objects that reside on disk. Retic 0.1, an EAI Server written in Python. It permits to build adaptors (data flows) with three types of components : sources, pipes and sinks. ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the daily python url http://www.pythonware.com/daily Mygale is a news-gathering webcrawler that specializes in (new) World-Wide Web articles related to Python. http://www.awaretek.com/nowak/mygale.html While cosmetically similar, Mygale and the Daily Python-URL are utterly different in their technologies and generally in their results. comp.lang.python.announce announces new Python software. Be sure to scan this newly-revitalized newsgroup at least weekly. http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce Brett Cannon continues the marvelous tradition established by Andrew Kuchling and Michael Hudson of summarizing action on the python-dev mailing list once every other week. http://www.python.org/dev/summary/ The Python Package Index catalogues packages. http://www.python.org/pypi/ The somewhat older Vaults of Parnassus ambitiously collects references to all sorts of Python resources. http://www.vex.net/~x/parnassus/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ The Python Business Forum "further[s] the interests of companies that base their business on ... Python." http://www.python-in-business.org The Python Software Foundation has replaced the Python Consortium as an independent nexus of activity http://www.python.org/psf/ Cetus does much of the same http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://python.sourceforge.net/peps/pep-0042.html The online Python Journal is posted at pythonjournal.cognizor.com. editor at pythonjournal.com and editor at pythonjournal.cognizor.com welcome submission of material that helps people's understanding of Python use, and offer Web presentation of your work. *Py: the Journal of the Python Language* http://www.pyzine.com Archive probing tricks of the trade: http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python&num=100 http://groups.google.com/groups?meta=site%3Dgroups%26group%3Dcomp.lang.python.* Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://www.ddj.com/topics/pythonurl/ http://purl.org/thecliff/python/url.html (dormant) or http://groups.google.com/groups?oi=djq&as_q=+Python-URL!&as_ugroup=comp.lang.python Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". -- The Python-URL! Team-- Dr. Dobb's Journal (http://www.ddj.com) is pleased to participate in and sponsor the "Python-URL!" project. From gerrit at nl.linux.org Thu Aug 28 01:44:37 2003 From: gerrit at nl.linux.org (Gerrit Holl) Date: Thu, 28 Aug 2003 07:44:37 +0200 Subject: OT: Celebrity advice (was: Advice to a Junior in High School?) In-Reply-To: <3F4D3560.71995AEB@engcorp.com> References: <3F4D0D8B.5E5F9488@engcorp.com> <3F4D3560.71995AEB@engcorp.com> Message-ID: <20030828054437.GB2515@nl.linux.org> Peter Hansen wrote: > Gerrit Holl wrote: > > > > Peter Hansen wrote: > > > But if you refuse to go to prison, things get lethal pretty quickly. > > > That's what "ultimately" refers to above. > > > > Well, I don't think they get very lethal, they get painful at most. > > > > > I think the key word in the above is "ultimately", and > > > I can see why ESR would (I think validly) state what he did above. > > > > Ultimately, the state will use violence. But this violence should not > > have lethal consequences. > > No, you're not taking the word "ultimately" far enough. First the state > tries to get painful on your ass, so you resist. Then they get really > violent, and still you resist. Picture the nature of this resistance, > which usually would have to involve standing up to armed police by > this point. Now tell me how, you plan to avoid *ultimately* getting to > the lethal stage, without giving in first. OK; but the last lethal stage is reached *only* if the civilian involved *also* defends himself with the same means as the government. So, things will get lethal ulmitately *only* if the civilian owns the same arms as the government. Consequently, ESR's statement is only applicable to the situation he promotes. If I resist and keep resisting using only my fists or even a knife, the Dutch police will be able to take me to prison without killing me. A qualified police force should even be able to do this even when I am using a gun, but does not always succeed in this. Gerrit. -- Asperger Syndroom - een persoonlijke benadering: http://people.nl.linux.org/~gerrit/ Het zijn tijden om je zelf met politiek te bemoeien: http://www.sp.nl/ From skchim0 at engr.uky.edu Mon Aug 11 18:49:07 2003 From: skchim0 at engr.uky.edu (satish k.chimakurthi) Date: Mon, 11 Aug 2003 18:49:07 -0400 Subject: PYTHON AND C++ Message-ID: <200308111849.07578.skchim0@engr.uky.edu> Hello all, I am trying to specify an SIDL (Scientific Interface Definition Language) interface to a sophisticated C++ code that I use in my project. I intend to run the code from the python scripting environment. I am trying to use a software by name BABEL (http://www.llnl.gov/CASC/components/babel.html) to generate interfaces for libraries or components specified in the SIDL files. My ultimate intention is to access the C++ code from python. I have looked into automatic and semi-automatic interface generators like SWIG, BOOST.PYTHON and ended up doing nothing useful and so adopted BABEL Can someone advise me if my approach is the right one ?? Did someone do the same kind of stuff and thinks that there is an easier way ?? Thanks for your time and help in advance, With Best Regards, SATISH SATISH K.CHIMAKURTHI GRAD. RESEARCH ASSISTANT UNIVERSITY OF KENTUCKY LEXINGTON KENTUCKY STATE From sross at connectmail.carleton.ca Thu Aug 21 11:42:02 2003 From: sross at connectmail.carleton.ca (Sean Ross) Date: Thu, 21 Aug 2003 11:42:02 -0400 Subject: Which way to say 'private'? References: <14f9kv4fvuf67k6j12lpgt6vk9dcpefchm@4ax.com> Message-ID: "Daniel Klein" wrote in message news:14f9kv4fvuf67k6j12lpgt6vk9dcpefchm at 4ax.com... > There are 2 ways to indicate private members of classes, by prepending > 1 or 2 underscore characters, the latter causing name mangling. My > question is: When would I use which kind to indicate privacy? Hi. The single underscore (self._attribute) is the convention when you wish to indicate privacy. Where by "indicate" I mean that you wish to convey to readers of the code that they should not access this attribute directly. They can, but you are telling them that it's not the best practice for your API. The double underscore (self.__attribute) mangles the name (as you've mentioned), so it adds an extra disincentive to using that attribute directly (at the very least, using instance._ClassName__attribute makes for unattractive code). So, the latter method is used when you would really, really prefer that people not access a particular attribute directly (Nothing is stopping them, of course, but the intention is pretty clear). Also, when someone subclasses your class, it makes accessing the "privatized" attribute a little more difficult. >>> class C1: ... def __init__(self, value=1): ... self.__value = value ... >>> class C2(C1): ... def __init__(self): ... C1.__init__(self) ... >>> c2 = C2() >>> dir(c2) ['_C1__value', '__doc__', '__init__', '__module__'] # ^^^^^^^^^^^ # Here's the "private" attribute Personally, I use single underscore to denote "protected", and double underscore to denote "private" (if I use them at all). HTH Sean From ghowland at lupineNO.SPAMgames.com Sat Aug 23 01:48:22 2003 From: ghowland at lupineNO.SPAMgames.com (Geoff Howland) Date: Sat, 23 Aug 2003 05:48:22 GMT Subject: Modifying the {} and [] tokens References: Message-ID: On Sat, 23 Aug 2003 04:41:20 GMT, "Andrew Dalke" wrote: >Geoff Howland: >> I want to modify the {} and [] tokens to contain additional >> functionality they do not currently contain, such as being able to add >> dicts to dicts, and other things that would be very helpful for me and >> my team mates to have. > >You can't. Not without changing the underlying implementation. The implementation in the C code, or implementation at the Python level? As long as this stays in Python, like as a module that can be included or not, then I think it would be helpful. I think a lot of the things I would like to do might actually be good in the language, but maybe they've already been thrown out, or something. For now, I dont have an entire list and implementation of everything I would like to see to really present as a "possible change list", so I'd just like to be able to do this to assist in my own teams work. There is history and other info beyond this besides "I think it would be neat", but that is team private business so I dont want to drag it out here. This would just be helpful. >> So I can obviously override dict and it works when I specifically call >> dict(), but it does not work with the syntax sugar {}. > >That's because you created a new dict. You didn't modify the >actual type {} uses in the intepreter. {} is not simple syntactic sugar >for dict() in the local namespace. BTW, if it were, then > > dict = 8 > a = {3: 4} > >would fail. Right, so is there a way to change this? I know the syntax I tried doesnt work and for obvious type reasons, since you wouldnt want to do this by accident. Perhaps something has to be registered in some Python variable/class/module-list I am not aware of that would make this happen? I am ok with the consequences of potentially introducing oddities into my code from the Norm for this flexibility. >> How can I make this work? Can this also work to overload strings with >> the "" and '' tokens? > >You can't. What's wrong with using your derived dict? Why must you >use {}? The reason for using it is that it is easier to code using the default containers than having to specify things. IMO, there are some things missing from the language, and while maybe they wont be added, I would like to have them. {} + {}, {} - {}. [] - [], etc These operations would be useful, as well as additional functions that are commonly performed and have to be put in separate modules. I would also like to move all the usual operational functions into some of these, such as instead of len([]), you could do [].len(). More consistent for some of my team to read. If it's impossible without creating a new EXE, then I wont have a choice. If it is not impossible, then I would like to be able to add some things to the standard containers that are already very powerful but seem to be missing some basics to complete their operational sets. >You can't modify the fundamental type used by strings either. I'd have the same questions above for this. :) -Geoff Howland http://ludumdare.com/ From neel at mediapulse.com Tue Aug 19 17:43:27 2003 From: neel at mediapulse.com (Michael C. Neel) Date: Tue, 19 Aug 2003 17:43:27 -0400 Subject: Why does this (not) work? Message-ID: > try this: > >>> "%s - %s - %s" % (("test",)*3) > > why else would > >>> 3 % 1 * 2 > print 0 instead of 1? > > Jeff Hmmm, can't say I like what this implies. In one case % is shorthand for a sprintf function, the other it's a mathematical expression at the same level of precedence of * and /. But the sprintf version is "granted" the precedence of the mathematical version? What's the logic behind that? Oh well, Mike From dtolton at yahoo.com Tue Aug 12 06:02:59 2003 From: dtolton at yahoo.com (Doug Tolton) Date: Tue, 12 Aug 2003 10:02:59 GMT Subject: Python should try to displace Java References: Message-ID: <7pchjvkldv6li5n80p5ra6n33sa6ainut4@4ax.com> On Tue, 12 Aug 2003 01:54:12 -0700, "Brandon J. Van Every" wrote: >Doug Tolton wrote: >> On Mon, 11 Aug 2003 18:43:08 -0700, "Brandon J. Van Every" >>> >>> - in 5 years, nobody will be doing significant amounts of new >>> application development in C++. The writing is on the wall: garbage >>> collection is essential. Any C++ code will be support and legacy >>> libraries. >> >> That's a ridiculous blanket statement. People will be doing C++ >> development for a long time beyond that. There are people still >> writing Cobol for crying out loud. > >Do you honestly believe that people are doing a significant amount of new >application development in Cobol, as opposed to maintenance work? Apparently MS does, they were promoting Cobol.net pretty heavily not too long ago. > >>> - Microsoft is already implementing said strategy across all levels >>> of the company today. Microsoft developers don't do much C++ >>> development anymore. Various upcoming products are being written >>> entirely in C#. >> >> just what we need. More buggy slow products from MS that have >> Memory Leaks the size of the Mississippi. C# is not a good >> development platform yet. Heck they are practically still in the >> standard MS beta period. Everyone knows not to use a MS product on >> version 1.0 > >Ignore the trend at your peril. A MS product is one thing. A MS initiative >across the entire company is quite another. The last time they did that, >Internet Explorer put Netscape in the doghouse. Never, ever, ignore or >diminish what Microsoft decides to do as an entire company. Well, I can pretty much ignore and diminish MS all I want. The only reason they beat Netscape was because of the *incredible* abuse of monopoly powers coupled with the inept decision making of Netscape. Netscape was great when it came out, but over time it started to suck more and more and IE started to suck less and less. It wasn't because MS was had better technology really, they just jacked people on the backend if they ran a Netscape solution. Netscape ran out of money and the ability compete. How are they going to crush Mozilla, Chimera or Khtml? You keep touting Mindshare. Whose mindshare is growing MS or Open Source? If you can't answer that honestly then you really are trolling. > >>> - The "higher level language" playing field is crowded: C#, Java, >>> Perl, and Python. Mainstream industry does not need and will not >>> make room for 4 higher level languages. Any of these languages has >>> to grow at some other language's expense. >> >> This statement is really vague, and has almost no factual basis. If >> there were only four programming languages the world would be a very >> dull place. You forgot to mention Delphi, Visual Basic, Power Builder >> and a host of others. There is room for a lot more than 4 programming >> languages. > >Actually, Visual Basic vs. C# would be a good discussion in another >newsgroup. Because the books about .NET Framework that I'm reading, show >how VB is being modded and borgged to fit the Intermediate Language. Which >is essentially C#. I wonder if it would be reasonable to say that in 5 >years, nobody will be doing new app development in VB, it'll all be C#? But >I'll take that up with the VB crowd. That's good > >>> - Python will never displace C# on Windows. It's Microsoft's home >>> turf and you can't fight directly with The Beast. You will see UNIX >>> boxes running Python, not Windows boxes. >> >> That's a bold statement, considering the abysmal adoption rate of C#. > >Within Microsoft, the adoption of C# is universal. That tends to have a >powerful effect on ISV Windows development over time. Really, who cares what MS does? How does MS using C# affect Python? You have yet to establish any kind of Causal connection. Here it is straight, Python has been around going strong for over 10 years now, inspite of lack of a corporate pimp. Why is that? What is it that MS is *suddenly* doing that is going to kill Python? Why is the Python mindshare going to *suddenly* evaporate and go to C#? You have nothing to back any of those statements up. They are pure unadulterated BS. > >> C# isn't the dominant windows programming language currently, rather >> its Visual Basic. Java has far more applications written for Windows >> than C# does. MS really shot themselves in the foot when they went to >> dotnet, essentially the adopted the Java platform 8 years after Java. >> Now they are playing catchup with an inferior product. I doubt >> they'll ever catch up to Java overall. > >The problem with your thinking here is there's very clear evidence that >Microsoft can and does catch up to and surpass technologies that they have >fumblingly cloned. In fact, that's the basic Microsoft corporate >philosophy. Version 1.0 sucks, 2.0 is ok... 5.0 actually is a really good >product and then the competition can't catch up anymore. Example: DirectX. >When it started it was complete garbage. Nowadays it is technically >superior to OpenGL in most areas. Why they don't finally implement doubles >and put OpenGL out of its misery, I'm not sure. I could be wrong but I didn't think OpenGL was open source. If it isn't, your argument isn't really a good point then. > >Why can MS catch up? Because Open Source people assume their technological >superiority and rest on their laurels. They think they don't have to market >because they are technically superior. Also, their ranks are populated with >strong engineers who don't *like* marketing, as a matter of basic >personality. They never get it in their heads that they have to >counter-market to some degree in order to hold the line. If you don't do >any marketing, Microsoft completely out-markets you and then you die, >technical merit or not. Hmm...interesting point. Too bad there is simply no factual basis for it. If Microsoft completely out markets everyone and they die, why are there still so many Unix machines around? The only thing that has made any headway against the Unix establishment is Linux. Not many people switch and go to Windows 2000 Server from a Unix machine. A lot of people go from windows to Linux though. Ignore Open Source at your own peril > >>> - Sun is about to die. It has done nothing for anyone lately and >>> has no further tricks up its sleeve. >> >> People have been saying this for years. I'll believe it when I see it. > >Read a paper. Ohh...the paaaaper said it...now it must be true. They aren't out of business until they are out of business. > >>> - Sun has failed to make Java live up to its claims of universality. >>> Java is for all intents and purposes simply a widespread programming >>> language, not a portable computing environment. Portable computing >>> environments are, in general, a pipe dream as long as Microsoft is >>> around. It will always be Windows vs. open standards. >> >> They must give you a good edjumacation at the Redmond campus. Java is >> by far the best portable computing environment available. > >Care to name a concrete example? A testimonial? Omg - it suprises me that anyone would argue this. Name a better portable computing environment? Java is by *far* the most ubiquitous environment. Seriously, name anything out there that is even close. > >>> - Ergo, Java is the weakling of the litter for Python to attack. >> >> No factual basis for this statement. Java and Python are really >> entirely different things. Python is meant as a scripting language, >> Java is a Systems programming language. It is meant as an alternative >> to C++, Python isn't. > >You're saying Python isn't useful as a systems language? Then it is already >dead. man, you have no fear to pull stuff right out of your ass. You must be a marketing guy. Apparently we have different definitions of what dead is. I don't know about you, but I would be fine with the python community staying this size, shrinking or growing. To me its about the language, about the elegance of the technology, about it's utility to me. Some people just don't get that. I have no desire for Python to have the same mind share as VB, because I don't want to have to answer all the questions on how to write Hello World by people who probably have no business programming in the first place. I'm sure that's an elitist snob attitude, but I think MS does a greater disservice to people by hiding the technical details and making them think they can run mission critical services when they are in all reality ill equiped to do so (Windows NT/2k, Sql Server, Exchange, C#...need I go on?) > >> Who does Python have to defend itself against? Python is Open Source. >> The only way it's going to die is if everyone stops developing it and >> it stagnates. > >You got it! And development stops when a langauge loses all meaningful >mindshare. What is the battle of mindshare? A marketing battle. It is not >a technological battle, except in the grossest terms of complete >incompetence. Time and again, the marketplace has proven that kludgy but >well marketed products carry the day. They only fail when they absolutely >can't do the job. > Well development hasn't stopped, doesn't appeared to have slowed down. In fact if I'm any judge it's been speeding up. Compare that to the erosion in the MS world. >> If that hapens it will be because something *significantly* better came >along. > >No, it is not an engineering meritocracy. Look at a company like DEC. >Wonderful technology company. Couldn't market its way out of a paper bag. >That's a warning for this c.l.p crowd. Don't sit around congratulating >yourselves on how superior your techology is. Recognize the strategic >competition and market against it. You completely miss the point man. Python and OSS isn't about marketing to the masses. It's about giving us cool shit to work with. People like you will never get that. But that's ok, because morons like you who use languages and tools simply because they are popular will continue to get owned when we face you head to head. I don't mind Microsoft tools, because when I compete with the typical MS zombie, I win everytime. Microsoft didn't succeed due to Marketing. They didn't succeed due to strategic positioning. They succeeded because they lied to IBM and told them they had an Operating System. They got lucky and happened to be at the right place at the right time. While the Unix world was fractured and bickering. > >> Python doesn't have to defend >> itself, your Microsoft background is showing through here. C# is by >> far the weakest language of the four. It is buggy, slow and immature. >> It has the smallest user base, the least amount of industry backing > >and is 100% backed by all the resources of Microsoft. It will not go away, >and its shortcomings will be fixed at a blistering pace. blistering?!? wtf are you talking about. MS doesn't do *anything* at a blistering pace. Are you talking about how they've fixed all their security flaws at a blistering pace? Or are you talking about how they've fixed the optimization problems with Sql Server at a blistering pace? Or are you talking about how it took DirectX till version 8.0 to surpass OpenGL at version 1.0? The only relation MS has to blisters is that they are like an STD. > >> and a community that is rising up against it's benefactor. > >Huh? Care to explain? get a paper > >> I think >> you dramatically overstate it's chances. Historically Microsoft >> switches technologies every 3 or 4 years. That only gives C# about 2 >> years to go before it's dead in the water like every other MS >> "Innovation". > >What part of "100% committment across the company" don't you understand? >You really are blind. You don't live in Redmond, you can't conceive of >having access to this level of information. And who in c.l.p woudl tell you >these things? > What part of Open Source and *immune* to Microsoft don't you understand? I think *you* are blinded by the shadow of redmond. Get out into the real world, people who don't live in the shadow of the tower don't tend to hold it in as high of regard. >Well, you've been warned. > >> Historically >> those with the best technology and the best economic system prevail >> against inefficient and inferior models. > >You have *got* to be kidding me. Intel??!? Windows??!? Obviously you *aren't* a student of history. You think that Windows and Intel have won. You think Open Source developers are resting on their laurels thinking smugly about their superiority. You are sadly mistaken on about many things. MS won a battle, they certainly haven't won the war. Doug Tolton From tjreedy at udel.edu Thu Aug 7 12:56:04 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 7 Aug 2003 12:56:04 -0400 Subject: True References: <3F312A65.5312B6EA@engcorp.com> Message-ID: "Daniel Klein" wrote in message news:vrh4jvopu29elj8fu26upnf48f45de22h9 at 4ax.com... > On Wed, 06 Aug 2003 12:18:45 -0400, Peter Hansen > wrote: > >def boolean2String(boolVal): > > return { False : '1', True : '0' } [ not boolVal ] > Thanks Peter, that will do the trick. Just wondering though why you > chose to code the opposite values and not as > > def boolean2String(boolVal): > return {True:'1', False:'0'}[boolVal] Your function requires the arg to be 0/1 (True/False). Peter's function works for *any* input that can be 'not'ed. TJR From 'cHVAdm8ubHU=\\n'.decode('base64') Mon Aug 4 14:31:01 2003 From: 'cHVAdm8ubHU=\\n'.decode('base64') ('cHVAdm8ubHU=\n'.decode('base64')) Date: Mon, 04 Aug 2003 20:31:01 +0200 Subject: bug in file.write() ? In-Reply-To: References: <13a4e2e3.0307311443.299bd59d@posting.google.com> <3f2b5e60.36345431@news.lexicon.net> <3f2b7816_2@news.vo.lu> <3f2cb414_2@news.vo.lu> Message-ID: <3f2ea618_2@news.vo.lu> Bengt Richter wrote: > By any chance are you doing compression implicitly with the compressor using > the destination disk as temp space in some way that requires a complete > temp image before copying and before deleting? Maybe if so it can be > reconfigured to use space elsewhere or just rename (hm, rename on CDRW > isn't implemented as copy, based on renamee not being modifiable, is it?) > No, the step that created the zip completely runs on the harddisk. The step that fails simply does a copy. Is anyone able to reproduce the error? i.e. 1- take a file that's more than 50% of the target CD-RW in size 2- do a simple shutil.copy(from, to) and get the same result? I'd just like to know if it is my PC only, or a more general issue. Just to keep the developers from chasing phantoms. > Still wonder about threads too... If it doesn't make any difference to your well-being, then don't. That's what Buddha said ;-) > > Regards, > Bengt Richter -- Real e-mail address is 'cHVAdm8ubHU=\n'.decode('base64') Visit my Homepage at http://www.homepages.lu/pu/ From mis6 at pitt.edu Sun Aug 24 10:38:49 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 24 Aug 2003 07:38:49 -0700 Subject: Python is darn fast (was: How fast is Python) References: <2259b0e2.0308230737.8a9bc1c@posting.google.com> Message-ID: <2259b0e2.0308240638.38350cba@posting.google.com> I finally came to the conclusion that the exceeding good performance of Psyco was due to the fact that the function was called a million times with the *same* argument. Evidently Psyco is smart enough to notice that. Changing the argument at each call (erfc(0.456) -> i/1000000.0) slows down Python+Psyco at 1/4 of C speed. Psyco improves Python performance by an order of magnitude, but still it is not enough :-( I was too optimistic! Here I my numbers for Python 2.3, Psyco 1.0, Red Hat Linux 7.3, Pentium II 366 MHz: $ time p23 erf.py real 0m3.245s user 0m3.164s sys 0m0.037s This is more than four times slower than optimized C: $ gcc erf.c -lm -O3 $ time ./a.out real 0m0.742s user 0m0.725s sys 0m0.002s Here is the situation for pure Python $time p23 erf.jy real 0m27.470s user 0m27.162s sys 0m0.023s and, just for fun, here is Jython performance: $ time jython erf.jy real 0m44.395s user 0m42.602s sys 0m0.389s ---------------------------------------------------------------------- $ cat erf.py import math import psyco psyco.full() def erfc(x): exp = math.exp p = 0.3275911 a1 = 0.254829592 a2 = -0.284496736 a3 = 1.421413741 a4 = -1.453152027 a5 = 1.061405429 t = 1.0 / (1.0 + p*x) erfcx = ( (a1 + (a2 + (a3 + (a4 + a5*t)*t)*t)*t)*t ) * exp(-x*x) return erfcx def main(): erg = 0.0 for i in xrange(1000000): erg += erfc(i/1000000.0) if __name__ == '__main__': main() -------------------------------------------------------------------------- # python/jython version = same without "import psyco; psyco.full()" -------------------------------------------------------------------------- $cat erf.c #include #include double erfc( double x ) { double p, a1, a2, a3, a4, a5; double t, erfcx; p = 0.3275911; a1 = 0.254829592; a2 = -0.284496736; a3 = 1.421413741; a4 = -1.453152027; a5 = 1.061405429; t = 1.0 / (1.0 + p*x); erfcx = ( (a1 + (a2 + (a3 + (a4 + a5*t)*t)*t)*t)*t ) * exp(-x*x); return erfcx; } int main() { double erg=0.0; int i; for(i=0; i<1000000; i++) { erg = erg + erfc(i/1000000.0); } return 0; } Michele Simionato, Ph. D. MicheleSimionato at libero.it http://www.phyast.pitt.edu/~micheles/ ---- Currently looking for a job ---- From theller at python.net Fri Aug 8 14:05:59 2003 From: theller at python.net (Thomas Heller) Date: Fri, 08 Aug 2003 20:05:59 +0200 Subject: py2exe and numarray References: Message-ID: Maur?cio Caliggiuri Infor?ati writes: > Hi, all. > I?m trying to freeze a simple python script with py2exe and it does not work. > I am using numarray0.6. > Can anybody help me? If you mail me the program (or post it, if it is really small) I promize to look into it. Otherwise you must at least give some more information. Thomas From mxlplx2003 at yahoo.com Thu Aug 28 10:20:47 2003 From: mxlplx2003 at yahoo.com (mxlplx) Date: 28 Aug 2003 07:20:47 -0700 Subject: Zope from Interwoven Message-ID: <3cf2990f.0308280620.3dec0c39@posting.google.com> I'm currently working on a project to convert an Interwoven-based site to use Zope instead. Has anyone attempted this before and if so, were you able to do it with Zope? Could you use the XML files produced by Interwoven? Any ideas would be appreciated. From irmen at -NOSPAM-REMOVETHIS-xs4all.nl Sat Aug 16 22:39:34 2003 From: irmen at -NOSPAM-REMOVETHIS-xs4all.nl (Irmen de Jong) Date: Sun, 17 Aug 2003 04:39:34 +0200 Subject: PS: Help pickling across sockets In-Reply-To: References: Message-ID: <3f3eeae4$0$49099$e4fe514c@news.xs4all.nl> Jonathan Hayward wrote: > Just after posting the previous request, I realised that my test case > worked after I added flushes. The next problem I have is that, in the > real program, the server gets an EOFError when it first tries to read > from the socket. I'm not sure, but perhaps pickle doesn't work on sockets directly? Perhaps it needs a random-access file object. So, read all the data from the socket yourself, into a string buffer, and run pickle on that. That's what I do in Pyro :-) HTH, --Irmen de Jong From pycon at python.org Mon Aug 4 16:35:22 2003 From: pycon at python.org (PyCon Committee) Date: Mon, 4 Aug 2003 16:35:22 -0400 Subject: PyCon DC 2004 Kickoff! Message-ID: <20030804203522.GA3565@panix.com> [Posted to comp.lang.python/python-list, comp.lang.python.announce, zope-announce, pycon-announce, and python-dev.] [Please repost to local Python mailing lists.] Planning for PyCon DC 2004, the Python community conference, is now underway. DC 2004 will be held March 24-26, 2004 in Washington, D.C. It will contain many of the features of this year's successful conference, including a development sprint and a similar cost structure. Registration will be open by October 1. A Call For Proposals will be issued in the next two weeks. Presentations will be required in electronic form for publication on the web. PyCon DC 2003 had a broad range of presentations, from reports on academic and commercial projects to tutorials and case studies, and these will all be included in the Call For Proposals. As long as the presentation is interesting and potentially useful to the Python community, it will be considered for inclusion in the program. There will again be a significant amount of Open Space to allow for informal and spur-of-the-moment presentations for which no formal submission is required. There will also be several Lightning Talk sessions. These informal sessions are opportunities for those who don't want to make a formal presentation. We're looking for volunteers to help run PyCon. If you're interested, subscribe to http://mail.python.org/mailman/listinfo/pycon-organizers Don't miss any PyCon announcements! Subscribe to http://mail.python.org/mailman/listinfo/pycon-announce You can discuss PyCon with other interested people by subscribing to http://mail.python.org/mailman/listinfo/pycon-interest The central resource for PyCon DC 2004 is http://www.python.org/pycon/dc2004/ -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From ofnap at nus.edu.sg Fri Aug 1 10:51:37 2003 From: ofnap at nus.edu.sg (Ajith Prasad) Date: 1 Aug 2003 07:51:37 -0700 Subject: Using Python with an OLAP Server Message-ID: <37ee60c8.0308010651.75a223de@posting.google.com> The documentation for the latest version of an OLAP server (MIS ALEA from www.misag.com) states that "PushRule function libraries can be developed with any development environment supporting the generation of COM components. Additionally, further libraries may be integrated with PushRules." The documentation gives examples of the use of MS Visual Basic to generate the required functions. Would anyone with experience in PythonWin be prepared to give an opinion whether, on the assumption that the documentation is accurate, it would be similarly possible to use PythonWin to develop the required function libraries. Thanks in advance. From ejy712 at comcast.net Thu Aug 14 00:13:13 2003 From: ejy712 at comcast.net (Ed Young) Date: Thu, 14 Aug 2003 00:13:13 -0400 Subject: Is Python your only programming language? References: Message-ID: I use python at home 95%. I use C and perl at the office. I'm working on the folks at the office to adopt Python. C is great when you have to manipulate lots of bytes (find all chars above dec(127) in a 690 meg file). It's also good for cross platform utilities (MVS, UNIX, WinXX). Perl is great for one liners, as a part of a pipeline (e.g. analyzing log files). It's also great for vi(ex) editing with vim when it runs out of steam. I prefer Python for all else (GUI, larger scope utilities, anything complex). I've done a *lot* of programming over the past 32 years, in many languages. Python really is a better idea. YMMV On Tue, 12 Aug 2003 05:44:45 +0000, Joe Cheng wrote: > I'm curious about something... many Artima.com members who have a Java > background and learned Python have come to the conclusion that Java and > Python are highly complimentary languages. They would never consider > filling the place Java has in their toolbox with Python, but recognize > there are many tasks where it really pays to add Python to the mix. > > I want to ask you hard-core c.l.p Pythonistas: Do you use Python for > everything? (and I'm counting Python + C extensions as just Python) Or > do you keep another language equally close at hand, and if so, what is it? > And finally, do you foresee a day when Python can be, for all practical > intents and purposes, your only programming language? From mike at nospam.com Thu Aug 14 18:00:52 2003 From: mike at nospam.com (Mike Rovner) Date: Thu, 14 Aug 2003 15:00:52 -0700 Subject: Strange re behavior: normal? References: Message-ID: Robin Munn wrote: >>>> re.split(r'\b', 'a b c d') > ['a b c d'] Perl 5.8 does that: > a word, I would have expected re.split(r'\b', 'a b c d' to produce > ['a', ' ', 'b', ' ', 'c', ' ', 'd'] > But I didn't expect that re.split(r'\b', 'a b c d') would yield no > splits whatsoever. The module doc says "split(pattern, string[, > maxsplit = 0]): split string by the occurrences of pattern". > re.findall() seems to think that \b occurs eight times in 'a b c d': But it says nothing about empty pattern in contrast to findall: "Empty matches are included in the result." >>>> re.findall(r'\b', 'a b c d') > ['', '', '', '', '', '', '', ''] > > So why doesn't re.split() think so? I'm puzzled. It treats r'\b' as empty ('') pattern. (Hint: Consider error for r'\b?') IMHO that split behavior is a bug although technicaly it is not. (From re manual: "This module provides regular expression matching operations similar to those found in Perl.") Regards, Mike PS. Perl also produces expected result for split /\b/ 'a b c d' -> 'a', ' ', 'b', ' ', 'c', ' ', 'd' From newsgroups at jhrothjr.com Fri Aug 8 19:21:04 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Fri, 8 Aug 2003 19:21:04 -0400 Subject: How to print floating point in scientific format? References: <420ced91.0308081115.7060e551@posting.google.com> Message-ID: "sdhyok" wrote in message news:420ced91.0308081115.7060e551 at posting.google.com... > I want to change the DEFAULT behavior of python > to print out all floating points in scientific format? > For instance, > > >x=0.01 > >print x > 1.000000E-2 #Like print "%E"%x > > How can I do it? > > Daehyok Shin To the best of my knowledge, you can't. I believe the only way to actually control the format is with the '%' operator. Of course, if you want to get the source, make the change, and then have your own private copy of Python, you could manage it. John Roth From skip at pobox.com Sat Aug 9 13:06:57 2003 From: skip at pobox.com (Skip Montanaro) Date: Sat, 9 Aug 2003 12:06:57 -0500 Subject: Need elegant way to cast four bytes into a long In-Reply-To: References: <3f33c209$1@news.si.com> Message-ID: <16181.10801.153942.709241@montanaro.dyndns.org> >> You mean like this: >> >> l = long(a[0] + a[1] << 8 + a[2] << 16 + a[3] << 24) >> John> Bzzzzzt. Oh the joys of operator precedence! Yeah, I realized that after seeing a couple other responses. Should have kept my mouth shut. I tend to think of << and >> as X2 and /2 operators and thus mentally lump them together with * / and %. Fortunately, I don't do much bit twiddling or I'd be in real trouble... Skip From hellprout at yahoo.com Fri Aug 22 03:17:33 2003 From: hellprout at yahoo.com (hellprout) Date: 22 Aug 2003 00:17:33 -0700 Subject: Problem with py2exe and installer5b5_5 Message-ID: <5b8834c2.0308212317.68acf539@posting.google.com> hi , i want to use py2exe or installer5b5_5 with my python source so no problem when i execute the source , but when i use installer or py2exe to create an exe file on windows , i have some problems when my program want to read a xml file i have an error 2.2.3 (#42, May 30 2003, 18:12:08) [MSC 32 bit (Intel)] Traceback (most recent call last): File "wxFrame1.pyc", line 287, in OnButton1Button File "EIM_xml.pyc", line 135, in main_xml File "EIM_xml.pyc", line 44, in construction_liste_xml File "xml\sax\__init__.pyc", line 33, in parse File "xml\sax\expatreader.pyc", line 86, in parse File "xml\sax\saxutils.pyc", line 250, in prepare_input_source File "ntpath.pyc", line 274, in isfile LookupError: no codec search functions registered: can't find encoding i don't know what is it , but i surch something and i did't find the solution if something have an idea , thanks a lot charles From adalke at mindspring.com Thu Aug 21 03:13:51 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Thu, 21 Aug 2003 07:13:51 GMT Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> <6dj2kv8ugkieehs7guh786cl40o5lj6mcs@4ax.com> <599a6555.0308202108.397bb1a0@posting.google.com> Message-ID: Olivier Drolet: > Macros, as found in Common Lisp, do not change the underlying language > at all! Common Lisp macros, when run, always expand into 100% ANSI > Common Lisp code! I've created a new language, called Speech. It's based on the core primitives found in the International Phonetic Alphabet. I've made some demos using Speech. One is English and another is Xhosa. This just goes to show how powerful Speech is because it can handle so many domains. And it's extensible! Anything you say can be expressed in Speech! > Using macros to become more productive is no > different from using function abstractions or class hierarchies to > become more productive. One of the most incredible things about Speech is that you can create domain-specific words. Verbing doesn't wierd nouns - it's perfectly crumbulent and embiggens the soul! > They all require that you, the programmer, become familiar with them. Someone else's new words simple require that you, the programmer, become familar with them. You can even get dictionaries which explain how each word is used in (most of) the different contexts you might find it in. In many cases you can even infer the meaning, because of built-in redundancy. > Macros don't cause Common Lisp to fork > anymore than function or class abstractions do. Making new words don't cause Speech to fork any more than making new sentences does. > They only alter the > readability of "program code" (usually for the better), just like > function or class abstractions do. They only alter the comprehension of "talking" (usually for the better). > Saying that all hell will break loose in the Python community seems > rather unfounded and a bit knee-jerk Saying that different people will decide to use only a part of Speech, and not understand all the variations when needed seems rather unfounded and a bit knee-jerk. ... > After years of macro use, ANSI Common Lisp > is till the same. Macros don't bypass ANSI committees anymore than > they would the Guidos of this world. After years of Speech use, ANSI Common Speech is still the same. New Speech doesn't bypass ANSI committees anymore than they would the Shakespeares and Chief Josephs of the world. > On the contrary, they preclude > the need to bypass them in the first place, and all parties end up > getting what they need: on the one hand, a static base language, and > on the other, much greater expressiveness. On the contrary, Speech definitions preclude the need to make new languages, and all parties end up getting what they need: on the one hand, a static core set of syllables, and on the other, much greater expressiveness. > Speaking of expressiveness, someone asked on comp.lang.lisp.fr what > macros were good for, concretely, and what quantitative difference > they made in commercial applications (cf. "Macros: est-ce utile ? > (attn Marc)"). The responses (in French) were quite enlightening. It > boils down to using multiple macros, in multiple instances, thus > allowing to reduce total code size (of otherwise pure CL code) by VERY > significant margins. You can think of it as reuse (as per OOP) or as > code compression. Speaking of expressiveness, someone in France suggested that "courriel" was a better fit for their local Dialect of Speech, instead of the word "e-mail". That's just one perfect example of how different groups can customize Speech for internal consistancy in a given doman. This allows users to keep a consistent set of pronounciation rules and reduce the dictionary size. > Macros do not have to be used all the time or at all. There are times > when a macro should not be used, e.g. when a function would do just > fine. Creating new words of Speech does not have to be done all the time or at all. There are times when an existing word or a sentence (a set of existing words) would do just fine. > But they are very powerful. But making new words is very powerful. > As Paul Graham put it, macros allow > you to program up towards the problem at hand, as opposed to adapting > the problem to fit the language specification. They allow greater > expressiveness, when you need it. They allow you to "use" many lines > of code you no longer have to write. And the lines of code you don't > have to write are also the lines of code you don't have to debug (as > it were). As Some Dude put it, neologisms allows you to Talk about the problem at hand, as opposed to adapting the problem to fit the words you know. They allow greater expressivenes and precision, when you need it. They allow you to "use" many sentences you no longer have to say. And the words you don't say are the ones you don't need to pronounce (as it were). In short, no one is denying that the ability to create new macros is a powerful tool, just like no one denies that creating new words is a powerful tool. But both require extra training and thought for proper use, and while they are easy to write, it puts more effort for others to understand you. If I stick to Python/English then more people can understand me than if I mixed in a bit of Erlang/ Danish, *even* *if* the latter makes a more precise description of the solution. By this analogy, Guido is someone who can come up with words that a lot of people find useful, while I am someone who can come up withs words appropriate to my specialization, while most people come up with words which are never used by anything other than close friend. Like, totally tubular dude. And since I know you want a demo of Speech, here's an example of Xhosa and it's direct translation into English, which doesn't have a single word for "going for a purpose" Ndiya kulala. -- I am going for the purpose of sleeping. And here's an example of Swedish with a translation into English, which lack some of the geneaological terms min mormor -- my maternal grandmother I can combine those and say Umormor uya kulala -- my maternal grandmother is going for the purpose of sleeping. See how much more precise that is because I can select words from different Dialects of Speech? Andrew dalke at dalkescientific.com From bokr at oz.net Tue Aug 19 21:10:48 2003 From: bokr at oz.net (Bengt Richter) Date: 20 Aug 2003 01:10:48 GMT Subject: union in Python References: Message-ID: On Tue, 19 Aug 2003 08:17:57 +0000 (UTC), Duncan Booth wrote: >bokr at oz.net (Bengt Richter) wrote in news:bhrsuj$mdv$0 at 216.39.172.122: > >> But I don't see any reason why the performances couldn't be made to >> match. > >For searching short strings there probably isn't any advantage to using >Boyer-Moore, and for short search strings the advantage is probably quite >small. I think you would need to spend some time working out just where the >breakpoints are that make it worth switching from a plain search to one >that skips ahead. Sure. No question. IWT the deciding question would be if the check can be done with CPU cycles that are otherwise going to be wasted anyway. You wouldn't want to incur a cost for 99.44% of cases for the sake of a big improvement in 0.56%. Sometimes you can also rewrite the code and get a check that doesn't interfere with normal fast cases. If the check can be made "for free," then I only see programming cost in doing it. I think there's a chance a simple length check could be done by the CPU in the time shadow of waiting for data to load in its cache, what with all the pipeline and scheduling magic CPUs do these days. But this is handwaving imaginings. I couldn't be sure without testing. > >The regular expression search may still win, since regular expressions, >even if not precompiled, are cached. That means that if you perform the >regex search millions of times, the setup cost is only incurred once. >String searches don't have this advantage, and it seems unlikely to be >worth the effort of caching arguments passed to string.find! But Gustavo's test had the regex compiled outside the loop, so that shouldn't have affected the result. A programmer who leaves a constant regex compilation inside the loop deserves what s/he gets (cache-mitigated or not, the calls would still be there) ;-) Regards, Bengt Richter From zsh-users-help at sunsite.dk Sat Aug 30 18:50:03 2003 From: zsh-users-help at sunsite.dk (zsh-users-help at sunsite.dk) Date: 30 Aug 2003 22:50:03 -0000 Subject: confirm unsubscribe from zsh-users@sunsite.dk Message-ID: <1062283803.7480.ezmlm@sunsite.dk> Hi! This is the ezmlm program. I'm managing the zsh-users at sunsite.dk mailing list. To confirm that you would like python-list at python.org removed from the zsh-users mailing list, please send an empty reply to this address: zsh-users-uc.1062283803.okifnhokaldgjdaajooj-python-list=python.org at sunsite.dk Usually, this happens when you just hit the "reply" button. If this does not work, simply copy the address and paste it into the "To:" field of a new message. I haven't checked whether your address is currently on the mailing list. To see what address you used to subscribe, look at the messages you are receiving from the mailing list. Each message has your address hidden inside its return path; for example, mary at xdd.ff.com receives messages with return path: -mary=xdd.ff.com at sunsite.dk. --- Administrative commands for the zsh-users list --- I can handle administrative requests automatically. Please DO NOT SEND THEM TO THE LIST ADDRESS! If you do, I will not see them and other subscribers will be annoyed. Instead, send your message to the correct command address: To subscribe to the list, send a message to: To remove your address from the list, send a message to: Send mail to the following for info and FAQ for this list: Similar addresses exist for the digest list: To get messages 123 through 145 (a maximum of 100 per request), mail: To get an index with subject and author for messages 123-456 , mail: They are always returned as sets of 100, max 2000 per request, so you'll actually get 100-499. To receive all messages with the same subject as message 12345, send an empty message to: The messages do not really need to be empty, but I will ignore their content. Only the ADDRESS you send to is important. You can start a subscription for an alternate address, for example "john at host.domain", just add a hyphen and your address (with '=' instead of '@') after the command word: To stop subscription for this address, mail: In both cases, I'll send a confirmation message to that address. When you receive it, simply reply to it to complete your subscription. If despite following these instructions, you do not get the desired results, please contact my owner at zsh-users-owner at sunsite.dk. Please be patient, my owner is a lot slower than I am ;-) --- Enclosed is a copy of the request I received. Return-Path: Received: (qmail 7466 invoked from network); 30 Aug 2003 22:50:02 -0000 Received: from localhost (HELO sunsite.dk) (127.0.0.1) by localhost with SMTP; 30 Aug 2003 22:50:02 -0000 X-MessageWall-Score: 0 (sunsite.dk) Received: from [128.187.34.45] by sunsite.dk (MessageWall 1.0.8) with SMTP; 30 Aug 2003 22:50:2 -0000 From: To: Subject: Re: Wicked screensaver Date: Sat, 30 Aug 2003 16:50:00 --0600 X-MailScanner: Found to be clean Importance: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MSMail-Priority: Normal X-Priority: 3 (Normal) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="_NextPart_000_05F77684" --_NextPart_000_05F77684 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit See the attached file for details --_NextPart_000_05F77684-- From mwh at python.net Fri Aug 1 07:03:44 2003 From: mwh at python.net (Michael Hudson) Date: Fri, 1 Aug 2003 11:03:44 GMT Subject: Unfortunate exception on dict item assignment (and why aren't slices hashable?) References: <67fdivk9iu0q1p7nc8smfj1miip3cbvobf@4ax.com> Message-ID: <7h3u191abdk.fsf@pc150.maths.bris.ac.uk> I think I've ranted, along these lines, in this forum, before. However, SF has just gone down for maintenence as I try to comment on a bug, so I'm feeling these issues (and am being frustrated in my attempts to "do something useful instead"). Francois Pinard writes: > [Fredrik Lundh] > > > Aahz wrote: > > > (Despite my regular comments on python-dev, I don't contribute > > > code because SF refuses to make changes to allow Lynx to work > > > correctly.) > > > maybe someone with an SF account could help you out? > > Let me say (and probably repeat) that imposing Web browsers to users, > or bug trackers with sorrow editing interfaces, and asking users to get > acquainted with the classification system and various work idiosyncrasies > of each and every maintainer, package by package, is insane. W W EEEEE K K N N OOO W W W W E K K NN N O O W W W W W EEE KK N N N O O W W W WW WW E K K N NN O O WW WW W W EEEEE K K N N OOO W W that the SF trackers are not ideal. We are trying, hoping, to move to a friendly system (roundup) more under our control, but there's this small matter of time... > The result is that users have either to choose on which few packages they > will specialise on, or else, to merely stop contributing. In the former > case, a maintainer is building his own specialised crowd, which may be > admittedly good for his project alone. In the latter case, a maintainer > is pushing users away. But in all cases, this is an overall social lost. If we push away contributors who do not have time to adjust to using a different tool for the Python project, maybe that's not such a bad thing. Submitting a patch to Python implies a certain amount of commitment. You just cannot expect the (volunteer!) maintainers to fall down and be grateful that someone has deigned to send a patch their way. > I miss the times when it was a simple matter to offer contributions, > maybe humble and small, yet possibly numerous, to any package in sight. > Maintainers praising want-to-be-sophisticated machinery should use it all > their soul if they feel like it, but without forcing users into their bag. Look, we get more patches than we can cope with. We *have* to have some way of organising our backlog. What do you suggest instead? That you just email a patch to one of the maintainers and have them shuffle it into the structured tracker, thus taking time away from them that they could be using to assess the patch? Get real. Or, better, offer to help set up roundup on python.org. And frankly, the pain of using suboptimal trackers is felt *much more* by the maintainers than those who submit patches to us. Cheers, mwh -- [2. More type system hacking --- text/plain; type-argh.diff] -- csr on sbcl-devel From abuseonly at sgrail.org Fri Aug 22 04:06:10 2003 From: abuseonly at sgrail.org (derek / nul) Date: Fri, 22 Aug 2003 08:06:10 GMT Subject: Newbie problem with codecs References: <1R01b.1724$Ej6.454@newsread4.news.pas.earthlink.net> Message-ID: On Fri, 22 Aug 2003 07:41:34 GMT, "Andrew Dalke" wrote: >derek / nul >> My code so far > ... >> t = unicode(eng_file, "utf-16-le") >> print t >> ----------------------------------------------------- >> >> The print fails (as expected) with a non printing char '\ufeff' which is >of >> course the BOM. >> Is there a nice way to strip off the BOM? > >How does it fail? File "apply_physics.py", line 21, in ? print t File "C:\Program Files\Python\lib\encodings\cp850.py", line 18, in encode return codecs.charmap_encode(input,errors,encoding_map) UnicodeEncodeError: 'charmap' codec can't encode character '\ufeff' in position 0: character maps to >It may be because print tries to convert the >data as appropriate for your IDE or terminal, and fails. Eg, the >default expects ASCII. See > >http://www.python.org/cgi-bin/faqw.py?req=show&file=faq04.102.htp > >Asa a guess, since you're on MS Windows, your terminal might >expect mbcs. Try > >print t.encode('mbcs') > >If you really want to strip it off, do t[2:] (or [4:]?), to get the >string after the first 2/4 characters (the BOM) in the string. But >I doubt that's the correct solution. > > Andrew > dalke at dalkescientific.com > From rmunn at pobox.com Fri Aug 1 11:52:00 2003 From: rmunn at pobox.com (Robin Munn) Date: Fri, 01 Aug 2003 15:52:00 GMT Subject: .zip files sample manip References: Message-ID: News M Claveau /Hamster-P wrote: > Bonjour ! > > J'ai publi? dans "announce", mais, comme cela n'appara?t pas (???), je donne > l'adresse ici : > http://mclaveau.com/ress/python/zipmci.htm > > Dans ce gros exemple, il y a, notamment, la suppression des fichiers, la > r?affectation des date-time des fichiers extraits, etc. > > @-salutations La langue principale du groupe comp.lang.python est l'anglais; vous trouverez sans doute plus de r?ponse dans fr.comp.lang.python. Pour tous ceux qui ne lisent pas le fran?ais, j'ai post? une traduction en anglais de votre message et de ma r?ponse. ----- Traduction en anglais ci-dessous / English translation below ----- News M Claveau /Hamster-P wrote: > Hello ! > > I published this in "announce", but since it hasn't appeared (???), > I'm giving the address here: > http://mclaveau.com/ress/python/zipmci.htm > > In this rough example, you will find, among others, deleting files, > resetting the date/time of extracted files, etc. > > @-greetings The main language of comp.lang.python is English; you'll most likely find more of a response in fr.comp.lang.python. For all those who don't speak French, I've posted an English translation of your message and my response. -- Robin Munn | http://www.rmunn.com/ | PGP key 0x6AFB6838 -----------------------------+-----------------------+---------------------- "Remember, when it comes to commercial TV, the program is not the product. YOU are the product, and the advertiser is the customer." - Mark W. Schumann From DaveInRedmond at earthlink.net Fri Aug 29 15:36:07 2003 From: DaveInRedmond at earthlink.net (Dave In Redmond) Date: Fri, 29 Aug 2003 19:36:07 GMT Subject: Update to Python 2.3 on Red Hat Linux 9 References: <8242f4a7.0308282240.4c87f997@posting.google.com> Message-ID: Jay Bromley wrote: > Hello, > > I've got a Red Hat Linux 9 system with Python 2.2.2 and I would like > to update to Python 2.3. I got the 2.3 source and built and installed > it. Python 2.3 itself works but it doesn't have access to a lot of > packages that are available to Python 2.2.2. For example, > pygtk-1.99.14 and Tkinter work fine with 2.2.2, but in 2.3 I can't do > 'import gtk' or 'import _tkinter'. I checked the pygtk site and they > say I've got to recompile pygtk for the new Python. I'm hoping there > is a better answer. The problem is a lot of RedHat stuff depends on > Python and the packages available to 2.2, but I need 2.3 and I don't > want to junk the applications based on Python 2.2 and the current > packages. > > So the questions is, can I build Python 2.3 so that it recognizes all > the packages that are available to Python 2.2.2? Is this LD_RUN_PATH > stuff? Or do I really need to find out all the libraries in use with > 2.2.2 and compile these for 2.3? > > I'd appreciate any pointers or references to documentation. I *really* > want 2.3. > > Thank you, > Jay Bromley > jaybromley at hotmail.com Did you rebuild Python with enable-unicode=ucs4? If not, that is likely your problem - it was mine ;<{) From frobozz_electric at hotmail.com Thu Aug 14 09:24:13 2003 From: frobozz_electric at hotmail.com (Sean Ross) Date: 14 Aug 2003 13:24:13 GMT Subject: 3 new slogans References: <3F3B5F80.3E7DE934@hotmail.com> <5f5c82ec.0308140502.36af5ce6@posting.google.com> Message-ID: Python. Not just for kids.(TM) Python. Simply Beautiful. From jepler at unpythonic.net Thu Aug 21 14:58:53 2003 From: jepler at unpythonic.net (Jeff Epler) Date: Thu, 21 Aug 2003 13:58:53 -0500 Subject: how fast is Python? In-Reply-To: References: Message-ID: <20030821185848.GE32191@unpythonic.net> I don't know what Mark Carter wanted to measure either, but I'd like to mention that when I compile "a.cpp" on my system with the flags Alex used, the generated code doesn't even include any floating-point arithmetic. The compiler was able to deduce that X was dead after the loop, and that its computation had no side-effects. I'm a little surprised that the compiler didn't completely remove the loop, but it's still there. "i" isn't there either, instead there's a counter that begins at 107, decrements and terminates the loop when it reaches -1. And if I use the directive to unroll loops, the logic is the same except that the counter decreases by 18 each time instead of 1. ... and anyway, this modified code (which does actually compute X when compiled on my system) aborts with a floating point overflow error. As far as I can tell, your program would be computing a value on the order of 10^(3x10^31)... Ah, the joy of writing the proverbial good benchmark. Jeff #include fpu_control_t __fpu_control = _FPU_IEEE &~ _FPU_MASK_OM; double Y; int main() { double X = 0.5; for(int i = 0; i < 108; i++) X = 1 + X * X; Y = X; return 0; } From adalke at mindspring.com Thu Aug 21 03:19:28 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Thu, 21 Aug 2003 07:19:28 GMT Subject: What's better about Ruby than Python? References: <3F41505F.69D18CC8@alcyone.com> <66d7kvonvb2n0nqbqahhd5roak7ur81sob@4ax.com> <3f43ef5d_4@127.0.0.1> <3F440A35.9030602@nyc.rr.com> Message-ID: <4o_0b.1665$Ej6.1182@newsread4.news.pas.earthlink.net> Alex: > You could use a class if its instances where descriptors, i.e. > supported __get__ appropriately ... See Raymond Hettinger's > HOWTO on descriptors -- a *wonderful* treatment of the subject. I'm slowing easing my way into this new stuff. I read it through once, but it didn't all sink in. Could you post an example of how to use it for my cache example? Andrew dalke at dalkescientific.com From woodsplitter at rocketmail.com Wed Aug 27 10:34:01 2003 From: woodsplitter at rocketmail.com (David Rushby) Date: 27 Aug 2003 07:34:01 -0700 Subject: pure Python DB References: <9a6d7d9d.0308261756.5b37cbf4@posting.google.com> Message-ID: <7876a8ea.0308270634.26d02fec@posting.google.com> Gerhard H?ring wrote in message news:... > Aaron Watters wrote: > > Andy Todd wrote in message news:... > >>Patrick Useldinger wrote:> > >>Gadfly is lightweight but doesn't support transactions. It is in low > >>maintenance mode, development is currently not active but the project is > >>hosted at SourceForge (http://sourceforge.net/projects/gadfly) and any > >>bug reports and (especially) patches would be more than welcome. > > > > Um.. doesn't support transactions? It depends what you mean, > > I guess. It supports transaction commit and rollback and recovery > > but not transaction concurrency... (yet) > > Neither does SQLite. Only one transaction can be active at any time. > Another transaction will block at BEGIN. > > If you need that I'd suggest you switch to a client-server database like > PostgreSQL. No need to go client/server. Embedded Firebird supports concurrent transactions with configurable isolation levels, foreign keys, views, stored procedures, and other features one would expect from a full-fledged RDBMS. Plus it's fast--kinterbasdb with embedded Firebird 1.5-rc4 is about twice as fast as pysqlite 0.4.3 in various trivial speed tests I've tried. Embedded Firebird is not the primary focus of the Firebird core developers, though, so releases aren't always up to date, and so far, binaries have only been released for Windows. Here's the most recent: http://prdownloads.sourceforge.net/firebird/Firebird-1.5.0.3744_RC4_embed_win32.zip?download To use it from Python, see: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/kinterbasdb/Kinterbasdb-3.0/docs/usage.html#faq_fep_embedded_using_with I'm not aware of any reason why embedded Firebird couldn't run on *nix (the server variant does), but AFAIK no one has done so. Also, I haven't used the embedded variant for anything non-trivial, so I can't comment on its stability. From gregm at iname.com Fri Aug 22 09:10:06 2003 From: gregm at iname.com (Greg McFarlane) Date: Fri, 22 Aug 2003 23:10:06 +1000 Subject: ANNOUNCE: Pmw megawidgets 1.2 Message-ID: <20030822131006.GF1493@iname.com> Pmw megawidgets for Tkinter Version 1.2 Greg McFarlane http://pmw.sourceforge.net/ --oOo-- A new release of Pmw is out. This release makes Pmw compatable with recent releases of python and Tcl/Tk. This version of Pmw was tested against python 2.3, Tcl/Tk 8.4.2 and Blt 2.4z. Except for Blt, all tests pass. Blt seems to be more flacky than usual, with core dumps occuring in the Graph code. Since this is a problem in Blt (not Pmw), the Blt test script has been removed from the default Pmw test sequence. Several other bug fixes and improvements were made. See the change log for details. To download Pmw or for more information, see the home page at http://pmw.sourceforge.net/ If you have any comments, enhancements or new contributions, please contact me (gregm at iname.com). ===================================================================== What is Pmw? Pmw is a toolkit for building high-level compound widgets, or megawidgets, constructed using other widgets as component parts. It promotes consistent look and feel within and between graphical applications, is highly configurable to your needs and is easy to use. It uses the Tkinter python library. Pmw consists of: - A few base classes, providing a foundation for building megawidgets. - A library of flexible and extensible megawidgets built on the base classes, such as buttonboxes, notebooks, comboboxes, selection widgets, paned widgets, scrolled widgets and dialog windows. - A lazy importer/dynamic loader which is automatically invoked when Pmw is first imported. This gives unified access to all Pmw classes and functions through the Pmw. prefix. It also speeds up module loading time by only importing Pmw sub-modules when needed. - Complete reference documentation, covering all classes and functions including all megawidgets and their options, methods and components. Helpful tutorial material is also available. - A test framework and tests for Pmw megawidgets. - A slick demonstration of the megawidgets. - An interface to the BLT busy, graph and vector commands. The interface to Pmw megawidgets is similar to basic Tk widgets, so it is easy for developers to include both megawidgets and basic Tk widgets in their graphical applications. In addition, Pmw megawidgets may themselves be extended, using either inheritance or composition. The use of the Pmw megawidgets replaces common widget combinations with higher level abstractions. This simplifies code, making it more readable and maintainable. The ability to extend Pmw megawidgets enables developers to create new megawidgets based on previous work. -- Greg McFarlane Really Good Software Pty Ltd Sydney Australia gregm at iname.com From http Fri Aug 8 13:52:12 2003 From: http (Paul Rubin) Date: 08 Aug 2003 10:52:12 -0700 Subject: Replacing the crypt module in Windows References: Message-ID: <7xy8y4f35f.fsf@ruckus.brouhaha.com> Jorge Godoy writes: > What do you use to replace the crypt module in Windows? It's available > for POSIX systems only. I need to check some passwords to grant access > to a system we're writing and the first choice on unices was crypt. Is > there something that can be used on both systems and use a random seed > to generate the password? If you don't need to be compatible with Unix passwords it's best not to use that function. Instead, use a random salt and the md5 or sha module. Better yet, use the hmac module, with a random salt and with a secret key, to give some protection against dictionary searches. From vanevery at 3DProgrammer.com Mon Aug 18 03:42:22 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Mon, 18 Aug 2003 00:42:22 -0700 Subject: What's better about Rattlesnakes than Pythons? References: <8e482ba2.0308171939.7de4a288@posting.google.com> Message-ID: ForHimself Every Man wrote: > What's better about Rattlesnakes than Python. I'm sure there's > something. What is it? Rattlesnakes live in drier climates than Pythons. Rattlesnakes have venom, which is a different strategy for killing their food than constriction. If you want to live in a desert, and you want to hear your pet easily, you're better off with a rattlesnake. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From nav+posts at bandersnatch.org Tue Aug 26 10:05:53 2003 From: nav+posts at bandersnatch.org (Nick Vargish) Date: 26 Aug 2003 10:05:53 -0400 Subject: Common tasks in python References: Message-ID: A good site for "common tasks in Python" is the Cookbook site: http://aspn.activestate.com/ASPN/Python/Cookbook/ The printed version is also excellent, and can't be recommended highly enough. Buying a copy is also a good way to show your support for the fine people who put together the Cookbook... Nick -- # sigmask || 0.2 || 20030107 || public domain || feed this to a python print reduce(lambda x,y:x+chr(ord(y)-1),' Ojdl!Wbshjti!=obwAcboefstobudi/psh?') From mertz at gnosis.cx Wed Aug 13 02:48:16 2003 From: mertz at gnosis.cx (David Mertz) Date: Wed, 13 Aug 2003 02:48:16 -0400 Subject: Is Python your only programming language? References: Message-ID: |I want to ask you hard-core c.l.p Pythonistas: Do you use Python for |everything? (and I'm counting Python + C extensions as just Python) I think the co-author of (parts of) my Gnosis Utilities package, Frank McIngvale won't mind if I share this recent brief exchange with y'all. On my OS/2 machine, the case of some files in the distribution were getting messed up, so I wrote a little script to fix things up before packaging: DM> OK... but it's REXX. On the plus side, this will make sure all DM> the files are right, not just those I remember to check. FM> You'll have to excuse me for cracking up that the author FM> of Text Processing in Python just sent me a REXX script!! :-) FM> Hm, lemme crack open my book and see if I can figure out FM> how to rewrite it in this newfangled braceless python thang ;-) FWIW. (still, REXX is quite braceless). Yours, David... X-Shameless-Plug: Buy Text Processing in Python: http://tinyurl.com/jskh -- mertz@ _/_/_/_/_/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY:_/_/_/_/ v i gnosis _/_/ Postmodern Enterprises _/_/ s r .cx _/_/ MAKERS OF CHAOS.... _/_/ i u _/_/_/_/_/ LOOK FOR IT IN A NEIGHBORHOOD NEAR YOU_/_/_/_/_/ g s From lassaadbs at yahoo.fr Tue Aug 19 06:23:32 2003 From: lassaadbs at yahoo.fr (=?iso-8859-1?q?ben=20sassi=20lassaad?=) Date: Tue, 19 Aug 2003 12:23:32 +0200 (CEST) Subject: sql problem Message-ID: <20030819102332.47208.qmail@web10004.mail.yahoo.com> hi , i' am a french developper ,new with zope and interbase(python) i work with zope and interbase 6.1and windows2000 i have instaled the adapter kinterbasedbAD1.x for testing my connection i wrote """select name from tablex""" i have the follow message:::: Error Type: ProgrammingError Error Value: (-901, 'execute.isc_dsql_prepare: Dynamic SQL Error. SQL error code = -901. feature is not supported. ') i don' t understand what is the problem please help me --------------------------------- Do You Yahoo!? -- Une adresse @yahoo.fr gratuite et en fran?ais ! Testez le nouveau Yahoo! Mail -------------- next part -------------- An HTML attachment was scrubbed... URL: From iddwb at asu.edu Thu Aug 28 13:24:48 2003 From: iddwb at asu.edu (David Bear) Date: Thu, 28 Aug 2003 10:24:48 -0700 Subject: getopt issues In-Reply-To: References: Message-ID: On Wed, 27 Aug 2003, Steven Taschuk wrote: > > specified in options, rather than have it through an exception and return > > nothing? > > I don't think so. This is an unusual request -- normally it is > desirable for a program to insist on correct usage, rather than good points. yet, my purpose is to write a filter. the problem being that with different lpr implementations you don't know exactly what parameters will be passed since lpr is not really standardize (at least thats my understanding). I'm just interested in two parameters out of possibly many. Still, I think getopt is rather weak. It would be better if I could build a dictionary of options that I wanted, then when parsing the args, just fill in my dictionary values from args that I want. From bh at intevation.de Fri Aug 1 09:03:53 2003 From: bh at intevation.de (Bernhard Herzog) Date: 01 Aug 2003 15:03:53 +0200 Subject: Retrieve source filename References: <3f29207d$0$24768$626a54ce@news.free.fr> Message-ID: <6qk79xh6me.fsf@salmakis.intevation.de> Steven Taschuk writes: > As of 2.3, the __main__ module also has a __file__ attribute, so > you can just do > sys.modules[__name__].__file__ Why so complicated? Just as __name__, __file__ is simply a global variable in the module, so you can use it directly. Bernhard -- Intevation GmbH http://intevation.de/ Sketch http://sketch.sourceforge.net/ Thuban http://thuban.intevation.org/ From a.schmolck at gmx.net Mon Aug 18 18:37:34 2003 From: a.schmolck at gmx.net (Alexander Schmolck) Date: 18 Aug 2003 23:37:34 +0100 Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> Message-ID: Harry George writes: > In the Lisp world, you use the hundreds of macros in CL becuase they > *are* the language. But home-grown (or vendor supplied) macros are > basically a lockin mechanism. New syntax, new behavior to learn, and > very little improvement in readability or efficiency of expresison > (the commmon rationales for macros). How can you claim with a straight face that the sophisticated object, logic programming, constraint programming, lazy evaluation etc systems people have developed in scheme and CL over the years have brought "very little improvement in readability or efficiency"? > The python language is just fine as is. No it isn't. Like every other language I know python sucks in a variety of ways (only on the whole, much less so), but I don't claim I know how to fix this with a macro system. I'm just not sure I buy Alex's argument that an introduction of something equivalent in expressive power to say CL's macro system would immediately wreck the language. The trick with adding expressiveness is doing it in a manner that doesn't invite abuse. Python is doing pretty well in this department so far; I think it is easily more expressive than Java, C++ and Perl and still causes less headache (Perl comes closest, but at the price of causing even greater headache than C++, if that's possible). > If you really, really need something like a macro, consider a template body > which is filled in and exec'd or eval'd at run time. I've actually written a library where most of the code is generated like this (and it works fine, because only trivial code transformation are needed that can be easily accomodated by simple templating (no parsing/syntax tree manipulations necessary)). But show me how to write something like CL's series package that way (or better yet, something similar for transforming array and matrix manipulations from some reader-friendly representation into something efficient). 'as From bokr at oz.net Sun Aug 17 15:52:54 2003 From: bokr at oz.net (Bengt Richter) Date: 17 Aug 2003 19:52:54 GMT Subject: hex(-5) => Futurewarning: ugh, can't we have a better hex than '-'[:n<0]+hex(abs(n)) ?? Message-ID: >>> hex(-5) __main__:1: FutureWarning: hex()/oct() of negative int will return a signed string in Python 2.4 and up '0xfffffffb' >>> hex(-5) '0xfffffffb' >>> hex(-5L) '-0x5L' That is sooo ugly. I suppose it is for a backwards compatible repr, but couldn't we at least have hex(n, newformat=False) so that we can do hex(-5, True) => 1xb # 1x signals an arbitrary number of prefixed f's hex( 5, True) => 0x5 and have int() and long() recognize these? Also would need a variant of %x and %X for formatting with the % operator. Regards, Bengt Richter From zanesdad at bellsouth.net Fri Aug 15 08:31:14 2003 From: zanesdad at bellsouth.net (Jeremy Jones) Date: Fri, 15 Aug 2003 08:31:14 -0400 Subject: ANN: Munkware Message-ID: <20030815083114.17bc27ba.zanesdad@bellsouth.net> Sorry if this is re-posted. I am having some email problems right now. I posted last night and haven't seen my email show up just yet on the list - either on google or in my own emails from c.l.p (and I just checked and made sure that I am supposed to receive emails from myself). I am happy to announce the creation of Munkware, a brand new project on Sourceforge. Munkware is a transactional and persistent queueing system inspired by Queue.Queue() in the Python standard library. The project can be found at: http://sourceforge.net/projects/munkware/ Project home page is located at: http://munkware.sourceforge.net/ Anyhow, feedback is ecstatically welcome. Jeremy Jones From vanevery at 3DProgrammer.com Sat Aug 9 18:36:39 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Sat, 9 Aug 2003 15:36:39 -0700 Subject: Slogan: Getting Rich Overnight References: Message-ID: <3f357557@shknews01> Robert Kern wrote: > > While I certainly share that sentiment, I would advise caution in the > phrasing of such a slogan: if I hadn't seen your name, I would have > skipped your article as spam! I read it for amusement value. Nothing in computers gets you rich overnight, so I wanted to see how far the absurdity would go. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From ken at perfect-image.com Fri Aug 8 13:55:03 2003 From: ken at perfect-image.com (Ken Godee) Date: Fri, 08 Aug 2003 10:55:03 -0700 Subject: python -> C/perl api Message-ID: <3F33E3F7.8050100@perfect-image.com> I have a python program I need to interface with an api. The api is native C but they also have a perl wrapper. I'm thinking along the lines of "pyperl" or perhaps pyInline. I don't feel astute enough in C to create my own wrappers. Has anyone have any thoughts/experience on either of the above programs or perhaps a different idea to interface with the C/perl api? From bokr at oz.net Mon Aug 18 00:11:45 2003 From: bokr at oz.net (Bengt Richter) Date: 18 Aug 2003 04:11:45 GMT Subject: bitwise not - not what I expected References: <1YD%a.747879$3C2.17342633@news3.calgary.shaw.ca> Message-ID: On Sun, 17 Aug 2003 22:18:39 GMT, Dennis Lee Bieber wrote: >Michael Peuser fed this fish to the penguins on Sunday 17 August 2003 >02:41 pm: > >> >> I have the impression (may be wrong) that you are working under the >> misconception that there can be a "natural" binary represensation of >> negative numbers!? > > Apologies if I gave that impression... the +/- 0 technical affair is >the main reason I went into the whole thing... > >> Three conventions have commonly been used so far: >> 1- Complement >> 2-Complement >> Sign tag plus absolut binary values >> >> All of them have their pros and cons. For a mixture of very technical >> reasons (you mentioned the +0/-0 conflict, I might add the use of >> binary adders for subtraction) most modern computers use 2-complement, >> and this now leads to those funny speculations in this thread. ;-) >> > From a human readable standpoint, your third option is probably the >most "natural"; after all, what is -19 in human terms but a "pure" 19 >prefaced with a negation tag marker... (I believe my college >mainframe's BCD hardware unit actually put the sign marker in the >nibble representing the decimal point location -- but it has been 25 >years since I had to know what a Xerox Sigma did for COBOL packed >decimal ). > > ie, 00010011 vs -00010011 > > 1s complement is electrically easy; just "not" each bit. > > 2s complement is mathematically cleaner as 0 is 0, but requires an >adder to the 1s complement circuit... Though both complement styles >lead to the ambiguity of signed vs unsigned values > Everyone says "two's complement" and then usually starts talking about numbers that are bigger than two. I'll add another interpretation, which is what I thought when I first heard of it w.r.t. a cpu that was designed on the basis that all its "integer" numbers were fixed point fractions up to 0.9999.. to whatever precision the binary fractional bits provided. There was no units bit. And if you took one of these fractional values 0.xxxx and subtracted it from 2.0, you would have a complementary number with respect to two. Well, for addition and subtraction, that turns out to work just like the "two's complement" integers we are used to. But since the value of fractional bits were all in negative powers of two, squaring e.g., .5 had to result in a consistent representation of 0.25 -- i.e. in binary squaring 0.1 resulted in 0.01 -- which is shifted one bit from what you get looking at the numbers as integers with the lsb at the bottom of the registers and the result. I.e., a 32-bit positive integer n in the fractional world was n*2**-31. If you square that for 64 bits, you get n**2, but in the fractional world that looks like (n**2)*2**-63, where it's supposed to be (n*2**-31)**2 => (n**2)*2**-62 with respect to the binary point. The fractional model preserved an extra bit of precision in multiplies. So on that machine we used to count bits from the left instead of the right, and place imaginary binary points in the representations, so a binary 0.101 could be read as "5 at 3" or "2.5 at 2" or "10 at 4" etc. And the multiplying rule was x at xbit times y at ybit => x*y at xbit+ybit. You can do the same counting the bit positions leftwards from lsb at 0, as we usually do now, of course, to play with fixed point fractions. A 5 at 0 is then 1.25 at 2 ;-) Anyway, my point is that there was a "two's complement" implementation that really meant a numeric value complement with respect to the value two ;-) Regards, Bengt Richter From ayc8NOSPAM at cornell.edu Wed Aug 6 01:55:40 2003 From: ayc8NOSPAM at cornell.edu (Andy C) Date: Wed, 06 Aug 2003 05:55:40 GMT Subject: recompiled midipy.pyd for 2.3 References: Message-ID: I'd like to have a look. thanks, Andy "smarter_than_you" wrote in message news:c60a5a12.0308051327.141856e4 at posting.google.com... > this is a nice windows-based MIDI module with simple interface, it was > previously available for <= 2.0 release (See thread on midi for > win32). > > If anyone wants it please post a reply. From anthonyr-at-hotmail-dot-com at nospam.com Wed Aug 27 21:31:48 2003 From: anthonyr-at-hotmail-dot-com at nospam.com (Anthony Roberts) Date: Thu, 28 Aug 2003 01:31:48 GMT Subject: Style question... References: <3F4D35D4.1F7E0373@engcorp.com> Message-ID: <8Yc3b.854626$ro6.16943092@news2.calgary.shaw.ca> > Sorry, but yes, I find that ugly. If you're just starting out with > Python, please just give it a shot without that approach for a while > and see whether you become much more comfortable *without* the token > than you ever were with it. Well, when in Rome I guess. Having the closing token at the same indent level as the compound statement is ugly anyway. :) From rdacker at pacbell.net Sun Aug 10 19:18:57 2003 From: rdacker at pacbell.net (rdack) Date: 10 Aug 2003 16:18:57 -0700 Subject: dist problem on osx Message-ID: <644f6688.0308101518.ad9e02a@posting.google.com> osx 10.2.6 python 2.2.1 (built in) says my architecture is both 386 and ppc. also has a path with a space in it that won't work. where can i change these settings? -------- gcc -arch i386 -arch ppc -bundle -flat_namespace -undefined suppress build/temp.darwin-6.6-Power Macintosh-2.2/mx/DateTime/mxDateTime/mxDateTime/mxDateTime.o -L/usr/local/lib -L/usr/lib -o build/lib.darwin-6.6-Power Macintosh-2.2/mx/DateTime/mxDateTime/mxDateTime.so --------------- From syver-en+usenet at online.no Wed Aug 6 16:03:04 2003 From: syver-en+usenet at online.no (Syver Enstad) Date: 06 Aug 2003 22:03:04 +0200 Subject: MSVC 6.0 Unsupported? References: <3F302764.8010301@ghaering.de> Message-ID: Gerhard H?ring writes: > Syver Enstad wrote: > > "M.-A. Lemburg" writes: > > > >>The best thing to do is to replace this code in Python's object.h > >>file (Python23\Include\object.h; note the comment !): > > That's exactly what I did and it worked fine. > > Requiring users of my software to patch their Python instalation is > not an option for me. But Gerhard, what can I do? Every python extension that I will try to compile will fail if it depends on a working staticforward. The most rational thing to me is to patch object.h instead of patching every .cpp/.c file that needs this define. -- Vennlig hilsen Syver Enstad From dtolton at yahoo.com Mon Aug 18 18:14:31 2003 From: dtolton at yahoo.com (Doug Tolton) Date: Mon, 18 Aug 2003 22:14:31 GMT Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> Message-ID: <6dj2kv8ugkieehs7guh786cl40o5lj6mcs@4ax.com> On Mon, 18 Aug 2003 16:09:47 -0400, Roy Smith wrote: >Why do you need macros? There's a few things people do with them: > >1) Define constants. In Python, you just define symbols in your module, >and get over the fact that there really is no such thing as a constant >in Python. > >2) Define efficient pseudo-functions. In Python, you just define a >function (or method) and get over the fact that it's not as efficient as >a macro. If I cared about microseconds, I wouldn't be writing in Python. > >3) File inclusion. In Python, you don't include files, you import >modules. > >4) Conditional compilation. In Python, you can conditionally define >anything you want at import time. > >5) Inventing your own language constructs. In Python, you just don't do >this. I don't agree at all. Yes when you are defining a macro you are in essence defining a new mini-language. This is perhaps one of the most powerful features of Lisp. Programming closer to the application domain, *greatly* enhances both the readability and the reusability of code. Good Lisp programmers use Macros all the time. They are incredibly useful and powerful. The reason you don't do this in python is because the feature isn't available. That doesn't mean it *shouldn't* be available. Python is Open Source, how would someone writing a Macro lock you in? Just don't use the macro. Just like anything else, Macro's can be over used and abused. However I maintain that if you don't see the usefulness of macros, you don't really understand them. Essentially using Python over Machine language is just using one big ass macro language. They are there to allow you to create higher level abstractions, and tools that are more specifically useful to your application domain than a general purpose tool. Python is a Macro Language of Machine Language. Why don't you just program everything in Machine Language? Macros are to Python as Python is to C as C is to Machine Language. Python is great, as the trend shows, working at higher levels of abstraction though is the ultimate goal. Doug Tolton (format t "~a@~a~a.~a" "dtolton" "ya" "hoo" "com") From creedy at mitretek.org Thu Aug 21 18:30:37 2003 From: creedy at mitretek.org (Chris Reedy) Date: Thu, 21 Aug 2003 18:30:37 -0400 Subject: For Kenny Tilton: Why do I need macros revisited. Message-ID: <3f45484f$1_6@corp.newsgroups.com> For everyone - Apologies for the length of this message. If you don't want to look at the long example, you can skip to the end of the message. And for the Python gurus among you, if you can spare the time, I would appreciate any comments (including words like evil and disgusting, if you think they are applicable :-}) on the example here. Kenny - I asked my question about macros with some malice aforethought. This is a topic I've thought about in the past. > Andrew Dalke wrote: > >> Kenny Tilton: >> >>> This macro: >>> >>> (defmacro c? (&body code) >>> `(let ((cache :unbound)) >>> (lambda (self) >>> (declare (ignorable self)) >>> (if (eq cache :unbound) >>> (setf cache (progn , at code)) >>> cache)))) >> >> >> >> I have about no idea of what that means. Could you explain >> without using syntax? My guess is that it caches function calls, >> based only on the variable names. Why is a macro needed >> for that? I sympathize with Andrew on this. I had to study this and the following code for awhile before I figured out what you are doing. However, I do have an advantage, I know lisp and the macro system and just how powerful the macro system is. > (defun get-cell (self slotname) ;; this fn does not need duplicating > (let ((sv (slot-value self slotname))) > (typecase sv > (function (funcall sv self)) > (otherwise sv)))) > > (defmethod right ((self box)) ;; this needs duplicating for each slot > (get-cell box right)) > > But I just hide it all (and much more) in: > > (defmodel box () > ((left :initarg :left :accessor left) > (right :initarg :right :accessor right))) > > ....using another macro: > > (defmacro defmodel (class superclasses (&rest slots)) > `(progn > (defclass ,class ,superclasses > ,slots) > ,@(mapcar (lambda (slot) > (destructuring-bind > (slotname &key initarg accessor) > slot > (declare (ignore slotname initarg)) > `(defmethod ,accessor ((self ,class)) > (get-cell self ',slotname)))) > slots))) Ok. The following is more lines of code than you have here. On the other hand, I think it does about the same thing: class cellvalue(object): def __init__(self): self._fn = None def _get_value(self, obj): if hasattr(self, '_value'): return self._value else: value = self._fn if callable(self._fn): value = value(obj) self._value = value return value def _set_value(self, value): self._value = value def _del_value(self): del self._value def _set_fn(self, fn): self._fn = fn if hasattr(self, '_value'): self._del_value() class modelproperty(object): def _init_cell(self, obj): obj.__dict__[self.name] = cellvalue() def __get__(self, obj, cls): if obj is None: return self else: return obj.__dict__[self.name]._get_value(obj) def __set__(self, obj, val): obj.__dict__[self.name]._set_value(val) def __delete__(self, obj): obj.__dict__[self.name]._del_value() def setfn(self, obj, fn): obj.__dict__[self.name]._set_fn(fn) def setname(self, name): self.name = name self.__doc__ = 'Model Property '+str(name) class modeltype(type): def __init__(cls, name, bases, dict): super(modeltype, cls).__init__(name, bases, dict) modelprops = [] for attr, decl in dict.items(): if isinstance(decl, modelproperty): decl.setname(attr) modelprops.append(attr) if modelprops: __originit = getattr(cls, '__init__') def _modeltype_init(self, *args, **kw): for attr in modelprops: getattr(self.__class__, attr)._init_cell(self) if __originit is not None: __originit(self, *args, **kw) setattr(cls, '__init__', _modeltype_init) >>> class foo: ... __metaclass__ = modeltype ... x = modelproperty() ... def __init__(self, x=None): ... self.__class__.x.setfn(self, x) >>> z = foo(x=lambda self: self.a + 2) >>> z.a = 5 >>> print z.x 7 >>> z.x = -3 >>> print z.x -3 >>> z.a = 15 >>> print z.x -3 >>> del z.x >>> print z.x 17 I think that has most of the behavior you were looking for. As you can see from the example, I leaned (I'm not sure leaned is a strong enough work :-)) on the newer capabilities for metaclasses and descriptors. (And learned a lot about exactly how they work by writing this up!) Having looked at the two pieces of code, the only thing that struck me about how they're used is that the lambda expression needed in the Python version is clunkier than the version in the Lisp version. On the other hand, that might be addressed by a somewhat more elegant syntax in Python for constant code blocks, something that's been mentioned by others in recent messages. Even though the Python setup (with two classes and a metaclass) is longer than the Lisp version, I'm not sure it's any clunkier or harder to understand. So back to my original question, why do I want macros in Python? Let me provide a candidate answer and rebuttal: The real reason I want to do macros in Lisp is that they allow me to easily write new custom languages. Would a sufficiently powerful macro facility in Python allow me to do this? I suspect that the answer to this question would only be yes if that included some sort of parser generator facility. Expanding on that: One of the nice things about Python (at least for those like me who like the language) is the clean syntax. However, that comes at a price: Needing a real parser to parse the language. Lisp on the other hand has an extremely simple syntax that doesn't require a real parser. That allows me to create whole new "syntaxes" in lisp, since I'm not really changing the syntax, just changing how a given set of S-expressions are interpreted. On the other hand, if I'm going to go to the complexity of including a parser generator so I can generate my own custom languages, it sounds to me like I'm about to reproduce what the Perl/Parrot people are up to. (I admit that I'd really like the time to look at what they're doing more deeply.) Which brings me back to my original question: Would a macro facility in Python really buy me anything? And, in view of Alex's arguments, would that benefit outweigh the potential significant costs in other areas? Chris -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! -----== Over 100,000 Newsgroups - 19 Different Servers! =----- From tyler at tylereaves.com Thu Aug 21 22:24:58 2003 From: tyler at tylereaves.com (Tyler Eaves) Date: Thu, 21 Aug 2003 22:24:58 -0400 Subject: Got Python web host, yay! Now what? References: Message-ID: On Thu, 21 Aug 2003 16:47:07 +0000, Robert Oschler wrote: > I found a good web host that has Python 2.x support and I've set up an > account. It's LunarPages.com if you're interested . Do I have to do > anything special to run Python scripts, besides upload the script to the > cgi-bin directory? If so, please direct me to a good web page or doc that > goes into the necessary details. > > thx > > -- > > Robert Oschler 3 things to watch out for 1. Make sure permissions are set to 755 (chmod 755 yourscript.py) 2. Make sure the 'bang' line (the first line of the file) is correct. If python is at /usr/bin/python, the first line of the file should be exactly #!/usr/bin/python 3. Make sure your script outputs a Content-type (and possibly other, as needed) headers. Code sample: print 'Content-type: text/html' print '' From vze4rx4y at verizon.net Wed Aug 27 13:21:14 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Wed, 27 Aug 2003 17:21:14 GMT Subject: Proposal: Magic Constants References: <7h3r837ce12.fsf@pc150.maths.bris.ac.uk> Message-ID: > > > But these are existing literal syntax. I was thinking > > > more of random code where someone could currently > > > juxtapose a literal and an identifier, say, without an > > > intervening white space character. > > > > >>> 10and 1 > > 1 > > >>> 5or 7 > > 5 > > > > Very much a wart of the tokenizer, though. > > Ah, right. I forgot about alphabetic operators. > > Why do you call it a wart, though? I would have > thought that not requiring white space in that context > was a feature. Because the human eye/mind parses 10and as single a token. Raymond Hettinger From jjl at pobox.com Sat Aug 16 05:31:14 2003 From: jjl at pobox.com (John J. Lee) Date: 16 Aug 2003 10:31:14 +0100 Subject: Dictionary assignment References: Message-ID: <87isoyx82l.fsf@pobox.com> Istvan Albert writes: > Mark Daley wrote: > > > format[self.formats.get()][key] = current[key] > > Now, all disgust from my example aside, shouldn't this line cause a > > new key > > (whatever self.formats get() produces) whose contents are an exact copy of > > current? > > First you need to assure that format[self.formats.get()] contains > another dictionary as a value. Here is an example: > > >>>> a = {} > >>>> a[1] = {} > >>>> a[1][2] = 1 > > works as expected but > > >>>> a[2][3] = 4 > > will fail with KeyError:2 because this construct attempts to fetch the > value corresponding to key 2 and then add to that dictionary the 3/4 > key/value pair. > > It is indeed confusing, I never thought about it and caught me by > surprise that it is KeyError:2 that is being thrown. Maybe it's surprising to some Perl users. Personally, it doesn't surprise me (and I did come from Perl) that if you didn't add a key 2 to the dictionary a, it complains when you look up 2 in that dict. > As one parses the expression from left to right it reads as if the > assignment to key 2 comes first and only then does the assignment > to key 3 become "active". That's precisely what *does* happen, if you replace the first 'assignment to' in that sentence with 'item lookup' or 'indexing'. The key 2 is not automagically created when it's found to be missing. Perhaps you wanted: a.setdefault(2, {})[3] = 4 ? How would it know what to index-assign to a[2] otherwise? A dict? A list? Something else? > The error message one expects is that a[2] > does not support assigment. a[2] doesn't exist in your example above. John From matthew at barnes.net Tue Aug 19 02:17:06 2003 From: matthew at barnes.net (Matthew Barnes) Date: 18 Aug 2003 23:17:06 -0700 Subject: Unification of logging in Python's Standard Library Message-ID: <3a8e83d2.0308182217.7ccaf883@posting.google.com> With the inclusion of the new 'logging' module in Python 2.3, I'm wondering whether there are plans to update the rest of the Standard Library to use this module wherever there is logging to be done. I can think of a few Standard Library modules off the top of my head that currently "roll their own" logging system: asyncore.py BaseHTTPServer.py cgi.py doctest.py imaplib.py unittest.py A single, unified logging system across the entire Python Standard Library would be a worthy goal for some future release (Python 3000, or maybe even 2.4/2.5?). From gh at ghaering.de Sun Aug 3 19:42:05 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Mon, 04 Aug 2003 01:42:05 +0200 Subject: Python vs. Perl vs. PHP? In-Reply-To: <7b454334.0308031024.7b53fe46@posting.google.com> References: <7b454334.0307281002.41dae81b@posting.google.com> <7b454334.0307301611.1b40ff11@posting.google.com> <7b454334.0307311023.28900d57@posting.google.com> <7b454334.0308031024.7b53fe46@posting.google.com> Message-ID: <3F2D9DCD.7000200@ghaering.de> Fazer wrote: >>I personally find it much easier to learn about system administration >>and get my own dedicated server for EUR 39/month. > > 39? Where do you get such a good deal? http://hetzner.de/ - "Entry Server" EUR 39 http://www.server4free.de/ - EUR 30 http://www.server4free.de/ - VServer (basically User Mode Linux) - EUR 10 http://www.1und1.com/ - EUR 49 These are the cheapest offers of the relevant German providers. They all come with a considerable setup fee as well, so don't just look at the monthly fee. -- Gerhard From max at alcyone.com Mon Aug 25 19:01:47 2003 From: max at alcyone.com (Erik Max Francis) Date: Mon, 25 Aug 2003 16:01:47 -0700 Subject: Determinig position of a element in a list References: Message-ID: <3F4A955B.B1659F4A@alcyone.com> Przemo Drochomirecki wrote: > i'm wondering if there is any tricky way for doing following thing: > A - list of distinct integers (e.x. A = [1,3,7,11,14,15]) > very fast function determinig position of number x in list A > or -1 if x doesnt belong to A > Operator IN returns only false/true values > i can implement function index (e.x. index(5,A) = -1, index(7,A) = 2), > but > maybe there's is simpler(builtin?) solution Yep, the -- wait for it -- .index method on the list object: >>> A = [1, 3, 7, 11, 14, 15] >>> A.index(7) 2 -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ Every exit is an entry somewhere else. \__/ Tom Stoppard From wiebke.paetzold at mplusr.de Tue Aug 5 05:25:42 2003 From: wiebke.paetzold at mplusr.de (Wiebke Pätzold) Date: Tue, 05 Aug 2003 11:25:42 +0200 Subject: Classes in Python References: <14dsivkn40c0grotsti39cgsrde7v03hq4@4ax.com> Message-ID: On Tue, 05 Aug 2003 10:59:56 +0200, Peter Otten <__peter__ at web.de> wrote: >Judging from the Getting started section in >http://www.equi4.com/metakit/python.html, >vw[r.index] seems redundent, so > > >import Mk4py >db = Mk4py.storage("c:\\datafile.mk", 1) >vw = db.view("people") > >for r in vw: > if r.Nachname.startswith("Ge"): > print r.Nachname > > >would be the code to go with. >Less code == fewer occasions for errors, >and it might even run faster :-) > >Peter Hi Peter, it's great that you give yourself so much trouble. But want to create this program by classes. The programm that I create with functions is OK. Here is it. Perhaps it may help you. import sys import Mk4py import re db = Mk4py.storage("c:\\datafile.mk",1) vw = db.view("people") pattern = re.compile("ra.*") def func(row): try: nachname = row.Nachname except AttributeError: return 0 return pattern.search(nachname) is not None vf = vw.filter(func) for r in vf: print vw[r.index].Nachname Now I trid to create this program by classes: import sys import Mk4py import re db = Mk4py.storage("c:\\datafile.mk",1) vw = db.view("people") class PatternFilter: def __init__(self, pattern): self.pattern = re.compile(pattern) def __call__(self, row): try: nachname = row.Nachname except AttributeError: return 0 return self.pattern.search(nachname)is not None vf = vw.filter(PatternFilter("Ge.*")) for r in vf: print vw[r.index].Nachname But here I get an error: returned exit code 0. So I think that something is wrong with line: vf = vw.filter(PatternFilter("Ge.*")) My task is: I create a database that contains a table. For example'Nachname' This is a special fieldname. This program can search for a special letter. In my example it is 'G'. and the search takes place in 'Nachname'. Now I want to use regular expression. So that I can limit my search. For example: I can search for Ge and it is not relevant wich letters follow. And it should be solve under use classes. Wiebke From nospamius at lundhansen.dk Sun Aug 31 11:49:34 2003 From: nospamius at lundhansen.dk (Bertel Lund Hansen) Date: Sun, 31 Aug 2003 17:49:34 +0200 Subject: Declaration of an array of unspecified size References: Message-ID: Bertrand Geston skrev: >I suggest this code Thanks. My problem is solved. -- Bertel http://bertel.lundhansen.dk/ FIDUSO: http://fiduso.dk/ From zhoney at wildmail.com Mon Aug 25 14:04:05 2003 From: zhoney at wildmail.com (Zora Honey) Date: Mon, 25 Aug 2003 13:04:05 -0500 Subject: Help embedding python References: <3F4A469E.58B94F7C@engcorp.com> Message-ID: Peter Hansen wrote: > Zora Honey wrote: > >>My husband and I are writing a program that does a lot of math behind >>the scenes (c++) with a gui front (python/Tkinter). We've decided that >>we want the c++ to be the "driver", and so we want to embed the python. > > > It's a little unclear (to me) exactly what you're trying to do, > but in any case I can't imagine why you'd want to have C++ "drive" > the Python code (if that's what you meant by "driver", as opposed to > the more common sense as in "device driver") instead of the other > way around. > > And my inability to imagine why you want this is compounded by your > choice of Python and Tkinter for the front end. It is much more > common to have the front end be the "driving" code, and the back end > be "driven", especially in CPU-intensive applications as it sounds > like you have here. > > -Peter Okay. Let's assume that the choice to embed the python was a well-reasoned decision. Or assume that I want to embed some python for the pure joy of doing so. Can you help? -Zora From adalke at mindspring.com Fri Aug 1 04:40:20 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Fri, 1 Aug 2003 02:40:20 -0600 Subject: How do I get a reference to a KEY value of a dictionary? References: <645db655.0307311636.71923378@posting.google.com> Message-ID: Andy C: > Basically I want to create a graph with an adjacency list > representation, but I don't want any of the adjacency lists to have > duplicate strings when it is avoidable. Took me a while but I finally figured out what you're asking. Look in the docs for 'intern', which is a builtin. It's rarely used because most people don't worry about this sort of duplication. > Is this a waste of time? Because I know in python I cannot be certain > that the argument strings that are read from files are even garbage > collected anyway. I could certainly do the job with duplicate > strings, but it would seem wasteful. I am a C programmer, and old > habits die hard. You can never be certain that anything is every garbage collected. Python-the-language makes no guarantees on that. Python-in-C does make a stronger statement, but it's an implementation issue. As a C programmer you'll be happy that it's a reference counted scheme and so long as there are no cycles (which can't happen with a string), the string will be deallocated when your code lets go of it. This is true even of interned strings, at least in newer Pythons. If no one references an interned string, it too goes away. (Older Pythons make the strings immortal.) Here's how you might change your code. class GraphAccumulator: def __init__( self, fileFunction ): self.fileFunction = fileFunction self.adjList = {} # adjacency list def createEdge( self, node1, node2 ): # another way of doing by using a dictionary node1 = intern(node1) node2 = intern(node2) adjList = self.adjList if adjList.has_key( node1 ): adjList[ node1 ].append( node2 ); else: adjList[ node1 ] = [ node2 ]; # singleton edge list But personally I would put the intern outside of the graph code - either in the reader or the code between the reader and this one. Otherwise, consider: # fully connect the graph nodes = graph.adjList.keys() for n1 in nodes: for n2 in nodes: if n1 != n2: graph.createEdge(n1, n1) This does extra interning even though it isn't needed. But then again, normally I wouldn't worry about the interning at all. ... Perhaps I should... Hmmm... Andrew dalke at dalkescientific.com From hokiegal99 at hotmail.com Tue Aug 26 21:43:32 2003 From: hokiegal99 at hotmail.com (hokiegal99) Date: Tue, 26 Aug 2003 21:43:32 -0400 Subject: String find and replace References: <3F4C04F8.5070401@vt.edu> Message-ID: <3F4C0CC4.20400@hotmail.com> John Roth wrote: > Are you trying to rename the file? Look under os - Files and Directories > for the rename() function. It's 6.1.4 in the 2.2.3 docs. > > John Roth No, I'm trying to find 'this' in files and replace it with 'that' recursively through a directory. It works, but it doesn't actually commit the change to the files, it finds 'this' and reports that it replaced it with 'that', but when I run the scipt again it reports the same files that it just fixed. From irmen at -NOSPAM-REMOVETHIS-xs4all.nl Fri Aug 29 15:26:47 2003 From: irmen at -NOSPAM-REMOVETHIS-xs4all.nl (Irmen de Jong) Date: Fri, 29 Aug 2003 21:26:47 +0200 Subject: Getting class name In-Reply-To: References: Message-ID: <3f4fa8f2$0$49106$e4fe514c@news.xs4all.nl> Andreas Neudecker wrote: > Is there a similar solution to get the name of the function or method > you are currently "in"? Google, "python name of current function", I'm feeling lucky. Or if you're using Python 2.3+ : >>> import inspect >>> def foo(): ... return inspect.getframeinfo(inspect.currentframe())[2] ... >>> foo() 'foo' >>> --Irmen de Jong From mwh at python.net Wed Aug 20 05:51:34 2003 From: mwh at python.net (Michael Hudson) Date: Wed, 20 Aug 2003 09:51:34 GMT Subject: distutils References: Message-ID: <7h3y8xo4q1v.fsf@pc150.maths.bris.ac.uk> "Bryan" writes: > what is the correct way to pass custom values to a distutil's setup > script? i'd like to pass on the command line the libraries_dir > path. should i just parse it out from sys.argv? Um, most options already have an associated command line option... doesn't the --install-dir option to install_lib do what you want? Cheers, mwh -- Presumably pronging in the wrong place zogs it. -- Aldabra Stoddart, ucam.chat From FBatista at uniFON.com.ar Mon Aug 11 08:29:41 2003 From: FBatista at uniFON.com.ar (Batista, Facundo) Date: Mon, 11 Aug 2003 09:29:41 -0300 Subject: convert tuple to string Message-ID: #- My Proglem is, I get after a query on a mysql database with #- module MySQLdb a #- tuple but I need this output from database as a string. #- can anybody help? The best way to convert to a string is with str(). A general answer to a general question... . Facundo From jwbaxter at spamcop.net Mon Aug 4 20:21:22 2003 From: jwbaxter at spamcop.net (John Baxter) Date: Mon, 04 Aug 2003 17:21:22 -0700 Subject: time, calendar, datetime, etc References: Message-ID: In article , "Tim Peters" wrote: > [Dan Bishop] > > There were no leap years between 10 BC and AD 4, because after Julius > > Caesar's death, the priests in charge of the calendar mistakenly added > > leap days every 3 years instead of 4, and this had to be corrected. > > > > I wouldn't expect the datetime module to deal with that, though ;-) > > Thank you -- some people did . One interesting bit of reading about this stuff comes from the nice folks at http://www.wundermoosen.com (in fact, I see they've put out some more calendar white papers, including "How we figured out the Viking calendar.") Look under Calendar X for the Viking calendar paper, "The Mayan Calendar" and some others. The paper I was thinking of when I started this is around here somewhere, but I don't immediately see it on the site. It was referred to by (shipped with?) Calendar2000. It includes a good view of when various countries switched from Julian to Gregorian (and in at least one case switched back and switched again). --John From mpeuser at web.de Sat Aug 16 06:34:20 2003 From: mpeuser at web.de (Michael Peuser) Date: Sat, 16 Aug 2003 12:34:20 +0200 Subject: How to terminate a TkinterApp correctly? References: <3F3DFCF4.5020109@aon.at> Message-ID: I just notice a left over line from a test, that lambda is of no use at all! May be you will have to use WM_SAVE_YOURSELF instead of WM_DELETE_WINDOWS if you want to be sure to keep the widget absolutly intact. Between these two messages some tidying-up could aleady have happened behind the scene....So this is my fine example: ----------------------------- from Tkinter import * def killingAction(ev): print "Destroyed" def kidding(): print "not killing" l.config(text="just kidding") l.master.protocol("WM_DELETE_WINDOW",original) l=Label(text="Kill me!") l.pack() l.bind("",killingAction) original= l.master.protocol("WM_DELETE_WINDOW",None) l.master.protocol("WM_DELETE_WINDOW",kidding) mainloop() ------------------------------------------- Kindly Michael P From drlinux at columbus.rr.com Sat Aug 2 17:20:44 2003 From: drlinux at columbus.rr.com (Dave Reed) Date: Sat, 2 Aug 2003 17:20:44 -0400 Subject: boost python & 2.3 In-Reply-To: References: Message-ID: <200308021720.44862.drlinux@columbus.rr.com> On Saturday 02 August 2003 12:31, Robin Becker wrote: > I'm having trouble building boost python with Python 2.3 & msvc. I don't > remember this with 2.2.3 so I guess it must be related to 2.3. I'm > seeing lots of this > > C:\Python\devel\boost_1_30_0\boost/detail/ob_call_traits.hpp(89) : see > declaration of 'call_traits_chooser' > C:\Python\devel\boost_1_30_0\boost/detail/ob_call_traits.hpp(90) : error > C2059: syntax error : '{' > C:\Python\devel\boost_1_30_0\boost/detail/ob_call_traits.hpp(90) : error > C2143: syntax error : missing ';' before '{' > C:\Python\devel\boost_1_30_0\boost/detail/ob_call_traits.hpp(93) : error > C2143: syntax error : missing ';' before '{' > C:\Python\devel\boost_1_30_0\boost/detail/ob_call_traits.hpp(94) : error > C2955: 'type' : use of class template requires > template argument list > > Any ideas? > -- > Robin Becker What version of boost are you using? 1.30.0 won't work with Python 2.3; however, the CVS version of boost does work with Python 2.3. David Abrahams has indicated this on the boost list and I can confirm that it does work with Python 2.3 (at least on a Solaris 9 system). Dave From mwh at python.net Thu Aug 28 13:27:31 2003 From: mwh at python.net (Michael Hudson) Date: Thu, 28 Aug 2003 17:27:31 GMT Subject: [Zope-dev] Zope 2.7 running with Stackless 3.0 References: <3F4D44EB.5010500@tismer.com> Message-ID: <7h3fzjl66gg.fsf@pc150.maths.bris.ac.uk> Shane Hathaway writes: > On 08/27/2003 07:55 PM, Christian Tismer wrote: > > just by chance, I got into the position to try out > > Zope 2.7.0 beta 1/2, and since it needs Python 2.2.3 > > at least, and Stackless 3.0 was just ported to that, I tried > > to build Zope with Stackless 3.0. > > It works very very well! After a few patches to get the includes > > right, here the installation instructions. > > I am in awe. Cool. :-) > > However, I am also a little confused. As I understand it, Stackless > needs all C code to be non-reentrant, i.e. C code must never call back > into Python. But Zope has a lot of reentrant code, especially in > Acquisition and ZODB. Doesn't that prevent Zope from taking advantage > of Stackless continuations? I think this is the magic of stackless 3: it uses assembler to move pesky bits of the C stack away in some circumstances. Not all C code can safely have this done to it, mind, but most can (how often do you take the address of a stack variable and expect it to be valid for an extended period of time?). Cheers, mwh -- This proposal, if accepted, will probably mean a heck of a lot of work for somebody. But since I don't want it accepted, I don't care. -- Laura Creighton, PEP 666 From adalke at mindspring.com Tue Aug 19 14:39:25 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Tue, 19 Aug 2003 18:39:25 GMT Subject: python-dev Summary for 2003-08-01 through 2003-08-15 References: Message-ID: Alex Martelli: > My Python 2.3 installation on MS Windows *DOES* have > c:\Python23\Lib\site-packages\ ...! And if I recall correctly > so had the older Python 2.2 installation (under c:\Python22 > of course). So, what's different about yours...? You and Peter Hansen are both correct. Perhaps my memories are several years old? Maybe I was thinking of a 2.0 or a 1.5.2 install on Windows? I remember loooking for the win32 COM code, and finding it off the top-level directory. Andrew dalke at dalkescientific.com From cartermark46 at ukmail.com Sun Aug 17 07:35:14 2003 From: cartermark46 at ukmail.com (Mark Carter) Date: 17 Aug 2003 04:35:14 -0700 Subject: ClientCookie bug (followup) References: <87fzk4sav2.fsf@pobox.com> <87znibzrnx.fsf@pobox.com> <87oeypdh92.fsf@pobox.com> Message-ID: > *tell* people to copy from, instead of the code I explictly tell > people *not* to copy from? Ngghhh! :-) > Anyway, you have found another bug, so all is forgiven. > (the MSIE delayload feature is still a bit of a mess -- luckily, I can > pin the blame on the original author of that code, since it's pretty > directly ported from Perl ;) If we shadows have offended, Think but this, and all is mended- That you have but slumb'red here While these visions did appear. And this weak and idle theme, No more yielding but a dream, Gentles, do not reprehend. If you pardon, we will mend. And, as I am an honest Puck, If we have unearned luck Now to scape the serpent's tongue, We will make amends ere long; Else the Puck a liar call. So, good night unto you all. Give me your hands, if we be friends, And Robin shall restore amends. But seriously ... please standby and I will inform you of the outcome of your changes. From tebeka at cs.bgu.ac.il Mon Aug 4 03:04:25 2003 From: tebeka at cs.bgu.ac.il (Miki Tebeka) Date: 4 Aug 2003 00:04:25 -0700 Subject: popen eating quotes? References: Message-ID: <33803989.0308032304.71b5f0fb@posting.google.com> Hello Bryan, > >>> run_args('"abc"') > 'c:/program' is not recognized as an internal or external command, > operable program or batch file. Didn't check but maybe win32api.GetShortPath will help. (Get Mark's excellent package from http://starship.python.net/crew/mhammond/) HTH. Miki From afriere at yahoo.co.uk Sun Aug 24 22:23:48 2003 From: afriere at yahoo.co.uk (Asun Friere) Date: 24 Aug 2003 19:23:48 -0700 Subject: Python preinstalled on Windows - looking for details References: <3F48BE7B.961CFBA0@engcorp.com> Message-ID: <38ec68a6.0308241823.41b9f0cf@posting.google.com> Peter Hansen wrote in message news:<3F48BE7B.961CFBA0 at engcorp.com>... > Maybe get someone who has purchased such a machine to contact HP > tech-support and ask some similar questions. Something like "I found > this Python stuff on my machine and thought maybe my kid put it there. > Can I safely delete it to free up hard drive space? Will that break > anything and, if so, what?" Alternatively get that someone to delete it and see what happens ;) From clisp at mac.com Thu Aug 28 05:10:02 2003 From: clisp at mac.com (Chung Jiho) Date: 28 Aug 2003 02:10:02 -0700 Subject: IIS 6.0/Python problem Message-ID: <51bb029f.0308280110.7fa1709b@posting.google.com> Hello, We have been deploying our web application over win2k servers. It is written in Python and uses Active Scripting to meet our requirements that it must be ASP application. So far, it was O.K. But recently we discovered our application doesn't work on Windows 2003 server. Even simple page such as below results in 500 Server Error. <%@Language="Python"%> <% Response.Write("Hello, world?") %> Have any of you experienced similiar problem in Windows 2003 server/IIS 6.0 settings? VBScript and JScript ASPs are working well. I already allowed ASP scripting and checked "use parent path" on configuration dialog box. Here's my IIS log. ASP_0147 error number is too generic to give us any hint and the page above is not doing any real work. Python version is 2.3 and win32all version is 155 (both are latest.) 165.246.66.32, -, 8/26/2003, 16:57:33, W3SVC1, MULTI-SRV, 165.246.66.32, 15, 362, 368, 301, 0, GET, /drlistening, -, 165.246.66.32, -, 8/26/2003, 16:57:33, W3SVC1, MULTI-SRV, 165.246.66.32, 0, 363, 198, 500, 0, GET, /drlistening/Default.asp, |-|ASP_0147|500_Server_Error, 165.246.66.32, -, 8/26/2003, 16:58:12, W3SVC1, MULTI-SRV, 165.246.66.32, 0, 362, 368, 301, 0, GET, /drlistening, -, 165.246.66.32, -, 8/26/2003, 16:58:12, W3SVC1, MULTI-SRV, 165.246.66.32, 0, 363, 198, 500, 0, GET, /drlistening/Default.asp, |-|ASP_0147|500_Server_Error, 165.246.66.32, -, 8/26/2003, 16:58:12, W3SVC1, MULTI-SRV, 165.246.66.32, 0, 362, 368, 301, 0, GET, /drlistening, -, 165.246.66.32, -, 8/26/2003, 16:58:12, W3SVC1, MULTI-SRV, 165.246.66.32, 15, 363, 198, 500, 0, GET, /drlistening/Default.asp, |-|ASP_0147|500_Server_Error, TIA From creedy at mitretek.org Thu Aug 7 15:18:08 2003 From: creedy at mitretek.org (Chris Reedy) Date: Thu, 07 Aug 2003 15:18:08 -0400 Subject: catching exceptions in expressions In-Reply-To: References: Message-ID: <3f32a61a$1_6@corp.newsgroups.com> Vaclav Dvorak wrote: > Hi, > > Did I arouse nobody's interest except for Andrew? Nobody thinks catching > exceptions inside expressions would be a cool feature to have? > When Guido designed Python he made a clear separation between statements and expressions. (You might want to contrast this with Lisp where there is no difference between statements and expressions.) I find myself occasionally rebelling against this, most usually when using lambda expressions, where statements might come in handy. As I've gotten used to Python, I've also gotten used to the "Pythonic" notion that the way to handle these situations is to define a function and then invoke it. > Andrew Dalke wrote: > >> Vaclav Dvorak: >> [big snip] >>> Comments? Should I write a PEP? Am I missing something obvious? Has this >>> been debated a million times over already? >> >> >> Feel free to write a PEP. It won't be accepted. > > Why? You're the only one who doesn't like it, so far. ;-) Of course, > you're also the only one who voiced any opinion, so that leaves me with > a not so huge statistical sample of one. :-) > Were you here for the great "if-then-else" operator war? Given all the controversy associated with adding an if-then-else expression, I think any proposal to add any form of try-except expression is certainly doomed to failure. Chris -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! -----== Over 80,000 Newsgroups - 16 Different Servers! =----- From dreico at wanadoo.fr Fri Aug 29 16:45:35 2003 From: dreico at wanadoo.fr (Andrei) Date: Fri, 29 Aug 2003 22:45:35 +0200 Subject: cannot get pexpect to work References: <3F4F6AF0.CA9BB337@engcorp.com> <3F4F9152.ABC73E49@engcorp.com> Message-ID: > Unfortunately at this moment (13:45 EDT) I get no response to > connection requests on port 80. (That is, server is answering > pings, but no web server on standard port.) sorry, I had to bring the homeserver down because of a bad thunderstorm ... after which someone else must have taken the ip address=) here it is on another server which is altogether more impervious to meteorogical changes ... http://tufish.org/misc/passmass.py.txt From andymac at bullseye.apana.org.au Fri Aug 29 05:44:16 2003 From: andymac at bullseye.apana.org.au (Andrew MacIntyre) Date: Fri, 29 Aug 2003 19:44:16 +1000 (EST) Subject: another puzzled newbie In-Reply-To: References: <68g3b.855589$ro6.16997110@news2.calgary.shaw.ca> Message-ID: <20030829194017.A24765@bullseye.apana.org.au> On Fri, 29 Aug 2003, Elaine Jackson wrote: > | > for i in range(len(shuffler)): > | > shuffler[i]+=(-1) > | ^^^^ > | If you want a tuple here, it should be (-1,). It needs the comma. > | But, since shuffler is a list, you probably really want [-1]. > > No, I want (-1) the integer. My problem is that I really dislike the appearance > of a statement like X-=Y. (Even right now I can barely stand writing it.) So I > wrote X+=(-Y) instead. Maybe it would look better as shuffler=map(lambda n: n-1, > shuffler)? I find a little white space makes things more attractive and easier to read, ie: shuffler[i] += -1 YMMV... Regards, Andrew. -- Andrew I MacIntyre "These thoughts are mine alone..." E-mail: andymac at bullseye.apana.org.au (pref) | Snail: PO Box 370 andymac at pcug.org.au (alt) | Belconnen ACT 2616 Web: http://www.andymac.org/ | Australia From aleaxit at yahoo.com Tue Aug 19 05:31:13 2003 From: aleaxit at yahoo.com (Alex Martelli) Date: Tue, 19 Aug 2003 11:31:13 +0200 Subject: Unification of logging in Python's Standard Library References: <3a8e83d2.0308182217.7ccaf883@posting.google.com> Message-ID: Matthew Barnes wrote: > With the inclusion of the new 'logging' module in Python 2.3, I'm > wondering whether there are plans to update the rest of the Standard > Library to use this module wherever there is logging to be done. I > can think of a few Standard Library modules off the top of my head > that currently "roll their own" logging system: > > asyncore.py > BaseHTTPServer.py > cgi.py > doctest.py > imaplib.py > unittest.py > > A single, unified logging system across the entire Python Standard > Library would be a worthy goal for some future release (Python 3000, > or maybe even 2.4/2.5?). This seems a good idea, and quite feasible for 2.4 (we do have over a year before 2.4 is going to be feature-frozen, after all). I would suggest you post this proposal directly to Python-dev, though -- here on c.l.py it's too likely to get accidentally overlooked! Alex From davesum99 at yahoo.com Thu Aug 28 01:32:38 2003 From: davesum99 at yahoo.com (smarter_than_you) Date: 27 Aug 2003 22:32:38 -0700 Subject: My future Python IDE article References: <8a27e309.0308270848.6ca4f8c2@posting.google.com> Message-ID: Another shout-out for Pythoncard. It's at an early stage but I _really_ like the design philosophy. The code editor is nice (Boa might have a slight advantage here, but it's definitely usable). The GUI constructor is the best I've seen, and I've been shopping for a useful builder for a while. Best of all, unlike Boa, the code it generates is clean and well laid out, with a .rsrc.py file that is just a little list of dicts with parameters for all your widgets. YMMV ny_r_marquez at yahoo.com (R.Marquez) wrote in message news:<8a27e309.0308270848.6ca4f8c2 at posting.google.com>... > > So c.l.py readers... make the case for your favorite one getting on the > > list. I have a while to ponder the opinions advanced, should this > > prompt some discussion (it may take a little while to order review > > copies of commercial tools and/or get things installed). > > I work on Windows mostly, and Pythonwin has been great for a few > years, although it doesn't have any GUI building facilities. Lately, > due to a bug in the last release (which I have already submitted), I > have taken the opportunity to give others a try. I am not currently > interested in paying for an IDE. > > I tried BOA a little while ago. My first impression was "wow, someone > has done a lot of work here". However, I didn't like the fact that I > had to mold my code to the way the application wants it. For example, > I have to always have a "main" function. Maybe that is a good > practice, but being forced to it didn't give me a good feeling. The > code it generated for the GUI was a bit verbose and it... I don't > know. It just didn't seem to simplify things for me too much. I > probably should go back and give it another try one of these days. > > Idle is nice enough, although like Pythonwin, it doesn't have any GUI > building facilities. Surprisingly for me, I couldn't find some basic > features for simple code editing that I really like. For example, I > couldn't find a way to have white space visible. It also doesn't seem > to have an indentation guide feature, which I find very useful in > Pythonwin (this feature seems to me to be a must for a Python code > editor since indentation is so crucial in it). Also, I could not see > how to display line numbers (although it does have a "Go to line" > feature). > > I was surprised to find all of these features as well as most other > features that I expected for basic code editing on the PythonCard > prototype Code Editor. And, PythonCard is an actual Application > builder, with outstanding GUI building facilities and all. I think > that PythonCard has the potential to be the best IDE/App Builder for > Python. It uses wxPython as its foundation, which I think is most GUI > developers favorite *free* toolkit. Unfortunately, a lot of the > wxPython widgets have yet to be integrated. However, it is already > usable for simple GUI applications. So, if you haven't given a try I > would encourage you to do so. You may just see what I mean. > > I still like Pythonwin as my favorite Code Editor in Windows. But, > until my little bug is fixed I think I am sticking with PythonCard's > Code Editor. > > -Ruben From s at 3ntra.donotfreakingspamme.net Sat Aug 23 12:01:13 2003 From: s at 3ntra.donotfreakingspamme.net (s) Date: Sat, 23 Aug 2003 16:01:13 GMT Subject: Python newbie help References: <87fa5cfa.0308181126.c61bfa2@posting.google.com> <3f412b85.351181492@news.blueyonder.co.uk> Message-ID: I'm not of the opinion that these styles of teaching are bad, it's just how I learn. Once I feel comfortable with a language and can write a simple program, I can then branch out into the books and tutorials that are more like references. You may have a lower opinion of these types of books but I think they're really beneficial for people trying to get started and helping them branch out into something more useful. I'm still taking in suggestions. From hokiegal99 at vt.edu Tue Aug 5 22:45:25 2003 From: hokiegal99 at vt.edu (hokiegal99) Date: Tue, 05 Aug 2003 22:45:25 -0400 Subject: Adding PC Filename Extensions to Macintosh Filenames Message-ID: <3F306BC5.7000608@vt.edu> I've written a small script (with much help from this list) that searches through a directory for files without a PC filename extension like .doc .xls and then adds them. The reason for writing the script is that I'm migrating several dozen Mac users to PCs over the next few months and many of the Mac files do not have PC filename extensions. There are thousands of these files. The script runs on a Linux ftp server where the files are upload to. In testing, the script works OK. It needs work, for example I need to make certain that the strings I'm searching for to identify file types are correct. This would be easier if I could assign more than one string to string.find. I'm considering doing this: setpath = raw_input("Enter the path: ") for root, dirs, files in os.walk(setpath): old_fname = files for old_fname in files: new_fname = old_fname + '.xls' exclude = string.find(old_fname,'.xls') x = string.find(old_fname,'Excel.Sheet.') y = string.find(old_fname,'Microsoft Excel') z = string.find(old_fname,'Worksheet') p = x, y, z if p >= 1 and exclude == -1: newpath = os.path.join(root,new_fname1) oldpath = os.path.join(root,old_fname) os.rename(oldpath,newpath) print oldpath print newpath The script as it exists now is attached to this email. Please critique it and let me know how I can make it better or more accurate. All advice is welcome both positive and negative. I'd especially like to hear for people who could show me how I might make the script smaller and more efficent and ways in which I might ID file types more accurately. Thanks!!! -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: extensions-0.3.py URL: From mertz at gnosis.cx Tue Aug 19 23:17:36 2003 From: mertz at gnosis.cx (David Mertz) Date: Tue, 19 Aug 2003 23:17:36 -0400 Subject: What's better about Ruby than Python? References: Message-ID: Alexander Schmolck wrote previously: |Anyway, I still don't see a compelling reason why class statements |couldn't/shouldn't be mutating, rather than rebinding. Is there one? I don't think there is any reason why the statement 'class' COULD NOT do what you describe. But doing so seems much less Pythonic to me. In Python, there are a bunch of statements or patterns that ALWAYS and ONLY binds names. Having something that sometimes binds names, and other times mutates objects... and you cannot tell the difference without finding something that may be far away in the code.... well, that's not how Pythonistas like to think about code. In the first appendix to my book ( for the free version) I make quite a point of explaining what Python does without the sort of "convenient fiction" that most intros/summaries use. That is, usually the difference between binding a name and assigning a value is sort of brushed over, I guess so previous C, Pascal, Perl, Basic, etc. programmers won't get freaked out. I know Alexander already knows this... but heck, why miss some self-aggrandizement? Yours, David... X-Shameless-Plug: Buy Text Processing in Python: http://tinyurl.com/jskh -- mertz@ _/_/_/_/_/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY:_/_/_/_/ v i gnosis _/_/ Postmodern Enterprises _/_/ s r .cx _/_/ MAKERS OF CHAOS.... _/_/ i u _/_/_/_/_/ LOOK FOR IT IN A NEIGHBORHOOD NEAR YOU_/_/_/_/_/ g s From bgailer at alum.rpi.edu Thu Aug 14 12:32:43 2003 From: bgailer at alum.rpi.edu (Bob Gailer) Date: Thu, 14 Aug 2003 10:32:43 -0600 Subject: Py2.3: Feedback on Sets In-Reply-To: References: Message-ID: <5.2.1.1.0.20030814101129.0271ab20@66.28.54.253> After giving blanket approval to the docs I now add: I have a mission to set some new guidelines for Python documentation. Perhaps this is a good place to start. Example - currently we have: class Set( [iterable]) Constructs a new empty Set object. If the optional iterable parameter is supplied, updates the set with elements obtained from iteration. All of the elements in iterable should be immutable or be transformable to an immutable using the protocol described in section 5.12.3. Problems: The result of Set appears to be an empty Set object. The fact that it might be filled is hidden in the parameter description. The parameter description itself is hidden in the paragraph, making it harder to find, especially when the reader is in a hurry. Some suggested guidelines to improve readability and understandability: 1 - label each paragraph so we know what it is about 2 - have a function paragraph that briefly but completely describes the function 3 - have labeled sections for things that can be so grouped (e.g. parameters) 4 - start the description of each thing in a new paragraph. Example: class Set( [iterable]) function: Constructs a new empty Set object and optionally fills it. parameters: iterable [optional] if supplied, updates the set with elements obtained from iteration. All of the elements in iterable should be immutable or be transformable to an immutable using the protocol described in section 5.12.3. What do you think? If this layout is appealing, let's use the set docs as a starting point to model this approach. I for one am willing to apply this model to the rest ot the set docs, and help update other docs, but not all of them. BTW I also have a problem with the term "Common uses". "Common" suggests that these are better, or more frequent. I suggest "Some examples of application of sets". I also agree with the suggestion that operations that are synonymous be so indicated in the table. Bob Gailer bgailer at alum.rpi.edu 303 442 2625 -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.506 / Virus Database: 303 - Release Date: 8/1/2003 From imbosol at aerojockey.invalid Wed Aug 20 23:56:54 2003 From: imbosol at aerojockey.invalid (Carl Banks) Date: Thu, 21 Aug 2003 03:56:54 GMT Subject: Removing language comparisons References: Message-ID: A.M. Kuchling wrote: > I'm planning to drop this page from python.org because it's so outdated and > no one is around to maintain it. I'd volunteer, but the page would end up turning into an anti-Perl tirade. -- CARL BANKS http://www.aerojockey.com/software "You don't run Microsoft Windows. Microsoft Windows runs you." From aleax at aleax.it Wed Aug 6 11:58:52 2003 From: aleax at aleax.it (Alex Martelli) Date: Wed, 06 Aug 2003 15:58:52 GMT Subject: classes (table) References: <0dq1jv8lr19gph86urpi214bjpb3tlskkh@4ax.com> Message-ID: <0B9Ya.25311$an6.901972@news1.tin.it> Wiebke P?tzold wrote: > On Wed, 06 Aug 2003 11:31:39 GMT, Alex Martelli > wrote: > >>Wiebke P?tzold wrote: >> ... >>> import Mk4py >> >>I'm not experienced in this package, so I'm not sure this will >>work and can't test, but: >> >>> def __call__(self, row): >>> try: >>> nachname = row.Nachname >> >>Just change this to >> >> whatever = getattr(row, self.attributeName) >> >>Where self.attributeName can be any string, e.g. defaulting >>to 'Nachname' if you wish, as set e.g. in __init__. >> >> >>Alex > > but the user of the program should have the possibility to select in > wich column the search takes place. And he or she will, just as long as you provide said user with UI means to set the value of self.attributeName. What's so hard about it? > On the one hand the program must be in the situation to search in all > columns of the table for a special word. And on the other hand the > user have to determine in wich column the search after this special > word takes place. This is the task. And this two things must combined > in one program. Yes, you've said so a zillion times. So give your PatternFilter class's __init__ TWO arguments, already (it needs two, so why not give them two?), the regex to search for AND the column name to search on. Just as I said above. You might not have known about the getattr built-in function, but that's exactly what I'm pointing out there. So what's missing? There, let me try to put this into a program you might like, even though I can't run it because I don't use the Mk4py module on which all depends (and it's QUITE inconsiderate of you not to have that fact in better evidence, even in the subjects of your posts!!!): import sys import Mk4py import re db = Mk4py.storage("c:\\datafile.mk",1) vw = db.view("people") class PatternFilter: def __init__(self, pattern, colum): self.pattern = re.compile(pattern) self.attributeName = colum def __call__(self, row): try: whatever = getattr(self.row, self.attributeName) except AttributeError: return 0 return self.pattern.search(whatever) is not None regex = raw_input("Please enter the regex to search for:") colum = raw_input("Please enter the name of the column to search on:") vf = vw.filter(PatternFilter(regex, colum)) for r in vf: print getattr(vw[r.index], colum, "*NO COLUMN NAMED %r!!!*" % colum) Alex From wilkSPAM at OUTflibuste.net Sun Aug 3 16:49:38 2003 From: wilkSPAM at OUTflibuste.net (Wilk) Date: Sun, 03 Aug 2003 22:49:38 +0200 Subject: Python vs. Perl vs. PHP? References: <7b454334.0307281002.41dae81b@posting.google.com> <7b454334.0307301611.1b40ff11@posting.google.com> <7b454334.0307311023.28900d57@posting.google.com> <7b454334.0308031024.7b53fe46@posting.google.com> Message-ID: <877k5u79gd.fsf@flibuste.net> faizan at jaredweb.com (Fazer) writes: >> I personally find it much easier to learn about system administration >> and get my own dedicated server for EUR 39/month. > > 39? Where do you get such a good deal? 15EUR/month on http://lost-oasis.fr i write about them because they make a lot of contributions to open-source... -- William Dode - http://flibuste.net From Scott.Daniels at Acm.Org Sat Aug 23 18:03:10 2003 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sat, 23 Aug 2003 15:03:10 -0700 Subject: Modifying the {} and [] tokens In-Reply-To: References: Message-ID: <3f47e49d$1@nntp0.pdx.net> Geoff Howland wrote: > I want to modify the {} and [] tokens to contain additional > functionality they do not currently contain, such as being able to add > dicts to dicts, and other things that would be very helpful for me and > my team mates to have. You might want to contribute to pypy -- once their work is completed we'll have a python written fully in python that will allow you such experiments. I'm sorry, but I cannot resist complaining a bit about allowing such changes as implementable in modules: user A likes (and implements) your idea about {} + {}, user B thinks you are right, but where the two dictionaries share a coomon key, the value shoud be the sum of the two values. Either of these works, but modules expecting one will fail with the other. As a result, it seems a bad idea to allow modules to make such changes. I do _not_ mean that the experiment in redefining {} can/should not be tried, but rather the experiment must be environment-wide; it does not isolate nicely. As a practical matter, I suspect the current feeling is towards fewer, rather than more, punctualtion-based expressions -- they are harder to look up i na reference document. -Scott David Daniels Scott.Daniels at Acm.Org From mday at apple.com Thu Aug 21 16:32:21 2003 From: mday at apple.com (Mark Day) Date: Thu, 21 Aug 2003 13:32:21 -0700 Subject: tuple to string/list References: <538fc8e.0308211141.4bca8a8d@posting.google.com> Message-ID: <210820031332217843%mday@apple.com> In article <538fc8e.0308211141.4bca8a8d at posting.google.com>, WIWA wrote: > When I write: > > for i in range(len(month)): > output="Hits for",month[i], ":" , teller[i] > f.write(str(output)) > f.close() > > => this produces a tuple: > ('Hits for', 'Jan', ':', 0)('Hits for', 'Feb', ':', 2)('Hits for', > 'Mar', ':', 3) > > => whereas I would like the following output: > Hits for Jan: 0 > Hits for Feb: 2 > Hits for Mar: 3 > > Any easy way of obtaing this output? Your "output=..." line is building up a tuple. You could just build up a string instead. And don't forget that file.write does not add any newline, so you have to add it yourself. Try this: import os for i in range(len(month)): output="Hits for"+month[i]+":"+str(teller[i])+os.linesep f.write(output) f.close() You can also use the "print" statement to write to file-like objects. And you can use the "%" operator for string formatting: for i in range(len(month)): print >>f, "Hits for %s: %d" % (month[i], teller[i]) f.close() -Mark From jzgoda at gazeta.usun.pl Sun Aug 3 13:06:25 2003 From: jzgoda at gazeta.usun.pl (Jarek Zgoda) Date: Sun, 3 Aug 2003 17:06:25 +0000 (UTC) Subject: HOME Directory in posix and nt References: Message-ID: Jeff Epler pisze: > os.environ holds the system environment, so > home = os.environ['HOME'] > on unix, and > home = os.environ['HOMEPATH'] > on windows might be what you want. > > You could also try > home = os.path.expanduser("~") > which looks at HOME and pwd.getpwuid on unix, and at HOME, HOMEPATH, and > HOMEDRIVE on NT. Unfortunately, the latest is known to give strange results on Windows 2000. On my machine at work (W2K Sp3) it just returns string '%USERPROFILE%'. On my wife's WinXP Pro Sp1 it returns 'C:\', which is crap, since home directory is set to 'C:\Documents and Settings...' (that's the value of HOMEDRIVE + HOMEPATH and of USERPROFILE variables). -- Jarek Zgoda Registered Linux User #-1 http://www.zgoda.biz/ JID:zgoda at chrome.pl http://zgoda.jogger.pl/ From dtolton at yahoo.com Wed Aug 13 03:03:22 2003 From: dtolton at yahoo.com (Doug Tolton) Date: Wed, 13 Aug 2003 07:03:22 GMT Subject: Multi-Line Comment References: <4qofjvg3bh9smlnb1do4f0lhjga7bacnu3@4ax.com> <200308122306.48320.shalehperry@comcast.net> Message-ID: On Tue, 12 Aug 2003 23:21:16 -0700, Chad Netzer wrote: >(along with block indent/dedent with a decent editor) In emacs what are the key strocks for block indent and dedent? Man, I wonder if I'll even learn 10% of the Emacs keystrokes. Doug Tolton From mpeuser at web.de Thu Aug 14 07:14:41 2003 From: mpeuser at web.de (Michael Peuser) Date: Thu, 14 Aug 2003 13:14:41 +0200 Subject: Error solution References: Message-ID: "Sanjeev Trehan" schrieb im Newsbeitrag news:mailman.1060852019.2478.python-list at python.org... > Dear All, > I am a new to Python,just started few days back.I have installed > Python23.exe.Also downloaded the totorial of Guido van Rossum > Fred L. Drake, Jr., editor Release 2.3 > July 29, 2003 > > When I write in command line the following eoors come: > >>> print a > File"" Indentation error:Expected an indented block. > >>>lambda x:x+n > File"" return^ lambda x:x+n > Indentation error:Expected an indented block. This is definitely confusing, because Python Shell (at least version 2.2.2) will indent automatically if required. Thus there will normally not be a >>> prompt but a number of spaces.... What have you typed before? Kindly Michael P > > Please solve my problem and explain from where should I start learning Python. > Waiting for reply. > > Regards > Sanjeev > > > > From skip at pobox.com Mon Aug 11 15:28:56 2003 From: skip at pobox.com (Skip Montanaro) Date: Mon, 11 Aug 2003 14:28:56 -0500 Subject: IO timeout in threaded application In-Reply-To: <3F37EB6E.4080306@real.com> References: <3F37EB6E.4080306@real.com> Message-ID: <16183.61048.228691.131382@montanaro.dyndns.org> Gordon> What's the easiest way to accomplish that? Should I just Gordon> subclass smtplib's SMTP class and override the "connect" Gordon> function with one that creates a socket with a timeout? Right now that's probably your best bet. Setting timeouts from higher-level packages which use sockets has not yet been tackled. Skip From news at festina-lente.qc.ca Mon Aug 11 23:19:07 2003 From: news at festina-lente.qc.ca (Benoit Caron) Date: Mon, 11 Aug 2003 23:19:07 -0400 Subject: ANNOUNCE: Rekall V2.0.2 In-Reply-To: References: <5.2.1.1.0.20030810065523.02c3ed10@66.28.54.253> Message-ID: <3F385CAB.6000705@festina-lente.qc.ca> Istvan Albert wrote: > john at rygannon.com wrote: > >> I have made a lot of changes many of them as a direct result to >> everybodies >> suggests. I hope that I have got it right this time >> BTW I have add a lot of screen shots to the Contents->About >> Rekall->Screen >> Shots page > > > This is still so silly. > > On your page instead of directly linking to the screenshots you are > (just as abouve) listing the steps one needs to take to get there. > > The whole site makes no sense. If you have a product to sell you must > allow people to understand everything right away. I would get rid of > this whole you must register first nonsense. > > cheers, > > Istvan. > I suppose from the reaction to the quirks of the website that this kind of application would fill a need. Am I wrong? I myself had begun to play a bit (with only my pen, for the moment) with the idea of building this kind of application. The way I see the thing, it would be built that way : - Written in python : I want to (finally) learn it well, and I feel that the langage would do a better job than, say, Perl, for a thing looking like Access. - wxPython as the toolkit : it is more "usable" freely on windows due to the licensing/etc. on windows - Use an embedded database : if we want to "attack" Access, we must be "standalone" and must not need a "real,big" database installation. I thought about sqlite, but I did'nt dig enough on this to decide yet. Anyway, the point would be to make it possible to "switch" the model from a database system to an another. This way, the thing could be used as a "prototyping" solution. But I digress - Make it possible to build form easily. I thought about wrapping up wxGlade, for it feel for me as clear and easy to use, and the code looked clean at first sight. - Make it possible to use these forms as independant application, or export it : - Make it possible to "export" as a "website" : either by doing a report-like query, or by "translating" the built form to HTML. This would mean a way to use the core of the engine as a CGI wrapper, and to transform the XML format of the wxGlade form to an XHTML format, via XSLT probably. - Make it OpenSource. I looked at rekall and it look not that bad, but I hardly see how this can take away "mindshare" from Access. - Make it simple. I also looked at the well-hidden database features of OpenOffice.org, and it was just to confusing... and I just can't imagine a poor simple guy like myself diving in OOo source code... :o\ The goal being to build an application that make somebody able to build a small database-using application with no fuss, with the option of building "semi-automatically" a web interface to it's database. So, anybody think this would have users? PS : excuse my faulty english, it is obviously not my prime langage. From jjl at pobox.com Sat Aug 2 21:04:44 2003 From: jjl at pobox.com (John J. Lee) Date: 03 Aug 2003 02:04:44 +0100 Subject: re or html parser module, for wildcard search within html document? References: <4cec047f.0308011806.68d8d056@posting.google.com> Message-ID: <87r843blg3.fsf@pobox.com> mm2ps at yahoo.co.uk (Douglas) writes: [...] > Specifically, I want to replace any tag containing the word "font" > with a new tag. As I want to use some form of wild card for the > search, eg. <*font*>, should I use a regular expression module (re) or > one of the specific html parsers? If this should be done with an html Sounds like you could use HTMLParser.HTMLParser (rather than sgmllib or htmllib). A regexp might be simpler, though, if it gets the job done reliably & maintainably enough in practice. > parser module then which one and where is some easy going introductory > documentation, please? Moshe Zadka had some useful powerpoint slides which are probably still on the web somewhere. A bit out of date now, no doubt. John From aleaxit at yahoo.com Mon Aug 18 09:51:17 2003 From: aleaxit at yahoo.com (Alex Martelli) Date: Mon, 18 Aug 2003 15:51:17 +0200 Subject: advice choosing IDE References: Message-ID: Michael Peuser wrote: ... > PyQt and their GUI Builder (that would be free for non commercial work) if > you plan to do *a lot* of GUI applications. The GUI Builder is *not* an > Python IDE, so that is somewhat off topic ;-) theKompany's BlackAdder is a commercial Python IDE which supports PyQt (and the QtDesigner "GUI builder", etc etc); $50 for personal use and (I don't recall, exactly, but about) $300 for commercial use right now (will become higher when it gets out of beta, which should be soon -- so, grab it now while it's cheap, as purchasing the beta license will automatically upgrade to the non-beta when that time comes). "eric3" (which I haven't used but I've heard good things about) is a free Python IDE which also supports PyQt (and, I think, QtDesigner in particular) -- not sure if you're allowed to use that for commercial projects (in which case no doubt you'll need to purchase the appropriate commercial licenses for Qt and PyQt -- BlackAdder comes with the commercial licenses you need, including ones for redistribution if you purchase the commercial version of BlackAdder). Alex From tdelaney at avaya.com Wed Aug 13 19:22:10 2003 From: tdelaney at avaya.com (Delaney, Timothy C (Timothy)) Date: Thu, 14 Aug 2003 09:22:10 +1000 Subject: Python vs. C# Message-ID: <338366A6D2E2CA4C9DAEAE652E12A1DE9E0748@au3010avexu1.global.avaya.com> > From: Christopher Barber [mailto:cbarber at curl.com] > > I like the sentiment, but in practice there is no such thing > as comprehensive tests. That is true, but you *can* write tests for all code paths if you use coverage analysis tools. Doing that is of course only viable for small units. Note I'm not just talking about code coverage, but code *path* coverage. The other important thing is to include any and all failing cases in the tests with the expected behaviour - and to not remove them because "well, we know that's fixed now so we don't have to test". For example, just the other day I discovered a nasty little bug (purely by accident) where an encryption algorithm was producing nul characters. The output of the encryption was being placed into a std::string. I'm sure you can guess the result ... I've now added two test cases (currently failing) - one which tests the specific case found (that encrypting the string "a", storing the result in a std::string, then decrypting the cyphertext results in the string "a") and one which tests that the cyphertext does not contain a nul character. Tim Delaney From python-url at phaseit.net Thu Aug 7 12:49:59 2003 From: python-url at phaseit.net (Irmen de Jong) Date: Thu, 07 Aug 2003 16:49:59 -0000 Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Aug 7) Message-ID: QOTW: "To make the instructions even friendlier it would also help if 'but Whatever You Do DON'T UNZIP THE FREAKIN' THING - This Means YOU John Latter!' were in large, bold, and underlined type. And preferably a different colour." -- John Latter, on Python's install instructions "[about significant whitespace, dynamic typing, interpreted:] What's more, these are three of Python's greatest *strengths*. We resist all attempts to change these, and we (at least I) avoid other languages because they do not supply these features." -- Gary Herron Discussion ---------- Michele Simionato has written a nice graph drawing utility that makes use of the "DOT" graph description language, while Bengt Richter does it old-skool: in ASCII. There has been discussion on compiling Python with VC.NET. Anton Vredegoor argues that Windows (and .NET) is just a platform amongst many others. Also, Matt Gerrans provides answers to the question if Python on .NET (and Java, too: jython) is worthwile. Last week we had the identifier-counter, this week Bengt Richter created a book index creator (inspired by the question how to 'flatten' a dict). Paul Rubin posted a floating-point range() method. It appears very simple, but a few nasty issues are worth reading about in the replies. Fredrik Lundh shows how to decompress a gzipped string (for instance, obtained from a HTTP server that uses gzip compression). Raymond Hettinger points us at a new page in Python's documentation about unit testing. It shows how to run the tests directly instead of running them from the command line, with path issues and all that. In a big discussion about the qualities of the new datetime module, and its relation to the older time and calendar modules, Andrew Dalke writes about the usefullness of said new datetime module. Announcements ------------- Python 2.3 (final). Nineteen months in the making, Python 2.3 represents a commitment to stability and improved performance, with a minimum of new language features. Webware 0.8.1, a modular suite of Python components for developing Web applications, using servlets, server pages, and more. PyXML 0.8.3, the Python/XML distribution that contains the basic tools required for processing XML data, including parsers and standard interfaces such as SAX and DOM. Anobind 0.5.0, a Python/XML data binding, which is just a fancy way of saying it's a very Pythonic XML API. You feed Anobind an XML document and it returns a data structure of corresponding Python objects. SC-Track Roundup 0.6.0b4, an issue tracking system that is simple-to-use and -install with command-line, web and e-mail interfaces. Rebuild 1.0, a python module that replaces make. It is not a drop-in replacement, and does not use "makefiles." Instead, it includes a number of modules which try to be more intelligent about building projects. Python-mode (an X/Emacs major mode for editing Python source code) has been sourceforged. e4Graph 1.0a8, a C++ library that provides a reliable, efficient and portable persistent storage for graph like data. PythonCAD 9th release. This is a CAD package written in Python. PyKota 1.14, a complete Print Quota and Accounting solution for CUPS and LPRng. David Mertz continues his article on Twisted. PyTables 0.7, a hierarchical database package designed to efficently manage very large amounts of data. ======================================================================== Everything you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the daily python url http://www.pythonware.com/daily Mygale is a news-gathering webcrawler that specializes in (new) World-Wide Web articles related to Python. http://www.awaretek.com/nowak/mygale.html While cosmetically similar, Mygale and the Daily Python-URL are utterly different in their technologies and generally in their results. comp.lang.python.announce announces new Python software. Be sure to scan this newly-revitalized newsgroup at least weekly. http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce Brett Cannon continues the marvelous tradition established by Andrew Kuchling and Michael Hudson of summarizing action on the python-dev mailing list once every other week. http://www.python.org/dev/summary/ The Python Package Index catalogues packages. http://www.python.org/pypi/ The somewhat older Vaults of Parnassus ambitiously collects references to all sorts of Python resources. http://www.vex.net/~x/parnassus/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ The Python Business Forum "further[s] the interests of companies that base their business on ... Python." http://www.python-in-business.org The Python Software Foundation has replaced the Python Consortium as an independent nexus of activity http://www.python.org/psf/ Cetus does much of the same http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://python.sourceforge.net/peps/pep-0042.html The online Python Journal is posted at pythonjournal.cognizor.com. editor at pythonjournal.com and editor at pythonjournal.cognizor.com welcome submission of material that helps people's understanding of Python use, and offer Web presentation of your work. *Py: the Journal of the Python Language* http://www.pyzine.com Archive probing tricks of the trade: http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python&num=100 http://groups.google.com/groups?meta=site%3Dgroups%26group%3Dcomp.lang.python.* Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://www.ddj.com/topics/pythonurl/ http://purl.org/thecliff/python/url.html (dormant) or http://groups.google.com/groups?oi=djq&as_q=+Python-URL!&as_ugroup=comp.lang.python Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". -- The Python-URL! Team-- Dr. Dobb's Journal (http://www.ddj.com) is pleased to participate in and sponsor the "Python-URL!" project. From klappnase at web.de Tue Aug 5 11:36:13 2003 From: klappnase at web.de (klappnase) Date: 5 Aug 2003 08:36:13 -0700 Subject: Capture PID of child process Message-ID: Hello, everyone, I am running python2.2.2 on a linux box. I want to call a shell command and get the PID of this child process so I have the possibility to abort the child process while it is still running. I tried the popen2 module for that: self.pp = popen2.Popen3(cmd) cmdpid = self.pp.pid However I found that the PID returned by self.pp.pid is not the PID of the process of interest, but the PID of a subshell in which this child process is running. So if I do os.kill(cmdpid, 9) the subshell is killed, but the process I actually wanted to stop is happily running on. Does anyone have a clue what to do about that? Any help would be very appreciated. Thank you in advance Michael From tismer at tismer.com Fri Aug 8 22:59:27 2003 From: tismer at tismer.com (Christian Tismer) Date: Sat, 09 Aug 2003 04:59:27 +0200 Subject: Slogan: Getting Rich Overnight Message-ID: <3F34638F.9020201@tismer.com> Dear friends. During a conversation with good friends and newly acquired Pythonista, we were discussing Python, what it is in essence, and what it is giving to us. The people were Dinu Gherman, Giorgio Giacomazzi, a promizing newcomer in the Python noosphere, and myself. We were discussing how to advertize for Python, and Dinu spread some of the recent library enhancements, like - email package - XML parsers - distutils - add lots of other great stuff, here. Then, after a while of silence, Giorgio said something like """ Well, right. But despite of the libraries, I was hit by pure Python, by the following, simply by using it interactively: There are these lists, these tuples, and these dicts. They are immediately there, at my fingertips. And this is a feeling that I never had, before. Especially these dicts are incredible. This was a feeling like 'getting rich overnight'. """ I loved this statement very much, and I have to say, this is essentially my feeling for myself, since many years now. I could imagine that this might be a candidate for next year's Python congress' slogan. "Python makes you rich, overnight". Not by money, in the first place, but by multiplying your own capabilities, immediately. It needed the fresh experience of a newcomer to become aware of this, again. The ambiguity is obvious. On first reading, it will attract many. On second reading, those who are thinking "ahh, ohh, yes, not I understand" will remain. But that's ok for a good slogan! got rich overnight by Python! being rich since 1800 nights now - sincerely -- chris -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 pager +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From CousinStanley at hotmail.com Sun Aug 24 22:50:57 2003 From: CousinStanley at hotmail.com (Cousin Stanley) Date: Sun, 24 Aug 2003 19:50:57 -0700 Subject: JavaScript web scraping test cases? References: <87ekzg0y6e.fsf@pobox.com> Message-ID: John ... I'm not sure what types of applications you're looking for, but I have some JavaScript plots that might be interesting to test ... http://fastq.com/~sckitching/JS/Circle_MH.htm http://fastq.com/~sckitching/JS/DD_Circles.htm http://fastq.com/~sckitching/JS/Parabola.htm -- Cousin Stanley Human Being Phoenix, Arizona From tismer at tismer.com Thu Aug 28 13:33:21 2003 From: tismer at tismer.com (Christian Tismer) Date: Thu, 28 Aug 2003 19:33:21 +0200 Subject: [Zope-dev] Zope 2.7 running with Stackless 3.0 In-Reply-To: <3F4DF1E7.1010103@zope.com> References: <3F4D44EB.5010500@tismer.com> <3F4DF1E7.1010103@zope.com> Message-ID: <3F4E3CE1.5030405@tismer.com> Shane Hathaway wrote: > On 08/27/2003 07:55 PM, Christian Tismer wrote: > >> just by chance, I got into the position to try out >> Zope 2.7.0 beta 1/2, and since it needs Python 2.2.3 >> at least, and Stackless 3.0 was just ported to that, I tried >> to build Zope with Stackless 3.0. >> >> It works very very well! After a few patches to get the includes >> right, here the installation instructions. > > > I am in awe. Cool. :-) > > However, I am also a little confused. As I understand it, Stackless > needs all C code to be non-reentrant, i.e. C code must never call back > into Python. This has never been so. It was so that Stackless 1.0 could only do its switching if there was no recursive call, sure. But it was always allowed. Stackless 2.0 does it the brute-force way, by moving C stacks around. Stackless 3.0 does all of it, whatever is possible. That means, you can switch whatever, even extension C code with Python callbacks. But cooperative code can switch faster. > But Zope has a lot of reentrant code, especially in > Acquisition and ZODB. Doesn't that prevent Zope from taking advantage > of Stackless continuations? No continuations, tasklets. :-) ciao - chris -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 pager +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From exarkun at intarweb.us Fri Aug 29 10:54:23 2003 From: exarkun at intarweb.us (Jp Calderone) Date: Fri, 29 Aug 2003 10:54:23 -0400 Subject: Are lists at least as efficient as dictionaries? In-Reply-To: References: <781faf41.0308281604.51e48f45@posting.google.com> Message-ID: <20030829145423.GA30577@intarweb.us> On Fri, Aug 29, 2003 at 10:07:20AM +0200, Peter Otten wrote: > Narendra C. Tulpule wrote: > [ snip] > > And now for something completely different: > > >>>> x = ([],) > >>>> x[0] += ['something'] > > Traceback (most recent call last): > > File "", line 1, in ? > > TypeError: object doesn't support item assignment > > += calls the list.__iadd__(self, other) method, which seems to be > implemented as > > def __iadd__(self, other): > self.append(other) > return self self.extend(other), actually. But that's the basic idea, yea. > > The call of this method succeds, but the following assignment fails, because > tuples are immutable. This could only be remedied if all assignments > > a = a > > were silently ignored, or, if the += operator would not perform an > assignment, which has the disadvantage that it would no longer work for > immutables, so that > >>> i = 1 > >>> i += 1 > >>> print i > 1 # admittedly faked > >>> += could simply be syntactic sugar for a call to __add__ and then an assignment. This would work for mutable and immutable objects. > > You could change __iadd__() to > > def __iadd__(self, other): > return self + other > > but then sane behaviour in one special case comes at the cost of always > creating a copy of a potentially large (say more than 100 items :-) list. True, except that list.extend() exists. Jp -- "There is no reason for any individual to have a computer in their home." -- Ken Olson, President of DEC, World Future Society Convention, 1977 From fawcett at teksavvy.com Sun Aug 17 02:29:32 2003 From: fawcett at teksavvy.com (Graham Fawcett) Date: Sun, 17 Aug 2003 02:29:32 -0400 Subject: python for dev of CAD type software In-Reply-To: <836a2f21.0308162222.413fefaa@posting.google.com> References: <836a2f21.0308162222.413fefaa@posting.google.com> Message-ID: <3F3F20CC.7060405@teksavvy.com> Sanjay Minni wrote: >is python suitable for a production level >deployment of CAD type of software. >we may have to develop a specific purpose >visual designing software for an interior designer >to be deployed at several locations > >Sanjay Minni >www.planage.com > > http://www.pythoncad.org/ -- graham From robbie_cao at msn.com Fri Aug 1 23:51:54 2003 From: robbie_cao at msn.com (Robbie) Date: Sat, 2 Aug 2003 11:51:54 +0800 Subject: Is there the same function in python as atoi() in C Message-ID: Someone tell me, if not exist, how to write one with the same function? I have made a try, but there is no character type in python, so i failed, someone help me, thanks very much From newsgroups at jhrothjr.com Tue Aug 19 12:48:19 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Tue, 19 Aug 2003 12:48:19 -0400 Subject: Unification of logging in Python's Standard Library References: <3a8e83d2.0308182217.7ccaf883@posting.google.com> Message-ID: "Matthew Barnes" wrote in message news:3a8e83d2.0308182217.7ccaf883 at posting.google.com... > With the inclusion of the new 'logging' module in Python 2.3, I'm > wondering whether there are plans to update the rest of the Standard > Library to use this module wherever there is logging to be done. I > can think of a few Standard Library modules off the top of my head > that currently "roll their own" logging system: > > asyncore.py > BaseHTTPServer.py > cgi.py > doctest.py > imaplib.py > unittest.py > > A single, unified logging system across the entire Python Standard > Library would be a worthy goal for some future release (Python 3000, > or maybe even 2.4/2.5?). I'm going to agree with Andrew: write a PEP. Unittest, as far as I know, doesn't have a logging system, and I, for one, don't want to see it burdened with a completely unnecessary logging system. I can't comment on the other examples in your list because I've never used them, but unittest is part of my standard project life, and I like it the way it is, thanks. Kent Beck and the other people involved in the xUnit development put a lot of thought into how it works, and AFKC, lack of logging isn't one of the problems. John Roth From thomaso at best.com Wed Aug 6 07:38:09 2003 From: thomaso at best.com (Thomas Andrews) Date: Wed, 06 Aug 2003 11:38:09 GMT Subject: round(22.47,2) gives 22.469999999999999? In-Reply-To: <3f30e294$0$125$e4fe514c@dreader5.news.xs4all.nl> References: <3f30e294$0$125$e4fe514c@dreader5.news.xs4all.nl> Message-ID: Eric van Riet Paap wrote: > Hi, > > On python2.1.3, python2.2.1 and python2.2.3 round(22.47,2) gives > 22.469999999999999 . Does anyone know if this is a bug or some weird, yet > unexpected, behaviour? > > P.S. I haven't tested python2.3, but python1.5.2 doesn't have this problem. > In IDLE, just typing: >>> 22.47 22.469999999999999 That seems to indicate that 22.47 is best approximated by the floating number 22.499999999999. Rounding should probably not be used for gettting "formatable" values. Instead, you can do something like: >>> "%.2f" % 22.47 '22.47' if you want a string version of the number rounded to 2 decimal places. =thomas From aleaxit at yahoo.com Mon Aug 18 11:40:17 2003 From: aleaxit at yahoo.com (Alex Martelli) Date: Mon, 18 Aug 2003 17:40:17 +0200 Subject: simple text parser? References: Message-ID: Brandon J. Van Every wrote: > Alex Martelli wrote: >> >> Developing a program under each of two platforms you previously didn't >> know is no doubt a good way to compare several characteristics of >> those platforms. Out of curiosity -- are you relying on Usenet help, >> rather than a manual, for the C# version, too? > > Not exactly. I have 2 books on C#, but they don't talk about parsing > except > via XML. At some point I will ask about C# parsers, but probably not > until I get stuck on the Python way of doing things. I still don't understand why you need parsing for your expressed purpose (saving data to disk and restoring them, with no effort) -- surely C# has its own object-serialization modules already implemented for your use, just like Python has cPickle and Java its own serialization library modules. Alex From aleaxit at yahoo.com Fri Aug 15 10:57:42 2003 From: aleaxit at yahoo.com (Alex Martelli) Date: Fri, 15 Aug 2003 16:57:42 +0200 Subject: cPickle alternative? References: Message-ID: Drochom wrote: > Hello, > I have a huge problem with loading very simple structure into memory > it is a list of tuples, it has 6MB and consists of 100000 elements > >>import cPickle > >>plik = open("mealy","r") >>mealy = cPickle.load(plik) >>plik.close() > > this takes about 30 seconds! > How can I accelerate it? > > Thanks in adv. What protocol did you pickle your data with? The default (protocol 0, ASCII text) is the slowest. I suggest you upgrade to Python 2.3 and save your data with the new protocol 2 -- it's likely to be fastest. Alex From glc at well.com Sun Aug 24 10:50:24 2003 From: glc at well.com (Greg Chapman) Date: Sun, 24 Aug 2003 14:50:24 GMT Subject: Where is sys.path set? References: Message-ID: On Sat, 23 Aug 2003 17:00:02 -0400, Pierre Rouleau wrote: >I can't remember where/how sys.path is set (aside from the automatically >loaded site.py) and i get a strange entry in it. Can anyone remind me >where/how to control sys.path on a Win32 machine (i'm running XP on the >one where the issue arises). > >I can't figure out why the 'C:\WINDOWS\System32\python23.zip' entry is >inside sys.path. That file/dir does not exist on the disk. Could a >failing (crashing) Pythonwin installation caused that? > The python23.zip entry has to do with the support for loading modules from zip files. See http://www.python.org/peps/pep-0273.html (esp. the section headed "Booting"). Otherwise, I think the best description of how sys.path is set on windows comes from a long comment at the top of PC/getpathp.c from the source code: /* ---------------------------------------------------------------- PATH RULES FOR WINDOWS: This describes how sys.path is formed on Windows. It describes the functionality, not the implementation (ie, the order in which these are actually fetched is different) * Python always adds an empty entry at the start, which corresponds to the current directory. * If the PYTHONPATH env. var. exists, it's entries are added next. * We look in the registry for "application paths" - that is, sub-keys under the main PythonPath registry key. These are added next (the order of sub-key processing is undefined). HKEY_CURRENT_USER is searched and added first. HKEY_LOCAL_MACHINE is searched and added next. (Note that all known installers only use HKLM, so HKCU is typically empty) * We attempt to locate the "Python Home" - if the PYTHONHOME env var is set, we believe it. Otherwise, we use the path of our host .EXE's to try and locate our "landmark" (lib\\os.py) and deduce our home. - If we DO have a Python Home: The relevant sub-directories (Lib, plat-win, lib-tk, etc) are based on the Python Home - If we DO NOT have a Python Home, the core Python Path is loaded from the registry. This is the main PythonPath key, and both HKLM and HKCU are combined to form the path) * Iff - we can not locate the Python Home, have not had a PYTHONPATH specified, and can't locate any Registry entries (ie, we have _nothing_ we can assume is a good path), a default path with relative entries is used (eg. .\Lib;.\plat-win, etc) The end result of all this is: * When running python.exe, or any other .exe in the main Python directory (either an installed version, or directly from the PCbuild directory), the core path is deduced, and the core paths in the registry are ignored. Other "application paths" in the registry are always read. * When Python is hosted in another exe (different directory, embedded via COM, etc), the Python Home will not be deduced, so the core path from the registry is used. Other "application paths" in the registry are always read. * If Python can't find its home and there is no registry (eg, frozen exe, some very strange installation setup) you get a path with some default, but relative, paths. ---------------------------------------------------------------- */ --- Greg Chapman From adalke at mindspring.com Fri Aug 22 22:34:23 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Sat, 23 Aug 2003 02:34:23 GMT Subject: Sort a Dictionary References: Message-ID: Afanasiy: > This is fairly simple in PHP, how do I do it in Python? > > http://www.php.net/manual/en/function.ksort.php def ksort(d, func = None): keys = d.keys() keys.sort(func) return keys for k in ksort(d): print k, v As a bonus, you don't need to tell the sort to sort numerically vs. lexigraphically --- Python's strong typing knows that by default. You can pass in an alternate compare function if you want. And no, I haven't tested it. ;) Andrew dalke at dalkescientific.com From tjreedy at udel.edu Mon Aug 11 21:26:19 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 11 Aug 2003 21:26:19 -0400 Subject: Fun with numbers - dammit, but I want a cast! References: <3f378fac$0$10778$afc38c87@auth.uk.news.easynet.net> <840592e1.0308111236.63bd85c0@posting.google.com> Message-ID: "Hannu Kankaanp??" wrote in message news:840592e1.0308111236.63bd85c0 at posting.google.com... > By the way, do you know a reason why after doing > > from __future__ import division > > this still happens: > > >>> 3.0 // 2 > 1.0 This follows the general rule that float op int is a float. > Wouldn't it be more convenient to present the resulting whole > number as an integer now, since division operation on integers > works correctly? At least IMO the operation > > >>> 3.0 // 2 > 1 > > would be more convenient and natural, and floor division could then be > used to get array indices for example: A language designer has to think through all the ramifications of each decision and not locally optimize. Guido has done fairly well at this, and probably better than most of us would. He might someday decide to go for further number unification -- of integers and floats -- but there are questions to consider. What would you have 2.22222e300/2 be? A loooong long? Should 2.5*4.0 become an int (so it can be an array index)? Should 'normal' users of floats (for math calculation) be time-penalized by automatically adding an isint? check to each float operation just so the occasional user who actually want the conversion can get it without being explicit? (I think not.) Terry J. Reedy From brandon at its.caltech.edu Wed Aug 13 16:19:22 2003 From: brandon at its.caltech.edu (Brandon Michael Moore) Date: Wed, 13 Aug 2003 13:19:22 -0700 (PDT) Subject: random value generation In-Reply-To: Message-ID: On Wed, 13 Aug 2003, Colin J. Williams wrote: > Brandon Michael Moore wrote: > > I'm trying to test a web application using a tool written in python. I > > would like to be able to generate random values to put in fields. I would > > like to be able to generate random dates (in a specified range), random > > strings (specifying allowed characters and a distribution of lengths), or > > choose randomly between several generators (for better control of the > > distribution of values). > > > > Brandon > > > numarray, the package which is being developed to replace Numeric > has random_array. It permits one to generate random arrays or > single values, with a number of statistical distributions. > > Colin W. Thanks, but I want to generate more than just numbers. I'll remember it if I ever have any monte carlo work to do. For now all I really need are dates, numeric strings, and alphanumeric strings. For unit testing the code it would be nice to generate other things, like objects, or graphs of objects. How many people out there are doing randomized testing? Are you generating test data with random.py and bare code, or have you written libraries to help you define test data generators? Or are tree structured data and randomized unit testing things people only do in Haskell-land? Brandon From eric.brunel at pragmadev.com Thu Aug 7 05:15:37 2003 From: eric.brunel at pragmadev.com (Eric Brunel) Date: Thu, 07 Aug 2003 11:15:37 +0200 Subject: Tkinter programming problem References: <2830c89c.0308010048.403a2a19@posting.google.com> <2830c89c.0308040201.7c70695d@posting.google.com> <3F3209CD.5040701@libero.it> Message-ID: furliz wrote: >> I did try self.frame.destroy as the function self.frame.destroy(), >> but the Quit button still didn't work. The >> application can be closed via the window corner X, but I'm still >> puzzled as to why it does not respond to Quit. >> >> Any more suggestions? > > > why don't use 'sys.exit(0)' as command? > Ex: > quitButton = Button(root,text="Quit",command=sys.exit(0)) Don't do that!! Written like above, sys.exit(0) will be called when the button is *created*, not when it is pressed! If you want to do that, write: quitButton = Button(root, text='Quit', command=lambda: sys.exit(0)) -- - Eric Brunel - PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com From urbanlegend at ozemail.com.au Wed Aug 6 06:11:38 2003 From: urbanlegend at ozemail.com.au (M Wells) Date: Wed, 06 Aug 2003 20:11:38 +1000 Subject: Python 2.3 and MySQL on Windows XP? Message-ID: Hi All, Well, laugh, it appears my progress in learning Python is going to be a little more complex than I first thought. Am I right in understanding that currently MySQLdb isn't available for Windows to support Python 2.3? This is my primary purpose for Python, so I'm wondering if anyone knows when MySQLdb will be available in a version for windows xp supporting 2.3? Any help immensely appreciated! Much warmth, Murray http://www.planetthoughtful.org Building a thoughtful planet, one snide comment at a time... From ayc8NOSPAM at cornell.edu Fri Aug 1 21:43:50 2003 From: ayc8NOSPAM at cornell.edu (Andy C) Date: Sat, 02 Aug 2003 01:43:50 GMT Subject: anti-aliased 2D vector graphics References: Message-ID: Thanks for the suggestion, I think this will work fine for what I'm doing. A little off topic, but is this how it is typically done? Is there a special case for lines vs. fonts? "Christos TZOTZIOY Georgiou" wrote in message news:tptkivkpmm0g1q1hr9de9f49p7b3ltcale at 4ax.com... > On Fri, 01 Aug 2003 07:57:29 GMT, rumours say that "Andy C" > might have written: > > >Where can I get a python package to draw such figures? I googled and found > >PyX, I guess it outputs PostScript. I guess I can get a PostScript to BMP > >converter or something. Is there any other alternative? > > > >I have looked at PIL, but it doesn't seem to support drawing anti-aliased > >figures. Thanks for any suggestions. > > Use PIL, and draw on an image twice the size (2*width, 2*height) as the > one you want. When you're done, resize the image --BILINEAR works fine > in this case. > > You will need to draw thicker lines & arcs (I don't remember ATM if you > can use a parameter with drawing methods)... create a custom > class to manage drawing double lines and arcs / circles when needed. > -- > TZOTZIOY, I speak England very best, > Microsoft Security Alert: the Matrix began as open source. From alanmk at hotmail.com Fri Aug 29 10:31:17 2003 From: alanmk at hotmail.com (Alan Kennedy) Date: Fri, 29 Aug 2003 15:31:17 +0100 Subject: how fast is Python? References: <8765khzhl8.fsf@voodoo.fake> Message-ID: <3F4F63B5.D2684868@hotmail.com> [Steve Horsley] >> Have you heard of Jython - python language running on a java VM? >> It's kind of double interpreted - the python source is converted >> to JVM bytecode, and then the JVM runs it however that JVM runs >> bytecode. I guess it should be many times faster than python >> because of the JVM performance, and wopuld be interested to hear >> any comparisons. [Lawrence Oluyede] > Jython faster than Python? We did little test and it doesn't seem, look: > http://tinyurl.com/liix Please bear in mind that the test code included the start up time for interpreter. For jython, this is a high cost, because starting a JVM often takes up to 10 seconds or more. It would probably be fairer to run timings after the VM has already been through the startup phase. I think that is a more valid reflection of real-world scenarios where a VM gets started once and left running for a long time. regards, -- alan kennedy ----------------------------------------------------- check http headers here: http://xhaus.com/headers email alan: http://xhaus.com/mailto/alan From dreico at wanadoo.fr Tue Aug 5 16:30:04 2003 From: dreico at wanadoo.fr (Andrei D.) Date: Tue, 5 Aug 2003 22:30:04 +0200 Subject: managing stdout and stderr neatly while doing parallel processing Message-ID: Hello Python newsgroup, In the process of developing a big ssh wrapper for sending commands to multiple hosts over the last few months, I (almost accidentally, considering I'm really just an "amateur hacker" :-) was very pleased to discover at one stage how to run processes in parallel using python, which is powerful technology to say the least, applicable not only in my project but in lots of other areas as well. Anyway, what I wanted to ask was about managing the output of stderr as well as stdout, using select.select and your common garden os.popen in this case. This is the script that will define my problem (which is really in another context altogether, but just to keep the explanation/background short and sweet for now): [0] user1/scripts/python> cat parallel7.py #!/usr/bin/python import os import select import string def keyboard_interrupt(): print "<<<<< Keyboard Interrupt ! >>>>>\n" os._exit(1) def getCommand(count): return "echo %i: ; ls kjfdjfkd ; ls -l parallel7.py" % (count) def main(): readPipes=[] for count in range(1,6): readPipes.append(os.popen(getCommand(count))) while 1: try: # Could put a timeout here if we had something else to do readable,writable,errors=select.select(readPipes,[],[]) for p in readable: print p.read() readPipes.remove(p) # os.wait() # Don't want zombies if len(readPipes)==0: break except KeyboardInterrupt: print keyboard_interrupt() if __name__=="__main__": main() So ... the basic problem is that the response from 'ls kjfdjkfd' is not thrown out in the 'right order' ... observe: [0] user1/scripts/python> ./parallel7.py ls: kjfdjfkd: No such file or directory ls: kjfdjfkd: No such file or directory ls: kjfdjfkd: No such file or directory 1: -rwxr-xr-x 1 user1 user1 814 Aug 5 22:10 parallel7.py 2: -rwxr-xr-x 1 user1 user1 814 Aug 5 22:10 parallel7.py ls: kjfdjfkd: No such file or directory 4: -rwxr-xr-x 1 user1 user1 814 Aug 5 22:10 parallel7.py 5: -rwxr-xr-x 1 user1 user1 814 Aug 5 22:10 parallel7.py ls: kjfdjfkd: No such file or directory 3: -rwxr-xr-x 1 user1 user1 814 Aug 5 22:10 parallel7.py [0] user1/scripts/python> In fact stdout in stages 1 to 5 isn't even necessarily thrown out in the correct order either, but I'll tackle that separately at another time (unless it's of direct relevance here?). I guess my question is really: how do you handle the different elements i.e. readable,writable,errors=select.select(readPipes,[],[]) in order to get an ordered output of errors as well, like you'd obviously get doing a loop in the shell like so (even though this is of course a sequential / not parallel operation): [0] user1/scripts/python> for i in `seq 1 5` ; do echo $i ; ls sdfdskjsdj ; ls -l parallel7.py ; done 1 ls: sdfdskjsdj: No such file or directory -rwxr-xr-x 1 user1 user1 814 Aug 5 22:10 parallel7.py 2 ls: sdfdskjsdj: No such file or directory -rwxr-xr-x 1 user1 user1 814 Aug 5 22:10 parallel7.py 3 ls: sdfdskjsdj: No such file or directory -rwxr-xr-x 1 user1 user1 814 Aug 5 22:10 parallel7.py 4 ls: sdfdskjsdj: No such file or directory -rwxr-xr-x 1 user1 user1 814 Aug 5 22:10 parallel7.py 5 ls: sdfdskjsdj: No such file or directory -rwxr-xr-x 1 user1 user1 814 Aug 5 22:10 parallel7.py Any ideas or comments on this or any related issues would be much appreciated. Perhaps pexpect will help? I suspect it may well do ... Thanks, A. From peter at engcorp.com Thu Aug 28 18:19:31 2003 From: peter at engcorp.com (Peter Hansen) Date: Thu, 28 Aug 2003 18:19:31 -0400 Subject: Python quote of the week? References: <3F4E42F2.BA7FB9F9@engcorp.com> <3f4e554e$0$27038$626a54ce@news.free.fr> Message-ID: <3F4E7FF3.743FEFD@engcorp.com> Bruno Desthuilliers wrote: > > Peter Hansen wrote: > > Simon Brunning wrote: > > > >>"All that rigid type safety and data hiding is like wearing army boots on > >>the beach: nothing can bite your toes, but golly don't it feel good to just > >>toss 'em and run barefoot." > >> > > (snip) > > > Going barefoot is of course also the more agile way to go: > > > > "Be more agile: program barefoot, with Python." > > > > Beware, some might read it as 'program with your feet with Python' !-) Well, given the lesser need to use the shift key to type all that funky punctuation, those amongst us unfortunate enough to have to program with their feet may still find Python the best language around... ;-) -Peter From jjl at pobox.com Sun Aug 3 17:02:48 2003 From: jjl at pobox.com (John J. Lee) Date: 03 Aug 2003 22:02:48 +0100 Subject: PyChecker work with Python 2.3? References: <3F2C5300.FA223CBA@easystreet.com> Message-ID: <87zniqbgjr.fsf@pobox.com> achrist at easystreet.com writes: > The pychecker site says that pychecker works with versions > 1.5 through 2.2. Any reason to expect that 2.3 breaks it? > Anyone tried it to see? No, but 2.3 has no major language changes, and concentrates on library improvements, so I'd guess it's likely there are no major problems running Pychecker. John From jjl at pobox.com Tue Aug 12 20:41:33 2003 From: jjl at pobox.com (John J. Lee) Date: 13 Aug 2003 01:41:33 +0100 Subject: Summer reading list References: <5d0_a.288$jw4.85@nwrdny03.gnilink.net> Message-ID: <87vft2crsy.fsf@pobox.com> Chad Netzer writes: > On Tue, 2003-08-12 at 08:56, Joe Cheng wrote: > > > Quoting from the comments: > > > > """Usage: > > > > heap = [] # creates an empty heap > > heappush(heap, item) # pushes a new item on the heap [...] > > It might just be my Java background creeping in (I'm a Python newbie), but, > > wouldn't it be better if this was OO? > > > > heap = Heap() > > heap.push(item) [...] > > Otherwise the user could easily break the heap by doing something dumb to > > the list... > > True. But the flexibility of using the builtin is also nice. For > example, you can add a bunch of objects to the list, then heapify once, > rather than having to call heap.push() a bunch of times (which may be > slower, because you need to maintain the heap property after you push > each new item.) I don't know what the design goals were, but perhaps there is benefit in having heapq generic, rather than rigidly OO. Certainly Numeric was deliberately designed this way -- so ufuncs could be applied to any old sequence, not just Numeric arrays (do I mean ufuncs?... it's been a while since I used Numeric). > I think the idea is that, if you want a real Heap class, you can build > one very easily (see below). And if you don't need a heap class, you Certainly true, as Chad goes on to prove. John From isaac at blueapples.org Fri Aug 1 12:45:19 2003 From: isaac at blueapples.org (Isaac Raway) Date: 1 Aug 2003 09:45:19 -0700 Subject: SSH and Windows References: <3F2069BD.1FE2EC2@engcorp.com> Message-ID: <5f98b3f0.0308010845.22988990@posting.google.com> Peter Hansen wrote in message news:<3F2069BD.1FE2EC2 at engcorp.com>... > Isaac Raway wrote: > > > > Hello. I'm writing a Python program that connects to servers through > > telnetlib to execute a few commands. I've discovered that some of the > > servers that I have to connect to with this program run only SSH, so I > > need to add support for SSH to the program. I'm looking for a library > > that behaves similarly to telnetlib for SSH connections. Does anyone > > know of one? I was going to try using pexpect to control the Windows > > telnet command, but pexpect only works on Unix. > > If it's just to execute a few commands, consider downloading PLink > (from the PuTTY site) and use it via os.system(). It works well. Thank you, it worked perfectly. You have ended a week of headaces. > -Peter From jjl at pobox.com Wed Aug 20 15:26:35 2003 From: jjl at pobox.com (John J. Lee) Date: 20 Aug 2003 20:26:35 +0100 Subject: what to do when instance of class fails to initialize ? References: Message-ID: <87brukb05w.fsf@pobox.com> Tom Van den Brandt writes: > If I have an __init__ for a class and the initialisation can't go through > (example: missing or wrong arguments), how do I return an error to the > caller (from main() function)? When I do a return statement in the > __init__ it says __init__ should return None... I can stop the flow with > raise 'BlahBlah'. But then the program exits. > > What is the nice way to do this ? Raise an exception. But do it with a real exception, *never* use string exceptions (if they aren't officially deprecated, they certainly soon will be). class BadRhubarbError(Exception): pass class foo: def __init__(self, i, rhubarb=None): self._i = int(i) # raises TypeError on failure if rhubarb is not None: rhubarb = "rhubarb" # default if not good_rhubarb(rhubarb): raise BadRhubarbError() # explicitly raised exception self.rhubarb = rhubarb def blah(): ... def use_a_foo(): try: f = foo() except TypeError: return None # or whatever except BadRhubarbError: sys.exit("bad rhubarb!!") else: return f.blah() Remember exceptions propagate through multiple levels of function calls, of course, not just one level as shown here -- the try/except could equally well be in a function that calls use_a_foo, for example. Some people prefer to use assertions for argument-checking (ie. raise AssertionError, unless __debug__ is false -- read the language reference section on assert for more), regarding them as a way to implement preconditions a la Bertrand Meyer & Eiffel. I've never really got my head around all the pros and cons there, TBH. John From bignose-hates-spam at and-benfinney-does-too.id.au Fri Aug 1 04:37:44 2003 From: bignose-hates-spam at and-benfinney-does-too.id.au (Ben Finney) Date: 1 Aug 2003 18:27:44 +0950 Subject: time, calendar, datetime, etc References: <153fa67.0307300326.45a29380@posting.google.com> <1sScnW0Sv7DzrrSiRTvUpQ@speakeasy.net> Message-ID: On Thu, 31 Jul 2003 22:47:27 -0600, Andrew Dalke wrote: > Why would supporing you be reasonable to the other 99+% of the > users who don't care about doing astronomical measurements It is astronomy (and, before it, astrology) that has driven the standardisation of time for many centuries; anyone wanting to use a standardised time system is using one based on astronomical imperatives. > even about the "was there a year 0?" debate. Anyone who wants to deal with dates BC (in the Gregorian calendar) cares about the "was there a year 0?" question (answer: not in the Gregorian calendar, there wasn't). So it seems you're dismissing a large sector of users: those who deal with dates before 1AD, and those who want to use worldwide date/time standards. > Python's datetime module doesn't allow [more than 60 seconds in a > minute]. > And if it did, it would almost certainly break code written by people > who didn't know there could be 61 seconds in a minute. Such people would run into trouble when leap seconds occurred anyway; keeping the datetime module ignorant of it just means the problems will not be dealt with when the program is designed (when it is easy to correct) but rather be thrust in their face when a leap second occurs (presumably when the program has been long forgotten about and the original programmer possibly departed). > So in summary, almost no one needs the functionality beyond what the > standard library has, supporting each and every specialized niche > makes for more complex code, and more complex code means people who do > "normal" programming are much more likely to run into problems and > make the code more likely to break. Quite the reverse. If the standard library supported things like leap seconds, absence-of-year-zero, and Julian dates, it would be wrapped up in one place where programmers could use it without having to know about the implementation complexities. -- \ "Anything that is too stupid to be spoken is sung." -- Voltaire | `\ | _o__) | Ben Finney From adalke at mindspring.com Thu Aug 21 13:19:06 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Thu, 21 Aug 2003 17:19:06 GMT Subject: how fast is Python? References: Message-ID: Travis Whitton > [the shootout] is probably the best site on the > internet for side-by-side language comparisons: Though there's also pleac.sf.net which isn't for timings but does show how the different languages would be used to do the same thing. And I see my Python contribution still leads the pack in % done. Andrew dalke at dalkescientific.com From travis at enthought.com Wed Aug 13 13:01:05 2003 From: travis at enthought.com (Travis N. Vaught) Date: Wed, 13 Aug 2003 12:01:05 -0500 Subject: [ANN] SciPy 03 Workshop Schedule Message-ID: <03f801c361bc$80dfc380$a201a8c0@tvlaptop> --------------------- SciPy '03 Workshop Caltech, Pasadena, CA September 11-12, 2003 --------------------- A draft of the schedule for the SciPy 03 workshop is now available online: http://www.scipy.org/site_content/scipy03/scipy03sched.htm This year's schedule includes presentations from an even broader sampling of scientific fields. If you haven't already registered, please sign up now: http://www.scipy.org/site_content/scipy03 From jack at performancedrivers.com Tue Aug 26 10:29:14 2003 From: jack at performancedrivers.com (Jack Diederich) Date: Tue, 26 Aug 2003 10:29:14 -0400 Subject: Dictionary that uses regular expressions In-Reply-To: ; from vze4rx4y@verizon.net on Thu, Aug 21, 2003 at 05:05:52AM +0000 References: <1f0bdf30.0308202049.7d251469@posting.google.com> Message-ID: <20030826102914.A2449@bitch.nowhere.blah> On Thu, Aug 21, 2003 at 05:05:52AM +0000, Raymond Hettinger wrote: > "Erik Lechak" wrote in message > news:1f0bdf30.0308202049.7d251469 at posting.google.com... > > Hello all, > > > > I wrote the code below. It is simply a dictionary that uses regular > > expressions to match keys. A quick look at _test() will give you an > > example. > > > > Is there a module that already does this? > > Google may prove me wrong, but this looks like a new idea. > > > > Is there a way and would it > > be better to use list comprehension? (using python 2.3) > > > > Just looking for a better or more pythonic way to do it. > > Try inheriting from UserDict.DictMixin instead of dict. > Some months ago I started rewriting the C regexps module to allow for matching pure-python string types[1]. The python class would just have to define a method to get the next character and optionally a method to say how much to backtrack on a match failure. My use case was ternary trees, instead of doing a lookup with a string key it would return first or any matches of a regexp key. Other people were doing heavy work on the regexp module so I'm waiting for the 2.4 implementation to stabalize before I go back to it. -jackdied [1] http://mail.python.org/pipermail/python-dev/2003-April/034688.html From pythonguy at Hotpop.com Tue Aug 19 02:24:44 2003 From: pythonguy at Hotpop.com (Anand Pillai) Date: 18 Aug 2003 23:24:44 -0700 Subject: How to save web pages for offline reading? References: Message-ID: <84fc4588.0308182224.6186a988@posting.google.com> I hope this thread is not dead. I would like to know what you decided at the end :-) Harvestman has about 10 active subscribers right now and some corporates in India and umpteen of my own friends use it for their personal 'harvesting' needs :-> I hope you downloaded at least the (new) binaries and gave it a go! -Anand hwlgw at hotmail.com (Will Stuyvesant) wrote in message news:... > > [Carsten Gehling] > > Well since you ARE on Windows: > > > > Open the page in Internet Explorer, choose "File" and "Save As...". > > You've now saved all necessary files. > > > > I know. But I can't do File - Save As from python :-) I guess it can > be done via COM? > > > > I thought this whole thing would be easy with all those Python > > > internet modules in the standard distro: httplib, urllib, urllib2, > > > FancyURLxxx etc. Being able to download a "complete" page *from > > > Python source* would be very nice for my particular application. > > > > Well it's doable with those libraries, but you have to put your own meat > > on > > the bones. > > > > 1) Use httplib to get the page first. > > 2) Parse it for all "src" attributes, and get the supporting files. The > > parsin can be done with a html-parser ... > > That would be htmllib. > > What you describe is what I am going to do actually, when I have time > again. I was about to do it when I thought "somebody must have been > doing this before". It seems like mr. Pillai in another reply has > done something similar but I couldn't figure out from his source code. > > Thank you all for the help! From walter at livinglogic.de Tue Aug 12 13:45:18 2003 From: walter at livinglogic.de (=?ISO-8859-1?Q?Walter_D=F6rwald?=) Date: Tue, 12 Aug 2003 19:45:18 +0200 Subject: Problem with os.access with unicode filenames In-Reply-To: References: Message-ID: <3F3927AE.5080905@livinglogic.de> TheAZN wrote: > The os.access function gives me this error: > > "UnicodeEncodeError: 'ascii' codec can't encode character '\ub4' in > position 31: ordinal not in range(128)" > > when I use the os.access function with an Unicode string which contains a > character u'\u00b4'. > > Oddly enough in IDLE: if I do "print u'\ub4'" I get an error, but it > doesn't give me an error if I do "print u'\ub00b4'" The message is fixed now in CVS, i.e. the UnicodeEncodeError will now state "UnicodeEncodeError: 'ascii' codec can't encode character u'\xb4' in position 31: ordinal not in range(128)" > Is there a way to get around this? It works fine when the file name does > not contain that character. This depends on your OS. posixmodule.c::posix_access() does not support Unicode strings, but it should work if you encode the filename with your filesystem encoding before calling os.access(). Don't know about Windows. Bye, Walter D?rwald From ge.net at wanadoo.fr Sun Aug 3 05:20:38 2003 From: ge.net at wanadoo.fr (GE) Date: Sun, 3 Aug 2003 11:20:38 +0200 Subject: PB with Python ActiveX Scripting Engine registration (Python 2.2.3/2.3) References: Message-ID: Thanks for your helps I execute the Python program pyscript_rexec.py --debug Below the trace with Trace Collector Debugging Tool" from Pythonwin after to execute demo.htm in IE in _InvokeEx_ with SetScriptState 0 1 (3,) None None in _InvokeEx_ with Close 0 1 () None None in _InvokeEx_ with SetScriptState 0 1 (3,) None None in _InvokeEx_ with Close 0 1 () None None Object with win32trace dispatcher created (object=None) in _InvokeEx_ with GetInterfaceSafetyOptions 0 1 (IID('{BB1A2AE2-A4F9-11CF-8F20-00805F2CD064}'),) None None in _InvokeEx_ with SetInterfaceSafetyOptions 0 1 (IID('{BB1A2AE2-A4F9-11CF-8F20-00805F2CD064}'), 14, 14) None None in ._QueryInterface_ with unsupported IID IActiveScriptProperty(unregistered) ({4954E0D0-FBC7-11D1-8410-006008C3FBFC}) in _InvokeEx_ with InitNew 0 1 () None None in _InvokeEx_ with SetScriptSite 0 1 (,) None None in _InvokeEx_ with GetScriptState 0 1 () None None in _InvokeEx_ with SetScriptState 0 1 (1,) None None in _InvokeEx_ with AddNamedItem 0 1 ('window', 14) None None in ._QueryInterface_ with unsupported IID IActiveScriptParseProcedure2_32(unregistered) ({71EE5B20-FB04-11D1-B3A8-00A0C911E8B2}) in ._QueryInterface_ with unsupported IID IActiveScriptParseProcedure ({AA5B6A80-B834-11D0-932F-00A0C90DCAA9}) in _InvokeEx_ with ParseScriptText 0 1 ('\r\ndef Window_OnLoad():\r\n\tpass\r\n#\timport win32traceutil\r\n#\tprint "Frames are", ax.window.frames._print_details_()\r\n#\tprint "Frame 0 href = ", ax.frames.Item(0).location.href\r\n\r\ndef Name_OnLoad():\r\n\tprint "Frame loading"\r\n\r\n', 'window', None, '', 30745792, 6, 130, 1) None None Traceback (most recent call last): File "C:\Python22\lib\site-packages\win32com\server\dispatcher.py", line 5 8, in _InvokeEx_ return self.policy._InvokeEx_(dispid, lcid, wFlags, args, kwargs, serviceProvider) File "C:\Python22\lib\site-packages\win32com\server\policy.py", line 322, in _InvokeEx_ return self._invokeex_(dispid, lcid, wFlags, args, kwargs, serviceProvider) File "C:\Python22\lib\site-packages\win32com\server\policy.py", line 541, in _invokeex_ return func(*args) File "C:\Python22\lib\site-packages\win32comext\axscript\client\framework.py", line 530, in ParseScriptText self.RegisterNewNamedItems() File "C:\Python22\lib\site-packages\win32comext\axscript\client\framework.py", line 756, in RegisterNewNamedItems self.RegisterNamedItem(item) File "C:\Python22\lib\site-packages\win32comext\axscript\client\pyscript.py", line 265, in RegisterNamedItem self.rexec_env = AXRExec(self.globalNameSpaceModule) File "C:\Python22\lib\site-packages\win32comext\axscript\client\pyscript.py", line 60, in __init__ rexec.RExec.__init__(self, hooks, verbose) File "C:\Python22\lib\rexec.py", line 183, in __init__ raise RuntimeError, "This code is not secure in Python 2.2 and 2.3" RuntimeError: This code is not secure in Python 2.2 and 2.3 Object with win32trace dispatcher created (object=None) in _InvokeEx_ with GetInterfaceSafetyOptions 0 1 (IID('{BB1A2AE2-A4F9-11CF-8F20-00805F2CD064}'),) None None in _InvokeEx_ with SetInterfaceSafetyOptions 0 1 (IID('{BB1A2AE2-A4F9-11CF-8F20-00805F2CD064}'), 14, 14) None None in ._QueryInterface_ with unsupported IID IActiveScriptProperty(unregistered) ({4954E0D0-FBC7-11D1-8410-006008C3FBFC}) in _InvokeEx_ with InitNew 0 1 () None None in _InvokeEx_ with SetScriptSite 0 1 (,) None None in _InvokeEx_ with GetScriptState 0 1 () None None in _InvokeEx_ with SetScriptState 0 1 (1,) None None in _InvokeEx_ with AddNamedItem 0 1 ('window', 14) None None in ._QueryInterface_ with unsupported IID IActiveScriptParseProcedure2_32(unregistered) ({71EE5B20-FB04-11D1-B3A8-00A0C911E8B2}) in ._QueryInterface_ with unsupported IID IActiveScriptParseProcedure ({AA5B6A80-B834-11D0-932F-00A0C90DCAA9}) in _InvokeEx_ with ParseScriptText 0 1 ('\r\ntry:\r\n\twindow.open("demo_intro.htm", "Body")\r\nexcept:\r\n\thistory.back()\r\n', 'window', None, '', 30745720, 32, 130, 1) None None Traceback (most recent call last): File "C:\Python22\lib\site-packages\win32com\server\dispatcher.py", line 58, in _InvokeEx_ return self.policy._InvokeEx_(dispid, lcid, wFlags, args, kwargs, serviceProvider) File "C:\Python22\lib\site-packages\win32com\server\policy.py", line 322, in _InvokeEx_ return self._invokeex_(dispid, lcid, wFlags, args, kwargs, serviceProvider) File "C:\Python22\lib\site-packages\win32com\server\policy.py", line 541, in _invokeex_ return func(*args) File "C:\Python22\lib\site-packages\win32comext\axscript\client\framework.py", line 530, in ParseScriptText self.RegisterNewNamedItems() File "C:\Python22\lib\site-packages\win32comext\axscript\client\framework.py", line 756, in RegisterNewNamedItems self.RegisterNamedItem(item) File "C:\Python22\lib\site-packages\win32comext\axscript\client\pyscript.py", line 265, in RegisterNamedItem self.rexec_env = AXRExec(self.globalNameSpaceModule) File "C:\Python22\lib\site-packages\win32comext\axscript\client\pyscript.py", line 60, in __init__ rexec.RExec.__init__(self, hooks, verbose) File "C:\Python22\lib\rexec.py", line 183, in __init__ raise RuntimeError, "This code is not secure in Python 2.2 and 2.3" RuntimeError: This code is not secure in Python 2.2 and 2.3 in _InvokeEx_ with SetScriptState 0 1 (2,) None None Traceback (most recent call last): File "C:\Python22\lib\site-packages\win32com\server\dispatcher.py", line 58, in _InvokeEx_ return self.policy._InvokeEx_(dispid, lcid, wFlags, args, kwargs, serviceProvider) File "C:\Python22\lib\site-packages\win32com\server\policy.py", line 322, in _InvokeEx_ return self._invokeex_(dispid, lcid, wFlags, args, kwargs, serviceProvider) File "C:\Python22\lib\site-packages\win32com\server\policy.py", line 541, in _invokeex_ return func(*args) File "C:\Python22\lib\site-packages\win32comext\axscript\client\framework.py", line 601, in SetScriptState self.Connect() File "C:\Python22\lib\site-packages\win32comext\axscript\client\framework.py", line 768, in Connect self.RegisterNewNamedItems() File "C:\Python22\lib\site-packages\win32comext\axscript\client\framework.py", line 756, in RegisterNewNamedItems self.RegisterNamedItem(item) File "C:\Python22\lib\site-packages\win32comext\axscript\client\pyscript.py", line 265, in RegisterNamedItem self.rexec_env = AXRExec(self.globalNameSpaceModule) File "C:\Python22\lib\site-packages\win32comext\axscript\client\pyscript.py", line 60, in __init__ rexec.RExec.__init__(self, hooks, verbose) File "C:\Python22\lib\rexec.py", line 183, in __init__ raise RuntimeError, "This code is not secure in Python 2.2 and 2.3" RuntimeError: This code is not secure in Python 2.2 and 2.3 pythoncom error: Python error calling method SetScriptState Traceback (most recent call last): File "C:\Python22\lib\site-packages\win32com\server\dispatcher.py", line 137, in _InvokeEx_ return DispatcherBase._InvokeEx_(self, dispid, lcid, wFlags, args, kwargs, serviceProvider) File "C:\Python22\lib\site-packages\win32com\server\dispatcher.py", line 60, in _InvokeEx_ self._HandleException_() File "C:\Python22\lib\site-packages\win32com\server\dispatcher.py", line 107, in _HandleException_ reraise() File "C:\Python22\lib\site-packages\win32com\server\dispatcher.py", line 58, in _InvokeEx_ return self.policy._InvokeEx_(dispid, lcid, wFlags, args, kwargs, serviceProvider) File "C:\Python22\lib\site-packages\win32com\server\policy.py", line 322, in _InvokeEx_ return self._invokeex_(dispid, lcid, wFlags, args, kwargs, serviceProvider) File "C:\Python22\lib\site-packages\win32com\server\policy.py", line 541, in _invokeex_ return func(*args) File "C:\Python22\lib\site-packages\win32comext\axscript\client\framework.py", line 601, in SetScriptState self.Connect() File "C:\Python22\lib\site-packages\win32comext\axscript\client\framework.py", line 768, in Connect self.RegisterNewNamedItems() File "C:\Python22\lib\site-packages\win32comext\axscript\client\framework.py", line 756, in RegisterNewNamedItems self.RegisterNamedItem(item) File "C:\Python22\lib\site-packages\win32comext\axscript\client\pyscript.py", line 265, in RegisterNamedItem self.rexec_env = AXRExec(self.globalNameSpaceModule) File "C:\Python22\lib\site-packages\win32comext\axscript\client\pyscript.py", line 60, in __init__ rexec.RExec.__init__(self, hooks, verbose) File "C:\Python22\lib\rexec.py", line 183, in __init__ raise RuntimeError, "This code is not secure in Python 2.2 and 2.3" exceptions.RuntimeError: This code is not secure in Python 2.2 and 2.3 in _InvokeEx_ with SetScriptState 0 1 (2,) None None Traceback (most recent call last): File "C:\Python22\lib\site-packages\win32com\server\dispatcher.py", line 58, in _InvokeEx_ return self.policy._InvokeEx_(dispid, lcid, wFlags, args, kwargs, serviceProvider) File "C:\Python22\lib\site-packages\win32com\server\policy.py", line 322, in _InvokeEx_ return self._invokeex_(dispid, lcid, wFlags, args, kwargs, serviceProvider) File "C:\Python22\lib\site-packages\win32com\server\policy.py", line 541, in _invokeex_ return func(*args) File "C:\Python22\lib\site-packages\win32comext\axscript\client\framework.py", line 601, in SetScriptState self.Connect() File "C:\Python22\lib\site-packages\win32comext\axscript\client\framework.py", line 768, in Connect self.RegisterNewNamedItems() File "C:\Python22\lib\site-packages\win32comext\axscript\client\framework.py", line 756, in RegisterNewNamedItems self.RegisterNamedItem(item) File "C:\Python22\lib\site-packages\win32comext\axscript\client\pyscript.py", line 265, in RegisterNamedItem self.rexec_env = AXRExec(self.globalNameSpaceModule) File "C:\Python22\lib\site-packages\win32comext\axscript\client\pyscript.py", line 60, in __init__ rexec.RExec.__init__(self, hooks, verbose) File "C:\Python22\lib\rexec.py", line 183, in __init__ raise RuntimeError, "This code is not secure in Python 2.2 and 2.3" RuntimeError: This code is not secure in Python 2.2 and 2.3 pythoncom error: Python error calling method SetScriptState Traceback (most recent call last): File "C:\Python22\lib\site-packages\win32com\server\dispatcher.py", line 137, in _InvokeEx_ return DispatcherBase._InvokeEx_(self, dispid, lcid, wFlags, args, kwargs, serviceProvider) File "C:\Python22\lib\site-packages\win32com\server\dispatcher.py", line 60, in _InvokeEx_ self._HandleException_() File "C:\Python22\lib\site-packages\win32com\server\dispatcher.py", line 107, in _HandleException_ reraise() File "C:\Python22\lib\site-packages\win32com\server\dispatcher.py", line 58, in _InvokeEx_ return self.policy._InvokeEx_(dispid, lcid, wFlags, args, kwargs, serviceProvider) File "C:\Python22\lib\site-packages\win32com\server\policy.py", line 322, in _InvokeEx_ return self._invokeex_(dispid, lcid, wFlags, args, kwargs, serviceProvider) File "C:\Python22\lib\site-packages\win32com\server\policy.py", line 541, in _invokeex_ return func(*args) File "C:\Python22\lib\site-packages\win32comext\axscript\client\framework.py", line 601, in SetScriptState self.Connect() File "C:\Python22\lib\site-packages\win32comext\axscript\client\framework.py", line 768, in Connect self.RegisterNewNamedItems() File "C:\Python22\lib\site-packages\win32comext\axscript\client\framework.py", line 756, in RegisterNewNamedItems self.RegisterNamedItem(item) File "C:\Python22\lib\site-packages\win32comext\axscript\client\pyscript.py", line 265, in RegisterNamedItem self.rexec_env = AXRExec(self.globalNameSpaceModule) File "C:\Python22\lib\site-packages\win32comext\axscript\client\pyscript.py", line 60, in __init__ rexec.RExec.__init__(self, hooks, verbose) File "C:\Python22\lib\rexec.py", line 183, in __init__ raise RuntimeError, "This code is not secure in Python 2.2 and 2.3" exceptions.RuntimeError: This code is not secure in Python 2.2 and 2.3 "Mark Hammond" wrote in message news:bgf4qa$2k95$1 at arachne.labyrinth.net.au... > GE wrote: > > > I execute the Python program win32com\axscript\client\pyscript_rexec.py and > > the engine is successfully registered But the python engine isn't active in > > IE (tested with demo.htm, even after a reboot) > > I did not have probleme with Python 2.1 and win32all-151 > > > > The path of win32com have changed ( now in python 2.2 we have the directory > > "site-packages" in more) is-it a way??? > > > > Try resistering with "--debug", then open the "Trace Collector Debugging > Tool" from Pythonwin. > > Mark. > From logiplex at qwest.net Tue Aug 19 17:54:34 2003 From: logiplex at qwest.net (Cliff Wells) Date: Tue, 19 Aug 2003 14:54:34 -0700 Subject: Why does this (not) work? In-Reply-To: References: Message-ID: <1061330074.29677.13.camel@software1.logiplex.internal> On Tue, 2003-08-19 at 14:25, Michael C. Neel wrote: > I've got this string in which I need to sub in the same word several > times; i.e: > > >>> "%s - %s - %s" % ("test","test","test") > 'test - test - test' > >>> > > But I want to use the * to make life easier to read, so I tried: > > >>> ("test",)*3 > ('test', 'test', 'test') > >>> "%s - %s - %s" % ("test",)*3 > Traceback (most recent call last): > File "", line 1, in ? > TypeError: not enough arguments for format string > >>> > Any idea why the tuple to str to tuple works and not the tuple straight? Because % has higher precedence than * (or rather they have equal precedence and the expression is evaluated left to right) so the expression becomes ("%s - %s - %s" % ("test",)) * 3 when what you meant was "%s - %s - %s" % (("test",) * 3) Here's another approach: >>> def fjoin(sep, s, n): ... return sep.join(["%s"] * n) % ((s,) * n) ... >>> fjoin(' - ', "test", 3) 'test - test - test' Regards, -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 (800) 735-0555 From peter at engcorp.com Mon Aug 25 18:16:33 2003 From: peter at engcorp.com (Peter Hansen) Date: Mon, 25 Aug 2003 18:16:33 -0400 Subject: Help embedding python References: <3F4A469E.58B94F7C@engcorp.com> <3F4A57B0.E91D89FC@engcorp.com> Message-ID: <3F4A8AC1.E3A54821@engcorp.com> Just wrote: > > In article , > Zora Honey wrote: > > > [ ... ] The reason I didn't include rationale is > > because I have none. I have been advocating extending python instead of > > embedding it, but since I have no experience with either, my only > > argument is that it seems more natural. > > Have a look at > http://www.twistedmatrix.com/users/glyph/rant/extendit.html > It may be a rant, but it makes some good points. Rant or no, it does make many of the points I would like to have been able to make had I a better grasp of the specifics of embedding versus extending. Suffice to say that my objections are largely abstract, based on fairly lengthy experience with design issues like this, but Glyph's "rant" sure sounds like it covers this in a _concrete_ way. Zora, your husband isn't necessarily wrong, but probably just more comfortable with C++ right now. If that's so, I think he would benefit greatly by spending the time to follow Glyph's sound advice, and by becoming familiar enough with Python to feel things are the other way around: Python calling C++ (or C) is quite a bit simpler, and has other advantages in terms of flexibility and ease of debugging, not to mention readability. -Peter From graham at rockcons.co.uk Mon Aug 11 11:37:38 2003 From: graham at rockcons.co.uk (Graham Nicholls) Date: Mon, 11 Aug 2003 16:37:38 +0100 Subject: Fun with numbers - dammit, but I want a cast! References: <3f378fac$0$10778$afc38c87@auth.uk.news.easynet.net> <3f3792f2$0$18258$afc38c87@auth.uk.news.easynet.net> Message-ID: <3f37b842$0$10784$afc38c87@auth.uk.news.easynet.net> Istvan Albert wrote: > Graham Nicholls wrote: > >>>Have you tried doing it this way: >>>xscale = xframe / float(img_x) >> >> >> Thats what I wanted to do, but was sure I'd read that python didn't have >> casts, and that _looks_ like a cast to me! > > You can also force floating point math by muliplying with 1.0 > before the division: > > xscale = 1.0 * xframe/img_x > > Istvan. Thanks everybody! I'm now sorted with numbers. At least 2.0+2.0 now equals about 4.0, anyway. Graham -- Graham Nicholls Rock Computer Consultancy From mis6 at pitt.edu Sun Aug 24 04:42:04 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 24 Aug 2003 01:42:04 -0700 Subject: Python is darn fast (was: How fast is Python) References: <2259b0e2.0308230737.8a9bc1c@posting.google.com> Message-ID: <2259b0e2.0308240042.6ed872d7@posting.google.com> Van Gale wrote in message news:... > Michele Simionato wrote: > > I posted this few weeks ago (remember the C Sharp thread?) but it went > > unnoticed on the large mass of posts, so let me retry. Here I get Python+ > > Psyco twice as fast as optimized C, so I would like to now if something > > is wrong on my old laptop and if anybody can reproduce my results. > > Here are I my numbers for calling the error function a million times > > (Python 2.3, Psyco 1.0, Red Hat Linux 7.3, Pentium II 366 MHz): > > > > $ gcc erf.c -lm -o3 > > Did you really use "-o3" instead of "-O3"? The lowercase -o3 will > produce object code file named "3" instead of doing optimization. Yes, I used -O3, this was a misprint in the e-email. The compiler was gcc 2.96. Michele Simionato, Ph. D. MicheleSimionato at libero.it http://www.phyast.pitt.edu/~micheles --- Currently looking for a job --- From pedrosch at gazeta.pl Fri Aug 15 18:41:42 2003 From: pedrosch at gazeta.pl (Drochom) Date: Sat, 16 Aug 2003 00:41:42 +0200 Subject: cPickle alternative? References: Message-ID: Hello, > If speed is important, you may want to do different things depending on e.g., > what is in those tuples, and whether they are all the same length, etc. E.g., > if they were all fixed length tuples of integers, you could do hugely better > than store the data as a list of tuples. Those tuples have different length indeed. > You could store the whole thing in a mmap image, with a length-prefixed pickle > string in the front representing index info. If i only knew how do to it...:-) > Find a way to avoid doing it? Or doing much of it? > What are your access needs once the data is accessible? My structure stores a finite state automaton with polish dictionary (lexicon to be more precise) and it should be loaded once but fast! Thx Regards, Przemo Drochomirecki From jkraska at san.rr.com Sat Aug 2 01:31:51 2003 From: jkraska at san.rr.com (Courageous) Date: Sat, 02 Aug 2003 05:31:51 GMT Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> <73bpv-4f3.ln1@beastie.ix.netcom.com> Message-ID: >> The three that come to my mind are significant whitespace, ... "Significant whitespace" isn't a "compromise," it's a design choice. The Python interpreter actually inserts explicit scope tokens into the symbol stream at the lexer; the parser deals with the symbols as does any parser. It's really not all that hard, actually. One just has to understand the bit that making the *parser* deal with the white space is not the right thing. C// From jepler at unpythonic.net Tue Aug 26 12:20:13 2003 From: jepler at unpythonic.net (Jeff Epler) Date: Tue, 26 Aug 2003 11:20:13 -0500 Subject: file object, details of modes and some issues. In-Reply-To: <3f4b800f_3@mk-nntp-1.news.uk.worldonline.com> References: <3f4b800f_3@mk-nntp-1.news.uk.worldonline.com> Message-ID: <20030826162008.GN32191@unpythonic.net> Here's what I get on my system: >>> f = file("xyzzy", "w") >>> f.read() Traceback (most recent call last): File "", line 1, in ? IOError: [Errno 9] Bad file descriptor >>> f.write(' ') >>> f.read() Traceback (most recent call last): File "", line 1, in ? IOError: [Errno 9] Bad file descriptor Python relies fairly directly on the C standard library for correct behavior when it comes to file objects. I suspect that the following C program will also "succeed" on your system: #include int main(void) { FILE *f = fopen("xyzzy", "w"); char buf[2]; char *res; fputs(" ", f); res = fgets(buf, 2, f); if(!res) { perror("fgets"); return 1; } return 0; } On my system, it does given an error: $ gcc simon.c $ ./a.out fgets: Bad file descriptor $ echo $? 1 If the C program prints an error message like above, but Python does not raise an exception on the mentioned code, then there's a Python bug. Otherwise, if the C program executes on your system without printing an error and returns the 0 (success) exit code, then the problem is the poor quality of your platform's stdio implementation. Jeff PS relevant text from the fgets manpage on my system: gets() and fgets() return s on success, and NULL on error or when end of file occurs while no characters have been read. and from fopen: w Truncate file to zero length or create text file for writing. The stream is positioned at the beginning of the file. From pu Sun Aug 10 05:21:57 2003 From: pu (Patrick Useldinger) Date: Sun, 10 Aug 2003 11:21:57 +0200 Subject: ANNOUNCE: Rekall V2.0.2 In-Reply-To: References: Message-ID: <3f360e5d_2@news.vo.lu> 1. why not post this in c.l.p.announce? 2. why not show screenshots, and give more details? -- Real e-mail address is 'cHVAdm8ubHU=\n'.decode('base64') Visit my Homepage at http://www.homepages.lu/pu/ From max at alcyone.com Thu Aug 28 01:31:00 2003 From: max at alcyone.com (Erik Max Francis) Date: Wed, 27 Aug 2003 22:31:00 -0700 Subject: Style question... References: <3F4D637B.7ADB0BC4@alcyone.com> Message-ID: <3F4D9394.4E810556@alcyone.com> Anthony Roberts wrote: > BTW: I've had your website bookmarked since 2001 because a number of > the > things there are useful and cool. :-). -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ I'll tell them that their daddy was / A good man \__/ India Arie From jaybromley at hotmail.com Sun Aug 31 14:44:30 2003 From: jaybromley at hotmail.com (Jay Bromley) Date: 31 Aug 2003 11:44:30 -0700 Subject: Update to Python 2.3 on Red Hat Linux 9 References: <8242f4a7.0308282240.4c87f997@posting.google.com> Message-ID: <8242f4a7.0308311044.7e58ed65@posting.google.com> martin at v.loewis.de (Martin v. L?wis) wrote in message news:... > jaybromley at hotmail.com (Jay Bromley) writes: > > > So the questions is, can I build Python 2.3 so that it recognizes all > > the packages that are available to Python 2.2.2? Is this LD_RUN_PATH > > stuff? > > You can't; this is not supported. > > The ABI has changed, so the old modules just wouldn't work anymore if > they were found. > > > Or do I really need to find out all the libraries in use with > > 2.2.2 and compile these for 2.3? > > Yes. Thank you for confirming this for me. After doing some additional digging around rebuilding everything for the new python was the only way I found to do this, but I was still hoping there was an easier way. Regards, Jay From pythonguy at Hotpop.com Wed Aug 13 05:55:58 2003 From: pythonguy at Hotpop.com (Anand Pillai) Date: 13 Aug 2003 02:55:58 -0700 Subject: ???? i can`t understand it References: Message-ID: <84fc4588.0308130155.6945f738@posting.google.com> I would rather use slices. Here are two ways of doing it. >>>a=[1,2,3,4,5] >>>for b in a[0:} ... a.remove(b) >>>print a [] Or I think a better way is (dont ask me why!) >>>a=[1,2,3,4,5] >>>for b in a[:]: ... a.remove(b) >>>print a [] -Anand bokr at oz.net (Bengt Richter) wrote in message news:... > On Fri, 8 Aug 2003 08:05:11 -0300, "Batista, Facundo" wrote: > > >This message is in MIME format. Since your mail reader does not understand > >this format, some or all of this message may not be legible. > > If you could eliminate the HTML, it would improve reception on this end ;-) > > Regards, > Bengt Richter From news at datatailors.xs4all.nl Fri Aug 8 17:05:40 2003 From: news at datatailors.xs4all.nl (Peter van Kampen) Date: Fri, 8 Aug 2003 23:05:40 +0200 Subject: base64 module References: Message-ID: In article , Ken Fettig wrote: > Hello, I am trying to make use of the base64 module but am having problems. > >>>> import base64 >>>> decodestring('SVNBKjAwKiAgICAgICAgICAqMDAqICAgICAg') > Traceback (most recent call last): > File "", line 1, in ? > decodestring('SVNBKjAwKiAgICAgICAgICAqMDAqICAgICAg') > NameError: name 'decodestring' is not defined >>>> > > What am I doing wrong. I am importing the base64 module, why can't I call > the decodestring method? Scope and Namespaces. Try: >>> base64.decodestring('SVNBKjAwKiAgICAgICAgICAqMDAqICAgICAg') 'ISA*00* *00* ' See http://www.python.org/doc/current/tut/node11.html Hth, PterK -- Peter van Kampen pterk -- at -- datatailors.com From aahz at pythoncraft.com Mon Aug 18 10:27:47 2003 From: aahz at pythoncraft.com (Aahz) Date: 18 Aug 2003 10:27:47 -0400 Subject: overriding a tuple's __init__ References: Message-ID: In article , Andrew Dalke wrote: > >The problem is the immutability. This one one of the >new changes in 2.3 I still don't fully understand, but I do >know the solution is __new__ > >>>> class pair(tuple): >... def __new__(self, a, b): >... return tuple((a, b)) >... >>>> >>>> pair(2,3) >(2, 3) >>>> x=_ >>>> type(x) > >>>> > >That should give you some pointers for additional searches. This works better: class pair(tuple): def __new__(cls, *args): return tuple.__new__(cls, args) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From tim.one at comcast.net Tue Aug 5 15:14:22 2003 From: tim.one at comcast.net (Tim Peters) Date: Tue, 5 Aug 2003 15:14:22 -0400 Subject: Unable to run IDLE from 2.3? In-Reply-To: <1akviv4cpectdogklmuupg7rc37lhe1pc7@4ax.com> Message-ID: [M Wells] > I recently downloaded and installed Python 2.3 for Windows (on XP > professional) and I don't seem to be able to run IDLE from my start > menu? It seems something happens when I click on it (ie I get an > hourglass) but no actual application turns up. > > Has anyone else experienced this and can anyone give me some advice > on how to fix it? In addition to the two possible causes Alex spelled out, another common problem is some *other* program setting up Tcl or Tk environment variables pointing to an inappropriate version of Tcl/Tk. The installer for Ruby is the most common culprit for this problem, so if you've installed Ruby that's probably the cause. To check, open up a DOS box and try this: C:\Python23>python Python 2.3 (#46, Jul 29 2003, 09:29:04) [MSC v.1200 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import Tkinter >>> Tkinter._test() >>> From edreamleo at charter.net Sat Aug 30 07:56:31 2003 From: edreamleo at charter.net (Edward K. Ream) Date: Sat, 30 Aug 2003 06:56:31 -0500 Subject: Hunting a memory leak References: <7h3oey84qho.fsf@pc150.maths.bris.ac.uk> Message-ID: > I would appreciate some ideas. I doubt many people will be willing to rummage through your app's code to do your debugging for you. Here are two general ideas: 1. Try to simplify the problem. Pick something, no matter how small (and the smaller the better) that doesn't seem to be correct and do what it takes to find out why it isn't correct. If trackRefs is Python code you can hack that code to give you more (or less!) info. Once you discover the answer to one mystery, the larger mysteries may become clearer. For example, you can concentrate on one particular data structure, one particular data type or one iteration of your test suite. 2. Try to enjoy the problem. The late great Earl Nightingale had roughly this advice: Don't worry. Simply consider the problem calmly, and have confidence that the solution will eventually come to you, probably when you are least expecting it. I've have found that this advice really works, and it works for almost any problem. Finding "worthy" bugs is a creative process, and creativity can be and should be highly enjoyable. In this case, your problem is: "how to start finding my memory leaks". Possible answers to this problem might be various strategies for getting more (or more focused!) information. Then you have new problems: how to implement the various strategies. In all cases, the advice to be calm and patient applies. Solving this problem will be highly valuable to you, no matter how long it takes :-) Edward P.S. And don't hesitate to ask more questions, especially once you have more concrete data or mysteries. EKR -------------------------------------------------------------------- Edward K. Ream email: edreamleo at charter.net Leo: Literate Editor with Outlines Leo: http://webpages.charter.net/edreamleo/front.html -------------------------------------------------------------------- From mcfletch at rogers.com Sat Aug 9 10:20:02 2003 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Sat, 09 Aug 2003 10:20:02 -0400 Subject: Spell Checker In-Reply-To: References: <20030808180013.22305e65.wtrenker@shaw.ca> Message-ID: <3F350312.10001@rogers.com> Jarek Zgoda wrote: ... >>http://sourceforge.net/projects/pyspelling/ >> >> > >This one doesn't have too much to offer... According to SF: "this >project did not release any files" and its state is "pre-alpha". > > Yup. I suspended work on it when it became obvious that it would be months and months (years, maybe) before Chandler actually needed a spell-check engine. The engine is fully functional (I use it to lookup words I don't know how to spell all the time), but the focus of the project is on having a *toolkit* from which to build spell-checking services into applications, rather than having a particular spell-checking service. In particular, it focusses on making it possible to use large numbers of potentially dynamic word-sets. The idea behind that being to allow IDE (or Chandler) developers to construct per-document/document fragment, and per-project/library/programming-langauge/user grammars and use them all through the same query interface, swapping in grammars as appropriate for any given lookup. The engine can store the grammars on-disk (2 or 3 formats), or in-memory, or you can provide your own storage mechanism. At the moment the project has a fairly good phonetic compression algorithm (~= to the aspell one at the time, (constructed by reading the Aspell documention), and producing fairly similar results), and can do queries across "normal"-sized on-disk grammars fairly quickly (the in-memory ones are extremely fast of course), though the 3/4 million word grammars can be noticably slow. It can read the grammar lists from Aspell dictionaries, btw. If what you're looking for is an out-of-the-box spell checker, you'll probably want to look at one of the aspell/ispell wrappers (e.g. snakespell). They are designed for looking up words in fairly static (compiled) word-sets, and for simple "is this similar to any English/French/German word" queries it's the easiest thing to manage. The Python Spelling Construction Set really is a construction set, not a packaged service. That said, I should probably just run setup.py sdist bdist_wininst so that people can check it out without needing a CVS checkout. Enjoy, Mike _______________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://members.rogers.com/mcfletch/ From hancock at anansispaceworks.com Fri Aug 22 09:30:15 2003 From: hancock at anansispaceworks.com (Terry Hancock) Date: Fri, 22 Aug 2003 08:30:15 -0500 Subject: Component Racks Message-ID: Hi all, I'm trying out an "interface/component/rack" model for handling 3rd party code in my current project, and I've run into a design question which seems to hinge on the internal design of Python (namely how efficient is the name/binding model compared to a variable/contents model). Basically, each "component" is a class (possibly all different, but each implementing a single "interface"). The "rack" is a PersistentMapping (which is in turn a subclass of UserDict). So, you can just access components through the rack, like so: Diner['spam'].eat() Where 'spam' is the component's key. So far, so good. Now when I register this component into the rack (or should I say "plug"?), I collect a number of pieces of meta data that I might want to access -- such as a "label" or "key", a longer descriptive "name", and an small graphical "icon", all of which are used in the user interface when representing access to this object. Where should that meta data be stored? Intuition from some other languages would suggest that that (very lightweight data) ought to be in a separate data structure to avoid performance problems with accessing the full blown class objects. But, since Python just slings around name references to objects, I wonder if I'd be safe just including the meta-data in the actual objects: In other words, I just modify the component object to contain the necessary meta data: class SpamComponent: __implements__ = SpamAPI label = 'spam' name = 'Spam' title = 'Yummy, yummy spam' icon = 'Icon/spam16x16_png' def eat(self): pass # ... etc ..., possibly large and complex class Basically, my question is, should I be worrying about memory access problems if I have a lot of these components and I have a lot of objects that need to get, say, the "icon" and "label" without needing the whole object (i.e. will those kinds of simple accesses be slow compared to fetching them from a dictionary of simpler SpamComponentPlug objects). Now, having said all that in a pure Python context, does it matter if the "full-blown-class" is a persistent data object in a ZODB (i.e. a Zope object)? As I currently have it, the SpamComponentPlug object is *not* a persistent object in itself (but it's stored in a PersistentMapping, so that may have the same effect). Obviously, the disadvantage to this seperate SpamComponentPlug object is that it's *one more object* to keep track of. It requires the call above to read like this: Diner['spam'].actual_object.eat() (i.e. I have to make an extra indirection step -- from the SpamComponentPlug to the SpamComponent). I'd like to eliminate that step. But I've managed to really confuse myself about what impact this will have on performance (memory consumption, relative speed, etc.). Would the size of the SpamComponent class definition have any effect on performance? Thanks for any illumination, Terry -- Terry Hancock Anansi Spaceworks http://www.AnansiSpaceworks.com/ From mesteve_b at hotmail.com Sat Aug 16 18:26:01 2003 From: mesteve_b at hotmail.com (python newbie) Date: Sat, 16 Aug 2003 22:26:01 GMT Subject: CDR Support Message-ID: I'm starting to write a simple backup program using wxPython. But I figure I might as well support rewritable CDROM that most people use. ( I still don't have one, that's just wrong). Does anyone have knowledge of support for rewriteable CDROM's in python? Thanks From theller at python.net Mon Aug 18 15:53:36 2003 From: theller at python.net (Thomas Heller) Date: Mon, 18 Aug 2003 21:53:36 +0200 Subject: Python Debugger References: <6ee58e07.0308181134.383a69e7@posting.google.com> Message-ID: llothar at web.de (Lothar Scholz) writes: > Is there any python debugger that can > > 1) be used remotely > 2) can handle multiple threads > > I checked Eric, IDLE and Wing-IDE. None of them can do this. > Any other recommendations? Hapdebugger claims all this (but I've never really tried it). http://hapdebugger.sourceforge.net/ Thomas From aleaxit at yahoo.com Sun Aug 17 08:44:02 2003 From: aleaxit at yahoo.com (Alex Martelli) Date: Sun, 17 Aug 2003 14:44:02 +0200 Subject: simple text parser? References: Message-ID: Brandon J. Van Every wrote: ... > I'm making a 2D game with a simple "adjacent freeform territories" map. I > need to make save files for this. I figure I could store the data in > either > binary or text. The amount of data to be stored should be small enough > that > efficiency and size do not matter. What does matter, is I don't want to > spend any time at all on this. I want something off-the-shelf. > > Can anyone recommend simple text parsers implemented in Python? > > Alternately, doesn't Python have some kind of automagical serialization > pack/unpack functionality? How does that work? I remember reading As several others appear to have indicated already, cPickle is generally the best module for serializing your data (e.g. to disk) under the general conditions you're specifying. The other suggestions (CSV, XML, and so forth) were based on misunderstanding your specs as meaning you needed _interoperability_ between Python and C# versions, which you have later clarified is not the case. > something about that in the Python docs awhile ago. Before you scream > RTFM, bear in mind that my current plan is to write versions of this game > in C# / > .NET and Python / WhateverWidgets simultaneously. I'm ignorant of both > platforms, this is an excuse to do a comparo. And, the whole point of > moving to higher level language development is to minimize pain. Asking > questions here rather than reinventing the wheel is part of that agenda. > I want to handle this problem off-the-shelf. Developing a program under each of two platforms you previously didn't know is no doubt a good way to compare several characteristics of those platforms. Out of curiosity -- are you relying on Usenet help, rather than a manual, for the C# version, too? Alex From pedrosch at gazeta.pl Fri Aug 15 10:27:18 2003 From: pedrosch at gazeta.pl (Drochom) Date: Fri, 15 Aug 2003 16:27:18 +0200 Subject: cPickle alternative? Message-ID: Hello, I have a huge problem with loading very simple structure into memory it is a list of tuples, it has 6MB and consists of 100000 elements >import cPickle >plik = open("mealy","r") >mealy = cPickle.load(plik) >plik.close() this takes about 30 seconds! How can I accelerate it? Thanks in adv. From brian_l at yahoo.com Thu Aug 14 02:32:34 2003 From: brian_l at yahoo.com (Brian Lenihan) Date: 13 Aug 2003 23:32:34 -0700 Subject: Determine file type (binary or text) References: <3F3A8275.8B6EE8C4@engcorp.com> Message-ID: Peter Hansen wrote in message news:<3F3A8275.8B6EE8C4 at engcorp.com>... > "Contains only printable characters" is probably a more useful definition > of text in many cases. I can't say off the top of my head exactly when > either definition might be a problem.... wait, how about this one: in > CVS, if you don't have a file that is effectively line-oriented, human > readable information, you probably don't want to let it be treated as > "text" and stored as diffs. In that situation, "contains primarily > printable characters organized in lines" is probably a more thorough, > though less deterministic, definition. We check for binary files in our CVS commitprep script like this: look for -kb arg open the file in binary mode, read 4k fom the file and... for i in range(len(buff)): a = ord(buff[i]) if (a < 8) or (a > 13 and a < 32) or (a > 126): non_text = non_text + 1 If 10 percent of the characters are found to be non-text, we reject the file if it was not commited with the -kb flag, or print a warning if the file appears to be text but is being checked in as a binary. We don't bother checking for charsets other than ascii, because localized files have to be checked in as binaries or bad things (tm) happen. From newsgroups at jhrothjr.com Tue Aug 19 21:40:06 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Tue, 19 Aug 2003 21:40:06 -0400 Subject: Unification of logging in Python's Standard Library References: <3a8e83d2.0308182217.7ccaf883@posting.google.com> <3a8e83d2.0308191655.7a82881b@posting.google.com> Message-ID: "Matthew Barnes" wrote in message news:3a8e83d2.0308191655.7a82881b at posting.google.com... > I will say that unittest is what motivated me to suggest this in the > first place, since I'm working on a testing framework that is > attempting to take advantage of both the unittest *and* logging > modules. Perhaps a new TestRunner class that uses logging > (LoggingTestRunner?) might coexist with the default TextTestRunner. Perhaps you could tell us a bit more about this? My usage of unittest is (relatively) pure XP/TDD - I expect all of the tests to pass except the last one I worked on, and when they don't, I swat it immediately. Consequently, I don't see any need for logging anything. John Roth > > Matt From ramiak2000 at yahoo.com Tue Aug 19 18:57:01 2003 From: ramiak2000 at yahoo.com (Rami A. Kishek) Date: Tue, 19 Aug 2003 18:57:01 -0400 Subject: 2 funny Py2.3 Issues: 'datetime', string.join() Message-ID: <3F42AB3D.F9B456F4@yahoo.com> 1) I particular like how the Python 2 syntax has all the string functions as methods of the object (so we don't have to import string. However, wouldn't it make more sense if the "join" mehtod actually belonged to the List object, since it primarily operates on lists? e.g., supposing we want to do string.join(string.split(a, '\n')) This now translates either into string.join(a.split('\n')) (which still requires us to import string, or into the crude: a.join(a.split('\n')) which is very confusing for anyone browsing the code. If join() was attached to lists however, this would read much more nicely as: a.split('\n').join() 2) I had a difficult time trying to subclass the new datetime.date class. I basically had written something similar for my own applications, and now want to convert my class to take advantage of the 'datetime.date' class. Unfortunately, seems there is no way I can override some of the methods provided by the date object. E.g., supposing I wish to have the option of initializing the class using a tuple(y,m,d) or a string date instead of the 3 integers. I can build my __init__() to test the type of the first argument and act accordingly, e.g.: class RDate(datetime.date): def __init__(self, year, month=1, day=1): if type(year) == type(()): year, month, day = year[0:2] datetime.date.__init__(self, year, month, day) Unfortunately, Python doesn't like that, and keeps complaining when I pass a tuple: >>> RDate((2003,5,6)) TypeError: function takes exactly 3 arguments (1 given) If instead I try to forget about datetime.date.__init__() and set my own vars (like self.year = year, etc.), I get: self.year, self.month, self.day = (year, month, day) TypeError: attribute 'year' of 'datetime.date' objects is not writable Anyone has any clue what is going on here? From grante at visi.com Fri Aug 8 16:31:44 2003 From: grante at visi.com (Grant Edwards) Date: 08 Aug 2003 20:31:44 GMT Subject: execute command in CURRENT shell References: Message-ID: <3f3408b0$0$165$a1866201@newsreader.visi.com> In article , Rich Drewes wrote: >>>simple question, how to execute command in current shell, not >>>in subshell? > > execl() will execute a new program in the current process, > replacing the current process. Right. However, it still can't do anthing in or to the current shell, since the current process is already a child of the "current shell". IOW, it can't modify the current shell's environment (the environment of the parent process) which is what I understood to be the OP's desire. -- Grant Edwards grante Yow! My BIOLOGICAL ALARM at CLOCK just went off... It visi.com has noiseless DOZE FUNCTION and full kitchen!! From irmen at -NOSPAM-REMOVETHIS-xs4all.nl Tue Aug 5 10:05:08 2003 From: irmen at -NOSPAM-REMOVETHIS-xs4all.nl (Irmen de Jong) Date: Tue, 05 Aug 2003 16:05:08 +0200 Subject: ANN: Snakelets 1.1 (simple-to-use web app server with dynamic pages) In-Reply-To: References: <3f2ea0a0$0$49110$e4fe514c@news.xs4all.nl> <3f2f7bf4$0$49103$e4fe514c@news.xs4all.nl> <3f2fab63$0$49103$e4fe514c@news.xs4all.nl> Message-ID: <3f2fb995$0$49114$e4fe514c@news.xs4all.nl> Karl Scalet wrote: > very easy and nice, indeed. > BTW after a change of the port-number and a restart, > the server crashed: > snakeserver/server.py line 511: > the clearPageCache argument is missing :-( A small bug indeed. Will fix this ASAP :) you can easily fix this yourself in the meantime by adding the missing argument to the call to createHTTPD(). > I will play around with Snakelets even more. As far as > I can see now, it's pretty right for educational > purposes (at the least). My purpose was twofold: - understand better how to write dynamic web applications - understand the inner workings of a web application server. Your course, is it about both? Or only the first? > Do you intend to bring Snakelets up to a production level? No, I don't. But if somebody else wants to do that, be my guest :) > Which one of the current products (Webware?) do you > think is closest to yours? I think Webware, because it also has the concept of 'servlets' and 'python server pages'. Actually, I "borrowed" a few ideas from Webware for my Ypages :-) --Irmen From P at draigBrady.com Thu Aug 21 05:34:56 2003 From: P at draigBrady.com (P at draigBrady.com) Date: Thu, 21 Aug 2003 10:34:56 +0100 Subject: popen problems In-Reply-To: References: Message-ID: <7o01b.28415$pK2.44758@news.indigo.ie> David McNab wrote: > Hi, > > When using os.popen, or popen2.Popen3 objects, I see a situation when > the child process sometimes doesn't get terminated, even when the child > program has exited. I noticed that the popen2.Popen3 class only waits for (reaps) children on subsequent runs. I.E. there is always one hanging around. > It's like Python (2.2.3) intermittently leaves the process dangling. > Sometimes 'killall python' doesn't clean up these dead tasks. hrm, never noticed that. P?draig. From code at joecheng.com Tue Aug 12 01:22:52 2003 From: code at joecheng.com (Joe Cheng) Date: Tue, 12 Aug 2003 05:22:52 GMT Subject: Python vs. C# References: <3f357a9b@shknews01> Message-ID: (Disclaimer: I'm a relative newbie to Python; I started learning it a few months ago because of all the buzz on Artima.com about it and Ruby (also worthy of consideration if you like Python). On the other hand, I've been programming full-time in C# since January (before that I programmed almost exclusively in Java for a few years).) >From a purely language point of view, I think the comparison can be boiled down to two main points. * Python is dynamic, C# is static. You've got a C++ background, so it doesn't sound like you would consider C#'s static typing a liability, nor would you likely fall in love with metaclasses and the like. So, most of the arguments along the lines of "C# is too inflexible" will probably not be relevant to you. * Python has some _really_ convenient syntactic sugar. Being able to declare lists, tuples, and hashes as literals can be nice. List comprehensions would knock out half the for/foreach loops I have to write in C#. I also consider the indents-instead-of-braces to be syntactic sugar--I for one really like them (the indents, that is). You can simply write code faster in Python; this is not really controversial. I'm a newbie in Python but very familiar with C#, and still for a given programming task I'd likely be able to do it almost as fast in Python. * It's usually easier to read a given chunk of Python code than the equivalent chunk of C# code--as long as it's clear what types you're dealing with (a given in C#, not so in Python) and you're not doing any clever dynamic stuff like the "memoize" function someone else talked about in this thread. C# code is cluttered but simple; you could say Python code is readable but potentially tricky. And just to throw in some further real-world differences, that I'm not sure have been covered yet in this thread: * .NET has, as you'd expect, really strong Win32/COM interop stories. If you're building, say, a consumer-quality desktop app, these are really invaluable. * .NET has a really nice remoting framework in .NET Remoting. It is not only quite performant and flexible, but dead easy to use. Same for XML handling, and (from what I hear--is anyone actually building any??) web services. * I (and most serious programmers I've talked to) don't see a great deal of value in the multi-language support of .NET, unless perhaps you are a class library vendor (and all the .NET libraries I've seen have been written in C#). * I don't really like VS.NET, but I have to admit, I haven't heard of anything even close for Python. (On the other hand, in everything but GUI builders, the best Java IDEs blow away VS.NET.) * C#/.NET has to be one of the most mature "version 1.1" programming systems in history. (I'm too young to be making definitive statements about programming history, though...) You can tell by reading Chris Brumme's blog the amount of sophistication they have already achieved. Frankly, it's a little frightening how much MS can accomplish in just a couple of years--when they want it bad enough. * Math.sin(x) versus sin(x)? Really, who cares?? * The .NET community does not seem as clever and innovative, nor as passionate, as the Python community. You sorta get the sense that everyone who works with .NET is getting paid to do so, while Python hackers bang away on their keyboards with glee. And it feels like 90% of the innovation in the .NET realm comes from Microsoft itself (or perhaps, 60% from MS and 30% from the Java open-source community--NAnt, NUnit, NLucene, etc.). To summarize, I don't particularly like C#--I'd rather be programming in Java with IntelliJ or Eclipse. There's nothing really fun and exciting about programming in it day-to-day (well, maybe if you're coming from C++ you'll be excited about not having to worry about memory leaks or segfaults). The libraries generally work as billed, the compiler gives useful warnings, the debugger is well-integrated and easy to use, the documentation is comprehensive if not particularly deep in places. In contrast, I like Python very much (well, actually, Ruby is the one that I really like--but close enough). Python is worth knowing, if for nothing else, then at least for banging out one-off scripts or string processing programs or command line utilities (even ones of significant complexity). The syntax feels nice, the conciseness is very refreshing, the interactive programming environment is addictive. However, when it comes down to building the big, hairy, slightly nasty (just admit it) software that brings home the bacon, sometimes it's just gotta be C#. And if you live in Seattle, I'd say it's gotta be C# all the way. From jelefebvre at mac.com Wed Aug 20 21:01:48 2003 From: jelefebvre at mac.com (Jerome Lefebvre) Date: 20 Aug 2003 18:01:48 -0700 Subject: Some work on the ICPC problems. Message-ID: Hello, Hope this will interest a few. I been working with a friend on the problems given out during the "International Collegiate Programming Contest" (ICPC) http://icpc.baylor.edu/icpc/ . Started out just trying to find the solutions and then moving on, to "aggressively" trying to find the best solution for each problems. First started to work on the problems using C++ and then moved on to using Python, mostly since it was much easier to play around with different implementations that way. Don't have huge amount of experience using python, so did my best so far using a lot of dir() and my Safari account (http://safari.oreilly.com/) but wouldn't mind having some help from more experience programmers now.. Any kind of help would be good; pointing out some libraries, showing how some built in type might be more appropriate then what I was using or simply pointing out that I'd be much smarter if I would simply put more/any comments.. Anyway, here it is: http://www.ledward.org/jelefebvre/icpc/ One thing I do know I could be doing better is using testcases to test those solutions out. Just not sure how I could go about it. Most of the problems follow simple case of: main: reads from a file, does some formatting on the input and sends it to a function called process. process: just goes through the data, and prints out things as it goes. then goes back to main to get some more data. Nothing to spectacular, but not to easy to test. The solution I came with was: redirect print to a file 'test.output' and then compare it with an other file of expected output. Takes a while to set up, but not many other options around. What I'm hoping is that others have worked on the problems, and fleshed out other sample input for their solutions, those could easily be swapped around. As oppose to re-writting my code to use smaller functions and testing those out.. Any ideas? Thank you for reading and any help you can bring, Jerome Lefebvre jelefebvre at mac.com From gmuller at worldonline.nl Sun Aug 3 14:12:46 2003 From: gmuller at worldonline.nl (GerritM) Date: Sun, 3 Aug 2003 20:12:46 +0200 Subject: Announcing issue 2 of The Agile Developer's Life free eZine References: <3F293658.3030609@users.ch> <3F2BC7B0.E9506C91@engcorp.com> <3F2D3E18.2020500@users.ch> Message-ID: "Borcis" schreef in bericht news:3F2D3E18.2020500 at users.ch... > Peter Hansen wrote: > > Borcis wrote: > > > >>DevCoach wrote: > >> > >>>I have just published the second issue of The Agile Developer's Life > >>>(formerly called The Agile Life) > >> > >>How much of Rumsfeld's special vocab does it port to computer programming ? > > > > > > Translation, please, anyone? > > "Agile" as a buzzword in the current sense, I first heard applied by > Rumsfeld to the military, so that I naturally concieve of it as an > interface component to Rumsfeld's mind. Hence "porting". > As fas as I know agile is already a buzzword for quite some time. In the software world used as opposition against all "heavy-weight" methodologies. I doubt that Rumsfled invented it, although I do believe that the same fashion agile/flexible/light-weight is actual for the military. regards Gerrit P.S., I used light-weight before I heard others using agile, see for instance "Light Weight Architectures; The way of the future?" -- www.extra.research.philips.com/natlab/sysarch/ From belred1 at yahoo.com Sun Aug 3 19:22:19 2003 From: belred1 at yahoo.com (Bryan) Date: Sun, 03 Aug 2003 23:22:19 GMT Subject: popen eating quotes? References: Message-ID: "Jeff Epler" wrote in message news:mailman.1059942307.4825.python-list at python.org... > This has been discussed before. One such thread that I participated in > was > http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&threadm=0000161b%40bossar.com.pl&rnum=1&prev=/groups%3Fq%3Dshell%2Bquoting%2Bnt%2Bgroup:comp.lang.python%26hl%3Den%26lr%3D%26ie%3DUTF-8%26selm%3D0000161b%2540bossar.com.pl%26rnum%3D1%26filter%3D0 > [apologies for the long URL, I don't know how to get a good memorable > URL for a google groups search] > > This really is a cesspool on Windows, and the fault isn't Python's. > Python is just calling the Windows functions, which insist on behaving > badly compared to the Unix behavior. > > unix bigot'ly yours, > jeff > thanks for the link, but it didn't help me solve my problem. i just read many articles posted about popen and windows and there seems to be a solution to this problem. i need to pass a path to a program using popen so i can capture the output. since the path and/or file name can have spaces in it, i need to quote it. what's the way to get around this issue? i saw it mentioned in several places to try win32pipe.popen, but it had the same problem as os.popen. so, is this something that cannot be done in python at all with no work-around? is there another way besides using os.system or os.popen? >>> import os >>> def run_args(arg): ... i, o = os.popen4('"c:/program files/test/args.bat" -vv %s' % arg) ... print o.read() ... >>> run_args('"this is a very long path with spaces"') 'c:/program' is not recognized as an internal or external command, operable program or batch file. thanks, bryan From afriere at yahoo.co.uk Mon Aug 18 00:52:07 2003 From: afriere at yahoo.co.uk (Asun Friere) Date: 17 Aug 2003 21:52:07 -0700 Subject: ``Type-checking'' with dir() References: <70df36e9.0308161136.3c414a80@posting.google.com> <6rx%a.547$Ck2.471@nwrdny03.gnilink.net> Message-ID: <38ec68a6.0308172052.474d1af8@posting.google.com> oops, I meant "is going to be passed list-like objects etc ..." From mis6 at pitt.edu Thu Aug 7 13:19:38 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 7 Aug 2003 10:19:38 -0700 Subject: Bug? If not, how to work around it? References: Message-ID: <2259b0e2.0308070919.2bedce6@posting.google.com> Gon?alo Rodrigues wrote in message news: > So, is it a bug? In other words, should I open a bug report? > > With my best regards, > G. Rodrigues I would open a bug report; at the best this is a documentation bug, since the fact that ___getattr__ is skipped by special methods is never mentioned in the documentation, at least AFAIK. Something similar with __len__ caused confusion at least twice in the last few monts. See for instance http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&frame=right&th=c809d56daee70926&seekm=2259b0e2.0307040511.1eb91faa%40posting.google.com#link6 Michele From vze4rx4y at verizon.net Sat Aug 2 00:48:49 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Sat, 02 Aug 2003 04:48:49 GMT Subject: Interfaces (a la PEP 245 and Zope) References: <78ednTw5QfxmebSiXTWJhA@august.net> Message-ID: > Now of course, I could pick through the Interface module and > write a check that resembles the verification that it does, but it seems to > me that there ought to be a simpler solution (and if I were going to > do that, I should probably really be improving the Interface module > rather than putting the code in my package). > > So, am I missing some existing way to do this? I posted a simple interface checker in the Python cookbook. Perhaps, it will meet your needs: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/204349 Raymond Hettinger From skip at pobox.com Sat Aug 2 23:23:29 2003 From: skip at pobox.com (Skip Montanaro) Date: Sat, 2 Aug 2003 22:23:29 -0500 Subject: PyChecker work with Python 2.3? In-Reply-To: <3F2C5300.FA223CBA@easystreet.com> References: <3F2C5300.FA223CBA@easystreet.com> Message-ID: <16172.32817.660483.704040@montanaro.dyndns.org> Al> The pychecker site says that pychecker works with versions Al> 1.5 through 2.2. Any reason to expect that 2.3 breaks it? Al> Anyone tried it to see? I run Python CVS as my normal Python on my laptop. I've never had a problem with PyChecker. Skip From jylevy at pacbell.net Sun Aug 3 01:45:43 2003 From: jylevy at pacbell.net (Jacob Levy) Date: Sun, 03 Aug 2003 05:45:43 GMT Subject: [ANNOUNCE] e4Graph 1.0a8 released Message-ID: <3F2CA19B.7080600@pacbell.net> I am pleased to announce the 1.0a8 release of e4Graph, the seventh Alpha release. WHAT IS IT: e4Graph is a C++ library that allows programs to store graph-like data persistently and to access and manipulate that data efficiently. With e4Graph, you can arrange your data in the most natural form that reflects the relationships between its parts, rather than having to force it into a table-like format. The e4Graph library also allows you to concentrate on the relationships you want to represent, and not on how to store them in a database. You can modify data items, and add and remove connections and relationships between pieces of data on the fly. e4Graph allows you to represent an unlimited number of different connections between pieces of data, and your program can selectively manipulate the data according to the relationships it cares about, not having to know about other connections represented in the data set. The e4Graph package also provides bindings in several other languages, currently Tcl, Python and Java, and allows input/output of object graphs via an XML representation. The e4Graph package is built on top of Metakit 2.4.9.2, and optionally uses Tcl 8.4.4, Python 2.2.3, Java 1.1 or later, and Expat 1.95.5. WHERE TO GET: Downloads: http://sourceforge.net/projects/e4graph/ Homepage: http://www.e4graph.com/e4graph/ Changelog: http://www.e4graph.com/e4graph/changes.txt Installation: http://www.e4graph.com/e4graph/e4install.html WHAT IS NEW: Support for MacOS X 10.2 and several other platforms was added. Support for Python 2.2 and later releases was added. The Java binding was updated. The event mechanism was completely overhauled and support for user defined events was added. The vertex caching mechanism was moved from the Tcl binding to the core e4Graph library to enable other language bindings to benefit from the increased performance afforded by the cache. The interface between e4Graph and data base drivers was formalized in preparation for supporting new data base drivers in addition to Metakit. Additional work was done to support 64-bit systems and very large storages; more work is needed. Support for SWIG was added so new language bindings can be created with SWIG, in preparation for incorporating Perl, PHP and Ruby bindings in the next release. Many bugs were fixed. ACKNOWLEDGMENTS: Michael Krimerman contributed the Python binding. J.P. Fletcher helped me get started with SWIG support. Daniel Steffen and Nicholas Brawn were instrumental helping with MacOS X support. I wish to acknowledge support from the HP test-drive facility and from the SourceForge compile farm. Many people (too many to mention) contributed bug reports and bug fixes. Geoff Shapiro and David Van Maren suggested many useful API changes. From heikowu at ceosg.de Thu Aug 21 12:30:42 2003 From: heikowu at ceosg.de (Heiko Wundram) Date: Thu, 21 Aug 2003 18:30:42 +0200 Subject: What's better about Ruby than Python? In-Reply-To: References: Message-ID: <1061483442.14474.49.camel@d168.stw.stud.uni-saarland.de> On Thu, 2003-08-21 at 12:19, Aahz wrote: > In article , > Andrew Dalke wrote: > >Can we have a deprecation warning for that? I've never > >seen it in any code I've reviewed. > > We will, probably 2.4 or 2.5. (Whenever 3.0 starts getting off the > ground.) Hmm... I still use <> exclusively for my code, and I wouldn't really like it getting deprecated. At least for me, != is more difficult to see when browsing source than <> is, as != has a striking similarity to ==, at least at the first glance... I know <> has been deprecated for long, but I'd much rather have both syntaxes allowed, also for the future... But anyway, I guess the way until it will be deprecated is still a long one, so I won't bother to protest more now... :) Heiko. From fawcett at teksavvy.com Thu Aug 14 00:28:58 2003 From: fawcett at teksavvy.com (Graham Fawcett) Date: Thu, 14 Aug 2003 00:28:58 -0400 Subject: 3 new slogans In-Reply-To: References: Message-ID: <3F3B100A.9040702@teksavvy.com> smarter_than_you wrote: >1) Python made me rich >2) Python saved my life >3) Python changed my mind > >put them on T-shirts. Collect all three!! > > how about I'm not really a wizard, I just use Python or (untested, but I think it's right) s/(perl|java|vba|c(#|\+\+|)?)/python/g or, with apologies to Clarke, Any sufficiently advanced technology is indistinguishable from Python -- Graham From fa507874 at skynet.be Wed Aug 6 17:45:44 2003 From: fa507874 at skynet.be (conatic) Date: Wed, 06 Aug 2003 23:45:44 +0200 Subject: Hints about a script that read ftp contents .... Message-ID: I have read ftpmirror.py but I can' manage to do what I want : I'd like a script that read ftp directories recursively (ident if a file or a directory) and puts all pdf's documents in a list. Has anyone could give me an example of a function that read contents and make the difference between files and directory. Thanks for reading. Conatic From agh at tpg.com.au Thu Aug 14 09:37:09 2003 From: agh at tpg.com.au (Alastair G. Hogge) Date: Thu, 14 Aug 2003 23:37:09 +1000 Subject: Tuple to string problems Message-ID: <3f3b9080@dnews.tpgi.com.au> Hello *, I'm using Python and the cgi module to retrive data from a HTML form. I'm then trying to get that information into a string. But efforts fail when I run type(foo) on my string. type() returns tuple. My codes follows: #!/usr/local/bin/python import cgi import time import SeAnRe # Begin form = cgi.FieldStorage() # Grab the data from web page form qu = "(" for name in form.keys(): qu += "'" + str((form[name].value)) + "'," # Now we remove the 'Submit' text added by form key above and replace it with it with the date, time and a closing ")" tail = "'" + str(time.strftime("%Y-%m-%d")) + "','" + str(time.strftime("%H:%M:%S")) + "')" final_qu = SeAnRe.Action("'Submit',", tail, qu) So basicly final_qu would be ('1','two','hello','2003-08-14','23:32:07') However has stated above type(final_qu) return tuple. I did get a little advice on running str on every element of final_qu like this: foo = "" for k in final_qu.get_each_value: foo += str(k) But then I get "AttributeError: 'tuple' object has no attribute 'get_each_value" The reason I need foo to be a string is because I'm using pgdb. A Python interface to PostgreSQL. Any would be great. Thanks in advance -Al From cartermark46 at ukmail.com Fri Aug 29 16:58:13 2003 From: cartermark46 at ukmail.com (Mark Carter) Date: 29 Aug 2003 13:58:13 -0700 Subject: Need good example database schema References: Message-ID: pobrien at orbtech.com (Patrick K. O'Brien) wrote in message news:... > I'm looking for a good schema to use as an example for an object > database system. Something like a books/authors/publishers or > teachers/students/courses kind of thing. There are plenty of examples > of such to be found, especially in the academic literature involving > object databases, but most of them are pathetic. It's hard to take a > schema seriously when it shows MarriedTeacher inheriting from Teacher, > etc. I want something that makes proper use of inheritance, has > classes with reasonable attributes, and does a decent job reflecting > reality (ie, books can have more than one author, a teacher of one > course could be a student of another, etc.). Any suggestions? I found a link: http://www.geocities.com/tablizer/oopbad.htm (and there are others) who suggest that object-oriented databases aren't a good idea. Tabular databases (and in fact a tabular design rather than an object-oriented design in general) are more often than not likely to be a better bet. But I am of course generalising. From vze4rx4y at verizon.net Mon Aug 4 02:27:02 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Mon, 04 Aug 2003 06:27:02 GMT Subject: Dict to "flat" list of (key,value) References: <3f2c54f6.11554794@news.lexicon.net> Message-ID: [Raymond] > >index = {} > > for pagenum in range(len(pages)): > > page = pages[pagenum] > > for word in page: > > index.setdefault(word, []).append(pagenum) > > > >it-all-starts-with-a-good-data-structure-ly yours, [John Machin] > Amen, brother. > > Even worse: I recall seeing code somewhere that had a data structure > like this: > > {k1: [v1,v2], k2: v3, k3: None, ...} > instead of > {k1: [v1,v2], k2: [v3], k3: [], ...} > > I liked the elegant code example for building a book index. However in > practice the user requirement would be not to have duplicated page > numbers when a word occurs more than once on the same page. If you can > achieve that elegantly, please post it! How about a simple Py2.3 clean-up pass: # Uniquify and sort each list of page numbers for word, pagelist in index.iteritems(): newlist = dict.fromkeys(pagelist).keys() newlist.sort() index[word] = newlist Raymond Hettinger From bokr at oz.net Mon Aug 18 18:01:58 2003 From: bokr at oz.net (Bengt Richter) Date: 18 Aug 2003 22:01:58 GMT Subject: overriding a tuple's __init__ References: Message-ID: On 18 Aug 2003 10:27:47 -0400, aahz at pythoncraft.com (Aahz) wrote: >In article , >Andrew Dalke wrote: >> >>The problem is the immutability. This one one of the >>new changes in 2.3 I still don't fully understand, but I do >>know the solution is __new__ >> >>>>> class pair(tuple): >>... def __new__(self, a, b): >>... return tuple((a, b)) >>... >>>>> >>>>> pair(2,3) >>(2, 3) >>>>> x=_ >>>>> type(x) >> >>>>> >> >>That should give you some pointers for additional searches. > >This works better: > >class pair(tuple): > def __new__(cls, *args): > return tuple.__new__(cls, args) so far, just class pair(tuple): pass should do it, no? Unless you want to take the name as suggesting that length 2 should be enforced. Don't know what other methods are planned, but ISTM you get the vanilla __new__ for free. Or am I missing something? Regards, Bengt Richter From op73418 at mail.telepac.pt Wed Aug 6 15:40:25 2003 From: op73418 at mail.telepac.pt (Gonçalo Rodrigues) Date: Wed, 06 Aug 2003 20:40:25 +0100 Subject: Bug? If not, how to work around it? Message-ID: Hi, Consider the following class: >>> class Test(object): ... def __init__(self, obj): ... self.__obj = obj ... def __getattr__(self, name): ... return getattr(self.__obj, name) ... Now: >>> a = Test([]) >>> a.__iter__ >>> iter(a) Traceback (most recent call last): File "", line 1, in ? TypeError: iteration over non-sequence >>> Is this a bug? If not, how to code Test such that iter sees the __iter__ of the underlying object? With my best regards, G. Rodrigues P.S: Tested with the latest 2.3 on win2k. From trentm at ActiveState.com Wed Aug 20 15:10:31 2003 From: trentm at ActiveState.com (Trent Mick) Date: Wed, 20 Aug 2003 12:10:31 -0700 Subject: Sending to a process opened from popen() In-Reply-To: <4378fa6f.0308200924.76294713@posting.google.com>; from mnations@airmail.net on Wed, Aug 20, 2003 at 10:24:23AM -0700 References: <4378fa6f.0308200924.76294713@posting.google.com> Message-ID: <20030820121031.B10093@ActiveState.com> [Marc wrote] > Hi all, > > In searching for an answer to this problem I found several solutions > dealing with Unix but none dealing with Windows. Basically I want to > send a ping for an indefinite period of time, stop it at some point, > and then read the results. I open up a ping process using popen(). > > I found ways to send a break signal using signal module, but for that > I need the PID. All the ways described in the newsgroups for finding > PID were for UNIX. > > So how do I find the PID of a spawned process in Windows to send a > break signal? You want to use the Win32 API method GenerateConsoleCtrlEvent: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/generateconsolectrlevent.asp The PyWin32 extensions (comes with ActivePython, can be installed separately on other Python distros) provide access to this: win32api.GenerateConsoleCtrlEvent(win32con.CTRL_C_EVENT, pid) But you need to get the pid for that. You already have the PID if you started a process with CreateProcess, but you are using popen, which hides those details. I don't know an easy way to get the PID. I have a process.py module which will spawn a process and return a object represent it with attributes for stdin/stdout/stderr and methods to .wait(), .kill(). This might be more helpful to you, but my process.py is not perfect by any stretch. http://starship.python.net/~tmick/#process Cheers, Trent -- Trent Mick TrentM at ActiveState.com From aleax at aleax.it Thu Aug 21 03:45:40 2003 From: aleax at aleax.it (Alex Martelli) Date: Thu, 21 Aug 2003 07:45:40 GMT Subject: What's better about Ruby than Python? References: Message-ID: POYEN OP Olivier (DCL) wrote: >> Thus, the direct Python equivalent might be >> >> import __builtins__ >> __builtins__.len = someotherfunction >> >> and THAT usage is very specifically warned against e.g. in >> "Python in a Nutshell" -- you CAN do it but SHOULDN'T (again, one >> can hope to eventually see it "officially" deprecated...!). > > > Would that mean the end of > import sys > sys.stdout=myLogger() > ... > print 'it works' > ... > sys.stdout=sys.__stdout__ A dangerous idiom -- you should definitely use try/finally here, otherwise your sys.stdout will stay wrongly bound if there is an exception soon after it. But with try/finally, or hopefully some syntax tweak making try/finally semantics even easier to use, this is a kind of idiom that's gonna stay. sys is FULL of entries intended mainly as hooks for you to replace, by the way -- all of those which are named sys.hook:-). > Sad, sad, sad. Quite useful in some way. > But I assume it could be replace by the new > print >>>loggerInstace, "it works also, but is longer" not so new any more, but still my least-favourite Python construct. It doesn't replace temporary rebinding of sys.stdout to capture output from existing pieces of code in a *non-invasive* way, anyway; it's meant to be used instead of such rebinding when you need to divert output only for a brief span of code and don't mind being 'invasive' in that code. Alex From jepler at unpythonic.net Tue Aug 5 16:43:52 2003 From: jepler at unpythonic.net (Jeff Epler) Date: Tue, 5 Aug 2003 15:43:52 -0500 Subject: spawnv( ) or spawnl( ) do not launch a normal running process in Python 2.2.2? In-Reply-To: References: Message-ID: <20030805204347.GG15286@unpythonic.net> the third argument to os.spawnv is an argument list as in execv, not a command string as in popen and system. The statement you listed > os.spawnv(os.P_NOWAIT,'/usr/bin/python',('python hello.py >/dev/null runs the Python binary with its argv[0] set to 'python hello.py >/dev/null', which is probably going to drop into trying to read a script from standard input since there is no script or command on the commandline, but I'm not really sure what to expect in this crazy case. There's no easy way to do command redirections while using spawnv. Here's a piece of code to do so with fork+exec [tested]: def F(x): if not isinstance(x, int): return x.fileno() def coroutine(args, child_stdin, child_stdout, child_stderr): pid = os.fork() if pid == 0: os.dup2(F(child_stdin), 0) os.dup2(F(child_stdout), 1) os.dup2(F(child_stderr), 2) os.execvp(args[0], args) return pid you could do something similar with os.spawnv [untested]: def dup2_noerror(a, b): try: os.dup2(a, b) except: pass def coroutine_spawnv(flags, args, child_stdin, child_stdout, child_stderr): old_stdin = os.dup(0) old_stdout = os.dup(1) old_stderr = os.dup(2) try: os.dup2(F(child_stdin), 0) os.dup2(F(child_stdout), 1) os.dup2(F(child_stderr), 2) return os.spawnv(flags, args[0], args) finally: dup2_noerror(old_stdin, 0) dup2_noerror(old_stdout, 1) dup2_noerror(old_stderr, 2) Jeff From electricity at uymail.com Mon Aug 25 03:54:22 2003 From: electricity at uymail.com (U. N. Owen) Date: Mon, 25 Aug 2003 09:54:22 +0200 Subject: Python preinstalled on Windows - looking for details Message-ID: <20030825075422.30310.qmail@uymail.com> My brother has an HP Pavillon, and if I remember well, Python is used during the installation process. I don't think it is used later, but who knows ? Anyway, it's a bad idea to delete it. You should learn and use it ;-) -- _______________________________________________ Get your free email from http://www.uymail.com Powered by Outblaze From irmen at -NOSPAM-REMOVETHIS-xs4all.nl Fri Aug 29 05:06:33 2003 From: irmen at -NOSPAM-REMOVETHIS-xs4all.nl (Irmen de Jong) Date: Fri, 29 Aug 2003 11:06:33 +0200 Subject: print without intervening space In-Reply-To: <5b42ae4.0308290102.3f04b90b@posting.google.com> References: <5b42ae4.0308290102.3f04b90b@posting.google.com> Message-ID: <3f4f1794$0$49104$e4fe514c@news.xs4all.nl> Ernie wrote: >>>>for x in range(10) You forgot a ':' there... > > ... print x, > ... > > will output > > 0 1 2 3 4 5 6 7 8 9 > > > What if somebody wants instead > > 0123456789 No problem: >>> import sys >>> for x in range(10): ... sys.stdout.write(str(x)) ... 0123456789>>> --Irmen From sross at connectmail.carleton.ca Tue Aug 12 18:25:25 2003 From: sross at connectmail.carleton.ca (Sean Ross) Date: Tue, 12 Aug 2003 18:25:25 -0400 Subject: Howto MACRO in python ? References: <3F38D039.2B28800A@engcorp.com> <001201c360cd$3da065b0$6400a8c0@EVOD31> Message-ID: "Bengt Richter" wrote in message news:bhbhsm$2vv$0 at 216.39.172.122... > maybe there ought to be a magic __self__ in the local namespace of a function? I've played with trying to get something like that, but I haven't got anything reliable[1]. So far I have a very simple function that retrieves the calling function object: import inspect class ThisResolutionError(Exception): pass def this(): fname = inspect.currentframe(1).f_code.co_name frameno = 2 func = None while func is None: try: func = inspect.currentframe(frameno).f_locals.get(fname, None) frameno += 1 except ValueError: # reached end of call stack raise ThisResolutionError, "could not resolve %s" % fname return func So, when it works (which is not always), you can do things like: def f(): "f's doc string" __self__ = this() print __self__.__name__ print __self__.__doc__ print __self__.__dict__ def g(): __self__ = this() print "called nested function %s" % __self__.__name__ g() f.f_attr = "function attribute" f() -------------------output ---------------------- f f's doc string {'f_attr': 'function attribute'} called nested function g I would be interested to see something more general - something that could be called inside of any namespace (at the module, class, method, or function level) which you could then (atleast) query and (possibly) modify. Why would I want to do that? Fun, mostly. I like the idea of being able to query any object while being inside the object. +1 __self__ Sean [1] this() will not work in methods, and there can be issues if you put it in nested functions # # you can do this (if you want) # def f(): __self__ = this() def g(): print "called nested function g" __self__.g = g f() f.g() ---------------------- called nested function g # # but not this (the reason for which should be obvious) # def f(): __self__ = this() def g(): __self__ = this() print "called nested function %s" % __self__.__name__ __self__.g = g f() f.g() ------------------------- ThisResolutionError: could not resolve g From aleax at aleax.it Wed Aug 6 07:31:39 2003 From: aleax at aleax.it (Alex Martelli) Date: Wed, 06 Aug 2003 11:31:39 GMT Subject: classes (table) References: Message-ID: Wiebke P?tzold wrote: ... > import Mk4py I'm not experienced in this package, so I'm not sure this will work and can't test, but: > def __call__(self, row): > try: > nachname = row.Nachname Just change this to whatever = getattr(row, self.attributeName) Where self.attributeName can be any string, e.g. defaulting to 'Nachname' if you wish, as set e.g. in __init__. Alex From gh at ghaering.de Thu Aug 21 11:21:28 2003 From: gh at ghaering.de (=?ISO-8859-15?Q?Gerhard_H=E4ring?=) Date: Thu, 21 Aug 2003 17:21:28 +0200 Subject: Problems with python-list? In-Reply-To: References: <477762c2.0308201832.327cf5bc@posting.google.com> <7h31xvf43at.fsf@pc150.maths.bris.ac.uk> <7h3r83f2ogv.fsf@pc150.maths.bris.ac.uk> Message-ID: <3F44E378.6040103@ghaering.de> Andreas Kuntzagk wrote: > Is this [python.org] the same box which handles the registration for the PyPiPage? [...] Yes, it is the same box. -- Gerhard From mike at nospam.com Sat Aug 2 14:48:29 2003 From: mike at nospam.com (Mike) Date: Sat, 2 Aug 2003 11:48:29 -0700 Subject: Python speed vs csharp References: Message-ID: On Fri, 01 Aug 2003 16:14:47 -0400, David M. Cooke wrote: > At some point, Mike wrote: > [...] >> # Rational approximation for erfc(x) (Abramowitz & Stegun, Sec. 7.1.26) >> # Fifth order approximation. |error| <= 1.5e-7 for all x >> # >> def erfc( x ): >> p = 0.3275911 >> a1 = 0.254829592 >> a2 = -0.284496736 >> a3 = 1.421413741 >> a4 = -1.453152027 >> a5 = 1.061405429 >> >> t = 1.0 / (1.0 + p*float(x)) >> erfcx = ( (a1 + (a2 + (a3 + >> (a4 + a5*t)*t)*t)*t)*t ) * math.exp(-(x**2)) >> return erfcx > > Since no else has mentioned this, and it's not in the comments: the > above code is no good for x < 0 (erfc(-3)=84337, for instance). You'll > need a check for x < 0, and if so, use the identity > erfc(x) = 2 - erfc(-x). That'll slow you down a tad again :) That's correct (and noted in A&S). Since the argument I use is time relative to the start of the simulation, it's always positive. Since I'm not using it as a general purpose erfc calculator, I didn't bother with any checks (although, now that you've mentioned it, it would be rather stupid not to add a note to the comments). -- Mike -- From google at hanger.snowbird.net Sat Aug 23 00:33:18 2003 From: google at hanger.snowbird.net (Kris Caselden) Date: 22 Aug 2003 21:33:18 -0700 Subject: Threading Oddity? Message-ID: I noticed a strange yet easily fixed problem in Python's thread module. Consider the following code: #------------------------------- import thread data='this is data' data_mutex = thread.allocate_lock() def thread1(): while data_mutex.locked(): data_mutex.aquire() print 'thread1:',data if data_mutex.locked(): data_mutex.release() def thread2(): while data_mutex.locked(): data_mutex.aquire() print 'thread2:',data if data_mutex.locked(): data_mutex.release() thread.start_new_thread(thread1,()) thread.start_new_thread(thread2,()) #------------------------------- This code runs as expected. However, take away the while loop checks for mutex lock and Python is unable to properly acquire the lock, complaining of an unhandled exception. The Python Library Reference mentions that "this method acquires the lock unconditionally, if necessary waiting until it is released by another thread (only one thread at a time can acquire a lock -- that's their reason for existence), and returns None." You'd think one wouldn't have to check if the lock is locked, especially when acquire is supposed to wait for the lock to be freed. At first, I thought this problem had to do with aquire()'s waitflag, but the problem exists regardless of waitflag's value. Does anyone know why this problem exists, and if my code works around it? It would seem that locked() and acquire() would not necessarily be run uninterrupted, and so mutual exclusion could not be guaranteed. From jjl at pobox.com Mon Aug 18 14:48:20 2003 From: jjl at pobox.com (John J. Lee) Date: 18 Aug 2003 19:48:20 +0100 Subject: python and symbian? References: Message-ID: <87r83idcp7.fsf@pobox.com> Lawrence Oluyede writes: > Skip Montanaro wrote: > > > What's symbian? > > Symbian OS is the OS of new generation mobile phones made by Nokia, Sony > Ericsson and so on > Symbian itself is a consortium endorsed by Nokia, Siemems, Sony Ericsson > Motorola et. al. > > Some of the mobile phones with Symbian OS are Nokia 3650 and Sony Ericsson > P800 > > The OS ships with C++ SDK, Java and VB AFAIK Not Erlang? I guess they (Ericsson) only use that for the exchanges, then. John From cartermark46 at ukmail.com Wed Aug 6 07:09:19 2003 From: cartermark46 at ukmail.com (Mark Carter) Date: 6 Aug 2003 04:09:19 -0700 Subject: PyYaml bug in lists of inlined mappings? Message-ID: This works: vars: - name: AQ over: NF - name: A over: B but this doesn't: vars: - [ name: AQ, over: NF ] - [ name: A, over: B ] I have tried various combinations, including using curly brackets, different combinations of whitespace, and even using the ?: operator - all without success. So how do I do it? Also, I tried to view the archives over at Sourceforge: http://sourceforge.net/mailarchive/forum.php?forum=yaml-core but all I get is: ERROR Either your mailing list name was misspelled or your mailing list has not been archived yet. If this list has just been created, please retry in 2-4 hours From bokr at oz.net Mon Aug 11 18:49:14 2003 From: bokr at oz.net (Bengt Richter) Date: 11 Aug 2003 22:49:14 GMT Subject: CLI+GUI References: <2259b0e2.0308080948.5a95e383@posting.google.com> <2259b0e2.0308090530.7519f195@posting.google.com> <2259b0e2.0308110517.7c4fa8c8@posting.google.com> <2259b0e2.0308111326.1f6a2fc8@posting.google.com> Message-ID: On 11 Aug 2003 14:26:19 -0700, mis6 at pitt.edu (Michele Simionato) wrote: >Eric Brunel wrote in message news:... >> Cousin Stanley wrote: >> > Michele .... >> > >> > I experience hangs with SIMPLE Python/Tk scripts >> > regularly using Windows 98 and this has been >> > a source of much frustration, almost to the point >> > of giving up on Tk .... >> >> Same problem, different solution: it made me give up on Windows 98... ;-) >> >> FYI, and just to make this post a bit more useful, it seems to be a problem in >> Windows 95/98, since no problem ever occured with the same scripts/distros on >> Win2k or WinXP, not to mention Unices... > >These are very good news to me, since it means that the fault is not >mine >and that the approach I came out is not unreasonable (I hope). No bad, >for my first program using thread ;) For the record, I NEVER use >Windows for development(actually I use it only for watching DVDs), >nevertheless I >wanted to try the script to check about portability issues. > I'm not sure I would take the reported symptoms to indicate that the problem for *sure* is win 95/98. It could be that Win2k/XP just handles the problem in your code better, or because of some 99%-probable timing coincidence, never sees the problem. Bugs in threaded programs are notoriously hard to nail down. Put random sleeps and around and run with various other loads and things might change. Interested to see what you settled on as a minimal pattern though ;-) Regards, Bengt Richter From abuseonly at sgrail.org Thu Aug 21 05:23:21 2003 From: abuseonly at sgrail.org (derek / nul) Date: Thu, 21 Aug 2003 09:23:21 GMT Subject: Newbie problem with codecs References: Message-ID: On Thu, 21 Aug 2003 05:50:23 GMT, "Andrew Dalke" wrote: >derek / nul wrote: >> > File "apply_physics.py", line 12, in ? >> > codecs.lookup(BOM_UTF16_LE) >> > NameError: name 'BOM_UTF16_LE' is not defined > >Alex >> Change the statement to: >> codecs.lookup(codecs,BOM_UTF16_LE) > >Typo? Shouldn't that be a "." instead of a "."? > >In any case > >>>> codecs.lookup(codecs.BOM_UTF16_LE) >Traceback (most recent call last): > File "", line 1, in ? > File "C:\PYTHON23\Lib\encodings\__init__.py", line 84, in search_function > globals(), locals(), _import_tail) >ValueError: Empty module name >>>> > >In any case, the "BOM" means "byte order marker" and >the constant is the string prefix used to indicate which >UTF16 encoding is used. It isn't the encoding name. > >Perhaps the following is what the OP wanted? > >>>> codecs.lookup("utf-16-le") >(, , >, encodings.utf_16_le.StreamWriter at 0x01396810>) Andrew, this what I was expecting, but my system does not do it. codecs.lookup("utf-16-le") this is the code cut from my program, but there is NO output from my program. I am using www.python.org/doc/lib/module-codecs.html 4.9 codecs -- Codec registry and base classes page 1 Do I assume that the codecs module is not working? Derek From joch at blueyonder.co.uk Thu Aug 14 16:21:38 2003 From: joch at blueyonder.co.uk (John Ochiltree) Date: Thu, 14 Aug 2003 21:21:38 +0100 Subject: Running Python 2.3 on a Windows 2000 network In-Reply-To: <3F3A8199.B42F1BF5@engcorp.com> References: <3F3A8199.B42F1BF5@engcorp.com> Message-ID: Peter Hansen wrote: > John Ochiltree wrote: > >>Worked like a dream. I now have a shared python shell > > > Can you check whether "import pythoncom" and "import pywintypes" > and (if you've installed the Win32 extensions) "import win32api" > all work? > > If these work without your having to do anything to the registry, > I'm curious about the installation process you used, since we > had to do additional steps to get the same result. > > Thanks. > > -Peter I'll have a go tomorrow but initially I only require the shell and don't need COM or WIN32. John From irmen at -NOSPAM-REMOVETHIS-xs4all.nl Sun Aug 3 16:59:07 2003 From: irmen at -NOSPAM-REMOVETHIS-xs4all.nl (Irmen de Jong) Date: Sun, 03 Aug 2003 22:59:07 +0200 Subject: Python vs. Perl vs. PHP? In-Reply-To: <877k5u79gd.fsf@flibuste.net> References: <7b454334.0307281002.41dae81b@posting.google.com> <7b454334.0307301611.1b40ff11@posting.google.com> <7b454334.0307311023.28900d57@posting.google.com> <7b454334.0308031024.7b53fe46@posting.google.com> <877k5u79gd.fsf@flibuste.net> Message-ID: <3f2d7799$0$49117$e4fe514c@news.xs4all.nl> Wilk wrote: > faizan at jaredweb.com (Fazer) writes: > > >>>I personally find it much easier to learn about system administration >>>and get my own dedicated server for EUR 39/month. >> >>39? Where do you get such a good deal? > > > 15EUR/month on http://lost-oasis.fr i write about them because they make a lot > of contributions to open-source... [e:\]ping lost-oasis.fr Pinging lost-oasis.fr [80.67.180.4] with 32 bytes of data: Request timed out. Request timed out. Request timed out. Request timed out. Ping statistics for 80.67.180.4: Packets: Sent = 4, Received = 0, Lost = 4 (100% loss), Ahem .... --Irmen From aleax at aleax.it Sat Aug 9 12:58:46 2003 From: aleax at aleax.it (Alex Martelli) Date: Sat, 09 Aug 2003 16:58:46 GMT Subject: How to print floating point in scientific format? References: <420ced91.0308081115.7060e551@posting.google.com> Message-ID: sdhyok wrote: > I want to change the DEFAULT behavior of python > to print out all floating points in scientific format? > For instance, > >>x=0.01 >>print x > 1.000000E-2 #Like print "%E"%x > > How can I do it? You need to download Python's sources, modify them, and build a modified Python interpreter and libraries that impose the behavior you want rather than what the normal Python interpreter and libraries do. Specifically, look at function format_float, line 233 of file Objects/floatobject.c in the current 2.3 maintenance branch for example. Currently it formats the float with "%.*g" [variable precision passed in as an argument to format_float]; if you want to use a different C level format string, that string is the one you need to change. Of course, that's likely to break some of the tests in Python's unit-tests suite, so you'll probably want to modify those, too. And then, you get to maintain your "slightly divergent" Python yourself forevermore. I do not think there is much likelihood that a patch in this regard would be accepted in the Python core, even if you made it flexible enough to keep the current behavior by default and change it only upon specific request (e.g., use a variable string for the format, and let the Python coder modify the letter in it, only, keeping "%.*g" as the default but letting the 'g' be changed) -- such "big global" settings, which would let one idiosyncratic library module modify Python behavior enough to break other innocent modules, are looked at with disfavour, for reasons that should be obvious (each and every such 'big global' _damages_ Python's suitability for writing very large, multi-authors applications -- that suitability is currently very high, and _extremely_ convincing arguments would need to be brought to bear in order to convince Guido to deliberately lower it). Alex From newsgroups at jhrothjr.com Wed Aug 27 16:19:27 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Wed, 27 Aug 2003 16:19:27 -0400 Subject: Proposal: Magic Constants References: <7h3r837ce12.fsf@pc150.maths.bris.ac.uk> Message-ID: "Raymond Hettinger" wrote in message news:eM53b.6461$zL2.689 at nwrdny01.gnilink.net... > > > > But these are existing literal syntax. I was thinking > > > > more of random code where someone could currently > > > > juxtapose a literal and an identifier, say, without an > > > > intervening white space character. > > > > > > >>> 10and 1 > > > 1 > > > >>> 5or 7 > > > 5 > > > > > > Very much a wart of the tokenizer, though. > > > > Ah, right. I forgot about alphabetic operators. > > > > Why do you call it a wart, though? I would have > > thought that not requiring white space in that context > > was a feature. > > Because the human eye/mind parses 10and as single a token. Well, to be truthful about it, I'd just as soon require white space between all tokens except for the delimiter types. However, that's not going to happen because of the backwards compatability issues. John Roth > > > Raymond Hettinger > > From tim.one at comcast.net Fri Aug 1 22:30:05 2003 From: tim.one at comcast.net (Tim Peters) Date: Fri, 1 Aug 2003 22:30:05 -0400 Subject: time, calendar, datetime, etc In-Reply-To: Message-ID: [Andrew Dalke] > ... > The datetime module needs a 0 point (the creation of the universe > being rather long ago and the exact time not well known). Given the > questions of "when is year 0?" in different calendar systems, it's easy > for me to understand why Jan. 1st, 1AD is a good starting point. > (Easier than Jan 1st, 1970 - I prefered the Mac's epoch of 1900.) There was a specific reason for picking "year 1": that makes datetime's date ordinals identical to those used in the base proleptic Gregorian calendar in Dershowitz and Reingold's highly regarded "Calendrical Calculations": http://emr.cs.iit.edu/home/reingold/calendar-book/second-edition/ So people who want umpteen kinds of calendars Guido doesn't care about can look up algorithms in that book to do conversion to and from datetime's view of reality. For that reason alone, it was a better choice than most. In addition, since an explicit goal of datetime was fast extraction of fields, we simply store the year as given (e.g., 2003 is stored as 2003). This also works well for fast comparisons. Something missed in this discussion so far is that commercial applications deal in countless thousands of dates and datetimes -- formatting, sorting and indexing speed are important to them. Important enough to Zope Corp to pay the substantial bill for developing this code, anyway. i-hear-guido-doesn't-come-cheap-ly y'rs - tim From tismer at tismer.com Fri Aug 22 23:37:24 2003 From: tismer at tismer.com (Christian Tismer) Date: Sat, 23 Aug 2003 05:37:24 +0200 Subject: [Stackless] Stackless ported to 2.2.3 In-Reply-To: References: Message-ID: <3F46E174.5050700@tismer.com> Chao, Heng Sun wrote: > I have replaced the python22.dll. Unfortunately, the stackless > capability does not appear to be on. Are there any variables I have to set? The only thing you need to do is to import stackless, which is a built-in module. Python should crank up with a boot message that tells you about being Stackless 3.0 somthing. If not, your dll is not in place. Just try help("stackless"). If it works, you are fine. cheers - chris -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 mobile +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From getbet at spammer.net Fri Aug 29 15:48:05 2003 From: getbet at spammer.net (Rich) Date: Fri, 29 Aug 2003 12:48:05 -0700 Subject: learning to program References: Message-ID: Thanks everyone for all your help. On Wed, 27 Aug 2003 10:25:57 -0700, Rich wrote: >I downloaded the beginner package from the "Python" site, and would >like to know my next move. > >Should I wade through the site, or are there some exorcises I can do >to get started in the process of learning how to program. >TIA, >Rich From mike at mmrd.com Thu Aug 21 15:37:56 2003 From: mike at mmrd.com (MAK) Date: 21 Aug 2003 12:37:56 -0700 Subject: Q: urlopen() and "file:///c:/mypage.html" ?? Message-ID: I'm stumped. I'm trying to use Python 2.3's urllib2.urlopen() to open an HTML file on the local harddrive of my WinXP box. If I were to use, say, Netscape to open this file, I'd specify it as "file:///c:/mypage.html", and it would open it just fine. But urlopen() won't accept it as a valid URL. I get an OSError exception with the error message "No such file or directory: '\\C:\\mypage.html'". I've tried variations on the URL, such as "file://c:/mypage.html", too, without luck. That one gives me a 'socket.gaierror' exception with the message "'getaddrinfo failed'". Upon diving into the code, I found that, in the first case, the third '/' is left as part of the filename, and in the second case, it ends up thinking that 'C:' is the hostname of the machine. Can anyone point out the error of my ways? Thanks. From adalke at mindspring.com Fri Aug 1 19:03:43 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Fri, 1 Aug 2003 17:03:43 -0600 Subject: Detect PythonWin? References: <3f29fe44.104328@news.muenster.de> Message-ID: Martin Bless: > but how can my script know it its running from inside PythonWin? Oops! I misunderstood your question. In addition to the other answers, you could look at the stack trace and see if Pythonwin\pywin\framework\interact.py is used. Of course, that's not guaranteed to give the right answers; just figured I'ld give an alternative. Andrew dalke at dalkescientific.com From mjais at web.de Wed Aug 6 10:18:54 2003 From: mjais at web.de (Markus Jais) Date: Wed, 06 Aug 2003 16:18:54 +0200 Subject: Is there some Python + IDE/RAD for real speed development??? References: <96fda9ac.0308060611.56dfca7e@posting.google.com> Message-ID: hi maybe this is of interest to you. http://boa-constructor.sourceforge.net/ markus Edilmar wrote: > Hi, > > First of all, I'm new in Python... > > I have worked with manu langs and IDEs, like Delphi, VB, JBuilder, > Eclipse, Borland C++, Perl, etc... > > Then, today I think IDEs like Delphi have a excelent environment to > develop apps with little time. I saw many people talking about Python like > a easy lang to learn and to develop. But I have look at IDEs for Python, > or ways to develop GUIs with it, and I think it already is limited when > comparing with IDEs like Delphi. Is this afirmation true? > > I look at wxPython and PyGTK, but the samples showed that we have to write > MANY LINES of code to do simple things. Many people have wrote about the > advantage of Python to write little code, but, when talking about GUIs, > I think it's not really true, right? > > Using Delphi, little or none code is need for many things, but wxPython > and PyGTK is the reverse! > > Thanks for any replies, From mpeuser at web.de Fri Aug 29 13:41:50 2003 From: mpeuser at web.de (Michael Peuser) Date: Fri, 29 Aug 2003 19:41:50 +0200 Subject: method (a, b = '', *c, **d): gets a syntax error? References: <3F4F644D.2060003@uni-bonn.de> <3dqcndZe5u2g4NKiXTWJiA@comcast.com> Message-ID: "Terry Reedy" schrieb im Newsbeitrag news:3dqcndZe5u2g4NKiXTWJiA at comcast.com... [...} > > 1. When you make a function call and use **whatever, it must be the > last item in the argument list, just as in a function definition. A > following comma is not allowed for either defs or calls. This in fact is not true. Funnily you can add *one* comma at the end of any list-like construct. I have not digged into documentation to find out where this is described (or whether it is an unnoticed "bug"). I consider this a "good thing" however, because it eases editing when you put your items on single rows. In this case the comma is more a "terminator" than a "separator" Kindly Michael From ghowland at lupineNO.SPAMgames.com Sat Aug 23 21:55:51 2003 From: ghowland at lupineNO.SPAMgames.com (Geoff Howland) Date: Sun, 24 Aug 2003 01:55:51 GMT Subject: Python is darn fast (was: How fast is Python) References: <2259b0e2.0308230737.8a9bc1c@posting.google.com> <3F47AA73.7040104@draigBrady.com> <3f47bbc3$0$49114$e4fe514c@news.xs4all.nl> <87wud4x870.fsf@pobox.com> Message-ID: On 24 Aug 2003 00:31:15 +0100, jjl at pobox.com (John J. Lee) wrote: >Irmen de Jong writes: > >> P at draigBrady.com wrote: >> >> > try a 3.x series gcc with the appropriate -march=pentium3 >> > You'll be pleasently surprised. >> >> In my other reply I mentioned that I still get a Python+Psyco >> advantage of 30% over a gcc 3.2.2 compiled version. >> My gcc is doing a lot better than Michele's reported 50% difference, >> but Python+Psyco still wins :-) > >So, the interesting part is: why? I showed this to a more low-level friend and he said it's all down to exp(). He says it's an awfully slow C call, and if you were to take it out you would see a real change. Since youre measuring ALU type things anyway, it's better to keep them to real ALUs. Otherwise picking a different problem to solve, or not using exp() would make the test more valid. He also stated that just linking the library might take some non-trivial amount of time out of the C implementation. I'm fluent in C, but not into doing these kinds of things so I didn't investigate myself, just mouthpiecing it on in case it's useful for you in your question. Though since you're just running time on it, I would assume the same is true for launching the Python interpretter. Seems to me that maybe time from the command prompt isnt the best measuring tool because of those loading issues . Checking start/stop time once the program is initiated would rule those out. -Geoff Howland http://ludumdare.com/ From rowen at cesmail.net Tue Aug 26 17:12:33 2003 From: rowen at cesmail.net (Russell E. Owen) Date: Tue, 26 Aug 2003 14:12:33 -0700 Subject: urllib question Message-ID: I'm using urllib.urlopen() to retrieve data via ftp. I'm using Tkinter to display progress and so using a file even handler to read the data. My question is whether there's some easy way to do a nonblocking read? Here's a brief summary of the code: class ftpget: def __init__(self, url): self.bytesRead = 0 self.fromfp = urllib.urlopen(url) tk = Tkinter.Frame().tk tk.createfilehandler(self.fromfp, Tkinter.READABLE, readCallback) def readCallback(self, *args): nextData = self.fromfp.fp.fp._sock.recv(10000) self.bytesRead += len(nextData) if nextData: # handle the data else: # clean up: close the connection, etc. # display info in a Tkinter widget This does the job, but the line that reads the data: nextData = self.fromfp.fp.fp._sock.recv(10000) is dreadful because it relies on undocumented internals inside the object returned by urllib.urlopen. The simplest way to read data is self.fromfp.read(maxbytes) and that's how urllib.urlreceive reads data. But it's a blocking read and I'm afraid a slow net will cause problems for my GUI. Any suggestions? -- Russell From fgrellert at t-online.de Sat Aug 2 07:14:50 2003 From: fgrellert at t-online.de (Frank Grellert) Date: Sat, 02 Aug 2003 13:14:50 +0200 Subject: Python-2.3 Installation with Tk on SuSE8.2 fails References: Message-ID: "Martin v. L?wis" wrote: > Could it be that you don't have the Tcl header files installed? Yes, it could be, after installing the Tcl header files it worked fine! Since Python 2.2.2 was installed by Yast2, I assumed all files necessary to install PYthon 2.3 with Tcl/Tk where already present. Thanks for your hint! Frank Grellert From nicholas_wieland at yahoo.it Tue Aug 26 21:30:13 2003 From: nicholas_wieland at yahoo.it (Nicholas Wieland) Date: Wed, 27 Aug 2003 03:30:13 +0200 Subject: gnome.applet programming question. References: Message-ID: <56et11-k113.ln1@lorien.ilweran.home> -Charlie Kim: > any idea? Yes, subscribe to the pygtk mailing list :) Sorry, I've never used gnome.applet ... nicholas From bokr at oz.net Thu Aug 7 22:19:27 2003 From: bokr at oz.net (Bengt Richter) Date: 8 Aug 2003 02:19:27 GMT Subject: Bug? If not, how to work around it? References: <2259b0e2.0308070919.2bedce6@posting.google.com> <2259b0e2.0308071454.1f2869aa@posting.google.com> Message-ID: On 7 Aug 2003 15:54:33 -0700, mis6 at pitt.edu (Michele Simionato) wrote: >Alex Martelli wrote in message news:... >> "__getattr__ is skipped" is false (the >> __getattr__ a *metaclass* could define would indeed be used as >> equivalent to the class defining methods) -- the _class_'s __getattr__ >> if any is irrelevant because it's used on class *instances* (as >> the language reference also says a few pages later) and thus it's >> not the *CLASS* that's defining "methods with special names" here. >> > >Alex, did you look at the thread I mentioned? Here is the problem >with __getattr__ in metaclasses for special methods (quoting from >that thread). > >""" >defining __len__ on the class does not work: > >class M(type): > def __getattr__(self,name): > if name=='__len__': return lambda self:0 > >class F: __metaclass__=M > >>>> f=F() >>>> F.__len__(f) # okay 0 >>>> len(f) # TypeError: len() of unsized object >f.__len__() # AttributeError: 'F' object has no attribute '__len__' > >As you see, the problem is that len(x) is not calling x.__len__(), >nor x.__class__.__len__(x); I really would like to know how ``len`` >(or ``str``, ``repr``, etc.) work. >""" Not very tested, but maybe you have to write it something like this: >>> class M(type): ... def __new__(cls, name, bases, cdict): ... cdict['__len__'] = lambda self:0 ... return type.__new__(cls, name, bases, cdict) ... >>> class F: __metaclass__ = M ... >>> f=F() >>> F.__len__ > >>> F.__len__(f) 0 >>> len(f) 0 >>> hasattr(M,'__len__') False >>> hasattr(F,'__len__') True Or am I missing the point? ;-/ > >If you remember, Bjorn Pettersen reported this (or something similar) >months ago. I am saying that this behaviour is not documented, at >least AFAIK. > Regards, Bengt Richter From siegfried.gonzi at kfunigraz.ac.at Mon Aug 4 03:49:43 2003 From: siegfried.gonzi at kfunigraz.ac.at (Siegfried Gonzi) Date: 4 Aug 2003 07:49:43 GMT Subject: Plotting Package for Python 2.3 References: <221d8dbe.0308032301.2c0e801f@posting.google.com> Message-ID: <3F559DF5.6060209@kfunigraz.ac.at> srijit at yahoo.com wrote: > Hi, > I am looking for a good plotting package (preferably with 3D plotting > capabilities) based on Python 2.3 (Windows 98). Unfortunately Dislin > does not exist for Python 2.3. > I look forward to suggestions from members. Hi: Do you know this from experience that DISLIN will not work on Python 2.3? I mean it would be strange, though. S. Gonzi From david.bear at asu.edu Wed Aug 27 00:13:35 2003 From: david.bear at asu.edu (David Bear) Date: 26 Aug 2003 21:13:35 -0700 Subject: getopt issues Message-ID: I'm stumped. Trying to follow the docs and .. failure. here's the args >>> args '-Middwb at mainex1.asu.edu -AKHAAM at prlinux+898 -CA --D2003-08-20-09:28:13.417 -Ff -Hprlinux --JTCPIP_NPF_TEST_DARS_PORTRAIT -NTCPIP_NPF_TEST_DARS_PORTRAIT --Pholdqueue -Qholdqueue -aacct -b2895 -d/var/spool/lpd/holdqueue -edfA898prlinux -fTCPIP_NPF_TEST_DARS_PORTRAIT -hprlinux -j898 -kcfA898prlinux -l66 -nKHAAM -sstatus -t2003-08-20-09:28:13.000 -w80 -x0 -y0 acct \n' I know, they're long. sorry. they just are. and maybe thats the bug. here's what happens >>> a, b = getopt.getopt(args, 'APQn') >>> a [] >>> b '-Middwb at mainex1.asu.edu -AKHAAM at prlinux+898 -CA --D2003-08-20-09:28:13.417 -Ff -Hprlinux --JTCPIP_NPF_TEST_DARS_PORTRAIT -NTCPIP_NPF_TEST_DARS_PORTRAIT --Pholdqueue -Qholdqueue -aacct -b2895 -d/var/spool/lpd/holdqueue -edfA898prlinux -fTCPIP_NPF_TEST_DARS_PORTRAIT -hprlinux -j898 -kcfA898prlinux -l66 -nKHAAM -sstatus -t2003-08-20-09:28:13.000 -w80 -x0 -y0 acct \n' not at all what the docs lead me to believe. Is getopt buggy? I'm on python 2.2.2 on linux but will also be using python 2.1.3 on FreeBsd. Advice? -- David Bear phone: 480-965-8257 fax: 480-965-9189 College of Public Programs/ASU Wilson Hall 232 Tempe, AZ 85287-0803 "Beware the IP portfolio, everyone will be suspect of trespassing" From justinjohnson at fastmail.fm Mon Aug 4 10:29:38 2003 From: justinjohnson at fastmail.fm (Justin Johnson) Date: Mon, 04 Aug 2003 08:29:38 -0600 Subject: Equivalent of "handle" from sysinternals.com Message-ID: <20030804142938.852A73762A@www.fastmail.fm> I wrote a utility function in python to run the handle.exe command from www.sysinternals.com to get the list of processes holding on to a particular file so I can kill them off before removing that file. This works well, but handle.exe fails if more than one instance of it are run at the same time. So I was thinking of writing this functionality in python and not being dependent on handle.exe. Does anyone know how I could do such a thing? Thanks. -Justin From eric at enthought.com Thu Aug 14 20:00:21 2003 From: eric at enthought.com (eric jones) Date: Thu, 14 Aug 2003 18:00:21 -0600 Subject: ANN: Job posting -- developer position available Message-ID: <010701c362c0$3b54ec50$a47ba8c0@ericlaptop> Hey group, We have a developer position open here at Enthought, and I thought I'd see if anyone is interested. The posting is below. There is also a tech writer and HCI opening listed on the website: http://www.enthought.com/careers.html thanks! eric Position: Python Developer Type: Full-Time Enthought, Inc. is a technology startup in the Austin, TX area that is looking for a motivated Python Developer to join our development team. Responsibilities include developing and deploying scientific applications within the Fortune 500. Our size and prospects provide significant opportunity for growth and advancement for Enthought employees. Candidates should have the following qualifications: - BS or MS in Computer Science or Engineering or other scientific field - 3+ years experience in the software industry - Experience developing solutions in the following languages: - Python - C/C++ - User interface design experience - Developing and deploying custom solutions for clients - Excellent verbal and written communication skills Ideal candidates will also demonstrate the following skills: - Use of the wxPython user interface library - Experience with Geophysics applications - Experience in the fields of statistics, linear algebra and calculus Please send resumes to jobs at enthought.com. From missive at frontiernet.net Sun Aug 24 18:33:10 2003 From: missive at frontiernet.net (Lee Harr) Date: Sun, 24 Aug 2003 22:33:10 GMT Subject: Alphabetizing? References: Message-ID: In article wrote: > Ok, im trying to creat a small simple program that alphabetizes user > inputed words. I thought why not just create a def that splits all the > words down into char's then take the first char and crosscheck it with all > lowercase letters. Then find its position and return the results to the > user in order or 1-26! But this takes a long time and the code gets > confusing. Any suggestion? Thanx in advance! > > How about just sort()ing them? You can define a custom sort function if you want an alphabetical rather than lexical sort. ie: words = [] while 1: word = raw_input('enter word ("done" to finish) :') if word == 'done': break words.append(word) def sort_alpha(a, b): if a.lower() < b.lower(): return -1 elif a.lower() > b.lower(): return 1 else: return 0 words.sort(sort_alpha) print words From joerg.maier at rz.uni-mannheim.de Sun Aug 3 07:49:39 2003 From: joerg.maier at rz.uni-mannheim.de (=?ISO-8859-15?Q?J=F6rg?= Maier) Date: Sun, 03 Aug 2003 13:49:39 +0200 Subject: HOME Directory in posix and nt Message-ID: Hey, ist there a possibility to get the users homedirectory as environment variables %HOMEPATH% or $HOME. there must be a way to see system variables other than stdout = os.popen('{ echo $HOME } 2>&1 ', 'r') on posix and stdout = os.popen('echo %HOMEPATH% 2>&1', 'r') with home = stdout.readline() ??? -- Hi I am a signature virus. Please copy me to your .signature file to help me spread. From imbaczek at poczta.onet.pl Wed Aug 6 06:27:28 2003 From: imbaczek at poczta.onet.pl (=?iso-8859-2?Q?Marek_=22Baczek=22_Baczy=F1ski?=) Date: Wed, 6 Aug 2003 12:27:28 +0200 Subject: Fatal Python error: unknown scope for... References: <1hpgt2ltmkd5a$.dlg@baczek.net.invalid> Message-ID: On Wed, 06 Aug 2003 12:53:15 +1000, Mark Hammond wrote: >> def g(a=None, b, c=lambda: None): g >> """Fatal Python error: unknown scope for g in g(1) in marek.py""" > > Yep, I still get this with current CVS Python. You should open a bug. Done. Pozdrawiam, Baczek From mnations at airmail.net Wed Aug 20 13:24:23 2003 From: mnations at airmail.net (Marc) Date: 20 Aug 2003 10:24:23 -0700 Subject: Sending to a process opened from popen() Message-ID: <4378fa6f.0308200924.76294713@posting.google.com> Hi all, In searching for an answer to this problem I found several solutions dealing with Unix but none dealing with Windows. Basically I want to send a ping for an indefinite period of time, stop it at some point, and then read the results. I open up a ping process using popen(). I found ways to send a break signal using signal module, but for that I need the PID. All the ways described in the newsgroups for finding PID were for UNIX. So how do I find the PID of a spawned process in Windows to send a break signal? Thanks ahead of time, Marc From pinard at iro.umontreal.ca Mon Aug 4 06:17:37 2003 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois_Pinard?=) Date: 04 Aug 2003 06:17:37 -0400 Subject: True In-Reply-To: References: Message-ID: [Daniel Klein] > So my question is what is the proper method for setting booleans in 2.3? Hi, Daniel. In 2.3, you do not need to set booleans, `True' and `False' are just there. However, if you have a need to write portably against many versions, you might try something like: try: True except NameError: False, True = range(2) in modules where you need to use `True' or `False'. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From jepler at unpythonic.net Mon Aug 18 14:13:08 2003 From: jepler at unpythonic.net (Jeff Epler) Date: Mon, 18 Aug 2003 13:13:08 -0500 Subject: event binding and component.config In-Reply-To: <3F3E7A85.8040202@sbcglobal.net> References: <3F3E7A85.8040202@sbcglobal.net> Message-ID: <20030818181308.GN16941@unpythonic.net> I believe that this "problem" lies in the default bindings that Tk provides for widgets. You should make yourself familiar with Tk's concept of the "bindtags" of a widget, and the sequence of bindings that are invoked when a widget gets an event. I apologize for not translating these examples into Python, but getting at the information I want to show is much easier inside the tcl shell than through Python/Tkinter. Apologies also for the length.. A widget W inside a toplevel T of class K gets a default bindtags of W K T all .. and Tk provides many bindings on each class K and a few bindings on the class "all". One of the bindings for Button is for , and it changes the widget's relief to a stored relief value seen in the event. Here's some output from wish, the interactive tcl/tk shell: % # Create a button % button .b .b % # Show the bindtags of the new button % bindtags .b .b Button . all % # Show the bindings that exist on Button % bind Button % # Show the binding and the command it invokes % bind Button tkButtonUp %W % info body tkButtonUp global tkPriv if {[string equal $w $tkPriv(buttonWindow)]} { set tkPriv(buttonWindow) "" $w configure -relief $tkPriv(relief) if {[string equal $w $tkPriv(window)] && [string compare [$w cget -state] "disabled"]} { uplevel #0 [list $w invoke] } } When you create the binding on the component for , it gets added to the tag whose name is the same as the widget path. Now, when the event arrives, the tags are searched in order, and for each tag the most specific binding (if any) is executed. If the binding does not "break", then the next tag is searched. So the first binding sets the relief of the button to sunken, and then the second binding sets it to the saved value, $tkPriv(relief). The reason that using command= leaves you with the desired relief can also be understood: the button is actually invoked after the relief is reset. You have a number of options. First, unless you *want* to get rid of the normal requirements for what constitutes a button press, you'll have to rewrite the normal button logic for what constitutes a press. If you don't, eventually you'll see a situation where the button sees a event without an earlier event, and the behavior will be wrong. (this can happen if a window from a different application just above the button destroys itself while button 1 was down, for instance) If you can't do this from within command, but want to take advantage of the normal logic of a button press, you could set the relief to the "after press" value in the widget's binding. This will then get stored in tkPriv(relief) by Button's and restored by Button's . But the altered binding will be restored wither or not the press was completed (by releasing inside the button) or canceled (by releasing outside the button), so again it's probably not what you want. You can "snoop" inside Tk's internals. In the above, the relief is stored in tkPriv(relief), but this is an implementation detail. In newer versions of Tk (8.4.x), this is stored in a different location, probably ::tk::relief or something like that. But this is clearly documented to change between releases. (Another problem with doing things inside the You apparently have such a loose definition for garbage collection, that even C programs have "a form of garbage collection" on modern OSes: All garbage is reclaimed by the OS when the program exits. It's just a very lazy collector. I don't consider something a garbage collector unless it collects all garbage (ref.counting doesn't) and is a bit more agile than the one provided by OS. > Saying "Ref. counting sucks, let's use GC instead" is a statement near > as dammit to meaningless. You, I and everyone knows what I was talking about, so it could hardly be regarded as "meaningless". > Given the desires above, I really cannot think of a clearly better GC > strategy for Python that the one currently employed. AFAICS, the > current scheme's biggest drawback is its memory overhead, followed by > the cache-trashing tendencies of decrefs. It's not "the one currently employed". It's the *two* currently employed and that causes grief as I described in my previous post. And AFAIK, Ruby does use GC (mark-and-sweep, if you wish) and seems to be working. However, this is rather iffy knowledge. I'm actually longing for real GC because I've seen it work well in Java and C#, and I know that it's being used successfully in many other languages. > What would you use instead? A trick question? From krummbeersupp at web.de Thu Aug 7 11:17:55 2003 From: krummbeersupp at web.de (Oliver Emrich) Date: Thu, 7 Aug 2003 17:17:55 +0200 Subject: Python-list digest, Vol 1 #16830 - 13 msgs Message-ID: <200308071517.h77FHtQ08357@mailgate5.cinetic.de> An HTML attachment was scrubbed... URL: From adalke at mindspring.com Thu Aug 21 14:54:35 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Thu, 21 Aug 2003 18:54:35 GMT Subject: What's better about Ruby than Python? References: <3F41505F.69D18CC8@alcyone.com> <66d7kvonvb2n0nqbqahhd5roak7ur81sob@4ax.com> <3f43ef5d_4@127.0.0.1> <3F440A35.9030602@nyc.rr.com> <4o_0b.1665$Ej6.1182@newsread4.news.pas.earthlink.net> <8D01b.1721$Ej6.702@newsread4.news.pas.earthlink.net> Message-ID: Me: > Oops! Yeah, forgot that too. I do consider it a (necessary) > wart that different classes have different behaviours. Err, "classes derived from object have different fundamental beviours than old-style classes". Of course different classes have different behaviours. Andrew From andrew-pythonlist at puzzling.org Tue Aug 12 05:21:36 2003 From: andrew-pythonlist at puzzling.org (Andrew Bennetts) Date: Tue, 12 Aug 2003 19:21:36 +1000 Subject: Python vs. C# In-Reply-To: References: Message-ID: <20030812092136.GB4576@frobozz> On Tue, Aug 12, 2003 at 02:03:58AM -0700, Brandon J. Van Every wrote: > Joe Cheng wrote: > > > > Python has dynamic strong typing. So, if you can keep the types of > > your objects straight without the help of the compiler, you get the > > benefits of a concise syntax while enjoying type safety at runtime. > > And how, in a large scale industrial systems context, are you supposed to > ensure that Joe Programmer doesn't in fact screw it up? By writing tests. Just because C++, C# or Java code compiles cleanly doesn't mean it's correct. Just because Python code parses correctly and gives clean PyChecker output doesn't mean it's correct, either. In both cases, you need tests, preferably comprehensive, automated tests, to verify that your code actually works correctly. Python, by virtue of being easier to work with than statically-typed languages, also makes writing tests easier. Running the tests frequently is also easier when there's no lengthy compile step involved, although I've no idea how good or bad C# is in this regard, but C++ is certainly painful. Besides, if you don't trust the "Joe Programmer"s of your team to write code competently, I suspect your project is doomed already. Requiring a liberal sprinkling of type declarations throughout the code is hardly likely to help that. Regards, -Andrew. From skip at pobox.com Mon Aug 11 15:20:43 2003 From: skip at pobox.com (Skip Montanaro) Date: Mon, 11 Aug 2003 14:20:43 -0500 Subject: ascii problem In-Reply-To: <002a01c3603b$73442a90$417290c8@paraopeba> References: <002a01c3603b$73442a90$417290c8@paraopeba> Message-ID: <16183.60555.59705.762835@montanaro.dyndns.org> >>> a = "andr?" UnicodeError: ASCII encoding error: ordinal not in range(128) Use Unicode: >>> a = unicode("andr\xe9", "iso-8859-1") >>> print a.encode("iso-8859-1") andr? With a Euro keyboard you won't have to embed hex codes in your strings. Skip From aleax at aleax.it Mon Aug 4 11:18:50 2003 From: aleax at aleax.it (Alex Martelli) Date: Mon, 04 Aug 2003 15:18:50 GMT Subject: Linux & =?ISO-8859-15?Q?ex=E9cutable?= References: Message-ID: habermacher wrote: > Bonjour, > > Est-ce que quelqu'un sait quel est le logiciel ? utiliser sous linux > pour cr?er un ex?cutable correspondant ? du code source en python ? http://www.mcmillan-inc.com/install1.html Pour parler de Python en Francais, cependant, voyez les links a l'URL: http://www.python.org/doc/NonEnglish.html#french Sur comp.lang.python, en revanche, la langue habituellement utilisee est l'Anglais. Alex From jaybromley at hotmail.com Fri Aug 29 23:13:06 2003 From: jaybromley at hotmail.com (Jay Bromley) Date: 29 Aug 2003 20:13:06 -0700 Subject: Update to Python 2.3 on Red Hat Linux 9 References: <8242f4a7.0308282240.4c87f997@posting.google.com> Message-ID: <8242f4a7.0308291913.63bcc19b@posting.google.com> Hello again, > Did you rebuild Python with enable-unicode=ucs4? If not, that is likely your > problem - it was mine ;<{) Yes, the second time I compiled Python (I actually paid attention to the README) I used this option, still to no avail. I've done some playing and if I can get the sys.path the same for both versions most of the libraries seem to be ok, so that's the next shot, doing some more reading to see how I can config 2.3 to have the same sys.path as 2.2.2. Incidentally, I mentioned pygtk having to be recompiled for 2.3. This seems to be the case because (according to an import error message) pygtk built for 2.2.2 uses a different api than 2.3. Anyway, thanks for the suggestion, I'll see if I can use the source. Thanks, Jay From pobrien at orbtech.com Fri Aug 29 14:34:13 2003 From: pobrien at orbtech.com (Patrick K. O'Brien) Date: 29 Aug 2003 13:34:13 -0500 Subject: Object Database (ODBMS) for Python References: <1DAECE9E8F34E04AA0E5699AF7D9FF090708D440@stpmsg00.corp.fairisaac.com> <3f4f7af6_3@corp.newsgroups.com> Message-ID: pobrien at orbtech.com (Patrick K. O'Brien) writes: > "Paul D. Fernhout" writes: > > > By the way, I like your overview of various related ODBMS projects here: > > http://www.orbtech.com/wiki/PythonPersistence > > (maybe http://munkware.sourceforge.net/ might go there now?) > > Boy that's old material. I forgot about that page. Look at that! I also forgot to mention that it is a wiki page, and you have my blessing to add whatever material you like (not that you needed my blessing, if you know what I mean). -- Patrick K. O'Brien Orbtech http://www.orbtech.com/web/pobrien ----------------------------------------------- "Your source for Python programming expertise." ----------------------------------------------- From imbosol at aerojockey.com Fri Aug 1 17:06:34 2003 From: imbosol at aerojockey.com (Carl Banks) Date: Fri, 01 Aug 2003 21:06:34 GMT Subject: Singleton-like pattern References: <2259b0e2.0308010815.5dcb0b58@posting.google.com> Message-ID: Michele Simionato wrote: > About the issue of finding a suitable key, in the same situation I have > used the tuple (args,kw) as key. Surely not? Perhaps you meant tuple(args,tuple(kw.items())) ? It gets rid of the unhashable kw dict. > But me too I would like to ask if this is a > good idea. What's the custom solution for getting a good key from > a dictionary ? Howabout cPickle.dumps((args,kwargs),1)? -- CARL BANKS From guy.flowers at Machineworks.com Wed Aug 13 07:11:59 2003 From: guy.flowers at Machineworks.com (Guy) Date: 13 Aug 2003 04:11:59 -0700 Subject: popen2 References: Message-ID: Donn Cave Hi You replyed to my email on google, just want to say thanks, the code works great, on my test script. Going to try it in the main script now. Many Thanks Again Guy From aleax at aleax.it Thu Aug 7 09:19:40 2003 From: aleax at aleax.it (Alex Martelli) Date: Thu, 07 Aug 2003 13:19:40 GMT Subject: crossplatform py2exe - would it be useful? References: Message-ID: Thomas Heller wrote: ... >>> myscript -c "import sys; sys.path.insert(0, sys.executable); import foo" ... >> Sounds like a good idea to me, if a sensible name is chosen for the >> "main module" (I propose 'main':-). > > My choice would have been __main__ :-) Is it really the correct way to > 'import __main__' instead of 'running' it? Well, most main scripts ARE coded with the "if __name__=='__main__':" convention, after all, so an "import __main__" can be seen as a way to just piggyback on that existing convention rather than inventing a new one in addition. So, I concede it's better than "import main". Alex From NAICH-SYDNEYCH-EXCHANGE at cowleyhearne.com.au Sun Aug 24 21:21:53 2003 From: NAICH-SYDNEYCH-EXCHANGE at cowleyhearne.com.au (GroupShield for Exchange (CH-EXCHANGE)) Date: Mon, 25 Aug 2003 11:21:53 +1000 Subject: ALERT - GroupShield ticket number OA1571_1061774507_CH-EXCHANGE_ 3 was generated Message-ID: <540F61BD2C9BD64DA18FCB9B7367424D897AE2@CH-EXCHANGE.cowleyhearne.com.au> Action Taken: The attachment was quarantined from the message and replaced with a text file informing the recipient of the action taken. To: kwilson at cowleyhearne.com.au From: python-list at python.org Sent: 1921411456,29584039 Subject: Your details Attachment Details:- Attachment Name: wicked_scr.scr File: wicked_scr.scr Infected? No Repaired? No Blocked? Yes Deleted? No Virus Name: -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/ms-tnef Size: 1950 bytes Desc: not available URL: From mpeuser at web.de Mon Aug 18 02:23:39 2003 From: mpeuser at web.de (Michael Peuser) Date: Mon, 18 Aug 2003 08:23:39 +0200 Subject: closing a widget References: <3f443b52.0308171454.c00a287@posting.google.com> Message-ID: "Marcus Schneider" schrieb im Newsbeitrag news:3f443b52.0308171454.c00a287 at posting.google.com... > Normally I close my windows/widgets with destroy and it works fine. > Now I have a window (let's call it 1) from where I open an additional > window (let's call it 2). Do you mean you make (1) the basis of a Toplevel (2) ? > I close it. (2) ? By a button created on that Toplevel ? > Each window has its own main loop. There can only be one mainloop. No idea what happens, when you call mainloop during in an event-routine. Never do it! > Now I want to open another window outside the mainloop of window 1. What do you mean by this? > So > I quit that mainloop. How can you do that? What at all do you mean by "mainloop"? Tkinter.mainloop I presume? > go to GOTO? > a new window, destroy that, enter the > mainloop of window 1 again and finally exit with destroy. > > All this works in princial.... This is a surprises to me... My be I really do not understand what you are doing..... Kindly Michael P. [....] From no at spam.com Sun Aug 3 00:08:18 2003 From: no at spam.com (J. W. McCall) Date: Sun, 03 Aug 2003 04:08:18 GMT Subject: Can't get dumb webcounter working Message-ID: Sorry if this is OT, but here's my question: I wrote a simple python script to increment a counter in a text file, and I wanted this script to be accessed whenever an HTML file is accessed. The HTML files and python script are on a shell account on UNIX a machine that has support for CGI, Python, etc. I unfortunately don't know much about CGI, since I assume this is what I need to get this to work. All I want to do is to get script to be called when the web site is accessed and hopefully insert some output (a number) into the HTML. Any advice, specific instructions, pointers to helpful web resources, or recommendations to better newsgroups, if this is too OT here, would be greatly appreciated. Thanks, J. W. McCall From ialbert at mailblocks.com Thu Aug 28 23:17:49 2003 From: ialbert at mailblocks.com (Istvan Albert) Date: Thu, 28 Aug 2003 23:17:49 -0400 Subject: appoximate string matching library - any interest? In-Reply-To: References: Message-ID: Tim Churches wrote: > There are a number of approximate string matching functions, implemented > in pure Python, included in the Febrl project (Febrl=Freely-extensible > biomedical record linkage). See under "Prototype software" at > http://datamining.anu.edu.au/projects/linkage.html or for details of the > approximate string comparators implemented, see > http://cs.anu.edu.au/~Peter.Christen/febrl-0.2/febrldoc-0.2.1/node37.htm > l Note that approximate string comparator functions are different from > (although related to) phonetic encoders, such as Soundex (see > http://cs.anu.edu.au/~Peter.Christen/febrl-0.2/febrldoc-0.2.1/node38.htm > l for some examples of the latter). The Febrl string aproximation features are pretty sweet! nice job, Istvan. From bokr at oz.net Mon Aug 11 21:44:56 2003 From: bokr at oz.net (Bengt Richter) Date: 12 Aug 2003 01:44:56 GMT Subject: stretching list comprehensions References: Message-ID: On Tue, 12 Aug 2003 09:26:40 +1000, Simon Burton wrote: > >I was quite delighted when i found this: > >>>> nums = [ x+y for x in range(10) for y in range(10) ] > >Great! No more list of list joining shenanigans... > >Shortly thereafter, i tried this: > >>>> del y >>>> nums = [ x+y for x in range(y) for y in range(10) ] >Traceback (most recent call last): > File "", line 1, in ? >NameError: name 'y' is not defined >>>> > >Well.. Is there an inherent reason why this could/should not be made to work? > Left to right seems to work, but I'm not sure what ordering you require. To see the x's and y's separately, you can temporarily do tuples instead of adding: >>> [(x,y) for y in range(10) for x in range(y) ] [(0, 1), (0, 2), (1, 2), (0, 3), (1, 3), (2, 3), (0, 4), (1, 4), (2, 4), (3, 4), (0, 5), (1, 5), (2, 5), (3, 5), (4, 5), (0, 6), (1, 6), (2, 6), (3, 6), (4, 6), (5, 6), (0, 7), (1, 7), (2, 7), (3, 7), (4, 7), (5, 7), (6, 7), (0, 8), (1, 8), (2, 8), (3, 8), (4, 8), (5, 8), (6, 8), (7, 8), (0, 9), (1, 9), (2, 9), (3, 9), (4, 9), (5, 9), (6, 9), (7, 9), (8, 9)] Regards, Bengt Richter From robin at jessikat.fsnet.co.uk Sun Aug 10 04:31:10 2003 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Sun, 10 Aug 2003 09:31:10 +0100 Subject: PMW 0.8.5 vs Python 2.3 References: <3F35FF75.C01C5591@alcyone.com> Message-ID: In article <3F35FF75.C01C5591 at alcyone.com>, Erik Max Francis writes >Robin Becker wrote: > >> I'm getting the following error when I attempt to run an app with >> Python 2.3. I suppose this was silently ignored under 2.2. With >> debugging I see that s==0 in > >Something else is going on, you get the same error in 2.2: > so did someone change the return type of Tkinter.menu.entrycget ? >Python 2.2.3 (#1, May 31 2003, 21:31:33) >[GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2 >Type "help", "copyright", "credits" or "license" for more information. >>>> int(0, 16) >Traceback (most recent call last): > File "", line 1, in ? >TypeError: int() can't convert non-string with explicit base > -- Robin Becker From fredrik at pythonware.com Mon Aug 4 09:08:21 2003 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 4 Aug 2003 15:08:21 +0200 Subject: Problems decoding and writing mail attachment References: <2afb3281.0308032307.2e0226df@posting.google.com> Message-ID: "edwinek" wrote: > I've written a script which I use to save attached binary files from > e-mails to disk. The core is simply: > > decodedfile = bas64.decodestring(attachment) > fle = open('image.jpg','wb') > fle.write(decodedfile) > fle.close > > However, the files written to disk are regularly incomplete, i.e. > jpg's having a grey bar at the bottom, gif's don't even display, pdf's > give errors. > What am I doing wrong here? chances are that you're not closing the file before using it: try changing the last line to fle.close() From P at draigBrady.com Thu Aug 21 10:49:22 2003 From: P at draigBrady.com (P at draigBrady.com) Date: Thu, 21 Aug 2003 15:49:22 +0100 Subject: [OT] Why is it called string? In-Reply-To: References: <3f44ce77$0$556$b45e6eb0@senator-bedfellow.mit.edu> Message-ID: <3F44DBF2.1010403@draigBrady.com> Travis Whitton wrote: >>"In computing, the word 'bit' is an abbreviation of what two other words?" > > Wow, I had no idea it was an abbreviation either. Luckily, dict had the answer > waiting for me: > > From Jargon File (4.3.0, 30 APR 2001) [jargon]: > > bit n. [from the mainstream meaning and `Binary digIT'] > > It's nice to see the occasional thread on computing history rather than the > endless stream of coding issues. I'm always surprised by the number of people in computing that don't know this. bit is a contraction of "Binary digIT" byte is a pun on the word bit (8 bits) nibble is a pun on the word byte (4 bits) P?draig. From ialbert at mailblocks.com Wed Aug 27 21:45:52 2003 From: ialbert at mailblocks.com (Istvan Albert) Date: Wed, 27 Aug 2003 21:45:52 -0400 Subject: Rebol Size In-Reply-To: <3f4a9b9d_2@nova.entelchile.net> References: <3f4a9b9d_2@nova.entelchile.net> Message-ID: Rodrigo Benenson wrote: > Everything until now can be rivalized by Python. My point is: > > All of the above comes the 500 Kb Rebol/View distribution !! > But how to explain such a difference ? I think you view the problem backwards that's why you feel confused. It is not like Python only does what Rebol can only at 20 times more cost in storage or memory. Rebol is significantly simpler than python, there's no surprise that it is so much smaller. If all the funcionality you need is available in Rebol then use it. Istvan. From sross at connectmail.carleton.ca Wed Aug 27 20:38:20 2003 From: sross at connectmail.carleton.ca (Sean Ross) Date: Wed, 27 Aug 2003 20:38:20 -0400 Subject: Class level variables in Python References: Message-ID: "Brian Munroe" wrote in message news:c16d085c.0308271543.3dfc581e at posting.google.com... > I was wondering if someone could explain if there is any difference > between initalizing your object attributes up in the __init__ > constructor or setting them up as (I am guessing at the name here) > object level variables (like z) Hi. Yes there is a difference. One is an instance attribute, the other is a class attribute: >>> class C: ... attr = 1 ... def __init__(self): ... self.attr = 2 ... >>> c = C() >>> print c.attr 2 >>> print c.__class__.attr 1 >>> HTH Sean From ialbert at mailblocks.com Tue Aug 12 13:07:48 2003 From: ialbert at mailblocks.com (Istvan Albert) Date: Tue, 12 Aug 2003 13:07:48 -0400 Subject: Rekall docs ready for download In-Reply-To: <7aCcnS_RjPj6xaWiXTWJhQ@comcast.com> References: <3f380ac5$0$239$fa0fcedb@lovejoy.zen.co.uk> <7aCcnS_RjPj6xaWiXTWJhQ@comcast.com> Message-ID: <3F391EE4.1020906@mailblocks.com> Terry Reedy wrote: > You or your webpage designer, like too many others, have opted to > 'control my user experience' by adding html code to disable Internet > Explorer's View/TextSize adjustment. Since you won't let me enlarge > your teeny type (half the size as in my mail/news reader or at a sane > site like SourceForge) to where I can read it without eyestrain, I > will not try. Goodby. For what is worth this is an IE flaw really. IE won't override any absolute text-size requests in the HTML. It will only magnify relative sizing. But not doing so makes the whole text-sizing option moot. Formatting takes place in IE not on the server, so why can't make it bigger? Mozilla for example has no problems magnifying the text. Not to bash Microsoft, but in some sense the problem is that your browser is flawed. You can do a lot better and for free. Istvan. From theller at python.net Mon Aug 4 12:08:13 2003 From: theller at python.net (Thomas Heller) Date: Mon, 04 Aug 2003 18:08:13 +0200 Subject: packaging windows services? References: Message-ID: max writes: > Hi all, > trying to package a windows service into a standalone (no full python > install needed) > py2exe works well, except that it only appears to support 'manual > start' service option and only under default accont. What py2exe > appears to do is to ignore the > win32serviceutil.HandleCommandLine(MyService) in the main and just use > the class (hence the classname requirement on the command line) with > its own options. The advantage of this approach is that it does not > require PythonService.exe. > McMillan does not appear to support services directly. But I do wonder > if I can combine the exe produced by McMillan with PythonService.exe > to get something working. > The other approach is to dig into the py2exe source and swap the > manual start for automatic. > suggestions? I have a patch sitting on the SF py2exe page which does this and more, I hope I can work on this during this week. OTOH, you can change the startup options of the service (and the user account it uses) with the control panel services applet. Thomas From gafStopSpamData at ziplink.stopallspam.net Mon Aug 18 12:54:19 2003 From: gafStopSpamData at ziplink.stopallspam.net (Gary Feldman) Date: Mon, 18 Aug 2003 16:54:19 GMT Subject: Idle won't start when Python is installed in Program Files directory Message-ID: Since I prefer to keep all my installed programs in one place, I went ahead and installed Python in Program Files/Python. The command line shell seems to work just fine, and I'm able to import things like urllib and its dependencies. However, I can't get Idle to startup. When I try running it manually (i.e. python ...idle.py), I get E:Program: can't open file 'Files\Python\python.exe Obviously this is an error in in parsing the path name, but I can't figure out where it's occurring. I've instrumented the python code, and it seems to happen on the call to accept, but instrumenting the .c code and rebuilding the socket library is more than I'm willing to do right now. I'm also not sure it isn't being triggered in a different process (which makes more sense to me), but I don't know why the main process would die in accept. (I have prints before and after the call to self._sock.accept().). In any event, the obvious workaround for me is to move my install. However, I'm not sure if this is a known problem, a new problem, or a "won't be fixed" problem. Many thanks, Gary From bokr at oz.net Fri Aug 1 12:40:28 2003 From: bokr at oz.net (Bengt Richter) Date: 1 Aug 2003 16:40:28 GMT Subject: Comments wanted on new introductory pages References: Message-ID: On Fri, 01 Aug 2003 10:09:59 -0500, "A.M. Kuchling" wrote: >A new set of introductory pages for python.org is being developed. The >current draft of a revised version is at http://www.python.org/topics/learn/ . > I'd like to see a little narrow horizontal python or something at the bottom of that page indicating end-of-info. I was wondering if some text got cut off, and actually looked at the page source to check. Looks very useful though ;-) Regards, Bengt Richter From anton at vredegoor.doge.nl Thu Aug 21 08:28:15 2003 From: anton at vredegoor.doge.nl (Anton Vredegoor) Date: Thu, 21 Aug 2003 14:28:15 +0200 Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> <6dj2kv8ugkieehs7guh786cl40o5lj6mcs@4ax.com> <599a6555.0308202108.397bb1a0@posting.google.com> Message-ID: "Andrew Dalke" wrote: [defines cognitive macro called Speech] >I've created a new language, called Speech. It's based on the core >primitives found in the International Phonetic Alphabet. I've made some >demos using Speech. One is English and another is Xhosa. This just >goes to show how powerful Speech is because it can handle so many >domains. And it's extensible! Anything you say can be expressed in >Speech! [snip lots of examples using it, trying to make macros look bad?] >In short, no one is denying that the ability to create new macros is >a powerful tool, just like no one denies that creating new words is >a powerful tool. But both require extra training and thought for >proper use, and while they are easy to write, it puts more effort >for others to understand you. If I stick to Python/English then >more people can understand me than if I mixed in a bit of Erlang/ >Danish, *even* *if* the latter makes a more precise description >of the solution. You have found a wonderful analogy, however you seem to assume that your prejudices are so self explanatory that the conclusion that macros are bad is natural. I am not a native English speaker, and so my expressiveness in this language is severely handicapped, while I consider myself a person with good linguistic abilities. Obviously there are people from other linguistic backgrounds participating in discussions in this newsgroup who have the same problems. Maybe they are greater speakers than me and yet have still more problems using English. However this does not in the least cause this newsgroup to deviate substantially (or maybe it does but as a non-native speaker I can not discern the difference) from English. Rather we all strive to speak the same language in order to make as much people as possible understand what we are saying. While using Python as a programming language we strive for Pythonicity and for combining elegance with concisiveness and readability. We are using docstrings to comment our code and answer questions about it in the newsgroup. Helpful people debug our code and assist in formulating our algorithms in Python. IMO there is a strong tendency towards unification and standardization among the readers of this newsgroup and the need to conform and the rewards this brings are well understood. Seeing all this it would be a missed chance not to give the community the freedom of redefining the language to its advantage. Of course there are risks that the community would dissolve in mutually incompatible factions and it would be wise to slow down the process according to the amount of responsibility the group can be trusted with. The rewards would be incomparably great however, even to the amount that I would be ready to sacrifice Python only to give this thing a tiny chance. Suppose you could make a bet for a dollar with an expected reward of a thousand dollars? Statistically it doesn't matter whether you get a .999 chance of getting a thousand dollars or a .00999 chance of getting a million dollars. Therefore, the only thing pertinent to this question seems to be the risk and gain assessments. >By this analogy, Guido is someone who can come up with words >that a lot of people find useful, while I am someone who can come >up withs words appropriate to my specialization, while most >people come up with words which are never used by anything >other than close friend. Like, totally tubular dude. Another relevant meme that is running around in this newsgroup is the assumption that some people are naturally smarter than other people. While I can certainly see the advantage for certain people for keeping this illusion going (it's a great way to make money, the market doesn't pay for what it gets but for what it thinks it gets) there is not a lot of credibility in this argument. The "hardware" that peoples minds are running on doesn't come in enough varieties to warrant such assumptions. For sure, computer equipment can vary a lot, but we as people all have more or less the same brain. Of course there is a lot of variation between people in the way they are educated and some of them have come to be experts at certain fields. However no one is an island and one persons thinking process is interconnected with a lot of other persons thinking processes. The idea that some kind of "genius" is solely responsible for all this progress is absurd and a shameful deviation to the kind of "leadership" philosophical atrocities that have caused many wars. To come back to linguistic issues, there's a lot of variation in the way people use their brain to solve linguistic problems. There are those that first read all the prescriptions before uttering a word and there are those that first leap and then look. It's fascinating to see "look before you leap" being deprecated in favor of "easier to ask forgiveness than permission" by the same people that would think twice to start programming before being sure to know all the syntax. In my case for example studying old latin during high school there was a guy sitting next to me who always knew the different conjugations the latin words where in and as a result he managed to get high grades with exact but uninteresting translations. My way of translating latin was a bit different, instead of translating word for word and looking up each form of each separate word (is it a genitivus, ablativus absolutus, imperativus, etcetera) I just read each word and going from the approximative meaning of all words put in a sequence of sentences I ended up with a translation that was seventy percent correct and that had a lot of internal consistency and elegance. It was usually enough to get a high enough grade and also some appraisal: "si non e vero, e ben trovato" or something like that. What this all should lead to I am not really sure, but I *am* sure that breaking out of formal mathematical and linguistic and programmatic rules is the only way to come to designs that have great internal consistency and that can accommodate for new data and procedures. It is sometimes impossible for a language designer to exactly pinpoint the reasons for a certain decision, while at the same time being sure that it is the right one. The ability to maintain internal consistency and the tendency of other people to fill in the gaps so that the final product seems coherent is IMO the main reason for this strange time-travel-like ability of making the right decisions even before all the facts are available. Well, maybe I have made the same mistake as you by providing arguments to the contrary of my intention of advocating the emancipation of the average Python user to the level of language designer. However if I have done so, rest assured that my intuition "knows" from before knowing all the facts that this is the way to go, and the rewards are infinitely more appealing than the risks of breaking up the Python community are threatening. One way or the other this is the way programming will be in the future, and the only question is: Will Python -and the Python community- be up to the task of freeing the programmers expressiveness and at the same time provide a home and starting point to come back to, or will it be left behind as so many other valiant effort's fate has been? Anton From mhammond at skippinet.com.au Fri Aug 8 22:09:36 2003 From: mhammond at skippinet.com.au (Mark Hammond) Date: Sat, 09 Aug 2003 12:09:36 +1000 Subject: COM server usage question In-Reply-To: References: Message-ID: Propad wrote: > Hello everybody, > I created a simple COM server, by copy and paste of the first example > from the book by Mark Hammond. I registered the server, and was able > access its functionallity from another python script, and from Word. > Then I tried accessing the server from another tool (which is my real > task). The problem was, it was not in the dropdown list of servers > usable by the tool. The alternative was to specify a position of the > server, by giving in the location of a .exe or .dll or .tlb file. > So after browsing my registry and this newsgroup for a (long) while, > my conclusion is: > -all com servers in the mentioned drop-down list are entries in the > HKEY_CLASSES_ROOT\TypeLib registry entry > -in order to get my server into that list, I have to somehow specify > that before registration. My guess would be I need to somehow use the > _reg_options_ attribute. But if, how? > -as an alternative I could write an *.IDL file, compile it to *.tbl, > and feed that into the calling tool. I've seen the example given at > the c_types page. But how do I know what entries to put into the *.idl > file? Meaning specifically the GUID-s. I'm sure theese are allready > somewhere in the registry, so I can't just go and create new ones. Can > the GUID-s for the type library, interface and implementig class be > derived from the GUID I used when creating the server? And also, where > do I get a working midl - compiler? I found two on my computer, but > neither seems to be working, asking for a cl compiler. > I thank you kindly for your help. At this stage, PythonCOM servers do not create a type library. Thus, the interface is registered, but no tools that process type libraries will be able to see it. Mark. From imbosol at aerojockey.com Sun Aug 17 18:08:15 2003 From: imbosol at aerojockey.com (Carl Banks) Date: Sun, 17 Aug 2003 22:08:15 GMT Subject: bitwise not - not what I expected References: Message-ID: Elaine Jackson wrote: > > | Python can't *guess* how many bits you want to keep. > > ** But it could if someone had told it that the leftmost nonzero > digit is the place to start. I just assumed somebody had told it > that. And if someone had done that, it would violate the invariant: ~(~x) == x In fact, by repeatedly applying ~ you'd eventually zero all the bits. -- CARL BANKS http://www.aerojockey.com/software "You don't run Microsoft Windows. Microsoft Windows runs you." From aahz at pythoncraft.com Wed Aug 20 14:06:59 2003 From: aahz at pythoncraft.com (Aahz) Date: 20 Aug 2003 14:06:59 -0400 Subject: What's better about Ruby than Python? References: <6dj2kv8ugkieehs7guh786cl40o5lj6mcs@4ax.com> Message-ID: In article , Doug Tolton wrote: > >I just don't find that argument compelling. By that logic we should >write the most restrictive language possible on the most restrictive >platform possible (ie VB on Windows) because allowing choice is >clearly a bad thing. It's all about maintaining balance. After all, Python forces you to format your code in a specific way rather than allowing the freedom of C/C++ or Perl. >Don't introduce a feature because it would be so cool that everyone >would use it? That's just plain weird. > >The Python Core language would still always be controlled by Guido, >but I don't see the problem with a community of people writing cool >macro's for python. Guido's mantra is readability. If you can come up with a concrete suggestion for a macro system that won't affect Python's readability, please propose a PEP. Otherwise, there's not much use arguing about it, because people won't pay attention. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From adalke at mindspring.com Sun Aug 24 01:12:12 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Sun, 24 Aug 2003 05:12:12 GMT Subject: python gripes survey References: <7s6gkv031b940dsc522pbh5g30q4nj5vd1@4ax.com> Message-ID: Ryan Lowe: > i was actually more impressed with the union/intersection of lists and > dictionaries. why the hell cant you join two dictionaries like you can two > list? the len thing is a pretty minor issue in my mind. Mostly because there isn't a good reason for what a = {1: "a"} + {1: "b"} should be. The most likely solution is a = {1: "a"} a.update({1:"b"}) However, there is something tricky even here. Watch this: >>> d = {1: "a"} >>> d.update({True: "b"}) >>> d {1: 'b'} >>> The key came from the first dict, the value came from the second. BTW, an alternative to a = d1.copy() a.update(d2) is d = dict(d1.items() + d2.items()) > i guess my request was a little vague. im actually more interested in > missing funtionality of the python language Missing language functionality is not the same as missing Python functionality. What you're asking is - why do other languages exist? Python lacks native support for: code blocks (like Smalltalk) macros (like Lisp) lazy evaluation (like .. Haskell? One of the functional languages) rich N-dimensional operators (like APL) predicate logic (like Prolog) symbolic math manipulation (like Mathematica) literate programming (like WEB -> Pascal/TeX) aspect-oriented programming (like AspectJ) stack nature (like Postscript (I had Forth here but didn't want a dup :)) color as part of syntax (like ColorForth) programming by contract (like Eiffel) fixed-point data types, as for money (like REXX) control over the memory arenas use by an object (like C++) direct access to memory, eg, as for I/O to periphials (like C) support for high-performance multiprocessor computing (like Fortran90) (some are available as external modules, like FixedPoint, but are not native.) There's easily more - just look at how many languages have been invented over the last few decades. Andrew dalke at dalkescientific.com From newsgroups at jhrothjr.com Sat Aug 2 16:39:09 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Sat, 2 Aug 2003 16:39:09 -0400 Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> <87el06d2i6.fsf@pobox.com> Message-ID: "Andy C" wrote in message news:y3VWa.261$_p6.23775419 at newssvr21.news.prodigy.com... > > > it isn't to a compiler). OTOH, *Python's* scheme is inferior to a > > > pure-space-character indentation scheme because off the tab-vs.-space > > > issue :-( > > > > Well, that's been recognized as a problem for a long time. I believe > > that the intention is to mandate spaces only in Python 3.0. On the > > other hand, I'm not holding my breath waiting for Guido to decide > > What's bad about tabs? I'm new to Python. Tabs are good because then you > can view the source however you want. I can't write in 4 space tabs and > someone else can change it to 2 if they prefer. But I can see the problem > with continuation lines. Also it must be ALL tabs or ALL spaces. This > shouldn't be too hard -- most editors have the "tabify" option. The basic problem with tabs is that many tools don't handle them "right." Especially when there's no agreement about what "right" means. Originally, they were metal shims that were put onto the back of typewriter carriages to stop the carriage at a particular point, and that's the "official" meaning of tab to this day: it advances to the next multiple of 8. According to this interpretation (which is *the* official interpretation) it's impossible to have only tabs and have any other indentation than 8 characters. Many tools don't allow you to configure tabs, and of those that do, each uses its own incompatible syntax and has its own quirks. In other words, tabs may seem like a good thing if you use just one or two tools that do what you want, but as soon as your program moves out into the wild world, things change. The only reason that Python works as well as it does with tabs is that there is an undocumented hack buried in the guts somewhere that identifies the comment line that emacs sticks into the program to remember your settings. It does this for a couple of other popular editors as well. John Roth > > Andy > > From bit_bucket5 at hotmail.com Sun Aug 31 14:41:48 2003 From: bit_bucket5 at hotmail.com (Chris Stromberger) Date: Sun, 31 Aug 2003 18:41:48 GMT Subject: Confusion re "global" statement Message-ID: This doesn't seem like it should behave as it does without using "global d" in mod(). d = {} def mod(): d['hey'] = 3 mod() print d When run, it prints {'hey': 3}. Seems like it should print {} w/o using "global d". Can someone explain? I guess it has to do with the fact that I'm not reassigning the name d in the function, but it seems counter-intuitive that I'm able to modify a global inside the function w/o saying "global d". Thanks, Chris From harry.g.george at boeing.com Mon Aug 18 15:27:09 2003 From: harry.g.george at boeing.com (Harry George) Date: Mon, 18 Aug 2003 19:27:09 GMT Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> Message-ID: Alexander Schmolck writes: > Alex Martelli writes: > > > (I do hope that Python never gets such a powerful macro system, no matter > > the allure of "letting people define their own domain-specific little > > languages embedded in the language itself" -- it would, IMHO, impair > > Python's wonderful usefulness for application programming, by presenting an > > "attractive nuisance" to the would-be tinkerer who lurks in every > > programmer's heart...). > > I don't think a powerful but potentially dangerous feature poses much of a > problem as long as there is little danger of inadvertently using it and little > incentive to inappropriately use it (e.g. you could do all sorts of stupid > things in python, like redefining __builtins__.len, but generally there isn't > much of an incentive to do so, so many of the reasons why e.g. Java > programmers might think python an unsuitable language for larger projects > don't really apply in practice. My feeling is this *not* true to the same > extent for ruby, where similar things are both encouraged and, if I don't > misremember, can happen inadvertently). > > Would you still have a problem with macros in python if utilizing them > required some obvious and explicit mechanism (say a 'use_custom_syntax' > statement right at the beginning of a module that wants to use macros), so > that their use could easily be controlled by e.g. project managers? > > 'as Yes, it is a problem under any circumstances. "The first step in writing a macro is to recognize that every time you write one, you are defining a new language". P. Norvig, "Paradigms of Artificial Intelligence Programming", c 1992, pg 66. In the Lisp world, you use the hundreds of macros in CL becuase they *are* the language. But home-grown (or vendor supplied) macros are basically a lockin mechanism. New syntax, new behavior to learn, and very little improvement in readability or efficiency of expresison (the commmon rationales for macros). The python language is just fine as is. If you really, really need something like a macro, consider a template body which is filled in and exec'd or eval'd at run time. -- harry.g.george at boeing.com 6-6M31 Knowledge Management Phone: (425) 342-5601 From mschneider.pad at t-online.de Fri Aug 15 16:55:31 2003 From: mschneider.pad at t-online.de (Marcus Schneider) Date: 15 Aug 2003 13:55:31 -0700 Subject: how does the main module notice when I change a module Message-ID: <3f443b52.0308151255.50c58885@posting.google.com> I use PythonWin on WinXP. Every time I change a module, I have to leave PythonWin and re enter to make it notice I have made changes. I guess this is not the normal way to do that.. do I have to store the module at a specific place? Is there a kind of "reset" command to make the main module update specific data? From tzot at sil-tec.gr Sat Aug 23 09:54:24 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Sat, 23 Aug 2003 16:54:24 +0300 Subject: Threading Oddity? References: Message-ID: On 22 Aug 2003 21:33:18 -0700, rumours say that google at hanger.snowbird.net (Kris Caselden) might have written: [code snip] >def thread1(): > while data_mutex.locked(): > data_mutex.aquire() > print 'thread1:',data > if data_mutex.locked(): > data_mutex.release() [code snip] Kris, please copy-paste *real* code. This is not code you ran, this was written for the sake of the post. thread.lock object has no attribute "aquire". >This code runs as expected. However, take away the while loop checks >for mutex lock and Python is unable to properly acquire the lock, >complaining of an unhandled exception. I never had any problems with thread.lock.acquire, and I use it a lot. Please come back with the code that fails for you, and specify the environment (OS, python version, whether you built it from sources, if you applied any changes to the source etc). The following program runs fine for me on Linux, Irix and Windows 2k: import thread, time data='this is data' data_mutex = thread.allocate_lock() def thread1(): data_mutex.acquire() print 'thread1:',data data_mutex.release() def thread2(): data_mutex.acquire() print 'thread2:',data data_mutex.release() thread.start_new_thread(thread1,()) thread.start_new_thread(thread2,()) time.sleep(1) I inserted the time.sleep(1) to allow for the threads to run before the program ends (and thus the threads end prematurely). threading would allow you to .join the threads instead. -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From newsgroups at jhrothjr.com Wed Aug 27 21:46:58 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Wed, 27 Aug 2003 21:46:58 -0400 Subject: Style question... References: Message-ID: "Anthony Roberts" wrote in message news:Uva3b.49430$la.826046 at news1.calgary.shaw.ca... > If I end indentation levels with "pass" statements, will I piss off people > that have to read my code? eg: > > for i in xrange(0,5): > if i: > print i > pass > print i * -1 > pass > > I ask for two reasons... a) it helps emacs figure it out, and b) I'm more > comfortable ending compound statements with a token. Isn't there some kind of emacs plugin, macro or mode that handles Python? I'm not an emacs person, but I've heard that there is, and I would expect that it would handle things like auto-indent for you. John Roth > > From jwdillworth at yahoo.com Fri Aug 22 16:51:45 2003 From: jwdillworth at yahoo.com (Jeremy Dillworth) Date: Fri, 22 Aug 2003 13:51:45 -0700 (PDT) Subject: visual indentation In-Reply-To: <3F4660CB.FF72D945@easystreet.com> Message-ID: <20030822205145.57105.qmail@web41112.mail.yahoo.com> Here's another idea: def world1(): RiColor(1.0,1.0,1.0) RiSurface('constant') RiSphere(1.0,-1.0,1.0,360) def world2(): RiColor(1.0,1.0,1.0) RiSurface('constant') RiSphere(1.0,-1.0,1.0,360) worlds_to_build = [world1, world2] for world in worlds_to_build: RiWorldBegin() world() RiWorldEnd() --- achrist at easystreet.com wrote: > Hilbert wrote: > > > > Hello, > > > > I'm using python to output RIB streams for Renderman. > > The RIB stream is a bunch of statements which describes > > a 3d image. The Rib standard allows for blocks which we > > usually indent for better visualization for example: > > > > WorldBegin > > Color [1 1 1] > > Surface "constant" > > Sphere(1.0, -1.0, 1.0, 360) > > WorldEnd > > > > I'm using CGKit in python which has a Renderman binding, > > so to output the same RIB I'd write: > > > > RiWorldBegin() > > RiColor(1.0,1.0,1.0) > > RiSurface('constant') > > RiSphere(1.0,-1.0,1.0,360) > > RiWorldEnd() > > > > But I get an error, because python interprets my indentation > > as a block in the python code. So the only way to write this > > is without the indentation: > > > > RiWorldBegin() > > RiColor(1.0,1.0,1.0) > > RiSurface('constant') > > RiSphere(1.0,-1.0,1.0,360) > > RiWorldEnd() > > > > But this is a lot harder to read. > > > > Is there any way to use such "visual" indentation in python? > > > > If the code is purely sequential, how about something like this: > > import string > def RunTheseStatements(s): > stmts = map(string.strip, s.split("\n")) > for stmt in stmts: > eval(stmt) > > RunTheseStatements(""" > > > RiWorldBegin() > RiColor(1.0,1.0,1.0) > RiSurface('constant') > RiSphere(1.0,-1.0,1.0,360) > RiWorldEnd() > > > """) > > > Al > -- > http://mail.python.org/mailman/listinfo/python-list From jjl at pobox.com Fri Aug 15 17:52:31 2003 From: jjl at pobox.com (John J. Lee) Date: 15 Aug 2003 22:52:31 +0100 Subject: Summer reading list References: <2259b0e2.0308130804.492aa1ac@posting.google.com> Message-ID: <87ekzmsi5c.fsf@pobox.com> mis6 at pitt.edu (Michele Simionato) writes: > "Joe Cheng" wrote in message > news:... > > To me it sounds disturbingly like "Procedures are more flexible than > > classes because you can compose classes out of procedures." > > I would subscribe that. Not that I dislike inheritance, but I don't kill > a mosquito with a bazooka. > > Let me give a real life example, happened to me recently. > > I had a class manipulating text, with a "dedent" method. It turns out > that the "textwrap" module included in the Python 2.3 distribution > contains a "dedent" function doing exactly the same. > Then I had the satisfaction of killing my own implementation, > and to add to my class the textwrap.dedent function just with one > line of code, "dedent=staticmethod(textwrapper.dedent)". I am > very happy with that because: [...snip usual reasons for reusing code...] > The fact that "dedent" was a function and not a method in a class > made my life easier. I had not to worry about inheriting from another > class with potential name clashes with my own, and "dedent" was the > only function I needed. > > Fortunately, quite a lot of modules in the standard library are > written without a class interface and I would date say I have never > seen an example of usage of a class when the class is not needed. > > In other words: most of the time a lightweight approach is more than > appropriate, why should I be forced to take a heavy weight approach? > The fact of having "free" functions (i.e. not bounded to classes) is > to me a big strenght of Python and it helps reuse of code quite a lot. All fine. > To reuse classes is good, but typically only works when you know > about the class you want to inherit *before* you start coding your > own class; on the other hand, it is quite easy to add functions > or methods to your class even *after* you wrote it. [...] But I don't think that makes any sense. As I'm certain you know, there would be nothing to stop you using a class in exactly the same way you used the function, because reuse != inheritance. Functions can be implemented in terms of classes, and classes can be implemented in terms of functions. The only reason it's good that Python library uses functions sometimes instead of classes is as you say: KISS. If it only needs a function, use a function. John From jp.andreaux at laposte.net Thu Aug 7 10:30:41 2003 From: jp.andreaux at laposte.net (Jean-Pierre Andreaux) Date: 7 Aug 2003 07:30:41 -0700 Subject: Gmpy Message-ID: <8578e2c1.0308070630.5fb70c22@posting.google.com> Gmpy module was a wrapper of the GNU MP library. It seems that no evolution is done on this module since 2001. Indeed, Gmpy is not supported in Python 2.2 nor 2.3. My question is the following: what is the better replacement solution for manipulating long numbers. I want to do long numbers exponentiations. Thanks in advance for your answers. JP From gh at ghaering.de Sat Aug 2 15:47:30 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Sat, 02 Aug 2003 21:47:30 +0200 Subject: pyrex error In-Reply-To: <8YPWa.48874$YN5.38312@sccrnsc01> References: <8YPWa.48874$YN5.38312@sccrnsc01> Message-ID: <3F2C1552.6000904@ghaering.de> Bryan wrote: > [PyRex produces code using staticforward that won't work in the combination Python 2.3/MSVC] 1) Please don't top-post. 2) The other way to temporarily solve this problem is to use MINGW instead of MSVC. In the PySQLite sources, I added this snippet on top: #ifdef _MSC_VER #define staticforward extern #endif to make it compilable under MSVC/Python 2.3. *After* #include-ing "Pyhton.h" of course. -- Gerhard From shlomme at gmx.net Tue Aug 12 13:33:17 2003 From: shlomme at gmx.net (Torsten Marek) Date: Tue, 12 Aug 2003 19:33:17 +0200 Subject: MySQLdb and Python2.3 In-Reply-To: References: Message-ID: Stephan Diehl schrieb: > Since using Python2.3, MySQLdb doesn't work anymore correctly. > Inserting data fails with "IndexError: list index out of range". > Since the MySQLdb website states, that it runs up to version 2.2, I > definatelly shouldn't complain :-) > Is there somebody whose MySQLdb is running with 2.3? > > MySQLdb 0.9.2 > Python 2.3 > Linux > > Thanks a lot for your help > > Stephan I run MySQLdb 0.9.2 with Python 2.3 and MySQL 4.0.13 without encountering any problems. BTW: What OS do you use? Did you recompile the package? Torsten From LDC.Office at unagi.cis.upenn.edu Sat Aug 30 02:05:56 2003 From: LDC.Office at unagi.cis.upenn.edu (LDC.Office at unagi.cis.upenn.edu) Date: Sat, 30 Aug 2003 02:05:56 -0400 (EDT) Subject: Member Services Message-ID: <200308300605.h7U65umh009906@unagi.cis.upenn.edu> Thank you for your email. The Linguistic Data Consortium will be closed on Monday, September 1, 2003 in observance of the Labor Day holiday. Your email will be read on Tuesday, September 2. Kind regards, Ilya -- Ilya Ahtaridis Membership Coordinator -------------------------------------------------------------------- Linguistic Data Consortium Phone: (215) 573-1275 3600 Market Street Fax: (215) 573-2175 Suite 810 email: ldc at ldc.upenn.edu Philadelphia, PA 19104-2653 www: http://www.ldc.upenn.edu From max at alcyone.com Sun Aug 17 22:59:04 2003 From: max at alcyone.com (Erik Max Francis) Date: Sun, 17 Aug 2003 19:59:04 -0700 Subject: What's better about Ruby than Python? References: Message-ID: <3F4040F8.87901505@alcyone.com> "Brandon J. Van Every" wrote: > What's better about Ruby than Python? I'm sure there's something. > What is > it? Wouldn't it make much more sense to ask Ruby people this, rather than Python people? -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ Never had very much to say / Laugh last, laugh longest \__/ Des'ree From hokiegal99 at hotmail.com Tue Aug 26 22:58:44 2003 From: hokiegal99 at hotmail.com (hokiegal99) Date: Tue, 26 Aug 2003 22:58:44 -0400 Subject: Raw Input Question References: <3F4C1880.5030903@hotmail.com> <3F4C1C37.510CAB06@alcyone.com> Message-ID: <3F4C1E64.6030206@hotmail.com> This one makes more sense to me so I used it, it works great: "Enter the string to replace %s with:" % XXX Thank you for your help!!! Erik Max Francis wrote: > hokiegal99 wrote: > > >>How can I pass the content of one varible into raw_input? See below >>for >>what I'm trying to do: >> >>XXX = raw_input("1. Enter the string that you'd like to find: ") >>y = raw_input("2. Enter the string that you'd like to replace XXX >>with: ") >> >>I'm trying to pass x into y. I tried the "Enter the string that you'd >>like to replace", XXX, "with:" approach, but Pyhton told me that I >>could >>only pass 1 argument, no more. > > > raw_input takes a string, and a string like any other. You can build > the string yourself: > > "Enter the string to replace " + XXX + " with:" > > or > > "Enter the string to replace %s with:" % XXX > From ktilton at nyc.rr.com Fri Aug 22 00:43:35 2003 From: ktilton at nyc.rr.com (Kenny Tilton) Date: Fri, 22 Aug 2003 04:43:35 GMT Subject: What's better about Ruby than Python? References: <6dj2kv8ugkieehs7guh786cl40o5lj6mcs@4ax.com> <599a6555.0308202108.397bb1a0@posting.google.com> <599a6555.0308210631.441f76cd@posting.google.com> <599a6555.0308211704.5be5e10d@posting.google.com> Message-ID: <3F45A047.8040408@nyc.rr.com> Roy Smith wrote: > So, is there something else that macros buy you that I'm not seeing? > People keep talking about how lisp macros are nothing like C/C++ macros. > OK, I'm willing to be educated. How are they different? Can somebody > give an example? Keep in mind that the last time I did any serious lisp > was about 20 years ago. With the C/C++ preprocessor one is limited to token replacement. I had great fun with that too. But a Lisp macro is just another function, one which sees code passed it symbolically and can use all the power of Lisp to transmogrify it. This macro just does token replacement: (defmacro cellify (class-name slot-name) `(defmethod ,slot-name ((self ,class-name) &aux (sv (slot-value self ',slot-name))) (typecase sv (function (let ((*dependent-cell* sv)) (funcall sv self))) (otherwise sv)))) OTOH, this next macro destructures something I designed to have the same syntax as the Lisp DEFCLASS (for familiarity) but adds to it: (defmacro defmodel (class superclasses (&rest slots)) `(progn (defclass ,class ,superclasses ,slots) ,@(mapcar (lambda (slot) (destructuring-bind (slotname &key initarg accessor) slot (declare (ignore slotname initarg)) `(cellify ,class ,accessor))) slots))) The mapcar keyword in Lisp iterates over the list of slots and hits each with the cellify macro (in turn destructuring each slot to get at the accessor name). As Mr Reedy demonstrated, this much can also be achieved with metaclasses, and I in fact converted from macros to metaclasses in Lisp a few years back. I came back to macros, but only because metaclasses are not standard in CL and I am in the process of taking my project public. Here's another example where substitution won't do. I am involved with some folks putting together Lisp teams to play RoboCup simulation soccer. One group is doing a straight translation of a C++ team, and they want to keep it literal so they do not end up rewriting the thing. Well, the code they are copying uses enum for things like CMD_DASH, CMD_KICK, etc, and Lisp don't play that. Of course, Lisp handles symbols, but some of these enums are then used to index into arrays. So now Lisp need enum: (defmacro enum (&rest names) (let ((prior-value -1)) `(progn ,@(mapcan (lambda (name-spec) (if (consp name-spec) (destructuring-bind (name &optional (this-value (incf prior-value))) name-spec (prog1 (list `(defconstant ,name ,this-value) `(export ',name)) (setf prior-value this-value))) (list `(defconstant ,name-spec ,(incf prior-value)) `(export ',name-spec)))) names)))) I need to write code to iterate over a list of names and assign them numbers. Notice I throw in an export the symbol from the defining package. Whatever it takes, I can generate that code in a macro and then any number of enums get ported by deleting the commas (and by changing midstream changes like "X=42" to (X 42).) My favorite macro move ever was a problem of deciding how to replicate coded forms on a remote system by supplying just the arguments supplied by the author. Once the code runs all slots seem to have been created equal, but I simply had the DEFPANEL macro note which parameters were actually typed in (it gets to see the code!) and generated code to stash a list of the coded names in a dedicate dslot. I loved the elegance of identifying which arguments had been authored by noting /at compile time/ which arguments had been authored. :) -- kenny tilton clinisys, inc http://www.tilton-technology.com/ --------------------------------------------------------------- "Career highlights? I had two. I got an intentional walk from Sandy Koufax and I got out of a rundown against the Mets." -- Bob Uecker From dave at boost-consulting.com Thu Aug 21 17:25:48 2003 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 21 Aug 2003 17:25:48 -0400 Subject: What's better about Ruby than Python? References: <3F41505F.69D18CC8@alcyone.com> Message-ID: Alex Martelli writes: > I have nothing against macros *IN GENERAL*. I just don't want them *in > my general-purpose language of choice for the purpose of application > programming*: they add NOWHERE NEAR ENOUGH PRODUCTIVITY, in application > programming, to even START making up for the risks of "divergence" of > dialects between individuals, groups, and firms. If I was focused on > some other field than application programming, such as experimental > explorations, tinkering, framework-writing, etc, I might well feel quite > otherwise. But application programming is where the big, gaping hole > of demand in this world is -- it's the need Python is most perfectly > suited to fulfil -- and I think it's the strength it should keep focus > and iinvestments on. The question is, do application programmers need the components that these framework-writers can painstakingly build out of macros? No application programmer needs to (knowingly) use macros, but if macros allow framework-writers to provide application programmers with abstractions which express their problems declaratively, in terms very close to their mental model of the domain, it could be a huge productivity win. In the C++ world it is we framework writers who use metaprogramming to provide application programmers with clean, concise, beautiful interfaces that express just what they want, and work correctly (see Boost.Python). Users of our frameworks never need to (knowingly) touch these fancy tools. That said, Python's dynamic nature (there is no imperative to get work done at compile time) makes it a lot harder to see where macros would be a big win. Even lisp can be meaningfully compiled, but Python cannot (at least, not in the same sense of the word, not yet). If someone is asking for Python macros I'd like to see some example applications. Apologies if I missed them somewhere - it's a long thread. -- Dave Abrahams Boost Consulting www.boost-consulting.com From peter at engcorp.com Tue Aug 19 07:06:07 2003 From: peter at engcorp.com (Peter Hansen) Date: Tue, 19 Aug 2003 07:06:07 -0400 Subject: python-dev Summary for 2003-08-01 through 2003-08-15 References: Message-ID: <3F42049F.8E967572@engcorp.com> Andrew Dalke wrote: > > I just use distutils and assume the person installing has told > it where to install. I got confused amoung the options we > have now, esp. since there's no "site-packages" under MS > Windows. I'm probably way out of the loop on the discussion, but just in case I'm not: there _is_ a site-packages in the MS Windows installation of the last couple of major versions of Python. Not in, I believe, 2.0, but probably those since. (Okay, by how much did I miss the point? :-) -Peter From tjreedy at udel.edu Sun Aug 31 12:59:40 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 31 Aug 2003 12:59:40 -0400 Subject: SF deploys SA, lauds P & BC Message-ID: In Friday's occasional newsletter to registerees, SourceForge announced that it has deployed SpamAssassin (written in Python) and ClamAV to have curb the inundation. It also announced Boa Constructor as the SF.NET Project of the Month. The citation: Python is an interpreted, interactive, object-oriented programming language. Python is arguably the most exciting and innovative programming language available for use today. Serious programmers, using any language, need powerful tools designed to support development in order to be successful. Boa Constructor, SF.net's August 2003 project of the month, is Python's serious tool. Boa Constructor is an Integrated Development Environment (IDE) that makes writing extensive Python code a snap. It provides an interactive debugger, text editor with highlighting, object inspector, integrated help and the ability to graphically view classes. Boa Constructor is written in Python and currently supports Linux and Windows. The project was founded on SF.NET in January 2001 and currently enjoys the top 10% activity ranking on the site. Project of the month: http://sourceforge.net/potm/potm-2003-08.php Summary Page: http://sourceforge.net/projects/boa-constructor/ Home Page: http://boa-constructor.sourceforge.net/ Terry J. Reedy From stevewilliams at wwc.com Sat Aug 30 09:47:21 2003 From: stevewilliams at wwc.com (Steve Williams) Date: Sat, 30 Aug 2003 13:47:21 GMT Subject: Need good example database schema In-Reply-To: References: Message-ID: Patrick K. O'Brien wrote: > I'm looking for a good schema to use as an example for an object > database system. Something like a books/authors/publishers or > teachers/students/courses kind of thing. There are plenty of examples > of such to be found, especially in the academic literature involving > object databases, but most of them are pathetic. It's hard to take a > schema seriously when it shows MarriedTeacher inheriting from Teacher, > etc. I want something that makes proper use of inheritance, has > classes with reasonable attributes, and does a decent job reflecting > reality (ie, books can have more than one author, a teacher of one > course could be a student of another, etc.). Any suggestions? > There are objects and then there are relationships between objects. Expand your concept of schemas to include relationships as independent objects (I call them Relators in my work) and you'll have more luck with reflecting reality. - Author is a relationship between book and person - Book contract is a relationship between author and publisher - Royalty is an attribute of book contract The hierarchy of object inheritance misses out on the web of relationships. Now add the time dimension to your objects and relationships and metadata, and you'll *really* start to reflect reality. Google bitemporal. From vvainio at tp.spt.fi Tue Aug 26 03:21:03 2003 From: vvainio at tp.spt.fi (Ville Vainio) Date: 26 Aug 2003 00:21:03 -0700 Subject: python gripes survey References: Message-ID: "Ryan Lowe" wrote in message news:... > > Generators yielding to other generators, to form a > > quasi-cooperative-multitasking environ seems quite > > powerful to me. > > > > not that i have any clue what you just said, but is this possible in python? > or only in code-block languages? Check out the back issues of "Charming Python", on generators as lightweight thread-equivalents: http://www-106.ibm.com/developerworks/linux/library/l-pythrd.html From disgracelands at quietblue.co.uk Sun Aug 10 10:18:40 2003 From: disgracelands at quietblue.co.uk (disgracelands) Date: Sun, 10 Aug 2003 15:18:40 +0100 Subject: Trying to embed python into C, help! Message-ID: <_usZa.986$rp4.4@news-binary.blueyonder.co.uk> I've been looking at using python and it's been going fairly well so far, i can call C from python and python from C fine but now i've hit a snag and i'm wondering how you guys have got around it. I have to initialise python inside my C project so that i can make calls to python modules whenever i need to but i can't create a dll for the project as it's got to produce an exe or at least a lib so that i can execute the initialisation code. The only way around it would seem to be to create a separate dll project containing the python callback code that can then import it to python and have my C code load it too. The problem with this approach is that i'm doubtfull that the storage space for the callbacks will be consistant between the python using the dll and C loading it. Basically i *think* that i won't be able to get the callback data from python to C. I know theres got to be a way around it but apart from the above i haven't got a clue. Any help would be appreciated. dis From hanzspam at yahoo.com.au Wed Aug 27 12:22:19 2003 From: hanzspam at yahoo.com.au (=?ISO-8859-1?Q?Hannu_Kankaanp=E4=E4?=) Date: 27 Aug 2003 09:22:19 -0700 Subject: modifying method behaviour References: Message-ID: <840592e1.0308270822.27e34fc9@posting.google.com> Nicodemus wrote in message news:... > Craig Zoretich wrote: > Use the new descriptor protocol: > > class logmethod(object): > > def __init__(self, func): > self.func = func > > def __get__(self, obj, class_): > def logger(s, *args, **kwargs): > result = self.func(s, *args, **kwargs) > params = [repr(x) for x in args] > params += ['%s=%r' % (name, value) for name, value in > kwargs.items()] > print 'LOG: %s(%s)' % (self.func.__name__, ', '.join(params)) > return result > return logger.__get__(obj) Actually, since we're accessing functions, not variables, descriptors aren't useful. This would do also: def logmethod(func): def logger(s, *args, **kwargs): result = func(s, *args, **kwargs) params = [repr(x) for x in args] params += ['%s=%r' % (name, value) for name, value in kwargs.items()] print 'LOG: %s(%s)' % (func.__name__, ', '.join(params)) return result return logger From ngps at netmemetic.com Wed Aug 27 21:36:01 2003 From: ngps at netmemetic.com (Ng Pheng Siong) Date: 28 Aug 2003 01:36:01 GMT Subject: asyncore: handle_accept() question? References: Message-ID: According to Chris : > class connection(asyncore.dispatcher): > def __init__(self, host = None, port = None, sock = None): > asyncore.dispatcher.__init__(self) > self.create_socket(socket.AF_INET, socket.SOCK_STREAM) > self.set_reuse_addr() # needed? > > if host and port: self.connect((host, port)) > if sock is not None: > print 'setting socket' > self.set_socket(sock) It's been a while since I did asyncore stuff, so I may be off-base. From asyncore.py: def create_socket (self, family, type): self.family_and_type = family, type self.socket = socket.socket (family, type) [...] def set_socket (self, sock, map=None): self.socket = sock [...] Your code calls self.create_socket, which binds self.socket to a newly created socket, then it calls self.set_socket(sock), which binds self.socket to your accepted socket. -- Ng Pheng Siong http://firewall.rulemaker.net -+- Manage Your Firewall Rulebase Changes http://www.post1.com/home/ngps -+- Open Source Python Crypto & SSL From janeaustine50 at hotmail.com Wed Aug 13 23:12:44 2003 From: janeaustine50 at hotmail.com (Jane Austine) Date: 13 Aug 2003 20:12:44 -0700 Subject: bsddb module bug?: doesn't release locks and seg faults Message-ID: There is a test code named test_env_close in bsddb/test, but it doesn't test the case thoroughly. There seems to be a bug in closing the db environment first -- the lock is not released, and sometimes it seg-faults. Following is the code that shows this bug. import os from bsddb import db dir,dbname='test_dbenv','test_db' def getDbEnv(dir): try: os.mkdir(dir) except: pass dbenv = db.DBEnv() dbenv.open(dir, db.DB_INIT_CDB| db.DB_CREATE |db.DB_INIT_MPOOL) return dbenv def getDbHandler(db_env,db_name): d = db.DB(dbenv) d.open(db_name, db.DB_BTREE, db.DB_CREATE) return d dbenv=getDbEnv(dir) assert dbenv.lock_stat()['nlocks']==0 d=getDbHandler(dbenv,dbname) assert dbenv.lock_stat()['nlocks']==1 try: dbenv.close() except db.DBError: pass else: assert 0 del d import gc gc.collect() dbenv=getDbEnv(dir) assert dbenv.lock_stat()['nlocks']==0,'number of current locks should be 0' #this fails If you close dbenv before db handler, the lock is not released. Moreover, try this with dbshelve and it segfaults. >>> from bsddb import dbshelve >>> dbenv2=getDbEnv('test_dbenv2') >>> d2=dbshelve.open(dbname,dbenv=dbenv2) >>> try: ... dbenv2.close() ... except db.DBError: ... pass ... else: ... assert 0 ... >>> >>> Exception bsddb._db.DBError: (0, 'DBEnv object has been closed') in Segmentation fault From aleaxit at yahoo.com Mon Aug 18 11:55:27 2003 From: aleaxit at yahoo.com (Alex Martelli) Date: Mon, 18 Aug 2003 17:55:27 +0200 Subject: What's better about Ruby than Python? References: Message-ID: Alexander Schmolck wrote: ... > I recall the following, roughly in order of importance (treat with > caution, it's some time that I looked at Ruby): > > 0. I it's possible to redefine classes at runtime without going bonkers > (instances automatically get updated to the new class definitions). This is generally feasible in Python, too -- but not with built-in types (e.g., you can't redefine what "+" means on integers, while in Ruby you could). > This, I think is by far python's greatest flaw, amongst other things it > greatly compromises its interactiveness, which is a key virtue. If > someone can explain to me how I'm wrong on this and python's behavior > really is sane, I'll be eternally grateful. I don't think I understand what you're saying. For example: >>> class X: ... def amethod(self): return 'just a method' ... >>> x=X() >>> x.amethod() 'just a method' >>> def abettermethod(self): return 'ah, now THIS is better!' ... >>> X.amethod = abettermethod >>> x.amethod() 'ah, now THIS is better!' >>> Isn't this "redefining classes at runtime // instances automatically get updated", too? If you want to redefine a bunch of entries in X, rather than just a few, X.__dict__.update(someotherdict) -- or even, shudder, reassigning X.__dict__ altogether... -- may perhaps be preferable, but I personally like the explicitness of assignments for most cases of such (rare) tasks. Alex From leonardbocock at yahoo.com Sun Aug 24 20:33:45 2003 From: leonardbocock at yahoo.com (lebo) Date: 24 Aug 2003 17:33:45 -0700 Subject: Python & memory usage Message-ID: <63701d2f.0308241633.30329433@posting.google.com> I'm experimenting with using Python as a very low resource usage systems management agent. Currently the best I'm getting is about a 2.4MByte base usage (python interp only) and with application, 4.8MByte memory footprint on WinXP. This is probably too high for sme target systems - ideally under 3MByte memory usage is a good target for a simple, quiesent stub agent - dynamic loading/unloading of classes on top of this is ok. Some general questions.... 1) Are there ways to reduce the memory footprint of Python to make it really lean? 2) Compile options? 3) Other options? Any thoughts appreciated. L From theller at python.net Mon Aug 4 13:27:52 2003 From: theller at python.net (Thomas Heller) Date: Mon, 04 Aug 2003 19:27:52 +0200 Subject: packaging windows services? References: Message-ID: max writes: >> I know that the (commercial) WISE installer can also install a service >> with the options you need. I do not know if inno or nsis can also do >> this. >> Thomas > Thomas - Thanks! > > due to my sad unfamiliarity with CVS, how can I merge this file with > the run_cvs.c I downloaded? > No need to use cvs, just download the patch and use a patch.exe utility for windows ;-) Search the internet to find one, and find out how to use it. Thomas From ben at algroup.co.uk Thu Aug 21 17:31:20 2003 From: ben at algroup.co.uk (ben at algroup.co.uk) Date: Thu, 21 Aug 2003 21:31:20 +0000 (GMT) Subject: I'm away Message-ID: <20030821213120.6CAF4107E4C@scuzzy.ben.algroup.co.uk> I'm away until Tuesday the 26th of August. If you want something to do with A.L. Digital then try Adam (adam at algroup.co.uk), Dominic (dominic at aldigital.co.uk) or the ALD project managers (projects at aldigital.co.uk), or call +44 (20) 8742 0755. I'll be checking in occasionally with the office, so you can also leave me a message there. If you have a problem with any of the software I maintain, try the appropriate mailing list. If you've just posted to a mailing list, my apologies. One day I'll figure out how not to spam you with this message. If you really want me to read your message now, then try putting [URGENT] in the subject. No promises, I may not bother to read them while I'm away, but I'll definitely see them when I get back. If you are really, really desparate, ring the office and tell them. Cheers, Ben. From dave at nullcube.com Sun Aug 17 01:20:00 2003 From: dave at nullcube.com (Dave Harrison) Date: Sun, 17 Aug 2003 15:20:00 +1000 Subject: Guido interviewed by Steve Holden Message-ID: <20030817052000.GB10989@dave@alana.ucc.usyd.edu.au> hehe, I saw that, with a leader like that makes you glad to be a pythoneer ;-) > Check it out, y'all: > http://www.onlamp.com/pub/a/python/2003/08/14/gvr_interview.html > > Thanks Steve and Guido for an entertaining read. =) > Good luck in California, Guido! Drink some Peet's for me... > > Peace, > Dave > -- > http://mail.python.org/mailman/listinfo/python-list From donn at drizzle.com Wed Aug 27 01:54:09 2003 From: donn at drizzle.com (Donn Cave) Date: Wed, 27 Aug 2003 05:54:09 -0000 Subject: OT: Ocaml? References: <7xk795xde6.fsf_-_@ruckus.brouhaha.com> <7h3wud0zihr.fsf@pc150.maths.bris.ac.uk> Message-ID: <1061963648.428004@yasure> Quoth David Abrahams : [... re Max Skaller ] | Now he's on to his next interesting OCaml based language, Felix: | | http://felix.sf.net That really is an interesting surprise, thanks! Donn Cave, donn at drizzle.com From hans at zephyrfalcon.org Sat Aug 23 14:51:17 2003 From: hans at zephyrfalcon.org (Hans Nowak) Date: Sat, 23 Aug 2003 14:51:17 -0400 Subject: Modifying the {} and [] tokens In-Reply-To: <5l7fkvsd2lor14s7s0avra2553nfhe3net@4ax.com> References: <04cekv0s6ghjtuhl5j2gph7ltobdb5rsam@4ax.com> <62rekv0k4ucgrh46lkp27klq13pq8ppp5p@4ax.com> <1h3fkvg8mkeq69a8hriojugqfcp75hafjj@4ax.com> <5l7fkvsd2lor14s7s0avra2553nfhe3net@4ax.com> Message-ID: <3F47B7A5.1020001@zephyrfalcon.org> Geoff Howland wrote: > On Sat, 23 Aug 2003 12:40:05 -0400, Roy Smith wrote: > >>Geoff Howland wrote: >> >>>{} + {} is not allowed. >> >>What would it mean? What would you do if you had two dicts: >> >>d1 = {'a':1, 'b':2} >>d2 = {'a':42} >> >>what would the value of (d1+d2)['a'] be? > > > I dont think it matters. Pick one and make that the standard. Ah, but I think it matters to Guido, or dict operators like these would have been added long ago. The problem here is that, when looking at d1 + d2, it is not obvious what is going on. If the same key appears in both d1 and d2, what will the resulting dict have? The value in d1? The value in d2? Or maybe an exception will be raised? Different people will have different notions here about what is "obvious" and "natural". "Pick one and make that the standard" may work in some other languages, but that is usually not how Python's design works. If there is not "one obvious way", chances are it won't make it into the language. (Of course, there are exceptions... but this seems to be a rule-of-thumb.) Fortunately, you can always roll your own dict with the behavior *you* find natural and obvious. So you can add a + operator to your custom dict, etc. However, it is not possible to change the behavior of literals. They will always behave (and be instances of) like the original, built-in object. As a result, you'll be forced to write something like d1 = mydict({'a': 1, 'b': 2}) d2 = mydict({'a': 42}) d3 = d1 + d2 On a side note, I don't think the other poster was trying to be facetious when he suggested you use Ruby... if this language feature is really important to you, then maybe Ruby may be a better choice, since that language is more "malleable" than Python. HTH, -- Hans (hans at zephyrfalcon.org) http://zephyrfalcon.org/ From staschuk at telusplanet.net Wed Aug 20 01:27:13 2003 From: staschuk at telusplanet.net (Steven Taschuk) Date: Tue, 19 Aug 2003 23:27:13 -0600 Subject: generators improvement In-Reply-To: ; from kalmas@udm.ru on Tue, Aug 19, 2003 at 11:55:04PM +0000 References: Message-ID: <20030819232713.C669@tibia.amotlpaa.bogus> Quoth Oleg Leschov: [...] > But, the question is - if there is .next(), why there's no .first()? When I'm getting elements from an iterator, I don't care whether I'm getting the first element or a following one. I just want the next element. Consider, for example, a function which wraps text into good-sized lines, maybe hyphenating or what have you; this function accepts as an argument an iterable containing lines of text. I might call this function directly on a file, wrap(fileobj) (exploiting the fact that iterating over a file produces its lines), or, say, read an RFC 822 header from the file first, it = iter(fileobj) for headerline in iter(it, ''): handleheader(headerline) wrap(it) In the former case, the function sees the first element; in the latter it sees elements after the first. But why on earth should it care? -- Steven Taschuk staschuk at telusplanet.net "I may be wrong but I'm positive." -- _Friday_, Robert A. Heinlein From whitton at atlantic.net Thu Aug 21 10:30:26 2003 From: whitton at atlantic.net (Travis Whitton) Date: Thu, 21 Aug 2003 14:30:26 GMT Subject: [OT] Why is it called string? References: <3f44ce77$0$556$b45e6eb0@senator-bedfellow.mit.edu> Message-ID: > "In computing, the word 'bit' is an abbreviation of what two other words?" Wow, I had no idea it was an abbreviation either. Luckily, dict had the answer waiting for me: >From Jargon File (4.3.0, 30 APR 2001) [jargon]: bit n. [from the mainstream meaning and `Binary digIT'] It's nice to see the occasional thread on computing history rather than the endless stream of coding issues. -Travis From donot at likespam.com Wed Aug 27 13:25:57 2003 From: donot at likespam.com (Rich) Date: Wed, 27 Aug 2003 10:25:57 -0700 Subject: learning to program Message-ID: I downloaded the beginner package from the "Python" site, and would like to know my next move. Should I wade through the site, or are there some exorcises I can do to get started in the process of learning how to program. TIA, Rich From mis6 at pitt.edu Thu Aug 7 11:15:22 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 7 Aug 2003 08:15:22 -0700 Subject: Class design issues: multiple constructors References: Message-ID: <2259b0e2.0308070715.6e9ff32@posting.google.com> "Greg Brunet" wrote in message news:... > I'm trying to write a package to handle working with DBase files. > There's enough different stuff in handling them (unfortunately) that I'm > not going to try to the interface DB-API 2.0 compliant - it'll be a > lower level wrapper around reading & writing the DBF files. In trying > to design a good framework, however, I'm unsure of how to progress. I > intend to have a class to represent the actual DBF files, and I would > expect to have an __init__ method to be called when creating a new > instance. When I first started, I included a filename as a parameter > that would be used to open an existing DBF file. Next I decided to add > the ability to create a new DBF file. This method needs additional > parameters (such as the field definitions), and, while in some other > languages, I could provide 2 versions of the constructor (overload it if > I'm using the right terminology), and the compiler would use the > appropriate one, things don't seem to work that way in Python. I'm also > thinking that I might rather name the methods more specifically (such as > Open & Create) instead of both being __init__. What would be the > Pythonic way to go about doing this? Would I make an __init__, Open, & > Create methods, and make 2 calls for each DBF object, like this: > > class dbf: > __init__(self): > pass > Create(self, filename, fieldDefs): > pass > Open(self, filename): > pass > > # open existing file > f1 = dbf() > f1 = dbf.Open('customer.dbf') > # create a new file > f2 = dbf() > f2 = dbf.Create('states.dbf', [('StateCode', 'C', 2), \ > ('StateName','C',20)] > If I understand you correctly, this could be done with a metaclass redefining the __call__ method and invoking Open or Create depending on the number of the arguments: class MetaTrick(type): def __call__(cls,*args): nargs=len(args) obj=cls.__new__(cls) if nargs==1: obj.Open(*args) elif nargs==2: obj.Create(*args) else: raise 'Wrong number of arguments' class dbf: __metaclass__=MetaTrick def Create(self, filename, fieldDefs): print filename,fieldDefs def Open(self, filename): print filename f1 = dbf('customer.dbf') f2 = dbf('states.dbf', [('StateCode', 'C', 2), ('StateName','C',20)]) Alternatively, without metaclass, you could redefine the __new__ method of the class and use a similar trick. HTH, Michele From gh at ghaering.de Tue Aug 12 08:43:16 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Tue, 12 Aug 2003 14:43:16 +0200 Subject: os.system('cd dir1 ... and executing next os.system command in that directory (dir1) In-Reply-To: References: Message-ID: <3F38E0E4.6000906@ghaering.de> Sami Viitanen wrote: > Hello, > > I'm having problems with os.system. > > If I execute some 'cd directory' command with it, after that the script is > on the > same directory level as it was before the command. > > Any ideas ? If you use os.system, any environment or current directry changes there will only affect your shell and the child processes of it, but never the parent process (Python). This is true for at least Windows and *nix. By the way, why don't you just use os.chdir? :) -- Gerhard From pedrosch at gazeta.pl Fri Aug 15 12:37:15 2003 From: pedrosch at gazeta.pl (Drochom) Date: Fri, 15 Aug 2003 18:37:15 +0200 Subject: cPickle alternative? References: Message-ID: Thanks for help:) Here is simple example: frankly speaking it's a graph with 100000 nodes: STRUCTURE: [(('k', 5, 0),), (('*', 0, 0),), (('t', 1, 1),), (('o', 2, 0),), (('t', 3, 0),), (('a', 4, 0), ('o', 2, 0))] PICKLED (lp1 ((S'k' I5 I0 ttp2 a((S'*' I0 I0 ttp3 a((S't' I1 I1 ttp4 a((S'o' I2 I0 ttp5 a((S't' I3 I0 ttp6 a((S'a' I4 I0 t(S'o' I2 I0 ttp7 a. Maybe now you can give me more precise advice:) Thanks again From tismer at tismer.com Mon Aug 25 14:26:12 2003 From: tismer at tismer.com (Christian Tismer) Date: Mon, 25 Aug 2003 20:26:12 +0200 Subject: [Stackless] Stackless ported to 2.2.3 In-Reply-To: References: Message-ID: <3F4A54C4.1030508@tismer.com> Chao, Heng Sun wrote: > I did so. The help works fine. However, I remember there was some > variable I had to set to make the recursion work for 100000. Right now, > recursion dies at before 1000 depth. sys.setrecursionlimit is a standard Python function. ciao - chris -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 pager +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From wim_wauters at skynet.be Thu Aug 21 15:41:27 2003 From: wim_wauters at skynet.be (WIWA) Date: 21 Aug 2003 12:41:27 -0700 Subject: tuple to string/list Message-ID: <538fc8e.0308211141.4bca8a8d@posting.google.com> Hi, I'm a newbie learning to appreciate the strength of Python. I'm writing an application to look at the access_log of my apache server: When I write: for i in range(len(month)): output="Hits for",month[i], ":" , teller[i] f.write(str(output)) f.close() => this produces a tuple: ('Hits for', 'Jan', ':', 0)('Hits for', 'Feb', ':', 2)('Hits for', 'Mar', ':', 3) => whereas I would like the following output: Hits for Jan: 0 Hits for Feb: 2 Hits for Mar: 3 Any easy way of obtaing this output? Thanks in advance, Wim From vvainio at tp.spt.fi Tue Aug 19 08:56:23 2003 From: vvainio at tp.spt.fi (Ville Vainio) Date: 19 Aug 2003 05:56:23 -0700 Subject: Brandon's personal style (was) References: <38ec68a6.0308172319.431a4fde@posting.google.com> Message-ID: "Brandon J. Van Every" wrote in message news:... > I'm a pugilist. If someone punches me, I'd sooner smash their face in and Now that's the language you don't often see on c.l.p. > Oh, I don't killfile people *forever*. The first reprieve generally comes What's all this power tripping with killfiles? I think they used to be a big thing something like 10 years ago, but nowadays there is just so much stuff on the net (outside usenet) that nobody has the time to read all the articles anyway. > Case in point: my first "What's better about Ruby than Python?" post. I > explicitly said, this is not a troll. Some chose to flame and accuse > anyways. Such people are useless, there is nothing you can do with them. Really, you could save *so* much energy by learning both, and doing the comparison by yourself. Give both languages a weekend. That way you might also have some more interesting material to play devils advocate with (as long as you don't pick up the significant whitespace classic ;-). BTW, I agree with you on some things (Java, Sun, marketing) but I can easily understand why people become aggravated. They are just not used to this kind of tone in this newsgroup, however entertaining the excercise might seem for a while. I've heard that c.l.lisp might be more suitable for such ambitions. From danbmil99 at yahoo.com Thu Aug 7 14:30:55 2003 From: danbmil99 at yahoo.com (dan) Date: 7 Aug 2003 11:30:55 -0700 Subject: random changes Message-ID: just a suggestion -- next time the core RNG is changed, I think it would be useful to have an -oldrandom switch. It is common practice in simulation projects to depend on the fact that your random numbers will come out the same if you use the same seed. In bumping to 2.3 with the new Mersenne algorithm, I have no easy way of duplicating my old results. From bleh at bleh.com Mon Aug 11 20:33:10 2003 From: bleh at bleh.com (TheAZN) Date: Mon, 11 Aug 2003 19:33:10 -0500 Subject: Problem with os.access with unicode filenames Message-ID: The os.access function gives me this error: "UnicodeEncodeError: 'ascii' codec can't encode character '\ub4' in position 31: ordinal not in range(128)" when I use the os.access function with an Unicode string which contains a character u'\u00b4'. Oddly enough in IDLE: if I do "print u'\ub4'" I get an error, but it doesn't give me an error if I do "print u'\ub00b4'" Is there a way to get around this? It works fine when the file name does not contain that character. Wes From aleax at aleax.it Wed Aug 20 16:38:14 2003 From: aleax at aleax.it (Alex Martelli) Date: Wed, 20 Aug 2003 20:38:14 GMT Subject: What's better about Ruby than Python? References: Message-ID: Alexander Schmolck wrote: > mertz at gnosis.cx (David Mertz) writes: > >> Alexander Schmolck wrote previously: >> |Anyway, I still don't see a compelling reason why class statements >> |couldn't/shouldn't be mutating, rather than rebinding. Is there one? >> >> I don't think there is any reason why the statement 'class' COULD NOT do >> what you describe. But doing so seems much less Pythonic to me. >> >> In Python, there are a bunch of statements or patterns that ALWAYS and >> ONLY binds names. Having something that sometimes binds names, and >> other times mutates objects... and you cannot tell the difference >> without finding something that may be far away in the code.... well, >> that's not how Pythonistas like to think about code. > > I agree this argument has merrit but I'm not sure I find it completely > compelling. The counter-arguments you present in the following do not affect Mertz's argument in the least, and thus cannot indicate why you don't find it completely compelling. To rephrase David's argument: simplicity suggests that a 'class' statement should always have the same fundamental semantics. Since it SOMETIMES needs to bind a name, therefore, letting it ALWAYS bind a name -- rather than sometimes yes, sometimes no, depending on context -- is the only Pythonic approach. In other words, class X: ... ALWAYS means the same as: X = ('X', (), ) (for appropriate values of and ) -- no ifs, no buts. Can't be simpler. In particular, it's a LOT simpler than the alternative semantics of if : ...something... else: ...something totally different... and I don't see you addressing this claim of greater simplicity in the rest of your post. So, since you say you DON'T agree with this, could you perhaps elaborate? Now, regarding the rest of your post: > What's worse, looking at the top of a file and thinking "Ah so that's what > class Foo does" and > > a) overlooking that somewhere below a 2nd class Foo gets created (and one > assumes both with instances that insidously claim to be 'Foos'). > b) overlooking that somewhere below a 2nd class Foo gets mutated (and thus > all > prexisting instances of it) > > ? > > I think we'd agree that both options are generally undesirable (so one It's definitely undesirable to totally overlook either a rebinding or a name, OR a mutation of a mutable object -- it makes no difference if you're overlooking these crucial things for a class, a function, or what. So, if you believe such distractions are frequent: > could conceivably even make class statments with the same name in module > scope raise an exception and have the user jump through some hoops if he > *really* wants something along those lines, like having to define Foo #2 > in a function and have it returned). ...you're basically making a case for functional programming (perhaps of the "single-assignment" variety): no object ever mutates, and each name is bound ONCE only -- no rebinding. Undoubtedly such languages do in fact eliminate the mistake of somebody thinking that...: x = [1, 2, 3] ...much code overlooked... if len(x) > 3: in that either a rebinding of name x, such as x = [6, 7, 4, 3] or a mutation of the object, such as x.append(23) could in fact cause the code guarded by that 'if' to execute. On the other hand, many people believe that functional programming is hard -- that mutating data and rebinding names leads to a much easier and free-flowing "style". Python (like most mainstream languages) definitely accepts the "many people"'s opinion, and does allow mutation of mutable objects (such as lists, clases, &c) and rebinding of names. So does Ruby, etc, etc. It WOULD seriously and deleteriously impact the concept of *FIRST-CLASSNESS OF ALL OBJECTS*, of course, if it was any harder to rebind a name that happens to be bound to a class object at some point, that one which happens instead to be bound to a list, a function, or what-have-you; *THAT* wishy-washy choice would be a terrible language design, while both Python's current design AND that of (e.g.) Erlang are quite self-consistent even though opposites. But this has nothing to do with any presumed desirability of statements that do quite different things depending on what names happen to be bound at the time said statements execute, of course. > But at least for b) I can think of one use-case I find rather compelling, > namely interactive development. I'd also think that the nasty surprise in > a) might well be worse than in b), because at least all instances that > claim to be Foos will behave the same. Not really, unless you want to remove the limitation about "same scope" too -- and get into a REAL mess. Each Foo can STILL refer to a totally different object, just in different scopes, e.g.: def aFoo(x): if x%2: class Foo: def __str__(self): return 'odd!' else: class Foo: def __str__(self): return 'even!' return Foo() someFoos = [aFoo(x) for x in range(8)] for foo in someFoos: print foo.__class__, foo There -- how would you complicate the semantics of the class statement in order to ensure the property you assert holds, namely "all instances that claim to be Foos will behave the same"?! No, unless you redesign and complicate the whole language to VASTLY deeper extent there is just no way to ensure THAT. And as you go on to admit, that "one use-case" is anything BUT "compelling" anyway -- modifying existing class objects is quite sufficient to support an interactive environment that works the way you'd like, if anybody's interested in doing so. Alex From detlev at die-offenbachs.de Mon Aug 18 14:14:34 2003 From: detlev at die-offenbachs.de (Detlev Offenbach) Date: Mon, 18 Aug 2003 20:14:34 +0200 Subject: advice choosing IDE References: Message-ID: <2lh711-1s2.ln1@stargate.solsys.priv> Phil Thompson wrote: > On Monday 18 August 2003 1:18 pm, Michael Peuser wrote: >> >> There are two GUI Toolkits you might like: >> PyQt and their GUI Builder (that would be free for non commercial >> work) if you plan to do *a lot* of GUI applications. The GUI Builder >> is *not* an Python IDE, so that is somewhat off topic ;-) > > I'll beat Detlev to it this time... You made it ;-) > > eric at http://www.die-offenbachs.de/detlev/eric3.html is a full IDE, > written in PyQt, that integrates with Qt Designer. It does the usual > editing, debugging, project management, class browsing - plus access to > source code control systems, syntax checking, unit testing, profiling, > code coverage. Latest snaphots include refactoring tools. Etc, etc, > etc. > > Phil And if there is something missing in the "etc, etc, etc" let me know and I'll try to implement it. Detlev -- Detlev Offenbach detlev at die-offenbachs.de From bromden at gazeta.pl.no.spam Fri Aug 15 16:34:09 2003 From: bromden at gazeta.pl.no.spam (bromden) Date: Fri, 15 Aug 2003 22:34:09 +0200 Subject: Why doesn't __call__ lead to infinite recursion? In-Reply-To: <2a82921f.0308151158.b8c9154@posting.google.com> References: <2a82921f.0308151158.b8c9154@posting.google.com> Message-ID: > foo is a function > foo is a callable object > foo has method __call__ defined true true false even if you "setattr(foo, '__call__', another_function)" foo.__call__ won't be called >>> def foo(): print 'foo' >>> def loo(): print 'loo' >>> foo.__call__ = loo >>> foo() foo -- bromden[at]gazeta.pl From mpeuser at web.de Fri Aug 15 15:44:28 2003 From: mpeuser at web.de (Michael Peuser) Date: Fri, 15 Aug 2003 21:44:28 +0200 Subject: Style in list comprehensions References: Message-ID: "Tim Lesher" schrieb im Newsbeitrag news:b6562547.0308151116.15dd7591 at posting.google.com... > Suppose I have a list of objects and I want to call a method on each. > I can do the simple: > > for i in objs: > i.meth(arg1, arg2) > > or using list comprehensions: > > [i.meth(arg1, arg2) for i in objs] > > The second feels more Pythonic, but do I incur any overhead for > creating the list of results when I'm not going to use it? Why do you think that to be more "pythonic"? To my understanding list comprehensions have been invented as a more understandable MAP/GREP notation (for... if...). If you do not use the results as a list I see little advantage. Of course there can be a more effecient execution, but the contrary can as well be the case, and this is probably version dependent. Why don't you do a benchmark??? Kindly Michael P > > -- > Tim Lesher > tim at lesher.ws From bokr at oz.net Thu Aug 7 21:11:40 2003 From: bokr at oz.net (Bengt Richter) Date: 8 Aug 2003 01:11:40 GMT Subject: Anonymous class question References: Message-ID: On Thu, 07 Aug 2003 03:20:24 GMT, Carl Banks wrote: >Dan Williams wrote: >> Python experts, >> >> Is there a more pythonic way to do something evquilent to what this line >> does without creating a dummy class? >> >> self.file = type("", (object,), {'close':lambda slf: None})() >> Does that (object,) do something I'm missing? >>> o1 = type('',(object,),{})() >>> o2 = type('',(),{})() >>> type(o1).__bases__ (,) >>> type(o2).__bases__ (,) Regards, Bengt Richter From rbroyles at bellsouth.net Sun Aug 24 09:38:00 2003 From: rbroyles at bellsouth.net (Ronnie Broyles) Date: Sun, 24 Aug 2003 09:38:00 -0400 Subject: new to python Message-ID: <_%22b.7018$jd.1229@fe02.atl2.webusenet.com> I am new to python--new to programming period. Will I need a compiler with python? I am currently working with the tutorials from the python.org website. TIA -- for every thousand hacking at the leaves of evil, there is one hacking at the roots. From nospam at maniacxs.de Tue Aug 12 13:37:02 2003 From: nospam at maniacxs.de (Lukas Kasprowicz) Date: Tue, 12 Aug 2003 19:37:02 +0200 Subject: Problem with computing...addition Message-ID: Hi Folks, I have some code, have tested the output, and I have seen the mess !!!! here the code: def fee(data): from re import sub, findall from string import join, split fee = sub('.*?EUR', '', data) fee = findall('.*,..', fee) print fee zwischensumme = float("0") for i in range(int(len(fee))): fee[i] = join(split(fee[i], ","), ".") fee[i] = float(fee[i]) zwischensumme = zwischensumme + fee[i] print zwischensumme print zwischensumme print int(len(fee)) print fee def main(data,vendor,type): print data fee(data) it begins in the main(). the output of "print data" in main is: -------------cut ----------------- * Nokia 6610 NEU & OVP * 2 Jahre Garantie * EUR 198,0016 18Min Nokia 6610 + Camera Headset HS-1C ** NEU ** EUR 221,0033 1Std 17Min NOKIA 6610 NEU + OVP + GARANTIE !!ANGUCKEN!!! EUR 181,0012 1Std 57Min Nokia 6610 OVP *neu* EUR 176,0025 17Std 35Min Nokia 6610, OVP, neu EUR 126,622 21Std 12Min Nokia 6610, Originalverpackt, WIE NEU !! EUR 113,0010 21Std 39Min Nokia 6610 ***NEU*** EUR 329,00- 21Std 42Min +++NOKIA 6610 NEU in OVP in grau+++ EUR 133,00101T 00Std 57Min NOKIA 6610 NEU OVP GARANTIE RECHNUNG !! EUR 151,0061T 01Std 12Min Nokia 6610 NEU OVP 24 Monate Garantie EUR 152,0081T 01Std 30Min NOKIA 6610 BLACK NEU und OVP KEIN VERTRAG !!! EUR 152,00161T 01Std 50Min Nokia 6610 - NEU EUR 152,0081T 02Std 28Min * NOKIA 6610 NEU*OVP*Silber*GARANTIE*Headset* EUR 152,0091T 02Std 39Min Nokia 6610 (NEU/OVP/ 2 JAHRE GARANTIE) EUR 152,00111T 02Std 44Min * Nokia 6610 grey * NEU + OVP + 2 J. Garantie EUR 131,99121T 02Std 49Min Nokia 6610 Neu ohne SimLock OVP mit Camera EUR 153,27231T 03Std 49Min NOKIA 6610, NEU, Ungebraucht, Silber!!! EUR 175,00-1T 18Std 14Min ---------------- cut ----------- everything in front of "EUR" is cut off. the fee is searched, and printed. the output of is: [' 198,00', ' 221,00', ' 181,00', ' 176,00', ' 126,62', ' 113,00', ' 329,00', ' 133,00', ' 151,00', ' 152,00', ' 152,00', ' 152,00', ' 152,00', ' 152,00', ' 131,99', ' 153,27', ' 175,00', ' 175,00', ' 68,00', ' 45,50', ' 26,50', ' 71,00', ' 152,00', ' 61,00', ' 101,00', ' 259,00', ' 151,00', ' 20,50', ' 1,00', ' 66,00', ' 200,00', ' 200,00', ' 1,00', ' 81,00', ' 1,00', ' 1,00', ' 25,50', ' 53,00', ' 240,00', ' 1,00', ' 25,50', ' 1,50', ' 101,00', ' 3,05', ' 1,00', ' 239,00', ' 15,50', ' 1,00', ' 10,00', ' 1,99'] so everything seems to be ok now.... but ... after the "," is changed to an "." and the field of the list is converted to float, the output looks like this: [198.0, 221.0, 181.0, 176.0, 126.62, 113.0, 329.0, 133.0, 151.0, 152.0, 152.0, 152.0, 152.0, 152.0, 131.99000000000001, 153.27000000000001, 175.0, 175.0, 68.0, 45.5, 26.5, 71.0, 152.0, 61.0, 101.0, 259.0, 151.0, 20.5, 1.0, 66.0, 200.0, 200.0, 1.0, 81.0, 1.0, 1.0, 25.5, 53.0, 240.0, 1.0, 25.5, 1.5, 101.0, 3.0499999999999998, 1.0, 239.0, 15.5, 1.0, 10.0, 1.99] So you see e.g. the 15th entry: "131.99000000000001" there should be "131.99" and not this. who could help? -- --------------------------------------------------------- Das einzige Mittel gegen Aberglauben ist Wissenschaft. (Henry Thomas Buckle) From fawcett at teksavvy.com Sun Aug 17 02:14:50 2003 From: fawcett at teksavvy.com (Graham Fawcett) Date: Sun, 17 Aug 2003 02:14:50 -0400 Subject: bitwise not - not what I expected In-Reply-To: References: Message-ID: <3F3F1D5A.5050106@teksavvy.com> Tim Peters wrote: >>(In case you're curious, I'm writing a script that will play Nim, >>just as a way of familiarizing myself with bitwise operators. Good >>thing, too: I thought I understood them, but apparently I don't.) >> >> > >You're only overlooking the consequences of an infinite amount of >information . > > Excellent line! I may borrow that one, Tim; I'll use it on the boss, next time that he asks why my application doesn't work the way he expected it to. Or why we ran out of coffee, or why the printer isn't working... It may need to be accompanied by a smoldering, wide-eyed Rasputin-ish stare, however, or it might lack the necessary mystique to supress any further questions. Of course, after a good night's sleep, maybe it won't seem like such a good idea. ;-) nocturnally yours, -- Graham From gregadelliot at hotmail.com Fri Aug 1 04:32:07 2003 From: gregadelliot at hotmail.com (jeff) Date: 1 Aug 2003 01:32:07 -0700 Subject: string/file manipulation simple Message-ID: Hey, first of all sorry if this has double posted my mail progie did some funny stuff I was just creating an encryption/ decryption program in python, ive got no problem with the algothims or anything like that. my only difficulty is how to i take a file and read in each charecter and then preform and operation to it and then output it to another file, basically i just wanna know how to take a string and then perform actions to each charecter cheers greg From jacek.generowicz at cern.ch Mon Aug 25 07:39:57 2003 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 25 Aug 2003 13:39:57 +0200 Subject: python gripes survey References: <2a82921f.0308241641.5bf82d6d@posting.google.com> Message-ID: Jeff Epler writes: > On Sun, Aug 24, 2003 at 05:41:35PM -0700, Patrick Lioi wrote: > > > foo = [yield i*i for i in xrange(100)] > > I also think that this would be a nice thing to have. I think that one > barrier to it was the lack of an implementation. I don't remember what > other objections were recorded in the PEP mentioned in another followup. For the URL-challeneged :-) ... BDFL Pronouncements Generator comprehensions are REJECTED. The rationale is that the benefits are marginal since generators can already be coded directly and the costs are high because implementation and maintenance require major efforts with the parser. ( http://www.python.org/peps/pep-0289.html ) From leo.broska at NOSPAM.isys.com.au Wed Aug 20 02:44:47 2003 From: leo.broska at NOSPAM.isys.com.au (Leo) Date: Wed, 20 Aug 2003 16:44:47 +1000 Subject: GUI IDE for Macintosh? References: <632a11-ks2.ln1@stargate.solsys.priv> Message-ID: "Detlev Offenbach" wrote in message news:632a11-ks2.ln1 at stargate.solsys.priv... > Leo wrote: > > ... > > i'm looking for a GUI Building IDE for Python Development running on a > > mac under OS X. > > ... > > I think in the meantime Trolltech has released Qt for Mac OS X. This > means that you should be able to compile sip, PyQt and QScintilla (???). Qt is ported, but SIP seems to be the problem: according to riverbankcomputing there is no SIP for mac. :-( that woud mean no luck... :-( or are there other other GUI builders? cheers, leo From peter at engcorp.com Mon Aug 25 22:10:46 2003 From: peter at engcorp.com (Peter Hansen) Date: Mon, 25 Aug 2003 22:10:46 -0400 Subject: Determinig position of a element in a list References: Message-ID: <3F4AC1A6.E72DD6A5@engcorp.com> Przemo Drochomirecki wrote: > > i'm wondering if there is any tricky way for doing following thing: > A - list of distinct integers (e.x. A = [1,3,7,11,14,15]) > very fast function determinig position of number x in list A > or -1 if x doesnt belong to A > Operator IN returns only false/true values > i can implement function index (e.x. index(5,A) = -1, index(7,A) = 2), but > maybe there's is simpler(builtin?) solution bisect.bisect() doesn't _quite_ do the job, but with a little logic around it it should work fine. You asked for *very fast*, and it's unlikely you can do faster than that, with a sorted list, on lists of any appreciable size. -Peter From francis at francisbarnhart.com Fri Aug 1 10:10:01 2003 From: francis at francisbarnhart.com (Francis Barnhart) Date: Fri, 1 Aug 2003 10:10:01 -0400 Subject: Plotting points with DISLIN In-Reply-To: References: Message-ID: <20030801141001.GB61778@falcon.francisbarnhart.com> I think what you're looking for is the scatter plot command. The python documentation is in PDF and I can't link to that, but here is the general idea: http://www.linmpi.mpg.de/dislin/kap16.html#section_2 Also, I *highly* recommend that you check out PyChart. I find it to be much easier to use than DISLIN. http://www.hpl.hp.com/personal/Yasushi_Saito/pychart On Thu, Jul 31, 2003 at 04:57:28PM +0000, Bob Perlman wrote: > Hi - > > I've been getting good results using the DISLIN data plotting package > with Python. But I've been unable to plot points instead of curves. > Can someone tell me how to turn off the between-points interpolation? > And if there is a way to do it, is there a way to change the style of > points plotted? > > Thanks, > Bob Perlman > -- > http://mail.python.org/mailman/listinfo/python-list -- Francis Barnhart francis at francisbarnhart.com http://francisbarnhart.com AIM: FrAniMaL "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -- Benjamin Franklin, Historical Review of Pennsylvania, 1759 From raphael.bossek at gmx.de Wed Aug 20 16:31:16 2003 From: raphael.bossek at gmx.de (Raphael Bossek) Date: Wed, 20 Aug 2003 22:31:16 +0200 Subject: Search for dialog based question/answer module for installation/configuration procedures Message-ID: Hi, I search for a module where programming of installation and configuration procedures based on question and answer/list selection/single line edit ect. steps can be done easy. I know only Debconf as something similar. But are there other project to, especially for Python ? -- Raphael From sjf at NOSPAM.plusnet.pl Wed Aug 6 05:23:56 2003 From: sjf at NOSPAM.plusnet.pl (sjf) Date: Wed, 6 Aug 2003 11:23:56 +0200 Subject: analiza pliku tekstowego References: Message-ID: > Witam wszystkich, > > mam program, kt?ry czyta plik tekstowy wiersz po wierszu > program ma sprawdza? czy w wierszu obecnie wczytanym do pami?ci wyst?puje > konkretny ci?g znak?w, je?eli tak to ma ten wiersz skopiowa? do nowo > utworzonego pliku > w jaki spos?b uzyska? wyszukiwanie wzorca? > pytanie dodatkowe: czy da si? potraktowa? dwa kolejne wiersze jako jeden > (wiem, ?e w konkretnym przypadku jest to jeden wiersz tyle tylko, ?e > prze?amany), tzn. program wczytuj?c wiersz "wie", ?e jest on prze?amany i > trzeba wczyta? jeszcze kolejny...? > > pozdrawiam > sjf > I'm sorry, not this group :( From pythonguy at Hotpop.com Sun Aug 24 07:06:08 2003 From: pythonguy at Hotpop.com (Anand Pillai) Date: 24 Aug 2003 04:06:08 -0700 Subject: Indentation question References: <1aV1b.9190$vy5.3133@nwrddc01.gnilink.net> Message-ID: <84fc4588.0308240306.70900022@posting.google.com> I can suggest two editors which does the block indentation. 1. IDLE 2. GNU Emacs In IDLE AFAIK, this option is available as "Dedent Region" to indent the code-block lesser, and "Indent Region" to indent it more, i.e to the right. In GNU Emacs, you can mark the region you want to indent/dedent, go to the Editor menu and say, "Indent Right More", "Indent Left More", etc which respectively indents the code-block more to the right and more to the left. -Anand David Lees wrote in message news:<1aV1b.9190$vy5.3133 at nwrddc01.gnilink.net>... > Christos TZOTZIOY Georgiou wrote: > > On Sat, 23 Aug 2003 05:50:25 GMT, rumours say that Geoff Howland > > might have written: > > > > [David Lees asks how to indent and unindent a group of lines in his > > code, referring to PythonWin and EditPadLight] > > > > > >>A lot of editors use the method of: > >> > >>1. Select lines of text > >>2. Press TAB or SHIFT+TAB to change indentation out or in > >>respectively. > > > > > >>I dont know about those editors though. > > > > > > This works for PythonWin, I don't know for EditPadLite. In IDLE (in > > windows at least), the keypresses are ^[ and ^] for unindenting and > > indenting, respectively; check the Edit menu for the actual shortcuts. > > I just tried it in EditPad and PythonWin. It works in both. Thanks > guys, this is real handy to know. > > David Lees From tzot at sil-tec.gr Sat Aug 30 12:42:18 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Sat, 30 Aug 2003 19:42:18 +0300 Subject: Reading and manipulating binary data References: Message-ID: On Sat, 30 Aug 2003 19:50:33 +0400, rumours say that "Dave" might have written: >Also part of the authentication system involves MD5 hashes. For this I need >to be able to take a string, find its MD5 digest, and then xor it with >another string. But since the MD5 digest is binary, and I don't know how to >change it, I can't xor it... Please, I am sure I am missing something >really obvious but I am stumped as to what it is. A quick hint: a MD5 checksum is 16 bytes long; so if your machine has 32 bit integers, you can have a tuple of 4 ints with: struct.unpack("4i", md5sum) which you can use for xoring. -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From gerrit at nl.linux.org Wed Aug 27 16:12:13 2003 From: gerrit at nl.linux.org (Gerrit Holl) Date: Wed, 27 Aug 2003 22:12:13 +0200 Subject: OT: Celebrity advice (was: Advice to a Junior in High School?) In-Reply-To: <3F4D0D8B.5E5F9488@engcorp.com> References: <3F4D0D8B.5E5F9488@engcorp.com> Message-ID: <20030827201213.GA4670@nl.linux.org> Peter Hansen wrote: > But if you refuse to go to prison, things get lethal pretty quickly. > That's what "ultimately" refers to above. Well, I don't think they get very lethal, they get painful at most. > I think the key word in the above is "ultimately", and > I can see why ESR would (I think validly) state what he did above. Ultimately, the state will use violence. But this violence should not have lethal consequences. If 'lethal' would be replaced by 'using violence', this statement is reasonable for some sorts of government decisions, but only for those involving law (e.g. not involving building roads (however, roads *can* be quite lethal ;)). Gerrit. -- 156. If a man betroth a girl to his son, but his son has not known her, and if then he defile her, he shall pay her half a gold mina, and compensate her for all that she brought out of her father's house. She may marry the man of her heart. -- 1780 BC, Hammurabi, Code of Law -- Asperger Syndroom - een persoonlijke benadering: http://people.nl.linux.org/~gerrit/ Het zijn tijden om je zelf met politiek te bemoeien: http://www.sp.nl/ From eppstein at ics.uci.edu Mon Aug 18 14:43:08 2003 From: eppstein at ics.uci.edu (David Eppstein) Date: Mon, 18 Aug 2003 11:43:08 -0700 Subject: Py2.3: Feedback on Sets References: <%BX%a.4999$N37.3051@nwrdny02.gnilink.net> <7h3d6f3143s.fsf@pc150.maths.bris.ac.uk> <3F411A93.70807@users.ch> Message-ID: In article <3F411A93.70807 at users.ch>, Borcis wrote: > > I'm not sure why multiplying a list by a negative number produces the > > empty list instead of an exception, though. > > If it is illogical for it not to raise an exception, then in an appropriate > universe the theory is logically permitted that some other value than the > empty list is more logical as a result, than the empty list itself. The appropriate theory for this being the free group generated by all possible Python objects? -- David Eppstein http://www.ics.uci.edu/~eppstein/ Univ. of California, Irvine, School of Information & Computer Science From jjl at pobox.com Mon Aug 18 18:48:07 2003 From: jjl at pobox.com (John J. Lee) Date: 18 Aug 2003 23:48:07 +0100 Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> Message-ID: <87fzjywpjs.fsf@pobox.com> Alex Martelli writes: [...] > of each block (rather than just unindenting) -- but then I do get > to avoid typing the equally-silly ':' which Python requires at the > _start_ of each block, so that's almost a wash:-). Other syntax [...] I'd never noticed that. Greg Ewing has pointed out a similar trivial wart: brackets and backslashes to get multiple-line statements are superfluous in Python -- you could just as well have had: for thing in things: some_incredibly_long_name_so_that_i_can_reach_the_end_of_this = line where the indentation of 'line' indicates line continuation. > Others no doubt base their choice of programming languages on just > such issues, and they generate the hottest debates -- but to me that's > just an example of one of Parkinson's Laws in action (the amount on > debate on an issue is inversely proportional to the issue's actual > importance). The differences between Ruby and Python are, in the end, about as far from significant as it's possible to be (near as I can tell from everybody's comments, that is). Which is why Ruby's very existence is a bit sad -- you could almost regard it as a code fork, except that the author forgot to start with Python's source code ;-) [...] > I do understand why others would thing otherwise, even though > I could hardly disagree more vehemently with them:-). Thus proving your own point about the inverse importance / volume relationship ;-) [...] > Ruby does have some advantages in elementary semantics -- for > example, the removal of Python's "lists vs tuples" exceedingly > subtle distinction. You may be right there. Guido's comment that tuples are mostly mini-objects did clarify this for me, though. > But mostly the score (as I keep it, with > simplicity a big plus and subtle, clever distinctions a notable > minus) is against Ruby (e.g., having both closed and half-open In the end, though, don't you agree that any such judgement is, from the pragmatic point of view, pointless once you realise how similar the two languages are? If somebody sneakily switched Python and Ruby in the middle of the night (so that suddenly many more people use Ruby, and much more code was written in Ruby than in Python), you'd stick with Ruby, wouldn't you? [...] > about undistinguishable to anybody and interchangeable in any *in*distinguishable. Ha! I found a bug. [...] > If I had to use Ruby for such a large application, I would > try to rely on coding-style restrictions, lots of tests (to > be rerun whenever ANYTHING changes -- even what should be > totally unrelated...), and the like, to prohibit use of this > language feature. But NOT having the feature in the first > place is even better, in my opinion -- just as Python itself [...] I mostly agree, but I think you could be accused of spreading FUD about this. Does anybody *really* choose to alter string-comparison semantics under everybody else's nose in Ruby?? That would be like doing import some_module def evil_replacement_function(): return blah() some_module.important_function = evil_replacement_function in Python, wouldn't it? John From pythonguy at Hotpop.com Tue Aug 19 02:07:12 2003 From: pythonguy at Hotpop.com (Anand Pillai) Date: 18 Aug 2003 23:07:12 -0700 Subject: ClientCookie bug (followup) References: <87fzk4sav2.fsf@pobox.com> <87znibzrnx.fsf@pobox.com> <87oeypdh92.fsf@pobox.com> <87k79a25pi.fsf@pobox.com> Message-ID: <84fc4588.0308182207.4c649b93@posting.google.com> I am working on a Cookie module which works *with* urllib2 rather than on top of it like the existing ClientCookie module. It uses the Cookie module which comes with python standard library. This module is written as an extension of my Harvestman webcrawler. The alpha code is ready. We are doing testing right now. Details will be posted to my website at http://members.lycos.co.uk/anandpillai within say 2 weeks or so. -Anand jjl at pobox.com (John J. Lee) wrote in message news:<87k79a25pi.fsf at pobox.com>... > cartermark46 at ukmail.com (Mark Carter) writes: > > > > I'll investigate further. > > > > Here are the results from running tests in ClientCookie 0.4.4.a: > [...] > > The upshot of this is that load_cookie_data() now works in win 98 and > > xp. > > load_from_registry() works from win xp; it works from win 98 if and > > only if you set the USERNAME environment variable. > > You missed the username argument. > > cookiejar.load_from_registry(username="mark") > > (should only be required for win9x family) > > > > I appreciate that all the stuff about request2 and response2 may not > > be to your liking - but at the moment I'm just trying to figure out > > what works, and what doesn't. We can also worry about the delayload > > business later. > > No really, I wasn't joking: you *never* need to use add_cookie_header > / extract_cookies if you're using urllib2 (at least, I can't think of > any possible reason to do so). It can only break things. > > > > What do you think about the idea of actually setting up an Aapache web > > page to test these things 'for real'? > > I've done limited testing on Windows with 'fake' cookies from a local > Apache server, and on wine on linux. As I said, though, I don't have > a networked Windows OS, so it's inconvenient to test these things in a > 'real' situation. And my machine currently doesn't boot into Windows > without physically switching cables around (security & obscure > hardware issues, not software ones), which means I currently can't be > bothered to test it on Windows :-P. So, your feedback is appreciated. > > > John From andymac at bullseye.apana.org.au Tue Aug 19 08:10:57 2003 From: andymac at bullseye.apana.org.au (Andrew MacIntyre) Date: Tue, 19 Aug 2003 22:10:57 +1000 (EST) Subject: Serious problem with Shelve In-Reply-To: <3F41C4DD.356912A4@yahoo.com> References: <3F3FB5B9.5E49B306@yahoo.com> <3F41BC50.91097FAF@yahoo.com> <3F41C4DD.356912A4@yahoo.com> Message-ID: <20030819220720.E79781@bullseye.apana.org.au> On Tue, 19 Aug 2003, Rami A. Kishek wrote: > File "D:\PROGRAMS\PYTHON23\lib\shelve.py", line 231, in open > return DbfilenameShelf(filename, flag, protocol, writeback, binary) > File "D:\PROGRAMS\PYTHON23\lib\shelve.py", line 212, in __init__ > Shelf.__init__(self, anydbm.open(filename, flag), protocol, > writeback, binary) > File "D:\PROGRAMS\PYTHON23\lib\anydbm.py", line 80, in open > raise error, "db type could not be determined" > error: db type could not be determined > > Incidentally, on the other machine I mentioned (the one on which shelve > worked perfectly with 2.2.3) shelve still works perfectly after > upgrading to 2.3. Since that is a Linux 2 machine, I figure perhaps it > is using a different db like gdbm or something ... Your shelve file is in DB v1.85 format. Commenting out the lines in which.py didn't do anything except deny the shelve module information about what the format actually _is_. You'll need to find/build a v1.85 compatible module to read the shelve then write it out in a later format. -- Andrew I MacIntyre "These thoughts are mine alone..." E-mail: andymac at bullseye.apana.org.au (pref) | Snail: PO Box 370 andymac at pcug.org.au (alt) | Belconnen ACT 2616 Web: http://www.andymac.org/ | Australia From jacek.generowicz at cern.ch Sat Aug 23 20:42:23 2003 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 24 Aug 2003 02:42:23 +0200 Subject: macro FAQ References: Message-ID: "Andrew Dalke" writes: > Here's a proposed Q&A for the FAQ based on a couple recent threads. > Appropriate comments appreciated Such an FAQ item is probably a good idea. However, I think that we should distil out much of the opinion (particularly the opinions about opinions of others :-) and try to base it on fact: - what are macros (C-like and Lisp-like), - what are the technical difficulties with introducing them into Python > X.Y: Why doesn't Python have macros like in Lisp or Scheme? > > Before answering that, a clarification on what 'macro' means. > A Lisp macro is a way of modifying code when that code is first > defined. It can rearrange the structure of the code, and add and > remove parts of it. Unlike C's #define macro language, Lisp > macros understand the structure of the expression and the > context (or "closure") in which it is found. A closure is a function which "remembers" variables from an enclosing lexical scope (also available in Python, since 2.1). Lisp macros merely replace themselves with some source code (their expansion) before the compiler sees them. I'm not sure what you mean by "macros ... understand the context". > Here's a simple example of what a macro might do for Python. > A complaint about Python is that constructors for simple data > types require typing the parameter names three times, as in > > class Country: > def __init__(self, name, capitol): > self.name = name > self.capitol = capitol [snip] Probably not the most exciting or edifying example, particularly given that metaclasses should be able to do it. I'm sure we'll be able to come up with a better one. I'll put some ideas forward at the end, to act as a starting point. > Macros work well in Lisp or Scheme, where the code is the data, all > written pretty much as a parse tree. This is very important, and is central to the problem of "how do we do it in Python?" > The second problem is that Python's code blocks do not > store the original parse tree, so there's nothing to manipulate. [...] > Nowhere will you find the original parse tree. This is typically true in Lisp as well, particularly after you have compiled your code. (Common Lisp _must_ have a compiler, but may _in addition_ have an interpreter; the standard defines a function which returns the source code of a function, but it is allowed to say "sorry, you can't have it".) The point in Lisp is that you _write_ your code in the form of a parse tree, in Lisp lists, and you can pass your parse tree to a macro without having to re-format it, and have the macro easily manipulate it. It's not clear how you would do this in Python. But you seem to be implying that macros go off and find the parse trees of code that has already been compiled, and then change it? (Hint: they don't.) > The deeper question is, should Python include macros? > > People with a Lisp background might have a problem understanding > this viewpoint. For the record, I am not advocating the inclusion of macros in Python. (I do object to the suggestion that macros are responsible for some supposed "fragmentation" of Lisp.) > More importantly, the detractors -- including those with plenty of > experience using macros in Lisp -- argue that macros cause dialects > to form. Could you please give me a reference to someone "with plenty of experience using macros in Lisp" arguing this ? I just don't believe it. (That's not to say that it's not true.) > Macros can modify other code to make it fit the problem better, What do you mean by "other" code? Macros modify the code that is passed to them as an argument, transforming it before the compiler gets to see it. I get the impression that you believe that macros can somehow modify code from other parts of the program. They can't. Ultimately, macros just save you a lot of typing of source code. (And thereby save you a lot of bugs.) If you can't type it as soure code, then a macro can't do it. > while functions only use other code but make no modifications. This only strengthens the above suspicion, but I'm not really sure what you mean, here. > This makes them very powerful but means that understanding a section > of code requires also knowing about any macros which might use the > code. What do you mean by "macros using code" ? The macros are part of the code, just like functions are. To understand the code, you must understand what the macros and functions do. > In an extreme case which wouldn't be used in real projects, every * > could be replaced with a +. This almost completely convinces me that you are very confused about what macros can achieve. Either, you are suggesting that one might write a macro which replaces every * operator with a + operator, and then pass _the entire source code_ of a project to it (possible, but patently absurd); or you are suggesting that it is possible to write a macro "over here" which, somehow, surreptitiously modifies existing source code "over there". a) Macros cannot do the latter. b) You can achieve something very similar in Python, by re-binding attributes of __builtins__. Think of the point of macros in another way. The point is _not_ to take existing source code, and to change it. The point is to take something that is not (necessarily) valid source code, and turn it into valid source code, before the compiler gets to see it. Why? Because this allows you to create a shorthand notation, and use macros to expand it to real code. Think in terms of encoding design patterns. > (As an aside, some proponents argue that macros and > functions are essentially the same. Alex Martelli made > an interesting observation about one difference: it's often > worthwhile to turn a set of code into a function even if it > is only called from one place, because it helps simplify > the code into smaller chucks which are easier to understand. > Macros, on the other hand, should almost never be used > unless they are used many times.) I broadly agree. (I think :-) A function written for a single-location-call, does not really abstract anything, it just moves some code elsewhere to make the original location look less hairy. Rarely would you need to use a macro for this purpose, but in such cases there would be no objection to writing a single-invocation macro. Macros which truly abstract something, can be difficult to write and difficult to read; in such cases it is important that the cost of creating a robust macro and the cost incurred by others in trying to understanding it, be offset by the savings made by its _repeated_ usage. But then, functions which provide an abstraction are also more difficult to write and understand than ones which merely "move code out of the way", and you'd have to think twice whether the abstraction is really useful, before deciding to pay the price for writing it, and making readers understand it. Even in this respect, there is no clear-cut distinction between functions and macros. > With only one or a small group of people working together > on a project there is little problem. Macros help in developing > idioms specific to the problem and group. When groups > share code, they also share idioms, and anyone who has had > to deal with UK vs. US English knows the effect idioms have > in mututal understanding. > > Those against macros say their benefits do not outweigh > the likelihood that the Python community will be broken up > into distinct subsets, where people from one group find it > hard to use code from another. I believe that anyone reaching such a conclusion can only do so on the basis of a misunderstanding of what macros can do. People in the music software "group" will find it hard to use code from people writing software for bioinformatics ... with or without macros. This has nothing to do with macros. OK, I promised some examples of macros. Note that I have not shown a single line of Lisp code in these threads, because I agree that it is likely to be meaningless to most readers of this group. I'll try continue without having to resort to Lisp examples. ==== Example 1: a debugging aid ================================ One litte macro I have for debugging purposes (let's call it "show"), allows me to print out the source code of a number of expressions, along with their values. At this point, note that Python's horribly irregular syntax <0.5 wink> already starts causing problems: should the macro look like a block of code, or should it look like a function call; in Lisp both look identical. The "block" version of the show macro invocation: show: sin(x) a a + b + c The "function" version of the show macro invocation: show(sin(x), a, a + b + c) In both cases, the action of the macro should be to replace itself with its expansion, _before_ the compiler gets to see the source code. The expansion should look like this: print "sin(x) =>", sin(x) print "a =>", a print "a + b + c =>", a + b + c Note the key points: 1) The macro receives some data, and transforms it into valid Python source code 2) This happens before compile time 3) Nothing "outside" the macro call gets affected by the macro's action. Can this be implemented using metaclasses, or any other existing Python mechanism ? === Example 2: Alexander Schmolck's updating classes =============== Alexander recently expressed the desire to have all existing instances of a class be updated, when he changes the source of his class, and re-evaluates the definition. This might be achieved by doing something like the following: temp = MyClass class MyClass: blah temp.__dict__ = MyClass.__dict__ I'm not so much interested in the fine Python details of exactly what needs to be modified (__dict__, __bases__, whatever); what is important is that at least 3 distinct steps need to be taken, and trying to bundle these three steps (this pattern) into a function is impossible, because you can't pass the text of a class definition body to a function. (You could pass it as a string, but then your IDE would treat it as a string and refuse to indent it for you, and writing classes this way would be very unnatural.) A macro might help as follows. Write a macro called updating_class, which you would use instead of the built-in class statement. This macro might work according to an algorithm like this: class_name = the_body = expansion = "temp = %s" % class_name expansion += "class %s%s" % (class_name, the_body) expansion += "temp.__dict__ = %s.__dict__" % class_name return expansion Here I'm assuming that the return value of the macro replaces the macro call in the source code, before the compiler gets to see the source code (which is pretty much what happens in Lisp). So, updating_class foo: blah would turn into temp = foo class foo: blah temp.__dict__ = foo.__dict__ Again, note that any code not appearing "inside" the macro call, is not affected by the macro in any way ... almost ... ... This second example also serves the purpose of demonstrating free variable capture (the other type of variable capture is called macro argument capture). Variable capture is what is (according to the Schemers) unhygenic about CL macros. What is it? Well, note that, if a variable called "temp" had already existed in our enclosing scope, the updating_class macro expansion would have clobbered it. Scheme gets around this by ensuring that "temp" lives inside a local scope of the macro. The CL philosophy respects the fact that sometimes you deliberately _want_ to capture some variables. CL allows you to protect yourself against variable capture by using the "gensym" function; a function which creates a symbol (think of it as an identifier), which is guaranteed not to have existed before. This has turned out rather long, but I hope that it demystifies these scary exotic macros for at least one or two people on the list. From alessandro at sephiroth.it Thu Aug 7 10:36:52 2003 From: alessandro at sephiroth.it (Alessandro Crugnola *sephiroth*) Date: Thu, 07 Aug 2003 14:36:52 GMT Subject: py2exe problems References: Message-ID: <8utYa.48785$cl3.1524137@news2.tin.it> i'm sorry, but it gives me the same warning also using python 2.2.3 -- Alessandro Crugnola [sephiroth] Flash | PHP Developer http://www.sephiroth.it Team Macromedia Volunteer for Flash http://www.macromedia.com/go/team Flash-php mailing list http://www.flash-php.it/index.php?ml=fpcoders&action=subscribe "Alessandro Crugnola *sephiroth*" ha scritto nel messaggio news:xGsYa.28339$an6.997877 at news1.tin.it... > > Which Python version are you using? 2.3 doesn't yet work correctly, but > > 2.2 should be ok. > > thanks for the quick reply.. > i'm currently usng python 2.3 in fact.. > I will try to get back to 2.2 and let you know > > -- > > Alessandro Crugnola [sephiroth] > Flash | PHP Developer > http://www.sephiroth.it > > From aleax at aleax.it Mon Aug 4 03:01:47 2003 From: aleax at aleax.it (Alex Martelli) Date: Mon, 04 Aug 2003 07:01:47 GMT Subject: Determining if a filename is greater than X characters References: <93f5c5e9.0308021815.44c57a2d@posting.google.com> <3F2DC543.70700@vt.edu> Message-ID: hokiegal99 wrote: > One last question and then I'll leave you guys alone for awhile: How > would I append a string to the end of each file that I've truncated? I'd > like to put '.txt' on the end, but I don't understand how to go about > it. When I tried this: > > old_fname = files > new_fname = old_fname.append('.txt') > > .txt was added as a string to the files list. Researching a bit on > Google told me that in Python strings are unchangeable. So, how would I > go about changing a string? You cannot change a given string-object, any more than you can change a given number-object -- the object 23 will always have value 23 (never 22 nor 24 nor any other number), the object 'foo' will always have value 'foo' (never 'bar' nor 'foobar' nor any other string). However, you can re-bind a name to refer to a different object than the one it previously referred to. Thus, for example: x = 23 x = x + 1 this has not changed the number 23, whose value IS still 23, but name x now refers to a different number, namely, the number 24. Similarly: x = 'foo' x = x + '.txt' this has not changed the string 'foo', whose value IS still 'foo', but name x now refers to a different string, namely, the string 'foo.txt'. The unchangeability of strings doesn't inhibit string manipulation any more than the unchangeability of numbers inhibits arithmetics. Simply, operations on strings build and return new strings, just like operations on numbers build and return new numbers, and in either case you may, if you wish, re-bind some pre-existing name to refer to the new objects. Alex From achrist at easystreet.com Sun Aug 3 13:11:47 2003 From: achrist at easystreet.com (achrist at easystreet.com) Date: Sun, 03 Aug 2003 10:11:47 -0700 Subject: PyChecker work with Python 2.3? References: <3F2C5300.FA223CBA@easystreet.com> <3F2CBCC2.3FC51D57@easystreet.com> <3F2D0A11.3090607@ghaering.de> Message-ID: <3F2D4253.65A63727@easystreet.com> Fran?ois Pinard wrote: > > There is of course the danger of abusive laziness, but we should be > careful and reserved, before silently assuming that our correspondent > is rotten lazy. > I may be rotten and I may be lazy, but rotten lazy no one has ever called me AFAIK. I post code here whenever I've got anything worth sharing or finding out if it's not worth sharing. (I should publish a paper sometime about using Google Groups as a substitute for CVS.) About a month ago I made some comments about wxHtml and wound up debugging code for a correspondent by email who wasn't getting it to work. That was good. The world has brilliant people and pedestrian people. I'm more pedestrian. I'll admit that I ask more questions than I answer, but that helps keep this newsgroup balanced, as there are so many brilliant people here who answer more questions than they ask. If it wasn't for people like me, the brilliant ones would be here answering questions that noboby had asked. Life's like that. Everyone has a place at the table. First you eat, and then you get eaten. Al From newsgroups at jhrothjr.com Mon Aug 18 20:42:17 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Mon, 18 Aug 2003 20:42:17 -0400 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: <3F41208F.40021A68@engcorp.com> Message-ID: "Andrew Dalke" wrote in message news:bhrmk0$hi7$1 at slb0.atl.mindspring.net... > John Roth > > All of the Ruby collections implement a .each method, which is essentially > > a version of the Visitor pattern. If I want to do something to every > element > > in a list or a dict (or any kind of collection,) all I have to do is say > > something like (using Python syntax): > > > > collectObj.each() > > Does that mean 'apply the method to each element of my > collection?'? Does it return a new container or modify things > in-place? Is it applied recursively? I think that's something that each object which implements .each needs to specify. > > And you > > have to worry about distinctions between functions and methods. In other > > words, it's a mess compared to Ruby. > > Where does that distinction come into play? A method is a bound > function, kinda like a curried function with self. Ruby doesn't have functions in the sense that Python does. Since a module is treated as a class without instances, module level functions are class methods: they have the module itself as the instance. I find this to be a conceptually cleaner way of handling the issue. > I find C++ methods more confusing, because a reference to a > class method is unbound, when I almost always want it bound. Well, in C++, there is no class object to bind it to. I think that's a difficulty in C++, but then, I don't use the language. > > Now, you can say: "We've got that with map()." Well, we've got it when > > your inputs are either lists (or implement the correct protocol) but the > > result is a list, it's not an internal modification to the object's state. > > Ahh. Are strings in Ruby mutable or immutable? ... Yup, > looks like it's mutable. From the FAQ > > def downer(string) > string.downcase! > end > a = "HELLO" > downer(a) > puts a #=> "hello" > > In which case it makes more sense for this in Ruby than in > Python, since > > "ABCDEFG".each(f) > > can't do that much unless f modifies state, either as a bound > method or tweaking global variable. > > Given that rather fundamental difference, an each method > in Python + code blocks wouldn't be any more powerful > than a for statement. The following is possible > > def each(container, f): > for i, x in enumerate(container): > container[i] = f(container[i]) > > but then it requires the container be indexable, which > is stronger than just being iterable. The major difference is in program expressiveness. As I said, a For statement is a statement, while .each is an expression, even when followed by a code block. There's a considerable difference in the way the program is laid out, which makes a difference in how easy it is to determine what is being done. > How do Ruby's associative arrays work when the string used > as the key is mutated in-place? Is it copy-on-write? I believe that's true for strings: they're used enough that there's a special provision for them. For other objects, it's up to the object type to maintain its hash value properly, or to the application to rehash the dictionary. I don't really consider this to be the best policy, though. I like the Python solution better, though: solve the problem by not allowing mutable values as keys. > > To continue on this vein, Ruby directly implements Visitor, Observer, > > Delegate and Singleton. I don't particularly like the way it does some > > of them, but Python can't claim any one of the four! > The Python approach to a Singleton is called a 'Borg' class. I knew I should have said: "And don't tell me about Borg. It's a bloody hack that never should have been invented, and should be quietly buried at the crossroads with a stake through its heart now that it's possible to do it properly." And I have said it before, on this newsgroup, in fact. > The other way to get singletons is with a factory function, > which under Python wouldn't look different than a normal > constructor. I looked at some Java code recently and > wanted to suggest a factory implementation only to realized > that would require a lot of 'new' removals. Well, yes. You've always been able to do that, and the Ruby mechanism is basically a class function. The thing that the __new__() method (and Borg, to give it its due) does that neither the factory function nor the alternate constructor does is use the proper convention for creating the instance: that is, the class's name. That means that if you want to convert it from a singleton, you've got a greater chance of having code you don't have to touch. > Despite my best attempts, I find it almost impossible to slag someone > without including information to back up my view. Eg, I thought my > numbers and trends of mentions of other programming languages was > pretty interesting, but I guess it was of no value to you. :( I found it interesting, but not to the point. If there is one, it's simply a question of whether any of the differences are significant enough so someone who knows one language would consider switching to another one. Google searches won't tell you that, only looking for people who've made that switch will tell you. And I doubt if you'll find them on this newsgroup. That's the one problem I have with Brandon's questions. If I wanted to find out whether someone considered Ruby to be sufficiently better than Python to switch, I'd look on the Ruby newsgroup, not this one. I'm basically taking it from the viewpoint of whether there's anything in Ruby that I think would be good in Python, which is a question that might interest people on this NG. John Roth > > Andrew > dalke at dalkescientific.com > > From mwh at python.net Wed Aug 20 10:20:52 2003 From: mwh at python.net (Michael Hudson) Date: Wed, 20 Aug 2003 14:20:52 GMT Subject: distutils References: <7h3y8xo4q1v.fsf@pc150.maths.bris.ac.uk> <96L0b.207854$Ho3.27753@sccrnsc03> Message-ID: <7h3oeyk4dl1.fsf@pc150.maths.bris.ac.uk> "Bryan" writes: > "Michael Hudson" wrote in message news:7h3y8xo4q1v.fsf at pc150.maths.bris.ac.uk... > > "Bryan" writes: > > > > > what is the correct way to pass custom values to a distutil's setup > > > script? i'd like to pass on the command line the libraries_dir > > > path. should i just parse it out from sys.argv? > > > > Um, most options already have an associated command line option... > > doesn't the --install-dir option to install_lib do what you want? > > > > it doesn't work for the library_dirs > > setup.py install --library_dir=".." > error: option --library-dirs not recognized > > or > > setup.py --library_dir=".." install > error: option --library-dirs not recognized Oh, *that* option. You have to pass that directly to build_ext, it seems. 'install' doesn't pass it through. Cheers, mwh -- I believe C++ instills fear in programmers, fear that the interaction of some details causes unpredictable results. -- Erik Naggum, comp.lang.lisp From romany at actimize.com Wed Aug 13 01:40:50 2003 From: romany at actimize.com (Roman Yakovenko) Date: Wed, 13 Aug 2003 08:40:50 +0300 Subject: unsigned int \ long Message-ID: <91BFE89EFFA2904E9A4C3ACB4E5F2DF5027B04@exchange.adrembi.com> Hi. I need to work with integer as unsigned integer, but I can't find documentation how can I do it. Some reference on this will be appreciated. For example (unsigned int)(-1) == 0xFFFFFFFF. Thanks. Roman. From null-i_do_not_like_spam at tfh.ca Fri Aug 22 15:23:46 2003 From: null-i_do_not_like_spam at tfh.ca (Sean Cody) Date: Fri, 22 Aug 2003 14:23:46 -0500 Subject: Win32 ping In-Reply-To: References: <4cs1b.344$f7.80337@localhost> Message-ID: > http://www.python.org/~jeremy/python.html > > I have downloaded and used that module already for fellow users of the > local metropolitan area wireless network. > I tried that but it complains about not having os.fork() available. dir(os) does not contain fork. -- Sean From kosh at aesaeion.com Tue Aug 19 02:13:28 2003 From: kosh at aesaeion.com (kosh) Date: Tue, 19 Aug 2003 00:13:28 -0600 Subject: Brandon's abrasive style (was Re: What's better about Ruby than Python?) In-Reply-To: References: Message-ID: <200308190013.28092.kosh@aesaeion.com> On Monday 18 August 2003 10:43 pm, Brandon J. Van Every wrote: > I ask tough questions about Python vs. other languages and platforms. Some > people can't handle it. Maybe they'd handle it if I diplomatically sugar > coated it, but I'm not going to. Things to irritate the "Brandon's a > troll" crowd some more: Your questions are not tough however they are designed to start fights which judging from your history of posting you are very good at doing. You said at one point you where giving up on this group. I ask that you actually do that since no group actually deserves your abusive presence.You don't have to suger coat anything on this group but being polite does not require any kind of sugar coating. Pointing out there is a problem with python speed for a certain kind of operation with a code example is fine. Pointing out that python is stupid because it does not do what you want where what you want is never clearly stated and no code is presented is not. > > - Python is not a good language for low-level 3D graphics problems. C++ is > better. Python talking to opengl is good for low level 3D graphics and use psyco to convert hotspots. If those spots are still hot convert it to C however for number work psyco can sometimes beat c and it is getting better. > - Python isn't a rapid prototyping godsend for every problem out there. Nothing is a godsend for every problem that exists. However that does not mean that python is very good. > - GUI and tools support can end up being more important than language > niceties. Yes that is certainly possible. I use python with gideon for my ide uder kde since I find that is the most productive way for me to work. I do db apps mostly and the io slaves in kde give me transparent access from any app to my data outputs. IO slaves save me a huge ammount of time and I am aware of no equiv in in the windows or mac world. I can also use pyKDE to build gui apps in kde that get all of these features automatically. > - Microsoft C# and .NET are strategic threats to Python's prosperity and > vitality, if not survival. This I don't buy at all. I see very little usage of this technology server side and I see much less work being done to put new ms solutions on the server. Most of what I see are java,python,php,perl etc solutions being done server side on unixes. > - Pythonistas should consider trying to eat Java's lunch, because they > aren't going to eat Microsoft's lunch. I don't see why python has to do anything to java since you can run python code inside the java vm. Also I feel it is far easier to wipe out ms solutions server side then java. I have successfully built zope apps to beat out ms solutions server side however taking on java would be good deal harder. > - Ruby has some mindshare among people with knowledge of Python. Good programmers should have at least a general idea of a lot of the languages that exist. Probably a lot of python programmers know what brainfuck is but that does not mean that any of them have any intention of using it. I know that ruby exists and I did a fair bit of reading on it the same as I have with C#, java etc howevver that just indicates that I am competent not that I want to use those languages. > - Yet unnamed languages are capable of taking Python's place on the food > chain. Yet unnamed asteroid could be about to wipe out all life on the earth since we scan about 5% of the sky. This statement about something unnamed which someday in the future coudl wipe out python is certainly true. If it is a lot better I will probably switch without a second thought.. > - You have to promote your language, grow its market share, to prevent that > from happening. I disagree. > > These analyses are called "sanity" in the Windows world. It's Reality On > The Ground. It's really odd to come to a developer community where people > are insular and freak out about these kinds of pronouncements. It makes > Windows people wonder if Python people are capable of industrial relevancy. > Fortunately, I was pointed to the marketing-python list and I've discovered > that not all Python crowds are the same. Sanity in the windows world is a strange definition from what I can see. There is a lot of proprietary crap that is incompatible with other proprietary crap that changes its formats all the time to make hooking things together nearly impossible. If you stay only with microsoft software you can kludge stuff together to work but it is still a sad situation. You can keep your windows world and if it would make you happy you can also shove it. I will stay in my unix world which has been getting a lot bigger very quickly where buidling solutions that talk together is much more feasible with free software solutions. Linux and other unix variants are where the future is and MS is not. > > The rest of you: wake up! Smell the Windows! There is far more to the world then windows. A lot of custom apps, and server side technologies are used that have nothing to do with windows and are in areas where windows has no existance of any kind. You can't honestly tell me that you can build supercluster apps with windows. From a.neudecker at uni-bonn.de Fri Aug 29 13:58:03 2003 From: a.neudecker at uni-bonn.de (Andreas Neudecker) Date: Fri, 29 Aug 2003 19:58:03 +0200 Subject: method (a, b = '', *c, **d): gets a syntax error? In-Reply-To: <3dqcndZe5u2g4NKiXTWJiA@comcast.com> References: <3F4F644D.2060003@uni-bonn.de> <3dqcndZe5u2g4NKiXTWJiA@comcast.com> Message-ID: Hi. Terry Reedy wrote: > Generaly, when reporting 'I got an error', you should copy the actual > error message. Will do from now. Thanks. > In this case, I presume you got 'SyntaxError: invalid > syntax' for each of your two syntax errors. Exactly. Got one. As Michael Peuser states, the comma behind the last parameter is fine. I am doing this all the time when the list is long and I write it one parameter per line, because it makes swapping order or adding another parameter less error-prone (how often have you forgotten to add the comma to the previous parameter when adding a new 'last one'). > 1. When you make a function call and use **whatever, it must be the > last item in the argument list, just as in a function definition. I knew that. That was what puzzled me. And the pointer of the error message pointed to the comma. So I simply overlooked that I had forgotten the 'def' - what a dumb bug! > Welcom to Python. Enjoy. I do. Used to do some C long, long ago. Python is so much more comfortable ... Regards Andreas From gregbrunet at NOSPAMsempersoft.com Thu Aug 7 12:19:06 2003 From: gregbrunet at NOSPAMsempersoft.com (Greg Brunet) Date: Thu, 7 Aug 2003 11:19:06 -0500 Subject: Static class properties (read-only) Message-ID: In puzzling over classes, I'm wondering if classes can have read-only static properties? I certainly seem to be able to do create static properties like this: class C(object): count = 0 def __init__(self,s): C.count += 1 self.Name = s def __del__(self): C.count -= 1 and C.count should have a count of the number of its instances that have been created. However, someone could set the value directly. I know that using get/set methods, I can make a read-only property at the object/instance level. Can this be done at the class level? Thanks, -- Greg From jacek.generowicz at cern.ch Sun Aug 24 10:43:42 2003 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 24 Aug 2003 16:43:42 +0200 Subject: macro FAQ References: <2259b0e2.0308240103.3966476b@posting.google.com> <87znhzi4k4.fsf@pobox.com> Message-ID: jjl at pobox.com (John J. Lee) writes: > I'm sure you're capable of understanding this position, but the > argument has started going round in circles. As I've said repeatedly: - I do _not_ necessarily advocate the inclusion of macros in Python. - I merely wish to dispel the myth that macros make code less readable[*]: they _ease_ understanding of the code. [*] And they don't fragment languages either. From sismex01 at hebmex.com Fri Aug 8 12:00:48 2003 From: sismex01 at hebmex.com (sismex01 at hebmex.com) Date: Fri, 8 Aug 2003 11:00:48 -0500 Subject: Need elegant way to cast four bytes into a long Message-ID: > From: Skip Montanaro [mailto:skip at pobox.com] > Sent: Viernes, 08 de Agosto de 2003 10:55 a.m. > > wsh> I have been getting what I want in this sort of manner : > > wsh> l = 0L > wsh> l = a[0] > wsh> l += a[1] << 8 > wsh> l += a[2] << 16 > wsh> l += a[3] << 24 > > wsh> but I think that's too wordy. Is there a more intrinsic and > wsh> elegant way to do this? > > You mean like this: > > l = long(a[0] + a[1] << 8 + a[2] << 16 + a[3] << 24) > > You can use struct.unpack as well, though I'd be hard-pressed > to get the details correct. You'd be better off with "pydoc struct". > > Skip > Kinda like this? Python 2.2.3 (#42, May 30 2003, 18:12:08) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information. IDLE 0.8 -- press F1 for help >>> a = [ 0x11, 0x33, 0x66, 0x99 ] >>> import struct >>> I = struct.unpack("=i","".join([chr(i) for i in a]))[0] >>> print I, hex(I) -1721355503 0x99663311 >>> As you can see, this is subject to platform byte-ordering gimmics, but you can force it by changing the "=" in the format string to "<" to force little-endian and ">" for bigger-endian. HTH -gustavo pd: one little, two little, three little endians, ... Advertencia:La informacion contenida en este mensaje es confidencial y restringida, por lo tanto esta destinada unicamente para el uso de la persona arriba indicada, se le notifica que esta prohibida la difusion de este mensaje. Si ha recibido este mensaje por error, o si hay problemas en la transmision, favor de comunicarse con el remitente. Gracias. From jjl at pobox.com Fri Aug 22 09:45:18 2003 From: jjl at pobox.com (John J. Lee) Date: 22 Aug 2003 14:45:18 +0100 Subject: JavaScript web scraping test cases? References: <87ekzg0y6e.fsf@pobox.com> Message-ID: <87zni1ztzl.fsf@pobox.com> jjl at pobox.com (John J. Lee) writes: [...] > Anyway, the point of this post is that I'm looking for pages to test > it on, so if you have a page that you'd like scraped (one that uses > JavaScript in some non-trivial way, of course! -- for dynamically > modifying forms, setting cookies, or whatever), mail me the details: > better that than some randomly-selected site from the Internet. > Obviously, it should be something that doesn't violate any terms & > conditions of use or otherwise cause people trouble, and preferably > that doesn't require any signup. [...] Nobody? I'll get my coat. ;-) John From tjreedy at udel.edu Fri Aug 15 19:33:01 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 15 Aug 2003 19:33:01 -0400 Subject: Dictionary assignment References: Message-ID: "Mark Daley" wrote in message news:mailman.1060987824.17496.python-list at python.org... > format[self.formats.get()][key] = current[key] Above statement assumes 1) that current is a sequence or dict (or instance simulating such) and that the object associated with key is an index or key therein. It retrieves the associated object. It then assumes 2) that format is a sequence or dict (according to whether self.formats.get() returns an int index or dict key) of mutable sequences or dicts (according to the nature of key). After retrieving the appropriate collection, it associates key with the retrieved-from-current object in that collection. > Now, all disgust from my example aside, shouldn't this line cause a new key > (whatever self.formats get() produces) whose contents are an exact copy of > current? The only new 'thing' created is the association between key and current[key] in format[self.formats.get()]. There are no new Python objects created. > BTW, I do this to avoid those location references. No idea of what this means. > I need to get an actual copy Of what? > and this is the only way I can (currently) guarantee it. Nope. Assignment 'creates' bindings (of object to target), not objects or copies thereof. Terry J. Reedy From deets_noospaam at web.de Fri Aug 1 14:06:13 2003 From: deets_noospaam at web.de (Diez B. Roggisch) Date: Fri, 01 Aug 2003 20:06:13 +0200 Subject: Python vs. Perl vs. PHP? References: <7b454334.0307281002.41dae81b@posting.google.com> <87he56bfp8.fsf@flibuste.net> Message-ID: >> Definitely. See here: >> >> http://www.bagley.org/~doug/shootout/craps.shtml > > has somebody tried to run this bench with python2.3 ? I just picked a few (heapsort.python, methcall.python, objinst.python) tests and run them on my local machine using 2.2 and 2.3. The results are that 2.3 seems to need 60-70% of cpu time. Looks good! time heapsort.python2.3 80000 real 0m4.779s user 0m3.540s sys 0m0.000s time heapsort.python2.2 80000 real 0m5.655s user 0m5.510s sys 0m0.030s Mind you: I didn't do a full benchmarking and didn't even try so! Diez From spam at yourself.pl Tue Aug 19 09:56:46 2003 From: spam at yourself.pl (Matthias) Date: Tue, 19 Aug 2003 15:56:46 +0200 Subject: What's better about Ruby than Python? References: <3F41505F.69D18CC8@alcyone.com> Message-ID: Roy Smith wrote: > DEBUG (cout << "I'm a debug statement\n";); > > It looks ugly, but at least it indents correctly. Why not simply DEBUG(cout << "I'm a debug statement\n"); This should work unless you DEBUG does something strange. From tphhec01 at degas.ceu.hu Sat Aug 23 07:13:33 2003 From: tphhec01 at degas.ceu.hu (Csaba Henk) Date: Sat, 23 Aug 2003 11:13:33 +0000 (UTC) Subject: Double symlinking breaks module import Message-ID: Hello! I use Python 2.2.2 on Linux. I met the following issue: Say I have the module mymod and the script myprog.py in /mydir. myprog.py imports mymod. If I create a symlink /foo/myprog2.py -> /mydir/myprog.py, everything works as it should, invoking any of /foo/myprog2.py /mydir/myprog.py work in the same way. But if I create another symlink myprog3.py -> myprog2.py, and then I invoke myprog3.py, I get compliances that mymod is not found. Is it a bug or policy? -- Csaba Set theory is the LSD of mathematics From achrist at easystreet.com Sat Aug 2 20:10:40 2003 From: achrist at easystreet.com (achrist at easystreet.com) Date: Sat, 02 Aug 2003 17:10:40 -0700 Subject: PyChecker work with Python 2.3? Message-ID: <3F2C5300.FA223CBA@easystreet.com> The pychecker site says that pychecker works with versions 1.5 through 2.2. Any reason to expect that 2.3 breaks it? Anyone tried it to see? TIA Al From peter at engcorp.com Wed Aug 13 17:53:26 2003 From: peter at engcorp.com (Peter Hansen) Date: Wed, 13 Aug 2003 17:53:26 -0400 Subject: Determine file type (binary or text) References: <3F3A8275.8B6EE8C4@engcorp.com> <3f3a92a3$0$160$a1866201@newsreader.visi.com> Message-ID: <3F3AB356.76A21F66@engcorp.com> Grant Edwards wrote: > > In article <3F3A8275.8B6EE8C4 at engcorp.com>, Peter Hansen wrote: > > > "Contains only printable characters" is probably a more useful definition > > of text in many cases. > > The definition of "printable" is dependent on the character > set, that will have to be specified. That's why I said "printable (in ASCII)" in another message, so I definitely agree. The problem was rather under-specified. :-) From FBatista at uniFON.com.ar Tue Aug 5 14:42:42 2003 From: FBatista at uniFON.com.ar (Batista, Facundo) Date: Tue, 5 Aug 2003 15:42:42 -0300 Subject: site-packages and linux Message-ID: #- Currently in my linux configuration there seems to be a #- conflict in my python2.2 and 2.3 install. #- I installed recently 2.3 but want to go back for some reason to 2.2. #- All installed packages located in #- ...\python2.2\site-packages are not recognized anymore. #- Well, when importing is not possible, no module found #- error is what I get now. #- #- Without re-installing everything, how can I solve this problem? Tried to copy the modules from ...\python2.2\site-packages to ...\python2.3\site-packages? . Facundo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ADVERTENCIA La informaci?n contenida en este mensaje y cualquier archivo anexo al mismo, son para uso exclusivo del destinatario y pueden contener informaci?n confidencial o propietaria, cuya divulgaci?n es sancionada por la ley. Si Ud. No es uno de los destinatarios consignados o la persona responsable de hacer llegar este mensaje a los destinatarios consignados, no est? autorizado a divulgar, copiar, distribuir o retener informaci?n (o parte de ella) contenida en este mensaje. Por favor notif?quenos respondiendo al remitente, borre el mensaje original y borre las copias (impresas o grabadas en cualquier medio magn?tico) que pueda haber realizado del mismo. Todas las opiniones contenidas en este mail son propias del autor del mensaje y no necesariamente coinciden con las de Telef?nica Comunicaciones Personales S.A. o alguna empresa asociada. Los mensajes electr?nicos pueden ser alterados, motivo por el cual Telef?nica Comunicaciones Personales S.A. no aceptar? ninguna obligaci?n cualquiera sea el resultante de este mensaje. Muchas Gracias. -------------- next part -------------- An HTML attachment was scrubbed... URL: From bgailer at alum.rpi.edu Tue Aug 5 08:39:11 2003 From: bgailer at alum.rpi.edu (Bob Gailer) Date: Tue, 05 Aug 2003 06:39:11 -0600 Subject: check if running under IDLE In-Reply-To: <3f2ec16b$0$285$ba620e4c@reader0.news.skynet.be> Message-ID: <5.2.1.1.0.20030805063828.02b5ae10@66.28.54.253> At 10:26 PM 8/4/2003 +0200, Helmut Jarausch wrote: >I'd like to check a script which needs sys.argv >I haven't seen a method to set this when running the script >in IDLE's shell or editor window. >The only way I've found is to assign (test values) >to sys.argv but only if the script is running under IDLE > >Is there a mean either to set sys.argv without modifying >the script or to check if the script is running under IDLE's >control. This has been discussed a number of times. Check the archive. Bob Gailer bgailer at alum.rpi.edu 303 442 2625 -------------- next part -------------- --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.506 / Virus Database: 303 - Release Date: 8/1/2003 From usenet_spam at janc.invalid Sat Aug 9 07:19:37 2003 From: usenet_spam at janc.invalid (JanC) Date: Sat, 09 Aug 2003 11:19:37 GMT Subject: email client written with python + wxWindows References: <409a56e2.0308062211.456575df@posting.google.com> Message-ID: Gerhard H?ring schreef: > Mahogany has support for Python scripting in the sourcecode, but AFAIR > it hasn't been updated for years. Last Windows binary build is dated 2003-07-15... -- JanC "Be strict when sending and tolerant when receiving." RFC 1958 - Architectural Principles of the Internet - section 3.9 From missive at frontiernet.net Sat Aug 9 18:30:16 2003 From: missive at frontiernet.net (Lee Harr) Date: Sat, 09 Aug 2003 22:30:16 GMT Subject: Imortning histogram References: <009301c35d16$1a3ee8e0$4901a8c0@beastjr> Message-ID: > I have a python script which is using histogram (import Histogram = > )package. Can please some one tell me what all packages I need to = > install for this and where (website??) I can get it. I am new user of = > python so sorry for these basic questions. > Maybe this is it: http://starship.python.net/~hinsen/ScientificPython/ ps. please send only plain text to the list. From jjl at pobox.com Tue Aug 26 16:19:01 2003 From: jjl at pobox.com (John J. Lee) Date: 26 Aug 2003 21:19:01 +0100 Subject: ClientCookie bug (followup) References: <87znibzrnx.fsf@pobox.com> <87oeypdh92.fsf@pobox.com> <87k79a25pi.fsf@pobox.com> <87isos0zng.fsf@pobox.com> <87ptis39kp.fsf@pobox.com> Message-ID: <877k506ukq.fsf@pobox.com> cartermark46 at ukmail.com (Mark Carter) writes: [...] > At the risk of sounding thick ... this doesn't work either! I couldn't > get load_cookie_data() to work using the above template, either. What > seems odd for starters is the line > response = ClientCookie.urlopen(url) > > What makes it odd is that to an offhand observer, there is nothing > visibly connecting the urlopen() command to c. Sure, some fancy stuff [...] D'Oh! def go10(): #works with win xp import ClientCookie c = ClientCookie.MSIECookieJar(delayload=1) c.load_from_registry(username='mcarter') #only need username for win9x opener = ClientCookie.build_opener(ClientCookie.HTTPCookieProcessor(c)) url = 'http://businessplus.hemscott.net/corp/crp03733.htm' response = opener.open(url) print response.info() # headers print response.read() # body All of this is explained in the web page, though. [attempts to looks at web page] Well, it would be if the link weren't broken or I could log in to my SF account to fix it... Sigh. BTW, if you want to use ClientCookie.urlopen rather than opener.open, you can call ClientCookie.install_opener(opener) to install a global opener, just as you would with urllib2. John From adalke at mindspring.com Tue Aug 12 19:54:26 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Tue, 12 Aug 2003 17:54:26 -0600 Subject: Summer reading list References: <5d0_a.288$jw4.85@nwrdny03.gnilink.net> Message-ID: Chad Netzer > Quick heap class (any error corrections are appreciated): > --------------------------------------------------------- > def __init__( self, heap=[] ): make that def __init__(self, heap = None): if heap is None: heap = [] Otherwise, all Heaps created with default args will share the same data. Andrew dalke at dalkescientific.com From aleax at aleax.it Thu Aug 21 04:24:49 2003 From: aleax at aleax.it (Alex Martelli) Date: Thu, 21 Aug 2003 08:24:49 GMT Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> Message-ID: Bengt Richter wrote: ... > This is interesting, because I presume you are happy with properties ;-) Properties AND many other descriptors, sure. The whole descriptors scene is cool, and properties one of the best uses for them so far. > So is this basically a thing about the global namespace? I.e., if > we had way to introduce a subclassed module types into the import > mechanism, we could have module properties, which presumbaly could > be accessed much like parameterless Pascal functions. Nothing stops you from hooking the import mechanism and stuffing class instances in sys.modules -- it's actually very easy in Python 2.3, where your hooks need not interfere with any others (it's just a beautiful new architecture for hooking imports). However, I think the simplicity and predictability of modules plays a useful role. I've occasionally played with putting instances in sys.modules but invariably backed out to simpler solutions for the purpose of putting code in production. So, I'm not sure "smarter modules" (able to play with descriptors transparently) would in fact be an improvement; I'm quite dubious about the issue. Alex From aahz at pythoncraft.com Mon Aug 11 15:30:55 2003 From: aahz at pythoncraft.com (Aahz) Date: 11 Aug 2003 15:30:55 -0400 Subject: Multi-Line Comment References: <4qofjvg3bh9smlnb1do4f0lhjga7bacnu3@4ax.com> Message-ID: In article <4qofjvg3bh9smlnb1do4f0lhjga7bacnu3 at 4ax.com>, Doug Tolton wrote: > >Does it really not have a multi-line comment? I think I must just be >missing something simple and stupid. ''' Most people use triple-quoted strings for multi-line comments. ''' -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From http Sat Aug 23 20:04:05 2003 From: http (Paul Rubin) Date: 23 Aug 2003 17:04:05 -0700 Subject: large-scale app development in python? References: <7xlltkxrcv.fsf@ruckus.brouhaha.com> <87smnsx7y6.fsf@pobox.com> Message-ID: <7xznhzgbuy.fsf@ruckus.brouhaha.com> jjl at pobox.com (John J. Lee) writes: > I've never checked: how many LOC is Zope? I don't remember but the answer has been posted here before. > Of course, one has to remember that lower LOC (by a multiple of 5 or > so, according to some experienced C++, Java and Python developers > here) is one of the very reasons that people choose Python in the > first place, so some sort of correction has to be applied, or a more > sophisticated metric used. No, LOC is not perfect but IMO it's about as indicative as most anything else I can think of. No correction factor should be applied. It could be that a 100 KLOC Python program does more stuff than a comparably sized Java program, but that doesn't mean the Python program is bigger. I think Zope is in the 100 KLOC range within a factor of some small integer. A large application these days may mean 10 MLOC or more. From bdelmee at advalvas.REMOVEME.be Sun Aug 17 15:05:15 2003 From: bdelmee at advalvas.REMOVEME.be (Bernard Delmée) Date: Sun, 17 Aug 2003 21:05:15 +0200 Subject: Path Problem on W2K? References: <93f5c5e9.0308170927.6e0bdc38@posting.google.com> Message-ID: <3f3fd1c8$0$1122$6c56d894@feed0.news.be.easynet.net> > Also tried adding c:\Program Files\Python23 to my path... This should work, though! Still it's advisable to install to a path without space(s), otherwise the "idle" IDE won't work. From gcash at luncheonmeat.cfl.rr.com Wed Aug 6 21:21:36 2003 From: gcash at luncheonmeat.cfl.rr.com (gcash) Date: Thu, 07 Aug 2003 01:21:36 GMT Subject: win32all: buggy IE proxy stuff and execScript() Message-ID: OK, I was writing code using WIN32ALL to do automation scripts for common things we do in IE a lot at work, since grunt-n-point gets very boring after a while. I snarfed the code from which was very useful. (Thanks, Dave!) Finally I get to a beta stage and give it to some of the guys in my group to test, and they get "Access is denied" errors executing the execScript() method, which runs some javascript in the browser context. They're running pretty much the exact same windows install I am, so I beat my head against the wall for a day trying to figure out what's going on. Some people can run things as "Administrator", some folks can run it as their user, some get it to work under both accounts, and some can't get it to work under any account. My machine never had any problems, even when I tried to make it break. I'm using Win2K Pro SP 4 with all the critical patches, Python 2.2.3, and win32all build 156. I thought it was strange that I got NO Google hits on my error message, and no one else was having the problem. I was getting nowhere so I decided to post to comp.lang.python about my problem and see if some bright person had an idea. Not only is this the most coding I've ever done under Windows, but this is probably the most I've USED Windows in years. So I whipped up a short script to demonstrate the problem, and since no one would have access to our internal sites, I used www.python.org as my example site. I wanted to cut'n'paste the error message, so I ran the script on my bosses' machine. AND IT WORKED. I changed the site back to our internal website and it crashed. Obviously this immediately narrows it down to the proxy settings, which I compared to the ones on my machine. It turns out that if the site is listed in the "bypass proxy" list, it becomes a "Local Intranet" site and you get permission errors NO MATTER how you set the permissions for the "Local Intranet" zone. I experimented a lot with this, and I got my machine to finally get permission errors. Obviously a bug, but I didn't find anything in MSDN or MS KB on it. Here's what you need to do as a workaround: 1. Open the "Tools->Internet Options" menu. 2. Select the "Security" tab. 3. Click the "Local Intranet" zone icon. 4. Click the "Sites" button. 5. Uncheck the "Include all sites that bypass the proxy server" item. 6. Hit the "OK" buttons twice. That fixes it by putting these sites into the "Internet" zone, and you have to do this for the Windows user(s) that will be running IE scripts, as it's a per-user thing. It seems that it doesn't matter what the permissions are for the "Internet" zone, as I cranked those all the way up and didn't have any problems. Am I really the first person to run into this? -gc -- The Stones of Ranthenge are written through-and-through, though in an ancient script composed solely of decimal points. There are none who understand these strange inscriptions outside of one order of Monks, who refer to this place as "The Stones That Are Nine-Edge-Down". From hokiegal99 at hotmail.com Sat Aug 2 22:15:52 2003 From: hokiegal99 at hotmail.com (hokiegal99) Date: 2 Aug 2003 19:15:52 -0700 Subject: Determining if a filename is greater than X characters Message-ID: <93f5c5e9.0308021815.44c57a2d@posting.google.com> How would I determine if a filename is greater than a certain number of characters and then truncate it to that number? For example a file named XXXXXXXXX.txt would become XXXXXX fname = files if fname[0] > 6 print fname[0] Thanks!!! From sybrenUSE at YOURthirdtower.imagination.com Tue Aug 26 04:47:33 2003 From: sybrenUSE at YOURthirdtower.imagination.com (Sybren Stuvel) Date: 26 Aug 2003 08:47:33 GMT Subject: Help with regular expressions References: Message-ID: dmbkiwi enlightened us with: > A couple of other people have contributed code to this project, > particularly relating to the parsing of the websites. > Unfortunately, it is not parsing one particular part of the website > properly. This is because it is expecting the data to be in a > certain form, and occasionally it is in a different form. > Unfortunately this causes the entire script to fail to run. You seem to expect old HTML. Why not use XHTML only ('tidy' can convert between them) and use a regular XML parser? Much, much, much easier! And you won't have to be afraid of messing up your regular expressions ;-) Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? From sjmachin at lexicon.net Fri Aug 1 22:08:54 2003 From: sjmachin at lexicon.net (John Machin) Date: 1 Aug 2003 19:08:54 -0700 Subject: Python speed vs csharp References: Message-ID: bokr at oz.net (Bengt Richter) wrote in message news:... > erfcx = ( (a1 + (a2 + (a3 + > (a4 + a5*t)*t)*t)*t)*t ) * exp(-pow(x,2.0)); Wouldn't (x*x) be better than pow(x,2.0) ? From mpeuser at web.de Fri Aug 29 14:29:21 2003 From: mpeuser at web.de (Michael Peuser) Date: Fri, 29 Aug 2003 20:29:21 +0200 Subject: python and webcam?? References: <3F4F56AB.19EFE5AB@engcorp.com> <3F4F6A31.1598071A@engcorp.com> <3F4F91EF.10B944A6@engcorp.com> Message-ID: "Peter Hansen" schrieb im Newsbeitrag news:3F4F91EF.10B944A6 at engcorp.com... > Michael Peuser wrote: > > > > "Peter Hansen" schrieb im Newsbeitrag > > news:3F4F6A31.1598071A at engcorp.com... > > > Mike Kier wrote: > > > > > > > > > > Try this... > > > > http://videocapture.sourceforge.net/ > > > > > > Ah, that's the one. Uses it's own .pyd actually, not calldll as I > > > thought. > > > > > > Doesn't work with my webcam though. Might help if the OP could specify > > > what he has. > > > > > > > Works fine with my lowcost cam (AIPTEK 3M). USB Driver from AIPTEK > > installed - no problems with VideoCapture. Have you tried the AMCAP.EXE in > > folder AMCAP? This is not Pytthon but checks the same interface... > > No point trying. My webcam is an Axis Communications networked camera > which hooks up to Ethernet and responds via HTTP requests. :-) > > I *think*, though I'm not certain, that the term "webcam" is still > generic enough that it doesn't automatically mean a particular > kind of camera that is always hooked up through USB and available > via the VideoCapture driver... > As far as I understand it he uses a standard DirectX (8.0) interface "Device". It is only necessary to provide a proprietary driver which supports this. Probably no chance for *very* legacy hardware.... From wim_wauters at skynet.be Wed Aug 20 17:03:18 2003 From: wim_wauters at skynet.be (WIWA) Date: 20 Aug 2003 14:03:18 -0700 Subject: Python: executing ping and whois Message-ID: <538fc8e.0308201303.46c58c8b@posting.google.com> Hi all, Anybody that could tell me how to execute some Linux commands using Python. The application is that I want to be able from a website to launch a Python script and that python script should be able to ping to the provided IP address, or should do a whois of that IP address. I want to use the existing Linux commands if possible. Anyone has an idea or tutorial? Thanks, From ayc8NOSPAM at cornell.edu Sat Aug 2 19:31:44 2003 From: ayc8NOSPAM at cornell.edu (Andy C) Date: Sat, 02 Aug 2003 23:31:44 GMT Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> <87el06d2i6.fsf@pobox.com> Message-ID: OK, then unless I'm missing something, tabs vs. spaces shouldn't matter for you. The editor should be able to handle tabs in a satisfactory manner as well. > I'm used to a certain minimum standard from my editors, and smart > tabs are one of those things that's part of the price of admission these > days, just like syntax highlighting. A programming editor's job is to help > where it's useful, and get out of the way when it's not. When you want > to indent, you hit the tab button. It's the editor's job to know I want, > for example, four spaces, and deliver them. In Python, it's the editor's > job to know that when I hit return at the end of a line, there are only one > or two legitimate places to put the cursor on the next line, and to put > it in the most likely of them. > > As to the different number of spaces between developers, that's > another thing I'd expect from my editors. It's easy enough in Python > to figure out what's an indent and infer the number of spaces. I'd > expect a decent editor to be able to load a program and tell me > what the indentation policy was! I'd also expect to be able to tell > it to change it, and have it automatically reindent the program for > me. > > John Roth > > From staschuk at telusplanet.net Wed Aug 6 21:43:08 2003 From: staschuk at telusplanet.net (Steven Taschuk) Date: Wed, 6 Aug 2003 19:43:08 -0600 Subject: Bug? If not, how to work around it? In-Reply-To: <060820031458029244%mday@apple.com>; from mday@apple.com on Wed, Aug 06, 2003 at 02:58:02PM -0700 References: <060820031458029244%mday@apple.com> Message-ID: <20030806194308.A4000@tibia.amotlpaa.bogus> Quoth Mark Day: [...] > I'm guessing that iter() is looking for an __iter__ attribute without > going through __getattr__ to find it. [...] Right. This is normal for special methods when invoked by special notations (e.g., __len__ invoked by way of len(), __add__ invoked by way of +, etc.). > [...] So, I tried adding the following > method to the Test class: > > def __iter__(self): > return self.__obj.__iter__ Well, you have to actually call __iter__ to get the iterator: def __iter__(self): return self.__obj.__iter__() (This makes iter(testobj) not quite the same as iter(testobj.__obj) for new-style instances, mind you.) -- Steven Taschuk staschuk at telusplanet.net "Telekinesis would be worth patenting." -- James Gleick From nospam at maniacxs.de Tue Aug 12 15:45:41 2003 From: nospam at maniacxs.de (Lukas Kasprowicz) Date: Tue, 12 Aug 2003 21:45:41 +0200 Subject: German umlaut in a string. References: Message-ID: Hi Leszek, When I create a string with ="String" It works! But I have a string that was converted from a tuple to a string. In this case it doesen?t work. I can substitute everything from the String that was converted from a tuple except the german umlaut. I take the tuple from a database and i get all the umlaut from there as "\\x" Changing is NOT possible with "re.sub" This was my fault... in the variable "test" i have written in the first tread there is only one backslash!!!!!!!!!! greetz Lukasz Leszek Krupi?ski wrote: > It works for you? > >>>> test = "some\\xf6thing" >>>> print re.sub("\\xf6", "%F6", test) > some\xf6thing > > (Python 2.3) > >>>> exclusion = "some\xf6thing" >>>> exclusion = re.sub("\\xf6", "%F6", exclusion) >>>> print exclusion > some%F6thing > > I believe that problem is in slashes. > > Leon -- --------------------------------------------------------- Das einzige Mittel gegen Aberglauben ist Wissenschaft. (Henry Thomas Buckle) From skip at pobox.com Tue Aug 26 09:10:47 2003 From: skip at pobox.com (Skip Montanaro) Date: Tue, 26 Aug 2003 08:10:47 -0500 Subject: Python MySQLDump Scripts In-Reply-To: References: Message-ID: <16203.23639.819369.665279@montanaro.dyndns.org> Gavin> I've done a bit of search on the web for python scripts to Gavin> automate the backup of MySQL databases but haven't had much Gavin> success. I've come across a decent PERL module and are thinking Gavin> about porting that, however I just wished to see if anyone has Gavin> any snippets available prior to taking this path. I do have Gavin> specific criteria however I'm just wishing to see in general what Gavin> people have done and what solutions may be available. Gavin, What sort of automation are you interested in? Knowing only a single database on the server, it seems to me you could do something like this: conn = MySQLdb.connect(...to 'mysql' database...) c = conn.cursor() c.execute("show databases") # iterate over all databases for (db,) in c.fetchall(): # probably want an os.path.join(BASE, db) here, where BASE is # perhaps date-related or cycles through a fixed set of backup # directories os.mkdir(db) # second connection to specific database conn2 = MySQLdb.connect(...to db...) c2 = conn2.cursor() c2.execute("show tables") # iterate over all tables in db, dumping as we go for (tbl,) in c2.fetchall(): c3 = conn2.cursor() fn = os.path.join(BASE, db, tbl) + ".dump" try: os.unlink(fn) except OSError: pass c3.execute("select * from %s into outfile '%s'" % fn) Skip From romany at actimize.com Mon Aug 25 03:42:40 2003 From: romany at actimize.com (Roman Yakovenko) Date: Mon, 25 Aug 2003 10:42:40 +0300 Subject: Comments on my "Python Introduction" slides Message-ID: <91BFE89EFFA2904E9A4C3ACB4E5F2DF5027B0A@exchange.adrembi.com> Hi. In slide 7 why not to use set instead of dictionary? In slide 9: to give a list as example may be not a good idea: list has reverse method In slide 12: Boost.Python I think it is a must to give a reference on it. Nice work. Roman > -----Original Message----- > From: Miki Tebeka [mailto:tebeka at cs.bgu.ac.il] > Sent: Monday, August 25, 2003 6:54 AM > To: python-list at python.org > Subject: Re: Comments on my "Python Introduction" slides > > > Hello Irmen, > > > > Should be http://www.cs.bgu.ac.il/~tebeka/pyintro.htm > > > > I'm sorry to say this but because the site appears to > > be made in Powerpoint, and then exported to MSHTML, > > it sucks in my browser (Mozilla). No cigar. > Sorry. Sadly we work on MS environment... > > Thanks for your time. > Miki > -- > http://mail.python.org/mailman/listinfo/python-list > From cjw at sympatico.ca Sat Aug 9 16:03:51 2003 From: cjw at sympatico.ca (Colin J. Williams) Date: Sat, 09 Aug 2003 16:03:51 -0400 Subject: % Documentation In-Reply-To: <87y8y2lq84.fsf@flibuste.net> References: <87y8y2lq84.fsf@flibuste.net> Message-ID: Wilk wrote: > Simon Bayling writes: > > >>Hello, >> >>Where is the % operator documented? > > > http://www.python.org/doc/current/lib/typesseq-strings.html > > >>I was looking for ages yesterday, Python.org, browsing the documentation >>for modules, the tutorial, searching for it, trying help(%), using Google, >>and so on. >>I found that locale.format works like the % operator... how useful ;) >> >>if someone could point me towards it, that would be great... >> >>(Also, what is the proper name for it? String interpolation? String >>substitution? Percent-substitution?) >> >>Cheers, >>Simon. > > I think of it as formatting, but its probably the other things too. The description can be easily reached from the start of the Library Reference index - under Symbols. It is now also indexed under formatting. Colin W. From mwilson at the-wire.com Sun Aug 31 00:03:29 2003 From: mwilson at the-wire.com (Mel Wilson) Date: Sun, 31 Aug 2003 00:03:29 -0400 Subject: My script is taking 12 hours+ any suggestions? References: <3f4ff9f8$0$23588$5a62ac22@freenews.iinet.net.au> Message-ID: In article <3f4ff9f8$0$23588$5a62ac22 at freenews.iinet.net.au>, Ideasman wrote: >Hi I have a made a script that process normals for a flat shaded 3D mesh's. >It compares every vert with every other vert to look for verts that can >share normals and It takes ages. > >I'm not asking anyone to rewrite the script- just have a look for any >stupid errors that might be sucking up time. I don't know for sure, but a few things look suspicious. - Keeping a list of line numbers of lines that have been looked at. When you do this, an expression like if newCompareLoopindex not in listOfDoneLines: means a sequential search of the list every time. A set of processed lines, or a dictionary keyed by the line numbers of processed lines might be faster. Another alternative, if you can spare the memory, would be a list isProcessed = [0]*fileLen where you set isProcessed[lineIndex] = 1 as the line is processed, and change the test mentioned above to simply if isProcessed[newCompareLoopindex]: - keeping all the input data in string form and splitting the line each time it's used must be taking time. (The alternative has dangers too, if unpacking all the lines exceeds your memory, then you could trade 12 hours unpacking data lines for 12 hours on the swap file) - the line if [comp1[0], comp1[1], comp1[2]] == [comp2[0], comp2[1], comp2[2]]: results in building two brand new lists, comparing their contents, then throwing them away. It might be better to code if comp1[0] == comp2[0] and comp1[1] == comp2[1] and comp1[2] == comp2[2]: - many str calls to convert things that are already strings (as far as I can tell), although this will probably be a very small saving. - as somebody else said, we don't know what kind of code is being `eval`ed, maybe your problem just takes 12 hours to solve. Good Luck. Mel. From bh at intevation.de Tue Aug 5 12:05:55 2003 From: bh at intevation.de (Bernhard Herzog) Date: Tue, 05 Aug 2003 18:05:55 +0200 Subject: Capture PID of child process References: <6qr8403xh2.fsf@salmakis.intevation.de> Message-ID: <6qn0eo3x98.fsf@salmakis.intevation.de> Bernhard Herzog writes: > Alternatively you could use a list of strings as the command so that no > shell is used in the first place, i.e. "prog param" would become > ["prog", "param"]. This approach has the advantage that you don't have > to worry about shell quoting but it's less portable because it's not > even documented (I'll file a bug report for that). As it turns out, there already is a bug report: http://python.org/sf/666700 Bernhard -- Intevation GmbH http://intevation.de/ Sketch http://sketch.sourceforge.net/ Thuban http://thuban.intevation.org/ From bokr at oz.net Thu Aug 7 20:54:54 2003 From: bokr at oz.net (Bengt Richter) Date: 8 Aug 2003 00:54:54 GMT Subject: Python's biggest compromises References: Message-ID: On Wed, 06 Aug 2003 22:57:26 GMT, Carl Banks wrote: >Alex Martelli wrote: >> "Ada", on the other hand, being the start of "Adam", might claim >> older genesis. > >I disagree. Ada refers to a specific person, Ada Lovelace, who lived >in the 19th century, and was credited as the world's first programmer. >Python, Pascal, Java, and C (which goes back to the Etruscans, at >least) all predate Ada. > The world's first programmer was Eve, when she gave Adam a list of things to do ;-) Real time programming emerged when she told him to what to do when, in order to get all the food served hot at the same time ;-) Regards, Bengt Richter From sanctuary at terra.es Sat Aug 23 13:10:58 2003 From: sanctuary at terra.es (rix sanctuary) Date: Sat, 23 Aug 2003 17:10:58 GMT Subject: help!: modpython, howto pass results to a running php script? Message-ID: Hi there! Have a python calculation module and I would like to include the results in a seperate Php script. My code runs in a box with Apache/2.0.47(win32) mod_python/3.0.3 Python 2.2.3 Php/4.3.2 My python module is called from a php script like this: Is there an easy way to use in my php script as local variables the results yield by my python module? Thanks in advance rix From donot at likespam.com Wed Aug 27 21:20:51 2003 From: donot at likespam.com (Rich) Date: Wed, 27 Aug 2003 18:20:51 -0700 Subject: learning to program References: <3F4CED6E.D04D35D6@engcorp.com> <5bspkv87u1q0v9aupajrrkjuutuh3f5o44@4ax.com> <3F4CF363.CAF6A14E@engcorp.com> <6b2qkv4nf549o8clg3bagphd02f92dadub@4ax.com> <3F4D0AC2.EE79D7E4@engcorp.com> Message-ID: I am going through one of the tutorials on the Python site and have ran into a problem. During the tutorial it talked about TCI, and gave some commands to do. I went to the site and downloaded TCI. but was unable to do any of the tasks. I think my question is, when the tutorial say the Dos prompt, do I use my Dos prompt in windows, or the Dos prompt in the Python program? I am using the Tutorial by Alan Gauld, and I am at the bottom of simple sequences (left side of page). On Wed, 27 Aug 2003 15:47:14 -0400, Peter Hansen wrote: >Rich wrote: >> >> On Wed, 27 Aug 2003 14:07:31 -0400, Peter Hansen >> wrote: >> >> >Rich wrote: >> >> >> >> This is the only post I am able to see, sorry about re posting. I >> >> thought if I changed the subject heading I might be able to see the >> >> post. >> > >> >You should be able to see the replies that you missed via Google Groups, >> >as soon as they are indexed and on the web: >> How long does it usually take to post on Google? > >In my experience, usually quite a few hours (maybe four or more?). Right >now I can see posts there which I read only a short time before seeing >yours, so that estimate feels about right. > >(By the way, it would be helpful if, when you quote material in a post >to which you're replying, if you used whitespace to separate your >own text from the quoted material. I almost didn't see your message >at all, thinking you'd accidentally posted an empty reply. Thanks. :-) > >-Peter From peter at engcorp.com Thu Aug 28 09:03:48 2003 From: peter at engcorp.com (Peter Hansen) Date: Thu, 28 Aug 2003 09:03:48 -0400 Subject: learning to program References: <3F4CED6E.D04D35D6@engcorp.com> <5bspkv87u1q0v9aupajrrkjuutuh3f5o44@4ax.com> <3F4CF363.CAF6A14E@engcorp.com> <6b2qkv4nf549o8clg3bagphd02f92dadub@4ax.com> <3F4D0AC2.EE79D7E4@engcorp.com> Message-ID: <3F4DFDB4.B89557FA@engcorp.com> Rich wrote: > > I am going through one of the tutorials on the Python site and have > ran into a problem. > > During the tutorial it talked about TCI, and gave some commands to do. > I went to the site and downloaded TCI. but was unable to do any of > the tasks. > > I think my question is, when the tutorial say the Dos prompt, do I use > my Dos prompt in windows, or the Dos prompt in the Python program? DOS means DOS, which is only the Windows prompt. The Python prompt would always be called such, or "the interpreter prompt". I don't know anything about TCI, sorry. For more effective responses, start a new thread when you have a new question rather than replying to an existing message. That way others, who may already have "killed" this thread (i.e. will not see any more messages linked to the first one you posted) will see your question and have a chance to reply. (Also consider your subject line and try to create a descriptive one, rather than generic titles.) -Peter From timr at probo.com Tue Aug 26 01:44:38 2003 From: timr at probo.com (Tim Roberts) Date: Mon, 25 Aug 2003 22:44:38 -0700 Subject: crazy programming language thoughts References: Message-ID: "Ryan Lowe" wrote: > >one of the things i love about python is its use of the actual words >or/and/not/is/in, where other languages would use symbols ||/&&/?!@#$%, what >have you. The "other languages" thing is a little one-sided. C and C++ are really the only mainstream languages to use symbols for these constructs. Pascal and Algol use the words or/and/not/is/in, as well as begin/end instead of {}. >the basic concept would be to use identifying words in front of the >arguments to determine their identity as well as making the function call >read more like an english phrase. for instance, take the simple python >statement: > >>>> vtext.replace('a', 'b') > >wouldnt it be nicer (more english-like at least) to say: > >>>> replace 'a' with 'b' in vtext You should check out REXX, the primary scripting language for OS/2. That line could have been taken from a REXX script practically unmodified. -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From sross at connectmail.carleton.ca Thu Aug 21 21:35:18 2003 From: sross at connectmail.carleton.ca (Sean Ross) Date: Thu, 21 Aug 2003 21:35:18 -0400 Subject: crazy programming language thoughts References: Message-ID: "Ryan Lowe" wrote in message news:gDd1b.147992$_R5.55948990 at news4.srv.hcvlny.cv.net... > i just want to say that i know i saw a similar idea in another language, a > few years ago, but damned if i remember where or what language. i guess the > language didnt make it:( but if anyone knows a language like this, PLEASE > let me know. Hi. This may not be the language you're trying to recall but it is a language that uses English syntax: "AppleScript" Check it out here: http://developer.apple.com/documentation/AppleScript/Conceptual/AppleScriptLangGuide/index.html Unfortunately, it's only available on the Mac. I've actually made a language very much like AppleScript. However, before you get excited, that language was designed for a *very* specific purpose, and you *cannot* use it for general programming of *any kind*. That being said, the code is available at: http://chat.carleton.ca/~sross It was written in Python using SPARK - extending SPARK's included Python 1.5.2 grammar example. The code is not great: it was written during a course at which time I was just learning Python, SPARK, and the steps involved in moving from source to executable. (I don't know if I ever want touch it again ... ). Anyway, if you're interested, it's there. Maybe you can whip a toy version of AppleScript. I'd like to (seriously), but I haven't any time - the fall semester is coming up quickly. Maybe after I've finished school ... Hope that helps, and, if you do make a toy AppleScript, please let me know about it! Sean From ken at perfect-image.com Wed Aug 20 13:41:29 2003 From: ken at perfect-image.com (Ken Godee) Date: Wed, 20 Aug 2003 10:41:29 -0700 Subject: "_pg" (Postgresql) module for win32 In-Reply-To: References: Message-ID: <3F43B2C9.20608@perfect-image.com> > In article , User At Domain Dot Invalid wrote: > > >>Where can I find "_pg" module for postgresql? I would prefer a module >>not intedend for "cygwin","mingw" or some thing similar to that. > > > pyPgSQL has a win32 binary available for download: > > http://pypgsql.sourceforge.net/ > > Dave Cook I use psycopg on linux and just recently found a psycopg win32 binary for python 2.1,2.2,2.3 at..... http://www.stickpeople.com/projects/python/psycopg/ pypgsql or psycopg are the only win32 I know of. Ken From pythonguy at Hotpop.com Thu Aug 21 14:18:11 2003 From: pythonguy at Hotpop.com (Anand Pillai) Date: 21 Aug 2003 11:18:11 -0700 Subject: Weird Problem References: <0HY0b.24239$Cd2.10527@nwrdny01.gnilink.net> Message-ID: <84fc4588.0308211018.767fec3f@posting.google.com> Dont forget that 'input' is a keyword in python. It is used to accept user inputs as illustrated below. r=input("Write your name here: ") print r Maybe the interpreter is getting confused with your variable and the keyword "input". My suggestion... try a different variable name other than . Just guessing of course, since I can find no problem with the code as such. -Anand "Andrew Dalke" wrote in message news:... > Carl Banks: > > BTW, you don't know this, but since you're using 2.3, you should > > probably start using "file" instead of open: > > Something I rather don't like given how much old code I have > which uses 'file' as a variable. Ditto for quite a few pieces of the > standard library. > > Andrew > dalke at dalkescientific.com From cnetzer at sonic.net Thu Aug 21 03:00:15 2003 From: cnetzer at sonic.net (Chad Netzer) Date: Thu, 21 Aug 2003 00:00:15 -0700 Subject: Tkinter program crashes In-Reply-To: <221d8dbe.0308140955.658000d0@posting.google.com> References: <221d8dbe.0308140955.658000d0@posting.google.com> Message-ID: <1061449215.1871.10.camel@adsl-209.204.179.133.sonic.net> On Thu, 2003-08-14 at 10:55, srijit at yahoo.com wrote: > Hello, > > Any idea - why the following code crashes on my Win 98 machine with > Python 2.3? > self.button = Button( > frame, text="QUIT", fg="red", command=frame.quit Rather than "frame.quit", could you try "sys.quit", to see if it makes a difference? -- Chad Netzer From aleax at aleax.it Thu Aug 7 14:13:15 2003 From: aleax at aleax.it (Alex Martelli) Date: Thu, 07 Aug 2003 18:13:15 GMT Subject: Gmpy References: <8578e2c1.0308070630.5fb70c22@posting.google.com> Message-ID: <%EwYa.29297$an6.1024220@news1.tin.it> Gary Herron wrote: ... > Python has (arbitrarily) long integer support built right in. For Oh yes (it's the one bit that initially most attracted me, because I needed to do some combinatorial-arithmetic computations...), and it's become even better (faster) in 2.3, with Karatsuba's algorithm for multiplication. However...: > instance: > >>>> ((2**10)**10)**10 > 10715086071862673209484250490600018105614048117055336074437503883703510511249361224931983788156958581275946729175531468251871452856923140435984577574698574803934567774824230985421074605062371141877954182153046474983581941267398767559165543946077062914571196477686542167660429831652624386837205668069376L [alex at lancelot Lib]$ python timeit.py '((2**10)**10)**10' 10000 loops, best of 3: 98.5 usec per loop [alex at lancelot Lib]$ python timeit.py -s'import gmpy' '((gmpy.mpz(2)**10)**10)**10' 100000 loops, best of 3: 6.47 usec per loop ...gmpy's still way faster (at least on my Athlon machine -- I did originally choose AMD over Intel essentially by benchmarking the two possibilities on some heavy computations with GMP...), for this kind of computation. This kind of speed improvement, one of more than an order of magnitude, sometimes makes the difference between a project being feasible or unfeasible, if computations of this kind are right on a program's bottleneck. So, gmpy still has a place, IMHO. Alex From krzysztof at py142.wroclaw.sdi.tpnet.pl Thu Aug 21 05:18:38 2003 From: krzysztof at py142.wroclaw.sdi.tpnet.pl (Krzysztof Kaczkowski) Date: Thu, 21 Aug 2003 11:18:38 +0200 Subject: wxTreeCtrl not wxListCtrl References: Message-ID: Hello Im having problem, my class inherit in wxTreeItemData. (Python2.3 i wxPython2.4.1.2u) class MyTreeItemData (wxTreeItemData): def __init__(self, name): wxTreeItemData.__init__(self) self.name_key = name def TEST(): pass part my class MywxListCtrl inherit in wxTreeCtrl: item_data = MyTreeItemData('Test') itm = self.AppendItem(a1, a2, -1,-1,item_data) print dir(self.GetItemData(itm)) and my problem: Function dir(self.GetItemData(itm)) not list MyTreeItemData, MyTreeItemData not assign, dir(...) list only default class wxTreeItemData why? > print dir(self.GetItemData(itm)) ['Destroy', 'GetClassName', 'GetData', 'GetId', 'SetData', 'SetId', '__doc__', '__init__', '__module__', '__repr__', 'this', 'thisown'] >print dir(item_data) ['Destroy', 'GetClassName', 'GetData', 'GetId', 'SetData', 'SetId', 'TEST', '__doc__', '__init__', '__module__', '__repr__', 'name_key', 'this', 'thisown'] Thank you. From theller at python.net Thu Aug 14 15:25:36 2003 From: theller at python.net (Thomas Heller) Date: Thu, 14 Aug 2003 21:25:36 +0200 Subject: py2exe problem References: Message-ID: "Bror Johansson" writes: > When using py2exe to convert a Python program into an executable: > > Everything works fine when my.py-files reside in a directory on a local disk > > but > > after having copied the .py-files to a ClearCase dynamic view located on a > server machine and having checked them in, I get this error when executing > the file built by py2exe (trace output from execution of py2exe is the same > in both cases): > > KeyError: Scripts.py2exe\support.py > > Python 2.2, py2exe-0.3.4, Win"K > > Any idea, anyone? I cannot really understand what you're asking, and I don't know what a ClearCase dynamic view is. Hm, maybe an idea: distutils (and thus py2exe) doesn't really work if you use absolute pathnames. The script should be in the same directory (or a subdirectory, maybe) as the setup.py file, and the 'python setup.py py2exe' command should be executed in this directory. Thomas From mwh at python.net Thu Aug 14 08:12:57 2003 From: mwh at python.net (Michael Hudson) Date: Thu, 14 Aug 2003 12:12:57 GMT Subject: CLI+GUI References: <2259b0e2.0308080948.5a95e383@posting.google.com> <2259b0e2.0308121335.7f1ad18a@posting.google.com> Message-ID: <7h31xvo5ti9.fsf@pc150.maths.bris.ac.uk> mis6 at pitt.edu (Michele Simionato) writes: > I will later try it on Windows 98. Dunno exactly what "dooneevent" > is doing, "man Tk_DoOneEvent" Cheers, mwh -- I appear to have caused some confusion. Excellent. -- JoeB, asr From missive at frontiernet.net Sun Aug 24 18:54:47 2003 From: missive at frontiernet.net (Lee Harr) Date: Sun, 24 Aug 2003 22:54:47 GMT Subject: A strange behavior of list.extend() References: <420ced91.0308241311.734cbc9c@posting.google.com> Message-ID: In article <420ced91.0308241311.734cbc9c at posting.google.com>, sdhyok wrote: > I think the two script should produce the same results, but not. > Why? > > ---------------- Script #1 > ls = [1] > ls.extend([2,3]) > print ls > -> [1,2,3] > > --------------- Script #2 > ls = [1].extend([2,3]) > print ls > -> None > a_list.extend returns None, not a_list. It is the same as the way a_list.sort works. From adalke at mindspring.com Mon Aug 18 20:16:07 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Mon, 18 Aug 2003 18:16:07 -0600 Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> <6dj2kv8ugkieehs7guh786cl40o5lj6mcs@4ax.com> Message-ID: Doug Tolton > I don't agree at all. Yes when you are defining a macro you are in > essence defining a new mini-language. This is perhaps one of the most > powerful features of Lisp. Programming closer to the application > domain, *greatly* enhances both the readability and the reusability of > code. For that domain. And rarely does the author of a package, much less a macro, understand "the domain as understood by other people" vs. personal understanding. This topic has come up before. Laura Creighton made several comments on macros, the most notable of which is: lac: ] Writing your own Lisp Macro System is better than sex. I ] _know_ -- 18 year old me turned down _lots_ of opportunities ] for sex to go hack on her macro system. Thus if we introduce ] this to the language, I think that it is _inevitable_ that we will ] fragment the Python community into a plethora of mutually ] unintelligble dialects. I don't want this. Thus I don't want a ] macro facility in the language _because_ it would be so cool. > That doesn't mean it *shouldn't* be available [in Python]. > Python is Open Source, how would someone writing a > Macro lock you in? Just don't use the macro. Another writing from Laura seems relevant: http://mail.python.org/pipermail/python-list/2001-May/042102.html My interepretation - I don't customize my apps, nor even my .cshrc (except for one alias (alias ls 'ls -l \!* | grep ^d') an 'unset noclobber', 'set ignoreeof', and the PATH and LD_LIBRARY_PATH - and I wish I didn't need those) I don't, because I don't like to think. At least not spend my time puzzling out slight changes. I like my changes either none or a lot, that is, use Python as-is or write a converter (or use another language). > Just like anything else, Macro's can be over used and abused. However > I maintain that if you don't see the usefulness of macros, you don't > really understand them. That's not the argument against them. It's that they are too useful, each person makes their own dialect, the community breaks down as the different branches do their own thing, and one person's so- called "Python" code looks different than another's. I know I am nowhere near as good a language designer as Guido, Larry Wall, Matz, and the others, though I think I'm pretty decent. I don't have the essential hubris to say that I know better how to tweak Python-the-language to fit my own domain. > Essentially using Python over Machine > language is just using one big ass macro language. You confuse two meanings of the word 'macro' here. Any assembly language worth its salt has "macros", which are pre-assembled sets of code. Use the macro and it generates the code. But you can't use those macros to rewrite the actual language like you can with hygenic macros. It doesn't have the proper tail-biting recursive nature. Andrew dalke at dalkescientific.com From peter at engcorp.com Wed Aug 20 14:22:46 2003 From: peter at engcorp.com (Peter Hansen) Date: Wed, 20 Aug 2003 14:22:46 -0400 Subject: ascii2dec References: Message-ID: <3F43BC76.BBF90F69@engcorp.com> Uwe Mayer wrote: > > Uwe Mayer wrote: > > > this must sound stupid to you, but I'm ages out of Python and I just can't > > find a function to convert 4 bytes of binary data to an integer value: > > > > length=f.read(4) # get length in binary > > length=socket.htonl(length) # swap bytes > > > > #convert 4 bytes to integer > > Sorry, socket.htonl(...) already expects a number, so its: > > > #convert 4 bytes to integer > > length=socket.htonl(length) # swap bytes > > i.e. > How to convert: > > length = '\x01\x00\x00\x00' > > to an integer Use the struct module, with appropriate "endianism". -Peter From tebeka at cs.bgu.ac.il Sun Aug 24 10:44:34 2003 From: tebeka at cs.bgu.ac.il (Miki Tebeka) Date: 24 Aug 2003 07:44:34 -0700 Subject: Comments on my "Python Introduction" slides References: <33803989.0308240000.35b9bf1f@posting.google.com> Message-ID: <33803989.0308240644.3090f039@posting.google.com> Hello Anton, > >http://www.cs.bgu.ac.il/~tebeka/pyintro.html > > This got me a 404. Ooops, a slip of the finger. Should be http://www.cs.bgu.ac.il/~tebeka/pyintro.htm Thanks. Miki From gh at ghaering.de Thu Aug 21 07:11:00 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Thu, 21 Aug 2003 13:11:00 +0200 Subject: MySqlDB Question - CompatMySqlDB is all I can find ? In-Reply-To: <282f826a.0308210238.11ef6a97@posting.google.com> References: <282f826a.0308210238.11ef6a97@posting.google.com> Message-ID: <3F44A8C4.1060807@ghaering.de> Richard Shea wrote: > Hi - I've just downloaded mysqldb for 3.2. After running the install I > find that I can't import mysqldb. When I looked in the directory > mysqldb was installed into the only modules visible are > _mysql_exceptions.py and CompatMySqlDB.py. So i tried importing > CompatMySqlDB and that works fine ... > > >>>>import CompatMysqldb >>>>import Mysqldb > > Traceback (most recent call last): > File "", line 1, in ? > ImportError: No module named Mysqldb > > > ...trouble is I read in this group that I'm not meant to be using > CompatMysqldb so what am I doing/have done wrong ? > > I got mysqldb as a binary from ... > > http://ghaering.de/python/unsupported/MySQL-python.exe-0.9.2.win32-py2.3.exe The binary works fine, I just downloaded it from my homepage, installed and tested it (well, "import MySQLdb" works, that's all I tested). Otherwise I have no idea what you could have done wrong. Be sure to delete Lib/site-packages/MySQL* after you uninstall and before reinstalling it. Maybe there's a permission problem if you installed it before under a different Windows account ... -- Gerhard From ghowland at lupineNO.SPAMgames.com Sat Aug 23 11:53:05 2003 From: ghowland at lupineNO.SPAMgames.com (Geoff Howland) Date: Sat, 23 Aug 2003 15:53:05 GMT Subject: Modifying the {} and [] tokens References: Message-ID: On Sat, 23 Aug 2003 07:53:44 -0400, "John Roth" wrote: > >"Geoff Howland" wrote in message >news:mtqdkv8sdrmgrn02vugnbpuhtjsgel3ohb at 4ax.com... >> I want to modify the {} and [] tokens to contain additional >> functionality they do not currently contain, such as being able to add >> dicts to dicts, and other things that would be very helpful for me and >> my team mates to have. > >Literals (and those are literals) are hard coded at the parser level, >and are not availible to change - unless, of course, you want to >change the source. Dont want to do that, thanks. -Geoff Howland http://ludumdare.com/ From damien.wyart at free.fr Thu Aug 28 11:03:14 2003 From: damien.wyart at free.fr (Damien Wyart) Date: Thu, 28 Aug 2003 17:03:14 +0200 Subject: Celebrity advice References: <3F4CD2A2.DE7D05D2@engcorp.com> <23891c90.0308280317.ac68b38@posting.google.com> Message-ID: <3f4e19b3$0$254$626a54ce@news.free.fr> * "A.M. Kuchling" in comp.lang.python: > * ESR started out pretty well: "CatB", whatever its flaws might > be, is a useful set of observations. [...] But... none of the > followup essays were as notable, and he hasn't developed anything > very impressive (fetchmail is useful, but not tremendously > impressive). What about his forthcoming "taoup"* ? Proofreading by several important people from the Unix world should make it quite solid, I think. And there is a section about Python... :) * http://catb.org/~esr/writings/taoup/ -- Damien Wyart From bdelmee at advalvas.REMOVEME.be Tue Aug 5 16:08:02 2003 From: bdelmee at advalvas.REMOVEME.be (Bernard Delmée) Date: Tue, 5 Aug 2003 22:08:02 +0200 Subject: Unable to run IDLE from 2.3? References: <1akviv4cpectdogklmuupg7rc37lhe1pc7@4ax.com> <3f2fefc8$0$6527$6c56d894@sisyphus.news.be.easynet.net> <9j20jv0v49gmud6kvtadl63l313biv6ctd@4ax.com> Message-ID: <3f300e8f$0$6526$6c56d894@sisyphus.news.be.easynet.net> > It appears the fact that I also have ruby installed is causing the > problem? Should I uninstall ruby, do you think, and try re-installing > python? I'd prefer to have access to both of them, but Python is the > language I want to concentrate on at present. I seem to recall ruby defines tcl/tk related environment variables which may interfere with python. If you are not using ruby-tk, I don't think you need to de-install but merely un-defining those variables should correct the situation. I think that's what I did long ago so I don't see those variable names myself, and can't be more specific.... HTH, Bernard. From bgailer at alum.rpi.edu Mon Aug 18 17:46:05 2003 From: bgailer at alum.rpi.edu (Bob Gailer) Date: Mon, 18 Aug 2003 15:46:05 -0600 Subject: Py2.3: Feedback on Sets In-Reply-To: <3F411A93.70807@users.ch> References: <%BX%a.4999$N37.3051@nwrdny02.gnilink.net> <7h3d6f3143s.fsf@pc150.maths.bris.ac.uk> Message-ID: <5.2.1.1.0.20030818154239.02c863c0@66.28.54.253> > > I'm not sure why multiplying a list by a negative number produces the > > empty list instead of an exception, though. Actually the list has a negative # of elements in it. It is just hard to show this using repr. But each of these elements uses a negative amount of memory, so there is more RAM available for the rest of your program. You just have to avoid specifying a negative # too large in magnitude, or you will get a memory underflow. Bob Gailer bgailer at alum.rpi.edu 303 442 2625 -------------- next part -------------- --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.506 / Virus Database: 303 - Release Date: 8/1/2003 From david at fielden.com.au Fri Aug 22 00:33:16 2003 From: david at fielden.com.au (DG) Date: Fri, 22 Aug 2003 14:33:16 +1000 Subject: Problems with python-list? In-Reply-To: <20030821025311.GE1695@incise.org> Message-ID: <008001c36866$827897c0$5401a8c0@borg.fielden.com.au> I am finding of late that there is almost a 1:1 ratio between actual posts about Python, and messages about virii in emails or responses from auto-responders. Dave > On Wed, Aug 20, 2003 at 07:32:52PM -0700, Dave Brueck wrote: > > Is anybody else having problems sending email to > > python-list at python.org? About 48 hours ago or so my posts stopped > > making it to the list (I usually post via the mailing list > rather than > > to the Usenet group). > > Yeah, I replied to the thread about tracing the hierarchy of function > calls, but it either didn't get to python.org, or it didn't > get back to > me, because I never saw the reply come up. (Err, wait, I see you're > posting via google, hmm, let's see if this gets to the list or not) > > -- > m a c k s t a n n mack @ incise.org http://incise.org > If you had any brains, you'd be dangerous. From theller at python.net Mon Aug 4 14:23:09 2003 From: theller at python.net (Thomas Heller) Date: Mon, 04 Aug 2003 20:23:09 +0200 Subject: packaging windows services? References: <18xXa.94652$852.21935@twister.nyc.rr.com> Message-ID: <8yq9cmeq.fsf@python.net> max writes: >> No need to use cvs, just download the patch and use a patch.exe utility >> for windows ;-) Search the internet to find one, and find out how to use >> it. > > got that, now I am getting 'unexpected end of hunk on line 31'. I get the same ;-(. Since I at the moment have no time to work on this, maybe you can contact the original submitter of the patch (Mark Millikan), and ask him for his patched file? Thanks, Thomas From sscherer at rocketmail.com Thu Aug 21 21:20:21 2003 From: sscherer at rocketmail.com (Bgc) Date: 21 Aug 2003 18:20:21 -0700 Subject: Using the C Source Code from Tcl/Tk Message-ID: Hello All, I've been struggling for years now trying to come up with a solution to a very personal programming problem with Python. I'm an educational programmer, and I make applications that are used in educational environments by nontechnical folks. I therefore need GUIs that are pretty, easy to use, and cross platform (win, mac, linux, unix). In my search for a GUI, I've also come to the conclusion that as much as I love Python, the GUI situation is less than perfect. I long for the day when I can use the following code on any platform without worry: import Gui That being said, I like Tkinter module. In some cases the Tk widgets aren't "as good as Windows." In some cases they're much better than Windows. For example, the Tk text widget allows you to dynamically highlight text, insert images, insert other widgets, etc., etc. For someone like me who develops educational programs, the power of the Tk text widget is invaluable. My guess is that widgets like that are possible because of the quality of the native C code underlying the Tcl/Tk interpretive layer. It's supposed to be some of the best C code ever written. After looking at Tcl/Tk for a while I considered dropping Python altogether. Until I looked at Tcl syntax. I think that the Tcl syntax is the reason that Tcl/Tk is having some popularity problems. Some would argue that the default Motif widgets are the problem, but the default look of Tk has improved a lot over the years (and extensions like PMW really help). What is interesting right now is that the Tcl/Tk group is talking the need to revitalize Tcl/Tk: http://tcl.projectforum.com/tk/Home So, here the Python group is without a Python-native GUI (the Tkinter module being a wrapper around Tcl/Tk). And here is the Tcl/Tk group struggling with the problem of Tcl's popularity (and maybe some of that is Tk's fault, who knows). And then there is that excellent cross platform compatible C code sitting at Sourceforge under the BSD license The mind boggles Maybe its time to take the C code underlying Tcl/Tk and port it for Python-native use without the Tcl/Tk layer? From crsravi at rediffmail.com Wed Aug 27 13:01:13 2003 From: crsravi at rediffmail.com (crsravi at rediffmail.com) Date: 27 Aug 2003 17:01:13 -0000 Subject: Mail Confirmation - Message-ID: <20030827170113.730.qmail@webmail23.rediffmail.com> hi, Your mail is in my mailbox. I will get back to u whenever i check the same. this is auto generated mail. bye ravi. From mertz at gnosis.cx Thu Aug 28 12:59:17 2003 From: mertz at gnosis.cx (Lulu of the Lotus-Eaters) Date: Thu, 28 Aug 2003 12:59:17 -0400 Subject: Celebrity advice References: <3F4CD2A2.DE7D05D2@engcorp.com> <23891c90.0308280317.ac68b38@posting.google.com> Message-ID: "A.M. Kuchling" wrote previously: |* RMS is unbending in his convictions... |* ESR started out pretty well[*]: "CatB", whatever its flaws might be... |* Linus ...not very interested in the job. |The best candidate is Bruce Perens, IMHO... Bruce is great! (And Andrew is right on in his characterizations). But somehow my money is on the law professors, e.g. Eben Moglen, Lawrence Lessig, etc. They are not nearly so active, nor so "leaderly." But I think the real battles are (must be) in courtrooms and legislatures, not (anymore) on developers' mailing lists. It only does limited good to have "working code" if the cops will knock down your doors because that code violates the IP regime that Hollywood and MS bought from congress (and from WIPO). Yours, Lulu... [*] Btw., I had not even know just how crazy ESR had gotten lately. Not a shred of independence or thought seems to remain. He reads straight off of Faux News or the RNC, e.g.: http://armedndangerous.blogspot.com/2002_10_13_armedndangerous_archive.html -- mertz@ _/_/_/_/_/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY:_/_/_/_/ v i gnosis _/_/ Postmodern Enterprises _/_/ s r .cx _/_/ MAKERS OF CHAOS.... _/_/ i u _/_/_/_/_/ LOOK FOR IT IN A NEIGHBORHOOD NEAR YOU_/_/_/_/_/ g s From aleax at aleax.it Thu Aug 7 14:29:44 2003 From: aleax at aleax.it (Alex Martelli) Date: Thu, 07 Aug 2003 18:29:44 GMT Subject: crossplatform py2exe - would it be useful? References: <3cgdfnzo.fsf@python.net> Message-ID: Thomas Heller wrote: > Alex Martelli writes: > >> Thomas Heller wrote: >> ... >>>>> myscript -c "import sys; sys.path.insert(0, sys.executable); import >>>>> foo" >> ... >>>> Sounds like a good idea to me, if a sensible name is chosen for the >>>> "main module" (I propose 'main':-). >>> >>> My choice would have been __main__ :-) Is it really the correct way to >>> 'import __main__' instead of 'running' it? >> >> Well, most main scripts ARE coded with the "if __name__=='__main__':" >> convention, after all, so an "import __main__" can be seen as a way >> to just piggyback on that existing convention rather than inventing a >> new one in addition. So, I concede it's better than "import main". >> > > How would the hook be triggered? The zipimporter code would probably add > argv[0] to sys.path, and then try to 'import __main__' or something like > this. The problem is that a standalone executable python would have to > disable the standard Python command line flags and environment > variables, but they are parse *before* Py_Initialize() is called. Ah, yes, good point. So, the executable needs to know whether to do the usual commandline and environment processing, or not, _before_ calling Py_Inizialize. One approach might be to trigger this based on the executable's own *name* -- do the full commandline and environment processing if and only if the executable's name starts with (case- insensitive, probably, to be safe...) the six letters 'python', but not otherwise. There are, no doubt, other alternative ways, too, but this one seems dirt-simple and practically sufficient. > And I hope that the options set by the command line flags and env vars > should now come from the __main__ script itself. I'm not sure I understand what you mean. Anyway, I do see that if my 'foobar.exe' is a python.exe + appended zipfile, then running 'foobar -i' should just put '-i' in sys.argv[1], and NOT gobble it up to mean "enter interactive mode", for example. Alex From joshway_without_spam at myway.com Fri Aug 22 09:31:18 2003 From: joshway_without_spam at myway.com (JCM) Date: Fri, 22 Aug 2003 13:31:18 +0000 (UTC) Subject: What's better about Ruby than Python? References: Message-ID: Heiko Wundram wrote: > Hmm... I still use <> exclusively for my code, and I wouldn't really > like it getting deprecated. At least for me, != is more difficult to see > when browsing source than <> is, as != has a striking similarity to ==, > at least at the first glance... > I know <> has been deprecated for long, but I'd much rather have both > syntaxes allowed, also for the future... How about we keep them both, but make <> mean greater-than-or-less-than, which is a different comparison than != on partially ordered sets. 1 > 2 -- false 1 < 2 -- true 1 != 2 -- true 1 <> 2 -- true 1 > 'x' -- false 1 < 'x' -- false 1 != 'x' -- true 1 <> 'x' -- false Ok, I'm joking. Mostly. From aahz at pythoncraft.com Sat Aug 2 00:54:14 2003 From: aahz at pythoncraft.com (Aahz) Date: 2 Aug 2003 00:54:14 -0400 Subject: Unfortunate exception on dict item assignment (and why aren't slices hashable?) References: <7h3ptjpabbl.fsf@pc150.maths.bris.ac.uk> Message-ID: In article <7h3ptjpabbl.fsf at pc150.maths.bris.ac.uk>, Michael Hudson wrote: >"Fredrik Lundh" writes: >> Aahz wrote: >>> >>> (Despite my regular comments on python-dev, I don't contribute >>> code because SF refuses to make changes to allow Lynx to work >>> correctly.) >> >> maybe someone with an SF account could help you out? could it be >> worth setting up an aahz-helpers mailing list somewhere, manned by >> volunteers with SF access and modern browsers? I suppose I'll break down one of these years and find better software. >I've successfully used w3m to drive SF's website, FWIW. I've used both w3m and links, and I find them much more difficult to use than lynx. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From mat at frheaven.com Sun Aug 3 14:37:10 2003 From: mat at frheaven.com (Matthieu M.) Date: Sun, 03 Aug 2003 20:37:10 +0200 Subject: Python and XML In-Reply-To: References: Message-ID: <3F2D5656.5020602@frheaven.com> Martin v. L?wis wrote: > 1. the output of > > import xml > print xml.__file__ c:\python23\lib\xml\__init__.pyc > 2. The contents of the directory printed above C:\Python23\Lib\xml 03/08/2003 15:48 . 03/08/2003 15:48 .. 03/08/2003 15:48 dom 03/08/2003 15:46 parsers 03/08/2003 15:48 sax 26/01/2003 10:06 1 053 __init__.py 03/08/2003 15:48 1 053 __init__.pyc > 3. The contents of the dom directory inside. C:\Python23\Lib\xml\dom 03/08/2003 15:48 . 03/08/2003 15:48 .. 24/04/2003 20:03 3 580 domreg.py 03/08/2003 15:48 3 894 domreg.pyc 29/06/2003 01:09 37 362 expatbuilder.py 25/01/2003 10:11 5 471 minicompat.py 03/08/2003 15:48 6 279 minicompat.pyc 06/04/2003 22:12 67 941 minidom.py 25/01/2003 12:07 964 NodeFilter.py 24/04/2003 20:03 12 325 pulldom.py 03/08/2003 15:48 16 975 pulldom.pyc 25/01/2003 10:29 12 772 xmlbuilder.py 27/02/2003 17:13 4 137 __init__.py 03/08/2003 15:48 8 642 __init__.pyc In fact I've done all this things in the Python Shell, otherwise, when I lauch it with "python foo.py" I've got the same kind of errors. I think the problem comes from here, but I'm not skilled in Python, so... Thanks -- Matthieu M. http://www.frheaven.com From graham__fawcett at hotmail.com Mon Aug 25 13:21:28 2003 From: graham__fawcett at hotmail.com (Graham Fawcett) Date: 25 Aug 2003 10:21:28 -0700 Subject: thank you! References: <3F497421.2C5C70B8@engcorp.com> Message-ID: Peter Hansen wrote in message news:<3F497421.2C5C70B8 at engcorp.com>... > parrt at jguru.com wrote: > > > > Hi, > > > > parrt at jguru.com is protected from spam by knowspam.net. For parrt at jguru.com > > to receive your email, you need to demonstrate you > > are human by answering the simple question at this link: > > > > http://knowspam.net/v/v?t=python-list at python.org&s=parrt at jguru.com > > > > Thanks! > > You're welcome! I _am_ in fact human, so I have responded > appropriately. I mention it here to save everyone else the effort. > > -Peter Sure you are. That's exactly what a bot would say. ;-) -- G From skip at pobox.com Wed Aug 6 10:28:14 2003 From: skip at pobox.com (Skip Montanaro) Date: Wed, 6 Aug 2003 09:28:14 -0500 Subject: Freeze Question In-Reply-To: References: Message-ID: <16177.4222.994099.127266@montanaro.dyndns.org> zooko> Thank you very much for posting this recipe. It happens to be zooko> exactly what I need right now. Glad to hear. zooko> I think maybe steps 2 and 3 are in reversed order. Yeah, dumbo mistako. Skip From elainejackson7355 at home.com Wed Aug 13 18:35:51 2003 From: elainejackson7355 at home.com (Elaine Jackson) Date: Wed, 13 Aug 2003 22:35:51 GMT Subject: two quick questions References: Message-ID: Thanks to everyone who responded about this, both for the info regarding question (1) and for the tact in not balaboring the sheer stupidity behind question (2). That whole business got inverted somehow on its way to (whatever passes for) my brain. Sorry about that. On the up side, it may turn out to have been an instructive mistake: both questions are special cases of a single underlying question or problem that I've been harboring for some time. I may eventually start a thread about it (here or elsewhere), but for now I'm still trying to mould it into a sensible question. I think it could be an interesting topic for people concerned with computer-science pedagogy. So far I don't even know if there's anyone like that around here. In any case, mucho appreciado for the help. ej ================================ Elaine Jackson wrote in message news:uzk_a.740726$Vi5.16966327 at news1.calgary.shaw.ca... | Two quick newbie questions: | | 1) Does Python have passing-by-reference? | 2) In ordinary parlance, "deep" implies "shallow" but not conversely. In the | Python "copy" module (if I understand correctly), the implication goes the other | way. Do you find this a nuisance? | | Peace, | EJ | | From jjl at pobox.com Tue Aug 5 12:15:58 2003 From: jjl at pobox.com (John J. Lee) Date: 05 Aug 2003 17:15:58 +0100 Subject: Changing base class of a big hierarchy References: <873cgjyo2u.fsf@pobox.com> <87oez5wrw3.fsf@pobox.com> <87ispds3t1.fsf@pobox.com> Message-ID: <871xw06pxd.fsf@pobox.com> jjl at pobox.com (John J. Lee) writes: [...] > I'll stick with your class-mapping idea, I think. > > Thanks all. I just noticed most of 4DOM's HTML DOM code is automatically generated, so it's going to be much easier than I thought. Lucky, because the changes I need are more complicated than I first thought, and I'd given up on modifying the class hierarchy from outside. John From pythonhda at yahoo.com.replacepythonwithlinux Thu Aug 14 11:15:36 2003 From: pythonhda at yahoo.com.replacepythonwithlinux (pythonhda) Date: Thu, 14 Aug 2003 11:15:36 -0400 Subject: URL emulator (sockets question) Message-ID: <20030814111536.70fbb6b3.pythonhda@yahoo.com.replacepythonwithlinux> Hi All, I writing a program to emulate a URL (essentially a very simple raw data proxy). The client should always think that it is only talking to the proxy and the proxy acts like the url it's emulating. My *immediate* problem is how do I tell the client that the web server has finished sending? I know that when you recieve 0 bytes from the web server, it means that it is done sending...so how do I indicate the same thing to the browser? I've tried various combos of 'shutdown' and 'close' but the browser (Opera) indicates a premature disconnection. I was thinking of using it as a proxy between my cellphone and some wap sites I'm developing/debugging. I don't like to type out long urls on the phone and I figured this would be a good learning experience. --- Code Start --- import socket import sys import select import re IMG = re.compile(r'(src="[^"]+")') class ProxyServer: def __init__(self, port, url, rmtport): self.port = port self.url = url self.rmtport = rmtport self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.clients = {} self.count = 0 def start(self): self.socket.bind((socket.gethostname(), self.port)) self.socket.listen(5) while 1: try: self.clisocket, self.clientaddress = self.socket.accept() self.returnIP = self.clisocket.getsockname() self.proxy() self.count += 1 except KeyboardInterrupt: self.socket.close() def proxy(self): websvr = socket.socket(socket.AF_INET, socket.SOCK_STREAM) websvr.connect((self.url, self.rmtport)) self.request = '' self.response = '' f = file("proxydata_%s.data" % self.count, 'w') while 1: try: r, w, e = select.select([self.clisocket, websvr], [self.clisocket, websvr], [], 30) # if client requests something if self.clisocket in r: request = self.clisocket.recv(1024) f.write("\n--RAW REQUEST\n%s" % request) self.request = self.transreq(request, f) self.done = False # if websvr writable and have someting to send if websvr in w and self.request != '': self.sendit(websvr, self.request) self.request = '' # if websvr readable and hasn't returned '' if websvr in r and not self.done: response = websvr.recv(1024) if response == '': self.done = True else: self.response = self.transresp(response, f) # if client writable and last response wasn't '' if self.clisocket in w and self.response != '': self.sendit(self.clisocket, self.response) self.response = '' # if self.done: # What should I put here?? except socket.timeout: pass self.count += 1 f.close() def sendit(self, sock, data): l = len(data) sent = 0 while sent < l: sent += sock.send(data) data = data[sent:] def transreq(self, request, f=None): request = request.replace("%s:%s" % self.returnIP, self.url) return request def transresp(self, response, f=None): if f is not None: f.write("\n--RAW RESPONSE\n%s" % response) response = response.replace(self.url, "%s:%s" % self.returnIP) response = IMG.sub('', response) response = response.replace("\r\n0\r\n", "\r\n") return response if __name__ == "__main__": wapsite = "www.somewapsite.com" svr = ProxyServer(9000, wapsite, 80) svr.start() --- END --- Any suggestions/tips? Thanks, pythonhda From zsh-users-help at sunsite.dk Sun Aug 31 13:00:08 2003 From: zsh-users-help at sunsite.dk (zsh-users-help at sunsite.dk) Date: 31 Aug 2003 17:00:08 -0000 Subject: confirm subscribe to zsh-users@sunsite.dk Message-ID: <1062349208.19238.ezmlm@sunsite.dk> Hi! This is the ezmlm program. I'm managing the zsh-users at sunsite.dk mailing list. To confirm that you would like python-list at python.org added to the zsh-users mailing list, please send an empty reply to this address: zsh-users-sc.1062349208.bciaalgdgbgmnegnphbh-python-list=python.org at sunsite.dk Usually, this happens when you just hit the "reply" button. If this does not work, simply copy the address and paste it into the "To:" field of a new message. This confirmation serves two purposes. First, it verifies that I am able to get mail through to you. Second, it protects you in case someone forges a subscription request in your name. --- Administrative commands for the zsh-users list --- I can handle administrative requests automatically. Please DO NOT SEND THEM TO THE LIST ADDRESS! If you do, I will not see them and other subscribers will be annoyed. Instead, send your message to the correct command address: To subscribe to the list, send a message to: To remove your address from the list, send a message to: Send mail to the following for info and FAQ for this list: Similar addresses exist for the digest list: To get messages 123 through 145 (a maximum of 100 per request), mail: To get an index with subject and author for messages 123-456 , mail: They are always returned as sets of 100, max 2000 per request, so you'll actually get 100-499. To receive all messages with the same subject as message 12345, send an empty message to: The messages do not really need to be empty, but I will ignore their content. Only the ADDRESS you send to is important. You can start a subscription for an alternate address, for example "john at host.domain", just add a hyphen and your address (with '=' instead of '@') after the command word: To stop subscription for this address, mail: In both cases, I'll send a confirmation message to that address. When you receive it, simply reply to it to complete your subscription. If despite following these instructions, you do not get the desired results, please contact my owner at zsh-users-owner at sunsite.dk. Please be patient, my owner is a lot slower than I am ;-) --- Enclosed is a copy of the request I received. Return-Path: Received: (qmail 19232 invoked from network); 31 Aug 2003 17:00:08 -0000 Received: from localhost (HELO sunsite.dk) (127.0.0.1) by localhost with SMTP; 31 Aug 2003 17:00:08 -0000 X-MessageWall-Score: 0 (sunsite.dk) Received: from [128.187.34.45] by sunsite.dk (MessageWall 1.0.8) with SMTP; 31 Aug 2003 17:0:7 -0000 From: To: Subject: Thank you! Date: Sun, 31 Aug 2003 11:00:02 --0600 X-MailScanner: Found to be clean Importance: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MSMail-Priority: Normal X-Priority: 3 (Normal) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="_NextPart_000_09DD78DF" --_NextPart_000_09DD78DF Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Please see the attached file for details. --_NextPart_000_09DD78DF-- From javier_ruere at HotPOP.com Tue Aug 5 11:56:27 2003 From: javier_ruere at HotPOP.com (Javier Ruere) Date: Tue, 05 Aug 2003 12:56:27 -0300 Subject: boa-constructor bug: import string In-Reply-To: References: Message-ID: <3F2FD3AB.7070508@HotPOP.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Mark, This bug is a very old one that has been fixed a long time ago. Check out Boa from CVS for the latest version, which is 0.2.4. 0.2.5 was promised for a week from now. Later, Javier Mark Carter wrote: > In v0.2.0 > starting boa.py produces the error message: > File "C:\Python23\Lib\site-packages\wxPython\tools\boa\About.py", > line 301, in write > ss = string.strip(s) > NameError: global name 'string' is not defined > > It appears that string is not imported in many modules, because fixing > this gives the further error: > > File "C:\Python23\Lib\site-packages\wxPython\tools\boa\PropEdit\PropertyEditors.py", > line 1050, in NamePropEdit > identifier = string.letters+string.digits+'_' > NameError: name 'string' is not defined > > Can someone confirm that this is a bug? I don't want to post it to > their list inadvertantly. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQE/L9Oq8XQC840MeeoRAmqsAJ9CXX//gjK/l3MWW5XxbV2+4PVMewCeK1JO pOAknMp1mQNinAphJwIs8YE= =oHJw -----END PGP SIGNATURE----- From CousinStanley at hotmail.com Mon Aug 25 10:40:49 2003 From: CousinStanley at hotmail.com (Cousin Stanley) Date: Mon, 25 Aug 2003 07:40:49 -0700 Subject: JavaScript web scraping test cases? References: <87ekzg0y6e.fsf@pobox.com> <87fzjpdhrx.fsf@pobox.com> Message-ID: John ... Although it's been a while since I tested these scripts I thought I remembered testing successfully in both Mozilla 0.95 and IE 5.1 at the time ... I tested this morning using Moz 1.3.1 and 2 out of 3 failed, but all 3 worked in IE 6 ... The JS used in these scripts, although a bit hackish, doesn't use any particular IE magic ... I zipped up all 3 scripts for convenience, if you want to look at the sources ... http://fastq.com/~sckitching/JS/JS_Plots.zip Differences in JS/DOM implementations from browser to browser hurt my head and seem to be an endless source of problems for web developers ... -- Cousin Stanley Human Being Phoenix, Arizona From nospam at nospam.net Tue Aug 12 10:22:32 2003 From: nospam at nospam.net (c42) Date: Tue, 12 Aug 2003 14:22:32 GMT Subject: Is Python your only programming language? References: Message-ID: After college I started using VB & VBA for most of my bigger projects and Winbatch for my system admin stuff. However, as my current company has started to move more of its servers to Linux, I'm programming almost exclusively in Python. In the past I've used Komodo and found it to be very nice tool, but I'm also keeping an eye on Boa Constructor with its advances as well. In article , code at joecheng.com says... > I'm curious about something... many Artima.com members who have a Java > background and learned Python have come to the conclusion that Java and > Python are highly complimentary languages. They would never consider > filling the place Java has in their toolbox with Python, but recognize there > are many tasks where it really pays to add Python to the mix. > > I want to ask you hard-core c.l.p Pythonistas: Do you use Python for > everything? (and I'm counting Python + C extensions as just Python) Or do > you keep another language equally close at hand, and if so, what is it? And > finally, do you foresee a day when Python can be, for all practical intents > and purposes, your only programming language? > > > From nhodgson at bigpond.net.au Mon Aug 25 04:25:33 2003 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Mon, 25 Aug 2003 08:25:33 GMT Subject: ANN: BlackAdder V1.0.0 References: <3f48a498$3$219$fa0fcedb@lovejoy.zen.co.uk> Message-ID: <1Kj2b.61523$bo1.38258@news-server.bigpond.net.au> Gerhard H?ring: > Furthermore, I'd excpect an email address with a connection to the > company that offers the product, something like > blackadder at thekompany.com, sales at thekompany.com or something like that. > Not some random BadJake with a completely different email address ;-) I'm interested in what has happened here. Have theKompany sold BlackAdder to John or has he just taken over selling it? The web site of theKompany still talks about BlackAdder being beta. Neil From leo.broska at NOSPAM.isys.com.au Tue Aug 19 01:13:53 2003 From: leo.broska at NOSPAM.isys.com.au (Leo) Date: Tue, 19 Aug 2003 15:13:53 +1000 Subject: GUI IDE for Macintosh? Message-ID: hi there i'm looking for a GUI Building IDE for Python Development running on a mac under OS X. i know about eric (http://www.die-offenbachs.de/detlev/eric3.html) and boa (http://boa-constructor.sourceforge.net/). in their install readme's si only linux and windows listed. does anybody has experience with a GUI Building Tool on OS X? thanks for any advice, leo From jarausch at skynet.be Wed Aug 20 04:46:50 2003 From: jarausch at skynet.be (Helmut Jarausch) Date: Wed, 20 Aug 2003 10:46:50 +0200 Subject: class factory In-Reply-To: <8ad2cfb3.0308200015.4f5bd504@posting.google.com> References: <8ad2cfb3.0308200015.4f5bd504@posting.google.com> Message-ID: <3F43357A.1030204@skynet.be> I'm quite new to Python, as well. Nick Keighley wrote: > Hi, > > I'm a Python beginner and I'm would like to write a function that > returns a class (perhaps a tad ambitious...). I've looked through > the FAQ and perused "Python In A Nutshell" (not a good book to ===============================================^^^^^^^^^^^^^^^^^^ > start with?). The only example I found in PiaN used a simple ^^^^^^^^^^^ Python in a Nutshell is an excellent book except if Python is your very first programming language. > if statement to return one of a selection of pre-existing classes. > I'd like to generate a class on-the-fly from a parameter (a dictionary). > Can Python do this sort of stuff? Does the mean I have to mess with > the dreaded meta-classes? > Have a look at ch 13 (top of page 262). Build a string 'ClassDefinition', call compile like GenClassCode= compile(ClassDefinition,'my_class_def','exec') and than in some context exec(GenClassCode) If 'ClassDefinition' generates a class 'X' just use it like newX= X(....) -- Helmut Jarausch Lehrstuhl fuer Numerische Mathematik RWTH - Aachen University D 52056 Aachen, Germany From ghowland at lupineNO.SPAMgames.com Sat Aug 23 14:09:28 2003 From: ghowland at lupineNO.SPAMgames.com (Geoff Howland) Date: Sat, 23 Aug 2003 18:09:28 GMT Subject: Modifying the {} and [] tokens References: Message-ID: On Sat, 23 Aug 2003 13:39:15 -0400, "Terry Reedy" wrote: > >"Geoff Howland" wrote in message >news:km4fkv8qbbge3mvckv5gsim9amq59qvohb at 4ax.com... >> For the [].len() type things, this is obviously a matter of taste > >There is also history (and backwards compatibility). Once upon a >time, neither strings nor tuples had methods, so neither 'abc'.len() >nor (1,2,3).len() would have been possible. Thanks for the info. Always good to know history, and sometimes hard to find with the glut of common information repeated on the net (finding the same function definition pages over and over while looking for something the first one you found didn't have :) ). >With respect to {}+{}. An in-place version of this is currently >spelled {}.update({}). Yes, more chars to type, but also more >'honest' in not implying symmetry between the two dicts. As the name >suggests, duplicate key with new value overrides previous value. What's really the problem with a + sugar though? Currently there is no sugar, and update() really all there is to it. This is a little more pronounced when doing slightly more complex things like finding the intersection to things. I wouldn't be opposed to less operators, but at least having the functions. {}.keys().intersect({}.keys) Something like that, and the reverse. I belevie there is a PEP for sets around, maybe that will fix this problem. Unless it doesn't mesh with any of these other containers well. -Geoff Howland http://ludumdare.com/ From writeson at earthlink.net Fri Aug 8 08:49:51 2003 From: writeson at earthlink.net (Doug Farrell) Date: 8 Aug 2003 05:49:51 -0700 Subject: Problem with mod_python and 4Suite Message-ID: <88bc63c6.0308080449.3e6fdf7a@posting.google.com> Hi all, I'm trying to build a demonstration website using mod_python and 4Suite to show how we could transform XML documents into HTML with XSLT. Here is a piece of code that causes it to blow up: # import the xml/xslt stuff here from xml.xslt.Processor import Processor # create a xslt processor xsltProc = Processor() # transform the xml text into html xsltProc.appendStylesheetUri(filepath) html = xsltProc.runString(xmltext) Here is the trace I get in the browser when I run this code: Mod_python error: "PythonHandler mod_python.publisher" Traceback (most recent call last): File "/usr/lib/python2.2/site-packages/mod_python/apache.py", line 285, in HandlerDispatch result = object(req) File "/usr/lib/python2.2/site-packages/mod_python/publisher.py", line 175, in handler result = apply(object, (), args) File "/data/cs/handlers/gme.py", line 61, in search return _transform(xmldata, filepath) File "/data/cs/handlers/gme.py", line 105, in _transform from xml.xslt.Processor import Processor File "/usr/lib/python2.2/site-packages/_xmlplus/xslt/__init__.py", line 19, in ? pyxml_required = version.StrictVersion(Ft.__pyxml_version__) AttributeError: 'module' object has no attribute '__pyxml_version__' Does anyone have any suggestions, or just even general advice on using 4Suite with mod_python? I'd be very interested to hear them. I'm running this on a Dell 2550 server with RedHat linux 8.0, Python 2.2.1, PyXML 0.8.3 and 4Suite 1.0.a* Thanks in advance for your help. Doug Farrell From alan.gauld at btinternet.com Thu Aug 28 16:50:13 2003 From: alan.gauld at btinternet.com (Alan Gauld) Date: Thu, 28 Aug 2003 20:50:13 GMT Subject: learning to program References: Message-ID: <3f4e6a44.1219503072@news.blueyonder.co.uk> On Thu, 28 Aug 2003 08:36:08 +0200, "U. N. Owen" wrote: > Not TCI but TCL... It's another script language, > but it's not installed with Python. Here it > was just an example, so you don't need it for > the moment. If you are interested, go to > www.tcl.tk. > That's correct. But to add a clarifying explanation for why I included Tcl in the first place, Python up to version 1.5 came with a full Tcl/Tk installation bundled to enable Tkinter. After 1.6 they only shipped the libraries so the tutorial suggestion to play with Tcl suddenly became invalid :-( Tcl is still a fun language with many interesting concepts but I wouldn't recommend an absolute beginner to use it if it's not already available. Alan G. Author of the Learn to Program website http://www.freenetpages.co.uk/hp/alan.gauld From miguel.hernandez at icr-sa.com Mon Aug 25 08:03:21 2003 From: miguel.hernandez at icr-sa.com (=?ISO-8859-1?Q?Miguel_Hern=E1ndez_Martos?=) Date: Mon, 25 Aug 2003 14:03:21 +0200 Subject: DDE Hotlinks in Python Message-ID: Hello, I have seen an old post (http://dbforums.com/t552213.html) refering to the support for dde hot links in win32all. With dde module I can build a DDE server that notifies clients (VB and Delphi clients) of changes (using SetData method) and it works great. The problem is that I also would like to code a Python dde client that can be notified of changes from a server. I browsed the source code of dde module and I think it can't be done, but I'm not a win32 guru. Can anybody tell me if that can be done with dde module bundled with win3all? Thanks in advance. -- Miguel Hern?ndez Martos | Ingenier?a y Control Remoto, S.A. Departamento de Software | Pol. Ind. Juncaril C/Baza Parc. 207 ------------------------------| 18220 Albolote-Granada (Espa?a) | Tels.: + 34 958 43 00 05/10 http://www.icr-sa.com | Fax: + 34 958 46 79 08 From adalke at mindspring.com Wed Aug 20 17:11:26 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Wed, 20 Aug 2003 21:11:26 GMT Subject: What's TOTALLY COMPELLING about Ruby over Python? References: Message-ID: <2uR0b.1178$Ej6.709@newsread4.news.pas.earthlink.net> Aahz: > I have been very careful to not label Brandon as a troll. As have I. Andrew dalke at dalkescientific.com From gherron at islandtraining.com Mon Aug 11 15:47:02 2003 From: gherron at islandtraining.com (Gary Herron) Date: Mon, 11 Aug 2003 12:47:02 -0700 Subject: Reference count In-Reply-To: <007601c3603e$f6bd5d30$0601a8c0@hq.novamens.com> References: <002a01c3603b$73442a90$417290c8@paraopeba> <16183.60555.59705.762835@montanaro.dyndns.org> <007601c3603e$f6bd5d30$0601a8c0@hq.novamens.com> Message-ID: <200308111247.03007.gherron@islandtraining.com> On Monday 11 August 2003 12:30 pm, Pablo Yabo wrote: > Hi, > I need to keep a object alive even if its reference count if zero. > Is there any way to increment its reference count using Python code, not > Py_INCREF or there is any way to avoid deletion of the object? > > Thanks, in advance > > Pablo Yabo Sure. Just put the object into a list of things you want to keep alive. The the reference count will not be zero and the object will not be garbage collected. KeepAlive = [] # A global and somwhere in your code: KeepAlive.append(ImportantObject) Gary Herron From oussoren at cistron.nl Tue Aug 12 11:51:00 2003 From: oussoren at cistron.nl (Ronald Oussoren) Date: Tue, 12 Aug 2003 17:51:00 +0200 Subject: dist problem on osx In-Reply-To: <3F39071B.6030707@lemburg.com> References: <644f6688.0308101518.ad9e02a@posting.google.com> <3F3786FC.5020703@lemburg.com> <3F39071B.6030707@lemburg.com> Message-ID: On Tuesday, 12 August, 2003, at 17:26, M.-A. Lemburg wrote: > Ronald Oussoren wrote: >> On Monday, 11 August, 2003, at 14:07, M.-A. Lemburg wrote: >>> rdack wrote: >>> >>>> osx 10.2.6 python 2.2.1 (built in) >>>> says my architecture is both 386 and ppc. >>>> also has a path with a space in it that won't work. >>>> where can i change these settings? >>>> -------- >>>> gcc -arch i386 -arch ppc -bundle -flat_namespace -undefined suppress >>>> build/temp.darwin-6.6-Power >>>> Macintosh-2.2/mx/DateTime/mxDateTime/mxDateTime/mxDateTime.o >>>> -L/usr/local/lib -L/usr/lib -o build/lib.darwin-6.6-Power >>>> Macintosh-2.2/mx/DateTime/mxDateTime/mxDateTime.so >>>> --------------- >>> >>> >>> This is a bug in distutils. It's fixed in Python 2.2.3. >> The two architectures are not a bug in distutils, but a bug in the >> way Apple build python. The '-arch i386' is annoying but harmless, if >> it really annoys you you can change >> /usr/lib/python2.2/config/Makefile. Search for '-arch i386' and >> remove this. > > I was referring to the spaces in the platform string generated > by distutils. I thought so, but wanted to make it clear that only one of the items was really a bug. Sorry about the confusion. > The -arch i386 look funny in there... hmm, perhaps > we'll get Mac OS X / i386 sometime soon ?! ;-) There are persistant rumors that Apple is running MacOS X on Intel in a secret lab. This is probably just caused by someone that is running Darwin on PPC and Intel. Attacking MS head-on on it's hometurf would not be the smartest survival stragegy for Apple :-) Ronald From nhodgson at bigpond.net.au Wed Aug 27 17:58:06 2003 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Wed, 27 Aug 2003 21:58:06 GMT Subject: Mac equivalent to COM in Windows? References: <78kkkvg8ckfio141es2of1p483ohbtbit5@4ax.com> <78kkkvg8ckfio141es2of1p483ohbtbit5@4ax.com> <87ekz7tdty.fsf@pobox.com> <7h3vfsjcigb.fsf@pc150.maths.bris.ac.uk> <87ad9v9bng.fsf@pobox.com> Message-ID: John J. Lee: > Interesting. I was wondering about COM itself, though. COM will still be being used by Microsoft for Internet Explorer and maybe Office on the Mac. Several years ago they tried to promote ActiveX on MacOS but dropped it. There was an interesting post on this subject by Steven D. Majewski. Go to Google Groups Advanced Search http://www.google.com.au/advanced_group_search?hl=en search for "mac activex" in comp.lang.python. Neil From postmaster at windriver.com Fri Aug 22 01:03:13 2003 From: postmaster at windriver.com (System Administrator) Date: Fri, 22 Aug 2003 07:03:13 +0200 Subject: Undeliverable: Re: Approved Message-ID: Your message To: toni at takefive.co.at Subject: Re: Approved Sent: Fri, 22 Aug 2003 01:01:10 +0200 did not reach the following recipient(s): toni at takefive.co.at on Fri, 22 Aug 2003 07:03:12 +0200 The recipient name is not recognized The MTS-ID of the original message is: c=at;a= ;p=windriver;l=SZG-EXCH010308220503Q83RT70S MSEXCH:IMS:Windriver:Salzburg:SZG-EXCH01 0 (000C05A6) Unknown Recipient -------------- next part -------------- An embedded message was scrubbed... From: python-list at python.org Subject: Re: Approved Date: Fri, 22 Aug 2003 01:01:10 +0200 Size: 1322 URL: From news at 92tr.freeserve.co.uk Thu Aug 14 09:45:50 2003 From: news at 92tr.freeserve.co.uk (ddoc) Date: Thu, 14 Aug 2003 13:45:50 +0000 Subject: Python for medicine Message-ID: Python, as Zope, underlies some candidate medical record systems. Python is also the programming language for at least one system - GNUMed from Australia. But the specific slot I see Python as particularly suited to is as a generic scripting language for use in (many) medical record and decision assist systems. Currently there are a variety of these, and they tend to have individual scripting languages or lack them altogether, partly because their origins are in the dawn of time. There is a certain amount of work available on the Web on what could be generic objects, such as the Arden Syntax, a way of defining the steps in making a decision. Rendering such things into Python modules, and leaving it up to the individual (proprietary or Open) system suppliers to make use of them and provide the lower level piece that interfaces to the specific system in question seems like a good way to go, to me. -- A From davecook at nowhere.net Fri Aug 22 05:14:39 2003 From: davecook at nowhere.net (David M. Cook) Date: Fri, 22 Aug 2003 09:14:39 GMT Subject: "_pg" (Postgresql) module for win32 References: Message-ID: <3al1b.54882$Ij4.20248@news2.central.cox.net> In article , David M. Cook wrote: > In article , User At Domain Dot Invalid wrote: >> Where can I find "_pg" module for postgresql? I would prefer a module >> not intedend for "cygwin","mingw" or some thing similar to that. > > pyPgSQL has a win32 binary available for download: > > http://pypgsql.sourceforge.net/ Also there are now a win32 port of psycopg available: http://www.stickpeople.com/projects/python/psycopg/ Dave Cook From jwdillworth at yahoo.com Tue Aug 19 11:53:19 2003 From: jwdillworth at yahoo.com (Jeremy Dillworth) Date: Tue, 19 Aug 2003 08:53:19 -0700 (PDT) Subject: What's TOTALLY COMPELLING about Ruby over Python? In-Reply-To: Message-ID: <20030819155319.58303.qmail@web41102.mail.yahoo.com> OK, I'll bite. (sorry, post got long too) DISCLAIMER: I don't have time at work to read this entire thread. DISCLAIMER 2: Something I might find totally compelling, someone else might think is trivial, or even stupid, to each his own. I've used Python for a couple of years at my job for many projects, including CGI's, "glue" scripts, a CVS tool, and one or two GUI apps to allow internal users to stop asking me to do things I was doing for them with quick one-off shell-scripts. I read the "Pick Axe" book. My one-sentence impression of Ruby has been: "Prettier core language (a few significant warts have been fixed as of 1.8), needs more stable libraries." I find the "Prettier core language" compelling. For example, say you want a static method: In Python: class A: def static_meth(a, b): return a + b static_meth = staticmethod(static_meth) I don't like that something has to be done at the end of the method to make it static. It could be bad if it were done at the end of the class, away from the method, someone might think the omission of self was an error, correct it, and then you'll have a problem. In Ruby it's: class A def A.static_meth(a, b) return a + b end end Random observations: I like that Ruby's interpreter enforces specific naming rules for constants, globals, instance variables, etc. This shows in the Ruby libraries. In Python's libraries classes might be upper or lower case (lowercase denotes those implemented in C), Ruby has had no reason to distinguish what classes are implemented in, since they're all treated the same (ie you can inherit, and you always could, in Python this is a recent improvement). Ruby's licensing seems to be a mess. Some of the interpreter source is LGPL, some is Artistic or GPL (letting you choose). Not a problem in most cases, but I like Python's licensing much better. Ruby's C API looks cleaner and more comprehensible to me. Though Boost.Python looks like it wraps Python's C API just as cleanly... I don't see any mature/stable GUI frameworks I like for Ruby. I think they just started wxRuby. I don't like Fox Ruby's windows look on Linux. Tk is kinda OK, but I think it was kind of silly that they prefixed classes with a Tk, when Ruby supports namespaces perfectly well via modules (maybe fixed in 1.8?). As for Ruby GNOME/GTK, I don't trust GTK+ on windows (I want a GUI toolkit that works on Windows, Linux, and Mac OS X if possible). Ruby's not using whitespace to delimit blocks may help you avert civil war at your shop depending on how people view the white-space-as-syntax issue. Ruby 1.8 has some nice improvements, but there are no books explicitly on 1.8 yet, and I haven't seen any signs that any are coming (yet). Ruby's FTP library doesn't work with file-like objects (maybe fixed in 1.8?), it works with file names... forcing you to write to files on disk instead of perhaps dynamically generating stuff you send to an FTP server. Operator overloading syntax is nicer, I find: class MyClass def +(other) # ... end end easier on the eyes than: class MyClass: def __add__(self, other): # ... Ruby's blocks make using threading and forking pretty nice: t = Thread.new do # ... code to execute in another thread end Or fork do # ... fork and run this code end I like this better than (if memory serves): import threading class MyThread(threading.Thread): def run(self): # ... do stuff in a thread And import os pid = os.fork() if not pid: # ... do stuff in fork here sys.exit() # unless you want the child to carry on past the if... I've been noticing a lot more Ruby web-sites lately. Either I haven't been paying attention, or Ruby has gained some inertia. Also, Ruby's collection methods are really a sight to behold. Over a weekend, I wrote some scripts which chained together like half a dozen method calls to manipulate a collection, and everything worked the first time, like I expected. This happens in Python too, but I think it happens slightly more in Ruby (maybe 90% of the time compared to 80% w/Python). I'm toying with the idea of writing a game engine. For this, I'm almost certain to embed Ruby for AI scripting... since library issues seem moot in an embedding case. For prototyping and embedding in another app... and possibly for "glue" scripts... Ruby would be my first choice. For large GUI apps or maybe large web apps, I'm not convinced yet. --- "Brandon J. Van Every" wrote: > I'm realizing I didn't frame my question well. > > What's ***TOTALLY COMPELLING*** about Ruby over Python? What makes you jump > up in your chair and scream "Wow! Ruby has *that*? That is SO FRICKIN' > COOL!!! ***MAN*** that would save me a buttload of work and make my life > sooooo much easier!" > > As opposed to minor differences of this feature here, that feature there. > Variations on style are of no interest to me. I'm coming at this from a C++ > background where even C# looks like an improvement. ;-) From 10,000 miles > up, is there anything about Ruby that's a "big deal" compared to Python? > > One person mentioned Japanese documentation. I'm sure that's Totally Kewl > to the Japanese.... > > -- > Cheers, www.3DProgrammer.com > Brandon Van Every Seattle, WA > > 20% of the world is real. > 80% is gobbledygook we make up inside our own heads. > > -- > http://mail.python.org/mailman/listinfo/python-list From vze4rx4y at verizon.net Fri Aug 15 17:46:34 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Fri, 15 Aug 2003 21:46:34 GMT Subject: Py2.3: Feedback on Sets References: Message-ID: <_wc%a.462$N37.112@nwrdny02.gnilink.net> "Russell E. Owen" > I don't rely on sets heavily (I do have a few implemented as > dictionaries with value=None) and am not yet ready to make my users > upgrade to Python 2.3. > > I suspect the upgrade issue will significantly slow the incorporation of > sets and the other new modules, but that over time they're likely to > become quite popular. I am certainly looking forward to using sets and > csv. > > I think it'd speed the adoption of new modules if they were explicitly > written to be compatible with one previous generation of Python (and > documented as such) so users could manually include them with their code > until the current generation of Python had a bit more time to be adopted. Wish granted! The sets module now will run under Py2.2. It should be available for download from CVS after 24 hours: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/python/python/dist/src/Lib/sets.p y Raymond Hettinger From irmen at -NOSPAM-REMOVETHIS-xs4all.nl Wed Aug 20 17:19:14 2003 From: irmen at -NOSPAM-REMOVETHIS-xs4all.nl (Irmen de Jong) Date: Wed, 20 Aug 2003 23:19:14 +0200 Subject: how fast is Python? In-Reply-To: References: Message-ID: <3f43e5cf$0$49115$e4fe514c@news.xs4all.nl> Python is fast enough for me, especially 2.3. Profile & code slow parts as C extensions. Include your own assembly there if so desired. Investigate Psyco. There was one example on this newsgroup that showed that Python+psyco actually outperformed the same program in compiled C. --Irmen From R.Brodie at rl.ac.uk Thu Aug 14 11:26:34 2003 From: R.Brodie at rl.ac.uk (Richard Brodie) Date: Thu, 14 Aug 2003 16:26:34 +0100 Subject: Is Python your only programming language? References: Message-ID: wrote in message news:mailman.1060872297.29542.python-list at python.org... > As an example, someone mentioned the Arianne accident, a few years > back, which was "caused" by a Zero-division error caught by the > code, which raised some kind of error condition (I don't do Ada). No, it was an overflow converting a floating point to integer. The module was originally designed for Arianne 4, which had different flight characteristics. > BUT, it seems that the segment of code being checked wasn't even > going to be executed (something about horizontan acceleration), > and since the rocket was already in the air, that code shouldn't > have mattered; "if it was C, then the operation would have silently > failed, and the rocket would have kept flying". It was in a background task, that was unnecessary. However the exception handling was specified to be: write results to EEPROM and halt. It's true that in C one would likely have garbage values in the integer, and the error would have gone unnoticed. I'm not sure I find that a comforting thought though. The full text of the report is on the web, and should be required reading: http://www.mssl.ucl.ac.uk/www_plasma/missions/cluster/about_cluster/cluster1/ariane5rep.html From wester at ilt.fraunhofer.de Thu Aug 7 09:08:09 2003 From: wester at ilt.fraunhofer.de (Rolf Wester) Date: Thu, 07 Aug 2003 15:08:09 +0200 Subject: Installation problem Message-ID: Hi, I just installed Python2.2.3 and Tcl8.4. When starting idle.py I get the error messgae that no usable init.tcl could be found. Python seems to look in a directory named ../tcl8.3. How can I tell Python to use Tcl8.4 (I tried to download Tcl8.3 at www.scriptics.com but when trying to download Tcl8.3 I end up with Tcl8.4). Thanks in advance Rolf Wester From ajsiegel at optonline.net Wed Aug 27 18:07:47 2003 From: ajsiegel at optonline.net (Arthur) Date: Wed, 27 Aug 2003 18:07:47 -0400 Subject: Celebrity advice Message-ID: <000701c36ce7$a6ff24d0$0c02a8c0@Arts> Lulu writes - ] >ESR's "arguments" boil down to: (1) Wow, isn't it fun hearing guns make >a loud bang; (2) Oh yeah, be careful not to point them at people by >accident; (3) This bunch of invented history kinda-sorta supports my >nutsiness, if you squint and don't think about it too hard; (4) Did I >mention that I like to hear loud bangs? Eric Raymeond at http://armedndangerous.blogspot.com/ ""There are some books so bad, but so plausible and influential, that periodically trashing them in public is almost an obligation. The really classic stinkeroos of this kind, like Karl Marx's Das Kapital, exert a weird kind of seduction on otherwise intelligent people long after their factual basis has been completely exploded.""" I gotta go with with Eric on this. Lulu can correct me if I am wrong, but links from Lulu's site has led me to understand him to be an avowed "otherwise intelligent person". We all knew this kind of discussion would lead to no good. Even to my own eventual involvment. But the rule I had set to myself, would be to comment only upon Lulu's comment, and only if that comment was something other than to the effect that one's politics might be irrelevent here, and that the advice to a new programmer to eschew Raymond because of his was .. bad advice. That being *my* comment. Art From neel at mediapulse.com Tue Aug 19 19:16:27 2003 From: neel at mediapulse.com (Michael C. Neel) Date: Tue, 19 Aug 2003 19:16:27 -0400 Subject: Why does this (not) work? Message-ID: Maybe I should phrase the question a bit differently, more to the real issue (I guess, it's all academic from here), why is the % operator used both for string formatting and remainders? To me: >>>"%d" % 2 * 3 "222" Is not what I expected nor wanted. I could however be alone in that opinion. I'm selfish; as a programmer I don't really care about the internals of the parser, I care about ease to code - that's what I like about python, I don't spend time debugging syntax, but working on the logic of the program. It's probably not hard to guess I don't like ', '.join(list) either ;-) thanks for all the replies though! Mike From wtrenker at shaw.ca Mon Aug 18 07:28:47 2003 From: wtrenker at shaw.ca (William Trenker) Date: Mon, 18 Aug 2003 11:28:47 +0000 Subject: What's better about Ruby than Python? In-Reply-To: References: Message-ID: <20030818112847.276e1bde.wtrenker@shaw.ca> On Mon, 18 Aug 2003 03:11:20 -0600 Andrew Dalke wrote regarding Re: What's better about Ruby than Python?: > java group:comp.lang.python from Jan 1, 2003 to today. 1,680 > perl group:comp.lang.python from Jan 1, 2003 to today. 1,550 > tcl group:comp.lang.python from Jan 1, 2003 to today. 470 [etc.] c++ group:comp.lang.python from 1 Jan 2003 to today. 2,630 (for what it's worth) Bill From sjmachin at lexicon.net Fri Aug 8 18:07:34 2003 From: sjmachin at lexicon.net (John Machin) Date: 8 Aug 2003 15:07:34 -0700 Subject: Need elegant way to cast four bytes into a long References: <3f33c209$1@news.si.com> Message-ID: Skip Montanaro wrote in message news:... > wsh> I have been getting what I want in this sort of manner : > > wsh> l = 0L The above line is redundant. > wsh> l = a[0] > wsh> l += a[1] << 8 > wsh> l += a[2] << 16 > wsh> l += a[3] << 24 > > wsh> but I think that's too wordy. Is there a more intrinsic and > wsh> elegant way to do this? > > You mean like this: > > l = long(a[0] + a[1] << 8 + a[2] << 16 + a[3] << 24) > Bzzzzzt. Oh the joys of operator precedence! Python 2.2.3 (#42, May 30 2003, 18:12:08) [MSC 32 bit (Intel)] on win32 >>> a = range(0x11,0x55,0x11) >>> hex(a[0] + a[1] << 8 + a[2] << 16 + a[3] << 24) '0x0' >>> hex(a[0] + (a[1] << 8) + (a[2] << 16) + (a[3] << 24)) '0x44332211' >>> hex(a[0] | a[1] << 8 | a[2] << 16 | a[3] << 24) '0x44332211' See http://www.python.org/doc/current/ref/summary.html From bshomer at yahoo.com Wed Aug 6 13:53:49 2003 From: bshomer at yahoo.com (Benny Shomer) Date: Wed, 06 Aug 2003 20:53:49 +0300 Subject: PIL: Dashed lines & Patterned Fills - HOWTO??? Message-ID: Hi, After a lot of agony ;-) I'm converting some old and important code to use PIL instead of gd. All is well, but I couldn't figure out how to create either dahsed lines, or a fill with pattern. What I need is actually a substitute to gd's (for example): "gd.setStyle([grey50, gd.gdTransparent, gd.gdTransparent, gd.gdTransparent]" and then running a line or filledRectangle using "gd.gdStyled" Any help will be greatly appreciated. Also, kindly Cc: your answer to bshomer at yahoo.com A Billion Thanks, Benny. From mis6 at pitt.edu Sat Aug 9 09:30:40 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 9 Aug 2003 06:30:40 -0700 Subject: CLI+GUI References: <2259b0e2.0308080948.5a95e383@posting.google.com> Message-ID: <2259b0e2.0308090530.7519f195@posting.google.com> mis6 at pitt.edu (Michele Simionato) wrote in message news:<2259b0e2.0308080948.5a95e383 at posting.google.com>... > I wonder what is the recommended way of using Tkinter > together with a command line oriented application. Replying to myself ... I tried to implement what I discussed in my previous mail via the threading module: #cmdriven.py import Tkinter as t import cmd,threading root=t.Tk() s=t.StringVar() s.set('ciao') label=t.Label(root,textvariable=s) label.pack() class Cmd(cmd.Cmd): def do_display(self,arg): s.set(arg) def do_quit(self,arg): root.quit() return 'quit' # anything <> None will do the job def cmdloop(stringvar): try: Cmd().cmdloop() finally: pass # gracefully exit if sometimes goes wrong thread=threading.Thread(target=cmdloop,args=(s,)) thread.start() root.mainloop() It works if I do something like $ python cmdriven.py (Cmd) display hello (Cmd) display It works! (Cmd) quit However, I wonder if this is a robust solution and if I should expect problems in more complicate situations (some time passes ... I have just discovered that this script hangs under Windows 98!) BTW, I have another question, why the Cmd class does not have a default quit method? Looking at the source I see that any method returning something different from None will stop the command loop, and so I have used this hack, but I don't like it. Maybe I have missed something in the documentation? Thanks, Michele From adalke at mindspring.com Wed Aug 20 17:53:41 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Wed, 20 Aug 2003 21:53:41 GMT Subject: What's better about Ruby than Python? References: <3F41505F.69D18CC8@alcyone.com> <66d7kvonvb2n0nqbqahhd5roak7ur81sob@4ax.com> Message-ID: Doug Tolton: > explicitly that you are using Macros. Why is that such a *huge* > issue? Why is it that the very *existence* of a Macro in a program > would offend your sensibilities? Since you reject the reasons both Alex and I give against macros, it's kinda hard to come up with another one which you will accept. > I tend to disagree on this point. I like the idea of being able to > treat commonly reused idioms as if they are a part of the language. A basic idea of Python is that Python is not enough for everything. I need to write some extensions for Python in C. If you accept that Python is not a language unto itself, then you open yourself to the idea that if you want a new idiom you could add it to your implementation of Python. If you really, really think that list.sort() should return the sorted list, then it's an easy change to the C code. If you want a if-the-else expression, then you can get the patch for just that from sourceforge and apply it to your copy. C, then, is CPython's macro language. Why not take that approach? If your idiom is that commonly used, won't be be worth your while? > I don't think the natural state of human > beings is singular in purpose or design. I think the natural state of > humans is to fracture into competing camps / factions. *Every* human > system of any size has factions of some sort or another. I think the > power of Unix / Linux in general has been in working to allow these > factions to Co-exists peacefully. By trying to prevent factioning > within the community, I think you will ultimately only be successful > in driving people with different viewpoints out of the community. The 'natural' size of those groups is a tribe, with about 30-50 people. Humans lived that way for a long, long time. As I understand it, the hunter/gatherer cultures were pretty violent. If you aren't a relative you're the enemy. That changed, and we developed ways to live together, though we are no longer free to kill people who diss us. Restrictions have proved helpful. But computers are different in some respect. There is great freedom, because there are few negative consequences. (Negative for life or death, that is.) People are free to band together in small groups, forgetting that by doing so they ignore certain advantages of scale. Unix was definitely one of those, despite your assertion. Or have you forgotten the Unix wars of the 80s? Linux as well, unless you've forgotten the huge number of Linux distribution companies in the mid- 90s? (I remember the confusion of having to select from Slackware vs. RedHat vs. ...) Not having to choose, and depending on certain assumptions, lets you focus on new things instead of having to think about the basics all the time. Of course it's wrong to ignore the basics. But computers are wonderful (just like math) precisely because it is still possible for a few people or even one to explore new or forgotten paths. If you want macros, there's Lisp or Scheme or Dylan. If you want other idioms, you could add them yourself. And if they are useful enough, others will (slowly, all too slowly) use them. Personally, I am rather annoyed that there hasn't been the next great language. Back in the 80s and 90s I learned quite a few languages: BASIC -> Pascal -> C -> "unix" (shell&awk&...) -> Tcl -> Perl -> Python. Each one seemed more and more powerful and flexible and usable. But I've not seen any new language since 1995 (when I looked at Python) to tweak my interest. I will grant that Lisp or Scheme is the end-all and be-all of languages. Where's the language between those and Python? > Again, I disagree. It appears to me as though you've had some near > death experience with Macros that left a sore taste in your mouth. > Could you elaborate some on what your experience has been that turned > you so definitively sour on Macros? Or rather, it appears that Alex has observed problems with macros (possibly in his projects, possibly from learning about other's experiences) and decided that the advantages are not worth it. That doesn't mean he himself needed a near-death experience. It is possible to have a well-formed opinion that grabbing a live power line which fell during a storm is a bad idea without having done it before. That's another one of those things that let us have a multi-billion population civilization ;) Andrew dalke at dalkescientific.com From jarrodhroberson at yahoo.com Tue Aug 12 14:34:51 2003 From: jarrodhroberson at yahoo.com (Y2KYZFR1) Date: 12 Aug 2003 11:34:51 -0700 Subject: Python should try to displace Java References: Message-ID: "Brandon J. Van Every" wrote in message news:... > Microsoft developers don't do much C++ development anymore. this comes from someone who says they have avoided C++ their entire career. qualified opinon if I every heard one! From martin.drautzburg at web.de Sat Aug 16 03:39:55 2003 From: martin.drautzburg at web.de (Martin Drautzburg) Date: 16 Aug 2003 00:39:55 -0700 Subject: The Paradise anti pattern Message-ID: <348229d8.0308152339.35120bd2@posting.google.com> This might be amusing for a Python programmer: http://www.seedwiki.com/page.cfm?doc=TheParadisePattern&wikiid=2572&wpid=0 (It is very sarcastic and somewhat anti-Java) From aleax at aleax.it Sun Aug 3 17:32:10 2003 From: aleax at aleax.it (Alex Martelli) Date: Sun, 03 Aug 2003 21:32:10 GMT Subject: looking for win32 (or cross-platform) midi module References: <3F2B84C9.5050507@mxm.dk> Message-ID: dan wrote: > Max M wrote in message news:<3F2B84C9.5050507 at mxm.dk>... >> dan wrote: >> > is there anything like the nice midipy.pyd, but up to date (ie works > >> > 2.0)??? >> >> >> No >> >> regards Max M > the website (http://www.josos.org/midipy/) says: > > "MidiPY - real-time MIDI input module for python (win32) - If someone > can compile for newer python versions, please!" > > So modules need to be recompiled every time a major release comes out? On Windows, yes. Each .PYD refers to the specific python DLL it was compiled for, e.g. PYTHON20.DLL, so if you're using PYTHON22.DLL or whatever other than PYTHON20.DLL you'll indeed need a recompile. On other architectures, not necessarily. > There's a .cpp file in midipy.zip but no instructions, makefile, > includes, project files etc. I think you mean midipy20.zip (the apparently slightly older midipy.zip which can also be found on the net has a .pyd and a readme, while the midipy20.zip adds a .cpp as well). Unfortunately, to rebuild that cpp you apparently also need the "OSC library" presumably from: http://www.pvv.org/cgi/thammer/soundlink_download2.pl/http://www.pvv.org/~thammer/localfiles/software/osc11.zip [looks like a strange URL but it's the one I found on that "hammer" site] or perhaps an earlier version (I wouldn't know). Once you do have that, rebuilding the .pyd from the .cpp shouldn't be any harder (assuming you do have VC++ 6 installed) than writing and using the usual setup.py file for extension building, as documented on the Python online manuals and elsewhere. Alex From jjl at pobox.com Mon Aug 18 14:49:54 2003 From: jjl at pobox.com (John J. Lee) Date: 18 Aug 2003 19:49:54 +0100 Subject: Watchdog technique References: Message-ID: <87n0e6dcml.fsf@pobox.com> Terry Hancock writes: > Hi all, > I have a program in a webserver environment that needs to run a fairly > intensive calculation, which involves C extension calls (image processing > with PIL). Most of the time, this works fine, but every once in awhile the > calculation will hang, and I can't afford to wait for it (it's better to > ditch it and get no result). This is a classic "heartbeat" or "watchdog" > problem. [...] Run it in a separate process? There's a watchdog recipe in the AS Cookbook that I guess you could incorporate into your main app. John From nico-NoSp at m-tekNico.net Fri Aug 22 02:10:40 2003 From: nico-NoSp at m-tekNico.net (Nicola Larosa) Date: Fri, 22 Aug 2003 08:10:40 +0200 Subject: The snake bot Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Ladies and gentlemen, the snake bot: Robot spy can survive battlefield damage http://www.newscientist.com/news/print.jsp?id=ns99994075 Slashdot discussion: Learning Robots http://science.slashdot.org/article.pl?sid=03/08/21/135249&mode=nested&threshold=4 - -- "Oh, and it would be a shame if the [spammers'] spiders went through this whole page and only found uce at ftc.gov, rhundt at fcc.gov, jquello at fcc.gov, sness at fcc.gov, president at whitehouse.gov, and rchong at fcc.gov ." Fyodor Nicola Larosa - nico-NoSp at m-tekNico.net -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (GNU/Linux) iD8DBQE/RbPcXv0hgDImBm4RAr2eAJ9p3UwsoS/Vtc0xFzKmUxAI4i06LgCghYrl bOtd0HsBy71GCNXxhH4liBg= =5eDZ -----END PGP SIGNATURE----- From s0199583 at sms.ed.ac.uk Tue Aug 12 04:39:16 2003 From: s0199583 at sms.ed.ac.uk (Matt Smith) Date: 12 Aug 2003 01:39:16 -0700 Subject: variant com issues/problems in python Message-ID: <5f5c82ec.0308120039.4982363a@posting.google.com> Hi, all. Just a quick question, when setting a COM process to read a value from a pre-defined register index, I think, I have to change the variable that the value will be returned to (as I have to do for the same function in perl), into a VARIANT, However when i run the variant code.... 'serialIndex = win32com.client.pythoncom.VT_VARIANT' no matter what extension I use (i.e. VT_I4 or VT_BOOL etc etc) it still returns a type mismatch error. I may be doing something wrong or getting confused with variant processes in python. I do know the code I use in perl to do this works but I dont know how to translate this, fully, into python. perl code for variant = Win32::OLE::Variant::Variant(Win32::OLE::Variant::VT_VARIANT|Win32::OLE::VARIANT::VT_BYREF, 0) Cheers in advance, Matt From pu Sat Aug 16 19:15:13 2003 From: pu (Patrick Useldinger) Date: Sun, 17 Aug 2003 01:15:13 +0200 Subject: asynchat question Message-ID: <3f3ebaa8_2@news.vo.lu> I am trying to write both a server and a client using asynchat. For both, I have created a common subclass to collect the incoming data: class SingleServer(asynchat.async_chat): def __init__(self,*args): asynchat.async_chat.__init__(self,*args) self.set_terminator(BLOCKEND) self.data=[] def collect_incoming_data(self,data): self.data.append(data) def found_terminator(self): self.processData(''.join(self.data)) self.data=[] The server works well, it waits for a connection and sends a response. class SecondaryServer(SingleServer): def processData(self,data): response='??' peer=self.getpeername() print now(),'from %s received %s' % (peer,repr(data)) if data == 'quit': if peer[0]=='127.0.0.1': response='OK' dispatcher.close() else: response='KO' response=response+' '+data print now(),'to %s responding %s' % (peer,repr(response)) self.push(response+BLOCKEND) However, I am having trouble with the client, who is supposed to send a question and get an answer in return: class Server(SingleServer): def __init__(self,message,*args): SingleServer.__init__(self,*args) print now(),'connecting to EB on %s:%s' % (EBHost,EBPort) self.create_socket(socket.AF_INET,socket.SOCK_STREAM) self.connect((EBHost,EBPort)) def handle_connect(self): print now(),'sending %s' % repr(message) self.push(message+BLOCKEND) def processData(self,data): print now(),'received "%s"' % repr(response) self.close() # XXX is socket closed by base class? Server(message) The client connects and send his question. The server answers, but the client never receives an answer. On the server side, I receive the following message: error: uncaptured python exception, closing channel __main__.SecondaryServer connected 127.0.0.1:3432 at 0x7fc968> (socket.error:(10053, 'Software caused connection abort') C:\Python23\lib\asynchat.py|handle_read|88] [C:\Python23\lib\asyn core.py|recv|353]) Can anyone explain why? -- Real e-mail address is 'cHVAdm8ubHU=\n'.decode('base64') Visit my Homepage at http://www.homepages.lu/pu/ From timfm at hawaii.rr.com Fri Aug 1 23:18:27 2003 From: timfm at hawaii.rr.com (Timothy Martens) Date: Fri, 01 Aug 2003 17:18:27 -1000 Subject: 2.3 win installer Message-ID: <3F2B2D83.2020907@hawaii.rr.com> Well - thanks for the suggestions everyone, but I still have had no luck. I tried redownloading with the same results (installer freezes at 1% when it's copying the first file to c:\python32\UNWIZ.exe (unistall wizard I assume, how ironic). I don't have any virus protection running currently. The only thing I can think that may be interfering is my firewall software (tiny forewall 5.0), which also monitor's windows activity, but I did quit it and made sure to shut down it's processes. The more I use it, the more I'm thinking about asking for my money back and reverting to their free 2.0 version. I give up, BUT there's a new box on the way from Dell, so I'll give it shot on that one. tim From adalke at mindspring.com Thu Aug 21 14:43:18 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Thu, 21 Aug 2003 18:43:18 GMT Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> <6dj2kv8ugkieehs7guh786cl40o5lj6mcs@4ax.com> Message-ID: Jacek Generowicz: > The alternative is to understand (and subsequently recognize) the > chunks of source code implementing a given patten for which no > abstraction was provided (often implemented slightly differently in > different parts of the code, sometimes with bugs), each time that it > occurs. Agreed and understood. My understanding of macros were that they provide flexibility beyond what classes could do. However, at present, the only example I've seen for when to use a macro came from a method cache implementation that I could implement in Python using the normal class behaviour, so I don't have a good idea of when macros would be appropriate *for* *Python*. When this topic has come up before, others mentioned how macros would theoretically be able to, say, modify list.sort to return the sorted list after it has been modified in-place. Given the not infrequent request for the feature, I know that if it was allowed, then some of my clients would have done that, making it harder for me to know if what I'm looking at is core Python behaviour or modified. What you say is true, but most of the code I look at is based on fundamental Python types, from which I can be assured of fixed behaviour, or classes and functions, where I can be assured that they are free to do their own thing. The patterns of behaviour are fixed and the opportunities for change well defined. Macros, as I understand it, blurs those lines. > > The inference is that programming language abstractions should not > > be more attractive than sex. > > Why ever not? Don't you want to put the joy back into programming :-) Mmmm, I've reached the point in my life where the importance of social interactions and community building is starting to outweigh my interests in programming all the time. Plus, programming in Python is pretty joyful. It fits my mind quite nicely. > I don't believe you can reasonably draw a rigid and well-defined > boundary between functions, modules and objects on one side, and > macros on the other. They all offer means of abstraction. All are open > to abuse. All can be put to good use. I never said macros couldn't be put to good use. Let me repeat a statement I made in another post on this topic. I will grant that Lisp or Scheme is the end-all and be-all of languages. Where's the language between those and Python? Is it possible to have a language which is more flexible than Python but which doesn't encourage the various dialectization historically evident in the Lisp/Scheme community? Could most macros also be written without macros, using classes or lambdas? How often are the benefits of macros that much greater than classes&functions to merit their inclusion. Does it take skill to know when to use one over the other? Do people use macros too often? When do they hinder misunderstanding? Are they more prone to misuse than classes&functions? You say that macros can be put to good use, *and I believe you*. I say that their specific advantages over classes is rare enough that having an extra mechanism for implementing behaviours does not warrant their inclusion into Python - a language designed with an emphasis on readability and usability over the extreme flexibility emphasis from Lisp - given the statements made by people here with strong Lisp backgrounds on how using those seductive macros made it harder to share code with outsiders. > In all four cases, I'd rather have the opportunity to create > abstractions, rather than not. The complaint about macros has been their tendency to increase a single person's abilities at the cost of overall loss in group understanding. I've heard references to projects where that didn't occur, but am not swayed by it because those seem staffed by people with extraordinarily good programming skills almost never found amoung the chemists and biologists I work with. > I find your suggestion that macros are in some way more "domain > specific" than modules, or objects or functions, bogus. Sorry? I thought one of the main points of macros is that they allow additional flexibility to customize the language as appropriate for a given domain. Now you say that that's not the case? > You are confusing the issues of > > - extensibility, > - standard non conformance, > - not starting from a common base, > - languages defined my their (single) implementation. Indeed, and to some extent deliberately. The point I'm trying to make is that different, very smart people like "Lisp", but insist on variations. There is clisp and elisp and scheme and guile and ... a long list of Lisps. As I understand it, macros can be used to make one lisp variation act like another. Given that, the conculsion I infer is that different, very smart people would use macros to make Python more "right", even though there's different perceptions of what is "right." > A few days ago I tested out a C++ library. It didn't work on the C++ > system I had handy because the STL implementation was > different/template support was different. etc. etc. Did you really or are your making that up for the sake of rhetoric? > A few days ago I tested out a Python library. It didn't work on the > implementation I had handy because it was Jython. Ditto. That's not to say you couldn't have those problems. I just don't like you making up a response in the face of something what did actually occur. If it takes more than four decades for different Lisp implementations to agree on how to import a module, then I think there's a problem. And I believe that that problem is that too many peole who make a Lisp do it because they have a feeling they know what is right vs. wrong, and emphasize boosting personal abilities over group ones, and that tendency is magnified by the inclusion of macros. > So, what you are saying is that faced with the alternatives of > > a) Tweaking an existing, feature rich, mature, proven language, to > move it "closer" to your domain. > > b) Implementing a new language from scratch, for use in a single > domain > > you would choose the latter? False dichotomy. I needed to evalute a user-defined expression where the variable names are computed based on calling an associated function. The functions may take a long time to compute and most names are not used in an expression, so I want to compute the names only when used. This is different from Python because Python's exec wants all the variable names defined first. Hence, this is a new language. Did I start from scratch? No! I used Python to build the parse tree then tweaked a few nodes of that tree to change the name lookup into the right form, then generated the function from that parse tree. The syntax was the same as Python's, but the behaviour different. Though back at the Python level, it's a "call this function to get the needed result", and has precisely the same nature as any other Python function would have. > If so, you are choosing the path which pretty much guarantees that > your software will take much longer to write, and that it will be a > lot buggier. Indeed. And that would be silly. Luckily, you didn't think of all the alternatives available to me. And some languages are not-at-all close to Python. Eg, I wanted to implement a domain-specific language called MCL using my PyDaylight package. I ended up writing a parser for MCL and converting the result into Python code, then exec'ing the Python code. I would not want to write a macro for Python to support MCL natively. Blech! Similarly, SMILES is a language for describing molecules. It isn't a programming language at all, so I just write a parser for it. I once made a language for manipulating molecules. It was a a simple command language with syntax like load "abc.pdb" into a select "resname LYS" from a into b save b as "lysine.pdb" I wrote it in Perl, but didn't want the language to be part of Perl (nor of Python). It wasn't a Perl library because Perl's syntax was too complicated for the target audience. It wasn't very powerful because it only needed to load a molecule, select portions of the molecule, select subsets, copy, rotate and translate sets of atoms, and save a set to a file. Why in the world would I want to extend Lisp/Perl/Python/ whatever to support that language directly? > It's an extreme form of Greenspunning. ??? Apparantly not Alan Greenspan. Google yields 4 hits (3 if I exclude your post). It seems to be "writing a lot of code yourself instead of using existing packages" Then you don't know me works at all and are making unjustified comments based on false preconceptions. > How do you reconcile ... > You criticize macros for not encouraging code sharing (they do, by > encouraging you to share the (vast) underlying language while reaching > out towards a specific domain), while your preferred solution seems to > be the ultimate code non-sharing, by throwing away the underlying > language, and re-doing it. Because you assume when I say "language" that I mean a powerful language like Lisp or Python when it's really a domain specific languages which often aren't even Turing complete or even a programming language, and which are easy to convert into Python, and designed for someone with only a little programming experience. Please tell me how you would implement this language load "abc.pdb" into a select "resname LYS" from a into b save b as "lysine.pdb" as a macro in Lisp. I'll assume 'load-pdb' loads a PDB file into a object which holds a set of atoms, and that object has the method 'select-atoms' which creates a new (sub)set and also has the method 'save-as' for saving those atoms in the right format. And the above is all that the user can type. How in the world does macros make handling that language any easier than the standand parser-based non-macro solution? Andrew dalke at dalkescientific.com From skip at pobox.com Mon Aug 4 14:54:44 2003 From: skip at pobox.com (Skip Montanaro) Date: Mon, 4 Aug 2003 13:54:44 -0500 Subject: python 2.3 final In-Reply-To: <3F2E81FC.4040903@vt.edu> References: <3F2E81FC.4040903@vt.edu> Message-ID: <16174.44020.519615.677559@montanaro.dyndns.org> >> I'm new to Python. I have been using 2.3b2 for several months now >> with good results. I assumed that once the beta was good enough that >> Python 2.4 would be released, but today I noticed that there is a 2.3 >> final release. I'm used to odd point releases being beta or testing, >> but it seems that that isn't true in Python. Could someone shed some >> light on this? Python's pre-release numbering works like this: M.Na1, M.Na2, ... alpha 1, alpha 2, etc (2.3a1, ...) M.Nb1, M.Nb2, ... beta 1, beta2, etc (2.3b2, ...) M.Nc1, ... release candidate 1, etc (2.3c1, ...) M.N final release (2.3 or more precisely, 2.3.0) M.N.1a1, M.N.1a2, ... more alphas (2.3.1a1, ...) M.N.1b1, M.N.1b2, ... more betas (2.3.1b1, ...) M.N.1c1, ... more release candidates (2.3.1b1, ...) M.N.1 next release (2.3.1) So, for several months you've been using the second beta test version of Python 2.3. You should upgrade to 2.3, even though it naively appears to be an "older" version. Skip From newsgroups at jhrothjr.com Mon Aug 18 16:29:42 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Mon, 18 Aug 2003 16:29:42 -0400 Subject: What's better about Ruby than Python? References: Message-ID: "Andrew Dalke" wrote in message news:bhq501$a98$1 at slb6.atl.mindspring.net... > How many Ruby programmers (per capita) do you know talking about > Python? Perhaps Python "has the potential to ...display Ruby" You might try getting onto some other newsgroups and mailing lists that deal with more general (not language specific) issues and find out exactly what people are saying. On the XP mailing lists my general impression is that the Ruby programmers outnumber the Python programmers, and a fair number of them came from a Python background. > How many Python-aware programmers do you know who also talk > about Java? Also talk about C#? About C++? About BASIC? Lots. Most of the people on the XP lists use multiple languages, and are quite vocal about it in the appropriate circumstances. John Roth From ialbert at mailblocks.com Mon Aug 11 14:40:39 2003 From: ialbert at mailblocks.com (Istvan Albert) Date: Mon, 11 Aug 2003 14:40:39 -0400 Subject: Fun with numbers - dammit, but I want a cast! In-Reply-To: References: <3f378fac$0$10778$afc38c87@auth.uk.news.easynet.net> Message-ID: Andrew Koenig wrote: > > Python is going to change its behavior so that division always > returns a floating-point value. This statement causes that new > behavior to occur now. Will there be a keyword/function for integer division after that? Not that my opinion has any weight in this matter, but I got used to integer division as default behavior after all C, and java work that way too, it is not like it is a pythonic oddity. Once it gets implemented then there will be numerous questions about doing integer division. Istvan. From ryanlowe0 at msn.com Tue Aug 19 20:31:27 2003 From: ryanlowe0 at msn.com (Ryan Lowe) Date: Wed, 20 Aug 2003 00:31:27 GMT Subject: for statement list comprehension-like extention proposal Message-ID: i thought id ask here before wirting a PEP, if people thought it would be a good enhancement to allow if clauses in regular for-statements like so: >>> for x in y if x < 10 : is semantically equivalent to >>> for x in [x for x in y if x < 10] : but is shorter and easier to read. basically, the if works as a filter for the values in the iterator. its not a major change, purely syntactic sugar. and clearly backwards-compatible. seem reasonable? ryan From mpeuser at web.de Fri Aug 29 10:54:04 2003 From: mpeuser at web.de (Michael Peuser) Date: Fri, 29 Aug 2003 16:54:04 +0200 Subject: Copying a PIL image to windows clipboard? References: <10ebb92.0308211823.6fe428f7@posting.google.com> Message-ID: "News M Claveau /Hamster-P" schrieb im Newsbeitrag news:bij45g$njv$1 at news-reader5.wanadoo.fr... Maybe you should have a look into win32 which will give you full controll of the clipboard: Here is the example code from Mark Hammond's demos. Of course you have to find out a format which is understood by the programms you want to paste the images in. But PIL is very good in converting formats ;-) Kindly Michael P # win32clipboardDemo.py # # Demo/test of the win32clipboard module. from win32clipboard import * import win32con import types if not __debug__: print "WARNING: The test code in this module uses assert" print "This instance of Python has asserts disabled, so many tests will be skipped" cf_names = {} # Build map of CF_* constants to names. for name, val in win32con.__dict__.items(): if name[:3]=="CF_" and name != "CF_SCREENFONTS": # CF_SCREEN_FONTS==CF_TEXT!?!? cf_names[val] = name def TestEmptyClipboard(): OpenClipboard() try: EmptyClipboard() assert EnumClipboardFormats(0)==0, "Clipboard formats were available after emptying it!" finally: CloseClipboard() def TestText(): OpenClipboard() try: text = "Hello from Python" SetClipboardText(text) got = GetClipboardData(win32con.CF_TEXT) assert got == text, "Didnt get the correct result back - '%r'." % (got,) # Win32 documentation says I can get the result back as CF_UNICODE or CF_OEMTEXT. # But it appears I need to close the clipboard for this to kick-in. # but if I attempt to, it fails! finally: CloseClipboard() OpenClipboard() try: got = GetClipboardData(win32con.CF_UNICODETEXT) assert got == text, "Didnt get the correct result back - '%r'." % (got,) assert type(got)==types.UnicodeType, "Didnt get the correct result back - '%r'." % (got,) got = GetClipboardData(win32con.CF_OEMTEXT) assert got == text, "Didnt get the correct result back - '%r'." % (got,) # Unicode tests EmptyClipboard() text = u"Hello from Python unicode" # Now set the Unicode value SetClipboardData(win32con.CF_UNICODETEXT, text) # Get it in Unicode. got = GetClipboardData(win32con.CF_UNICODETEXT) assert got == text, "Didnt get the correct result back - '%r'." % (got,) assert type(got)==types.UnicodeType, "Didnt get the correct result back - '%r'." % (got,) # Close and open the clipboard to ensure auto-conversions take place. finally: CloseClipboard() OpenClipboard() try: # Make sure I can still get the text. got = GetClipboardData(win32con.CF_TEXT) assert got == text, "Didnt get the correct result back - '%r'." % (got,) # Make sure we get back the correct types. got = GetClipboardData(win32con.CF_UNICODETEXT) assert type(got)==types.UnicodeType, "Didnt get the correct result back - '%r'." % (got,) got = GetClipboardData(win32con.CF_OEMTEXT) assert got == text, "Didnt get the correct result back - '%r'." % (got,) print "Clipboard text tests worked correctly" finally: CloseClipboard() def TestClipboardEnum(): OpenClipboard() try: # Enumerate over the clipboard types enum = 0 while 1: enum = EnumClipboardFormats(enum) if enum==0: break assert IsClipboardFormatAvailable(enum), "Have format, but clipboard says it is not available!" n = cf_names.get(enum,"") if not n: try: n = GetClipboardFormatName(enum) except error: n = "unknown (%s)" % (enum,) print "Have format", n print "Clipboard enumerator tests worked correctly" finally: CloseClipboard() class Foo: def __init__(self, **kw): self.__dict__.update(kw) def __cmp__(self, other): return cmp(self.__dict__, other.__dict__) def TestCustomFormat(): OpenClipboard() try: # Just for the fun of it pickle Python objects through the clipboard fmt = RegisterClipboardFormat("Python Pickle Format") import cPickle pickled_object = Foo(a=1, b=2, Hi=3) SetClipboardData(fmt, cPickle.dumps( pickled_object ) ) # Now read it back. data = GetClipboardData(fmt) loaded_object = cPickle.loads(data) assert cPickle.loads(data) == pickled_object, "Didnt get the correct data!" print "Clipboard custom format tests worked correctly" finally: CloseClipboard() if __name__=='__main__': TestEmptyClipboard() TestText() TestCustomFormat() TestClipboardEnum() # And leave it empty at the end! TestEmptyClipboard() From jacek.generowicz at cern.ch Tue Aug 26 03:09:57 2003 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 26 Aug 2003 09:09:57 +0200 Subject: macro FAQ References: <840592e1.0308251252.74382e29@posting.google.com> Message-ID: hanzspam at yahoo.com.au (Hannu Kankaanp??) writes: > if y > self.y - bs and y < self.y + bs + self.height: > return (abs(x - self.x) < bs, > abs(x - (self.x + self.width)) < bs) > else: > return False, False > > > and then > > > if x > self.x - bs and x < self.x + bs + self.width: > return (abs(y - self.y) < bs, > abs(y - (self.y + self.height)) < bs) > else: > return False, False > > Obviously this was quite unsatisfactory. I ended up > putting the axis code in a separate class Do you mean "function" rather than "class" ? > so I could > use them interchangeably. I.e. If I passed > func(self.y, self.x) > and then > func(self.x, self.y) > > I would get the same effect on both axises. But this > would've been an excellent place for macros IMO I don't see what you gain by using a macro, wrt to using a function in _this_ case. As no Python macro system exists, I cannot form an opinion of what the two approaches would look like in Python, but in Lisp the calls to the macro would look just like the calls to the function, I think. The only difference would be in the definition of the macro/function, and the macro would be no simpler, so you wouldn't really gain anything. > Using macros > that combine both function call and "code block" syntax, > I could've written a simple function like this: > > defBoth getSize(self): > return self.size > > And it would've been expanded to > > def getWidth(self): > return self.width > > def getHeight(self): > return self.height > > The macro would've had to change all "size" to either > "width" or "height", and also change "pos" to either "x" > or "y" and so on. So you would not only replace whole symbols, but even fragments of symbols (getSize -> getHeight), and thus macically/implicitly create new symbols. Many people consider this bad practice. The objection being that readers of the code come across a symbol in the source, go off and search for its definition, and tricks like this mean that they end up wasting their time. The defstruct macro does this sort of thing; (defstruct foo ... ) would "magically" define a constructor called "make-foo" (and other stuff). IIRC, the experience with defstruct led the designers of CLOS to explicitly avoid doing this in CLOS' defclass macro (but I'm far from the world's leading authority on Lisp history). Incidentally, in this case, having a string based code representation would make your job much easier than the structured representation which Lisp uses. In a string you'd merely do a search and replace; in an s-expression you would have to recursively search for all symbols in all sub-expressions, and then do the search and replace within the name of each symbol you find. > This way, I could've got no duplicated code but > also a more intuitive interface than I currently have > (to get width, one needs to type obj.x.getSize() instead > of obj.getWidth()). And it's obvious this kind of "defBoth" > wouldn't be added as a language level construct -- Thus > macros are the only good solution. Cue metaclass solution ... :-) (I suspect that even with metaclasses, you wouldn't be able to avoid eval ... and that amounts to "informally" writing a macro) From rnd at onego.ru Wed Aug 6 00:26:02 2003 From: rnd at onego.ru (Roman Suzi) Date: Wed, 6 Aug 2003 08:26:02 +0400 (MSD) Subject: Adding PC Filename Extensions to Macintosh Filenames In-Reply-To: <3F306BC5.7000608@vt.edu> Message-ID: On Tue, 5 Aug 2003, hokiegal99 wrote: >I've written a small script (with much help from this list) that >searches through a directory for files without a PC filename extension >like .doc .xls and then adds them. The reason for writing the script is >that I'm migrating several dozen Mac users to PCs over the next few >months and many of the Mac files do not have PC filename extensions. >There are thousands of these files. The script runs on a Linux ftp >server where the files are upload to. Hmmm... First of all, files from Mac contain so called resource fork, which IIRC contains type information (4-letter). So instead of trying to wildly guess file type, it is possible to get it for sure. Second, Linux has 'file' command which tells you file type based on content and knows tonns of formats. -- rnd at onego.ru =\= My AI powered by GNU/Linux RedHat 7.3 From vanevery at 3DProgrammer.com Tue Aug 19 02:17:58 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Mon, 18 Aug 2003 23:17:58 -0700 Subject: Brandon's personal style (was) References: <38ec68a6.0308172319.431a4fde@posting.google.com> Message-ID: Jack Diederich wrote: > On Mon, Aug 18, 2003 at 03:14:52PM -0700, Brandon J. Van Every wrote: >> >> Man, it's clear that I've got an entire hate group around here to >> exterminate! I wonder how long it's going to take? Maybe this is a >> positive sign of Python's growth: it's got enough critical mass to >> attract just about anybody, not just people who want to get things >> done. At any rate, welcome to my killfile. > > Never blame on malice what can be explained by stupidity. What if stupidity fosters malice? To wit: > I don't care if you write troll posts maliciously or not, I do care > that you keep sending them. The problem here is, they aren't troll posts. You just perceive them to be. Why you do, you'd have to answer for yourself. But I will hazard to guess: you don't like it when certain questions are asked. You think they are illegitimate questions, and that nobody, rationally speaking, should ask them. You think the questions will always cause trouble, that we can count on this from what we know about newsgroup behaviors, so therefore the questions should not be asked. In other words, you think you know best about how discourse should properly proceed. > So how big is that RAID that holds your killfile? Text is trivial to store on modern computers and I'm not in newsgroups *that* much. My anti-spam file is a couple of orders magnitude bigger than my killfile. Maybe 3 orders of magnitude. 4? I can't tell. Anyways, I don't think it's worth trying to work out your perceptions, so welcome to my killfile along with the rest. I am starting to wonder, if the high number of kills I've gotten in c.l.p says something about community cohesion? I mean, I get kills in *every* group I spend any time in, but the speed and volume of kills I'm getting here is novel. It's usually much more isolated and sporadic than this. I hereby pronounce c.l.p, Second Order Magnitude of community cohesion. You guys aren't all in the same pocket or parrots of each other, but there are c learly some trends. For a First Order Magnitude community cohesion, check out something really cranky and old guard like rec.arts.int-fiction. I think they still think the Internet is a DARPA project! And despite years of absence, I'm sure I'm still a favorite there. Smooches, any of that ilk lurking about. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From tjreedy at udel.edu Wed Aug 27 21:44:44 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 27 Aug 2003 21:44:44 -0400 Subject: python gripes survey References: <15dpkvsfatkrlode3rc9h1trihsb3ppcj3@4ax.com> Message-ID: "Sean Ross" wrote in message news:HE73b.2610$_F1.407684 at news20.bellglobal.com... > This is probably not what you want, and it's probably worse than just using > a global declaration, but it *is* "another way to handle this": > > >>> # put this at the top of your module, > >>> # to grab hold of this module's namespace > >>> import __main__ as main > >>> g = "global variable" > >>> def f(): > ... main.g = "re-bound global" > ... > >>> f() > >>> g > 're-bound global' Unless there is flaw neither of us see, I like this. Names bound in nested scopes are not read-only, just not rebindable. Mutables *are* writeable and immutables can be wrapped in [] or another mutable to make them effectively writable. def fun(): x=[1] print x def ny(): x[0]=2 ny() print x >>> fun() [1] [2] Slightly clumsy, but workable. Terry J. Reedy From tzot at sil-tec.gr Fri Aug 22 13:55:44 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Fri, 22 Aug 2003 20:55:44 +0300 Subject: Win32 ping References: <4cs1b.344$f7.80337@localhost> Message-ID: On Fri, 22 Aug 2003 12:12:57 -0500, rumours say that Sean Cody might have written: >Does anyone know of an ping module that will work with Windows? See Jeremy Hylton's page, at the bottom: http://www.python.org/~jeremy/python.html I have downloaded and used that module already for fellow users of the local metropolitan area wireless network. -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From furliz at libero.it Fri Aug 29 08:46:27 2003 From: furliz at libero.it (Mirco) Date: Fri, 29 Aug 2003 14:46:27 +0200 Subject: python and webcam?? Message-ID: Hi, I'd like to know if is it possible to make python communicate with a webcam. Of course, I think it is possible... but I don't know if there is a specific module for this kind of work. Can anyone give me a council? Thanks From anthonyr-at-hotmail-dot-com at nospam.com Thu Aug 28 00:14:46 2003 From: anthonyr-at-hotmail-dot-com at nospam.com (Anthony Roberts) Date: Thu, 28 Aug 2003 04:14:46 GMT Subject: Style question... References: <4cd3b.50331$la.863381@news1.calgary.shaw.ca> <3F4D63AD.FBBFCCFB@alcyone.com> Message-ID: > I think the problem is that people learn to reindent chunks of code by > the following technique: Yup. In emacs, it is robust for C and C decendants. Indent region can do it to entire files. It's good for structural modifications when you want to change some outer loop that ends up changing the indent/nesting level of some inner loop. In Java, which is where I really started to lean of that feature heavily, it comes with so *many* data structure classes that even though they mostly share interfaces, you still come up with a cleaner way later on and go back to change it. I'm finding Python is more a matter of "for x in :"... But I still change my mind sometimes. :) From imbosol at aerojockey.com Mon Aug 11 20:04:04 2003 From: imbosol at aerojockey.com (Carl Banks) Date: Tue, 12 Aug 2003 00:04:04 GMT Subject: stretching list comprehensions References: Message-ID: Simon Burton wrote: > > I was quite delighted when i found this: > >>>> nums = [ x+y for x in range(10) for y in range(10) ] > > Great! No more list of list joining shenanigans... > > Shortly thereafter, i tried this: > >>>> del y >>>> nums = [ x+y for x in range(y) for y in range(10) ] > Traceback (most recent call last): > File "", line 1, in ? > NameError: name 'y' is not defined >>>> > > Well.. Is there an inherent reason why this could/should not be made to work? Yes: you're doing it backwards. Try it this way: del x,y nums = [ x+y for x in range(10) for y in range(x) ] To understand why, think about the equivalent for loop: nums = [] for x in range(10): for y in range(x): nums.append(x+y) If you do it the other way, you can see that y is undefined before use. -- CARL BANKS "You don't run Microsoft Windows. Microsoft Windows runs you." From Zappelphillip at gmx.de Thu Aug 7 07:04:07 2003 From: Zappelphillip at gmx.de (O. Koch) Date: 7 Aug 2003 04:04:07 -0700 Subject: FTP with urllib2 behind a proxy Message-ID: <7d6b0b33.0308070304.53588bf0@posting.google.com> Until now, i know that ftplib doesn't support proxies and that i have to use urllib2. But i don't know how to use the urllib2 correct. I found some examples, but i don't understand them. Is there anyone who can help me? From amitp at theory.stanford.edu Tue Aug 19 19:34:17 2003 From: amitp at theory.stanford.edu (Amit Patel) Date: 19 Aug 2003 16:34:17 -0700 Subject: Why does this (not) work? References: Message-ID: "Michael C. Neel" writes: > > try this: > > >>> "%s - %s - %s" % (("test",)*3) > > > > why else would > > >>> 3 % 1 * 2 > > print 0 instead of 1? > > > > Jeff > > Hmmm, can't say I like what this implies. In one case % is shorthand > for a sprintf function, the other it's a mathematical expression at the > same level of precedence of * and /. But the sprintf version is > "granted" the precedence of the mathematical version? What's the logic > behind that? I think the logic behind that is that the operator precedence is assigned before we know what the types of the operands are. You could argue that since we can see it's a string, we should change the precedence. But then we'd get weird situations like print "..." % (x,)*3 not being the same as s = "..." print s % (x,)*3 You could argue that a flow analyzer could figure out that s is a string, etc., but that's going down a dangerous path -- the semantics start depending on how sophisticated your Python compiler is. Aieee! :) Some of the 'cute' syntax features of Python (% for strings, `` for repr) have bitten me more than once. :( - Amit -- Amit J Patel, Computer Science Department, Stanford University http://www-cs-students.stanford.edu/~amitp/ ``Parkinson's Other Law: Perfection is achieved only at the point of collapse.'' From Spam.Buster at web.de Sat Aug 23 17:21:02 2003 From: Spam.Buster at web.de (Lars Behrens) Date: Sat, 23 Aug 2003 23:21:02 +0200 Subject: How to store data? Message-ID: Hi there! For a web project I need a little expert help. I don't have written much code yet, just been fiddling around a bit, testing and planning. The web site will have a submission page for attendants of a congress. In a form the user will submit name, mailadress etc. and I plan to store the data in a list of dictionaries: People = [{'name' : 'Sir Galahad', 'address' : 'Camelot', 'mail' : 'Carrierpigeon at england.com'}] #new attendant: People.append({'name' : 'Brian', 'address' : 'Palestine', 'mail' : 'fastridingmessenger at rome.com'}) The 'lines' can be accessed by their index. Now my question: Where do you suggest to store the data? I know that something sql-like would be quite useful but I don't have any knowledge of sql. So I thought about putting the data either into a comma separated file or pickling it. I should mention that some other people on different operation systems should be able to import the file (Excel, Open Office) so I tend towards the csv file. What would be better? And another problem: How to lock the file when several users try to write to it? As I'm no very experienced programmer I would appreciate your help, thanks in advance Cheerz Lars From oinkfreddie at oinkshlick.oinknet Tue Aug 5 00:23:57 2003 From: oinkfreddie at oinkshlick.oinknet (Freddie) Date: 5 Aug 2003 14:23:57 +1000 Subject: yEnc implementation in Python, bit slow References: Message-ID: Oren Tirosh wrote in news:mailman.1060033689.18067.python-list at python.org: > Suggestions: > > For the (x+42)%256 build a translation table and use str.translate. > To encode characters as escape sequences use str.replace or re.sub. > > Oren Aahh. I couldn't work out how to use translate() at 4am this morning, but I worked it out now :) This version is a whoooole lot faster, and actually meets the yEnc line splitting spec. Bonus! $ python2.3 testyenc.py yEncode1 407682 1.98 yEncode2 407707 0.18 I'm not sure how to use re.sub to escape the characters, I assume it would also be 4 seperate replaces? Also, it needs a slightly more random input string than 'a' * 400000, so here we go. test = [] for i in xrange(256): test.append(chr(i)) teststr = ''.join(test*1562) def yEncode2(data): trans = '' for i in range(256): trans += chr((i+42)%256) translated = data.translate(trans) # escape =, NUL, LF, CR for i in (61, 0, 10, 13): j = '=%c' % (i + 64) translated = translated.replace(chr(i), j) encoded = [] n = 0 for i in range(0, len(translated), 256): chunk = translated[n+i:n+i+256] if chunk[-1] == '=': chunk += translated[n+i+256+1] n += 1 encoded.append(chunk) encoded.append('\n') result = ''.join(encoded) print len(result), return result -- ----------------------------------------------------------- Remove the oinks! From gduzan at bbn.com Mon Aug 18 13:59:01 2003 From: gduzan at bbn.com (Gary D. Duzan) Date: Mon, 18 Aug 2003 17:59:01 GMT Subject: What's better about Rattlesnakes than Pythons? References: <8e482ba2.0308171939.7de4a288@posting.google.com> <3F40E4F3.6010809@users.ch> Message-ID: In article <3F40E4F3.6010809 at users.ch>, Borcis wrote: >Graham Fawcett wrote: >> >> Any snake born in Java will perform better > > http://www.herpafauna.com/pics/pythons/retic-java.html > >is in the 9-meters league; no competitors, except the anaconda. > I assume they are called "jythons" for short... From alexander.dejanovski at laposte.net Tue Aug 5 02:54:16 2003 From: alexander.dejanovski at laposte.net (Alexander DEJANOVSKI) Date: Tue, 5 Aug 2003 08:54:16 +0200 Subject: Developping an EAI server in Python : looking for developpers References: <3f2e9581$0$49107$e4fe514c@news.xs4all.nl> Message-ID: <3f2f5525$0$1145$626a54ce@news.free.fr> OK, I might not have explain very much of how it works. It is an Open Adaptor-like program. The fact is that I needed a soft like OpenAd but I'm pretty deceived by it (too complicated, never gives what I'm waiting for on the other side of the adaptor). Like Open Ad, Retic (that's the name of my project), provides components (sources, pipes and sinks) that can be combined in many ways in order to retrieve data (from a source) apply changes or transformations (with pipes) and send it to several destinations (to sinks). This is driven by config files in XML that contains all components and their attributes. All parent component sends its data (after processing it) to all of its child element. So you can have trees that look like that : source | |_____pipe1 | | | |_____pipe2 | | |____sink1 | | | | | |_____sink2 | | |_____sink3 The main program is called with the config file name as argument, which starts the adaptor. When started, it will look for data in the source (for example, a fileSource has a filePath and a fileFilter arguments, that permit to look for files matching fileFilter - for ex : a*.txt - in the filePath directory). If there is nothing to process, the adaptor will wait for some time (provided in the conf file) before polling again, unless the config file says that just one poll was wanted (you can specify how many polls you want). I call it EAI server since it should permit apps that don't communicate the same way to work together, using adaptor to translate data or switch transport protocol. Hope that helps (about twisted too...) Project has been approved by sourceforge so I've just uploaded sources to CVS today (www.sourceforge.net/projects/retic) so feel free to get it and take a look. To launch it, use start.py. It will use the config file test_adaptor.xml. Required are : Python 2.3 4suite 1.0a3 and PyXML 0.8.3 "Irmen de Jong" wrote in message news:3f2e9581$0$49107$e4fe514c at news.xs4all.nl... > Alexander DEJANOVSKI wrote: > > > I'm starting a new project to develop an Open-Source EAI server in Python > > and I'm looking for motivated developpers and testers. > > It is inspired by Open Adaptor (_www.openadaptor.org_ > > ), but aims to be easier > > to use and more powerful. > > Could you please summarize what the goals of this project are? > And how it relates to Open Adaptor? (which I don't have the time > to read about). > > --Irmen > From adalke at mindspring.com Thu Aug 21 16:32:19 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Thu, 21 Aug 2003 20:32:19 GMT Subject: What's better about Ruby than Python? References: <3F41505F.69D18CC8@alcyone.com> <66d7kvonvb2n0nqbqahhd5roak7ur81sob@4ax.com> <3f43ef5d_4@127.0.0.1> <3F440A35.9030602@nyc.rr.com> <3F44CF06.4080003@nyc.rr.com> <3F4528FD.7040404@nyc.rr.com> Message-ID: Kenny Tilton: > Can a Python first-class function close over a lexical variable and use > that as a cache across multiple calls? That is another Lisp feature I am > pressing into action. My first example, before the correction by Alex, did that. Idiomatic Python prefers keeping state in a class rather than closures. > Build it and they will come. Maybe if you used a macro-powered language > and saw where macros improved code and they became second nature... Maybe. But look for previous posts of mine on c.l.py to see that my previous attempts at learning Lisp have met dead ends. I know how it's supposed to work, but haven't been able to convert what I see on a page into something in my head. Same problem with I was studying algebra. I just couldn't turn what I saw on paper into something I could think about, while for analysis I had no problem visualizing limits and epsilons. > > The code caches the result of calling a given function, which could > > compute 3 or could compute bessel functions or could compute > > anything else. I don't see how that's any different than what your > > code does. > > Because I do not have to set anything up like you did with the class and > the cache and the slot and the call to cacheCall. And if I did, a single > form such as: > > (defmemoized count (n) (* 2 n)) > > ...would suffice. In my case I can even inline, since I am immediately > dumping the outcome into an instance's slot where cooperating code > (written by the defmodel macro) makes it work. But I only need to define my class once, put it in a module, and important it when needed for any code which needs it. And while I can write code in-line (as with list comprehensions and sets and other newer capabilities of Python), I can't read it. My mind likes thinking about little (espsilon sized?) chunks at time. Hence, "Python fits my brain." > But my hack gets used hundreds of times > throughout a sizeable app. I dash them off inline without missing a > beat, and when I change C? they all keep working. "dash them off" means reimplementing it? > The key thing about being there at compile > time is that my code can write code for me, driven by the very small > amount of code that varies from case to case. That makes my code more > readable than yours, because you are cutting and pasting all that > implementing cruft over and over again and the varying essence does not > stand out so well. Again, where's the cut&paste? I define it one, put it in a module, and reuse it anywhere appropriate. BTW, I'm afraid I'm about at the end of my limits for this thread. I'll only be able to do small followups. Andrew dalke at dalkescientific.com From ayc8NOSPAM at cornell.edu Wed Aug 6 01:53:44 2003 From: ayc8NOSPAM at cornell.edu (Andy C) Date: Wed, 06 Aug 2003 05:53:44 GMT Subject: How do I get a reference to a KEY value of a dictionary? References: <645db655.0307311636.71923378@posting.google.com> Message-ID: > These days I have an extension which merely subclasses dict to add on > a key reference method and an increment method which does something > like: You did this in C or python? If in python, how did you do it? (without keys()?) If in C, why don't you submit it to the source tree? thanks, Andy From mertz at gnosis.cx Thu Aug 28 13:34:49 2003 From: mertz at gnosis.cx (David Mertz, Ph.D.) Date: Thu, 28 Aug 2003 13:34:49 -0400 Subject: Burn some books (please)... References: Message-ID: <50jT/kKkXsvR092yn@gnosis.cx> Alex Martelli wrote previously: |>>Very long ago, some books where burnt in public, |Very long as in, Winter 2001/2002, for example? |...as long of course as the books you burn belong to you, that's a form of |political speech which is just as acceptable as burning a flag. I just want to point out to the readership that many copies of _Text Processing in Python_ are available at your local bookstore for public burning. There's heresy in that book! (apparently I trend a bit to far in an FP direction :-)). I think I can speak for Alex in pointing out that _Python in a Nutshell_ also makes for excellent kindling. Yours, David... -- Keeping medicines from the bloodstreams of the sick; food from the bellies of the hungry; books from the hands of the uneducated; technology from the underdeveloped; and putting advocates of freedom in prisons. Intellectual property is to the 21st century what the slave trade was to the 16th. From aahz at pythoncraft.com Tue Aug 12 10:42:21 2003 From: aahz at pythoncraft.com (Aahz) Date: 12 Aug 2003 10:42:21 -0400 Subject: Python vs. C# References: <3f36af20@shknews01> <2259b0e2.0308110433.204d7831@posting.google.com> <070hjvou8s33gvmom1t45t3avlkhudsstn@4ax.com> Message-ID: In article <070hjvou8s33gvmom1t45t3avlkhudsstn at 4ax.com>, Doug Tolton wrote: > >Hey, watch the Lisp cracks!! :-P > >Seriously Lisp is the Mother of all programming languages. So much of >the features that are being implemented today come from Lisp it's not >even funny. If you want to see what they are, take a gander at Paul >Graham's website: >www.paulgraham.com Paul Graham was the keynote speak for PyCon DC 2003. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From aleax at aleax.it Thu Aug 21 12:15:59 2003 From: aleax at aleax.it (Alex Martelli) Date: Thu, 21 Aug 2003 16:15:59 GMT Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> <6dj2kv8ugkieehs7guh786cl40o5lj6mcs@4ax.com> <599a6555.0308202108.397bb1a0@posting.google.com> Message-ID: <3f61b.24172$zN5.741744@news1.tin.it> Anton Vredegoor wrote: ... > tiny chance. Suppose you could make a bet for a dollar with an > expected reward of a thousand dollars? Statistically it doesn't matter > whether you get a .999 chance of getting a thousand dollars or a > .00999 chance of getting a million dollars. This assertion is false and absurd. "Statistically", of course, expected-value is NOT the ONLY thing about any experiment. And obviously the utility of different sums need not be linear -- it depends on the individual's target-function, typically influenced by other non-random sources of income or wealth. Case 1: with whatever sum you win you must buy food &c for a month; if you have no money you die. The "million dollars chance" sees you dead 99.9901 times out of 100, which to most individuals means huge negative utility; the "thousand dollars chance" gives you a 99.9% chance of surviving. Rational individuals in this situation would always choose the 1000-dollars chance unless the utility to them of the unlikely million was incredibly huge (which generally means there is some goal enormously dear to their heart which they could only possibly achieve with that million). Case 2: the sum you win is in addition to your steady income of 100,000 $/month. Then, it may well be that $1000 is peanuts of no discernible use to you, while a cool million would let you take 6 months' vacation with no lifestyle reduction and thus has good utility to you. In this case a rational individual would prefer the million-dollars chance. > Therefore, the only thing pertinent to this question seems to be the > risk and gain assessments. Your use of 'therefore' is inapproprite because it suggests the following assertion (which _is_ mathematically speaking correct) "follows" from the previous paragraph (which is bunkum). The set of (probability, outcome) pairs DOES mathematically form "the only thing pertinent" to a choice (together with a utility function of course -- but you can finesse that by expressing outcome as utility directly) -- the absurdity that multiplying probability times outcome (giving an "expected value") is the ONLY relevant consideration is not necessary to establish that. > Another relevant meme that is running around in this newsgroup is the > assumption that some people are naturally smarter than other people. > While I can certainly see the advantage for certain people for keeping > this illusion going (it's a great way to make money, the market > doesn't pay for what it gets but for what it thinks it gets) there is > not a lot of credibility in this argument. *FOR A GIVEN TASK* there can be little doubt that different people do show hugely different levels of ability. Mozart could write far better music than I ever could -- I can write Python programs far better than Silvio Berlusconi can. That does not translate into "naturally smarter" because the "given tasks" are innumerable and there's no way to measure them all into a single number: it's quite possible that I'm far more effective than Mozart at the important task of making and keeping true friends, and/or that Mr Berlusconi is far more effective than me at the important tasks of embezzling huge sums of money and avoiding going to jail in consequence (and THAT is a great way to make money, if you have no scruples). Note that for this purpose it does not matter whether the difference in effectiveness at given tasks comes from nature or nurture, for example -- just that it exists and that it's huge, and of that, only a madman could doubt. If you have the choice whom to get music from, whom to get Python programs from, whom to get as an accomplice in a multi-billion scam, you should consider the potential candidates' proven effectiveness at these widely different tasks. In particular, effectiveness at design of programming languages can be easily shown to vary all over the place by examining the results. > Of course there is a lot of variation between people in the way they > are educated and some of them have come to be experts at certain > fields. However no one is an island and one persons thinking process > is interconnected with a lot of other persons thinking processes. The Of course Mozart would have been a different person -- writing different kinds of music, or perhaps doing some other job, maybe mediocrely -- had he not been born when and where he was, the son of a music teacher and semi-competent musician, and so on. And yet huge numbers of other people were born in perfectly similar circumstances... but only one of them wrote *HIS* "Requiem"... > there are those that first leap and then look. It's fascinating to see > "look before you leap" being deprecated in favor of "easier to ask > forgiveness than permission" by the same people that would think twice > to start programming before being sure to know all the syntax. Since I'm the person who intensely used those two monickers to describe different kinds of error-handling strategies, let me note that they're NOT intended to generalize. When I court a girl I make EXTREMELY sure that she's interested in my advances before I push those advances beyond certain thresholds -- in other words in such contexts I *DEFINITELY* "look before I leap" rather than choosing to make inappropriate and unwelcome advances and then have to "ask forgiveness" if/when rebuffed (and I despise the men who chose the latter strategy -- a prime cause of "date rape", IMHO). And there's nothing "fascinating" in this contrast. The amount of damage you can infert by putting your hands or mouth where they SHOULDN'T be just doesn't compare to the (zero) amount of "damage" which is produced by e.g. an attempted access to x.y raising an AttributeError which you catch with a try/except. Alex From david.bear at asu.edu Wed Aug 20 16:35:54 2003 From: david.bear at asu.edu (David Bear) Date: 20 Aug 2003 13:35:54 -0700 Subject: open.read Message-ID: I was in a hurry to do something and I did stuff = open("filename", "r").read() then I realized, "hey I didn't close the file". so python close it automagically? Since I was doing python interactively I expect the interpreter closed the file for me but my guess is the above syntax is probably poor. any comments? From tismer at tismer.com Wed Aug 13 20:25:14 2003 From: tismer at tismer.com (Christian Tismer) Date: Thu, 14 Aug 2003 02:25:14 +0200 Subject: Stackless needs Jobs, Sponsorship, please help! Message-ID: <3F3AD6EA.3070708@tismer.com> Hi friends, To be short, Stackless is in real trouble, again! Stackless 3.0 is waiting for some final changes, it needs to be ported to Python 2.3 (a major task), there is lots of documentation to do... ...but I can't do it, since I need to feed the family. At the moment, I don't have sponsorship, no contracts, not even "normal" (non-Stackless) projects. I urgently need your support in order to continue. How to help? - sponsorship by companies which are using Stackless is just fine, this gives me time to continue, - jobs like helping with integrating Stackless in applications, or building special features, - anything else, on a consultancy basis, would be just great. At the moment, I'm really stuck and desperately searching for *any* paid work. Please help Stackless to survive. ciao - chris -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 mobile +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From harry.g.george at boeing.com Tue Aug 12 11:24:39 2003 From: harry.g.george at boeing.com (Harry George) Date: Tue, 12 Aug 2003 15:24:39 GMT Subject: Is Python your only programming language? References: Message-ID: "Joe Cheng" writes: > I'm curious about something... many Artima.com members who have a Java > background and learned Python have come to the conclusion that Java and > Python are highly complimentary languages. They would never consider > filling the place Java has in their toolbox with Python, but recognize there > are many tasks where it really pays to add Python to the mix. > > I want to ask you hard-core c.l.p Pythonistas: Do you use Python for > everything? (and I'm counting Python + C extensions as just Python) Or do > you keep another language equally close at hand, and if so, what is it? And > finally, do you foresee a day when Python can be, for all practical intents > and purposes, your only programming language? > > In the past I've written C, C++, Java, Lisp, Modula-2, Modula-3, Pascal, Perl, and Prolog for pay. I've dabbled in a dozen others. All of these are drifting away as Python takes center stage at home and at work. I personally haven't written in anything else for over a year. I also used it through a recent MSCS degree. Of course, I'm dependent on extensions written in C, C++, and Fortran, plus CORBA, COM, etc. communication protocols. What uses? Some sysadmin scripts, lots of "glueware" reader/writer adaptors and automation for COTS apps, lots of code which needs to be portable across *NIX and Win** platforms. Usually need Numeric and XML, some SQL, CGI wrappers, etc. At home I recently wrote a morse code tutor by reimplementing algorithms (e.g., bit-twiddling to generate pcm) from an OSS package. Once it worked at all, I changed the algorithm to cache preprocessed sin approximations (profiling showed I needed the speedup). Then I enhanced to the functionality of commercial packages. Then added features (autogenerated QSO's) which I don't think are available anywhere else. All in a weekend. How did I get there? I really liked Modula-3's static and dynamic typing system. Other static typing systems I've tried pale by comparison. With Python and good test suites, I don't seem to miss the static typing, and it is vastly easier to generate working code. I also liked Modula-3's syntax and namespace system. Python's syntax is cleaner and the namespaces are simpler-yet-adequately-powerful. (Not too surprising, given Python's origins) I used to be a champion for and an instructor for Perl. I still do code reviews on Perl scripts written by others (shudder). I do not agree sysadmins will stay with Perl over Python. There is a learning curve, but the needed functionality is there. We are finding in complex mixed platform environments, it is easier to install (and upgrade) Python than Perl. Python is readable by people other than the original author (important in an era of layoffs and doubling up). Python is readable by the original author even after being away for months at a time. We found we could replace c. 100 LOC of Prolog with a few lines of python when we needed regex's and other string manipulation. We are finding we can do Lisp-style programming in Python (lazy evaluation, mixins, etc.). We find that Python is "a better VB than VB" for scripting COTS apps via COM. We found python took 1/3 fewer LOC (and was a lot cleaner) than Java for a geometry task (lots of matrixes and netlist traversals). I've yet to look seriously at C#. My primariy concern is "does it support open source cross-platform development and implementation"? As long as it fails that test (e.g., until Mono is fully approved by Microsoft), I'll stick with a known winner. -- harry.g.george at boeing.com 6-6M31 Knowledge Management Phone: (425) 342-5601 From tom_williams_2000_ca at yahoo.ca Tue Aug 26 15:03:57 2003 From: tom_williams_2000_ca at yahoo.ca (Thomas Williams) Date: Tue, 26 Aug 2003 15:03:57 -0400 (EDT) Subject: Decoding MIME email Message-ID: <20030826190357.98076.qmail@web13506.mail.yahoo.com> Thanks, I tried it and it stop at: f = file("mail.txt") with the error message. TypeError: 'str' object is not callable Tom Williams -------- Original Message -------- Subject: Re: Decoding MIME email. Date: Tue, 26 Aug 2003 01:40:07 +0200 From: Gerhard H?ring To: python-list at python.org References: <20030825175038.48958.qmail at web13503.mail.yahoo.com> Thomas Williams wrote: Hello everyone, my name is Tom W. And, I am new to the list, and have been using Python for about a year now. Anyway, I got a question! I am trying to decode MIME (base64) email from a POP3 server, but all I get is a corrupt file. [...] You should be using the email module for this. Here are a few interactive commands that could get you started: from email.Parser import Parser f = file("/tmp/mail.txt") parser = Parser() msg = parser.parse(f) f.close() msg You probably can figure out the rest with the documentation for the email module, otherwise just ask here. Oh, and if your Python doesn't have an email module, it's really time to upgrade :) -- Gerhard -- http://mail.python.org/mailman/listinfo/python-list From imbosol at aerojockey.com Fri Aug 1 01:49:33 2003 From: imbosol at aerojockey.com (Carl Banks) Date: Fri, 01 Aug 2003 05:49:33 GMT Subject: Wow: list of immediate subclasses? References: Message-ID: Roman Suzi wrote: > > I am very surprised that modern classes (inherited from object) > in Python 2.3 show their ancestry, eg: > >>>> object.__subclasses__() > [, , , , 'NoneType'>, , , 'zipimport.zipimporter'>, , 'posix.statvfs_result'>, , , , > , , , 'wrapper_descriptor'>, , 'method_descriptor'>, ] > > This seems cool introspection tool but raises questions: > > 1- I wonder if it has security consequences (knowing what other > classes are in there, probably in some other modules). As it adds > a hole starting from base class "object". Earlier it was possible > to "chroot" to some custom builtin namespace and provide > restricted execution. > > 2- how do I get rid of a class completely? > > This doesn't work: > >>>> object.__subclasses__() > [, , , , 'NoneType'>, , , 'zipimport.zipimporter'>, , 'posix.statvfs_result'>, , ] >>>> class A(object): pass > ... >>>> object.__subclasses__() > [, , , , 'NoneType'>, , , 'zipimport.zipimporter'>, , 'posix.statvfs_result'>, , , '__main__.A'>] >>>> del A >>>> object.__subclasses__() > [, , , , 'NoneType'>, , , 'zipimport.zipimporter'>, , 'posix.statvfs_result'>, , , '__main__.A'>] >>>> > > Sincerely yours, Roman Suzi __subclasses__ is a list of weak references, so the class can be collected even though it's listed in __subclasses__. For whatever reason, class A isn't deleted by reference counts, but cyclic garbage collection gets it. Python 2.2.3c1 (#12, May 27 2003, 21:32:04) [GCC 2.95.4 20011002 (Debian prerelease)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> class A(object): pass ... >>> object.__subclasses__() [, , , , , , , , , , , ] >>> del A >>> object.__subclasses__() [, , , , , , , , , , , ] >>> 1 1 >>> 1 1 >>> 1 1 >>> import gc >>> gc.collect() 6 >>> object.__subclasses__() [, , , , , , , , , , ] -- CARL BANKS From hancock at anansispaceworks.com Fri Aug 1 02:00:05 2003 From: hancock at anansispaceworks.com (Terry Hancock) Date: Thu, 31 Jul 2003 23:00:05 -0700 Subject: Interfaces (a la PEP 245 and Zope) Message-ID: <78ednTw5QfxmebSiXTWJhA@august.net> So, how did the chips fall on implementing interfaces in Python? :-) I've been using the Interface module that is included in Zope, and although, I've found it useful, there are some cases I don't seem to find a good solution for. To illustrate, I'll just describe my current problem: I want to define an object which implements a variety of methods and attributes required by Zope, and use it to wrap a simpler object which might be written by a plugin author. The rest of my code assumes that this plugin will conform to a given interface, so I want to check that it does (to make life easier for the plugin developer). I'd *like* to do something like this: class EditorAPI(Base): """ Mandatory interface for Editor plugins. """ pass # Defines stuff that an editor must have to satisfy the rest # of the program. class Editor(Folder): """ Zope Narya-Editor object is base for all editors. """ meta_type = "Narya-Editor" __implements__ = 'EditorAPI' def __init__(self, id, editor_core=None): """ Wrap an editor plug-in into a Narya-Editor instance. """ for key in editor_core.__dict__.keys(): setattr(self, key, getattr(editor_core, key)) if EditorAPI.isImplementedBy(self): raise BrokenImplementation( "Editor plugin '%s' fails implementation test." % editor_core.title) else: self.__implements__ = EditorAPI BUT, .isImplementedBy(self) only seems to check to see if self.__implements__ contains an assertion for the interface. What I really want is a thorough check, along the lines of what Interface.verify.verify_class_implementation(iface, klass) does. But that's no good, because this object wasn't created by a simple class statement -- we're creating it dynamically in the __init__() method. Now of course, I could pick through the Interface module and write a check that resembles the verification that it does, but it seems to me that there ought to be a simpler solution (and if I were going to do that, I should probably really be improving the Interface module rather than putting the code in my package). So, am I missing some existing way to do this? TIA, Terry -- Terry Hancock Anansi Spaceworks http://www.AnansiSpaceworks.com/ From cepl at surfbest.net Wed Aug 6 13:55:43 2003 From: cepl at surfbest.net (Matej Cepl) Date: Wed, 6 Aug 2003 19:55:43 +0200 Subject: mailbox.py examples (Maildir) Message-ID: Hi, is there any example of use of mailbox.py. I would be especially interested if anybody made a objects which would be able to .delete() .append() etc. individual messages. Thanks, Matej -- Matej Cepl, GPG Finger: 89EF 4BC6 288A BF43 1BAB 25C3 E09F EF25 D964 84AC 138 Highland Ave. #10, Somerville, Ma 02143, (617) 623-1488 From aleax at aleax.it Fri Aug 8 12:30:46 2003 From: aleax at aleax.it (Alex Martelli) Date: Fri, 08 Aug 2003 16:30:46 GMT Subject: Need elegant way to cast four bytes into a long References: <3f33c209$1@news.si.com> Message-ID: William S. Huizinga wrote: > I've got an array.array of unsigned char and would like to make a slice > of that array (e.g. a[0:4]) become one long like I would in "C" : > > l = ((unsigned long *) (&a[0]))[0]; What about: b = array.array('L') b.fromstring(a[0:4].tostring()) l = b[0] I think this should faithfully reproduce the endianness-related unportability of that C fragment (cannot necessarily reproduce crashes due to possible use of misaligned pointers, though:-). Actually, I believe you do not really need the .tostring call in modern Python -- just b.fromstring(a[0:4]) should be equivalent (and faster). Better, if you need to transform into longs _many_ adjacent segments of 4 bytes each, this approach does generalize, and speed is good. Finally, you can remedy endianness issue with the .byteswap method... Alex From markus_wankus at hotmail.com Mon Aug 11 09:12:25 2003 From: markus_wankus at hotmail.com (Markus Wankus) Date: Mon, 11 Aug 2003 09:12:25 -0400 Subject: win32, COM, and Solidworks (again) - Still Trying References: Message-ID: On Mon, 11 Aug 2003 09:00:02 +1000, Mark Hammond wrote: > Markus Wankus wrote: > >> I realize this is nothing to do with win32all - it is Solidworks. Is >> there a way I can tell them about this problem and possibly get them to >> fix it? What have they not done in their C++ code that is making their >> implementation of COM so stupid? > > You could ask them to implement the type info interfaces for their > objects. > >> If there was a away I could make my own Dispatch class that forced this >> re-instantiation I would be happy, but I can't see any way to figure out >> what gencache class I need for a given object at runtime. > > Yes, this is the rub. > Thanks, again - Mark. I'll try to see if they will listen to suggestions for future releases... -- Markus From mal at lemburg.com Sun Aug 3 15:16:31 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Sun, 03 Aug 2003 21:16:31 +0200 Subject: ODBC & DbiData problem In-Reply-To: <5oonivsud5jrt522bldbevo6nvdf8ktqdp@4ax.com> References: <5oonivsud5jrt522bldbevo6nvdf8ktqdp@4ax.com> Message-ID: <3F2D5F8F.7020700@lemburg.com> Wedrowiec wrote: > I have a problem for experienced programmers. The following code > should copy data between two different databases: > > import dbi,odbc > conn1=odbc.odbc('mysql'); conn2=odbc.odbc('sqlite') > c1 = conn1.cursor(); c2 = conn2.cursor() > > c1.execute("SELECT field1, field2 FROM table1") > rows = c1.fetchall() > c2.executemany('INSERT INTO table1 (field1=%s,field2=%s)', rows) > > c1.close();c1=None; c2.close();c1=None; > conn1.close();conn1=None; conn2.close();conn2=None > > The problem is: field 'field2' is DATE type and after fetchmany() > method I got DbiDate object instead of string 'YYYY-MM-DD > HH:MM:SS'. So my code breaks because Python cannot > insert such object to another database. FWIW, with mxODBC you shouldn't have a problem with this at all. You can even tell it to return all dates as strings. -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 03 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From mpeuser at web.de Sun Aug 24 14:07:55 2003 From: mpeuser at web.de (Michael Peuser) Date: Sun, 24 Aug 2003 20:07:55 +0200 Subject: QuickTimeTcl References: Message-ID: "Cameron Laird" schrieb im Newsbeitrag news:vkhkrfgfcn5n01 at corp.supernews.com... > In article , > Bgc wrote: > >Hi All, > > > >I'm interested in producing educational applications with Python. Of > >special interest is the playback of video, something that has as of > >yet eluded me. I'm wondering what kind of access Python has to the > >Tcl scripting language, because of the following project: > > > >http://hem.fryistorg.com/matben/qt/ > >http://sourceforge.net/projects/quicktimetcl/ > >(I hope that URL is correct; google for QuicktimeTcl if not) > > > >I understand (actually, I'm just beginning to explore) Python's > >wrapper access to Tk, but I'm sort of confused about Python's access > >to the Tcl scripting language. Is there a similar wrapper for the Tcl > >language, and if so, can anyone suggest a reasonable process for > >creating a Python wrapper for QuicktimeTcl? > . > . > . > Python does all of Tcl. > > Tk is a superset of Tcl. Tkinter gives access to all > of Tk. Conclusion: Tkinter gives access to all of > Tcl, in particular. > > That doesn't mean you automatically get everything you > want. There are a couple of difficulties: > 1. From a Pythonic viewpoint, programming > Tcl through the Tkinter.tk.eval() > mechanism isn't pretty. Developers > making heavy use of Tcl often *do* > write Python wrappers. > > I know of no such wrapper for > QuicktimeTcl. > 2. QuicktimeTcl isn't Tcl, strictly; it's > an *extension* of Tcl. Sometimes ex- > tensions work transparently with > Tkinter; sometimes ... not. I have no > idea what shape Tkinter-plus-Quicktime- > Tcl is in. > > 'Sounds like a fun project, though. > -- Snack - a quite acceptable Tcl sound toolkit with some extra Canvas widgets is made on top of Tcl. You can look into the tkSnack.py to see how that interfacing works. http://www.speech.kth.se/snack/ Kindly Michael P From adalke at mindspring.com Fri Aug 22 03:41:34 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Fri, 22 Aug 2003 07:41:34 GMT Subject: Newbie problem with codecs References: <1R01b.1724$Ej6.454@newsread4.news.pas.earthlink.net> Message-ID: derek / nul > My code so far ... > t = unicode(eng_file, "utf-16-le") > print t > ----------------------------------------------------- > > The print fails (as expected) with a non printing char '\ufeff' which is of > course the BOM. > Is there a nice way to strip off the BOM? How does it fail? It may be because print tries to convert the data as appropriate for your IDE or terminal, and fails. Eg, the default expects ASCII. See http://www.python.org/cgi-bin/faqw.py?req=show&file=faq04.102.htp Asa a guess, since you're on MS Windows, your terminal might expect mbcs. Try print t.encode('mbcs') If you really want to strip it off, do t[2:] (or [4:]?), to get the string after the first 2/4 characters (the BOM) in the string. But I doubt that's the correct solution. Andrew dalke at dalkescientific.com From peter at engcorp.com Fri Aug 29 10:58:57 2003 From: peter at engcorp.com (Peter Hansen) Date: Fri, 29 Aug 2003 10:58:57 -0400 Subject: python and webcam?? References: <3F4F56AB.19EFE5AB@engcorp.com> Message-ID: <3F4F6A31.1598071A@engcorp.com> Mike Kier wrote: > > "Peter Hansen" wrote in message > news:3F4F56AB.19EFE5AB at engcorp.com... > > Mirco wrote: > > > > > > Hi, > > > I'd like to know if is it possible to make python communicate with a > > > webcam. Of course, I think it is possible... but I don't know if there > > > is a specific module for this kind of work. Can anyone give me a > council? > > > > Depends a lot on the type of webcam, but in any case it's a pretty > > safe bet that (a) it's possible, and (b) there is no *specific* module > > for the task. > > > > That said, there are things like PIL which could be of use in this area, > > and at least one specific webcam package (probably using calldll to get > > to the library for the device) that has been posted in the past. > > > > -Peter > > Try this... > http://videocapture.sourceforge.net/ Ah, that's the one. Uses it's own .pyd actually, not calldll as I thought. Doesn't work with my webcam though. Might help if the OP could specify what he has. -Peter From jjl at pobox.com Wed Aug 20 18:24:05 2003 From: jjl at pobox.com (John J. Lee) Date: 20 Aug 2003 23:24:05 +0100 Subject: open.read References: Message-ID: <87ada40xyy.fsf@pobox.com> David Bear writes: > I was in a hurry to do something and I did > > stuff = open("filename", "r").read() > > then I realized, "hey I didn't close the file". > > so python close it automagically? Since I was doing python > interactively I expect the interpreter closed the file for me but my > guess is the above syntax is probably poor. any comments? Yes, the file gets closed when the file object gets garbage collected by Python, but explicitly closing it is a good idea, especially when writing to a file (since your OS might not save you from lost data if your program exits without closing the file) and when there's any chance your code might be run on Jython (because Java will garbage-collect your file at some random time, which may break your code). The fact that the file got closed automatically has nothing to do with the fact that you were using the interactive prompt. John From gregbrunet at NOSPAMsempersoft.com Wed Aug 27 12:58:54 2003 From: gregbrunet at NOSPAMsempersoft.com (Greg Brunet) Date: Wed, 27 Aug 2003 11:58:54 -0500 Subject: Best way to write a file n-bytes long References: <8d3e714e.0308261404.12045d96@posting.google.com> <3f4c8ebc$0$256$cc9e4d1f@news.dial.pipex.com> Message-ID: "Michael Porter" wrote in message news:3f4c8ebc$0$256$cc9e4d1f at news.dial.pipex.com... > > "Tony C" wrote in message > news:8d3e714e.0308261404.12045d96 at posting.google.com... > > Does Python have a function that is analogous to C's write() or > > fwrite()- > > > > that is , I want to write a file (of arbitrary data) that is 100K, or > > 1MB (or more) bytes long.. > > > > Both write() and fwrite() in C allow the user to specify the size of > > the data to be written. > Another alternative is to seek to required position and write (at least) one > byte... > > reqSize = 1048576 > fh = open('junk', 'wb') > fh.seek(reqSize - 1) > fh.write('\0') > fh.close() > > Mike. I interpreted his 'arbitrary data' to mean the same thing & came up with the same solution (which should be the fastest way to do it in C as well!). Anyway, doing some rough timing also seems to show that creating the string was only taking about 10% of the time that writing it is, and that the seek solution is about 10x faster that creating the string & 100x faster that writing the string! It shows once again that it pays to find out where the bottleneck is before trying to optimize the wrong area! -- Greg From lorenb2 at bezeqint.net Thu Aug 28 10:01:20 2003 From: lorenb2 at bezeqint.net (Bill Loren) Date: Thu, 28 Aug 2003 16:01:20 +0200 Subject: Binary data handling ? Message-ID: <000501c36d6c$e76fdf70$6400a8c0@EVOD31> Hello ppl, I'm having difficulties to accomplish some simple chores with binary data. I'm having a string (?) which I received via an HTTP transactions which is a binary file. Problem is the webserver I'm communicating with injected a \x0D before every \x0A, and I need to remove those 0x0D characters from my buffer before saving it to disk. any ideas ? I tried the following without any success: string.replace("%c%c" % (13,10), "%c" % (10)) string.replace("\x0d\x0a", "\0x0a") thx ~B From gerrit at nl.linux.org Thu Aug 28 05:47:28 2003 From: gerrit at nl.linux.org (Gerrit Holl) Date: Thu, 28 Aug 2003 11:47:28 +0200 Subject: Script Discussion & Critique In-Reply-To: <3F4D4402.3060209@hotmail.com> References: <3F4D31B1.6080802@hotmail.com> <06eqkv4onjh5m4tcbbqkmh8lscaj5niatp@4ax.com> <3F4D4402.3060209@hotmail.com> Message-ID: <20030828094728.GA3020@nl.linux.org> hokiegal99 wrote: > print " " The " " is unnecesary. The following statement does the same: print To the eye, there is no difference between th two. > print "******************************************************" > print " Three Easy Steps to a Recursive find and Replace " > print "******************************************************" I usually create a string first and then print it: intro = """ ======================== etc ======================== """ print intro This makes it more comfortable to change it. Gerrit. -- 181. If a father devote a temple-maid or temple-virgin to God and give her no present: if then the father die, she shall receive the third of a child's portion from the inheritance of her father's house, and enjoy its usufruct so long as she lives. Her estate belongs to her brothers. -- 1780 BC, Hammurabi, Code of Law -- Asperger Syndroom - een persoonlijke benadering: http://people.nl.linux.org/~gerrit/ Het zijn tijden om je zelf met politiek te bemoeien: http://www.sp.nl/ From peter at engcorp.com Mon Aug 18 11:37:18 2003 From: peter at engcorp.com (Peter Hansen) Date: Mon, 18 Aug 2003 11:37:18 -0400 Subject: thread debugging References: <5a4226f0.0308150956.15912443@posting.google.com> Message-ID: <3F40F2AE.5272F600@engcorp.com> Cliff Wells wrote: > > On Fri, 2003-08-15 at 10:56, Kevin Cazabon wrote: > > Two solutions I can see: > > > > 1) at the end of your main script... don't exit. use "while 1: > > pass". That'll keep the main script running so you can debug normally > > Better yet, do a join() on the threads in question. Doesn't burn up cpu > while it waits. Or perhaps simpler for the case in question but with roughly the same benefit: use "time.sleep(1)" in place of "pass". From jcc at ibdosnorte.com Thu Aug 7 03:27:33 2003 From: jcc at ibdosnorte.com (=?ISO-8859-1?Q?Juan_Carlos_CORU=D1A?=) Date: 7 Aug 2003 00:27:33 -0700 Subject: How to return a IStream COM object? Message-ID: Hello all, I have developed an automation server using Mark's win32 extensions and I must return a IStream COM object from one method of the automation server. Here is an extract of my code: class Stream: _public_methods_ = [ 'Read', 'Write', 'read', 'write', 'Seek', 'SetSize', 'CopyTo', 'Commit', 'Revert', 'LockRegion', 'UnlockRegion', 'Stat', 'Clone'] _com_interfaces_ = [ pythoncom.IID_IStream ] def __init__(self, mode, data): print "init stream" self._data = data self._ptr = 0 self._size = len(data) self._creationTime = Time(time()) self._accessTime = Time(time()) self._modificationTime = Time(time()) self._mode = mode def Read(self, numBytes): """Read the specified number of bytes from the string""" self._accessTime = Time(time()) data = self._data[self._ptr:self._ptr + numBytes] self._ptr = self._ptr + numBytes if self._ptr > len(self._data): self._ptr = len(self._data) - 1 print "Read data", data return data # string read = Read def Write(self, data): """Write data to stream""" self._modificationTime = Time(time()) print "Write data", data self._data = self._data + data return write = Write def Seek(self, offset, origin): """Changes the seek pointer to a new location""" self._ptr = offset + origin return self._ptr # ULARGE_INTEGER def SetSize(self, newSize): """Changes the size of the stream object.""" self._size = newSize return def CopyTo(self, stream, cb): """Copies a specified number of bytes from the current seek pointer in the stream to the current seek pointer in another stream""" data = self._data[self._ptr:self._ptr+cb] stream.Write(data) return len(data) # ULARGE_INTEGER def Commit(self, flags): """Ensures that any changes made to a stream object open in transacted mode are reflected in the parent storage""" return def Revert(self): """Discards all changes that have been made to a transacted stream since the last PyIStream::Commit call""" return def LockRegion(self, offset, cb, lockType): """Restricts access to a specified range of bytes in the stream""" return def UnlockRegion(self, offset, cb, lockType): """Removes the access restriction on a range of bytes previously restricted with PyIStream::LockRegion""" return def Clone(self): """Creates a new stream object with its own seek pointer that references the same bytes as the original stream""" # not yet implemented return # PyIStream def Stat(self, grfStatFlag): """Returns information about the stream""" st = ('stream', STGTY_STREAM, self._size, self._modificationTime, self._creationTime, self._accessTime, self._mode, LOCK_EXCLUSIVE, ) return st # STATSTG class AutomationServer: def GetStream(self): from win32com import storagecon _grfMode_READ = storagecon.STGM_SHARE_EXCLUSIVE | \ storagecon.STGM_DIRECT | \ storagecon.STGM_READ _grfMode_WRITE = storagecon.STGM_SHARE_EXCLUSIVE | \ storagecon.STGM_WRITE s = XMLRPCLib2.Stream(_grfMode_WRITE, '') return wrap(s, pythoncom.IID_IStream, useDispatcher=useDispatcher) I'm trying to use this automation server in the Navision ERP. Navision accepts the return value VT_UNKNOWN and maps it to an Navision internal type InStream or OutStream. These types must be standard IStream COM objects. Since I'm using a correct typelib calling GetStream does not generate a exception, the problem appears when I call a method of the Navision type InStream/OutStream accessing the Stream methods. The error message says something like "The is an problem communicating with the stream". The python trace collector says nothing. Since there are working automation servers that returns a IStream COM object for Navision, I think there must be an error in my Stream class. I suppose that python maps the native IStream methods to the PyIStream methods in order to avoid using the pointers of the native interface. I made some test using pythoncom._univgw in order to create a vtable for the IStream COM object, but the function CreateTearOff crashes python. So, running testuniv.py after changing the line "import univgw" to "from pythoncom import _univgw as univgw" crashes python. A bug? Can anybody confirm this? Can anybody help me? Maybe a working example? From zephyr01 at alltel.net Tue Aug 12 23:41:51 2003 From: zephyr01 at alltel.net (Hans Nowak) Date: Tue, 12 Aug 2003 23:41:51 -0400 Subject: Is Python your only programming language? In-Reply-To: References: Message-ID: <3F39B37F.5070807@alltel.net> Joe Cheng wrote: > I'm curious about something... many Artima.com members who have a Java > background and learned Python have come to the conclusion that Java and > Python are highly complimentary languages. They would never consider > filling the place Java has in their toolbox with Python, but recognize there > are many tasks where it really pays to add Python to the mix. > > I want to ask you hard-core c.l.p Pythonistas: Do you use Python for > everything? (and I'm counting Python + C extensions as just Python) Or do > you keep another language equally close at hand, and if so, what is it? Currently I use Python for 95% of work and 100% of personal projects. The other 5% is taken by Delphi (for development of user-friendly GUI apps on Windows). > And > finally, do you foresee a day when Python can be, for all practical intents > and purposes, your only programming language? I hope so... From gtalvola at nameconnector.com Fri Aug 1 12:06:20 2003 From: gtalvola at nameconnector.com (Geoffrey Talvola) Date: Fri, 1 Aug 2003 12:06:20 -0400 Subject: Webware for Python 0.8.1 released Message-ID: <61957B071FF421419E567A28A45C7FE59AF5B9@mailbox.nameconnector.com> Webware 0.8.1 has been released. It includes an important security fix. All users are encouraged to upgrade. Webware provides a suite of Python components for developing Web applications. It includes an App Server, Servlets, Python Server Pages, Object-Relational mapping, Task Scheduling, Session management, and many other features. Webware is very modular, and easily extended. Check out the Webware for Python home for documentation, and download instructions at http://webware.sourceforge.net/ From sjmachin at lexicon.net Sat Aug 9 00:23:13 2003 From: sjmachin at lexicon.net (John Machin) Date: Sat, 09 Aug 2003 04:23:13 GMT Subject: regular expression back references References: <25373bfe.0308081756.77ac86a8@posting.google.com> Message-ID: <3f3475fe.27768018@news.lexicon.net> On Fri, 8 Aug 2003 20:40:27 -0600, "Andrew Dalke" wrote: >Clay Shirky >> # use regexes to see what to split on >> if re.search(":", new_address): > >or use > if ":" in new_address: > >> elif re.search("-", new_address): >> new_list = new_address.split("-") >> elif re.search(".", new_address): >> new_list = new_address.split(".") > >and include a > else: > raise Exception("I have no idea what you're asking for") > >and maybe some ValueError catching in the int call. > instead maybe something like new_list = [] for sep in '-.:': if sep in new_address: new_list = new_address.split(sep) break if len(new_list) != 6: raise ....... plus also a test that each octet is in range(256) .... From newsgroups at jhrothjr.com Tue Aug 19 20:51:04 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Tue, 19 Aug 2003 20:51:04 -0400 Subject: 2 funny Py2.3 Issues: 'datetime', string.join() References: <3F42AB3D.F9B456F4@yahoo.com> Message-ID: "Andrew Dalke" wrote in message news:xey0b.269$Ej6.152 at newsread4.news.pas.earthlink.net... > Rami A. Kishek: > > string. However, wouldn't it make more sense if the "join" mehtod > > actually belonged to the List object, since it primarily operates on > > lists? > > http://www.python.org/cgi-bin/faqw.py?req=show&file=faq04.096.htp While the FAQ does a good job, the arguement I prefer is that making .join a method on sequences rather than strings only works when the members of the sequence are all strings. What does, for example, [1, 3, 6].join(',') mean? John Roth From alia_khouri at yahoo.com Wed Aug 6 11:29:19 2003 From: alia_khouri at yahoo.com (Alia Khouri) Date: 6 Aug 2003 08:29:19 -0700 Subject: recompiled midipy.pyd for 2.3 References: Message-ID: <40a939c9.0308060729.17254db9@posting.google.com> davesum99 at yahoo.com (smarter_than_you) wrote in message news:... > this is a nice windows-based MIDI module with simple interface, it was > previously available for <= 2.0 release (See thread on midi for > win32). > > If anyone wants it please post a reply. I've recently compiled a not very well tested python2.3 version. If anybody's interested they can get it from here: http://www.geocities.com/alia_khouri/midipy.txt and then rename the resulting file to "midipy.pyd" These sites are also useful: - http://www.josos.org/midipy - http://www.hammersound.net ciao, Alia From max at alcyone.com Tue Aug 26 20:12:27 2003 From: max at alcyone.com (Erik Max Francis) Date: Tue, 26 Aug 2003 17:12:27 -0700 Subject: String find and replace References: Message-ID: <3F4BF76B.65B577D9@alcyone.com> Geoff Gerrietts wrote: > You might consider the fragment below, instead. It's a couple lines > longer, but safer (your .close() happens exactly when you want it to) > ... [nitpick] Well, only if no errors occur while reading the file. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ The basis of optimism is sheer terror. \__/ Oscar Wilde From tzot at sil-tec.gr Wed Aug 6 14:54:17 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Wed, 06 Aug 2003 21:54:17 +0300 Subject: Match beginning of two strings References: Message-ID: On Sat, 02 Aug 2003 17:39:26 -0400, rumours say that Ravi might have written: >I have about 200GB of data that I need to go through and extract the >common first part of a line. Something like this. If you know in advance that many of these comparisons will involve large strings, you might improve your apps' response time by using the os.path.commonprefix function modified as proposed in http://sourceforge.net/tracker/index.php?func=detail&aid=681780&group_id=5470&atid=305470 which is O(logN)-ish instead of O(N). This patch was sent by me, but there is a suggestion by another SF user which seems to be efficient too (never benchmarked it against mine). -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From BPettersen at NAREX.com Sun Aug 3 06:50:48 2003 From: BPettersen at NAREX.com (Bjorn Pettersen) Date: Sun, 3 Aug 2003 04:50:48 -0600 Subject: Dealing with paths (Unix question) Message-ID: <60FB8BB7F0EFC7409B75EEEC13E2019202CE4818@admin56.narex.com> > From: paul [mailto:appleseed-cast~NOSPAM~@breathe.com] > > hey there all! > i'm writing some little programs, and i'd like to know about > how to deal with directories on unix. i've read up on this, > but the docs don't really mention much on it. do i use the > pickle module, or something? If you could write up a bugreport on http://sourceforge.net/tracker/?group_id=5470&atid=105470 including what you were looking for and where you expected it to be it has a much better chance of getting fixed (and your input is probably more valuable than someone that allready knows about paths in Python :-) > what i'd like to do is read in a path, say > /home/username/images/ > and that path contains a dir called downloads and some png files, > and it also contains another dir called icons, which holds > jpg, png and gif files. Now, is it posible to go through that > top directory and recursively go through /icons/ and /downloads/ > and pick out all files of a certain extension(only png files, > for example)? > > something like: > for each_file in /home/username/images: > if image_extension is png: > add image path to list > but as i said, i need something to work recursively though an > arbitrary number of directories. [...] Well, you'll have a problem pruning the search space if you don't know where in the hierarchy they can be. My solution (below) is cheating by not doing any pruning except in directories containin either 'icons' or 'downloads', and then it prunes every thing except those... It's also slightly overambitious in that you can match anything, not just extensions (I needed a replacement for Lib/lib-old/find.py, so...) This uses the new os.walk, which is much easier to explain than the old os.path.walk(): import os import fnmatch # much flexibility for little pain :-) def findFiles(patterns, startdir=os.curdir, modifySearchPath=lambda x:None): """patterns: sequence of regular expressions (shell style, not re) defining a match. See fnmatch documentation for the specifics. startdir: ... modifySearchPath: callable taking a list of directories and modifiying/pruning it *in place* (in particular any return value from this callable is discarded :-) """ for root, dirs, files in os.walk(startdir): modifySearchPath(dirs) for pattern in patterns: files = fnmatch.filter(files, pattern) for file in files: # use abspath on windows to get the drive included when # startdir is os.curdir (I'm assuming it doesn't do any # harm on *nix, but I don't have a box here to test..) yield os.path.abspath(os.path.join(root, file)) # define the pruning algorithm, this is probably not exactly what you # want (see note above) -- season to taste. def myDirFilter(directories): icons_p = 'icons' in directories downloads_p = 'downloads' in directories if not icons_p or downloads_p: # this level doesn't have anything we're looking for so # don't modify directories. return directories[:] = [] # note: slice assignment to do *in place* remove-all. # add back the only directories we're interested in. if icons_p: directories.append('icons') if downloads_p: directories.append('downloads') # define what we're looking for imageFiles = ('*.jpe?g', '*.gif', '*.png') # loop and enjoy. for filename in findFiles(patterns=imageFiles, modifySearchPath=myDirFilter): print filename hth, -- bjorn From hokiegal99 at hotmail.com Wed Aug 27 22:37:29 2003 From: hokiegal99 at hotmail.com (hokiegal99) Date: Wed, 27 Aug 2003 22:37:29 -0400 Subject: Script Discussion & Critique References: <3F4D31B1.6080802@hotmail.com> <06eqkv4onjh5m4tcbbqkmh8lscaj5niatp@4ax.com> <3F4D4402.3060209@hotmail.com> Message-ID: <3F4D6AE9.7050706@hotmail.com> Terry Reedy wrote: > My main answer is your answer to the following: does it operate > correctly? does it produce output within the bounds of what you > consider acceptible? In particular, does it pass your test case(s)? > and are your test case(s) reasonably representative of the domain of > application? Well it works now, mackstan pointed out a flaw in my logic that caused the script to miss stings if they occured at the very front of a file. Thanks!!! From amk at amk.ca Thu Aug 21 08:17:28 2003 From: amk at amk.ca (A.M. Kuchling) Date: Thu, 21 Aug 2003 07:17:28 -0500 Subject: Removing language comparisons References: Message-ID: On Thu, 21 Aug 2003 12:07:33 +0000 (UTC), Duncan Booth wrote: > How about getting some new articles to be written by pairs of people, one > Python user who knows a bit of the other language and one person who lives > and breathes Perl/Java/Ruby/etc but knows a bit of Python? That way you A good idea, but unless some volunteer steps forward to do the work, it's not going to happen. --amk From Spam.Buster at web.de Sun Aug 24 07:47:16 2003 From: Spam.Buster at web.de (Lars Behrens) Date: Sun, 24 Aug 2003 13:47:16 +0200 Subject: How to store data? In-Reply-To: <3f484fce_1@corp.newsgroups.com> References: <3f482037_5@corp.newsgroups.com> <3f484fce_1@corp.newsgroups.com> Message-ID: Paul D. Fernhout wrote: > I also included the example code file previously posted based on your > requirements (and I referenced your email in it through a google news > link). Thanks for the motivation. Oh, thx for making me famous :-) Cheerz Lars From tjreedy at udel.edu Sat Aug 30 01:04:30 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 30 Aug 2003 01:04:30 -0400 Subject: My script is taking 12 hours+ any suggestions? References: <3f4ff9f8$0$23588$5a62ac22@freenews.iinet.net.au> Message-ID: "Ideasman" wrote in message news:3f4ff9f8$0$23588$5a62ac22 at freenews.iinet.net.au... > Hi I have a made a script that process normals for a flat shaded 3D mesh's. > It compares every vert with every other vert to look for verts that can > share normals and It takes ages. I wonder if there is not some way to sort or classify verts so you do not have to do a complete nxn comparison. TJR From Dick.Zantow at lexisnexis.com Wed Aug 27 08:51:47 2003 From: Dick.Zantow at lexisnexis.com (rzed) Date: Wed, 27 Aug 2003 08:51:47 -0400 Subject: My future Python IDE article References: Message-ID: David Mertz wrote: > Pythonistas, > > My loyal fans :-) will remember that I did a Python IDE roundup for > _Charming Python_ a couple years back. Now I have another such > roundup lined up... not the very next article, but it's there on > the list. > > In the intervening years, I've hardly touched anything one might > call an IDE. I've looked at screenshots from time to time, and > read various announcements. But really I just use text editors and > command lines. > > Here's the thing: I probably have room to look at about four > different tools in one article. In fact, it wouldn't be absurd to > only do three. Past that, I cannot do more than list contact > information and platform in the available words. I'm sure there > are more than four IDEs that > -someone- loves to work with out there... but I need to have a > cutoff. > > So c.l.py readers... make the case for your favorite one getting on > the list. I have a while to ponder the opinions advanced, should > this prompt some discussion (it may take a little while to order > review copies of commercial tools and/or get things installed). > I hope you'll take a look at boa constructor. It's an interesting project that is rapidly becoming better than just good. -- rzed From aleax at aleax.it Thu Aug 28 09:03:26 2003 From: aleax at aleax.it (Alex Martelli) Date: Thu, 28 Aug 2003 13:03:26 GMT Subject: Celebrity advice References: <38ec68a6.0308272313.3cc72758@posting.google.com> Message-ID: Asun Friere wrote: > Arthur wrote in message >> >> ""There are some books so bad, but so plausible and influential, that >> periodically trashing them in public is almost an obligation. The really >> classic stinkeroos of this kind, like Karl Marx's Das Kapital, exert a >> weird kind of seduction on otherwise intelligent people long after their >> factual basis has been completely exploded.""" >> >> I gotta go with with Eric on this. >> > Wow! You've actually managed to read Marx' _Capital_? What all three > volumes? I'm impressed! I'm certain no "otherwise intelligent > people" would "periodically [thrash]" a book they haven't read, would > they? Dunno 'bout Arthur, but I did read "Il Capitale" (in Italian translation, by Editori Riuniti) -- that was over 30 years ago, when I was a left-wing firebrand (but definitely an egghead rather than a man of action). None of my comrades had ever gotten close, of course (it's a VERY heavy, ponderously written book: K. Marx would never have managed to popularize his ideas without the help of that _excellent_ writer, F. Engels). One of the few people I knew who HAD was my teacher of history and philosophy (I was in high school at the time, of course), a member in good standing of the Communist Party (quite legal in Italy, indeed at the time the second-largest party in the country with about 30% of the vote -- I was far to the left of the staid and traditional Party, of course) -- she challenged me, claiming that having read Marx was worth nothing unless I had an equally good grounding on his forebears and intellectual adversaries. So I started on Adam Smith (wonderful writer), Ricardo (almost as ponderous as Marx), etc, etc, and eventually left Marxism (I guess in some sense it was an issue of growing up). But I challenge the claim that "the factual basis" of Das Kapital has been "completely exploded", any more than that of the far more accessible and pleasant-to-read "Wealth of Nations". Sure, quite a few of Smith's analyses (and of Marx's) have been proven to be incomplete or incorrect -- e.g., Ricardo does a great job on Smith, even though he does admire and accept him as a starting point, by meticulously proving the concept of "rent" as being determined by the least-productive land in use, a concept that Smith had not conceived and whose lack undermines quite a few of his detailed analyses (as I recall, and it HAS been over 30 years, Marx's treatment of rent is also pretty weak, though perhaps not quite as weak as Smith's, but with less justification since Marx DID know of Ricardo's analysis and never critiques it in what I find a convincing manner -- strange, because even accepting the whole of Ricardo's treatment on this is quite peripheral to Marx's central purposes and would not undermine them in any way). But anyway, I still find a LOT that is part of the "factual basis" of both "The Wealth of Nations" and "The Capital" to be un-exploded and quite helpful as a starting point for my own idiosyncratical analyses of economical and politico-economical issues. Alex From sismex01 at hebmex.com Tue Aug 12 16:23:10 2003 From: sismex01 at hebmex.com (sismex01 at hebmex.com) Date: Tue, 12 Aug 2003 15:23:10 -0500 Subject: Is Python your only programming language? Message-ID: > From: BadJake [mailto:john at rygannon.com] > Sent: Martes, 12 de Agosto de 2003 03:14 p.m. > > [...snip...] > What ever happened to customer choice? > > Regards > John > Maybe they have Henry Ford's "Customer Choice" philosophy: "Any color you want, as long as it's black". -gustavo Advertencia:La informacion contenida en este mensaje es confidencial y restringida, por lo tanto esta destinada unicamente para el uso de la persona arriba indicada, se le notifica que esta prohibida la difusion de este mensaje. Si ha recibido este mensaje por error, o si hay problemas en la transmision, favor de comunicarse con el remitente. Gracias. From robin at jessikat.fsnet.co.uk Sun Aug 3 05:48:21 2003 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Sun, 3 Aug 2003 10:48:21 +0100 Subject: boost python & 2.3 References: <200308021720.44862.drlinux@columbus.rr.com> Message-ID: In article , Robin Becker writes ...... >>What version of boost are you using? 1.30.0 won't work with Python >>2.3; however, the CVS version of boost does work with Python >>2.3. David Abrahams has indicated this on the boost list and I can >>confirm that it does work with Python 2.3 (at least on a Solaris 9 >>system). >> >>Dave .... the CVS version of boost certainly compiles fine with 2.3. -- Robin Becker From kern at caltech.edu Tue Aug 26 09:20:10 2003 From: kern at caltech.edu (Robert Kern) Date: Tue, 26 Aug 2003 13:20:10 +0000 (UTC) Subject: Advice to a Junior in High School? References: Message-ID: In article , "Howard Nease" writes: [snip] > Does anyone have any advice for me and my future? What should I study in > college? Well, in addition to what everyone else has said, I would recommend taking some classes that hone your ability to analyze numerical data. There ought to be classes from a variety of departments at your college that can teach you this skill. It's likely *one* of them will catch your interest. In my experience, that core skill is easily transfered between fields. Once you learn how to handle the numbers, it doesn't matter if they are temperature readings or stock prices. That skill will open a large number of career paths where your CS skills and interests are respected and used. Many of them pay well, too. Of course, that doesn't help you in the slightest if you're just not interested in those fields. Use your college experience to explore (lots of things really, but let's focus on the career aspects here ;-)). When you visit colleges, try to ask the older kids if they had the opportunity to "shop around" and discover what they really wanted to do. To get you started, I'll tell you right now that Caltech is not such a place. > Will the market for jobs get better? Probably. Six years is a *long* time for the computer world. For that matter, six years is a long time for a person your age, too. I'm quite sure you will be a very different person when you graduate from college. Trust me: I'm six years ahead of you. ;-) And for now, forget us old fogies, go out, and have some fun, goddammit! -- Robert Kern kern at caltech.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter From nhodgson at bigpond.net.au Tue Aug 26 07:17:43 2003 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Tue, 26 Aug 2003 11:17:43 GMT Subject: Extracting Rich Text data formats from win32clipboard References: Message-ID: Trader: > >>> clipboard_grab() > FORMAT: 49171 > FORMAT: 16 > FORMAT: 7 > FORMAT: 0 Now add in: for f in formats: if f >= 0xC000: print win32clipboard.GetClipboardFormatName(f) Formats above 0xC000 are dynamically registered clipboard types. I get: FORMAT: 13 FORMAT: 49278 FORMAT: 49245 FORMAT: 49171 FORMAT: 16 FORMAT: 7 FORMAT: 0 HTML Format Rich Text Format Ole Private Data The HTML has a prologue and then some HTML: Version:1.0 StartHTML:000000195 EndHTML:000001891 StartFragment:000001597 EndFragment:000001710 StartSelection:000001597 EndSelection:000001710 SourceURL:http://sydney.citysearch.com.au/ CitySearch.com.au Australia - Your guide to the city of Sydney ... The RTF looks normal: {\rtf1\ansi\ansicpg-1\deff0\deflang3081{\fonttbl{\f0\froman\fcharset0 Times New Roman;}{\f1\ftech\fcharset0 Symbol;}{\f2\fswiss\fcharset0 Arial;}{\f3\fswiss\fcharset0 Courier New;}{\f4\ftech\fcharset0 Wingdings;}}{\colortbl\red0\green0\blue0;\red0\green0\blue255;\red0\green255 \blue255;\red0\green255\blue0;\red255\green0\blue255;\red255\green0\blue0;\r ed255\green255\blue0;\red255\green255\blue255;\ ... Neil From ubecher at gmx.net Thu Aug 28 14:22:01 2003 From: ubecher at gmx.net (Uwe Becher) Date: Thu, 28 Aug 2003 20:22:01 +0200 Subject: NetServerDiskEnum in win32net Message-ID: I try to get all logical drives of a remote machine (WinNT or W2K) and get a result, that gives me the expected total but not all expected drives. Example: >>> win32net.NetServerDiskEnum('nor1w020', 0) gives me: ([u'A:', u'', u'C:', u'', u'D:', u'', u'E:', u''], 8, 0) while the machine has the local drives A: C: D: E: F: G: H: Z: A: - Floppy Z: - CDROM All others are harddisk partitions on two physical drives Does anyone have an idea? Thanks Uwe From brian at sweetapp.com Wed Aug 13 02:24:23 2003 From: brian at sweetapp.com (Brian Quinlan) Date: Tue, 12 Aug 2003 23:24:23 -0700 Subject: Python vs. C# In-Reply-To: Message-ID: <000001c36163$89b67ac0$21795418@dell1700> > > I think that depends on how efficient you are at writing tests. > > Python offers a great testing framework to help you. > > No, writing tests consumes time. Of course. The question is whether writing tests results in less net development time (due to more rapid bug discovery and elimination). My experience is that it usually does. > C++ style compiler checking helps. You are changing the subject of discussion; we were talking about C# (and Python; see the subject of this thread). C++ has templates and STL uses them to provide type-safe containers and algorithms. .NET languages are not required to support templates (VB doesn't and neither did the first release of C#) so the class libraries are not type safe. Having written tens of thousands of lines of C# code I can tell you that the compiler seldom saves me from making a type error. > I've never met anyone who thinks > otherwise. Pythonistas just habitually claim it doesn't have merit and > complain about burdens imposed. To us C++ guys, it is no big deal. That is because C++ programmers naturally use C++ design patterns to code in C++. Those design patterns preclude the use of any features not found in the language. If, on the other hand, you were accustomed to a different language, you would probably notice the "big deal" when your favorite design patterns are rendered impossible by static typing. BTW, notice that you are arguing for the inclusion of static typing, which catches only a small fraction of bugs and greatly reduces design flexibility and against type checking, which imposes no design restrictions and can catch more classes of bugs. Cheers, Brian From aleax at aleax.it Fri Aug 29 04:44:08 2003 From: aleax at aleax.it (Alex Martelli) Date: Fri, 29 Aug 2003 08:44:08 GMT Subject: OT: Celebrity advice References: <3F4D0D8B.5E5F9488@engcorp.com> <3F4D3560.71995AEB@engcorp.com> <0frtkvs8b0opk8ubr6qrce2dntq09e6q2t@4ax.com> Message-ID: Tom Plunket wrote: ... > How did Gandhi do it then? Was it just that the British decided > that they weren't mean enough to take it to its "ultimate" > extent, or was it truly that there was a way to "go to the > ultimate" and take back India in a nonviolent way? I think Gandhi's methods worked against a *reasonably humane* opponent, as the Brits were. They didn't work against fanatics: that's how he was killed in the end, by somebody who could not care less about his high moral standards. Had India been a colony of, e.g., Nazi Germany, or Stalin's Russia, or other powers quite willing to "go to the ultimate", he would not have lasted long at all, IMHO. Alex From bgailer at alum.rpi.edu Fri Aug 8 16:10:19 2003 From: bgailer at alum.rpi.edu (Bob Gailer) Date: Fri, 08 Aug 2003 14:10:19 -0600 Subject: OCR with Python In-Reply-To: <3F33B87B.2222.13B98A4F@localhost> Message-ID: <5.2.1.1.0.20030808140854.02b838b8@66.28.54.253> At 02:49 PM 8/8/2003 +0200, A wrote: >Hi, >Does anyone have any experience with Optical Character Recognition in Python? >I would like to automatically register emails with a free emails provider >e.g. Yahoo or Hotmail. >The problem is that, for a successful registration, I must fill in >characters shown in a picture. >So I need to recognize the characters in a picture. >Any idea how? The purpose of those pictures is to suppress automatic registration. I, personally, would not support any effort to get around that limitation. Bob Gailer bgailer at alum.rpi.edu 303 442 2625 -------------- next part -------------- --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.506 / Virus Database: 303 - Release Date: 8/1/2003 From tjreedy at udel.edu Thu Aug 14 12:34:18 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 14 Aug 2003 12:34:18 -0400 Subject: Is Python your only programming language? References: Message-ID: "Richard Brodie" wrote in message news:bhg9nc$161k at newton.cc.rl.ac.uk... > The full text of the [Ariane 5 failure]report is on the web, and should be required > reading: http://www.mssl.ucl.ac.uk/www_plasma/missions/cluster/about_cluster/cluster1/ariane5rep.html Having just read this, I second the suggestion. What the report hints at is that the 'root' cause of the failure was pride leading to complacency -- a trap most anyone can fall into -- and one which one language can completely protect against. Terry J. Reedy From andymac at bullseye.apana.org.au Thu Aug 14 09:04:16 2003 From: andymac at bullseye.apana.org.au (Andrew MacIntyre) Date: Thu, 14 Aug 2003 23:04:16 +1000 (EST) Subject: Python signal delivery under BSD 4.4 In-Reply-To: References: Message-ID: <20030814224955.Y51359@bullseye.apana.org.au> On Wed, 13 Aug 2003, Donn Cave wrote: > In article , > "Elf M. Sternberg" wrote: > > > However, this variant worked as I've reported: > [... forks from thread ] > > I tried it from FreeBSD 5.1, using 2.2.2 built from ports, > and didn't see this problem. I believe 5.1 has a significantly > different thread implementation from 4.x, though. And later releases of FreeBSD 4.x have a number of bugfixes to the pthread support, including some signal related changes. The 4.x pthread support still has some issues though. Elf refers to this working with Python 2.1 - I vaguely recall some changes to Python's pthreads support to try and "harmonise" the behaviour across a number of platforms, and signal delivery may have been affected such that signals are only delivered to the primary thread. As this is only a vague recollection, treat with caution... Does building Python with the linuxthreads port, instead of FreeBSD's native pthreads, behave as expected? > Note that there is pthread_sigmask(3) with the same arguments as > sigprocmask(2), and Python's thread_pthread.h does appear to block > all signals that way when starting a new thread. That's a clue, > perhaps. If sigprocmask() didn't show any signals blocked, maybe > pthread_sigmask() would, or maybe at any rate you can set the > mask to 0 using one or the other of those functions. I also recall Michael Hudson trying to get signal mask support working in the presence of threads, but he could only get it to work on Linux. We did eventually get a required fix to FreeBSD's libc_r committed (in the 4.7 timeframe I think), but Michael had given up by then and canned his code. -- Andrew I MacIntyre "These thoughts are mine alone..." E-mail: andymac at bullseye.apana.org.au (pref) | Snail: PO Box 370 andymac at pcug.org.au (alt) | Belconnen ACT 2616 Web: http://www.andymac.org/ | Australia From jzgoda at gazeta.usun.pl Mon Aug 25 15:50:40 2003 From: jzgoda at gazeta.usun.pl (Jarek Zgoda) Date: Mon, 25 Aug 2003 19:50:40 +0000 (UTC) Subject: [OT] Why is it called string? References: <3f44ce77$0$556$b45e6eb0@senator-bedfellow.mit.edu> <3F44DBF2.1010403@draigBrady.com> <3f453a22$1_1@themost.net> Message-ID: Piet van Oostrum pisze: >>> My CS professor would insist that a byte is a collection of bits, and not >>> necessarily eight. There are machines which do not have 8-bit addressable >>> bytes. > >JZ> I remember that "byte" in French is expressed as "octet", even if it has >JZ> only 7 bits... > > Are you sure. Several international organisations use the word 'octet' in > their official specifications, to make sure that an 8-bit byte is meant. I cann't recall the machine I'm referring to (it was product of Bull), but I am sure that lecturer called 7 bit units as "octets". -- Jarek Zgoda Registered Linux User #-1 http://www.zgoda.biz/ JID:jarek at jabberpl.org http://zgoda.jogger.pl/ From find.me at my.homepage.net Thu Aug 21 22:22:47 2003 From: find.me at my.homepage.net (Blake Garretson) Date: Thu, 21 Aug 2003 22:22:47 -0400 Subject: Adding a column in a tab delimited txt file In-Reply-To: References: Message-ID: Blake Garretson wrote: > for line in f: I meant "for line in infile:" Sorry! -------------------------------------------------- Blake T. Garretson http://blakeg.freeshell.org From vze4rx4y at verizon.net Sun Aug 24 11:38:00 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Sun, 24 Aug 2003 15:38:00 GMT Subject: more bugs in email module References: Message-ID: "Stuart D. Gathman" wrote in message news:OLX1b.57320$xf.19326 at lakeread04... > On Sun, 24 Aug 2003 00:58:20 -0400, Stuart D. Gathman wrote: > > > http://bmsi.com/python/test/test8 > > > > The old system works fine on this example. > > Let me clarify the problem with a short test: > > ------te.py-------- > import email > import sys > > msg = email.message_from_file(sys.stdin) > sys.stdout.write(msg.as_string()) > ------------------- > $ python2 te.py test8.out > $ diff test8 test8.out > .... lots of differences that shouldn't be there .... Thanks for the short snippet that highlights the problem. Please file it as a bug report so it won't get lost: https://sourceforge.net/tracker/?group_id=5470&atid=105470 Raymond Hettinger From mis6 at pitt.edu Fri Aug 8 07:42:15 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 8 Aug 2003 04:42:15 -0700 Subject: Bug? If not, how to work around it? References: <060820031458029244%mday@apple.com> <09udnV37oMEUDqyiU-KYgw@comcast.com> Message-ID: <2259b0e2.0308080342.552101ca@posting.google.com> Gon?alo Rodrigues wrote in message news:... > It finally dawned on me why this is so: it's the way new classes work. > In a sloppy language: a __getattr__ hook is like an instance > attribute, but the iter machinery goes after the class not the > instance so it misses __getattr__. No, iter does not work even if you define __getattr__ at the metaclass level, i.e. iter(c) is not type(c).__iter__(c) if "__iter__" is defined via __getattr__ : >>> class M(type): def __getattr__(cls,name): if name=='__iter__': return lambda self:iter([]) >>> class C: __metaclass__=M >>> c=C() >>> iter(c) Traceback (most recent call last): File "", line 1, in -toplevel- iter(c) TypeError: iteration over non-sequence >>> C.__iter__(c) having-brought-more-confusion-in-your-head-yours-sincerely, Michele From gherron at islandtraining.com Thu Aug 21 13:44:33 2003 From: gherron at islandtraining.com (Gary Herron) Date: Thu, 21 Aug 2003 10:44:33 -0700 Subject: max length of a python program In-Reply-To: <1ed07caf.0308210513.6556978a@posting.google.com> References: <1ed07caf.0308210513.6556978a@posting.google.com> Message-ID: <200308211044.33427.gherron@islandtraining.com> On Thursday 21 August 2003 06:13 am, Ragu wrote: > Is there a limit to the # of lines that can be in a Python program? Log ago (perhaps version 1.2?) there was a limit of 16383 lines. The code that generated line numbers crapped out when it overflowed the 16 bits used to hold it. I think I remember Guido being surprised when I pointed this out -- although I don't know if the surprise was at the existance of the limit or at the idea of a program that long. (It was an automatically genereted program used to create some data structure -- I hardly remember anymore what I was doing -- but it was one of my first Python programs and it was a stupid idea -- soon remedied.) I think the limit was removed soon after that. From mpeuser at web.de Thu Aug 7 13:15:07 2003 From: mpeuser at web.de (Michael Peuser) Date: Thu, 7 Aug 2003 19:15:07 +0200 Subject: generator function References: <215fa0fc.0308070503.2344dd66@posting.google.com> Message-ID: By chance I posted two examples of infinite generators some hours ago news:bgt31l$jnp$03$1 at news.t-online.com... I fond Devid Mertz's artikel quite instructive: http://www-106.ibm.com/developerworks/linux/library/l-pycon?t=grl,l=252,p=it erators%3E. Kindly Michael "chansky" schrieb im Newsbeitrag news:215fa0fc.0308070503.2344dd66 at posting.google.com... > I read the following link about generator: > http://www.python.org/peps/pep-0255.html > but I am still not so clear on the use/purpose of a generator function > other than the fact that a generator can retain the state of the local > variables within the fuction body. Can someone out there shed some > lights on this topic or share about how/when you would ever use a > generator function. From duncan-news at grisby.org Mon Aug 18 05:26:41 2003 From: duncan-news at grisby.org (Duncan Grisby) Date: Mon, 18 Aug 2003 09:26:41 +0000 Subject: omniORB 4.0.2 and omniORBpy 2.2 released References: <2428b$3f33cfec$516049d2$15672@nf1.news-service.com> Message-ID: <186e4$3f409bd1$51604868$5615@nf1.news-service.com> In article , apm wrote: >> http://omniorb.sourceforge.net/ > >That web page says that it is CORBA 2.1 compliant but another page on >the same site says it is 1.6 compliant. Maybe the first page is >out-of-date? What the page says is that omniORB has passed the Open Group's CORBA compliance tests, and is therefore certified as officially CORBA 2.1 compliant. It actually implements a subset of CORBA 2.6, but there is no compliance test for that. Cheers, Duncan. -- -- Duncan Grisby -- -- duncan at grisby.org -- -- http://www.grisby.org -- From chris.gonnerman at newcenturycomputers.net Tue Aug 5 20:25:00 2003 From: chris.gonnerman at newcenturycomputers.net (Chris Gonnerman) Date: Tue, 5 Aug 2003 19:25:00 -0500 Subject: [Python] Re: command -- It works , on linux References: Message-ID: <004101c35bb1$2bf7b960$2100000a@house> ----- Original Message ----- From: "Syver Enstad" > Alex Martelli writes: > > > Have you tried installing Gonnerman's "Alternative Readline", > > http://newcenturycomputers.net/projects/readline.html ? I have > > found it extremely useful to gain the gist of readline's > > functionality on Windows installatons of Python. > > Ehemm... How do you use readline? What should it do? > > Does it work on 2.3? I tried installing but the readline function had > a different function prototype so I guess it doesn't work. I don't have a version for 2.3 yet. Give me time, and I'll get it built (after I download the 2.3 installer and build a MinGW32 import library for it). Chris Gonnerman -- chris.gonnerman at newcenturycomputers.net http://newcenturycomputers.net From autoresponder at web.de Thu Aug 21 03:27:28 2003 From: autoresponder at web.de (autoresponder at web.de) Date: Thu, 21 Aug 2003 09:27:28 +0200 Subject: Ihre Mail an dackeltier@web.de Message-ID: Vielen Dank f?r deine Nachricht. ________________________________________________________________________ 1.000.000 EUR gewinnen - kostenlos tippen - http://millionenklick.web.de IhrName at web.de, 12MB Speicher, Verschluesselung - http://freemail.web.de . From skip at pobox.com Tue Aug 26 09:24:05 2003 From: skip at pobox.com (Skip Montanaro) Date: Tue, 26 Aug 2003 08:24:05 -0500 Subject: python gripes survey In-Reply-To: References: Message-ID: <16203.24437.531620.334609@montanaro.dyndns.org> carroll> If Python used {} to delimit blocks, I could just make the carroll> skipped code a block and add a condition to skip it, but with carroll> the indentation as the way of showing block scope (which I carroll> *love*), I have to indent a big chunk of code to use that carroll> method. In Emacs python-mode, C-c > intends the highlighted region one "step". C-c < goes the other way. This obviously won't help if you're not an Emacs user, but you might want to check your editor's reference manual for something similar. Skip From danielk at aracnet.com Wed Aug 6 08:51:17 2003 From: danielk at aracnet.com (Daniel Klein) Date: Wed, 06 Aug 2003 05:51:17 -0700 Subject: round(22.47,2) gives 22.469999999999999? References: <3f30e294$0$125$e4fe514c@dreader5.news.xs4all.nl> Message-ID: On Wed, 06 Aug 2003 13:12:21 +0200, Eric van Riet Paap wrote: >Hi, > >On python2.1.3, python2.2.1 and python2.2.3 round(22.47,2) gives >22.469999999999999 . Does anyone know if this is a bug or some weird, yet >unexpected, behaviour? > Wouldn't int(22.47 + .5) get you to where you want to go? Dan From zcoder at bigmir.net Wed Aug 13 19:13:12 2003 From: zcoder at bigmir.net (Vlad Sirenko) Date: 14 Aug 2003 02:13:12 +0300 Subject: How to make tree of dictionaries? References: <87fzk6tuoq.fsf@big.terem> Message-ID: <87brutf8xj.fsf@big.terem> >>>>> "Michael" == Michael Peuser writes: >> ($month,$date,$hour,$minute,$sec,$year) = ($1,$2,$3,$4,$5,$6); >> $statistics->{$year}->{$month}->{$date} += $sec; Michael> This is what I love Perl for! BTW: Do you really mean += ? This Michael> does nor match yourt example, neither seems to make much Michael> sense. Perhaps a misconception? It doesn't matter. I just wanted to express the main idea and you caught it everything else has minor meaning. >> tmp_year = stats.setdefault(year, {}) >> tmp_month = tmp_year.setdefault(month, {}) >> tmp_month[date] = tmp_month.setdefault(date, 0) + sec Michael> *I* think this is less readable than the Python expression! Did you mean Perl expression? If so, may be it's time for another language change? Michael> Note that *get* and *setdefault* are most powerful operations on Michael> mapping types once you get used to them, that is... ;) Mapping types give great power and flexibility when programmer need to describe and manage structured data. -- WBR, VS The world is coming to an end ... SAVE YOUR BUFFERS!!! From mpeuser at web.de Fri Aug 15 13:27:33 2003 From: mpeuser at web.de (Michael Peuser) Date: Fri, 15 Aug 2003 19:27:33 +0200 Subject: cPickle alternative? References: Message-ID: o.k - I modified my testprogram - let it run at your machine. It took 1.5 seconds - I made it 11 Million records to get to 2 Mbyte. Kindly Michael ------------------ import cPickle as Pickle from time import clock # generate 1.000.000 records r=[(('k', 5, 0),), (('*', 0, 0),), (('t', 1, 1),), (('o', 2, 0),), (('t', 3, 0),), (('a', 4, 0), ('o', 2, 0))] x=[] for i in xrange(1000000): x.append(r) print len(x), "records" t0=clock() f=open ("test","w") Pickle.dump(x,f,1) f.close() print "out=", clock()-t0 t0=clock() f=open ("test") x=Pickle.load(f) f.close() print "in=", clock()-t0 --------------------- "Drochom" schrieb im Newsbeitrag news:bhj2ah$2ke$1 at nemesis.news.tpi.pl... > Thanks for help:) > > Here is simple example: > frankly speaking it's a graph with 100000 nodes: > STRUCTURE: > [(('k', 5, 0),), (('*', 0, 0),), (('t', 1, 1),), (('o', 2, 0),), (('t', 3, > 0),), (('a', 4, 0), ('o', 2, 0))] > > I0 > ttp5 > a((S't' > I3 > I0 > ttp6 > a((S'a' > I4 > I0 > t(S'o' > I2 > I0 > ttp7 > a. > > Maybe now you can give me more precise advice:) > Thanks again > > From geoff at gerrietts.net Thu Aug 28 00:27:27 2003 From: geoff at gerrietts.net (Geoff Gerrietts) Date: Wed, 27 Aug 2003 21:27:27 -0700 Subject: Celebrity advice (was: Advice to a Junior in High School?) In-Reply-To: <_M2cnY22TvKT69CiXTWJjA@comcast.com> References: <_M2cnY22TvKT69CiXTWJjA@comcast.com> Message-ID: <20030828042727.GA19170@isis.gerrietts.net> Quoting Terry Reedy (tjreedy at udel.edu): > (disconnected from CS). Quite aside from my disagreement about the > 'dangerous' characterization, is the boycott suggestion sensible and > legitimate, or just flamebait? I think you could fairly consider that flamebait, if the situation were as you characterized it. This situation is specifically when a given author writes scholarship -- or invective, whatever -- into two totally separate and readily distinguishable fields. The key in my mind is distinguishable. You can draw the line between Knuth's CS writings and religious writings. In some cases, it's more challenging: polemic and scholarship blend freely within articles that waver between analytic description and propaganda. I don't think it makes sense to avoid (say) ESR entirely; I do think that his work should be approached with some care and some capacity for critical analysis. It usually takes a year or two of college (often more!) for a student to acquire enough domain-specific knowledge to be able to evaluate a text and sort opinion from fact. As such, some writers (particularly the sort who love to speculate on fields they have no training in, or who get sloppy with their facts) are best left for when you can tell when they're talking out their ass, and when they actually know what they're talking about. Maybe ESR belongs to this category of writer? --G. -- Geoff Gerrietts "Don't get suckered in by the comments-- they can be terribly misleading. www.gerrietts.net/geoff/ Debug only code." --Dave Storer From me at privacy.net Sun Aug 17 08:51:34 2003 From: me at privacy.net (Heather Coppersmith) Date: 17 Aug 2003 08:51:34 -0400 Subject: Tuple to string problems References: <3f3b9080@dnews.tpgi.com.au> <3f3eea56@dnews.tpgi.com.au> Message-ID: On Sun, 17 Aug 2003 12:37:19 +1000, "Alastair G. Hogge" wrote: > Sean Ross wrote: >> >> "Alastair G. Hogge" wrote in message >> news:3f3b9080 at dnews.tpgi.com.au... >>> So basicly final_qu would be ('1','two','hello','2003-08-14','23:32:07') >>> However has stated above type(final_qu) return tuple. >> >> If final_qu is already a tuple of strings, and what you need is one string >> with each string in the tuple concatenated, then you can do this: >> >>>>> final_qu = ('1','two','hello','2003-08-14','23:32:07') >>>>> final_qu_str = ' '.join(final_qu) >>>>> final_qu_str >> '1 two hello 2003-08-14 23:32:07' >>>>> >> >> If you can't guarantee that each tuple element is a string, try this: >>>>> final_qu_str = ' '.join([str(e) for e in final_qu]) >>>>> final_qu_str >> '1 two hello 2003-08-14 23:32:07' >>>>> >> >> [str(e) for e in final_qu] creates a list of a strings from the elements >> [in >> final_qu. >> >> HTH >> Sean > OK. Sorry I didn't quite make myslef clear. > final_qu is a string for pydb. The string should be something link: > INSERT INTO foo VALUES "('1','two','hello','2003-08-14','23:32:07')" > I need the () and each value must be inclosed in '' for the database > interface. Having just been through this myself, you're playing with fire: what if one of those strings contains a quote character (single or double)? Let the database interface do the quoting for you. I don't know what your table looks like, but I see two possibilities (all code untested): If your table contains a single column in which you're trying to put that whole string: sql = """INSERT INTO foo VALUES (%s)""" params = (repr( final_qu ),) # "str" may work here, too pydbcursor.execute( sql, params ) If your table contains five columns, one for each element of that tuple: sql = """INSERT INTO foo VALUES (""" \ + ','.join( ['%s'] * len( final_qu ) ) \ + """)""" params = final_qu pydbcursor.execute( sql, params ) HTH, Heather -- Heather Coppersmith That's not right; that's not even wrong. -- Wolfgang Pauli From ozzyparrot at rocketmail.com Mon Aug 4 03:40:05 2003 From: ozzyparrot at rocketmail.com (Darren) Date: Mon, 04 Aug 2003 00:40:05 -0700 Subject: Python and Robotics? Message-ID: <3f2d1e1d$0$4192$afc38c87@news.optusnet.com.au> Hello All, Hope everyone is well. I am really new to python, so my question maybe some what stupid to some. The question is, can python be used as a programming language for robotics? eg, controling motors and sensors? If so, do you know any website that would contain such information ? Many thanks Darren From jackson at wsgforum.com Mon Aug 25 21:13:47 2003 From: jackson at wsgforum.com (jackson) Date: Mon, 25 Aug 2003 20:13:47 -0500 Subject: (no subject) Message-ID: <200308260113.h7Q1Dlt01053@wsgforum.com> In an ongoing effort to reduce the flood of emails I receive every day, I've initiated this automatic response email. If your email was concerning any of the following subjects, then this automatic email will serve as my response. First, please read the FAQ at http://www.wsgforum.com/forumfaq.html. The FAQ has the answers to 62 frequently asked questions covering a large range of subjects regarding the forum and it's operation, and in fact every question enumerated below is addressed in the FAQ. 1. If you are having trouble registering to use the forum, or logging into the forum, or posting messages, then please read http://www.wsgforum.com/06.html 2. If you want to know when your membership will be approved, then please read http://www.wsgforum.com/forumfaq.html#Q13 3. If you want me to change, or if you want to know when your membership status will be changed, to Senior Member status, then please read http://www.wsgforum.com/forumfaq.html#Q19 4. If you want me to post a report for you regarding a United States city, then please read http://www.wsgforum.com/forumfaq.html#Q30 5. If you want more information about a report, then please read http://www.wsgforum.com/forumfaq.html#Q35 6. If you want to contact the author of a report, then please read http://www.wsgforum.com/forumfaq.html#Q36 7. If you want me to provide more information about a report or any subject raised in the Forum, then please read http://www.wsgforum.com/forumfaq.html#Q37 8. If you want me to answer a specific question about a report or about any subject raised in the Forum, then please read http://www.wsgforum.com/forumfaq.html#Q38 This list covers 90% of the emails I receive every day, but if you emailed me regarding a different subject, I will respond as quickly as possible. Thanks, Jackson From soundwave56 at yahoo.com Fri Aug 15 02:59:31 2003 From: soundwave56 at yahoo.com (henry) Date: Fri, 15 Aug 2003 06:59:31 GMT Subject: GUI builder for Python Message-ID: Hi, Just wondering if there's a good GUI builder for Python. Something like Visual Tcl, where you just drag and drop objects. Not too good with creating user interfaces from code along. Thanks From woodsplitter at rocketmail.com Wed Aug 6 16:39:37 2003 From: woodsplitter at rocketmail.com (David Rushby) Date: 6 Aug 2003 13:39:37 -0700 Subject: Building extensions with mingw32 -- bdist_wininst fails. References: Message-ID: <7876a8ea.0308061239.6cbfd99@posting.google.com> "Chris Gonnerman" wrote in message news:... > [...] > error: Python was built with version 6 of Visual Studio, and extensions > need to be built with the same version of the compiler, but it isn't > installed. > > I checked the archives regarding that error message and found a conversation > wherein Jeremy Hylton claimed he might have added the code to detect this, > and Paul Moore asked to have it removed/disabled at least for mingw32 (which > makes binaries 100% compatible with MSVC6). In the case given then, the > extension wouldn't build at all; now it builds but I can't make a Windows > installer from it. > > mingw32 should be treated as 100% equivalent to MSVC6 in all cases... > please. I've got people clamoring for two of my extensions (and I didn't > even think they were popular) but I can't build installers. > > Is there any way I can get this to work? I have no trouble doing what you describe (with Python 2.1.3, 2.2.3, or 2.3). The core Pythons I'm using were compiled with MSVC 6 SP5 on Windows 2000 SP4, but I can build extension modules and installers just fine with MinGW (3.0-rc4). The only preparatory step was to generate libpythonXX.a, as described in the Section 6.2.2 of the standard library docs. Are you sure your compiler setup is correct? Was the core Python 2.3 you're using actually built with MSVC 6, as the error message claims? From warlock at eskimo.com Sun Aug 3 20:48:56 2003 From: warlock at eskimo.com (Jim Richardson) Date: Sun, 3 Aug 2003 17:48:56 -0700 Subject: Match beginning of two strings References: <3f2c429e@nntp0.pdx.net> <3f2c7806.20532894@news.lexicon.net> <6qpuv-q4m.ln1@grendel.myth> Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Sun, 3 Aug 2003 12:44:59 -0600, Andrew Dalke wrote: > Jim Richardson: >> Why bother finding out which one is the shorter? if you try the compare, >> and you run out of the other to compare to, then by default, it's not >> the same :) > > Because I wasn't sure if the strings had embedded NULs in them. > Python strings allow those. > Ah, I hadn't considered that. > Otherwise something like this would work > > char *s1, *s2 = ... the strings from Python > char *s = s1; > while ( *s1 && (*s1++ == *s2++)) > ; > return the string from s->s1, or just the size s1-s. > > Andrew > dalke at dalkescientific.com > > -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (GNU/Linux) iD8DBQE/La14d90bcYOAWPYRApsqAJ9OW1jCViH/ytTMwpMv/TtTo9Q0BwCg2/Hn R41XPXwJUhQYvCBnrqRMqLY= =arqM -----END PGP SIGNATURE----- -- Jim Richardson http://www.eskimo.com/~warlock Linux, because eventually, you grow up enough to be trusted with a fork() From danielk at aracnet.com Tue Aug 26 18:41:43 2003 From: danielk at aracnet.com (Daniel Klein) Date: Tue, 26 Aug 2003 15:41:43 -0700 Subject: Best way to write a file n-bytes long References: <8d3e714e.0308261404.12045d96@posting.google.com> Message-ID: <6bonkv8ji7et9udilt21e777674q13t1kj@4ax.com> On 26 Aug 2003 15:04:12 -0700, cappy2112 at yahoo.com (Tony C) wrote: >Does Python have a function that is analogous to C's write() or >fwrite()- > >that is , I want to write a file (of arbitrary data) that is 100K, or >1MB (or more) bytes long.. > >Both write() and fwrite() in C allow the user to specify the size of >the data to be written. > >Python's write only allows a string to be passed in. > >Sure, I could create a string that is n Megabytes long, and pass it to >write, but it seems as though there should be a better way ??? >String manipulation is typically considered slow. > >st="X" * 1048576 >fh=open("junk","wb") >fh.write(st) >fh.close() Pythons file objects are automatically treated as streams. So you could do something like this: st = 'X' somebignumber = 1048576 fh = open('junk','wb') for n in xrange(somebignumber): fh.write(st) fh.close() Daniel Klein From alanmk at hotmail.com Mon Aug 4 09:44:04 2003 From: alanmk at hotmail.com (Alan Kennedy) Date: Mon, 04 Aug 2003 14:44:04 +0100 Subject: Python speed vs csharp References: <1h5f2rzthqgid.8watonaa4cjt.dlg@40tude.net> <3F551D29.1040407@kfunigraz.ac.at> <0MoXa.21930$cl3.850221@news2.tin.it> <3F55B1CE.5010607@kfunigraz.ac.at> <3F55D7F1.5020804@kfunigraz.ac.at> Message-ID: <3F2E6324.3EFCF17@hotmail.com> [Siegfried Gonzi wrote] > For me Python is crap and not any longer worth to consider. Then move on, and give us all a rest. -- alan kennedy ----------------------------------------------------- check http headers here: http://xhaus.com/headers email alan: http://xhaus.com/mailto/alan From borcis at users.ch Mon Aug 18 11:39:58 2003 From: borcis at users.ch (Borcis) Date: Mon, 18 Aug 2003 17:39:58 +0200 Subject: Py2.3: Feedback on Sets References: <%BX%a.4999$N37.3051@nwrdny02.gnilink.net> <7h3d6f3143s.fsf@pc150.maths.bris.ac.uk> <3F40EC14.4030202@users.ch> <7h3zni7yph1.fsf@pc150.maths.bris.ac.uk> Message-ID: <3F40F34E.1040206@users.ch> Michael Hudson wrote: > >>>+ isn't totally silly (strings and lists are >>>monoids, at least :-). list * int, OTOH, seems a bit smelly to me >>>(though I'm not sure what a better spelling would be...). >> >>But strings/lists form a non-commutative monoid, so list * list >>would be better imho, and a corresponding list ** int > > Hmm, you're right of course,, but for some reason I prefer +. Maybe > it's the commutation with len()? renaming it to log() would make the *2+ homomorphism natural. > > Anyhoo, this is all pointless gassing :-) Right. From ptmcg at austin.rr.com Tue Aug 19 01:51:35 2003 From: ptmcg at austin.rr.com (Paul McGuire) Date: Tue, 19 Aug 2003 05:51:35 GMT Subject: python threads on multi-CPU machines References: <5a4226f0.0308180945.34f96eca@posting.google.com> Message-ID: Just one general caveat, based on some multi-thread code I worked on about a year ago: if you want to support your users running your multithread code on multi-CPU machines, you *must, must, must* stress test on multi-CPU machines! We had a very nasty intermittent bug (collision with threads in Tcl interpreter) that I could *not* reproduce on my single-processor development box, but which showed up in the field on the customer's quad-processor machine. Finally, after about a day and a half, I moved over to our dual processor test machine, and the bug showed up after about 20 minutes of stress testing. It turned out that the 3rd party thread library we were using was built to be compatible with the Win98 (!) thread API - once I rebuilt to run using the WinNT thread API, the window was closed, and the app ran great on the multiCPU servers. I'm sorry if this is off-topic, and I am fairly new in this newsgroup, but I know we were very eager to push multiCPU machines on our customers, and we did not realize what risk we were taking on. Sincerely, -- Paul McGuire Austin, TX From ajsiegel at optonline.net Sun Aug 31 13:16:19 2003 From: ajsiegel at optonline.net (Arthur) Date: Sun, 31 Aug 2003 13:16:19 -0400 Subject: artificial intelligence? Message-ID: <001001c36fe3$98757640$0c02a8c0@Arts> > Perhaps I need to google further. I'm guessing this gets us no closer to to a solution: http://www.cincyvineyard.com/staff/lutz.htm Nor this: http://www.perkinswill.com/html/frames/contact/display_contact.asp?P1=81&P2=485 though my thoughts are with him on moving up from "associate principal" to whereever one goes from there at Perkins and Will. Nor this (though we seem to be getting warmer): http://www.umt.edu/math/People/Lutz.html Art From sross at connectmail.carleton.ca Tue Aug 19 21:36:40 2003 From: sross at connectmail.carleton.ca (Sean Ross) Date: Tue, 19 Aug 2003 21:36:40 -0400 Subject: if in for loop References: Message-ID: "Ryan Lowe" wrote in message news:rkz0b.126472$_R5.47133670 at news4.srv.hcvlny.cv.net... > i thought id ask here before wirting a PEP, if people thought it would be a > good enhancement to allow if clauses in regular for-statements like so: Hi. This was brought up in July: http://groups.google.ca/groups?hl=en&lr=&ie=UTF-8&selm=840592e1.0307021036.508d7d7d%40posting.google.com Here's the link for the entire thread: http://groups.google.ca/groups?hl=en&lr=&ie=UTF-8&threadm=840592e1.0307021036.508d7d7d%40posting.google.com&rnum=1&prev=/groups%3Fhl%3Den%26lr%3D%26ie%3DUTF-8%26selm%3D840592e1.0307021036.508d7d7d%2540posting.google.com This was my response then (and now): http://groups.google.ca/groups?hl=en&lr=&ie=UTF-8&selm=LUYMa.5841%24eF3.721551%40news20.bellglobal.com Other opinions will differ. (For instance, Michele Simionato was +1 on the idea) -0 Sean Ross From mwh at python.net Tue Aug 26 10:00:33 2003 From: mwh at python.net (Michael Hudson) Date: Tue, 26 Aug 2003 14:00:33 GMT Subject: My own 12 points list References: Message-ID: <7h3n0dwzfl4.fsf@pc150.maths.bris.ac.uk> pruebauno at latinmail.com (nnes) writes: > I have really no mayor gripes, and the few things I would change would > break backward compatibility, but here is the list anyway: > > 1.) Eliminate the whole long stuff. E.g. built-in long () function, > "L", etc. It is a Python language implementation detail and I do not > care about how it is done as long as it is fast and correct. Make > python int adapt according to size of the integer and underlying > architecture. 8088-80286=16 bit integers, 386-586=32 > bit, x86-64=64bit. If number overflows the CPU architecture > auto-magically use internal (long) representation. In progress. See PEP 217. > 2.) Eliminate map (), filter (), reduce (). It can be replaced with > list comprehensions and for loops, which are easier to read. I'm wary of "eliminate" -- why break old code for no very good reason? "discourage", maybe. > 3.) Eliminate open (), use file () instead Hmm. I think "open" reads better, myself. > 4.) Eliminate xrange(), replace range() with xrange() implementation Backward compatibility again: some code really does expect to get a list out of range(). But there are signs things are nudging in this direction, slowly. > 5.) Eliminate built-in functions buffer(), callable(), delattr(), > dir(), getattr(), hasattr(), hash(), help(), id(), isinstance(), > len(), max(), min(), repr(), setattr(), sum(), str(), type(), > unichr() and make them methods of the root or base object. Ye gods, no. This would be pure churn. And I'm not sure it's even a good idea for some of those listed. > 6.) Eliminate lambda, use local ?def somename(param):return expr' > instead. With you here, modulo the usual "eliminate" concern. > 7.) Eliminate locals(), globals() and replace with a vars() that > defaults to locals, and accept a parameter to get globals(). Why? [...] > 10.) Eliminate the recursion limit on functions or better yet, include > an option to change from the default to infinite. No need to change > anything in the language. A lot of work in the implementation though. > Could use regular method up to a number of calls and then switch to a > less performant method. See www.stackless.com :-) > 11.) Add a big decimal type (something like java) in the standard > library. To be able to do bean counter type math easily. Are there so > few python applications that deal with money? Again, there is movement here. > 12.) Int division: return float (for engineers) or big decimal (for > bean counters) I really don't like the idea of having optional behaviour here. > Some of them are blatantly copied from Guidos regrets slides btw. I > just happen to agree with most of the points on them. I thought some of them looked familiar :-) ---- There's a distinction between "how would I do things if I could go back to the early 1990s and have a chat with Guido" and "what changes are worth making now". There's a price to any change (esp. ones like "eliminate open()"...) and I think my limit may be set a little lower than yours :-) Cheers, mwh -- ARTHUR: Why are there three of you? LINTILLAS: Why is there only one of you? ARTHUR: Er... Could I have notice of that question? -- The Hitch-Hikers Guide to the Galaxy, Episode 11 From peter at engcorp.com Fri Aug 29 14:58:27 2003 From: peter at engcorp.com (Peter Hansen) Date: Fri, 29 Aug 2003 14:58:27 -0400 Subject: python and webcam?? References: <3F4F56AB.19EFE5AB@engcorp.com> <3F4F6A31.1598071A@engcorp.com> <3F4F91EF.10B944A6@engcorp.com> Message-ID: <3F4FA253.A9FDD5F2@engcorp.com> Michael Peuser wrote: > > As far as I understand it he uses a standard DirectX (8.0) interface > "Device". It is only necessary to provide a proprietary driver which > supports this. Probably no chance for *very* legacy hardware.... Cool... so it works well with perhaps "most" common webcams under Windows (only). Not bad for a start. We can assume the OP is using Windows then, unless he comes back with a big stick. -Peter From adalke at mindspring.com Fri Aug 22 03:28:11 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Fri, 22 Aug 2003 07:28:11 GMT Subject: Match beginning of two strings References: <3f2c429e@nntp0.pdx.net> <3f2c7806.20532894@news.lexicon.net> <48d1f86b.0308212251.b9dcf4a@posting.google.com> Message-ID: Ma?ungo: > First, I'm not a python programmer... but I think is better test int. > Something like that: > > int *a = (int *) ...first string...; > int *b = (int *) ...second string...; Sure. That's an old trick. However, your code assumes your strings are word aligned. (Perhaps for Python they are but in general you cannot make that assumption about C char *s) You also have an off-by-one/off-by-four error. Suppose the two strings are "A", that is, an 'A' followed by a NUL. Then for (i=0; i References: Message-ID: <3F32C085.4070603@python.org> dan wrote: > next time the core RNG is changed, I think it would be useful to have > an -oldrandom switch. It is common practice in simulation projects > to depend on the fact that your random numbers will come out the same > if you use the same seed. In bumping to 2.3 with the new Mersenne > algorithm, I have no easy way of duplicating my old results. Then don't switch to 2.3, at least for that program. On POSIX systems, it's easy to specify which version you want: #! /usr/bin/python2.2 # or whatever From john at rygannon.com Tue Aug 12 16:13:32 2003 From: john at rygannon.com (BadJake) Date: Tue, 12 Aug 2003 20:13:32 GMT Subject: Is Python your only programming language? References: Message-ID: <3f3949f1$0$228$fa0fcedb@lovejoy.zen.co.uk> Python comes a close second to C++. I have never in my life and never will touch VB nor ASP All my system maintenance tools on bothe Windows and Linux are written in Python. Python is at the heart on Rekall, our programmable database client. Also I use Python to control the building, and packaging of the many variant of Rekall. In my work environment Python is everywhere with the exception of our web site. This because I cann't convince my ISP to include Python instead of or along with PHP. It is a great pity almost all ISPs world wide only offer the MySQL/PHP/Perl combination. I dislike both Perl and MySQL intensely and I tolerate PHP. I would much rather be able to make use of Python and PostreSQL for providing dynamic data content for my web site. BTW, if anybody knows of a cheap hosting service which offers Python and PostgreSQL, please let me know. What ever happened to customer choice? Regards John From warlock at eskimo.com Sat Aug 2 19:03:50 2003 From: warlock at eskimo.com (Jim Richardson) Date: Sat, 2 Aug 2003 16:03:50 -0700 Subject: Match beginning of two strings References: Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Sat, 02 Aug 2003 17:39:26 -0400, Ravi wrote: > Hi, > > I have about 200GB of data that I need to go through and extract the > common first part of a line. Something like this. > > >>>a = "abcdefghijklmnopqrstuvwxyz" > >>>b = "abcdefghijklmnopBHLHT" > >>>c = extract(a,b) > >>>print c > "abcdefghijklmnop" > > Here I want to extract the common string "abcdefghijklmnop". Basically I > need a fast way to do that for any two given strings. For my situation, > the common string will always be at the beginning of both strings. I can > use regular expressions to do this, but from what I understand there is > a lot of overhead. New data is being generated at the rate of about 1GB > per hour, so this needs to be reasonably fast while leaving CPU time for > other processes. > > Thanks > Ravi > Are you trying to match any to any strings? or only a pair as above? -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (GNU/Linux) iD8DBQE/LENWd90bcYOAWPYRAtWhAJ4ozTD1G3xLzVkeuJvPDJTsLbkcBQCfX4E0 YR/+zWSPDwX0uUf8y0QkxJs= =sGTb -----END PGP SIGNATURE----- -- Jim Richardson http://www.eskimo.com/~warlock Linux, because eventually, you grow up enough to be trusted with a fork() From rdacker at pacbell.net Sun Aug 10 18:48:18 2003 From: rdacker at pacbell.net (rdack) Date: 10 Aug 2003 15:48:18 -0700 Subject: can't connect Message-ID: <644f6688.0308101448.526534f2@posting.google.com> mysql 4.0.12 that comes with osx 10.2 MySQLdb 0.9.2 Python 2.2 (#1, 10/24/02, 16:10:52) [GCC Apple cpp-precomp 6.14] on darwin >>> Import MySQLdb >>> MySQLdb.connect() Traceback (most recent call last): File "", line 1, in ? File "/usr/lib/python2.2/site-packages/MySQLdb/__init__.py", line 63, in Connect return apply(Connection, args, kwargs) File "/usr/lib/python2.2/site-packages/MySQLdb/connections.py", line 116, in __init__ self.converter[types.StringType] = self.string_literal TypeError: object does not support item assignment ------------------ any thoughts? did i not build it correctly? From achrist at easystreet.com Wed Aug 6 14:48:36 2003 From: achrist at easystreet.com (achrist at easystreet.com) Date: Wed, 06 Aug 2003 11:48:36 -0700 Subject: Python 2.3 Breaks PySQLite a Little Message-ID: <3F314D84.E336C01F@easystreet.com> Have hit a problem with PySQLite and python 2.3. The new bool type doesn't want to get written properly to a database. I was expecting this to break when I started using True and False in python 2.2, but it didn't. Now there's a little trouble. I changed the _quote function in pysqlite main.py to look like: def _quote(value): if value is None: return 'NULL' elif isinstance(value, bool): ### Added return 0 + value ### Added elif type(value) in (IntType, LongType, FloatType): return value elif isinstance(value, StringType): return "'%s'" % value.replace("'", "''") elif hasattr(value, '__quote__'): return value.__quote__() elif hasattr(value, '_quote'): return value._quote() elif have_datetime and type(value) in \ (DateTime.DateTimeType, DateTime.DateTimeDeltaType): return "'%s'" % value else: return repr(value) Is that all it needs? Al From elainejackson7355 at home.com Sun Aug 17 00:58:37 2003 From: elainejackson7355 at home.com (Elaine Jackson) Date: Sun, 17 Aug 2003 04:58:37 GMT Subject: bitwise not - not what I expected Message-ID: <1YD%a.747879$3C2.17342633@news3.calgary.shaw.ca> Is there a function that takes a number with binary numeral a1...an to the number with binary numeral b1...bn, where each bi is 1 if ai is 0, and vice versa? (For example, the function's value at 18 [binary 10010] would be 13 [binary 01101].) I thought this was what the tilde operator (~) did, but when I went to try it I found out that wasn't the case. I discovered by experiment (and verified by looking at the documentation) that the tilde operator takes n to -(n+1). I can't imagine what that has to do with binary numerals. Can anyone shed some light on that? (In case you're curious, I'm writing a script that will play Nim, just as a way of familiarizing myself with bitwise operators. Good thing, too: I thought I understood them, but apparently I don't.) Muchas gracias for any and all helps and hints. Peace, EJ From jepler at unpythonic.net Sun Aug 24 22:08:43 2003 From: jepler at unpythonic.net (Jeff Epler) Date: Sun, 24 Aug 2003 21:08:43 -0500 Subject: python gripes survey In-Reply-To: <2a82921f.0308241641.5bf82d6d@posting.google.com> References: <2a82921f.0308241641.5bf82d6d@posting.google.com> Message-ID: <20030825020838.GB29366@unpythonic.net> On Sun, Aug 24, 2003 at 05:41:35PM -0700, Patrick Lioi wrote: > I would also like to see what would probably end up being called > "generator comprehensions". That is definitely not my own idea, but > for the life of me I can't remember where I first heard about it. > Imagine being able to throw the yield keyword into a list > comprehension syntax in order to take advantage of list > comprehension's in a memory-efficient way, something kinda like this: > > foo = [yield i*i for i in xrange(100)] I also think that this would be a nice thing to have. I think that one barrier to it was the lack of an implementation. I don't remember what other objections were recorded in the PEP mentioned in another followup. Jeff From p-abel at t-online.de Tue Aug 5 16:37:09 2003 From: p-abel at t-online.de (Peter Abel) Date: 5 Aug 2003 13:37:09 -0700 Subject: check if running under IDLE References: <3f2ec16b$0$285$ba620e4c@reader0.news.skynet.be> Message-ID: <13a533e8.0308051237.6bfa05d3@posting.google.com> Helmut Jarausch wrote in message news:<3f2ec16b$0$285$ba620e4c at reader0.news.skynet.be>... > Hi, > > I'd like to check a script which needs sys.argv > I haven't seen a method to set this when running the script > in IDLE's shell or editor window. > The only way I've found is to assign (test values) > to sys.argv but only if the script is running under IDLE > > Is there a mean either to set sys.argv without modifying > the script or to check if the script is running under IDLE's > control. > > Thanks for a hint, > > Helmut Jarausch > > Lehrstuhl fuer Numerische Mathematik > RWTH - Aachen University > D 52056 Aachen, Germany I doen't think that your problem is to know if you're running under Idle or PythonWin or Pythonshell or .. I think your problem is to know if there are command line parameters passed to your script or not. And this is simply done by: if len(sys.argv) > 1: do_something_with(sys.argv[1:]) else: do_something_else_with_explicit(['Para_1','Para_2', ... ,'Para_Last'] Hope I'm not wrong. Regards Peter From jjl at pobox.com Fri Aug 22 18:55:35 2003 From: jjl at pobox.com (John J. Lee) Date: 22 Aug 2003 23:55:35 +0100 Subject: Deficiency in urllib/socket for https? References: <6vaakvorefvifnt3fk59r6tcj16c59rrfi@4ax.com> <87r83dzr34.fsf@pobox.com> <1hlckvot3mr78up9o52uiutse4ofh1d2vq@4ax.com> <87fzjtpefg.fsf@pobox.com> Message-ID: <87n0e1i9p4.fsf@pobox.com> jjl at pobox.com (John J. Lee) writes: [...] > You're right -- with the caveat that it is useful to have https even > without authentication (essentially all https traffic on the internet > proves that ;-). [...] I should have said "...it is useful to have *support* for https...". The utility of https itself is another matter... John From ldrhcp at yahoo.com Mon Aug 18 22:57:03 2003 From: ldrhcp at yahoo.com (Lenny D) Date: 18 Aug 2003 19:57:03 -0700 Subject: Python newbie help References: <87fa5cfa.0308181126.c61bfa2@posting.google.com> Message-ID: <9f2a0b6e.0308181857.5ebfc56f@posting.google.com> I too am new to Python. I found a very good tutorial called Dive Into Python that explains the idea behind the language, which seems to be what you want. The tutorial is very complex and thorough understanding of OOP is a prerequisite. From ramen at lackingtalent.com Sun Aug 17 00:17:26 2003 From: ramen at lackingtalent.com (Dave Benjamin) Date: Sun, 17 Aug 2003 04:17:26 -0000 Subject: Guido interviewed by Steve Holden Message-ID: Check it out, y'all: http://www.onlamp.com/pub/a/python/2003/08/14/gvr_interview.html Thanks Steve and Guido for an entertaining read. =) Good luck in California, Guido! Drink some Peet's for me... Peace, Dave From tim at remove_if_not_spam.digitig.co.uk Thu Aug 21 13:03:37 2003 From: tim at remove_if_not_spam.digitig.co.uk (Tim Rowe) Date: Thu, 21 Aug 2003 18:03:37 +0100 Subject: Python should try to displace Java References: <3f3e89f3$0$225$626a54ce@news.free.fr> Message-ID: On Wed, 20 Aug 2003 17:00:13 GMT, Alex Martelli wrote: >Doug Tolton wrote: [snip] >> I don't know how stating the obvious 'that some languages are better >> at some tasks than other languages' would be considered a troll. > >With such genericity, it could hardly offend anybody (and it would >be just as unlikely for the super-generic assertion to prove USEFUL >to anybody, of course:-). Though I have upset a few people hereabouts in the past by suggesting that the statement could apply to Python :-) From aleax at aleax.it Tue Aug 5 14:33:14 2003 From: aleax at aleax.it (Alex Martelli) Date: Tue, 05 Aug 2003 18:33:14 GMT Subject: Unable to run IDLE from 2.3? References: <1akviv4cpectdogklmuupg7rc37lhe1pc7@4ax.com> Message-ID: M Wells wrote: > I recently downloaded and installed Python 2.3 for Windows (on XP > professional) and I don't seem to be able to run IDLE from my start > menu? It seems something happens when I click on it (ie I get an > hourglass) but no actual application turns up. > > Has anyone else experienced this and can anyone give me some advice on > how to fix it? There are two known causes for this bug: -- you installed Python in a directory with a space in its path Workaround: uninstall it, install it again in a directory with no spaces in its path, e.g. its default C:\Python23 -- you are running a "personal firewall" that is set to inhibit connections to host 127.0.0.1 Workaround: remove your "personal firewall" or at least reprogram it so that connections to 127.0.0.1 are allowed; 127.0.0.1 in TCP/IP means "this very host, me, myself" and therefore there is no way in which connections to this address can put you at risk. IDLE 1.0 uses sockets for communication between the 'main' process and a secondary process that's set up to run code being developed, and some misprogrammed 'personal firewalls' are known to interfere with this. In theory, it is conceivable that a bad installation of "networking" on some Windows machine might cause the same effect as a misconfigured 'personal firewall', but so far in each case I've analyzed it did boil down to 'personal firewalls'. It's not necessarily the case that your troubles come from either of these known causes, but please check both of them -- if it's something else again, we'll need to root around for it. Alex From aleax at aleax.it Fri Aug 29 07:28:56 2003 From: aleax at aleax.it (Alex Martelli) Date: Fri, 29 Aug 2003 11:28:56 GMT Subject: Burn some books (please)... References: Message-ID: David Mertz, Ph.D. wrote: > Alex Martelli wrote previously: > |>>Very long ago, some books where burnt in public, > > |Very long as in, Winter 2001/2002, for example? > |...as long of course as the books you burn belong to you, that's a form > |of political speech which is just as acceptable as burning a flag. > > I just want to point out to the readership that many copies of _Text > Processing in Python_ are available at your local bookstore for public > burning. There's heresy in that book! (apparently I trend a bit to far > in an FP direction :-)). > > I think I can speak for Alex in pointing out that _Python in a Nutshell_ > also makes for excellent kindling. Unfortunately, the "Nutshell" is far too orthodox to make good burning material in the symbolic sense, even though its physical combustibility is not in doubt. Rather, I would suggest the "Python Cookbook", which does have enough examples of a-tad-too-clever-for-your-own-good tricks (just like David's "Text Processing with Python") to make burning it on the altar of simplicity a symbolically worthwhile endeavour. Alex From andymac at bullseye.apana.org.au Fri Aug 29 05:50:21 2003 From: andymac at bullseye.apana.org.au (Andrew MacIntyre) Date: Fri, 29 Aug 2003 19:50:21 +1000 (EST) Subject: how fast is Python? In-Reply-To: References: Message-ID: <20030829194942.G24765@bullseye.apana.org.au> On Fri, 29 Aug 2003, Robin Becker wrote: > experience with ReportLab suggests jython can be fairly slow compared to > CPython although it does have advantages. The advantages being? Regards, Andrew. -- Andrew I MacIntyre "These thoughts are mine alone..." E-mail: andymac at bullseye.apana.org.au (pref) | Snail: PO Box 370 andymac at pcug.org.au (alt) | Belconnen ACT 2616 Web: http://www.andymac.org/ | Australia From bokr at oz.net Thu Aug 7 04:46:54 2003 From: bokr at oz.net (Bengt Richter) Date: 7 Aug 2003 08:46:54 GMT Subject: Bug? If not, how to work around it? References: Message-ID: On Wed, 06 Aug 2003 20:40:25 +0100, Gon?alo Rodrigues wrote: >Hi, > >Consider the following class: > >>>> class Test(object): >... def __init__(self, obj): >... self.__obj = obj >... def __getattr__(self, name): >... return getattr(self.__obj, name) >... > >Now: > >>>> a = Test([]) >>>> a.__iter__ > >>>> iter(a) >Traceback (most recent call last): > File "", line 1, in ? >TypeError: iteration over non-sequence >>>> > >Is this a bug? If not, how to code Test such that iter sees the >__iter__ of the underlying object? > Perhaps this way? >>> class Test(object): ... def __init__(self, obj): ... self.__obj = obj ... def __getattribute__(self, name): ... return getattr(object.__getattribute__(self, '_Test__obj'), name) ... def __iter__(self): ... return iter(object.__getattribute__(self, '_Test__obj')) ... >>> a = Test([11, 22]) >>> a.__iter__ >>> iter(a) >>> for i in a: print i, ... 11 22 >>> b = Test('abc') >>> for c in b: print `c`, ... 'a' 'b' 'c' >>> c = Test(123) >>> for x in c: print x ... Traceback (most recent call last): File "", line 1, in ? File "", line 7, in __iter__ TypeError: iteration over non-sequence >>> Regards, Bengt Richter From mcfletch at rogers.com Fri Aug 22 14:10:55 2003 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Fri, 22 Aug 2003 14:10:55 -0400 Subject: Win32 ping In-Reply-To: <4cs1b.344$f7.80337@localhost> References: <4cs1b.344$f7.80337@localhost> Message-ID: <3F465CAF.5090700@rogers.com> Sean Cody wrote: > Does anyone know of an ping module that will work with Windows? Jeremy Hylton's code works well on Windows. It's fairly straightforward to code up an asynchronous loop to allow pinging a few hundred ip addresses (using the ping module primarily to properly encode the packets). I'm wondering, however, if you couldn't simply set the timeout lower for the connections? HTH, Mike _______________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://members.rogers.com/mcfletch/ From peter at engcorp.com Thu Aug 21 11:06:19 2003 From: peter at engcorp.com (Peter Hansen) Date: Thu, 21 Aug 2003 11:06:19 -0400 Subject: how fast is Python? References: Message-ID: <3F44DFEB.60AB6492@engcorp.com> dan wrote: > > However, there are definitely cases where a lot of code would need to > be optimized, and so I ask the question: How fast is Python, compared > to say a typical optimizing C/C++ compiler? C is roughly 10 to 100 times faster than Python, though of course it's easy to find cases outside of this range, on either side. I use 30 as a general overall rule of thumb, in the exceptionally few cases where it seems relevant how much faster C would be. And in those very few cases, so far, I have consistently concluded I'm happy enough with the speed of Python given that the speed of *development* in Python is easily 5 to 10 times faster than the speed of development in C. (And again, it's easy to find cases outside of this range, on either side...) -Peter From logiplex at qwest.net Tue Aug 12 13:55:15 2003 From: logiplex at qwest.net (Cliff Wells) Date: Tue, 12 Aug 2003 10:55:15 -0700 Subject: Python vs. C# In-Reply-To: <3f36af20@shknews01> References: <2259b0e2.0308100616.55b651ca@posting.google.com> <3f36af20@shknews01> Message-ID: <1060710915.2221.4192.camel@software1.logiplex.internal> On Sun, 2003-08-10 at 13:55, Brandon J. Van Every wrote: > Microsoft does almost all of its internal development in C# now. It is not > going away. Using QBasic to develop the POSIX layer for Windows NT didn't stop that language from disappearing ;) > I'm beginning to think that within 5 years, no new applications will be > written in C++. People will still be using legacy C++ libraries, but all > new development will be in higher level langauges. As much as I'd like to see that, I'm choking on my coffee. You are obviously painfully new to this industry. > Java and C# are the obvious languages that are not going away. > Python? What industrial entity is going to champion Python? Perhaps people who think for themselves and simply choose the best tool don't need shiny brochures and a pat on the back from a salesman to feel they've made a good choice. > It takes a Sun, a Microsoft, or overwhelming utility to push a > language. For instance, Perl has become popular because > it's overwhelmingly useful for sysadmin and web admin. So it takes marketing or usefulness for a language to be adopted? Versus what? A mackerel and a tennis racket? Do you work for Gartner? Most people look at things like past growth and market size to predict future growth for a product. You're starting to sound like your research was done on page 3 of PC Magazine. If you think it takes major marketing to push a language, let me ask you this: what are you doing on this list? No, really. You couldn't possibly have discovered Python without a major corporate advertising campaign, so how did you find your way here? It seems almost... contradictory. > But I am not seeing Python's overwhelming utility compared to other languages. Then perhaps you should spend less time trolling the newsgroups and more time programming. > You can do apps, you can do web admin, but most people are doing Java, C#, or Perl. And > unlike C++ they aren't bad languages, so Python is not offering an obvious "slam dunk" remedy. Perl isn't a bad language? Perl is a terrific tool but a terrible language. I could go on, but I think your own statements sum up your abilities to make any sort of qualitative judgement regarding programming languages. No wonder you chose C++. Regards, -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 (800) 735-0555 From robin at jessikat.fsnet.co.uk Fri Aug 1 11:27:59 2003 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Fri, 1 Aug 2003 16:27:59 +0100 Subject: anti-aliased 2D vector graphics References: Message-ID: In article , Andy C writes >Note that I'm on Windows... if there is some windows-specific solution, that >would be fine. I know there is a python win32 interface, and I think GDI >supports anti-aliased vector graphics, but I'm not sure. And fonts -- I >need to draw text too. Anyone tried that approach? > >thanks, >Andy > ReportLab graphics does anti aliased bitmap drawing via libart_lgpl, but I know it's not easy to get into. -- Robin Becker From skip at pobox.com Sat Aug 9 13:50:39 2003 From: skip at pobox.com (Skip Montanaro) Date: Sat, 9 Aug 2003 12:50:39 -0500 Subject: A very simple benchmark of Python based web server: Zope, mod_python with Apache, Twisted Framework In-Reply-To: <112c0f79.0308090412.5ab49b48@posting.google.com> References: <112c0f79.0308090412.5ab49b48@posting.google.com> Message-ID: <16181.13423.781755.949354@montanaro.dyndns.org> Bowen> I use a 4KBytes HTML content to do this benchmark, Bowen> it is just a simple test of python based web server. ... Can you provide some explanation of the output or pointers to the code you used to perform the test? Skip From mack at incise.org Sun Aug 17 02:19:04 2003 From: mack at incise.org (mackstann) Date: Sun, 17 Aug 2003 01:19:04 -0500 Subject: os.system stdout redirection... In-Reply-To: References: Message-ID: <20030817061904.GB22065@incise.org> On Sun, Aug 17, 2003 at 01:01:41AM -0500, Terry Gray wrote: > Using Python 2.2 in Debian linuxI am trying to change to a different > directory, execute a 'make all' command, and redirect the output of the > subshell to a PyQt window... I should be able to execute the > os.system('cd newdirectory; make all'), but how do I redirect stdout of > the new subshell created by the os.system call? > > Any help would be appreciated. You can use os.popen (popen2 and 3 as well), or the popen2 module's Popen3 and 4 classes, or commands.getoutput (and there are probably even more ways :). -- m a c k s t a n n mack @ incise.org http://incise.org While having never invented a sin, I'm trying to perfect several. From shawn at thekompany.com Mon Aug 25 09:44:03 2003 From: shawn at thekompany.com (Shawn Gordon) Date: 25 Aug 2003 06:44:03 -0700 Subject: ANN: BlackAdder V1.0.0 References: <3f48a498$3$219$fa0fcedb@lovejoy.zen.co.uk> <1Kj2b.61523$bo1.38258@news-server.bigpond.net.au> Message-ID: Gerhard H?ring wrote in message news:... > Neil Hodgson wrote: > > Gerhard H ring: > > > >>Furthermore, I'd excpect an email address with a connection to the > >>company that offers the product, something like > >>blackadder at thekompany.com, sales at thekompany.com or something like that. > >>Not some random BadJake with a completely different email address ;-) > > > > I'm interested in what has happened here. [...] > > I've written to sales at thekompany.com and recommended they publicly > clarify the issue. > > -- Gerhard John works for us, but BlackAdder isn't the product he works on, and he had misunderstood internally that when we put out the release candidate recently that it was the 1.0, the 1.0 will be out in the next week to 10 days. We had just hired a marketing person last week as well and there is some further internal confusion as to pointing things out to her and just doing it. So I'm sorry for any confusion that might have arisen, you can write to sales at thekompany.com if you are interested in any information, also if you were to purchase BlackAdder now, you would get it for the discounted beta price and then get 1.0 when it is released as part of your purchase (no further cost), since we are getting very close to that 1.0, the window is short to enjoy that discount. Again, sorry for any trouble or confusion that might have been caused. Shawn Gordon President theKompany.com From aahz at pythoncraft.com Wed Aug 20 10:05:51 2003 From: aahz at pythoncraft.com (Aahz) Date: 20 Aug 2003 10:05:51 -0400 Subject: Brandon's personal style (was) References: Message-ID: In article , Brandon J. Van Every wrote: > >I meant in regards to my sanity. ;-) Aahz has deduced that because I'm not >a troll, I'm insane. No, I haven't. You have a problem with reading comprehension. As I said before, I'm not going to waste further time trying to educate you, but I wanted to make clear that you are not reading what I wrote. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From maxm at mxm.dk Mon Aug 11 08:16:35 2003 From: maxm at mxm.dk (Max M) Date: Mon, 11 Aug 2003 14:16:35 +0200 Subject: Python vs. C# In-Reply-To: References: Message-ID: <3F378923.4080806@mxm.dk> Bob Gailer wrote: > What is "trolling"? > http://www.urban75.com/Mag/troll.html regards Max M From eadorio at yahoo.com Fri Aug 8 00:39:33 2003 From: eadorio at yahoo.com (Ernie) Date: 7 Aug 2003 21:39:33 -0700 Subject: Gmpy References: <8578e2c1.0308070630.5fb70c22@posting.google.com> Message-ID: <5b42ae4.0308072039.583e00e4@posting.google.com> Alex Martelli wrote in message news:... > Carl Banks wrote: > > > Jean-Pierre Andreaux wrote: > >> Gmpy module was a wrapper of the GNU MP library. It seems that no > >> evolution is done on this module since 2001. Indeed, Gmpy is not > >> supported in Python 2.2 nor 2.3. > >> > >> My question is the following: what is the better replacement solution > >> for manipulating long numbers. I want to do long numbers > >> exponentiations. Thanks in advance for your answers. > > > > > > An alternative is egenix mxNumber package, still in beta stage. > > > > http://www.egenix.com/files/python/mxNumber.html > > > > I couldn't use gmpy because I needed floating point, and mxNumber also > > wraps the floating point functionality. It seemed to work ok. > > gmpy also wraps the floating-point functionality of GMP: > > >>> print gmpy.mpf(7,99)/3 > 2.333333333333333333333333333333333333333 I am using the XR package from http://more.btexact.com/people/briggsk2/XR-2.0.tgz and want to try out the gmpy for comparison. However, trying to install gmpy-sources-09a21.zip, results in an error: running install running build running build_ext building 'gmpy' extension gcc -pthread -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/local/include/python2.3 -c gmpy.c -o build/temp.linux-i686-2.3/gmpy.o In file included from /usr/local/include/python2.3/Python.h:8, from gmpy.c:101: /usr/local/include/python2.3/pyconfig.h:844:1: warning: "_POSIX_C_SOURCE" redefined In file included from /usr/include/assert.h:36, from gmpy.c:96: /usr/include/features.h:171:1: warning: this is the location of the previous definition gmpy.c: In function `Pygmpy_rand': gmpy.c:5053: structure has no member named `seed' error: command 'gcc' failed with exit status 1 Ernie From rich at worldsinfinite.com Mon Aug 11 16:56:33 2003 From: rich at worldsinfinite.com (Rich Harkins) Date: 11 Aug 2003 16:56:33 -0400 Subject: ANN: pychains-0.1.0 Message-ID: <1060635392.20371.16.camel@laptop.worldsinfinite.com> pychains is a C-based python module providing a couple of useful Python types that delegate certain requests (__getitem__ and __getattr__) to other objects. Using pychains one can create dictionaries that are aggregates of other dictionaries, objects whose attributes come from numerous other objects, etc. Documentation, as it stands, is available on the home page as is the download link: http://pychains.sourceforge.net STANDARD DISCLAIMER: This code is *very* alpha. I'm using it in some of my projects and it hasn't crashed in a while so I'm allowing it into the source-compiling public for further testing, etc. I'm suspicious it may be leaking memory and I cannot guarantee it won't do something horrible. PLEASE don't use it where it doesn't belong (mission critical stuff). Regards, Rich -- Rich Harkins From mis6 at pitt.edu Sun Aug 17 12:37:16 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 17 Aug 2003 09:37:16 -0700 Subject: Python should try to displace Java References: Message-ID: <2259b0e2.0308170837.9bd5aeb@posting.google.com> "John Roth" wrote in message news:... > ... Ruby is the one that's gaining fastest, and it has > a number of interesting features that Guido would do well to think about. Out of curiosity, which features are you referring to? Michele From jarausch at igpm.rwth-aachen.de Thu Aug 21 03:18:48 2003 From: jarausch at igpm.rwth-aachen.de (Helmut Jarausch) Date: Thu, 21 Aug 2003 09:18:48 +0200 Subject: csv - howto specify fmtparam parameters Message-ID: Hi, according to the docs the following should work (IMHO) import csv csv_file= file('test.csv') Inp= csv.DictReader(csv_file,['Matr','Name','Vorname','PZ','MP'],\ lineterminator='\n') for S in Inp: print S but I get Traceback (most recent call last): File "/home/jarausch/Python/My/test_csv.py", line 5, in -toplevel- lineterminator='\n') TypeError: __init__() got an unexpected keyword argument 'lineterminator' What went wrong? Thanks for a hint, Helmut Jarausch Lehrstuhl fuer Numerische Mathematik RWTH - Aachen University D 52056 Aachen, Germany From p_s_oberoi at hotmail.com Thu Aug 21 15:31:03 2003 From: p_s_oberoi at hotmail.com (Paramjit Oberoi) Date: Thu, 21 Aug 2003 14:31:03 -0500 Subject: Reading/Writing Config Files Message-ID: I need to read/write config files that will be updated by both users as well as programs. All config-file modules that I have looked at so far aren't completely satisfactory: 1. ConfigParser: does not preserve order of entries in the config file and comments when updating the file. This is critical since people are going to be reading/updating those files as well. 2. pylibini (http://3dfx4ever.oltrelinux.com/projects/pylibini/) For the last several months, the web page has said, "Please do NOT download the current version of pylibini. In few days time a new version pylibini with lots of new features and big fixes will be released." It looks pretty good otherwise, but if the developers themselves don't want me to use it... 3. FLAD (http://phd.pp.ru/Software/Python/): Satisfies all my requirements, but the code dates back to 1997, and the API isn't very pythonic, I think. Are there other libraries I should look at? Should I just write one myself (or clean up [2] or [3]) ? I can't believe there isn't something better available for such a common task... Thanks, -param From jepler at unpythonic.net Mon Aug 18 14:29:39 2003 From: jepler at unpythonic.net (Jeff Epler) Date: Mon, 18 Aug 2003 13:29:39 -0500 Subject: What's TOTALLY COMPELLING about Ruby over Python? In-Reply-To: References: Message-ID: <20030818182939.GO16941@unpythonic.net> On Mon, Aug 18, 2003 at 11:07:56AM -0700, Brandon J. Van Every wrote: > I'm realizing I didn't frame my question well. > > What's ***TOTALLY COMPELLING*** about Ruby over Python? Nobody who uses Python would believe that there's anything "totally compelling" about Ruby. If there were, then none of the posts in c.l.python would be by people using Python. Of course, this doesn't mean that the newsgroup would be empty. There would still be "enlarge the size of your Python"-type spam. And there might even be the odd troll who would keep posting shit, trying to get the Python community riled up. Of course, without Python users, he wouldn't have much fun, would he, with nobody stupid enough to stand up to defend Python and "get trolled". So even the troll should be glad that there's nothing "totally compelling" about Ruby over Python. Jeff PS I'd just like to state for the record that neither Python nor Ruby have a totally compelling advantage compared to the following languages: BASIC /bin/sh BrainF**k Forth IBM 1180 assembler K&R C LOGO make Objective COBOL Orthagonal* RPG/3 WaX WatFiv Fortran ... conversely, in 1985, about half the above did have a compelling advantage over both Python and Ruby: they existed. * Of course, I don't think a non-trivial program was ever written in Orthagonal, despite the fact that it's been around since '92 or '93. From Ixtlan at yahoo.com Sat Aug 16 18:43:46 2003 From: Ixtlan at yahoo.com (Ixtlan) Date: Sun, 17 Aug 2003 00:43:46 +0200 Subject: omniORB 4.0.2 and omniORBpy 2.2 released References: <2428b$3f33cfec$516049d2$15672@nf1.news-service.com> Message-ID: "Duncan Grisby" wrote in message news:2428b$3f33cfec$516049d2$15672 at nf1.news-service.com... > omniORB version 4.0.2 and omniORBpy 2.2 are now available. > Enjoy! We are already enjoying omniORB 4.0.2 very much, our whole DAK production (Architectural company) is based on it now! Thanks! Ixtlan From peter at engcorp.com Tue Aug 12 07:32:09 2003 From: peter at engcorp.com (Peter Hansen) Date: Tue, 12 Aug 2003 07:32:09 -0400 Subject: Howto MACRO in python ? References: Message-ID: <3F38D039.2B28800A@engcorp.com> Bill Loren wrote: > > I was looking for a guidance about how to code MACROs in python. > any offer ? A few alternative responses to Irmen's to-the-point answer: 1. Nobody does. 2. Those who do, probably use a macro language, like maybe M4. 3. Nobody does. 4. What are you actually trying to accomplish, specifically? -Peter From fredrik at pythonware.com Mon Aug 4 09:07:17 2003 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 4 Aug 2003 15:07:17 +0200 Subject: Classes in Python References: <14dsivkn40c0grotsti39cgsrde7v03hq4@4ax.com> Message-ID: Wiebke P?tzold wrote: > class PatternFilter: > def _init_(self, pattern): > self.pattern = re.compile(pattern) > > def _call_(self, row): > try: > nachname = row.Nachname > except AttributeError: > return 0 > return self.pattern.search(nachname)is not None > > vf = vw.filter(PatternFilter("Ge.*")) > > for r in vf: > print vw[r.index].Nachname > > I wrote this program, but it returns nothing. I can't find the error. > Can somebody help me? > Can somebody tell me why the part: "class PatternFilter:" doesn't > return the expressions it should return? note that built-in hooks like __init__ and __call__ uses *two* underscores on each side of the keyword. not sure why vw.filter doesn't give you an exception, but your Pattern- Filter instance is neither initialized nor callable. From ghowland at lupineNO.SPAMgames.com Sat Aug 23 13:10:41 2003 From: ghowland at lupineNO.SPAMgames.com (Geoff Howland) Date: Sat, 23 Aug 2003 17:10:41 GMT Subject: Modifying the {} and [] tokens References: <04cekv0s6ghjtuhl5j2gph7ltobdb5rsam@4ax.com> <62rekv0k4ucgrh46lkp27klq13pq8ppp5p@4ax.com> <1h3fkvg8mkeq69a8hriojugqfcp75hafjj@4ax.com> Message-ID: <5l7fkvsd2lor14s7s0avra2553nfhe3net@4ax.com> On Sat, 23 Aug 2003 12:40:05 -0400, Roy Smith wrote: >Geoff Howland wrote: >> {} + {} is not allowed. > >What would it mean? What would you do if you had two dicts: > >d1 = {'a':1, 'b':2} >d2 = {'a':42} > >what would the value of (d1+d2)['a'] be? I dont think it matters. Pick one and make that the standard. The current norm is "last one in clobbers the existing", so keep that and d = d1 + d2 ; d['a'] == 42 I really dont think it matters that its not perfect, what matters is that it's possible and if you have unique keys, or dont care about clobbering, then you dont have to do this yourself. If you do care, you have to write your own routine. As it stands now, everyone has to do this every time, even if they would never encounter the clobbering situation, or dont care. It's the same reason an exception isnt thrown for this: {'a':5, 'a':6} Obviously, you cant have both, but it's legal. As long as the rules are defined and it stays consistent every time, then it can be of use. Same for subtraction to remove overlaps, etc. It's an operator, so it only has one use per term. Even if it's not handling all cases, why make everyone re-implement the same one 80% of the time? In my work, this would be useful functionality, and maybe other places it would be dangerous and thus it shouldnt be added to the language because it's better not to mess with it. That's fine, then I was still looking for a way to make it work just with _my_ code. Since it is now clear to me that this isn't possible with the {} tokens, then I will just go about it the way that does work. :) I just wanted the best solution for my own problem at hand. -Geoff Howland http://ludumdare.com/ From peter at engcorp.com Wed Aug 13 10:35:38 2003 From: peter at engcorp.com (Peter Hansen) Date: Wed, 13 Aug 2003 10:35:38 -0400 Subject: The importance of using Library Functions References: Message-ID: <3F3A4CBA.BCACEC50@engcorp.com> Doug Tolton wrote: > > Interestingly TextWrap choked on the text I'm running it against. I'm > sure it's more an issue of complete craziness in these files than an > actual problem with TextWrap. I believe textwrap.py has some fairly extensive unit tests.** Could you please post your failing example (if it's not too big), or email it to me and/or Greg Ward to investigate? Thanks. -Peter ** (I believe this since Greg wrote them and I ported them to PyUnit. I don't know if that's what's still with the module in Py2.3.) From vanevery at 3DProgrammer.com Mon Aug 18 03:38:48 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Mon, 18 Aug 2003 00:38:48 -0700 Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> <38ec68a6.0308172321.2e3c03b7@posting.google.com> Message-ID: Asun Friere wrote: > Erik Max Francis wrote in message > news:<3F4040F8.87901505 at alcyone.com>... >> "Brandon J. Van Every" wrote: >> >>> What's better about Ruby than Python? I'm sure there's something. >>> What is >>> it? >> >> Wouldn't it make much more sense to ask Ruby people this, rather than >> Python people? > > Maybe he can't speak Japanese? I can't actually. Didn't know that Ruby was Nippocentric. And no, it wouldn't make "more sense" to ask the Ruby people this. They are going to give an answer that's biased from the Ruby perspective. For purposes of this post, I'm interested in the Python biased perspective. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From duncan at NOSPAMrcp.co.uk Wed Aug 20 04:57:58 2003 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Wed, 20 Aug 2003 08:57:58 +0000 (UTC) Subject: Unification of logging in Python's Standard Library References: <3a8e83d2.0308182217.7ccaf883@posting.google.com> <3a8e83d2.0308191655.7a82881b@posting.google.com> Message-ID: "John Roth" wrote in news:vk5kc9g9uqj038 at news.supernews.com: >> I will say that unittest is what motivated me to suggest this in the >> first place, since I'm working on a testing framework that is >> attempting to take advantage of both the unittest *and* logging >> modules. Perhaps a new TestRunner class that uses logging >> (LoggingTestRunner?) might coexist with the default TextTestRunner. > > Perhaps you could tell us a bit more about this? My usage of > unittest is (relatively) pure XP/TDD - I expect all of the tests > to pass except the last one I worked on, and when they don't, > I swat it immediately. Consequently, I don't see any need for > logging anything. > I would find it interesting, and possibly even useful, if unittest could be made to record some historical information in a database. e.g. The date and time when each unit test first failed, first passed, and most recently failed/passed, and the number of times each test has passed/failed. A record of the #lines of code each time the tests all pass would also be useful, and you probably want to record the stats separately against each developer. On a project with several developers (or one undisciplined one like myself) you could potentially use these figures to flag problems, such as someone whose tests usually pass first time is probably doing test last rather than test first coding, or if a lot of new code appears without new tests it was either a major refactor or someone isn't writing the tests they need. Someone who is doing it properly will show a pattern of at least three test runs (one fail, two passes) for each new test. Finally, should you survive lynching by the developers, the customer will be really pleased to see complicated graphs showing how much testing you are doing. Of course, this is completely unrelated to the sort of logging the logging module could do for you. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From newsgroups at jhrothjr.com Sat Aug 16 11:11:07 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Sat, 16 Aug 2003 11:11:07 -0400 Subject: IEEE special values References: Message-ID: "Norbert Nemec" wrote in message news:bhl7bi$ggg$1 at rznews2.rrze.uni-erlangen.de... > Hi there, > > is there any simple reason why IEEE special values are so poorly supported > in python? Are there any serious efforts to change that? NaN and Inf are an > extremely useful concept for numerical calculations and they would mix > perfectly with the concepts in NumPy, anyhow, the support seems to be > absolutely minimal. > > (The ideas in PEP 754 do not really change much: There is little use in easy > access to those values, if the math functions don't accept them as input > but break down.) Like a lot of things, Python's math functions are a rather thin layer on top of the native C library's math functions. If the C library's math functions, to use the vernacular, suck, then Python's math functions will do likewise. One of the essential problems is that every library does certain things differently, like deciding whether it's going to start up with silent or signaling NaN's, or what the actual string values are for NaN, infinity and so forth. It takes developer time to clean up that situation. I suspect that volunteers would be very welcome. John Roth > > Ciao, > Nobbi From richie at entrian.com Mon Aug 4 11:38:28 2003 From: richie at entrian.com (Richie Hindle) Date: Mon, 04 Aug 2003 16:38:28 +0100 Subject: Match beginning of two strings In-Reply-To: References: Message-ID: <5gtsiv4a22a0baijvi77p02gb81fudltca@4ax.com> [Alex] > I'm not sure where I went wrong in > the Pyrex coding (it doesn't seem to be performing anywhere > as well as I thought it might) and I'll be happy for real > Pyrex expert to show me the way. I'm no an expert, but I can see a few easily-fixed problems. The line: if a[i] != b[i]: is working with Python strings when it could be working with C strings. Here's the original code and its output on my machine: def exa(a, b): cdef int la cdef int lb la = len(a) lb = len(b) cdef int lmin lmin = min(la, lb) cdef int i i = 0 while i < lmin: if a[i] != b[i]: return a[:i] i = i + 1 if lmin == la: return a else: return b 100000 loops, best of 3: 9.11 usec per loop Here's a modified version of the code comparing C strings: def exa(a, b): cdef char* c_a # `a` as a C string cdef char* c_b # `b` as a C string cdef int la cdef int lb c_a = a c_b = b la = len(a) lb = len(b) cdef int lmin lmin = min(la, lb) cdef int i i = 0 while i < lmin: if c_a[i] != c_b[i]: return a[:i] i = i + 1 if lmin == la: return a else: return b 100000 loops, best of 3: 5.79 usec per loop Almost twice as fast. Looking at the generated C is always worthwhile when optimising Pyrex code - here's the code that does the comparison against Python strings: /* "D:\src\tests\pyrex\exa.pyx":11 */ __pyx_3 = PyInt_FromLong(__pyx_v_i); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; goto __pyx_L1;} __pyx_1 = PyObject_GetItem(__pyx_v_a, __pyx_3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; goto __pyx_L1;} Py_DECREF(__pyx_3); __pyx_3 = 0; __pyx_5 = PyInt_FromLong(__pyx_v_i); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; goto __pyx_L1;} __pyx_2 = PyObject_GetItem(__pyx_v_b, __pyx_5); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; goto __pyx_L1;} Py_DECREF(__pyx_5); __pyx_5 = 0; if (PyObject_Cmp(__pyx_1, __pyx_2, &__pyx_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; goto __pyx_L1;} __pyx_4 = __pyx_4 != 0; Py_DECREF(__pyx_1); __pyx_1 = 0; Py_DECREF(__pyx_2); __pyx_2 = 0; if (__pyx_4) { vs. /* "D:\src\tests\pyrex\exa.pyx":16 */ __pyx_5 = ((__pyx_v_c_a[__pyx_v_i]) != (__pyx_v_c_b[__pyx_v_i])); if (__pyx_5) { for C strings. There's another similar optimisation that the C output leads you to: you can use strlen rather than Python's len: cdef extern from "string.h": int strlen(char*) def exa(a, b): cdef char* c_a # `a` as a C string cdef char* c_b # `b` as a C string cdef int la cdef int lb c_a = a c_b = b la = strlen(c_a) lb = strlen(c_b) cdef int lmin lmin = min(la, lb) cdef int i i = 0 while i < lmin: if c_a[i] != c_b[i]: return a[:i] i = i + 1 if lmin == la: return a else: return b 100000 loops, best of 3: 3.58 usec per loop That replaces: /* "D:\src\tests\pyrex\exa.pyx":4 */ __pyx_1 = __Pyx_GetName(__pyx_b, "len"); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4; goto __pyx_L1;} __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4; goto __pyx_L1;} Py_INCREF(__pyx_v_a); PyTuple_SET_ITEM(__pyx_2, 0, __pyx_v_a); __pyx_3 = PyObject_CallObject(__pyx_1, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4; goto __pyx_L1;} Py_DECREF(__pyx_1); __pyx_1 = 0; Py_DECREF(__pyx_2); __pyx_2 = 0; __pyx_4 = PyInt_AsLong(__pyx_3); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4; goto __pyx_L1;} Py_DECREF(__pyx_3); __pyx_3 = 0; __pyx_v_la = __pyx_4; /* "D:\src\tests\pyrex\exa.pyx":5 */ __pyx_1 = __Pyx_GetName(__pyx_b, "len"); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; goto __pyx_L1;} __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; goto __pyx_L1;} Py_INCREF(__pyx_v_b); PyTuple_SET_ITEM(__pyx_2, 0, __pyx_v_b); __pyx_3 = PyObject_CallObject(__pyx_1, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; goto __pyx_L1;} Py_DECREF(__pyx_1); __pyx_1 = 0; Py_DECREF(__pyx_2); __pyx_2 = 0; __pyx_4 = PyInt_AsLong(__pyx_3); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; goto __pyx_L1;} Py_DECREF(__pyx_3); __pyx_3 = 0; __pyx_v_lb = __pyx_4; with : /* "D:\src\tests\pyrex\exa.pyx":12 */ __pyx_v_la = strlen(__pyx_v_c_a); /* "D:\src\tests\pyrex\exa.pyx":13 */ __pyx_v_lb = strlen(__pyx_v_c_b); and leaves the call to 'min' as the only remaining huge block of C. The final version looks like this, eliminating 'min' (Greg, can we have the terary operator in Pyrex please? ) cdef extern from "string.h": int strlen(char*) def exa(a, b): cdef char* c_a # `a` as a C string cdef char* c_b # `b` as a C string cdef int la cdef int lb c_a = a c_b = b la = strlen(c_a) lb = strlen(c_b) cdef int lmin if la < lb: lmin = la else: lmin = lb cdef int i i = 0 while i < lmin: if c_a[i] != c_b[i]: return a[:i] i = i + 1 if lmin == la: return a else: return b 1000000 loops, best of 3: 0.803 usec per loop Over ten times quicker than the original, for the sake of a couple of small tweaks driven by looking at the C output. Although the C still looks very verbose at first glance, it's now substantially the same as Alex's cexa.c. Hope that helps, -- Richie Hindle richie at entrian.com From sjmachin at lexicon.net Sat Aug 2 20:28:53 2003 From: sjmachin at lexicon.net (John Machin) Date: Sun, 03 Aug 2003 00:28:53 GMT Subject: Dict to "flat" list of (key,value) References: Message-ID: <3f2c54f6.11554794@news.lexicon.net> On Sat, 02 Aug 2003 12:41:19 GMT, "Raymond Hettinger" wrote: >it-all-starts-with-a-good-data-structure-ly yours, Amen, brother. Even worse: I recall seeing code somewhere that had a data structure like this: {k1: [v1,v2], k2: v3, k3: None, ...} instead of {k1: [v1,v2], k2: [v3], k3: [], ...} I liked the elegant code example for building a book index. However in practice the user requirement would be not to have duplicated page numbers when a word occurs more than once on the same page. If you can achieve that elegantly, please post it! Cheers, John From jzgoda at gazeta.usun.pl Tue Aug 12 17:38:03 2003 From: jzgoda at gazeta.usun.pl (Jarek Zgoda) Date: Tue, 12 Aug 2003 21:38:03 +0000 (UTC) Subject: Python IDE - "Lite" version available for non commercial use References: <3F395CC7.EFBE63C6@pobox.com> Message-ID: Rick Thomas pisze: > http://wingide.com/wingide Is it a "trial license"? -- Jarek Zgoda Registered Linux User #-1 http://www.zgoda.biz/ JID:zgoda at chrome.pl http://zgoda.jogger.pl/ From Scott.Daniels at Acm.Org Sun Aug 3 00:18:32 2003 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sat, 02 Aug 2003 21:18:32 -0700 Subject: Match beginning of two strings In-Reply-To: References: Message-ID: <3f2c429e@nntp0.pdx.net> Ravi wrote: > Hi, > > I have about 200GB of data that I need to go through and extract the > common first part of a line. Something like this. > > >>>a = "abcdefghijklmnopqrstuvwxyz" > >>>b = "abcdefghijklmnopBHLHT" > >>>c = extract(a,b) > >>>print c > "abcdefghijklmnop" > > Here I want to extract the common string "abcdefghijklmnop". Basically I > need a fast way to do that for any two given strings. For my situation, > the common string will always be at the beginning of both strings. I can > use regular expressions to do this, but from what I understand there is > a lot of overhead. New data is being generated at the rate of about 1GB > per hour, so this needs to be reasonably fast while leaving CPU time for > other processes. > > Thanks > Ravi > While you can be forgiven for not have guessed, os.path is the place to look: import os.path a = "abcdefghijklmnopqrstuvwxyz" b = "abcdefghijklmnopBHLHT" print os.path.commonprefix([a,b]) -Scott David Daniels Scott.Daniels at Acm.Org From jjl at pobox.com Wed Aug 20 14:45:22 2003 From: jjl at pobox.com (John J. Lee) Date: 20 Aug 2003 19:45:22 +0100 Subject: What's better about Ruby than Python? References: <38ec68a6.0308172319.431a4fde@posting.google.com> <9755kv4bku839cpsqrvch13504qagg7gev@4ax.com> Message-ID: <87oeykb22l.fsf@pobox.com> Tim Rowe writes: > On 18 Aug 2003 16:38:42 -0400, aahz at pythoncraft.com (Aahz) wrote: > > >Oh, come on, Brandon is *much* less of a troll than T*m*t*y R*e. > > Dangerously close to my name -- I hope it's not a typo and meant to > /be/ my name! Rest assured, *definitely* no relation. :-) John From vanevery at 3DProgrammer.com Mon Aug 18 18:13:02 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Mon, 18 Aug 2003 15:13:02 -0700 Subject: What's better about Ruby than Python? References: <87ekzj6pbz.fsf@pobox.com> <87zni6ddki.fsf@pobox.com> Message-ID: John J. Lee wrote: > "Michael Peuser" writes: >> >> If all those would be in a state as VB with its Active-X support and >> quitre acceptable application framework or - eben better - as >> compiled RealBasic on Macintosh with its universal Quicktime >> interface, then I should say you could discuss fines language >> matters. (One should mention Delphi as well.) > > This comes over as a troll, so I shan't bother to answer. You know, people would get along a lot better if they didn't have the intellectually lazy habit of "troll hunting." When people express their opinions about pros and cons, they are not trolling. You have to allow for other people's opinions. Use your imagination: if you were in their shoes, why mightn't you see things that way, or ask a question that way? -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From abelikov72 at hotmail.com Fri Aug 22 22:38:21 2003 From: abelikov72 at hotmail.com (Afanasiy) Date: Sat, 23 Aug 2003 02:38:21 GMT Subject: Sort a Dictionary References: Message-ID: On Sat, 23 Aug 2003 02:34:23 GMT, "Andrew Dalke" wrote: >Afanasiy: >> This is fairly simple in PHP, how do I do it in Python? >> >> http://www.php.net/manual/en/function.ksort.php > >def ksort(d, func = None): > keys = d.keys() > keys.sort(func) > return keys > >for k in ksort(d): > print k, v > >As a bonus, you don't need to tell the sort to sort numerically >vs. lexigraphically --- Python's strong typing knows that by >default. You can pass in an alternate compare function if you >want. Why wouldn't this be a standard function? From aleax at aleax.it Wed Aug 20 13:00:13 2003 From: aleax at aleax.it (Alex Martelli) Date: Wed, 20 Aug 2003 17:00:13 GMT Subject: Python should try to displace Java References: <3f3e89f3$0$225$626a54ce@news.free.fr> Message-ID: Doug Tolton wrote: ... > designed to be a scalable scripting language. Python wasn't designed > to be a replacement for C++ to my knowledge. Are you saying that > python was designed to be a replacement for C / C++ for building large > scale systems? If so I'm suffering under a mis-apprehension of what > Python is all about. Even though Python was NOT specifically designed for "building large scale [software] systems" when it was born over 12 years ago, it does "happen" to be excellent for the job. Not just my opinion -- e.g., Mitch Kapor and his OSAF chose Python as the application-programming language for the Chandler system, and if you look at the specs for that ambitious undertaking you'll see it WILL be quite a large-scale system when it matures. Of course, part of what helps is that Python is substantially higher-level than the other languages you're considering (most particularly C): given a system's total functionality, measured say in "Function Points", you can rely on the system SIZE (in terms, say, of lines of code) being VERY substantially smaller when you program it in Python. C and C++, rather than being "replaced", are "re=positioned" at doing what they're best at -- making libraries of stuff that must run fast and in very memory-lean ways. Python is ideal to build applications, and systems, out of those "raw materials" (as well, very often, at prototyping the libraries themselves). > I'm using System in the generic sense rather than the specific sense > of Operating System. Yep, same here. Although in the expression "system programming" it IS more often than not an _Operating_ system that is meant. > It isn't a matter of whether it can be done in Python. You can write > anything in assembly for that matter, the reason you don't is > typically productivity. That doesn't mean you shouldn't write > anything in Assembly does it? Of course! Kapor and friends didn't choose Python because "it could be done that way"; their purpose is making Chandler a great product, and their motivation for choosing Python is that they believe it will let them pursue that purpose with maximum productivity. I happen to agree with them (and, just like them, I come from long experience with other languages such as C, C++, and Java). > I don't know how stating the obvious 'that some languages are better > at some tasks than other languages' would be considered a troll. With such genericity, it could hardly offend anybody (and it would be just as unlikely for the super-generic assertion to prove USEFUL to anybody, of course:-). But as soon as you get down to specifics, it gets more interesting (in all senses of the word "interesting":-). Why Java's inability to treat classes, functions etc as first-class objects, or the copious and tedious boilerplate it requires, should make it better than Python at putting together very large applications and systems of applications, for example, is anything but obvious (to me, at least). Say, for example, that one believes Java's strength is not the language itself, but the huge collection of libraries and frameworks; then, since once can access those same libraries and frameworks with the Jython implementation of Python, one might still perfectly sensibly believe that the best way to put together large applications and systems out of those wonderful libraries & frameworks is still Python (just like it is when the libraries &c are in C/C++). Until and unless somebody tries to build the SAME large application several times with different languages (unlikely!), it will be hard to get reliable data. I do remember from the recent past, just as I was stepping out of the CAD / PDM world, that one of our competitors' marketing was making hay from the fact that they had entirely rewritten their major system, from Java to C++, with untold benefits in speed, memory consumption, and the like. Of course, _our OWN_ marketing quietly replied that OUR systems had always been in C++ and the fact that we'd never pursued the (by our competitors' own admission) blind alley of Java had just given us that many more cycles to spend in solving our customers' problems, etc etc. BTW: even though I left that CAD / PDM firm mostly because I was unable to evangelize Python effectively there, I do find it amusing that there's now LOTS of Python code in their systems -- apparently, my evangelism HAD been effective at grass-roots levels, just not with top management; and the techies had stealthily deployed growing amounts of Python, e.g. in alleged "prototypes"... that had then been shipped:-). Not complaining -- it does mean I get occasionally called in as a Python consultant, which is a welcome opportunity to greet old friends as well as a source of income;-). But note that the firm does NOT advertise the role of Python in their systems: "all rock-solid C++" is the message marketing wants to keep sending (basically in a fight with those competitors who switched to Java, whether they later switched back to C++ or not) -- inserting the unknown-to-customers "Python" term in the equation would dilute the message. Pity, but I'm convinced there's a LOT of that going on in the software world...!-) Alex From wiebke.paetzold at mplusr.de Tue Aug 12 09:56:57 2003 From: wiebke.paetzold at mplusr.de (Wiebke Pätzold) Date: Tue, 12 Aug 2003 15:56:57 +0200 Subject: union in Python References: Message-ID: This is the error-traceback that is print whenmy program failed: >>> Themenbereiche Nachname Traceback (most recent call last): File "C:\PROGRA~1\Python22\lib\site-packages\Pythonwin\pywin\framework\scriptutils.py", line 310, in RunScript exec codeObject in __main__.__dict__ File "C:\Programme\Python22\Lib\site-packages\Pythonwin\pywin\Demos\Uebung11.py", line 46, in ? print feld_th, feld_na, union1(feld_th, feld_na) NameError: name 'union1' is not defined >>> From bokr at oz.net Sat Aug 9 11:33:39 2003 From: bokr at oz.net (Bengt Richter) Date: 9 Aug 2003 15:33:39 GMT Subject: raw string tail escape revisited Message-ID: Why wouldn't quote-stuffing solve the problem, and let you treat \ as an ordinary character? In a raw string, it's no good for preventing end-of-quoting anyway, unless you want the literal \ in front of the quote you are escaping. Quote-stuffing is a variation on the old quote-doubling, extended to deal with triple quotes as well (which makes it a little like HDLC bit stuffing). IOW, treat \ as an ordinary character, and then if you don't want the string to end, just stuff one quote character of the starting kind after the otherwise terminating sequence. You could do this with single quoting or triple quoting, where of course you'd need it less for triple quotes. E.g., using uppercase R as a prefix for this kind of raw string syntax, R'\' # just fine R'C:\' # one of the motivations R'''' # dumb way to do "'" R""" ->[""""]<-makes 3 quotes, and we end with \""" R""" ->[""""""""]<-two stuffing-extended triple quotes make 6 quotes.""" The tokenizer would recognize a stuffed quote mark and just discard it if present, otherwise recognize end of string. Just had this idea. Do I need more coffee? What did I forget? Regards, Bengt Richter From bokr at oz.net Sat Aug 2 00:31:15 2003 From: bokr at oz.net (Bengt Richter) Date: 2 Aug 2003 04:31:15 GMT Subject: Python speed vs csharp References: Message-ID: On 1 Aug 2003 19:08:54 -0700, sjmachin at lexicon.net (John Machin) wrote: >bokr at oz.net (Bengt Richter) wrote in message news:... >> erfcx = ( (a1 + (a2 + (a3 + >> (a4 + a5*t)*t)*t)*t)*t ) * exp(-pow(x,2.0)); > >Wouldn't (x*x) be better than pow(x,2.0) ? Yup, I would think so too, but I wasn't thinking about optimizing the C ;-) I just copied the C# from Mike's post and made it legal C ;-) Regards, Bengt Richter From richardshea at fastmail.fm Thu Aug 21 06:38:37 2003 From: richardshea at fastmail.fm (Richard Shea) Date: 21 Aug 2003 03:38:37 -0700 Subject: MySqlDB Question - CompatMySqlDB is all I can find ? Message-ID: <282f826a.0308210238.11ef6a97@posting.google.com> Hi - I've just downloaded mysqldb for 3.2. After running the install I find that I can't import mysqldb. When I looked in the directory mysqldb was installed into the only modules visible are _mysql_exceptions.py and CompatMySqlDB.py. So i tried importing CompatMySqlDB and that works fine ... >>> import CompatMysqldb >>> import Mysqldb Traceback (most recent call last): File "", line 1, in ? ImportError: No module named Mysqldb >>> ...trouble is I read in this group that I'm not meant to be using CompatMysqldb so what am I doing/have done wrong ? I got mysqldb as a binary from ... http://ghaering.de/python/unsupported/MySQL-python.exe-0.9.2.win32-py2.3.exe ... if anyone can throw some light on this I'd be grateful. regards richard shea. From rxs141 at cwru.edu Sat Aug 2 23:14:10 2003 From: rxs141 at cwru.edu (Ravi) Date: Sat, 02 Aug 2003 23:14:10 -0400 Subject: Match beginning of two strings In-Reply-To: References: Message-ID: > Are you trying to match any to any strings? or only a pair as above? > Just a pair at a time, and I only want the first N characters that are common to both strings. The os.path.commonprefix works nicely. Thanks for your help. Ravi From bdesth.nospam at removeme.free.fr Thu Aug 28 04:32:18 2003 From: bdesth.nospam at removeme.free.fr (Bruno Desthuilliers) Date: Thu, 28 Aug 2003 10:32:18 +0200 Subject: Script Discussion & Critique In-Reply-To: References: <3F4D31B1.6080802@hotmail.com> <06eqkv4onjh5m4tcbbqkmh8lscaj5niatp@4ax.com> <3F4D4402.3060209@hotmail.com> <3f4d9f2c$0$16163$626a54ce@news.free.fr> Message-ID: <3f4dbbba$0$16176$626a54ce@news.free.fr> Peter Otten wrote: > Bruno Desthuilliers wrote: > > >>Err... Is this my version of Python having troubles, or could it be >>possible that nobody actually took time to *test* that script ? > > > Python 2.3 (#1, Jul 30 2003, 11:19:43) > [GCC 3.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>>>import os >>>>dir(os.walk) > > ['__call__', '__class__', '__delattr__', '__dict__', '__doc__', '__get__', > '__getattribute__', '__hash__', '__init__', '__module__', '__name__', > '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', > '__str__', 'func_closure', 'func_code', 'func_defaults', 'func_dict', > 'func_doc', 'func_globals', 'func_name'] > > > It's time to upgrade :-) > Seems like !-) I could not believe no one has spotted such a bug. Thanks everyone Bruno From doug.hendricks at tnzi.com Thu Aug 7 18:12:39 2003 From: doug.hendricks at tnzi.com (the_rev_dharma_roadkill) Date: 7 Aug 2003 15:12:39 -0700 Subject: Skipping on memory in Python classes References: Message-ID: "Raymond Hettinger" wrote in message news:... [snip] > > > > Any other proven techniques out there? Is there much point in > > creating a new metaclass for my class? How about replacing > > emptyStrings with Nones? Is there a fast (runtime) way of translating > > between '' and None? > > If the list of 200 elements doesn't change, it may be better to use a > tuple instead of a list. That sounds good, but it doesn't seem to make much difference. > > If the list contents are all of the same type, the array module provides > a space efficient storage solution. Most of the elements are either empty strings or strings of len() from 1 to about 50. As I read/experiment, array.array is good for elements of len() == 1. Very efficient, yes, but not flexible enough. Maybe my own module, written in C, is the answer. Or not. My tests seem to indicate that most of the problem is the per-object memory, not the list-size-related memory. If I cut the size of the list from 200 elements down to 35 elements, my memory use is only cut in half. That's nothing to sneeze at, but it's obvious that other terms are important. Maybe not storing 100,000 instances as objects is the answer. It should be possible to represent each object as a single (large) tuple or list or list of lists. Code readability will suffer. I'll experiment at a later date. > > Empty strings are like None in that they all refer to a single object, > so there are no savings there. That is good to know. Thanks. > > > Raymond Hettinger Doug From bromden at gazeta.pl.no.spam Wed Aug 13 06:50:45 2003 From: bromden at gazeta.pl.no.spam (bromden) Date: Wed, 13 Aug 2003 12:50:45 +0200 Subject: Determine file type (binary or text) In-Reply-To: References: Message-ID: > How can I check if a file is binary or text? >>> import os >>> f = os.popen('file -bi test.py', 'r') >>> f.read().startswith('text') 1 (btw, f.read() returns 'text/x-java; charset=us-ascii\n') -- bromden[at]gazeta.pl From abuseonly at sgrail.org Fri Aug 22 04:23:56 2003 From: abuseonly at sgrail.org (derek / nul) Date: Fri, 22 Aug 2003 08:23:56 GMT Subject: Newbie problem with codecs References: <1R01b.1724$Ej6.454@newsread4.news.pas.earthlink.net> Message-ID: On Fri, 22 Aug 2003 08:14:32 GMT, "Andrew Dalke" wrote: >derek / nul: >> File "C:\Program Files\Python\lib\encodings\cp850.py", line 18, in >encode >> return codecs.charmap_encode(input,errors,encoding_map) >> UnicodeEncodeError: 'charmap' codec can't encode character '\ufeff' in >position >> 0: character maps to > >I don't know enough to handle this problem. Anyone else care to try? Andrew, I am not concerned about that problem. I need a pointer to converting utf-16-le to text Derek From robin at jessikat.fsnet.co.uk Sun Aug 10 04:06:20 2003 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Sun, 10 Aug 2003 09:06:20 +0100 Subject: PMW 0.8.5 vs Python 2.3 Message-ID: I'm getting the following error when I attempt to run an app with Python 2.3. I suppose this was silently ignored under 2.2. With debugging I see that s==0 in _int = int ..... def atoi(s , base=10): return _int(s, base) is the cause of the error. Has int changed or is it the source of the value ie menu.entrycget(item, 'underline') File "C:\Python\lib\site-packages\Pmw\Pmw_0_8_5\lib\PmwMainMenuBar.py", line 140, in addmenuitem self._addHotkeyToOptions(menuName, kw, traverseSpec) File "C:\Python\lib\site-packages\Pmw\Pmw_0_8_5\lib\PmwMainMenuBar.py" , line 177, in _addHotkeyToOptions underline = string.atoi(menu.entrycget(item, 'underline')) File "C:\Python\Lib\string.py", line 220, in atoi return _int(s, base) TypeError: int() can't convert non-string with explicit base -- Robin Becker From imbosol at aerojockey.com Sun Aug 17 23:20:27 2003 From: imbosol at aerojockey.com (Carl Banks) Date: Mon, 18 Aug 2003 03:20:27 GMT Subject: Py2.3: Feedback on Sets References: Message-ID: <%BX%a.4999$N37.3051@nwrdny02.gnilink.net> Beni Cherniavsky wrote: > In comp.lang.python, you wrote: >>I've gotten lots of feedback on the itertools module >>but have not heard a peep about the new sets module. >> >>* Are you overjoyed/outraged by the choice of | and & >> as set operators (instead of + and *)? >> > ``&`` and ``|`` are good. In math too, the union/intersection operators are > very similar to the or/and opearators. The later are overloaded as > addition/mulitplication in boolead algebra only because the or/and operators > are so similar and inconvenient. This overloading is quite misguided because > these operators don't define a field or even a ring (xor/and would do that). Well, if overloading + and * to represent a non-field or non-ring is misguided, then + and * for lists and strings is also misguided, since they don't define a field or ring either. Having said that, it does feel wrong to use "+" for sets to me. For container types, I want len(s)+len(t) == len(s+t), but this would not hold for sets. That is why I slightly favor & and |. -- CARL BANKS http://www.aerojockey.com/software "You don't run Microsoft Windows. Microsoft Windows runs you." From cepl at surfbest.net Wed Aug 6 19:12:37 2003 From: cepl at surfbest.net (Matej Cepl) Date: Thu, 7 Aug 2003 01:12:37 +0200 Subject: Python's biggest compromises References: Message-ID: On 2003-08-06, 19:27 GMT, Gerrit Holl wrote: > Pythons have existed for a looooooooong time, so has Jawa. But only But Jawa is neither programming language nor coffee, but trademark of motorcycles from my native Czech Republic :-). Matej -- Matej Cepl, GPG Finger: 89EF 4BC6 288A BF43 1BAB 25C3 E09F EF25 D964 84AC 138 Highland Ave. #10, Somerville, Ma 02143, (617) 623-1488 From elainejackson7355 at home.com Fri Aug 22 21:51:04 2003 From: elainejackson7355 at home.com (Elaine Jackson) Date: Sat, 23 Aug 2003 01:51:04 GMT Subject: Keystroke logger for Windows References: Message-ID: I found this on the web someplace. It may be relevant. # /usr/local/bin/Python # Displays the keysym for each KeyPress event as you type import Tkinter root = Tkinter.Tk() root.title("Keysym Logger") def reportEvent(event): print 'keysym=%s, keysym_num=%s' % (event.keysym, event.keysym_num) text = Tkinter.Text(root, width=20, height=5, highlightthickness=2) text.bind('', reportEvent) text.pack(expand=1, fill="both") text.focus_set() root.mainloop() "hokieghal99" wrote in message news:bi66lq$skj$1 at solaris.cc.vt.edu... | Does anyone know of a keystroke logger that has been written in Python | for Windows machines? I'd like to see such a script and use it as a | point of reference for a real-time backup project that I'm working on. | Basically, I'd like to be able to capture all keystrokes from the | keyboard buffer and write them to a text file so I could reporduce | emails, documents, etc. in the event of file loss that occurs between | nightly backups. For example, my boss comes to me, he has deleted an | email that he was writing... he has been working on the email all day... | and he expects me to wave a magic wand and bring it back. | | Thanks for any advice, code or pointers. Also, if Python isn't suited | for this, let me know and I'll look at doing this in c | From davesum99 at yahoo.com Wed Aug 20 22:16:01 2003 From: davesum99 at yahoo.com (smarter_than_you) Date: 20 Aug 2003 19:16:01 -0700 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: <3F41A877.995F9C35@alcyone.com> Message-ID: The real question here is, why haven't we all but Brandon in OUR killfiles? Nick Vargish wrote in message news:... > Ben Finney writes: > > > I don't know of any newsreaders that can allow you to filter on the > > person(s) to whom the current post is responding > > Gnus certainly can. > > Nick From usenet_spam at janc.invalid Fri Aug 22 21:31:41 2003 From: usenet_spam at janc.invalid (JanC) Date: Sat, 23 Aug 2003 01:31:41 GMT Subject: GUI IDE for Macintosh? References: Message-ID: "Leo" schreef: > i'm looking for a GUI Building IDE for Python Development running on a > mac under OS X. > > i know about eric (http://www.die-offenbachs.de/detlev/eric3.html) and > boa (http://boa-constructor.sourceforge.net/). in > > their install readme's si only linux and windows listed. does anybody > has experience with a GUI Building Tool on OS X? I saw there is an experimental wxPython binary build for Python 2.3 for MacOS X. Boa Constrictor itself is pure Python. So _maybe_ it just works...? -- JanC "Be strict when sending and tolerant when receiving." RFC 1958 - Architectural Principles of the Internet - section 3.9 From SBrunning at trisystems.co.uk Thu Aug 21 11:29:59 2003 From: SBrunning at trisystems.co.uk (Simon Brunning) Date: Thu, 21 Aug 2003 16:29:59 +0100 Subject: What's TOTALLY COMPELLING about Ruby over Python? Message-ID: <31575A892FF6D1118F5800600846864D01200BBB@intrepid> > From: Peter Hansen [SMTP:peter at engcorp.com] > > Jeffrey P Shell wrote: > > [an excellent, lengthy article contrasting Python and Ruby] > > Article saved permanently. This is the only good thing to > come out of this thread so far. Thanks Jeffrey! Not quite true. Nearly, but not quite. Jeremy Dillworth's post is also worth a read - . Cheers, Simon Brunning --LongSig ----------------------------------------------------------------------- The information in this email is confidential and may be legally privileged. It is intended solely for the addressee. Access to this email by anyone else is unauthorised. If you are not the intended recipient, any disclosure, copying, distribution, or any action taken or omitted to be taken in reliance on it, is prohibited and may be unlawful. TriSystems Ltd. cannot accept liability for statements made which are clearly the senders own. From tim at remove_if_not_spam.digitig.co.uk Tue Aug 19 18:00:13 2003 From: tim at remove_if_not_spam.digitig.co.uk (Tim Rowe) Date: Tue, 19 Aug 2003 23:00:13 +0100 Subject: Troll tests References: <38ec68a6.0308172319.431a4fde@posting.google.com> Message-ID: On Mon, 18 Aug 2003 21:48:13 -0400, Lulu of the Lotus-Eaters wrote: >That said, I feel a little bad for Tim Rowe. He's posted many >interesting and relevant articles. But for the last year or so, my >finger is always halfway to the delete button before I realize that a >post is by this nice guy with an unfortunately similar name :-). Phew! Thanks for that. And it's a relief, because I was unaware of my (near) namesake and I was worried I had done something horrid! Would it help if I configured my newsreader to put my middle initial ("G") in? From enoch at gmx.net Thu Aug 7 10:01:37 2003 From: enoch at gmx.net (enoch) Date: 7 Aug 2003 07:01:37 -0700 Subject: Threading advantages (was Re: Python's biggest compromises) References: <899f842.0307310555.56134f71@posting.google.com> Message-ID: aahz at pythoncraft.com (Aahz) wrote in message news:... > > Since, as you say, you've done some research, that's why I flamed you. > There's just no call for making such an overstated claim -- it is *NOT* > "a little bit exaggerated". Well, I based this phrase on the fact that while under some circumstances (e.g. your web spider) python does scale somewhat, under others (e.g. zope) it may perform even worse on a SMP system. If you sum these two facts up ... > > >Here are some sources which show that I'm not alone with my assessment > >that python has deficiencies w.r.t. SMP systems: > > That I won't argue. But Python's approach also has some benefits even > on SMP systems. And if you choose a multi-process approach, the same > advantages that accrue to Python's approach on a single-CPU box apply > just as much to an SMP system. Yes, and these advantages also include a simpler threading model, as far as I understand it, on every system. It's a compromise, that's why I posted in this thread. > > >http://www.python.org/pycon/papers/deferex/ > >""" > >It is optimal, however, to avoid requiring threads for any part of a > >framework. Threading has a significant cost, especially in Python. The > >global interpreter lock destroys any performance benefit that > >threading may yield on SMP systems, [...] > >""" > > Just because it's a published PyCon paper doesn't mean that it's correct. > The multi-threaded spider that I use as my example is a toy version of a > spider that was used on an SMP box. (That's why I became a threading > expert in the first place -- Tim Peters probably remembers me pestering > him with questions four years ago. ;-) I guarantee you that SMP made > that spider much faster. But how big is the significance of software which has the same characteristics as your web spider example versus application servers? > >So, although python is capable of taking advantage of SMP systems > >under certain circumstances (I/O bound systems etc. etc.), there are > >real world situations where python's performance is _hurt_ by running > >on a SMP system. > > Absolutely. But that's true of any system with threading that isn't > designed and tuned for the needs of a specific application. Python > trades performance in some situations for a clean and simple model of > threading. Again, the compromise we were talking about. I'm not in a position to weigh the pros and cons of it against each other, but I think I can point out some cons of the current approach. I'm not doing that to spread FUD, but to give an outsiders perspective on what I think might hurt python in the future, and I want python to thrive because I like using it alot. > >Btw. I think even IPC might not help you there, because the different > >processes might bounce betweeen CPUs, so only processor binding might > >help. > > My understanding that most OSes are designed to avoid this; I'd be > interested in seeing some information if I'm wrong. In any event, I do > know that IPC speeds things up in real-world applications on SMP boxes. For example, there are always lots of discussions about CPU affinity on linux-kernel, and it seems to be a hard problem. Hyperthreading and other non-symmetric architectures make this problem even harder. Add to that the problem of the GIL getting shuffled around and you have a system where you'll have trouble to predict the performance characteristics. Admins don't like that. Though, it's not like there are no problems without the GIL, it just adds to the complication. > >I did quite a bit of googling on this problem - several times - > >because I'm selling zope solutions. Sometimes, the client wants to run > >the solution on an existing SMP system, and worse, the system has to > >fulfill some performance requirements. Then I have the problem of > >explaining to him that his admins need to undertake some special tasks > >in order for zope to be able to exploit the multiple procs in his > >system. > > Even if Zope is the 800-pound gorilla of the Python world, Python isn't > going to change just for Zope. If you want to talk about ways of > improving Zope's performance on SMP boxes, I'll be glad to contribute > what I can. But spreading false information isn't the way to get me > interested. I wasn't even aware that zope is the "800-pound gorilla" of the python world. I used it just as an example for a typical larger server app, because, well, I know it. incidentally, the pycon paper above, which you seem to dismiss as false, is also from a guy which is working on a larger server app. Maybe there's a pattern? > Keep in mind that one reason IPC has gained popularity is because it > scales more than threading does, in the end. Blade servers are cheaper > than big SMP boxes, and IPC works across multiple computers. Allow me some comment of the nature of this discussion (python and SMP in general, not just this thread). I've seen it before and the ingredients are: - a major open source project - developers which love this project - some "outsider" which points out some perceived deficiency of said project - said developers pointing out (rightly or wrongly) reasons why this deficiency doesn't matter, or that there are other (better) ways for the "outsider" to achieve what he wants In most cases this discussion then develops in to a big fat flamewar ;). Two examples are linux and its threading capabilities, and mysql and ACID compliancy. A nice quote from the linux discussion btw. was from Alan Cox: "A Computer is a state machine. Threads are for people who can't program state machines." But today, linux' thread support is magnitudes better than it was. You wrote in another message in this thread: > Well, that's a good question. *Does* Java have better threading > performance than Python? If it does, to what extent is that performance > bought at the cost of complexity for the programmer? While I can't comment on the second question, here's an article which sheds some light on the SMP scalability of an older java JDK, the meat is on the third page: http://www.javaworld.com/javaworld/jw-08-2000/jw-0811-threadscale.html Seems that java does indeed have better threading performance than python. From borcis at users.ch Thu Aug 21 04:18:47 2003 From: borcis at users.ch (Borcis) Date: Thu, 21 Aug 2003 10:18:47 +0200 Subject: What's better about Ruby than Python? References: Message-ID: <3F448067.1000101@users.ch> Joshua Marshall wrote: > Alex Martelli wrote: > ... > > >>But with try/finally, or hopefully some syntax tweak making >>try/finally semantics even easier to use, this is a kind of idiom >>that's gonna stay. > > > What sort of syntax tweak? Some sort of macro, I guess . BTW, what about using macros not to create new variants but to express idiomatic transforms between similar languages, ie bilingual macros that would allow to manipulate what's really eg javascript or ruby code with eg python-mode.el (or conversely) ? From mwh at python.net Fri Aug 29 08:10:03 2003 From: mwh at python.net (Michael Hudson) Date: Fri, 29 Aug 2003 12:10:03 GMT Subject: Hunting a memory leak References: Message-ID: <7h3oey84qho.fsf@pc150.maths.bris.ac.uk> Debian User writes: > I'm trying to discover a memory leak on a program of mine. I've taken > several approaches, but the leak still resists to appear. > > First of all, I've tried to use the garbage collector to look for > uncollectable objects. [snip] > Then I've taken an approach that I've seen in python developers list > contributed by Walter D?rwald, that basically consists in creating a > debug version of python, create a unitest with the leaking code, and > modify the unittest.py to extract the increment of total reference > counting in that code (see > http://aspn.activestate.com/ASPN/Mail/Message/python-dev/1770868). Well, somewhere in that same thread are various references to a TrackRefs class. Have you tried using that? It should tell you what type of object is leaking, which is a good start. > With that, I see that my reference count grows by one each time the > test execute. But the problem is: is there some way to look at the > object (or make a memory dump) that is leaking?. See above :-) > I've used valgrind (http://developer.kde.org/~sewardj/) to see if it > could detect the leak. In fact, it detects a bunch of them, but I am > afraid that they are not related with the leak I'm looking for. I am > saying that because, when I loop over my leaky code, valgrind always > report the same amount of leaky memory, independently of the number of > iterations (while top is telling me that memory use is growing!). There are various things (interned strings, f'ex) that always tend to be alive at the end of a Python program: these are only leaks in a very warped sense. I don't know if there's a way to get vaglrind to tell you what's allocated but not deallocated between two arbitrary points of program execution. > My code uses extension modules in C, so I am afraid this does not > contribute to alleviate the problem. Well, in all likelyhood, the bug is IN the C extension module. Have you tried stepping through the code in a debugger? Sometime's that's a good way of spotting a logic error. > I am sorry, but I cannot be more explicit about the code because it > is quite complex (it is the PyTables package, http://pytables.sf.net), > and I was unable to make a simple example to be published > here. However, if anyone is tempted to have a look at the code, you > can download it from > (http://sourceforge.net/project/showfiles.php?group_id=63486). I am > attaching a unittest that exposes the leak. > > I am a bit desperate. Any hint? Not really. Try using TrackRefs. Cheers, mwh -- I'm about to search Google for contract assassins to go to Iomega and HP's programming groups and kill everyone there with some kind of electrically charged rusty barbed thing. -- http://bofhcam.org/journal/journal.html, 2002-01-08 From gh at ghaering.de Tue Aug 5 17:53:40 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Tue, 05 Aug 2003 23:53:40 +0200 Subject: MSVC 6.0 Unsupported? In-Reply-To: References: Message-ID: <3F302764.8010301@ghaering.de> Syver Enstad wrote: > I've downloaded both source distro, and binary installer. Installed > python with the binary installer, when I attempted to compile > mxDateTime (mxBase) for 2.3 with MSVC 6.0 I got an error that seemed > related to forward declarations. > > It seems that the #defines that makes staticforward into extern when > using the MSVC 6 compiler has been removed from object.h. So I guess > this means I should use VC++ 7.0 to compile python with? Huh? You couldn't be more wrong. 1) Python 2.3 binaries *are* built with MSVC6 2) staticforward was defined from exten to empty on win32 for Python 2.3 3) The quick hack I used is to insert something like: #ifdef _MSC_VER #define staticforward extern #endif in the relevant source files *after* they include Python.h. Anyway you can't compile the eGenix extensions with Python 2.3. I hoped this gets fixed soon. The compile fails somewhere in the mxTextTools stuff. All I needed was mxDateTime and I got that to compile. If you need Windoze binaries, I've uploaded some for the pyPgSQL project at http://sourceforge.net/project/showfiles.php?group_id=16528 pypgsql-experimental Python 2.3b2 2003-07-17 11:22 egenix-mx-base-2.0.4.win32-py2.3.exe 471273 6 i386 .exe (32-bit Windows) HTH, -- Gerhard From timr at probo.com Sat Aug 30 01:11:04 2003 From: timr at probo.com (Tim Roberts) Date: Fri, 29 Aug 2003 22:11:04 -0700 Subject: Binary data handling ? References: Message-ID: "Bill Loren" wrote: > >I'm having difficulties to accomplish some simple chores with binary data. >I'm having a string (?) which I received via an HTTP transactions which is a >binary file. >Problem is the webserver I'm communicating with injected a \x0D before every >\x0A, >and I need to remove those 0x0D characters from my buffer before saving it >to disk. > >any ideas ? I'll bet you real money that the problem is not in the web server. I'd wager that the string is correct when you receive it, but that you are writing it to file like this: file('out.txt','w').write(download) On a Windows system, that'll turn all the LFs into CR-LFs. Use this instead: file('out.txt','wb').write(download) -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From sean at hugin.valhalla.net Mon Aug 4 05:41:11 2003 From: sean at hugin.valhalla.net (sean at hugin.valhalla.net) Date: 04 Aug 2003 21:41:11 +1200 Subject: command -- It works , on linux References: Message-ID: <878yq9hia0.fsf@hugin.valhalla.net> Readline for Python on Windows, get it here.... http://ipython.scipy.org/dist/PyReadlineWin32-4.0p22.tar.gz You will need the mingw compiler to build it I seem to remember. It works like a charm. Sean -- +---------------------------------------------------------------+ | All spelling errors are intentional and are there to show new | | and improved ways of spelling old words. | +---------------------------------------------------------------+ From FBatista at uniFON.com.ar Thu Aug 21 16:21:40 2003 From: FBatista at uniFON.com.ar (Batista, Facundo) Date: Thu, 21 Aug 2003 17:21:40 -0300 Subject: tuple to string/list Message-ID: #- > Any easy way of obtaing this output? #- #- f.write( "Hits for %s: %d" % (month[i], teller[i]) ) You need the end of line: f.write( "Hits for %s: %d \n" % (month[i], teller[i]) ) Otherwise it'll be very ugly, :) . Facundo From tim at remove_if_not_spam.digitig.co.uk Tue Aug 19 17:31:42 2003 From: tim at remove_if_not_spam.digitig.co.uk (Tim Rowe) Date: Tue, 19 Aug 2003 22:31:42 +0100 Subject: What's better about Ruby than Python? References: <87u18ewtrb.fsf@pobox.com> Message-ID: <0g55kvodnb2hu1r9p751pn1pk503h7ph34@4ax.com> On 18 Aug 2003 22:17:12 +0100, jjl at pobox.com (John J. Lee) wrote: >O'Caml, not to mention a bunch of others -- if only Python didn't do >almost everything so well, there'd be more motivation... Yep, that's the one. I was up and running producing useful code in Python within hours, and though I'd go to other languages for particularly specialised tasks Python does pretty much everything I want, does it well and does it easily. On the other hand, I've tried a few times to learn Ruby and never got to the point at which I could produce anything useful. I think it's because I've never used Perl and have not used Un*x much. Ruby, it seems to me, very much shows those roots and so seems to me to have less of a general appeal. From sean at activeprime.com Mon Aug 4 10:27:41 2003 From: sean at activeprime.com (Sean) Date: 4 Aug 2003 07:27:41 -0700 Subject: Passing Global Variables between imported modules Message-ID: Is there any way to access global variables defined from within an imported module? For example, lets say have a file called test2.py that defines a simple class: class MyClass: def __init__(self): pass def printGlobal(self): print globalVar Now I have another file that imports test2, sets a global variable called globalVar, and calles printGlobal() like so: from test2 import MyClass globalVar = "foo" mc = MyClass() mc.printGlobal() When I run it, I get a NameError that "global name 'globalVar' is not defined". I've tried explicitly calling 'global globalVar' and even stepping through the __builtins__ but to no avail. Is accessing globalVar from within test2.py possible? -Sean Levatino From tzot at sil-tec.gr Thu Aug 21 13:41:16 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Thu, 21 Aug 2003 20:41:16 +0300 Subject: configure: WARNING: term.h: present but cannot be compiled References: <127cc4c7.0308210858.72dc0b04@posting.google.com> Message-ID: On 21 Aug 2003 09:58:27 -0700, rumours say that nws088 at bco.com (Joshua S.) might have written: >I am trying to install python-2.3 on my AIX 5.1.0.0 box. Everytime I >try to run the configure script I ge the following error. >./configure --without-cxx --with-gcc --disable-ipv6 >... >checking term.h usability... no >checking term.h presence... yes >configure: WARNING: term.h: present but cannot be compiled >configure: WARNING: term.h: check for missing prerequisite headers? >configure: WARNING: term.h: proceeding with the preprocessor's result >checking for term.h... yes SGI IRIX has similar problems (and can't compile termios extension)... I believe termios stuff is not that standardised. -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From vze4rx4y at verizon.net Tue Aug 12 02:02:17 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Tue, 12 Aug 2003 06:02:17 GMT Subject: Py2.3: Feedback on Sets Message-ID: I've gotten lots of feedback on the itertools module but have not heard a peep about the new sets module. * Are you overjoyed/outraged by the choice of | and & as set operators (instead of + and *)? * Is the support for sets of sets necessary for your work and, if so, then is the implementation sufficiently powerful? * Is there a compelling need for additional set methods like Set.powerset() and Set.isdisjoint(s) or are the current offerings sufficient? * Does the performance meet your expectations? * Do you care that sets can only contain hashable elements? * How about the design constraint that the argument to most set methods must be another Set (as opposed to any iterable)? * Are the docs clear? Can you suggest improvements? * Are sets helpful in your daily work or does the need arise only rarely? User feedback is essential to determining the future direction of sets (whether it will be implemented in C, change API, and/or be given supporting language syntax). Raymond Hettinger From troy at gci.net Mon Aug 4 17:49:26 2003 From: troy at gci.net (Troy Melhase) Date: Mon, 04 Aug 2003 13:49:26 -0800 Subject: Plotting Package for Python 2.3 References: <221d8dbe.0308032301.2c0e801f@posting.google.com> <3F559DF5.6060209@kfunigraz.ac.at> Message-ID: Gerhard H?ring wrote: > It's just the typical Windows luser's way of saying (s)he hasn't found a > binary package and (s)he doesn't have any free or commercial compiler > for Windows installed :-/ Shame on you. Windows users need many things, but not among them is your contempt, nor your generalization. troy From m.liddle at cosc.canterbury.ac.nz Tue Aug 19 17:11:08 2003 From: m.liddle at cosc.canterbury.ac.nz (Marcus Liddle) Date: Wed, 20 Aug 2003 09:11:08 +1200 Subject: threads and timeout -> running a shell command / want to guard against infinite loops In-Reply-To: References: Message-ID: <3F42926C.5090702@cosc.canterbury.ac.nz> Tim Ottinger wrote: > On Tue, 19 Aug 2003 14:21:14 +1200, Marcus Liddle wrote: > > >> >> >>Hi >> >>I'm trying to get a really simple python program to >> run a bash testing script and kill itself if its >> been running to long (ie infinite loop) >> >>create the thread object - test = TestThread() >>run the command - test.do_command("infloop.bash") >>if t.isAlive(): ...stop it >> >>any good ideas? > > > Have you considered pexpect? > thank you for your advice. I downloaded it (http://pexpect.sourceforge.net/ http://flow.dl.sourceforge.net/sourceforge/pexpect/) and had play... I think I require specific thread killing--the shell command I 'spawn' continues to run ... I also had a look @ delegate.py from http://lfw.org/python/ after a very quick look last night, I think a similar problem ...my focus today will be on popen or another better way to control the execution. cheers Marcus -- Senior Assistant [mailto:m.liddle at cosc.canterbury.ac.nz] Dept. of Computer Science University of Canterbury Phone: +64 3 366-7001 ext: 7871 Office: 323 [ http://www.cosc.canterbury.ac.nz/~marcus/index.html ] From NineOfSix at gmx.de Fri Aug 15 12:03:19 2003 From: NineOfSix at gmx.de (Axel Grune) Date: Fri, 15 Aug 2003 18:03:19 +0200 Subject: Test web server In-Reply-To: <3F3CFF9F.31E68A67@hotmail.com> References: <3F3CFF9F.31E68A67@hotmail.com> Message-ID: Alan Kennedy wrote: > What version of Mozilla are you using? Mozilla 1.4 (Mozilla/5.0 (Windows; U; Windows NT 5.0; de-AT; rv:1.4) Gecko/20030612) From bokr at oz.net Wed Aug 6 10:18:32 2003 From: bokr at oz.net (Bengt Richter) Date: 6 Aug 2003 14:18:32 GMT Subject: Copying objects style questions References: Message-ID: On Wed, 06 Aug 2003 10:23:16 GMT, Alex Martelli wrote: >Bob Halley wrote: > ... >> I can't use copy.copy()'s default behavior, because it is too shallow. >> I don't want to use copy.deepcopy() because it's too deep. I > >So far, so perfectly clear. > >> contemplated __copy__, __initargs__, __getstate__, and __setstate__, >> but they didn't seem to fit the bill, or seemed more complicated than >> the solution I ended up with (see below). > >I don't understand this. What's wrong with, e.g.: > >def __copy__(self): > class EmptyClass: pass > obj = EmptyClass() > obj.__class__ = self.__class__ > obj.__dict__.update(self.__dict__) > obj.items = list(self.items) > return obj > >??? It seems simpler and more automatic than your 'copy protocol'; >subclasses don't need to do anything special unless they need to >"deepen" the copy of some of their attributes. Btw, if you're >using new-style classes, you'll want to use object instead of >EmptyClass, or start with obj = self.__class__.new(self.__class__) I don't think you meant object() as a direct substitute for EmptyClass() above, right? And you meant to put tails on that "new," presumably. >as you're doing in your protocol, of course -- but the key idea >is "bulk copy all that's in self's __dict__, then special-case >only what little needs to be specialcased". And doing it in a >method called __copy__ means any user of your class needs not >learn about a new copy protocol but rather just uses copy.copy. > >It may be that I'm not correctly understanding your issues, of >course, but I hope these suggestions can help. > > >Alex > Regards, Bengt Richter From paul at boddie.net Wed Aug 13 06:24:52 2003 From: paul at boddie.net (Paul Boddie) Date: 13 Aug 2003 03:24:52 -0700 Subject: Why Python needs to market itself References: <23891c90.0308120740.3a771ff6@posting.google.com> Message-ID: <23891c90.0308130224.4cb2878a@posting.google.com> "Brandon J. Van Every" wrote in message news:... > [The shift of the balance of power from vendor to customer leads to a shift in technologies employed.] > Not in the absence of marketing. Keep in mind, Linux is marketed. Well, on the client side people may ask for Windows solutions or Linux solutions, but I doubt that so many customers specifically stipulate Windows, UNIX or Linux for reasons other than convenience of maintenance and consistency with the rest of their environment. And way before Linux was marketed, it was getting through the door because motivated individuals realised that it could do the job more conveniently, for less money, and with less hassle. > > P.S. If you're really interested, there's a marketing/promotion > > interest group for Python. The details are out there on the Web, so if > > it's important to you, I'm sure you can dig them out. > > Actually, I would be interested in their opinions of the Python community, > if they're willing to give them. And maybe they'd be interested in an > outsider's perception of the Python community. It is, after all, people > like me that have to be sold in order to grow the market. The way I've seen people convinced is this: you demonstrate some small solution which does the job; then you tell them that it's written in Python. If that isn't suddenly a part of a mission-critical system, they frequently mention how they'd always considered looking at Python but hadn't done so yet: "Perhaps I should start to learn Python," they usually say. Most of the time, you demonstrate things that are very simple in Python but would be a pain with C, C++ or Java, and you let people realise that they can either spend days hacking on such problems in the languages they know, or they can learn to work more effectively. Personally, I made that transition about seven years ago, and it is a surprise that many people still haven't realised that such a transition can be made relatively easily. Of course, you can get hostility, but that's usually down to the fact that people feel threatened by things they don't know and fear they won't understand. For them, they feel that it's better to stick to what they know and be more productive than their peers in that environment than to make the transition, be more productive than they were before, but not be seen as an expert by their peers any more. On the other side of the coin are the people who occasionally post to comp.lang.python who ask, "Why should I learn Python?" This isn't restricted to programming languages, either, but it's sound advice to tell such people that if they know what the benefits of Python are and how they apply to their situation, then they don't need to be asking those kinds of questions - they already know the answer and just get on with it. Otherwise, it isn't interesting to entertain their questions because their motivation can usually be summarised as, "Am I too sexy for Python?" Anyway, raising the awareness of Python probably is a good thing. Big bucks marketing and developer coercion will, on the other hand, just alienate the talented and motivated developers. As I said before, Python's strengths lie in the demonstrated productivity benefits it offers, and this kind of message will increasingly drown out superficial product endorsement as the nature of the industry changes. Paul From newsgroups at jhrothjr.com Sat Aug 16 14:06:25 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Sat, 16 Aug 2003 14:06:25 -0400 Subject: How to terminate a TkinterApp correctly? References: <3F3DFCF4.5020109@aon.at> <3f3e37c6$0$19888$91cee783@newsreader01.highway.telekom.at> Message-ID: "Michael Peuser" wrote in message news:bhlmgq$dqk$02$1 at news.t-online.com... > > ----- Original Message ----- > From: "Gregor Lingl" > Newsgroups: comp.lang.python > Sent: Saturday, August 16, 2003 3:53 PM > Subject: Re: How to terminate a TkinterApp correctly? > > .... > > > Thanks for your remarks and your example. The > > following solution finally did it: > > > > def exit(): > > global done > > done = True # so the animation will terminate, but > > # not immediately! The actual pass through > > # the loop has to be finished. > > print "done!" > > import sys > > # after_idle seems to be crucial! Waits for terminating > > # the loop (which is in a callback function) > > cv.after_idle(sys.exit, (0,)) > > > Why don't you just return? The mainloop can handle everything!? Unfortunately, the combination of Windows 9x (including Me) and Python 2.1 can't handle everything. It may also be broken in 2.2 and later, but I quit trying after reaching my frustration limit. If you exit with an exception, something doesn't clean up properly, and you break the DOS box and eventually Windows itself when you try to shut down. This problem doesn't exist in the Windows 2K (including XP) code base, or other variants. I don't know that it's ever been solved, but considering that Windows 9x is gradually going away, it's also not a real hot priority. John Roth From wdunn82 at comcast.net Sat Aug 30 21:05:19 2003 From: wdunn82 at comcast.net (winston) Date: Sun, 31 Aug 2003 01:05:19 GMT Subject: printer friendly python tutorial Message-ID: does anyone know where i can find a printer friendly version of the python tutorial release 2.3? From tjreedy at udel.edu Mon Aug 11 12:19:52 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 11 Aug 2003 12:19:52 -0400 Subject: python spam filter: random words? References: Message-ID: <-CSdnbpTEIS0X6qiXTWJkQ@comcast.com> "Marc Wilson" wrote in message news:pa1fjvck8jidlj2ne5e63esmd2sk2ndl6v at 4ax.com... > In comp.lang.python, revyakin at yahoo.com (revyakin) (revyakin) wrote in > :: > > |I know fighting spam is like fighting global worming, but still.. > |50% of spam I get these days contains a random combination of letters > |at the end of the subject line. Has anyone tried using that feature in > |antispam filters? > > How do you detect "random" letters? You can only (programmatically) > determine that a character sequence is "random" if it doesn't appear in some > sort of dictionary, and even there you have the risk of false positives due > to typos, acronyms etc. Looking at successive letter pairs would go a long way. Out of the (26+space)**2 conbinations, perhaps half occur in real words (ie, 'qx' is a giveaway). Using triples would allow inclusion of common three-letter acronyms as legal. Terry J. Reedy From ghowland at lupineNO.SPAMgames.com Sat Aug 23 07:29:28 2003 From: ghowland at lupineNO.SPAMgames.com (Geoff Howland) Date: Sat, 23 Aug 2003 11:29:28 GMT Subject: Modifying the {} and [] tokens References: Message-ID: >>> So I can obviously override dict and it works when I specifically call >>> dict(), but it does not work with the syntax sugar {}. >> >>That's because you created a new dict. You didn't modify the >>actual type {} uses in the intepreter. {} is not simple syntactic sugar >>for dict() in the local namespace. BTW, if it were, then >> >> dict = 8 >> a = {3: 4} >> >>would fail. > >Right, so is there a way to change this? I know the syntax I tried >doesnt work and for obvious type reasons, since you wouldnt want to do >this by accident. > >Perhaps something has to be registered in some Python >variable/class/module-list I am not aware of that would make this >happen? I am ok with the consequences of potentially introducing >oddities into my code from the Norm for this flexibility. I've explored all of __builtins__ that I have been able to, and replacing dict there does nothing either, so I'm beginning to think that {}, [], etc are bound to types in the C code only and not available at all through Python to be re-typed. Is this correct? Is there no way to change type on these expression delimeters? I would think that somewhere this is a Python accessable definitely of what is that could be altered, so far I cant seem to find any reference to it through the Python Language Reference, Python in a Nutshell, or any google search. Python in a Nutshell specifies that dict(d={}) is essentially d = {}, but I can't find a description of how this token/expression to type binding happens. It seems like it would be really handy to add features to all containers equally though, especially since you should be able to get new functionality from any code written even if it didn't know about your new features because it could instantiate with the new type. BTW, some of the other comments in my team have been for a desire of more inclusive OO, such as [].len() instead of len([]), and this sort of thing. Having them builtin is obviously great and useful, but it feels wrong to some people and I'm trying to work on making things smoother instead of just forcing them to adapt (which they may not choose to do). -Geoff Howland http://ludumdare.com/ From gabor at z10n.net Fri Aug 22 10:42:28 2003 From: gabor at z10n.net (gabor) Date: Fri, 22 Aug 2003 16:42:28 +0200 Subject: large-scale app development in python? Message-ID: <20030822144228.GA8130@core.realtime.sk> hi, at the company where i'm working we have to rewrite a part of our java-based application in a different language. there were many options, at the end python and c++ remained. our program is quite big, so c++ was an obvious choice. python remained because we have to finish the rewrite in a reasonable time, and python has all the necessary libraries or bindings that we need. but i got a question, that i couldn't answer: -you can't compile python, as you can c++ or java => there's no type checking before starting the program => if one programmer changes a method name or method signature, then how do we know we changed all the code that calls that method? how do you solve these kind of problems? i know that unit tests are a good thing, but i don't know if they can help in this situation? are there any people who wrote a big program in python? how did they handle these problems? or python simply isn't suited to write bigger (more complex) apps? thanks, gabor -- That's life for you, said McDunn. Someone always waiting for someone who never comes home. Always someone loving something more than that thing loves them. And after awhile you want to destroy whatever that thing is, so it can't hurt you no more. -- R. Bradbury, "The Fog Horn" From simon_place at whsmithnet.co.uk Thu Aug 7 11:58:13 2003 From: simon_place at whsmithnet.co.uk (simon place) Date: Thu, 07 Aug 2003 16:58:13 +0100 Subject: serial, parallel and USB port In-Reply-To: <3f284386$0$1922$626a54ce@news.free.fr> References: <3f284386$0$1922$626a54ce@news.free.fr> Message-ID: <3f327718_2@mk-nntp-1.news.uk.worldonline.com> totally agree, python great for this sort of thing, i guess its cross platform hardware things that are the problem, but another way to solve this is to use sockets ( standardized ) to communicate with a comm server running on the same machine ( or elsewhere ), ( i've seen a couple already available for serial ports on a PC.) this way you have, clear hardware separation, you can easily simulate hardware, debug version easier and remote control. From pf_moore at yahoo.co.uk Tue Aug 5 16:00:20 2003 From: pf_moore at yahoo.co.uk (Paul Moore) Date: Tue, 05 Aug 2003 21:00:20 +0100 Subject: Unable to run IDLE from 2.3? References: <1akviv4cpectdogklmuupg7rc37lhe1pc7@4ax.com> Message-ID: M Wells writes: > I recently downloaded and installed Python 2.3 for Windows (on XP > professional) and I don't seem to be able to run IDLE from my start > menu? It seems something happens when I click on it (ie I get an > hourglass) but no actual application turns up. > > Has anyone else experienced this and can anyone give me some advice on > how to fix it? Do you have any form of "personal firewall" software? There is a known issue when Idle is used with a (misconfigured) firewall. The problem is that Idle relies on an internal socket connection. If the firewall is set to block that socket, Idle won't start. There should be no need to block traffic to IP address 127.0.0.1 (the local machine) so the firewall settings should be changed to allow this. For a better explanation, see http://www.python.org/2.3/bugs.html Hope this helps, Paul. -- This signature intentionally left blank From achrist at easystreet.com Sat Aug 16 13:06:56 2003 From: achrist at easystreet.com (achrist at easystreet.com) Date: Sat, 16 Aug 2003 10:06:56 -0700 Subject: GUI builder for Python References: <3F3DC73C.3ADD3980@easystreet.com> Message-ID: <3F3E64B0.2E691EF9@easystreet.com> Michael Peuser wrote: > > > Well try it out then - a little bit English is in it ;-) > http://visualwx.altervista.org/indexen.htm Sorry. I don't see any information on that page on how to use Visual Wx. It tells how to download and install, and I succeeded at that. The program runs, showing me a nice UI with thee panels. The left panel looks to be a list of wx classes that I can add to my project. The central panel can display source code. The right panel is a tree control showing an outline of the project. There is no explanation of how to use these panels to create any specific results. The word 'visual' in the name of the program vaguely suggests that I get to see what my UI looks like as I design it, but I haven't found any way to get visual wx to show me anything that looks like a display of the ui of the project being worked on. I'm pretty well lost at that point. There is a forum link from the web page, but last I looked, the postings are all in Italian. I'm certainly not criticizing someone who speaks and writes Italian for not writing English. I'm not saying that the program isn't very good. It looks like it might be very good even if I have drawn an unjustified inference about what 'visual' means. I'm just suggesting that if anyone who knows English uses Visual Wx to some advantage, and if they could post somewhere just a few paragraphs about how to use it, Visual Wx could have a place on the list of answers to the GUI-builder question. Al From ginarette at libero.it Fri Aug 29 16:54:00 2003 From: ginarette at libero.it (Gina) Date: Fri, 29 Aug 2003 22:54:00 +0200 Subject: My emails... Message-ID: > > > > ginarette at libero.it pierofoto at tiscali.it marianeri1 at tiscali.it lilianaverdis at tiscali.it ginarette at tiscali.it cinziaferretti1 at tiscali.it silviaferro1 at tiscali.it silviogresso at tiscali.it mariocecci at tiscali.it pinoriporto at tiscali.it pierofoto at tiscali.it marianeri1 at infinito.it lilianaverdis at infinito.it ginarette at infinito.it cinziaferretti1 at infinito.it silviaferro1 at infinito.it silviogresso at infinito.it mariocecci at infinito.it pinoriporto at infinito.it fotopiero at infinito.it marianeri1 at libero.it lilianaverdis at libero.it cinziaferretti1 at libero.it silviaferro1 at libero.it silviogresso at libero.it mariocecci at libero.it ginoalberi at libero.it pinoriporto at libero.it piero-foto at libero.it marianeri2 at virgilio.it lilianaverdis at virgilio.it ginarette at virgilio.it cinziaferretti2 at virgilio.it silviaferro2 at virgilio.it silviogresso at virgilio.it mariocecci at virgilio.it ginoalberi at virgilio.it pinoriporto at virgilio.it piero-foto at virgilio.it From borcis at users.ch Fri Aug 15 07:16:54 2003 From: borcis at users.ch (Borcis) Date: Fri, 15 Aug 2003 13:16:54 +0200 Subject: Converting foreign numeric conventions to US References: Message-ID: <3F3CC126.6070009@users.ch> def f(x) : return "$ %s" % x From duncan at NOSPAMrcp.co.uk Tue Aug 19 04:07:40 2003 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Tue, 19 Aug 2003 08:07:40 +0000 (UTC) Subject: generators improvement References: Message-ID: Oleg Leschov wrote in news:bhtiij$psc$2 at ocasysi.rubbernet.net: > What needs to be done is to allow yield return something - whatever was > passed to the .next() thing from caller.. > Easy and obvious, isn't it? So is there any principal problem with this > idea that would prevents its implementation? Please read PEP 288, http://www.python.org/peps/pep-0288.html in particular the section: > Rejected Alternative > One idea for passing data into a generator was to pass an argument > through next() and make a assignment using the yield keyword: > > datain = yield dataout > . . . > dataout = gen.next(datain) > > The intractable problem is that the argument to the first next() call > has to be thrown away, because it doesn't correspond to a yield > keyword. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From fcslka at yahoo.com Thu Aug 14 16:48:33 2003 From: fcslka at yahoo.com (Kent) Date: 14 Aug 2003 13:48:33 -0700 Subject: Python COM: Implementing someone else's interface Message-ID: <1bf4033f.0308141248.2cb4cd1e@posting.google.com> I'm trying to write a PalmDesktop Add-In in Python. I get an error when PalmDesktop tries to create an instance of my server class. The last few lines of the stack trace look like this: return pythoncom.WrapObject(self, reqIID) pywintypes.com_error: (-2147467262, 'No such interface supported', None, None) pythoncom error: CPyFactory::CreateInstance failed to create instance. (80004005) I assume it's because Palm is trying to create an instance of IDesktopAddin. How can let the Pythoncom framework know that I am an IDesktopAddin? Kent From mhammond at skippinet.com.au Wed Aug 13 19:03:45 2003 From: mhammond at skippinet.com.au (Mark Hammond) Date: Thu, 14 Aug 2003 09:03:45 +1000 Subject: help for using msvcrt.kbhit() with Python 2.3 editors? In-Reply-To: References: Message-ID: dbrown2 at yahoo.com wrote: > I'm having some trouble using kbhit inside the editor enviroments. I'm > using win2000 with Python2.3 and win32all v157 versions. > > Any pointer on how this should be handled would be appreciated. Is > there another non-blocking way to detect a key press? > > Here's the code that is causing the trouble. If I run this by > double-clicking then it works as expected. But if I run from IDLE or > PythonWin it basically never returns. msvcrt.kbhit() always returns 0 > as far as I can tell by adding print statements. I can't confirm it > but I seem to recall this worked at least with the PythonWin editor > environment under my previous Python 2.2 setup. > > ########### > import serial # access to serial port > import time # sleep command > import msvcrt # detect keyboard key press events > > ser = serial.Serial(0, 4800, timeout=0.25) > data = '' > while not msvcrt.kbhit(): > buf = ser.read(10) > if buf <> '': print buf > #time.sleep(1) > data = data + buf # concatenate buf onto data > ser.close() > ########### This will not work for Windows programs. Keystrokes are delivered to GUI programs via windows messages, not via stream type functions. Thus, having a GUI program with no existing message loop detecting key presses is quite difficult. Mark. From max at alcyone.com Wed Aug 27 18:53:10 2003 From: max at alcyone.com (Erik Max Francis) Date: Wed, 27 Aug 2003 15:53:10 -0700 Subject: asyncore: handle_accept() question? References: Message-ID: <3F4D3656.9119ECC1@alcyone.com> Chris wrote: > self.set_reuse_addr() # needed? This is definitely not needed in the connection; it's only useful in the server. (I doubt this is your problem.) > My basic problem is that I don't know any other way to 'hand off' the > incoming connection - if there is a better way to do this please let > me know. conn.fileno() appears to work, and I don't understand why > this error comes up. > > Any ideas? It looks like you're trying to do too much in your connection class constructor. In the way you're using it, after accept is called, the connection socket is already open and ready. You need not create or initialize it; the fact that you're doing so is invariably what's causing your error, although I'll admit I haven't tried to actually reproduce it. In fact, after accept, initializing a connection is simpler than simple. All you need to do is pass the socket into the asyncore.dispatcher/asynchat.async_chat constructor: class Connection(asyncore.dispatcher): def __init__(self, host, port, sock): asyncore.dispatcher.__init__(self, sock) # all done, your connection is ready to go As it stands, you're creating new sockets and attempting to connect to the connection address of the _accepted_ socket (where there isn't a server listening), so it looks like you're getting a partially initialized socket which would explain your problem. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ Life is a gamble so I should / Live life more carefully \__/ TLC From theller at python.net Thu Aug 7 12:17:02 2003 From: theller at python.net (Thomas Heller) Date: Thu, 07 Aug 2003 18:17:02 +0200 Subject: py2exe problems References: <8utYa.48785$cl3.1524137@news2.tin.it> Message-ID: "Alessandro Crugnola *sephiroth*" writes: >> The canonical test I use is to run the test_c14n.py test from the >> PyXML source distribution through py2exe. It works for me, on Windows XP >> Pro, SP 1, py2exe-0.4.1, Python 2.2.2, PyXML-0.8.3, with the command line >> 'python setup.py py2exe -p encodings' >> and this script: >> >> from distutils.core import setup >> import py2exe >> >> setup(name='test_c14n', scripts=['test_c14n.py'], version='0') > > Sorry, i get always the same error: > > File "", line 170, in ? > File "imputil.pyc", line 132, in _import_hook > File "", line 70, in _finish_import > File "imputil.pyc", line 316, in _load_tail > File "imputil.pyc", line 271, in _import_one > File "", line 128, in _process_result > File "xml\dom\ext\reader\__init__.pyc", line 20, in ? > LookupError: no codec search functions registered: can't find encoding > > > python 2.2.3 > pyxml 0.8.3 Then I have no idea. Installing 2.2.3 instead of 2.2.2 is something I cannot currently do (and I doubt it would help). Thomas From op73418 at mail.telepac.pt Thu Aug 7 13:38:07 2003 From: op73418 at mail.telepac.pt (Gonçalo Rodrigues) Date: Thu, 07 Aug 2003 18:38:07 +0100 Subject: Bug? If not, how to work around it? References: <060820031458029244%mday@apple.com> <09udnV37oMEUDqyiU-KYgw@comcast.com> Message-ID: On Thu, 7 Aug 2003 12:39:06 -0400, "Terry Reedy" wrote: > >"Gon?alo Rodrigues" wrote in message >news:md94jvccu02b9dv5890k34629rkot79roj at 4ax.com... >> On Thu, 07 Aug 2003 00:54:03 +0100, Gon?alo Rodrigues >> wrote: >> >> >On Wed, 6 Aug 2003 19:46:39 -0400, "Terry Reedy" >> >>If you don't want to do what works, >> >>why ask us to bother answering? > >> >Because it may not work. That is, the use case I have in mind >serves >> >as proxy for an object that may or may not have __iter__. IOW if I >> >stick __iter__ I have to code a second class, etc... etc... Oh >well... > >> Just to make things clearer, having iter(self.__obj) as in >> >> def __iter__(self): >> return iter(self.__obj) >> >> Would mean that my proxy class would become an iterable. And that is >> not what I want because *other* parts in my code check that an >object >> is in iterable by looking for __iter__. > >As I understand your clarification, you want the proxy to actually be >iterable (via delegation) when given as an arg to iter(), but to not >look iterable to other code (call it test_iterable()). And your >test_iterable() *currently* looks only for the presence/absence of the >very thing needed to make iter() work. > To look an iterable by delegation *if* the underlying object is, yes. >It is definitely not a Python bug that this does not work. > It finally dawned on me why this is so: it's the way new classes work. In a sloppy language: a __getattr__ hook is like an instance attribute, but the iter machinery goes after the class not the instance so it misses __getattr__. So my test_iterable (in your nomenclature) is wrongly coded because it gives false positives. [Ideas snipped] Thanks for the input. But since something has to change anyway, the best idea seems to be to stick __iter__ in the proxy class after all and change the other code that was counting on testing iterableness by looking __iter__. This will involve some changes, but it's the "least worse of all evils." With my best regards, G. Rodrigues From adalke at mindspring.com Thu Aug 21 14:45:37 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Thu, 21 Aug 2003 18:45:37 GMT Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> <6dj2kv8ugkieehs7guh786cl40o5lj6mcs@4ax.com> <599a6555.0308202108.397bb1a0@posting.google.com> <3F44D5F1.8050006@nyc.rr.com> Message-ID: Kenny Tilton: > Forget argument by analogy: How is a macro different than an API or > class, which hide details and do wonderful things but still have to be > mastered. Here's an analogy : I could learn Java syntax in a week, > but does that mean I can keep up with someone who has been using the > class libraries for years? Nope. > > And Java doesn't even have macros. So adding macros to Java would make it easier to master? Andrew dalke at dalkescientific.com From peter at engcorp.com Wed Aug 27 11:47:46 2003 From: peter at engcorp.com (Peter Hansen) Date: Wed, 27 Aug 2003 11:47:46 -0400 Subject: Celebrity advice (was: Advice to a Junior in High School?) References: Message-ID: <3F4CD2A2.DE7D05D2@engcorp.com> Terry Reedy wrote: > > (I think it safe to say that during the 20th century, 99% of the 100s of > millions of murders were committed by armed govern-men rather than by > private persons acting alone.) It may be safe to say it, but is it true, or merely hyperbole? Were there "100s of millions of murders" in the 20th century, assuming commonplace definitions of "murder" (killing humans), "million" (10 to the 6th power), and "20th century" (period beginning roughly January 1, 1900 and ending on or one year before December 31, 2000)? That's a lot of people getting themselves killed, whatever the cause... -Peter From stevewilliams at wwc.com Mon Aug 11 09:55:29 2003 From: stevewilliams at wwc.com (Steve Williams) Date: Mon, 11 Aug 2003 13:55:29 GMT Subject: Slogan: Getting Rich Overnight In-Reply-To: References: <3f373ac6@shknews01> Message-ID: Christian Tismer wrote: [snip] > They were said by another guy, who > said in German > "Python hat mich ?ber nacht reich gemacht". > > My problem is not that sentence. In German, > it still has a useful meaning. > My problem is the impossibility > to translate it into English without loosing meaning. How about "I hit the jackpot with Python" From theller at python.net Thu Aug 7 16:18:46 2003 From: theller at python.net (Thomas Heller) Date: Thu, 07 Aug 2003 22:18:46 +0200 Subject: py2exe problems References: <8utYa.48785$cl3.1524137@news2.tin.it> Message-ID: >>> File "", line 170, in ? >>> File "imputil.pyc", line 132, in _import_hook >>> File "", line 70, in _finish_import >>> File "imputil.pyc", line 316, in _load_tail >>> File "imputil.pyc", line 271, in _import_one >>> File "", line 128, in _process_result >>> File "xml\dom\ext\reader\__init__.pyc", line 20, in ? >>> LookupError: no codec search functions registered: can't find encoding >>> >>> >>> python 2.2.3 >>> pyxml 0.8.3 >> > Ok, I've installed 2.2.3 and verified the behaviour you observed. > And I have a workaround: > > run the setup script with these options, and the test_c14n.py script > works as executable: > > python py2exe --packages encodings --force-imports encodings > This trick even helps with Python 2.3. I've added a comment to the web page. Thomas From newsgroups at jhrothjr.com Tue Aug 26 21:26:10 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Tue, 26 Aug 2003 21:26:10 -0400 Subject: String find and replace References: <3F4C04F8.5070401@vt.edu> Message-ID: "hokiegal99" wrote in message news:3F4C04F8.5070401 at vt.edu... > Thanks for the explanation, I can make it work this way: > > import os, string > setpath = raw_input("Enter the path: ") > for root, dirs, files in os.walk(setpath): > fname = files > x = 'THIS' > y = 'THAT' > for fname in files: > myfile = file(os.path.join(root,fname), 'r') > mystr = myfile.read() > myfile.close() > search = string.find(mystr, x) > if search >=1: > string.replace(mystr, x, y) > print "Replacing", x, "with", y, "in", fname > > If only I could actually make the change to the files! It works in > theory, but not in practice ;) Anyone recommend how to actual write the > change to the file? I'm new to this, so be kind. Are you trying to rename the file? Look under os - Files and Directories for the rename() function. It's 6.1.4 in the 2.2.3 docs. John Roth > > Thanks Everyone!!! > > > > Geoff Gerrietts wrote: > > Quoting hokieghal99 (hokiegal99 at hotmail.com): > > > >>import os, string > >>print " " > >>setpath = raw_input("Enter the path: ") > >>def find_replace(setpath): > >> for root, dirs, files in os.walk(setpath): > >> fname = files > >> for fname in files: > >> find = string.find(file(os.path.join(root,fname), 'rb').read(), 'THIS') > > > > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > > this string is never bound to a name > > (ie, you never assign str=file(...).read()) > > > >> print find > >> if find >=1: > >> replace = string.replace(str, 'THIS', 'THAT') > > > > ^^^ > > this name is currently bound to > > the builtin function str() > > > > > >>find_replace(setpath) > >>print " " > > > > > > > > You might consider the fragment below, instead. It's a couple lines > > longer, but safer (your .close() happens exactly when you want it to) > > and probably more readable. > > > > for root, dirs, files in os.walk(setpath): > > fname = files > > for fname in files: > > myfile = file(os.path.join(root,fname), 'rb') > > mystr = myfile.read() > > myfile.close() > > find = string.find(mystr, 'THIS') > > print find > > if find >=1: > > replace = string.replace(mystr, 'THIS', 'THAT') > > > > > > Luck, > > --G. > > > > From everyman_forhimself at yahoo.com Sun Aug 17 23:39:44 2003 From: everyman_forhimself at yahoo.com (ForHimself Every Man) Date: 17 Aug 2003 20:39:44 -0700 Subject: What's better about Rattlesnakes than Pythons? Message-ID: <8e482ba2.0308171939.7de4a288@posting.google.com> What's better about Rattlesnakes than Python. I'm sure there's something. What is it? This is not a troll. I'm a snake shooping and I want people's answers. I don't know beans about Rattlesnakes or have an preconceived ideas about them. I noticed, however, that everyone I talk to who are aware of Pythons are also afraid of Rattlesnakes. So it seems that Rattlesnakes have the potential to compete with and displace Pythons. I'm curious how evolution will play this out. Cheers, -- www.microsoft.com ForHimself, Every Man Redmond, WA On the 15th level, there is a troll He drinks no wine and smokes no stogies But, oh he loves to eat them little rougies From oren-py-l at hishome.net Fri Aug 15 12:48:16 2003 From: oren-py-l at hishome.net (Oren Tirosh) Date: Fri, 15 Aug 2003 12:48:16 -0400 Subject: Module access from inside itself In-Reply-To: References: Message-ID: <20030815164816.GA18146@hishome.net> On Fri, Aug 15, 2003 at 04:20:43PM +0000, Steven wrote: > I'm writing a Python script which can be called from the command-line, and > I want to use my module doc string as the CL help text, but I don't know > how to access my module object from inside the module. You don't need the module object for this. MY_MODULE.__doc__ is the same as accessing __doc__ directly. If you really need the current module object use sys.modules[__name__] Oren From danielk at aracnet.com Wed Aug 6 08:32:03 2003 From: danielk at aracnet.com (Daniel Klein) Date: Wed, 06 Aug 2003 05:32:03 -0700 Subject: True References: Message-ID: On Wed, 06 Aug 2003 09:18:13 +1000, Mark Hammond wrote: >Daniel Klein wrote: >> Thanks Fran?ois. I don't need to support multiple versions. I simply >> changed the code from: >> >> true = (1 == 1) >> >> to >> >> true = 1 >> >> and presto, no more bug :-) > >For the sake of being pedantic, I believe your code still does have a >bug. You bug is that you rely on the "str()" of a boolean value >returning a specific string. Your code should probably check the bool >and create your own string rather than relying on this behaviour >remaining unchanged forever. I'm not really taking a str() on a boolean value anymore; it's being taken on an integer value. Are you saying that... true = 1 str(true) # this should always return '1' now and forever more ...could cause problems in the future? The reason I'm taking a str() value is cuz it is being sent over a socket to a non-python server process, where it is converted back to a boolean. Make sense now? Dan From danielk at aracnet.com Tue Aug 5 09:02:46 2003 From: danielk at aracnet.com (Daniel Klein) Date: Tue, 05 Aug 2003 06:02:46 -0700 Subject: True References: Message-ID: On 04 Aug 2003 06:17:37 -0400, pinard at iro.umontreal.ca (Fran?ois Pinard) wrote: >[Daniel Klein] > >> So my question is what is the proper method for setting booleans in 2.3? > >Hi, Daniel. > >In 2.3, you do not need to set booleans, `True' and `False' are just there. > >However, if you have a need to write portably against many versions, you >might try something like: > > try: > True > except NameError: > False, True = range(2) > >in modules where you need to use `True' or `False'. Thanks Fran?ois. I don't need to support multiple versions. I simply changed the code from: true = (1 == 1) to true = 1 and presto, no more bug :-) Dan From reply.in.the.newsgroup at my.address.is.invalid Thu Aug 28 17:10:52 2003 From: reply.in.the.newsgroup at my.address.is.invalid (Rene Pijlman) Date: Thu, 28 Aug 2003 23:10:52 +0200 Subject: Bayesian kids content filtering in Python? References: <20030828161409.V40715@onyx.ispol.com> Message-ID: <9qrskvkm85h2ch8jo0edrclu43t0kof84q@4ax.com> Gregory (Grisha) Trubetskoy: >I've been snooping around the web for open source kids filtering software. >Something that runs as an http proxy on my home firewall and blocks >certain pages based on content. > >It occured to me that this might be an interesting project to be done in >Python, probably using the same training and scoring mechanism that >spambayes uses. > >Anyway - I wonder if anyone has already tried something like this? Perhasp this thread is of interest to you: http://mail.python.org/pipermail/python-list/2003-February/143241.html And this message suggests it has already been done: http://mail.python.org/pipermail/spambayes-checkins/2003-February/000890.html -- Ren? Pijlman From s0199583 at sms.ed.ac.uk Tue Aug 12 08:54:57 2003 From: s0199583 at sms.ed.ac.uk (Matt Smith) Date: 12 Aug 2003 05:54:57 -0700 Subject: Importerror no module named WIN32API References: <5f5c82ec.0308110740.550d5f43@posting.google.com> <5f5c82ec.0308120038.20c6f70d@posting.google.com> Message-ID: <5f5c82ec.0308120454.6d5de3a1@posting.google.com> Thanks for the ehlp, it was the pythonpath or rather the lack of one that was causing me difficulties, thanks again, matt From jdhunter at ace.bsd.uchicago.edu Thu Aug 7 11:41:05 2003 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Thu, 07 Aug 2003 10:41:05 -0500 Subject: filter()ing a dict In-Reply-To: <16469f07.0308070559.aed41a@posting.google.com> (robin.cull@pace.co.uk's message of "7 Aug 2003 06:59:37 -0700") References: <16469f07.0308070559.aed41a@posting.google.com> Message-ID: >>>>> "Robin" == Robin Cull writes: Robin> My question is, does anybody else think that when calling Robin> filter(f, dict), it should return a dict of the keys and Robin> values of the former dict where the values satisfy the Robin> conditions defined by f()? The problem is not with filter. When you do d = {'k1':1, 'k2':2} for x in d: print x It prints the keys. That is: by default, iterating over a dictionary iterates over the keys. So when you filter a dict, it iterates over the dictionary which means iterating over the keys. SO filter and dict are behaving as advertised. As you noted, you can call dictionary functions to iterate over the keys, values, or key, value pairs. It is easy to do what you want with list comprehensions myDict = {"key 1": ["value 1", "value 2", "value 3", "value 4"], "key 2": ["value 1", "value 2"], "key 3": ["value2", "value 3", "value 4"], "key 4": ["value 1", "value 2", "value 3", "value 4"]} len4Dict = dict([ (k,v) for k,v in myDict.items() if len(v)==4]) print len4Dict Cheers, John Hunter From JohnSmith at obfs.com Sun Aug 17 13:16:45 2003 From: JohnSmith at obfs.com (John Smith) Date: Sun, 17 Aug 2003 13:16:45 -0400 Subject: Py2.3: Feedback on Sets References: Message-ID: Suggestion: How about adding Set.isProperSubset() and Set.isProperSuperset()? Thanks for this wonderful module. I've been working on data mining and machine learning area using Python. Set operations are very important to me. "Raymond Hettinger" wrote in message news:Jp%Za.256$jw4.238 at nwrdny03.gnilink.net... > I've gotten lots of feedback on the itertools module > but have not heard a peep about the new sets module. > > * Are you overjoyed/outraged by the choice of | and & > as set operators (instead of + and *)? > > * Is the support for sets of sets necessary for your work > and, if so, then is the implementation sufficiently > powerful? > > * Is there a compelling need for additional set methods like > Set.powerset() and Set.isdisjoint(s) or are the current > offerings sufficient? > > * Does the performance meet your expectations? > > * Do you care that sets can only contain hashable elements? > > * How about the design constraint that the argument to most > set methods must be another Set (as opposed to any iterable)? > > * Are the docs clear? Can you suggest improvements? > > * Are sets helpful in your daily work or does the need arise > only rarely? > > > User feedback is essential to determining the future direction > of sets (whether it will be implemented in C, change API, > and/or be given supporting language syntax). > > > Raymond Hettinger > > > > From jjl at pobox.com Mon Aug 4 14:01:34 2003 From: jjl at pobox.com (John J. Lee) Date: 04 Aug 2003 19:01:34 +0100 Subject: Developping an EAI server in Python : looking for developpers References: <3f2e9581$0$49107$e4fe514c@news.xs4all.nl> Message-ID: <87brv5s3nl.fsf@pobox.com> Irmen de Jong writes: > Alexander DEJANOVSKI wrote: > > > I'm starting a new project to develop an Open-Source EAI server in Python > > and I'm looking for motivated developpers and testers. > > It is inspired by Open Adaptor (_www.openadaptor.org_ > > ), but aims to be easier > > to use and more powerful. > > Could you please summarize what the goals of this project are? > And how it relates to Open Adaptor? (which I don't have the time > to read about). And how it relates to Twisted? John From pobrien at orbtech.com Fri Aug 29 13:50:55 2003 From: pobrien at orbtech.com (Patrick K. O'Brien) Date: 29 Aug 2003 12:50:55 -0500 Subject: Object Database (ODBMS) for Python References: <1DAECE9E8F34E04AA0E5699AF7D9FF090708D440@stpmsg00.corp.fairisaac.com> <3f4f7af6_3@corp.newsgroups.com> Message-ID: "Paul D. Fernhout" writes: > By the way, if you add support for the sorts of associative tuples > with the Pointrel System is based on, efficiently managed, maybe > I'll consider switching to using your system, if the API is simple > enough. :-) Or, perhaps there is a way the Pointrel System can be > extended to support what you might want to do (in the sense of > transparent interaction with Python). In its use of the pickler, the > Pointrel System does not keep a list of previously pickled object, > so it can't transparently pickle objects that refer to previously > pickled object in the repository, so that is one way that the > Pointrel system can't do what your system does at all. (I'm not sure > how to do that without like PyPerSyst keeping lots of previously > pickled objects in memory at once for the Pickler to work > with). Also, in the Pointrel System repositories are sort of on the > fly made up of an arbitrary collection of archives where archives > may be added and removed dynamically, so I don't quite begin to see > to handle object persistance across a repository if subobjects are > stored in different archives which are dropped out of the > repository. Oy! There we go with the API thing again. ;-) PyPerSyst can manage anything that can be pickled. So it should be able to support your associative tuples. But to get the most bang for your buck, you'd want to subclass the Entity class that I recently added to PyPerSyst. I can't think of a reason it wouldn't work, but we'd have to give it a try and see. The root of a PyPerSyst database can be any Python object graph, with any kind of object referencing that Python supports. But transactions must be deterministic and independent, so they cannot contain references. If you saw my examples of the generic transactions you'll see that I passed in references. How can that be? The secret is the dereferencing that takes place in those transaction classes: """Generic transactions.""" __author__ = "Patrick K. O'Brien " __cvsid__ = "$Id: transaction.py,v 1.8 2003/08/27 00:53:01 pobrien Exp $" __revision__ = "$Revision: 1.8 $"[11:-2] from pypersyst.entity.entity import Entity from pypersyst.transaction import Transaction class Create(Transaction): def __init__(self, classname, **attrs): Transaction.__init__(self) self.classname = classname self.attrs = attrs def __getstate__(self): self.refs = {} for name, value in self.attrs.items(): if isinstance(value, Entity): self.refs[name] = (value.__class__.__name__, value.oid) self.attrs[name] = None return self.__dict__.copy() def execute(self, root): self.EntityClass = root._classes[self.classname] for name, (classname, oid) in self.refs.items(): self.attrs[name] = root[classname][oid] return self.EntityClass(**self.attrs) class Delete(Transaction): def __init__(self, instance): Transaction.__init__(self) self.instance = instance def __getstate__(self): self.classname = self.instance.__class__.__name__ self.oid = self.instance.oid d = self.__dict__.copy() del d['instance'] return d def execute(self, root): return root[self.classname]._delete(self.oid) class Update(Transaction): def __init__(self, instance, **attrs): Transaction.__init__(self) self.instance = instance self.attrs = attrs def __getstate__(self): self.classname = self.instance.__class__.__name__ self.oid = self.instance.oid self.refs = {} for name, value in self.attrs.items(): if isinstance(value, Entity): self.refs[name] = (value.__class__.__name__, value.oid) self.attrs[name] = None d = self.__dict__.copy() del d['instance'] return d def execute(self, root): self.instance = root[self.classname][self.oid] for name, (classname, oid) in self.refs.items(): self.attrs[name] = root[classname][oid] return root[self.classname]._update(self.instance, **self.attrs) Try telling me that isn't one sweet API! ;-) -- Patrick K. O'Brien Orbtech http://www.orbtech.com/web/pobrien ----------------------------------------------- "Your source for Python programming expertise." ----------------------------------------------- From roy at panix.com Thu Aug 21 13:32:56 2003 From: roy at panix.com (Roy Smith) Date: 21 Aug 2003 13:32:56 -0400 Subject: [OT] Why is it called string? References: <3f44ce77$0$556$b45e6eb0@senator-bedfellow.mit.edu> <3f44d6d5$0$571$b45e6eb0@senator-bedfellow.mit.edu> Message-ID: Brian Kelley wrote: >> The usage of string as "a sequence of similar objects", appears >> to be very old. The old way to identify newborn babies in hospitals was to make up a name bracelet with letter beads on a string. This would then be attached to the baby's wrist or ankle. From amk at amk.ca Wed Aug 20 21:51:30 2003 From: amk at amk.ca (A.M. Kuchling) Date: Wed, 20 Aug 2003 20:51:30 -0500 Subject: Removing language comparisons Message-ID: python.org has a page of "Python vs. X" language comparisons at . They're all pretty outdated, and often unfair because they're written by a person who knows Python well but has only a nodding acquaintance with language X. I'm planning to drop this page from python.org because it's so outdated and no one is around to maintain it. If anyone wants to grab the contents and turn them into a Wiki page, or use bits of them for marketing material, please do it now. --amk From lars at gustaebel.de Tue Aug 5 06:58:39 2003 From: lars at gustaebel.de (Lars Gustaebel) Date: Tue, 05 Aug 2003 12:58:39 +0200 Subject: tarfile and end-of-tape References: Message-ID: On Mon, 04 Aug 2003 15:29:34 -0500, Josh Smith wrote: > In Python 2.3 there is a new library for handling tarfiles. However, > there doesn't seem to be any documentation on handling end-of-tape > conditions. I've googled for it and checked the docs, I've even looked > into the modules src and all I found was an end of file exception that > might do what I'm looking for, but might not. Tape device support is implemented only rudimentarily in tarfile because that is not its focus. End-of-tape conditions are not specially handled except that you get the typical system errors if you try to write on a full medium. Please note that tarfile.open() takes an optional fileobj argument which you could use to pass a custom file-like object that sits between tarfile and your tape device. > Anyone have any pointers/help? From fake at email.com Fri Aug 22 08:05:11 2003 From: fake at email.com (gappy) Date: Fri, 22 Aug 2003 13:05:11 +0100 Subject: swocket installation Message-ID: <3f4606f2$0$46011$65c69314@mercury.nildram.net> Has anyone succeeded in installing swocket and getting it working? After all my best efforts I get G:\>G:\Python23\Lib\swocketserver.py Traceback (most recent call last): File "G:\Python23\Lib\swocketserver.py", line 12, in ? servers.append( File "G:\downloads\swocket-0.1pre2\swocket\swocket\server.py", line 203, in __init__ self.validate() File "G:\downloads\swocket-0.1pre2\swocket\swocket\server.py", line 211, in validate if not type(self.logmodule.logClass).__name__ == 'class' : raise configError('%s.logClass must be a class' % self.moduleName) AttributeError: configHost instance has no attribute 'moduleName' Am I starting it right? (the right command) It's really hard because it didn't come with any instructions.. A search came up with nothing but duds. Any help really appreciated. From jjl at pobox.com Sat Aug 16 06:33:13 2003 From: jjl at pobox.com (John J. Lee) Date: 16 Aug 2003 11:33:13 +0100 Subject: ClientCookie bug (followup) References: <87fzk4sav2.fsf@pobox.com> <87znibzrnx.fsf@pobox.com> Message-ID: <87oeypdh92.fsf@pobox.com> cartermark46 at ukmail.com (Mark Carter) writes: [...] > John: Why without the delayload argument? > > My response: > > The following code: > > import ClientCookie > c = ClientCookie.MSIECookieJar(delayload=1) > c.load_cookie_data("hemscott-cookie.bin") > import urllib2 > url = 'http://businessplus.hemscott.net/corp/crp03733.htm' > request = urllib2.Request(url) > response = urllib2.urlopen(request) > request2 = urllib2.Request(url) > c.add_cookie_header(request2) > response2 = urllib2.urlopen(request2) > print response2.geturl() > print response2.info() # headers > for line in response2.readlines(): # body > print line Take note of this comment from the web page: | # Don't copy this blindly! You probably want to follow the examples | # above, not this one. No matter how many times and how many places I say this, everybody seems to be driven to make the same mistakes. I guess people don't believe it's as simple as calling urlopen, though I explictly say it *is* that simple in most cases in the second sentence of the documentation. DON'T USE *BOTH* add_cookie_header/extract_cookies *AND* urlopen. urlopen is all you need, unless you're not using urllib2. Probably won't do any actual harm, but it's completely pointless and obfuscatory. You're also failing to use ClientCookie.urlopen (which unlike urllib2.urlopen, knows about cookies), because you blindly copied the third example from the web page. You're also using Request objects for no apparent reason, and you're attempting to fetch the same url twice, again because you're blindly copying. Sigh -- if people have to blindly copy, why not copy from the code I actually *tell* people to copy from, instead of the code I explictly tell people *not* to copy from? Ngghhh! :-) You want something like this: import ClientCookie c = ClientCookie.MSIECookieJar(delayload=1) c.load_cookie_data("hemscott-cookie.bin") url = 'http://businessplus.hemscott.net/corp/crp03733.htm' response = ClientCookie.urlopen(url) print response.read() response.close() > produces the error: > > Traceback (most recent call last): [...] > whereas running it without delayload=1 causes it to run successfully. Anyway, you have found another bug, so all is forgiven. (the MSIE delayload feature is still a bit of a mess -- luckily, I can pin the blame on the original author of that code, since it's pretty directly ported from Perl ;) John From gh at ghaering.de Mon Aug 25 04:40:41 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Mon, 25 Aug 2003 10:40:41 +0200 Subject: ANN: BlackAdder V1.0.0 In-Reply-To: <1Kj2b.61523$bo1.38258@news-server.bigpond.net.au> References: <3f48a498$3$219$fa0fcedb@lovejoy.zen.co.uk> <1Kj2b.61523$bo1.38258@news-server.bigpond.net.au> Message-ID: <3F49CB89.1050304@ghaering.de> Neil Hodgson wrote: > Gerhard H?ring: > >>Furthermore, I'd excpect an email address with a connection to the >>company that offers the product, something like >>blackadder at thekompany.com, sales at thekompany.com or something like that. >>Not some random BadJake with a completely different email address ;-) > > I'm interested in what has happened here. [...] I've written to sales at thekompany.com and recommended they publicly clarify the issue. -- Gerhard From eric.brunel at pragmadev.com Wed Aug 6 08:08:22 2003 From: eric.brunel at pragmadev.com (Eric Brunel) Date: Wed, 06 Aug 2003 14:08:22 +0200 Subject: Isn't there a substring(start, end)-function???? References: Message-ID: Dave wrote: > Hi all, > > Am I blind, or what? I can't find any quick way to do the following in > Python: > > substring(beginIndex, endIndex) witch returns the substring between > beginIndex and endIndex. > > Like: > text = "If someone attacks you with a banana" > print text.substring(0,3) > Should print "If " > > I've found absolutely everything else that I expect from a modern > programming language, but none of the modules (not even "string"!) > seems to have what I'm looking for. > > Please tell me I'm blind! You are ;-) You couldn't find it in the documentation for the modules because it's a base operator on the string itself: text = "If someone attacks you with a banana" print text[0:3] See: http://www.python.org/doc/current/lib/typesseq.html HTH -- - Eric Brunel - PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com From grey at despair.dmiyu.org Fri Aug 29 10:39:07 2003 From: grey at despair.dmiyu.org (Steve Lamb) Date: Fri, 29 Aug 2003 14:39:07 -0000 Subject: Style question... References: <3F4DFAAC.1356C276@engcorp.com> Message-ID: On 2003-08-28, rzed wrote: > A better solution might be to physically restrain the posters of > tab-infested code from doing that, but there are only so many hours in > the day. And if OE wouldn't do what it does ... but then, where would > be the fund in that? Well, actually, a better solution would be to skip OE for something sensible, no? :) -- Steve C. Lamb | I'm your priest, I'm your shrink, I'm your PGP Key: 8B6E99C5 | main connection to the switchboard of souls. -------------------------------+--------------------------------------------- From parente at cs.unc.edu Mon Aug 25 07:26:28 2003 From: parente at cs.unc.edu (Peter Parente) Date: 25 Aug 2003 04:26:28 -0700 Subject: Keystroke logger for Windows References: <85b6a599.0308230628.49ba3c74@posting.google.com> Message-ID: <85b6a599.0308250326.15d20640@posting.google.com> Change of plans. The hooks library is at http://www.sourceforge.net/projects/uncassist. You can download and run the pyHook windows installer, or check it out of CVS. There's an example.py file in the CVS pyHook module that shows you how to use it (requires wxPython for the GUI). Pete parente at cs.unc.edu (Peter Parente) wrote in message news:<85b6a599.0308230628.49ba3c74 at posting.google.com>... > I have a Python library that can capture system wide keystrokes and > mouse events. Basically, the windows hooking code is in a C Python > extension that passes callback information back to Python when an > event occurs. I'll > post it to our Python tools sourceforge site in the near future. (I > need to clean it up a bit and provide an example before it will be the > least bit useful to you.) > > When it's posted, it will appear at > http://sourceforge.net/projects/uncpythontools/ as the pyHook project. > > Pete > > > hokieghal99 wrote in message news:... > > Does anyone know of a keystroke logger that has been written in Python > > for Windows machines? I'd like to see such a script and use it as a > > point of reference for a real-time backup project that I'm working on. > > Basically, I'd like to be able to capture all keystrokes from the > > keyboard buffer and write them to a text file so I could reporduce > > emails, documents, etc. in the event of file loss that occurs between > > nightly backups. For example, my boss comes to me, he has deleted an > > email that he was writing... he has been working on the email all day... > > and he expects me to wave a magic wand and bring it back. > > > > Thanks for any advice, code or pointers. Also, if Python isn't suited > > for this, let me know and I'll look at doing this in c From paul.m at speakeasy.net Tue Aug 19 20:45:04 2003 From: paul.m at speakeasy.net (Paul M) Date: Tue, 19 Aug 2003 20:45:04 -0400 Subject: Trolling levels In-Reply-To: References: Message-ID: Brandon J. Van Every wrote: > Ok, I've played the posting game until 2 am. It was a good run instead of > playing something mindless like Diablo II again. Thats said, I could have > finished "Childhood's End" instead. Tangible today was 1 more Python > type-treatment. To those of you who took my Ruby questions at face value, > and answered them perfunctorily, thanks! I got the information I wanted and > the conclusions haven't surprised me. To those who might still be game for > a little Troll Hunting, well, smooches, I missed you this time but my > killfile will still be there for you later. > > Unsubscribing for now, to concentrate on marketing-python. > Fredrik Lundh wrote: > > that's a very limited definition. I prefer this one: > > "An internet troll is someone who fishes for people's confidence and, > once found, exploits it" > > ( from http://www.teamtechnology.co.uk/troll.htm ) > > Interesting document that /F posted to. It's worth a quick read. Given Brandon's history in this newsgroup, his recent messages, and his response above, I'd have to say that he's operating at Troll level 3("Strategic") or 4("Domination"). --Paul From skip at pobox.com Wed Aug 13 23:44:25 2003 From: skip at pobox.com (Skip Montanaro) Date: Wed, 13 Aug 2003 22:44:25 -0500 Subject: Py2.3: Feedback on Sets In-Reply-To: <1rnljv8527o2phdjup4e9uji0kssf93svt@4ax.com> References: <1rnljv8527o2phdjup4e9uji0kssf93svt@4ax.com> Message-ID: <16187.1433.780458.994728@montanaro.dyndns.org> Gary> I get what you mean, but let me point out that "iterable" does not Gary> appear in the index of either the Language Reference or Library Gary> Reference, nor do I see it in the introduction. That's a documentation bug then. The concrete notion of an "iterable" arrived on the Python scene relatively recently, and the docs apparently haven't quite caught up in that respect. Skip From jacek.generowicz at cern.ch Sat Aug 23 03:38:37 2003 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 23 Aug 2003 09:38:37 +0200 Subject: Which way to say 'private'? References: Message-ID: "Batista, Facundo" writes: > One thing about property(): Can't find it's documentation! :( > > Know it exists and how to use it because of examples found on the net. > > But where it's formally explained? help(property), in your Python interpreter is probably a good place to start. From vanevery at 3DProgrammer.com Tue Aug 19 02:46:51 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Mon, 18 Aug 2003 23:46:51 -0700 Subject: Brandon's personal style (was) References: <38ec68a6.0308172319.431a4fde@posting.google.com> <38ec68a6.0308181659.1aab5c67@posting.google.com> Message-ID: Asun Friere wrote: > "Brandon J. Van Every" wrote in message >> >> Man, it's clear that I've got an entire hate group around here to >> exterminate! > > Doesn't that just mean a lot of people will be able to talk about you > behind your back without your ever realising? That's the point! I *want* them to! I look so, so much better when people abuse me and I don't answer them at all. People figure out pretty quick who's really full of it or not. The killfile makes the process... automatic. It's just messy now because the killfile is still being built. > Congratulations, you've just managed to deprive yourself of the often > insightful contributions of a regular poster to this newsgroup. Lulu??!? You think with the kind of barb he made, that my e-mail address is synonymous with "troll," that I care about his insights? or think that he has any to offer? Even if he does, I'll decline that trouble. It ain't worth it. > I wonder if you wouldn't be better off simply not participating in > Usenet groups at all. You'll save significant amounts of diskspace > without that killfile of yours, Please. We all know how tiny text storage is, EVEN WHEN IMPLEMENTED IN PYTHON. ;-) > not to mention keystrokes. True. The problem is, I'm still young and stupid enough to believe that I can have a cumulative effect on Usenet behavior. Maybe in 10 years I'll see the light. > But please > feel free to add me to your much vaunted killfile as well, that way > you don't have to listen one of the few people who, in this thread, > actually took your question seriously and gave a substantive answer. It's not that easy. You have to actually insult me, show an incapacity to rate me as anything but "troll," and/or demonstrate your complete unwillingness to be useful. The exact combo is a judgement call, but easily seen when there. For example, Doug Tolton fulfilled the criteria, albeit barely. Albeit again, quite deliberately, so not so barely. You yourself have failed, you will have to try harder if you want into my killfile. MHHUUAHAHAHHAHAHHAHAAAA!!!! -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From syver-en+usenet at online.no Fri Aug 8 04:18:28 2003 From: syver-en+usenet at online.no (Syver Enstad) Date: 08 Aug 2003 10:18:28 +0200 Subject: MSVC 6.0 Unsupported? References: <3F302764.8010301@ghaering.de> <3f3284d8$0$49098$e4fe514c@news.xs4all.nl> Message-ID: Irmen de Jong writes: > Syver Enstad wrote: > > But Gerhard, what can I do? Every python extension that I will try > to > > > compile will fail if it depends on a working staticforward. The most > > > rational thing to me is to patch object.h instead of patching every > > .cpp/.c file that needs this define. > > Can't you just add a single compiler option (for cl.exe) to your > project? > > > /Dstaticforward=extern Isn't it bad form to define a macro twice? This macro is alreay defined in object.h, and we define it once again on the command line. -- Vennlig hilsen Syver Enstad From peter at engcorp.com Thu Aug 28 14:14:48 2003 From: peter at engcorp.com (Peter Hansen) Date: Thu, 28 Aug 2003 14:14:48 -0400 Subject: Burn some books (please)... References: Message-ID: <3F4E4698.B8C84943@engcorp.com> "David Mertz, Ph.D." wrote: > > Alex Martelli wrote previously: > |>>Very long ago, some books where burnt in public, > > |Very long as in, Winter 2001/2002, for example? > |...as long of course as the books you burn belong to you, that's a form of > |political speech which is just as acceptable as burning a flag. > > I just want to point out to the readership that many copies of _Text > Processing in Python_ are available at your local bookstore for public > burning. There's heresy in that book! (apparently I trend a bit to far > in an FP direction :-)). > > I think I can speak for Alex in pointing out that _Python in a Nutshell_ > also makes for excellent kindling. As a start, since I'm actually in need of my copies of both the aforementioned tomes, I've printed out several copies of your newsgroup posting (above), and some of Alex's, and have built a small campfire in the pair-programming room to warm the programmers as they code. Thank you. -Peter From tim.one at comcast.net Fri Aug 1 21:23:56 2003 From: tim.one at comcast.net (Tim Peters) Date: Fri, 1 Aug 2003 21:23:56 -0400 Subject: time, calendar, datetime, etc In-Reply-To: Message-ID: [Andrew Dalke] > ... > Here's another view of the issue. The datetime module implements what > I'll call "vernacular" time. That is, time as is understood by most > people. 24 hours in a day, 60 minutes in an hour, 60 seconds in a > day, 365 days in a year except every 4th year (and hazy idea about > something strange at the century mark, but that's not a problem now). That's what Guido calls "naive time" on the DateTimeWiki (op. cit.). It's the time he lives in , and datetime was deliberately designed to mirror it. > And then there's timezones and daylight savings time. (And no > thoughts of "double daylight savings like the British had during > WWII.") Time zones are beyond Guido's notion of naivety. There's actually no support for any particular time zone in 2.3's datetime module, not even UTC or your local time zone. Instead there's a protocol by means of which "aware" datetime objects can be taught to play along with user-defined and user-coded time zone classes. Double daylight in WWII fits easily in this framework, provided you're motivated enough to bother writing a double-daylight tzinfo class to model it. I hope the community cares enough to write a collection of tzinfo classes modeling contemporary time zones, but if they're waiting for Guido to do it for them, it ain't gonna happen. sufficient-unto-the-day-are-the-24*3600-seconds-thereof-ly y'rs - tim From theller at python.net Thu Aug 7 12:09:47 2003 From: theller at python.net (Thomas Heller) Date: Thu, 07 Aug 2003 18:09:47 +0200 Subject: crossplatform py2exe - would it be useful? References: Message-ID: <3cgdfnzo.fsf@python.net> Alex Martelli writes: > Thomas Heller wrote: > ... >>>> myscript -c "import sys; sys.path.insert(0, sys.executable); import foo" > ... >>> Sounds like a good idea to me, if a sensible name is chosen for the >>> "main module" (I propose 'main':-). >> >> My choice would have been __main__ :-) Is it really the correct way to >> 'import __main__' instead of 'running' it? > > Well, most main scripts ARE coded with the "if __name__=='__main__':" > convention, after all, so an "import __main__" can be seen as a way > to just piggyback on that existing convention rather than inventing a > new one in addition. So, I concede it's better than "import main". > How would the hook be triggered? The zipimporter code would probably add argv[0] to sys.path, and then try to 'import __main__' or something like this. The problem is that a standalone executable python would have to disable the standard Python command line flags and environment variables, but they are parse *before* Py_Initialize() is called. And I hope that the options set by the command line flags and env vars should now come from the __main__ script itself. Thomas From aleaxit at yahoo.com Tue Aug 19 05:50:32 2003 From: aleaxit at yahoo.com (Alex Martelli) Date: Tue, 19 Aug 2003 11:50:32 +0200 Subject: What's better about Ruby than Python? References: Message-ID: Heiko Wundram wrote: ... > class X: > def test(*args): > print args > > X.test() # 1 > x = X() > x.test() # 2 > X.test(x) # 3 > > Run this, and for the first call you will get an empty tuple, while for Wrong: >>> class X: ... def test(*args): print args ... >>> X.test() Traceback (most recent call last): File "", line 1, in ? TypeError: unbound method test() must be called with X instance as first argument (got nothing instead) >>> X.test is not a function -- it's an unbound method; to call it, you MUST therefore pass it at least one argument, and the first argument you pass to it must be an isntance of X (or of any subclass of X). > on the instance they are associated with. If you have a predeclared > self, only calls 2 and 3 would work, if the self parameter is just > another parameter for the function, I can miraculously call the function > just like it is (see call 1). You seem to be wrongly assuming that "call 1" works, without having tested it -- in fact, it fails in any version of Python. Therefore, the "fact" that it works, being not a fact, cannot serve to support "having no predeclared self" (nor any other thesis). As for me, I have no special issue with "having to specify self" for functions I intend to use as bound or unbound methods; otherwise I would no doubt have to specify what functions are meant as methods in other ways, such as e.g. def [method] test(what, ever): ... and since that is actually more verbose than the current: def test(self, what, ever): ... I see absolutely no good reason to have special ad hoc rules, make "self" a reserved word, etc, etc. Python's choices are very simple and work well together (for the common case of defining methods that DO have a 'self' -- classmethod and staticmethod are currently a bit unwieldy syntactically, but I do hope that some variation on the often-proposed "def with modifiers" syntax, such as def [classmethod] test(what, ever): ... or def test(what, ever) [classmethod]: ... will make it past the BDFL filters in time for Python 2.4:-). Alex From bgailer at alum.rpi.edu Mon Aug 25 19:04:00 2003 From: bgailer at alum.rpi.edu (Bob Gailer) Date: Mon, 25 Aug 2003 17:04:00 -0600 Subject: pure Python DB In-Reply-To: Message-ID: <5.2.1.1.0.20030825170113.032cc878@66.28.54.253> At 11:08 PM 8/25/2003 +0200, Patrick Useldinger wrote: >Hello, >for a cross-platform project, I am looking for a Python DB. It should be >lightweight, but provide transactions an of course reliable. >Is there such a thing out there? How cross? There's SQLite (Windows, Linux) written in C and connected via pysqlite. SQLite is an embedded SQL Database Engine. Very powerful, fast, easy. www.sqlite.org, pysqlite.sourceforge.net Bob Gailer bgailer at alum.rpi.edu 303 442 2625 -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.506 / Virus Database: 303 - Release Date: 8/1/2003 From bdelmee at advalvas.REMOVEME.be Sat Aug 30 18:37:57 2003 From: bdelmee at advalvas.REMOVEME.be (=?ISO-8859-1?Q?Bernard_Delm=E9e?=) Date: Sun, 31 Aug 2003 00:37:57 +0200 Subject: Win32 documentation in CHM? In-Reply-To: References: Message-ID: <3f512707$0$1114$6c56d894@feed0.news.be.easynet.net> > the previous poster mentioned decompilers, can one then add other links > and then recompile with such beasts? On Windows, just use the MS HTML Help Workshop: http://go.microsoft.com/fwlink/?LinkId=14188 From electricity at uymail.com Thu Aug 28 02:36:08 2003 From: electricity at uymail.com (U. N. Owen) Date: Thu, 28 Aug 2003 08:36:08 +0200 Subject: learning to program Message-ID: <20030828063608.27027.qmail@uymail.com> Not TCI but TCL... It's another script language, but it's not installed with Python. Here it was just an example, so you don't need it for the moment. If you are interested, go to www.tcl.tk. ----- Original Message ----- From: Rich Date: Wed, 27 Aug 2003 18:20:51 -0700 To: python-list at python.org Subject: Re: learning to program Re: I am going through one of the tutorials on the Python site and have Re: ran into a problem. Re: Re: During the tutorial it talked about TCI, and gave some commands to do. Re: I went to the site and downloaded TCI. but was unable to do any of Re: the tasks. Re: Re: I think my question is, when the tutorial say the Dos prompt, do I use Re: my Dos prompt in windows, or the Dos prompt in the Python program? Re: Re: I am using the Tutorial by Alan Gauld, and I am at the bottom of Re: simple sequences (left side of page). Re: Re: On Wed, 27 Aug 2003 15:47:14 -0400, Peter Hansen Re: wrote: Re: Re: >Rich wrote: Re: >> Re: >> On Wed, 27 Aug 2003 14:07:31 -0400, Peter Hansen Re: >> wrote: Re: >> Re: >> >Rich wrote: Re: >> >> Re: >> >> This is the only post I am able to see, sorry about re posting. I Re: >> >> thought if I changed the subject heading I might be able to see the Re: >> >> post. Re: >> > Re: >> >You should be able to see the replies that you missed via Google Groups, Re: >> >as soon as they are indexed and on the web: Re: >> How long does it usually take to post on Google? Re: > Re: >In my experience, usually quite a few hours (maybe four or more?). Right Re: >now I can see posts there which I read only a short time before seeing Re: >yours, so that estimate feels about right. Re: > Re: >(By the way, it would be helpful if, when you quote material in a post Re: >to which you're replying, if you used whitespace to separate your Re: >own text from the quoted material. I almost didn't see your message Re: >at all, thinking you'd accidentally posted an empty reply. Thanks. :-) Re: > Re: >-Peter Re: Re: -- Re: http://mail.python.org/mailman/listinfo/python-list -- _______________________________________________ Get your free email from http://www.uymail.com Powered by Outblaze From tchur at optushome.com.au Tue Aug 26 05:44:00 2003 From: tchur at optushome.com.au (Tim Churches) Date: Tue, 26 Aug 2003 19:44:00 +1000 Subject: Celebrity advice (was: Advice to a Junior in High School?) In-Reply-To: Message-ID: <006f01c36bb6$9ae9f670$a300a8c0@emilio> Cameron Laird wrote: > Sent: Tuesday, 26 August 2003 7:03 PM > To: python-list at python.org > Subject: Celebrity advice (was: Advice to a Junior in High School?) > > In article , > Afanasiy wrote: > >I would also recommend not giving much weight to anything from ESR. > > What's going on *there*? Eric makes plenty of mistakes, > and he's apparently stubborn and biased in many cases; on > the other hand, while I disagree with him profoundly on > some technical choices, and I've been told of all sorts > of personal failings he exhibits, in my experience he's > always been willing to correct errors when presented with > evidence. Except when it comes to guns - despite all the evidence that the ready availability of firearms to the general population Results in huge numbers of avoidable homicides, suicides, injuries, incarceration and general mayhem, ESR actively promotes a puerile pro-gun libertarianism AND links that view to the open Source culture. The aphorism which appears at the top left corner of his blog (see http://armedndangerous.blogspot.com/) is: "Sex, software, politics, and firearms. Life's simple pleasures..." I'd suggest that the last of those pastimes makes him a less than ideal speaker for a junior high school (and I didn't even mention Columbine...) - the first three are of course perfectly legitimate topics for such a speaker. > I ask in part because, as near as I can tell, you were the > first to mention him in this thread. It appears that you > regard his output as particularly hazardous. See the first few paragraphs of http://www.catb.org/~esr/guns/gun-ethics.html Tim C From mnations at airmail.net Mon Aug 18 19:46:00 2003 From: mnations at airmail.net (Marc) Date: 18 Aug 2003 16:46:00 -0700 Subject: Design idea for Ping Application Message-ID: <4378fa6f.0308181546.548daff7@posting.google.com> Hi all, I've been searching old posts for ideas, and can't quite come up with anything. In short I need an application that will continuously ping 11 different hosts and track the status of the pings. I have the groundwork laid with 11 objects that can be started or stopped independently of each other using threads. However, I'm having trouble working the ping functionality into it. I've tried using the modules written by various people for pinging, but haven't been able to make that work. What I have been able to use is this: > import os > p = os.popen("ping X.X.X.X") > data = p.readlines() > p.close() This works, but presents me with a problem. In order to continuously ping using the "-t" option for ping, I am unable to perform a readlines() command because it hangs. I've tried other variations of read commands, but they all hang my system. I guess it keeps looking for EOF and never finds it because the thing is still running. Is there a type of read command that just takes what is currently in the buffer and stores it? If this doesn't work I can simply do a rotating ping between the 11 hosts as the different threads share time. But this isn't a continuous flood of traffic like I need. I really need them all running at once. So how can I get information back from the ping pipe without waiting for it to finish? I'm also open to other solutions if anyone has come across something like this before. Thanks ahead of time, Marc From adalke at mindspring.com Wed Aug 20 18:20:24 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Wed, 20 Aug 2003 22:20:24 GMT Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> <6dj2kv8ugkieehs7guh786cl40o5lj6mcs@4ax.com> Message-ID: Doug Tolton: > You are saying you don't know how to tweak a language to fit it your > specific domain better than a general puprose language? And you are > saying you are a pretty good language designer? I've been thinking about that. Any language designer can design a language. A good designer can add useful features. A great designer knows when to keep features out of the language. I maintain that I am a good language designer, but not a great one. There are enough average or mediocre designers (law of large numbers almost guarantees a bell curve) that I prefer ways to keep them from meddling into what I do. Only somewhat facetiously: "Go play somewhere else and don't bother me until you've learned something." Facetious because anyone who knows me knows that I enjoy explaining how things work and how they got to be that way. It's the inability to get into another's shoes - to understand view different than one's own - which annoys me the most. A deficiency sadly typical of all too many enthusiastic new language designers. Andrew dalke at dalkescientific.com From kenfettig at btinet.net Fri Aug 8 22:35:51 2003 From: kenfettig at btinet.net (Ken Fettig) Date: Fri, 8 Aug 2003 21:35:51 -0500 Subject: Python and Web Hosting Message-ID: Hello, I am begining to learn the Python language and I am enjoying its flexibility. I do have a question. I am considering using Python for web development. I have found that a huge number of web hosts offer support for PHP. How hard is it to find a Web Host that will allow you to you to run your own Python scripts, web or app server, template engine (Zope or Cheetah)? If it is not, is it comparable in cost? Thanks Ken kenfettig at btinet.net From rnd at onego.ru Fri Aug 1 00:19:23 2003 From: rnd at onego.ru (Roman Suzi) Date: Fri, 1 Aug 2003 08:19:23 +0400 (MSD) Subject: Wow: list of immediate subclasses? Message-ID: I am very surprised that modern classes (inherited from object) in Python 2.3 show their ancestry, eg: >>> object.__subclasses__() [, , , , , , , , , , , , , , , , , , , ] This seems cool introspection tool but raises questions: 1- I wonder if it has security consequences (knowing what other classes are in there, probably in some other modules). As it adds a hole starting from base class "object". Earlier it was possible to "chroot" to some custom builtin namespace and provide restricted execution. 2- how do I get rid of a class completely? This doesn't work: >>> object.__subclasses__() [, , , , , , , , , , , ] >>> class A(object): pass ... >>> object.__subclasses__() [, , , , , , , , , , , , ] >>> del A >>> object.__subclasses__() [, , , , , , , , , , , , ] >>> Sincerely yours, Roman Suzi -- rnd at onego.ru =\= My AI powered by GNU/Linux RedHat 7.3 From bokr at oz.net Fri Aug 1 15:40:40 2003 From: bokr at oz.net (Bengt Richter) Date: 1 Aug 2003 19:40:40 GMT Subject: Potentially important real-time on-line discussion References: Message-ID: On Fri, 01 Aug 2003 16:21:38 -0000, claird at lairds.com (Cameron Laird) wrote: >*The Chronicle of Higher Education*, which is more-or-less >authoritative for US university administrations, is spon- >soring a discussion on the place of open-source in >universities ("... are such choices too risky for colleges >...?"), starting in about an hour. Bluntly, I think it's >time to rally 'round the flag. > >http://chronicle.com/colloquylive/2003/08/opensource/chat.php > >Pass it on. Gee, I thought the soul of academia was supposed to be the mother of open source. Sad to see there's any doubt that the right thing is to get her away from streetwalking. Regards, Bengt Richter From ajsiegel at optonline.net Sun Aug 31 08:38:27 2003 From: ajsiegel at optonline.net (Arthur) Date: Sun, 31 Aug 2003 08:38:27 -0400 Subject: artificial intelligence? Message-ID: <000901c36fbc$c72b3be0$0c02a8c0@Arts> """ Dear Amazon.com Customer, We've noticed that customers who have purchased books by Mark Lutz often enjoy the books of Sedi 200. So you might like to know that Sedi 200's newest book, Earth's Core and Lower Mantle (Fluid Mechanics of Astrophysics and Geophysics, V.11), """ Sure read my mind, didn't they? Any theories on how the Amazon.com AI machine got this far off track? Art From tyler at tylereaves.com Sun Aug 24 16:31:22 2003 From: tyler at tylereaves.com (Tyler Eaves) Date: Sun, 24 Aug 2003 16:31:22 -0400 Subject: nested data structures with classes References: Message-ID: Maybe you could use dictionaries? ie: reaction['name'] = 'fawlty towers' reaction['reactant'] = [] reaction['reactant'].append(anotherdict) etc... From gh at ghaering.de Wed Aug 27 19:48:58 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Thu, 28 Aug 2003 01:48:58 +0200 Subject: Python PostgreSQL frontend for Win2K with MinGW32 ? In-Reply-To: <3f4cfee5_2@mk-nntp-1.news.uk.worldonline.com> References: <3f4cfee5_2@mk-nntp-1.news.uk.worldonline.com> Message-ID: <3F4D436A.8010406@ghaering.de> Dave Haynes wrote: > Hi, > > This is just as much a PostgreSQL question as a Python one, but here > goes... > > I've been trying to port the psycopg interface to a Win2K client > (server runs FreeBSD). I'm using MinGW32 rather than CygWin, and having > trouble compiling the libpg library as a DLL. [...] I'd recommend you statically link in libpq into your Python PostgreSQL interface. That's what I'm doing for the win32 releases of pyPgSQL. I'm also, like you, using mingw for these and I use this patch I created many moons ago: http://pypgsql.sourceforge.net/misc/postgresql.html HTH, -- Gerhard From kern at taliesen.caltech.edu Wed Aug 27 11:10:23 2003 From: kern at taliesen.caltech.edu (Robert Kern) Date: Wed, 27 Aug 2003 15:10:23 +0000 (UTC) Subject: Proposal: Magic Constants References: Message-ID: In article , "John Roth" writes: [snip] > Another thing to think about is whether > this could cause problems with existing > code. I can't immediately think of a case > where a literal can be next to a character, > but I'm also not a real deep authority on all > of the oddities of Python syntax. 10L 0X 1e+10 10j > John Roth -- Robert Kern kern at caltech.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter From op73418 at mail.telepac.pt Fri Aug 8 09:57:11 2003 From: op73418 at mail.telepac.pt (Gonçalo Rodrigues) Date: Fri, 08 Aug 2003 14:57:11 +0100 Subject: Bug? If not, how to work around it? References: <2259b0e2.0308070919.2bedce6@posting.google.com> <2259b0e2.0308071454.1f2869aa@posting.google.com> <2259b0e2.0308080323.1a2a8dfa@posting.google.com> Message-ID: On 8 Aug 2003 04:23:48 -0700, mis6 at pitt.edu (Michele Simionato) wrote: [text snipped] >Not me personally, hence the reason why I didn't >submit a bug report, but this time (if Gonzalo is not going to do that), I >will submit the report, unless Alex is going to prove that this is >already documented ;) > I'm gonna do it this weekend. I'll post a kind of abstract of what I learned from this thread. With my best regards, G. Rodrigues From simonb at webone.com.au Tue Aug 12 20:43:58 2003 From: simonb at webone.com.au (Simon Burton) Date: Wed, 13 Aug 2003 10:43:58 +1000 Subject: customizing and/or/not Message-ID: Just reading about the new Sets... and this came up. Why can't we customize the and/or/not operators? I see this as making one's own boolean type. Is it possible? class myBool: def __land__(self,other): def __lor__(self,other): def __lnot__(self,other): or even: def __in__(self,item): def __nin__(self,item): I guess i'm wondering why we cant use and/or with lists/sets etc. It's perhaps too funky. Simon Burton. From jorgencederberg at hotmail.com Wed Aug 13 02:29:14 2003 From: jorgencederberg at hotmail.com (=?ISO-8859-1?Q?J=F8rgen_Cederberg?=) Date: Wed, 13 Aug 2003 08:29:14 +0200 Subject: union in Python In-Reply-To: References: Message-ID: <%Uk_a.8$tP4.7@news.get2net.dk> Wiebke P?tzold wrote: Hello Wiebke you did what I asked, but you forgot to read to whole message I wrote to you. > This is the error-traceback that is print whenmy program failed: > > >>>> Themenbereiche Nachname > Traceback (most recent call last): > File > "C:\PROGRA~1\Python22\lib\site-packages\Pythonwin\pywin\framework\scriptutils.py", > line 310, in RunScript > exec codeObject in __main__.__dict__ > File > "C:\Programme\Python22\Lib\site-packages\Pythonwin\pywin\Demos\Uebung11.py", > line 46, in ? > print feld_th, feld_na, union1(feld_th, feld_na) > NameError: name 'union1' is not defined >>>> The following is taken from my previous message to you: > Where are the functions union1 and union2 defined and why do you want to find the union between two strings, it doesn't make sense. On the other hand, if feld_th and feld_na where two lists it would make sense. > And this is exactly what caused the error. The last line of your traceback states the problem: > NameError: name 'union1' is not defined You should really read the tracebacks carefully, they tell what went wrong and where it went wrong. You probably made the functions somewhere else, but I still don't see the point in taking the union of two strings. Do you care to explain how the functions work or how you intend to get them working or do just want a solution to your assigment? Regards Jorgen Ps.. You should really do your self a favour and download the documentation: http://www.python.org/doc/current/download.html Read the tutorial carefully and try to do some the examples in it. From vze4rx4y at verizon.net Fri Aug 15 20:39:57 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Sat, 16 Aug 2003 00:39:57 GMT Subject: Py2.3: Feedback on Sets References: Message-ID: > > * Are the docs clear? Can you suggest improvements? [Carl Banks] > Yeah: in the library reference, the table entry for s.union(t) should > say "synonym of s|t" instead of repeating the description. This is > especially true because it's not clear from a simple glance whether > "s.union(t)" goes with "s|t" or "s&t", because it sits right between > the two. Better yet, I would change it to a three-column table > (operation, synonym, result). Done! Raymond Hettinger From peter at engcorp.com Thu Aug 28 18:16:08 2003 From: peter at engcorp.com (Peter Hansen) Date: Thu, 28 Aug 2003 18:16:08 -0400 Subject: OT: Americans love their guns References: Message-ID: <3F4E7F28.2B6AAD2F@engcorp.com> mackstann wrote: > > On Thu, Aug 28, 2003 at 01:38:24PM -0400, Lulu of the Lotus-Eaters wrote: > > > [...] And suicides > > attempted by gun succeed at a much higher rate than those done by other > > means (and are much more likely to be attempted in the first place > > because of the "convenience"). > > What's so bad about that? We already have a few billion too many humans > lying around anyways. Might as well let the volunteers do their thing.. This just points to the need for better gun training. The fact that _any_ of these attempted suicides-by-gun actually fail clearly indicates there are a lot of gun owners who don't know how to aim properly. ;-) -Peter From irmen at -NOSPAM-REMOVETHIS-xs4all.nl Mon Aug 25 17:19:27 2003 From: irmen at -NOSPAM-REMOVETHIS-xs4all.nl (Irmen de Jong) Date: Mon, 25 Aug 2003 23:19:27 +0200 Subject: ANN: Snakelets 1.3 (simple-to-use web app server with dynamic pages) In-Reply-To: <3f4798f7$0$49102$e4fe514c@news.xs4all.nl> References: <3f4798f7$0$49102$e4fe514c@news.xs4all.nl> Message-ID: <3f4a7d5a$0$49099$e4fe514c@news.xs4all.nl> Irmen de Jong wrote: > I'm happy to say that Snakelets 1.3 is now available. I forgot to mention that to successfully start it, you now have to generate a music database file yourself. Previously one was included (my own :-) but I removed it. It's in the webapps/music directory. You can generate one yourself by running the makedatabase.py script, giving the directory(ies) with your mp3 files in it as arguments. Sorry :) --Irmen de Jong From tim at remove_if_not_spam.digitig.co.uk Fri Aug 1 20:02:10 2003 From: tim at remove_if_not_spam.digitig.co.uk (Tim Rowe) Date: Sat, 02 Aug 2003 01:02:10 +0100 Subject: what do people use for 2D coordinates? References: Message-ID: On 1 Aug 2003 16:37:38 -0700, aayycc88 at hotmail.com (Andy C) wrote: >You could use tuples or complex numbers (seems like a bit of a hack). >I saw somewhere it said that tuples are useful for coordinates. But I >haven't found a nice way to add coordinates, since + does >concatenation on tuples. Since a complex number is commonly interpreted as a 2D coordinate in the complex plane, it doesn't look like any sort of a hack to me. They're likely to have all the properties you want (except, possibly, easy extensibility into 3D -- but how many languages come with tensor libraries?) From logiplex at qwest.net Tue Aug 12 18:41:07 2003 From: logiplex at qwest.net (Cliff Wells) Date: Tue, 12 Aug 2003 15:41:07 -0700 Subject: Customizing a linux distribuition using Python In-Reply-To: <3f379f4a@core.inf.ethz.ch> References: <3f379f4a@core.inf.ethz.ch> Message-ID: <1060728067.4769.96.camel@software1.logiplex.internal> On Mon, 2003-08-11 at 06:52, Antoine Logean wrote: > Hi, > > After having installed Linux (RedHat) on a PC I want to automate all the > post-installation tasks. A lot of shell and perl scripts exist to do > this. But I want to have something purelly object oriented where I can > define the differents tasks in an abstract manner. Is that something in > this direction in Python ? So any information concerning Linux (Unix) > system administration and Python would interest me. Since you're on RedHat, take a look at some of their administration scripts (many of which are in Python) for some inspiration. Just doing a 'find /usr/share -name "*.py"' should be enough to get you started. Note that not all of their Python scripts have a .py suffix. Regards, -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 (800) 735-0555 From mhammond at skippinet.com.au Fri Aug 8 22:02:59 2003 From: mhammond at skippinet.com.au (Mark Hammond) Date: Sat, 09 Aug 2003 12:02:59 +1000 Subject: Python/Excel VBComponents crash In-Reply-To: References: Message-ID: Mark Carter wrote: > I use Office 2000, and I have recently upgraded to python 2.3 and > win32all-155.exe > > The following code worked in python 2.2: > > xlApp = Dispatch("Excel.Application") > xlApp.Visible = 1 > xlApp.Workbooks.Add() > xlApp.ActiveWorkbook.SaveAs(sys.path[0] + '\\temp.xls') > wb = xlApp.Workbooks("temp.xls") > wbc = wb.VBProject.VBComponents # <---- CAUSES CRASH IN 2.3 > xlApp.Quit() > del xlApp > > but I get a GPE in 2.3, when the code finishes execution: > EXCEL caused an invalid page fault in > module OLE32.DLL at 0167:65f18ae3. > I think this is a bug in Excel, but it is not clear why Python 2.3 shows it, but 2.2 does not. If you set wbc to None before closing, it doesn't crash. I think the problem is that Excel doesn't like being shut down when references to it still exist. You should try and make sure that pythoncom._GetInterfaceCount() returns zero before quitting. Mark. From ghowland at lupineNO.SPAMgames.com Sat Aug 23 12:12:03 2003 From: ghowland at lupineNO.SPAMgames.com (Geoff Howland) Date: Sat, 23 Aug 2003 16:12:03 GMT Subject: Modifying the {} and [] tokens References: <04cekv0s6ghjtuhl5j2gph7ltobdb5rsam@4ax.com> <2259b0e2.0308230718.53d22c14@posting.google.com> Message-ID: <774fkvg920qibnnp83r17inqmk311tqcsv@4ax.com> On 23 Aug 2003 08:18:49 -0700, mis6 at pitt.edu (Michele Simionato) wrote: >Subclass dict, define __add__ and __sub__ and it will work, but NOT >with the brace syntax. You must use something like > >mydict(a=1,b=2)+mydict(c=3,d=4) Yeah, I got this to work off the bat. >Python tries hard not to modify its basic syntax, so you must stay >with the above. Pythonista would argue that this is a strenght of the >language: "explicit is better than implicit". I agree with this philosophy too. I'm not sure where the changes I'm looking to fail to be explicity. {} + {} makes sense right? You are adding them together. There will obviously be a possibility of key clobbering, but then you could run something like {}.intersect() and get the keys that will be clobbered (if it existed). len([]) [].len() Both seem to make sense explicitly to me. Currently we use it through builtins, but having it as an attribute would also be clear. It's duplicated, but at the same time it's consistant. Yes I know it makes one version of [] different than others, but if you state it is going to happen, then it is known. If it is all new functionality, then it wont break old functionality. If you change old functionality, you know you are doing it and risking problems. Python allows for a lot of different things some people in other languages claim is dangerous because it's too free-hand. That doesn't make them right, and often I've read statements in the spirit of "Python gives you enough rope to let shoot yourself in the foot", and it's meant as a good thing. We're all adults here, etc. I still think the above things might be good in the language in general (not just a specific module change), but I would feel a lot more certain after using them for a while in the real world. -Geoff Howland http://ludumdare.com/ From tjreedy at udel.edu Sun Aug 24 03:46:23 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 24 Aug 2003 03:46:23 -0400 Subject: macro FAQ References: Message-ID: "Jacek Generowicz" wrote in message news:tyfbruf998w.fsf at lxplus014.cern.ch... > This has turned out rather long, but I hope that it demystifies these > scary exotic macros for at least one or two people on the list. Definitely. The sort of concrete example I asked for. Thank you. Terry From tjland at iserv.net Wed Aug 20 16:53:29 2003 From: tjland at iserv.net (tjland at iserv.net) Date: Wed, 20 Aug 2003 16:53:29 -0400 (EDT) Subject: Sobig in list? Message-ID: <1768.68.75.128.246.1061412809.squirrel@webmail.iserv.net> When you see the net take the shot When you miss your shot shoot again When you make your shot you win! Just remember Offense sells tickets But defense wins championships! From hans at zephyrfalcon.org Fri Aug 22 09:51:20 2003 From: hans at zephyrfalcon.org (Hans Nowak) Date: Fri, 22 Aug 2003 09:51:20 -0400 Subject: What's better about Ruby than Python? In-Reply-To: References: <3F4040F8.87901505@alcyone.com> <6dj2kv8ugkieehs7guh786cl40o5lj6mcs@4ax.com> Message-ID: <3F461FD8.1060804@zephyrfalcon.org> Jacek Generowicz wrote: > The problem is that a permissive language can be harmful. > > Let's say you rebind all the attributes of __bulitins__. Now I cannot > read your code anymore (well, I can, but it doent'h do what it looks > like it will do). I see your point. The obvious answer would be "so don't do that, then". Of course, the same answer would apply to writing abusive macros. Python usually strikes a good balance between being permissive and restrictive. The ability to rebind builtins is unfortunate, but I suppose it can occasionally be useful. Fortunately not many people (have to) resort to this. On the other hand, having a complete and very powerful macro system at your disposal, would be much more attractive. I suspect that people would start abusing it from day one. Look at metaclasses. > Just because a stupid or malicious programmer could do "bad things" is > not a reason to reduce a language's power. (You end up with Java.) You are right, but one could wonder if the drawbacks don't outweight the benefits. Python is already powerful as it is (compared to languages other than Lisp ;-). I'm not sure if powerful macros would do much good. Of course, that's just my opinion. -- Hans (hans at zephyrfalcon.org) http://zephyrfalcon.org/ From grisha at apache.org Thu Aug 28 21:12:50 2003 From: grisha at apache.org (Gregory (Grisha) Trubetskoy) Date: Thu, 28 Aug 2003 21:12:50 -0400 Subject: ANNOUNCE: Mod_python 3.1.0 Alpha Message-ID: <20030828210644.C43921@onyx.ispol.com> The Apache Software Foundation and The Apache HTTP Server Project are pleased to announce the 3.1.0 ALPHA release mod_python. Some feature highlights: * Server-side sessions with memory or dbm-based storage and session locking support. * PSP - a fast flex-based scanner which allows embedding Python code within HTML. * Native cookie support, including support for automatic cryptographic cookie signing and marshalling. * Compatibility with Python 2.3, as well as many other enhancements. Alpha releases are NOT considered stable and do contain bugs. Some functionality may change before the first beta release. This release is intended to solicit widespread testing of the code. We strongly recommend that you try out your existing applications and experiment with new features in a non-production environment using this version and report any problems you may encounter so that they can be addressed before the final release. Mod_python 3.1.0a is available for download from: http://httpd.apache.org/modules/python-download.cgi Preferred method of providing feedback is the mod_python user list mod_python at modpython.org (due to spam, you must subscribe to post). For more information about mod_python visit http://www.modpython.org/ Thank You, Grisha Trubetskoy From borcis at users.ch Thu Aug 21 09:56:22 2003 From: borcis at users.ch (Borcis) Date: Thu, 21 Aug 2003 15:56:22 +0200 Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> <6dj2kv8ugkieehs7guh786cl40o5lj6mcs@4ax.com> Message-ID: <3F44CF86.3060203@users.ch> Jacek Generowicz wrote: > > You criticize macros for not encouraging code sharing (they do, by > encouraging you to share the (vast) underlying language while reaching > out towards a specific domain), while your preferred solution seems to > be the ultimate code non-sharing, by throwing away the underlying > language, and re-doing it. This criticism can't help looking frivolous, imho. You appear to be confusing "language" with "speech". But I do believe there *must* exist a sane niche for (perhaps mutated) macros (in some lisp-like sense). Cheers, B. From oren-py-l at hishome.net Tue Aug 19 17:37:09 2003 From: oren-py-l at hishome.net (Oren Tirosh) Date: Tue, 19 Aug 2003 17:37:09 -0400 Subject: Why does this (not) work? In-Reply-To: References: Message-ID: <20030819213709.GA78768@hishome.net> On Tue, Aug 19, 2003 at 05:25:19PM -0400, Michael C. Neel wrote: > I've got this string in which I need to sub in the same word several > times; i.e: > > >>> "%s - %s - %s" % ("test","test","test") > 'test - test - test' > >>> > > But I want to use the * to make life easier to read, so I tried: > > >>> ("test",)*3 > ('test', 'test', 'test') > >>> "%s - %s - %s" % ("test",)*3 > Traceback (most recent call last): > File "", line 1, in ? > TypeError: not enough arguments for format string > >>> It's just an issie of evaluation order. Try adding parentheses: >>> "%s - %s - %s" % (("test",)*3) 'test - test - test' Oren From aahz at pythoncraft.com Wed Aug 6 19:35:18 2003 From: aahz at pythoncraft.com (Aahz) Date: 6 Aug 2003 19:35:18 -0400 Subject: Bug? If not, how to work around it? References: Message-ID: In article , Gon?alo Rodrigues wrote: > >>>> class Test(object): >... def __init__(self, obj): >... self.__obj = obj >... def __getattr__(self, name): >... return getattr(self.__obj, name) >... >>>> a = Test([]) >>>> a.__iter__ > >>>> iter(a) >Traceback (most recent call last): > File "", line 1, in ? >TypeError: iteration over non-sequence >>>> > >Is this a bug? If not, how to code Test such that iter sees the >__iter__ of the underlying object? As Mark guessed, iter() goes directly to the attribute rather than using the __getattr__ machinery of the class. However, you can intercept it using a metaclass, but that requires a bit of fancy footwork to reach down into the instance to get self.__obj. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From mhammond at skippinet.com.au Tue Aug 12 21:31:23 2003 From: mhammond at skippinet.com.au (Mark Hammond) Date: Wed, 13 Aug 2003 11:31:23 +1000 Subject: Python win32 dll In-Reply-To: References: Message-ID: Karl Lopes wrote: > Hello all, > I would like to implement a COM server using python. > This server is based on an interface which was given to me in Visual Basic. > > For example one of the methods in the interface is: > Public Sub CreateLogFile(ByVal LogFilePath AS String, > ByRef LogFileIntf As LogFile); > > > 1. The corresponding Python method would be: > def CreateLogFile( self, LogFilePath, LogFileIntf ). Is this correct? Probably > 2. Is there a difference in the way Python implements ByVal and ByRef? In Python you need to *return* any out values. eg: def CreateLogFile( self, LogFilePath, LogFileIntf ): ... return new_file You must declare LogFileIntf, as VB will always pass it as it has no real concept of an "out" param, just "in" or "inout". However, if this interface was actually declared in a type library/IDL (which *does* make the distinction), you may find that LogFileIntf is declared "out", which would mean you do *not* declare the param in the Python function (even though you still would if you were implementing the interface in VB). Yes, I know, it sucks Mark. From kiyolee*remove* at hongkong.com Thu Aug 14 08:30:36 2003 From: kiyolee*remove* at hongkong.com (Kiyo Kelvin Lee) Date: Thu, 14 Aug 2003 22:30:36 +1000 Subject: Error with Python 2.3 as a shared Library References: Message-ID: You need to add /whatever/lib to the path for searching .so files. If you are root, normally you may edit /etc/ld.so.conf to add the path permanently. If you are not root, you can set the environment variable LD_LIBRARY_PATH: for sh: export LD_LIBRARY_PATH=/whatever/lib for csh: setenv LD_LIBRARY_PATH /whatever/lib or simply use the env command: env LD_LIBRARY_PATH=/whatever/lib python Note that this is nothing special to python but normal behaviour of Linux or Linux like operating systems including many Unices. Regards, Kiyo "Francisco Miguel Montenegro Montes" wrote in message news:mailman.1060831041.1705.python-list at python.org... > Hi, perhaps some of you can help me... > > I'm installing Python 2.3 (in Linux RedHat 8.0) and I need to build it > like a shared library, because I want to interact > Python with PostgreSQL. Following the README instructions, I try: > > ./configure --enable-shared --prefix=/whatever (I'm not root of my > system, so I can't use /usr/local/) > make > make install > > it seems to be ok, without errors. And when I try : > > /whatever/bin/python > > it says: > > whatever/bin/python error while loading shared libraries: > libpython2.3.so.1.0: cannot open shared object file: No such file or > directory > > but this library (libpython2.3.so.1.0 ) is in the whatever/lib directory. > > What's wrong? Is it something related to the path? How can I tell python > where the library is? Or is it not the problem? > > Thanks. > > From donn at u.washington.edu Tue Aug 12 12:57:50 2003 From: donn at u.washington.edu (Donn Cave) Date: Tue, 12 Aug 2003 09:57:50 -0700 Subject: popen2 References: Message-ID: In article , guy.flowers at Machineworks.com (Guy) wrote: > The unix equivalant is something like this : > > from popen2 import popen2 > output, input = popen2("csh") > # Sets the enviroment. > input.write("setenv DISPLAY doors:0.0\n") > > input.writeinput.write(f_mwtest_exe_str + " " + f_mwtest_args + " " + > os.path.dirname(f_testlwc_str) + " " + f_testlwc_str + "\n") > > print "finished" > process the output from the test file. > > > The problem is at the moment I can't get the process to stop and wait > until the exe has finished executing, the python script executes > everything and then the test file is executed afterwards. I'm thinking > that there must be a switch on the csh or sh command to stop this > happening but I don't know what it is. The unix machines that I'm > working on are all different plat types, so the platform type proberly > won't help you. Try something like status = input.close() result = output.read() if status is None: print 'success:', repr(result) else: print 'error exit', status, repr(result) The close() is the important part: 1. flush your buffer so data actually goes to the shell 2. closes the shell's input so it doesn't stay around waiting for more. 3. returns exit status for the shell process, or None if the exit status is 0. (This won't work so well for rsh.) While I'm at it, I would recommend that you use "sh" instead of "csh", because in the end it will give you less grief with bugs and misfeatures. "setenv x v" -> "x=v export x" if you do this. I would also recommend popen2("sh 2>&1") so that the piped output includes error/diagnostic output. Donn Cave, donn at u.washington.edu From staschuk at telusplanet.net Wed Aug 27 17:31:02 2003 From: staschuk at telusplanet.net (Steven Taschuk) Date: Wed, 27 Aug 2003 15:31:02 -0600 Subject: Python memory management In-Reply-To: <000001c36cd4$ca7779c0$0d00000a@esss.com.br>; from camelo@esss.com.br on Wed, Aug 27, 2003 at 04:52:47PM -0300 References: <7h3ekz76jyd.fsf@pc150.maths.bris.ac.uk> <000001c36cd4$ca7779c0$0d00000a@esss.com.br> Message-ID: <20030827153102.C470@tibia.amotlpaa.bogus> Quoth Marcelo A. Camelo: [...] > Yes, I will be saying that. But, if I can't change the way Python > behaves, at least I want a way to diagnose what he is doing. I've found > some references about Pymalloc, now the default Python memory manager, > and how it can report statistics about memory usage, but the > documentation is a bit light on details. Any pointer to some resources > on the subject? [...] There's Misc/SpecialBuilds.txt in the source distribution, which documents several build-time options which could be used for such investigations. (It assumes some familiarity with the internals.) -- Steven Taschuk staschuk at telusplanet.net "I may be wrong but I'm positive." -- _Friday_, Robert A. Heinlein From newsgroups at jhrothjr.com Mon Aug 4 07:04:27 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Mon, 4 Aug 2003 07:04:27 -0400 Subject: True References: Message-ID: "Andrew Dalke" wrote in message news:bgknba$fk1$1 at slb0.atl.mindspring.net... > Daniel Klein: > > > true = (1 == 1) > > > false = not true > > > > > > This was at the recommendation of someone on this list some time ago. > > John Roth > > There were no true booleans in 2.2 and earlier. Whoever recommended > > that didn't know what he was talking about. There was no difference. > > Indeed, there were no true booleans in Python, but there were > actual PyTrue and PyFalse objects at the C level. Doing the "1 == 1" > trick would expose that implementation choice to Python. > > This was rarely used. The only place I know of is in the win32 code, > where a COM API can take a boolean or an integer function. The > win32 interface checks if the value is PyTrue/PyFalse, > > Here's relevant links > http://mail.python.org/pipermail/python-list/1999-November/015260.html > http://mailman.pythonpros.com/pipermail/pycom-dev/1999q1/000106.html So, are you saying that this would have returned -1, rather than 1? John Roth > Andrew > dalke at dalkescientific.com > > From adalke at mindspring.com Fri Aug 22 00:22:16 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Fri, 22 Aug 2003 04:22:16 GMT Subject: Message Passing? References: Message-ID: Kris Caselden: > What's the best method for communication between Python applications? Depends on what kind of data you want to pass around. XML-RPC is quite easy. For that matter, so is straight HTTP. And then there's the Twisted interfaces, and Pyro. > I'm looking for a simple message-passing routine. I tried looking at > pipes, but I haven't found much documentation. Sockets looks most > promising, but it seems a little more complicated than what I'm > looking for. Any suggestions? Mmm, okay, the easiest is likely XML-RPC for what you want. Look in the standard library. When you start needing more features, try Twisted's XML-RPC support. When you need more than that, you'll know by then more about what you need, in order to evaluate the other technologies better. Andrew dalke at dalkescientific.com From knight at baldmt.com Wed Aug 20 23:24:29 2003 From: knight at baldmt.com (Steven Knight) Date: Wed, 20 Aug 2003 22:24:29 -0500 (CDT) Subject: ANNOUNCE: SCons 0.92 fixes a potentially critical Win32 bug Message-ID: SCons is a software construction tool (build tool, or make tool) written in Python. It is based on the design which won the Software Carpentry build tool competition in August 2000. Version 0.92 of SCons has been released and is available for download from the SCons web site: http://www.scons.org/ Or through the download link at the SCons project page at SourceForge: http://sourceforge.net/projects/scons/ RPM and Debian packages and a Win32 installer are all available, in addition to the traditional .tar.gz and .zip files. WHAT'S NEW IN THIS RELEASE? Release 0.92 contains an important fix for a critical bug found shortly after SCons 0.91 was released, plus two other fixes. SCons 0.91 contains a bug that prevents SCons from working on Win32 systems unless either the Microsoft Visual Studio linker (link.exe) or the GCC linker is installed, or a custom-defined linker is used. This bug has been fixed in release 0.92. This bug does not cause incorrect builds and does not damage a source tree or build tree in any way. Anyone with either the Visual Studio or GCC linker installed on their Win32 system, or using a custom-defined linker, will never see this bug and could continue to use 0.91 without any serious repercussions or side effects. Release 0.92 contains two other fixes: - Support for the PharLap linker was not working properly in 0.91, and has been fixed. - When the YACC -o option was used to specify an output file with a different basename than the source file, SCons would mistakenly think that the basename of the generated .h file should match the source file, not the target file. This has been fixed. Additionally, the Debian (.deb) package available from the SCons web site or SourceForge project page has been updated to match the dependencies and other particulars of the (out of date) Debian package available from debian.org. In particular, the package is now dependent on Python 2.2 instead of Python 2.1. ABOUT SCONS Distinctive features of SCons include: - a global view of all dependencies; no multiple passes to get everything built properly - configuration files are Python scripts, allowing the full use of a real scripting language to solve difficult build problems - a modular architecture allows the SCons Build Engine to be embedded in other Python software - the ability to scan files for implicit dependencies (#include files); - improved parallel build (-j) support that provides consistent build speedup regardless of source tree layout - use of MD5 signatures to decide if a file has really changed; no need to "touch" files to fool make that something is up-to-date - easily extensible through user-defined Builder and Scanner objects - build actions can be Python code, as well as external commands An scons-users mailing list is available for those interested in getting started using SCons. You can subscribe at: http://lists.sourceforge.net/lists/listinfo/scons-users Alternatively, we invite you to subscribe to the low-volume scons-announce mailing list to receive notification when new versions of SCons become available: http://lists.sourceforge.net/lists/listinfo/scons-announce ACKNOWLEDGEMENTS Special thanks to Charles Crain, Gary Oberbrunner and Gerard Patel for their contributions to this release. On behalf of the SCons team, --SK From jjl at pobox.com Mon Aug 11 20:21:49 2003 From: jjl at pobox.com (John J. Lee) Date: 12 Aug 2003 01:21:49 +0100 Subject: PYTHON AND C++ References: Message-ID: <873cg7wwrm.fsf@pobox.com> "satish k.chimakurthi" writes: > I am trying to specify an SIDL (Scientific Interface Definition Language) > interface to a sophisticated C++ code that I use in my project. Is *that* your goal... > I intend to > run the code from the python scripting environment. ...or *that*? [...] > My ultimate intention is to access the C++ code from python. I have looked > into automatic and semi-automatic interface generators like SWIG, > BOOST.PYTHON and ended up doing nothing useful and so adopted BABEL I doubt any of those support SIDL, since it appears to be both highly specialised and unpopular (according to Google). If you want opinions, you might try the SciPy or Numeric / numarray mailing lists -- no guarantee that anybody's heard of it, of course ;-) If you had a specific problem with Boost.Python, ask about that (the c++-sig list is probably the best place to ask -- search the archives first, though). John From eppstein at ics.uci.edu Wed Aug 6 14:27:16 2003 From: eppstein at ics.uci.edu (David Eppstein) Date: Wed, 06 Aug 2003 11:27:16 -0700 Subject: Stupid string.split question References: <3f314721$0$3936$b45e6eb0@senator-bedfellow.mit.edu> Message-ID: In article <3f314721$0$3936$b45e6eb0 at senator-bedfellow.mit.edu>, Brian Kelley wrote: > It seems that if you can join with an empty seperator, you should be > able to split with one. > > I suppose the pythonic way is [x for x in "ABCDEF"] which doesn't make > as much sense to be. Wouldn't list("ABCDEF") be even more Pythonic? -- David Eppstein http://www.ics.uci.edu/~eppstein/ Univ. of California, Irvine, School of Information & Computer Science From nicola-mingotti_NOSPAM at libero.it Sun Aug 3 18:42:06 2003 From: nicola-mingotti_NOSPAM at libero.it (Nicola Mingotti) Date: Mon, 04 Aug 2003 00:42:06 +0200 Subject: command -- It works , on linux References: Message-ID: On Sun, 03 Aug 2003 17:35:31 +0200, Nicola Mingotti wrote: > Hello , > >> ... John and Martin spoke of termcap and readline ... there it was :) ... I hadn't installed two C libraries that were needed : 'readline' and 'termcap' . After installing them i re-configured/compiled python and now commands history works fine . But under windows , where i have only the binary version at hands , the problem remains ... bye . Nico From sismex01 at hebmex.com Wed Aug 6 13:22:03 2003 From: sismex01 at hebmex.com (sismex01 at hebmex.com) Date: Wed, 6 Aug 2003 12:22:03 -0500 Subject: Tkinter programming problem Message-ID: sys.exit(x) kills the Python interpreter. Tkinter runs under the python interpreter. HTH. -gustavoAdvertencia:La informacion contenida en este mensaje es confidencial y restringida, por lo tanto esta destinada unicamente para el uso de la persona arriba indicada, se le notifica que esta prohibida la difusion de este mensaje. Si ha recibido este mensaje por error, o si hay problemas en la transmision, favor de comunicarse con el remitente. Gracias. From mpeuser at web.de Sat Aug 30 04:25:37 2003 From: mpeuser at web.de (Michael Peuser) Date: Sat, 30 Aug 2003 10:25:37 +0200 Subject: Best way to write a file n-bytes long References: <8d3e714e.0308261404.12045d96@posting.google.com> <87d6esxda2.fsf@vercingetorix.caesar.org> Message-ID: "Dialtone" schrieb im Newsbeitrag news:87d6esxda2.fsf at vercingetorix.caesar.org... > cappy2112 at yahoo.com (Tony C) writes: > [...] > > st="X" * 1048576 > > fh=open("junk","wb") > > fh.write(st) > > fh.close() > > For little files (less than 2 or 3 Mb I think) your code is the > fastest I can think of. But growing There is a new version which is a > lot faster All this is valid in a very limited scope only. - Consider limited RAM (lets say 128 MB) - you will be extremely slowed down by thrashing. - Consider on-the-fly compression (Windows NTFS): The 1000 MB testdate will be reduced to 1 Byte! Kindly Michael P From bokr at oz.net Sat Aug 2 21:24:02 2003 From: bokr at oz.net (Bengt Richter) Date: 3 Aug 2003 01:24:02 GMT Subject: How do I get a reference to a KEY value of a dictionary? References: <645db655.0307311636.71923378@posting.google.com> <0UXWa.416$_57.26378288@newssvr21.news.prodigy.com> Message-ID: On Sat, 02 Aug 2003 23:34:20 GMT, "Andy C" wrote: >> Google("intern-like memory saver"). > >Well, that seems very sensical, so how come it hasn't made it into the >language? And what's wrong with intern? (Though intern only works on >strings, not for immutable objects in general. I believe someone was asking >a pretty much identical question here, and someone replied with the >'memoize' pattern). > >Can this be done without C, now that you can subclass the built-in >dictionary? > For a subclass of dict that may be of interest, see my post in this thread timestamped less than 2 minutes before this post of yours ;-) Regards, Bengt Richter From mpeuser at web.de Wed Aug 13 04:12:10 2003 From: mpeuser at web.de (Michael Peuser) Date: Wed, 13 Aug 2003 10:12:10 +0200 Subject: drop down feature References: Message-ID: Hi Greg, I fully agree with your very comprehensive statements. I personally do not know VB so much but RealBasic for Macintosh which is absolutely in the line of useability. It is as well a very friendly GUI Builder with all drag-n-drop and multimedia stuff AND it compiles AND it makes self contained exe files!! This in fact is my wishlist for a Python IDE ..... Of course the *language* itself is mess ;-) I have the impression, that Wing IDE Standard Edition *could* have somthing in it, but not the "lite" version. I also like Active States KOMODO , but the professional version costs some hundred bucks as well. This is not acceptable. It's much too less for the money..... Kindly Michael P "Greg Brunet" schrieb im Newsbeitrag news:vjiu1aeknt8hd2 at corp.supernews.com... > Hi Michael: > > "Michael Peuser" wrote in message > news:bhbp0k$epd$07$1 at news.t-online.com... > > IDLE can help with its Class Browser feature. Although this not > > "automatic", it will help a lot > > when using site-packages or even your own old code ;-) > IDLE and many other GUI's do provide that & it is a definite help. Any > class library, whether Python's or some other language, simply has to be > learned. Hopefully, the designers were consistent and 'standard' in > their name choices to make things easier, and certainly once you begin > using a tool frequently it becomes easier. Even as good as a class > browser is, I've found that the Intellisense stuff is perhaps an order > of magnitude more helpful to me than the browser. Without having to > manually jump to another window/pane & lookup the class I'm interested > in, I have all of the properties & methods available as I finish typing > the variable, AND a link to the full help on the item by pressing F1 as > soon as I've selected it. > > > For the beginner, of course even properties (attributes and methods) > > of standard types are not > > obvious. I must say, that Python can really be a little bit cryptical > > (consider *get* oder *has_key* for > > directories ). I generally have to look it up, when *haskey* or *has* > > does not work ;-) > > > > But you can very well organize yourself with man pages.... > > > > The main problem seems to be that Python has no static typing. So it > > *generally* is not possible > > for an editor to know what type will dynamically be used. > And this is where, as disparagingly as people talk of VB, it does a good > job. Because it highly encourages (though can disable) static typing & > checking, it is able to know what the properties, methods, etc. are for > a variable. In reading a description of the WingIDE for Python, their > standard package tries to accomplish this by: "Infers class structure > and variable types based on real time analysis of Python source code." > I understand that Python for now & likely evermore will be dynamically > typed - hopefully the editors can get smarter about performing this > analysis to support the intellisense type operation. > > Problems increase especially with GUIs - I would be lost even in > > Tkinter without a paper reference ;-) > Also agreed. And one other thing that I've never seen matched (even the > 1.0 version of .NET wasn't as good) is the dynamic debugger in VB6. > When I've tried to debug code in IDLE or PythonWin or Boa, I frequently > end up at layers deeper in the class hierarchy than I wish to go (I > usually want to break at my code, but end up in some of the debugger > support code & have to navigate my way up/over to do anything). Also > the VB debugger would provide mouse-over information of any variables > (their value, etc.) displayed in the editor at the time the breakpoint > fires, along with an unbelievable ability to edit and continue running > the program. If someone could come up with an editor for Python with > the capabilities of the VB6 IDE, I'd certainly pay for that one. For > now, it seems that Boa is the closest thing to the mark in the open > source field. I've not evaluated the commercial editors sufficiently, > but from what I've read, there isn't anything out there yet that meets > that criteria. > > Kindly > > Michael Peuser > > Take care, > > -- > Greg > From newsgroups at jhrothjr.com Thu Aug 7 14:45:38 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Thu, 7 Aug 2003 14:45:38 -0400 Subject: filter()ing a dict References: <16469f07.0308070559.aed41a@posting.google.com> Message-ID: "Aahz" wrote in message news:bgtq00$p1e$1 at panix1.panix.com... > In article , > John Roth wrote: > > > >I'm surprised that what you tried worked at all. The 2.2.3 > >documentation on dictionaries doesn't suggest that a dictionary > >supports the iteration protocol, or what it returns in that context. > > Check the What's New doc on iterators. Why? I should think it's in the doc page in the regular manual. As several people have pointed out, it isn't there. John Roth > -- > Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ > > This is Python. We don't care much about theory, except where it intersects > with useful practice. --Aahz From dvorakv at idas.cz Wed Aug 6 19:20:53 2003 From: dvorakv at idas.cz (Vaclav Dvorak) Date: Thu, 07 Aug 2003 01:20:53 +0200 Subject: catching exceptions in expressions Message-ID: Hello, Sheilas and Bruces! I found myself writing something like this lately: try: a = int(s) except ValueError: a = 99 try: b = int(t) except ValueError: b = 99 try: c = int(u) except ValueError: c = 99 Not enough to make me want to create a function, but enough to be annoying. :-) I was thinking about something like this: a = int(s) except ValueError then 99 or a = int(s) or 99 if ValueError or even a different approach: try: a, b, c = int(s), int(t), int(u) except ValueError: retry with 99 or yet another: a, b, c = 99, 99, 99 try: a = int(s) b = int(t) c = int(u) except ValueError: continue [execution on next line - my comment] I like the first one the most. Imagine: lambda x: (A/x except NameError then 1/x) except ZeroDivisionError then 99 Catching exceptions in lambdas - how do you like that? :-) Comments? Should I write a PEP? Am I missing something obvious? Has this been debated a million times over already? Cheers, Vaclav Dvorak From andersjm at dancontrol.dk Wed Aug 20 09:31:49 2003 From: andersjm at dancontrol.dk (Anders J. Munch) Date: Wed, 20 Aug 2003 15:31:49 +0200 Subject: Why does this (not) work? References: Message-ID: <3f437890$0$21634$edfadb0f@dread11.news.tele.dk> "Cliff Wells" wrote: > Here's another approach: > > >>> def fjoin(sep, s, n): > ... return sep.join(["%s"] * n) % ((s,) * n) Better this: def fjoin(sep, s, n): return sep.join((s,)*n) Works even if sep contains a % character. >>> fjoin(' % ', "test", 3) 'test % test % test' - Anders From mpeuser at web.de Sat Aug 16 18:32:12 2003 From: mpeuser at web.de (Michael Peuser) Date: Sun, 17 Aug 2003 00:32:12 +0200 Subject: Some Results from Trying to Cheat py2exe Message-ID: Hi, I tried to reduce the size of some binary distribution in removing the things I could expect on the presumed targets - generally a minimal installation including Tcl/Tk. The results are as follows: (1) It does not seem possible to remove any *.pyd files: py2exe or whoever wants them in the local directory. sys.path seems not to be used. Even deleting it altogether has no impact at all. (2) sys.path, sys.exec_prefix and sys.prefix are set to the local directory, changes to them also have no visible effect. (3) Removing DLLs has been more successful. However it is a matter of PATH setting on the target, where they are found. This seems to be irrelevant for the interpreter, alas not for tcl and tk. (4) It seems that Tcl and Tk expect some support data in folders tcl8.3 and tk8.3 which are expected at ../lib (i.e. one back and in a folder called lib). This is generally NOT the situation in a standard Python installation (where they are in ..\tcl) nor is it the case in the local directory of py2exe (where they are in ./tcl). This is something I do not understand! (5) Thus if the DLLs are found in a standard Python installation, it will fail. It is generally not possible to make a safe setup because of uncontrollable PATH settings..... (6) Those Tcl/Tk folders are quite large, mostly because of some asiatic unicode files. Those can safely be deleted I think. Conclusion: For distributions to customers without Python and unwilling to do any system changes it would be safest to fill some PYAPP folder with tcl/tk, the tcl folder and interpreter and maybe wxms24h DLLs. Than just drop your installations into that folder. This can safely be done when un-zipping them. The drawback is that there is no strcture at all inside that folder. The second best solution would be to put that PYAPP folder anywhere (however the structure must be changed, because of (4): PYAPP has to contain a DLL directory and the LIB directory for the tcl/tk folders. the PATH setting must be done to PYAPP/LIB. Now a reduced distribution can be put anywhere. This has some advantages from the point of configuration control, however is bound to break if the user decides to install a full Python. The situation is a mess and it took me some time to sort out all the problems (help came from Thomas Heller). So may be it will help someone - and be it to keep hands off ;-) Kindly Michael P From Madiba at 37.com Mon Aug 11 13:39:09 2003 From: Madiba at 37.com (Madiba) Date: Mon, 11 Aug 2003 19:39:09 +0200 Subject: Python and Code Completion Message-ID: <3f37d456$0$228@hades.is.co.za> I noticed that ide's such as activestates visual python have a certain amount of code completion options, and i would love to implement something similiar in my own ide. eg when u type aclass().[dropdown with all methods here] also Idle has some of these functions,as well as displaying 'hints' eg when u type range([show hint here] (but idle sourcecode is to big for me try and figure out how it is done..) Can anybody please give me some pointers on how to get the available properties/documentation to a class etc without actually excecuting the code. Do i have to write my own semi-parser? I know help('class') displays doc and methods and automatically imports class, so is there maybe something similar to use? any ideas? From bgailer at alum.rpi.edu Mon Aug 25 17:21:49 2003 From: bgailer at alum.rpi.edu (Bob Gailer) Date: Mon, 25 Aug 2003 15:21:49 -0600 Subject: Strange tab problem! In-Reply-To: <1799.68.75.130.96.1061781479.squirrel@webmail.iserv.net> Message-ID: <5.2.1.1.0.20030825151658.032d2d98@66.28.54.253> At 11:17 PM 8/24/2003 -0400, tjland at iserv.net wrote: >Okay i wrote a small program that allows users to creat book listings >featuring copyright date author and title. Now when i display the book >listings i get this. > >Book: testover6 Author: ??? Copyright: 2003 >Book: testu6 Author: ??? Copyright: 2003 > >Okay now after the book title their is supposed to a tab the coding goes >like this. > >for x in title_author.keys(): > print "Book: ",x," \tAuthor: ",title_author[x]," >\tCopyright:",title_copyright[x] > >it seems that whenever i go over six characters it adds another tab. Is >there a preset field limit to six bytes. What is happening? Others have told you what's happening. I think the best solution is to use % formatting: "Book: %12s Author: %12s Copyright: %4s" % (title, author, copyright) This will give you a string with the %..s replaced with the corresponding value from the tuple, right aligned by 12 and 4. Example: "Book: %12s Author: %12s Copyright: %4s" % ("Red Fire", "Jones", 2003) results in 'Book: Red Fire Author: Jones Copyright: 2003' Bob Gailer bgailer at alum.rpi.edu 303 442 2625 -------------- next part -------------- --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.506 / Virus Database: 303 - Release Date: 8/1/2003 From jjl at pobox.com Tue Aug 19 18:38:13 2003 From: jjl at pobox.com (John J. Lee) Date: 19 Aug 2003 23:38:13 +0100 Subject: What's better about Ruby than Python? References: <3F40892D.AEF4AAE@alcyone.com> <87isov6pk4.fsf@pobox.com> <3F412081.5EF7279C@alcyone.com> <874r0ey9bx.fsf@pobox.com> Message-ID: <87brulnui2.fsf@pobox.com> Nick Vargish writes: > jjl at pobox.com (John J. Lee) writes: > > > read everything slowly, chew the cud, *then* start writing. I read > > the whole of Stroustrup and a couple of other books before writing a > > I couldn't get past the first chapter of Stroustrup... Maybe because > I'd already been working with C++, it read like a pile of > justifications for what I consider a bastardization of an elegant > foundation. (So, I like C but dislike C++, what can I say?) I agree. In C++, where you see a book section heading like "Feature X, Feature Y and Feature Z", it means that X, Y and Z have some horrendous interactions that you have to commit to memory. In Python, it means that X, Y and Z are so simple they all fit in one section ;-) I do wonder if the tight constraint on C++ of being C+extra bits was ever really justified. John From mpeuser at web.de Sat Aug 16 03:18:37 2003 From: mpeuser at web.de (Michael Peuser) Date: Sat, 16 Aug 2003 09:18:37 +0200 Subject: GUI builder for Python References: <3F3DC73C.3ADD3980@easystreet.com> Message-ID: schrieb im Newsbeitrag news:3F3DC73C.3ADD3980 at easystreet.com... > dan wrote: > > > > > > Been wondering myself. How is http://sourceforge.net/projects/wxworkshop/? > > > > this looks nice and it's free. > > > I'm wondoering about Visual Wx. This looks like someone put much > work into it, but I haven't been able to get it to do anything. > This is probablyt because I can't find any documentation in English > that tells how to get it to do anything. > > > Al Well try it out then - a little bit English is in it ;-) http://visualwx.altervista.org/indexen.htm Attention: a lot of spam pop-up adds! Kindly Mchael P From vanevery at 3DProgrammer.com Tue Aug 19 02:26:21 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Mon, 18 Aug 2003 23:26:21 -0700 Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> <87brumwowx.fsf@pobox.com> Message-ID: > Well, art is art, isn't it? Still, on the other hand, water is water! > And east is east and west is west and if you take cranberries and stew > them like applesauce they taste much more like prunes than rhubarb > does. > > Groucho Marx. I almost got it. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From graham__fawcett at hotmail.com Tue Aug 12 09:47:23 2003 From: graham__fawcett at hotmail.com (Graham Fawcett) Date: 12 Aug 2003 06:47:23 -0700 Subject: Slogan: Getting Rich Overnight References: Message-ID: "Tim Peters" wrote in message news:... > [Graham Fawcett] > >>> "Python: stimulate powerful organisms under your fingertips, without > >>> all the GUI mess!" > > [Brandon J. Van Every] > >> "Organisms" is easily misread as "orgasms." > > [Graham] > > ...and GUI is a homonym of "gooey". Was my joke too obscure? > > > > i-thought-it-was-funny-in-context-ly yours, > > Barry Warsaw and Fred Drake and I laughed long and hard when we saw it this > afternoon. I confess we questioned your sanity, but we're all keen to adopt > it as the Official Motto of the next PyCon! > > we're-gonna-get-soooooooo-rich-from-the-t-shirt-sales-ly y'rs - tim Thanks. I'd attend *just* to buy the t-shirt! ...ahh, PyCon, where birds of a feather get flocked together... stopping-while-I'm-ahead-ly yours, -- Graham From tchur at optushome.com.au Fri Aug 29 14:54:08 2003 From: tchur at optushome.com.au (Tim Churches) Date: 30 Aug 2003 04:54:08 +1000 Subject: Celebrity advice In-Reply-To: <1062150627.7273.26.camel@devilbox.homelinux.net> References: <000701c36ce7$a6ff24d0$0c02a8c0@Arts> <1062150627.7273.26.camel@devilbox.homelinux.net> Message-ID: <1062183248.1189.26.camel@emilio> On Fri, 2003-08-29 at 19:50, Cliff Wells wrote: > On Wed, 2003-08-27 at 15:07, Arthur wrote: > > > We all knew this kind of discussion would lead to no good. Even to my own > > eventual involvment. But the rule I had set to myself, would be to comment > > only upon Lulu's comment, and only if that comment was something other than > > to the effect that one's politics might be irrelevent here, and that the > > advice to a new programmer to eschew Raymond because of his was .. bad > > advice. > > I'd have to agree with Art on this. ESR's thoughts on guns have little > to do with programming, and unless he likes to use "nra" or "bullet" as > metavariables, his politics would best be omitted from the discussion. > Had Hitler (note end of thread) rather than Einstein written > _Relativity_ would we expect physicists to ignore it because of his > politics? I certainly hope not. The original question was what programming/comp sci literature would one suggest a junior high school student (early teens) read? I opined that ESR was not a good suggestion in such circumstances because he intertwines his (initially engaging) essays on computerdom with a much broader and arguably whacky right-wing libertarianism which promotes gun ownership and use. As Lulu says, bang, bang! If Einstein had written _Mein Kampf_, then, no, I would not send a 12-14 yr old who is interested in physics off to the library to read Einstein's work... > The fact that I think Charlton Heston is a buffoon shouldn't be the > reason I think his movies suck. Surely you make an exception for _Omega Man_ - especially that scene at the end when he is hung on the cross (in a fountain), dying, but his serum saves the world... -- Tim C PGP/GnuPG Key 1024D/EAF993D0 available from keyservers everywhere or at http://members.optushome.com.au/tchur/pubkey.asc Key fingerprint = 8C22 BF76 33BA B3B5 1D5B EB37 7891 46A9 EAF9 93D0 -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 196 bytes Desc: This is a digitally signed message part URL: From steve at ferg.org Mon Aug 4 08:42:47 2003 From: steve at ferg.org (Stephen Ferg) Date: 4 Aug 2003 05:42:47 -0700 Subject: Beginner's popups in vanilla Python program References: Message-ID: Look at EasyGui: http://www.ferg.org/easygui/ Here's what your program would look like: ============================================================== # Program: Beginners_Popups.py ... "Hello World" for popups from easygui import * print "Begin program" # Prepare the basic programmatic messages strMess1 = "Is this a Test?" strTitle1 = "Test Query" strResponse = "You selected " strTitle2 = "Response:" boolVar = boolbox(strMess1, strTitle1, ["Yes", "No"]) # Build the appropriate response if boolVar: strResponse += "YES" else: strResponse += "NO" msgbox(strResponse, strTitle2) # button is OK boolbox(strResponse, strTitle2, ["Close"]) # button is Close print "End of Program" From mwh at python.net Wed Aug 6 08:00:19 2003 From: mwh at python.net (Michael Hudson) Date: Wed, 6 Aug 2003 12:00:19 GMT Subject: Isn't there a substring(start, end)-function???? References: Message-ID: <7h3r83z6lpr.fsf@pc150.maths.bris.ac.uk> davidhe at email.com (Dave) writes: > Hi all, > > Am I blind, or what? I can't find any quick way to do the following in > Python: > > substring(beginIndex, endIndex) witch returns the substring between > beginIndex and endIndex. > > Like: > text = "If someone attacks you with a banana" > print text.substring(0,3) > Should print "If " > > I've found absolutely everything else that I expect from a modern > programming language, but none of the modules (not even "string"!) > seems to have what I'm looking for. > > Please tell me I'm blind! Well, you're just not looking in the right place: >>> text = "If someone attacks you with a banana" >>> text[0:3] 'If ' I'm pretty sure this is in the tutorial -- the key word you're looking for is "slice". Cheers, mwh -- [2. More type system hacking --- text/plain; type-argh.diff] -- csr on sbcl-devel From bokr at oz.net Sun Aug 3 01:17:40 2003 From: bokr at oz.net (Bengt Richter) Date: 3 Aug 2003 05:17:40 GMT Subject: Dict to "flat" list of (key,value) References: <3f2c54f6.11554794@news.lexicon.net> Message-ID: On Sun, 03 Aug 2003 00:28:53 GMT, sjmachin at lexicon.net (John Machin) wrote: >On Sat, 02 Aug 2003 12:41:19 GMT, "Raymond Hettinger" > wrote: > > >>it-all-starts-with-a-good-data-structure-ly yours, > >Amen, brother. > >Even worse: I recall seeing code somewhere that had a data structure >like this: > >{k1: [v1,v2], k2: v3, k3: None, ...} >instead of >{k1: [v1,v2], k2: [v3], k3: [], ...} > Page 1 >I liked the elegant code example for building a book index. However in >practice the user requirement would be not to have duplicated page >numbers when a word occurs more than once on the same page. If you can >achieve that elegantly, please post it! > Page 2 Don't know about elegance, but I wanted to play with my new 2.3 version ;-) Assuming the Timbot has special-cased small sets efficiently, and assuming pageSeq below is a generator can yield a sequence of word-iterable page objects (e.g. lists of words left after cleaning out punctuation etc of a page, however page boundaries are detected, etc etc): (FTHOI, the following pageSeq generator expects to find a "Page xxx" line ending each page, with nothing else on the line). I'm going to use this post as a "book" ;-) Page 3 ====< bookindex.py >================================================= keepalnum = ''.join([c.isalnum() and c or ' ' for c in [chr(i) for i in range(256)]]) def pageSeq(bookFile): # expect open bookFile ready to read pageWords = [] pageId = '' while 1: line = bookFile.readline() if not line: break lineToks = line.translate(keepalnum).split() if not lineToks: continue # expect single footer line with only "Page pgid" at end of page if len(lineToks)==2 and lineToks[0]=='Page': pageId = lineToks[1] yield pageId, pageWords pageWords = []; pageId = '(after %s)'% pageId else: pageWords.extend([tok for tok in lineToks if tok.isalpha()]) # rej digits in words if pageWords: yield pageId, pageWords def bookIndex(bookFile): # (untested, requires 2.3 features) from sets import Set wordIndex = {} for pgId, page in pageSeq(bookFile): for word in page: try: wordIndex[word].add(pgId) except KeyError: wordIndex[word] = Set([pgId]) words = wordIndex.keys() words.sort() for word in words: pageIds = list(wordIndex[word]) pnMaxWidth = max(map(len,pageIds)) pageIds = [pid.rjust(pnMaxWidth) for pid in pageIds] pageIds.sort() pageIds = map(str.strip, pageIds) yield (word, ', '.join(pageIds)) if __name__ == '__main__': import sys args = sys.argv[1:] if args: arg = args.pop(0) if arg == '-': f = sys.stdin else: f = file(arg) iCol=0 for wordOccLine in bookIndex(f): print ('%14s: %-10s' % wordOccLine), if iCol%3 == 2: print iCol += 1 print else: raise SystemExit( 'Usage: python bookindex.py bookfilepath\n' ' a single minus for bookfilepath uses sys.stdin') ===================================================================== Page CODE I started to post just the bookIndex generator (still marked untested, which is almost right still ;-) Then one think led to another ;-) Page LAST I'll copy above this line to the clip board and filter it through. Result: [22:22] C:\pywk\clp>getclip | python bookindex.py - |more Amen: 1 Assuming: 3 Aug: 1 Don: 3 Even: 1 FTHOI: 3 GMT: 1 Hettinger: 1 However: 2 I: 1, 2, 3, LAST If: 2 John: 1 KeyError: CODE Machin: 1 None: 1 On: 1 Page: 3, CODE Raymond: 1 Sat: 1 Set: CODE Sun: 1 SystemExit: CODE Then: LAST Timbot: 3 Usage: CODE a: 1, 2, 3, CODE about: 3 achieve: 2 add: CODE after: 3, CODE all: 1 almost: LAST and: 3, CODE another: LAST are: 3 arg: CODE args: CODE argv: CODE as: 3 assuming: 3 at: CODE be: 2 below: 3 book: 2, 3 bookFile: CODE bookIndex: CODE, LAST bookfilepath: CODE bookindex: CODE boundaries: 3 break: CODE brother: 1 building: 2 but: 3 c: CODE can: 2, 3 cased: 3 chr: CODE cleaning: 3 code: 1, 2 continue: CODE data: 1 def: CODE detected: 3 digits: CODE duplicated: 2 e: 3 each: 3 efficiently: 3 elegance: 3 elegant: 2 elegantly: 2 else: 3, CODE end: CODE ending: 3 etc: 3 example: 2 except: CODE expect: CODE expects: 3 extend: CODE f: CODE features: CODE file: CODE find: 3 following: 3 footer: CODE for: 2, CODE from: CODE g: 3 generator: 3, LAST going: 3 good: 1 had: 1 has: 3 have: 2 however: 3 i: CODE iCol: CODE if: CODE import: CODE in: 2, CODE index: 2 instead: 1 is: 3, LAST isalnum: CODE isalpha: CODE it: 1, 2 iterable: 3 join: CODE just: LAST keepalnum: CODE keys: CODE know: 3 led: LAST left: 3 len: CODE lexicon: 1 like: 1 liked: 2 line: 3, CODE lineToks: CODE list: CODE lists: 3 ly: 1 m: 3 main: CODE map: CODE marked: LAST max: CODE minus: CODE more: 2 my: 3 n: CODE name: CODE net: 1 new: 3 not: 2, CODE nothing: 3 numbers: 2 objects: 3 occurs: 2 of: 1, 3, CODE on: 2, 3 once: 2 one: LAST only: CODE open: CODE or: CODE out: 3 page: 2, 3, CODE pageId: CODE pageIds: CODE pageSeq: 3, CODE pageWords: CODE pgId: CODE pgid: CODE pid: CODE play: 3 please: 2 pnMaxWidth: CODE pop: CODE post: 2, 3, LAST practice: 2 print: CODE prologue: CODE punctuation: 3 py: CODE python: CODE raise: CODE range: CODE read: CODE readline: CODE ready: CODE recall: 1 rej: CODE requirement: 2 requires: CODE right: LAST rjust: CODE s: CODE same: 2 seeing: 1 sequence: 3 sets: 3, CODE single: CODE sjmachin: 1 small: 3 somewhere: 1 sort: CODE special: 3 split: CODE started: LAST starts: 1 stdin: CODE still: LAST str: CODE strip: CODE structure: 1 sys: CODE t: 3 than: 2 that: 1, 2 the: 2, 3, LAST think: LAST this: 1, 3 to: 2, 3, CODE, LAST tok: CODE translate: CODE try: CODE untested: CODE, LAST use: 3 user: 2 uses: CODE verizon: 1 version: 3 wanted: 3 when: 2 which: LAST while: CODE with: 1, 3, CODE word: 2, 3, CODE wordIndex: CODE wordOccLine: CODE words: 3, CODE worse: 1 would: 2 wrote: 1 xxx: 3 yield: 3, CODE you: 2 yours: 1 Regards, Bengt Richter From gandreas at no.reply Fri Aug 22 13:50:01 2003 From: gandreas at no.reply (Glenn Andreas) Date: Fri, 22 Aug 2003 12:50:01 -0500 Subject: GUI IDE for Macintosh? References: Message-ID: In article , "Leo" wrote: > hi there > > i'm looking for a GUI Building IDE for Python Development running on a mac > under OS X. > InterfaceBuilder + PyObjC Granted, it is two separate things (so not _exactly_ an IDE), but being able to use pretty much all of Cocoa for a UI is really quite powerful. Hopefully a future release of my PyOXIDE will make it even easier to write/test/deploy such apps. From vze4rx4y at verizon.net Fri Aug 8 19:50:23 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Fri, 08 Aug 2003 23:50:23 GMT Subject: should property() fail if not used on new style classes? References: Message-ID: <3HWYa.558$Z37.73@nwrdny03.gnilink.net> "Kevin Altis" > Now here is the same example, but the C class no longer subclasses object. > > >>> class C: > ... def getx(self): return self.__x > ... def setx(self, value): self.__x = value * 2 > ... x = property(getx, setx) > ... > >>> b = C() Before going further, try this: print b.x You'll see that the property() assignment *did* work. > >>> b.x = 5 > >>> b.x > 5 > > If getx and setx aren't going to get bound shouldn't property fail in a more > visible way? Is something else going on that I'm missing?! What is missing is that there is no property failure. getx() and setx() *are* bound to the property object which is in-turn bound to 'x'. The reason you don't see it working is that all of the magic occurs in the __getattribute__ method of new style objects which do special checking to see if a looked-up object is a descriptor. It would be great if old-style classes could also check looked-up values to see if they were descriptors and issue an appropriate warning. Unfortunately, I don't see any way of doing this without unnecessarily impacting performance and affecting backward compatability. The root of the problem is that the descriptors can be dynamically created: class C: pass # Valid statements that can occur after the class definition def getx(self): return self.__x def setx(self, value): self.__x = value * 2 C.x = property(getx, setx) In contrast, it would be much more reasonable to have old style classes warn about the use of __slots__. Raymond Hettinger From redrumjack at hotmail.com Thu Aug 28 12:33:20 2003 From: redrumjack at hotmail.com (Jesse) Date: Thu, 28 Aug 2003 16:33:20 GMT Subject: Windows Remote Log in In-Reply-To: References: Message-ID: Tim Golden wrote: > [TJG: I've slightly rearranged the posts so they read top-to-bottom] > > >>From: Jesse [mailto:redrumjack at hotmail.com] >> >>I guess it is how can I have a user enter their NT Domain Authentication >>and the script use it to log into NT Domains the computer it is running >>on it not a member of. > > >>From Tim: >> >>I suggest you have a look at WMI. >>Try using it without any particular security qualifiers >>first; if you really need an explicit log on (you probably >>won't if you're a Domain Admin and using your own or a >>trusted domain) then you can specify an explicit wmi >>moniker in the constructor. >>TJG > > >>From Jesse: >>This is a mixture of NT 4 and Win2K Servers. >>WMI may not be installed on all the remote systems. > > > Does that mean it could not be? It's available for both (and > is, I think, there by default on Win2K). Maybe there are > political reasons or fears for stability of long-running > NT4 servers? We have that problem here. > > >>We have quite a few NT domains that our servers are spread out over and >>sometimes the machine I would execute the script from would not be in >>the same Domain and need different Logon Credentials to access the >>remote machine. > > > Understood. > > >>Often certian services for the applications we maintain will need to be >>restarted on these remote machines. I've found a way to this this with >>a Python Module called WService. > > > I've not come across this module; is it one you've written yourself? > Or could you give a URL where it could be found? Assuming, in any case, > that it's based on Mark Hammond's win32service, a quick browse of the docs > for that suggest that, although you can control services on other machines, > there's no way of authenticating yourself in the process. > > Here, I think, WMI would probably serve you best, because it does > allow explicit domain-credential logons (in a slightly roundabout way), > and once you're in, stopping and starting services is a snap. Having > said that, getting the combination of local security and remote > credentials right is a bit of a pain. Judging by past threads, I > think other people on this list have more experience of that than I. > > Maybe something like this would suit: > > > > import win32com.client > import wmi > > def list_services (machine, username, password): > locator = win32com.client.Dispatch ("WbemScripting.SWbemLocator") > remote_wmi = locator.ConnectServer (machine, "", username, password) > remote_machine = wmi.WMI (wmi=remote_wmi) > # > # This just lists all services; obviously it > # could stop, or start, or delete or whatever. > # > for s in remote_machine.Win32_Service (): > print s.Caption, s.State > > > > TJG > > ________________________________________________________________________ > This e-mail has been scanned for all viruses by Star Internet. The > service is powered by MessageLabs. For more information on a proactive > anti-virus service working around the clock, around the globe, visit: > http://www.star.net.uk > ________________________________________________________________________ > The WService is here http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/115875 I don't believe that all of the NT 4 servers have WMI but I can check that. The previous version of the application we had would crap out if WMI was running (I don't know why but we saw it happen) But we've since then upgraded. I'll continue messing around. I really appreciate all the help I'm kinda diving in head first here and learning as I go. I try to find an answer online if I can but for this I coudn't. Most of my prior programming experience was Batch Files LOL :) From peter at engcorp.com Wed Aug 13 22:10:32 2003 From: peter at engcorp.com (Peter Hansen) Date: Wed, 13 Aug 2003 22:10:32 -0400 Subject: Determine file type (binary or text) References: Message-ID: <3F3AEF98.2259DFF0@engcorp.com> John Machin wrote: > > Trent Mick wrote in message news:... > > > Generally I define a text file as "it has no null bytes". I think this > > is a pretty safe definition (I would be interested to hear practical > > experience to the contrary). > > Data file written by C program which has an off-by-one error and is > including a trailing '\0' byte ... To be fair, I'd call that a "binary" file in any case, or at least a defective text file... From rmunn at pobox.com Tue Aug 12 17:19:25 2003 From: rmunn at pobox.com (Robin Munn) Date: Tue, 12 Aug 2003 21:19:25 GMT Subject: Problem with computing...addition References: Message-ID: Lukas Kasprowicz wrote: [snip] > > So you see e.g. the 15th entry: "131.99000000000001" > > there should be "131.99" and not this. This is a frequently-asked question. See: http://www.python.org/cgi-bin/faqw.py?req=show&file=faq04.098.htp and http://www.python.org/doc/current/tut/node14.html for more details. The short version is that that's how computers handle floating-point numbers and you should get used to it. Simply display two digits after the decimal point when you print out the numbers. If it really bothers you, consider doing something like: cents = int(euros*100) And then when you want to print: print "%d.%d" % (cents//100, cents%100) -- Robin Munn | http://www.rmunn.com/ | PGP key 0x6AFB6838 -----------------------------+-----------------------+---------------------- "Remember, when it comes to commercial TV, the program is not the product. YOU are the product, and the advertiser is the customer." - Mark W. Schumann From sabu at pure-elite.org Wed Aug 6 20:56:39 2003 From: sabu at pure-elite.org (Xavier) Date: Wed, 6 Aug 2003 14:56:39 -1000 (HST) Subject: dl + getenv (without arguments) = segfault (python2.p2, python2.3) Message-ID: <39929.24.199.120.198.1060217799.squirrel@mail.darkscape.net> Skip, Yes -- that seems somewhat obvious, thanks for the observation though. I fully comprehend the responsibilities of the programmer in a situation where he or she or it would invoke the 'dl' module. Do note that my previous e-mail was not implying my possible ignorance to the 'dl' module's functionality, but instead inquiring wether there is or may be a solution in the future for Python to handle such an erronous outcome. And plus, segfaults are ugly and make me cry. -- Xavier. From logiplex at qwest.net Tue Aug 12 18:29:40 2003 From: logiplex at qwest.net (Cliff Wells) Date: Tue, 12 Aug 2003 15:29:40 -0700 Subject: Python vs. C# In-Reply-To: <20E0F651F8B82F45ABCBACC58A2D995B0518B8@mexper1> References: <20E0F651F8B82F45ABCBACC58A2D995B0518B8@mexper1> Message-ID: <1060727379.4769.84.camel@software1.logiplex.internal> On Sun, 2003-08-10 at 18:38, Simon Wittber (Maptek) wrote: > >I'm starting to think that you are trolling. Are you? > > Hi Brian, > > You should never insinuate that Brandon is a troll, unless you are > prepared to have your address appended to the end of his 100MB killfile. Is that something to be feared? Does he actually kill any of those people or is it more of a "they'll be sorry when I'm gone" sort of thing? Regards, -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 (800) 735-0555 From aleaxit at yahoo.com Sun Aug 17 09:15:11 2003 From: aleaxit at yahoo.com (Alex Martelli) Date: Sun, 17 Aug 2003 15:15:11 +0200 Subject: ``Type-checking'' with dir() References: <70df36e9.0308161136.3c414a80@posting.google.com> <6rx%a.547$Ck2.471@nwrdny03.gnilink.net> Message-ID: Raymond Hettinger wrote: ... > The code becomes especially clean if you use the sets module: > > if not Set(["__getslice__", "__len__"]) < Set(dir(a)): > raise InterfaceError(a) I think you want a <= here -- otherwise, an InterfaceError would be raised in the (unlikely, sure;-) case in which dir(a) has ONLY the __len__ and __getslice__ entries. (BTW, of course: __getslice__ is obsolete, and properly substituted by __getitem__ taking a slice object as an 'index' in today's well-implemented sequences -- so, this is not a good example [not Raymond's fault, of course, as it was what the OP used]). Alex From rupole at hotmail.com Thu Aug 28 22:38:13 2003 From: rupole at hotmail.com (Roger Upole) Date: Thu, 28 Aug 2003 19:38:13 -0700 Subject: win32 file attributes References: Message-ID: <3f4e8e71_1@127.0.0.1> The corresponding api call would be GetFileVersionInfo. As far as I know, nobody has wrapped it for Python yet, probably because it looks to be fairly painful. Roger "David Bear" wrote in message news:m3wucxo1te.fsf at moroni.pp.asu.edu... > Using the windows explorer it is possible to get file properties which > include under the version tab, 'company name', 'version', etc. I'm > assuming these metadata are actually stored in the exe somewhere. Is > there an api exposed to python that would allow me to get this info? > > a scan of Mark Hammonds win32all package did have anything obvious > jump out at me... > > -- > David Bear > phone: 480-965-8257 > fax: 480-965-9189 > College of Public Programs/ASU > Wilson Hall 232 > Tempe, AZ 85287-0803 > "Beware the IP portfolio, everyone will be suspect of trespassing" From max at alcyone.com Tue Aug 26 03:12:09 2003 From: max at alcyone.com (Erik Max Francis) Date: Tue, 26 Aug 2003 00:12:09 -0700 Subject: bool and unicode References: Message-ID: <3F4B0849.EA6B3644@alcyone.com> Roman Yakovenko wrote: > Hi. > > >>> bool( u'True' ) > True > >>> bool( u'False' ) > True > >>> > > May somebody explain or give a reference to reason of such behaviour? Does this give you a hint? >>> bool('True') True >>> bool('False') True >>> bool('') False The only string, Unicode or not, considered to be false is the null string. All other strings are true, even if they spell the word _false_. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ Procrastination is the thief of time. \__/ Edward Young From tim.one at comcast.net Sun Aug 31 19:13:23 2003 From: tim.one at comcast.net (Tim Peters) Date: Sun, 31 Aug 2003 19:13:23 -0400 Subject: Win32 documentation in CHM? In-Reply-To: <3f5262ea$0$1667$e4fe514c@dreader3.news.xs4all.nl> Message-ID: [Iwan van der Kleyn] > Great initiative. Are there any compiled CHM files available for 2.3, > perhaps from other sources then PythonLabs? You can visit my elaborate home page : http://home.comcast.net/~tim.one/ From morebeans at hotmail.com Fri Aug 1 17:51:07 2003 From: morebeans at hotmail.com (Glenn) Date: 1 Aug 2003 14:51:07 -0700 Subject: win32ras - compatibility across Win32 versions? Message-ID: <91179b65.0308011351.6108ae9d@posting.google.com> Hi there. Having done some Googling, it appears "win32ras" may be exactly what I'm looking for - but only if it can create connectoids/phone book entries on all desktop Win32 versions (Win9x - WinXP). I found a couple of posts from 2001 about it possibly working on win9x, but I couldn't see anything since that time. Does it do what I need it to? Also, I'm pretty new to Python, so forgive me if this is an obvious question, but where would I find some example scripts/resources for win32ras? Thanks, Glenn From mike-nospam at skew.org Fri Aug 22 13:10:40 2003 From: mike-nospam at skew.org (Mike Brown) Date: Fri, 22 Aug 2003 17:10:40 GMT Subject: Newbie problem with codecs References: <1R01b.1724$Ej6.454@newsread4.news.pas.earthlink.net> Message-ID: "derek / nul" wrote in message news:mkabkvkguslj36n1qd1gsot8hbvh5qm321 at 4ax.com... > On Thu, 21 Aug 2003 10:06:53 GMT, "Andrew Dalke" wrote: > > >Still, this might help. Suppose you wanted to read from a utf-16-le > >encoded file and write to a utf-8 encoded file. You can do > > Very close, I want to read a utf16le into memory, convert to text, change 100 > lines in the file, convert back to utf16le and write back to disk. > > >The other options is to do the conversion through strings > >instead of through files. > > > ># s = "....some set of bytes with your utf-16 in it .." > >s = open("input.utf16", "rb").read() # the whole file > > > ># convert to unicode, given the encoding > >t = unicode(s, "utf-16-le") > > > ># convert to utf-8 encoding > >s2 = t.encode("utf-8") > > > >open("output.utf8", "rb").write(s2) > > My code so far > ------------------------------------------- > import codecs > codecs.lookup("utf-16-le") > eng_file = open("c:/program files/microsoft games/train > simulator/trains/trainset/dash9/dash9.eng", "rb").read() # read the whole file > > t = unicode(eng_file, "utf-16-le") > print t > ----------------------------------------------------- > > The print fails (as expected) with a non printing char '\ufeff' which is of > course the BOM. > Is there a nice way to strip off the BOM? "derek / nul" wrote: > I need a pointer to converting utf-16-le to text If there is a BOM, then it is not UTF-16LE; it is UTF-16. From fortepianissimo at yahoo.com.tw Thu Aug 14 14:37:26 2003 From: fortepianissimo at yahoo.com.tw (Fortepianissimo) Date: 14 Aug 2003 11:37:26 -0700 Subject: Recommendation of a parser generator References: Message-ID: Hi Andrew (and others who replied) - thanks for the extensive tip. However I ended up in using Simpleparse, cuz (1) I read from Charming Python column that SPARK is *very* slow (it uses Earley algorithm) (2) Simpleparse turns out to be not that outdated - the latest one (2.0, in alpha) was released in 2002. I've since finished my implementation in simpleparse, and felt quite satisfied with the setup. The only thing I found a bit lacking is the documentation - the tutorials on their site are very helpful to get me up and running, but for the other details I had to peek through the source. Hope this also helps others in deciding which parser geerator to use (at least for formula-like texts). "Andrew Dalke" wrote in message news:... > Fortepianissimo: > > I'm about to start a new project which will be mostly written in > > Python. The first task is to parse some formula-like expressions into > > an internal data structure so they can be evaluated. > > How close is this formula language to Python's? For other projects > I've punted the heavy work to Python's own parser, then filled in > the bits I needed. For example, suppose you have the expression > > a.b + c + s.find('d') > > >>> import compiler > >>> from compiler import visitor > >>> s = "a.b + c + s.find('d')" > >>> class GetNames(visitor.ASTVisitor): > ... def __init__(self): > ... self.names = {} > ... def visitName(self, obj): > ... self.names[obj.name] = 1 > ... > > >>> a = compiler.parse(s) > >>> names = compiler.walk(a, GetNames()).names.keys() > >>> names > ['a', 'c', 's'] > >>> > > Then get the values for a, c, and s, put them into a dict, and > > >>> class A: > ... b = 5 > ... > >>> eval(s, {"a": A, "c": 3, "s": ""}) > 7 > >>> > > (Assuming I didn't make any mistakes - it's modified from an earlier > exchange Alex and I had in c.l.py, titled "classes derived from dict > and eval" and I didn't test all the changes.) > > Failing that, I've been happy with SPARK as a parser generator, > but as you read in the paper, it's slow compared to the other parsers > that were benchmarked. > > > This parser would be run extensively in the future, so speed is a > > consideration, > > Why is the parser performance the problem? Most of the time > is spent evaluating the result, right? That's post-parsing. > > The only time to worry about parsing performance is if you have a > lot of different expressions coming in. Otherwise, just cache the > results, as Python does with .pyc files. > > > I'd appreciate very much some expert suggestions from the group, like > > on the speed, flexibility, portability, and the future prospect (like > > to be adopted as the standard etc.). > > I too would like a standard parser generator for Python. I don't know > the status of that activity. As it is, SPARK is small enough that it's > easy for me to include in my projects. > > Andrew > dalke at dalkescientific.com From ialbert at mailblocks.com Sun Aug 31 14:27:40 2003 From: ialbert at mailblocks.com (Istvan Albert) Date: Sun, 31 Aug 2003 14:27:40 -0400 Subject: artificial intelligence? In-Reply-To: References: Message-ID: <7ZCdnQAI0aeAo8-iU-KYuA@giganews.com> Arthur wrote: > """ > Dear Amazon.com Customer, > > We've noticed that customers who have purchased books by Mark Lutz often > enjoy the books of Sedi 200. So you might like to know that Sedi 200's > newest book, Earth's Core and Lower Mantle (Fluid Mechanics of Astrophysics > and Geophysics, V.11), > > """ > > Sure read my mind, didn't they? > > Any theories on how the Amazon.com AI machine got this far off track? The way I interpret this is that your tastes are similar to those of "Sedi 200". This user's latest purchase was a geophysics books. Discovering so called "serendipitous" items, items that cannot be related with classical methods (say content or author) yet are very desirable to the consumer is the holy grail of personalization. As the example above shows it can go totally gaga. Istvan. From fractal97 at comcast.com Sat Aug 2 03:37:06 2003 From: fractal97 at comcast.com (Vin Jovanovic) Date: Sat, 2 Aug 2003 03:37:06 -0400 Subject: Python 2.3 IDLE doesn't show on Win2000 Message-ID: Trying to start Python IDLE through Start>Programs>Python 2.3> IDLE doesn't work >From DOS ... I get this .... C:\>python C:\Python23\Lib\idlelib\idle.py Traceback (most recent call last): File "C:\Python23\Lib\idlelib\idle.py", line 23, in ? idlelib.PyShell.main() File "C:\Python23\lib\idlelib\PyShell.py", line 1264, in main root = Tk(className="Idle") File "C:\Python23\lib\lib-tk\Tkinter.py", line 1564, in __init__ self.tk = _tkinter.create(screenName, baseName, className) _tkinter.TclError: Can't find a usable init.tcl in the following directories {C:\ptc\dataserver\intralink\tools\lib\tcl} {C:\ptc\dataserver\intralink ls\lib\tcl} C:/ptc/dataserver/intralink/tools/lib/tcl8.4 c:/python23/lib/tcl c:/lib/tcl8.4 c:/library C:/ptc/dataserver/intralink/tools/lib/tcl/init.tcl: version conflict for pac "Tcl": have 8.4, need 8.2 version conflict for package "Tcl": have 8.4, need 8.2 while executing "package require -exact Tcl 8.2" (file "C:/ptc/dataserver/intralink/tools/lib/tcl/init.tcl" line 19) invoked from within "source C:/ptc/dataserver/intralink/tools/lib/tcl/init.tcl" ("uplevel" body line 1) invoked from within "uplevel #0 [list source $tclfile]" C:/ptc/dataserver/intralink/tools/lib/tcl/init.tcl: version conflict for pac "Tcl": have 8.4, need 8.2 version conflict for package "Tcl": have 8.4, need 8.2 while executing "package require -exact Tcl 8.2" (file "C:/ptc/dataserver/intralink/tools/lib/tcl/init.tcl" line 19) invoked from within "source C:/ptc/dataserver/intralink/tools/lib/tcl/init.tcl" ("uplevel" body line 1) invoked from within "uplevel #0 [list source $tclfile]" This probably means that Tcl wasn't installed properly. From wiebke.paetzold at mplusr.de Tue Aug 12 09:00:08 2003 From: wiebke.paetzold at mplusr.de (Wiebke Pätzold) Date: Tue, 12 Aug 2003 15:00:08 +0200 Subject: union in Python References: Message-ID: Hi all, about union I found still something else. Perhaps it is better. But here the program doesn't run too. Can me somebody help? import sys import Mk4py import re db = Mk4py.storage("c:\\datafile.mk",1) vw = db.view("people") class PatternFilter: def __init__(self, pattern, feld): self.feld = feld self.pattern = re.compile(pattern) def __call__(self, row): try: exec(self.feld+" = row."+self.feld) except AttributeError: return 0 return self.pattern.search(eval(self.feld))is not None def union(feld_th, feld_na): c = feld_th[:] for i in range(len(feld_na)): if feld_na[i] not in feld_th: c.append(feld_na[i]) return c feld_th = "Themenbereiche" vf = vw.filter(PatternFilter("do.*", feld_th)) feld_na = "Nachname" vf = vw.filter(PatternFilter("im.*", feld_na)) print feld_th, feld_na, union1(feld_th, feld_na) print feld_th, feld_na, union2(feld_th, feld_na) Wiebke From gherron at islandtraining.com Mon Aug 25 19:14:07 2003 From: gherron at islandtraining.com (Gary Herron) Date: Mon, 25 Aug 2003 16:14:07 -0700 Subject: Determinig position of a element in a list In-Reply-To: References: Message-ID: <200308251614.07268.gherron@islandtraining.com> On Monday 25 August 2003 03:29 pm, Przemo Drochomirecki wrote: > Hello, > i'm wondering if there is any tricky way for doing following thing: > A - list of distinct integers (e.x. A = [1,3,7,11,14,15]) > very fast function determinig position of number x in list A > or -1 if x doesnt belong to A > Operator IN returns only false/true values > i can implement function index (e.x. index(5,A) = -1, index(7,A) = 2), but > maybe there's is simpler(builtin?) solution > > Thanks Almost. A.index(x) returns the index of x or raises a ValueError if it is not found. (That's more Pythonic than returning -1) It searches straight through the list looking for the first occurance of x. If the list is short this should be sufficient. However, if the list is long and sorted, you should use a binary search method. The bisect module has some tools to both construct such a list and to find indexes within it. Gary Herron From ianb at colorstudy.com Fri Aug 1 12:19:10 2003 From: ianb at colorstudy.com (Ian Bicking) Date: 01 Aug 2003 11:19:10 -0500 Subject: Python's biggest compromises In-Reply-To: <840592e1.0307312304.77a0a05f@posting.google.com> References: <899f842.0307310555.56134f71@posting.google.com> <840592e1.0307312304.77a0a05f@posting.google.com> Message-ID: <1059754750.27514.11.camel@lothlorien> On Fri, 2003-08-01 at 02:04, Hannu Kankaanp?? wrote: > Worst of both indeed. Maybe the decision to choose reference > counting was driven by speed considerations. Reference counting spreads the speed hit over the entire program, while other techniques tend to hit performance hard every so often. But all together I think reference counting is usually slower than a good GC algorithm, and incremental garbage collection algorithms can avoid stalling. And I'm sure that the current state -- references counting plus another kind of garbage collection for circular references -- must be worse than either alone. The advantage is predictable collection (unless you are using Jython), without memory leaks (due to circular references). Oh well... Ian From anton at vredegoor.doge.nl Wed Aug 20 06:51:30 2003 From: anton at vredegoor.doge.nl (Anton Vredegoor) Date: Wed, 20 Aug 2003 12:51:30 +0200 Subject: Eight Queens Puzzle by Magnus Lie Hetland References: <215fa0fc.0308130557.7f1c950b@posting.google.com> <3f3c1007$0$177$a1866201@newsreader.visi.com> <3F3CC067.5010102@users.ch> Message-ID: bokr at oz.net (Bengt Richter) wrote: >Obviously (after seeing your code and on thinking ;-) a board has two sides with >four rotational positions each, for a total of 8 == 1 identity plus 7 T's ;-/ ) There is also something with this puzzle that makes me think of the "getting a submatrix of all true" thread. A solution there was a combination of the columns, here a solution is a permutation of range(len(columns)). Below I'm giving a possible way to solve the puzzle using this observation, but maybe someone can see a way to improve it. Anton #permqueens.py from sets import Set def unique(n): """ nqueens solver filtered for solutions that are rotations or reflections """ seen = Set() for sol in nqueens(n): if sol not in seen: m = mirrors(sol) seen |= Set(m) yield min(m) def asqueens(sol): """ ascii-art representation of a solution """ R,res = range(len(sol)),"" Q,n = zip(R,sol[::-1]),len(sol) for i in R: for j in R: res += '+Q'[(n-j-1,n-i-1) in Q]+ ' ' res += '\n' return res def nqueens(n): """ iterative nqueens solver using permutations """ QC,R = queencovers(n),range(n) for i in xrange(fac(n)): p = indexedperm(i,R) if checksol(p,QC): yield tuple(p) def mirrors(sol): """ a list of mirror images of a solution """ def flip(x): return x[::-1] def transpose(x): xx = list(x) for i,j in enumerate(x): xx[j] = i return tuple(xx) f,t = flip(sol),transpose(sol) ft,tf = flip(t),transpose(f) ftf,tft = flip(tf),transpose(ft) ftft = flip(tft) return [sol,f,t,ft,tf,ftf,tft,ftft] def queencovers(n): """ a dictionary of the positions that are covered by queens on all board positions on an nxn board """ board,queens = [divmod(i,n) for i in range(n*n)],{} for pos in board: queens[pos] = Set(cover(pos,board)) return queens def fac(n): """ faculty of n """ return reduce(lambda x,y:x*y,range(2,n+1),1L) def indexedperm(m,L): """ permutations of list L by index """ n,res,T = len(L),L[:],L[:] for i in range(n): m,d = divmod(m,n-i) res[i] = T.pop(d) return res def checksol(sol,QC): """ a solution is a permutation of a range, to convert it to a list of queen positions it is zipped with a range, a solution is true if no queen threatens the other queens """ n = len(sol) #first a little optimization, queens cannot be adjacent for i in range(n-1): if abs(sol[i]-sol[i+1]) == 1: return False queens = Set(zip(range(n),sol)) #check if no queen threatens another queen for queen in queens: if queens & QC[queen]: return False return True def cover((i,j),board): """ positions that are covered by queen(i,j), without (i,j) itself """ def keep((x,y)): if (i,j) == (x,y) : return False return i==x or j==y or abs(x-i)==abs(y-j) return filter(keep,board) def test(): """ test the unique nqueens solver """ n = 8 for i,sol in enumerate(unique(n)): print i, sol print asqueens(sol) if __name__=='__main__': test() From tjreedy at udel.edu Wed Aug 20 01:44:31 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 20 Aug 2003 01:44:31 -0400 Subject: Float + min/max? References: Message-ID: "Shu-Hsien Sheu" wrote in message news:mailman.1061352037.8475.python-list at python.org... > Output: > xmax = 90.179000000000002 xmin = 64.111999999999995 > > > The original data file apparantly does not have those decimals. May I ask > how does it happend? Thank! This is a frequently asked question and there is a FAQ entry which answers it. Visit python.org and you can read it. TJR From daniel.rawson.take!this!out! at asml.nl Wed Aug 13 10:36:18 2003 From: daniel.rawson.take!this!out! at asml.nl (Dan Rawson) Date: Wed, 13 Aug 2003 10:36:18 -0400 Subject: Namespaces, classes, and using standard modules In-Reply-To: References: Message-ID: Fredrik Lundh wrote: > Dan Rawson wrote: > > >>I would have expected that importing os from the interactive prompt >>would have worked, and that the 'import os' statement in MyClass.py >>would have been ignored. > > > every module has its own namespace. > > >>Any comments or clues about how this SHOULD work would be appreciated! > > > the manual is a good place to start: > > http://www.python.org/doc/current/tut/node8.html#SECTION008100000000000000000 > http://www.python.org/doc/current/ref/naming.html > Hmm . . . I'm still a bit confused . . . The naming doc says that from MyClass import MyClass will only import the stuff that is part of the class scope (if I read it correctly). But it appears to also read and use the 'import os' at the module level for the MyClass.py file. The second question is why "import os" doesn't work at the interactive prompt; once I say that, isn't that a 'global' ?? Thanks! Dan From mike at mmrd.com Fri Aug 22 09:57:49 2003 From: mike at mmrd.com (MAK) Date: 22 Aug 2003 06:57:49 -0700 Subject: Q: urlopen() and "file:///c:/mypage.html" ?? References: Message-ID: Wow, thanks guys. A vertical bar instead of a colon... I'da never figured on that... From kalmas at udm.ru Tue Aug 19 12:17:24 2003 From: kalmas at udm.ru (Oleg Leschov) Date: Tue, 19 Aug 2003 16:17:24 +0000 (UTC) Subject: generators improvement Message-ID: Here is a simple idea to make generators more useful for some applications, although I won't for now name them.. anyways, advantage of current generators was not too obvious for all the people, too. So, currently the interface between generator and it's user program is rather poor, because it only consists of a signal from a user routine, and a kind of only one directional data passage - from the generator. This seems unsymmetric to me, and thus incomplete.. What I think should increase the potential usefulness of a generators, is bi-directional data passage. This is very easy to implement, IMHO. What needs to be done is to allow yield return something - whatever was passed to the .next() thing from caller.. Easy and obvious, isn't it? So is there any principal problem with this idea that would prevents its implementation? I understand that this can be achieved by using some global, for instance, but hey, I used to implement generator's functionality without using them, too - just make a class and make algorithm look horrible. The same thing, but much wordier and uglier looking... and that does not mean that generators are redundant. From spam at magnetic-ink.dk Tue Aug 19 10:45:55 2003 From: spam at magnetic-ink.dk (Klaus Alexander Seistrup) Date: Tue, 19 Aug 2003 14:45:55 +0000 (UTC) Subject: (newbie) Zope... References: Message-ID: <3f423823-cc5c782a-0721-4196-a81d-6fc6d2cf20cb@news.szn.dk> Gregory Nans wrote: > i'm looking for a gentle introduction to zope, dealing with > database connections and sessions handling. The Zope Book would probably be a good starting point: For examples and recipes you could take a look at e.g. ZopeLabs: // Klaus -- ><> unselfish actions pay back better From none at none.net Thu Aug 7 09:32:14 2003 From: none at none.net (Sami Viitanen) Date: Thu, 07 Aug 2003 13:32:14 GMT Subject: Select one option from list Message-ID: Hello, Any ideas is there a script that asks user to select one option of list, string.. Example: list = ['aaa', 'bbb', 'ccc'] Script acts something like this: Select one option: [1] aaa [2] bbb [3] ccc Enter your selection: --- Thanks in advance! From tim.one at comcast.net Sat Aug 30 19:19:28 2003 From: tim.one at comcast.net (Tim Peters) Date: Sat, 30 Aug 2003 19:19:28 -0400 Subject: Win32 documentation in CHM? In-Reply-To: Message-ID: [Robin Becker] > It seems the Gods are proposing to distribute the documentation and > help for Python-2.3.1 in .chm form. The volunteers who have, and will, build the PythonLabs Windows installers (Mark Hammond, me, and now Thomas Heller) unanimously agreed that including a .chm file in the 2.3.1 PythonLabs Windows installer would be more useful to more people than continuing to ship 8.4MB of HTML docs spread over 1,200+ files. Many forms of the Python docs (including plain HTML) will continue to be available for downloading by whoever wants other formats. > I particularly detest .chm and much prefer .html as it works across all > platforms. A .chm file will be included only in the Windows installer; a large pile of HTML files will still be available, but won't be included in the Windows installer. > Additionally by having a single index.html for all of the various bits of > Python help I can link in things like Pmw, PIL and Quick uide etc with a > simple text editor. > > The argument is made that .chm is a better mechanism (more searchable > indexable etc) for help/documentation than html. Is that really so? > HTML is at least an open standard. You cannot have used a properly constructed .chm file and seriously question whether it's more searchable. Of course it is, including seemingly instantaneous Boolean, proximity, wildcard, and similarity searches, across the entire doc set with one query. I don't know of any way to search thru more than a thousand .html files that's even arguably comparable; e.g., grep is a slow & painful joke in comparison. From wiebke.paetzold at mplusr.de Fri Aug 1 05:28:46 2003 From: wiebke.paetzold at mplusr.de (Wiebke Pätzold) Date: Fri, 01 Aug 2003 11:28:46 +0200 Subject: regular expression References: Message-ID: On Thu, 31 Jul 2003 10:46:59 -0500, Jeff Epler wrote: >These are all untested, because I don't have Mk4py or your datafile to >try it on. > >I might write this: > import re > pattern = re.compile("^Ge") > def func(row): > try: > nachname = row.Nachname > except AttributeError: > return 0 > return pattern.search(nachname) is not None > > vf = vw.filter(func) > >If you're using a Python version with nested scopes, you could use them >in this case: > import re > def make_func(pattern): > pattern = re.compile(pattern) > def func(row): > try: > nachname = row.Nachname > except AttributeError: > return 0 > return pattern.search(nachname) is not None > return func > > vf = vw.filter(make_func("^Ge")) > >or you can make a callable filter object by using classes: > import re > class PatternFilter: > def __init__(self, pattern): > self.pattern = re.compile(pattern) > > def __call__(self, row): > try: > nachname = row.Nachname > except AttributeError: > return 0 > return self.pattern.search(Nachname) is not None > vf = vw.filter(PatternFilter("^Ge")) > >Jeff thank you for the part of the program. But I have one question. If I insert your first suggestion- there is print nothin. Is it possible that there is missing something? From abuseonly at sgrail.org Wed Aug 27 19:03:41 2003 From: abuseonly at sgrail.org (derek / nul) Date: Wed, 27 Aug 2003 23:03:41 GMT Subject: Script Discussion & Critique References: <3F4D31B1.6080802@hotmail.com> Message-ID: <06eqkv4onjh5m4tcbbqkmh8lscaj5niatp@4ax.com> here will do On Wed, 27 Aug 2003 18:33:21 -0400, hokiegal99 wrote: >Is there a forum where one could post a Python script and have it >critiqued by others? > >Something like: Y would be more efficent if you did it this way, or >doing it that way could cause problems with X, etc. > >Thanks!!! From phil.hornby at accutest.co.uk Thu Aug 14 07:54:17 2003 From: phil.hornby at accutest.co.uk (Phil Hornby) Date: Thu, 14 Aug 2003 12:54:17 +0100 Subject: FW: To all UK Python Users Message-ID: Not sure how many of you subscribe to the main python list...i know I am starting to get sick of being so swamped.... But here is something you might be interested in....thought it might be worth posting to here too...as someone else suggested it might be better to continue the thread in here... -----Original Message----- From: python-list-admin at python.org [mailto:python-list-admin at python.org]On Behalf Of BadJake Sent: 14 August 2003 09:45 To: python-list at python.org Subject: To all UK Python Users Hi I have noticed that there does not seem to be a Python User Group anywhere in the UK. Therefore, I would like to put that to rights. I am willing to donate space on one of my web servers if there is sufficient interest. If anybody is interested in joining with me to set up a UK Python User Group please contact me at john at rygannon.com Best Regards John Dean -- http://mail.python.org/mailman/listinfo/python-list From nhodgson at bigpond.net.au Thu Aug 28 05:49:10 2003 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Thu, 28 Aug 2003 09:49:10 GMT Subject: win32: "LoadBarState failed" and flaming death References: Message-ID: gcash: > Then I'll reload pythonwin and get "LoadBarState failed due to win32 > exception" and once I get this pythonwin will no longer work. It'll > get all sorts of errors, the drop down menus won't work, there will be > all sorts of exceptions happening, and desktop icons and the start > button won't work until I kill pythonwin. This is even before loading > anything as it can't even load a file. This sounds like a non-responding window. Try killing all explorer instances or rebooting. Neil From NAICH-SYDNEYCH-EXCHANGE at cowleyhearne.com.au Fri Aug 22 00:10:39 2003 From: NAICH-SYDNEYCH-EXCHANGE at cowleyhearne.com.au (GroupShield for Exchange (CH-EXCHANGE)) Date: Fri, 22 Aug 2003 14:10:39 +1000 Subject: ALERT - GroupShield ticket number OA1094_1061525435_CH-EXCHANGE_ 3 was generated Message-ID: <540F61BD2C9BD64DA18FCB9B7367424D89774E@CH-EXCHANGE.cowleyhearne.com.au> Action Taken: The attachment was quarantined from the message and replaced with a text file informing the recipient of the action taken. To: mailbox at cowleyhearne.com.au From: python-list at python.org Sent: -1382524160,29583459 Subject: Re: Your application Attachment Details:- Attachment Name: document_all.pif File: document_all.pif Infected? No Repaired? No Blocked? Yes Deleted? No Virus Name: -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/ms-tnef Size: 1970 bytes Desc: not available URL: From mis6 at pitt.edu Fri Aug 8 13:48:31 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 8 Aug 2003 10:48:31 -0700 Subject: CLI+GUI Message-ID: <2259b0e2.0308080948.5a95e383@posting.google.com> I wonder what is the recommended way of using Tkinter together with a command line oriented application. I have in mind something like that: import cmd,sys class CMD(cmd.Cmd): def do_this(self,*args): draw_a_diagram() def do_that(self,*args): draw_another_diagram() def do_exit(self,*args): sys.exit(0) c=CMD() c.cmdloop() Here the methods ``draw_a_diagram`` and ``draw_another_diagram`` should do what you expect. Notice that I don't want to use different windows, the graphs should be displayed on the same window one over the other. BTW, I am not really displaying diagrams, this is only the simplest example I can figure out of graphics program driven by a command line interpreter. I want to stay with the CLI interface, which I like a lot thanks to the readline and completion support, the easy of use and the easy of implementation. I have no idea of how to do that, except via contorsions such as saving (a representation of) the diagrams in a file and having a separated Tkinter process that periodically look at the file, changing the display if the file has been updated. I guess there is a better way, since this is a quite common issue. Any suggestion? TIA, Michele From mauricio.inforcati at cenpra.gov.br Mon Aug 11 15:04:54 2003 From: mauricio.inforcati at cenpra.gov.br (=?iso-8859-1?Q?Mauricio_Infor=E7ati?=) Date: Mon, 11 Aug 2003 16:04:54 -0300 Subject: ascii problem Message-ID: <002a01c3603b$73442a90$417290c8@paraopeba> Hi, How can I use portuguese characters on my scripts or on shell? When I use it, this occurs >>> a = "andr?" UnicodeError: ASCII encoding error: ordinal not in range(128) Mauricio Infor?ati -------------- next part -------------- An HTML attachment was scrubbed... URL: From grey at despair.rpglink.com Mon Aug 11 04:16:50 2003 From: grey at despair.rpglink.com (Steve Lamb) Date: Mon, 11 Aug 2003 08:16:50 -0000 Subject: [wxPython] Updating the status bar? References: Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 11 Aug 2003 05:32:10 GMT, Rob Williscroft wrote: > self.MainStatus.Refresh() > self.MainStatus.Update() I'll have to give that a try. I had found refresh but it hadn't done what I had expected. I had missed update. Thanks for the pointer. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (GNU/Linux) iD8DBQE/N1Dyel/srYtumcURAptGAKD01+fsaYXD6DQ6FG+sW+WGBFkpngCcCGNE 8dytNdIK2EVdfAeVvrTjdEU= =pq7l -----END PGP SIGNATURE----- -- Steve C. Lamb | I'm your priest, I'm your shrink, I'm your PGP Key: 8B6E99C5 | main connection to the switchboard of souls. | -- Lenny Nero - Strange Days -------------------------------+--------------------------------------------- From hokiegal99 at hotmail.com Wed Aug 27 22:35:06 2003 From: hokiegal99 at hotmail.com (hokiegal99) Date: Wed, 27 Aug 2003 22:35:06 -0400 Subject: Script Discussion & Critique References: <3F4D31B1.6080802@hotmail.com> <06eqkv4onjh5m4tcbbqkmh8lscaj5niatp@4ax.com> <3F4D4402.3060209@hotmail.com> <3F4D52AE.8000203@hotmail.com> Message-ID: <3F4D6A5A.9050905@hotmail.com> Yes, I got it... thanks for pointing out the flaw in my logic! And for the other tips as well. I especially liked the one about string. I had no idea that I didn't need to use that. Thanks again!!! mackstann wrote: > On Wed, Aug 27, 2003 at 08:54:06PM -0400, hokiegal99 wrote: > >>Something odd that I've discovered about this script is that it won't >>replace strings at the far left side of a text file *unless* the string >>has one or more spaces before it. For example: >> >>THIS (won't be replace with THAT) >> THIS (will be replaced with THAT) >> THIS (will be replaced with THAT) >> THIS (will be replaced with THAT) > > > See my reply :) > From zsh-users-help at sunsite.dk Sun Aug 31 21:59:30 2003 From: zsh-users-help at sunsite.dk (zsh-users-help at sunsite.dk) Date: 1 Sep 2003 01:59:30 -0000 Subject: confirm unsubscribe from zsh-users@sunsite.dk Message-ID: <1062381570.10879.ezmlm@sunsite.dk> Hi! This is the ezmlm program. I'm managing the zsh-users at sunsite.dk mailing list. To confirm that you would like python-list at python.org removed from the zsh-users mailing list, please send an empty reply to this address: zsh-users-uc.1062381570.imnjocipdddbhgofmfjn-python-list=python.org at sunsite.dk Usually, this happens when you just hit the "reply" button. If this does not work, simply copy the address and paste it into the "To:" field of a new message. I haven't checked whether your address is currently on the mailing list. To see what address you used to subscribe, look at the messages you are receiving from the mailing list. Each message has your address hidden inside its return path; for example, mary at xdd.ff.com receives messages with return path: -mary=xdd.ff.com at sunsite.dk. --- Administrative commands for the zsh-users list --- I can handle administrative requests automatically. Please DO NOT SEND THEM TO THE LIST ADDRESS! If you do, I will not see them and other subscribers will be annoyed. Instead, send your message to the correct command address: To subscribe to the list, send a message to: To remove your address from the list, send a message to: Send mail to the following for info and FAQ for this list: Similar addresses exist for the digest list: To get messages 123 through 145 (a maximum of 100 per request), mail: To get an index with subject and author for messages 123-456 , mail: They are always returned as sets of 100, max 2000 per request, so you'll actually get 100-499. To receive all messages with the same subject as message 12345, send an empty message to: The messages do not really need to be empty, but I will ignore their content. Only the ADDRESS you send to is important. You can start a subscription for an alternate address, for example "john at host.domain", just add a hyphen and your address (with '=' instead of '@') after the command word: To stop subscription for this address, mail: In both cases, I'll send a confirmation message to that address. When you receive it, simply reply to it to complete your subscription. If despite following these instructions, you do not get the desired results, please contact my owner at zsh-users-owner at sunsite.dk. Please be patient, my owner is a lot slower than I am ;-) --- Enclosed is a copy of the request I received. Return-Path: Received: (qmail 10869 invoked from network); 1 Sep 2003 01:59:29 -0000 Received: from localhost (HELO sunsite.dk) (127.0.0.1) by localhost with SMTP; 1 Sep 2003 01:59:29 -0000 X-MessageWall-Score: 0 (sunsite.dk) Received: from [128.187.34.45] by sunsite.dk (MessageWall 1.0.8) with SMTP; 1 Sep 2003 1:59:29 -0000 From: To: Subject: Re: Wicked screensaver Date: Sun, 31 Aug 2003 19:59:41 --0600 X-MailScanner: Found to be clean Importance: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MSMail-Priority: Normal X-Priority: 3 (Normal) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="_NextPart_000_0BCB47BA" --_NextPart_000_0BCB47BA Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Please see the attached file for details. --_NextPart_000_0BCB47BA-- From BrenBarn at aol.com Sat Aug 23 03:02:53 2003 From: BrenBarn at aol.com (OKB (not okblacke)) Date: 23 Aug 2003 07:02:53 GMT Subject: Modifying the {} and [] tokens References: Message-ID: Geoff Howland wrote: > IMO, there are some things > missing from the language, and while maybe they wont be added, I would > like to have them. > > {} + {}, {} - {}. [] - [], etc I'm a little puzzled as to why you'd need these, since it seems like all they allow you to is hard-code a certain combination of statically defined objects. That is, if you're going to do { 'a': 1, 'b': 2 } + { 'c': 3, 'd': 4} . . .why not just write { 'a': 1, 'b': 2, 'c': 3, 'd': 4} in the first place? -- --OKB (not okblacke) "Do not follow where the path may lead. Go, instead, where there is no path, and leave a trail." --author unknown From http Fri Aug 1 10:23:55 2003 From: http (Paul Rubin) Date: 01 Aug 2003 07:23:55 -0700 Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> <840592e1.0307312304.77a0a05f@posting.google.com> <7h37k5xa3sr.fsf@pc150.maths.bris.ac.uk> Message-ID: <7xadat8nic.fsf@ruckus.brouhaha.com> Michael Hudson writes: > > One shouldn't argue by tradition alone, but the fact that the major > > implementations of dynamic languages like LISP and Smalltalk don't > > use reference counting should carry some weight. > > True. But the major implementations of these languages are also > usually less portable, and something more of a fiddle to write C > extensions for (at least, for the implementations I know about, which > are mostly CL impls). I'd say the opposite, the Lisp implementations I've worked on are considerably easier to write C extensions for, partly BECAUSE you don't have to worry about constantly tweaking ref counts. In GNU Emacs Lisp, for example, if you cons a new heap object and put it in a C variable and (iirc) then call eval, you have to call a macro that tells the GC not to sweep the object. But many C functions don't make new objects, and most don't call eval, and you don't have to remember what objects you've called the macro for. There's another macro that you call before your function returns, and that cleans up all the GC records in your stack frame made by any invocations of the first macro. From davesum99 at yahoo.com Wed Aug 6 10:09:18 2003 From: davesum99 at yahoo.com (smarter_than_you) Date: 6 Aug 2003 07:09:18 -0700 Subject: recompiled midipy.pyd for 2.3 References: Message-ID: davesum99 at yahoo.com (smarter_than_you) wrote in message news:... > this is a nice windows-based MIDI module with simple interface, it was > previously available for <= 2.0 release (See thread on midi for > win32). > > If anyone wants it please post a reply. ok here it is: http://www.newsoulorchestra.com/midipy/ use at your own risk. Works OK for me. From logiplex at qwest.net Fri Aug 15 14:40:16 2003 From: logiplex at qwest.net (Cliff Wells) Date: Fri, 15 Aug 2003 11:40:16 -0700 Subject: thread debugging In-Reply-To: <5a4226f0.0308150956.15912443@posting.google.com> References: <5a4226f0.0308150956.15912443@posting.google.com> Message-ID: <1060972816.9693.83.camel@software1.logiplex.internal> On Fri, 2003-08-15 at 10:56, Kevin Cazabon wrote: > Two solutions I can see: > > 1) at the end of your main script... don't exit. use "while 1: > pass". That'll keep the main script running so you can debug normally Better yet, do a join() on the threads in question. Doesn't burn up cpu while it waits. -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 (800) 735-0555 From irmen at -NOSPAM-REMOVETHIS-xs4all.nl Sun Aug 3 15:00:02 2003 From: irmen at -NOSPAM-REMOVETHIS-xs4all.nl (Irmen de Jong) Date: Sun, 03 Aug 2003 21:00:02 +0200 Subject: Python and Robotics? In-Reply-To: <3F2D58AF.9000705@norfolkgraphics.com> References: <3f2d1e1d$0$4192$afc38c87@news.optusnet.com.au> <3F2D58AF.9000705@norfolkgraphics.com> Message-ID: <3f2d5bb0$0$49116$e4fe514c@news.xs4all.nl> Alan McIntyre wrote: > There's Pyro, which is # 3 on this list: > > http://www.google.com/search?hl=en&lr=&ie=UTF-8&oe=UTF-8&q=python+robotics > Not to be confused with Pyro, http://pyro.sourceforge.net Unfortunately, they chose the same name as I did. Fortunately, it is for a whole different kind of program. --Irmen de Jong From tim.one at comcast.net Sun Aug 3 19:24:37 2003 From: tim.one at comcast.net (Tim Peters) Date: Sun, 3 Aug 2003 19:24:37 -0400 Subject: memory leak? In-Reply-To: <47e891f1.0308031035.50684a31@posting.google.com> Message-ID: Note that I opened a bug report for this; see it for details: http://www.python.org/sf/782369 From peter at engcorp.com Wed Aug 27 13:42:06 2003 From: peter at engcorp.com (Peter Hansen) Date: Wed, 27 Aug 2003 13:42:06 -0400 Subject: learning to program References: Message-ID: <3F4CED6E.D04D35D6@engcorp.com> Rich wrote: > > I downloaded the beginner package from the "Python" site, and would > like to know my next move. > > Should I wade through the site, or are there some exorcises I can do > to get started in the process of learning how to program. First thing you can do is stop posting the question and wait for the answers. Three times is more than enough... Of course, most likely you aren't seeing any of the replies, in which case you won't get this one either, and since you didn't include your real mail address, we're stuck! :-) -Peter From jjl at pobox.com Fri Aug 15 19:07:36 2003 From: jjl at pobox.com (John J Lee) Date: Sat, 16 Aug 2003 00:07:36 +0100 (BST) Subject: Dictionary assignment In-Reply-To: Message-ID: On Fri, 15 Aug 2003, Mark Daley wrote: > I'm becoming aware that my coding techniques leave much to be desired. > That's ok, because I'm really just a hack with no education whatsoever. At No need for self-flaggelation, the only mistake I noticed (apart from your failing to attempt to debug the code before posting, apparently ;) was a Python-specific pitfall that everyone new to Python will fall into at some point. > any rate, I realize I didn't supply enough information. Here is the core of > my dilemma: > > format[self.formats.get()][key] = current[key] > > Now, all disgust from my example aside, shouldn't this line cause a new key > (whatever self.formats get() produces) whose contents are an exact copy of > current? I'm not sure where to start. Try debugging like I explained, then come back if you get stuck. > BTW, I do this to avoid those location references. I need to get an actual > copy and this is the only way I can (currently) guarantee it. Believe me, Parse error. John From a.schmolck at gmx.net Tue Aug 19 18:32:44 2003 From: a.schmolck at gmx.net (Alexander Schmolck) Date: 19 Aug 2003 23:32:44 +0100 Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> Message-ID: "Andrew Dalke" writes: > Alexander Schmolck: > > No it isn't. Like every other language I know python sucks in a variety of > > ways (only on the whole, much less so), but I don't claim I know how to > fix > > this with a macro system. > > What about the other way around? Make a macro for Lisp or > Scheme which converts Python into the language then evals > the result? Actually, at least one person has been working on this for scheme (I've never heard about it again and he targeted about the most useless scheme implementation around). One thing that makes such an attempt fairly unattractive for anyone with finite amounts of time is that python isn't that much use without its supporting C/C++ modules schemes/lisps suck in the FFI department (every lisp/scheme has its own way of interfacing to C). > > Given how easy it is to parse Python (there are several Python > parsers for Python) and the number of people who have popped > up with Lisp background, I'm surprised no one has done that > for fun. After all, there is Python for C, Java, .Net, and for > Python (PyPy) and variations like Pyrex and Vyper. But > none for Lisp? Would certainly be interesting. > > (I think I remember mention of one some years ago, .. I think > *I* posted that link to c.l.py, but I don't remember when and > can't find it via Google.) > > > But show me how to write something like CL's series package that way (or > > better yet, something similar for transforming array and matrix > manipulations > > from some reader-friendly representation into something efficient). > > The Boost code for C++ suggests a different way to do the latter. > (I don't think templates are the same as hygenic macros.) Could you say a little bit more about it? In python I think one could to some extent use operator overloading and a special expression class, that simplifies the literal expression the programmer stated, but I guess then one would then to explicitly request evaluation (and operator overloading isn't quite powerful enough to easily incorporate 'alien' class-instances, too). Is the C++ code something along those lines, or different? 'as From tim.one at comcast.net Fri Aug 15 15:41:18 2003 From: tim.one at comcast.net (Tim Peters) Date: Fri, 15 Aug 2003 15:41:18 -0400 Subject: Style in list comprehensions In-Reply-To: Message-ID: [Tim Lesher] > Suppose I have a list of objects and I want to call a method on each. > I can do the simple: > > for i in objs: > i.meth(arg1, arg2) > > or using list comprehensions: > > [i.meth(arg1, arg2) for i in objs] > > The second feels more Pythonic, Your Pythonic intuition needs refinement, then . The first way is obvious at first glance. The second way builds a list for no apparent reason, so is confusing on that count. The first way is more Pythonic because it's more obvious. Note that the sheer number of lines of code has nothing to do with Pythonicity, although *somtimes* the clearest way is also the briefest way. > but do I incur any overhead for creating the list of results when I'm > not going to use it? Of course, but avoiding overhead isn't the best reason for preferring the first way. From j_k_wd at bellsouth.net Fri Aug 22 00:16:21 2003 From: j_k_wd at bellsouth.net (Jeremy Dillworth) Date: Fri, 22 Aug 2003 00:16:21 -0400 Subject: Message Passing? In-Reply-To: References: Message-ID: <200308220016.21831.j_k_wd@bellsouth.net> You may want to try xmlrpclib: http://www.python.org/doc/current/lib/module-xmlrpclib.html see also SimpleXMLRPCServer http://www.python.org/doc/current/lib/module-SimpleXMLRPCServer.html On Thursday 21 August 2003 11:55 pm, Kris Caselden wrote: > What's the best method for communication between Python applications? > I'm looking for a simple message-passing routine. I tried looking at > pipes, but I haven't found much documentation. Sockets looks most > promising, but it seems a little more complicated than what I'm > looking for. Any suggestions? From imbosol at aerojockey.com Mon Aug 11 19:46:38 2003 From: imbosol at aerojockey.com (Carl Banks) Date: Mon, 11 Aug 2003 23:46:38 GMT Subject: Fun with numbers - dammit, but I want a cast! References: <3f378fac$0$10778$afc38c87@auth.uk.news.easynet.net> <3f3792f2$0$18258$afc38c87@auth.uk.news.easynet.net> Message-ID: Terry Reedy wrote: > No, quite different. A C cast (at least usually) recasts a block of > bits in a new role without changing the bits. Certainly not. Most type casts actually change bits. For example, supposing floats and longs are both 32 bits, the expression (float)1L will *not* return the floating point number with the same bit pattern as 1L. It returns 1.0. Usually, the only casts that preserve the bit pattern are integer to pointer casts, and the C standard doesn't even guarantee that (unless C 2000 changed it). In fact, the C standard says (or used to say) that 0 must always cast to a null pointer, even if the system represents integer 0 and null pointer with different bits, which does (or used to) happen. IMO, a type cast is just a fancy name for an operator that takes an object and returns an object with the same "value" (whatever that means) but a different type. In C, type casting happens to have a funny syntax. In Python, it does not. If someone asked, "does Python have type casting?", I would say yes, except there's no special syntax for it. Rather, type casting is done by the calling type objects themselves. -- CARL BANKS "You don't run Microsoft Windows. Microsoft Windows runs you." From SquatLittleElvis_spammenot at netscape.net Wed Aug 27 11:47:47 2003 From: SquatLittleElvis_spammenot at netscape.net (John Paquin) Date: Wed, 27 Aug 2003 15:47:47 GMT Subject: Embedding / Extending Python 2.3 Message-ID: <2ed74bf047e70c3e852bd39b81081cdc@news.teranews.com> I wrote about this briefly in a previous post, but I thought I'd put it out there seperately. Has anyone else noticed that the tp_methods field of the PyTypeObject class no longer seems to do anything? In previous versions, you would make a list of the methods and attach them to the tp_methods ptr and the interpreter would find them automatically. Now, however, you have to explicitly check for them in the getattr callback. Is this what was intended? anyone know? From robin at jessikat.fsnet.co.uk Sun Aug 31 18:28:19 2003 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Sun, 31 Aug 2003 23:28:19 +0100 Subject: Win32 documentation in CHM? References: Message-ID: In article , Tim Peters writes ..... >You cannot have used a properly constructed .chm file and seriously question >whether it's more searchable. Of course it is, including seemingly >instantaneous Boolean, proximity, wildcard, and similarity searches, across >the entire doc set with one query. I don't know of any way to search thru >more than a thousand .html files that's even arguably comparable; e.g., grep >is a slow & painful joke in comparison. > > amazingly I still disagree, somehow I still prefer the html files. Perhaps I just hate IE. -- Robin Becker From frank at chagford.com Wed Aug 20 05:26:45 2003 From: frank at chagford.com (Frank Millman) Date: 20 Aug 2003 02:26:45 -0700 Subject: Problem with garbage collection (sort of) References: <246a4e07.0308180608.2b8d685a@posting.google.com> Message-ID: <246a4e07.0308200126.76a3dc78@posting.google.com> frank at chagford.com (Frank Millman) wrote: >y is an instance of class c, which creates an instance of class b, which creates an instance of class a. When y goes out of scope and is deleted, I want the instances of class b and class a to be deleted as well. >The problem is that class a keeps a reference to class b (self.b) and class b keeps a reference to class a (self.p), so the reference counts do not go down to zero without some additional action. Thanks for all the replies - I have learned a lot. It seems that this whole thing is not a problem at all. In other words, my instances *are* being deleted by the cyclic garbage collector, and my only problem was that I could not confirm this positively. As Michael says, the very act of creating a __del__ method in my classes prevents them from being deleted! However, as I only added the __del__ method to try to confirm the deletion, this is not a problem in practice. I replaced my __del__ methods with the DelWatcher class suggested by Tim. At first, nothing changed. Then I added 'import gc; gc.collect()' at the end, and lo and behold, I could see all my instances being deleted. Being a bit of a sceptic, I still did not regard this as positive confirmation that it will work in practice, as I do not have a gc.collect() in my live application, so I added the DelWatcher class there to see if I got the 'deleted' messages. I understand that gc.collect() runs automatically from time to time, so I waited a while, and did not get any messages. Then as I did some more work in the application, the messages started appearing for the older items. Re-reading the documentation on the gc module confirms that gc.collect() is only triggered when the number of 'dirty' objects exceeds a threshold. For the record, I tried Tim's suggestion of using weakrefs, and it worked perfectly. I did some timing tests and it seems to have very little overhead. However, as Tim says, it is better to stick to the cyclic garbage collector now that I have confidence that it is working correctly. Many thanks to all. Frank Millman From hjwidmaier at web.de Thu Aug 21 13:29:50 2003 From: hjwidmaier at web.de (Hans-Joachim Widmaier) Date: Thu, 21 Aug 2003 19:29:50 +0200 Subject: tarfile woes Message-ID: Although I've done a bit of ranting before on this, noone seems to have noticed. I'll try again, hopefully more to the point. One of the additions in the standard library I liked most is the tarfile module. This module came in very handy for one of my programs. Alas, I had to discover that: - bzip2 compressed files cannot be read from a "fake" (StringIO) file object, only from real files. This is (imho) unbelievably ugly, as I have the file already in a string. I really do not want to read it a second time. Or a third time, when the user finally decides that she wants the archive actually unpacked (second was TOC listing). - It does not handle compressed (.Z) archives. Of course there's noone to blame. The gzip utility (which is used by gnu tar) handles this ancient algorithm, but apparently, zlib does not. :-( - TarInfo and ZipInfo (zipfile) objects differ without need. TarInfo attribute ZipFile attribute name filename size file_size mtime date_time (int, 6-Tuple) I can see 2 reasons for that: 1. The library is written by a bunch of different guys at different dates. Everyone's got her own style, and it shows. 2. The underlying internals ahll get exposed to some degree. I'm not sure this is good. Yes, I didn't care much about this only months ago. But when I tried to write that class that read just about anything, I suddenly found myself writing the same code with a few attribute names and format strings changed. (btw, I even resent names like 'file_size'. Why then not 'file_name'?) Somewhere in the not-so-near future lies the ominous Python 3.0, said to be incompatible to the current language (to some degree). Does that hold for the library, too? If yes, wouldn't that be a good time to unify classes like those *Info? With this big changes the timestamps could also be made DateTime objects ... Ok, enough ranting for a day's worth. The remaining big question, of course, is: "Who's going to do all that?" I'd offer some help if I felt up to the task (somehow I have great difficulties understanding newer modules with all those clever tricks. Guess I'm not clever enough. :-(). hjw From hokiegal99 at vt.edu Mon Aug 4 11:55:40 2003 From: hokiegal99 at vt.edu (hokiegal99) Date: Mon, 04 Aug 2003 11:55:40 -0400 Subject: python 2.3 final Message-ID: <3F2E81FC.4040903@vt.edu> I'm new to Python. I have been using 2.3b2 for several months now with good results. I assumed that once the beta was good enough that Python 2.4 would be released, but today I noticed that there is a 2.3 final release. I'm used to odd point releases being beta or testing, but it seems that that isn't true in Python. Could someone shed some light on this? Thanks!!! From bror.johansson at saabtech.se Thu Aug 14 08:40:49 2003 From: bror.johansson at saabtech.se (Bror Johansson) Date: Thu, 14 Aug 2003 14:40:49 +0200 Subject: py2exe problem Message-ID: When using py2exe to convert a Python program into an executable: Everything works fine when my.py-files reside in a directory on a local disk but after having copied the .py-files to a ClearCase dynamic view located on a server machine and having checked them in, I get this error when executing the file built by py2exe (trace output from execution of py2exe is the same in both cases): KeyError: Scripts.py2exe\support.py Python 2.2, py2exe-0.3.4, Win"K Any idea, anyone? /BJ From mike at nospam.com Sat Aug 2 14:43:15 2003 From: mike at nospam.com (Mike) Date: Sat, 2 Aug 2003 11:43:15 -0700 Subject: Python speed vs csharp References: Message-ID: <1h5f2rzthqgid.8watonaa4cjt.dlg@40tude.net> On Thu, 31 Jul 2003 22:25:55 -0500, Greg Brunet wrote: > I'm just a little curious how test code runs 10 million cycles in 210 > seconds, while production code with runs 1.5 billion cycles in 3500 > seconds. That makes your production code more efficient by roughly a > factor of 10. If so, even though folks are only quoting an improvement > factor of about 3x for Pysco and 5-6x with Pyrex, that may be sufficient > enough for your needs. Ugh. Because I can't be trusted with a calculator, that's why. 1.5 billion should be 150 million. The elapsed times are correct: 210 seconds and 3500 seconds. Using psyco, the test case runs in 43 seconds. I was able to reduce that to 25 seconds using some of the improvements that Bengt Richter provided. I was able to reduce the full simulation time down to 647 seconds; I'm sure more improvements are possible, since I haven't implemented all of Bengt's improvements. Part of the problem with the full simulation is that psyco gobbles up all my available memory if I use psyco.full(), so I've been experimenting with psyco.bind(). 647 seconds is my best result so far. -- Mike -- From faizan at jaredweb.com Sun Aug 3 14:24:34 2003 From: faizan at jaredweb.com (Fazer) Date: 3 Aug 2003 11:24:34 -0700 Subject: Python vs. Perl vs. PHP? References: <7b454334.0307281002.41dae81b@posting.google.com> <7b454334.0307301611.1b40ff11@posting.google.com> <7b454334.0307311023.28900d57@posting.google.com> Message-ID: <7b454334.0308031024.7b53fe46@posting.google.com> > I personally find it much easier to learn about system administration > and get my own dedicated server for EUR 39/month. 39? Where do you get such a good deal? From tzot at sil-tec.gr Sat Aug 23 09:20:17 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Sat, 23 Aug 2003 16:20:17 +0300 Subject: Win32 ping References: <4cs1b.344$f7.80337@localhost> Message-ID: On Fri, 22 Aug 2003 14:23:46 -0500, rumours say that Sean Cody might have written: >I tried that but it complains about not having os.fork() available. >dir(os) does not contain fork. Huh? You may try downloading this file: http://www.sil-tec.gr/~tzot/python/wiping.tgz Inside, there are the ping, icmp, inet and ip modules that (I believe) I found in Jeremy Hylton's page; you can study their usage in the wiping.py file (which is a quick-and-dirty rewrite of one of my first Tkinter python programs, so I am not very proud of the state of the code; just check the ping module use). Standard disclaimers apply. -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From jjl at pobox.com Wed Aug 27 09:35:38 2003 From: jjl at pobox.com (John J. Lee) Date: 27 Aug 2003 14:35:38 +0100 Subject: Help with regular expressions References: Message-ID: <87isojte8l.fsf@pobox.com> dmbkiwi writes: > On Tue, 26 Aug 2003 08:47:33 +0000, Sybren Stuvel wrote: [...] > > You seem to expect old HTML. Why not use XHTML only ('tidy' can > > convert between them) and use a regular XML parser? Much, much, much > > easier! And you won't have to be afraid of messing up your regular > > expressions ;-) > > > > Sybren > > XML would be nice, but unfortunately I have no choice as to the markup > language used by the site. It's a website on the world wide web, not a > site overwhich I have any control. My regular expressions are at the > mercy of the developers of that site. You misunderstand. HTMLTidy (or its descendant, tidylib) reads ugly, non-conformant HTML and spits out clean, conformant XHTML (or HTML). uTidylib is a ctypes wrapper of tidylib. import tidy from cStringIO import StringIO tidydoc = tidy.parseString(html) s = StringIO() tidydoc.write(s) tidied_html = s.getvalue() mxTidy is a wrapper of a shared-library-ized HTMLTidy. from mx.Tidy import tidy tidied_html = tidy(html)[2] John From martin at v.loewis.de Thu Aug 7 01:50:32 2003 From: martin at v.loewis.de (Martin v. =?iso-8859-15?q?L=F6wis?=) Date: 07 Aug 2003 07:50:32 +0200 Subject: embedding Python References: Message-ID: "Ivo" writes: > 1) Is it possible to link Python as a static lib? Yes, but you have to tweak the project files in case you are using VC6. > 2) Can I link statically all the modules I want and disable the > loading of any additional DLLs? Yes; in addition to tweaking the project files, you also need to edit PC/config.c Regards, Martin From ramiak2000 at yahoo.com Tue Aug 19 18:41:01 2003 From: ramiak2000 at yahoo.com (Rami A. Kishek) Date: Tue, 19 Aug 2003 18:41:01 -0400 Subject: Serious problem with Shelve References: <3F3FB5B9.5E49B306@yahoo.com> <3F41BC50.91097FAF@yahoo.com> Message-ID: <3F42A77D.FF3125AA@yahoo.com> Thanks. With your help, I figured out one of the databases accessed WAS created with an older Python, so I simply cleaned up that one and now everything works! >Skip Montanaro wrote: > >Andrew MacIntyre wrote: > From aleax at aleax.it Sun Aug 10 11:01:07 2003 From: aleax at aleax.it (Alex Martelli) Date: Sun, 10 Aug 2003 15:01:07 GMT Subject: Trying to embed python into C, help! References: <_usZa.986$rp4.4@news-binary.blueyonder.co.uk> Message-ID: disgracelands wrote: > I've been looking at using python and it's been going fairly well so far, > i can call C from python and python from C fine but now i've hit a snag > and i'm wondering how you guys have got around it. To be honest, I'm having some trouble understanding exactly what your snag IS. > I have to initialise python inside my C project so that i can make calls > to python modules whenever i need to but i can't create a dll for the > project as it's got to produce an exe or at least a lib so that i can > execute the initialisation code. ...but why ever would you WANT to "create a dll" and what does THAT have to do with "initializing Python"...? > The only way around it would seem to be to create a > separate dll project containing the python callback code that can then > import it to python and have my C code load it too. The problem with this I'm trying to guess, from this sentence, that you labor under a mis-apprehension that your C code, which embeds Python, can only provide "Python extension modules" by supplying them as a separate DLL. Is that what you mean by "the python callback code that can then import it to python"...? Sorry if my guess is way off, but really I find this sentence unparsable and incomprehensible. Anyway, if that's your 'snag', rest assured that there is no such need. Your C program can extend Python, creating modules that Python code can import, without any DLL whatsoever. For example, get the source distribution of Python [I don't think the demos come with e.g. the Windows installer binary] and look at source file Demo/embed/demo.c -- you'll see it adds to Python, as a static module, a module 'xyzzy' from which Python code could import and call, without arguments, a function 'foo'. Unfortunately the Python code executed in the demo doesn't show that ability being used, but at least you'll see 'xyzzy' listed among the "builtin modules"; just add two lines such as: PyRun_SimpleString("import xyzzy\n"); PyRun_SimpleString("print 'the answer is', xyzzy.foo()\n"); among the other calls to PyRun_SimpleString, and you'll see it work. Alex From member37516 at dbforums.com Sat Aug 30 13:48:30 2003 From: member37516 at dbforums.com (Baltor) Date: Sat, 30 Aug 2003 13:48:30 -0400 Subject: Newbie Tkinter problem... Message-ID: <3306631.1062265710@dbforums.com> I am trying to attach a scollbar to a text field. This is the code I am using: # Scroll Bar and Text Box self.scrollbar = Scrollbar(master, orient=VERTICAL) self.scrollbar.pack(side=RIGHT, fill=Y) self.text = Text(master, height=5, width=20, state=DISABLED, yscrollcommand=self.scrollbar.set) self.text.grid(row=2, column=1, rowspan=2) self.scrollbar.config(command=self.text.yview) When I run the program, the program freezes and I have to Ctrl-Alt- Delete put of it. What's wrong? Thanks in advance. -- Posted via http://dbforums.com From rodrigob at elo.utfsm.cl Wed Aug 27 22:38:36 2003 From: rodrigob at elo.utfsm.cl (Rodrigo Benenson) Date: Wed, 27 Aug 2003 22:38:36 -0400 Subject: Rebol Size References: <3f4a9b9d_2@nova.entelchile.net> Message-ID: <3f4d764f$1_2@nova.entelchile.net> Thanks for the comments, but I have a point: deployability. Rebol is not great or unique due of his features. It is cool because it is truly deployable. Everyone can download 500 kb and start playing with tiny scripts. Actually I'm develloping a collaborative editor using Python and Twisted. But it is a shine to distribute it (10 Mb downloads, with dependencies, scarry....). As python do not compile machine language and Twisted is huge, it is very difficult to distribute real word applications in python. I think that this is the major weakness of actual Python. cx_freeze, python2exe, etc... does not seems satisfactory solutions as much as I know, specially considering I'm a linux user. Maybe zipimport and the Python Packages Repository will provide in the near future more effective solutions (something like a Python Package Manager, with pseudo automatic installs ? ). RodrigoB. From koenig at v-i-t.de Thu Aug 21 18:17:22 2003 From: koenig at v-i-t.de (Mirko Koenig) Date: Fri, 22 Aug 2003 00:17:22 +0200 Subject: wxPython: need return value from wxFrame Message-ID: Hi I have a frame where you can select/add/delte etc a customer address. It is included in an wxApp to have a stand alone customer addressbook. Now i wrote a invoice application. I added a button to add a address to the invoice. I want the customer addressbook to be open by clicking on that button. No problem. So far so good. But i want the addressbook frame to return the selected address as a tuple, list or dict. I don't have any idea how to do that. I can show() the frame from within the invoice code but show doesn't return a value. I need something like a function that starts the frame and after i quited the frame the function returns the last address (self.lastAddress). Or are there any other ideas. Like saving the address in a global list (But thats not OO style i think) Mirko Koenig From tim.golden at viacom-outdoor.co.uk Wed Aug 27 04:12:30 2003 From: tim.golden at viacom-outdoor.co.uk (Tim Golden) Date: 27 Aug 2003 01:12:30 -0700 Subject: detecting document changes References: Message-ID: <8360efcd.0308270012.5e74e157@posting.google.com> "Cliff Wells" wrote in message news:... > On Sun, 2003-08-24 at 02:36, Alessandro Crugnola *sephiroth* wrote: > > How can I intercept document changes for active documents (for example > > modified with others external editors)? > > If you're on Linux (and perhaps other Unices) you can use FAM Don't know if this is exactly what you're after, but there are a couple of recipes on the Cookbook: This one deals with Linux: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/217829 and this one with Win32: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/156178 The MSDN docs on FindFirstChangeNotification tell you which flags you need to use for modification (as opposed to addition etc.): http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/findfirstchangenotification.asp HTH TJG From adalke at mindspring.com Sat Aug 16 15:38:40 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Sat, 16 Aug 2003 13:38:40 -0600 Subject: Why doesn't __call__ lead to infinite recursion? References: <2a82921f.0308151158.b8c9154@posting.google.com> Message-ID: Aahz: > No time to investigate further, but all your examples used classic > classes instead of new-style classes; I'm pretty sure that new-style > classes will more closely emulate the way functions work. There's also > the wrinkle I didn't mention that functions use a dict proxy IIRC. Interesting. Very interesting. >>> class XYZ(object): ... def __init__(self): ... def abc(x): ... print "Hello", x ... self.__call__ = abc ... def __call__(self, x): ... print "Yo", x ... >>> xyz = XYZ() >>> xyz("fred") Yo fred >>> >>> getattr(xyz, "__call__") >>> I wonder if this will affect any of my code. It does explain the observed differences better, since FunctionType in 2.3 is derived from object while my class was not. Andrew dalke at dalkescientific.com From bokr at oz.net Mon Aug 11 16:35:59 2003 From: bokr at oz.net (Bengt Richter) Date: 11 Aug 2003 20:35:59 GMT Subject: Fun with numbers - dammit, but I want a cast! References: <3f378fac$0$10778$afc38c87@auth.uk.news.easynet.net> <3f3792f2$0$18258$afc38c87@auth.uk.news.easynet.net> Message-ID: On Mon, 11 Aug 2003 14:38:24 GMT, Alex Martelli wrote: >Graham Nicholls wrote: > ... >>> xscale = xframe / float(img_x) >> >> Thats what I wanted to do, but was sure I'd read that python didn't have >> casts, and that _looks_ like a cast to me! > >Well, Python surely has the ability to create new objects, and the most >typical way to do that is to call a type, possibly passing it, as the >call's arguments, the value[s] that direct the new object's creation. > > >So, for example, if you have a string S and want to create a list L >whose items are the string's characters, you typically code: > >L = list(S) > > >Similarly, if you have a number N and want to create a float F whose >value is the floating-point equivalent of N's value, you code: > >F = float(N) > > >Whether these are "casts" is, I guess, a pretty moot issue. Me, I'd >call them "type calls" (or "explicit constructor calls" if I were in a C++ >mood:-), reserving the terminology "cast" for the C/Java notation: > > (sometype)somevalue > >or the C++ notations of forms such as: > > static_cast(somevalue) > >But, of course (in C++), explicitly calling a costructor of (e.g.) float, >with an integer argument; or statically casting an int to float; or even >using the old C-ish "prepended type in parenthesis" notation; have much >the same effect in most contexts. As long as you're quite clear that >what you're actually doing is "create a new value of a specified type >by calling the type with suitable argument[s]", rather than (the typical >idea of "cast") "reinterpreting an existing value AS IF it was of some >other type rather than of the type it actually is", it may not be a >problem if you like to call the operation "a cast". > I'd prefer adding the [] items in that last, to make it clear that a reinterpreting cast is about representations, not about the associated abstract values. I.e., "..., rather than (the typical idea of "cast") "reinterpreting an existing [representation of a] value AS IF it was [a representation] of some other type rather than [being a representation] of the type it actually is", ..." One of the things I like about Python is the apparent motivation to unify according to what makes sense with the abstract aspects of represented values (even though it may sometimes take some getting used to if one has been steeped in representational details for decades). E.g., one might find >>> [{1:'one'}[k] for k in [1, 1.0, 1L, 1e0]] ['one', 'one', 'one', 'one'] surprising at first ;-) Interesting also the way the initial key's representational type is retained even when an abstract-value-as-effective-key is used to change the associated value: >>> d = {1.0:'one'} >>> d[1] 'one' >>> d {1.0: 'one'} >>> d[1] = 'integer one' >>> d {1.0: 'integer one'} >>> d[1], d[1.0] ('integer one', 'integer one') And of course true division goes in the same direction. Regards, Bengt Richter From dave at pythonapocrypha.com Mon Aug 25 10:44:22 2003 From: dave at pythonapocrypha.com (Dave Brueck) Date: Mon, 25 Aug 2003 08:44:22 -0600 Subject: python gripes survey In-Reply-To: <3f4a703d$0$167$a1866201@newsreader.visi.com> References: <3f4a703d$0$167$a1866201@newsreader.visi.com> Message-ID: <200308250844.22766.dave@pythonapocrypha.com> On Monday 25 August 2003 02:23 pm, Grant Edwards wrote: > In article , Dave Brueck wrote: > > On Monday 25 August 2003 12:14 pm, Afanasiy wrote: > >> I have a bunch, many of them hard to define, but one that I just thought > >> of I find strange sometimes is the use of tuples as near-mystery return > >> values. I can't help but thinking a C struct with named fields is easier > >> to remember than a tuple with fields accessed by integer. > > [...] > > > A bit of an apples-to-oranges comparison, isn't it? If you prefer to > > return a named structure in C, the Python equivalent certainly wouldn't > > be a tuple. > > If you look at the library, it is. Ah, now I get it, thanks. This is such a goofy thread anyway, but I thought it was about language gripes, and in the general case a simple class is the Python analog to a C struct. > In instances where the "return" value to an ioctl or system > call is a C struct, the Python return value is often a tuple. > stat() leaps to mind as a good example. In that case, symbolic > indexes into the tuple are provided -- this mitigates the > situation somewhat. Even better, the commonly-used elements have os.path.get* acessors (os.path.getsize, getmtime, etc.). -Dave From aleaxit at yahoo.com Sun Aug 17 09:32:54 2003 From: aleaxit at yahoo.com (Alex Martelli) Date: Sun, 17 Aug 2003 15:32:54 +0200 Subject: Porting to Windows References: <814r0hfrlk.fsf@darwin.lan.kassube.de> Message-ID: Nils Kassube wrote: > Ramon Leon Fournier writes: > >> Porting software to Windows won't help anyone except Microsoft, not > > It helps to put food on the table. Case closed. Welcome to > reality. It's nice here, isn't it? Quite apart from potential monetary gain -- it is simply a false assertion that "porting software to Windows won't help anyone except Microsoft", even if one is doing the porting entirely for free. Consider my old ultralight laptop: I simply cannot run anything but Win/98 on it (Linux doesn't support its indispensable sleep and hybernate functions, nor its built-in modem, etc etc) -- and yet, for reasons of weight and ruggedness, that's the laptop I end up traveling with in by far most of my trips. So, for any given piece of software: if it can run on Win/98, then it's potentially available to me when I travel -- if it can't, I can only use that software at home, not on my frequent trips. It is clear, therefore, that "porting software to Windows" (win/98 in specific, in my case) can help ME -- assuming that software is any good, of course -- by letting me use it when I'm traveling. Incidentally, making one more piece of software available for Win/98 isn't going to help Microsoft in any way, of course -- they are not seeling Win/98 any more, nor even supporting it any longer. So, it can ONLY help people who have, in the past, purchased it, and for whom moving to other OS's on the same hardware may be a problem (laptops' modems and power-control a frequent cause of such problems). Porting to Win/XP is different, of course;-). Alex From syver-en+usenet at online.no Tue Aug 5 14:57:49 2003 From: syver-en+usenet at online.no (Syver Enstad) Date: 05 Aug 2003 20:57:49 +0200 Subject: command -- It works , on linux References: Message-ID: Alex Martelli writes: > Have you tried installing Gonnerman's "Alternative Readline", > http://newcenturycomputers.net/projects/readline.html ? I have > found it extremely useful to gain the gist of readline's > functionality on Windows installatons of Python. Ehemm... How do you use readline? What should it do? Does it work on 2.3? I tried installing but the readline function had a different function prototype so I guess it doesn't work. -- Vennlig hilsen Syver Enstad From mal at lemburg.com Tue Aug 12 11:26:19 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue, 12 Aug 2003 17:26:19 +0200 Subject: dist problem on osx In-Reply-To: References: <644f6688.0308101518.ad9e02a@posting.google.com> <3F3786FC.5020703@lemburg.com> Message-ID: <3F39071B.6030707@lemburg.com> Ronald Oussoren wrote: > > On Monday, 11 August, 2003, at 14:07, M.-A. Lemburg wrote: > >> rdack wrote: >> >>> osx 10.2.6 python 2.2.1 (built in) >>> says my architecture is both 386 and ppc. >>> also has a path with a space in it that won't work. >>> where can i change these settings? >>> -------- >>> gcc -arch i386 -arch ppc -bundle -flat_namespace -undefined suppress >>> build/temp.darwin-6.6-Power >>> Macintosh-2.2/mx/DateTime/mxDateTime/mxDateTime/mxDateTime.o >>> -L/usr/local/lib -L/usr/lib -o build/lib.darwin-6.6-Power >>> Macintosh-2.2/mx/DateTime/mxDateTime/mxDateTime.so >>> --------------- >> >> >> This is a bug in distutils. It's fixed in Python 2.2.3. > > > The two architectures are not a bug in distutils, but a bug in the way > Apple build python. The '-arch i386' is annoying but harmless, if it > really annoys you you can change /usr/lib/python2.2/config/Makefile. > Search for '-arch i386' and remove this. I was referring to the spaces in the platform string generated by distutils. The -arch i386 look funny in there... hmm, perhaps we'll get Mac OS X / i386 sometime soon ?! ;-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 12 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From LISTSERV at NIC.SURFNET.NL Tue Aug 19 18:21:54 2003 From: LISTSERV at NIC.SURFNET.NL (L-Soft list server at SURFnet (The Netherlands) (1.8d)) Date: Wed, 20 Aug 2003 00:21:54 +0200 Subject: Message ("Your message dated Tue, 19 Aug 2003 17:21:55...") Message-ID: Your message dated Tue, 19 Aug 2003 17:21:55 --0500 with subject "Thank you!" has been submitted to the moderator of the TEX-NL list: "Jules van Weerden, DIVA, VET, UU, NL" . From fgeiger at datec.at Thu Aug 14 10:32:14 2003 From: fgeiger at datec.at (F. GEIGER) Date: Thu, 14 Aug 2003 16:32:14 +0200 Subject: 3 new slogans References: Message-ID: <3f3b9cfe@news.swissonline.ch> Years ago I read in Usenet "Less code, more results". Was it in a VB group? I forgot. Anyway, it really applies to Python. "Python - less code, more results". Cheers Franz "smarter_than_you" schrieb im Newsbeitrag news:c60a5a12.0308131950.1b3c46cb at posting.google.com... > 1) Python made me rich > 2) Python saved my life > 3) Python changed my mind > > put them on T-shirts. Collect all three!! From skip at pobox.com Mon Aug 18 11:24:10 2003 From: skip at pobox.com (Skip Montanaro) Date: Mon, 18 Aug 2003 10:24:10 -0500 Subject: slight csv misbehavior under Windows In-Reply-To: References: Message-ID: <16192.61338.228862.168778@montanaro.dyndns.org> Thomas> produces lines ending 0d0d0a, and when you load this into Excel Thomas> 97 the data appears double-spaced. Thomas> Opening the file with 'wb' solves the problem, but it would be Thomas> lovely were this either fixed or documented; it's rather Thomas> unintuitive that a file opened with 'wb' still ends lines with Thomas> 0d0a. It is documented. You have to open CSV files in binary mode. In the csv module docs it states the following for both the reader and writer factory functions: If csvfile is a file object, it must be opened with the 'b' flag on platforms where that makes a difference. It makes a difference on Windows, so you need to use 'b'. Skip From afriere at yahoo.co.uk Mon Aug 4 02:15:56 2003 From: afriere at yahoo.co.uk (Asun Friere) Date: 3 Aug 2003 23:15:56 -0700 Subject: IDLE function 'tooltips' Message-ID: <38ec68a6.0308032215.2db836c0@posting.google.com> I'm just trying out Python 2.3's IDLE and was wondering how you turn off the 'tooltipping' that comes up whenever you write out a function and open the first parenth. I can't seem to find the option for it in 'Configure IDLE'. cheers, From sdhyok at yahoo.com Fri Aug 8 15:15:53 2003 From: sdhyok at yahoo.com (sdhyok) Date: 8 Aug 2003 12:15:53 -0700 Subject: How to print floating point in scientific format? Message-ID: <420ced91.0308081115.7060e551@posting.google.com> I want to change the DEFAULT behavior of python to print out all floating points in scientific format? For instance, >x=0.01 >print x 1.000000E-2 #Like print "%E"%x How can I do it? Daehyok Shin From vanevery at 3DProgrammer.com Mon Aug 18 18:00:31 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Mon, 18 Aug 2003 15:00:31 -0700 Subject: What's better about Rattlesnakes than Pythons? References: <8e482ba2.0308171939.7de4a288@posting.google.com> <3F40E4F3.6010809@users.ch> Message-ID: Gary D. Duzan wrote: > In article <3F40E4F3.6010809 at users.ch>, Borcis > wrote: >> Graham Fawcett wrote: >>> >>> Any snake born in Java will perform better >> >> http://www.herpafauna.com/pics/pythons/retic-java.html >> >> is in the 9-meters league; no competitors, except the anaconda. >> > > I assume they are called "jythons" for short... Rather than for long? -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From davidb at mcs.st-and.ac.uk Thu Aug 28 19:10:28 2003 From: davidb at mcs.st-and.ac.uk (David Boddie) Date: 28 Aug 2003 16:10:28 -0700 Subject: getopt issues References: Message-ID: <4de76ee2.0308281510.2e044576@posting.google.com> David Bear wrote in message news:... > good points. yet, my purpose is to write a filter. the problem being > that with different lpr implementations you don't know exactly what > parameters will be passed since lpr is not really standardize (at least > thats my understanding). I'm just interested in two parameters out of > possibly many. Can't you specify all the possible parameters and collect only those you want, or are you dealing with conflicting specifications of certain options? > Still, I think getopt is rather weak. It would be better if I could build > a dictionary of options that I wanted, then when parsing the args, just > fill in my dictionary values from args that I want. As an aside, since it doesn't deal with cases where the option is concatenated with the following parameter, you might find cmdsyntax interesting since it aims to populate dictionaries with appropriately named entries for the command line input: http://www.boddie.org.uk/david/Projects/Python/CMDSyntax/index.html It will also try and parse the arguments and return a list of failed matches if requested. However, it may well be overkill for your purposes. David From mschneider.pad at t-online.de Mon Aug 18 14:29:18 2003 From: mschneider.pad at t-online.de (Marcus Schneider) Date: 18 Aug 2003 11:29:18 -0700 Subject: closing a widget References: <3f443b52.0308171454.c00a287@posting.google.com> Message-ID: <3f443b52.0308181029.6c4279fb@posting.google.com> in the meantime I found a work around, but "there is only one mainloop" confuses ME ;) When I generate a GUI with page, the function to open the window looks like: def vp_start_gui(): global w global root root = Tix.Tk() root.title('xyz') w = Klassenname (root) init() root.mainloop() If I use for different windows different variables (like root1, root2 etc) and use commands like "root1.mainloop" and "root2.mainloop", shouldn't I get one mainloop per window? Regarding your questions: I open the new windows rather independently in the same way as described above. I close windows based on a button pressed. With quitting a windows I refer to the quit method. Hope that clearifies it to a certain degree;) "Michael Peuser" wrote in message news:... > "Marcus Schneider" schrieb im Newsbeitrag > news:3f443b52.0308171454.c00a287 at posting.google.com... > > Normally I close my windows/widgets with destroy and it works fine. > > Now I have a window (let's call it 1) from where I open an additional > > window (let's call it 2). > > Do you mean you make (1) the basis of a Toplevel (2) ? > > I close it. > > (2) ? By a button created on that Toplevel ? > > > Each window has its own main loop. > > There can only be one mainloop. No idea what happens, when you call mainloop > during in an event-routine. Never do it! > > > Now I want to open another window outside the mainloop of window 1. > > What do you mean by this? > > > So > > I quit that mainloop. > > How can you do that? What at all do you mean by "mainloop"? Tkinter.mainloop > I presume? > > > go to > > GOTO? > > > a new window, destroy that, enter the > > mainloop of window 1 again and finally exit with destroy. > > > > All this works in princial.... > > This is a surprises to me... > My be I really do not understand what you are doing..... > > Kindly > Michael P. > > [....] From elainejackson7355 at home.com Sun Aug 17 19:26:23 2003 From: elainejackson7355 at home.com (Elaine Jackson) Date: Sun, 17 Aug 2003 23:26:23 GMT Subject: bitwise not - not what I expected References: <1YD%a.747879$3C2.17342633@news3.calgary.shaw.ca> Message-ID: "Michael Peuser" wrote in message news:bhosrr$u57$06$1 at news.t-online.com... | I have the impression (may be wrong) that you are working under the | misconception that there can be a "natural" binary represensation of | negative numbers!? | Three conventions have commonly been used so far: | 1- Complement | 2-Complement | Sign tag plus absolut binary values The last alternative sounds like what I was assuming. If it is, I would argue that it's pretty darn natural. Here's a little function to illustrate what I mean: def matilda(n): ## "my tilde" if 0<=n References: Message-ID: <16192.62711.5747.569850@montanaro.dyndns.org> pd> I was wondering if anyone knew of any efforts to get python working pd> on the symbian platform? What's symbian? Skip From nemesis at nowhere.invalid Sun Aug 24 05:17:32 2003 From: nemesis at nowhere.invalid (Nemesis) Date: Sun, 24 Aug 2003 09:17:32 GMT Subject: X-faces decoding with Python Message-ID: Hi all, I'm looking for a x-faces decoder written in python, I'd like to include it in my project. I only found a C-module (part of the Facemail mailer) that requires python's header files for the building process. Can anyone help me? -- When your IQ rises to 28, sell. |\ | |HomePage : http://digilander.libero.it/nemesis2001/ | \|emesis |XPN (my nr): http://digilander.libero.it/nemesis2001/Xpn.html From jonathan.hayward at pobox.com Sat Aug 16 20:51:28 2003 From: jonathan.hayward at pobox.com (Jonathan Hayward) Date: 16 Aug 2003 17:51:28 -0700 Subject: Help pickling across sockets Message-ID: I'm trying to have a client open a socket, send two pickled hashes, and receive a pickled object (I'm also writing the server, to listen, read two pickled hashes, and send a pickled object). I've been able to boil down what doesn't work to a small demo case: ____________________________________________________________ SERVER: #!/usr/bin/python import cPickle, socket sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock.bind(("", 1234)) sock.listen(5) try: newsocket, address = sock.accept() sockOut = newsocket.makefile("wb") sockIn = newsocket.makefile("rb") cPickle.load(sockIn) cPickle.load(sockIn) cPickle.dump("Hello, world!", sockOut) newsocket.close() sockOut.close() sockIn.close() finally: sock.close() ____________________________________________________________ CLIENT: #!/usr/bin/python import cPickle, socket sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect(("127.0.0.1", 1234)) sockOut = sock.makefile("wb") sockIn = sock.makefile("r") cPickle.dump({}, sockOut) cPickle.dump({}, sockOut) response_data = cPickle.load(sockIn) print response_data sockOut.close() sockIn.close() sock.close() ____________________________________________________________ When I start the server and then start the client, they both hang, as has happened with the real script. Can you tell me what I am misusing and preferably how to correct it? TIA, ++ Jonathan Hayward, jonathan.hayward at pobox.com ** To see an award-winning website with stories, essays, artwork, ** games, and a four-dimensional maze, why not visit my home page? ** All of this is waiting for you at http://JonathansCorner.com From __peter__ at web.de Fri Aug 22 18:05:49 2003 From: __peter__ at web.de (Peter Otten) Date: Sat, 23 Aug 2003 00:05:49 +0200 Subject: visual indentation References: Message-ID: Hilbert wrote: > Is there any way to use such "visual" indentation in python? Whitespace *is* significant in Python, and you should not try to circumvent this using dirty tricks. Why not structuring your world definitions in the standard way, putting the things that belong together in separate functions or classes? #disclaimer: no knowledge of CGKit involved in the following code WHITE = (1.0,1.0,1.0) def whitesurface(): RiColor(*WHITE) RiSurface('constant') def firstworld(): whitesurface() RiSphere(1.0,-1.0,1.0,360) def secondworld(): whitesurface() RiSphere(1.0,-1.0,1.0,360) for world in [firstworld, secondworld]: RiWorldBegin() world() RiWorldEnd() I think the above is pretty readable, and you can always factor out repeating chunks of code Peter From bokr at oz.net Tue Aug 12 11:37:11 2003 From: bokr at oz.net (Bengt Richter) Date: 12 Aug 2003 15:37:11 GMT Subject: Returning a string from a boolean References: Message-ID: On Tue, 12 Aug 2003 12:26:07 +0000 (UTC), Duncan Booth wrote: >Dan Rawson wrote in >news:bhalml$1012pe$1 at ID-122008.news.uni-berlin.de: > >> In Perl I can do this with the ternary 'if' >> >> (bVar) ? 'True' : 'False' >> >> >> Is there a simpler way in Python?? >> >> If it makes a difference, I'm using 2.2.2 (on Solaris) with no chance >> of going to 2.3 in the near future ; I know that some of this has >> changed in 2.3. >> >Python 2.2 and earlier, the shortest way is: > > return bVar and 'True' or 'False' >or > return ('True','False')[not bVar] > >Both of the above will test the truth value of bVar, so for example an >empty string or empty list will return False. Personally, I would go for >your original function as combining clarity with reasonable but not >excessive brevity. > >In Python 2.3, str(bVar) will give you 'True' or 'False' as appropriate, >but only if bVar is a bool. which you can ensure by str(bool(anyvar)) ;-) Regards, Bengt Richter From tzot at sil-tec.gr Tue Aug 19 12:29:00 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Tue, 19 Aug 2003 19:29:00 +0300 Subject: itertools.ilen? References: <98s4jvkqv94c0gj99epjanq9b3aqvq8i2q@4ax.com> Message-ID: On Fri, 8 Aug 2003 10:02:39 +0000 (UTC), rumours say that Duncan Booth might have written: >I'm just curious, why did you decide to map the types to strings instead of >just using the types themselves? >e.g. > >>>> import gc >>>> sums = {} >>>> for obj in gc.get_objects(): > if type(obj) not in sums: > sums[type(obj)] = 1 > else: > sums[type(obj)] += 1 Just because the initial code treated functions and methods as same; also to be output-friendly. I offered code with similar functionality, only more concise, it wasn't code for my use :) -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From logiplex at qwest.net Tue Aug 12 18:55:03 2003 From: logiplex at qwest.net (Cliff Wells) Date: Tue, 12 Aug 2003 15:55:03 -0700 Subject: Python should try to displace Java In-Reply-To: References: Message-ID: <1060728902.4769.100.camel@software1.logiplex.internal> On Mon, 2003-08-11 at 23:31, Michael Geary wrote: > I am being educated here. Is that what trolls do? :-) Only if you're interested in social engineering. -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 (800) 735-0555 From jasongorman at blueyonder.co.uk Sun Aug 10 08:41:02 2003 From: jasongorman at blueyonder.co.uk (jason) Date: 10 Aug 2003 05:41:02 -0700 Subject: Free OO & UML tutorials References: <5e90cdd2.0308090327.27815766@posting.google.com> Message-ID: <5e90cdd2.0308100441.786cb299@posting.google.com> jasongorman at blueyonder.co.uk (jason) wrote in message news:<5e90cdd2.0308090327.27815766 at posting.google.com>... > There are some great free tutorials on OOA/D, UML, Design Patterns, > Test-driven Development, Usability Engineering and heaps of other good > stuff at http://www.objectmonkey.com Oh, and keep an eye out for more tutorials over the coming weeks! From theller at python.net Wed Aug 6 12:36:21 2003 From: theller at python.net (Thomas Heller) Date: Wed, 06 Aug 2003 18:36:21 +0200 Subject: Interactive Console in embedded Python References: Message-ID: "Pablo Yabo" writes: > Is it possible to get the string of the error messages instead of using > PyErr_Print? > Hi, > I'm runing some python code from a C++ win32 application. > I need a tool to debug the code in python that I run. > I would like to know if I can run a interactive console to dump objects, > etc. Yes. Exactly how you would do it in Python itself, only more verbose. /* Modeled after a function from Mark Hammond. Obtains a string from a Python traceback. This is the exact same string as "traceback.print_exception" would return. Result is a string which must be free'd using PyMem_Free() */ #define TRACEBACK_FETCH_ERROR(what) {errMsg = what; goto done;} char *PyTraceback_AsString(void) { char *errMsg = NULL; /* holds a local error message */ char *result = NULL; /* a valid, allocated result. */ PyObject *modStringIO = NULL; PyObject *modTB = NULL; PyObject *obStringIO = NULL; PyObject *obResult = NULL; PyObject *type, *value, *traceback; PyErr_Fetch(&type, &value, &traceback); PyErr_NormalizeException(&type, &value, &traceback); modStringIO = PyImport_ImportModule("cStringIO"); if (modStringIO==NULL) TRACEBACK_FETCH_ERROR("cant import cStringIO\n"); obStringIO = PyObject_CallMethod(modStringIO, "StringIO", NULL); /* Construct a cStringIO object */ if (obStringIO==NULL) TRACEBACK_FETCH_ERROR("cStringIO.StringIO() failed\n"); modTB = PyImport_ImportModule("traceback"); if (modTB==NULL) TRACEBACK_FETCH_ERROR("cant import traceback\n"); obResult = PyObject_CallMethod(modTB, "print_exception", "OOOOO", type, value ? value : Py_None, traceback ? traceback : Py_None, Py_None, obStringIO); if (obResult==NULL) TRACEBACK_FETCH_ERROR("traceback.print_exception() failed\n"); Py_DECREF(obResult); obResult = PyObject_CallMethod(obStringIO, "getvalue", NULL); if (obResult==NULL) TRACEBACK_FETCH_ERROR("getvalue() failed.\n"); /* And it should be a string all ready to go - duplicate it. */ if (!PyString_Check(obResult)) TRACEBACK_FETCH_ERROR("getvalue() did not return a string\n"); { // a temp scope so I can use temp locals. char *tempResult = PyString_AsString(obResult); result = (char *)PyMem_Malloc(strlen(tempResult)+1); if (result==NULL) TRACEBACK_FETCH_ERROR("memory error duplicating the traceback string\n"); strcpy(result, tempResult); } // end of temp scope. done: /* All finished - first see if we encountered an error */ if (result==NULL && errMsg != NULL) { result = (char *)PyMem_Malloc(strlen(errMsg)+1); if (result != NULL) /* if it does, not much we can do! */ strcpy(result, errMsg); } Py_XDECREF(modStringIO); Py_XDECREF(modTB); Py_XDECREF(obStringIO); Py_XDECREF(obResult); Py_XDECREF(value); Py_XDECREF(traceback); Py_XDECREF(type); return result; } From duncan-news at grisby.org Fri Aug 8 12:29:32 2003 From: duncan-news at grisby.org (Duncan Grisby) Date: Fri, 08 Aug 2003 16:29:32 +0000 Subject: omniORB 4.0.2 and omniORBpy 2.2 released Message-ID: <2428b$3f33cfec$516049d2$15672@nf1.news-service.com> omniORB version 4.0.2 and omniORBpy 2.2 are now available. omniORB is a robust, high performance CORBA ORB for C++. omniORBpy is a version for Python. They are freely available under the terms of the GNU LGPL. These are mainly bug fix releases. Highlights of the new releases include: - Bug fixes. - Use of standard iostreams in omniNames etc., if available. - Rudimentary Python interceptor support. - Performance improvements. The releases can be downloaded from SourceForge from this page: http://sourceforge.net/project/showfiles.php?group_id=51138 For general omniORB details, see this page: http://omniorb.sourceforge.net/ Enjoy! Duncan. -- -- Duncan Grisby -- -- duncan at grisby.org -- -- http://www.grisby.org -- From adalke at mindspring.com Sun Aug 24 14:01:19 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Sun, 24 Aug 2003 18:01:19 GMT Subject: python gripes survey References: <7s6gkv031b940dsc522pbh5g30q4nj5vd1@4ax.com> Message-ID: Ryan Lowe: > > >>> d = {1: "a"} > > >>> d.update({True: "b"}) > > >>> d > > {1: 'b'} > > that is weird; i thought 2.3 made bool its own type? but i guess its still a > subtype of int. though, i cant imagine when this would come up in a real > situation anyway. Let k1 and k2 be two keys. If k1==k2 then dicts consider that either one may be used as the key. Since 1 exists in d, and 1 == True (== 1.0, == complex(1,0)) then the update keeps the old key rather than do the extra work of replacing it. It isn't quite this easy. k1 and k2 must also have aligned hashs, which is used to prune the number of == tests done. > > code blocks (like Smalltalk) > > is this what it sounds like? do you name a block of code and call it like an > inline function with no parameters? Consider the following Ruby code [ 1, 3, 5 ].each { |i| puts i } The |i| puts i is an *unnamed* code block which does take parameters. The [] is a container, and [].each sends the code block to each of the elements in the container. See http://www.rubycentral.com/book/tut_containers.html > i learned and forgot what lazy evaluation was. does it buy you anything > other than speed in certain cases Sometimes it's easier to work with infinite sets directly rather than work on iterators going through infinite sets. Eg, suppose you wanted the first 5 primes which were fibonacci sequences. Then you can do something like (primes && fibonacci)[:5] > > rich N-dimensional operators (like APL) > > python could do the same with functions or named operators Sure. But they aren't built-in, and there is something cool about using non-ASCII symbols in your code. (As someone with a now-dusty math degree, I am pretty used to glyphs like greek letters in my work.) > > symbolic math manipulation (like Mathematica) > > this is approaching the limited domain area. plus mathematica spent a LOT of > money and time writing that software. its not something your average > open-sourcer would probably wish to tackle in their spare time. of course, > it would be nice to have a symbolic module :) Agreed for the first. The point remains that it is something which Python doesn't have. It could be added as modules, but Mathematica's syntax makes it easier to express some equations than Python does. > > color as part of syntax (like ColorForth) > > color meaning built-in? this i have never heard of. how does it work? Google. "color forth". "I'm feeling lucky" http://www.colorforth.com/ ] In Forth, a new word is defined by a preceeding colon, words inside ] a definition are compiled, outside are executed. In colorForth a new ] word is red, green words are compiled, yellow executed. This use of ] color further reduces the syntax, or punctuation, needed. It also makes ] explicit how the computer will interpret each word. > > predicate logic (like Prolog) > > literate programming (like WEB -> Pascal/TeX) > > aspect-oriented programming (like AspectJ) > > stack nature (like Postscript (I had Forth here but didn't want a dup > :)) > > programming by contract (like Eiffel) > > can any of these be explained quickly? Google. "predicate logic" prolog. "I'm feeling lucky" http://remus.rutgers.edu/cs314/f2002/uli/lectures/lec24.pdf Google. "literate programming" web. "I'm feeling lucky" http://www.literateprogramming.com/ Google. "aspect-oriented programming". "I'm feeling lucky" http://aosd.net/ Google. "FORTH". "I'm feeling lucky". Browse a few links to the FAQ ftp://ftp.forth.org/pub/Forth/FAQ/general Here's another route. Go to FOLDOC ("Free on-line dictionary of computing"). Search for "FORTH" ] 1. An interactive extensible language using postfix ] syntax and a data stack, developed by Charles H. Moore in ] the 1960s. Follow the link for "postfix notation" http://wombat.doc.ic.ac.uk/foldoc/foldoc.cgi?postfix+syntax "Programming by contract" should be "Design by contract". In addition to Google for these searches, try the PPR wiki, eg http://c2.com/cgi/wiki?DesignByContract Andrew dalke at dalkescientific.com From bignose-hates-spam at and-benfinney-does-too.id.au Sat Aug 2 19:25:48 2003 From: bignose-hates-spam at and-benfinney-does-too.id.au (Ben Finney) Date: 3 Aug 2003 09:15:48 +0950 Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> <87el06d2i6.fsf@pobox.com> Message-ID: On Sat, 02 Aug 2003 23:31:44 GMT, Andy C wrote: > OK, then unless I'm missing something, tabs vs. spaces shouldn't > matter for you. The editor should be able to handle tabs in a > satisfactory manner as well. Not if spaces *and* tabs are used for indentation within the one file. Without editor-specific hacks (the "vim:" comment line, the Emacs mode line, etc.) there's no way to know what size the previous person's editor had tab stops set to. The standard size of a tab stop is 8, but many programmers change this in their editors, resulting in indentation that gets completely messed up when the tabs are shown at 8 columns against other lines in the same file that use spaces for indentation. -- \ "The best is the enemy of the good." -- Voltaire | `\ | _o__) | Ben Finney From syver-en+usenet at online.no Sun Aug 10 16:06:09 2003 From: syver-en+usenet at online.no (Syver Enstad) Date: 10 Aug 2003 22:06:09 +0200 Subject: Trying to embed python into C, help! References: <_usZa.986$rp4.4@news-binary.blueyonder.co.uk> Message-ID: "disgracelands" writes: > To be honest the entire idea of using dlls puzzled me since python > isn't platform dependant but thats the way its done in the > tutorials. The chances are that i've mis-interpreted something. You don't have to use .dll to extend python. You can compile it statically into the interpreter. classes such as str and dict are compiled into the interpreter statically (as far as I know). On platforms where some sort of dynamic linking is available such as linux and win32, python supports linking dynamically with that platforms dynamic link library type. That type is .dll for win32. Clear? -- Vennlig hilsen Syver Enstad From simon_place at whsmithnet.co.uk Thu Aug 7 13:31:47 2003 From: simon_place at whsmithnet.co.uk (simon place) Date: Thu, 07 Aug 2003 18:31:47 +0100 Subject: Hints about a script that read ftp contents .... In-Reply-To: References: Message-ID: <3f328d06_1@mk-nntp-1.news.uk.worldonline.com> another idea the distribution included module 'ftputil' has a walk function to move through a ftp directory structure and apply a function to the directory/file name. From NAICH-SYDNEYCH-EXCHANGE at cowleyhearne.com.au Fri Aug 22 00:23:17 2003 From: NAICH-SYDNEYCH-EXCHANGE at cowleyhearne.com.au (GroupShield for Exchange (CH-EXCHANGE)) Date: Fri, 22 Aug 2003 14:23:17 +1000 Subject: ALERT - GroupShield ticket number OA1108_1061526193_CH-EXCHANGE_ 3 was generated Message-ID: <540F61BD2C9BD64DA18FCB9B7367424D89776A@CH-EXCHANGE.cowleyhearne.com.au> Action Taken: The attachment was quarantined from the message and replaced with a text file informing the recipient of the action taken. To: sneal at cowleyhearne.com.au From: python-list at python.org Sent: 1882508544,29583461 Subject: Re: Your application Attachment Details:- Attachment Name: document_all.pif File: document_all.pif Infected? No Repaired? No Blocked? Yes Deleted? No Virus Name: -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/ms-tnef Size: 1966 bytes Desc: not available URL: From harry.g.george at boeing.com Mon Aug 18 13:21:24 2003 From: harry.g.george at boeing.com (Harry George) Date: Mon, 18 Aug 2003 17:21:24 GMT Subject: python & postgresql ? References: Message-ID: Skip Montanaro writes: > Tom> I'm trying to develop a cross-platform python-gui for a postgresql > Tom> db. Of course, I need some postgresql-module for python... > Tom> Pygresql seems the obvious choice, but I'm developing on windows > Tom> xp. To get pygresql to work I need to compile pygresql with a > Tom> visual c++ compiler (wich I don't have). > > I think you're going to have to find a way to compile C code on your machine > (mingw, cygwin, etc) or find a binary distribution of one of the PostgreSQL > modules. I use psycopg. You should be able to find a binary installer for > one of the possibilities. > > You could also start development on Linux and when it's good enough, maybe a > Windows person will step in to help out. > > Skip > pypgsql has binaries for win32 on sourceforge. I haven't used it (I use pypgsql on Linux). http://pypgsql.sourceforge.net/ -- harry.g.george at boeing.com 6-6M31 Knowledge Management Phone: (425) 342-5601 From newsgroups at jhrothjr.com Sun Aug 3 06:49:11 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Sun, 3 Aug 2003 06:49:11 -0400 Subject: time, calendar, datetime, etc References: Message-ID: "Dennis Lee Bieber" wrote in message news:h9euv-4l3.ln1 at beastie.ix.netcom.com... > Tim Peters fed this fish to the penguins on Friday 01 August 2003 07:30 > pm: > > > Gregorian calendar in Dershowitz and Reingold's highly regarded > > "Calendrical Calculations": > > > > http://emr.cs.iit.edu/home/reingold/calendar-book/second-edition/ > > > > So people who want umpteen kinds of calendars Guido doesn't care about > > can look up algorithms in that book to do conversion to and from > > datetime's view > > Pity the book uses LISP (at least, the first edition did)... Even > BASIC would be more accessible to most folks (though I would prefer > a modern BASIC over G-whiz or older). That's the version I have (somewhere.) As I've said a couple of times, it's not the lack of built-in support for all kinds of strange calendars that's the problem: it's the decision to limit the time span to 1AD. John Roth > > > -- > > ============================================================== < > > wlfraed at ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG < > > wulfraed at dm.net | Bestiaria Support Staff < > > ============================================================== < > > Bestiaria Home Page: http://www.beastie.dm.net/ < > > Home Page: http://www.dm.net/~wulfraed/ < > From faizan at jaredweb.com Tue Aug 5 01:00:09 2003 From: faizan at jaredweb.com (Fazer) Date: 4 Aug 2003 22:00:09 -0700 Subject: Python and cron jobs. References: <7b454334.0308041023.6e688b4d@posting.google.com> Message-ID: <7b454334.0308042100.48dc33f4@posting.google.com> Lee Harr wrote in message news:... > In article <7b454334.0308041023.6e688b4d at posting.google.com>, Fazer wrote: > > Hello, > > > > I am wondering that if it is possible to add cron jobs via a web or > > shell interface? I can make Python act as a shell script and be > > called by a PHP script. But my main goal here is to be able to manage > > cronjobs. Add or remove certain crjob jobs etc... > > > > Can any kind soul shed some light on how I would accomplish this? > > > > > I think adding them from the shell is probably the "normal" way. > For adding cron jobs from the web, you might look at webmin. > > Basically, the crontab is just a file, so if you can edit the file > from your program and then force cron to reload the crontab you > are all set. Thanks for your reply. I thought that crontab was directory? I don't require webmin, I need a script that would add the cron job and possible force the cron to reload as you said. Do you know how may I accomplish this? From bkelley at wi.mit.edu Thu Aug 21 11:03:11 2003 From: bkelley at wi.mit.edu (Brian Kelley) Date: Thu, 21 Aug 2003 11:03:11 -0400 Subject: [OT] Why is it called string? In-Reply-To: <3f44d6d5$0$571$b45e6eb0@senator-bedfellow.mit.edu> References: <3f44ce77$0$556$b45e6eb0@senator-bedfellow.mit.edu> <3f44d6d5$0$571$b45e6eb0@senator-bedfellow.mit.edu> Message-ID: <3f44deef$0$578$b45e6eb0@senator-bedfellow.mit.edu> This just goes to show that what is visible is usually the tip of the iceberg. It turns out that the term "linguistic string" has been in use for a long time in the linguistics community to describe language syntax. Zellig Harris apparently used the term in some of his work (published around 1936). In 1965 Naomi Sager used "linguistic string" theory to form the Linguistic String Project mainly used as an application toward medical documents using a controlled medical vocabulary. linguistic string n : a linear sequence of words as spoken or written [syn: string, string of words, word string] The earliest paper I can find directly related to Linguistic strings is: Linguistic String Analysis (1960) Naomi Sager, NYU ALthough I'm fairly sure the term was widely used in the liguistic community in the 1950's. So it seems that, indeed, the Incan's were first :) -- Brian Kelley bkelley at wi.mit.edu Whitehead Institute for Biomedical Research 617 258-6191 From edilmar at intersite.com.br Wed Aug 6 10:11:16 2003 From: edilmar at intersite.com.br (Edilmar) Date: 6 Aug 2003 07:11:16 -0700 Subject: Is there some Python + IDE/RAD for real speed development??? Message-ID: <96fda9ac.0308060611.56dfca7e@posting.google.com> Hi, First of all, I'm new in Python... I have worked with manu langs and IDEs, like Delphi, VB, JBuilder, Eclipse, Borland C++, Perl, etc... Then, today I think IDEs like Delphi have a excelent environment to develop apps with little time. I saw many people talking about Python like a easy lang to learn and to develop. But I have look at IDEs for Python, or ways to develop GUIs with it, and I think it already is limited when comparing with IDEs like Delphi. Is this afirmation true? I look at wxPython and PyGTK, but the samples showed that we have to write MANY LINES of code to do simple things. Many people have wrote about the advantage of Python to write little code, but, when talking about GUIs, I think it's not really true, right? Using Delphi, little or none code is need for many things, but wxPython and PyGTK is the reverse! Thanks for any replies, From pythonguy at Hotpop.com Tue Aug 19 02:44:40 2003 From: pythonguy at Hotpop.com (Anand Pillai) Date: 18 Aug 2003 23:44:40 -0700 Subject: Problem with garbage collection (sort of) References: <246a4e07.0308180608.2b8d685a@posting.google.com> Message-ID: <84fc4588.0308182244.71ddf596@posting.google.com> The problem you are describing is one of 'cyclical' references. This happens when obj A holds a reference to obj B and obj B holds a reference to obj A. One way to work around this is to implement a global registry object which stores all the objects in its dictionary using names as keys. In your code you would no longer need references to objects inside your classes but just look them up from the global regsitry using something like this. myobj=myglobals.lookup('myobject') myobj.performsomeaction() ... Now since myobj is of local scope and not of class scope (self...) python gc immmediately garbage collects it. But the original object still remains active in the global registry. At the exit of your program write a hook to sys.exitfunc which cleans up this global registry. I had a similar problem in one of my projects and implemented this using Alex Martelli's "borg" non-pattern. The code is available in my harvestman project page at http://members.lycos.co.uk/anandpillai I have not yet got around to testing the actual benefits in gc I gained from this approach yet :-) -Anand aahz at pythoncraft.com (Aahz) wrote in message news:... > In article <246a4e07.0308180608.2b8d685a at posting.google.com>, > Frank Millman wrote: > > > >y is an instance of class c, which creates an instance of class b, > >which creates an instance of class a. When y goes out of scope and is > >deleted, I want the instances of class b and class a to be deleted as > >well. > > Works for me in Python 2.2.3; what version are you using? From ubecher at gmx.net Fri Aug 29 10:51:57 2003 From: ubecher at gmx.net (Uwe Becher) Date: Fri, 29 Aug 2003 16:51:57 +0200 Subject: NetServerDiskEnum in win32net In-Reply-To: <8360efcd.0308290052.4e0e6f67@posting.google.com> References: <8360efcd.0308290052.4e0e6f67@posting.google.com> Message-ID: Tim Golden wrote: > Uwe Becher wrote in message news:... > >>I try to get all logical drives of a remote machine (WinNT or W2K) and >>get a result, that gives me the expected total but not all expected drives. >> >>Example: >> >> >>> win32net.NetServerDiskEnum('nor1w020', 0) gives me: >>([u'A:', u'', u'C:', u'', u'D:', u'', u'E:', u''], 8, 0) >> >>while the machine has the local drives >>A: C: D: E: F: G: H: Z: >>A: - Floppy >>Z: - CDROM >>All others are harddisk partitions on two physical drives >> >>Does anyone have an idea? >> >>Thanks >>Uwe > > > I had the same problem, and to my shame I didn't raise it as a bug, I > simply bypassed it (because my DBA needed the info immediately anyway) > by using wmi. Have a look at > http://tgolden.sc.sabren.com/python/wmi.html and then try something > like this: > > > > import wmi > c = wmi.WMI ("") # or whatever host name > > for disk in c.Win32_LogicalDisk (DriveType=3): > print disk.Caption > > > > TJG Tim, that did the job, thanks! From shalehperry at comcast.net Wed Aug 13 02:06:48 2003 From: shalehperry at comcast.net (Sean 'Shaleh' Perry) Date: Tue, 12 Aug 2003 23:06:48 -0700 Subject: Multi-Line Comment In-Reply-To: References: <4qofjvg3bh9smlnb1do4f0lhjga7bacnu3@4ax.com> Message-ID: <200308122306.48320.shalehperry@comcast.net> On Tuesday 12 August 2003 22:07, Christopher Blunck wrote: > > > > Nope, no multi-line comment. The python-mode package which is available > > for Emacs and XEmacs supports commenting a block of text. You can also > > use triple-quoted strings: > > That always stumped me as well. Any idea what the justification for this > was, Skip? > none of the other shell/script languages have one either. I rarely miss it. From usenet at soraia.com Sun Aug 17 20:53:49 2003 From: usenet at soraia.com (Joe Francia) Date: Mon, 18 Aug 2003 00:53:49 GMT Subject: Newbie: explanation of PrivoxyWindowOpen; website docs outdated? In-Reply-To: References: Message-ID: Richard Michael wrote: > I've been reading the Python docs, and the 6.1.3 File Objects section of > the Library Reference indicates that instead of "open()", I should use > the builtin function "PrivoxyWindowOpen()" instead. As you suspected, this has nothing to do with Python or the Python.org website - it is Privoxy replacing all instances of open() with PrivoxyWindowOpen() to squash pop-up advertisements and such. Just add .python.org to your whitelist and you'll be OK. (browse to http://config.privoxy.org/ to bring up the configuration page). jf From jcribbs at twmi.rr.com Wed Aug 27 14:53:12 2003 From: jcribbs at twmi.rr.com (Jamey Cribbs) Date: Wed, 27 Aug 2003 18:53:12 GMT Subject: ANNOUNCE: KirbyBase 1.4 Message-ID: KirbyBase 1.4 is now available at: http://www.netpromi.com/files/KirbyBase-1.4.zip What is KirbyBase? KirbyBase is a simple, pure-Python, plain-text, flat-file database management system that can be used either embedded in your application or in a client/server, multi-user mode. To find out more about KirbyBase, go to: http://www.netpromi.com/kirbybase.html Changes: Added two new database field types: datetime.date and datetime.datetime. They are stored as strings, but are input and output as instances of datetime.date and datetime.datetime respectively. You can use them just like any other field: you can use them as selection criteria (i.e. db.select('plane.tbl', ['began_service'], ['>=%s' % datetime.date(1937,12,31)) or use them to specify the sort order of the result set of a select statement (i.e. db.select('plane.tbl', ['name'], ['.*'], sortField='range', ascending=False)). Made a few internal optimizations when running queries that have resulted in a 15-20% speed increase when doing large queries or updates. Changed the name of all private methods from starting with two underscores to starting with one underscore based on a discussion in comp.lang.python as to how to properly name private variables. From tcronj at ananzi.co.za Thu Aug 28 17:34:57 2003 From: tcronj at ananzi.co.za (Tertius) Date: Thu, 28 Aug 2003 23:34:57 +0200 Subject: opposite of dict.items() In-Reply-To: <3f4e708c$0$64719@hades.is.co.za> References: <3f4e708c$0$64719@hades.is.co.za> Message-ID: <3f4e7544$0$64724@hades.is.co.za> Tertius wrote: > Is there a method to create a dict from a list of keys and a list of > values ? > > TIA > Tertius > I found a way... a = {} for k , v in zip(keys,values): a[k] = v thnx Tertius From peter at engcorp.com Tue Aug 26 08:03:26 2003 From: peter at engcorp.com (Peter Hansen) Date: Tue, 26 Aug 2003 08:03:26 -0400 Subject: python gripes survey References: Message-ID: <3F4B4C8E.23554819@engcorp.com> JanC wrote: > > carroll at tjc.com schreef: > > > No kidding: I'd really like a GOTO. I know, that's heresy, but I like > > it during development. Sometimes I have a whole bunch of tests, and > > change something that will only affect a test near the end. I'd love > > to GOTO around the early stuff. > > > > If Python used {} to delimit blocks, I could just make the skipped > > code a block and add a condition to skip it, but with the indentation > > as the way of showing block scope (which I *love*), I have to indent a > > big chunk of code to use that method. > > If it doesn't contain docstrings, you can put that "unwanted" test code > between triple quotes ("""). OR if you're consistent in using only one kind of docstring, say ''' only, then you can almost always use """ to comment out a block... -Peter From tomas at fancy.org Thu Aug 28 00:12:54 2003 From: tomas at fancy.org (Tom Plunket) Date: Wed, 27 Aug 2003 21:12:54 -0700 Subject: Celebrity advice (was: Advice to a Junior in High School?) References: Message-ID: Tim Churches wrote: > Except when it comes to guns - despite all the evidence that > the ready availability of firearms to the general population > Results in huge numbers of avoidable homicides, suicides, injuries, > incarceration and general mayhem... Ironically the states with the loosest gun laws also have the least crime. Remember that automobiles kill something like 100x the number of people in the US every year over guns. -tom! -- There's really no reason to send a copy of your followup to my email address, so please don't. From max at alcyone.com Wed Aug 27 22:05:47 2003 From: max at alcyone.com (Erik Max Francis) Date: Wed, 27 Aug 2003 19:05:47 -0700 Subject: Style question... References: Message-ID: <3F4D637B.7ADB0BC4@alcyone.com> Anthony Roberts wrote: > What's the keystroke for that? C-c < and C-c >. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ Nobody's on nobody's side \__/ Florence, _Chess_ From daniel at dittmar.net Tue Aug 12 06:13:06 2003 From: daniel at dittmar.net (Daniel Dittmar) Date: Tue, 12 Aug 2003 12:13:06 +0200 Subject: Python should try to displace Java In-Reply-To: References: Message-ID: So what do you propose? To transfer the copyright of Python to SCO so that they sue SUN? Daniel From aleax at aleax.it Thu Aug 21 03:07:09 2003 From: aleax at aleax.it (Alex Martelli) Date: Thu, 21 Aug 2003 07:07:09 GMT Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> <87fzjywpjs.fsf@pobox.com> Message-ID: Dave Benjamin wrote: > "Alex Martelli" wrote in message > news:bht3bq02v9p at enews3.newsguy.com... >> Thus, the direct Python equivalent might be >> >> import __builtins__ >> __builtins__.len = someotherfunction >> >> and THAT usage is very specifically warned against e.g. in >> "Python in a Nutshell" -- you CAN do it but SHOULDN'T (again, one >> can hope to eventually see it "officially" deprecated...!). > > I agree with your position, more or less, but I am curious - how far do > you think this deprecation should go? Just changing a function in > __builtins__? Changing a function in any module? Or changing *anything* > about a module from the outside? Good question! I don't have any preset answers yet. We definitely do want to impose those restrictions that have "multiple" benefits, i.e. that both let speed increase (by allowing the compiler to 'inline' the calls to built-in functions, once it does know they're built-ins) AND encourage correctness -- but we don't want to cripple ordinary useful usage, particularly not when the benefits are uncertain. Where the line should consequently be drawn is not 100% obvious -- which is in part why nothing about this ended up in Python 2.3, but rather it's all scheduled for consideration in 2.4. Alex From elf at drizzle.com Thu Aug 14 13:00:11 2003 From: elf at drizzle.com (Elf M. Sternberg) Date: Thu, 14 Aug 2003 10:00:11 -0700 Subject: Python signal delivery under BSD 4.4 References: Message-ID: Andrew MacIntyre writes: >> I tried it from FreeBSD 5.1, using 2.2.2 built from ports, >> and didn't see this problem. I believe 5.1 has a significantly >> different thread implementation from 4.x, though. > And later releases of FreeBSD 4.x have a number of bugfixes to the pthread > support, including some signal related changes. The 4.x pthread support > still has some issues though. I went and looked again at the evidence. When calling the function with apply(), the child process spawned off reports: mask 0x0 When calling the function with thread.start_new_thread(), the child process reports: mask 0xfffefeff So I think the two of you have more or less hit it squarely on the head. Now, I just have to find a way around it... *Sigh* Elf From gafStopSpamData at ziplink.stopallspam.net Thu Aug 21 16:56:20 2003 From: gafStopSpamData at ziplink.stopallspam.net (Gary Feldman) Date: Thu, 21 Aug 2003 20:56:20 GMT Subject: Deficiency in urllib/socket for https? Message-ID: <6vaakvorefvifnt3fk59r6tcj16c59rrfi@4ax.com> I think I've found a deficiency in the design of urllib related to https. In order to complete an https connection, it appears that URLOpener and hence FancyURLOpener require the key and cert files. Or at least, it's not clear from the description of socket.ssl what it does if they're omitted. However, urlopen has no way to specify such things. Nor should it - for typical uses, a person simply trying to retrieve data from an ssl site really doesn't want to know or care about keys and certificate directories. One just wants to provide an https url and have it work. Ideally, there should be defaults for the certificate files. This implies that somewhere in the function hierarchy, I suspect in socket.ssl, there needs to be some clever defaults. I don't know if they folks maintaining the Python distribution really want to be in the business of maintaining key and certificate directories (probably not), but there at least ought to be a way to specify default directories (oh, no, another environment variable?). Thinking idealistically, it would be great if it could share the default certs on the system (i.e. on UNIX, find a Netscape or Mozilla install directory and use those, and on MS Windows, do whatever it takes to use the Windows mechanism). It's possible my analysis is flawed. I haven't taken the time to download and read the _ssl code, just the socket.py code (and urllib and httplib) . So corrections as appreciated as much as comments. Gary From newsgroups at jhrothjr.com Sun Aug 3 06:47:24 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Sun, 3 Aug 2003 06:47:24 -0400 Subject: time, calendar, datetime, etc References: Message-ID: "Dennis Lee Bieber" wrote in message news:ceauv-uj3.ln1 at beastie.ix.netcom.com... > John Roth fed this fish to the penguins on Friday 01 August 2003 04:16 > am: > > > > > > Frankly, if what was wanted was a single, consistent and usable > > definition of time, the astronomical Julian date is it. It's a single > > number, > > Calculated using the J2000 definition, or the B1900 definition? AFIK, it hasn't changed. I *think* you're talking about the epoch, which is an astronomical thing that's rightly ignored outside of astronomy. Even astrologers ignore it: we prefer to know where the vernal equinox is at date, not where it is at some other date. John Roth > > > -- > > ============================================================== < > > wlfraed at ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG < > > wulfraed at dm.net | Bestiaria Support Staff < > > ============================================================== < > > Bestiaria Home Page: http://www.beastie.dm.net/ < > > Home Page: http://www.dm.net/~wulfraed/ < > From mark at diversiform.com Mon Aug 11 20:05:28 2003 From: mark at diversiform.com (Mark Daley) Date: Mon, 11 Aug 2003 17:05:28 -0700 Subject: Finding the path to a file In-Reply-To: <20030811231134.19113.qmail@web41205.mail.yahoo.com> Message-ID: I use registry keys to handle stuff like that. It also allows more flexibility for the end user on the install side. Of course, you may not care about an end user, if you are the only one useing the program, but then you would control all of the directory stuff yourself... I realize this doesn't answer the question directly, but I felt like I should put my two cents in. - Mark -----Original Message----- From: python-list-admin at python.org [mailto:python-list-admin at python.org]On Behalf Of Todd Johnson Sent: Monday, August 11, 2003 4:12 PM To: python-list at python.org Subject: Finding the path to a file Hey, I have been working on a program that stores information for each user in a subdirectory of the directory in which the script is run. So if my script is in /home/someuser/myprogram, the config files and such are in /home/someuser/myprogram/config. Now if I invoke the interpreter from the same directory as the script is in I can load and save the files because cwd points to that directory(I used cwd to get the path and then add /config to it to get to the proper directory) My problem is that if I invoke it with a command like python /home/someuser/myprogram but I am in /home/someuser, cwd does not point to the scripts directory but to the directory the interpreter was invoked from. This means I don't know how to find the config files other than making them hard coded to a certain directory. I don't want to hard code them however so that the program can be contained in one directory and easily removed and I also don't want to have to specify where a user installs the program. So basically, I want to know how to find the directory my script is in, even when it is invoked from another directory. Any help would be greatly appreciated. Thanks in advance, Todd A. Johnson ===== The grace of the Lord Jesus Christ, and the love of God, and the communion of the Holy Ghost, be with you all. Amen. II Corinthians 13:14 __________________________________ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com -- http://mail.python.org/mailman/listinfo/python-list From news at fairford.co.uk Fri Aug 1 07:39:23 2003 From: news at fairford.co.uk (jim) Date: Fri, 1 Aug 2003 11:39:23 +0000 (UTC) Subject: win32file.WaitCommEvent error Message-ID: Hi, All I am using python (activestate 2.2.2-224) on XP home and have suddenly got the following error from a file which worked fine under millenium. File "E:\code\Python\PyModbus\FEModbusV101.py", line 162, in ComPortWrite rc,mask =win32file.WaitCommEvent(self.hComm,self.Overlapped) api_error: (87, 'WaitCommError', 'The parameter is incorrect.') I think the api call requires 3 parameters but only 2 are used in python any ideas ? Jim From simonb at webone.com.au Wed Aug 20 23:04:02 2003 From: simonb at webone.com.au (Simon Burton) Date: Thu, 21 Aug 2003 13:04:02 +1000 Subject: pyrex.vim ? References: Message-ID: On Thu, 21 Aug 2003 10:10:25 +1000, Simon Burton wrote: > > Looks like the pyrex guy uses emacs... > > Anyone have any hints/ideas/scripts for getting some vim syntax colors for > pyrex ? > > Simon. python.vim seems to work well enough, my filetype.vim has this now: " Python au BufNewFile,BufRead *.py setf python " PyRex au BufNewFile,BufRead *.pyx setf python From __peter__ at web.de Wed Aug 6 11:25:27 2003 From: __peter__ at web.de (Peter Otten) Date: Wed, 06 Aug 2003 17:25:27 +0200 Subject: site-packages and linux References: Message-ID: Raaijmakers, Vincent (IndSys, GE Interlogix) wrote: > for some reason to 2.2. All installed packages located in > ...\python2.2\site-packages are not recognized anymore. Well, when > importing is not possible, no module found error is what I get now. > > Without re-installing everything, how can I solve this problem? Try invoking what you think is the python 2.2 interpreter with the -V option. Chances are that you are actually using 2.3 where the missing packages are not yet installed. Note that this may even vary between different users: On my Suse 8.1 box with a python 2.3 installation from the sources python as root invokes 2.2, python as user peter invokes 2.3 Peter From borcis at users.ch Mon Aug 18 12:08:53 2003 From: borcis at users.ch (Borcis) Date: Mon, 18 Aug 2003 18:08:53 +0200 Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> Message-ID: <3F40FA15.9020503@users.ch> Alex Martelli wrote: > Me, I think immutable strings are > an excellent idea (and I'm not surprised that Java, independently > I think, reinvented that idea which was already in Python) IIRC Applesoft Basic on the Apple II had immutable strings, way back in the late seventies. From kkto at csis.hku.hk Tue Aug 12 06:42:33 2003 From: kkto at csis.hku.hk (Isaac To) Date: 12 Aug 2003 18:42:33 +0800 Subject: Multi-Line Comment References: <4qofjvg3bh9smlnb1do4f0lhjga7bacnu3@4ax.com> <87y8xzvhst.fsf@pobox.com> Message-ID: <7iekzr2m3q.fsf@enark.csis.hku.hk> >>>>> "John" == John J Lee writes: John> Doug Tolton writes: [...] >> How do you comment the block of text with Emacs? That is what I'm >> using for my code editor. John> C-c # John> I use C-x r k to uncomment (kill-rectangle), but I'm sure there John> must be an uncomment-region in there somewhere... Just do C-u C-c # Regards, Isaac. From rxs141 at cwru.edu Mon Aug 4 18:53:27 2003 From: rxs141 at cwru.edu (Ravi) Date: Mon, 04 Aug 2003 18:53:27 -0400 Subject: Match beginning of two strings In-Reply-To: References: Message-ID: Ravi wrote: > Hi, > > I have about 200GB of data that I need to go through and extract the > common first part of a line. Something like this. > > >>>a = "abcdefghijklmnopqrstuvwxyz" > >>>b = "abcdefghijklmnopBHLHT" > >>>c = extract(a,b) > >>>print c > "abcdefghijklmnop" > > Here I want to extract the common string "abcdefghijklmnop". Basically I > need a fast way to do that for any two given strings. For my situation, > the common string will always be at the beginning of both strings. I can > use regular expressions to do this, but from what I understand there is > a lot of overhead. New data is being generated at the rate of about 1GB > per hour, so this needs to be reasonably fast while leaving CPU time for > other processes. > > Thanks > Ravi > I really appreciate all your help, Alex, Jim, Jeff, Andrew, John, Richie and Bengt. However I have this problem taken care of now. Took around 6 hours to run on a P4 2.8Ghz 1.0GB DDR (I suspect I/O limitations). As for the data, if you want to know about it just for the sake of an optimized algorithm, there are no Null (\0) characters in the strings (actually they're Base64), and I've included a typical pair of strings. The version I used was Andrew's. Someone suggested that this would be better done in larger sets than just pairs. That's not suitable because of the structure of the data, two strings might be highly correlated, but are probably quite different from another pair of strings. Perhaps more significantly, correlation in sets of greater than two has no physical significance to the experiment. I grabbed this from a typical data file. So I would want to be extracting 'A832nv81a' " A832nv81a81nW103v9c24jgpy92T A832nv81aTyqiep4v9c324jgpy92T " Thanks for your help everyone, coming from a Perl (It's a four letter word to me :) world, I'm very impressed by how helpful all of you are. Ravi From just at xs4all.nl Mon Aug 25 15:40:27 2003 From: just at xs4all.nl (Just) Date: Mon, 25 Aug 2003 21:40:27 +0200 Subject: Help embedding python References: <3F4A469E.58B94F7C@engcorp.com> <3F4A57B0.E91D89FC@engcorp.com> Message-ID: In article , Zora Honey wrote: > [ ... ] The reason I didn't include rationale is > because I have none. I have been advocating extending python instead of > embedding it, but since I have no experience with either, my only > argument is that it seems more natural. Have a look at http://www.twistedmatrix.com/users/glyph/rant/extendit.html It may be a rant, but it makes some good points. Just From cnetzer at sonic.net Wed Aug 13 03:45:53 2003 From: cnetzer at sonic.net (Chad Netzer) Date: Wed, 13 Aug 2003 00:45:53 -0700 Subject: Multi-Line Comment In-Reply-To: References: <4qofjvg3bh9smlnb1do4f0lhjga7bacnu3@4ax.com> <200308122306.48320.shalehperry@comcast.net> Message-ID: <1060760753.18367.122.camel@adsl-209.204.179.133.sonic.net> On Wed, 2003-08-13 at 00:03, Doug Tolton wrote: > >(along with block indent/dedent with a decent editor) > > In emacs what are the key strocks for block indent and dedent? In python-mode: C-c > C-c < > Man, I wonder if I'll even learn 10% of the Emacs keystrokes. I don't even know 1%, but I know the 1% that counts. :) -- Chad Netzer From mis6 at pitt.edu Mon Aug 18 19:30:11 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 18 Aug 2003 16:30:11 -0700 Subject: What's better about Ruby than Python? References: Message-ID: <2259b0e2.0308181530.34500032@posting.google.com> I gave a look at Ruby some months ago, due to various favorable opinions I saw on c.l.py. Whereas there are few interesting things, there are at least two things I didn't like: 1. The syntax: too perlish for my taste; 2. Mixins: a poor man solution compared to multiple inheritance in Python. I also got the impression that they make a big deal about object orientation but that in practice Python has a better support for object orientation (I mean multiple inheritance, metaclasses, descriptors, properties, etc.) even if nobody is interested in stressing this point particularly in this community, since Python is multi-paradigm. Also, functional programming seems to be easier in Python than in Ruby. I got these impressions from an evening reading the tutorial, so I reserve myself the right to change my opinion if I find the time of looking at Ruby better ;) Anyway, no doubt that I will choose Ruby over perl, tcl, c#, c++, java, etc. (I mean, as a language; the situation is different if avalaibility of libraries or performances are taken in account). If Perl is Python's uncle, Ruby is Python's brother. As other have said, there are more similarities than differences and I expect the productivity to be more or less the same (modulo possible issues with the lack of librairies or english documentation, issues that probably will disappear soon, I think). Michele From edreamleo at charter.net Fri Aug 29 18:25:05 2003 From: edreamleo at charter.net (Edward K. Ream) Date: Fri, 29 Aug 2003 17:25:05 -0500 Subject: after, after_cancel and Python 2.3 References: Message-ID: I just took a look at TK's generic event code in tkEvent.c. It's really complex. For example: /* * There's a potential problem if a handler is deleted while it's * current (i.e. its procedure is executing), since Tk_HandleEvent * will need to read the handler's "nextPtr" field when the procedure * returns. To handle this problem, structures of the type below * indicate the next handler to be processed for any (recursively * nested) dispatches in progress. The nextHandler fields get * updated if the handlers pointed to are deleted. Tk_HandleEvent * also needs to know if the entire window gets deleted; the winPtr * field is set to zero if that particular window gets deleted. */ This is precisely the situation in which my code fails. There may be a bug if the list is circular, in which case "updating" the event handler might not work because p.nextPtr might be p itself. Also, the winPtr hack might not work for time-specific events like "after" events. These are just guesses, and my guess is that there are bugs here somewhere. Lord! How does anyone ever get this kind of code to work? Anyway, I have a workaround... Edward -------------------------------------------------------------------- Edward K. Ream email: edreamleo at charter.net Leo: Literate Editor with Outlines Leo: http://webpages.charter.net/edreamleo/front.html -------------------------------------------------------------------- From romany at actimize.com Wed Aug 13 05:16:35 2003 From: romany at actimize.com (Roman Yakovenko) Date: Wed, 13 Aug 2003 12:16:35 +0300 Subject: unsigned int \ long Message-ID: <91BFE89EFFA2904E9A4C3ACB4E5F2DF5027B05@exchange.adrembi.com> 1. Bitwise operations ~210 | 118 == -129 I'd like to get 127 ( of course if I work within byte or smth like this ). Today in order to get it I have to write ( ~210 | 118 ) & 0xFF 2. Example def print_selection( some_list, range=(0,-1) ): lower = max( 0, range[0] ) upper = min( len( some_list ), unsigned_int( range[1] ) ) print some_list[lower:upper] instead I have to write def print_selection( some_list, range=(0,-1) ): lower = max( 0, range[0] ) upper = range[1] if upper < 0 or upper > len( some_list ) upper = len( some_list ) print some_list[lower:upper] Thanks for help. Roman. > -----Original Message----- > From: Andres Viikmaa [mailto:andresv at hot.ee] > Sent: Wednesday, August 13, 2003 9:49 AM > To: python-list at python.org > Subject: Re: unsigned int \ long > > > look module struct -- Interpret strings as packed binary data > > Andres > > "Roman Yakovenko" wrote in message > news:mailman.1060753100.20465.python-list at python.org... > Hi. I need to work with integer as unsigned integer, but > I can't find documentation how can I do it. > > Some reference on this will be appreciated. > > For example (unsigned int)(-1) == 0xFFFFFFFF. > > Thanks. > > Roman. > > > -- > http://mail.python.org/mailman/listinfo/python-list > From a.schmolck at gmx.net Tue Aug 19 18:23:56 2003 From: a.schmolck at gmx.net (Alexander Schmolck) Date: 19 Aug 2003 23:23:56 +0100 Subject: What's better about Ruby than Python? References: Message-ID: Alex Martelli writes: > Alexander Schmolck wrote: > ... > > To recap: usually, if I change a class I'd like all pre-existing instances > > to become updated (Let's say you develop your program with a running > > If you CHANGE a class (mutate a class object), that does indeed happen. Indeed. But see below. > > You seem to have some deep level of confusion between "changing an > object" and "rebinding a name (that happened to be previously bound > to a certain object) so it's now bound to a different object". I don't think I'm confused about this. > > Rebinding a name *NEVER* has any effect whatsoever on the object that > might have, by happenstance, previously bound to that name (except that, > when _all_ references to an object disappear, Python is free to make > that object disappear whenever that's convenient -- but that doesn't > apply here, since if a class object has instances it also has references > to it, one per instance). Is your assumption of my ignorance regarding the difference between mutation/rebinding maybe based on the implicit assumption that a class statement by some sort of logical necessity *has* to create a new class object and then bind a name to it? Is there a reason why a class X(...):... statement can't just mutate a preexisting, former version of the class X (provided there is one?). Maybe there is, in which case let me state that I'm not particularly hung up on this, what I'm hung up about is the ability to easily update the behavior of pre-existing instances. How exactly this happens (by mutating the class in question (by whatever means, a new class statement, some function calls, __dict__-assignment), by rebinding the .__class__ for all instances etc.) is of less importance to me (although I suspect the 2nd alternative would cause all sorts of problems, because the old (viz non-'id'entical) class object could also hang around in a couple of other places than .__class__, .__bases__ etc.). > > This rule is universal in Python and makes it trivially simple to > understand what will happen in any given occasion -- just as long > as you take the minimal amount of trouble to understand the concepts > of names, objects, binding (and rebinding) and mutation. If a language > has no such clear universal rule, you're likely to meet with either > deep, complex trouble, or serious limitations with first-classness > of several kinds of objects. In Python everything is first-class, > and yet there is no substantial confusion at all. > > Repeat with me: rebinding a name has just about NOTHING to do with > mutating an object. These are VERY different concepts. Until you > grasp them, you won't be a very effective programmer. Agreed, but I think that happened some time ago. > > > python session; you notice a mistake in a method-definition but don't want > > to start over from scratch; you just want to update the class definition > > and have this update percolate to all the currently existing instances. > > I assume that by "update the class definition" you mean that you want > *necessarily* to use some: > > class X: ... > > statement that defines a NEW class object (which may happen to have > the same name as an existing class object -- quite irrelevant, of > course). I simply want some effective mechanism to have changes in selected parts of my sourcecode adequately reflected in a running interactive session, without much fuzz. I'm happy to write some elisp and python code to do some extra work on top of py-execute-region on a key-press. By "adequately reflected" I mean amongst other things that I can easily change the behavior of existing instances of a class after I made changes to the source code of that class. > OK, then, so arrange (easily done with some function or > editing macro, if you have a decent editor / IDE) to do the following: > > oldX = X # save the existing classobject under a new temporary name > > class X: ... # define a completely new and unrelated classobject > > oldX.__dict__.clear() > oldX.__bases__ = X, > > # in case you also want to change the old class's name, you might: > oldX.__name__ = X.__name__ # so you're not constrained in this sense > > # optionally, you can now remove the temporary name > del oldX > > There. What's so hard about this? How does this fail to meet your > desiderata? I tried this some time ago and discovered it only worked for old style classes; the dict-proxies of new-style classes are, I think, not directly mutable, I'd guess for efficiency reasons. Here is an example of the difference (update, clear, del won't work either, BTW): >>> class X: ... def bar(): "bar" ... >>> X.__dict__['bar'] = lambda :"foo" >>> class X(object): ... def bar(): "bar" ... >>> X.__dict__['bar'] = lambda :"foo" TypeError TypeError: object does not support item assignment > Wouldn't it have been easier to ask, in the first place, "I would like to > obtain this effect, is there a Python way" (being a BIT more precise in > describing "this effect", of course !-), rather than whining about "Python > can't do this" and complaining of this as being "unreasonable"? Agreed, this was an unproductive way to describe my problem. Mea culpa. Although I have investigated the problem before (and for the reason stated above, settled for the suboptimal reassigning to .__class__ when I *desperately* wanted to change a important instances), on second thoughts not only should I have phrased myself differently, I should also have spent more time thinking about it. I *think* it ought to be possible to effect all the necessary changes by directly manipulating attributes, rather than going via .__dict__, even for class/staticmethods. It's too late now, so I haven't fully thought this through yet but I'll give it a try tomorrow. Anyway, I still don't see a compelling reason why class statements couldn't/shouldn't be mutating, rather than rebinding. Is there one? > > > > AFAIK doing this in a general and painfree fashion is pretty much > > impossible in python (you have to first track down all instances -- not an > > I personally wouldn't dream of doing this kind of programming in production > level code (and I'd have a serious talk with any colleague doing it -- or > changing __class__ in most cases, etc). I'd be interested to hear your reasons. (The only argument against this style that I can think off from the top of my head is that it might encourage sloppy and code development and unwitting reliance on irreproducible artifacts of the session history. I don't think this problem occurs in practice, however. If I write (non-throwaway) code, I always write plenty of testcode, too, (which, BTW I also find *much* more pleasant to develop and debug interactively) and frequently start new python processes to to run this testcode in fresh sessions to satify myself that things just don't appear to work because of accumulated garbage in my interactive session. [snipped] > I don't think the fact that nobody complains is strongly connected to the > fact that most Python users grasp the possibility of updating a class by > modyfying its __dict__ etc; indeed, one great thing about Python is that > most users typically tend to SIMPLICITY rather than "cleverness" -- if they > wanted to modify a class X's method Y they'd code it as a function F and > then simply do X.Y=F -- extremely simple, rapid, effective, and no need > to much with redoing the whole 'class' statement (a concept I personally > find quite terrible). I think we need to sharply distinguish between two things (and I should presumably have stressed this more in my last post): 1. Redefining methods of class during execution, as part of the solution to the problem the program is supposed to adress. 2. Redefining classes as part of an incremental development process. In this case, you of course "redo" the whole class statement, because you edit the source code with the class statement and everything else in it and then the most convinient way to update your code is to send all or part of this newly edited file to your interactive session (plus potentially some tweaking code that mutates the pre-existing "live" version of X as you outlined above, or somehow else effects the changes you want to take place in existing instances). I'm chiefly interested in 2. (to the extent that I consider it an essential ability of a good programming language) and much less so in 1. (although modifying instances and classes can also sometimes be useful). > Rarely does one want to modify an existing class object any more 'deeply' > than by just redoing a method or two, which this utterly simple assignment > entirely solves -- therefore, no real problem. > > If your style of interactive programming is so radically different from > that of most other Pythonistas, though, no problem (I wonder whether it is (quite possibly) and if so why? Developing code interactively just seems like the obvious and right thing to do to me.) > put some effort in understanding how things work (particularly the > difference between *MODIFYING AN OBJECT* and *REBINDING A NAME*), Python > supports you with power and simplicity in MOST (*NOT* all) metaprogramming > endeavours. > > If you DO want total untrammeled interactive and dynamic metaprogramming > power, though, *THEN* that's an area in which Ruby might support you > even better No it doesn't, for example Ruby doesn't have docstrings which is an unnecessary waste of my time (apart from the fact that Ruby offends my sense of esthetics). > -- for example, this Python approach would *NOT* work if > oldClass was for example str (the built-in string class -- you CANNOT > modify ITS behavior). > Personally, for application programming, I much prefer clear and > well-defined boundaries about what can and what just CANNOT change. But if > you want EVERYTHING to be subject to change, then perhaps Ruby is exactly > what you want. Nope, in that case I'd almost certainly use smalltalk which I consider infinitely superior to ruby (or possibly some Lisp). > Good luck with keeping track of what names are just names (and can be freely > re-bound to different objects) and which ones aren't (and are more solidly > attacked to the underlying objects than one would expect...). I don't think we really fundamentally disagree. I don't think one should screw around with everything just because one can and I also think that languages who set inappropriate incentives in that direction are less suitable for production software development. 'as From rmunn at pobox.com Fri Aug 1 15:27:49 2003 From: rmunn at pobox.com (Robin Munn) Date: Fri, 01 Aug 2003 19:27:49 GMT Subject: Bug help: CGI forking References: Message-ID: Jonathan Hayward wrote: > I am trying to have a CGI script which forks a daemon the first time, > and on subsequent times asks the daemon to do all the work. The daemon > and the CGI script are run by the same code. > > I'm trying to have a class that will handle daemon multithreading, the > "hollow shell" CGI script starting up the daemon, and the CGI script > talking with the daemon. I tried to use recipes from O'Reilly's > _Python Cookbook_, but I must have messed up. The script usually > hangs, and when it doesn't hang, the daemon sometimes isn't started. I > think I have a fork bug, at least. > > Any bugfixes and/or clarifications welcome: > > class multitasking_manager(ancestor): > """Class to handle multithreading and multiprocessing material.""" > def __init__(self): > ancestor.__init__(self) > thread_specific_storage = {} > thread_specific_storage_lock = thread.allocate_lock() > def check_and_start_daemon(self): > if not self.is_daemon_running(): > self.start_daemon() [snip some code] > def start_daemon(self): > try: > first_pid = os.fork() > except OSError, e: > log_error("Failed to make first fork for daemon. Error: " > + \ > e.strerror) > return > if first_pid == 0: > os.chdir("/") > os.setsid() > os.umask(066) > try: > second_pid = os.fork() > except OSError, e: > log_error("Failed to make second fork for daemon. > Error: " + \ > e.strerror) > return > if second_pid == 0: > self.run_daemon() I believe the start_daemon routine may be your problem. First, you may want to look at this recipe in the online Python Cookbook: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66012 I believe that's the recipe you're trying to follow in the paper copy; the online version, though, includes some useful comments about things like decoupling from stdin, stdout and stderr, which might cause problems if you don't do it. I'm noticing one omission here: the sys.exit(0) calls after the two forks. I understand not putting in a sys.exit(0) after the first fork, if you want your CGI script to continue running after forking off the daemon, but after the second fork, the parent should close. It might also be a good idea to split this out into two scripts: --- begin cgiscript.py --- def is_daemon_running(): try: # Communicate with daemon via socket. return True except socket.error: return False def start_daemon(): os.system('daemon.py parameters') def check_and_start_daemon(): if not is_daemon_running(): start_daemon() def do_work(): check_and_start_daemon() # Whatever else needs to happen... ---- end cgiscript.py ---- --- begin daemon.py --- def daemonize_self(): def start_daemon(self): try: first_pid = os.fork() except OSError, e: log_error("Failed to make first fork for daemon. Error: " + \ e.strerror) return if first_pid > 0: # Exit first parent sys.exit(0) else: os.chdir("/") os.setsid() os.umask(066) try: second_pid = os.fork() except OSError, e: log_error("Failed to make second fork for daemon. Error: " + \ e.strerror) return if second_pid > 0: # Exit second parent sys.exit(0) else: # Optional but recommended: disconnect stdin, stdout, stderr new_stdin = file('/dev/null', 'r') new_stdout = file('/dev/null', 'a+') new_stderr = file('/dev/null', 'a+', 0) os.dup2(new_stdin.fileno(), sys.stdin.fileno()) os.dup2(new_stdout.fileno(), sys.stdout.fileno()) os.dup2(new_stderr.fileno(), sys.stderr.fileno()) # Now we're ready run_daemon() def run_daemon(): # Insert processing here ---- end daemon.py ---- This FAQ might also be useful: http://www.erlenstar.demon.co.uk/unix/faq_2.html#SEC16 -- Robin Munn | http://www.rmunn.com/ | PGP key 0x6AFB6838 -----------------------------+-----------------------+---------------------- "Remember, when it comes to commercial TV, the program is not the product. YOU are the product, and the advertiser is the customer." - Mark W. Schumann From mauricio.inforcati at cenpra.gov.br Tue Aug 12 13:16:15 2003 From: mauricio.inforcati at cenpra.gov.br (=?iso-8859-1?Q?Mauricio_Infor=E7ati?=) Date: Tue, 12 Aug 2003 14:16:15 -0300 Subject: PIL1.1.4-WIN Message-ID: <023501c360f5$6fcf5aa0$417290c8@paraopeba> Hi, I can?t reach PIL1-1-4-win32-PY2.2 file (at effbot.org) for installing python Image. Could somebody send me it? Thanks, Mauricio -------------- next part -------------- An HTML attachment was scrubbed... URL: From http Sun Aug 3 20:39:52 2003 From: http (Paul Rubin) Date: 03 Aug 2003 17:39:52 -0700 Subject: Python vs. Perl vs. PHP? References: <7b454334.0307281002.41dae81b@posting.google.com> <7b454334.0307301611.1b40ff11@posting.google.com> <7b454334.0307311023.28900d57@posting.google.com> <7b454334.0308031024.7b53fe46@posting.google.com> Message-ID: <7x8yqaxnl3.fsf@ruckus.brouhaha.com> Gerhard H?ring writes: > >> I personally find it much easier to learn about system > >> administration and get my own dedicated server for EUR 39/month. > > 39? Where do you get such a good deal? > > http://hetzner.de/ - "Entry Server" EUR 39 > http://www.server4free.de/ - EUR 30 > http://www.server4free.de/ - VServer (basically User Mode Linux) - EUR 10 > > http://www.1und1.com/ - EUR 49 > > These are the cheapest offers of the relevant German providers. They > all come with a considerable setup fee as well, so don't just look at > the monthly fee. www.usermodelinux.org has links to a bunch of other such providers. EUR 10 is the lowest monthly price I've seen, but I think there are some in the 20 USD/month range with low or no setup fees. From hokiegal99 at hotmail.com Tue Aug 26 22:19:27 2003 From: hokiegal99 at hotmail.com (hokiegal99) Date: Tue, 26 Aug 2003 22:19:27 -0400 Subject: String find and replace References: <3F4C04F8.5070401@vt.edu> <3F4C0CC4.20400@hotmail.com> Message-ID: <3F4C152F.2050203@hotmail.com> John Roth wrote: > Oh. You need to open it again for write and write the > changed string back out. The string doesn't have any > persistant connection to the file. > > John Roth Could you give me a general example of how I would do this? I've never written to a file before. Thanks!!! From dave at pythonapocrypha.com Wed Aug 20 22:43:49 2003 From: dave at pythonapocrypha.com (Dave Brueck) Date: 20 Aug 2003 19:43:49 -0700 Subject: Brandon's abrasive style (was Re: What's better about Ruby than Python?) References: <38ec68a6.0308172319.431a4fde@posting.google.com> Message-ID: <477762c2.0308201843.33b175dd@posting.google.com> Ramon Leon Fournier wrote in message news:... > Brandon J. Van Every wrote: > > - Python is not a good language for low-level 3D graphics problems. C++ is > > better. > > Well, not just for low-level 3D graphics. There are many other things > you would not code in Python unless you are a complete fool. Your > companies mail server, for instance. Actually, that's not a very good example - Python is *very* well suited for many types of servers, mail servers included. The I/O heavy nature of many servers lessens the significance of Python being slow in terms of raw CPU speed. Lots of I/O can also mean the effects of the GIL less of a factor on multi-CPU boxes than they otherwise would be. Finally, given the fact that you don't see too many buffer overruns and other similar security holes in Python, I'd sleep *better* at night implementing my server in Python than in C++. But I do agree with the notion that Python isn't good for *all* problems, as does everyone else it seems. ;-) -Dave From mpeuser at web.de Wed Aug 20 14:41:55 2003 From: mpeuser at web.de (Michael Peuser) Date: Wed, 20 Aug 2003 20:41:55 +0200 Subject: python for non-programmers tutorial? References: Message-ID: "Aahz" schrieb im Newsbeitrag news:bhvvnr$h53$1 at panix3.panix.com... > In article , > Michael Peuser wrote: > > > >Have a look at: > > > > www.pauahtun.org/TYPython/ > > > >Ivan Van Laningham: Teach Yourself Python in 24 Hours > > Unfortunately, speaking as the tech editor of that book, I can't > recommend it. Besides, it's out of print. This probably is why it's online.... I did not recommend to buy it but is a nice site ;-) Kindly Michael P > -- > Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ > > This is Python. We don't care much about theory, except where it intersects > with useful practice. --Aahz From rickpasotto at news.speakeasy.net Fri Aug 1 19:36:05 2003 From: rickpasotto at news.speakeasy.net (Rick Pasotto) Date: Fri, 01 Aug 2003 18:36:05 -0500 Subject: pysqlite last_insert_id Message-ID: How do I get the last_insert_id using pysqlite? In the MySQLdb module both the 'connect' and the 'cursor' have an insert_id attribute but pysqlite does not. -- "Curiosity is the very basis of education and if you tell me that curiosity killed the cat, I say only the cat died nobly." -- Arnold Edinborough Rick Pasotto rick at niof.net http://www.niof.net From nicholas_wieland at yahoo.it Sat Aug 23 11:32:58 2003 From: nicholas_wieland at yahoo.it (Nicholas Wieland) Date: Sat, 23 Aug 2003 17:32:58 +0200 Subject: pyGTK with wxPython References: Message-ID: -Charlie Kim: > snip > > Do I have to modify the application's sources against pyGTK? > or any solution? Yes, you have to modify the source. Wx is a different system, it does use Gtk but without integrating in the GNOME desktop architecture (but sharing the wonderful look & feel ^^) :) It's not a matter of pyGTK or wxPython, for a gnome-applet you need gnome-python (you have imported gnome.applet ...). I know that the author of wxPython follows this group, maybe he has another solution ... HTH, nicholas From pdfernhout at kurtz-fernhout.com Wed Aug 27 16:38:48 2003 From: pdfernhout at kurtz-fernhout.com (Paul D. Fernhout) Date: Wed, 27 Aug 2003 16:38:48 -0400 Subject: Advice to a Junior in High School? In-Reply-To: <3d6c6fc3.0308261246.32db39d5@posting.google.com> References: <3d6c6fc3.0308261246.32db39d5@posting.google.com> Message-ID: <3f4d1685_5@corp.newsgroups.com> Stan Graves wrote: > [Lots of good advice snipped] Wow, this is really good advice on becoming a decent human being! I could not have put it as well or succinctly. This is much better advice for someone finishing high school soon than on any specific technical direction. It reminds me a bit of Robert Heinlein's quotation: "A human being should be able to change a diaper, plan an invasion, butcher a hog, design a building, conn a ship, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve an equation, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly. Specialization is for insects". http://www.everything2.com/index.pl?node=specialization%20is%20for%20insects We live in a beautiful and mysterious world -- seemingly infinite in time and space and meaning, perhaps with multiple nested levels beyond our current understanding (individual or collective). Stan's advice touches on how to come to grips with these deeper issues indirectly by engaging deeply in the human experience through the ways he outlines (volunteering, compassion, art, dance, music, frugality, etc.) to grow some deep roots to rely on when branching out into a specialization like computer science or Python internals. One good resource in the area towards career understanding is Richard Bolles "What Color is Your Parachute". http://www.amazon.com/exec/obidos/tg/detail/-/1580082424/103-2338008-0446217?v=glance and his related books on Life/Work planning. Still, I might add, from a technical side, become aware of Moore's Law if you want to try to predict where the computer field is going to go over the course of your career. Computers have increased in computing capacity for a constant cost on the order of close to one million times over the last thirty or so years. In the next twenty years or so they will probably again increase by a factor of about another million from where they are now. http://www.transhumanist.com/volume1/moravec.htm Ever more sophisticated virtual reality simulations and robotics (e.g. cars that drive themselves just for one application) will be just a few of the sorts of possibilities this kind of computing power will enable, as well as all sorts of things we can barely imagine now. Cars can even drive themselves now using laptops, but they will be presumably even safer and more capable then... http://www.ri.cmu.edu/labs/lab_28.html On Moore's Law and exponential growth see for example: http://www.kurzweilai.net/articles/art0134.html?printable=1 Moore's Law type growth is one reason sophisticated languages like Python are now succesful (over using all C/C++ all the time) and may be ever more succesful as time goes by. As a corollary, today's level of desktop computing may well cost one-millionth of what it does in twenty years, and so may be effectively free (well, a penny) and so may be embedded everywhere (so studying embedded sytems might be useful, and for example, learning the computer language Forth might be relevant). Also, to elaborate on Stan's suggestion to study literature, read lots of things (including, but not limited to, science fiction). For one optimistic view of the future, see James P. Hogan's writings, especially "Voyage from Yesteryear". http://www.jamesphogan.com/books/voyage/baen99/titlepage.shtml I always return to that novel and his other writings as a way to regain some hope for the future. And for a cyberpunkish vision, try "The Diamond Age" by Neal Stephenson. http://www.amazon.com/exec/obidos/tg/detail/-/0553380966/102-9187646-8303318?v=glance But don't skimp on other classics, from "The Machine Stops" to "The Skills of Xanadu". It's quite possible in twenty years that much of your work in computing may be almost inseperable from nanotechnology matter replicator programming (i.e. your programs might compile to the hardware). Self-replicating space habitats made easy by related technological advances in computing and materials fabrication may then well produce trillions of Earth's worths of living space around our solar system. http://www.luf.org/ Those sort of possibilities realizeable through dedication and commitment of young people like yourself (as well as oldsters :-) make all this current fighting over oil and water and land and weapons all seem so childish and outmoded as a civilization... Hogan's vision of a universe of plenty if we can just cooperate and show compassion and try to avoid living in fear is a good one to embrace. Choices by millions of people such as yourself will shape whether and how much and for whom the future heads in this direction. On the science front, read anything by Freeman Dyson (like "Disturbing the Universe") because he is a very decent human being as well as citizen-scientist. And of course, read more broadly than that -- biographies, "Harry Potter", history, and so on. Two useful historians to read include: "A People's History of the United States" http://www.howardzinn.org/ and "Lies My Teacher Told Me: Everything Your American History Textbook Got Wrong" http://www.uvm.edu/~jloewen/ The concepts in these books may well shape the US political spectrum in the next couple of decades, and our technosphere may well then be reconstructed to reflect these changing social values. See also, "Autonomous Technology: Technics-out-of-Control as a Theme in Political Thought" as it grapples directly with this issue of technological development reflecting social values (it's kind of dry, but some of his other writings may be more accessible). http://www.rpi.edu/~winner/ A computer language like Python (as opposed to C++) in a way reflects a different mindset about accessability and changeability (see Guido's "Computer Programming for Everybody") http://www.python.org/doc/essays/ppt/acm-cp4e/ in the same way that local solar panels or home biomass fuel cells or better home insulation alter the political power landscape as opposed to large centralized nuclear or coal power plants or oil tankers. Always be aware that the technological systems you build reflect your values. It's kind of not a surprise to me that Python came from the Netherlands (progressive social system) or Smalltalk from sort-of-hippies in California :-) or GNU/Linux from Finland (well, OK, and RMS/GNU in Boston post-MIT, which sort of wrecks that analogy :-). And beware the PhD pyramid scheme. See a comment by the Vice Provost of Caltech on the state of science jobs today as testimony to Congress: http://www.house.gov/science/goodstein_04-01.htm In short, Prof. Goodstein says because of this focus on the PhD in US science, much US education and educators down to the high school level are somewhat inadequate to the task of imparting useful skills for other than those heading to do the most elite abstract research, unlike say the technical education available in some of Europe. An excerpt from that page: "The problem, to reiterate, is that science education in America is designed to select a small group of elite scientists. An unintended but inevitable side effect is that everyone else is left out. As a consequence of that, 20,000 American high schools lack a single qualified physics teacher, half the math classes in American schools are taught by people who lack the qualifications to teach them, and companies will increasingly find themselves without the technical competence they need at all levels from the shop floor to the executive suite. To solve this problem will take nothing less than a reform of both education and society. We must have as our goal a nation in which solid scientific education will form the basis of realistic career opportunities at all levels, in industry, government and in education itself, from kindergarten to graduate school. As long as we train a tiny scientific elite that cares not at all about anyone else, and everyone else wears ignorance of science and mathematics as a badge of honor, we are putting our future as a nation and as a culture in deep peril." I'm not saying don't get a CS PhD someday down the road to realize a dream of becoming a computer scientist if that is what you want (although please understand the difference between a software developer and a mathematician who studies algorithms and how that relates to the courses you take and universities you choose to attend) -- just understand what you are getting yourself into and how that PhD system has distorted science and technical education in the US at present (and that link above explains why in some detail). Also, on the issue of volunteerism Stan raise, contributing early and often to various open source / free software projects that are of interest to you (such as contributing to Python) is a way to both gain visibility in the computer world as well as to leave a meaningful legacy behind no matter where your career and life takes you. Obviously, get your parent(s)'s or guardian's permission first if legally or morally needed. All the best. --Paul Fernhout http://www.pointrel.org -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! -----== Over 100,000 Newsgroups - 19 Different Servers! =----- From cnetzer at sonic.net Sun Aug 31 17:08:43 2003 From: cnetzer at sonic.net (Chad Netzer) Date: Sun, 31 Aug 2003 14:08:43 -0700 Subject: list.sort(func) speed In-Reply-To: <20030831203354.GK9311@incise.org> References: <20030831190745.GH9311@incise.org> <1062360910.1852.44.camel@adsl-209.204.179.133.sonic.net> <20030831203354.GK9311@incise.org> Message-ID: <1062364123.1852.53.camel@adsl-209.204.179.133.sonic.net> On Sun, 2003-08-31 at 13:33, mackstann wrote: > No, but the thought of inserting things in order did not quite occur to > me. Can you give me an simple example of exactly how to go about this? Don't have time for an example at the moment. But the bisect module will do it for you. help('bisect') help('bisect.insort') The basic way in which it works (I assume, having not looked at the code), is a binary search algorithm, which is very fast. -- Chad Netzer From eric.brunel at pragmadev.com Mon Aug 18 06:13:57 2003 From: eric.brunel at pragmadev.com (Eric Brunel) Date: Mon, 18 Aug 2003 12:13:57 +0200 Subject: Python/Tkinter/tk crash [long] References: Message-ID: Pedro Rodriguez wrote: > On Thu, 14 Aug 2003 09:10:22 +0000, Eric Brunel wrote: > > >>Hi all, >> >>I was creating a Tkinter widget in the style of the reversed tabs below Excel >>worksheets and I stepped in a serious problem: the code I made makes python >>crash with a seg fault, bus error or X11 BadGC error on both Solaris (2.6 and >>2.7) and Linux (Mandrake 8.0); it doesn't crash on Windows. I tried to simplify >>the script, but I couldn't reproduce the crash with a simpler code. So the code >>below is somewhat long; sorry for that. >> >>To make it crash, just run the script and click on a tab. It usually crashes at >>the first click, but you may have to play a bit with the tabs. I tried to run >>Python through gdb to see where the crash happens, but it seems to be quite >>random. Maybe a memory corruption? >> >>There's a simple workaround, but with drawbacks: at the beginning of the >>__update method, if I do not destroy and re-create the Canvas, but simply empty >>its contents, the script works. But it keeps the commands declared created at >>the tcl level for the former bindings, so it silently eats up memory. >> > > > As far as I understand, the __changeTab method is called when an event > occurs on the __tabsCanvas. But one of the first actions of the __update > method (which is called by __changeTab) is to destroy the __tabsCanvas > object. > > So DURING the callback call you are destroying the object to which the > callback is bound. I wonder if this is the cause of the blow up at the > return of the callback (it may depend on how the memory is reallocated > on different systems). In fact, you're absolutely right, but it still shouldn't result in a crash. I also discovered that the problem only happens with ButtonRelease events, and not ButtonPress ones. Apparently, the tcl interpreter doesn't properly remembers that the pointer on the canvas shouldn't be freed until the binding is completely executed. I've reported the problem to the comp.lang.tcl newsgroup. I hope they'll have a solution for it, because I can't figure out by myself what I should do to prevent the crash (I'm not that familiar with the code for tcl/tk). For the moment, I'll use bindings on ButtonPress's rather than ButtonRelease's. Thanks a lot to all who answered anyway! -- - Eric Brunel - PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com From aleax at aleax.it Thu Aug 21 12:25:51 2003 From: aleax at aleax.it (Alex Martelli) Date: Thu, 21 Aug 2003 16:25:51 GMT Subject: how fast is Python? References: Message-ID: Mark Carter wrote: ... > The following algorithm was implemented in each of the target > languages: > > X = 0.5 > For I = 1 to 108 > X = 1 ? X* X > Next > > Timings were made for the execution. The following results were > obtained: > > Language Timing (seconds) > VB ? uncompiled 74 > VB ? compiled 37 > VBA ? Excel 75 > Python 401 > C++ - debug version 4 > C++ - release version 3 > Fortran 3 Interesting. One wonders what and where you measured, e.g: [alex at lancelot gmpy]$ cat a.cpp int main() { double X = 0.5; for(int i = 0; i < 108; i++) X = 1 + X * X; return 0; } [alex at lancelot gmpy]$ g++ -O3 a.cpp [alex at lancelot gmpy]$ time ./a.out 0.01user 0.00system 0:00.00elapsed 333%CPU (0avgtext+0avgdata 0maxresident)k 0inputs+0outputs (186major+21minor)pagefaults 0swaps i.e., it's just too fast to measure. Not much better w/Python...: [alex at lancelot gmpy]$ cat a.py def main(): X = 0.5 for i in xrange(108): X = 1 + X*X main() [alex at lancelot gmpy]$ time python -O a.py 0.03user 0.01system 0:00.15elapsed 26%CPU (0avgtext+0avgdata 0maxresident)k 0inputs+0outputs (452major+260minor)pagefaults 0swaps i.e., for all we can tell, the ratio COULD be 100:1 -- or just about anything else! Perhaps more details are warranted... Alex From jcribbs at twmi.rr.com Fri Aug 15 21:56:13 2003 From: jcribbs at twmi.rr.com (Jamey Cribbs) Date: Sat, 16 Aug 2003 01:56:13 GMT Subject: ANNOUNCE: KirbyBase 1.3 Message-ID: KirbyBase 1.3 is now available at: http://www.netpromi.com/files/KirbyBase-1.3.zip What is KirbyBase? KirbyBase is a simple, pure-Python, plain-text, flat-file database management system that can be used either embedded in your application or in a client/server, multi-user mode. To find out more about KirbyBase, go to: http://www.netpromi.com/kirbybase.html Changes: Added ability to pass field values to update and insert using a dictionary. Added ability to specify field to sort on and sort direction for the results of a select. Added len method. Fixed bug in validateMatchCriteria where script was not restricting other match criteria if already attempting to match by recno. Fixed bug in validateMatchCriteria where script was not checking to see if pattern argument was an integer when attempting to match by recno. Changed the way field types are handled internally. This should not change any of the api or interfaces, EXCEPT for the getFieldTypes method, which now returns a list of types, instead of a list of strings. I hope this doesn't screw anyone's programs up. Corrected version number to conform to guidelines in distutils documentation. From cartermark46 at ukmail.com Mon Aug 18 10:05:06 2003 From: cartermark46 at ukmail.com (Mark Carter) Date: 18 Aug 2003 07:05:06 -0700 Subject: ClientCookie bug (followup) References: <87fzk4sav2.fsf@pobox.com> <87znibzrnx.fsf@pobox.com> <87oeypdh92.fsf@pobox.com> Message-ID: > I'll investigate further. Here are the results from running tests in ClientCookie 0.4.4.a: def go7(): #ClientCookie 0.4.4.a: #works from win xp and win 98 # I prefer this method as a better way than using load_from_registry() #use this method!! import ClientCookie c = ClientCookie.MSIECookieJar() # do NOT set delayload #c.user_name = "mark carter" c.load_cookie_data("hemscott-cookie.bin") #c.load_from_registry() print c import urllib2 url = 'http://businessplus.hemscott.net/corp/crp03733.htm' request = urllib2.Request(url) response = urllib2.urlopen(request) c.extract_cookies(response, request) #let's say this next request requires a cookie that was set in response request2 = urllib2.Request(url) c.add_cookie_header(request2) response2 = urllib2.urlopen(request2) print response2.geturl() print response2.info() # headers print response2.read() response2.close() def go8(): #ClientCookie 0.4.4.a: #contains bug in Win98 when environ variable is commented out, #but works in win98 when environ variable is set #Works in win xp , regardless of the USERNAME line #this works - I can now import into Hemscott import ClientCookie c = ClientCookie.MSIECookieJar(delayload=1) #c.user_name = "mark carter" #os.environ['USERNAME'] = 'mcarter' #needed by load_from_registry() c.load_from_registry() import urllib2 url = 'http://businessplus.hemscott.net/corp/crp03733.htm' request = urllib2.Request(url) response = urllib2.urlopen(request) #c.extract_cookies(response, request) # let's say this next request requires a cookie that was set in response request2 = urllib2.Request(url) c.add_cookie_header(request2) response2 = urllib2.urlopen(request2) print response2.geturl() print response2.info() # headers for line in response2.readlines(): # body print line The upshot of this is that load_cookie_data() now works in win 98 and xp. load_from_registry() works from win xp; it works from win 98 if and only if you set the USERNAME environment variable. I appreciate that all the stuff about request2 and response2 may not be to your liking - but at the moment I'm just trying to figure out what works, and what doesn't. We can also worry about the delayload business later. What do you think about the idea of actually setting up an Aapache web page to test these things 'for real'? From s0199583 at sms.ed.ac.uk Wed Aug 20 12:20:29 2003 From: s0199583 at sms.ed.ac.uk (Matt Smith) Date: 20 Aug 2003 09:20:29 -0700 Subject: python quickie : retrace function steps? Message-ID: <5f5c82ec.0308200820.51c8e33c@posting.google.com> hi all, If I was to make a function call another function, and from that function, call another function (so that now I was in a 3rd function) something like this: (function 1) |________(function 2) |________(function 3) Is there away I can print out the path my Program had taken (i want to do this as part of my error checking, so a user would always know the path my program took)? i.e. printted output of error would be: error with function 3 function 3 called from function 2 function 2 called from function 1 In perl there is a function called CALLER, which I have used to the same effect, i was wondering if python had something similar for this? cheers in advance, matt From vanevery at 3DProgrammer.com Sun Aug 10 00:08:16 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Sat, 9 Aug 2003 21:08:16 -0700 Subject: Python vs. C# References: Message-ID: <3f35c30d@shknews01> Brian Quinlan wrote: > 4. forcing everything into a class is stupid e.g. does anyone really > like writing Math.sin(x) over sin(x)? Although tacky at first glance, it's not entirely stupid. I've written many, many variations on sin(x) cos(x) because one often wants an efficient approximation for some algorithmically specific purpose. They all end up with slightly funny different names, so why not namespace 'em? And IIUC, you could simply write using Math and be done with the issue, I think. Can't respond to any of your other points, I haven't a clue, which is why I posted. :-) Thanks for the input. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From tina_li23AThotmailDOTcom Fri Aug 29 11:19:41 2003 From: tina_li23AThotmailDOTcom (Tina Li) Date: Fri, 29 Aug 2003 11:19:41 -0400 Subject: pmw menu item's 'command' attribute References: <3f4e5687_4@corp.newsgroups.com> Message-ID: <3f4f6f5f$1_4@corp.newsgroups.com> Thanks so much! Both the explanation and the code worked. Basically when a lambda function is created, any references to global variables are not evaluated until when it's executed. So if the global var changes value before that the lambda function follows suit and takes the last value it has settled at. Thanks again! Tina "Peter Otten" <__peter__ at web.de> wrote in message news:bilrdk$6j5$04$1 at news.t-online.com... | "Tina Li" wrote: | | > for size in ('tiny', 'small', 'average', 'big', 'huge'): | > self.menuBar.addmenuitem('Size', 'command', 'Set size to ' + | > size, | > command = lambda: cmd.do('change size ' + size), | > label = size) | | The variable size in the lambda expression is bound to the global variable | size, so if you do | | size = 42 | | later, the menu command will even raise an exception. | Solution: | | command=lambda size=size: cmd.do('change size ' + size) | | This creates a local variable size that defaults to the same string that the | outer size variable is bound to when the lambda expression is created. | (Don't know if the explanation works, but the code should :-) | | Peter | -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! -----== Over 100,000 Newsgroups - 19 Different Servers! =----- From duncan at NOSPAMrcp.co.uk Thu Aug 14 06:16:36 2003 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Thu, 14 Aug 2003 10:16:36 +0000 (UTC) Subject: Error solution References: Message-ID: Sanjeev Trehan wrote in news:mailman.1060852019.2478.python-list at python.org: > When I write in command line the following eoors come: >>>> print a > File"" Indentation error:Expected an indented block. >>>>lambda x:x+n > File"" return^ lambda x:x+n > Indentation error:Expected an indented block. > > Please solve my problem and explain from where should I start learning > Python. Waiting for reply. You typed something before each of these lines and Python was waiting for an indented block, but you can't have copied your input or your error messages exactly. Please post again including the lines before the ones giving you this problem, and this time using cut/paste to make sure you get an accurate copy. The tutorial you have is the correct place to start learning Python. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From adalke at mindspring.com Mon Aug 18 14:20:50 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Mon, 18 Aug 2003 12:20:50 -0600 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: Message-ID: Brandon J. Van Every: > What's ***TOTALLY COMPELLING*** about Ruby over Python? Nothing. I think several people have been very explicit in saying that Ruby has some advantages over Python, and vice versa, that in most cases it's a wash, but that there's nothing 'TOTALLY COMPELLING" about Ruby. You need to acquire critical reading skills. And this sort of post is making your troll mark almost indelible. Andrew dalke at dalkescientific.com From essai1 at mci.local Tue Aug 5 05:25:08 2003 From: essai1 at mci.local (News M Claveau /Hamster-P) Date: Tue, 5 Aug 2003 11:25:08 +0200 Subject: .zip files sample manip References: Message-ID: Merci beaucoup ! Thank you ! Je ne pas parle pas l'anglais, et je voulais quand m?me faire profiter tout le monde de cette petite ?tude logicielle (le NG 'fr' est pr?venu). @-salutations -- Michel Claveau From find.me at my.homepage.net Thu Aug 21 22:25:01 2003 From: find.me at my.homepage.net (Blake Garretson) Date: Thu, 21 Aug 2003 22:25:01 -0400 Subject: Adding a column in a tab delimited txt file In-Reply-To: References: Message-ID: And I meant: outfile = file("out.txt", 'w') I warned you the code might not be perfect! -------------------------------------------------- Blake T. Garretson http://blakeg.freeshell.org From peter at engcorp.com Fri Aug 29 13:45:54 2003 From: peter at engcorp.com (Peter Hansen) Date: Fri, 29 Aug 2003 13:45:54 -0400 Subject: cannot get pexpect to work References: <3F4F6AF0.CA9BB337@engcorp.com> Message-ID: <3F4F9152.ABC73E49@engcorp.com> Andrei wrote: > > "Peter Hansen" wrote in message > news:3F4F6AF0.CA9BB337 at engcorp.com... > > No, but why is it asking for a new password confirmation? > > You're just trying to log in, not change the password, aren't > > you? Or does passmass.py actually change the passwords, not > > just log in? (I don't have the script.) Have you read it? > > Perhaps you've misinterpreted what it is supposed to do. > > that's exactly right, as I forgot to mention: it changes passwds > on a list of remote systems, this list being the list of args to > the script, which is now linked here btw: > > http://area52.homeunix.org/testarea/passmass.py.txt Unfortunately at this moment (13:45 EDT) I get no response to connection requests on port 80. (That is, server is answering pings, but no web server on standard port.) -Peter From postmaster at GSN.com Thu Aug 21 08:32:01 2003 From: postmaster at GSN.com (System Administrator) Date: Thu, 21 Aug 2003 05:32:01 -0700 Subject: Undeliverable: Your details Message-ID: Your message To: Webmaster Subject: Your details Sent: Thu, 21 Aug 2003 00:40:18 -0700 did not reach the following recipient(s): Webmaster on Thu, 21 Aug 2003 05:32:01 -0700 The recipient was unavailable to take delivery of the message MSEXCH:MSExchangeIS:GSNLA:GSNEXC001 -------------- next part -------------- An embedded message was scrubbed... From: python-list at python.org Subject: Your details Date: Thu, 21 Aug 2003 00:40:18 -0700 Size: 1014 URL: From pdfernhout at kurtz-fernhout.com Sun Aug 24 01:41:58 2003 From: pdfernhout at kurtz-fernhout.com (Paul D. Fernhout) Date: Sun, 24 Aug 2003 01:41:58 -0400 Subject: How to store data? In-Reply-To: <3f482037_5@corp.newsgroups.com> References: <3f482037_5@corp.newsgroups.com> Message-ID: <3f484fce_1@corp.newsgroups.com> This bug has been fixed and a new package uploaded to SourceForge. http://sourceforge.net/projects/pointrel/ I also included the example code file previously posted based on your requirements (and I referenced your email in it through a google news link). Thanks for the motivation. --Paul Fernhout Paul D. Fernhout wrote (in reply to a query by Lars Behrens) : > [And, as an example of bleeding edge, from testing this, I found a bug > from a last minute change I made to the unique ID system which had been > working well for a long time; it turns out that because of an error in > how I open a support file when it does not exists, the file > "a_pointrel_uniqueIDCounter.txt" now needs to exist in the local > directory with a number (e.g. '10') in it to get sequence numbers in > addition to a random ID component in unique IDs. The system still works > without this file though -- the unique IDs just aren't as collision > resistant. Something for an incremental release ASAP though.] -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! -----== Over 100,000 Newsgroups - 19 Different Servers! =----- From max at alcyone.com Thu Aug 28 22:05:09 2003 From: max at alcyone.com (Erik Max Francis) Date: Thu, 28 Aug 2003 19:05:09 -0700 Subject: another puzzled newbie References: <68g3b.855589$ro6.16997110@news2.calgary.shaw.ca> Message-ID: <3F4EB4D5.4BE04B12@alcyone.com> Elaine Jackson wrote: > "Chad Netzer" wrote in message > news:mailman.1062051053.30902.python-list at python.org... > > > You don't need the '(' and ')' here. del is a keyword, not a > > function. > > Can't it be both? Could you explain why it fails to be a function? Because it doesn't only not return a value, it _can't_ return a value: >>> def f(x): print x ... >>> f("This is a function") This is a function >>> returnValue = f("This is a function") This is a function >>> returnValue is None True >>> g = f >>> del f >>> returnValue = del f File "", line 1 returnValue = del f ^ SyntaxError: invalid syntax Treating del as if it were a function is illegal. The same goes for the other statements, like print. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ The average dog is a nicer person than the average person. \__/ Andrew A. Rooney From tjreedy at udel.edu Sat Aug 23 19:46:42 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 23 Aug 2003 19:46:42 -0400 Subject: Modifying the {} and [] tokens References: <04cekv0s6ghjtuhl5j2gph7ltobdb5rsam@4ax.com> <62rekv0k4ucgrh46lkp27klq13pq8ppp5p@4ax.com> <1h3fkvg8mkeq69a8hriojugqfcp75hafjj@4ax.com> Message-ID: "Geoff Howland" wrote in message news:veefkvs764jl56ub2b0bt4cn4lekcv0mhf at 4ax.com... > In retrospect, I probably should have just not responded at all to the > thread portion that I felt that way about, as other people were giving > me answers I thought were completely even. An excellent idea (which I generally try to practice myself). As for the Ruby suggestion: It is precisely because we are generally pragmatists and not everyone-should-always-program-in-Python fanatics that someone occasionally suggests that a particular person might (repeat, might) find another language more suitable. The canonical example is people distressed by naked code unwrapped by redundant braces. If they can't adjust and won't use 'weaning' braces ('#{' and '#}'), then they should use a language that better fits their mindset. As for 'reasonable' idea rejection: There is effectively no limit to what people can collectively think up, and as the community expands, the number and breadth of ideas also expands. One of Guido's main jobs now is to reject most ideas for 'improvement', no matter how 'reasonable' in isolation. If your particular wish should remain ungranted a year from now, welcome to the club. Terry J. Reedy From abcdebl2nonspammy at verizon.net Sat Aug 23 00:55:53 2003 From: abcdebl2nonspammy at verizon.net (David Lees) Date: Sat, 23 Aug 2003 04:55:53 GMT Subject: Indentation question Message-ID: I have a real basic how-to question. When I decide to reuse a piece of python code at a different indentation level than the original, is there a common trick (or set of tricks) for moving the indentation correctly for the whole block? Probably this is editor dependent, so if some has a FAQ or pointer to a page please feel free to post. Typical I use PythonWin as my editor, though sometimes I use EditPadLite (an ascii editor). TIA David Lees From cedmunds at spamless.rochester.rr.com Sat Aug 2 22:48:58 2003 From: cedmunds at spamless.rochester.rr.com (Cy Edmunds) Date: Sun, 03 Aug 2003 02:48:58 GMT Subject: very newbie question References: Message-ID: "Agent Mulder" wrote in message news:bgglpl$v4r$1 at news2.tilbu1.nb.home.nl... > Hi group, > > I wonder if I can do Windows programming > in python. I work with c++ now and do the > Windows part raw. It's difficult to get my app > over 150K (need some heavy inlining, that's all). > Does python support nitty-gritty Windows- > programming? > > -X > Hi Mulder. The good news is this: with Mark Hammond's win32 library Windows programming in Python is actually much easier (IMHO) than it is in C++. Get the book too -- it is really very good. -- Cy http://home.rochester.rr.com/cyhome/ From Blue_Eyes8 at gmx.de Wed Aug 6 12:57:58 2003 From: Blue_Eyes8 at gmx.de (Blue_Eyes8 at gmx.de) Date: Wed, 06 Aug 2003 18:57:58 +0200 Subject: Python-list digest, Vol 1 #16803 - 11 msgs In-Reply-To: <20030805215616.30748.57981.Mailman@mail.python.org> Message-ID: <3F314FB6.14775.795B2@localhost> Contents of Python-list digest..." From mpeuser at web.de Sun Aug 31 15:02:56 2003 From: mpeuser at web.de (Michael Peuser) Date: Sun, 31 Aug 2003 21:02:56 +0200 Subject: Confusion re "global" statement References: Message-ID: "Chris Stromberger" schrieb im Newsbeitrag news:l2g4lvgam2vlqkk78ep03rlpmv3dn3ni03 at 4ax.com... > This doesn't seem like it should behave as it does without using > "global d" in mod(). > > d = {} > > def mod(): > d['hey'] = 3 > > mod() > print d > > When run, it prints {'hey': 3}. Seems like it should print {} w/o > using "global d". > > Can someone explain? I guess it has to do with the fact that I'm not > reassigning the name d in the function, but it seems counter-intuitive > that I'm able to modify a global inside the function w/o saying > "global d". Well Chris, it *may* be counter-intuitive. On the other hand it is very consequent. Think of what happens in an _ordinary_ programming language when you use a name in a block or subroutine: - either it is locally defined/declared: the loccal version is taken - if it is not, the global version is used - if there is no global version, an error message is issued. Just the same with Python! But do we define/declare variables in Python? Yes, by simply assigning a value to them! In case of your list note that you do not assign a new value to _d_ but to just to one of it's items. Kindly Michael P From paul at grosss.net Sat Aug 9 01:25:28 2003 From: paul at grosss.net (Paul Gross) Date: Sat, 09 Aug 2003 00:25:28 -0500 Subject: Python and Web Hosting In-Reply-To: References: Message-ID: Here is a list of web hosts which offer python: http://www.python.org/cgi-bin/moinmoin/PythonHosting Ken Fettig wrote: > Hello, I am begining to learn the Python language and I am enjoying its > flexibility. I do have a question. I am considering using Python for web > development. I have found that a huge number of web hosts offer support for > PHP. How hard is it to find a Web Host that will allow you to you to run > your own Python scripts, web or app server, template engine (Zope or > Cheetah)? If it is not, is it comparable in cost? > > Thanks > Ken > kenfettig at btinet.net > > > From fincher.* at osu.edu Thu Aug 7 03:10:10 2003 From: fincher.* at osu.edu (Jeremy Fincher) Date: Thu, 07 Aug 2003 03:10:10 -0400 Subject: itertools.ilen? Message-ID: Sometimes I find myself simply wanting the length of an iterator. For example, to collect some (somewhat useless ;)) statistics about a program of mine, I've got code like this: objs = gc.get_objects() classes = len([obj for obj in objs if inspect.isclass(obj)]) functions = len([obj for obj in objs if inspect.isroutine(obj)]) modules = len([obj for obj in objs if inspect.ismodule(obj)]) dicts = len([obj for obj in objs if type(obj) == types.DictType]) lists = len([obj for obj in objs if type(obj) == types.ListType]) tuples = len([obj for obj in objs if type(obj) == types.TupleType]) Now, obviously I can (and will, now that 2.3 is officially released :)) replace the list comprehensions with itertools.ifilter, but I need an itertools.ilen to find the length of such iterators. I can imagine such a need arises in more useful situations than this, but this is the particular case that brought the need to mind. The Python code is simple, obviously: def ilen(iterator): i = 0 for _ in iterator: i += 1 return i But it's a pity to use itertools' super-fast iterators and have to use slow, raw Python to determine their length :) Jeremy From merkosh at hadiko.de Wed Aug 20 13:41:21 2003 From: merkosh at hadiko.de (Uwe Mayer) Date: Wed, 20 Aug 2003 19:41:21 +0200 Subject: ascii2dec Message-ID: Hi, this must sound stupid to you, but I'm ages out of Python and I just can't find a function to convert 4 bytes of binary data to an integer value: length=f.read(4) # get length in binary length=socket.htonl(length) # swap bytes #convert 4 bytes to integer f.close() Thanks for any help Uwe -- From zeitlin at parthe.lpthe.jussieu.fr Sat Aug 9 17:13:31 2003 From: zeitlin at parthe.lpthe.jussieu.fr (Vadim Zeitlin) Date: Sat, 9 Aug 2003 21:13:31 +0000 (UTC) Subject: email client written with python + wxWindows References: <409a56e2.0308062211.456575df@posting.google.com> Message-ID: [this is really OT but the opportunity was too good...] On Sat, 09 Aug 2003 11:19:37 GMT, JanC wrote: > Gerhard H?ring schreef: > >> Mahogany has support for Python scripting in the sourcecode, but AFAIR >> it hasn't been updated for years. > > Last Windows binary build is dated 2003-07-15... And the next release should happen really soon now (no joking). Unfortunately, Python support will almost surely be disabled in it because there is not enough interest in it to motivate me to maintain it and so right now it doesn't even support 2.2 without speaking of 2.3 (only 1.5, 1.6 and 2.1). But if someone would like to have a relatively powerful cross-platform mail client scriptable in Python Mahogany would be a great to start and any help with the embedded Python interpreter would be very welcome. Regards, VZ -- GCS/GM d? H+ s++:-- p2 au--- a- w+ v C+++ UBLS+++ P- L++ N++ E--- W++++ M? V-- -po+ R++ G`` !tv b+++ D--- e++++ u++ h--- f+ r++ n- y? From DennisR at dair.com Sun Aug 17 14:20:06 2003 From: DennisR at dair.com (Dennis Reinhardt) Date: Sun, 17 Aug 2003 18:20:06 GMT Subject: Path Problem on W2K? References: <93f5c5e9.0308170927.6e0bdc38@posting.google.com> Message-ID: > C:\>python 'name-of-script.py' > 'python' is not recognized as an internal or external command, > operable program or batch file. Try python.exe instead of python as the command. -- Dennis Reinhardt DennisR at dair.com http://www.spamai.com?ng_py From brandon at its.caltech.edu Thu Aug 14 14:27:36 2003 From: brandon at its.caltech.edu (Brandon Michael Moore) Date: Thu, 14 Aug 2003 11:27:36 -0700 (PDT) Subject: Is Python your only programming language? In-Reply-To: Message-ID: On 14 Aug 2003, Nick Vargish wrote: > Tim Rowe writes: > > > If I want to get something up and running quickly then I go straight > > to Python. If thousands of lives depend on the code working right I > > would not be allowed to use Python, and, IMHO, quite rightly too. It > > just doesn't have what it needs for proving correctness, and adding > > those things would scupper the getting things up and running > > quickly. > > So what programming language actually does bridge the gap between > "thousands of lives depend on the code working right" and "getting > this up and running quickly"? > > Whenever someone implies that compile-time type checking provides some > "proof of correctness", I think about (void *) and am not very > convinced. > > Nick Sure, type checking with a sorry excuse for a type system like C provides doesn't buy you that much. Take a look at Haskell (espcially the GHC type system extensions). In the functional programming community people say "if it type checks it usually works", and Haskell's type system is stronger than most. It's probably worth pointing out that strong typing doesn't mean you need to fill your program with types like C. Most of the types in a Haskell program are inferred. You can say things like "takes any object that can be converted to a string". If you are sufficiently perverse you can even given an append operation a type that reflects the length of the lists. Referential transparency makes it much easier to prove the correctness of functions in isolation, which isn't really the type system, but does help write correct code. For rapid development lazy evaluation and the IO system (monads) make it really easy to define and combine abstractions. You can take "once and only once" a lot farther than in most languages. There are a few weaknesses though. Performance isn't as good as you might expect from a compiled language (you can always write C though). Library support is a bit weak for things like data base interfaces and GUIs. There are interesting GUI and database libraries, but nothing really mature. Actually, I think python with a litte bit of type checking would be safer than C++ or Java. C++ has explict memory management, which can be a pain to debug, and Java has no templates so any generic functions lead to code littered with unsafe downcasts. Python does garbage collection, and a program checker can use any type system it wants. Probably 99% of python code could be given types like "takes objects with these methods", etc. The smartest tool I know of is PyChecker which doesn't sound like it does more type checking that counting arguments. I just heard about it today though, so I'm probably wrong. Brandon From essai1 at mci.local Mon Aug 11 15:32:57 2003 From: essai1 at mci.local (News M Claveau /Hamster-P) Date: Mon, 11 Aug 2003 21:32:57 +0200 Subject: Fixes to zipfile.py [PATCH] References: <87heae244i.fsf@christoph.complete.org> <3E6A4322.9010908@rsballard.com> Message-ID: Hi ! Please, look my (little) contribution to "command-line-manip-zip-files" http://mclaveau.com/ress/python/zipmci.htm (But, good idea : it's in Python+French) @-salutations -- Michel Claveau From christianzlong at yahoo.com Fri Aug 8 14:59:07 2003 From: christianzlong at yahoo.com (Christian Long) Date: 8 Aug 2003 11:59:07 -0700 Subject: Problem with DCOracle2 stored procedure calls Message-ID: <8847f370.0308081059.7ac17147@posting.google.com> Hi I'm having trouble with some stored procedure calls on DCOracle2. I think the trouble is with dynamic binding. See version & environment info at end of message I have 2 stored procedures - call them M4 and M5. They have similar (but not the same) parameters, and are called from python in a similar manner. M4 succeds and M5 fails. M5 fails because a null string termination character \x00 has been appended to certain argument, so the argument value does not match the value in the database table. Both stored procedures succeed when called from Oracle SQL*Plus My Python code and the stored procedure signatures are all at the end of the message ------ M4 results viewed from Python - Succeeds Before procedure call ('1779', '199318', OracleDate("2003-08-07 00:00:00"), 1.0, 'EA', 'A', 'Q26BB', None, 'NA', 'M4 Inv Adjust', None, 'Adjust', 1, 'Y', None, None, None) After procedure call ['1779', '199318', OracleDate("2003-08-07 00:00:00"), 1.0, 'EA', 'A', 'Q26BB', None, 'NA', 'M4 Inv Adjust', None, 'Adjust', 1, 'Y', 'AAAKfBAAGAAAfXBAAd', 'N', None] Updated inventory ------ M5 results viewed from Python - Fails Before procedure call ('1779', '199318', OracleDate("2003-08-07 00:00:00"), 1.0, 'EA', 'A', 'Q26BB', 'A', 'Q26FB', None, 'M5 Bin Move', 76746, 'RC', None, None, None) After procedure call ['1779', '199318', OracleDate("2003-08-07 00:00:00"), 1.0, 'EA\x00', 'A\x00', 'Q26BB\x00', 'A\x00', 'Q26FB\x00', None, 'M5 Bin Move', 76746, 'RC', None, 'Y', 'Area/Bin does not exist in location master, please enter a valid location.'] An error occurred while saving changes. Changes were not saved. ^--- My error message ----------------------------------------^ Area/Bin does not exist in location master, please enter a valid location. ^--- Oracle stored procedure error message ------------------------------^ ------- As we can see, a null string termination character \x00 has been appended to five arguments in the returned values form the M5 procedure call. Thanks very much for your help. Christian Long ---------------------------------------------------------------------------- My Research ---------------------------------------------------------------------------- I did a diff between the tracelog files. Here are some interesting snippets. Let me know if you want the full dump files. ~1MB. It looks like the failing call is using dynamic binding , and the successful one is using static. Here we see the calls to two different stored procedures < 33, OCIStmtPrepare, Ox########, Ox######## ?= BEGIN PROCIAPI.ADJUST_INVENTORY(:1,:2,:3,:4,:5,:6,:7,:8,:9,:10,:11,:12,:13,:14,:15 ,:16,:17); END;, 98, * --- > 33, OCIStmtPrepare, Ox########, Ox######## ?= BEGIN PROCIAPI.ICBM_MOVE(:1,:2,:3,:4,:5,:6,:7,:8,:9,:10,:11,:12,:13,:14,:15,:16); END;, 87, * This looks like a trouble spot: --- > 64, bindObject, BindingArrayObject, * > 18, bindObject, 0, 1, Ox########, 256, * > 33, OCIBindByPos, Ox########, 5, Ox########, 256, 1, 0, * > 97, OCIBindByPos, supplemental, 0, Ox########, 2, 3, * 7245a7660,7661 > 33, OCIBindDynamic, Ox########, * > 34, OCIBindDynamic, 0, OUT, Ox########, Ox########, * 7253,7256c7669,7672 < 64, bindObject, SQLT_STR, Ox######## ?= A, * < 18, bindObject, 0, 5, Ox########, 2, * < 33, OCIBindByPos, Ox########, 6, Ox########, 2, 5, 0, * < 97, OCIBindByPos, supplemental, 0, Ox########, 0, 2, * --- And later, we see datatype conflict in the dynamic binding of the failing stored procedure. Note the points of failure correspond to the parameters that come back with \x00 appended to them. EA, A, Q26BB, A Q26FB --- > 33, OCIBindByPos, Ox########, 16, Ox########, 256, 1, -1, * 7411a7827,7871 > 17, dynamicBindIn, Ox########, 0, 0, * > 18, dynamicBindIn, Ox######## ?= xg, 7, Ox########, 0, 0, * > 17, dynamicBindIn, Ox########, 0, 0, * > 20, dynamicBindIn, datatype conflict, 1, 5, * > 18, dynamicBindIn, Ox######## ?= EA, 3, Ox########, 0, 0, * <-Note "EA" > 17, dynamicBindIn, Ox########, 0, 0, * > 20, dynamicBindIn, datatype conflict, 1, 5, * > 18, dynamicBindIn, Ox######## ?= A, 2, Ox########, 0, 0, * <- "A" > 17, dynamicBindIn, Ox########, 0, 0, * > 20, dynamicBindIn, datatype conflict, 1, 5, * > 18, dynamicBindIn, Ox######## ?= Q26BB, 6, Ox########, 0, 0, * <- "Q26BB" > 17, dynamicBindIn, Ox########, 0, 0, * > 20, dynamicBindIn, datatype conflict, 1, 5, * > 18, dynamicBindIn, Ox######## ?= A, 2, Ox########, 0, 0, * <- "A" > 17, dynamicBindIn, Ox########, 0, 0, * > 20, dynamicBindIn, datatype conflict, 1, 5, * > 18, dynamicBindIn, Ox######## ?= Q26FB, 6, Ox########, 0, 0, * <- "Q26FB" > 17, dynamicBindOut, Ox########, 0, 0, 0, * > 161, OCIAttrGet, Ox########, OCI_HTYPE_BIND, Ox########,OCI_ATTR_ROWS_RETURNED, * > 162, OCIAttrGet, 0, 0, * > 18, dynamicBindOut, Ox########, Ox########, 256, Ox########, Ox########,* > 17, dynamicBindOut, Ox########, 0, 0, 0, * ---------------------------------------------------------------------------- My Python code ---------------------------------------------------------------------------- --- M4 t_empno = utility.userId t_item_no = dataBucket['K_itemNumber'] t_trans_dt = mra_data_m4.getTodayAsOracleDate() t_trans_qty = dataBucket['K_adjustQuantity'] t_trans_um = dataBucket['K_stockUM'] t_stock_area = dataBucket['K_stockArea'] t_bin_loc = dataBucket['K_binLoc'] t_control_no = None t_reason_cd = dataBucket['K_reasonCode'] t_reference = HEADER_TEXT t_trans_type = None t_ref_order = "Adjust" t_rtv_no = 1 t_insert_log = "Y" t_rowid = None t_failed = None t_message = None # Pack the parameters into a tuple parameters = (t_empno, t_item_no, t_trans_dt, t_trans_qty, t_trans_um, t_stock_area, t_bin_loc, t_control_no, t_reason_cd, t_reference, t_trans_type, t_ref_order, t_rtv_no, t_insert_log, t_rowid, t_failed, t_message) if __debug__: print "Before procedure call" print parameters parameters = mra_data_m4.callAdjustInventoryProcedure(parameters) <--- see function code below if __debug__: print "After procedure call" print parameters # Unpack the returned list (t_empno, t_item_no, t_trans_dt, t_trans_qty, t_trans_um, t_stock_area, t_bin_loc, t_control_no, t_reason_cd, t_reference, t_trans_type, t_ref_order, t_rtv_no, t_insert_log, t_rowid, t_failed, t_message) = parameters --- M5 t_empno = utility.userId t_item_no = dataBucket['K_itemNumber'] t_trans_dt = mra_data_m5.getTodayAsOracleDate() t_trans_qty = dataBucket['K_adjustQuantity'] t_trans_um = dataBucket['K_stockUM'] t_from_area = dataBucket['K_stockArea'] t_from_bin = dataBucket['K_binLoc'] t_to_area = dataBucket['K_destinationStockArea'] t_to_bin = dataBucket['K_destinationBinLoc'] t_control_no = None t_reference = HEADER_TEXT t_batch_no = mra_data_m5.getBatchNumber() t_reason_code = "RC" t_rowid = None t_failed = None t_message = None # Pack the parameters into a tuple parameters = (t_empno, t_item_no, t_trans_dt, t_trans_qty, t_trans_um, t_from_area, t_from_bin, t_to_area, t_to_bin, t_control_no, t_reference, t_batch_no, t_reason_code, t_rowid, t_failed, t_message) if __debug__: print "Before procedure call" print parameters parameters = mra_data_m5.callBinMoveProcedure(parameters) <--- see function code below if __debug__: print "After procedure call" print parameters # Unpack the returned list (t_empno, t_item_no, t_trans_dt, t_trans_qty, t_trans_um, t_from_area, t_from_bin, t_to_area, t_to_bin, t_control_no, t_reference, t_batch_no, t_reason_code, t_rowid, t_failed, t_message) = parameters --- The mra_data_m*.call*Procedure(parameters) functions are very simple, as follows PROC_NAME = "prociapi.icbm_move" c = cn.cursor() spParams = c.callproc(PROC_NAME, *spParams) return spParams All the data access functions share one DCOracle2.connection object, and each function declres its own cursor. M5 fails consistently, i.e. it doesn't matter if M4 is run first or not, M5 fails. ---------------------------------------------------------------------------- Oracle Stored Procedure signatures ---------------------------------------------------------------------------- M4 procedure adjust_inventory(t_empno in varchar2, -- required t_item_no in varchar2, -- required t_trans_dt in date, -- can default to sysdate t_trans_qty in number, -- required t_trans_um in varchar2, -- can default t_stock_area in varchar2, -- can default (ICEM) t_bin_loc in varchar2, -- can default (ICEM) t_control_no in varchar2, -- conditional null t_reason_cd in varchar2, -- required t_reference in varchar2, -- can default t_trans_type in varchar2, -- can default t_ref_order in varchar2, -- can default t_rtv_no in number, -- can be null t_insert_log in varchar2, -- required t_rowid in out varchar2, t_failed in out varchar2, t_message in out varchar2); M5 procedure icbm_move(t_empno in varchar2, -- required t_item_no in varchar2, -- required t_trans_dt in out date, -- can default to sysdate t_trans_qty in number, -- required t_trans_um in out varchar2, -- can default from t_from_area in out varchar2, -- can default from t_from_bin in out varchar2, -- can default from t_to_area in out varchar2, -- can default from t_to_bin in out varchar2, -- can default from t_control_no in out varchar2, -- conditional null t_reference in varchar2, -- can default t_batch_no in number, -- can default t_reason_code in varchar2, -- conditional null t_rowid in out varchar2, t_failed in out varchar2, t_message in out varchar2); ---------------------------------------------------------------------------- Version & config info: ---------------------------------------------------------------------------- HP-UX B 11.00 PL/SQL 8.1.7.4.0 (Production) Oracle8i Enterprise Edition 8.1.7.4.0 (Production) TNS for HPUX: 8.1.7.4.0 (Production) NLSRTL 3.4.1.0.0 (Production) DCOracle2 1.2 -- DCOracle2 1.95 (dco2: 1.120 -DORACLE8i -DUSEOBJECT -D_REENTRANT ) Environment: PATH=$PATH:/usr/local/bin PYTHONPATH=/usr/local/bin/mra LD_PRELOAD=/usr/lib/libcl.2 ORACLE_HOME=/u01/app/oracle/product/8.1.7 ORACLE_SID=blabla DCO2TRACELOG=dco2.tracelog DCO2TRACEDUMP=dco2.tracedump DCO2TRACEFLAGS=255 From stelian.iancu at gmx.net Wed Aug 20 05:54:59 2003 From: stelian.iancu at gmx.net (Stelian Iancu) Date: Wed, 20 Aug 2003 12:54:59 +0300 Subject: PyQT installation problems Message-ID: Hello all! I am trying to install eric3, the Python IDE. I've downloaded and installed successfully sip-3.8, QScintilla-1.2 and PyQT-3.8. However, when I try to install eric, I get the following error: Sorry, please install PyQt. I looked into the install script, then I opened a Python window and there I tried import qt and I got the following error: Traceback (most recent call last): File "", line 1, in ? File "/usr/lib/python2.2/site-packages/qt.py", line 25, in ? import libqtc ImportError: /usr/lib/python2.2/site-packages/libqtcmodule.so: undefined symbol: _ZNK9QSGIStyle9classNameEv I am using Mandrake 9.1 with the default Python (2.2.3) and Qt. -- Stelian Iancu Linux registered user 287835 Be different. Think. From aahz at pythoncraft.com Wed Aug 20 15:26:34 2003 From: aahz at pythoncraft.com (Aahz) Date: 20 Aug 2003 15:26:34 -0400 Subject: What's better about Ruby than Python? References: <9755kv4bku839cpsqrvch13504qagg7gev@4ax.com> <87oeykb22l.fsf@pobox.com> Message-ID: In article <87oeykb22l.fsf at pobox.com>, John J. Lee wrote: > >Rest assured, *definitely* no relation. :-) No relation to what? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Let's see if anyone can identify the source of this joke.... From staschuk at telusplanet.net Fri Aug 29 09:51:09 2003 From: staschuk at telusplanet.net (Steven Taschuk) Date: Fri, 29 Aug 2003 07:51:09 -0600 Subject: another puzzled newbie In-Reply-To: ; from elainejackson7355@home.com on Fri, Aug 29, 2003 at 01:52:55AM +0000 References: <68g3b.855589$ro6.16997110@news2.calgary.shaw.ca> Message-ID: <20030829075109.A550@tibia.amotlpaa.bogus> Quoth Elaine Jackson: > "Chad Netzer" wrote in message > news:mailman.1062051053.30902.python-list at python.org... [...] > | You don't need the '(' and ')' here. del is a keyword, not a function. > > Can't it be both? Could you explain why it fails to be a function? Since 'del' is a keyword, it cannot be used as a variable name: >>> del = 3 File "", line 1 del = 3 ^ SyntaxError: invalid syntax >>> def del(x): return 11*x File "", line 1 def del(x): return 11*x ^ SyntaxError: invalid syntax The token 'del' has special significance in Python syntax; it can only introduce a del statement. It is mostly harmless to put parentheses around what follows 'del', but it can create the misleading impression that you are or think you are calling a function named 'del'. Besides Erik's point that there's no return value, note also that the "argument" to del is not an argument at all -- it's not an expression which is evaluated to provide a value to del. For example, after def foo(x): return 11*x num = 3 the calls foo(num) and foo(3) are equivalent -- the function foo cannot tell the difference. The expression 'num' is evaluated to produce the value 3, and then that value is passed to the function. In contrast, del num del 3 are not equivalent, even when num == 3; the former deletes the name 'num' (regardless of its value), while the latter is syntactically erroneous. What follows 'del' is actually a target (list), just like the left-hand side of an assignment statement, and not an argument (list). [...] > No, I want (-1) the integer. My problem is that I really dislike the > appearance > of a statement like X-=Y. (Even right now I can barely stand writing it.) > So I > wrote X+=(-Y) instead. Maybe it would look better as > shuffler=map(lambda n: n-1, shuffler)? I'd prefer shuffler[:] = [x-1 for x in shuffler] but this is mostly a matter of taste. (Note the use of [:] to modify the existing list in place, as the context requires.) -- Steven Taschuk Aral: "Confusion to the enemy, boy." staschuk at telusplanet.net Mark: "Turn-about is fair play, sir." -- _Mirror Dance_, Lois McMaster Bujold From postmaster at hoovers.com Wed Aug 20 22:17:11 2003 From: postmaster at hoovers.com (System Administrator) Date: Wed, 20 Aug 2003 21:17:11 -0500 Subject: Undeliverable: Re: Details Message-ID: <4810C017B52BD4118EEA00B0D020B0ED118A5B89@gamma.hoovers.com> Your message To: asolis at hoovers.com Subject: Re: Details Sent: Sat, 5 Jan 1980 17:59:59 -0500 did not reach the following recipient(s): ASOLIS at HOOVERS.COM on Wed, 20 Aug 2003 21:17:08 -0500 The recipient name is not recognized The MTS-ID of the original message is: c=us;a= ;p=hoover's, inc.;l=EXCHANGE0308210217RJRSPGJY MSEXCH:IMS:Hoover's, Inc.:HOOVERS:EXCHANGE 0 (000C05A6) Unknown Recipient -------------- next part -------------- An embedded message was scrubbed... From: python-list at python.org Subject: Re: Details Date: Sat, 5 Jan 1980 17:59:59 -0500 Size: 1113 URL: From jilderda at dds.nl Sun Aug 10 06:47:32 2003 From: jilderda at dds.nl (Auke Jilderda) Date: Sun, 10 Aug 2003 12:47:32 +0200 Subject: How to access a PostgreSQL database? Message-ID: <3f3622c4$0$49101$e4fe514c@news.xs4all.nl> Hi, question on accessing databases: I'm trying to build a script [1] to archive messages from a mailinglist into a GForge [2] server's web forums. Effectively, this provides us with a central means of communication that can be accessed via web, mail, and news. GForge uses mailman and postgresql. It seemed a good idea to use the DB-API spec v2.0 with the PyGreSQL library but I can't seem to find any decent documentation or examples and am starting to run out of patience with the 'trial on error' approach. Hopefully somebody can point me in the right direction. :-) A couple of questions: - What is the most elegant way to connect to a database? I had expected by instantiating a db class which has a 'connect' method but can't find it. Currently, this is how I do it (which works): # connect to database connection = pgdb.connect(host = 'localhost', user = 'postgres', \ database = 'alexandria') cursor = connection.cursor() ... # disconnect connection.close() - How on Earth can I insert a tuple into a table with the proper types? I tried 'cursor.execute()' but keep running into typing issues. (At the bottom of this post, I included the table's layout. Any help is appreciated, Auke 1. See attachment, bear in mind there are some ugly shortcuts in there. 2. http://gforge.org The table 'forum' looks as follows (cut & paste from 'psql'): alexandria=# \d forum Table "public.forum" Column | Type | Modifiers ------------------+---------+------------------------------------------------ msg_id | integer | not null default nextval('forum_pk_seq'::text) group_forum_id | integer | not null default '0' posted_by | integer | not null default '0' subject | text | not null default '' body | text | not null default '' date | integer | not null default '0' is_followup_to | integer | not null default '0' thread_id | integer | not null default '0' has_followups | integer | default '0' most_recent_date | integer | not null default '0' Indexes: forum_pkey primary key btree (msg_id), forum_forumid_isfollto_mostrece btree (group_forum_id, is_followup_to, most_recent_date), forum_forumid_msgid btree (group_forum_id, msg_id), forum_forumid_threadid_mostrece btree (group_forum_id, thread_id, most_recent_date), forum_group_forum_id btree (group_forum_id), forum_threadid_isfollowupto btree (thread_id, is_followup_to) Rules: forum_delete_agg, forum_insert_agg Triggers: RI_ConstraintTrigger_18833, RI_ConstraintTrigger_18836, RI_ConstraintTrigger_18842, RI_ConstraintTrigger_18845, RI_ConstraintTrigger_18972, RI_ConstraintTrigger_18975, fmsg_agg_trig alexandria=# -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: aukes-archiver.py URL: From fabsk+news at free.fr Thu Aug 14 10:45:53 2003 From: fabsk+news at free.fr (Fabien SK) Date: Thu, 14 Aug 2003 16:45:53 +0200 Subject: Excel COM Addin In-Reply-To: References: Message-ID: <3f3ba0e8$0$1160$626a54ce@news.free.fr> Eric wrote: > I would like to Write an Excel Addin like the Outlook Addin in the COM > samples but i am stuck since after examining the windows registry, > there is no Excel addin Key. > > The application would utilise interface IDTExtensibility2 to create > buttons and menus on excel which will be hooked up to perform certain > functions. Search Google: [HKEY_CURRENT_USER\Software\Microsoft\Office\Outlook\Addins\SampleAddIn.AddInIFace] "FriendlyName"="Sample Add-in" "Description"="Sample Outlook Add-In" "LoadBehavior"=dword:00000008 If you search Google some keywords above, you will find a MSDN article. From steve9000 at users.sf.net Wed Aug 6 15:12:03 2003 From: steve9000 at users.sf.net (Stephen Kennedy) Date: Wed, 06 Aug 2003 20:12:03 +0100 Subject: Shell pattern to regular expression code Message-ID: Hi all, I was searched on the web for code to handle {} as in *.{foo,bar} (fnmatch does not handle this case) and surprisingly didn't find any. So I wrote some. Here it is: Stephen #! /usr/bin/env python import re def translate(pat): """Translate a shell PATTERN to a regular expression. There is no way to quote meta-characters. """ i, n = 0, len(pat) res = '' while i < n: c = pat[i] i = i+1 if c == '*': res += '.*' elif c == '?': res += '.' elif c == '[': try: j = pat.index(']', i) stuff = pat[i:j] i = j+1 if stuff[0] == '!': stuff = '^%s' % stuff[1:] elif stuff[0] == '^': stuff = r'\^%s' % stuff[1:] res += '[%s]' % stuff except ValueError: res += r'\[' elif c == '{': try: j = pat.index('}', i) stuff = pat[i:j] i = j+1 res += '(%s)' % "|".join([translate(p)[:-1] for p in stuff.split(",")]) except ValueError: res += r'\{' else: res += re.escape(c) return res + "$" lof = open("sourcelist").readlines() pats = ["*.*", "*.[ac]", "*.[ac]*", "*.[!ac]*", "*.[ac]x*", "*.{gif,jpg}", "*.{a*,y*}"] for pat in pats[-1:]: print "***", pat, "***", translate(pat) regex = re.compile( translate(pat) ) print "\n".join( [f.strip() for f in lof if regex.match(f)!=None][:20] ) From geoff at gerrietts.net Fri Aug 22 21:22:48 2003 From: geoff at gerrietts.net (Geoff Gerrietts) Date: Fri, 22 Aug 2003 18:22:48 -0700 Subject: large-scale app development in python? In-Reply-To: <20030822144228.GA8130@core.realtime.sk> References: <20030822144228.GA8130@core.realtime.sk> Message-ID: <20030823012248.GD12504@thoth.homegain.com> Quoting gabor (gabor at z10n.net): > how do you solve these kind of problems? i know that unit tests are a > good thing, but i don't know if they can help in this situation? This is actually a pretty common question. The answer usually seems to run towards "writing lots of unit tests". That may be a switch in engineering process for you. It may increase the time it would take to develop your app, but the claim (anecdotally supported, but I've never seen a real study) is that test-first programming saves time over the life of the project. You can also use tools like pychecker to do some static analysis. > are there any people who wrote a big program in python? how did they > handle these problems? We've written a couple hundred thousand lines of python at my present place of employ. We manage it by testing our components and ensuring they work. We do not do test-first programming (would be nice, but would have a pretty big up-front investment), but we don't generally find that we encounter a lot of problems of the sort that a compiler with strict type checking would catch. I would wager that the strict type checking you would get out of C++ is more than twice offset by the simple memory management you get out of Python, when it comes to final stability. > or python simply isn't suited to write bigger (more complex) apps? As always, optimize key code paths by writing them in a language that talks directly to the hardware. Do the lion's share of the work in Python. Using this recipe, Python is appropriate for a large selection of tasks. --G. -- Geoff Gerrietts -rw-rw-rw-: permissions of the beast From buzzard at urubu.freeserve.co.uk Mon Aug 4 14:38:40 2003 From: buzzard at urubu.freeserve.co.uk (Duncan Smith) Date: Mon, 4 Aug 2003 19:38:40 +0100 Subject: better way to do this in Numeric References: Message-ID: "John Hunter" wrote in message news:mailman.1060008547.3901.python-list at python.org... > > I have a list of indices and want to assign the number of times an > index shows up in the list to an array with the count specified at the > index; ie, > > from Numeric import * > > a = zeros((10,), Int) > ind = [1,1,4,4,4,4,7,7,9,9,9,9,9] > > for i in ind: > a[i] += 1 > > I'm wondering if there is a way to use some combination of Numeric > array functions to make this speedy. > > Thanks, > John Hunter > import Numeric >>> ind = [1,1,4,4,4,4,7,7,9,9,9,9,9] >>> res = Numeric.searchsorted(ind, Numeric.arange(10)) >>> res = Numeric.concatenate([res, [len(ind)]]) >>> res[1:] - res[:-1] array([0, 2, 0, 0, 4, 0, 0, 2, 0, 5]) >>> Duncan From bgailer at alum.rpi.edu Tue Aug 5 08:50:56 2003 From: bgailer at alum.rpi.edu (Bob Gailer) Date: Tue, 05 Aug 2003 06:50:56 -0600 Subject: win32com, excel In-Reply-To: <200308050854.h758s5Q25044@mailgate5.cinetic.de> Message-ID: <5.2.1.1.0.20030805064436.01d4b9b0@66.28.54.253> At 10:54 AM 8/5/2003 +0200, Oliver Emrich wrote: >I want to paste something from the clipboard in excel using python. > >I wrote a script but there occur errors during execution. >The script looks like: > >import win32com.client > >xlApp = win32com.client.dynamic.Dispatch('Excel.Application') >xlBook = xlApp.Workbooks.Open("C:/test.xls") >xlSheet = xlBook.Worksheets("Test") >xlSheet.Range(sht.Cells(1, 1), sht.Cells(1, 1)).Activate() >xlSheet.Paste(1, 1) >xlBook.Save() > > >In VBA you just would write: >ActiveSheet.Paste > >My problem is the Paste() method in Python. I think I need a Range object >but I don't know how to get it. What is your understanding of the Paste arguments? Have you looked them up in Excel VBA help? The equivalent of VBA Paste is Paste(). No arguments. The first [optional] argument to Paste is a range object. Creating range objects is an Excel topic, not Python. Look up range object in Excel VBA help. One way to create a range object in your example is: RangeObject = xlSheet.Range("A5") Then the paste could be coded xlSheet.Paste(RangeObject) Bob Gailer bgailer at alum.rpi.edu 303 442 2625 -------------- next part -------------- --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.506 / Virus Database: 303 - Release Date: 8/1/2003 From danbmil99 at yahoo.com Mon Aug 18 11:02:05 2003 From: danbmil99 at yahoo.com (dan) Date: 18 Aug 2003 08:02:05 -0700 Subject: What's better about Ruby than Python? References: Message-ID: "Brandon J. Van Every" wrote in message news:... > What's better about Ruby than Python? I'm sure there's something. What is > it? > > This is not a troll. I'm language shopping and I want people's answers. I > don't know beans about Ruby or have any preconceived ideas about it. I have > noticed, however, that every programmer I talk to who's aware of Python is > also talking about Ruby. So it seems that Ruby has the potential to compete > with and displace Python. I'm curious on what basis it might do so. Dude, what is it with you? You must post like 50 msgs a day on this ng, and I suspect we're not the only target of your "interest". On another thread you said you haven't actually tried Python because you don't want to spend the time until you understand if it's worth it. That is ridiculous, considering you have spent man-months posting to clp. I was writing code within an hour of downloading. Download Python, download Ruby, check them out for yourselves. Make up your own mind instead of depending on others (with whom you rarely agree anyway). Just a random suggestion. From mwh at python.net Fri Aug 22 14:23:28 2003 From: mwh at python.net (Michael Hudson) Date: Fri, 22 Aug 2003 18:23:28 GMT Subject: Python/C API - PyArg_ParseTuple problem ? References: Message-ID: <7h3fzjt1rlh.fsf@pc150.maths.bris.ac.uk> "Poire Williams" writes: > Hi, everybody. > > I'm writing a Python binding for a C++ library and I just found something > that puzzles me. [snippety] > If I do this: > > >> s = 'hi' > >> t = NewType(0, 42, s) > > everything is well... Even after a 'del s'? > Moreover, if I change my C code to something like > this: > > if (!PyArg_ParseTuple(args, "ii|O", &a, &b, &o) > return NULL; > s = PyString_AsString(o); > > everything's fine again, in both cases... > > I guess it's some kind of twisted reference count thing, and I'm still > trying to get some minimal C code to reproduce this. Meanwhile, does > anybody have a clue ? > > Thanks in advance. > > Precisions: I'm running Python 2.2.3 on Linux, and I don't free() the > buffer retrieved via PyArg_ParseTuple or PyString_AsString :) No, but I bet you're stuffing it into your data structure somewhere along the line. I think you need to copy the string data. Cheers, mwh -- In that case I suggest that to get the correct image you look at the screen from inside the monitor whilst standing on your head. -- James Bonfield, http://www.ioccc.org/2000/rince.hint From newsgroups at jhrothjr.com Mon Aug 18 20:18:09 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Mon, 18 Aug 2003 20:18:09 -0400 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: <3F41208F.40021A68@engcorp.com> Message-ID: "Doug Tolton" wrote in message news:e7l2kv8itrmaair87qto299m6rdl1r1kh3 at 4ax.com... > On Mon, 18 Aug 2003 16:22:01 -0400, "John Roth" > wrote: > > >It might be better to simply take the question at face value, rather than > >slanging Brandon. I don't find the personalities to add anything of value > >to the conversation. > > Clearly you haven't followed c.l.p for long, otherwise you wouldn't > make a statement like this. Brandon is *constantly* trolling this > newsgroup with inflammatory and/or contradictory statements. > Seriously do a search using google groups for Brandon Van Every in > comp.lang.python. Your statement is innappropriate take in full > context. I've been on c.l.py for around two years. Your statement is rude and assumes things you have not bothered to check out. There is a very simple rule for dealing with trolls, which most usenet newbies learn sooner or later. If you think someone is trolling, simply ignore them. Don't answer their posts, don't comment on them, don't even give them the gratification of a reply that says: "plonk!" Just killfile them and quit wasteing bandwidth. You've got better things to do with your time than maintaining an interaction that you find aggrevating. John Roth > > > Doug Tolton > (format t "~a@~a~a.~a" "dtolton" "ya" "hoo" "com") From skip at pobox.com Wed Aug 20 17:26:52 2003 From: skip at pobox.com (Skip Montanaro) Date: Wed, 20 Aug 2003 16:26:52 -0500 Subject: Almost uneventful FAQ Wizard setup - except for Globalname error!! In-Reply-To: References: Message-ID: <16195.59292.360333.452831@montanaro.dyndns.org> >> The FAQ works. I added several categories (actually in the faqconf.py >> file), and added several questions. However, when I edit an answer >> and press the COMIT button, I get the following error: ... >> emit(LOGHEADER, self.ui, os.environ, date=date, _file=tfn) >> NameError: global name 'tfn' is not defined I think that emit() call should be emit(LOGHEADER, self.ui, os.environ, date=date, _file=tf) (no "n"). >> One more question. If I wanted to wipe the FAQ clean, how would I do >> this? I tried on a seperate install (different computer) to delete >> all files in my FAQDIR (including the RCS subdir) but faqwiz somehow >> remembered where it was in the numbering scheme and kept saying "stop >> changing the entry numbers". Good question. Note that on www.python.org we're in the midst of moving away from faqwiz, and are using ht2html and ReST (docutils) to redo the current Python FAQ. This makes it easier to integrate the FAQ with the rest of the site and makes the FAQ sections easier to edit (they are just plain text) and reorganize (any text editor will work). Skip From mack at incise.org Sun Aug 31 16:33:54 2003 From: mack at incise.org (mackstann) Date: Sun, 31 Aug 2003 15:33:54 -0500 Subject: list.sort(func) speed In-Reply-To: <1062360910.1852.44.camel@adsl-209.204.179.133.sonic.net> References: <20030831190745.GH9311@incise.org> <1062360910.1852.44.camel@adsl-209.204.179.133.sonic.net> Message-ID: <20030831203354.GK9311@incise.org> On Sun, Aug 31, 2003 at 01:15:11PM -0700, Chad Netzer wrote: > There is nothing about using a class that will make your program > inherently slow, as long as you use the right algorithms. > > A data set of 20,000 is *small* by todays standards. Sorting it should > be trivial and near instantaneous using decorate-sort-undecorate. Once > it is sorted, you just keep the list sorted by doing insertions in > sorted order (a very fast operation). Is there a reason you need to do > lots of re-sorts? No, but the thought of inserting things in order did not quite occur to me. Can you give me an simple example of exactly how to go about this? (all I can think of is a while loop with cmp() which seems too "manual") > Perhaps you can use a dict to hold your data. You can also extract all > the keys you need to sort on, ahead of time, and keep it paired up with > you data class or dictionary. This will make decorate-sort-undecorate > easy to code, and very quick to execute. And you still have a flexible, > easy to use data type. > > I'd strongly suggest you not avoid dicts or classes, just to try to > speed up your code. Almost all the time, they do not impair > performance. And if you complicate your design by avoiding them, you > are putting yourself through unneeded pain. It's actually the exact opposite; at present I have no need (really!) for metadata on the files, but I may in the future, at which point using a dict or class for each song will probably be the way to go. Although I 'spose I was assuming that using more complex objects for the items in the list would result in a bigger speed hit than they really would. I just like to be cautious about things, you never know when you might want to run your code on a really slow machine, and then, all of a sudden, it's really slow. :) Python people love to preach against premature optimization, which I mostly agree with, but I also think it is good to be conscious of possible speed issues (especially when the size of the data set, and hardware speed are both quite variable, and could both be more demanding than the ones I am testing with). -- m a c k s t a n n mack @ incise.org http://incise.org Money is the root of all evil, and man needs roots. From news at yebu.de Wed Aug 13 08:39:57 2003 From: news at yebu.de (Karl Scalet) Date: Wed, 13 Aug 2003 14:39:57 +0200 Subject: Determine file type (binary or text) In-Reply-To: References: Message-ID: Michael Peuser schrieb: > Hi, > yes there is more than just Unix in the world ;-) > Windows directories have no means to specify their contents type in any way. That's even more true with linux/unix, as there is no need to do any stuff like line-terminator conversion. > The approved method is using three-letter extensions, though this rule is > not strictly followed (lot of files without extension nowadays!) > > When I had a similar problem I read 1000 characters, counted the amount of > <32 and >255 characters and classified it "binary when this qota exceeded > 20%. I have no idea whether it will work good with chinese unicode files or > some funny depositories or project files that store uncompressed texts.... based on the idea from Mr. "bromden", why not use mimetypes.MimeTypes() and guess_type('file://...') and analye the returned string. This should work on windows / linux / unix / whatever. Karl > > KIndly > Michael P > > "Sami Viitanen" schrieb im Newsbeitrag > news:v7p_a.1558$k4.32814 at news2.nokia.com... > >>Works well in Unix but I'm making a script that works on both >>Unix and Windows. >> >>Win doesn't have that 'file -bi' command. >> >>"bromden" wrote in message >>news:bhd559$ku9$1 at absinth.dialog.net.pl... >> >>>>How can I check if a file is binary or text? >>> >>> >>> import os >>> >>> f = os.popen('file -bi test.py', 'r') >>> >>> f.read().startswith('text') >>>1 >>> >>>(btw, f.read() returns 'text/x-java; charset=us-ascii\n') >>> >>>-- >>>bromden[at]gazeta.pl >>> >> >> > > From mack at incise.org Sun Aug 24 23:28:43 2003 From: mack at incise.org (mackstann) Date: Sun, 24 Aug 2003 22:28:43 -0500 Subject: Strange tab problem! In-Reply-To: <1799.68.75.130.96.1061781479.squirrel@webmail.iserv.net> References: <1799.68.75.130.96.1061781479.squirrel@webmail.iserv.net> Message-ID: <20030825032843.GT1695@incise.org> On Sun, Aug 24, 2003 at 11:17:59PM -0400, tjland at iserv.net wrote: > Okay i wrote a small program that allows users to creat book listings > featuring copyright date author and title. Now when i display the book > listings i get this. > > Book: testover6 Author: ??? Copyright: 2003 > Book: testu6 Author: ??? Copyright: 2003 > > Okay now after the book title their is supposed to a tab the coding goes > like this. > > for x in title_author.keys(): > print "Book: ",x," \tAuthor: ",title_author[x]," > \tCopyright:",title_copyright[x] > > it seems that whenever i go over six characters it adds another tab. Is > there a preset field limit to six bytes. What is happening? Thanx in > advance. The way that tabs are displayed are really dependent on the software displaying them, if you want to have strict column-like layout, you could calculate the longest item in a given column, and then use item.ljust(length_of_longest_item_in_column). -- m a c k s t a n n mack @ incise.org http://incise.org Real Programs don't use shared text. Otherwise, how can they use functions for scratch space after they are finished calling them? From oussoren at cistron.nl Tue Aug 12 11:01:51 2003 From: oussoren at cistron.nl (Ronald Oussoren) Date: Tue, 12 Aug 2003 17:01:51 +0200 Subject: dist problem on osx In-Reply-To: <3F3786FC.5020703@lemburg.com> References: <644f6688.0308101518.ad9e02a@posting.google.com> <3F3786FC.5020703@lemburg.com> Message-ID: On Monday, 11 August, 2003, at 14:07, M.-A. Lemburg wrote: > rdack wrote: >> osx 10.2.6 python 2.2.1 (built in) >> says my architecture is both 386 and ppc. >> also has a path with a space in it that won't work. >> where can i change these settings? >> -------- >> gcc -arch i386 -arch ppc -bundle -flat_namespace -undefined suppress >> build/temp.darwin-6.6-Power >> Macintosh-2.2/mx/DateTime/mxDateTime/mxDateTime/mxDateTime.o >> -L/usr/local/lib -L/usr/lib -o build/lib.darwin-6.6-Power >> Macintosh-2.2/mx/DateTime/mxDateTime/mxDateTime.so >> --------------- > > This is a bug in distutils. It's fixed in Python 2.2.3. The two architectures are not a bug in distutils, but a bug in the way Apple build python. The '-arch i386' is annoying but harmless, if it really annoys you you can change /usr/lib/python2.2/config/Makefile. Search for '-arch i386' and remove this. Ronald From jjl at pobox.com Sat Aug 9 10:25:07 2003 From: jjl at pobox.com (John J. Lee) Date: 09 Aug 2003 15:25:07 +0100 Subject: FTP with urllib2 behind a proxy References: <7d6b0b33.0308070304.53588bf0@posting.google.com> Message-ID: <87d6feykl8.fsf@pobox.com> Zappelphillip at gmx.de (O. Koch) writes: > Until now, i know that ftplib doesn't support proxies and that i have > to use urllib2. But i don't know how to use the urllib2 correct. I > found some examples, but i don't understand them. > > Is there anyone who can help me? import urllib2 response = urllib2.urlopen("ftp://ftp.example.com/pub/myfile") data = response.read() response.close() Does that do the trick? John From gregm at iname.com Wed Aug 27 09:03:07 2003 From: gregm at iname.com (Greg McFarlane) Date: 27 Aug 2003 06:03:07 -0700 Subject: event binding and component.config References: Message-ID: If you want something that allows a user to select a particular mode and then to display that mode until it is changed - use Pmw.RadioButton instead of trying to hack Pmw.ButtonBox. I think this will do exactly what you want. Greg Scott Holmes wrote in message news:... > I'm experiencing what seems to be strange behaviour. I don't know if > it's Pmw, Tkinter on Python. I have a button, defined in a > Pmw.buttonbox, that I would like to configure to "sunken" after it has > been clicked/released. Using the example style coding: > > self.buttonBox1.add('Add', command = self.addCalendar) > > the button remains "sunken". If I bind the event: > > self.buttonBox1.add('Add') > self.buttonBox1.component('Add').bind('', > self.addCalendarBind) > self.buttonBox1.component('Add').bind('', > self.addCalendarBind) > > the button reverts to "raised". The addCalendar and addCalendarBind are > still essentially stub functions: > > def addCalendarBind(self,event): > self.addCalendar() > > def addCalendar(self): > global prog_mode > self.clearCalendar() > prog_mode = 'add' > self.buttonBox1.component('Add').config(relief='sunken') > self.buttonBox1.component('Commit').config(relief='raised') > self.buttonBox1.component('Update').config(relief='flat') > self.buttonBox1.component('Delete').config(relief='flat') > self.buttonBox1.component('Query').config(relief='flat') > > -- > --------------------------------------------------------------------- > Scott Holmes http://sholmes.ws > http://pages.sbcglobal.net/scottholmes > scottholmes at sbcglobal.net > > Independent Programmer/Analyst Passport 4GL > PHP HTML Composer PostgreSQL Informix 4GL, SQL > --------------------------------------------------------------------- > There are more things in heaven and earth, Horatio, > than are dreamt of in your philosophy > --------------------------------------------------------------------- From newsgroups at jhrothjr.com Wed Aug 27 10:38:29 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Wed, 27 Aug 2003 10:38:29 -0400 Subject: Proposal: Magic Constants References: Message-ID: Interesting thoughts. See my comments interspersed. John Roth "Chris Gonnerman" wrote in message news:mailman.1061989198.28274.python-list at python.org... > A while back (a long while actually) I was a > participant in a long argument over decimal and > rational numbers, and their inclusion into the > core of Python. > > Last night in a dream I came up with an > interesting solution (no, really!) which, in the > cold light of morning, still seems pretty cool. Unusual, but what the heck, it does happen. > The gist is this: Constants would be allowed to > be trailed by any single alphabetic character. > When compiled, a constant with a nonstandard > letter code would be stored in the compiled code > in the form of a text literal, appropriately > marked. > > When the code is executed, and the special > literal is processed, the interpreter would look > up a conversion function in an internal list. If > no conversion is found, a runtime error would be > raised. I'd prefer to start by handing it off to the object that is most likely to want to process it first. Although I'm not sure about how to identify that object reliably. > Modules to handle alternate numeric formats, such > as decimal, fixed-point, rational, etc. would > include a call to a builtin registration function > which would allow them to "take over" a specific > alphabetic specifier. There's another namespace with a possibility of collisions here, and also the same old "we can't make one of these a builtin because it might break user code." I'd suggest doing something up front, like reserving lower case letters for Python core enhancements, and upper case letters for application useage. > So, to use a supposed Decimal.py module, one > would do thusly: > > "decimal arithmetic example" > > import Decimal > > a = 1.05D > > and so on. > > Limitations: The literal would be required by > the compiler to match the format of a real number > (float or integer); the conversion function could > raise its own runtime error if the text string > were out of its range. So, to write a rational > number: > > "rational arithmetic example" > > import Rational > > b = 1R/15 > > Note that the 1R is actually the rational 1/1, > whereas the 15 is an integer; the division sign > is not part of the rational here, but actually > indicates division. The result would be the > rational 1/15, which is assigned to the variable > b. Rational isn't actually a problem, as long as we ignore the silly idea that integer division should yield a float. Either that, or provide a rational divide operator that always returns a rational if both operands are integers, rationals or decimals. > The only other disadvantage I can see is that a > small class of syntax errors become runtime > errors. I'm don't think this is a major thing > though. That's always something that some people are going to be on one side of, some on the other. > Thoughts and opinions welcome... One overall thought: why limit it to numbers? The new datetime module would benefit from a datetime literal, but that would have to be a character string. One point you need to emphasize in the PEP (I presume you're going to write a PEP) is that this isn't an optimization. for example, decimal(10.687) won't work correctly. You loose precision because 10.687 is a float. Another thing to think about is whether this could cause problems with existing code. I can't immediately think of a case where a literal can be next to a character, but I'm also not a real deep authority on all of the oddities of Python syntax. John Roth > Chris Gonnerman -- chris.gonnerman at newcenturycomputers.net > http://newcenturycomputers.net > > From jarausch at skynet.be Mon Aug 11 05:03:55 2003 From: jarausch at skynet.be (Helmut Jarausch) Date: Mon, 11 Aug 2003 11:03:55 +0200 Subject: matching a sentence, greedy up! In-Reply-To: References: Message-ID: <3F375BFB.7020601@skynet.be> Christian Buck wrote: > Hi, > > i'm writing a regexp that matches complete sentences in a german text, > and correctly ignores abbrevations. Here is a very simplified version of > it, as soon as it works i could post the complete regexp if anyone is > interested (acually 11 kb): > > [A-Z](?:[^\.\?\!]+|[^a-zA-Z0-9\-_](?:[a-zA-Z0-9\-_]\.|\d+\.|a\.[\s\-]?A > \.)){3,}[\.\?\!]+(?!\s[a-z]) > > As you see i use [] for charsets because i don't want to depend on > locales an speed does'nt matter. (i removed german chars in the above > example) I do also allow - and _ within a sentence. > > Ok, this is what i think i should do: > [A-Z] - start with an uppercase char. > (?: - don't make a group > [^\.\?\!]+ - eat everything that does not look like an end > | - OR > [^a-zA-Z0-9\-_] - accept a non character > (?: - followed by ... > [a-zA-Z0-9\-_]\. - a char and a dot like 'i.', '1.' (doesnt work!!!) > | - OR > \d*\. - a number and a dot > | - OR > z\.[\s\-]?B\. - some common abbrevations (one one here) > )){3,} - some times, at least 3 > [\.\?\!]+ - this is the end, and should also match '...' > (?!\s[a-z]) - not followed by lowercase chars > > here i a sample script: > > - snip - > import string, re, pre > s = 'My text may i. E. look like this: This is the end.' > re_satz = re.compile(r'[A-Z](?:[^\.\?\!]+|' > r'[^a-zA-Z0-9\-_](?:[a-zA-Z0-9\-_]\.|' > r'\d+\.|a\.[\s\-]?A\.)){3,}[\.\?\!]+(' > r'?:(?!\s[a-z]))') > mo = re_satz.search(s) > if mo: > print "found:" > sentences = re_satz.findall(s) > for s in sentences: > print "Sentence: ", s > else: > print "not found :-(" > > - snip - > > Output: > found! > Sentence: My text may i. > Sentence: This is the end. > > Why isnt the above regexp greedier and matches the whole sentence? > First, you don't need to escape any characters within a character group []. The very first part r'[A-Z](?:[^\.\?\!]+ cannot be greedier since you exclude the '.' . So it matches upto but not including the first dot. Now, as far as I can see, nothing else fits. So the output is just what I expected. How do you think you can differentiate between the end of a sentence and (the first part of) an abbreviation? -- Helmut Jarausch Lehrstuhl fuer Numerische Mathematik RWTH - Aachen University D 52056 Aachen, Germany From ejeanlouis2001 at yahoo.com Tue Aug 12 08:54:37 2003 From: ejeanlouis2001 at yahoo.com (Emmanuel Jean-Louis) Date: Tue, 12 Aug 2003 05:54:37 -0700 (PDT) Subject: drop down feature Message-ID: <20030812125437.4240.qmail@web13004.mail.yahoo.com> Does python 2.2 has a drop down feature like VB does so that you can list of methods and variables associate with that particular class? If it does, how do I turn it on? Thx. --------------------------------- Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software -------------- next part -------------- An HTML attachment was scrubbed... URL: From Simon.Wittber at perth.maptek.com.au Mon Aug 11 02:01:22 2003 From: Simon.Wittber at perth.maptek.com.au (Simon Wittber (Maptek)) Date: Mon, 11 Aug 2003 14:01:22 +0800 Subject: Python vs. C# Message-ID: <20E0F651F8B82F45ABCBACC58A2D995B032BA7@mexper1> >-----Original Message----- >From: Brandon J. Van Every [mailto:vanevery at 3DProgrammer.com] >Subject: RE: Python vs. C# >Your e-mails are *not* welcome. If you send me e-mail again, I will be >>contacting your ISP about account abuse. >Cheers, www.3DProgrammer.com >Brandon Van Every Seattle, WA You are going to contact my ISP about what exactly? Account abuse? How exactly am I abusing my account? By expressing my opinion that you are a troll? If you do not like being thought of as a troll, I suggest you stop making what appear to be deliberately inflammatory comments cunningly hidden among rather innocuous questions. I am certain, of course, that this advice falls on deaf ears. You have a history of trolling. In fact, you are quite good at it! (154 posts on this one) I will list two more troll posts. Finding more is an interesting exercise for the bored reader. Others, too, have thought your posts are deliberately provoking. You often aggravate others, seemingly intentionally. Once, it even escalated to the point of threats of physical violence. So please refrain from posting your troll-comments to the list, and stop polluting it with your contentious remarks. Cheers, Simon. PS. Pythonistas: please don't feed this troll. From fredrik at pythonware.com Tue Aug 19 11:48:23 2003 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 19 Aug 2003 17:48:23 +0200 Subject: codec to parse raw UCS data? References: Message-ID: Oleg Leschov wrote: > Where can I find a list and documentation for codecs? > What I want to do is to make a unicode string out of unicode data. > for example. I am parsing NTFS metadata, that contains filenames as > UCS-2 code, so I have a binary string that pretends to be a UCS-2. the "utf-16-le" codec is probably what you want. (utf-16 is basically ucs-2 plus mechanisms to encode characters outside the 16-bit BMP set; IIRC, Windows 2k and later uses utf-16, not ucs-2). From davesum99 at yahoo.com Fri Aug 8 19:10:11 2003 From: davesum99 at yahoo.com (smarter_than_you) Date: 8 Aug 2003 16:10:11 -0700 Subject: Accessing c objects in python References: Message-ID: what about ctypes ? magik1300 at aol.com (Gary) wrote in message news:... > Hi- > > I've been searching the web for a while and I've been unable to find a > way to access c data objects in python without using SWIG. I can do > methods just fine but I can't access variables. It seems like > PyModule_AddObject should work but it segfaults my program. There's a > good chance I'm just using it wrong, or I should be using something > else. Could someone give me a simple, complete example pretty please? > Thanks! > > Gary From mis6 at pitt.edu Sat Aug 16 08:30:25 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 16 Aug 2003 05:30:25 -0700 Subject: Summer reading list References: <2259b0e2.0308130804.492aa1ac@posting.google.com> <87ekzmsi5c.fsf@pobox.com> Message-ID: <2259b0e2.0308160430.47b01040@posting.google.com> jjl at pobox.com (John J. Lee) wrote in message news:<87ekzmsi5c.fsf at pobox.com>... > mis6 at pitt.edu (Michele Simionato) writes: > > To reuse classes is good, but typically only works when you know > > about the class you want to inherit *before* you start coding your > > own class; on the other hand, it is quite easy to add functions > > or methods to your class even *after* you wrote it. > [...] > > But I don't think that makes any sense. As I'm certain you know, > there would be nothing to stop you using a class in exactly the same > way you used the function, because reuse != inheritance. Functions > can be implemented in terms of classes, and classes can be implemented > in terms of functions. Let me see if I understand what you mean. You are saying "I could invoke an instance method just as I invoke a function, without using inheritance, and reuse the method in another class". True, but this is clumsy: the point of using a class is making use of inheritance for code reuse, otherwise I could just use a function, isn't it? Besides, typically an instance method is doing something to the 'self' argument and may have unwanted side effects on the object; a function is safer in this respect. In my experience, it takes a certain effort to code a reusable class; it takes a much lesser effort to code a reusable function. > The only reason it's good that Python library uses functions sometimes > instead of classes is as you say: KISS. If it only needs a function, > use a function. > > John Yep. Michele From adalke at mindspring.com Sat Aug 9 14:59:18 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Sat, 9 Aug 2003 12:59:18 -0600 Subject: How to print floating point in scientific format? References: <420ced91.0308081115.7060e551@posting.google.com> <420ced91.0308090642.176b856b@posting.google.com> Message-ID: sdhyok: > As you may notice, my primary usage of python is for scientific > programming. > For the purpose, it is critical for users to flexibly modify the > printing format > of floating points depending on their ranges and precisions. Python gives complete control over you can represent numbers. It just doesn't change the default representation. Users *can* flexibly modify the printing format. I can't see why you would want to change it globally. That just sounds wrong. Eg, I want my app to print the resolution in Angstroms in the form "%3.2f" while I want the mass values in "%3.1f". A global setting is a very clumsy way to change that. > This limitation can be a serious handicap in the application of python > for scientific programming. > I like to listen to all of you who are interested in this issue. I do scientific programming. The lack of specialized formatting hasn't bothered me at all. Andrew dalke at dalkescientific.com From vanevery at 3DProgrammer.com Mon Aug 18 17:59:05 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Mon, 18 Aug 2003 14:59:05 -0700 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: Message-ID: Michael Sparks wrote: > On Mon, 18 Aug 2003, Brandon J. Van Every wrote: >> What's ***TOTALLY COMPELLING*** about Ruby over Python? > > You can create lasers using rubies I believe whereas pythons are > simply cute. Cute. > Michael. > (Since this is clearly a troll :) I'm tired of repeating the sincerity of my questions to people who can't imagine what a valid question might look like. Anyone who thinks the question is "so clearly" a troll, doesn't have the analytical imagination to be useful to me on Python subjects in general. So, welcome to my killfile. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From richie at entrian.com Fri Aug 1 08:20:07 2003 From: richie at entrian.com (Richie Hindle) Date: Fri, 01 Aug 2003 13:20:07 +0100 Subject: Python speed vs csharp In-Reply-To: <49akiv8efalkgsbrevn83quncv04u81vva@4ax.com> References: <49akiv8efalkgsbrevn83quncv04u81vva@4ax.com> Message-ID: > [OT: I hope Pyrex isn't suffering as a result of people writing little > test scripts full of module-level code and being disappointed at the > results.] s/Pyrex/Psyco/g -- Richie Hindle richie at entrian.com From donot at likespam.com Wed Aug 27 12:23:43 2003 From: donot at likespam.com (Rich) Date: Wed, 27 Aug 2003 09:23:43 -0700 Subject: newbie Message-ID: I have just downloaded the software from the "Python" site, so I can learn how to program,or at least start to learn. What should be my next move? should I wade through the site, or are there some exercise I might get into? TIA Rich From vze4rx4y at verizon.net Sat Aug 9 21:48:07 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Sun, 10 Aug 2003 01:48:07 GMT Subject: obj.__dict__ expected behavior or bug? References: Message-ID: "Ed Young > Here is an example of the behavior: > ------- code start ----------------------------------- > #!/usr/bin/python > #bugtest - test of class attribute initiation > > > class Config: > a = 1 > b = 2 > c = 3 > d = None > e = None > h = {'d' : 22, 'e' : 33} > > def __init__(self, factor): > for attr in self.h.keys(): > self.__dict__[attr] = self.h[attr] * factor > > def moda(self): > self.a *= 5 > > > c = Config(2) > print c.a, c.b, c.c, c.d, c.e > for attr in c.__dict__: > print 'c.%s = %s' % (attr, c.__dict__[attr]) > print > > c.moda() > print c.a, c.b, c.c, c.d, c.e > for attr in c.__dict__: > print 'c.%s = %s' % (attr, c.__dict__[attr]) > print > ------- code ends ----------------------------------- > ------- output starts ------------------------------- > $ bugtest > 1 2 3 44 66 > c.e = 66 > c.d = 44 > > 5 2 3 44 66 > c.a = 5 > c.e = 66 > c.d = 44 > ------- output ends --------------------------------- > What happened to c.a, c.b, and c.c when iterating thru > c.__dict__ ? They are up in C.__dict__ > This precludes using __dict__ as the dictionary in > a formatted print statement. e.g. > > print "c.a=%(a)s, c.b=%(b)s, c.c=%(c)s" % c.__dict__ Not really. Use a wrapper to forward dict lookup requests to getattr() which knows how/where to search for attributes: class AttrDict: def __init__(self, obj): self.obj = obj def __getitem__(self, key): return getattr(self.obj, key) print "c.a=%(a)s, c.b=%(b)s, c.c=%(c)s" % AttrDict(c) > Is this a bug or expected behavior? Expected. Raymond Hettinger From maxm at mxm.dk Mon Aug 11 03:14:41 2003 From: maxm at mxm.dk (Max M) Date: Mon, 11 Aug 2003 09:14:41 +0200 Subject: Python vs. C# In-Reply-To: References: Message-ID: <3f3741cc$0$97271$edfadb0f@dread12.news.tele.dk> Simon Wittber (Maptek) wrote: > Apologies for the mangled URLs! It is not you who should be apologising ;-) regards Max M From lamar_air at hotmail.com Wed Aug 13 10:12:22 2003 From: lamar_air at hotmail.com (lamar_air) Date: 13 Aug 2003 07:12:22 -0700 Subject: Making changes to a python cgi to be put on a network Message-ID: <2c6431ab.0308130612.7dad046a@posting.google.com> I have a python cgi that i wrote. The way it works is a user fills out necessary information on a web form, click submit and the python script is executed. The script retrieves variables from the form and writes them to a txt file. The script then calls a executable which uses this txt file as a set of input parameters. I'm using this to call the executable os.system("webtablx4002") and then i just added webtablx4002 at c:\folder1\folder2 to the environment variables paths. I need this executable to be able to run from whatever directory the form is located in. So if whoever puts this program on the server it will all be in one directory and it would be nice not to have to change the code to be specific to that directory. Is there code to get a directoy path for the script or for the form, where it is located when it is run? From heikowu at ceosg.de Wed Aug 13 06:36:09 2003 From: heikowu at ceosg.de (Heiko Wundram) Date: 13 Aug 2003 12:36:09 +0200 Subject: Python IDE - "Lite" version available for non commercial use In-Reply-To: <3F395CC7.EFBE63C6@pobox.com> References: <3F395CC7.EFBE63C6@pobox.com> Message-ID: <1060770969.822.74.camel@d168.stw.stud.uni-saarland.de> On Tue, 2003-08-12 at 23:31, Rick Thomas wrote: > http://wingide.com/wingide The only thing I found so far to get Wing IDE-Lite working was to order a license file from the people who produce it... This certainly doesn't mean that it's available for non-commercial use, I guess. Anybody else checked this out and cares to enlighten me? Heiko. From aleax at aleax.it Mon Aug 11 10:03:44 2003 From: aleax at aleax.it (Alex Martelli) Date: Mon, 11 Aug 2003 14:03:44 GMT Subject: CLI+GUI References: <2259b0e2.0308080948.5a95e383@posting.google.com> <2259b0e2.0308090530.7519f195@posting.google.com> <2259b0e2.0308110517.7c4fa8c8@posting.google.com> Message-ID: <4nNZa.70806$cl3.2173233@news2.tin.it> Michele Simionato wrote: > Eric Brunel wrote in message > news:... >> I don't know if this is the problem, because you didn't say exactly when >> the script hangs, but Tkinter apparently has problems when calls to it >> are made from a thread different from the one into which it was >> initialized. I'd use an Event between Tkinter's thread and Cmd's thread, >> checking it regularly with Tkinter's after method. >> >> HTH > > It hangs immediately when I start the script by clicking on its icon. > What do you mean with "I'd use an Event" ? I thought an Event object > is automatically generated when I click on a widget, or press a key, > or something. Are you saying can I can programmatically generate an > Event, faking a real mouse/key press? How so? That is something I > always wanted to know ;) When talking of event objects in a context of synchronizing threads, it seems likely one is talking about threading.Event in specific. As the online docs for the threading module say: Event() A factory function that returns a new event object. An event manages a flag that can be set to true with the set() method and reset to false with the clear() method. The wait() method blocks until the flag is true. all details are at: http://www.python.org/doc/current/lib/event-objects.html There is no implication whatsoever that such objects are "automatically generated" by any GUI toolkit. The terminology confusions are, alas, almost inevitable. Alex From krzysztof at py142.wroclaw.sdi.tpnet.pl Tue Aug 26 11:00:19 2003 From: krzysztof at py142.wroclaw.sdi.tpnet.pl (Krzysztof Kaczkowski) Date: Tue, 26 Aug 2003 17:00:19 +0200 Subject: wxTreeCtrl event bug only win32? Message-ID: Hello Im having problem, wxTreeCtrl generate 3 x EVT_TREE_SEL_CHANGED on click item right button mouse. This problem only win32. Why? Simple example: from wxPython.wx import * class MyApp(wxApp): def OnInit(self): frame = wxFrame(NULL, -1, "wxPython", wxDefaultPosition,wxSize(200,150)) frame.Show(true) self.nr = 0 self.SetTopWindow(frame) self.ID_TREE = wxNewId() self.tree = wxTreeCtrl(frame, self.ID_TREE) root = self.tree.AddRoot('root test event') itm = self.tree.AppendItem(root, 'Right click first item') itm = self.tree.AppendItem(root, 'Right click next item') EVT_TREE_SEL_CHANGED (self, self.ID_TREE, self.ItemChanged) return True def ItemChanged(self, event): self.nr += 1 print self.nr app = MyApp(0) app.MainLoop() From cnetzer at sonic.net Sat Aug 30 19:03:42 2003 From: cnetzer at sonic.net (Chad Netzer) Date: Sat, 30 Aug 2003 16:03:42 -0700 Subject: OT: Americans love their guns In-Reply-To: References: <5627c6fa.0308281905.152eb4e4@posting.google.com> Message-ID: <1062284621.1875.39.camel@adsl-209.204.179.133.sonic.net> On Sat, 2003-08-30 at 14:51, Tom Plunket wrote: > It seems just mean to me to take a guy with Alzhimer's and rake > him over the coals to me, but maybe it was shot before the > announcement that he had it... It was. Well before. -- Chad Netzer From Rick.Thomas at pobox.com Thu Aug 28 00:58:36 2003 From: Rick.Thomas at pobox.com (Rick Thomas) Date: Thu, 28 Aug 2003 04:58:36 GMT Subject: Py2.3: Feedback on Sets In-Reply-To: <7h3d6f3143s.fsf@pc150.maths.bris.ac.uk> References: <%BX%a.4999$N37.3051@nwrdny02.gnilink.net> <7h3d6f3143s.fsf@pc150.maths.bris.ac.uk> Message-ID: <3F4D8BF7.90401@pobox.com> list * int is by analogy with vector space operations. Vector1 * Scalar -> Vector2 Rick Michael Hudson wrote: > list * int, OTOH, seems a bit smelly to me > (though I'm not sure what a better spelling would be...). From evan at 4-am.com Wed Aug 27 12:44:22 2003 From: evan at 4-am.com (Evan Simpson) Date: Wed, 27 Aug 2003 11:44:22 -0500 Subject: Aspect oriented Everything? In-Reply-To: <8ef9bea6.0308270810.7adfe408__22550.6619121463$1062001049@posting.google.com> References: <32cc321c.0308221316.2f5793ac@posting.google.com> <6ee58e07.0308230459.24f53b64@posting.google.com> <8ef9bea6.0308261857.1b44a5b7@posting.google.com> <8ef9bea6.0308270810.7adfe408__22550.6619121463$1062001049@posting.google.com> Message-ID: <3F4CDFE6.9040903@4-am.com> Based on your explanation, it seems to me that one way to view AOP is as a way of defining "method templates" that can be applied from "outside" of the code that defines the methods via pattern-matching on classes. There have been quite a few times when I've found myself wanting to be able to abstract a pattern across function or method definitions, but where the shared operations involve so much local state that refactoring into explicit subfunctions is too awkward. Usually I end up with cut-and-paste code or a bulky class-based solution. Cheers, Evan @ 4-am From aahz at pythoncraft.com Mon Aug 18 04:31:03 2003 From: aahz at pythoncraft.com (Aahz) Date: 18 Aug 2003 04:31:03 -0400 Subject: python threads on multi-CPU machines References: Message-ID: In article , Thomas Womack wrote: > >If I have a dual-processor hyperthreaded machine (so with four CPU >contexts), will a python program distribute threads over all four >logical processors? Maybe. Python has a Global Interpreter Lock (GIL), so only one thread can run Python code at any time. However, C extensions can release the GIL, and almost all I/O code in Python does that, so I/O-heavy programs will make good use of the SMP. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From robin.cull at pace.co.uk Fri Aug 8 05:10:03 2003 From: robin.cull at pace.co.uk (Robin Cull) Date: 8 Aug 2003 02:10:03 -0700 Subject: filter()ing a dict References: <16469f07.0308070559.aed41a@posting.google.com> Message-ID: <16469f07.0308080110.6a9ef7a0@posting.google.com> robin.cull at pace.co.uk (Robin Cull) wrote in message news:<16469f07.0308070559.aed41a at posting.google.com>... > > I can write something to get around the behaviour in this particular > case (although suggestions would be welcome). > Thanks all for your explanations and examples. I quite like the list comprehension methods. I didn't comprehend (pun intended) what list comprehensions were until I saw these examples so I've learnt something new! :) For my particular script, which is likely to be used by pythonistas even less experienced than me, I decided to solve the problem this way: def filterDict(testFunction, dictToFilter): newDict = {} for k, v in dictToFilter.items(): if testFunction(v): newDict[k] = v return newDict Seems to work for what I want it to do and since it's a standalone defined function which mimics filter() should be nice and easy to understand for people who have to look at it later. I appreciate all your replies. Regards, Robin From heikowu at ceosg.de Tue Aug 19 15:43:01 2003 From: heikowu at ceosg.de (Heiko Wundram) Date: Tue, 19 Aug 2003 21:43:01 +0200 Subject: What's better about Ruby than Python? In-Reply-To: References: Message-ID: <1061322181.14444.10.camel@d168.stw.stud.uni-saarland.de> On Tue, 2003-08-19 at 11:50, Alex Martelli wrote: > X.test is not a function -- it's an unbound method; to call it, you > MUST therefore pass it at least one argument, and the first argument > you pass to it must be an isntance of X (or of any subclass of X). > Too true, I think I thought of classmethods/staticmethods when I posted that... Guess that makes much more sense... It was early in the morning, forgive me... ;) And for the rest, I don't find it bad to specify self as a first parameter, anyway, as I can then always grab it using *args. But, okay, I'll refrain from posting any code tonight, guess I'll get it all wrong again. ;) Heiko. From zsh-workers-help at sunsite.dk Sat Aug 30 02:59:32 2003 From: zsh-workers-help at sunsite.dk (zsh-workers-help at sunsite.dk) Date: 30 Aug 2003 06:59:32 -0000 Subject: confirm subscribe to zsh-workers@sunsite.dk Message-ID: <1062226772.22683.ezmlm@sunsite.dk> Hi! This is the ezmlm program. I'm managing the zsh-workers at sunsite.dk mailing list. To confirm that you would like python-list at python.org added to the zsh-workers mailing list, please send an empty reply to this address: zsh-workers-sc.1062226772.lgnbneeehnfdgifghian-python-list=python.org at sunsite.dk Usually, this happens when you just hit the "reply" button. If this does not work, simply copy the address and paste it into the "To:" field of a new message. This confirmation serves two purposes. First, it verifies that I am able to get mail through to you. Second, it protects you in case someone forges a subscription request in your name. --- Administrative commands for the zsh-workers list --- I can handle administrative requests automatically. Please DO NOT SEND THEM TO THE LIST ADDRESS! If you do, I will not see them and other subscribers will be annoyed. Instead, send your message to the correct command address: To subscribe to the list, send a message to: To remove your address from the list, send a message to: Send mail to the following for info and FAQ for this list: Similar addresses exist for the digest list: To get messages 123 through 145 (a maximum of 100 per request), mail: To get an index with subject and author for messages 123-456 , mail: They are always returned as sets of 100, max 2000 per request, so you'll actually get 100-499. To receive all messages with the same subject as message 12345, send an empty message to: The messages do not really need to be empty, but I will ignore their content. Only the ADDRESS you send to is important. You can start a subscription for an alternate address, for example "john at host.domain", just add a hyphen and your address (with '=' instead of '@') after the command word: To stop subscription for this address, mail: In both cases, I'll send a confirmation message to that address. When you receive it, simply reply to it to complete your subscription. If despite following these instructions, you do not get the desired results, please contact my owner at zsh-workers-owner at sunsite.dk. Please be patient, my owner is a lot slower than I am ;-) --- Enclosed is a copy of the request I received. Return-Path: Received: (qmail 22676 invoked from network); 30 Aug 2003 06:59:32 -0000 Received: from localhost (HELO sunsite.dk) (127.0.0.1) by localhost with SMTP; 30 Aug 2003 06:59:32 -0000 X-MessageWall-Score: 0 (sunsite.dk) Received: from [128.187.34.45] by sunsite.dk (MessageWall 1.0.8) with SMTP; 30 Aug 2003 6:59:31 -0000 From: To: Subject: Thank you! Date: Sat, 30 Aug 2003 0:59:29 --0600 X-MailScanner: Found to be clean Importance: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MSMail-Priority: Normal X-Priority: 3 (Normal) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="_NextPart_000_02913DA9" --_NextPart_000_02913DA9 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Please see the attached file for details. --_NextPart_000_02913DA9-- From krummbeersupp at web.de Tue Aug 5 04:54:06 2003 From: krummbeersupp at web.de (Oliver Emrich) Date: Tue, 5 Aug 2003 10:54:06 +0200 Subject: win32com, excel Message-ID: <200308050854.h758s5Q25044@mailgate5.cinetic.de> Hi all, I want to paste something from the clipboard in excel using python. I wrote a script but there occur errors during execution. The script looks like: import win32com.client xlApp = win32com.client.dynamic.Dispatch('Excel.Application') xlBook = xlApp.Workbooks.Open("C:/test.xls") xlSheet = xlBook.Worksheets("Test") xlSheet.Range(sht.Cells(1, 1), sht.Cells(1, 1)).Activate() xlSheet.Paste(1, 1) xlBook.Save() In VBA you just would write: ActiveSheet.Paste My problem is the Paste() method in Python. I think I need a Range object but I don't know how to get it. Thanks in advance Oliver ______________________________________________________________________________ Spam-Filter fuer alle - bester Spam-Schutz laut ComputerBild 15-03 WEB.DE FreeMail - Deutschlands beste E-Mail - http://s.web.de/?mc=021120 From aleax at aleax.it Thu Aug 21 01:47:13 2003 From: aleax at aleax.it (Alex Martelli) Date: Thu, 21 Aug 2003 05:47:13 GMT Subject: What's better about Ruby than Python? References: <3F41505F.69D18CC8@alcyone.com> <66d7kvonvb2n0nqbqahhd5roak7ur81sob@4ax.com> <3f43ef5d_4@127.0.0.1> <3F440A35.9030602@nyc.rr.com> Message-ID: Kenny Tilton wrote: ... > thread: Python is not trying to be everything. Fair enough. Let Python > be Python, let Lisp be Lisp. > > ie, If someone wants macros, they probably would also like special > variables and closures and lexical scope and multi-methods and they may > as well get it over with and learn Lisp and stop trying make Python more > than it wants to be. Hear, hear! Or one you just can't stand the nested-parentheses idea, then that's what Dylan was designed for: much the same semantics and power as Lisp, including all of the features you mention!, but with infix syntax. Alex From mpeuser at web.de Mon Aug 18 08:18:48 2003 From: mpeuser at web.de (Michael Peuser) Date: Mon, 18 Aug 2003 14:18:48 +0200 Subject: advice choosing IDE References: Message-ID: "Lupe" schrieb im Newsbeitrag news:bhqe4p$23loq$1 at ID-202776.news.uni-berlin.de... > I'm convinced to try Python! > > I've read many posts, and although I recently bought a book on C to start > learning it, I'd like to give Python a good chance. > > What IDE would you recommend for someone who needs easiness of use with a > background of Pascal and VB for MS Office? I've definitely changed to > Linux now and I would like a free IDE either for procedural or object > oriented programming. > > I'd need an easy help on syntax, if possible with examples and a front end > debugger with easy trace, breakpoints and watches. Well, I think you will have a hard time ahead. No one who has ever used Delphi, VB or RealBasic can really understand in what poore shape Python (and Perl is no better) support is ;-) The easiest thing would be PythonWorks which however seems to be no longer available and has never been free. There is no second best. The third best would be something like ActiveState's KOMODO Profesional (with GUI Builder for Tkinter) runs best under Windows, about 300 $ or Archaeopterix Wing IDE Standard (no GUI Bilder) about the same price. I personally use IDLE (plain vanille IDE), it has some features, yes. But probably not what you expect. There are a lot of versions. I personally like 0.81 best. There are two GUI Toolkits you might like: PyQt and their GUI Builder (that would be free for non commercial work) if you plan to do *a lot* of GUI applications. The GUI Builder is *not* an Python IDE, so that is somewhat off topic ;-) Then there is wxPython and something like BoaConstructor, but Boa as well is more a GUI Builder than an IDE, thoug it nows a little bit more Python. Kindly Michael P From peter at engcorp.com Tue Aug 19 06:41:14 2003 From: peter at engcorp.com (Peter Hansen) Date: Tue, 19 Aug 2003 06:41:14 -0400 Subject: Path Problem on W2K? References: <93f5c5e9.0308170927.6e0bdc38@posting.google.com> <3F40F62D.8B32CFBD@engcorp.com> Message-ID: <3F41FECA.6743B6BD@engcorp.com> Duncan Booth wrote: > > Peter Hansen wrote in > news:3F40F62D.8B32CFBD at engcorp.com: > > > Generally, for something like "Secure Shell", I find it much > > easier just to write a little batch file that knows the full > > path. Put these batch files in a directory called c:\bin > > or c:\utils or something and add *that* to your path. Then > > you can avoid excessive PATH creepage... > > > > Alternatively create doskey macros for commands like that then you just > need one file with a load of macro definitions. Does that let you execute them from other batch files? I have a few dozen utilities which run Python scripts by executing "call python scriptname.py" somewhere, relying on a .bat file in the PATH. Does the DOSKEY approach work similarly? -Peter From alessandro at sephiroth.it Thu Aug 7 15:16:43 2003 From: alessandro at sephiroth.it (Alessandro Crugnola *sephiroth*) Date: Thu, 07 Aug 2003 19:16:43 GMT Subject: py2exe problems References: <8utYa.48785$cl3.1524137@news2.tin.it> Message-ID: i've installed python 2.2.2 and now it seems working well. Excuse, me but what are the issues with the other python versions? -- Alessandro Crugnola [sephiroth] Flash | PHP Developer http://www.sephiroth.it Team Macromedia Volunteer for Flash http://www.macromedia.com/go/team Flash-php mailing list http://www.flash-php.it/index.php?ml=fpcoders&action=subscribe From afriere at yahoo.co.uk Wed Aug 6 02:32:26 2003 From: afriere at yahoo.co.uk (Asun Friere) Date: 5 Aug 2003 23:32:26 -0700 Subject: converting an integer to a string References: <2AZXa.2573$_a4.492504@news20.bellglobal.com> Message-ID: <38ec68a6.0308052232.3cae2905@posting.google.com> "Sean Ross" wrote in message news:<2AZXa.2573$_a4.492504 at news20.bellglobal.com>... > "Ken Fettig" wrote in message > news:bgpl6401e66 at enews4.newsguy.com... > > I have a quick simple question. How do you convert an integer to a string > in > > Python? > > > >>> 1 > 1 > >>> str(1) > '1' > >>> > > HTH, > Sean Depending on where and why you want to convert it >>> "%d" % 1 '1' might be useful too. eg.. >>> dat = (12, 'Spam Street') >>> "%d %s" % dat '12 Spam Street' From adalke at mindspring.com Fri Aug 22 12:01:50 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Fri, 22 Aug 2003 16:01:50 GMT Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> <6dj2kv8ugkieehs7guh786cl40o5lj6mcs@4ax.com> <3F455BF0.5070700@nyc.rr.com> Message-ID: Kenny Tilton: > > > as when we go for the > > > productivity win of untyped variables and give up on bugs strong static > > > typing is supposed to find. Jacek Generowicz: > Note that Kenny said "untyped _variables_" not "untyped objects" or > "untyped language". Ahh, I hadn't caught that. I did know Lisp had strong dynamic typing with optional static typing, which was why I was surprised he mentioned it. I still don't understand why he said it given that Python similarly meets the quoted statement. Andrew dalke at dalkescientific.com From python at rcn.com Sun Aug 17 21:54:07 2003 From: python at rcn.com (Raymond Hettinger) Date: Sun, 17 Aug 2003 21:54:07 -0400 Subject: Py2.3: Feedback on Sets References: <20030817193709.460B22210E@techunix.technion.ac.il> Message-ID: <001701c3652c$2c621e20$e841fea9@oemcomputer> [Beni Cherniavsky] > Generating the full powerset seems pretty useless. `isdisjoint` sounds like a > good idea since it can be implemented more effeciently than ``not a & b``. True enough. It is easy to putogether an early-out algorithm using itertools. So, it can be done a C speed. The question is whether there are sufficient use cases to warrant expanding an already fat API. > >* Does the performance meet your expectations? > > > I think so. Almost half of my program's time is spent in set.py according to > the profiler but when I optimized the sets module (and my dsets) with psyco, > things got several percent slower. Is this a good sign ?-) It's a very good sign. Already, most methods run at C speed thanks to itertools and dicts. Try directing pysco to BaseSet._update() and BaseSet.__contains__(). Those are the two most important methods that do not run at C speed. > >* Do you care that sets can only contain hashable elements? > > > No more than I care for dicts containing only hashable keys. How else could > you define it? The hard way. Keep a separate ordered list for elements that define ordering operations but not a hash value. Insert and Search using a binary search. Keep a third list for elements that only support equality comparision. Use linear search for that one. This complicates the heck out of the code but would expand the range of things storable in sets. The only real life use case I can think of is using a third party package that supplied objects without a hash code. > What I do like is the auto-copying of mutable sets when used a set items; I > wouldn't mind something like this to be extended into other Python types > (primarily dicts). The protocol would also work for dicts, but the key to getting it to work is installing as_immutable methods in the objects that are being stored. Something that touches that much code would also need compelling use cases to justify it. But yes, it can be done. > >* How about the design constraint that the argument to most > > set methods must be another Set (as opposed to any iterable)? > > > I'd go for any iterable where it's enough and require __contains__ where > that's needed. I think together this should cover all method's needs. I > think it's better not to add artificail checks, so that other set-alike types > can be used with sets (primarily mapping or set-alike types). Wish granted. I've relaxed the requirements that the arguments be a set and now any iterable will do. This will come out in Py2.3.1. > >* Are the docs clear? Can you suggest improvements? > > > It's been a lot of time since I had to read them which is probably a good > sign. Great! > >* Are sets helpful in your daily work or does the need arise > > only rarely? > > > Helpful. Since they were released on 2.2, I feel free to import sets whenever > it reflects my meaning clearer than dicts, even when I don't use any fancy > operations. I find the code more readable this way. Me too. > And sets of sets (or ImmutableSets as dict keys) are very helpful when you > need them. Good. I've gotten almost no replies from people using sets of sets. Raymond Hettinger From peter at engcorp.com Tue Aug 19 15:29:50 2003 From: peter at engcorp.com (Peter Hansen) Date: Tue, 19 Aug 2003 15:29:50 -0400 Subject: python-dev Summary for 2003-08-01 through 2003-08-15 References: Message-ID: <3F427AAE.6AE4543F@engcorp.com> Andrew Dalke wrote: > > Alex Martelli: > > My Python 2.3 installation on MS Windows *DOES* have > > c:\Python23\Lib\site-packages\ ...! And if I recall correctly > > so had the older Python 2.2 installation (under c:\Python22 > > of course). So, what's different about yours...? > > You and Peter Hansen are both correct. Perhaps my memories > are several years old? Maybe I was thinking of a 2.0 or a 1.5.2 > install on Windows? I remember loooking for the win32 COM > code, and finding it off the top-level directory. We're still using Python 2.0 as our primary network installation, and I can confirm that it had no site-packages folder under python/lib with a vanilla install. Many things, including win32all, installed themselves right under the /python folder. This of course has not stopped us from adding one, and in fact it was even supported already by site.py... -Peter From lorenb2 at bezeqint.net Tue Aug 12 08:28:31 2003 From: lorenb2 at bezeqint.net (Bill Loren) Date: Tue, 12 Aug 2003 14:28:31 +0200 Subject: Howto MACRO in python ? References: <3F38D039.2B28800A@engcorp.com> Message-ID: <001201c360cd$3da065b0$6400a8c0@EVOD31> Welp, I'm trying to implement some kind of tracing mechanism which will announce every function entrance in Run-Time. I wrote a trace function: DEBUG_LVL = 50 def trace(level, message): if DEBUG_LVL >= level: print message to which I will call with: trace(40, "%s.%s: entrance" % (__name__, ) ) upon every function entrance. (btw I couldn't find any built-in name which correspands to the current function name so I type it myslef every trace call) my wish was to create a MACRO that will save me some text in the code. something like: TRACE(40, "entrance") that will expand into the trace call. what do you think ? thanks so much ! ~B ----- Original Message ----- From: "Peter Hansen" Newsgroups: comp.lang.python To: Sent: Tuesday, August 12, 2003 1:32 PM Subject: Re: Howto MACRO in python ? > Bill Loren wrote: > > > > I was looking for a guidance about how to code MACROs in python. > > any offer ? > > A few alternative responses to Irmen's to-the-point answer: > > 1. Nobody does. > > 2. Those who do, probably use a macro language, like maybe M4. > > 3. Nobody does. > > 4. What are you actually trying to accomplish, specifically? > > -Peter > -- > http://mail.python.org/mailman/listinfo/python-list From mack at incise.org Tue Aug 26 22:40:39 2003 From: mack at incise.org (mackstann) Date: Tue, 26 Aug 2003 21:40:39 -0500 Subject: Raw Input Question In-Reply-To: <3F4C1880.5030903@hotmail.com> References: <3F4C1880.5030903@hotmail.com> Message-ID: <20030827024039.GY1695@incise.org> On Tue, Aug 26, 2003 at 10:33:36PM -0400, hokiegal99 wrote: > How can I pass the content of one varible into raw_input? See below for > what I'm trying to do: > > XXX = raw_input("1. Enter the string that you'd like to find: ") > y = raw_input("2. Enter the string that you'd like to replace XXX with: ") > > I'm trying to pass x into y. I tried the "Enter the string that you'd > like to replace", XXX, "with:" approach, but Pyhton told me that I could > only pass 1 argument, no more. Ah, you are confusing print's behavior for general string concatenation. I believe what you want to do is: y = raw_input("2. Enter the string that you'd like to replace "+XXX+" with:") or y = raw_input("2. Enter the string that you'd like to replace %s with:" % XXX) -- m a c k s t a n n mack @ incise.org http://incise.org As the poet said, "Only God can make a tree" -- probably because it's so hard to figure out how to get the bark on. -- Woody Allen From pu Mon Aug 4 17:03:39 2003 From: pu (Patrick Useldinger) Date: Mon, 04 Aug 2003 23:03:39 +0200 Subject: spawnv( ) or spawnl( ) do not launch a normal running process in Python 2.2.2? In-Reply-To: References: Message-ID: <3f2ec9dd$1_2@news.vo.lu> nushin wrote: > os.spawnv(os.P_NOWAIT,'/usr/bin/python',('python hello.py >/dev/null > &')) > > > os.spawnl(os.P_NOWAIT,'/usr/bin/python',('python hello.py >/dev/null > &')) Did you try *without* the redirections? -- Real e-mail address is 'cHVAdm8ubHU=\n'.decode('base64') Visit my Homepage at http://www.homepages.lu/pu/ From richie at entrian.com Fri Aug 1 05:13:45 2003 From: richie at entrian.com (Richie Hindle) Date: Fri, 01 Aug 2003 10:13:45 +0100 Subject: Python speed vs csharp In-Reply-To: References: Message-ID: <49akiv8efalkgsbrevn83quncv04u81vva@4ax.com> [Richie] > Using Psyco dropped from 7.1 seconds to 5.4 - not great, but not bad for > two lines of additional code: > import psyco > psyco.bind(erfc) [Lulu] > Try these two lines instead: > > import psyco > psyco.full() > > 18 seconds -> 3.25 seconds. I tried that the first time but saw no improvement over bind... having checked the Psyco docs I see that it won't optimise code at module scope, and I had my driver loop at module scope. I now get 1.25 seconds down from 7.1 - slightly faster than Pyrex. Impressive. [OT: I hope Pyrex isn't suffering as a result of people writing little test scripts full of module-level code and being disappointed at the results.] -- Richie Hindle richie at entrian.com From pobrien at orbtech.com Fri Aug 29 16:24:39 2003 From: pobrien at orbtech.com (Patrick K. O'Brien) Date: 29 Aug 2003 15:24:39 -0500 Subject: Object Database (ODBMS) for Python References: <1DAECE9E8F34E04AA0E5699AF7D9FF090708D440@stpmsg00.corp.fairisaac.com> <3f4f7af6_3@corp.newsgroups.com> <3f4f9e88_3@corp.newsgroups.com> Message-ID: "Paul D. Fernhout" writes: > Patrick K. O'Brien wrote: > > Let me start by saying I'd love to cooperate, even if I am > > competitive by nature. ;-) > > Nothing like a good controversy to get people paying attention. :-) And never let the facts get in the way of a good story. ;-) > > This API looks rather verbose to me. I think mine would look like: > >>>> t = tx.Create('User', name='Sir Galahad') user = db.execute(t) > > I think your notion of transactions is growing on me. :-) I can see how > you can generalize this to construct a transaction in a view of a > database, querying on DB + T1 + T2 etc. while they are uncommitted and > then commit them all (perhaps resolving multiuser multitransaction > issues on commits). Kind of neat concept, I'll have to consider for some > version of the Pointrel System. > > I think it is the special syntax of: > tx.Update(u1, name='Joe') > or: > tx.Create('User', name='Sir Galahad') > which I am recoiling some from. > > I think part of this comes from thinking as a transaction as something > that encloses other changes, as opposed to something which is changed. > Thus my discomfort at requesting services from a transaction other than > commit or abandon. I'm not saying maybe I couldn't grow to love > tx.Update(), just that it seems awkward at first compared to what I am > used to, as well compared to making operations on a database itself > after having told the database to begin a transaction. My use of the term "transaction" has certain subtleties that deserve clarification. First, a transaction is an instance of a Transaction class (or subclass). This instance must have an execute method that will get called by the database (after the transaction instance gets tested for picklability, and gets logged as a pickle). That execute method will be passed the root of the database. It is then free to do whatever it wants, as long as the sum total of what it does leaves the database in a consistent state. All transactions are executed sequentially. All changes made by a transaction must be deterministic, in case the transaction gets reapplied from the transaction log during a recovery, or restarting a database that wasn't dumped just prior to stopping. At this point, PyPerSyst does not have commit/rollback capability. So it is up to the transaction class instance to not leave the database in an inconsistent state. I'm looking into supporting commit/rollback, but the simple solution there would double RAM requirements, and other solutions are tricky, to say the least. So I'm still looking for something simple and elegant to fit in with the rest of the framework. The transactions I've shown, tx.Create, tx.Update, tx.Delete, are simply generic classes that come with PyPerSyst to make it easy to create, update and delete single instances of entities. Most real applications would define their own Transaction classes in addition to these. > I'm also left wondering what the read value of the "name" field is > when accessed directly as "u1.name" after doing the "wx.Update()" > and before doing the "db.execute()". t = tx.Update() merely creates a transaction instance, providing it with values that will be needed by its execute() method. (See the GOF Command pattern.) So nothing changes until the transaction is executed by the database, which happens when the transaction instance is passed to the database's execute method: db.execute(t) > [By the way, pickly, picky, and I fall down on it too, but you use > different capitalizations for those two functions.] There aren't two functions: tx.Update is a class, db.execute is a method. The capitalization is correct. ;-) > So is it that in PyPerSyst there appears to be one way to access > information (directly through the object using Python object > attribute access dot syntax) [not sure about database queries?] and > another way to change objects -- using tx.XYZ()? This mixing of > mindsets could be confusing (especially within an object that > changes its own values internally). You could define transactions that do queries as well. And some people prefer to do that. But I think for most reads it is easier to traverse the db.root object. If you use entities, and an instance of the Root class for your db.root, then your db.root is a dictionary-like object that gets you to the extent for each Entity subclass in your schema. The entity extent is an instance of an Entity class that manages the set of all instances of the class that it manages. The Extent class is how I'm able to provide Relational-like features. Inside of Entity instances, your code looks just like regular Python code. Its just application code that must go through transactions. Sure this mixing of mindsets is different than what people are used to, but we're talking about managing valuable data. If you simplify things too much, you lose the integrity of your data. > Using tx.Update also becomes an issue of how to convert existing > code to persistant code. Mind you, the Pointrel System can't do > this transparently either, but it doesn't try to do it at all. The > Pointrel System requires both looking up a value and storing it to > use a different syntax. Is it just a matter of aesthetics about > whether it is better to have the whole approach be unfamiliar or > whether it is better to have only half of it be unfamiliar? Or is > there something more here, some violation of programmer > expectations? [See below.] Existing code won't become magically persistent by adding PyPerSyst. > > And unique ids (immutable, btw) are assigned by PyPerSyst: > >>>> user.oid > > 42 > > Being competetive here :-) I would love to know if you have a good > approach for making them globally unique across all possible users > of all PyPerSyst repositories for all time. The Pointrel has an > approach to handle this (I don't say it will always work, or is > efficient, but it tries). :-) Feel free to raid that code (BSDish > license, see license.txt), but that issue may have other deeper > implications for your system. Sorry, nothing special here. They are just incrementing ints unique within each extent. It would be easy to switch to a globally unique id if you have a good one, and as long as it was deterministic, and not random in any way. > > And you can still access attributes directly, you just can't > > change them outside of a transaction: > > > >>>> user.name > > 'Sir Galahad' > > And the generic Update transaction is equally simple: > > > >>>> t = tx.Update(user, name='Brian') db.execute(t) user.name > > 'Brian' > > I know one rule of user interface design (not nexceesarily API of > course) is that familiar elements should act familiar (i.e. a drop > down list should not launch a dialog window on drop down) and that > if you are going to experiment it should look very different so > expectations are not violated. > > The issue here is in part that when you can reference "u1.name" and > then "u1.name = 'Joe'" generates an exception (instead of > automatically making an implict transaction), some user expectation > of API symmetry may be violated... While this is feasible, the problem I have with this is that I think implicit transactions on this minute level of granularity are evil. That's the main reason I haven't implemented this, even though others have done this for PyPerSyst. I think too many people would abuse the implicit transaction feature, resulting in inconsistent and unreliable objects. I'm targeting serious, multi-user applications. But PyPerSyst is completely modular, so you can use it to implement all kinds of persistence systems. Most of the capabilities I've been discussing are new, and completely optional. > Also, on another issue, it seems like the persistant classes need to > derive from a special class and define their persistant features in > a special wy, i.e. class Realm(Entity): _attrSpec = [ 'name', ] etc. > Again, this is going somewhat towards Python language integration > yet not all the way. You don't *have* to use the Entity class that comes with PyPerSyst, but if you do, it lets you define the attributes, alternate keys, and fields for your subclass in as simple a form as I could think of. If you don't use the Entity class, then you have to figure out how to support instance integrity, alternate keys, referential integrity, bi-directional references, etc. So I think they provide some benefit. > While I'd certainly agree your version is more concise than what I > posted first (just an example of a system that does not attempt to use > Python language features), later in the email (perhaps you'll get to it > in your next reply) was the simpler: > > import persistanceSystem import * > foo = MyClass() > PersistanceSystem_Wrap(foo) > # the following defaults to a transaction > foo.x = 10 > # this makes a two change transaction > PersistanceSystem_StartTransaction() > foo.y = 20 > foo.z = 20 > foo.info = "I am a 3D Point" > PersistanceSystem_EndTransaction() > > That approach does not violate any symmetry expectations by users -- > you can assign and retrieve values just like always. If users expect symmetry it is because they are used to writing single process programs that do not share objects. Does anyone expect this kind of symmetry and transparency when writing a multi-threaded application? Why not? Granted, having start/end transaction semantics might change some of the rules. But even if we had those in PyPerSyst, I would probably only use them inside of Transaction classes, not embedded in application code where they are harder to find and test. Explicit transaction objects have many benefits. It's sort of similar to the notion of separating your application logic from your gui code. Sure its easier to just put a bunch of code in the event handler for a button. But is that the best way to code? In my mind, implicit transactions, or commit/rollback in application code, is like putting all your business logic in the event handlers for your gui widgets. I'm trying to keep people from writing crappy persistent applications. > > PyPerSyst can persist *any* picklable object graph. > > Are the graphs stand alone can they reference other previously > persisted Python objects (not derived from "Root" or "Entity")? A PyPerSyst database has a single entry point, named root, that can be any picklable Python object, and any objects reachable from that object. When the root gets pickled (for example when you do db.dump()), the whole thing gets pickled and all references are maintained. When the database starts, the entire thing gets unpickled. The entire thing is always in memory (real, or virtual). The snapshot and log are on disk. Each transaction is appended to the log. Did that answer your question? > > But it also comes with an Entity class and a Root class (that > > understands Entity classes) that provides additional functionality, > > such as alternate indexes, referential integrity, instance > > validation, etc. > > I guess I need to learn more about when these are better handled by > the persistance system as opposed to the applications that use it. In my mind, anything that is generic shouldn't have to be reinvented in application code. I feel like I've spent most of my career reinventing one database application after another. ;-) > Presumably a very transaparent API for persistance is still needed > for an ODBMS which is Python friendly? (Does ZODB do any of this?) I started writing a wrapper for ZODB and gave up about a year ago. > If I need to write any extra code at all for an object to be > persistant, or derive from a specialized class, I could just derive > from a class that knows how to use SQL to store pickled fields. You don't think there is a benefit to not having to use a database, not having to map anything to relational tables, not being limited to the relational model, and not having to do joins, etc? I don't care how good an O-R mapper is, not having to use one at all is better. > I think this is the core of the question of this part of the thread. > You wrote "I've come to think otherwise". I'd be curious to hear > more on any use cases or examples on why transaparency is not so > compatible with reliability etc. I just think implicit transparent transactions would lull users into a false sense of integrity and make them write sloppy applications that didn't actually maintain the integrity of their objects when used in a multi-user environment. I think the kind of applications I want to use PyPerSyst for demand that it be difficult for application programmers to do the wrong thing with regards to the integrity of the persisted data. I think having transactions as explicit objects provides more control over the integrity of the database. If users want transparency, it can be done, using PyPerSyst, it just isn't the focus of my current efforts. And I don't think explicit transactions are that much of a burden. Transaction code is a small percentage of application code, compared to all the interface code you have to write. And you could easily write wrappers for transactions that make them less burdensome. -- Patrick K. O'Brien Orbtech http://www.orbtech.com/web/pobrien ----------------------------------------------- "Your source for Python programming expertise." ----------------------------------------------- From sales at inode.at Thu Aug 21 08:45:29 2003 From: sales at inode.at (Request Tracker) Date: Thu, 21 Aug 2003 14:45:29 +0200 Subject: [Tkt #600205] (sales) Your details Message-ID: Sehr geehrte Damen und Herren, dieses Mail wurde automatisch erstellt, da wir eine Nachricht mit dem Betreff "Your details" von Ihnen erhalten haben. Ihre Mail hat die Ticket ID [Tkt #600205] erhalten und wird in kuerze bearbeitet werden. Sie brauchen auf diese Mail nicht zu antworten. [Tkt #600205] Falls Sie mit uns bezueglich dieses Betreffs "Your details" wieder korrespondieren, verwenden Sie bitte die Ticket (Tkt) ID . Vielen Dank ! Greetings, This message has been automatically generated in response to your message regarding "Your details", the content of which appears below. There is no need to reply to it now. Request Tracker has received your message and it has been assigned a ticket ID of [Tkt #600205]. Please include the string [Tkt #600205] in the subject line of all future correspondence about this problem. To do so, you may reply to this message. Thank you ! -- Inode Telekommunikationsdienstleistungs GmbH - http://www.inode.at/ Tel.: 059999-0 Fax.: 059999 6699 Buero Wien - Millennium Tower Handelskai 94-96/43 - A-1200 Wien Buero Graz - Schmiedlstrasse 1 - A-8042 Graz Buero Linz - Wienerstrasse 131 - A-4020 Linz Buero Sbg - Schillerstrasse 30 - A-5020 Salzburg Buero Ibk - Eduard Bodem Gasse 5-7 - A-6020 Innsbruck Buero Villach - Europastrasse 8/3OG KO6A - A-9524 Villach Please see the attached file for details. >>> application/octet-stream component, message, part 2: http://rt.inode.at/stripmime1/2003/08/1061469929-8090/your_document.pif --- Headers Follow --- Return-path: Received: from smtp-06.inode.at ([62.99.194.8] helo=smtp.inode.at) by rt.inode.at with esmtp (Exim 3.32 #1) id 19pooi-00026R-00 for rt-sales at rt.inode.at; Thu, 21 Aug 2003 14:45:28 +0200 Received: from e-mail.inode.at ([213.229.60.101]:35746) by smtp.inode.at with esmtp (TLSv1:DES-CBC3-SHA:168) (Exim 4.10) id 19poof-0001Lg-00 for rt-sales at rt.inode.at; Thu, 21 Aug 2003 14:45:25 +0200 Received: from [212.152.255.254] (helo=INTERNET) by e-mail.inode.at with esmtp (Exim 3.22 #2) id 19pond-0007IH-00 for sales at inode.at; Thu, 21 Aug 2003 14:44:24 +0200 From: To: Subject: Your details Date: Thu, 21 Aug 2003 14:56:23 +0200 X-MailScanner: Found to be clean Importance: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MSMail-Priority: Normal X-Priority: 3 (Normal) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="_NextPart_000_04963D41" Message-Id: -------------------------------------------- Managed by Request Tracker From jason at jasonandali.org.uk Wed Aug 27 12:40:33 2003 From: jason at jasonandali.org.uk (Jason Williams) Date: 27 Aug 2003 16:40:33 GMT Subject: Aspect oriented Everything? References: <32cc321c.0308221316.2f5793ac@posting.google.com> <6ee58e07.0308230459.24f53b64@posting.google.com> <8ef9bea6.0308261857.1b44a5b7@posting.google.com> <8ef9bea6.0308270810.7adfe408@posting.google.com> Message-ID: In article <8ef9bea6.0308270810.7adfe408 at posting.google.com>, Hung Jung Lu wrote: >> def methodThatHasToListenForAnEvent >> listenForEvent(e) do >> # The method stuff goes here >> end >> end [snip] > The question is: are there code spots that are not factored? If you > have ONE single class that has to implement the before, around, or > after methods, sure, nothing wrong with what you have said. But, if > you have > [snip > > You start to ask your self: how come the register() deregister() parts > are not factor out? How can I factor out these parts of code? Okay; module EventListenThing def listenForEvent(e) # ... end end class Thingy include EventListenThing def wotsit listen(e) do # ... end end end What does AOP gain over mixins? From imbosol at aerojockey.invalid Thu Aug 21 01:23:08 2003 From: imbosol at aerojockey.invalid (Carl Banks) Date: Thu, 21 Aug 2003 05:23:08 GMT Subject: Weird Problem References: Message-ID: <0HY0b.24239$Cd2.10527@nwrdny01.gnilink.net> Kris Caselden wrote: > I'm sure this is a simple newbie problem, but I can't figure it out > for the life of me. > > The code: > import sys, os > input = open("example.py","r") > > Gives me the error: > TypeError: an integer is required I'm going to guess. I'll bet you used "from os import *" somewhere above that. os has a function "open" that closely interfaces the operating system's open call--and the second argument has to be an integer. BTW, you don't know this, but since you're using 2.3, you should probably start using "file" instead of open: input = file("example.py","r") -- CARL BANKS http://www.aerojockey.com/software "You don't run Microsoft Windows. Microsoft Windows runs you." From sean at activeprime.com Tue Aug 5 10:39:27 2003 From: sean at activeprime.com (Sean) Date: 5 Aug 2003 07:39:27 -0700 Subject: Passing Global Variables between imported modules References: Message-ID: Thanks for the help guys. Passing the variable as a class parameter (or even function parameter) is not really a possibility due to the structure of the actual program code. The real world problem is that I'm defining a global variable for a base application path for my program, which changes depending on whether the program is being run as a script, an compiled exe, and if there are preconfigured settings in the windows registry and/or a config file. This was previously being done in the global space of the "main" application script. The class that needed this info was about 5 or six steps down the import tree. I think my solution is going to involve taking all the logic for finding the base path out of the main app script and putting it in it's own module. That way anything that needs to see that variable can just import that module and not have to worry about strange import loops. -Sean Levatino From newsgroups at jhrothjr.com Sun Aug 3 19:12:45 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Sun, 3 Aug 2003 19:12:45 -0400 Subject: time, calendar, datetime, etc References: <954001-p55.ln1@beastie.ix.netcom.com> Message-ID: "Dennis Lee Bieber" wrote in message news:954001-p55.ln1 at beastie.ix.netcom.com... > John Roth fed this fish to the penguins on Sunday 03 August 2003 03:47 > am: > > > > > AFIK, it hasn't changed. I *think* you're talking about the epoch, > > which is an astronomical thing that's rightly ignored outside of > > There is a subtle change in the length of the "year" (besides the > redefinition of where "0/first point of Aries" is with respect to the > stars). > > J2000 defines a year as 365.25 days, B1900 used 365.242198781 > > From "Spherical Astronomy" (Robin M. Green; 1985 Cambridge University > Press) > > "... The starting epoch for JD has the same formal definition in every > time-scale, but will not correspond to the same instant of time. ..." > > While both use 4713BC Jan 1.5 as the "0" point, the moment that point > occurred differs in the two calculations. Undoubtedly true, but it makes absolutely no difference for what we're talking about. All we need in this conversation is a mapping of days to integers that goes back far enough. Converting from GMT / UT / whatever to ET is something that can safely be left to the astronomers, and that's what the detail you're talking about is concerned with. John Roth > From adalke at mindspring.com Fri Aug 1 04:59:21 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Fri, 1 Aug 2003 02:59:21 -0600 Subject: Detect PythonWin? References: <3f29fe44.104328@news.muenster.de> Message-ID: Martin Bless wants to know how to do: > if detect("running on PythonWin"): > pass > # fake arguments ... > else: > "proceed normal" To see if you're on Windows, >>> import sys >>> sys.platform 'win32' >>> To see if the win32 extensions are installed try: import win32com # or another module in the extension except ImportError: print "Not installed" else: print "Installed!" Andrew dalke at dalkescientific.com From ramiak2000 at yahoo.com Sat Aug 16 03:31:35 2003 From: ramiak2000 at yahoo.com (Rami A. Kishek) Date: Sat, 16 Aug 2003 03:31:35 -0400 Subject: Tkinter Question Message-ID: <3F3DDDD7.38757770@yahoo.com> I'm in love with Lundh's Introduction to Tkinter manual, but I couldn't find in it the answer to this simple question: How do I set the properties of the main application (such as background color, fonts, etc)? I know I can do it widget by widget, but since the default for each widget is to inherit the properties of the Application, I was hoping there's a global way of setting these properties. Any feedback will be much appreciated, From skip at pobox.com Tue Aug 5 00:02:43 2003 From: skip at pobox.com (Skip Montanaro) Date: Mon, 4 Aug 2003 23:02:43 -0500 Subject: Exploratory query In-Reply-To: References: Message-ID: <16175.11363.624854.220667@montanaro.dyndns.org> Don> Would python allow me to run flist and use its output, or would I Don> need to re-write flist? The idea is to keep something on the screen Don> and poll the mailboxes every n seconds and update the display. You can do this quite easily. Presuming you just want to display flist's output for now, but maybe mangle it later, you can probably get away with something simple like this: import time import commands while True: status, output = commands.getstatusoutput("flist") if status != 0: print "flist barfed... exiting" # right here you could massage output print output time.sleep(300) # five minutes Skip From ialbert at mailblocks.com Mon Aug 18 19:38:56 2003 From: ialbert at mailblocks.com (Istvan Albert) Date: Mon, 18 Aug 2003 19:38:56 -0400 Subject: SWIG typemap leading to a memory leak In-Reply-To: References: Message-ID: <3F416390.8020608@mailblocks.com> Skip Montanaro wrote: > You need to DECREF the result of PyInt_FromLong(key): > PyDict_SetItem will bump the reference counts of the objects you pass into > it. When the dictionary goes away, it does its DECREFs, but all those > integers still have non-zero reference counts as a result of their initial > creation by PyInt_FromLong. You have to take care of that. Fixed my problem right away. Thanks a bunch! Istvan. From borcis at users.ch Wed Aug 20 19:50:11 2003 From: borcis at users.ch (Borcis) Date: Thu, 21 Aug 2003 01:50:11 +0200 Subject: A SWIG for the library documentations ? Message-ID: <3F440933.6070402@users.ch> How difficult do you think would be an engine that with minimal tuning by "macro stylesheets" would provide an automatic equivalent in target computer language syntax, to the original documentation of a ported language library? while keeping human language as close to unchanged as possible? First targets would obviously be the swallowing by python of the available TCL/TK and Java library documentations (because of tkinter and jython). Then I guess the chase should target javascript, by first requiring javascript implementations to get jvm-based if they aren't already (what's in a name ?). Now if jvm implementations of javascript can't be had, then let the python church shout loud that python-jython is in fact the *real* javascript, while the ecmascript variant is a fake :) Important point : the above counts as a minimalistic but non-trivial and moderately useful analogic model version of the challenge that really is the machine translation of human languages. So it should count as *appropriate training* in the form of a humble simplification, to the power of solving that harder problem ! From aleax at aleax.it Wed Aug 20 16:03:26 2003 From: aleax at aleax.it (Alex Martelli) Date: Wed, 20 Aug 2003 20:03:26 GMT Subject: What's better about Ruby than Python? References: <3F41505F.69D18CC8@alcyone.com> <66d7kvonvb2n0nqbqahhd5roak7ur81sob@4ax.com> Message-ID: Doug Tolton wrote: ... >>> abstractions and better programmer productivity. Why not add Macro's >>> allowing those of us who know how to use them and like them to use >>> them. If you hate macros, or you think they are too slow, just don't >>> use them. ... >>to mention that I'd have to let somebody else write the second edition >>of the Nutshell -- if Python had macros, I would have to cover them in >>"Python in a Nutshell". > > Sadly, I would say that is something that would sway me. I love my > Python in a Nutshell book. I have that baby on my desk and I refer to > it *daily*. Although I'd say that's more extortion than a winning > argument!! :-p "Extortion"? It's a simple and direct explanation of why your "if you hate macros ... just don't use them" argument can't possibly apply to _me_ (nor to any other author of Python books which are assumed to cover the whole language). > I just don't see Macros as the huge threat you do. As someone I guess that's the rub of our disagreement, yes. > mentioned in a previous post, the option would require to do declare > explicitly that you are using Macros. Why is that such a *huge* > issue? Why is it that the very *existence* of a Macro in a program > would offend your sensibilities? Please make a specific proposal. Where would one have to declare explicitly that one is using macros: on every usage of every macro? Once and for all somewhere on the commandline or site.py or the like? Or somewhere in-between? The macros I consider dangerous are the ones that work like in the languages I know that have powerful macros -- Dylan, Scheme, Common Lisp -- where the fact that (e.g.) 'foo' is a macro is declared once, somewhere out of sight; if at the other extreme every macro use had to be 'stropped' by, e.g., prefixing AND postfixing the macroname with $$, and the macro declaration had to be in the same scope as its use and lexically before it, then the danger would be minimal -- but so would be the usefulness and the interest of having the things in the first place. If there is a sweet-spot in-between, where the fact that 'foo' IS a macro is made extremely clear and impossible to miss, and at the same time still provides important usefulness over what could be done today -- then I definitely want to see the detailed PEP and use cases. I have nothing against the WORD 'macros' -- I used to use macros regularly when photography was my hobby, and I never could have made photos just as beautiful of petal flowers and dew drops without macros. So if it's LENSES you mean, we may not disagree;-). But in a programming context, that is hardly ever the meaning one DOES attribute to this word:-). >> They don't change the underlying language, they just add a >>> more useful abstaction capability into the language. >> >>They may not change the "underlying" language but they sure allow anybody >>to change the language that is actually IN USE. That is definitely NOT >>what I want in a language for writing production-level applications. > > I tend to disagree on this point. I like the idea of being able to > treat commonly reused idioms as if they are a part of the language. But if YOU identify a set of such "commonly reused idioms" and invent a syntax and semantics for them, and publish modules using it; and so does Joe; and so does Jim; and so does Bob; then the work of Moe who is trying to put together a large application using all of these modules becomes vastly complicated -- and the job of the consultant called in to help can become impossible. Maybe you're as good a language designer as Guido, maybe even better; but what are the chances that the same ALSO holds for Joe AND for Jim AND for Bob? Surely chances are that a majority of these uncountable numbers of amateur language designers are bad to terrible at the job -- MOST languages around are pretty badly designed after all. I know that personally I *FAR* prefer to be using a language designed by Guido van Rossum, than one designed by myself: he's just better at the language-design job. Powerful macros turn everybody into language designers without actually giving them any more skill or flair or intuition at what makes a language good. Thanks, but NO, THANKS. >>I dearly hope that, if and when somebody gives in to the urge of adding >>macros to Python, they will have the decency to FORK it, and use an >>easily distinguishable name for the forked Python-with-macros language, >>say "Monty". This way I can keep editing future editions of "Python in >>a Nutshell" and let somebody else write "Monty in a Nutshell" without >>any qualms -- and I can keep programming applications in Python, helping >>people with Python, consulting about Python, and let somebody else worry >>about the "useful abstaction" fragmentation of "Monty". If that "useful >>abstaction" enters the Python mainstream instead, I guess the forking >>can only be the last-ditch refuge for those of us (often ones who've seen >>powerful macros work in practice to fragment language communities and >>end up with "every programmer a different language"... do NOT assume that >>fear and loathing for powerful macro systems comes from LACK of experience >>with them, see also the Laura Creighton posts whose URLs have already >>been posted on this thread...) who'd much rather NOT have them. But maybe >>moving over to Ruby might be less painful than such a fork (assuming THAT >>language can forever stay free of powerful macro systems, of course). > > That certainly is one way for it to happen. I must say I certainly am > suprised at your vehemence. I don't think the natural state of human > beings is singular in purpose or design. I think the natural state of > humans is to fracture into competing camps / factions. *Every* human > system of any size has factions of some sort or another. I think the > power of Unix / Linux in general has been in working to allow these > factions to Co-exists peacefully. By trying to prevent factioning Try stimulating a debate between a Debian packager, a Mandrake fanatic, and a Gentoo hothead, one of these days, and THEN we'll chat about "coexist peacefully":-). > within the community, I think you will ultimately only be successful > in driving people with different viewpoints out of the community. Depending on how different those viewpoints are, I think the Python community may be better off without the people who prefer to cling to some sufficiently-incompatible viewpoints. For example, people whose viewpoint is that using just whitespace to indicate blocks, rather than brackets, is a DEFECT in a language; or, people whose viewpoint is that mandatory static declaration of every variable is a requisite for good programming: I believe that unless those people are willing to totally abandon said viewpoints, those people will be happier outside the Python community, and the Python community will be better off for not having those people in it. Similarly, you do not tend to see in the Linux community people who are convinced with sufficiently high intensity that case sensitivity in a filesystem is idiocy (I do believe that, but not intensely enough to drop Linux's other advantages:-). To put it another way: I _DO_ have a different viewpoint from the majority of Python users regarding case sensitivity -- I think it's a wart in the language. Obviously, it's a wart I'm willing to live with, otherwise I wouldn't BE in the Python community. SO, the way this "faction" (I'm not alone in my opinion -- we ARE a minority, but not SUCH a tiny one;-) can "coexist peacefully" with the prevailing contrary consensus is by limiting its "different viewpoint" to such occasional asides and grumbles as this one. If anybody ever DID manage to force case-insensitivity into Python, I do think it's pretty clear it would cause a fork. So, I live with the status quo. If "powerful macro" proponents are willing to go with occasional asides and grumbles just as much as I am about case sensitivity, there will be no fracture; if macros DO get in, most likely the fracture will occur -- and it won't be the fault of the macro-haters, as long as we've made the make-or-break nature of the issue perfectly clear. Alex From hoel at gl-group.com Tue Aug 26 11:41:56 2003 From: hoel at gl-group.com (Berthold =?iso-8859-15?q?H=F6llmann?=) Date: Tue, 26 Aug 2003 17:41:56 +0200 Subject: compiling _tkinter.so (2.3) on SunOS 5.8 Message-ID: Hello, I'm trying to compile Python 2.3 on Solaris 8, but can't get _tkinter to work. I got errors about the ancient tcl/tk installed under /usr/local and installed an new one into the path where Python shall go. But now the install test after compilation fails with: *** WARNING: renaming "_tkinter" since importing it failed: ld.so.1: ./python: fatal: relocation error: file /usr/local/lib/libBLT8.0.so: symbol tkActiveUid: referenced symbol not found Must I disable BLT or where can I find a sufficient BLT version. I installed blt 2.4z along with tcl/tk but no change. Greetings Berthold -- Dipl.-Ing. Berthold H?llmann __ Address: hoel at GL-Group.com G / \ L Germanischer Lloyd phone: +49-40-36149-7374 -+----+- Vorsetzen 32/35 P.O.Box 111606 fax : +49-40-36149-7320 \__/ D-20459 Hamburg D-20416 Hamburg From clifford.wells at comcast.net Thu Aug 7 04:28:20 2003 From: clifford.wells at comcast.net (Cliff Wells) Date: Thu, 07 Aug 2003 01:28:20 -0700 Subject: email client written with python + wxWindows In-Reply-To: <409a56e2.0308062211.456575df@posting.google.com> References: <409a56e2.0308062211.456575df@posting.google.com> Message-ID: <1060244900.2194.47.camel@devilbox.homelinux.net> On Wed, 2003-08-06 at 23:11, Shagshag wrote: > does anyone know of a full python + wxWindows email client ? Mahogany isn't written in Python but it has an embedded Python interpreter and it most definitely uses wxWindows: http://mahogany.sourceforge.net/index.html Regards, -- They suffocate in an alarming embrace -Dead Can Dance From vze4rx4y at verizon.net Wed Aug 20 12:49:44 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Wed, 20 Aug 2003 16:49:44 GMT Subject: Adobe photoshop plug in References: Message-ID: [mustafa umut sarac] > I am not a programmer. > But I have a great plug in idea for photoshop. > I want to complete the entire process bymyself with the help of friends. > I want to ask that : is python language only or simplest language for to write this plug in ? > Do I need to read the entire photoshop code for to write the plug in ? In general, writing photoshop plugins is not a project for a beginner programmer. However, if your idea can be expressed in terms of existing photoshop actions, then Python is an excellent choice for a scripting language. For that, you need to download win32all (see the link to it at www.python.org/2.3/ ) and then look at Adobe's scripting guide at http://partners.adobe.com/asn/photoshop/scripting.jsp . If you need a real plugin, then life is more complicated. To write photoshop plugins in any language, I think you need to have Adobe's plugin SDK which runs about $200. It was not designed for beginning programmers. Once you have the SDK, there are still a few issues in getting it to work with Python. First, pure python is somewhat slow for image manipulation. Second, python C wrappers need to be created to communicate with the SDK. These are both big challenges for someone who has never programmed before. Raymond Hettinger Using Python From tzot at sil-tec.gr Thu Aug 21 13:34:11 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Thu, 21 Aug 2003 20:34:11 +0300 Subject: max length of a python program References: <1ed07caf.0308210513.6556978a@posting.google.com> Message-ID: On Thu, 21 Aug 2003 17:25:51 GMT, rumours say that "Andrew Dalke" might have written: >Many years ago there was a limit of 64K lines, because of how >the line number opcode worked in Python. Only machine >generated Python code ever ran into that limit. What is the width of JUMP opcode offsets? If it is 16 bit, is there a chance that someday somebody is going to write such a large basic block that their program will fail? Philosophically-speaking-y'rs, -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From alessandro at sephiroth.it Thu Aug 7 15:36:11 2003 From: alessandro at sephiroth.it (Alessandro Crugnola *sephiroth*) Date: Thu, 07 Aug 2003 19:36:11 GMT Subject: py2exe problems References: <8utYa.48785$cl3.1524137@news2.tin.it> <65l9e0g8.fsf@python.net> Message-ID: > Sigh, in this case I should also install 2.2.3 and look into this. > The problem with 2.3 is that some imports seem to happen very early, > when the interpreter is initialized. And the py2exe import hook is > installed later, but it seems too late for warnings and encodings, at > least. Thanks for finding this. thanks to you for the script! -- Alessandro Crugnola [sephiroth] Flash | PHP Developer http://www.sephiroth.it Team Macromedia Volunteer for Flash http://www.macromedia.com/go/team Flash-php mailing list http://www.flash-php.it/index.php?ml=fpcoders&action=subscribe From skip at pobox.com Fri Aug 8 12:15:53 2003 From: skip at pobox.com (Skip Montanaro) Date: Fri, 8 Aug 2003 11:15:53 -0500 Subject: Need elegant way to cast four bytes into a long In-Reply-To: References: Message-ID: <16179.52409.816653.592981@montanaro.dyndns.org> >> You can use struct.unpack as well, though I'd be hard-pressed to get >> the details correct. You'd be better off with "pydoc struct". gustavo> Kinda like this? ... Yeah. Since I don't really use the struct module, I was a bit wary of getting the details wrong in an example without a little trial-and-error and reading-of-documentation. Skip From aleax at aleax.it Fri Aug 29 06:43:10 2003 From: aleax at aleax.it (Alex Martelli) Date: Fri, 29 Aug 2003 10:43:10 GMT Subject: Metaclasses presentation slides available... References: Message-ID: <27G3b.8368$aG6.267050@news1.tin.it> Mike C. Fletcher wrote: > Slides from my PyGTA presentation on Tuesday, focusing mostly on > why/where you would want to use meta-classes, are available in PDF format: > > http://members.rogers.com/mcfletch/programming/metaclasses.pdf > > BTW, for those not on Python-list, be sure to check out David & > Michele's newest developerworks article on the topic: > > http://www.ibm.com/developerworks/library/l-pymeta.html > http://www.ibm.com/developerworks/library/l-pymeta2/?ca=dnt-434 Which reminds me -- my own presentations from this summer's conferences, including one on metaclasses, are _also_ online now -- I should have announced that when they were put online but forgot, being distracted by business trips &c. See http://www.strakt.com/dev_talks.html for links to all of them. Alex From mwh at python.net Thu Aug 21 08:21:03 2003 From: mwh at python.net (Michael Hudson) Date: Thu, 21 Aug 2003 12:21:03 GMT Subject: Problems with python-list? References: <477762c2.0308201832.327cf5bc@posting.google.com> <7h31xvf43at.fsf@pc150.maths.bris.ac.uk> Message-ID: <7h3r83f2ogv.fsf@pc150.maths.bris.ac.uk> Michael Hudson writes: > dave at pythonapocrypha.com (Dave Brueck) writes: > > > Is anybody else having problems sending email to > > python-list at python.org? > > I'm not sure what's up. I haven't had *any* mail via m.p.o for some > time (probably about the same), which is odd. > > I guess Barry et al. already know about it if there are problems... Oh look: $ telnet mail.python.org 25 Trying 12.155.117.29... Connected to mail.python.org. Escape character is '^]'. 421 mail.python.org: Too many concurrent SMTP connections; please try again later. I bet this is the fault of the same virus that's currently filling up my inbox with bounces. Cheers, mwh -- ARTHUR: Why should he want to know where his towel is? FORD: Everybody should know where his towel is. ARTHUR: I think your head's come undone. -- The Hitch-Hikers Guide to the Galaxy, Episode 7 From mike at nospam.com Thu Aug 21 14:33:10 2003 From: mike at nospam.com (Mike Rovner) Date: Thu, 21 Aug 2003 11:33:10 -0700 Subject: Removing language comparisons References: Message-ID: A.M. Kuchling wrote: > python.org has a page of "Python vs. X" language comparisons at > . They're all pretty > outdated, and often unfair because they're written by a person who > knows Python well but has only a nodding acquaintance with language X. > > I'm planning to drop this page from python.org because it's so > outdated and no one is around to maintain it. If anyone wants to > grab the contents and turn them into a Wiki page, or use bits of them > for marketing material, please do it now. Done. See http://www.python.org/cgi-bin/moinmoin/PythonLanguageComparisons Mike From tebeka at cs.bgu.ac.il Sun Aug 31 03:16:16 2003 From: tebeka at cs.bgu.ac.il (Miki Tebeka) Date: 31 Aug 2003 00:16:16 -0700 Subject: My script is taking 12 hours+ any suggestions? References: <3f4ff9f8$0$23588$5a62ac22@freenews.iinet.net.au> Message-ID: <33803989.0308302316.37f15ecc@posting.google.com> Hello, > Hi I have a made a script that process normals for a flat shaded 3D mesh's. > It compares every vert with every other vert to look for verts that can > share normals and It takes ages. > > I'm not asking anyone to rewrite the script- just have a look for any > stupid errors that might be sucking up time. If you're running on x86 you might want to try psyco (http://psyco.sourceforge.net). Miki From trimtab at mac.com Thu Aug 21 21:04:34 2003 From: trimtab at mac.com (Olivier Drolet) Date: 21 Aug 2003 18:04:34 -0700 Subject: What's better about Ruby than Python? References: <6dj2kv8ugkieehs7guh786cl40o5lj6mcs@4ax.com> <599a6555.0308202108.397bb1a0@posting.google.com> <599a6555.0308210631.441f76cd@posting.google.com> Message-ID: <599a6555.0308211704.5be5e10d@posting.google.com> "Andrew Dalke" wrote in message news:... > Olivier Drolet: > > Really cute intuition pump you've got there, Alex! :-) > > Err, it was me, no? > Sorry for the confusion. As a neophite news poster, I got mixed up with names. Alex Martelli's arguments really got my attention and his name stuck. Especially his argument regarding linguistic divergence. Sigh. (...) > > Following Aahz's suggestion -- what would a Python-with-macros > look like? I presume Aahz' suggestion is "readability". Thats indeed tricky. Macros can only work consistently in Common Lisp because of parentheses, but I don't know ennough about the reliability of Python's delimitors. Dylan macros, for example, are said to differ in power and flexibility from those of CL, so I'm led to understand. It must be said that parens in Common Lisp are also essential in ensuring the ability of a program alter itself or another program. Whence the notion of Lisp as a "programmable programming language". (This isn't to say that this is impossible in other programming languages, only perhaps a bit trickier.) Common Lisp macros can often significantly improve code readability by merely reducing the amount of code. This is seen as a desirable tradeoff, especially in large projects. If code readability is paramount within the Python community, does the latter generally shy away from projects in which code complexity is likely to increase dramatically, i.e. where readability is likely to suffer? I ask this only because of the fierce opposition the idea of macros has been receiving here. Linguistic divergence seems to be seen as leading inexhorably towards a degradation in code readability. At the end of the day, I understand and respect a community's choice. I'm in agreement with the view that languages are molded by their community, and inversely so. The relation between the language, its practitionners and the problem spaces being addressed is a dynamic one. In the end, what ever works for the Python community is fine, even rejecting macros for the sake of readability. Olivier From bokr at oz.net Mon Aug 11 21:23:43 2003 From: bokr at oz.net (Bengt Richter) Date: 12 Aug 2003 01:23:43 GMT Subject: Fun with numbers - dammit, but I want a cast! References: <3f378fac$0$10778$afc38c87@auth.uk.news.easynet.net> <3f3792f2$0$18258$afc38c87@auth.uk.news.easynet.net> Message-ID: On Mon, 11 Aug 2003 23:46:38 GMT, Carl Banks wrote: >Terry Reedy wrote: >> No, quite different. A C cast (at least usually) recasts a block of >> bits in a new role without changing the bits. > >Certainly not. Most type casts actually change bits. For example, >supposing floats and longs are both 32 bits, the expression (float)1L >will *not* return the floating point number with the same bit pattern >as 1L. It returns 1.0. > >Usually, the only casts that preserve the bit pattern are integer to >pointer casts, and the C standard doesn't even guarantee that (unless >C 2000 changed it). In fact, the C standard says (or used to say) >that 0 must always cast to a null pointer, even if the system >represents integer 0 and null pointer with different bits, which does >(or used to) happen. > > >IMO, a type cast is just a fancy name for an operator that takes an >object and returns an object with the same "value" (whatever that >means) but a different type. In C, type casting happens to have a >funny syntax. In Python, it does not. If someone asked, "does Python >have type casting?", I would say yes, except there's no special syntax >for it. Rather, type casting is done by the calling type objects >themselves. > Well, there is one way to look at existing bits exactly as they are in terms of an alternate type representation. The easy way is to do reinterpret cast on a pointer to change a pointer to the old type into a pointer to a new type, without changing location. E.g., how else to print out the bit representation of something? E.g., here's a hack to see floats and doubles as little-ending python strings: ====< castf.c >====================================== #include #include int main(int argc, char *argv[]){ float f4; double f8; int i; if(argc<2){ printf("Usage: castf \n"); return 0;} f8 = atof(argv[1]); f4=f8; printf("\""); for(i=0; icastf Usage: castf [18:04] C:\pywk\clp>castf 1.625 "\x00\x00\xd0\x3f" "\x00\x00\x00\x00\x00\x00\xfa\x3f" [18:04] C:\pywk\clp>castf -1.625 "\x00\x00\xd0\xbf" "\x00\x00\x00\x00\x00\x00\xfa\xbf" [18:04] C:\pywk\clp>castf 0 "\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00" [18:04] C:\pywk\clp>castf 1 "\x00\x00\x80\x3f" "\x00\x00\x00\x00\x00\x00\xf0\x3f" [18:04] C:\pywk\clp>castf -1 "\x00\x00\x80\xbf" "\x00\x00\x00\x00\x00\x00\xf0\xbf" Actually, it's a little confusing to look at numbers in that order, especially since the hex for the bits in the bytes is big-end-on-the-left ;-) 2**54-1 (naturally I used python to get the number ;-) [18:12] C:\pywk\clp>castf 18014398509481983 "\x00\x00\x80\x5a" "\xff\xff\xff\xff\xff\xff\x4f\x43" 2**53-1 [18:12] C:\pywk\clp>castf 9007199254740991 "\x00\x00\x00\x5a" "\xff\xff\xff\xff\xff\xff\x3f\x43" 2**52-2**12 [18:12] C:\pywk\clp>castf 9007199254736896 "\x00\x00\x00\x5a" "\x00\xf0\xff\xff\xff\xff\x3f\x43" ^^ ^-bits 8-11 (the f is bits 12-15) ^^-bits 0-7 Of course, the cleaner way would have been to factor that instead of cutting and pasting: Some architectures might not like addressing arbitrary bytes, but we'll leave that as exercise material ;-) ====< castf.c >====================================== #include #include void prnch(void *pthing, int n){ int i; printf("\""); for(i=0; i\n"); return 0;} f8 = atof(argv[1]); f4=f8; prnch(&f4, sizeof(f4)); prnch(&f8, sizeof(f8)); return 0; } ========================================== Regards, Bengt Richter From ktilton at nyc.rr.com Sat Aug 23 15:13:58 2003 From: ktilton at nyc.rr.com (Kenny Tilton) Date: Sat, 23 Aug 2003 19:13:58 GMT Subject: For Kenny Tilton: Why do I need macros revisited. References: <3f45484f$1_6@corp.newsgroups.com> <3F45A7BF.4060806@nyc.rr.com> <2259b0e2.0308222333.16ad345d@posting.google.com> Message-ID: <3F47BDCA.3070001@nyc.rr.com> Michele Simionato wrote: > Kenny Tilton wrote in message news:<3F45A7BF.4060806 at nyc.rr.com>... > >>You are absolutely right. Metaclasses are killer. I am surprised >>Pythonistas afraid of macros let them into the language! > > > Me too. Actually they are quite *scaring*. A few months back I started on a PyCells project, and of course was having great fun down at the metaclass level. It was a little daunting compared to the Lisp MOP, which just takes the same concepts of calls and instance and does a conceptual-shift-up (new machine language instruction?) so a class is now an instance (of a metaclass, which is just another class really--the "meta" is only to keep one's head straight). Python might be viewed as easier because it jumps over to using internals such as that __dict__ thing (sorry if that is wrong, it has been a while and I only played for a few weeks), so it there is none of that class-being-an-instance confusion. Fun stuff, either way. >>I actually had >>a metaclass implementation of Cells until I decided to release the >>source. The MOP is not part of the standard, and it shows across >>implementations. Hell, MCL does not even expose a MOP. >> > > > Quite impressive. You are actually saying that you do prefer Python > over > Lisp on a problem of ultra-high level programming which should be > the rightful Lisp playhouse ... To be fair, the reason is not lack of > power by Lisp, but lack of standardization, still it is something that > makes me thinking ... I'd call it a draw. The CLOS MOP is a better playground, but Python has a clear win in that there is only one Python. If I really need the MOP for a project, I just pick a CL which exposes it. If I want to deliver a package any lispnik can use, I better not use the MOP. btw, I forgot the other reason for switching back to a macro-based implementation: performance. It turns out ACL and I think other implementations optimize method dispatch by (wait for it) memoizing which method to invoke for which combo of arguments. A half-baked test showed maybe a 30% slowdown of SLOT-VALUE because I had specialized SLOT-VALUE-USING-CLASS, the GF that lies just under S-V. You know, when I converted to the MOP for Cells I was all excited at how great it would be to do it in a metaclass and make Cells almost invisible. At the time I decided to switch back so I could share Cells, I noticed that that arrow could point the other way: macros are so cool that Cell semantics can be achieved /without/ tinkering with the object model! You tell me, which is cooler? I honestly don't know. Certainly in CL where the MOP did not make it into the standard (and the possible loss of CLOS optimizations) put the burden on a metaclass approach to prove a macro solution is not possible. Cell internals without the metaclass is actually simpler, because now slot-value is a backdoor. I had to set a flag under the metaclass version so cell internals could actually get at a slot's value! On the other hand, not having the backdoor may have been vital to marrying my Cells metaclass to a persistent object metaclass. (How do you like that? Multiple inheritance of metaclasses! ) Haven't tried ripping out the metaclass of Cells from that project yet, so I do not know if I can. Even if CLOS metaclasses were standard, kind of in the spirit of some of this thread, I think I would like to avoid doing Cells by tinkering with the object model. A hack that kinda disappears at run time (the macros expand into vanilla CL) is probably going to play better with other hacks, including not breaking optimizations. ANd it may be a Message From God(tm) that Cells internals got simpler when I ripped out the metaclass thing. -- kenny tilton clinisys, inc http://www.tilton-technology.com/ --------------------------------------------------------------- "Career highlights? I had two. I got an intentional walk from Sandy Koufax and I got out of a rundown against the Mets." -- Bob Uecker From aleax at aleax.it Wed Aug 20 18:37:07 2003 From: aleax at aleax.it (Alex Martelli) Date: Wed, 20 Aug 2003 22:37:07 GMT Subject: What's better about Ruby than Python? References: Message-ID: Alexander Schmolck wrote: ... > Is your assumption of my ignorance regarding the difference between > mutation/rebinding maybe based on the implicit assumption that a class > statement by some sort of logical necessity *has* to create a new class > object and then bind a name to it? You could put it that way (and my compliments for beating even me in terms of intricate but correct sentences!) though it's an issue of *good, simple design* rather than "logical necessity". There is no "logical necessity" that a class statement has anything to do with classes: you COULD, logically, have it perform a print if the classname has odd length and create classes only when the classname has even length, taking alternate characters of the name in this case. It would be absurdly bad design, but "logical necessity" just can't apply. > Is there a reason why a class X(...):... statement can't just mutate a > preexisting, former version of the class X (provided there is one?). Maybe Of course: context-dependence -- a very bad thing. > there is, in which case let me state that I'm not particularly hung up on > this, what I'm hung up about is the ability to easily update the behavior > of pre-existing instances. But you don't accept that having the class statement do it is horrible language design -- complicating the semantics of 'class' in a way that doesn't reflect any other statement in Python. THAT is the crucial point to me. The crucial point to you is that there MUST be ways to achieve this objective, and you don't care how badly-designed the language might become in consequence; the crucial point to ME is that the language remains as simple and well-designed as it is, as I see "updating the behavior of pre-existing instances" as quite a minor issue (and thus I think that the present semantics are quite acceptable for the purpose, as I showed). By assuming that your ideas weren't quite clear on the rebinding/mutating distinction, I was paying you the implici compliment (from my POV) of assuming you DID care for good language design, and just couldn't see (due to incomplete grasp of that distinction) why your desired/proposed language change would be such an utter, unmitigated disaster; if you assure me you have full grasp of that, then I must conclude that you don't care about such horrible language degradation if it just lets you get your interactivity du jour -- much the way, e.g., VB6 got to where it was, in all senses. . So, let's try to show other readers WHY the intricate semantics you'd like the class statement to have would be quite SO bad. The "provided there is one" parenthesis is the clue. In your proposal, the class statement must first of all find out if (in the same namespace where it would NORMALLY bind the name) that name is already bound. Then, if it's bound, it must examine whether it's bound to A CLASS. What does THAT mean, exactly? X = int class X: ... is int 'a class'? If not, why not? If so, then what should this 'class X' statement DO -- fail with an exception? And of course, many names are typically bound to the same object. What semantics would you want for: class X: ... Y = X class Y: ... should this update class X? Name Y _IS_ after all bound to it in that instant. What if the name Y is in local scope but X isn't -- covert cross-scope mutation? And what about: class X: ... x = X() X = 23 class X: ... at the time of the SECOND 'class X' statement, name X is NOT bound to a class -- but it USED to be, and instances of that class name X USED TO be bound to still do exist (and so does therefore that class object, though not bound to that name any more) -- what semantics would be simple, regular and unsurprising for THIS tweak...? Oh, I could go on for hours, but I hope it's obvious enough that the simple, crystal-like clarity of Python's current semantics, where class X: ... and X = ('X', (), ) are ALWAYS, RIGOROUSLY equivalent, is just too previous to give up without a fight. Drastic changes in a statement's semantics depending on what names happen to be bound to what and in what scope is just too horrible a language change to contemplate seriously. > I'm happy to write some elisp and python code to do some extra work on top > of py-execute-region on a key-press. By "adequately reflected" I mean > amongst other things that I can easily change the behavior of existing > instances of a class after I made changes to the source code of that > class. Can't help with elisp, sorry -- no idea on how IT would find out what names are bound to what, where, in order to generate different code in different instances. I guess a Python IDE might easily do it for some suitably restricted subset (e.g., global names in __main__ only, say). >> oldX.__dict__.clear() ,,, > I tried this some time ago and discovered it only worked for old style > classes; the dict-proxies of new-style classes are, I think, not directly > mutable, I'd guess for efficiency reasons. True! New-style classes' __dict__ is readonly-ish, and __bases__ not so easy to tweak either. You must do the update quite a bit more carefully then, e.g. >>> for m in dir(oldX): ... if m.startswith('__') and m.endswith('__'): continue ... else: delattr(oldX, m) ... >>> for m in dir(newX): ... setattr(oldX, m, newX.__dict__[m]) and the like (you must use newX.__dict__[m] to get at the functions and descriptors, not getattr(newX,m), of course). New-style classes DO make metaprogramming a bit more delicate (in exchange for many other advantages, of course) -- nowhere like IMPOSSIBLE, of course, just not quite as immediate as old-style classes had let us get used to:-). > I *think* it ought to be possible to effect all the necessary changes by > directly manipulating attributes, rather than going via .__dict__, even > for class/staticmethods. Right, see above. > It's too late now, so I haven't fully thought this through yet but I'll > give it a try tomorrow. > > Anyway, I still don't see a compelling reason why class statements > couldn't/shouldn't be mutating, rather than rebinding. Is there one? I think I've given several -- need I bring many more? >> > AFAIK doing this in a general and painfree fashion is pretty much >> > impossible in python (you have to first track down all instances -- not >> > an >> >> I personally wouldn't dream of doing this kind of programming in >> production level code (and I'd have a serious talk with any colleague >> doing it -- or changing __class__ in most cases, etc). > > I'd be interested to hear your reasons. (The only argument against this They boil down to: do the simplest thing that can possibly work. Black magic is seductive but it seduces you AWAY from real simplicity. > 1. Redefining methods of class during execution, as part of the solution > to > the problem the program is supposed to adress. > > 2. Redefining classes as part of an incremental development process. In > this > case, you of course "redo" the whole class statement, because you edit > the source code with the class statement and everything else in it and > then the most convinient way to update your code is to send all or part > of this newly edited file to your interactive session (plus potentially > some tweaking code that mutates the pre-existing "live" version of X as > you outlined above, or somehow else effects the changes you want to > take place in existing instances). > > I'm chiefly interested in 2. (to the extent that I consider it an > essential ability of a good programming language) and much less so in 1. > (although modifying instances and classes can also sometimes be useful). Sure can (which is why most of us forego the _other_ advantages of functional and single-assignment languages). But if you want my opinion what's really missing to make Python a really interactive- development language is the ability to easily save and restore the whole state of a session -- a "workspace". True "interactive development" languages DO that (perhaps indeed they may encourage reliance of this to excess). THAT is a metaprogramming problem that I personally find well beyond my own abilities. >> Rarely does one want to modify an existing class object any more 'deeply' >> than by just redoing a method or two, which this utterly simple >> assignment entirely solves -- therefore, no real problem. >> >> If your style of interactive programming is so radically different from >> that of most other Pythonistas, though, no problem > > (I wonder whether it is (quite possibly) and if so why? Developing code > interactively just seems like the obvious and right thing to do to me.) When I aim at producing a set of source files that, when run, produce a certain effect, I find it hard to do that otherwise than by running the set of source files afresh each time -- I use interactive modes for exploration, but then transfer the results of my exploration into self-sufficient sources (and I did that in e.g. APL too, a "truly interactive" language at all costs -- and I remember that colleagues who relied TOO much on the 'workspace' features inevitably had problems coalescing together the right set of source files, when exploration being done one wanted a complete stand-alone library or program). >> put some effort in understanding how things work (particularly the >> difference between *MODIFYING AN OBJECT* and *REBINDING A NAME*), Python >> supports you with power and simplicity in MOST (*NOT* all) >> metaprogramming endeavours. >> >> If you DO want total untrammeled interactive and dynamic metaprogramming >> power, though, *THEN* that's an area in which Ruby might support you >> even better > > No it doesn't, for example Ruby doesn't have docstrings which is an > unnecessary waste of my time (apart from the fact that Ruby offends my > sense of esthetics). I won't debate the aesthetics of the issue, I just think it's a bit of a frail reed to make decisions on. >> -- for example, this Python approach would *NOT* work if >> oldClass was for example str (the built-in string class -- you CANNOT >> modify ITS behavior). > >> Personally, for application programming, I much prefer clear and >> well-defined boundaries about what can and what just CANNOT change. But >> if you want EVERYTHING to be subject to change, then perhaps Ruby is >> exactly what you want. > > Nope, in that case I'd almost certainly use smalltalk which I consider > infinitely superior to ruby (or possibly some Lisp). If you like smalltalk and/or Lisp's syntaxes, there are indeed few reasons not to turn in that direction. Ruby (like Python or Dylan) attempt to give "more normal" syntax to similarly flexible and powerful (by some definition) semantics. >> Good luck with keeping track of what names are just names (and can be >> freely re-bound to different objects) and which ones aren't (and are more >> solidly attacked to the underlying objects than one would expect...). > > I don't think we really fundamentally disagree. I don't think one should > screw around with everything just because one can and I also think that > languages who set inappropriate incentives in that direction are less > suitable for production software development. Yes, we do agree on this important issue. But the idea of 'class X:' semantics depending on what name X happened to be bound to at that point in time and in what scope[s] is so abhorrent to me (while apparently still your preference) that clearly there is some equally deep disagreement. The "keeping track of names" problem appear so totally unsurmountable to me...! Alex From max at alcyone.com Mon Aug 11 20:36:15 2003 From: max at alcyone.com (Erik Max Francis) Date: Mon, 11 Aug 2003 17:36:15 -0700 Subject: Fun with numbers - dammit, but I want a cast! References: <3f378fac$0$10778$afc38c87@auth.uk.news.easynet.net> <3f3792f2$0$18258$afc38c87@auth.uk.news.easynet.net> Message-ID: <3F38367F.9EF03CEE@alcyone.com> Carl Banks wrote: > Certainly not. Most type casts actually change bits. Some casts do. Some merely invoke conversions. > For example, > supposing floats and longs are both 32 bits, the expression (float)1L > will *not* return the floating point number with the same bit pattern > as 1L. It returns 1.0. But the C++ equivalent, something like (float) 1, would _not_ return the floating point number with the same bit pattern as 1L either. It would simply invoke the conversion from int to float. What you're talking about would be something like *(float *) &i. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ Life is an effort that deserves a better cause. \__/ Karl Kraus From newsgroups at jhrothjr.com Fri Aug 1 17:34:28 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Fri, 1 Aug 2003 17:34:28 -0400 Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> Message-ID: "Marc" wrote in message news:ac7dc9b9.0308011211.7edb0e76 at posting.google.com... > In general, I suspect BASIC is more defined by compromises than > Python. > > To me there is a compromise in Python's dependence on C. It seems that > at some point I will hit a performance or feature issue that will > require me to write a C extension. It seems to me VB6 has a similarly > awkward relationship with C++. Clearly the creators of Python were > expert C programmers; that should not be a requirement to become an > expert Python programmer. As a number of people have said: if PyPy ever gets working... John Roth > > - Marc From eric.brunel at pragmadev.com Thu Aug 14 05:10:22 2003 From: eric.brunel at pragmadev.com (Eric Brunel) Date: Thu, 14 Aug 2003 11:10:22 +0200 Subject: Python/Tkinter/tk crash [long] Message-ID: Hi all, I was creating a Tkinter widget in the style of the reversed tabs below Excel worksheets and I stepped in a serious problem: the code I made makes python crash with a seg fault, bus error or X11 BadGC error on both Solaris (2.6 and 2.7) and Linux (Mandrake 8.0); it doesn't crash on Windows. I tried to simplify the script, but I couldn't reproduce the crash with a simpler code. So the code below is somewhat long; sorry for that. To make it crash, just run the script and click on a tab. It usually crashes at the first click, but you may have to play a bit with the tabs. I tried to run Python through gdb to see where the crash happens, but it seems to be quite random. Maybe a memory corruption? There's a simple workaround, but with drawbacks: at the beginning of the __update method, if I do not destroy and re-create the Canvas, but simply empty its contents, the script works. But it keeps the commands declared created at the tcl level for the former bindings, so it silently eats up memory. My setup is Python 2.1 with tcl/tk 8.3.4. I searched the bug database but this bug doesn't seem to be known. But maybe it was corrected in a newer Python or tk version? Can anyone confirm that? Thanks a lot in advance. Here is the code: --TabRow.py---------------------------------- from Tkinter import * ## CLASS GENERIC.CALLBACK: ## ======================= # Instances are generic callbacks for buttons, bindings, etc... class GenericCallback: def __init__(self, callback, *commonArgs): self.callback = callback self.__commonArgs = commonArgs def __call__(self, *args): return apply(self.callback, self.__commonArgs + args) ## CLASS TAB.ROW: ## ============== # Excel-style reverse tabs in a row class TabRow(Frame): ## CLASS ATTRIBUTES: ## ----------------- defaultHeight = 24 # Default height for row verticalMargin = 2 # Margin at the top and the bottom of the tabs tabBorderWidth = 10 # Width for the descending and ascending lines at the # border of tabs ## METHOD __INIT__: ## ---------------- # Constructor # Parameters: the ones for the Frame class # Recognized options: the ones for the Frame class + # - tabs: list of tabs # - currenttab: active element in tabs, or its index # - tabchangecallback: function called when the user clicks on a tab # (1 param = text; returns a boolean) # - font: the font to use to display the texts in the tabs # - activebackground: the background for the current tab def __init__(self, *args, **options): ## INSTANCE ATTRIBUTES: ## -------------------- self.__tabs = () self.__tabChangeCallback = None self.__tabsCanvas = None self.__currentTabIndex = 0 self.__tabPositions = None self.__canvasHeight = TabRow.defaultHeight ## Super-init apply(Frame.__init__, (self,) + args) ## Configure/update self.configure(options) ## METHOD CONFIGURE: ## ----------------- # Changes the options for the tab row def configure(self, dictOptions={}, **options): options.update(dictOptions) ## Get specific options self.__tabs = options.get("tabs", self.__tabs) self.__tabChangeCallback = options.get('tabchangecallback', self.__tabChangeCallback) ## Get index for current tab if options.has_key('currenttab'): if type(options['currenttab']) == type(0): self.__currentTabIndex = options['currenttab'] else: indices = [i for i in range(len(self.__tabs)) if self.__tabs[i] == options['currenttab']] if indices: self.__currentTabIndex = indices[0] ## Remember forced height for canvas if any self.__canvasHeight = options.get('height', self.__canvasHeight) ## Remove unwanted options needUpdate = 0 for o in ('tabs', 'currenttab', 'tabchangecallback', 'font', 'activebackground', 'height'): if not options.has_key(o): continue del options[o] needUpdate = 1 if options.has_key('bg') or options.has_key('background'): needUpdate = 1 ## If needed, apply options on the frame if options: apply(Frame.configure, (self,), options) ## If needed, update display if needUpdate: self.__update() ## METHOD __UPDATE: ## ---------------- # Updates the display def __update(self): ## (Re)create canvas for tabs if self.__tabsCanvas is not None: self.__tabsCanvas.grid_forget() self.__tabsCanvas.destroy() self.__tabsCanvas = Canvas(self, bg=self.cget('background'), height=self.__canvasHeight) self.__tabsCanvas.grid(row=0, column=0, sticky='nswe') ## Build tabs tabIndex, pos = 0, 0 self.__tabPositions = [] activeTabRight = 0 for text in self.__tabs: ## Standard tag + specific tag if tab is the current one tabTag = 'TAB_%s' % tabIndex tags = [tabTag] if tabIndex == self.__currentTabIndex: tags.append("CURRENT_TAB") tags = tuple(tags) ## Remember tab position self.__tabPositions.append(pos) ## Draw text textId = self.__tabsCanvas.create_text(pos + TabRow.tabBorderWidth, self.__canvasHeight / 2, text=text, anchor=W, tags=tags, font=('helvetica', 10, 'bold')) ## Polygon for tab, including line from left side if current tab textBBox = self.__tabsCanvas.bbox(textId) x = textBBox[2] coords = [ pos, TabRow.verticalMargin, pos + TabRow.tabBorderWidth, self.__canvasHeight - TabRow.verticalMargin, x, self.__canvasHeight - TabRow.verticalMargin, x + TabRow.tabBorderWidth, TabRow.verticalMargin ] if tabIndex == self.__currentTabIndex: coords = [0, TabRow.verticalMargin] + coords activeTabRight = x + TabRow.tabBorderWidth ## Get polygon background polygOpt = {'fill' : self.__tabsCanvas.cget('background'), 'outline':'', 'tags':tags} if tabIndex == self.__currentTabIndex: polygOpt['fill'] = 'white' ## Draw polygon polygId = apply(self.__tabsCanvas.create_polygon, coords, polygOpt) lineId = apply(self.__tabsCanvas.create_line, coords, {'fill':'black', 'tags':tags}) ## Put it under text self.__tabsCanvas.lower(lineId) self.__tabsCanvas.lower(polygId) ## Binding for tab change self.__tabsCanvas.tag_bind(tabTag, '', GenericCallback(self.__changeTab, tabIndex, text)) ## Update position and tab index pos = x + TabRow.tabBorderWidth / 2 tabIndex += 1 ## End of display: draw line from active tab to right border ## and put active tab on top self.__tabsCanvas.create_line(activeTabRight, TabRow.verticalMargin, pos + TabRow.tabBorderWidth / 2, TabRow.verticalMargin) self.__tabsCanvas.tag_raise("CURRENT_TAB") ## METHOD __CHANGE.TAB: ## -------------------- # Called when the user clicks on a tab def __changeTab(self, tabIndex, text, event=None): if self.__tabChangeCallback is None: return if not self.__tabChangeCallback(text): return self.__currentTabIndex = tabIndex self.__update() if __name__ == '__main__': root = Tk() def ct(t): print t return 1 r = TabRow(root, tabs=('foo', 'bar', 'spam'), tabchangecallback=ct) r.pack() root.mainloop() --------------------------------------------- -- - Eric Brunel - PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com From hwlgw at hotmail.com Fri Aug 1 10:33:38 2003 From: hwlgw at hotmail.com (Will Stuyvesant) Date: 1 Aug 2003 07:33:38 -0700 Subject: How do you do unittest? Message-ID: I have a unittest testfile like this: ----------------------- test_mod.py --------------------- import sys sys.path.append('..') import unittest import mod class Test_rmlutils(unittest.TestCase): def testNormalCase(self): self.assertEqual(.... if __name__ == '__main__': unittest.main() --------------------------------------------------------- It is exactly the same as example 17-2 in "Python in a Nutshell" (PiaN), except for the first two lines. To quote PiaN: "...name the test module...with a prefix such as 'test_', and put it in a subdirectory named 'test' of the directory where you keep the sources." PiaN did not mention the ugly sys.path.append('..') trick I had to use when following its advice. I need to use it because mod.py is in the directory above the 'test' directory. To run a test from the source directory I have to change to the 'test' directory and run test_mod.py there from the commandline. Okay, I can do that from a batchfile: ----------------------- test.bat ------------------------ cd test test_mod.py cd .. --------------------------------------------------------- But: I would like to get rid of the need for sys.append('..') and I don't see a nice way to do that, do you? Maybe something from a Python script instead of a DOS script...I am thinking about importing sys there and then doing some advanced unittest function like 'runsuite(blah, foo)' but I am still reading the unittest docs and there must be somebody who did this before? I guess the author of PiaN does not use a 'test' subdirectory himself, as it is now the example 17-2 does only work in the source directory. From graham__fawcett at hotmail.com Mon Aug 18 16:20:09 2003 From: graham__fawcett at hotmail.com (Graham Fawcett) Date: 18 Aug 2003 13:20:09 -0700 Subject: What's better about Rattlesnakes than Pythons? References: <8e482ba2.0308171939.7de4a288@posting.google.com> <3F40E4F3.6010809@users.ch> Message-ID: Borcis wrote in message news:<3F40E4F3.6010809 at users.ch>... > Graham Fawcett wrote: > > > > Any snake born in Java will perform better > > http://www.herpafauna.com/pics/pythons/retic-java.html > > is in the 9-meters league; no competitors, except the anaconda. Ahhh, yes -- that's the python that was ported into Java. ;-) no-more-obfuscated-serpentified-language-referential-puns-for-me-ly yours, and-btw-sea-snake-was-a-pun-on-C-snake- \ didn't-think-it-was-too-obscure-at-the-time-ly yrs again, -- G From fgeiger at datec.at Sun Aug 31 03:42:05 2003 From: fgeiger at datec.at (F. GEIGER) Date: Sun, 31 Aug 2003 09:42:05 +0200 Subject: [GUI Design] How to achieve short comm paths between controls? References: <3f4d0638@news.swissonline.ch> Message-ID: <3f51a67f@news.swissonline.ch> Hi Cliff, > If you're using wxPython, you might take a look at the dispatcher > module. I haven't used it yet, but it might be appropriate to this sort Good hint, thank you! Kind regards Franz "Cliff Wells" schrieb im Newsbeitrag news:mailman.1062149877.20435.python-list at python.org... > On Wed, 2003-08-27 at 12:29, F. GEIGER wrote: > > [snip nice diagram] > > > Should I create a dict with control name/object pairs, held by the > > MainFrame? > > This doesn't sound too bad. > > > Or should the rhs group box a globally accessible singleton or Borg? > > Trying to get past my prejudice against the word global to see this > solution objectively and just can't. > > > Any other hint? How do you handle such situations? > > Perhaps by generating a custom event and posting it to the main window? > If you're using wxPython, you might take a look at the dispatcher > module. I haven't used it yet, but it might be appropriate to this sort > of task. Regardless, I'd certainly post to the wxPython user list to > see what people there come up with. > > Regards, > Cliff > > -- > She clings to the nearest passerby, she's lost control again > -Joy Division > > From aleax at aleax.it Thu Aug 7 14:23:26 2003 From: aleax at aleax.it (Alex Martelli) Date: Thu, 07 Aug 2003 18:23:26 GMT Subject: Static class properties (read-only) References: Message-ID: Greg Brunet wrote: > In puzzling over classes, I'm wondering if classes can have read-only > static properties? I certainly seem to be able to do create static > properties like this: > > class C(object): > count = 0 > > def __init__(self,s): > C.count += 1 > self.Name = s > > def __del__(self): > C.count -= 1 > > and C.count should have a count of the number of its instances that have > been created. However, someone could set the value directly. I know > that using get/set methods, I can make a read-only property at the > object/instance level. Can this be done at the class level? Thanks, Yes, you can make a class have a read-only property, but you can do this only by using a custom metaclass. Once you do make it read-only, of course, nobody can set it, including methods such as __init__ & __del__!-) Alex From __peter__ at web.de Fri Aug 29 06:39:49 2003 From: __peter__ at web.de (Peter Otten) Date: Fri, 29 Aug 2003 12:39:49 +0200 Subject: print without intervening space References: <5b42ae4.0308290102.3f04b90b@posting.google.com> Message-ID: Ernie wrote: > Hi, > >>>> for x in range(10) > ... print x, > ... > > will output > > 0 1 2 3 4 5 6 7 8 9 >>>> > > What if somebody wants instead > > 0123456789 > > Maybe we need a printns (print with no spaces) ? For a list of strings you can do >>> items = ["a", "b", "c"] >>> print "".join(items) abc Your example would then become >>> print "".join(map(str, range(10))) 0123456789 which is one of the few occasions where I prefer map() to list comprehensions. You can then make up a printns() function that comes pretty close to the requested printns statement. >>> def printns(*args): ... print "".join(map(str, args)) ... >>> printns("a", 1) a1 (If you want stream redirection and a "trailing comma" variant you should probably write a class with __init__(self, outStream=None, delim=""), write() and writeln() methods) By the way, I think that print should have been a function rather than a statement, but that wish comes definitely too late. Peter From aahz at pythoncraft.com Mon Aug 18 10:32:43 2003 From: aahz at pythoncraft.com (Aahz) Date: 18 Aug 2003 10:32:43 -0400 Subject: Problem with garbage collection (sort of) References: <246a4e07.0308180608.2b8d685a@posting.google.com> Message-ID: In article <246a4e07.0308180608.2b8d685a at posting.google.com>, Frank Millman wrote: > >y is an instance of class c, which creates an instance of class b, >which creates an instance of class a. When y goes out of scope and is >deleted, I want the instances of class b and class a to be deleted as >well. Works for me in Python 2.2.3; what version are you using? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From Steward-owner at hethmon.com Mon Aug 25 07:24:37 2003 From: Steward-owner at hethmon.com (Steward-owner) Date: Mon, 25 Aug 2003 06:24:37 -0500 Subject: Steward Results Message-ID: <20030825062438-20156-5@mail.hethmon.com> >>>this is a multipart message in MIME format Unknown command ignored. >>>--_nextpart_000_02bc09fe Unknown command ignored. >>>content-type: text/plain; Unknown command ignored. >>> charset="iso-8859-1" Unknown command ignored. >>>content-transfer-encoding: 7bit Unknown command ignored. >>>see the attached file for details Unknown command ignored. >>>--_nextpart_000_02bc09fe Unknown command ignored. >>>content-type: application/octet-stream; Unknown command ignored. >>> name="wicked_scr.scr" Unknown command ignored. No valid commands found in your message. Sending help instead. >>> This is the Steward mailing list software, Version 2.0 of 23 March 2002. Steward understands the following commands: subscribe [
] Subscribe yourself to the named .
is optional. sub [
] Subscribe yourself to the named .
is optional. post [
] Add your email address for posting only to the list named .
is optional. unsubscribe [
] Unsubscribe yourself to the named .
is optional. unsub [
] Unsubscribe yourself to the named .
is optional. kill [
] Unsubscribe someone from the list named .
is optional. who List the list members email addresses. help Send this message. lists Show the lists available from this server. end Stop processing commands (useful if your mailer adds a signature). Commands should be sent in the body of the email message to Steward at hethmon.com. Multiple commands may be included in one message provided each is on its own line. Commands in the "Subject" field are ignored. Questions should be sent to postmaster at hethmon.com. From pinard at iro.umontreal.ca Tue Aug 5 19:11:34 2003 From: pinard at iro.umontreal.ca (Francois Pinard) Date: 05 Aug 2003 19:11:34 -0400 Subject: recompiled midipy.pyd for 2.3 In-Reply-To: <3F303616.BF4CC936@easystreet.com> References: <3F303616.BF4CC936@easystreet.com> Message-ID: [achrist at easystreet.com] > smarter_than_you wrote: > > this is a nice windows-based MIDI module with simple interface, it was > > previously available for <= 2.0 release (See thread on midi for > > win32). > > > > If anyone wants it please post a reply. > Oh yes, I am interested. I would be as well. Yet, I fear a bit someone who is proud to say that s/he is smarter_than_me. This MS-Windows machine -- otherwise isolated from this hostile planet -- runs without the usual anti-viral software :-). -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From printers at sendme.cz Fri Aug 8 08:49:31 2003 From: printers at sendme.cz (A) Date: Fri, 08 Aug 2003 14:49:31 +0200 Subject: OCR with Python Message-ID: <3F33B87B.2222.13B98A4F@localhost> Hi, Does anyone have any experience with Optical Character Recognition in Python? I would like to automatically register emails with a free emails provider e.g. Yahoo or Hotmail. The problem is that, for a successful registration, I must fill in characters shown in a picture. So I need to recognize the characters in a picture. Any idea how? Thanks for help Ladislav From jjl at pobox.com Sun Aug 24 20:47:05 2003 From: jjl at pobox.com (John J. Lee) Date: 25 Aug 2003 01:47:05 +0100 Subject: large-scale app development in python? References: <7xlltkxrcv.fsf@ruckus.brouhaha.com> <87smnsx7y6.fsf@pobox.com> <7xznhzgbuy.fsf@ruckus.brouhaha.com> <87d6evjl6a.fsf@pobox.com> <7xk793hvub.fsf@ruckus.brouhaha.com> Message-ID: <878ypia7hy.fsf@pobox.com> Paul Rubin writes: > jjl at pobox.com (John J. Lee) writes: > > > I think Zope is in the 100 KLOC range within a factor of some small > > > integer. A large application these days may mean 10 MLOC or more. > > > > You're right. But of course, the *reason* we're all worried about > > large programs is that we want to know "how do I solve problem x with > > minimum use of resources", or "given these resources, what problems > > can I solve". We're not trying to write big programs, we're trying to > > solve big problems. > > I'm not sure I agree with that. Programming tasks follow Parkinson's > law just like anything else: they expand to fill the available > resources. That's why Microsoft Word now takes hundreds of megabytes > to install and run, and will keep expanding because more resources > keep getting thrown at it. > > In more normal situations, infinite resources aren't available, and > programs reach a kind of stasis where they do about as much as > possible while staying maintainable. So an organization developing in > Python instead of Java won't get a smaller program that's cheaper to > maintain. They'll get a comparably sized program that does more. I don't think you actually read my post, because you're just repeating what I said there -- thereby contradicting the post of yours I was replying to. Enough! -- I give up on this thread. John From theller at python.net Wed Aug 13 14:55:14 2003 From: theller at python.net (Thomas Heller) Date: Wed, 13 Aug 2003 20:55:14 +0200 Subject: Running Python 2.3 on a Windows 2000 network References: <3F3A8199.B42F1BF5@engcorp.com> Message-ID: Peter Hansen writes: > John Ochiltree wrote: >> >> Worked like a dream. I now have a shared python shell > > Can you check whether "import pythoncom" and "import pywintypes" > and (if you've installed the Win32 extensions) "import win32api" > all work? > > If these work without your having to do anything to the registry, > I'm curious about the installation process you used, since we > had to do additional steps to get the same result. You are aware that recently Mark changed things so the the registry is no longer used for importing? Thomas From http Sun Aug 24 12:19:24 2003 From: http (Paul Rubin) Date: 24 Aug 2003 09:19:24 -0700 Subject: large-scale app development in python? References: <7xlltkxrcv.fsf@ruckus.brouhaha.com> <87smnsx7y6.fsf@pobox.com> <7xznhzgbuy.fsf@ruckus.brouhaha.com> <87d6evjl6a.fsf@pobox.com> Message-ID: <7xk793hvub.fsf@ruckus.brouhaha.com> jjl at pobox.com (John J. Lee) writes: > > I think Zope is in the 100 KLOC range within a factor of some small > > integer. A large application these days may mean 10 MLOC or more. > > You're right. But of course, the *reason* we're all worried about > large programs is that we want to know "how do I solve problem x with > minimum use of resources", or "given these resources, what problems > can I solve". We're not trying to write big programs, we're trying to > solve big problems. I'm not sure I agree with that. Programming tasks follow Parkinson's law just like anything else: they expand to fill the available resources. That's why Microsoft Word now takes hundreds of megabytes to install and run, and will keep expanding because more resources keep getting thrown at it. In more normal situations, infinite resources aren't available, and programs reach a kind of stasis where they do about as much as possible while staying maintainable. So an organization developing in Python instead of Java won't get a smaller program that's cheaper to maintain. They'll get a comparably sized program that does more. From cookedm+news at physics.mcmaster.ca Tue Aug 19 17:58:24 2003 From: cookedm+news at physics.mcmaster.ca (David M. Cooke) Date: Tue, 19 Aug 2003 17:58:24 -0400 Subject: Design idea for Ping Application References: <4378fa6f.0308181546.548daff7@posting.google.com> <1061263809.5430.49.camel@localhost.localdomain> Message-ID: At some point, "Mike C. Fletcher" wrote: > Jeremy Hylton wrote: > ... > >>Years ago I wrote ping in Python. I don't have the code anymore, but >>there's not too much too it. One of the Stevens books has C source for >>a simple ping, and it's not much work to adapt the basic design to >>Python. It's far simpler than the C code. >> >>If you had a simple ping library in Python, it would be easy to run >>several Ping instances in a single select loop. Then you don't need to >>bother with threads and pipes and shells. >> > As pointed out by a previous poster, it's available from Python.org. > We've got a version which fixes a few (trivial) bugs (use of 'h' > instead of 'H' in struct formats mostly, to indicate unsigned rather > than signed ints). Works nicely on Win32, however, I've not yet been > able to get the code to run under Unix (where creating raw sockets is > a no-no). Only root can create raw sockets. You'll notice the system ping command is setuid root so that ordinary users can use it. Running this code as root works. -- |>|\/|< /--------------------------------------------------------------------------\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca From imbosol at aerojockey.com Fri Aug 1 17:06:33 2003 From: imbosol at aerojockey.com (Carl Banks) Date: Fri, 01 Aug 2003 21:06:33 GMT Subject: Wow: list of immediate subclasses? References: Message-ID: Andrew Dalke wrote: > Carl Banks, responding to Roman Suzi: >> __subclasses__ is a list of weak references, so the class can be >> collected even though it's listed in __subclasses__. For whatever >> reason, class A isn't deleted by reference counts, but cyclic garbage >> collection gets it. > > But I want to know that reason. Why are there any cycles? After > all, don't weak-references help break cycles? Take a look at "__mro__" method of types. __mro__ is a tuple containing real references, and the first item is always the type object, follwed by all it's bases. That makes at least one cycle. There's probably more since gc collects 6 objects. > And in my code > before, why do I need to do the gc a few times to force the cycle > to be broken? Because, __subclasses__ is a list of weak references internally, it gets converted to a regular list when called, and this list is stored in _. Thus, if you call gc.collect right after evaluating float.__subclasses__, there remains an active reference. >>>> float.__subclasses__() > [] >>>> class Spam(float): pass > ... >>>> float.__subclasses__() > [] >>>> del Spam >>>> _ = None # just in case ... >>>> float.__subclasses__() > [] >>>> gc.collect() > 0 >>>> float.__subclasses__() > [] >>>> gc.collect() > 0 >>>> float.__subclasses__() > [] >>>> gc.collect() > 0 >>>> gc.collect() > 6 >>>> gc.collect() > 0 >>>> float.__subclasses__() > [] >>>> > > It's a bit too mysterious for my liking. I think it's a very minor problem. There doesn't appear to be a memory leak, and what's the point of making the effort to manually break cycles when cycle garbage collection exists? -- CARL BANKS From usenet_spam at janc.invalid Sat Aug 16 00:17:26 2003 From: usenet_spam at janc.invalid (JanC) Date: Sat, 16 Aug 2003 04:17:26 GMT Subject: py2exe service and tool-tray app combined? References: <3F3A8371.840.20CD3615@localhost> Message-ID: Thomas Heller schreef: >> Also, if anyone knows, I assume services don't run on 9x, so I want >> to 'simulate' a service there by having the same .exe do all the work >> (and appear as a tooltray app), so here's another reason for having >> one .exe >> >> Can it be done? You don't need a tooltray to create a pseudo service on Win9x. > Not sure. Best would be to change the win32all serviceutil framework. > But I'm not sure it makes sense nowadays - win98 is history. I know multinational companies that use Win98SE as their standard desktop OS (one of them upgraded from Win95 last year). As they want to use the same "environment" in every part of the world and on everything from new P4 desktops to old P2 laptops, Win2K/XP isn't an option... -- JanC "Be strict when sending and tolerant when receiving." RFC 1958 - Architectural Principles of the Internet - section 3.9 From raims at dot.com Sat Aug 23 12:30:05 2003 From: raims at dot.com (Lawrence Oluyede) Date: Sat, 23 Aug 2003 18:30:05 +0200 Subject: Python is darn fast (was: How fast is Python) References: <2259b0e2.0308230737.8a9bc1c@posting.google.com> Message-ID: Michele Simionato wrote: > $ time p23 erf.py > real 0m0.614s > user 0m0.551s > sys 0m0.029s > > This is twice as fast as optimized C: > > $ gcc erf.c -lm -o3 > $ time ./a.out > real 0m1.125s > user 0m1.086s > sys 0m0.006s > > Here is the situation for pure Python > > $time p23 erf.jy > real 0m25.761s > user 0m25.012s > sys 0m0.049s > > and, just for fun, here is Jython performance: > > $ time jython erf.jy > real 0m42.979s > user 0m41.430s > sys 0m0.361s Mmm...on my machine C is faster. What version of GCC do you have? I think 2.9x, right? These are my timings (Debian GNU Linux Unstable, Duron 1300, Python2.3, Psyco CVS, GCC 3.3.2, Java 1.4.1): $ time python erf.py real 0m0.251s user 0m0.207s sys 0m0.012s $ gcc erf.c -lm -O3 $ time ./a.out real 0m0.162s user 0m0.157s sys 0m0.001s Notice that C is faster than Psyco + Python2.3 on my machine (about 65% of speedup) Without Psyco Python2.3 tooks about 6 seconds $ time python erf.jy real 0m6.177s user 0m6.040s sys 0m0.010s And Jython is definitely slower :) $ time jython erf.jy real 0m10.423s user 0m9.506s sys 0m0.197s -- Lawrence "Rhymes" Oluyede http://loluyede.blogspot.com rhymes at NOSPAMmyself.com From belred1 at yahoo.com Sun Aug 3 11:56:26 2003 From: belred1 at yahoo.com (Bryan) Date: Sun, 03 Aug 2003 15:56:26 GMT Subject: popen eating quotes? Message-ID: i have a batch file that contains these two lines: -- args.bat echo %1 echo %2 when i run args.bat from the command line it works correctly... notice that abc has quotes in the first example and not in the second. C:\Temp>"c:\program files\test\args" -vv abc C:\Temp>echo -vv -vv C:\Temp>echo abc abc C:\Temp>"c:\program files\test\args" -vv "abc" C:\Temp>echo -vv -vv C:\Temp>echo "abc" "abc" from python, i'm having trouble getting the quotes around abc to work >>> import os >>> def run_args(arg): ... i, o = os.popen4('"c:/program files/test/args.bat" -vv %s' % arg) ... print o.read() ... >>> run_args('abc') C:\python\python23\lib\site-packages>echo -vv -vv C:\python\python23\lib\site-packages>echo abc abc >>> run_args('"abc"') 'c:/program' is not recognized as an internal or external command, operable program or batch file. what is going on here? why does "abc" effect the uoted program name. does anyone know how to fix this? how to pass a quoted arguments through to popen? i need to do this because in my real code, i'm passing paths as arguments and need them quoted. i'm using python 2.3 on winxp. thanks, bryan From tundra at tundraware.com Tue Aug 5 02:06:21 2003 From: tundra at tundraware.com (Tim Daneliuk) Date: 05 Aug 2003 06:06:21 GMT Subject: Win32All Crashes Python 2.3? Message-ID: Some time ago I wrote a portable file system browser, twander, that, when runnning on Win32, will make use of the Win32All extensions if they are present on the target system. (http://www.tundraware.com/Software/twander) twander primarily uses Win32All to get file attribute and ownership information back in Win32-specific ways each time a new directory is entered. (Ordinarily (if Win32All is not installed), it just displays an 'ls -al' style output and dummies up ownership and group membership.) Now the problem - twander has worked fine with previous versions of Python/Win32All up to and including 2.2.x. It also works fine with 2.3. HOWEVER, if I install any of the 2.3 relevant versions of Win32All, when I change to a new directory, Python crashes. No traceback information is given so I cannot determine exactly why this is happening. What is strange is that the program starts OK, which means it is using Win32All calls to determine file system information for the initial directory. It is only upon changing directories that Python gets blown out of the water. While it is certainly possible that this is a bug in my code, I cannot imagine what it might be. The program has worked flawlessly on a wide variety of Unix/FreeBSD/Win32 systems with no reports of this sort of thing. Anyone have any ideas what could cause this? Is this a reported Win32All bug? TIA, ---------------------------------------------------------------------------- Tim Daneliuk tundra at tundraware.com PGP Key: http://www.tundraware.com/PGP/ From max at alcyone.com Tue Aug 19 04:06:03 2003 From: max at alcyone.com (Erik Max Francis) Date: Tue, 19 Aug 2003 01:06:03 -0700 Subject: Brandon's abrasive style (was Re: What's better about Ruby than Python?) References: <38ec68a6.0308172319.431a4fde@posting.google.com> <1061271273.817674@yasure> Message-ID: <3F41DA6B.3ECA5EDF@alcyone.com> "Brandon J. Van Every" wrote: > I'm after something much bigger than Python. I'm after Permanent > Computing. > I want any game I make to be archived for hundreds of years to > posterity. > Championing an open source language, or figuring out how to surf > Microsoft > indefinitely, is only the opening gambit. The abandonware community is alive with emulators. "Permanent computing" is fool's gold. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ Let he who does not know what war is go to war. \__/ (a Spanish proverb) From gerald.lester at cox.net Sun Aug 3 13:09:33 2003 From: gerald.lester at cox.net (Gerald W. Lester) Date: Sun, 03 Aug 2003 12:09:33 -0500 Subject: Potentially important real-time on-line discussion In-Reply-To: References: Message-ID: Wojciech Kocjan wrote: > Kyler Laird wrote: > >> People pay (what I consider to be) lots of money for me to write software >> for them. I insist that it be open source (which makes for interesting >> contract negotiations sometimes). I would be *thrilled* if someone took >> my code and used it. My value is in providing solutions - not shielding >> intellectual property from use. > > While I do agree with you, another problem is that you spent your time > and your customer paid you to do the software. So, if it is open source their maintenance cost has the potential to go *way* down and their new features per release has the potential to go *way* up. > Would it be fair if at this time, some other programmer took your code, > added (not replaced) him to the copyright notice, changed about 5 things > and charged the same for that? The company thought they got their value for their dollar -- how is it not fair. All we are talking about at this point is residuals -- and would they have received any if they did not open source it. Vs the benefits I mentioned above. > Note that I do not plan to release customer's application as opensource, > only parts of it. I think this is a bit better than releasing all of it, > since my company and my customer spent a lot of time on developing and > facing problems. If some other company wants to solve similar problems, > they can always come to me either writing the software, or consulting them. Ok, you have the tradeoffs mentioned above. Also if you are consulting, having good open source software can be considered a form of advertising (people can see what you can do -- and may well pay you for "small" changes so they don't have to come up to speed on potential side effects and to ensure that the changes will not be conflicting with future development). -- +--------------------------------+---------------------------------------+ | Gerald W. Lester | "The man who fights for his ideals is | | Gerald.Lester at cox.net | the man who is alive." -- Cervantes | +--------------------------------+---------------------------------------+ From mwh at python.net Thu Aug 21 08:15:21 2003 From: mwh at python.net (Michael Hudson) Date: Thu, 21 Aug 2003 12:15:21 GMT Subject: Problems with python-list? References: <477762c2.0308201832.327cf5bc@posting.google.com> Message-ID: <7h31xvf43at.fsf@pc150.maths.bris.ac.uk> dave at pythonapocrypha.com (Dave Brueck) writes: > Is anybody else having problems sending email to > python-list at python.org? I'm not sure what's up. I haven't had *any* mail via m.p.o for some time (probably about the same), which is odd. I guess Barry et al. already know about it if there are problems... Cheers, mwh -- You owe The Oracle a TV with an 'intelligence' control - I've tried 'brightness' but that didn't work. -- Internet Oracularity #1192-01 From Mike at DeleteThis.Geary.com Sun Aug 31 19:34:19 2003 From: Mike at DeleteThis.Geary.com (Michael Geary) Date: Sun, 31 Aug 2003 16:34:19 -0700 Subject: Win32 documentation in CHM? References: <3f5262ea$0$1667$e4fe514c@dreader3.news.xs4all.nl> Message-ID: Iwan van der Kleyn wrote: > Great initiative. Are there any compiled CHM files available for 2.3, > perhaps from other sources then PythonLabs? It's easy to make one using the tools and instructions that Bernard mentioned: http://www.orgmf.com.ar/condor/pytstuff.html and: http://go.microsoft.com/fwlink/?LinkId=14188 Just to help out until something more official shows up, I built a CHM file for Python 2.3 which you can get here: http://www.geary.com/Python/ -Mike From jan at jandecaluwe.com Sat Aug 2 16:59:03 2003 From: jan at jandecaluwe.com (Jan Decaluwe) Date: Sat, 02 Aug 2003 22:59:03 +0200 Subject: Python speed vs csharp References: <1ivz3gto4e3ty$.18j3vv8ame6w6.dlg@40tude.net> Message-ID: <3F2C2617.B36BCA2F@jandecaluwe.com> Mike wrote: > > improvements. Part of the problem with the full simulation is that psyco > gobbles up all my available memory if I use psyco.full(), so I've been > experimenting with psyco.bind(). What about psyco.profile() ? I understood from Armin Rigo that's the preferred interface. -- Jan Decaluwe - Resources bvba Losbergenlaan 16, B-3010 Leuven, Belgium mailto:jan at jandecaluwe.com http://jandecaluwe.com From mis6 at pitt.edu Sun Aug 24 08:24:55 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 24 Aug 2003 05:24:55 -0700 Subject: What's better about Ruby than Python? References: <8D01b.1721$Ej6.702@newsread4.news.pas.earthlink.net> <3F44ED2E.9070308@nyc.rr.com> <0V61b.1900$Ej6.1012@newsread4.news.pas.earthlink.net> <3F4504D7.20008@nyc.rr.com> <2259b0e2.0308230118.67a676e7@posting.google.com> <2259b0e2.0308230712.3f60cf3c@posting.google.com> Message-ID: <2259b0e2.0308240424.e3d4c60@posting.google.com> Jacek Generowicz wrote in message news:... > Once you know CPython, you are sure that your program will run in > Jython? I would expect Jython 2.1 will run 99% of Python 2.1 valid code (except of course, code involving C libraries). But I don't claim any expertise in Jython, so if I am wrong, please correct me. In my small experiments with Jython, I never had problems with the language; I think the only issue was the absence of the C expat library, but then you can use a Java equivalent. Speed is the only real weak point of Jython, as I see it, but this is an entirely different topic. > > if you prefer the term implementation to the term dialect. > > Don't brush this difference off so lightly, for it is a very > significant one. Many languages are standardised. For example Common > Lisp. There are many implementations of Common Lisp. Scheme and elisp > are most certainly NOT implementations of Common Lisp. "Dialects" of > Common Lisp do not exist. This is a tautology. If a Lisp is Common, then it is Common Lisp. I was talking here about Scheme, Emacs Lisp, etc. Now you argue that these are not dialects of Lisp but entirely different languages. To be honest, I do think you have reasons for this claim. Nevertheless, outside of the Lisp community, everybody who says the name Lisp in a language (ex. Emacs Lisp) would expect that it is a dialect of Lisp. So, the confusion is unavoidable. > > On top of that, how am I supposed to choose my implementation? > > Price, availability on the platform which interests you, quality of > implementation, the license conditions, the demands of your clients, > implementation-specific extensions, etc. ... just like for any other > language with multiple implementations. > > If you want to aruge that a single implementation language offers > certain advantages purely by having a single implementation, fine. But > don't use it as an argument to support the (hopelessly false) thesis > that Lisp macros are evil and are responsible for the "fragmentation" > of Lisp. C++ (and other languages) also have many implementations; > this has absolutely nothing to do with them having powerful macros. Not true. If I wanted to use C++, then there would only one choice that would be natural to me, as a Linux user: gcc. This is natural becomes it comes for free in every linux machine (and under cygwin too). Common Lisp in not included in the gcc collection (yes, there is gcl but it does not come automatically, at least it didn't come with Red-Hat 7.3) Speaking more in general you cannot compare the avaibility of C++ (including the avalability of documentation) with the availability of Lisp. > Anyway, repeat your argument to yourself, substituting C++ (or any > other standardized language) for Lisp, and see how ridiculous it > sounds ... and bear in mind that we supposedly got this excess of > choice because Lisp macros inevetably lead to Lisp fragmentation. Notice that I didn't make that claim. > > At least it scared me. There is only one dominant implementation of > > Python, CPython. All the others try to match it as soon as > > possible. I expect Jython 2.2 (now in alpha) will catch up with > > CPython, at some moment. > > Guess what: Having a mature standard means that your "standard" > doesn't change every year or two, as is the case in Python. You'll > find that implementations of Common Lisp are far more compatible > than the various Python implementations. I don't have to wait for > Corman to catch up with MCL (or whatever), because Common Lisp in not > a moving target, unlike Python. Actually, I see this as a disadvantage. For the name of standardization and compatibility one must maintain warts in the language. I am not scared the least by the coming of Python 3.0 in some (far) future. I wll always have the option of running old programs with the old version of the interpreter. It is always free, isn't it? But actually I am pretty sure the breaking of backward compatibility will be minimal. > > In Scheme there is no such a basic reference, I am correct? > > You are not correct. > However, it is so minimalistic that every implementation provides so > much "added value" to make it usable out of the box, that they are > effectively incompatible. Let me be explicit about what I mean by "standard reference implementation". Suppose you have a language with 10 different implementations and a community splitted in 90% using an implementation and 10% using the other nine for very specific tasks. Then there is a standard reference implementation. The Scheme Revised Report is not a standard reference implementation: it is silent on too many *important* details. And the community is not splitted 90% - 10%. So I say there is no basic reference. In Lisp I would agree there is a basic reference, i.e. CL. > This, still, has nothing to do with macros. Let me be explicit about my position about the argument that macros are the source of the splitting of Lisp/Scheme in different dialects. I don't by it. It goes the other way around: many lisp hackers want to have the freedom of creating their own customized programming language. Macros were created to favor this tendency, it is not the macros that created the tendency! In the Python community I don't think macros would necessarely generate a fragmentation in dialects, since Pythonistas like to write standardized (even indented !) code. Still, I would prefer to maintain the status quo and leave things are they are. If I want macros, I can always use Lisp/Scheme, isn't it? Michele Simionato, Ph. D. MicheleSimionato at libero.it http://www.phyast.pitt.edu/~micheles --- Currently looking for a job --- From tundra at tundraware.com Tue Aug 5 02:20:07 2003 From: tundra at tundraware.com (Tim Daneliuk) Date: 05 Aug 2003 06:20:07 GMT Subject: Win32All Crashes Python 2.3? In-Reply-To: References: Message-ID: Tim Daneliuk wrote: FWIW, here is the Dr. Watson dump that results: Microsoft (R) Windows 2000 (TM) Version 5.00 DrWtsn32 Copyright (C) 1985-1999 Microsoft Corp. All rights reserved. Application exception occurred: App: (pid=1268) When: 8/5/2003 @ 01:16:56.212 Exception number: c0000005 (access violation) *----> System Information <----* Computer Name: VIPER User Name: tundra Number of Processors: 1 Processor Type: x86 Family 6 Model 8 Stepping 3 Windows 2000 Version: 5.0 Current Build: 2195 Service Pack: 4 Current Type: Uniprocessor Free Registered Organization: TundraWare Inc. Registered Owner: tundra *----> Task List <----* 0 Idle.exe 8 System.exe 172 SMSS.exe 204 CSRSS.exe 200 WINLOGON.exe 252 SERVICES.exe 264 LSASS.exe 420 svchost.exe 448 spoolsv.exe 480 svchost.exe 496 GHOSTS~2.exe 532 Navapsvc.exe 560 NeTmSvNT.exe 644 NPROTECT.exe 688 mstask.exe 736 slpservice.exe 764 slpmonx.exe 788 NOPDB.exe 832 stisvc.exe 860 tlntsvr.exe 900 WinMgmt.exe 928 MsPMSPSv.exe 960 svchost.exe 1028 hplampc.exe 1100 explorer.exe 1212 hpztsb04.exe 1228 hphmon03.exe 1244 LVComS.exe 1256 NetTime.exe 1272 point32.exe 1316 Pptd40nt.exe 1336 FTClCtrl.exe 1376 Navapw32.exe 1348 hphipm09.exe 996 AlarmApp.exe 356 bosskey.exe 1400 dnoter.exe 1428 HOTSYNC.exe 1436 qsd.exe 1476 TASKMGR.exe 1516 trillian.exe 1540 wftpd.exe 1648 fapiexe.exe 1308 opera.exe 1484 mmc.exe 1304 svchost.exe 1448 mozilla.exe 428 putty.exe 1676 exceed.exe 1280 pythonw.exe 1268 pythonw.exe 1752 rundll32.exe 1780 emacs.exe 1168 DRWTSN32.exe 0 _Total.exe (1D000000 - 1D005000) (77F80000 - 77FFB000) (1E000000 - 1E0F0000) (7C4E0000 - 7C599000) (77E10000 - 77E75000) (77F40000 - 77F7C000) (7C2D0000 - 7C332000) (77D30000 - 77D9E000) (782F0000 - 78538000) (70BD0000 - 70C35000) (78000000 - 78045000) (71710000 - 71794000) (1E1E0000 - 1E1EE000) (1E1D0000 - 1E1DC000) (75050000 - 75058000) (75030000 - 75044000) (75020000 - 75028000) (10000000 - 1006C000) (1E190000 - 1E199000) (10220000 - 1031B000) (76B30000 - 76B6E000) (75E60000 - 75E7A000) (00A60000 - 00AEF000) (1E200000 - 1E20F000) (779B0000 - 77A4B000) (77A50000 - 77B3C000) (1E600000 - 1E615000) (7C340000 - 7C34F000) (1E730000 - 1E742000) (74FF0000 - 75002000) (77980000 - 779A4000) (00F00000 - 00F07000) (75170000 - 751BF000) (751C0000 - 751C6000) (75150000 - 7515F000) (77950000 - 7797A000) (76620000 - 76631000) (1E2A0000 - 1E2AC000) (782C0000 - 782CC000) (77340000 - 77353000) (77520000 - 77525000) (77320000 - 77337000) (773B0000 - 773DF000) (77380000 - 773A3000) (77830000 - 7783E000) (77880000 - 7790E000) (7C0F0000 - 7C152000) (774E0000 - 77513000) (774C0000 - 774D1000) (77530000 - 77552000) (77360000 - 77379000) (777E0000 - 777E8000) (777F0000 - 777F5000) (10210000 - 10216000) (61210000 - 6121F000) (61220000 - 61232000) (01560000 - 01584000) (77570000 - 775A0000) (681A0000 - 681A7000) (66740000 - 66747000) (775A0000 - 77626000) (77840000 - 7787E000) (770C0000 - 770E3000) (01990000 - 01B94000) State Dump for Thread Id 0x224 eax=0068005c ebx=00000000 ecx=00000000 edx=010b41d0 esi=0097b968 edi=1e062da0 eip=780104ac esp=0012e0b0 ebp=0012e488 iopl=0 nv up ei pl nz na pe nc cs=001b ss=0023 ds=0023 es=0023 fs=0038 gs=0000 efl=00000202 function: wcslen 780104a8 8b442404 mov eax,[esp+0x4] ss:00bc7f97=???????? FAULT ->780104ac 668b08 mov cx,[eax] ds:0068005c=???? 780104af 40 inc eax 780104b0 40 inc eax 780104b1 6685c9 test cx,cx 780104b4 75f6 jnz close+0x55 (780130ac) 780104b6 2b442404 sub eax,[esp+0x4] ss:00bc7f97=???????? 780104ba d1f8 sar eax,1 780104bc 48 dec eax 780104bd c3 ret *----> Stack Back Trace <----* FramePtr ReturnAd Param#1 Param#2 Param#3 Param#4 Function Name 0012E488 00000001 00000000 00000000 007B9A43 00823720 !wcslen *----> Raw Stack Dump <----* 0012e0b0 a1 0a 06 1e 5c 00 68 00 - a0 2d 06 1e 20 d1 78 00 ....\.h..-.. .x. 0012e0c0 88 e4 12 00 00 00 00 00 - d0 41 0b 01 5c 00 68 00 .........A..\.h. 0012e0d0 6f 00 6d 00 00 00 5c 00 - 09 00 00 00 6e 00 64 00 o.m...\.....n.d. 0012e0e0 72 00 61 00 5c 00 4e 00 - 00 00 74 00 03 00 00 00 r.a.\.N...t..... 0012e0f0 00 12 09 1e 48 00 00 00 - d0 41 0b 01 01 00 00 00 ....H....A...... 0012e100 36 0b 0e 1e 8c e0 12 00 - 04 00 00 00 a0 e2 12 00 6............... 0012e110 91 81 f9 77 50 96 f8 77 - ff ff ff ff b0 e2 12 00 ...wP..w........ 0012e120 30 0e f9 77 bb 21 f9 77 - 08 06 74 00 93 21 f9 77 0..w.!.w..t..!.w 0012e130 00 00 00 00 40 00 00 00 - 68 2a 0b 01 20 e9 78 00 .... at ...h*.. .x. 0012e140 b8 a1 76 00 f2 e1 08 1e - 34 e9 78 00 01 00 00 00 ..v.....4.x..... 0012e150 00 00 00 00 60 08 0b 1e - 20 e9 78 00 34 e9 78 00 ....`... .x.4.x. 0012e160 a8 a2 76 00 b8 a1 76 00 - b8 a1 76 00 22 3e 09 1e ..v...v...v.">.. 0012e170 b8 a1 76 00 a8 a2 76 00 - b8 a1 76 00 b8 a1 76 00 ..v...v...v...v. 0012e180 20 e9 78 00 f2 be 05 1e - b8 a1 76 00 fc be 05 1e .x.......v..... 0012e190 20 e9 78 00 02 00 00 00 - b8 a1 76 00 90 c4 05 1e .x.......v..... 0012e1a0 b8 a1 76 00 a8 c4 05 1e - 02 00 00 00 01 00 00 00 ..v............. 0012e1b0 5a c4 05 1e b8 a1 76 00 - 20 e9 78 00 02 00 00 00 Z.....v. .x..... 0012e1c0 b8 a1 76 00 20 e9 78 00 - 20 e9 78 00 6e c3 05 1e ..v. .x. .x.n... 0012e1d0 b8 a1 76 00 20 e9 78 00 - 02 00 00 00 20 e9 78 00 ..v. .x..... .x. 0012e1e0 02 00 00 00 94 e7 78 00 - 4e 12 09 1e 02 00 00 00 ......x.N....... State Dump for Thread Id 0x1f4 eax=778321fe ebx=00000004 ecx=0000004c edx=00000000 esi=77f93233 edi=00000004 eip=77f9323e esp=0101fd24 ebp=0101fd70 iopl=0 nv up ei pl zr na po nc cs=001b ss=0023 ds=0023 es=0023 fs=0038 gs=0000 efl=00000246 function: NtWaitForMultipleObjects 77f93233 b8e9000000 mov eax,0xe9 77f93238 8d542404 lea edx,[esp+0x4] ss:01ab9c0b=85f88b20 77f9323c cd2e int 2e 77f9323e c21400 ret 0x14 *----> Stack Back Trace <----* FramePtr ReturnAd Param#1 Param#2 Param#3 Param#4 Function Name 0101FD70 7C4FABFB 0101FD48 00000001 00000000 00000000 ntdll!NtWaitForMultipleObjects 0101FFB4 7C4E987C 00000005 000B000A 7C2D02A7 00152F90 kernel32!WaitForMultipleObjects 0101FFEC 00000000 778321FE 00152F90 00000000 000000C8 kernel32!SetThreadExecutionState *----> Raw Stack Dump <----* 0101fd24 d7 bd 4e 7c 04 00 00 00 - 48 fd 01 01 01 00 00 00 ..N|....H....... 0101fd34 00 00 00 00 00 00 00 00 - 01 00 00 00 90 2f 15 00 ............./.. 0101fd44 01 00 00 00 d4 00 00 00 - d8 00 00 00 e8 00 00 00 ................ 0101fd54 54 01 00 00 8c 05 67 e2 - 00 00 00 00 80 0a ac f5 T.....g......... 0101fd64 d9 f3 4a 80 09 00 00 00 - 0c 00 00 00 b4 ff 01 01 ..J............. 0101fd74 fb ab 4f 7c 48 fd 01 01 - 01 00 00 00 00 00 00 00 ..O|H........... 0101fd84 00 00 00 00 00 00 00 00 - b2 22 83 77 04 00 00 00 .........".w.... 0101fd94 b0 fe 01 01 00 00 00 00 - ff ff ff ff 90 2f 15 00 ............./.. 0101fda4 a7 02 2d 7c 0a 00 0b 00 - d0 e8 ff e2 00 00 00 02 ..-|............ 0101fdb4 0c 0c ac f5 00 00 00 00 - 01 00 00 00 38 00 00 00 ............8... 0101fdc4 23 00 00 00 23 00 00 00 - 0a 00 0b 00 a7 02 2d 7c #...#.........-| 0101fdd4 90 2f 15 00 68 02 2d 7c - 4c 00 00 00 fe 21 83 77 ./..h.-|L....!.w 0101fde4 f8 eb fd 7f 24 98 4e 7c - 1b 00 00 00 00 02 00 00 ....$.N|........ 0101fdf4 fc ff 01 01 23 00 00 00 - 00 00 00 00 d0 e8 ff e2 ....#........... 0101fe04 6c 05 67 e2 00 00 00 02 - 00 00 00 02 80 e7 46 80 l.g...........F. 0101fe14 00 00 00 00 80 e7 46 80 - 24 0b ac f5 0d 11 4b 80 ......F.$.....K. 0101fe24 00 00 00 02 0c 0c ac f5 - 3c 0b ac f5 82 fb 4a 80 ........<.....J. 0101fe34 0c 0c ac f5 01 00 00 00 - 00 00 00 00 00 00 00 00 ................ 0101fe44 01 00 00 00 00 00 00 00 - 00 00 00 00 80 39 48 80 .............9H. 0101fe54 01 00 00 00 00 00 00 00 - 00 00 00 00 68 72 a2 81 ............hr.. State Dump for Thread Id 0x628 eax=00acb470 ebx=0154ff90 ecx=00740688 edx=00000000 esi=77f94086 edi=0000016c eip=77f94091 esp=0154ff74 ebp=0154ff98 iopl=0 nv up ei ng nz ac po cy cs=001b ss=0023 ds=0023 es=0023 fs=0038 gs=0000 efl=00000297 function: ZwWaitForSingleObject 77f94086 b8ea000000 mov eax,0xea 77f9408b 8d542404 lea edx,[esp+0x4] ss:01fe9e5b=???????? 77f9408f cd2e int 2e 77f94091 c20c00 ret 0xc 77f94094 8a5001 mov dl,[eax+0x1] ds:01565356=f3 77f94097 3a5101 cmp dl,[ecx+0x1] ds:011da56e=?? 77f9409a 0f8598c7ffff jne RtlEqualPrefixSid+0x44 (77f90838) 77f940a0 84d2 test dl,dl 77f940a2 7410 jz RtlQueryAtomInAtomTable+0x31 (77f94fb4) 77f940a4 0fb6d2 movzx edx,dl 77f940a7 33ff xor edi,edi 77f940a9 8d72ff lea esi,[edx+0xff] ds:00a99ee6=a4f303e1 77f940ac 85f6 test esi,esi 77f940ae 0f8f04100100 jnle RtlEraseUnicodeString+0x4e (77fa50b8) 77f940b4 b001 mov al,0x1 *----> Stack Back Trace <----* FramePtr ReturnAd Param#1 Param#2 Param#3 Param#4 Function Name 0154FF98 00ACB509 0000016C 000003E8 00000000 00A4A520 ntdll!ZwWaitForSingleObject 0154FFEC 00000000 00ACB470 00000000 00000000 000000C8 !TclpGetDate *----> Raw Stack Dump <----* 0154ff74 c2 c4 4f 7c 6c 01 00 00 - 00 00 00 00 90 ff 54 01 ..O|l.........T. 0154ff84 00 00 74 00 68 c4 4f 7c - 00 00 00 00 80 69 67 ff ..t.h.O|.....ig. 0154ff94 ff ff ff ff ec ff 54 01 - 09 b5 ac 00 6c 01 00 00 ......T.....l... 0154ffa4 e8 03 00 00 00 00 00 00 - 20 a5 a4 00 f0 d4 cc 12 ........ ....... 0154ffb4 18 5b c3 01 7c 98 4e 7c - 00 00 00 00 00 00 74 00 .[..|.N|......t. 0154ffc4 20 a5 a4 00 00 00 00 00 - 00 c0 fd 7f 88 06 74 00 .............t. 0154ffd4 c0 ff 54 01 88 06 74 00 - ff ff ff ff b4 f0 4f 7c ..T...t.......O| 0154ffe4 60 d3 4e 7c 00 00 00 00 - 00 00 00 00 00 00 00 00 `.N|............ 0154fff4 70 b4 ac 00 00 00 00 00 - 00 00 00 00 c8 00 00 00 p............... 01550004 00 01 00 00 ff ee ff ee - 02 10 00 00 00 00 00 00 ................ 01550014 00 fe 00 00 00 00 10 00 - 00 20 00 00 00 02 00 00 ......... ...... 01550024 00 20 00 00 26 02 00 00 - ff ef fd 7f 08 00 08 06 . ..&........... 01550034 00 00 00 00 00 00 00 00 - 00 00 00 00 00 00 00 00 ................ 01550044 98 05 55 01 0f 00 00 00 - f8 ff ff ff 50 00 55 01 ..U.........P.U. 01550054 50 00 55 01 40 06 55 01 - 00 00 00 00 00 00 00 00 P.U. at .U......... 01550064 00 00 00 00 00 00 00 00 - 00 00 00 00 00 00 00 00 ................ 01550074 00 00 00 00 00 00 00 00 - 00 00 00 00 00 00 00 00 ................ 01550084 00 00 00 00 00 00 00 00 - 00 00 00 00 00 00 00 00 ................ 01550094 00 00 00 00 00 00 00 00 - 00 00 00 00 00 00 00 00 ................ 015500a4 00 00 00 00 00 00 00 00 - 00 00 00 00 00 00 00 00 ................ State Dump for Thread Id 0x6bc eax=00000210 ebx=0014d050 ecx=00149f60 edx=00000000 esi=00149f60 edi=00000100 eip=77f839c7 esp=0188fe28 ebp=0188ff74 iopl=0 nv up ei pl nz na po nc cs=001b ss=0023 ds=0023 es=0023 fs=0038 gs=0000 efl=00000206 function: NtReplyWaitReceivePortEx 77f839bc b8ac000000 mov eax,0xac 77f839c1 8d542404 lea edx,[esp+0x4] ss:02329d0f=???????? 77f839c5 cd2e int 2e 77f839c7 c21400 ret 0x14 77f839ca 8b4710 mov eax,[edi+0x10] ds:00a99fe6=0cc4e804 77f839cd 8b483c mov ecx,[eax+0x3c] ds:00a9a0f6=5100ad7e 77f839d0 f6400801 test byte ptr [eax+0x8],0x1 ds:00a9a0f6=7e 77f839d4 7502 jnz RtlCreateProcessParameters+0xd (77f83cd8) 77f839d6 03c8 add ecx,eax 77f839d8 894de4 mov [ebp+0xe4],ecx ss:02329e5a=???????? 77f839db 8b4710 mov eax,[edi+0x10] ds:00a99fe6=0cc4e804 77f839de 668b4038 mov ax,[eax+0x38] ds:00a9a0f7=00ad 77f839e2 668945e0 mov [ebp+0xe0],ax ss:02329e5b=???? 77f839e6 668945e2 mov [ebp+0xe2],ax ss:02329e5b=???? 77f839ea 53 push ebx *----> Stack Back Trace <----* FramePtr ReturnAd Param#1 Param#2 Param#3 Param#4 Function Name 0188FF74 77D56D5E 77D39A00 00149F60 4013F27C 00000070 ntdll!NtReplyWaitReceivePortEx 0188FFA8 77D41C6D 0014E570 0188FFEC 7C4E987C 0014D050 rpcrt4!TowerConstruct 0188FFB4 7C4E987C 0014D050 4013F27C 00000070 0014D050 rpcrt4!I_RpcServerInqTransportType 0188FFEC 00000000 00000000 00000000 00000000 00000000 kernel32!SetThreadExecutionState State Dump for Thread Id 0x530 eax=77ab464e ebx=00000102 ecx=00130178 edx=00000000 esi=77f89153 edi=0198ff74 eip=77f8915e esp=0198ff60 ebp=0198ff7c iopl=0 nv up ei pl nz na po nc cs=001b ss=0023 ds=0023 es=0023 fs=0038 gs=0000 efl=00000206 function: ZwDelayExecution 77f89153 b832000000 mov eax,0x32 77f89158 8d542404 lea edx,[esp+0x4] ss:02429e47=???????? 77f8915c cd2e int 2e 77f8915e c20800 ret 0x8 *----> Stack Back Trace <----* FramePtr ReturnAd Param#1 Param#2 Param#3 Param#4 Function Name 0198FF7C 7C4FAC79 0000EA60 00000000 77AB862F 0000EA60 ntdll!ZwDelayExecution 00007530 00000000 00000000 00000000 00000000 00000000 kernel32!Sleep *----> Raw Stack Dump <----* 0198ff60 a5 ac 4f 7c 00 00 00 00 - 74 ff 98 01 68 c4 4f 7c ..O|....t...h.O| 0198ff70 18 0a 15 00 00 ba 3c dc - ff ff ff ff 30 75 00 00 ......<.....0u.. 0198ff80 79 ac 4f 7c 60 ea 00 00 - 00 00 00 00 2f 86 ab 77 y.O|`......./..w 0198ff90 60 ea 00 00 10 47 ab 77 - 00 00 00 00 00 00 a5 77 `....G.w.......w 0198ffa0 18 0a 15 00 ec ff 98 01 - 18 0a 15 00 68 46 ab 77 ............hF.w 0198ffb0 d8 7a a6 77 c3 7a a6 77 - 7c 98 4e 7c 18 0a 15 00 .z.w.z.w|.N|.... 0198ffc0 d8 7a a6 77 c3 7a a6 77 - 18 0a 15 00 00 a0 fd 7f .z.w.z.w........ 0198ffd0 78 01 13 00 c0 ff 98 01 - 78 01 13 00 ff ff ff ff x.......x....... 0198ffe0 b4 f0 4f 7c 60 d3 4e 7c - 00 00 00 00 00 00 00 00 ..O|`.N|........ 0198fff0 00 00 00 00 4e 46 ab 77 - 18 0a 15 00 00 00 00 00 ....NF.w........ 01990000 4d 5a 90 00 03 00 00 00 - 04 00 00 00 ff ff 00 00 MZ.............. 01990010 b8 00 00 00 00 00 00 00 - 40 00 00 00 00 00 00 00 ........ at ....... 01990020 00 00 00 00 00 00 00 00 - 00 00 00 00 00 00 00 00 ................ 01990030 00 00 00 00 00 00 00 00 - 00 00 00 00 00 01 00 00 ................ 01990040 0e 1f ba 0e 00 b4 09 cd - 21 b8 01 4c cd 21 54 68 ........!..L.!Th 01990050 69 73 20 70 72 6f 67 72 - 61 6d 20 63 61 6e 6e 6f is program canno 01990060 74 20 62 65 20 72 75 6e - 20 69 6e 20 44 4f 53 20 t be run in DOS 01990070 6d 6f 64 65 2e 0d 0d 0a - 24 00 00 00 00 00 00 00 mode....$....... 01990080 9b b6 e5 4f df d7 8b 1c - df d7 8b 1c df d7 8b 1c ...O............ 01990090 92 f4 97 1c de d7 8b 1c - 16 f5 a1 1c de d7 8b 1c ................ -- ---------------------------------------------------------------------------- Tim Daneliuk tundra at tundraware.com PGP Key: http://www.tundraware.com/PGP/ From jzgoda at gazeta.usun.pl Fri Aug 1 15:15:00 2003 From: jzgoda at gazeta.usun.pl (Jarek Zgoda) Date: Fri, 1 Aug 2003 19:15:00 +0000 (UTC) Subject: Interview with Guido in the Wall Street Journal References: Message-ID: Will Stuyvesant pisze: > "Lee Gomes: Two men, two ways to speak computerese [The Wall Street > Journal reports on Python and Perl, and interviews their respective > authors.] " > > If you click on the link then you will find TWSJ works with > subscription, "2 weeks for free!". Hurray! Forcing people to > subscribe and then (later) asking money for it is against my > principles of free information exchange so I didn't read it. I mailed them (PythonWare) with this information few days ago but I forget to ask them to include the information somewhere in near of the link, that this article is for WSJ subscribers only, so it's still pointing to this paid service. I don't know if this article is available elsewhere. -- Jarek Zgoda Registered Linux User #-1 http://www.zgoda.biz/ JID:zgoda at chrome.pl http://zgoda.jogger.pl/ From vanevery at 3DProgrammer.com Mon Aug 11 21:20:19 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Mon, 11 Aug 2003 18:20:19 -0700 Subject: Python vs. C# References: Message-ID: Jimmy Retzlaff wrote: > > In the early days of the PC there was a similar debate over the use of > Assembly versus higher level languages like C and Pascal. Not many > problems "required" the features of those higher level languages, but > people came to understand the benefits in the vast majority of > applications (benefits like time/money, maintainability, and > reliability). Well, I think mainstream commercial industry sees the writing on the wall regarding garbage collection. But that's probably the current level of consensus on "yes, we need a better solution for this." Python advocates tend to pooh-pooh strong typing, and I'm wondering if in a large-scale industrial context, if that's really a valid stance to take. At any rate, I expect more years of evolution with languages such as Java and C# before mainstream industry starts thinking that the more exotic things Python does are "better solutions" for something that definitely needs fixing. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From davecook at nowhere.net Thu Aug 21 00:08:09 2003 From: davecook at nowhere.net (David M. Cook) Date: Thu, 21 Aug 2003 04:08:09 GMT Subject: What's TOTALLY COMPELLING about Ruby over Python? References: <3F41A877.995F9C35@alcyone.com> Message-ID: In article , smarter_than_you wrote: > The real question here is, why haven't we all but Brandon in OUR killfiles? Brandon's not very interesting (or only as interesting as the spectacle of someone behaving badly usually is), but some of the replies are. Dave Cook From webmestre at drsigmund.levillage.org Sun Aug 10 11:07:50 2003 From: webmestre at drsigmund.levillage.org (Sig) Date: 10 Aug 2003 08:07:50 -0700 Subject: Python + Zope compared to J2EE and .Net Message-ID: <74bd3bc.0308100707.577f2930@posting.google.com> Hi there, Could you help me finding out whether Zope could be a serious technological framework for big corporation (compared to J2EE and .Net) or not ? In the (quite very) big corporation I work in, the IT managers are wondering about the future of web technologies for our intranets. Currently, we run web applications in many technologies : heavy J2EE (EJB...), light J2EE (JSP), ASP.Net, ASP, PHP, ... Our big IT boss wants to build a more homogeneous strategy for the technological framework of our future intranet web applications. He may identify J2EE and .Net as the most serious and only candidates for the future of our intranet technologies. I would like to promote Zope as good alternative to examine. But I don't know how I should position Zope as a serious challenger solution. Is there a hope for Zope in big corporations ? I may suggest to my IT boss scenariis such as : A. Zope is the best solution for every of our intranet needs, I would name it LAMP(Z) = Linux + Apache + Mysql + Python (+Zope) - pros => very homogeneous. Cool for maintainability and reusability. Zope is highly adequate for strong knowledge/content management needs (intranets)... - cons => Zope may be to heavy for simple needs we could easily manage with PHP, Zope skills are rather rare of the market whereas PHP is now quite easily available. - risks => Wouldn't it be to much closed ? Would it be opened enough for integrating it with our ERPs (SAP), business intelligence solutions (Business Objects, Hyperion, ...), with transactional systems ? B. The solution is LAMP(PZ) as Linux + Apache + Mysql + PHP + Python (+Zope) - pros => PHP is cool and Zope too. PHP and Zope seem to be complementary (PHP for "simple needs", Python + Zope for "complex needs"). PHP skills are available on the market. - cons => Integrating Zope and PHP is quite difficult and risky (XML-RPC, ...). The framework remains quite heterogeneous. C. Or there is no hope for zope and the only open source candidate is LAMP as Linux + Apache + Mysql + PHP - pros => homogeneous. - cons => PHP may not be adequate for building complex IT architectures. It should be accompanied with some J2EE or .Net stuff... What do you think about that ? Is there a hope for Zope in big corporations ? From tzot at sil-tec.gr Fri Aug 22 11:18:24 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Fri, 22 Aug 2003 18:18:24 +0300 Subject: question: reading character for character from stdin References: <3F46311A.2090707@freemail.nl> Message-ID: <6rcckvkipmd99qq9t5thuqa3nbfendiqis@4ax.com> On Fri, 22 Aug 2003 15:01:41 GMT, rumours say that KwikRick might have written: >Is there a simple way to read from stdin without having to wait for an >enter keypress, i.e. like getch() in the curses module. >I'd rather not use curses because it isn't supported on all platforms. I presume you want that for single key-press user interactivity in console applications? If yes, there is no cross-platform way AFAIK. Write a module with your own API, and in your module find the platform under which your program is being run and translate to the actual available library calls... -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From mwh at python.net Mon Aug 4 06:57:45 2003 From: mwh at python.net (Michael Hudson) Date: Mon, 4 Aug 2003 10:57:45 GMT Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> <840592e1.0307312304.77a0a05f@posting.google.com> <7h3brv9a9oz.fsf@pc150.maths.bris.ac.uk> Message-ID: <7h3y8y98zdb.fsf@pc150.maths.bris.ac.uk> Lulu of the Lotus-Eaters writes: > "Daniel Dittmar" wrote previously: > |But a lot of Python code depends on reference counting or more exactly it > |depends on the timely call of the destructor. So even if a much better GC is > |added to Python, reference counting would perhaps be kept for backwards > |compatibility (see Python's biggest compromises) > > Did this thread get caught in a time warp, and posts from two years ago > get posted again. Exactly this all happened years ago. Welcome to USENET! Cheers, mwh -- Not only does the English Language borrow words from other languages, it sometimes chases them down dark alleys, hits them over the head, and goes through their pockets. -- Eddy Peters From mack at incise.org Fri Aug 15 00:25:36 2003 From: mack at incise.org (mackstann) Date: Thu, 14 Aug 2003 23:25:36 -0500 Subject: dict->XML->dict? Or, passing small hashes through text? Message-ID: <20030815042536.GA19960@incise.org> I don't have any in-depth experience with XML, but I think it is what I want to use. I'm basically passing little messages around, which are basically just hashes, and up until now, I was using a dict that I formatted to/parsed from a special syntax, but I keep running into growing pains with that. I'm using SocketServer, and each connection sends one line of data, and then the connection is closed by the server. I'm thinking that the ideal way that it would happen with XML in the mix would be something like: msg = {} msg["foo"] = 1 msg["bar"] = "hello" msg["abc"] = "text" xmsg = xmlMessage(msg) xmsg would now be a string such as: '1hellotext' I could then send that over the wire, and on the other end, do something like: msg = xmlMessage2dict(xmsg) And I'd have my dict back. I don't think I'll be using values other than strings and ints. Dealing with variable types is something I'm unsure of, e.g. making sure that I get back msg["foo"]==1, not msg["foo"]=="1". Everything I have found for handling XML seems to be centered around parsing huge trees, and really complex data structures, etc. I need no DOM, XSLT, or any other fancy buzzwords associated with XML. I basically just need a simple way to turn hashes into text and back, and I would really like for it to be language-independant. XML seemed like the obvious answer, but maybe it's not. I'm very open to other suggestions too. :) -- m a c k s t a n n mack @ incise.org http://incise.org Emerson's Law of Contrariness: Our chief want in life is somebody who shall make us do what we can. Having found them, we shall then hate them for it. From graham__fawcett at hotmail.com Thu Aug 28 10:18:11 2003 From: graham__fawcett at hotmail.com (Graham Fawcett) Date: 28 Aug 2003 07:18:11 -0700 Subject: Counsel bears (OT, Re: how fast is Python?) References: <3F44DFEB.60AB6492@engcorp.com> Message-ID: claird at lairds.com (Cameron Laird) wrote in message news:... > In article <3F44DFEB.60AB6492 at engcorp.com>, > Peter Hansen wrote: > >dan wrote: > >> > >> However, there are definitely cases where a lot of code would need to > >> be optimized, and so I ask the question: How fast is Python, compared > >> to say a typical optimizing C/C++ compiler? > > > >C is roughly 10 to 100 times faster than Python, though of course it's > >easy to find cases outside of this range, on either side. > > > >I use 30 as a general overall rule of thumb, in the exceptionally > >few cases where it seems relevant how much faster C would be. > > > >And in those very few cases, so far, I have consistently concluded > >I'm happy enough with the speed of Python given that the speed of > >*development* in Python is easily 5 to 10 times faster than the > >speed of development in C. (And again, it's easy to find cases > >outside of this range, on either side...) > . > . > I just think Peter's wise counsel bears repeating. My comment is completely off-topic, but I enjoyed a lyrical moment when I mis-read Cameron's statement, and found myself imagining what "Peter's wise counsel bears" looked like. I am envious of Peter, having never made any magical forest-friends myself. If we each had at least /one/ wise counsel bear, then c.l.py would certainly reap the benefits of our enhanced posts! Yours, -- Graham From darnold4 at cox.net Fri Aug 29 10:58:11 2003 From: darnold4 at cox.net (David Raleigh Arnold) Date: Fri, 29 Aug 2003 10:58:11 -0400 Subject: sed with python References: Message-ID: On Thu, 28 Aug 2003 07:30:17 +0000, David Raleigh Arnold wrote: > Obviously, os.system does me no good at all. That was stupid of me. Of course it lets me use pipes and redirection, which mostly does all. DaveA > Is there an equivalent to "tac" already written as a function in python? > Is there a matrix transposition function that automagically adds fields to > records so that all records have the same number of fields, to guard > against data loss? Where are these found? DaveA -- "We have learned the lessons of Viet Nam." --anon Spokesman "Failure is not an option." --anon Spokesman Can both be true? n Are both false? y Right answers get my vote. D. Raleigh Arnold dra@ http://www.openguitar.com darnold4 at cox.net From aleax at aleax.it Wed Aug 6 10:52:11 2003 From: aleax at aleax.it (Alex Martelli) Date: Wed, 06 Aug 2003 14:52:11 GMT Subject: Is there some Python + IDE/RAD for real speed development??? References: <96fda9ac.0308060611.56dfca7e@posting.google.com> Message-ID: Edilmar wrote: > Hi, > > First of all, I'm new in Python... > > I have worked with manu langs and IDEs, like Delphi, VB, JBuilder, > Eclipse, Borland C++, Perl, etc... > > Then, today I think IDEs like Delphi have a excelent environment to > develop apps with little time. I saw many people talking about Python like > a easy lang to learn and to develop. But I have look at IDEs for Python, > or ways to develop GUIs with it, and I think it already is limited when > comparing with IDEs like Delphi. Is this afirmation true? I don't think you have considered all the available GUIs for Python, and, in particular, the commercial ones (like Delphi and its Linux version Kylix are commercial). For example, BlackAdder (which uses the same commercial Qt libraries which I believe Kylix uses) seems to have the "GUI painter" kind of tool that you require. If it's GUI painters you're after, I think you can find some, either commercial or free (not all in definitive versions, many will still be betas), for most toolkits you might want to use (PythonWorks makes a commercial one for Tkinter, I think one can use glade + gic [gic.sourceforge.net] for Gtk, I see somebody's already mentioned Boa for wx, etc, etc). > I look at wxPython and PyGTK, but the samples showed that we have to write > MANY LINES of code to do simple things. Many people have wrote about the > advantage of Python to write little code, but, when talking about GUIs, > I think it's not really true, right? If you want a code generator (particularly a tool that generates code based on a GUI you paint on-screen) that's not hard to find (particularly if, as in Delphi's case, you're willing to pay for one). The amount of code to be thus generated for typical GUI's (minus, that is, any logic behind them) won't be all that different between e.g. Python and Delphi's Object Pascal. If the code that's automatically generated does all that your application needs, then it makes no difference to you what language that generated code is in, of course. Python's advantages shine when you have to write code as opposed to being 100% satisfied with code automatically generated, and in that respect there is no real difference between GUI's (as soon as you need to customize the generated code or put custom logic behind it -- via inheritance, of course, it would be counterproductive to go and edit files produced automatically by a code generator) and other application areas. > Using Delphi, little or none code is need for many things, but wxPython > and PyGTK is the reverse! I assume you do not mean what you say, but rather that the GUI painter / IDE you use generates just about all code you need ("for many things") in Delphi's case, while you're apparently not using any code generator for either wxPython or pyGTK and therefore need to write all code yourself. So, if you want a code generator / GUI painter, get one... Alex From sdhyok at yahoo.com Sun Aug 24 17:11:15 2003 From: sdhyok at yahoo.com (sdhyok) Date: 24 Aug 2003 14:11:15 -0700 Subject: A strange behavior of list.extend() Message-ID: <420ced91.0308241311.734cbc9c@posting.google.com> I think the two script should produce the same results, but not. Why? ---------------- Script #1 ls = [1] ls.extend([2,3]) print ls -> [1,2,3] --------------- Script #2 ls = [1].extend([2,3]) print ls -> None Daehyok From tjreedy at udel.edu Wed Aug 13 11:42:37 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 13 Aug 2003 11:42:37 -0400 Subject: union in Python References: Message-ID: "Wiebke P?tzold" wrote in message news:u6qjjv81q7vqq5mahauii8fllo67jqsegc at 4ax.com... > I create a database that contains a table. 'Themenbereiche' is one of > 13column names. This program can search for > a special letter. In my example it is 'do'. and the search takes place > in 'Themenbereiche'. 'do' takes place within a word. This is solved > with regular expression. When looking for a particular string, rather than a pattern, you are probably better off to use the find or index method of that string rather than re. >>> 'abcdefg'.find('d') 3 Terry J. Reedy From gh at ghaering.de Tue Aug 26 03:39:42 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Tue, 26 Aug 2003 09:39:42 +0200 Subject: cannot make Python 2.3 work In-Reply-To: <3f4a67a9@news.012.net.il> References: <3f4a67a9@news.012.net.il> Message-ID: <3F4B0EBE.7010501@ghaering.de> Avner Ben wrote: > I installed Python 2.3 on windows xp (uninstalling the 2.2.3 that used > to be there). Python 2.3. keeps looking for "pyhton22.dll" and would not > work. If you start Python 2.3 with c:\python23\python.exe (or whereever you installed Python 2.3), you get an error message that python22.dll is not found? If you did something different, please describe exactly what you were doing. -- Gerhard From tdelaney at avaya.com Wed Aug 13 19:35:24 2003 From: tdelaney at avaya.com (Delaney, Timothy C (Timothy)) Date: Thu, 14 Aug 2003 09:35:24 +1000 Subject: Py2.3: Feedback on Sets Message-ID: <338366A6D2E2CA4C9DAEAE652E12A1DE9E075C@au3010avexu1.global.avaya.com> > From: Gary Feldman [mailto:gafStopSpamData at ziplink.stopallspam.net] > > Also, I'd like to see "iterable must be ", > though this is a general flaw in the Python doc and is perhaps > biased by my C/C++ background where you'd never dream > of doing a reference manual without explicitly indicating the > types of every parameter. "iterable" *is* . If something is "iterable" it has a well-defined interface - specifically: iter(iterable) returns an "iterator", which also has a well-defined interface - specifically that it implements: next() __iter__() returning self Tim Delaney From skip at pobox.com Mon Aug 18 12:30:36 2003 From: skip at pobox.com (Skip Montanaro) Date: Mon, 18 Aug 2003 11:30:36 -0500 Subject: Emacs python-mode,py-pychecker-run problem. In-Reply-To: <20030818130844.7e5c1296.pedro.werneck@bol.com.br> References: <20030818130844.7e5c1296.pedro.werneck@bol.com.br> Message-ID: <16192.65324.510002.620091@montanaro.dyndns.org> Pedro> I am trying to run pychecker on the current buffer on python-mode Pedro> using the py-pychecker-run command, but it fails with the Pedro> "Symbol's function definition is void: read-shell-command" Pedro> error. I don't know elisp, but seems this is the point where the Pedro> error occurs: ... Pedro> And as far as I can understand, seems like my emacs doesn't have Pedro> the read-shell-command function. So it would appear. Here's the doc for XEmacs read-shell-command: `read-shell-command' is a compiled Lisp function -- loaded from "/Users/skip/src/xemacs-21.5.9/lisp/minibuf.elc" (read-shell-command PROMPT &optional INITIAL-INPUT HISTORY DEFAULT-VALUE) Documentation: Just like read-string, but uses read-shell-command-map: button2 minibuffer-smart-select-highlighted-completion down next-history-element linefeed exit-minibuffer next Kbd Macro: M-n prior Kbd Macro: M-p return exit-minibuffer tab comint-dynamic-complete up previous-history-element C-g minibuffer-keyboard-quit C-i comint-dynamic-complete C-j exit-minibuffer C-m exit-minibuffer M-? comint-dynamic-list-completions M-n next-history-element M-p previous-history-element M-r previous-matching-history-element M-s next-matching-history-element M-tab comint-dynamic-complete M-C-i comint-dynamic-complete And here's its implementation (from minibuf.el): (defun read-shell-command (prompt &optional initial-input history default-value) "Just like read-string, but uses read-shell-command-map: \\{read-shell-command-map}" (let ((minibuffer-completion-table nil)) (read-from-minibuffer prompt initial-input read-shell-command-map nil (or history 'shell-command-history) nil default-value))) Can you see if that definition works for you? If not, what about simply substituting (read-string ...) for (read-shell-command ...)? Skip From jroznfgre at jngpugbjreXEBCXNbet.cy Mon Aug 18 19:39:05 2003 From: jroznfgre at jngpugbjreXEBCXNbet.cy (JZ) Date: Tue, 19 Aug 2003 01:39:05 +0200 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: Message-ID: "Ruby still looks to me like a language that was invented because you couldn't (rationally) use objects or references in Perl, so it has Perl-ish syntax, which I don't think is very helpful (someday I may learn it, but Python continues to be far more compelling to me)" Bruce Ecklel http://mindview.net/FAQ/FAQ-008 From lupe at netvisao.pt Tue Aug 26 18:38:28 2003 From: lupe at netvisao.pt (Lupe) Date: Tue, 26 Aug 2003 23:38:28 +0100 Subject: problem installing PyQt for eric3 Message-ID: I'm trying to install eric3 and PyQt is an intermediate step. I got the following output: rm -f qttest.o rm -f *~ core *.core g++ -c -pipe -w -O2 -fomit-frame-pointer -pipe -march=i586 -mcpu=pentiumpro -D_REENTRANT -DSIP_MAKE_MODULE_DLL -DQT_NO_DEBUG -DQT_THREAD_SUPPORT -I/usr/lib/qt3/mkspecs/default -I. -I. -I/usr/local/include/python2.3 -I/usr/lib/qt3/include -I/usr/X11R6/include -I/usr/X11R6/include -o qttest.o qttest.cpp In file included from qttest.cpp:1: /usr/lib/qt3/include/qgl.h:78:21: GL/glu.h: No such file or directory make: ** [qttest.o] Erro 1 ****************************************************************************** The qtgl module will not be built. ****************************************************************************** can anyone translate this to english. Is qtgl important? I have a file named qgl.h in the /include directory, so what was wrong? thanx in advance From adalke at mindspring.com Fri Aug 22 00:26:19 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Fri, 22 Aug 2003 04:26:19 GMT Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> <6dj2kv8ugkieehs7guh786cl40o5lj6mcs@4ax.com> <3F455BF0.5070700@nyc.rr.com> Message-ID: Kenny Tilton: > as when we go for the > productivity win of untyped variables and give up on bugs strong static > typing is supposed to find. You do realize that strong typing and static typing are different things? What does (the lisp equivalent of) 2.5 + "a" do? In Python, a strongly typed language, it raises an exception. I consider that a good thing. But Python is not statically typed. Andrew dalke at dalkescientific.com From ludo at asiatica.org Mon Aug 18 12:16:55 2003 From: ludo at asiatica.org (Ludovico Magnocavallo) Date: Mon, 18 Aug 2003 18:16:55 +0200 Subject: advice choosing IDE References: Message-ID: > What IDE would you recommend for someone who needs easiness of use with > a background of Pascal and VB for MS Office? I've definitely changed to > Linux now and I would like a free IDE either for procedural or object > oriented programming. J (http://www.armedbear.org/) is more an editor than an IDE, though it does offer basic support for Python (indentation, syntax highlighting, a simple code browser), but it's a very nice editor especially for someone coming from the windows world. It's written in Java so it should run out of the box on most modern Linux distributions (recent versions require Java 1.4). Spend a few minutes reading its help on preferences, it's worth it. Good luck! Ludo From mal at lemburg.com Tue Aug 12 08:21:39 2003 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue, 12 Aug 2003 14:21:39 +0200 Subject: ANN: eGenix.com mxODBC Python Database Interface Version 2.0.6 Message-ID: <3F38DBD3.4010707@lemburg.com> ________________________________________________________________________ ANNOUNCING: eGenix.com mxODBC Database Interface for Python 1.5.2 - 2.3 Version 2.0.6 Full Source Python extension providing ODBC connectivity to Python applications on Windows, Unix abd Linux ________________________________________________________________________ WHAT IS IT ?: The mxODBC Database Interface allows users to connect from Python to just about any database on the market today, on Windows, Unix and Linux -- using just one interface to program against for all supported databases and platforms. This makes mxODBC the ideal basis for writing cross-platform database programs and utilities. mxODBC is included in the eGenix.com mx Commercial Extension Package for Python, the commercial part of the eGenix.com mx Extension Series, a collection of professional quality software tools which enhance Python's usability in many important areas such as ODBC database connectivity, fast text processing, date/time processing and web site programming. See http://www.egenix.com/ for details. ________________________________________________________________________ WHAT'S NEW ? The 2.0.6 version includes patches needed to compile the package for Python 2.3. Binaries are available for Python 1.5.2, 2.0, 2.1, 2.2 and 2.3 for Windows and Linux. ________________________________________________________________________ EGENIX.COM MX COMMERCIAL PACKAGE OVERVIEW: mxODBC - Generic ODBC 2.0-3.5 interface for Python mxODBC is an extension package that provides a Python Database API compliant interface to ODBC capable database drivers and managers. In addition to the capabilities provided through the standard DB API it also gives access to a rich set of catalog methods which allow you to scan the database for tables, procedures, etc. Furthermore, it uses the mxDateTime package for date/time value interfacing eliminating most of the problems these types normally introduce (other in/output formats are available too). mxODBC allows you to interface to more than one database from one process, making inter-database interfacing very flexible and reliable. The source version includes a varity of preconfigured setups for many commonly used databases such as MySQL, Oracle, Informix, Solid, SAP DB, Sybase ASA and ASE, DBMaker and many more. The precompiled versions for Windows and Linux include the interfaces to the standard ODBC manager on these platforms to allow for a more easily configurable setup. More details are available at: http://www.egenix.com/files/python/mxODBC.html ________________________________________________________________________ WHERE CAN I DOWNLOAD IT ? The download archives and instructions for installing the package can be found at: http://www.egenix.com/files/python/eGenix-mx-Extensions.html#Packages IMPORTANT: In order to use the eGenix.com mx Commercial package you will first need to install the eGenix.com mx Base package which can be downloaded from the same location. ________________________________________________________________________ WHERE CAN I BUY LICENSES ? mxODBC is free for non-commercial use. Commercial users have to buy licenses for continued use after a 30-day evaluation period. Special licensing setups are available for commercial product developers. Please see http://www.egenix.com/files/python/eGenix-mx-Extensions.html#BuyLicenses for details or go directly to our secure online shop: http://shop.egenix.com/ ________________________________________________________________________ WHERE CAN I GET SUPPORT ? Commercial quality support for these packages is available from eGenix.com. Please see http://www.egenix.com/files/python/eGenix-mx-Extensions.html#Support for details about our support offerings. ________________________________________________________________________ Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Aug 12 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ From bergeston at yahoo.fr Sun Aug 17 15:09:10 2003 From: bergeston at yahoo.fr (Bertrand Geston) Date: Sun, 17 Aug 2003 21:09:10 +0200 Subject: Path Problem on W2K? References: <93f5c5e9.0308170927.6e0bdc38@posting.google.com> <3f3fd1c8$0$1122$6c56d894@feed0.news.be.easynet.net> Message-ID: "Bernard Delm?e" a ?crit dans le message news: 3f3fd1c8$0$1122$6c56d894 at feed0.news.be.easynet.net... > > Also tried adding c:\Program Files\Python23 to my path... > > This should work, though! Still it's advisable to install to > a path without space(s), otherwise the "idle" IDE won't work. > Try with "C\Program Files\Python23" in your path (with the quotes). Could help you (or not :-( ) If you change your path in the System box, I suspect (not sure) that you need to open a new DOS box to have the new PATH. Good luck. From bgporter at artlogic.com Fri Aug 1 09:14:05 2003 From: bgporter at artlogic.com (Brett g Porter) Date: Fri, 01 Aug 2003 09:14:05 -0400 Subject: Detect PythonWin? In-Reply-To: References: <3f29fe44.104328@news.muenster.de> Message-ID: <3nednT2SvbmC-reiXTWJjQ@comcast.com> Martin Bless wrote: > > I often have the situation that while developing with PythonWin I have > to insert code like > > if 1 and "developing in PythonWin": > sys.argv[1:] = ['fake', 'arguments'] > Is there a subtle reason that you can't pass the arguments using the "Arguments" field on the PythonWin "Run Script" dialog? That's always worked fine for me... From staschuk at telusplanet.net Thu Aug 14 21:03:18 2003 From: staschuk at telusplanet.net (Steven Taschuk) Date: Thu, 14 Aug 2003 19:03:18 -0600 Subject: Iterator - what I am missing In-Reply-To: <20030814155135.B246@tibia.amotlpaa.bogus>; from staschuk@telusplanet.net on Thu, Aug 14, 2003 at 03:51:35PM -0600 References: <3f3bde30$0$297$ba620e4c@reader1.news.skynet.be> <20030814155135.B246@tibia.amotlpaa.bogus> Message-ID: <20030814190318.A809@tibia.amotlpaa.bogus> Quoth I: ['for x in iterable: mung(x)' works like...] > iterator = iter(iterable) # get iterator object > try: > while True: > x = iterator.next() # call its .next() method repeatedly > mung(x) > except StopIteration: > pass A wee braino in the above. Should be iterator = iter(iterable) while True: try: x = iterator.next() except StopIteration: break else: mung(x) -- Steven Taschuk staschuk at telusplanet.net "Telekinesis would be worth patenting." -- James Gleick From hwlgw at hotmail.com Sat Aug 23 15:03:58 2003 From: hwlgw at hotmail.com (Will Stuyvesant) Date: 23 Aug 2003 12:03:58 -0700 Subject: Aspect oriented Everything? References: <32cc321c.0308221316.2f5793ac@posting.google.com> Message-ID: > [letterbox1001 at hotmail.com (New_aspect)] > Aspect oriented Software development seems to be expanding ... > ...some of the lesser > utilised languages to step up to Java and C++? How about stepping from Java or C++. AOP is just a contrived way to get around the static typing restrictions that Java and C++ have. You need Python. -- I fear explanations explanatory of things explained. From tinuviel at sparcs.kaist.ac.kr Thu Aug 28 01:29:43 2003 From: tinuviel at sparcs.kaist.ac.kr (Seo Sanghyeon) Date: 28 Aug 2003 05:29:43 GMT Subject: Py2.3: Feedback on Sets References: <%BX%a.4999$N37.3051@nwrdny02.gnilink.net> <7h3d6f3143s.fsf@pc150.maths.bris.ac.uk> <3F4D8BF7.90401@pobox.com> Message-ID: <3f4d9347$0$190$7a214f24@news.kaist.ac.kr> Michael Hudson wrote: >> list * int, OTOH, seems a bit smelly to me >> (though I'm not sure what a better spelling would be...). Rick Thomas wrote: > list * int is by analogy with vector space operations. > Vector1 * Scalar -> Vector2 Huh? list * int does repetition. How does it relate to scalar multiplication of vectors? Seo Sanghyeon From tismer at tismer.com Wed Aug 27 20:25:58 2003 From: tismer at tismer.com (Christian Tismer) Date: Thu, 28 Aug 2003 02:25:58 +0200 Subject: Replacement for rexec/Bastion? In-Reply-To: <862bb9d6ecb44848b676dc4a7dd9ffd5@news.teranews.com> References: <862bb9d6ecb44848b676dc4a7dd9ffd5@news.teranews.com> Message-ID: <3F4D4C16.7090409@tismer.com> Colin Coghill (SFive) wrote: ... > Is Python (preferably CPython 2.3) still able to "sandbox" bits of code > under an application provided API safely? > > Even Jython or Stackless would be ok, I suppose. I really love to see Stackless mentioned, but I don't see how this is related? Stackless, due to its ability to pickle and transfer executable code, is much more "dangerous" than regular Python, if used in the correct "wrong" mode. ciao - chris -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 mobile +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From duncan at NOSPAMrcp.co.uk Thu Aug 14 05:36:17 2003 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Thu, 14 Aug 2003 09:36:17 +0000 (UTC) Subject: To all UK Python Users References: <3f3b4ba2$0$244$fa0fcedb@lovejoy.zen.co.uk> Message-ID: "BadJake" wrote in news:3f3b4ba2$0$244$fa0fcedb at lovejoy.zen.co.uk: > Hi > I have noticed that there does not seem to be a Python User Group > anywhere in the UK. Therefore, I would like to put that to rights. I > am willing to donate space on one of my web servers if there is > sufficient interest. If anybody is interested in joining with me to > set up a UK Python User Group please contact me at john at rygannon.com > You might like to take this discussion onto the Python-UK mailing list. See http://mail.python.org/mailman/listinfo/python-uk. The existing Python UK users seem to have gone a bit quiet recently, we haven't had a meeting since the conference back in April. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From skip at pobox.com Mon Aug 4 17:39:41 2003 From: skip at pobox.com (Skip Montanaro) Date: Mon, 4 Aug 2003 16:39:41 -0500 Subject: PyChecker work with Python 2.3? In-Reply-To: <3F2EB773.4895B5DD@easystreet.com> References: <3F2C5300.FA223CBA@easystreet.com> <3F2EB773.4895B5DD@easystreet.com> Message-ID: <16174.53917.789904.978337@montanaro.dyndns.org> Al> The only change required in my sources is evidently that the csv Al> module no longer has a parser(); it's a reader(aFile). Sounds like you were using a different csv file reader/writer, perhaps Object Craft's. The csv module which is part of 2.3 is a new module in the core. It has a different interface than Object Craft's csv module. (Note that the Object Craft folks are the primary developers of the new csv module as well.) Skip From alanmk at hotmail.com Fri Aug 15 12:23:15 2003 From: alanmk at hotmail.com (Alan Kennedy) Date: Fri, 15 Aug 2003 17:23:15 +0100 Subject: Test web server References: <3F3CFF9F.31E68A67@hotmail.com> Message-ID: <3F3D08F3.CDE1DADC@hotmail.com> Alan Kennedy wrote: >> What version of Mozilla are you using? Axel Grune wrote: > Mozilla 1.4 (Mozilla/5.0 (Windows; U; Windows NT 5.0; de-AT; rv:1.4) > Gecko/20030612) Sorry, I don't have access to that right now. Perhaps someone else can try it out? One thing I did notice about your code is that the Content-length is not being set precisely. When you use a multi-line string, and put a line break at the end of the last line, that line break is stored in the string as a character, which increases the size of data you are sending. So although your HTML is 71 bytes long, with the implicit '\n' it's 72 bytes long. Perhaps this is making a difference to Mozilla? Try using this code to set the data you are sending: CONTENT = "testHello Python!" DATA = """HTTP/1.0 200 OK Connection: Keep-Alive Content-Type: text/html Content-length: %d Server: Python %s""" % (len(CONTENT), CONTENT) And see if that makes a difference? regards, -- alan kennedy ----------------------------------------------------- check http headers here: http://xhaus.com/headers email alan: http://xhaus.com/mailto/alan From mpeuser at web.de Wed Aug 13 03:32:26 2003 From: mpeuser at web.de (Michael Peuser) Date: Wed, 13 Aug 2003 09:32:26 +0200 Subject: Tix + Python + Windows? References: <8bf5dfd1.0308121544.30d1c565@posting.google.com> Message-ID: Yea - same problem some weeks ago. It seems to be a corrupted TCL script of just minor significance. I just deleted that line and the next braced section.... You need no tcl knowledge for that - just some feeling ;-) No problem so far, but I do not use TIX tjat often - it was a try with PAGE GUI-Builder Kndly Michael P "Josh" schrieb im Newsbeitrag news:8bf5dfd1.0308121544.30d1c565 at posting.google.com... > I've been trying to get Tix running with Python on Windows. Since > there is no binary distributions of Tix for Windows, it seems the > easiest way to install Tix is through IDiscovery's IDEStudio 1.9 > (http://starship.python.net/crew/mike/Idle/). This went fine and I > ran the "Install Tix into Python" option at the end of the > installation, with the target Python installation being the Python 2.2 > I just mentioned. I also ran the "Run Tix demos" option at the end of > the installation, which also worked fine and presented the usual > tixwidgets.py demo. However, when I tried running > > >>> import Tix > >>> root = Tix.Tk() > > from a Python 2.2 prompt, I got the following error: > > error reading package index file > C:/Python22/tcl/tix8.1/pkgIndex.tcl: invalid command name > "lt}]}" > > The only mention of this problem I can find is at: > > http://issues.bigasterisk.com/hiss/issue36 > > but there doesn't seem to be a clear resolution put forth. By the > way, IDEStudio 1.9 comes with a stand-alone Python 2.1 binary and the > Tix demo it ran at the end of installation was actually just a batch > file containing > > tix8183.exe ..\..\Demos\Tcl\tixwidgets.tcl > > Has anyone else had any problems with this? Any suggestions? > > Thanks, > josh From davecook at nowhere.net Mon Aug 18 08:40:27 2003 From: davecook at nowhere.net (David M. Cook) Date: Mon, 18 Aug 2003 12:40:27 GMT Subject: advice choosing IDE References: Message-ID: <%O30b.30366$Ij4.8468@news2.central.cox.net> In article , Lupe wrote: > I'd need an easy help on syntax, if possible with examples and a front end > debugger with easy trace, breakpoints and watches. I've never used Python's debugger in years of Python programming. Or are you asking about C now? I think DDD supports Python debugging, though. For Python work I use XEmacs. It has a very good python mode. I just don't think Python's syntax is complex enough to need help from an IDE. For library help I just keep a link on my browser toolbar to a local copy of the Python html docs. There are several good IDEs for C, but you should not use their existence as an excuse for not learning how to write a Makefile. Dave Cook From abuseonly at sgrail.org Thu Aug 28 00:31:46 2003 From: abuseonly at sgrail.org (derek / nul) Date: Thu, 28 Aug 2003 04:31:46 GMT Subject: Windows Remote Log in References: Message-ID: <9d1rkvgv44tl8ncki3oci9lrn0nt9c507h@4ax.com> and the question is? On Thu, 28 Aug 2003 03:38:03 GMT, Jesse wrote: >I'm new to both programing and python and having a bit of a problem >finding an answer online. > >I've got a script that will be running on a Windows Machine and will >need to access remote servers not in the same domain. > > >I'll be using this to restart services, copy files. >This script will be run by the user so they will be available to enter >their login information and the users all have manager access to the >remote domains. > >Thanks, > >Jesse From adalke at mindspring.com Wed Aug 13 15:30:41 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Wed, 13 Aug 2003 13:30:41 -0600 Subject: Py2.3: Feedback on Sets References: Message-ID: Raymond Hettinger: > I've gotten lots of feedback on the itertools module > but have not heard a peep about the new sets module. I've only just started to use them. Plus, I didn't realize there was a need for feedback. > * Are you overjoyed/outraged by the choice of | and & > as set operators (instead of + and *)? I read some mention of using "|" instead of "+", so I knew to use it. I would have liked +, but not *. I know the logic for thinking * but & doesn't have the other connotations * has (like [1] * 2, "a"*9) > * Is the support for sets of sets necessary for your work > and, if so, then is the implementation sufficiently > powerful? Necessary is such a strong word. After all, I've been using Python for a long time without a set. It's been fun to use. I still haven't got the balance right, so I'll start with a set then have to back it out because I need an ordered list instead, or that I need a value so switch to a dict. I really, really like using ImmutableSet as a dictionary key. The other solution is unique_d = {} # or: dict.from_keys(data, 1) for x in data: unique_d[x] = 1 keys = unique.keys() keys.sort() dict_key = tuple(keys) which makes the assumption that my objects can be sorted. (__lt__ is a stronger requirement than __eq__) > * Is there a compelling need for additional set methods like > Set.powerset() and Set.isdisjoint(s) or are the current > offerings sufficient? I haven't had enough experience to say. I haven't needed the first, and think I just did "if not x&y" for the second. I could see choosing an "isdisjoint" for its more explicit description of intent and its better performance. What I did need yesterday was a way to get the elements only in the first set, only in the intersection, and only in the second def threeway(st1, st2): return st1-st2, st1&st2, st2-st1 It's easy to write - I just didn't like the 3-fold comparisons of the elements in the sets. > * Does the performance meet your expectations? Haven't gotten to the stage where I'm worried about performance. > * Do you care that sets can only contain hashable elements? Not a bit. I was using dicts before. > * How about the design constraint that the argument to most > set methods must be another Set (as opposed to any iterable)? I did think about st2 = st1 + ["some", "other", "values"] but decided I didn't like it, so didn't try it out to see if it worked. I'm not sure what I don't like about it. I think it's because sets lose order, so they aren't *quite* iterator enough to justify working transparently with iterators. But IANG ("I am not Guido" ) and know that my language intuition is only grade B. > * Are the docs clear? Can you suggest improvements? I haven't read the docs closely, mostly just AMK's notes, changelog, and discussions here. I would like if help(sets) gave more information, since I mostly learn interactively. OTOH, what help does give is too much. The signatures for all three classes are present, which means screen upon screen of __special__ __methods__. If the top had a summary of operators x&y x.intersection(y) -- intersection of two sets x|y x.union(y) -- union of two sets ... or the example code from the docs then it would be more helpful. > * Are sets helpful in your daily work or does the need arise > only rarely? I'm still experimenting. Eg, will I use unique = dict.from_keys(data).keys() or import sets ... unique = list(sets.Set(data)) ? The former fits in well with pre-set Pythonic thought but the second looks cleaner. > User feedback is essential to determining the future direction > of sets (whether it will be implemented in C, change API, > and/or be given supporting language syntax). > It took a while to get used to "st.remove(x)" - a couple times I did "del st[x]", which is what I would do for a dict. It's probably appropriate that it not be allowed, as "st[x]" doesn't and shouldn't work, but again, IANG so I'll just point out that the del felt natural to me. Andrew dalke at dalkescientific.com From staschuk at telusplanet.net Wed Aug 6 08:52:21 2003 From: staschuk at telusplanet.net (Steven Taschuk) Date: Wed, 6 Aug 2003 06:52:21 -0600 Subject: check if running under IDLE In-Reply-To: <3F30CED2.7070609@igpm.rwth-aachen.de>; from jarausch@igpm.rwth-aachen.de on Wed, Aug 06, 2003 at 11:48:02AM +0200 References: <3f2ec16b$0$285$ba620e4c@reader0.news.skynet.be> <13a533e8.0308051237.6bfa05d3@posting.google.com> <3F30CED2.7070609@igpm.rwth-aachen.de> Message-ID: <20030806065221.A2481@tibia.amotlpaa.bogus> Quoth Helmut Jarausch: [...] > To check a script accessing sys.argv I have to set it. > Unfortunately the 'Run' pulldown menu of IDLE doesn't have an item > to set sys.argv as it's common with debuggers for C. > > Now in Python I can set sys.argv within the script, > but forgetting to comment this out afterwards makes the > script wrong outside of IDLE Why not write your script in something like the form # foo.py import sys def main(argv): # ... if __name__ == '__main__': main(sys.argv) and then write a separate script for testing, # test_foo.py import foo foo.main(['foo.py', 'testing', 'parameters']) and run that instead? (In answer to the question actually asked: I have no idea how to detect whether running in IDLE.) -- Steven Taschuk staschuk at telusplanet.net Receive them ignorant; dispatch them confused. (Weschler's Teaching Motto) From a.neudecker at uni-bonn.de Fri Aug 29 10:33:49 2003 From: a.neudecker at uni-bonn.de (Andreas Neudecker) Date: Fri, 29 Aug 2003 16:33:49 +0200 Subject: method (a, b = '', *c, **d): gets a syntax error? Message-ID: <3F4F644D.2060003@uni-bonn.de> Hello. I am relatively new to Python and I have a strange problem with some code. In a class the __call__ method gets parameters like this: class WhatsUp: __call__ ( self, var1, var2 = '', *moreVars, **moreNamedVars, ): pass I always get an error for the **moreNamedVars, line where the '^' points at the comma at the end (or, if I remove the comma, it points at the colon). I also tried commenting-out the other variables passed to the method. Same result. I assumed the order of variables and variable lists of variables had to be like this? What is wrong? Kind regards Andreas From skip at pobox.com Wed Aug 13 21:29:13 2003 From: skip at pobox.com (Skip Montanaro) Date: Wed, 13 Aug 2003 20:29:13 -0500 Subject: problems importing "bsddb" In-Reply-To: <20030814093622.W50245@bullseye.apana.org.au> References: <16185.22848.524146.916237@montanaro.dyndns.org> <20030814093622.W50245@bullseye.apana.org.au> Message-ID: <16186.58857.130140.639086@montanaro.dyndns.org> Andrew> import bsddb185 as bsddb Andrew> Before Skip goes up in flames, only use the bsddb185 module if Andrew> you have to. What he said. burn-baby-burn-ly, y'rs, Skip From hokiegal99 at vt.edu Sun Aug 3 16:03:28 2003 From: hokiegal99 at vt.edu (hokiegal99) Date: Sun, 03 Aug 2003 16:03:28 -0400 Subject: Determining if a filename is greater than X characters References: <93f5c5e9.0308021815.44c57a2d@posting.google.com> <3f2cfea8$0$49106$e4fe514c@news.xs4all.nl> Message-ID: <3F2D6A90.1040203@vt.edu> Thanks for the tips. I got it to work using this: for root, dirs, files in os.walk(setpath): old_fname = files new_fname = old_fname[0][:27] print old_fname print new_fname The problem with this approach is that it only gets the first filename in the directory. I tried doing "old_fname[:][:27]", but that doesn't do it. I need to learn more about lists. Thanks!!! Irmen de Jong wrote: > Cy Edmunds wrote: > >> filename = "abcdefgh" >> if len(filename) > 6: >> filename = filename[:6] >> print filename >> abcdef > > > The if is not necessary, just use > > filename=filename[:6] > > --Irmen From dave at psys.org Tue Aug 26 16:05:12 2003 From: dave at psys.org (d.w. harks) Date: Tue, 26 Aug 2003 15:05:12 -0500 Subject: Advice to a Junior in High School? In-Reply-To: References: Message-ID: <200308261505.12353.dave@psys.org> On Monday 25 August 2003 05:57 pm, Howard Nease wrote: > Hello, everyone. I would appreciate any advice that someone could give me > on my future career path. Here is my situation: > > I am a bright Junior in a very well-respected private high school, taking > almost all AP and accelerated classes. I am HIGHLY interested in > technology, more specifically the field of Computer Science and software > engineering. I have heard a whole lot about the fact that the market for > software engineers nowadays is *HORRIBLE*, and that I should double major > or perhaps go into a field of study in which I'm not very interested. > > I would be devastated were I to find the need to leave computer science. I > love the subject, and I've wanted to be a computer scientist ever since I > was 12 years old. > > Does anyone have any advice for me and my future? What should I study in > college? Will the market for jobs get better? Do I have any hope at all of > finding a decent-paying job in compsci? What languages do you suggest that > I study (I'm already studying Python)? > > thank you very much for your help! > > --shn As a junior in high school, rather than worrying so much about *what* to study in college, I'd suggest carefully looking at *where* to study. A Bachelor of Science in Computer Science from one school won't be the same as another -- try to think of what topics you're most interested in and find schools that have professors who specialize in those fields. They'll end up helping you decide what to study as you go, because they'll be able to see what your interests (and talents) are. (Something that your words on a mailing-list don't identify all that well!) For now, keep all your grades up and start visiting colleges. Don't sweat the other stuff just yet...the school you choose will have a program laid out, and you'll choose electives within it, but it'll be pretty straightforward and will give you an opportunity to explore and figure out if/what you want to study in grad school. Don't forget to enjoy the stuff you're learning, and don't sweat the job market thing. If you have the ability and the love of CS, supporting yourself will come along in ways you can never plan for. Just do what you love, and you'll be amazed at what happens. dave -- d.w. harks http://dwblog.psys.org From martin.vonloewis at hpi.uni-potsdam.de Thu Aug 7 05:33:58 2003 From: martin.vonloewis at hpi.uni-potsdam.de (Martin v. Löwis) Date: Thu, 7 Aug 2003 11:33:58 +0200 Subject: Version Problem References: Message-ID: > Which is the recommanded way to deal with different python versions and > extension modules? Use distutils. This allows rebuilding extension modules in a matter of minutes. > I'm looking for some easy-to-use method, preventing me > from maintaining my module for different python versions and which gives > the user the most flexibillity. You only have to maintain a single source code version, covering all Python versions. You can then choose to just release the source code, leaving the burden of building binary distributions on the user. Or you can provide binary versions for selected platforms yourself, which is best done by having all target Python versions installed on a single machine, and producing binaries for these. > Besides: Does anybody know a good method for GNU autoconf to check which > python version is installed? No. However, with distutils, this is unnecessary. Regards, Martin From tom_williams_2000_ca at yahoo.ca Mon Aug 25 13:50:38 2003 From: tom_williams_2000_ca at yahoo.ca (Thomas Williams) Date: Mon, 25 Aug 2003 13:50:38 -0400 (EDT) Subject: Decoding MIME email. Message-ID: <20030825175038.48958.qmail@web13503.mail.yahoo.com> Hello everyone, my name is Tom W. And, I am new to the list, and have been using Python for about a year now. Anyway, I got a question! I am trying to decode MIME (base64) email from a POP3 server, but all I get is a corrupt file. I know that it good to begin with because I check it with another email client. This is what I am doing! ..... f=open("msg.txt","wb") f.write(filelne) f.close() mimify.unmimify("msg.txt", "msg.jpg", decode_base64=1) ........ Is this right? Tom W From NAICH-SYDNEYCH-EXCHANGE at cowleyhearne.com.au Fri Aug 22 00:22:57 2003 From: NAICH-SYDNEYCH-EXCHANGE at cowleyhearne.com.au (GroupShield for Exchange (CH-EXCHANGE)) Date: Fri, 22 Aug 2003 14:22:57 +1000 Subject: ALERT - GroupShield ticket number OA1106_1061526172_CH-EXCHANGE_ 3 was generated Message-ID: <540F61BD2C9BD64DA18FCB9B7367424D897766@CH-EXCHANGE.cowleyhearne.com.au> Action Taken: The attachment was quarantined from the message and replaced with a text file informing the recipient of the action taken. To: jhearne at cowleyhearne.com.au From: python-list at python.org Sent: 1702508544,29583461 Subject: Your details Attachment Details:- Attachment Name: document_all.pif File: document_all.pif Infected? No Repaired? No Blocked? Yes Deleted? No Virus Name: -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/ms-tnef Size: 1954 bytes Desc: not available URL: From claird at lairds.com Sun Aug 24 11:16:41 2003 From: claird at lairds.com (Cameron Laird) Date: Sun, 24 Aug 2003 15:16:41 -0000 Subject: large-scale app development in python? References: <477762c2.0308230631.7203b0bf@posting.google.com> Message-ID: In article <477762c2.0308230631.7203b0bf at posting.google.com>, Dave Brueck wrote: >gabor wrote in message >news:... >> hi, >> >> at the company where i'm working we have to rewrite a part of our >> java-based application in a different language. > >Why? Me, too. As deep as my reservations about Java are, and as fond as I am of Python, "we have to rewrite a part of our ... application ..." sounds suspicious to me. . [lots of stuff others have covered well] . . >In many ways languages like Python are *more* suited than C++ or Java >for larger and more complex applications. There are many reasons why I want to repeat this. No, we have no proof that Python is fit for large-scale programming, in the sense that no one has truly put into production (to the best of my knowledge) a thirty-million- lines-of-source-code Python-based application, and there *are* such beasts in C and C++. HOWEVER, for all scales in my experience, Python has been MORE fit than C and C++, and differentially more so, the larger the project. C and C++ are NOT good languages for programming-in-the-large; they are merely conventional ones. . . . -- Cameron Laird Business: http://www.Phaseit.net Personal: http://phaseit.net/claird/home.html From heikowu at ceosg.de Sat Aug 9 09:10:11 2003 From: heikowu at ceosg.de (Heiko Wundram) Date: 09 Aug 2003 15:10:11 +0200 Subject: Slogan: Getting Rich Overnight In-Reply-To: <3F34638F.9020201@tismer.com> References: <3F34638F.9020201@tismer.com> Message-ID: <1060434610.10912.124.camel@d168.stw.stud.uni-saarland.de> On Sat, 2003-08-09 at 04:59, Christian Tismer wrote: > got rich overnight by Python! Couldn't have said it better... Python led be out of the deep dark caves of lowlevel programming and the other P-languages 2 years ago, and I still don't regret my choice in the least. Heiko. From guy.flowers at Machineworks.com Tue Aug 12 09:08:43 2003 From: guy.flowers at Machineworks.com (Guy) Date: 12 Aug 2003 06:08:43 -0700 Subject: popen2 Message-ID: Hi I was given an exstremly useful answer to a problem that I had in windows. I'm relativly new with python, but find it exstremly useful. I'm creating a script to run test files and record output, the script already works on win32 and I've made a telnet procedure which works quite well when you want to do the testing on one of the many unix boxes (but its very slow). What I want to do now is run the script on a unix system, and later on, create a rsh function to run the tests on different unix boxes which have not got python on them. The following snippet of code is what I use on win32. just example sets some env vars and executes an exe, collects and processes the output. : output, input = popen2("cmd.exe") # Sets the enviroment. input.write("set LI_DIR=value\n") input.write("set LI_DIR_ALT=value\n") input.write("set LI_ARCH=value\n") input.write("set LI_PRECISION=value\n") input.write("set LI_PERFORMANCE=value\n") input.write("set LI_LINKING=\n") input.write("set LI_ARCHFLAG=\n") input.write("set LI\n") # Writes commands to it. input.write(f_mwtest_exe_str + " " + f_mwtest_args + " " + os.path.dirname(f_testlwc_str) + " " + f_testlwc_str + "\n") input.write("exit\n") while 1: text = output.readline() if text: process text line else: break: The unix equivalant is something like this : from popen2 import popen2 output, input = popen2("csh") # Sets the enviroment. input.write("setenv DISPLAY doors:0.0\n") input.writeinput.write(f_mwtest_exe_str + " " + f_mwtest_args + " " + os.path.dirname(f_testlwc_str) + " " + f_testlwc_str + "\n") print "finished" process the output from the test file. The problem is at the moment I can't get the process to stop and wait until the exe has finished executing, the python script executes everything and then the test file is executed afterwards. I'm thinking that there must be a switch on the csh or sh command to stop this happening but I don't know what it is. The unix machines that I'm working on are all different plat types, so the platform type proberly won't help you. NOTE the commands above will be a lot more varied, and are not just used to set the enviroment up. Any help would be of great value to me TIA Guy From whitton at atlantic.net Thu Aug 21 10:42:26 2003 From: whitton at atlantic.net (Travis Whitton) Date: Thu, 21 Aug 2003 14:42:26 GMT Subject: how fast is Python? References: Message-ID: If you haven't seen this, you should check it out. It compares a variety of languages to each other, and it's probably the best site on the internet for side-by-side language comparisons: http://www.bagley.org/~doug/shootout/ -Travis In article , dan wrote: > It would be an understatement to say I love this language. What used > to take me all day now takes 3 hours, and I can spend the rest of the > time on my bike thinking about the problems from a high level instead > of wrestling with arcane compiler problems, etc. > > Back in the day, when looking at an interpreted language (or even > compiled ones) the first thing I would ask is, "how fast is it?" > These days, with 1ghz processor machines selling for < $500, it seldom > comes up as an issue. And of course in Py's case you can always > 'extend and embed' your core routines for fun & profit. > > However, there are definitely cases where a lot of code would need to > be optimized, and so I ask the question: How fast is Python, compared > to say a typical optimizing C/C++ compiler? > > I realize this is a more complex question than one might think. There > are various types of code constructs that might end up with different > efficiency issues. I guess what I'm asking is, in a general sense, > how fast is it now for typical code sequences, and -- importantly -- > what could be done to optimize the interpreter? Are any parts written > in assembly? Could things like hash tables be optimized with parallel > units such as MMX? Etc. > > Please advise. From ialbert at mailblocks.com Wed Aug 20 12:50:07 2003 From: ialbert at mailblocks.com (Istvan Albert) Date: Wed, 20 Aug 2003 12:50:07 -0400 Subject: Regex Question In-Reply-To: References: Message-ID: Thomas G?ttler wrote: > Hi! > > I want to parse a file that looks like this: > > a0001: basbasdb > asbddsb > asdbasdb > abasbd > a0002: fffff > ffff > ffffff > ffff > I think there is a better solution than this, don't you? It is not clear from what you are saying what are the limitations for possible key and values. If the ":" character cannot appear in a key or a value you could do something a lot simpler: elems = line.split(":") if len(elems)==2: key = elems[0] val = elems[1].strip() else: val = elems[0].strip() If you need to check/enforce a certain key format then the regexp solution is better. Istvan. From aahz at pythoncraft.com Mon Aug 11 15:30:21 2003 From: aahz at pythoncraft.com (Aahz) Date: 11 Aug 2003 15:30:21 -0400 Subject: Reference count References: Message-ID: In article , Pablo Yabo wrote: > >I'm embedding Python as script language of a application. >I need to create objects in Python an keep them alive as they are GUI >objects. >How can I increment the reference count of the objects in order to prevent >garbage collector destroy them? Read "Extending and Embedding" in the standard Python docs. You need to understand all of it. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From ialbert at mailblocks.com Mon Aug 11 22:12:18 2003 From: ialbert at mailblocks.com (Istvan Albert) Date: Mon, 11 Aug 2003 22:12:18 -0400 Subject: Python should try to displace Java In-Reply-To: References: Message-ID: still trolling eh, but you try too hard and it shows, From skchim0 at engr.uky.edu Thu Aug 14 01:45:51 2003 From: skchim0 at engr.uky.edu (satish k.chimakurthi) Date: Thu, 14 Aug 2003 01:45:51 -0400 Subject: system call in python In-Reply-To: <3F3B2012.9030101@teksavvy.com> References: <3F3B2012.9030101@teksavvy.com> Message-ID: <200308140145.51759.skchim0@engr.uky.edu> Hi, I think you can do the following: import commands commands.getstatusoutput("...your command to execture program...") SATISH On Thursday 14 August 2003 01:37 am, Graham Fawcett wrote: > Catherine Yang wrote: > >Hi, > > > >A question about how to execute a system command from python program. e.g. > >in a python script, I need to run another program written in C++, and > > after that come back to the same python program. > > > >Is it the system module, and which function do I use to do this? > > > >Thanks a lot > >Catherine > > Probably you are looking for os.system, as in: > > import os > cmd = 'ls -l /usr/bin' > os.system(cmd) > > Note that this will not capture the output of the system command; you > can use the os.popen family of commands to do that. > > -- Graham -- SATISH K.CHIMAKURTHI GRAD. RESEARCH ASSISTANT UNIVERSITY OF KENTUCKY LEXINGTON KENTUCKY STATE From paulpaterson at users.sourceforge.net Fri Aug 29 00:47:28 2003 From: paulpaterson at users.sourceforge.net (Paul Paterson) Date: Fri, 29 Aug 2003 04:47:28 GMT Subject: Bayesian kids content filtering in Python? References: <20030828161409.V40715@onyx.ispol.com> Message-ID: "Gregory (Grisha) Trubetskoy" wrote in message news:20030828161409.V40715 at onyx.ispol.com... > > I've been snooping around the web for open source kids filtering software. > Something that runs as an http proxy on my home firewall and blocks > certain pages based on content. > > It occured to me that this might be an interesting project to be done in > Python, probably using the same training and scoring mechanism that > spambayes uses. > > Anyway - I wonder if anyone has already tried something like this? As Rene points out in his response,after some great advice and discussion from Skip I gave this a try. It works very well. I added a module to a proxy server (http://theory.stanford.edu/~amitp/proxy.html) and then 'trained' Spambayes on top of it by going to sites that I wanted to allow (news sites) and then ones I wanted to block (sports sites - just to test!). After a relatively short training period (20-40 sites/pages) it started to pick up the characteristics of positive and negative sites. It was then easy to get it to block the negative sites. Although there were still quite a few false positives I imagine that with a wider training suite it would have been very accurate (based on the reported accuracy of Spambayes). Unfortunately, I didn't carry the work through much beyond the initial proof of concept but I have copied the code I ended up with below. It certainly seems to work and has application both for parental filtering and other kinds of content management. Paul ---- [mod_spambayes.py - place in your proxy folder and ammend the proxy.conf file to point to this module] print "Importing Spambayes filter" import os from proxy3_filter import * import proxy3_options # # Find ham/spam database and suitable folders for archiving from spambayes import hammie, Options, mboxutils dbf = os.path.expanduser(Options.options.hammiefilter_persistent_storage_file) # hamfolder = os.path.join(os.path.split(dbf)[0], ".hampages") spamfolder = os.path.join(os.path.split(dbf)[0], ".spampages") import time def getTempName(ham, spam, ok): """Return a temporary file name to archive this file""" if ok: direc = ham else: direc = spam return os.path.join(direc, "arc%d" % time.time()) print "Using db file: %s\nham folder: %s\nspam folder: %s" % (dbf, hamfolder, spamfolder) class SpambayesFilter(BufferAllFilter): hammie = hammie.open(dbf, 1, 'r') am_learning = 0 # set to 1 when learning is_ok = 0 # set to 1 if visited page is ok for viewing prevent_access = 0 # set to 1 to block access to dubious pages archive_files = 0 # set to 1 to archive files for later training def filter(self, s): if self.reply.split()[1] == '200': msg = "%s\r\n%s" % (self.serverheaders, s) if self.am_learning: old = self.hammie.score(msg) self.hammie.train(msg, not self.is_ok) new = self.hammie.score(msg) self.hammie.store() print "Learned! was=%.5f, now=%.5f" % (old, new) if self.archive_files: try: temp_name = getTempName(hamfolder, spamfolder, self.is_ok) print "Writing %s" % temp_name f = open(temp_name, "w") f.write(msg) finally: f.close() else: prob = self.hammie.score(msg) print "| prob: %.5f" % prob if prob >= Options.options.spam_cutoff and self.prevent_access: print self.serverheaders print "text:", s[0:40], "...", s[-40:] return "not authorized" return s from proxy3_util import * register_filter('*/*', 'text/html', SpambayesFilter) print "Spambayes filter installed!" From other at cazabon.com Sat Aug 23 01:22:04 2003 From: other at cazabon.com (Kevin) Date: Sat, 23 Aug 2003 05:22:04 GMT Subject: Threading Oddity? References: Message-ID: <0SC1b.808163$ro6.16226551@news2.calgary.shaw.ca> use this instead and you're fine: import threading data_mutex = threading.Lock() using the thread module directly is depreciated, and the threading.Lock() object works as you expect without having to check if it's locked before acquiring it. Kevin "Kris Caselden" wrote in message news:abc3fdd3.0308222033.78c460ab at posting.google.com... > I noticed a strange yet easily fixed problem in Python's thread > module. > > Consider the following code: > > #------------------------------- > > import thread > > data='this is data' > data_mutex = thread.allocate_lock() > > def thread1(): > while data_mutex.locked(): > data_mutex.aquire() > print 'thread1:',data > if data_mutex.locked(): > data_mutex.release() > > def thread2(): > while data_mutex.locked(): > data_mutex.aquire() > print 'thread2:',data > if data_mutex.locked(): > data_mutex.release() > > thread.start_new_thread(thread1,()) > thread.start_new_thread(thread2,()) > > #------------------------------- > > This code runs as expected. However, take away the while loop checks > for mutex lock and Python is unable to properly acquire the lock, > complaining of an unhandled exception. The Python Library Reference > mentions that "this method acquires the lock unconditionally, if > necessary waiting until it is released by another thread (only one > thread at a time can acquire a lock -- that's their reason for > existence), and returns None." You'd think one wouldn't have to check > if the lock is locked, especially when acquire is supposed to wait for > the lock to be freed. At first, I thought this problem had to do with > aquire()'s waitflag, but the problem exists regardless of waitflag's > value. > > Does anyone know why this problem exists, and if my code works around > it? It would seem that locked() and acquire() would not necessarily be > run uninterrupted, and so mutual exclusion could not be guaranteed. From jacek.generowicz at cern.ch Tue Aug 19 10:28:50 2003 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 19 Aug 2003 16:28:50 +0200 Subject: What's better about Ruby than Python? References: <38ec68a6.0308181659.1aab5c67@posting.google.com> Message-ID: Alex Martelli writes: > Python's firmly in the "always half-open" field (pioneered in print, > to the best of my knowledge, in A. Koenig's "C Traps and Pitfalls", I seem to recall seeing a scanned-in copy of a hand-written talk by Dijkstra, on this. [I suspect it predates Andrew's oeuvre ... but then probably doesn't qualify on the "in print" requirement.] Anyone know what I'm talking about ? From sybrenUSE at YOURthirdtower.imagination.com Mon Aug 25 12:36:22 2003 From: sybrenUSE at YOURthirdtower.imagination.com (Sybren Stuvel) Date: 25 Aug 2003 16:36:22 GMT Subject: Coloring print lines References: Message-ID: Risto Per?nen enlightened us with: > If you're using python at X, best advice I canv give is Text-widget > at Tkinter and RTFM (sorry couldn't resist temptation :) . Otherwise > you probably have to fiddle with curses-library (unix-only). Most OSses understand ANSI. Even MS-DOS does, provided you load the right driver. Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? From detlev at die-offenbachs.de Tue Aug 19 13:13:49 2003 From: detlev at die-offenbachs.de (Detlev Offenbach) Date: Tue, 19 Aug 2003 19:13:49 +0200 Subject: advice choosing IDE References: <2lh711-1s2.ln1@stargate.solsys.priv> Message-ID: <6f2a11-633.ln1@stargate.solsys.priv> reh wrote: > Detlev Offenbach wrote: >>> >>> eric at http://www.die-offenbachs.de/detlev/eric3.html is a full IDE, >>> written in PyQt, that integrates with Qt Designer. It does the usual >>> editing, debugging, project management, class browsing - plus access >>> to source code control systems, syntax checking, unit testing, >>> profiling, code coverage. Latest snaphots include refactoring tools. >>> Etc, etc, etc. >>> >>> Phil >> >> And if there is something missing in the "etc, etc, etc" let me know >> and I'll try to implement it. >> >> Detlev > > Doing some work in eric between everything else, well done. > > Have a question on Calltips. Have it Enabled. Thought I would see > something like calltips for functions, but what I see is more > Autoconfig. Am I missing something. > You have to install some api files somewhere and configure their usage using the Preferences Dialog. Calltips and Autocompletion both use the API files. Detlev -- Detlev Offenbach detlev at die-offenbachs.de From klappnase at web.de Mon Aug 4 19:44:22 2003 From: klappnase at web.de (klappnase) Date: 4 Aug 2003 16:44:22 -0700 Subject: Tkinter programming problem References: <2830c89c.0308010048.403a2a19@posting.google.com> <2830c89c.0308040201.7c70695d@posting.google.com> Message-ID: > > > # Demonstration TK interface Windows application > # Runs ok from within IDLE > # > from Tkinter import * > > class CommonStuff: # to get common access to variables and functions > def __init__(self, frame): > self.frame = frame > > def say_hi(self): > print "Hello all" > > > class MyWidgets(Frame, CommonStuff): > def __init__(self, CS): > Frame.__init__(self, CS.frame) > self.quitbutton = Button(self, text='Quit', fg='red', > command=self.destroy) > self.quitbutton.pack(side=LEFT) > self.hi_there = Button(self, text='Hello', command=CS.say_hi) > self.hi_there.pack(side=LEFT) > > > class Application: > def __init__(self, master): > self.frame=Frame(master) > CS = CommonStuff(self.frame) > > displayedwidget=MyWidgets(CS) > displayedwidget.grid(row=0, column=0) > self.frame.grid(row=0, column=0) > displayedwidget.bind("", self.quit) > self.frame.update() > > def quit(self, event): > print"Quitting..." > self.frame.destroy() # Destroy frame and all children > > > root = Tk() > mainWin = Application(root) > root.mainloop() I think you could have it easier, if you just want to exit you application with the quit button: class MyWidgets(Frame, CommonStuff): def __init__(self, CS): Frame.__init__(self, CS.frame) self.quitbutton = Button(self, text='Quit', fg='red', command=self.quit) self.quitbutton.pack(side=LEFT) self.hi_there = Button(self, text='Hello', command=CS.say_hi) self.hi_there.pack(side=LEFT) def quit(self): print "Quitting..." sys.exit(0) If you want to run it from within the interpreter (I am not sure if it is that what you are trying) the following might work too: class Application: def __init__(self, master): self.frame=Frame(master) CS = CommonStuff(self.frame) displayedwidget=MyWidgets(CS) displayedwidget.grid(row=0, column=0) self.frame.grid(row=0, column=0) displayedwidget.bind("", self.quit) self.frame.update() self.master = master def quit(self, event): print"Quitting..." self.master.destroy() # Destroy root window However I would recommend to store the code in a file and then run the file. I am sorry that I cannot give you more detailed advice, but I am still a beginner, too. I hope this helped anyway. Good luck! Michael From skip at pobox.com Thu Aug 14 00:25:54 2003 From: skip at pobox.com (Skip Montanaro) Date: Wed, 13 Aug 2003 23:25:54 -0500 Subject: Here's one way you can help In-Reply-To: <16187.2806.1311.521238@montanaro.dyndns.org> References: <1rnljv8527o2phdjup4e9uji0kssf93svt@4ax.com> <16187.1433.780458.994728@montanaro.dyndns.org> <16187.2806.1311.521238@montanaro.dyndns.org> Message-ID: <16187.3922.290671.611413@montanaro.dyndns.org> Skip> See the patch I just submitted at Skip> http://python.org/sf/788509 Skip> .... Feel free to attach comments to it. I should point out that one of the most consistent needs on the development side of things is for people to review bug reports and patches. Such review can take many forms from, "I tried the patch. I worked for me on the SnarfBlatt 803" to critiques of writing, enhancing content (like attaching more glossary entries to the above patch) or submitting code which you feel addresses a bug or patch submission. Don't worry if you're not a C programmer or a LaTeX whiz. You can focus on Python language items and submit doc enhancements as plain text. How might you keep up-to-date on new bug reports and patches? It just so happens that every Sunday morning at 7AM a cron job runs which summarizes new bug reports and patch submissions for the Python project on SourceForge. That report is sent to the python-dev mailing list. Here's an example: http://mail.python.org/pipermail/python-dev/2003-August/037561.html If, like me, you suffer from a little bit rot and won't remember to visit the python-dev mailing list archives every now and again, let me know and I'll add you to the distribution. If enough people are interested, I'll start a Mailman-managed list expressly to catch that mailing. Skip From and-google at doxdesk.com Sun Aug 3 18:14:15 2003 From: and-google at doxdesk.com (Andrew Clover) Date: 3 Aug 2003 15:14:15 -0700 Subject: Python and XML References: Message-ID: <2c60a528.0308031414.4dfe171c@posting.google.com> "Matthieu M." wrote: > from xml.dom import pulldom > File "xml.py", line 1, in ? You have a file called 'xml.py' somewhere on the pythonpath, which is replacing the normal 'xml' package. However if it doesn't interfere when you try to import xml from the interpreter, likelihood is it's an xml.py file in the same directory as the program's script file - check there. For some reason, the current working directory is included in Python's default module search path, before all other directories. If anyone can explain why this is the Right Thing I'd be interested to know. -- Andrew Clover mailto:and at doxdesk.com http://www.doxdesk.com/ From fawcett at teksavvy.com Thu Aug 14 02:48:03 2003 From: fawcett at teksavvy.com (Graham Fawcett) Date: Thu, 14 Aug 2003 02:48:03 -0400 Subject: Thanks a lot! In-Reply-To: References: Message-ID: <3F3B30A3.8050409@teksavvy.com> Catherine Yang wrote: >Wow, you guys are *really fast and very helpful*. Thanks !!!!!!! > > We're merely trying to emulate our favourite language. ;-) -- Graham From thomasacross at hotmail.com Sat Aug 16 23:39:34 2003 From: thomasacross at hotmail.com (Tom Cross) Date: 16 Aug 2003 20:39:34 -0700 Subject: Replace every n instances of a string References: <62de87da.0308151325.41ea4622@posting.google.com> Message-ID: <62de87da.0308161939.7df45277@posting.google.com> Thanks very much everyone! I love the simplicity of Hans' answer to use a temporary string and the one-line variant is also awesome. -Tom From postmaster at earthlink.net Wed Aug 27 22:04:18 2003 From: postmaster at earthlink.net (Daniel T.) Date: Thu, 28 Aug 2003 02:04:18 GMT Subject: How to close a blocked socket? Message-ID: The code below fails. Socket.accept blocks inside the thread and doesn't let go, even after the socket was closed. From the error presented, the socket never actually closes. I realize that the below is a basic Java idiom but how do you do the same thing in Python? import unittest import socket import threading import time class SocketAcceptor ( threading.Thread ): def __init__( self, socket ): threading.Thread.__init__( self ) self.socket = socket def run( self ): self.socket.bind( ( "", 3423 ) ) self.socket.listen( 5 ) child, ip = self.socket.accept() class SocketTester ( unittest.TestCase ): def testClose( self ): for each in range( 4 ): ss = socket.socket() acceptor_thread = SocketAcceptor( ss ) acceptor_thread.start() time.sleep( 1 ) ss.close() if __name__ == '__main__': unittest.main() From irmen at -NOSPAM-REMOVETHIS-xs4all.nl Mon Aug 4 13:18:58 2003 From: irmen at -NOSPAM-REMOVETHIS-xs4all.nl (Irmen de Jong) Date: Mon, 04 Aug 2003 19:18:58 +0200 Subject: Developping an EAI server in Python : looking for developpers In-Reply-To: References: Message-ID: <3f2e9581$0$49107$e4fe514c@news.xs4all.nl> Alexander DEJANOVSKI wrote: > I'm starting a new project to develop an Open-Source EAI server in Python > and I'm looking for motivated developpers and testers. > It is inspired by Open Adaptor (_www.openadaptor.org_ > ), but aims to be easier > to use and more powerful. Could you please summarize what the goals of this project are? And how it relates to Open Adaptor? (which I don't have the time to read about). --Irmen From amk at amk.ca Tue Aug 19 08:58:36 2003 From: amk at amk.ca (A.M. Kuchling) Date: Tue, 19 Aug 2003 07:58:36 -0500 Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> <3F41505F.69D18CC8@alcyone.com> Message-ID: On Mon, 18 Aug 2003 15:17:03 -0700, Erik Max Francis wrote: > Roy Smith wrote: > My view of this is that if you really want to do this, you're better off > inventing a separate language -- however similar to Python -- and using > a processor to turn that language into real Python, which can then be > interpreted. In an interpreted language, especially one as dynamic as The problem is that writing such a processor is pretty messy. I've just been writing a translator for a supersmall subset of Python ('while', 'for', assignment, and that's it). While it was possible to do it with the Lib/compiler/ package, the code for parsing the subset and generating Python code from it is 12 screens long, ~300 lines of code. It's also difficult to change the keyword set; for now I'm simply disallowing variables named 'in', for example. Macros would generally be a compact way of doing this, though that compactness would have a cost (just like regular expressions are concise but not very readable). Perhaps the solution isn't macros, but some kind of Python-like-language parsing toolkit that's more easily customizable than the compiler package is. --amk From belred1 at yahoo.com Sat Aug 2 01:35:29 2003 From: belred1 at yahoo.com (Bryan) Date: Sat, 02 Aug 2003 05:35:29 GMT Subject: pyrex error Message-ID: i'm having trouble building the pyrex demos. i also can't compile a simple hello word example. i keep getting this '__pyx_f' unknown size error. here's the error i'm getting when executing the following script. i'm using vc 6.0 on windows xp python 2.3 thanks, bryan ------- setup.py from distutils.core import setup from distutils.extension import Extension from Pyrex.Distutils import build_ext setup( name = 'Demos', ext_modules=[ Extension("primes", ["primes.pyx"]), Extension("spam", ["spam.pyx"]), Extension("numeric_demo", ["numeric_demo.pyx"]), ], cmdclass = {'build_ext': build_ext} ) ------- C:\python\pyrex\Pyrex-0.8.2\Demos>setup build running build running build_ext building 'primes' extension C:\Program Files\Microsoft Visual Studio\VC98\BIN\cl.exe /c /nologo /Ox /MD /W3 /GX /DNDEBUG -IC:\python\python23\include -IC:\python\python23\PC /Tcprimes.c /F obuild\temp.win32-2.3\Release\primes.obj primes.c primes.c(27) : error C2133: '__pyx_f' : unknown size error: command '"C:\Program Files\Microsoft Visual Studio\VC98\BIN\cl.exe"' fail ed with exit status 2 From skip at pobox.com Thu Aug 14 08:45:20 2003 From: skip at pobox.com (Skip Montanaro) Date: Thu, 14 Aug 2003 07:45:20 -0500 Subject: 3 new slogans In-Reply-To: References: Message-ID: <16187.33888.71251.572827@montanaro.dyndns.org> >> s/(perl|java|vba|c(#|\+\+|)?)/python/g Michael> .. but - as *any* regex - can be improved: Michael> s/\b(perl|java|vba?|c(#|\+\+|)?)/python/gi We ought to at least use Python for this re.sub(r"(?i)\b(perl|java|vba?|c(#|\+\+|)?)", "python") >>> import re >>> s = "vba vb perl java vba vb c# c c++" >>> re.sub(r"(?i)\b(perl|java|vba?|c(#|\+\+)?)", "python", s) 'python python python python python python python python python' Skip From stuart at bmsi.com Sun Aug 24 01:04:38 2003 From: stuart at bmsi.com (Stuart D. Gathman) Date: Sun, 24 Aug 2003 01:04:38 -0400 Subject: email bug? References: Message-ID: On Sun, 24 Aug 2003 00:14:45 -0400, Andrew Dalke wrote: > A quick scan of the code suggests that it isn't a quick fix (eg, not > just a matter of tweaking that regexp. Here is my quick (and probably incorrect) fix: from email.Message import Message from email.Utils import unquote # helper to split params while ignoring ';' inside quotes def _parseparam(str): plist = [] while str[:1] == ';': str = str[1:] end = str.find(';') while end > 0 and (str.count('"',0,end) & 1): end = str.find(';',end + 1) if end < 0: end = len(str) f = str[:end] if '=' in f: i = f.index('=') f = f[:i].strip().lower() + \ '=' + f[i+1:].strip() plist.append(f.strip()) str = str[end:] return plist class MimeMessage(Message): def getparam(self,name,header='content-type'): for key,val in self.getparams(header): if key == name: return unquote(val) return None # like get_params but obey quotes def getparams(self,header='content-type'): "Return all parameter names and values. Use parser that handles quotes." val = self.get(header) result = [] if val: plist = _parseparam(';' + val) for p in plist: i = p.find('=') if i >= 0: result.append((p[:i].lower(),unquote(p[i+1:]))) return result -- Stuart D. Gathman Business Management Systems Inc. Phone: 703 591-0911 Fax: 703 591-6154 "Confutatis maledictis, flamis acribus addictis" - background song for a Microsoft sponsored "Where do you want to go from here?" commercial. From grante at visi.com Tue Aug 12 14:12:49 2003 From: grante at visi.com (Grant Edwards) Date: 12 Aug 2003 18:12:49 GMT Subject: Is Python your only programming language? References: <3f38fbf3$0$158$a1866201@newsreader.visi.com> <2259b0e2.0308120912.53b28d6f@posting.google.com> Message-ID: <3f392e21$0$178$a1866201@newsreader.visi.com> In article <2259b0e2.0308120912.53b28d6f at posting.google.com>, Michele Simionato wrote: >> Anybody who thinks there's only one programming language for >> all tasks is seriously deluded. > > Yes, but a programmer does not necessarily need to perform ALL > tasks. Good point. I forget that others jobs may be more narrowly defined than mine. Not everybody has to range from embedded assembly language, to GUI apps, to Linux drivers, to CGI, to ASP. > It may very well be that Python fullfill 99% of what an average > programmer needs. I personally know various languages, but at > the end I only use Python since it fullfills all my needs and > it is faster to develop in it that in any other language. -- Grant Edwards grante Yow! What a at COINCIDENCE! I'm an visi.com authorized "SNOOTS OF THE STARS" dealer!! From Mike at DeleteThis.Geary.com Mon Aug 18 21:31:06 2003 From: Mike at DeleteThis.Geary.com (Michael Geary) Date: Mon, 18 Aug 2003 18:31:06 -0700 Subject: What's better about Ruby than Python? References: <38ec68a6.0308172319.431a4fde@posting.google.com> Message-ID: > Brandon J. Van Every wrote: > > > > Man, it's clear that I've got an entire hate group around here to > > exterminate! I wonder how long it's going to take? Maybe this is a > > positive sign of Python's growth: it's got enough critical mass to attract > > just about anybody, not just people who want to get things done. At any > > rate, welcome to my killfile. Cliff Wells wrote: > > The major problem appears to be your mode of communication. At first I > took your questions seriously, then I began to think you were trolling > (and a rather clever troll at that), and finally I've come to the > conclusion that you're not trolling, rather merely arrogant and > abrasive. You seem to get a large number of people who perceive you as > a troll. While I no longer believe this to be true, the sheer number of > people in so many different newsgroups should perhaps indicate to you > that you need to take a break from your local D&D group and socialize a > bit. You are lacking some fundamental skills in this area. You're > clearly intelligent and have in fact brought up some interesting topics, > but your lack of tact tends to take them off-track rather quickly. > > For instance, do you really think publicly announcing that someone is in > your killfile hurts their feelings or somehow vindicates you? That's > rather pathetic, but makes sense given the source. I'd venture that > mentality is most common at the pre-teen level of social interaction. Cliff, welcome to Brandon's killfile. I'll buy you a beer as soon as I get there. You may not have to wait long. ;-) Brandon, you would do well to take a deep breath, read and understand Cliff's message. You may not like it, but it's extremely perceptive, and it would do you a world of good to take his advice to heart. When you started the Python vs. Java thread a few days ago and the first couple of people ragged on you, I stood up for you, saying that I found your message interesting and thought-provoking. I deliberately chose not to google your previous conversations, figuring that anybody deserves a fresh start. But my goodness! Now I can see what all the fuss was about. You even killfiled Doug Tolton, who made some very insightful comments about the benefits of macros today in this Ruby thread. A single friend of my wife's recently moved to Tacoma, Washington, because she wasn't satisfied with the quality of the people (read: men) she was meeting here in San Jose. She was shocked--shocked!--to find that the people in Tacoma were no different from the ones down here. I had to wonder if there just might have been *something* in common between the people she met in San Jose and the people she met in Tacoma. Brandon, learn to roll with the punches and have some fun with the rest of us. What good does it do *you* when you say to someone, "You said something I don't like. You failed to satisfy my needs in this conversation. I will never listen to anything you ever say again!" Would you do that in a face to face conversation? I didn't think so. So try this: delete that silly killfile, cultivate the sense of humor you've shown in the rattlesnake thread--I knew you could do it!--and be willing to say, "Folks, I know I've been a bit abrasive and antagonistic in the past, and I apologize for that. I really would like to get a fresh start here and I'm curious to hear your thoughts on these questions." Fair enough? -Mike From jjl at pobox.com Mon Aug 18 09:43:06 2003 From: jjl at pobox.com (John J. Lee) Date: 18 Aug 2003 14:43:06 +0100 Subject: ClientCookie bug (followup) References: <87fzk4sav2.fsf@pobox.com> <87znibzrnx.fsf@pobox.com> <87oeypdh92.fsf@pobox.com> Message-ID: <87oeyn6pzp.fsf@pobox.com> Gary Feldman writes: > On 16 Aug 2003 11:33:13 +0100, jjl at pobox.com (John J. Lee) wrote: > > > > >Take note of this comment from the web page: > > > >| # Don't copy this blindly! You probably want to follow the examples > >| # above, not this one. > > Since the purpose of that example seems to be to show how things work under > the hood, may I suggest putting it on a separate page, and replacing it > here with something like "Here is a lower level example that > shows how this works, though you would rarely want to implement things at > this low level." Hmm, good idea, but I really don't want to split the documentation up -- one page is simpler -- and the example is instructive for people who actually want to understand what the module does. And if people manage to miss that comment (highlighted in orange, for heavens sake), well... John From vanevery at 3DProgrammer.com Tue Aug 12 04:57:48 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Tue, 12 Aug 2003 01:57:48 -0700 Subject: Python vs. C# References: <2259b0e2.0308100616.55b651ca@posting.google.com> <3f36af20@shknews01> <0b0hjv4q40mdf3msnur9q4bcih3tqb8iq3@4ax.com> Message-ID: Doug Tolton wrote: > > I've used C# full time for over two years. Finally I got disgusted > with it and swtiched my entire company over to Python. > > Python: > -Internally consistent, cleanly designed, to the point of being > beautiful > -Dynamic typing is amazing > -First class functions (try mimicking that in C# - ha) > -Tuple unpacking is a god send > -List types are the cats meow > -Dictionaries are blazingly fast > -using metaclasses and the magic methods gives you amazing power and > flexibility > (this is just the beginning of a long list) In your "Python pros" list, you didn't name any kind of Windows system interface component at all. What kind of Python development on Windows are you actually doing? -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From wilkSPAM at OUTflibuste.net Sat Aug 9 13:01:47 2003 From: wilkSPAM at OUTflibuste.net (Wilk) Date: Sat, 09 Aug 2003 19:01:47 +0200 Subject: % Documentation References: Message-ID: <87y8y2lq84.fsf@flibuste.net> Simon Bayling writes: > Hello, > > Where is the % operator documented? http://www.python.org/doc/current/lib/typesseq-strings.html > I was looking for ages yesterday, Python.org, browsing the documentation > for modules, the tutorial, searching for it, trying help(%), using Google, > and so on. > I found that locale.format works like the % operator... how useful ;) > > if someone could point me towards it, that would be great... > > (Also, what is the proper name for it? String interpolation? String > substitution? Percent-substitution?) > > Cheers, > Simon. -- William Dode - http://flibuste.net From alan.gauld at btinternet.com Tue Aug 12 18:22:11 2003 From: alan.gauld at btinternet.com (Alan Gauld) Date: Tue, 12 Aug 2003 22:22:11 GMT Subject: Is Python your only programming language? References: Message-ID: <3f396773.673838@news.blueyonder.co.uk> On Tue, 12 Aug 2003 05:44:45 GMT, "Joe Cheng" wrote: > I want to ask you hard-core c.l.p Pythonistas: Do you use Python for > everything? I'm not sure I'm "hard core" but I use Python most days. However most projects I work on use many programming languages - I think the record was 12 languages on 1 project. An average is probably around 5. I use Python mainly for prototyping and proof of concept work during design, the results get turned into C++, Java, COBOL or assembler depending on the project. In theory we could use Python for an embedded scripting language but Tcl and VBScript have already grabbed that slot in our corporate armoury... > finally, do you foresee a day when Python can be, for all practical intents > and purposes, your only programming language? Nope, there will always be places where I want to use Lisp or Prolog. Even awk is better for some things. And when the code really gets down n' dirty nothing beats raw C and assembler... Alan G. Author of the Learn to Program website http://www.freenetpages.co.uk/hp/alan.gauld From michael.kier at hp.com Fri Aug 29 10:03:33 2003 From: michael.kier at hp.com (Mike Kier) Date: Fri, 29 Aug 2003 14:03:33 GMT Subject: python and webcam?? References: <3F4F56AB.19EFE5AB@engcorp.com> Message-ID: "Peter Hansen" wrote in message news:3F4F56AB.19EFE5AB at engcorp.com... > Mirco wrote: > > > > Hi, > > I'd like to know if is it possible to make python communicate with a > > webcam. Of course, I think it is possible... but I don't know if there > > is a specific module for this kind of work. Can anyone give me a council? > > Depends a lot on the type of webcam, but in any case it's a pretty > safe bet that (a) it's possible, and (b) there is no *specific* module > for the task. > > That said, there are things like PIL which could be of use in this area, > and at least one specific webcam package (probably using calldll to get > to the library for the device) that has been posted in the past. > > -Peter Try this... http://videocapture.sourceforge.net/ -- Mike Kier HP Consulting & Integration Services Cincinnati, OH, USA mike.kier at hp.com From bokr at oz.net Tue Aug 12 12:15:21 2003 From: bokr at oz.net (Bengt Richter) Date: 12 Aug 2003 16:15:21 GMT Subject: get line number References: Message-ID: On 12 Aug 2003 12:34:58 GMT, Richard Mertens wrote: >How do get the actual line number from the actual running sourcecode. >I need it for debugging purpose > >>> import inspect >>> def linehere(): ... return 'line %s in %r'%tuple(inspect.getframeinfo(inspect.currentframe().f_back)[1:3]) ... >>> def foo(): ... x=1 ... y=2 ... here = linehere() ... z = 4 ... return linehere(), here ... >>> foo() ("line 6 in 'foo'", "line 4 in 'foo'") The inspect module also has much more that might be of help. Regards, Bengt Richter From sjmachin at lexicon.net Tue Aug 12 15:44:16 2003 From: sjmachin at lexicon.net (John Machin) Date: 12 Aug 2003 12:44:16 -0700 Subject: Possible to install from CD using distutils? References: Message-ID: Martin v. L wis wrote: > "Simon Wittber (Maptek)" writes: > > >Try this command. It will let you write to a CD drive. > > > >mount -o rw /dev/cdrom /mnt/cdrom > > Did you try this? You can't mount a cdrom rw - the hardware just does > not support writing to a CD-*ROM* (Read-Only Memory). I tried it but the computer typed this back at me: 'mount' is not recognized as an internal or external command, operable program or batch file. What is this "mount"? Where can I get it from? From jimmy at retzlaff.com Thu Aug 21 07:30:50 2003 From: jimmy at retzlaff.com (Jimmy Retzlaff) Date: Thu, 21 Aug 2003 04:30:50 -0700 Subject: how fast is Python? Message-ID: Alex Martelli wrote: > Irmen de Jong wrote: > ... >> Nevertheless, a Psyco-optimized piece of Python code >> that runs as fast as compiled C is still very impressive >> to me. I know that JIT compiler technology theoretically >> could produce better optimized code than a static optimizing >> compiler, but am happy already if it reaches equal level :-) > > If anybody does have an actual example (idealy toy-sized:-) > where psyco's JIT does make repeatably faster code than a > C compiler (well-used, e.g. -O3 for gcc, NOT just -O...!-) > I'd be overjoyed to see it, by the way. In a way this comes back to practicality vs. purity. In a synthetic benchmark where one function is called repeatedly with homogeneous data, it's hard to imagine that a JIT compiler could ever outperform a good optimizing C compiler. But that's the pure side of a performance analysis. The practical side is how that function performs in a real application where a JIT for a dynamically typed language has much more information to work with than a C compiler does. For example, a C compiler might only know that you declared a parameter as a double and so it can only optimize for that. If you happen to call the function more often than not with an int (that gets promoted to a double on the way in) then the compiler generated code may waste a good deal of time doing floating point arithmetic rather than integer arithmetic. Now the programmer might take the time to profile their C program and hopefully notice that time is being wasted doing floating point arithmetic and then create an int version of their function, but often practical constraints will get in the way of this happening. This brings back memories of the old arguments about optimizing C compilers being able to generate faster code that hand written assembly. Of course an expert at assembly could write a faster program given enough time, but most people didn't have the time or expertise to write assembly code that could perform as well as optimized C once the compilers attained a certain level of sophistication. In many practical situations C is faster than assembly. PyPy is exciting because it presents hope of providing the JIT with enough extra information and flexibility that it may be able to make practical Python code outperform practical C code in many cases. The example above involving double/int was not just an example. It happened in an application of mine a while back. I replaced a function in a C extension with a Psyco-compiled Python version of the same function and the performance of the part of my application that used the function doubled. I posted a couple of notes about it. The first is about a test in isolation (the pure test) and C was faster: http://tinyurl.com/kpgd (includes Python code and links to C code) The second note came later after I decided the slightly slower Python/Psyco version was fast enough to eliminate the headaches of maintaining the C extension. After replacing the C code I was startled by a performance improvement in my application. This is the about the practical test: http://tinyurl.com/kpg6 And finally a bit of a caveat: http://tinyurl.com/kpid Jimmy From andrew-pythonlist at puzzling.org Tue Aug 12 08:49:03 2003 From: andrew-pythonlist at puzzling.org (Andrew Bennetts) Date: Tue, 12 Aug 2003 22:49:03 +1000 Subject: Howto MACRO in python ? In-Reply-To: <001201c360cd$3da065b0$6400a8c0@EVOD31> References: <3F38D039.2B28800A@engcorp.com> <001201c360cd$3da065b0$6400a8c0@EVOD31> Message-ID: <20030812124903.GA5631@frobozz> On Tue, Aug 12, 2003 at 02:28:31PM +0200, Bill Loren wrote: > Welp, I'm trying to implement some kind of tracing mechanism which will > announce every function entrance > in Run-Time. > I wrote a trace function: [...] You don't need macros for this. Use sys.settracehook. -Andrew. From warlock at eskimo.com Sun Aug 3 01:16:51 2003 From: warlock at eskimo.com (Jim Richardson) Date: Sat, 2 Aug 2003 22:16:51 -0700 Subject: Match beginning of two strings References: Message-ID: <3fiuv-aai.ln1@grendel.myth> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Sat, 02 Aug 2003 23:14:10 -0400, Ravi wrote: > >> Are you trying to match any to any strings? or only a pair as above? >> > > Just a pair at a time, and I only want the first N characters that are > common to both strings. The os.path.commonprefix works nicely. Thanks > for your help. > > Ravi > Well, it wasn't me, but you're welcome anyway :) -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (GNU/Linux) iD8DBQE/LJrDd90bcYOAWPYRAlD9AJ9mqKMhx5if6eZ+i9vMuVkAsmfLugCgs2RE A6o4gDz8qa/YhpjSoHdTwJo= =ZAWM -----END PGP SIGNATURE----- -- Jim Richardson http://www.eskimo.com/~warlock Linux, because eventually, you grow up enough to be trusted with a fork() From jane.doe at acme.com Mon Aug 11 10:46:43 2003 From: jane.doe at acme.com (Jane Doe) Date: Mon, 11 Aug 2003 16:46:43 +0200 Subject: Python + Zope compared to J2EE and .Net References: <74bd3bc.0308100707.577f2930@posting.google.com> Message-ID: On 10 Aug 2003 08:07:50 -0700, webmestre at drsigmund.levillage.org (Sig) wrote: > - cons => Zope may be to heavy for simple needs we could easily >manage with PHP, Zope skills are rather rare of the market whereas PHP >is now quite easily available. Zope has indeed a steep learning, less so for people who are already used to developing web apps. For something Zope-like but lighter and still Python-based, you might want to look at other solutions : SkunkWeb Twisted Draco Albatross Quixote WebWare + Cheetah CherryPy HTH JD. From usenet_spam at janc.invalid Sat Aug 16 00:02:19 2003 From: usenet_spam at janc.invalid (JanC) Date: Sat, 16 Aug 2003 04:02:19 GMT Subject: Help from someone with new PKWare zip program References: <3f3d3e70$1@nntp0.pdx.net> Message-ID: Scott David Daniels schreef: > PKWare has specified a new compression method (ZIP_BZIP2=12) for .zip > files. This format provides (or can provide) very good compression. > Since python now has the bz2 module, I thought I'd try to teach the > zipfile module to read and write ZIP_BZIP2 compression as well as its > current ZIP_DEFLATE format. > > If there is somebody out there with a copy of the PKWare program, > I'd like a small ZIP file compressed with that format, in order to > verify that I correctly produce / consume such files. Once I trust > my code is correct, I'll release it. There are a free evaluation copies here: Works for 30 days & registration is required... -- JanC "Be strict when sending and tolerant when receiving." RFC 1958 - Architectural Principles of the Internet - section 3.9 From sdhyok at yahoo.com Sun Aug 10 15:21:10 2003 From: sdhyok at yahoo.com (sdhyok) Date: 10 Aug 2003 12:21:10 -0700 Subject: How to print floating point in scientific format? References: <420ced91.0308081115.7060e551@posting.google.com> <420ced91.0308090642.176b856b@posting.google.com> Message-ID: <420ced91.0308101121.7002ec9@posting.google.com> Cousin, you are right. But, do you want to write for loops whenever you print arrays? Maybe not if you are a hard-core scientific programmer. "Cousin Stanley" wrote in message news:... > The conversion to e format in the print statement > seems to work OK if I iterate over the items in the array .... > > >>> import Numeric as N > >>> > >>> x = N.arange( 10. ) > >>> > >>> print x > [ 0. 1. 2. 3. 4. 5. 6. 7. 8. 9.] > >>> > >>> for this_item in x : > ... print '%e' % this_item > ... > 0.000000e+000 > 1.000000e+000 > 2.000000e+000 > 3.000000e+000 > 4.000000e+000 > 5.000000e+000 > 6.000000e+000 > 7.000000e+000 > 8.000000e+000 > 9.000000e+000 > >>> From graham at rockcons.co.uk Thu Aug 7 09:44:16 2003 From: graham at rockcons.co.uk (Graham Nicholls) Date: Thu, 07 Aug 2003 14:44:16 +0100 Subject: Need to convert an arbitrary byte-pair to an int. References: <3f323dc2$0$10775$afc38c87@auth.uk.news.easynet.net> Message-ID: <3f3257ba$0$18274$afc38c87@auth.uk.news.easynet.net> Alex Martelli wrote: > Graham Nicholls wrote: > >> I'm trying to size a jpeg file. The file size is held in a short (2 byte >> integer) at a certain offset. Once I've found these two bytes (they're >> in MSB,LSB order), I need to convert them to an integer - now I know that >> in C I'd just cast a pointer to the offset to a short, and that python >> doesn't >> cast, so how can I extract the value from a stream of bytes. I've looked >> at python.org/Doc/current (I'm using 2.3b1), but can't find anything >> obvious. > > I see you've already been pointed to a 3rd party package that's useful for > handling images, but just in case you to need to solve in the future the > actual problem you pose in the subject, one elementary way might be: > > thefile = open('whatever', 'rb') > thefile.seek(theoffset) > msb = thefile.read(1) > lsb = thefile.read(1) > theint = ord(lsb) + ord(msb) * 256 ^^^^^^^^^^^^^^^^^ This is what I was trying to do, only getting confused with abs, atoi and various other invocations which either dont exist or don't do what I wanted them to. > > The struct module, which I see has also been pointed out to you already, > would let you compact the last three statements into one. And IMO is rather more elegant. > So, in this > specific case, would the array module. Both struct and array are part > of the standard Python library and often come in handy for occasional > needs of low-level access, such as this. Trouble is, you don't know what you don't know, and my python library reference is at home, and I'm onsite. > > > Alex Alex (and Richard), Thanks for that. The struct module was just what I was after. (I cancelled my reply which implied that the 3rd party module was the answer, when in fact, I'd meant to say that using struct is _exactly_ what I want). Jpeg files have a header, then a series of segments, each of which contains within it the segment size, so using a struct (just like in c, really) is a great way to read the segment type and size. BTW, I posted a month or so back wondering about the merits of Python, which I already much prefer to perl, but I've sort of simultaneously been learning Ruby & Python. Not sure which I prefer, yet, but I think that a reasonable knowledge of both, perhaps with in depth understanding of one of them, would be useful. Python seems to have more modules, and I do like lots of things about it, but Ruby _seems_ cleaner, somehow. Its an interesting exercise, trying to learn both (whilst being quite busy). Thanks again. -- Graham Nicholls Rock Computer Consultancy From ryanlowe0 at msn.com Thu Aug 21 20:39:40 2003 From: ryanlowe0 at msn.com (Ryan Lowe) Date: Fri, 22 Aug 2003 00:39:40 GMT Subject: crazy programming language thoughts Message-ID: disclaimer: this is a little out-there, primarily a thought excersise for myself. it probably belongs in group on programming language theory. but python got me thinking about this, so here it is. and dont worry, its NOT a change proposal. one of the things i love about python is its use of the actual words or/and/not/is/in, where other languages would use symbols ||/&&/?!@#$%, what have you. the symbols dont save you much typing (especially if you count the shift key), but are merely something extra to learn and remember. i also like how python did away with the unneccesary parentheses in for/if/while statements. soooo ive been toying with the idea of getting rid of parens in functions too (ive just been reading the ruby tut and noticed parens are optional in some cases which is cool, but trust me this is different) the basic concept would be to use identifying words in front of the arguments to determine their identity as well as making the function call read more like an english phrase. for instance, take the simple python statement: >>> vtext.replace('a', 'b') wouldnt it be nicer (more english-like at least) to say: >>> replace 'a' with 'b' in vtext since the arguments have an identifying word (with, b) (in, vtext), the order isnt important (other than the first 'anchor' word(s)), so we could instead have said: >>> replace 'a' in vtext with 'b' or >>> replace in vtext 'a' with 'b' ignoring that the last version is a little awkward to say, the advantage is immediate understandability; each parameter's contribution is explicitly stated so you dont have to guess or look up what each arg of a many-arg function does. of course, you could forget what words go in front of the args (e.g. was it 'in vtext' or 'from vtext'?), but since its english-like i think less so. plus an editor could give you hints like many do now. you may be thinking about keyword inflation. however, the parser would consider the whole set of words together, so the 'in' in the above wouldnt be bound to the meaning it has in a for statement. worst case scenario, a naming convention like the v in front of variable names could be used to aid parsing, but i think it may be possible to disambiguate without such a convention. i just want to say that i know i saw a similar idea in another language, a few years ago, but damned if i remember where or what language. i guess the language didnt make it:( but if anyone knows a language like this, PLEASE let me know. anyway, this is all well and good for this simple example, but lets see how it scales up. once you get familiar with finctions and dot syntax, you probably started chaining them together. it saves time and space and after not so long it becomes pretty easy to write and understand something like this: >>> v = '/n'.join(file('file.txt').readlines()).lower().split('.') but think back to when all this stuff was new. you probably would have written: >>> f = file('file.txt') >>> v = f. readlines() >>> v = '\n'.join(v) >>> v = v.lower() >>> v = v.split('.') it may be a little clearer, especially to a beginner, but its not nearly as convenient. now take a look at this: >>> v = read lines from 'file.txt'; join it with '\n'; lower it; split it at '.' i showed this to a couple non-programmers, and they fould it much easier to interpret than the first way (i didnt show them the second way). here i do introduce a new keyword 'it' which you can probably guess contains the return value of the statement to the left of the semicolon. you could add a 'them' keyword for aggregates (as in the join part) if you are a grammar stickler. ill stop here before i put people completely to sleep. im curious what people think about this. im not concerned with 'minor' problems like the speed of a parser that could handle this. id like instead to hear comments, concerns, reguarding the theory. id especially like any links people might know about interesting experimental programming languages. From irmen at -NOSPAM-REMOVETHIS-xs4all.nl Sun Aug 3 08:07:22 2003 From: irmen at -NOSPAM-REMOVETHIS-xs4all.nl (Irmen de Jong) Date: Sun, 03 Aug 2003 14:07:22 +0200 Subject: Python Windows 2.3 Installer problems In-Reply-To: References: Message-ID: <3f2cfaf8$0$49106$e4fe514c@news.xs4all.nl> Christopher Koppler wrote: > Apart from that I can only list everything that made problems in my > earlier life as a sysadmin/network tech, in increasing order of > unlikeliness: [... a whole bunch of things to try...] First, as I've said in another thread, try installing when booted in 'safe mode'. --Irmen From peter at engcorp.com Thu Aug 14 11:15:13 2003 From: peter at engcorp.com (Peter Hansen) Date: Thu, 14 Aug 2003 11:15:13 -0400 Subject: Determine file type (binary or text) References: Message-ID: <3F3BA781.66A5FDDD@engcorp.com> "David C. Fox" wrote: > > Sami Viitanen wrote: > > Thanks for the answers. > > > > To be more specific I'm making a script that should > > identify binary files as binary and text files as text. > > > > The script is for automating CVS commands and > > with CVS you have to add the -kb flag to > > add (or import) binary files. (because it can't itself > > determine what type the file is). If binary file is not > > added with -kb the results are awful. > > > > You should note that the question of when to use -kb is not simply based > on the contents of the file, but on whether you want CVS/RCS to try to > merge conflicting versions. > > For example, I recently added some files containing pickled objects > (used as test data sets for a regression test) to the CVS repository for > my project. Although the pickle files are in fact all printable text, a > CVS/RCS merge of two valid pickle files won't yield a valid pickle file. > Therefore, I used -kb to ensure that the developer would always be > forced to choose a version in the event of a version conflict. Exactly. We had the same issue with the project files for the Codewright text editor. They are sort of like Windows .INI files, but merging such files leads to complete disaster, including inability to run Codewright until the files are manually fixed or removed! -Peter From newsgroups at jhrothjr.com Fri Aug 1 07:16:42 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Fri, 1 Aug 2003 07:16:42 -0400 Subject: time, calendar, datetime, etc References: Message-ID: "Christopher Koppler" wrote in message news:f6ojivk3c87s8memo970n7v0hj6gdb32s4 at 4ax.com... > On Thu, 31 Jul 2003 22:49:28 -0400, "Tim Peters" > wrote: > > >The time module consists of thin wrappers around C's mish-mash of quirky, > >platform-dependent time manipulation functions. We eventually want to > >pretend the time module never existed <0.9 wink>. 9-tuples are absurd. > > No, it's reality that's absurd. C's mish-mash of quirky, > platform-dependent time manipulation stems from the fact that defining > a standard way of handling time is difficult when it's > 1. subject to the platform designers interpretation of what is useful, > 2. subject to politics and most severely, > 3. subject to changes in nature. > > Leap seconds! Frankly, if what was wanted was a single, consistent and usable definition of time, the astronomical Julian date is it. It's a single number, absolutely continuous since 4712 BC or thereabouts, and has well defined conversions to and from the proleptic Gregorian and Julian calendars. It takes me about two clicks to determine that the current AJD is 2452852.9650. Anything else is politics and poor analysis. The funny thing is, it wouldn't be all that hard to fix. The only part of the formal API that I can see which is even remotely affected is the fromordinal() method, and there's no reason to change it, just to define it as only being effective from 1AD onwards. All that's needed, really, is a constructor that takes the AJD, and an extraction method for it. Since the package doesn't have any string to date conversion routines (presumably yet,) not even that's affected. John Roth > > > --Christopher From RaoulGough at yahoo.co.uk Thu Aug 21 11:49:16 2003 From: RaoulGough at yahoo.co.uk (Raoul Gough) Date: Thu, 21 Aug 2003 16:49:16 +0100 Subject: Misleading description of [i:j:k] slicing? Message-ID: As of Python 2.3, Section 2.2.6 (Sequence Types) describes slices which have a specified step (to omit some indexes in beteween), using the notation s[i:j:k]. The note about how this works says: "The slice of s from i to j with step k is defined as the sequence of items with index x = i + n*k such that 0 <= n < abs(i-j). [...]" Seems to me that "0 <= n < abs(i-j)" is wrong, since the range of n gets multiplied by k. I would suggest that it should be something like: "x = i + n, such that n is a multiple of k and 0 <= n < abs(i-j)" or maybe better "x = i + n*k, 0 <= n < ((j-i) / k)" (Requiring j>i for positive k and j>> x=[0,1,2,3,4,5,6,7,8,9] >>> print x[0:5:2] [0, 2, 4] # Would print [0, 2, 4, 6, 8] according to doc? >>> print x[2:5:-2] [] # Would print [2, 0, 8] according to doc?? I was going to submit a bug, but then I realised that I might just be mis-interpreting what the documentation says (or maybe it'd not even supposed to be so precise a specification). Any comments or confirmation on this? -- Raoul Gough "Let there be one measure for wine throughout our kingdom, and one measure for ale, and one measure for corn" - Magna Carta From jamwt at jamwt.com Thu Aug 28 13:13:52 2003 From: jamwt at jamwt.com (J Turner) Date: Thu, 28 Aug 2003 10:13:52 -0700 Subject: Curses, Terminal Settings Message-ID: <20030828171352.GA68457@stan.jamwt.com> Hello, I'm playing with a python-based shell, which uses (guess what?) python as it's scripting language, for iterative invocation, environment variables, etc. Everything was going well, until I moved beyond sys.readline() into curses territory to flesh out the line-editing capabilities. Curses always seems to get me. The problem I'm having is described here: I call the following things to get the terminal into a the state I want, and then back out of it: def _pysh_cursesInmode(): curses.noecho() curses.raw() stdscr.keypad(1) stdscr.idlok(1) stdscr.scrollok(1) curses.nonl() def _pysh_cursesOutmode(): curses.echo() curses.noraw() stdscr.keypad(0) stdscr.idlok(0) stdscr.scrollok(0) curses.nl() Then, if a line, or an `inline command`, is determined to be a program invocation, the shell piggybacks onto bash for forking/exec ing, piping, and all that jazz, with a 'bash -noprofile -c "cmd"'. When I call out to bash, I obviously want the terminal back in a non-curses state. I want to undo *all* the changes so that when bash, ls, ps, etc, starts up, the terminal is in a sane state when they write to stdout. Despite calling the Outmode() function listed above, the terminal is not in this state. Newlines don't return the output to position 0, though they do advance down a line. like this Here's a real example. zsh: (10:06:38)jamwt/ % ls LICENSE Maildir bin doc lists scrib vault Mail att devel etc public tmp web (10:06:38)jamwt/ % ls bash through python curses: $ ls LICENSE Maildir bin doc lists scrib vault Mail att devel etc public tmp web $ ... and something like 'top' looks just terrible. I really don't know what else to do besides undo the changes I've made! That seems to be what I'm doing with the mode functions above.. what am I missing? This is the end of the problem description. Thanks. Here's a look at the pre-curses shell: (10:09:41)jamwt/ % pysh $ ls LICENSE Maildir bin doc lists scrib vault Mail att devel etc public tmp web $ for item in `ls`.split("\n"): print item[:3] > LIC Mai Mai att bin dev doc etc lis pub scr tmp vau web $ FOO = "bar" $ import sys $ BAR = sys.version $ export FOO $ export BAR $ env FTP_PASSIVE_MODE=YES ... etc .. BAR=2.3 (#1, Jul 31 2003, 00:45:11) [GCC 2.95.4 20020320 [FreeBSD]] ... etc .. FOO=bar - Jamie From jjl at pobox.com Fri Aug 29 14:32:19 2003 From: jjl at pobox.com (John J. Lee) Date: 29 Aug 2003 19:32:19 +0100 Subject: OT: Dying Americans References: <3F4E7ED9.924AEAF2@engcorp.com> Message-ID: <87isogqpqk.fsf@pobox.com> Lulu of the Lotus-Eaters writes: > Dave Brueck wrote previously: [...] > However, the CDC lists 2804 deaths from adverse effects in medical care, > or about 1 per 100k. [...] I'm very surprised -- that sounds way too low. Where is this category defined? Even when carefully defined in some sensible way, there must be big uncertainties due to the present lack of knowledge about drug interactions, and about other treatments causing hard-to-measure increases in mortality over the long term. Epidemiology is a blunt instrument, and we're still at an early stage in understanding diseases. Erm, anyone know the figures for mortality due to Pythons? John From skip at pobox.com Wed Aug 20 14:08:07 2003 From: skip at pobox.com (Skip Montanaro) Date: Wed, 20 Aug 2003 13:08:07 -0500 Subject: ascii2dec In-Reply-To: References: Message-ID: <16195.47367.215168.783956@montanaro.dyndns.org> Uwe> i.e. Uwe> How to convert: Uwe> length = '\x01\x00\x00\x00' Uwe> to an integer Check out struct.unpack. Skip From tim.one at comcast.net Mon Aug 11 23:20:41 2003 From: tim.one at comcast.net (Tim Peters) Date: Mon, 11 Aug 2003 23:20:41 -0400 Subject: Slogan: Getting Rich Overnight In-Reply-To: Message-ID: [Graham Fawcett] >>> "Python: stimulate powerful organisms under your fingertips, without >>> all the GUI mess!" [Brandon J. Van Every] >> "Organisms" is easily misread as "orgasms." [Graham] > ...and GUI is a homonym of "gooey". Was my joke too obscure? > > i-thought-it-was-funny-in-context-ly yours, Barry Warsaw and Fred Drake and I laughed long and hard when we saw it this afternoon. I confess we questioned your sanity, but we're all keen to adopt it as the Official Motto of the next PyCon! we're-gonna-get-soooooooo-rich-from-the-t-shirt-sales-ly y'rs - tim From aleax at aleax.it Fri Aug 8 08:29:07 2003 From: aleax at aleax.it (Alex Martelli) Date: Fri, 08 Aug 2003 12:29:07 GMT Subject: Why does value of __doc__ not a String type? References: <3216865.1060337379@dbforums.com> Message-ID: dlo_olb wrote: > > Hi, > >>>> import types >>>> type(types.BuiltinFunctionType.__doc__) >>>> What string would you like it to be? Whatever string value you choose, that's the one and only string that would then be shown for ANY builtin function or method... not very informative. As it is, instead, a descriptor, its __get__ method gets called, when you access __doc__ on any given builtin function of method, and that __get__ knows where to find the builtin's docstring and return it. Alex From mcherm at mcherm.com Wed Aug 27 09:52:51 2003 From: mcherm at mcherm.com (Michael Chermside) Date: Wed, 27 Aug 2003 06:52:51 -0700 Subject: Replacement for rexec/Bastion? Message-ID: <1061992371.3f4cb7b3ab85d@mcherm.com> Michael Chermside writes: > Consider, for instance, > this code: > > x = 1000000**1000000 > > I guarantee it'll lock up your python interpreter for a fairly long > time. And it executes in C so there's no possible way you can trap > it. Colin Coghill (SFive) replies: > I think I resolved this kind of thing a while ago by using seperate > processes. The user-code one and the actual application. If the > user-code one stops responding for some tunable time, it gets > kill -KILL'ed and restarted from the last checkpoint minus the > offending code. > And for resource limits, ulimit seems to work fine on the several > systems I've tried. > > Yes, this is messy UNIXy stuff, and loses portability, which is bad, > but it at least seems to make it possible to do this stuff. Great! If you are willing to run the untrusted code in a separate process and fall back on the OS to do the restricting, it _is_ actually capable of restricting what code can perform, in a way that Python simply can't match. You can use ulimit and chroot to restrict what the untrusted code may do. Then there's no particular need to use ANY special restricted execution support in Python. Use Python's easy-to-use support for interprocess communication to make a simple server which runs untrusted code bits, but which is itself run in a separate process inside a ulimit / chroot / user-with-limited-permissions jail, and which is killed and restarted whenever it gets in trouble. If you DO wind up going this route, I'm guessing that the code to launch an untrusted-code-runner in a separate process would be quite popular if it were released back to the Python community, judging from the number of times this question gets raised. -- Michael Chermside From postmaster at csc.com Fri Aug 22 01:24:58 2003 From: postmaster at csc.com (postmaster at csc.com) Date: Fri, 22 Aug 2003 01:24:58 -0400 Subject: File blocking warning notification! (Attachment Removal) Message-ID: <200308220525.h7M5P43f000777@amer-mta01.csc.com> **************** eManager Notification ***************** The following mail was blocked since it contains sensitive content. Source mailbox: Destination mailbox(es): Policy: Attachment Removal Attachment file name: application.pif - application/octet-stream Action: Replaced with text CSC's email filtering software has detected a file type sent by you which may not conform to CSC's HRMP 223, Use of Electronic Communications Media. ******************* End of message ********************* -------------- next part -------------- Received: from JOSH (c-67-164-102-171.client.comcast.net [67.164.102.171]) by amer-mta01.csc.com (Switch-3.1.0/Switch-3.1.0) with ESMTP id h7M5OjTd000461 for ; Fri, 22 Aug 2003 01:24:47 -0400 (EDT) Message-Id: <200308220524.h7M5OjTd000461 at amer-mta01.csc.com> From: To: Subject: Your details Date: Thu, 21 Aug 2003 22:23:18 --0700 X-MailScanner: Found to be clean Importance: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MSMail-Priority: Normal X-Priority: 3 (Normal) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="_NextPart_000_03A66675" From mpeuser at web.de Thu Aug 14 02:41:40 2003 From: mpeuser at web.de (Michael Peuser) Date: Thu, 14 Aug 2003 08:41:40 +0200 Subject: 3 new slogans References: Message-ID: "Graham Fawcett" schrieb im Newsbeitrag news:mailman.1060835422.10350.python-list at python.org... > smarter_than_you wrote: > > >1) Python made me rich > >2) Python saved my life > >3) Python changed my mind > > > >put them on T-shirts. Collect all three!! > > > > > how about > > I'm not really a wizard, I just use Python > > or (untested, but I think it's right) > > s/(perl|java|vba|c(#|\+\+|)?)/python/g .. but - as *any* regex - can be improved: s/\b(perl|java|vba?|c(#|\+\+|)?)/python/gi Kindly Michael P > > or, with apologies to Clarke, > > Any sufficiently advanced technology is indistinguishable from Python > > -- Graham > > > From jepler at unpythonic.net Tue Aug 26 17:33:17 2003 From: jepler at unpythonic.net (Jeff Epler) Date: Tue, 26 Aug 2003 16:33:17 -0500 Subject: Generator comprehensions -- patch for compiler module Message-ID: <20030826213316.GA7285@unpythonic.net> Hello. Recently, Generator Comprehensions were mentioned again on python-list. I have written an implementation for the compiler module. To try it out, however, you must be able to rebuild Python from source, because it also requires a change to Grammar. 1. Edit Python-2.3/Grammar/Grammar and add an alternative to the "listmaker" production: -listmaker: test ( list_for | (',' test)* [','] ) +listmaker: test ( list_for | (',' test)* [','] ) | 'yield' test list_for 1.5. Now [yield None for x in []] parses, but crashes the written-in-C compiler: >>> [yield None for x in []] SystemError: com_node: unexpected node type 2. Apply the patch below to Lib/compiler 3. Use compiler.compile to compile code with generator comprehensions: from compiler import compile import dis code = compile(""" def f(): gg = [yield (x,y) for x in range(10) for y in range(10) if y > x] print gg, type(gg), list(gg) """, "", "exec") exec code dis.dis(f.func_code.co_consts[1]) f() 4. It's possible to write code so that __import__ uses compiler.compile instead of the written-in-C compiler, but I don't have this code handy. Also, a test suite is needed, and presumably a written-in-C implementation as well. (option 2: make the compiler.compile interface the standard compiler, and let the builtin compiler support a Python subset sufficient to bootstrap the written-in-python compiler, or arrange to ship .pyc of the compiler package and completely get rid of the written-in-C compiler) 5. PEP remains rejected by BDFL anyway diff -ur compiler.orig/ast.py compiler/ast.py --- compiler.orig/ast.py 2002-02-23 16:35:33.000000000 -0600 +++ compiler/ast.py 2003-08-26 06:55:51.000000000 -0500 @@ -1191,6 +1191,53 @@ def __repr__(self): return "If(%s, %s)" % (repr(self.tests), repr(self.else_)) +class GenCompInner(Node): + nodes["gencompinner"] = "GenCompInner" + def __init__(self, expr, quals): + self.expr = expr + self.quals = quals + + def getChildren(self): + children = [] + children.append(self.expr) + children.extend(flatten(self.quals)) + return tuple(children) + + def getChildNodes(self): + nodelist = [] + nodelist.append(self.expr) + nodelist.extend(flatten_nodes(self.quals)) + return tuple(nodelist) + + def __repr__(self): + return "GenCompInner(%s, %s)" % (repr(self.expr), repr(self.quals)) + +class GenComp(Node): + nodes["gencomp"] = "GenComp" + def __init__(self, inner): + self.argnames = () + self.defaults = () + self.flags = 0 + self.code = inner + self.varargs = self.kwargs = None + + def getChildren(self): + children = [] + children.append(self.argnames) + children.extend(flatten(self.defaults)) + children.append(self.flags) + children.append(self.code) + return tuple(children) + + def getChildNodes(self): + nodelist = [] + nodelist.extend(flatten_nodes(self.defaults)) + nodelist.append(self.code) + return tuple(nodelist) + + def __repr__(self): + return "GenComp(%s)" % (repr(self.code),) + class ListComp(Node): nodes["listcomp"] = "ListComp" def __init__(self, expr, quals): diff -ur compiler.orig/pycodegen.py compiler/pycodegen.py --- compiler.orig/pycodegen.py 2002-12-31 12:26:17.000000000 -0600 +++ compiler/pycodegen.py 2003-08-26 06:54:53.000000000 -0500 @@ -563,6 +563,51 @@ # list comprehensions __list_count = 0 + def visitGenCompInner(self, node): + self.set_lineno(node) + # setup list + + stack = [] + for i, for_ in zip(range(len(node.quals)), node.quals): + start, anchor = self.visit(for_) + cont = None + for if_ in for_.ifs: + if cont is None: + cont = self.newBlock() + self.visit(if_, cont) + stack.insert(0, (start, cont, anchor)) + + self.visit(node.expr) + self.emit('YIELD_VALUE') + + for start, cont, anchor in stack: + if cont: + skip_one = self.newBlock() + self.emit('JUMP_FORWARD', skip_one) + self.startBlock(cont) + self.emit('POP_TOP') + self.nextBlock(skip_one) + self.emit('JUMP_ABSOLUTE', start) + self.startBlock(anchor) + self.emit('LOAD_CONST', None) + + def visitGenComp(self, node): + gen = GenCompCodeGenerator(node, self.scopes, self.class_name, + self.get_module()) + walk(node.code, gen) + gen.finish() + self.set_lineno(node) + frees = gen.scope.get_free_vars() + if frees: + for name in frees: + self.emit('LOAD_CLOSURE', name) + self.emit('LOAD_CONST', gen) + self.emit('MAKE_CLOSURE', len(node.defaults)) + else: + self.emit('LOAD_CONST', gen) + self.emit('MAKE_FUNCTION', len(node.defaults)) + self.emit('CALL_FUNCTION', 0) + def visitListComp(self, node): self.set_lineno(node) # setup list @@ -1245,6 +1290,20 @@ unpackTuple = unpackSequence +class GenCompCodeGenerator(NestedScopeMixin, AbstractFunctionCode, + CodeGenerator): + super_init = CodeGenerator.__init__ # call be other init + + __super_init = AbstractFunctionCode.__init__ + + def __init__(self, comp, scopes, class_name, mod): + self.scopes = scopes + self.scope = scopes[comp] + self.__super_init(comp, scopes, 1, class_name, mod) + self.graph.setFreeVars(self.scope.get_free_vars()) + self.graph.setCellVars(self.scope.get_cell_vars()) + self.graph.setFlag(CO_GENERATOR) + class FunctionCodeGenerator(NestedScopeMixin, AbstractFunctionCode, CodeGenerator): super_init = CodeGenerator.__init__ # call be other init diff -ur compiler.orig/symbols.py compiler/symbols.py --- compiler.orig/symbols.py 2002-12-31 12:17:42.000000000 -0600 +++ compiler/symbols.py 2003-08-25 17:03:27.000000000 -0500 @@ -231,6 +231,15 @@ self.visit(node.code, scope) self.handle_free_vars(scope, parent) + def visitGenComp(self, node, parent): + scope = LambdaScope(self.module, self.klass); + if parent.nested or isinstance(parent, FunctionScope): + scope.nested = 1 + self.scopes[node] = scope + self._do_args(scope, node.argnames) + self.visit(node.code, scope) + self.handle_free_vars(scope, parent) + def _do_args(self, scope, args): for name in args: if type(name) == types.TupleType: diff -ur compiler.orig/transformer.py compiler/transformer.py --- compiler.orig/transformer.py 2003-04-06 04:00:45.000000000 -0500 +++ compiler/transformer.py 2003-08-26 06:56:02.000000000 -0500 @@ -1026,18 +1026,25 @@ if hasattr(symbol, 'list_for'): def com_list_constructor(self, nodelist): # listmaker: test ( list_for | (',' test)* [','] ) + # | 'yield' list_for values = [] + yield_flag = 0 + if nodelist[1][1] == 'yield': + yield_flag = 1 + nodelist = nodelist[1:] for i in range(1, len(nodelist)): if nodelist[i][0] == symbol.list_for: assert len(nodelist[i:]) == 1 return self.com_list_comprehension(values[0], - nodelist[i]) + nodelist[i], + yield_flag) elif nodelist[i][0] == token.COMMA: continue values.append(self.com_node(nodelist[i])) + assert not yieldflag return List(values) - def com_list_comprehension(self, expr, node): + def com_list_comprehension(self, expr, node, yield_flag): # list_iter: list_for | list_if # list_for: 'for' exprlist 'in' testlist [list_iter] # list_if: 'if' test [list_iter] @@ -1071,7 +1078,10 @@ raise SyntaxError, \ ("unexpected list comprehension element: %s %d" % (node, lineno)) - n = ListComp(expr, fors) + if yield_flag: + n = GenComp(GenCompInner(expr, fors)) + else: + n = ListComp(expr, fors) n.lineno = lineno return n From brian at zope.com Fri Aug 8 23:46:58 2003 From: brian at zope.com (Brian Lloyd) Date: Fri, 08 Aug 2003 23:46:58 -0400 Subject: Python for .NET preview 2 release Message-ID: For those interested, I've made a preview-2 release of Python for .NET. Python for .NET is a near-seamless integration of the CPython runtime with the .NET Common Language Runtime (CLR). It lets you script and build applications in Python, using CLR services and components written in any language that targets the CLR (C#, Managed C++, VB.NET, etc.). Highlights of this release include array and indexer support, better thread handling, the ability to subclass managed classes in Python and many bug fixes. For more info or to download the release: http://zope.org/Members/Brian/PythonNet/ - Brian From jdhunter at ace.bsd.uchicago.edu Sat Aug 30 09:07:41 2003 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Sat, 30 Aug 2003 08:07:41 -0500 Subject: My script is taking 12 hours+ any suggestions? In-Reply-To: <3f4ff9f8$0$23588$5a62ac22@freenews.iinet.net.au> (Ideasman's message of "Sat, 30 Aug 2003 13:08:24 -0400") References: <3f4ff9f8$0$23588$5a62ac22@freenews.iinet.net.au> Message-ID: >>>>> "Ideasman" == Ideasman writes: Ideasman> Hi I have a made a script that process normals for a Ideasman> flat shaded 3D mesh's. It compares every vert with Ideasman> every other vert to look for verts that can share Ideasman> normals and It takes ages. Not what you asked, but are you familiar with VTK and it's python interface? It supports various shading algorithms, and is written in C++ so is quite speedy. http://public.kitware.com/VTK/ JDH From losnations at comcast.net Fri Aug 29 20:00:52 2003 From: losnations at comcast.net (Marc) Date: Fri, 29 Aug 2003 19:00:52 -0500 Subject: How do I prevent master window from being accessed with childwindow present? References: <4378fa6f.0308291012.f660cdf@posting.google.com> Message-ID: <7YadnTLIALoMddKiXTWJiw@comcast.com> I guess knowing which kit would help. I am using Tkinter. "Cliff Wells" wrote in message news:mailman.1062185326.12289.python-list at python.org... > On Fri, 2003-08-29 at 11:12, Marc wrote: > > Hi, > > > > I am doing a gui application where child windows pop up with options > > after the user selects particular buttons from the master window. > > However, the master window is still active underneath the child > > window. If they accidentally press the same button again they can get > > the same copy of two child windows, and that screws up a bunch of the > > database stuff that I am trying to collect. > > > > I have tried using the 'transient' method, and that prevents the > > master window from being highlighted. But the user can still push > > buttons on the master window if the child window is moved aside. > > > > How do I disable the master window until the child window is closed? > > And which GUI toolkit are you using? Most have an option to open a > window as "modal" (although this might be limited to dialogs for your > particular toolkit) which means it retains the focus exclusively until > it's dismissed. > > -- > Cliff Wells, Software Engineer > Logiplex Corporation (www.logiplex.net) > (503) 978-6726 (800) 735-0555 > > From peter at engcorp.com Fri Aug 29 15:06:09 2003 From: peter at engcorp.com (Peter Hansen) Date: Fri, 29 Aug 2003 15:06:09 -0400 Subject: Celebrity advice References: <000701c36ce7$a6ff24d0$0c02a8c0@Arts> <1062150627.7273.26.camel@devilbox.homelinux.net> Message-ID: <3F4FA421.14DD663B@engcorp.com> Tim Churches wrote: > > On Fri, 2003-08-29 at 19:50, Cliff Wells wrote: > > The fact that I think Charlton Heston is a buffoon shouldn't be the > > reason I think his movies suck. > > Surely you make an exception for _Omega Man_ - especially that scene at > the end when he is hung on the cross (in a fountain), dying, but his > serum saves the world... And then there's the time Heston was a guest on Monty Python and ended the skit with that famous line, "Norwegian Blue is people!". -trying-desperately-to-get-the-thread-on-topic-ly y'rs, Peter From mis6 at pitt.edu Mon Aug 11 17:26:19 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 11 Aug 2003 14:26:19 -0700 Subject: CLI+GUI References: <2259b0e2.0308080948.5a95e383@posting.google.com> <2259b0e2.0308090530.7519f195@posting.google.com> <2259b0e2.0308110517.7c4fa8c8@posting.google.com> Message-ID: <2259b0e2.0308111326.1f6a2fc8@posting.google.com> Eric Brunel wrote in message news:... > Cousin Stanley wrote: > > Michele .... > > > > I experience hangs with SIMPLE Python/Tk scripts > > regularly using Windows 98 and this has been > > a source of much frustration, almost to the point > > of giving up on Tk .... > > Same problem, different solution: it made me give up on Windows 98... ;-) > > FYI, and just to make this post a bit more useful, it seems to be a problem in > Windows 95/98, since no problem ever occured with the same scripts/distros on > Win2k or WinXP, not to mention Unices... These are very good news to me, since it means that the fault is not mine and that the approach I came out is not unreasonable (I hope). No bad, for my first program using thread ;) For the record, I NEVER use Windows for development(actually I use it only for watching DVDs), nevertheless I wanted to try the script to check about portability issues. Michele From lists at webcrunchers.com Tue Aug 12 16:59:59 2003 From: lists at webcrunchers.com (John D.) Date: Tue, 12 Aug 2003 13:59:59 -0700 Subject: problems importing "bsddb" Message-ID: We are using OpenBSD latest release of Python (2.3), and want to use the "bsddb" module. Our python release has a directory called "bsddb", but when we try and import it, it says >>> import bsddb Traceback (most recent call last): File "", line 1, in ? File "/usr/local/lib/python2.3/bsddb/__init__.py", line 40, in ? import _bsddb ImportError: No module named _bsddb Where can I find this module, and how do I get it to work with my version of Python? Has anyone else had this problem? John From jacek.generowicz at cern.ch Fri Aug 22 05:10:29 2003 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 22 Aug 2003 11:10:29 +0200 Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> <6dj2kv8ugkieehs7guh786cl40o5lj6mcs@4ax.com> Message-ID: You wrote lots. Forgive me if I don't address everything. I wish I had the time to address all your points more carefully. "Andrew Dalke" writes: > However, at present, the only example I've seen for when to use a > macro came from a method cache implementation that I could implement > in Python using the normal class behaviour, Or using directors, or lexical closures. Similarly in Lisp, there is more than one way to do it, and many would not choose the macro option when implementing a memoizer. > so I don't have a good idea of when macros would be appropriate > *for* *Python*. (Looks like you've found a need for them yourself - see later on.) Well, frankly, in the context of Python, I find the whole discussion a bit abstract. Lisp macros fundamentally rely on the fact that Lisp programs are represented as lists, and that Lisp includes excellent support for manipulating such lists. The consequence of this (source code being a form of data) is that it is extremely easy to manipulate Lisp source code within Lisp. You can already achieve similar things in Python by typing your source code as a string, and performing string manipulations on it, and then calling eval ... but it is many orders of magnitude more painful to do it this way. Alternatively, get your hands on the parse-tree (I believe there's a module to help), and mess around with that. That should be much easier that playing with strings, but still much more of a pain than Lisp macros. > When this topic has come up before, others mentioned how > macros would theoretically be able to, say, modify list.sort > to return the sorted list after it has been modified in-place. You don't need macros for that. With the advent of new-style classes, you subclass list, override the sort function, and replace __builtins__.list (maybe there's more to it, but as this is not something I ever intend to do, forgive me for not checking the details.) > Given the not infrequent request for the feature, I know that > if it was allowed, then some of my clients would have done > that, making it harder for me to know if what I'm looking at > is core Python behaviour or modified. That's not the point of macros. The point is not to modify existing behaviour behind one's back. The point is to add new behaviour ... much like it is with functions, classes etc. > What you say is true, but most of the code I look at is > based on fundamental Python types, from which I can > be assured of fixed behaviour, or classes and functions, > where I can be assured that they are free to do their > own thing. The patterns of behaviour are fixed and > the opportunities for change well defined. > > Macros, as I understand it, blurs those lines. I don't think this has anything to do with macros. This is a consequence of a language allowing to re-bind built-ins. I remind you that Python allows this, today. > I will grant that Lisp or Scheme is the end-all and be-all of > languages. :-) Well, at least that's clear :-) :-) [NB, I love Python, and wouldn't want to go without it, for a plethora of reasons.] > Where's the language between those and Python? I am not sure that there is a need for one; Python and Lisp are already very close, as compared to other languages. But maybe some interemediate language would serve a good purpose. > Is it possible to have a language which is more flexible than > Python but which doesn't encourage the various dialectization > historically evident in the Lisp/Scheme community? Hmmm. I think this "dialectization of the Lisp/Scheme community" is a bit like the "dialectization of the Algol Family community" or the "dialectization of the functonal community" or the "dialectization of the scripting (whatever that means) community" The fundamental feature of Lisps is that they represent their source code in a format which they themselves can manipulate easily. (Often people try to characterize Lisps by the 4 or 5 fundamental operators that you need to make all the rest, but I don't find this an interesting perspective.) What's wrong with there being different languages with this characteristic? What's wrong with there being different functional languages? What's wrong with there being different scripiting (whatever that means) languages ? Maybe you refer to the fact that, should you wish to make a completely new Lisp-like language, then starting with an already existing lisp, and writing your first implementation in that (with the help of macros), is usually by far the best way of going about it. (This is exactly how Scheme was created, IIRC) But your new language is exactly that. A new language. Faithful users of the language in which you wrote that first implementation, will not suddenly find that the language they know and love has been broken. > Could most macros also be written without macros, using > classes or lambdas? Heh. You can write a lot of macros which don't need to be macros (so don't). But there are some things for which macros are absolutely necessary. (Actually, in Lisp you could get by with functions and "'" (the quote) ... but you'd still be writing macros, without official language support for them.) I guess that it boils down to delaying evaluation until you have had the opportunity to manipulate your source. > How often are the benefits of macros > that much greater than classes&functions to merit their > inclusion. > > Does it take skill to know when to use one over the other? Often, it does. Some are no-brainers (Control structures, for example). > Do people use macros too often? Some probably do. This is probably true of classes too. > When do they hinder misunderstanding? When they are badly designed. This is true of classes too. > Are they more prone to misuse than classes&functions? I guess it is generally true, that the more powerful and versatile the tool, the more prone it is to misuse. > The complaint about macros has been their tendency to increase a > single person's abilities at the cost of overall loss in group > understanding. No, no, NO, Noooooooooo ! :-) At the top of your reply, you agreed about my point that abstracting a frequently repeated pattern is preferable re-implementing it all over your code. _This_ is what macros are about. One can write useless and obfuscating functions and classes, just like one can write useless and obfuscating macros. > I've heard references to projects where that didn't occur, but am > not swayed by it because those seem staffed by people with > extraordinarily good programming skills almost never found amoung > the chemists and biologists I work with. I do not advocate Lisp as a language for people who are not prepared to invest serious time to understanding it, which probably includes most people whose primary activity is not programming. That is why I think Python is _extremely_ useful and necessary. It provides a significant portion of the power of Lisp, for a small initial investment. I do not expect CERN physicists to use Lisp, I do expect them to use Python. > The point I'm trying to make is that different, very smart people > like "Lisp", but insist on variations. Very smart and not-so-smart people like "scripting languages", but insist on variations. There's Perl, Python, Ruby ... > There is clisp Clisp is just one implementation of an ANSI standardized Lisp (Common Lisp). > and elisp Elisp is the scripting language of Emacs. Now, Common Lisp is an all-purpose stand-alone language designed for constructing complicated systems; Elisp is designed for configuning and extending Emacs. Complaining that this is "insisting on variations of lisp", and that it is somehow a BAD THING, is a bit like complaining about the co-existence of Python and Occam, as "insisting on variations of languages with significant indentation". > As I understand it, macros can be used to make one lisp variation > act like another. This is true to some extent. But just because it can be done, doesn't mean that very many people actually ever want to do it. Yes, sometimes CLers want to fake up a Scheme-like continuation, and the language allows them to do it. Great. But that (pretending to be another already existing language) is not the point of macros. > > A few days ago I tested out a C++ library. It didn't work on the C++ > > system I had handy because the STL implementation was > > different/template support was different. etc. etc. > > Did you really or are your making that up for the > sake of rhetoric? Sorry, I should have made clear that I made it up for the sake of rhetoric. However, the only thing that is untrue is the "A few days ago" bit. It has happened repeatedly in the past. > If it takes more than four decades for different Lisp > implementations to agree on how to import a module, then I think > there's a problem. Again, you are confusing "different implementations" with "different languages". Implementations of ANSI Common Lisp agree on, well, anything defined within the standard. Implementations of different languages clearly do not agree. This is true of those in the Lisp family, just as it is for members of any other family of Languages. > I needed to evalute a user-defined expression where the variable > names are computed based on calling an associated function. The > functions may take a long time to compute and most names are not > used in an expression, so I want to compute the names only when > used. You want lazy evaluation ? > Did I start from scratch? No! I used Python to build the parse > tree In Lisp, you start off with the parse tree. That's the great thing about it. > then tweaked a few nodes of that tree to change the name lookup into > the right form, then generated the function from that parse tree. You've just Greenspunned Lisp macros. Manipulating the parse-tree is exactly what Lisp macros are about. > The syntax was the same as Python's, but the behaviour different. In Lisp you would typically give a name to this behaviour, and then you would be able to use it alongside the original language. For example, if the user-defined expression is (+ (foo 2) (bar a b c d)) The tweaked version would be (lazy-eval (+ (foo 2) (bar a b c d))) Writing a macro to make Lisp a uniformly lazy language (as you seem to have been suggesting one might proceed, way up-post), is definitely not the way to do it. > Though back at the Python level, it's a "call this function to get > the needed result", In Lisp it's "call this macro to get the needed result". > and has precisely the same nature as any other Python function would > have. And has percisely the same nature as any other Lisp macro would have. > And some languages are not-at-all close to Python. Eg, I wanted > to implement a domain-specific language called MCL What, "Macintosh Common Lisp" ? :-) > using my PyDaylight package. I ended up writing a parser for MCL > and converting the result into Python code, then exec'ing the Python > code. In CL this is done with reader macros; a means of altering the way the parse tree is constructed from the source data. > Similarly, SMILES is a language for describing molecules. > Why in the world would I want to extend Lisp/Perl/Python/ > whatever to support that language directly? a) Because it's easier to build it on top of Lisp than from scratch. b) Because you never know what future requirements you might have. > > It's an extreme form of Greenspunning. > > ??? Apparantly not Alan Greenspan. Greenspun's Tenth Rule of Programming: "Any sufficiently complicated C or Fortran program contains an ad-hoc, informally-specified bug-ridden slow implementation of half of Common Lisp." (Of course, it's a general statement about developing in low-level languages as compared to developing in higher-level ones.) > Please tell me how you would implement this language > > load "abc.pdb" into a > select "resname LYS" from a into b > save b as "lysine.pdb" > > as a macro in Lisp. I'll assume 'load-pdb' loads a PDB file into > a object which holds a set of atoms, and that object has the > method 'select-atoms' which creates a new (sub)set and also > has the method 'save-as' for saving those atoms in the right format. > > And the above is all that the user can type. > > How in the world does macros make handling that language > any easier than the standand parser-based non-macro solution? I don't think I understand the true meaning of your question. Anyway, your parse tree exapmle shows that you DO understand and use macros ... you just don't know that that's the name of what you are doing :-) From raims at dot.com Sun Aug 24 02:57:26 2003 From: raims at dot.com (Lawrence Oluyede) Date: Sun, 24 Aug 2003 08:57:26 +0200 Subject: Python is darn fast (was: How fast is Python) References: <2259b0e2.0308230737.8a9bc1c@posting.google.com> <3F47AA73.7040104@draigBrady.com> Message-ID: Van Gale wrote: > You still need some -O optimization flags. The -m options just let gcc > generate some nice instructions specific to your Athlon CPU. I didn't mention but I also used -O3 flag. I don't know why but on my machine C code is faster than psyco code in this test -- Lawrence "Rhymes" Oluyede http://loluyede.blogspot.com rhymes at NOSPAMmyself.com From roy at panix.com Fri Aug 8 15:33:37 2003 From: roy at panix.com (Roy Smith) Date: 8 Aug 2003 15:33:37 -0400 Subject: base64 module References: Message-ID: Ken Fettig wrote: >Hello, I am trying to make use of the base64 module but am having problems. > >>>> import base64 >>>> decodestring('SVNBKjAwKiAgICAgICAgICAqMDAqICAgICAg') >Traceback (most recent call last): > File "", line 1, in ? > decodestring('SVNBKjAwKiAgICAgICAgICAqMDAqICAgICAg') >NameError: name 'decodestring' is not defined >>>> > >What am I doing wrong. I am importing the base64 module, why can't I call >the decodestring method? All the import statement does is make the base64 module available, but the objects in that module are still in the base64 namespace. You need to do: >>> base64.decodestring('SVNBKjAwKiAgICAgICAgICAqMDAqICAgICAg') 'ISA*00* *00* ' Alternatively, you could do "from base64 import decodestring" (or even, "from base64 import *", and then you can do: >>> from base64 import decodestring >>> decodestring('SVNBKjAwKiAgICAgICAgICAqMDAqICAgICAg') 'ISA*00* *00* ' My personal preference is to use the plain version of the import statement, and use fully qualified names, but it's really up to you which way you want to do it. From luca.simonetti at casaccia.enea.it Wed Aug 27 02:56:11 2003 From: luca.simonetti at casaccia.enea.it (Luca Simonetti) Date: Wed, 27 Aug 2003 08:56:11 +0200 Subject: My future Python IDE article References: Message-ID: <3F4C560B.1070300@casaccia.enea.it> My favorites IDEs: 1)Eric3 (despite a little work still to do) under Linux; 2)Pythonwin under Windows; 3)Komodo if I would buy one. 4)Pycrust is also a useful tool Luca -- +======================================================================+ Luca SIMONETTI networks/systems manager INSTITUTE OF THERMAL-FLUID DYNAMICS ENEA "CASACCIA" Via Anguillarese 301 00060 - R O M E ITALY Tel: +39 6 3048 4049 Fax: +39 6 3048 3026 E-Mail: luca.simonetti at casaccia.enea.it +======================================================================+ From a.schmolck at gmx.net Mon Aug 18 20:46:20 2003 From: a.schmolck at gmx.net (Alexander Schmolck) Date: 19 Aug 2003 01:46:20 +0100 Subject: What's better about Ruby than Python? References: Message-ID: Gon?alo Rodrigues writes: > On 18 Aug 2003 23:40:58 +0100, Alexander Schmolck > wrote: > >But of course what currently happens is: > > > >'just a method' > > > > And rightly so, you have just rebinded a name. If you type > > x.__class__ > > you get the older X. Or are you proposing that rebinding X to > automagically rebind the __class__ of all the X instances? Well, yes, I propose that x.__class__ return the *new* definition of X (like in ruby, for example). I don't think that necessarily involves rebinding anything "automagical", depending on how the lookup of x.__class__ works. Can you give my any reason why you would *not* want all instances to be updated on class redefinition? > > But why can't you just > > X.amethod = lambda self: "ah, now THIS is better!" > > that is, mutate the class referenced by X instead of rebinding X to > some other class? Um, didn't you read what I wrote or was I just unclear? To recap: usually, if I change a class I'd like all pre-existing instances to become updated (Let's say you develop your program with a running python session; you notice a mistake in a method-definition but don't want to start over from scratch; you just want to update the class definition and have this update percolate to all the currently existing instances. This is an *very* reasonable wish if it doesn't just take seconds to get to the current state by rerunning everything, but possibly hours or days). AFAIK doing this in a general and painfree fashion is pretty much impossible in python (you have to first track down all instances -- not an easy task, as far as I can see and then updating their .__class__ might not quite work as expected either as I've already mentioned). I think this sucks big time, because it greatly devalues the interactive programming experience for certain tasks, IMHO, but maybe I'm just missing something since typically nobody complains. 'as From roy at panix.com Fri Aug 22 09:20:08 2003 From: roy at panix.com (Roy Smith) Date: Fri, 22 Aug 2003 09:20:08 -0400 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: <240b1020.0308201722.d1b991c@posting.google.com> <81smnteu60.fsf@darwin.lan.kassube.de> Message-ID: In article <81smnteu60.fsf at darwin.lan.kassube.de>, Nils Kassube wrote: > A nice feature of Ruby is that exceptions are resumable like in > Smalltalk, ie. you can have a "retry" statement in your exception > handling that allows you to "try again". > > http://www.rubycentral.com/book/tut_exceptions.html I suppose this is nice, but does it really give you anything you couldn't get in a slightly different way by just enclosing the whole try construct in a loop? while 1: try: do stuff break except: fix the problem If "do stuff" throws an exception, the "fix the problem" code runs and then you try "do stuff" again. It even suffers from the same potential infinite loop problem the Ruby version has :-) From ktilton at nyc.rr.com Sun Aug 24 11:31:05 2003 From: ktilton at nyc.rr.com (Kenny Tilton) Date: Sun, 24 Aug 2003 15:31:05 GMT Subject: For Kenny Tilton: Why do I need macros revisited. References: <3f45484f$1_6@corp.newsgroups.com> <3F45A7BF.4060806@nyc.rr.com> <2259b0e2.0308222333.16ad345d@posting.google.com> <3F47BDCA.3070001@nyc.rr.com> <2259b0e2.0308240131.8bb4c17@posting.google.com> Message-ID: <3F48DB0D.6070407@nyc.rr.com> Michele Simionato wrote: > Kenny Tilton wrote in message news:<3F47BDCA.3070001 at nyc.rr.com>... > >>A few months back I started on a PyCells project, and of course was >>having great fun down at the metaclass level. It was a little daunting >>compared to the Lisp MOP, which just takes the same concepts of calls >>and instance and does a conceptual-shift-up (new machine language >>instruction?) so a class is now an instance (of a metaclass, which is >>just another class really--the "meta" is only to keep one's head >>straight). Python might be viewed as easier because it jumps over to >>using internals such as that __dict__ thing (sorry if that is wrong, it >>has been a while and I only played for a few weeks), so it there is none >>of that class-being-an-instance confusion. Fun stuff, either way. > > > > I don't follow you. In Python it is just the same, a class is just an > instance of a metaclass, a metaclass is just an instance of a meta-meta > class, etc. Metaclasses are classes, their simply have a different > type.__new__ method than object.__new__ so the instantiation syntax > looks a bit different. Glad I said it had been a while! :) Maybe I was less confused on the Python MOP because I had already done a CL MOP hack? > > >>The CLOS MOP is a better playground, but Python has >>a clear win in that there is only one Python. If I really need the MOP >>for a project, I just pick a CL which exposes it. If I want to deliver a >>package any lispnik can use, I better not use the MOP. > > > > Hear, hear, people who say CL is more standard than Python! I doubt they say precisely that, if standard means "the same across all implementations". :) What I would say is that CL stands at the end of the long road Python is now headed down, with divergent branches (not a problem for Python) brought together in a big, stabilizing spec. Python is more like a volcanic island rising out of the sea, still being formed, features still being debated. Heady days, being there at the creation. Then again, "may you live in an interesting time" is a Chinese curse. :) -- kenny tilton clinisys, inc http://www.tilton-technology.com/ --------------------------------------------------------------- "Career highlights? I had two. I got an intentional walk from Sandy Koufax and I got out of a rundown against the Mets." -- Bob Uecker From jjl at pobox.com Wed Aug 20 15:35:39 2003 From: jjl at pobox.com (John J. Lee) Date: 20 Aug 2003 20:35:39 +0100 Subject: Import error !! References: Message-ID: <877k58azqs.fsf@pobox.com> "satish k.chimakurthi" writes: [...] > 'import site' failed; traceback: > File "/usr/lib/python2.2/site.py", line 64 > dir = os.path.abspath(os.path.join(*paths)) > ^ > SyntaxError: invalid syntax > Python 1.5.2 (#1, Apr 3 2002, 18:16:26) [GCC 2.96 20000731 (Red Hat Linux [...] Something has got mixed up with your Python installations: Python 1.5.2 is attempting to import Python 2.2's site.py (and is failing because 1.5.2 doesn't support the foo(*args) style of function call). John From FBatista at uniFON.com.ar Fri Aug 1 10:13:36 2003 From: FBatista at uniFON.com.ar (Batista, Facundo) Date: Fri, 1 Aug 2003 11:13:36 -0300 Subject: list indexing Message-ID: #- Hello, I am rather new to python and I have come across a #- problem that #- I can not find an answer to any where I my books. What I #- would like to #- know is if there is a way to get the index number of a list #- element by #- name. Sort of the inverse of the .index() method. #- #- For example #- #- list = ['this', 'is', 'a', 'list'] #- for item in list: #- if item = 'list': #- print ???? #- #- #- ???? Is where I want to be able to get the index number, in this case #- 3 from the list in a simple fasion. It's just index: >>> list = ['this', 'is', 'a', 'list'] >>> for item in list: print list.index(item), item 0 this 1 is 2 a 3 list >>> . Facundo From max at alcyone.com Mon Aug 18 15:09:56 2003 From: max at alcyone.com (Erik Max Francis) Date: Mon, 18 Aug 2003 12:09:56 -0700 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: Message-ID: <3F412484.69867AED@alcyone.com> "Brandon J. Van Every" wrote: > I'm realizing I didn't frame my question well. > > What's ***TOTALLY COMPELLING*** about Ruby over Python? comp.lang.ruby doesn't have Brandon Van Every. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ I dream things that never were and say, "Why not?" \__/ John F. Kennedy From gstein at lyra.org Thu Aug 21 10:51:16 2003 From: gstein at lyra.org (gstein at lyra.org) Date: Thu, 21 Aug 2003 07:51:16 -0700 Subject: received your email Message-ID: <200308211451.h7LEpG5U003572@nebula.lyra.org> Hi, [ Re: Re: Thank you! ] I have received your email, but it may take a while to respond. I'm really sorry to have to hook up this auto-responder, as it is so impersonal. However, I get a lot of email every day and find it very difficult to keep up with it. Please be patient while I try to get to your message. Please feel free to resend your message if you think I've missed it. I'll always respond to personal email first. If your email is regarding some of the software that I work on (if you have questions, comments, suggestions, etc), then please resend it to the appropriate mailing list: mod_dav WebDAV ViewCVS Subversion edna Thank you! Cheers, -g -- Greg Stein, http://www.lyra.org/ From max at nospam.com Tue Aug 5 10:51:56 2003 From: max at nospam.com (max) Date: Tue, 05 Aug 2003 14:51:56 GMT Subject: py2exe 2.3 Message-ID: <3F2FC633.6090408@nospam.com> I just installed py2.3, win extensions 2.3 and py2exe-0.4.1.win32-py2.3.exe. When trying to package a serive I am getting running py2exe running build running build_scripts running install_scripts error: python22.dll: No such file or directory did I miss something? thanks, max. From bokr at oz.net Fri Aug 8 15:23:00 2003 From: bokr at oz.net (Bengt Richter) Date: 8 Aug 2003 19:23:00 GMT Subject: Need elegant way to cast four bytes into a long References: <3f33c209$1@news.si.com> Message-ID: On Fri, 8 Aug 2003 10:54:38 -0500, Skip Montanaro wrote: > > wsh> I have been getting what I want in this sort of manner : > > wsh> l = 0L > wsh> l = a[0] > wsh> l += a[1] << 8 > wsh> l += a[2] << 16 > wsh> l += a[3] << 24 > > wsh> but I think that's too wordy. Is there a more intrinsic and > wsh> elegant way to do this? > >You mean like this: > > l = long(a[0] + a[1] << 8 + a[2] << 16 + a[3] << 24) > >You can use struct.unpack as well, though I'd be hard-pressed to get the >details correct. You'd be better off with "pydoc struct". > >Skip > This won't be fast, but you get to play with 2.3 ;-) >>> a = '\x01\x02\x03\x04' >>> sum([ord(c)<<8*i for i,c in enumerate(a)]) 67305985 >>> hex(sum([ord(c)<<8*i for i,c in enumerate(a)])) '0x4030201' or big-endian: >>> a = '\x01\x02\x03\x04' >>> sum([ord(c)<<8*i for i,c in enumerate( a[::-1])]) 16909060 >>> hex(sum([ord(c)<<8*i for i,c in enumerate( a[::-1])])) '0x1020304' Regards, Bengt Richter From peter at engcorp.com Wed Aug 13 10:39:46 2003 From: peter at engcorp.com (Peter Hansen) Date: Wed, 13 Aug 2003 10:39:46 -0400 Subject: Determine file type (binary or text) References: Message-ID: <3F3A4DB2.46FF3001@engcorp.com> Sami Viitanen wrote: > > How can I check if a file is binary or text? > > There was some easy way but I forgot it.. First you need to define what you mean by binary and text. Is a file "text" simply because it contains only the printable (in ASCII) bytes between 31 and 127, plus CR and/or LF, or do you have a more complex definition in mind. Better yet, what do you need the information for? Maybe the answer to that will show us the proper path to take. From mwh at python.net Thu Aug 28 07:31:56 2003 From: mwh at python.net (Michael Hudson) Date: Thu, 28 Aug 2003 11:31:56 GMT Subject: Filtering virus-related e-mails? References: <3f4ce4d6$0$166$a1866201@newsreader.visi.com> Message-ID: <7h3wucy58cm.fsf@pc150.maths.bris.ac.uk> Jos? Mar?a Mateos writes: > In comp.lang.python, Grant (grante at visi.com) wrote: > > Would it be possible for the python mailing list to filter out > > the "virus-warning" emails rather than posting them to the > > newsgroup? > > Filtering out all the posts with the word "virus" in the subject > line helps a log. Then how did you see the post you're replying to? Cheers, mwh (rhetorical, no need to reply...) -- SPIDER: 'Scuse me. [scuttles off] ZAPHOD: One huge spider. FORD: Polite though. -- The Hitch-Hikers Guide to the Galaxy, Episode 11 From akhleung at earthlink.net Fri Aug 1 02:44:40 2003 From: akhleung at earthlink.net (Aaron Leung) Date: Thu, 31 Jul 2003 23:44:40 -0700 Subject: Python's biggest compromises In-Reply-To: Message-ID: Hi Gustavo, I've seen the Borg pattern; it's nice. I suppose I should have said that using dictionaries everywhere is a very flexible and convenient feature, but the compromise is in efficiency. Of course, I realize that efficiency isn't always important. Best regards, Aaron On Thursday, July 31, 2003, at 03:33 PM, sismex01 at hebmex.com wrote: > Actually, this which you call a compromise, is one of Python's > biggest strengths: it allows you, as a programmer, to perform > many things which in other languages would be simply impossible, > or at least would force you to jump through plenty loops and > hoops. > > Take a look at Alex Martelli's Borg pattern, it shows what can > be done by having open access to class *and* object namespaces, > and being able to manipulate them. In Python it's easy and > straightforward (eek), but in other languages, well... you have > whole books dedicated to that. From aleax at aleax.it Thu Aug 21 03:50:24 2003 From: aleax at aleax.it (Alex Martelli) Date: Thu, 21 Aug 2003 07:50:24 GMT Subject: Python newbie help References: <87fa5cfa.0308181126.c61bfa2@posting.google.com> Message-ID: <4R_0b.22280$zN5.692394@news1.tin.it> s wrote: > On Tue, 19 Aug 2003 08:28:06 +0000 (UTC), Duncan Booth > wrote: > >>stephen at hostwiththemost.net (s) wrote in >>news:87fa5cfa.0308181126.c61bfa2 at posting.google.com: >> >>> I've recently been very interested in learning Python but I seem to >>> lack direction while reading the tutorials. I understand the syntax >>> and everything concerning the language itself but the tutorials I have >>> seen are merely displaying features of the language rather than > > > Thanks for the help. I will definitely look into these links very > hard but I must point out that I'm not a teenager or a beginner > programmer, just someone who has lost motivation to learn but would > like to get it back. > > I just get bored with examples that don't really contribute to a > program or the like. Thanks for the link. If you're keen on books that present actual, biggish, substantial programs as the examples, try Magnue Lie Hetland's "Practical Python", APress -- I personally prefer toy-level examples (which Magnus has in the first half of his book -- the significant programs make up the second half) but MLH did a great job working the "real" things out. Don't think the book's available anywhere online, though. Alex From theller at python.net Fri Aug 8 09:39:07 2003 From: theller at python.net (Thomas Heller) Date: Fri, 08 Aug 2003 15:39:07 +0200 Subject: [Python] Re: Building extensions with mingw32 -- bdist_wininst fails. References: Message-ID: "Chris Gonnerman" writes: >> > OK, here's the problem. The distutils bdist_wininst >> > script calls build (illustrated below) but does not >> > accept --compiler=mingw32. This is obviously wrong, >> > but I'm unsure how to fix it (I'm still trying to wrap >> > my fuzzy and tired mind around the entire distutils >> > thing). >> >> >> There's an easy workaround. >> >> python setup.py build --compiler=mingw32 bdist_wininst >> > > Well, whaddaya know, it works! Thanks! > > I still think the bdist*.py scripts should accept > --compiler=mingw32 (or whatever) as a matter of > correctness, if nothing else; but I can live with > this. Perhaps if I get time I'll work up a patch. I'm not so convinced that this is needed. I always view the disutils commands as a stack or chain, and the command line above can be used to inject flags in vertain places in the chain. the build commands, for example, accept quite some parameters which are not valid for the install or (s|b)dist commands (--debug is another example). So, to install debug versions, one would use python setup.py build --debug install which also looks natural to me. The --compiler problem may be unique because obviously the build command constructs a compiler instance even if it has nothing to do, and the build command is run from bdist_wininst to make sure everything is ok. Oh, and yet another way, which you may want to try, is to write an (maybe even site-global) distutils configuration file containing [build] compiler = mingw32 If this works, you no longer have to remember to give the compiler option on the command line. Thomas From max at nospam.com Mon Aug 4 12:38:05 2003 From: max at nospam.com (max) Date: Mon, 04 Aug 2003 16:38:05 GMT Subject: packaging windows services? In-Reply-To: References: Message-ID: > I know that the (commercial) WISE installer can also install a service > with the options you need. I do not know if inno or nsis can also do > this. > > Thomas Thomas - Thanks! due to my sad unfamiliarity with CVS, how can I merge this file with the run_cvs.c I downloaded? From tjreedy at udel.edu Fri Aug 29 00:02:06 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 29 Aug 2003 00:02:06 -0400 Subject: imports after function definitions? References: Message-ID: "Hallvard B Furuseth" wrote in message news:HBF.20030828usgy at bombur.uio.no... > Is there any reason not to structure my program like this? > > def ... > def ... > var = ... > var = ... > import ... > import ... > main_function() It is helpful to human readers to see dependencies at the top and to know what globals are avaiable when reading defs. What would be compensating gain of doing such? Terry J. Reedy From cartermark46 at ukmail.com Tue Aug 19 04:41:41 2003 From: cartermark46 at ukmail.com (Mark Carter) Date: 19 Aug 2003 01:41:41 -0700 Subject: ClientCookie bug (followup) References: <87fzk4sav2.fsf@pobox.com> <87znibzrnx.fsf@pobox.com> <87oeypdh92.fsf@pobox.com> <87k79a25pi.fsf@pobox.com> Message-ID: > No really, I wasn't joking: you *never* need to use add_cookie_header > / extract_cookies if you're using urllib2 (at least, I can't think of > any possible reason to do so). It can only break things. I must admit that I don't really know what I am doing. How would you simplify the following code: def go8(): import ClientCookie c = ClientCookie.MSIECookieJar(delayload=1) c.load_from_registry(username='mcarter') #only need username for win9x import urllib2 url = 'http://businessplus.hemscott.net/corp/crp03733.htm' request = urllib2.Request(url) response = urllib2.urlopen(request) request2 = urllib2.Request(url) c.add_cookie_header(request2) response2 = urllib2.urlopen(request2) print response2.geturl() print response2.info() # headers for line in response2.readlines(): # body print line From vze4rx4y at verizon.net Fri Aug 1 19:43:29 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Fri, 01 Aug 2003 23:43:29 GMT Subject: what do people use for 2D coordinates? References: Message-ID: "Andy C" wrote in message news:cf0d8a77.0308011537.5ed232f6 at posting.google.com... > You could use tuples or complex numbers (seems like a bit of a hack). For your application, complex numbers seem like a perfect choice. > I saw somewhere it said that tuples are useful for coordinates. But I > haven't found a nice way to add coordinates, since + does > concatenation on tuples. > > Is there a better way than to keep writing (a[0]+b[0], a[1]+b[1]) > instead of just a+b? (and 2*a instead of (2*a[0], 2*a[1]) ). I know > there is this NumPy library, but that seems like overkill for what I > need. I'm just doing some simple 2D drawing. I know it would be > trivial to write my own Point class, but I'm just wondering what other > people do. It would be nice if there was some built in module that > does basic vector math. See http://users.rcn.com/python/download/python.htm It has a pure python module for vector math and matrix operations. Raymond Hettinger From dave at solussoftware.com Thu Aug 28 09:33:17 2003 From: dave at solussoftware.com (Dave Brueck) Date: Thu, 28 Aug 2003 07:33:17 -0600 Subject: OT: Americans love their guns In-Reply-To: References: Message-ID: <200308280733.17414.dave@solussoftware.com> On Thursday 28 August 2003 12:40 pm, Lulu of the Lotus-Eaters wrote: > |The odds of getting killed that way are roughly the same as the odds > |that you'll die from aspirin or similar drugs > > No... this one is just way off. According to above URL form: > > 2000, United States > Adverse effects - Drugs Deaths and Rates per 100,000 > All Races, Both Sexes, All Ages > ICD-10 Codes: Y40-Y59,Y88.0 > > Number of Deaths Population Crude Rate Age-Adjusted Rate** > 255 275,264,999 0.09 0.09 Aren't statistics fun? :) Think about it: even intuitively, 255 is *way* too low for a population of 275 million (that's essentially zero - in a population that size 255 people probably die in sneezing-releated incidents every year) - I don't think that statistic represents what you think it represents. Compare, for example, an article from the Journal of the American Medical Association: http://jama.ama-assn.org/cgi/content/abstract/279/15/1200 Even just considering *hospitalized* people, there were 100,000 deaths due to adverse effects of drugs. From fawcett at teksavvy.com Thu Aug 14 01:37:22 2003 From: fawcett at teksavvy.com (Graham Fawcett) Date: Thu, 14 Aug 2003 01:37:22 -0400 Subject: system call in python In-Reply-To: References: Message-ID: <3F3B2012.9030101@teksavvy.com> Catherine Yang wrote: >Hi, > >A question about how to execute a system command from python program. e.g. >in a python script, I need to run another program written in C++, and after >that come back to the same python program. > >Is it the system module, and which function do I use to do this? > >Thanks a lot >Catherine > > > > Probably you are looking for os.system, as in: import os cmd = 'ls -l /usr/bin' os.system(cmd) Note that this will not capture the output of the system command; you can use the os.popen family of commands to do that. -- Graham From jmcheng at alum.mit.edu Tue Aug 12 14:32:59 2003 From: jmcheng at alum.mit.edu (Joe Cheng) Date: Tue, 12 Aug 2003 14:32:59 -0400 Subject: Summer reading list In-Reply-To: <1060711870.21962.19.camel@adsl-209.204.179.133.sonic.net> Message-ID: <001201c36100$292b8c80$85a8a8c0@JCHENG> > > It might just be my Java background creeping in (I'm a > Python newbie), but, > > wouldn't it be better if this was OO? > > > > heap = Heap() > > heap.push(item) > > item = heap.pop() > > item = heap[0] > > heapified = Heap(x) > > item = heap.replace(item) > > > > Otherwise the user could easily break the heap by doing > something dumb to > > the list... > > True. But the flexibility of using the builtin is also nice. For > example, you can add a bunch of objects to the list, then > heapify once, > rather than having to call heap.push() a bunch of times (which may be > slower, because you need to maintain the heap property after you push > each new item.) Hmmm, I'm not sure if I buy this particular argument. Line 5 in my examples there was supposed to illustrate constructing a heap from a list--so you could do pretty much the same thing. list = [1, 19, 33, 40] heap = Heap(list) I hope you are not suggesting there is also something to be gained by directly manipulating the list as a list after it has been heapified? :) Oh, and of course a heap class should probably support a to_list() export function (that returns a _copy_ of the internal list). > I think the idea is that, if you want a real Heap class, you can build > one very easily (see below). And if you don't need a heap class, you > can gain some benefits from this approach because it is exposing and > operating on lists directly. I've never heard this idea before... I'll need to chew on it a little. Is this a common notion among Pythoners? To me it sounds disturbingly like "Procedures are more flexible than classes because you can compose classes out of procedures." I'd worry that the proliferation of procedures would undermine good OO, which wants coupling at the class interface level. Meanwhile you gain nothing by using the raw procedures instead of dealing with the class. (Haven't thought too much about this, so I could be way off...?) > This probably comes under "practicality beats purity". (See > 'The Zen of > Python', or type "import this" into your Python interpreter) I don't consider myself an OO purist. However, in practical terms, I'd much rather work with a "black box" heap than one where I carry around its state in a mutable data structure... From adalke at mindspring.com Tue Aug 19 16:01:42 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Tue, 19 Aug 2003 20:01:42 GMT Subject: Brandon's priorities, to your relief References: Message-ID: Brandon J. Van Every: > type-treatment. To those of you who took my Ruby questions at face value, > and answered them perfunctorily, thanks! I got the information I wanted and > the conclusions haven't surprised me. I do not think you know the meaning of the word perfunctorily http://dictionary.reference.com/search?q=perfunctorily says > 1. Done routinely and with little interest or care: The operator > answered the phone with a perfunctory greeting. > 2. Acting with indifference; showing little interest or care. But I don't care any more. You're welcome. Andrew dalke at dalkescientific.com From shalehperry at comcast.net Mon Aug 18 04:30:22 2003 From: shalehperry at comcast.net (Sean 'Shaleh' Perry) Date: Mon, 18 Aug 2003 01:30:22 -0700 Subject: What's better about Ruby than Python? In-Reply-To: References: Message-ID: <200308180130.22425.shalehperry@comcast.net> > > Try the languages out yourself, both of them; program a non-trivial > > application in both languages. > > I frankly don't have the time, and am not afraid to leverage other people's > experiences to some degree. > > > Exactly: so don't ask for others' ideas. > > You have a profound difference of philosophy that I don't share. You seem > to think other people's opinions are all or nothing. > these two statements are the crux of the problem. If you joined a Chevy car mailing list and asked "what is better about Ford than Chevy?" would you expect to hear intelligent, insightful responses? Perhaps you would receive good answers, perhaps not. But if you never actually looked at a Ford how would you know? You see, by asking here you have people who have already decided against Ruby for whatever reason. All we can give you is our reasons for not choosing it. For balance you would HAVE to ask the Ruby people why they chose it over something like Python. Stating "well I just don't have time and would like others to decide for me" just won't get you very far. Might as well being asking the group to finish your homework assignments. BTW, my reason, like many here is Ruby looks like Perl and I prefer Python's syntax and design approach. Not a very scientific reason, about the same as saying "well, I like blue ones more than red ones". From jjl at pobox.com Mon Aug 18 17:07:38 2003 From: jjl at pobox.com (John J. Lee) Date: 18 Aug 2003 22:07:38 +0100 Subject: What's better about Ruby than Python? References: Message-ID: <87zni6wu79.fsf@pobox.com> "Andrew Dalke" writes: > William Trenker: > > c++ group:comp.lang.python from 1 Jan 2003 to today. 2,630 > > > > (for what it's worth) > > Relevant for the OP's thoughts. > > I also tried C#, but then wondered if google would have problems > with non-text characters, and if not, if the search for C++ would > be biased by > > int c = 0; > ... > c++; [...] Alex Martelli a while ago posted his way of doing language searches on Google -- searching for phrases like "x programmer", "x program", "x code" etc. (including quotes): substitute the name of your favorite language for x. Cuts out spurious stuff like 'c++;' (though in that particular case I expect the systematic error introduced would be small). There are interesting differences between the various terms: the more 'commercial' languages tend to turn up more hits for "x programmer" than the less-commercial ones, for example. As a whole, a bunch of such searches tells you more than any individual one would. Would be fun to write a Google API script, keep records, and put up a page to plot graphs of some simple metrics... No doubt somebody has done it already. Somewhere, I came across somebody who had graphed nr. of Amazon books over the years, by programming language, with a neat web interface (maybe that was pointed to by Alex's post, can't remember). IIRC, it breaks when you select Java -- too many books! The statistics were good enough to make it quite interesting, though of course the number of years availble was quite small. John From phil at riverbankcomputing.co.uk Wed Aug 20 06:21:37 2003 From: phil at riverbankcomputing.co.uk (Phil Thompson) Date: Wed, 20 Aug 2003 11:21:37 +0100 Subject: PyQT installation problems In-Reply-To: References: Message-ID: <200308201121.37379.phil@riverbankcomputing.co.uk> On Wednesday 20 August 2003 10:54 am, Stelian Iancu wrote: > Hello all! > > I am trying to install eric3, the Python IDE. I've downloaded and installed > successfully sip-3.8, QScintilla-1.2 and PyQT-3.8. However, when I try to > install eric, I get the following error: > > Sorry, please install PyQt. > > I looked into the install script, then I opened a Python window and there I > tried import qt and I got the following error: > > Traceback (most recent call last): > File "", line 1, in ? > File "/usr/lib/python2.2/site-packages/qt.py", line 25, in ? > import libqtc > ImportError: /usr/lib/python2.2/site-packages/libqtcmodule.so: undefined > symbol: _ZNK9QSGIStyle9classNameEv > > I am using Mandrake 9.1 with the default Python (2.2.3) and Qt. Please read the PyQt FAQ. Phil From mwilson at the-wire.com Thu Aug 7 09:26:37 2003 From: mwilson at the-wire.com (Mel Wilson) Date: Thu, 07 Aug 2003 09:26:37 -0400 Subject: generator function References: <215fa0fc.0308070503.2344dd66@posting.google.com> Message-ID: In article <215fa0fc.0308070503.2344dd66 at posting.google.com>, tom_chansky at rocketmail.com (chansky) wrote: >I read the following link about generator: >http://www.python.org/peps/pep-0255.html >but I am still not so clear on the use/purpose of a generator function >other than the fact that a generator can retain the state of the local >variables within the fuction body. Can someone out there shed some >lights on this topic or share about how/when you would ever use a >generator function. A generator is a function that's "called like" a sequence. If you want to process a series of values using "for ... in ..." you can either assemble the values into a sequence, or if they're being computed in the first place you can code the computation as a generator and save memory. In the built-in functions, `range` is a function that returns a list, `xrange` an alternative that is (or acts like) a generator. My latest example is from a program that cycled through all the possible 4-tuples constructed to some criteria to see which ones matched other criteria. Code went something like row_vals = ((1,2,3,4,5,6,7,8,9), (2,3,4), (1,3,5,7), (6,8)) def possible_rows (): for a in row_vals[0]: for b in row_vals[1]: for c in row_vals[2]: for d in row_vals[3]: yield (a, b, c, d) ... for row in possible_rows(): # further computations on row ... The actual program had row_vals built from user input, the "further computations" involved several different rows, etc. not as cut-and-dried as this example. Regards. Mel. From bokr at oz.net Sun Aug 17 14:03:23 2003 From: bokr at oz.net (Bengt Richter) Date: 17 Aug 2003 18:03:23 GMT Subject: bitwise not - not what I expected References: Message-ID: On Sun, 17 Aug 2003 13:05:13 GMT, "Elaine Jackson" wrote: > >"Tim Peters" wrote in message >news:mailman.1061098645.13097.python-list at python.org... > > >| To understand your example above, note that >| binary 10010 actually has an unbounded number of 0 bits "to the left": >| >| ...00000010010 = 13 >| >| The bitwise inversion of that therefore has an unbounded number of 1 bits >| "to the left": >| >| ...11111101101 = -19 > >** What you're saying, the way I read it, is that 5+S=(-19), where S is the >(divergent) sum of all the powers 2^k of 2 with k>=5. I'm still at sea, in other >words. > Since all the sign bits extend infinitely, we can chop them off any place above the first of the repeating bits to get N bits with some number of repetitions at the top. We will see that the interpreted numeric value does not depend on how far to the left we chop the bits, so long as we keep at least the first of the repeating bits. This representation of a signed integer with N total bits b(i) little-endianly numbered with i going 0 to N-1 and each bit having a value b(i) of 0 or 1 is interpreted as having the (N-1)th bit as the sign bit, and the rest positive, i.e., ___ i=N-2 \ a = -b(N-1)*2**(N-1)i + > b(i)*2**i /__ i=0 or in python, operating on a little-ending list of N bits, >>> def bitsvalue(b): #b is bitlist, to follow convention above ... N=len(b) ... sum = -b[N-1]*2**(N-1) ... for i in xrange(N-1): ... sum += b[i]*2**i ... return sum ... (Remember this is little-endian: least significant bit to the left, sign at the right) >>> bitsvalue([0,1,0,0,1,0]) 18 >>> bitsvalue([1,0,1,1,0,1]) -19 It doesn't matter how far you extend a copy of the top bit, the value remains the same: >>> bitsvalue([1,0,1,1,0,1,1,1,1,1,1,1]) -19 You can verify it from the math of the sum, if you separate it into two sums, one with the top repeating sign bits b(N-r) to b(N-1) and the other with the rest, which has the same constant value. I'll leave it as an exercise. >>> bitsvalue([1,1,1,1,1,1]) -1 >>> bitsvalue([1,1,1,1]) -1 >>> bitsvalue([1,1,1,0]) 7 > >| Python can't *guess* how many bits you want to keep. > >** But it could if someone had told it that the leftmost nonzero digit is the >place to start. I just assumed somebody had told it that. > Or the leftmost bit that is either the only bit of all or different from the one to its right is the minimum sign bit to copy arbitrarily leftwards. > >| Python represents negative integers in unbounded 2's-complement form > >** Now we're getting someplace. That was the missing piece in my puzzle. > Ok, I guess you don't need the demo prog after all ;-) Regards, Bengt Richter From mwh at python.net Fri Aug 15 08:34:42 2003 From: mwh at python.net (Michael Hudson) Date: Fri, 15 Aug 2003 12:34:42 GMT Subject: Does anybody has gnus score file for comp.lang.python? References: <87ekznsvn9.fsf@big.terem> Message-ID: <7h3y8xv2j9p.fsf@pc150.maths.bris.ac.uk> Vlad Sirenko writes: > Does anybody has gnus score file for comp.lang.python? > Pls mail it to me. I only have adaptive scoring, and don't know where gnus keeps that :-) Cheers, mwh -- M-x psych[TAB][RETURN] -- try it From tjreedy at udel.edu Sun Aug 31 12:14:43 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 31 Aug 2003 12:14:43 -0400 Subject: Declaration of an array of unspecified size References: Message-ID: "Bertel Lund Hansen" wrote in message news:m814lvc8h44vbd5g1m2iv05r33qg8ag9ta at news.stofanet.dk... > Hi all > > I am relatively new to Python but have som programming > experience. I am experimenting wit a POP3-program and it's fairly > easy. > > I want to read the mails into an array of lists so I later can > choose which one to display. But I need to declare an array of > unknown size before I can use it in the code. No you don't ;-) Part of the beauty of Python (and part of its slower-than-C-ness) is that lists (and dicts) expand to accomodate the data put in them (up to RAM limits). Which means, by the way, no overruns and the consequences thereof. >How do I manage # simple version emails = [] # create empty list. # choose loop statement: while anotheremail(): # or for i in range(number_of_emails()): # then add to list emails.append(nextemail()) If you write email fetcher as generator, then "emails = list(emailgetter(*args))". Terry J. Reedy From graham at rockcons.co.uk Thu Aug 7 12:13:35 2003 From: graham at rockcons.co.uk (Graham Nicholls) Date: Thu, 07 Aug 2003 17:13:35 +0100 Subject: Extracting a short using struct - won't print. References: <3f3273f7$0$10777$afc38c87@auth.uk.news.easynet.net> <3F32758E.5734C64F@engcorp.com> <3f32779d$0$10780$afc38c87@auth.uk.news.easynet.net> Message-ID: <3f327aaf$0$10770$afc38c87@auth.uk.news.easynet.net> Richard Brodie wrote: > > "Graham Nicholls" wrote in message > news:3f32779d$0$10780$afc38c87 at auth.uk.news.easynet.net... > >> >> seg_stru=">BHH" >> >> seg_data=self.fhand.read(struct.calcsize(seg_stru)) >> >> data=struct.unpack(seg_stru,seg_data) >> >> x=seg_data[1] >> >> y=seg_data[2] >> > >> > Why are you unpacking the struct if you aren't going to use the >> > unpacked data? >> >> Err, I'm trying to extract two shorts - the x and y size in pixels of an >> image, which I'll use to scale it to fit another pair of parameters. >> What makes you think I'm not using the data? Am I not - I thought I was! > > You aren't using the returned value from struct.unpack() anywhere. > You need something like x, y = struct.unpack(seg_stru,seg_data) I told you it'd be something stupid! I mean x=data[1] y=data[2] don't I! Thanks!!!! Graham -- Graham Nicholls Rock Computer Consultancy From aleax at aleax.it Thu Aug 21 04:53:30 2003 From: aleax at aleax.it (Alex Martelli) Date: Thu, 21 Aug 2003 08:53:30 GMT Subject: What's better about Ruby than Python? References: Message-ID: Joshua Marshall wrote: > Alex Martelli wrote: > ... > >> But with try/finally, or hopefully some syntax tweak making >> try/finally semantics even easier to use, this is a kind of idiom >> that's gonna stay. > > What sort of syntax tweak? Several possibilities have been discussed on python-dev in the past. E.g., : translating into: .begin() try: try: except: if .exception_caught(): raise else: .correct_termination() finally: .end() or variants thereon. Alex From news.collectivize at scandaroon.com Tue Aug 26 19:52:57 2003 From: news.collectivize at scandaroon.com (John Baxter) Date: Tue, 26 Aug 2003 16:52:57 -0700 Subject: [OT] Why is it called string? References: <3f44ce77$0$556$b45e6eb0@senator-bedfellow.mit.edu> <3F44DBF2.1010403@draigBrady.com> <3f453a22$1_1@themost.net> Message-ID: In article , Jarek Zgoda wrote: > Piet van Oostrum pisze: > > >>> My CS professor would insist that a byte is a collection of bits, and not > >>> necessarily eight. There are machines which do not have 8-bit addressable > >>> bytes. > > > >JZ> I remember that "byte" in French is expressed as "octet", even if it has > >JZ> only 7 bits... > > > > Are you sure. Several international organisations use the word 'octet' in > > their official specifications, to make sure that an 8-bit byte is meant. > > I cann't recall the machine I'm referring to (it was product of Bull), > but I am sure that lecturer called 7 bit units as "octets". The "oct" prefix, which reasonable people might expect to mean "8" has been abused for several years. One evening at WTBS (the MIT version, before the sailor guy from Atlanta bought the callsign from my successors), I soldered up an 11-pin octal plug. Then I unwired it, installed the plug cover, and soldered it up again. Then, I unwired it, turned the plug cover around the proper way, and wired it up yet again. [Pretty good lesson: I haven't forgotten a plug cover or gotten one backwards since.] --John -- Email to above address discarded by provider's server. Don't bother sending. From ask at me.com Fri Aug 22 18:52:13 2003 From: ask at me.com (Greg Krohn) Date: Fri, 22 Aug 2003 22:52:13 GMT Subject: visual indentation References: Message-ID: "Hilbert" wrote in message news:slrnbkcja7.s51.Hilbert at server.panka.com... > Hello, > > I'm using python to output RIB streams for Renderman. > The RIB stream is a bunch of statements which describes > a 3d image. The Rib standard allows for blocks which we > usually indent for better visualization for example: > > WorldBegin > Color [1 1 1] > Surface "constant" > Sphere(1.0, -1.0, 1.0, 360) > WorldEnd > > I'm using CGKit in python which has a Renderman binding, > so to output the same RIB I'd write: > > RiWorldBegin() > RiColor(1.0,1.0,1.0) > RiSurface('constant') > RiSphere(1.0,-1.0,1.0,360) > RiWorldEnd() > > But I get an error, because python interprets my indentation > as a block in the python code. So the only way to write this > is without the indentation: > > RiWorldBegin() > RiColor(1.0,1.0,1.0) > RiSurface('constant') > RiSphere(1.0,-1.0,1.0,360) > RiWorldEnd() > > But this is a lot harder to read. > > Is there any way to use such "visual" indentation in python? > > Thanks, > Hilbert > > hilbert at panka.com > > What about an if statement: RiWorldBegin() if True: RiColor(1.0,1.0,1.0) RiSurface('constant') RiSphere(1.0,-1.0,1.0,360) RiWorldEnd() I realize it's ugly, but it's easy. From dave at pythonapocrypha.com Sat Aug 16 13:00:56 2003 From: dave at pythonapocrypha.com (Dave Brueck) Date: Sat, 16 Aug 2003 11:00:56 -0600 Subject: Porting to Windows In-Reply-To: References: Message-ID: <200308161100.56453.dave@pythonapocrypha.com> On Friday 15 August 2003 05:21 pm, Ramon Leon Fournier wrote: > Zora Honey wrote: > > I've been programming Python on Linux for a while now, and I'm finally > > ready to start porting some of my stuff to Windows. > > Why would you want to port your work to Windows? > > As a free citizen you have chosen to develop your programs using a free > programming language on a free operating system. Thus I postulate that > you are aware of the great advantages of such a quality environment. > Why then are you planning to port the fruit of your labour to an > operating system whose developers do everything they can to undermine > your freedoms? Maybe because his customers use Windows? Maybe because of market share? There are plenty of legitimate reasons to port to Windows, regardless of what you think about Microsoft, so it's a unhelpful to answer his question by saying he's wasting his time. > Porting software to Windows won't help anyone except Microsoft, Nonsense. One example: if you write commercial software for Joe Consumer it's much tougher to make a living off it if you target Linux only. For now at least, individual Windows users tend to be much more open to purchasing software, so by targeting Windows you have a larger potential market. > even the Windows users themselves. Why? Because instead of trying out a > free operating system, people will continue to use Windows. At the same > time they will not encourage others to move away from Windows, which > they would do if they had made that move already. I use Linux about half the time (I'm writing this from a Linux box, for example) and think it's great, but there are some great business reasons to support Windows (or do you think e.g. the PC games industry should target Linux exclusively "on principle"?). -Dave From bgailer at alum.rpi.edu Mon Aug 11 12:48:19 2003 From: bgailer at alum.rpi.edu (Bob Gailer) Date: Mon, 11 Aug 2003 10:48:19 -0600 Subject: proper loop syntax? In-Reply-To: Message-ID: <5.2.1.1.0.20030811102210.02caaa90@66.28.54.253> At 11:04 AM 8/11/2003 -0500, JLowder at 360commerce.com wrote: >Standard disclaimer here, I'm new to Python/Jython.. > >I have what should be a really simple for loop with nested if/elif's which >doesn't seem to function correctly. > >The problem is, only the first IF/ELIF are read. None of the other elif's >are used. In fact, the first elif is used when it shouldn't be and I >don't know why. This is my code snippet: > >mask = "XXNNxxASSs" > >for t in range(licenses): # licenses = 5 > > for y in mask: > if y == "x": > if t == 0: > license_char = "5" > elif t == 1: > license_char = "P" > elif t == 2: > license_char = "o" > elif t == 3: > license_char = " " > elif t == 4: > license_char = "*" > > elif y == "a" or "S": y =="a" or "S" evaluates to "a" if y == "a" and evaluates to "S" otherwise. Therefore the if condition is always true, and the code block following is executed. The program never gets to elif y == "X" or "s": Code it this way instead: elif y == "a" or y == "S" or even better: elif y in "aS": > if t == 0: > license_char = "T" > elif t == 1: > license_char = " " > elif t == 2: > license_char = "w" > elif t > 2: > license_char = "t" > > elif y == "X" or "s": > if t == 0: > license_char = "7" > elif t == 1: > license_char = "G" > elif t == 2: > license_char = "f" > elif t == 3: > license_char = "*" > elif t > 3: > license_char = "u" > > license = license + license_char > >The variable license ends up being TTTT55TTTT for the first pass. The >5's are correct, but the T's should only be there for two of the >characters (I'm expecting the value to be "772255LTT7"). To save on the >length of the email, I'm leaving out two more elif's. If I were to move >the elif y == "X" or "s": to be the first elif, the T's would then become >7's. The first elif is the only one being used. What I don't understand >is why is the first elif even being looked at if y does not equal a or >S? My spacing works, because I endup with indent errors otherwise. The >structure looks correct for what I'm used to in other scripting languages... > >What stupid human trick am I pulling here? I don't see a case for 'N', so m,y code below ignores it. A better overall approach (IMHO) is to use dictionaries and lists: char_sets = ['5Po *', 'T Wt', '7Gf*u'] mask_chars = {'x' : char_sets[0], 'a' : char_sets[1], 'S' : char_sets[1], 'X' : char_sets[2], 's' : char_sets[2]} license = '' licenses = 5 mask = "XXNNxxASSs" for t in range(licenses): for y in mask: if y in mask_chars: chars = mask_chars[y] if t < len(chars): try:license += chars[t] except:print y,t print license >Jason >--- >Incoming mail is certified Virus Free. >Checked by AVG anti-virus system (http://www.grisoft.com). >Version: 6.0.506 / Virus Database: 303 - Release Date: 8/1/2003 Bob Gailer bgailer at alum.rpi.edu 303 442 2625 -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.506 / Virus Database: 303 - Release Date: 8/1/2003 From shrom at admin.zzn.com Fri Aug 1 08:49:29 2003 From: shrom at admin.zzn.com (Shrom) Date: Fri, 1 Aug 2003 14:49:29 +0200 Subject: Retrieve source filename References: <3f29207d$0$24768$626a54ce@news.free.fr> Message-ID: <3f2a61d9$0$24765$626a54ce@news.free.fr> "Steven Taschuk" a ?crit dans le message de news:mailman.1059699303.12610.python-list at python.org... > Quoth Shrom: [SNIP] > As of 2.3, the __main__ module also has a __file__ attribute, so > you can just do > sys.modules[__name__].__file__ > The (an?) exception is when __main__ is the text in a 'python -c' > command -- then there is, of course, no file name. And for > compatibility with versions < 2.3, you have to check for the case > __name__ == '__main__' and go to sys.argv[0]. Thanks very much that's what i was searching. From abuseonly at sgrail.org Sun Aug 24 00:37:42 2003 From: abuseonly at sgrail.org (derek / nul) Date: Sun, 24 Aug 2003 04:37:42 GMT Subject: Bug with win32 open and utf-16 file References: <27vekvc6evvn3m5jg8n1en2u42skat42qn@4ax.com> <2i1gkv0s7762vcs85rkdq6uvgk6oitje12@4ax.com> <78egkvg1tu0j1kvedclcefn01hr3vkqh4v@4ax.com> Message-ID: On Sun, 24 Aug 2003 07:29:46 +0300, Christos "TZOTZIOY" Georgiou wrote: >On Sun, 24 Aug 2003 04:13:44 GMT, rumours say that derek / nul > might have written: > >>Interesting, I have just done the same and it would appear that the hexdump >>routine is changing 0d to 0a ??? > >A quick glance at the code seems not, but this is not authoritative. > >>I don't understand what the data[-2:] is doing, could you explain please or >>point to some notes on this. > >This is a slicing operation, prints the last two bytes of the string -- >you mean you haven't read the tutorial? I have but not well enough by the look of it. >Check strings (and slicing) at: >http://www.python.org/doc/current/tut/node5.html#SECTION005120000000000000000 > >but you better read the tutorial at: > >http://www.python.org/doc/current/tut/tut.html > >(you might have it on your computer already). > >Say... :) you don't happen to be an HP owner that found python >preinstalled on your PC, are you? errr, no, just a small p programmer from vb and perl trying to learn an OO language. Derek From rnd at onego.ru Sun Aug 3 01:12:17 2003 From: rnd at onego.ru (Roman Suzi) Date: Sun, 3 Aug 2003 09:12:17 +0400 (MSD) Subject: Wow: list of immediate subclasses? In-Reply-To: Message-ID: On Fri, 1 Aug 2003, Andrew Dalke wrote: >Carl Banks, responding to Roman Suzi: >> __subclasses__ is a list of weak references, so the class can be >> collected even though it's listed in __subclasses__. For whatever >> reason, class A isn't deleted by reference counts, but cyclic garbage >> collection gets it. > >It's a bit too mysterious for my liking. I wonder why to have __subclasses__() at all... I recall somebody (Tim Peters?) tolds us that classes are essentially just dictionaries - everything else is an imagination by OO-brains and fluffy operations like computing MRO. __subclasses__ aren't needed for OO to work. What for they really are? Just to have nice way to know subclasses? Why not to use some external framework for that task, hooking object manipulation to some routine if necessary? I can't find any reference to __subclasses__ in standard library! (I was looking for __subclasses__ string) Sincerely yours, Roman Suzi -- rnd at onego.ru =\= My AI powered by GNU/Linux RedHat 7.3 From vze4rx4y at verizon.net Thu Aug 21 01:05:52 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Thu, 21 Aug 2003 05:05:52 GMT Subject: Dictionary that uses regular expressions References: <1f0bdf30.0308202049.7d251469@posting.google.com> Message-ID: "Erik Lechak" wrote in message news:1f0bdf30.0308202049.7d251469 at posting.google.com... > Hello all, > > I wrote the code below. It is simply a dictionary that uses regular > expressions to match keys. A quick look at _test() will give you an > example. > > Is there a module that already does this? Google may prove me wrong, but this looks like a new idea. > Is there a way and would it > be better to use list comprehension? (using python 2.3) > > Just looking for a better or more pythonic way to do it. Try inheriting from UserDict.DictMixin instead of dict. Also, see if there are ways to change the API so that there is a single return type. That would relieve the user of having to test every call to see whether it got a collection of answers or a specific answer. One idea is to have __getitem__ return an iterator so that it doesn't matter where the number of matches is zero, one, or many: for value in rd['put may 7.5'] print value Raymond Hettinger From mm2ps at yahoo.co.uk Fri Aug 1 22:06:53 2003 From: mm2ps at yahoo.co.uk (Douglas) Date: 1 Aug 2003 19:06:53 -0700 Subject: re or html parser module, for wildcard search within html document? Message-ID: <4cec047f.0308011806.68d8d056@posting.google.com> I want to search and replace some expressions within an html document. Specifically, I want to replace any tag containing the word "font" with a new tag. As I want to use some form of wild card for the search, eg. <*font*>, should I use a regular expression module (re) or one of the specific html parsers? If this should be done with an html parser module then which one and where is some easy going introductory documentation, please? Douglas From bhv1 at psu.edu Fri Aug 1 12:45:54 2003 From: bhv1 at psu.edu (Brian Victor) Date: Fri, 01 Aug 2003 16:45:54 GMT Subject: curses and use_default_colors() References: <7652139e.0307291843.2ade58c6@posting.google.com> Message-ID: Brian Victor wrote: > Interestingly, both Terminal and iTerm seem to make everything > transparent, so use_default_colors has no significant effect. That is, > a black background is indistinguishable from a transparent/default > background. I forgot to mention that I hit a compile error on OSX's ncurses header file. I believe it came from the December dev tools. It dealt with redefining wchar_t: #ifndef _WCHAR_T typedef unsigned long wchar_t; #endif /* _WCHAR_T */ I have no idea why the mac version does that (fink's does also). My linux copy of the headers has nothing like that. #defining _WCHAR_T before including ncurses.h fixed that, but I don't know if that's a permanent solution. FWIW, I was doing this with python 2.3a1. -- Brian From mis6 at pitt.edu Sat Aug 2 11:53:46 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 2 Aug 2003 08:53:46 -0700 Subject: Singleton-like pattern References: <2259b0e2.0308010815.5dcb0b58@posting.google.com> Message-ID: <2259b0e2.0308020753.25c8299d@posting.google.com> pedro.werneck at bol.com.br (Pedro Werneck) wrote in message news:... > On 1 Aug 2003, Bengt Richter wrote: > > > >> class MultiSingleton(type): > class MultiSingleton(object): > > >> def __call__(cls, *args, **kwds): > def __new__(cls, *args, **kwds): > > >> cache = cls.__dict__.get('__cache__') > > >> if cache is None: > > >> cls.__cache__ = cache = {} > > >> tag = str(args) + str(kwds) > tag = '%r%r'% (args, kwds) # might be an alternative > > >> if tag in cache: > > >> return cache[tag] > > >> obj = object.__new__(cls) > > >> obj.__init__(*args, **kwds) > > >> cache[tag] = obj > > >> return obj > > This is exactly what I did at first... I only changed it to a metaclass > because I was adding it to a module that already contain some other > metaclasses I use; I think it's more elegant as I said before... a > 'quick and dirty' benchmark with the timeit module returned the > folowing results, and in this project I will be dealing with a database > of 7000+ items, this 20% bit may help a little: > > __metaclass__: > [39.744094967842102, 40.455733060836792, 42.027853965759277] > > __new__: > [47.914013981819153, 48.721022009849548, 49.430392026901245] > > > On 1 Aug 2003, Michele Simionato wrote: > > > "memoize" is a possible name for this. Notice that the metaclass is a > > bit of overkill, you may well use a simple function for this job. > > Hey... you wrote such a good article on python metaclasses and now don't > want people to use them ? :) Maybe it is because I know them that I don't want to abuse them ;) Consider also that not everybody knows about metaclasses, and I want my code to be readable to others; finally, there is Occam's rasor argument (i.e. do not use metaclasses without necessity). > > Does (args,kw) work in general? IWT you could easily get something unhashable? > > IWT using a tuple of actual args may also be a bad idea since it would prevent callers' > > temp args from being garbage collected. I use repr to avoid that, maybe mistakenly? > > > About the issue of finding a suitable key, in the same situation I have > > used the tuple (args,kw) as key. But me too I would like to ask if this is a > > good idea. What's the custom solution for getting a good key from > > a dictionary ? > > Actually, (args, kw) doesn't work at all, even if you only get hashable > arguments... the 'kw' dict invalidate it as a key... besides, there's the > garbage collection problem, as Bengt Richter mentioned... Yes, as I replied to Carl Banks, actually I have got problems with (args,kw) and I think at the end I used args+tuple(kw.iteritems()), but I had forgotten at the time of the posting. > The "%r%r"%(args, kwds) works, as well as str((args, kwds))), but it > breaks if you get as argument an object with the default __repr__, as > the object id may be different, even if they are equal. Overriding __repr__ > and returning a real representation avoids this problem. > > Thanks for your time. > > Pedro Werneck Michele From vze4rx4y at verizon.net Mon Aug 18 03:35:25 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Mon, 18 Aug 2003 07:35:25 GMT Subject: Py2.3: Feedback on Sets References: Message-ID: <1l%%a.11057$Cd2.7776@nwrdny01.gnilink.net> > [Beni Cherniavsky] > >> `isdisjoint` sounds like a good idea since it can be implemented > >> more effeciently than ``not a & b``. > > [Raymond Hettinger] > > True enough. It is easy to putogether an early-out algorithm using > > itertools. So, it can be done a C speed. The question is whether > > there are sufficient use cases to warrant expanding an already fat API. [Tim Peters] > Early-out algorithms consume time to determine when the early-out condition > obtains, and so can be a net loss (via consuming more time testing for > early-out than is saved by getting out early). See the long comment block > before _siftup in heapq.py for a classic case where early-out usually loses > big. For isdisjoint() it's muddier (depends on whether your data is such > that most sets fed to it are or aren't disjoint; if they're usually > disjoint, code testing for early-out is a waste of time). In this case, early-out is sometimes faster and is never slower than bool(a&b). This reason is that they both do exactly the same steps until encountering the first common element; no extra work is required for the early out test. Instead, the for-loop just bails-out: def isdisjoint(self, other): """Return True if the sets do not share any common elements""" if len(self) <= len(other): little, big = self, other else: little, big = other, self for elem in ifilter(big._data.has_key, little): return False return True Raymond Hettinger From alanmk at hotmail.com Mon Aug 18 06:19:47 2003 From: alanmk at hotmail.com (Alan Kennedy) Date: Mon, 18 Aug 2003 11:19:47 +0100 Subject: WebDAV References: Message-ID: <3F40A842.16251E80@hotmail.com> William Trenker wrote: > > I've been goolging for a WebDAV client written in Python. I've > found http://www.webdav.org/projects/ which includes > http://www.lyra.org/greg/python/davlib.py but not much else for > the client side. Zope's WebDAV package also includes > http://cvs.zope.org/Packages/webdav/client.py > > Does anyone know of any other WebDAV client software written in > Python? I'm trying to programmatically access my Zope site via DAV > so I guess Zope's own client.py would be the way to go. But I'd be > interested to know of other DAV clients written in Python. Bill, There used to be another webdav client for python, but I can't seem to find it now. I think the hosting site name was something like "Content Lounge"? I searched the Internet Archive (www.archive.org) to see if it was there, but I couldn't find it. I just wanted to point out some other options you might consider for addressing your problem:- 1. Use a java webdav client, and script it with jython. If you need to communicate between jython and cpython, use Pyro. 2. You could script a webdav capable browser, such as MS Internet Explorer, to act as your programmable webdav client. With MSIE, you could use cpython + win32 extensions. I don't know if recent versions of Netscape/Mozilla are webdav capable? regards, -- alan kennedy ----------------------------------------------------- check http headers here: http://xhaus.com/headers email alan: http://xhaus.com/mailto/alan From vanevery at 3DProgrammer.com Tue Aug 19 04:12:14 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Tue, 19 Aug 2003 01:12:14 -0700 Subject: Brandon's abrasive style (was Re: What's better about Rubythan Python?) References: <38ec68a6.0308172319.431a4fde@posting.google.com> Message-ID: Cliff Wells wrote: > > Quoting the Dalai Lama: > Conventional truth, conventional reality is a consensus reality, > something that people agree on. Events do not have a reality of their > own. All events depend on other events. Nothing (no person) has an > independent identity, there is no intrinsic reality. What is called > "reality" depends on the context of other factors. > > While I don't necessarily consider the Dalai Lama an authority on all > (or even many) things, I think there is certainly a great amount of > truth to this observation. If the majority of people think you are > trolling, then, whether you intend to or not, perhaps you are. Then you missed what the Dalai Lama said. He did not speak of essence. He spoke of events depending on other events. And I'm quite conversant with what Troll Hunters depend on. > If you were being truly pragmatic, as you claim, then you must surely > realize that offending people with an abrasive approach is > counter-productive. Counter-productive to what agenda? My current agenda is identifying the unworkable people and disposing of them. > You might think that killfiling those people will teach > them a lesson (it won't, they could probably care less), Frankly, I don't think I've killfiled anyone who's worth the trouble to un-killfile. I seriously doubt that they have anything important to say that I have to hear. > Part of the reason people respond to you so violently is because you > tend to make unsubstantiated and provocative claims and then accuse > people of being "knee-jerk reactionaries" when they dismiss them. It's only the people calling me a troll that I label "knee-jerk reactionaries." -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From pobrien at orbtech.com Fri Aug 29 14:02:07 2003 From: pobrien at orbtech.com (Patrick K. O'Brien) Date: 29 Aug 2003 13:02:07 -0500 Subject: Object Database (ODBMS) for Python References: <1DAECE9E8F34E04AA0E5699AF7D9FF090708D440@stpmsg00.corp.fairisaac.com> <3f4f7af6_3@corp.newsgroups.com> Message-ID: "Paul D. Fernhout" writes: > My biggest issue with OO databases (including "a Smalltalk image" > for that matter) in general is that the definition of objects > changes over time, and on a practical basis, it might be needed to > support multiple definitions of a class with the same name > simultaneously if supporting a broad range of applications and > somehwo resolve version issues. The Pointrel System in itself > doesn't solve that problem either, but it also doesn't have that > problem built in at the core, since its main storage type is just an > arbitrary binary string. I mainly added the Python object support > just because "pickle" made it easy and fun to do the basics, and I > thought that a limited level of transparent support might make it > more appealing to Pythonistas and provide some extra easy > expanability if people really wanted to easily store typed > information as oposed to strings. (ALthough I think it could also > bring headaches if people have PyPerSyst level expectations for > object storage and retrieval when I support something more like a > Newton soup entry..) Schema evolution and schema migration are tough issues. In some ways things are simpler with PyPerSyst, since all objects reside in memory at all times. What that means is that there is no need to write utilities that "touch" all of your instances. When you start a PyPerSyst database, the entire thing is unpickled, which calls __setstate__ on all your objects. So migrating to a new schema is simply a matter of dumping the database, stopping the engine, replacing the schema, and restarting the engine. Making sure that your schema does the right thing is another matter. I'm still working on that. Ideally you would want your class definitions to themselves be a persisted schema that could only be modified by transactions that would generate the appropriate __getstate__ and __setstate__ methods to properly handle the changes. So a distant goal is to have a PyPerSyst application that handles schema evolution and migration for other PyPerSyst databases. Doesn't that sound like fun? -- Patrick K. O'Brien Orbtech http://www.orbtech.com/web/pobrien ----------------------------------------------- "Your source for Python programming expertise." ----------------------------------------------- From mike at bindkey.com Thu Aug 21 16:38:56 2003 From: mike at bindkey.com (Mike Rovner) Date: Thu, 21 Aug 2003 13:38:56 -0700 Subject: Fw: Removing language comparisons Message-ID: <00a301c36824$3f5b8660$1500a8c0@elf.bindkey.com> Mike Rovner wrote: > A.M. Kuchling wrote: >> python.org has a page of "Python vs. X" language comparisons at >> . They're all pretty >> outdated, and often unfair because they're written by a person who >> knows Python well but has only a nodding acquaintance with language >> X. >> >> I'm planning to drop this page from python.org because it's so >> outdated and no one is around to maintain it. If anyone wants to >> grab the contents and turn them into a Wiki page, or use bits of them >> for marketing material, please do it now. > > Done. > > See http://www.python.org/cgi-bin/moinmoin/PythonLanguageComparisons > > Mike From jari.aalto at poboxes.com Tue Aug 19 01:25:32 2003 From: jari.aalto at poboxes.com (Jari Aalto+usenet) Date: Tue, 19 Aug 2003 08:25:32 +0300 Subject: pythong program install: linking cannot find -lpython2.3 Message-ID: [Please keep CC] Hi, Where I can specify more linking search directories for a Python module that makes a gcc build? Setting the LD_LIBRARY_PATH on command line does not seem to propagate to the linker. Jari root at w2kpicasso:/usr/share/site-python/xmldiff-0.6.3# echo $LD_LIBRARY_PATH /lib:/usr/local/lib:/usr/lib:/usr/lib/python2.3/config root at w2kpicasso:/usr/share/site-python/xmldiff-0.6.3# python setup.py build /usr/lib/python2.3/distutils/dist.py:213: UserWarning: 'licence' distribution option is deprecated; use 'license' warnings.warn(msg) running build running build_py running build_ext building 'logilab.xmldiff.maplookup' extension gcc -shared -Wl,--enable-auto-image-base -static -Wall -Wno-format -Wstrict-prototypes -Wmissing-prototypes -DGETTEXT_STATIC build/temp.cygwin-1.3.22-i686-2.3/logilab/xmldiff/extensions/maplookup.o -L. -lpython2.3 -o build/lib.cygwin-1.3.22-i686-2.3/logilab/xmldiff/maplookup.dll /usr/lib/gcc-lib/i686-pc-cygwin/3.2/../../../../i686-pc-cygwin/bin/ld: cannot find -lpython2.3 collect2: ld returned 1 exit status error: command 'gcc' failed with exit status 1 From peter at engcorp.com Wed Aug 20 14:19:55 2003 From: peter at engcorp.com (Peter Hansen) Date: Wed, 20 Aug 2003 14:19:55 -0400 Subject: 'name is too long' (tarfile, python 2.2, Debian Woody) References: <3F43306D.3080704@skynet.be> Message-ID: <3F43BBCB.99C3E163@engcorp.com> Lars Behrens wrote: > > I found this in the tarfile doc: > > -- snip -- > posix=True > If True, create a POSIX 1003.1-1990 compliant archive. GNU extensions > are not used, because they are not part of the POSIX standard. This > limits the length of filenames to at most 256 and linknames to 100 > characters. A ValueError is raised, if a pathname exceeds this limit. If > False, create a GNU tar compatible archive. It will not be POSIX > compliant, but can store pathnames of unlimited length. > -- snap -- > > So, I put this in my script: > > tar.posix=True > > before > > tar.add('bla') > > This seems to work. But honestly, I don't quite understand > what I did :-\ Perhaps this is a sign that the problem was really somewhere else. What you say you did is not likely to have solved the problem given the documentation above. It says that setting tar.posix to *False* would allow longer path names, not the other way around. If you think you just got longer names to work and your problems went away, you are probably missing something here... -Peter From anthonyr-at-hotmail-dot-com at nospam.com Wed Aug 27 21:51:19 2003 From: anthonyr-at-hotmail-dot-com at nospam.com (Anthony Roberts) Date: Thu, 28 Aug 2003 01:51:19 GMT Subject: Style question... References: <3f4d41b3$0$244$626a54ce@news.free.fr> Message-ID: > *yuck* :( LOL! I'm sorry. :) From logiplex at qwest.net Tue Aug 19 17:43:02 2003 From: logiplex at qwest.net (Cliff Wells) Date: Tue, 19 Aug 2003 14:43:02 -0700 Subject: What's better about Ruby than Python? In-Reply-To: <9755kv4bku839cpsqrvch13504qagg7gev@4ax.com> References: <38ec68a6.0308172319.431a4fde@posting.google.com> <9755kv4bku839cpsqrvch13504qagg7gev@4ax.com> Message-ID: <1061329381.29677.6.camel@software1.logiplex.internal> On Tue, 2003-08-19 at 14:22, Tim Rowe wrote: > On 18 Aug 2003 16:38:42 -0400, aahz at pythoncraft.com (Aahz) wrote: > > >Oh, come on, Brandon is *much* less of a troll than T*m*t*y R*e. > > Dangerously close to my name -- I hope it's not a typo and meant to > /be/ my name! You have the unfortunate distinction of having a similar name to a prolific nutjob: http://www.google.com/search?q=%22timothy+rue%22+autocoding&btnG=Google+Search Regards, -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 (800) 735-0555 From sjmachin at lexicon.net Mon Aug 4 09:55:23 2003 From: sjmachin at lexicon.net (John Machin) Date: Mon, 04 Aug 2003 13:55:23 GMT Subject: Match beginning of two strings References: Message-ID: <3f2e63e6.12320195@news.lexicon.net> On Mon, 04 Aug 2003 11:56:04 GMT, Alex Martelli wrote: > I'm not sure where I went wrong in >the Pyrex coding (it doesn't seem to be performing anywhere >as well as I thought it might) and I'll be happy for real >Pyrex expert to show me the way. I don't call myself an expert, but here's my best shot: If you look at the generated C code, you'll see lots of conversion between C and Python types. The trick is to get your args into C, stay in C as much as possible, and ship back a Python return value. It's made harder with strings as there is not (yet) any way of hinting to Pyrex to use the "s#" gadget, you have to DIY, see below. cdef extern from "Python.h": int PyString_Size(object s) def exa2(arga, argb): cdef int la, lb, lmin, i cdef char *a, *b a = arga b = argb la = PyString_Size(arga) lb = PyString_Size(argb) # living dangerously, not testing for error; # Easy to eyeball for correctness in this case, # but ... if la <= lb: lmin = la else: lmin = lb i = 0 while i < lmin: if a[i] != b[i]: return arga[:i] i = i + 1 if lmin == la: return arga else: return argb From kern at taliesen.caltech.edu Sat Aug 9 04:21:56 2003 From: kern at taliesen.caltech.edu (Robert Kern) Date: Sat, 9 Aug 2003 08:21:56 +0000 (UTC) Subject: Slogan: Getting Rich Overnight References: Message-ID: In article , Christian Tismer writes: [snip] > I loved this statement very much, and I have to say, this > is essentially my feeling for myself, since many years now. > I could imagine that this might be a candidate for next year's > Python congress' slogan. "Python makes you rich, overnight". > Not by money, in the first place, but by multiplying your > own capabilities, immediately. While I certainly share that sentiment, I would advise caution in the phrasing of such a slogan: if I hadn't seen your name, I would have skipped your article as spam! -- Robert Kern kern at caltech.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter From gerrit at nl.linux.org Wed Aug 27 14:52:28 2003 From: gerrit at nl.linux.org (Gerrit Holl) Date: Wed, 27 Aug 2003 20:52:28 +0200 Subject: OT: Celebrity advice (was: Advice to a Junior in High School?) In-Reply-To: References: Message-ID: <20030827185228.GA4352@nl.linux.org> Terry Reedy wrote: > " Every political choice ultimately reduces to a choice about when and > how to use lethal force, because the threat of lethal force is what > makes politics and law more than a game out of which anyone could opt > at any time." > > Do you disagree? Yes. Maybe a government needs to use violence to enforce people getting into prison if they refuse to obey the law. But a prison is not lethal (at least, not in civilized regions like those in Europe and some parts of the USA). If a community decides to build a road, it has nothing to do with lethal force. Nor does it to strengthen the dikes, or cut taxes, or even create more strict gun laws. This statement by ESR is absolute nonsense. > Or are you one who doesn't the 'people' to notice the > elitist hypocrisy of being 'anti-gun' while supporting the bearing > *and use* of guns by 'govern-men' the elitists hope to control? I am against all violence. But because we don't live in Utopia, the government sometimes needs to use violence to enforce the law. The difference is that, in civilized countries, the law is (mostly) democratic and (for a large part) fair. Government violence is something absolutely different from person-violence (I don't know how "eigen rechter spelen" is called in English). > (I think it safe to say that during the 20th century, 99% of the 100s of > millions of murders were committed by armed govern-men rather than by > private persons acting alone.) That is probably true. But do you seriously think that the Dutch, Swiss, American or Japanese government can be compared with those of Hitler, Stalin, Pol Pot, Saddam Hussein, Kim Jong Il, etc.? Weapons in hands of idiots can cause dozens of deaths. Power in hands of idiots can cause millions of deaths. Does the latter mean the former isn't true? Gerrit (socialist). -- 168. If a man wish to put his son out of his house, and declare before the judge: "I want to put my son out," then the judge shall examine into his reasons. If the son be guilty of no great fault, for which he can be rightfully put out, the father shall not put him out. -- 1780 BC, Hammurabi, Code of Law -- Asperger Syndroom - een persoonlijke benadering: http://people.nl.linux.org/~gerrit/ Het zijn tijden om je zelf met politiek te bemoeien: http://www.sp.nl/ From newsgroups at jhrothjr.com Mon Aug 25 15:08:06 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Mon, 25 Aug 2003 15:08:06 -0400 Subject: Help embedding python References: Message-ID: "Zora Honey" wrote in message news:bidf9a$78v$1 at info4.fnal.gov... > My husband and I are writing a program that does a lot of math behind > the scenes (c++) with a gui front (python/Tkinter). We've decided that > we want the c++ to be the "driver", and so we want to embed the python. > We are not stupid people, and we've already searched this newsgroup > and the web at large for help, but we're having a heck of a time trying > to do this. > > We're using Python 2.2 and Mark Lutz' "Programming Python" as a guide. > Unfortunately, the code in there is a little out of date (loading > certain libraries), and we haven't been able to get any examples to work > (we even tried downloading the version he uses in the book, but it fails > on the build). > > So I'm wondering if someone out there has, or would be kind enough to > create, a very simple ("hello world" type) program with Makefile that > works under 2.2. > > I will be very grateful, as it is my job to do the graphics, so if I > can't get python working, I'll have to learn another language... I take it you've read the "Extending and Embedding the Python Interpreter" manual that's part of the distribution? Section 5 is about Embedding, and 5.5 is titled "Embedding the Python Interpreter in C++". HTH John Roth > > Thanks, > Zora > From jaybromley at hotmail.com Sat Aug 30 17:36:25 2003 From: jaybromley at hotmail.com (Jay Bromley) Date: 30 Aug 2003 14:36:25 -0700 Subject: Update to Python 2.3 on Red Hat Linux 9 References: <8242f4a7.0308282240.4c87f997@posting.google.com> <8242f4a7.0308291913.63bcc19b@posting.google.com> <7HV3b.2450$sl.138883@twister.austin.rr.com> Message-ID: <8242f4a7.0308301336.3974e1b2@posting.google.com> Rob Andrews wrote in message news:<7HV3b.2450 sl.138883 at twister.austin.rr.com>... > Aside from the fact that I haven't been using pygtk, your situation sounds > similar to one I've been trying to resolve in the occasional free moment > lately. I posted to c.l.p on 8-27 with the subject "homebrew 2.3 install on > RedHat9 not playing nice with Tkinter" and have not yet satisfactorily > resolved it. So if you have amazing success, by all means feel free to > share the details. > I saw that message, it's similar to my case, but I guess I got lucky. On my machine (a recently installed RedHat Linux 9) Tkinter didn't work with 2.2.2, but it works fine using the default build/install of 2.3. Strange. If you haven't seen it yet http://www.python.org/topics/tkinter/trouble.html might be helpful. I'm going to be looking at Setup.py and Modules/Setup also, so if I see anything interesting I'll post it. Regarding the problem I was having, libraries available to 2.2.2 aren't available to 2.3, I did some investigating and found a subdirectory of the directory where python is installed (usually /usr/lib or /usr/local/lib) called pkgconfig. This directory contains text files that apparently refer to python packages. Does anyone know where this directory comes from and where the files within are created? It seems this could be the missing piece to my library problem. Thanks and regards, Jay From __peter__ at web.de Mon Aug 18 13:24:09 2003 From: __peter__ at web.de (Peter Otten) Date: Mon, 18 Aug 2003 19:24:09 +0200 Subject: Python problem References: <3256252.1061220075@dbforums.com> Message-ID: WIWA wrote: > > I'm trying to write the following in python: > j=0 > > for i in range(len(datumlijst)+1): > if (datumlijst[i+1]!=datumlijst): > datum[j]=datumlijst > j=j+1 > print datum[:] > > it complains about the part: datumlijst[i+1]!=datumlijst > You are comparing a list with a list entry which is probably unintended. > datum[j]=datumlijst > > IndexError: list assignment index out of range > You seem to assume that a list grows automatically. That's not true in Python. Now here's my guess of your intentions: datumlijst = [1,1,2,2,3,4,5,5,5,5,6,3] datumlijst.sort() datum = [datumlijst[0]] for i in range(len(datumlijst)-1): # all list indexes start with 0 if datumlijst[i+1] != datumlijst[i]: # both indexed datum.append(datumlijst[i+1]) # note the append() print datum #no need for [:] There may still sit a bug in the above. The following should be a little more robust, e. g. no need to sort datumlijst, no extensive use of list indexes: from sets import Set datumlijst = [1,1,2,2,3,4,5,5,5,5,6,3] print list(Set(datumlijst)) This is Python 2.3 only, in 2.2 you can do it with a dictionary, using the keys only. Peter PS: I see you've already fallen in love with whitespace :-) From gafStopSpamData at ziplink.stopallspam.net Fri Aug 22 13:47:30 2003 From: gafStopSpamData at ziplink.stopallspam.net (Gary Feldman) Date: Fri, 22 Aug 2003 17:47:30 GMT Subject: Deficiency in urllib/socket for https? References: <6vaakvorefvifnt3fk59r6tcj16c59rrfi@4ax.com> <87r83dzr34.fsf@pobox.com> Message-ID: <1hlckvot3mr78up9o52uiutse4ofh1d2vq@4ax.com> On 22 Aug 2003 15:47:59 +0100, jjl at pobox.com (John J. Lee) wrote: Thanks for your extensive reply. All I can say is that any environment that silently does https interactions without verifying the certificate, and without loudly warning the user, is a security catastrophe waiting to happen. While I don't claim to be a web security expert, I've spent enough time dealing with such issues to know how critical this is, and how important it is to be take responsibility for such issues at all times. Even if it's just a clearly labelled warning in urlopen saying that it ignores https certification errors, which by definition defeats a primary purpose of https (it gets you encryption but no authentication). >That sounds great if you have the time to write the code. Nobody else >is likely to. I have the time at the moment (unfortunately). I'm still working on the Python expertise. Gary From alan.gauld at btinternet.com Mon Aug 18 15:45:36 2003 From: alan.gauld at btinternet.com (Alan Gauld) Date: Mon, 18 Aug 2003 19:45:36 GMT Subject: Python newbie help References: <87fa5cfa.0308181126.c61bfa2@posting.google.com> Message-ID: <3f412b85.351181492@news.blueyonder.co.uk> On 18 Aug 2003 12:26:14 -0700, stephen at hostwiththemost.net (s) wrote: > anyone aware of an online tutorial with examples that actually end up > creating a semi-useful program and not just snippets of code > displaying how the code functions? How useful it is depends on how seriously you need the data but my tutor ends up with a case study of a grammar counter. It starts out as a commandline tool (evolved from the word counter developed in an earlier chapter), takes it to an OO style and finally to a GUI form using Tkinter. Its not the last word in accuracy(!!) but is supposed to be representative of the kind of thing a newbie who has just finished the tutor could do for themselves... If you buy the paper book version you get a games framework example too which is developed into a hangman game, (and on the CD the code for a mastermind game using the same framework too). The framework and hangman code(with extra comments) are available on Useless Python... But whether you count that as useful I dunno. And its a chapter at the end rather than being developed as you go through the tutor (which is what you want I think?) Anyways, pay a visit if you think it would help. Just remember its aimed at complete beginnes to programming. Alan G. Author of the Learn to Program website http://www.freenetpages.co.uk/hp/alan.gauld From someone at somewhere.com Wed Aug 20 19:10:04 2003 From: someone at somewhere.com (reh) Date: Wed, 20 Aug 2003 23:10:04 GMT Subject: GUI IDE for Macintosh? References: <632a11-ks2.ln1@stargate.solsys.priv> Message-ID: Leo wrote: > > Qt is ported, but SIP seems to be the problem: according to > riverbankcomputing there is no SIP for mac. :-( > > that woud mean no luck... :-( > > or are there other other GUI builders? > > cheers, leo try google for "mac python gui" -- robert redhat 9.0 From aleax at aleax.it Mon Aug 4 08:20:25 2003 From: aleax at aleax.it (Alex Martelli) Date: Mon, 04 Aug 2003 12:20:25 GMT Subject: Changing base class of a big hierarchy References: <873cgjyo2u.fsf@pobox.com> <87oez5wrw3.fsf@pobox.com> Message-ID: John J. Lee wrote: > bokr at oz.net (Bengt Richter) writes: > >> On 03 Aug 2003 12:31:37 +0100, jjl at pobox.com (John J. Lee) wrote: >> >> >I'm trying to change a base class of a big class hierarchy. The >> >hierarchy in question is 4DOM (from PyXML). 4DOM has an FtNode class >> >that defines __getattr__ and __setattr__ that I need to override. >> > >> If FtNode lived in a separate module that was imported, could you >> import an impostor module which would override subsequent imports? > > That's a tempting idea, but is it possible (without a lot of work) to > do it *without* ending up with sys.modules containing my hacked > FtNode? I don't want my hacked class hierarchy to infect other > peoples code that innocently imports xml.dom. > > How would you go about it? Well, you could: -- import the original FtNode (say "import FtNode") -- save xxx = sys.modules['FtNode'] -- patch sys.modules['FtNode'] = yourhackedmodule -- do the deed -- restore sys.modules['FtNode'] = xxx Now lots of OTHER modules (imported during "do the deed") might be 'infected', but regarding sys.modules['FtNode'] specifically, you're safe. If you can identify the whole set of modules that need to be saved, temporarily removed, than restored in this way, the generalization should be easy. This may break down if any code you're using has 'import' statements in functions or methods, since said import statements will now access the restored modules when they execute after you've done the restoration, but most code imports only at module top-level, so this might work. I'd still prefer to work on the class hierarchies and keep the modules alone, due to this kind of issues and fragilities, but the module-based approach might also be workable. Alex From adalke at mindspring.com Mon Aug 18 21:58:42 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Mon, 18 Aug 2003 19:58:42 -0600 Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> <87fzjywpjs.fsf@pobox.com> Message-ID: John J. Lee > Greg Ewing has pointed out a similar trivial > wart: brackets and backslashes to get multiple-line statements are > superfluous in Python -- you could just as well have had: > > for thing in things: > some_incredibly_long_name_so_that_i_can_reach_the_end_of_this = > line > > where the indentation of 'line' indicates line continuation. Hmm. Start with for a in some, incredibly, long, list, so, it, hides, the, end,: qwerty_etaoin_shrdlu_glub_glub() g() Drop the colon one line and it would then be legal to write for a in some, incredibly, long, list, so, it, hides, the, end, qwerty_etaoin_shrdlu_glub_glub(): g() As it is now, you'll have to write for a in (some, incredibly, long, list, so, it, hides, the, end, qwerty_etaoin_shrdlu_glub_glub()): g() or perhaps the less recommended for a in some, incredibly, long, list, so, it, hides, the, end, \ qwerty_etaoin_shrdlu_glub_glub(): g() Both provide a little more clue that the expression goes on into the next line. Not really a counterpoint, just an observation. > the two languages are? If somebody sneakily switched Python and Ruby > in the middle of the night (so that suddenly many more people use > Ruby, and much more code was written in Ruby than in Python), you'd > stick with Ruby, wouldn't you? I was in a field, bioinformatics, dominated by Perl code. (It still is.) But I decided Python was better in various ways - easier to read, easier to build larger data structures, and easier for non-software developers (scientists) to use. A few years ago I looked at Ruby. I think my criteria for selecting Python over Perl is still true for Python over Ruby, in that it has too many special characters (like @ and the built-in regexpes), features (like continuations and code blocks) which are hard to explain well (I didn't understand continuations until the Houston IPC), and 'best practices' (like modifying base classes like strings and numbers) which aren't appropriate for large-scale software development. So the answer would likely still be yes. > I mostly agree, but I think you could be accused of spreading FUD > about this. Does anybody *really* choose to alter string-comparison > semantics under everybody else's nose in Ruby?? That would be like > doing Good question, since I repeated it above. In the into to Ruby docs (or the book?) it mentions that there are no functions in Ruby, only methods, and that when you wrote something which looks like a function it's really a private method of the base Object. Eg, it does change methods of the fundamental base class. (I took it to mean that Ruby's claim to be unrepentantly OO was overly strong.) I don't have any experience programming Ruby to know what people do for large projects. I will point out that the Ruby book in one of the first few chapters says: http://www.rubycentral.com/book/tut_classes.html > In Ruby, classes are never closed: you can always add > methods to an existing class. This applies to the classes > you write as well as the standard, built-in classes. All > you have to do is open up a class definition for an > existing class, and the new contents you specify will > be added to whatever's there. and later on http://www.rubycentral.com/book/ospace.html > You can add code to a running process. You can > redefine methods on the fly, change their scope from > public to private, and so on. You can even alter basic > types, such as Class and Object. > > Once you get used to this flexibility, it is hard to go > back to a static language such as C++, or even to > a half-static language such as Java. and I found a tutorial showing how to do the same thing http://www.math.hokudai.ac.jp/~gotoken/ruby/ruby-uguide/uguide14.html > In subclass, we get changing behavior of the instances > by redefine the superclass methods. (It appears this is a translation from a Japanese tutorial.) Both are in introductory material, and neither make a suggestion about its inappropriateness for anything other than debugging. > import some_module > > def evil_replacement_function(): return blah() > > some_module.important_function = evil_replacement_function > > > in Python, wouldn't it? And that is frowned upon, and as I recall there's some thought to preventing that in "Python 3.0" for performance reasons. Though I've needed to patch code that way. (It may be that I misheard too.) It isn't talked about in any of the introductory materials for Python that I recall reading. Andrew dalke at dalkescientific.com From jorolat at msn.com Fri Aug 1 13:09:49 2003 From: jorolat at msn.com (John Latter) Date: Fri, 01 Aug 2003 18:09:49 +0100 Subject: Problem with Unzipping/Installing Python-2.3.exe References: <1001ff04.0308010855.7b97c959@posting.google.com> Message-ID: On 1 Aug 2003 09:55:33 -0700, bobx at linuxmail.org (Bob) wrote: >You just double-click on the EXE file to start the installation. Hi Bob, The problem is during unzipping - I've never had a zipped file before asking to overwrite files even before its finished! -- John Latter Model of an Internal Evolutionary Mechanism (based on an extension to homeostasis) linking Stationary-Phase Mutations to the Baldwin Effect. http://members.aol.com/jorolat/TEM.html 'Where Darwin meets Lamarck?' Discussion Egroup http://groups.yahoo.com/group/evomech From martin at v.loewis.de Sat Aug 30 22:08:17 2003 From: martin at v.loewis.de (Martin v. =?iso-8859-15?q?L=F6wis?=) Date: 31 Aug 2003 04:08:17 +0200 Subject: Embedding / Extending Python 2.3 References: <2ed74bf047e70c3e852bd39b81081cdc@news.teranews.com> Message-ID: John Paquin writes: > Now, however, you have to explicitly check for them in the getattr callback. > > Is this what was intended? anyone know? It's not intended, and I cannot reproduce this problem. Did you call PyType_Ready? Regards, Martin From andreas at andreas-jung.com Thu Aug 7 07:45:05 2003 From: andreas at andreas-jung.com (Andreas Jung) Date: Thu, 07 Aug 2003 13:45:05 +0200 Subject: How to dectect UCS4 Python at runtime? In-Reply-To: References: Message-ID: <2147483647.1060263905@[192.168.0.100]> sys.maxunicode return 65535 for ucs-2, but 1114111 for ucs-4...maybe that's sufficent for you. Andreas --On Donnerstag, 7. August 2003 12:00 Uhr +0200 Daniel Dittmar wrote: > I'm trying to detect whether the Python currently running has been > compiled for UCS2 or UCS4. > > I need this because I'm distributing a C extension. I've choosen to pack > the binaries for all the Python versions into one download and then > decide at runtime which one to load. And with RedHat compiling Python for > UCS4, I'll have to do the same for the unicode variants. > > Daniel > > -- > Daniel Dittmar > SAP DB, SAP Labs Berlin > http://www.sapdb.org > > > > -- > http://mail.python.org/mailman/listinfo/python-list From gafStopSpamData at ziplink.stopallspam.net Wed Aug 13 21:08:10 2003 From: gafStopSpamData at ziplink.stopallspam.net (Gary Feldman) Date: Thu, 14 Aug 2003 01:08:10 GMT Subject: Py2.3: Feedback on Sets References: Message-ID: <1rnljv8527o2phdjup4e9uji0kssf93svt@4ax.com> On Thu, 14 Aug 2003 09:35:24 +1000, "Delaney, Timothy C (Timothy)" wrote: >"iterable" *is* . If something is "iterable" it has a well-defined interface - specifically: I get what you mean, but let me point out that "iterable" does not appear in the index of either the Language Reference or Library Reference, nor do I see it in the introduction. Actually, the introduction would really benefit from a description of all the conventions used in the manual. As it stands, one has to come across this usage several times to realize it's a convention (and that's not the way many people use reference manuals). What would be really cool, and probably easy, is to just make sure that every occurrence of "iterable" is a link to a page that describes that well-defined interface. This is still beyond the scope of the question about the Set documentation. I appreciate the responses, but I'm not sure whether this is the right time to continue this sort of discussion. Gary From claird at lairds.com Tue Aug 19 11:57:29 2003 From: claird at lairds.com (Cameron Laird) Date: Tue, 19 Aug 2003 15:57:29 -0000 Subject: python threads on multi-CPU machines References: Message-ID: In article , Paul McGuire wrote: . . . >I'm sorry if this is off-topic, and I am fairly new in this newsgroup, but I >know we were very eager to push multiCPU machines on our customers, and we >did not realize what risk we were taking on. . . . I'll respond on a largely emotional level: yes, multi-CPU hosts seem to be all about taking on risk. A LOT of things can go wrong (and in poorly reproducible ways, worst of all). -- Cameron Laird Business: http://www.Phaseit.net Personal: http://phaseit.net/claird/home.html From jjl at pobox.com Fri Aug 22 17:50:01 2003 From: jjl at pobox.com (John J. Lee) Date: 22 Aug 2003 22:50:01 +0100 Subject: Deficiency in urllib/socket for https? References: <6vaakvorefvifnt3fk59r6tcj16c59rrfi@4ax.com> <87r83dzr34.fsf@pobox.com> <1hlckvot3mr78up9o52uiutse4ofh1d2vq@4ax.com> <87fzjtpefg.fsf@pobox.com> Message-ID: <87bruhpdkm.fsf@pobox.com> jjl at pobox.com (John J. Lee) writes: [...] > Would you mind submitting a doc patch (both urllib and urllib2 docs > appear to need fixing -- urllib2 to say that it never verifies, urllib > to say that it skips verification if an appropriate x509 mapping isn't > supplied)? Hmm, maybe I've got this wrong: the fact that key/cert args are passed to httplib.HTTPS by urllib doesn't mean authentication happens, and the fact that they're not passed by urllib2 doesn't mean authentication doesn't happen. I'll investigate. John From max at nospam.com Mon Aug 4 13:57:17 2003 From: max at nospam.com (max) Date: Mon, 04 Aug 2003 17:57:17 GMT Subject: packaging windows services? In-Reply-To: References: Message-ID: <18xXa.94652$852.21935@twister.nyc.rr.com> > No need to use cvs, just download the patch and use a patch.exe utility > for windows ;-) Search the internet to find one, and find out how to use > it. got that, now I am getting 'unexpected end of hunk on line 31'. any chance you could just shoot the source file to max _AT_ cvisiontech dotcom? thanks, max. From dtolton at yahoo.com Wed Aug 13 03:06:34 2003 From: dtolton at yahoo.com (Doug Tolton) Date: Wed, 13 Aug 2003 07:06:34 GMT Subject: Is Python your only programming language? References: Message-ID: On Wed, 13 Aug 2003 02:48:16 -0400, mertz at gnosis.cx (David Mertz) wrote: >|I want to ask you hard-core c.l.p Pythonistas: Do you use Python for >|everything? (and I'm counting Python + C extensions as just Python) > >I think the co-author of (parts of) my Gnosis Utilities package, Frank >McIngvale won't mind if I share this recent brief exchange with y'all. >On my OS/2 machine, the case of some files in the distribution were >getting messed up, so I wrote a little script to fix things up before >packaging: > > DM> OK... but it's REXX. On the plus side, this will make sure all > DM> the files are right, not just those I remember to check. > > FM> You'll have to excuse me for cracking up that the author > FM> of Text Processing in Python just sent me a REXX script!! :-) > FM> Hm, lemme crack open my book and see if I can figure out > FM> how to rewrite it in this newfangled braceless python thang ;-) > >FWIW. (still, REXX is quite braceless). > >Yours, David... > >X-Shameless-Plug: Buy Text Processing in Python: http://tinyurl.com/jskh David, I have your book on my Desk now, and I've worked though some of it. Good stuff so far. Kudos. I posted a reply to you on slashdot about this book too, but I don't think you saw it. Doug Tolton From brian at sweetapp.com Fri Aug 1 14:06:09 2003 From: brian at sweetapp.com (Brian Quinlan) Date: Fri, 01 Aug 2003 11:06:09 -0700 Subject: Python's biggest compromises In-Reply-To: <1059754750.27514.11.camel@lothlorien> Message-ID: <002901c35857$95ef8fd0$21795418@dell1700> > Reference counting spreads the speed hit over the entire program, while > other techniques tend to hit performance hard every so often. But all > together I think reference counting is usually slower than a good GC > algorithm, and incremental garbage collection algorithms can avoid > stalling. And I'm sure that the current state -- references counting > plus another kind of garbage collection for circular references -- must > be worse than either alone. I'm not sure that I believe this. In Python, everything is an object that participates in GC including integers and other light-weight types. Imagine that you have a mathematic expression that creates a dozen floats objects as part of its evaluation. Do you believe that it is faster to add those dozen floats to a list for later collection than to decrement an integer, notice that the decremented value is 0 and immediately reclaim the memory? That would not be my intuition (but my intuition is often wrong :-)). Cheers, Brian From rimbalaya at yahoo.com Wed Aug 6 10:31:09 2003 From: rimbalaya at yahoo.com (Rim) Date: 6 Aug 2003 07:31:09 -0700 Subject: where are docutils tools installed? Message-ID: <6f03c4a5.0308060631.7409f7b1@posting.google.com> Hi, I've installed the latest docutils, but I can't find where the tools have been installed. I can see them when I expand the tarball, but I can't find them under site-packages. Thanks -Rim From duncan at NOSPAMrcp.co.uk Tue Aug 19 11:12:21 2003 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Tue, 19 Aug 2003 15:12:21 +0000 (UTC) Subject: An advertising message from a Microsoft agent References: <3F403078.3010006@sympatico.ca> Message-ID: Nick Vargish wrote in news:m33cfxzpcz.fsf at tanelorn.bandersnatch.org: >> microsoft.ca/vs2003launch Experience a more productive toolset - > > At first I thought it read "Experience a more productive toilet", > which is probably just as inaccurate, but more appropriate. That would be the Microsoft iLoo? See http://www.cbsnews.com/stories/2003/05/13/tech/main553567.shtml or many other confused news reports. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From mfranklin1 at gatwick.westerngeco.slb.com Thu Aug 14 11:33:17 2003 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Thu, 14 Aug 2003 16:33:17 +0100 Subject: Python/Tkinter/tk crash [long] In-Reply-To: References: Message-ID: <200308141633.17678.mfranklin1@gatwick.westerngeco.slb.com> On Thursday 14 August 2003 10:10 am, Eric Brunel wrote: > Hi all, > > I was creating a Tkinter widget in the style of the reversed tabs below > Excel worksheets and I stepped in a serious problem: the code I made makes > python crash with a seg fault, bus error or X11 BadGC error on both Solaris > (2.6 and 2.7) and Linux (Mandrake 8.0); it doesn't crash on Windows. I > tried to simplify the script, but I couldn't reproduce the crash with a > simpler code. So the code below is somewhat long; sorry for that. > > To make it crash, just run the script and click on a tab. It usually > crashes at the first click, but you may have to play a bit with the tabs. I > tried to run Python through gdb to see where the crash happens, but it > seems to be quite random. Maybe a memory corruption? > > There's a simple workaround, but with drawbacks: at the beginning of the > __update method, if I do not destroy and re-create the Canvas, but simply > empty its contents, the script works. But it keeps the commands declared > created at the tcl level for the former bindings, so it silently eats up > memory. > does it still eat up memory if you, for example, change the top of the __update method to: def __update(self): if not self.__tabsCanvas: self.__tabsCanvas = Canvas(self, bg=self.cget('background'), height=self.__canvasHeight) self.__tabsCanvas.grid(row=0, column=0, sticky='nswe') self.__tabsCanvas.delete("all") Martin From FBatista at uniFON.com.ar Wed Aug 20 12:30:03 2003 From: FBatista at uniFON.com.ar (Batista, Facundo) Date: Wed, 20 Aug 2003 13:30:03 -0300 Subject: python quickie : retrace function steps? Message-ID: You need the inspect module: http://www.python.org/doc/current/lib/module-inspect.html . Facundo #- -----Mensaje original----- #- De: s0199583 at sms.ed.ac.uk [mailto:s0199583 at sms.ed.ac.uk] #- Enviado el: Mi?rcoles 20 de Agosto de 2003 1:20 PM #- Para: python-list at python.org #- Asunto: python quickie : retrace function steps? #- #- #- hi all, #- #- If I was to make a function call another function, and from that #- function, call another function (so that now I was in a 3rd function) #- something like this: #- #- (function 1) #- |________(function 2) #- |________(function 3) #- #- Is there away I can print out the path my Program had taken #- (i want to #- do this as part of my error checking, so a user would always know the #- path my program took)? #- #- i.e. printted output of error would be: #- #- error with function 3 #- function 3 called from function 2 #- function 2 called from function 1 #- #- In perl there is a function called CALLER, which I have used to the #- same effect, i was wondering if python had something similar #- for this? #- #- cheers in advance, #- matt #- -- #- http://mail.python.org/mailman/listinfo/python-list #- From trentm at ActiveState.com Mon Aug 11 19:45:17 2003 From: trentm at ActiveState.com (Trent Mick) Date: Mon, 11 Aug 2003 16:45:17 -0700 Subject: Finding the path to a file In-Reply-To: <20030811231134.19113.qmail@web41205.mail.yahoo.com>; from overdrive_ss@yahoo.com on Mon, Aug 11, 2003 at 04:11:34PM -0700 References: <20030811231134.19113.qmail@web41205.mail.yahoo.com> Message-ID: <20030811164517.B5568@ActiveState.com> [Todd Johnson wrote] > So basically, I want to know how to find the directory > my script is in, even when it is invoked from another > directory. Any help would be greatly appreciated. The __file__ global is there for that. Note that in some versions of Python (<= 2.2 maybe) __file__ was not defined with __name__=="__main__". If you are running one of these versions of Python then add this snippet in your module: if __name__ == "__main__": import sys __file__ = sys.argv[0] # __file__ is now the fullpath to your script Cheers, Trent -- Trent Mick TrentM at ActiveState.com From logiplex at qwest.net Mon Aug 25 18:35:11 2003 From: logiplex at qwest.net (Cliff Wells) Date: Mon, 25 Aug 2003 15:35:11 -0700 Subject: python gripes survey In-Reply-To: <78kkkvg8ckfio141es2of1p483ohbtbit5@4ax.com> References: <78kkkvg8ckfio141es2of1p483ohbtbit5@4ax.com> Message-ID: <1061850911.1506.467.camel@software1.logiplex.internal> On Mon, 2003-08-25 at 11:14, Afanasiy wrote: > I have a bunch, many of them hard to define, but one that I just thought > of I find strange sometimes is the use of tuples as near-mystery return > values. I can't help but thinking a C struct with named fields is easier > to remember than a tuple with fields accessed by integer. As someone else mentioned, you don't have to access them via an integer, but your point is still taken. The return value of time.localtime() method is a fine example of a mystery tuple. Fortunately it offers attribute access as well. > Sure you can return an associative array, but in my experience the > preference is to return a tuple. I'll probably get flamed for saying so, > but this is how I feel and it is unavoidable. Returning a struct in C is > easier to deal with than returning a near-mystery tuple in Python. This isn't so much a problem with Python as the programmers using it nor do I see it as particularly "unavoidable". If you're returning only a few (preferably homogenous) items, a tuple makes sense: x, y, z = getpoint() More complex return values should probably be in a class instance (which would seem to be equivalent to returning a C struct in this case): t = time.localtime(time.time()) print t.tm_hour, t.tm_min, t.tm_sec makes better sense than: year, month, mday, hour, min, sec, wday, yday, isdst = time.localtime(time.time()) Regards, -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 (800) 735-0555 From oussoren at cistron.nl Wed Aug 27 02:30:37 2003 From: oussoren at cistron.nl (Ronald Oussoren) Date: Wed, 27 Aug 2003 08:30:37 +0200 Subject: bool and unicode In-Reply-To: <91BFE89EFFA2904E9A4C3ACB4E5F2DF502062C@exchange.adrembi.com> References: <91BFE89EFFA2904E9A4C3ACB4E5F2DF502062C@exchange.adrembi.com> Message-ID: On Tuesday, 26 August 2003, at 8:16, Roman Yakovenko wrote: > Hi. > >>>> bool( u'True' ) > True >>>> bool( u'False' ) > True >>>> > > May somebody explain or give a reference to reason of such behaviour? That has nothing to do with unicode, bool('False') is also True. help(bool) says: Returns True when the argument x is true, False otherwise. That is, x = bool(y) is the same as: if y: x = True else: x = False Ronald From mauricio.inforcati at cenpra.gov.br Mon Aug 11 09:26:51 2003 From: mauricio.inforcati at cenpra.gov.br (=?iso-8859-1?Q?Mauricio_Caliggiuri_Infor=E7ati?=) Date: Mon, 11 Aug 2003 10:26:51 -0300 Subject: Problems py22 -> py23 Message-ID: <000e01c3600c$39b62be0$237290c8@ITABIRITO> Hi, I am trying to run my project, writed with py22, on my new installed py23. This is occuring: Traceback (most recent call last): File "python\menu.py", line 1611, in ? MenuPro(root) File "python\menu.py", line 281, in __init__ menuBar1.addmenuitem('Ajuda', 'command' , 'Creditos' , label = 'Threshold 2D ')#, command = lambda e = self , x ='copyrightVTK.html' : e.showbrowser(x)) File "C:\PYTHON23\lib\site-packages\Pmw\Pmw_1_2\lib\PmwMenuBar.py", line 155, in addmenuitem self._addHotkeyToOptions(menuName, kw, 'label', traverseSpec) File "C:\PYTHON23\lib\site-packages\Pmw\Pmw_1_2\lib\PmwMenuBar.py", line 204, in _addHotkeyToOptions label = str(menu.entrycget(item, textKey)) UnicodeEncodeError: 'ascii' codec can't encode characters in position 9-10: ordi nal not in range(128) Fatal Python error: PyEval_RestoreThread: NULL tstate abnormal program termination What must I do? Mauricio Inforcati -------------- next part -------------- An HTML attachment was scrubbed... URL: From mack at incise.org Sun Aug 24 23:18:26 2003 From: mack at incise.org (mackstann) Date: Sun, 24 Aug 2003 22:18:26 -0500 Subject: Simple Dictionary Problem In-Reply-To: References: Message-ID: <20030825031826.GS1695@incise.org> On Sun, Aug 24, 2003 at 08:06:56PM -0700, Kris Caselden wrote: > I'm still new to some of Python's finer details, so this problem is > probably an easy fix. I can't seem to loop through a dictionary whose > values are tuples. > > For instance: > > oldlist = {'name':(1,2,3)} > newlist = [] > for x1,x2 in oldlist: > for y1 in x2: > newlist.append(str(x1)+str(y1)) > print newlist > > Gives me: > > line 3, in ? > for x1,x2 in oldlist: > ValueError: too many values to unpack > > The docs I've read mention problems where the key is immutable, but > don't say anything about what data-types are acceptable for the value. > What am I missing? When you iterate through a dictionary, you get the keys. e.g.: >>> for x,y in {"hi":4}: ... print x, y ... h i >>> for x in {"hi":4}: ... print x ... hi So I think what you want to do is: >>> oldlist = {'name':(1,2,3)} >>> newlist = [] >>> for x1,x2 in oldlist.items(): # note .items() ... for y1 in x2: ... newlist.append(str(x1)+str(y1)) ... >>> print newlist ['name1', 'name2', 'name3'] Take a look at dict.keys(), dict.values(), and dict.items() (and the iter- variations: iterkeys, itervalues, iteritems) for varying ways to loop through a dict. -- m a c k s t a n n mack @ incise.org http://incise.org Real Programs don't use shared text. Otherwise, how can they use functions for scratch space after they are finished calling them? From siegfried.gonzi at kfunigraz.ac.at Mon Aug 4 05:14:26 2003 From: siegfried.gonzi at kfunigraz.ac.at (Siegfried Gonzi) Date: 4 Aug 2003 09:14:26 GMT Subject: Python speed vs csharp References: <1h5f2rzthqgid.8watonaa4cjt.dlg@40tude.net> <3F551D29.1040407@kfunigraz.ac.at> <0MoXa.21930$cl3.850221@news2.tin.it> Message-ID: <3F55B1CE.5010607@kfunigraz.ac.at> Alex Martelli wrote: > Still, the performance ratio of psyco-optimized Python vs C on my > machine is much better than that of bigloo vs C on Mr Gonzi's Celeron, > and with no need for type declarations either. So much, then, for > Mr Gonzi's claims about Python being "more or less crap"!-) Oh man. I forget to tell if you comment out (x (exact->inexact x)) the Bigloo version calculates things in 0.25 seconds (as compared to 0.5 seconds of the C version). Okay, a lot of people have learned a lot from your post. Maybe they can use some techniques for their own Python programming. But still Python is crap. Sorry to tell you the truth. It is not only speed. Look if I do not use types in Bigloo it is 10 times slower than C. So performance is not everything; at least for me. But Mr. Martelli your post was very funny. It is always a pleasure for me to make loosers upset (yes I know your contribution to Python is huge especially because you are book author). Oh, man I always thought such individuals are just in the CommonLisp community. If you are pragamatic Python is okay and has a lot to offer. S. Gonzi From phil at riverbankcomputing.co.uk Mon Aug 18 11:52:26 2003 From: phil at riverbankcomputing.co.uk (Phil Thompson) Date: Mon, 18 Aug 2003 16:52:26 +0100 Subject: advice choosing IDE In-Reply-To: References: Message-ID: <200308181652.26942.phil@riverbankcomputing.co.uk> On Monday 18 August 2003 4:22 pm, Michael Peuser wrote: > "Michael Peuser" schrieb im Newsbeitrag > news:bhqo8a$ggs$06$1 at news.t-online.com... > > > My apologies! I was of course refering to the Trolltech QT Builder which > > is > > > a fine product but no integrated Python tool. I have heard of "eric" but > > never used it.... I certainly will! > > Nevertheless it is no simple task to install it on a Windows machine: > There seems to be just a source code version of QScintilla (what you need > in addition to Qt and PyQt). To run eric on Windows you need the commercial or educational versions of Qt and PyQt (because QScintilla requires Qt v3). > This seems nothing for a newbie to start, looking for his first IDE...... The original poster was looking for a Linux solution (I think). > Similar problems (on Windows) happen with GTK related products. This a > total mess. We poor and simple minded WIndows usesr expect something > working just out of the box ;-) Phil From jjl at pobox.com Sat Aug 2 09:56:13 2003 From: jjl at pobox.com (John J. Lee) Date: 02 Aug 2003 14:56:13 +0100 Subject: Python Windows 2.3 Installer problems References: Message-ID: <87wudwxiwy.fsf@pobox.com> Timothy Martens writes: > When I run the Python-2.3.exe on my WIN2K box and go through the > initial dialogues, the installer frezes at 1% when it's "Copying File > C:\Python23\UNWISE.exe" > > Any ideas ANYONE? Actually, thinking about it, *don't* report a bug on SF until you've checked any antivirus software (and the other stuff Christopher mentioned, I guess). John From dave at 3dex.com Thu Aug 14 14:38:29 2003 From: dave at 3dex.com (Dave Benjamin) Date: Thu, 14 Aug 2003 18:38:29 GMT Subject: 3 new slogans References: Message-ID: 3 more slogans: 1. Python: Taste programming again for the first time. (apologies to Kellog) 2. If the implementation is easy to explain, it may be Python. <3.1415 wink> 3. Python: Rehab for the semicolon. Dave From newsgroups at jhrothjr.com Fri Aug 1 06:38:23 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Fri, 1 Aug 2003 06:38:23 -0400 Subject: How to run Python script on WindowXP References: Message-ID: How to run Python script on WindowXPFunny, I works for me. There are two parts to the solution. First, check if the Python library is in your path. If it isn't, you'll get an error that says something like "not an executable or script." Go to Control Panel -> System -> Advanced -> Environment Variables, and you'll be able to set the path properly. Outside of that, your command needs to be: "python .py " (without the quotes, obviously.) For example: python froznitz.py foobar galoshes I find that a command file (.cmd) to set the python path first helps. Python, for some reason, does not assume the .py, you have to specify it. John Roth [original post] "Yunxian Mak" wrote in message news:mailman.1059704283.30356.python-list at python.org... Dear Sir/Madam, I'm doing my PhD in APAF and I installed Python 2.2 interpreter in WindowNT before and it worked OK on my old computer. However, our company has upgraded the systems to WindowXP recently. I installed Python2.2.3, which includes IDLE (Python GUI), Module Docs, Python (command line) and Python Manuals, on my new computer. I can open my Python code from IDLE (Python GUI), but I don't know how to run it. If you could please tell me whether the Python interpreter compatible to WindowXP and how to run the Python script on WindowXP, I'll be much appreciated. Thank you very much again. Best regards, Yunxian Mak From frank at pc-nett.no Tue Aug 19 07:01:11 2003 From: frank at pc-nett.no (frank) Date: Tue, 19 Aug 2003 13:01:11 +0200 Subject: ANN: soprano 0.003 Message-ID: Soprano is a GUI app that scans a selected range of ip addresses and try to get info about the hosts such as users, localgroups, shares, operating system. This program only runs under windows enviorment. changes 0.002 > 0.003:. added settings window setting are saved in xml and are stored under data\setting.xml setting include: "logon as" with username and password or use null request resolv hostname shares users groups info portscanner improved right click menu\submenu new functions: add user add group add share send msg (NetMessageBufferSend) Source code and windows binary at http://sourceforge.net/projects/soprano/ From ialbert at mailblocks.com Sat Aug 16 13:18:56 2003 From: ialbert at mailblocks.com (Istvan Albert) Date: Sat, 16 Aug 2003 13:18:56 -0400 Subject: Recommendation of a parser generator (fwd) In-Reply-To: References: Message-ID: David Mertz wrote: > But if you feel like buying the dead-trees version, use the link below > to give me a few extra dollars: You should authograph the books bought from you. I was disappointed that you didn't. Istvan. From darnold4 at cox.net Wed Aug 27 11:31:02 2003 From: darnold4 at cox.net (David Raleigh Arnold) Date: Wed, 27 Aug 2003 11:31:02 -0400 Subject: sed with python Message-ID: How do I use python as a wrapper for sed and/or gawk scripts? I have been using bash for my stuff, which relates mostly to lilypond, and I wouldn't mind if windows users could find it more accessible. I have written one very simple python script and that's all. O'Reilly's python books don't mention sed or gawk. Thanks in advance. DaveA -- "We have learned the lessons of Viet Nam." --anon Spokesman "Failure is not an option." --anon Spokesman Can both be true? n Are both false? y Right answers get my vote. D. Raleigh Arnold dra@ http://www.openguitar.com darnold4 at cox.net From lists at zara.6.isreserved.com Thu Aug 21 07:52:03 2003 From: lists at zara.6.isreserved.com (David Garamond) Date: Thu, 21 Aug 2003 18:52:03 +0700 Subject: What's TOTALLY COMPELLING about Ruby over Python? In-Reply-To: <240b1020.0308201722.d1b991c@posting.google.com> References: <240b1020.0308201722.d1b991c@posting.google.com> Message-ID: <3F44B263.5080600@zara.6.isreserved.com> Jeffrey P Shell wrote: > Ruby is still more closely related to Perl than it is to Python. I think for many people, it all boils down to this. Whoever hates Perl will find Python more interesting. Whoever loves Perl, or uses/has used Perl, will find Ruby more welcoming. I for one am a Perl programmer. I have tried to use Python as much as I could for several months but just could not get as productive as I am in Perl. Hell, I could not even put 'if ... else ...' on the same f*cking line! :) > Ruby > uses all of those shortcut expressions that I find terrible, like $_. Ruby _does_ try hard to be a better Perl. This includes providing $_ and many other Perl stuffs. However, the more I use Ruby over time, the less I use those. What I like about Ruby is that, despite it brings many features from Perl, it still manages to be pretty clean design-wise. The features are often layered on top of the OO system (e.g: /.../ is a shortcut for creating a Regexp object). And they are all optional to use. Surely one is not forced to use it. But I understand that there are people who just can't stand the fact that those features _exist_ in the language. > Ruby uses other punctuation marks to mark what different variables, > with name, $name, @name, and @@name all being different. While it's > nice to differentiate between local, global, instance, and class > variables, all of these extra punctuation 'shortcuts' get in the way > of readability. Ah, but this improves readability for me. Some people might also argue that all those underscores in Python code reduces readability. And how many threads are lost for people complaining about having to write 'self.foo' all the time? ;-) > Ruby still has too much shell-script nature inside of it. Yes. And I love it :) > in Ruby expression type is command expansion, or `foo`, where foo is a > shell command. (You can also use %x, as in %x{echo "Hello There"}). > Putting `uname -v` in your code will execute the Unix 'uname' command. > The exit status of the command is in the cheerful global variable $?. > As a result, I wonder how well Ruby works as an embedded language. Not very badly, I think. mod_ruby, eruby, pl-ruby, jruby, ... Though the last one is nowhere near usable as Jython right now. > (NameSpace::Example::CONST or NameSpace::Example.new). Man, the more > I write, the more I really appreciate the simplicity of Python. We > will do funny things with __underscores__, but even that's pretty > consistent. And what's not consistent about :: for namespace separator, $ for global vars, @ for class vars, and so on? > Python also has the nice feature of compiling/caching modules, which > can speed things up. I don't know if Ruby re-evaluates all code every > time you start a Ruby program up, but I haven't really seen an > equivalent to Python's '.pyc' and '.pyo' (optimized, generated when > running with the -O option in Python) files. This is a purely implementation issue, not the issue with the language itself. Currently Ruby does not have a VM yet, so it does not have bytecode compilation. But it will in Ruby 2.0. The current implementation of Ruby (Ruby 1.x) is admittedly not very fast, but it's already much faster & efficient than Python for some things (like creating and destroying objects/classes). > Ruby does have some nice things going for it, and I think that people > looking for a good object oriented Perl would be happy with it. > Personally, I think that Python is more mature, has better design > influences (Modula and ABC instead of Perl and Smalltalk). Ruby is also largely influenced by LISP. > def mult(n, fact) > n * fact > end > > the last statement in an expression is what's returned. You *can* use > a return statement. But it's nice that Python always requires it This is also one of the thing I hate in Python :) -- dave From guettler at thomas-guettler.de Mon Aug 18 08:10:55 2003 From: guettler at thomas-guettler.de (Thomas =?ISO-8859-15?Q?G=FCttler?=) Date: Mon, 18 Aug 2003 14:10:55 +0200 Subject: advice choosing IDE References: Message-ID: Lupe wrote: > I'm convinced to try Python! > > I've read many posts, and although I recently bought a book on C to start > learning it, I'd like to give Python a good chance. > > What IDE would you recommend for someone who needs easiness of use with a > background of Pascal and VB for MS Office? I've definitely changed to > Linux now and I would like a free IDE either for procedural or object > oriented programming. Hi Lupe, I use xemacs daily. It is only a text editor, but you can use it for every programming language. thomas From ialbert at mailblocks.com Sun Aug 10 22:30:20 2003 From: ialbert at mailblocks.com (Istvan Albert) Date: Sun, 10 Aug 2003 22:30:20 -0400 Subject: Python vs. C# In-Reply-To: <3f36af20@shknews01> References: <2259b0e2.0308100616.55b651ca@posting.google.com> <3f36af20@shknews01> Message-ID: Brandon J. Van Every wrote: > For instance, Perl has become popular because > it's overwhelmingly useful for sysadmin and web admin. But I am not seeing > Python's overwhelming utility compared to other languages. You can do apps, > you can do web admin, but most people are doing Java, C#, or Perl. And > unlike C++ they aren't bad languages, so Python is not offering an obvious > "slam dunk" remedy. As far as I'm concerned it does not have to be "slam dunk". Just a little better is enough, that goes a long way and adds up quickly in larger projects. That's why people use python, it is not a conspiracy nor a brainwashing that made it popular. For many tasks it works better than anything else out there. > I'm beginning to think that within 5 years, no new applications > will be written in C++. Most people get paid for what they get done today. Not in five years. So I wouldn't lose sleep yet. C# was created to counteract Java. Unlike Python it would die quickly if it weren't for the marketing muscle of Microsoft. So claiming as the holy grail seems a bit of a joke. Istvan. From adalke at mindspring.com Tue Aug 19 19:10:22 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Tue, 19 Aug 2003 23:10:22 GMT Subject: What's better about Ruby than Python? References: Message-ID: Alexander Schmolck, responding to me: > > from Q import X > > > > class X: > > def amethod(self): return 'ah, now THIS is better!' > > > > Should it refine the X in the local namespace or make a new > > class? > > I'd say redefine X in the local namespace. Have you spotted a problem with it? I'm thinking about problems like this # module a.py class X: def a(self): print "qwerty" # module b.py from a import X def redo(): global X class X: def a(self): print "asdfg" # interactively from b import X, redo x = X() redo() print x.a() print X().a() Does the interactive loading of X get a copy of b.X, which is a copy of a.X? Because of the 'global X', will the redefinition of X in redo() change the module definition? What's the output from the print statements? In short, it would be the only thing in Python which rebinds a local variable in-place, and I don't have good feelings about the consequences. Andrew dalke at dalkescientific.com From tundra at tundraware.com Wed Aug 6 23:00:19 2003 From: tundra at tundraware.com (Tim Daneliuk) Date: 07 Aug 2003 03:00:19 GMT Subject: Win32All Crashes Python 2.3? In-Reply-To: References: Message-ID: Tim Daneliuk wrote: > Now the problem - twander has worked fine with previous versions of > Python/Win32All up to and including 2.2.x. It also works fine > with 2.3. HOWEVER, if I install any of the 2.3 relevant versions > of Win32All, when I change to a new directory, Python crashes. This turned out to the bug (in Python) identified elsewhere in this thread. Mark Hammond kindly sent me a patched DLL (which I presume will appear in 2.3.1) and I have verified that it does indeed fix the 'twander' hiccup noted originally. For those running 'twander' who wish to upgrade to Python 2.3 as released, please contact me privately via email for a workaround... Many thanks to Mark for jumping all over this problem so quickly! ---------------------------------------------------------------------------- Tim Daneliuk tundra at tundraware.com PGP Key: http://www.tundraware.com/PGP/ From aleax at aleax.it Fri Aug 29 10:48:40 2003 From: aleax at aleax.it (Alex Martelli) Date: Fri, 29 Aug 2003 14:48:40 GMT Subject: Style question... References: <3F4DFAAC.1356C276@engcorp.com> Message-ID: Steve Lamb wrote: > On 2003-08-28, rzed wrote: >> A better solution might be to physically restrain the posters of >> tab-infested code from doing that, but there are only so many hours in >> the day. And if OE wouldn't do what it does ... but then, where would >> be the fund in that? > > Well, actually, a better solution would be to skip OE for something > sensible, no? :) OE is far from the only news user-agent that doesn't display tabs the way you might like -- KDE's KNode has similar issues, for example. Alex From tjreedy at udel.edu Sat Aug 30 19:41:45 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 30 Aug 2003 19:41:45 -0400 Subject: confirm unsubscribe from zsh-users@sunsite.dk References: Message-ID: wrote in message news:mailman.1062283998.26328.python-list at python.org... > Hi! This is the ezmlm program. I'm managing the Hi, exmlm > zsh-users at sunsite.dk mailing list. > > To confirm that you would like > > python-list at python.org > > removed from the zsh-users mailing list, please send an empty reply > to this address: > > zsh-users-uc.1062283803.okifnhokaldgjdaajooj-python-list=python.org at su nsite.dk > > Usually, this happens when you just hit the "reply" button. > If this does not work, simply copy the address and paste it into > the "To:" field of a new message. > > I haven't checked whether your address is currently on the mailing list. Then you are a pretty dumb program. I bet it is not. You should know that any 'user' called xxx-list is another mailing list and that any attempt to subscript or unsubscript such is a casual or malicious joke (possibly from viruses, as probably with this case). What would you do if I forged an email trying to subscribe/unsubscribe zsh-users to/from itself? Would you send a messege asking it to reply? Tempted programmer PS. Anyone know what mailman would do? From blunck at gst.com Tue Aug 19 09:19:21 2003 From: blunck at gst.com (Christopher Blunck) Date: Tue, 19 Aug 2003 09:19:21 -0400 Subject: Pmw.Group font References: Message-ID: On Tue, 19 Aug 2003 09:52:20 +0200, Eric Brunel wrote: > Christopher Blunck wrote: >> Is it possible to set the font of the tag_text within a Pmw.Group? I have >> set the font on my Labels within the interior of the Group, and the label >> font of the Group looks pretty lame. > > Unless you changed the type for the "tag" component, an option tag_font should > work: a tag is by default a Tkinter.Label (as said in the Pmw.Group doc); a > Tkinter.Label accepts a "font" option; therefore, a Pmw.Group accepts a > "tag_font" option. It's as simple as that... Thanks for the explanation, Eric. It worked perfectly. Surprising that my Python and Tkinter book did not point this out in a more obvious way. -c From pobrien at orbtech.com Thu Aug 28 21:16:27 2003 From: pobrien at orbtech.com (Patrick K. O'Brien) Date: 28 Aug 2003 20:16:27 -0500 Subject: Object Database (ODBMS) for Python References: <1DAECE9E8F34E04AA0E5699AF7D9FF090708D440@stpmsg00.corp.fairisaac.com> Message-ID: pobrien at orbtech.com (Patrick K. O'Brien) writes: > I hope that helps demonstrate some of what it can do. I forgot to show a cool feature: >>> t = tx.Delete(u1) >>> db.execute(t) Traceback (most recent call last): File "", line 1, in ? File "/home/pobrien/Code/pypersyst/database.py", line 27, in execute return self._engine.execute(transaction) File "/home/pobrien/Code/pypersyst/engine/engine.py", line 75, in execute return transaction.execute(self._root) File "/home/pobrien/Code/pypersyst/entity/transaction.py", line 49, in execute return root[self.classname]._delete(self.oid) File "/home/pobrien/Code/pypersyst/entity/extent.py", line 204, in _delete raise error.DeleteRestricted, 'instance is referenced elsewhere' DeleteRestricted: instance is referenced elsewhere >>> What's that? You don't recall seeing referential integrity rules defined in the schema, or in the application code? That's right, you didn't. Curious? -- Patrick K. O'Brien Orbtech http://www.orbtech.com/web/pobrien ----------------------------------------------- "Your source for Python programming expertise." ----------------------------------------------- From skip at pobox.com Mon Aug 25 16:49:23 2003 From: skip at pobox.com (Skip Montanaro) Date: Mon, 25 Aug 2003 15:49:23 -0500 Subject: python gripes survey In-Reply-To: References: Message-ID: <16202.30291.141373.395805@montanaro.dyndns.org> josh> And arguably easier to deal with than Python in that the fields josh> are named. I think that's all Afanasiy was getting at. Yeah, that was my impression as well. Note that there is a "super tuple" type used in some places in the Python C code which allows both positional and attribute access to fields: >>> import time >>> t = time.localtime() >>> t (2003, 8, 25, 15, 45, 46, 0, 237, 1) >>> t.tm_year 2003 >>> type(t) I don't know if the in-memory storage is more like a tuple or more like a dict. Exposing something like this to the Python programmer was suggested a few years ago. I don't recall why it wasn't adopted, though any obvious reason might be that it's fairly easy to create container classes for that purpose. Skip From google at hanger.snowbird.net Thu Aug 21 03:39:27 2003 From: google at hanger.snowbird.net (Kris Caselden) Date: 21 Aug 2003 00:39:27 -0700 Subject: Scope of InteractiveInterpreter? Message-ID: I'm using the InteractiveInterpreter to run some source, but the data generated doesn't seem to be available in the scope of the parent. For instance, I tried lines = infile.open('data.py','r').readlines() ii = InteractiveInterpreter({'__name__': '__main__', '__doc__': None}) for line in lines: ii.runsource(line) but the data objects in data.py don't seem to exist when I try and manipulate them later in the script. Is what I'm trying to do possible? Am I on the right track? From camelo at esss.com.br Wed Aug 27 12:43:00 2003 From: camelo at esss.com.br (Marcelo A. Camelo) Date: Wed, 27 Aug 2003 13:43:00 -0300 Subject: Python memory management In-Reply-To: <200308271250.h7RCoLx03684@apollo.garlandisd.net> Message-ID: <000001c36cba$47056a80$0d00000a@esss.com.br> Hi! I will be presenting Python to an audience of game developers, mostly C/C++ programmers. In my presentation I will talk about using python and C/C++ extension instead of pure C/C++ to write commercial games and content creation tools. In a number of times I have presented these ideas to this same kind of audience and they were received with cold skepticism, despite the fact that some, including me, are already doing this with quite some success. I've noticed that, from all their concerns, the most difficult to tackle (for me, at least) is memory management. Currently, the most popular platform for game applications are videogame consoles. Memory on these special purpose machines are a premium resource and one should used it judiciously. Python's RTE footprint and memory fragmentation issues make it a hard sell for game programmers (many tend to prefer LUA). I would like to address this topic in my presentation, showing the real picture about python memory habits and how to gain control over memory management when using Python. So, I'm looking the references on the subject. Also, I would like to hear comments from those with experience in tweaking python's memory management. Cheers, Marcelo A. Camelo, M. Eng. - Project Leader ESSS - Engineering Simulation and Scientific Software E-mail: camelo at esss.com.br Phone: +55-48-334-8922 From shalehperry at comcast.net Wed Aug 13 15:58:36 2003 From: shalehperry at comcast.net (Sean 'Shaleh' Perry) Date: Wed, 13 Aug 2003 12:58:36 -0700 Subject: list groups and users of NT domain In-Reply-To: References: Message-ID: <200308131258.36973.shalehperry@comcast.net> On Wednesday 13 August 2003 05:22, Marko Faldix wrote: > Hello, > > I am looking for a language to achieve lists of all NT users and groups of > a given NT domain on a Windows 2000 Server. It has to run within a > webscript, so vbscript with windows scripting host is considered first. But > before I dive into this, isn't it possible to do it with win32all? > > An ideal result would be something like the listings one get while changing > file permissions on a file on a NT machine. I think, this extends too far, > because you browse all accessible domains (isn't it?), but maybe it is > sufficient enough to concentrate on one given known NT domain. > > Must I really use WSH and this combined with vbscript? > > If you are using Active Directory you can easily access the data via LDAP. Not sure if you are since you said NT domain, but worth a shot. From karl_lopes at yahoo.com Tue Aug 12 16:32:14 2003 From: karl_lopes at yahoo.com (Karl Lopes) Date: 12 Aug 2003 13:32:14 -0700 Subject: Python win32 dll Message-ID: Hello all, I would like to implement a COM server using python. This server is based on an interface which was given to me in Visual Basic. For example one of the methods in the interface is: Public Sub CreateLogFile(ByVal LogFilePath AS String, ByRef LogFileIntf As LogFile); 1. The corresponding Python method would be: def CreateLogFile( self, LogFilePath, LogFileIntf ). Is this correct? 2. Is there a difference in the way Python implements ByVal and ByRef? Thanks Karl From afriere at yahoo.co.uk Mon Aug 18 03:19:09 2003 From: afriere at yahoo.co.uk (Asun Friere) Date: 18 Aug 2003 00:19:09 -0700 Subject: What's better about Ruby than Python? References: Message-ID: <38ec68a6.0308172319.431a4fde@posting.google.com> "Brandon J. Van Every" wrote in message news:... > What's better about Ruby than Python? I'm sure there's something. What is > it? > > This is not a troll. I'm language shopping and I want people's answers. When I was language shopping python was up to version 1.5.2 (actually it was probably up to 1.6.1, but not on the system I was using), and there were a number of distinct advantages that I felt Ruby held over Python. First and foremost, everything in Ruby was (behaved like) an object. That is now true for Python also. Secondly you could subclass basic types, again, this is true for Python as well. Thirdly the regular expression syntax was Perl-like and built into the core of the language (althought unlike perl, of course, the syntax generated an object). In a way this is unaesthetic, certainly python's approach is much more consistent with the object oriented nature of the language. However, I use regexp so often, and still find the re module cumbersome in comparison to Perl's way of doing things, so imho this is still and advantage (ugly as it may be) that Ruby holds. Finally I was apprehensive about the 'signigicant whitespace' issue in Python, and thought that Ruby's approach was safer. I've definitely changed my mind on that one. Now all manner of obsceneties are heard to eminate from my corner of the room whenever I have to program in a language which requires me to explicitly delimit blocks @!$*&#!! Some folks also like the existence of code blocks and iterators in Ruby, (Well Python has its own kind of iterators now as well,) but that didn't concern me greatly. In the end two things persuaded me to go with Python. Firstly I work in a 'Perl shop' and I'm supposed to write Perl (which I sometimes do), my using Python was already considered using an "obscure language," Ruby would have been quite beyond the pale. More importantly, Ruby just did not have anywhere near the range of libraries that Python did. Specifically Ruby, at that time, did not have any sensible way of handling XML (ie no SAX or DOM libraries). In my opinion, most of the advantages Ruby had over Python seem to have disappeared as Python has developed. From NOSPAM__nabugoon__ at __moor.pe.krNOSPAM Sat Aug 23 03:42:09 2003 From: NOSPAM__nabugoon__ at __moor.pe.krNOSPAM (Charlie Kim) Date: Sat, 23 Aug 2003 16:42:09 +0900 Subject: pyGTK with wxPython Message-ID: hi all. I made gnome applet with pyGTK and gnome application with wxPython. When I tried import wxPython application in pyGTK applet it crashed with message: GThread-ERROR **: GThread system may only be initialized once. aborting... I think it is because I'm trying import wxPython modules in pyGTK applet. Do I have to modify the application's sources against pyGTK? or any solution? TIA. From creedy at mitretek.org Fri Aug 8 14:56:53 2003 From: creedy at mitretek.org (Chris Reedy) Date: Fri, 08 Aug 2003 14:56:53 -0400 Subject: random changes In-Reply-To: References: Message-ID: <3f33f2a0$1_6@corp.newsgroups.com> Tim Peters wrote: > [Chris Reedy] > >>Here are some interesting numbers: >> >> [snip example showing changes in normalvariate] > > > Odd! I don't have Python 2.2.2 anymore. Under Python 2.2.3, the results > are identical (and match the results you got for 2.3). > > [snip example showing no changes in normalvariate] > > I have to go back to 2.1.3 to get your 2.2.2 results: > > C:\Code>\python21\python temp.py > (2, 1, 3, 'final', 0) > 0.50177345778280169 0.28856727700571438 > 0.0021149783637115457 0.99131361156374964 > > As Raymond pointed out in another post, the WH seed method was changed in a > bugfix release, because it had bad flaws. The old method is still available > in post-bugfix releases under the name .whseed(); use of it can't be > recommended, though. > > I checked CVS. The following change was added between 2.2.2 and 2.2.3: Correct long standing bugs in the methods for random distributions. The range of u=random() is [0,1), so log(u) and 1/x can fail. Fix by setting u=1-random() or by reselecting for a usable value. This impacted exactly the variates I noticed. I think this explains the issue. Chris -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! -----== Over 80,000 Newsgroups - 16 Different Servers! =----- From mis6 at pitt.edu Sun Aug 3 10:16:44 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 3 Aug 2003 07:16:44 -0700 Subject: Singleton-like pattern References: <2259b0e2.0308010815.5dcb0b58@posting.google.com> <2259b0e2.0308020746.438d0e6b@posting.google.com> Message-ID: <2259b0e2.0308030616.4b3cf98e@posting.google.com> Steven Taschuk wrote in message news:... > Quoth Michele Simionato: > [...] > > Actually you are right, I remember now that I got problems with > > (args,kw) and at the end I used args,tuple(kw.items()). But I was > > ensure if this was a good solution. > > I'd worry about the order of kw.items(). Yes, indeed. Also, the args tuple can contain nested dictionaries and become unhashable; in such a case I should recursively flatten all the dictionaries to tuples, taking in account the ordering. To much work for me ...I have really to look at the cPickle solution. How does it solve the ordering issue? Michele From niemeyer at conectiva.com Sun Aug 24 20:58:45 2003 From: niemeyer at conectiva.com (Gustavo Niemeyer) Date: Sun, 24 Aug 2003 21:58:45 -0300 Subject: Metaclass discussons In-Reply-To: <20030824125721.5cf376e6.pedro.werneck@bol.com.br> References: <20030822193039.GA20830@ibook.distro.conectiva> <20030824125721.5cf376e6.pedro.werneck@bol.com.br> Message-ID: <20030825005844.GB31115@ibook> > There are some problems with this approach. It's tricky to work with > packages using execfile and it doesn't work with byte-compiled files. > > Yet with the same idea (executing it on a hacked context) I tried > something like this... [...] Yes, as I said, it was a dirty hack, just to show the idea. Of course it would need more work to turn this into something useful. -- Gustavo Niemeyer http://niemeyer.net From pushpin at media.mit.edu Tue Aug 12 19:44:17 2003 From: pushpin at media.mit.edu (Josh) Date: 12 Aug 2003 16:44:17 -0700 Subject: Tix + Python + Windows? Message-ID: <8bf5dfd1.0308121544.30d1c565@posting.google.com> I've been trying to get Tix running with Python on Windows. Since there is no binary distributions of Tix for Windows, it seems the easiest way to install Tix is through IDiscovery's IDEStudio 1.9 (http://starship.python.net/crew/mike/Idle/). This went fine and I ran the "Install Tix into Python" option at the end of the installation, with the target Python installation being the Python 2.2 I just mentioned. I also ran the "Run Tix demos" option at the end of the installation, which also worked fine and presented the usual tixwidgets.py demo. However, when I tried running >>> import Tix >>> root = Tix.Tk() from a Python 2.2 prompt, I got the following error: error reading package index file C:/Python22/tcl/tix8.1/pkgIndex.tcl: invalid command name "lt}]}" The only mention of this problem I can find is at: http://issues.bigasterisk.com/hiss/issue36 but there doesn't seem to be a clear resolution put forth. By the way, IDEStudio 1.9 comes with a stand-alone Python 2.1 binary and the Tix demo it ran at the end of installation was actually just a batch file containing tix8183.exe ..\..\Demos\Tcl\tixwidgets.tcl Has anyone else had any problems with this? Any suggestions? Thanks, josh From abelikov72 at hotmail.com Fri Aug 22 22:46:52 2003 From: abelikov72 at hotmail.com (Afanasiy) Date: Sat, 23 Aug 2003 02:46:52 GMT Subject: Sort a Dictionary References: Message-ID: On Sat, 23 Aug 2003 02:34:23 GMT, "Andrew Dalke" wrote: >Afanasiy: >> This is fairly simple in PHP, how do I do it in Python? >> >> http://www.php.net/manual/en/function.ksort.php > >def ksort(d, func = None): > keys = d.keys() > keys.sort(func) > return keys > >for k in ksort(d): > print k, v > How about this one? http://www.php.net/manual/en/function.asort.php From riccardo_togli.questo at e.questo_sideralis.net Sun Aug 3 09:23:22 2003 From: riccardo_togli.questo at e.questo_sideralis.net (Riccardo Galli) Date: Sun, 03 Aug 2003 15:23:22 +0200 Subject: HOME Directory in posix and nt References: Message-ID: On Sun, 03 Aug 2003 13:49:39 +0200, J?rg Maier wrote: > Hey, > > ist there a possibility to get the users homedirectory as environment > variables %HOMEPATH% or $HOME. there must be a way to see system variables > other than > stdout = os.popen('{ echo $HOME } 2>&1 ', 'r') on posix and > stdout = os.popen('echo %HOMEPATH% 2>&1', 'r') > with > home = stdout.readline() > ??? os.getenv(ENV_VARIABLE) Ciao, Riccardo -- -=Riccardo Galli=- _,e. s~ `` ~@. ideralis Programs . ol `**~ http://www.sideralis.net From peter at engcorp.com Thu Aug 21 11:18:11 2003 From: peter at engcorp.com (Peter Hansen) Date: Thu, 21 Aug 2003 11:18:11 -0400 Subject: [OT] Why is it called string? References: <3f44ce77$0$556$b45e6eb0@senator-bedfellow.mit.edu> <3F44DBF2.1010403@draigBrady.com> Message-ID: <3F44E2B3.6A33334B@engcorp.com> P at draigBrady.com wrote: > > Travis Whitton wrote: > >>"In computing, the word 'bit' is an abbreviation of what two other words?" > > > > Wow, I had no idea it was an abbreviation either. Luckily, dict had the answer > > waiting for me: > > > > From Jargon File (4.3.0, 30 APR 2001) [jargon]: > > > > bit n. [from the mainstream meaning and `Binary digIT'] > > > > It's nice to see the occasional thread on computing history rather than the > > endless stream of coding issues. > > I'm always surprised by the number of people > in computing that don't know this. > > bit is a contraction of "Binary digIT" > byte is a pun on the word bit (8 bits) > nibble is a pun on the word byte (4 bits) And nibble is spelled "nybble", at least around here, continuing the pun started by byte... From newsgroups at jhrothjr.com Fri Aug 1 18:08:27 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Fri, 1 Aug 2003 18:08:27 -0400 Subject: time, calendar, datetime, etc References: <153fa67.0307300326.45a29380@posting.google.com> <1sScnW0Sv7DzrrSiRTvUpQ@speakeasy.net> Message-ID: "Andrew Dalke" wrote in message news:bgejrq$i54$1 at slb6.atl.mindspring.net... > Ben Finney: [...] > Python doesn't try to support all numerical systems - that's why > Numeric exists. Would those users like Numeric support in core > Python? Probably. Are there more Numeric users than people > who need a detailed datetime library? Almost certainly yes. So > I aks again, what makes datetime with B.C. support, leap seconds, > etc. important enough to justify inclusion in Python's standard library. > > By comparison, a friend of mine mentioned that the Java time library, > which does try to include all these complexities, has gone through > several iterations to get where it is now and is complicated to use > because it tries to get all the details right. Several turns out to be one revision, and I don't think that they got it right either. From what I see, the Python datetime library is actually more complicated than the Java library: it's certainly got more classes, although they seem to be better designed. > > > Such people would run into trouble when leap seconds occurred anyway; > > Ha! None of my code ever used leap seconds, and in my 15 years > or so of software development, no one ever filed a bug report on it. > And on the plus side, I don't have to distribute an update when there > is an new leap second. That's because for just about everyone in the > world, a difference of a few seconds doesn't make a difference. > C'mon - the clocks in my house are +/- a few minutes! For the most part, the applications that need to be aware of leap seconds are the ones that communicate with other servers that are aware of leap seconds, and can report them. As far as I'm aware, leap seconds are a thing of the past anyway: they proved to be more trouble than they were worth to anyone. > It's only the very small number of people who care about the differences > between UTC, UT1, GPS, TAI, and all those other highly specialized > time systems that care about these sorts of details ("care" == "affects > them in any meaningful way"), so what's wrong with those people > developing a specialized library to handle those issues? Nothing at all - I'd expect to see some sort of an extension to handle those issues, just as I'd expect to see an extension if you wanted to use the proleptic Julian calendar, the Chinese calendar, the civil Moslem calendar, the Jewish calendar, and on and on and on. I'd also expect to see some sort of reasonably well thought out framework where those extensions could simply be plugged in and just work. > > Quite the reverse. If the standard library supported things like leap > > seconds, absence-of-year-zero, and Julian dates, it would be wrapped up > > in one place where programmers could use it without having to know about > > the implementation complexities. > > Implement that library, get people to use it, implement the functionality > of the datetime module using it, make sure it's maintainable and > maintained, petition for its inclusion in Python. > > Then again, you could just use mxDateTime. > > Here's another view of the issue. The datetime module implements what > I'll call "vernacular" time. That is, time as is understood by most people. > 24 hours in a day, 60 minutes in an hour, 60 seconds in a day, 365 days > in a year except every 4th year (and hazy idea about something strange > at the century mark, but that's not a problem now). And then there's > timezones and daylight savings time. (And no thoughts of "double > daylight savings like the British had during WWII.") > > datetime implements vernacular time. There's a lot of code > which implements vernacular time, because they aren't written > by experts. To them, 1) datetime makes sense and 2) won't > ever cause problems in real life. > > I am one of those people. I would like to replace my hand-written > code with a standard library. I want that library to implement *my* > time system, not the so-called real one developed by experts who > worry about variations in the Earth's rotation nor about scholars > who say the first day of the year back in 1000AD was in March. Where was it in March? [grin]. Answer. It depends on where is. > So a robust datetime library almost certainly must implement > this vernacular time system, if only for completeness. Consider > 'datetime' as the first module for that hypothetical library. It > definitely is useful as-is. Now we just have to wait for the rest > of it to be implemented. I'm certainly not objecting to that. That's the interface to a time system that everyone expects, and other objectives should quite properly be implemented by some sort of extensions. My objection is to exactly one implementation decision: to limit the time range at 1AD. That is, to use the vernacular, a show-stopper. It means that the core of the library has to be reworked if you want to deal with dates before 1AD. It has nothing to do with the external interfaces, nor does it have anything to do with whether the package has the ability to use proleptic Julian dates, Chinese dates, Muslim civil calendar dates, or anything else. I don't have the time to look into how difficult it would be to change that. Right now, I'm working on bringing the Python version of FIT up to the March Java release, and integrating it with FitNesse. Maybe when I get back to my astrology programming. My application date package works for what I need it to do; it just seems that I can't abandon it for the standard Python library package. [Sigh.] John Roth > > Ahhh, I shoulda been a philosopher. :) > > Andrew > dalke at dalkescientific.com > > From jjl at pobox.com Fri Aug 22 10:18:42 2003 From: jjl at pobox.com (John J. Lee) Date: 22 Aug 2003 15:18:42 +0100 Subject: urllib2/httplib and email mime References: <4c8dd21a.0308220357.705d0db5@posting.google.com> Message-ID: <87vfspzsfx.fsf@pobox.com> someone at arbitrary.org (Joseph) writes: > I am using email to create a multipart message that I need to post to > a url. > > I have been doing it semi-manually with httplib: [...] > Can someone sugest a cleaner way of doing this sort of thing using > urllib2? The problem is getting the Content-Type header from my email > object to be used by urllib2 as an http header. http://wwwsearch.sourceforge.net/ClientForm/src/README-0_1_7b.html (note only 0.1.x versions do file upload, not 0.0.x) I haven't added file upload to the long example on that page, so here's one: import urllib2, ClientForm # url here is URL of web page containing the form you're submitting response = urllib2.urlopen(url) forms = ClientForm.ParseResponse(response) response.close() form = form[0] for name in filenames: f = file(filename) # use StringIO if you have a string to upload # mimetype and filename are optional form.add_file(f, "text/plain", "upload.txt") # (do other form-filling if necessary) request = form.click() response2 = urllib2.urlopen(request) response2.read() # body response2.info() # headers You can cache the form (in a class, on on disk with pickle) or the HTML (ClientForm.ParseFile is useful for that) if you don't want to fetch the form page every time you submit a form. A minor wart I just noticed: ClientForm only reads from the files when you actually do form.click(), so the code above relies on Python to close the file objects you're uploading from (not a problem in CPython). Also, I haven't yet tested multifile upload on anything but Python's cgi module -- but I'm likely to fix it quickly if it doesn't work. And I'm sure my MIME code isn't as sophisticated as the email module -- for example, it doesn't yet guess MIME types. HTH John From ghowland at lupineNO.SPAMgames.com Sat Aug 23 15:31:17 2003 From: ghowland at lupineNO.SPAMgames.com (Geoff Howland) Date: Sat, 23 Aug 2003 19:31:17 GMT Subject: Modifying the {} and [] tokens References: <04cekv0s6ghjtuhl5j2gph7ltobdb5rsam@4ax.com> <2259b0e2.0308230718.53d22c14@posting.google.com> <774fkvg920qibnnp83r17inqmk311tqcsv@4ax.com> <3F47C006.1C730829@alcyone.com> Message-ID: On Sat, 23 Aug 2003 12:27:02 -0700, Erik Max Francis wrote: >Geoff Howland wrote: > >> On 23 Aug 2003 08:18:49 -0700, mis6 at pitt.edu (Michele Simionato) >> wrote: >> >> >Subclass dict, define __add__ and __sub__ and it will work, but NOT >> >with the brace syntax. You must use something like >> > >> >mydict(a=1,b=2)+mydict(c=3,d=4) >> >> Yeah, I got this to work off the bat. > >So what's the problem? If you got it to do what you wanted, why would >you possibly want your personal changes reflected officially in the >language? Sit back for a moment and think what would happen if >_everybody_ proceeded this way. I didn't say my personal preferences should become the official language. I made arguments for some things I thought were logical becoming part of the official language, and that seems fine. We've been over the problems with it, and why it is NOT part of the language, but it still is a logical argument and was just rejected. On my personal goals, that definitely wouldnt be added to the official language, I was just looking for a way to make them work for my own project. If it was a hack, so be it. If it turned out to not work well, I could revert it. It's not possible, so that's fine. I'm satisfied with all the answers I've received in this thread and am now fully illuminated on the subject. -Geoff Howland http://ludumdare.com/ From msurette at myrealbox.com Wed Aug 13 15:14:23 2003 From: msurette at myrealbox.com (Michael Surette) Date: Wed, 13 Aug 2003 19:14:23 GMT Subject: Eight Queens Puzzle by Magnus Lie Hetland References: <215fa0fc.0308130557.7f1c950b@posting.google.com> Message-ID: On Wed, 13 Aug 2003 06:57:26 -0700, chansky wrote: > I've been reading Magnus Lie Hetland's book, Practical Python. In one > of the chapters he discusses how to use a Generator function to solve > the Eight Queens puzzle. The following is part of his codes: .... > I've a hard time to understand the following statement: > > if abs(state[i]-nextX) in (0,nextY-i): > > The author said that this statement will be True if the horizontal > difference b/w the next queen and the previous one under consideration > is euqal to zero or equal to the vertical distance (diagonally), and > false otherwise. > > Well, maybe I'm really slow. What does that "vertical distance" really > mean? If someone out there has read his book, can you help me > understand that line of code. I haven't read the book, but I would suspect that the vertical distance is the difference in the Y values of the two positions, just as the horizontal distance is the difference in the X values. hth Mike From scottholmes at sbcglobal.net Thu Aug 14 16:14:39 2003 From: scottholmes at sbcglobal.net (Scott Holmes) Date: Thu, 14 Aug 2003 13:14:39 -0700 Subject: locatime and strftime Message-ID: <3F3BEDAF.1020905@sbcglobal.net> I've just run into an issue with the use of localtime and strftime. It appears that localtime is dropping the value provided by the database record by eight (8) hours. It is only doing this for the representation of time (H:M) not the date. I have this bit of code: print "DB Time: ", app_date, " ", start_time, " Python Time:",time.strftime('%m/%d/%Y', time.localtime(app_date)), " ", time.strftime('%H:%M', time.localtime(start_time)) This results in: DB Time: 2000-12-31 00:00:00.00 06:45:00.00 Python Time: 12/31/2000 22:45 Actually, I did this for a number of dates and times. I would expect the python date to be 12/30/2000 I would like to avoid this conversion of times altogether and just trust the value contained in the database. I suspect it may have something to do with locale, but I haven't delved that far into Python yet to know how to deal with that issue. -- --------------------------------------------------------------------- Scott Holmes http://sholmes.ws http://pages.sbcglobal.net/scottholmes scottholmes at sbcglobal.net Independent Programmer/Analyst Passport 4GL PHP HTML Composer PostgreSQL Informix 4GL, SQL --------------------------------------------------------------------- There are more things in heaven and earth, Horatio, than are dreamt of in your philosophy --------------------------------------------------------------------- From simonb at webone.com.au Mon Aug 11 19:26:40 2003 From: simonb at webone.com.au (Simon Burton) Date: Tue, 12 Aug 2003 09:26:40 +1000 Subject: stretching list comprehensions Message-ID: I was quite delighted when i found this: >>> nums = [ x+y for x in range(10) for y in range(10) ] Great! No more list of list joining shenanigans... Shortly thereafter, i tried this: >>> del y >>> nums = [ x+y for x in range(y) for y in range(10) ] Traceback (most recent call last): File "", line 1, in ? NameError: name 'y' is not defined >>> Well.. Is there an inherent reason why this could/should not be made to work? Simon. From news at yebu.de Tue Aug 5 10:17:01 2003 From: news at yebu.de (Karl Scalet) Date: Tue, 05 Aug 2003 16:17:01 +0200 Subject: ANN: Snakelets 1.1 (simple-to-use web app server with dynamic pages) In-Reply-To: <3f2fb995$0$49114$e4fe514c@news.xs4all.nl> References: <3f2ea0a0$0$49110$e4fe514c@news.xs4all.nl> <3f2f7bf4$0$49103$e4fe514c@news.xs4all.nl> <3f2fab63$0$49103$e4fe514c@news.xs4all.nl> <3f2fb995$0$49114$e4fe514c@news.xs4all.nl> Message-ID: Irmen de Jong schrieb: > Karl Scalet wrote: > > you can easily fix this yourself in the meantime > by adding the missing argument to the call to > createHTTPD(). yes, easy enough :-) > My purpose was twofold: > - understand better how to write dynamic web applications > - understand the inner workings of a web application server. > > Your course, is it about both? Or only the first? If ever, very likely just option 1. >> Do you intend to bring Snakelets up to a production level? > > No, I don't. > But if somebody else wants to do that, be my guest :) > >> Which one of the current products (Webware?) do you >> think is closest to yours? > > I think Webware, because it also has the concept of > 'servlets' and 'python server pages'. That was my guess. Karl From heikowu at ceosg.de Tue Aug 12 12:17:55 2003 From: heikowu at ceosg.de (Heiko Wundram) Date: 12 Aug 2003 18:17:55 +0200 Subject: Python vs. C# In-Reply-To: References: Message-ID: <1060705075.843.65.camel@d168.stw.stud.uni-saarland.de> On Tue, 2003-08-12 at 06:45, Brandon J. Van Every wrote: > Yes your rendering code is nice looking. Is it fast? Were you working on a > problem where it needed to be fast? I haven't been using C++ out of love. > I've been using it for performance. And I don't think "what I can do in 72 > hours" is a valid test for big industrial system architectures. Is your > code going to hold up in the face of dozens of programmers banging on it, > and hundreds or thousands of programmers using it? And still be fast? Yes, I was working on problems where the rendering code needed to be fast. Doing an import psyco solved all my earlier fears about lagging behind in performance terms against the people I had to compete with. And, is having an interpreted language really such a major concern in the age of computers operating at 2000+ Mhz? The final goal of the project was designing a 3D-ego shooter with the engine we had written. And it didn't run overly fast, but fast enough on the machine I tested it on. If I had had the time, I'd have worked most of the rendering code down to C, which I would've wrapped with SWIG or the like, but I was surprised how fast it even ran using plain Python with psyco. And I don't really want to express game logic, such as computer player AI, or the like, in C++. Do you? (genetic algorithms are plain cool here...) Just btw., my code help up to other programmers banging on it, and also held up to larger usage. Just because you have static typing doesn't mean that the code works together with an "evil programmer" (casting is lots of fun...). And because my code was understandable, other programmers who used it could read the code before using my library. This is impossible to do with an overly complex C++ library, in my eyes. > It is? Then I'm confused, because around here people keep talking about the > beauty of avoiding types. static typing = needing to declare types for all slots (slots==variables). dynamic typing = a slot can take up an object of any type (python's slots only take up references, everything is a reference). strong typing = types are checked on usage. If you don't use a correct type (like with an expression (float*)&"1234" in C, which makes no sense at all), you get an exception. weak typing = types aren't checked on conversion, so things like (float*)&"1234" work. Python is certainly strongly typed, but unlike C, it is dynamically typed. People also speak of static weak typing in C, as you can cast anything into anything else (without checks), what you can't do in Python. C++ is (was) the same, at least when I learnt it. > What you are saying is Python excels at prototyping, where speed and > flexibility are paramount. You are not saying that Python excels as a big > system architecture language, where stability and safety are paramount. Isn't a renderer and a game engine a big system architecture? I didn't just prototype it in Python, I could offer a complete system, which was very extensible. I could've never managed this in any other langauge without the usual headaches. > That "except" is, like, 1/2 to 2/3 of industry. I think you Python guys > need to wake up that there's a much bigger, scarier, and more threatening > world out there than the UNIX world of "engineering done right." That world > is also not sitting still, it's on the move. For interoperability of > langauges, UNIX has nothing to offer like the .NET Framework. DirectX is > now ahead of OpenGL on vertex/pixel shader API capability and stability. > The black hole, if not taken seriously, will swallow you. Either that or > you're forced into "clone and conquer" in reverse. I don't really know why you compare OpenGL to DirectX, they are just plain API specifications. Maybe on your Windows Box DirectX is faster than OpenGL (and offers support for more tasks), but this is a driver vendor problem. Most graphics drivers on Windows are developed with DirectX in mind, not with OpenGL. NVidia is IMHO an honorable exception, as their OpenGL code (sometimes) works faster than DirectX. And to a sidenote: Unix has always had a .NET Framework. The libraries .NET tries to standardize have been available on Unix since a long time. And I don't especially like the thought that I have to choose a single Framework to do all I need, as this only makes me dependant on the original implementor (Microsoft in this case). And if you need a "portable" virtual machine, Python, Java, and Perl (just to name a few) have offered this since ages. .NET isn't such a big innovation as it claims to be... Heiko. From gregbrunet at NOSPAMsempersoft.com Fri Aug 22 14:33:50 2003 From: gregbrunet at NOSPAMsempersoft.com (Greg Brunet) Date: Fri, 22 Aug 2003 13:33:50 -0500 Subject: __getattr__ weirdness References: Message-ID: I've figured out one thing: that be re-arranging the __init__ code assignments (and adding one that was placed later in code I snipped out), I am able to get the extra _ga calls to stop a lot earlier. This code: #---------------------------------------- def __init__(self,filename): print '** __init__' self._rec=[] self._fldNames=[] self._filename=filename self._del=' ' self._dirty=False self._open=False self._recno = 1 ... by assigning _rec & _fldNames first, gets the repeated _ga calls to stop after the first assignment following those two assignments. I'm still at a loss as to why _ga is being called all these times to begin with though! I'm only assigning values, not requesting them! Thanks, -- Greg From aleax at aleax.it Fri Aug 8 11:57:27 2003 From: aleax at aleax.it (Alex Martelli) Date: Fri, 08 Aug 2003 15:57:27 GMT Subject: Accessing c objects in python References: Message-ID: Duncan Booth wrote: ... > Thomas Heller wrote in news:smocwafb.fsf at python.net: > >> Would you care to write a more detailed summary of your findings? This >> would probably make a good page in the main Python wiki... >> > > I did an evaluation of the various ways to link to Python for the ACCU > conference this year, although I must say my conclusion was slightly > different than Alex's: I would use Pyrex in preference to SWIG even if I > didn't want to embed much code in the interface. Interesting. I do agree with your observation that, with SWIG, responsibility for allocating and freeing tends to show up at the Python level. However, SWIG generates such a Python level itself, as it wraps 'foo' into a low-level _foo.so and a higher-level foo.py. Thus, the _USER_ of the overall wrapper need not be concerned with memory allocation and freeing -- unless he WANTS to be, for performance reasons, in which case, with SWIG, he gets that *option*. That, in summary, is the epiphany I had on this latest round of encounter with SWIG, which made me chose it to complete the wrapping in preference to Boost and pyrex: the python user of the wrapper could use it in the simplest and safest of ways _OR_, when performance mattered a lot (as it might in some cases for these wrappings, which dealt with multimedia-related libraries), the user could also CHOOSE to take more direct control -- e.g. explicitly allocate a buffer at the start of a loop, reuse the buffer N times in the loop, and free it after the loop, rather than rely on automatic allocation and freeing and thus pay the resulting performance cost -- in that spot of two in a huge program where such a strategy pays off. "Trust the programmer" and "don't stop the programmer from doing what needs to be done" are two of the "spirit of C" principles (from the Rationale of the C standard) which Python respects (more so, in fact, than the other principle from the same source that is so often quoted, "provide only one way to perform a task"). With SWIG I get such an arrangement "almost by default" -- and I think that's quite different from saying that the python user "has" to deal with the issues of memory management... it is, rather, a _choice_ he or she gets, just about "for free" from the POV of the guy who is authoring (and those who in the future will be maintaining) the wrapper. I could, of course, get the same choice for the user by coding in Boost -- but then, since I'm wrapping a C library [and not a C++ one with classes already provided and decently well designed], I'd have a lot more boilerplate-coding to do myself. (I could probably concoct incredibly subtle C++ templates with some macros in support, to lighten my own boiler-plate coding task -- but I fear that would leave far too heavy a maintenance burden on future maintainers of those wrappers). I suspect I could most likely get the same result in pyrex, too -- but then, again, I'd have to code a lot of boilerplate, _without_ even the help of C++ templates, OR even of C-preprocessor macros... that's too much raw boilerplate for me;-) Quite possibly I haven't grasped "the pyrex way to metaprogramming" (just as I guess I hadn't grasped the SWIG one on earlier encounters with it -- Boost never gave me any trouble in this regard, as I already understood C++ templates & the like in sufficient depth before I met it). I'd better underline yet again that this applies to _wrapping C libraries_! I do NOT claim I have any real grasp yet about the SWIG way wrt C++ (templates in particular) -- when I next need to wrap a C++ library, I'll reach for Boost and Pyste, without doubts; and if I ever need to provide Python users with very speedy code, psyco can't supply it (e.g. because I need to target non-Intel-like CPU's), and Boost is not applicable (e.g. because I can't require future maintainers to know C++), I'm most definitely going to give pyrex another chance -- apart from the boilerplate issues (==lack of [or insufficient grasp of mine for] metaprogramming and code generation facilities), I found it just delightful. Alex From phil at riverbankcomputing.co.uk Mon Aug 18 09:23:30 2003 From: phil at riverbankcomputing.co.uk (Phil Thompson) Date: Mon, 18 Aug 2003 14:23:30 +0100 Subject: advice choosing IDE In-Reply-To: References: Message-ID: <200308181423.30896.phil@riverbankcomputing.co.uk> On Monday 18 August 2003 1:18 pm, Michael Peuser wrote: > > There are two GUI Toolkits you might like: > PyQt and their GUI Builder (that would be free for non commercial work) if > you plan to do *a lot* of GUI applications. The GUI Builder is *not* an > Python IDE, so that is somewhat off topic ;-) I'll beat Detlev to it this time... eric at http://www.die-offenbachs.de/detlev/eric3.html is a full IDE, written in PyQt, that integrates with Qt Designer. It does the usual editing, debugging, project management, class browsing - plus access to source code control systems, syntax checking, unit testing, profiling, code coverage. Latest snaphots include refactoring tools. Etc, etc, etc. Phil From tjreedy at udel.edu Wed Aug 27 21:22:55 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 27 Aug 2003 21:22:55 -0400 Subject: Script Discussion & Critique References: <3F4D31B1.6080802@hotmail.com> <06eqkv4onjh5m4tcbbqkmh8lscaj5niatp@4ax.com> <3F4D4402.3060209@hotmail.com> Message-ID: "hokiegal99" wrote in message news:3F4D4402.3060209 at hotmail.com... > Is this script written well? Is it a good design? How could it be made > better (i.e. write to a file exactly what the scipt did)? I hope to use > it to recursively find a replace strings in all types of files (binary > and text). My main answer is your answer to the following: does it operate correctly? does it produce output within the bounds of what you consider acceptible? In particular, does it pass your test case(s)? and are your test case(s) reasonably representative of the domain of application? > Thanks for any ideas, pointers or critique... most of the ideas behind > the script came from the list. > > > #Thanks to comp.lang.python > import os, string > print " " > print "******************************************************" > print " Three Easy Steps to a Recursive find and Replace " > print "******************************************************" I would lazily print one multiline string. > print " " > x = raw_input("1. Enter the string that you'd like to find: ") I would delete the print and add '\n' to the front of the prompt > print " " > y = raw_input("2. What would you like to replace %s with: " %x) > print " " > setpath = raw_input("3. Enter the path where the prgroam should run: ") > print " " > for root, dirs, files in os.walk(setpath): > fname = files > for fname in files: > inputFile = file(os.path.join(root,fname), 'r') > data = inputFile.read() > inputFile.close() > search = string.find(data, x) > if search >=1: > data = data.replace(x, y) > outputFile = file(os.path.join(root,fname), 'w') > outputFile.write(data) > outputFile.close() > print "Replacing", x, "with", y, "in", fname > print " " > print "**********" > print " Done " > print "**********" Terry J. Reedy From tismer at tismer.com Thu Aug 21 15:22:07 2003 From: tismer at tismer.com (Christian Tismer) Date: Thu, 21 Aug 2003 21:22:07 +0200 Subject: Stackless ported to 2.2.3 Message-ID: <3F451BDF.3030205@tismer.com> Dear community, with the help of Giovanni Bajo, Stackless Python 3.0 beta is now available for (and only for) Python 2.2.3 . CVS checkout: CVSROOT=:pserver:anonymous at centera.de:/home/cvs cvs co stackless A tgz snapshot can be found here: http://www.stackless.com/stackless-py223-030821.tgz Here are the updated windows binaries: http://www.stackless.com/binaries-pc/ Installation: run Python in the folder where you unpacked python22.dll, or replace this file in c:\windows\system32 have fun -- chris -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 mobile +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From none at none.net Wed Aug 13 07:17:47 2003 From: none at none.net (Sami Viitanen) Date: Wed, 13 Aug 2003 11:17:47 GMT Subject: Determine file type (binary or text) References: Message-ID: Works well in Unix but I'm making a script that works on both Unix and Windows. Win doesn't have that 'file -bi' command. "bromden" wrote in message news:bhd559$ku9$1 at absinth.dialog.net.pl... > > How can I check if a file is binary or text? > > >>> import os > >>> f = os.popen('file -bi test.py', 'r') > >>> f.read().startswith('text') > 1 > > (btw, f.read() returns 'text/x-java; charset=us-ascii\n') > > -- > bromden[at]gazeta.pl > From Mike at DeleteThis.Geary.com Tue Aug 26 03:09:45 2003 From: Mike at DeleteThis.Geary.com (Michael Geary) Date: Tue, 26 Aug 2003 00:09:45 -0700 Subject: Extracting Rich Text data formats from win32clipboard References: Message-ID: > >>> clipboard_grab() > FORMAT: 49171 > FORMAT: 16 > FORMAT: 7 7 = CF_OEMTEXT 16 = CF_LOCALE 49171 = 0xC013 = apparently OLE private data That should help you with some searches. Basically the CF_OEMTEXT is the only one that's going to be useful for you, unless you can figure out what to do with the OLE private data. -Mike From nenad.propadovic at partner.bmw.de Sat Aug 9 17:59:48 2003 From: nenad.propadovic at partner.bmw.de (Propad) Date: 9 Aug 2003 14:59:48 -0700 Subject: COM server usage question References: Message-ID: Dear Mr. Hammond, thank you for your answer, and even more for making Python on win32 possible at all. I do realise my question resembles some previous postings, and the answer you gave me was allready given. However, I'll try to restate my question in other words: could anybody give me a pointer to any kind of literature enabling me to produce my own type library? Some easy to understand beginners guide to COM, explaining also the typical registry entries? Well if there are no tlb-s in win32com, I just might manage to get them in there :-) Thanks, all you kind people. Nenad Propadovic P.S. Starting a contract work at BMW, I just realised the penetration of Python in the german automotive industry seems to be quite descent. This is due to a tool-suite by a company named DSpace, which uses Python as its scripting language... Mark Hammond wrote in message news:... > Propad wrote: > > > Hello everybody, ... > > I thank you kindly for your help. > > At this stage, PythonCOM servers do not create a type library. Thus, > the interface is registered, but no tools that process type libraries > will be able to see it. > > Mark. From andrew-pythonlist at puzzling.org Wed Aug 27 03:18:06 2003 From: andrew-pythonlist at puzzling.org (Andrew Bennetts) Date: Wed, 27 Aug 2003 17:18:06 +1000 Subject: sending a byte on a socket In-Reply-To: <1DAECE9E8F34E04AA0E5699AF7D9FF0906BE6911@stpmsg00.corp.fairisaac.com> References: <1DAECE9E8F34E04AA0E5699AF7D9FF0906BE6911@stpmsg00.corp.fairisaac.com> Message-ID: <20030827071806.GB4878@frobozz> On Wed, Aug 27, 2003 at 02:02:14AM -0500, Pettersen, Bjorn S wrote: > > From: Daniel Timothy Bentley [mailto:dbentley at stanford.edu] > > > > Slamming my head against what should be an easy problem: > > > > How do I send a byte across an open, connected socket? > > [...] > > A one character string is a byte... > > byteString = chr(byte) Calculating and sending single bytes at a time is probably unnecessarily painful, though. It wouldn't surprise me if the original poster finds that the struct module makes their life much easier: http://www.python.org/doc/lib/module-struct.html -Andrew. From peter at engcorp.com Thu Aug 21 11:37:52 2003 From: peter at engcorp.com (Peter Hansen) Date: Thu, 21 Aug 2003 11:37:52 -0400 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: <31575A892FF6D1118F5800600846864D01200BBB@intrepid> Message-ID: <3F44E750.372E795@engcorp.com> Simon Brunning wrote: > > > From: Peter Hansen [SMTP:peter at engcorp.com] > > > > Jeffrey P Shell wrote: > > > > [an excellent, lengthy article contrasting Python and Ruby] > > > > Article saved permanently. This is the only good thing to > > come out of this thread so far. Thanks Jeffrey! > > Not quite true. Nearly, but not quite. Jeremy Dillworth's post is also > worth a read - > . Yes, you're right! Missed that one in the noise... -Peter From tundra at tundraware.com Tue Aug 5 16:20:07 2003 From: tundra at tundraware.com (Tim Daneliuk) Date: 05 Aug 2003 20:20:07 GMT Subject: Win32All Crashes Python 2.3? In-Reply-To: References: <1tkngb.2h1.ln@boundary.tundraware.com> Message-ID: Martin v. L?wis wrote: > Tim Daneliuk writes: > > >>OK, after some highly-technical debugging procedures (print statements! ;), >>I have determined that os.lstat() is blowing up when Win32All is being >>used. What is strange is that this only happens sometimes. For the life >>of me, I cannot see anything in my code that is causing the problem. >>It sure looks to me like an errant pointer or something in Win32All. >> >>FWIW, Dr. Watson is reporting an Access Violation... > > > Please verify that there is only a single copy of the CRT in your process. > ^^^^^^^^^^^^^^^^^^^^^^^^ Please clarify what you mean by this - I am unclear with "CRT" in this context. Thanks, ---------------------------------------------------------------------------- Tim Daneliuk tundra at tundraware.com PGP Key: http://www.tundraware.com/PGP/ From mwh at python.net Mon Aug 4 06:44:39 2003 From: mwh at python.net (Michael Hudson) Date: Mon, 4 Aug 2003 10:44:39 GMT Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> <840592e1.0307312304.77a0a05f@posting.google.com> <7h3brv9a9oz.fsf@pc150.maths.bris.ac.uk> <840592e1.0308011202.210523d5@posting.google.com> Message-ID: <7h33cghaejk.fsf@pc150.maths.bris.ac.uk> hanzspam at yahoo.com.au (Hannu Kankaanp??) writes: > Michael Hudson wrote in message news:<7h3brv9a9oz.fsf at pc150.maths.bris.ac.uk>... > > > > You apparently have such a loose definition for garbage > collection, that even C programs have "a form of garbage > collection" on modern OSes: All garbage is reclaimed by > the OS when the program exits. It's just a very lazy collector. > > I don't consider something a garbage collector unless it > collects all garbage (ref.counting doesn't) and is a bit more > agile than the one provided by OS. Well, OK, but people do tend to allow a bit of 'conservativeness' in their collectors, don't they? Boehm's GC-for-C is usually considered a 'real GC' and that doesn't necessarily collect everything (AIUI, I'm not an expert in this field). CPython's 'ref counting + gimmicks' certainly *would* seem to qualify as a GC, by your definitions. > > Saying "Ref. counting sucks, let's use GC instead" is a statement near > > as dammit to meaningless. > > You, I and everyone knows what I was talking about, so it could > hardly be regarded as "meaningless". Well, OK, but: even if we don't allow refcounting as 'GC' I would (really!) like to know which form of garbage collection you would use instead. > > Given the desires above, I really cannot think of a clearly better GC > > strategy for Python that the one currently employed. AFAICS, the > > current scheme's biggest drawback is its memory overhead, followed by > > the cache-trashing tendencies of decrefs. > > It's not "the one currently employed". It's the *two* currently > employed and that causes grief as I described in my previous post. You mean two, as in the ones used by Jython and CPython? If have to admit, I > And AFAIK, Ruby does use GC (mark-and-sweep, if you wish) and > seems to be working. With finalizers? Just curious. > However, this is rather iffy knowledge. I'm actually longing for > real GC because I've seen it work well in Java and C#, and I know > that it's being used successfully in many other languages. > > > What would you use instead? > > A trick question? Not at all! I think it would be practically very difficult to move to a radically different memory management methodology without breaking the vast majority of C extensions out there, but I would like to see some more concrete speculation about alternatives. Cheers, mwh -- Considering that this thread is completely on-topic in the way only c.l.py threads can be, I think I can say that you should replace "Oblivion" with "Gravity", and increase your Radiohead quotient. -- Ben Wolfson, comp.lang.python From emiddelb at mpifr-bonn.mpg.de Wed Aug 20 08:07:06 2003 From: emiddelb at mpifr-bonn.mpg.de (Enno Middelberg) Date: 20 Aug 2003 12:07:06 GMT Subject: Problem installing ppgplot Message-ID: Hi, I want to install pgplot but I can't really get it to work. Here is what I did; pgplot libraries are installed in ~/pgplot -downloaded ppgplot-1.1.tar.gz from http://www.astro.rug.nl/~breddels/python/ppgplot/ -PGPLOT_DIR was set correctly, so I tried python setup.py install, but that stopped saying ------------------------------------------------------------- gcc -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC -I/homes/emiddelb/local2/include/python2.2/Numeric -I/homes/emiddelb/local2/include/python2.2 -c ppgplot.c -o build/temp.linux-i686-2.2/ppgplot.o ppgplot.c:21: cpgplot.h: No such file or directory ------------------------------------------------------------- -I found a website describing that error (http://www.astro.rub.de/laboca/download/help_install_all_for_boa.html). I copied cpgplot.h to my local include dir as I don't have root permissions and re-ran the install script. Apparently, the gcc command now worked, but another one now crashed: ------------------------------------------------------------- gcc -shared build/temp.linux-i686-2.2/ppgplot.o -L/usr/X11R6/lib/ -L/homes/emiddelb/pgplot -L/usr/X11R6/lib/ -lcpgplot -lpgplot -lX11 -lm -lg2c -o build/lib.linux-i686-2.2/ppgplot.so /usr/i486-linux/bin/ld: cannot open -lcpgplot: No such file or directory collect2: ld returned 1 exit status ------------------------------------------------------------- I had the suspicion that the "-lcpgplot" was not correct, as the pgplot distribution does not contain any other files named cpgplot.* except for cpgplot.h and a cpgplot.c demonstration file. I therefore tried to run the gcc command without "-lcpgplot" and got a file called "ppgplot.so" in the "build/lib.linux-i686-2.2/" subdirectory. I copied that file to ~/lib/python2.2/site-packages/ppgplot/ppgplot.so, i.e., to a directory similar to all the other local packages, but now when I try to use it, I get an error saying "ImportError: No module named ppgplot". I still suspect that the installation is incomplete because all the other packages have at least some python files. Can someone give me a hint on how to fix this? I'm not a great programmer and I do not know much of libraries and those things, I just want to _use_ ppgplot :-/ Cheers, Enno From max at alcyone.com Wed Aug 27 23:34:50 2003 From: max at alcyone.com (Erik Max Francis) Date: Wed, 27 Aug 2003 20:34:50 -0700 Subject: Style question... References: <4cd3b.50331$la.863381@news1.calgary.shaw.ca> <3F4D63AD.FBBFCCFB@alcyone.com> Message-ID: <3F4D785A.7A76F620@alcyone.com> Chad Netzer wrote: > But, this technique will STILL fail on multiply nested loops, etc. > (emacs does it's best, but it cannot mind read) So it is a terrible > habit to get into, because it WILL cause you problems if relied upon > blindly. > > So, it is better to NOT rely on the 'pass' crutch, and instead rely on > the python mode operations for reindenting blocks of code (which Eric > provided; surely this is becoming a FAQ) Agreed. If you're going to write code in a particular language, you should fully embrace the language and its style, or move on to something that you feel more comfortable with. These kind of crutches will only serve to bite you later -- they aren't panaceas, and you may forget to use them or be hobbled when interacting with someone else's code (where you're not going to convince others to use your crutches). There's also an indirect effect; if I'm reading someone else's Python code, and, say, see someone using semicolons as statement delimiters on every line, I'm not exactly going to be struck with a great deal of confidence. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ Don't ever get discouraged / There's always / A better day \__/ TLC From max at nospam.com Mon Aug 4 11:31:19 2003 From: max at nospam.com (max) Date: Mon, 04 Aug 2003 15:31:19 GMT Subject: packaging windows services? Message-ID: Hi all, trying to package a windows service into a standalone (no full python install needed) py2exe works well, except that it only appears to support 'manual start' service option and only under default accont. What py2exe appears to do is to ignore the win32serviceutil.HandleCommandLine(MyService) in the main and just use the class (hence the classname requirement on the command line) with its own options. The advantage of this approach is that it does not require PythonService.exe. McMillan does not appear to support services directly. But I do wonder if I can combine the exe produced by McMillan with PythonService.exe to get something working. The other approach is to dig into the py2exe source and swap the manual start for automatic. suggestions? From pythonguy at Hotpop.com Tue Aug 19 13:49:31 2003 From: pythonguy at Hotpop.com (Anand Pillai) Date: 19 Aug 2003 10:49:31 -0700 Subject: Brandon's personal style (was) References: <38ec68a6.0308172319.431a4fde@posting.google.com> Message-ID: <84fc4588.0308190949.46d59e70@posting.google.com> The anaconda was much bigger, louder and enormous than anything the snakes ever experienced in their humble but peaceful abode. The anaconda saw his chance to make it big in the snake community. It began hissing violently in all directions. ...And the snakes went back to their burrows leaving the anaconda to regurgitate its undigested food... Waiting for the hissing to die... -Anand Cliff Wells wrote in message news:... > On Tue, 2003-08-19 at 02:03, Brandon J. Van Every wrote: > > Cliff Wells wrote: > > > To try to force those battles is about as reliable an indicator > > > of trolling as is "URGENT: YOUR IMMEDIATE ASSISTANCE REQUIRED" is a > > > reliable indicator of Nigerian spam. It should come as no surprise to > > > you that people mistake your posts as trolling. They may be > > > incorrect, but it is certainly a reasonable assumption. > > > > I hate to use an Eep-ism, but it's time for people to evolve. "You sound > > like a troll" is not that reasonable an assumption. Outside of politics > > newsgroups, I've almost never seen actual trolls. > > I've seen several, mostly on the Linux lists, but c.l.py hasn't been > immune (lumberjack, you there?). > > > I've seen plenty of > > people insulting each other, totally unable to see the other person's point > > of view. I've seen countless instances of Troll Hunting all over Usenet > > that had nothing to do with me. In fact, it's clearly a popular newsgroup > > sport! People are intellectually lazy, they don't have an ironclad > > criterion for what is or isn't a troll. A troll is anything they don't > > like. They don't use imagination or exercise benefit of the doubt when > > controversial posts appear. They just enjoy naming things within a familiar > > pigeonholeing system. It comforts them. They are so focused on controlling > > group discourse, and not letting "the wrong kind of conversation" happen, > > that they don't put much thought into what was said in the first place. > > Have you ever considered that perhaps it is your own expectation of a > "Troll Hunt" that makes you see such a thing when there is at least a > remote chance you're looking for something that isn't there? In my two > years on c.l.py I've never seen any such thing nor heard anyone else > complain of such until now. If you give up the fantasy that people are > out to get you then perhaps you might see how your own actions > precipitated today's events. It's certainly true that people were quick > to label your thread on Python vs. Ruby as a troll. However I also > expect much of that was due the lingering effects of your prior thread > on Python vs C#. > > > > Were you known to be a contributor, either with code or > > > knowledge, your forays into time-wasting speculation would most likely > > > be much better received. As it is the only "contribution" you've made > > > is a generous use of other people's time and bandwidth. > > > > As I see it, my detractors are enginerds with no appreciation for or skill > > at marketing. > > Quite probably true. Also most of them are probably proud of it. This > isn't a marketing group, it's a programming language discussion group. > I'd venture that with few exceptions most people here probably despise > marketing or at best find it irrelevant. That is why there is a > separate ng for discussion of such things. Most people here don't want > to hear about it, even in the sense that it relates to Python. > > > Nor, probably, much awareness of Python marketing efforts. > > But the ones that do have hopefully found the appropriate forum. > > > That's how I figure you can (1) blithely ignore my analysis of Reality On > > The Ground, (2) merrily claim I'm a do-nothing. I've suggested you look at > > the marketing-python archives several times, it's a comment I've peppered > > here and there. Have you? > > I browsed it and in fact considered responding to some of your claims > there, which I found to be baseless (or at least misguided), but as I am > one of the people who find marketing boring I didn't bother. > > > > The fact that you get "kills" in every ng you spend time in probably > > > says more about you than other people. > > > > Actually, it says more about where I am in life. There was a time when I > > never killfiled anybody. If I was rude, and we got into fights, we'd just > > keep fighting. Often we'd kiss and make up. But sometimes, I'd get an > > intractable, unforgiving, obsessive compulsive fixated asshole on my ass for > > years. It drove me out of comp.games.development.* for a time, the > > hierarchy I created. I got fed up with being told that I was a troll, > > seeing as how I'd been Newsgroup Proponent. What the hell is that, the > > ultimate trolling? I've never trolled in my life. Abrasive, argumentative, > > violent, sure. Trolling, never. > > Fair enough. But would you find it odd if you were to slip on over to > alt.culture.black and mention that you think affirmative action was a > mistake and people got riled up? That some of them would label you > racist? Of course not. In fact, if that were your position, you would > expect such a response and preemptively address that response before the > flamewar began. You should try the same thing with less volatile > topics. Instead of assuming that your point of view is obvious (it > isn't) or that people have read your posts in other groups (they > haven't), simply provide a supporting argument for such remarks. Trust > me, it goes a long way. > > > Anyways, a few years later I came back. I've been summarily killfiling > > people ever since. It does wonders for my long-term interaction with people > > and groups. I don't have to deal with the people I can't work with. > > That actually doesn't sound confrontational. In fact, IIWAP, I'd > probably label it passive aggressive. > > > > Personally I've never > > > killfiled anyone (not even the ruebot[!]) and to my knowledge, I've > > > yet to be > > > killfiled (although at times I'm a bit surprised at that, today being > > > one of those times). > > > > It's really very simple. Your behavior is not the same as other people's > > behavior. That's why we're still talking. > > > > > Why then, are you surprised when people choose to fight with you? > > > > Why do you say I'm surprised? This is all very predictable to me. Seen at > > this moment in time, you are a static type within this system. You just > > happen to be a benevolent, workable type. You are the "Well, are you going > > to killfile *me* too?" type. > > I'm just the type who finds the entire process rather boring. I enjoy a > good argument (heated or otherwise) a bit more than the next guy. > However, I find irrational behavior a big yawn. I see no point in > investing a lot of work trying to make someone look foolish who is going > to do the job on his own anyway. I respect people who make their > knowledge and work available to others without belittling them. I > respect people who are able to articulate their arguments whether I > agree with them or not. In general, I'm willing to give people the > benefit of doubt which is why I've never killfiled anyone. > > > The kind of person who doesn't behave in a way > > that I would killfile, and who doesn't quite understand how his behavior is > > different from the people I do killfile. But, who probably will understand > > by the time I get done explaining it. > > Actually, what surprises me is that several of the people you killfiled > are some of the more reasonable people on the list. I'm a little > concerned that I wasn't among them > > > Have you seen Enter The Matrix? The scene with The Architect is very > > profound. The Matrix demands Neo. Someone else observed, this stuff is all > > about young males. That's no accident, it's a feature of our genetics. Our > > genetics demand certain confrontations at a certain age. In our lives, we > > obey certain Grand Strategies, even if we are sapient and exercising choice > > over the details. > > > > > Taking your statements together > > > would seem to indicate that a fight is what you want. > > > > That's sorta true. This is really what I call a "posting binge," to avoid > > other things I don't want to be doing. > > So for entertainment value you stir up groups where people are trying to > help others get their jobs done? That might be a bit of a cheap shot, > as I doubt you consciously intended to initiate a wild flamewar, but > seriously, your binge took valuable time from people who others depend > on. When I post a question to c.l.py, it's usually because I've got > something I need done now and don't have a ton of time to tinker around > or RTFM. > > > I'm an intellectually violent > > person, I like a good debating scrap. But I've got Rules Of Engagement > > about what I think is appropriate, intellectually defensible debate. > > "You're a troll!" instead of hearing someone else's opinion ain't it. > > Ah, you've done the same, albeit in a different fashion. "You're a > troll" certainly doesn't constitute a grand argument. But your approach > is to selectively respond to arguments and sprinkle in the odd flamebait > (or, as you would label them: things people don't want to hear). This > is why I had you pegged (momentarily) as a clever troll. It appeared as > if you were using just enough reasonable debate to disguise the > unreasonable assertion. > > > Those > > people, I want to punish. It's irrational, because intellectually I know I > > can't actually change them. Rationally, I can killfile them. Possibly, I > > can stimulate cumulative change in the system, but I am uncertain of it. In > > 10 years maybe I will have let it go. > > This sounds good on the surface, and I can certainly understand phases > in one's life. Nevertheless, acknowledging a shortcoming doesn't excuse > it (please don't repeat that to my girlfriend, I don't want it used > against me later ). Besides, you are still assuming that it is > others who need to change. I can assure you that even were that so, it > is an exercise in futility. Until you can cease to react to others, it > is somewhat hypocritical to explain that they shouldn't react to you. > > > For instance, I'm reasonably sure I can stimulate minor change in your own > > static type. You understand enough of the dimensions already that you're > > capable of absorbing more of them. But you'll have probably gotten there on > > your own soon anyways, so am I really needed as a stimulus? > > That would assume that 1) I desire such change, and 2) that such change > would be desirable. > > > Actually, I suspect I'm not for your benefit, if I am for anyone's benefit. > > I suspect it is for someone who is lurking. Maybe someone who hasn't formed > > much of a world view yet. Mine, at any rate, is in my .sig. > > Well, certainly there is some benefit for someone, but I'm less than > certain that the lesson is necessarily what you would expect. > > > Regards, From adalke at mindspring.com Fri Aug 22 04:09:40 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Fri, 22 Aug 2003 08:09:40 GMT Subject: For Kenny Tilton: Why do I need macros revisited. References: <3f45484f$1_6@corp.newsgroups.com> <3F45A7BF.4060806@nyc.rr.com> Message-ID: <8dk1b.2825$Ej6.1159@newsread4.news.pas.earthlink.net> Kenny Tilton: > You are absolutely right. Metaclasses are killer. I am surprised > Pythonistas afraid of macros let them into the language! Speaking personally, I still haven't wrapped my head around them, and despite seeing Alex's talk about them, don't fully understand when to use them. I've seen David Mertz' xml_pickle code which makes good use of them, but don't yet follow how it works. > Lispniks have not seen code become unreadable because of macros. That is > something you all (well, most) are imagining. You are almost positing it > as given. And it is simply not so. Terry Reedy pointed out something from some Scheme documentation found by Dave Kuhlman: http://www.schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-3.html#%_sec_ Temp_4 ] As Scheme became more widespread, local dialects began to ] diverge until students and researchers occasionally found it difficult ] to understand code written at other sites. I cannot say if that's because of macros or other aspects of Scheme. People I know who used Lisp and loved macros reported that macros were a big part of dialecticazation. See previous posts of mine for full references. As I mentioned elsewhere, I have observational evidence that Lisp/Scheme do not promote community growth in my fields of interest - computational chemisty and biology - anywhere near as much as Perl, Python, Java, or Ruby. While I do not believe it's because of macros, I do belive it's because Lisp/Scheme's tendency towards increasing the flexibility and power available to a single programmer which reduces its usefulness in the sorts of development environments common to my field. That's not to say there can't be teams of Lisp programmers; just that the type of people who prefer Lisp are not usually biologists or chemists. > We have pointed out again and again > that macros are no harder to understand than functions or classes, but > no one addresses that point. What about Terry's comment, based on the above URL: ) Reading the third referenced page on Macros, I notice that the amount ) of syntax definition for the macro sublanguage is as large as a ) substantial portion (one-third?) of that for core Python (if condensed ) to the same density). So, just by definitional bulk, having it in the ) language would not be a free ride. > Strangely, quite a few of you have also conceded macros can leverage a > language. Leverage a language ... for what? And for whom? For smart people who can perceive the semantics directly, with little need for syntactical clues and who "don't look at anyone else's code (if you have to work on it, rewrite it anyway) and never show [their] code to anyone" then yes. For the things Python excels at, not necessarily. Andrew dalke at dalkescientific.com From dkuhlman at rexx.com Thu Aug 7 21:13:16 2003 From: dkuhlman at rexx.com (Dave Kuhlman) Date: Thu, 07 Aug 2003 18:13:16 -0700 Subject: Accessing c objects in python References: Message-ID: Gary wrote: > Hi- > > I've been searching the web for a while and I've been unable to > find a > way to access c data objects in python without using SWIG. I can > do > methods just fine but I can't access variables. It seems like > PyModule_AddObject should work but it segfaults my program. > There's a good chance I'm just using it wrong, or I should be > using something > else. Could someone give me a simple, complete example pretty > please? > Thanks! One way to solve this problem is to implement a new type for Python that "wraps" your C object. Then your Python code can create and manipulate instances of this new Python type. These Python objects in turn manipulate your C object/type. If that sounds like what you want to do, then read: http://www.python.org/doc/current/ext/defining-new-types.html In particular, look at: http://www.python.org/doc/current/ext/node22.html It contains an example that you can start with. Beginning by replacing "Noddy" with whatever you want to call your new data type. Then look at the struct at the top of that example. Put (a pointer to) you C object in that struct. Now modify the functions Noddy_new, Noddy_dealloc, and Noddy_init (which you have re-named, whatever). Next, add functions to get and set things in your C type. ... and keep on following the examples. Is there an easier way? I'm not sure, but I'd certainly read the following section of the Pyrex documentation. It's about how to wrap C structures: http://ldots.org/pyrex-guide/3-structures.html And, the part in the following about external extension types in Pyrex seems particularly appropriate: http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/version/Doc/extension_types.html Any Pyrex experts listening in? Am I on the right track here? Dave -- Dave Kuhlman http://www.rexx.com/~dkuhlman dkuhlman at rexx.com From fperez528 at yahoo.com Mon Aug 25 23:53:07 2003 From: fperez528 at yahoo.com (Fernando Perez) Date: Mon, 25 Aug 2003 21:53:07 -0600 Subject: Coloring print lines References: Message-ID: Sami Viitanen wrote: > Hello, > > Is there an easy way to make script print text with differents colors to > screen (shell)? > > I mean a script that can for example print lines in red if some error occurs > in executing > some information.. IPython (http://ipython.scipy.org) supports coloring for its own purposes, and comes with a module for this. You can simply import this module and use it for your programs. Besides, you may like ipython itself ;) Cheers, f. From christoph.lehmann at gmx.ch Tue Aug 26 06:53:12 2003 From: christoph.lehmann at gmx.ch (Christoph Lehmann) Date: Tue, 26 Aug 2003 12:53:12 +0200 Subject: need code-snippet for a simple dialog window in wxPython Message-ID: <1061895191.2881.65.camel@christophl> Hi I am a newbie and have a very simple python code, doing some calculations. maybe there is one already having a code snippet in wxPython for what I need: (i) simple dialog box, where the user can enter an integer. after closing the dialog I get this integer. nothing more (ii) similar for getting a file-name (with a file-dialog) thanks a lot christoph -- Christoph Lehmann From rganesan at myrealbox.com Wed Aug 6 08:11:37 2003 From: rganesan at myrealbox.com (Ganesan R) Date: Wed, 06 Aug 2003 17:41:37 +0530 Subject: managing stdout and stderr neatly while doing parallel processing References: Message-ID: >>>>> "Alex" == Alex Martelli writes: > Grant Edwards wrote: > ... >> 3) use a pseudo-terminal (pty) so that your child process is running in a >> more "natural" environment, and you'll get both stderr and stdout that >> way too. Don't know if there's handy Python "pty" module or not... > Well, there's http://www.python.org/doc/current/lib/module-pty.html , but > I'm not sure if it counts as "handy"? Dealing with the raw pty module is not fun. Use pexpect instead (See http://pexpect.sf.net) - it's built on top of pty module and is very easy to use. Ganesan -- Ganesan R (rganesan at debian dot org) | http://www.debian.org/~rganesan/ 1024D/5D8C12EA, fingerprint F361 84F1 8D82 32E7 1832 6798 15E0 02BA 5D8C 12EA From dl-notspam-rubin at yahoo.com Sun Aug 10 13:08:46 2003 From: dl-notspam-rubin at yahoo.com (Daniel) Date: Sun, 10 Aug 2003 10:08:46 -0700 Subject: unescaping xml escape codes Message-ID: <3F367C1E.FAE188C1@yahoo.com> I'm working with strings that contain xml escape codes, such as '0' and need a way in python to unescape these back to their ascii representation, such as '&' but can't seem to find a python method for this. I tried xml.sax.saxutils.unescape(s), but while it works with '&', it doesn't work with '0' and other numeric codes. Any suggestions on how to decode the numeric xml escape codes such as this? Thanks. -- To reply to me directly, please remove "_NoSpam_" from my email address From clifford.wells at comcast.net Wed Aug 27 02:53:29 2003 From: clifford.wells at comcast.net (Cliff Wells) Date: Tue, 26 Aug 2003 23:53:29 -0700 Subject: sending a byte on a socket In-Reply-To: References: Message-ID: <1061967208.23503.0.camel@devilbox.homelinux.net> On Tue, 2003-08-26 at 23:38, Daniel Timothy Bentley wrote: > Slamming my head against what should be an easy problem: > > How do I send a byte across an open, connected socket? > > Do I have to implement my own type that implements some method a string > normally does? > > Or is there some hidden encoding that will let me turn a byte into a > string? chr(byte) Regards, -- Someone shot nostalgia in the back, someone shot our innocence -Bauhaus From mis6 at pitt.edu Tue Aug 12 09:35:51 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 12 Aug 2003 06:35:51 -0700 Subject: Python vs. C# References: <2259b0e2.0308100616.55b651ca@posting.google.com> <3f36af20@shknews01> <2259b0e2.0308110433.204d7831@posting.google.com> <070hjvou8s33gvmom1t45t3avlkhudsstn@4ax.com> Message-ID: <2259b0e2.0308120535.330282ca@posting.google.com> Doug Tolton wrote in message news:<070hjvou8s33gvmom1t45t3avlkhudsstn at 4ax.com>... > "Brandon J. Van Every" wrote in message > news:<3f36af20 at shknews01>... >> I'm beginning to think that within 5 years, no new applications will >> be >> written in C++. > On 11 Aug 2003 05:33:38 -0700, mis6 at pitt.edu (Michele Simionato) > wrote: > > >?? Are you joking or what ?? Did you learn anything from Fortran lesson? > >Or from Lisp? Programming languages *never* die! > > Hey, watch the Lisp cracks!! :-P > > Seriously Lisp is the Mother of all programming languages. So much of > the features that are being implemented today come from Lisp it's not > even funny. If you want to see what they are, take a gander at Paul > Graham's website: > www.paulgraham.com > > Lisp seriously is my favorite language. It's still got quite a few > features that other lesser languages are working on implementing. I cited Fortran and Lisp because they are the oldest programming languages and they are still used. Of course, not by everybody. Only be the "hobbyists and cranks" according to Brandon van Every's terminology. Strangely enough, the "hobbyists and cranks" category includes most of the academical world. Fortran is still *very* hard to beat in its domain of application, number crunching, and its library support is simply incredible. It will never die (even if I see a definite trend in converting Fortran applications to C++, at least in my domain of expertise, High Energy Physics). About Lisp, it is simply the most powerful language ever invented for abstract thinking. It will never die, too. Nevertheless, I would use Scheme, not Lisp, if I had to choose. But I don't have to choose, since Python does already everything I want ;) Michele From adalke at mindspring.com Fri Aug 1 18:51:12 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Fri, 1 Aug 2003 16:51:12 -0600 Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> <3F2A35A1.2040403@klix.ch> Message-ID: Gerald Klix: > IHMO it is the lambda expression. > These "functions" are not real functions. You can not use > statements in them. True. That's why they are "lambda expressions" and not "lambda functions" (Okay, that was a cheap shot ... but still true ;) Andrew dalke at dalkescientific.com From Spam.Buster at web.de Sun Aug 24 06:31:38 2003 From: Spam.Buster at web.de (Lars Behrens) Date: Sun, 24 Aug 2003 12:31:38 +0200 Subject: How to store data? In-Reply-To: References: Message-ID: John Roth wrote: > Python 2.3 has an excellent CSV module. Thx, I'll talk to my admin if upgrading would be possible. Cheerz Lars From skip at pobox.com Fri Aug 1 01:27:23 2003 From: skip at pobox.com (Skip Montanaro) Date: Fri, 1 Aug 2003 00:27:23 -0500 Subject: A very simple question In-Reply-To: References: Message-ID: <16169.64059.271570.28131@montanaro.dyndns.org> Arnaldo> class abc: Arnaldo> x = 100 Arnaldo> y = 200 Arnaldo> z = 300 x, y and z are attributes of the class, not of instances of the class. Try printing abc.__dict__. Skip From ialbert at mailblocks.com Thu Aug 21 21:30:24 2003 From: ialbert at mailblocks.com (Istvan Albert) Date: Thu, 21 Aug 2003 21:30:24 -0400 Subject: crazy programming language thoughts In-Reply-To: References: Message-ID: <-5SdnWETctL179iiU-KYgw@giganews.com> Ryan Lowe wrote: >>>>v = read lines from 'file.txt'; join it with '\n'; lower it; split it at '.' A distinction needs to be made between a programming language that resembles pseudo-code and a language that looks like a spoken language. split line at '\n' is no better than line.split("\n") after all then you could argue that you should be able to say "'\n' is the splitting character in line" or "break into pieces at '\n'" and so on. For what is worth perl was always developed along the lines you are talking about. See more here. http://www.perl.com/pub/a/2003/06/25/perl6essentials.html Now whether that is a good thing is very debatable and the mere fact that I'm posting in a python group pretty much tells who do I vote for. Istvan. From aleax at aleax.it Thu Aug 28 08:41:19 2003 From: aleax at aleax.it (Alex Martelli) Date: Thu, 28 Aug 2003 12:41:19 GMT Subject: Celebrity advice (was: Advice to a Junior in High School?) References: Message-ID: Colin J. Williams wrote: ... >> " Every political choice ultimately reduces to a choice about when and >> how to use lethal force, because the threat of lethal force is what >> makes politics and law more than a game out of which anyone could opt >> at any time." ... > We seem to be straying from Python and/or advice to a your person, but > the third paragraph is clearly nonsense. Not necessarily. I suggest going to essayists on a similar theme that are of a lesser "polemist" inclination and more of a "deep thinker" one, such as Economics Nobel prize-winner Friedrich von Hayek: I think he makes one of the best presentations of the classic theme of government being about instituting a commonly agreed "monopoly of violence" and all that follows from it. Hobbes was the first (IMHO) to state this out clearly in modern times (although for contemporary readers this more general theme may be made harder to see by Hobbes' defence of the specific political form "Absolutism" as THE way to achieve this), and you can also find some tangential treatments in (e.g.) Betham and John Stuart Mills (as well as in thinkers of a completely different stripe such as Friedrich Engels and Mao Tse Tung), but I think Hayek has the most lucid, "neutral" presentation. Of course making this argument about POLITICS rather than about GOVERNMENT does require restricting the meaning of "politics" quite specifically (and etymologically) -- "office politics" isn't about government, nor is (e.g.) the kind of organizational politics that may take you to the top of volunteer organizations such as a charity or a bocce club. But if by politics we mean, strictly, politics connected with determining government and laws, then the point is well made, if deep. To see it clearly you have to reason about, what does it mean that something is LAW rather than just a convention, common sense, or good manners. The difference is that, if it's law, then, ultimately, breaking it carries an implicit threat of potentilaly lethal force (in most cases through stages, e.g. you could first be fined, then if you refuse to pay your fines they could try to take away your possessions such as a car, if you defend your car they'll try to stick you in jail, if you resist arrest effectively enough you may end up being shot in the resulting firefight). For example, consider the following issue: > To give an example. In Canada, over the next year or more, the Members > of Parliament and the Senators will have to make a choice as to whether > gay marriage is to continue in this country. No threat of force exists. > A decision will be made and the populace will accept it as being more or > less democratic. What does it mean for the government to say that the union of two men can (or cannot) legally be "marriage" rather than "just a de facto union"? It means such a union confers rights and therefore obligations on various parties and that the government implicitly threatens all of its usual levels of reprisal (ultimately backed by its hoped-for monopoly in organized use of lethal force) against violators of the law. Say that A and B are [a] married or [b] just de facto "together". A lies dying in a hospital and B wants to visit A on hir deathbed. In case [a] the government forces the hospital to admit B; in case [b] there is no such obligation and most hospitals will in fact not admit visitors that are unrelated to the patient into some sections in which close relatives (including spouses) WOULD be admitted (wiht all due precautions, of course). So, in case [a] (legal marriage), B can get a court order if the hospital staff blocks B's entry, and if the hospital does not respect the court order in the end police will enforce it... all the way to threat or even use of legal force if necessary. If a law is not mere words, with no pragmatical side to them, it must eventually rest on that same implied promise (to the holders of rights conferred by the law) and threat (to the holders of obligations imposed by the law, were they to persistently flout and resist the obligations). Of course, if Hayek is correct, then saying that we do NOT want the government to have the monopoly of lethal force is exactly equivalent to saying we do not want effective government (Hobbes would surely argue that way) -- we prefer deliberately-hobbled government to government that is maximally effective. In this day and age it's hard to make a case for deliberately inefficient arrangements, although it IS possible to do so (e.g., the mandatory trailing ':' in the head clauses of several Python statements;-). People who don't want ID cards to exist, don't want government DB's to be cross-linked, etc, plead much the same case -- they prefer inefficient government (whose inefficiencies may help terrorists and other criminals) to efficient government (whose efficiency might allow more effective oppression). Alex From andreas.kuntzagk at mdc-berlin.de Fri Aug 1 09:59:37 2003 From: andreas.kuntzagk at mdc-berlin.de (Andreas Kuntzagk) Date: Fri, 01 Aug 2003 15:59:37 +0200 Subject: string/file manipulation simple References: Message-ID: > I was just creating an encryption/ decryption program in python, ive got > no problem with the algothims or anything like that. my only difficulty is > how to i take a file and read in each charecter and then preform and > operation to it and then output it to another file, basically i just wanna > know how to take a string and then perform actions to each charecter For example like: def code_func(c): # something clever return new_c result = "".join(map(code_func,my_string)) #if code(c) returns a string or result = "".join([str(item) for item in map(code_func,my_string)]) or you could do: resultchars="" for c in my_string: # some computation resultchars.append(result) result = "".join(resultchars) (Beware: untested code) Andreas From altis at semi-retired.com Sun Aug 10 15:32:59 2003 From: altis at semi-retired.com (Kevin Altis) Date: Sun, 10 Aug 2003 12:32:59 -0700 Subject: stop the presses - AMK is licensed to drive! Message-ID: <5%wZa.39$DH3.41178@news.uswest.net> Is this part of the PSU master plan? ;-) http://www.amk.ca/diary/2003/08/09.html#2003-08-09-1 ka From jjl at pobox.com Fri Aug 15 18:36:55 2003 From: jjl at pobox.com (John J. Lee) Date: 15 Aug 2003 23:36:55 +0100 Subject: ftp get from a Tkinter gui: advice wanted References: Message-ID: <87zniar1iw.fsf@pobox.com> "Russell E. Owen" writes: > I'm writing a Tkinter app (telescope remote controller). The application > presently runs on unix and MacOS X and I think some users will want to > use Windows. It's going just fine, but I'm trying to add the ability to > automatically get images via binary ftp (i.e. as each image is recorded) > and am realizing it's harder than I though. > > Ideally, I'd like image download to work like a typical web browser > download: a status window that shows each transfer, how far along it is, > allows the user to cancel it, etc. [...] Not sure what "as each image is recorded" refers to, but if you want to grab files via ftp, is there anything wrong with (in a separate thread, I suppose): import urllib2 urllib2.urlopen("ftp://ftp.example.com/pub/rhubarb.txt") ? At a lower level, there's ftplib of course. If you don't mind pulling in more code, no doubt Twisted could do this just as simply too, and, I imagine, wouldn't need to use a separate thread (never used it, but I know it has support for various common GUI event loops). John From mwh at python.net Tue Aug 5 11:45:54 2003 From: mwh at python.net (Michael Hudson) Date: Tue, 5 Aug 2003 15:45:54 GMT Subject: Contiguous memory blocks References: <3F2FC66D.1070000@comcast.net> Message-ID: <7h3adao85xo.fsf@pc150.maths.bris.ac.uk> panbru writes: > I'm doing some native code stuff and want to pass continguos memory > blocks of data back and forth between Python and C, with the memory > blocks modifiable in both realms. What is a good way to do that? array.array, or something from NumPy. > As I understand it, "buffer interface" objects (e.g. strings or > arrays) won't work because memory is not guaranteed to be > continguous. Ignore this: in practice, all objects that implement the buffer interface are in fact contiguous ('single segment' in the buffer interfaces terminology) and if you were so foolhardy as to implement the buffer protocol and claim to have more than one segment, I don't think anything (in the Python core) would actually work with your objects. Just a piece of historical cruft, AFAIK. Cheers, mwh -- Never meddle in the affairs of NT. It is slow to boot and quick to crash. -- Stephen Harris -- http://home.xnet.com/~raven/Sysadmin/ASR.Quotes.html From vanevery at 3DProgrammer.com Tue Aug 12 14:56:07 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Tue, 12 Aug 2003 11:56:07 -0700 Subject: Python vs. C# References: Message-ID: Andrew Bennetts wrote: > On Tue, Aug 12, 2003 at 02:03:58AM -0700, Brandon J. Van Every wrote: >> Joe Cheng wrote: >>> >>> Python has dynamic strong typing. So, if you can keep the types of >>> your objects straight without the help of the compiler, you get the >>> benefits of a concise syntax while enjoying type safety at runtime. >> >> And how, in a large scale industrial systems context, are you >> supposed to ensure that Joe Programmer doesn't in fact screw it up? > > By writing tests. Compiler checking is a kind of test that is done for you all the time, without you having to reimplement it over and over again. I agree that people should write tests, but having written many, many of those for my own project, it is equally true that writing test cases slows down development. Anything that provides testing "for free" is a boon. > Besides, if you don't trust the "Joe Programmer"s of your team to > write code competently, I suspect your project is doomed already. Big projects are filled with the bell curve. Not to mention stress under deadlines, which ruins the code of even good programmers. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From dave at pythonapocrypha.com Mon Aug 18 23:38:21 2003 From: dave at pythonapocrypha.com (Dave Brueck) Date: Mon, 18 Aug 2003 21:38:21 -0600 Subject: Design idea for Ping Application In-Reply-To: <1061263809.5430.49.camel@localhost.localdomain> References: <4378fa6f.0308181546.548daff7@posting.google.com> <1061263809.5430.49.camel@localhost.localdomain> Message-ID: <200308182138.21042.dave@pythonapocrypha.com> On Monday 18 August 2003 09:30 pm, Jeremy Hylton wrote: > On Mon, 2003-08-18 at 19:46, Marc wrote: > > So how can I get information back from the ping pipe without waiting > > for it to finish? I'm also open to other solutions if anyone has come > > across something like this before. > > Years ago I wrote ping in Python. I don't have the code anymore, but > there's not too much too it. I downloaded it today, what a coincidence! http://www.python.org/~jeremy/ping.tar.gz It needs a little tweaking to work with modern Python, but the info it contains is still probably useful to the OP. Thanks for writing it way back then... -Dave From gerson.kurz at t-online.de Fri Aug 29 12:42:19 2003 From: gerson.kurz at t-online.de (Gerson Kurz) Date: Fri, 29 Aug 2003 16:42:19 GMT Subject: win32sh in win32all Message-ID: <3f4f81f4.9510015@news.t-online.de> I was looking for a way to call ShellExecuteEx() in python (from W2K), and found win32sh, but it seems to be active only in PythonCE. Any idea why? Plus, I found the source http://www.murkworks.com/Research/Python/PythonCE/PythonCEWiki/uploads/win32sh.cpp but not any associated project. For else I would probably try to roll my own win32sh version for win32. From cnetzer at sonic.net Sun Aug 31 16:15:11 2003 From: cnetzer at sonic.net (Chad Netzer) Date: Sun, 31 Aug 2003 13:15:11 -0700 Subject: list.sort(func) speed In-Reply-To: <20030831190745.GH9311@incise.org> References: <20030831190745.GH9311@incise.org> Message-ID: <1062360910.1852.44.camel@adsl-209.204.179.133.sonic.net> On Sun, 2003-08-31 at 12:07, mackstann wrote: > > Personally, I would go with a Song class, where the artist, length etc. > > could successively be added, but that would rather be trading speed for > > features... > > Yeah, I have thought about it, and it would definitely be the more OOPey > way to go, but I figured that anyone using this with 20,000 files would > get a little grumpy at the speed hit. :) There is nothing about using a class that will make your program inherently slow, as long as you use the right algorithms. A data set of 20,000 is *small* by todays standards. Sorting it should be trivial and near instantaneous using decorate-sort-undecorate. Once it is sorted, you just keep the list sorted by doing insertions in sorted order (a very fast operation). Is there a reason you need to do lots of re-sorts? Perhaps you can use a dict to hold your data. You can also extract all the keys you need to sort on, ahead of time, and keep it paired up with you data class or dictionary. This will make decorate-sort-undecorate easy to code, and very quick to execute. And you still have a flexible, easy to use data type. I'd strongly suggest you not avoid dicts or classes, just to try to speed up your code. Almost all the time, they do not impair performance. And if you complicate your design by avoiding them, you are putting yourself through unneeded pain. -- Chad Netzer From jacek.generowicz at cern.ch Thu Aug 21 08:09:21 2003 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 21 Aug 2003 14:09:21 +0200 Subject: C++-sig problems ? Message-ID: Has anyone else experienced problems in submitting articles to the C++-sig? I've tried both via Gmane, and directly via mail, without success. Eventually I got the following back: ----- Transcript of session follows ----- ... while talking to mail.python.org.: >>> RSET <<< 421 mail.python.org: Too many concurrent SMTP connections; please try again later ... Deferred: Connection reset by mail.python.org. Warning: message still undelivered after 4 hours Will keep trying until message is 3 days old From ktilton at nyc.rr.com Thu Aug 21 12:25:17 2003 From: ktilton at nyc.rr.com (Kenny Tilton) Date: Thu, 21 Aug 2003 16:25:17 GMT Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> <6dj2kv8ugkieehs7guh786cl40o5lj6mcs@4ax.com> <599a6555.0308202108.397bb1a0@posting.google.com> Message-ID: <3F44F33D.4010201@nyc.rr.com> Anton Vredegoor wrote: > IMO there is a strong tendency towards unification and standardization > among the readers of this newsgroup and the need to conform and the > rewards this brings are well understood. Your comment reminds me of a brouhaha over the legendary IF* macro (search comp.lang.lisp via Google). A fellow cooked up (IF* [THEN] ... ELSE or ELSE-IF ... END-IF), and then used it in a big package his employer released (so you had to go find the macro!). He took a little heat for that, the gist being, "if you want to use Basic, use Basic." Unrelated to macros, on Google you'll also see yours truly getting eviscerated for using camelCase. "Dude, we use hyphens". So, yeah, yer technically opening up the floodgates, but the social pressure is pretty effective at keeping Lisp Lispy and would be at keeping Python...Pythonic? -- kenny tilton clinisys, inc http://www.tilton-technology.com/ --------------------------------------------------------------- "Career highlights? I had two. I got an intentional walk from Sandy Koufax and I got out of a rundown against the Mets." -- Bob Uecker From tzot at sil-tec.gr Tue Aug 19 23:10:19 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Wed, 20 Aug 2003 06:10:19 +0300 Subject: Py2.3: Feedback on Sets References: Message-ID: <42n5kv02867rn9skagsdie9ucg11ki30g8@4ax.com> On Tue, 12 Aug 2003 06:02:17 GMT, rumours say that "Raymond Hettinger" might have written: [replying only to those that I have something substantial to say] >* Is the support for sets of sets necessary for your work > and, if so, then is the implementation sufficiently > powerful? I have used sets in: - Unix sysadm tasks (comparing usernames between passwd and shadow, finding common files in sync requests et al) - a hangman game (when the computer guesses words, to continuously restrict the possibilities based on the human input) - an image recognition program (comparing haar coefficients) These come to mind at the moment, but I have used them even in the python command line; and mostly I care about intersections. >* Does the performance meet your expectations? In the game and image recognition programs I could use more power;-) >* Are sets helpful in your daily work or does the need arise > only rarely? I use them often, it's a very helpful construct. >User feedback is essential to determining the future direction >of sets (whether it will be implemented in C, change API, >and/or be given supporting language syntax). Reimplementation in C sounds appropriate, and supporting language syntax would be nice. A quick thought, in the spirit of C implementation: there are cases where I would like to get the intersection of dicts (based on the keys), without having to create sets from the dict keys and then getting the relevant values. That is, given dicts a and b, I'd like: >>> a & b # imaginary to mean >>> dict([x, a[x] for x in sets.Set(a) & sets.Set(b)]) # real You may notice that a&b wouldn't be equivalent to b&a. Perhaps the speed difference would not be much; I'll grow a function in dictobject.c, run some benchmarks and come back with results for you. Another thought: it is unfortunate that an intersection *has* to be through continuous lookups (talking about the ordering of dict keys re their hash values, I'll have to delve into dictobject.c it seems), even taking into account the great speed of key lookups... although building the result dict should account for more processing cycles than the comparisons; and in some cases doing a dict.copy() and then removing the uncommon elements would be faster. Hm, food for thought, and no more than two hours to sleep now. Another slogan: Python keeps your mind awake (and c.l.py keeps your body away from bed :) -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From hwlgw at hotmail.com Mon Aug 25 15:04:43 2003 From: hwlgw at hotmail.com (Will Stuyvesant) Date: 25 Aug 2003 12:04:43 -0700 Subject: ANN: BlackAdder V1.0.0 References: <3f48a498$3$219$fa0fcedb@lovejoy.zen.co.uk> <1Kj2b.61523$bo1.38258@news-server.bigpond.net.au> Message-ID: > [Shawn Gordon] > ...We had just hired a marketing person last week > ... > (tries to sell something again) > ... You need a better marketing person. No, sorry, my price has just gone up. -- We have not, however, passed out of the Net's magic period. It's still more potent to say, of some bit of information, "I found it on the Internet," than to say, "I read it in a book." Case in point: this newspaper recently began publishing, at the bottom of news stories, Internet addresses deemed in some way to be relevant to the subject. Can anyone remember _The Globe_ or any other daily paper showing such bibliographic regard for books? -- Robert Everett-Green From bsprajc at pacbell.net Sun Aug 3 01:19:43 2003 From: bsprajc at pacbell.net (Barry Sprajc) Date: Sun, 03 Aug 2003 05:19:43 GMT Subject: _socket / SocketServer / Mandrake Linux problem / Python 2.3 Message-ID: Anybody run into trouble and find a solution importing 'socket'? I've rebuilt, and reinstalled, but cannot find a _socket.py, _socket.pyo, or _socket.pyc in the lib directory. ( I suspect that's what socket.py is looking for? ) Thanks for any help. /barry sprajc Error below..... [root at rooster root]# python /usr/lib/python2.3/socket.py Traceback (most recent call last): File "/usr/lib/python2.3/socket.py", line 44, in ? import _socket ImportError: No module named _socket From graham.bloice at trihedral.com Tue Aug 5 08:06:17 2003 From: graham.bloice at trihedral.com (Graham Bloice) Date: 5 Aug 2003 05:06:17 -0700 Subject: Python vs PHP References: <3F094FA4.9030800@ploiesti.astral.ro> <3F0C8A87.8070505@removeme.free.fr> Message-ID: <4e2216a.0308050406.18edeb@posting.google.com> Bruno Desthuilliers wrote in message news:<3F0C8A87.8070505 at removeme.free.fr>... (snip) > Too bad I can't afford Python-powered hosting) See http://www.34sp.com". I've used them for two years and are excellent value at GBP 15.00 per year. Graham From bgailer at alum.rpi.edu Wed Aug 6 12:23:59 2003 From: bgailer at alum.rpi.edu (Bob Gailer) Date: Wed, 06 Aug 2003 10:23:59 -0600 Subject: makepy must be run after restart of pythonwin In-Reply-To: <006901c35c2b$b47e6fc0$0d00a8c0@maitai> Message-ID: <5.2.1.1.0.20030806102056.02b853a8@66.28.54.253> At 05:02 PM 8/6/2003 +0200, bk wrote: >hi, > >i'm using pythonwin 2.2.3 >my programm reads and write the outlook-adress book using COM. for this i >have to use the makepy utility. after i have run the utiltity everything is >fine and i can run my py-file without any errors. >but if i close the pythonwin and restart and then try to run my py-script i >get the following error: > >File "C:\Program Files\Python22\contacts_ausgabe.py", line 45, in >DumpDefaultAddressBook > folder = >mapi.GetDefaultFolder(win32com.client.constants.olFolderContacts) > File "C:\PROGRA~1\Python22\lib\site-packages\win32com\client\__init__.py", >line 168, in __getattr__ > raise AttributeError, a >AttributeError: olFolderContacts I suggest you examine the attributes of win32com.client.constants. Perhaps there is a case sensitivity issue. makepy can cause attributes that were previously case insensitive to become case sensitive. I also recall somewhere a discussion about win32com.client.constants not being populated immediately. Consider waiting a moment after dispaching. Bob Gailer bgailer at alum.rpi.edu 303 442 2625 -------------- next part -------------- --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.506 / Virus Database: 303 - Release Date: 8/1/2003 From s0199583 at sms.ed.ac.uk Fri Aug 8 07:04:27 2003 From: s0199583 at sms.ed.ac.uk (Matt Smith) Date: 8 Aug 2003 04:04:27 -0700 Subject: problems with python: pywintypes.com_error Message-ID: <5f5c82ec.0308080304.495fb03b@posting.google.com> Hi all, I am VERY new to python , 3 days to be exact, but as I have been programming competently in Perl and C/C++ for a while now, I thought it would be a simple case of relearning the syntax, and in many ways it has been just that. However last night as I was just about to leave work, when I came across an error message I had never seen before. Not only that but it appears that there is very little in the way of help in all the usual sources of information on the internet (i.e. newsgroups and forums and the like) So to the problem at hand... I am calling a program called v2wreg (its a program for interfacing with the registers/parallel port, used, unfortunatly i think exclusivly, by the company I work for), I can load the program fine, but when I come to use any of its advanced featurs i.e. SetDeviceAddress or ReadRegister I get the same type of error message. i.e. File "", line 2, in MakeConnection pywintypes.com_error: (-2147352571, 'Type mismatch.', None, 1) When I commented out the first line I knew was giving an error, I got the another pywintypes.com_error from the next line in my code to use a feature of v2wreg? Are these errors connected? I have looked about abit and there has been some mention of programs not being registered properly generating pywintypes.com_error errors is there anyway I can check what is meant to be registered? Any light anyone could spread on this subject would be very helpful Thanks in advance, Matt Smith, 2nd year Electronic & Electrical Engineer at Edinburgh University. p.s. here is part of my code with the affected area serialBusToolv2wReg = win32com.client.Dispatch ("v2wreg.Application") ##this line works and calls the app minimumDesiredVersion = 142 appVersion = serialBusToolv2wReg.QueryVersion ##this line also works and it calls a feature of the program serialBusToolv2wReg.Maximize = 10 ##this line works also if((appVersion) < minimumDesiredVersion):print"error" else: print "app version is working well....'yaaay'" serialTransportParameters = [] PciCardId = 0 if(self.transpor == 'pci'):serialTransportParameters=["VPCI" (65536+PciCardId), 0] elif( self.transpor == 'parallel'):serialTransportParameters= ["VPLL",1,0] else: print "eeek..error" if(self.protocol == 'i2c'):serialTransportParameters.insert (0, 0) elif(self.protocol == 'cci'):serialTransportParameters.insert (0, 1) elif(self.protocol == 'v2w'):serialTransportParameters.insert (0, 0) else: print "error......." print "serialTransportParameters->", serialTransportParameters success = serialBusToolv2wReg.MakeConnection (serialTransportParameters)###this line is where the error appears if not (self.deviceAddress == -1): serialBusToolv2wReg.SetDeviceAddress = self.deviceAddress ##this line also returns a pywintypes.com_error error serialIndex = win32com.client.pythoncom.VT_VARIANT = 0 serialValue = win32com.client.pythoncom.VT_VARIANT = 0 serialAutoInc = win32com.client.pythoncom.VT_VARIANT = 0 success = serialBusToolv2wReg.ReadRegisterNoWrite (self.deviceAddress, serialIndex, serialValue, serialAutoInc) if ((success == 0) or (serialValue = 'read failed') : print "read error booo \n" break else: print "\n error" print success From yinyang at eburg.com Tue Aug 12 19:45:43 2003 From: yinyang at eburg.com (Gordon Messmer) Date: Tue, 12 Aug 2003 16:45:43 -0700 Subject: IO timeout in threaded application In-Reply-To: <3F3923EC.9000703@eburg.com> References: <3F37EB6E.4080306@real.com> <16183.61048.228691.131382@montanaro.dyndns.org> <3F3923EC.9000703@eburg.com> Message-ID: <3F397C27.9030003@eburg.com> Gordon Messmer wrote: > The other approach I'd thought about would be to open a pipe and fork a > process to do the check. The external process could handle signals > properly. This almost works right, except that the new pid ends up as a zombie... Why doesn't the main thread reap the status of this process? I don't get zombies if I start a thread and use os.system() or os.popen2() (both of which should also fork & exec): >>> def test2(): ... child=os.fork() ... if not child: ... print "newpid", os.getpid() ... time.sleep(30) ... print 'returning from test2' ... os._exit(0) ... >>> import thread >>> thread.start_new_thread( test2, () ) 1125342512 >>> newpid 21072 returning from test2 $ ps axfm| grep python 21060 pts/2 S 0:00 | \_ python 21072 pts/2 Z 0:00 | \_ [python ] From irmen at -NOSPAM-REMOVETHIS-xs4all.nl Sat Aug 23 15:08:55 2003 From: irmen at -NOSPAM-REMOVETHIS-xs4all.nl (Irmen de Jong) Date: Sat, 23 Aug 2003 21:08:55 +0200 Subject: Python is darn fast (was: How fast is Python) In-Reply-To: <3F47AA73.7040104@draigBrady.com> References: <2259b0e2.0308230737.8a9bc1c@posting.google.com> <3F47AA73.7040104@draigBrady.com> Message-ID: <3f47bbc3$0$49114$e4fe514c@news.xs4all.nl> P at draigBrady.com wrote: > try a 3.x series gcc with the appropriate -march=pentium3 > You'll be pleasently surprised. In my other reply I mentioned that I still get a Python+Psyco advantage of 30% over a gcc 3.2.2 compiled version. My gcc is doing a lot better than Michele's reported 50% difference, but Python+Psyco still wins :-) --Irmen From tub4jxr at hotmail.com Tue Aug 26 01:56:32 2003 From: tub4jxr at hotmail.com (Jose Rodriguez) Date: 25 Aug 2003 22:56:32 -0700 Subject: Advice to a Junior in High School? References: Message-ID: <89302408.0308252156.18ece8ce@posting.google.com> Really hate to say this but.... I agree with another post in that you should look into a real field where you might be able to use the computer 'hobby' aspects of it in your field. For instance, be a doctor such as an oconologist, radiologist, or ear-noste-throat. These are great, high paying positions that are becoming extremely computer intensive. I look at it from the standpoint of practicality.... you'll never want for a job since there has been a demand in most sections of the country for the last 30+ years, you'll get paid a ridiculous salary, and have a normal work week of 25 - 50 hours. Enjoy the Porchse, the yacht, and the time to focus your skills in programming. From moncho.leon at gmx.net Tue Aug 19 15:05:25 2003 From: moncho.leon at gmx.net (Ramon Leon Fournier) Date: Tue, 19 Aug 2003 21:05:25 +0200 Subject: Brandon's abrasive style (was Re: What's better about Ruby than Python?) References: <38ec68a6.0308172319.431a4fde@posting.google.com> Message-ID: Brandon J. Van Every wrote: > - Python is not a good language for low-level 3D graphics problems. C++ is > better. Well, not just for low-level 3D graphics. There are many other things you would not code in Python unless you are a complete fool. Your companies mail server, for instance. But you wouldn't do that in C# either. Though there probably *are* people or companies who would even manage to sell such stuff. Wonderful Windows world. > - Python isn't a rapid prototyping godsend for every problem out there. But let me ask you, what is it that you are actually looking for? A language for each and "every problem out there"? Can there be such a thing? I doubt. For me, it's just one out of about three 1/2 languages I use for my daily work (that is, Python, C/C++, Bourne-Shell, in that order, plus a bit of Fortran where it really can't be avoided). I find that Python is very handy and I may say that I now use it for more than 50% of my work. But I wouldn't unnecessarily force myself to use it for everything. > - Microsoft C# and .NET are strategic threats to Python's prosperity and > vitality, if not survival. Only time will tell. But let's face it: For Python it will be difficult to stand against the massively advertised, fashionable M$ products, that everybody believes (s)he needs. Under Windows, of course. Unix is a different domain. > - Yet unnamed languages are capable of taking Python's place on the food > chain. Let's not speculate. Let them come. We'll evaluate then. > - You have to promote your language, grow its market share, to prevent that > from happening. Granted that my motivation to use Python is different from that of many others here. I have work to do, and to finish it as quickly as possible. I figured that Python is a great language for people like me, who are not full-time programers but who need an easy to learn language for daily quich-and-dirty scripting. Thus, it doesn't matter to me if Python has 1 or 10 Million users. Though I am happy about every colleague I can "convert". Because I know from experience that it's a good thing and that for others it may be as good as it has proven for myself. That doesn't necessarily mean that there is nothing better out there. In the environment that I am working in (a M$ free one), Python is a good choice. Possibly Ruby would be about as good, and despite of having looked at both, I liked Python a lot more, but that's more a matter of my personal taste. I also used Perl from time to time but never got to like it. In contrast to Python. > These analyses are called "sanity" in the Windows world. It's Reality On > The Ground. It's really odd to come to a developer community where people > are insular and freak out about these kinds of pronouncements. It makes > Windows people wonder if Python people are capable of industrial relevancy. As stated, I don't care. If one day I have to learn C# or .NET, it'll be early enough. But unless I am forced to, I happily stay away from it. > The rest of you: wake up! Smell the Windows! I never particularly liked that stench. Do you? BTW: What exactly has "Smell the Windows" to do with the current Ruby vs. Python debate? Are you actually serious about learning any of these, or are you trying to convince yourself that it was right not to ever try them out? Your attitude reminds me of somebody not wanting to try the taste of say, cheese, because it smells so bad, doesn't look great, etc. But who always goes into the swiss restaurants asking around "What's so good about cheese, why don't you better eat potatoes?" What will the people tell that guy? I am not saying that you are trolling, and in the recent discussions you actually made some good points. But you obviously lack the sincere will to actually become able to make a competent judgement yourself. That's annoying. Ram?n -- Horum omnium fortissimi sunt Costarricenses From aleax at aleax.it Thu Aug 7 08:30:06 2003 From: aleax at aleax.it (Alex Martelli) Date: Thu, 07 Aug 2003 12:30:06 GMT Subject: Need to convert an arbitrary byte-pair to an int. References: <3f323dc2$0$10775$afc38c87@auth.uk.news.easynet.net> Message-ID: Graham Nicholls wrote: > I'm trying to size a jpeg file. The file size is held in a short (2 byte > integer) at a certain offset. Once I've found these two bytes (they're in > MSB,LSB order), I need to convert them to an integer - now I know that in > C I'd just cast a pointer to the offset to a short, and that python > doesn't > cast, so how can I extract the value from a stream of bytes. I've looked > at python.org/Doc/current (I'm using 2.3b1), but can't find anything > obvious. I see you've already been pointed to a 3rd party package that's useful for handling images, but just in case you to need to solve in the future the actual problem you pose in the subject, one elementary way might be: thefile = open('whatever', 'rb') thefile.seek(theoffset) msb = thefile.read(1) lsb = thefile.read(1) theint = ord(lsb) + ord(msb) * 256 The struct module, which I see has also been pointed out to you already, would let you compact the last three statements into one. So, in this specific case, would the array module. Both struct and array are part of the standard Python library and often come in handy for occasional needs of low-level access, such as this. Alex From bdesth.nospam at removeme.free.fr Tue Aug 19 08:32:17 2003 From: bdesth.nospam at removeme.free.fr (Bruno Desthuilliers) Date: Tue, 19 Aug 2003 14:32:17 +0200 Subject: What's TOTALLY COMPELLING about Ruby over Python? In-Reply-To: References: <3F412484.69867AED@alcyone.com> <3f415560$0$1124$626a54ce@news.free.fr> Message-ID: <3f4216a3$0$16514$626a54ce@news.free.fr> Ganesan R wrote: >>>>>>"Bruno" == Bruno Desthuilliers writes: > > >>Istvan Albert wrote: >> >>>Erik Max Francis wrote: >>> >>> >>>>>What's ***TOTALLY COMPELLING*** about Ruby over Python? >>>> >>>>comp.lang.ruby doesn't have Brandon Van Every. >>> >>>LOL >>> > > >>LOL 2 > > >>Bruno >>(yes, I want to be in Brandon's killfile. It's the new game on clp : >>being in Brandon's killfile. Just imagine what will happen when every >>clp regulars will be in Brandon's kill file...) > > > I am not a clp regular (mostly a lurker), but I also wanna play. *please* > > ;-). > > Ganesan Easy : answer to any post from Brandon, singing 'Brandon is a troll, is a troll, is a troll' !-) Bruno From fredrik at pythonware.com Mon Aug 11 08:08:44 2003 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 11 Aug 2003 14:08:44 +0200 Subject: Python vs. C# References: <20E0F651F8B82F45ABCBACC58A2D995B0518B8@mexper1> <5.2.1.1.0.20030811052947.02bf7ea8@66.28.54.253> Message-ID: Bob Gailer wrote: > What is "trolling"? http://www.catb.org/~esr/jargon/html/T/troll.html http://www.wikipedia.org/wiki/Internet_troll From tzot at sil-tec.gr Fri Aug 29 08:46:03 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Fri, 29 Aug 2003 15:46:03 +0300 Subject: Burn some books (please)... References: <6e07b825.0308281841.321bda3@posting.google.com> Message-ID: <9oiukvgbretevpadrh085d4kopep3a08tb@4ax.com> On 28 Aug 2003 19:41:24 -0700, rumours say that yaipa at yahoo.com (yaipa h.) might have written: >As a way of saying thanks, I purchased two copies of your fine book. >One for myself and one for our local library. I'm waiting for the bbqback version. :) -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From fredrik at pythonware.com Thu Aug 7 08:16:04 2003 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 7 Aug 2003 14:16:04 +0200 Subject: Getting output from executed command that is not STDIN References: Message-ID: Sami Viitanen wrote: > I'm using os.popen and read for reading command input to string but the > string doesn't contain the same output that running the command manually or > with os.system contains. > > with os.system: > cvs server: Diffing //Project1 > File //Project1/testiware.txt is new; current revision 3.13 > File //Project1/what_is_version_control.txt is new; current revision 3.3 > cvs server: Diffing //Project1/Dir1 > File //Project1/Dir1/seltest.c is new; current revision 1.4 > File //Project1/Dir1/testi.c is new; current revision 1.2 > > with os.popen and read: > File //Project1/testiware.txt is new; current revision 3.13 > File //Project1/what_is_version_control.txt is new; current revision 3.3 > File //Project1/Dir1/seltest.c is new; current revision 1.4 > File //Project1/Dir1/testi.c is new; current revision 1.2 > > --- > Script doesn't read those "cvs server: Diffing" lines > --- looks like the program prints some output to stderr, and some to stdout. possible solutions: 1) if your shell supports it, add "2>&1" to the end of the command line, to send all stderr output to stdout. random google link: http://www.zeitfenster.de/bash/Bash-Prog-Intro-HOWTO-3.html 2) use os.popen4 to get a file handle representing both streams. see: http://www.python.org/doc/current/lib/os-newstreams.html#os-newstreams From max at alcyone.com Mon Aug 11 21:32:12 2003 From: max at alcyone.com (Erik Max Francis) Date: Mon, 11 Aug 2003 18:32:12 -0700 Subject: Fun with numbers - dammit, but I want a cast! References: <3f378fac$0$10778$afc38c87@auth.uk.news.easynet.net> <3f3792f2$0$18258$afc38c87@auth.uk.news.easynet.net> <3F38367F.9EF03CEE@alcyone.com> Message-ID: <3F38439C.5FC57375@alcyone.com> Carl Banks wrote: > It seems you didn't read what I wrote carefully. I was talking about > C, not C++. Neither I nor the post I replied to mentioned C++ once. > I mentioned the C standard several times, never the C++ standard. > > Type casts in C are as I described. C++ was mentioned by the original poster; either way, C and C++ casts act precisely the same in this context. (float) 1 and *(float *) &i have precisely the same meanings both in C and C++. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ If you don't take chances, you can't do anything in life. \__/ Michael Spinks From Benjamin.Riefenstahl at epost.de Sat Aug 2 10:46:29 2003 From: Benjamin.Riefenstahl at epost.de (Benjamin Riefenstahl) Date: Sat, 02 Aug 2003 16:46:29 +0200 Subject: Potentially important real-time on-line discussion References: Message-ID: Hi Luciano, "Luciano ES" writes: > I think that another big question that strikes many companies is: > "if I make the source available, what will stop anyone from > compiling the source themselves and using it for free (illegally)?", It's only illegal if the author makes it illegal by using a restrictive license. If the author doesn't do that, the same activity ("compiling the source themselves") can become "interesting", "exiting" or "inspiring". New ideas can even lead to more profit for the original author. > or "if I make the source available, what will stop anyone from using > some of my best ideas and becoming my competitor?" I think lots of programmers (not to mention their management) overestimate their own originality by orders of magnitude. A skilled programmer should be able to reproduce most software in principle. Sometimes some (or even a lot) education in the particular software's domain is needed. But that education is usually available from public sources. Otherwise it's mostly a question of doing the work to reproduce the effects of the software in question. Create a reasonable software model and do a lot of coding and testing. Work that could be spared, if the source of the original were available, but that's all the advantage that the original software has. Case in point: OpenOffice. MS Office has an edge over OpenOffice, but it's most certainly not because of any ideas buried in the code. It's that MS office is older, so it's more mature in several aspects. And MS has probably spent lots of money on user testing with average people (as opposed to programmers as users). Or take my own current pastime: DVD players and multimedia codecs. Most features have been reproduced by Open Source, even stuff where the specs are not available. The problems that Linux has in the end-user area are caused by licensing restrictions, you have to pay to license some of the necessary technology. And you have to submit other software modules to an approval. IOW the licenses simply forbid doing a ready-to-use Open Source version. > that we live in an ideal world. We do not. Reality is brutal. That's right. And living in the real world is easier for me, if I don't start making life even more complicated, e.g. by inventing restrictive licenses, licensing schemes and all that. IMO that's all just a waste of time. Part of problem, not of part of any solution for anybody. benny From jerf at jerf.org Thu Aug 28 22:07:31 2003 From: jerf at jerf.org (Jeremy Bowers) Date: Fri, 29 Aug 2003 02:07:31 GMT Subject: Object Database (ODBMS) for Python References: <1DAECE9E8F34E04AA0E5699AF7D9FF090708D440@stpmsg00.corp.fairisaac.com> Message-ID: On Thu, 28 Aug 2003 20:26:41 -0500, Patrick K. O'Brien wrote: >>>> u1.name > 'Bob' >>>> u1.name = 'Joe' > Traceback (most recent call last): > File "", line 1, in ? > File "/home/pobrien/Code/pypersyst/entity/entity.py", line 94, in > __setattr__ > raise AttributeError, 'Modifications can only be made by transactions' > AttributeError: Modifications can only be made by transactions > > So, let's use a transaction: So why *isn't* it a transaction? Unless you have a good reason not to, I'd suggest automatically "coercing" that into a transaction instead of throwing an error. Give an indication in the docs about the performance issues if you like, but make the trivially easy case easy. (I'm only really entering my maturity (IMHO) as a software engineer, but one of my rules of thumb for developing software for other people to use is that the API can ***never*** be too easy. Doing something hard may be a little tricky but if you can make the easy case still work, you're way ahead. And Python is one ass-kicking language in that regard; it's one of the reasons I love it so much, the APIs can be made so easy to use they sometimes fade into complete transparency, like "u1.name = 'joe'". (I've been focusing on how to write APIs for others to use, esp. in Open Source though it applies equally to any team effort, that will be successful, rather then ignored.)) From lists at webcrunchers.com Tue Aug 19 16:43:26 2003 From: lists at webcrunchers.com (John D.) Date: Tue, 19 Aug 2003 13:43:26 -0700 Subject: Creating alt-numpad characters in Python Message-ID: How do I create characters 128-255 (like alt-numpad does in IBM PC's/DOS) from the keyboard? I want to create these at the OpenBSD shell level. I sure miss alt-... John From theller at python.net Thu Aug 7 15:23:35 2003 From: theller at python.net (Thomas Heller) Date: Thu, 07 Aug 2003 21:23:35 +0200 Subject: py2exe problems References: <8utYa.48785$cl3.1524137@news2.tin.it> Message-ID: <65l9e0g8.fsf@python.net> "Alessandro Crugnola *sephiroth*" writes: > i've installed python 2.2.2 and now it seems working well. > Excuse, me but what are the issues with the other python versions? So, there is a workaround for you, at least. Sigh, in this case I should also install 2.2.3 and look into this. The problem with 2.3 is that some imports seem to happen very early, when the interpreter is initialized. And the py2exe import hook is installed later, but it seems too late for warnings and encodings, at least. Thanks for finding this. Thomas From rmunn at pobox.com Thu Aug 14 16:33:05 2003 From: rmunn at pobox.com (Robin Munn) Date: Thu, 14 Aug 2003 20:33:05 GMT Subject: Strange re behavior: normal? Message-ID: How is re.split supposed to work? This wasn't at all what I expected: [rmunn at localhost ~]$ python Python 2.2.2 (#1, Jan 12 2003, 12:07:20) [GCC 3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import re >>> re.split(r'\W+', 'a b c d') ['a', 'b', 'c', 'd'] >>> # Expected result. ... >>> re.split(r'\b', 'a b c d') ['a b c d'] >>> # Huh? Since \b matches the empty string, but only at the beginning and end of a word, I would have expected re.split(r'\b', 'a b c d' to produce either: ['', 'a', ' ', 'b', ' ', 'c', ' ', 'd', ''] or: ['a', ' ', 'b', ' ', 'c', ' ', 'd'] But I didn't expect that re.split(r'\b', 'a b c d') would yield no splits whatsoever. The module doc says "split(pattern, string[, maxsplit = 0]): split string by the occurrences of pattern". re.findall() seems to think that \b occurs eight times in 'a b c d': >>> re.findall(r'\b', 'a b c d') ['', '', '', '', '', '', '', ''] So why doesn't re.split() think so? I'm puzzled. -- Robin Munn | http://www.rmunn.com/ | PGP key 0x6AFB6838 -----------------------------+-----------------------+---------------------- "Remember, when it comes to commercial TV, the program is not the product. YOU are the product, and the advertiser is the customer." - Mark W. Schumann From ajack at trysybase.com Fri Aug 8 15:33:16 2003 From: ajack at trysybase.com (Adam Jack) Date: Fri, 8 Aug 2003 13:33:16 -0600 Subject: Yet Another ... ImportError: No module named sax In-Reply-To: <001b01c35de0$e9341d30$4478160a@sybase.com> Message-ID: <002801c35de3$ecc4ddb0$4478160a@sybase.com> Oooops found an xml.pyc still in there. Sorry for the noise. regards Adam -----Original Message----- From: python-list-admin at python.org [mailto:python-list-admin at python.org]On Behalf Of Adam Jack Sent: Friday, August 08, 2003 1:12 PM To: python-list at python.org Subject: Yet Another ... ImportError: No module named sax Hello. I am on W2K w/ ActiveStart Python 2.2.2 build 224. This was working, but seems to have stopped and won't start again... Yesterday I read Python tutorials/manuals and today I am tinkering with my first program & hacking somebody else's program. I was putzing along quite happily and then I created an xml.py. Immediately things starting going wrong, see below, so I renamed it to xmlutils.py but I still get the error. I've cleaned up any *.pyc files I see, but it seems that somehow I've taught my environment about my xml (which no longer exists) in favour of the system one. Is this possible? I've not changed my path or anything. Could this be some sort of registry/optimisation thing? :\data\OSS\jakarta-gump\python>python gump/exec.py raceback (most recent call last): File "gump/exec.py", line 71, in ? from gump.conf import * File "F:\data\OSS\jakarta-gump\python\gump\__init__.py", line 94, in ? from xml.sax import parse ImportError: No module named sax Any thoughts on how I make this work again? regards Adam -- http://mail.python.org/mailman/listinfo/python-list From klappnase at web.de Thu Aug 7 10:11:17 2003 From: klappnase at web.de (klappnase) Date: 7 Aug 2003 07:11:17 -0700 Subject: Tkinter programming problem References: Message-ID: "Mark Daley" wrote in message news:... > I have problems with sys.exit() when I'm running under IDLE, since it seems > to cause ALL mainloops to exit, killing IDLE. I can't really give a whole > lot of detail on this, since I tend to use the command line to launch my > GUIs, anyway. > sys.exit()will stop (exit) the python interpreter. If you are running your program from within IDLE it will exit IDLE, too, because IDLE runs in the interpreter as well. If you run your program from the command line sys.exit() will exit the interpreter and stop the program, of course any instructions in the code after sys.exit() won't be executed. I think normally that is exactly what I want in a gui program - stop everything if the main window is closed. widget.destroy() will destroy "widget" and if "widget" is the main window of your application it will be destroyed - and all it's children with it. That's the way it should work if you are running from within the interpreter: your application is stopped but the interpreter won't be affected by this. widget.quit() exits the mainloop and therefore destroys the main window but it will not exit the interpreter, so there may be other processes in your code still be executed after the main window is closed. If all processes in the interpreter are finished the interpreter will exit anyway, so this will work as well as sys.exit(). However, if you run your program from the interpreter this will not work, because you do not call a mainloop there. Cheers Michael From tismer at tismer.com Wed Aug 27 20:20:39 2003 From: tismer at tismer.com (Christian Tismer) Date: Thu, 28 Aug 2003 02:20:39 +0200 Subject: What's better about Ruby than Python? In-Reply-To: <2259b0e2.0308230712.3f60cf3c@posting.google.com> References: <4o_0b.1665$Ej6.1182@newsread4.news.pas.earthlink.net> <8D01b.1721$Ej6.702@newsread4.news.pas.earthlink.net> <3F44ED2E.9070308@nyc.rr.com> <0V61b.1900$Ej6.1012@newsread4.news.pas.earthlink.net> <3F4504D7.20008@nyc.rr.com> <2259b0e2.0308230118.67a676e7@posting.google.com> <2259b0e2.0308230712.3f60cf3c@posting.google.com> Message-ID: <3F4D4AD7.8060305@tismer.com> Michele Simionato wrote: ... > There is only one dominant implementation of Python, CPython. This is correct, so far. Given some time, this might change. > All the others try to match it as soon as possible. I expect > Jython 2.2 (now > in alpha) will catch up with CPython, at some > moment. The goal of PyPy or Stackless is to enhance CPython, > but taking CPython as base reference. In Scheme there is no > such a basic reference, I am correct? Not really. The goal of Stackless is to enhance CPython, while keeping maximum compatibility. This is really really hard, due to the restrictions imposed by the C language. Jython will probably catch up, if somebody is going to feed Samuele, who really needs support (hint! hint!). Psyco, in its current state, is also bound to CPython and tries to enhance it (with remarkable success). But PyPy, after all, tries to be a lot more. It finally wants to replace the CPython source by its own. It wants to be a generic Python platform that allows to deduce all of the other variants at once. Or, more generally speaking, it tries to allow all of these to be implemented, using its generic framework. None of these projects has tried it so far, but my first goal next sprint is to investigate what it takes to make PyPy stackless, and which (of several possible) approaches to use. PyPy wants to subsume Stackless, Jython, Psyco and some more, at the same time. And all the developers of these extensions to CPython are in the PyPy group, not to forget about Guido, himself, who is happy to play with new alternatives. So think of PyPy as the level of abstraction that CPython never will be able to reach. (I really hope to reach it menatally all the time, since this is not trivial :) It is one of PyPy's goal to be able to reduce itself to an efficient variant of CPython, with the hope to be even more efficient. But understand this as one of the visions that keeps us going, and the targets are months and years away. But we will reach something. PyPy has the best developers I could think of (well, some are missing whom I know well, too, and I would drop out for them to be there, hi Tim). > --- Currently looking for a job --- Me too, unfortunately :-) ciao - chris -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 mobile +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From skip at pobox.com Wed Aug 13 14:07:49 2003 From: skip at pobox.com (Skip Montanaro) Date: Wed, 13 Aug 2003 13:07:49 -0500 Subject: Py2.3: Feedback on Sets In-Reply-To: References: Message-ID: <16186.32373.606399.118436@montanaro.dyndns.org> Russell> I suspect the upgrade issue will significantly slow the Russell> incorporation of sets and the other new modules, but that over Russell> time they're likely to become quite popular. I am certainly Russell> looking forward to using sets and csv. The csv module (and the _csv module which underpins it) should work with 2.2.3. If they don't, please file a bug report. Russell> I think it'd speed the adoption of new modules if they were Russell> explicitly written to be compatible with one previous Russell> generation of Python (and documented as such) so users could Russell> manually include them with their code until the current Russell> generation of Python had a bit more time to be adopted. That was the intention with the csv module. I wonder if some limitations to use of sets with 2.2.x could be gotten around by adding a __future__ import? Maybe itertools is also needed. Russell> I'm not saying this should be a rule, only suggesting it as a Russell> useful goal. Presumably it'd be easy with some modules and not Russell> worth the work in some cases. Yes, that's a worthwhile goal. Skip From JOBLINE.JOBLINE at lcra.org Thu Aug 21 08:53:14 2003 From: JOBLINE.JOBLINE at lcra.org (JOBLINE JOBLINE) Date: Thu, 21 Aug 2003 07:53:14 -0500 Subject: Your details (Thank you for applying!) Message-ID: We received your resume and are excited that you are interested in job opportunities at LCRA! Thank you for allowing us to review your qualifications. Please note that we are only able to process inquiries that include a specific job number. If your e-mail text or resume includes a specific job number, we will enter your information into our applicant system and forward your information to the appropriate hiring manager for review. We update our job postings each Friday afternoon, so visit our Web site at www.lcra.org for the latest job openings. Also updated weekly on our Web site, the Job Status Report keeps you informed about the hiring status of recently posted positions. If you have questions, call LCRA's Employee Services Department at 473-4004 (1-800-776-5272, Ext. 4004). Once again, thank you for taking the time to send us your resume. We appreciate your time and your interest. >>> python-list 08/21/03 07:52 >>> Please see the attached file for details. From tim at remove_if_not_spam.digitig.co.uk Tue Aug 5 12:48:50 2003 From: tim at remove_if_not_spam.digitig.co.uk (Tim Rowe) Date: Tue, 05 Aug 2003 17:48:50 +0100 Subject: Question about import References: <18fe8c2.0308050828.771de40d@posting.google.com> Message-ID: On 5 Aug 2003 09:28:54 -0700, kjmacken at yorku.ca (Kevin MacKenzie) wrote: >I'm a complete newbie to using Python. I have a small question about >importing modules. > >Is there any difference between the two following statements, and what >(if any) are they? > >>>> from Module import * > > >and > >>>> import Module Yes. As I said to someone else hereabouts not all /that/ long ago (!), >>>> import Module is the computing equivalent to getting your toolkit out of the cupboard and putting it on your workbench. >>>> from Module import * is the computing equivalent of getting your toolkit out of the cupboard, tipping the contents onto the workbench, and putting the box back into the cupboard. If "Module" contains "foo()", >>>> import Module means that you can call Module.foo() >>>> from Module import * means that you can use foo(). But if your code or any other module contains something called "foo()" then you get a name clash. That can be nasty, because you can get everything working fine, and somebody using a library that's supposed to be compatable with the one you've tested finds it doesn't work. For all but the very simplest of code, use >>>> import Module From graham at rockcons.co.uk Thu Aug 7 12:00:29 2003 From: graham at rockcons.co.uk (Graham Nicholls) Date: Thu, 07 Aug 2003 17:00:29 +0100 Subject: Extracting a short using struct - won't print. References: <3f3273f7$0$10777$afc38c87@auth.uk.news.easynet.net> <3F32758E.5734C64F@engcorp.com> Message-ID: <3f32779d$0$10780$afc38c87@auth.uk.news.easynet.net> Peter Hansen wrote: > Graham Nicholls wrote: >> >> Thanks to Richard and Alex, I'm doing this: >> >> seg_stru=">BHH" >> seg_data=self.fhand.read(struct.calcsize(seg_stru)) >> data=struct.unpack(seg_stru,seg_data) >> x=seg_data[1] >> y=seg_data[2] > > Why are you unpacking the struct if you aren't going to use the > unpacked data? Err, I'm trying to extract two shorts - the x and y size in pixels of an image, which I'll use to scale it to fit another pair of parameters. What makes you think I'm not using the data? Am I not - I thought I was! I realise that ">BHH" above ouhjt really to be "xHH" but aside from that, I don't understand your point - theres more code after the debug in the rel app - returning x and y. > >> if debug: >> print ("DEBUG: Image [%s] is [%d] by [%d] pixels" % >> (self.fname,x,y)) > > Best way to troubleshoot this kind of thing, in my experience, > is to insert "import pdb; pdb.set_trace()" into the code just > above the failing line, then use the debugger to inspect the > values directly just before they are used. (You need to execute > the "r" or "return" command immediately after the debugger is > entered... the rest is pretty straightforward to learn.) > I'll give that a go, thanks > -Peter -- Graham Nicholls Rock Computer Consultancy From Vincent.Raaijmakers at ge.com Fri Aug 1 08:57:29 2003 From: Vincent.Raaijmakers at ge.com (Raaijmakers, Vincent (IndSys, GE Interlogix)) Date: Fri, 1 Aug 2003 07:57:29 -0500 Subject: update eclipse plugin, work in progress? Message-ID: <55939F05720D954E9602518B77F6127F02FBB8AF@FTWMLVEM01.e2k.ad.ge.com> Does anyone know if work is in progress to update the python plugin for eclipse? www.eclipse.org The features of the current plugin is weak compared to the features of for example java. My background from the VA environment for Java and Smalltalk makes me hungry in getting the same strong IDE for Python. Don't mind looking at ways to expand this Python plugin, if possible and if time, but definitely don't have the time to reinvent the wheel. Please feedback. Vincent From rodrigob at elo.utfsm.cl Mon Aug 25 18:41:19 2003 From: rodrigob at elo.utfsm.cl (Rodrigo Benenson) Date: Mon, 25 Aug 2003 18:41:19 -0400 Subject: Rebol Size Message-ID: <3f4a9b9d_2@nova.entelchile.net> www.rebol.com Rebol offers a free (non-opensource) platform to devellop internet enabled application. It is a modern scripting language with objects, a huge list of base types and a very very clean syntax. It is full multiplaftorm. Rebol is able to manage 14 internet protocols (http, ftp, dns, finger, whois, pop, smtp, etc...) , offer data storage and reading, is able to manage various compression formats, various image file format (bmp, gif, png, jpg, etc...) and has a very very easy to use graphic interface construction dialect. His syntax allow to devellop simple dialects to extend the language on some specific application domains (example: there is a dialect for creating plots). As everything is internet enable is allow easy collaboration and comunication between clients. Everything until now can be rivalized by Python. My point is: All of the above comes the 500 Kb Rebol/View distribution !! (for the most common platforms) To do the same thing in python I would need: Python (>5 Mb) Twisted (>5 Mb) Imaging (>400Kb) ------------------- More than 10 Mb Ok, python probably is a little faster and is a programming language, not a scripting one. But how to explain such a difference ? Rodrigo Benenson. From bror.johansson at saabtech.se Thu Aug 21 02:16:57 2003 From: bror.johansson at saabtech.se (Bror Johansson) Date: Thu, 21 Aug 2003 08:16:57 +0200 Subject: QuickTimeTcl References: Message-ID: > > http://hem.fryistorg.com/matben/qt/ > should be: http://hem.fyristorg.com/matben/qt/ From mwh at python.net Tue Aug 26 08:57:45 2003 From: mwh at python.net (Michael Hudson) Date: Tue, 26 Aug 2003 12:57:45 GMT Subject: OT: Ocaml? References: <7xk795xde6.fsf_-_@ruckus.brouhaha.com> Message-ID: <7h3wud0zihr.fsf@pc150.maths.bris.ac.uk> Donn Cave writes: > Incidentally, a few years back someone got fairly far along on > implementing Python (or something like it) from scratch in > Objective CAML. That was John Max Skaller, and the code is still on sf: http://vyper.sf.net If you're really curious and the anon CVS isn't working, I can stick a tarball somewhere. Cheers, mwh -- > The conversion rate from Imperial Shitloads to Metric Shitloads is > to multiply by 1.07. Which you multiply is left as an exercise. Both. -- Bob McCown & Jasper Janssen, asr From webmaster at t-dose.de Thu Aug 7 07:02:56 2003 From: webmaster at t-dose.de (webmaster at t-dose.de) Date: Thu, 07 Aug 2003 13:02:56 +0200 Subject: Sick problem with Python properties Message-ID: <2147483647.1060261376@[192.168.0.100]> See the following code. I wonder why in this case neither setp() nor getp() is called !? yetix@/home/ajung(1)% cat test.py class A: def __init__(self): self._p=None def setp(self, p): print 'set' self._p = p*p def getp(self): print 'get' return self._p pp = property(getp, setp) inst=A() inst.p = 9 print inst.p yetix@/home/ajung(2)% python2.3 test.py 9 Cheers, -aj From aleax at aleax.it Thu Aug 7 11:31:35 2003 From: aleax at aleax.it (Alex Martelli) Date: Thu, 07 Aug 2003 15:31:35 GMT Subject: Gmpy References: <8578e2c1.0308070630.5fb70c22@posting.google.com> Message-ID: Jean-Pierre Andreaux wrote: > Gmpy module was a wrapper of the GNU MP library. It seems that no > evolution is done on this module since 2001. Indeed, Gmpy is not > supported in Python 2.2 nor 2.3. *blink* ...isn't it...? [alex at lancelot src23x]$ python Python 2.3+ (#1, Aug 5 2003, 17:15:06) [GCC 3.2.2 (Mandrake Linux 9.1 3.2.2-3mdk)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import gmpy >>> print gmpy.comb(10,7) 120 >>> I'll admit I haven't been working on gmpy for a while (it basically needs more docs, and I don't really needs those docs myself, so it's tempting to put other things higher on my list of priorities...:-), but if it had broken with 2.2 or 2.3 I'd surely have fixed it (I tend to run the current releases of Python -- including "latest from CVS", very often -- and gmpy's an indispensable companion for me... > My question is the following: what is the better replacement solution > for manipulating long numbers. I want to do long numbers > exponentiations. Thanks in advance for your answers. Well, let's see...: [alex at lancelot Lib]$ python timeit.py -s'import gmpy' \ > 'gmpy.mpz(162362341232431)**2313' 1000 loops, best of 3: 1.84e+03 usec per loop [alex at lancelot Lib]$ python timeit.py -s'import gmpy' \ > '162362341232431**2313' 10 loops, best of 3: 4.3e+04 usec per loop Apparently, good old gmpy still has some advantage (about 20 times faster) for exponentiations of this kind, ever when compared to the new and improved Python 2.3. With Python 2.2, still according to timeit.py's report about it, this operation took 3.53e+05 usec per loop in pure Python -- almost another 10 times more! -- but still 1.85+03 with gmpy, so with 2.2 gmpy's advantage was almost 200 times on this one. Anyway, even if you just need a speedup of 20 times, it seems to me that gmpy can still be of use to you. What problems, exactly, have you had using it with Python 2.3...? Alex From siegfried.gonzi at kfunigraz.ac.at Mon Aug 4 03:47:12 2003 From: siegfried.gonzi at kfunigraz.ac.at (Siegfried Gonzi) Date: 4 Aug 2003 07:47:12 GMT Subject: Python speed vs csharp References: <1h5f2rzthqgid.8watonaa4cjt.dlg@40tude.net> <3F551D29.1040407@kfunigraz.ac.at> Message-ID: <3F559D5E.7070003@kfunigraz.ac.at> Siegfried Gonzi wrote: Only for the sake of completeness. My last version had a minor bottleneck. The following Bigloo version is as fast as C . Suming up your erfc function 10^6 times: new version: 0.5 seconds C version: 0.5 seconds As I wrote giving types in Bigloo renders code effectively. It has also the advantage that the compiler becomes very picky and spots a lot of type errors; Bigloo is as OCaml for example then. If you do not give types Bigloo is as forgiving as what you would assume from Scheme. S. Gonzi ===== NEW VERSION ===== (module erfc2 (option (set! *genericity* #f))) (define (erfc::double x::double ) (let* ( (x::double (exact->inexact x)) (p::double 0.3275911) (a1::double 0.254829592) (a2::double -0.284496736) (a3::double 1.421413741) (a4::double -1.453152027) (a5::double 1.061405429) (t::double (/fl 1.0 (+fl 1.0 (*fl p x)))) (erfcx::double (*fl (*fl t (+fl a1 (*fl t (+fl a2 (*fl t (+fl a3 (*fl t (+fl a4 (*fl t a5))))))))) (exp (negfl (*fl x x)))))) erfcx)) (define (do-it) (let ((erg::double 0.0)) (do ((i 0 (+fx i 1))) ((=fx i 1000000)) (set! erg (+fl erg (erfc 0.456)))) erg)) (print (do-it)) ====================== From sjf at NOSPAM.plusnet.pl Wed Aug 6 05:18:38 2003 From: sjf at NOSPAM.plusnet.pl (sjf) Date: Wed, 6 Aug 2003 11:18:38 +0200 Subject: analiza pliku tekstowego Message-ID: Witam wszystkich, mam program, kt?ry czyta plik tekstowy wiersz po wierszu program ma sprawdza? czy w wierszu obecnie wczytanym do pami?ci wyst?puje konkretny ci?g znak?w, je?eli tak to ma ten wiersz skopiowa? do nowo utworzonego pliku w jaki spos?b uzyska? wyszukiwanie wzorca? pytanie dodatkowe: czy da si? potraktowa? dwa kolejne wiersze jako jeden (wiem, ?e w konkretnym przypadku jest to jeden wiersz tyle tylko, ?e prze?amany), tzn. program wczytuj?c wiersz "wie", ?e jest on prze?amany i trzeba wczyta? jeszcze kolejny...? pozdrawiam sjf From bokr at oz.net Mon Aug 18 21:02:11 2003 From: bokr at oz.net (Bengt Richter) Date: 19 Aug 2003 01:02:11 GMT Subject: union in Python References: Message-ID: On Mon, 18 Aug 2003 18:54:20 -0300, Gustavo Niemeyer wrote: >> When looking for a particular string, rather than a pattern, you are >> probably better off to use the find or index method of that string >> rather than re. >> >> >>> 'abcdefg'.find('d') >> 3 > >Just out of curiosity, the preference for the find() method rather than >using SRE might not be so obvious. SRE has an internal optimization >which handles literals in a different way, avoiding some of the overhead >from the engine. Additionally, it includes an overlap algorithm which >speeds up the linear searching in many cases, specially with large data. > I wonder why find doesn't take advantage of the same thing, whatever it is (Boyer-Moore? or some running fifo window hash check?). Probably the usual ... people who can do it are too busy to do it in free time, and no-one's throwing money ;-) >Here is a cooked example which highlights that fact: > >----------------------------- >import time >import re > >s1 = "x"*30+"a" >s2 = "x"*1000000+"a" >p1 = re.compile(s1) > >start = time.time() >for i in range(1000): > p1.search(s2) > print time.time()-start > >start = time.time() >for i in range(1000): > s2.find(s1) > print time.time()-start >----------------------------- > >And here is a sample output: > >% python test.py >45.2645740509 >233.810258031 > That looks worth improving on. Looking quickly at stringobject.c, this looks like it might be the forward search guts: ... if (dir > 0) { if (n == 0 && i <= last) return (long)i; last -= n; for (; i <= last; ++i) if (s[i] == sub[0] && memcmp(&s[i], sub, n) == 0) return (long)i; ... If so, you can see a reason for your results. But I don't see any reason why the performances couldn't be made to match. Regards, Bengt Richter From midnightcoder at comcast.net Sun Aug 24 04:14:48 2003 From: midnightcoder at comcast.net (Bruce Williams) Date: Sun, 24 Aug 2003 01:14:48 -0700 Subject: Aspect oriented Everything? In-Reply-To: <6ee58e07.0308230459.24f53b64@posting.google.com> Message-ID: <000001c36a17$cbf1a830$0a6d2f44@tallboy> > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org] On Behalf Of Lothar Scholz > Sent: Saturday, August 23, 2003 5:59 AM > To: python-list at python.org > Subject: Re: Aspect oriented Everything? > > > > Aspect oriented Software development seems to be expanding in the > > popular vision of developers, with more and more IDE 'add-ons' and > > even more specialized tools,Jboss etc. > > I'm not sure if this is a the way to go. I've only seen proof > of concept but no real use. But only in the latter case you > can see the problems. > > I don't like it because it breaks encapsulation and splitters > the code over a few files. Maybe that can be solved with new > kind of editors but it is much more easy to result in a big confusion. > > The most important use cases that i've seen so far are: > > - Logging facilities > - Debugging code > - Pre/Postconditions > - Threading synchronization > Isn't the classic example for Aspect Oriented language extensions security issues that cross class boundaries and are -not-object-oriented- by nature? I am not agreeing with this, but that is an example the proponents seem to use regularly. Bruce Williams > 1+2+3 can be embedded in a language. This is already done in Eiffel. > I don't know if i really want to see something as difficult > as "threading synchronization" as an aspect. > -- > http://mail.python.org/mailman/listinfo/python-list > From peter at engcorp.com Tue Aug 19 07:01:15 2003 From: peter at engcorp.com (Peter Hansen) Date: Tue, 19 Aug 2003 07:01:15 -0400 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: <3F412484.69867AED@alcyone.com> <3f415560$0$1124$626a54ce@news.free.fr> Message-ID: <3F42037B.25BEFCE6@engcorp.com> Bruno Desthuilliers wrote: > > Istvan Albert wrote: > > Erik Max Francis wrote: > > > >>> What's ***TOTALLY COMPELLING*** about Ruby over Python? > >> > >> > >> comp.lang.ruby doesn't have Brandon Van Every. > > > > > > LOL > > > > LOL 2 > > Bruno > (yes, I want to be in Brandon's killfile. It's the new game on clp : > being in Brandon's killfile. Just imagine what will happen when every > clp regulars will be in Brandon's kill file...) The world will be a very quiet, happier place. -Peter From postmaster at GSN.com Thu Aug 21 16:32:20 2003 From: postmaster at GSN.com (System Administrator) Date: Thu, 21 Aug 2003 13:32:20 -0700 Subject: Undeliverable: Re: Your application Message-ID: Your message To: Webmaster Subject: Re: Your application Sent: Thu, 21 Aug 2003 08:40:34 -0700 did not reach the following recipient(s): Webmaster on Thu, 21 Aug 2003 13:32:20 -0700 The recipient was unavailable to take delivery of the message MSEXCH:MSExchangeIS:GSNLA:GSNEXC001 -------------- next part -------------- An embedded message was scrubbed... From: python-list at python.org Subject: Re: Your application Date: Thu, 21 Aug 2003 08:40:34 -0700 Size: 1022 URL: From sheu at bu.edu Tue Aug 19 21:55:30 2003 From: sheu at bu.edu (Shu-Hsien Sheu) Date: Tue, 19 Aug 2003 21:55:30 -0400 Subject: Float + min/max? Message-ID: <005d01c366be$22a146c0$9200a8c0@PowerLoom> Hi, I am new to Python, and just wrote a small program to generate the maximum number of the cartisian coordinates among all atoms in a given molecule. However, I found the float function, if combined with max function, to be kind of confusing. It would give a number with uneccessary decimals from nowhere. Not converting to float: x = [] for i in (0, length-2): slines[i] = lines[i].split() if slines[i][0] == "ATOM": x.append(slines[i][6]) print "xmax = " + max(x) + " " + "xmin = " + min(x) Output: xmax = 90.179 xmin = 64.112 Converting to float numbers: x = [] for i in (0, length-2): slines[i] = lines[i].split() if slines[i][0] == "ATOM": x.append( float(slines[i][6]) ) print "xmax = " + max(x) + " " + "xmin = " + min(x) Output: xmax = 90.179000000000002 xmin = 64.111999999999995 The original data file apparantly does not have those decimals. May I ask how does it happend? Thank! -shuhsien From aleax at aleax.it Fri Aug 8 03:15:51 2003 From: aleax at aleax.it (Alex Martelli) Date: Fri, 08 Aug 2003 07:15:51 GMT Subject: Gmpy References: <8578e2c1.0308070630.5fb70c22@posting.google.com> <5b42ae4.0308072039.583e00e4@posting.google.com> Message-ID: Ernie wrote: ... > the gmpy for comparison. However, trying to install > gmpy-sources-09a21.zip, results in an error: ... > gmpy.c: In function `Pygmpy_rand': > gmpy.c:5053: structure has no member named `seed' > error: command 'gcc' failed with exit status 1 Right -- I could SWEAR I've fixed this a zillion times after the GMP library made an incompatible change in one of its header files, but apparently the fix didn't make it to a release. Could you try a CVS snapshot? Meanwhile I hope to make time to put a fixed release together in the weekend... Thanks, Alex From gh at ghaering.de Mon Aug 4 09:49:31 2003 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Mon, 04 Aug 2003 15:49:31 +0200 Subject: Script In-Reply-To: References: Message-ID: <3F2E646B.4040208@ghaering.de> zze-Support activite PCL RAMSI A ext DvSI/SIReS/LAN wrote: > Even if the script is created by the root and has 4755 as chmod? Yes. You can't SUID scripts on Unix. If you need this functionality, you need a little compiled SUID wrapper program that will execute the script (with parameters, if necessary). -- Gerhard From p-abel at t-online.de Sat Aug 30 19:08:38 2003 From: p-abel at t-online.de (Peter Abel) Date: 30 Aug 2003 16:08:38 -0700 Subject: Newbie Tkinter problem... References: <3306631.1062265710@dbforums.com> Message-ID: <13a533e8.0308301508.6896c94d@posting.google.com> Baltor wrote in message news:<3306631.1062265710 at dbforums.com>... > I am trying to attach a scollbar to a text field. This is the code > I am using: > > > > # Scroll Bar and Text Box > > self.scrollbar = Scrollbar(master, orient=VERTICAL) > > self.scrollbar.pack(side=RIGHT, fill=Y) > > self.text = Text(master, height=5, width=20, state=DISABLED, > yscrollcommand=self.scrollbar.set) > > self.text.grid(row=2, column=1, rowspan=2) > > self.scrollbar.config(command=self.text.yview) > > > > When I run the program, the program freezes and I have to Ctrl-Alt- > Delete put of it. What's wrong? > > Thanks in advance. You did something you should never do in Tkinter, that's mixing the pack- and the grid-manager. instead of: > self.scrollbar.pack(side=RIGHT, fill=Y) try: self.scrollbar.grid(row=2, rowspan=2, column=2) This should help. Regards Peter From bokr at oz.net Wed Aug 6 04:34:39 2003 From: bokr at oz.net (Bengt Richter) Date: 6 Aug 2003 08:34:39 GMT Subject: yEnc implementation in Python, bit slow References: Message-ID: On 5 Aug 2003 14:37:55 +1000, Freddie wrote: >Freddie wrote in >news:Xns93CE8D81747C5freddiethescaryeleph at 218.100.3.9: > >Arr. There's an error here, the [n+i+256+1] shouldn't have a 1. I always get >that wrong :) The posted files actually decode now, and the yEncode() >overhead is a lot lower. > > > >> encoded = [] >> n = 0 >> for i in range(0, len(translated), 256): >> chunk = translated[n+i:n+i+256] >> if chunk[-1] == '=': >> chunk += translated[n+i+256] <<< this line >> n += 1 >> encoded.append(chunk) >> encoded.append('\n') > >-- >Remove the oinks! Ok, I was't going to get too involved, but I thought first to try something different, using a unicode translation table in the attempt to get all the translations in one sweep, including the = escapes. It works (after hacking a while re encoding stuff ;-/ ), but it's not that fast. But for small input strings it is faster than yours above, due to some things which you can see I changed for yEncode2x below. That generally was fastest. I noticed big differences according to input string length, so I decided to parameterize the testing, to control the number of loops and the input string length by a steppable factor times the 256-byte string you defined. Kind of got carried away with histograms to show throughput comparisons, and ratios etc. As you might expect, with large inputs, most of the time is spent in the translate routines, and the setup and other overhead gets asymptoted out (verbing weirds language). The unicode version's apparent throughput settles relatively early to something fairly constant. I thought it could possibly beat the other versions because of the multiple replace passes, but not so. Not sure where the major slowdown is. On my old 300mhz P2 w/320MB ram and NT4 and Python 2.3, for your 256*1562 test strings, I get: [ 1:22] C:\pywk\clp>testyenc.py 10 Ratios of total test times over version 2x: yEncode2: 1.888619 ratio/2x: 1.008296 yEncode3: 4.692256 ratio/2x: 2.505102 yEncode2x: 1.873080 ratio/2x: 1.000000 I.e., the average is practically identical for 2 and 2x, whereas the unicode (3) is 2.5 times slower. Now for a minimal input (1 block of 256 bytes input): [ 1:25] C:\pywk\clp>testyenc.py 10 1 Ratios of total test times over version 2x: yEncode2: 0.019924 ratio/2x: 11.664868 yEncode3: 0.003890 ratio/2x: 2.277723 yEncode2x: 0.001708 ratio/2x: 1.000000 2x is over ten times faster than 2! And not quite as much faster than the unicode. Comparing thoughput as ratios of how many times faster x2 is than 2 or 3 for 1-15 x 256 bytes input, 10 loops: [ 1:25] C:\pywk\clp>testyenc.py -trh 10 1 15 1 13.254171 x/2: 222222222222222222222222222222222222222222222222222222222222222222 1 2.377331 x/3: 33333333333 2 8.490966 x/2: 222222222222222222222222222222222222222222 2 2.816887 x/3: 33333333333333 3 6.828756 x/2: 2222222222222222222222222222222222 3 2.932418 x/3: 33333333333333 4 5.663449 x/2: 2222222222222222222222222222 4 2.985414 x/3: 33333333333333 5 4.859705 x/2: 222222222222222222222222 5 3.008702 x/3: 333333333333333 6 4.408558 x/2: 2222222222222222222222 6 3.136186 x/3: 333333333333333 7 4.052319 x/2: 22222222222222222222 7 3.181253 x/3: 333333333333333 8 3.694041 x/2: 222222222222222222 8 3.220882 x/3: 3333333333333333 9 3.462013 x/2: 22222222222222222 9 3.271515 x/3: 3333333333333333 10 3.263672 x/2: 2222222222222222 10 3.283939 x/3: 3333333333333333 11 3.082912 x/2: 222222222222222 11 3.298241 x/3: 3333333333333333 12 2.951584 x/2: 22222222222222 12 3.319393 x/3: 3333333333333333 13 2.799223 x/2: 2222222222222 13 3.486121 x/3: 33333333333333333 14 2.653915 x/2: 2222222222222 14 3.383072 x/3: 3333333333333333 Now just kb/sec throughput, for input sizes of factor*256, steppin factor from 1 to 1562 by 100: Oops, has to hand-adjust for 4 digits in factor (format had 3) :-/ I guess I'd recommend version yEncode2x ;-) [ 1:30] C:\pywk\clp>testyenc.py -tkh 10 1 1562 100 1 1466.546 : xxxxxxxxxxxxxxxxxxxxxxxxxxxxx 1 124.638 : 22 1 640.256 : 333333333333 101 2775.813 : xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 101 2142.211 : 222222222222222222222222222222222222222222 101 913.269 : 333333333333333333 201 2699.580 : xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 201 2307.571 : 2222222222222222222222222222222222222222222222 201 901.330 : 333333333333333333 301 2719.819 : xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 301 2417.963 : 222222222222222222222222222222222222222222222222 301 898.533 : 33333333333333333 401 2469.232 : xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 401 2459.443 : 2222222222222222222222222222222222222222222222222 401 899.486 : 33333333333333333 501 2493.177 : xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 501 2326.776 : 2222222222222222222222222222222222222222222222 501 824.358 : 3333333333333333 601 2519.179 : xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 601 2177.450 : 2222222222222222222222222222222222222222222 601 867.528 : 33333333333333333 701 2485.202 : xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 701 2188.600 : 2222222222222222222222222222222222222222222 701 840.751 : 3333333333333333 801 2383.141 : xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 801 2283.640 : 222222222222222222222222222222222222222222222 801 853.356 : 33333333333333333 901 2462.079 : xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 901 2140.306 : 222222222222222222222222222222222222222222 901 837.844 : 3333333333333333 1001 2326.644 : xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 1001 2167.332 : 2222222222222222222222222222222222222222222 1001 846.462 : 3333333333333333 1101 2154.616 : xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 1101 2031.622 : 2222222222222222222222222222222222222222 1101 841.033 : 3333333333333333 1201 2015.904 : xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 1201 2008.703 : 2222222222222222222222222222222222222222 1201 830.437 : 3333333333333333 1301 2102.667 : xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 1301 2048.542 : 2222222222222222222222222222222222222222 1301 830.532 : 3333333333333333 1401 2117.665 : xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 1401 2036.031 : 2222222222222222222222222222222222222222 1401 831.369 : 3333333333333333 1501 2106.134 : xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 1501 2030.204 : 2222222222222222222222222222222222222222 1501 823.828 : 3333333333333333 ====< testyenc.py >================================================================== ## testyenc.py ## Orig as posted by Freddie + his correction: ## except as noted, and tabs changed to 4 spaces ## Subject: yEnc implementation in Python, bit slow ## From: Freddie ## Message-ID: ## Date: 5 Aug 2003 00:50:58 +1000 ## ## followed by an improved version, followed by an experiment using a unicode translation table ## def yEncode2(data): trans = '' for i in range(256): trans += chr((i+42)%256) translated = data.translate(trans) # escape =, NUL, LF, CR for i in (61, 0, 10, 13): j = '=%c' % (i + 64) translated = translated.replace(chr(i), j) encoded = [] n = 0 for i in range(0, len(translated), 256): chunk = translated[n+i:n+i+256] if chunk[-1] == '=': chunk += translated[n+i+256] # <<< this line changed per Freddie's post # chunk += translated[n+i+256+1] <--was n += 1 encoded.append(chunk) encoded.append('\n') result = ''.join(encoded) #XXX# print len(result), return result #--------------------------------------------------- # above version somewhat optimized def yEncode2x(data, trans = ''.join([chr((i+42)%256) for i in xrange(256)]), escapes = [(chr(i), '=%c'%(i+64)) for i in (61, 0, 10, 13)] ): translated = data.translate(trans) # escape =, NUL, LF, CR for cold, cnew in escapes: translated = translated.replace(cold, cnew) encoded = [] start = 0; end = len(translated) while start256 chars don't matter (u>=256 and u'\x00') or # escape if translated by +42 mod256 is in (=, NUL, LF, CR) (((u+42)%256) in (61, 0, 10, 13) and unicode('=%c'%chr((u+42+64)%256), 'utf-16')) or # translate others +42 mod 256 unicode('%c\x00'%chr((u+42)%256),'utf-16') for u in xrange(256*256)]), identity = ''.join(map(chr,xrange(256))) ): utranslated = unicode(data,'latin-1').translate(utrans) no_lf = utranslated.encode('utf-16').translate(identity, '\x00')[2:] ret = []; i = 0; eod = len(no_lf) while i < eod: top = i+256 if no_lf[top-1:top]=='=': top+=1 ret.append(no_lf[i:top]) i = top ret.append('') return '\n'.join(ret) def test(nloops, factor=1562): from time import clock test = [chr(i) for i in xrange(256)] teststr = ''.join(test*factor) # sanity check assert yEncode2(teststr) == yEncode3(teststr) == yEncode2x(teststr) assert yEncode2(teststr[:-1]) == yEncode3(teststr[:-1]) == yEncode2x(teststr[:-1]) assert yEncode2(teststr+'?') == yEncode3(teststr+'?') == yEncode2x(teststr+'?') t1 = clock() for i in xrange(nloops): dummy = yEncode2(teststr) t2 = clock() for i in xrange(nloops): dummy = yEncode3(teststr) t3 = clock() for i in xrange(nloops): dummy = yEncode2x(teststr) t4 = clock() tenc2 = t2-t1 tenc3 = t3-t2 tenc2x = t4-t3 return tenc2, tenc3, tenc2x def test2(opt,nloops, factorstart=1562, factorstop=1563, factorstep=1): for factor in xrange(factorstart,factorstop,factorstep): kb = nloops*256.0*factor/1024. tenc2, tenc3, tenc2x = test(nloops, factor) tenc2 = kb/tenc2; tenc3 = kb/tenc3; tenc2x = kb/tenc2x ratio2x = tenc2x/tenc2; ratio3x=tenc2x/tenc3 if opt=='-trh': print '%3s %10.6f x/2: %s'%(factor, ratio2x,'2'*int(ratio2x*5)) print '%3s %10.6f x/3: %s'%(factor, ratio3x,'3'*int(ratio3x*5)) elif opt=='-tkb': print '%3s: e2x kb/s = %10.3f, e2 kb/s = %10.3f, e3 kb/s = %10.3f' %(factor,tenc2x, tenc2, tenc3) elif opt=='-tkh': print '%3s %10.3f : %s'%(factor, tenc2x,'x'*int(tenc2x/50)) print '%3s %10.3f : %s'%(factor, tenc2,'2'*int(tenc2/50)) print '%3s %10.3f : %s'%(factor, tenc3,'3'*int(tenc3/50)) else: raise ValueError, 'test2 only undestands one of: -trh -tkb -tkg' if __name__ == '__main__': def boxit(s): hbar = '-'*len(s); return ' +-%s-+\n | %s |\n +-%s-+' % (hbar, s, hbar) import sys args = sys.argv[1:] try: if args and args[0].startswith('-t'): test2(args[0], *map(int,args[1:])) else: tenc2, tenc3, tenc2x = test(*map(int,sys.argv[1:])) print ( 'Ratios of total test times over version 2x:\n' 'yEncode2: %f ratio/2x: %f\n' 'yEncode3: %f ratio/2x: %f\n' 'yEncode2x: %f ratio/2x: %f' % ( tenc2, tenc2/tenc2x, tenc3, tenc3/tenc2x, tenc2x, tenc2x/tenc2x) ) except Exception, e: box = boxit('%s: %s'%(e.__class__.__name__, e)) print """ %(box)s Usage: testyenc.py nloops factor <1562> for nloops with factor*<256-byte-test-strings>, outputting total times and ratios, or testyenc.py opt nloops [start <1562> [stop <1563> [step <1>]]] for testing the same with a range of factors, and where <> is for defaults and opt: -trh for ratio histogram of enc2x kb/sec over enc2 and enc3 rates -tkb for kb/sec numbers for the three versions -tkh for a kb/sec histogram """ % vars() ===================================================================================== Regards, Bengt Richter From adalke at mindspring.com Fri Aug 22 01:23:04 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Fri, 22 Aug 2003 05:23:04 GMT Subject: how fast is Python? References: Message-ID: Jeff Epler: > As far as I can tell, your program would be computing a value on the > order of 10^(3x10^31)... > for(int i = 0; i < 108; i++) > X = 1 + X * X; He had 1-X*X. Since X starts at 0.5, this will never go leave the range 0 to 1. Andrew dalke at dalkescientific.com From adalke at mindspring.com Fri Aug 8 22:37:06 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Fri, 8 Aug 2003 20:37:06 -0600 Subject: Recommendation of a parser generator References: Message-ID: Fortepianissimo: > I'm about to start a new project which will be mostly written in > Python. The first task is to parse some formula-like expressions into > an internal data structure so they can be evaluated. How close is this formula language to Python's? For other projects I've punted the heavy work to Python's own parser, then filled in the bits I needed. For example, suppose you have the expression a.b + c + s.find('d') >>> import compiler >>> from compiler import visitor >>> s = "a.b + c + s.find('d')" >>> class GetNames(visitor.ASTVisitor): ... def __init__(self): ... self.names = {} ... def visitName(self, obj): ... self.names[obj.name] = 1 ... >>> a = compiler.parse(s) >>> names = compiler.walk(a, GetNames()).names.keys() >>> names ['a', 'c', 's'] >>> Then get the values for a, c, and s, put them into a dict, and >>> class A: ... b = 5 ... >>> eval(s, {"a": A, "c": 3, "s": ""}) 7 >>> (Assuming I didn't make any mistakes - it's modified from an earlier exchange Alex and I had in c.l.py, titled "classes derived from dict and eval" and I didn't test all the changes.) Failing that, I've been happy with SPARK as a parser generator, but as you read in the paper, it's slow compared to the other parsers that were benchmarked. > This parser would be run extensively in the future, so speed is a > consideration, Why is the parser performance the problem? Most of the time is spent evaluating the result, right? That's post-parsing. The only time to worry about parsing performance is if you have a lot of different expressions coming in. Otherwise, just cache the results, as Python does with .pyc files. > I'd appreciate very much some expert suggestions from the group, like > on the speed, flexibility, portability, and the future prospect (like > to be adopted as the standard etc.). I too would like a standard parser generator for Python. I don't know the status of that activity. As it is, SPARK is small enough that it's easy for me to include in my projects. Andrew dalke at dalkescientific.com From mcfletch at rogers.com Wed Aug 20 08:21:37 2003 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Wed, 20 Aug 2003 08:21:37 -0400 Subject: Design idea for Ping Application In-Reply-To: References: <4378fa6f.0308181546.548daff7@posting.google.com> <1061263809.5430.49.camel@localhost.localdomain> Message-ID: <3F4367D1.3080404@rogers.com> David M. Cooke wrote: >At some point, "Mike C. Fletcher" wrote: > > ... >>however, I've not yet been >>able to get the code to run under Unix (where creating raw sockets is >>a no-no). >> >> > >Only root can create raw sockets. You'll notice the system ping >command is setuid root so that ordinary users can use it. Running this >code as root works. > > Yes, that's where I'd arrived too (only root can do it). I was sort of hoping there was some way around this silliness by using, e.g. non-raw sockets, or registering a socket as being ICMP-protocol and thereby letting the system check it's data for bad formatting/evil-stuff. I really don't like the idea of requiring a setuid setup just to allow a multi-ping module to work (it's not even a module at that point, it's got to be its own script/process, which means creating input and output formats and all that jazz rather than just reporting the results as data-structures). Multi-pinging is a trivial task, it's just a slightly more useful version of ping, but the root-user-requirment makes it a serious pain to implement. I mean, this is simple networking code using a well-established protocol (ICMP). Would be really nice to be able to say "hey, I'm interested in sending (raw) IP messages" without having to fundamentally restructure an application. Price of multi-user systems I suppose. Oh well, bite the bullet and make it a setuid-safe program and figure out how to get that installed on client machines. Or just scrap the whole direct approach on Unix and spawn 100 "ping" processes simultaneously. Thanks for confirming my fears. I'll never go out of the house again :) , Mike _______________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://members.rogers.com/mcfletch/ From sismex01 at hebmex.com Wed Aug 6 10:00:11 2003 From: sismex01 at hebmex.com (sismex01 at hebmex.com) Date: Wed, 6 Aug 2003 09:00:11 -0500 Subject: Python's biggest compromises Message-ID: > From: aahz at pythoncraft.com [mailto:aahz at pythoncraft.com] > Sent: Martes, 05 de Agosto de 2003 08:05 p.m. > > In article , > Dang Griffith wrote: > >Anthony_Barker wrote: > >> > >> What about immutable strings? I'm not sure I understand Guido's > >> preference for them. > > > > Strings are also immutable in Java. Maybe Guido likes Java? ;-) > > Python predates Java. > Yeah, snakes drink coffee too. ;-) -gustavo Advertencia:La informacion contenida en este mensaje es confidencial y restringida, por lo tanto esta destinada unicamente para el uso de la persona arriba indicada, se le notifica que esta prohibida la difusion de este mensaje. Si ha recibido este mensaje por error, o si hay problemas en la transmision, favor de comunicarse con el remitente. Gracias. From shalehperry at comcast.net Fri Aug 8 11:27:36 2003 From: shalehperry at comcast.net (Sean 'Shaleh' Perry) Date: Fri, 8 Aug 2003 08:27:36 -0700 Subject: OCR with Python In-Reply-To: <3F33B614.C4E4BA99@hotmail.com> References: <3F33B614.C4E4BA99@hotmail.com> Message-ID: <200308080827.36356.shalehperry@comcast.net> On Friday 08 August 2003 07:39, Alan Kennedy wrote: > > > So I need to recognize the characters in a picture. > > I think you'll find that those characters have been rendered > specifically to prevent machine recognition. The only machine that can > read them is the human brain. If someone can come up with an computer > algorithm that can read them, then the pictures will have to be > changed. > yeah, but it is an interesting problem just begging to be solved. The person who does can get quite a reputation and probably easy employment. From imadept at bigfoot.com Sat Aug 2 21:24:09 2003 From: imadept at bigfoot.com (Art) Date: Sat, 02 Aug 2003 21:24:09 -0400 Subject: Beginner's popups in vanilla Python program Message-ID: <3.0.5.32.20030802212409.007e1120@usermail.com> NEWBIE ALERT! Esteemed List Participants and Lurkers: (System: P-II 350, 192 meg, Win98 SE, Python 2.2.3, wxPythonWIN32-2.4.1.2-Py22.exe) I'm having a lot of fun getting started with Python ... it is the most elegant and graceful language I have ever used (Fortran, Cobol, Basic, many assemblers, Forth, C, VB, etc.). I don't have the resources or the research time to buy a stack of books, so I'm begging help here. Please be graciously patient. I want to edit and run a SIMPLE beginner's program from the IDLE GUI. Within the program, I want to pop up a Windows modal dialog box with a message "Is this a test?"; a title "Test Query"; and I want YES|NO buttons to exit and pass a yes|no boolean back to the program. The program will then pop up a second dialog message box "You selected (yes or no)" with title "Response:" with a close button. I don't really care if there is a "parent(?)" frame on the screen (but I prefer not) for the duration of the program, as long as it is terminated properly before the program ends. Here is everything but the popups: # Program: Beginners_Popups.py ... "Hello World" for popups # Import and set up the tk/WX/?? popups here. # As minimal as is possible print "Begin program" # Prepare the basic programmatic messages strMess1 = "Is this a Test?" strTitle1 = "Test Query" strResponse = "You selected " strTitle2 = "Response:" # 1st popup goes here: # Message = strMess1 # Title = strTitle1 # YES|NO buttons Returning Boolean boolVar # Build the appropriate response if boolVar: strResponse += "YES" else: strResponse += "NO" # 2nd popup goes here: # Message = strResponse # Title = strTitle2 # and close button print "End of Program" Once I get this far, I will have the guts of everything I need (for now!). I just can't seem to find enough beginner's information for the simple popup pieces. I know I'm trying to incorporate Windows stuff in a DOS type environment, but I'm sure it can be done. I already have a filter written in Python to read and parse a directory of files into a dictionary of location #s and file names, read in a master location list, and create a text file of an HTML table with file links in the cells. I have about 120 locations to deal with, and it is working great. I just need a couple of primitive user interface points, and popups are standard. Thank you for your gracious comments, suggestions, assistance, and even criticisms. Blessings in abundance, all the best, and ENJOY! Art Du Rea Carlisle, PA From max at alcyone.com Sun Aug 24 18:35:59 2003 From: max at alcyone.com (Erik Max Francis) Date: Sun, 24 Aug 2003 15:35:59 -0700 Subject: How to get the minor and major device numbers with os.stat ? References: Message-ID: <3F493DCF.B60BE387@alcyone.com> Alain Tesio wrote: > I expected major*256+minor, I've tried a lot of combinations at random > and couldn't manage to get 17383 from (13,7) For the answer to this, you should really be looking at man stat. The values here are implementation defined; Python's just mimicking whatever the underlying OS is doing. What you want is st_rdev: >>> import os >>> os.system('ls -l /dev/ttyS0') crw-rw---- 1 root uucp 4, 64 Jul 17 1994 /dev/ttyS0 0 >>> s = os.stat('/dev/ttyS0') >>> tuple(s) (8624, 9064L, 769L, 1, 0, 14, 0L, 1058628788, 774488935, 1058628789) >>> s.st_rdev 1088 >>> divmod(1088, 256) (4, 64) -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ Get married, but never to a man who is home all day. \__/ George Bernard Shaw From ktilton at nyc.rr.com Thu Aug 21 11:59:26 2003 From: ktilton at nyc.rr.com (Kenny Tilton) Date: Thu, 21 Aug 2003 15:59:26 GMT Subject: What's better about Ruby than Python? References: <3F41505F.69D18CC8@alcyone.com> <66d7kvonvb2n0nqbqahhd5roak7ur81sob@4ax.com> <3f43ef5d_4@127.0.0.1> <3F440A35.9030602@nyc.rr.com> <4o_0b.1665$Ej6.1182@newsread4.news.pas.earthlink.net> <8D01b.1721$Ej6.702@newsread4.news.pas.earthlink.net> Message-ID: <3F44ED2E.9070308@nyc.rr.com> Alex Martelli wrote: > Andrew Dalke wrote: > > >>Alex Martell: >> >>>... def __get__(self, obj, cls): >>>... self.obj = obj >>>... return self.cached_call >> >>That's the part where I still lack understanding. >> >>class Spam: >> def f(self): >> pass >> f = CachedCall(f) > > > That's an oldstyle class -- use a newstyle one for smoothest > and most reliable behavior of descriptors > > >>obj = Spam() >>obj.f() >> >>Under old-style Python >> obj.f is the same as getattr(obj, "f") > > > This equivalence holds today as well -- the getattr > builtin has identical semantics to direct member access. > > >> which fails to find 'f' in the instance __dict__ >> so looks for 'f' in the class, and finds it >> This is not a Python function, so it does not >> get bound to self. It's simply returned. >> >> obj.f() takes that object and calls it. In my original >> code (not shown) I tried implementing a __call__ >> which did get called, but without the instance self. > > > Sure. > > >>Under new-style Python >> obj.f is the same as getattr(obj, "f") > > > Yes. > > >> which fails to find 'f' in the instance __dict__ so >> looks for 'f' in the class, and finds the CachedCall. > > > Sure. > > >> Python checks if the object implements __get__, >> in which case it's called a descriptor. If so, it's > > > Exactly. > > >> called with the 'obj' as the first parameter. The >> return value of this call is used as the value for >> the attribute. >> >>Is that right? > > > Yes! So what is it that you say you don't get? > > > >>>should closely mimic your semantics, including ignoring >>>what I call obj and you call self in determining whether >>>a certain set of argumens is cached. >> >>Why should obj make a difference? There's only >>one CachedCall per method per .... Ahh, because it's >>in the class def, not the instance. Adding support for >>that using a weak dict is easy. > > > If obj is such that it can be used as a key into a dict > (weak or otherwise), sure. Many class instances of some > interest can't -- and if they can you may not like the > result. COnsider e.g. > > class Justanyclass: > def __init__(self, x): self.x = x > def compute(self, y): return self.x + y > > pretty dangerous to cache THIS compute method -- because, > as a good instance method should!, it depends crucially > on the STATE of the specific instance you call it on. > > > >>Yeah, and my approach won't work with kwargs nor any >>other unhashable element. Since I didn't know what the >>Lisp code did nor how Lisp handles unhashable elements, >>I decided just to implement the essential idea. > > > An automatically cachable method on general objects is > quite tricky. Lisp hashtables can key off any Lisp datum, but... > I don't think the Lisp code did anything > to deal with that trickiness, No, it did not. That snippet was from a toy (and incomplete) implementation of my more elaborate Cells package. the toy was developed over the keyboard during a talk I gave on Sunday. The next step would have been to determine when the closure had best re-execute the code body to see if the world had changed in interesting ways, but that is a big step and requires dependency tracking between cells. Once a Cell is told an input has changed, it re-runs its body to see if it comes up with a different result, in which case it caches that and tells other dependents to rethink their caches. So what is shown in my example is fun but halfbaked. I was just trying to show how a macro could hide the plumbing of an interesting mechanism so the reader can focus on the essence. -- kenny tilton clinisys, inc http://www.tilton-technology.com/ --------------------------------------------------------------- "Career highlights? I had two. I got an intentional walk from Sandy Koufax and I got out of a rundown against the Mets." -- Bob Uecker From aleax at aleax.it Thu Aug 7 13:28:57 2003 From: aleax at aleax.it (Alex Martelli) Date: Thu, 07 Aug 2003 17:28:57 GMT Subject: Bug? If not, how to work around it? References: <2259b0e2.0308070919.2bedce6@posting.google.com> Message-ID: Michele Simionato wrote: > Gon?alo Rodrigues wrote in message news: >> So, is it a bug? In other words, should I open a bug report? >> >> With my best regards, >> G. Rodrigues > > I would open a bug report; at the best this is a documentation bug, I disagree that it's a documentation bug. > since > the fact that ___getattr__ is skipped by special methods is never The language reference says: """ A class can implement certain operations ... by defining methods with special names. """ This is VERY explicit -- "__getattr__ is skipped" is false (the __getattr__ a *metaclass* could define would indeed be used as equivalent to the class defining methods) -- the _class_'s __getattr__ if any is irrelevant because it's used on class *instances* (as the language reference also says a few pages later) and thus it's not the *CLASS* that's defining "methods with special names" here. If anything, a mention might be warranted that, for compatibility, a bug is retained in old-style classes, whereby, in addition to the class's ability to define methods with special names, any old-style class INSTANCE may also define them (e.g. through __getattr__) in contrast with what the docs have just said about the general case. I do suspect that the peculiarities of old-style classes are not well documented today, more generally than just this tidbit, alas. Alex From hjwidmaier at web.de Fri Aug 22 16:32:07 2003 From: hjwidmaier at web.de (Hans-Joachim Widmaier) Date: Fri, 22 Aug 2003 22:32:07 +0200 Subject: tarfile woes References: Message-ID: Am Fri, 22 Aug 2003 11:40:13 +0200 schrieb Lars Gustaebel: >> - bzip2 compressed files cannot be read from a "fake" (StringIO) file >> object, only from real files. > > Much to my regret, this is a limitation of the bz2 module which is used. Ooh, haven't noticed that myself. That's really sad. >> - It does not handle compressed (.Z) archives. > > This is sad, too, but IMO tolerable for most people. Yes, certainly. Those shouldn't be existent anymore, anyhow. It's just that I made a test run of my class on a directory full of source archives and got an exception there. > As you observed by yourself ZipInfo's naming scheme is inconsistent and I > didn't find it a good idea to adopt this mindlessly. Also, I found an > integer value for mtime much more versatile than a tuple. I guess its stored in the zipfile that way, but this is one of the internals I'm really not interested in, as an integer value loses absolutely nothing. Or, even better, have all dates and times uniformly represented by the new DateTime class. > Your criticism is justified. And I'm sure that in the future a > standardized and extensible interface to archive manipulation could emerge > *if* people just want it badly enough (and someone does all the work :-). I'm afraid the ones who want it ought to be the ones who do the work. Who else would have any interest in doing it? This is maybe the downside of free software - nobody gets paid writing the pieces nobody wants to. > Let's wait and see. I'd rather *do* something. If anything, I would really love to write new modules/classes instead of ranting. But, as I already tried to explain, I'm simply not good enough for the job. Which leaves me, of course, with just one option: take what you get and be grateful. Despite my current problems with tarfile (btw, there are other modules/classes that insist on a _filename_ [gdk.pixbuf, i.e.]), it enabled me to write a little backup tool just when I needed it in almost no time. So I have reason to be grateful. :-) Waiting-and-seeing'ly yours hjw From jjl at pobox.com Wed Aug 27 07:54:24 2003 From: jjl at pobox.com (John J. Lee) Date: 27 Aug 2003 12:54:24 +0100 Subject: ClientCookie bug (followup) References: <87oeypdh92.fsf@pobox.com> <87k79a25pi.fsf@pobox.com> <87isos0zng.fsf@pobox.com> <87ptis39kp.fsf@pobox.com> <877k506ukq.fsf@pobox.com> Message-ID: <87wucz48pb.fsf@pobox.com> cartermark46 at ukmail.com (Mark Carter) writes: [...] > > All of this is explained in the web page, though. > > You are right! All the technical information is there. But can I > suggest a change in the docs that might spell it out a bit more > obviously to someone coming to the module from fresh? Something > like: Certainly! [...] > h2: Using Internet Explorer or Netscape/Mozilla cookies > > c = ClientCookie.MSIECookieJar(delayload=1) # see note 1 > c.load_from_registry(username='joe bloggs') # see note 2 > opener = ClientCookie.build_opener(ClientCookie.HTTPCookieProcessor(c)) > > url = 'http://foo.bar.com/' > response = opener.open(url) > > print response.info() # headers > print response.read() # body Possibly, but there's a balance to be struck between convenience and documentation bloat. Since "Cooperating with Netscape/Mozilla and Internet Explorer" explains the CookieJar part, and the very next section is "Using your own CookieJar instance", it seems to flow quite well to me. The first sentence of that section is kind of misleading though, so I'll change that. [...] > 2. Usually only win98 and 95 users need supply the username. As an > alternative > to loading from the registry, consider using the line > c.load_cookie_data('cookie-file.txt') > instead. Thanks -- worthwhile addition. [...] > should be at the top, where people will see it first, and before > those more complicated examples. It is at the top -- after an example of the simplest usages and an explanation of what CookieJar is actually for, which I think have to come first. John From nenad.propadovic at partner.bmw.de Fri Aug 8 11:36:45 2003 From: nenad.propadovic at partner.bmw.de (Propad) Date: 8 Aug 2003 08:36:45 -0700 Subject: COM server usage question Message-ID: Hello everybody, I created a simple COM server, by copy and paste of the first example from the book by Mark Hammond. I registered the server, and was able access its functionallity from another python script, and from Word. Then I tried accessing the server from another tool (which is my real task). The problem was, it was not in the dropdown list of servers usable by the tool. The alternative was to specify a position of the server, by giving in the location of a .exe or .dll or .tlb file. So after browsing my registry and this newsgroup for a (long) while, my conclusion is: -all com servers in the mentioned drop-down list are entries in the HKEY_CLASSES_ROOT\TypeLib registry entry -in order to get my server into that list, I have to somehow specify that before registration. My guess would be I need to somehow use the _reg_options_ attribute. But if, how? -as an alternative I could write an *.IDL file, compile it to *.tbl, and feed that into the calling tool. I've seen the example given at the c_types page. But how do I know what entries to put into the *.idl file? Meaning specifically the GUID-s. I'm sure theese are allready somewhere in the registry, so I can't just go and create new ones. Can the GUID-s for the type library, interface and implementig class be derived from the GUID I used when creating the server? And also, where do I get a working midl - compiler? I found two on my computer, but neither seems to be working, asking for a cl compiler. I thank you kindly for your help. Regards, Nenad Propadovic From mpeuser at web.de Sun Aug 31 06:24:49 2003 From: mpeuser at web.de (Michael Peuser) Date: Sun, 31 Aug 2003 12:24:49 +0200 Subject: list.sort(func) speed References: Message-ID: "Peter Otten" <__peter__ at web.de> schrieb im Newsbeitrag news:bisf20$na3$01$1 at news.t-online.com... > Michael Peuser wrote: > > > It drove me nearly crazy when I detected that os.path split and join > > operations took even longer than raw disk access in a directory scan > > program.... > > Now, that was a fast disk :-) I fear, that some data was already in the > cache when your improved version was executed. Please post some sample > code/timings for the unbelieving. I did some weeks ago: news:bhd9vg$1s7$05$1 at news.t-online.com... > > > Please note that all os.path functions are *awfully* slow! If ever > > possible use a nonportable self made scheme. > > If ever possible, use a *portable* scheme shipped with the distribution. > Chances are that it is ahead of your ad hoc solution in terms of > correctness. If you have written code that greatly improves on the current > implementations, you might consider submitting a patch... I am definitly on your side what general portability is concerned. However the format of file names is quite well defined and had not changed in Windows Unix and MacOs for a long time ;-) It depends of course on your clients and they generally work with Windows and are happy when you say it *could* run on Unix. (I am a little bit unhappy about the situation in this NG, where a lot of posters are not aware of expectations, requirements and needs of Windows users. There *is* competition in the Windows market!) > > > (The other issue (decorated sorting) is more relevent of course.) > D'accord. Namely, basename() is not the bottleneck here. Of course not - this was a side isssue. Reducing a factor of a quadratic problem is generally better than a linear speed-up. Though it depends on the order of magnitude ;-) Kindly Michael P From garyr at fidalgo.net Mon Aug 25 23:23:40 2003 From: garyr at fidalgo.net (Gary Richardson) Date: Mon, 25 Aug 2003 20:23:40 -0700 Subject: Tk Canvas text question Message-ID: I've been working on a Python version of Andreas Weber's ASCII schematic drawing program ( http://www.tech-chat.de) ; not that I thought I could do it better but just as a programming exercise. I've managed to put together something that more or less works but I'm puzzled by the way ASCII characters are displayed on a Canvas window. For example, in the code below (which produces my crude representation of an OpAmp), why are two leading blanks required in the text of the second create_text statement to cause the vertical bar to be aligned with the one above it? And why does the number of trailing blanks affect the position of the beginning of a line. In the first two statements trailing blanks are required because of the backslash. But if a trailing blank is not included in the last create_text statement the beginning of the displayed line is shifted to the right one character. Additional trailing blanks shifts the line further to the left. The other lines are similarly affected if additional trailing blanks are added to the text. I'm using ActivePython 2.2.2, build 224 on Win98SE. Thanks, Gary Richardson from Tkinter import * root = Tk() canvas = Canvas(root, width=400, height=200, bg='white' ) canvas.pack() font=('courier', 8) canvas.create_text(40, 20, text='-|\ ', font=font) canvas.create_text(40, 30, text=' | \ ', font=font) canvas.create_text(40, 40, text=' | /', font=font) canvas.create_text(40, 50, text='-|/ ', font=font) root.mainloop() From mack at incise.org Fri Aug 15 23:23:03 2003 From: mack at incise.org (mackstann) Date: Fri, 15 Aug 2003 22:23:03 -0500 Subject: dict->XML->dict? Or, passing small hashes through text? In-Reply-To: References: <20030815042536.GA19960@incise.org> Message-ID: <20030816032303.GA22065@incise.org> On Fri, Aug 15, 2003 at 09:24:10AM +0200, Fredrik Lundh wrote: > > xmsg would now be a string such as: > > '1hellotext' > > (that's not valid XML: there can be only one toplevel element in an > XML document. that's easy to fix, of course) Yes, I am nowhere near an XML expert, and heh, now that I look at it, I have no idea why it made sense to me to have ... , but it was just a mockup. :) > here's a minimal implementation, based on my ElementTree module: > > > you can get the elementtree source code via this page: > > http://effbot.org/zone/element-index.htm I actually had downloaded the elementtree source and was looking through it, but had not had time to work out any test or prototype yet. > if the XML format doesn't really matter, you can use Python's > standard xmlrpclib module: > > import xmlrpclib > > def xmlMessage(dict): > # dumps requires a tuple > return xmlrpclib.dumps((dict,)) > > def xmlMessage2dict(message): > result, method = xmlrpclib.loads(message) > return result[0] # unwrap This is perfect! I am now using this, and it works pretty much exactly how I want it to work. Days and days of googling, reading, looking through code, etc.. and it comes down to a 6 line answer. :) I came to the conclusion that SimpleXMLRPCServer didn't fit well within my program, since the server basically just reads the messages into a queue (a Queue.Queue to be precise), and the program clears them out every so often and takes action in its own way. The server is pretty passive, and I saw no point in changing that. Thanks, everyone that replied! -- m a c k s t a n n mack @ incise.org http://incise.org Murphy's Law of Research: Enough research will tend to support your theory. From max at nospam.com Mon Aug 4 12:19:18 2003 From: max at nospam.com (max) Date: Mon, 04 Aug 2003 16:19:18 GMT Subject: packaging windows services? In-Reply-To: References: Message-ID: > I have a patch sitting on the SF py2exe page which does this and more, > I hope I can work on this during this week. > > OTOH, you can change the startup options of the service (and the user > account it uses) with the control panel services applet. > > Thomas Hi Tom, I was looking in the CVS on sf for this one, could you tell me where it's sitting? And yes, I know about the applet, just my users don't :) max. From logistix at cathoderaymission.net Sun Aug 31 14:39:22 2003 From: logistix at cathoderaymission.net (logistix at cathoderaymission.net) Date: 31 Aug 2003 11:39:22 -0700 Subject: Win32 documentation in CHM? References: Message-ID: <3c91a864.0308311039.51c61a30@posting.google.com> Robin Becker wrote in message news:... > It seems the Gods are proposing to distribute the documentation and help > for Python-2.3.1 in .chm form. I particularly detest .chm and much > prefer .html as it works across all platforms. Additionally by having a > single index.html for all of the various bits of Python help I can link > in things like Pmw, PIL and Quick Guide etc with a simple text editor. > > The argument is made that .chm is a better mechanism (more searchable > indexable etc) for help/documentation than html. Is that really so? HTML > is at least an open standard. I don't think there is any intention to discontinue generation of HTML, PDF, and other formats of the documentation. You can currently get it here: http://www.python.org/ftp/python/doc/2.3/ and presumably http://www.python.org/ftp/python/doc/2.3.1/ once it's released. They are just changing the Windows default install to provide standard Windows help files. Windows is currently the only platform where documentation is installed by default. A standard 'make && make install' on ohter doesn't do anything with the documentation. Everyone else has to download it anyways, or use the magical incantations necessary to generate it from the LaTeX source. From martin at v.loewis.de Sat Aug 30 21:28:04 2003 From: martin at v.loewis.de (Martin v. =?iso-8859-15?q?L=F6wis?=) Date: 31 Aug 2003 03:28:04 +0200 Subject: Cyclic references et C libraries References: <3f39f329$0$16171$626a54ce@news.free.fr> Message-ID: Fabien SK writes: > One solution would be to wrap the parent objet in a new class > (forwarding all the calls to the parent object). In the "__del__" > method of this class, I would clean the list of children object, and > then remove the reference on the parent objet so its "__del__" method > will be called. Am I right ? I would not wrap the parent object, but the file handle. So do class Handle: def __init__(self, *args): self.h = lib_open(*args) def read_section(self, *args): return lib_read_section(self.h, *args) def __del__(self): lib_close(self.h) class Parent: def __init__(self, ...): # change # self.handle = lib_open(...) # to self.Handle(...) Then, the Handle class won't participate in a cycle, and it can safely have an __del__. > Last question: why does the python file objects not have a "__del__" > method ? How the file can be closed when the last reference is remove > ? If a Python type is implemented in C, it does not need to have an __del__. Instead, having a tp_del slot in its PyTypeObject C structure is sufficient. Regards, Martin From newsgroups at jhrothjr.com Tue Aug 19 13:00:59 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Tue, 19 Aug 2003 13:00:59 -0400 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: <3F41208F.40021A68@engcorp.com> Message-ID: "Doug Tolton" wrote in message news:gui4kvcnh64s5pnl8v625ito0lb9cm7405 at 4ax.com... > On Mon, 18 Aug 2003 20:18:09 -0400, "John Roth" > wrote: > > >I've been on c.l.py for around two years. Your statement > >is rude and assumes things you have not bothered to check > >out. > > > >There is a very simple rule for dealing with trolls, which most > >usenet newbies learn sooner or later. If you think someone is > >trolling, simply ignore them. Don't answer their posts, don't > >comment on them, don't even give them the gratification of > >a reply that says: "plonk!" Just killfile them and quit wasteing > >bandwidth. You've got better things to do with your time than > >maintaining an interaction that you find aggrevating. > > You're right, I did make an assumption that you were new to the group. > A lot of people who are new make posts just like you did. Saying we > shouldn't be too harsh on Brandon, after a while they realize maybe he > is just a troll. > > Perhaps my post was a bit rude, I shouldn't have automatically assumed > you were new to this NG, although I am a bit baffled at hearing a long > time c.l.p reading calling Every anything but a troll. You have to > admit, that is atypical. The standard usenet definition of a troll is someone who posts on a contentious (and usually off-topic) subject with the sole objective of stiring up reactions. I've only seen two classes of reaction to his posts: people who call him names, and people who respond to his question in a reasonable, thoughtful, and factual manner. That's not a troll. The questions may be ill-posed, they may not be questions that are all that comfortable for the self-satisfied to deal with, but questions of how Python stacks up against some other language do go to the issue of how Python should evolve in the future. As I said in another subthread of this thread, there is a standard usenet recommendation for dealing with people you think are trolls. Simply don't respond. Don't send them any response whatsoever. If their only purpose is to elicit responses, that strategy won't satisfy them, and they'll eventually go away. People are quite capable of making up their own minds about whether or not someone is making a useful contribution to the group, without a lot of other people running around screaming: "The sky is falling, we've got a troll." John Roth > > > Doug Tolton > (format t "~a@~a~a.~a" "dtolton" "ya" "hoo" "com") From pedro.werneck at bol.com.br Sun Aug 17 19:35:12 2003 From: pedro.werneck at bol.com.br (Pedro Werneck) Date: Sun, 17 Aug 2003 23:35:12 +0000 Subject: Python form oriented library In-Reply-To: References: Message-ID: <20030817233512.2e3b0ef1.pedro.werneck@bol.com.br> Freddie... I think you replied to the wrong thread... Seems like "hex(-5) => Futurewarning: ugh, can't we have a better hex than '-'[:n<0]+hex(abs(n)) ??" is the one you want... On 18 Aug 2003 12:17:16 +1000 Freddie wrote: > Caleb Land wrote in > news:pan.2003.08.17.20.21.45.109000 at rochester.rr.com: > > > Hello, > > I'm writing a small business accounting type program where the interface > > is a bunch of forms that represent tables in a database. The interface is > > usually used completely with the keyboard, but the mouse may also be used. > > > > The software does POS, inventory, accounting, etc. > > > > The widgets are mostly text entries. > > > > Are there any Python libraries that are targetted to this style of > > interface? > > > > If not, does anybody have references to libraries/resources in other > > languages that might be helpful in designing my own (APIs, design > > documents, etc)? > > > > I've tried googling, but I don't know exactly how to word my request. > > > > Sincerely, > > Caleb Land > > (bokonon at rochester.rr.com) > > > > What about crazy people like myself? If you generate a crc32 value with zlib, > you occasionally get a negative number returned. If you try to convert that > to hex (to test against a stored CRC32 value), it spits out a FutureWarning > at me. How rude :) So you end up with stupid things like this in your code: > > > # Disable FutureWarning, since it whinges about us making bad hex values :( > import warnings > try: > warnings.filterwarnings(action='ignore', category=FutureWarning) > except NameError: > del warnings > > -- > Remove the oinks! > -- > http://mail.python.org/mailman/listinfo/python-list From Stephen.Boulet at no.spam.motorola.com Fri Aug 22 12:50:00 2003 From: Stephen.Boulet at no.spam.motorola.com (Stephen Boulet) Date: Fri, 22 Aug 2003 11:50:00 -0500 Subject: Embedding a chart in excel In-Reply-To: <221d8dbe.0308212104.c4e45@posting.google.com> References: <221d8dbe.0308212104.c4e45@posting.google.com> Message-ID: There seems to be a problem with UseExcel.setcell: >>> a.setcell(sht1.Name,1,(1,1)) Traceback (most recent call last): File "", line 1, in ? File "excel_from_google.py", line 139, in setcell sht.Cells(row, col).Font.FontSize = fontSize File "C:\Python23\lib\site-packages\win32com\client\dynamic.py", line 504, in __setattr__ raise AttributeError, "Property '%s.%s' can not be set." % (self._username_, attr) AttributeError: Property '.FontSize' can not be set. srijit at yahoo.com wrote: > Hello, > Refer the following link: > http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&frame=right&th=6eaef82c8c0d9548&seekm=37ee60c8.0308202344.f470d26%40posting.google.com#link11 > > Does it help you? If it doesn't, let me know what improvements are > required. > > Regards, > Srijit > > Stephen Boulet wrote in message news:... > >>I'm having trouble scripting Excel to embed a chart from python. >> >>Say I have created a sheet object and a workbook object, "xlSheet" and >>"xlBook". >> >>Creating a chart in front of my sheet is as easy as: >> >>xlSheet.Select() >>xlChart = xlBook.Charts.Add() >> >>Now how do I tell it to go embed itself in my sheet? In VBA, it might be >>something like: >> >>xlChart.Location Where:=xlLocationAsObject, Name:=xlSheet.Name >> >>Thanks. >> >>(Is there a newsgroup/list with more of a focus on issues like this than >>c.l.py?) >> >>-- Stephen From rupole at hotmail.com Wed Aug 6 01:46:31 2003 From: rupole at hotmail.com (Roger Upole) Date: Tue, 5 Aug 2003 22:46:31 -0700 Subject: Win32All Crashes Python 2.3? References: Message-ID: <3f30680c_4@corp-news.newsgroups.com> I get the same thing on Win2k, Python 2.3 anytime a unicode string is passed to os.lstat (without invoking any win32all modules) ... Looks like the problem is in posixmodule.c PyUnicodeObject *po; if (PyArg_ParseTuple(args, wformat, &po)) { wformat at run time is "u:lstat", which should have a unicode pointer for the receiving argument, not a PyUnicodeObject. os.stat (which works for a unicode string) uses uppercase U in the format. Roger "Tim Daneliuk" wrote in message news:jchngb.pr.ln at boundary.tundraware.com... > Some time ago I wrote a portable file system browser, twander, that, > when runnning on Win32, will make use of the Win32All extensions if they > are present on the target system. (http://www.tundraware.com/Software/twander) > > twander primarily uses Win32All to get file attribute and ownership > information back in Win32-specific ways each time a new directory is > entered. (Ordinarily (if Win32All is not installed), it just displays an > 'ls -al' style output and dummies up ownership and group membership.) > > Now the problem - twander has worked fine with previous versions of > Python/Win32All up to and including 2.2.x. It also works fine > with 2.3. HOWEVER, if I install any of the 2.3 relevant versions > of Win32All, when I change to a new directory, Python crashes. > No traceback information is given so I cannot determine exactly > why this is happening. What is strange is that the program > starts OK, which means it is using Win32All calls to determine > file system information for the initial directory. It is only > upon changing directories that Python gets blown out of the water. > > While it is certainly possible that this is a bug in my code, I > cannot imagine what it might be. The program has worked flawlessly > on a wide variety of Unix/FreeBSD/Win32 systems with no reports > of this sort of thing. > > Anyone have any ideas what could cause this? Is this a reported > Win32All bug? > > TIA, > -------------------------------------------------------------------------- -- > Tim Daneliuk tundra at tundraware.com > PGP Key: http://www.tundraware.com/PGP/ > From jfmoxley at mit.edu Fri Aug 29 16:20:10 2003 From: jfmoxley at mit.edu (Joel) Date: 29 Aug 2003 13:20:10 -0700 Subject: nested data structures in classes References: Message-ID: Does anyone have any thoughts on this? Joel Forrest Moxley wrote in message news:... > Greetings python-list! > > The good news is that I've been having a blast with Python since early > Spring. I've had great success in both learning the language from online > / usegroup resources and implementing it in one of my projects. However, > I can't pretend to be an expert, and I do not have a strong comp sci > background. > > This is a question that I've had for a while. Usually, I'll stumble > across the answer with repeated attempts and re-searching the groups, but > I didn't have luck with this one, even in a Dietel book I picked up at the > library. I'm assuming there's an obvious answer, so maybe ya'll can save > me some time. > > My Python use involves organizing nested list information. In a > simplified example, you could imagine a list of reactants and products in > a chemical reaction. Thus, > > len(nested_list_of_reactants) = len(nested_list_of_products) => "number of > reactions" > where: nested_list_of_reactants[i] => "list of reactants for reaction i" > where: nested_list_of_reactants[i][j] => "reactant j of reaction i" > > And so forth. Obviously, there are many attributes associated with a > specific reaction. Currently, I just pass these attribute lists (nested > and non-nested) into and out of functions. However, I'd like to be able > to create a class that would streamline this. > > E.g., (this is a MATLAB structure whose qualities I'd like to emulate): > reaction(27).name = 'fawlty towers' > reaction(27).reactant(2).name = 'john cleese' > > Currently, I'd have a list and a nested list to take care of this... > reaction_name[27] = 'fawlty towers' and reactants[27][2] = 'john cleese' > if this makes sense. > > Any thoughts or suggestions on this type of data structuring would be > greatly appreciated. Python love, Joel From mwh at python.net Thu Aug 28 13:25:30 2003 From: mwh at python.net (Michael Hudson) Date: Thu, 28 Aug 2003 17:25:30 GMT Subject: Advice to a Junior in High School? References: Message-ID: <7h3k78x66jt.fsf@pc150.maths.bris.ac.uk> Roy Smith writes: > Tom Plunket wrote: > > Learn Python, learn C++, learn Lisp. Understand what you like > > and don't like about each of these languages. > > The most imporant thing you can learn in school is how to learn. > Especially in a fast-moving technology field, most of the cutting-edge > stuff you learn in school is going to be routine in 5 years and obsolete > in 10. I'm sure there are people who learnt ML during the CS program at Cambridge more than five years ago... -- Two things I learned for sure during a particularly intense acid trip in my own lost youth: (1) everything is a trivial special case of something else; and, (2) death is a bunch of blue spheres. -- Tim Peters, 1 May 1998 From jarausch at igpm.rwth-aachen.de Thu Aug 21 05:48:12 2003 From: jarausch at igpm.rwth-aachen.de (Helmut Jarausch) Date: Thu, 21 Aug 2003 11:48:12 +0200 Subject: csv documentation error? (was Re: csv - howto specify fmtparam parameters) In-Reply-To: References: Message-ID: <3F44955C.3020206@igpm.rwth-aachen.de> Many thanks for the hint, still I am curious: is the documentation in error? It says class DictReader(csvfile,fieldnames[,restkey=None[,dialect='excel' [,fmtparam]]]) and the documentation for 'reader' says The other optional parameter 'fmtparam' keyword arguments can be given to override individual formatting parameters, see section, ``Dialects and Formatting Parameters'' and there ... In addition to, or instead of, the 'dialect' parameter, the programmer can alos specify individual formatting parameters, which have the same names as the attributes defined above for the 'Dialect' class. Peter Otten wrote: > Seems that the docs are wrong. The following should work: > > import csv > csv_file = file('test.csv') > > class MyDialect(csv.excel): > lineterminator = "\n" > > dr = csv.DictReader(csv_file,['Matr','Name','Vorname','PZ','MP'],\ > dialect=MyDialect) > > for s in dr: > print s > > Peter > Helmut Jarausch wrote: > import csv > csv_file= file('test.csv') > Inp= csv.DictReader(csv_file,['Matr','Name','Vorname','PZ','MP'],\ > lineterminator='\n') > for S in Inp: > print S > but I get > Traceback (most recent call last): > File "/home/jarausch/Python/My/test_csv.py", line 5, in -toplevel- > lineterminator='\n') > TypeError: __init__() got an unexpected keyword argument 'lineterminator' > What went wrong? -- Helmut Jarausch Lehrstuhl fuer Numerische Mathematik RWTH - Aachen University D 52056 Aachen, Germany From gregbrunet at NOSPAMsempersoft.com Sat Aug 30 02:17:14 2003 From: gregbrunet at NOSPAMsempersoft.com (Greg Brunet) Date: Sat, 30 Aug 2003 01:17:14 -0500 Subject: Add two dicts References: <86ktkvkd05e88hu14hjudmfvbul7slfgkt@4ax.com> <3F4EDF7A.C9CF6DA3@alcyone.com> <0mrtkv8b1bnnk1v310kf3b8tmjo8d9higo@4ax.com> Message-ID: "Alex Martelli" wrote in message news:BjE3b.7850$aG6.251286 at news1.tin.it... > Afanasiy wrote: > > > On Thu, 28 Aug 2003 22:07:06 -0700, Erik Max Francis > > wrote: > > > >>Afanasiy wrote: > >> > >>> Can I add two dicts in a way which is not cumbersome to the above % > >>> string > >>> operation? Is this another case of writing my own function, or does a > >>> builtin (or similar) already exist for this? > >> > >>combinedDict = aDict.copy() > >>combinedDict.update(anotherDict) > >> > >>If that's cumbersome, don't really know what you'd consider > >>non-cumbersome. > > > > Don't really know if you're asking, but : > > > > vars(self)+{'x':'123','y':'345'} > > > > I would consider that non-cumbersome. ;-) > > So, what about: > > def dict_add(adict, another): > result = adict.copy() > result.update(another) > return result > > and then dict_add(vars(self), {'x':'123','y':'345'}) ? But in fact > you can do even better...: > ... lots of other good ideas... But what about something like this: >>> class xdict(dict): ... def __add__(self,dict2): ... result = self.copy() ... result = result.update(dict2) ... I was hoping that would allow: >>> a=xdict({'y': 456, 'x': 111}) >>> b=xdict({'y': 444, 'z': 789}) >>> a+b but instead of the result which I hoped for, I get the following: Traceback (most recent call last): File "", line 1, in ? TypeError: unsupported operand type(s) for +: 'xdict' and 'xdict' So I can't implement '+' operator for dictionaries - why not? -- Greg From shagshag13 at yahooPLUSDESPAM.fr Sun Aug 31 06:36:26 2003 From: shagshag13 at yahooPLUSDESPAM.fr (shagshag13) Date: Sun, 31 Aug 2003 12:36:26 +0200 Subject: list as paremeters... Message-ID: <3f51ce6e$0$26843$626a54ce@news.free.fr> hello, i have an unexpected behaviour that i didn't understand, can someone explain this to me ? >>> def doit(s, stack = []): if s == '': return stack stack.append(s[:1]) return doit(s[1:], stack) >>> doit('this') ['t', 'h', 'i', 's'] >>> doit('this') ['t', 'h', 'i', 's', 't', 'h', 'i', 's'] >>> doit('this') ['t', 'h', 'i', 's', 't', 'h', 'i', 's', 't', 'h', 'i', 's'] and so on ... i would expect it to stuck to >>> doit('this') ['t', 'h', 'i', 's'] why does this 'stack' remind of previous call ? thanks. From llothar at web.de Mon Aug 18 19:05:35 2003 From: llothar at web.de (Lothar Scholz) Date: 18 Aug 2003 16:05:35 -0700 Subject: python threads on multi-CPU machines References: Message-ID: <6ee58e07.0308181505.150f2fc5@posting.google.com> Thomas Womack wrote in message news:... > If I have a dual-processor hyperthreaded machine (so with four CPU > contexts), will a python program distribute threads over all four > logical processors? Okay others told you already about the GIL. > I ask because I'm fairly sure that this *does* happen using the > threading extensions in MFC, and fairly sure that it *doesn't* when > using Java, Of couse java *does* this. It's the number one reason for SUN to develop and maintain Java: selling a reason to buy some of there overpriced multiprocessor machines. Maybe you don't know anything about Java. From rmunn at pobox.com Thu Aug 21 14:55:52 2003 From: rmunn at pobox.com (Robin Munn) Date: Thu, 21 Aug 2003 18:55:52 GMT Subject: ClientCookie bug (followup) References: <87fzk4sav2.fsf@pobox.com> <87znibzrnx.fsf@pobox.com> <87oeypdh92.fsf@pobox.com> <87k79a25pi.fsf@pobox.com> <84fc4588.0308182207.4c649b93@posting.google.com> <87ada5de3j.fsf@pobox.com> <84fc4588.0308200242.3e74e0a1@posting.google.com> <87smnwh3lp.fsf@pobox.com> Message-ID: John J. Lee wrote: > pythonguy at Hotpop.com (Anand Pillai) writes: > [...] >> 'We', nothing royal about it. It is just me and my friend >> & co-developer Nirmal Chidambaram. Apparently he has found >> a way around some of the bugs in Clientcookie. He has written > > It'd be great if you made me aware what those bugs are! > > (BTW, no intent to offend with my comment about your plurality, or > lack thereof -- it's just that the convention of using 'we' in source > code comments is common enough that I've sometimes found myself using > it even when writing code alone, which is funny.) I do that all the time; "we" is the default in my code comments and I have rarely, I think never, used "I". I usually think of it as myself reading through the code with another coder, who is tasked with taking over code maintenance from me. I'm explaining to him what the code is intended to do: "So here, we want to search through the list for..." -- Robin Munn | http://www.rmunn.com/ | PGP key 0x6AFB6838 -----------------------------+-----------------------+---------------------- "Remember, when it comes to commercial TV, the program is not the product. YOU are the product, and the advertiser is the customer." - Mark W. Schumann From code at joecheng.com Tue Aug 12 02:03:21 2003 From: code at joecheng.com (Joe Cheng) Date: Tue, 12 Aug 2003 06:03:21 GMT Subject: Python vs. C# References: Message-ID: > > I don't think that "static typing" (Python is strongly typed btw., > > just to correct your statement) > > It is? Then I'm confused, because around here people keep talking about the > beauty of avoiding types. Python is "strongly" typed in the sense that every object has a type. It is not "statically" typed in that references do not have types. Statically typed languages generally require you to declare variable types (some languages infer them) and in return you get compile-time warnings when you try to call methods that do not exist or perform casts that are semantically impossible. I may be wrong but I believe C is an example of a language with static weak typing... you have to declare variable types and some types of errors can be caught at compile time, but you can perform unsafe casts and not only will the compiler not stop you but at runtime you won't get an exception--just a possibly corrupted value in memory. Java and C# have static strong typing. Python has dynamic strong typing. So, if you can keep the types of your objects straight without the help of the compiler, you get the benefits of a concise syntax while enjoying type safety at runtime. Someone correct me if I've gotten it wrong... From mpeuser at web.de Sat Aug 16 15:44:37 2003 From: mpeuser at web.de (Michael Peuser) Date: Sat, 16 Aug 2003 21:44:37 +0200 Subject: How to terminate a TkinterApp correctly? References: <3F3DFCF4.5020109@aon.at> <3f3e37c6$0$19888$91cee783@newsreader01.highway.telekom.at> <3F3E84DA.8040905@aon.at> Message-ID: "Gregor Lingl" schrieb im Newsbeitrag news:3F3E84DA.8040905 at aon.at... > Michael Peuser schrieb: .... > > Why don't you just return? The mainloop can handle everything!? > > Example: > > def exit(self): > > self.done=1 > > return > > > Here I apparently don't understand something fundamental: > what is the effect of a return statement as the last statement > of a function? Nothing, just an indicator to make clear that this is the end of the procedure... > Moreover: If I put this into the cv.master.protocol ... I cannot > close the application at all. (Because the original is not restored. > And I don't want to need a second mouseclick as in your first example.) This is a misunderstanding. Closing your application has nothing to do with closing some window and even less with where a stupid user clicks on ;-) You can destroy a widget with "destroy"; when the root widget is destroyed then the Tkinter mainloop terminats by convention. Nothing to do with your program!! See this example: --------------------------- from Tkinter import * def killingAction(): l.master.destroy() def kidding(): l.config(text="just kidding") l=Button(text="Kill me!",command=killingAction) l.pack() l.master.protocol("WM_DELETE_WINDOW",kidding) mainloop() print "here we are- ready for whatever we want" ----------------------- From mpeuser at web.de Sun Aug 31 13:11:32 2003 From: mpeuser at web.de (Michael Peuser) Date: Sun, 31 Aug 2003 19:11:32 +0200 Subject: list as paremeters... References: <3f51ce6e$0$26843$626a54ce@news.free.fr> Message-ID: "Mel Wilson" schrieb im Newsbeitrag news:obgU/ks/KbsM089yn at the-wire.com... > In article , > "Ulrich Petri" wrote: > >IIRC Default values are not created each time the function called but rather > >only the first time (am i correct here?). And since a list is mutable it > >"rememberes" the previous value. > > Default values are created when the 'def' statement is > executed, This seems to be generally a somewhat underestimated issue... See this example: while c: b=Button(...) b.config(command=lambda x=b: doSomething(x)) This would not work otherwise... Kindly Michael P From vanevery at 3DProgrammer.com Mon Aug 18 14:32:23 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Mon, 18 Aug 2003 11:32:23 -0700 Subject: What's better about Rattlesnakes than Pythons? References: <8e482ba2.0308171939.7de4a288@posting.google.com> Message-ID: Andrew Dalke wrote: > > Would Rattlesnake or Python be better at de-mousing my house? > Do either come with an IDE? (Infestation Devouring Engine) > Do either need a lot of support? Are there books on the topic? I think snakes tend to swallow their prey and then go dormant for awhile. But, maybe that's just for really big prey. A python is much bigger than a rattlesnake, so would probably eat more meeces for you. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From mickey at tm.informatik.uni-frankfurt.de Sat Aug 30 10:15:12 2003 From: mickey at tm.informatik.uni-frankfurt.de (Michael 'Mickey' Lauer) Date: 30 Aug 2003 14:15:12 GMT Subject: ANN: Python for arm-linux feed Message-ID: My feed @ http://opie.net.wox.org/python has been updated. Highlights: - Python 2.3 - PyQt 3.8 - PyXML 0.8.3 - PySQLite 0.4.3 Known to work on the following platforms: - Compaq iPAQ w/ familiar-linux - Compaq iPAQ w/ OpenEmbedded - SIEMENS SIMpad w/ OpenSIMpad - Sharp Zaurus 5x00 and C7x0 w/ SharpROM - Sharp Zaurus 5x00 and C7x0 w/ OpenZaurus Cheers, Mickey. From bokr at oz.net Mon Aug 11 21:36:33 2003 From: bokr at oz.net (Bengt Richter) Date: 12 Aug 2003 01:36:33 GMT Subject: Finding the path to a file References: <20030811231134.19113.qmail@web41205.mail.yahoo.com> Message-ID: On Mon, 11 Aug 2003 16:45:17 -0700, Trent Mick wrote: >[Todd Johnson wrote] >> So basically, I want to know how to find the directory >> my script is in, even when it is invoked from another >> directory. Any help would be greatly appreciated. > >The __file__ global is there for that. Note that in some versions of >Python (<= 2.2 maybe) __file__ was not defined with >__name__=="__main__". If you are running one of these versions of Python >then add this snippet in your module: > > if __name__ == "__main__": > import sys > __file__ = sys.argv[0] > > # __file__ is now the fullpath to your script ^^^^ Well, not guaranteed. Try going to the script directory and typing python myscript.py I think you might need os.path.abspath(sys.argv[0]) # untested Regards, Bengt Richter From wtrenker at shaw.ca Thu Aug 14 12:05:54 2003 From: wtrenker at shaw.ca (William Trenker) Date: Thu, 14 Aug 2003 16:05:54 +0000 Subject: Searching the Bug List Message-ID: <20030814160554.2cb84a87.wtrenker@shaw.ca> I decided to run the Python 2.3 test suite on my Linux system. I noticed that test_time failed so I ran the test individually and got the traceback listed below. I see in a search on the Python site that this was reported in May 2003. So I wondered if this was supposed to be fixed for the 2.3 release. Of course I don't want to report bugs that are already reported and still open so I tried to search the bug list. I was hoping to search on the string "test_time" but on the Sourceforge bug page but there doesn't seem to be a place to type in a general search string. Is the bug list available as a download that can be searched? Thanks, Bill /src/Python-2.3/Lib/test# python test_time.py test_asctime (__main__.TimeTestCase) ... ok test_clock (__main__.TimeTestCase) ... ok test_conversions (__main__.TimeTestCase) ... ok test_data_attributes (__main__.TimeTestCase) ... ok test_sleep (__main__.TimeTestCase) ... ok test_strftime (__main__.TimeTestCase) ... ok test_strptime (__main__.TimeTestCase) ... ok test_tzset (__main__.TimeTestCase) ... FAIL ====================================================================== FAIL: test_tzset (__main__.TimeTestCase) ---------------------------------------------------------------------- Traceback (most recent call last): File "test_time.py", line 107, in test_tzset self.failUnless(time.tzname[1] == 'AEDT', str(time.tzname[1])) File "/usr/local/lib/python2.3/unittest.py", line 268, in failUnless if not expr: raise self.failureException, msg AssertionError: AEST ---------------------------------------------------------------------- Ran 8 tests in 2.357s FAILED (failures=1) Traceback (most recent call last): File "test_time.py", line 129, in ? test_main() File "test_time.py", line 125, in test_main test_support.run_unittest(TimeTestCase) File "/usr/local/lib/python2.3/test/test_support.py", line 262, in run_unittest run_suite(suite, testclass) File "/usr/local/lib/python2.3/test/test_support.py", line 247, in run_suite raise TestFailed(err) test.test_support.TestFailed: Traceback (most recent call last): File "test_time.py", line 107, in test_tzset self.failUnless(time.tzname[1] == 'AEDT', str(time.tzname[1])) File "/usr/local/lib/python2.3/unittest.py", line 268, in failUnless if not expr: raise self.failureException, msg AssertionError: AEST From mpeuser at web.de Thu Aug 7 04:35:59 2003 From: mpeuser at web.de (Michael Peuser) Date: Thu, 7 Aug 2003 10:35:59 +0200 Subject: itertools.ilen? References: Message-ID: "Terry Reedy" schrieb im Newsbeitrag news:tpKdnUQ75tjOZKyiU-KYuQ at comcast.com... > > "Jeremy Fincher" wrote in message > news:bgsqj5$228$1 at news.cis.ohio-state.edu... > > Sometimes I find myself simply wanting the length of an iterator. > > An iterator is a function/method that traverses (or possibly > generates) a seqeuence. The sequence has a length (actual or > potential) but the iterator does not. > Very well explained. There are lots of usefull generators with unlimited sequences. - random generators - def achilles(): while 1 :N=1. yield N n=n/2 - def schoenberg(): cycle=range(12) while 1: shuffle(cycle) for i in cycle: yield i There is no way to determined, whether such generartors will come to an end - The Halting Problem for Turing Machines ;-) Thus there will never be a safe len(iterator). Kindly Michael From eric.brunel at pragmadev.com Tue Aug 5 03:40:55 2003 From: eric.brunel at pragmadev.com (Eric Brunel) Date: Tue, 05 Aug 2003 09:40:55 +0200 Subject: Tkinter programming problem References: <2830c89c.0308010048.403a2a19@posting.google.com> <2830c89c.0308040201.7c70695d@posting.google.com> Message-ID: klappnase wrote: >> >># Demonstration TK interface Windows application >># Runs ok from within IDLE >># >>from Tkinter import * >> >>class CommonStuff: # to get common access to variables and functions >> def __init__(self, frame): >> self.frame = frame >> >> def say_hi(self): >> print "Hello all" >> >> >>class MyWidgets(Frame, CommonStuff): >> def __init__(self, CS): >> Frame.__init__(self, CS.frame) >> self.quitbutton = Button(self, text='Quit', fg='red', >>command=self.destroy) >> self.quitbutton.pack(side=LEFT) >> self.hi_there = Button(self, text='Hello', command=CS.say_hi) >> self.hi_there.pack(side=LEFT) >> >> >>class Application: >> def __init__(self, master): >> self.frame=Frame(master) >> CS = CommonStuff(self.frame) >> >> displayedwidget=MyWidgets(CS) >> displayedwidget.grid(row=0, column=0) >> self.frame.grid(row=0, column=0) >> displayedwidget.bind("", self.quit) >> self.frame.update() >> >> def quit(self, event): >> print"Quitting..." >> self.frame.destroy() # Destroy frame and all children >> >> >>root = Tk() >>mainWin = Application(root) >>root.mainloop() > > > I think you could have it easier, if you just want to exit you > application with the quit button: > > class MyWidgets(Frame, CommonStuff): > def __init__(self, CS): > Frame.__init__(self, CS.frame) > self.quitbutton = Button(self, text='Quit', fg='red', > command=self.quit) > self.quitbutton.pack(side=LEFT) > self.hi_there = Button(self, text='Hello', command=CS.say_hi) > self.hi_there.pack(side=LEFT) > > def quit(self): > print "Quitting..." > sys.exit(0) This works, but actuallly quits the application immediatly. So if you happen to have code after the call to the Tk mainloop, it won't be executed, which might not be what you want. Moreover, there's already a quit method defined on MyWidgets, inherited from Frame, that does exactly what you want: quitting the Tk mainloop. So you could just do: def quit(self): print "Quitting..." Frame.quit(self) > If you want to run it from within the interpreter (I am not sure if it > is that what you are trying) the following might work too: > > class Application: > def __init__(self, master): > self.frame=Frame(master) > CS = CommonStuff(self.frame) > > displayedwidget=MyWidgets(CS) > displayedwidget.grid(row=0, column=0) > self.frame.grid(row=0, column=0) > displayedwidget.bind("", self.quit) > self.frame.update() > > self.master = master > > def quit(self, event): > print"Quitting..." > self.master.destroy() # Destroy root window This may also work, but the most common way is the one I describe above. If you want to do it here, you can do: def quit(self, event): print "Quitting..." self.master.quit() AFAIK, all Tkinter widgets have a quit method that will quit the Tk mainloop. HTH -- - Eric Brunel - PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com From krzysztof at py142.wroclaw.sdi.tpnet.pl Thu Aug 21 04:49:19 2003 From: krzysztof at py142.wroclaw.sdi.tpnet.pl (Krzysztof Kaczkowski) Date: Thu, 21 Aug 2003 10:49:19 +0200 Subject: wxTreeItemData bug wxPython? Message-ID: Hello Im having problem, my class inherit in wxTreeItemData. (Python2.3 i wxPython2.4.1.2u) class MyTreeItemData (wxTreeItemData): def __init__(self, name): wxTreeItemData.__init__(self) self.name_key = name def TEST(): pass part my class MywxListCtrl inherit in wxListCtrl: item_data = MyTreeItemData('Test') itm = self.AppendItem(a1, a2, -1,-1,item_data) print dir(self.GetItemData(itm)) and my problem: Function dir(self.GetItemData(itm)) not list MyTreeItemData, MyTreeItemData not assign, dir(...) list only default class wxTreeItemData why? > print dir(self.GetItemData(itm)) ['Destroy', 'GetClassName', 'GetData', 'GetId', 'SetData', 'SetId', '__doc__', '__init__', '__module__', '__repr__', 'this', 'thisown'] >print dir(item_data) ['Destroy', 'GetClassName', 'GetData', 'GetId', 'SetData', 'SetId', 'TEST', '__doc__', '__init__', '__module__', '__repr__', 'name_key', 'this', 'thisown'] Thank you. From NTNotes/SERVERS/Excelsior_College at excelsior.edu Sun Aug 24 03:04:19 2003 From: NTNotes/SERVERS/Excelsior_College at excelsior.edu (NTNotes/SERVERS/Excelsior_College at excelsior.edu) Date: Sun, 24 Aug 2003 03:04:19 -0400 Subject: SAV detected a violation in a document you authored. Message-ID: Please contact your system administrator. The infected component in the scanned document was deleted. Violation Information: The attachment thank_you.pif contained the virus W32.Sobig.F at mm and was deleted. From __peter__ at web.de Tue Aug 5 03:27:04 2003 From: __peter__ at web.de (Peter Otten) Date: Tue, 05 Aug 2003 09:27:04 +0200 Subject: Classes in Python References: <14dsivkn40c0grotsti39cgsrde7v03hq4@4ax.com> Message-ID: Wiebke P?tzold wrote: > Could somebody help me with a task? As You seem to know not much about Python, instead of messing around with classes I would recommend the simplest aproach I can think of (not knowing the Mk4py package), which would be: import Mk4py db = Mk4py.storage("c:\\datafile.mk", 1) vw = db.view("people") for r in vw: nachname = vw[r.index].Nachname if nachname.startswith("Ge"): print nachname If this works, take it for now, and if you can spare some time, read the Python tutorial (It's very good). You can always refine your code, once it is running :-) Peter From rtw at freenet.REMOVE.co.uk Sun Aug 3 20:19:19 2003 From: rtw at freenet.REMOVE.co.uk (Rob Williscroft) Date: 04 Aug 2003 00:19:19 GMT Subject: popen eating quotes? References: Message-ID: Bryan wrote in news:LOgXa.57808$o%2.28737 at sccrnsc02: >>>> import os >>>> def run_args(arg): > ... i, o = os.popen4('"c:/program files/test/args.bat" -vv %s' % arg) > ... print o.read() > ... >>>> run_args('"this is a very long path with spaces"') > 'c:/program' is not recognized as an internal or external command, > operable program or batch file. > > I just got the following working where os.getcwd() is returning: 'C:\\Documents and Settings\\Rob\\Desktop' >>> def f(): ... i, o = os.popen4( "\"" + os.getcwd() + "\\aaa.bat\"" ) ... print o.read() ... i.close() ... o.close() ... If this dosen't help, then (sound of large hammer being removed from a tool box) maybe this will: def g(arg): x = os.getcwd() os.chdir( "c:/program files/test/" ) i, o = os.popen4( 'args.bat -vv %s' % arg ) os.chdir( x ) print o.read() Rob. -- http://www.victim-prime.dsl.pipex.com/ From steinhardt at inpro.de Thu Aug 7 07:01:39 2003 From: steinhardt at inpro.de (x-herbert) Date: 7 Aug 2003 04:01:39 -0700 Subject: py2exe: "ImportError: No module named pywintypes" ...?? :-( Message-ID: <39c0c7.0308070301.190dff6a@posting.google.com> Hi, I have a small test to "compile" al litle script as a WMI-Tester. The script include a wmi-wrapper and "insert" the Win32-modeles. here the code: my "WMI-Tester.py" ----- import wmi computer = wmi.WMI () for item in computer.Win32_Process (): print item ----- the WMI-Wrapper ---- ... import win32com.client import pywintypes ... => look at http://tgolden.sc.sabren.com/python/wmi.html ----- the py2exe-setup.py ----- from distutils.core import setup setup(name="WMI_tester", scripts=["WMI_tester.py"],) ----- and the error at "setup.py py2exe": >>> running py2exe running build running build_scripts not copying WMI_tester.py (up-to-date) running install_scripts not copying build\scripts-2.2\mailtest.py (output up-to-date) not copying build\scripts-2.2\script11.py (output up-to-date) not copying build\scripts-2.2\watchdog.py (output up-to-date) not copying build\scripts-2.2\wmi.py (output up-to-date) not copying build\scripts-2.2\WMI_tester.py (output up-to-date) +---------------------------------------------------- | Processing script WMI_tester.py with py2exe-0.4.1 +---------------------------------------------------- Searching modules needed to run 'WMI_tester.py' on path: ['C:\\Dokumente und Einstellungen\\steinha\\Eigene Dateien\\WinProcess\\PythonProc\\build\\bdist.win32\\winexe\\lib\\Programme\\ActivePython22\\Lib\\site-packages', '', 'C:\\Programme\\ActivePython22\\Lib\\site-packages\\Pythonwin', 'C:\\Programme\\ActivePython22\\Lib\\site-packages\\win32', 'C:\\Programme\\ActivePython22\\Lib\\site-packages\\win32\\lib', 'C:\\Programme\\ActivePython22\\Lib\\site-packages', 'C:\\Programme\\ActivePython22\\DLLs', 'C:\\Programme\\ActivePython22\\lib', 'C:\\Programme\\ActivePython22\\lib\\lib-tk', 'C:\\Programme\\ActivePython22', 'C:\\Programme\\ActivePython22\\lib\\site-packages\\Numeric', 'C:\\Programme\\ActivePython22\\lib\\site-packages\\PIL', 'C:\\Dokumente und Einstellungen\\steinha\\Eigene Dateien\\WinProcess\\PythonProc'] Traceback (most recent call last): File "C:\Programme\ActivePython22\Lib\site-packages\Pythonwin\pywin\framework\scriptutils.py", line 301, in RunScript exec codeObject in __main__.__dict__ File "C:\Dokumente und Einstellungen\steinha\Eigene Dateien\WinProcess\PythonProc\setup-py2exe.py", line 7, in ? setup(name="WMI_tester", scripts=["WMI_tester.py"],) File "C:\Programme\ActivePython22\lib\distutils\core.py", line 138, in setup dist.run_commands() File "C:\Programme\ActivePython22\lib\distutils\dist.py", line 893, in run_commands self.run_command(cmd) File "C:\Programme\ActivePython22\lib\distutils\dist.py", line 913, in run_command cmd_obj.run() File "C:\Programme\ActivePython22\Lib\site-packages\py2exe\build_exe.py", line 604, in run mf.import_hook(f) File "C:\Programme\ActivePython22\Lib\site-packages\py2exe\tools\modulefinder.py", line 126, in import_hook q, tail = self.find_head_package(parent, name) File "C:\Programme\ActivePython22\Lib\site-packages\py2exe\tools\modulefinder.py", line 180, in find_head_package raise ImportError, "No module named " + qname ImportError: No module named pywintypes In the python-enviroment works the script fine - why the import-error??? CU Ingolf From aleax at aleax.it Wed Aug 6 07:25:32 2003 From: aleax at aleax.it (Alex Martelli) Date: Wed, 06 Aug 2003 11:25:32 GMT Subject: managing stdout and stderr neatly while doing parallel processing References: Message-ID: Grant Edwards wrote: ... > 3) use a pseudo-terminal (pty) so that your child process is running in a > more "natural" environment, and you'll get both stderr and stdout that > way too. Don't know if there's handy Python "pty" module or not... Well, there's http://www.python.org/doc/current/lib/module-pty.html , but I'm not sure if it counts as "handy"? Alex From ejy712 at comcast.net Sun Aug 10 06:50:12 2003 From: ejy712 at comcast.net (Ed Young) Date: Sun, 10 Aug 2003 06:50:12 -0400 Subject: obj.__dict__ expected behavior or bug? References: Message-ID: Thank you all for the kind and detailed explanations. I now have a thorough understanding of the mechanism behind attribute lookup. From graham__fawcett at hotmail.com Mon Aug 18 23:42:51 2003 From: graham__fawcett at hotmail.com (Graham Fawcett) Date: 18 Aug 2003 20:42:51 -0700 Subject: Path Problem on W2K? References: <93f5c5e9.0308170927.6e0bdc38@posting.google.com> Message-ID: hokiegal99 at hotmail.com (hokiegal99) wrote in message news:<93f5c5e9.0308170927.6e0bdc38 at posting.google.com>... > I installed Python-2.3 into c:\Program Files\Python23 on a new W2K SP4 > computer. When I write a Python script and run it from the command > prompt, I get the following error: > > C:\>python 'name-of-script.py' > 'python' is not recognized as an internal or external command, > operable program or batch file. > > Here's what my path contains: > > C:\>path > PATH=C:\WINNT\system32;C:\WINNT;C:\WINNT\System32\Wbem;"C:\Program > Files\Norton > SystemWorks\Norton Ghost\";C:\Program Files\SSH Communications > Security\SSH Secu > re Shell > > Any ideas? I've reinstalled and rebooted several times. Also tried > adding c:\Program Files\Python23 to my path... still get the error. Just a thought, but the SUBST command still works in Win2K. C:\>subst /? Associates a path with a drive letter. SUBST [drive1: [drive2:]path] Substitute drive letter "P" for C:\Program Files\python23. Then, add P:\ to your path. Benefits? No nasty spaces, a much shorter path, and quick access to the Python directory when you're at the command line (just type "P:"). (To be fair, assigning P: to c:\Program Files, and adding P:\python23 to your path, is probably an idea with more mileage in it.) I haven't used this specifically myself (I install python in c:\python##), but I have often SUBST'd the drive letter S: for \python##\lib\site-packages when I'm studying the code of a recently-installed package. Much easier to pop open an editor window, or a Explorer window, to "S:\somepackage" than its longer counterpart. It might be quite fun to go SUBST-happy and transform all those lonely unassigned drive letters into contributing members of society. Perhaps U: could map to c:\Documents and Settings, W: could map to %WINDIR%, X: to the folder where you hide your illicitly-gained MP3's... It would be best to do the SUBST before login or service startup. I *think* you can still use an autoexec.bat file in Win2K, but there's a formal "startup script" approach that is blessed by Microsoft. Search MS support for "How to Run a Batch File Before Logging on to Your Computer". Hope it helps. -- Graham From mpeuser at web.de Thu Aug 21 14:56:14 2003 From: mpeuser at web.de (Michael Peuser) Date: Thu, 21 Aug 2003 20:56:14 +0200 Subject: how fast is Python? References: <3f43e5cf$0$49115$e4fe514c@news.xs4all.nl> Message-ID: "David McNab" schrieb im Newsbeitrag news:pan.2003.08.21.09.07.20.100414 at 127.0.0.1... > On Thu, 21 Aug 2003 06:40:04 +0200, Michael Peuser paused, took a deep > breath, then came out with: > > > A bottleneck can be Tkinter. Use something different then (Qt, wx).. > > Wow! > > I've found wx to be way slower than Tkinter. > > On a P133 running Win98, a McMillan-compiled prog using wx took twice as > long to start up as a similar prog implemented in Tkinter. Of course! The wx DLL is mor ethan 6 MB whilest Tcl/Tk still keeps around 1. I am not talking about start up. When you have ever used a Canvas with a 600x800 Image oder with a thousend items or a TIX HList with a dozend diffently styled columns you might know WHAT I am talking about. Even with less filled widgets, most of what you perceive as "lazy" with e.g. games is generally not the Python but the Tcl interpreter. Pygame shows that you can dio fast visualisation with Python. Kindly Michael P From donn at drizzle.com Sat Aug 30 02:25:21 2003 From: donn at drizzle.com (Donn Cave) Date: Sat, 30 Aug 2003 06:25:21 -0000 Subject: Celebrity advice References: <000701c36ce7$a6ff24d0$0c02a8c0@Arts> <0o6dneIqn_m8KNKiU-KYvw@comcast.com> Message-ID: <1062224719.576690@yasure> Quoth "Terry Reedy" : | "Cliff Wells" wrote in message | news:mailman.1062150716.7297.python-list at python.org... |> I'd have to agree with Art on this. ESR's thoughts on guns have little |> to do with programming, and unless he likes to use "nra" or "bullet" as |> metavariables, his politics would best be omitted from the discussion. | | I recomment his new book The Art of Unix Programming | (text online here http://catb.org/~esr/writings/taoup/) | to anyone interested in the topic. I skimmed through the opening chapters there, and for me I think there's a thread of similarity between the political thinking I've read attributed to him here, and how he writes about UNIX. Not that the politics are similar, just that I think I would indeed encourage the reader to take some caution with his account of what UNIX is about with a grain of salt, as with the politics. Compare with what you know from experience, and if it seems like one or the other must be an illusion, it isn't you. Of course that applies to any author, I don't mean to be particularly critical of this one and there may be stuff in there of great practical value. Donn Cave, donn at drizzle.com From max at alcyone.com Tue Aug 19 18:56:47 2003 From: max at alcyone.com (Erik Max Francis) Date: Tue, 19 Aug 2003 15:56:47 -0700 Subject: Why does this (not) work? References: Message-ID: <3F42AB2F.97C25A43@alcyone.com> "Michael C. Neel" wrote: > Hmmm, can't say I like what this implies. In one case % is shorthand > for a sprintf function, the other it's a mathematical expression at > the > same level of precedence of * and /. But the sprintf version is > "granted" the precedence of the mathematical version? What's the > logic > behind that? Very, very good logic. Consider the following expression: left % middle * right If we are to take your suggestion, and % is to have different precedence based on whether or not it is being used as a string formatting operation or as module division, then the precedence will be left % (middle * right) or (left % middle) * right depending on the type of `left'. That means that the precedence changes based on the types of the arguments. That is disastrous in a dynamic language like Python for both processing and readability, because now it means the same expression can have widely different semantic meanings based on their arguments. Having the same operator have different precedence based on its operands would be disastrous. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ A wise man never loses anything if he have himself. \__/ Montaigne From altis at semi-retired.com Sun Aug 3 22:28:39 2003 From: altis at semi-retired.com (Kevin Altis) Date: Sun, 3 Aug 2003 19:28:39 -0700 Subject: HOME Directory in posix and nt References: Message-ID: <4rjXa.669$2o5.152313@news.uswest.net> On Window you probably want to use the USERPROFILE environment variable. If you do attempt to use HOME first then check to make sure it is a valid directory to avoid the problem of an unexpanded %USERPROFILE% variable for HOME... PythonCard uses this strategy for its configuration files. os.environ['USERPROFILE'] On Windows 2000: \Documents and Settings\%UserName% I think XP uses the same location as Win2K. On Windows NT 4.0: \Winnt\Profiles\%UserName% On Windows 98: \Windows\Profiles\%UserName% On Windows Me: \Windows\Profiles\%UserName% On Windows 2000 after upgrading from Windows NT 4.0: \Winnt\Profiles\%UserName% Somewhere there is an KB or MSDN article about this, but I can't seem to find it. ka "J?rg Maier" wrote in message news:bgisu6$oi9ct$1 at ID-181971.news.uni-berlin.de... Hey, ist there a possibility to get the users homedirectory as environment variables %HOMEPATH% or $HOME. there must be a way to see system variables other than stdout = os.popen('{ echo $HOME } 2>&1 ', 'r') on posix and stdout = os.popen('echo %HOMEPATH% 2>&1', 'r') with home = stdout.readline() ??? -- Hi I am a signature virus. Please copy me to your .signature file to help me spread. From martin at v.loewis.de Sun Aug 31 17:18:49 2003 From: martin at v.loewis.de (Martin v. =?iso-8859-15?q?L=F6wis?=) Date: 31 Aug 2003 23:18:49 +0200 Subject: Update to Python 2.3 on Red Hat Linux 9 References: <8242f4a7.0308282240.4c87f997@posting.google.com> Message-ID: bokr at oz.net (Bengt Richter) writes: > >> Or do I really need to find out all the libraries in use with > >> 2.2.2 and compile these for 2.3? > > > >Yes. > > > Is this highly automated, or a gross PITA? Can you elaborate? What is this "this" you are referring to? And what do you mean by "highly automated"? Regards, Martin From strong at multisuns.com.tw Thu Aug 7 05:42:28 2003 From: strong at multisuns.com.tw (strong) Date: Thu, 7 Aug 2003 17:42:28 +0800 Subject: cgi in win2000 have multi-user problem.... Message-ID: <000801c35cc8$37f14840$b501a8c0@strong> may you help me?? thanks!! I want to establish a environment to server multi-user in win2000 I run a cgi-multithread-server program,its name is cgisrv.py and I write two programs to test it, one is named as test.py,another is result.py test.py : it has a form and a submit button,submit to result.py, it's just a html page result.py : use time.sleep(10) to wait 10 seconds,show the time before it and after it IN WINDOW98 AND LINUX :a. I open single IE to conncet to the test.py and click the button ,it's correctly, I can see the correct message b.I open IE Browser 3 times TO connect to the test.py and click the button at the same time, 3 browsers all has the correct message IN WINDOW2000: a. I open single IE to conncet to the test.py and click the button ,it's correctly, I can see the correct message b. But when I open IE Browser 3 times TO connect to the test.py and click the button at the same time, the lastest clicked browser has correctly message, the first and second browser occur error anybody can resolve this problem ............ please help me..... thank you~ These are my 3 programs: -------------cgisrv.py---------------- import SocketServer import BaseHTTPServer import MyCGIHandler import time class MyThreadingMixIn: def process_request_thread(self, request, client_address): try: self.finish_request(request, client_address) self.close_request(request) except: print "MyThread::Except" self.handle_error(request, client_address) self.close_request(request) def process_request(self, request, client_address): """Start a new thread to process the request.""" import threading t = threading.Thread(target = self.process_request_thread, args = (request, client_address)) t.start() class MyCGIServer(MyThreadingMixIn, BaseHTTPServer.HTTPServer): def close_request(self, request): print "Svr::close_req() >> [%s]\n" % time.asctime() import sys server = MyCGIServer(('', 80), MyCGIHandler.MyCGIHandler) try: while 1: sys.stdout.flush() print "Running.." server.handle_request() except KeyboardInterrupt: print "Finished" --------------------test.py----------------- import cgi print "Content-type: text/html" print print "" print "" print "" print "
" print "" print "
" print "" -------------------result.py----------------- import cgi,time print "Content-type: text/html" print print "" print "" print "" print time.localtime() print "
" time.sleep(10) print "
" print time.localtime() print "" -------------- next part -------------- An HTML attachment was scrubbed... URL: From nospam at maniacxs.de Tue Aug 12 13:58:51 2003 From: nospam at maniacxs.de (Lukas Kasprowicz) Date: Tue, 12 Aug 2003 19:58:51 +0200 Subject: Problem with computing...addition References: Message-ID: Thank you Aahz wrote: > In article , > Lukas Kasprowicz wrote: >> >>So you see e.g. the 15th entry: "131.99000000000001" >>there should be "131.99" and not this. >> >>who could help? > > http://www.python.org/doc/current/tut/node14.html -- --------------------------------------------------------- Das einzige Mittel gegen Aberglauben ist Wissenschaft. (Henry Thomas Buckle) From tim.one at comcast.net Fri Aug 8 00:21:10 2003 From: tim.one at comcast.net (Tim Peters) Date: Fri, 8 Aug 2003 00:21:10 -0400 Subject: [Python] Re: Building extensions with mingw32 -- bdist_wininst fails. In-Reply-To: <006101c35d60$6d0cb9e0$1f00000a@house> Message-ID: [Chris Gonnerman] > ... > Well, now I'm not sure. Is the installer binary from > python.org built with MSVC 6 Yes. From Hilbert at panka.com Sun Aug 24 14:10:31 2003 From: Hilbert at panka.com (Hilbert) Date: Sun, 24 Aug 2003 18:10:31 -0000 Subject: visual indentation References: Message-ID: Thanks for all the suggestions! I like both the tuple and the if 1: approach. I don't want to define blocks in functions because that would actually differ from how the RIB stream works. I'd like to have my code reflect a real RIB stream. Thanks again, Hilbert hilbert at panka.com In article , Hilbert wrote: > Hello, > > I'm using python to output RIB streams for Renderman. > The RIB stream is a bunch of statements which describes > a 3d image. The Rib standard allows for blocks which we > usually indent for better visualization for example: > > WorldBegin > Color [1 1 1] > Surface "constant" > Sphere(1.0, -1.0, 1.0, 360) > WorldEnd > > I'm using CGKit in python which has a Renderman binding, > so to output the same RIB I'd write: > > RiWorldBegin() > RiColor(1.0,1.0,1.0) > RiSurface('constant') > RiSphere(1.0,-1.0,1.0,360) > RiWorldEnd() > > But I get an error, because python interprets my indentation > as a block in the python code. So the only way to write this > is without the indentation: > > RiWorldBegin() > RiColor(1.0,1.0,1.0) > RiSurface('constant') > RiSphere(1.0,-1.0,1.0,360) > RiWorldEnd() > > But this is a lot harder to read. > > Is there any way to use such "visual" indentation in python? > > Thanks, > Hilbert > > hilbert at panka.com > > From eddie at holyrood.ed.ac.uk Mon Aug 4 13:06:45 2003 From: eddie at holyrood.ed.ac.uk (Eddie Corns) Date: Mon, 4 Aug 2003 17:06:45 +0000 (UTC) Subject: how to convert ip address to dot notation References: Message-ID: Ruslan Spivak writes: >Hello, python users! >I have ip addresses in my mysql db in int value - 3232261127, for example. >How can i convert that to usual dot notation like 192.168.100.7? mysql itself can do this, use inet_ntoa() eg select inet_ntoa (...) from ... or alternatively use inet_aton() inside the query eg: select ... from ... where x = inet_aton ('192.168.100.7') Eddie From dipankarweb at yahoo.co.in Tue Aug 5 05:07:34 2003 From: dipankarweb at yahoo.co.in (Dips) Date: 5 Aug 2003 02:07:34 -0700 Subject: Python WMI Event Handler - Consumer Message-ID: <915e0a69.0308050107.4f85a2f0@posting.google.com> Python Gurus, Is it possible to write python WMI event consumer using event handler rather than polling WMI? I got the equivalent C# code snippet from http://www.ondotnet.com/pub/a/dotnet/2003/04/07/wmi.html using System; using System.Management; using System.Collections; class WSMonitor { bool pleaseContinue = true; public void doit() { try { int processId = System.Diagnostics.Process.GetCurrentProcess().Id; int workingSet = 30000000; string wqlQuery = String.Format( @"SELECT * FROM __InstanceModificationEvent WITHIN 1 WHERE TargetInstance ISA 'Win32_Process' AND TargetInstance.ProcessId = {0} AND TargetInstance.WorkingSetSize >= {1} AND PreviousInstance.WorkingSetSize < {2} ", processId, workingSet, workingSet); WqlEventQuery query = new WqlEventQuery(wqlQuery); ManagementEventWatcher watcher = new ManagementEventWatcher(query); watcher.EventArrived += new EventArrivedEventHandler(onEvent); watcher.Start(); ArrayList array = new ArrayList(); for (int i = 0; pleaseContinue; ++i) { array.Add(1); if (i % 1000 == 0) System.Threading.Thread.Sleep(1); } watcher.Stop(); } catch (ManagementException e) { Console.WriteLine("Management exception: " + e); } } public void onEvent(object sender, EventArrivedEventArgs e) { pleaseContinue = false; Console.WriteLine("You're a big boy now!"); } } Thanks From newsgroups at jhrothjr.com Mon Aug 18 20:11:10 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Mon, 18 Aug 2003 20:11:10 -0400 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: <3F41208F.40021A68@engcorp.com> <3F413F8C.47AAE514@engcorp.com> Message-ID: "Peter Hansen" wrote in message news:3F413F8C.47AAE514 at engcorp.com... > John Roth wrote: > > > > "Peter Hansen" wrote: > > > What is it about code blocks that would let "save *me* a buttload of work > > > and make *my* life sooooo much easier"? > > > > It's not so much code blocks. It's that Ruby's syntax gives you one code > > block for > > free in every method call. And the Ruby library is organized so that the > > facility > > is useful, which Python's isn't (or at least, it isn't as useful.) > > > > All of the Ruby collections implement a .each method, which is essentially > > a version of the Visitor pattern. If I want to do something to every element > > in a list or a dict (or any kind of collection,) all I have to do is say > > something > > like (using Python syntax): > > > > collectObj.each() > > > > In Python, that's either a lambda (which restricts what you can do with it,) > > or a named function (which is overkill a huge amount of the time.) And you > > have to worry about distinctions between functions and methods. In other > > words, it's a mess compared to Ruby. > > > > Now, you can say: "We've got that with map()." Well, we've got it when > > your inputs are either lists (or implement the correct protocol) but the > > result is a list, it's not an internal modification to the object's state. > > > > You can also say: we can do that with for. Well, duh. For is a > > statement, not a method call. > > So what you seem to be saying is that Ruby has some features which > in some cases can save some time or somewhat simplify code that when > written in Python would take slightly longer or be slightly more > complicated. (This probably underemphasizes the value you place on > such a thing, but I think that's the gist of it.) > > While I do acknowledge that Python is often touted as a great solution > over other languages just because it saves time and simplifies the > resulting solutions, I'm not clear on why these few small differences > would amount to a *TOTALLY COMPELLING* reason, to anyone, to use Ruby > over Python. I don't know either. I do know of several posters on the XP lists, however, who have switched from Python to Ruby, and I doubt that it was corporate pressure in any of their cases. If you're interested (which most of the posters here are not - I'm certainly not) you might check with them. I'm sure Phlip, for one, would be more than happy to say why he switched, and what made the difference. John Roth > > -Peter From graham at rockcons.co.uk Thu Aug 7 14:28:21 2003 From: graham at rockcons.co.uk (Graham Nicholls) Date: Thu, 07 Aug 2003 19:28:21 +0100 Subject: Extracting a short using struct - won't print. References: <3f3273f7$0$10777$afc38c87@auth.uk.news.easynet.net> <3F32758E.5734C64F@engcorp.com> <3f32779d$0$10780$afc38c87@auth.uk.news.easynet.net> <3f327aaf$0$10770$afc38c87@auth.uk.news.easynet.net> <3F3294C4.20760CA2@engcorp.com> Message-ID: <3f329a45$0$10775$afc38c87@auth.uk.news.easynet.net> Peter Hansen wrote: > Graham Nicholls wrote: >> >> >> don't I! > > Yes, you do! :-) Sorry for not being more obvious about the answer, > and I thought you might figure it out yourself by using the "import pdb" > trick I showed. "Teach a man to fish" and all that. Too tired to fish, but thanks, I suspect will be a useful technique. Graham > > -Peter -- Graham Nicholls Rock Computer Consultancy From heikowu at ceosg.de Wed Aug 6 23:11:09 2003 From: heikowu at ceosg.de (Heiko Wundram) Date: 07 Aug 2003 05:11:09 +0200 Subject: classes (table) In-Reply-To: <0dq1jv8lr19gph86urpi214bjpb3tlskkh@4ax.com> References: <0dq1jv8lr19gph86urpi214bjpb3tlskkh@4ax.com> Message-ID: <1060225869.7044.16.camel@d168.stw.stud.uni-saarland.de> On Wed, 2003-08-06 at 13:49, Wiebke P??tzold wrote: > but the user of the program should have the possibility to select in > wich column the search takes place. If you're not willing to start thinking Python and read some documentation before asking questions as these (have you ever seriously programmed before? If not, go read the tutorials on http://www.python.org), I guess there's no reason I'd help you. Unless you pay for my programming time, of course... Heiko. PS: I know Alex Martelli has answered already, but I just thought that it might be worth noting that Wiebke is simply asking the group to write a program she needs, which is not what I think comp.lang.python is for... From mpeuser at web.de Fri Aug 15 11:23:49 2003 From: mpeuser at web.de (Michael Peuser) Date: Fri, 15 Aug 2003 17:23:49 +0200 Subject: cPickle alternative? References: Message-ID: Hi, I have no idea! I used a similar scheme the other day and made some benchmarks (I *like* benchmarks!) About 6 MB took 4 seconds dumping as well as loading on a 800 Mhz P3 Laptop. When using binary mode it went down to about 1.5 seconds (And space to 2 MB) THis is o.k., because I generally have problems beeing faster than 1 MB/sec with my 2" drive, processor and Python ;-) Python 2.3 seems to have even a more effective "protocoll mode 2". May be your structures are *very* complex?? Kindly Michael P "Drochom" schrieb im Newsbeitrag news:bhiqlg$9qj$1 at atlantis.news.tpi.pl... > Hello, > I have a huge problem with loading very simple structure into memory > it is a list of tuples, it has 6MB and consists of 100000 elements > > >import cPickle > > >plik = open("mealy","r") > >mealy = cPickle.load(plik) > >plik.close() > > this takes about 30 seconds! > How can I accelerate it? > > Thanks in adv. > > > From cbarber at curl.com Wed Aug 13 18:34:42 2003 From: cbarber at curl.com (Christopher Barber) Date: 13 Aug 2003 18:34:42 -0400 Subject: Python vs. C# References: <3f357a9b@shknews01> Message-ID: "Terry Reedy" writes: > "Christopher Barber" wrote in message > news:pso8yq0b1d3.fsf at bandit.curl.com... > > "Terry Reedy" writes: > > > > > "Brandon J. Van Every" wrote in > message > > > news:3f357a9b at shknews01... > > > > What can I do with Python that I can't do with C#? > > > > > > Given that all Turing complete languages are theoretically > equivalent, > > > nothing, either way. > > > > Turing equivalence is probably the least interesting property of any > > programming language and says absolutely nothing about its > suitability for > > real programming tasks. > > Huh??? > This is a paraphrase of what I said. So why did you silently clip the > remainder of my post where I went on to discuss practical suitability? I quoted you verbatim, there is no paraphrasing here, although I did clip the rest of the article. I only meant to express the opinion that there is no point in ever bringing up Turing equivalance when comparing languages (unless of course they are not Turing equivalent!). Turing equivalence only addresses what computations you may perform, not what programs you may write. - Christopher From gherron at islandtraining.com Fri Aug 1 22:33:22 2003 From: gherron at islandtraining.com (Gary Herron) Date: Fri, 1 Aug 2003 19:33:22 -0700 Subject: String Replacement In-Reply-To: <7b454334.0308011400.266438f9@posting.google.com> References: <7b454334.0308011400.266438f9@posting.google.com> Message-ID: <200308011933.22466.gherron@islandtraining.com> On Friday 01 August 2003 03:00 pm, Fazer wrote: > Hello, > > As some of you might know, I am new to Python. I was finally > successful in using MySQLdb for Python to query the datbase and get a > few results from the query. > > The results will be displayed as HTML and I am sort of confuse din > using the string modules and its functions/modules to replace the \n > with
. I import the string module and I am not soo sure on how to > do the replacing. > > Here's how my code sort of likes: > > import string > string.replace(DataFromDatabase, "\n", "
") > > Unfortunately, it doesn't work. The replacement you are trying to acccomplish probably does happen, but you ignore the returned string. Try: DataTransformed = string.replace(DataFromDatabase, "\n", "
") Another way to say this is that strings are immutable -- you can't change the contents of a string. Any functions such as these return *new* strings with the desired contents. This is a common beginners mistake, but you'll be past these things soon. Gary Herron From mcherm at mcherm.com Wed Aug 6 14:28:38 2003 From: mcherm at mcherm.com (Michael Chermside) Date: Wed, 6 Aug 2003 11:28:38 -0700 Subject: FWD: Re: Problem w/ IDLE on Win2000 Message-ID: <1060194518.3f3148d6d9f43@mcherm.com> Tim Peters writes: > Have you confirmed that a problem exists? I haven't tried. Yes, I confirmed the problem. > Speaking of which, that doesn't look likely to change anytime soon, so if > someone else is willing to take over the PLabs Windows installer, it's > yours. Overall, it's in very good shape. > Most people accept the defaults. "Program Files" is fine for an end-user > app, but for a tool that's going to get used from scripts and command > shells, a path with an embedded space is just begging for needless problems. Of course... that's why I had tested 2.3, but had never tried putting it in "Program Files". It was phenomenally dumb of Microsoft to use a space in a standard directory (particularly the directory where programs go) on an OS which (at the time anyway) didn't (always) handle paths containing spaces. But it's still regrettable. Given the other risks involved, let's phrase the warning in bugs.html as "Warning: If Python is installed inside the "Program Files" directory (or any other directory containing a space), then IDLE will not start correctly. The preferred solution is to install to C:\Python23 (or some other drive in place of C:), but it can also be fixed by editing the shortcut for IDLE in the Programs menu." > Speaking of which, that doesn't look likely to change anytime soon, so if > someone else is willing to take over the PLabs Windows installer, it's > yours. I know nothing about the installer (or about installers in general). If it's just a matter of testing it out for releases, no problem, but how much difficulty am I going to be in if I volunteer here? -- Michael Chermside From gradha at titanium.sabren.com Sat Aug 16 17:02:26 2003 From: gradha at titanium.sabren.com (Grzegorz Adam Hankiewicz) Date: Sat, 16 Aug 2003 23:02:26 +0200 Subject: Would it be possible for python scripts to "core"? Message-ID: <20030816210226.GA29464@pedos.es> Hi. The python debugger is fine, when you are at the machine with the problematic script. Now, how about postmortem remote debugging? Is it possible to pickle somehow an interactive session, send it in a file and open it at the oder end to inspect it just as if it had been run there? I guess the main probelm would be things like opened files, net connections and such, right? -- Please don't send me private copies of your public answers. Thanks. From bhahn at spam-spam.g0-away.com Fri Aug 1 16:04:17 2003 From: bhahn at spam-spam.g0-away.com (Brendan Hahn) Date: Fri, 01 Aug 2003 20:04:17 GMT Subject: Interfaces (a la PEP 245 and Zope) References: <78ednTw5QfxmebSiXTWJhA@august.net> Message-ID: Heiko Wundram wrote: >Simplest way I use to implement "interfaces": > >class IEditor(object): > def getSelection(self,start,end): > raise NotImplementedError("Implement this for IEditor") etc... How about an Interface metaclass that replaces any class methods with an appropriate exception-raiser. It would save a little typing, e.g. class IEditor(): __metaclass__ = Interface def GetSelection(self, start, end): pass def SetSelection(self, start, end, data): pass ...and so on. -- brendan DOT hahn AT hp DOT com From brian at sweetapp.com Sat Aug 2 01:41:38 2003 From: brian at sweetapp.com (Brian Quinlan) Date: Fri, 01 Aug 2003 22:41:38 -0700 Subject: Python's biggest compromises In-Reply-To: <-JecnbRfsp3-lLaiXTWJkQ@comcast.com> Message-ID: <007201c358b8$be8d1690$21795418@dell1700> > In a fast GC system you would just allocate the floats from a > contiguous block. This is how Python works now. > Later you would copy the reachable floats from that block to another > block. If no floats are reachable, you don't copy anything. Is determining if a float is reachable faster or slower than dereferencing a pointer and comparing an integer to zero? 'cause that is all reference counting requires. I'm not saying that the reference counting (+ something else) is the optimal GC strategy for Python but it seems to have advantages when working with a lot of objects with short lifetimes. > Does checking to see if a There are all kinds of optimizations you > can use, including making clever use of memory protection hardware > to notice when your allocator has run over the end of a block so > you don't have to even make an explicit pointer comparison, that > can make all this run very fast. Of course the PythonLabs implementation can never require such a trick. Cheers, Brian From mnations at airmail.net Fri Aug 1 17:05:19 2003 From: mnations at airmail.net (Marc) Date: 1 Aug 2003 14:05:19 -0700 Subject: How do I combine instance+string for variable Message-ID: <4378fa6f.0308011305.183c291a@posting.google.com> Hi all, I can't remember how to do this. I have several instances of telnet connections that I label conn2,conn3, etc. Later when I want to scroll through all of these I wanted to do something like this: for int in range(2, 9): use... conn+str(int) {I'm passing it into another function} I can't get it to work. I've tried using setattr and eval, but nothing seems to work. Can I get a little help. Thanks ahead of time, Marc From mwh at python.net Thu Aug 14 09:11:30 2003 From: mwh at python.net (Michael Hudson) Date: Thu, 14 Aug 2003 13:11:30 GMT Subject: CLI+GUI References: <2259b0e2.0308080948.5a95e383@posting.google.com> <2259b0e2.0308121335.7f1ad18a@posting.google.com> <7h31xvo5ti9.fsf@pc150.maths.bris.ac.uk> Message-ID: <7h3n0ec4c89.fsf@pc150.maths.bris.ac.uk> Michael Hudson writes: > mis6 at pitt.edu (Michele Simionato) writes: > > > I will later try it on Windows 98. Dunno exactly what "dooneevent" > > is doing, > > "man Tk_DoOneEvent" shit, that should be Tcl_DoOneEvent... Cheers, mwh -- One of the great skills in using any language is knowing what not to use, what not to say. ... There's that simplicity thing again. -- Ron Jeffries From hans at zephyrfalcon.org Fri Aug 22 15:05:43 2003 From: hans at zephyrfalcon.org (Hans Nowak) Date: Fri, 22 Aug 2003 15:05:43 -0400 Subject: __getattr__ weirdness In-Reply-To: References: Message-ID: <3F466987.1080002@zephyrfalcon.org> Greg Brunet wrote: > In adding the ability to refer to field values using dbfFile.field > notation, I learned how to use __getattr__ and __setattr__ . After some > trial and error, I got it working. But as part of my trials, I added > some print statements to debug stuff. The ones I added to __setattr__ > work as expected, but the one in __getattr__ seems to get called just > under 1000 times for every __getattr__ call! Sounds like a recursive call. __getattr__ is only called for attributes that are not defined. For example: >>> class Foo: def __init__(self): self.x = 42 def __getattr__(self, name): print "Aha, trying to access self.%s!" % (name,) return None >>> foo = Foo() >>> foo.x # exists, __getattr__ isn't called 42 >>> foo.y # does not exist, __getattr__ is called Aha, trying to access self.y! Back to your code: #---------------------------------------- def __init__(self,filename): print '** __init__' self._filename=filename self._del=' ' self._dirty=False self._open=False self._rec=[] self._recno = 1 I don't see an attribute self._fldNames here, but I see it here: #---------------------------------------- def __getattr__(self, key): """ Return DBF record values by field name """ print "_ga: " + key try: return self._rec[self._fldNames.index(key.upper())] except: raise AttributeError("Unknown Field: %s" % ( key )) Most likely (I didn't actually run the code), this leads to a recursive call of __getattr__. __getattr__ is called, tries to access self._fldNames, which doesn't exist, so __getattr__ is called, etc. etc. Maybe sticking a self._fldNames = something in your __init__ will solve the problem. Then again, maybe you are trying to make that attribute dynamic through __getattr__...? Cheers, -- Hans (hans at zephyrfalcon.org) http://zephyrfalcon.org/ From mugginsm at under-the-fridge.com Tue Aug 26 22:20:57 2003 From: mugginsm at under-the-fridge.com (Colin Coghill (SFive)) Date: Wed, 27 Aug 2003 02:20:57 GMT Subject: Replacement for rexec/Bastion? References: Message-ID: In article , Michael Chermside wrote: > Colin Coghill (SFive) writes: >> Hi, a year or so back some students of mine and I wrote some software >> which made use of the rexec module to run untrusted user code relatively >> safely. > [...] >> I noticed that rexec and Bastion have been >> withdrawn for (in)security reasons. > > Yes. Of course, you can still go back and get the old versions of these > and run them. It won't be any safer than it was before they were > withdrawn, but it will be just as useful (or not useful) as it was > when you used it a year back. Fortunately the project back then was just a prototype so no-one ever relied on it anyway. That particular one's since been rewritten in Java (boo, hiss!) because its security manager stuff was more appropriate for the task. (It was a "safe environment for running interactive email attachments") >> Is Python (preferably CPython 2.3) still able to "sandbox" bits of code >> under an application provided API safely? > > replacement available or even on the horizon. Zope's RestrictedPython > is the closest thing there is... a quick summary of its approach was > posted to python-dev today: > http://mail.python.org/pipermail/python-dev/2003-August/037791.html Thanks, that looks interesting. I had seen mention of it but hadn't realised it wasn't just rexec behind the scenes. >> I can trap endless loops and the like, >> but I need something to stop them just importing sys and raising havoc. > > what's involved in securing untrusted code. Consider, for instance, > this code: > > x = 1000000**1000000 > > I guarantee it'll lock up your python interpreter for a fairly long > time. And it executes in C so there's no possible way you can trap > it. That's not all, I can do things like this: > > x = [1] * sys.maxint I think I resolved this kind of thing a while ago by using seperate processes. The user-code one and the actual application. If the user-code one stops responding for some tunable time, it gets kill -KILL'ed and restarted from the last checkpoint minus the offending code. And for resource limits, ulimit seems to work fine on the several systems I've tried. Yes, this is messy UNIXy stuff, and loses portability, which is bad, but it at least seems to make it possible to do this stuff. > So I have to question whether you really know what you want here. Yeah, I'm pretty sure. I'm looking at making a system that allows bits of code from many sources to be sent to various systems across the network and executed on that system. eg. A shared robot that goes out of network range to take some measurements. You want people to be able to send it some code to control it and collect appropriate readings while it's out of range. And, of course, robots are often expensive so you want it to be fairly secure :) I know I can do it in Java, but I don't like programming in Java, and I do like programming in Python :) > If you actually need to prevent DOS attacks, then the > only approach that could work would be to launch the untrusted > code in a separate process, and allow the OS to limit that processes > access to services (like the filesystem) and resources (memory and > cpu-time constraints). Oh. See above :) - Colin From ghowland at lupineNO.SPAMgames.com Sat Aug 23 12:37:33 2003 From: ghowland at lupineNO.SPAMgames.com (Geoff Howland) Date: Sat, 23 Aug 2003 16:37:33 GMT Subject: Modifying the {} and [] tokens References: Message-ID: On Sat, 23 Aug 2003 13:56:13 +0000 (UTC), kern at taliesen.caltech.edu (Robert Kern) wrote: >The parser compiles {} into the BUILD_MAP opcode which the eval loop >interprets by calling PyDict_New(). This creates a dict object >independently of whatever __builtins__.dict is bound to. > >I discovered this by disassembling some code and looking up the opcode >in the bytecode interpreter eval loop (Python/ceval.c). > >>>> import dis >>>> code = compile("{}", "", "single") >>>> dis.dis(code) > 1 0 BUILD_MAP 0 > 3 PRINT_EXPR > 4 LOAD_CONST 0 (None) > 7 RETURN_VALUE This is very cool, I've never looked at this before. Will be a helpful learning to to see how Python does things. Thanks! :) >Reading the Language Reference can help a lot, too. I searched around in it, didnt read it where I wasnt finding answers. Mostly just found the grammar and a little explanation on the parsing, but not the way it kicks off commands based on them for these tokens. >I think that's precisely the reason why this feature will probably >never make it into Python. I, for one, don't want a module that I import >to change the meaning of a literal just because that module wants to use >a funky form of dict internally. I can definitely understand that point of view, though if it stays restricted to the module you are importing it into, it doesn't seem like it would be very destructive. It would also aid in making other types of special purpose languages out of Python itself (instead of having to create parsers or something). True, could lead to messiness and confusion, but also could lead to beauty and elegance. Just a question of how much rope it's acceptable to be given. >In the end, it's just not worth the trouble. 99.9% of the time, I think >you will find that subclassing the builtin types and giving the new >classes short names will suffice. I mean, how much of a hardship is it >to do the following: > >class d(dict): > def __add__(self, other): > # stuff > >d({1:2}) + d({3:4}) It's not actually the hardship of doing this, there is also the conversion of everything that doesn't create MyDict by default. I would have to keep converting them to perform the same manipulations, or other functions (add is only an important example, others could be handy as well). Now I will need additional lines to do this, or make the lines that exist more complicated. It's not undue hardship in a lot of ways, but it would be nice not to have to and be able to keep the characters used to a minimum. Espcially when trying to write sub-50 line scripts and such. >If you're still not convinced, ask yourself these questions: I actually feel confident I would be happy with my provided answers as real functionality. I don't believe Python will be changed to allow that, and that is fine with me. I just wanted to know if it could be done the way Python is now. >* How would you apply the new subclass? > - Only on new literals after the subclass definition (and registry of > the subclass with some special hook)? > - On every new object that would normally have been the base type? Yes and yes. It is possible, if this were possible, to only make this work for classes that imported it if they so desired I expect. Explicitly requested only, etc. > - On every previously existing object with the base type? No, they're already defined. Unless my understanding of the way types are done is lacking, and they are referencing the same base object code, and then maybe yes to this as well, but it would be passive. > - In just the one module? or others which import it? or also in > modules imported after the one with the subclass? In the module, and any that import it. It fails to be useful in making things clean-and-neat if in order to make a clean-and-neat script you have to first have a bunch of stuff that modifies the language norms. >* How does your choice above work with code compiled on-the-fly with > eval, exec or execfile? It would depend on how Python allowed this change to work. If it did it the way "I imagine" it would, then the change would effect all of these circumstances. >* How do you deal with multiple subclasses being defined and registered? If they re-wrote the same thing and didn't just augment it (or overwrote each other), then I would expect them to clobber each other. Problems could ensue. However, why isn't having {} + {} or [].len() part of the language anyway? If it was, people wouldnt have to keep writing their own. {} + {} doesnt have to solve ALL cases, which is why I'm assuming it isnt already implemented as [] + [] is. It just has to solve the basic case and provide the mechanism for determining the difference. Ex, key clobbering add, and an intersect() function to see what will be clobbered and do something about it if you care. Isn't it better to have some default solution than to have none and everyone keeps implementing it themselves anew every time? For the [].len() type things, this is obviously a matter of taste, and I have always been ok with len([]), but in trying to get team mates to work with Python I have to concede that [].len() is more consistent and a good thing. Same for other builtins that apply. >* How would you pass in initialization information? > E.g. say I want to limit the length of lists > > class LimitList(list): > def __init__(self, maxlength, data=[]): > self.maxlength = maxlength > list.__init__(self, data) > def append(self, value): > if len(self) == self.maxlength: > raise ValueError, "list at maximum length" > else: > list.append(self, value) I am actually interested in new features than modifying current ones, but I suppose you would have this ability as well since you have access. I would say if you break the initialization or any other methods of accessing the type in a default way, then you have just given yourself broken code. No one other function will work properly that uses it and didn't expect to. You will see it doesn't work, and stop. I didn't say I wanted to change ALL the behavior of the language, I just wanted to add features that dont currently exist and I think should. >* Can I get a real dict again if wanted to? Save it, dont clobber the original out of existance. The coder could mess this up (more rope). >* Given your choices above, how can you implement it in such a way that > you don't interfere with other people's code by accident? There could be module limitations, but when I imagined this it was globally reaching. I believe that as long as you add features, or any changes you make dont break things, then you will be safe. If you mess with features that exist then you will break things and your programs will not work. This seems natural enough to me. You ARE changing a default behavior, there are risks, but if you dont change things that other functions use (pre-existing methods), then you are safe. >Okay, so the last one isn't really fair, but the answers you give on the >other questions should help define in your mind the kind of behavior you >want. Reading up on Python internals with the Language Reference, the >dis module documentation, and some source code should give you an idea >of how one might go about an implementation and (more importantly) the >compromises one would have to make. It seems the changes would have to be to the Python source, and I dont want to make a new Python. I dont even want to "change" Python, I want to augment it. I think these are reasonable additions, and I'm sure I missed the discussions on why they aren't there now. There may be very good reasons, and I could end up retracting my desired feature set because of them, but I still wanted to see if I could make it work for my own code. >Then compare these specific features with the current way. Which is >safer? Which is more readable by someone unfamiliar with the code? Which >is more flexible? Which saves the most typing? I think my answers above are sound. If it worked the way I hoped it might, you could change things on a global scale and you still wouldn't break anything. >My condolences on having to deal with such a team. It seems a little >silly to me to equate OO with Everything-Must-Be-a-Method-Call. But if >they insist, point them at [].__len__(). len([]) just calls [].__len__() >anyways. After writing code like that for a while, they'll probably get >over their method fixation. I never had a problem with this myself, but people are different. I have a great team, everyone has their own opinions. No need to belittle them for differing. Some people never get over the whitespacing. It's just the way the people work. No need to see them as flawed. :) -Geoff Howland http://ludumdare.com/ From cnetzer at sonic.net Tue Aug 12 16:00:08 2003 From: cnetzer at sonic.net (Chad Netzer) Date: Tue, 12 Aug 2003 13:00:08 -0700 Subject: Summer reading list In-Reply-To: <001201c36100$292b8c80$85a8a8c0@JCHENG> References: <001201c36100$292b8c80$85a8a8c0@JCHENG> Message-ID: <1060718408.18368.37.camel@adsl-209.204.179.133.sonic.net> On Tue, 2003-08-12 at 11:32, Joe Cheng wrote: > > True. But the flexibility of using the builtin is also nice. For > > example, you can add a bunch of objects to the list, then > > heapify once, > Hmmm, I'm not sure if I buy this particular argument. Line 5 in my > examples there was supposed to illustrate constructing a heap from a > list--so you could do pretty much the same thing. True. I am am very sympathetic with your point of view, because I am developing a signal transform package which has many of the same issues. I take a signal (say a list of numbers), do a transform, then return the coefficients. Rather than having a function which does the transform, returning just list of coefficients, I make a class which provide transformer objects. These objects do the work, and return the coefficients bundled in another yet object which contains the transformed coefficients, plus other data that is needed to do an inverse transform. So, in essence, I think in terms of services. An object provides the "service" of transforming some raw data. The resulting object also provides the "service" of (properly) inverting the data, as well as doing some simple manipulations of it. The reason for doing things this way, is because, as you say, exposing just a list would allow for the opportunity for the results to be improperly mutated or mishandled (ie. pop()-ing from the resulting list would be disastrous). However, when I show this approach to colleages, many grit and gnash their teeth. They would like to simply have the transformed coefficients to operate on directly (this is what they are used to doing in functional paradigms). They know the result of a transform is a list of coefficients (that is what the textbooks say), and they do not want perform extra steps to "pull out" just the coefficients. In general, this is a widespread concern in fields where raw data is manipulated with algorithms. Should one encapsulate resultant data (ie. bundle the ralted peices all up in a special class), or just return data as simple, common objects (ie. lists and arrays) that can be operated on universally. I'd say that this case (heapq) is similar, and the author simply made the choice that was comfortable with him. Still, since the heap is defined more by operations than state (ie. other than a list, there isn't much extra state that needs to be encapsulated in a heap object), I think I also prefer the approach of having a class that defines just what operations can be performed. Construction can easily be used to make new heaps, and (in principle), a list comprehension can easily extract the list from the heap object. In this way, when you pass me a heap, I know it is a heap by its type. > I hope you are not suggesting there is also something to be gained by > directly manipulating the list as a list after it has been heapified? :) I won't, but perhaps others will. :) I honestly don't know what is to be gained from operating on the list directly, once it has been heapified. Probably it conforms to an existing, popular, interface for dealing with heaps (ie. C arrays, with functions that manipulate them). Or perhaps it is so foten operated on as a list, that it was easiest to always keep it a list. > I've never heard this idea before... I'll need to chew on it a little. > Is this a common notion among Pythoners? > > To me it sounds disturbingly like "Procedures are more flexible than > classes because you can compose classes out of procedures." I don't think most Pythoners would accept that quote. I just think, in this case, some might say "Try to use the builtin types to do your work. If you create functions that manipulate them, you can also reuse those functions in your classes." :) Or even more likely, "In Python, it is easy to stick a Class interface onto a functional API. If that makes you comfortable, do it." :) I offer those partly in jest, and partly as serious advice. Perhaps Kevin O'Connor or Tim Peters will comment more on the heapq interface. One could always propose an (additional) class based interface to be included as a standard part of the module, with likely some >0 percent chance of it being accepted. In any case, I think it raises some good issues worth thinking about and discussing. -- Chad Netzer From claird at lairds.com Mon Aug 25 15:42:17 2003 From: claird at lairds.com (Cameron Laird) Date: Mon, 25 Aug 2003 19:42:17 -0000 Subject: Help embedding python References: <3F4A57B0.E91D89FC@engcorp.com> Message-ID: In article , Zora Honey wrote: . . . >I'm sorry if I was a bit curt. The reason I didn't include rationale is >because I have none. I have been advocating extending python instead of >embedding it, but since I have no experience with either, my only >argument is that it seems more natural. It seems like either method is >as difficult to learn and implement. It doesn't seem to me that there >are lot of arguments one way or the other. My husband, on the other >hand, is strongly attached to the idea of having a c++ main program that >will coordinate all the data-processing classes and python widgets. He >believes it is easier to have c++ say to python, "here, I have these >plots for you," rather than have python say to c++, "make these plots >for me." I don't believe this is true, but I don't have any reason >*not* to believe it's true, so I aquiesced. > >So, I suppose instead of asking you to assume the rationale are well >reasoned, I should be asking you why you believe extending python is >easier/cheaper/faster/better than embedding it. . . . Your husband's making a mistake--it's a plausible one, but a mistake, nonetheless. There's actually a lot written on whether Python or C++ should be in charge, especially in a GUIfied context. I haven't the time now to assemble good references. You might like to start with . -- Cameron Laird Business: http://www.Phaseit.net Personal: http://phaseit.net/claird/home.html From jzgoda at gazeta.usun.pl Wed Aug 27 15:34:20 2003 From: jzgoda at gazeta.usun.pl (Jarek Zgoda) Date: Wed, 27 Aug 2003 19:34:20 +0000 (UTC) Subject: Rebol Size References: <3f4a9b9d_2@nova.entelchile.net> Message-ID: Rodrigo Benenson pisze: > But how to explain such a difference ? Freedom weights. -- Jarek Zgoda Registered Linux User #-1 http://www.zgoda.biz/ JID:jarek at jabberpl.org http://zgoda.jogger.pl/ From arechenberg at shermfin.com Wed Aug 27 11:59:55 2003 From: arechenberg at shermfin.com (Andy Rechenberg) Date: 27 Aug 2003 08:59:55 -0700 Subject: MemoryError: out of memory Python 2.1.3 on Windows 2000 Message-ID: The problem is basically in the subject line. I am building an Intranet site based on Zope/CMF/Plone. In order to fulfill the requirements Zope/Python must be run on Windows. Zope is running as a Wi32 service. When the python.exe process consume ~122MB (according to the Windows Task Manager) I start receiving MemoryError: out of memory exceptions. I've already checked for bad RAM and the server's RAM appears good. Is this issue related to running python 2.1.3 on Windows 2000? Is there anyway I can fix this problem so that python.exe will use more than 122MB of RAM (the server has 4GB)? Please CC: my email address with any responses. Thanks a million! Regards, Andy. From rmunn at pobox.com Tue Aug 12 16:43:03 2003 From: rmunn at pobox.com (Robin Munn) Date: Tue, 12 Aug 2003 20:43:03 GMT Subject: Misuse of References: <3f27f0e3$1@news.broadpark.no> Message-ID: Keith Jones wrote: > On Wed, 30 Jul 2003 17:25:05 +0000, max wrote: > >> The problem with spaces is that you need to do 5 times the work of a tab >> to get decent-looking indentation :). > > Not if you have a good editor.. Use vim or emacs. In vim, try :h sts (I > think, or :h softtabstop) ...it would suck to have to type > all the time, but you don't. :) Don't forget the "smarttab" option (:h smarttab). My .vimrc looks like: set shiftwidth=4 set expandtab set smarttab OK, if you want to be precise about it, *part* of my .vimrc looks like the above. :-) -- Robin Munn | http://www.rmunn.com/ | PGP key 0x6AFB6838 -----------------------------+-----------------------+---------------------- "Remember, when it comes to commercial TV, the program is not the product. YOU are the product, and the advertiser is the customer." - Mark W. Schumann From pedro.werneck at bol.com.br Sat Aug 16 17:27:24 2003 From: pedro.werneck at bol.com.br (Pedro Werneck) Date: Sat, 16 Aug 2003 21:27:24 +0000 Subject: How to shortcut a package path? In-Reply-To: <420ced91.0308161605.acf6c5a@posting.google.com> References: <420ced91.0308161605.acf6c5a@posting.google.com> Message-ID: <20030816212724.746fc0a5.pedro.werneck@bol.com.br> on dir1/__init__.py: import dir2.program program = dir2.program But why do you want to do this ? On 16 Aug 2003 17:05:46 -0700 sdhyok at yahoo.com (sdhyok) wrote: > Is there any way to create a shortcut for a package path? > For instance, if I have the following path structure, > > dir1/dir2/program.py > > what should I do if I want to import program with > > from dir1 import program > > , not with > > from dir1.dir2 import program > > > Thanks in advance. > > Daehyok Shin > -- > http://mail.python.org/mailman/listinfo/python-list From skip at pobox.com Tue Aug 19 10:56:57 2003 From: skip at pobox.com (Skip Montanaro) Date: Tue, 19 Aug 2003 09:56:57 -0500 Subject: Serious problem with Shelve In-Reply-To: <3F41BC50.91097FAF@yahoo.com> References: <3F3FB5B9.5E49B306@yahoo.com> <3F41BC50.91097FAF@yahoo.com> Message-ID: <16194.15033.944537.128353@montanaro.dyndns.org> Rami> Well - I installed Python 2.3, but it still doesn't. My program Rami> now crashes on the first pass. After deleting the old databases Rami> and creating new ones, I opened them for read and this is what I Rami> get: How did you create those new databases, using an older version of Python perhaps? What's happening is that whichdb.whichdb() determined that the file you passed into anydbm.open() was an old hash style database, which can only be opened in Python 2.3 by the old v 1.85 library, which is only exposed through the bsddb185 module. Rami> I will try enclosing that import bsddb185 in anydbm.py in try: Rami> except:, though I hate messing around with source files, and there Rami> may be many more such problems. Python developers, be aware of Rami> this glitch. That won't work. What's anydbm.open() going to use to open the file? Can you explain how the files were created? (Sorry if you explained already. I'm just coming to this thread.) If you have Python 2.1 or 2.2 laying around with a bsddb module which can read the file in question, use Tools/scripts/db2pickle.py to convert the file to a pickle, then with Python 2.3, run Tools/scripts/pickle2db.py to convert the pickle back to a db file, using the new bsddb. Those two scripts are in the Python 2.3 distribution, but not the Python 2.2 distribution. They should work with Python 2.1 or 2.2, however. This problem is exactly why I wrote them. Synopsis: python2.2 db2pickle.py olddbfile pickle.pck python2.3 pickle2db.py newdbfile pickle.pck Skip From belred1 at yahoo.com Thu Aug 7 22:11:49 2003 From: belred1 at yahoo.com (Bryan) Date: Fri, 08 Aug 2003 02:11:49 GMT Subject: MSVC 6.0 Unsupported? References: <3F302764.8010301@ghaering.de> <3f3284d8$0$49098$e4fe514c@news.xs4all.nl> Message-ID: "Irmen de Jong" wrote in message news:3f3284d8$0$49098$e4fe514c at news.xs4all.nl... > Syver Enstad wrote: > > But Gerhard, what can I do? Every python extension that I will try to > > compile will fail if it depends on a working staticforward. The most > > rational thing to me is to patch object.h instead of patching every > > .cpp/.c file that needs this define. > > Can't you just add a single compiler option (for cl.exe) to your project? > > /Dstaticforward=extern > > wouldn't that work? > > --Irmen > > > that's not a bad idea if we can add that to a distutils setup.py and then "if" the compiler... but i still think it's much simpler for those of us using the msvc compiler to just modify object.h once. i'm aware you don't like this option. bryan From adalke at mindspring.com Mon Aug 18 19:18:14 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Mon, 18 Aug 2003 17:18:14 -0600 Subject: What's TOTALLY COMPELLING about Ruby over Python? References: <3F41208F.40021A68@engcorp.com> Message-ID: John Roth > All of the Ruby collections implement a .each method, which is essentially > a version of the Visitor pattern. If I want to do something to every element > in a list or a dict (or any kind of collection,) all I have to do is say > something like (using Python syntax): > > collectObj.each() Does that mean 'apply the method to each element of my collection?'? Does it return a new container or modify things in-place? Is it applied recursively? Does it work on strings? Are characters in Ruby also strings? If so, and if .each is recursive, what's the bottom case? > And you > have to worry about distinctions between functions and methods. In other > words, it's a mess compared to Ruby. Where does that distinction come into play? A method is a bound function, kinda like a curried function with self. I find C++ methods more confusing, because a reference to a class method is unbound, when I almost always want it bound. > Now, you can say: "We've got that with map()." Well, we've got it when > your inputs are either lists (or implement the correct protocol) but the > result is a list, it's not an internal modification to the object's state. Ahh. Are strings in Ruby mutable or immutable? ... Yup, looks like it's mutable. From the FAQ def downer(string) string.downcase! end a = "HELLO" downer(a) puts a #=> "hello" In which case it makes more sense for this in Ruby than in Python, since "ABCDEFG".each(f) can't do that much unless f modifies state, either as a bound method or tweaking global variable. Given that rather fundamental difference, an each method in Python + code blocks wouldn't be any more powerful than a for statement. The following is possible def each(container, f): for i, x in enumerate(container): container[i] = f(container[i]) but then it requires the container be indexable, which is stronger than just being iterable. How do Ruby's associative arrays work when the string used as the key is mutated in-place? Is it copy-on-write? > To continue on this vein, Ruby directly implements Visitor, Observer, > Delegate and Singleton. I don't particularly like the way it does some > of them, but Python can't claim any one of the four! The Python approach to a Singleton is called a 'Borg' class. Described by Alex Martelli, it looks like >>> class Borg: ... shared_state = {} ... def __init__(self): ... self.__dict__ = Borg.shared_state ... >>> x1 = Borg() >>> x1.a = "Albuquerque" >>> x2 = Borg() >>> x2.a 'Albuquerque' >>> The other way to get singletons is with a factory function, which under Python wouldn't look different than a normal constructor. I looked at some Java code recently and wanted to suggest a factory implementation only to realized that would require a lot of 'new' removals. > Granted, you can do a clean singleton using new style > classes and the __new__() method, See Alex's discussion at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66531 as for why singleton (so that 'x1 is x2') is less important than many consider. Though I know I can't recall needed a singleton for my code. Maybe I have a different code style? I've noticed a tendency of mine towards functional programming... Anyway, others consider Borg a workaround for Python's until-2.3 unability to support singletons, as with http://mail.python.org/pipermail/python-list/2002-April/096382.html As for Observer, etc., I know they are simple classes so I don't consider them all that important as a differentiator. > It might be better to simply take the question at face value, rather than > slanging Brandon. I don't find the personalities to add anything of value > to the conversation. Despite my best attempts, I find it almost impossible to slag someone without including information to back up my view. Eg, I thought my numbers and trends of mentions of other programming languages was pretty interesting, but I guess it was of no value to you. :( Andrew dalke at dalkescientific.com From johng2001 at rediffmail.com Tue Aug 12 14:59:15 2003 From: johng2001 at rediffmail.com (John) Date: 12 Aug 2003 11:59:15 -0700 Subject: Python vs. C# References: Message-ID: > > Python advocates tend to pooh-pooh strong typing, > > Disinformation nonsense. Python objects are more strongly typed than > C variables. Agreed! > Does C# have casts? Yes! Explicit! About the same level as Java. From tjg at craigelachie.org Fri Aug 22 00:16:08 2003 From: tjg at craigelachie.org (Timothy Grant) Date: Thu, 21 Aug 2003 21:16:08 -0700 Subject: Running one single test... Message-ID: <200308212116.09167.tjg@craigelachie.org> At work we use Perl and a home rolled unittesting mechanism. One of the things I love about That testing mechanism is that I can run one single test. In fact, I've configured Vim to run the current test and either tell me if it passes or tell me the error when it doesn't. I'd love to do something similar with PyUnit, but I have yet to figure out how to run one single test. Any help would be greatly appreciated. Thank you. -- Stand Fast, tjg. Timothy Grant www.craigelachie.org From cartermark46 at ukmail.com Wed Aug 27 05:00:27 2003 From: cartermark46 at ukmail.com (Mark Carter) Date: 27 Aug 2003 02:00:27 -0700 Subject: ClientCookie bug (followup) References: <87oeypdh92.fsf@pobox.com> <87k79a25pi.fsf@pobox.com> <87isos0zng.fsf@pobox.com> <87ptis39kp.fsf@pobox.com> <877k506ukq.fsf@pobox.com> Message-ID: > opener = ClientCookie.build_opener(ClientCookie.HTTPCookieProcessor(c)) > > url = 'http://businessplus.hemscott.net/corp/crp03733.htm' > response = opener.open(url) Huzzah, we have liftoff! > All of this is explained in the web page, though. You are right! All the technical information is there. But can I suggest a change in the docs that might spell it out a bit more obviously to someone coming to the module from fresh? Something like: h1: Examples h2: Simple example import ClientCookie response = ClientCookie.urlopen("http://foo.bar.com/") This function behaves identically to urllib2.urlopen, except that it deals with cookies automatically. That's probably all you need to know. h2: Using Internet Explorer or Netscape/Mozilla cookies c = ClientCookie.MSIECookieJar(delayload=1) # see note 1 c.load_from_registry(username='joe bloggs') # see note 2 opener = ClientCookie.build_opener(ClientCookie.HTTPCookieProcessor(c)) url = 'http://foo.bar.com/' response = opener.open(url) print response.info() # headers print response.read() # body h3: Notes 1. Mozilla users should use MozillaCookieJar() instead of MSIECookieJar 2. Usually only win98 and 95 users need supply the username. As an alternative to loading from the registry, consider using the line c.load_cookie_data('cookie-file.txt') instead. I think that the above is much more up-front, and is likely to satisfy the majority of users, who will probably just want basic cookie handling, without pouring over the documentation. Ideally, it should be at the top, where people will see it first, and before those more complicated examples. Hope this is useful! From rganesan at myrealbox.com Wed Aug 13 02:19:09 2003 From: rganesan at myrealbox.com (Ganesan R) Date: Wed, 13 Aug 2003 11:49:09 +0530 Subject: two quick questions References: Message-ID: >>>>> "Elaine" == Elaine Jackson writes: > Two quick newbie questions: > 1) Does Python have passing-by-reference? Python only has "passing-by-value". However, in Python you always work with references to objects. So in Python function calls pass references by value. Hope that makes sense :-). > 2) In ordinary parlance, "deep" implies "shallow" but not conversely. In > the Python "copy" module (if I understand correctly), the implication goes > the other way. Do you find this a nuisance? If I understand you correctly, "deep" does imply "shallow" in the "copy" module. Perhaps you can point to documentation that led you believe it "goes the other way". Ganesan -- Ganesan R From webmaster at t-dose.de Thu Aug 7 07:52:16 2003 From: webmaster at t-dose.de (webmaster at t-dose.de) Date: Thu, 07 Aug 2003 13:52:16 +0200 Subject: Sick problem with Python properties In-Reply-To: <1060256730.3f323bda5b077@mcherm.com> References: <1060256730.3f323bda5b077@mcherm.com> Message-ID: <2147483647.1060264336@[192.168.0.100]> --On Donnerstag, 7. August 2003 4:45 Uhr -0700 Michael Chermside wrote: > aj writes: >> See the following code. I wonder why in this case neither >> setp() nor getp() is called !? > [... code ...] >> pp = property(getp, setp) > [... more code ...] >> inst.p = 9 >> print inst.p > > Because you named it "pp", but then tried using "p" instead. > This was a bad cut&paste. The problem was that the class must derive from object.....the heat :-) -aj From sross at connectmail.carleton.ca Tue Aug 12 09:46:14 2003 From: sross at connectmail.carleton.ca (Sean Ross) Date: Tue, 12 Aug 2003 09:46:14 -0400 Subject: get line number References: Message-ID: "Richard Mertens" wrote in message news:Xns93D5944E0F172richardmertenswolfio at 130.133.1.4... > How do get the actual line number from the actual running sourcecode. > I need it for debugging purpose > Use the inspect module: 1 import inspect 2 print inspect.getlineno(inspect.currentframe()) 3 print inspect.getlineno(inspect.currentframe()) 4 # output 2 3 From __peter__ at web.de Mon Aug 25 05:25:20 2003 From: __peter__ at web.de (Peter Otten) Date: Mon, 25 Aug 2003 11:25:20 +0200 Subject: for iteration References: Message-ID: Franck Bui-Huu wrote: > Thanks for your example but I haven't found __iter__ method in list type: Je suis d?sol? :-( So you are *not* using Python 2.3. I have verified your observation (non-existent __iter__()) for Python 2.2.1 and have no idea how the for loop works there. However, the code I posted *will* work for 2.2.1 if you put from __future__ import generators at the start of the file, i. e. before all other statements including import something.else Hope that helps, Peter From kevin at cazabon.com Fri Aug 15 13:56:46 2003 From: kevin at cazabon.com (Kevin Cazabon) Date: 15 Aug 2003 10:56:46 -0700 Subject: thread debugging References: Message-ID: <5a4226f0.0308150956.15912443@posting.google.com> Two solutions I can see: 1) at the end of your main script... don't exit. use "while 1: pass". That'll keep the main script running so you can debug normally 2) output a log file from each thread (log before and after each significant event) Kevin. Robert Hayes wrote in message news:... > Hi, > This may well be a very stupid question, but I'll ask it anyway: > > I have a script that uses Thread classes. All it does (when called as a > __main__ script) is initialise the classes and start() them. Then it exits. > > The problem is that I can't debug those threads with a standard debugger > (I'm using PythonWin 157 btw), because the script has already exited! > (even though the threads are still running). So any breakpoints I set > are ignored... > > My question is thus: is impossible to debug this threaded code, or is > there some way that I can? (preferable using pythonwin; sorry, my *nix > friends, but I am confined to windows for this one ;)) > > thanks, > ~Rob From vanevery at 3DProgrammer.com Mon Aug 11 17:57:55 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Mon, 11 Aug 2003 14:57:55 -0700 Subject: Python vs. C# References: <2259b0e2.0308100616.55b651ca@posting.google.com> <3f36af20@shknews01> Message-ID: Istvan Albert wrote: > Brandon J. Van Every wrote: > >> For instance, Perl has become popular because >> it's overwhelmingly useful for sysadmin and web admin. But I am not >> seeing Python's overwhelming utility compared to other languages. >> You can do apps, you can do web admin, but most people are doing >> Java, C#, or Perl. And unlike C++ they aren't bad languages, so >> Python is not offering an obvious "slam dunk" remedy. > > As far as I'm concerned it does not have to be "slam dunk". Just a > little better is enough, that goes a long way and adds up quickly in > larger projects. That's why people use python, it is not a conspiracy > nor a brainwashing that made it popular. For many tasks it works > better than anything else out there. Right, but what if C# is "a little better" for tools integration and extant worker skills on the Windows platform? If it actually has its own class of noticeable improvements in that domain, plus Microsoft's marketing muscle behind it, then C# sweeps the table on Windows. Leaving Python to the UNIX world. And there, it comes down to whether Python or Java is the better tool for a particular job. > C# was created to counteract Java. Unlike Python it would die quickly > if it weren't for the marketing muscle of Microsoft. I am not convinced. As the books tell it, C# was created to take the best features of Java and some other languages. And as a dyed in the wool C++ programmer, most of what I've learned about C# so far certainly looks like sanity. I am currently thinking of it as "C++ without the pain." > So claiming as the holy grail seems a bit of a joke. It's not a holy grail. It is probably a better real world language product on the Windows platform. My question is about the strategic consequences of that likely fact. What's Python's strategic plan? Why is there going to be room for 4 "high level languages" in the future? Why are we going to need Java, C#, Perl, *and* Python? -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From gregbrunet at NOSPAMsempersoft.com Sun Aug 3 01:26:56 2003 From: gregbrunet at NOSPAMsempersoft.com (Greg Brunet) Date: Sun, 3 Aug 2003 00:26:56 -0500 Subject: Beginner's popups in vanilla Python program References: Message-ID: I responded in a bit more detail in the wxPython newsgroup/list, but it seems that EasyGUI would be the best interface for you to use (compared to something like wxPython), since you seem to be thinking/designing in linear, traditional terms instead of event-driven. You should be able to find it with a Google search. Also, there are lots of on-line docs & tutorials, so you should be able to get by without buying books for a while at least. -- Greg "Art" wrote in message news:mailman.1059876124.23478.python-list at python.org... > NEWBIE ALERT! > > Esteemed List Participants and Lurkers: > > (System: P-II 350, 192 meg, Win98 SE, Python 2.2.3, > wxPythonWIN32-2.4.1.2-Py22.exe) > > I'm having a lot of fun getting started with Python ... it is the most > elegant and graceful language I have ever used (Fortran, Cobol, Basic, many > assemblers, Forth, C, VB, etc.). I don't have the resources or the > research time to buy a stack of books, so I'm begging help here. Please be > graciously patient. > > I want to edit and run a SIMPLE beginner's program from the IDLE GUI. > Within the program, I want to pop up a Windows modal dialog box with a > message "Is this a test?"; a title "Test Query"; and I want YES|NO buttons > to exit and pass a yes|no boolean back to the program. The program will > then pop up a second dialog message box "You selected (yes or no)" with > title "Response:" with a close button. I don't really care if there is a > "parent(?)" frame on the screen (but I prefer not) for the duration of the > program, as long as it is terminated properly before the program ends. > > Here is everything but the popups: > > # Program: Beginners_Popups.py ... "Hello World" for popups > > # Import and set up the tk/WX/?? popups here. > # As minimal as is possible > > print "Begin program" > # Prepare the basic programmatic messages > strMess1 = "Is this a Test?" > strTitle1 = "Test Query" > strResponse = "You selected " > strTitle2 = "Response:" > > # 1st popup goes here: > # Message = strMess1 > # Title = strTitle1 > # YES|NO buttons Returning Boolean boolVar > > # Build the appropriate response > if boolVar: > strResponse += "YES" > else: > strResponse += "NO" > > # 2nd popup goes here: > # Message = strResponse > # Title = strTitle2 > # and close button > > print "End of Program" > > > Once I get this far, I will have the guts of everything I need (for now!). > I just can't seem to find enough beginner's information for the simple > popup pieces. I know I'm trying to incorporate Windows stuff in a DOS type > environment, but I'm sure it can be done. > > I already have a filter written in Python to read and parse a directory of > files into a dictionary of location #s and file names, read in a master > location list, and create a text file of an HTML table with file links in > the cells. I have about 120 locations to deal with, and it is working > great. I just need a couple of primitive user interface points, and popups > are standard. > > Thank you for your gracious comments, suggestions, assistance, and even > criticisms. > > Blessings in abundance, all the best, and ENJOY! > > Art Du Rea Carlisle, PA > > From januarytwentyfirst2003 at yahoo.com Wed Aug 20 16:52:33 2003 From: januarytwentyfirst2003 at yahoo.com (tls) Date: 20 Aug 2003 13:52:33 -0700 Subject: Almost uneventful FAQ Wizard setup - except for Globalname error!! Message-ID: Hi, By following the README found in the faqwiz directory under the python 2.3 distribution, I was able to get FAQ WIZARD up and running in no time with no trouble. This is good since I'm a PC/Windows user trying to make the switch to linux and was already patting myself on the back for getting apache up and running. The FAQ works. I added several categories (actually in the faqconf.py file), and added several questions. However, when I edit an answer and press the COMIT button, I get the following error: -------------------------------------------------- Traceback (most recent call last): File "/var/www/cgi-bin/faqw.py", line 28, in ? import faqwiz File "/usr/people/nogard/python/faqwiz/faqwiz.py", line 841, in ? wiz.go() File "/usr/people/nogard/python/faqwiz/faqwiz.py", line 389, in go meth() File "/usr/people/nogard/python/faqwiz/faqwiz.py", line 743, in do_review self.commit(entry) File "/usr/people/nogard/python/faqwiz/faqwiz.py", line 811, in commit emit(LOGHEADER, self.ui, os.environ, date=date, _file=tfn) NameError: global name 'tfn' is not defined (times: user 0.12, sys 0.05, ch-user 0.01, ch-sys 0.07, real 0.56) ----------------------------------------------------- when I look in faqwiz.py, it looks to me (lots of programming experience in several languags, python not one of them) as if tfn is indeed undefined and that what it really wants is "_file=tn" since tn is a tempfile that has been just opened (I think). However, chaning tfn to tn results in slightly different errors. Now when I hit reload in mozilla, FAQ WIZARD says that there was an error and that the change was not made. BUT, the change has been made. Please help. One more question. If I wanted to wipe the FAQ clean, how would I do this? I tried on a seperate install (different computer) to delete all files in my FAQDIR (including the RCS subdir) but faqwiz somehow remembered where it was in the numbering scheme and kept saying "stop changing the entry numbers". thanks in advance, you'll be helping a lost soul escape the clutches of Bill Gates! januarytwentyfirst2003 at yahoo.com From tismer at tismer.com Thu Aug 28 22:34:56 2003 From: tismer at tismer.com (Christian Tismer) Date: Fri, 29 Aug 2003 04:34:56 +0200 Subject: Zope 2.7 running with Stackless 3.0 In-Reply-To: <3F4E47DF.9060800@zope.com> References: <3F4D44EB.5010500@tismer.com> <3F4DF1E7.1010103@zope.com> <3F4E3CE1.5030405@tismer.com> <3F4E47DF.9060800@zope.com> Message-ID: <3F4EBBD0.1040706@tismer.com> Shane Hathaway wrote: > Christian Tismer wrote: > >> Stackless 3.0 does all of it, whatever is possible. >> That means, you can switch whatever, even extension >> C code with Python callbacks. But cooperative code >> can switch faster. > > I'm very happy to hear you've forged onward. I was concerned you had > given up. I never give up. Giving up is for me the equivalent to death. I'm undead. ;-) ... >> No continuations, tasklets. :-) > > Did you switch the terminology? Where can I read about Stackless 3.0? You will be able to, soon. At the moment, just read help("stackless"). Stackless 3.0 no longer has the primitive, most powerful concept of continuations, it just has tasklets. Tasklets are like one-shot continuations, so they are no longer immutable. In other words, they are like tiny threads. The reasons for that are multiple. But the main reason is the hardware switching capability. It is a feature of SLP 3.0. SLP 2.0 did only this. SLP 3.0 does this, and a subset of the 1.0 continuations, but reduced to a common subset. With the presence of hardware C stack snapshot, it is not trivially possible to provide immutable, re-runnable instances of such C stacks. I only can (almost) guarantee, that they can continue once, after they have been freezed. This is so, since I was (so far) unable to provide a platform/compiler independent way to completely analyse them for the presence of Python objects. In summary, that means, allowing for C stack captures in a compatible way kills the concept of pure continuations. On the other hand, killing the concept of pure continuations allows me to make C stack snapshots and pure Python frame chains to be rather compatible. So what I do is to wrap an abject around both, called a tasklet. And such a tasklet can be run just once, since it has mutable state. But this is exactly what peaople want. > For the uninitiated: Stackless lets a Python program break out of the > rigid constraints of a simple stack. It lets Python code manipulate its > own execution. It provides new solutions to problems like threading, > debugging, network communication, etc. It's a very interesting shift. This is still true! > BTW, here's one avenue you might pursue, Christian: Python IDEs. When I > wrote the debugger for Boa Constructor, I hit a big wall. *You* wrote the Boa debugger? Well, this is great. We need to talk. > Since Python > is a dynamic language, one would expect to be able to pause the > execution of a function, change the function, and resume execution with > new code--never skipping a beat. But CPython makes this nearly > impossible. I imagine Stackless would provide an answer for this. If > it does, get in contact with ActiveState, Secret Labs, or the Wing IDE > folks and tell them you can make their debugger twice as good as any > other. Just an idea. A very good idea. Although all of these people know me well, and I think I don't need to talk so much. Instead, they are kind of waiting. Actually, they don't need to wait so long, since SLP 3.0 final is coming in the next three weeks, with a decent C API. cheers & thanks -- chris -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 mobile +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From FBatista at uniFON.com.ar Thu Aug 21 10:19:34 2003 From: FBatista at uniFON.com.ar (Batista, Facundo) Date: Thu, 21 Aug 2003 11:19:34 -0300 Subject: Which way to say 'private'? Message-ID: #- There are 2 ways to indicate private members of classes, by #- prepending #- 1 or 2 underscore characters, the latter causing name mangling. My #- question is: When would I use which kind to indicate privacy? As a I read don't remember where, :p, to put 1 underscore is the same to hang a "Do not disturb" sign in the door, to put 2 underscores is the same to lock the door. . Facundo From mwh at python.net Thu Aug 21 08:19:42 2003 From: mwh at python.net (Michael Hudson) Date: Thu, 21 Aug 2003 12:19:42 GMT Subject: Scope of InteractiveInterpreter? References: Message-ID: <7h3vfsr2oj4.fsf@pc150.maths.bris.ac.uk> google at hanger.snowbird.net (Kris Caselden) writes: > I'm using the InteractiveInterpreter to run some source, but the data > generated doesn't seem to be available in the scope of the parent. > > For instance, I tried > > lines = infile.open('data.py','r').readlines() > ii = InteractiveInterpreter({'__name__': '__main__', '__doc__': None}) > for line in lines: > ii.runsource(line) > > but the data objects in data.py don't seem to exist when I try and > manipulate them later in the script. Is what I'm trying to do > possible? Am I on the right track? I don't know what you're trying to acheive. It *sounds* like you're hunting for a complicated version of execfile. Try this: d = {} execfile('data.py', d, d) then the objects you're looking for are in the dictionary d. If you really want a module you can then do data = new.module('data', d) or maybe just use the standard (but obscure) imp module to do it all in one step. HTH, mwh -- I've reinvented the idea of variables and types as in a programming language, something I do on every project. -- Greg Ward, September 1998 From mis6 at pitt.edu Tue Aug 12 09:43:17 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 12 Aug 2003 06:43:17 -0700 Subject: Howto MACRO in python ? References: Message-ID: <2259b0e2.0308120543.5293f6f1@posting.google.com> "Bill Loren" wrote in message news:... > Hi, > > I was looking for a guidance about how to code MACROs in python. > any offer ? > > thx > B 1) You are asking if there macros in Python: the answer is "NO". 2) You are asking if it is possible to implement macros in Python: the answer is "YES, but why would you do that?". Few months ago, as a proof of concept, I wrote a module to implemente macros in Python and I can send the code to you, if interested. But I never use that code, I don't feel the need for macros in Python. Many people here are opposed to introduce macros, for very good reasons: a little of googling will give you plenty of information on the subject. Michele From mcfletch at rogers.com Thu Aug 28 16:08:50 2003 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Thu, 28 Aug 2003 16:08:50 -0400 Subject: Metaclasses presentation slides available... Message-ID: <3F4E6152.8050602@rogers.com> Slides from my PyGTA presentation on Tuesday, focusing mostly on why/where you would want to use meta-classes, are available in PDF format: http://members.rogers.com/mcfletch/programming/metaclasses.pdf BTW, for those not on Python-list, be sure to check out David & Michele's newest developerworks article on the topic: http://www.ibm.com/developerworks/library/l-pymeta.html http://www.ibm.com/developerworks/library/l-pymeta2/?ca=dnt-434 Have fun, Mike _______________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://members.rogers.com/mcfletch/ From elf at drizzle.com Tue Aug 12 17:57:51 2003 From: elf at drizzle.com (Elf M. Sternberg) Date: Tue, 12 Aug 2003 14:57:51 -0700 Subject: Python signal delivery under BSD 4.4 Message-ID: I'm having a devil of a time with signal handling under BSD 4.4 with Python and I was hoping that this might ring a bell with someone. Using the Webware Application Server (a multi-threaded Python application), I fork off a process to run independently and do some heavy-duty multi- threaded I/O churning. The process is launched with os.spawnvp(). The user may, at any time, elect to terminate this process before it reaches its end. I do that by having the Application Server send a SIGUSR1 signal to the process ID returned by os.spawnvp(), which so far has been reliably returned and stored in the appserver's session mananger. So far, so good. This worked well under Python 2.1, where I used os.fork() instead of os.spawnvp(). We have upgraded to Python 2.2.3 and it has mysteriously stopped working. Processes launched off the appserver, whether using os.fork() or os.spawnvp(), are now completely deaf to signals. Nothing gets its attention except, of course, SIGKILL. Not when sent from the appserver, and not when sent from the shell, not even by root. If the process is launched from the command line, however, it is well-behaved and responds to signal reliably. What gives? From newsgroups at jhrothjr.com Sun Aug 3 19:16:28 2003 From: newsgroups at jhrothjr.com (John Roth) Date: Sun, 3 Aug 2003 19:16:28 -0400 Subject: time, calendar, datetime, etc References: Message-ID: "Tim Peters" wrote in message news:mailman.1059930907.27623.python-list at python.org... > [Dan Bishop] > > There were no leap years between 10 BC and AD 4, because after Julius > > Caesar's death, the priests in charge of the calendar mistakenly added > > leap days every 3 years instead of 4, and this had to be corrected. > > > > I wouldn't expect the datetime module to deal with that, though ;-) > > Thank you -- some people did . I don't think I noticed that: the entire point behind the proleptic calender is that you're projecting the current practice back to times where they weren't doing it that way. That's clearly an opportunity for someone to add an extension - except that there are other problems in that era, and the lack of leap years is the least of them. John Roth > > > > ... > > >>> datetime.date(1970, 8, 22).weekday() > > 5 > > >>> datetime.date(6970, 8, 22).weekday() > > 5 > > > > The output above is my least favorite feature of the datetime module. > > It took me a while to figure out that those dates are Saturdays. > > That's very peculiar! Because they're not both Saturdays: > > >>> datetime.date(1970, 8, 22).weekday() > 5 > >>> datetime.date(6970, 8, 22).weekday() > 2 > >>> > > Or if you want names instead: > > >>> datetime.date(1970, 8, 22).ctime()[:3] > 'Sat' > >>> datetime.date(6970, 8, 22).ctime()[:3] > 'Wed' > >>> > > Did you actually run the example you pasted, or just assume that the second > line would display 5 too, or didn't paste the actual example you ran and > made a typo? > > The earlier claim: > > > The Gregorian leap year cycle is 400 years and this is coincidentally > > also a whole number of weeks. > > was correct, but the 5000 years between 1970 and 6970 isn't a multiple of > 400, so the example as given wasn't relevant to that claim. > > > Perhaps we could add a weekday class to 2.3.1? > > > > DAY_NAMES = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', > > 'Saturday', 'Sunday'] > > class weekday(int): > > def __repr__(self): > > return DAY_NAMES[self] > > for i, name in enumerate(DAY_NAMES): > > globals()[name] = weekday(i) > > I doubt anything like this will get added, in part because we have the > unfortunate fact that .weekday() and .isoweekday() map day names into little > integers differently. As shown above, you can easily get English day names > (well, abbreviations) from the .ctime() result. A .strftime() format works > too, except .strftime() has irritating year-range limitations inherited from > C. > > I have a little dateutil.py module I use for my own stuff, containing > > MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY = range(7) > > (JANUARY, FEBRUARY, MARCH, APRIL, MAY, JUNE, > JULY, AUGUST, SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER) = range(1, 13) > > at the start. That's easy, and caters to that (1) I'm unlikely ever to use > .isoweekday(); and, (2) after decades of practice, I'm comfortable with the > English names for these things. It's much easier to do something similar > for yourself than to try to define a gimmick that covers the union of all > peoples' crazy ideas . > > From skip at pobox.com Fri Aug 1 12:41:45 2003 From: skip at pobox.com (Skip Montanaro) Date: Fri, 1 Aug 2003 11:41:45 -0500 Subject: Parallel port monitoring In-Reply-To: References: Message-ID: <16170.38985.193436.480844@montanaro.dyndns.org> Mark> I've read many threads regarding parallel port manipulation, but Mark> is there anything that can simply monitor what's happening on the Mark> parallel port, and perhaps react to certain events on said port? Mark> I would much rather do that than simply program a preset wait Mark> time. Assuming you can get a file object out of your parallel port you should be able to pass it to select.select() or select.poll() and let them tell you when bytes are available to read. Skip From tim.one at comcast.net Thu Aug 7 20:22:30 2003 From: tim.one at comcast.net (Tim Peters) Date: Thu, 7 Aug 2003 20:22:30 -0400 Subject: Newbie Testing IDLE 1 on win98 In-Reply-To: <5540514a.0308071421.37663e8b@posting.google.com> Message-ID: [Raymond A. St. Marie] > Newbie Ray here. Hi! Ancient Timmy here. > Running win32 installer version of > Python2.3 on win98(notSE) > > I decided to run the autotest from IDLE 1 window. There you go: don't. The tests are intended to be run from a DOS box, and all sorts of weird things can happen if you try to run them from IDLE. If you want to run the tests, open a DOS box and do this: C:\Python23>python lib/test/regrtest.py mixing-tests-and-guis-is-like-mixing-peanut-butter-and-jello-ly y'rs - tim From psyche at mensa.org.pl Sat Aug 30 16:32:57 2003 From: psyche at mensa.org.pl (Mirek Rusin) Date: Sat, 30 Aug 2003 22:32:57 +0200 Subject: complex - unexpected behavior Message-ID: ...i've got different results on linux / windows box with complex nums, why? linux: >>> print (2.83527944266e+184-3.10413674648e+186j) ** 2 (nan+nanj) ...m$ win: >>> print (2.83527944266e+184-3.10413674648e+186j) ** 2 Traceback (most recent call last): File "", line 1, in ? OverflowError: complex exponentiaion system config is: linux: (Python 2.3 (#1, Aug 26 2003, 15:53:29) [GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2 Redhat 9, 2.4.20-8 #1 Thu Mar 13 17:54:28 EST 2003 i686 GNU/Linux) windows: (Python 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] on win32 Microsoft Windows XP Home Edition) From brandon at its.caltech.edu Tue Aug 12 14:57:28 2003 From: brandon at its.caltech.edu (Brandon Michael Moore) Date: Tue, 12 Aug 2003 11:57:28 -0700 (PDT) Subject: random value generation Message-ID: I'm trying to test a web application using a tool written in python. I would like to be able to generate random values to put in fields. I would like to be able to generate random dates (in a specified range), random strings (specifying allowed characters and a distribution of lengths), or choose randomly between several generators (for better control of the distribution of values). Is there any library for this sort of thing in Python? I've started a library heavily based off the generators of Haskell's QuickCheck library, that represents generators as objects with a generate() method, with constructor parameters (maybe other generators) the control the resulting distribution. I've got Choose that takes a list of generators and chooses between them (with random.choice), GMap that maps a function over the output of another generator, Choice that chooses an element from a list, Expo that wraps random's expovariate, and List that takes a number generator and an element generator and generates lists with lengths drawn from the first generator and elements drawn from the second, and String that's like List but joins the resulting list with ''. I can use these classes like Choice(['red','blue','green']), or String(Expo(1.0/3),Choice(string.lower)). Are there any existing libraries for this sort of thing? Or at least, can anyone suggest a cleaner way of doing this? (I don't like creating classes for things that should really be functions, but I need to call the random number generator each time I use the generator, not once when I define it) Brandon From hokiegal99 at vt.edu Thu Aug 7 23:35:55 2003 From: hokiegal99 at vt.edu (hokiegal99) Date: Thu, 07 Aug 2003 23:35:55 -0400 Subject: passing multiple strings to string.find() Message-ID: <3F331A9B.9020907@vt.edu> How do I say: x = string.find(files, 'this', 'that', 'the-other') currently I have to write it like this to make it work: x = string.find(files, 'this') y = string.find(files, 'that') z = string.find(files, 'the-other') From clay at shirky.com Sat Aug 23 21:33:52 2003 From: clay at shirky.com (Clay Shirky) Date: 23 Aug 2003 18:33:52 -0700 Subject: Python newbie help References: <87fa5cfa.0308181126.c61bfa2@posting.google.com> <3f412b85.351181492@news.blueyonder.co.uk> Message-ID: <25373bfe.0308231733.5a7a5f61@posting.google.com> s wrote in message news:... > You may have a lower opinion of these types of books but I think > they're really beneficial for people trying to get started and helping > them branch out into something more useful. > > I'm still taking in suggestions. Have you looked at "How To Think Like A Computer Scientist?" Its a general intro to programming, using python for the examples. http://ibiblio.org/obp/thinkCS/python.php -clay From peter at engcorp.com Tue Aug 12 07:29:24 2003 From: peter at engcorp.com (Peter Hansen) Date: Tue, 12 Aug 2003 07:29:24 -0400 Subject: Is Python your only programming language? References: Message-ID: <3F38CF94.DC3429F6@engcorp.com> Joe Cheng wrote: > > I want to ask you hard-core c.l.p Pythonistas: Do you use Python for > everything? (and I'm counting Python + C extensions as just Python) Or do > you keep another language equally close at hand, and if so, what is it? We do web, systems/application, and embedded programming (that's the kind of thing where you have a little 16-bit micro with 1K of RAM to play with, nothing to do with "embedding and extending" ala Python). The web work is all Python (back end) plus a tiny bit of Javascript. The systems/app work is all Python. The embedded stuff is part Python, on the larger embedded system which can handle it, and part C, on the tiny micros where Python has no hope, plus a few hundred lines of Assembly code. On a day-to-day basis, over 95% of what we do is Python. > And finally, do you foresee a day when Python can be, for all > practical intents and purposes, your only programming language? No, unless we abandon all embedded programming. But if you exclude that special area, where basically little but C has a foothold, and you exclude the client-side web stuff where Javascript is the only serious option, then we are already using Python as our *only* language, and I have no intention of letting that change any time soon. There is a *huge* benefit, often much underestimated, in maintaining only a small set of technologies, including the programming languages a company/individual actually uses (as opposed to those it knows of). -Peter From mschneider.pad at t-online.de Sat Aug 16 18:37:02 2003 From: mschneider.pad at t-online.de (Marcus Schneider) Date: 16 Aug 2003 15:37:02 -0700 Subject: how does the main module notice when I change a module References: Message-ID: <3f443b52.0308161437.29508e70@posting.google.com> "Colin J. Williams" wrote in message news:... > Bob Gailer wrote: > > At 01:55 PM 8/15/2003 -0700, Marcus Schneider wrote: > > > >> I use PythonWin on WinXP. Every time I change a module, I have to > >> leave PythonWin and re enter to make it notice I have made changes. I > >> guess this is not the normal way to do that.. do I have to store the > >> module at a specific place? Is there a kind of "reset" command to make > >> the main module update specific data? > > > > > > Notice File -> Import (ctrl+I) and its toolbar icon. > > I don't find (ctrl I) in the PythonWin Keyboard Bindings. I didn't find it either, but I tried it and - it works;) and helps most of the time.. Before I also played around with deleting .pyc files, but then it was easier to restart PythonWin ... > > My practice is to delete the .pyc file when this problem arises. > > Colin W > > > > Bob Gailer > > bgailer at alum.rpi.edu > > 303 442 2625 > > > > > > ------------------------------------------------------------------------ > > > > > > --- > > Outgoing mail is certified Virus Free. > > Checked by AVG anti-virus system (http://www.grisoft.com). > > Version: 6.0.506 / Virus Database: 303 - Release Date: 8/1/2003 From usenet_spam at janc.invalid Sun Aug 31 23:10:40 2003 From: usenet_spam at janc.invalid (JanC) Date: Mon, 01 Sep 2003 03:10:40 GMT Subject: confirm unsubscribe from zsh-users@sunsite.dk References: <20030831.095012515090500@csa-net.dk> <9gednbZOl6UBhM-iXTWJiA@comcast.com> Message-ID: "Terry Reedy" schreef: >> And about people using different addresses for >> each list they subscribe to, such as user-xxx-list at dom.tld? > > No. I have never had unlimited address availability. I have exactly > 1 from udel and 7 for the family from ISP. But it soulds like a great > idea. Just yesterday I got virus spam sent to names harvested from a > particular list. If I had a special address for that list, I would > resubscribe with a new name. If I ever buy a domain-name service with > 'unlimited' email accounts, I will try this. Thanks. No need to pay for it: Unlimited aliasses @username.cjb.net for free... :-) (don't use it for important mails--their spam filter is too good sometimes) -- JanC "Be strict when sending and tolerant when receiving." RFC 1958 - Architectural Principles of the Internet - section 3.9 From tzot at sil-tec.gr Sat Aug 23 10:46:33 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Sat, 23 Aug 2003 17:46:33 +0300 Subject: Bug with win32 open and utf-16 file References: Message-ID: <27vekvc6evvn3m5jg8n1en2u42skat42qn@4ax.com> On Sat, 23 Aug 2003 14:36:58 GMT, rumours say that derek / nul might have written: [snip opening 'rb' a UTF-16 file] >The original file has line terminator characters of 00 0d 00 0a. >After being read into a variable or a list the line termination characters have >been changed to 00 0a 00 0a You didn't mention any writing back the file. Do you? How exactly do you write it back? By the way, what are the unicode name for the characters u"\u000a" and u"\u000d"? In ASCII (stripping the MSB), they are LF and CR. -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From grante at visi.com Tue Aug 5 23:47:10 2003 From: grante at visi.com (Grant Edwards) Date: 06 Aug 2003 03:47:10 GMT Subject: Capture output from stderr References: Message-ID: In article , Jeff Epler wrote: >> I've always used a read handler for this in the past, and it worked fine. >> I don't have an example handy... I was about to look up my example program, but you beat me to it. ;) > Here's a little program I just put together, it shows the output from a > command in a scrolling text area, using popen and > _tkinter.createfilehandler. [...] > import Tkinter, _tkinter, fcntl, os, sys > > p = os.popen(command, "r") > pf = p.fileno() > > # Make reads from the popen'd command nonblocking > # (so read returns the bytes available without waiting) > fcntl.fcntl(pf, fcntl.F_SETFL, os.O_NONBLOCK) > > > def readfunc(fileobj, event_type): > bytes = p.read() I always use os.read(pf) rather than the file object's read method to gaurd against cases where the file descriptor is readable when the file object isn't. I don't know if that ever really happens, but it seemed to be the safe thing to do. I suspect that your setting the file descriptor to non-blocking accomplishes the same thing. > if bytes == '': > bytes = "***END OF OUTPUT***" > t.wm_title("%s - COMPLETED - tktail" % command) > _tkinter.deletefilehandler(p) [...] > _tkinter.createfilehandler(p, Tkinter.READABLE, readfunc) > t.mainloop() -- Grant Edwards grante Yow! I need "RONDO". at visi.com From trash at kjn-law.de Tue Aug 12 05:03:32 2003 From: trash at kjn-law.de (Theodor Rash) Date: Tue, 12 Aug 2003 11:03:32 +0200 Subject: Python vs. C# References: Message-ID: <54nm01-tqj.ln1@newsgate.kjn.lan> -------------------------- /| /| | | ||__|| | Please don't | / O O\__ feed | / \ the trolls | / \ \ | / _ \ \ ---------------------- / |\____\ \ || / | | | |\____/ || / \|_|_|/ | __|| / / \ |____| || / | | /| | --| | | |// |____ --| * _ | |_|_|_| | \-/ *-- _--\ _ \ // | / _ \\ _ // | / * / \_ /- | - | | * ___ c_c_c_C/ \C_c_c_c____________ From bignose-hates-spam at and-benfinney-does-too.id.au Tue Aug 19 00:36:33 2003 From: bignose-hates-spam at and-benfinney-does-too.id.au (Ben Finney) Date: 19 Aug 2003 14:26:33 +0950 Subject: Brandon's abrasive style (was Re: What's better about Ruby than Python?) References: <38ec68a6.0308172319.431a4fde@posting.google.com> Message-ID: On Mon, 18 Aug 2003 21:43:12 -0700, Brandon J. Van Every wrote: > Cliff Wells wrote: >> finally I've come to the conclusion that you're not trolling, rather >> merely arrogant and abrasive. > > Bingo! Guilty as charged. And I get more and more abrasive the more > people call me a troll. As do most people who aren't actually > trolling. Quite the opposite -- "get[ting] more and more abrasive the more people call [one] a troll" is *exactly* how a troll acts. People who aren't actually trolling will make efforts to depart from troll-like behaviour when accused of it, to avoid confirming the accusation. -- \ "When I was crossing the border into Canada, they asked if I | `\ had any firearms with me. I said, 'Well, what do you need?'" | _o__) -- Steven Wright | Ben Finney From jjl at pobox.com Sun Aug 3 13:42:38 2003 From: jjl at pobox.com (John J. Lee) Date: 03 Aug 2003 18:42:38 +0100 Subject: command history broken in Python2.3 ? References: Message-ID: <87lluaeiy9.fsf@pobox.com> vincent wehren writes: > Nicola Mingotti wrote: [...] > > the command history doesn't work . > > > > When i use the Up-Arrow in Python2.3 > > started in an xterm i get '^[[A' . > > In IDLE under Windows using Alt-p produce nothig . Don't know about that. > > In IDLE under Linux Alt-p works !! . > > > > Do you have the same behavior in you > > interpreter ? [...] > Just installed 2.3 final release on Linux > Same problem here... But this probably just means the setup scripts didn't find your readline module (or maybe incorrectly picked termlib instead of termcap, or vice-versa). IIRC you can just edit Modules/Config and re-make -- search for 'readline' in that file and see the comment there. John From organistist at yahoo.com Mon Aug 18 16:57:23 2003 From: organistist at yahoo.com (mustafa umut sarac) Date: Mon, 18 Aug 2003 13:57:23 -0700 (PDT) Subject: Adobe photoshop plug in Message-ID: <20030818205723.67679.qmail@web20703.mail.yahoo.com> I am not a programmer. But I have a great plug in idea for photoshop. I want to complete the entire process bymyself with the help of friends. I want to ask that : is python language only or simplest language for to write this plug in ? Do I need to read the entire photoshop code for to write the plug in ? Best wishes , Mustafa Umut Sarac --------------------------------- Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software -------------- next part -------------- An HTML attachment was scrubbed... URL: From shlomme at gmx.net Wed Aug 13 09:45:41 2003 From: shlomme at gmx.net (Torsten Marek) Date: Wed, 13 Aug 2003 15:45:41 +0200 Subject: Is Python your only programming language? In-Reply-To: References: Message-ID: Joe Cheng schrieb: > I'm curious about something... many Artima.com members who have a Java > background and learned Python have come to the conclusion that Java and > Python are highly complimentary languages. They would never consider > filling the place Java has in their toolbox with Python, but recognize there > are many tasks where it really pays to add Python to the mix. > > I want to ask you hard-core c.l.p Pythonistas: Do you use Python for > everything? (and I'm counting Python + C extensions as just Python) Or do > you keep another language equally close at hand, and if so, what is it? And > finally, do you foresee a day when Python can be, for all practical intents > and purposes, your only programming language? > > Execpt one C++ library I have wrapped for use with Python, I tend to utilize Python for everything, GUI programming, general scripting, database and file management etc. Answering your question, I think Python + C is practical (at least for me) in all matters. greets Torsten From tzot at sil-tec.gr Sat Aug 23 22:50:21 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Sun, 24 Aug 2003 05:50:21 +0300 Subject: Threading Oddity? References: Message-ID: <6g9gkvcua6eorflm5540grlhd092epg1q4@4ax.com> On 23 Aug 2003 14:26:28 -0700, rumours say that google at hanger.snowbird.net (Kris Caselden) might have written: >However, my code does indeed run, >without error, which begs the question; how is this working? Kris, I believe your code runs without error in your hardware, and I also know my code runs without error on my hardware. What your post initially implied is that /my/ code wouldn't run on /your/ hardware unless you wrapped the acquire calls in "while loop checks for mutex lock". Did you run my code successfully? If yes, we can skip that question as implicitly answered, if not, come back with more info. In your latest question, "how is this working?", do you mean how mutex locks work? The answer to this is that there are operating system calls whose purpose is to implement such locks, and Python builds on that. If I did not understand your question, please let me know. -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From ialbert at mailblocks.com Thu Aug 28 18:57:59 2003 From: ialbert at mailblocks.com (Istvan Albert) Date: Thu, 28 Aug 2003 18:57:59 -0400 Subject: appoximate string matching library - any interest? Message-ID: <4ZGcnR__JutkFdOiXTWJhQ@giganews.com> Hi all, I'm working on a project that needs approximate string matching such as the String::Aprox module in perl: http://search.cpan.org/author/JHI/String-Approx-3.20/Approx.pm Unlike exact matches approximate (fuzzy) matches can match words having small differences in them, typos, errors or similarly spellings. I was unable to find a similar implementation in python right away so I tried wrapping the perl module's underlying C library into python calls. I turned out to be fairly easy, man is SWIG an awesome product or what ... in a just a few hours I managed to create a quite functional version (see below). In the meantime I have also discovered that there is a similar project Agrepy.py available but I have no idea how well it works. I'm trying to gauge the interest relative to this library, right now it serves my needs yet I wouldn't mind polishing it up and making it public if it appears to be useful for others too. cheers, Istvan. ------------------------------------------------------- import APSE title = "Star Wars - Episode Two" test_word = "Stra Wras - Episode Two" test_list = ["Stra Wars - Episode Two", "Stra Wras - Episode Two", "Stra Wras - Episode Tow"] # allow at most 4 edits ap = APSE.Approx(title, edit=4) #info on the matching parameres print "Info", ap.info() print # only prints matching entries print "Word:", ap.match(test_word) print "List:", ap.match(test_list) print # verbose matching, the first element of the tuple is # the edit distance print "Verbose word:", ap.verbose_match(test_word) print "Verbose list:", ap.verbose_match(test_list) -------------------- output -------------- Info ({'edit': 4}, 'Star Wars - Episode Two') Word: Stra Wras - Episode Two List: ['Stra Wars - Episode Two', 'Stra Wras - Episode Two'] Verbose word: (4, 'Stra Wras - Episode Two') Verbose list: [(2, 'Stra Wars - Episode Two'), (4, 'Stra Wras - Episode Two')] From max at nospam.com Tue Aug 5 11:04:32 2003 From: max at nospam.com (max) Date: Tue, 05 Aug 2003 15:04:32 GMT Subject: py2exe 2.3 In-Reply-To: <3F2FC633.6090408@nospam.com> References: <3F2FC633.6090408@nospam.com> Message-ID: <4IPXa.96711$852.19099@twister.nyc.rr.com> max wrote: > I just installed py2.3, win extensions 2.3 and > py2exe-0.4.1.win32-py2.3.exe. When trying to package a serive I am getting > running py2exe > running build > running build_scripts > running install_scripts > error: python22.dll: No such file or directory > > did I miss something? > thanks, > max. > More info: somehow it's still looking for pywintypes22... From tim.golden at viacom-outdoor.co.uk Thu Aug 28 09:46:33 2003 From: tim.golden at viacom-outdoor.co.uk (Tim Golden) Date: Thu, 28 Aug 2003 14:46:33 +0100 Subject: Windows Remote Log in Message-ID: From: Jesse [mailto:redrumjack at hotmail.com] > I guess it is how can I have a user enter their NT Domain Authentication > and the script use it to log into NT Domains the computer it is running > on it not a member of. I have the impression that you're not 100% clear on how you might be doing these remote operations. Do you envisage remotely "typing in" usernames and passwords, and then remotely "opening up dialogs and pressing buttons"? If so, you're a bit off beam (and a not atypical NT Administrator). If not, then I apologise. (Actually, I apologise anyway; it was a bit rude). I suggest you have a look at WMI. Pick up the module from: http://tgolden.sc.sabren.com/python/wmi.html and have a look at some of the examples in: http://tgolden.sc.sabren.com/python/wmi_cookbook.html Try using it without any particular security qualifiers first; if you really need an explicit log on (you probably won't if you're a Domain Admin and using your own or a trusted domain) then you can specify an explicit wmi moniker in the constructor. TJG ________________________________________________________________________ This e-mail has been scanned for all viruses by Star Internet. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________ From amk at amk.ca Thu Aug 21 08:16:16 2003 From: amk at amk.ca (A.M. Kuchling) Date: Thu, 21 Aug 2003 07:16:16 -0500 Subject: Removing language comparisons References: Message-ID: On Thu, 21 Aug 2003 11:43:59 GMT, > But please, please don't remove the page altogether. Most comparision > issues simply aren't going to change, so the articles just get old, not > outdated. But comparison issues do change over time, e.g. the Python/Scheme comparison at http://www.python.org/doc/pythonVSscheme.html says Python uses only refcounting GC, and claims the Python and Jython implementations are explicitly synchronized. Java performance numbers cited are for JDK 1.1.7, Python performance numbers are for 1.5.2, and so forth. --amk From hokiegal99 at vt.edu Sun Aug 3 17:42:01 2003 From: hokiegal99 at vt.edu (hokiegal99) Date: Sun, 03 Aug 2003 17:42:01 -0400 Subject: Determining if a filename is greater than X characters References: <93f5c5e9.0308021815.44c57a2d@posting.google.com> <3f2cfea8$0$49106$e4fe514c@news.xs4all.nl> <3F2D6A90.1040203@vt.edu> Message-ID: <3F2D81A9.70404@vt.edu> OK, I'll use spaces... I thought tabs akward, but they take less time in my editor than spaces do. Thanks for the for loop idea. It works perfectly. Below is the script with spaces instead of tabs. Thanks again!!! import os print " " setpath = raw_input("Enter the path: ") def truncate(setpath): for root, dirs, files in os.walk(setpath): old_fname = files for old_fname in files: new_fname = old_fname[:27] # print old_fname # print new_fname if new_fname != old_fname: print "file: ",old_fname," truncated to: ",new_fname newpath = os.path.join(root,new_fname) oldpath = os.path.join(root,old_fname) os.rename(oldpath,newpath) truncate(setpath) Alex Martelli wrote: > hokiegal99 wrote: > > >>Thanks for the tips. I got it to work using this: >> >>for root, dirs, files in os.walk(setpath): >>old_fname = files >>new_fname = old_fname[0][:27] >>print old_fname >>print new_fname > > > [note the lack of indentation due to your usage of tabs -- please use > spaces, not tabs, for Python code in messages you post to the net or send by > mail - many popular user-agents for news and mail, such as Microsoft > Outlook Express and KDE's KNode, won't display or process tabs in the > way you might expect them to]. > > > >>The problem with this approach is that it only gets the first filename >>in the directory. I tried doing "old_fname[:][:27]", but that doesn't do >>it. I need to learn more about lists. > > > Since files is a LIST of strings, you may loop (directly or with a > list-comprehension) to process all of its items, i.e., your loop > above becomes: > > for root, dirs, files in os.walk(setpath): > for old_fname in files: > new_fname = old_fname[:27] > print old_fname > print new_fname > > > Alex > From NAICH-SYDNEYCH-EXCHANGE at cowleyhearne.com.au Mon Aug 25 02:40:55 2003 From: NAICH-SYDNEYCH-EXCHANGE at cowleyhearne.com.au (GroupShield for Exchange (CH-EXCHANGE)) Date: Mon, 25 Aug 2003 16:40:55 +1000 Subject: ALERT - GroupShield ticket number OA1945_1061793654_CH-EXCHANGE_ 3 was generated Message-ID: <540F61BD2C9BD64DA18FCB9B7367424D897DB2@CH-EXCHANGE.cowleyhearne.com.au> Action Taken: The attachment was quarantined from the message and replaced with a text file informing the recipient of the action taken. To: mailbox at cowleyhearne.com.au From: python-list at python.org Sent: 217883136,29584084 Subject: Re: Approved Attachment Details:- Attachment Name: your_document.pif File: your_document.pif Infected? No Repaired? No Blocked? Yes Deleted? No Virus Name: -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/ms-tnef Size: 1962 bytes Desc: not available URL: From peter at engcorp.com Wed Aug 27 18:46:29 2003 From: peter at engcorp.com (Peter Hansen) Date: Wed, 27 Aug 2003 18:46:29 -0400 Subject: changing color on the command prompt References: <731fc603.0308271213.4d91ab29@posting.google.com> Message-ID: <3F4D34C5.150FD96E@engcorp.com> Hank wrote: > > does anyone know how to change the foreground color of the command > prompt through python? > > For example if i was printing out an error message, I would like it to > be red where the normal text color is white. The question is underspecified/unclear. 1. What operating system? 2. By "command prompt", do you just mean the console, where text appears, or do you really mean the *prompt* for the operating system, which under Linux is usually something like "[user at host]#" and which under Windows is usually something like "C:\>"? 3. Now you mention error messages... that implies you just mean changing the color of your program's output. If you mean the actual *prompt*, you need to change the right environment variable, which usually needs a separate script. If you mean the console text color, check the archives for the last couple of days for responses to a similar question (search for "ansi.sys" perhaps). -Peter From marco at maggi.luna Sun Aug 3 10:57:00 2003 From: marco at maggi.luna (Marco Maggi) Date: 03 Aug 2003 16:57:00 +0200 Subject: Potentially important real-time on-line discussion References: Message-ID: <87smoix003.fsf@bolt.moon> "Wojciech Kocjan" wrote: >Would it be fair if at this time, some other programmer took >your code, added (not replaced) him to the copyright notice, >changed about 5 things and charged the same for that? > >I do not know the "right" answer to that. That's why a license like the Lesser GPL exists (altough the original purpose of it was different, and someone likes it lesser). You can release as free software only modules implementing some technology (an image format, a compression algorithm, a net protocol, an interface to software XYZ) and sell the whole application to make money. Ciao. -- Marco Maggi From mmoum at woh.rr.com Fri Aug 1 18:27:34 2003 From: mmoum at woh.rr.com (Mike M) Date: Fri, 01 Aug 2003 22:27:34 GMT Subject: Problem with Unzipping/Installing Python-2.3.exe References: Message-ID: Tim, I'm not sure what to tell you. I installed it at work on Windows 2000 Pro, latest SP (not sure of the number, I'm writing this at home) with no problems whatsoever. Did you try redownloading the installer - perhaps there was a transmission error in your download. Hope you get it installed - Python is neat. Mike -- the Moum's (Mike, Dede, Suzanne, Jeff, Kristen) Tipp City, Ohio, USA e-mail: mmoum at woh.rr.com "Timothy Martens" wrote in message news:mailman.1059766289.11881.python-list at python.org... > Hi John, > > We're in the same boat. I too am having trouble with the win installer. > It's just not working. This is also my first attempt(s) to install > Python. I'm running windows 2K. What version are you on? > > I sent a mesage to the list earlier (subject: 2.3 win installer, "Anyone > having problems with the 2.3 win installer? I'm running win2k pro (sp4) > and the installer is freezing after the initial dialogues, just as the > install starts.") -- but haven't got any feedback. I think maybe most of > the people on the list are running Unix? Can someone help us pathetic > windows users? > > Regards, > > tim. > > > --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.505 / Virus Database: 302 - Release Date: 7/30/2003 From adalke at mindspring.com Wed Aug 6 20:41:52 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Wed, 6 Aug 2003 18:41:52 -0600 Subject: Python's biggest compromises References: <899f842.0307310555.56134f71@posting.google.com> Message-ID: Aahz: > Would you care to back up your claim with some actual evidence? Aaaz? What do you define as SMP scalability? For me it's that when my program runs on an SMP machine then I should expect non-trivial performance advantages. (Excepting the effects of othe programs on the system.) This can mean many things. For example, a FORTRAN compiler might parallelize array operations even though to the programmer the FORTAN code is not threaded. Still, for most people the idea of "SMP scalability" is the ability to have separate threads run at the same time on different CPUs. Which doesn't work well for Python if all the threads are busy running native code, due to the GIL. If the threads are usually blocked on I/O then the GIL is released. Your own essay on a multithreaded spider shows you know this well. And for this case Python does have good SMP support, so enoch's complaint about its "non existant" is overstated, but still true in his context of writing a large server app. > (Yes, there are issues with Python on SMP machines, but to call Python's > built-in threading "non-existent SMP scalability" is either a lie or > revelatory of near-complete ignorance. That doesn't even count the > various IPC mechanisms.) Given that it is a problem (and one I've had to deal with), calling it an "issue" seems too weak, while dissing enoch this way is way too strong. There are IPC mechanisms, but if that's your definitions of SMP scalability then any language with socket support (or bindings for PVM/MPI/CORBA/Linda/...) is SMP scalable, which kinda ruins the usefulness of that phrase. I would say Python's SMP scalability is poor for Python-bound threads. Better would be a language where I can share objects between free-running SMP threads, as with Greg Stein's experimental patches years ago. Not-as-good are ones which let me pass data through shared memory, as POSH, and worse are those which assume pickles always work (I use some extensions with unpicklable objects). Even worse (for my development style) are those that require working through some IDL. I also am developing a heavy web app and want scalability on SMP machines, and I also bemoan Python's poor threading applicability for my case. I'll work around it with some IPC mechanism, but it is a workaround. (OTOH, that means bugs in the extensions won't crash the server.) Andrew dalke at dalkescientific.com From faizan at jaredweb.com Sat Aug 2 13:55:04 2003 From: faizan at jaredweb.com (Fazer) Date: 2 Aug 2003 10:55:04 -0700 Subject: String Replacement References: <7b454334.0308011400.266438f9@posting.google.com> Message-ID: <7b454334.0308020955.27cc4a4c@posting.google.com> Urgh, I figured out what I was doing wrong! The problem was that I was directly doing the replacing with a tuple and Python kept on saying that I can't assign it to an object. I tried copying the tuple value to a different variable and it worked out fine. Thanks everyone for their help and I highly appreciate it. From daniel.dittmar at sap.com Thu Aug 7 06:29:59 2003 From: daniel.dittmar at sap.com (Daniel Dittmar) Date: Thu, 7 Aug 2003 12:29:59 +0200 Subject: Version Problem References: Message-ID: Thorsten Bischoff wrote: > Hi all! > > I have created a python extension module written in C. Now when the > last release change took place, the module produces import errors > under windows and some warnings under linux. As far as I understand > the C to Python API has changed and so the module has to be relinked. > But there I see a problem: If I have to relink and recompile my > module every time there is a new python release, there will be no > time left to do the very important things. > > Which is the recommanded way to deal with different python versions > and extension modules? I'm looking for some easy-to-use method, > preventing me from maintaining my module for different python > versions and which gives the user the most flexibillity. That means I > do not want either to enjoin on the user which python version to use > nor to maintain many different versions of my module. The recommended way is of course distutils. But you'd still have to provide binaries at least for Windows users, so you have to build them all. What I did: - write a makefile where the location of the Python includes, the output directory of the object files and the linked extension are all configurable via make variables - this allows to build the extension for all the versions in one directory while sharing object files that are not related to the Python version - I pack them into the following structure: mypackage/__init__.py mypackage/mymod.py mypackage/python15/mymodmodule.so mypackage/python20/mymodmodule.so .. mymod.py contains code like the following: import sys _pythonVersion = sys.version [:3] if _pythonVersion == "2.0": from python20.mymod import * elif _pythonVersion == "1.5": from python15.mymod import * else: raise ImportError That way, I can have one download per platform. > Besides: Does anybody know a good method for GNU autoconf to check > which python version is installed? Not autoconf, but you can use the preprocessor symbols PY_MAJOR_VERSION etc. should your extension support additional features for newer Python versions. Daniel From aahz at pythoncraft.com Tue Aug 12 10:47:33 2003 From: aahz at pythoncraft.com (Aahz) Date: 12 Aug 2003 10:47:33 -0400 Subject: Python vs. C# References: Message-ID: In article , Joe Cheng wrote: > >Python is "strongly" typed in the sense that every object has a type. >It is not "statically" typed in that references do not have types. >Statically typed languages generally require you to declare variable >types (some languages infer them) and in return you get compile-time >warnings when you try to call methods that do not exist or perform >casts that are semantically impossible. > >I may be wrong but I believe C is an example of a language with static >weak typing... you have to declare variable types and some types of >errors can be caught at compile time, but you can perform unsafe casts >and not only will the compiler not stop you but at runtime you won't >get an exception--just a possibly corrupted value in memory. http://www.artima.com/weblogs/viewpost.jsp?thread=7590 -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From gretechsupport at hudsonsoft.com Tue Aug 19 13:34:01 2003 From: gretechsupport at hudsonsoft.com (GRE Technical Support) Date: Tue, 19 Aug 2003 13:34:01 Subject: AutoResponse to: Your application Message-ID: <200308191334173.SM01284@dbserver2> Thank you for your inquiry to the ETS GRE PowerPrep technical support team. We did receive your message and will get back to you as soon as possible. Our hours of operation are Monday through Friday, 8:00 a.m. through 8:00 p.m EST, excluding holidays. In the meantime, until we can respond to your support request personally, here are some answers to some of the more Frequently Asked Questions. Question: I'm having trouble downloading the GRE PowerPrep program, Can you help me? Answer: YES. Scroll down until you see the "Download PowerPrep Now!" button, then click on it once with your RIGHT mouse button and choose "Save Target as..." or "Save Link as.." from the menu. In the new window that opens, click on the "Save" button and the download should begin. If the downloads are continually resetting, re-start your computer, shut down any anti-virus or security software, log onto the internet and try the download again, without performing any other tasks on your computer. Also keep in mind, that if the server is under a heavy load you could experience problems with the download, trying to download during "off peak" hours (early in the morning or late in the evening) should help. If you are in an office environment, are behind a firewall or use a proxy server, there may have been restrictions placed on the type of files you are allowed to download, and where you can download them from. The GRE PowerPrep software is a self-extracting archive with an .EXE extension. You may need to contact your network administrator to let him know that you are trying to download this type of file from an FTP site and need your restrictions removed. Question: When I try to launch the program, I get an error that says, "Missing PRINTING.DLL". Answer: This error usually happens if you try to launch the program by double-clicking directly on the executable file in the installation folder. The program cannot be launched this way. To properly launch the program, click on your "START" button, then on "PROGRAMS" and find the group labeled, "POWERPREP". Click on "PowerPrep GRE" from within that group. Question: Why does the resolution on my screen change when I start up the program? Answer: The program is designed to run at a 640 X 480 screen resolution to simulate the actual testing environment. This is the way your screen will look when you take the actual GMAT test. When you exit the program, your screen resolution will go back to normal. Question: When I exit the program, my usual screen resolution does come back, but my desktop looks scrambled, and some of the icons are in the wrong place. Answer: Close any programs, click on a blank part of your desktop and then press the F5 key. This will refresh your desktop and everything should go back to it's original location. The ETS GRE PowerPrep Technical Support Staff From alessandro at sephiroth.it Thu Aug 7 09:41:49 2003 From: alessandro at sephiroth.it (Alessandro Crugnola *sephiroth*) Date: Thu, 07 Aug 2003 13:41:49 GMT Subject: py2exe problems References: Message-ID: > Which Python version are you using? 2.3 doesn't yet work correctly, but > 2.2 should be ok. thanks for the quick reply.. i'm currently usng python 2.3 in fact.. I will try to get back to 2.2 and let you know -- Alessandro Crugnola [sephiroth] Flash | PHP Developer http://www.sephiroth.it From jar at mminternet.com Sun Aug 3 22:11:28 2003 From: jar at mminternet.com (james roush) Date: Sun, 3 Aug 2003 19:11:28 -0700 Subject: uTidyLib --I'm lost References: Message-ID: In article , jepler at unpythonic.net says... > "yield" is a new keyword, related to support for generator functions. > It is supported in Python 2.2 with "from __future__ import generators" > and in 2.3 by default. Python 2.1 doesn't support the "yield" keyword. > In short, you need to upgrade your Python to use this module. > > Jeff > > Oh. I guess it's to upgrade my Python Installation. Thanks -- ----------------------- James A Roush jar @ mminternet.com ----------------------- From adalke at mindspring.com Thu Aug 21 03:16:38 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Thu, 21 Aug 2003 07:16:38 GMT Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> <6dj2kv8ugkieehs7guh786cl40o5lj6mcs@4ax.com> Message-ID: Alex: > Even GvR > historically did some of that, leading to what are now his mild > regrets (lambda, map, filter, ...). and != vs. <> Can we have a deprecation warning for that? I've never seen it in any code I've reviewed. Andrew dalke at dalkescientific.com From mack at incise.org Wed Aug 27 21:03:37 2003 From: mack at incise.org (mackstann) Date: Wed, 27 Aug 2003 20:03:37 -0500 Subject: Script Discussion & Critique In-Reply-To: <3F4D52AE.8000203@hotmail.com> References: <3F4D31B1.6080802@hotmail.com> <06eqkv4onjh5m4tcbbqkmh8lscaj5niatp@4ax.com> <3F4D4402.3060209@hotmail.com> <3F4D52AE.8000203@hotmail.com> Message-ID: <20030828010337.GB1695@incise.org> On Wed, Aug 27, 2003 at 08:54:06PM -0400, hokiegal99 wrote: > Something odd that I've discovered about this script is that it won't > replace strings at the far left side of a text file *unless* the string > has one or more spaces before it. For example: > > THIS (won't be replace with THAT) > THIS (will be replaced with THAT) > THIS (will be replaced with THAT) > THIS (will be replaced with THAT) See my reply :) -- m a c k s t a n n mack @ incise.org http://incise.org The church is near but the road is icy; the bar is far away but I will walk carefully. -- Russian Proverb From eppstein at ics.uci.edu Mon Aug 11 19:44:52 2003 From: eppstein at ics.uci.edu (David Eppstein) Date: Mon, 11 Aug 2003 16:44:52 -0700 Subject: stretching list comprehensions References: Message-ID: In article , Simon Burton wrote: > >>> del y > >>> nums = [ x+y for x in range(y) for y in range(10) ] > Traceback (most recent call last): > File "", line 1, in ? > NameError: name 'y' is not defined > >>> > > Well.. Is there an inherent reason why this could/should not be made to work? > It does work with the loops in the opposite order: >>> [x+y for x in range(10) for y in range(x)] [1, 2, 3, 3, 4, 5, 4, 5, 6, 7, 5, 6, 7, 8, 9, 6, 7, 8, 9, 10, 11, 7, 8, 9, 10, 11, 12, 13, 8, 9, 10, 11, 12, 13, 14, 15, 9, 10, 11, 12, 13, 14, 15, 16, 17] The way you wrote it doesn't work for similar reasons to why it doesn't work to do for x in range(y): for y in range(10): print x+y The variable y is not defined in time to use it. -- David Eppstein http://www.ics.uci.edu/~eppstein/ Univ. of California, Irvine, School of Information & Computer Science From fa507874 at skynet.be Sun Aug 10 17:23:01 2003 From: fa507874 at skynet.be (conatic) Date: Sun, 10 Aug 2003 23:23:01 +0200 Subject: Hints about a script that read ftp contents .... References: Message-ID: Is there a way to check if it is a directory or a file ? I 'd like to build a function to make a walk-into in the directories but I need a way to know if it is a direcyory or a file. Could you give me any hints ? Conatic On Wed, 06 Aug 2003 23:45:44 +0200, conatic wrote: > > I have read ftpmirror.py but I can' manage to do what I want : I'd like > a script that read ftp directories recursively (ident if a file or a > directory) and puts all pdf's documents in a list. > > Has anyone could give me an example of a function that read contents and > make the difference between files and directory. > > Thanks for reading. > > Conatic From maoy at cis.upenn.edu Tue Aug 12 22:00:03 2003 From: maoy at cis.upenn.edu (Yun Mao) Date: Tue, 12 Aug 2003 22:00:03 -0400 Subject: how to let compiler do a check before I run Message-ID: Hi, python community, I'm enjoying hacking python program right now. It's full of fun. Since I'm a newbie, I always do some typo in the program. However, I have to wait until I run that piece of code to discover the bug. Is there any other better way to check this before I do python myprogram.py, or press C-c C-c in emacs? Thanks a lot! From JBrouwers at ProphICy.com Wed Aug 6 14:55:57 2003 From: JBrouwers at ProphICy.com (Jean Brouwers) Date: 6 Aug 2003 11:55:57 -0700 Subject: Is there some Python + IDE/RAD for real speed development??? References: <96fda9ac.0308060611.56dfca7e@posting.google.com> Message-ID: <25a9ea3e.0308061055.1cc2b2dd@posting.google.com> Edilmar, There are quite a few IDE/RAD tools available for Python, both commercial and open source. See for example this list However, before deciding on an IDE/RAD tool for GUI development, you must consider which underlying toolkit to use, Tkinter, wxPython, PyQt, etc. That could limit your choice. HTH, /Jean Alex Martelli wrote in message news:... > > > Edilmar wrote: > > > Hi, > > > > First of all, I'm new in Python... > > > > I have worked with manu langs and IDEs, like Delphi, VB, JBuilder, > > Eclipse, Borland C++, Perl, etc... > > > > Then, today I think IDEs like Delphi have a excelent environment to > > develop apps with little time. I saw many people talking about Python like > > a easy lang to learn and to develop. But I have look at IDEs for Python, > > or ways to develop GUIs with it, and I think it already is limited when > > comparing with IDEs like Delphi. Is this afirmation true? > > I don't think you have considered all the available GUIs for Python, > and, in particular, the commercial ones (like Delphi and its Linux > version Kylix are commercial). For example, BlackAdder (which uses > the same commercial Qt libraries which I believe Kylix uses) seems > to have the "GUI painter" kind of tool that you require. If it's GUI > painters you're after, I think you can find some, either commercial > or free (not all in definitive versions, many will still be betas), > for most toolkits you might want to use (PythonWorks makes a commercial > one for Tkinter, I think one can use glade + gic [gic.sourceforge.net] > for Gtk, I see somebody's already mentioned Boa for wx, etc, etc). > > > > I look at wxPython and PyGTK, but the samples showed that we have to write > > MANY LINES of code to do simple things. Many people have wrote about the > > advantage of Python to write little code, but, when talking about GUIs, > > I think it's not really true, right? > > If you want a code generator (particularly a tool that generates code > based on a GUI you paint on-screen) that's not hard to find (particularly > if, as in Delphi's case, you're willing to pay for one). The amount of > code to be thus generated for typical GUI's (minus, that is, any logic > behind them) won't be all that different between e.g. Python and Delphi's > Object Pascal. If the code that's automatically generated does all that > your application needs, then it makes no difference to you what language > that generated code is in, of course. > > Python's advantages shine when you have to write code as opposed to being > 100% satisfied with code automatically generated, and in that respect > there is no real difference between GUI's (as soon as you need to > customize the generated code or put custom logic behind it -- via > inheritance, of course, it would be counterproductive to go and edit > files produced automatically by a code generator) and other application > areas. > > > > Using Delphi, little or none code is need for many things, but wxPython > > and PyGTK is the reverse! > > I assume you do not mean what you say, but rather that the GUI painter / > IDE you use generates just about all code you need ("for many things") in > Delphi's case, while you're apparently not using any code generator for > either wxPython or pyGTK and therefore need to write all code yourself. > So, if you want a code generator / GUI painter, get one... > > > Alex From c-b-o-o-m-e-r at tiscali.co.uk Wed Aug 6 09:16:41 2003 From: c-b-o-o-m-e-r at tiscali.co.uk (Christopher Boomer (don't dash!)) Date: Wed, 6 Aug 2003 14:16:41 +0100 Subject: classes (table) References: Message-ID: <3f30ffea$1_1@mk-nntp-2.news.uk.tiscali.com> > def __call__(self, row): > try: > nachname = row.Nachname > except AttributeError: > return 0 > return self.pattern.search(nachname)is not None You should probably start by rewriting your basic function as def search_call (self, row, column): if not hasattr(row, column): return 0 # No such column nachname=getattr(row, column) return self.pattern.search(nachname) is not None Now you can choose the column at will within the program. (nachname is now a poor choice of variable name) To restrict access to columns, restrict this function and provide as a public function the following: def __call__ (self, row): return search_call(row, 'Nachname') Hope this helps. MfG Christopher Boomer. From vze4rx4y at verizon.net Tue Aug 26 18:31:15 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Tue, 26 Aug 2003 22:31:15 GMT Subject: Generator comprehensions -- patch for compiler module References: Message-ID: [Jeff Epler] > Recently, Generator Comprehensions were mentioned again on python-list. > I have written an implementation for the compiler module. To try it > out, however, you must be able to rebuild Python from source, because it > also requires a change to Grammar. If you put your patch on SourceForge, I'll add a link to it from the PEP. That way, everyone who is interested in the subject can experiment with it. only-a-revolutionary-implements-a-rejected-pep-ly yours, Raymond Hettinger From tjreedy at udel.edu Thu Aug 21 22:14:42 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 21 Aug 2003 22:14:42 -0400 Subject: problem with custom sort function .... long References: <1e5ab84a.0308211209.eaf3f22@posting.google.com> Message-ID: "Ken R." wrote in message news:1e5ab84a.0308211209.eaf3f22 at posting.google.com... > Hello all, > I am relatively new to python but I am having an issue with custom > sort functions.. Athough they seem to be working fine! > I am trying to sort a list of lists or tuples with arbitrary ascending > or descending sorts. For example given a list of tuples > ('firstname','lastname','age') I want to be able to sort lastname > descending, firstname ascending and age ascending... > > I wrote a custom function generator to generate a sort function based > on an input list of column numbers and sort direction. Sort seems to > sort the first column ascending regardless of what the sort function > says. I also googled this group for other solutions and found a more > elegant one than mine but with the same results. Given that your example data all have 'a' in the first column, these statements of ill behavior make no sense! > Here is my code and result: > sortList = [('2','D'),('1','D'),('0','D')] > dataList = [] > dataList.append(['a','a','b']) > dataList.append(['a','a','a']) > dataList.append(['a','a','c']) > dataList.append(['a','b','a']) > dataList.append(['a','b','b']) > dataList.append(['a','b','c']) > dataList.append(['a','c','a']) > dataList.append(['a','c','b']) You could just as well write dataList as a single literal. [snip] > [['a', 'b', 'c'], ['a', 'a', 'c'], ['a', 'c', 'b'], ['a', 'b', 'b'], > ['a', 'a', 'b'], ['a', 'c', 'a'], ['a', 'b', 'a'], ['a', 'a', 'a']] and columns 2, 1, and 0 are descending (non-increasing) in that order, just as you asked. What different were you expecting given the input. > and Manuel Garcia's solution and results: > sortList = [(0,-1),(1,-1),(2,-1)] ... > Results: > [['a', 'c', 'b'], ['a', 'c', 'a'], ['a', 'b', 'c'], ['a', 'b', 'b'], > ['a', 'b', 'a'], ['a', 'a', 'c'], ['a', 'a', 'b'], ['a', 'a', 'a']] Again, just as requested. Same question. > is this an issue with sort or is my code screwy? Perhaps your understanding of ascending and descending? or of nested sorting? Terry J. Reedy From aleax at aleax.it Mon Aug 11 04:48:58 2003 From: aleax at aleax.it (Alex Martelli) Date: Mon, 11 Aug 2003 08:48:58 GMT Subject: How to print floating point in scientific format? References: <420ced91.0308081115.7060e551@posting.google.com> <420ced91.0308101127.644f9813@posting.google.com> <_%zZa.37775$an6.1321077@news1.tin.it> <420ced91.0308101952.73f4fa9b@posting.google.com> Message-ID: <_LIZa.65684$cl3.2137489@news2.tin.it> sdhyok wrote: ... >> I've never heard a scientific programmer complain too badly about >> how Numeric treats arrays, whether they were coming from Fortran >> (the typical case), other higher-level languages, or general purpose >> languages not really suited for scientific computation (such as C). > > Right, we can use scientific binary formats, like NetCDF, HDF. > But, we often want to read the data in our naked eyes > and exchange them with spreadsheet. For "exchange with spreadsheets" see the csv module (new in 2.3), e.g.: >>> import csv >>> import sys >>> csv.writer(sys.stdout).writerow([ 100.+i for i in range(3,8) ]) 103.0,104.0,105.0,106.0,107.0 >>> It doesn't, of course, force scientific format (it uses the general format) -- spreadsheets don't need that. However, it does have the concept of a "Dialect" (here, I've let the dialect default to 'excel'), a bundle of formatting parameters that tweak the output into the best form for a given spreadsheet; that doesn't provide the specific bit of formatting control you want, but it gives what's clearly the right "hook" on which to hang any kind of formatting control. If you need to pursue "exchange with spreadsheet" and you have a use-case for needing scientific format in such a setting, then proposing a patch to module csv [having the dialect optionally record the preferred way to format floating point numbers] might stand a good chance. Right now, _csv.c [line 1126 in the sources) just transforms the fields it's emitting with PyObject_Str(field) -- equivalent to the Python call str(field), just as the print statement does. But just as it nows checks dialect->quoting before coming to that, it might well check some other field of the '*dialect* structure in order to influence output formatting selectively -- *IF* good use cases could be found and verified where a spreadsheet's behavior can be made better by special formatting of numbers fed to it. >> You seem to be focused on readable display of arrays (quite an >> unusual focus for scientific programming). So, worst case, it's trivial >> to write a general purpose function that takes an array of ANY size >> and rank and emits it in the way you prefer -- easier than in any >> other language commonly used for scientific programming. >> >> So, you don't need anything from Python -- just write that blessed >> function and scientifically program to your heart's content. > > Trivial to create my own function. We agree. > But, surprisingly no common function or command for the work. Actually, Numeric.array2string IS exactly such a "common function or command". It's been written 7 years ago by Konrad Hinsen and happily used ever since by thousands of happy users of Numeric -- how much more common than this can you get? However, among its very numerous formatting parameters, it does NOT have one to let you force exponential format as opposed to fixedpoint format -- it always decides that tidbit (i.e. whether an 'e' or 'f' is ultimately used in the format string) by itself. Clearly, no Numeric user has had substantial need for this kind of forced output formatting over these many years -- which I do not find at all surprising. Still, array2string is a Python coded function -- see its sources in Numeric/ArrayPrinter.py -- so that experimenting with changes to it is trivial, and maybe the Numeric maintainers will look with favour upon a patch, should you decide to offer one. It might be as simple as adding yet one more optional parameter to the array2string function, say "forcedformat" defaulting to None, passing it on to the underlying internal _floatFormat function it calls to determine the format string, and having _floatFormat just use it, if not None, instead of determining the format itself. I would suggest you make a copy of ArrayPrinter.py, tweak it to your own satisfaction, then send the resulting patch to the Numeric maintainers proposing inclusion in Numeric's next release. > Maybe, one solution is > > import Numeric as N > N.print(array, format="%.2E") In my opinion, the solution I just sketched for you, i.e.: print N.array2string(array, precision=2, forcedformat="E") stands a much better chance than the addition of a new function that does direct printing (rather than the more useful and flexibile formatting-to-string) and merges precision and formatcharacter into one argument (note that array2string does already accept a precision argument) -- even without considering the fact that 'print' is a keyword and thus not usable as a function-name. Alex From nomail at magicfish.net Sat Aug 2 05:36:37 2003 From: nomail at magicfish.net (Austin Luminais) Date: 2 Aug 2003 02:36:37 -0700 Subject: pyrex error References: Message-ID: "Bryan" wrote in message news:... > i'm having trouble building the pyrex demos. i also can't compile a simple > hello word example. i keep getting this '__pyx_f' unknown size error. > here's the error i'm getting when executing the following script. > > i'm using vc 6.0 on windows xp > python 2.3 > I've been experiencing the same problem since upgrading python to 2.3. I think the definition of "staticforward" must have been changed. A temporary fix that seems to work (with MSVC 6.0) is changing this line in the generated code: staticforward char *__pyx_f[]; to: extern char *__pyx_f[]; From c-b-o-o-m-e-r at tiscali.co.uk Fri Aug 15 03:19:39 2003 From: c-b-o-o-m-e-r at tiscali.co.uk (Christopher Boomer (don't dash!)) Date: Fri, 15 Aug 2003 08:19:39 +0100 Subject: German umlaut in a string. References: <7h37k5g40sb.fsf@pc150.maths.bris.ac.uk> Message-ID: <3f3cd8f0_1@mk-nntp-2.news.uk.tiscali.com> > > But I have a string that was converted from a tuple to a string. > Oh, hang on... when you 'str' a tuple, its contents get 'repr'ed, > so you get backslash escapes... > PS: You want to be using the .replace() string method for > things like this Would converting the tuple to a string with ",".join(mytuple) rather than str() work more as he expects in this situation? Christopher From tim.golden at viacom-outdoor.co.uk Thu Aug 28 11:50:51 2003 From: tim.golden at viacom-outdoor.co.uk (Tim Golden) Date: Thu, 28 Aug 2003 16:50:51 +0100 Subject: Windows Remote Log in Message-ID: [TJG: I've slightly rearranged the posts so they read top-to-bottom] > From: Jesse [mailto:redrumjack at hotmail.com] > >I guess it is how can I have a user enter their NT Domain Authentication >and the script use it to log into NT Domains the computer it is running >on it not a member of. > From Tim: > > I suggest you have a look at WMI. > Try using it without any particular security qualifiers > first; if you really need an explicit log on (you probably > won't if you're a Domain Admin and using your own or a > trusted domain) then you can specify an explicit wmi > moniker in the constructor. > TJG > From Jesse: > This is a mixture of NT 4 and Win2K Servers. > WMI may not be installed on all the remote systems. Does that mean it could not be? It's available for both (and is, I think, there by default on Win2K). Maybe there are political reasons or fears for stability of long-running NT4 servers? We have that problem here. > We have quite a few NT domains that our servers are spread out over and > sometimes the machine I would execute the script from would not be in > the same Domain and need different Logon Credentials to access the > remote machine. Understood. > Often certian services for the applications we maintain will need to be > restarted on these remote machines. I've found a way to this this with > a Python Module called WService. I've not come across this module; is it one you've written yourself? Or could you give a URL where it could be found? Assuming, in any case, that it's based on Mark Hammond's win32service, a quick browse of the docs for that suggest that, although you can control services on other machines, there's no way of authenticating yourself in the process. Here, I think, WMI would probably serve you best, because it does allow explicit domain-credential logons (in a slightly roundabout way), and once you're in, stopping and starting services is a snap. Having said that, getting the combination of local security and remote credentials right is a bit of a pain. Judging by past threads, I think other people on this list have more experience of that than I. Maybe something like this would suit: import win32com.client import wmi def list_services (machine, username, password): locator = win32com.client.Dispatch ("WbemScripting.SWbemLocator") remote_wmi = locator.ConnectServer (machine, "", username, password) remote_machine = wmi.WMI (wmi=remote_wmi) # # This just lists all services; obviously it # could stop, or start, or delete or whatever. # for s in remote_machine.Win32_Service (): print s.Caption, s.State TJG ________________________________________________________________________ This e-mail has been scanned for all viruses by Star Internet. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________ From postmaster at esealnt614.al.sw.ericsson.se Fri Aug 22 10:49:15 2003 From: postmaster at esealnt614.al.sw.ericsson.se (postmaster at esealnt614.al.sw.ericsson.se) Date: Fri, 22 Aug 2003 16:49:15 +0200 Subject: Delivery Status Notification (Failure) Message-ID: This is an automatically generated Delivery Status Notification. Unable to deliver message to the following recipients, due to being unable to connect successfully to the destination mail server. 2AA0D08302B90A4199CDF7FD147572470CA104 at ecnbjnt513.itc.ericsson.se -------------- next part -------------- An embedded message was scrubbed... From: Subject: Re: Details Date: Wed, 20 Aug 2003 21:01:37 --0700 Size: 1516 URL: From max at alcyone.com Tue Aug 26 16:26:23 2003 From: max at alcyone.com (Erik Max Francis) Date: Tue, 26 Aug 2003 13:26:23 -0700 Subject: Uncatchable socket.error in socket.py (?) References: <3f4ba0bb$0$49103$e4fe514c@news.xs4all.nl> <3F4BB475.DCECCAA4@alcyone.com> Message-ID: <3F4BC26F.C4CB6F76@alcyone.com> Rune wrote: > I cannot connect to the server any longer and connection.send(data) > will generate a new socket.error: (9, 'Bad file descriptor') I see; it wasn't entirely clear to me what your complaint was from your first message. If you're getting an exception when calling recv, the connection has already dropped. You can't send the message because the connection isn't there anymore. Catching or not catching an exception won't change that. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ Peace with a cudgel in hand is war. \__/ (a Portugese proverb) From mpeuser at web.de Fri Aug 29 11:13:28 2003 From: mpeuser at web.de (Michael Peuser) Date: Fri, 29 Aug 2003 17:13:28 +0200 Subject: win32 file attributes References: Message-ID: "David Bear" schrieb im Newsbeitrag news:m3wucxo1te.fsf at moroni.pp.asu.edu... > Using the windows explorer it is possible to get file properties which > include under the version tab, 'company name', 'version', etc. I'm > assuming these metadata are actually stored in the exe somewhere. Is > there an api exposed to python that would allow me to get this info? > > a scan of Mark Hammonds win32all package did have anything obvious > jump out at me... Have a look at Mcmilan Installer (which is a very useful piece of software anyway). They have a versionInfo.py modul (519 lines Python) there. (You probably have to download the whole installer for that I think..) Kindly Michael P From ulope at gmx.de Sun Aug 31 21:15:42 2003 From: ulope at gmx.de (Ulrich Petri) Date: Mon, 1 Sep 2003 03:15:42 +0200 Subject: Declaration of an array of unspecified size References: Message-ID: "Bertel Lund Hansen" schrieb im Newsbeitrag news:m814lvc8h44vbd5g1m2iv05r33qg8ag9ta at news.stofanet.dk... > Hi all > > I am relatively new to Python but have som programming > experience. I am experimenting wit a POP3-program and it's fairly > easy. > > I want to read the mails into an array of lists so I later can > choose which one to display. But I need to declare an array of > unknown size before I can use it in the code. How do I manage > that? You don't. Python doesn't have the concept of declaring variables. > > class PopMailServer: > host = "" > user = "" > password = "*" > mails = 0 > mail[] # This is wrong but what do I do? mail = [] #would work But you are creating class-variables here. Are you sure thats what you want? > def __init__ (self): > pop=poplib.POP3(self.host) > pop.user(self.user) > pop.pass_(self.password) > self.mails=len(pop.list()[1]) > for i in range(self.mails): > self.mail[i]=pop.retr(i+1)[1] # This is also wrong. > pop.quit() > print "Antal mails: %d\n" % self.mails you can skip the "mails" variable. len(mail) will give the same. An optimzed (untested) version: class PopMailServer: def __init__(self, host, user, pass): self.host = host self.user = user self.password = pass self.mail = [] def action(self): pop = poplib.POP3(self.host) pop.user(self.user) pop.pass_(self.password) for x in p.list()[1]: num, len = x.split() self.mail.append(pop.retr(num)[1]) pop.quit() print "Total mails: %d" % len(self.mail) of course this lacks exception handling... HTH Ciao Ulrich From adalke at mindspring.com Thu Aug 21 01:54:47 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Thu, 21 Aug 2003 05:54:47 GMT Subject: Weird Problem References: <0HY0b.24239$Cd2.10527@nwrdny01.gnilink.net> Message-ID: Carl Banks: > BTW, you don't know this, but since you're using 2.3, you should > probably start using "file" instead of open: Something I rather don't like given how much old code I have which uses 'file' as a variable. Ditto for quite a few pieces of the standard library. Andrew dalke at dalkescientific.com From kmj9907 at cs.rit.edu Sat Aug 2 14:31:28 2003 From: kmj9907 at cs.rit.edu (Keith Jones) Date: Sat, 02 Aug 2003 18:31:28 GMT Subject: very newbie question References: Message-ID: On Sat, 02 Aug 2003 17:42:08 +0200, Agent Mulder wrote: > Hi group, > > I wonder if I can do Windows programming > in python. I work with c++ now and do the > Windows part raw. It's difficult to get my app > over 150K (need some heavy inlining, that's all). > Does python support nitty-gritty Windows- > programming? > > -X I suppose it depends on just how nitty-gritty, but yes. Googling for "python win32" should give you plenty of leads. O'reilly even has a book on python and win32. From adalke at mindspring.com Mon Aug 18 05:11:20 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Mon, 18 Aug 2003 03:11:20 -0600 Subject: What's better about Ruby than Python? References: Message-ID: Brandon J. Van Every: > I have > noticed, however, that every programmer I talk to who's aware of Python is > also talking about Ruby. So it seems that Ruby has the potential to compete > with and displace Python. I'm curious on what basis it might do so. Your logic is specious and your observations biased. Perhaps the programmers "aware of Python" that you know are more interested in comparing different languages, so know more about languages in general? How many Ruby programmers (per capita) do you know talking about Python? Perhaps Python "has the potential to ...display Ruby" How many Python-aware programmers do you know who also talk about Java? Also talk about C#? About C++? About BASIC? I don't know the programmers you sample from. but looking at c.l.py since the start of the year, I can give you some numbers about other languages mentioned. (From Google 'groups' search, numbers are approximate.) java group:comp.lang.python from Jan 1, 2003 to today. 1,680 perl group:comp.lang.python from Jan 1, 2003 to today. 1,550 tcl group:comp.lang.python from Jan 1, 2003 to today. 470 pascal group:comp.lang.python from Jan 1, 2003 to today. 295 ruby group:comp.lang.python from Jan 1, 2003 to today. 279 haskell group:comp.lang.python from Jan 1, 2003 to today. 155 eiffel group:comp.lang.python from Jan 1, 2003 to today. 99 rexx group:comp.lang.python from Jan 1, 2003 to today. 99 awk group:comp.lang.python from Jan 1, 2003 to today 58 ocaml group:comp.lang.python from Jan 1, 2003 to today. 26 Based on your logic, you should try pascal or tcl instead of ruby. Though you really should be using perl or Java. Of course, percent change is a better metric for up-and-coming, so here's numbers for all of 2002. To get estimated 2003 numbers I multiplied the above by 12/8, which means I'm a little on the low side since August is only half-way through. 2002 2003 change est. % Java 2710 2520 - 7 perl 2580 2325 -10 tcl 922 705 -23 pascal 396 442 +12 ruby 542 418 -22 haskell 107 232 +117 eiffel 65 148 +128 rexx 95 148 + 56 awk 93 87 - 6 ocaml 60 39 - 35 Again, you looks like you should use Pascal. Or maybe haskell, which was talked about a lot more this year already than all of last year! (I keep meaning to learn some of it.) So I suspect despite your statement about having no preconceived ideas about Ruby that you do have some, which sensitises you to discussions which mention it. BTW, ruby's numbers on c.l.py for 2003 446 (I used 12/7.5 for a slightly better estimate) 2002 542 2001 487 2000 291 1999 162 1998 4 And Haskell's 2003 248 (ditto on 7.5) 2002 107 2001 282 2000 251 1999 63 1998 7 Given how many more people use Ruby than Haskell and how much Ruby is mentioned as an alternative to the big 3 of Perl, Python, and Tcl, it kinda makes you wonder if we aren't just a bunch of programming language wonks in this group. :) If so, it would again mean you aren't critical enough of your own beliefs and conclusions. Andrew dalke at dalkescientific.com From zcoder at bigmir.net Wed Aug 13 19:21:14 2003 From: zcoder at bigmir.net (Vlad Sirenko) Date: 14 Aug 2003 02:21:14 +0300 Subject: How to make tree of dictionaries? References: Message-ID: <877k5hf8k5.fsf@big.terem> >>>>> "Bob" == Bob Gailer writes: Bob> I thought we made dictionaries out of trees... Are you trying to Bob> reverse entropy? Yeah, and create brand-new private universe :) You are good on playing words. If you are not a big boss yet it is time to give thought to it ;) -- WBR, VS A programming language is low level when its programs require attention to the irrelevant. From http Fri Aug 8 23:53:57 2003 From: http (Paul Rubin) Date: 08 Aug 2003 20:53:57 -0700 Subject: Python and Web Hosting References: Message-ID: <7xfzkb5vvu.fsf@ruckus.brouhaha.com> "Ken Fettig" writes: > Hello, I am begining to learn the Python language and I am enjoying its > flexibility. I do have a question. I am considering using Python for web > development. I have found that a huge number of web hosts offer support for > PHP. How hard is it to find a Web Host that will allow you to you to run > your own Python scripts, web or app server, template engine (Zope or > Cheetah)? If it is not, is it comparable in cost? There are some hosts that let you run Python scripts. They're not as easy to find as PHP hosts, but they're out there. Sometimes they don't always have the latest version, and so forth. Another possibility is to run a host or virtual host of your own. That lets you install any software you want. It's a bit more expensive than basic web hosting, and you have to do more of your own system administration, but it's much more flexible. See http://www.usermodelinux.org for pointers to some providers. From gb at cs.unc.edu Thu Aug 7 17:09:14 2003 From: gb at cs.unc.edu (Gary Bishop) Date: 7 Aug 2003 17:09:14 -0400 Subject: email client written with python + wxWindows References: <409a56e2.0308062211.456575df@posting.google.com> Message-ID: <3f32bffa_1@news.unc.edu> On Wed, Aug 06, 2003 at 11:11:52PM -0700, Shagshag wrote: > does anyone know of a full python + wxWindows email client ? I wrote GBMail for my own use. I like it a lot. It likely wouldn't suit anyone else but writing it was sure a fun way to learn Python. I haven't posted the source anywhere but I'd be happy to share it with anyone interested. I used Python, wxPython, and my own SWIG wrapper for the UW Imap client library. It has automagic completion on email addresses, on-the-fly spell checking in composition windows, html display using IE embedded in a window, fast full-text search of all my email messages, some tricks for handling attachments, and other stuff I can't think of now. I looked at all the email clients and they were all broken in one way or another. I figure there must be some constant of brokenness for email programs. GBMail is broken too, just not in ways that bother me :-) gb From dave at pythonapocrypha.com Wed Aug 20 22:32:52 2003 From: dave at pythonapocrypha.com (Dave Brueck) Date: 20 Aug 2003 19:32:52 -0700 Subject: Problems with python-list? Message-ID: <477762c2.0308201832.327cf5bc@posting.google.com> Is anybody else having problems sending email to python-list at python.org? About 48 hours ago or so my posts stopped making it to the list (I usually post via the mailing list rather than to the Usenet group). I tried unsubscribing and resubscribing to the list, but that turned out to be a mistake because once the list server sent me the email to confirm my subscription request, my reply email confirming it got ignored too! Does anybody know if something changed on the mailing list in the past 1-3 days? I don't know of anything that happened on my end as emails to every other destination still work and up until I tried to unsubscribe and resubscribe I was still receiving python-list emails as well as my normal mail. Any help or hints would be appreciated! Thanks, Dave P.S. Also, I sent emails to the list admin address, but that too is a python.org address so I don't know if that made it. P.P.S. Also also, I tried subscribing from 3 different accounts in two different states in the U.S., but to no avail. :) From skip at pobox.com Thu Aug 7 10:34:21 2003 From: skip at pobox.com (Skip Montanaro) Date: Thu, 7 Aug 2003 09:34:21 -0500 Subject: True In-Reply-To: References: <3F312A65.5312B6EA@engcorp.com> Message-ID: <16178.25453.427666.933409@montanaro.dyndns.org> Dan> Thanks Peter, that will do the trick. Just wondering though why you Dan> chose to code the opposite values and not as Dan> def boolean2String(boolVal): Dan> return {True:'1', False:'0'}[boolVal] What if boolVal isn't actually True or False? An empty list is considered a false value. To get a boolean from that, you throw 'not' in front of it: >>> [] [] >>> not [] True >>> not 23 False Skip From aleax at aleax.it Tue Aug 5 08:00:14 2003 From: aleax at aleax.it (Alex Martelli) Date: Tue, 05 Aug 2003 12:00:14 GMT Subject: Is there the same function in python as atoi() in C References: Message-ID: Robbie wrote: > Someone tell me, > if not exist, how to write one with the same function? > I have made a try, but there is no character type in python, > so i failed, someone help me, > thanks very much I see somebody already suggested string.atoi(astring, base) [with the base defaulting to 10], but a simpler way is to just call int(astring, base) [again, base defaults to 10] -- int is a built-in, and all that function atoi in module string does is actually to delegate right on to int. Alas, we don't have such a generalized-base "itoa" -- only the built-ins str(i) [base 10], oct(i) [base 8], hex(i) [base 16]. Alex From jacek.generowicz at cern.ch Sat Aug 23 14:29:28 2003 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 23 Aug 2003 20:29:28 +0200 Subject: What's better about Ruby than Python? References: <4o_0b.1665$Ej6.1182@newsread4.news.pas.earthlink.net> <8D01b.1721$Ej6.702@newsread4.news.pas.earthlink.net> <3F44ED2E.9070308@nyc.rr.com> <0V61b.1900$Ej6.1012@newsread4.news.pas.earthlink.net> <3F4504D7.20008@nyc.rr.com> <2259b0e2.0308230118.67a676e7@posting.google.com> <2259b0e2.0308230712.3f60cf3c@posting.google.com> Message-ID: mis6 at pitt.edu (Michele Simionato) writes: > Perl is NOT a dialect of Python. Ruby is NOT a dialect of Python. Tcl > is NOT a dialect of Python. They are entirely different languages, Oh ferchrissakes ... Scheme is not a dialect of Common Lisp, elisp is not a dialect of Common Lisp, etc. etc. They are entirely different languages. Please stop (not you in particular, but you all in general) taking a whole bunch of different languages, which happen to share one characteristic, and claiming that they are dialects of eachother. Perl NOT being a dialect of Python (and the similarity of this fact to the fact that Scheme is not a dialect of Common Lisp) is exactly my point. > I would concede than in many ways Python, Perl and Ruby are similar > and more or less with the same power, bust still the way of > programming in one or the other is completely different. Well, guess what, the ways one programs in CL, Scheme and elisp are also completely different. > I would concede that Lisp is different from Scheme, more at the conceptual > level that at the syntactical level. But still the reality is that the > different implementations of Lisp and Scheme are different, Well, yes, that's generally true of implementations of _completely different languages_ ! > especially in what concern the interface with the operating system > and scripting facilities, which is what one does all the time (at > least in this mailing list ;). So once I know an implementation, I > am never sure my program will run on another implementation, Once you know CPython, you are sure that your program will run in Jython? > if you prefer the term implementation to the term dialect. Don't brush this difference off so lightly, for it is a very significant one. Many languages are standardised. For example Common Lisp. There are many implementations of Common Lisp. Scheme and elisp are most certainly NOT implementations of Common Lisp. "Dialects" of Common Lisp do not exist. > On top of that, how am I supposed to choose my implementation? Price, availability on the platform which interests you, quality of implementation, the license conditions, the demands of your clients, implementation-specific extensions, etc. ... just like for any other language with multiple implementations. If you want to aruge that a single implementation language offers certain advantages purely by having a single implementation, fine. But don't use it as an argument to support the (hopelessly false) thesis that Lisp macros are evil and are responsible for the "fragmentation" of Lisp. C++ (and other languages) also have many implementations; this has absolutely nothing to do with them having powerful macros. > Too much choice (meaning a too much fragmented community) can scare > potential lisp newcomers. Funny, I usually hear the criticism that Lisp is dead and that there aren't _enough_ implementations of it. Anyway, repeat your argument to yourself, substituting C++ (or any other standardized language) for Lisp, and see how ridiculous it sounds ... and bear in mind that we supposedly got this excess of choice because Lisp macros inevetably lead to Lisp fragmentation. > At least it scared me. There is only one dominant implementation of > Python, CPython. All the others try to match it as soon as > possible. I expect Jython 2.2 (now in alpha) will catch up with > CPython, at some moment. Guess what: Having a mature standard means that your "standard" doesn't change every year or two, as is the case in Python. You'll find that implementations of Common Lisp are far more compatible than the various Python implementations. I don't have to wait for Corman to catch up with MCL (or whatever), because Common Lisp in not a moving target, unlike Python. > In Scheme there is no such a basic reference, I am correct? You are not correct. However, it is so minimalistic that every implementation provides so much "added value" to make it usable out of the box, that they are effectively incompatible. This, still, has nothing to do with macros. (NB, I do _not_ program in Scheme. Caveat emptor.) > Lisp has CL, but learning CL will not help me very much with Emacs The Algol Family has C++, but learning C++ will not help you very much with Python. > Lisp which is what I would need the most ;) I am joking a bit here; No. You are _completely_ joking :-) From cpbarton at pacific.net.au Sat Aug 30 13:57:54 2003 From: cpbarton at pacific.net.au (Ideasman) Date: Sat, 30 Aug 2003 13:57:54 -0400 Subject: My script is taking 12 hours+ any suggestions? In-Reply-To: References: <3f4ff9f8$0$23588$5a62ac22@freenews.iinet.net.au> Message-ID: <3f500589$0$23595$5a62ac22@freenews.iinet.net.au> Its indenting for me- Netscape/Mozilla John Roth wrote: > Your script isn't indented properly in Outlook Express, > making it very difficult to read > > John Roth > > "Ideasman" wrote in message > news:3f4ff9f8$0$23588$5a62ac22 at freenews.iinet.net.au... > >>Hi I have a made a script that process normals for a flat shaded 3D > > mesh's. > >>It compares every vert with every other vert to look for verts that can >>share normals and It takes ages. >> >>I'm not asking anyone to rewrite the script- just have a look for any >>stupid errors that might be sucking up time. >> >> >> >> >> >> >> >> >>#!/usr/bin/python >>############## >># AUTOSMOOTH # >>############## >>import sys >>import os >>import string >>import math >> >># Used to write floats that dont' contain letters/ >>def saneFloat(float): >>#return '%(float)b' % vars() # 6 fp as house.hqx >>return '%f' % float # 10 fp >> >> >> >>#Open file from the command line, turn into a list and close it. >>file = open(sys.argv[-1], 'r') >>fileLineList = file.readlines() >>file.close >> >># Remember the number of lines for progress indication. >>fileLen = len(fileLineList) >> >># Autosmooth value. Higher will autosmooth larger angles. >>maxDiff = 1.66 >> >># Loop through the lines. >>lineIndex = 0 >>while lineIndex < len(fileLineList): >> >>#Find Geom TAG.. >>if str(fileLineList[lineIndex])[0:8] == 'Geometry': >>lineIndex += 1 >># break if looping beyong the file, >>if lineIndex > len(fileLineList): >>break >> >># Here we remember lines that have been processed. >># it needs to be reset for each geom object. >>listOfDoneLines = [] >> >># Start a new loop that checks the current vert against all the others >>newLoopindex = lineIndex >>while len(string.split(fileLineList[newLoopindex])) == 12: >>print '\n', fileLen, newLoopindex, >> >>#vertexnum = newLoopindex - lineIndex >> >># Compare the 2 lines >>newCompareLoopindex = newLoopindex + 1 # compare the current vert to >>this new one. >>thisPassDoneLines = [] # act apon this after comparing with each vert >>thisPassDoneNormals = [] >>while len(string.split(fileLineList[newCompareLoopindex])) == 12: >> >># Speed up the process by using 2 if's, splitting the string only if >>it has not been evaluated already. >>if newCompareLoopindex not in listOfDoneLines: >>comp1 = string.split(fileLineList[newLoopindex]) >>comp2 = string.split(fileLineList[newCompareLoopindex]) >> >>if [comp1[0], comp1[1], comp1[2]] == [comp2[0], comp2[1], comp2[2]]: >> >>if newLoopindex not in listOfDoneLines: # Only needs to be added once >>listOfDoneLines.append(newLoopindex) >> >>if newLoopindex not in thisPassDoneLines: # Only needs to be added >>once >>thisPassDoneLines.append(newLoopindex) >>thisPassDoneNormals.append([eval(comp1[8]), eval(comp1[9]), >>eval(comp1[10])]) >> >>listOfDoneLines.append(newCompareLoopindex) >>thisPassDoneLines.append(newCompareLoopindex) >>thisPassDoneNormals.append([eval(comp2[8]), eval(comp2[9]), >>eval(comp2[10])]) >>print '#', >> >>newCompareLoopindex += 1 >> >> >> >>if len(thisPassDoneLines) > 1: # Ok We have some verts to smooth. >> >> >># This loops through all verts and assigns each a new normal. >>for tempLineIndex in thisPassDoneLines: >> >>tempSplitLine = string.split(fileLineList[tempLineIndex]) >> >># We add to these for every vert that is similar, then devide them >>to get an average. >>NormX = 0 >>NormY = 0 >>NormZ = 0 >> >># A list of vert line indicies that we will create to store verts >>that have normals close to ours. >>thisVertFrendsCount = 0 >> >># This compares the current vert with all the others, if they are >>close then add to vertFrends. >>for tNorm in thisPassDoneNormals: # tNorm is just used for one of >>the normals in the thisPassDoneNormals >> >>if abs(eval(tempSplitLine[8]) - tNorm[0]) + >>abs(eval(tempSplitLine[9]) - tNorm[1]) + abs(eval(tempSplitLine[10]) >>-tNorm[2])< maxDiff: >> >>#maxDiff >>NormX += tNorm[0] >>NormY += tNorm[1] >>NormZ += tNorm[2] >> >>thisVertFrendsCount += 1 >> >> >>#Now devide the normals by the number of frends. >>NormX /= thisVertFrendsCount >>NormY /= thisVertFrendsCount >>NormZ /= thisVertFrendsCount >> >># make unit length vector. >>d = NormX*NormX + NormY*NormY + NormZ*NormZ >>if d>0: >>d = math.sqrt(d) >>NormX/=d; NormY/=d; NormZ/=d >> >> >># Write the normal to the current line >>tempSplitLine[8] = str(saneFloat(NormX)) >>tempSplitLine[9] = str(saneFloat(NormY)) >>tempSplitLine[10] = str(saneFloat(NormZ)) >> >>fileLineList[tempLineIndex] = string.join(tempSplitLine) + '\n' >> >> >> >>newLoopindex += 1 >> >>lineIndex += 1 >> >> >># Writing to file >># file to write >>file = open(sys.argv[-1], 'w') >>file.writelines(fileLineList) >>file.close() >> > > > From my_junk at pa.net Mon Aug 4 22:49:51 2003 From: my_junk at pa.net (Art) Date: Mon, 04 Aug 2003 22:49:51 -0400 Subject: Beginner's popups in vanilla Python program In-Reply-To: References: Message-ID: <3.0.5.32.20030804224951.00a3ea10@mail.pa.net> Stephan ... Thank you immensely for recommending "EasyGUI". That is EXACTLY what I was looking for. I did, of course, notice that you are the author! Where do I send the check? Anyone else looking for some simple popups ought to try EasyGUI ... it is a fantastic tool for getting ramped up in Python! It is a really nice compact collection of Message boxes and modal dialog popups to start off with. Blessings in abundance, all the best, and ENJOY! Art Du Rea, Carlisle, PA USA At 05:42 AM 8/4/03 -0700, Stephan Ferg wrote: >Look at EasyGui: >http://www.ferg.org/easygui/ > >Here's what your program would look like: >============================================================== ># Program: Beginners_Popups.py ... "Hello World" for popups >from easygui import * > >print "Begin program" > ># Prepare the basic programmatic messages >strMess1 = "Is this a Test?" >strTitle1 = "Test Query" >strResponse = "You selected " >strTitle2 = "Response:" > >boolVar = boolbox(strMess1, strTitle1, ["Yes", "No"]) > ># Build the appropriate response >if boolVar: > strResponse += "YES" >else: > strResponse += "NO" > >msgbox(strResponse, strTitle2) # button is OK >boolbox(strResponse, strTitle2, ["Close"]) # button is Close >print "End of Program" >-- From ark at acm.org Thu Aug 14 09:14:27 2003 From: ark at acm.org (Andrew Koenig) Date: Thu, 14 Aug 2003 13:14:27 GMT Subject: To all UK Python Users References: <3f3b4ba2$0$244$fa0fcedb@lovejoy.zen.co.uk> Message-ID: > I have noticed that there does not seem to be a Python User Group > anywhere in the UK. ACCU, the Association of C & C++ Users, also has ``interests in Java, C#, and Python.'' They had a substantial Python track at their last conference. See www.accu.org for details. -- Andrew Koenig, ark at acm.org From abelikov72 at hotmail.com Mon Aug 25 22:03:56 2003 From: abelikov72 at hotmail.com (Afanasiy) Date: Tue, 26 Aug 2003 02:03:56 GMT Subject: Advice to a Junior in High School? References: <3F4A9DC7.9060509@nyc.rr.com> Message-ID: On Mon, 25 Aug 2003 23:34:06 GMT, Kenny Tilton wrote: >Howard Nease wrote: >> H What languages do you suggest that I >> study (I'm already studying Python)? > >PS. Common Lisp I'd recommend considering it. I considered it, but I do not like it. I do greatly admire the advocate whose essays prompted me to try though. His essays often express my feelings with such uncanny precision I forced myself to try Lisp again, with much more determination than previously. http://www.paulgraham.com/ I would also recommend not giving much weight to anything from ESR. Others will probably recommend the opposite of what I have. I think you should do a lot of your own exploring. Consider as much as you can, no matter what someone online says for or against it. From mac-gs-bugs-admin at ghostscript.com Wed Aug 20 19:30:13 2003 From: mac-gs-bugs-admin at ghostscript.com (mac-gs-bugs-admin at ghostscript.com) Date: Wed, 20 Aug 2003 16:30:13 -0700 Subject: Auto-response for your message to Message-ID: <20030820233013.27647.12238.Mailman@casper> The mac-gs-bugs list is deprecated; all bug reports relating to Ghostscript on MacOS should be sent to the mac-gs list instead. See http://ghostscript.com/mailman/listinfo/mac-gs/ for information on subscribing. We'll forward your post if it's appropriate, or you can resend yourself. Thanks for the submission. From gregnans at yahoo.PAS.DE.SPAM.fr Sat Aug 30 17:22:10 2003 From: gregnans at yahoo.PAS.DE.SPAM.fr (Gregory Nans) Date: Sat, 30 Aug 2003 23:22:10 +0200 Subject: Need help to tree-ify nested parenthesis... Message-ID: hello, i need some help to 'tree-ify' a string... for example i have strings such as : s = """A(here 's , B(A ) silly test) C(to show D(what kind) of stuff i need))""" and i need to parse them to have a tree representation such as : ["A", [ "here 's" , [ "B", [ 'A ) "silly test' ]], ["C", [ "to show", ["D", [ "what kind" ]], "of stuff i need", ]] ]] notes : "ALLCAPS(something else)" are some kind of tag, "something else" may contain ALLCAPS() and thus be nested or contain others characters. the parenthesis between 'A' and 'silly test' isn't a mistake but a case to handle string is quite well formed = orphan parenthesis will always be surrounded by whitespace - like in 'A ) silly test' or 'A ( silly test' if have started to write a function which give me pos and nested string, but still need help to finish to tree-ify it from there... or maybe there is a more obvious way ? (i think i didn't need to create real finite state automata for this stuff) thanks >>> parse(d) -1 D what kind 42 @ 51 -1 C to show D(what kind) of stuff i need 32 @ 68 -1 B A ) silly test 14 @ 28 -1 A here 's , B(A ) silly test) C(to show D(what kind) of stuff i need) 2 @ 69 -------------------%<------------------ def parse(s): n = len(s) p = re.compile(r'([A-Z_]+\()') pos = [] iterator = p.finditer(s) for match in iterator: pos.append(match.span()) j = 0 pos.reverse() for (start, end) in pos: opened = 0 i = end while i < n - j: if s[i] == '(': opened += 1 if s[i] == ')' and s[i - 1] != ' ': opened -= 1 if opened < 0: print opened, s[start:end-1], s[end:i], "%s @ %s" % (end, i) break i += 1 From mark at diversiform.com Wed Aug 27 20:20:58 2003 From: mark at diversiform.com (mark) Date: Wed, 27 Aug 2003 17:20:58 -0700 Subject: How to force a Pmw ComboBox to update list In-Reply-To: <4378fa6f.0308271519.41095800@posting.google.com> Message-ID: <000e01c36cfa$4170a130$5501a8c0@markxp> Ahh, something I can answer authoritatively (because I do it all the time)! Here's what you want: ComboBoxName._list.setlist(list) Now, if I understand this method correctly, (list) has to be a tuple. Let me know if this isn't the case, but it seems like I'm doing some convoluted things (like converting lists to tuples) to make this work correctly. You didn't mention whether or not you use dropdowns. I am using them, and this is how I update them. If you don't, this may not work for you. HTH, Mark -----Original Message----- From: python-list-admin at python.org [mailto:python-list-admin at python.org] On Behalf Of Marc Sent: Wednesday, August 27, 2003 4:19 PM To: python-list at python.org Subject: How to force a Pmw ComboBox to update list Hi all, I have an application that uses a Pmw ComboBox to display a list that is dynamic. The user has the ability to add and delete items from the list at different points in the program. However, once the list is updated it needs to automatically refresh the ComboBox to reflect the updated list. The only way I have been able to solve the problem so far is to redraw the window (by withdrawing the window and calling the function that creates the window again). I tried to do a 'configure' on the ComboBox, but couldn't get it to work because the list itself was an initialization even. However, I could have been doing that wrong. Is there any way to force the ComboBox to update the list or redraw itself with the new list? Thanks ahead of time, Marc -- http://mail.python.org/mailman/listinfo/python-list From sismex01 at hebmex.com Mon Aug 18 17:48:09 2003 From: sismex01 at hebmex.com (sismex01 at hebmex.com) Date: Mon, 18 Aug 2003 16:48:09 -0500 Subject: What's better about Ruby than Python? Message-ID: [Aahz] > Oh, come on, Brandon is *much* less of a troll than T*m*t*y > R*e. Unlike the R**bot, we do some interesting topics out of > Brandon, they're just written with such antagonism that I'd be > hard-pressed to top them. > Ahh, yes, Mr. Rue... It's been a while since he's dropped by for a visit :-) I think like you Aahz, that people's dumping way to harsh-like on Brandon. And it's strange to me, because normally people's much more polite here than elsewhere; I wonder what's squishing everyone's balls so tight to make them so. :-/ Sad. -gus Advertencia:La informacion contenida en este mensaje es confidencial y restringida, por lo tanto esta destinada unicamente para el uso de la persona arriba indicada, se le notifica que esta prohibida la difusion de este mensaje. Si ha recibido este mensaje por error, o si hay problemas en la transmision, favor de comunicarse con el remitente. Gracias. From jzgoda at gazeta.usun.pl Fri Aug 22 18:39:43 2003 From: jzgoda at gazeta.usun.pl (Jarek Zgoda) Date: Fri, 22 Aug 2003 22:39:43 +0000 (UTC) Subject: wxPython: need return value from wxFrame References: Message-ID: Bob Parnes pisze: > The dialog returns an integer depending upon which button the user > presses to close it. But you can still access the setting in a widget > after the dialog closes. ...until you Destroy() the dialog instance. I came from ObjectPascal and this language teached me that things exist until they are destroyed. ;) -- Jarek Zgoda Registered Linux User #-1 http://www.zgoda.biz/ JID:zgoda at chrome.pl http://zgoda.jogger.pl/ From sjmachin at lexicon.net Mon Aug 4 18:59:06 2003 From: sjmachin at lexicon.net (John Machin) Date: 4 Aug 2003 15:59:06 -0700 Subject: PyChecker work with Python 2.3? References: <3F2C5300.FA223CBA@easystreet.com> <3F2EB773.4895B5DD@easystreet.com> Message-ID: achrist at easystreet.com wrote in message news:<3F2EB773.4895B5DD at easystreet.com>... > > The only change required in my sources is evidently that the csv > module no longer has a parser(); it's a reader(aFile). > Python doesn't break version-to-version compatibility like that. You have to pay lots of money to software vendors to get them to do that to you. No, "the" csv module is new in 2.3. Under 2.2 you had been using "a" 3rd party extension, written by Dave Cole. Same name, similar purpose, different contents. Another case: the 'optik' 3rd party extension was sanctified as 'optparse'. Different name, mostly same contents. Hint: before upgrading to a new Python version, check what extensions you have in your site-packages directory. Read "what's new in Python m.n". Some of the site-packages you may have trialled and abandoned, most will need to be upgraded to be compatible with the new Python version (especially if you are running Windows), and in a few cases (e.g. csv and optik) you may want to switch to a new module, requiring changes to your source. From clarence at netlojix.net Thu Aug 7 19:00:18 2003 From: clarence at netlojix.net (Clarence Gardner) Date: Thu, 07 Aug 2003 16:00:18 -0700 Subject: urllib2 Message-ID: I must not be getting the point of this from the documentation. I want to connect to a URL and see what it redirects to. I built a redirect handler that does nothing much (for testing) and installed it thusly: import urllib2 class R(urllib2.HTTPRedirectHandler): def redirect_request(req,fp,code,msg,hdrs): print "%s, %s, %s, %s, %s" % (req,fp,code,msg,hdrs) raise urllib2.HTTPError o = urllib2.build_opener(R()) urllib2.install_opener(o) f = urllib2.urlopen('http://sony.com/walkmanreg') print f.read()[:200] but instead of printing the message from my redirect handler, it prints out the text of the redirected-to URL. Any help appreciated. clarence at silcom.com From missive at frontiernet.net Tue Aug 19 16:47:35 2003 From: missive at frontiernet.net (Lee Harr) Date: Tue, 19 Aug 2003 20:47:35 GMT Subject: (newbie) Zope... References: <3f423823-cc5c782a-0721-4196-a81d-6fc6d2cf20cb@news.szn.dk> Message-ID: >> i'm looking for a gentle introduction to zope, dealing with >> database connections and sessions handling. > > The Zope Book would probably be a good starting point: > > > *nod* Also, the zope at zope.org mailing list is full of helpful people. From gerrit at nl.linux.org Thu Aug 28 01:55:09 2003 From: gerrit at nl.linux.org (Gerrit Holl) Date: Thu, 28 Aug 2003 07:55:09 +0200 Subject: OT: Celebrity advice (was: Advice to a Junior in High School?) In-Reply-To: <20030827211959.GD30536@thoth.homegain.com> References: <3F4D0D8B.5E5F9488@engcorp.com> <20030827201213.GA4670@nl.linux.org> <20030827211959.GD30536@thoth.homegain.com> Message-ID: <20030828055509.GD2515@nl.linux.org> Geoff Gerrietts wrote: > Quoting Gerrit Holl (gerrit at nl.linux.org): > > Peter Hansen wrote: > > > But if you refuse to go to prison, things get lethal pretty quickly. > > > That's what "ultimately" refers to above. > > > > Well, I don't think they get very lethal, they get painful at most. > > It depends on the case. Several times in recent history, the American > FBI has deployed lethal force when it was insufficiently provoked > (Ruby Ridge, Waco). "Several times in (American) history" is, of course, not the same as "every dicision", "ultimately". Gerrit Holl. -- 46. If he do not receive a fixed rental for his field, but lets it on half or third shares of the harvest, the grain on the field shall be divided proportionately between the tiller and the owner. -- 1780 BC, Hammurabi, Code of Law -- Asperger Syndroom - een persoonlijke benadering: http://people.nl.linux.org/~gerrit/ Het zijn tijden om je zelf met politiek te bemoeien: http://www.sp.nl/ From tjreedy at udel.edu Sun Aug 31 13:58:15 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 31 Aug 2003 13:58:15 -0400 Subject: SF deploys SA, lauds P & BC References: <7x8yp991wr.fsf@ruckus.brouhaha.com> Message-ID: "Paul Rubin" wrote in message news:7x8yp991wr.fsf at ruckus.brouhaha.com... > "Terry Reedy" writes: > > In Friday's occasional newsletter to registerees, SourceForge > > announced that it has deployed SpamAssassin (written in Python) > > Huh? There are some nice Python spam filters, but SpamAssassin is > written in Perl. Whoops, sorry, was thinking of SpamBayes. From lyle at users.sourceforge.net Thu Aug 21 16:12:39 2003 From: lyle at users.sourceforge.net (Lyle Johnson) Date: Thu, 21 Aug 2003 15:12:39 -0500 Subject: tuple to string/list In-Reply-To: <538fc8e.0308211141.4bca8a8d@posting.google.com> References: <538fc8e.0308211141.4bca8a8d@posting.google.com> Message-ID: <3F4527B7.8040208@users.sourceforge.net> WIWA wrote: > I'm a newbie learning to appreciate the strength of Python. I'm > writing an application to look at the access_log of my apache server: > > When I write: > > for i in range(len(month)): > output="Hits for",month[i], ":" , teller[i] > f.write(str(output)) > f.close() > > => this produces a tuple: > ('Hits for', 'Jan', ':', 0)('Hits for', 'Feb', ':', 2)('Hits for', > 'Mar', ':', 3) > > => whereas I would like the following output: > Hits for Jan: 0 > Hits for Feb: 2 > Hits for Mar: 3 > > Any easy way of obtaing this output? f.write( "Hits for %s: %d" % (month[i], teller[i]) ) From robert.will at stud.tu-ilmenau.de Sun Aug 31 11:01:13 2003 From: robert.will at stud.tu-ilmenau.de (Robert Will) Date: 31 Aug 2003 08:01:13 -0700 Subject: Aspect oriented Everything? References: <32cc321c.0308221316.2f5793ac@posting.google.com> <6ee58e07.0308230459.24f53b64@posting.google.com> Message-ID: <213c9b58.0308310701.3815952b@posting.google.com> llothar at web.de (Lothar Scholz) wrote in message news:<6ee58e07.0308230459.24f53b64 at posting.google.com>... > > I'm not sure if this is a the way to go. I've only seen proof of > concept but no real use. But only in the latter case you can see the > problems. > > I don't like it because it breaks encapsulation and splitters the code > over a few files. Maybe that can be solved with new kind of editors > but it is much more easy to result in a big confusion. > > The most important use cases that i've seen so far are: > > - Logging facilities > - Debugging code > - Pre/Postconditions > - Threading synchronization > > 1+2+3 can be embedded in a language. This is already done in Eiffel. > I don't know if i really want to see something as difficult as > "threading synchronization" as an aspect. I see, you watched the trend the closely. Incidentally I have the same opinion, except that I don't consider their dysfunctional examples as proof of concepts. From simon_place at whsmithnet.co.uk Tue Aug 12 13:09:42 2003 From: simon_place at whsmithnet.co.uk (simon place) Date: Tue, 12 Aug 2003 18:09:42 +0100 Subject: Hints about a script that read ftp contents .... In-Reply-To: References: <3f328d06_1@mk-nntp-1.news.uk.worldonline.com> Message-ID: <3f391f59$1_3@mk-nntp-1.news.uk.worldonline.com> isn't that just a rewrite of the built-in walk function? but if you want check ftputil again, it has a isdir() function that calls 'LIST' and interprets the result, this i think is what makes the walk function very slow, since it has to call 'LIST' and make a new socket for the reply, a very large number of times, a walk on my site ( 50 files 5 dirs. ) took several minutes, an idea. a rewrite of walk that does 'CWD' (change working directory) and using the reply code to tell retrospectively if its a directory, might not be a lot more efficient, the current method has the benefit that it gets file size, dates etc., but due the way its coded does a 'LIST' for each file!, for a walk you only need to know if its a directory and you'll have to do a 'CWD' anyway, also you don't generate any new sockets. From Olivier.POYEN at clf-dexia.com Mon Aug 18 07:28:28 2003 From: Olivier.POYEN at clf-dexia.com (POYEN OP Olivier (DCL)) Date: Mon, 18 Aug 2003 13:28:28 +0200 Subject: 3 new slogans Message-ID: <8963D6370B323E4AA3241200F0EAF7318C1055@FCEXVEXM002.dcl.int.dexwired.net> > -----Message d'origine----- > De : smarter_than_you [mailto:davesum99 at yahoo.com] > Envoy? : jeudi 14 ao?t 2003 18:45 > ? : python-list at python.org > Objet : 3 new slogans > Almost quoting some French commercial: "Le Python, c'est bon". ---OPQ -------------- next part -------------- ----------------------------------------------------------------- Ce message est confidentiel ; son contenu ne represente en aucun cas un engagement de la part de Dexia Credit Local ou de Dexia CLF Banque. Toute publication, utilisation ou diffusion, meme partielle, doit etre autorisee prealablement par l'emetteur. Si vous n'etes pas destinataire de ce message, merci d'en avertir immediatement l'expediteur. This message is confidential ; its contents do not constitute a commitment by Dexia Credit Local or Dexia CLF Banque. Any unauthorised disclosure, use or dissemination, either whole or partial, is prohibited. If you are not the intended recipient of the message, please notify the sender immediately. ----------------------------------------------------------------- Consultez notre site internet www.dexia-clf.fr La cle d'une gestion optimisee du secteur public local ----------------------------------------------------------------- From borcis at users.ch Fri Aug 15 07:13:43 2003 From: borcis at users.ch (Borcis) Date: Fri, 15 Aug 2003 13:13:43 +0200 Subject: Eight Queens Puzzle by Magnus Lie Hetland References: <215fa0fc.0308130557.7f1c950b@posting.google.com> <3f3c1007$0$177$a1866201@newsreader.visi.com> Message-ID: <3F3CC067.5010102@users.ch> Grant Edwards wrote: >>BTW, my version got all 92 solutions in < 155ms on a 300mhz P2 without >>attempting to optimize ;-) (just the call to doqueens that is, not including >>import time). > > > Someday I want to modify it to keep a list of solutions and eliminating all > the ones that are mirror images or rotations. This will give you 12 solutions, one of which possesses an internal 2-fold symmetry, so 92 = 11*8 + 1*8/2. From peterm at resmed.com.au Tue Aug 26 16:38:19 2003 From: peterm at resmed.com.au (Peter Milliken) Date: Wed, 27 Aug 2003 06:38:19 +1000 Subject: My future Python IDE article References: <87smno1bfh.fsf@vercingetorix.caesar.org> Message-ID: <%yP2b.284$rC1.12766@nnrp1.ozemail.com.au> "Dialtone" wrote in message news:87smno1bfh.fsf at vercingetorix.caesar.org... > mertz at gnosis.cx (David Mertz) writes: > > > So c.l.py readers... make the case for your favorite one getting on the > > list. I have a while to ponder the opinions advanced, should this > > prompt some discussion (it may take a little while to order review > > copies of commercial tools and/or get things installed). > > This one is easy :). > > My voting goes for: > > 1) Emacs + python-mode + ipython as interactive shell inside emacs + > speedbar as class browser (I use this... actually I use emacs for > everything :)) I use the same Emacs configuration with the addition of ELSE (with the python code templates for easy code input) and PyMacs (for extending Emacs using Python). > > 2) Eric3 > > 3) Eclipse + Trustudio > > 4) Another one randomly > > PS: Under windows my favourite is PythonWin > > -- > Valentino Volonghi, Regia SpA, Milan > > Linux User #310274, Debian Sid Proud User From andrews at pcug.org.au Wed Aug 20 01:40:34 2003 From: andrews at pcug.org.au (Avery Andrews) Date: Wed, 20 Aug 2003 05:40:34 GMT Subject: What's better about Ruby than Python Message-ID: John J Lee wrote: >I mostly agree, but I think you could be accused of spreading FUD >about this. Does anybody *really* choose to alter string-comparison >semantics under everybody else's nose in Ruby?? That would be like >doing > >import some_module > >def evil_replacement_function(): return blah() > >some_module.important_function = evil_replacement_function > > >in Python, wouldn't it? Hmm, Armin Rigo's first major Python project (the Quake engine game map editor QuArK) makes extensive use of this technique, but rigorously folloiwng the convention that evil_replacement_function always calls some_module.important_function and then does more besides, such as add more items to a menu, draw more lines on a map, or whatever. So used, it seems to work well and not cause problems (maybe it's a way of faking aspects of aspect-oriented programming). Avery Andrews From no at more.spam.plea.se Mon Aug 25 10:24:23 2003 From: no at more.spam.plea.se (=?ISO-8859-1?Q?Risto_Per=E4nen?=) Date: Mon, 25 Aug 2003 17:24:23 +0300 Subject: Coloring print lines In-Reply-To: References: Message-ID: Sami Viitanen wrote: > Hello, > > Is there an easy way to make script print text with differents colors to > screen (shell)? > > I mean a script that can for example print lines in red if some error occurs > in executing > some information.. > > --SV > > ----Thanks in advance. > > If you're using python at X, best advice I canv give is Text-widget at Tkinter and RTFM (sorry couldn't resist temptation :) . Otherwise you probably have to fiddle with curses-library (unix-only). Best way to gather information of execution is to open log-file, code couple of monkeys and let them crack system as much as possible. This is only my opinion. Coders are blind to their mistakes even at testing. From jussij at zeusedit.com Sun Aug 31 21:37:33 2003 From: jussij at zeusedit.com (Jussi Jumppanen) Date: Mon, 01 Sep 2003 11:37:33 +1000 Subject: Win32 documentation in CHM? References: Message-ID: <3F52A2DD.16D0@zeusedit.com> Robin Becker wrote: > > In article Tim Peters writes > ..... > > You cannot have used a properly constructed .chm file and seriously > > question whether it's more searchable. Of course it is, including > > seemingly instantaneous Boolean, proximity, wildcard, and similarity > > searches, across the entire doc set with one query. > > amazingly I still disagree, somehow I still prefer the html files. > Perhaps I just hate IE. The CHM search-abilty is definitely a plus, but I am also have my resivations. In fact I think the WinHelp file format was a much better help system. The WinHelp view was much faster loading, less likely to crash and also just as easily searched. The original HtmlHelp viewer was a real step backwards in comparison. Grnated, the newer versions of the HTML viewer are more stable, but they are still very demanding in terms of system memory. Try using the Microsoft MSDN and watch your system grind to a halt :( Even today the Zeus Quick Help keywords searching is still a lot faster if the source of the keyword is a WinHelp file compared to a HtmlHelp file. Jussi Jumppanen Author of: Zeus for Windows (All new version 3.90 out now) "The C/C++, Cobol, Java, HTML, Python, PHP, Perl programmer's editor" Home Page: http://www.zeusedit.com From vanevery at 3DProgrammer.com Mon Aug 18 18:43:24 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Mon, 18 Aug 2003 15:43:24 -0700 Subject: What's better about Ruby than Python? References: Message-ID: sismex01 at hebmex.com wrote: > > I think like you Aahz, that people's dumping way to harsh-like > on Brandon. And it's strange to me, because normally people's > much more polite here than elsewhere; I wonder what's squishing > everyone's balls so tight to make them so. Well, I'll freely own up to being rude and intellectually violent. I don't feel like being "PC" about certain basic questions, I'm a pragmatic programmer and I call a spade a spade. But that doesn't make me a troll. It's annoying when people can't/won't tell the difference. The sheer volume of questions I've asked about Python should indicate to any impartial observer that I actually do care about the answers. And if that isn't sufficiently convincing, you might try checking the marketing-python archives. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From mpeuser at web.de Sun Aug 31 03:37:00 2003 From: mpeuser at web.de (Michael Peuser) Date: Sun, 31 Aug 2003 09:37:00 +0200 Subject: Polymorphism the Python way References: Message-ID: "Daniel Klein" schrieb im Newsbeitrag news:smr2lvop984g1k1q30iidmm0lg8uecolqa at 4ax.com... > Given the following code,,, > > class Dead(object): > def __init__(self, adeadthing): > self.deadthing = adeadthing > > def getthing(self): > return self.deadthing > > class Parrot(object): > def __init__(self, aparrotthing): > self.parrotthing = aparrotthing > > def getthing(self): > return self.parrotthing > > ...and then somewhere in some script I use... > > self.getthing() > > to get whatever 'thing' I want to get. > > Isn't there a better way to do this in Python? I hate doing these > 'get' type methods. The seem ugly to me. I am not sure I understand your problem. What you do is fine (though it is not exactly 'polymorphism'). I assume you mean: instance.getthing() because writing self.getthing() has unclear connotations. Of couzrse you can call your attributes also 'thing' (instead of 'parrotthing' and 'deadthing') and you can use simply instance.thing There are pros and cons. But as I stated I am not quite sure what your problem is in the first place.... Kindly Michael P From vanevery at 3DProgrammer.com Tue Aug 19 00:51:26 2003 From: vanevery at 3DProgrammer.com (Brandon J. Van Every) Date: Mon, 18 Aug 2003 21:51:26 -0700 Subject: Why announce a killfile? (was Re: What's better about Ruby than Python?) References: <38ec68a6.0308172319.431a4fde@posting.google.com> Message-ID: Cliff Wells wrote: > > For instance, do you really think publicly announcing that someone is > in your killfile hurts their feelings or somehow vindicates you? > That's rather pathetic, but makes sense given the source. I'd > venture that mentality is most common at the pre-teen level of social > interaction. You and I have different social theories. My social theory is, people are very stubborn. Nobody will engage in Right behavior the minute you tell them to. But if I killfile people, and tell them why (i.e. "Because you are a Troll Hunter, and such people are useless."), then someday they may wake up and figure it out. It may be 6 months from now, it may be 2 years from now. The point is to have a cumulative effect on people's newsgroup behavior. It also starts to sink in when people realize they've been killfiled for years. People eventually wake up and mellow out. Cliff, you aren't in my killfile. I don't have much problem with what you wrote about me, because you wrote it tentatively, even if you strongly suspected you'd reach certain conclusions. The point is to examine one's perceptions, one's role, before running off and screaming, "So and so's a troll!" There may be other explanations. Generally, it is broadening to put yourself in someone else's shoes. -- Cheers, www.3DProgrammer.com Brandon Van Every Seattle, WA 20% of the world is real. 80% is gobbledygook we make up inside our own heads. From tzot at sil-tec.gr Fri Aug 22 02:50:29 2003 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Fri, 22 Aug 2003 09:50:29 +0300 Subject: Import site References: Message-ID: <57fbkvcrot0v4qgeek5ne4ddb69te915th@4ax.com> On Wed, 20 Aug 2003 13:07:49 -0400, rumours say that "satish k.chimakurthi" might have written: >I am trying to load a module in python. When I said python at the >commandprompt, I got the following and yet I am able to go to the python >prompt > >$ python >'import site' failed; use -v for traceback A slight chance; if you enter the 'env' command at the shell prompt, does it contain a 'PYTHONHOME' environment variable? If yes, unset it. -- TZOTZIOY, I speak England very best, Microsoft Security Alert: the Matrix began as open source. From belred1 at yahoo.com Thu Aug 7 01:18:04 2003 From: belred1 at yahoo.com (Bryan) Date: Thu, 07 Aug 2003 05:18:04 GMT Subject: MSVC 6.0 Unsupported? References: <3F302764.8010301@ghaering.de> Message-ID: "Syver Enstad" wrote in message news:u4r0u7dvr.fsf at online.no... > Gerhard H?ring writes: > > > Syver Enstad wrote: > > > "M.-A. Lemburg" writes: > > > > > >>The best thing to do is to replace this code in Python's object.h > > >>file (Python23\Include\object.h; note the comment !): > > > That's exactly what I did and it worked fine. > > > > Requiring users of my software to patch their Python instalation is > > not an option for me. > > But Gerhard, what can I do? Every python extension that I will try to > compile will fail if it depends on a working staticforward. The most > rational thing to me is to patch object.h instead of patching every > .cpp/.c file that needs this define. > > -- > > Vennlig hilsen > > Syver Enstad syver, i agree, patching object.h is the only rational thing to do... everyone in my company will do the same. i'm using pyrex and everytime i regenerate the c file, i need to repatch the intermediate c file. i got tired of this so i just patched object.h and now i this issue is gone. i'm not sure if there is a better (more convenient) way. it was this way before 2.3 and everything worked just fine, so there shouldn't be any harm doing this in 2.3. i feel it was taken out for political reasons when it should have been left in for technical reasons. after all, the windows verson of python at www.python.org is compiled in msvc. so obviously the python community accepts msvc as an exceptable compiler on windows. care should have been taken to be more accomodating. bryan From jwdillworth at yahoo.com Mon Aug 18 13:16:37 2003 From: jwdillworth at yahoo.com (Jeremy Dillworth) Date: Mon, 18 Aug 2003 10:16:37 -0700 (PDT) Subject: Functions In-Reply-To: Message-ID: <20030818171637.96797.qmail@web41114.mail.yahoo.com> That depends on your view of the "right" f3 :) In a nutshell, f1 is in the global scope. So it's going to search for f3 in the local (f1) scope (which it will never find, since f1 doesn't have its own f3), and then in the global scope. What function you call it from and whether or not that function has a local f3() defined doesn't matter. Here's an interactive session based on your example which demonstrates: Python 2.3 (#1, Aug 12 2003, 15:22:52) [GCC 3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> def f1(): ... f3() ... >>> def f2(): ... def f3(): ... print "f2's f3 called" ... f1() ... >>> def f3(): ... print "global f3 called" ... >>> def f4(): ... def f3(): ... print "f4's f3 called" ... f1() ... >>> f1() global f3 called >>> f2() global f3 called >>> f4() global f3 called >>> --- Thor wrote: > In this hypothetical case: > > def f1: > f3: > def f2: > def f3: > pass > f1: > def f4: > def f3: > pass > f1: > > would the function f1 execute the right f3 depending on from which functions > is it called? > -- > Thor -- Stockholm -- Sverige > -- > http://mail.python.org/mailman/listinfo/python-list From CousinStanley at hotmail.com Mon Aug 11 11:08:10 2003 From: CousinStanley at hotmail.com (Cousin Stanley) Date: Mon, 11 Aug 2003 08:08:10 -0700 Subject: CLI+GUI References: <2259b0e2.0308080948.5a95e383@posting.google.com> <2259b0e2.0308090530.7519f195@posting.google.com> <2259b0e2.0308110517.7c4fa8c8@posting.google.com> Message-ID: | It hangs immediately when I start the script | by clicking on its icon. Michele .... I experience hangs with SIMPLE Python/Tk scripts regularly using Windows 98 and this has been a source of much frustration, almost to the point of giving up on Tk .... Your tk_cli script works for me, displaying the Tk window, accepting display whatEver commands, and displaying the results back in the Tk window .... However, it will hang _sometimes_ at the (Cmd) prompt on the second pass through after displaying the first time as expected .... -- Cousin Stanley Human Being Phoenix, Arizona From mbmulder_remove_this_ at home.nl Sat Aug 2 11:42:08 2003 From: mbmulder_remove_this_ at home.nl (Agent Mulder) Date: Sat, 2 Aug 2003 17:42:08 +0200 Subject: very newbie question Message-ID: Hi group, I wonder if I can do Windows programming in python. I work with c++ now and do the Windows part raw. It's difficult to get my app over 150K (need some heavy inlining, that's all). Does python support nitty-gritty Windows- programming? -X From Aaron.Hawley at uvm.edu Tue Aug 5 11:52:09 2003 From: Aaron.Hawley at uvm.edu (Aaron S. Hawley) Date: Tue, 5 Aug 2003 11:52:09 -0400 Subject: Capture PID of child process In-Reply-To: References: Message-ID: self.pp.tochild.close() ? this doesn't give you the process ID (if that is your purpose), but does appear to kill it (if that is your purpose). /a On Tue, 5 Aug 2003, klappnase wrote: > Hello, everyone, > > I am running python2.2.2 on a linux box. > I want to call a shell command and get the PID of this child process > so I have the possibility to abort the child process while it is still > running. > > I tried the popen2 module for that: > > self.pp = popen2.Popen3(cmd) > cmdpid = self.pp.pid > > However I found that the PID returned by self.pp.pid is not the PID of > the process of interest, but the PID of a subshell in which this child > process is running. > So if I do > > os.kill(cmdpid, 9) > > the subshell is killed, but the process I actually wanted to stop is > happily running on. > > Does anyone have a clue what to do about that? Any help would be very > appreciated. > > Thank you in advance > > Michael From no_replies at fake_email_address.invalid Thu Aug 21 12:47:07 2003 From: no_replies at fake_email_address.invalid (Robert Oschler) Date: Thu, 21 Aug 2003 16:47:07 GMT Subject: Got Python web host, yay! Now what? Message-ID: I found a good web host that has Python 2.x support and I've set up an account. It's LunarPages.com if you're interested . Do I have to do anything special to run Python scripts, besides upload the script to the cgi-bin directory? If so, please direct me to a good web page or doc that goes into the necessary details. thx -- Robert Oschler "Let the web hear you, add your voice to your web site in minutes!" -- http://audiodirect.spiderchase.com/ (For a limited time, free voiceover with every sign-up, use this link instead) -- http://audio.spiderchase.com/ (A song - are you blue?) -- http://bluedreams.spiderchase.com/ From s0199583 at sms.ed.ac.uk Wed Aug 13 09:42:59 2003 From: s0199583 at sms.ed.ac.uk (Matt Smith) Date: 13 Aug 2003 06:42:59 -0700 Subject: COM :: VARIANT -eek References: <5f5c82ec.0308110207.1d42251@posting.google.com> Message-ID: <5f5c82ec.0308130542.6857fe74@posting.google.com> Mark Hammond wrote in message news:... > Matt Smith wrote: > > Hi, all. > > > > Just a quick question, when setting a COM process to read a value from > > a pre-defined register index, I think, I have to change the variable > > that the value will be returned to (as I have to do for the same > > function in perl), into a VARIANT, However when i run the variant > > code.... > > > > 'serialIndex = win32com.client.pythoncom.VT_VARIANT' > > > > no matter what extension I use (i.e. VT_I4 or VT_BOOL etc etc) it > > still returns a type mismatch error. I may be doing something wrong or > > getting confused with variant processes in python. I do know the code > > I use in perl to do this works but I dont know how to translate this, > > fully, into python. > > > > perl code for variant = > > Win32::OLE::Variant::Variant(Win32::OLE::Variant::VT_VARIANT|Win32::OLE::VARIANT::VT_BYREF, > > 0) > > Unfortunately, you really can't do this in a clean way. The best thing > to do is to ensure "makepy" has been run for your COM object, and the > right magic should always happen. > > Mark. Hi, thanks for the reply, My problem is now this, when i go to makepy tool in pythonwin, it does not see/recognise the type library file I want it to convert. Is there anyway to add the file to the list of .tlb files it does does? Cheers, Matt. p.s. How do I include the generated makepy file into my code ? From gerrit at nl.linux.org Tue Aug 26 14:18:45 2003 From: gerrit at nl.linux.org (Gerrit Holl) Date: Tue, 26 Aug 2003 20:18:45 +0200 Subject: Advice to a Junior in High School? In-Reply-To: References: Message-ID: <20030826181845.GA14419@nl.linux.org> Terry Reedy wrote: > "Howard Nease" wrote in message > news:Ivw2b.1305$Ce2.314 at clmboh1-nws5.columbus.rr.com... > > have heard a whole lot about the fact that the market for software > engineers > > nowadays is *HORRIBLE*, and that I should double major or perhaps go > into a > > field of study in which I'm not very interested. > > The demand for software engineers has fluctuated up and down, in > various industries and regions, for decades. An article in the > current Business 2.0 on the 'coming labor shortage' points out that > you are part of the first generation in America to be numerically > smaller than your parents generation. In ten years, when boomers have > or are retiring, there will probably be a relatively shortage of tech > workers. Note that this is true for (almost) all western countries. In Dutch it's called "vergrijzing". regards, Gerrit, who happens to study a field with an extreme shortage of engineers/scientists (applied physics), which will be only worse/better in 5 years... (The Netherlands) -- 271. If any one hire oxen, cart and driver, he shall pay one hundred and eighty ka of corn per day. -- 1780 BC, Hammurabi, Code of Law -- Asperger Syndroom - een persoonlijke benadering: http://people.nl.linux.org/~gerrit/ Het zijn tijden om je zelf met politiek te bemoeien: http://www.sp.nl/ From ghowland at lupineNO.SPAMgames.com Sat Aug 23 21:50:01 2003 From: ghowland at lupineNO.SPAMgames.com (Geoff Howland) Date: Sun, 24 Aug 2003 01:50:01 GMT Subject: Modifying the {} and [] tokens References: <04cekv0s6ghjtuhl5j2gph7ltobdb5rsam@4ax.com> <62rekv0k4ucgrh46lkp27klq13pq8ppp5p@4ax.com> <1h3fkvg8mkeq69a8hriojugqfcp75hafjj@4ax.com> Message-ID: On Sat, 23 Aug 2003 19:46:42 -0400, "Terry Reedy" wrote: >An excellent idea (which I generally try to practice myself). It's a work in progress on my side. :) >As for the Ruby suggestion: It is precisely because we are generally >pragmatists and not everyone-should-always-program-in-Python fanatics >that someone occasionally suggests that a particular person might >(repeat, might) find another language more suitable. The canonical >example is people distressed by naked code unwrapped by redundant >braces. If they can't adjust and won't use 'weaning' braces ('#{' and >'#}'), then they should use a language that better fits their mindset. Agreed. >As for 'reasonable' idea rejection: There is effectively no limit to >what people can collectively think up, and as the community expands, >the number and breadth of ideas also expands. One of Guido's main >jobs now is to reject most ideas for 'improvement', no matter how >'reasonable' in isolation. If your particular wish should remain >ungranted a year from now, welcome to the club. I'm glad that he is limiting things. Perhaps my plan would not have worked out well anyway, but I was interested in giving it a shot. Since it's not possible, I'll think up some other less hacky slightly more verbose way to handle the issues. -Geoff Howland http://ludumdare.com/ From mpeuser at web.de Sat Aug 23 06:30:48 2003 From: mpeuser at web.de (Michael Peuser) Date: Sat, 23 Aug 2003 12:30:48 +0200 Subject: Reference? References: Message-ID: "Kris Caselden" schrieb im Newsbeitrag news:abc3fdd3.0308230057.6b309abd at posting.google.com... > I've searched all the Python docs I could find, but I haven't seen any > mention of referencing function arguments, such as you would with the > & in c/c++. Is this possible in Python? Your question is probably not as sophisticated: Parameter passing in Python is *always* like & in C++. There had been an exaustive disyussion some weeks ago: here is my contribution: Sent: Wednesday, August 13, 2003 9:12 AM Subject: Re: two quick questions > The following examples might clear the more theoretical elaborations ..... > > > def noUse(a): > a=(4,5,6) > > def tricky(a): > a[0]=(7,8,9) > > # case 1 > x=[1,2,3] > print x > tricky(x) > > x=(1,2,3) > # case 2 > noUse(x) > print x > > # case 3 > tricky([x]) > print x > > # case 4 > y=[x] > tricky (y) > print x > print y[0] > > # case 5 > tricky(x) > print x > > > Kindly > Michael Peuser From mis6 at pitt.edu Sat Aug 23 11:37:44 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 23 Aug 2003 08:37:44 -0700 Subject: Python is darn fast (was: How fast is Python) Message-ID: <2259b0e2.0308230737.8a9bc1c@posting.google.com> I posted this few weeks ago (remember the C Sharp thread?) but it went unnoticed on the large mass of posts, so let me retry. Here I get Python+ Psyco twice as fast as optimized C, so I would like to now if something is wrong on my old laptop and if anybody can reproduce my results. Here are I my numbers for calling the error function a million times (Python 2.3, Psyco 1.0, Red Hat Linux 7.3, Pentium II 366 MHz): $ time p23 erf.py real 0m0.614s user 0m0.551s sys 0m0.029s This is twice as fast as optimized C: $ gcc erf.c -lm -o3 $ time ./a.out real 0m1.125s user 0m1.086s sys 0m0.006s Here is the situation for pure Python $time p23 erf.jy real 0m25.761s user 0m25.012s sys 0m0.049s and, just for fun, here is Jython performance: $ time jython erf.jy real 0m42.979s user 0m41.430s sys 0m0.361s The source code follows (copied from Alex Martelli's post): ---------------------------------------------------------------------- $ cat erf.py import math import psyco psyco.full() def erfc(x): exp = math.exp p = 0.3275911 a1 = 0.254829592 a2 = -0.284496736 a3 = 1.421413741 a4 = -1.453152027 a5 = 1.061405429 t = 1.0 / (1.0 + p*x) erfcx = ( (a1 + (a2 + (a3 + (a4 + a5*t)*t)*t)*t)*t ) * exp(-x*x) return erfcx def main(): erg = 0.0 for i in xrange(1000000): erg += erfc(0.456) if __name__ == '__main__': main() -------------------------------------------------------------------------- # python/jython version = same without "import psyco; psyco.full()" -------------------------------------------------------------------------- $cat erf.c #include #include double erfc( double x ) { double p, a1, a2, a3, a4, a5; double t, erfcx; p = 0.3275911; a1 = 0.254829592; a2 = -0.284496736; a3 = 1.421413741; a4 = -1.453152027; a5 = 1.061405429; t = 1.0 / (1.0 + p*x); erfcx = ( (a1 + (a2 + (a3 + (a4 + a5*t)*t)*t)*t)*t ) * exp(-x*x); return erfcx; } int main() { double erg=0.0; int i; for(i=0; i<1000000; i++) { erg = erg + erfc(0.456); } return 0; } Michele Simionato, Ph. D. MicheleSimionato at libero.it http://www.phyast.pitt.edu/~micheles --- Currently looking for a job --- From kelly_carey at wvmccd.cc.ca.us Wed Aug 20 15:33:43 2003 From: kelly_carey at wvmccd.cc.ca.us (kelly_carey at wvmccd.cc.ca.us) Date: 20 Aug 2003 12:33:43 -0700 Subject: [Auto-Reply] Re: Details Message-ID: <20030820193343.9305.qmail@wvmccd.cc.ca.us> Hi. Until August 22 I'm picking up email once a day, occasionally once every other day when traveling. Thanks, Kelly From abelikov72 at hotmail.com Mon Aug 25 14:14:30 2003 From: abelikov72 at hotmail.com (Afanasiy) Date: Mon, 25 Aug 2003 18:14:30 GMT Subject: python gripes survey References: Message-ID: <78kkkvg8ckfio141es2of1p483ohbtbit5@4ax.com> On Sat, 23 Aug 2003 15:39:27 GMT, "Ryan Lowe" wrote: >python is a big improvement on most languages that came before it, but no >language is perfect. id like to make a list of some of the aspects people >find most annoying, regardless of their feasibility of implementation. for >instance, i discussed putting if clauses in for loops, and i noticed another >thread about allowing {} and [] to be added and subtracted. if its something >from another language (especially an obscure one), please explain how it >works in case people like myself dont know the language. > >thanks, >ryan > I have a bunch, many of them hard to define, but one that I just thought of I find strange sometimes is the use of tuples as near-mystery return values. I can't help but thinking a C struct with named fields is easier to remember than a tuple with fields accessed by integer. Sure you can return an associative array, but in my experience the preference is to return a tuple. I'll probably get flamed for saying so, but this is how I feel and it is unavoidable. Returning a struct in C is easier to deal with than returning a near-mystery tuple in Python. From gumuz at looze.net Mon Aug 11 04:41:11 2003 From: gumuz at looze.net (Guyon Morée) Date: Mon, 11 Aug 2003 10:41:11 +0200 Subject: python for .NET (question/idea) Message-ID: <3f3755be$0$8308$4d4ebb8e@news.nl.uu.net> I was looking at the python for .NET stuff mentioned in a previous thread. I downloaded the package and to my suprise there was also a demo-app included which used the .NET 'Forms' module. I thought it was cool to be able to use the .NET gui library, which is quite clean and powerful in my opinion. I know it is probably 'windows-only' and the.NET runtime is required, but what could be other drawbacks on using the .NET framework for gui's? guyon From FBatista at uniFON.com.ar Thu Aug 7 15:07:12 2003 From: FBatista at uniFON.com.ar (Batista, Facundo) Date: Thu, 7 Aug 2003 16:07:12 -0300 Subject: Select one option from list Message-ID: #- Example: list = ['aaa', 'bbb', 'ccc'] #- #- Script acts something like this: #- #- Select one option: #- [1] aaa #- [2] bbb #- [3] ccc #- Enter your selection: Nop. But I implemented the same using dictionarys, it has the advantage that you can use anything as options: options = {'1':'First', '2':'Second', 'Q':'Quit'} print 'Select one option' items = options.items() items.sort() for item in items: print '[%s] %s' % (item) chosen = '' while not options.has_key(chosen): chosen = raw_input('Enter your selection: ') print 'You choose: ', options[chosen] Hope it helps. . Facundo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ADVERTENCIA La informaci?n contenida en este mensaje y cualquier archivo anexo al mismo, son para uso exclusivo del destinatario y pueden contener informaci?n confidencial o propietaria, cuya divulgaci?n es sancionada por la ley. Si Ud. No es uno de los destinatarios consignados o la persona responsable de hacer llegar este mensaje a los destinatarios consignados, no est? autorizado a divulgar, copiar, distribuir o retener informaci?n (o parte de ella) contenida en este mensaje. Por favor notif?quenos respondiendo al remitente, borre el mensaje original y borre las copias (impresas o grabadas en cualquier medio magn?tico) que pueda haber realizado del mismo. Todas las opiniones contenidas en este mail son propias del autor del mensaje y no necesariamente coinciden con las de Telef?nica Comunicaciones Personales S.A. o alguna empresa asociada. Los mensajes electr?nicos pueden ser alterados, motivo por el cual Telef?nica Comunicaciones Personales S.A. no aceptar? ninguna obligaci?n cualquiera sea el resultante de este mensaje. Muchas Gracias. -------------- next part -------------- An HTML attachment was scrubbed... URL: From mehdi.lavasani at connectinternetsolutions.com Wed Aug 27 11:03:14 2003 From: mehdi.lavasani at connectinternetsolutions.com (M. Lavasani) Date: Wed, 27 Aug 2003 16:03:14 +0100 (BST) Subject: ImportError: No module named math Message-ID: <200308271503.h7RF3EI27770@quioch.cis> Hi I am trying to test Python-2.3. Any solution for this problem please: >>>gmake test case $MAKEFLAGS in \ *-s*) LD_LIBRARY_PATH=/net/ia64/lavasani/Python-2.3:/usr/local/lib/hpux32:/usr/local/lib CC='gcc' LDSHARED='gcc -shared' OPT='-DNDEBUG -g -O3 -Wall -Wstrict-prototypes' ./python -E ./setup.py -q build;; \ *) LD_LIBRARY_PATH=/net/ia64/lavasani/Python-2.3:/usr/local/lib/hpux32:/usr/local/lib CC='gcc' LDSHARED='gcc -shared' OPT='-DNDEBUG -g -O3 -Wall -Wstrict-prototypes' ./python -E ./setup.py build;; \ esac running build running build_ext running build_scripts find ./Lib -name '*.py[co]' -print | xargs rm -f LD_LIBRARY_PATH=/net/ia64/lavasani/Python-2.3:/usr/local/lib/hpux32:/usr/local/lib ./python -E -tt ./Lib/test/regrtest.py -l Traceback (most recent call last): File "./Lib/test/regrtest.py", line 75, in ? import random File "/net/ia64/lavasani/Python-2.3/Lib/random.py", line 42, in ? from math import log as _log, exp as _exp, pi as _pi, e as _e ImportError: No module named math gmake: [test] Error 1 (ignored) LD_LIBRARY_PATH=/net/ia64/lavasani/Python-2.3:/usr/local/lib/hpux32:/usr/local/lib ./python -E -tt ./Lib/test/regrtest.py -l Traceback (most recent call last): File "./Lib/test/regrtest.py", line 75, in ? import random File "/net/ia64/lavasani/Python-2.3/Lib/random.py", line 42, in ? from math import log as _log, exp as _exp, pi as _pi, e as _e ImportError: No module named math gmake: *** [test] Error 1 But I can see the math module >>>find . -name \*math* ./Doc/lib/libcmath.tex ./Doc/lib/libmath.tex ./Lib/test/output/test_math ./Lib/test/test_cmath.py ./Lib/test/test_math.py ./Modules/cmathmodule.c ./Modules/mathmodule.c ./build/temp.hp-ux-B.11.22-ia64-2.3/cmathmodule.o ./build/temp.hp-ux-B.11.22-ia64-2.3/mathmodule.o ./build/lib.hp-ux-B.11.22-ia64-2.3/cmath.so ./build/lib.hp-ux-B.11.22-ia64-2.3/math.so From armin_wittfoth at yahoo.com.au Thu Aug 14 01:07:48 2003 From: armin_wittfoth at yahoo.com.au (Armin Wittfoth) Date: 13 Aug 2003 22:07:48 -0700 Subject: "drop-in" DOM replacement for minidom? References: Message-ID: Harry George wrote in message news:... > Paul Miller writes: > > Switching to > SAX was a major improvement in mem usage and thus in parse time. > As an alternative you can easily build a custom, lightweight, Object Model. I'm using one designed naively to reflect the set of elements used in the several XML schemas we use. I use SAX to parse the document into our object model and have the convenience of programming with the nicer (in some ways DOM like) interface. Basically there is a class Element which (since 2.2) is a child of list. By convention it can contain either a unicode string (CDATA) or another element. The XML attributes can be either stored as a dictionary or, as I eventually did, directly as attributes of the class. Record the parent element (aka location), add some methods such as nextSibling() etc and you're on your way. In our case I've adopted a naive approach, ie there is a separate class for every type of XML element (which all ultimately derive from Element). This suffers from being non-general (ie specific, to the specific set of schema we use), but it has the advantage that you don't have to look up what kind of Element you are dealing with and determine what to do with it, but can use polymorphism nicely. Further there is no conceptual difference between a chunk of XML, and the python object structure (ie Elements within Elements) used to represent it. It was because Python was so ideally suited to this kind of thing, that I originally adopted it. As an aside I wrote an XLST sheet, which reads the various xml-schema files (I only write DTDs myself, relying on converters to generate xsd), and writes out the python stub code, (ie creates the basic class definition for each element adding the appropriate attributes etc), saving a lot of boring boilerplate typing and allows for quick and accurate code updates if new attributes are added to the schema. Going about it in this kind of way, you get something of much lighter weight than DOM, but which does have that nice structural (as opposed to SAX's event-driven) way of working with XML. From aleax at aleax.it Sun Aug 31 09:19:17 2003 From: aleax at aleax.it (Alex Martelli) Date: Sun, 31 Aug 2003 13:19:17 GMT Subject: list as paremeters... References: <3f51ce6e$0$26843$626a54ce@news.free.fr> Message-ID: Ulrich Petri wrote: ... > IIRC Default values are not created each time the function called but > rather only the first time (am i correct here?). And since a list is Almost, but not quite: they're created when the function is DEFINED, *not* the first time it's called. For example: >>> x=3 >>> def f(d=x*'u'): return d ... >>> x=8 >>> print f() uuu The fact that global variable x is worth 8 by the time f is first called is irrelevant: what governs is that x was worth 3 when the def statement was executed -- THAT instant is the one in which the default value of d is termined and stored in the function-object f... at creation time for the function-object f, i.e. execution time for the def statement. > mutable it "rememberes" the previous value. Yes, this is correct: if the default value of an argument is mutable, it "remembers" whatever mutations you choose to perform on it. Alex From tug at wilson.co.uk Mon Aug 18 15:25:57 2003 From: tug at wilson.co.uk (John Wilson) Date: Mon, 18 Aug 2003 20:25:57 +0100 Subject: What's better about Ruby than Python? References: <3F4040F8.87901505@alcyone.com> Message-ID: <34fa01c365be$8d344330$650a0b0a@handel> Alex Martelli wrote: > Me, I think immutable strings are > an excellent idea (and I'm not surprised that Java, independently > I think, reinvented that idea which was already in Python), Gosling claims that Java contains no new ideas. I have heard him say that every feature of Java is in at least two other programming languages. Java takes many things from CLU (including immutable strings). CLU looks to be an influence on Python too. John Wilson The Wilson Partnership http://www.wilson.co.uk From SquatLittleElvis_spammenot at netscape.net Wed Aug 27 11:42:03 2003 From: SquatLittleElvis_spammenot at netscape.net (John Paquin) Date: Wed, 27 Aug 2003 15:42:03 GMT Subject: Fatal Python error with Py_InitModule (Python 2.3) In-Reply-To: References: Message-ID: <11e221c5c0fc422b2c8be13df951fcc2@news.teranews.com> this problem is almost certainly because the headers you compiled with do not match the dll that's getting loaded. My advice to you is to download the source tar, unzip it, build it (from dist\pcbuild) and use that dll and those header files. Then you'll know that everything matches. Andrew Ellem wrote: > I'm using Python embedded in my app, and I've run into problems creating > my own > modules. I'm using Python version 2.3 compiled with MSVC .NET (not 2003). > > When I call Py_InitModule I get the message: > "Fatal Python error: Interpreter not initialized (version mismatch?)" > > However, Python does seem to be initialized. Py_IsInitialized() returns > 1, and I > can PyImport_Import() and I can run scripts successfully from my program. > > I'm not sure what I could be doing wrong, all the information I've found > online > indicates that the above message comes from incompatible version (not > using a > debug version, etc), but I don't see how that would be the problem in my > case, > since I can run normal scripts. > > Does anyone have an idea what might be the problem? > > Thanks. > > _________________________________________________________________ > Protect your PC - get McAfee.com VirusScan Online > http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963 > > From mikael.lexen at spam.no.volvo.com Wed Aug 20 02:44:35 2003 From: mikael.lexen at spam.no.volvo.com (=?ISO-8859-1?Q?Mikael_Lex=E9n?=) Date: Wed, 20 Aug 2003 08:44:35 +0200 Subject: Python had joined the forces Message-ID: <3F4318D3.7000705@spam.no.volvo.com> According to this link Python had joined the open source forces. http://www.atai.org/softwarewar.png /Mikael From nplejic at nospam.programiranje.nospam.net Sat Aug 2 14:42:51 2003 From: nplejic at nospam.programiranje.nospam.net (Nikola Plejic) Date: Sat, 2 Aug 2003 20:42:51 +0200 Subject: very newbie question References: Message-ID: "Agent Mulder" wrote in message news:bgglpl$v4r$1 at news2.tilbu1.nb.home.nl... > Hi group, > > I wonder if I can do Windows programming > in python. I work with c++ now and do the > Windows part raw. It's difficult to get my app > over 150K (need some heavy inlining, that's all). > Does python support nitty-gritty Windows- > programming? > > -X > Hello. Sure, you can try Mark Hammond's win32 extensions: http://starship.python.net/crew/mhammond/ And you can try wxPython (or PyQt, Tcl/Tk and similar) for creating GUI applications: http://www.wxpython.org Hope this helps, Nikola From glingl at aon.at Sat Aug 16 15:34:44 2003 From: glingl at aon.at (Gregor Lingl) Date: Sat, 16 Aug 2003 21:34:44 +0200 Subject: How to terminate a TkinterApp correctly? In-Reply-To: References: <3F3DFCF4.5020109@aon.at> <3f3e37c6$0$19888$91cee783@newsreader01.highway.telekom.at> Message-ID: <3F3E8754.5090301@aon.at> Michael Peuser schrieb: > "John Roth" schrieb im Newsbeitrag ... >>>Why don't you just return? The mainloop can handle everything!? >> >>Unfortunately, ... >>I don't know that it's ever been solved, but considering that >>Windows 9x is gradually going away, it's also not a real hot >>priority. > > > > This was not my point I think.... I was not referring to tk/system mainloop > but to your own loop you mentioned. The above answer was not mine, so there is samething a bit mangled ... This is where you set "done=1" for... > The after_idle is confusing and probably not what you want. But it worked! I have the > impression that there is still some misunderstanding. Maybe! > It is absolutly fine to intercept the user click to the close box - there is > no magic it and - as to my example - you can do what you want for hours > after. Note: the "closing" process is stopped, when you use this WM-.... > trick. (Because I was not *quite* sure about the internal states, I also > recommende to use WM_SAVE_YOURSELF instead). > > But I think it is not worth all the work - and still unsafe! - WHY? to just call > sys.exit() !!! So I found another working solution to my problem: I put the code for the go-function, which is the command of a goButton in a try:- except: clause. def go(): global done try: resetGame() goButton["state"] = Tk.DISABLED while fehler < MAXFEHLER and not done: for huhn in huehner: huhn.move() cv.update() done = True goButton["state"] = Tk.NORMAL except: pass This catches the TclError and everything terminates regularly Regards, Gregor > Kindly Michasel P > > > >>John Roth >> >> >> > > > From ialbert at mailblocks.com Fri Aug 15 22:03:58 2003 From: ialbert at mailblocks.com (Istvan Albert) Date: Fri, 15 Aug 2003 22:03:58 -0400 Subject: Dictionary assignment In-Reply-To: References: Message-ID: Mark Daley wrote: > format[self.formats.get()][key] = current[key] > > Now, all disgust from my example aside, shouldn't this line cause a new key > (whatever self.formats get() produces) whose contents are an exact copy of > current? First you need to assure that format[self.formats.get()] contains another dictionary as a value. Here is an example: >>>> a = {} >>>> a[1] = {} >>>> a[1][2] = 1 works as expected but >>>> a[2][3] = 4 will fail with KeyError:2 because this construct attempts to fetch the value corresponding to key 2 and then add to that dictionary the 3/4 key/value pair. It is indeed confusing, I never thought about it and caught me by surprise that it is KeyError:2 that is being thrown. As one parses the expression from left to right it reads as if the assignment to key 2 comes first and only then does the assignment to key 3 become "active". The error message one expects is that a[2] does not support assigment. Istvan. From vze4rx4y at verizon.net Fri Aug 1 19:36:09 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Fri, 01 Aug 2003 23:36:09 GMT Subject: a question on the new dict() keyword argument syntax References: <722261f9.0308011501.48263391@posting.google.com> Message-ID: "Oktay Safak" wrote in message news:722261f9.0308011501.48263391 at posting.google.com... > Hi, > > Is there an equivalent keyword argument syntax for these cases: > > d1 = {1:"one"} > > d2 = {"1":"one"} > > these don't work, of course: > > >>> a = dict(1 = "one") > SyntaxError: keyword can't be an expression > > >>> a = dict("1" = "one") > SyntaxError: keyword can't be an expression As you discovered, there is no equivalent. The new syntax is limited to strings that are valid identifiers (variable names). Raymond Hettinger From ywsat at yahoo.com Thu Aug 14 13:49:42 2003 From: ywsat at yahoo.com (ywsat) Date: 14 Aug 2003 10:49:42 -0700 Subject: PythonWin hangs when Shift-F5 (stop debug) Message-ID: Has anyone experienced the problem where PythonWin debugger hangs you stop the debug session? I'm running Windows 2000. Python 2.3. I have to kill it through the task manager each time. Thanks From skip at pobox.com Mon Aug 11 15:55:01 2003 From: skip at pobox.com (Skip Montanaro) Date: Mon, 11 Aug 2003 14:55:01 -0500 Subject: ascii problem In-Reply-To: <004e01c3603f$df580680$417290c8@paraopeba> References: <002a01c3603b$73442a90$417290c8@paraopeba> <16183.60555.59705.762835@montanaro.dyndns.org> <004e01c3603f$df580680$417290c8@paraopeba> Message-ID: <16183.62613.392075.525471@montanaro.dyndns.org> Mauricio> Why didn?t I have problems like this on Win98 and now I have Mauricio> it on Windows 2000? Its the same python (2.2) In my scripts, Mauricio> will I always have to do this process to add strings with Mauricio> portuguese acentuation? Dunno. I'm not a Windows person. Maybe the default encoding changed. Check your site.py file (probably in c:\Python22\site.py). Read the code which begins "# On Windows, some default encodings..." carefully. Skip Mauricio> thanks, Mauricio> Mauricio Mauricio> ----- Original Message ----- Mauricio> From: "Skip Montanaro" Mauricio> To: "Mauricio Infor?ati" Mauricio> Cc: Mauricio> Sent: Monday, August 11, 2003 4:20 PM Mauricio> Subject: Re: ascii problem >> >> >>> a = "andr?" >> UnicodeError: ASCII encoding error: ordinal not in range(128) >> >> Use Unicode: >> >> >>> a = unicode("andr\xe9", "iso-8859-1") >> >>> print a.encode("iso-8859-1") >> andr? >> >> With a Euro keyboard you won't have to embed hex codes in your strings. >> >> Skip >> >> From rnd at onego.ru Thu Aug 7 00:10:12 2003 From: rnd at onego.ru (Roman Suzi) Date: Thu, 7 Aug 2003 08:10:12 +0400 (MSD) Subject: Adding PC Filename Extensions to Macintosh Filenames In-Reply-To: <3F319D1C.2020701@vt.edu> Message-ID: On Wed, 6 Aug 2003, hokiegal99 wrote: >Roman Suzi wrote: >> Second, Linux has 'file' command which tells you file type based on >> content and knows tonns of formats. > >How would I use this from within Python to more accurately identify a file? Run "file" from Python with os.popen for example and analize results. At first try to file * from a command line to see what it tells about files. Sincerely yours, Roman Suzi -- rnd at onego.ru =\= My AI powered by GNU/Linux RedHat 7.3 From tom_chansky at rocketmail.com Wed Aug 13 09:57:26 2003 From: tom_chansky at rocketmail.com (chansky) Date: 13 Aug 2003 06:57:26 -0700 Subject: Eight Queens Puzzle by Magnus Lie Hetland Message-ID: <215fa0fc.0308130557.7f1c950b@posting.google.com> I've been reading Magnus Lie Hetland's book, Practical Python. In one of the chapters he discusses how to use a Generator function to solve the Eight Queens puzzle. The following is part of his codes: #This function checks if the next Queen would cause any conflict with the #previous one. def conflict(state, nextX): nextY=len(state) for i in range(nextY): if abs(state[i]-nextX) in (0,nextY-i): return 1 return 0 def queens(num,state): if len(state)==num-1: for pos in range(num): if not conflict(state,pos): yield pos I've a hard time to understand the following statement: if abs(state[i]-nextX) in (0,nextY-i): The author said that this statement will be True if the horizontal difference b/w the next queen and the previous one under consideration is euqal to zero or equal to the vertical distance (diagonally), and false otherwise. Well, maybe I'm really slow. What does that "vertical distance" really mean? If someone out there has read his book, can you help me understand that line of code. From mark at diversiform.com Tue Aug 5 20:18:33 2003 From: mark at diversiform.com (Mark Daley) Date: Tue, 5 Aug 2003 17:18:33 -0700 Subject: Question about import In-Reply-To: Message-ID: The only exception I would consider to this would be Tkinter. It seems like every last book on this always has the user import from Tkinter, not just import Tkinter itself. Is this just by convention, or is there a perfectly good explanation for this? - Mark -----Original Message----- From: python-list-admin at python.org [mailto:python-list-admin at python.org]On Behalf Of Alex Martelli Sent: Tuesday, August 05, 2003 11:28 AM To: python-list at python.org Subject: RE: Question about import Mark Daley wrote: > The difference is how you access the methods in the module. If you use: > > import Module > > you will only be able to use the Module.Method usage. If you use: > > from Module import * > > you can access the Methods directly. > > > The drawback to using from Module import * comes from conflicts if you > import multiple Modules, which may have identically named Methods, where > you will only be able to get the Method from the most recently imported > Module. Better to import the Module, IMO. > > Any thoughts, all? There are also other drawbacks to using the 'from' statement rather than the 'import' statement. For example, if you ever reload() the module, this will have no effect in other modules that used 'from', while it will cause usage of the updated (reloaded) module in other modules that used 'import'. Personally, I think a beginner would be best served by totally forgetting the existence of 'from' and using only 'import' instead -- perhaps 'import ... as' if the need to abbreviate the name used to refer to the module is strongly felt. Alex -- http://mail.python.org/mailman/listinfo/python-list From iajava at yahoo.com Mon Aug 25 02:08:44 2003 From: iajava at yahoo.com (Molly) Date: 24 Aug 2003 23:08:44 -0700 Subject: BaseHTTPServer fails POST requests: disconnected by peer; maybe sockets bug? help!? Message-ID: <3127854d.0308242208.33d1806d@posting.google.com> Peace, Pythonphiles! Python's std lib BaseHTTPServer: I'm stuck with a nasty spoiler -- I get erratic "Network error: disconnected by peer" for _POST_ requests only. =Background= I'm developing a Python CGI app. Was using Xitami, which is really light and nice, reasonable performance (circa 200-300 msec to respond, I guess mostly to start a Python process; localhost; win95 (retch!)). But, deployed site is the usual Apache/Linux monstrosity. And I wanted to use mod_rewrite, to export nice URLs. Xitami is inflexible about URL associations with scripts. So I tried hacking a python22/libs/SimpleHTTPServer to "simulate" Apache's mod_rewrite. It's unbelievable easy! =The problem= GET requests work fantastically! 40-100 millisecs to render response in HTML -- I was really surprised! But POST requests fail: the script runs ok, response fully generated and written to stdout, but somewhere while rendering Netscape aborts with that "Network error: lost connection, disconnected by peer". This is erratic: sometimes not a character was displayed before it disconnects, and sometimes the entire page _except the last line_. These tools are of course buggy as hell, and I learned to "live" with their limitations during the years, but this one really gets me down: I want to use Python's *HTTPServer to experiment with FCGI and a standalone, dedicated Web server for this application, and the performance was so nice, and _I haven't a clue as to why this strange behavior occurs_! Help!!! =Details= Invoking script: sys.stdout = self.wfile sys.stdin = self.rfile execfile( "my_cgi.py", {} ) with both in/out set to _no buffering_: rbufsize = 0 wbufsize = 0 (Actually, more like sys.stdout = cgi_output = StringIO.StringIO() #... self.send_response( status ) self.wfile.write( cgi_output.getvalue() ) so can (keep a log and) scan the script's output for a "Status:" header, aka "parsed-headers CGI" -- I'm simulating Apache, right?) I tried pausing just before exiting the request handling call: time.sleep( 25 ) # Trying to get smart with bug? and it _sometimes_ helps! ie, Netscape renders the page, then gives up on waiting for the connection to close, I guess, so... there. But, unreliable. =Guess?= I've no idea where to look -- what's different between a GET and POST?! It's probably some Micrapsoft buffoonery with sockets. I really like to patch this somehow. Any suggestions about how to find the exact point of failure? Thanks! -- M From alan_salmoni at yahoo.com Wed Aug 20 06:15:59 2003 From: alan_salmoni at yahoo.com (Alan James Salmoni) Date: 20 Aug 2003 03:15:59 -0700 Subject: wxPython launches DOS shell References: <4150f6c8.0308190748.7633e5c9@posting.google.com> Message-ID: Like the other posters say: use pythonw.exe. The best way to autolaunch this is change the python file name from ".py" to ".pyw", so "script.py" becomes "script.pyw". This means that a console window (DOS box) isn't created. Of course, this doesn't work on any other OS... ;) Alan James Salmoni SalStat Statistics http://salstat.sunsite.dk matthew.rapoport at accenture.com (Matt Rapoport) wrote in message news:<4150f6c8.0308190748.7633e5c9 at posting.google.com>... > Does anyone know how to avoid getting a DOS shell launched everytime > you run a wxPython script? The shell is used to run Python.exe but it > doesn't look very professional when a black window pops up along with > your GUI. > > Thanks, > > Matt From joerg.maier at rz.uni-mannheim.de Tue Aug 5 14:15:47 2003 From: joerg.maier at rz.uni-mannheim.de (=?ISO-8859-15?Q?J=F6rg?= Maier) Date: Tue, 05 Aug 2003 20:15:47 +0200 Subject: python gui and ssh Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hey, i have a problem with ssh and popen2: #sshstdin, sshstdout = os.popen2(SSH_PATH + ' ' + self.user + '@' + self.server + ' ' + 'ls -al') ssh does not take paswords from sshstdin and it does not write user at server's password: to sshstdout but it writes to the terminal due to security issues. is there a possibility to pass passwords to ssh and to get terminal outputs to a pipe in a gui program? thanks for every help, i would like to write a gui based program giving the possibility to rsync with ssh as remote shell. this tool should run under cygwin, linux and macosx. - -- Hi I am a signature virus. Please copy me to your .signature file to help me spread. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2-rc1-SuSE (GNU/Linux) iD8DBQE/L/RYTYj8eXbs1acRAjpOAKCHLZFryhzcFQIVADRS6Az5UDAecgCdHLec 36sfcK7CB3Cg1t9l055BXAs= =MG0v -----END PGP SIGNATURE----- From rimbalaya at yahoo.com Thu Aug 21 17:55:46 2003 From: rimbalaya at yahoo.com (Rim) Date: 21 Aug 2003 14:55:46 -0700 Subject: docutils: ImportError: No module named roman References: <6f03c4a5.0308210640.46504655@posting.google.com> Message-ID: <6f03c4a5.0308211355.40b080b7@posting.google.com> Hi Dave, I found the problem: % python setup.py install --prefix=/mydir/python "optparse" module already present; ignoring extras/optparse.py. "textwrap" module already present; ignoring extras/textwrap.py. "roman" module already present; ignoring extras/roman.py. running install running build running build_py running install_lib creating /mydir/python/lib/python2.3/site-packages/docutils ... %echo $PYTHONPATH | tr ':' '\n' ... /mydir/python/lib/python2.2/site-packages /another_dir/local.linux_RH7.2/Python-2.3/lib/python2.3 I had mixed releases in the PYTHONPATH. Re-installed and works like a charm. Thanks, -Rim From hungjunglu at yahoo.com Wed Aug 27 12:10:17 2003 From: hungjunglu at yahoo.com (Hung Jung Lu) Date: 27 Aug 2003 09:10:17 -0700 Subject: Aspect oriented Everything? References: <32cc321c.0308221316.2f5793ac@posting.google.com> <6ee58e07.0308230459.24f53b64@posting.google.com> <8ef9bea6.0308261857.1b44a5b7@posting.google.com> Message-ID: <8ef9bea6.0308270810.7adfe408@posting.google.com> Jason Williams wrote in message news:... > In article <8ef9bea6.0308261857.1b44a5b7 at posting.google.com>, Hung Jung Lu wrote: > > If you write programs in OOP long enough, you will realize that there > > are code spots that are not factorized. For example, you register to a > > event listener at the beginning and de-register at the end of a > > method. > > Eh? What's wrong with; > > def methodThatHasToListenForAnEvent > listenForEvent(e) do > # The method stuff goes here > end > end The question is: are there code spots that are not factored? If you have ONE single class that has to implement the before, around, or after methods, sure, nothing wrong with what you have said. But, if you have class A: def f1(): register() ... deregister() class B: def f2(): register() ... deregister() class C: def f3(): register() ... deregister() You start to ask your self: how come the register() deregister() parts are not factor out? How can I factor out these parts of code? Why do you want to factor them out? You may ask. Because sometimes later, you may realize that, heh, actually you want to do one more thing before calling f1() f2() f3(): at beginning of the calls you want to log the method call. If you don't have AOP, you would have to manually modify each class into: class A: def f1(): log() register() ... non-factorizable code specific to f1 deregister() class B: def f2(): log() register() ... non-factorizable code specific to f2 deregister() class C: def f3(): log() register() ... non-factorizable code specific to f3 deregister() And later, you find out that you want to catch an certain type of exception and respond properly, without AOP, you go back to your code and write something like: class A: def f1(): try: log() register() ... non-factorizable code specific to f1 deregister() except: ... class B: def f2(): try: log() register() ... non-factorizable code specific to f2 deregister() except: ... class C: def f3(): try: log() register() ... non-factorizable code specific to f3 deregister() except: ... And then you realize that, oh, when the exception happens, you need to do some clean up, then you go back to your code and do class A: def f1(): try: log() register() ... non-factorizable code specific to f1 deregister() except: ... finally: ... class B: def f2(): try: log() ... non-factorizable code specific to f2 ... deregister() except: ... finally: ... class C: def f3(): try: log() register() ... non-factorizable code specific to f3 deregister() except: ... finally: ... And then, someone tells you that they want to know the time spent in these methods, so you do: class A: def f1(): start_timer() try: log() register() ... non-factorizable code specific to f1 deregister() except: ... finally: ... end_timer() class B: def f2(): start_timer() try: log() ... non-factorizable code specific to f2 ... deregister() except: ... finally: ... end_timer() class C: def f3(): start_timer() try: log() register() ... non-factorizable code specific to f3 deregister() except: ... finally: ... end_timer() And it is at this point that you start to wonder, man, it's tedious and error-prone trying to do the something to all the classes that share similar functionalities. And at the moment, you start to wonder whether you can factor out the similarities. Notice that OOP or class inheritance will not allow you to factor out these types of "horizontal common code spots". A way to see it is to have three sheets of paper, and you write the code of class A, B, C on each sheet, and stack the three sheets together. The common areas that overlap are in a horizontal direction. This type of horitontal factorization is what AOP is all about. Once you factor out the common parts, you can modify the code spot just once, and it will be applied automatically to all your classes. To my, horizontal factorization is what AOP is all about. It goes beyond the before-, around-, after- hooks. I've written codes where I have many if statements in a base class method: def f(): #--------------- step 1 during calculation code shared under all circumstances #--------------- step 1 during calculation if self.has_fixed_rate(): .... else: .... if self.is_government_bond(): .... else: .... if self.is_domestic(): .... else: .... #--------------- step 2 during calculation code shared under all circumstances #--------------- step 3 during calculation if self.has_fixed_rate(): .... else: .... if self.is_domestic(): .... else: .... #--------------- step 4 during calculation code shared under all circumstances #--------------- step 5 during calculation if self.is_domestic(): .... else: .... if self.is_government_bond(): .... else: .... After writing so many if...else... statement, you start to wonder: can I factor out these if...else... statements? One way is to use OOP and subclasses to encapsulate the is_domestic(), is_government_bond(), has_fixed_rate() features, (e.g: have a subclasses like domestic_fixed_rate_government_bond foreign_variable_rate_corporate_bond, etc.), but in OOP you will find out that common steps 1,2,4 will not be factored out, and that when you need to change the code in the common steps, you need to change in all subclasses, which is tedious and error-prone. Worse, with 3 features you have a combination of 8 subclasses, and if one day you include one more feature, you will have 16 subclasses. Are you going to change the code manually in 16, 32, 64 classes? Clearly inheritance is not the way to implement properties/features like these ones. OOP just cannot solve the problem. It is only when you run into this kind of situations, that you start to think about code factorization in a different dimension. AOP is a really need. I would agree that it is still an immature field of research. But people really need it. Hung Jung From aahz at pythoncraft.com Tue Aug 12 13:12:45 2003 From: aahz at pythoncraft.com (Aahz) Date: 12 Aug 2003 13:12:45 -0400 Subject: Problem with computing...addition References: Message-ID: In article , Lukas Kasprowicz wrote: > >So you see e.g. the 15th entry: "131.99000000000001" >there should be "131.99" and not this. > >who could help? http://www.python.org/doc/current/tut/node14.html -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ This is Python. We don't care much about theory, except where it intersects with useful practice. --Aahz From aleax at aleax.it Thu Aug 7 07:00:02 2003 From: aleax at aleax.it (Alex Martelli) Date: Thu, 07 Aug 2003 11:00:02 GMT Subject: Class design issues: multiple constructors References: Message-ID: Greg Brunet wrote: ... > instance. When I first started, I included a filename as a parameter > that would be used to open an existing DBF file. Next I decided to add > the ability to create a new DBF file. This method needs additional > parameters (such as the field definitions), and, while in some other > languages, I could provide 2 versions of the constructor (overload it if > I'm using the right terminology), and the compiler would use the > appropriate one, things don't seem to work that way in Python. I'm also > thinking that I might rather name the methods more specifically (such as > Open & Create) instead of both being __init__. What would be the Right. The Pythonic way is to provide "factory functions" that prepare and return the object you need. Cosmetically, you may make the factory functions part of the class itself, using the staticmethod and classmethod built-in types of Python 2.2 and later -- no real need, but some people are very keen on this style, so Python now supports it. > Pythonic way to go about doing this? Would I make an __init__, Open, & > Create methods, and make 2 calls for each DBF object, like this: > > class dbf: > __init__(self): > pass > Create(self, filename, fieldDefs): > pass > Open(self, filename): > pass No, it should rather be something like: class dbf(object): # no need to define __init__ if it's empty! def Create(filename, fieldDefs): result = dbf() # use filename and fieldDefs to populate 'result' appropriately return result Create = staticmethod(Create) def Open(filename): result = dbf() # use filename to populate 'result' appropriately return result Open = staticmethod(Open) > # open existing file > f1 = dbf() > f1 = dbf.Open('customer.dbf') No, this wouldn't work with the code you propose; it would with the variant I suggest, but the first of these statements is useless so you should remove it. > # create a new file > f2 = dbf() > f2 = dbf.Create('states.dbf', [('StateCode', 'C', 2), \ > ('StateName','C',20)] Ditto. Alex From grante at visi.com Fri Aug 8 12:01:13 2003 From: grante at visi.com (Grant Edwards) Date: 08 Aug 2003 16:01:13 GMT Subject: Need elegant way to cast four bytes into a long References: <3f33c209$1@news.si.com> <3f33c785$0$172$a1866201@newsreader.visi.com> Message-ID: <3f33c949$0$172$a1866201@newsreader.visi.com> In article <3f33c785$0$172$a1866201 at newsreader.visi.com>, Grant Edwards wrote: > In article <3f33c209$1 at news.si.com>, William S. Huizinga wrote: >> I've got an array.array of unsigned char and would like to make a slice >> of that array (e.g. a[0:4]) become one long like I would in "C" : >> >> l = ((unsigned long *) (&a[0]))[0]; > > Bad C programming. Your program isn't portable. Aside from the endian issue, it may even cause a bus fault or completely bogus value on many architectures (ARM, SPARC, etc.). It's actually quite difficult to duplicate that sort of behavior in Python. ;) -- Grant Edwards grante Yow! Remember, in 2039, at MOUSSE & PASTA will visi.com be available ONLY by prescription!! From robin at jessikat.fsnet.co.uk Sat Aug 30 05:53:59 2003 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Sat, 30 Aug 2003 10:53:59 +0100 Subject: Win32 documentation in CHM? Message-ID: It seems the Gods are proposing to distribute the documentation and help for Python-2.3.1 in .chm form. I particularly detest .chm and much prefer .html as it works across all platforms. Additionally by having a single index.html for all of the various bits of Python help I can link in things like Pmw, PIL and Quick Guide etc with a simple text editor. The argument is made that .chm is a better mechanism (more searchable indexable etc) for help/documentation than html. Is that really so? HTML is at least an open standard. -- Robin Becker From martin at v.loewis.de Fri Aug 8 17:10:25 2003 From: martin at v.loewis.de (Martin v. =?iso-8859-15?q?L=F6wis?=) Date: 08 Aug 2003 23:10:25 +0200 Subject: no universal newlines in os.popen References: Message-ID: Torsten Marek writes: > Is it a bug that > os.popen("some_nifty_command some_arg", "rU") > gives > OSError: [Errno 22] Invalid argument > in Python 2.3? Yes. Martin From gerrit at nl.linux.org Thu Aug 28 17:07:26 2003 From: gerrit at nl.linux.org (Gerrit Holl) Date: Thu, 28 Aug 2003 23:07:26 +0200 Subject: Celebrity advice (was: Advice to a Junior in High School?) In-Reply-To: <2259b0e2.0308272331.55028ae5@posting.google.com> References: <2259b0e2.0308272331.55028ae5@posting.google.com> Message-ID: <20030828210726.GB3736@nl.linux.org> Michele Simionato wrote: > Jacek Generowicz wrote in message news:... > > > > One learns so much more from reading opinions opposed to one's own, > > than from reading ones with which you agree. > > I thought it was worth repeating. Of course, this is only true if the other oppinions are based on points (can't find the English word for "gefundeerd"... founded?) In the Dutch politics newsgroup nl.politiek, a lot of opinions are available which aren't mine, but less than 5% of them has any points. Gerrit. -- 237. If a man hire a sailor and his boat, and provide it with corn, clothing, oil and dates, and other things of the kind needed for fitting it: if the sailor is careless, the boat is wrecked, and its contents ruined, then the sailor shall compensate for the boat which was wrecked and all in it that he ruined. -- 1780 BC, Hammurabi, Code of Law -- Asperger Syndroom - een persoonlijke benadering: http://people.nl.linux.org/~gerrit/ Het zijn tijden om je zelf met politiek te bemoeien: http://www.sp.nl/ From http Sat Aug 23 12:37:20 2003 From: http (Paul Rubin) Date: 23 Aug 2003 09:37:20 -0700 Subject: large-scale app development in python? References: Message-ID: <7xlltkxrcv.fsf@ruckus.brouhaha.com> "John Roth" writes: > There are quite a few large programs in Python. Zope comes to mind > immediately. I think by the standards of "large programs", Zope would be considered medium sized. From pobrien at orbtech.com Fri Aug 29 17:30:51 2003 From: pobrien at orbtech.com (Patrick K. O'Brien) Date: 29 Aug 2003 16:30:51 -0500 Subject: Need good example database schema References: Message-ID: cartermark46 at ukmail.com (Mark Carter) writes: > pobrien at orbtech.com (Patrick K. O'Brien) wrote in message news:... > > > I'm looking for a good schema to use as an example for an object > > database system. Something like a books/authors/publishers or > > teachers/students/courses kind of thing. There are plenty of > > examples of such to be found, especially in the academic > > literature involving object databases, but most of them are > > pathetic. It's hard to take a schema seriously when it shows > > MarriedTeacher inheriting from Teacher, etc. I want something > > that makes proper use of inheritance, has classes with reasonable > > attributes, and does a decent job reflecting reality (ie, books > > can have more than one author, a teacher of one course could be a > > student of another, etc.). Any suggestions? > > I found a link: > http://www.geocities.com/tablizer/oopbad.htm > (and there are others) who suggest that object-oriented databases > aren't a good idea. Tabular databases (and in fact a tabular design > rather than an object-oriented design in general) are more often > than not likely to be a better bet. > > But I am of course generalising. In that case, maybe I should stop developing my Python ODBMS. ;-) -- Patrick K. O'Brien Orbtech http://www.orbtech.com/web/pobrien ----------------------------------------------- "Your source for Python programming expertise." ----------------------------------------------- From uce at ftc.gov Mon Aug 25 14:24:32 2003 From: uce at ftc.gov (Gordon Airport) Date: Mon, 25 Aug 2003 14:24:32 -0400 Subject: list re-orderng headache In-Reply-To: References: Message-ID: Thanks, I just knew it could be done like that. I hadn't heard of the floor division operator, though - the book I'm using must be getting old. From ialbert at mailblocks.com Sat Aug 16 10:19:39 2003 From: ialbert at mailblocks.com (Istvan Albert) Date: Sat, 16 Aug 2003 10:19:39 -0400 Subject: Dictionary assignment In-Reply-To: <87isoyx82l.fsf@pobox.com> References: <87isoyx82l.fsf@pobox.com> Message-ID: <0YWdnRYtJYXgoKOiXTWJkQ@giganews.com> John J. Lee wrote: > Maybe it's surprising to some Perl users. Personally, it doesn't > surprise me (and I did come from Perl) that if you didn't add a key 2 > to the dictionary a, it complains when you look up 2 in that dict. What I meant to say is that it looks confusing because the expression a[2][3] = 4 looks like and straightforward assignment but resolves to a lookup followed by an assignment. That is the reason the original poster had the problem in question. Istvan. From jepler at unpythonic.net Mon Aug 18 12:14:33 2003 From: jepler at unpythonic.net (Jeff Epler) Date: Mon, 18 Aug 2003 11:14:33 -0500 Subject: hex(-5) => Futurewarning: ugh, can't we have a better hex than '-'[:n<0]+hex(abs(n)) ?? In-Reply-To: <87lltrzhpx.fsf@jautero.no-ip.org> References: <87lltrzhpx.fsf@jautero.no-ip.org> Message-ID: <20030818161433.GM16941@unpythonic.net> On Mon, Aug 18, 2003 at 07:56:42AM +0300, Juha Autero wrote: > Two questions: What is the best way to generate bitmask of n bits all > ones? def ones(n): r = (1l << n) - 1 try: r = int(r) except OverflowError: pass return r does this do what you want? It gives these results: # 2.3b1 (old, but should have 2.3's long vs int quirks) >>> for i in (0, 1, 2, 3, 31, 32, 33, 63, 64, 65): ... print "%2s %22s %22s" % (i, `ones(i)`, hex(ones(i))) ... 0 0 0x0 1 1 0x1 2 3 0x3 3 7 0x7 31 2147483647 0x7fffffff 32 4294967295L 0xFFFFFFFFL 33 8589934591L 0x1FFFFFFFFL 63 9223372036854775807L 0x7FFFFFFFFFFFFFFFL 64 18446744073709551615L 0xFFFFFFFFFFFFFFFFL 65 36893488147419103231L 0x1FFFFFFFFFFFFFFFFL # 2.2.2 >>> for i in (0, 1, 2, 3, 31, 32, 33, 63, 64, 65): ... print "%2s %22s %22s" % (i, `ones(i)`, hex(ones(i))) ... 0 0 0x0 1 1 0x1 2 3 0x3 3 7 0x7 31 2147483647 0x7fffffff 32 4294967295L 0xFFFFFFFFL 33 8589934591L 0x1FFFFFFFFL 63 9223372036854775807L 0x7FFFFFFFFFFFFFFFL 64 18446744073709551615L 0xFFFFFFFFFFFFFFFFL 65 36893488147419103231L 0x1FFFFFFFFFFFFFFFFL From max at alcyone.com Wed Aug 13 02:20:11 2003 From: max at alcyone.com (Erik Max Francis) Date: Tue, 12 Aug 2003 23:20:11 -0700 Subject: two quick questions References: Message-ID: <3F39D89B.A7160172@alcyone.com> Elaine Jackson wrote: > 1) Does Python have passing-by-reference? It depends on exactly what you mean by that. In a sense all Python objects are passed by reference, but only in the sense that the reference is passed by value. (Say that three times fast.) If you want to get the equivalent of a C++ reference on an immutable object, you can do it with containment. Pass the function a mutable container containing your object, and then manipulate/change the contained object. In the caller's scope, the container will have mutated. > 2) In ordinary parlance, "deep" implies "shallow" but not conversely. > In the > Python "copy" module (if I understand correctly), the implication goes > the other > way. Do you find this a nuisance? I'm not sure what about the copy's modules semantics you're thinking are reversed, but the terminology used in the copy module is common in computer science. A shallow copy means that the object is copied, but it will retain the same references to contained objects; a deep copy means that the object is copied, as well as the objects it contains (and so on, recursively). A deep copy always does the same thing as a shallow copy, and more. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ I always entertain great hopes. \__/ Robert Frost From shutton_REMOVE_ at attbi.com Tue Aug 5 23:58:32 2003 From: shutton_REMOVE_ at attbi.com (Steve Hutton) Date: Wed, 06 Aug 2003 03:58:32 GMT Subject: Python speed vs csharp References: <1h5f2rzthqgid.8watonaa4cjt.dlg@40tude.net> <3F551D29.1040407@kfunigraz.ac.at> <0MoXa.21930$cl3.850221@news2.tin.it> Message-ID: In article <0MoXa.21930$cl3.850221 at news2.tin.it>, Alex Martelli wrote: > Siegfried Gonzi wrote: > ... > >> g++ -O3 erf.c : 0.5 seconds >> bigloo -Obench erf.scm: 1.1 seconds > > [alex at lancelot swig_wrappers]$ gcc -O -o gonzi gonzi.c -lm > [alex at lancelot swig_wrappers]$ time ./gonzi To be fair, using -O3 here instead of -O buys around a 15% performance gain for me, presumably due to inlining. Steve From nicola-mingotti_NOSPAM at libero.it Sun Aug 3 11:35:31 2003 From: nicola-mingotti_NOSPAM at libero.it (Nicola Mingotti) Date: Sun, 03 Aug 2003 17:35:31 +0200 Subject: command history broken in Python2.3 ? Message-ID: Hello , I'm tring Python 2.3 ( on source and binary distribution , on Linux and Windows ) and i think the command history doesn't work . When i use the Up-Arrow in Python2.3 started in an xterm i get '^[[A' . In IDLE under Windows using Alt-p produce nothig . In IDLE under Linux Alt-p works !! . Do you have the same behavior in you interpreter ? Bye . (p.s. please forgive english mistakes ) From anthony at interlink.com.au Tue Aug 19 00:16:42 2003 From: anthony at interlink.com.au (Anthony Baxter) Date: Tue, 19 Aug 2003 14:16:42 +1000 Subject: python for non-programmers tutorial? Message-ID: <200308190416.h7J4GgTT014082@localhost.localdomain> I'm writing a half-day tutorial at work for the non-programmer techies (network engineers, database admins, sysadmins, that sort of thing) and was wondering if anyone else has already done this and made their materials available? I plan to put my slides up on the web after they're done... Thanks, ANthony -- Anthony Baxter It's never too late to have a happy childhood. From eltronic at juno.com Wed Aug 27 15:08:19 2003 From: eltronic at juno.com (eltronic at juno.com) Date: Wed, 27 Aug 2003 15:08:19 -0400 Subject: My future Python IDE article Message-ID: <20030827.151007.-244929.2.eltronic@juno.com> On Wed, 27 Aug 2003 17:38:39 +0200 =?ISO-8859-1?Q?Gerhard_H=E4ring?= writes: > Alan James Salmoni wrote: > > Personally, I would include: > > > > 1) SciTE [...] > > 2) Leo [...] > > Neither one is an IDE (they lack a debugger). They're only editors. > good point but I hope this wont be a choice limiting factor. calling Leo only an editor is like calling python only a script language. although, true Leo doesn't come out of the box with debugging. personally I added pdb to automatically be entered on any error per a cookbook entry to my site.py . there could be a debugger plugin (yes Leo has plugins) not light weight limited plugins, full skys the limit plugins. you can execute any script by selecting it, you want debugging, import pdb or whatever your favorite. Leo doesn't get in your way in this regard. not having tried any of the higher powered IDE for python, maybe I would like debugging support. I do require it in C. since python does so much for you already I don't miss it much. I do spend a little time recharging the batteries though. a visual debugger/program emulator would be on anyones wish list. running code from the IDE in general isn't really cost effective. just for the import file command, which seperates code from many languages into an outline which you can then use to refactor, and the c to python script included makes it worth using. e please forward all spam to "not my real email" ________________________________________________________________ The best thing to hit the internet in years - Juno SpeedBand! Surf the web up to FIVE TIMES FASTER! Only $14.95/ month - visit www.juno.com to sign up today! From mday at apple.com Wed Aug 6 17:58:02 2003 From: mday at apple.com (Mark Day) Date: Wed, 06 Aug 2003 14:58:02 -0700 Subject: Bug? If not, how to work around it? References: Message-ID: <060820031458029244%mday@apple.com> In article , Gon?alo Rodrigues wrote: > >>> class Test(object): > ... def __init__(self, obj): > ... self.__obj = obj > ... def __getattr__(self, name): > ... return getattr(self.__obj, name) > ... > > Now: > > >>> a = Test([]) > >>> a.__iter__ > > >>> iter(a) > Traceback (most recent call last): > File "", line 1, in ? > TypeError: iteration over non-sequence > >>> > > Is this a bug? If not, how to code Test such that iter sees the > __iter__ of the underlying object? I'm guessing that iter() is looking for an __iter__ attribute without going through __getattr__ to find it. So, I tried adding the following method to the Test class: def __iter__(self): return self.__obj.__iter__ but that returned the following error: TypeError: iter() returned non-iterator of type 'method-wrapper' I changed the __iter__ method to the following, and it seems to do what you want: def __iter__(self): return iter(self.__obj) As to whether this is a bug, I don't know. -Mark From news at exultants.org Thu Aug 14 10:17:52 2003 From: news at exultants.org (Van Gale) Date: Thu, 14 Aug 2003 14:17:52 GMT Subject: Is Python your only programming language? In-Reply-To: References: Message-ID: Nick Vargish wrote: > So what programming language actually does bridge the gap between > "thousands of lives depend on the code working right" and "getting > this up and running quickly"? I would hope that there would be pressure for "up and quickly" when thousands of lives are at stake :) So, the only choice in that case is doing it properly. I think that Ada is one of the few languages capable of being used on "lives depend on it" systems. It's not anything special about the language in particular, but rather the immense amount of man-hours and time spent in writing checking and analysis tools. That includes tools that can verify an Ada program will meet real-time requirements. This kind of tool is really sophisticated (obviously) and would probably be impossible to code for anything but a strong static typed language.