From inno0658 at kornet.net Fri Mar 1 03:31:25 2002 From: inno0658 at kornet.net (=?ks_c_5601-1987?B?uN7Az8bExq6zyg==?=) Date: Fri, 01 Mar 2002 11:31:25 +0900 Subject: =?ks_c_5601-1987?B?W7GksO1dIHB5dGhvbi1saXN0tNQgvsiz58fPvcq0z7HuPyC0qbG4PyC3zrn2xq7H0riusKEuLrm5PyC8vL26v7W+7lRhcGW4pi4uvvO4tj8gsPjCpbfOLi4=?= Message-ID: <3c7c44be3c82de9d@relay3.kornet.net> (added by relay3.kornet.net) ????(???)??????????????????.???????????????. ????? ???? ????? ?? ??? ?? ? ???? ??? ??? ??? ? ????. >>> ?? ?? ??? ????? ?? ??? ??? ????. ??? ?? ???? ?? ??? ??? ????? ???? ??? ??? ??? ????. ??? ?? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-list/attachments/20020301/8367b043/attachment.html From plussm at orgio.net Sun Mar 3 09:09:57 2002 From: plussm at orgio.net (°øµ¿±¸¸Å) Date: Sun, 3 Mar 2002 17:09:57 +0900 Subject: [±¤ °í] ³õÄ¥¼ö ¾ø´Â °øµ¿±¸¸Å! ÈÄȸ¾øÀ¸½Ç°ÍÀÔ´Ï´Ù. Message-ID: An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-list/attachments/20020303/a8e53923/attachment.html From plussm at orgio.net Sun Mar 3 09:09:57 2002 From: plussm at orgio.net (°øµ¿±¸¸Å) Date: Sun, 3 Mar 2002 17:09:57 +0900 Subject: [±¤ °í] ³õÄ¥¼ö ¾ø´Â °øµ¿±¸¸Å! ÈÄȸ¾øÀ¸½Ç°ÍÀÔ´Ï´Ù. Message-ID: An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-list/attachments/20020303/0ac370da/attachment.htm From marketnews at yahoo.com Fri Mar 1 17:03:51 2002 From: marketnews at yahoo.com (marketnews at yahoo.com) Date: Fri, 01 Mar 2002 07:03:51 -0900 Subject: Aquisition Alert Message-ID: <038c74a21d7c$3827d2d3$4be84ae6@qwfioq> URGENT TRADING FLUCTUATION! Company: IRV Inc. Symbol: ( I R V V ) Exchange: OTCBB Current Price (IRVV): $.34 cents per share Recent High (IRVV): $.64 cents per share Short Term Outlook: $1.15 per share Notes: With the company aquiring Scarab Systems, We suggest aggressive buying at these levels for a short term performance (news below). Company Aquisition News: IRV Inc. announces intent to acquire Scarab Systems Inc., smart card payment solution provider The Board of Directors of iRV inc. (OTC BB:IRVV) is pleased to announce that the company has signed a letter of intent to acquire Scarab Systems Inc., a privately held Nevada corporation. Scarab Systems Inc. is engaged in the distribution and sale of smart card payment systems for applications in e-commerce, banking, telecommunications, security and personal data transfer. The acquisition will proceed pending completion of specific terms and conditions to be laid out in a formal agreement. Scarab Systems provides rechargeable stored value smart cards that the cardholder can load from a designated banking account via the internet or via designated ABM's. The funds can be withdrawn from most ATM's worldwide, or the stored value can be used to purchase goods and services anywhere that VISA is accepted, whether online or in brick and mortar businesses. Scarab's payment solutions operate on existing network infrastructures. Unlike many other smart card systems, Scarab's program uses existing processing and billing platforms and encryption technology, which work with existing POS and ATM systems. This technology helps eliminate the usual cost-prohibitive infrastructure required to set up a smart card program. "Scarab Systems technology provides exciting prospects for innovative payment solutions that we feel represent a valuable contribution in iRV's strategy of expanding its technological asset base. The acquisition of Scarab represents a critical step in the process of implementing technologies that deliver recurring revenue," stated Clifford C. Thygesen, President of iRV Inc. "The public market allows the investment community the opportunity to share in the exciting growth that Scarab Systems and the smart card industry is experiencing. The revised corporate structure will help accelerate the rollout of Scarab's payment system technologies." Thomas Mills, President of Scarab Systems stated. The smart card industry continues to experience tremendous growth. Year on year card sales continue to set records, as the market is poised for enormous prosperity in the new millennium. Smart card sales at $274 Million in 1996 are estimated to be $5 Billion in 2003 (Frost & Sullivan). The number of cards shipped worldwide is estimated to be 2.8 billion for 2000, up from 1.8 billion cards in 1998. It is estimated that the industry as a whole will continue to grow at a rate between 30 and 50% annually for the foreseeable future. (SBJ Research). Safe Harbor Statement: The statements contained herein which are not historical fact are forward-looking statements that are subject to risks and uncertainties that could cause actual results to differ materially from those expressed in the forward-looking statements, including but not limited to, certain delays in testing and evaluation of products and other risks detailed from time to time in iRV Inc. filings with the United States Securities and Exchange Commission. 1704UTrK8-432fLOH5259Kxmi0-145kZSZ8877DOnw4-714AjvX624l51 From cfelling at iae.nl Fri Mar 1 00:03:38 2002 From: cfelling at iae.nl (Carel Fellinger) Date: 1 Mar 2002 00:03:38 +0100 Subject: map-like function on dict values? References: Message-ID: Skip Montanaro wrote: ... > Don't assume for loop iteration is your only culprit... ;-) List creation > overhead can be as big a problem. I added another test function called iter yep, see my other posting:) > which relies on 2.2's new "for k in dict" capability to completely avoid > list creation. (I also changed your range() to an xrange() to avoid the > extra list allocation, and called clock() instead of time() to measure CPU > time instead of elapsed time. This is on a Linux system) Here's what I get > on my laptop: Ah a new contestent, double fun, better algoritme better timing (linux too), but the real iter still wins, although by a very slight margin:) > iter 6.69 > iteritems 28.36 > mapvalue 8.12 ... def iteriteritems(f, d): for k, v in d.iteritems(): d[k] = f(v) ... > timeit(iter, f, d) timeit(iteriteritems, f, d) timeit(iteritems, f, d) > timeit(mapvalue, f, d) iter 10.95 iteriteritems 10.43 iteritems 52.15 mapvalue 12.88 -- groetjes, carel From James_Althoff at i2.com Fri Mar 1 00:17:17 2002 From: James_Althoff at i2.com (James_Althoff at i2.com) Date: Thu, 28 Feb 2002 15:17:17 -0800 Subject: PEP 276 (was Re: Status of PEP's?) Message-ID: [Carel Fellinger] > you being such a heavy weight that I fear > Guido might be lured into thinking this to be a good idea > that I felt compelled to react in public. Well, thanks (I think ), but I can assure you that I hold no special brownie points and have zero ability to "lure" Guido (or anyone on the Python team) into anything. So, no need to lose any sleep over that one. (On the other hand, if anyone knows *how* to "lure" any of them, be sure to let me know ). [Samuele Pedroni offers this perspective sans endorsement ] > in mathematics it is not uncommon to > identify the natural numbers with the set > of their predecessors > > 0 = {} > 1 = {0} = {{}} > 2 = {0, 1} {{},{{}}} > etc [Carel Fellinger] > Not only newbie unfriedly, you need a firm grasp of modern set > based number theory to appreciate it, it seems. As fond as we all surely are of the neat mathematical underpinnings suggested here and before, I believe that most programmers -- regardless of skill level (and pedigree in the field of mathematics) -- would be able to understand -- and certainly easily remember the second time -- that iterating on n means taking each of 0,1,2, ..., n-1 in turn; this without having to think about -- much less have "a firm grasp of" -- number theory (modern, set-based, or otherwise ). At least if one has enough background to understand "iteration" to begin with. Let's try that again. Q: What does it mean to iterate a number n? A: Take each of 0,1,2, ..., n-1 in turn. Q: When would I want to do that? A: When you need the indices of an indexed-collection, for example. (No set theory needed ). I certainly acknowledge the feelings of those who don't like the suggested idiom. At the same time, claims of its alleged *great difficulty* seem overblown. [Carel Fellinger] > So please explain why you think it natural to loop over a number. The "rational" section of PEP 276 talks about iterating through the indices of an indexed collection. These, as we know, are related to the length (an integer) of the indexed collection. [Carel Fellinger] > here in your PEP you make it look like some minority > of nitwits objected I don't remember writing anything about nitwits. But that does remind me of the joke about "when failing to find a needed wit, they substituted two half-wits, instead". Seriously though, I don't recall and didn't intend any insult to those who don't like PEP 276's suggestion of an iterator for integers. Please feel free to point out the actual text that you find offensive. [Aahz Maruch] > My primary complaint about the PEP is that the following idiom is > awkward, ugly, and prone to misunderstanding: > > if i in 5: I will note this. However given that current Python seems able to do type-checking on strings used with "in" as in, for example: >>> 1 in 'spam' Traceback (most recent call last): File "", line 1, in ? TypeError: 'in ' requires character as left operand >>> it's not obvious (to me, anyway) why the same (throwing a TypeError, that is) could not be done for ints assuming one believes that "i in 5" is so bad. On the other hand, as noted by Bjorn Pettersen, "if i in len(mylist):" seems like a pretty straightforward and handy thing to write. I would use it were it available. And I don't think it would confuse any of the developers I work with. YMMV [Remco Gerlich] > Compare: > > for i in 6: print i > for i in 6,7: print i > for i in 6,7,8: print i > > You wouldn't think the first line does something different, would you? [Emile van Sebille] > Is that really any different from what we have now: > > for i in "Spam": print i > for i in "Spam","and": print i > for i in "Spam","and", "Eggs": print i [Andy Gimblett] > Yes, it really is. "Spam" is a sequence, whereas 6 isn't. I agree with Emile on this one. >>> for s in 'spam': print s ... s p a m >>> for s in 'spam','eggs': print s ... spam eggs >>> Two different results. One needs to understand how and why. Sometimes one wants to treat a string as a unit, other times as a sequence. It's useful and convenient to be able to do both. [Courageous] > for i in [0:len(mylist):1]: [Bjorn Pettersen] > And exactly this notation has been rejected in PEP 204 -- > basically because it's butt-ugly in a Perl'ish sort of way > Besides, this goes under the section of solving the "interval" > problem which PEP 276 *explicitly* says it is not doing (and which > I personally don't find very compelling, especially if PEP 276 is > adopted). I agree with Bjorn. A lot of alternatives for full-blown intervals were proposed during previous discussions of PEP 276. Many of them require new syntax. Much of such new syntax, though logical and nice in theory, ends up looking pretty cluttered when used in common examples. PEP 276 attempts to reduce clutter for a common case with minimal change to Python (no new syntax at all). In any event, proponents of alternatives should take the time to write a PEP. [David Eppstein] > Maybe it's as natural as Perl's ability to concatenate numbers? I don't appreciate your sarcasm. Maybe others do. Jim From tdelaney at avaya.com Fri Mar 1 00:21:36 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Fri, 1 Mar 2002 10:21:36 +1100 Subject: Status of PEP's? Message-ID: > I'd also like to put in my (unrequested) two cents and go on record as > disliking the "for i in 5" syntax. Not just as a matter of taste, but > because it provides unintuitive behavior, as pointed out previously. > The two lines... > for i in 5: print i > for i in 5, 6: print i > ...would behave differently under the proposal. They behave differently now. One is a syntax error, the other isn't. For the record (I've said this before), I like the idea of integers being iterable (and I'm not a set theory wonk). I never think of it though as for i in 5: print i but always as for i in len(seq): print i or something similar, which has obvious semantic logic. However, I could see myself happily using for i in 5: in a quick script. One important thing to remember, which I think a few people have missed, is that an integer will not be an iterator. An integer will be iterable - that is, to get this behaviour, iter(integer) must be called at some stage. This is done transparently in a for: loop. Are the following two equivalent though? if 1 in obj: pass if 1 in iter(obj): pass i.e. is iter(obj) called implicitly in the first case? Tim Delaney From ron at ire.org Fri Mar 1 00:25:06 2002 From: ron at ire.org (ron nixon) Date: 28 Feb 2002 15:25:06 -0800 Subject: ASV module, CVS modules Message-ID: <61ff32e3.0202281525.3e9bb102@posting.google.com> Hello, I'm trying to use either of these two modules ASV by Laurence Tratt at http://tratt.net/laurie/python/asv/ and CSV by Dave Cole at http://object-craft.com.au/projects/csv/. I tried both of these and get this error: Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information. IDLE 0.8 -- press F1 for help >>> import ASV >>> my_data = ASV.ASV() >>> my_data.input_from_file("c:\test_data.csv", ASV.CSV(), has_field_names =1) Traceback (most recent call last): File "", line 1, in ? my_data.input_from_file("c:\test_data.csv", ASV.CSV(), has_field_names =1) File "C:\PYTHON22\ASV.py", line 222, in input_from_file file = open(input_file, "rb") IOError: invalid argument: rb >>> I get a similar message from CSV module. Anyone use either of these and can tell me what's wrong? Ron Nixon From edcjones at erols.com Fri Mar 1 00:48:56 2002 From: edcjones at erols.com (Edward C. Jones) Date: Thu, 28 Feb 2002 18:48:56 -0500 Subject: Python DB that supports numbers References: Message-ID: <3C7EC1E8.7070001@erols.com> Randall Hopper wrote: > I'm looking for a very simple Python DB which supports: > > 1) ints and floats as keys and values, > 2) performs DB access in the client, and > 3) stores the DB on disk. > > Just a simple DB for quick projects without the setup headache of > server-based database systems. > > For example, on the following table I just want to: "select * where > column_1 is 1". I'm using raw binary files now, but I'd prefer something > more self-describing like an SQL table. > > 1 10 1.814 177.1 13.61 73.2 > 1 5 1.624 182.5 -9999 -9999 > 1 2 1.259 185.9 13.24 73.9 > 2 10 2.672 181.4 13.59 72.5 > 2 5 2.423 183.2 -9999 -9999 > 2 2 1.902 190.7 13.27 73 > 3 10 3.208 181.9 13.46 72.1 > 3 5 2.787 186.6 -9999 -9999 > 3 2 2.17 194.7 13.16 72.3 > > Does anything like this exist in Python? I would use a Python dictionary which I would store to disk using module cPickle. table = {} def AddRow(table, row): key = row[0] if not table.has_key(key): table[key] = [] table[key].append(row) AddRow(table, [1, 10, 1.814, 177.1, 13.61, 73.2]) AddRow(table, [1, 5, 1.624, 182.5, -9999, -9999]) # ... AddRow(table, [3, 2, 2.17, 194.7, 13.16, 72.3]) print table[1] In the C++ Standard Template Library, there is a thing called a Multimap. It is like a Python dictionary except that each key can occur more than once. My Python name for this concept is "MultiDict". A MultiDict can be implemented in Python as a dictionary whose values are lists (like table[1] above). A MultiDict is a natural way to process sets of n-tuples. I have attached MultiDict.py which I use when the approach above is too simple but MySQL is overkill. Thanks, Ed Jones -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: MultiDict.py Url: http://mail.python.org/pipermail/python-list/attachments/20020228/f38c6be1/attachment.pot From bokr at oz.net Fri Mar 1 00:46:47 2002 From: bokr at oz.net (Bengt Richter) Date: 28 Feb 2002 23:46:47 GMT Subject: Telnet connection References: <8z9f2rks.fsf@fido.trinitycapital.com> Message-ID: On Thu, 28 Feb 2002 19:51:06 +0100, "Riss Nicolas" wrote: >Has somebody a python program where it is an telnet connection ? You appear to be running windows. What happens if you get into your browser and put telnet://192.168.0.9:32 in the location (i.e., what you are trying to connect to with your code)? Do you get a telnet client screen with a login prompt? Did you try \r\n in place of plain \n in your code? Regards, Bengt Richter From James_Althoff at i2.com Fri Mar 1 00:52:38 2002 From: James_Althoff at i2.com (James_Althoff at i2.com) Date: Thu, 28 Feb 2002 15:52:38 -0800 Subject: Status of PEP's? Message-ID: [Tim Delaney] > I never think of it though as > > for i in 5: > print i > > but always as > > for i in len(seq): > print i > > or something similar, which has obvious semantic logic. And I think such context makes the example easy to understand. (And, yes, abuse is possible). > However, I could see myself happily using for i in 5: in a quick script. Me too. :-) > One important thing to remember, which I think a few people have missed, > is that an integer will not be an iterator. An integer will be iterable - > that is, to get this behaviour, iter(integer) must be called at some stage. > This is done transparently in a for: loop. Very good point. > Are the following two equivalent > though? > > if 1 in obj: > pass > > if 1 in iter(obj): > pass > > i.e. is iter(obj) called implicitly in the first case? Good question. I was wondering that, myself. I'm guessing that the answer is no because of the following: >>> >>> 1 in 'spam' Traceback (most recent call last): File "", line 1, in ? TypeError: 'in ' requires character as left operand >>> >>> 1 in iter('spam') 0 >>> Jim From eppstein at ics.uci.edu Fri Mar 1 00:43:29 2002 From: eppstein at ics.uci.edu (David Eppstein) Date: Thu, 28 Feb 2002 15:43:29 -0800 Subject: Status of PEP's? References: Message-ID: In article , "Bjorn Pettersen" wrote: > Since many of the brightest minds on c.l.py have tried hard to come up > with a general range syntax without much success I would argue with the "without success" opinion you express. I still like for lower_bound <= var < upper_bound (or similar three-way comparisons, with middle argument of comparison required to be a variable), in parallelism with the current "for var in seq" with first argument of "in" required to be a variable. I guess we haven't made it into a PEP for the BDFL to rule on, if that's your measure of success, but the only arguments I can remember seeing against it are (1) some people view "in" as a keyword integrally attached to "for" rather than part of an expression, and don't like for loops without "in", and (2) this isn't sufficiently terse for those situations where you want an integer range outside of a for loop. Am I misinterpreting the previous discussion? -- David Eppstein UC Irvine Dept. of Information & Computer Science eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/ From tim at frontier.net.nospam Fri Mar 1 00:52:24 2002 From: tim at frontier.net.nospam (Tim H) Date: Thu, 28 Feb 2002 16:52:24 -0700 Subject: Can use python to play MP3 file? References: <3C7E6328.6050500@bigfoot.de> Message-ID: <3c7ec28f$0$27085$4c41069e@reader1.ash.ops.us.uu.net> "Gerhard H?ring" wrote in message news:3C7E6328.6050500 at bigfoot.de... > Ricky wrote: > > I hear that PHP can online play MP3 file. Is there any method that can make > > me play MP3 by using Python CGI? > > > > Thanks for any reply! > > Do you want to play the MP3 file on the server, like a jukebox. Or do > you want to stream MP3 files back to the client computer? > > (Of course you can do both with Python) > > Gerhard > Do you have examples, links, hints to doing each with python? Thanks, Tim From peter at engcorp.com Fri Mar 1 01:16:21 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 28 Feb 2002 19:16:21 -0500 Subject: Windows GUI - which way? References: Message-ID: <3C7EC855.5844B19F@engcorp.com> Spencer Doidge wrote: > > I have a nice script running and doing useful work--in the Windows console > mode. [...] I'd like to make this palatable for others around the company > to use, and that means Windows GUI. > So should I write up a program in my favorite style, Win32 API, and embed > Python in it? > Or should I write the whole thing in Python? > > Would somebody like to comment on the pros and cons? Write the whole thing in Python (my preference would be with wxPython) and package it up with py2exe or equivalent. Use a standard installer to distribute it and no one in the company will ever know it was written with Python. Except for the higher reliability. And your greater responsiveness in implementing feature requests quickly. And how quickly you got it to them. Etc. :-) (We've written several utilities with wxPython and serial ports running under Windows. So far the wxPython side of things is quite primitive since we're still learning, but even in their current state they're quite acceptable, and have no real issues the way a more traditionally developed program (i.e. Windows GUI with C/C++ or whatever) would have. -Peter From peter at engcorp.com Fri Mar 1 01:22:30 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 28 Feb 2002 19:22:30 -0500 Subject: Want to monitor process.. References: <87550ef1.0202272315.15779bbd@posting.google.com> <97ae44ee.0202280901.3153bdfc@posting.google.com> Message-ID: <3C7EC9C6.D11FB17@engcorp.com> Stephen wrote: > > Unfortunately, my own applications seem to crash as opposed to > shutdown normally, so it's probably not going to help me. From the > library reference ~ > "Note: the functions registered via this module are not called when > the program is killed by a signal, when a Python fatal internal error > is detected, or when os._exit() is called. " Yikes! "Crash"? Do you really mean they crash the Python interpreter, or do you mean they exit with an exception? If the former, you've got seriously problems, I agree. If the latter, just wrap the highest level code with a try/finally or try/except and put code in to ensure the child processes are properly terminated. Simple, clean, safe. My Python programs *never* crash (as in kill the interpreter) but maybe that's just me... I doubt it. -Peter From elflord at panix.com Fri Mar 1 01:22:16 2002 From: elflord at panix.com (Donovan Rebbechi) Date: Fri, 1 Mar 2002 00:22:16 +0000 (UTC) Subject: Scripting C++ -- 2 -- a more concrete example. References: <3C7E6642.2030202@physics.ucsb.edu> Message-ID: In article <3C7E6642.2030202 at physics.ucsb.edu>, Craig Maloney wrote: > If I use wrapper generators, it seems like there is a chance (e.g. using > SILOON/PDT or BOOST/PDT) that it would be possible to have the wrapper > code automatically generated. Most of it. Using sip, I generate about 4 times as much code as I write, so the ratio is pretty good. There are things sip doesn't do like mapping python and C++ exceptions that I need to take care of manually. > 2) Marshalling and Objects-by-value. > When the "Crystal" computes its energy it should *NOT* have to marshall > calls to get at the atom data structures. This is an operation that > will be repeated about 2.85 bijillllion times. In CORBA, this is no > problem -- I would either have Crystal::addAtom take a valuetype (atoms > are easy enough to serialize), or I would use some "co-location" trick > so that the ORB knows that the atom *really* lives in the same address > space as the crystal. Preferrably the former. > > If using a wrapper generator (e.g. SILOON) I don't see a way around the > marshalling of the call to get at the atom data structure. I don't really understand exactly what the problem is. > > Of course, this would be taken care of by a revamp of the design of the > class library... maybe making the crystal an atom factory that produces > new atoms in its own address space. But I would like to avoid thinking Now I'm really confused. If you're not using CORBA, the atoms are in the same address space, aren't they ? -- Donovan From peter at engcorp.com Fri Mar 1 01:32:31 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 28 Feb 2002 19:32:31 -0500 Subject: listing threads? References: Message-ID: <3C7ECC1F.F4FD6AFD@engcorp.com> maximilianscherr wrote: > > in the docs theres the information, that i can list all active > threads with threading.enumerate(), but i always just get the > Mainthread displayed in the interpreter console. > > im doing somethin like: [...snip] > then if i do threading.enumerate() i just get the mainthread int he > list. > > so how can i now list all (active) threads? Just as you are trying to do. Does this help? >>> class test(t.Thread): ... def run(self): ... print 'hi' ... self.terminated = 0 ... import time ... while not self.terminated: ... time.sleep(1) ... print 'done' ... >>> te = test() >>> te.start() hi >>> t.enumerate() [, <_MainThread(MainThread, started)>] >>> te.terminated = 1 >>> done >>> t.enumerate() [<_MainThread(MainThread, started)>] >>> Your problem is that (a) you don't have a run() method in your thread class, and that is what gets executed when you call te.start(), and (b) your thread is therefore terminating immediately upon creation, and therefore t.enumerate() is returning only the main thread, because no others are running. -Peter From totpleras at yahoo.com Fri Mar 1 01:23:08 2002 From: totpleras at yahoo.com (totpleras at yahoo.com) Date: Thu, 28 Feb 2002 19:23:08 -0500 Subject: Make the kind of money you only dream of Message-ID: <09006U.0H099W2ASF4G.totpleras@yahoo.com> Make It Happen Online Today!! 5 Cash Generating Websites!! Full resell rights! You keep 100% of the Money!! 100% money back guarantee! Check it out at http://www.renetcom.net/way2wealth2/ -------------------------------------------------------------------------------- If you would like to be removed from this opportunities mailing, simply reply to this message with remove in your subject line. You will be removed automatically by our system. -------------------------------------------------------------------------------- -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-list/attachments/20020228/124a2deb/attachment.html From robin at jessikat.fsnet.co.uk Fri Mar 1 01:26:14 2002 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Fri, 1 Mar 2002 00:26:14 +0000 Subject: win32+popen4 Message-ID: <$4LupWAmqsf8Ew0o@jessikat.fsnet.co.uk> What's the correct way to give a command to popen4 under win32 when the command/arguments may have spaces in it. EG I want to use "c:\program files\dimbo\bongo.exe" "c:\program files\dumbo\my file.dat" as the command. -- Robin Becker From eppstein at ics.uci.edu Fri Mar 1 01:22:47 2002 From: eppstein at ics.uci.edu (David Eppstein) Date: Thu, 28 Feb 2002 16:22:47 -0800 Subject: algorithm snippets available Message-ID: I've been teaching the undergraduate algorithms course here at UCI this quarter using Python syntax for my pseudocode (or, often, actual code) as an experiment instead of the C/C++/Java syntax I'd used before. Anyway, to help the students experiment with the algorithms, I've been posting some implementations to my web site, and thought maybe others on this list might find them interesting or useful. They're at . Today's addition: kmp.py, a Knuth-Morris-Pratt string matcher. Compared to using string.find or regular expressions, it allows the input to be any kind of list or sequence (not just a string), and allows the longer of the two inputs to be any kind of iterator rather than having to be all in memory at once. -- David Eppstein UC Irvine Dept. of Information & Computer Science eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/ From bokr at oz.net Fri Mar 1 01:37:53 2002 From: bokr at oz.net (Bengt Richter) Date: 1 Mar 2002 00:37:53 GMT Subject: PEP 276 (was Re: Status of PEP's?) References: Message-ID: [just posted] On 28 Feb 2002 05:57:05 -0800, aahz at panix.com (Aahz Maruch) wrote: >[posted & e-mailed] > >In article , > wrote: >> >>Rather than restart the entire debate on PEP 276, please send me >>suggestions for specific changes to the PEP. > >My primary complaint about the PEP is that the following idiom is >awkward, ugly, and prone to misunderstanding: > > if i in 5: > ... > >Please add this to your list of objections. how about if i in [:5]: # (colon required to specify slice vs list) The implication is an anonymous slice of xrange(sys.maxint+1) (if that were legal). This could also allow [2:5] or [1:5:2] etc. For an anonynous slice of integers, it might be reasonable to interpret negative numbers in the slice as legitimate indices backwards from zero. E.g., i in [-2:5:2] would be mean "i in [-2,0,2,4]", not effectively "i in []". Regards, Bengt Richter From eppstein at ics.uci.edu Fri Mar 1 01:35:50 2002 From: eppstein at ics.uci.edu (David Eppstein) Date: Thu, 28 Feb 2002 16:35:50 -0800 Subject: PEP 276 (was Re: Status of PEP's?) References: Message-ID: In article , James_Althoff at i2.com wrote: > [David Eppstein] > > Maybe it's as natural as Perl's ability to concatenate numbers? > > I don't appreciate your sarcasm. Maybe others do. I'm sorry that my sarcastic tone seems to have obscured what I think is a real point: one feature of Python is that, although variables are untyped, their values are strongly typed: what you can do with a value depends on its type. So, you can concatenate strings but not integers; you can multiply integers but not strings. The credo "explicit is better than implicit" is in part about this: if you want to concatenate the decimal representation of two numbers, you should use an explicit function to convert the numbers into strings. Your proposal, by blurring the distinction between integers and ranges of integers, decreases this level of explicitness in Python. -- David Eppstein UC Irvine Dept. of Information & Computer Science eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/ From Gareth.McCaughan at pobox.com Fri Mar 1 01:29:56 2002 From: Gareth.McCaughan at pobox.com (Gareth McCaughan) Date: Fri, 1 Mar 2002 00:29:56 +0000 Subject: Status of PEP's? References: <3c7d8f26_3@news.bluewin.ch> Message-ID: Samuele Pedroni wrote: > Maybe this is a useful insight: > > in mathematetics it is not uncommon to > identify the natural numbers with the set > of their predecessors [etc] > so also the notation 1 in 5 is natural. I am a mathematician. The areas of mathematics I always liked best were set theory and number theory (though I ended up doing my PhD on something else). I am very familiar with the von Neumann ordinals, which Samuele describes. Nevertheless, I think this would be a terrible thing to put into Python. "Explicit is better than implicit", remember? It would confuse newbies severely. It would confuse non-newbies severely too, actually, though I expect they'd get used to it. (Heck, people get used to Perl and C++, too.) The "for x in 5" notation seems to me to have no advantage whatever other than brevity. von Neumann didn't invent his construction of the ordinals because it was obviously the right thing, or because it was natural. He did it because it was simple. When what you're doing is laying foundations for mathematics, that counts for a lot. But that's not what Python is about. Go and look at a set theory textbook that describes that construction of the natural numbers. It's a good guess that within a few pages they will also have defined integers as equivalence classes of ordered pairs of natural numbers, rationals as equivalence classes of ordered pairs of integers, and real numbers as Dedekind sections or equivalence classes of Cauchy sequences or something. Should we take inspiration from those too? Then, for instance, we could do >>> for x in -3: ... print x ... (3, 0) (4, 1) (5, 2) [etc, etc, until interrupted] It doesn't get much more natural than that. :-) I suppose we might also get >>> for x in math.pi: ... print x ... Traceback (most recent call last): File "", line 1, in ? TypeError: iteration over uncountable set (My own preferences, not that anyone asked for them: I always rather liked the range literal proposal, but GvR rejected that. I also like the "for 3 <= i < 10" one, which I think is *beautiful* but maybe slightly too cute.) -- Gareth McCaughan Gareth.McCaughan at pobox.com .sig under construc From tim.one at comcast.net Fri Mar 1 00:03:47 2002 From: tim.one at comcast.net (Tim Peters) Date: Thu, 28 Feb 2002 18:03:47 -0500 Subject: Contributing patches (was Re: urllib and proxy) In-Reply-To: <3c7d2377$1_6@news.newsgroups.com> Message-ID: [Brad Clements] > I think the Python keepers are swamped. I've had a patch pending for a > little over a month, made 3 rounds of changes as requested but now it's > stalled. Yup, it sucks. On the bright side, some patches sit over a year . > There are a lot more patches older than mine, so I'll just wait. Don't > get discouraged if your patch sits for a while. I don't know what can be done about this. Outside of Martin v. Loewis and Michael Hudson, and even less so most days some of the PythonLabs crew, it seems that nobody routinely looks at the bugs, patch or feature request trackers. It's particularly discouraging for patches because, against initial hopes, nobody "out there" *tries* them and reports back on their experience. So, in practice, nothing much happens on these fronts day to day except work on critical bugs. Then again, that's probably a good thing to people who fear change . this-kind-of-bottleneck-needs-a-bigger-bottle-ly y'rs - tim From James_Althoff at i2.com Fri Mar 1 02:06:54 2002 From: James_Althoff at i2.com (James_Althoff at i2.com) Date: Thu, 28 Feb 2002 17:06:54 -0800 Subject: Status of PEP's? Message-ID: [David Eppstein] > I would argue with the "without success" opinion you express. > I still like > for lower_bound <= var < upper_bound > (or similar three-way comparisons, with middle argument of > comparison required to be a variable), in parallelism with the current > "for var in seq" with first argument of "in" required to be a variable. > I guess we haven't made it into a PEP for the BDFL to rule on, if that's > your measure of success, but the only arguments I can remember seeing > against it are (1) some people view "in" as a keyword integrally attached > to "for" rather than part of an expression, and don't like for loops without > "in", and (2) this isn't sufficiently terse for those situations where you > want an integer range outside of a for loop. Am I misinterpreting the > previous discussion? I think this comment illustrates that a PEP would, in fact, be useful as a way to focus discussion on this specific approach to dealing with integer intervals. For example, one problem I had when playing with an experimental implementation of the "middle argument" variant mentioned above is that the specific relational operators are tied to the values of the bounds. If you want to iterate from the smaller value (up) to the larger value you write: for 1 <= var < 5: whereas if you want to iterate from the larger value (down) to the smaller value you have to turn things around and write: for 5 > var >= 1: which all looks very nice when you are dealing with literal constants. But suppose you have variables for the bounds, "start" and "end"? Let's say I have a function def doSomethingFromTo(start,end): The function has to test to see which of "start" and "end" is the smaller value in order to know whether to execute a for-loop with "<" or a for-loop with ">" (and the code specified in each separate for-loop has to be written redundantly). I found this to be awkward. Another issue that I have is that the syntax does not work outside of a for-loop header. I want to be able to create integer intervals anywhere in my code, not just in the header of a for-loop. If a large-scale change (that includes new syntax) is to be made in Python to handle general intervals, I would much rather see an approach that does not have these drawbacks. Other issues might surface if there were a proper PEP and discussion of this specific suggestion. Jim From cliechti at gmx.net Fri Mar 1 02:23:01 2002 From: cliechti at gmx.net (Chris Liechti) Date: 1 Mar 2002 02:23:01 +0100 Subject: Can python handle operating a modem? References: Message-ID: "G. Willoughby" wrote in news:a5ltoj$m59$1 @newsg2.svr.pol.co.uk: > Can python handle operating a modem? i.e. can i say, lift the hook > on the line to see if there is a dial tone? and test this? are > there any modules available for this? two days ago i wrote a program that wait untils it sees a special window and then dials the phone to call me (the pc is in the basement doing some work and i don't want to wait there...). i used my lib: http://pyserial.sf.net and then i sent out "AT" commands. -- Chris From eppstein at ics.uci.edu Fri Mar 1 02:24:40 2002 From: eppstein at ics.uci.edu (David Eppstein) Date: Thu, 28 Feb 2002 17:24:40 -0800 Subject: Status of PEP's? References: Message-ID: In article , James_Althoff at i2.com wrote: > Another issue that I have is that the syntax does not work outside of a > for-loop header. I want to be able to create integer intervals anywhere in > my code, not just in the header of a for-loop. [x for 3 <= x < 10] or, for a slightly more complicated example: yesterday I wanted to iterate over powers of two: [1L << x for 0 <= x < 1000] -- David Eppstein UC Irvine Dept. of Information & Computer Science eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/ From tim.one at comcast.net Fri Mar 1 02:36:48 2002 From: tim.one at comcast.net (Tim Peters) Date: Thu, 28 Feb 2002 20:36:48 -0500 Subject: Status of PEP's? In-Reply-To: Message-ID: [Gareth McCaughan] > ... > (My own preferences, not that anyone asked for them: > I always rather liked the range literal proposal, but > GvR rejected that. I did too -- until I applied the patch and used it for a couple hours. That's part of how it ended up getting rejected; another part was that the patch author confessed he didn't really care for it either. One annoyance was that for i in [0:len(a)]: was actually more clumsy to type than for i in range(len(a)): and even after two intense hours I just couldn't stop from writing it for i in [len(a)]: instead -- which also has a meaning, but not one I had in mind. Negative bang for the buck isn't Pythonic, at least not when we can help it. > I also like the "for 3 <= i < 10" one, which I think is *beautiful* > but maybe slightly too cute.) I'd rather iterate over i than over 3 . From pedronis at bluewin.ch Fri Mar 1 02:25:28 2002 From: pedronis at bluewin.ch (Samuele Pedroni) Date: Fri, 1 Mar 2002 02:25:28 +0100 Subject: Status of PEP's? References: <3c7d8f26_3@news.bluewin.ch> Message-ID: <3c7edb7f_3@news.bluewin.ch> > von Neumann didn't invent his construction of the ordinals > because it was obviously the right thing, or because it > was natural. He did it because it was simple. When what > you're doing is laying foundations for mathematics, > that counts for a lot. But that's not what Python is about. > > Go and look at a set theory textbook that describes that > construction of the natural numbers. It's a good guess that > within a few pages they will also have defined integers > as equivalence classes of ordered pairs of natural numbers, > rationals as equivalence classes of ordered pairs of integers, > and real numbers as Dedekind sections or equivalence classes > of Cauchy sequences or something. Should we take inspiration > from those too? Then, for instance, we could do > No. But anyway I don't want to enter a debate around mathematical taste (because btw it would be irrelevant here ). I'm guilty, especially because I have used and stretched the word natural that for mathematicians have very peculiar meanings, but as I said in another post, my insight was not particularly against or in favor. Just a datapoint. regards, Samuele Pedroni. PS: I have a Master in Mathematics. From db3l at fitlinxx.com Fri Mar 1 02:42:18 2002 From: db3l at fitlinxx.com (David Bolen) Date: 28 Feb 2002 20:42:18 -0500 Subject: win32+popen4 References: <$4LupWAmqsf8Ew0o@jessikat.fsnet.co.uk> Message-ID: Robin Becker writes: > What's the correct way to give a command to popen4 under win32 when the > command/arguments may have spaces in it. EG I want to use > > "c:\program files\dimbo\bongo.exe" "c:\program files\dumbo\my file.dat" Are you including the quotes in your call to popen4? E.g.: os.popen4(r'"c:\program files\dimbo\bongo.exe" "c:\program files\dumbo\my file.dat"') And if, so which version of Windows are you using? I thought there might have been an issue under Win9x platforms with losing quoted information on the way to using the helper module w9xpopen, but a quick Google search didn't show up anything, so I may be mis-remembering. However, if you are on a 9x platform, and quoting the command just as you want the command interpreter to see it on the command line doesn't work, you might just want to revert to using the short (non-space) version of the name. So in your example you would replace "program files" with "progra~1" (or whatever it may be in the unlikely event it's different than that). -- -- David -- /-----------------------------------------------------------------------\ \ David Bolen \ E-mail: db3l at fitlinxx.com / | FitLinxx, Inc. \ Phone: (203) 708-5192 | / 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \ \-----------------------------------------------------------------------/ From tdelaney at avaya.com Fri Mar 1 02:45:28 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Fri, 1 Mar 2002 12:45:28 +1100 Subject: Status of PEP's? Message-ID: > From: Samuele Pedroni [mailto:pedronis at bluewin.ch] > > PS: I have a Master in Mathematics. Burn him! Tim Delaney From aahz at panix.com Fri Mar 1 02:50:11 2002 From: aahz at panix.com (Aahz Maruch) Date: 28 Feb 2002 17:50:11 -0800 Subject: listing threads? References: Message-ID: In article , maximilianscherr wrote: > >in the docs theres the information, that i can list all active >threads with threading.enumerate(), but i always just get the >Mainthread displayed in the interpreter console. DON'T DO THAT. I'm serious. You really do NOT want to use threading.enumerate(); you'll only confuse yourself. I've pointed you at my web page on threading; is there some reason you haven't read it, or is there something you don't understand? -- --- Aahz <*> (Copyright 2002 by aahz at pobox.com) Hugs and backrubs -- I break Rule 6 http://www.rahul.net/aahz/ Androgynous poly kinky vanilla queer het Pythonista "He's Quebecois. He puts mayonnaise on *everything*." --siobhan at virulent.org From clarence at netlojix.com Fri Mar 1 02:53:11 2002 From: clarence at netlojix.com (Clarence Gardner) Date: Fri, 01 Mar 2002 01:53:11 GMT Subject: mime multipart messages References: Message-ID: In article , Glenn Stauffer writes: > I'm using the MimeWriter module to attach a file, submitted through an html > form, to an email message. When I do this and send mail to a unix machine > and read the mail with mutt or kmail, the file is attached to the message as > I would expect. However, when the message is opened on a Mac or Windows > machine, the file is mixed into the body of the message. > > This is the code I use to construct the message: > > ------------------------------------------------------------------------------- > > message = StringIO.StringIO() > writer = MimeWriter.MimeWriter(message) > writer.addheader('Subject', mail_subject) > writer.startmultipartbody('mixed') > > part=writer.nextpart() > body = part.startbody('text/plain') > body.write(msgbody) > > part=writer.nextpart() > part.addheader('Content-Type','application/mixed') > part.addheader('Content-Transfer-Encoding', 'base64') > part.addheader('Content-Disposition','attachment; filename=%s' % > form['file'].filename) > body = part.startbody('application/binary') > base64.encode(open(tmpfile,'rb'), body) > > writer.lastpart() > > ------------------------------------------------------------------------------- > > This is how the file looks when someone opens it with Eudora on a Windows PC: > > --130.58.64.30.99.29450.1014921136.814.11340 > Content-Type: text/plain > > > --130.58.64.30.99.29450.1014921136.814.11340 > Content-Type: application/binary > Content-Type: application/mixed > Content-Transfer-Encoding: base64 > Content-Disposition: attachment; filename=README > > PT09PT09PT09PT09PT09PT09PT0NClRoZSB4bWxycGNsaWIgbW9kdWxlDQo9PT09PT09PT09PT09 > PT09PT09PQ0KDQpUaGlzIGtpdCBjb250YWlucyBhIFB5dGhvbiBpbXBsZW1lbnRhdGlvbiBmb3Ig > > ------------------------------------------------------------------------------- > > Anyone have any thoughts on what I'm doing wrong or where to look to figured > this problem out? > > Thanks, > > Glenn > -- Clarence Gardner Software Engineer NetLojix Communications clarence at netlojix.com From tim.one at comcast.net Fri Mar 1 00:54:46 2002 From: tim.one at comcast.net (Tim Peters) Date: Thu, 28 Feb 2002 18:54:46 -0500 Subject: Status of PEP's? In-Reply-To: Message-ID: [Delaney, Timothy] > ... > Are the following two equivalent though? Not necessarily, but the possible difference isn't where you think: > if 1 in obj: > pass > > if 1 in iter(obj): > pass > > i.e. is iter(obj) called implicitly in the first case? Maybe. First type(obj) is checked to see whether it implements __contains__ (at the C level, whether obj->ob_type->tp_as_sequence->sq_contains is reachable and non-NULL). If it is, iter() gets involved if and only if the __contains__ method decides to use iter() (and, for example, dicts certainly do not). If type(obj) doesn't implement __contains__, then "in" tickles iter(obj) repeatedly. From tdelaney at avaya.com Fri Mar 1 03:04:37 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Fri, 1 Mar 2002 13:04:37 +1100 Subject: Status of PEP's? Message-ID: > From: Tim Peters [mailto:tim.one at comcast.net] > [Delaney, Timothy] > > ... > > Are the following two equivalent though? > > Not necessarily, but the possible difference isn't where you think: > > > if 1 in obj: > > pass > > > > if 1 in iter(obj): > > pass > > > > i.e. is iter(obj) called implicitly in the first case? > > Maybe. First type(obj) is checked to see whether it > implements __contains__ > (at the C level, whether obj->ob_type->tp_as_sequence->sq_contains is > reachable and non-NULL). If it is, iter() gets involved if > and only if the > __contains__ method decides to use iter() (and, for example, > dicts certainly > do not). If type(obj) doesn't implement __contains__, then > "in" tickles > iter(obj) repeatedly. That's pretty much what I thought - I was assuming the case that __contains__ wasn't defined. It answers the real question, which was "In the general case, is '1 in iterable' a valid expression?". The answer is "Yes, but you can do something to prevent it." Tim Delaney From huaiyu at gauss.almadan.ibm.com Fri Mar 1 02:22:47 2002 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Fri, 1 Mar 2002 01:22:47 +0000 (UTC) Subject: map-like function on dict values? References: Message-ID: On 1 Mar 2002 00:03:38 +0100, Carel Fellinger wrote: >Skip Montanaro wrote: >... >> Don't assume for loop iteration is your only culprit... ;-) List creation >> overhead can be as big a problem. I added another test function called iter > >yep, see my other posting:) Thank you both for 1) convincing me to install 2.2 (even the same algorithm speeds up 6-7%) 2) altogether speeding it up seven times over my initial version >Ah a new contestent, double fun, better algoritme better timing (linux >too), but the real iter still wins, although by a very slight margin:) >iter 10.95 >iteriteritems 10.43 >iteritems 52.15 >mapvalue 12.88 They are very similar, to say the least. In any case, the remainder time seems mostly function call overhead. Here's my result (also linux). def emptyloop(f, d): for i in xrange(len(d)): pass def emptyloopcall(f, d): for i in xrange(len(d)): f(None) emptyloop 0.67 emptyloopcall 2.39 iter 2.87 iteriteritems 2.94 iteritems 18.63 mapvalue 3.94 Huaiyu From joekm at earthlink.net Fri Mar 1 03:03:07 2002 From: joekm at earthlink.net (Joe) Date: Fri, 01 Mar 2002 02:03:07 GMT Subject: problems with photoimage and tkinter References: <3c7e5639$1@buckaroo.cs.rit.edu> Message-ID: <3c7ee06c.621416@news.earthlink.net> On Thu, 28 Feb 2002 11:27:36 -0500, "Keith Jones" wrote: >Eric, > >Thanks for the info; I'm glad I'm not just losing my mind. Btw, I'm Keith, I >was using my brother's account to access the newsgroup last night. Again, >thanks. I can't wait to get home to try to get this sucker to work. :) > > > >Keith > > > > BTW - just went through a similar PhotoImage thing myself. The FAQ at www.python.org (#4.69 I think) mentions something similar as well - although the author (Frederick Lundh (?) ) says it is not a bug. It is frustrating though. If you search Google (I tried Tkinter PhotoImage bug), you find some stuff as well. From bp at sam.localdomain Fri Mar 1 03:13:41 2002 From: bp at sam.localdomain (Bob Parnes) Date: Fri, 01 Mar 2002 02:13:41 -0000 Subject: Mod-python problem References: Message-ID: On 28 Feb 2002 07:34:08 -0800, Alan Kennedy wrote: >bp at sam.localdomain (Bob Parnes) wrote in message >> Just in case I am missing something obvious, the following >> is my test code, for a linux system: > > >So, the corrected version, which works for me, is as follows > ># Script starts here > >from mod_python import util >from mod_python import apache > >class clTest: > def cltest(self, req, formDict): > res = '' > res += '' > res += '
Welcome to the \ > mod-python class test' > res += '
keys: %s' \ > % formDict.keys() > res += '
' > res += '
Name name="name">' > res += '
Phone name="phone">' > res += '
\ > ' > res += '
' > return res > >def handler(req): > formDict = util.FieldStorage(req) > cl = clTest() > req.content_type = "text/html" > req.send_http_header() > req.write(cl.cltest(req, formDict)) > return apache.OK > ># Script ends here > >Hope that works. Al, Thanks for the detailed response. Your comments were easy to understand. Furthermore your corrected version works for me too, under the conditions you had assumed. I learned a lot from this. The only trouble is that I had forgotten about my httpd.conf file. The relevant lines are: AddHandler python-program .py PythonHandler mod_python.publisher This was the reason I used main() instead of handler(); in the url window I typed in "test.py/main" and got the table but no response from FieldStorage(). When I changed the third line to "PythonHandler test", your corrected version works. When I do not change the line and type 'test.py/handler' in the url window, the browser renders a table but also additional lines showing an error. The source of the rendered display is as follows: ---------------------------------------------------------------------
Welcome to the mod-python class test
keys: []
Name
Phone
HTTP/1.1 200 OK Date: Fri, 01 Mar 2002 01:34:22 GMT Server: Apache/1.3.23 (Unix) Debian GNU/Linux mod_python/2.7.6 Python/2.1.2 Connection: close Transfer-Encoding: chunked Content-Type: text/html; charset=iso-8859-1 200 OK

OK

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, bp at sam and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

------------------------------------------------------------------------- No lines concerning the error were printed in the error log. But it seems to me that, as a result of the error, the http header and "OK" from "return apache.OK" were simply displayed as text. Are publisher and FieldStorage() incompatible, or am I misusing them? Knowing what I know now, I can probably get along without publisher, but I am accustomed to placing several scripts in one directory. Bob -- Bob Parnes rparnes at megalink.net From pan-news at asheeshenterprises.com Fri Mar 1 03:14:16 2002 From: pan-news at asheeshenterprises.com (Asheesh Laroia) Date: Fri, 01 Mar 2002 02:14:16 GMT Subject: Regular expression problem References: Message-ID: Actually, I think this is the most elegant solution I've seen so far. Good thinking; I forgot to "Use the Source," as some put it. Only one problem: the parser still balks on embedded tags, like: <@Trap Body text:

> becomes > It leaves an extra '>' character at the end. Any suggestions? I can write a simple workaround for something like this, but it seems like it should work "the right way." Thanks for everything! -- Asheesh. On Thu, 28 Feb 2002 01:17:11 -0500, Sean 'Shaleh' Perry wrote: > On 28-Feb-2002 Asheesh Laroia wrote: >> I've been trying to use sgmllib, actually, to delete all the other >> tags. >> >> It just doesn't handle the <@ [...] > condition well. It refuses to >> parse it, treating it as text. >> >> > The reason is this: > > starttagopen = re.compile('<[>a-zA-Z]') tagfind = > re.compile(r'[a-zA-Z][-_.a-zA-Z0-9]*') > > near the top of sgmllib.py. > > Changing them in your code will allow the parser to understand the tag. > However there is another problem which requires more work. When a tag > is found the parser tries to run 'start_' + tag. start_ at Trap() is not a > valid python name. You could redefine the function which calls the > handlers so that it looks for perhaps start_atTrap(). This would allow > you to use the SGMLParser for all of your parsing needs, but may also be > overkill for the problem. From robinjim at earthlink.net Fri Mar 1 03:18:01 2002 From: robinjim at earthlink.net (robin and jim) Date: Fri, 01 Mar 2002 02:18:01 GMT Subject: super confused ! Message-ID: I'm confused about the behavior of "new-style" classes in Python 2.2. Here is a sample session that illustrates my confusion. >>> class Int_a(int): ... def __init__(self, spec): ... super(Int_a, self).__init__(spec) ... >>> Int_a(1) 1 >>> class Int_b(Int_a): ... def __init__(self, spec): ... super(Int_b, self).__init__(spec) ... >>> Int_b(2) 2 >>> class Int_c(Int_a): ... def __init__(self): ... super(Int_c, self).__init__(99) ... >>> Int_c() 0 >>> class Int_d(Int_a): ... def __init__(self): ... Int_a.__init__(self, 99) ... >>> Int_d() 0 Why are Int_c() and Int_d() zero (the default for int()) rather than 99? How can I make them 99? Thanks for your interest. From joshm at taconic.net Fri Mar 1 03:20:15 2002 From: joshm at taconic.net (Joshua Muskovitz) Date: Thu, 28 Feb 2002 21:20:15 -0500 Subject: python-list, FOR YOUR PRIVATE EYES ONLY !!!! References: <3c7f623f.7801758@127.0.0.1> Message-ID: <3c7ee303$1_2@corp.newsgroups.com> > Damn. And here I thought I was getting an invitation to join the PSU. You are. This is just one of the perks, along with -----= 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 tim.one at comcast.net Fri Mar 1 01:20:15 2002 From: tim.one at comcast.net (Tim Peters) Date: Thu, 28 Feb 2002 19:20:15 -0500 Subject: PEP 276 (was Re: Status of PEP's?) In-Reply-To: Message-ID: [Carel Fellinger] > you being such a heavy weight that I fear > Guido might be lured into thinking this to be a good idea > that I felt compelled to react in public. [James_Althoff] > Well, thanks (I think ), but I can assure you that I hold no > special brownie points and have zero ability to "lure" Guido (or anyone > on the Python team) into anything. So, no need to lose any sleep over > that one. (On the other hand, if anyone knows *how* to "lure" any of > them, be sure to let me know ). Well, I'm particularly swayed by posters who have a "" key and know how to use it. Still, my take remains what it was at the start: it isn't even half as disgusting as most people will say it is . some-people-don't-even-like-listcomps-ly y'rs - tim From joshm at taconic.net Fri Mar 1 03:32:12 2002 From: joshm at taconic.net (Joshua Muskovitz) Date: Thu, 28 Feb 2002 21:32:12 -0500 Subject: Want to monitor process.. References: <87550ef1.0202272315.15779bbd@posting.google.com> <97ae44ee.0202280901.3153bdfc@posting.google.com> Message-ID: <3c7ee5d0_4@corp.newsgroups.com> > I'm chuckling to myself. This is exactly what I'm doing at the moment > too and it sucks. I'm so glad you asked this question, Haeyoung, and > described it so well :) I described a solution about six weeks ago (with code!). Here's the link (or search on google yourself for SingleInstance and Muskovitz): http://groups.google.com/groups?q=SingleInstance+Muskovitz+group:comp.lang.p ython Basically, your app creates a lockfile, and periodically touches it. An external app can check the timestamp on the file, and if it is too old, then your process has hung up and could be killed/restarted. Alternately, you can stick your app directly in cron. When a new instance starts up, it can check the lock and if things are ok, then it can just kill itself. The code works on NT and Solaris. I haven't tried other platforms. -- # Joshua Muskovitz # joshm at taconic.net def lyyrs(sig): return '-'.join(sig.split()+["ly y'rs"]) lyyrs('Hire me! I need the work!') -----= 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 akakakhel at attbi.com Fri Mar 1 03:56:23 2002 From: akakakhel at attbi.com (Ali K) Date: Fri, 01 Mar 2002 02:56:23 GMT Subject: images References: Message-ID: How do i do this with Tkinter? "Ricky" wrote in message news:a5f093$6mqk7$1 at ID-12869.news.dfncis.de... > If you want to display a pic, you must use one GUI toolkit. If your program > is not very explicit, you may use PIL+Tkinter. > > "Ali K" wrote in message > news:iGhe8.20623$vP.68360 at rwcrnsc51.ops.asp.att.net... > > I would like to know how to show a picture in Python so that it shows up > on > > my window. > > > > Please Reply. > > > > Thank You. > > > > Ali K. > > > > > > From skip at pobox.com Fri Mar 1 04:19:20 2002 From: skip at pobox.com (Skip Montanaro) Date: Thu, 28 Feb 2002 21:19:20 -0600 Subject: map-like function on dict values? In-Reply-To: References: Message-ID: <15486.62264.311324.231880@12-248-41-177.client.attbi.com> >> which relies on 2.2's new "for k in dict" capability to completely >> avoid list creation. Carel> Ah a new contestent, double fun, better algoritme better timing Carel> (linux too), but the real iter still wins, although by a very Carel> slight margin:) >> iter 6.69 >> iteritems 28.36 >> mapvalue 8.12 Carel> iter 10.95 Carel> iteriteritems 10.43 Carel> iteritems 52.15 Carel> mapvalue 12.88 Not on my system: iter 6.73 iteritems 28.71 iteriteritems 7.28 mapvalue 8.19 :-) I'm using 2.3a0 (aka CVS), and compile with -O3 -minline-all-stringops -fomit-frame-pointer Skip From skip at pobox.com Fri Mar 1 04:21:51 2002 From: skip at pobox.com (Skip Montanaro) Date: Thu, 28 Feb 2002 21:21:51 -0600 Subject: ASV module, CVS modules In-Reply-To: <61ff32e3.0202281525.3e9bb102@posting.google.com> References: <61ff32e3.0202281525.3e9bb102@posting.google.com> Message-ID: <15486.62415.486257.652769@12-248-41-177.client.attbi.com> ron> file = open(input_file, "rb") ron> IOError: invalid argument: rb ron> I get a similar message from CSV module. Anyone use either of these ron> and can tell me what's wrong? Sounds to me like your builtin open function is hosed somehow. Opening files using "rb" works for me: >>> f = open("cities.csv", "rb") >>> -- Skip Montanaro (skip at pobox.com - http://www.mojam.com/) From db3l at fitlinxx.com Fri Mar 1 04:34:36 2002 From: db3l at fitlinxx.com (David Bolen) Date: 28 Feb 2002 22:34:36 -0500 Subject: listing threads? References: Message-ID: aahz at panix.com (Aahz Maruch) writes: > DON'T DO THAT. I'm serious. You really do NOT want to use > threading.enumerate(); you'll only confuse yourself. I've pointed you > at my web page on threading; is there some reason you haven't read it, > or is there something you don't understand? I wouldn't go all that far. Clearly you have to understand the nature of the snapshot that threading.enumerate() returns with respect to the asychronous nature of threads (which of course is what was confusing the OP, since the example had a thread that barely got off the ground before exiting). But I don't see that enumerate() is in and of itself a bad method, when used properly - certainly not something to warrant such a sweeping statement. We certainly use it in some of our applications as a passive way to get a snapshot of thread activity and it works fine. -- -- David -- /-----------------------------------------------------------------------\ \ David Bolen \ E-mail: db3l at fitlinxx.com / | FitLinxx, Inc. \ Phone: (203) 708-5192 | / 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \ \-----------------------------------------------------------------------/ From jason at jorendorff.com Fri Mar 1 04:35:56 2002 From: jason at jorendorff.com (Jason Orendorff) Date: Thu, 28 Feb 2002 21:35:56 -0600 Subject: PEP 263 comments In-Reply-To: Message-ID: Piet van Oostrum wrote: > JO> Advantage: simple, universal, easy, similar to what Java does. > > Java does accept iso-latin-1 files as input. In fact on my machine (Mac > OSX) it doesn't even accept utf-8 files with the utf-8 signature. And > strings containing utf-8 are interpreted as just 8-bit characters, meaning > every byte is a character. Oh! Yes, it works this way on Windows, too. javac assumes source files are latin-1, and System.out.println() encodes output in latin-1. Odd, because Java assumes UTF-8 everywhere else. Somehow I missed this before (I guess because UTF-8 data slips through intact). Scratch that, then. > JO> No confusion about embedded 0x22 bytes in strings. Also, > JO> stylistically I prefer not to have a document specify its own > JO> encoding, or for comments to affect the meaning of a source > JO> file. > > Which 0x22 bytes? I'm referring to this paragraph in Martin's original post: The only problem with this approach is that encodings where " or ' could be the second byte of a multi-byte character cannot be supported as a source encoding. Python supports no such encoding in the standard library at the moment, anyway, so this should not be a problem. \x22 is a double-quote mark. Martin is a little off on the last bit, though; UTF-16 can produce \x22 bytes. ## Jason Orendorff http://www.jorendorff.com/ From andrew-pythonlist at puzzling.org Fri Mar 1 04:48:57 2002 From: andrew-pythonlist at puzzling.org (Andrew Bennetts) Date: Fri, 1 Mar 2002 14:48:57 +1100 Subject: Wierd traceback from threading module Message-ID: <20020301034857.GA14419@ritsuko.xware.cx> Here is the entire traceback: """ Unhandled exception in thread: Traceback (most recent call last): File "D:\Python22\lib\threading.py", line 423, in __bootstrap self.__stop() File "D:\Python22\lib\threading.py", line 429, in __stop self.__block.notifyAll() File "D:\Python22\lib\threading.py", line 242, in notifyAll self.notify(len(self.__waiters)) File "D:\Python22\lib\threading.py", line 224, in notify me = currentThread() TypeError: 'NoneType' object is not callable """ I'm not doing *anything* with the threading module except starting a daemonic thread. This traceback occurred as the program was shutting down -- the main thread would probably have already finished. Is this a bug or am I doing something silly? Please CC replies to me, as I'm not currently subscribed to the list/newsgroup. -Andrew. From shriek at gmx.co.uk Fri Mar 1 04:47:26 2002 From: shriek at gmx.co.uk (Stephen) Date: 28 Feb 2002 19:47:26 -0800 Subject: How to have multi-threaded server log to one file ? References: Message-ID: <97ae44ee.0202281947.78dea8cf@posting.google.com> > > [...] how do I get the same Queue object into both MyHandler and > > MyServer in the first place ? [...] Or is this somewhere that a > > global variable Queue object should be used ? > > Try making a separate module that says: > > --------------------------------------------------------------- > # logging.py - used by everyone else that needs to log messages > > import Queue > > # This is the queue object that's used to hold log events. > # LoggingThread knows about it, and the log() function below > # knows about it. No one else is allowed to see it. > _log_queue = Queue.Queue() > > class LoggingThread: > ... > def run(self): > while 1: > message = _log_queue.get() > self.logfile.write(message + '\n') # (or whatever) > > # Kick off the logging thread. > LoggingThread().start() > > def log(msg): > _log_queue.put(msg) > > --------------------------------------------------------------- > > Then your MyHandler and MyServer code can just use the log() > function, like this: > > from logging import log > ... > ... > log("Something happened") > ... > > ## Jason Orendorff http://www.jorendorff.com/ (I thought I'd posted a reply to this but it seems to have got lost.) Thank you Jason, this is such a clear and simple example. It's never occured to me to create the object within the module (in your example, the Queue.Queue instance "_log_queue" within the "log" module) and then access it indirectly through a function (ie. log.log()). I usually end up passing objects around in my code but the method you describe looks like an incredibly good way to avoid this as well as hide complexity. This type of code (having shared objects instantiated within an imported module) looks like something I should employ more often. One of them 'ta-da' moments. Stephen. From sabren at manifestation.com Fri Mar 1 04:52:42 2002 From: sabren at manifestation.com (Michal Wallace) Date: Thu, 28 Feb 2002 22:52:42 -0500 (EST) Subject: super confused ! In-Reply-To: Message-ID: On Fri, 1 Mar 2002, robin and jim wrote: > >>> class Int_c(Int_a): > ... def __init__(self): > ... super(Int_c, self).__init__(99) > ... > >>> Int_c() > 0 > >>> class Int_d(Int_a): > ... def __init__(self): > ... Int_a.__init__(self, 99) > ... > >>> Int_d() > 0 > > Why are Int_c() and Int_d() zero (the default for int()) rather than 99? > > How can I make them 99? use __new__ instead of __init__... Guido explains it in "Unifying types and classes in Python 2.2": http://www.python.org/2.2/descrintro.html#__new__ Cheers, - Michal http://www.sabren.net/ sabren at manifestation.com ------------------------------------------------------------ Give your ideas the perfect home: http://www.cornerhost.com/ cvs - weblogs - php - linux shell - perl/python/cgi - java ------------------------------------------------------------ From aahz at panix.com Fri Mar 1 04:57:53 2002 From: aahz at panix.com (Aahz Maruch) Date: 28 Feb 2002 19:57:53 -0800 Subject: Simple threads (was Re: listing threads?) References: Message-ID: In article , David Bolen wrote: >aahz at panix.com (Aahz Maruch) writes: >> >> DON'T DO THAT. I'm serious. You really do NOT want to use >> threading.enumerate(); you'll only confuse yourself. I've pointed you >> at my web page on threading; is there some reason you haven't read it, >> or is there something you don't understand? > >I wouldn't go all that far. Clearly you have to understand the nature >of the snapshot that threading.enumerate() returns with respect to the >asychronous nature of threads (which of course is what was confusing >the OP, since the example had a thread that barely got off the ground >before exiting). > >But I don't see that enumerate() is in and of itself a bad method, >when used properly - certainly not something to warrant such a >sweeping statement. We certainly use it in some of our applications >as a passive way to get a snapshot of thread activity and it works >fine. I am generally more interested in "practicality over purity". And the fact remains that 99% of the time that someone wants enumerate(), they should have been storing references to thread objects in a list or dict; that way, they're guaranteed to not make a mistake in trying to perform some operation on the main thread. I advocate against enumerate() for the same reasons I advocate against Lock(), Condition(), Event(), and Semaphore(). (I strongly recommend sticking with RLock() and Queue().) Writing correct threaded applications is difficult enough -- KISS, KISS, KISS. -- --- Aahz <*> (Copyright 2002 by aahz at pobox.com) Hugs and backrubs -- I break Rule 6 http://www.rahul.net/aahz/ Androgynous poly kinky vanilla queer het Pythonista "How come we choose from just two people for President but more than 50 for Miss America?" --AEN From greg at cosc.canterbury.ac.nz Fri Mar 1 04:59:23 2002 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Fri, 01 Mar 2002 16:59:23 +1300 Subject: dirwalk.py generator version of os.path.walk References: Message-ID: <3C7EFC9B.AB6029EA@cosc.canterbury.ac.nz> Jim Dennis wrote: > > I guess I'm just wary of recursion, particularly when I've read > that Python doesn't support tail-end recursion. That's only an issue if you abuse recursion for the likes of iterating along a linear list. In languages which optimise tail-recursion, it is common for people to do things like that using recursion, but it would be silly in Python. If, e.g. the list were a million items long, you'd need a million stack frames. But here, the stack is only going to be as deep as the directory hierarchy, which is hardly going to kill you. So, don't just blindly reject recursion -- think about how it applies to the problem at hand! -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand To get my email address, please visit my web page: http://www.cosc.canterbury.ac.nz/~greg From greg at cosc.canterbury.ac.nz Fri Mar 1 05:28:31 2002 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Fri, 01 Mar 2002 17:28:31 +1300 Subject: Status of PEP's? References: Message-ID: <3C7F036F.FF1EF7A9@cosc.canterbury.ac.nz> James_Althoff at i2.com wrote: > > def doSomethingFromTo(start,end): > > The function has to test to see which of "start" and "end" is the smaller > value in order to know whether to execute a for-loop with "<" or a for-loop > with ">" (and the code specified in each separate for-loop has to be > written redundantly). This is no worse than what you would have to do to achieve the same thing using range() or any other existing facility. If I were writing a function like that, I think I'd make the caller responsible for passing the arguments in the right order. But if you really want, you can always sort out the argument order before entering the loop, e.g. if start > end: start, end = end, start for start <= i < end: ... No redundant for-loop code required. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand To get my email address, please visit my web page: http://www.cosc.canterbury.ac.nz/~greg From eppstein at ics.uci.edu Fri Mar 1 05:56:34 2002 From: eppstein at ics.uci.edu (David Eppstein) Date: Thu, 28 Feb 2002 20:56:34 -0800 Subject: Status of PEP's? References: Message-ID: In article , James_Althoff at i2.com wrote: > For example, one problem I had when playing with an experimental > implementation of the "middle argument" variant mentioned above is that the > specific relational operators are tied to the values of the bounds. If you > want to iterate from the smaller value (up) to the larger value you write: > > for 1 <= var < 5: > > whereas if you want to iterate from the larger value (down) to the smaller > value you have to turn things around and write: > > for 5 > var >= 1: > > which all looks very nice when you are dealing with literal constants. But > suppose you have variables for the bounds, "start" and "end"? Let's say I > have a function > > def doSomethingFromTo(start,end): > > The function has to test to see which of "start" and "end" is the smaller > value in order to know whether to execute a for-loop with "<" or a for-loop > with ">" (and the code specified in each separate for-loop has to be > written redundantly). I found this to be awkward. What's wrong with for min(start,end) < var < max(start,end) ? I am assuming you want an open interval because you wrote < and > above. If you want a closed interval, of course, use <=, but I don't think it makes sense to ask for a half-open interval when you don't know which end is which. -- David Eppstein UC Irvine Dept. of Information & Computer Science eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/ From tim.one at comcast.net Fri Mar 1 06:12:45 2002 From: tim.one at comcast.net (Tim Peters) Date: Fri, 01 Mar 2002 00:12:45 -0500 Subject: dirwalk.py generator version of os.path.walk In-Reply-To: <3C7EFC9B.AB6029EA@cosc.canterbury.ac.nz> Message-ID: [Jim Dennis] > I guess I'm just wary of recursion, particularly when I've read > that Python doesn't support tail-end recursion. [Greg Ewing] > That's only an issue if you abuse recursion for the likes of > iterating along a linear list. In languages which optimise > tail-recursion, it is common for people to do things like > that using recursion, but it would be silly in Python. > If, e.g. the list were a million items long, you'd need a > million stack frames. > > But here, the stack is only going to be as deep as the > directory hierarchy, which is hardly going to kill you. > > So, don't just blindly reject recursion -- think about > how it applies to the problem at hand! If I were Jim, I'd continue leaving recursion out of this specific application. An explicit "todo list" trivially supports either breadth-first or depth-first traversal (a choice Jim explicitly mentioned as something he wants to control). Calling it "a stack" is an illusion suffered by those blindly embracing recursion . From greg at cosc.canterbury.ac.nz Fri Mar 1 06:08:35 2002 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Fri, 01 Mar 2002 18:08:35 +1300 Subject: list vs. dict References: <3C7CF0EE.3010009@vscht.cz> <3C7CFAF8.1080108@mxm.dk> <3C7E8D47.21BE30B3@ccvcorp.com> Message-ID: <3C7F0CD3.E70832BB@cosc.canterbury.ac.nz> David Eppstein wrote: > > It would be good if dict.has_key(x,y) > worked without having to double the parentheses I don't have a recent enough Python at my fingertips to check, but I think if (x,y) in dict does the same thing nowadays. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand To get my email address, please visit my web page: http://www.cosc.canterbury.ac.nz/~greg From landshark at verticaladdiction.net Fri Mar 1 06:16:31 2002 From: landshark at verticaladdiction.net (Dave Marotti) Date: Fri, 01 Mar 2002 05:16:31 -0000 Subject: what does this do? (really basic question) Message-ID: Hey, Hopefully this is a really basic question. I'm still in the learning phase, and came across this in a sample program: class Whatever: def __init__(self, user_list, cmd_list, **kw): code.... What does the **kw mean (specifically, the **) ? -dave -- +-----------------------------+----------------------------------------------+ | Dave Marotti | Looking for a Visio alternative for *nix? | | lndshark ! speakeasy net | Kivio : http://thekompany.com/projects/kivio | +-----------------------------+----------------------------------------------+ | I just don't trust anything | I suppose that in a few more hours I will | | that bleeds for 5 days and | sober up. That's such a sad thought. I think | | doesn't die. - Mr. Garrison | I'll have a few more drinks to prepare myself| +-----------------------------+----------------------------------------------+ From chris.gonnerman at newcenturycomputers.net Fri Mar 1 06:27:49 2002 From: chris.gonnerman at newcenturycomputers.net (Chris Gonnerman) Date: Thu, 28 Feb 2002 23:27:49 -0600 Subject: Can somebody kill getpathp for me? Message-ID: <00bb01c1c0e1$d9045940$0101010a@local> In the PC subdir of the Python-2.1.2 build directory is a module called getpathp.c, which sets up the initial sys.path value. It is well known by Python programmers on Windows that the sys.path initialization includes directories plucked from special registry keys... unless you are using the PythonWare version. I thought, great, I can use this (the PythonWare version) to create Python runnables on CD-ROM; but now I discover a fly in the ointment. If the computer already has an installed Python interpreter, the paths set in the registry are added, and BEFORE the paths from the PythonWare PYROOT variable are added. Gah. What I want is a version of either python.exe or python21.dll (whichever contains the offending getpathp.c module) with the registry-probing code disabled. Ideally it should still apply the paths from PYROOT (basically in this case it must). Can anyone help with this? I am experienced in Linux programming but a novice at Win32, and I don't have MSVC in any event. (Yeah, I know, you can build Python with MinGW32, but it's a PITA.) Chris Gonnerman -- chris.gonnerman at newcenturycomputers.net http://newcenturycomputers.net From sjmachin at lexicon.net Fri Mar 1 06:32:06 2002 From: sjmachin at lexicon.net (John Machin) Date: 28 Feb 2002 21:32:06 -0800 Subject: ASV module, CVS modules References: <61ff32e3.0202281525.3e9bb102@posting.google.com> Message-ID: ron at ire.org (ron nixon) wrote in message news:<61ff32e3.0202281525.3e9bb102 at posting.google.com>... > Hello, I'm trying to use either of these two modules ASV by Laurence > Tratt at http://tratt.net/laurie/python/asv/ and CSV by Dave Cole at > http://object-craft.com.au/projects/csv/. I tried both of these and > get this error: > > Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on win32 > Type "copyright", "credits" or "license" for more information. > IDLE 0.8 -- press F1 for help > >>> import ASV > >>> my_data = ASV.ASV() > >>> my_data.input_from_file("c:\test_data.csv", ASV.CSV(), > has_field_names =1) > Traceback (most recent call last): > File "", line 1, in ? > my_data.input_from_file("c:\test_data.csv", ASV.CSV(), > has_field_names =1) > File "C:\PYTHON22\ASV.py", line 222, in input_from_file > file = open(input_file, "rb") > IOError: invalid argument: rb > >>> > > I get a similar message from CSV module. Anyone use either of these > and can tell me what's wrong? > Wow. You have two problems. Bill Gates has one. And one of either you or Dave Cole will get busted real soon now if you keep smoking that stuff :-) To be more explicit: You 1: Don't clutter the root directory of your C: drive with anything other than "necessary" directories, and files other than what Bill & other software providers dump in there. You 2: On Windows, either use forward slashes "c:/test_data.csv" (it works!) -- recommended -- or use raw strings r"c:\test_data.csv" if you must. The problem is that Python's escape handling intervenes; what Bill's software got to see in your case was equivalent to "C:" + a_bloody_tab_character + "est_data.csv" !!! Bill behaving badly: Seems like Bill chucks a wobbly if there is a_bloody_tab_character in a file name. I could be maligning Bill unjustly; could be GvR & Co -- I'll have a look at the Python source in a minute -- but I'd bet a couple of pots of beer that it's down to Bill. You and/or Dave in peril of the law: Last time I saw Dave's module it didn't presume to read files at all, it expected you to read lines and pass them to it one at a time. So either Dave has had a very recent rush of blood or something worse to the head and released unbeknownst to me a file-handling version of his module, or you are gravely mistaken when you assert "I get a similar message from CSV module". Hope this helps, John From eppstein at ics.uci.edu Fri Mar 1 06:33:29 2002 From: eppstein at ics.uci.edu (David Eppstein) Date: Thu, 28 Feb 2002 21:33:29 -0800 Subject: list vs. dict References: <3C7CF0EE.3010009@vscht.cz> <3C7CFAF8.1080108@mxm.dk> <3C7E8D47.21BE30B3@ccvcorp.com> <3C7F0CD3.E70832BB@cosc.canterbury.ac.nz> Message-ID: In article <3C7F0CD3.E70832BB at cosc.canterbury.ac.nz>, Greg Ewing wrote: > I don't have a recent enough Python at my fingertips > to check, but I think > > if (x,y) in dict > > does the same thing nowadays. You're right! Every time I see something like this I like the language design more. -- David Eppstein UC Irvine Dept. of Information & Computer Science eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/ From stephen at xemacs.org Fri Mar 1 06:40:22 2002 From: stephen at xemacs.org (Stephen J. Turnbull) Date: 01 Mar 2002 14:40:22 +0900 Subject: PEP 263 comments References: <87g03lhm3p.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: <87u1s0eth5.fsf@tleepslib.sk.tsukuba.ac.jp> >>>>> "Carel" == Carel Fellinger writes: Carel> Stephen J. Turnbull wrote: Carel> Now that we have your attention, what's your personal Carel> opinion on using something else but ascii (in whatever Carel> encoding:) for the code itself (things like keywords and Carel> variable names). My _very_ personal opinion is that identifiers can be run through an online dictionary, and I'm fortunate to be pretty good at languages, so that's fun. Nor do I do programming for a living, I can afford to concentrate on "fun." My opinion as a teacher is that I'd really like to be able to teach programming to my freshmen with a language that uses Japanese identifiers (including reserved words) and syntax (Japanese is a reverse Polish language). Carel> My Western centered view would be that it would make Carel> reading code harder, but that's probably what the rest of Carel> the world already experiences. For "real-world" use, I mostly agree that sticking to English is better, for code. None of the Japanese programmers I know feel that use of English for identifiers and reserved words hinders them. In fact, some think it may help somewhat, as it allows them to abstract from any connotations that the word may have in natural language. (Note that this implies that second courses in programming should use an English-based language.) There are exceptions, however. I maintain code that implements Japanese input methods in XEmacs, and even native speakers of Japanese sometimes get confused about what certain identifiers drawn from English, or even romanized Japanese, are supposed to mean. On the other hand, edict.el, which implements morphological transformations for dictionary lookup, uses mixed English-Japanese identifiers. The verbs (search, transform, etc) are English; the parts of speech and technical names for transformations are Japanese (ie, ideographs). Nobody (who is competent to understand what the code does) ever makes a mistake. This is a very special case, of course. But you can imagine many cases where an organization has internal practices that would best be described in native vocabulary. Then it's a tradeoff between short-term maintainability and long-term internationalizability. Carel> I even try to stick to English in my comments, just in case Carel> some foreignor might have to look at it:) If it weren't for the "groetjes, carel" in your .sig, I'd not be able to say with confidence you're not a native English-speaker. Despite the excellent English educational system, I cannot say the same for Indians in general. Most are sufficiently fluent that your practice would make sense, but many are not. And Japanese are legendarily bad at English. A correct comment in an illegible character set is harmless, although perhaps frustrating; an incorrect one that you can read is dangerous. So I'd have to say that except for the very worst cases, there are benefits to having code in English, or near-English, vocabulary. But comments should be written in a language you can use for teaching. -- Institute of Policy and Planning Sciences http://turnbull.sk.tsukuba.ac.jp University of Tsukuba Tennodai 1-1-1 Tsukuba 305-8573 JAPAN Don't ask how you can "do" free software business; ask what your business can "do for" free software. From daniels at mindspring.com Fri Mar 1 07:05:12 2002 From: daniels at mindspring.com (Alan Daniels) Date: 28 Feb 2002 22:05:12 -0800 Subject: Status of PEP's? References: Message-ID: <5d283efe.0202282205.7049ff32@posting.google.com> [snippety doo dah, snippety ay...] "Delaney, Timothy" wrote in message news:... > > The two lines... > > for i in 5: print i > > for i in 5, 6: print i > > ...would behave differently under the proposal. > > They behave differently now. One is a syntax error, the other isn't. Well duh, that's my point. It *should* be an error. "for i in 5" has no natural meaning, and grafting one onto it just to save having to type "xrange" would be, in my opinion, a detriment to the language. > For the record (I've said this before), I like the idea of integers being > iterable (and I'm not a set theory wonk). That's fine if you like the idea. I don't. The only validations I've seen for it are obscure references to set theory, or the vague notion that it looks neat since it would make Python read more like Haskell (or insert whatever favorite research langugage here). I have yet to see any meaningful explanation on how it fixes some gap in Python, or improves it other than saving the need to type the word "xrange". While I'm at it, two problems with it that I haven't yet seen addressed: 1) If you have a class that defines both __int__ and __getitem__ methods, and iterate over an instance of it, which method "wins" comes iteration time? The usual, or the "for i in 5" trick? Maybe this is covered in PEP 276. I've read through it once when it was first introduced and didn't see any mention on how this would be handled. I'd read it through again, but it's late and frankly reading it makes my skin crawl. 2) Anyone new to the language will wonder exactly why it is that they can iterate over ints, strings, tuples, lists, dictionaries, files, generators, and indeed, any class instance that implements an iterable interface... ...but not floats. Hey, if "for i in 5" means something, then obviously "for i in 5.0" should mean something too, right? That's what a newbie will think, and what good reason answer will anyone be able to give them? > ...an integer will not be an iterator. An integer will be > iterable... Again, my point. As I've come to think of it, the whole point of "iterating" is that the programmer is walking through a collection: A tuple is a collection, naturally. So is a list. A string is, umm, a collection of characters (Cough). A file is a collection of lines, mostly, if you squint at it right. A dictionary is a collection of keys, where each key maps to a value. An class instance can be a collection, as long as it acts like one. I can NEVER bring myself to see an integer as a collection, not outside of a lecture on number theory, anyway. Sorry to rant, but this is the only idea for Python I've seen in a VERY long time, since the 1.5.2 days, where rather than capturing my interest and giving me something to contemplate, just strikes me as ugly, and stays ugly no matter how long I look at it. From store_li at sina.com Fri Mar 1 07:04:48 2002 From: store_li at sina.com (Ricky) Date: Fri, 1 Mar 2002 14:04:48 +0800 Subject: Can use python to play MP3 file? References: Message-ID: Thank you for you all! I means I want to play a MP3 stream using a local MP3 player, while, I'd like to play with transfer stream not download the whole file to my hard disk and play it. now, what shall I do? download a special application or use a special proctor which some thing like http:// news://? Thank you! "Tim Hammerquist" wrote in message news:slrna7tdgp.113.tim at vegeta.ath.cx... > Ricky graced us by uttering: > > I hear that PHP can online play MP3 file. Is there any method that > > can make me play MP3 by using Python CGI? > > If you mean an MP3 stream server written in Python, try edna > . It will serve MP3s in a stream to the client > computer. (NB: it's up to the client to "play" the MP3, often through > MIME associations in the browser.) > > If you mean you want an MP3 player written in Python, well, I don't > suggest it. Processing MP3 data is very processor intensive and is > often thought best accomplished with a compiled C program. However, > cymbaline is a Python frontend > to the (very pervasive) mpg123 MP3 player. > > You don't mention which OS, so I should mention, this is from a linux > perspective. edna might very well work on Windows. > > HTH > Tim Hammerquist > -- > $ echo pizza > /dev/oven From gjlap at yahoo.com Fri Mar 1 07:10:41 2002 From: gjlap at yahoo.com (Gil) Date: 28 Feb 2002 22:10:41 -0800 Subject: python and eroaster Message-ID: <1eed326b.0202282210.2ba54f24@posting.google.com> I've installed eroaster-2.0.11-0.7.noarch.rpm with no problem on my RedHat 7.1 box. I chose noarch because it seemed to be the only stable version that wasn't i586 or i686. I used the 'extra' verbose switch with rpm and it gave a complete run down of the install. It's all there. But when I try to run it, bash: /usr/bin/eroaster: No such file or directory It even finds the dir! The executable shows up in kde with the proper permissions but not as an icon of a gear but as a piece of paper with a question mark on it. Hmmm, something not right here ;-) I'm running Python2.2 and it gets along OK with my Pygame stuff. Thanks in advance for any help in this matter. -Gil From shalehperry at attbi.com Fri Mar 1 07:19:25 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Thu, 28 Feb 2002 22:19:25 -0800 (PST) Subject: what does this do? (really basic question) In-Reply-To: Message-ID: On 01-Mar-2002 Dave Marotti wrote: > Hey, > > Hopefully this is a really basic question. I'm still in the learning phase, > and came across this in a sample program: > > class Whatever: > def __init__(self, user_list, cmd_list, **kw): > code.... > > What does the **kw mean (specifically, the **) ? > the kw is a nmemonic for 'keyword'. >>> def foo(**kw): ... print kw ... >>> foo(a=3, b=6, c='Sean') {'b': 6, 'c': 'Sean', 'a': 3} >>> foo(c='David', a=42, b=25) {'b': 25, 'c': 'David', 'a': 42} the ** syntax means 'take every argument that was not matches elsewhere and store it in a dictionary. The key will be the variable name and the value will be its value'. So self, use_list, and cmd_list will get their values and then kw gets the rest. >>> def bar(name, **kw): ... print name ... print kw ... >>> bar('Sean', a=1,b=2,c=3) Sean {'b': 2, 'c': 3, 'a': 1} >>> def wuz(name, age): ... print name ... print age ... >>> wuz(age=25, name='Lesley') Lesley 25 Note the key=value syntax works even without the **kw magic. The advantage of using the key=value syntax is that it makes functions with several arguments easier to call without reading the docs. This is often handy for things like GUI toolkits and network code: win = MakeWindow(title="My Window", width=100, height=200, x=34, y=67) or socket = Network.Connect(url="http://www.python.org", keepalive=1, port=80) From tim.one at comcast.net Fri Mar 1 07:23:59 2002 From: tim.one at comcast.net (Tim Peters) Date: Fri, 01 Mar 2002 01:23:59 -0500 Subject: Can somebody kill getpathp for me? In-Reply-To: <00bb01c1c0e1$d9045940$0101010a@local> Message-ID: [Chris Gonnerman] > In the PC subdir of the Python-2.1.2 build directory is a module > called getpathp.c, which sets up the initial sys.path value. It > is well known by Python programmers on Windows that the sys.path > initialization includes directories plucked from special registry > keys... unless you are using the PythonWare version. Or the PythonLabs distribution: while the core installer does set up a registry entry containing "the usual" Python path, it *normally* never uses it. Read the long comment block at the start of getpathp.c, and this time believe that it means what it says . Note that the core installer never sets up what the comment block calls "'application paths' - that is, sub-keys under the main PythonPath registry key". If there aren't any application paths, then, as the rest of the comment block says, the main PythonPath key is ignored, unless a "Python Home" isn't given by a PYTHONHOME envar and can't be guessed from the python.exe path. > I thought, great, I can use this (the PythonWare version) to create > Python runnables on CD-ROM; but now I discover a fly in the ointment. > If the computer already has an installed Python interpreter, the > paths set in the registry are added, and BEFORE the paths from the > PythonWare PYROOT variable are added. AFAIK PythonWare doesn't ship with a custom getpathp.c, and neither does ActiveState, so AFAIK the comment block applies to all Python installations. The "PythonWare PYROOT variable" is news to me, google hasn't heard of it either, and I find no mention of PYROOT in my PythonWare PY21 installation. Setting a PYROOT envar has no visible effect on sys.path when I run under PY21 either. That's a long-winded way of saying I think you must be confused . Have you tried setting PYTHONHOME? If, e.g., I set PYTHONHOME to \Python22, then execute python while *in* my \Python21 directory (these both referring to PythonLabs distros), then Python 2.1.2 comes up with sys.path pointing entirely at Python 2.2 directories. This is insane, but shows that PYTHONHOME works the way getpathp.c says it works. > Gah. > > What I want is a version of either python.exe or python21.dll > (whichever contains the offending getpathp.c module) with the > registry-probing code disabled. If that's what you really want, you'll have to edit getpathp.c and compile your own Python. > Ideally it should still apply the paths from PYROOT (basically in this > case it must). Python doesn't look at any such envar on any platform. Maybe that's why setting PYROOT isn't doing you any good . Try PYTHONHOME. From python at chajadan.net Fri Mar 1 10:47:47 2002 From: python at chajadan.net (chajadan) Date: Fri, 01 Mar 2002 01:47:47 -0800 Subject: wxPython error on import Message-ID: <5.1.0.14.0.20020301014436.00a79ae0@63.118.78.184> I get this error: from wxPython.wx import * SystemError: C:\Code\22\Objects\listobject.c:88: bad argument to internal function Now, there is no C:\Code\22\ anything on my comp, but maybe you guessed that. This error generates with or without the .wx on wxPython I'm on Windows, using python 2.2 and wxPython (Hybrid) for 2.2 hmm.... maybe it's this hybrid thing... any help, as always, gives me less work to do ;) --chajadan From stephen at xemacs.org Fri Mar 1 07:39:42 2002 From: stephen at xemacs.org (Stephen J. Turnbull) Date: 01 Mar 2002 15:39:42 +0900 Subject: PEP 263 comments References: <87g03lhm3p.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: <87pu2oeqq9.fsf@tleepslib.sk.tsukuba.ac.jp> Please note, you are correct---I missed the main point. I'm not going to address that point-by-point, unless you ask. However, it's easy enough to paraphrase my comments to apply to "are we going to mandate UTF-8 for all source code?". The following is a rough counter- proposal to handle the main issues, framed correctly. >>>>> "Martin" == Martin von Loewis writes: Martin> [U]nder the proposed change, Python would refuse to accept Martin> source code if it is not UTF-8 encoded. In turn, code that Martin> has a euc-jp comment in it and is now happily accepted as Martin> source code in the current Python programming language Martin> would be rejected. Fine with me for Elisp. We don't have satisfactory UTF-8 support yet, but will soon. After that there will be no excuses for us, since the editor is the interpreter. This _is_ the direction we're heading. Emacs treats Lisp files the same as any other on initial loading, so we already have hooks in place that could be used to translate. The point is that if XEmacs didn't accept the encoding of a Lisp file, it would be on the user- provided codec to get it right. It's not our problem (except to the extent that we would of course provide such codecs). We're currently working to make codecs available to users in a convenient, consistent way--and Python has the advantage that that part is done! Such a hook probably would be something new in Python, but I don't see that it would be terribly difficult to implement. Martin> Will you reject a source module just because it contains a Martin> latin-1 comment? >> That depends. Somebody is going to run it through the >> converter; it's just a question of whether it's me, or the >> submitter. Martin> 'you' in this case isn't the maintainer of a software Martin> package; it is the Python source code parser... Same thing either way, if you add the preprocessing hook. IMO, the Python source code parser should never see any text data[1] that is not UTF-8 encoded. If you want to submit Python programs to the parser that are not UTF-8 encoded, then it is your responsibility as the programmer to make sure they get translated into UTF-8 (eg, by the preprocessing hook) before the interpreter proper ever sees them. Note that the Python language doesn't need to specify at all what's allowed on the preprocessing hook. It can be a Perl-to-Python translator, for all I care. You simply say "if the parser doesn't accept it when run `python --skip-preprocessing-hook', it's not valid Python." No more problem. From the user's point of view, in everyday operation it's basically the same as a Python which accepts his favorite encoding. From your point of view, the interpreter is invulnerable to coding issues. Even if you choose to support complex (eg, autorecognizing[2]) codecs on the pre-processing hook as part of the Python library, bugs are more easily localized. Since the preprocessing-hook would be callable from Python, it would be easy to run it as a separate program, and require the users to send the output of that as the bug report. The final benefit is that in multilingual environments it makes use of UTF-8 a lot more attractive to the users. But those are exactly the environments where coding cookies will be a massive pain for Python to support them, because people will forever be copying the top matter from German files into Polish files and forgetting to adjust the cookie, etc. Footnotes: [1] Ie, Python language or character text. It might be convenient to have an octet-string primitive data type, in which you could put EUC-encoded Japanese or Java byte codes. However, the Python interpreter would never do anything with them except (1) pass them whole as arguments or variable values, (2) extract slices, and (3) extract individual octets as an integral (but non-character) type. (Roughly speaking. There might be other operations that "base Python" should implement, like applying codecs.) [2] But I recommend against this. Don't offer support for such; it's a time and effort sink, for little return. -- Institute of Policy and Planning Sciences http://turnbull.sk.tsukuba.ac.jp University of Tsukuba Tennodai 1-1-1 Tsukuba 305-8573 JAPAN Don't ask how you can "do" free software business; ask what your business can "do for" free software. From wesc at deirdre.org Fri Mar 1 07:48:46 2002 From: wesc at deirdre.org (wesc at deirdre.org) Date: Thu, 28 Feb 2002 22:48:46 -0800 (PST) Subject: ANN: SV-SF Bay Area Python user grp (BayPIGgies) mtg 3/13 7:30pm Message-ID: <200203010648.WAA23404@alpha.ece.ucsb.edu> When: March 13, 2002, 7:30-9pm Where: Stanford University, Palo Alto, CA Title: BioPython Jeffrey Chang (School of Medicine, Stanford University) founded the BioPython project in 1999 to promote the development of shared software infrastructure in bioinformatics. His talk will cover the architecture and capabilities of Biopython and also give a sneak preview of the upcoming version. Click on BayPIGgies link below for more info, including driving directions, past meetings, schedule, etc. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "Core Python Programming", Prentice Hall PTR, ? 2001 http://starship.python.net/crew/wesc/cpp/ Silicon Valley-San Francisco Bay Area Python Users Group (BayPIGgies) http://deirdre.org/baypiggies wesley.j.chun :: wesc at deirdre.org cyberweb.consulting : henderson, nv : cyberweb at rocketmail.com http://roadkill.com/~wesc/cyberweb/ From dyoo at hkn.eecs.berkeley.edu Fri Mar 1 07:51:39 2002 From: dyoo at hkn.eecs.berkeley.edu (Daniel Yoo) Date: Fri, 1 Mar 2002 06:51:39 +0000 (UTC) Subject: what does this do? (really basic question) References: Message-ID: Dave Marotti wrote: : Hey, : Hopefully this is a really basic question. I'm still in the learning phase, : and came across this in a sample program: : class Whatever: : def __init__(self, user_list, cmd_list, **kw): : code.... : What does the **kw mean (specifically, the **) ? "kw" stands for "keyword", and what's being used is called a "keyword argument". Keyword arguments allow us to pass parameters to a function in a very general way. In the example above, the keyword argument becomes a dictionary that captures any keyword variables that "fall through the cracks" of a function call. Keyword arguments aren't particular to class methods --- they're a general concept in function calls. Here's an example: ### >>> def test_keywords(var1, var2, **keywords): ... print 'var1 = ', var1 ... print 'var2 = ', var2 ... print 'keywords = ', keywords ... >>> test_keywords(3, 4) var1 = 3 var2 = 4 keywords = {} >>> test_keywords(var2=4, var1=42) var1 = 42 var2 = 4 keywords = {} >>> test_keywords(var2=4, var1=42, var3 =17, var4='planet') var1 = 42 var2 = 4 keywords = {'var4': 'planet', 'var3': 17} >>> ### Here, the last call of test_keywords() shows that 'keywords' grabs all all the variables unaccounted for. Keyword arguments might seem somewhat Useless at a first glance, but they are actually quite nice: Peter Norvig uses examples of keyword arguments in his "Infrequently Asked Questions" page: http://norvig.com/python-iaq.html There's also a little bit of explanation about them in the Python tutorial: http://www.python.org/doc/current/tut/node6.html#SECTION006720000000000000000 Please feel free to ask more questions about them. Good luck to you! From jason at jorendorff.com Fri Mar 1 07:54:19 2002 From: jason at jorendorff.com (Jason Orendorff) Date: Fri, 1 Mar 2002 00:54:19 -0600 Subject: PEP 276 (was Re: Status of PEP's?) In-Reply-To: Message-ID: > some-people-don't-even-like-listcomps-ly y'rs - tim Detour: I still haven't decided whether I like list comps (although I *use* them all the time) but today I found something surprisingly similar scribbled in a notebook of mine, perhaps a few years old. { file f | f.parent = '/home/jason' } ... the same code in something more like prolog ... set { file f | f in folder '/home' } It was really disconcerting to see this in my own handwriting, considering my mixed feelings on Python's list comps. Hmm. :) ## Jason Orendorff http://www.jorendorff.com/ From rwgk at yahoo.com Fri Mar 1 08:05:07 2002 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: 28 Feb 2002 23:05:07 -0800 Subject: Scripting C++ -- 2 -- a more concrete example. References: <3C7E6642.2030202@physics.ucsb.edu> Message-ID: <8be7693c.0202282305.12ee7d46@posting.google.com> Craig Maloney wrote in message news:<3C7E6642.2030202 at physics.ucsb.edu>... > Thanks to all for the great leads to wrapper generators for > Suppose that I have a class Crystal, and a class Atom. I'd like to be > able to do the following: > > ----------------- > Crystal c; > ... > Atom a1; > Atom a2; > ... > > c.addAtom(a1); > c.addAtom(a2); > ... > c.computeEnergy(); > --------------------- > > Atom is a simple enough data structure that default copy works. Crystals and atoms... that looks familiar to me :-) See cctbx.sf.net. This is a C++ library with Python bindings implemented using Boost.Python. > Now here comes the concrete question. If I want to use this class > library from a scripting language (e.g. Python) what are the pros and > cons of using wrapper code (e.g. Boost.Python or SILOON from lanl) vs CORBA. > > To me the main differences are: > > 1) Interface generation. > If I use CORBA, I would have to write IDL interfaces on top of the > library, since there is no reverse mapping from C++ as there is in java. > It seems contrary to the spirit to write the IDL *after* I've written > the class library -- indicating a lack of regard to issues of > distributedness in designing the class library. (see my comment at the end) > > If I use wrapper generators, it seems like there is a chance (e.g. using > SILOON/PDT or BOOST/PDT) that it would be possible to have the wrapper > code automatically generated. I do not know about PDT, it certainly is not currently integrated with Boost.Python. I.e. you have to write the wrappers manually. If you do this while developing a library, the extra coding time is in general negligible compared to the time it takes to develop the rest. If you want to wrap a large existing library it can be a bit cumbersome. > This is a major boon as I would not have to convert > std::valarray to sequence or whatever monkeying I would > have to do. I can imaging this getting pretty hairy to the point of > unworkable. > > 2) Marshalling and Objects-by-value. > When the "Crystal" computes its energy it should *NOT* have to marshall > calls to get at the atom data structures. This is an operation that > will be repeated about 2.85 bijillllion times. In CORBA, this is no > problem -- I would either have Crystal::addAtom take a valuetype (atoms > are easy enough to serialize), or I would use some "co-location" trick > so that the ORB knows that the atom *really* lives in the same address > space as the crystal. Preferrably the former. > > If using a wrapper generator (e.g. SILOON) I don't see a way around the > marshalling of the call to get at the atom data structure. > > Of course, this would be taken care of by a revamp of the design of the > class library... maybe making the crystal an atom factory that produces > new atoms in its own address space. But I would like to avoid thinking > about multi-language and distribution issues when designing the core of > the library. Is this dream just simply self-contradictory? Does "marshalling" mean converting objects to strings (and vice versa)? If you use Boost.Python the wrapped C++ objects are never marshalled. The run-time overhead for crossing the language boundary is very small. In our applications (higher-level management in Python, number-crunching in C++) it is hardly ever noticeable. Ralf From fperez528 at yahoo.com Fri Mar 1 08:17:33 2002 From: fperez528 at yahoo.com (Fernando Pérez) Date: Fri, 1 Mar 2002 00:17:33 -0700 Subject: sorting References: <3c7e3d12_7@news.teranews.com> Message-ID: "Jeff McComas" wrote > As a newbie i find the python scripting language very interesting and useful. > I am trying to write a script that will search a .txt file and have the script > tell me how many of the same numbers are in the .txt file. I know you can do > it with the f.count command but my problem is how can you do an input that > makes the numbers strings? Or puts double quotes and a comma around a number? You've received a number of perfectly good suggestions so far, and they illustrate nice and useful python programming techniques which you'll benefit from learning. If you need to do this for production code though, I suggest you look into Numerical python for handling large data arrays, and you may want to use a convenient histogram builder from the Scientific python family: http://starship.python.net/crew/hinsen/ Konrad's code is very good and well tested. With it, building a histogram for a large data file is one line of code. There's nothing wrong with your approach while you learn, I just wanted to point you in the direction of production-quality resources for when you need them. Enjoy python! f. From jolsen at mailme.dk Fri Mar 1 08:23:45 2002 From: jolsen at mailme.dk (Jesper Olsen) Date: 28 Feb 2002 23:23:45 -0800 Subject: Numeric Python Installation woes References: <2dg03lvk1q.fsf@james.hut.fi> Message-ID: I do not know what is wrong, but as the error messages suggest, it seems your python 2.2 instalation is the problem. Have you otherwise tested python 2.2? Maybe you should re-install it (python 22) and get rid of the two old installations. Cheers Jesper > For some reasons even after upgrading to python 2.2 python 1.5 is > still there in the bin. > > Wishes and thankx in advance > karthik > > -- > > ----------------------------------------------------------------------- > Karthikesh Raju, email: karthik at james.hut.fi > Researcher, http://www.cis.hut.fi/karthik > Helsinki University of Technology, Tel: +358-9-451 5389 > Laboratory of Comp. & Info. Sc., Fax: +358-9-451 3277 > Department of Computer Sc., > P.O Box 5400, FIN 02015 HUT, > Espoo, FINLAND > ----------------------------------------------------------------------- From marijn at sanity.dhs.org Fri Mar 1 08:30:57 2002 From: marijn at sanity.dhs.org (marijn Vriens) Date: 28 Feb 2002 23:30:57 -0800 Subject: import Random: NV_MAGICCONST deviates too much. Message-ID: <29575ad6.0202282330.16226275@posting.google.com> Hi all... I have get a strange exception when importing random. I brought it down to: Python 2.1.2 (#1, Jan 18 2002, 18:05:45) [GCC 2.95.4 (Debian prerelease)] on linux2 Type "copyright", "credits" or "license" for more information. >>> import gnome.ui >>> import random Traceback (most recent call last): File "", line 1, in ? File "/usr/lib/python2.1/random.py", line 93, in ? _verify('NV_MAGICCONST', 1.71552776992141) File "/usr/lib/python2.1/random.py", line 88, in _verify raise ValueError( ValueError: computed value for NV_MAGICCONST deviates too much (computed 2,82843, expected 1) >>> If I first import random and then gnome.ui I have no problems. my distr is debian woody with the standard python packages (not self-compiled) on an AMD-K6 Anybody know what's going on ? Cheers, Marijn. PS: Thanks to the #python crew for helping me out on this one! From martin at v.loewis.de Fri Mar 1 08:29:43 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 01 Mar 2002 08:29:43 +0100 Subject: PEP 263 comments References: <87g03lhm3p.fsf@tleepslib.sk.tsukuba.ac.jp> <87pu2oeqq9.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: "Stephen J. Turnbull" writes: > IMO, the Python source code parser should never see any text data[1] > that is not UTF-8 encoded. If you want to submit Python programs to > the parser that are not UTF-8 encoded, then it is your responsibility > as the programmer to make sure they get translated into UTF-8 (eg, by > the preprocessing hook) before the interpreter proper ever sees them. That would cause surprises to users. They have a source program that says # -*- coding: koi8-r -*- print "some cyrillic text" This currently works fine on their system; the text comes out on the terminal just right. Now, Python would convert this text silently to UTF-8 behind their backs, and the terminal would show just garbage. In XEmacs, this is no problem: the "terminal" mostly is the *Messages* buffer, and that would know that all text is UTF-8. For Unicode strings, we indeed plan to make the transformation you suggest (not to UTF-8, though): If you have a script that reads # -*- coding: koi8-r -*- print u"some cyrillic text" then the string literal will be converted to the internal Unicode type. How to print it is then another issue; you'll have to figure out the encoding of the terminal - that is feasible in most cases. It is not feasible to do the same for arbitrary byte strings: You (the Python interpreter) could not know whether the string is supposedly UTF-8 encoded, and that conversion to the terminal's encoding is needed, or whether the string is an arbitrary byte sequence, which is intended to appear on the terminal as-is. "All byte strings are UTF-8" is not going to work, since Python is used to operate on binary data as well, and the bytes that make up a GIF file just aren't UTF-8. > [1] Ie, Python language or character text. It might be convenient to > have an octet-string primitive data type, in which you could put > EUC-encoded Japanese or Java byte codes. The traditional "string" type is, in fact, a byte string type. Many people use it still for character strings, since the Unicode type was the later addition. Changing the string type to be a Unicode type was not feasible since that would have broken many applications, in particular C modules which expect that the internal representation of the string type is char[]. > [2] But I recommend against this. Don't offer support for such; it's > a time and effort sink, for little return. There will be a simple form of auto-recognition: an UTF-8 signature (i.e. a UTF-8 encoded BOM) at the beginning of a source file will be treated as a clear indication that the file is UTF-8. Regards, Martin From martin at v.loewis.de Fri Mar 1 08:34:26 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 01 Mar 2002 08:34:26 +0100 Subject: PEP 263 comments References: Message-ID: "Jason Orendorff" writes: > > Java does accept iso-latin-1 files as input. In fact on my machine (Mac > > OSX) it doesn't even accept utf-8 files with the utf-8 signature. And > > strings containing utf-8 are interpreted as just 8-bit characters, meaning > > every byte is a character. > > Oh! Yes, it works this way on Windows, too. javac assumes source > files are latin-1, and System.out.println() encodes output in latin-1. That is not completely true. javac has the -encoding command line which allows you to specify the source encoding; this defaults to the platform default encoding (which probably was latin-1 resp. windows-1252 on your systems). > I'm referring to this paragraph in Martin's original post: > > The only problem with this approach is that encodings where " or ' > could be the second byte of a multi-byte character cannot be > supported as a source encoding. Python supports no such encoding > in the standard library at the moment, anyway, so this should not > be a problem. > > \x22 is a double-quote mark. Martin is a little off on the last > bit, though; UTF-16 can produce \x22 bytes. Right. Source encodings (atleast under the initial implementation) need to be an ASCII superset (in the sense that source code that uses only ASCII characters is ASCII-encoded); I see no way to allow UTF-16 as a source encoding. Regards, Martin From fperez528 at yahoo.com Fri Mar 1 08:36:28 2002 From: fperez528 at yahoo.com (Fernando Pérez) Date: Fri, 1 Mar 2002 00:36:28 -0700 Subject: Numeric Python Installation woes References: <2dg03lvk1q.fsf@james.hut.fi> Message-ID: > > Maybe you should re-install it (python 22) and get rid of the two old installations. Careful. The OP hasn't specified but from the symptoms I suspect he's a victim of RedHat's completely ass-backwards python setup as of 7.2. He'll majorly blow his system if he removes 1.5. His best bet is to manually build 2.2, shove it into /usr/local/, and make sure that gets found by his user's /usr/bin/env before 1.5. But NOT by root and other system-level users (like those of certain daemons), those need to see 1.5. He'll just have to play a few path games. And complain to redhat for the mess they've made. Every other week there's someone here totally (and justly) confused by their setup. I have yet to hear a convincing argument from them justifying what they did. They could perfectly have made it so that _their_ scripts find 1.5 first if they need it, while allowing the user system default to be 2.x. But no, instead they chose to make it difficult for users who aren't too savvy with internals to safely switch to 2.x (if you simply change the global python link to point to 2.x, you break lots of stuff). Cheers, f. From dyoo at hkn.eecs.berkeley.edu Fri Mar 1 08:42:12 2002 From: dyoo at hkn.eecs.berkeley.edu (Daniel Yoo) Date: Fri, 1 Mar 2002 07:42:12 +0000 (UTC) Subject: ANN: SV-SF Bay Area Python user grp (BayPIGgies) mtg 3/13 7:30pm References: Message-ID: wesc at deirdre.org wrote: : When: March 13, 2002, 7:30-9pm : Where: Stanford University, Palo Alto, CA : Title: BioPython : Jeffrey Chang (School of Medicine, Stanford University) founded the : BioPython project in 1999 to promote the development of shared software : infrastructure in bioinformatics. His talk will cover the architecture : and capabilities of Biopython and also give a sneak preview of the : upcoming version. Expect to see a crowd of biologists there as well. I told my boss to make an announcement about it too. We should bring refreshments this time. *grin* From jgardn at alumni.washington.edu Fri Mar 1 09:04:58 2002 From: jgardn at alumni.washington.edu (Jonathan Gardner) Date: Fri, 01 Mar 2002 17:04:58 +0900 Subject: PyQT and shaped windows in X References: Message-ID: Moray Taylor wrote: > Hi, > > Can anyone point me in the direction of an example of shaped windows > using QT with Python, is the XLib module required? Is it even > possible? > I really doubt there is one. > BTW I have tried asking in the PyQT/PyKDE mailing list, but it wasn't > considered to be a PyQT question, go figure. > This is a Qt question - not a PyQt one. You'll probably figure out how to do it, but it will take a lot of study and experimentation. Perhaps you should investigate Xt, as there is a QXtWidget and QXtApplication class available in Qt. The silence was because no one knows how to do it, not because it was a stupid question or because we don't like you. Jonathan From thomas at gatsoft.no Fri Mar 1 08:55:18 2002 From: thomas at gatsoft.no (Thomas Weholt) Date: Fri, 01 Mar 2002 07:55:18 GMT Subject: Simple threading thing References: Message-ID: I was calling the maintanence-thread's run()-method, not its start()-method. Thanks to Cliff Wells for helping me with that. Here's the code in question for later use : import time, threading class MyThread(threading.Thread): def __init__(self): threading.Thread.__init__(self) def run(self): while 1: time.sleep(10) print "Doing something" class t: def __init__(self): self.worker = MyThread() def serve(self): self.worker.start() # was self.worker.run() while 1: time.sleep(5) print "Main class serving ..." x = t() x.serve() Now it works just great! Thanks for all your help, interest and input. Best regards, Thomas Weholt "Martin v. Loewis" wrote in message news:m3u1s19qhu.fsf at mira.informatik.hu-berlin.de... > "Thomas Weholt" writes: > > > I need a thread, no forking. Should run in Linux and Win32. I need a thread > > that functions in the background, running beside the main server, with a > > reference to the main server so it can maintain states etc. in it. The > > purpose of the process is to mainly remove expired sessions ( remember this > > is a webserver ), log certain values and monitor the server, and work as > > sort of a janitor. > > > > Does that make it any clearer? > > Not really. The main process starts. What happens next? I interpret > your posting as > > - creates a new thread, to observe the main thread > - the main thread should continue to run, but doesn't > > Is that correct? How do you know it does not run? > > If this are all the fact, it is really hard to believe. There must be > details that you've omitted. > > Regards, > Martin From karthik at james.hut.fi Fri Mar 1 09:13:31 2002 From: karthik at james.hut.fi (Karthikesh Raju) Date: 01 Mar 2002 10:13:31 +0200 Subject: Numeric Python Installation woes References: <2dg03lvk1q.fsf@james.hut.fi> Message-ID: <2dbse8vh78.fsf@james.hut.fi> Hi, Thankx. This is exactly what happens with my RH7.1 system. When i try to upgrade 1.5 to 2.2, the system complained and so i left it alone. Now Python 2 which also exists. Dont know how to set this right, and probably because of this numpy does not work even. wishes karthik -- ----------------------------------------------------------------------- Karthikesh Raju, email: karthik at james.hut.fi Researcher, http://www.cis.hut.fi/karthik Helsinki University of Technology, Tel: +358-9-451 5389 Laboratory of Comp. & Info. Sc., Fax: +358-9-451 3277 Department of Computer Sc., P.O Box 5400, FIN 02015 HUT, Espoo, FINLAND ----------------------------------------------------------------------- From andreas at mtg.co.at Fri Mar 1 09:33:19 2002 From: andreas at mtg.co.at (Andreas Kostyrka) Date: Fri, 1 Mar 2002 09:33:19 +0100 Subject: xor on strings In-Reply-To: <%hI98.3302$pC1.668524@newssrv26.news.prodigy.com> References: <3c674cbd_2@corp.newsgroups.com> <%hI98.3302$pC1.668524@newssrv26.news.prodigy.com> Message-ID: <20020301093319.4b73f174.andreas@mtg.co.at> On Mon, 11 Feb 2002 05:04:59 GMT "dsavitsk" wrote: > the truncate part is the problem. I am building VB Hex strings to send to a > VB server. so > > >>> red = hex(56)[2:4] What about: red=56 green=156 blue=12 thestring="%02x%02x%02x" % (red,green,blue) > >>> green = hex(156)[2:4] > >>> blue = hex(12)[2:4] > >>> thestring = '&H' + blue + green + red > > but here, since the blue string is only 1 character it throws the rest off. Andreas From michael at stroeder.com Fri Mar 1 09:47:16 2002 From: michael at stroeder.com (=?ISO-8859-1?Q?Michael_Str=F6der?=) Date: Fri, 01 Mar 2002 09:47:16 +0100 Subject: ASV module, CVS modules References: <61ff32e3.0202281525.3e9bb102@posting.google.com> Message-ID: <3C7F4014.7090800@stroeder.com> John Machin wrote: > > You 2: On Windows, either use forward slashes "c:/test_data.csv" (it > works!) AFAIK this does not work on W2K anymore. I might be wrong. Ciao, Michael. From shriek at gmx.co.uk Fri Mar 1 10:02:08 2002 From: shriek at gmx.co.uk (Stephen) Date: 1 Mar 2002 01:02:08 -0800 Subject: Want to monitor process.. References: <87550ef1.0202272315.15779bbd@posting.google.com> <97ae44ee.0202280901.3153bdfc@posting.google.com> <3C7EC9C6.D11FB17@engcorp.com> Message-ID: <97ae44ee.0203010102.14ebf2bb@posting.google.com> > > Unfortunately, my own applications seem to crash as opposed to > > shutdown normally, so it's probably not going to help me. From the > > library reference ~ > > "Note: the functions registered via this module are not called when > > the program is killed by a signal, when a Python fatal internal error > > is detected, or when os._exit() is called. " > > Yikes! "Crash"? Do you really mean they crash the Python interpreter, > or do you mean they exit with an exception? Sorry, I guess I mean "exit with an exception" though to be honest, I still don't know because I haven't been able to run the programs interactively during a 'crash'. The problem seems to be that sometimes a thread can take up to 60 seconds to be dealt with (not by design but because one of the backend systems takes so long to respond) and in the meantime requests keep coming in ~ during peak load (5 requests/sec), this can result in a high number of threads kept open. > If the former, you've got seriously problems, I agree. > > If the latter, just wrap the highest level code with a try/finally > or try/except and put code in to ensure the child processes are > properly terminated. Simple, clean, safe. Will do. I didn't want to put try/except/finally at the highest level of code yet since we're actually in Beta and I want to know when my server encounters a problem. Problem has been that not running it in interactive mode, I've missed the reasons for the failures. That's why I also asked about logging recently. > My Python programs *never* crash (as in kill the interpreter) > but maybe that's just me... I doubt it. I doubt it too. More likely my error handling isn't sufficient. Stephen. From jason at jorendorff.com Fri Mar 1 10:04:13 2002 From: jason at jorendorff.com (Jason Orendorff) Date: Fri, 1 Mar 2002 03:04:13 -0600 Subject: ASV module, CVS modules In-Reply-To: <3C7F4014.7090800@stroeder.com> Message-ID: Michael Stroder wrote: > John Machin wrote: > > You 2: On Windows, either use forward slashes "c:/test_data.csv" (it > > works!) > > AFAIK this does not work on W2K anymore. I might be wrong. As far as I can tell, you are. I'm constantly using this ability on Windows 2000. ## Jason Orendorff http://www.jorendorff.com/ From robin at jessikat.fsnet.co.uk Fri Mar 1 10:07:58 2002 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Fri, 1 Mar 2002 09:07:58 +0000 Subject: win32+popen4 References: <$4LupWAmqsf8Ew0o@jessikat.fsnet.co.uk> Message-ID: . .... > >However, if you are on a 9x platform, and quoting the command just as >you want the command interpreter to see it on the command line doesn't >work, you might just want to revert to using the short (non-space) >version of the name. So in your example you would replace "program >files" with "progra~1" (or whatever it may be in the unlikely event >it's different than that). > >-- >-- David this is win2k. I have tried quoting with "", but I still seem to be getting no such command C:\program etc -- Robin Becker From shomon at softhome.net Fri Mar 1 10:34:03 2002 From: shomon at softhome.net (skoria) Date: Fri, 01 Mar 2002 09:34:03 -0000 Subject: newbie lists and code examples for OOP. Message-ID: Hi Firstly: is there a better forum for newbie questions like this one? It's hard for me to post to a high traffic list, and maybe there's a local uk based one or one specifically aimed at newbies. I'm trying to write a class where one function calls a method in the same class. Right now I'm doing this with trial and error, and I don't really understand where I need to put parentheses, use (self), etc. I can't find any "functional" examples of object oriented programming on any online tutorials, or any simple programs already written that can be used as a good tool to figure out how to call functions within classes in python, when to use self.* what internal functions (like __init__) can be used for. Lots of theory on this, but no functional examples. Can anyone suggest any? Thanks, Ale From bokr at oz.net Fri Mar 1 10:30:13 2002 From: bokr at oz.net (Bengt Richter) Date: 1 Mar 2002 09:30:13 GMT Subject: PEP 263 comments References: <87g03lhm3p.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: On 28 Feb 2002 15:09:23 +0100, Martin von Loewis wrote: [...] >You may wonder why Python (the programming language) needs to worry >about the encoding at all. The reason is that we allow Unicode >literals, in the form > > u"text" > >The question is what is the encoding of "text", on disk. In memory, it >will be 2-byte Unicode, so the interpreter needs to convert. To do >that, it must know what the encoding is, on disk. The choices are >using either UTF-8, or allowing encoding cookies. > I'm not sure what you mean by 'encoding cookies' but I assume you mean something analogous to browser cookies, where some data of interest is stored separately but related to some other data and processing, like HTML form sumbissions etc. Well, forget the cookie associations, but I think keeping meta-data separate from data is a Good Thing(tm). Also keeping it out of the names of things (i.e., don't encode file types in name extensions ;-) Perhaps we could just use a file to contain extra file metadata, letting a file of metadata govern other files it names in the same directory as itself. Probably a dot file in *nix. For PEP 263 purposes, it would only need to be a text file with file names tab delimited from keyword=encoding-info, with the first line(s) perhaps with a glob pattern for a compact way of specifying encoding for a lot of files in a directory at once. To provide international encoding for file-associated info, like a local dialect/special characters name etc., in a system whose native file naming is more restricted, perhaps this directory of file attributes could be standardized to UTF-8 for its own encoding. That way, you could have the first column represent the file name the system sees and an optional uname= keyword could provide an alternate utf-8 encoded name for the file that tools that knew of it could display, and then encoding=whatever for the actual file data per se. The nice thing is that you don't have to touch the original files to describe them. By including a location= keyword you could even have this work like a symbolic link to a network file or even an URL-specified file, which could be read-only and burned in a CD, or a please-mount-backup-tape-x location, etc. The actual file data would not have to be in the same directory at all. I have more ideas, but I tend to overdo one post that way ;-) Regards, Bengt Richter P.S. This discussion made me look for some more UTF info. For anyone interested, I found a FAQ at http://www.unicode.org/unicode/faq/utf_bom.html#2 and http://www.unicode.org/unicode/reports/tr27/ has a nice table showing where bits go for UTF-8 and UTF-16 encoding of unicode characters, and even 32-bit stuff. Might make a refs links for the PEP. There are some changes as to legality checks, apparently, as of last May. I'm wondering if this affects PEP 263 and/or the unicode implementation in Python. From loewis at informatik.hu-berlin.de Fri Mar 1 11:04:06 2002 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 01 Mar 2002 11:04:06 +0100 Subject: PEP 263 comments References: <87g03lhm3p.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: bokr at oz.net (Bengt Richter) writes: > I'm not sure what you mean by 'encoding cookies' but I assume you > mean something analogous to browser cookies, where some data of > interest is stored separately but related to some other data and > processing, like HTML form sumbissions etc. I took the term from Stephen Turnbell, and I understood him to mean the coding: variable that Emacs recognizes, i.e. some declaration inside the file - quite unlike a browser cookie. > Perhaps we could just use a file to contain extra file metadata, > letting a file of metadata govern other files it names in the same > directory as itself. Probably a dot file in *nix. Nice idea, different PEP. > For PEP 263 purposes, it would only need to be a text file with file > names tab delimited from keyword=encoding-info, with the first line(s) > perhaps with a glob pattern for a compact way of specifying encoding > for a lot of files in a directory at once. I don't think the file encoding information should be stored in a different file; the risk of the two files becoming disassociated is just to big to be acceptable. > To provide international encoding for file-associated info, like > a local dialect/special characters name etc., in a system whose > native file naming is more restricted, perhaps this directory of > file attributes could be standardized to UTF-8 for its own encoding. We are not talking about file names here, but about file contents. > There are some changes as to legality checks, apparently, > as of last May. I'm wondering if this affects PEP 263 > and/or the unicode implementation in Python. That doesn't affect this PEP; as for the Unicode 3.1 conformance, I believe the current CVS implements UTF-8 correctly. Regards, Martin From robin at jessikat.fsnet.co.uk Fri Mar 1 11:11:24 2002 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Fri, 1 Mar 2002 10:11:24 +0000 Subject: Aquisition Alert References: Message-ID: I thought we could just inherit, but if you say Acquisition is smarter I guess I have to try and understand it. -- Robin Becker From mwh at python.net Fri Mar 1 11:14:16 2002 From: mwh at python.net (Michael Hudson) Date: Fri, 1 Mar 2002 10:14:16 GMT Subject: Deitel and Deitel Book... References: <3C7D8DCA.119D52EC@earthlink.net> <20020227163411.71b4b4d8.alex@netWindows.org> Message-ID: Dennis Roark writes: > The Python book appears substantially based on the templates of > their previous books. Certainly the first draft of chapter 2 that I reviewed[0] looked suspiciously like the corresponding chapter from Java:HTP. That went back with a lot of red ink on it... Cheers, M. [0] My, there were a lot of reviewers weren't there? -- same software, different verbosity settings (this one goes to eleven) -- the effbot on the martellibot From henrik.motakef at web.de Fri Mar 1 09:51:25 2002 From: henrik.motakef at web.de (Henrik Motakef) Date: 01 Mar 2002 09:51:25 +0100 Subject: Python GUI References: Message-ID: <86zo1sy8ky.fsf@apo.hmotakef.int> "Avi Homes" writes: > some type of gui builder or somesuch for python Just because nobody mentioned it yet: You can use the Qt Builder (included in the default Qt distribution) with PyQt as well. hth Henrik From robin at jessikat.fsnet.co.uk Fri Mar 1 11:40:45 2002 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Fri, 1 Mar 2002 10:40:45 +0000 Subject: win32+popen4 References: <$4LupWAmqsf8Ew0o@jessikat.fsnet.co.uk> Message-ID: OK to be more precise I'm executing like this Python 2.1.2 (#31, Jan 15 2002, 17:28:11) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information. >>> import os >>> import sys ... >>> cmd '"C:\\Program Files\\ReportLab\\Demo\\rml2pdf.exe" "C:\\Program Files\\ReportLab\\Demo\\rlextra\\pageCatcher\\PageCatchI ntro.rml" --outdir="C:\\Program Files\\ReportLab\\Demo\\Doc"' >>> i, o = os.popen4(cmd,'t') >>> t = o.read() >>> print t 'C:\Program' is not recognized as an internal or external command, operable program or batch file. >>> I can run the command directly C:\Program Files\ReportLab\Demo>"C:\\Program Files\\ReportLab\\Demo\\rml2pdf.exe" "C:\\Program Files\\ReportLab\\Demo\\r lextra\\pageCatcher\\PageCatchIntro.rml" --outdir="C:\\Program Files\\ReportLab\\Demo\\Doc" C:\Program Files\ReportLab\Demo> so somewhere something odd is happening. This is win2k. -- Robin Becker From bokr at oz.net Fri Mar 1 11:49:00 2002 From: bokr at oz.net (Bengt Richter) Date: 1 Mar 2002 10:49:00 GMT Subject: Telnet connection References: <8z9f2rks.fsf@fido.trinitycapital.com> Message-ID: On 28 Feb 2002 23:46:47 GMT, bokr at oz.net (Bengt Richter) wrote: >On Thu, 28 Feb 2002 19:51:06 +0100, "Riss Nicolas" wrote: > >>Has somebody a python program where it is an telnet connection ? > >You appear to be running windows. What happens if you get into your browser >and put > > telnet://192.168.0.9:32 > >in the location (i.e., what you are trying to connect to with your code)? >Do you get a telnet client screen with a login prompt? > >Did you try \r\n in place of plain \n in your code? > Whoa, I just realized your program seems to be missing a couple of lines for waiting for a user prompt and sending the user name. After that, wait for the password prompt. At least that is typical. Or do you have some special telnet server setup that bypasses that? Maybe it still needs a \r\n to trigger it past the missing user entry? It's hard to say with so little info. Or copy from the screen of a manual login and successful connect with a couple commands. (Do you connect to an ordinary shell or some special program)? BTW, if you somehow have wrapped your telnet program execution in a try: do_it() except: pass, you could be missing a bug-caused exception discussed in another thread. You might want to try changing line 424 of telnetlib.py. In the other thread I wrote: I suspect line 424 self.msg('IAC %d not recognized' % ord(opt)) should be self.msg('IAC %d not recognized' % ord(c)) Regards, Bengt Richter PS., explain in French if that helps. Someone will translate if needed. Maybe even if not needed ;-) From peter at engcorp.com Fri Mar 1 12:23:59 2002 From: peter at engcorp.com (Peter Hansen) Date: Fri, 01 Mar 2002 06:23:59 -0500 Subject: ASV module, CVS modules References: <61ff32e3.0202281525.3e9bb102@posting.google.com> <3C7F4014.7090800@stroeder.com> Message-ID: <3C7F64CF.771E7319@engcorp.com> Michael Str?der wrote: > > John Machin wrote: > > > > You 2: On Windows, either use forward slashes "c:/test_data.csv" (it > > works!) > > AFAIK this does not work on W2K anymore. I might be wrong. Since Win2K is just WinNT relabelled, I suspect you're wrong. I could be wrong though. :) From peter at engcorp.com Fri Mar 1 12:31:55 2002 From: peter at engcorp.com (Peter Hansen) Date: Fri, 01 Mar 2002 06:31:55 -0500 Subject: Want to monitor process.. References: <87550ef1.0202272315.15779bbd@posting.google.com> <97ae44ee.0202280901.3153bdfc@posting.google.com> <3C7EC9C6.D11FB17@engcorp.com> <97ae44ee.0203010102.14ebf2bb@posting.google.com> Message-ID: <3C7F66AB.D51BEA03@engcorp.com> Stephen wrote: > > > Yikes! "Crash"? Do you really mean they crash the Python interpreter, > > or do you mean they exit with an exception? > > Sorry, I guess I mean "exit with an exception" though to be honest, I > still don't know because I haven't been able to run the programs > interactively during a 'crash'. I'm not sure what the interactive thing would add, since the interpreter will already print exception tracebacks to the console whenever your program exits exceptionally. If you aren't seeing a traceback, maybe you aren't really exiting with an exception. > > If the latter, just wrap the highest level code with a try/finally > > or try/except and put code in to ensure the child processes are > > properly terminated. Simple, clean, safe. > > Will do. I didn't want to put try/except/finally at the highest level > of code yet since we're actually in Beta and I want to know when my > server encounters a problem. No problem, just put a "raise" statement as the final statement in the exception handling block (when using try/except only) and you'll still propagate the exception up and right out of the interpreter so it prints a traceback to the console. In the try/finally case, however, you'll still get the traceback if an exception *did* occur, because the interception is only a temporary one. After the finally code executes, exception processing continues on. > Problem has been that not running it in > interactive mode, I've missed the reasons for the failures. That's > why I also asked about logging recently. Logging is good, but shouldn't be absolutely essential to catch a serious exception. The interactive mode should be entirely unnecessary and, as you suggest, gets in the way of normal execution. I think you might focus on the lack of a traceback. You should always see one if you aren't explicitly swallowing the exception. (Note, a few standard modules such as the SocketServer and such will internally swallow exceptions in the server threads by default.) -Peter From peter at engcorp.com Fri Mar 1 12:35:01 2002 From: peter at engcorp.com (Peter Hansen) Date: Fri, 01 Mar 2002 06:35:01 -0500 Subject: win32+popen4 References: <$4LupWAmqsf8Ew0o@jessikat.fsnet.co.uk> Message-ID: <3C7F6765.94A82394@engcorp.com> Robin Becker wrote: > > . > .... > > > >However, if you are on a 9x platform, and quoting the command just as > >you want the command interpreter to see it on the command line doesn't > >work, you might just want to revert to using the short (non-space) > >version of the name. So in your example you would replace "program > >files" with "progra~1" (or whatever it may be in the unlikely event > >it's different than that). > > > >-- > >-- David > this is win2k. I have tried quoting with "", but I still seem to be > getting > > no such command C:\program etc I'm pretty sure the last time I checked the PROGRA~1 convention still worked on WinNT. Are you sure this doesn't work on Win2K as well? They're supposed to be the same thing, no? -Peter From GetCapsOffDomain Fri Mar 1 12:08:58 2002 From: GetCapsOffDomain (Javier) Date: Fri, 1 Mar 2002 12:08:58 +0100 Subject: wiin32clipboard "odd" behaviour?? Message-ID: Hi all!! I am experiencing a "strange" thing when trying to use the win32clipboard module that comes with Active State's Active Python distro... The thing is, I want to "load" a list of strings to the "main" clipboard (thing loading a list of alternate URLs to clipoard managers like GetRight :-) The thing is, I OpenCliboard(), I SetClipboardText(text) and I can GetClipboardData(format), but I can't "get" the clipboard data from outside apps (not even after I've CloseClipboard() )... It seems like I've gotten a "new" clipboard all for myself... So, what would I have to do to manage things "as usual"?? Ideas, pointers?? TIA Javier ---- To be, or not to be. *BOOM!* Not to be. From alanmk at hotmail.com Fri Mar 1 12:34:10 2002 From: alanmk at hotmail.com (Alan Kennedy) Date: 1 Mar 2002 03:34:10 -0800 Subject: Mod-python problem References: Message-ID: bp at sam.localdomain (Bob Parnes) wrote in message > The only trouble is that I had forgotten about my httpd.conf file. The > relevant lines are: > > > AddHandler python-program .py > PythonHandler mod_python.publisher > > > This was the reason I used main() instead of handler(); in the url window I > typed in "test.py/main" and got the table but no response from FieldStorage(). > Are publisher and FieldStorage() incompatible, or am I misusing them? Knowing > what I know now, I can probably get along without publisher, but I am > accustomed to placing several scripts in one directory. Bob, Sorry, I didn't realise you were using the Publisher handler, otherwise I wouldn't have gone and rewritten your code to work with a completely different paradigm. And I was wondering how you were getting results with something that just didn't look like it could work %-) D'oh! Silly me. Warning: I don't use the publisher handler, so I haven't tested any of the stuff below! Looking at the publisher handler documentation, section 6.1.3: Publisher handler: Form data http://www.modpython.org/live/mod_python-2.7.6/doc-html/node74.html which says: "In the process of matching arguments, the Publisher handler creates an instance of FieldStorage class. A reference to this instance is stored in an attribute form of the Request object. Since a FieldStorage can only be instantiated once per request, one must not attept to instantiate FieldStorage when using the Publisher handler and should use Request.form instead." So it would appear to me that you shouldn't be trying to instantiate the util.FieldStorage() class at all. Instead, you should be referring to the already extant req.form attribute. So your main function should change from this def main(req): formDict = util.FieldStorage(req) cl = clTest() return cl.cltest(req, formDict) to this def main(req): cl = clTest() return cl.cltest(req, req.form) As mentioned, I haven't tested any of this! Hope this helps, Al. From stephen at xemacs.org Fri Mar 1 12:34:59 2002 From: stephen at xemacs.org (Stephen J. Turnbull) Date: 01 Mar 2002 20:34:59 +0900 Subject: PEP 263 comments References: <87g03lhm3p.fsf@tleepslib.sk.tsukuba.ac.jp> <87pu2oeqq9.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: <87u1s0bjx8.fsf@tleepslib.sk.tsukuba.ac.jp> >>>>> "Martin" == Martin v Loewis writes: Martin> "Stephen J. Turnbull" writes: >> IMO, the Python source code parser should never see any text >> data[1] that is not UTF-8 encoded. If you want to submit >> Python programs to the parser that are not UTF-8 encoded, then >> it is your responsibility as the programmer to make sure they >> get translated into UTF-8 (eg, by the preprocessing hook) >> before the interpreter proper ever sees them. Martin> That would cause surprises to users. They have a source Martin> program that says Martin> # -*- coding: koi8-r -*- Martin> print "some cyrillic text" Martin> This currently works fine on their system; the text comes Martin> out on the terminal just right. Now, Python would convert Martin> this text silently to UTF-8 behind their backs, and the Martin> terminal would show just garbage. No, it shows "Error: non-UTF-8 data detected in string." Conversion only takes place if a preprocessing hook function is defined, and the same environment that provides an appropriate preprocessing hook will also arrange to make sure that program I/O is done in KOI8-R, too. But I take your point. It will take time to develop such environments. In the interim, it will cause users who are currently depending on undefined behavior pain. You _can_ say "no" now, while things are undefined. Or you can change the language definition to promise support. If you do that, you are unlikely to be able to get rid of that support for decades, as legacy software will depend on it. Martin> How to print it is then another issue; you'll have to Martin> figure out the encoding of the terminal - that is Martin> feasible in most cases. Why open up that Pandora's box? Push it out into user space. Support them as much as you want to with libraries, give up when it gets too hard (it will!). My experience is that users will not thank you for anything less than perfect support for all coding systems yesterday, if the language definition promises any support at all. If the language definition says "UTF-8 or die", they will thank you for the nice codecs you provide to ease the transition. >> [1] Ie, Python language or character text. It might be >> convenient to have an octet-string primitive data type, in >> which you could put EUC-encoded Japanese or Java byte codes. Martin> The traditional "string" type is, in fact, a byte string Martin> type. Many people use it still for character strings, Maybe you don't need a third type. I see it as a matter of a transition strategy, to allow you to generate exactly the error I suggest above. -- Institute of Policy and Planning Sciences http://turnbull.sk.tsukuba.ac.jp University of Tsukuba Tennodai 1-1-1 Tsukuba 305-8573 JAPAN Don't ask how you can "do" free software business; ask what your business can "do for" free software. From peter at engcorp.com Fri Mar 1 13:07:39 2002 From: peter at engcorp.com (Peter Hansen) Date: Fri, 01 Mar 2002 07:07:39 -0500 Subject: newbie lists and code examples for OOP. References: Message-ID: <3C7F6F0B.9B606460@engcorp.com> skoria wrote: > > Firstly: is there a better forum for newbie questions like this one? > It's hard for me to post to a high traffic list, and maybe there's a > local uk based one or one specifically aimed at newbies. > > I'm trying to write a class where one function calls a method in the > same class. Right now I'm doing this with trial and error, and I don't > really understand where I need to put parentheses, use (self), etc. I > can't find any "functional" examples of object oriented programming on > any online tutorials, or any simple programs already written that can > be used as a good tool to figure out how to call functions within > classes in python, when to use self.* what internal functions (like > __init__) can be used for. Lots of theory on this, but no functional > examples. I'm not sure if by "functional" you mean "working examples" rather than "functional programming" in the computer science sense... If the former, have you looked in the python\lib folder to examine the source code for all the standard modules. At least some of them are object-oriented with samples of what you are looking for, and more. -Peter From jgardn at alumni.washington.edu Fri Mar 1 13:13:15 2002 From: jgardn at alumni.washington.edu (Jonathan Gardner) Date: Fri, 01 Mar 2002 21:13:15 +0900 Subject: Useful, robust shell utilities Message-ID: I tried to use the shutil module... and to tell you the truth, it stinks. Is there an effort to make a robust, useful shutil module that has the equivalent of the unix shell utilities? I think it would be nice to make things like 'grep' even... Here is my wish list. Each of these should implement a significant portion of what the GNU utils do. They should be robust, and give reasonable results, and reasonable exceptions. touch, chmod, chown, chgrp, touch df, du cp, dd, install, mv, rm, shred If there isn't an effort to make this, or if no one has done anything like this yet, I am willing to volunteer some time to do it. It would be really nice if they ended up being compatible with Windows and Macintosh - give them some powerful tools they didn't even know existed! Jonathan From robin at jessikat.fsnet.co.uk Fri Mar 1 12:57:17 2002 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Fri, 1 Mar 2002 11:57:17 +0000 Subject: win32+popen4 References: <$4LupWAmqsf8Ew0o@jessikat.fsnet.co.uk> <3C7F6765.94A82394@engcorp.com> Message-ID: In article <3C7F6765.94A82394 at engcorp.com>, Peter Hansen writes ..... > >I'm pretty sure the last time I checked the PROGRA~1 convention still >worked on WinNT. Are you sure this doesn't work on Win2K as well? >They're supposed to be the same thing, no? > >-Peter I'm sure it does and I guess that Program Files will always match as it's often the first. On the other hand working with a path name obtained from an execution path there's no guarantee I can always do the correct conversion by assuming ~1, some end up as ~2 etc. Is there a proper way to get the 8.3 name? -- Robin Becker From sjmachin at lexicon.net Fri Mar 1 13:07:26 2002 From: sjmachin at lexicon.net (John Machin) Date: 1 Mar 2002 04:07:26 -0800 Subject: Apology to Bill Gates (was Re: ASV module, CVS modules) References: <61ff32e3.0202281525.3e9bb102@posting.google.com> Message-ID: sjmachin at lexicon.net (John Machin) wrote in message news:... > > my_data.input_from_file("c:\test_data.csv", ASV.CSV(), > > File "C:\PYTHON22\ASV.py", line 222, in input_from_file > > file = open(input_file, "rb") > > IOError: invalid argument: rb > Bill behaving badly: Seems like Bill chucks a wobbly if there is > a_bloody_tab_character in a file name. I could be maligning Bill > unjustly; could be GvR & Co -- I'll have a look at the Python source > in a minute -- but I'd bet a couple of pots of beer that it's down to > Bill. Looks like the Windows compiler runtimes, enforcing the (sensible, IMO) Windows rule that file names shouldn't have "unprintable" characters in them, are faced with signalling the error with a least-bad choice of errno: ENOENT ("No such file or directory") or EINVAL ("Invalid argument"). Borland chose ENOENT, MS chose EINVAL. Python, starting from a Unix background, where there is evidently no such thing as an invalid character in a file name, can only imagine that EINVAL must refer to the mode argument, and in fact special-cases EINVAL (see below) to produce the error message that baffled (inter alia) the OP. if (errno == EINVAL) PyErr_Format(PyExc_IOError, "invalid argument: %s", mode); else PyErr_SetFromErrnoWithFilename(PyExc_IOError, name); However given what Tim P. said in a recent posting, I won't add to the patching bottleneck by rushing off to file an enhancement request on this one. From mwh at python.net Fri Mar 1 13:10:56 2002 From: mwh at python.net (Michael Hudson) Date: Fri, 1 Mar 2002 12:10:56 GMT Subject: import Random: NV_MAGICCONST deviates too much. References: <29575ad6.0202282330.16226275@posting.google.com> Message-ID: marijn at sanity.dhs.org (marijn Vriens) writes: > Hi all... > > I have get a strange exception when importing random. > I brought it down to: > > Python 2.1.2 (#1, Jan 18 2002, 18:05:45) > [GCC 2.95.4 (Debian prerelease)] on linux2 > Type "copyright", "credits" or "license" for more information. > >>> import gnome.ui > >>> import random > Traceback (most recent call last): > File "", line 1, in ? > File "/usr/lib/python2.1/random.py", line 93, in ? > _verify('NV_MAGICCONST', 1.71552776992141) > File "/usr/lib/python2.1/random.py", line 88, in _verify > raise ValueError( > ValueError: computed value for NV_MAGICCONST deviates too much > (computed 2,82843, expected 1) > >>> > > If I first import random and then gnome.ui I have no problems. my > distr is debian woody with the standard python packages (not > self-compiled) on an > AMD-K6 > > Anybody know what's going on ? At a guess, something in gnome.ui is buggering around with locale settings. Don't know if this actually helps -- I can't see quite how it could produce the above error... Cheers, M. -- The Internet is full. Go away. -- http://www.disobey.com/devilshat/ds011101.htm From fabi.kreutz at gmx.de Fri Mar 1 13:42:51 2002 From: fabi.kreutz at gmx.de (fabi.kreutz at gmx.de) Date: 1 Mar 2002 12:42:51 GMT Subject: SAX-Parser entity Message-ID: Hi, I spend the last 3 hours browsing FAQs and Mailinglist - without success - but have nevertheless the feeling, that this is a very easy question: I try to use the minidom XML-Parser to parse my little file in order to generate HTML Code. Being german, I really like to use Umlauts but minidom does not. Traceback (most recent call last): File "", line 1, in ? File "/usr/lib/python2.0/site-packages/_xmlplus/dom/minidom.py", line 908, in parse return _doparse(pulldom.parse, args, kwargs) File "/usr/lib/python2.0/site-packages/_xmlplus/dom/minidom.py", line 900, in _doparse toktype, rootNode = events.getEvent() File "/usr/lib/python2.0/site-packages/_xmlplus/dom/pulldom.py", line 251, in getEvent self.parser.feed(buf) File "/usr/lib/python2.0/site-packages/_xmlplus/sax/expatreader.py", line 92, in feed self._err_handler.fatalError(exc) File "/usr/lib/python2.0/site-packages/_xmlplus/sax/handler.py", line 38, in fatalError raise exception xml.sax._exceptions.SAXParseException: :29:19: not well-formed where Character 19 in Row 29 is the occurence of an ?. After browsing the FAQs I changed the default encoding in site.py to iso-8859-1, which had some nice effect, but not on minidom. Some more browsing let me tell pulldom to use StringIO instead of cStringIO, still no success. Since I want to use the text in HTML it would be enough, if I could use the ü instead, but parse gives me in this case ... File "/usr/lib/python2.0/site-packages/_xmlplus/sax/handler.py", line 38, in fatalError raise exception xml.sax._exceptions.SAXParseException: :29:19: undefined entity where 29:19 is the &. I tried to protected it with an \ or / but still no success. Can anybody help me with this? -- The irony of the Information Age is that it has given new respectability to uninformed opinion. - John Lawton From gerson.kurz at t-online.de Fri Mar 1 12:28:42 2002 From: gerson.kurz at t-online.de (Gerson Kurz) Date: Fri, 01 Mar 2002 11:28:42 GMT Subject: Import-Hook and subclassed file objects Message-ID: <3c7f65c2.357716562@news.isar.de> I want to create an import hook that reads data from encrypted files. To redirect the import hook, I do this: ----------- (snip here) ------------- # redirect import hook old_import_func = __import__ def my_import_func(name, globals=None, locals=None, fromlist=None): global old_import_func if name[:10] == "encrypted.": # todo: load encrypted module return imp.load_module(name, file, '', ('.dat','rb',imp.PY_SOURCE)) # use original code return old_import_func( name, globals, locals, fromlist ) __builtins__.__import__ = my_import_func import encrypted.test ----------- (snip here) ------------- (Of course, I'll use lambda for that in the final version ;) Anyway, I have two problems with that. imp.load_module expects a file object. But, Problem #1, the file object cannot be a subclassed "file-type" class. If I define my own file class, I get an error bad/closed file object. Looking at the PythonCore source, I find that the C runtime uses the raw FILE* and not abstract PyFile functions. See function "imp_load_module" in "Python\Import.c": converts Py-File-Object to raw FILE* and then uses that further on. I think I'll have a more deeper look at the python sources and see if I can add PyFileObject-style access. Problem #2, how do I subclass files? I try this: ----------- (snip here) ------------- class my_file_class(file): def read(self,size): # todo: add read implementation ----------- (snip here) ------------- the problem is - where to I subclass a file returned from open()? open() always returns the builtin file class. Attempting to do this ----------- (snip here) ------------- raw_file = open(...) my_file = my_file_class() raw_file.read = my_file.read ----------- (snip here) ------------- I'll get an error that read is a read-only method. From theller at python.net Fri Mar 1 13:54:28 2002 From: theller at python.net (Thomas Heller) Date: Fri, 1 Mar 2002 13:54:28 +0100 Subject: win32+popen4 References: <$4LupWAmqsf8Ew0o@jessikat.fsnet.co.uk> <3C7F6765.94A82394@engcorp.com> Message-ID: "Robin Becker" wrote in message news:gS1JDJAdy2f8EwUF at jessikat.demon.co.uk... > In article <3C7F6765.94A82394 at engcorp.com>, Peter Hansen > writes > ..... > > > >I'm pretty sure the last time I checked the PROGRA~1 convention still > >worked on WinNT. Are you sure this doesn't work on Win2K as well? > >They're supposed to be the same thing, no? > > > >-Peter > I'm sure it does and I guess that Program Files will always match as > it's often the first. On the other hand working with a path name > obtained from an execution path there's no guarantee I can always do the > correct conversion by assuming ~1, some end up as ~2 etc. > > Is there a proper way to get the 8.3 name? >>> import win32api >>> win32api.FindFiles(r"c:\Program Files") [(49, , , , 0, 0, 100, 1244528, ' Program Files', 'PROGRA~1')] >>> win32api.FindFiles(r"c:\Program Files")[0][-1] 'PROGRA~1' Thomas From hst at empolis.co.uk Fri Mar 1 14:06:21 2002 From: hst at empolis.co.uk (Harvey Thomas) Date: Fri, 1 Mar 2002 13:06:21 -0000 Subject: SAX-Parser entity Message-ID: <8FC4E7C302A6A64AAD5DB1FA0E825DEB220AEE@hendrix.empolisuk.com> I would guess that your document is in ISO 8859/1 (otherwise known as latin-1). XML parsers must be able to parse utf-8 and utf-16 and may support other encodings. If your parser supports latin-1 then modify the XML declaration. Otherwise use the codecs module. > -----Original Message----- > From: fabi.kreutz at gmx.de [mailto:fabi.kreutz at gmx.de] > Sent: 01 March 2002 12:43 > To: python-list at python.org > Subject: SAX-Parser entity > > > Hi, > > I spend the last 3 hours browsing FAQs and Mailinglist - > without success - > but have nevertheless the feeling, that this is a very easy question: > > I try to use the minidom XML-Parser to parse my little file > in order to > generate HTML Code. > Being german, I really like to use Umlauts but minidom does not. > Traceback (most recent call last): > File "", line 1, in ? > File > "/usr/lib/python2.0/site-packages/_xmlplus/dom/minidom.py", > line 908, in parse > return _doparse(pulldom.parse, args, kwargs) > File > "/usr/lib/python2.0/site-packages/_xmlplus/dom/minidom.py", > line 900, in _doparse > toktype, rootNode = events.getEvent() > File > "/usr/lib/python2.0/site-packages/_xmlplus/dom/pulldom.py", > line 251, in getEvent > self.parser.feed(buf) > File > "/usr/lib/python2.0/site-packages/_xmlplus/sax/expatreader.py" > , line 92, in feed > self._err_handler.fatalError(exc) > File > "/usr/lib/python2.0/site-packages/_xmlplus/sax/handler.py", > line 38, in fatalError > raise exception > xml.sax._exceptions.SAXParseException: :29:19: not > well-formed > > where Character 19 in Row 29 is the occurence of an ?. > > After browsing the FAQs I changed the default encoding in site.py to > iso-8859-1, which had some nice effect, but not on minidom. > Some more browsing let me tell pulldom to use StringIO > instead of cStringIO, > still no success. > > Since I want to use the text in HTML it would be enough, if I > could use > the ü instead, but parse gives me in this case > ... > File > "/usr/lib/python2.0/site-packages/_xmlplus/sax/handler.py", > line 38, in fatalError > raise exception > xml.sax._exceptions.SAXParseException: :29:19: > undefined entity > > where 29:19 is the &. > I tried to protected it with an \ or / but still no success. > > Can anybody help me with this? > > -- > The irony of the Information Age is that it has given > new respectability to uninformed opinion. > - John Lawton > -- > http://mail.python.org/mailman/listinfo/python-list > > _____________________________________________________________________ > This message has been checked for all known viruses by Star Internet > delivered through the MessageLabs Virus Scanning Service. For further > information visit http://www.star.net.uk/stats.asp or > alternatively call > Star Internet for details on the Virus Scanning Service. > _____________________________________________________________________ This message has been checked for all known viruses by the MessageLabs Virus Scanning Service. From skip at pobox.com Fri Mar 1 14:07:20 2002 From: skip at pobox.com (Skip Montanaro) Date: Fri, 1 Mar 2002 07:07:20 -0600 Subject: newbie lists and code examples for OOP. In-Reply-To: References: Message-ID: <15487.32008.202205.269512@12-248-41-177.client.attbi.com> Ale> Firstly: is there a better forum for newbie questions like this Ale> one? There are two mailing lists that might be of interest: python-help at python.org and tutor at python.org. They are described, respectively, at http://www.python.org/psa/MailingLists.html#help and http://www.python.org/psa/MailingLists.html#tutor choose-your-poison-ly, y'rs, -- Skip Montanaro (skip at pobox.com - http://www.mojam.com/) From usenet at thinkspot.net Fri Mar 1 14:04:44 2002 From: usenet at thinkspot.net (Sheila King) Date: Fri, 01 Mar 2002 05:04:44 -0800 Subject: newbie lists and code examples for OOP. References: Message-ID: On Fri, 01 Mar 2002 09:34:03 -0000, "skoria" wrote in comp.lang.python in article : > > I'm trying to write a class where one function calls a method in the > same class. Right now I'm doing this with trial and error, and I don't > really understand where I need to put parentheses, use (self), etc. I > can't find any "functional" examples of object oriented programming on > any online tutorials, or any simple programs already written that can > be used as a good tool to figure out how to call functions within > classes in python, when to use self.* what internal functions (like > __init__) can be used for. Lots of theory on this, but no functional > examples. For one thing: A beginner's forum would be the Tutor mailing list: http://mail.python.org/mailman/listinfo/tutor A good reference I would recommend for the type of stuff you are asking about: Core Python Programming by Wesley Chun. When to use self: Do you want the method to be called in the following way: object.method() where the method is always called by an instance of the object? Or would you like to be able to call it like this: method() without having to necessarily have an object to use that method? if the former, use "self". If the latter, don't use "self". Hope this answers some of your questions. Join the Tutor list and ask some more. You will get some good answers. -- Sheila King http://www.thinkspot.net/sheila/ "When introducing your puppy to an adult cat, restrain the puppy, not the cat." -- Gwen Bailey, _The Perfect Puppy: How to Raise a Well-behaved Dog_ From jhorneman at pobox.com Fri Mar 1 14:07:00 2002 From: jhorneman at pobox.com (Jurie Horneman) Date: 1 Mar 2002 05:07:00 -0800 Subject: fileinput not Unicode compatible? / UTF16 codec problems Message-ID: <9ac02e81.0203010507.377dba0d@posting.google.com> Is it possible that the fileinput module is not Unicode compatible? Because I have a little endian 16-bit Unicode file and have trouble reading it in. Decoding it with the UTF16 LE decoder gives me a 'truncated data' error. This is because the string ends with '0x0a' and '0x0a00'. The string is read in using the fileinput module, which apparently call C stdio getc(), which read a byte and not a 16-bit Unicode character. Oddly, this problem doesn't occur for every line. Is there a solution for this, apart from rewriting a number of modules myself? Is there any documentation on which Python modules are Unicode-aware or not? Oh, and how does one handle big endian / little endian Unicode when the UTF16 decoders look for BOMs at the start of each string, but I only have on at the start of the file? There seems to be no way for me to tell it which endianness I have, apart from circumventing the codec and calling the right version myself. Thanks, Jurie Horneman From jhorneman at pobox.com Fri Mar 1 14:08:40 2002 From: jhorneman at pobox.com (Jurie Horneman) Date: 1 Mar 2002 05:08:40 -0800 Subject: Trouble importing / using a custom text codec References: <9ac02e81.0202280152.5bb1bf25@posting.google.com> Message-ID: <9ac02e81.0203010508.4ebccd75@posting.google.com> Martin von Loewis wrote in message news:... > I recommend a different strategy. Aim for allowing "cp932" as an > encoding name. To achieve this, put the following (or something like > this) into MBCS_codecs/__init__.py Thanks. I had to actually solve the problem so I took my code out of the codecs and just called it directly, but at some point in the future I will try this approach. I'd still like to know why my approach didn't work, but oh well... > If you want this to happen at startup time of Python, just add a > MBCS_codecs.pth file in site-packages, which reads What is a .pth file? Jurie Horneman From skip at pobox.com Fri Mar 1 14:13:18 2002 From: skip at pobox.com (Skip Montanaro) Date: Fri, 1 Mar 2002 07:13:18 -0600 Subject: Apology to Bill Gates (was Re: ASV module, CVS modules) In-Reply-To: References: <61ff32e3.0202281525.3e9bb102@posting.google.com> Message-ID: <15487.32366.219011.387073@12-248-41-177.client.attbi.com> John> Python, starting from a Unix background, where there is evidently John> no such thing as an invalid character in a file name, ... I believe "/" is not allowed in Unix filenames. Not sure if this is escapable or not. I'm not going to take the chance of hosing my laptop's filesystem to find out. ;-) -- Skip Montanaro (skip at pobox.com - http://www.mojam.com/) From chris.gonnerman at newcenturycomputers.net Fri Mar 1 14:22:06 2002 From: chris.gonnerman at newcenturycomputers.net (Chris Gonnerman) Date: Fri, 1 Mar 2002 07:22:06 -0600 Subject: Can somebody kill getpathp for me? References: Message-ID: <005601c1c124$4bcb90a0$0101010a@local> ----- Original Message ----- From: "Tim Peters" > [Chris Gonnerman] > > In the PC subdir of the Python-2.1.2 build directory is a module > > called getpathp.c, which sets up the initial sys.path value. It > > is well known by Python programmers on Windows that the sys.path > > initialization includes directories plucked from special registry > > keys... unless you are using the PythonWare version. > > Or the PythonLabs distribution: while the core installer does set up a > registry entry containing "the usual" Python path, it *normally* never uses > it. Read the long comment block at the start of getpathp.c, and this time > believe that it means what it says . From robin at jessikat.fsnet.co.uk Fri Mar 1 14:21:30 2002 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Fri, 1 Mar 2002 13:21:30 +0000 Subject: win32+popen4 References: <$4LupWAmqsf8Ew0o@jessikat.fsnet.co.uk> <3C7F6765.94A82394@engcorp.com> Message-ID: In article , Thomas Heller writes ..... >> Is there a proper way to get the 8.3 name? > >>>> import win32api >>>> win32api.FindFiles(r"c:\Program Files") >[(49, , , >, 0, 0, 100, 1244528, ' >Program Files', 'PROGRA~1')] >>>> win32api.FindFiles(r"c:\Program Files")[0][-1] >'PROGRA~1' > >Thomas > > thanks, but it would still be better to get the popen methods to work properly wouldn't it? -- Robin Becker From erno-news at erno.iki.fi Fri Mar 1 14:27:31 2002 From: erno-news at erno.iki.fi (Erno Kuusela) Date: 01 Mar 2002 15:27:31 +0200 Subject: Useful, robust shell utilities References: Message-ID: In article , Jonathan Gardner writes: | Is there an effort to make a robust, useful shutil module that has the | equivalent of the unix shell utilities? yes, mostly. (there might be some missing system calls - but they are covered quite well). | I think it would be nice to make things like 'grep' even... | Here is my wish list. [...] you could use the existing utilities and save the trouble :) | If there isn't an effort to make this, or if no one has done anything like | this yet, I am willing to volunteer some time to do it. It would be really | nice if they ended up being compatible with Windows and Macintosh - give | them some powerful tools they didn't even know existed! you can get the real things for windows with cygwin. macintoshes are natively unix-based these days. if you decide to go ahead with it, you could look into for ideas and inspiration. -- erno From ron at ire.org Fri Mar 1 14:37:12 2002 From: ron at ire.org (ron nixon) Date: 1 Mar 2002 05:37:12 -0800 Subject: ASV module, CVS modules References: <61ff32e3.0202281525.3e9bb102@posting.google.com> Message-ID: <61ff32e3.0203010537.79082e89@posting.google.com> sjmachin at lexicon.net (John Machin) wrote in message news:... > ron at ire.org (ron nixon) wrote in message news:<61ff32e3.0202281525.3e9bb102 at posting.google.com>... > > Hello, I'm trying to use either of these two modules ASV by Laurence > > Tratt at http://tratt.net/laurie/python/asv/ and CSV by Dave Cole at > > http://object-craft.com.au/projects/csv/. I tried both of these and > > get this error: > > > > Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on win32 > > Type "copyright", "credits" or "license" for more information. > > IDLE 0.8 -- press F1 for help > > >>> import ASV > > >>> my_data = ASV.ASV() > > >>> my_data.input_from_file("c:\test_data.csv", ASV.CSV(), > > has_field_names =1) > > Traceback (most recent call last): > > File "", line 1, in ? > > my_data.input_from_file("c:\test_data.csv", ASV.CSV(), > > has_field_names =1) > > File "C:\PYTHON22\ASV.py", line 222, in input_from_file > > file = open(input_file, "rb") > > IOError: invalid argument: rb > > >>> > > > > I get a similar message from CSV module. Anyone use either of these > > and can tell me what's wrong? > > > > Wow. You have two problems. Bill Gates has one. And one of either you > or Dave Cole will get busted real soon now if you keep smoking that > stuff :-) > > To be more explicit: > > You 1: Don't clutter the root directory of your C: drive with anything > other than "necessary" directories, and files other than what Bill & > other software providers dump in there. > > You 2: On Windows, either use forward slashes "c:/test_data.csv" (it > works!) -- recommended -- or use raw strings r"c:\test_data.csv" if > you must. The problem is that Python's escape handling intervenes; > what Bill's software got to see in your case was equivalent to "C:" + > a_bloody_tab_character + "est_data.csv" !!! > > Bill behaving badly: Seems like Bill chucks a wobbly if there is > a_bloody_tab_character in a file name. I could be maligning Bill > unjustly; could be GvR & Co -- I'll have a look at the Python source > in a minute -- but I'd bet a couple of pots of beer that it's down to > Bill. > > You and/or Dave in peril of the law: Last time I saw Dave's module it > didn't presume to read files at all, it expected you to read lines and > pass them to it one at a time. So either Dave has had a very recent > rush of blood or something worse to the head and released unbeknownst > to me a file-handling version of his module, or you are gravely > mistaken when you assert "I get a similar message from CSV module". > > Hope this helps, > John John: Thanks a bunch. Let me try you suggestions and see if they work. It was late at night while I was trying this :). Maybe I should have had a beer. You're right about the CSV module, I didn't look at it carefully. Again, lack of beer. Ron From BPettersen at NAREX.com Fri Mar 1 14:42:59 2002 From: BPettersen at NAREX.com (Bjorn Pettersen) Date: Fri, 1 Mar 2002 06:42:59 -0700 Subject: Status of PEP's? Message-ID: <60FB8BB7F0EFC7409B75EEEC13E2019221514A@admin56.narex.com> > From: David Eppstein [mailto:eppstein at ics.uci.edu] > > In article , > James_Althoff at i2.com wrote: > > > For example, one problem I had when playing with an experimental > > implementation of the "middle argument" variant mentioned above is > > that the specific relational operators are tied to the > values of the > > bounds. If you want to iterate from the smaller value (up) to the > > larger value you write: > > > > for 1 <= var < 5: > > > > whereas if you want to iterate from the larger value (down) to the > > smaller value you have to turn things around and write: > > > > for 5 > var >= 1: > > > > which all looks very nice when you are dealing with literal > constants. > > But suppose you have variables for the bounds, "start" and "end"? > > Let's say I have a function > > > > def doSomethingFromTo(start,end): > > > > The function has to test to see which of "start" and "end" is the > > smaller value in order to know whether to execute a > for-loop with "<" > > or a for-loop with ">" (and the code specified in each separate > > for-loop has to be written redundantly). I found this to > be awkward. > > What's wrong with > for min(start,end) < var < max(start,end) Nothing at all, but with this syntax you have different semantics for: for start <= i < end: And if start <= i < end: One being an iterative construct, the other being a 'simple' comparison. I find that at least as confusing as integers producing iterators in iterative constructs. Of course, if anyone actually cared about this syntax, we would have a PEP with a pro/con section, so we wouldn't have to reiterate the same arguments over and over again -- bjorn From loewis at informatik.hu-berlin.de Fri Mar 1 14:50:12 2002 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 01 Mar 2002 14:50:12 +0100 Subject: fileinput not Unicode compatible? / UTF16 codec problems References: <9ac02e81.0203010507.377dba0d@posting.google.com> Message-ID: jhorneman at pobox.com (Jurie Horneman) writes: > Is it possible that the fileinput module is not Unicode compatible? That is certainly possible. You'd need to tell it the encoding for opening files; that is currently not supported. > Because I have a little endian 16-bit Unicode file and have trouble > reading it in. Decoding it with the UTF16 LE decoder gives me a > 'truncated data' error. I assume you first split the input into lines, then try the decoding? That does not work with UTF-16; you first need to decode, then split into lines. > Oddly, this problem doesn't occur for every line. No, but for every second line. The UTF-16 decoder will complain if you don't give it an even number of bytes. After the first line is read, the second will (incorrectly) start with a NUL byte, which fills this line to an even number of bytes, again. Decoding as UTF-16 will succeed, but will give you garbage: the wrong bytes will get grouped to form a character. > Is there a solution for this, apart from rewriting a number of modules > myself? As long as it is fileinput only, I recommend to rewrite your code to not use that module; this is probably simpler than rewriting the module to support encodings in full generality. Of course, patches will be welcome; if you do change fileinput, please submit a patch to sf.net/projects/python. > Is there any documentation on which Python modules are Unicode-aware > or not? Not that I'm aware of. In most cases, if issues become known, they problems will be corrected instead of being documented. > Oh, and how does one handle big endian / little endian Unicode when > the UTF16 decoders look for BOMs at the start of each string, but I > only have on at the start of the file? There seems to be no way for me > to tell it which endianness I have, apart from circumventing the codec > and calling the right version myself. You cannot decode UTF-16 on a line-by-line basis. Instead, you need to use a stream reader, which will remember the right encoding across .read or .readline invocations (only since Python 2.2, AFAIR). The most convenient way to open a Unicode stream is to use codecs.open, passing the encoding. In case of UTF-16, the endianness will be determined on first .read* invocation. HTH, Martin From loewis at informatik.hu-berlin.de Fri Mar 1 14:53:31 2002 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 01 Mar 2002 14:53:31 +0100 Subject: Trouble importing / using a custom text codec References: <9ac02e81.0202280152.5bb1bf25@posting.google.com> <9ac02e81.0203010508.4ebccd75@posting.google.com> Message-ID: jhorneman at pobox.com (Jurie Horneman) writes: > What is a .pth file? See http://www.python.org/doc/current/lib/module-site.html Regards, Martin From rstephens at vectron.com Fri Mar 1 15:14:48 2002 From: rstephens at vectron.com (Ron Stephens) Date: 1 Mar 2002 06:14:48 -0800 Subject: Black Adder and PyQt Message-ID: I am thinking of buying a "home" license of Black Adder, to use for making GUI's for Python programs to be used on Linux+KDE and also perhaps for the new Sharp Zaurus. Does anyone have any experience with Black Adder that they can share? One of my main reasons for wanting Black Adder is to use the GUI builder, so I am particualrly interested in opinions about that aspect of Black Adder, but I am also interested in other aspects as well. One question I have concerns licensing. If I buy the "home" version, could I still share my programs as GPL'ed open source, or would that require me to buy the "professional" license, which is much more expensive? In other words, my programs would never be used in any commercial way but I might want to post them as open source, free software. I know Black Adder is still in beta, but is it stable enoough to use already? I suppose I should ask how it compares to PythonWare amd WingIDE, but I kind of favor the PyQt toolkit becuase it will hopefully work well on the Sharp Zaurus as well as the KDE desktop. From DeepBleu at DeepBleu.org Fri Mar 1 15:13:32 2002 From: DeepBleu at DeepBleu.org (DeepBleu) Date: Fri, 1 Mar 2002 08:13:32 -0600 Subject: Deitel and Deitel Book... References: <3C7D8DCA.119D52EC@earthlink.net> <20020227163411.71b4b4d8.alex@netWindows.org> Message-ID: "Dennis Roark" wrote in message news:Xns91C39C93F933Edenroearthlinknet at 207.217.77.23... > Alex Russell wrote in > news:20020227163411.71b4b4d8.alex at netWindows.org: > [....................] >That the D & D book > came out in Python was more of an indication of Python going mainstream, > and for that I celebrate it. > This is the only saving grace of this book. What is so sad is that they'll end up making tons of money (to my knowledge, two of their books are textbooks: C++ and Java) with their money making publishing machines while someone like Mark Hammond can not find a job. Of course not to mention that they may be probably going ahead for plans for a book on Python (Complete Python Lab maybe) with a CD and start their won consulting business on Python. Rediculous! Then of course we'll see some professors assigning the D & D Python book as a textbook on a scripting language. How disgusting! DeepBleu From danielk at aracnet.com Fri Mar 1 15:02:04 2002 From: danielk at aracnet.com (Daniel Klein) Date: Fri, 01 Mar 2002 06:02:04 -0800 Subject: Socket connection manager Message-ID: Just wondering if there is a commercial product out there (written in Python of course) that maintains a pool of connections and keeps track of 'state' for web users. Thanks, Daniel Klein From mwh at python.net Fri Mar 1 15:18:43 2002 From: mwh at python.net (Michael Hudson) Date: Fri, 1 Mar 2002 14:18:43 GMT Subject: Apology to Bill Gates (was Re: ASV module, CVS modules) References: <61ff32e3.0202281525.3e9bb102@posting.google.com> Message-ID: Skip Montanaro writes: > John> Python, starting from a Unix background, where there is evidently > John> no such thing as an invalid character in a file name, ... > > I believe "/" is not allowed in Unix filenames. Not sure if this is > escapable or not. Don't think so. NULLs are out, too. Cheers, M. -- Presumably pronging in the wrong place zogs it. -- Aldabra Stoddart, ucam.chat From bkelley at wi.mit.edu Fri Mar 1 15:27:18 2002 From: bkelley at wi.mit.edu (Brian Kelley) Date: Fri, 01 Mar 2002 09:27:18 -0500 Subject: ASV module, CVS modules References: <61ff32e3.0202281525.3e9bb102@posting.google.com> <3C7F4014.7090800@stroeder.com> Message-ID: <3C7F8FC6.8090500@wi.mit.edu> Michael Str?der wrote: > John Machin wrote: > >> >> You 2: On Windows, either use forward slashes "c:/test_data.csv" (it >> works!) > > > AFAIK this does not work on W2K anymore. I might be wrong. > It does on my system at least. file = open("c:/test_data.csv", "wb") > Ciao, Michael. > Brian Kelley From bh at intevation.de Fri Mar 1 15:37:45 2002 From: bh at intevation.de (Bernhard Herzog) Date: 01 Mar 2002 15:37:45 +0100 Subject: PEP 276 (was Re: Status of PEP's?) References: Message-ID: <6q3czkqrpi.fsf@salmakis.intevation.de> James_Althoff at i2.com writes: > [Aahz Maruch] > > My primary complaint about the PEP is that the following idiom is > > awkward, ugly, and prone to misunderstanding: > > > > if i in 5: > > I will note this. > > However given that current Python seems able to do type-checking on strings > used with "in" as in, for example: > > >>> 1 in 'spam' > Traceback (most recent call last): > File "", line 1, in ? > TypeError: 'in ' requires character as left operand > >>> That's because strings implement the in operator. However, Python is smart enough to make in work for iterable objects. Quick experiment (Python 2.2): >>> from __future__ import generators >>> class MyInt(int): ... def __iter__(self): ... for i in range(self): ... yield i ... >>> num = MyInt(3) >>> for i in num: print i ... 0 1 2 >>> 1 in num 1 Bernhard -- Intevation GmbH http://intevation.de/ Sketch http://sketch.sourceforge.net/ MapIt! http://mapit.de/ From garret_mcgraw at yahoo.com Fri Mar 1 15:40:54 2002 From: garret_mcgraw at yahoo.com (garret_mcgraw) Date: Fri, 01 Mar 2002 14:40:54 -0000 Subject: I am not getting group messages Message-ID: I am not getting any group messages. Could any body tell me why? GM From marijn at sanity.dhs.org Fri Mar 1 15:48:29 2002 From: marijn at sanity.dhs.org (marijn Vriens) Date: 1 Mar 2002 06:48:29 -0800 Subject: gnome.ui is doing scary things.... Message-ID: <29575ad6.0203010648.3c2ec3d8@posting.google.com> Anybody know what is going on here?: Python 2.1.2 (#1, Jan 18 2002, 18:05:45) [GCC 2.95.4 (Debian prerelease)] on linux2 Type "copyright", "credits" or "license" for more information. >>> t = 10.5 >>> print t 10.5 >>> import gnome.ui >>> t = 10.5 >>> print t 10.0 >>> And how I can make it to stop doing this? IMHO this _VERY_ evil behavure, thank god I had unittests to catch it! Now how do I fix it? Ohh, and by the way my version of python-gnome is 1.4.1-17 in debian-woody. Thanks, Marijn. From aahz at panix.com Fri Mar 1 15:50:19 2002 From: aahz at panix.com (Aahz Maruch) Date: 1 Mar 2002 06:50:19 -0800 Subject: Deitel and Deitel Book... References: <3C7D8DCA.119D52EC@earthlink.net> <20020227163411.71b4b4d8.alex@netWindows.org> Message-ID: In article , Michael Hudson wrote: >Dennis Roark writes: >> >> The Python book appears substantially based on the templates of >> their previous books. > >Certainly the first draft of chapter 2 that I reviewed[0] looked >suspiciously like the corresponding chapter from Java:HTP. That went >back with a lot of red ink on it... All right, let me ask: are there any reviewers who think that PyHTP looks like a book written by Python programmers rather than a book written by Java programmers? >[0] My, there were a lot of reviewers weren't there? Yup. A lot of *opinionated* reviewers, at that. In all fairness, it's pretty clear that Deitel paid a fair amount of attention to our comments, but thought it was more important to stick with the style of their existing books. And, heck, they *did* pay well for my time. -- --- Aahz <*> (Copyright 2002 by aahz at pobox.com) Hugs and backrubs -- I break Rule 6 http://www.rahul.net/aahz/ Androgynous poly kinky vanilla queer het Pythonista "How come we choose from just two people for President but more than 50 for Miss America?" --AEN From tom at peresys.co.za Fri Mar 1 15:52:09 2002 From: tom at peresys.co.za (Tomasz Stochmal) Date: 1 Mar 2002 06:52:09 -0800 Subject: ADO GetRows() example for newbies Message-ID: #ADO GetRows() example import win32com.client import pprint def main(): ConnectionString = 'Provider=SQLOLEDB.1' \ +';Data Source=127.0.0.1' \ +';Initial Catalog=ZASecurities' \ +';User ID=sa' \ +';Password=' SQL='SELECT TOP 1 * FROM TESTCASE' DBConnection=win32com.client.Dispatch('ADODB.Connection') DBConnection.Open(ConnectionString) try: rs=win32com.client.Dispatch('ADODB.Recordset') rs.Open(SQL,DBConnection) try: # Info Row: Field Name/Type result=[] buf=[] for i in range(rs.Fields.Count): buf.append([rs.Fields.Item(i).Name,rs.Fields.Item(i).Type]) result.append(buf) # Data Rows if not rs.EOF: data=rs.GetRows() assert len(data) > 0 data=[[r[col] for r in data] for col in range(len(data[0]))] result.extend(data) finally: rs.Close() pprint.pprint(result) finally: DBConnection.Close() if __name__ == "__main__": main() # Change ConnectionString & SQL From Kevin.Smith at sas.com Fri Mar 1 15:31:34 2002 From: Kevin.Smith at sas.com (Kevin Smith) Date: 1 Mar 2002 14:31:34 GMT Subject: Swapping out sys.stdout globally Message-ID: <20020301093135467-0500@braeburn.na.sas.com> I am working on a command-line utility written in Python which daemonizes itself. In the process of daemonizing, sys.stdout and sys.stderr are redirected to now file-like objects as follows: sys.stdout = NewFile() sys.stderr = NewFile() However, I have some logging routines in a separate package that already have their own references to sys.stdout and sys.stderr which are unaffected by this. Is there a way to chonge where sys.stdout and sys.stderr print their output to and have this change affect all existing references? -- Kevin SmithKevin.Smith at sas.com From claird at starbase.neosoft.com Fri Mar 1 15:56:32 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 1 Mar 2002 08:56:32 -0600 Subject: Useful, robust shell utilities References: Message-ID: In article , Erno Kuusela wrote: >In article , Jonathan Gardner > writes: > >| Is there an effort to make a robust, useful shutil module that has the >| equivalent of the unix shell utilities? ... >| nice if they ended up being compatible with Windows and Macintosh - give >| them some powerful tools they didn't even know existed! > >you can get the real things for windows with cygwin. macintoshes are >natively unix-based these days. > >if you decide to go ahead with it, you could look into > for ideas and inspiration. ... Also . -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From robin at jessikat.fsnet.co.uk Fri Mar 1 15:54:22 2002 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Fri, 1 Mar 2002 14:54:22 +0000 Subject: win32+popen4 References: <$4LupWAmqsf8Ew0o@jessikat.fsnet.co.uk> <3C7F6765.94A82394@engcorp.com> Message-ID: In article , Robin Becker writes >In article , Thomas Heller > writes >..... >>> Is there a proper way to get the 8.3 name? >> >>>>> import win32api >>>>> win32api.FindFiles(r"c:\Program Files") >>[(49, , , >>, 0, 0, 100, 1244528, ' >>Program Files', 'PROGRA~1')] >>>>> win32api.FindFiles(r"c:\Program Files")[0][-1] >>'PROGRA~1' >> >>Thomas >> >> >thanks, but it would still be better to get the popen methods to work >properly wouldn't it? after investigation it seems that module nt is using cmd.exe /c string to run programs and I can't find any way to quote things in the string. A typically rubbish M$-ism. -- Robin Becker From theller at python.net Fri Mar 1 16:33:10 2002 From: theller at python.net (Thomas Heller) Date: Fri, 1 Mar 2002 16:33:10 +0100 Subject: win32+popen4 References: <$4LupWAmqsf8Ew0o@jessikat.fsnet.co.uk> <3C7F6765.94A82394@engcorp.com> Message-ID: "Robin Becker" wrote in message news:PtFyMdAeY5f8EwjI at jessikat.demon.co.uk... > after investigation it seems that module nt is using > cmd.exe /c string > > to run programs and I can't find any way to quote things in the string. > A typically rubbish M$-ism. > -- > Robin Becker On win2k it seems to be even documented (for the first time?): C:\sf\python>type "\Program Files\test.py" import sys print sys.argv C:\sf\python>cmd /c ""\Program Files\test.py" "1 2 3" 4 5 "6"" ['C:\\Program Files\\test.py', '1 2 3', '4', '5', '6'] and here are the rules: C:\sf\python>cmd /? Starts a new instance of the Windows 2000 command interpreter CMD [/A | /U] [/Q] [/D] [/E:ON | /E:OFF] [/F:ON | /F:OFF] [/V:ON | /V:OFF] [[/S] [/C | /K] string] /C Carries out the command specified by string and then terminates /K Carries out the command specified by string but remains /S Modifies the treatment of string after /C or /K (see below) /Q Turns echo off /D Disable execution of AutoRun commands from registry (see below) /A Causes the output of internal commands to a pipe or file to be ANSI /U Causes the output of internal commands to a pipe or file to be Unicode /T:fg Sets the foreground/background colors (see COLOR /? for more info) /E:ON Enable command extensions (see below) /E:OFF Disable command extensions (see below) /F:ON Enable file and directory name completion characters (see below) /F:OFF Disable file and directory name completion characters (see below) /V:ON Enable delayed environment variable expansion using c as the delimiter. For example, /V:ON would allow !var! to expand the variable var at execution time. The var syntax expands variables at input time, which is quite a different thing when inside of a FOR loop. /V:OFF Disable delayed environment expansion. Note that multiple commands separated by the command separator '&&' are accepted for string if surrounded by quotes. Also, for compatibility reasons, /X is the same as /E:ON, /Y is the same as /E:OFF and /R is the same as /C. Any other switches are ignored. If /C or /K is specified, then the remainder of the command line after the switch is processed as a command line, where the following logic is used to process quote (") characters: 1. If all of the following conditions are met, then quote characters on the command line are preserved: - no /S switch - exactly two quote characters - no special characters between the two quote characters, where special is one of: &<>()@^| - there are one or more whitespace characters between the the two quote characters - the string between the two quote characters is the name of an executable file. 2. Otherwise, old behavior is to see if the first character is a quote character and if so, strip the leading character and remove the last quote character on the command line, preserving any text after the last quote character. From mwh at python.net Fri Mar 1 16:33:30 2002 From: mwh at python.net (Michael Hudson) Date: Fri, 1 Mar 2002 15:33:30 GMT Subject: Deitel and Deitel Book... References: <3C7D8DCA.119D52EC@earthlink.net> <20020227163411.71b4b4d8.alex@netWindows.org> Message-ID: aahz at panix.com (Aahz Maruch) writes: > In article , Michael Hudson wrote: > >Dennis Roark writes: > >> > >> The Python book appears substantially based on the templates of > >> their previous books. > > > >Certainly the first draft of chapter 2 that I reviewed[0] looked > >suspiciously like the corresponding chapter from Java:HTP. That went > >back with a lot of red ink on it... > > All right, let me ask: are there any reviewers who think that PyHTP looks > like a book written by Python programmers rather than a book written by > Java programmers? Well, the published version looks less like this than the initial version, at least. What worried me more was the fact that it seems to cover 101 topics -- I have a feeling it might give a reader enough knowledge to be really dangerous in some areas, but no more. > >[0] My, there were a lot of reviewers weren't there? > > Yup. A lot of *opinionated* reviewers, at that. In all fairness, it's > pretty clear that Deitel paid a fair amount of attention to our > comments, but thought it was more important to stick with the style of > their existing books. Well, some of the things that struck me as odd might have some thought behind them -- the repitition being one of the more obvious. > And, heck, they *did* pay well for my time. Yeah, though I'll be happier when I actually get paid... (this is my first encounter with the IRS). And I now have the 2.2 source on my home box (which is currently sundered from the internet). Must find a book to review as 2.3 is being prepared . Cheers, M. -- The meaning of "brunch" is as yet undefined. -- Simon Booth, ucam.chat From skip at pobox.com Fri Mar 1 16:53:34 2002 From: skip at pobox.com (Skip Montanaro) Date: Fri, 1 Mar 2002 09:53:34 -0600 Subject: Swapping out sys.stdout globally In-Reply-To: <20020301093135467-0500@braeburn.na.sas.com> References: <20020301093135467-0500@braeburn.na.sas.com> Message-ID: <15487.41982.968248.121857@12-248-41-177.client.attbi.com> Kevin> sys.stdout = NewFile() Kevin> sys.stderr = NewFile() Kevin> However, I have some logging routines in a separate package that Kevin> already have their own references to sys.stdout and sys.stderr Kevin> which are unaffected by this. Sounds like they use something like from sys import stdout,stderr The best solution there would be for those packages to import sys in the usual fashion: import sys and refer to sys.stdout & sys.stderr. -- Skip Montanaro (skip at pobox.com - http://www.mojam.com/) From anthony_barker at hotmail.com Fri Mar 1 16:54:47 2002 From: anthony_barker at hotmail.com (Anthony_Barker) Date: 1 Mar 2002 07:54:47 -0800 Subject: proxy authentication: how to hide password References: <9ff6b66.0201250109.1c68a130@posting.google.com> <899f842.0202120818.11412d4b@posting.google.com> <9ff6b66.0202270901.3837af8b@posting.google.com> Message-ID: <899f842.0203010754.33ab63f2@posting.google.com> vtail - what about prompting the first time a script is run? store the password to a text file (or in the registry) and encrypt it. Anthony > I _feel_ bad - Perl didn't ask me any password when I run similar > script. Neither did I defined any environment variables. > > > prompt for the password if need be. > > That's so painful to enter your login&password every time the script > is running... ;-( Perl uses http_proxy env variable. > > Anyway, thanks for you ideas. > > Vtail From p.vrijlandt at aig.azn.nl Fri Mar 1 17:02:11 2002 From: p.vrijlandt at aig.azn.nl (Patrick Vrijlandt) Date: Fri, 1 Mar 2002 17:02:11 +0100 Subject: Telnet connection References: <8z9f2rks.fsf@fido.trinitycapital.com> Message-ID: The problem could of course be in insufficient negotiation capabilities of telnetlib. Again, you would find out by using your browser or the standard windows Telnet client. "Bengt Richter" schreef in bericht news:a5nmas$mfe$0 at 216.39.172.122... > On 28 Feb 2002 23:46:47 GMT, bokr at oz.net (Bengt Richter) wrote: > > >On Thu, 28 Feb 2002 19:51:06 +0100, "Riss Nicolas" wrote: > > > >>Has somebody a python program where it is an telnet connection ? > > > >You appear to be running windows. What happens if you get into your browser > >and put > > > > telnet://192.168.0.9:32 > > > >in the location (i.e., what you are trying to connect to with your code)? > >Do you get a telnet client screen with a login prompt? > > > >Did you try \r\n in place of plain \n in your code? > > > > Whoa, I just realized your program seems to be missing > a couple of lines for waiting for a user prompt and sending > the user name. > > After that, wait for the password prompt. At least > that is typical. Or do you have some special telnet server > setup that bypasses that? Maybe it still needs a \r\n to > trigger it past the missing user entry? It's hard to say > with so little info. > > Or copy from the screen of a manual login and successful > connect with a couple commands. (Do you connect to an ordinary > shell or some special program)? > > BTW, if you somehow have wrapped your telnet program execution > in a try: do_it() except: pass, you could be missing a bug-caused > exception discussed in another thread. You might want to try > changing line 424 of telnetlib.py. In the other thread I wrote: > > I suspect line 424 > self.msg('IAC %d not recognized' % ord(opt)) > should be > self.msg('IAC %d not recognized' % ord(c)) > > Regards, > Bengt Richter > PS., explain in French if that helps. Someone will translate if needed. > Maybe even if not needed ;-) > From sheershion at mailexpire.com Fri Mar 1 17:08:00 2002 From: sheershion at mailexpire.com (Robert Amesz) Date: Fri, 01 Mar 2002 16:08:00 -0000 Subject: win32+popen4 References: <$4LupWAmqsf8Ew0o@jessikat.fsnet.co.uk> Message-ID: Robin Becker wrote: > .... >> >>However, if you are on a 9x platform, and quoting the command just >>as you want the command interpreter to see it on the command line >>doesn't work, you might just want to revert to using the short >>(non-space) version of the name. So in your example you would >>replace "program files" with "progra~1" (or whatever it may be in >>the unlikely event it's different than that). >> >>-- >>-- David > this is win2k. I have tried quoting with "", but I still seem to > be getting > > no such command C:\program etc On Win98 I've found I had to quote *and* escape the quote characters, and - sometimes - backslashes too. I'm not sure if this is also the case on Win2000, but it's worth a try. This would yield something like: '\\"c:\\\\program files\\\\dimbo\\\\bongo.exe\\\\" \\"c:\\\\program files\\\\dumbo\\\\my file.dat\\"' Horrible, I know. Somewhere in the gizzards of Python there's some double parsing of the commandline going on. This is doubly insidious on Win98 as it pipes its data through a little program called win9xpopen.exe, which chokes when argc isn't exactly 2. Well, chokes isn't the right word: it pops up a dialog box, but when called from Python this dialog is invisible... Fun, ain't it? I'm not going to tell you how long it took me to find out this little quirk. I hope it's fixed in 2.2. And yes, I did report this behaviour a while back. Robert Amesz From marijn at sanity.dhs.org Fri Mar 1 17:07:43 2002 From: marijn at sanity.dhs.org (Marijn Vriens) Date: Fri, 01 Mar 2002 16:07:43 GMT Subject: import Random: NV_MAGICCONST deviates too much. References: <29575ad6.0202282330.16226275@posting.google.com> Message-ID: <3C7FA749.6090005@sanity.dhs.org> Michael Hudson wrote: > marijn at sanity.dhs.org (marijn Vriens) writes: > > >>Hi all... >> >>I have get a strange exception when importing random. >>I brought it down to: >> >>Python 2.1.2 (#1, Jan 18 2002, 18:05:45) >>[GCC 2.95.4 (Debian prerelease)] on linux2 >>Type "copyright", "credits" or "license" for more information. >> >>>>>import gnome.ui >>>>>import random >>>>> >>Traceback (most recent call last): >> File "", line 1, in ? >> File "/usr/lib/python2.1/random.py", line 93, in ? >> _verify('NV_MAGICCONST', 1.71552776992141) >> File "/usr/lib/python2.1/random.py", line 88, in _verify >> raise ValueError( >>ValueError: computed value for NV_MAGICCONST deviates too much >>(computed 2,82843, expected 1) >> >>If I first import random and then gnome.ui I have no problems. my >>distr is debian woody with the standard python packages (not >>self-compiled) on an >>AMD-K6 >> >>Anybody know what's going on ? >> > > At a guess, something in gnome.ui is buggering around with locale > settings. Don't know if this actually helps -- I can't see quite how > it could produce the above error... > The work-around for this is to set the LC_NUMERIC locale after importing gnome.ui. like so: >>> import locale >>> import gnome.ui >>> locale.setlocale(locale.LC_NUMERIC, 'C') 'C' >>> import random >>> Thanks for the people at #python for helping with this issue! Cheers, Marijn From anthony_barker at hotmail.com Fri Mar 1 17:12:21 2002 From: anthony_barker at hotmail.com (Anthony_Barker) Date: 1 Mar 2002 08:12:21 -0800 Subject: Deitel and Deitel Book... References: <3C7D8DCA.119D52EC@earthlink.net> Message-ID: <899f842.0203010812.6151d817@posting.google.com> "DeepBleu" wrote in message > Deitel and Deitel book on Python? I personally would not touch it. Give me > a book written by Lutz, Holden or Hammond any time. But not from the > establishment of Deitel. I bet you they do not even know how to program in > Python. All their books are churned out by what resembles an > industry-complex with standard issue. > Long ago I discovered a mistake in their old C++ How to Program. I sent > them an e-mail. The answer still brings vivd memories of when you feel like > throwing up. Arrogant bunch of oppurtunists who are not worth the price of > the paper their books are printed on. > You want books on Python: Buy Beazley, Lundh, Holden, Hammond, Greyson > etc.... > Leave Deitel alone! > DeepBleu I agree with you to a point. They don't seem passionate about programming, and the books are definitely cookie cutter. That said, more books on the python landscape is a good thing. And as the previous poster said, programming books are a personal thing. Personally I found a lot of the best material is online. Beazley's presentations are excellent, as is his dead tree book. Eckel's, "The thinking in Python", is very good. For beginners the "How to Think Like a Computer Scientist" I found better that most dead tree books (http://www.ibiblio.org/obp/thinkCSpy/). I would love to see books on Algorithms with Python (makes a perfect fit), and more advanced topics such as threads and extending python. From rsalz at zolera.com Fri Mar 1 17:19:55 2002 From: rsalz at zolera.com (Rich Salz) Date: 1 Mar 2002 08:19:55 -0800 Subject: importing C libraries, Solaris2.6, gcc2.95 :( Message-ID: <17214de2.0203010819.240c00d3@posting.google.com> I have a Solaris 2.6 machine, gcc 2.95.3 installed in /usr/local; /usr/local/bin is in my $PATH ; /usr/ccs/bin is not in my $PATH. I have python 2.1.1 sources; I did "./configure" with no flags. Attempting to import any library that includes a C shared library fails with the same backtrace: (gdb) bt 6 #0 0xef5a4674 in strlen () #1 0x64204 in PyString_FromString ( str=0xd26368

) at Objects/stringobject.c:89 #2 0x60da4 in PyDict_SetItemString (v=0xba68c, key=0xd26368
, item=0xc3cf8) at Objects/dictobject.c:1403 #3 0x37278 in Py_InitModule4 (name=0xadf5c "", methods=0xeed36790, doc=0x0, passthrough=0x0, module_api_version=802040) at Python/modsupport.c:57 #4 0xeed25b5c in init_tkinter () at /export/home/jjb/Python-2.1.1/Modules/_tkinter.c:2113 #5 0x35088 in _PyImport_LoadDynamicModule (name=0xefffef80 "_tkinter", pathname=0xefffea90 "/usr/local/lib/python2.1/lib-dynload/_tkinter.so", fp=0xab7c8) at ./Python/importdl.c:52 What am I doing wrong in building? Replies to me will be summarized, thanks! From eppstein at ics.uci.edu Fri Mar 1 17:21:04 2002 From: eppstein at ics.uci.edu (David Eppstein) Date: Fri, 01 Mar 2002 08:21:04 -0800 Subject: Status of PEP's? References: Message-ID: In article , "Bjorn Pettersen" wrote: > Nothing at all, but with this syntax you have different semantics for: > > for start <= i < end: > > And > > if start <= i < end: Different in what sense? "for something" loops over all values of the variable that make "something" true. Which part of "something" is the variable is determined by its location in the overall expression. That is true with the current "for x in y" syntax as well as the suggested "for start <= i < end" syntax. Well, except that by "all values" substitute "all integer values" since it doesn't make sense to loop over all floats. -- David Eppstein UC Irvine Dept. of Information & Computer Science eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/ From eppstein at ics.uci.edu Fri Mar 1 17:21:54 2002 From: eppstein at ics.uci.edu (David Eppstein) Date: Fri, 01 Mar 2002 08:21:54 -0800 Subject: Status of PEP's? References: Message-ID: In article , "Bjorn Pettersen" wrote: > Of course, if anyone actually cared about this syntax, we would have a > PEP with a pro/con section, so we wouldn't have to reiterate the same > arguments over and over again I was starting to think it might be time to write a PEP, but then Tim's comment about how he dislikes iterating over 3 discouraged me. -- David Eppstein UC Irvine Dept. of Information & Computer Science eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/ From landshark at verticaladdiction.net Fri Mar 1 17:37:22 2002 From: landshark at verticaladdiction.net (Dave Marotti) Date: Fri, 01 Mar 2002 16:37:22 -0000 Subject: what does this do? (really basic question) References: Message-ID: Daniel / Sean, Thanks for the great explaination and the links. I wasn't sure what to think of the syntax. I haden't seen the use of asterisks before in python code, and my background in C/C++ instantly made me think of pointers. I couldn't have been further from the truth. -dave >"kw" stands for "keyword", and what's being used is called a "keyword >argument". Keyword arguments allow us to pass parameters to a >function in a very general way. In the example above, the keyword >argument becomes a dictionary that captures any keyword variables that >"fall through the cracks" of a function call. -- +-----------------------------+----------------------------------------------+ | Dave Marotti | Looking for a Visio alternative for *nix? | | lndshark ! speakeasy net | Kivio : http://thekompany.com/projects/kivio | +-----------------------------+----------------------------------------------+ | I just don't trust anything | I suppose that in a few more hours I will | | that bleeds for 5 days and | sober up. That's such a sad thought. I think | | doesn't die. - Mr. Garrison | I'll have a few more drinks to prepare myself| +-----------------------------+----------------------------------------------+ From claird at starbase.neosoft.com Fri Mar 1 17:39:42 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 1 Mar 2002 10:39:42 -0600 Subject: Minor, minor style question Message-ID: <5F9A347EAC81A19E.F4E6D6813EA4DC98.17114695240B3A22@lp.airnews.net> Why would I prefer string = "" string = string + "abc " string = string + "def " string = string + "xyz" over string = "abc " + \ "def " + \ "xyz" ? I see a lot of the former in contexts I associate with Visual Basic- or JavaScript-majority folkways. Is there an attraction to the redundancy (and fragil- ity!) I'm missing? Are \-s *so* deprecated? -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From brueckd at tbye.com Fri Mar 1 18:21:04 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Fri, 1 Mar 2002 09:21:04 -0800 (PST) Subject: Swapping out sys.stdout globally In-Reply-To: <20020301093135467-0500@braeburn.na.sas.com> Message-ID: On 1 Mar 2002, Kevin Smith wrote: > I am working on a command-line utility written in Python which daemonizes > itself. In the process of daemonizing, sys.stdout and sys.stderr are > redirected to now file-like objects as follows: > > sys.stdout = NewFile() > sys.stderr = NewFile() > > However, I have some logging routines in a separate package that already > have their own references to sys.stdout and sys.stderr which are > unaffected by this. Is there a way to chonge where sys.stdout and > sys.stderr print their output to and have this change affect all existing > references? Nope - there's nothing magical about sys.stdout/err - they're just variables that reference objects. By rebinding them they lose knowledge of what they referenced previously, just as with any other variable. You need to rebind stdout/err as soon as your program starts, before any other modules load. Then as the others load they'll refer to your replacement objects. -Dave From vincent_a_primavera at netzero.net Fri Mar 1 12:49:40 2002 From: vincent_a_primavera at netzero.net (Vincent A. Primavera) Date: 01 Mar 2002 11:49:40 +0000 Subject: C-ISAM... Message-ID: <1014983381.22216.3.camel@del-vap-bos.ralphpill.com> Hello, Does anyone know of a module/api to access records from a C-ISAM database? Thank you, Vincent A. Primavera. From shalehperry at attbi.com Fri Mar 1 17:54:01 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Fri, 01 Mar 2002 08:54:01 -0800 (PST) Subject: Minor, minor style question In-Reply-To: <5F9A347EAC81A19E.F4E6D6813EA4DC98.17114695240B3A22@lp.airnews.net> Message-ID: On 01-Mar-2002 Cameron Laird wrote: > Why would I prefer > string = "" > string = string + "abc " > string = string + "def " > string = string + "xyz" > over > string = "abc " + \ > "def " + \ > "xyz" > ? I see a lot of the former in contexts I associate > with Visual Basic- or JavaScript-majority folkways. > Is there an attraction to the redundancy (and fragil- > ity!) I'm missing? Are \-s *so* deprecated? According to posts by people like Tim Peters the preferred idiom is more like: l = ["abc", "def", "xyz"] s = string.join("", l) i.e. build up a list of pieces through out the function and then join() them at the end. From ron at ire.org Fri Mar 1 17:50:42 2002 From: ron at ire.org (ron nixon) Date: 1 Mar 2002 08:50:42 -0800 Subject: Does python have a function like similar_text in PHP Message-ID: <61ff32e3.0203010850.3aedc22f@posting.google.com> List: Does anyone know if Python has a function like similar_text in PHP. It compares two strings and returns a percentage for the match. Anyone know of anything like this in Python and would be willing to send along an example? Ron From phd at phd.pp.ru Fri Mar 1 18:02:48 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Fri, 1 Mar 2002 20:02:48 +0300 Subject: Does python have a function like similar_text in PHP In-Reply-To: <61ff32e3.0203010850.3aedc22f@posting.google.com>; from ron@ire.org on Fri, Mar 01, 2002 at 08:50:42AM -0800 References: <61ff32e3.0203010850.3aedc22f@posting.google.com> Message-ID: <20020301200248.I25553@phd.pp.ru> On Fri, Mar 01, 2002 at 08:50:42AM -0800, ron nixon wrote: > Does anyone know if Python has a function like similar_text in PHP. It > compares two strings and returns a percentage for the match. Anyone > know of anything like this in Python and would be willing to send > along an example? --- >From mlh at idt.ntnu.no Fri Aug 27 18:06:22 1999 Date: 27 Aug 1999 15:51:03 +0200 From: Magnus L. Hetland To: python-list at python.org Newsgroups: comp.lang.python Subject: Re: Fuzzy string matching Status: RO X-Status: X-Keywords: X-UID: 1 Explanation of the distance algorithm... (Got a request for this, and thought I might as well post it...) The algorithm: def distance(a,b): c = {} n = len(a); m = len(b) for i in range(0,n+1): c[i,0] = i for j in range(0,m+1): c[0,j] = j for i in range(1,n+1): for j in range(1,m+1): x = c[i-1,j]+1 y = c[i,j-1]+1 if a[i-1] == b[j-1]: z = c[i-1,j-1] else: z = c[i-1,j-1]+1 c[i,j] = min(x,y,z) return c[n,m] It calculates the following: Given two strings, a and b, and three operations, adding, subtracting and exchanging single characters, what is the minimal number of steps needed to translate a into b? The method is based on the following idea: We want to find the distance between a[:x] and b[:y]. To do this, we first calculate 1) the distance between a[:x-1] and b[:y], adding the cost of a subtract-operation, used to get from a[:x] to a[:z-1]; 2) the distance between a[:x] and b[:y-1], adding the cost of an addition-operation, used to get from b[:y-1] to b[:y]; 3) the distance between a[:x-1] and b[:y-1], adding the cost of a *possible* exchange of the letter b[y] (with a[x]). The cost of the subtraction and addition operations are 1, while the exchange operation has a cost of 1 if a[x] and b[y] are different, and 0 otherwise. After calculating these costs, we choose the least one of them (since we want to use the best solution.) Instead of doing this recursively (i.e. calculating ourselves "back" from the final value), we build a cost-matrix c containing the optimal costs, so we can reuse them when calculating the later values. The costs c[i,0] (from string of length n to empty string) are all i, and correspondingly all c[0,j] (from empty string to string of length j) are j. Finally, the cost of translating between the full strings a and b (c[n,m]) is returned. I guess that ought to cover it... -- Magnus Making no sound / Yet smouldering with passion Lie The firefly is still sadder / Than the moaning insect Hetland : Minamoto Shigeyuki -- http://www.python.org/mailman/listinfo/python-list >From mlh at idt.ntnu.no Sun Aug 29 13:39:11 1999 Date: 28 Aug 1999 19:50:04 +0200 From: Magnus L. Hetland To: python-list at python.org Newsgroups: comp.lang.python Subject: Re: Fuzzy string matching? Status: RO X-Status: X-Keywords: X-UID: 2 Yet another version, without the append... def distance(a,b): "Calculates the Levenshtein distance between a and b." n, m = len(a), len(b) if n > m: # Make sure n <= m, to use O(min(n,m)) space a,b = b,a n,m = m,n current = range(n+1) for i in range(1,m+1): previous, current = current, [i]+[0]*m for j in range(1,n+1): add, delete = previous[j]+1, current[j-1]+1 change = previous[j-1] if a[j-1] != b[i-1]: change = change + 1 current[j] = min(add, delete, change) return current[n] I *could* have written [i]*(m+1) - but I thought this was clearer... :) -- Magnus Making no sound / Yet smouldering with passion Lie The firefly is still sadder / Than the moaning insect Hetland : Minamoto Shigeyuki -- http://www.python.org/mailman/listinfo/python-list --- Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From webmaster at greich.co.uk Fri Mar 1 06:01:53 2002 From: webmaster at greich.co.uk (David Russell) Date: Fri, 1 Mar 2002 05:01:53 -0000 Subject: Python's Syntax Message-ID: Hi, I can't get my head around Python's syntax for the if, for, while etc. statements. I'm used to the classic: if (condition == TRUE) { Do this } else { Do this } I've had a look at a couple of tutorials for Python and it appears like this: if condition == TRUE: do this How do you tell it when to stop? I just can't figure out how to do it. Could somebody explain it to me please, even though I have a strange suspicious that it is one of the simplest deatils imaginable. Also, another thing about Python's syntax. Are statements just sperated by their lines, or do they have some form of seperator (like a semi-colon)? Thanks for any help, it is appreciated. (Sorry if this appears twice, the first time I sent it I got an error so I'm not sure if both will show up) From matthias_j at lycos.com Fri Mar 1 18:08:22 2002 From: matthias_j at lycos.com (Matthias Janes) Date: 1 Mar 2002 09:08:22 -0800 Subject: Can't seem to get it right: Win NT registry save and load Message-ID: Hi I would like in a python script to save a Win NT Registry entry to a file and load it later - but it's seems I can't get it right. win32api.RegSaveKey RegSaveKey(key, filename, sa) I could not realy figure out the 3 part (sa ) get always a error about the security rights. after I saved it how could I load it again? Any Help would be real nice. Matthias Janes From justin at iago.org Fri Mar 1 18:14:54 2002 From: justin at iago.org (Justin Sheehy) Date: Fri, 01 Mar 2002 12:14:54 -0500 Subject: Minor, minor style question In-Reply-To: <5F9A347EAC81A19E.F4E6D6813EA4DC98.17114695240B3A22@lp.airnews.net> (claird@starbase.neosoft.com's message of "1 Mar 2002 10:39:42 -0600") References: <5F9A347EAC81A19E.F4E6D6813EA4DC98.17114695240B3A22@lp.airnews.net> Message-ID: claird at starbase.neosoft.com (Cameron Laird) writes: > Why would I prefer > string = "" > string = string + "abc " > string = string + "def " > string = string + "xyz" > over > string = "abc " + \ > "def " + \ > "xyz" > ? If those really are the two things being compared, there's a far better option: >>> string = ("abc" ... "def" ... "xyz") >>> string 'abcdefxyz' > I see a lot of the former in contexts I associate > with Visual Basic- or JavaScript-majority folkways. > Is there an attraction to the redundancy (and fragil- > ity!) I'm missing? Are \-s *so* deprecated? I can't stand either of the two styles you quoted. They are both ugly and more work than is needed. The first one also creates a potentially large number of wasteful intermediate strings. -Justin From donn at u.washington.edu Fri Mar 1 17:51:47 2002 From: donn at u.washington.edu (Donn Cave) Date: 1 Mar 2002 16:51:47 GMT Subject: Useful, robust shell utilities References: Message-ID: Quoth Jonathan Gardner : | I tried to use the shutil module... and to tell you the truth, it stinks. | Is there an effort to make a robust, useful shutil module that has the | equivalent of the unix shell utilities? Go ahead. Then keep an eye out on comp.lang.python, and after some years pass finally someone will mention it: "it stinks", they'll say, with no particular explanation. | I think it would be nice to make things like 'grep' even... | | Here is my wish list. Each of these should implement a significant portion | of what the GNU utils do. They should be robust, and give reasonable | results, and reasonable exceptions. | | touch, chmod, chown, chgrp, touch | df, du | cp, dd, install, mv, rm, shred Some of them are essentially POSIX 1003.1 functions, hence supported in the posix module (which we usually call "os" so it will appear that these functions are supported on all platforms, whether they really are or not.) chmod == chmod() chown == chown() chgrp == chown() rm == unlink() mv == rename() dd ~= read(), write(), lseek() df == fstatvfs() Donn Cave, donn at u.washington.edu From justin at iago.org Fri Mar 1 18:18:22 2002 From: justin at iago.org (Justin Sheehy) Date: Fri, 01 Mar 2002 12:18:22 -0500 Subject: Python's Syntax In-Reply-To: ("David Russell"'s message of "Fri, 1 Mar 2002 05:01:53 -0000") References: Message-ID: "David Russell" writes: > if condition == TRUE: > do this > > > How do you tell it when to stop? I just can't figure out how to do it. Could > somebody explain it to me please, even though I have a strange suspicious > that it is one of the simplest deatils imaginable. Just return to the previous indent level. For instance: if test: line1 line2 line3 line4 Lines 1-3 will be executed inside the if clause, and line4 follws it. Python's logical blocks are delimited by indentation. > Also, another thing about Python's syntax. Are statements just sperated by > their lines, or do they have some form of seperator (like a semi-colon)? Either. You may place multiple statements on one line and delimit them with a semicolon. -Justin From max at alcyone.com Fri Mar 1 18:10:43 2002 From: max at alcyone.com (Erik Max Francis) Date: Fri, 01 Mar 2002 09:10:43 -0800 Subject: Python's Syntax References: Message-ID: <3C7FB613.BA4B2A7A@alcyone.com> David Russell wrote: > I've had a look at a couple of tutorials for Python and it appears > like > this: > > if condition == TRUE: > do this > > How do you tell it when to stop? I just can't figure out how to do it. > Could > somebody explain it to me please, even though I have a strange > suspicious > that it is one of the simplest deatils imaginable. That's an if statement, there's no "stopping" involved; it simply tests the condition and then executes the "then" clause if it evaluates to true. You probably meant somethinng like a while loop: while condition: statements this continues to execute the statements while condition evaluates to true. It's precisely the same as C's while (condition) { statements } > Also, another thing about Python's syntax. Are statements just > sperated by > their lines, or do they have some form of seperator (like a > semi-colon)? You can use semicolons to separate multiple statements on the same line: x = 1; print x -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Laws are silent in time of war. \__/ Cicero Esperanto reference / http://www.alcyone.com/max/lang/esperanto/ An Esperanto reference for English speakers. From sam_collett at lycos.co.uk Fri Mar 1 18:12:40 2002 From: sam_collett at lycos.co.uk (Sam Collett) Date: 1 Mar 2002 09:12:40 -0800 Subject: Javascript to Python Message-ID: <2030665d.0203010912.1bb9c0ae@posting.google.com> Does anyone know of any good sites on Javascript > Python examples? I have a function in javascript that returns the file extension: function FileExtension(sFilePath) { return Right(sFilePath,sFilePath.length-sFilePath.lastIndexOf(".")) } so FileExtension("/path/to/file.doc") would return .doc I would also want to return the filename (file) and the path (/path/to/). How would I go about that? What equivalents to the functions Right and Left (right side of string, left side of string) Also is there an easier way to do number incrementing (just me being lazy): while r<5 print r r=r+1 I have tried r++ to add 1 each time, and r-- to take away one, but this does not work, so is the only way r=r+1 or r=r-1 ? TIA From jhorneman at pobox.com Fri Mar 1 18:15:36 2002 From: jhorneman at pobox.com (Jurie Horneman) Date: 1 Mar 2002 09:15:36 -0800 Subject: fileinput not Unicode compatible? / UTF16 codec problems References: <9ac02e81.0203010507.377dba0d@posting.google.com> Message-ID: <9ac02e81.0203010915.5c170f1f@posting.google.com> Martin von Loewis wrote in message news:... > I assume you first split the input into lines, then try the decoding? > That does not work with UTF-16; you first need to decode, then split > into lines. Your assumption is correct :) And your explanation of what the UTF-16 decoder is doing makes a lot of sense. > As long as it is fileinput only, I recommend to rewrite your code to > not use that module; this is probably simpler than rewriting the > module to support encodings in full generality. That's what I did. I basically wrote a function that takes a path and returns a list of strings. It's not the cleanest design right now, but it works. > You cannot decode UTF-16 on a line-by-line basis. Instead, you need to > use a stream reader, which will remember the right encoding across > .read or .readline invocations (only since Python 2.2, AFAIR). The > most convenient way to open a Unicode stream is to use codecs.open, > passing the encoding. In case of UTF-16, the endianness will be > determined on first .read* invocation. OK, that makes sense. I'll keep that (and your other remarks) in mind when I refactor what I have now. Thanks a lot for your help! Jurie Horneman From alien275 at libertysurf.fr Fri Mar 1 18:21:13 2002 From: alien275 at libertysurf.fr (Riss Nicolas) Date: Fri, 1 Mar 2002 18:21:13 +0100 Subject: Ping Message-ID: Bonjour, on ma dit que je pouvais ?crire en francais alors j'?crit en francais. Je voudrais pouvoir v?rifier toutes les 5 min que une machine ping une autre machine et si elle ne ping pas qu'elle execute un script. Comment faut il faire avec python pour pinger une machine et v?rifier qu'elle r?pond?? Merci de votre aide. From shalehperry at attbi.com Fri Mar 1 18:19:52 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Fri, 01 Mar 2002 09:19:52 -0800 (PST) Subject: Python's Syntax In-Reply-To: Message-ID: > Also, another thing about Python's syntax. Are statements just sperated by > their lines, or do they have some form of seperator (like a semi-colon)? > read some more on http://www.python.org. Python is whitespace delimited. Your if statement above knew when to stop because you stopped indenting. if test: do() something() here() else: maybe() other() thing() more() Most of us who like coding in python appreciate this syntax because it makes for easier rapid development. No worrying about braces, semi-colons, etc. I just type and and type and it works. This also gets rid of the dangling else issue in languages like C. Takes some getting used to, but if it works for you, using another language feels odd. From fabi.kreutz at gmx.de Fri Mar 1 18:20:10 2002 From: fabi.kreutz at gmx.de (fabi.kreutz at gmx.de) Date: 1 Mar 2002 17:20:10 GMT Subject: SAX-Parser entity References: Message-ID: Hi, Harvey! Ahh, utf-16 sounds good. Thanks, I have at least one solution: Reading the xml-file into a buffer and convert it to utf-16. minidom is then able to parse the whole thing and saves the strings in unicode, which is fine again. I do not understand the part with "If your parser supports...". As it seems to me, the minidom default parser does not support ISO 8859/1 and even unicode makes problems only. I didn't know, you can reprogram the parser so easily. Anyway, thanks a lot. Bye Fabian Harvey Thomas wrote: > I would guess that your document is in ISO 8859/1 (otherwise known as > latin-1). XML parsers must be able to parse utf-8 and utf-16 and may > support other encodings. If your parser supports latin-1 then modify the > XML declaration. Otherwise use the codecs module. >> Problem: >> I try to use the minidom XML-Parser to parse my little file >> in order to generate HTML Code. >> Being german, I really like to use Umlauts but minidom does not. >> ... >> Traceback (most recent call last): >> "/usr/lib/python2.0/site-packages/_xmlplus/sax/handler.py", >> line 38, in fatalError >> raise exception >> xml.sax._exceptions.SAXParseException: :29:19: not well-formed >> >> where Character 19 in Row 29 is the occurence of an ?. From christophe.delord at free.fr Fri Mar 1 18:22:50 2002 From: christophe.delord at free.fr (Christophe Delord) Date: Fri, 01 Mar 2002 18:22:50 +0100 Subject: Python's Syntax References: Message-ID: <3C7FB8EA.8060005@free.fr> Hi, If your question is about block separators, just read the documentation for further details : http://www.python.org/doc/current/ref/indentation.html Lines with the same indentation are in the same block: if condition: inst1 # do this if true inst2 # do this if true else: inst3 # do this if false inst4 # always do this David Russell wrote: > Hi, > > I can't get my head around Python's syntax for the if, for, while etc. > statements. > > I'm used to the classic: > > if (condition == TRUE) > { > Do this > } > else > { > Do this > } > > I've had a look at a couple of tutorials for Python and it appears like > this: > > if condition == TRUE: > do this > > > How do you tell it when to stop? I just can't figure out how to do it. Could > somebody explain it to me please, even though I have a strange suspicious > that it is one of the simplest deatils imaginable. > > Also, another thing about Python's syntax. Are statements just sperated by > their lines, or do they have some form of seperator (like a semi-colon)? > > > Thanks for any help, it is appreciated. > > (Sorry if this appears twice, the first time I sent it I got an error so I'm > not sure if both will show up) > > > > > > -- Christophe Delord http://christophe.delord.free.fr/ From shalehperry at attbi.com Fri Mar 1 18:26:44 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Fri, 01 Mar 2002 09:26:44 -0800 (PST) Subject: Javascript to Python In-Reply-To: <2030665d.0203010912.1bb9c0ae@posting.google.com> Message-ID: On 01-Mar-2002 Sam Collett wrote: > Does anyone know of any good sites on Javascript > Python examples? > I have a function in javascript that returns the file extension: > > function FileExtension(sFilePath) > { > return Right(sFilePath,sFilePath.length-sFilePath.lastIndexOf(".")) > } > > so FileExtension("/path/to/file.doc") would return .doc > I would also want to return the filename (file) and the path > (/path/to/). How would I go about that? > import os, os.path >>> filename = '/path/to/foo.doc' >>> os.path.splitext(filename) ('/path/to/foo', '.doc') >>> os.path.splitext(os.path.basename(filename)) ('foo', '.doc') >>> os.path.basename(filename) 'foo.doc' >>> os.path.splitext(filename) ('/path/to/foo', '.doc') >>> os.path.splitext(os.path.basename(filename)) ('foo', '.doc') os.path has a bunch of nice path related tools like abspath() and join(). Check out the python docs. > What equivalents to the functions Right and Left (right side of > string, left side of string) > sorry, not quite sure what the Right side of a string is (-: > Also is there an easier way to do number incrementing (just me being > lazy): > while r<5 > print r > r=r+1 > > I have tried r++ to add 1 each time, and r-- to take away one, but > this does not work, so is the only way r=r+1 or r=r-1 ? > in python 1.5.2 and earlier the only way was r = r + 1. In the 2.x series the += operator was added (I think this works in javascript too, it works in most C like languages) r += 1. There is equivalents for the other standard math ops. From robin at jessikat.fsnet.co.uk Fri Mar 1 18:24:02 2002 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Fri, 1 Mar 2002 17:24:02 +0000 Subject: win32+popen4 References: <$4LupWAmqsf8Ew0o@jessikat.fsnet.co.uk> <3C7F6765.94A82394@engcorp.com> Message-ID: <2vec8LAyk7f8EwEi@jessikat.demon.co.uk> In article , Thomas Heller writes >"Robin Becker" wrote in message news:PtFyMdAeY5f8Ew >jI at jessikat.demon.co.uk... >> after investigation it seems that module nt is using >> cmd.exe /c string >> >> to run programs and I can't find any way to quote things in the string. >> A typically rubbish M$-ism. >> -- >> Robin Becker > >On win2k it seems to be even documented (for the first time?): wow, well there's hope yet. I of course looked in the win2k help which is shorter than the /? output. I used this function to quote for passing to system def _quote(*args): fmt = max(map(lambda s: len(string.split(s)), args))>1 and '"%s"' or '%s' return fmt % string.join(map(lambda s: len(string.split(s))>1 and '"%s"' % s or s, args),' ') then I can do system(_quote(r'c:\program files\bingo\bango.exe', r'c:\test dir\my rubbish.txt')) and it seems to work. I guess spaces in filenames might be a pain everywhere in win32 land. Does the same work in other win32's? -- Robin Becker From cmaloney at physics.ucsb.edu Fri Mar 1 18:25:46 2002 From: cmaloney at physics.ucsb.edu (Craig Maloney) Date: 1 Mar 2002 09:25:46 -0800 Subject: Scripting C++ -- 2 -- a more concrete example. References: <3C7E6642.2030202@physics.ucsb.edu> Message-ID: <6bf54244.0203010925.38d237ed@posting.google.com> Donovan Rebbechi wrote in message news:... > In article <3C7E6642.2030202 at physics.ucsb.edu>, Craig Maloney wrote: > > If using a wrapper generator (e.g. SILOON) I don't see a way around the > > marshalling of the call to get at the atom data structure. > > I don't really understand exactly what the problem is. > > > > Of course, this would be taken care of by a revamp of the design of the > > class library... maybe making the crystal an atom factory that produces > > new atoms in its own address space. But I would like to avoid thinking > > Now I'm really confused. If you're not using CORBA, the atoms are in the > same address space, aren't they ? This is how I presumed that Boost also worked -- I must be mistaken. After having seen yours and Ralf's comments, I now have the impression that Boost works it's magic differently. Perhaps Craig Rasmussen could enlighten us as to how SILOON deals with co-location issues such as the one above? From fabi.kreutz at gmx.de Fri Mar 1 18:26:59 2002 From: fabi.kreutz at gmx.de (fabi.kreutz at gmx.de) Date: 1 Mar 2002 17:26:59 GMT Subject: Python's Syntax References: Message-ID: Hi, > if condition == TRUE: > do this > How do you tell it when to stop? I just can't figure out how to do it. It's the identation that "closes the brackets". Like this: if condition: do something so something else continue indepently from condition programm cntinues Just try to change the identation slightly, you will get an parser error, if it does not fit: if condition: idented wrong-idented > Also, another thing about Python's syntax. Are statements just sperated by > their lines, or do they have some form of seperator (like a semi-colon)? Ah, this question is already aswered :) Bye From sam_collett at lycos.co.uk Fri Mar 1 18:27:09 2002 From: sam_collett at lycos.co.uk (Sam Collett) Date: 1 Mar 2002 09:27:09 -0800 Subject: ADO GetRows() example for newbies References: Message-ID: <2030665d.0203010927.38edc51@posting.google.com> How could you do pages of records (in ASP for example), you may only want a few records at a time (if you have 1000 records for example)? For example I may want a page with 10 records per page, with the page numbers at the bottom. For 100 records: 10 pages (10 links) Start at 1 on page 1, 11 on page 2 etc) TIA tom at peresys.co.za (Tomasz Stochmal) wrote in message news:... > #ADO GetRows() example > > import win32com.client > import pprint > > def main(): > ConnectionString = 'Provider=SQLOLEDB.1' \ > +';Data Source=127.0.0.1' \ > +';Initial Catalog=ZASecurities' \ > +';User ID=sa' \ > +';Password=' > > SQL='SELECT TOP 1 * FROM TESTCASE' > > DBConnection=win32com.client.Dispatch('ADODB.Connection') > DBConnection.Open(ConnectionString) > try: > rs=win32com.client.Dispatch('ADODB.Recordset') > rs.Open(SQL,DBConnection) > try: > # Info Row: Field Name/Type > result=[] > buf=[] > for i in range(rs.Fields.Count): > buf.append([rs.Fields.Item(i).Name,rs.Fields.Item(i).Type]) > > result.append(buf) > > # Data Rows > if not rs.EOF: > data=rs.GetRows() > assert len(data) > 0 > data=[[r[col] for r in data] for col in range(len(data[0]))] > result.extend(data) > finally: > rs.Close() > > pprint.pprint(result) > finally: > DBConnection.Close() > > > if __name__ == "__main__": > main() > > > # Change ConnectionString & SQL From webmaster at greich.co.uk Fri Mar 1 06:29:14 2002 From: webmaster at greich.co.uk (David Russell) Date: Fri, 1 Mar 2002 05:29:14 -0000 Subject: Python's Syntax References: Message-ID: Thanks, I think I get it now. From sdm7g at Virginia.EDU Fri Mar 1 18:36:29 2002 From: sdm7g at Virginia.EDU (Steven Majewski) Date: Fri, 1 Mar 2002 12:36:29 -0500 (EST) Subject: Useful, robust shell utilities In-Reply-To: Message-ID: On 1 Mar 2002, Donn Cave wrote: > Quoth Jonathan Gardner : > > | I think it would be nice to make things like 'grep' even... > | > | Here is my wish list. Each of these should implement a significant portion > | of what the GNU utils do. They should be robust, and give reasonable > | results, and reasonable exceptions. > | > | touch, chmod, chown, chgrp, touch > | df, du > | cp, dd, install, mv, rm, shred > > Some of them are essentially POSIX 1003.1 functions, hence supported in > the posix module (which we usually call "os" so it will appear that these > functions are supported on all platforms, whether they really are or not.) > > chmod == chmod() > chown == chown() > chgrp == chown() > rm == unlink() > mv == rename() > dd ~= read(), write(), lseek() > df == fstatvfs() > ... And some like 'dd' have a zillion options mainly because they are command line tools and aren't programmable on any finer scale. In python, it would be easier to just write a little function that does exactly what you want than it would be to remember all of the various option switches. -- Steve Majewski From logiplexsoftware at earthlink.net Fri Mar 1 18:39:40 2002 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Fri, 1 Mar 2002 09:39:40 -0800 Subject: python-list, FOR YOUR PRIVATE EYES ONLY !!!! In-Reply-To: <3c83f152.44429506@127.0.0.1> References: <3c7f623f.7801758@127.0.0.1> <3c7ee303$1_2@corp.newsgroups.com> <3c83f152.44429506@127.0.0.1> Message-ID: <20020301093940.0e5b7e29.logiplexsoftware@earthlink.net> On Fri, 01 Mar 2002 03:07:22 GMT (Five Fresh) Fish wrote: > On Thu, 28 Feb 2002 21:20:15 -0500, "Joshua Muskovitz" > wrote: > > >> Damn. And here I thought I was getting an invitation to join the PSU. > > > >You are. This is just one of the perks, along with > > > > [hands to face, look of aghast horror] > > Omigosh, ohno... I blew it! I blew my chance. Now they'll never invite me > into their elite echelons. > > Sigh. > > Well, then, I guess it's porn for me after all... And they'll make you change your name to something like "Peter Python". But I hear the money's good... -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From wayne at mishre.com Fri Mar 1 19:05:48 2002 From: wayne at mishre.com (Wayne Pierce) Date: Fri, 01 Mar 2002 10:05:48 -0800 Subject: Black Adder and PyQt References: Message-ID: <3C7FC2FC.4040304@mishre.com> Ron Stephens wrote: > I am thinking of buying a "home" license of Black Adder, to use for > making GUI's for Python programs to be used on Linux+KDE and also > perhaps for the new Sharp Zaurus. Does anyone have any experience with > Black Adder that they can share? One of my main reasons for wanting > Black Adder is to use the GUI builder, so I am particualrly interested > in opinions about that aspect of Black Adder, but I am also interested > in other aspects as well. I really like the GUI builder of BA, unfortunately I think it could use more work. Granted it is __still__ in beta, but it's been in beta for quite a while without an update. When I do GUI development I typically do the first part in BA, then manually add in the GUI pieces that BA doesn't support directly yet (like menus). The only thing I don't like about the GUI builder is that it doesn't support a lot of widgets yet. The last I heard they were waiting for Qt3. > One question I have concerns licensing. If I buy the "home" version, > could I still share my programs as GPL'ed open source, or would that > require me to buy the "professional" license, which is much more > expensive? In other words, my programs would never be used in any > commercial way but I might want to post them as open source, free > software. As I understand it, the only restriction on redistribution is if you are distributing commercial apps. Then you need the business edition to redistribute Qt and the other modules. It might be good to get the scoop directly from them on this since I got the business edition and haven't had to worry about it. > I know Black Adder is still in beta, but is it stable enoough to use > already? I suppose I should ask how it compares to PythonWare amd > WingIDE, but I kind of favor the PyQt toolkit becuase it will > hopefully work well on the Sharp Zaurus as well as the KDE desktopI haven't had too many problems with BA's stability; typically I use BA for the GUI design and syntax highlighting then compile and test in a shell. I've had some lockups when using the run from within BA in the past, not all the time but I was never able to figure out what would cause it so I just skipped it all together. The documentation could use some work, most of the PyQT docs are in C++ and can take some fiddeling to get right. At one point I started to do some documentation for BA to give to some coworkers, if I can find it you are welcome to it (they decided to stick with Perl, so I never had to finish it). They have a mailing list (somewhere) for BA discussions, I forgot what the address is and had it sent to an address I no longer have access to. :( If you do purchase BA, I would say skip the support and the option to receive CDs. In the time that I have had the program there hasn't been an update, the support is so-so and they haven't ever sent a CD. Even with all of that BA is usually the second program I open when I do Python development (the shell is first). The feature I like most is the ability to collapse code blocks. Wayne -- Wayne Pierce web: http://www.mishre.com email: wayne at mishre.com "What you need to know." From eddieborder2001 at yahoo.co.uk Fri Mar 1 19:07:42 2002 From: eddieborder2001 at yahoo.co.uk (Ed) Date: 1 Mar 2002 10:07:42 -0800 Subject: hotmail Message-ID: hi im just wondering whether it is possible to access hotmail thru python so that i have a far quicker way of checking my emails. can telnetlib do this? thanx ed From jwilhelm at outsourcefinancial.com Fri Mar 1 19:12:42 2002 From: jwilhelm at outsourcefinancial.com (Joseph Wilhelm) Date: 01 Mar 2002 11:12:42 -0700 Subject: Problems with multipart messages w/email class Message-ID: <1015006362.1673.7.camel@jwilhelm.ofsloans.com> I'm trying to send an email via the email class in Python 2.2 with an attached PDF. Easy feat, I assume. However, email.Generator is having problems in _handle_multipart() (Caused by some strange __getitem__ error in Message) >>> outer.get_payload() >>> That works fine. However... >>> for part in outer.get_payload(): ... print "Blah" ... Traceback (most recent call last): File "", line 1, in ? File "/opt/python/lib/python2.2/email/Message.py", line 151, in __getitem__ return self.get(name) File "/opt/python/lib/python2.2/email/Message.py", line 214, in get name = name.lower() AttributeError: 'int' object has no attribute 'lower' >>> I originally found this error because of this traceback: Traceback (most recent call last): File "", line 1, in ? File "/opt/python/lib/python2.2/email/Message.py", line 59, in as_string g(self, unixfrom=unixfrom) File "/opt/python/lib/python2.2/email/Generator.py", line 83, in __call__ self._write(msg) File "/opt/python/lib/python2.2/email/Generator.py", line 104, in _write self._dispatch(msg) File "/opt/python/lib/python2.2/email/Generator.py", line 134, in _dispatch meth(msg) File "/opt/python/lib/python2.2/email/Generator.py", line 240, in _handle_multipart for part in msg.get_payload(): File "/opt/python/lib/python2.2/email/Message.py", line 151, in __getitem__ return self.get(name) File "/opt/python/lib/python2.2/email/Message.py", line 214, in get name = name.lower() AttributeError: 'int' object has no attribute 'lower' I got this from calling message.as_string() I can provide my code used to generate the email if necessarry, however I don't believe it should be. I derived my code directly from an example in the email documentation. Any help would be appreciated. --Joseph Wilhelm From gbreed at cix.compulink.co.uk Fri Mar 1 19:12:42 2002 From: gbreed at cix.compulink.co.uk (gbreed at cix.compulink.co.uk) Date: Fri, 1 Mar 2002 18:12:42 +0000 (UTC) Subject: Javascript to Python References: <2030665d.0203010912.1bb9c0ae@posting.google.com> Message-ID: Sam Collett wrote: > Does anyone know of any good sites on Javascript > Python examples? Forgive me for being arrogant, but learning Python from the tutorial should tell you all you need. > I have a function in javascript that returns the file extension: > > function FileExtension(sFilePath) > { > return Right(sFilePath,sFilePath.length-sFilePath.lastIndexOf(".")) > } > > so FileExtension("/path/to/file.doc") would return .doc > I would also want to return the filename (file) and the path > (/path/to/). How would I go about that? >>> import os >>> os.path.splitext("/path/to/file.doc")[1] '.doc' >>> os.path.splitext(os.path.basename("/path/to/file.doc"))[0] 'file' >>> os.path.dirname("/path/to/file.doc") '/path/to' > What equivalents to the functions Right and Left (right side of > string, left side of string) >>> "hello world"[:5] 'hello' >>> "hello world"[-5:] 'world' > Also is there an easier way to do number incrementing (just me being > lazy): > while r<5 > print r > r=r+1 > > I have tried r++ to add 1 each time, and r-- to take away one, but > this does not work, so is the only way r=r+1 or r=r-1 ? Your code's missing a : You can use r+=1 and r-=1 with recent enough versions of Python. That particular example can be done >>> for r in range(r, 5): ... print r Graham From tim_one at email.msn.com Fri Mar 1 19:18:33 2002 From: tim_one at email.msn.com (Tim Peters) Date: Fri, 1 Mar 2002 13:18:33 -0500 Subject: Does python have a function like similar_text in PHP In-Reply-To: <61ff32e3.0203010850.3aedc22f@posting.google.com> Message-ID: [ron nixon] > Does anyone know if Python has a function like similar_text in PHP. It > compares two strings and returns a percentage for the match. The .ratio() method of SequenceMatcher objects looks like a similar gimmick, returning a "similarity score" as a float in [0, 1]: http://www.python.org/doc/current/lib/sequence-matcher.html From elflord at panix.com Fri Mar 1 19:17:09 2002 From: elflord at panix.com (Donovan Rebbechi) Date: Fri, 1 Mar 2002 18:17:09 +0000 (UTC) Subject: Scripting C++ -- 2 -- a more concrete example. References: <3C7E6642.2030202@physics.ucsb.edu> <6bf54244.0203010925.38d237ed@posting.google.com> Message-ID: In article <6bf54244.0203010925.38d237ed at posting.google.com>, Craig Maloney wrote: > Donovan Rebbechi wrote in message news:... >> In article <3C7E6642.2030202 at physics.ucsb.edu>, Craig Maloney wrote: >> > If using a wrapper generator (e.g. SILOON) I don't see a way around the >> > marshalling of the call to get at the atom data structure. >> >> I don't really understand exactly what the problem is. >> > >> > Of course, this would be taken care of by a revamp of the design of the >> > class library... maybe making the crystal an atom factory that produces >> > new atoms in its own address space. But I would like to avoid thinking >> >> Now I'm really confused. If you're not using CORBA, the atoms are in the >> same address space, aren't they ? > > This is how I presumed that Boost also worked -- I must be mistaken. > After having seen yours and Ralf's comments, I now have the impression > that Boost works it's magic differently. > > Perhaps Craig Rasmussen could enlighten us as to how SILOON deals with > co-location issues such as the one above? > > From the SILOON doc/design.html page : Looks like SILOON is using some sort of client/server architecture, much like CORBA. Sip, which is what I use, doesn't do this. It simply wraps C++ objects. Basically, Python objects are represented in C as PyObject* pointers. What sip does is create a "derived" struct by aggregating a PyObject, and some additional stuff. So in the sip model, you'd just be using wrapped python objects. It's not completely automatic, because there are some choices that can't be made automatically. For example, there are tricky choices about ownership -- when you call "add", does the object you "add" to want to own a reference (bump up the reference count) ? You also do need to add code to return python tuples instead of using the C/C++ "return-by-pass-by-pointer" idiom. Like I said, even though it's not automatic, you get a good code generation ratio. Also, even in instances where it's not completely automatic (eg exception mapping), you can use generated code as a starting point. I use macros to map exceptions, which makes this a very simple process. Cheers, -- Donovan From RStephens at viteonline.com Fri Mar 1 19:20:05 2002 From: RStephens at viteonline.com (Ron Stephens) Date: Fri, 1 Mar 2002 13:20:05 -0500 Subject: Black Adder and piquet Message-ID: <2B69DFB47D76D3118B0100A0C9DED182010FB900@vi_nor_mail.vectron.com> Thank you. If you do find the documentation you worked on, I would be glad to have it and maybe I can add to it. Thanks Ron Stephens > -----Original Message----- > From: Wayne Pierce [SMTP:wayne at mishre.com] > Sent: Friday, March 01, 2002 1:06 PM > To: Ron Stephens > Cc: python-list at python.org > Subject: Re: Black Adder and PyQt > > > Ron Stephens wrote: > > I am thinking of buying a "home" license of Black Adder, to use for > > making GUI's for Python programs to be used on Linux+KDE and also > > perhaps for the new Sharp Zaurus. Does anyone have any experience with > > Black Adder that they can share? One of my main reasons for wanting > > Black Adder is to use the GUI builder, so I am particualrly interested > > in opinions about that aspect of Black Adder, but I am also interested > > in other aspects as well. > > I really like the GUI builder of BA, unfortunately I think it could use > more work. Granted it is __still__ in beta, but it's been in beta for > quite a while without an update. When I do GUI development I typically > do the first part in BA, then manually add in the GUI pieces that BA > doesn't support directly yet (like menus). > > The only thing I don't like about the GUI builder is that it doesn't > support a lot of widgets yet. The last I heard they were waiting for Qt3. > > > One question I have concerns licensing. If I buy the "home" version, > > could I still share my programs as GPL'ed open source, or would that > > require me to buy the "professional" license, which is much more > > expensive? In other words, my programs would never be used in any > > commercial way but I might want to post them as open source, free > > software. > > As I understand it, the only restriction on redistribution is if you are > distributing commercial apps. Then you need the business edition to > redistribute Qt and the other modules. It might be good to get the > scoop directly from them on this since I got the business edition and > haven't had to worry about it. > > > I know Black Adder is still in beta, but is it stable enoough to use > > already? I suppose I should ask how it compares to PythonWare amd > > WingIDE, but I kind of favor the PyQt toolkit becuase it will > > hopefully work well on the Sharp Zaurus as well as the KDE desktopI > haven't had too many problems with BA's stability; typically I use BA > for the GUI design and syntax highlighting then compile and test in a > shell. I've had some lockups when using the run from within BA in the > past, not all the time but I was never able to figure out what would > cause it so I just skipped it all together. > > The documentation could use some work, most of the PyQT docs are in C++ > and can take some fiddeling to get right. At one point I started to do > some documentation for BA to give to some coworkers, if I can find it > you are welcome to it (they decided to stick with Perl, so I never had > to finish it). > > They have a mailing list (somewhere) for BA discussions, I forgot what > the address is and had it sent to an address I no longer have access to. > :( If you do purchase BA, I would say skip the support and the option > to receive CDs. In the time that I have had the program there hasn't > been an update, the support is so-so and they haven't ever sent a CD. > > Even with all of that BA is usually the second program I open when I do > Python development (the shell is first). The feature I like most is the > ability to collapse code blocks. > > Wayne > -- > Wayne Pierce > web: http://www.mishre.com > email: wayne at mishre.com > > "What you need to know." From DeepBleu at DeepBleu.org Fri Mar 1 19:21:05 2002 From: DeepBleu at DeepBleu.org (DeepBleu) Date: Fri, 1 Mar 2002 12:21:05 -0600 Subject: Deitel and Deitel Book... References: <3C7D8DCA.119D52EC@earthlink.net> <899f842.0203010812.6151d817@posting.google.com> Message-ID: "Anthony_Barker" wrote in message news:899f842.0203010812.6151d817 at posting.google.com... > "DeepBleu" wrote in message > > Deitel and Deitel book on Python? I personally would not touch it. Give me > > a book written by Lutz, Holden or Hammond any time. But not from the > > establishment of Deitel. I bet you they do not even know how to program in > > Python. All their books are churned out by what resembles an > > industry-complex with standard issue. > > Long ago I discovered a mistake in their old C++ How to Program. I sent > > them an e-mail. The answer still brings vivd memories of when you feel like > > throwing up. Arrogant bunch of oppurtunists who are not worth the price of > > the paper their books are printed on. > > You want books on Python: Buy Beazley, Lundh, Holden, Hammond, Greyson > > etc.... > > Leave Deitel alone! > > DeepBleu > > [...........] That said, > more books on the python landscape is a good thing. And as the > previous poster said, programming books are a personal thing. > I certainly agree with you on this one. I had formed a negative bias about them out of my old encounter with them over the error in C++ How to Program. > > I would love to see books on Algorithms with Python (makes a perfect > fit), and more advanced topics such as threads and extending python. I'd love to see something like that specially on threads and extending Python. This is something I can use. DeepBleu From andreas at zope.com Fri Mar 1 19:24:35 2002 From: andreas at zope.com (Andreas Jung) Date: Fri, 1 Mar 2002 13:24:35 -0500 Subject: Does python have a function like similar_text in PHP References: Message-ID: <04ef01c1c14e$acf37210$02010a0a@suxlap> I wrote a Python extension that implements the Levenshtein algorithm that PHP uses too. The same extension als contains implementations for soundex and metaphone. Available from the CVS: http://sourceforge.net/projects/pyproximity Andreas ----- Original Message ----- From: "Tim Peters" To: Sent: Friday, March 01, 2002 13:18 Subject: RE: Does python have a function like similar_text in PHP > [ron nixon] > > Does anyone know if Python has a function like similar_text in PHP. It > > compares two strings and returns a percentage for the match. > > The .ratio() method of SequenceMatcher objects looks like a similar gimmick, > returning a "similarity score" as a float in [0, 1]: > > http://www.python.org/doc/current/lib/sequence-matcher.html > > > -- > http://mail.python.org/mailman/listinfo/python-list > From bp at sam.localdomain Fri Mar 1 19:25:36 2002 From: bp at sam.localdomain (Bob Parnes) Date: Fri, 01 Mar 2002 18:25:36 -0000 Subject: Mod-python problem References: Message-ID: On 1 Mar 2002 03:34:10 -0800, Alan Kennedy wrote: >bp at sam.localdomain (Bob Parnes) wrote in message > >> The only trouble is that I had forgotten about my httpd.conf file. The >> relevant lines are: >> >> >> AddHandler python-program .py >> PythonHandler mod_python.publisher >> >> >> This was the reason I used main() instead of handler(); in the url window I >> typed in "test.py/main" and got the table but no response from FieldStorage(). > >> Are publisher and FieldStorage() incompatible, or am I misusing them? Knowing >> what I know now, I can probably get along without publisher, but I am >> accustomed to placing several scripts in one directory. > >Bob, > >Sorry, I didn't realise you were using the Publisher handler, >otherwise I wouldn't have gone and rewritten your code to work with a >completely different paradigm. And I was wondering how you were >getting results with something that just didn't look like it could >work %-) D'oh! Silly me. > >Warning: I don't use the publisher handler, so I haven't tested any of >the stuff below! > >Looking at the publisher handler documentation, section 6.1.3: >Publisher handler: Form data > >http://www.modpython.org/live/mod_python-2.7.6/doc-html/node74.html > >which says: > >"In the process of matching arguments, the Publisher handler creates >an instance of FieldStorage class. A reference to this instance is >stored in an attribute form of the Request object. > >Since a FieldStorage can only be instantiated once per request, one >must not attept to instantiate FieldStorage when using the Publisher >handler and should use Request.form instead." > >So it would appear to me that you shouldn't be trying to instantiate >the util.FieldStorage() class at all. Instead, you should be referring >to the already extant req.form attribute. So your main function should >change from this > >def main(req): > formDict = util.FieldStorage(req) > cl = clTest() > return cl.cltest(req, formDict) > >to this > >def main(req): > cl = clTest() > return cl.cltest(req, req.form) > >As mentioned, I haven't tested any of this! > >Hope this helps, > >Al. It works great. Thank you so much. I am ashamed to say that I have the documentation, but somehow. I overlooked section 6.1.3 Bob -- Bob Parnes rparnes at megalink.net From sjmachin at lexicon.net Fri Mar 1 19:28:50 2002 From: sjmachin at lexicon.net (John Machin) Date: 1 Mar 2002 10:28:50 -0800 Subject: Apology to Bill Gates (was Re: ASV module, CVS modules) References: <61ff32e3.0202281525.3e9bb102@posting.google.com> Message-ID: Michael Hudson wrote in message news:... > Skip Montanaro writes: > > > John> Python, starting from a Unix background, where there is evidently > > John> no such thing as an invalid character in a file name, ... > > > > I believe "/" is not allowed in Unix filenames. Not sure if this is > > escapable or not. > > Don't think so. NULLs are out, too. It is not a case of "not allowed". You simply can't supply a file name containing a "/" or a NUL (not a *NULL*) because "/" is interpreted as a path separator and NUL as a string terminator. My point was that Unix doesn't proactively check to see if you are trying to create a file whose name you may never see again. From sdm7g at Virginia.EDU Fri Mar 1 19:44:31 2002 From: sdm7g at Virginia.EDU (Steven Majewski) Date: Fri, 1 Mar 2002 13:44:31 -0500 (EST) Subject: Swapping out sys.stdout globally In-Reply-To: <15487.41982.968248.121857@12-248-41-177.client.attbi.com> Message-ID: On Fri, 1 Mar 2002, Skip Montanaro wrote: > > Kevin> sys.stdout = NewFile() > Kevin> sys.stderr = NewFile() > > Kevin> However, I have some logging routines in a separate package that > Kevin> already have their own references to sys.stdout and sys.stderr > Kevin> which are unaffected by this. > > Sounds like they use something like > > from sys import stdout,stderr > > The best solution there would be for those packages to import sys in the > usual fashion: > > import sys > > and refer to sys.stdout & sys.stderr. > Skip's advice is sound. However, if there's some reason you can't do that, if you're on unix then you can use posix.close, posix.open & posix.dup2 to redirect the posix file underneath the python file object. Something like: new_file = open( file, 'w' ) fd = sys.stdout.fileno() os.close(fd) os.dup2( new_file.fileno(), fd ) Don't use sys.stdout.close(), because it will mark the Python file object as closed. os.close() closes the real os file but doesn't mark the python file object as closed. -- Steve Majewski From brian at zope.com Fri Mar 1 19:54:30 2002 From: brian at zope.com (Brian Lloyd) Date: Fri, 1 Mar 2002 13:54:30 -0500 Subject: Embedding Python in C#... Message-ID: > >has this been done? > > Not that I know of. > > >is it even possible? > > I am pretty sure, yes. (Sorry I'm a little behind on this...) Yep - and it's pretty easy (though I'm not totally done yet) :) It looks something like: PythonInterpreter python = new PythonInterpreter(); PyModule sys = python.ImportModule("sys"); PyList list = (PyList)sys.GetAttr("path"); Console.WriteLine("Sys.path is: {0}", list.ToString()); Console.WriteLine("Item 0 is: {0}", list[0].ToString()); > >if it has where can i obtain information on doing so? If you're interested in playing with it in-progress, let me know. Brian Lloyd brian at zope.com Software Engineer 540.361.1716 Zope Corporation http://www.zope.com From kp87 at lycos.com Fri Mar 1 19:49:31 2002 From: kp87 at lycos.com (kevin parks) Date: 1 Mar 2002 10:49:31 -0800 Subject: C/C++ to Python translater Message-ID: <5e8bd451.0203011049.5d12d3a2@posting.google.com> Is there a translator to automatically port (rewrite) code snippets from C or C++ to Python? I have some old C code that i have been porting by hand (well by head really) and i was wondering if there were any translation utilities that i could try. I imagine that this would be a monster AI undertaking, Btu with Python's powerful built-in types i am guessing c --> Python is easier than the opposite. Just wondering... From carifio.nospam at nospam.usys.com Fri Mar 1 19:49:47 2002 From: carifio.nospam at nospam.usys.com (Mike Carifio) Date: Fri, 01 Mar 2002 18:49:47 GMT Subject: __abs(self)__? Message-ID: I'm reading about special method names. __abs__(self), which maps to the abs() method seems unneccessary(?). So: class ExampleNumber: def __init__(self, initializer): self.value = initializer def __abs__(self): return abs(self.value) >>> x = ExampleNumber(-1) >>> x.abs() 1 seems no different from: class ExampleNumber: def __init__(self, initializer): self.value = initializer def abs(self): # name isn't special? return abs(self.value) abs is a builtin function, so why do I need a special name for a function? I'm missing something... From db3l at fitlinxx.com Fri Mar 1 19:59:55 2002 From: db3l at fitlinxx.com (David Bolen) Date: 01 Mar 2002 13:59:55 -0500 Subject: Can somebody kill getpathp for me? References: Message-ID: "Chris Gonnerman" writes: > No, but win32all does (for instance). The point is, I never want my > CD-based runtime to ever see the end user's install, if he/she has one. > The programs I want to run from CD may get psycho if the local version > has conflicting libraries, and in fact I have already encountered this > problem (so it's not just theoretical). You may not technically need to package things up, but if you use Gordon McMillan's installer (or py2exe as well as I believe), they will lock down your sys.path to the local installation. So you could build an image for your application using one of those tools, and execute that from the CD. Of course, this may not be perfect if you want the CD to work on both Windows and Unix, but it would avoid needing to rebuild a different python front-end for Windows. -- -- David -- /-----------------------------------------------------------------------\ \ David Bolen \ E-mail: db3l at fitlinxx.com / | FitLinxx, Inc. \ Phone: (203) 708-5192 | / 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \ \-----------------------------------------------------------------------/ From BPettersen at NAREX.com Fri Mar 1 20:08:22 2002 From: BPettersen at NAREX.com (Bjorn Pettersen) Date: Fri, 1 Mar 2002 12:08:22 -0700 Subject: Status of PEP's? Message-ID: <60FB8BB7F0EFC7409B75EEEC13E2019221514B@admin56.narex.com> > From: David Eppstein [mailto:eppstein at ics.uci.edu] > > In article , > "Bjorn Pettersen" wrote: > > > Of course, if anyone actually cared about this syntax, we > would have a > > PEP with a pro/con section, so we wouldn't have to > reiterate the same > > arguments over and over again > > I was starting to think it might be time to write a PEP, > but then Tim's comment about how he dislikes iterating over 3 > discouraged me. I would still encourage you to write a PEP, especially if you think this should be implemented instead of PEP 276. I believe even Tim can be convinced by a superior argument -- besides it's not like we get to vote on the PEPs anyway . -- bjorn From fperez528 at yahoo.com Fri Mar 1 13:06:22 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Fri, 01 Mar 2002 12:06:22 +0000 Subject: C/C++ to Python translater References: <5e8bd451.0203011049.5d12d3a2@posting.google.com> Message-ID: kevin parks wrote: > Is there a translator to automatically port (rewrite) code snippets > from C or C++ to Python? I have some old C code that i have been > porting by hand (well by head really) and i was wondering if there > were any translation utilities that i could try. I imagine that this > would be a monster AI undertaking, Btu with Python's powerful built-in > types i am guessing c --> Python is easier than the opposite. Yes, almost. It doesn't translate it, but you can embed the C/C++ in your python source code: http://www.scipy.org/site_content/weave Besides, there's various systems for wrapping complete libraries as modules with minimal effort. google(swig,sip,boost.python,siloon) will help. cheers, f. From emile at fenx.com Fri Mar 1 20:05:41 2002 From: emile at fenx.com (Emile van Sebille) Date: Fri, 1 Mar 2002 11:05:41 -0800 Subject: Minor, minor style question References: <5F9A347EAC81A19E.F4E6D6813EA4DC98.17114695240B3A22@lp.airnews.net> Message-ID: claird at starbase.neosoft.com (Cameron Laird) writes: > Why would I prefer > string = "" > string = string + "abc " > string = string + "def " > string = string + "xyz" > over > string = "abc " + \ > "def " + \ > "xyz" > ? Isn't the question about line continuations? I don't use them (except on rare occasions), preferring to do something more like: string = ('abc' + 'def' + 'xzy') As to deprecation, a quick scan of the 2.2 standard library shows 42516 lines of which 249 used '\' style continuations, and other styles accounting for 958. (Note: I count a line as a sequence of source lines that together tokenize properly.) HTH, -- Emile van Sebille emile at fenx.com --------- From brueckd at tbye.com Fri Mar 1 20:56:34 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Fri, 1 Mar 2002 11:56:34 -0800 (PST) Subject: hotmail In-Reply-To: Message-ID: On 1 Mar 2002, Ed wrote: > im just wondering whether it is possible to access hotmail thru python > so that i have a far quicker way of checking my emails. can telnetlib > do this? If you're on Windows (and have either ActiveState Python or Mark Hammond's win32all extensions) then you can use COM to create a web browser instance and use its DOM interface to navigate. I made a small script to retrieve my address book this way - I'll try to dig it up and post it, but it's pretty easy to do from scratch too. -Dave From emile at fenx.com Fri Mar 1 20:11:34 2002 From: emile at fenx.com (Emile van Sebille) Date: Fri, 1 Mar 2002 11:11:34 -0800 Subject: __abs(self)__? References: Message-ID: "Mike Carifio" wrote in message news:f3Qf8.2391$26.139172 at typhoon.maine.rr.com... > I'm reading about special method names. __abs__(self), which maps to the > abs() method seems unneccessary(?). compare: From emile at fenx.com Fri Mar 1 20:13:00 2002 From: emile at fenx.com (Emile van Sebille) Date: Fri, 1 Mar 2002 11:13:00 -0800 Subject: __abs(self)__? References: Message-ID: "Mike Carifio" wrote in message news:f3Qf8.2391$26.139172 at typhoon.maine.rr.com... > I'm reading about special method names. __abs__(self), which maps to the > abs() method seems unneccessary(?). (Whoops, it got away from me) Compare: class ExampleNumber: def __init__(self, initializer): self.value = initializer def __abs__(self): return abs(self.value) x = ExampleNumber(-1) print abs(x) class ExampleNumber: def __init__(self, initializer): self.value = initializer def abs(self): # name isn't special? return abs(self.value) x = ExampleNumber(-1) print abs(x) HTH, -- Emile van Sebille emile at fenx.com --------- From nospam at bigfoot.com Fri Mar 1 20:35:34 2002 From: nospam at bigfoot.com (Gillou) Date: Fri, 1 Mar 2002 20:35:34 +0100 Subject: hotmail References: Message-ID: If you got a pop3 access to your hotmail account, have a look at the "poplib" package. This is the easiest way. If you can only read your mail through Web pages, I think that "urllib" (performs HTTP GET/POST requests and retrieve Web pages) and "htmllib" (simple HTML parser) will help you for that job. But it's harder. HTH --Gillou "Ed" a ?crit dans le message news: d5534716.0203011007.4cfeb8b8 at posting.google.com... > hi > im just wondering whether it is possible to access hotmail thru python > so that i have a far quicker way of checking my emails. can telnetlib > do this? > thanx > ed From terabaap at yumpee.org Fri Mar 1 20:38:42 2002 From: terabaap at yumpee.org (Manoj Plakal) Date: Fri, 01 Mar 2002 13:38:42 -0600 Subject: RSS writer module? Message-ID: <3C7FD8C2.9040702@yumpee.org> Does anyone know of a Python module to write RSS files? The format is not that hard to generate manually but perhaps someone's already done it? Manoj From huaiyu at gauss.almadan.ibm.com Fri Mar 1 20:41:54 2002 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Fri, 1 Mar 2002 19:41:54 +0000 (UTC) Subject: PEP 263 comments References: <87g03lhm3p.fsf@tleepslib.sk.tsukuba.ac.jp> <87pu2oeqq9.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: I've been following this discussion with quite some interest, but I do not have the background to delimit the scope of various concepts. Is there a gentle introduction to a unicode-newbie? On 01 Mar 2002 15:39:42 +0900, Stephen J. Turnbull wrote: > >IMO, the Python source code parser should never see any text data[1] >that is not UTF-8 encoded. Presumably this discussion only concerns unicode strings - I don't think want to lose the ability to read in arbitrary binary data as a raw string. But then you mention >[1] Ie, Python language or character text. It might be convenient to >have an octet-string primitive data type, in which you could put >EUC-encoded Japanese or Java byte codes. What's the difference between this and a raw string (a byte sequence) that you can translate into any other encoding? Huaiyu From gerson.kurz at t-online.de Fri Mar 1 19:50:34 2002 From: gerson.kurz at t-online.de (Gerson Kurz) Date: Fri, 01 Mar 2002 18:50:34 GMT Subject: ANN: experimental patch to allow importing from file-like objects Message-ID: <3c7fcbe6.7419921@news.t-online.de> Motivation: Write a customized import that reads data from encrypted files. Both execfile() and exec() are limited, if only that that they don't mimic the import syntax. Problem: imp.load_module does expect a file object, but you can only pass "real" files, not file-like objects. The internal C-code expects native FILE* stuff. Solution: An experimental patch to the python22.dll that makes this possible. Using file-like objects for import opens up a whole new set of possibilities, for example you could fetch the code at runtime from a database or a socket. Limitations: - Currently, Win32 only. - Currently, you can only import source from file-like objects, not precompiled binaries. - Currently, error handling is completely undefined. Sample Code: import imp, os, rotor # sample code *************************************** source = """ print 'Inside encrypted code' variable = 123 """ # generate encrypted file *************************** file = open("test.raw","wb") rt = rotor.newrotor('key', 12) file.write( rt.encrypt(source) ) file.close() # sample file class, that reads data from encrypted file class my_file_class: def __init__(self,filename): rt = rotor.newrotor('key', 12) self.lines = rt.decrypt(open(filename).read()).split('\n') print "read", len(self.lines), "lines from encrypted file" def read(self,size): if self.lines: line = self.lines[0] # must make sure line ends with \n if not line: line = '\n' elif not (line[-1] == '\n'): line += '\n' self.lines = self.lines[1:] return line # redirect import hook ****************************** old_import_func = __import__ def my_import_func(name, globals=None, locals=None, fromlist=None): global old_import_func if name == "encrypted_test": return imp.load_module(name, my_file_class("test.raw"), "test.raw", ('.raw','rb',imp.PY_FILEOBJECT_SOURCE)) # use original code return old_import_func( name, globals, locals, fromlist ) __builtins__.__import__ = my_import_func # test code import encrypted_test print encrypted_test.variable Download: http://p-nand-q.com/python/pyimport.zip More technical details: http://p-nand-q.com/pyimport.htm (at the bottom) Now what? PEP-stuff? Or completely uninteresting? From Tom_Good1 at excite.com Fri Mar 1 20:58:03 2002 From: Tom_Good1 at excite.com (Tom Good) Date: 1 Mar 2002 11:58:03 -0800 Subject: dirwalk.py generator version of os.path.walk References: Message-ID: jimd at vega.starshine.org (Jim Dennis) wrote in message news:... > In article , Just van Rossum wrote: > >In article , > > jimd at vega.starshine.org (Jim Dennis) wrote: > > >>> I wrote a different implementation of this general concept at: > > >>> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/105873 > > >>> You don't really need to keep a stack of directories and push/pop > >>> things, because with generators you can recurse instead. > >>> Tom > > BTW: Tom, I did come across your version in the ASPN a day or so > after I wrote mine. I agree it looks cleaner and simpler. > I might still use a list (FIFO or stack) and while loop instead > of the recursion. (see below). > If you've considered both approaches and prefer a non-recursive implementation, then sure, do it the way you like best. I wanted to point out another option in case you hadn't thought of it. [snip] > However, it would be nice if I > created a useful Python module which provided all of the power > for Python that the "find" command provides to the shell. That sounds cool. Post it when you're done :-) Tom From bfisseni at gmx.de Fri Mar 1 21:04:46 2002 From: bfisseni at gmx.de (Bernhard Fisseni) Date: 1 Mar 2002 20:04:46 GMT Subject: SAX-Parser entity References: Message-ID: Hi, Fabian, > > Ahh, utf-16 sounds good. > Thanks, I have at least one solution: > Reading the xml-file into a buffer and convert it to utf-16. > minidom is then able to parse the whole thing and saves the strings in > unicode, which is fine again. > > I do not understand the part with "If your parser supports...". As it seems > to me, the minidom default parser does not support ISO 8859/1 and even > unicode makes problems only. had you declared ?? > I didn't know, you can reprogram the parser so easily. When I wrote a programme using SAX, I finally used xml.sax.saxutils.escape() def characters(self, content): self._out.write(saxutils.escape(content, self.transhash)) where content means the characters and self.transhash looked like: transhash = { u'\u00c4' : 'Ä', u'\u00c6' : 'Æ', } I suppose, this is not the most elegant way to do it, but it works. Regards, Bernhard > Harvey Thomas wrote: >> I would guess that your document is in ISO 8859/1 (otherwise known as >> latin-1). XML parsers must be able to parse utf-8 and utf-16 and may >> support other encodings. If your parser supports latin-1 then modify the >> XML declaration. Otherwise use the codecs module. > >>> Problem: >>> I try to use the minidom XML-Parser to parse my little file >>> in order to generate HTML Code. >>> Being german, I really like to use Umlauts but minidom does not. >>> ... >>> Traceback (most recent call last): >>> "/usr/lib/python2.0/site-packages/_xmlplus/sax/handler.py", >>> line 38, in fatalError >>> raise exception >>> xml.sax._exceptions.SAXParseException: :29:19: not well-formed >>> >>> where Character 19 in Row 29 is the occurence of an ?. -- Bernhard Fisseni Studi: Steinweg 32 -- 53121 Bonn-Endenich, D -- +49-228-6203949 zu hause: Ubierstrasse 8 -- 53498 Bad Breisig, D -- +49-2633-96333 From shalehperry at attbi.com Fri Mar 1 21:06:54 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Fri, 01 Mar 2002 12:06:54 -0800 (PST) Subject: __abs(self)__? In-Reply-To: Message-ID: On 01-Mar-2002 Mike Carifio wrote: > I'm reading about special method names. __abs__(self), which maps to the > abs() method seems unneccessary(?). > So: > > class ExampleNumber: > def __init__(self, initializer): > self.value = initializer > def __abs__(self): > return abs(self.value) > >>>> x = ExampleNumber(-1) >>>> x.abs() > 1 > > seems no different from: > > class ExampleNumber: > def __init__(self, initializer): > self.value = initializer > def abs(self): # name isn't special? > return abs(self.value) > > abs is a builtin function, so why do I need a special name for a function? > I'm missing something... > the __foo__ method names are special because you do not call them directly (usually) rather they are triggered when a request is made. __abs__() causes the object to return a value that represents the absolute value of the object's data, whatever that means. abs(obj) translates into obj.__abs__(). This is just like 'print obj' calling obj.__str__() or 'obj[i]' calling obj.__getitem__(i). From cfelling at iae.nl Fri Mar 1 21:10:20 2002 From: cfelling at iae.nl (Carel Fellinger) Date: 1 Mar 2002 21:10:20 +0100 Subject: PEP 263 comments References: <87g03lhm3p.fsf@tleepslib.sk.tsukuba.ac.jp> <87u1s0eth5.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: Stephen J. Turnbull wrote: ---lots snipped--- Thanks for your well balanced commands, they sure refined my thinking on the subject. > My _very_ personal opinion is that identifiers can be run through an > online dictionary, and I'm fortunate to be pretty good at languages, > so that's fun. Nor do I do programming for a living, I can afford to > concentrate on "fun." Yep fun, but very hard as single word translation is amongs the hardest translation problems. Wouldn't it be better if we had a kind of inter-lingua-meaning-representation and each and every identifier linked to one by the author of the code himself? The `translation' process could then be automated, and everyone could read the source in her/his own language. (I know, in practice next to impossible to achieve such a inter-lingua complete with all the mappings to all the languages out there, but he I'm porting an old project I was involved in that tried this route for general texts, so why not dream on:) > My opinion as a teacher is that I'd really like to be able to teach > programming to my freshmen with a language that uses Japanese > identifiers (including reserved words) and syntax (Japanese is a > reverse Polish language). We used to make fun of the french who had their own version of Algol, but growing older, wiser(?) and more experienced and finally having kids of my own that want to program I've come to appreciate this point more and more. And now with the world getting smaller and smaller thanks to internet, I tent to think it's a problem we should tackle. ... > A correct comment in an illegible character set is harmless, although > perhaps frustrating; an incorrect one that you can read is dangerous. very true > So I'd have to say that except for the very worst cases, there are > benefits to having code in English, or near-English, vocabulary. But > comments should be written in a language you can use for teaching. Well, atleast a language you are reasonably well versed in as to prevent those `incorrect' comments. -- groetjes, carel From James_Althoff at i2.com Fri Mar 1 21:16:21 2002 From: James_Althoff at i2.com (James_Althoff at i2.com) Date: Fri, 1 Mar 2002 12:16:21 -0800 Subject: PEP 276 (was Re: Status of PEP's?) Message-ID: [James_Althoff] > (On the other hand, if anyone knows *how* to "lure" any of > them, be sure to let me know ). [Tim Peters] > Well, I'm particularly swayed by posters who have a "" key > and know how to use it. Still, my take remains what it was at the > start: it isn't even half as disgusting as most people will say it > is . Ah, very good. It's certainly encouraging to see that the ratio hasn't yet exceeded that crucial "49.999% disgusting" level . (Assuming decimal arithmetic on a calculator for this one). Jim From joonas at olen.to Fri Mar 1 21:14:13 2002 From: joonas at olen.to (Joonas Paalasmaa) Date: Fri, 01 Mar 2002 22:14:13 +0200 Subject: Securely passing arguments when opening a pipe to a program Message-ID: <3C7FE115.9832EE5C@olen.to> I am using Gnokii to send SMS messages with Python. Gnokii is started with popen2.popen2 like this: gnokiiRead, gnokiiWrite = popen2.popen2("gnokii --sendsms %s" % phonenumber) gnokiiWrite.write(message) gnokiiWrite.close() response = gnokiiRead.read() gnokiiRead.close() The problem is that the phonenumber string is not safe; it can even be "000; rm -fR ~/*". How can I securely pass arguments when opening the pipe? Is there a way to pass the arguments like in os.execv. - Joonas From tl_news at nexgo.de Fri Mar 1 21:29:05 2002 From: tl_news at nexgo.de (Tino Lange) Date: Fri, 01 Mar 2002 21:29:05 +0100 Subject: Ping References: Message-ID: On Fri, 1 Mar 2002 18:21:13 +0100, "Riss Nicolas" wrote: >Bonjour, >on ma dit que je pouvais ?crire en francais alors j'?crit en francais. Je >voudrais pouvoir v?rifier toutes les 5 min que une machine ping une autre >machine et si elle ne ping pas qu'elle execute un script. Comment faut il >faire avec python pour pinger une machine et v?rifier qu'elle r?pond?? > >Merci de votre aide. > Hi Riss! The best solution IMHO is to use the external "ping" provided by the underlying operating system and to catch and parse its output. So you don't have the possible suid and/or implementation problems. If you really want to use a pure "Python-Ping" you have to be familiar with (low-level) socket/network-programming. Have a look at http://mail.python.org/pipermail/python-list/2001-November/070944.html (the last two links will provide you with two working "Python-Pings") Best regards Tino From martin at v.loewis.de Fri Mar 1 21:34:02 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 01 Mar 2002 21:34:02 +0100 Subject: PEP 263 comments References: <87g03lhm3p.fsf@tleepslib.sk.tsukuba.ac.jp> <87pu2oeqq9.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) writes: > I've been following this discussion with quite some interest, but I do not > have the background to delimit the scope of various concepts. Is there a > gentle introduction to a unicode-newbie? There are a number of introductions to Unicode; you may want to search www.unicode.org, e.g. http://www.unicode.org/unicode/standard/WhatIsUnicode.html > >IMO, the Python source code parser should never see any text data[1] > >that is not UTF-8 encoded. > > Presumably this discussion only concerns unicode strings - I don't think > want to lose the ability to read in arbitrary binary data as a raw string. First and foremost, the discussion is only about source code. A byte string should certainly be able to store arbitrary bytes. Under Stephen's proposal, it would indeed not be possible anymore to put arbitrary binary data into source code. > >[1] Ie, Python language or character text. It might be convenient to > >have an octet-string primitive data type, in which you could put > >EUC-encoded Japanese or Java byte codes. > > What's the difference between this and a raw string (a byte sequence) that > you can translate into any other encoding? Arbitrary binary data uses don't have a character set. If they are character data, they should be stored as a character string (which, in Python, is a Unicode string). Regards, Martin From gregory.p.green at boeing.com Fri Mar 1 21:14:53 2002 From: gregory.p.green at boeing.com (Greg Green) Date: Fri, 1 Mar 2002 20:14:53 GMT Subject: Want to monitor process.. References: <87550ef1.0202272315.15779bbd@posting.google.com> <97ae44ee.0202280901.3153bdfc@posting.google.com> Message-ID: If you are using a unix OS, I would suggest using daemontools from Bernstein. It has a set of tools for supervising a process. I use it all of the time for these sorts of problems. http://cr.yp.to/daemontools.html -- Greg Green Advanced Design Systems Math & Computing Technology Boeing From martin at v.loewis.de Fri Mar 1 21:36:35 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 01 Mar 2002 21:36:35 +0100 Subject: SAX-Parser entity References: Message-ID: fabi.kreutz at gmx.de writes: > I spend the last 3 hours browsing FAQs and Mailinglist - without success - > but have nevertheless the feeling, that this is a very easy question: It is indeed very easy: There is an error in your document. It has no encoding declaration in the xml header. The parser rightfully rejects it. Regards, Martin From skip at pobox.com Fri Mar 1 21:53:06 2002 From: skip at pobox.com (Skip Montanaro) Date: Fri, 1 Mar 2002 14:53:06 -0600 Subject: PEP 263 comments In-Reply-To: References: <87g03lhm3p.fsf@tleepslib.sk.tsukuba.ac.jp> <87pu2oeqq9.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: <15487.59954.782142.191843@12-248-41-177.client.attbi.com> Martin> A byte string should certainly be able to store arbitrary Martin> bytes. Under Stephen's proposal, it would indeed not be possible Martin> anymore to put arbitrary binary data into source code. It's clear from discussions on python-dev that, like Barry Warsaw, I wear American sunglasses when exposed to the Unicode sun. Just to make sure I understand correctly, under Stephen's propsal would s = "\xff" be correct? I assume s = "?" (a literal 0377 character) would be an error, yes? That is, when you saw "arbitrary binary data" you are referring to non-printable octets in the source file, right? -- Skip Montanaro (skip at pobox.com - http://www.mojam.com/) From matt at mondoinfo.com Fri Mar 1 21:51:46 2002 From: matt at mondoinfo.com (Matthew Dixon Cowles) Date: Fri, 01 Mar 2002 20:51:46 GMT Subject: Ping References: Message-ID: On Fri, 1 Mar 2002 18:21:13 +0100, Riss Nicolas wrote: >Bonjour, Bonjour! >on ma dit que je pouvais ?crire en francais alors j'?crit en >francais. Of course it's reasonable to write in French here. I hope you will forgive me for replying in English because my French is sufficient for reading but rarely for writing. >Je voudrais pouvoir v?rifier toutes les 5 min que une machine ping >une autre machine et si elle ne ping pas qu'elle execute un >script. Comment faut il faire avec python pour pinger une machine et >v?rifier qu'elle r?pond?? Jeremy Hylton has Python code to do ping and traceroute at: http://www.python.org/~jeremy/python.html and my ping.py is at: ftp://ftp.visi.com/users/mdc/ping.py In order to open the raw socket that's necessary to send a ping, you'll need root authority under Unix and I don't think it's possible at all under Windows 9X. You might find it simpler or safer to use os.popen() to run your system's ping and parse its output. Andrae Muys points out in (wrapped for line length): http://groups.google.com/groups? selm=7934d084.0201081621.177c1c8e%40posting.google.com that it may also be possible to use an ordinary socket to connect to an ordinary port on the second machine and interpret any error message you get. You might have to experiment some to see what result was "normal" and what results represented errors. A bientot, Matt From cliechti at gmx.net Fri Mar 1 21:51:50 2002 From: cliechti at gmx.net (Chris Liechti) Date: 1 Mar 2002 21:51:50 +0100 Subject: Securely passing arguments when opening a pipe to a program References: <3C7FE115.9832EE5C@olen.to> Message-ID: Joonas Paalasmaa wrote in news:3C7FE115.9832EE5C at olen.to: > The problem is that the phonenumber string is not safe; it can even > be "000; rm -fR ~/*". How can I securely pass arguments when > opening the pipe? > Is there a way to pass the arguments like in os.execv. you could filter out any character that is not allowin in a phone number before passing the string but then you could also use: ... popen2.popen2("gnokii --sendsms %d" % long(phonenumber) and you will get an exception on illegal phone numbers chris -- Chris From quinn at barf.ugcs.caltech.edu Fri Mar 1 21:51:56 2002 From: quinn at barf.ugcs.caltech.edu (Quinn Dunkan) Date: 1 Mar 2002 20:51:56 GMT Subject: Minor, minor style question References: <5F9A347EAC81A19E.F4E6D6813EA4DC98.17114695240B3A22@lp.airnews.net> Message-ID: On Fri, 1 Mar 2002 11:05:41 -0800, Emile van Sebille wrote: >claird at starbase.neosoft.com (Cameron Laird) writes: > >> Why would I prefer >> string = "" >> string = string + "abc " >> string = string + "def " >> string = string + "xyz" >> over >> string = "abc " + \ >> "def " + \ >> "xyz" >> ? > >Isn't the question about line continuations? I don't use them (except >on rare occasions), preferring to do something more like: > >string = ('abc' + > 'def' + > 'xzy') Or, if they are all string constants: string = ('abc' 'dev' 'xyz') From martin at v.loewis.de Fri Mar 1 21:55:41 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 01 Mar 2002 21:55:41 +0100 Subject: importing C libraries, Solaris2.6, gcc2.95 :( References: <17214de2.0203010819.240c00d3@posting.google.com> Message-ID: rsalz at zolera.com (Rich Salz) writes: > I have a Solaris 2.6 machine, gcc 2.95.3 installed in /usr/local; > /usr/local/bin is in my $PATH ; /usr/ccs/bin is not in my $PATH. I > have python 2.1.1 sources; I did "./configure" with no flags. > Attempting to import any library that includes a C shared library > fails with the same backtrace: I think I've seen this before, but I can't find it, and I don't think it was resolved the last time. It sounds like a compiler/linker bug to me: The argument to SetItemString which is out of bounds *literally* comes from the methods array. Please try inspecting methods in the the gdb stack trace (up;up;up;up;p methods[0] - or some such). If this is still an invalid string, try finding out whether the compiler correctly passed address of _tkinter.c:moduleMethods. If that is the case, most likely the static or dynamic linker has messed up with relocations. What linker are you using? You may want to apply the latest patch cluster. Regards, Martin From martin at v.loewis.de Fri Mar 1 22:00:43 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 01 Mar 2002 22:00:43 +0100 Subject: ICU wrapper for Python? References: Message-ID: Fredrik Juhlin writes: > I was fiddling around with a Python wrapper for the ICU libraries this > weekend, when it occured to me to check if anyone else is/has been working > on the same thing. I looked around a bit on the net but couldn't find > anything, so I figured I'd drop a question here too :) Did you make any progress on that? I'd be most interested in exposing the codecs. Regards, Martin From martin at v.loewis.de Fri Mar 1 21:59:45 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 01 Mar 2002 21:59:45 +0100 Subject: what I would like to see in python to make a better "glue" language (Newbie) References: <899f842.0202261325.6ff3dd54@posting.google.com> <899f842.0202270934.281b65e4@posting.google.com> Message-ID: anthony_barker at hotmail.com (Anthony_Barker) writes: > If there is a package that supports distutils. what is the best way to > get this done? Post to the python-dev mailing list? Getting it into the standard library? Add a patch to the SF patch manager. Make sure you are the author of the code you are contributing, though - we won't normally incorporate anything without the explicit permission of the author. Regards, Martin From huaiyu at gauss.almadan.ibm.com Fri Mar 1 21:55:37 2002 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Fri, 1 Mar 2002 20:55:37 +0000 (UTC) Subject: mult-indexed xrange? Message-ID: The generator facility in 2.2 allows me to do something cool that I always wanted: looping around multiple indices with just one for-statement, as the following code does. Is this available with some built-in functions? Should we suggest that the definition of range and xrange be thus extended? Huaiyu # code example and output def multixrange(N): t = type(N) x = [0]*len(N) while 1: yield t(x) for i in xrange(len(N)-1, -1, -1): if x[i] < N[i]-1: x[i] += 1 break else: x[i] = 0 else: raise StopIteration if __name__ == '__main__': for x in multixrange((2,3,2)): print x for x in multixrange([2,4]): print x """ Outputs: (0, 0, 0) (0, 0, 1) (0, 1, 0) (0, 1, 1) (0, 2, 0) (0, 2, 1) (1, 0, 0) (1, 0, 1) (1, 1, 0) (1, 1, 1) (1, 2, 0) (1, 2, 1) [0, 0] [0, 1] [0, 2] [0, 3] [1, 0] [1, 1] [1, 2] [1, 3] """ From jeff at ccvcorp.com Fri Mar 1 22:18:14 2002 From: jeff at ccvcorp.com (Jeff Shannon) Date: Fri, 01 Mar 2002 13:18:14 -0800 Subject: win32+popen4 References: <$4LupWAmqsf8Ew0o@jessikat.fsnet.co.uk> Message-ID: <3C7FF015.D1A00D13@ccvcorp.com> Robert Amesz wrote: > On Win98 I've found I had to quote *and* escape the quote characters, > and - sometimes - backslashes too. I'm not sure if this is also the > case on Win2000, but it's worth a try. This would yield something like: > > '\\"c:\\\\program files\\\\dimbo\\\\bongo.exe\\\\" \\"c:\\\\program > files\\\\dumbo\\\\my file.dat\\"' > > Horrible, I know. This is why raw strings exist. >>> mystring1 = '\\"c:\\\\program files\\\\dimbo\\\\bongo.exe\\\\" \\"c:\\\\program files\\\\dumbo\\\\my file.dat\\"' >>> print mystring1 \"c:\\program files\\dimbo\\bongo.exe\\" \"c:\\program files\\dumbo\\my file.dat\" >>> mystring2 = r'\"c:\\program files\\dimbo\\bongo.exe\" \"c:\\program files\\dumbo\\my file.dat\"' >>> # note! ^ the 'r' here! >>> print mystring2 \"c:\\program files\\dimbo\\bongo.exe\" \"c:\\program files\\dumbo\\my file.dat\" >>> Note that you've got an extra backslash in your version -- you want a single escaped double quote after 'bongo.exe', not an escaped backslash followed by an unescaped double quote. Raw strings will save you much pain. Jeff Shannon Technician/Programmer Credit International From martin at v.loewis.de Fri Mar 1 22:20:47 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 01 Mar 2002 22:20:47 +0100 Subject: PEP 263 comments References: <87g03lhm3p.fsf@tleepslib.sk.tsukuba.ac.jp> <87pu2oeqq9.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: Skip Montanaro writes: > Just to make sure I understand correctly, under Stephen's propsal would > > s = "\xff" > > be correct? I assume > > s = "?" > > (a literal 0377 character) would be an error, yes? Yes, on both accounts. > That is, when you saw "arbitrary binary data" you are referring to > non-printable octets in the source file, right? Correct (except that whether something is printable is in the eye of the beholder). On the source level, the four letters '\', 'x', 'f', 'f' are not arbitrary binary - they follow a specific syntax. I actually doubt anybody is putting "arbitrary binary" data into source code. Instead, most such occurrences are likely "printable", if viewed in the encoding of the author of that code. Those would be outlawed, unless that encoding is UTF-8. Regards, Martin From emile at fenx.com Fri Mar 1 22:23:16 2002 From: emile at fenx.com (Emile van Sebille) Date: Fri, 1 Mar 2002 13:23:16 -0800 Subject: mult-indexed xrange? References: Message-ID: "Huaiyu Zhu" wrote in message news:slrna7vqm8.13q.huaiyu at gauss.almadan.ibm.com... > The generator facility in 2.2 allows me to do something cool that I always > wanted: looping around multiple indices with just one for-statement, as the > following code does. Is this available with some built-in functions? for (x,y) in [(i,j) for i in range(2) for j in range(3) ]: print x,y 0 0 0 0 0 1 0 1 0 0 1 1 0 2 0 0 2 1 1 0 0 1 0 1 1 1 0 1 1 1 1 2 0 1 2 1 Press any key to continue . . . -- Emile van Sebille emile at fenx.com --------- From xscottgjunk at yahoo.com Fri Mar 1 22:29:45 2002 From: xscottgjunk at yahoo.com (Scott Gilbert) Date: 1 Mar 2002 13:29:45 -0800 Subject: pickle, cPickle, zlib, and the future Message-ID: <79b2b0bb.0203011329.79469c5b@posting.google.com> I'm serializing Python objects to one of three formats: Ascii, Binary, or Compressed (a, b, or c). I would like to be able to load them using just one function that correctly guesses how they were pickled. This is similar to what I'm currently doing: def dump_a(o): return cPickle.dumps(o) def dump_b(o): return cPickle.dumps(o, 1) def dump_c(o): return zlib.compress(cPickle.dumps(o, 1)) def load(s): if s[0] == 'x': return cPickle.loads(zlib.decompress(s)) else: return cPickle.loads(s) This only works if future enhancements to pickle/cPickle don't step on the first characted being 'x', and only if zlib always returns a string with the first characted 'x'. Looking in cPickle.c and pickle.py, I see that capital 'X' is used for type BINUNICODE, but no mention of lowercase 'x'. I can't find anything in zlib, but empirically it seems to be consistant. I figure this was either planned or lucky. If it was planned, a quick comment in the source would relax my fears that my code won't break in the next version of Python. If it was lucky, it might be nice to jump on the opportunity. So can I rely on the first character 'x' being reserved for zlib, and cPickle/pickle strings never starting with 'x'? Cheers, -Scott Gilbert (BTW: In cases somebody asks why I don't just prefix my dump strings saying where they came from: The dumps can be rather large (maybe 10's of megabytes), and I really don't want to have to create a multiple megabyte substring from the original.) From emile at fenx.com Fri Mar 1 22:25:37 2002 From: emile at fenx.com (Emile van Sebille) Date: Fri, 1 Mar 2002 13:25:37 -0800 Subject: mult-indexed xrange? References: Message-ID: for (x,y, z) in [(i,j, k) for i in range(2) for j in range(3) for k in range(2) ]: print x,y, z -- Emile van Sebille emile at fenx.com From cfelling at iae.nl Fri Mar 1 22:25:19 2002 From: cfelling at iae.nl (Carel Fellinger) Date: 1 Mar 2002 22:25:19 +0100 Subject: PEP 276 (was Re: Status of PEP's?) References: Message-ID: James_Althoff at i2.com wrote: ... > [Carel Fellinger] >> you being such a heavy weight that I fear ... > Well, thanks (I think ), but I can assure you that I hold no special You think right, which could have be infered from *me* calling you a heavy weight, might you have known me:) ... > [Carel Fellinger] >> Not only newbie unfriedly, you need a firm grasp of modern set >> based number theory to appreciate it, it seems. > As fond as we all surely are of the neat mathematical underpinnings > suggested here and before, I believe that most programmers -- regardless of > skill level (and pedigree in the field of mathematics) -- would be able to > understand -- and certainly easily remember the second time -- that > iterating on n means taking each of 0,1,2, ..., n-1 in turn; this without > having to think about -- much less have "a firm grasp of" -- number theory > (modern, set-based, or otherwise ). At least if one has enough > background to understand "iteration" to begin with. I admit I will be able to remember this, know how and when to use it and all that. And certainly programmers in general will be able to handle it, hey some of them even handle APL (or so they believe). But even after that nice math lesson I still don't *understand* it, you iterate over a sequence and I have a hard time seeing an integer as a sequence. Same for a length. And I believe many would have the same problem. Besides, I don't see the huge advantage of this compared to `range(integer)' or `indici(sequenceORmapping)'. Unfortunately the whole subject has moved from a `preference' via `lack of knowledge' to a matter of `believe', so not much of a chance to resolve it:) > Let's try that again. > Q: What does it mean to iterate a number n? A: I wouldn't know. O wait you mean that awfull hack, yea I know, pretend an integer is a sequence... > I certainly acknowledge the feelings of those who don't like the suggested > idiom. At the same time, claims of its alleged *great difficulty* seem > overblown. It's not difficult to use once it's been explained, it's difficult to understand no matter how often it gets explained. > [Carel Fellinger] >> So please explain why you think it natural to loop over a number. > The "rational" section of PEP 276 talks about iterating through the indices > of an indexed collection. These, as we know, are related to the length (an > integer) of the indexed collection. far fatched isn't it? What about a function that accepts as argument such a collection and then generates the indici? Much easier to explain, to understand, to adopt. But admitted, it takes a little extra typing. Seriously I would like you to add something in your PEP that addresses this simple alternative and explain why you favour yours. True, `i in range(len(sequence))' doesn't look very pleasing, but `i in indici(sequence)' does. And as an added bonus it's very similar to `(i, item) in indexed(sequence)'. > [Carel Fellinger] >> here in your PEP you make it look like some minority >> of nitwits objected > I don't remember writing anything about nitwits. But that does remind me I'm sorry. Those are my words, and my words only. I was a bit itchy that day, would have formulated it differently now. But I do think that dismissing our point as a matter of preference misses our point. > [Remco Gerlich] >> Compare: >> >> for i in 6: print i >> for i in 6,7: print i >> for i in 6,7,8: print i >> >> You wouldn't think the first line does something different, would you? > [Emile van Sebille] >> Is that really any different from what we have now: >> >> for i in "Spam": print i >> for i in "Spam","and": print i >> for i in "Spam","and", "Eggs": print i > [Andy Gimblett] >> Yes, it really is. "Spam" is a sequence, whereas 6 isn't. > I agree with Emile on this one. To me this means you actually see and int as a sequence then. A string is a sequence, a sequence of chars. I still fail to understand how the same applies to integers. > Two different results. One needs to understand how and why. Sometimes one > wants to treat a string as a unit, other times as a sequence. It's useful > and convenient to be able to do both. I agree, but can't relate this to integers. looking forward to your views on meta programming though -- groetjes, carel From gcordova at hebmex.com Fri Mar 1 22:32:48 2002 From: gcordova at hebmex.com (Gustavo Cordova) Date: Fri, 1 Mar 2002 15:32:48 -0600 Subject: Code Review!! (or bash!) Message-ID: <19650FF08A99D511B19E00B0D0F06323060B2B@SRM201002> Howdy y'alls. "Once upon a time in a Python List far far away...", some one bitterly asked why python doesn't include an XML parser, since it relied on expat to do it's XML parsing for it. And that got me thinking... so, since I usually get a bit bored for an hour or so during lunchtime, I wrote a tiny, toy XML parser with a few helper classes. Emphasis on tiny toy. Before I let it out into the wild, I'd like to know what you all people think about this toy. I know, there's xml.dom stuff, and xml.sax stuff, but I can't seem to wrap my brain around it, so I just started writing this out of curiosity, and now it's starting to feel useful. But "useful" is so subjective, isn't it. :-) Mind you, it only works for 8-bit chars, so there's a limitation. So, here it is. -- Gustavo C?rdova Avila gcordova at sismex.com 8351-3861 | 8351-3862 -------------- next part -------------- A non-text attachment was scrubbed... Name: miniXML3.py Type: application/octet-stream Size: 19033 bytes Desc: not available Url : http://mail.python.org/pipermail/python-list/attachments/20020301/95fb24e6/attachment.obj From martin at v.loewis.de Fri Mar 1 22:37:53 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 01 Mar 2002 22:37:53 +0100 Subject: pickle, cPickle, zlib, and the future References: <79b2b0bb.0203011329.79469c5b@posting.google.com> Message-ID: xscottgjunk at yahoo.com (Scott Gilbert) writes: > I figure this was either planned or lucky. If it was planned, a quick > comment in the source would relax my fears that my code won't break in > the next version of Python. If it was lucky, it might be nice to jump > on the opportunity. I guess it was lucky. > So can I rely on the first character 'x' being reserved for zlib, and > cPickle/pickle strings never starting with 'x'? At the moment, no. If you can point to some zlib documentation that explains what the 'x' on each output does (*), feel free to submit a patch to the pickle implementations that documents (in a comment) that letter as being reserved for this purpose; it seems no harm is done doing so. Please submit that patch to sf.net/projects/python. Regards, Martin From donn at u.washington.edu Fri Mar 1 22:21:45 2002 From: donn at u.washington.edu (Donn Cave) Date: 1 Mar 2002 21:21:45 GMT Subject: Securely passing arguments when opening a pipe to a program References: <3C7FE115.9832EE5C@olen.to> Message-ID: Quoth Joonas Paalasmaa : | I am using Gnokii to send SMS messages with Python. Gnokii is started | with | popen2.popen2 like this: | | gnokiiRead, gnokiiWrite = popen2.popen2("gnokii --sendsms %s" % | phonenumber) | gnokiiWrite.write(message) | gnokiiWrite.close() | response = gnokiiRead.read() | gnokiiRead.close() | | The problem is that the phonenumber string is not safe; it can even be | "000; rm -fR ~/*". How can I securely pass arguments when opening the | pipe? | Is there a way to pass the arguments like in os.execv. Yes! I hear this isn't documented as well as it could be, but popen2 accepts either a string or a sequence, and in the latter case the sequence is argv, like in os.execv. Donn Cave, donn at u.washington.edu From James_Althoff at i2.com Fri Mar 1 22:47:00 2002 From: James_Althoff at i2.com (James_Althoff at i2.com) Date: Fri, 1 Mar 2002 13:47:00 -0800 Subject: Status of PEP's? Message-ID: [Jim] > For example, one problem I had when playing with an experimental > implementation of the "middle argument" variant mentioned above is that the > specific relational operators are tied to the values of the bounds. If you > want to iterate from the smaller value (up) to the larger value you write: > > for 1 <= var < 5: > > whereas if you want to iterate from the larger value (down) to the smaller > value you have to turn things around and write: > > for 5 > var >= 1: > > which all looks very nice when you are dealing with literal constants. But > suppose you have variables for the bounds, "start" and "end"? Let's say I > have a function > > def doSomethingFromTo(start,end): > > The function has to test to see which of "start" and "end" is the smaller > value in order to know whether to execute a for-loop with "<" or a for-loop > with ">" (and the code specified in each separate for-loop has to be > written redundantly). I found this to be awkward. [Greg Ewing] > But if you really want, you can > always sort out the argument order before entering > the loop, e.g. > > if start > end: > start, end = end, start > for start <= i < end: > ... > > No redundant for-loop code required. But I don't get the specified behavior, either. [David Eppstein] > What's wrong with > for min(start,end) < var < max(start,end) > ? It gives different results than specified. Let's take an example. Suppose start == 10 and end == 5 This means I want to iterate on 10,9,8,7,6,5 (ignore open vs closed -- not relevant here) in *that* order. In Greg's case we swap start and end and do for 5 <= i <= 10 and iterate 5,6,7,8,9,10 -- the right numbers but the wrong order. In David's case we pick 5 as the min and 10 as the max do for 5 <= var <= 10 and iterate 5,6,7,8,9,10 -- same deal. In other words, if I want to iterate up (smaller up to larger) I need to write the for-loop as for smaller <= i <= larger: # can *only* iterate up but if I want to iterate down (larger down to smaller) I need to write the for-loop with the reverse relational operators for larger >= i >= smaller: # can *only* iterate down So if you want/need "from/to" functionality for an "interval" using the suggested for+relational idiom, you need to have two for-loops at hand, test the bounds, *and* pick the corresponding, correct for-loop (whose relational operators are in the correct direction). Note that the existing range and xrange functions (when used in a for-loop), although requiring a test on the bounds in order to determine the correct order of the args, do *not* require the use of two for-loops in this context. for i in range(n,m,step): # can iterate up or down depending on n,m,step I would like to be able to create a "directional, interval-like" object that iterates 10,9,8,7,6,5 (for example) as well as one that iterates 5,6,7,8,9,10 -- and do that with *one* construct, not two (in a for-loops, list-comp.s, or anywhere else). Using the much beloved (by few beside me ) "overload the divide operators" approach (just to illustrate the point, no need to flame the syntax again ), you can do this by saying interval_5to10 = 5 // span // 10 interval_10to5 = 10 // span // 5 so that one for-loop does the trick for i in start // span // end: # can iterate up *or* down, just like range can The fact that the suggested for+relational idiom *does* require two loops seems like a step backwards (again, in *this* context) to me. Or a limitation, at least. Just to clarify. Jim From metaliu at yahoo.com Fri Mar 1 22:47:57 2002 From: metaliu at yahoo.com (BL) Date: Fri, 1 Mar 2002 13:47:57 -0800 Subject: new images from strings using PIL Message-ID: New at python and PIL so bear with me: I'm having difficulties creating images from strings. Basically, I have a string of integers I would like to create an image from. I'm trying to use python's PIL function Image.fromstring() to do this (any other methods of doing this would be appreciated). So I do: pixels = "1 2 3 4 5 6" //test pixels im = Image.fromstring("I", (2,1), pixels) //create a 3x2 image from pixels I'm not actually sure how to read the pixel data in im. im.getdata() returns: Also, im.getextrema() returns: (540155953, 540287027) These values are obviously wrong. Why isn't my 3x2 image being created with the proper pixel intensities? Thanks in advance, Bill From cfelling at iae.nl Fri Mar 1 22:54:11 2002 From: cfelling at iae.nl (Carel Fellinger) Date: 1 Mar 2002 22:54:11 +0100 Subject: __abs(self)__? References: Message-ID: Mike Carifio wrote: > I'm reading about special method names. __abs__(self), which maps to the > abs() method seems unneccessary(?). > So: > class ExampleNumber: > def __init__(self, initializer): > self.value = initializer > def __abs__(self): > return abs(self.value) >>>> x = ExampleNumber(-1) >>>> x.abs() > 1 strange, you haven't defined a method `abs' for `ExampleNumber's! I would expect: Traceback (most recent call last): File "", line 1, in ? AttributeError: ExampleNumber instance has no attribute 'abs' >>> unless you typed: >>> abs(x) in which case x.__abs__() is called under the hoods. > abs is a builtin function, so why do I need a special name for a function? > I'm missing something... many builtins work on instances of user defined classes by expecting a special named method (those methods names are easily recognizable due to the leading and trailing double underscores) So you have a generic builtin fucntion abs, you use it on integers and homebrew number classes alike, `abs(instance)' and all works as it should. -- groetjes, carel From jwilhelm at outsourcefinancial.com Fri Mar 1 23:18:14 2002 From: jwilhelm at outsourcefinancial.com (Joseph Wilhelm) Date: 01 Mar 2002 15:18:14 -0700 Subject: Problems with multipart messages w/email class In-Reply-To: <1015006362.1673.7.camel@jwilhelm.ofsloans.com> References: <1015006362.1673.7.camel@jwilhelm.ofsloans.com> Message-ID: <1015021094.1672.19.camel@jwilhelm.ofsloans.com> On Fri, 2002-03-01 at 11:12, Joseph Wilhelm wrote: > Traceback (most recent call last): > File "", line 1, in ? > File "/opt/python/lib/python2.2/email/Message.py", line 59, in > as_string > g(self, unixfrom=unixfrom) > File "/opt/python/lib/python2.2/email/Generator.py", line 83, in > __call__ > self._write(msg) > File "/opt/python/lib/python2.2/email/Generator.py", line 104, in > _write > self._dispatch(msg) > File "/opt/python/lib/python2.2/email/Generator.py", line 134, in > _dispatch > meth(msg) > File "/opt/python/lib/python2.2/email/Generator.py", line 240, in > _handle_multipart > for part in msg.get_payload(): > File "/opt/python/lib/python2.2/email/Message.py", line 151, in > __getitem__ > return self.get(name) > File "/opt/python/lib/python2.2/email/Message.py", line 214, in get > name = name.lower() > AttributeError: 'int' object has no attribute 'lower' Well, I have gotten a small fix for this traceback put into my copy of Generator.py. I don't know if it should be necessarry, but this is what I got to make it work (At line 240): I replaced for part in msg.get_payload(): With pload = msg.get_payload() if type( pload ) is not ListType: pload = [ pload ] for part in pload: Just something very small and simple, but it was necessarry to make this email work properly. Any comments on this? Is this a known bug? Is there something I may have done wrong that would cause the previous error? --Joseph Wilhelm From James_Althoff at i2.com Fri Mar 1 23:19:05 2002 From: James_Althoff at i2.com (James_Althoff at i2.com) Date: Fri, 1 Mar 2002 14:19:05 -0800 Subject: Status of PEP's? Message-ID: [Timothy Delaney] > For the record (I've said this before), I like the idea of integers > being iterable (and I'm not a set theory wonk). [Alan Daniels] > That's fine if you like the idea. I don't. The only validations > I've seen for it are obscure references to set theory, or the vague > notion that it looks neat since it would make Python read more like > Haskell (or insert whatever favorite research langugage here). I have > yet to see any meaningful explanation on how it fixes some gap in > Python, or improves it other than saving the need to type the word > "xrange". The actual PEP has a "rationale" section. Neither set theory nor Haskell come into play in the rationale. If you are happy with xrange when dealing with the indices of indexed-collections, then you will not be swayed by the rationale for PEP 276. Not everyone has thought xrange to be ideal, though. > While I'm at it, two problems with it that I haven't yet seen > addressed: > > 1) If you have a class that defines both __int__ and __getitem__ > methods, and iterate over an instance of it, which method "wins" > comes iteration time? The usual, or the "for i in 5" trick? PEP 276 doesn't propose any tricks. It suggests adding an iterator to the int class. If you define your own class with an instance x, and do "for i in x" the for-loop will try to get an iterator from your instance x -- just because that's what the for-loop does. PEP 276 doesn't affect this behavior in any way. > Maybe this is covered in PEP 276. I've read through it once when > it was first introduced and didn't see any mention on how this > would be handled. I'd read it through again, but it's late and > frankly reading it makes my skin crawl. Don't worry, I have some ointment for you . (Seriously though, is that kind of comment really necessary? I understand that you strongly dislike the proposal. But throwing in zingers isn't very considerate). > 2) Anyone new to the language will wonder exactly why it is that they > can iterate over ints, strings, tuples, lists, dictionaries, > files, generators, and indeed, any class instance that implements > an iterable interface... > > ...but not floats. Hey, if "for i in 5" means something, then > obviously "for i in 5.0" should mean something too, right? That's > what a newbie will think, and what good reason answer will anyone > be able to give them? Play with some code and see if you can come up with a meaningful, useful, practical, and reasonable-to-implement definition for a sequence of numbers related to a given floating point number x. I suspect that you will find a lot of tricky issues. > As I've come to think of it, the whole point of > "iterating" is that the programmer is walking through a collection: Others clearly agree with this perspective. I think that it is overly-restrictive to say that the *only* thing that you can iterate is a collection. > I can NEVER bring myself to see an integer as a collection, > not outside of a lecture on number theory, anyway. There's no requirement to think about number theory or to view integers as collections here. All that is suggested is a slightly-less cluttered (than current) way to iterate the indices of an indexed-collection. If you are happy with range/xrange, so be it. > Sorry to rant, but this is the only idea for Python I've seen > in a VERY long time, since the 1.5.2 days, where rather than > capturing my interest and giving me something to contemplate, just > strikes me as ugly, and stays ugly no matter how long I look at it. Well then, I guess you'll be giving PEP 276 high marks for "originality" . Jim From martin at v.loewis.de Fri Mar 1 23:23:45 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 01 Mar 2002 23:23:45 +0100 Subject: Code Review!! (or bash!) References: Message-ID: Gustavo Cordova writes: > "Once upon a time in a Python List far far away...", some one > bitterly asked why python doesn't include an XML parser, since it > relied on expat to do it's XML parsing for it. PyXML provides xmlproc, a pure-Python, full-featured, validating XML parser. Regards, Martin From shalehperry at attbi.com Fri Mar 1 23:33:22 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Fri, 01 Mar 2002 14:33:22 -0800 (PST) Subject: Code Review!! (or bash!) In-Reply-To: <19650FF08A99D511B19E00B0D0F06323060B2B@SRM201002> Message-ID: > > Before I let it out into the wild, I'd like to know what you > all people think about this toy. I know, there's xml.dom stuff, > and xml.sax stuff, but I can't seem to wrap my brain around it, > so I just started writing this out of curiosity, and now it's > starting to feel useful. But "useful" is so subjective, isn't it. > >:-) > > Mind you, it only works for 8-bit chars, so there's a limitation. > Verbose. Nice. The re.compile() where you buld the 'amp|lt|gt' string took me a moment to parse, but other than that it reads pretty well. One possible comment for future development. The ENTITIES list must always begin with ('&', '&') or the encode_entities() function may hiccup because it will encode say 'copy sign' to '©' and then turn that into '&copy;'. From James_Althoff at i2.com Fri Mar 1 23:33:44 2002 From: James_Althoff at i2.com (James_Althoff at i2.com) Date: Fri, 1 Mar 2002 14:33:44 -0800 Subject: Status of PEP's? Message-ID: [Bjorn Pettersen] > with this syntax you have different semantics for: > > for start <= i < end: > > And > > if start <= i < end: [David Eppstein] > Different in what sense? > > "for something" loops over all values of the variable that make > "something" true. Which part of "something" is the variable is determined > by its location in the overall expression. > > That is true with the current "for x in y" syntax as well as > the suggested "for start <= i < end" syntax. > Well, except that by "all values" substitute "all integer values" > since it doesn't make sense to loop over all floats. But that kind of definition isn't comprehensive enough because, for example, it says nothing about the order of the variables as processed by the for-loop. If you define the for-loop in terms of an iterable object (matching the implementation) the order is covered. And if you stick with an iterator-base view, then the two constructs above start to look different since that latter is clearly based on relational operators not iterators. Jim From max at alcyone.com Fri Mar 1 23:36:44 2002 From: max at alcyone.com (Erik Max Francis) Date: Fri, 01 Mar 2002 14:36:44 -0800 Subject: new images from strings using PIL References: Message-ID: <3C80027C.8B392E8E@alcyone.com> BL wrote: > These values are obviously wrong. Why isn't my 3x2 image being > created with > the proper pixel intensities? Image.fromstring reads in _raw_, binary image data, not text data. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Laws are silent in time of war. \__/ Cicero Esperanto reference / http://www.alcyone.com/max/lang/esperanto/ An Esperanto reference for English speakers. From joonas at olen.to Fri Mar 1 23:28:02 2002 From: joonas at olen.to (Joonas Paalasmaa) Date: Sat, 02 Mar 2002 00:28:02 +0200 Subject: Securely passing arguments when opening a pipe to a program References: <3C7FE115.9832EE5C@olen.to> Message-ID: <3C800072.43CEC524@olen.to> Donn Cave wrote: > > Quoth Joonas Paalasmaa : > | I am using Gnokii to send SMS messages with Python. Gnokii is started > | with > | popen2.popen2 like this: > | > | gnokiiRead, gnokiiWrite = popen2.popen2("gnokii --sendsms %s" % > | phonenumber) > | gnokiiWrite.write(message) > | gnokiiWrite.close() > | response = gnokiiRead.read() > | gnokiiRead.close() > | > | The problem is that the phonenumber string is not safe; it can even be > | "000; rm -fR ~/*". How can I securely pass arguments when opening the > | pipe? > | Is there a way to pass the arguments like in os.execv. > > Yes! I hear this isn't documented as well as it could be, but > popen2 accepts either a string or a sequence, and in the latter > case the sequence is argv, like in os.execv. Thanks for the answer. I wonder why this very helpful feature isn't documented in os-module's documentation? From phr-n2002a at nightsong.com Fri Mar 1 23:41:07 2002 From: phr-n2002a at nightsong.com (Paul Rubin) Date: 01 Mar 2002 14:41:07 -0800 Subject: Rotor in Jython? References: Message-ID: <7xr8n329oc.fsf@ruckus.brouhaha.com> writes: > Put another way: sorting by key length, AES beats rotors hands down. > Sorting by computational cost, rotors always win because you can just make > the keys longer (without having to reimplement your crypto). Longer keys are only relevant if breaking the cipher requires searching for the key. From eppstein at ics.uci.edu Fri Mar 1 23:45:21 2002 From: eppstein at ics.uci.edu (David Eppstein) Date: Fri, 01 Mar 2002 14:45:21 -0800 Subject: Status of PEP's? References: Message-ID: In article , James_Althoff at i2.com wrote: > In other words, if I want to iterate up (smaller up to larger) I need to > write the for-loop as > for smaller <= i <= larger: # can *only* iterate up > but if I want to iterate down (larger down to smaller) I need to write the > for-loop with the reverse relational operators > for larger >= i >= smaller: # can *only* iterate down > > So if you want/need "from/to" functionality for an "interval" using the > suggested for+relational idiom, you need to have two for-loops at hand, > test the bounds, *and* pick the corresponding, correct for-loop (whose > relational operators are in the correct direction). > > Note that the existing range and xrange functions (when used in a > for-loop), although requiring a test on the bounds in order to determine > the correct order of the args, do *not* require the use of two for-loops in > this context. > for i in range(n,m,step): # can iterate up or down depending on > n,m,step Ok, I missed your point that the iteration order and not just the endpoints are important in your example. But I think the current range system does too require two loops. Again, let's consider closed intervals. If from <= to: range(from,to+1) If from > to: range(from,to-1,-1) You could sort of avoid this by using a signum function: range(from,to+signum(from-to),signum(from-to)) but (besides being confusing) this breaks when from=to. Anyway, while you may need two ranges, you don't have to have two separate for-loops over those ranges: if from <= to: range = [x for from <= x <= to] else: range = [x for from >= x >= to] for x in range: ... -- David Eppstein UC Irvine Dept. of Information & Computer Science eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/ From jd764 at hotmail.com Fri Mar 1 23:53:13 2002 From: jd764 at hotmail.com (Jeff) Date: 1 Mar 2002 14:53:13 -0800 Subject: 16-bit grayscale images Message-ID: <6c585112.0203011453.2fd2a13f@posting.google.com> I am working on a medical imaging GUI project and am considering learning Python/Tkinter. I am actually trying to migrate from a high-priced software package designed specifically for medical imaging. With Python/Tkinter is there a way to read in, write out, and display 16 bit grayscale images? Or am I wasting my time? Thanks Jeff From skip at pobox.com Sat Mar 2 00:05:59 2002 From: skip at pobox.com (Skip Montanaro) Date: Fri, 1 Mar 2002 17:05:59 -0600 Subject: 16-bit grayscale images In-Reply-To: <6c585112.0203011453.2fd2a13f@posting.google.com> References: <6c585112.0203011453.2fd2a13f@posting.google.com> Message-ID: <15488.2391.822273.937850@12-248-41-177.client.attbi.com> Jeff> With Python/Tkinter is there a way to read in, write out, and Jeff> display 16 bit grayscale images? I suggest you check out PIL and VTK: http://www.pythonware.com/downloads/index.htm#pil http://public.kitware.com/VTK/ Completely different approaches, but I suspect there will be code in both that does what you want. -- Skip Montanaro (skip at pobox.com - http://www.mojam.com/) From spencer at efn.org Fri Mar 1 23:56:44 2002 From: spencer at efn.org (Spencer Ernest Doidge) Date: Fri, 1 Mar 2002 14:56:44 -0800 Subject: Windows Memory Mapped Files Message-ID: Is there a way, running a Python script in a console window, to read/write Memory Mapped files? Spencer Doidge www.spencerdoidge.com From chad.maine at broadlink.com Sat Mar 2 00:06:07 2002 From: chad.maine at broadlink.com (Chad Maine) Date: Fri, 01 Mar 2002 23:06:07 GMT Subject: Multple HTTPS requests over the same socket Message-ID: I have class that opens an SSL socket to an HTTPS server in it's __init__. I then call a class method to send the headers and make the request ( a 'POST') and return the results. If I try to use that same SSL socket again for another request, I get nothing. Is what I'm trying to possible or do I need to close the socket and open another? From les_ander at yahoo.com Sat Mar 2 00:22:21 2002 From: les_ander at yahoo.com (les ander) Date: 1 Mar 2002 15:22:21 -0800 Subject: string to dictionary Message-ID: Hi, i have a list of strings like this: aList=[ 'a_1 b_1', 'a_2 b_2', 'a_3 b_3',...] i want to convert this to a dictionary with a_i -> b_i without using loops (it is trivial to do it with loops) i tried this dict={} map(lambda x,d=dict: c=string.split(x), d[c[0]]=c[1], aList) but it complains that "keyword can't be an expression" can someone please help me get this right? thanks les From db3l at fitlinxx.com Sat Mar 2 00:31:18 2002 From: db3l at fitlinxx.com (David Bolen) Date: 01 Mar 2002 18:31:18 -0500 Subject: Older Python bug entries on SourceForge Message-ID: I was trying to look up an old bug entry on SourceForge (based on a bug number from some CVS log comments) and can't seem to pull it up. Does anyone know if SourceForge expires closed bugs after some time duration or something? Is there any archive available to view old bugs? Thanks. -- -- David -- /-----------------------------------------------------------------------\ \ David Bolen \ E-mail: db3l at fitlinxx.com / | FitLinxx, Inc. \ Phone: (203) 708-5192 | / 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \ \-----------------------------------------------------------------------/ From James_Althoff at i2.com Sat Mar 2 00:37:09 2002 From: James_Althoff at i2.com (James_Althoff at i2.com) Date: Fri, 1 Mar 2002 15:37:09 -0800 Subject: PEP 276 (was Re: Status of PEP's?) Message-ID: [Carel Fellinger] > But even after that nice math lesson I still don't *understand* it, > you iterate over a sequence and I have a hard time seeing an integer > as a sequence. Same for a length. And I believe many would have the > same problem. You're right; apparently they do. Here's how I think of it. Iterators are really useful. When asked to do so they produce items one after another according to some meaningful plan. You can associate an iterator with anything that you think is practical and useful. So, is there any reason to associate an iterator with an integer? PEP 276 suggests that because there are times when you have the length of an indexed-collection and you want to iterate over the indices of that collection it would be convenient to associate an iterator with that "length" number. It just makes it easy and uncluttered to do for rowindex in table.rowcount: process(rowindex) That's it. You don't have to think of integer n as a sequence. You just need to remember that n can produce the iteration 0,1,2,...,n-1. Perhaps it might help to change one's perspective of "for x in y" from "for each object that is a member of y, an ordered aggregation of other things" to "for each object that is produced by the iterator associated with y" Works for me, but, clearly not everyone. :-) >Besides, I don't see the huge advantage of this compared to >`range(integer)' or `indici(sequenceORmapping)'. If you are happy with range and xrange, then PEP 276 won't appeal to you. > What about a function that accepts as argument such a collection > and then generates the indici? Much easier to explain, to understand, > to adopt. But admitted, it takes a little extra typing. > > Seriously I would like you to add something in your PEP that addresses > this simple alternative and explain why you favour yours. True, > `i in range(len(sequence))' doesn't look very pleasing, but > `i in indici(sequence)' does. And as an added bonus it's > very similar to `(i, item) in indexed(sequence)'. This has been suggested and is fine for one-dimensional, indexed-collections that are written in Python and obey the standard protocol for sequences -- specifically that they implement __len__. But how is such a function going to work for a two-dimensional Java table (accessed via Jython)? PEP 276 is more general. And doesn't preclude such a function being added, in any case. > But I do think that dismissing our point as a matter of > preference misses our point. The PEP says this: - Some feel that iterating over the sequence "0, 1, 2, ..., n-1" for an integer n is not intuitive. "for i in 5:" is considered (by some) to be "non-obvious", for example. How does that miss your point? What should it say? > looking forward to your views on meta programming though Thanks. Jim From tk at start.com.au Sat Mar 2 00:45:48 2002 From: tk at start.com.au (Tony K) Date: Fri, 01 Mar 2002 23:45:48 GMT Subject: Stedents Question Message-ID: <3c80126f_1@news.iprimus.com.au> The question below is a tutorial question that stumps me. Any suggestions would be appreciated. Tony Write a Python function findABBC which takes a single string as parameter and returns all substrings thereof which match the regexp pattern ab+c. You are NOT allowed to use the re module. From martin at v.loewis.de Sat Mar 2 00:51:38 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 02 Mar 2002 00:51:38 +0100 Subject: Multple HTTPS requests over the same socket References: Message-ID: "Chad Maine" writes: > I have class that opens an SSL socket to an HTTPS server in it's > __init__. I then call a class method to send the headers and make > the request ( a 'POST') and return the results. If I try to use > that same SSL socket again for another request, I get nothing. Is > what I'm trying to possible or do I need to close the socket and > open another? At a minimum, it depends on the protocol you are using. You need to use HTTP/1.1., and post a Connection: Keep-alive header, otherwise the server will close the socket. The server may still close the connection even if you request that it be kept alive. Regards, Martin From James_Althoff at i2.com Sat Mar 2 00:57:26 2002 From: James_Althoff at i2.com (James_Althoff at i2.com) Date: Fri, 1 Mar 2002 15:57:26 -0800 Subject: Status of PEP's? Message-ID: [Jim] > In other words, if I want to iterate up (smaller up to larger) I need to > write the for-loop as > for smaller <= i <= larger: # can *only* iterate up > but if I want to iterate down (larger down to smaller) I need to write the > for-loop with the reverse relational operators > for larger >= i >= smaller: # can *only* iterate down > > So if you want/need "from/to" functionality for an "interval" using the > suggested for+relational idiom, you need to have two for-loops at hand, > test the bounds, *and* pick the corresponding, correct for-loop (whose > relational operators are in the correct direction). > > Note that the existing range and xrange functions (when used in a > for-loop), although requiring a test on the bounds in order to determine > the correct order of the args, do *not* require the use of two for-loops in > this context. > for i in range(n,m,step): # can iterate up or down depending on > n,m,step [David Eppstein] > Ok, I missed your point that the iteration order and not just the > endpoints are important in your example. > > But I think the current range system does too require two loops. I guess I was still a little fuzzy in my explanation. I meant this: (ignore open/closed stuff) >>> >>> def printFromTo(start,end): ... # only dealing with step == 1 or -1 ... step = 1 ... if start > end: ... step = -1 ... for i in range(start,end,step): # up or down ... print i ... >>> printFromTo(5,10) 5 6 7 8 9 >>> printFromTo(10,5) 10 9 8 7 6 >>> > Anyway, while you may need two ranges, you don't have to have two > separate for-loops over those ranges: > if from <= to: range = [x for from <= x <= to] > else: range = [x for from >= x >= to] > for x in range: > ... I agree that if you actualize the ranges using list comp.s as shown, then your one final for-loop is enough. I was counting list comp.s as "for loops", also. But your example shows what I was trying to say. In this case you need one list comp for the "up" case and one for the "down" case. That is the limitation that I was trying to point out. Jim From martin at v.loewis.de Sat Mar 2 00:54:36 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 02 Mar 2002 00:54:36 +0100 Subject: Older Python bug entries on SourceForge References: Message-ID: David Bolen writes: > I was trying to look up an old bug entry on SourceForge (based on a > bug number from some CVS log comments) and can't seem to pull it up. > Does anyone know if SourceForge expires closed bugs after some time > duration or something? Is there any archive available to view old > bugs? Normally, they will be kept forever. However, when SF updated the software to generalize trackers (i.e. making the bug tracker an instance of a general feature), they had to renumber all existing bugs. So if you have a bug number below 300000, SF will have renumbered the bug by now. They used to have a backwards-compatible URL in place, redirecting to the new report, but they may have disabled that by now. Regards, Martin From robin at jessikat.fsnet.co.uk Sat Mar 2 00:58:21 2002 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Fri, 1 Mar 2002 23:58:21 +0000 Subject: win32+popen4 References: <$4LupWAmqsf8Ew0o@jessikat.fsnet.co.uk> <3C7FF015.D1A00D13@ccvcorp.com> Message-ID: In article <3C7FF015.D1A00D13 at ccvcorp.com>, Jeff Shannon writes ..... >Note that you've got an extra backslash in your version -- you want a >single escaped double quote after 'bongo.exe', not an escaped backslash >followed by an unescaped double quote. Raw strings will save you much >pain. > ..... interestingly I don't seem to need the \ quotes in win2k. What system is it that needs those? I know that in unices it's possible to create files with very odd names including things with spaces in. Therefore the included space can happen and there I would expect to be able to use either " " or ' ' and provided that system/popen uses a shell I would expect to get away with quite strange paths. -- Robin Becker From python at chajadan.net Sat Mar 2 04:15:36 2002 From: python at chajadan.net (chajadan) Date: Fri, 01 Mar 2002 19:15:36 -0800 Subject: wxPython error on import -- number 2 Message-ID: <5.1.0.14.0.20020301191524.00a82ec0@63.118.78.184> I get this error: from wxPython.wx import * SystemError: C:\Code\22\Objects\listobject.c:88: bad argument to internal function Now, there is no C:\Code\22\ anything on my comp, but maybe you guessed that. This error generates with or without the .wx on wxPython I'm on Windows, using python 2.2 and wxPython (Hybrid) for 2.2 hmm.... maybe it's this hybrid thing... any help, as always, gives me less work to do ;) --chajadan From James_Althoff at i2.com Sat Mar 2 01:04:16 2002 From: James_Althoff at i2.com (James_Althoff at i2.com) Date: Fri, 1 Mar 2002 16:04:16 -0800 Subject: Status of PEP's? Message-ID: [David Eppstein] > I was starting to think it might be time to write a > PEP, but then Tim's comment about how he dislikes iterating > over 3 discouraged me. [Bjorn Pettersen] > I would still encourage you to write a PEP, especially if you think > this should be implemented instead of PEP 276. I agree as I just remembered another issue that came up concerning the "for-relational" suggestion. Namely, that the "for-relational" syntax doesn't handle step values for intervals. So even though there would be new syntax, we would still need to use range/xrange in cases requiring a step value not equal to 1 or -1. Jim From gvdbogae at vub.ac.be Sat Mar 2 01:12:14 2002 From: gvdbogae at vub.ac.be (Geert-Jan Van den Bogaerde) Date: 02 Mar 2002 01:12:14 +0100 Subject: Stedents Question In-Reply-To: <3c80126f_1@news.iprimus.com.au> References: <3c80126f_1@news.iprimus.com.au> Message-ID: <1015027935.1342.3.camel@gandalf> On Sat, 2002-03-02 at 00:45, Tony K wrote: > The question below is a tutorial question that stumps me. Any suggestions > would be appreciated. > Tony > > Write a Python function findABBC which takes a single string as parameter > and returns all substrings thereof which match the regexp pattern ab+c. You > are NOT allowed to use the re module. > Haven't used regexps in a while, but I believe that just means: def findABBC(str): return str == "a" + "b" * len(str[1:-1]) + "c" Geert-Jan From martin at v.loewis.de Sat Mar 2 01:08:18 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 02 Mar 2002 01:08:18 +0100 Subject: Windows Memory Mapped Files References: Message-ID: Spencer Ernest Doidge writes: > Is there a way, running a Python script in a console window, to read/write > Memory Mapped files? Using the mmap module, this should be possible. Regards, Martin From gvdbogae at vub.ac.be Sat Mar 2 01:16:57 2002 From: gvdbogae at vub.ac.be (Geert-Jan Van den Bogaerde) Date: 02 Mar 2002 01:16:57 +0100 Subject: Stedents Question In-Reply-To: <1015027935.1342.3.camel@gandalf> References: <3c80126f_1@news.iprimus.com.au> <1015027935.1342.3.camel@gandalf> Message-ID: <1015028218.1341.9.camel@gandalf> On Sat, 2002-03-02 at 01:12, Geert-Jan Van den Bogaerde wrote: > On Sat, 2002-03-02 at 00:45, Tony K wrote: > > The question below is a tutorial question that stumps me. Any suggestions > > would be appreciated. > > Tony > > > > Write a Python function findABBC which takes a single string as parameter > > and returns all substrings thereof which match the regexp pattern ab+c. You > > are NOT allowed to use the re module. > > > > Haven't used regexps in a while, but I believe that just means: > > def findABBC(str): > return str == "a" + "b" * len(str[1:-1]) + "c" > And as I press send I spot an error in my code, it should be: def findABBC(str): return len(str) > 2 and str == "a" + "b" * len(str[1:-1]) + "c" as we need at least one b Geert-Jan From James_Althoff at i2.com Sat Mar 2 01:23:55 2002 From: James_Althoff at i2.com (James_Althoff at i2.com) Date: Fri, 1 Mar 2002 16:23:55 -0800 Subject: Status of PEP's? Message-ID: [Jim] > Another issue that I have is that the syntax does not work outside of a > for-loop header. I want to be able to create integer intervals anywhere in > my code, not just in the header of a for-loop. [David Eppstein] > [x for 3 <= x < 10] Agreed, the for+relational syntax works in list comp.s. (Again, I was lumping list comp.s in with for-loops). I was thinking in a more general sense: I would like to create an iterator with start, end, and step values and pass it into a function without first actualizing it as a list (like one would have to do using for+relational in conjunction with list comp.s). And use the same construct in for-loops, list comp.s, etc. (For those just tuning in: I realize that I can create a class for this -- actually, I already have. I'm refering to proposals for new idioms in Python for iterating intervals of integers.) Jim From mats at laplaza.org Sat Mar 2 01:22:58 2002 From: mats at laplaza.org (Mats Wichmann) Date: Sat, 02 Mar 2002 00:22:58 GMT Subject: (OT?) Web-based document review system? Message-ID: <3c801a5b.68374897@news.laplaza.org> Note: this is not a Python question per se. I'm looking for a piece of software to aid in reviewing a document through the web - click on a paragraph tag, have the comment added (highlighted in some way). The wiki style doesn't seem to quite do it, as the core document is not protected. I haven't found much in web searches, and nothing where the software seems to be free. I'd of course love it if this were done through Python since I'm on a bit of an advocacy kick...but in the end it doesn't matter much. Anybody know if anything like this is happening in any of the web services projects? Mats Wichmann From cfelling at iae.nl Sat Mar 2 01:31:42 2002 From: cfelling at iae.nl (Carel Fellinger) Date: 2 Mar 2002 01:31:42 +0100 Subject: string to dictionary References: Message-ID: les ander wrote: > Hi, > i have a list of strings like this: > aList=[ 'a_1 b_1', 'a_2 b_2', 'a_3 b_3',...] > i want to convert this to a dictionary with a_i -> b_i without > using loops (it is trivial to do it with loops) > i tried this > dict={} > map(lambda x,d=dict: c=string.split(x), d[c[0]]=c[1], aList) try: >>> map(lambda x: d.__setitem__(*x), [x.split() for x in aList]) [None, None, None] >>> d {'a_3': 'b_3', 'a_2': 'b_2', 'a_1': 'b_1'} of with 2.2: >>> d = dict([x.split() for x in aList]) >>> d {'a_3': 'b_3', 'a_2': 'b_2', 'a_1': 'b_1'} -- groetjes, carel From shalehperry at attbi.com Sat Mar 2 01:35:35 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Fri, 01 Mar 2002 16:35:35 -0800 (PST) Subject: string to dictionary In-Reply-To: Message-ID: On 01-Mar-2002 les ander wrote: > Hi, > i have a list of strings like this: > > aList=[ 'a_1 b_1', 'a_2 b_2', 'a_3 b_3',...] > > i want to convert this to a dictionary with a_i -> b_i without > using loops (it is trivial to do it with loops) > i tried this > > dict={} > map(lambda x,d=dict: c=string.split(x), d[c[0]]=c[1], aList) > > but it complains that "keyword can't be an expression" > can someone please help me get this right? not sure if there is a better way to do this, I just wanted to make what you had work. Use of '=' is not allowed in lambdas. d.setdefault(*string.split(x)) works for me here. Yes it is quite ugly. The *foo syntax causes the tuple that split returns to be flattened into an argument list. This also may not work on 1.5, do not have a copy here to test. From jeff at ccvcorp.com Sat Mar 2 01:48:53 2002 From: jeff at ccvcorp.com (Jeff Shannon) Date: Fri, 01 Mar 2002 16:48:53 -0800 Subject: Status of PEP's? References: Message-ID: <3C802175.A527BFA0@ccvcorp.com> David Eppstein wrote: > In article , > James_Althoff at i2.com wrote: > > > Another issue that I have is that the syntax does not work outside of a > > for-loop header. I want to be able to create integer intervals anywhere in > > my code, not just in the header of a for-loop. > > [x for 3 <= x < 10] Personally, I still don't see this as being an advantage over xrange(3,10). > or, for a slightly more complicated example: yesterday I wanted to iterate > over powers of two: > > [1L << x for 0 <= x < 1000] [1L << x for x in xrange(1000)] While this would benefit from generator comprehension instead of list comprehension, other than that, I don't (personally) see an advantage to the interval-syntax proposal. I suppose it's just a matter of taste, but I'd rather see fewer "nifty syntax tricks" added to Python, and I don't see this as adding enough functionality over xrange() to be worthwhile. Jeff Shannon Technician/Programmer Credit International From claird at starbase.neosoft.com Sat Mar 2 01:54:39 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 1 Mar 2002 18:54:39 -0600 Subject: What readers want (was: Deitel and Deitel Book...) References: <3C7D8DCA.119D52EC@earthlink.net> <899f842.0203010812.6151d817@posting.google.com> Message-ID: <91F926228151D5F5.946DE1D959605688.72F5DF01B36707F9@lp.airnews.net> In article , DeepBleu wrote: . . . >> I would love to see books on Algorithms with Python (makes a perfect >> fit), and more advanced topics such as threads and extending python. > >I'd love to see something like that specially on threads and extending >Python. This is something I can use. >DeepBleu > > How would you feel if such material appeared in magazines rather than books? -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From yajurveda at yahoo.com Sat Mar 2 01:56:20 2002 From: yajurveda at yahoo.com (MShyam) Date: 1 Mar 2002 16:56:20 -0800 Subject: Use of select.select Message-ID: <98a8b53e.0203011656.7aaad470@posting.google.com> Hi, Our product embeds python in C++ and in our py methods, we use select.select in several places. When purifying the executable, we find that when select.select(...) is executed, we find several BSWs, BSRs, IPWs and IPRs (beyond stack writes/reads, invalid pointer writes/reads). Has such a problem been reported? What's the fix? We're using python 1.5.2. Because of these memory errors, we find that eventually our processes dump core. Any assistance is appreciated! thanks, yajurveda at yahoo.com From eppstein at ics.uci.edu Sat Mar 2 02:08:46 2002 From: eppstein at ics.uci.edu (David Eppstein) Date: Fri, 01 Mar 2002 17:08:46 -0800 Subject: Status of PEP's? References: Message-ID: In article , James_Althoff at i2.com wrote: > I agree as I just remembered another issue that came up concerning the > "for-relational" suggestion. Namely, that the "for-relational" syntax > doesn't handle step values for intervals. So even though there would be > new syntax, we would still need to use range/xrange in cases requiring a > step value not equal to 1 or -1. True, it doesn't handle step values, unless you count syntax like [2*x for start <= x < end]. Neither does PEP 276, of course. Nobody is proposing to eliminate range/xrange, I think. I will see if I can find some time to work on a PEP. -- David Eppstein UC Irvine Dept. of Information & Computer Science eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/ From bernie at 3captus.com Sat Mar 2 02:13:27 2002 From: bernie at 3captus.com (Bernard Yue) Date: Sat, 02 Mar 2002 01:13:27 GMT Subject: string to dictionary References: Message-ID: <3C8027BB.1FEA6419@3captus.com> les ander wrote: > > Hi, > i have a list of strings like this: > > aList=[ 'a_1 b_1', 'a_2 b_2', 'a_3 b_3',...] > > i want to convert this to a dictionary with a_i -> b_i without > using loops (it is trivial to do it with loops) > i tried this > > dict={} > map(lambda x,d=dict: c=string.split(x), d[c[0]]=c[1], aList) map(lambda x,d=dict: c=string.split(x), d[c[0]]=c[1], aList) ^ ^ First, assignment is not allowed within lambda. Secondly, the scope of lambda ends at the first comma (correct me if I were wrong). Hence d[c[0]=c[1] become a list and since c is not defined outside lambda, the error message resulted. The following code should work: >>> aList=[ 'a_1 b_1', 'a_2 b_2', 'a_3 b_3'] >>> dict = {} >>> map( lambda x, d=dict: d.update( {x.split()[0] : x.split()[1]}), aList) [None, None, None] >>> dict {'a_1': 'b_1', 'a_2': 'b_2', 'a_3': 'b_3'} >>> I would like to see a better solution as I find using split() twice ugly > > but it complains that "keyword can't be an expression" > can someone please help me get this right? > thanks > les Bernie -- There are three schools of magic. One: State a tautology, then ring the changes on its corollaries; that's philosophy. Two: Record many facts. Try to find a pattern. Then make a wrong guess at the next fact; that's science. Three: Be aware that you live in a malevolent Universe controlled by Murphy's Law, sometimes offset by Brewster's Factor; that's engineering. So far as I can remember, there is not one word in the Gospels in praise of intelligence. -- Bertrand Russell From claird at starbase.neosoft.com Sat Mar 2 02:14:11 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 1 Mar 2002 19:14:11 -0600 Subject: hotmail References: Message-ID: In article , Gillou wrote: >If you got a pop3 access to your hotmail account, have a look at the >"poplib" package. This is the easiest way. > >If you can only read your mail through Web pages, I think that "urllib" >(performs HTTP GET/POST requests and retrieve Web pages) and "htmllib" >(simple HTML parser) will help you for that job. But it's harder. . . . POP3 is *much* easier, whenever practical. As admirable as urllib and htmllib are, this sort of "Web scraping" invariably turns out to be hard, hard work. The sites most in need of automatic processing are generally barricaded behind cookies and other impedimenta that are a poor fit for urllib--and it's best we not talk about the parseability of their HTML! Those who insist on scraping should read If you do so, you're only a couple of clicks more from locating , "a neat little utility to download mail from a HotMail account ..." -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From jlh at cox.net Sat Mar 2 02:18:01 2002 From: jlh at cox.net (Jeff Hinrichs) Date: Sat, 02 Mar 2002 01:18:01 GMT Subject: Status of PEP's? References: Message-ID: wrote in message news:mailman.1015021205.11416.python-list at python.org... [...snip...] > There's no requirement to think about number theory or to view integers as > collections here. All that is suggested is a slightly-less cluttered (than > current) way to iterate the indices of an indexed-collection. If you are > happy with range/xrange, so be it. What you are asking everyone to agree with is: 5 = [0,1,2,3,4] I would fall in the camp that does not favor this. If you were to restate the above as: f(5)=[0,1,2,3,4] Then, I believe, that you wouldn't have any problem convincing a large majority that it is possible for f() to produce such an output. That being said, I would find that the argument favors the use of range/xrange over the concept of iterable integers. -Jeff Hinrichs From eppstein at ics.uci.edu Sat Mar 2 02:10:26 2002 From: eppstein at ics.uci.edu (David Eppstein) Date: Fri, 01 Mar 2002 17:10:26 -0800 Subject: Status of PEP's? References: <3C802175.A527BFA0@ccvcorp.com> Message-ID: In article <3C802175.A527BFA0 at ccvcorp.com>, Jeff Shannon wrote: > > [x for 3 <= x < 10] > > Personally, I still don't see this as being an advantage over xrange(3,10). Ok, quick, what if you want to loop over the same values in reverse order? . . . a n s w e r : . . . [x for 10 > x >= 3] or xrange(9,2,-1) Now which is easier to come up with? -- David Eppstein UC Irvine Dept. of Information & Computer Science eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/ From eppstein at ics.uci.edu Sat Mar 2 02:12:40 2002 From: eppstein at ics.uci.edu (David Eppstein) Date: Fri, 01 Mar 2002 17:12:40 -0800 Subject: Status of PEP's? References: Message-ID: In article , James_Althoff at i2.com wrote: > I was thinking in a more general sense: I would like to create an iterator > with start, end, and step values and pass it into a function without first > actualizing it as a list (like one would have to do using for+relational in > conjunction with list comp.s). And use the same construct in for-loops, > list comp.s, etc. (For those just tuning in: I realize that I can create a > class for this -- actually, I already have. I'm refering to proposals for > new idioms in Python for iterating intervals of integers.) Well, you can still always use xrange... Or the recently proposed [yield x for ...] generator-comprehension syntax. -- David Eppstein UC Irvine Dept. of Information & Computer Science eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/ From bokr at oz.net Sat Mar 2 02:38:35 2002 From: bokr at oz.net (Bengt Richter) Date: 2 Mar 2002 01:38:35 GMT Subject: Minor, minor style question References: <5F9A347EAC81A19E.F4E6D6813EA4DC98.17114695240B3A22@lp.airnews.net> Message-ID: On Fri, 01 Mar 2002 12:14:54 -0500, Justin Sheehy wrote: [...] >If those really are the two things being compared, there's a far >better option: > >>>> string = ("abc" >... "def" >... "xyz") >>>> string >'abcdefxyz' > I prefer >>> string = ( ... "abc" ... "def" ... "ghi" ... ) >>> string 'abcdefghi' (Oops, don't mean to say I prefer ghi over xyz ;-) Regards, Bengt Richter From jgardn at alumni.washington.edu Sat Mar 2 02:57:08 2002 From: jgardn at alumni.washington.edu (Jonathan Gardner) Date: Sat, 02 Mar 2002 10:57:08 +0900 Subject: Useful, robust shell utilities References: Message-ID: <%8Wf8.518$Az6.2357@news.hananet.net> Donn Cave scribbled with his keyboard: > Quoth Jonathan Gardner : > | I tried to use the shutil module... and to tell you the truth, it > | stinks. Is there an effort to make a robust, useful shutil module that > | has the equivalent of the unix shell utilities? > > Go ahead. Then keep an eye out on comp.lang.python, and after some > years pass finally someone will mention it: "it stinks", they'll > say, with no particular explanation. =) I didn't mean to be particularly offensive. It was just that the copytree function has this little comment: The source code for this should be considered an example rather than a tool. And it also won't copy to a directory that already exists... this is very different than what 'cp' does. > > | I think it would be nice to make things like 'grep' even... > | > | Here is my wish list. Each of these should implement a significant > | portion of what the GNU utils do. They should be robust, and give > | reasonable results, and reasonable exceptions. > | > | touch, chmod, chown, chgrp, touch > | df, du > | cp, dd, install, mv, rm, shred > > Some of them are essentially POSIX 1003.1 functions, hence supported in > the posix module (which we usually call "os" so it will appear that these > functions are supported on all platforms, whether they really are or not.) > > chmod == chmod() > chown == chown() > chgrp == chown() > rm == unlink() > mv == rename() > dd ~= read(), write(), lseek() > df == fstatvfs() > They do in fact appear in the 'os' module, but they are rather limited to the forms of input they take. For instance, you have to use (octal) numbers for chmod(). There would be a big benefit to see something like: res = chmod("-c", "-R", "u=rwx,g=rx,o=", a_file, another_file, a_directory) Even having a function reference you pass in that returns true or false in answer to questions like, "Shall I delete this directory?" would be very useful. Well, it looks like I'd better get started. I think 'cp', 'rm' and such will be the easiest to implement. Any ideas for a module name? > Donn Cave, donn at u.washington.edu Jonathan (jgardn at u.washington.edu) From jkraska at san.rr.com Sat Mar 2 02:48:30 2002 From: jkraska at san.rr.com (Courageous) Date: Sat, 02 Mar 2002 01:48:30 GMT Subject: Status of PEP's? References: <3C802175.A527BFA0@ccvcorp.com> Message-ID: <76c08ukou81p7lfnnoiftfhaf5v66amglm@4ax.com> >Now which is easier to come up with? for i in [9:3]: ... with the provision that the negative stride is inferable and therefor assumed. This has been rejected already so I hear. But it still seems perfectly clear to me. I guess I'll have to go hunt down the PEP and see what the rejection rationale was... At least we dont have for (exp-list;expr-listl;expr-list): That's nasty, imo. C// From gh_pythonlist at gmx.de Sat Mar 2 03:04:53 2002 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: Sat, 2 Mar 2002 03:04:53 +0100 Subject: Can use python to play MP3 file? In-Reply-To: <3c7ec28f$0$27085$4c41069e@reader1.ash.ops.us.uu.net> References: <3C7E6328.6050500@bigfoot.de> <3c7ec28f$0$27085$4c41069e@reader1.ash.ops.us.uu.net> Message-ID: <20020302020453.GD3201@lilith.hqd-internal> Le 28/02/02 ? 16:52, Tim H ?crivit: > "Gerhard H?ring" wrote: > > Ricky wrote: > > > I hear that PHP can online play MP3 file. Is there any method that > > > can make me play MP3 by using Python CGI? > > > > > > Thanks for any reply! > > > > Do you want to play the MP3 file on the server, like a jukebox. Or do > > you want to stream MP3 files back to the client computer? > > > > (Of course you can do both with Python) > > > > Gerhard > > Do you have examples, links, hints to doing each with python? Playing an MP3 file using pygame (http://www.pygame.org/): import pygame.mixer as mixer mixer.init(44100) mixer.music.load("White Bird.mp3") mixer.music.play() mixer.music.get_busy() print "Press enter to quit." raw_input() OTOH streaming MP3 files from the server to the client has IMHO little to do with Python, it's more of a HTTP thing. As long as you've set the correct content type and played the right tricks with HTML, it should just work. FWIW, there's a streaming MP3 server written in Python at Sourceforge: http://edna.sourceforge.net/ Gerhard -- This sig powered by Python! Au?entemperatur in M?nchen: 4.0 ?C Wind: 3.2 m/s From eppstein at ics.uci.edu Sat Mar 2 02:50:58 2002 From: eppstein at ics.uci.edu (David Eppstein) Date: Fri, 01 Mar 2002 17:50:58 -0800 Subject: Status of PEP's? References: <3C802175.A527BFA0@ccvcorp.com> <76c08ukou81p7lfnnoiftfhaf5v66amglm@4ax.com> Message-ID: In article <76c08ukou81p7lfnnoiftfhaf5v66amglm at 4ax.com>, Courageous wrote: > At least we dont have for (exp-list;expr-listl;expr-list): > > That's nasty, imo. I think a lot of us can agree on that. -- David Eppstein UC Irvine Dept. of Information & Computer Science eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/ From sjones16 at rochester.rr.com Sat Mar 2 02:58:48 2002 From: sjones16 at rochester.rr.com (Seth Jones) Date: Sat, 02 Mar 2002 01:58:48 GMT Subject: (Hopefully) simple IDLE question Message-ID: Hi all, Is there any way to set the current working directory for a file being used in IDLE? I simply want to open a file that is in the same directory as my script, which I've opened into the idle window, and I don't want to hard-code the full path of the file. Failing that, is there any alternative in Windows 95 to the normal command line? I ask, since the reason I'm using IDLE in the first place is to avoid calling my script from the horribly unsatisfying DOS prompt. Failing even that, is there a better way to get error output from a .pyw file than to catch all exceptions and write them to a file? A google search did lead me to an old mailing-list post about adding the option for setting current directories in IDLE, but apparently that hasn't been done yet. I hope someone can convey some wisdom to this poor soul who's still stuck on win95. Thanks in advance for any advice. Keith (not Seth) Jones (^ : From mapler at erinet.com Sat Mar 2 03:06:10 2002 From: mapler at erinet.com (RMaple) Date: Fri, 01 Mar 2002 21:06:10 -0500 Subject: Stop image shift on tkinter button press? Message-ID: <3c8035a8$0$35568$4c5ecdc7@news.erinet.com> Hello, Is there any way to suppress the annoying right/down shift a button image gets whenever the button is rendered with SUNKEN relief? Thanks, Ray From peter at engcorp.com Sat Mar 2 03:20:39 2002 From: peter at engcorp.com (Peter Hansen) Date: Fri, 01 Mar 2002 21:20:39 -0500 Subject: win32+popen4 References: <$4LupWAmqsf8Ew0o@jessikat.fsnet.co.uk> <3C7F6765.94A82394@engcorp.com> Message-ID: <3C8036F7.A0DB600E@engcorp.com> Robin Becker wrote: > > >I'm pretty sure the last time I checked the PROGRA~1 convention still > >worked on WinNT. > > > I'm sure it does and I guess that Program Files will always match as > it's often the first. On the other hand working with a path name > obtained from an execution path there's no guarantee I can always do the > correct conversion by assuming ~1, some end up as ~2 etc. > > Is there a proper way to get the 8.3 name? As Thomas showed, or more concisely with win32api.GetShortPathName(). But if this is not an application for distribution, you can definitely be 99.99% safe relying on progra~1 for that specific file name, since "program files" will be the first directory created with that pattern on almost any WinNT system. I'm just keeping Python pragmatism in mind: if I don't _really_ need to fix it, I wouldn't spend any more time on it, ugly though this solution is. -Peter From bokr at oz.net Sat Mar 2 03:26:34 2002 From: bokr at oz.net (Bengt Richter) Date: 2 Mar 2002 02:26:34 GMT Subject: PEP 263 comments References: <87g03lhm3p.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: On 01 Mar 2002 11:04:06 +0100, Martin von Loewis wrote: >bokr at oz.net (Bengt Richter) writes: [...] > >> Perhaps we could just use a file to contain extra file metadata, >> letting a file of metadata govern other files it names in the same >> directory as itself. Probably a dot file in *nix. > >Nice idea, different PEP. > >> For PEP 263 purposes, it would only need to be a text file with file >> names tab delimited from keyword=encoding-info, with the first line(s) >> perhaps with a glob pattern for a compact way of specifying encoding >> for a lot of files in a directory at once. > >I don't think the file encoding information should be stored in a >different file; the risk of the two files becoming disassociated is >just to big to be acceptable. > Well, there's risk of a sym link becoming dissociated from its file too, but if you are using the mechanism, it's quickly apparent when it breaks. I agree there is a dissociation danger, but when an error pops up, it will be easy to add the misbehaving file's name to the local meta-data directory file. Encoding detection tools also could do a one-time scan of a directory and validate the metadata, or at least warn. If desired you can hide the actual data file by renaming it to a hashed or other alias name, using the metadata entry to show the original name and its symlink-like location option to point to the renamed file. Thus you force the tools either not to find file_orig_name, or to look in the directory file, where it will find file_orig_name encoding=UTF-8 location=./hashedname or not find it at all, but meta-data would not silently be ignored. But the best way to keep metadata is with actual file system support, as Paul Prescod mentioned privately (and I was about to go into when I decided my post was getting too long ;-) What I want is a universal file typing metadata prefix with codes issued through a registry system that assigns numbers in a way that provides for both common de facto standards and private company proprietary file types. The prefix would be copied with any copy of the data file, but it would be excluded from the range of normal seek operations. If the prefix contained a location symlink, that would be all that was copied by default. Data-verifiable links could contain md5 hashes of the data they link to. The reason for the location link option is to be able to wrap legacy files and whole file systems without modifying them, yet being able to integrate them into the new file system. I like the idea of doing the prefix in UTF-8 so that a local system can wrap a foreign system with local file names in the "symlinks". Think of it as meta-data-enhanced UTF-8-encoded super-symlinks, with the principal purpose of carrying universal-file-type-code & encoding-id in the meta-data, and the option of an absent location-link meaning data follows immediately in the same container as the super-symlink. Note that not touching the linked file's data would allow you to enhance the meta-data to handle compounded encoding formats which would not allow embedding -*- "cookies" -*-, such zip, tgz, pgp, bin64, etc., etc. You could create a new file with the metadata as a prefix with data immediately following (probably on a block boundary), but this would be nicest with file system support. >> To provide international encoding for file-associated info, like >> a local dialect/special characters name etc., in a system whose >> native file naming is more restricted, perhaps this directory of >> file attributes could be standardized to UTF-8 for its own encoding. > >We are not talking about file names here, but about file contents. > Right, I was 'introducing an optional side benefit'[1] of the main idea. IOW, you could e.g. have optional meta-data containing a sanskrit string for whatever purpose, irrespective of the type or encoding declared for the file that the meta-data was associated with. If the meta-data file were standardly always UTF-8 encoded, there would be no restriction on *its* content, though the associated data file might be EBCDIC or whatever. Whether you wanted to support file annotations, or special-language display names or whatever would be a design decision above the super-symlink general infrastructure I am describing. [1] I guess that's a bad habit when trying to communicate a main idea ;-/ >> There are some changes as to legality checks, apparently, >> as of last May. I'm wondering if this affects PEP 263 >> and/or the unicode implementation in Python. > >That doesn't affect this PEP; as for the Unicode 3.1 conformance, I >believe the current CVS implements UTF-8 correctly. > I'll take your word for it ;-) BTW, if my display font is Lucida Console will I be able to see infinity like the 'A' in the following? >>> u'\u0041' u'A' >>> u'\u221e' u'\u221e' Will the following work? >>> print u'\u0041' A >>> print u'\u221e' Traceback (most recent call last): File "", line 1, in ? UnicodeError: ASCII encoding error: ordinal not in range(128) >>> And if I redirect the output to a file, what will be in the file? Regards, Bengt Richter From wayne at mishre.com Sat Mar 2 03:52:42 2002 From: wayne at mishre.com (Wayne Pierce) Date: Fri, 01 Mar 2002 18:52:42 -0800 Subject: (OT?) Web-based document review system? References: <3c801a5b.68374897@news.laplaza.org> Message-ID: <3C803E7A.6000200@mishre.com> Mats Wichmann wrote: > Note: this is not a Python question per se. > > I'm looking for a piece of software to aid in reviewing a document > through the web - click on a paragraph tag, have the comment added > (highlighted in some way). The wiki style doesn't seem to quite do it, > as the core document is not protected. I haven't found much in web > searches, and nothing where the software seems to be free. If Wiki allowed for password protection would it fit your requirements? I run a Wiki on Zope (ZWiki), which allows for password protection. You could also use Apache and setup the httpd.conf file to require authentication when someone accessed that part of the site. Something like Zope's CMF Workflow[2] might also be a good fit....then there's OpenFlow[3] (also running on Zope :). > I'd of course love it if this were done through Python since I'm on a > bit of an advocacy kick...but in the end it doesn't matter much. > Anybody know if anything like this is happening in any of the web > services projects? I don't know if these __exactly__ match what you are looking for, but hopefully they will get you started. [1] http://www.zwiki.org/FrontPage [2] http://cmf.zope.org/design/design/interfaces/tools/IF_portal_workflow [3] http://openflow.sourceforge.net/ -- Wayne Pierce web: http://www.mishre.com email: wayne at mishre.com "What you need to know." From shriek at gmx.co.uk Sat Mar 2 04:09:36 2002 From: shriek at gmx.co.uk (Stephen) Date: 1 Mar 2002 19:09:36 -0800 Subject: Want to monitor process.. References: <87550ef1.0202272315.15779bbd@posting.google.com> <97ae44ee.0202280901.3153bdfc@posting.google.com> <3C7EC9C6.D11FB17@engcorp.com> <97ae44ee.0203010102.14ebf2bb@posting.google.com> <3C7F66AB.D51BEA03@engcorp.com> Message-ID: <97ae44ee.0203011909.620b829b@posting.google.com> Peter Hansen wrote in message > > > Yikes! "Crash"? Do you really mean they crash the Python interpreter, > > > or do you mean they exit with an exception? > > > > Sorry, I guess I mean "exit with an exception" though to be honest, I > > still don't know because I haven't been able to run the programs > > interactively during a 'crash'. > > I'm not sure what the interactive thing would add, since the > interpreter will already print exception tracebacks to the console > whenever your program exits exceptionally. If you aren't seeing > a traceback, maybe you aren't really exiting with an exception. Sorry, I should have explained that the reason I don't see the output is that I run the programs in the background since I log into the servers from remote and don't want the programs exiting when I log out. > > > If the latter, just wrap the highest level code with a try/finally > > > or try/except and put code in to ensure the child processes are > > > properly terminated. Simple, clean, safe. > > > > Will do. I didn't want to put try/except/finally at the highest level > > of code yet since we're actually in Beta and I want to know when my > > server encounters a problem. > > No problem, just put a "raise" statement as the final statement in > the exception handling block (when using try/except only) and you'll > still propagate the exception up and right out of the interpreter > so it prints a traceback to the console. Good idea, this is something that I think I should employ for all code in future. When developing applications, I usually have exceptions raised at the lowest level of code (eg. the module/class level) but then as I start building the higher levels of code, the lower levels get lost ('swallowed') as opposed to propagated up. Damn, wish that had occured to me earlier. > In the try/finally case, > however, you'll still get the traceback if an exception *did* > occur, because the interception is only a temporary one. After the > finally code executes, exception processing continues on. > > I think you might focus on the lack of a traceback. You should > always see one if you aren't explicitly swallowing the exception. > (Note, a few standard modules such as the SocketServer and such > will internally swallow exceptions in the server threads by default.) I've been logged in and watching the console for several hours and I am getting a traceback when errors occur ~ the difficulty I had before was imposed by running to the background, which I've just seen in the link below (http://cr.yp.to/daemontools/faq/create.html#why) is apparently not good software design. ................................. > From: Greg Green (gregory.p.green at boeing.com) > Subject: Re: Want to monitor process.. > Newsgroups: comp.lang.python > View this article only > Date: 2002-03-01 12:35:56 PST > > > If you are using a unix OS, I would suggest using daemontools > from Bernstein. It has a set of tools for supervising a process. > I use it all of the time for these sorts of problems. Excellent! This looks like just the ticket. I've actually employed it in the past with Bernstein's Qmail but never truly understood the importance of it. Now that I've read the minimalist documentation, I think this is going to become an important addition to my toolbox. Thank you, gentlemen, thank you. Stephen. From jason at jorendorff.com Sat Mar 2 04:18:27 2002 From: jason at jorendorff.com (Jason Orendorff) Date: Fri, 1 Mar 2002 21:18:27 -0600 Subject: PEP 263 comments In-Reply-To: Message-ID: I've been following this rather closely and thinking a lot about it, and concluded that this is too big a headache to be believed. Ideally, from the programmer's perspective: * All my existing Python code should continue to run. * I shouldn't have to understand what Unicode is, if all I want is to bang out a quick script to say "hello world" in my native language. * I should be able to send Python files to other people in other countries, and they should run fine there too. * I should be able to use 'print' on strings and unicode strings and get sensible output (I'll know it when I see it ). * Comments shouldn't affect the meaning of code. * Random binary garbage in comments should be ignored, just like it is today. Unfortunately it's all impossible. I think MvL's proposal comes about as close as anyone can today, but it's still yucky, and it's *definitely* an abuse of Emacs's "-*- coding: -*-" magic (my main objection). I'm still holding out for an impossible ideal (or at least *clean*) solution. But of course it's not my opinion that matters ... ## Jason Orendorff http://www.jorendorff.com/ From quinn at regurgitate.ugcs.caltech.edu Sat Mar 2 04:26:13 2002 From: quinn at regurgitate.ugcs.caltech.edu (Quinn Dunkan) Date: 2 Mar 2002 03:26:13 GMT Subject: Useful, robust shell utilities References: Message-ID: On Fri, 01 Mar 2002 21:13:15 +0900, Jonathan Gardner wrote: >I tried to use the shutil module... and to tell you the truth, it stinks. >Is there an effort to make a robust, useful shutil module that has the >equivalent of the unix shell utilities? > >I think it would be nice to make things like 'grep' even... > >Here is my wish list. Each of these should implement a significant portion >of what the GNU utils do. They should be robust, and give reasonable >results, and reasonable exceptions. > >touch, chmod, chown, chgrp, touch >df, du >cp, dd, install, mv, rm, shred I have a single function that implements more than a sigificant portion: os.system() Seriously, why reinvent all those wheels? If you're looking for portability to systems without them, I'm sure you can find implementations. Maybe not on the Mac though--I don't know how shellish stuff works there. If the answer is "it doesn't" then maybe a python solution is necessary. But all most of the chgrp etc. stuff isn't going to work there anyway. >If there isn't an effort to make this, or if no one has done anything like >this yet, I am willing to volunteer some time to do it. It would be really >nice if they ended up being compatible with Windows and Macintosh - give >them some powerful tools they didn't even know existed! The cygwin people already did this. If you want to do some hacking that's great, but your time may be better spent elsewhere :) From aahz at panix.com Sat Mar 2 05:02:31 2002 From: aahz at panix.com (Aahz Maruch) Date: 1 Mar 2002 20:02:31 -0800 Subject: PEP 282: A Logging System -- comments please References: Message-ID: [posted & e-mailed] In article , Trent Mick wrote: > >Simple Example > > This shows a very simple example of how the logging package can be > used to generate simple logging output on stdout. Tim will whine about Win9x, but I suggest that stderr be the default. -- --- Aahz <*> (Copyright 2002 by aahz at pobox.com) Hugs and backrubs -- I break Rule 6 http://www.rahul.net/aahz/ Androgynous poly kinky vanilla queer het Pythonista "How come we choose from just two people for President but more than 50 for Miss America?" --AEN From test at biggulp.readfreenews.net Sat Mar 2 05:03:47 2002 From: test at biggulp.readfreenews.net (test) Date: Sat, 2 Mar 2002 14:03:47 +1000 Subject: (OT?) Web-based document review system? References: <3c801a5b.68374897@news.laplaza.org> Message-ID: <3c804f7b$0$4215$afc38c87@news.optusnet.com.au> Backtalk is another python-based framework. http://sourceforge.net/projects/backtalk/ From djc at object-craft.com.au Sat Mar 2 05:16:30 2002 From: djc at object-craft.com.au (Dave Cole) Date: 02 Mar 2002 15:16:30 +1100 Subject: ASV module, CVS modules References: <61ff32e3.0202281525.3e9bb102@posting.google.com> Message-ID: >>>>> "John" == John Machin writes: John> Wow. You have two problems. Bill Gates has one. And one of John> either you or Dave Cole will get busted real soon now if you John> keep smoking that stuff :-) I haven't smoked since I tried it as a young kid and threw up... John> You and/or Dave in peril of the law: Last time I saw Dave's John> module it didn't presume to read files at all, it expected you John> to read lines and pass them to it one at a time. So either Dave John> has had a very recent rush of blood or something worse to the John> head and released unbeknownst to me a file-handling version of John> his module, or you are gravely mistaken when you assert "I get a John> similar message from CSV module". No such luck on the rush of blood to the head thing. I think you were correct in your assessment of the problem. Bill and his stoopid backslashes are to blame. - Dave -- http://www.object-craft.com.au From cfelling at iae.nl Sat Mar 2 05:49:28 2002 From: cfelling at iae.nl (Carel Fellinger) Date: 2 Mar 2002 05:49:28 +0100 Subject: PEP 276 (was Re: Status of PEP's?) References: Message-ID: James_Althoff at i2.com wrote: Jim, I think I finally solved the riddle. From huaiyu_zhu at yahoo.com Sat Mar 2 05:51:26 2002 From: huaiyu_zhu at yahoo.com (Huaiyu Zhu) Date: Fri, 1 Mar 2002 20:51:26 -0800 (PST) Subject: Python 2.2 seriously crippled for numerical computation? Message-ID: There appears to be a serious bug in Python 2.2 that severely limits its usefulness for numerical computation: # Python 1.5.2 - 2.1 >>> 1e200**2 inf >>> 1e-200**2 0.0 # Python 2.2 >>> 1e-200**2 Traceback (most recent call last): File "", line 1, in ? OverflowError: (34, 'Numerical result out of range') >>> 1e200**2 Traceback (most recent call last): File "", line 1, in ? OverflowError: (34, 'Numerical result out of range') This produces the following serious effects: after hours of numerical computation, just as the error is converging to zero, the whole thing suddenly unravels. Note that try/except is completely useless for this purpose. I hope this is unintended behavior and that there is an easy fix. Have any of you experienced this? Huaiyu From peter at engcorp.com Sat Mar 2 06:29:38 2002 From: peter at engcorp.com (Peter Hansen) Date: Sat, 02 Mar 2002 00:29:38 -0500 Subject: Useful, robust shell utilities References: <%8Wf8.518$Az6.2357@news.hananet.net> Message-ID: <3C806342.E28D1ED0@engcorp.com> Jonathan Gardner wrote: > > There would be a big benefit to see something like: > > res = chmod("-c", "-R", "u=rwx,g=rx,o=", a_file, another_file, a_directory) Is that anything like os.system('chmod -c -R u=rwx,g=rx,o= %s %s %s' % (a_file, another_file, a_directory)) ?? If so, why are you trying to rebuild the unix shell within Python? (Or what am I missing?) -Peter From peter at engcorp.com Sat Mar 2 06:32:32 2002 From: peter at engcorp.com (Peter Hansen) Date: Sat, 02 Mar 2002 00:32:32 -0500 Subject: Want to monitor process.. References: <87550ef1.0202272315.15779bbd@posting.google.com> <97ae44ee.0202280901.3153bdfc@posting.google.com> <3C7EC9C6.D11FB17@engcorp.com> <97ae44ee.0203010102.14ebf2bb@posting.google.com> <3C7F66AB.D51BEA03@engcorp.com> <97ae44ee.0203011909.620b829b@posting.google.com> Message-ID: <3C8063F0.8BBD4A5C@engcorp.com> Stephen wrote: > > Peter Hansen wrote in message > > I'm not sure what the interactive thing would add, since the > > interpreter will already print exception tracebacks to the console > > whenever your program exits exceptionally. If you aren't seeing > > a traceback, maybe you aren't really exiting with an exception. > > Sorry, I should have explained that the reason I don't see the output > is that I run the programs in the background since I log into the > servers from remote and don't want the programs exiting when I log > out. Ah, I understand now. Could you just redirect stdout to a file for those? Then when they've crashed, you'll be able to pop in and check the log. -Peter From db3l at fitlinxx.com Sat Mar 2 06:33:20 2002 From: db3l at fitlinxx.com (David Bolen) Date: 02 Mar 2002 00:33:20 -0500 Subject: Older Python bug entries on SourceForge References: Message-ID: martin at v.loewis.de (Martin v. Loewis) writes: > So if you have a bug number below 300000, SF will have > renumbered the bug by now. They used to have a backwards-compatible > URL in place, redirecting to the new report, but they may have > disabled that by now. Is there any way to compute the new number based on the old (e.g., by adding some fixed constant or something)? -- -- David -- /-----------------------------------------------------------------------\ \ David Bolen \ E-mail: db3l at fitlinxx.com / | FitLinxx, Inc. \ Phone: (203) 708-5192 | / 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \ \-----------------------------------------------------------------------/ From tim.one at comcast.net Sat Mar 2 06:42:49 2002 From: tim.one at comcast.net (Tim Peters) Date: Sat, 02 Mar 2002 00:42:49 -0500 Subject: Python 2.2 seriously crippled for numerical computation? In-Reply-To: Message-ID: [Huaiyu Zhu] > There appears to be a serious bug in Python 2.2 that severely limits its > usefulness for numerical computation: > > # Python 1.5.2 - 2.1 > > >>> 1e200**2 > inf A platform-dependent accident, there. > >>> 1e-200**2 > 0.0 > > # Python 2.2 > > >>> 1e-200**2 > Traceback (most recent call last): > File "", line 1, in ? > OverflowError: (34, 'Numerical result out of range') That one is surprising and definitely not intended: it suggests your platform libm is setting errno to ERANGE for pow(1e-200, 2.0), or that your platform C headers define INFINITY but incorrectly, or that your platform C headers define HUGE_VAL but incorrectly, or that your platform C compiler generates bad code, or optimizes incorrectly, for negating and/or comparing against its definition of HUGE_VAL or INFINITY. Python intends silent underflow to 0 in this case, and I haven't heard of underflows raising OverflowError before. Please file a bug report with full details about which operating system, Python version, compiler and C libraries you're using (then it's going to take a wizard with access to all that stuff to trace into it and determine the true cause). > >>> 1e200**2 > Traceback (most recent call last): > File "", line 1, in ? > OverflowError: (34, 'Numerical result out of range') That one is intended; see http://sf.net/tracker/?group_id=5470&atid=105470&func=detail&aid=496104 for discussion. > This produces the following serious effects: after hours of numerical > computation, just as the error is converging to zero, the whole thing > suddenly unravels. It depends on how you write your code, of course. > Note that try/except is completely useless for this purpose. Ditto. If your platform C lets you get away with it, you may still be able to get an infinity out of 1e200 * 1e200. > I hope this is unintended behavior Half intended, half both unintended and never before reported. > and that there is an easy fix. Sorry, "no" to either. From tim.one at comcast.net Sat Mar 2 06:58:18 2002 From: tim.one at comcast.net (Tim Peters) Date: Sat, 02 Mar 2002 00:58:18 -0500 Subject: Use of select.select In-Reply-To: <98a8b53e.0203011656.7aaad470@posting.google.com> Message-ID: [MShyam] > Our product embeds python in C++ and in our > py methods, we use select.select in several > places. When purifying the executable, we > find that when select.select(...) is executed, > we find several BSWs, BSRs, IPWs and IPRs > (beyond stack writes/reads, invalid pointer > writes/reads). Has such a problem been reported? > What's the fix? We're using python 1.5.2. I strongly advise you try a more recent release (like 2.1.2). 1.5.2 is nearly 3 years old, never had a bugfix release, and nobody is likely to remember 1.5.2 details accurately anymore. More recent versions have also been run under Insure by other people. Short of that, I expect you won't get much help. You can view the CVS history of selectmodule.c online at then navigate to Modules and then to selectmodule.c. Revision 2.28 was released in 1.5.2; it's currently at revision 2.60. From tim.one at comcast.net Sat Mar 2 07:14:09 2002 From: tim.one at comcast.net (Tim Peters) Date: Sat, 02 Mar 2002 01:14:09 -0500 Subject: pickle, cPickle, zlib, and the future In-Reply-To: <79b2b0bb.0203011329.79469c5b@posting.google.com> Message-ID: [Scott Gilbert] > ... > So can I rely on the first character 'x' being reserved for zlib, and > cPickle/pickle strings never starting with 'x'? I sure wouldn't. > ... > (BTW: In cases somebody asks why I don't just prefix my dump strings > saying where they came from: The dumps can be rather large (maybe 10's > of megabytes), and I really don't want to have to create a multiple > megabyte substring from the original.) This part I didn't follow. Surely you're writing your dumps to a file? f.write('pick') - or - f.write('zlib') f.write(the_dump_string) when writing then dumpkind = f.read(4) if dumpkind == 'pick': # read next pickle from f elif dumpkind == 'zlib': # let zlib chew on the next part else: # etc when reading. A parallel file of kind-codes also comes to mind. Etc. From usenet at thinkspot.net Sat Mar 2 07:04:23 2002 From: usenet at thinkspot.net (Sheila King) Date: Fri, 01 Mar 2002 22:04:23 -0800 Subject: newbie password question References: <20020302003514.13693.00001116@mb-fw.aol.com> Message-ID: On 02 Mar 2002 05:35:14 GMT, etrofsouls at aol.com (EtrOFsouls) wrote in comp.lang.python in article <20020302003514.13693.00001116 at mb-fw.aol.com>: > password = "foobar" > > while password != "unicorn": > password = raw_input ("Password:") > print "Welcome In" > > I understand all this (thank god), but I'm having trouble figuring out how to > get it to keep track of the number of guesses and then print a message such as > "Halt, you do not have access!" if the number of guesses exceeds the limit. I'm > learning this thru on-line tutorials and this was given as an excersise. All I > have to work with is variables and statements such as...while, if, elif and > else. How about something like this? password = "foobar" validated = 0 for attempt in range(1, 6): password = raw_input ("Password:") if password == "foobar": validated = 1 print "Welcome In" break if not validated: print "Sorry, Charlie!" The variable validated keeps track of whether the person has yet managed to successfully give the correct password. (In this example, the correct password is "foobar".) The for loop lets the user try five times (try this at an interactive prompt: print range(1,6) It will return a list of the integers [1, 2, 3, 4, 5]. So basically, this loop will try for times 1, 2, 3, 4 and 5. The user gets five chances to get the correct password.. If they manage to get the correct password, the validated flag is set to "true" (i.e. the number 1), they are greeted with a "welcome", and the loop breaks. If the loop runs all five times, and after that the validated flag is still false, "Sorry, Charlie!". Hope this helps, -- Sheila King http://www.thinkspot.net/sheila/ "When introducing your puppy to an adult cat, restrain the puppy, not the cat." -- Gwen Bailey, _The Perfect Puppy: How to Raise a Well-behaved Dog_ From python at rcn.com Sat Mar 2 07:46:49 2002 From: python at rcn.com (Raymond Hettinger) Date: Sat, 2 Mar 2002 01:46:49 -0500 Subject: PEP 276 (was Re: Status of PEP's?) References: Message-ID: "Carel Fellinger" wrote in message news:a5orjv$7j0$1 at animus.fel.iae.nl... > Seriously I would like you to add something in your PEP that addresses > this simple alternative and explain why you favour yours. True, > `i in range(len(sequence))' doesn't look very pleasing, but > `i in indici(sequence)' does. And as an added bonus it's > very similar to `(i, item) in indexed(sequence)'. > > > > [Carel Fellinger] Yes! There is a pair of ideas that are intuitive, clean, and routinely useful: for i in indici(seqn) for i, item in indexed(seqn) Both ideas could be implemented as generators and work sequencially off the iter() of the sequence. This will accommodate lazy evaluation, low memory use, objects without a __len__ property, xrange objects, file objects, and objects with sequencial access defined by __getitem__ -- basically anything that could be used by a 'for item in sequence'. It may be that 'sequence' isn't the best choice of words. Iter() takes a 'collection' and 'for' takes an iterable. No matter what you call it, the pair of ideas looks like a great general purpose solution. I would add one little wrinkle. Define the functions to have an optional starting point. def indici(seqn, start=0). This will accommodate the common case of using natural numbers (starting from 1) or less common cases for those who start their check numbers at 1001. Let's implement those two ideas, cross-off the todo list (loop counter iteration proposals), then declare victory and get on with life. Raymond Hettinger "In theory, there is no difference between theory and practice. In practice, there is." From eppstein at ics.uci.edu Sat Mar 2 07:52:20 2002 From: eppstein at ics.uci.edu (David Eppstein) Date: Fri, 01 Mar 2002 22:52:20 -0800 Subject: PEP 276 (was Re: Status of PEP's?) References: Message-ID: In article , "Raymond Hettinger" wrote: > There is a pair of ideas that are intuitive, clean, and routinely useful: > for i in indici(seqn) > for i, item in indexed(seqn) Isn't this in PEP 212? Maybe it should be undeferred? -- David Eppstein UC Irvine Dept. of Information & Computer Science eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/ From emile at fenx.com Sat Mar 2 08:04:31 2002 From: emile at fenx.com (Emile van Sebille) Date: Fri, 1 Mar 2002 23:04:31 -0800 Subject: PEP 276 (was Re: Status of PEP's?) References: Message-ID: "Carel Fellinger" > You specify that the > integer to iterate over should be possitive, why not allow for > negative values and do the sensible thing, like: > > >>> [i for i in -3] > [-1, -2, -3] If you change the sensible thing to mean: [-3, -2, -1] I'd like it better. ;-) Emile van Sebille emile at fenx.com From jason at jorendorff.com Sat Mar 2 08:11:50 2002 From: jason at jorendorff.com (Jason Orendorff) Date: Sat, 2 Mar 2002 01:11:50 -0600 Subject: SAX-Parser entity In-Reply-To: Message-ID: fabi kreutz wrote: > where Character 19 in Row 29 is the occurence of an ?. Yep, if you are going to use non-ascii characters you have to specify the encoding in the XML document itself, so the XML parser knows what's going on. > After browsing the FAQs I changed the default encoding in site.py to > iso-8859-1, which had some nice effect, but not on minidom. What you need is: It must be the very first thing in the XML document; i.e. the two characters ") ## Jason Orendorff http://www.jorendorff.com/ From tanzer at swing.co.at Sat Mar 2 08:34:47 2002 From: tanzer at swing.co.at (Christian Tanzer) Date: Sat, 02 Mar 2002 08:34:47 +0100 Subject: Minor, minor style question In-Reply-To: Your message of "01 Mar 2002 10:39:42 CST." <5F9A347EAC81A19E.F4E6D6813EA4DC98.17114695240B3A22@lp.airnews.net> Message-ID: claird at starbase.neosoft.com (Cameron Laird) wrote: > Why would I prefer > string = "" > string = string + "abc " > string = string + "def " > string = string + "xyz" > over > string = "abc " + \ > "def " + \ > "xyz" > ? Why not use: string = ("abc" "def" "xyz" ) for constant strings, and string = "".join((abc, def, xyz)) for variable strings? Both are more robust, way more efficient, and (to me, at least) easier to read. BTW, beware of: result = "" for s in ... : result = result + mumble(s) For many elements, this gets really slow. Appending to a list and joining at the end is much faster. -- Christian Tanzer tanzer at swing.co.at Glasauergasse 32 Tel: +43 1 876 62 36 A-1130 Vienna, Austria Fax: +43 1 877 66 92 From python at rcn.com Sat Mar 2 08:45:21 2002 From: python at rcn.com (Raymond Hettinger) Date: Sat, 2 Mar 2002 02:45:21 -0500 Subject: string to dictionary References: Message-ID: "les ander" wrote in message news:a2972632.0203011522.16f1b8e0 at posting.google.com... > Hi, > i have a list of strings like this: > > aList=[ 'a_1 b_1', 'a_2 b_2', 'a_3 b_3',...] > > i want to convert this to a dictionary with a_i -> b_i without > using loops (it is trivial to do it with loops) This ought to do it: >>> aList=[ 'a_1 b_1', 'a_2 b_2', 'a_3 b_3'] >>> dict(map(lambda g: g.split() ,aList)) {'a_3': 'b_3', 'a_2': 'b_2', 'a_1': 'b_1'} If you don't have Python 2.2, then build the dictionary directly: >>> d = {} >>> map( lambda (k,v): d.__setitem__(k,v), map(string.split, aList) ) [None, None, None] >>> d {'a_3': 'b_3', 'a_2': 'b_2', 'a_1': 'b_1'} Note, the use of __setitem__ to avoid '='. Still, it's better to get Python 2.2 and avoid the second method. Good functional style stays away from lambdas with side-effects (setting the dictionary). > i tried this > > dict={} > map(lambda x,d=dict: c=string.split(x), d[c[0]]=c[1], aList) > I recommend: 1. Never use an assignment inside a lambda expression 2. Never name a dictionary 'dict' which overrides the constructor 3. If lambdas get confusing, write a simple, working 'def' first and use that in the map. > but it complains that "keyword can't be an expression" > can someone please help me get this right? > thanks > les Good luck, Raymond Hettinger From boudewijn at tryllian.com Sat Mar 2 10:57:15 2002 From: boudewijn at tryllian.com (Boudewijn Rempt) Date: Sat, 02 Mar 2002 08:57:15 -0100 Subject: Black Adder and PyQt References: Message-ID: <3c8087eb$0$18514$e4fe514c@dreader4.news.xs4all.nl> Ron Stephens wrote: > I am thinking of buying a "home" license of Black Adder, to use for > making GUI's for Python programs to be used on Linux+KDE and also > perhaps for the new Sharp Zaurus. Does anyone have any experience with > Black Adder that they can share? One of my main reasons for wanting > Black Adder is to use the GUI builder, so I am particualrly interested > in opinions about that aspect of Black Adder, but I am also interested > in other aspects as well. > > One question I have concerns licensing. If I buy the "home" version, > could I still share my programs as GPL'ed open source, or would that > require me to buy the "professional" license, which is much more > expensive? In other words, my programs would never be used in any > commercial way but I might want to post them as open source, free > software. > > I know Black Adder is still in beta, but is it stable enoough to use > already? I suppose I should ask how it compares to PythonWare amd > WingIDE, but I kind of favor the PyQt toolkit becuase it will > hopefully work well on the Sharp Zaurus as well as the KDE desktop. I think WingIDE is a better IDE -- but it doesn't include the GUI designer. The gui designer is, in fact, just the Qt Designer as included with Qt, so you could you use that, but you'd lose all the nice integration. With the latest version of PyQt, you can compile Qt 3 .ui files to Python, too, but that's not part of BlackAdder yet. Have you seen that my book on PyQt and BlackAdder is out? You can order it at opendocs.org (never mind that the website still says it's in final copy-edit -- copies are shipping now, only Joshua is a bit slow updating), or read it online. But the paper copy is very pleasant possession :-). -- Boudewijn | http://www.valdyas.org From webmaster at label.co.kr Sat Mar 2 09:19:46 2002 From: webmaster at label.co.kr (=?ks_c_5601-1987?B?v8DHx726x8G288Da?=) Date: Sat, 02 Mar 2002 17:19:46 +0900 Subject: =?ks_c_5601-1987?B?tvO6p1MvVyC5q7fhKLv1v+zG7bn4yKMgwNq1v8DUt8IpW8irurhd?= Message-ID: <3c808b0a3c8c65ba@relay3.kornet.net> (added by relay3.kornet.net) ?????? ??(????? ????) - ??? ???? DM ???? - ??? ???? Telemarketing - ??? ?? ?? S/W ?? - ??? ??? ???? ??, ?? ? [??/???] : ?? 400? ??/?? ??? ?? ? [???] : ?? 1,200? ?? ??? ?? ?? ????? ???? 1?(50?/A4)? ????? ????. ??? ???? ??, ?? ????? ???? ??? ???. ??? ?? ??? ?? ?? ??? ??? ??? ??? ? ? ?? ?? ?? ???? ????? DM??? ???? ?????. ???? ???? ?????? ??? ??? ??? ??? ??? ????. ?????(DM)? ?? ?? ??? ??? ??? ??, ???? ?? ?? ??? ?? ??, ?? ??? ???? ????? ?? ???? ?? ??? ??? ?????? ???? ???? ????. ? Web-to-DB : ?? ??? ?? ?? ?? ? ????. ??? ??? ?????? ????? ??? ????. (? : http://tel.hanmir.com (??? ???? ??)) ? ??? ?? ? ?? ?? ?? ? ????? ?? ??? ??? ??? ??? ?? ??????, ??? ?? ??? ??? ??? ??? ?? ????. ??? ??? ?? ???? ????? ?? ????. ?? ?? ????. [????] -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-list/attachments/20020302/d59438f6/attachment.html From python at rcn.com Sat Mar 2 09:06:06 2002 From: python at rcn.com (Raymond Hettinger) Date: Sat, 2 Mar 2002 03:06:06 -0500 Subject: PEP 276 (was Re: Status of PEP's?) References: Message-ID: "David Eppstein" wrote in message news:eppstein-EBDEA3.22522001032002 at news.service.uci.edu... > In article , > "Raymond Hettinger" wrote: > > > There is a pair of ideas that are intuitive, clean, and routinely useful: > > for i in indici(seqn) > > for i, item in indexed(seqn) > > Isn't this in PEP 212? > Maybe it should be undeferred? > -- > David Eppstein UC Irvine Dept. of Information & Computer Science > eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/ PEP 212 pre-dates generators and iterators. Back then, a list method seemed more attractive because there weren't that many things that could be iterated over. Hence, the argument for a built-in function was weaker. Since there were no generators, the idea of a lazily produced sequence wasn't in mind. Hence, the memory and time cost of building a separate items type list made the whole idea seem less attractive. Further, generatorless version of the idea was weak because its equivalent could be directly and simply coded: for i, item in zip(xrange(sys.maxint),seqn). So maybe this is PEP 212 re-incarnated in generator form and perhaps now the arguments for are much more compelling and the arguments against no longer matter. It doesn't matter to me whether we call it PEP 212, PEP 276, or PEP 279. Let's all just vote +1 and beg Guido to put it in ver 2.3. Raymond Hettinger P.S. If 212 can get revised in generator form, then YES, let's undefer it. From martin at v.loewis.de Sat Mar 2 09:25:38 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 02 Mar 2002 09:25:38 +0100 Subject: PEP 263 comments References: <87g03lhm3p.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: bokr at oz.net (Bengt Richter) writes: > Will the following work? > > >>> print u'\u0041' > A > >>> print u'\u221e' > > Traceback (most recent call last): > File "", line 1, in ? > UnicodeError: ASCII encoding error: ordinal not in range(128) > >>> With the patch to print Unicode to the Windows console, the UnicodeError will be gone. Whether or not Lucida Unicode supports that character, I cannot say. > And if I redirect the output to a file, what will be in the file? Since the isatty test fails, the system default encoding will be used. Unless you've changed that, you'll get a UnicodeError again. Regards, Martin From martin at v.loewis.de Sat Mar 2 09:36:04 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 02 Mar 2002 09:36:04 +0100 Subject: PEP 263 comments References: Message-ID: "Jason Orendorff" writes: > Unfortunately it's all impossible. Unfortunately, yes. Let me explain how this will work under PEP 263. > * All my existing Python code should continue to run. They will, but you will might get a DeprecationWarning; eventually, your code might stop being accepted. > * I shouldn't have to understand what Unicode is, if all I want > is to bang out a quick script to say "hello world" in my native > language. You won't need to understand what Unicode is. You will need to understand what encodings are, though, i.e. you should know that "Gr?? Gott" requires Latin-1. With that knowledge, you can either change the system default encoding, or put an encoding declaration in your file. > * I should be able to send Python files to other people in > other countries, and they should run fine there too. That will work for the encoding declaration case (either with the Unicode marker, or the UTF-8 signature). If people have changed the system default encoding, this property may not hold. > * I should be able to use 'print' on strings and unicode strings > and get sensible output (I'll know it when I see it ). That will work depending on the terminal. In IDLE, it does currently work. For plain strings, it will also normally work, unless the file's encoding differs from the system encoding (or, rather, the user's terminal encoding). For Unicode strings, I'll write a PEP describing the use of Unicode at system interfaces, which targets this issue. > * Comments shouldn't affect the meaning of code. They won't in phase 1 of the PEP (although you will get a warning if you haven't declared an encoding, and left the system encoding at ASCII). In phase 2, you'll get a warning if the comment is not well-formed under the encoding. > * Random binary garbage in comments should be ignored, just like > it is today. That property may go away in phase 2. E.g. in a UTF-8 encoded file, Python will eventually verify that the comments actually are UTF-8. Some people consider this a good thing, as editors can't really round-trip files with different encodings at different offsets. Regards, Martin From dugar at binet.lv Sun Mar 3 15:23:18 2002 From: dugar at binet.lv (dugar at binet.lv) Date: Sun, 03 Mar 2002 11:23:18 -0300 Subject: Help Yourself Live Longer. 4959oFcD9-612XwZq0l17 Message-ID: <028c77e30e6d$3457d8d8$3dd12db8@yoxnik> An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-list/attachments/20020303/19ac8e60/attachment.htm From martin at v.loewis.de Sat Mar 2 09:44:56 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 02 Mar 2002 09:44:56 +0100 Subject: Older Python bug entries on SourceForge References: Message-ID: David Bolen writes: > > So if you have a bug number below 300000, SF will have > > renumbered the bug by now. They used to have a backwards-compatible > > URL in place, redirecting to the new report, but they may have > > disabled that by now. > > Is there any way to compute the new number based on the old (e.g., by > adding some fixed constant or something)? I believe the following happened: Bugs, with bug-ids 1xxxxx, and URLs of the form http://sourceforge.net/bugs/?func=detailbug&bug_id=115845&group_id=5470 have been renumbered to 2xxxxx, with URLs of the form http://sourceforge.net/tracker/?group_id=5470&atid=105470&aid=215845&func=detail Just try it in this specific case; the redirection is still active. Patches in the 1xxxxx range have been renumbered to 3xxxxx. HTH, Martin From python at rcn.com Sat Mar 2 09:46:52 2002 From: python at rcn.com (Raymond Hettinger) Date: Sat, 2 Mar 2002 03:46:52 -0500 Subject: map-like function on dict values? References: Message-ID: "Skip Montanaro" wrote in message news:mailman.1014929989.16553.python-list at python.org... > > def mapvalue(f, d): > keys = d.keys() > map(operator.setitem, [d]*len(keys), keys, map(f, d.values())) > The mapvalue test needs a tune-up. Skipping the operator module and calling setitem directly speeds things up a bit: def tunedmap(f, d): return map( d.__setitem__, d.keys(), map(f, d.values()) ) I re-timed the result and it was close to the same as achieved for iteriteritems. Raymond Hettinger From jgardn at alumni.washington.edu Sat Mar 2 10:11:09 2002 From: jgardn at alumni.washington.edu (Jonathan Gardner) Date: Sat, 02 Mar 2002 18:11:09 +0900 Subject: Useful, robust shell utilities References: <%8Wf8.518$Az6.2357@news.hananet.net> <3C806342.E28D1ED0@engcorp.com> Message-ID: Peter Hansen scribbled with his keyboard: > Jonathan Gardner wrote: >> >> There would be a big benefit to see something like: >> >> res = chmod("-c", "-R", "u=rwx,g=rx,o=", a_file, another_file, >> a_directory) > > Is that anything like > > os.system('chmod -c -R u=rwx,g=rx,o= %s %s %s' % (a_file, another_file, > a_directory)) > Gotta love being on a Unix system. That's EXACTLY what it would do. For those of you who aren't intimately familiar with 'chmod', let me tell you what this command does. It recurses to all the subdirectories (but not the ones that start with '.') and changes the mode of the files to be inaccessible to the world, only readable and executable to the people in the file's group, and readable, writable, and executable by the owner. If it actually made a change, it would print out the name of the file it changed. > > If so, why are you trying to rebuild the unix shell within Python? > (Or what am I missing?) > The limitation of the above os.system call and my future, unimplemented chmod call would be that my function would return a list of names of the files it changed (provided the -c option is present, or something like that). It would also allow interactivity between the Python script and chmod, so you can have a function that will determine whether or not to change one particular file. So, while 'chmod' the program in the Unix toolbos is implemented for shells, 'chmod' the function in Python will be useful for Python. Also because Python ports to Windows, and Windows ain't Unix. It would be nice to have those tools with you no matter where your program goes, rather than having to do: if os.name != "posix": raise OSError, ("You're not using a real OS. " "You know that real OSes are free nowadays, don't you?.") I wanted to write an installation script for my program. No, it's not a standard module - it's a game, and you certainly don't want your games to get mixed in with your real modules. If all my users were on Unix systems, then I would have done it with a shell script. But they aren't. So I had to figure out how to get the job done on Windows. It looks like python was my closest bet. I ended up writing some simple tools for the job that could have been done with 'sed', 'rm', and 'install' in Unix. Perhaps someone else would like to have these tools available to them wherever they use Python. Jonathan From flognat at flognat.myip.org Sat Mar 2 09:59:50 2002 From: flognat at flognat.myip.org (Andrew Markebo) Date: Sat, 02 Mar 2002 08:59:50 GMT Subject: What have I missed with the lists?? Flattening two trees.. References: Message-ID: ahh if i do alist=[] blist=[] print a.flatten(alist) print b.flatten(blist) instead, it works as it shouldhmm what have I missed? is the default list to the dig function initialized at first parse, and not runtime as I thought? /Andy | | print a.flatten() | print b.flatten() | | -- | The eye of the beholder rests on the beauty! -- The eye of the beholder rests on the beauty! From hinsen at cnrs-orleans.fr Sat Mar 2 10:30:47 2002 From: hinsen at cnrs-orleans.fr (Konrad Hinsen) Date: 02 Mar 2002 10:30:47 +0100 Subject: [Numpy-discussion] RE: Python 2.2 seriously crippled for numerical computation? In-Reply-To: References: Message-ID: Tim Peters writes: > > # Python 2.2 > > > > >>> 1e-200**2 > > Traceback (most recent call last): > > File "", line 1, in ? > > OverflowError: (34, 'Numerical result out of range') > > That one is surprising and definitely not intended: it suggests your > platform libm is setting errno to ERANGE for pow(1e-200, 2.0), or that your > platform C headers define INFINITY but incorrectly, or that your platform C > headers define HUGE_VAL but incorrectly, or that your platform C compiler > generates bad code, or optimizes incorrectly, for negating and/or comparing I just tested and found the same behaviour, on RedHat Linux 7.1 running on a Pentium machine. Python 2.1, compiled and running on the same machine, returns 0. So does the Python 1.5.2 that comes with the RedHat installation. Although there might certainly be something wrong with the C compiler and/or header files, something has likely changed in Python as well in going to 2.2, the only other explanation I see would be a compiler optimization bug that didn't have an effect with earlier Python releases. > OverflowError before. Please file a bug report with full details about > which operating system, Python version, compiler and C libraries you're > using (then it's going to take a wizard with access to all that stuff to > trace into it and determine the true cause). I am willing to look into this if no one else does. But it won't be immediately. Konrad. -- ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hinsen at cnrs-orleans.fr Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-2.38.25.56.24 Rue Charles Sadron | Fax: +33-2.38.63.15.17 45071 Orleans Cedex 2 | Deutsch/Esperanto/English/ France | Nederlands/Francais ------------------------------------------------------------------------------- From joonas at olen.to Sat Mar 2 11:25:41 2002 From: joonas at olen.to (Joonas Paalasmaa) Date: 2 Mar 2002 02:25:41 -0800 Subject: (Hopefully) simple IDLE question References: Message-ID: <11aed8f9.0203020225.4d8b7922@posting.google.com> "Seth Jones" wrote in message news:... > Hi all, > > Is there any way to set the current working directory for a file being used > in IDLE? I simply want to open a file that is in the same directory as my > script, which I've opened into the > idle window, and I don't want to hard-code the full path of the file. > Failing that, is there any alternative in Windows 95 to the normal command > line? I ask, since the reason I'm using IDLE in the first place is to avoid > calling my script from the horribly unsatisfying DOS prompt. Failing even > that, is there a better way to get error output from a .pyw file than to > catch all exceptions and write them to a file? > > A google search did lead me to an old mailing-list post about adding the > option for setting > current directories in IDLE, but apparently that hasn't been done yet. > > > I hope someone can convey some wisdom to this poor soul who's still stuck on > win95. > Thanks in advance for any advice. IDLEfork should handle the working directory correctly. See http://idlefork.sourceforge.net/ From pachy at 012.net.il Sat Mar 2 11:44:10 2002 From: pachy at 012.net.il (Tal Linzen) Date: Sat, 2 Mar 2002 12:44:10 +0200 Subject: Fw: smtplib: including a subject Message-ID: <002901c1c1d7$306af590$e00dc7d4@ussr6gwe8yu2pu> Hi. I couldn't figure out how to send a mail with a subject. Help? (By the way, I think the docs on this module could use some rewriting -- it appears to be directed to those familiar with the c library it wraps, rather than to the common Python user). Thanks, Tal From phil at river-bank.demon.co.uk Sat Mar 2 12:05:07 2002 From: phil at river-bank.demon.co.uk (Phil Thompson) Date: Sat, 02 Mar 2002 11:05:07 +0000 Subject: Black Adder and PyQt References: Message-ID: <3C80B1E3.575761B7@river-bank.demon.co.uk> Ron Stephens wrote: > > I am thinking of buying a "home" license of Black Adder, to use for > making GUI's for Python programs to be used on Linux+KDE and also > perhaps for the new Sharp Zaurus. Does anyone have any experience with > Black Adder that they can share? One of my main reasons for wanting > Black Adder is to use the GUI builder, so I am particualrly interested > in opinions about that aspect of Black Adder, but I am also interested > in other aspects as well. > > One question I have concerns licensing. If I buy the "home" version, > could I still share my programs as GPL'ed open source, or would that > require me to buy the "professional" license, which is much more > expensive? In other words, my programs would never be used in any > commercial way but I might want to post them as open source, free > software. The main difference in the licence between the "home" and "professional" version relate to the re-distribution rights of Qt. The "professional" version allows you to re-distribute the copy of the Qt supplied with BlackAdder with your application (but under no other circumstances), so you can ship a complete binary package to your customers for both Linux and Windows without incurring any further licensing fees from Trolltech. If you are only developing GPL'ed applications, and you are expecting users to already have Qt installed, then the "home" version is fine. Phil From gerhard at bigfoot.de Sat Mar 2 12:33:56 2002 From: gerhard at bigfoot.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: 2 Mar 2002 11:33:56 GMT Subject: Fw: smtplib: including a subject References: Message-ID: Tal Linzen wrote in comp.lang.python: > Hi. > > I couldn't figure out how to send a mail with a subject. Help? You're not the first one to have this problem *hint, hint*: See http://groups.google.com/groups?q=python+smtplib+subject for previous discussions of this question. > (By the way, I think the docs on this module could use some > rewriting -- it appears to be directed to those familiar with the c > library it wraps, rather than to the common Python user). You'll need to file a bug report at the Sourceforge bug tracker if you want to bring this to the attention of the Python committers. Be sure to set the Category to "Documentation". Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0 public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From h.jehadalwan at student.kun.nl Sat Mar 2 12:46:52 2002 From: h.jehadalwan at student.kun.nl (husam) Date: Sat, 02 Mar 2002 12:46:52 +0100 Subject: a simple 'else' decrease speed by 1000 times. Message-ID: <3C80BBAC.2060600@student.kun.nl> Short intro: One else statement decrease speed by 1000 times. Why is that? Long intro: The only thing that this function does is the following: It takes two dictionaries. The first is a dictionary with 10000 keys. The value of each key is a list containing one integer item. The keys of the second dictionary have values that correspond to file names. These files must be opened one by one and scaned for the presence of two integers, lets call them 'new' and 'previous'. The link between the files is that the 'new' integer in file number one represents the 'previous' integer found in file number two, and so on. If the code finds that a 'prv' integer equal to the last item of the list of any dict_1[key], that 'prv' ingeger must be appended to the same key.The files differ in length. The first one contains 11000 lines, but the others has arbitrary length, but they are shorter than the first one in general. The problem is the following: a represantative line from the output of this code is like this: key nr. key value ------- --- ----- 3400 12.345 [45, 90000, 4003, 1203] the item '1203' is the 'new' ID of '4003', and this is the new ID of '90000' and so on. Each of these items are added in one round as a result of scanning one file. From the position of the items in the list I can tell from which file they were derived. As you see, the value of a key grows according to the number of files processed. But, since the files differ in length, not all the keys will grow. The symptom is that when a key value is not modified in the third round, simply because there was no match, the new item in the fourth round will be added, and therefor the length of the list will be 3 and hence I can not tell wether the last item is derived from the fourth file or from the third one. For this reason I thought let's add a zero to the list when there is no match by using a simple 'else' statement. This statement makes the code 1000 times slower. Why is that? def NewToOld(n,o): # n = a dictionary with 10000 keys, o = is a dictionary with 3 keys each represents a file name. count=1 files_keys=o.keys() files_keys.sort() print files_keys for key in files_keys: print 'Scanning ',o[key],' file....' SaveNew = open('rmsd_ranks.pickle','w') openfile=open(o[key]) lines=openfile.readlines() openfile.close() for i in n.keys(): for line in lines: words = string.split(line) if len(words) > 2: if words[0]=='G_DATA': prv=int(words[2]) new=int(words[1]) if prv == n[i][-1]: n[i].append(new) print count, '\t', i , '\t',n[i] count = count +1 break else: n[i].append(0) savednew = cPickle.dump(n, SaveNew) SaveNew.close() return n From nhodgson at bigpond.net.au Sat Mar 2 13:30:26 2002 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Sat, 02 Mar 2002 12:30:26 GMT Subject: PEP 263 comments References: <87g03lhm3p.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: Martin v. Loewis: > bokr at oz.net (Bengt Richter) writes: > > > Will the following work? > > > > >>> print u'\u0041' > > A > > >>> print u'\u221e' > > > > Traceback (most recent call last): > > File "", line 1, in ? > > UnicodeError: ASCII encoding error: ordinal not in range(128) > > >>> > > With the patch to print Unicode to the Windows console, the > UnicodeError will be gone. Whether or not Lucida Unicode supports that > character, I cannot say. It does, it is an infinity symbol and is available in most Windows fonts - Verdana, Times New Roman, ... > > And if I redirect the output to a file, what will be in the file? > > Since the isatty test fails, the system default encoding will be used. > Unless you've changed that, you'll get a UnicodeError again. How do you tell Python to treat stdout as a tty even though it is actually a pipe? I'd like to run Unicode printing programs from within SciTE with I/O redirected to SciTE's output pane. There is also an issue with stdin where I'd like to tell Python to treat redirected input, fed through a pipe, as a tty. Neil From gmcm at hypernet.com Sat Mar 2 13:30:42 2002 From: gmcm at hypernet.com (Gordon McMillan) Date: 02 Mar 2002 12:30:42 GMT Subject: ANN: experimental patch to allow importing from file-like objects References: <3c7fcbe6.7419921@news.t-online.de> Message-ID: Gerson Kurz wrote: > Motivation: Write a customized import that reads data from encrypted > files. Both execfile() and exec() are limited, if only that that they > don't mimic the import syntax. > > Problem: imp.load_module does expect a file object, but you can only > pass "real" files, not file-like objects. The internal C-code expects > native FILE* stuff. > > Solution: An experimental patch to the python22.dll that makes this > possible. Using file-like objects for import opens up a whole new set > of possibilities, for example you could fetch the code at runtime from > a database or a socket. Most people doing something like this don't use imp.load_module. First you need a code object for the module. If it's source: co = compile(open(srcfile, 'r').read()+'\n', srcfile, 'exec') If it's already compiled (and still fresh etc.) stuff = open(bytecodefile, 'rb').read() co = marshal.loads(stuff[8:]) Then you need a module object mod = imp.new_module(nm) (You need to set up mod.__file__, mod.__name__ etc. here). And finally sys.modules[fqname] = mod exec co in mod.__dict__ This is not to say that I'm against your patch (didn't look at it), just that there's another way around the problem. -- Gordon http://www.mcmillan-inc.com/ From cfelling at iae.nl Sat Mar 2 06:12:13 2002 From: cfelling at iae.nl (Carel Fellinger) Date: 2 Mar 2002 06:12:13 +0100 Subject: Status of PEP's? References: Message-ID: Jeff Hinrichs wrote: > What you are asking everyone to agree with is: > 5 = [0,1,2,3,4] No he isn't:) He explicitly says he doesn't think of sequences at all. ... > If you were to restate the above as: > f(5)=[0,1,2,3,4] > Then, I believe, that you wouldn't have any problem convincing a large > majority that it is possible for f() to produce such an output. That being And this is precisly what he's proposing, f is called iter in his case. He comes from the camp that sees everything as an object, so numbers are objects to. Hence integers know to do things, like adding, subtracting, and ... counting! Three knows how to count from zero upto but not including three. If you accept this, then the discussion is not whether integers are sequences, but whether it's natural to stretch Python's `for' construct to mean `count' or `over its preceding numbers' in case of an integer. Like the `for' construct recently got stretched to mean `over all lines' and `over its keys' for text-files and dictionaries. Admitted in those cases it still was a clear `iterate over', but the what was debatable. > said, I would find that the argument favors the use of range/xrange over the > concept of iterable integers. I'm still concerned how it releates to `programming for everybody', as that goal is a sure measure to keep Python lean and simple. -- groetjes, carel From martin at v.loewis.de Sat Mar 2 14:12:20 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 02 Mar 2002 14:12:20 +0100 Subject: PEP 263 comments References: <87g03lhm3p.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: "Neil Hodgson" writes: > How do you tell Python to treat stdout as a tty even though it is > actually a pipe? I'd like to run Unicode printing programs from within SciTE > with I/O redirected to SciTE's output pane. There is also an issue with > stdin where I'd like to tell Python to treat redirected input, fed through a > pipe, as a tty. If stdout is a pipe, you cannot use the WriteConsoleW API for output, I believe. So you *have* to perform some encoding, and unless you can find a good reason to use a different one, the system default encoding would be used. In general, I see the usability to print Unicode only for the interpreter prompt. In all other cases (including cases where output goes to a pipe), the application should explicitly use some codec. That would normally be the codec for the locale's encoding, something that is roughly determined as if system is windows: terminal_encoding = "mbcs" # (1) elif have_nl_langinfo and have_CODEPAGE: terminal_encoding = locale.nl_langinfo(locale.CODEPAGE) else: terminal_encoding = sys.getdefaultencoding() (1): This is actually incorrect. On the terminal, CP_OEMCP is used, not CP_ACP (what "mbcs" uses). In the MS Console API, there are ways to query and modify the code page of a console, which has no effect if the raster font is used. If Python output goes to a pipe, I believe there is *no* way of finding out what the right encoding should be: If the receiving end writes to a text file, ANSI would be right, if the receiving end prints to the console, OEM would be right - unless somebody has changed the console code page for this console. People are so used to characters not showing up correctly in a Windows console that they won't worry if the application picks (1). Regards, Martin From cliechti at gmx.net Sat Mar 2 15:16:35 2002 From: cliechti at gmx.net (Chris Liechti) Date: 2 Mar 2002 15:16:35 +0100 Subject: a simple 'else' decrease speed by 1000 times. References: <3C80BBAC.2060600@student.kun.nl> Message-ID: husam wrote in news:3C80BBAC.2060600 @student.kun.nl: > One else statement decrease speed by 1000 times. Why is that? ... > if prv == n[i][-1]: > n[i].append(new) > print count, '\t', i , '\t',n[i] > count = count +1 > break > else: > n[i].append(0) 'cause your not "break"-ing here? but you do in the "if-then" part... -- Chris From h.jehadalwan at student.kun.nl Sat Mar 2 15:44:05 2002 From: h.jehadalwan at student.kun.nl (husam) Date: Sat, 02 Mar 2002 15:44:05 +0100 Subject: a simple 'else' decrease speed by 1000 times. References: <3C80BBAC.2060600@student.kun.nl> Message-ID: <3C80E535.7000407@student.kun.nl> Chris Liechti wrote: > husam wrote in news:3C80BBAC.2060600 > @student.kun.nl: > >>One else statement decrease speed by 1000 times. Why is that? >> > ... > >> if prv == n[i][-1]: >> n[i].append(new) >> print count, '\t', i , '\t',n[i] >> count = count +1 >> break >> else: >> n[i].append(0) >> > > 'cause your not "break"-ing here? but you do in the "if-then" part... It should not break here. Because imagin that the matching 'prv' is somewhere in a line in the middle of the file, the code will break immediately at the first non-matching line. From mickey at tm.informatik.uni-frankfurt.de Sat Mar 2 14:53:31 2002 From: mickey at tm.informatik.uni-frankfurt.de (Michael 'Mickey' Lauer) Date: 2 Mar 2002 15:53:31 +0200 Subject: Possible to fake object type? Message-ID: <3c80e76b@nntp.server.uni-frankfurt.de> Hi, suppose I have the following code: class Dockable: "Represents a dockable window" def __init__( self, childclass, handlepos = gtk.POS_LEFT ): self.__dict__["_handlebox"] = gtk.HandleBox() self.__dict__["_child"] = childclass() self._handlebox.add( self._child ) def __getattr__( self, attr ): print "requesting attribut: '%s'" % attr return self.__dict__.get( attr, None ) \ or getattr( self._child, attr ) Dockable is composition of two classes trying to mimick the interface of the childclass and thus hiding that the childclass is embedded in a HandleBox. So far so good. The Problem: PyGTK (which I'm using) has typechecking. I cannot use my composition class instead of a - say gtk.HandleBox(), because I get, for instance: TypeError: child should be a GtkWidget It's no option to make Dockable a GtkWidget, for instance, by deriving it from gtk.HandleBox, because GtkWidget itself contains methods which I call on a Dockable but which should be reflected to the _child rather than be handled by the - then - baseclass GtkWidget. So: Is it possible to fake the type of a class or is it possible to magically override the method call "bouncing" to the base class ? Yours, :M: -- |----------------------------------------------------------------------------| | Dipl.-Inf. Michael 'Mickey' Lauer mickey at tm.informatik.uni-frankfurt.de | | Raum 10b - ++49 69 798 28358 Fachbereich Informatik und Biologie | |----------------------------------------------------------------------------| From cliechti at gmx.net Sat Mar 2 16:00:48 2002 From: cliechti at gmx.net (Chris Liechti) Date: 2 Mar 2002 16:00:48 +0100 Subject: a simple 'else' decrease speed by 1000 times. References: <3C80BBAC.2060600@student.kun.nl> <3C80E535.7000407@student.kun.nl> Message-ID: husam wrote in news:3C80E535.7000407 @student.kun.nl: > Chris Liechti wrote: > >> husam wrote in news:3C80BBAC.2060600 >> @student.kun.nl: >> >>>One else statement decrease speed by 1000 times. Why is that? >>> >> ... >> >>> if prv == n[i][-1]: n[i].append(new) >>> print count, '\t', i , '\t',n[i] >>> count = count +1 break else: >>> n[i].append(0) >>> >> >> 'cause your not "break"-ing here? but you do in the "if-then" part... > > > It should not break here. Because imagin that the matching 'prv' is > somewhere in a line in the middle of the file, the code will break > immediately at the first non-matching line. yes, you're right but that means that the else part is executen many times and that will slow down your program. -- Chris From sheershion at mailexpire.com Sat Mar 2 16:02:45 2002 From: sheershion at mailexpire.com (Robert Amesz) Date: Sat, 02 Mar 2002 15:02:45 -0000 Subject: win32+popen4 References: <$4LupWAmqsf8Ew0o@jessikat.fsnet.co.uk> <3C7FF015.D1A00D13@ccvcorp.com> Message-ID: Robin Becker wrote: > interestingly I don't seem to need the \ quotes in win2k. What > system is it that needs those? Well, usually you don't, but I've found I *had* to escape a \ when it's at the end of the commandline. ISTR that escaping all backslashes didn't hurt, so that would make it a safer option. Presumably, even MS wouldn't treat some \ combination as an escape sequence in a commandline, but there may be other strange combinations. Robert Amesz From drgergl at mindspring.com Sat Mar 2 16:02:41 2002 From: drgergl at mindspring.com (Greg Landrum) Date: Sat, 2 Mar 2002 07:02:41 -0800 Subject: Profiling extensions Message-ID: [Linux, python 2.1] Hi All, I've got a Boostified C++ class that I'm using from Python. The class supports pickling, but restoring things from pickles seems to be really, really slow. I figured that I'd profile the code and find out where the time is being spent, but I ran into a wall. I built both my extension modules and python itself with -pg. Running a test case and looking at the gprof output only shows me numbers for the python interpreter itself. This is none too edifying. So, my question is: is there any way to trick gprof (or prof, I don't much care) into gathering data for the extension modules as well as the interpreter? Thanks, -greg From cliechti at gmx.net Sat Mar 2 16:11:02 2002 From: cliechti at gmx.net (Chris Liechti) Date: 2 Mar 2002 16:11:02 +0100 Subject: Possible to fake object type? References: <3c80e76b@nntp.server.uni-frankfurt.de> Message-ID: Michael 'Mickey' Lauer wrote in news:3c80e76b at nntp.server.uni-frankfurt.de: > So: Is it possible to fake the type of a class or > is it possible to magically override the method call "bouncing" > to the base class ? you can allways call the methods of on e of the supperclasses by using: Baseclass.method(self, args, ...) it's the same you do in __init__ to initilaize base classes: class Dockable(gtk.HandleBox): def __init__(self): gtk.HandleBox.__init__(self) def dosomething(self, arg): print "calling dosomething...", result = gtk.HandleBox.dosomething(self, arg) print "result = %r" % result return result ... -- Chris From edream at tds.net Sat Mar 2 16:17:32 2002 From: edream at tds.net (Edward K. Ream) Date: Sat, 02 Mar 2002 15:17:32 GMT Subject: Why isn't pychecker mentioned prominently? Message-ID: <3C80ED0B.42292C99@tds.net> I just found out about pychecker (http://pychecker.sourceforge.net/) and I am wondering why it isn't mentioned prominently all over the Python web site: the tutorial, the links on the left and side of the home page, topics guides, general reference etc. I found out about it from reading one of Guido's recent presentations in which he mentions it as one of his favorite Python tools. So why is pychecker such a secret? This is a really important tool and it patches a major hole in the Python environment by making many of the checks that compilers make: pychecker catches unused variables, argument problems and generally finds problems that will be very hard to find otherwise. In about one hour I found at least six bugs using pychecker that would crash Leo in unusual situations. I just think this is a vital tool for any significant project. It should be much easier to find than it is. BTW, it is easy to run pychecker as described in the URL above, and the pychecker site above fails to mention an even easier way: running options.py brings up a gui interface to pychecker. I found out about this by studying the pychecker source code! Edward -------------------------------------------------------------------- Edward K. Ream email: edream at tds.net Leo: Literate Editor with Outlines Leo: http://personalpages.tds.net/~edream/front.html -------------------------------------------------------------------- From skip at pobox.com Sat Mar 2 16:23:44 2002 From: skip at pobox.com (Skip Montanaro) Date: Sat, 2 Mar 2002 09:23:44 -0600 Subject: map-like function on dict values? In-Reply-To: References: Message-ID: <15488.61056.406754.393735@12-248-41-177.client.attbi.com> Raymond> The mapvalue test needs a tune-up. Skipping the operator Raymond> module and calling setitem directly speeds things up a bit: Raymond> def tunedmap(f, d): Raymond> return map( d.__setitem__, d.keys(), map(f, d.values()) ) Ah, yes. operator.setitem would only be needed if you were using multiple dictionaries. Good point. -- Skip Montanaro (skip at pobox.com - http://www.mojam.com/) From boud at valdyas.org Sat Mar 2 18:22:53 2002 From: boud at valdyas.org (Boudewijn Rempt) Date: Sat, 02 Mar 2002 16:22:53 -0100 Subject: PyQT and shaped windows in X References: Message-ID: <3c80ef25$0$90048$e4fe514c@dreader1.news.xs4all.nl> Moray Taylor wrote: > Hi, > > Can anyone point me in the direction of an example of shaped windows > using QT with Python, is the XLib module required? Is it even > possible? > Have you tried translating the tux example from the Qt examples directory? I've attached a quick and dirty script. You should get the image from someplace yourself. > BTW I have tried asking in the PyQT/PyKDE mailing list, but it wasn't > considered to be a PyQT question, go figure. > Well, it certainly isn't very Qt specific. -- Boudewijn Rempt | http://www.valdyas.org -------------- next part -------------- A non-text attachment was scrubbed... Name: tux.py Type: text/x-java Size: 745 bytes Desc: not available Url : http://mail.python.org/pipermail/python-list/attachments/20020302/b69032a3/attachment.java From phd at phd.pp.ru Sat Mar 2 16:27:57 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Sat, 2 Mar 2002 18:27:57 +0300 Subject: Problems with multipart messages w/email class In-Reply-To: <1015006362.1673.7.camel@jwilhelm.ofsloans.com>; from jwilhelm@outsourcefinancial.com on Fri, Mar 01, 2002 at 11:12:42AM -0700 References: <1015006362.1673.7.camel@jwilhelm.ofsloans.com> Message-ID: <20020302182757.A8152@phd.pp.ru> On Fri, Mar 01, 2002 at 11:12:42AM -0700, Joseph Wilhelm wrote: > AttributeError: 'int' object has no attribute 'lower' This is well-known bug in the email package, and it was fixed in CVS. Please use the latest version from mimelib.sf.net. Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From boud at valdyas.org Sat Mar 2 18:25:26 2002 From: boud at valdyas.org (Boudewijn Rempt) Date: Sat, 02 Mar 2002 16:25:26 -0100 Subject: PyQT and shaped windows in X References: <3c80ef25$0$90048$e4fe514c@dreader1.news.xs4all.nl> Message-ID: <3c80efbe$0$90048$e4fe514c@dreader1.news.xs4all.nl> Boudewijn Rempt wrote: > > Well, it certainly isn't very Qt specific. > I meant to type: PyQt specific. -- Boudewijn Rempt | http://www.valdyas.org From woo910 at simmani.com Sat Mar 2 16:53:46 2002 From: woo910 at simmani.com (¹ÌÈ­) Date: Sun, 3 Mar 2002 00:53:46 +0900 Subject: [±¤-°í] "Çöó¿öµµ»ç" 2002³â ²ÉÁ¡À¸·Î ¿î¼¼¸¦... Message-ID: An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-list/attachments/20020303/cb2f76ca/attachment.htm From paul at pfdubois.com Sat Mar 2 16:53:37 2002 From: paul at pfdubois.com (Paul F Dubois) Date: Sat, 2 Mar 2002 07:53:37 -0800 Subject: [Numpy-discussion] RE: Python 2.2 seriously crippled for numerical computation? In-Reply-To: Message-ID: <000001c1c202$7996be90$1001a8c0@NICKLEBY> I also see the underflow problem on my Linux box 2.4.2-2. This is certainly untenable. However, I am able to catch OverflowError in both cases. I had a user complain about this just yesterday, so I think it is a new behavior in Python 2.2 which I was just rolling out. A small Fortran test problem did not exhibit the underflow bug, and caught the overflow bug at COMPILE TIME (!). There are two states for the IEEE underflow: one in which the hardware sets it to zero, and the other in which the hardware signals the OS and you can tell the OS to set it to zero. There is no standard for the interface to this facility that I am aware of. (Usually I have had to figure out how to make sure the underflow was handled in hardware because the sheer cost of letting it turn into a system call was prohibitive.) I speculate that on machines where the OS call is the default that Python 2.2 is catching the signal when it should let it go by. I have not looked at this lately so something may have changed. You can use the kinds package that comes with Numeric to test for maximum and minimum exponents. kinds.default_float_kind.MAX_10_EXP (equal to 308 on my Linux box, for example) tells you how big an exponent a floating point number can have. MIN_10_EXP (-307 for me) is also there. Work around on your convergence test: instead of testing x**2 you might test log10(x) vs. a constant or some expression involving kinds.default_float_kind.MIN_10_EXP. -----Original Message----- From: numpy-discussion-admin at lists.sourceforge.net [mailto:numpy-discussion-admin at lists.sourceforge.net] On Behalf Of Tim Peters Sent: Friday, March 01, 2002 9:43 PM To: Huaiyu Zhu; numpy-discussion at lists.sourceforge.net Cc: python-list at python.org Subject: [Numpy-discussion] RE: Python 2.2 seriously crippled for numerical computation? [Huaiyu Zhu] > There appears to be a serious bug in Python 2.2 that severely limits > its usefulness for numerical computation: > > # Python 1.5.2 - 2.1 > > >>> 1e200**2 > inf A platform-dependent accident, there. > >>> 1e-200**2 > 0.0 > > # Python 2.2 > > >>> 1e-200**2 > Traceback (most recent call last): > File "", line 1, in ? > OverflowError: (34, 'Numerical result out of range') That one is surprising and definitely not intended: it suggests your platform libm is setting errno to ERANGE for pow(1e-200, 2.0), or that your platform C headers define INFINITY but incorrectly, or that your platform C headers define HUGE_VAL but incorrectly, or that your platform C compiler generates bad code, or optimizes incorrectly, for negating and/or comparing against its definition of HUGE_VAL or INFINITY. Python intends silent underflow to 0 in this case, and I haven't heard of underflows raising OverflowError before. Please file a bug report with full details about which operating system, Python version, compiler and C libraries you're using (then it's going to take a wizard with access to all that stuff to trace into it and determine the true cause). > >>> 1e200**2 > Traceback (most recent call last): > File "", line 1, in ? > OverflowError: (34, 'Numerical result out of range') That one is intended; see http://sf.net/tracker/?group_id=5470&atid=105470&func=detail&aid=496104 for discussion. > This produces the following serious effects: after hours of numerical > computation, just as the error is converging to zero, the whole thing > suddenly unravels. It depends on how you write your code, of course. > Note that try/except is completely useless for this purpose. Ditto. If your platform C lets you get away with it, you may still be able to get an infinity out of 1e200 * 1e200. > I hope this is unintended behavior Half intended, half both unintended and never before reported. > and that there is an easy fix. Sorry, "no" to either. _______________________________________________ Numpy-discussion mailing list Numpy-discussion at lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/numpy-discussion From p.g at figu.no Sat Mar 2 17:10:31 2002 From: p.g at figu.no (Per Gummedal) Date: Sat, 2 Mar 2002 17:10:31 +0100 Subject: Black Adder and PyQt In-Reply-To: <3C80B1E3.575761B7@river-bank.demon.co.uk> References: <3C80B1E3.575761B7@river-bank.demon.co.uk> Message-ID: <1851070092828.20020302171031@figu.no> Wayne Pierce wrote: > As I understand it, the only restriction on redistribution is if you are > distributing commercial apps. Then you need the business edition to > redistribute Qt and the other modules. It might be good to get the > scoop directly from them on this since I got the business edition and > haven't had to worry about it. From eppstein at ics.uci.edu Sat Mar 2 17:08:07 2002 From: eppstein at ics.uci.edu (David Eppstein) Date: Sat, 02 Mar 2002 08:08:07 -0800 Subject: PEP 276 (was Re: Status of PEP's?) References: Message-ID: In article , "Emile van Sebille" wrote: > "Carel Fellinger" > > You specify that the > > integer to iterate over should be possitive, why not allow for > > negative values and do the sensible thing, like: > > > > >>> [i for i in -3] > > [-1, -2, -3] > > If you change the sensible thing to mean: > > [-3, -2, -1] > > I'd like it better. ;-) But that wouldn't be as useful for iterating backwards through lists. Which is what most of this seems to be directed at, rather than anything to do with integers per se, so I wonder why we are trying to convert integers into lists of indices rather than converting the lists directly. -- David Eppstein UC Irvine Dept. of Information & Computer Science eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/ From gerhard at bigfoot.de Sat Mar 2 17:12:18 2002 From: gerhard at bigfoot.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: 2 Mar 2002 16:12:18 GMT Subject: Profiling extensions References: Message-ID: Greg Landrum wrote in comp.lang.python: > [Linux, python 2.1] > Hi All, > > > I've got a Boostified C++ class that I'm using from Python. The class > supports pickling, but restoring things from pickles seems to be really, > really slow. I figured that I'd profile the code and find out where the > time is being spent, but I ran into a wall. > > I built both my extension modules and python itself with -pg. Running a > test case and looking at the gprof output only shows me numbers for the > python interpreter itself. This is none too edifying. > > So, my question is: is there any way to trick gprof (or prof, I don't much > care) into gathering data for the extension modules as well as the > interpreter? I had that problem once, too. My "solution" was to embed Python and the extension library into a statically linked minimal test application. Then, I just set PYTHONPATH=. and called the init function of the extension module. In the minimal application I then just ran my test sript with Py_Run... This workaround did it for me, but I'd be interested in a proper solution to profiling extension modules as shared libraries nevertheless. Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0 public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From mickey at tm.informatik.uni-frankfurt.de Sat Mar 2 16:18:53 2002 From: mickey at tm.informatik.uni-frankfurt.de (Michael 'Mickey' Lauer) Date: 2 Mar 2002 17:18:53 +0200 Subject: Possible to fake object type? References: <3c80e76b@nntp.server.uni-frankfurt.de> Message-ID: <3c80fb6d@nntp.server.uni-frankfurt.de> Chris Liechti wrote: > Michael 'Mickey' Lauer wrote > in > news:3c80e76b at nntp.server.uni-frankfurt.de: >> So: Is it possible to fake the type of a class or >> is it possible to magically override the method call "bouncing" >> to the base class ? > > you can allways call the methods of on e of the supperclasses by > using: > > Baseclass.method(self, args, ...) > > it's the same you do in __init__ to initilaize base classes: > > class Dockable(gtk.HandleBox): > def __init__(self): > gtk.HandleBox.__init__(self) > > def dosomething(self, arg): > print "calling dosomething...", > result = gtk.HandleBox.dosomething(self, arg) > print "result = %r" % result > return result Yeah, sure, but I'd have to do this for every single function - which is not quite the elegant solution I aimed to come up with by using the getattr magic. Yours, :M: From fperez528 at yahoo.com Sat Mar 2 10:13:38 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Sat, 02 Mar 2002 09:13:38 +0000 Subject: Python 2.2 seriously crippled for numerical computation? References: Message-ID: Huaiyu Zhu wrote: > There appears to be a serious bug in Python 2.2 that severely limits its > usefulness for numerical computation: > [snipped] Just to give some data points on this. I confirmed the problem on a Mandrake 8.1 box with python 2.2 built by hand, gcc 2.96. But the python 2.2 windows binary from python.org does NOT exhibit it in my WindowsXP box. The reuslt there is 1e-200**2 -> 0.0, as it should. I posted this report to the scipy-dev list to see if someone there (many linux users, all directly involved in numerical computing) can find out what the problem is. Cheers, f. From mats at laplaza.org Sat Mar 2 17:16:23 2002 From: mats at laplaza.org (Mats Wichmann) Date: Sat, 02 Mar 2002 16:16:23 GMT Subject: (OT?) Web-based document review system? References: <3c801a5b.68374897@news.laplaza.org> Message-ID: <3c80f9de.125594084@news.laplaza.org> On Fri, 01 Mar 2002 18:52:42 -0800, Wayne Pierce wrote: : :Mats Wichmann wrote: :> Note: this is not a Python question per se. :> :> I'm looking for a piece of software to aid in reviewing a document :> through the web - click on a paragraph tag, have the comment added :> (highlighted in some way). The wiki style doesn't seem to quite do it, :> as the core document is not protected. I haven't found much in web :> searches, and nothing where the software seems to be free. : :If Wiki allowed for password protection would it fit your requirements? Not really. A Wiki works on the model that everyone is the editor; the model that I need to operate on is a single editor, many reviewers. :Something like Zope's CMF Workflow[2] might also be a good fit....then :there's OpenFlow[3] (also running on Zope :). My understanding of Zope is limited, but it might provide the facilities needed, yes. Here's an implementation that's "almost there": http://www.quicktopic.com/10/D/9hmkxh7US2d.html The thing I want (that I've seen in private in-house implementations) is a view that shows the original document and the comment in a single view, here you have to click to get the comments. I can envision a scheme where a document is broken into objects that can be commented on, and on presentation a document object can be displayed togther with its' associated comment objects. Sound like something Zope could facilitate? Hmmm. Mats Mats Wichmann From justin at iago.org Sat Mar 2 17:37:56 2002 From: justin at iago.org (Justin Sheehy) Date: Sat, 02 Mar 2002 11:37:56 -0500 Subject: Python 2.2 seriously crippled for numerical computation? In-Reply-To: (Huaiyu Zhu's message of "Fri, 1 Mar 2002 20:51:26 -0800 (PST)") References: Message-ID: Huaiyu Zhu writes: > There appears to be a serious bug in Python 2.2 that severely limits its > usefulness for numerical computation: > # Python 2.2 > >>>> 1e-200**2 > Traceback (most recent call last): > File "", line 1, in ? > OverflowError: (34, 'Numerical result out of range') I suspect that this is a problem with your local compiler or math library. On the two most convenient platforms to me, this is properly handled. Python 2.2 (#1, Dec 28 2001, 09:54:53) [GCC 2.96 20000306 (experimental)] on sunos5 Type "help", "copyright", "credits" or "license" for more information. >>> 1e-200**2 0.0 Python 2.2 (#4, Jan 25 2002, 15:55:24) [GCC 2.95.3 20010315 (release) [FreeBSD]] on freebsd4 Type "help", "copyright", "credits" or "license" for more information. >>> 1e-200**2 0.0 I don't know a lot of details about platform math implementations, but if you post your compiler and OS, I suspect that people here will be more likely to be able to provide useful advice. -Justin From cliechti at gmx.net Sat Mar 2 17:59:52 2002 From: cliechti at gmx.net (Chris Liechti) Date: 2 Mar 2002 17:59:52 +0100 Subject: Possible to fake object type? References: <3c80e76b@nntp.server.uni-frankfurt.de> <3c80fb6d@nntp.server.uni-frankfurt.de> Message-ID: Michael 'Mickey' Lauer wrote in news:3c80fb6d at nntp.server.uni-frankfurt.de: > Chris Liechti wrote: >> Michael 'Mickey' Lauer wrote >> in news:3c80e76b at nntp.server.uni-frankfurt.de: >>> So: Is it possible to fake the type of a class or >>> is it possible to magically override the method call "bouncing" to >>> the base class ? >> >> you can allways call the methods of on e of the supperclasses by >> using: >> >> Baseclass.method(self, args, ...) >> >> it's the same you do in __init__ to initilaize base classes: >> >> class Dockable(gtk.HandleBox): >> def __init__(self): gtk.HandleBox.__init__(self) >> >> def dosomething(self, arg): >> print "calling dosomething...", result = >> gtk.HandleBox.dosomething(self, arg) print "result = >> %r" % result return result > > Yeah, sure, but I'd have to do this for every single > function - which is not quite the elegant solution > I aimed to come up with by using the getattr magic. why not something like that?: def __getattr__(self, name): try: return self.__dict__[name] except NameError: return getattr(gtk.HandleBox, name) something similar can be done for setattr too of course. you could also google for the Proxy Design Pattern which can be implemented in such a way. -- Chris From pereira at cis.upenn.edu Sat Mar 2 18:20:04 2002 From: pereira at cis.upenn.edu (Fernando Pereira) Date: Sat, 02 Mar 2002 12:20:04 -0500 Subject: [Numpy-discussion] RE: Python 2.2 seriously crippled for numerical computation? References: Message-ID: On 3/2/02 10:53 AM, in article mailman.1015084565.2836.python-list at python.org, "Paul F Dubois" wrote: > I also see the underflow problem on my Linux box 2.4.2-2. This is > certainly untenable. However, I am able to catch OverflowError in both > cases. I had a user complain about this just yesterday, so I think it is > a new behavior in Python 2.2 which I was just rolling out. It's not Python 2.2 itself: % python Python 2.2 (#1, Feb 10 2002, 13:29:43) [GCC 2.95.2 19991024 (release)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> 1e-200**2 0.0 -- F From h.jehadalwan at student.kun.nl Sat Mar 2 18:27:56 2002 From: h.jehadalwan at student.kun.nl (husam) Date: Sat, 02 Mar 2002 18:27:56 +0100 Subject: a simple 'else' decrease speed by 1000 times. References: <3C80BBAC.2060600@student.kun.nl> <3C80E535.7000407@student.kun.nl> Message-ID: <3C810B9C.6050208@student.kun.nl> hi Chris, I think that I've found a mistake in the script. The mistake is outside the function I posted. I corrected it and now in I'm testing it again. The script takes alot of time to excute, so if the test fails again, you will see a posting from me within days. From heinlr at gmx.de Sat Mar 2 18:34:33 2002 From: heinlr at gmx.de (heinl raimund) Date: Sat, 2 Mar 2002 18:34:33 +0100 Subject: Error on pysnmp and/or BER Module in Python2.2 Message-ID: <3c810d55$0$139$9b622d9e@news.freenet.de> i am using : Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on win32 i use the pysnmp modul. for coding and encoding of snmp packets pysnmp uses the BER Modul. on function call to MyPySnmp_session.decode_value i got the following error: session instance has no attribute 'decode_an_unsigned'-exceptions.AttributeError is it a known bug - maybe a fixed BER/pysnmp Modul already exists ? best regards ### CODE SNIPPLET session = pysnmp.session(agent, community) # create a SNMP session #the session is always not NONE - its not possible at this point to validate a password for objid in lobjid: # encode objids #DBG(DBG_SNMPLO, "snmpget: %s + %s ", objid, poid) encoded_oids.append(session.encode_oid(session.str2nums(objid+poid))) # build a packet packet = session.encode_request ('GETREQUEST', encoded_oids, encoded_vals) # send SNMP request and receive a response packet = session.send_and_receive (packet) if packet == None: # if None stop condition occured return (-2, None) # parse a response packet (encoded_oids, encoded_vals) = session.decode_response (packet) index = 0 while index < len(encoded_oids): # decode objs & vals objid = session.decode_value(encoded_oids[index]) # in Python2.2 an !!!!!!!!!!! ERROR !!!!!!!!!!!!! # session instance has no attribute 'decode_an_unsigned'-exceptions.AttributeError value = session.decode_value(encoded_vals[index]) lval.append(value) if lprivoid != None: pos = string.find(objid, lobjid[index]) #DBG(DBG_SNMPLO, "snmpget:oidfind %s,%s:%d", objid, lobjid[index], pos) if pos != 0: # OID not at begin or not found privoid = objid # return complete ??? else: # ok strip requested OID pos = len(lobjid[index]) privoid = objid[pos:] # return private part lprivoid.append(privoid) index = index + 1 # go to the next objid if CallBackRead != None: CallBackRead(0) return (index, None) -- =========================================================== Heinl Raimund SSH - Software Systeme Heinl gepr.Wirtschaftsinformatiker IHK Am Galling 3 91217 Hersbruck Email: heinlr at gmx.de =========================================================== From gh_pythonlist at gmx.de Sat Mar 2 18:43:35 2002 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: Sat, 2 Mar 2002 18:43:35 +0100 Subject: Forwarding messages with the email package In-Reply-To: <20020204041714.GA2141@lilith.hqd-internal> References: <20020204041714.GA2141@lilith.hqd-internal> Message-ID: <20020302174334.GA6868@lilith.hqd-internal> Le 04/02/02 ? 05:17, Gerhard H?ring ?crivit: > I'm having some problems with the new email package in Python 2.2. I > guess the reason is that I don't really understand MIME and I fear my > head will explode when I try to make sense of the source code of the > email package. > > What I'm trying to do is forward an email message with MIME. I. e. not > inline. I'm trying to duplicate what my MUA does. It creates a > multipart/mixed MIME doc with a text/plain part and a message/rfc822 > part, that contains the email to forward. So, my current code is: > [snip buggy code] Hello Gerhard, maybe you'll find the following code useful: #!/usr/bin/env python2.2 # # Written by: Gerhard H?ring (gerhard at bigfoot.de) # License: none/public domain import sys, os, smtplib, email from email.Message import Message from email.MIMEBase import MIMEBase from email.MIMEText import MIMEText from email.MIMEMessage import MIMEMessage class Config: """Settings for Spamcop reports. You must at least change SUBMISSION_ADDRESS to match the one you got from Spamcop. You also need to provide a valid SMTP server address, localhost is just fine on many *nix systems.""" SUBMISSION_ADDRESS = "Spamcop " SMTP_SERVER = "localhost" MY_ADDRESS = "you at yournetwork.net" SUBJECT = "Spam report" BODY = "Dear Spamcop! Please analyze the following spam." def strip_spamassassin_markup(spam): infile, outfile = os.popen2("spamassassin -d -") infile.write(spam) infile.close() return outfile.read() def main(): forwarded_mail = strip_spamassassin_markup(sys.stdin.read()) me = Config.MY_ADDRESS to = [Config.SUBMISSION_ADDRESS] message = MIMEBase("multipart", "mixed") message["Subject"] = Config.SUBJECT message["From"] = Config.MY_ADDRESS message["To"] = ", ".join(to) message.attach(MIMEText(Config.BODY)) rfcmessage = MIMEBase("message", "rfc822") message_to_forward = email.message_from_string(forwarded_mail) rfcmessage.attach(message_to_forward) message.attach(rfcmessage) smtpserver = smtplib.SMTP(Config.SMTP_SERVER) smtpserver.sendmail(me, to, message.as_string(unixfrom=0)) smtpserver.close() if __name__ == "__main__": main() Hmm, maybe I should submit a patch to the docs of the email module. Gerhard -- This sig powered by Python! Au?entemperatur in M?nchen: 2.4 ?C Wind: 3.4 m/s From netzapper at magicstar.net Sat Mar 2 18:44:08 2002 From: netzapper at magicstar.net (A. Jones) Date: Sat, 02 Mar 2002 17:44:08 GMT Subject: Newbie question Message-ID: <3c810efa.475638531@mammoth.usenet-access.com> What is the function that forces conversion to a three-quote string? I need to save a string that has a LOT of \n's in it, and need to save both the formatting and the \'ns. I checked the manuals (and the online lists of functions), and all I came up with was str(), which doesn't do the tripple quote. Thanks ______________________________________________________________________________ Posted Via Binaries.net = SPEED+RETENTION+COMPLETION = http://www.binaries.net From Janssen at rz.uni-frankfurt.de Sat Mar 2 18:47:10 2002 From: Janssen at rz.uni-frankfurt.de (Michael Janssen) Date: Sat, 02 Mar 2002 18:47:10 +0100 Subject: Stedents Question References: <3c80126f_1@news.iprimus.com.au> Message-ID: <3c811073@nntp.server.uni-frankfurt.de> Tony K wrote: > The question below is a tutorial question that stumps me. Any suggestions > would be appreciated. > Tony > > Write a Python function findABBC which takes a single string as parameter > and returns all substrings thereof which match the regexp pattern ab+c. > You are NOT allowed to use the re module. def findABBC(str): a=0 b=0 while str: for n in str: if n=="a": a=1 break if a==1 and n=="b": b=b+1 break if a==1 and n=="c": print "a"+"b"*b+"c" a, b = 0, 0 break if n!=[a-c]: a, b = 0, 0 break str=str[1:] produces every ab+c-string in str. But there must be something easier. Something smaller ;-) Michael From skip at pobox.com Sat Mar 2 19:04:44 2002 From: skip at pobox.com (Skip Montanaro) Date: Sat, 2 Mar 2002 12:04:44 -0600 Subject: [Numpy-discussion] RE: Python 2.2 seriously crippled for numerical computation? In-Reply-To: References: Message-ID: <15489.5180.402637.125675@12-248-41-177.client.attbi.com> Fernando> It's not Python 2.2 itself: Fernando> % python Fernando> Python 2.2 (#1, Feb 10 2002, 13:29:43) Fernando> [GCC 2.95.2 19991024 (release)] on darwin Fernando> Type "help", "copyright", "credits" or "license" for more information. >>>> 1e-200**2 Fernando> 0.0 According to the pow man page on my Mandrake 8.1 system it suggests that ERANGE should be set if its first arg is zero. This appears to happen when x is around 1.5717e-162. I suspect a bug in glibc (I have version 2.2.4). In the region where the problem occurs, Python's float_pow() looks like PyFPE_START_PROTECT("pow", return NULL) ix = pow(iv, iw); PyFPE_END_PROTECT(ix) Py_SET_ERANGE_IF_OVERFLOW(ix); Setting a break immediately after the pow() call shows that ERANGE is set even though it appears to have correctly returned 0. Perhaps if iv < 1, ix == 0, and errno is ERANGE, errno should be cleared, at least for certain versions of glibc? -- Skip Montanaro (skip at pobox.com - http://www.mojam.com/) From skip at pobox.com Sat Mar 2 19:13:23 2002 From: skip at pobox.com (Skip Montanaro) Date: Sat, 2 Mar 2002 12:13:23 -0600 Subject: [Numpy-discussion] RE: Python 2.2 seriously crippled for numerical computation? In-Reply-To: <15489.5180.402637.125675@12-248-41-177.client.attbi.com> References: <15489.5180.402637.125675@12-248-41-177.client.attbi.com> Message-ID: <15489.5699.603634.319536@12-248-41-177.client.attbi.com> (Minor point of possible confusion.) I wrote: Skip> According to the pow man page on my Mandrake 8.1 system it Skip> suggests that ERANGE should be set if its first arg is zero. This Skip> appears to happen when x is around 1.5717e-162. "x" is the name of the first arg to pow() in the pow() manpage. The actual arg in floatobject.c:float_pow() is "iv". Skip From cfelling at iae.nl Sat Mar 2 19:05:25 2002 From: cfelling at iae.nl (Carel Fellinger) Date: 2 Mar 2002 19:05:25 +0100 Subject: PEP 276 (was Re: Status of PEP's?) References: Message-ID: Emile van Sebille wrote: > "Carel Fellinger" >> You specify that the >> integer to iterate over should be possitive, why not allow for >> negative values and do the sensible thing, like: >> >> >>> [i for i in -3] >> [-1, -2, -3] > If you change the sensible thing to mean: > [-3, -2, -1] > I'd like it better. ;-) I noted the smiley, but just in case someone might think you have a point: what would be the benefit of that? It just let you loop over a sequence in the standard order, but now with negative indici. And the range call to get this isn't that hard either: range(-3,0). My proposal makes iterating in *reverse* order simple. The tutorial could introduce it like: In python integers are objects too. And objects know how to do things, e.g. integer objects know how to add and just recently they learned how to count. Positive integers count from zero upto but not including the number itself, whereas negative integers count from -1 downto and including the number itself. A common place where this feature of integers is used is in for loops and list comprehension. e.g. >>> s = "silly walk".split() >>> print " ".join([s[i] for i in len(s)]) silly walk >>> print " ".join([s[i] for i in -len(s)]) walk silly Although the first print statement is generally written as: >>> print " ".join([x for x in s]) The implementation is dead simple, to play around with it in 2.2: class Int(int): def __neg__(self): return Int(int(self).__neg__()) def __iter__(self): i = 0 if self >= 0: while i < self: yield i i += 1 else: while i > self: i -= 1 yield i and define your classes to let __len__ return an Int object. class List(list): def __len__(self): return Int(len(list(self))) trying it out, yack it doesn't work, len forces it into an int again:( >>> spam = List("spam") >>> type(spam.__len__()) >>> type(len(spam)) I think this qualifies as a bug. -- groetjes, carel From edream at tds.net Sat Mar 2 19:13:40 2002 From: edream at tds.net (Edward K. Ream) Date: Sat, 02 Mar 2002 18:13:40 GMT Subject: C/C++ to Python translater References: <5e8bd451.0203011049.5d12d3a2@posting.google.com> Message-ID: <3C811653.871C5BEF@tds.net> kevin parks wrote: > > Is there a translator to automatically port (rewrite) code snippets > from C or C++ to Python? leo.py contains a script called c2py.py that I have used to translate all my C++ code to Python. It does about 80% of the work and is mostly intended to be run from inside Leo. IIRC there is another entry in c2py.py script to translate "exterior" files and this can be run from idle, say. Munging source to Python is actually remarkably easy to do. You can download leo.py v1.0 at: http://sourceforge.net/project/showfiles.php?group_id=3458 One of these days I'll get around to cleaning it up and making a proper distribution of it. Let me know if you have problems with c2py: it will help me clean up the rough edges. Edward -------------------------------------------------------------------- Edward K. Ream email: edream at tds.net Leo: Literate Editor with Outlines Leo: http://personalpages.tds.net/~edream/front.html -------------------------------------------------------------------- From andymac at bullseye.apana.org.au Sat Mar 2 12:00:56 2002 From: andymac at bullseye.apana.org.au (Andrew MacIntyre) Date: Sat, 2 Mar 2002 22:00:56 +1100 (EDT) Subject: [Numpy-discussion] RE: Python 2.2 seriously crippled for numerical computation? In-Reply-To: Message-ID: On 2 Mar 2002, Konrad Hinsen wrote: > Tim Peters writes: > > > > # Python 2.2 > > > > > > >>> 1e-200**2 > > > Traceback (most recent call last): > > > File "", line 1, in ? > > > OverflowError: (34, 'Numerical result out of range') > > > > That one is surprising and definitely not intended: it suggests your > > platform libm is setting errno to ERANGE for pow(1e-200, 2.0), or that your > > platform C headers define INFINITY but incorrectly, or that your platform C > > headers define HUGE_VAL but incorrectly, or that your platform C compiler > > generates bad code, or optimizes incorrectly, for negating and/or comparing > > I just tested and found the same behaviour, on RedHat Linux 7.1 > running on a Pentium machine. Python 2.1, compiled and running on the > same machine, returns 0. So does the Python 1.5.2 that comes with the > RedHat installation. Although there might certainly be something wrong > with the C compiler and/or header files, something has likely changed > in Python as well in going to 2.2, the only other explanation I see > would be a compiler optimization bug that didn't have an effect with > earlier Python releases. Other examples... FreeBSD 4.4: Python 2.1.1 (#1, Sep 13 2001, 18:12:15) [GCC 2.95.3 20010315 (release) [FreeBSD]] on freebsd4 Type "copyright", "credits" or "license" for more information. >>> 1e-200**2 0.0 >>> 1e200**2 Inf Python 2.3a0 (#1, Mar 1 2002, 00:00:52) [GCC 2.95.3 20010315 (release) [FreeBSD]] on freebsd4 Type "help", "copyright", "credits" or "license" for more information. >>> 1e-200**2 0.0 >>> 1e200**2 Traceback (most recent call last): File "", line 1, in ? OverflowError: (34, 'Result too large') Both builds built with "./configure --with-fpectl", although the optimisation settings for the 2.3a0 (CVS of yesterday) build were tweaked (2.1.1: "-g -O3"; 2.3a0: "-s -m486 -Os"). My 2.2 OS/2 EMX build (which uses gcc 2.8.1 -O2) produces exactly the same result as 2.3a0 on FreeBSD. -- Andrew I MacIntyre "These thoughts are mine alone..." E-mail: andymac at bullseye.apana.org.au | Snail: PO Box 370 andymac at pcug.org.au | Belconnen ACT 2616 Web: http://www.andymac.org/ | Australia From fperez528 at yahoo.com Sat Mar 2 12:11:04 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Sat, 02 Mar 2002 11:11:04 +0000 Subject: [Numpy-discussion] RE: Python 2.2 seriously crippled for numerical computation? References: Message-ID: Fernando Pereira wrote: > It's not Python 2.2 itself: > > % python > Python 2.2 (#1, Feb 10 2002, 13:29:43) > [GCC 2.95.2 19991024 (release)] on darwin > Type "help", "copyright", "credits" or "license" for more information. >>>> 1e-200**2 > 0.0 Ok, some more details to try and find who the culprit is: [~]> uname -a Linux maqroll 2.4.8-26mdk #1 Sun Sep 23 17:06:39 CEST 2001 i686 unknown [~]> gcc -v Reading specs from /usr/lib/gcc-lib/i586-mandrake-linux-gnu/2.96/specs gcc version 2.96 20000731 (Mandrake Linux 8.1 2.96-0.62mdk) [~]> python Python 2.2 (#1, Jan 17 2002, 21:03:58) [GCC 2.96 20000731 (Mandrake Linux 8.2 2.96-0.71mdk)] on linux-i386 Type "help", "copyright", "credits" or "license" for more information. >>> 1e-200**2 Traceback (most recent call last): File "", line 1, in ? OverflowError: (34, 'Numerical result out of range') This python2.2 was built by myself on a Mandrake 8.1 box (which comes with 2.1 by default). So it probably is a gcc/glib bug of some sort, but I don't really know where. Cheers, f. From brueckd at tbye.com Sat Mar 2 20:11:27 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Sat, 2 Mar 2002 11:11:27 -0800 (PST) Subject: Rotor in Jython? In-Reply-To: <7xr8n329oc.fsf@ruckus.brouhaha.com> Message-ID: On 1 Mar 2002, Paul Rubin wrote: > writes: > > Put another way: sorting by key length, AES beats rotors hands down. > > Sorting by computational cost, rotors always win because you can just make > > the keys longer (without having to reimplement your crypto). > > Longer keys are only relevant if breaking the cipher requires searching > for the key. Heheh... that's essentially what cryptanalysis is - finding the key since in most cases the algorithm itself is known. If you're referring to non-brute force key searches, then key length is relevent there as well (unless the algorithm itself is flawed). For example, in differential cryptanalysis of DES you're basically deducing bits of the key until you have so few remaining that a brute force attack becomes feasible. Longer key sizes (and a higher number of rounds) have an enormous impact on whether or not you'll ultimately be successful. -Dave From shredwheat at attbi.com Sat Mar 2 19:31:23 2002 From: shredwheat at attbi.com (Pete Shinners) Date: Sat, 02 Mar 2002 18:31:23 GMT Subject: Why isn't pychecker mentioned prominently? References: <3C80ED0B.42292C99@tds.net> Message-ID: <3C811C18.1020208@attbi.com> Edward K. Ream wrote: > I just found out about pychecker (http://pychecker.sourceforge.net/) and > I am wondering why it isn't mentioned prominently all over the Python > web site: the tutorial, the links on the left and side of the home page, > topics guides, general reference etc. I found out about it from reading > one of Guido's recent presentations in which he mentions it as one of > his favorite Python tools. So why is pychecker such a secret? i heartily agree. i now try to use pychecker on absolutely everything i do. i really wish it came as part of the standard distribution. it could easily be enabled on the commandline with some sort of -wall. heck, python recently added the full "warning" framework. it seems like an ideal place to tie that all in. then users can control if the pychecker warnings were silenced, printed, or treated as exceptions. From cfelling at iae.nl Sat Mar 2 19:17:25 2002 From: cfelling at iae.nl (Carel Fellinger) Date: 2 Mar 2002 19:17:25 +0100 Subject: PEP 276 (was Re: Status of PEP's?) References: Message-ID: David Eppstein wrote: > In article , ... > But that wouldn't be as useful for iterating backwards through lists. > Which is what most of this seems to be directed at, rather than anything to > do with integers per se, so I wonder why we are trying to convert integers > into lists of indices rather than converting the lists directly. But then you would need yet another parameter to an enhanced range or the yet to come indici to indicate you want to iterate in reverse, like: for i in range("spam", reverse=1): pass for in in indici("spam", reverse=1): pass The nicety of the enhanced iterating-integers proposal is that it gives a very easy spelling of two of the more frequent usages of iterating over the (range of the:) length of something once you accept that integers can count (up/down) and that `count' is spelled `iter' in Python. Still haven't made up my mind on that last one:) -- groetjes, carel From jlh at cox.net Sat Mar 2 20:01:08 2002 From: jlh at cox.net (Jeff Hinrichs) Date: Sat, 02 Mar 2002 19:01:08 GMT Subject: Status of PEP's? References: Message-ID: "Carel Fellinger" wrote in message news:a5pmvd$fic$1 at animus.fel.iae.nl... > Jeff Hinrichs wrote: > > > What you are asking everyone to agree with is: > > 5 = [0,1,2,3,4] > > No he isn't:) He explicitly says he doesn't think of sequences at all. If it walks like a duck and talks like a duck... It's a duck. How can one iterate over something that is not a sequence/collection? > ... > > If you were to restate the above as: > > f(5)=[0,1,2,3,4] > > Then, I believe, that you wouldn't have any problem convincing a large > > majority that it is possible for f() to produce such an output. That being > > And this is precisly what he's proposing, f is called iter in his > case. But this is already in the language. It is called range/xrange. I haven't seen any argument on why range/xrange is less preferrable to iterable integers. I've heard the philosophical debate but not seen how python would be better for this addition. If a good, tangible case were made I could be influenced. It would have to be a stronger case than: for i in 5: is better than for i in range(5): print i print i I say that it isn't because the first case implies while the second case is explict. And it should show how my code would be improved in any of the following terms, a) readability b)robustness c)minimizing bugs >He comes from the camp that sees everything as an object, so > numbers are objects to. Hence integers know to do things, like > adding, subtracting, and ... counting! Three knows how to count from > zero upto but not including three. If you accept this, then the > discussion is not whether integers are sequences, but whether it's > natural to stretch Python's `for' construct to mean `count' or `over > its preceding numbers' in case of an integer. But I don't accept this. **Not everything is an object.** An apple is an object. A number is an abstact idea already. You can hold an apple. You can not hold a 7. A number is a property of something else. It is an atomic property. A number does not have ancestors nor children. Just because I have 7 apples doesn't mean that at one time I had 6. Numbers don't perform operations, you peform operations on operands. To make a number be able to count and perform operations on itself seems to me to be an extreme case of the tail wagging the dog. >Like the `for' > construct recently got stretched to mean `over all lines' and `over > its keys' for text-files and dictionaries. Admitted in those cases it > still was a clear `iterate over', but the what was debatable. The reason for this, is that it is natural to view a file/keys as a collection. It is not natural to consider a number as a collection of other numbers. > > > said, I would find that the argument favors the use of range/xrange over the > > concept of iterable integers. > > I'm still concerned how it releates to `programming for everybody', > as that goal is a sure measure to keep Python lean and simple. I am not sure whether you are referring to iterable integers or range/xrange by the above. > -- > groetjes, carel -Jeff Hinrichs From henrik.motakef at web.de Sat Mar 2 18:17:22 2002 From: henrik.motakef at web.de (Henrik Motakef) Date: 02 Mar 2002 18:17:22 +0100 Subject: (OT?) Web-based document review system? References: <3c801a5b.68374897@news.laplaza.org> Message-